Skip to content

Commit

Permalink
Added verbosity option to geotiff-driver in case anyone got tired of …
Browse files Browse the repository at this point in the history
…the verbose log statements
  • Loading branch information
SpencerFleming committed Sep 19, 2019
1 parent eb52b33 commit 1c86435
Show file tree
Hide file tree
Showing 4 changed files with 61 additions and 4 deletions.
33 changes: 30 additions & 3 deletions src/CmdLine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,11 @@ const static std::string prod_peaks[3] = {"first", "last", "all"};
const static std::string prod_vars[7] = {"elev", "amp", "width",
"riseTime", "backscatter", "heightAtEnergy", "energyAtHeight"};

//Verbosities
const static int num_verbs = 6;
const static std::string verbs[num_verbs] = {"trace", "debug", "info", "warn",
"error", "critical"};

const static std::vector<int> start = {0,18,36,54,72,90};//,96,102};

/****************************************************************************
Expand Down Expand Up @@ -52,7 +57,7 @@ void CmdLine::setUsageMessage()
<< " :Disables gaussian fitter, using first diff method instead" << std::endl;
buffer << " -h"
<< " :Prints this help message" << std::endl;
buffer << std::endl;
buffer << std::endl;
buffer << "Product Type Options:" << std::endl;
buffer << " -e <list of products>"
<< " :Generates Elevation products" << std::endl;
Expand All @@ -68,6 +73,10 @@ void CmdLine::setUsageMessage()
buffer << " Scientific notation allowed for calibration constant"
<< " (e.g. 0.78 = 7.8e-1 = 7.8E-1)"
<< std::endl;
buffer << " -v <verbosity level>"
<< " :Sets the level of verbosity for the logger to use" << std::endl;
buffer << " Options are 'trace', 'debug', 'info', 'warn', 'error'"
<< ", and 'critical'" << std::endl;
buffer << " --all <calibration constant>"
<< " :Generates all products for every variable. calibration constant"
<< " is used for backscatter coefficient calculations" << std::endl;
Expand Down Expand Up @@ -124,6 +133,7 @@ CmdLine::CmdLine(){
printUsageMessage = false;
useGaussianFitting = true;
calcBackscatter = false;
verb = (verbosity) NULL;
exeName = "";
setUsageMessage();
}
Expand All @@ -138,7 +148,18 @@ std::string CmdLine::getInputFileName(bool pls){
return pls ? plsFileName : wvsFileName;
}


/**
* Tries to match option given with verbosity flag to a known value,
* and if so, sets verbosity instance variable to match it.
*/
void CmdLine::set_verbosity (char* new_verb) {
int i;
for (i = 0; i < num_verbs; i++) {
if (!std::strncmp (new_verb, verbs[i].c_str(), 9)) {
verb = (verbosity) i;
}
}
}

/**
* Function that parses the command line arguments
Expand Down Expand Up @@ -171,6 +192,7 @@ bool CmdLine::parse_args(int argc,char *argv[]){
{"file", required_argument, NULL, 'f'},
{"help", no_argument, NULL, 'h'},
{"firstdiff", no_argument, NULL, 'd'},
{"verbosity", required_argument, NULL, 'v'},
{"elevation", required_argument,NULL,'e'},
{"amplitude", required_argument,NULL,'a'},
{"width", required_argument,NULL,'w'},
Expand All @@ -188,7 +210,7 @@ bool CmdLine::parse_args(int argc,char *argv[]){
* ":hf:s:" indicate that option 'h' is without arguments while
* option 'f' and 's' require arguments
*/
while((optionChar = getopt_long (argc, argv, "-:hdf:e:a:w:r:b:l:",
while((optionChar = getopt_long (argc, argv, "-:hdf:e:a:w:r:b:l:v:",
long_options, &option_index))!= -1){
if (optionChar == 'f') { //Set the filename to parse
fArg = optarg;
Expand All @@ -197,6 +219,11 @@ bool CmdLine::parse_args(int argc,char *argv[]){
printUsageMessage = true;
} else if (optionChar == 'd') { //Sets analysis method
useGaussianFitting = false;
} else if (optionChar == 'v') {
set_verbosity(optarg);
if (verb == (verbosity) NULL) {
printUsageMessage = true;
}
} else if (optionChar == 'e' || optionChar == 'a' || optionChar == 'w'
|| optionChar == 'r' || optionChar == 'b'){
//Sets which pruducts to create and for which variable
Expand Down
6 changes: 5 additions & 1 deletion src/CmdLine.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ class CmdLine{
// else, use smooth second difference
bool max_elev_flag;


void set_verbosity(char* new_verb);

public:
//calibration constant (for backscatter option)
Expand All @@ -49,6 +49,10 @@ class CmdLine{
//True stifles all output statements
bool quiet;

// For conveying verbosity to main function in a readable way
enum verbosity { trace, debug, info, warn, error, critical };
verbosity verb;

CmdLine();


Expand Down
2 changes: 2 additions & 0 deletions src/CmdLine_unittests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -305,6 +305,8 @@ TEST_F(CmdLineTest, invalidNonProductOption){
ASSERT_TRUE(cmd.printUsageMessage);
}

//Tests that verbosity is set to the correct value by the -v option

/****************************************************************************
*
* Long Option Tests
Expand Down
24 changes: 24 additions & 0 deletions src/pls_to_geotiff.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,30 @@ int main (int argc, char *argv[]) {
return 1;
}

// Set verbosity if not null
if (cmdLineArgs.verb != (CmdLine::verbosity) NULL) {
switch (cmdLineArgs.verb) {
case CmdLine::verbosity::trace:
spdlog::set_level(spdlog::level::trace);
break;
case CmdLine::verbosity::debug:
spdlog::set_level(spdlog::level::debug);
break;
case CmdLine::verbosity::info:
spdlog::set_level(spdlog::level::info);
break;
case CmdLine::verbosity::warn:
spdlog::set_level(spdlog::level::warn);
break;
case CmdLine::verbosity::error:
spdlog::set_level(spdlog::level::err);
break;
case CmdLine::verbosity::critical:
spdlog::set_level(spdlog::level::critical);
break;
}
}

//Collect start time
Clock::time_point t1 = Clock::now();

Expand Down

0 comments on commit 1c86435

Please sign in to comment.