Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
ElmerCSC
GitHub Repository: ElmerCSC/elmerfem
Path: blob/devel/elmergrid/src/metis-5.1.0/programs/cmdline_m2gmetis.c
3206 views
1
/*!
2
\file cmdline_m2gmetis.c
3
4
\brief Command-line argument parsing for m2gmetis
5
6
\date 12/24/2008
7
\author George
8
\version\verbatim $Id: cmdline_m2gmetis.c 10046 2011-06-01 14:13:40Z karypis $\endverbatim
9
*/
10
11
#include "metisbin.h"
12
13
14
/*-------------------------------------------------------------------
15
* Command-line options
16
*-------------------------------------------------------------------*/
17
static struct gk_option long_options[] = {
18
{"gtype", 1, 0, METIS_OPTION_GTYPE},
19
{"ncommon", 1, 0, METIS_OPTION_NCOMMON},
20
21
{"dbglvl", 1, 0, METIS_OPTION_DBGLVL},
22
23
{"help", 0, 0, METIS_OPTION_HELP},
24
{0, 0, 0, 0}
25
};
26
27
28
29
/*-------------------------------------------------------------------
30
* Mappings for the various parameter values
31
*-------------------------------------------------------------------*/
32
static gk_StringMap_t gtype_options[] = {
33
{"dual", METIS_GTYPE_DUAL},
34
{"nodal", METIS_GTYPE_NODAL},
35
{NULL, 0}
36
};
37
38
39
/*-------------------------------------------------------------------
40
* Mini help
41
*-------------------------------------------------------------------*/
42
static char helpstr[][100] =
43
{
44
" ",
45
"Usage: m2gmetis [options] <meshfile> <graphfile>",
46
" ",
47
" Required parameters",
48
" meshfile Stores the input mesh.",
49
" graphfile The filename of the output graph.",
50
" ",
51
" Optional parameters",
52
" -gtype=string",
53
" Specifies the graph that will be generated.",
54
" The possible values are:",
55
" dual - Generate dual graph of the mesh [default]",
56
" nodal - Generate the nodal graph of the mesh",
57
" ",
58
" -ncommon=int [applies when gtype=dual]",
59
" Specifies the common number of nodes that two elements must have",
60
" in order to put an edge between them in the dual graph. Default is 1.",
61
" ",
62
" -dbglvl=int ",
63
" Selects the dbglvl.",
64
" ",
65
" -help",
66
" Prints this message.",
67
""
68
};
69
70
static char shorthelpstr[][100] = {
71
" ",
72
" Usage: m2gmetis [options] <meshfile> <graphfile>",
73
" use 'm2gmetis -help' for a summary of the options.",
74
""
75
};
76
77
78
79
/*************************************************************************
80
* This is the entry point of the command-line argument parser
81
**************************************************************************/
82
params_t *parse_cmdline(int argc, char *argv[])
83
{
84
int i, j, k;
85
int c, option_index;
86
params_t *params;
87
88
params = (params_t *)gk_malloc(sizeof(params_t), "parse_cmdline");
89
memset((void *)params, 0, sizeof(params_t));
90
91
/* initialize the params data structure */
92
params->gtype = METIS_GTYPE_DUAL;
93
params->ncommon = 1;
94
params->dbglvl = 0;
95
params->filename = NULL;
96
params->outfile = NULL;
97
98
99
gk_clearcputimer(params->iotimer);
100
gk_clearcputimer(params->parttimer);
101
gk_clearcputimer(params->reporttimer);
102
103
104
/* Parse the command line arguments */
105
while ((c = gk_getopt_long_only(argc, argv, "", long_options, &option_index)) != -1) {
106
switch (c) {
107
case METIS_OPTION_GTYPE:
108
if (gk_optarg)
109
if ((params->gtype = gk_GetStringID(gtype_options, gk_optarg)) == -1)
110
errexit("Invalid option -%s=%s\n", long_options[option_index].name, gk_optarg);
111
break;
112
113
case METIS_OPTION_NCOMMON:
114
if (gk_optarg) params->ncommon = (idx_t)atoi(gk_optarg);
115
if (params->ncommon < 1)
116
errexit("The -ncommon option should specify a number >= 1.\n");
117
break;
118
119
case METIS_OPTION_DBGLVL:
120
if (gk_optarg) params->dbglvl = (idx_t)atoi(gk_optarg);
121
break;
122
123
case METIS_OPTION_HELP:
124
for (i=0; strlen(helpstr[i]) > 0; i++)
125
printf("%s\n", helpstr[i]);
126
exit(0);
127
break;
128
case '?':
129
default:
130
errexit("Illegal command-line option(s)\n"
131
"Use %s -help for a summary of the options.\n", argv[0]);
132
}
133
}
134
135
if (argc-gk_optind != 2) {
136
printf("Missing parameters.");
137
for (i=0; strlen(shorthelpstr[i]) > 0; i++)
138
printf("%s\n", shorthelpstr[i]);
139
exit(0);
140
}
141
142
params->filename = gk_strdup(argv[gk_optind++]);
143
params->outfile = gk_strdup(argv[gk_optind++]);
144
145
return params;
146
}
147
148
149
150