00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00028 #include <iostream>
00029 #include <getopt.h>
00030 #include <cstdlib>
00031 #include "arts.h"
00032 #include "parameters.h"
00033
00035 Parameters parameters;
00036
00037 bool get_parameters(int argc, char **argv)
00038 {
00039
00040
00041
00042
00043
00044
00045
00046
00047
00048
00049
00050
00051
00052
00053
00054
00055
00056
00057
00058
00059
00060
00061
00062
00063
00064
00065
00066
00067
00068
00069
00070
00071
00072
00073
00074
00075
00076
00077
00078
00079
00080
00081
00082
00083
00084 struct option longopts[] =
00085 {
00086 { "basename", required_argument, NULL, 'b' },
00087 { "describe", required_argument, NULL, 'd' },
00088 { "groups", no_argument, NULL, 'g' },
00089 { "help", no_argument, NULL, 'h' },
00090 { "includepath", required_argument, NULL, 'I' },
00091 { "input", required_argument, NULL, 'i' },
00092 { "methods", required_argument, NULL, 'm' },
00093 { "numthreads", required_argument, NULL, 'n' },
00094 { "plain", no_argument, NULL, 'p' },
00095 { "reporting", required_argument, NULL, 'r' },
00096 { "workspacevariables", required_argument, NULL, 'w' },
00097 { "version", no_argument, NULL, 'v' },
00098 { NULL, no_argument, NULL, 0 }
00099 };
00100
00101 parameters.usage =
00102 "Usage: arts [-bdghimnrvw]\n"
00103 " [--basename <name>]\n"
00104 " [--describe <method or variable>]\n"
00105 " [--groups]\n"
00106 " [--help]\n"
00107 " [--includepath <path>]\n"
00108 " [--input <variable>]\n"
00109 " [--methods all|<variable>]\n"
00110 " [--numthreads <#>\n"
00111 " [--plain]\n"
00112 " [--reporting xyz]\n"
00113 " [--version]\n"
00114 " [--workspacevariables all|<method>]\n"
00115 " file1.arts file2.arts ...";
00116
00117 parameters.helptext =
00118 "The Atmospheric Radiative Transfer System.\n\n"
00119 "-b, --basename Set the basename for the report\n"
00120 " file and for other output files.\n"
00121 "-d, --describe Print the description String of the given\n"
00122 " workspace variable or method.\n"
00123 "-g --groups List all workspace variable groups.\n"
00124 "-h, --help Print this message.\n"
00125 "-i, --input This is complementary to the --methods switch.\n"
00126 " It must be given the name of a variable (or group).\n"
00127 " Then it lists all methods that take this variable\n"
00128 " (or group) as input.\n"
00129 "-I --includepath Search path for include files. Can be given more\n"
00130 " than once to add several paths.\n"
00131 " Include paths can also be added by setting the\n"
00132 " environment variable ARTS_INCLUDE_PATH. Multiple\n"
00133 " paths have to be separated by colons.\n"
00134 " Paths specified on the commandline have precedence\n"
00135 " over the environment variable and will be searched\n"
00136 " first.\n"
00137 "-m, --methods If this is given the argument `all',\n"
00138 " it simply prints a list of all methods.\n"
00139 " If it is given the name of a variable\n"
00140 " (or variable group), it prints all\n"
00141 " methods that produce this\n"
00142 " variable (or group) as output.\n"
00143 "-n, --numthreads If arts was compiled with OpenMP support this option\n"
00144 " can be used to set the maximum number of threads.\n"
00145 " By default OpenMP uses all processors/cores.\n"
00146 "-p --plain Generate plain help output suitable for\n"
00147 " script processing.\n"
00148 "-r, --reporting Three digit integer. Sets the reporting\n"
00149 " level for agenda calls (first digit),\n"
00150 " screen (second digit) and file (third \n"
00151 " digit). All reporting levels can reach from 0\n"
00152 " (only error messages) to 3 (everything).\n"
00153 " The agenda setting applies in addition to both\n"
00154 " screen and file output.\n"
00155 " Default is 010.\n"
00156 "-v, --version Show version information.\n"
00157 "-w, --workspacevariables If this is given the argument `all',\n"
00158 " it simply prints a list of all variables.\n"
00159 " If it is given the name of a method, it\n"
00160 " prints all variables needed by this method.";
00161
00162
00163
00164
00165
00166
00167
00168
00169
00170
00171 String shortopts;
00172 {
00173 int i=0;
00174 while (NULL != longopts[i].name )
00175 {
00176 char c = (char)longopts[i].val;
00177 shortopts += c;
00178
00179
00180
00181
00182 if ( required_argument == longopts[i].has_arg )
00183 {
00184 shortopts += ":";
00185 }
00186
00187
00188 if ( optional_argument == longopts[i].has_arg )
00189 {
00190 shortopts += "::";
00191 }
00192
00193 ++i;
00194 }
00195 shortopts += '\0';
00196 }
00197
00198
00199 int optc;
00200
00201 while ( EOF != (optc = getopt_long (argc, argv, shortopts.c_str(),
00202 longopts, (int *) 0) ) )
00203 {
00204
00205 switch (optc)
00206 {
00207 case 'h':
00208 parameters.help = true;
00209 break;
00210 case 'b':
00211 parameters.basename = optarg;
00212 break;
00213 case 'd':
00214 parameters.describe = optarg;
00215 break;
00216 case 'g':
00217 parameters.groups = true;
00218 break;
00219 case 'i':
00220 parameters.input = optarg;
00221 break;
00222 case 'I':
00223 parameters.includepath.push_back (optarg);
00224 break;
00225 case 'm':
00226 parameters.methods = optarg;
00227 break;
00228 case 'n':
00229 {
00230 istringstream iss(optarg);
00231 iss >> std::dec >> parameters.numthreads;
00232 if (iss.fail())
00233 {
00234 cerr << "Argument to --numthreads (-n) must be an integer!\n";
00235 arts_exit ();
00236 }
00237 break;
00238 }
00239 case 'p':
00240 parameters.plain = true;
00241 break;
00242 case 'r':
00243 {
00244
00245 istringstream is(optarg);
00246 is >> parameters.reporting;
00247 ws(is);
00248
00249
00250
00251
00252 if ( !is || !is.eof() )
00253 {
00254 cerr << "Argument to --reporting (-r) must be an integer!\n";
00255 arts_exit ();
00256 }
00257 break;
00258 }
00259 case 'v':
00260 parameters.version = true;
00261 break;
00262 case 'w':
00263 parameters.workspacevariables = optarg;
00264 break;
00265 default:
00266
00267 return(1);
00268 break;
00269 }
00270 }
00271
00272
00273
00274 while ( optind < argc )
00275 {
00276 String dummy=argv[optind];
00277 parameters.controlfiles.push_back(dummy);
00278 optind++;
00279 }
00280
00281
00282
00283
00284
00285
00286 char *artspathenv = getenv ("ARTS_INCLUDE_PATH");
00287
00288 if (artspathenv)
00289 {
00290 String artspath (artspathenv);
00291
00292
00293 String::size_type lastPos = artspath.find_first_not_of(":", 0);
00294
00295 String::size_type pos = artspath.find_first_of(":", lastPos);
00296
00297 while (String::npos != pos || String::npos != lastPos)
00298 {
00299 parameters.includepath.push_back (artspath.substr (lastPos,
00300 pos - lastPos));
00301 lastPos = artspath.find_first_not_of(":", pos);
00302 pos = artspath.find_first_of(":", lastPos);
00303 }
00304 }
00305
00306 return false;
00307 }