| 1 | /* | 
| 2 | File autogenerated by gengetopt version 2.11 | 
| 3 | generated with the following command: | 
| 4 | gengetopt -i Dump2XYZ.ggo | 
| 5 |  | 
| 6 | The developers of gengetopt consider the fixed text that goes in all | 
| 7 | gengetopt output files to be in the public domain: | 
| 8 | we make no copyright claims on it. | 
| 9 | */ | 
| 10 |  | 
| 11 |  | 
| 12 | #include <stdio.h> | 
| 13 | #include <stdlib.h> | 
| 14 | #include <string.h> | 
| 15 |  | 
| 16 | /* If we use autoconf.  */ | 
| 17 | #ifdef HAVE_CONFIG_H | 
| 18 | #include "config.h" | 
| 19 | #endif | 
| 20 |  | 
| 21 | #include "getopt.h" | 
| 22 |  | 
| 23 | #include "Dump2XYZCmd.h" | 
| 24 |  | 
| 25 | void | 
| 26 | cmdline_parser_print_version (void) | 
| 27 | { | 
| 28 | printf ("%s %s\n", CMDLINE_PARSER_PACKAGE, CMDLINE_PARSER_VERSION); | 
| 29 | } | 
| 30 |  | 
| 31 | void | 
| 32 | cmdline_parser_print_help (void) | 
| 33 | { | 
| 34 | cmdline_parser_print_version (); | 
| 35 | printf("\n" | 
| 36 | "Usage: %s [OPTIONS]...\n", CMDLINE_PARSER_PACKAGE); | 
| 37 | printf("\n"); | 
| 38 | printf("  -h, --help                        Print help and exit\n"); | 
| 39 | printf("  -V, --version                     Print version and exit\n"); | 
| 40 | printf("  -i, --input=filename              input dump file\n"); | 
| 41 | printf("  -o, --output=filename             output file name\n"); | 
| 42 | printf("  -n, --frame=INT                   print every n frame  (default=`1')\n"); | 
| 43 | printf("  -d, --dipole                      print the dipole moments  (default=off)\n"); | 
| 44 | printf("  -w, --water                       skip the the waters  (default=off)\n"); | 
| 45 | printf("  -m, --periodicBox                 map to the periodic box  (default=off)\n"); | 
| 46 | printf("  -z, --zconstraint                 replace the atom types of zconstraint \n                                      molecules  (default=off)\n"); | 
| 47 | printf("  -r, --rigidbody                   add a pseudo COM atom to rigidbody  \n                                      (default=off)\n"); | 
| 48 | printf("  -t, --watertype                   replace the atom type of water model  \n                                      (default=on)\n"); | 
| 49 | printf("  -g, --ignore=atomtype             ignore the atom types\n"); | 
| 50 | printf("  -s, --selection=selection script  general selection syntax(now only support \n                                      select atoms within a specified range)\n"); | 
| 51 | printf("      --repeatX=INT                 The number of images to repeat in the x \n                                      direction  (default=`0')\n"); | 
| 52 | printf("      --repeatY=INT                 The number of images to repeat in the y \n                                      direction  (default=`0')\n"); | 
| 53 | printf("      --repeatZ=INT                 The number of images to repeat in the z \n                                      direction  (default=`0')\n"); | 
| 54 | } | 
| 55 |  | 
| 56 |  | 
| 57 | static char *gengetopt_strdup (const char *s); | 
| 58 |  | 
| 59 | /* gengetopt_strdup() */ | 
| 60 | /* strdup.c replacement of strdup, which is not standard */ | 
| 61 | char * | 
| 62 | gengetopt_strdup (const char *s) | 
| 63 | { | 
| 64 | char *result = (char*)malloc(strlen(s) + 1); | 
| 65 | if (result == (char*)0) | 
| 66 | return (char*)0; | 
| 67 | strcpy(result, s); | 
| 68 | return result; | 
| 69 | } | 
| 70 |  | 
| 71 | int | 
| 72 | cmdline_parser (int argc, char * const *argv, struct gengetopt_args_info *args_info) | 
| 73 | { | 
| 74 | int c;        /* Character of the parsed option.  */ | 
| 75 | int i;        /* Counter */ | 
| 76 | struct ignore_list | 
| 77 | { | 
| 78 | char * ignore_arg; | 
| 79 | struct ignore_list * next; | 
| 80 | }; | 
| 81 | struct ignore_list * ignore_list = NULL,* ignore_new = NULL; | 
| 82 |  | 
| 83 | int missing_required_options = 0; | 
| 84 |  | 
| 85 | args_info->help_given = 0 ; | 
| 86 | args_info->version_given = 0 ; | 
| 87 | args_info->input_given = 0 ; | 
| 88 | args_info->output_given = 0 ; | 
| 89 | args_info->frame_given = 0 ; | 
| 90 | args_info->dipole_given = 0 ; | 
| 91 | args_info->water_given = 0 ; | 
| 92 | args_info->periodicBox_given = 0 ; | 
| 93 | args_info->zconstraint_given = 0 ; | 
| 94 | args_info->rigidbody_given = 0 ; | 
| 95 | args_info->watertype_given = 0 ; | 
| 96 | args_info->ignore_given = 0 ; | 
| 97 | args_info->selection_given = 0 ; | 
| 98 | args_info->repeatX_given = 0 ; | 
| 99 | args_info->repeatY_given = 0 ; | 
| 100 | args_info->repeatZ_given = 0 ; | 
| 101 | #define clear_args() { \ | 
| 102 | args_info->input_arg = NULL; \ | 
| 103 | args_info->output_arg = NULL; \ | 
| 104 | args_info->frame_arg = 1 ;\ | 
| 105 | args_info->dipole_flag = 0;\ | 
| 106 | args_info->water_flag = 0;\ | 
| 107 | args_info->periodicBox_flag = 0;\ | 
| 108 | args_info->zconstraint_flag = 0;\ | 
| 109 | args_info->rigidbody_flag = 0;\ | 
| 110 | args_info->watertype_flag = 1;\ | 
| 111 | args_info->ignore_arg = NULL; \ | 
| 112 | args_info->selection_arg = NULL; \ | 
| 113 | args_info->repeatX_arg = 0 ;\ | 
| 114 | args_info->repeatY_arg = 0 ;\ | 
| 115 | args_info->repeatZ_arg = 0 ;\ | 
| 116 | } | 
| 117 |  | 
| 118 | clear_args(); | 
| 119 |  | 
| 120 | optarg = 0; | 
| 121 | optind = 1; | 
| 122 | opterr = 1; | 
| 123 | optopt = '?'; | 
| 124 |  | 
| 125 | while (1) | 
| 126 | { | 
| 127 | int option_index = 0; | 
| 128 | char *stop_char; | 
| 129 |  | 
| 130 | static struct option long_options[] = { | 
| 131 | { "help",       0, NULL, 'h' }, | 
| 132 | { "version",    0, NULL, 'V' }, | 
| 133 | { "input",      1, NULL, 'i' }, | 
| 134 | { "output",     1, NULL, 'o' }, | 
| 135 | { "frame",      1, NULL, 'n' }, | 
| 136 | { "dipole",     0, NULL, 'd' }, | 
| 137 | { "water",      0, NULL, 'w' }, | 
| 138 | { "periodicBox",        0, NULL, 'm' }, | 
| 139 | { "zconstraint",        0, NULL, 'z' }, | 
| 140 | { "rigidbody",  0, NULL, 'r' }, | 
| 141 | { "watertype",  0, NULL, 't' }, | 
| 142 | { "ignore",     1, NULL, 'g' }, | 
| 143 | { "selection",  1, NULL, 's' }, | 
| 144 | { "repeatX",    1, NULL, 0 }, | 
| 145 | { "repeatY",    1, NULL, 0 }, | 
| 146 | { "repeatZ",    1, NULL, 0 }, | 
| 147 | { NULL, 0, NULL, 0 } | 
| 148 | }; | 
| 149 |  | 
| 150 | stop_char = 0; | 
| 151 | c = getopt_long (argc, argv, "hVi:o:n:dwmzrtg:s:", long_options, &option_index); | 
| 152 |  | 
| 153 | if (c == -1) break;       /* Exit from `while (1)' loop.  */ | 
| 154 |  | 
| 155 | switch (c) | 
| 156 | { | 
| 157 | case 'h':       /* Print help and exit.  */ | 
| 158 | clear_args (); | 
| 159 | cmdline_parser_print_help (); | 
| 160 | exit (EXIT_SUCCESS); | 
| 161 |  | 
| 162 | case 'V':       /* Print version and exit.  */ | 
| 163 | clear_args (); | 
| 164 | cmdline_parser_print_version (); | 
| 165 | exit (EXIT_SUCCESS); | 
| 166 |  | 
| 167 | case 'i':       /* input dump file.  */ | 
| 168 | if (args_info->input_given) | 
| 169 | { | 
| 170 | fprintf (stderr, "%s: `--input' (`-i') option given more than once\n", CMDLINE_PARSER_PACKAGE); | 
| 171 | clear_args (); | 
| 172 | exit (EXIT_FAILURE); | 
| 173 | } | 
| 174 | args_info->input_given = 1; | 
| 175 | args_info->input_arg = gengetopt_strdup (optarg); | 
| 176 | break; | 
| 177 |  | 
| 178 | case 'o':       /* output file name.  */ | 
| 179 | if (args_info->output_given) | 
| 180 | { | 
| 181 | fprintf (stderr, "%s: `--output' (`-o') option given more than once\n", CMDLINE_PARSER_PACKAGE); | 
| 182 | clear_args (); | 
| 183 | exit (EXIT_FAILURE); | 
| 184 | } | 
| 185 | args_info->output_given = 1; | 
| 186 | args_info->output_arg = gengetopt_strdup (optarg); | 
| 187 | break; | 
| 188 |  | 
| 189 | case 'n':       /* print every n frame.  */ | 
| 190 | if (args_info->frame_given) | 
| 191 | { | 
| 192 | fprintf (stderr, "%s: `--frame' (`-n') option given more than once\n", CMDLINE_PARSER_PACKAGE); | 
| 193 | clear_args (); | 
| 194 | exit (EXIT_FAILURE); | 
| 195 | } | 
| 196 | args_info->frame_given = 1; | 
| 197 | args_info->frame_arg = strtol (optarg,&stop_char,0); | 
| 198 | break; | 
| 199 |  | 
| 200 | case 'd':       /* print the dipole moments.  */ | 
| 201 | if (args_info->dipole_given) | 
| 202 | { | 
| 203 | fprintf (stderr, "%s: `--dipole' (`-d') option given more than once\n", CMDLINE_PARSER_PACKAGE); | 
| 204 | clear_args (); | 
| 205 | exit (EXIT_FAILURE); | 
| 206 | } | 
| 207 | args_info->dipole_given = 1; | 
| 208 | args_info->dipole_flag = !(args_info->dipole_flag); | 
| 209 | break; | 
| 210 |  | 
| 211 | case 'w':       /* skip the the waters.  */ | 
| 212 | if (args_info->water_given) | 
| 213 | { | 
| 214 | fprintf (stderr, "%s: `--water' (`-w') option given more than once\n", CMDLINE_PARSER_PACKAGE); | 
| 215 | clear_args (); | 
| 216 | exit (EXIT_FAILURE); | 
| 217 | } | 
| 218 | args_info->water_given = 1; | 
| 219 | args_info->water_flag = !(args_info->water_flag); | 
| 220 | break; | 
| 221 |  | 
| 222 | case 'm':       /* map to the periodic box.  */ | 
| 223 | if (args_info->periodicBox_given) | 
| 224 | { | 
| 225 | fprintf (stderr, "%s: `--periodicBox' (`-m') option given more than once\n", CMDLINE_PARSER_PACKAGE); | 
| 226 | clear_args (); | 
| 227 | exit (EXIT_FAILURE); | 
| 228 | } | 
| 229 | args_info->periodicBox_given = 1; | 
| 230 | args_info->periodicBox_flag = !(args_info->periodicBox_flag); | 
| 231 | break; | 
| 232 |  | 
| 233 | case 'z':       /* replace the atom types of zconstraint molecules.  */ | 
| 234 | if (args_info->zconstraint_given) | 
| 235 | { | 
| 236 | fprintf (stderr, "%s: `--zconstraint' (`-z') option given more than once\n", CMDLINE_PARSER_PACKAGE); | 
| 237 | clear_args (); | 
| 238 | exit (EXIT_FAILURE); | 
| 239 | } | 
| 240 | args_info->zconstraint_given = 1; | 
| 241 | args_info->zconstraint_flag = !(args_info->zconstraint_flag); | 
| 242 | break; | 
| 243 |  | 
| 244 | case 'r':       /* add a pseudo COM atom to rigidbody.  */ | 
| 245 | if (args_info->rigidbody_given) | 
| 246 | { | 
| 247 | fprintf (stderr, "%s: `--rigidbody' (`-r') option given more than once\n", CMDLINE_PARSER_PACKAGE); | 
| 248 | clear_args (); | 
| 249 | exit (EXIT_FAILURE); | 
| 250 | } | 
| 251 | args_info->rigidbody_given = 1; | 
| 252 | args_info->rigidbody_flag = !(args_info->rigidbody_flag); | 
| 253 | break; | 
| 254 |  | 
| 255 | case 't':       /* replace the atom type of water model.  */ | 
| 256 | if (args_info->watertype_given) | 
| 257 | { | 
| 258 | fprintf (stderr, "%s: `--watertype' (`-t') option given more than once\n", CMDLINE_PARSER_PACKAGE); | 
| 259 | clear_args (); | 
| 260 | exit (EXIT_FAILURE); | 
| 261 | } | 
| 262 | args_info->watertype_given = 1; | 
| 263 | args_info->watertype_flag = !(args_info->watertype_flag); | 
| 264 | break; | 
| 265 |  | 
| 266 | case 'g':       /* ignore the atom types.  */ | 
| 267 | args_info->ignore_given++; | 
| 268 | ignore_new = (struct ignore_list *) malloc (sizeof (struct ignore_list)); | 
| 269 | ignore_new->next = ignore_list; | 
| 270 | ignore_list = ignore_new; | 
| 271 | ignore_new->ignore_arg = gengetopt_strdup (optarg); | 
| 272 | break; | 
| 273 |  | 
| 274 | case 's':       /* general selection syntax(now only support select atoms within a specified range).  */ | 
| 275 | if (args_info->selection_given) | 
| 276 | { | 
| 277 | fprintf (stderr, "%s: `--selection' (`-s') option given more than once\n", CMDLINE_PARSER_PACKAGE); | 
| 278 | clear_args (); | 
| 279 | exit (EXIT_FAILURE); | 
| 280 | } | 
| 281 | args_info->selection_given = 1; | 
| 282 | args_info->selection_arg = gengetopt_strdup (optarg); | 
| 283 | break; | 
| 284 |  | 
| 285 |  | 
| 286 | case 0: /* Long option with no short option */ | 
| 287 | /* The number of images to repeat in the x direction.  */ | 
| 288 | if (strcmp (long_options[option_index].name, "repeatX") == 0) | 
| 289 | { | 
| 290 | if (args_info->repeatX_given) | 
| 291 | { | 
| 292 | fprintf (stderr, "%s: `--repeatX' option given more than once\n", CMDLINE_PARSER_PACKAGE); | 
| 293 | clear_args (); | 
| 294 | exit (EXIT_FAILURE); | 
| 295 | } | 
| 296 | args_info->repeatX_given = 1; | 
| 297 | args_info->repeatX_arg = strtol (optarg,&stop_char,0); | 
| 298 | break; | 
| 299 | } | 
| 300 |  | 
| 301 | /* The number of images to repeat in the y direction.  */ | 
| 302 | else if (strcmp (long_options[option_index].name, "repeatY") == 0) | 
| 303 | { | 
| 304 | if (args_info->repeatY_given) | 
| 305 | { | 
| 306 | fprintf (stderr, "%s: `--repeatY' option given more than once\n", CMDLINE_PARSER_PACKAGE); | 
| 307 | clear_args (); | 
| 308 | exit (EXIT_FAILURE); | 
| 309 | } | 
| 310 | args_info->repeatY_given = 1; | 
| 311 | args_info->repeatY_arg = strtol (optarg,&stop_char,0); | 
| 312 | break; | 
| 313 | } | 
| 314 |  | 
| 315 | /* The number of images to repeat in the z direction.  */ | 
| 316 | else if (strcmp (long_options[option_index].name, "repeatZ") == 0) | 
| 317 | { | 
| 318 | if (args_info->repeatZ_given) | 
| 319 | { | 
| 320 | fprintf (stderr, "%s: `--repeatZ' option given more than once\n", CMDLINE_PARSER_PACKAGE); | 
| 321 | clear_args (); | 
| 322 | exit (EXIT_FAILURE); | 
| 323 | } | 
| 324 | args_info->repeatZ_given = 1; | 
| 325 | args_info->repeatZ_arg = strtol (optarg,&stop_char,0); | 
| 326 | break; | 
| 327 | } | 
| 328 |  | 
| 329 |  | 
| 330 | case '?':       /* Invalid option.  */ | 
| 331 | /* `getopt_long' already printed an error message.  */ | 
| 332 | exit (EXIT_FAILURE); | 
| 333 |  | 
| 334 | default:        /* bug: option not considered.  */ | 
| 335 | fprintf (stderr, "%s: option unknown: %c\n", CMDLINE_PARSER_PACKAGE, c); | 
| 336 | abort (); | 
| 337 | } /* switch */ | 
| 338 | } /* while */ | 
| 339 |  | 
| 340 |  | 
| 341 | if (! args_info->input_given) | 
| 342 | { | 
| 343 | fprintf (stderr, "%s: '--input' ('-i') option required\n", CMDLINE_PARSER_PACKAGE); | 
| 344 | missing_required_options = 1; | 
| 345 | } | 
| 346 | if ( missing_required_options ) | 
| 347 | exit (EXIT_FAILURE); | 
| 348 |  | 
| 349 | if (args_info->ignore_given) | 
| 350 | { | 
| 351 | args_info->ignore_arg = (char * *) malloc (args_info->ignore_given * sizeof (char *)); | 
| 352 | for (i = 0; i < args_info->ignore_given; i++) | 
| 353 | { | 
| 354 | args_info->ignore_arg [i] = ignore_list->ignore_arg; | 
| 355 | ignore_list = ignore_list->next; | 
| 356 | } | 
| 357 | } | 
| 358 |  | 
| 359 | return 0; | 
| 360 | } |