commit b57d8024410225801fb051271e0c56eaefce9076
parent cb2666aef7a8041674d5424d6fd088795a725d64
Author: Vincent Forest <vincent.forest@meso-star.com>
Date: Mon, 20 Mar 2017 11:36:16 +0100
Fix the dump radiative path command line argument -p
Make the '-p' options obligatory and add a "default" option.
Diffstat:
3 files changed, 30 insertions(+), 15 deletions(-)
diff --git a/doc/cli b/doc/cli
@@ -6,7 +6,7 @@ solstice
-h # Short help and exit
-g <dump> # Switch in dump geometry
-o OUTPUT # defaulting to stdout if not defined
- -p [ <dump-radiative-path> ] # Switch in dump radiative paths mode
+ -p <dump-radiative-path> # Switch in dump radiative paths mode
-q # don't print a message if no INPUT is submitted
-n INTEGER # Realisations count
-r <rendering> # Switch in rendering mode
@@ -47,7 +47,7 @@ solstice -g format=obj:split-group=1
<dump-path-option>[:<dump-path-option> ... ]
<dump-path-option> ::=
- <sun-ray-len> | <inf-ray-len>
+ <sun-ray-len> | <inf-ray-len> | default
<sun-ray-len> ::=
srlen=REAL
diff --git a/src/solstice_args.c b/src/solstice_args.c
@@ -59,7 +59,7 @@ print_help(const char* program)
" -o OUTPUT write results to OUTPUT. If not defined, write results to\n"
" standard output.\n");
printf(
-" -p switch in dump radiative paths mode.\n");
+" -p <dump-paths> switch in dump radiative paths mode and configure it.\n");
printf(
" -q do not print the helper message when no FILE is submitted.\n");
printf(
@@ -429,6 +429,12 @@ parse_dump_paths_option(const char* str, struct solstice_args* args)
res_T res = RES_OK;
ASSERT(str && args);
+ if(!strcmp(str, "default")) {
+ args->infinite_ray_length = SOLSTICE_ARGS_DEFAULT.infinite_ray_length;
+ args->sun_ray_length = SOLSTICE_ARGS_DEFAULT.sun_ray_length;
+ goto exit;
+ }
+
if(strlen(str) >= sizeof(buf) - 1/*NULL char*/) {
fprintf(stderr,
"Could not duplicate the dump radiative paths option string `%s'.\n", str);
@@ -485,7 +491,6 @@ solstice_args_init(struct solstice_args* args, const int argc, char** argv)
*args = SOLSTICE_ARGS_DEFAULT;
- opterr = 0;
optind = 0;
while((opt = getopt(argc, argv, "D:fg:Hhn:o:p:qR:r:t:")) != -1) {
switch(opt) {
@@ -526,16 +531,6 @@ solstice_args_init(struct solstice_args* args, const int argc, char** argv)
res = cstr_to_uint(optarg, &args->nthreads);
if(res == RES_OK && !args->nthreads) res = RES_BAD_ARG;
break;
- case '?': /* Option with optionnal arguments */
- switch(optopt) {
- case 'p': args->dump_paths = 1; break;
- default:
- fprintf(stderr, "%s: option requires an argument -- '%c'\n",
- argv[0], optopt);
- res = RES_BAD_ARG;
- break;
- }
- break;
default: res = RES_BAD_ARG; break;
}
if(res != RES_OK) {
diff --git a/src/test_solstice_args.c b/src/test_solstice_args.c
@@ -579,7 +579,7 @@ test_dump_paths(void)
solstice_args_release(&args);
cmd_delete(cmd);
- cmd = cmd_create(0, "test", "-D", "0,90", "-p", NULL);
+ cmd = cmd_create(0, "test", "-D", "0,90", "-p", "default", NULL);
CHECK(solstice_args_init(&args, cmd_size(cmd), cmd), RES_OK);
CHECK(args.dump_paths, 1);
CHECK(args.infinite_ray_length, SOLSTICE_ARGS_DEFAULT.infinite_ray_length);
@@ -611,6 +611,22 @@ test_dump_paths(void)
solstice_args_release(&args);
cmd_delete(cmd);
+ cmd = cmd_create(0, "test", "-D", "0,90", "-p", "srlen=3.14:default", NULL);
+ CHECK(solstice_args_init(&args, cmd_size(cmd), cmd), RES_OK);
+ CHECK(args.dump_paths, 1);
+ CHECK(args.infinite_ray_length, SOLSTICE_ARGS_DEFAULT.infinite_ray_length);
+ CHECK(args.sun_ray_length, SOLSTICE_ARGS_DEFAULT.sun_ray_length);
+ solstice_args_release(&args);
+ cmd_delete(cmd);
+
+ cmd = cmd_create(0, "test", "-D", "0,90", "-p", "default:srlen=1:irlen=2:", NULL);
+ CHECK(solstice_args_init(&args, cmd_size(cmd), cmd), RES_OK);
+ CHECK(args.dump_paths, 1);
+ CHECK(args.sun_ray_length, 1);
+ CHECK(args.infinite_ray_length, 2);
+ solstice_args_release(&args);
+ cmd_delete(cmd);
+
cmd = cmd_create(0, "test", "-D", "0,90", "-p", "srlen=", NULL);
CHECK(solstice_args_init(&args, cmd_size(cmd), cmd), RES_BAD_ARG);
cmd_delete(cmd);
@@ -630,6 +646,10 @@ test_dump_paths(void)
cmd = cmd_create(0, "test", "-D", "0,90", "-p", "=abcd", NULL);
CHECK(solstice_args_init(&args, cmd_size(cmd), cmd), RES_BAD_ARG);
cmd_delete(cmd);
+
+ cmd = cmd_create(0, "test", "-D", "0,90", "-p", NULL);
+ CHECK(solstice_args_init(&args, cmd_size(cmd), cmd), RES_BAD_ARG);
+ cmd_delete(cmd);
}
int