00001
00011 #include "metisbin.h"
00012
00013
00014
00015
00016
00017 static struct gk_option long_options[] = {
00018 {"gtype", 1, 0, METIS_OPTION_GTYPE},
00019 {"ncommon", 1, 0, METIS_OPTION_NCOMMON},
00020
00021 {"dbglvl", 1, 0, METIS_OPTION_DBGLVL},
00022
00023 {"help", 0, 0, METIS_OPTION_HELP},
00024 {0, 0, 0, 0}
00025 };
00026
00027
00028
00029
00030
00031
00032 static gk_StringMap_t gtype_options[] = {
00033 {"dual", METIS_GTYPE_DUAL},
00034 {"nodal", METIS_GTYPE_NODAL},
00035 {NULL, 0}
00036 };
00037
00038
00039
00040
00041
00042 static char helpstr[][100] =
00043 {
00044 " ",
00045 "Usage: m2gmetis [options] <meshfile> <graphfile>",
00046 " ",
00047 " Required parameters",
00048 " meshfile Stores the input mesh.",
00049 " graphfile The filename of the output graph.",
00050 " ",
00051 " Optional parameters",
00052 " -gtype=string",
00053 " Specifies the graph that will be generated.",
00054 " The possible values are:",
00055 " dual - Generate dual graph of the mesh [default]",
00056 " nodal - Generate the nodal graph of the mesh",
00057 " ",
00058 " -ncommon=int [applies when gtype=dual]",
00059 " Specifies the common number of nodes that two elements must have",
00060 " in order to put an edge between them in the dual graph. Default is 1.",
00061 " ",
00062 " -dbglvl=int ",
00063 " Selects the dbglvl.",
00064 " ",
00065 " -help",
00066 " Prints this message.",
00067 ""
00068 };
00069
00070 static char shorthelpstr[][100] = {
00071 " ",
00072 " Usage: m2gmetis [options] <meshfile> <graphfile>",
00073 " use 'm2gmetis -help' for a summary of the options.",
00074 ""
00075 };
00076
00077
00078
00079
00080
00081
00082 params_t *parse_cmdline(int argc, char *argv[])
00083 {
00084 int i, j, k;
00085 int c, option_index;
00086 params_t *params;
00087
00088 params = (params_t *)gk_malloc(sizeof(params_t), "parse_cmdline");
00089 memset((void *)params, 0, sizeof(params_t));
00090
00091
00092 params->gtype = METIS_GTYPE_DUAL;
00093 params->ncommon = 1;
00094 params->dbglvl = 0;
00095 params->filename = NULL;
00096 params->outfile = NULL;
00097
00098
00099 gk_clearcputimer(params->iotimer);
00100 gk_clearcputimer(params->parttimer);
00101 gk_clearcputimer(params->reporttimer);
00102
00103
00104
00105 while ((c = gk_getopt_long_only(argc, argv, "", long_options, &option_index)) != -1) {
00106 switch (c) {
00107 case METIS_OPTION_GTYPE:
00108 if (gk_optarg)
00109 if ((params->gtype = gk_GetStringID(gtype_options, gk_optarg)) == -1)
00110 errexit("Invalid option -%s=%s\n", long_options[option_index].name, gk_optarg);
00111 break;
00112
00113 case METIS_OPTION_NCOMMON:
00114 if (gk_optarg) params->ncommon = (idx_t)atoi(gk_optarg);
00115 if (params->ncommon < 1)
00116 errexit("The -ncommon option should specify a number >= 1.\n");
00117 break;
00118
00119 case METIS_OPTION_DBGLVL:
00120 if (gk_optarg) params->dbglvl = (idx_t)atoi(gk_optarg);
00121 break;
00122
00123 case METIS_OPTION_HELP:
00124 for (i=0; strlen(helpstr[i]) > 0; i++)
00125 printf("%s\n", helpstr[i]);
00126 exit(0);
00127 break;
00128 case '?':
00129 default:
00130 errexit("Illegal command-line option(s)\n"
00131 "Use %s -help for a summary of the options.\n", argv[0]);
00132 }
00133 }
00134
00135 if (argc-gk_optind != 2) {
00136 printf("Missing parameters.");
00137 for (i=0; strlen(shorthelpstr[i]) > 0; i++)
00138 printf("%s\n", shorthelpstr[i]);
00139 exit(0);
00140 }
00141
00142 params->filename = gk_strdup(argv[gk_optind++]);
00143 params->outfile = gk_strdup(argv[gk_optind++]);
00144
00145 return params;
00146 }
00147
00148