00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00028 #include "arts.h"
00029 #include <getopt.h>
00030 #include "parameters.h"
00031
00033 Parameters parameters;
00034
00035 bool get_parameters(int argc, char **argv)
00036 {
00037
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 struct option longopts[] =
00083 {
00084 { "help", no_argument, NULL, 'h' },
00085 { "version", no_argument, NULL, 'v' },
00086 { "basename", required_argument, NULL, 'b' },
00087 { "reporting", required_argument, NULL, 'r' },
00088 { "methods", required_argument, NULL, 'm' },
00089 { "input", required_argument, NULL, 'i' },
00090 { "workspacevariables", required_argument, NULL, 'w' },
00091 { "describe", required_argument, NULL, 'd' },
00092 { "groups", no_argument, NULL, 'g' },
00093 { NULL, no_argument, NULL, 0 }
00094 };
00095
00096 parameters.usage =
00097 "Usage: arts [-hvbrmiwdg] [--help] [--version] [--basename <name>]\n"
00098 " [--reporting xy]\n"
00099 " [--methods all|<variable>]\n"
00100 " [--input <variable>]\n"
00101 " [--workspacevariables all|<method>]\n"
00102 " [--describe <method or variable>]\n"
00103 " [--groups]\n"
00104 " file1.arts file2.arts ...";
00105
00106 parameters.helptext =
00107 "The Atmospheric Radiative Transfer System.\n\n"
00108 "-h, --help Print this message.\n"
00109 "-v, --version Show version information.\n"
00110 "-b, --basename Set the basename for the report\n"
00111 " file and for other output files.\n"
00112 "-r, --reporting Two digit integer. Sets the reporting\n"
00113 " level for screen (first digit) anf file\n"
00114 " (second digit). Levels can reach from 0\n"
00115 " (only error messages) to 3 (everything).\n"
00116 "-m, --methods If this is given the argument `all',\n"
00117 " it simply prints a list of all methods.\n"
00118 " If it is given the name of a variable\n"
00119 " (or variable group), it prints all\n"
00120 " methods that produce this\n"
00121 " variable (or group) as output.\n"
00122 "-i, --input This is complementary to the --methods switch.\n"
00123 " It must be given the name of a variable (or group).\n"
00124 " Then it lists all methods that take this variable\n"
00125 " (or group) as input.\n"
00126 "-w, --workspacevariables If this is given the argument `all',\n"
00127 " it simply prints a list of all variables.\n"
00128 " If it is given the name of a method, it\n"
00129 " prints all variables needed by this method.\n"
00130 "-d, --describe Print the description String of the given\n"
00131 " workspace variable or method.\n"
00132 "-g --groups List all workspace variable groups.";
00133
00134
00135
00136
00137
00138
00139
00140
00141
00142
00143 String shortopts;
00144 {
00145 int i=0;
00146 while (NULL != longopts[i].name )
00147 {
00148
00149 char c = longopts[i].val;
00150 shortopts += c;
00151
00152
00153
00154
00155 if ( required_argument == longopts[i].has_arg )
00156 {
00157 shortopts += ":";
00158 }
00159
00160
00161 if ( optional_argument == longopts[i].has_arg )
00162 {
00163 shortopts += "::";
00164 }
00165
00166 ++i;
00167 }
00168 shortopts += '\0';
00169 }
00170
00171
00172 int optc;
00173
00174 while ( EOF != (optc = getopt_long (argc, argv, shortopts.c_str(),
00175 longopts, (int *) 0) ) )
00176 {
00177
00178 switch (optc)
00179 {
00180 case 'h':
00181 parameters.help = true;
00182 break;
00183 case 'v':
00184 parameters.version = true;
00185 break;
00186 case 'b':
00187 parameters.basename = optarg;
00188 break;
00189 case 'r':
00190 {
00191
00192 istringstream is(optarg);
00193 is >> parameters.reporting;
00194 ws(is);
00195
00196
00197
00198
00199 if ( !is || !is.eof() )
00200 {
00201 cerr << "Argument to --reporting (-r) must be an integer!\n";
00202 exit(1);
00203 }
00204 break;
00205 }
00206 case 'm':
00207 parameters.methods = optarg;
00208 break;
00209 case 'i':
00210 parameters.input = optarg;
00211 break;
00212 case 'w':
00213 parameters.workspacevariables = optarg;
00214 break;
00215 case 'd':
00216 parameters.describe = optarg;
00217 break;
00218 case 'g':
00219 parameters.groups = true;
00220 break;
00221 default:
00222
00223 return(1);
00224 break;
00225 }
00226 }
00227
00228
00229
00230 while ( optind < argc )
00231 {
00232 String dummy=argv[optind];
00233 parameters.controlfiles.push_back(dummy);
00234 optind++;
00235 }
00236
00237
00238
00239
00240
00241 return false;
00242 }