commit 42370c21a54d26a5eadeb7f5e9baa517d10ee5f1 parent dd33e21ca7d871b7b44542a329d9816947b19be1 Author: Eduardo Fontana Lazzari <edufonlaz@gmail.com> Date: Fri, 23 Jan 2026 12:53:20 +0100 Improve code style consistency Standardize tabs, spaces, and includes across the codebase. Ensure lines do not exceed 80 characters and remove trailing whitespaces. Diffstat:
35 files changed, 235 insertions(+), 166 deletions(-)
diff --git a/src/sphin.h b/src/sphin.h @@ -313,18 +313,18 @@ sphin_volume_ref_put SPHIN_API res_T sphin_volume_get_name - (struct sphin_volume* volume, - char** name); + (struct sphin_volume* volume, + char** name); SPHIN_API res_T sphin_volume_compute_total_size (struct sphin_volume* volume, - double* total_size); + double* total_size); SPHIN_API res_T sphin_volume_get_sensor -(struct sphin_volume* volume, - struct sphin_sensor_volume** sensor_volume); /* May be NULL <=> no sensor */ + (struct sphin_volume* volume, + struct sphin_sensor_volume** sensor_volume); /* May be NULL <=> no sensor */ SPHIN_API res_T sphin_volume_get_geometry_count @@ -366,8 +366,8 @@ sphin_prop_rad_ref_put SPHIN_API res_T sphin_prop_rad_get_name - (struct sphin_prop_rad* prop_rad, - char** name); + (struct sphin_prop_rad* prop_rad, + char** name); SPHIN_API res_T sphin_prop_rad_get_scatterer @@ -429,13 +429,14 @@ sphin_surface_ref_put SPHIN_API res_T sphin_surface_get_name - (struct sphin_surface* surface, - char** name); + (struct sphin_surface* surface, + char** name); SPHIN_API res_T sphin_surface_get_sensor - (struct sphin_surface* surface, - struct sphin_sensor_surface** sensor_surface); /* May be NULL <=> no sensor */ + (struct sphin_surface* surface, + struct sphin_sensor_surface** sensor_surface); /* May be NULL <=> no + sensor */ SPHIN_API res_T sphin_surface_get_brdf diff --git a/src/sphin_brdf.c b/src/sphin_brdf.c @@ -29,7 +29,9 @@ #include "sphin_brdf.h" #include <rsys/cstr.h> +#include <rsys/mem_allocator.h> #include <rsys/ref_count.h> +#include <rsys/rsys.h> #include <rsys/text_reader.h> struct sphin_brdf { diff --git a/src/sphin_brdf.h b/src/sphin_brdf.h @@ -27,14 +27,13 @@ #include <rsys/rsys.h> -struct mem_allocator; struct txtrdr; extern LOCAL_SYM res_T parse_brdf -(struct sphin* sphin, - struct txtrdr* txtrdr, - char* value, - struct sphin_brdf** out_brdf); + (struct sphin* sphin, + struct txtrdr* txtrdr, + char* value, + struct sphin_brdf** out_brdf); #endif /* SPHIN_BRDF_H*/ diff --git a/src/sphin_config.c b/src/sphin_config.c @@ -30,6 +30,9 @@ #include "sphin_volume.h" #include <rsys/cstr.h> /* res_to_cstr */ +#include <rsys/mem_allocator.h> +#include <rsys/ref_count.h> +#include <rsys/rsys.h> #include <rsys/str.h> /* struct str */ #include <rsys/text_reader.h> /* struct txtrdr */ @@ -68,7 +71,7 @@ exit: return res; error: if (NULL != config) { - SPHIN(config_ref_put(config)); /* <=> ASSERT(sphin_config_ref_put(config) == RES_OK) */ + SPHIN(config_ref_put(config)); config = NULL; } goto exit; diff --git a/src/sphin_config.h b/src/sphin_config.h @@ -35,7 +35,6 @@ struct sphin; struct sphin_config { /* Put the fun things here */ - struct darray_sphin_surface_ptr surfaces; struct darray_sphin_volume_ptr volumes; struct sphin* sphin; diff --git a/src/sphin_geometry.c b/src/sphin_geometry.c @@ -28,6 +28,9 @@ #include <rsys/cstr.h> #include <rsys/double3.h> +#include <rsys/mem_allocator.h> +#include <rsys/ref_count.h> +#include <rsys/rsys.h> #include <star/sstl.h> /******************************************************************************* @@ -107,7 +110,7 @@ geometry_compute_area pos = darray_double_cdata_get(&geom->coords); ids = darray_size_t_cdata_get(&geom->indices); tri_count = darray_size_t_size_get(&geom->indices)/3; - if(0 == tri_count) return 0.; + if (0 == tri_count) return 0.; FOR_EACH(itri, 0, tri_count) { /* Retrieve vertex coordinates */ @@ -140,7 +143,7 @@ geometry_compute_volume pos = darray_double_cdata_get(&geom->coords); ids = darray_size_t_cdata_get(&geom->indices); tri_count = darray_size_t_size_get(&geom->indices)/3; - if(0 == tri_count) return 0.; + if (0 == tri_count) return 0.; FOR_EACH(itri, 0, tri_count) { /* Retrieve vertex coordinates */ @@ -168,7 +171,6 @@ geometry_compute_volume } return volume / 6.0; - } res_T @@ -297,8 +299,10 @@ sphin_geometry_get_desc return RES_BAD_ARG; } - mesh.coords = darray_double_data_get((struct darray_double*)&geometry->coords); - mesh.indices = darray_size_t_data_get((struct darray_size_t*)&geometry->indices); + mesh.coords = darray_double_data_get + ((struct darray_double*)&geometry->coords); + mesh.indices = darray_size_t_data_get + ((struct darray_size_t*)&geometry->indices); mesh.vertex_count = darray_double_size_get(&geometry->coords) / 3; mesh.triangle_count = darray_size_t_size_get(&geometry->indices) / 3; diff --git a/src/sphin_geometry.h b/src/sphin_geometry.h @@ -27,10 +27,10 @@ #include "sphin.h" -#include <rsys/dynamic_array.h> #include <rsys/dynamic_array_double.h> #include <rsys/dynamic_array_size_t.h> #include <rsys/ref_count.h> +#include <rsys/rsys.h> #include <rsys/str.h> struct mem_allocator; @@ -70,7 +70,8 @@ geometry_compute_volume * such as: * - darray_sphin_surface_ptr_release * - darray_sphin_surface_ptr_init - * - darray_sphin_surface_ptr_push_back => append element to the end of the dynamic array + * - darray_sphin_surface_ptr_push_back => append element to the end of the + * dynamic array * - darray_sphin_surface_ptr_size_get => returns the number of elements * (size_t) of the dynamic array * - darray_sphin_surface_ptr_data_get => returns the array itself @@ -79,7 +80,7 @@ geometry_compute_volume */ #define DARRAY_NAME sphin_geometry_ptr -/* Define the type of data stored in the dynamic array: pointers to sphin_geometry */ +/* Define the data type stored in the dynamic array: ptrs to sphin_geometry */ #define DARRAY_DATA struct sphin_geometry* /* @@ -91,8 +92,9 @@ geometry_compute_volume * declarations needed throughout the codebase. * * 2. Here, after defining DARRAY_NAME and DARRAY_DATA: - * - This triggers the preprocessor to generate a type-specific implementation - * of the dynamic array for 'struct sphin_geometry*' based on the provided macros. + * - This triggers the preprocessor to generate a type-specific + * implementation of the dynamic array for 'struct sphin_geometry*' based + * on the provided macros. */ #include <rsys/dynamic_array.h> diff --git a/src/sphin_main.c b/src/sphin_main.c @@ -25,10 +25,10 @@ #define _POSIX_C_SOURCE 200112L /* for getopt support */ #include "sphin.h" -#include "sphin_config.h" #include <rsys/cstr.h> #include <rsys/mem_allocator.h> +#include <rsys/rsys.h> #include <stdio.h> #include <stdlib.h> diff --git a/src/sphin_prop_rad.c b/src/sphin_prop_rad.c @@ -23,17 +23,16 @@ * along with this program. If not, see <http://www.gnu.org/licenses/>. */ #define _POSIX_C_SOURCE 200112L /* for strtok_r support */ -#include "sphin.h" #include "sphin_c.h" #include "sphin_config.h" #include "sphin_prop_rad.h" #include "sphin_scatterer.h" #include "sphin_volume.h" -#include <rsys/cstr.h> /* str_to_double */ +#include <rsys/mem_allocator.h> #include <rsys/ref_count.h> +#include <rsys/rsys.h> #include <rsys/str.h> -#include <rsys/text_reader.h> /******************************************************************************* * Helper functions @@ -98,9 +97,9 @@ release_prop_rad ******************************************************************************/ res_T parse_prop_rad - (struct sphin_volume* volume, - struct txtrdr* txtrdr, - char* value) + (struct sphin_volume* volume, + struct txtrdr* txtrdr, + char* value) { char* name = NULL; char* name_start = NULL; @@ -149,8 +148,8 @@ parse_prop_rad switch(prop_rad_type) { case SPHIN_PROP_RAD_BOLTZMANN: - break; /* TODO Parse prop rad coefficients */ + break; case SPHIN_PROP_RAD_SCATTERER: res = parse_scatterer(prop_rad, txtrdr); @@ -205,8 +204,8 @@ sphin_prop_rad_ref_put res_T sphin_prop_rad_get_name - (struct sphin_prop_rad* prop_rad, - char** name) + (struct sphin_prop_rad* prop_rad, + char** name) { if (NULL == prop_rad || NULL == name) { return RES_BAD_ARG; diff --git a/src/sphin_prop_rad.h b/src/sphin_prop_rad.h @@ -25,13 +25,12 @@ #ifndef SPHIN_PROP_RAD_H #define SPHIN_PROP_RAD_H -#include "sphin.h" - #include <rsys/str.h> #include <rsys/dynamic_array.h> #include <rsys/ref_count.h> #include <rsys/rsys.h> +struct sphin_volume; struct txtrdr; struct sphin_prop_rad{ @@ -52,8 +51,8 @@ parse_prop_rad /* Generate the dynamic array of pointers for the structure sphin_prop_rad * * Refer to sphin_geometry.h to a more detailed explanation on this */ -#define DARRAY_NAME sphin_prop_rad_ptr/* Prefix for api functions and structures: - darray_sphin_prop_rad_ptr */ +#define DARRAY_NAME sphin_prop_rad_ptr /* Prefix for api functions and + structs: darray_sphin_prop_rad_ptr */ #define DARRAY_DATA struct sphin_prop_rad* /* Generate the code */ diff --git a/src/sphin_refractive_index.c b/src/sphin_refractive_index.c @@ -23,11 +23,15 @@ * along with this program. If not, see <http://www.gnu.org/licenses/>. */ #define _POSIX_C_SOURCE 200112L /* for strtok_r support */ +#include "sphin.h" #include "sphin_c.h" #include "sphin_config.h" #include "sphin_refractive_index.h" #include "sphin_spectral_property.h" +#include <rsys/mem_allocator.h> +#include <rsys/ref_count.h> +#include <rsys/str.h> #include <rsys/text_reader.h> /******************************************************************************* @@ -44,7 +48,8 @@ refractive_index_create ASSERT(NULL != out_refractive_index); ASSERT(NULL != sphin); - refr_ind = MEM_CALLOC(sphin->allocator, 1, sizeof(struct sphin_refractive_index)); + refr_ind = MEM_CALLOC + (sphin->allocator, 1, sizeof(struct sphin_refractive_index)); if (NULL == refr_ind) { res = RES_MEM_ERR; goto error; } ref_init(&refr_ind->ref); SPHIN(ref_get(sphin)); diff --git a/src/sphin_refractive_index.h b/src/sphin_refractive_index.h @@ -25,10 +25,11 @@ #ifndef SPHIN_REFRACTIVE_INDEX_H #define SPHIN_REFRACTIVE_INDEX_H -#include "sphin.h" -#include "sphin_prop_rad.h" - #include <rsys/ref_count.h> +#include <rsys/rsys.h> + +struct sphin; +struct txtrdr; struct sphin_refractive_index { struct sphin_spectral_property* n_real; @@ -44,5 +45,4 @@ parse_refractive_index struct txtrdr* txtrdr, struct sphin_refractive_index** out_refractive_index); - #endif /* SPHIN_REFRACTIVE_INDEX_H */ diff --git a/src/sphin_scatterer.c b/src/sphin_scatterer.c @@ -31,7 +31,9 @@ #include "sphin_spectral_property.h" #include <rsys/cstr.h> /* str_to_double */ +#include <rsys/mem_allocator.h> #include <rsys/ref_count.h> +#include <rsys/rsys.h> #include <rsys/str.h> #include <rsys/text_reader.h> @@ -39,11 +41,9 @@ struct sphin_scatterer{ double concentration; struct sphin_spectral_property* abs_cross_sec; - /* TODO - * struct sca_cross_sec sca_cross_sec; - * struct mie* mie; + /* TODO struct sphin_spectral_property* sca_cross_sec; * struct phase_fn* phase_fn; - * */ + * struct mie* mie; */ struct sphin* sphin; ref_T ref; @@ -101,9 +101,9 @@ release_scatterer static res_T parse_concentration - (struct sphin_scatterer* scatterer, - struct txtrdr* txtrdr, - char* value) + (struct sphin_scatterer* scatterer, + struct txtrdr* txtrdr, + char* value) { char* concentration_val = NULL; char* concentration_unit = NULL; @@ -182,7 +182,7 @@ parse_abs_cross_sec if (NULL == value) { res = RES_BAD_ARG; goto error; } token = strtok_r(value, " \t", &token_ptr); - while (token != NULL && token_count < 5) { + while (token != NULL && token_count < 3) { tokens[token_count++] = trim_keyword(token); token = strtok_r(NULL, " \t", &token_ptr); } @@ -205,8 +205,6 @@ parse_abs_cross_sec (&scatterer->abs_cross_sec->wavelengths, spectral_unit); if (RES_OK != res) { goto error; } - /* TODO Convert property according to unit */ - res = txtrdr_read_line(txtrdr); if (RES_OK != res) { goto error; } @@ -218,8 +216,8 @@ error: static res_T parse_tabulated_cross_sections - (struct sphin_scatterer* scatterer, - struct txtrdr* txtrdr) + (struct sphin_scatterer* scatterer, + struct txtrdr* txtrdr) { char* keyword = NULL; char* token = NULL; @@ -246,14 +244,6 @@ parse_tabulated_cross_sections if (0 == strcmp(keyword, "abs_cross_sec")){ res = parse_abs_cross_sec(scatterer, txtrdr, token_ptr); } - /* TODO - * if (0 == strcmp(keyword, "sca_cross_sec")){ - * res = parse_sca_cross_sec(scatterer, txtrdr, token_ptr); - * } - * if (0 == strcmp(keyword, "phase_fn")){ - * res = parse_phase_fn(scatterer, txtrdr, token_ptr); - * } - */ else { break; } @@ -269,9 +259,9 @@ error: static res_T parse_cross_sections - (struct sphin_scatterer* scatterer, - struct txtrdr* txtrdr, - char* value) + (struct sphin_scatterer* scatterer, + struct txtrdr* txtrdr, + char* value) { char* type = NULL; char* token_ptr = NULL; @@ -336,7 +326,6 @@ parse_scatterer res = parse_concentration(scatterer, txtrdr, token); } else if (0 == strcmp(keyword, "cross_sections")){ - /* TODO Parse cross sections */ res = parse_cross_sections(scatterer, txtrdr, token); } else { diff --git a/src/sphin_scatterer.h b/src/sphin_scatterer.h @@ -25,9 +25,6 @@ #ifndef SPHIN_SCATTERER_H #define SPHIN_SCATTERER_H -#include "sphin.h" - -#include <rsys/dynamic_array.h> #include <rsys/rsys.h> struct sphin_prop_rad; diff --git a/src/sphin_sensor.c b/src/sphin_sensor.c @@ -26,7 +26,7 @@ #include "sphin_sensor.h" #include <rsys/cstr.h> -#include <rsys/ref_count.h> +#include <rsys/rsys.h> #include <rsys/str.h> #include <rsys/text_reader.h> diff --git a/src/sphin_sensor.h b/src/sphin_sensor.h @@ -27,7 +27,6 @@ #include <rsys/rsys.h> -struct sphin_sensor_surface; struct txtrdr; extern LOCAL_SYM res_T diff --git a/src/sphin_sensor_surface.c b/src/sphin_sensor_surface.c @@ -29,8 +29,9 @@ #include "sphin_sensor.h" #include "sphin_sensor_surface.h" -#include <rsys/cstr.h> +#include <rsys/mem_allocator.h> #include <rsys/ref_count.h> +#include <rsys/rsys.h> #include <rsys/str.h> #include <rsys/text_reader.h> @@ -61,7 +62,8 @@ sensor_surface_create ASSERT(NULL != name); ASSERT('\0' != name[0]); /* Name can't be empty */ - sensor_surface = MEM_CALLOC(sphin->allocator, 1, sizeof(struct sphin_sensor_surface)); + sensor_surface = MEM_CALLOC + (sphin->allocator, 1, sizeof(struct sphin_sensor_surface)); if (NULL == sensor_surface) { res = RES_MEM_ERR; goto error; } ref_init(&sensor_surface->ref); SPHIN(ref_get(sphin)); diff --git a/src/sphin_sensor_surface.h b/src/sphin_sensor_surface.h @@ -27,6 +27,7 @@ #include <rsys/rsys.h> +struct sphin; struct sphin_sensor_surface; struct txtrdr; diff --git a/src/sphin_sensor_volume.c b/src/sphin_sensor_volume.c @@ -30,7 +30,9 @@ #include "sphin_sensor_volume.h" #include <rsys/cstr.h> +#include <rsys/mem_allocator.h> #include <rsys/ref_count.h> +#include <rsys/rsys.h> #include <rsys/str.h> #include <rsys/text_reader.h> @@ -61,7 +63,8 @@ sensor_volume_create ASSERT(NULL != name); ASSERT('\0' != name[0]); /* Name can't be empty */ - sensor_volume = MEM_CALLOC(sphin->allocator, 1, sizeof(struct sphin_sensor_volume)); + sensor_volume = MEM_CALLOC + (sphin->allocator, 1, sizeof(struct sphin_sensor_volume)); if (NULL == sensor_volume) { res = RES_MEM_ERR; goto error; } ref_init(&sensor_volume->ref); SPHIN(ref_get(sphin)); diff --git a/src/sphin_sensor_volume.h b/src/sphin_sensor_volume.h @@ -27,6 +27,7 @@ #include <rsys/rsys.h> +struct sphin; struct sphin_sensor_volume; struct txtrdr; diff --git a/src/sphin_source_surface.c b/src/sphin_source_surface.c @@ -32,7 +32,9 @@ #include <rsys/cstr.h> #include <rsys/double3.h> +#include <rsys/mem_allocator.h> #include <rsys/ref_count.h> +#include <rsys/rsys.h> #include <rsys/str.h> #include <rsys/text_reader.h> @@ -67,7 +69,8 @@ source_surface_create ref_init(&source->ref); SPHIN(ref_get(sphin)); source->sphin = sphin; - source->direction_distribution = SPHIN_SOURCE_SURFACE_DIRECTION_DISTRIBUTION_NULL; + source->direction_distribution = + SPHIN_SOURCE_SURFACE_DIRECTION_DISTRIBUTION_NULL; source->flux_density = SPHIN_SOURCE_SURFACE_FLUX_DENSITY_NULL; str_init(sphin->allocator, &source->name); @@ -132,7 +135,7 @@ parse_collim_direction_distribution { char* str_direction = NULL; char* token_ptr = NULL; - double direction[3]; + double direction[3] = {0}; res_T res = RES_OK; (void)txtrdr; @@ -148,8 +151,6 @@ parse_collim_direction_distribution direction[0] = direction[1] = direction[2] = 0; } else{ - /* TODO implement parsing of a vector, taking into account the formatting - * in the input file to be decided */ res = RES_BAD_ARG; goto error; } @@ -354,8 +355,8 @@ parse_flux_density token = strtok_r(NULL, " \t", &token_ptr); } - /* The number of tokens must be either 2 (gray source) or 5 (read from file) */ - if (token_count != 2 && token_count != 5) { res = RES_BAD_ARG; goto error; } + /* The number of tokens must be 5 */ + if (token_count != 5) { res = RES_BAD_ARG; goto error; } /* Parse flux density value */ str_flux_density = tokens[0]; @@ -369,31 +370,29 @@ parse_flux_density if (NULL == flux_density_unit){ res = RES_BAD_ARG; goto error; } res = parse_flux_density_unit(source, txtrdr, flux_density_unit); - if (RES_OK != res){ goto error; } + if (RES_OK != res) { goto error; } - if (token_count == 5) { - filename = tokens[2]; - if (NULL == filename){ res = RES_BAD_ARG; goto error; } + filename = tokens[2]; + if (NULL == filename){ res = RES_BAD_ARG; goto error; } - spectral_unit = tokens[3]; - if (NULL == spectral_unit){ res = RES_BAD_ARG; goto error; } + spectral_unit = tokens[3]; + if (NULL == spectral_unit){ res = RES_BAD_ARG; goto error; } - property_unit = tokens[4]; - if (NULL == property_unit){ res = RES_BAD_ARG; goto error; } + property_unit = tokens[4]; + if (NULL == property_unit){ res = RES_BAD_ARG; goto error; } - res = parse_spectral_property - (source->sphin, filename, &source->flux_density.emission_spectrum); - if (RES_OK != res) { goto error; } + res = parse_spectral_property + (source->sphin, filename, &source->flux_density.emission_spectrum); + if (RES_OK != res) { goto error; } - /* Wavelengths will be in nm after conversion */ - res = convert_wavelengths - (&source->flux_density.emission_spectrum->wavelengths, spectral_unit); - if (RES_OK != res) { goto error; } + /* Wavelengths will be in nm after conversion */ + res = convert_wavelengths + (&source->flux_density.emission_spectrum->wavelengths, spectral_unit); + if (RES_OK != res) { goto error; } - /* Normalize spectrum */ - res = normalize_spectrum(source->flux_density.emission_spectrum); - if (RES_OK != res) { goto error; } - } + /* Normalize spectrum */ + res = normalize_spectrum(source->flux_density.emission_spectrum); + if (RES_OK != res) { goto error; } res = txtrdr_read_line(txtrdr); if (RES_OK != res) { goto error; } diff --git a/src/sphin_source_surface.h b/src/sphin_source_surface.h @@ -27,7 +27,8 @@ #include <rsys/rsys.h> -struct sphin_source; +struct sphin; +struct sphin_source_surface; struct txtrdr; extern LOCAL_SYM res_T diff --git a/src/sphin_spectral_property.c b/src/sphin_spectral_property.c @@ -29,9 +29,12 @@ #include <rsys/algorithm.h> #include <rsys/cstr.h> -#include <rsys/double3.h> +#include <rsys/mem_allocator.h> +#include <rsys/ref_count.h> #include <rsys/text_reader.h> -#include <star/sstl.h> + +#include <stdio.h> +#include <errno.h> /******************************************************************************* * Helper functions @@ -206,7 +209,7 @@ exit: *out_property = property; return res; error: - if( NULL != property) { + if ( NULL != property) { SPHIN(spectral_property_ref_put(property)); property = NULL; } diff --git a/src/sphin_spectral_property.h b/src/sphin_spectral_property.h @@ -25,15 +25,12 @@ #ifndef SPHIN_SPECTRAL_PROPERTY_H #define SPHIN_SPECTRAL_PROPERTY_H -#include "sphin.h" - -#include <rsys/dynamic_array.h> #include <rsys/dynamic_array_double.h> -#include <rsys/dynamic_array_size_t.h> #include <rsys/ref_count.h> +#include <rsys/rsys.h> #include <rsys/str.h> -struct mem_allocator; +struct sphin; struct sphin_spectral_property { /* Property data */ @@ -57,5 +54,4 @@ convert_wavelengths (struct darray_double* wavelengths, char* spectral_unit); - #endif /* SPHIN_SPECTRAL_PROPERTY_H */ diff --git a/src/sphin_surface.c b/src/sphin_surface.c @@ -32,17 +32,22 @@ #include "sphin_source_surface.h" #include "sphin_surface.h" -#include <rsys/cstr.h> +#include <rsys/mem_allocator.h> #include <rsys/ref_count.h> +#include <rsys/rsys.h> #include <rsys/str.h> #include <rsys/text_reader.h> +struct sphin_brdf; +struct sphin_sensor_surface; +struct sphin_source_surface; + struct sphin_surface { struct str name; struct sphin* sphin; struct sphin_brdf* brdf; - struct darray_sphin_geometry_ptr geometries; /* dynamic array of struct geometry. see - rsys/dynamic_array.h */ + struct darray_sphin_geometry_ptr geometries; /* dynamic array of struct + geometry. see rsys/dynamic_array.h */ struct sphin_sensor_surface* sensor_surface; struct sphin_source_surface* source_surface; ref_T ref; @@ -151,12 +156,12 @@ parse_geometry ASSERT(NULL != surface); ASSERT(NULL != txtrdr); - if(NULL == value) {res = RES_BAD_ARG; goto error; } + if (NULL == value) {res = RES_BAD_ARG; goto error; } res = geometry_parse(surface->sphin, value, &geom); if (RES_OK != res) { goto error; } - /* Append a new element (geom) to the end of the volume->geometries dynamic array */ + /* Append a new element to the end of the volume->geometries dynamic array */ res = darray_sphin_geometry_ptr_push_back(&surface->geometries, &geom); if (RES_OK != res) { goto error; } @@ -230,7 +235,8 @@ parse_surface * check if there is only tabs and spaces after : */ token = strtok_r(NULL, " \t", &token_ptr); if (NULL != token) { res = RES_BAD_ARG; goto error; } - res = parse_sensor_surface(surface->sphin, txtrdr, name, &surface->sensor_surface); + res = parse_sensor_surface + (surface->sphin, txtrdr, name, &surface->sensor_surface); } else { break; @@ -280,8 +286,8 @@ sphin_surface_ref_put res_T sphin_surface_get_name - (struct sphin_surface* surface, - char** name) + (struct sphin_surface* surface, + char** name) { if (NULL == surface || NULL == name) { return RES_BAD_ARG; @@ -358,7 +364,8 @@ sphin_surface_get_geometry return RES_BAD_ARG; } - *geometry = darray_sphin_geometry_ptr_data_get(&surface->geometries)[igeometry]; + *geometry = darray_sphin_geometry_ptr_data_get + (&surface->geometries)[igeometry]; return RES_OK; } @@ -374,7 +381,8 @@ sphin_surface_source_get_power size_t i = 0; struct sphin_geometry* geometry = NULL; struct sphin_source_surface* source_surface = NULL; - struct sphin_source_surface_flux_density density = SPHIN_SOURCE_SURFACE_FLUX_DENSITY_NULL; + struct sphin_source_surface_flux_density density = + SPHIN_SOURCE_SURFACE_FLUX_DENSITY_NULL; res_T res = RES_OK; source_surface = surface->source_surface; diff --git a/src/sphin_surface.h b/src/sphin_surface.h @@ -29,6 +29,7 @@ #include <rsys/rsys.h> struct sphin_config; +struct sphin_surface; struct txtrdr; extern LOCAL_SYM res_T @@ -40,8 +41,8 @@ parse_surface /* Generate the dynamic array of pointers for the structure sphin_surface * * Refer to sphin_geometry.h to a more detailed explanation on this */ -#define DARRAY_NAME sphin_surface_ptr /* Prefix for api functions and structures: - darray_sphin_surface_ptr */ +#define DARRAY_NAME sphin_surface_ptr /* Prefix for api functions and + structures: darray_sphin_surface_ptr */ #define DARRAY_DATA struct sphin_surface* /* Generate the code */ diff --git a/src/sphin_volume.c b/src/sphin_volume.c @@ -32,11 +32,14 @@ #include "sphin_sensor_volume.h" #include "sphin_volume.h" -#include <rsys/cstr.h> /* str_to_double */ +#include <rsys/mem_allocator.h> #include <rsys/ref_count.h> +#include <rsys/rsys.h> #include <rsys/str.h> #include <rsys/text_reader.h> +struct sphin_sensor_volume; + /******************************************************************************* * Helper functions ******************************************************************************/ @@ -149,7 +152,7 @@ parse_geometry res = geometry_parse(volume->sphin, value, &geom); if (RES_OK != res) { goto error; } - /* Append a new element (geom) to the end of the volume->geometries dynamic array */ + /* Append a new element to the end of the volume->geometries dynamic array */ res = darray_sphin_geometry_ptr_push_back(&volume->geometries, &geom); if (RES_OK != res) { goto error; } @@ -278,8 +281,8 @@ sphin_volume_ref_put res_T sphin_volume_get_name - (struct sphin_volume* volume, - char** name) + (struct sphin_volume* volume, + char** name) { if (NULL == volume || NULL == name) { return RES_BAD_ARG; @@ -354,7 +357,8 @@ sphin_volume_get_geometry return RES_BAD_ARG; } - *geometry = darray_sphin_geometry_ptr_data_get(&volume->geometries)[igeometry]; + *geometry = darray_sphin_geometry_ptr_data_get + (&volume->geometries)[igeometry]; return RES_OK; } diff --git a/src/sphin_volume.h b/src/sphin_volume.h @@ -28,10 +28,10 @@ #include "sphin_geometry.h" #include "sphin_prop_rad.h" -#include <rsys/ref_count.h> -#include <rsys/str.h> #include <rsys/dynamic_array.h> +#include <rsys/ref_count.h> #include <rsys/rsys.h> +#include <rsys/str.h> struct sphin_config; struct txtrdr; @@ -41,8 +41,8 @@ struct sphin_volume { struct sphin_refractive_index* refractive_index; struct sphin_sensor_volume* sensor_volume; struct darray_sphin_prop_rad_ptr prop_rads; - struct darray_sphin_geometry_ptr geometries; /* dynamic array of struct geometry. see - rsys/dynamic_array.h */ + struct darray_sphin_geometry_ptr geometries; /* dynamic array of struct + geometry. see rsys/dynamic_array.h */ struct sphin* sphin; ref_T ref; }; diff --git a/src/test_sphin.c b/src/test_sphin.c @@ -26,6 +26,9 @@ #include "test_sphin_utils.h" #include <rsys/logger.h> +#include <rsys/mem_allocator.h> +#include <rsys/rsys.h> + #include <stdio.h> static void diff --git a/src/test_sphin_load_geometry.c b/src/test_sphin_load_geometry.c @@ -26,8 +26,12 @@ #include <rsys/math.h> #include <rsys/mem_allocator.h> + +#include <stdio.h> #include <string.h> +struct sphin; + static void write_stl_test_files (void) diff --git a/src/test_sphin_load_prop_rad.c b/src/test_sphin_load_prop_rad.c @@ -26,8 +26,12 @@ #include <rsys/math.h> #include <rsys/mem_allocator.h> +#include <rsys/rsys.h> + +#include <stdio.h> #include <string.h> +struct sphin; static void write_prop_rad_test_files diff --git a/src/test_sphin_load_source.c b/src/test_sphin_load_source.c @@ -26,8 +26,13 @@ #include <rsys/math.h> #include <rsys/mem_allocator.h> +#include <rsys/rsys.h> + +#include <stdio.h> #include <string.h> +struct sphin; + static void write_stl_test_files (void) @@ -90,17 +95,17 @@ test_source_api fprintf(fp, "\t\t surface : \"surface name\"\n"); /* Source 0 */ fprintf(fp, "\tgeometry: FRONT test_0.stl\t\n"); fprintf(fp, "\tsource:#commentaire\n"); - fprintf(fp, "\tflux_density: 200e-6 mol/m^2/s \t\n"); + fprintf(fp, "\tflux_density: 200e-6 mol/m^2/s source_spec.txt nm nm^-1 \t\n"); fprintf(fp, "\tdirection: LAMBERT\n"); fprintf(fp, "\t\t surface : \"surface name 2\"\n"); /* Source 1 */ fprintf(fp, "\tgeometry: BACK test_0.stl\t\n"); fprintf(fp, "\tsource:\t #commentaire\n"); - fprintf(fp, "\tflux_density: 1e3 umol/m^2/s source_spec.txt nm unit\t\n"); + fprintf(fp, "\tflux_density: 1e3 umol/m^2/s source_spec.txt nm nm^-1\t\n"); fprintf(fp, "\tdirection: COLLIM NORMAL\n"); fprintf(fp, "\t\t surface : \"surface name 3\"\n"); /* Source 2 */ fprintf(fp, "\tgeometry: BACK test_0.stl\t\n"); fprintf(fp, "\tsource:\t #commentaire\n"); - fprintf(fp, "\tflux_density: 200e3 mW/m^2\t\n"); + fprintf(fp, "\tflux_density: 200e3 mW/m^2 source_spec.txt nm nm^-1\n"); fprintf(fp, "\tdirection: COS_POW_N 1\n"); fclose(fp); @@ -112,19 +117,21 @@ test_source_api CHK(sphin_surface_get_geometry_count(NULL, &ngeometries) == RES_BAD_ARG); CHK(sphin_surface_get_geometry_count(surface, &ngeometries) == RES_OK); CHK(sphin_surface_get_source(surface, &source) == RES_OK); - CHK(sphin_source_surface_get_direction_distribution(NULL, &dir_dist) == RES_BAD_ARG); - CHK(sphin_source_surface_get_direction_distribution(source, NULL) == RES_BAD_ARG); - CHK(sphin_source_surface_get_direction_distribution(source, &dir_dist) == RES_OK); + CHK(sphin_source_surface_get_direction_distribution + (NULL, &dir_dist) == RES_BAD_ARG); + CHK(sphin_source_surface_get_direction_distribution + (source, NULL) == RES_BAD_ARG); + CHK(sphin_source_surface_get_direction_distribution + (source, &dir_dist) == RES_OK); CHK(dir_dist.type == SPHIN_SOURCE_DIRECTION_ISOTROPIC); - CHK(dir_dist.cos_pow_n.collimation_degree == - SPHIN_SOURCE_SURFACE_DIRECTION_DISTRIBUTION_COS_POW_N_NULL.collimation_degree); CHK(dir_dist.collim.direction[0] == SPHIN_SOURCE_SURFACE_DIRECTION_DISTRIBUTION_COLLIM_NULL.direction[0]); CHK(dir_dist.collim.direction[1] == SPHIN_SOURCE_SURFACE_DIRECTION_DISTRIBUTION_COLLIM_NULL.direction[1]); CHK(dir_dist.collim.direction[2] == SPHIN_SOURCE_SURFACE_DIRECTION_DISTRIBUTION_COLLIM_NULL.direction[2]); - CHK(sphin_source_surface_get_flux_density(NULL, &flux_density) == RES_BAD_ARG); + CHK(sphin_source_surface_get_flux_density + (NULL, &flux_density) == RES_BAD_ARG); CHK(sphin_source_surface_get_flux_density(source, NULL) == RES_BAD_ARG); CHK(sphin_source_surface_get_flux_density(source, &flux_density) == RES_OK); CHK(eq_eps(flux_density.flux_density, 200, 1e-15)); @@ -136,24 +143,32 @@ test_source_api CHK(sphin_config_get_surface(config, 1, &surface) == RES_OK); CHK(sphin_surface_get_source(surface, &source) == RES_OK); - CHK(sphin_source_surface_get_direction_distribution(source, &dir_dist) == RES_OK); + CHK(sphin_source_surface_get_direction_distribution + (source, &dir_dist) == RES_OK); CHK(dir_dist.type == SPHIN_SOURCE_DIRECTION_COLLIM); - CHK(dir_dist.cos_pow_n.collimation_degree == - SPHIN_SOURCE_SURFACE_DIRECTION_DISTRIBUTION_COS_POW_N_NULL.collimation_degree); CHK(dir_dist.collim.direction[0] == 0); CHK(dir_dist.collim.direction[1] == 0); CHK(dir_dist.collim.direction[2] == 0); CHK(sphin_source_surface_get_flux_density(source, &flux_density) == RES_OK); CHK(eq_eps(flux_density.flux_density, 1000, 1e-15)); CHK(flux_density.unit == SPHIN_PHOTON_UNIT_MOL); - CHK(sphin_spectral_property_ref_get(flux_density.emission_spectrum) == RES_OK); - CHK(sphin_spectral_property_ref_put(flux_density.emission_spectrum) == RES_OK); - CHK(sphin_spectral_property_get_desc(flux_density.emission_spectrum, &emission_desc) == RES_OK); + CHK(sphin_spectral_property_ref_get + (flux_density.emission_spectrum) == RES_OK); + CHK(sphin_spectral_property_ref_put + (flux_density.emission_spectrum) == RES_OK); + CHK(sphin_spectral_property_get_desc + (flux_density.emission_spectrum, &emission_desc) == RES_OK); CHK(sphin_spectral_property_interpolate_at_wavelength - (flux_density.emission_spectrum, 100, SPHIN_INTERPOLATION_LINEAR, &value) == RES_OK); + (flux_density.emission_spectrum, + 100, + SPHIN_INTERPOLATION_LINEAR, + &value) == RES_OK); CHK(eq_eps(value, 1./750, 1e-15)); CHK(sphin_spectral_property_interpolate_at_wavelength - (flux_density.emission_spectrum, 175, SPHIN_INTERPOLATION_LINEAR, &value) == RES_OK); + (flux_density.emission_spectrum, + 175, + SPHIN_INTERPOLATION_LINEAR, + &value) == RES_OK); CHK(eq_eps(value, 1.75/750, 1e-15)); CHK(eq_eps(emission_desc.wavelengths[2], 300, 1e-15)); CHK(eq_eps(emission_desc.values[2], 3./750, 1e-15)); @@ -161,7 +176,8 @@ test_source_api CHK(sphin_config_get_surface(config, 2, &surface) == RES_OK); CHK(sphin_surface_get_source(surface, &source) == RES_OK); - CHK(sphin_source_surface_get_direction_distribution(source, &dir_dist) == RES_OK); + CHK(sphin_source_surface_get_direction_distribution + (source, &dir_dist) == RES_OK); CHK(dir_dist.type == SPHIN_SOURCE_DIRECTION_COS_POW_N); CHK(eq_eps(dir_dist.cos_pow_n.collimation_degree, 1, 1e-15)); CHK(dir_dist.collim.direction[0] == @@ -171,7 +187,8 @@ test_source_api CHK(dir_dist.collim.direction[2] == SPHIN_SOURCE_SURFACE_DIRECTION_DISTRIBUTION_COLLIM_NULL.direction[2]); CHK(sphin_source_surface_get_flux_density(source, NULL) == RES_BAD_ARG); - CHK(sphin_source_surface_get_flux_density(NULL, &flux_density) == RES_BAD_ARG); + CHK(sphin_source_surface_get_flux_density + (NULL, &flux_density) == RES_BAD_ARG); CHK(sphin_source_surface_get_flux_density(source, &flux_density) == RES_OK); CHK(eq_eps(flux_density.flux_density, 200, 1e-15)); CHK(sphin_surface_source_get_power(surface, &power) == RES_OK); diff --git a/src/test_sphin_load_surface.c b/src/test_sphin_load_surface.c @@ -26,8 +26,13 @@ #include <rsys/math.h> #include <rsys/mem_allocator.h> +#include <rsys/rsys.h> + +#include <stdio.h> #include <string.h> +struct sphin; + static void write_stl_test_files (void) @@ -46,7 +51,8 @@ write_stl_test_files static const char* test1 = "solid my_solid\n" "endsolid my_solid\n"; - static const char* test2 = /* Bad geometry => sstl should return RES_BAD_ARG */ + static const char* test2 = /* Bad geometry => sstl should return + RES_BAD_ARG */ "solid\n" " facet normal 0.0 -1.0 0.0\n" " outer loop\n" @@ -140,10 +146,12 @@ test_surface_api CHK(sphin_brdf_get_type(brdf, &brdf_type) == RES_OK); CHK(brdf_type == SPHIN_BRDF_LAMBERT); CHK(sphin_brdf_lambertian_get_reflectivity(NULL, NULL) == RES_BAD_ARG); - CHK(sphin_brdf_lambertian_get_reflectivity(NULL, &reflectivity) == RES_BAD_ARG); + CHK(sphin_brdf_lambertian_get_reflectivity + (NULL, &reflectivity) == RES_BAD_ARG); CHK(sphin_brdf_specular_get_reflectivity(brdf, &reflectivity) == RES_BAD_ARG); CHK(sphin_brdf_lambertian_get_reflectivity(NULL, NULL) == RES_BAD_ARG); - CHK(sphin_brdf_lambertian_get_reflectivity(NULL, &reflectivity) == RES_BAD_ARG); + CHK(sphin_brdf_lambertian_get_reflectivity + (NULL, &reflectivity) == RES_BAD_ARG); CHK(sphin_brdf_lambertian_get_reflectivity(brdf, NULL) == RES_BAD_ARG); CHK(sphin_brdf_lambertian_get_reflectivity(brdf, &reflectivity) == RES_OK); CHK(eq_eps(reflectivity, 0.1935, 1e-15)); @@ -153,7 +161,8 @@ test_surface_api CHK(sphin_surface_get_brdf(surface, &brdf) == RES_OK); CHK(sphin_brdf_get_type(brdf, &brdf_type) == RES_OK); CHK(brdf_type == SPHIN_BRDF_SPECULAR); - CHK(sphin_brdf_lambertian_get_reflectivity(brdf, &reflectivity) == RES_BAD_ARG); + CHK(sphin_brdf_lambertian_get_reflectivity + (brdf, &reflectivity) == RES_BAD_ARG); CHK(sphin_brdf_specular_get_reflectivity(NULL, NULL) == RES_BAD_ARG); CHK(sphin_brdf_specular_get_reflectivity(brdf, NULL) == RES_BAD_ARG); CHK(sphin_brdf_specular_get_reflectivity(NULL, &reflectivity) == RES_BAD_ARG); @@ -167,9 +176,12 @@ test_surface_api CHK(sphin_surface_get_sensor(surface, NULL) == RES_BAD_ARG); CHK(sphin_surface_get_sensor(surface, &sensor_surface) == RES_OK); CHK(sphin_sensor_surface_get_response_function(NULL, NULL) == RES_BAD_ARG); - CHK(sphin_sensor_surface_get_response_function(NULL, &response_function) == RES_BAD_ARG); - CHK(sphin_sensor_surface_get_response_function(sensor_surface, NULL) == RES_BAD_ARG); - CHK(sphin_sensor_surface_get_response_function(sensor_surface, &response_function) == RES_OK); + CHK(sphin_sensor_surface_get_response_function + (NULL, &response_function) == RES_BAD_ARG); + CHK(sphin_sensor_surface_get_response_function + (sensor_surface, NULL) == RES_BAD_ARG); + CHK(sphin_sensor_surface_get_response_function + (sensor_surface, &response_function) == RES_OK); CHK(eq_eps(response_function, 1, 1e-15)); CHK(sphin_surface_ref_get(surface) == RES_OK); CHK(sphin_surface_ref_get(surface) == RES_OK); diff --git a/src/test_sphin_load_volume.c b/src/test_sphin_load_volume.c @@ -26,8 +26,13 @@ #include <rsys/math.h> #include <rsys/mem_allocator.h> +#include <rsys/rsys.h> + +#include <stdio.h> #include <string.h> +struct sphin; + static void write_stl_test_files (void) @@ -46,7 +51,8 @@ write_stl_test_files static const char* test1 = "solid my_solid\n" "endsolid my_solid\n"; - static const char* test2 = /* Bad geometry => sstl should return RES_BAD_ARG */ + static const char* test2 = /* Bad geometry => sstl should + return RES_BAD_ARG */ "solid\n" " facet normal 0.0 -1.0 0.0\n" " outer loop\n" @@ -172,9 +178,12 @@ test_volume_api CHK(sphin_volume_get_sensor(volume, NULL) == RES_BAD_ARG); CHK(sphin_volume_get_sensor(volume, &sensor_volume) == RES_OK); CHK(sphin_sensor_volume_get_response_function(NULL, NULL) == RES_BAD_ARG); - CHK(sphin_sensor_volume_get_response_function(NULL, &response_function) == RES_BAD_ARG); - CHK(sphin_sensor_volume_get_response_function(sensor_volume, NULL) == RES_BAD_ARG); - CHK(sphin_sensor_volume_get_response_function(sensor_volume, &response_function) == RES_OK); + CHK(sphin_sensor_volume_get_response_function + (NULL, &response_function) == RES_BAD_ARG); + CHK(sphin_sensor_volume_get_response_function + (sensor_volume, NULL) == RES_BAD_ARG); + CHK(sphin_sensor_volume_get_response_function + (sensor_volume, &response_function) == RES_OK); CHK(eq_eps(response_function, 1, 1e-15)); CHK(sphin_volume_get_refractive_index(NULL, NULL) == RES_BAD_ARG); CHK(sphin_volume_get_refractive_index(NULL, &refr_ind) == RES_BAD_ARG); diff --git a/src/test_sphin_utils.h b/src/test_sphin_utils.h @@ -26,11 +26,14 @@ #define TEST_SPHIN_UTILS_H #include <rsys/mem_allocator.h> +#include <rsys/rsys.h> + +#include <stdio.h> static INLINE void check_memory_allocator(struct mem_allocator* allocator) { - if(MEM_ALLOCATED_SIZE(allocator)) { + if (MEM_ALLOCATED_SIZE(allocator)) { char dump[512]; MEM_DUMP(allocator, dump, sizeof(dump)/sizeof(char)); fprintf(stderr, "%s\n", dump);