smtk-import Use lrint() when rounding to integer values

As commented on mailing list. Most numerical values from libmdb are
doubles obtained via strtod(), so, rounding them instead of just
truncating seems the correct way.

Signed-off-by: Salvador Cuñat <salvador.cunat@gmail.com>
This commit is contained in:
Salvador Cuñat 2017-03-16 16:31:15 +01:00 committed by Dirk Hohndel
parent 9ddf2d2ad8
commit 2cef8395b5

View file

@ -286,7 +286,7 @@ static void smtk_wreck_site(MdbHandle *mdb, char *site_idx, struct dive_site *ds
notes = smtk_concat_str(notes, "\n", "%s: %s", wreck_fields[i - 3], col[i]->bind_ptr); notes = smtk_concat_str(notes, "\n", "%s: %s", wreck_fields[i - 3], col[i]->bind_ptr);
break; break;
default: default:
d = strtold(col[i]->bind_ptr, NULL); d = lrintl(strtold(col[i]->bind_ptr, NULL));
if (d) if (d)
notes = smtk_concat_str(notes, "\n", "%s: %d", wreck_fields[i - 3], d); notes = smtk_concat_str(notes, "\n", "%s: %d", wreck_fields[i - 3], d);
break; break;
@ -342,7 +342,7 @@ static void smtk_build_location(MdbHandle *mdb, char *idx, timestamp_t when, uin
switch (i) { switch (i) {
case 8: case 8:
case 9: case 9:
d = strtold(col[i]->bind_ptr, NULL); d = lrintl(strtold(col[i]->bind_ptr, NULL));
if (d) if (d)
notes = smtk_concat_str(notes, "\n", "%s: %d m", site_fields[i - 8], d); notes = smtk_concat_str(notes, "\n", "%s: %d m", site_fields[i - 8], d);
break; break;
@ -719,12 +719,12 @@ void smartrak_import(const char *file, struct dive_table *divetable)
size_t hdr_length, prf_length; size_t hdr_length, prf_length;
dc_status_t rc = 0; dc_status_t rc = 0;
smtkdive->number = strtod(col[1]->bind_ptr, NULL); smtkdive->number = lrint(strtod(col[1]->bind_ptr, NULL));
/* /*
* If there is a DC model (no zero) try to create a buffer for the * If there is a DC model (no zero) try to create a buffer for the
* dive and parse it with libdivecomputer * dive and parse it with libdivecomputer
*/ */
dc_model = (int) strtod(col[coln(DCMODEL)]->bind_ptr, NULL) & 0xFF; dc_model = lrint(strtod(col[coln(DCMODEL)]->bind_ptr, NULL)) & 0xFF;
if (dc_model) { if (dc_model) {
hdr_buffer = mdb_ole_read_full(mdb, col[coln(LOG)], &hdr_length); hdr_buffer = mdb_ole_read_full(mdb, col[coln(LOG)], &hdr_length);
if (hdr_length > 0 && hdr_length < 20) // We have a profile but it's imported from datatrak if (hdr_length > 0 && hdr_length < 20) // We have a profile but it's imported from datatrak
@ -754,7 +754,7 @@ void smartrak_import(const char *file, struct dive_table *divetable)
/* Dives without profile samples (usual in older aladin series) */ /* Dives without profile samples (usual in older aladin series) */
report_error("[Warning][smartrak_import]\t No profile for dive %d", smtkdive->number); report_error("[Warning][smartrak_import]\t No profile for dive %d", smtkdive->number);
smtkdive->dc.duration.seconds = smtkdive->duration.seconds = smtk_time_to_secs(col[coln(DURATION)]->bind_ptr); smtkdive->dc.duration.seconds = smtkdive->duration.seconds = smtk_time_to_secs(col[coln(DURATION)]->bind_ptr);
smtkdive->dc.maxdepth.mm = smtkdive->maxdepth.mm = strtod(col[coln(MAXDEPTH)]->bind_ptr, NULL) * 1000; smtkdive->dc.maxdepth.mm = smtkdive->maxdepth.mm = lrint(strtod(col[coln(MAXDEPTH)]->bind_ptr, NULL) * 1000);
} }
free(hdr_buffer); free(hdr_buffer);
free(prf_buffer); free(prf_buffer);
@ -762,12 +762,12 @@ void smartrak_import(const char *file, struct dive_table *divetable)
/* Manual dives or unknown DCs */ /* Manual dives or unknown DCs */
report_error("[Warning][smartrak_import]\t Manual or unknown dive computer for dive %d", smtkdive->number); report_error("[Warning][smartrak_import]\t Manual or unknown dive computer for dive %d", smtkdive->number);
smtkdive->dc.duration.seconds = smtkdive->duration.seconds = smtk_time_to_secs(col[coln(DURATION)]->bind_ptr); smtkdive->dc.duration.seconds = smtkdive->duration.seconds = smtk_time_to_secs(col[coln(DURATION)]->bind_ptr);
smtkdive->dc.maxdepth.mm = smtkdive->maxdepth.mm = strtod(col[coln(MAXDEPTH)]->bind_ptr, NULL) * 1000; smtkdive->dc.maxdepth.mm = smtkdive->maxdepth.mm = lrint(strtod(col[coln(MAXDEPTH)]->bind_ptr, NULL) * 1000);
} }
/* /*
* Cylinder and gasmixes completion. * Cylinder and gasmixes completion.
* Revisit data under some circunstances, e.g. a start pressure = 0 may mean * Revisit data under some circunstances, e.g. a start pressure = 0 may mean
* that dc don't support gas control, in this situation let's look into mdb data * that dc doesn't support gas control, in this situation let's look into mdb data
*/ */
int numtanks = (tanks == 10) ? 8 : 3; // Subsurface supports up to 8 tanks int numtanks = (tanks == 10) ? 8 : 3; // Subsurface supports up to 8 tanks
int pstartcol = coln(PSTART); int pstartcol = coln(PSTART);
@ -805,15 +805,15 @@ void smartrak_import(const char *file, struct dive_table *divetable)
/* Data that user may have registered manually if not supported by DC, or not parsed */ /* Data that user may have registered manually if not supported by DC, or not parsed */
if (!smtkdive->airtemp.mkelvin) if (!smtkdive->airtemp.mkelvin)
smtkdive->airtemp.mkelvin = C_to_mkelvin(strtod(col[coln(AIRTEMP)]->bind_ptr, NULL)); smtkdive->airtemp.mkelvin = C_to_mkelvin(lrint(strtod(col[coln(AIRTEMP)]->bind_ptr, NULL)));
if (!smtkdive->watertemp.mkelvin) if (!smtkdive->watertemp.mkelvin)
smtkdive->watertemp.mkelvin = smtkdive->mintemp.mkelvin = C_to_mkelvin(strtod(col[coln(MINWATERTEMP)]->bind_ptr, NULL)); smtkdive->watertemp.mkelvin = smtkdive->mintemp.mkelvin = C_to_mkelvin(lrint(strtod(col[coln(MINWATERTEMP)]->bind_ptr, NULL)));
if (!smtkdive->maxtemp.mkelvin) if (!smtkdive->maxtemp.mkelvin)
smtkdive->maxtemp.mkelvin = C_to_mkelvin(strtod(col[coln(MAXWATERTEMP)]->bind_ptr, NULL)); smtkdive->maxtemp.mkelvin = C_to_mkelvin(lrint(strtod(col[coln(MAXWATERTEMP)]->bind_ptr, NULL)));
/* No DC related data */ /* No DC related data */
smtkdive->visibility = strtod(col[coln(VISIBILITY)]->bind_ptr, NULL) > 25 ? 5 : strtod(col[13]->bind_ptr, NULL) / 5; smtkdive->visibility = strtod(col[coln(VISIBILITY)]->bind_ptr, NULL) > 25 ? 5 : lrint(strtod(col[13]->bind_ptr, NULL) / 5);
smtkdive->weightsystem[0].weight.grams = strtod(col[coln(WEIGHT)]->bind_ptr, NULL) * 1000; smtkdive->weightsystem[0].weight.grams = lrint(strtod(col[coln(WEIGHT)]->bind_ptr, NULL) * 1000);
smtkdive->suit = smtk_value_by_idx(mdb_clon, "Suit", 1, col[coln(SUITIDX)]->bind_ptr); smtkdive->suit = smtk_value_by_idx(mdb_clon, "Suit", 1, col[coln(SUITIDX)]->bind_ptr);
smtk_build_location(mdb_clon, col[coln(SITEIDX)]->bind_ptr, smtkdive->when, &smtkdive->dive_site_uuid); smtk_build_location(mdb_clon, col[coln(SITEIDX)]->bind_ptr, smtkdive->when, &smtkdive->dive_site_uuid);
smtkdive->buddy = smtk_locate_buddy(mdb_clon, col[0]->bind_ptr); smtkdive->buddy = smtk_locate_buddy(mdb_clon, col[0]->bind_ptr);