diff --git a/.github/workflows/build-windows.yml b/.github/workflows/build-windows.yml index 4afc6a9d..c7a9d909 100644 --- a/.github/workflows/build-windows.yml +++ b/.github/workflows/build-windows.yml @@ -115,6 +115,7 @@ jobs: .\bootstrap-vcpkg.bat .\vcpkg integrate install .\vcpkg install tiff # --recurse --editable + .\vcpkg install getopt # Write-Host "Listing all files in installed\x64-windows:" # Get-ChildItem -Recurse installed\x64-windows | ForEach-Object { $_.FullName } diff --git a/Cell2Fire/Cell2Fire.cpp b/Cell2Fire/Cell2Fire.cpp index 4faa5c61..dda54ba1 100644 --- a/Cell2Fire/Cell2Fire.cpp +++ b/Cell2Fire/Cell2Fire.cpp @@ -975,7 +975,7 @@ bool Cell2Fire::RunIgnition(std::default_random_engine generator, int ep){ } -// Send messages + // Send messages std::unordered_map> Cell2Fire::SendMessages(){ // Iterator std::unordered_map::iterator it; @@ -1698,15 +1698,16 @@ std::vector Cell2Fire::getFireProgressMatrix(){ *******************************************************************************/ int main(int argc, char* argv[]) { - printf("version: %s\n", c2fw_version.c_str()); + std::cout << "version: " << c2fw_version << "\n"; - // Read Arguments - std::cout << "------ Command line values ------\n"; - arguments args; - arguments* args_ptr = &args; - parseArgs(argc, argv, args_ptr); - - //printArgs(args); + std::cout << "------ Arguments ------\n"; + arguments args; + if (!parseArguments(argc, argv, args)) { + std::cerr << "Failed to parse arguments" << std::endl; + return 1; + } + postProcessArguments(args); + printArguments(args); // Random generator and distributions //std::default_random_engine generator (args.seed); diff --git a/Cell2Fire/ReadArgs.cpp b/Cell2Fire/ReadArgs.cpp index 92cf2dad..b33bc737 100644 --- a/Cell2Fire/ReadArgs.cpp +++ b/Cell2Fire/ReadArgs.cpp @@ -7,8 +7,8 @@ #include #include #include - - +#include +#include inline char separator() { @@ -19,565 +19,273 @@ inline char separator() #endif } +void printHelp() { + std::cout + << "Usage: Cell2Fire[.exe] [options]\n" + << "Options:\n" + << " -O, --Simulator Set simulator (S, C, K), default S\n" + << " -M, --InFolder Set input instance folder\n" + << " -N, --OutFolder Set output results folder\n" + << " -L, --HarvestPlan Set Harvest plan\n" + << " -P, --WeatherOpt Set Weather option\n" + + << " -a, --AllowCROS Enable CROS\n" + << " -b, --BBOTuning Enable BBO tuning\n" + << " -c, --FinalGrid Output final scars grids\n" + << " -d, --Ignitions Enable reading from Ignitions.csv\n" + << " -e, --IgnitionsLog Output ignition history csv\n" + << " -f, --OutCrown Output crown fire\n" + << " -g, --OutCrownConsumption Output crown consumption\n" + << " -i, --OutFl Output flame lenght\n" + << " -j, --OutIntensity Output fire line intensity (Byram)\n" + << " -k, --OutMessages Output propagation digraph messages\n" + << " -l, --OutRos Output Rate Of Spread\n" + << " -m, --OutSurfConsumption Output surface consumption\n" + << " -n, --OutputGrids Output scar grids\n" + + << " -p, --BFactor Set Backward ellipsoid spread factor\n" + << " -q, --CBDFactor Set Crown bulk density factor (S&B)\n" + << " -r, --CCFFactor Set Canopy cover fraction factor (S&B)\n" + << " -s, --CROSThreshold Set CROS threshold\n" + << " -t, --EFactor Set Ellipsoid spread factor\n" + << " -u, --FFactor Set Forward ellipsoid spread factor\n" + << " -o, --FirePeriodLen Set fire period length\n" + << " -w, --HFIThreshold Set HFI threshold\n" + << " -x, --HFactor Set Heat factor\n" + << " -y, --ROS10Factor Set ROS10 factor (S&B)\n" + << " -z, --ROSCV Set ROS coefficient of variation\n" + << " -A, --ROSThreshold Set ROS threshold\n" + + << " -B, --FMC Set Fuel Moisture Content\n" + << " -C, --IgnitionRadius Set Ignition radius\n" + << " -D, --MaxFirePeriods Set Maximum fire periods\n" + << " -E, --MinutesPerWP Set Minutes per weather period\n" + << " -F, --NWeatherFiles Set Number of weather files\n" + << " -G, --TotalSims Set Total simulations\n" + << " -H, --TotalYears Set Total years\n" + << " -I, --nthreads Set Number of threads\n" + << " -J, --scenario Set Scenario\n" + << " -K, --seed Set random number generator seed\n" + + << " -v, --verbose Enable verbose mode\n" + << " -h, --help Show this help message\n" + << "\n" + << "Documentation: https://fire2a.github.io/docs\n" + << "Software feedback: https://github.com/fire2a/C2F-W/issues\n" + << "General contact: www.fire2a.com\n" + << "\n" + << "Example:\n" + << " Cell2Fire --Simulator K --InFolder data/Kitral/Portillo-tif --OutFolder results --TotalSims 100 --nthreads 7 --OutMessages --OutputGrids | tee results/log.txt\n" + << "\n"; +} -char* getCmdOption(char ** begin, char ** end, const std::string & option) -{ - char ** itr = std::find(begin, end, option); - if (itr != end && ++itr != end) - { - return *itr; +void printArguments(const arguments& args) { + std::cout + << "--- Booleans ---\n" + << "AllowCROS: " << args.AllowCROS << "\n" + << "BBOTuning: " << args.BBOTuning << "\n" + << "FinalGrid: " << args.FinalGrid << "\n" + << "Ignitions: " << args.Ignitions << "\n" + << "IgnitionsLog: " << args.IgnitionsLog << "\n" + << "OutCrown: " << args.OutCrown << "\n" + << "OutCrownConsumption: " << args.OutCrownConsumption << "\n" + << "OutFl: " << args.OutFl << "\n" + << "OutIntensity: " << args.OutIntensity << "\n" + << "OutMessages: " << args.OutMessages << "\n" + << "OutRos: " << args.OutRos << "\n" + << "OutSurfConsumption: " << args.OutSurfConsumption << "\n" + << "OutputGrids: " << args.OutputGrids << "\n" + << "verbose: " << args.verbose << "\n" + + << "--- Floats ---\n" + << "BFactor: " << args.BFactor << "\n" + << "CBDFactor: " << args.CBDFactor << "\n" + << "CCFFactor: " << args.CCFFactor << "\n" + << "CROSThreshold: " << args.CROSThreshold << "\n" + << "EFactor: " << args.EFactor << "\n" + << "FFactor: " << args.FFactor << "\n" + << "FirePeriodLen: " << args.FirePeriodLen << "\n" + << "HFIThreshold: " << args.HFIThreshold << "\n" + << "HFactor: " << args.HFactor << "\n" + << "ROS10Factor: " << args.ROS10Factor << "\n" + << "ROSCV: " << args.ROSCV << "\n" + << "ROSThreshold: " << args.ROSThreshold << "\n" + + << "--- Integers ---\n" + << "FMC: " << args.FMC << "\n" + << "IgnitionRadius: " << args.IgnitionRadius << "\n" + << "MaxFirePeriods: " << args.MaxFirePeriods << "\n" + << "MinutesPerWP: " << args.MinutesPerWP << "\n" + << "NWeatherFiles: " << args.NWeatherFiles << "\n" + << "TotalSims: " << args.TotalSims << "\n" + << "TotalYears: " << args.TotalYears << "\n" + << "nthreads: " << args.nthreads << "\n" + << "scenario: " << args.scenario << "\n" + << "seed: " << args.seed << "\n" + + << "--- Strings ---\n" + << "HarvestPlan: " << args.HarvestPlan << "\n" + << "InFolder: " << args.InFolder << "\n" + << "OutFolder: " << args.OutFolder << "\n" + << "Simulator: " << args.Simulator << "\n" + << "WeatherOpt: " << args.WeatherOpt << "\n" + + << "--- auto ---\n" + << "HCells: "; + for (const auto& cell : args.HCells) { + std::cout << cell << " "; } - return 0; -} -bool cmdOptionExists(char** begin, char** end, const std::string& option) -{ - return std::find(begin, end, option) != end; + std::cout << "\nBCells: "; + for (const auto& cell : args.BCells) { + std::cout << cell << " "; + } + std::cout << std::endl; } -void parseArgs(int argc, char* argv[], arguments* args_ptr) -{ - // Help - if (cmdOptionExists(argv, argv + argc, "-h") || cmdOptionExists(argv, argv + argc, "--help")) { - printf("Help at https://github.com/fire2a/docs\n"); - printf("Try graphically building the arguments using the QGIS -processing algo.- plugin\n"); - exit(0); - } - - // Empty default - char empty = '\0'; - - - // Strings - //--input-instance-folder - char* input_folder = getCmdOption(argv, argv + argc, "--input-instance-folder"); - if (input_folder) { - printf("InFolder: %s \n", input_folder); - } - else input_folder = ∅ - - //--output-folder - char* output_folder = getCmdOption(argv, argv + argc, "--output-folder"); - if (output_folder) { - printf("OutFolder: %s \n", output_folder); - } - else output_folder = ∅ - - //--weather - char* input_weather = getCmdOption(argv, argv + argc, "--weather"); - if (input_weather) { - printf("WeatherOpt: %s \n", input_weather); - } - else input_weather = ∅ - - //--FirebreakPlan - char* input_hplan = getCmdOption(argv, argv + argc, "--FirebreakCells"); - if (input_hplan) { - printf("FirebreakCells: %s \n", input_hplan); - } - else input_hplan = ∅ - - // Booleans - bool out_messages = false; - bool out_trajectories = false; - bool no_output = false; - bool verbose_input = false; - bool iplog_input = false; - bool input_ignitions = false; - bool out_grids = false; - bool out_fl=false; - bool out_intensity=false; - bool out_ros=false; - bool out_crown = false; - bool out_crown_consumption=false; - bool out_surf_consumption=false; - bool out_finalgrid = false; - bool prom_tuned = false; - bool out_stats = false; - bool bbo_tuning = false; - bool allow_cros = false; - - //--out-messages - if (cmdOptionExists(argv, argv + argc, "--output-messages")) { - out_messages = true; - printf("OutMessages: %d \n", out_messages); - } - - //--fire-behavior - if (cmdOptionExists(argv, argv + argc, "--out-fl")) { - out_fl = true; - printf("OutFlameLength: %d \n", out_fl); - } - //--fire-behavior - if (cmdOptionExists(argv, argv + argc, "--out-intensity")) { - out_intensity = true; - printf("OutIntensity: %d \n", out_intensity); - } - //--fire-behavior - if (cmdOptionExists(argv, argv + argc, "--out-ros")) { - out_ros = true; - printf("OutROS: %d \n", out_ros); - } - //--fire-behavior - if (cmdOptionExists(argv, argv + argc, "--out-crown")) { - out_crown = true; - printf("OutCrown: %d \n", out_crown); - } - - if (cmdOptionExists(argv, argv + argc, "--out-cfb")) { - out_crown_consumption = true; - printf("OutCrownConsumption: %d \n", out_crown_consumption); - } - - if (cmdOptionExists(argv, argv + argc, "--out-sfb")) { - out_surf_consumption = true; - printf("OutSurfaceConsumption: %d \n", out_surf_consumption); - } - - - //--trajectories - //if (cmdOptionExists(argv, argv + argc, "--trajectories")) { - // out_trajectories = true; - // printf("Trajectories: %d \n", out_trajectories); - //} - - //--no-output - //if (cmdOptionExists(argv, argv + argc, "--no-output")) { - // no_output = true; - // printf("noOutput: %d \n", no_output); - //} - //--verbose - if (cmdOptionExists(argv, argv + argc, "--verbose")) { - verbose_input = true; - printf("verbose: %d \n", verbose_input); - } - - // --ignitionsLog - if (cmdOptionExists(argv, argv + argc, "--ignitionsLog")) { - iplog_input = true; - printf("Ignition Points Log: %d \n", iplog_input); - } - - //--ignitions - if (cmdOptionExists(argv, argv + argc, "--ignitions")) { - input_ignitions = true; - printf("Ignitions: %d \n", input_ignitions); - } - - //--grids - if (cmdOptionExists(argv, argv + argc, "--grids")) { - out_grids = true; - printf("OutputGrids: %d \n", out_grids); - } - - //--final-grid - if (cmdOptionExists(argv, argv + argc, "--final-grid")) { - out_finalgrid = true; - printf("FinalGrid: %d \n", out_finalgrid); - } - - //--Prom_tuned - //if (cmdOptionExists(argv, argv + argc, "--PromTuned")) { - // prom_tuned = true; - // printf("PromTuned: %d \n", prom_tuned); - //} - - //--statistics - //if (cmdOptionExists(argv, argv + argc, "--statistics")) { - // out_stats = true; - // printf("Statistics: %d \n", out_stats); - //} - - //--bbo - if (cmdOptionExists(argv, argv + argc, "--bbo")) { - bbo_tuning = true; - printf("BBOTuning: %d \n", out_stats); - } +bool parseArguments(int argc, char* argv[], arguments& args) { + static struct option long_options[] = { + // Booleans + {"AllowCROS", no_argument, 0, 'a'}, + {"BBOTuning", no_argument, 0, 'b'}, + {"FinalGrid", no_argument, 0, 'c'}, + {"Ignitions", no_argument, 0, 'd'}, + {"IgnitionsLog", no_argument, 0, 'e'}, + {"OutCrown", no_argument, 0, 'f'}, + {"OutCrownConsumption", no_argument, 0, 'g'}, + {"OutFl", no_argument, 0, 'i'}, + {"OutIntensity", no_argument, 0, 'j'}, + {"OutMessages", no_argument, 0, 'k'}, + {"OutRos", no_argument, 0, 'l'}, + {"OutSurfConsumption", no_argument, 0, 'm'}, + {"OutputGrids", no_argument, 0, 'n'}, + {"verbose", no_argument, 0, 'v'}, + + // Floats + {"BFactor", required_argument, 0, 'p'}, + {"CBDFactor", required_argument, 0, 'q'}, + {"CCFFactor", required_argument, 0, 'w'}, + {"CROSThreshold", required_argument, 0, 's'}, + {"EFactor", required_argument, 0, 't'}, + {"FFactor", required_argument, 0, 'u'}, + {"FirePeriodLen", required_argument, 0, 'o'}, + {"HFIThreshold", required_argument, 0, 'w'}, + {"HFactor", required_argument, 0, 'x'}, + {"ROS10Factor", required_argument, 0, 'y'}, + {"ROSCV", required_argument, 0, 'z'}, + {"ROSThreshold", required_argument, 0, 'A'}, + + // Integers + {"FMC", required_argument, 0, 'B'}, + {"IgnitionRadius", required_argument, 0, 'C'}, + {"MaxFirePeriods", required_argument, 0, 'D'}, + {"MinutesPerWP", required_argument, 0, 'E'}, + {"NWeatherFiles", required_argument, 0, 'F'}, + {"TotalSims", required_argument, 0, 'G'}, + {"TotalYears", required_argument, 0, 'H'}, + {"nthreads", required_argument, 0, 'I'}, + {"scenario", required_argument, 0, 'J'}, + {"seed", required_argument, 0, 'K'}, + + // Strings + {"HarvestPlan", required_argument, 0, 'L'}, + {"InFolder", required_argument, 0, 'M'}, + {"OutFolder", required_argument, 0, 'N'}, + {"Simulator", required_argument, 0, 'O'}, + {"WeatherOpt", required_argument, 0, 'P'}, + + {"help", no_argument, 0, 'h'}, + {0, 0, 0, 0} + }; + + int opt; + int option_index = 0; + while ((opt = getopt_long(argc, argv, "a:b:c:d:e:f:g:i:j:k:l:m:n:v:p:q:r:s:t:u:o:w:x:y:z:A:B:C:D:E:F:G:H:I:J:K:L:M:N:O:P:h", long_options, &option_index)) != -1) { + switch (opt) { + case 'a': args.AllowCROS = true; break; + case 'b': args.BBOTuning = true; break; + case 'c': args.FinalGrid = true; break; + case 'd': args.Ignitions = true; break; + case 'e': args.IgnitionsLog = true; break; + case 'f': args.OutCrown = true; break; + case 'g': args.OutCrownConsumption = true; break; + case 'i': args.OutFl = true; break; + case 'j': args.OutIntensity = true; break; + case 'k': args.OutMessages = true; break; + case 'l': args.OutRos = true; break; + case 'm': args.OutSurfConsumption = true; break; + case 'n': args.OutputGrids = true; break; + case 'v': args.verbose = true; break; + + case 'p': args.BFactor = std::atof(optarg); break; + case 'q': args.CBDFactor = std::atof(optarg); break; + case 'r': args.CCFFactor = std::atof(optarg); break; + case 's': args.CROSThreshold = std::atof(optarg); break; + case 't': args.EFactor = std::atof(optarg); break; + case 'u': args.FFactor = std::atof(optarg); break; + case 'o': args.FirePeriodLen = std::atof(optarg); break; + case 'w': args.HFIThreshold = std::atof(optarg); break; + case 'x': args.HFactor = std::atof(optarg); break; + case 'y': args.ROS10Factor = std::atof(optarg); break; + case 'z': args.ROSCV = std::atof(optarg); break; + case 'A': args.ROSThreshold = std::atof(optarg); break; + + case 'B': args.FMC = std::atoi(optarg); break; + case 'C': args.IgnitionRadius = std::atoi(optarg); break; + case 'D': args.MaxFirePeriods = std::atoi(optarg); break; + case 'E': args.MinutesPerWP = std::atoi(optarg); break; + case 'F': args.NWeatherFiles = std::atoi(optarg); break; + case 'G': args.TotalSims = std::atoi(optarg); break; + case 'H': args.TotalYears = std::atoi(optarg); break; + case 'I': args.nthreads = std::atoi(optarg); break; + case 'J': args.scenario = std::atoi(optarg); break; + case 'K': args.seed = std::atoi(optarg); break; + + case 'L': args.HarvestPlan = optarg; break; + case 'M': args.InFolder = optarg; break; + case 'N': args.OutFolder = optarg; break; + case 'O': args.Simulator = optarg; break; + case 'P': args.WeatherOpt = optarg; break; + case 'h': printHelp(); exit(0); + default: + std::cerr << "Unknown option: " << opt << std::endl; + printHelp(); + return false; + } + } + return true; +} - //--cros - if (cmdOptionExists(argv, argv + argc, "--cros")) { - allow_cros = true; - printf("CrownROS: %d \n", allow_cros); +void postProcessArguments(arguments& args) { + if (args.NWeatherFiles < 1) { + if (args.WeatherOpt == "random") { + args.NWeatherFiles = countWeathers(args.InFolder + separator() + "Weathers"); + } else { + args.NWeatherFiles = 1; } - - - // Floats and ints - // defaults - int dsim_years = 1; - int dnsims = 1; - int dweather_period_len = 60; - int dmax_fire_periods = 1000; - int dseed = 123; - int diradius = 0; - int dnthreads = 1; - int dfmc=100; - int dscen=3; - float dROS_Threshold= 0.1; - float dHFI_Threshold= 0.1; - float dCROS_Threshold= 0.5; - //float dCROSAct_Threshold= 1.0; - float dROSCV= 0.; - float dHFactor = 1.0; - float dFFactor = 1.0; - float dBFactor = 1.0; - float dEFactor = 1.0; - float dCBDFactor = 0.0; //spain - //float dCBHFactor = 1.0; - float dCCFFactor = 0.0; //spain - float dROS10Factor = 3.34; //spain - float dinput_PeriodLen= 1.; - - // aux - std::string::size_type sz; - - //--sim-years (float) - char * sim_years = getCmdOption(argv, argv + argc, "--sim-years"); - if (sim_years){ - printf("TotalYears: %s \n", sim_years); - args_ptr->TotalYears = std::stoi (sim_years ,&sz); - } - else args_ptr->TotalYears = dsim_years; - - //--nsims - char * input_nsims = getCmdOption(argv, argv + argc, "--nsims"); - if (input_nsims){ - printf("TotalSims: %s \n", input_nsims); - args_ptr->TotalSims = std::stoi (input_nsims ,&sz); } - else args_ptr->TotalSims = dnsims; - - //--nsims - char * simulator_option = getCmdOption(argv, argv + argc, "--sim"); - if (simulator_option){ - std::string s=simulator_option; - if (s!="S" && s!="K" && s!="C"){ - printf("%s Simulator Option not recognized or not developed, using S&B as default!!! \n", simulator_option); - args_ptr->Simulator=simulator_option; - } - else{ - printf("Simulator: %s \n", simulator_option); - args_ptr->Simulator = simulator_option; - } - } - else { - printf("No Simulator Option Selected, using S&B as default!!! \n"); - args_ptr->Simulator = "S";} - - - //--Weather-Period-Length - char * weather_period_len = getCmdOption(argv, argv + argc, "--Weather-Period-Length"); - if (weather_period_len){ - printf("WeatherPeriodLength: %s \n", weather_period_len); - args_ptr->MinutesPerWP = std::stoi (weather_period_len ,&sz); - } - else args_ptr->MinutesPerWP = dweather_period_len; - - //--nweathers - char * nweathers = getCmdOption(argv, argv + argc, "--nweathers"); - if (nweathers){ - args_ptr->NWeatherFiles = std::stoi (nweathers ,&sz); + if (args.FirePeriodLen <= args.MinutesPerWP) { + args.FirePeriodLen = args.MinutesPerWP; } - else{ - //std::cout << "No NWeatherFiles specified " << input_weather << std::endl; - if (std::string(input_weather) == "random") { - //std::cout << "Counting" << std::endl; - std::string input_string = input_folder; - args_ptr->NWeatherFiles = countWeathers(input_string + "/Weathers"); - } - else { - ///std::cout << "No NWeatherFiles specified 1 default" << std::endl; - args_ptr->NWeatherFiles = 1; - } - } - - //--Fire-Period-Length - char * input_PeriodLen = getCmdOption(argv, argv + argc, "--Fire-Period-Length"); - if (input_PeriodLen){ - printf("FirePeriodLength: %s \n", input_PeriodLen); - if (std::stof (input_PeriodLen ,&sz) <= args_ptr->MinutesPerWP){ - args_ptr->FirePeriodLen = std::stof (input_PeriodLen ,&sz); - } - else args_ptr->FirePeriodLen = args_ptr->MinutesPerWP; - } - else args_ptr->FirePeriodLen = dinput_PeriodLen; - - //--IgnitionRad - char * input_igrad = getCmdOption(argv, argv + argc, "--IgnitionRad"); - if (input_igrad){ - printf("IgnitionRadius: %s \n", input_igrad); - args_ptr->IgnitionRadius = std::stoi (input_igrad ,&sz); - } - else args_ptr->IgnitionRadius = diradius; - - //--fmc - char * input_fmc = getCmdOption(argv, argv + argc, "--fmc"); - if (input_fmc){ - printf("FoliarMoistureContent: %s \n", input_fmc); - args_ptr->FMC = std::stoi (input_fmc ,&sz); - } - else args_ptr->FMC = dfmc; - - //--scenario - char * input_scenario = getCmdOption(argv, argv + argc, "--scenario"); - if (input_scenario){ - printf("LiveAndDeadFuelMoistureContentScenario: %s \n", input_scenario); - args_ptr->scenario = std::stoi (input_scenario ,&sz); - } - else args_ptr->scenario = dscen; - - - //--ROS-Threshold - char * ROS_Threshold = getCmdOption(argv, argv + argc, "--ROS-Threshold"); - if (ROS_Threshold){ - printf("ROSThreshold: %s \n", ROS_Threshold); - args_ptr->ROSThreshold = std::stof (ROS_Threshold ,&sz); - } - else args_ptr->ROSThreshold = dROS_Threshold; - - //--CROS-Threshold - char * CROS_Threshold = getCmdOption(argv, argv + argc, "--CROS-Threshold"); - if (CROS_Threshold){ - printf("CROSThreshold: %s \n", CROS_Threshold); - args_ptr->CROSThreshold = std::stof (CROS_Threshold ,&sz); - } - else args_ptr->CROSThreshold = dCROS_Threshold; - - //--HFI-Threshold - char * HFI_Threshold = getCmdOption(argv, argv + argc, "--HFI-Threshold"); - if (HFI_Threshold){ - printf("HFIThreshold: %s \n", HFI_Threshold); - args_ptr->HFIThreshold = std::stof (HFI_Threshold ,&sz); - } - else args_ptr->HFIThreshold = dHFI_Threshold; - - //--CROSAct-Threshold - char * CROSAct_Threshold = getCmdOption(argv, argv + argc, "--CROSAct-Threshold"); - if (CROSAct_Threshold){ - printf("CROSActThreshold: %s \n", CROSAct_Threshold); - args_ptr->CROSActThreshold = std::stof (CROSAct_Threshold ,&sz); - } - else args_ptr->CROSThreshold = dCROS_Threshold; - - - //--HFactor - char * H_Factor = getCmdOption(argv, argv + argc, "--HFactor"); - if (H_Factor){ - printf("HFactor: %s \n", H_Factor); - args_ptr->HFactor = std::stof (H_Factor ,&sz); - } - else args_ptr->HFactor = dHFactor; - - //---FFactor - char * F_Factor = getCmdOption(argv, argv + argc, "--FFactor"); - if (F_Factor){ - printf("FFactor: %s \n", F_Factor); - args_ptr->FFactor = std::stof (F_Factor ,&sz); - } - else args_ptr->FFactor = dFFactor; - - ///--BFactor - char * B_Factor = getCmdOption(argv, argv + argc, "--BFactor"); - if (B_Factor){ - printf("BFactor: %s \n", B_Factor); - args_ptr->BFactor = std::stof (B_Factor ,&sz); - } - else args_ptr->BFactor = dBFactor; - - ///--EFactor - char * E_Factor = getCmdOption(argv, argv + argc, "--EFactor"); - if (E_Factor){ - printf("EFactor: %s \n", E_Factor); - args_ptr->EFactor = std::stof (E_Factor ,&sz); + if (args.Simulator != "S" && args.Simulator != "C" && args.Simulator != "K") { + printf("Simulator not in [\"S\", \"C\", \"K\"]\n"); + exit(1); } - else args_ptr->EFactor = dEFactor; - - ///--CBDFactor - char * CBD_Factor = getCmdOption(argv, argv + argc, "--CBDFactor"); - if (CBD_Factor){ - printf("CBDFactor: %s \n", CBD_Factor); - args_ptr->CBDFactor = std::stof (CBD_Factor ,&sz); - } - else args_ptr->CBDFactor = dCBDFactor; - - ///--CCFFactor - char * CCF_Factor = getCmdOption(argv, argv + argc, "--CCFFactor"); - if (CCF_Factor){ - printf("CCFFactor: %s \n", CCF_Factor); - args_ptr->CCFFactor = std::stof (CCF_Factor ,&sz); - } - else args_ptr->CCFFactor = dCCFFactor; - - ///--ROS10Factor - char * ROS10_Factor = getCmdOption(argv, argv + argc, "--ROS10Factor"); - if (ROS10_Factor){ - printf("ROS10Factor: %s \n", ROS10_Factor); - args_ptr->ROS10Factor = std::stof (ROS10_Factor, &sz); - } - else args_ptr->ROS10Factor = dROS10Factor; - - //--ROS-CV - char * ROS_CV = getCmdOption(argv, argv + argc, "--ROS-CV"); - if (ROS_CV){ - printf("ROS-CV: %s \n", ROS_CV); - args_ptr->ROSCV = std::stof (ROS_CV ,&sz); - } - else args_ptr->ROSCV = dROSCV; - - //--max-fire-periods - char * max_fire_periods = getCmdOption(argv, argv + argc, "--max-fire-periods"); - if (max_fire_periods){ - printf("MaxFirePeriods: %s \n", max_fire_periods); - args_ptr->MaxFirePeriods = std::stoi (max_fire_periods ,&sz); - } - else args_ptr->MaxFirePeriods = dmax_fire_periods; - - //--seed (int) - char * seed = getCmdOption(argv, argv + argc, "--seed"); - if (seed){ - printf("seed: %s \n", seed); - args_ptr->seed = std::stoi (seed ,&sz); - } - else args_ptr->seed = dseed; - - //--nthreads (int) - char* nthreads = getCmdOption(argv, argv + argc, "--nthreads"); - if (nthreads) { - printf("nthreads: %s \n", nthreads); - args_ptr->nthreads = std::stoi(nthreads, &sz); - } - else args_ptr->nthreads = dnthreads; - - // Populate structure - // Strings - if (input_folder == &empty){ - args_ptr->InFolder = ""; - } - else args_ptr->InFolder = input_folder; - - if (!args_ptr->InFolder.empty() && *args_ptr->InFolder.rbegin()!= separator()){ - args_ptr->InFolder+=separator(); - } - - if (output_folder == &empty && input_folder != &empty){ - args_ptr->OutFolder = args_ptr->InFolder + "simOuts"; - } else if(output_folder == &empty && input_folder == &empty){ - args_ptr->OutFolder = "simOuts"; - } else if(output_folder != &empty && input_folder == &empty){ - args_ptr->OutFolder = output_folder; - } else if(output_folder != &empty && input_folder != &empty){ - args_ptr->OutFolder = output_folder; - } - if (!args_ptr->OutFolder.empty() && *args_ptr->OutFolder.rbegin()!= separator()){ - args_ptr->OutFolder+=separator(); - } - - if (input_weather == &empty){ - args_ptr->WeatherOpt = "rows"; - } - else{ - args_ptr->WeatherOpt = input_weather; - } - - if (input_hplan == &empty){ - args_ptr->HarvestPlan = ""; - } - else args_ptr->HarvestPlan = input_hplan; - - // booleans - args_ptr->OutMessages = out_messages; - args_ptr->OutFl = out_fl; - args_ptr->OutIntensity = out_intensity; - args_ptr->OutRos = out_ros; - args_ptr->OutCrown = out_crown; - args_ptr->OutCrownConsumption = out_crown_consumption; - args_ptr->OutSurfConsumption = out_surf_consumption; - args_ptr->Trajectories = out_trajectories; - args_ptr->NoOutput = no_output; - args_ptr->verbose = verbose_input; - args_ptr->IgnitionsLog = iplog_input; - args_ptr->Ignitions = input_ignitions; - args_ptr->OutputGrids = out_grids; - args_ptr->FinalGrid = out_finalgrid; - args_ptr->PromTuned = prom_tuned; - args_ptr->Stats = out_stats; - args_ptr->BBOTuning = bbo_tuning; - args_ptr->AllowCROS = allow_cros; - -} - - -void printArgs(arguments args){ - - /* - std::cout << "Simulator: "< +#include +#include +#include +#include +#include +#include + + + +inline char separator() +{ +#if defined _WIN32 || defined __CYGWIN__ + return '\\'; +#else + return '/'; +#endif +} + + +char* getCmdOption(char ** begin, char ** end, const std::string & option) +{ + char ** itr = std::find(begin, end, option); + if (itr != end && ++itr != end) + { + return *itr; + } + return 0; +} + +bool cmdOptionExists(char** begin, char** end, const std::string& option) +{ + return std::find(begin, end, option) != end; +} + +void parseArgs(int argc, char* argv[], arguments* args_ptr) +{ + // Help + if (cmdOptionExists(argv, argv + argc, "-h") || cmdOptionExists(argv, argv + argc, "--help")) { + printf("Help at https://github.com/fire2a/docs\n"); + printf("Try graphically building the arguments using the QGIS -processing algo.- plugin\n"); + exit(0); + } + + // Empty default + char empty = '\0'; + + + // Strings + //--input-instance-folder + char* input_folder = getCmdOption(argv, argv + argc, "--input-instance-folder"); + if (input_folder) { + printf("InFolder: %s \n", input_folder); + } + else input_folder = ∅ + + //--output-folder + char* output_folder = getCmdOption(argv, argv + argc, "--output-folder"); + if (output_folder) { + printf("OutFolder: %s \n", output_folder); + } + else output_folder = ∅ + + //--weather + char* input_weather = getCmdOption(argv, argv + argc, "--weather"); + if (input_weather) { + printf("WeatherOpt: %s \n", input_weather); + } + else input_weather = ∅ + + //--FirebreakPlan + char* input_hplan = getCmdOption(argv, argv + argc, "--FirebreakCells"); + if (input_hplan) { + printf("FirebreakCells: %s \n", input_hplan); + } + else input_hplan = ∅ + + // Booleans + bool out_messages = false; + bool out_trajectories = false; + bool no_output = false; + bool verbose_input = false; + bool iplog_input = false; + bool input_ignitions = false; + bool out_grids = false; + bool out_fl=false; + bool out_intensity=false; + bool out_ros=false; + bool out_crown = false; + bool out_crown_consumption=false; + bool out_surf_consumption=false; + bool out_finalgrid = false; + bool prom_tuned = false; + bool out_stats = false; + bool bbo_tuning = false; + bool allow_cros = false; + + //--out-messages + if (cmdOptionExists(argv, argv + argc, "--output-messages")) { + out_messages = true; + printf("OutMessages: %d \n", out_messages); + } + + //--fire-behavior + if (cmdOptionExists(argv, argv + argc, "--out-fl")) { + out_fl = true; + printf("OutFlameLength: %d \n", out_fl); + } + //--fire-behavior + if (cmdOptionExists(argv, argv + argc, "--out-intensity")) { + out_intensity = true; + printf("OutIntensity: %d \n", out_intensity); + } + //--fire-behavior + if (cmdOptionExists(argv, argv + argc, "--out-ros")) { + out_ros = true; + printf("OutROS: %d \n", out_ros); + } + //--fire-behavior + if (cmdOptionExists(argv, argv + argc, "--out-crown")) { + out_crown = true; + printf("OutCrown: %d \n", out_crown); + } + + if (cmdOptionExists(argv, argv + argc, "--out-cfb")) { + out_crown_consumption = true; + printf("OutCrownConsumption: %d \n", out_crown_consumption); + } + + if (cmdOptionExists(argv, argv + argc, "--out-sfb")) { + out_surf_consumption = true; + printf("OutSurfaceConsumption: %d \n", out_surf_consumption); + } + + + //--trajectories + //if (cmdOptionExists(argv, argv + argc, "--trajectories")) { + // out_trajectories = true; + // printf("Trajectories: %d \n", out_trajectories); + //} + + //--no-output + //if (cmdOptionExists(argv, argv + argc, "--no-output")) { + // no_output = true; + // printf("noOutput: %d \n", no_output); + //} + + //--verbose + if (cmdOptionExists(argv, argv + argc, "--verbose")) { + verbose_input = true; + printf("verbose: %d \n", verbose_input); + } + + // --ignitionsLog + if (cmdOptionExists(argv, argv + argc, "--ignitionsLog")) { + iplog_input = true; + printf("Ignition Points Log: %d \n", iplog_input); + } + + //--ignitions + if (cmdOptionExists(argv, argv + argc, "--ignitions")) { + input_ignitions = true; + printf("Ignitions: %d \n", input_ignitions); + } + + //--grids + if (cmdOptionExists(argv, argv + argc, "--grids")) { + out_grids = true; + printf("OutputGrids: %d \n", out_grids); + } + + //--final-grid + if (cmdOptionExists(argv, argv + argc, "--final-grid")) { + out_finalgrid = true; + printf("FinalGrid: %d \n", out_finalgrid); + } + + //--Prom_tuned + //if (cmdOptionExists(argv, argv + argc, "--PromTuned")) { + // prom_tuned = true; + // printf("PromTuned: %d \n", prom_tuned); + //} + + //--statistics + //if (cmdOptionExists(argv, argv + argc, "--statistics")) { + // out_stats = true; + // printf("Statistics: %d \n", out_stats); + //} + + //--bbo + if (cmdOptionExists(argv, argv + argc, "--bbo")) { + bbo_tuning = true; + printf("BBOTuning: %d \n", out_stats); + } + + //--cros + if (cmdOptionExists(argv, argv + argc, "--cros")) { + allow_cros = true; + printf("CrownROS: %d \n", allow_cros); + } + + + // Floats and ints + // defaults + int dsim_years = 1; + int dnsims = 1; + int dweather_period_len = 60; + int dmax_fire_periods = 1000; + int dseed = 123; + int diradius = 0; + int dnthreads = 1; + int dfmc=100; + int dscen=3; + float dROS_Threshold= 0.1; + float dHFI_Threshold= 0.1; + float dCROS_Threshold= 0.5; + //float dCROSAct_Threshold= 1.0; + float dROSCV= 0.; + float dHFactor = 1.0; + float dFFactor = 1.0; + float dBFactor = 1.0; + float dEFactor = 1.0; + float dCBDFactor = 0.0; //spain + //float dCBHFactor = 1.0; + float dCCFFactor = 0.0; //spain + float dROS10Factor = 3.34; //spain + float dinput_PeriodLen= 1.; + + // aux + std::string::size_type sz; + + //--sim-years (float) + char * sim_years = getCmdOption(argv, argv + argc, "--sim-years"); + if (sim_years){ + printf("TotalYears: %s \n", sim_years); + args_ptr->TotalYears = std::stoi (sim_years ,&sz); + } + else args_ptr->TotalYears = dsim_years; + + //--nsims + char * input_nsims = getCmdOption(argv, argv + argc, "--nsims"); + if (input_nsims){ + printf("TotalSims: %s \n", input_nsims); + args_ptr->TotalSims = std::stoi (input_nsims ,&sz); + } + else args_ptr->TotalSims = dnsims; + + + //--nsims + char * simulator_option = getCmdOption(argv, argv + argc, "--sim"); + if (simulator_option){ + std::string s=simulator_option; + if (s!="S" && s!="K" && s!="C"){ + printf("%s Simulator Option not recognized or not developed, using S&B as default!!! \n", simulator_option); + args_ptr->Simulator=simulator_option; + } + else{ + printf("Simulator: %s \n", simulator_option); + args_ptr->Simulator = simulator_option; + } + } + else { + printf("No Simulator Option Selected, using S&B as default!!! \n"); + args_ptr->Simulator = "S";} + + + //--Weather-Period-Length + char * weather_period_len = getCmdOption(argv, argv + argc, "--Weather-Period-Length"); + if (weather_period_len){ + printf("WeatherPeriodLength: %s \n", weather_period_len); + args_ptr->MinutesPerWP = std::stoi (weather_period_len ,&sz); + } + else args_ptr->MinutesPerWP = dweather_period_len; + + //--nweathers + char * nweathers = getCmdOption(argv, argv + argc, "--nweathers"); + if (nweathers){ + args_ptr->NWeatherFiles = std::stoi (nweathers ,&sz); + } + else{ + //std::cout << "No NWeatherFiles specified " << input_weather << std::endl; + if (std::string(input_weather) == "random") { + //std::cout << "Counting" << std::endl; + std::string input_string = input_folder; + args_ptr->NWeatherFiles = countWeathers(input_string + "/Weathers"); + } + else { + ///std::cout << "No NWeatherFiles specified 1 default" << std::endl; + args_ptr->NWeatherFiles = 1; + } + } + + //--Fire-Period-Length + char * input_PeriodLen = getCmdOption(argv, argv + argc, "--Fire-Period-Length"); + if (input_PeriodLen){ + printf("FirePeriodLength: %s \n", input_PeriodLen); + if (std::stof (input_PeriodLen ,&sz) <= args_ptr->MinutesPerWP){ + args_ptr->FirePeriodLen = std::stof (input_PeriodLen ,&sz); + } + else args_ptr->FirePeriodLen = args_ptr->MinutesPerWP; + } + else args_ptr->FirePeriodLen = dinput_PeriodLen; + + //--IgnitionRad + char * input_igrad = getCmdOption(argv, argv + argc, "--IgnitionRad"); + if (input_igrad){ + printf("IgnitionRadius: %s \n", input_igrad); + args_ptr->IgnitionRadius = std::stoi (input_igrad ,&sz); + } + else args_ptr->IgnitionRadius = diradius; + + + //--fmc + char * input_fmc = getCmdOption(argv, argv + argc, "--fmc"); + if (input_fmc){ + printf("FoliarMoistureContent: %s \n", input_fmc); + args_ptr->FMC = std::stoi (input_fmc ,&sz); + } + else args_ptr->FMC = dfmc; + + //--scenario + char * input_scenario = getCmdOption(argv, argv + argc, "--scenario"); + if (input_scenario){ + printf("LiveAndDeadFuelMoistureContentScenario: %s \n", input_scenario); + args_ptr->scenario = std::stoi (input_scenario ,&sz); + } + else args_ptr->scenario = dscen; + + + //--ROS-Threshold + char * ROS_Threshold = getCmdOption(argv, argv + argc, "--ROS-Threshold"); + if (ROS_Threshold){ + printf("ROSThreshold: %s \n", ROS_Threshold); + args_ptr->ROSThreshold = std::stof (ROS_Threshold ,&sz); + } + else args_ptr->ROSThreshold = dROS_Threshold; + + //--CROS-Threshold + char * CROS_Threshold = getCmdOption(argv, argv + argc, "--CROS-Threshold"); + if (CROS_Threshold){ + printf("CROSThreshold: %s \n", CROS_Threshold); + args_ptr->CROSThreshold = std::stof (CROS_Threshold ,&sz); + } + else args_ptr->CROSThreshold = dCROS_Threshold; + + //--HFI-Threshold + char * HFI_Threshold = getCmdOption(argv, argv + argc, "--HFI-Threshold"); + if (HFI_Threshold){ + printf("HFIThreshold: %s \n", HFI_Threshold); + args_ptr->HFIThreshold = std::stof (HFI_Threshold ,&sz); + } + else args_ptr->HFIThreshold = dHFI_Threshold; + + //--CROSAct-Threshold + char * CROSAct_Threshold = getCmdOption(argv, argv + argc, "--CROSAct-Threshold"); + if (CROSAct_Threshold){ + printf("CROSActThreshold: %s \n", CROSAct_Threshold); + args_ptr->CROSActThreshold = std::stof (CROSAct_Threshold ,&sz); + } + else args_ptr->CROSThreshold = dCROS_Threshold; + + + //--HFactor + char * H_Factor = getCmdOption(argv, argv + argc, "--HFactor"); + if (H_Factor){ + printf("HFactor: %s \n", H_Factor); + args_ptr->HFactor = std::stof (H_Factor ,&sz); + } + else args_ptr->HFactor = dHFactor; + + //---FFactor + char * F_Factor = getCmdOption(argv, argv + argc, "--FFactor"); + if (F_Factor){ + printf("FFactor: %s \n", F_Factor); + args_ptr->FFactor = std::stof (F_Factor ,&sz); + } + else args_ptr->FFactor = dFFactor; + + ///--BFactor + char * B_Factor = getCmdOption(argv, argv + argc, "--BFactor"); + if (B_Factor){ + printf("BFactor: %s \n", B_Factor); + args_ptr->BFactor = std::stof (B_Factor ,&sz); + } + else args_ptr->BFactor = dBFactor; + + ///--EFactor + char * E_Factor = getCmdOption(argv, argv + argc, "--EFactor"); + if (E_Factor){ + printf("EFactor: %s \n", E_Factor); + args_ptr->EFactor = std::stof (E_Factor ,&sz); + } + else args_ptr->EFactor = dEFactor; + + ///--CBDFactor + char * CBD_Factor = getCmdOption(argv, argv + argc, "--CBDFactor"); + if (CBD_Factor){ + printf("CBDFactor: %s \n", CBD_Factor); + args_ptr->CBDFactor = std::stof (CBD_Factor ,&sz); + } + else args_ptr->CBDFactor = dCBDFactor; + + ///--CCFFactor + char * CCF_Factor = getCmdOption(argv, argv + argc, "--CCFFactor"); + if (CCF_Factor){ + printf("CCFFactor: %s \n", CCF_Factor); + args_ptr->CCFFactor = std::stof (CCF_Factor ,&sz); + } + else args_ptr->CCFFactor = dCCFFactor; + + ///--ROS10Factor + char * ROS10_Factor = getCmdOption(argv, argv + argc, "--ROS10Factor"); + if (ROS10_Factor){ + printf("ROS10Factor: %s \n", ROS10_Factor); + args_ptr->ROS10Factor = std::stof (ROS10_Factor, &sz); + } + else args_ptr->ROS10Factor = dROS10Factor; + + //--ROS-CV + char * ROS_CV = getCmdOption(argv, argv + argc, "--ROS-CV"); + if (ROS_CV){ + printf("ROS-CV: %s \n", ROS_CV); + args_ptr->ROSCV = std::stof (ROS_CV ,&sz); + } + else args_ptr->ROSCV = dROSCV; + + //--max-fire-periods + char * max_fire_periods = getCmdOption(argv, argv + argc, "--max-fire-periods"); + if (max_fire_periods){ + printf("MaxFirePeriods: %s \n", max_fire_periods); + args_ptr->MaxFirePeriods = std::stoi (max_fire_periods ,&sz); + } + else args_ptr->MaxFirePeriods = dmax_fire_periods; + + //--seed (int) + char * seed = getCmdOption(argv, argv + argc, "--seed"); + if (seed){ + printf("seed: %s \n", seed); + args_ptr->seed = std::stoi (seed ,&sz); + } + else args_ptr->seed = dseed; + + //--nthreads (int) + char* nthreads = getCmdOption(argv, argv + argc, "--nthreads"); + if (nthreads) { + printf("nthreads: %s \n", nthreads); + args_ptr->nthreads = std::stoi(nthreads, &sz); + } + else args_ptr->nthreads = dnthreads; + + // Populate structure + // Strings + if (input_folder == &empty){ + args_ptr->InFolder = ""; + } + else args_ptr->InFolder = input_folder; + + if (!args_ptr->InFolder.empty() && *args_ptr->InFolder.rbegin()!= separator()){ + args_ptr->InFolder+=separator(); + } + + if (output_folder == &empty && input_folder != &empty){ + args_ptr->OutFolder = args_ptr->InFolder + "simOuts"; + } else if(output_folder == &empty && input_folder == &empty){ + args_ptr->OutFolder = "simOuts"; + } else if(output_folder != &empty && input_folder == &empty){ + args_ptr->OutFolder = output_folder; + } else if(output_folder != &empty && input_folder != &empty){ + args_ptr->OutFolder = output_folder; + } + + if (!args_ptr->OutFolder.empty() && *args_ptr->OutFolder.rbegin()!= separator()){ + args_ptr->OutFolder+=separator(); + } + + if (input_weather == &empty){ + args_ptr->WeatherOpt = "rows"; + } + else{ + args_ptr->WeatherOpt = input_weather; + } + + if (input_hplan == &empty){ + args_ptr->HarvestPlan = ""; + } + else args_ptr->HarvestPlan = input_hplan; + + // booleans + args_ptr->OutMessages = out_messages; + args_ptr->OutFl = out_fl; + args_ptr->OutIntensity = out_intensity; + args_ptr->OutRos = out_ros; + args_ptr->OutCrown = out_crown; + args_ptr->OutCrownConsumption = out_crown_consumption; + args_ptr->OutSurfConsumption = out_surf_consumption; + args_ptr->Trajectories = out_trajectories; + args_ptr->NoOutput = no_output; + args_ptr->verbose = verbose_input; + args_ptr->IgnitionsLog = iplog_input; + args_ptr->Ignitions = input_ignitions; + args_ptr->OutputGrids = out_grids; + args_ptr->FinalGrid = out_finalgrid; + args_ptr->PromTuned = prom_tuned; + args_ptr->Stats = out_stats; + args_ptr->BBOTuning = bbo_tuning; + args_ptr->AllowCROS = allow_cros; + +} + + +void printArgs(arguments args){ + + /* + std::cout << "Simulator: "<d_type == DT_REG) { + std::string filename = ent->d_name; + if (filename.substr(0, 7) == "Weather" && filename.substr(filename.size() - 4) == ".csv") { + file_count++; + } + } + } + closedir(dir); + } + else { + std::cout << "Could not open directory" << std::endl; + return -1; + } + + return file_count; +} diff --git a/Cell2Fire/ReadArgs.h b/Cell2Fire/ReadArgs.h index ca7e5b12..f220bd44 100644 --- a/Cell2Fire/ReadArgs.h +++ b/Cell2Fire/ReadArgs.h @@ -9,28 +9,68 @@ #include #include #include -/* -* Args structure -*/ -typedef struct{ - std::string InFolder, OutFolder, WeatherOpt, HarvestPlan, Simulator; - bool OutMessages, OutFl,OutIntensity,OutRos,OutCrown,OutCrownConsumption,OutSurfConsumption, Trajectories, NoOutput, verbose, IgnitionsLog, Ignitions, OutputGrids, FinalGrid, PromTuned, Stats, BBOTuning, AllowCROS; - float ROSCV, ROSThreshold, CROSThreshold, HFIThreshold, HFactor, FFactor, BFactor, EFactor, FirePeriodLen; - float CBDFactor, CCFFactor, ROS10Factor, CROSActThreshold; - int MinutesPerWP, MaxFirePeriods, TotalYears, TotalSims, NWeatherFiles, IgnitionRadius, seed, nthreads,FMC,scenario; - std::unordered_set HCells, BCells; +#include + +typedef struct { + bool AllowCROS = false; + bool BBOTuning = false; + bool FinalGrid = false; + bool Ignitions = false; + bool IgnitionsLog = false; + bool OutCrown = false; + bool OutCrownConsumption = false; + bool OutFl = false; + bool OutIntensity = false; + bool OutMessages = false; + bool OutRos = false; + bool OutSurfConsumption = false; + bool OutputGrids = false; + bool verbose = false; + + float BFactor = 1.0f; + float CBDFactor = 1.0f; //S&B + float CCFFactor = 0.0f; //S&B + float CROSThreshold = 0.5f; + float EFactor = 1.0f; + float FFactor = 1.0f; + float FirePeriodLen = 0.0f; + float HFIThreshold = 0.1f; + float HFactor = 1.0f; + float ROS10Factor = 3.34f; //S&B + float ROSCV = 0.0f; + float ROSThreshold = 0.1f; + + int FMC = 100; + int IgnitionRadius = 0; + int MaxFirePeriods = 1000; + int MinutesPerWP = 60; + int NWeatherFiles = 0; + int TotalSims = 3; + int TotalYears = 1; + int nthreads = 1; + int scenario = 3; + int seed = 123; + + std::string HarvestPlan = ""; + std::string InFolder = "."; + std::string OutFolder = "results"; + std::string Simulator = "S"; + std::string WeatherOpt = "rows"; + + std::unordered_set BCells; + std::unordered_set HCells; } arguments; +void printHelp(); +void printArguments(const arguments& args); +void postProcessArguments(arguments& args); +bool parseArguments(int argc, char* argv[], arguments& args); char* getCmdOption(char ** begin, char ** end, const std::string & option); bool cmdOptionExists(char** begin, char** end, const std::string& option); -void parseArgs(int argc, char * argv[], arguments * args_ptr); - -void printArgs(arguments args); - int countWeathers(std::string directory_path); -#endif +#endif // READARGS_H diff --git a/Cell2Fire/ReadArgs.hBAK b/Cell2Fire/ReadArgs.hBAK new file mode 100644 index 00000000..ca7e5b12 --- /dev/null +++ b/Cell2Fire/ReadArgs.hBAK @@ -0,0 +1,36 @@ +#ifndef READARGS +#define READARGS + +#include +#include +#include +#include +#include +#include +#include +#include +/* +* Args structure +*/ +typedef struct{ + std::string InFolder, OutFolder, WeatherOpt, HarvestPlan, Simulator; + bool OutMessages, OutFl,OutIntensity,OutRos,OutCrown,OutCrownConsumption,OutSurfConsumption, Trajectories, NoOutput, verbose, IgnitionsLog, Ignitions, OutputGrids, FinalGrid, PromTuned, Stats, BBOTuning, AllowCROS; + float ROSCV, ROSThreshold, CROSThreshold, HFIThreshold, HFactor, FFactor, BFactor, EFactor, FirePeriodLen; + float CBDFactor, CCFFactor, ROS10Factor, CROSActThreshold; + int MinutesPerWP, MaxFirePeriods, TotalYears, TotalSims, NWeatherFiles, IgnitionRadius, seed, nthreads,FMC,scenario; + std::unordered_set HCells, BCells; +} arguments; + + +char* getCmdOption(char ** begin, char ** end, const std::string & option); + +bool cmdOptionExists(char** begin, char** end, const std::string& option); + +void parseArgs(int argc, char * argv[], arguments * args_ptr); + +void printArgs(arguments args); + +int countWeathers(std::string directory_path); + + +#endif diff --git a/test/target_results.zip b/test/target_results.zip index c732b3ad..03e1c5d1 100644 Binary files a/test/target_results.zip and b/test/target_results.zip differ diff --git a/test/test.ps1 b/test/test.ps1 index 56c07a04..8fb438fa 100644 --- a/test/test.ps1 +++ b/test/test.ps1 @@ -16,17 +16,17 @@ foreach ($format in "asc", "tif") { Remove-Item -Recurse -Force -Path "$outputDir/*" if ($model -eq "fbp") { - $additionalArgs = "--cros" + $additionalArgs = "--AllowCROS" $simCode = "C" } elseif ($model -eq "sb") { - $additionalArgs = "--scenario 1" + $additionalArgs = "--AllowCROS --scenario 1" $simCode = "S" } elseif ($model -eq "kitral") { $additionalArgs = "" $simCode = "K" } - $command = "Cell2Fire.exe --input-instance-folder model/$model-$format --output-folder $outputDir --nsims 113 --output-messages --grids --out-ros --out-intensity --sim $simCode --seed 123 $additionalArgs" + $command = "Cell2Fire.exe --InFolder model/$model-$format --OutFolder $outputDir --TotalSims 113 --OutMessages --OutputGrids --OutRos --OutIntensity --Simulator $simCode --seed 123 $additionalArgs" Start-Process -FilePath "pwsh" -ArgumentList "-Command $command" -RedirectStandardOutput "$outputDir/log.txt" -NoNewWindow -Wait $firstLine = (Get-Content "$outputDir/log.txt" -TotalCount 1) -replace '^version: .*', 'version: v0.0.1' diff --git a/test/test.sh b/test/test.sh index a8ccad57..91f4bd24 100755 --- a/test/test.sh +++ b/test/test.sh @@ -24,16 +24,16 @@ for format in asc tif; do mkdir -p $output_folder rm -rf $output_folder/* if [ "$model" == "fbp" ]; then - additional_args="--cros" + additional_args="--AllowCROS" sim_code="C" elif [ "$model" == "sb" ]; then - additional_args="--scenario 1" + additional_args="--AllowCROS --scenario 1" sim_code="S" elif [ "$model" == "kitral" ]; then additional_args="" sim_code="K" fi - Cell2Fire$1 --input-instance-folder model/$model-$format --output-folder $output_folder --nsims 113 --output-messages --grids --out-ros --out-intensity --sim ${sim_code} --seed 123 --ignitionsLog $additional_args > test_results/$model-$format/log.txt + Cell2Fire$1 --InFolder model/$model-$format --OutFolder $output_folder --TotalSims 113 --OutMessages --OutputGrids --OutRos --OutIntensity --Simulator ${sim_code} --seed 42 --IgnitionsLog $additional_args > test_results/$model-$format/log.txt sed -i "1 s/version: .*/version: v0.0.1/" test_results/$model-$format/log.txt done done