#include "StrideSearchConfig.h" #include "SSDefs.hpp" #include "SSUtilities.hpp" #include "SSSearchParams.hpp" #include "SSSearchManager.hpp" #include "SSInput.hpp" #include #include #include #include /** @file Basic example of a serial extratropical cyclone search driver. Input is from the command line, with defaults for each variable predefined in the Input struct's constructor. Criteria from Mendes et. al. 2010, _Theor. Appl. Climatology_ 100. The ::main function illustrates the StrideSearch workflow and how to use the StrideSearch::SearchManager class. */ using namespace StrideSearch; typedef LatLonLayout Layout; typedef std::shared_ptr crit_ptr; typedef std::shared_ptr colloc_ptr; struct ExTropInput : public Input { Real psl_max; Real grad_min; Int stop_timestep; Int timestep_stride; ExTropInput(int argc, char* argv[]): Input(argc, argv) {parse_args(argc, argv);} void parse_args(const int argc, char* argv[]) override; std::string help_msg() const override; std::string status_msg() const; }; int main(int argc, char* argv[]) { print_copyright(); /// Step 1: Collect user input ExTropInput input(argc, argv); std::cout << input.status_msg(); if (!input.valid) { throw std::runtime_error("invalid input."); } std::vector fn = {input.data_dir + "/" + input.filelist_fname}; crit_ptr press_crit(new MinCriterion("SLP", input.psl_max)); crit_ptr grad_crit(new MaxCriterion("PRESGRAD", input.grad_min)); //crit_ptr grad_crit(new MaxAverageCriterion("PRESGRAD", "lat", input.grad_min)); std::vector criteria = {press_crit, grad_crit}; colloc_ptr pgcolloc(new CollocationCriterion(press_crit, grad_crit, input.sec_radius)); std::vector coll_criteria = {pgcolloc}; /** Step 2: Define search parameters. This is required because this data set has time values define in units of minutes, not days. Also, using SearchParams::timestep_stride is a good way to speed up the search. */ SearchParams params(input.time_units, input.timestep_stride); /// Step 3: Setup the search SearchManager search(input.region(), input.sec_radius); search.setStartDate(input.start_date()); search.setInputFiles(fn, params); search.defineCriteria(criteria, coll_criteria); std::cout << search.infoString(); /// Step 4: Run the search search.runSpatialSearch(params, input.stop_timestep); /// Step 5: Output results std::ofstream outfile(input.ofilename); search.outputCSV(outfile); outfile.close(); } void ExTropInput::parse_args(const int argc, char* argv[]) { filelist_fname = "ERAinterim_extratrop_grad.nc"; sb = -70; nb = -30; wb = 240; eb = 360; sec_radius = 1000; psl_max = 101000; grad_min = 0.55; time_units = DTUnits::MINUTES; timestep_stride = 60; stop_timestep = -1; start_year = 1979; start_month = 1; ofilename = "so_extratrop_results.txt"; for (int i=1; i \t Sea level pressure threshold in Pascals.\n"; ss << "\t-grad \t Pressure gradient threshold in hPa per 250 km.\n"; ss << "\t-stop \t Stop search at this time step [default: -1].\n"; return ss.str(); }