summaryrefslogtreecommitdiffstats
path: root/smtk-import/smartrak.c
diff options
context:
space:
mode:
authorGravatar Berthold Stoeger <bstoeger@mail.tuwien.ac.at>2019-08-04 18:44:57 +0200
committerGravatar Dirk Hohndel <dirk@hohndel.org>2019-11-09 19:19:04 +0100
commit7c9f46acd202121e67557bb634961ef17a9f6c1f (patch)
treef21b6ff42a930cc97c31db9f20c03f1613e70291 /smtk-import/smartrak.c
parentcd4f66014f7b5269dff9e088c9d7d38241c03156 (diff)
downloadsubsurface-7c9f46acd202121e67557bb634961ef17a9f6c1f.tar.gz
Core: remove MAX_CYLINDERS restriction
Instead of using fixed size arrays, use a new cylinder_table structure. The code copies the weightsystem code, but is significantly more complex because cylinders are such an integral part of the core. Two functions to access the cylinders were added: get_cylinder() and get_or_create_cylinder() The former does a simple array access and supposes that the cylinder exists. The latter is used by the parser(s) and if a cylinder with the given id does not exist, cylinders up to that id are generated. One point will make C programmers cringe: the cylinder structure is passed by value. This is due to the way the table-macros work. A refactoring of the table macros is planned. It has to be noted that the size of a cylinder_t is 64 bytes, i.e. 8 long words on a 64-bit architecture, so passing on the stack is probably not even significantly slower than passing as reference. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
Diffstat (limited to 'smtk-import/smartrak.c')
-rw-r--r--smtk-import/smartrak.c26
1 files changed, 13 insertions, 13 deletions
diff --git a/smtk-import/smartrak.c b/smtk-import/smartrak.c
index 968233eda..64a613fc7 100644
--- a/smtk-import/smartrak.c
+++ b/smtk-import/smartrak.c
@@ -507,7 +507,7 @@ static void merge_cylinder_info(cylinder_t *src, cylinder_t *dst)
static int smtk_clean_cylinders(struct dive *d)
{
int i = tanks - 1;
- cylinder_t *cyl, *base = &d->cylinder[0];
+ cylinder_t *cyl, *base = &d->cylinders.cylinders[0];
cyl = base + tanks - 1;
while (cyl != base) {
@@ -966,8 +966,6 @@ void smartrak_import(const char *file, struct dive_table *divetable)
smtk_version = atoi(smtk_ver[0]);
tanks = (smtk_version < 10213) ? 3 : 10;
-
-
mdb_table = smtk_open_table(mdb, "Dives", col, bound_values);
if (!mdb_table) {
report_error("[Error][smartrak_import]\tFile %s does not seem to be an SmartTrak file.", file);
@@ -978,6 +976,8 @@ void smartrak_import(const char *file, struct dive_table *divetable)
dc_family_t dc_fam = DC_FAMILY_NULL;
unsigned char *prf_buffer, *hdr_buffer, *compl_buffer;
struct dive *smtkdive = alloc_dive();
+ for (i = 0; i < tanks; ++i)
+ add_empty_cylinder(&smtkdive->cylinders);
struct tm *tm_date = malloc(sizeof(struct tm));
size_t hdr_length, prf_length;
dc_status_t rc = 0;
@@ -1038,24 +1038,24 @@ void smartrak_import(const char *file, struct dive_table *divetable)
int tankidxcol = coln(TANKIDX);
for (i = 0; i < tanks; i++) {
- if (smtkdive->cylinder[i].start.mbar == 0)
- smtkdive->cylinder[i].start.mbar = lrint(strtod(col[(i * 2) + pstartcol]->bind_ptr, NULL) * 1000);
+ if (smtkdive->cylinders.cylinders[i].start.mbar == 0)
+ smtkdive->cylinders.cylinders[i].start.mbar = lrint(strtod(col[(i * 2) + pstartcol]->bind_ptr, NULL) * 1000);
/*
* If there is a start pressure ensure that end pressure is not zero as
* will be registered in DCs which only keep track of differential pressures,
* and collect the data registered by the user in mdb
*/
- if (smtkdive->cylinder[i].end.mbar == 0 && smtkdive->cylinder[i].start.mbar != 0)
- smtkdive->cylinder[i].end.mbar = lrint(strtod(col[(i * 2) + 1 + pstartcol]->bind_ptr, NULL) * 1000 ? : 1000);
- if (smtkdive->cylinder[i].gasmix.o2.permille == 0)
- smtkdive->cylinder[i].gasmix.o2.permille = lrint(strtod(col[i + o2fraccol]->bind_ptr, NULL) * 10);
+ if (smtkdive->cylinders.cylinders[i].end.mbar == 0 && smtkdive->cylinders.cylinders[i].start.mbar != 0)
+ smtkdive->cylinders.cylinders[i].end.mbar = lrint(strtod(col[(i * 2) + 1 + pstartcol]->bind_ptr, NULL) * 1000 ? : 1000);
+ if (smtkdive->cylinders.cylinders[i].gasmix.o2.permille == 0)
+ smtkdive->cylinders.cylinders[i].gasmix.o2.permille = lrint(strtod(col[i + o2fraccol]->bind_ptr, NULL) * 10);
if (smtk_version == 10213) {
- if (smtkdive->cylinder[i].gasmix.he.permille == 0)
- smtkdive->cylinder[i].gasmix.he.permille = lrint(strtod(col[i + hefraccol]->bind_ptr, NULL) * 10);
+ if (smtkdive->cylinders.cylinders[i].gasmix.he.permille == 0)
+ smtkdive->cylinders.cylinders[i].gasmix.he.permille = lrint(strtod(col[i + hefraccol]->bind_ptr, NULL) * 10);
} else {
- smtkdive->cylinder[i].gasmix.he.permille = 0;
+ smtkdive->cylinders.cylinders[i].gasmix.he.permille = 0;
}
- smtk_build_tank_info(mdb_clon, &smtkdive->cylinder[i], col[i + tankidxcol]->bind_ptr);
+ smtk_build_tank_info(mdb_clon, &smtkdive->cylinders.cylinders[i], col[i + tankidxcol]->bind_ptr);
}
/* Check for duplicated cylinders and clean them */
smtk_clean_cylinders(smtkdive);