/* Parameter handling. */ /* Copyright (C) 2004 University of Texas at Austin This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ #include #include #include #include #include #include "_bool.h" #include "simtab.h" #include "error.h" #include "alloc.h" static sf_simtab pars; //static char *prog = NULL; void sf_init(int argc,char *argv[]) /*< initialize parameter table from command-line arguments >*/ { int ic; FILE *fp; size_t len; pars = sf_simtab_init (argc); // number of arguments in commad line /* no pars and input from terminal */ if ( 1==argc) { sf_error("no pars and input from terminal"); } for (ic=1; ic < argc; ic++) { if (0 == strncmp(argv[ic],"par=",4)) { fp = fopen(argv[ic]+4,"r"); if (NULL == fp) sf_error ("%s: Cannot open par file %s:", __FILE__,argv[ic]+4); sf_simtab_input(pars,fp,NULL); (void) fclose (fp); } else { sf_simtab_put(pars,argv[ic]); } } } bool sf_getint (const char* key,/*@out@*/ int* par) /*< get an int parameter from the command line >*/ { return sf_simtab_getint (pars,key,par); } bool sf_getfloat (const char* key,/*@out@*/ float* par) /*< get a float parameter from the command line >*/ { return sf_simtab_getfloat (pars,key,par); } bool sf_getdouble (const char* key,/*@out@*/ double* par) /*< get a double parameter from the command line >*/ { return sf_simtab_getdouble (pars,key,par); } char* sf_getstring (const char* key) /*< get a string parameter from the command line >*/ { return sf_simtab_getstring(pars,key); } bool sf_getbool (const char* key,/*@out@*/ bool* par) /*< get a bool parameter from the command line >*/ { return sf_simtab_getbool(pars,key,par); } bool sf_getdoubles (const char* key,/*@out@*/ double* par,size_t n) /*< get a float array parameter from the command line >*/ { return sf_simtab_getdoubles (pars,key,par,n); }