commit 103fe1e5906610a0dfbf16054c13ba9e87714fd5
parent 0cfcbf06b500927adb1a61098424f8dd79aa84af
Author: Eduardo Fontana Lazzari <edufonlaz@gmail.com>
Date: Tue, 4 Mar 2025 18:38:20 +0100
Refactor line number increment strategy during input file parsing
Initially, the input file for star-phor supported only a single level of
branching structures (e.g., volumes, surfaces, and sources spanning
multiple lines). Line numbering was incremented after each read
operation, both at the root level (config) and in its sublevels (volume,
surface, source).
With the evolution of the input file format, multiple levels of
branching are now possible (e.g., config -> surface -> sensor), forming
a tree structure. This led to an issue where, after parsing the last
line of the deepest structure, the line number was incremented twice,
causing one line to be skipped.
To fix this, line number incrementation is now handled by each parsed
line at the deepest level of the tree structure (its leaves),
independent of depth.
Diffstat:
6 files changed, 28 insertions(+), 25 deletions(-)
diff --git a/src/sphin_brdf.c b/src/sphin_brdf.c
@@ -105,7 +105,7 @@ parse_brdf
res_T res = RES_OK;
ASSERT(NULL != sphin);
- (void) txtrdr; /* Disable unused variable warning */
+
res = brdf_create(sphin, &brdf);
if (RES_OK != res) { goto error; }
/* Parse brdf type */
@@ -125,6 +125,10 @@ parse_brdf
if (RES_OK != res) { goto error; }
if (reflectivity < 0 || reflectivity >1 ) { res = RES_BAD_ARG; goto error; }
+ /* Advance one line in the parsing */
+ res = txtrdr_read_line(txtrdr);
+ if (RES_OK != res) { goto error; }
+
switch(brdf->type) {
case SPHIN_BRDF_LAMBERT:
brdf->lambertian.reflectivity = reflectivity;
diff --git a/src/sphin_config.c b/src/sphin_config.c
@@ -187,10 +187,6 @@ load_stream
txtrdr_get_name(txtrdr), txtrdr_get_line_num(txtrdr));
goto error;
}
- res = txtrdr_read_line(txtrdr);
- if (RES_OK != res) {
- goto error;
- }
}
exit:
diff --git a/src/sphin_sensor.c b/src/sphin_sensor.c
@@ -106,7 +106,6 @@ parse_response_function
double response_function;
ASSERT(NULL != sensor);
- (void) txtrdr; /* Disable unused variable warning */
token = strtok_r(value, " \t", &token_ptr);
@@ -118,6 +117,9 @@ parse_response_function
token = strtok_r(NULL, " \t", &token_ptr);
if (NULL != token) { res = RES_BAD_ARG; goto error; }
+ /* Advance one line in the parsing */
+ res = txtrdr_read_line(txtrdr);
+ if (RES_OK != res) { goto error; }
exit:
return res;
error:
@@ -174,9 +176,6 @@ parse_sensor
break;
}
if (RES_OK != res) { goto error; }
- /* Advance one line in the parsing */
- res = txtrdr_read_line(txtrdr);
- if (RES_OK != res) { goto error; }
}
exit:
str_release(&line);
diff --git a/src/sphin_source.c b/src/sphin_source.c
@@ -114,7 +114,6 @@ parse_direction_distribution
res_T res = RES_OK;
ASSERT(NULL != source);
- (void) txtrdr; /* Disable unused variable warning */
/* Parse direction distribution type */
direction_distribution_type = strtok_r(value, " \t", &token_ptr);
@@ -149,6 +148,10 @@ parse_direction_distribution
}
else { res = RES_BAD_ARG; goto error; }
+ /* Advance one line in the parsing */
+ res = txtrdr_read_line(txtrdr);
+ if (RES_OK != res) { goto error; }
+
exit:
return res;
error:
@@ -168,7 +171,6 @@ parse_flux_density
res_T res = RES_OK;
ASSERT(NULL != source);
- (void) txtrdr; /* Disable unused variable warning */
/* Parse flux density value */
str_flux_density = strtok_r(value, " \t", &token_ptr);
@@ -207,6 +209,10 @@ parse_flux_density
}
else { res = RES_BAD_ARG; goto error; }
+ /* Advance one line in the parsing */
+ res = txtrdr_read_line(txtrdr);
+ if (RES_OK != res) { goto error; }
+
exit:
return res;
error:
@@ -268,9 +274,6 @@ parse_source
break;
}
if (RES_OK != res) { goto error; }
- /* Advance one line in the parsing */
- res = txtrdr_read_line(txtrdr);
- if (RES_OK != res) { goto error; }
}
exit:
diff --git a/src/sphin_surface.c b/src/sphin_surface.c
@@ -142,9 +142,7 @@ parse_geometry
res_T res = RES_OK;
ASSERT(NULL != surface);
- (void) txtrdr; /* Disable unused variable warning */
- //res = geometry_parse(&geom, value);
res = geometry_parse(surface->sphin, value, &geom);
if (RES_OK != res) { goto error; }
@@ -152,8 +150,11 @@ parse_geometry
res = darray_sphin_geometry_ptr_push_back(&surface->geometries, &geom);
if (RES_OK != res) { goto error; }
+ /* Advance one line in the parsing */
+ res = txtrdr_read_line(txtrdr);
+ if (RES_OK != res) { goto error; }
+
exit:
- // geometry_release(&geom);
return res;
error:
goto exit;
@@ -219,9 +220,6 @@ parse_surface
break;
}
if (RES_OK != res) { goto error; }
- /* Advance one line in the parsing */
- res = txtrdr_read_line(txtrdr);
- if (RES_OK != res) { goto error; }
}
/* Append a new element to the end of the sphin_config->surfaces array */
diff --git a/src/sphin_volume.c b/src/sphin_volume.c
@@ -130,7 +130,6 @@ parse_geometry
res_T res = RES_OK;
ASSERT(NULL != volume); /* txtrdr and value are already asserted by caller */
- (void) txtrdr; /* Disable unused variable warning */
res = geometry_parse(volume->sphin, value, &geom);
if (RES_OK != res) { goto error; }
@@ -139,6 +138,10 @@ parse_geometry
res = darray_sphin_geometry_ptr_push_back(&volume->geometries, &geom);
if (RES_OK != res) { goto error; }
+ /* Advance one line in the parsing */
+ res = txtrdr_read_line(txtrdr);
+ if (RES_OK != res) { goto error; }
+
exit:
return res;
error:
@@ -159,7 +162,6 @@ parse_ka
double ka;
ASSERT(NULL != volume);
- (void) txtrdr; /* Disable unused variable warning */
/* Parse ka value */
ka_val = strtok_r(value, " \t", &token_ptr);
@@ -188,6 +190,10 @@ parse_ka
token = strtok_r(NULL, " \t", &token_ptr);
if (NULL != token) { res = RES_BAD_ARG; goto error; }
+ /* Advance one line in the parsing */
+ res = txtrdr_read_line(txtrdr);
+ if (RES_OK != res) { goto error; }
+
exit:
return res;
error:
@@ -249,9 +255,6 @@ parse_volume
break;
}
if (RES_OK != res) { goto error; }
- /* Advance one line in the parsing */
- res = txtrdr_read_line(txtrdr);
- if (RES_OK != res) { goto error; }
}
/* Append a new element to the end of the sphin_config->volumes array */