// *=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=* // ** 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. // *=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=* /** * * @file Args.cc * * @class Args * * Class controlling the command line arguments for the program. * * @date 8/30/2011 * */ #include #include #include #include #include #include #include #include #include "Args.hh" using namespace std; /********************************************************************** * Constructor */ Args::Args (int argc, char **argv, char *prog_name) : _progName(prog_name), _startTime(DateTime::NEVER), _endTime(DateTime::NEVER) { string tmp_str; // Intialize bool okay = true; TDRP_init_override(&override); // search for command options for (int i = 1; i < argc; i++) { if (STRequal_exact(argv[i], "--") || STRequal_exact(argv[i], "-help") || STRequal_exact(argv[i], "-man")) { _usage(stdout); exit(0); } else if (STRequal_exact(argv[i], "-debug")) { tmp_str = "debug = true;"; TDRP_add_override(&override, tmp_str.c_str()); } else if (STRequal_exact(argv[i], "-end") || STRequal_exact(argv[i], "-endtime") || STRequal_exact(argv[i], "-end_time")) { if (i < argc - 1) { if (_endTime.set(argv[++i]) == DateTime::NEVER) { cerr << "*** Invalid end time string entered: " << argv[i] << endl << endl; okay = false; } } else { okay = false; } } else if (STRequal_exact(argv[i], "-mode")) { if (i < argc - 1) { tmp_str = string("trigger_mode = ") + argv[++i] + ";"; TDRP_add_override(&override, tmp_str.c_str()); } else { okay = false; } } else if (STRequal_exact(argv[i], "-start") || STRequal_exact(argv[i], "-starttime") || STRequal_exact(argv[i], "-start_time")) { if (i < argc - 1) { if (_startTime.set(argv[++i]) == DateTime::NEVER) { cerr << "*** Invalid start time string entered: " << argv[i] << endl << endl; okay = false; } } else { okay = false; } } else if (STRequal_exact(argv[i], "-verbose")) { tmp_str = "verbose = true;"; TDRP_add_override(&override, tmp_str.c_str()); } } /* i */ if (!okay) { _usage(stderr); exit(-1); } } /********************************************************************** * Destructor */ Args::~Args(void) { TDRP_free_override(&override); } /********************************************************************** * Private Member Functions * **********************************************************************/ /********************************************************************** * _usage() */ void Args::_usage(FILE *stream) { fprintf(stream, "%s%s%s", "This program resamples MDV data.\n" "\n" "Usage:\n\n", _progName.c_str(), " [options] as below:\n\n" " [ --, -help, -man ] produce this list.\n" " [ -debug ] debugging on\n" " [ -end yyyy/mm/dd_hh:mm:ss ] end time (TIME_LIST or FCST_TIME_LIST mode)\n" " [ -mode mode ] run mode (LATEST_DATA, TIME_LIST or FCST_TIME_LIST)\n" " [ -start yyyy/mm/dd_hh:mm:ss ] start time (TIME_LIST or FCST_TIME_LIST mode)\n" " [ -verbose ] verbose debugging on\n" "\n" ); TDRP_usage(stream); }