star-gs

Literate program for a geometric sensitivity calculation
git clone git://git.meso-star.fr/star-gs.git
Log | Files | Refs | README | LICENSE

commit 1d8b14778254a10a3975a5c3844ad99c46838600
parent 36b64b0d8030fab05ea955a37b23959073a27c7c
Author: Vincent Forest <vincent.forest@meso-star.com>
Date:   Sun, 18 Apr 2021 22:01:14 +0200

Parse the slope geometry

Diffstat:
Msrc/sgs_args.c | 90+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++------
Msrc/sgs_geometry.h | 2+-
2 files changed, 85 insertions(+), 7 deletions(-)

diff --git a/src/sgs_args.c b/src/sgs_args.c @@ -39,19 +39,19 @@ print_help(void) printf("\n"); printf( -" -b <box-parameters:...>\n" -" define an axis aligned bounding box. Available box\n" -" parameters are:\n"); +" -b <box-params:...>\n" +" define an axis aligned bounding box (default)\n" +" Available box parameters are:\n"); printf( " low=x,y,z\n" -" defines the lower bound of the box\n" +" define the lower bound of the box\n" " (default: %g,%g,%g).\n", SGS_GEOMETRY_BOX_ARGS_DEFAULT.lower[0], SGS_GEOMETRY_BOX_ARGS_DEFAULT.lower[1], SGS_GEOMETRY_BOX_ARGS_DEFAULT.lower[2]); printf( " upp=x,y,z\n" -" defines the upper bound of the box\n" +" define the upper bound of the box\n" " (default: %g,%g,%g).\n", SGS_GEOMETRY_BOX_ARGS_DEFAULT.upper[0], SGS_GEOMETRY_BOX_ARGS_DEFAULT.upper[1], @@ -61,6 +61,28 @@ print_help(void) printf( " -h display this help and exit.\n"); printf( +" -s <slope-params:...>\n" +" define an axis aligned box whose +Z face is tilted\n" +" along the X axis. Available slope parameters are:\n"); + printf( +" low=x,y,z\n" +" define the lower bound (default: %g,%g,%g).\n", + SGS_GEOMETRY_SLOPE_ARGS_DEFAULT.lower[0], + SGS_GEOMETRY_SLOPE_ARGS_DEFAULT.lower[1], + SGS_GEOMETRY_SLOPE_ARGS_DEFAULT.lower[2]); + printf( +" upp=x,y\n" +" define the upper bound in the XY plane\n" +" (default: %g,%g).\n", + SGS_GEOMETRY_SLOPE_ARGS_DEFAULT.upper[0], + SGS_GEOMETRY_SLOPE_ARGS_DEFAULT.upper[1]); + printf( +" heights=h0,h1\n" +" define the start and end heights of the slope\n" +" (default: %g,%g).\n", + SGS_GEOMETRY_SLOPE_ARGS_DEFAULT.heights[0], + SGS_GEOMETRY_SLOPE_ARGS_DEFAULT.heights[1]); + printf( " -t nthreads hint on the number of threads to use. By default use\n" " as many threads as CPU cores.\n"); printf( @@ -121,6 +143,59 @@ error: goto exit; } +static res_T +parse_slope_parameters(const char* str, void* ptr) +{ + char buf[128]; + struct sgs_args_geometry* geom = ptr; + char* key; + char* val; + char* ctx; + size_t len; + res_T res = RES_OK; + ASSERT(ptr && str); + + if(strlen(str) >= sizeof(buf) -1/*NULL char*/) { + fprintf(stderr, SGS_LOG_ERROR_PREFIX + "Could not duplicate the slope option string `%s'.\n", str); + res = RES_MEM_ERR; + goto error; + } + strncpy(buf, str, sizeof(buf)); + + key = strtok_r(buf, "=", &ctx); + val = strtok_r(NULL, "", &ctx); + + geom->type = SGS_GEOMETRY_SLOPE; + + if(!strcmp(key, "low")) { + res = cstr_to_list_double(val, ',', geom->args.slope.lower, &len, 3); + if(res == RES_OK && len != 3) res = RES_BAD_ARG; + } else if(!strcmp(key, "upp")) { + res = cstr_to_list_double(val, ',', geom->args.slope.upper, &len, 2); + if(res == RES_OK && len != 2) res = RES_BAD_ARG; + } else if(!strcmp(key, "heights")) { + res = cstr_to_list_double(val, ',', geom->args.slope.heights, &len, 2); + if(res == RES_OK && len != 2) res = RES_BAD_ARG; + } else { + fprintf(stderr, SGS_LOG_ERROR_PREFIX + "Invalid slope parameter `%s'.\n", key); + res = RES_BAD_ARG; + goto error; + } + if(res != RES_OK) { + fprintf(stderr, SGS_LOG_ERROR_PREFIX + "Error parsing the value of the `%s' slope parameter: %s -- %s.\n", + key, val, res_to_cstr(res)); + goto error; + } + +exit: + return res; +error: + goto exit; +} + /******************************************************************************* * sgs_args API ******************************************************************************/ @@ -133,7 +208,7 @@ sgs_args_init(struct sgs_args* args, int argc, char** argv) *args = SGS_ARGS_DEFAULT; - while((opt = getopt(argc, argv, "b:dht:v")) != -1) { + while((opt = getopt(argc, argv, "b:dhs:t:v")) != -1) { switch(opt) { case 'b': res = cstr_parse_list(optarg, ':', parse_box_parameters, &args->geom); @@ -144,6 +219,9 @@ sgs_args_init(struct sgs_args* args, int argc, char** argv) sgs_args_release(args); args->quit = 1; break; + case 's': + res = cstr_parse_list(optarg, ':', parse_slope_parameters, &args->geom); + break; case 't': res = cstr_to_uint(optarg, &args->nthreads); if(res == RES_OK && !args->nthreads) res = RES_BAD_ARG; diff --git a/src/sgs_geometry.h b/src/sgs_geometry.h @@ -73,7 +73,7 @@ static const struct sgs_geometry_box_args SGS_GEOMETRY_BOX_ARGS_DEFAULT = * . . . . l--------o . . . . . . * lower */ struct sgs_geometry_slope_args { - double lower[2]; /* 2D lower bound in the XY plane */ + double lower[3]; /* 3D lower bound */ double upper[2]; /* 2D upper bound in the XY plane */ double heights[2]; /* The slope heights in Z along the X axis */ };