/************************************************************************* * This function takes in a potentially full path specification of a file * and just returns a string containing just the filename. **************************************************************************/ char *gk_getfilename(char *path) { char *startptr; if ((startptr = strrchr(path, '/')) == NULL) return gk_strdup(path); else return gk_strdup(startptr+1); }
/************************************************************************* * This function takes in a potentially full path specification of a file * and extracts the directory path component if it exists, otherwise it * returns "./" as the path. The memory for it is dynamically allocated. **************************************************************************/ char *getpathname(char *path) { char *endptr, *tmp; if ((endptr = strrchr(path, '/')) == NULL) { return gk_strdup("."); } else { tmp = gk_strdup(path); *(strrchr(tmp, '/')) = '\0'; return tmp; } }
void test_skvsort() { gk_idx_t i; gk_skv_t array[N]; char line[256]; /* test the increasing sort */ printf("Testing skvsorti...\n"); for (i=0; i<N; i++) { sprintf(line, "%d", RandomInRange(123432)); array[i].key = gk_strdup(line); array[i].val = i; } gk_skvsorti(N, array); for (i=0; i<N-1; i++) { if (strcmp(array[i].key, array[i+1].key) > 0) printf("gk_skvsorti error at index %jd [%s %s] [%jd %jd]\n", (intmax_t)i, array[i].key, array[i+1].key, (intmax_t)array[i].val, (intmax_t)array[i+1].val); } /* test the decreasing sort */ printf("Testing skvsortd...\n"); for (i=0; i<N; i++) { sprintf(line, "%d", RandomInRange(123432)); array[i].key = gk_strdup(line); array[i].val = i; } gk_skvsortd(N, array); for (i=0; i<N-1; i++) { /*printf("%s\n", array[i].key);*/ if (strcmp(array[i].key, array[i+1].key) < 0) printf("gk_skvsortd error at index %jd [%s %s] [%jd %jd]\n", (intmax_t)i, array[i].key, array[i+1].key, (intmax_t)array[i].val, (intmax_t)array[i+1].val); } }
/************************************************************************ * This function tokenizes a string based on the user-supplied delimiters * list. The resulting tokens are returned into an array of strings. *************************************************************************/ void gk_strtokenize(char *str, char *delim, gk_Tokens_t *tokens) { int i, ntoks, slen; tokens->strbuf = gk_strdup(str); slen = strlen(str); str = tokens->strbuf; /* Scan once to determine the number of tokens */ for (ntoks = 0, i = 0; i < slen;) { /* Consume all the consecutive characters from the delimiters list */ while (i < slen && strchr(delim, str[i])) { i++; } if (i == slen) { break; } ntoks++; /* Consume all the consecutive characters from the token */ while (i < slen && !strchr(delim, str[i])) { i++; } } tokens->ntoks = ntoks; tokens->list = (char **) gk_malloc(ntoks * sizeof(char *), "strtokenize: tokens->list"); /* Scan a second time to mark and link the tokens */ for (ntoks = 0, i = 0; i < slen;) { /* Consume all the consecutive characters from the delimiters list */ while (i < slen && strchr(delim, str[i])) { str[i++] = '\0'; } if (i == slen) { break; } tokens->list[ntoks++] = str + i; /* Consume all the consecutive characters from the token */ while (i < slen && !strchr(delim, str[i])) { i++; } } }
/************************************************************************* * Let the game begin **************************************************************************/ int main(int argc, char *argv[]) { idx_t i; idx_t *perm, *iperm; graph_t *graph; params_t params; size_t maxlnz, opc; if (argc != 3) { printf("Usage: %s <GraphFile> <PermFile\n", argv[0]); exit(0); } params.filename = gk_strdup(argv[1]); graph = ReadGraph(¶ms); if (graph->nvtxs <= 0) { printf("Empty graph. Nothing to do.\n"); exit(0); } if (graph->ncon != 1) { printf("Ordering can only be applied to graphs with one constraint.\n"); exit(0); } /* Read the external iperm vector */ perm = imalloc(graph->nvtxs, "main: perm"); iperm = imalloc(graph->nvtxs, "main: iperm"); ReadPOVector(graph, argv[2], iperm); for (i=0; i<graph->nvtxs; i++) perm[iperm[i]] = i; printf("**********************************************************************\n"); printf("%s", METISTITLE); printf("Graph Information ---------------------------------------------------\n"); printf(" Name: %s, #Vertices: %"PRIDX", #Edges: %"PRIDX"\n\n", argv[1], graph->nvtxs, graph->nedges/2); printf("Fillin... -----------------------------------------------------------\n"); ComputeFillIn(graph, perm, iperm, &maxlnz, &opc); printf(" Nonzeros: %6.3le \tOperation Count: %6.3le\n", (double)maxlnz, (double)opc); printf("**********************************************************************\n"); FreeGraph(&graph); }
int main(int argc, char *argv[]) { graph_t *graph, *fgraph; char filename[256]; idx_t wgtflag; params_t params; if (argc != 2 && argc != 3) { printf("Usage: %s <GraphFile> [FixedGraphFile (for storing the fixed graph)]\n", argv[0]); exit(0); } memset((void *) ¶ms, 0, sizeof(params_t)); params.filename = gk_strdup(argv[1]); graph = ReadGraph(¶ms); if (graph->nvtxs == 0) { printf("Empty graph!\n"); exit(0); } printf("**********************************************************************\n"); printf("%s", METISTITLE); printf(" (HEAD: %s, Built on: %s, %s)\n", SVNINFO, __DATE__, __TIME__); printf(" size of idx_t: %zubits, real_t: %zubits, idx_t *: %zubits\n", 8 * sizeof(idx_t), 8 * sizeof(real_t), 8 * sizeof(idx_t * )); printf("\n"); printf("Graph Information ---------------------------------------------------\n"); printf(" Name: %s, #Vertices: %"PRIDX", #Edges: %"PRIDX"\n\n", params.filename, graph->nvtxs, graph->nedges / 2); printf("Checking Graph... ---------------------------------------------------\n"); if (CheckGraph(graph, 1, 1)) { printf(" The format of the graph is correct!\n"); } else { printf(" The format of the graph is incorrect!\n"); if (argc == 3) { fgraph = FixGraph(graph); WriteGraph(fgraph, argv[2]); FreeGraph(&fgraph); printf(" A corrected version was stored at %s\n", argv[2]); } } printf("\n**********************************************************************\n"); FreeGraph(&graph); gk_free((void **) ¶ms.filename, ¶ms.tpwgtsfile, ¶ms.tpwgts, LTERM); }
/************************************************************************* * This function takes in a potentially full path specification of a file * and just returns a string containing just the basename of the file. * The basename is derived from the actual filename by stripping the last * .ext part. **************************************************************************/ char *gk_getbasename(char *path) { char *startptr, *endptr; char *basename; if ((startptr = strrchr(path, '/')) == NULL) startptr = path; else startptr = startptr+1; basename = gk_strdup(startptr); if ((endptr = strrchr(basename, '.')) != NULL) *endptr = '\0'; return basename; }
int gk_strstr_replace(char *str, char *pattern, char *replacement, char *options, char **new_str) { gk_idx_t i; int j, rc, flags, global, nmatches; size_t len, rlen, nlen, offset, noffset; regex_t re; regmatch_t matches[10]; /* Parse the options */ flags = REG_EXTENDED; if (strchr(options, 'i') != NULL) flags = flags | REG_ICASE; global = (strchr(options, 'g') != NULL ? 1 : 0); /* Compile the regex */ if ((rc = regcomp(&re, pattern, flags)) != 0) { len = regerror(rc, &re, NULL, 0); *new_str = gk_cmalloc(len, "gk_strstr_replace: new_str"); regerror(rc, &re, *new_str, len); return 0; } /* Prepare the output string */ len = strlen(str); nlen = 2*len; noffset = 0; *new_str = gk_cmalloc(nlen+1, "gk_strstr_replace: new_str"); /* Get into the matching-replacing loop */ rlen = strlen(replacement); offset = 0; nmatches = 0; do { rc = regexec(&re, str+offset, 10, matches, 0); if (rc == REG_ESPACE) { gk_free((void **)new_str, LTERM); *new_str = gk_strdup("regexec ran out of memory."); regfree(&re); return 0; } else if (rc == REG_NOMATCH) { if (nlen-noffset < len-offset) { nlen += (len-offset) - (nlen-noffset); *new_str = (char *)gk_realloc(*new_str, (nlen+1)*sizeof(char), "gk_strstr_replace: new_str"); } strcpy(*new_str+noffset, str+offset); noffset += (len-offset); break; } else { /* A match was found! */ nmatches++; /* Copy the left unmatched portion of the string */ if (matches[0].rm_so > 0) { if (nlen-noffset < matches[0].rm_so) { nlen += matches[0].rm_so - (nlen-noffset); *new_str = (char *)gk_realloc(*new_str, (nlen+1)*sizeof(char), "gk_strstr_replace: new_str"); } strncpy(*new_str+noffset, str+offset, matches[0].rm_so); noffset += matches[0].rm_so; } /* Go and append the replacement string */ for (i=0; i<rlen; i++) { switch (replacement[i]) { case '\\': if (i+1 < rlen) { if (nlen-noffset < 1) { nlen += nlen + 1; *new_str = (char *)gk_realloc(*new_str, (nlen+1)*sizeof(char), "gk_strstr_replace: new_str"); } *new_str[noffset++] = replacement[++i]; } else { gk_free((void **)new_str, LTERM); *new_str = gk_strdup("Error in replacement string. Missing character following '\'."); regfree(&re); return 0; } break; case '$': if (i+1 < rlen) { j = (int)(replacement[++i] - '0'); if (j < 0 || j > 9) { gk_free((void **)new_str, LTERM); *new_str = gk_strdup("Error in captured subexpression specification."); regfree(&re); return 0; } if (nlen-noffset < matches[j].rm_eo-matches[j].rm_so) { nlen += nlen + (matches[j].rm_eo-matches[j].rm_so); *new_str = (char *)gk_realloc(*new_str, (nlen+1)*sizeof(char), "gk_strstr_replace: new_str"); } strncpy(*new_str+noffset, str+offset+matches[j].rm_so, matches[j].rm_eo); noffset += matches[j].rm_eo-matches[j].rm_so; } else { gk_free((void **)new_str, LTERM); *new_str = gk_strdup("Error in replacement string. Missing subexpression number folloing '$'."); regfree(&re); return 0; } break; default: if (nlen-noffset < 1) { nlen += nlen + 1; *new_str = (char *)gk_realloc(*new_str, (nlen+1)*sizeof(char), "gk_strstr_replace: new_str"); } (*new_str)[noffset++] = replacement[i]; } } /* Update the offset of str for the next match */ offset += matches[0].rm_eo; if (!global) { /* Copy the right portion of the string if no 'g' option */ if (nlen-noffset < len-offset) { nlen += (len-offset) - (nlen-noffset); *new_str = (char *)gk_realloc(*new_str, (nlen+1)*sizeof(char), "gk_strstr_replace: new_str"); } strcpy(*new_str+noffset, str+offset); noffset += (len-offset); } } } while (global); (*new_str)[noffset] = '\0'; regfree(&re); return nmatches + 1; }
pdbf *gk_readpdbfile(char *fname) { /* {{{ */ int i=0, res=0; char linetype[6]; int aserial; char aname[5] = " \0"; char altLoc = ' '; char rname[4] = " \0"; char chainid = ' '; char oldchainid = ' '; int rserial; int oldRserial = -37; char icode = ' '; char element = ' '; double x; double y; double z; double avgx; double avgy; double avgz; double opcy; double tmpt; char line[MAXLINELEN]; int corruption=0; int nresatoms; int atoms=0, residues=0, cas=0, bbs=0, firstres=1; pdbf *toFill = gk_malloc(sizeof(pdbf),"fillme"); FILE *FPIN; FPIN = gk_fopen(fname,"r",fname); while(fgets(line, 256, FPIN)) { sscanf(line,"%s ",linetype); /* It seems the only reliable parts are through temperature, so we only use these parts */ /* if(strstr(linetype, "ATOM") != NULL || strstr(linetype, "HETATM") != NULL) { */ if(strstr(linetype, "ATOM") != NULL) { sscanf(line, "%6s%5d%*1c%4c%1c%3c%*1c%1c%4d%1c%*3c%8lf%8lf%8lf%6lf%6lf %c\n", linetype,&aserial,aname,&altLoc,rname,&chainid,&rserial,&icode,&x,&y,&z,&opcy,&tmpt,&element); sscanf(linetype, " %s ",linetype); sscanf(aname, " %s ",aname); sscanf(rname, " %s ",rname); if(altLoc != ' ') { corruption = corruption|CRP_ALTLOCS; } if(firstres == 1) { oldRserial = rserial; oldchainid = chainid; residues++; firstres = 0; } if(oldRserial != rserial) { residues++; oldRserial = rserial; } if(oldchainid != chainid) { corruption = corruption|CRP_MULTICHAIN; } oldchainid = chainid; atoms++; if(strcmp(aname,"CA") == 0) { cas++; } if(strcmp(aname,"N") == 0 || strcmp(aname,"CA") == 0 || strcmp(aname,"C") == 0 || strcmp(aname,"O") == 0) { bbs++; } } else if(strstr(linetype, "ENDMDL") != NULL || strstr(linetype, "END") != NULL || strstr(linetype, "TER") != NULL) { break; } } fclose(FPIN); /* printf("File has coordinates for %d atoms in %d residues\n",atoms,residues); */ toFill->natoms = atoms; toFill->ncas = cas; toFill->nbbs = bbs; toFill->nresidues = residues; toFill->resSeq = (char *) gk_malloc (residues*sizeof(char),"residue seq"); toFill->threeresSeq = (char **)gk_malloc (residues*sizeof(char *),"residue seq"); toFill->atoms = (atom *) gk_malloc (atoms*sizeof(atom), "atoms"); toFill->bbs = (atom **)gk_malloc ( bbs*sizeof(atom *),"bbs"); toFill->cas = (atom **)gk_malloc ( cas*sizeof(atom *),"cas"); toFill->cm = (center_of_mass *)gk_malloc(residues*sizeof(center_of_mass),"center of mass"); res=0; firstres=1; cas=0; bbs=0; i=0; avgx = 0.0; avgy = 0.0; avgz = 0.0; nresatoms = 0; FPIN = gk_fopen(fname,"r",fname); while(fgets(line, 256, FPIN)) { sscanf(line,"%s ",linetype); /* It seems the only reliable parts are through temperature, so we only use these parts */ /* if(strstr(linetype, "ATOM") != NULL || strstr(linetype, "HETATM") != NULL) { */ if(strstr(linetype, "ATOM") != NULL ) { /* to ensure our memory doesn't get corrupted by the biologists, we only read this far */ sscanf(line, "%6s%5d%*1c%4c%1c%3c%*1c%1c%4d%1c%*3c%8lf%8lf%8lf%6lf%6lf %c\n", linetype,&aserial,aname,&altLoc,rname,&chainid,&rserial,&icode,&x,&y,&z,&opcy,&tmpt,&element); sscanf(aname, "%s",aname); sscanf(rname, "%s",rname); if(firstres == 1) { toFill->resSeq[res] = gk_threetoone(rname); toFill->threeresSeq[res] = gk_strdup(rname); oldRserial = rserial; res++; firstres = 0; } if(oldRserial != rserial) { /* we're changing residues. store the center of mass from the last one & reset */ toFill->cm[res-1].x = avgx/nresatoms; toFill->cm[res-1].y = avgy/nresatoms; toFill->cm[res-1].z = avgz/nresatoms; avgx = 0.0; avgy = 0.0; avgz = 0.0; nresatoms = 0; toFill->cm[res-1].name = toFill->resSeq[res-1]; toFill->threeresSeq[res] = gk_strdup(rname); toFill->resSeq[res] = gk_threetoone(rname); res++; oldRserial = rserial; } avgx += x; avgy += y; avgz += z; nresatoms++; toFill->atoms[i].x = x; toFill->atoms[i].y = y; toFill->atoms[i].z = z; toFill->atoms[i].opcy = opcy; toFill->atoms[i].tmpt = tmpt; toFill->atoms[i].element = element; toFill->atoms[i].serial = aserial; toFill->atoms[i].chainid = chainid; toFill->atoms[i].altLoc = altLoc; toFill->atoms[i].rserial = rserial; toFill->atoms[i].icode = icode; toFill->atoms[i].name = gk_strdup(aname); toFill->atoms[i].resname = gk_strdup(rname); /* Set up pointers for the backbone and c-alpha shortcuts */ if(strcmp(aname,"CA") == 0) { toFill->cas[cas] = &(toFill->atoms[i]); cas++; } if(strcmp(aname,"N") == 0 || strcmp(aname,"CA") == 0 || strcmp(aname,"C") == 0 || strcmp(aname,"O") == 0) { toFill->bbs[bbs] = &(toFill->atoms[i]); bbs++; } i++; } else if(strstr(linetype, "ENDMDL") != NULL || strstr(linetype, "END") != NULL || strstr(linetype, "TER") != NULL) { break; } } /* get that last average */ toFill->cm[res-1].x = avgx/nresatoms; toFill->cm[res-1].y = avgy/nresatoms; toFill->cm[res-1].z = avgz/nresatoms; /* Begin test code */ if(cas != residues) { printf("Number of residues and CA coordinates differs by %d (!)\n",residues-cas); if(cas < residues) { corruption = corruption|CRP_MISSINGCA; } else if(cas > residues) { corruption = corruption|CRP_MULTICA; } } if(bbs < residues*4) { corruption = corruption|CRP_MISSINGBB; } else if(bbs > residues*4) { corruption = corruption|CRP_MULTIBB; } fclose(FPIN); toFill->corruption = corruption; /* if(corruption == 0) printf("File was clean!\n"); */ return(toFill); } /* }}} */
void cmdline_parse(params_t *params, int argc, char *argv[]) { gk_idx_t i, j, k; int type=0; int c, option_index; /* print the command line */ for (i=0; i<argc; i++) printf("%s ", argv[i]); printf("\n"); /* initialize the params data structure */ params->nnbrs = 100; params->minsim = 0.25; params->verbosity = -1; /* Parse the command line arguments */ while ((c = gk_getopt_long_only(argc, argv, "", long_options, &option_index)) != -1) { switch (c) { case CMD_NNBRS: if (gk_optarg) { if ((params->nnbrs = atoi(gk_optarg)) < 1) errexit("The -nnbrs must be greater than 1.\n"); } break; case CMD_MINSIM: if (gk_optarg) { params->minsim = atof(gk_optarg); if (params->minsim < 0.0 ) errexit("The -minsim must be non-negative.\n"); } break; case CMD_VERBOSITY: if (gk_optarg) { params->verbosity = atoi(gk_optarg); if (params->verbosity < 0) errexit("The -verbosity must be non-negative.\n"); } break; case CMD_HELP: for (i=0; strlen(helpstr[i]) > 0; i++) printf("%s\n", helpstr[i]); exit(EXIT_SUCCESS); break; default: printf("Illegal command-line option(s)\nUse %s -help for a summary of the options.\n", argv[0]); exit(EXIT_FAILURE); } } /* Get the input/output file info */ if (argc-gk_optind == 0) { printf("Missing input/output file info.\n Use %s -help for a summary of the options.\n", argv[0]); exit(EXIT_FAILURE); } params->infstem = gk_strdup(argv[gk_optind++]); params->outfile = (gk_optind < argc ? gk_strdup(argv[gk_optind++]) : NULL); }
/************************************************************************* * This is the entry point of the command-line argument parser **************************************************************************/ params_t *parse_cmdline(int argc, char *argv[]) { int i, j, k; int c, option_index; params_t *params; params = (params_t *)gk_malloc(sizeof(params_t), "parse_cmdline"); memset((void *)params, 0, sizeof(params_t)); /* initialize the params data structure */ params->gtype = METIS_GTYPE_DUAL; params->ptype = METIS_PTYPE_KWAY; params->objtype = METIS_OBJTYPE_CUT; params->ctype = METIS_CTYPE_SHEM; params->iptype = METIS_IPTYPE_GROW; params->rtype = -1; params->minconn = 0; params->contig = 0; params->nooutput = 0; params->wgtflag = 3; params->ncuts = 1; params->niter = 10; params->ncommon = 1; params->dbglvl = 0; params->balance = 0; params->seed = -1; params->dbglvl = 0; params->tpwgtsfile = NULL; params->filename = NULL; params->nparts = 1; params->ufactor = -1; gk_clearcputimer(params->iotimer); gk_clearcputimer(params->parttimer); gk_clearcputimer(params->reporttimer); /* Parse the command line arguments */ while ((c = gk_getopt_long_only(argc, argv, "", long_options, &option_index)) != -1) { switch (c) { case METIS_OPTION_GTYPE: if (gk_optarg) if ((params->gtype = gk_GetStringID(gtype_options, gk_optarg)) == -1) errexit("Invalid option -%s=%s\n", long_options[option_index].name, gk_optarg); break; case METIS_OPTION_PTYPE: if (gk_optarg) if ((params->ptype = gk_GetStringID(ptype_options, gk_optarg)) == -1) errexit("Invalid option -%s=%s\n", long_options[option_index].name, gk_optarg); break; case METIS_OPTION_OBJTYPE: if (gk_optarg) if ((params->objtype = gk_GetStringID(objtype_options, gk_optarg)) == -1) errexit("Invalid option -%s=%s\n", long_options[option_index].name, gk_optarg); break; case METIS_OPTION_CTYPE: if (gk_optarg) if ((params->ctype = gk_GetStringID(ctype_options, gk_optarg)) == -1) errexit("Invalid option -%s=%s\n", long_options[option_index].name, gk_optarg); break; case METIS_OPTION_IPTYPE: if (gk_optarg) if ((params->iptype = gk_GetStringID(iptype_options, gk_optarg)) == -1) errexit("Invalid option -%s=%s\n", long_options[option_index].name, gk_optarg); break; /* case METIS_OPTION_RTYPE: if (gk_optarg) if ((params->rtype = gk_GetStringID(rtype_options, gk_optarg)) == -1) errexit("Invalid option -%s=%s\n", long_options[option_index].name, gk_optarg); break; */ case METIS_OPTION_CONTIG: params->contig = 1; break; case METIS_OPTION_MINCONN: params->minconn = 1; break; case METIS_OPTION_NOOUTPUT: params->nooutput = 1; break; case METIS_OPTION_BALANCE: params->balance = 1; break; case METIS_OPTION_TPWGTS: if (gk_optarg) params->tpwgtsfile = gk_strdup(gk_optarg); break; case METIS_OPTION_NCUTS: if (gk_optarg) params->ncuts = (idx_t)atoi(gk_optarg); break; case METIS_OPTION_NITER: if (gk_optarg) params->niter = (idx_t)atoi(gk_optarg); break; case METIS_OPTION_NCOMMON: if (gk_optarg) params->ncommon = (idx_t)atoi(gk_optarg); break; case METIS_OPTION_UFACTOR: if (gk_optarg) params->ufactor = (idx_t)atoi(gk_optarg); break; case METIS_OPTION_SEED: if (gk_optarg) params->seed = (idx_t)atoi(gk_optarg); break; case METIS_OPTION_DBGLVL: if (gk_optarg) params->dbglvl = (idx_t)atoi(gk_optarg); break; case METIS_OPTION_HELP: for (i=0; strlen(helpstr[i]) > 0; i++) printf("%s\n", helpstr[i]); exit(0); break; case '?': default: errexit("Illegal command-line option(s)\n" "Use %s -help for a summary of the options.\n", argv[0]); } } if (argc-gk_optind != 2) { printf("Missing parameters."); for (i=0; strlen(shorthelpstr[i]) > 0; i++) printf("%s\n", shorthelpstr[i]); exit(0); } params->filename = gk_strdup(argv[gk_optind++]); params->nparts = atoi(argv[gk_optind++]); if (params->nparts < 2) errexit("The number of partitions should be greater than 1!\n"); /* Set the ptype-specific defaults */ if (params->ptype == METIS_PTYPE_RB) { params->rtype = METIS_RTYPE_FM; } if (params->ptype == METIS_PTYPE_KWAY) { params->iptype = METIS_IPTYPE_METISRB; params->rtype = METIS_RTYPE_GREEDY; } /* Check for invalid parameter combination */ if (params->ptype == METIS_PTYPE_RB) { if (params->contig) errexit("The -contig option cannot be specified with rb partitioning.\n"); if (params->minconn) errexit("The -minconn option cannot be specified with rb partitioning.\n"); if (params->objtype == METIS_OBJTYPE_VOL) errexit("The -objtype=vol option cannot be specified with rb partitioning.\n"); } return params; }
params_t *parse_cmdline(int argc, char *argv[]) { int i; int c, option_index; params_t *params; params = (params_t *)gk_malloc(sizeof(params_t), "parse_cmdline: params"); /* initialize the params data structure */ params->niter = 100; params->ppr = -1; params->ntvs = -1; params->eps = 1e-10; params->lamda = 0.80; params->infile = NULL; params->outfile = NULL; /* Parse the command line arguments */ while ((c = gk_getopt_long_only(argc, argv, "", long_options, &option_index)) != -1) { switch (c) { case CMD_NITER: if (gk_optarg) params->niter = atoi(gk_optarg); break; case CMD_NTVS: if (gk_optarg) params->ntvs = atoi(gk_optarg); break; case CMD_PPR: if (gk_optarg) params->ppr = atoi(gk_optarg); break; case CMD_EPS: if (gk_optarg) params->eps = atof(gk_optarg); break; case CMD_LAMDA: if (gk_optarg) params->lamda = atof(gk_optarg); break; case CMD_HELP: for (i=0; strlen(helpstr[i]) > 0; i++) printf("%s\n", helpstr[i]); exit(0); break; case '?': default: printf("Illegal command-line option(s)\nUse %s -help for a summary of the options.\n", argv[0]); exit(0); } } if (argc-gk_optind != 2) { printf("Unrecognized parameters."); for (i=0; strlen(shorthelpstr[i]) > 0; i++) printf("%s\n", shorthelpstr[i]); exit(0); } params->infile = gk_strdup(argv[gk_optind++]); params->outfile = gk_strdup(argv[gk_optind++]); if (!gk_fexists(params->infile)) errexit("input file %s does not exist.\n", params->infile); if (params->ppr != -1 && params->ntvs != -1) errexit("Only one of the -ppr and -ntvs options can be specified.\n"); return params; }