Path: blob/devel/elmergrid/src/metis-5.1.0/programs/cmdline_m2gmetis.c
3206 views
/*!1\file cmdline_m2gmetis.c23\brief Command-line argument parsing for m2gmetis45\date 12/24/20086\author George7\version\verbatim $Id: cmdline_m2gmetis.c 10046 2011-06-01 14:13:40Z karypis $\endverbatim8*/910#include "metisbin.h"111213/*-------------------------------------------------------------------14* Command-line options15*-------------------------------------------------------------------*/16static struct gk_option long_options[] = {17{"gtype", 1, 0, METIS_OPTION_GTYPE},18{"ncommon", 1, 0, METIS_OPTION_NCOMMON},1920{"dbglvl", 1, 0, METIS_OPTION_DBGLVL},2122{"help", 0, 0, METIS_OPTION_HELP},23{0, 0, 0, 0}24};25262728/*-------------------------------------------------------------------29* Mappings for the various parameter values30*-------------------------------------------------------------------*/31static gk_StringMap_t gtype_options[] = {32{"dual", METIS_GTYPE_DUAL},33{"nodal", METIS_GTYPE_NODAL},34{NULL, 0}35};363738/*-------------------------------------------------------------------39* Mini help40*-------------------------------------------------------------------*/41static char helpstr[][100] =42{43" ",44"Usage: m2gmetis [options] <meshfile> <graphfile>",45" ",46" Required parameters",47" meshfile Stores the input mesh.",48" graphfile The filename of the output graph.",49" ",50" Optional parameters",51" -gtype=string",52" Specifies the graph that will be generated.",53" The possible values are:",54" dual - Generate dual graph of the mesh [default]",55" nodal - Generate the nodal graph of the mesh",56" ",57" -ncommon=int [applies when gtype=dual]",58" Specifies the common number of nodes that two elements must have",59" in order to put an edge between them in the dual graph. Default is 1.",60" ",61" -dbglvl=int ",62" Selects the dbglvl.",63" ",64" -help",65" Prints this message.",66""67};6869static char shorthelpstr[][100] = {70" ",71" Usage: m2gmetis [options] <meshfile> <graphfile>",72" use 'm2gmetis -help' for a summary of the options.",73""74};75767778/*************************************************************************79* This is the entry point of the command-line argument parser80**************************************************************************/81params_t *parse_cmdline(int argc, char *argv[])82{83int i, j, k;84int c, option_index;85params_t *params;8687params = (params_t *)gk_malloc(sizeof(params_t), "parse_cmdline");88memset((void *)params, 0, sizeof(params_t));8990/* initialize the params data structure */91params->gtype = METIS_GTYPE_DUAL;92params->ncommon = 1;93params->dbglvl = 0;94params->filename = NULL;95params->outfile = NULL;969798gk_clearcputimer(params->iotimer);99gk_clearcputimer(params->parttimer);100gk_clearcputimer(params->reporttimer);101102103/* Parse the command line arguments */104while ((c = gk_getopt_long_only(argc, argv, "", long_options, &option_index)) != -1) {105switch (c) {106case METIS_OPTION_GTYPE:107if (gk_optarg)108if ((params->gtype = gk_GetStringID(gtype_options, gk_optarg)) == -1)109errexit("Invalid option -%s=%s\n", long_options[option_index].name, gk_optarg);110break;111112case METIS_OPTION_NCOMMON:113if (gk_optarg) params->ncommon = (idx_t)atoi(gk_optarg);114if (params->ncommon < 1)115errexit("The -ncommon option should specify a number >= 1.\n");116break;117118case METIS_OPTION_DBGLVL:119if (gk_optarg) params->dbglvl = (idx_t)atoi(gk_optarg);120break;121122case METIS_OPTION_HELP:123for (i=0; strlen(helpstr[i]) > 0; i++)124printf("%s\n", helpstr[i]);125exit(0);126break;127case '?':128default:129errexit("Illegal command-line option(s)\n"130"Use %s -help for a summary of the options.\n", argv[0]);131}132}133134if (argc-gk_optind != 2) {135printf("Missing parameters.");136for (i=0; strlen(shorthelpstr[i]) > 0; i++)137printf("%s\n", shorthelpstr[i]);138exit(0);139}140141params->filename = gk_strdup(argv[gk_optind++]);142params->outfile = gk_strdup(argv[gk_optind++]);143144return params;145}146147148149150