diff --git a/src/FlightLineData.cpp b/src/FlightLineData.cpp index e764b49..5d56679 100644 --- a/src/FlightLineData.cpp +++ b/src/FlightLineData.cpp @@ -50,7 +50,7 @@ int FlightLineData::setFlightLineData(std::string fileName){ pOpener.set_file_name(fileName.c_str()); pReader = pOpener.open(); if(pReader == NULL){ - throw "Unable to Open File" + fileName; + spdlog::critical("Unable to Open File {}", fileName); return 1; } @@ -356,18 +356,18 @@ int FlightLineData::calc_xyz_activation(std::vector *peaks){ (*it)->triggering_location * current_wave_gps_info.dx + current_wave_gps_info.x_first; if((*it)->x_activation < bb_x_min || (*it)->x_activation > bb_x_max+1){ - std::cerr << "\nx activation: "<< (*it)->x_activation - << " not in range: " << bb_x_min << " - " << bb_x_max << - std::endl; + spdlog::error("\nx activation: {} not in range: {} - {}", + (*it)->x_activation, bb_x_min, bb_x_max); + } (*it)->y_activation = (*it)->triggering_location * current_wave_gps_info.dy + current_wave_gps_info.y_first; if((*it)->y_activation < bb_y_min || (*it)->y_activation > bb_y_max+1){ - std::cerr << "\ny activation: "<< (*it)->y_activation - << " not in range: " << bb_y_min << " - " << bb_y_max << - std::endl; + spdlog::error("\ny activation: {} not in range: {} - {}", + (*it)->y_activation, bb_y_min, bb_y_max); + } (*it)->z_activation = diff --git a/src/GaussianFitter.cpp b/src/GaussianFitter.cpp index ca73dfb..f4daed7 100644 --- a/src/GaussianFitter.cpp +++ b/src/GaussianFitter.cpp @@ -440,18 +440,14 @@ int GaussianFitter::find_peaks(std::vector* results, } // PRINT DATA AND MODEL FOR TESTING PURPOSES - #ifdef DEBUG - std::cout << "Gaussian sum based on guesses - before solve system:" - << std::endl; + spdlog::trace("Gaussian sum based on guesses - before solve system:"); + for (int i = 0; i < n; ++i){ double ti = fit_data.t[i]; // double yi = fit_data.y[i]; double fi = gaussianSum(x, ti); printf("%f ", fi); } - std::cout << std::endl; - std::cout << std::endl; - #endif fdf_params.trs = gsl_multifit_nlinear_trs_dogleg; @@ -459,9 +455,7 @@ int GaussianFitter::find_peaks(std::vector* results, fdf_params.solver = gsl_multifit_nlinear_solver_svd; fdf_params.fdtype = GSL_MULTIFIT_NLINEAR_CTRDIFF; -#ifdef DEBUG - std::cerr << "peakCount = " << peakCount << std::endl; -#endif + spdlog::error("peakCount = {}",peakCount); if(!solve_system(x, &fdf, &fdf_params, max)){ incr_pass(); @@ -526,11 +520,9 @@ int GaussianFitter::find_peaks(std::vector* results, peak->position_in_wave = i+1; } -#ifdef FINAL_PEAK_TEST - std::cerr << "--------------------" << std::endl; - std::cerr << "results.size = " << results->size() << std::endl; - std::cerr << "is empty = " << results->empty() << std::endl; -#endif + spdlog::error("--------------------"); + spdlog::error("results.size = {}", results->size()); + spdlog::error("is empty = {}", results->empty()); if (!results->empty()) { Peak* final_peak_ptr = results->back(); @@ -539,49 +531,39 @@ int GaussianFitter::find_peaks(std::vector* results, } i++; } - #ifdef DEBUG // PRINT DATA AND MODEL FOR TESTING PURPOSES - std::cout << "Gaussian sum in solve system and not failed:" - << std::endl; + spdlog::trace("Gaussian sum in solve system and not failed:"); + for (int i = 0; i < n; ++i){ double ti = fit_data.t[i]; // double yi = fit_data.y[i]; double fi = gaussianSum(x, ti); printf("%f ", fi); } - std::cout << std::endl; - std::cout << std::endl; - #endif } else{ - #ifdef DEBUG // FOR TESTING PURPOSES - std::cout << "In solve system and failed:" <* results, } noise_level = ((float)max)*.09; - #ifdef DEBUG - std::cerr << "Max = " << max << " Noise = " << ((float)max)*.09 - << std::endl; - #endif + spdlog::error("Max = {} Noise = {}", max, ((float)max)*.09); + if (noise_level < 6){ noise_level = 6; diff --git a/src/GetPLSDetails.cpp b/src/GetPLSDetails.cpp index e5352dd..6357548 100644 --- a/src/GetPLSDetails.cpp +++ b/src/GetPLSDetails.cpp @@ -7,13 +7,26 @@ #include "pulsewriter.hpp" #include "PulseData.hpp" +// Activity level must be defined before spdlog is included. +#define SPDLOG_ACTIVE_LEVEL SPDLOG_LEVEL_TRACE + +#include "spdlog/spdlog.h" +#include "spdlog/async.h" +#include "spdlog/sinks/stdout_color_sinks.h" int main (int argc, char *argv[]) { + // Setting up logger + spdlog::set_pattern("[%^%=8l%$] %v"); + // Sets new pattern for timestamp + + auto logger = spdlog::create_async( + "logger"); + PULSEreadOpener pOpener; PULSEreader *pReader; if(argc < 2){ - std::cerr << "Usage: " << argv[0] << " " <", argv[0]); return 1; } @@ -21,7 +34,7 @@ int main (int argc, char *argv[]) { pOpener.set_file_name(fileName.c_str()); pReader = pOpener.open(); if(pReader == NULL){ - throw "Unable to Open File" + fileName; + spdlog::critical("Unable to Open File {}", fileName); return 1; } @@ -66,34 +79,32 @@ int main (int argc, char *argv[]) { std::string utm_str = tokens[0]; std::string geog_cs = tokens[1]; - std::cout << "\nReading information from the header of: " << argv[1] - << std::endl; - std::cout << "----------------------------------------"; + spdlog::trace("\nReading information from the header of: {}", argv[1]); + + spdlog::trace("----------------------------------------") for(std::size_t i = 0; i < strlen(argv[1]); i++){ - std::cout << "-"; + spdlog::trace("-"); } - std::cout << std::endl; - std::cout << "No of pulses: " << number_of_pulses << std::endl; + spdlog::trace("No of pulses: {}", number_of_pulses); - std::cout << "\nUTM: " << utm_str << std::endl; - std::cout << "Geog_cs: "<< geog_cs << std::endl; + spdlog::trace("\nUTM: {}", utm_str); + spdlog::trace("Geog_cs: {}", geog_cs); - std::cout << "\nMin x: "<< bb_x_min << std::endl; - std::cout << "Max x: "<< bb_x_max << std::endl; - std::cout << "Min y: "<< bb_y_min << std::endl; - std::cout << "Max y: "<< bb_y_max << std::endl; + spdlog::trace("\nMin x: {}", bb_x_min); + spdlog::trace("Max x: {}", bb_x_max); + spdlog::trace("Min y: {}", bb_y_min); + spdlog::trace("Max y: {}", bb_y_max); fprintf(stdout,"\nMin x: %Lf\nMax y: %Lf\n",bb_x_min,bb_y_max); - std::cout << "\nCalculating i, j max, mins and extents:"<< std::endl; - std::cout << "---------------------------------------"<< std::endl; - std::cout << "\nBounding box 'x_idx' min: "<< bb_x_idx_min << std::endl; - std::cout << "Bounding box 'x_idx' max: "<< bb_x_idx_max << std::endl; - std::cout << "Bounding box 'y_idx' min: "<< bb_y_idx_min << std::endl; - std::cout << "Bounding box 'y_idx' max: "<< bb_y_idx_max << std::endl; + spdlog::trace("\nCalculating i, j max, mins and extents:"); + spdlog::trace("---------------------------------------"); + spdlog::trace("\nBounding box 'x_idx' min: {}", bb_x_idx_min); + spdlog::trace("Bounding box 'x_idx' max: {}", bb_x_idx_max); + spdlog::trace("Bounding box 'y_idx' min: {}", bb_y_idx_min); + spdlog::trace("Bounding box 'y_idx' max: {}", bb_y_idx_max); - std::cout << "\nBounding box 'x_idx' extent: "<< x_idx_extent << std::endl; - std::cout << "Bounding box 'y_idx' extent: "<< y_idx_extent << std::endl; - std::cout << std::endl; + spdlog::trace("\nBounding box 'x_idx' extent: {}", x_idx_extent); + spdlog::trace("Bounding box 'y_idx' extent: {}", y_idx_extent); } diff --git a/src/LidarDriver.cpp b/src/LidarDriver.cpp index 3a69c6a..dcded4e 100644 --- a/src/LidarDriver.cpp +++ b/src/LidarDriver.cpp @@ -51,13 +51,11 @@ void LidarDriver::calc_product_size(FlightLineData &data, int num_products){ //Use dimensional analysis to cancel out all units except for bytes bytes = bytes_per_val * vals_per_product * num_products / prefix_conversion; -#ifdef DEBUG - std::cerr << "Values per product: " << vals_per_product << std::endl; - std::cerr << "Bytes per value (float): " << bytes_per_val << std::endl; - std::cerr << "Conversion to " << units.at(i) << ". Divide by " << - prefix_conversion << std::endl; - std::cerr << "Total bytes needed: " << bytes << std::endl; -#endif + spdlog::error("Values per product: {}", vals_per_product); + spdlog::trace("Bytes per value (float): {}", bytes_per_val); + spdlog::trace("Conversion to {}. Divide by {}", units.at(i), prefix_conversion); + spdlog::trace("Total bytes needed: {}", bytes); + } //Find the best unit @@ -68,8 +66,8 @@ void LidarDriver::calc_product_size(FlightLineData &data, int num_products){ //Round to two decimals bytes = floorf(bytes * 100) / 100; - std::cout << num_products << " Tif files will require approximately " << - bytes << units.at(i) << std::endl; + spdlog::trace("{} Tif files will require approximately {} {}", num_products, + bytes, units.at(i)); } /** @@ -363,10 +361,10 @@ void LidarDriver::produce_product(LidarVolume &fitted_data, sizeof(float)); float avg = 0 ; float dev = 0; -#ifdef DEBUG - std::cerr << "Entering write image loop. In "<< __FILE__ << ":" << __LINE__ - << std::endl; -#endif + + spdlog::error("Entering write image loop. In {} : {}", __FILE__, __LINE__); + + //loop through every pixel position for (y = fitted_data.y_idx_extent - 1; y >= 0; y--) { @@ -410,10 +408,10 @@ void LidarDriver::produce_product(LidarVolume &fitted_data, break; } } -#ifdef DEBUG - std::cerr << "In writeImage loop. Writing band: "<< x << "," << y - << ". In " << __FILE__ << ":" << __LINE__ << std::endl; -#endif + + spdlog::error("In writeImage loop. Writing band: {}, {}. In {} : {}", x, y, + __FILE__, __LINE__); + //add the pixel values to the raster, one column at a time // Refer to http://www.gdal.org/classGDALRasterBand.html retval = gdal_ds->GetRasterBand(1)->RasterIO(GF_Write, 0, @@ -421,7 +419,7 @@ void LidarDriver::produce_product(LidarVolume &fitted_data, pixel_values, fitted_data.x_idx_extent, 1, GDT_Float32, 0, 0, NULL); if (retval != CE_None) { - std::cerr << "Error during writing band: 1 " << std::endl; + spdlog::error("Error during writing band: 1 "); } } diff --git a/src/LidarVolume.cpp b/src/LidarVolume.cpp index ea1d8bd..ffab9e5 100644 --- a/src/LidarVolume.cpp +++ b/src/LidarVolume.cpp @@ -3,7 +3,7 @@ // Author: ravi #include "LidarVolume.hpp" - +#include "spdlog/spdlog.h" //Default constructor LidarVolume::LidarVolume(){ @@ -114,7 +114,7 @@ void LidarVolume::insert_peak(Peak* peak){ // make sure we are in our bounding box if((long int)x_idx > x_idx_extent || (long int)y_idx > y_idx_extent){ - std::cerr << "ERROR: Invalid peak ignored" << std::endl; + spdlog::error("ERROR: Invalid peak ignored"); return; } unsigned long int p = position(y_idx,x_idx); diff --git a/src/Peak.cpp b/src/Peak.cpp index d56760c..b382fb0 100644 --- a/src/Peak.cpp +++ b/src/Peak.cpp @@ -5,6 +5,7 @@ #include "math.h" #include "Peak.hpp" #include +#include "spdlog/spdlog.h" //Default constructor Peak::Peak(){ @@ -75,15 +76,12 @@ void Peak::calcBackscatter(double emitted_amp, double emitted_fwhm, backscatter_coefficient = calibration_constant * (pow(range, 2)*amp*standard_dev) / (emitted_amp*n_atm); -#ifdef debug - std::cout << "Outgoing Amplitude = " << emitted_amp - << std::endl; - std::cout << "Returning Amplitude = " << amp << std::endl; - std::cout << "Range = " << range << std::endl; - std::cout << "Standard Deviation = " << standard_dev << std::endl; - std::cout << "Atmoshperic Transmission Factor = " << n_atm << std::endl; - std::cout << "Backscatter Coefficient = " << backscatter_coefficient << std::endl; -#endif + spdlog::trace("Outgoing Amplitude = {}", emitted_amp); + spdlog::trace("Returning Amplitude = {}", amp); + spdlog::trace("Range = {}", range); + spdlog::trace("Standard Deviation = {}", standard_dev); + spdlog::trace("Atmoshperic Transmission Factor = {}", n_atm); + spdlog::trace("Backscatter Coefficient = {}", backscatter_coefficient); } /** diff --git a/src/WaveGPSInformation.cpp b/src/WaveGPSInformation.cpp index 49da1fc..91cadf7 100644 --- a/src/WaveGPSInformation.cpp +++ b/src/WaveGPSInformation.cpp @@ -5,6 +5,8 @@ #include #include "WaveGPSInformation.hpp" #include +#include "spdlog/spdlog.h" + //Default constructor WaveGPSInformation::WaveGPSInformation(){ // enter default values @@ -100,20 +102,21 @@ void WaveGPSInformation::populateGPS(PULSEreader *pReader){ * Displays all GPS data */ void WaveGPSInformation::displayGPSData(){ - std::cout << x_anchor << std::endl; - std::cout << y_anchor << std::endl; - std::cout << z_anchor << std::endl; - std::cout << x_target << std::endl; - std::cout << y_target << std::endl; - std::cout << z_target << std::endl; - std::cout << x_first << std::endl; - std::cout << y_first << std::endl; - std::cout << z_first << std::endl; - std::cout << x_last << std::endl; - std::cout << y_last << std::endl; - std::cout << z_last << std::endl; - std::cout << edge << std::endl; - std::cout << facet << std::endl; - std::cout << scanDirection << std::endl; - std::cout << intensity << std::endl; + spdlog::trace("{}", x_anchor); + spdlog::trace("{}", y_anchor); + spdlog::trace("{}", z_anchor); + spdlog::trace("{}", x_target); + spdlog::trace("{}", y_target); + spdlog::trace("{}", z_target); + spdlog::trace("{}", x_first); + spdlog::trace("{}", y_first); + spdlog::trace("{}", z_first); + spdlog::trace("{}", x_last); + spdlog::trace("{}", y_last); + spdlog::trace("{}", z_last); + spdlog::trace("{}", edge); + spdlog::trace("{}", facet); + spdlog::trace("{}", scanDirection); + spdlog::trace("{}", intensity); + } diff --git a/src/testDriver.cpp b/src/testDriver.cpp index 75399c0..02d47ce 100644 --- a/src/testDriver.cpp +++ b/src/testDriver.cpp @@ -11,10 +11,28 @@ #include "cmdLine.hpp" #include "parseFile.hpp" +// Activity level must be defined before spdlog is included. +#define SPDLOG_ACTIVE_LEVEL SPDLOG_LEVEL_TRACE + +#include "spdlog/spdlog.h" +#include "spdlog/async.h" +#include "spdlog/sinks/stdout_color_sinks.h" + + int testCmdLine(); int testFileReader(); int main (){ + + // Setting up logger + spdlog::set_pattern("[%^%=8l%$] %v"); + // Sets new pattern for timestamp + + auto logger = spdlog::create_async( + "logger"); + + + int failCount = 0; // Call all tests associated with cmdLine parsing @@ -23,8 +41,8 @@ int main (){ // Call all tests associated with fileReading failCount += testFileReader(); - std::cerr << "All Testing Complete: " << failCount << " tests failed\n" - << std::endl; + spdlog::error("All Testing Complete: {} tests failed\n", failCount); + } /** @@ -62,8 +80,8 @@ int testCmdLine(){ } // if getting space failed just return with a failure if(someArgs == NULL){ - std::cerr << "FAILURE: Malloc failed for testing" << - std::endl; + spdlog::error("FAILURE: Malloc failed for testing"); + return 1; } @@ -83,7 +101,7 @@ int testCmdLine(){ noOfArgs = 1; strncpy( someArgs[0],"test",4); parseCmdLineArgs(noOfArgs,someArgs); - std::cerr << "\nFAIL: Test 1 - No command line arguments" << std::endl; + spdlog::error("\nFAIL: Test 1 - No command line arguments"); failCount++; }catch(const std::exception& e){ passCount++; @@ -101,8 +119,8 @@ int testCmdLine(){ strncpy( someArgs[1],"-f",2); parseCmdLineArgs(noOfArgs,someArgs); failCount++; - std::cerr << "FAIL: Test 2 - Valid option '-f' without argument" - << std::endl; + spdlog::error("FAIL: Test 2 - Valid option '-f' without argument"); + }catch(const std::exception& e){ passCount++; std::cerr << e.what(); @@ -119,16 +137,16 @@ int testCmdLine(){ strncpy( someArgs[1],"-g",2); parseCmdLineArgs(noOfArgs,someArgs); failCount++; - std::cerr << "FAIL: Test 3 - Invalid option '-f' without argument" - << std::endl; + spdlog::error("FAIL: Test 3 - Invalid option '-f' without argument"); + }catch(const std::exception& e){ passCount++; std::cerr << e.what(); } - std::cerr << "\nTesting Complete: " << failCount << " of " << - failCount+passCount << " tests failed" << std::endl; + spdlog::error("\nTesting Complete: {} of {} tests failed", failCount, + failCount+passCount); return failCount; }