Skip to content
Snippets Groups Projects
Commit c1d52c13 authored by Moritz Hanke's avatar Moritz Hanke
Browse files

improves help print output of weights2vtk tool

parent 774339e8
No related branches found
No related tags found
No related merge requests found
......@@ -569,11 +569,11 @@ void write_data_to_file(char const * filename, struct grid * src_grid,
free(points);
}
void interpret_grid_arg(struct grid_config * grid_config, char * arg, char * str) {
int interpret_grid_arg(struct grid_config * grid_config, char * arg, char * str) {
if (arg == NULL) {
fprintf(stderr, "-%c argument is missing\n", str[0]);
exit(EXIT_FAILURE);
return 1;
}
switch (grid_config->type) {
......@@ -581,7 +581,7 @@ void interpret_grid_arg(struct grid_config * grid_config, char * arg, char * str
grid_config->config.cube.n = atoi(arg);
if (grid_config->config.cube.n == 0) {
fprintf(stderr, "invalid N for cubed sphere %s grid\n", str);
exit(EXIT_FAILURE);
return 1;
}
break;
case CURVE:
......@@ -593,12 +593,37 @@ void interpret_grid_arg(struct grid_config * grid_config, char * arg, char * str
case NONE:
default:
fprintf(stderr, "invalid %s grid type\n", str);
exit(EXIT_FAILURE);
return 1;
}
return 0;
}
void print_help(char * command) {
fprintf(stderr, "Usage: %s -S src_grid_type -T tgt_grid_type "
"-s src_filename -t tgt_filename -w weight_filename "
"-o vtk_filename\n\n"
" grid_type can have the following values:\n"
" 'c', 'C': cubed sphere grid (instead of a "
"filename provide N, where\n"
" N = sqrt(n/6), with n being the "
"total number of cells\n"
" 'm', 'M': curvilinear grid\n"
" 'i', 'I': unstructured grid\n"
"\n"
"Example:\n"
" Configuration:\n"
" source grid type: unstructured\n"
" source grid file: src_grid.nc\n"
" target grid type: cubed sphere\n"
" target grid file: 100 (N instead of filename)\n"
" weight file name: weight_file.nc\n"
" vtk file name: weights.vtk\n"
" Command:\n"
" %s -S i -T c -s src_grid.nc -t 100 -w weight_file.nc "
"-o weights.vtk\n", command, command);
}
void parse_arguments(int argc, char ** argv,
struct grid_config * src_grid_config,
struct grid_config * tgt_grid_config,
......@@ -610,6 +635,8 @@ void parse_arguments(int argc, char ** argv,
*weight_filename = NULL;
*vtk_filename = NULL;
int error = 0;
char * src_arg = NULL;
char * tgt_arg = NULL;
......@@ -660,32 +687,38 @@ void parse_arguments(int argc, char ** argv,
break;
case '?':
default:
fprintf(stderr, "Usage: %s -S src_grid_type -T tgt_grid_type "
"-s src_filename -t tgt_filename -w weight_filename "
"-o vtk_filename\n\n"
" grid_type can have the following values:\n"
" 'c', 'C': cubed sphere grid (instead of a "
"filename provide N, where\n"
" N = sqrt(n/6), with n being the "
"total number of cells\n"
" 'm', 'M': curvilinear grid\n"
" 'i', 'I': unstructured grid\n", argv[0]);
exit(EXIT_FAILURE);
error = 1;
}
}
if (optind < argc) {
printf("non-option ARGV-elements: ");
while (optind < argc)
printf ("%s ", argv[optind++]);
printf("\n");
error = 1;
}
if (argc == 1) error = 1;
if (*weight_filename == NULL) {
if ((!error) && (*weight_filename == NULL)) {
fputs("weight_filename argument is missing\n", stderr);
exit(EXIT_FAILURE);
error = 1;
}
if (*vtk_filename == NULL) {
if ((!error) && (*vtk_filename == NULL)) {
fputs("vtk_filename argument is missing\n", stderr);
exit(EXIT_FAILURE);
error = 1;
}
interpret_grid_arg(src_grid_config, src_arg, "source");
interpret_grid_arg(tgt_grid_config, tgt_arg, "target");
if (!error)
error |= interpret_grid_arg(src_grid_config, src_arg, "source");
if (!error)
error |= interpret_grid_arg(tgt_grid_config, tgt_arg, "target");
if (error) {
print_help(argv[0]);
exit(EXIT_FAILURE);
}
}
struct grid * create_grid(struct grid_config grid_config) {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment