diff --git a/Makefile b/Makefile deleted file mode 100644 index b7e7c94..0000000 --- a/Makefile +++ /dev/null @@ -1,41 +0,0 @@ -# Compiler choice: - -# Gcc -CC = icc -CFLAGS = -O3 -ggdb - -MLIBS = -lm - -#QLIB = -L../qhull-2003.1/src/ -#QINC = -I../qhull-2003.1/src/ -QLIB = -L../qhull2002.1/src/ -QINC = -I../qhull2002.1/src/ - -############### - -all: vozinit voz1b1 voztie jozov - -jozov: jozov.o findrtop.o Makefile - $(CC) $(CFLAGS) -o jozov jozov.o findrtop.o $(MLIBS) -jozov.o: jozov.c Makefile - $(CC) $(CFLAGS) -c jozov.c -findrtop.o: findrtop.c Makefile - $(CC) $(CFLAGS) -c findrtop.c - -voz1b1: voz1b1.o readfiles.o vozutil.o voz.h Makefile - $(CC) -o voz1b1 $(CFLAGS) voz1b1.o readfiles.o vozutil.o -L. $(QLIB) -lqhull $(MLIBS) -voz1b1.o: voz1b1.c Makefile - $(CC) $(CFLAGS) $(QINC) -c voz1b1.c -vozutil.o: vozutil.c Makefile - $(CC) $(CFLAGS) $(QINC) -c vozutil.c - -vozinit: vozinit.o readfiles.o voz.h Makefile - $(CC) -o vozinit $(CFLAGS) vozinit.o readfiles.o -L. $(MLIBS) -vozinit.o: vozinit.c Makefile - $(CC) $(CFLAGS) -c vozinit.c $(QINC) - -voztie: voztie.o readfiles.o Makefile - $(CC) -o voztie $(CFLAGS) voztie.o readfiles.o -voztie.o: voztie.c Makefile - $(CC) $(CFLAGS) -c voztie.c - diff --git a/mytools/Makefile b/mytools/Makefile deleted file mode 100644 index 4e57705..0000000 --- a/mytools/Makefile +++ /dev/null @@ -1,55 +0,0 @@ -PROGS= showZobov buildObservedVoids - -CXX=g++ -CC=gcc - -include config.mk - -SOURCES= showZobov.cpp loadZobov.cpp zobovConf.c buildObservedVoids.cpp - -LIBS= $(LDFLAGS) - -all: $(PROGS) - -showZobov: showZobov.o loadZobov.o zobovConf.o - -testZobov: testZobov.o loadZobov.o - -buildObservedVoids: buildObservedVoids.o loadZobov.o buildObservedVoids_conf.o - -depend: $(SOURCES) - @echo "[DEPENDS] $^" - @$(CC) $(CPPFLAGS) -M -MM $^ > .mydepends - -distclean: clean - @rm -f .mydepends - -clean: - @rm -f *.o - @rm -f $(PROGS) - -.mydepends: $(SOURCES) - @touch .mydepends - @make depend - -%.prog: - @echo "[L] $@" - @$(CXX) -o $@ $^ $(LIBS) - -zobovConf.c zobovConf.h: showZobov.ggo Makefile - @echo "[OPT] $@" - @gengetopt -i $< -f zobovConf -a zobovConf_info -F zobovConf -C - -buildObservedVoids_conf.c buildObservedVoids_conf.h: buildObservedVoids.ggo Makefile - @echo "[OPT] $@" - @gengetopt -i $< -f buildObservedVoids_conf -a buildObservedVoids_info -F buildObservedVoids_conf -C - -%.o: %.c - @echo "[C] $< ..." - @$(CC) -c -o $@ $< $(CFLAGS) - -%.o: %.cpp - @echo "[C++] $< ..." - @$(CXX) -c -o $@ $< $(CXXFLAGS) - -include .mydepends diff --git a/mytools/buildObservedVoids_conf.c b/mytools/buildObservedVoids_conf.c deleted file mode 100644 index 7935daa..0000000 --- a/mytools/buildObservedVoids_conf.c +++ /dev/null @@ -1,1105 +0,0 @@ -/* - File autogenerated by gengetopt version 2.22.2 - generated with the following command: - gengetopt -i buildObservedVoids.ggo -f buildObservedVoids_conf -a buildObservedVoids_info -F buildObservedVoids_conf -C - - The developers of gengetopt consider the fixed text that goes in all - gengetopt output files to be in the public domain: - we make no copyright claims on it. -*/ - -/* If we use autoconf. */ -#ifdef HAVE_CONFIG_H -#include "config.h" -#endif - -#include -#include -#include - -#ifndef FIX_UNUSED -#define FIX_UNUSED(X) (void) (X) /* avoid warnings for unused params */ -#endif - -#include "getopt.h" - -#include "buildObservedVoids_conf.h" - -const char *buildObservedVoids_info_purpose = ""; - -const char *buildObservedVoids_info_usage = "Usage: buildObservedVoids [OPTIONS]..."; - -const char *buildObservedVoids_info_description = ""; - -const char *buildObservedVoids_info_help[] = { - " -h, --help Print help and exit", - " -V, --version Print version and exit", - " -d, --desc=STRING The description file name for the voids (jozov \n generated)", - " -p, --partzone=STRING Particles/Zones bind file", - " -v, --zonevoid=STRING Void/zone bind file (jozov generated)", - " -m, --minProba=DOUBLE Minimal probability to accept (default=`0.0')", - " --densityThreshold=DOUBLE Density threshold to consider a stable void \n (default=`-0.8')", - " -f, --configFile=STRING Configuration file", - " -o, --output=STRING Output file (default=`void_info.txt')", - " -g, --gridOutput=STRING 3d grid output of voids \n (default=`all_voids.nc')", - " -q, --quiet Quiet output (default=off)", - " --dumpVoids=STRING Dump the particles in void in a file", - " --dumpIds Dump particle ids (default=off)", - " --ramsesBase=STRING Base directory for ramses", - " --ramsesId=INT Ramses snapshot id", - " --dumpTree Dump the void tree (default=off)", - " --getTree Restore tree from file (default=off)", - 0 -}; - -typedef enum {ARG_NO - , ARG_FLAG - , ARG_STRING - , ARG_INT - , ARG_DOUBLE -} buildObservedVoids_conf_arg_type; - -static -void clear_given (struct buildObservedVoids_info *args_info); -static -void clear_args (struct buildObservedVoids_info *args_info); - -static int -buildObservedVoids_conf_internal (int argc, char * const *argv, struct buildObservedVoids_info *args_info, - struct buildObservedVoids_conf_params *params, const char *additional_error); - -static int -buildObservedVoids_conf_required2 (struct buildObservedVoids_info *args_info, const char *prog_name, const char *additional_error); -struct line_list -{ - char * string_arg; - struct line_list * next; -}; - -static struct line_list *cmd_line_list = 0; -static struct line_list *cmd_line_list_tmp = 0; - -static void -free_cmd_list(void) -{ - /* free the list of a previous call */ - if (cmd_line_list) - { - while (cmd_line_list) { - cmd_line_list_tmp = cmd_line_list; - cmd_line_list = cmd_line_list->next; - free (cmd_line_list_tmp->string_arg); - free (cmd_line_list_tmp); - } - } -} - - -static char * -gengetopt_strdup (const char *s); - -static -void clear_given (struct buildObservedVoids_info *args_info) -{ - args_info->help_given = 0 ; - args_info->version_given = 0 ; - args_info->desc_given = 0 ; - args_info->partzone_given = 0 ; - args_info->zonevoid_given = 0 ; - args_info->minProba_given = 0 ; - args_info->densityThreshold_given = 0 ; - args_info->configFile_given = 0 ; - args_info->output_given = 0 ; - args_info->gridOutput_given = 0 ; - args_info->quiet_given = 0 ; - args_info->dumpVoids_given = 0 ; - args_info->dumpIds_given = 0 ; - args_info->ramsesBase_given = 0 ; - args_info->ramsesId_given = 0 ; - args_info->dumpTree_given = 0 ; - args_info->getTree_given = 0 ; -} - -static -void clear_args (struct buildObservedVoids_info *args_info) -{ - FIX_UNUSED (args_info); - args_info->desc_arg = NULL; - args_info->desc_orig = NULL; - args_info->partzone_arg = NULL; - args_info->partzone_orig = NULL; - args_info->zonevoid_arg = NULL; - args_info->zonevoid_orig = NULL; - args_info->minProba_arg = 0.0; - args_info->minProba_orig = NULL; - args_info->densityThreshold_arg = -0.8; - args_info->densityThreshold_orig = NULL; - args_info->configFile_arg = NULL; - args_info->configFile_orig = NULL; - args_info->output_arg = gengetopt_strdup ("void_info.txt"); - args_info->output_orig = NULL; - args_info->gridOutput_arg = gengetopt_strdup ("all_voids.nc"); - args_info->gridOutput_orig = NULL; - args_info->quiet_flag = 0; - args_info->dumpVoids_arg = NULL; - args_info->dumpVoids_orig = NULL; - args_info->dumpIds_flag = 0; - args_info->ramsesBase_arg = NULL; - args_info->ramsesBase_orig = NULL; - args_info->ramsesId_orig = NULL; - args_info->dumpTree_flag = 0; - args_info->getTree_flag = 0; - -} - -static -void init_args_info(struct buildObservedVoids_info *args_info) -{ - - - args_info->help_help = buildObservedVoids_info_help[0] ; - args_info->version_help = buildObservedVoids_info_help[1] ; - args_info->desc_help = buildObservedVoids_info_help[2] ; - args_info->partzone_help = buildObservedVoids_info_help[3] ; - args_info->zonevoid_help = buildObservedVoids_info_help[4] ; - args_info->minProba_help = buildObservedVoids_info_help[5] ; - args_info->densityThreshold_help = buildObservedVoids_info_help[6] ; - args_info->configFile_help = buildObservedVoids_info_help[7] ; - args_info->output_help = buildObservedVoids_info_help[8] ; - args_info->gridOutput_help = buildObservedVoids_info_help[9] ; - args_info->quiet_help = buildObservedVoids_info_help[10] ; - args_info->dumpVoids_help = buildObservedVoids_info_help[11] ; - args_info->dumpIds_help = buildObservedVoids_info_help[12] ; - args_info->ramsesBase_help = buildObservedVoids_info_help[13] ; - args_info->ramsesId_help = buildObservedVoids_info_help[14] ; - args_info->dumpTree_help = buildObservedVoids_info_help[15] ; - args_info->getTree_help = buildObservedVoids_info_help[16] ; - -} - -void -buildObservedVoids_conf_print_version (void) -{ - printf ("%s %s\n", - (strlen(BUILDOBSERVEDVOIDS_CONF_PACKAGE_NAME) ? BUILDOBSERVEDVOIDS_CONF_PACKAGE_NAME : BUILDOBSERVEDVOIDS_CONF_PACKAGE), - BUILDOBSERVEDVOIDS_CONF_VERSION); -} - -static void print_help_common(void) { - buildObservedVoids_conf_print_version (); - - if (strlen(buildObservedVoids_info_purpose) > 0) - printf("\n%s\n", buildObservedVoids_info_purpose); - - if (strlen(buildObservedVoids_info_usage) > 0) - printf("\n%s\n", buildObservedVoids_info_usage); - - printf("\n"); - - if (strlen(buildObservedVoids_info_description) > 0) - printf("%s\n\n", buildObservedVoids_info_description); -} - -void -buildObservedVoids_conf_print_help (void) -{ - int i = 0; - print_help_common(); - while (buildObservedVoids_info_help[i]) - printf("%s\n", buildObservedVoids_info_help[i++]); -} - -void -buildObservedVoids_conf_init (struct buildObservedVoids_info *args_info) -{ - clear_given (args_info); - clear_args (args_info); - init_args_info (args_info); -} - -void -buildObservedVoids_conf_params_init(struct buildObservedVoids_conf_params *params) -{ - if (params) - { - params->override = 0; - params->initialize = 1; - params->check_required = 1; - params->check_ambiguity = 0; - params->print_errors = 1; - } -} - -struct buildObservedVoids_conf_params * -buildObservedVoids_conf_params_create(void) -{ - struct buildObservedVoids_conf_params *params = - (struct buildObservedVoids_conf_params *)malloc(sizeof(struct buildObservedVoids_conf_params)); - buildObservedVoids_conf_params_init(params); - return params; -} - -static void -free_string_field (char **s) -{ - if (*s) - { - free (*s); - *s = 0; - } -} - - -static void -buildObservedVoids_conf_release (struct buildObservedVoids_info *args_info) -{ - - free_string_field (&(args_info->desc_arg)); - free_string_field (&(args_info->desc_orig)); - free_string_field (&(args_info->partzone_arg)); - free_string_field (&(args_info->partzone_orig)); - free_string_field (&(args_info->zonevoid_arg)); - free_string_field (&(args_info->zonevoid_orig)); - free_string_field (&(args_info->minProba_orig)); - free_string_field (&(args_info->densityThreshold_orig)); - free_string_field (&(args_info->configFile_arg)); - free_string_field (&(args_info->configFile_orig)); - free_string_field (&(args_info->output_arg)); - free_string_field (&(args_info->output_orig)); - free_string_field (&(args_info->gridOutput_arg)); - free_string_field (&(args_info->gridOutput_orig)); - free_string_field (&(args_info->dumpVoids_arg)); - free_string_field (&(args_info->dumpVoids_orig)); - free_string_field (&(args_info->ramsesBase_arg)); - free_string_field (&(args_info->ramsesBase_orig)); - free_string_field (&(args_info->ramsesId_orig)); - - - - clear_given (args_info); -} - - -static void -write_into_file(FILE *outfile, const char *opt, const char *arg, const char *values[]) -{ - FIX_UNUSED (values); - if (arg) { - fprintf(outfile, "%s=\"%s\"\n", opt, arg); - } else { - fprintf(outfile, "%s\n", opt); - } -} - - -int -buildObservedVoids_conf_dump(FILE *outfile, struct buildObservedVoids_info *args_info) -{ - int i = 0; - - if (!outfile) - { - fprintf (stderr, "%s: cannot dump options to stream\n", BUILDOBSERVEDVOIDS_CONF_PACKAGE); - return EXIT_FAILURE; - } - - if (args_info->help_given) - write_into_file(outfile, "help", 0, 0 ); - if (args_info->version_given) - write_into_file(outfile, "version", 0, 0 ); - if (args_info->desc_given) - write_into_file(outfile, "desc", args_info->desc_orig, 0); - if (args_info->partzone_given) - write_into_file(outfile, "partzone", args_info->partzone_orig, 0); - if (args_info->zonevoid_given) - write_into_file(outfile, "zonevoid", args_info->zonevoid_orig, 0); - if (args_info->minProba_given) - write_into_file(outfile, "minProba", args_info->minProba_orig, 0); - if (args_info->densityThreshold_given) - write_into_file(outfile, "densityThreshold", args_info->densityThreshold_orig, 0); - if (args_info->configFile_given) - write_into_file(outfile, "configFile", args_info->configFile_orig, 0); - if (args_info->output_given) - write_into_file(outfile, "output", args_info->output_orig, 0); - if (args_info->gridOutput_given) - write_into_file(outfile, "gridOutput", args_info->gridOutput_orig, 0); - if (args_info->quiet_given) - write_into_file(outfile, "quiet", 0, 0 ); - if (args_info->dumpVoids_given) - write_into_file(outfile, "dumpVoids", args_info->dumpVoids_orig, 0); - if (args_info->dumpIds_given) - write_into_file(outfile, "dumpIds", 0, 0 ); - if (args_info->ramsesBase_given) - write_into_file(outfile, "ramsesBase", args_info->ramsesBase_orig, 0); - if (args_info->ramsesId_given) - write_into_file(outfile, "ramsesId", args_info->ramsesId_orig, 0); - if (args_info->dumpTree_given) - write_into_file(outfile, "dumpTree", 0, 0 ); - if (args_info->getTree_given) - write_into_file(outfile, "getTree", 0, 0 ); - - - i = EXIT_SUCCESS; - return i; -} - -int -buildObservedVoids_conf_file_save(const char *filename, struct buildObservedVoids_info *args_info) -{ - FILE *outfile; - int i = 0; - - outfile = fopen(filename, "w"); - - if (!outfile) - { - fprintf (stderr, "%s: cannot open file for writing: %s\n", BUILDOBSERVEDVOIDS_CONF_PACKAGE, filename); - return EXIT_FAILURE; - } - - i = buildObservedVoids_conf_dump(outfile, args_info); - fclose (outfile); - - return i; -} - -void -buildObservedVoids_conf_free (struct buildObservedVoids_info *args_info) -{ - buildObservedVoids_conf_release (args_info); -} - -/** @brief replacement of strdup, which is not standard */ -char * -gengetopt_strdup (const char *s) -{ - char *result = 0; - if (!s) - return result; - - result = (char*)malloc(strlen(s) + 1); - if (result == (char*)0) - return (char*)0; - strcpy(result, s); - return result; -} - -int -buildObservedVoids_conf (int argc, char * const *argv, struct buildObservedVoids_info *args_info) -{ - return buildObservedVoids_conf2 (argc, argv, args_info, 0, 1, 1); -} - -int -buildObservedVoids_conf_ext (int argc, char * const *argv, struct buildObservedVoids_info *args_info, - struct buildObservedVoids_conf_params *params) -{ - int result; - result = buildObservedVoids_conf_internal (argc, argv, args_info, params, 0); - - if (result == EXIT_FAILURE) - { - buildObservedVoids_conf_free (args_info); - exit (EXIT_FAILURE); - } - - return result; -} - -int -buildObservedVoids_conf2 (int argc, char * const *argv, struct buildObservedVoids_info *args_info, int override, int initialize, int check_required) -{ - int result; - struct buildObservedVoids_conf_params params; - - params.override = override; - params.initialize = initialize; - params.check_required = check_required; - params.check_ambiguity = 0; - params.print_errors = 1; - - result = buildObservedVoids_conf_internal (argc, argv, args_info, ¶ms, 0); - - if (result == EXIT_FAILURE) - { - buildObservedVoids_conf_free (args_info); - exit (EXIT_FAILURE); - } - - return result; -} - -int -buildObservedVoids_conf_required (struct buildObservedVoids_info *args_info, const char *prog_name) -{ - int result = EXIT_SUCCESS; - - if (buildObservedVoids_conf_required2(args_info, prog_name, 0) > 0) - result = EXIT_FAILURE; - - if (result == EXIT_FAILURE) - { - buildObservedVoids_conf_free (args_info); - exit (EXIT_FAILURE); - } - - return result; -} - -int -buildObservedVoids_conf_required2 (struct buildObservedVoids_info *args_info, const char *prog_name, const char *additional_error) -{ - FIX_UNUSED (additional_error); - int error = 0; - - /* checks for required options */ - if (! args_info->desc_given) - { - fprintf (stderr, "%s: '--desc' ('-d') option required%s\n", prog_name, (additional_error ? additional_error : "")); - error = 1; - } - - if (! args_info->partzone_given) - { - fprintf (stderr, "%s: '--partzone' ('-p') option required%s\n", prog_name, (additional_error ? additional_error : "")); - error = 1; - } - - if (! args_info->zonevoid_given) - { - fprintf (stderr, "%s: '--zonevoid' ('-v') option required%s\n", prog_name, (additional_error ? additional_error : "")); - error = 1; - } - - - /* checks for dependences among options */ - - return error; -} - - -static char *package_name = 0; - -/** - * @brief updates an option - * @param field the generic pointer to the field to update - * @param orig_field the pointer to the orig field - * @param field_given the pointer to the number of occurrence of this option - * @param prev_given the pointer to the number of occurrence already seen - * @param value the argument for this option (if null no arg was specified) - * @param possible_values the possible values for this option (if specified) - * @param default_value the default value (in case the option only accepts fixed values) - * @param arg_type the type of this option - * @param check_ambiguity @see buildObservedVoids_conf_params.check_ambiguity - * @param override @see buildObservedVoids_conf_params.override - * @param no_free whether to free a possible previous value - * @param multiple_option whether this is a multiple option - * @param long_opt the corresponding long option - * @param short_opt the corresponding short option (or '-' if none) - * @param additional_error possible further error specification - */ -static -int update_arg(void *field, char **orig_field, - unsigned int *field_given, unsigned int *prev_given, - char *value, const char *possible_values[], - const char *default_value, - buildObservedVoids_conf_arg_type arg_type, - int check_ambiguity, int override, - int no_free, int multiple_option, - const char *long_opt, char short_opt, - const char *additional_error) -{ - FIX_UNUSED (field); - char *stop_char = 0; - const char *val = value; - int found; - char **string_field; - - stop_char = 0; - found = 0; - - if (!multiple_option && prev_given && (*prev_given || (check_ambiguity && *field_given))) - { - if (short_opt != '-') - fprintf (stderr, "%s: `--%s' (`-%c') option given more than once%s\n", - package_name, long_opt, short_opt, - (additional_error ? additional_error : "")); - else - fprintf (stderr, "%s: `--%s' option given more than once%s\n", - package_name, long_opt, - (additional_error ? additional_error : "")); - return 1; /* failure */ - } - - FIX_UNUSED (default_value); - - if (field_given && *field_given && ! override) - return 0; - if (prev_given) - (*prev_given)++; - if (field_given) - (*field_given)++; - if (possible_values) - val = possible_values[found]; - - switch(arg_type) { - case ARG_FLAG: - *((int *)field) = !*((int *)field); - break; - case ARG_INT: - if (val) *((int *)field) = strtol (val, &stop_char, 0); - break; - case ARG_DOUBLE: - if (val) *((double *)field) = strtod (val, &stop_char); - break; - case ARG_STRING: - if (val) { - string_field = (char **)field; - if (!no_free && *string_field) - free (*string_field); /* free previous string */ - *string_field = gengetopt_strdup (val); - } - break; - default: - break; - }; - - /* check numeric conversion */ - switch(arg_type) { - case ARG_INT: - case ARG_DOUBLE: - if (val && !(stop_char && *stop_char == '\0')) { - fprintf(stderr, "%s: invalid numeric value: %s\n", package_name, val); - return 1; /* failure */ - } - break; - default: - ; - }; - - /* store the original value */ - switch(arg_type) { - case ARG_NO: - case ARG_FLAG: - break; - default: - if (value && orig_field) { - if (no_free) { - *orig_field = value; - } else { - if (*orig_field) - free (*orig_field); /* free previous string */ - *orig_field = gengetopt_strdup (value); - } - } - }; - - return 0; /* OK */ -} - - -int -buildObservedVoids_conf_internal ( - int argc, char * const *argv, struct buildObservedVoids_info *args_info, - struct buildObservedVoids_conf_params *params, const char *additional_error) -{ - int c; /* Character of the parsed option. */ - - int error = 0; - struct buildObservedVoids_info local_args_info; - - int override; - int initialize; - int check_required; - int check_ambiguity; - - package_name = argv[0]; - - override = params->override; - initialize = params->initialize; - check_required = params->check_required; - check_ambiguity = params->check_ambiguity; - - if (initialize) - buildObservedVoids_conf_init (args_info); - - buildObservedVoids_conf_init (&local_args_info); - - optarg = 0; - optind = 0; - opterr = params->print_errors; - optopt = '?'; - - while (1) - { - int option_index = 0; - - static struct option long_options[] = { - { "help", 0, NULL, 'h' }, - { "version", 0, NULL, 'V' }, - { "desc", 1, NULL, 'd' }, - { "partzone", 1, NULL, 'p' }, - { "zonevoid", 1, NULL, 'v' }, - { "minProba", 1, NULL, 'm' }, - { "densityThreshold", 1, NULL, 0 }, - { "configFile", 1, NULL, 'f' }, - { "output", 1, NULL, 'o' }, - { "gridOutput", 1, NULL, 'g' }, - { "quiet", 0, NULL, 'q' }, - { "dumpVoids", 1, NULL, 0 }, - { "dumpIds", 0, NULL, 0 }, - { "ramsesBase", 1, NULL, 0 }, - { "ramsesId", 1, NULL, 0 }, - { "dumpTree", 0, NULL, 0 }, - { "getTree", 0, NULL, 0 }, - { 0, 0, 0, 0 } - }; - - c = getopt_long (argc, argv, "hVd:p:v:m:f:o:g:q", long_options, &option_index); - - if (c == -1) break; /* Exit from `while (1)' loop. */ - - switch (c) - { - case 'h': /* Print help and exit. */ - buildObservedVoids_conf_print_help (); - buildObservedVoids_conf_free (&local_args_info); - exit (EXIT_SUCCESS); - - case 'V': /* Print version and exit. */ - buildObservedVoids_conf_print_version (); - buildObservedVoids_conf_free (&local_args_info); - exit (EXIT_SUCCESS); - - case 'd': /* The description file name for the voids (jozov generated). */ - - - if (update_arg( (void *)&(args_info->desc_arg), - &(args_info->desc_orig), &(args_info->desc_given), - &(local_args_info.desc_given), optarg, 0, 0, ARG_STRING, - check_ambiguity, override, 0, 0, - "desc", 'd', - additional_error)) - goto failure; - - break; - case 'p': /* Particles/Zones bind file. */ - - - if (update_arg( (void *)&(args_info->partzone_arg), - &(args_info->partzone_orig), &(args_info->partzone_given), - &(local_args_info.partzone_given), optarg, 0, 0, ARG_STRING, - check_ambiguity, override, 0, 0, - "partzone", 'p', - additional_error)) - goto failure; - - break; - case 'v': /* Void/zone bind file (jozov generated). */ - - - if (update_arg( (void *)&(args_info->zonevoid_arg), - &(args_info->zonevoid_orig), &(args_info->zonevoid_given), - &(local_args_info.zonevoid_given), optarg, 0, 0, ARG_STRING, - check_ambiguity, override, 0, 0, - "zonevoid", 'v', - additional_error)) - goto failure; - - break; - case 'm': /* Minimal probability to accept. */ - - - if (update_arg( (void *)&(args_info->minProba_arg), - &(args_info->minProba_orig), &(args_info->minProba_given), - &(local_args_info.minProba_given), optarg, 0, "0.0", ARG_DOUBLE, - check_ambiguity, override, 0, 0, - "minProba", 'm', - additional_error)) - goto failure; - - break; - case 'f': /* Configuration file. */ - - - if (update_arg( (void *)&(args_info->configFile_arg), - &(args_info->configFile_orig), &(args_info->configFile_given), - &(local_args_info.configFile_given), optarg, 0, 0, ARG_STRING, - check_ambiguity, override, 0, 0, - "configFile", 'f', - additional_error)) - goto failure; - - break; - case 'o': /* Output file. */ - - - if (update_arg( (void *)&(args_info->output_arg), - &(args_info->output_orig), &(args_info->output_given), - &(local_args_info.output_given), optarg, 0, "void_info.txt", ARG_STRING, - check_ambiguity, override, 0, 0, - "output", 'o', - additional_error)) - goto failure; - - break; - case 'g': /* 3d grid output of voids. */ - - - if (update_arg( (void *)&(args_info->gridOutput_arg), - &(args_info->gridOutput_orig), &(args_info->gridOutput_given), - &(local_args_info.gridOutput_given), optarg, 0, "all_voids.nc", ARG_STRING, - check_ambiguity, override, 0, 0, - "gridOutput", 'g', - additional_error)) - goto failure; - - break; - case 'q': /* Quiet output. */ - - - if (update_arg((void *)&(args_info->quiet_flag), 0, &(args_info->quiet_given), - &(local_args_info.quiet_given), optarg, 0, 0, ARG_FLAG, - check_ambiguity, override, 1, 0, "quiet", 'q', - additional_error)) - goto failure; - - break; - - case 0: /* Long option with no short option */ - /* Density threshold to consider a stable void. */ - if (strcmp (long_options[option_index].name, "densityThreshold") == 0) - { - - - if (update_arg( (void *)&(args_info->densityThreshold_arg), - &(args_info->densityThreshold_orig), &(args_info->densityThreshold_given), - &(local_args_info.densityThreshold_given), optarg, 0, "-0.8", ARG_DOUBLE, - check_ambiguity, override, 0, 0, - "densityThreshold", '-', - additional_error)) - goto failure; - - } - /* Dump the particles in void in a file. */ - else if (strcmp (long_options[option_index].name, "dumpVoids") == 0) - { - - - if (update_arg( (void *)&(args_info->dumpVoids_arg), - &(args_info->dumpVoids_orig), &(args_info->dumpVoids_given), - &(local_args_info.dumpVoids_given), optarg, 0, 0, ARG_STRING, - check_ambiguity, override, 0, 0, - "dumpVoids", '-', - additional_error)) - goto failure; - - } - /* Dump particle ids. */ - else if (strcmp (long_options[option_index].name, "dumpIds") == 0) - { - - - if (update_arg((void *)&(args_info->dumpIds_flag), 0, &(args_info->dumpIds_given), - &(local_args_info.dumpIds_given), optarg, 0, 0, ARG_FLAG, - check_ambiguity, override, 1, 0, "dumpIds", '-', - additional_error)) - goto failure; - - } - /* Base directory for ramses. */ - else if (strcmp (long_options[option_index].name, "ramsesBase") == 0) - { - - - if (update_arg( (void *)&(args_info->ramsesBase_arg), - &(args_info->ramsesBase_orig), &(args_info->ramsesBase_given), - &(local_args_info.ramsesBase_given), optarg, 0, 0, ARG_STRING, - check_ambiguity, override, 0, 0, - "ramsesBase", '-', - additional_error)) - goto failure; - - } - /* Ramses snapshot id. */ - else if (strcmp (long_options[option_index].name, "ramsesId") == 0) - { - - - if (update_arg( (void *)&(args_info->ramsesId_arg), - &(args_info->ramsesId_orig), &(args_info->ramsesId_given), - &(local_args_info.ramsesId_given), optarg, 0, 0, ARG_INT, - check_ambiguity, override, 0, 0, - "ramsesId", '-', - additional_error)) - goto failure; - - } - /* Dump the void tree. */ - else if (strcmp (long_options[option_index].name, "dumpTree") == 0) - { - - - if (update_arg((void *)&(args_info->dumpTree_flag), 0, &(args_info->dumpTree_given), - &(local_args_info.dumpTree_given), optarg, 0, 0, ARG_FLAG, - check_ambiguity, override, 1, 0, "dumpTree", '-', - additional_error)) - goto failure; - - } - /* Restore tree from file. */ - else if (strcmp (long_options[option_index].name, "getTree") == 0) - { - - - if (update_arg((void *)&(args_info->getTree_flag), 0, &(args_info->getTree_given), - &(local_args_info.getTree_given), optarg, 0, 0, ARG_FLAG, - check_ambiguity, override, 1, 0, "getTree", '-', - additional_error)) - goto failure; - - } - - break; - case '?': /* Invalid option. */ - /* `getopt_long' already printed an error message. */ - goto failure; - - default: /* bug: option not considered. */ - fprintf (stderr, "%s: option unknown: %c%s\n", BUILDOBSERVEDVOIDS_CONF_PACKAGE, c, (additional_error ? additional_error : "")); - abort (); - } /* switch */ - } /* while */ - - - - if (check_required) - { - error += buildObservedVoids_conf_required2 (args_info, argv[0], additional_error); - } - - buildObservedVoids_conf_release (&local_args_info); - - if ( error ) - return (EXIT_FAILURE); - - return 0; - -failure: - - buildObservedVoids_conf_release (&local_args_info); - return (EXIT_FAILURE); -} - -#ifndef CONFIG_FILE_LINE_SIZE -#define CONFIG_FILE_LINE_SIZE 2048 -#endif -#define ADDITIONAL_ERROR " in configuration file " - -#define CONFIG_FILE_LINE_BUFFER_SIZE (CONFIG_FILE_LINE_SIZE+3) -/* 3 is for "--" and "=" */ - -static int -_buildObservedVoids_conf_configfile (const char *filename, int *my_argc) -{ - FILE* file; - char my_argv[CONFIG_FILE_LINE_BUFFER_SIZE+1]; - char linebuf[CONFIG_FILE_LINE_SIZE]; - int line_num = 0; - int result = 0, equal; - char *fopt, *farg; - char *str_index; - size_t len, next_token; - char delimiter; - - if ((file = fopen(filename, "r")) == 0) - { - fprintf (stderr, "%s: Error opening configuration file '%s'\n", - BUILDOBSERVEDVOIDS_CONF_PACKAGE, filename); - return EXIT_FAILURE; - } - - while ((fgets(linebuf, CONFIG_FILE_LINE_SIZE, file)) != 0) - { - ++line_num; - my_argv[0] = '\0'; - len = strlen(linebuf); - if (len > (CONFIG_FILE_LINE_BUFFER_SIZE-1)) - { - fprintf (stderr, "%s:%s:%d: Line too long in configuration file\n", - BUILDOBSERVEDVOIDS_CONF_PACKAGE, filename, line_num); - result = EXIT_FAILURE; - break; - } - - /* find first non-whitespace character in the line */ - next_token = strspn (linebuf, " \t\r\n"); - str_index = linebuf + next_token; - - if ( str_index[0] == '\0' || str_index[0] == '#') - continue; /* empty line or comment line is skipped */ - - fopt = str_index; - - /* truncate fopt at the end of the first non-valid character */ - next_token = strcspn (fopt, " \t\r\n="); - - if (fopt[next_token] == '\0') /* the line is over */ - { - farg = 0; - equal = 0; - goto noarg; - } - - /* remember if equal sign is present */ - equal = (fopt[next_token] == '='); - fopt[next_token++] = '\0'; - - /* advance pointers to the next token after the end of fopt */ - next_token += strspn (fopt + next_token, " \t\r\n"); - - /* check for the presence of equal sign, and if so, skip it */ - if ( !equal ) - if ((equal = (fopt[next_token] == '='))) - { - next_token++; - next_token += strspn (fopt + next_token, " \t\r\n"); - } - str_index += next_token; - - /* find argument */ - farg = str_index; - if ( farg[0] == '\"' || farg[0] == '\'' ) - { /* quoted argument */ - str_index = strchr (++farg, str_index[0] ); /* skip opening quote */ - if (! str_index) - { - fprintf - (stderr, - "%s:%s:%d: unterminated string in configuration file\n", - BUILDOBSERVEDVOIDS_CONF_PACKAGE, filename, line_num); - result = EXIT_FAILURE; - break; - } - } - else - { /* read up the remaining part up to a delimiter */ - next_token = strcspn (farg, " \t\r\n#\'\""); - str_index += next_token; - } - - /* truncate farg at the delimiter and store it for further check */ - delimiter = *str_index, *str_index++ = '\0'; - - /* everything but comment is illegal at the end of line */ - if (delimiter != '\0' && delimiter != '#') - { - str_index += strspn(str_index, " \t\r\n"); - if (*str_index != '\0' && *str_index != '#') - { - fprintf - (stderr, - "%s:%s:%d: malformed string in configuration file\n", - BUILDOBSERVEDVOIDS_CONF_PACKAGE, filename, line_num); - result = EXIT_FAILURE; - break; - } - } - - noarg: - if (!strcmp(fopt,"include")) { - if (farg && *farg) { - result = _buildObservedVoids_conf_configfile(farg, my_argc); - } else { - fprintf(stderr, "%s:%s:%d: include requires a filename argument.\n", - BUILDOBSERVEDVOIDS_CONF_PACKAGE, filename, line_num); - } - continue; - } - len = strlen(fopt); - strcat (my_argv, len > 1 ? "--" : "-"); - strcat (my_argv, fopt); - if (len > 1 && ((farg && *farg) || equal)) - strcat (my_argv, "="); - if (farg && *farg) - strcat (my_argv, farg); - ++(*my_argc); - - cmd_line_list_tmp = (struct line_list *) malloc (sizeof (struct line_list)); - cmd_line_list_tmp->next = cmd_line_list; - cmd_line_list = cmd_line_list_tmp; - cmd_line_list->string_arg = gengetopt_strdup(my_argv); - } /* while */ - - if (file) - fclose(file); - return result; -} - -int -buildObservedVoids_conf_configfile ( - const char *filename, - struct buildObservedVoids_info *args_info, - int override, int initialize, int check_required) -{ - struct buildObservedVoids_conf_params params; - - params.override = override; - params.initialize = initialize; - params.check_required = check_required; - params.check_ambiguity = 0; - params.print_errors = 1; - - return buildObservedVoids_conf_config_file (filename, args_info, ¶ms); -} - -int -buildObservedVoids_conf_config_file (const char *filename, - struct buildObservedVoids_info *args_info, - struct buildObservedVoids_conf_params *params) -{ - int i, result; - int my_argc = 1; - char **my_argv_arg; - char *additional_error; - - /* store the program name */ - cmd_line_list_tmp = (struct line_list *) malloc (sizeof (struct line_list)); - cmd_line_list_tmp->next = cmd_line_list; - cmd_line_list = cmd_line_list_tmp; - cmd_line_list->string_arg = gengetopt_strdup (BUILDOBSERVEDVOIDS_CONF_PACKAGE); - - result = _buildObservedVoids_conf_configfile(filename, &my_argc); - - if (result != EXIT_FAILURE) { - my_argv_arg = (char **) malloc((my_argc+1) * sizeof(char *)); - cmd_line_list_tmp = cmd_line_list; - - for (i = my_argc - 1; i >= 0; --i) { - my_argv_arg[i] = cmd_line_list_tmp->string_arg; - cmd_line_list_tmp = cmd_line_list_tmp->next; - } - - my_argv_arg[my_argc] = 0; - - additional_error = (char *)malloc(strlen(filename) + strlen(ADDITIONAL_ERROR) + 1); - strcpy (additional_error, ADDITIONAL_ERROR); - strcat (additional_error, filename); - result = - buildObservedVoids_conf_internal (my_argc, my_argv_arg, args_info, - params, - additional_error); - - free (additional_error); - free (my_argv_arg); - } - - free_cmd_list(); - if (result == EXIT_FAILURE) - { - buildObservedVoids_conf_free (args_info); - exit (EXIT_FAILURE); - } - - return result; -} diff --git a/mytools/buildObservedVoids_conf.h b/mytools/buildObservedVoids_conf.h deleted file mode 100644 index 23fdbb6..0000000 --- a/mytools/buildObservedVoids_conf.h +++ /dev/null @@ -1,252 +0,0 @@ -/** @file buildObservedVoids_conf.h - * @brief The header file for the command line option parser - * generated by GNU Gengetopt version 2.22.2 - * http://www.gnu.org/software/gengetopt. - * DO NOT modify this file, since it can be overwritten - * @author GNU Gengetopt by Lorenzo Bettini */ - -#ifndef BUILDOBSERVEDVOIDS_CONF_H -#define BUILDOBSERVEDVOIDS_CONF_H - -/* If we use autoconf. */ -#ifdef HAVE_CONFIG_H -#include "config.h" -#endif - -#include /* for FILE */ - -#ifdef __cplusplus -extern "C" { -#endif /* __cplusplus */ - -#ifndef BUILDOBSERVEDVOIDS_CONF_PACKAGE -/** @brief the program name (used for printing errors) */ -#define BUILDOBSERVEDVOIDS_CONF_PACKAGE "buildObservedVoids" -#endif - -#ifndef BUILDOBSERVEDVOIDS_CONF_PACKAGE_NAME -/** @brief the complete program name (used for help and version) */ -#define BUILDOBSERVEDVOIDS_CONF_PACKAGE_NAME "buildObservedVoids" -#endif - -#ifndef BUILDOBSERVEDVOIDS_CONF_VERSION -/** @brief the program version */ -#define BUILDOBSERVEDVOIDS_CONF_VERSION "0" -#endif - -/** @brief Where the command line options are stored */ -struct buildObservedVoids_info -{ - const char *help_help; /**< @brief Print help and exit help description. */ - const char *version_help; /**< @brief Print version and exit help description. */ - char * desc_arg; /**< @brief The description file name for the voids (jozov generated). */ - char * desc_orig; /**< @brief The description file name for the voids (jozov generated) original value given at command line. */ - const char *desc_help; /**< @brief The description file name for the voids (jozov generated) help description. */ - char * partzone_arg; /**< @brief Particles/Zones bind file. */ - char * partzone_orig; /**< @brief Particles/Zones bind file original value given at command line. */ - const char *partzone_help; /**< @brief Particles/Zones bind file help description. */ - char * zonevoid_arg; /**< @brief Void/zone bind file (jozov generated). */ - char * zonevoid_orig; /**< @brief Void/zone bind file (jozov generated) original value given at command line. */ - const char *zonevoid_help; /**< @brief Void/zone bind file (jozov generated) help description. */ - double minProba_arg; /**< @brief Minimal probability to accept (default='0.0'). */ - char * minProba_orig; /**< @brief Minimal probability to accept original value given at command line. */ - const char *minProba_help; /**< @brief Minimal probability to accept help description. */ - double densityThreshold_arg; /**< @brief Density threshold to consider a stable void (default='-0.8'). */ - char * densityThreshold_orig; /**< @brief Density threshold to consider a stable void original value given at command line. */ - const char *densityThreshold_help; /**< @brief Density threshold to consider a stable void help description. */ - char * configFile_arg; /**< @brief Configuration file. */ - char * configFile_orig; /**< @brief Configuration file original value given at command line. */ - const char *configFile_help; /**< @brief Configuration file help description. */ - char * output_arg; /**< @brief Output file (default='void_info.txt'). */ - char * output_orig; /**< @brief Output file original value given at command line. */ - const char *output_help; /**< @brief Output file help description. */ - char * gridOutput_arg; /**< @brief 3d grid output of voids (default='all_voids.nc'). */ - char * gridOutput_orig; /**< @brief 3d grid output of voids original value given at command line. */ - const char *gridOutput_help; /**< @brief 3d grid output of voids help description. */ - int quiet_flag; /**< @brief Quiet output (default=off). */ - const char *quiet_help; /**< @brief Quiet output help description. */ - char * dumpVoids_arg; /**< @brief Dump the particles in void in a file. */ - char * dumpVoids_orig; /**< @brief Dump the particles in void in a file original value given at command line. */ - const char *dumpVoids_help; /**< @brief Dump the particles in void in a file help description. */ - int dumpIds_flag; /**< @brief Dump particle ids (default=off). */ - const char *dumpIds_help; /**< @brief Dump particle ids help description. */ - char * ramsesBase_arg; /**< @brief Base directory for ramses. */ - char * ramsesBase_orig; /**< @brief Base directory for ramses original value given at command line. */ - const char *ramsesBase_help; /**< @brief Base directory for ramses help description. */ - int ramsesId_arg; /**< @brief Ramses snapshot id. */ - char * ramsesId_orig; /**< @brief Ramses snapshot id original value given at command line. */ - const char *ramsesId_help; /**< @brief Ramses snapshot id help description. */ - int dumpTree_flag; /**< @brief Dump the void tree (default=off). */ - const char *dumpTree_help; /**< @brief Dump the void tree help description. */ - int getTree_flag; /**< @brief Restore tree from file (default=off). */ - const char *getTree_help; /**< @brief Restore tree from file help description. */ - - unsigned int help_given ; /**< @brief Whether help was given. */ - unsigned int version_given ; /**< @brief Whether version was given. */ - unsigned int desc_given ; /**< @brief Whether desc was given. */ - unsigned int partzone_given ; /**< @brief Whether partzone was given. */ - unsigned int zonevoid_given ; /**< @brief Whether zonevoid was given. */ - unsigned int minProba_given ; /**< @brief Whether minProba was given. */ - unsigned int densityThreshold_given ; /**< @brief Whether densityThreshold was given. */ - unsigned int configFile_given ; /**< @brief Whether configFile was given. */ - unsigned int output_given ; /**< @brief Whether output was given. */ - unsigned int gridOutput_given ; /**< @brief Whether gridOutput was given. */ - unsigned int quiet_given ; /**< @brief Whether quiet was given. */ - unsigned int dumpVoids_given ; /**< @brief Whether dumpVoids was given. */ - unsigned int dumpIds_given ; /**< @brief Whether dumpIds was given. */ - unsigned int ramsesBase_given ; /**< @brief Whether ramsesBase was given. */ - unsigned int ramsesId_given ; /**< @brief Whether ramsesId was given. */ - unsigned int dumpTree_given ; /**< @brief Whether dumpTree was given. */ - unsigned int getTree_given ; /**< @brief Whether getTree was given. */ - -} ; - -/** @brief The additional parameters to pass to parser functions */ -struct buildObservedVoids_conf_params -{ - int override; /**< @brief whether to override possibly already present options (default 0) */ - int initialize; /**< @brief whether to initialize the option structure buildObservedVoids_info (default 1) */ - int check_required; /**< @brief whether to check that all required options were provided (default 1) */ - int check_ambiguity; /**< @brief whether to check for options already specified in the option structure buildObservedVoids_info (default 0) */ - int print_errors; /**< @brief whether getopt_long should print an error message for a bad option (default 1) */ -} ; - -/** @brief the purpose string of the program */ -extern const char *buildObservedVoids_info_purpose; -/** @brief the usage string of the program */ -extern const char *buildObservedVoids_info_usage; -/** @brief all the lines making the help output */ -extern const char *buildObservedVoids_info_help[]; - -/** - * The command line parser - * @param argc the number of command line options - * @param argv the command line options - * @param args_info the structure where option information will be stored - * @return 0 if everything went fine, NON 0 if an error took place - */ -int buildObservedVoids_conf (int argc, char * const *argv, - struct buildObservedVoids_info *args_info); - -/** - * The command line parser (version with additional parameters - deprecated) - * @param argc the number of command line options - * @param argv the command line options - * @param args_info the structure where option information will be stored - * @param override whether to override possibly already present options - * @param initialize whether to initialize the option structure my_args_info - * @param check_required whether to check that all required options were provided - * @return 0 if everything went fine, NON 0 if an error took place - * @deprecated use buildObservedVoids_conf_ext() instead - */ -int buildObservedVoids_conf2 (int argc, char * const *argv, - struct buildObservedVoids_info *args_info, - int override, int initialize, int check_required); - -/** - * The command line parser (version with additional parameters) - * @param argc the number of command line options - * @param argv the command line options - * @param args_info the structure where option information will be stored - * @param params additional parameters for the parser - * @return 0 if everything went fine, NON 0 if an error took place - */ -int buildObservedVoids_conf_ext (int argc, char * const *argv, - struct buildObservedVoids_info *args_info, - struct buildObservedVoids_conf_params *params); - -/** - * Save the contents of the option struct into an already open FILE stream. - * @param outfile the stream where to dump options - * @param args_info the option struct to dump - * @return 0 if everything went fine, NON 0 if an error took place - */ -int buildObservedVoids_conf_dump(FILE *outfile, - struct buildObservedVoids_info *args_info); - -/** - * Save the contents of the option struct into a (text) file. - * This file can be read by the config file parser (if generated by gengetopt) - * @param filename the file where to save - * @param args_info the option struct to save - * @return 0 if everything went fine, NON 0 if an error took place - */ -int buildObservedVoids_conf_file_save(const char *filename, - struct buildObservedVoids_info *args_info); - -/** - * Print the help - */ -void buildObservedVoids_conf_print_help(void); -/** - * Print the version - */ -void buildObservedVoids_conf_print_version(void); - -/** - * Initializes all the fields a buildObservedVoids_conf_params structure - * to their default values - * @param params the structure to initialize - */ -void buildObservedVoids_conf_params_init(struct buildObservedVoids_conf_params *params); - -/** - * Allocates dynamically a buildObservedVoids_conf_params structure and initializes - * all its fields to their default values - * @return the created and initialized buildObservedVoids_conf_params structure - */ -struct buildObservedVoids_conf_params *buildObservedVoids_conf_params_create(void); - -/** - * Initializes the passed buildObservedVoids_info structure's fields - * (also set default values for options that have a default) - * @param args_info the structure to initialize - */ -void buildObservedVoids_conf_init (struct buildObservedVoids_info *args_info); -/** - * Deallocates the string fields of the buildObservedVoids_info structure - * (but does not deallocate the structure itself) - * @param args_info the structure to deallocate - */ -void buildObservedVoids_conf_free (struct buildObservedVoids_info *args_info); - -/** - * The config file parser (deprecated version) - * @param filename the name of the config file - * @param args_info the structure where option information will be stored - * @param override whether to override possibly already present options - * @param initialize whether to initialize the option structure my_args_info - * @param check_required whether to check that all required options were provided - * @return 0 if everything went fine, NON 0 if an error took place - * @deprecated use buildObservedVoids_conf_config_file() instead - */ -int buildObservedVoids_conf_configfile (const char *filename, - struct buildObservedVoids_info *args_info, - int override, int initialize, int check_required); - -/** - * The config file parser - * @param filename the name of the config file - * @param args_info the structure where option information will be stored - * @param params additional parameters for the parser - * @return 0 if everything went fine, NON 0 if an error took place - */ -int buildObservedVoids_conf_config_file (const char *filename, - struct buildObservedVoids_info *args_info, - struct buildObservedVoids_conf_params *params); - -/** - * Checks that all the required options were specified - * @param args_info the structure to check - * @param prog_name the name of the program that will be used to print - * possible errors - * @return - */ -int buildObservedVoids_conf_required (struct buildObservedVoids_info *args_info, - const char *prog_name); - - -#ifdef __cplusplus -} -#endif /* __cplusplus */ -#endif /* BUILDOBSERVEDVOIDS_CONF_H */ diff --git a/mytools/zobovConf.c b/mytools/zobovConf.c deleted file mode 100644 index 07b09e4..0000000 --- a/mytools/zobovConf.c +++ /dev/null @@ -1,1101 +0,0 @@ -/* - File autogenerated by gengetopt version 2.22.2 - generated with the following command: - gengetopt -i showZobov.ggo -f zobovConf -a zobovConf_info -F zobovConf -C - - The developers of gengetopt consider the fixed text that goes in all - gengetopt output files to be in the public domain: - we make no copyright claims on it. -*/ - -/* If we use autoconf. */ -#ifdef HAVE_CONFIG_H -#include "config.h" -#endif - -#include -#include -#include - -#ifndef FIX_UNUSED -#define FIX_UNUSED(X) (void) (X) /* avoid warnings for unused params */ -#endif - -#include "getopt.h" - -#include "zobovConf.h" - -const char *zobovConf_info_purpose = ""; - -const char *zobovConf_info_usage = "Usage: showZobov [OPTIONS]..."; - -const char *zobovConf_info_description = ""; - -const char *zobovConf_info_help[] = { - " -h, --help Print help and exit", - " -V, --version Print version and exit", - " -d, --desc=STRING The description file name for the voids", - " -a, --adj=STRING Adjacent file name", - " -v, --void=STRING Void/zone bind filename", - " -i, --id=INT Void id to extract", - " -s, --sProba Sort against probability (default=off)", - " -l, --sVol Sort against volume (default=on)", - " -m, --mProba=DOUBLE Minimal probability to accept (default=`0.0')", - " -b, --ramsesDir=STRING Ramses base output directory", - " -r, --ramsesId=INT Ramses output id", - " -f, --configFile=STRING Configuration file", - " -q, --quiet Quiet mode (default=off)", - " -p, --move=STRING Move the center by (x,y,z) (default=`(0,0,0)')", - " --galax Output is galax particles (default=off)", - " -o, --output=STRING Output file (default=`voidDesc')", - " --interactive Go in interactive mode (default=off)", - 0 -}; - -typedef enum {ARG_NO - , ARG_FLAG - , ARG_STRING - , ARG_INT - , ARG_DOUBLE -} zobovConf_arg_type; - -static -void clear_given (struct zobovConf_info *args_info); -static -void clear_args (struct zobovConf_info *args_info); - -static int -zobovConf_internal (int argc, char * const *argv, struct zobovConf_info *args_info, - struct zobovConf_params *params, const char *additional_error); - -static int -zobovConf_required2 (struct zobovConf_info *args_info, const char *prog_name, const char *additional_error); -struct line_list -{ - char * string_arg; - struct line_list * next; -}; - -static struct line_list *cmd_line_list = 0; -static struct line_list *cmd_line_list_tmp = 0; - -static void -free_cmd_list(void) -{ - /* free the list of a previous call */ - if (cmd_line_list) - { - while (cmd_line_list) { - cmd_line_list_tmp = cmd_line_list; - cmd_line_list = cmd_line_list->next; - free (cmd_line_list_tmp->string_arg); - free (cmd_line_list_tmp); - } - } -} - - -static char * -gengetopt_strdup (const char *s); - -static -void clear_given (struct zobovConf_info *args_info) -{ - args_info->help_given = 0 ; - args_info->version_given = 0 ; - args_info->desc_given = 0 ; - args_info->adj_given = 0 ; - args_info->void_given = 0 ; - args_info->id_given = 0 ; - args_info->sProba_given = 0 ; - args_info->sVol_given = 0 ; - args_info->mProba_given = 0 ; - args_info->ramsesDir_given = 0 ; - args_info->ramsesId_given = 0 ; - args_info->configFile_given = 0 ; - args_info->quiet_given = 0 ; - args_info->move_given = 0 ; - args_info->galax_given = 0 ; - args_info->output_given = 0 ; - args_info->interactive_given = 0 ; -} - -static -void clear_args (struct zobovConf_info *args_info) -{ - FIX_UNUSED (args_info); - args_info->desc_arg = NULL; - args_info->desc_orig = NULL; - args_info->adj_arg = NULL; - args_info->adj_orig = NULL; - args_info->void_arg = NULL; - args_info->void_orig = NULL; - args_info->id_orig = NULL; - args_info->sProba_flag = 0; - args_info->sVol_flag = 1; - args_info->mProba_arg = 0.0; - args_info->mProba_orig = NULL; - args_info->ramsesDir_arg = NULL; - args_info->ramsesDir_orig = NULL; - args_info->ramsesId_orig = NULL; - args_info->configFile_arg = NULL; - args_info->configFile_orig = NULL; - args_info->quiet_flag = 0; - args_info->move_arg = gengetopt_strdup ("(0,0,0)"); - args_info->move_orig = NULL; - args_info->galax_flag = 0; - args_info->output_arg = gengetopt_strdup ("voidDesc"); - args_info->output_orig = NULL; - args_info->interactive_flag = 0; - -} - -static -void init_args_info(struct zobovConf_info *args_info) -{ - - - args_info->help_help = zobovConf_info_help[0] ; - args_info->version_help = zobovConf_info_help[1] ; - args_info->desc_help = zobovConf_info_help[2] ; - args_info->adj_help = zobovConf_info_help[3] ; - args_info->void_help = zobovConf_info_help[4] ; - args_info->id_help = zobovConf_info_help[5] ; - args_info->sProba_help = zobovConf_info_help[6] ; - args_info->sVol_help = zobovConf_info_help[7] ; - args_info->mProba_help = zobovConf_info_help[8] ; - args_info->ramsesDir_help = zobovConf_info_help[9] ; - args_info->ramsesId_help = zobovConf_info_help[10] ; - args_info->configFile_help = zobovConf_info_help[11] ; - args_info->quiet_help = zobovConf_info_help[12] ; - args_info->move_help = zobovConf_info_help[13] ; - args_info->galax_help = zobovConf_info_help[14] ; - args_info->output_help = zobovConf_info_help[15] ; - args_info->interactive_help = zobovConf_info_help[16] ; - -} - -void -zobovConf_print_version (void) -{ - printf ("%s %s\n", - (strlen(ZOBOVCONF_PACKAGE_NAME) ? ZOBOVCONF_PACKAGE_NAME : ZOBOVCONF_PACKAGE), - ZOBOVCONF_VERSION); -} - -static void print_help_common(void) { - zobovConf_print_version (); - - if (strlen(zobovConf_info_purpose) > 0) - printf("\n%s\n", zobovConf_info_purpose); - - if (strlen(zobovConf_info_usage) > 0) - printf("\n%s\n", zobovConf_info_usage); - - printf("\n"); - - if (strlen(zobovConf_info_description) > 0) - printf("%s\n\n", zobovConf_info_description); -} - -void -zobovConf_print_help (void) -{ - int i = 0; - print_help_common(); - while (zobovConf_info_help[i]) - printf("%s\n", zobovConf_info_help[i++]); -} - -void -zobovConf_init (struct zobovConf_info *args_info) -{ - clear_given (args_info); - clear_args (args_info); - init_args_info (args_info); -} - -void -zobovConf_params_init(struct zobovConf_params *params) -{ - if (params) - { - params->override = 0; - params->initialize = 1; - params->check_required = 1; - params->check_ambiguity = 0; - params->print_errors = 1; - } -} - -struct zobovConf_params * -zobovConf_params_create(void) -{ - struct zobovConf_params *params = - (struct zobovConf_params *)malloc(sizeof(struct zobovConf_params)); - zobovConf_params_init(params); - return params; -} - -static void -free_string_field (char **s) -{ - if (*s) - { - free (*s); - *s = 0; - } -} - - -static void -zobovConf_release (struct zobovConf_info *args_info) -{ - - free_string_field (&(args_info->desc_arg)); - free_string_field (&(args_info->desc_orig)); - free_string_field (&(args_info->adj_arg)); - free_string_field (&(args_info->adj_orig)); - free_string_field (&(args_info->void_arg)); - free_string_field (&(args_info->void_orig)); - free_string_field (&(args_info->id_orig)); - free_string_field (&(args_info->mProba_orig)); - free_string_field (&(args_info->ramsesDir_arg)); - free_string_field (&(args_info->ramsesDir_orig)); - free_string_field (&(args_info->ramsesId_orig)); - free_string_field (&(args_info->configFile_arg)); - free_string_field (&(args_info->configFile_orig)); - free_string_field (&(args_info->move_arg)); - free_string_field (&(args_info->move_orig)); - free_string_field (&(args_info->output_arg)); - free_string_field (&(args_info->output_orig)); - - - - clear_given (args_info); -} - - -static void -write_into_file(FILE *outfile, const char *opt, const char *arg, const char *values[]) -{ - FIX_UNUSED (values); - if (arg) { - fprintf(outfile, "%s=\"%s\"\n", opt, arg); - } else { - fprintf(outfile, "%s\n", opt); - } -} - - -int -zobovConf_dump(FILE *outfile, struct zobovConf_info *args_info) -{ - int i = 0; - - if (!outfile) - { - fprintf (stderr, "%s: cannot dump options to stream\n", ZOBOVCONF_PACKAGE); - return EXIT_FAILURE; - } - - if (args_info->help_given) - write_into_file(outfile, "help", 0, 0 ); - if (args_info->version_given) - write_into_file(outfile, "version", 0, 0 ); - if (args_info->desc_given) - write_into_file(outfile, "desc", args_info->desc_orig, 0); - if (args_info->adj_given) - write_into_file(outfile, "adj", args_info->adj_orig, 0); - if (args_info->void_given) - write_into_file(outfile, "void", args_info->void_orig, 0); - if (args_info->id_given) - write_into_file(outfile, "id", args_info->id_orig, 0); - if (args_info->sProba_given) - write_into_file(outfile, "sProba", 0, 0 ); - if (args_info->sVol_given) - write_into_file(outfile, "sVol", 0, 0 ); - if (args_info->mProba_given) - write_into_file(outfile, "mProba", args_info->mProba_orig, 0); - if (args_info->ramsesDir_given) - write_into_file(outfile, "ramsesDir", args_info->ramsesDir_orig, 0); - if (args_info->ramsesId_given) - write_into_file(outfile, "ramsesId", args_info->ramsesId_orig, 0); - if (args_info->configFile_given) - write_into_file(outfile, "configFile", args_info->configFile_orig, 0); - if (args_info->quiet_given) - write_into_file(outfile, "quiet", 0, 0 ); - if (args_info->move_given) - write_into_file(outfile, "move", args_info->move_orig, 0); - if (args_info->galax_given) - write_into_file(outfile, "galax", 0, 0 ); - if (args_info->output_given) - write_into_file(outfile, "output", args_info->output_orig, 0); - if (args_info->interactive_given) - write_into_file(outfile, "interactive", 0, 0 ); - - - i = EXIT_SUCCESS; - return i; -} - -int -zobovConf_file_save(const char *filename, struct zobovConf_info *args_info) -{ - FILE *outfile; - int i = 0; - - outfile = fopen(filename, "w"); - - if (!outfile) - { - fprintf (stderr, "%s: cannot open file for writing: %s\n", ZOBOVCONF_PACKAGE, filename); - return EXIT_FAILURE; - } - - i = zobovConf_dump(outfile, args_info); - fclose (outfile); - - return i; -} - -void -zobovConf_free (struct zobovConf_info *args_info) -{ - zobovConf_release (args_info); -} - -/** @brief replacement of strdup, which is not standard */ -char * -gengetopt_strdup (const char *s) -{ - char *result = 0; - if (!s) - return result; - - result = (char*)malloc(strlen(s) + 1); - if (result == (char*)0) - return (char*)0; - strcpy(result, s); - return result; -} - -int -zobovConf (int argc, char * const *argv, struct zobovConf_info *args_info) -{ - return zobovConf2 (argc, argv, args_info, 0, 1, 1); -} - -int -zobovConf_ext (int argc, char * const *argv, struct zobovConf_info *args_info, - struct zobovConf_params *params) -{ - int result; - result = zobovConf_internal (argc, argv, args_info, params, 0); - - if (result == EXIT_FAILURE) - { - zobovConf_free (args_info); - exit (EXIT_FAILURE); - } - - return result; -} - -int -zobovConf2 (int argc, char * const *argv, struct zobovConf_info *args_info, int override, int initialize, int check_required) -{ - int result; - struct zobovConf_params params; - - params.override = override; - params.initialize = initialize; - params.check_required = check_required; - params.check_ambiguity = 0; - params.print_errors = 1; - - result = zobovConf_internal (argc, argv, args_info, ¶ms, 0); - - if (result == EXIT_FAILURE) - { - zobovConf_free (args_info); - exit (EXIT_FAILURE); - } - - return result; -} - -int -zobovConf_required (struct zobovConf_info *args_info, const char *prog_name) -{ - int result = EXIT_SUCCESS; - - if (zobovConf_required2(args_info, prog_name, 0) > 0) - result = EXIT_FAILURE; - - if (result == EXIT_FAILURE) - { - zobovConf_free (args_info); - exit (EXIT_FAILURE); - } - - return result; -} - -int -zobovConf_required2 (struct zobovConf_info *args_info, const char *prog_name, const char *additional_error) -{ - FIX_UNUSED (additional_error); - int error = 0; - - /* checks for required options */ - if (! args_info->desc_given) - { - fprintf (stderr, "%s: '--desc' ('-d') option required%s\n", prog_name, (additional_error ? additional_error : "")); - error = 1; - } - - if (! args_info->adj_given) - { - fprintf (stderr, "%s: '--adj' ('-a') option required%s\n", prog_name, (additional_error ? additional_error : "")); - error = 1; - } - - if (! args_info->void_given) - { - fprintf (stderr, "%s: '--void' ('-v') option required%s\n", prog_name, (additional_error ? additional_error : "")); - error = 1; - } - - if (! args_info->ramsesDir_given) - { - fprintf (stderr, "%s: '--ramsesDir' ('-b') option required%s\n", prog_name, (additional_error ? additional_error : "")); - error = 1; - } - - if (! args_info->ramsesId_given) - { - fprintf (stderr, "%s: '--ramsesId' ('-r') option required%s\n", prog_name, (additional_error ? additional_error : "")); - error = 1; - } - - - /* checks for dependences among options */ - - return error; -} - - -static char *package_name = 0; - -/** - * @brief updates an option - * @param field the generic pointer to the field to update - * @param orig_field the pointer to the orig field - * @param field_given the pointer to the number of occurrence of this option - * @param prev_given the pointer to the number of occurrence already seen - * @param value the argument for this option (if null no arg was specified) - * @param possible_values the possible values for this option (if specified) - * @param default_value the default value (in case the option only accepts fixed values) - * @param arg_type the type of this option - * @param check_ambiguity @see zobovConf_params.check_ambiguity - * @param override @see zobovConf_params.override - * @param no_free whether to free a possible previous value - * @param multiple_option whether this is a multiple option - * @param long_opt the corresponding long option - * @param short_opt the corresponding short option (or '-' if none) - * @param additional_error possible further error specification - */ -static -int update_arg(void *field, char **orig_field, - unsigned int *field_given, unsigned int *prev_given, - char *value, const char *possible_values[], - const char *default_value, - zobovConf_arg_type arg_type, - int check_ambiguity, int override, - int no_free, int multiple_option, - const char *long_opt, char short_opt, - const char *additional_error) -{ - FIX_UNUSED (field); - char *stop_char = 0; - const char *val = value; - int found; - char **string_field; - - stop_char = 0; - found = 0; - - if (!multiple_option && prev_given && (*prev_given || (check_ambiguity && *field_given))) - { - if (short_opt != '-') - fprintf (stderr, "%s: `--%s' (`-%c') option given more than once%s\n", - package_name, long_opt, short_opt, - (additional_error ? additional_error : "")); - else - fprintf (stderr, "%s: `--%s' option given more than once%s\n", - package_name, long_opt, - (additional_error ? additional_error : "")); - return 1; /* failure */ - } - - FIX_UNUSED (default_value); - - if (field_given && *field_given && ! override) - return 0; - if (prev_given) - (*prev_given)++; - if (field_given) - (*field_given)++; - if (possible_values) - val = possible_values[found]; - - switch(arg_type) { - case ARG_FLAG: - *((int *)field) = !*((int *)field); - break; - case ARG_INT: - if (val) *((int *)field) = strtol (val, &stop_char, 0); - break; - case ARG_DOUBLE: - if (val) *((double *)field) = strtod (val, &stop_char); - break; - case ARG_STRING: - if (val) { - string_field = (char **)field; - if (!no_free && *string_field) - free (*string_field); /* free previous string */ - *string_field = gengetopt_strdup (val); - } - break; - default: - break; - }; - - /* check numeric conversion */ - switch(arg_type) { - case ARG_INT: - case ARG_DOUBLE: - if (val && !(stop_char && *stop_char == '\0')) { - fprintf(stderr, "%s: invalid numeric value: %s\n", package_name, val); - return 1; /* failure */ - } - break; - default: - ; - }; - - /* store the original value */ - switch(arg_type) { - case ARG_NO: - case ARG_FLAG: - break; - default: - if (value && orig_field) { - if (no_free) { - *orig_field = value; - } else { - if (*orig_field) - free (*orig_field); /* free previous string */ - *orig_field = gengetopt_strdup (value); - } - } - }; - - return 0; /* OK */ -} - - -int -zobovConf_internal ( - int argc, char * const *argv, struct zobovConf_info *args_info, - struct zobovConf_params *params, const char *additional_error) -{ - int c; /* Character of the parsed option. */ - - int error = 0; - struct zobovConf_info local_args_info; - - int override; - int initialize; - int check_required; - int check_ambiguity; - - package_name = argv[0]; - - override = params->override; - initialize = params->initialize; - check_required = params->check_required; - check_ambiguity = params->check_ambiguity; - - if (initialize) - zobovConf_init (args_info); - - zobovConf_init (&local_args_info); - - optarg = 0; - optind = 0; - opterr = params->print_errors; - optopt = '?'; - - while (1) - { - int option_index = 0; - - static struct option long_options[] = { - { "help", 0, NULL, 'h' }, - { "version", 0, NULL, 'V' }, - { "desc", 1, NULL, 'd' }, - { "adj", 1, NULL, 'a' }, - { "void", 1, NULL, 'v' }, - { "id", 1, NULL, 'i' }, - { "sProba", 0, NULL, 's' }, - { "sVol", 0, NULL, 'l' }, - { "mProba", 1, NULL, 'm' }, - { "ramsesDir", 1, NULL, 'b' }, - { "ramsesId", 1, NULL, 'r' }, - { "configFile", 1, NULL, 'f' }, - { "quiet", 0, NULL, 'q' }, - { "move", 1, NULL, 'p' }, - { "galax", 0, NULL, 0 }, - { "output", 1, NULL, 'o' }, - { "interactive", 0, NULL, 0 }, - { 0, 0, 0, 0 } - }; - - c = getopt_long (argc, argv, "hVd:a:v:i:slm:b:r:f:qp:o:", long_options, &option_index); - - if (c == -1) break; /* Exit from `while (1)' loop. */ - - switch (c) - { - case 'h': /* Print help and exit. */ - zobovConf_print_help (); - zobovConf_free (&local_args_info); - exit (EXIT_SUCCESS); - - case 'V': /* Print version and exit. */ - zobovConf_print_version (); - zobovConf_free (&local_args_info); - exit (EXIT_SUCCESS); - - case 'd': /* The description file name for the voids. */ - - - if (update_arg( (void *)&(args_info->desc_arg), - &(args_info->desc_orig), &(args_info->desc_given), - &(local_args_info.desc_given), optarg, 0, 0, ARG_STRING, - check_ambiguity, override, 0, 0, - "desc", 'd', - additional_error)) - goto failure; - - break; - case 'a': /* Adjacent file name. */ - - - if (update_arg( (void *)&(args_info->adj_arg), - &(args_info->adj_orig), &(args_info->adj_given), - &(local_args_info.adj_given), optarg, 0, 0, ARG_STRING, - check_ambiguity, override, 0, 0, - "adj", 'a', - additional_error)) - goto failure; - - break; - case 'v': /* Void/zone bind filename. */ - - - if (update_arg( (void *)&(args_info->void_arg), - &(args_info->void_orig), &(args_info->void_given), - &(local_args_info.void_given), optarg, 0, 0, ARG_STRING, - check_ambiguity, override, 0, 0, - "void", 'v', - additional_error)) - goto failure; - - break; - case 'i': /* Void id to extract. */ - - - if (update_arg( (void *)&(args_info->id_arg), - &(args_info->id_orig), &(args_info->id_given), - &(local_args_info.id_given), optarg, 0, 0, ARG_INT, - check_ambiguity, override, 0, 0, - "id", 'i', - additional_error)) - goto failure; - - break; - case 's': /* Sort against probability. */ - - - if (update_arg((void *)&(args_info->sProba_flag), 0, &(args_info->sProba_given), - &(local_args_info.sProba_given), optarg, 0, 0, ARG_FLAG, - check_ambiguity, override, 1, 0, "sProba", 's', - additional_error)) - goto failure; - - break; - case 'l': /* Sort against volume. */ - - - if (update_arg((void *)&(args_info->sVol_flag), 0, &(args_info->sVol_given), - &(local_args_info.sVol_given), optarg, 0, 0, ARG_FLAG, - check_ambiguity, override, 1, 0, "sVol", 'l', - additional_error)) - goto failure; - - break; - case 'm': /* Minimal probability to accept. */ - - - if (update_arg( (void *)&(args_info->mProba_arg), - &(args_info->mProba_orig), &(args_info->mProba_given), - &(local_args_info.mProba_given), optarg, 0, "0.0", ARG_DOUBLE, - check_ambiguity, override, 0, 0, - "mProba", 'm', - additional_error)) - goto failure; - - break; - case 'b': /* Ramses base output directory. */ - - - if (update_arg( (void *)&(args_info->ramsesDir_arg), - &(args_info->ramsesDir_orig), &(args_info->ramsesDir_given), - &(local_args_info.ramsesDir_given), optarg, 0, 0, ARG_STRING, - check_ambiguity, override, 0, 0, - "ramsesDir", 'b', - additional_error)) - goto failure; - - break; - case 'r': /* Ramses output id. */ - - - if (update_arg( (void *)&(args_info->ramsesId_arg), - &(args_info->ramsesId_orig), &(args_info->ramsesId_given), - &(local_args_info.ramsesId_given), optarg, 0, 0, ARG_INT, - check_ambiguity, override, 0, 0, - "ramsesId", 'r', - additional_error)) - goto failure; - - break; - case 'f': /* Configuration file. */ - - - if (update_arg( (void *)&(args_info->configFile_arg), - &(args_info->configFile_orig), &(args_info->configFile_given), - &(local_args_info.configFile_given), optarg, 0, 0, ARG_STRING, - check_ambiguity, override, 0, 0, - "configFile", 'f', - additional_error)) - goto failure; - - break; - case 'q': /* Quiet mode. */ - - - if (update_arg((void *)&(args_info->quiet_flag), 0, &(args_info->quiet_given), - &(local_args_info.quiet_given), optarg, 0, 0, ARG_FLAG, - check_ambiguity, override, 1, 0, "quiet", 'q', - additional_error)) - goto failure; - - break; - case 'p': /* Move the center by (x,y,z). */ - - - if (update_arg( (void *)&(args_info->move_arg), - &(args_info->move_orig), &(args_info->move_given), - &(local_args_info.move_given), optarg, 0, "(0,0,0)", ARG_STRING, - check_ambiguity, override, 0, 0, - "move", 'p', - additional_error)) - goto failure; - - break; - case 'o': /* Output file. */ - - - if (update_arg( (void *)&(args_info->output_arg), - &(args_info->output_orig), &(args_info->output_given), - &(local_args_info.output_given), optarg, 0, "voidDesc", ARG_STRING, - check_ambiguity, override, 0, 0, - "output", 'o', - additional_error)) - goto failure; - - break; - - case 0: /* Long option with no short option */ - /* Output is galax particles. */ - if (strcmp (long_options[option_index].name, "galax") == 0) - { - - - if (update_arg((void *)&(args_info->galax_flag), 0, &(args_info->galax_given), - &(local_args_info.galax_given), optarg, 0, 0, ARG_FLAG, - check_ambiguity, override, 1, 0, "galax", '-', - additional_error)) - goto failure; - - } - /* Go in interactive mode. */ - else if (strcmp (long_options[option_index].name, "interactive") == 0) - { - - - if (update_arg((void *)&(args_info->interactive_flag), 0, &(args_info->interactive_given), - &(local_args_info.interactive_given), optarg, 0, 0, ARG_FLAG, - check_ambiguity, override, 1, 0, "interactive", '-', - additional_error)) - goto failure; - - } - - break; - case '?': /* Invalid option. */ - /* `getopt_long' already printed an error message. */ - goto failure; - - default: /* bug: option not considered. */ - fprintf (stderr, "%s: option unknown: %c%s\n", ZOBOVCONF_PACKAGE, c, (additional_error ? additional_error : "")); - abort (); - } /* switch */ - } /* while */ - - - - if (check_required) - { - error += zobovConf_required2 (args_info, argv[0], additional_error); - } - - zobovConf_release (&local_args_info); - - if ( error ) - return (EXIT_FAILURE); - - return 0; - -failure: - - zobovConf_release (&local_args_info); - return (EXIT_FAILURE); -} - -#ifndef CONFIG_FILE_LINE_SIZE -#define CONFIG_FILE_LINE_SIZE 2048 -#endif -#define ADDITIONAL_ERROR " in configuration file " - -#define CONFIG_FILE_LINE_BUFFER_SIZE (CONFIG_FILE_LINE_SIZE+3) -/* 3 is for "--" and "=" */ - -static int -_zobovConf_configfile (const char *filename, int *my_argc) -{ - FILE* file; - char my_argv[CONFIG_FILE_LINE_BUFFER_SIZE+1]; - char linebuf[CONFIG_FILE_LINE_SIZE]; - int line_num = 0; - int result = 0, equal; - char *fopt, *farg; - char *str_index; - size_t len, next_token; - char delimiter; - - if ((file = fopen(filename, "r")) == 0) - { - fprintf (stderr, "%s: Error opening configuration file '%s'\n", - ZOBOVCONF_PACKAGE, filename); - return EXIT_FAILURE; - } - - while ((fgets(linebuf, CONFIG_FILE_LINE_SIZE, file)) != 0) - { - ++line_num; - my_argv[0] = '\0'; - len = strlen(linebuf); - if (len > (CONFIG_FILE_LINE_BUFFER_SIZE-1)) - { - fprintf (stderr, "%s:%s:%d: Line too long in configuration file\n", - ZOBOVCONF_PACKAGE, filename, line_num); - result = EXIT_FAILURE; - break; - } - - /* find first non-whitespace character in the line */ - next_token = strspn (linebuf, " \t\r\n"); - str_index = linebuf + next_token; - - if ( str_index[0] == '\0' || str_index[0] == '#') - continue; /* empty line or comment line is skipped */ - - fopt = str_index; - - /* truncate fopt at the end of the first non-valid character */ - next_token = strcspn (fopt, " \t\r\n="); - - if (fopt[next_token] == '\0') /* the line is over */ - { - farg = 0; - equal = 0; - goto noarg; - } - - /* remember if equal sign is present */ - equal = (fopt[next_token] == '='); - fopt[next_token++] = '\0'; - - /* advance pointers to the next token after the end of fopt */ - next_token += strspn (fopt + next_token, " \t\r\n"); - - /* check for the presence of equal sign, and if so, skip it */ - if ( !equal ) - if ((equal = (fopt[next_token] == '='))) - { - next_token++; - next_token += strspn (fopt + next_token, " \t\r\n"); - } - str_index += next_token; - - /* find argument */ - farg = str_index; - if ( farg[0] == '\"' || farg[0] == '\'' ) - { /* quoted argument */ - str_index = strchr (++farg, str_index[0] ); /* skip opening quote */ - if (! str_index) - { - fprintf - (stderr, - "%s:%s:%d: unterminated string in configuration file\n", - ZOBOVCONF_PACKAGE, filename, line_num); - result = EXIT_FAILURE; - break; - } - } - else - { /* read up the remaining part up to a delimiter */ - next_token = strcspn (farg, " \t\r\n#\'\""); - str_index += next_token; - } - - /* truncate farg at the delimiter and store it for further check */ - delimiter = *str_index, *str_index++ = '\0'; - - /* everything but comment is illegal at the end of line */ - if (delimiter != '\0' && delimiter != '#') - { - str_index += strspn(str_index, " \t\r\n"); - if (*str_index != '\0' && *str_index != '#') - { - fprintf - (stderr, - "%s:%s:%d: malformed string in configuration file\n", - ZOBOVCONF_PACKAGE, filename, line_num); - result = EXIT_FAILURE; - break; - } - } - - noarg: - if (!strcmp(fopt,"include")) { - if (farg && *farg) { - result = _zobovConf_configfile(farg, my_argc); - } else { - fprintf(stderr, "%s:%s:%d: include requires a filename argument.\n", - ZOBOVCONF_PACKAGE, filename, line_num); - } - continue; - } - len = strlen(fopt); - strcat (my_argv, len > 1 ? "--" : "-"); - strcat (my_argv, fopt); - if (len > 1 && ((farg && *farg) || equal)) - strcat (my_argv, "="); - if (farg && *farg) - strcat (my_argv, farg); - ++(*my_argc); - - cmd_line_list_tmp = (struct line_list *) malloc (sizeof (struct line_list)); - cmd_line_list_tmp->next = cmd_line_list; - cmd_line_list = cmd_line_list_tmp; - cmd_line_list->string_arg = gengetopt_strdup(my_argv); - } /* while */ - - if (file) - fclose(file); - return result; -} - -int -zobovConf_configfile ( - const char *filename, - struct zobovConf_info *args_info, - int override, int initialize, int check_required) -{ - struct zobovConf_params params; - - params.override = override; - params.initialize = initialize; - params.check_required = check_required; - params.check_ambiguity = 0; - params.print_errors = 1; - - return zobovConf_config_file (filename, args_info, ¶ms); -} - -int -zobovConf_config_file (const char *filename, - struct zobovConf_info *args_info, - struct zobovConf_params *params) -{ - int i, result; - int my_argc = 1; - char **my_argv_arg; - char *additional_error; - - /* store the program name */ - cmd_line_list_tmp = (struct line_list *) malloc (sizeof (struct line_list)); - cmd_line_list_tmp->next = cmd_line_list; - cmd_line_list = cmd_line_list_tmp; - cmd_line_list->string_arg = gengetopt_strdup (ZOBOVCONF_PACKAGE); - - result = _zobovConf_configfile(filename, &my_argc); - - if (result != EXIT_FAILURE) { - my_argv_arg = (char **) malloc((my_argc+1) * sizeof(char *)); - cmd_line_list_tmp = cmd_line_list; - - for (i = my_argc - 1; i >= 0; --i) { - my_argv_arg[i] = cmd_line_list_tmp->string_arg; - cmd_line_list_tmp = cmd_line_list_tmp->next; - } - - my_argv_arg[my_argc] = 0; - - additional_error = (char *)malloc(strlen(filename) + strlen(ADDITIONAL_ERROR) + 1); - strcpy (additional_error, ADDITIONAL_ERROR); - strcat (additional_error, filename); - result = - zobovConf_internal (my_argc, my_argv_arg, args_info, - params, - additional_error); - - free (additional_error); - free (my_argv_arg); - } - - free_cmd_list(); - if (result == EXIT_FAILURE) - { - zobovConf_free (args_info); - exit (EXIT_FAILURE); - } - - return result; -} diff --git a/mytools/zobovConf.h b/mytools/zobovConf.h deleted file mode 100644 index 0b15094..0000000 --- a/mytools/zobovConf.h +++ /dev/null @@ -1,251 +0,0 @@ -/** @file zobovConf.h - * @brief The header file for the command line option parser - * generated by GNU Gengetopt version 2.22.2 - * http://www.gnu.org/software/gengetopt. - * DO NOT modify this file, since it can be overwritten - * @author GNU Gengetopt by Lorenzo Bettini */ - -#ifndef ZOBOVCONF_H -#define ZOBOVCONF_H - -/* If we use autoconf. */ -#ifdef HAVE_CONFIG_H -#include "config.h" -#endif - -#include /* for FILE */ - -#ifdef __cplusplus -extern "C" { -#endif /* __cplusplus */ - -#ifndef ZOBOVCONF_PACKAGE -/** @brief the program name (used for printing errors) */ -#define ZOBOVCONF_PACKAGE "showZobov" -#endif - -#ifndef ZOBOVCONF_PACKAGE_NAME -/** @brief the complete program name (used for help and version) */ -#define ZOBOVCONF_PACKAGE_NAME "showZobov" -#endif - -#ifndef ZOBOVCONF_VERSION -/** @brief the program version */ -#define ZOBOVCONF_VERSION "0" -#endif - -/** @brief Where the command line options are stored */ -struct zobovConf_info -{ - const char *help_help; /**< @brief Print help and exit help description. */ - const char *version_help; /**< @brief Print version and exit help description. */ - char * desc_arg; /**< @brief The description file name for the voids. */ - char * desc_orig; /**< @brief The description file name for the voids original value given at command line. */ - const char *desc_help; /**< @brief The description file name for the voids help description. */ - char * adj_arg; /**< @brief Adjacent file name. */ - char * adj_orig; /**< @brief Adjacent file name original value given at command line. */ - const char *adj_help; /**< @brief Adjacent file name help description. */ - char * void_arg; /**< @brief Void/zone bind filename. */ - char * void_orig; /**< @brief Void/zone bind filename original value given at command line. */ - const char *void_help; /**< @brief Void/zone bind filename help description. */ - int id_arg; /**< @brief Void id to extract. */ - char * id_orig; /**< @brief Void id to extract original value given at command line. */ - const char *id_help; /**< @brief Void id to extract help description. */ - int sProba_flag; /**< @brief Sort against probability (default=off). */ - const char *sProba_help; /**< @brief Sort against probability help description. */ - int sVol_flag; /**< @brief Sort against volume (default=on). */ - const char *sVol_help; /**< @brief Sort against volume help description. */ - double mProba_arg; /**< @brief Minimal probability to accept (default='0.0'). */ - char * mProba_orig; /**< @brief Minimal probability to accept original value given at command line. */ - const char *mProba_help; /**< @brief Minimal probability to accept help description. */ - char * ramsesDir_arg; /**< @brief Ramses base output directory. */ - char * ramsesDir_orig; /**< @brief Ramses base output directory original value given at command line. */ - const char *ramsesDir_help; /**< @brief Ramses base output directory help description. */ - int ramsesId_arg; /**< @brief Ramses output id. */ - char * ramsesId_orig; /**< @brief Ramses output id original value given at command line. */ - const char *ramsesId_help; /**< @brief Ramses output id help description. */ - char * configFile_arg; /**< @brief Configuration file. */ - char * configFile_orig; /**< @brief Configuration file original value given at command line. */ - const char *configFile_help; /**< @brief Configuration file help description. */ - int quiet_flag; /**< @brief Quiet mode (default=off). */ - const char *quiet_help; /**< @brief Quiet mode help description. */ - char * move_arg; /**< @brief Move the center by (x,y,z) (default='(0,0,0)'). */ - char * move_orig; /**< @brief Move the center by (x,y,z) original value given at command line. */ - const char *move_help; /**< @brief Move the center by (x,y,z) help description. */ - int galax_flag; /**< @brief Output is galax particles (default=off). */ - const char *galax_help; /**< @brief Output is galax particles help description. */ - char * output_arg; /**< @brief Output file (default='voidDesc'). */ - char * output_orig; /**< @brief Output file original value given at command line. */ - const char *output_help; /**< @brief Output file help description. */ - int interactive_flag; /**< @brief Go in interactive mode (default=off). */ - const char *interactive_help; /**< @brief Go in interactive mode help description. */ - - unsigned int help_given ; /**< @brief Whether help was given. */ - unsigned int version_given ; /**< @brief Whether version was given. */ - unsigned int desc_given ; /**< @brief Whether desc was given. */ - unsigned int adj_given ; /**< @brief Whether adj was given. */ - unsigned int void_given ; /**< @brief Whether void was given. */ - unsigned int id_given ; /**< @brief Whether id was given. */ - unsigned int sProba_given ; /**< @brief Whether sProba was given. */ - unsigned int sVol_given ; /**< @brief Whether sVol was given. */ - unsigned int mProba_given ; /**< @brief Whether mProba was given. */ - unsigned int ramsesDir_given ; /**< @brief Whether ramsesDir was given. */ - unsigned int ramsesId_given ; /**< @brief Whether ramsesId was given. */ - unsigned int configFile_given ; /**< @brief Whether configFile was given. */ - unsigned int quiet_given ; /**< @brief Whether quiet was given. */ - unsigned int move_given ; /**< @brief Whether move was given. */ - unsigned int galax_given ; /**< @brief Whether galax was given. */ - unsigned int output_given ; /**< @brief Whether output was given. */ - unsigned int interactive_given ; /**< @brief Whether interactive was given. */ - -} ; - -/** @brief The additional parameters to pass to parser functions */ -struct zobovConf_params -{ - int override; /**< @brief whether to override possibly already present options (default 0) */ - int initialize; /**< @brief whether to initialize the option structure zobovConf_info (default 1) */ - int check_required; /**< @brief whether to check that all required options were provided (default 1) */ - int check_ambiguity; /**< @brief whether to check for options already specified in the option structure zobovConf_info (default 0) */ - int print_errors; /**< @brief whether getopt_long should print an error message for a bad option (default 1) */ -} ; - -/** @brief the purpose string of the program */ -extern const char *zobovConf_info_purpose; -/** @brief the usage string of the program */ -extern const char *zobovConf_info_usage; -/** @brief all the lines making the help output */ -extern const char *zobovConf_info_help[]; - -/** - * The command line parser - * @param argc the number of command line options - * @param argv the command line options - * @param args_info the structure where option information will be stored - * @return 0 if everything went fine, NON 0 if an error took place - */ -int zobovConf (int argc, char * const *argv, - struct zobovConf_info *args_info); - -/** - * The command line parser (version with additional parameters - deprecated) - * @param argc the number of command line options - * @param argv the command line options - * @param args_info the structure where option information will be stored - * @param override whether to override possibly already present options - * @param initialize whether to initialize the option structure my_args_info - * @param check_required whether to check that all required options were provided - * @return 0 if everything went fine, NON 0 if an error took place - * @deprecated use zobovConf_ext() instead - */ -int zobovConf2 (int argc, char * const *argv, - struct zobovConf_info *args_info, - int override, int initialize, int check_required); - -/** - * The command line parser (version with additional parameters) - * @param argc the number of command line options - * @param argv the command line options - * @param args_info the structure where option information will be stored - * @param params additional parameters for the parser - * @return 0 if everything went fine, NON 0 if an error took place - */ -int zobovConf_ext (int argc, char * const *argv, - struct zobovConf_info *args_info, - struct zobovConf_params *params); - -/** - * Save the contents of the option struct into an already open FILE stream. - * @param outfile the stream where to dump options - * @param args_info the option struct to dump - * @return 0 if everything went fine, NON 0 if an error took place - */ -int zobovConf_dump(FILE *outfile, - struct zobovConf_info *args_info); - -/** - * Save the contents of the option struct into a (text) file. - * This file can be read by the config file parser (if generated by gengetopt) - * @param filename the file where to save - * @param args_info the option struct to save - * @return 0 if everything went fine, NON 0 if an error took place - */ -int zobovConf_file_save(const char *filename, - struct zobovConf_info *args_info); - -/** - * Print the help - */ -void zobovConf_print_help(void); -/** - * Print the version - */ -void zobovConf_print_version(void); - -/** - * Initializes all the fields a zobovConf_params structure - * to their default values - * @param params the structure to initialize - */ -void zobovConf_params_init(struct zobovConf_params *params); - -/** - * Allocates dynamically a zobovConf_params structure and initializes - * all its fields to their default values - * @return the created and initialized zobovConf_params structure - */ -struct zobovConf_params *zobovConf_params_create(void); - -/** - * Initializes the passed zobovConf_info structure's fields - * (also set default values for options that have a default) - * @param args_info the structure to initialize - */ -void zobovConf_init (struct zobovConf_info *args_info); -/** - * Deallocates the string fields of the zobovConf_info structure - * (but does not deallocate the structure itself) - * @param args_info the structure to deallocate - */ -void zobovConf_free (struct zobovConf_info *args_info); - -/** - * The config file parser (deprecated version) - * @param filename the name of the config file - * @param args_info the structure where option information will be stored - * @param override whether to override possibly already present options - * @param initialize whether to initialize the option structure my_args_info - * @param check_required whether to check that all required options were provided - * @return 0 if everything went fine, NON 0 if an error took place - * @deprecated use zobovConf_config_file() instead - */ -int zobovConf_configfile (const char *filename, - struct zobovConf_info *args_info, - int override, int initialize, int check_required); - -/** - * The config file parser - * @param filename the name of the config file - * @param args_info the structure where option information will be stored - * @param params additional parameters for the parser - * @return 0 if everything went fine, NON 0 if an error took place - */ -int zobovConf_config_file (const char *filename, - struct zobovConf_info *args_info, - struct zobovConf_params *params); - -/** - * Checks that all the required options were specified - * @param args_info the structure to check - * @param prog_name the name of the program that will be used to print - * possible errors - * @return - */ -int zobovConf_required (struct zobovConf_info *args_info, - const char *prog_name); - - -#ifdef __cplusplus -} -#endif /* __cplusplus */ -#endif /* ZOBOVCONF_H */