// *=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=* // ** Copyright UCAR (c) 1990 - 2016 // ** University Corporation for Atmospheric Research (UCAR) // ** National Center for Atmospheric Research (NCAR) // ** Boulder, Colorado, USA // ** BSD licence applies - redistribution and use in source and binary // ** forms, with or without modification, are permitted provided that // ** the following conditions are met: // ** 1) If the software is modified to produce derivative works, // ** such modified software should be clearly marked, so as not // ** to confuse it with the version available from UCAR. // ** 2) Redistributions of source code must retain the above copyright // ** notice, this list of conditions and the following disclaimer. // ** 3) Redistributions in binary form must reproduce the above copyright // ** notice, this list of conditions and the following disclaimer in the // ** documentation and/or other materials provided with the distribution. // ** 4) Neither the name of UCAR nor the names of its contributors, // ** if any, may be used to endorse or promote products derived from // ** this software without specific prior written permission. // ** DISCLAIMER: THIS SOFTWARE IS PROVIDED "AS IS" AND WITHOUT ANY EXPRESS // ** OR IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED // ** WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. // *=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=* ////////////////////////////////////////////////////////// // RadxAppArgs.cc : command line args for generalized Radx application // // Mike Dixon, RAP, NCAR, P.O.Box 3000, Boulder, CO, 80307-3000, USA // // Dec 2015 // ////////////////////////////////////////////////////////// #include #include #include #include #include using namespace std; // Constructor RadxAppArgs::RadxAppArgs () { TDRP_init_override(&override); startTime = 0; endTime = 0; tdrpExit = false; } // Destructor RadxAppArgs::~RadxAppArgs () { TDRP_free_override(&override); } // parse the command line // // returns 0 on success, -1 on failure int RadxAppArgs::parse (int argc, char **argv, string &prog_name) { _progName = prog_name; char tmp_str[BUFSIZ]; bool OK = true; // loop through args for (int i = 1; i < argc; i++) { if (!strcmp(argv[i], "--") || !strcmp(argv[i], "-h") || !strcmp(argv[i], "-help") || !strcmp(argv[i], "-man")) { _usage(cout); exit (0); } else if (!strcmp(argv[i], "-d") || !strcmp(argv[i], "-debug")) { sprintf(tmp_str, "debug = DEBUG_NORM;"); TDRP_add_override(&override, tmp_str); } else if (!strcmp(argv[i], "-v") || !strcmp(argv[i], "-verbose")) { sprintf(tmp_str, "debug = DEBUG_VERBOSE;"); TDRP_add_override(&override, tmp_str); } else if (!strcmp(argv[i], "-vv") || !strcmp(argv[i], "-extra")) { sprintf(tmp_str, "debug = DEBUG_EXTRA;"); TDRP_add_override(&override, tmp_str); } else if (!strcmp(argv[i], "-start")) { if (i < argc - 1) { startTime = RadxTime::parseDateTime(argv[++i]); if (startTime == RadxTime::NEVER) { OK = false; } else { sprintf(tmp_str, "mode = ARCHIVE;"); TDRP_add_override(&override, tmp_str); } } else { OK = false; } } else if (!strcmp(argv[i], "-end")) { if (i < argc - 1) { endTime = RadxTime::parseDateTime(argv[++i]); if (endTime == RadxTime::NEVER) { OK = false; } else { sprintf(tmp_str, "mode = ARCHIVE;"); TDRP_add_override(&override, tmp_str); } } else { OK = false; } } else if (!strcmp(argv[i], "-path") || !strcmp(argv[i], "-f")) { if (i < argc - 1) { // load up file list vector. Break at next arg which // start with - for (int j = i + 1; j < argc; j++) { if (argv[j][0] == '-') { break; } else { inputFileList.push_back(argv[j]); } } sprintf(tmp_str, "mode = FILELIST;"); TDRP_add_override(&override, tmp_str); } else { OK = false; } } else if (!strcmp(argv[i], "-check_params")) { tdrpExit = true; } else if (!strcmp(argv[i], "-tdrp_debug")) { tdrpExit = true; } else if (!strcmp(argv[i], "-tdrp_usage")) { tdrpExit = true; } else if (!strcmp(argv[i], "-print_params")) { tdrpExit = true; } } // i // set fields if specified if (!OK) { _usage(cerr); return -1; } return 0; } void RadxAppArgs::_usage(ostream &out) { out << "Usage: " << _progName << " [args as below]\n" << "Options:\n" << "\n" << " [ -h ] produce this list.\n" << "\n" << " [ -d, -debug ] print debug messages\n" << "\n" << " [ -end \"yyyy mm dd hh mm ss\"] end time\n" << " Sets mode to ARCHIVE\n" << "\n" << " [ -f, -paths ? ] set file paths\n" << " Sets mode to FILELIST\n" << "\n" << " [ -start \"yyyy mm dd hh mm ss\"] start time\n" << " Sets mode to ARCHIVE\n" << "\n" << " [ -v, -verbose ] print verbose debug messages\n" << "\n" << " [ -vv, -extra ] print extra verbose debug messages\n" << "\n" << " [ -print_fuzzy2d ] print an example of the Fuzzy2d parameters\n" << "\n" << endl; RadxAppParams::usage(out); }