cmdline_m2gmetis.c
Go to the documentation of this file.
1 
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  *-------------------------------------------------------------------*/
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;
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 
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 
The structure that stores the information about the command-line options.
Definition: gk_getopt.h:28
Definition: fis.c:15
void errexit(char *f_str,...)
Definition: error.c:54
int gk_optind
Index in ARGV of the next element to be scanned.
Definition: getopt.c:68
Scalar Scalar * c
Definition: benchVecAdd.cpp:17
static char shorthelpstr[][100]
static const SmartProjectionParams params
int32_t idx_t
#define gk_clearcputimer(tmr)
Definition: gk_macros.h:32
#define NULL
Definition: ccolamd.c:609
char * gk_strdup(char *orgstr)
Duplicates a string.
Definition: string.c:372
char * gk_optarg
For communication arguments to the caller.
Definition: getopt.c:56
static gk_StringMap_t gtype_options[]
void * gk_malloc(size_t nbytes, char *msg)
Definition: memory.c:140
Annotation for function names.
Definition: attr.h:48
int gk_GetStringID(gk_StringMap_t *strmap, char *key)
Definition: string.c:519
params_t * parse_cmdline(int argc, char *argv[])
static char helpstr[][100]
static struct gk_option long_options[]
int gk_getopt_long_only(int argc, char **argv, char *options, struct gk_option *long_options, int *opt_index)
Parse command-line arguments with only long options.
Definition: getopt.c:850
std::ptrdiff_t j


gtsam
Author(s):
autogenerated on Tue Jul 4 2023 02:34:01