Consistent input parameters to examples
My suggestion is to use getopt
and/or getopt_long
(if you want long and short parameter flags, for example --file=
and -f
) to handle input parameters to the example programs. I find this C API a more robust method than parsing the command line with string comparison.
Here is a possible implementation for the particle advection example:
const char *usage = "\n"
"NAME\n"
" ParticleAdvection - VTK-m particle advection example\n"
"SYNOPSIS\n"
" %s [--help | -h] [-d dataset]\n"
" (-p num_seeds) (-s num_steps) (-l step_length)\n"
" (-t num_threads)\n"
"OVERVIEW\n"
" Exe is an example showing how to use the particle\n"
" advection filter in VTK-m.\n"
"OPTIONS\n"
" -h | --help\n"
" Display this help information, then exit.\n"
" -f | --file=dataset\n"
" Input data set. Mandatory argument.\n"
" -p | --seeds=num_seeds\n"
" Number of seeds. Default: 1000.\n"
" -s | --steps=max_steps\n"
" Max number of steps. Default: 1000.\n"
" -l | --length=step_length\n"
" Length of each step. Default: 0.5.\n"
" -t | --threads=num_threads\n"
" Number of threads to use. Default: 8.\n"
" -o | --out=output_name\n"
" Name of resulting output file. Default: output.vtk.\n"