#include #include #include "iniparser.h" #include "config.h" using namespace std; using namespace glm; void Config::load(char* caseName, const char* iniFileName) { // Load parser file if (iniFileName == NULL) { ini = iniparser_load("glm.conf"); } else { ini = iniparser_load (iniFileName); } if (ini == NULL) { exit (1); } iniparser_dump(ini, stderr); if (caseName == NULL) { // Get casename from config file caseName_ = getString( "control:case name", NULL); } else { caseName_ = new char[strlen(caseName) + 1]; strcpy(caseName_, caseName); } cout << "case name: " << (caseName_ ? caseName_ : "UNDEF") << endl; // Get output dir from config file char* tmp = getString( "output directory:output dir", NULL); if (strlen(tmp) + strlen(caseName_) + 2 > sizeof(outputDir_)) { cerr << "output dir too long for buffer\n"; exit (1); } strcat (strcat (strcpy (outputDir_, tmp), "/"), caseName_); cout << "output directory: " << (outputDir_ ? outputDir_ : "UNDEF") << endl; // parse control options from config file TOTAL_HARVEST_SWITCH = getInt("control:total_harvest_switch"); SECONDARY_HARVEST_SWITCH = getInt("control:secondary_harvest_switch"); VIRGIN_HARVEST_SWITCH = getInt("control:virgin_harvest_switch"); FORCE_HARVEST_SWITCH = getInt("control:force_harvest_switch"); logging_option = getInt("control:logging_option"); start_year = getInt("control:start year"); stop_year = getInt("control:stop year"); smart_flow_option = getInt("control:smart_flow_option"); zdis_option = getInt("control:zdis_option"); cft_option = getInt("control:cft_option"); crop_rotations = getInt("control:crop_rotations"); adjust_smart_flow_option = getInt("control:adjust_smart_flow_option"); run_management = getInt("control:run_management"); //global params read in from config file MAXZ = getInt("control:maxz"); MAXL = getInt("control:maxl"); BEST_CASE = getInt("control:best_case"); BEST_CASE_MIN_FLOWS_T5 = getInt("control:best_case_min_flows_t5"); futureRun = iniparser_getboolean(ini, "control:futureRun", false); extensionRun = iniparser_getboolean(ini, "control:extensionRun", false); restartDataSet = getString("control:restart_data_set"); restartManagement = getString("control:restart_management"); restartTransitions = getString("control:restart_transitions"); restartDiagnostics = getString("control:restart_diagnostics"); // total biomass to bole biomass ratio, value of 2.0 assumes the // WH numbers are bole biomass only and we need to cut twice as much biomass TB2BB = iniparser_getdouble(ini,"control:tb2bb",1.0); PROB_FNAME = getString("control:phbio_filename"); runtype = getString("control:runtype"); shft_cult = getInt("control:shft_cult"); SMART_FLOW_BUG_PRINT = getInt("debug options:smart_flow_bug_print"); STATE_BUG_PRINT = getInt("debug options:state_bug_print"); STATE_PRINT = getInt("debug options:state_print"); FLOW_BUG_PRINT = getInt("debug options:flow_bug_print"); icew_input_path = getString("hyde_datasets:hyde_icew_path"); watr_input_path = getString("hyde_datasets:hyde_watr_path"); hyde_crop_path = getString("hyde_datasets:hyde_crop_path"); hyde_othr_path = getString("hyde_datasets:hyde_othr_path"); hyde_past_path = getString("hyde_datasets:hyde_past_path"); hyde_urbn_path = getString("hyde_datasets:hyde_urbn_path"); hyde_rangeland_path = getString("hyde_datasets:hyde_rangeland_path"); hyde_managed_past_path = getString("hyde_datasets:hyde_managed_past_path"); hyde_rice_path = getString("hyde_datasets:rice_file"); irrigation_file = getString("hyde_datasets:irrigation_file"); future_crop_path = getString("iam_datasets:future_crop_path"); future_othr_path = getString("iam_datasets:future_othr_path"); future_past_path = getString("iam_datasets:future_past_path"); future_urbn_path = getString("iam_datasets:future_urbn_path"); extension_crop_path = getString("iam_datasets:extension_crop_path"); extension_othr_path = getString("iam_datasets:extension_othr_path"); extension_past_path = getString("iam_datasets:extension_past_path"); extension_urbn_path = getString("iam_datasets:extension_urbn_path"); iam_croptypes_file = getString("iam_datasets:iam_croptypes_file"); iam_flooded_file = getString("iam_datasets:iam_flooded_file"); iam_crpbf_file = getString("iam_datasets:iam_crpbf_file"); iam_c3pbf_file = getString("iam_datasets:iam_c3pbf_file"); iam_c4pbf_file = getString("iam_datasets:iam_c4pbf_file"); national_flooded_file = getString("iam_datasets:national_flooded_file"); iam_fert_vals_file = getString("iam_datasets:iam_fert_vals_file"); iam_irrig_vals_file = getString("iam_datasets:iam_irrig_vals_file"); c4a_flag = getInt("iam_datasets:c4a_flag"); c4p_flag = getInt("iam_datasets:c4p_flag"); c3p_flag = getInt("iam_datasets:c3p_flag"); c3n_flag = getInt("iam_datasets:c3n_flag"); irrig_flag = getInt("iam_datasets:irrig_flag"); fert_flag = getInt("iam_datasets:fert_flag"); woodharvest_file = getString("woodharvest_datasets:woodharvest_file"); fuelwood_file = getString("woodharvest_datasets:fuelwood_file"); woodharvest_nodata_file = getString("woodharvest_datasets:woodharvest_nodata_file"); cellinfo_file = getString("other_datasets:cellinfo_file"); ccodes_file = getString("other_datasets:ccodes_file"); ccodes_map = getString("other_datasets:ccodes_map"); cnames_file = getString("other_datasets:cnames_file"); contcodes_file = getString("other_datasets:contcodes_file"); regcodes_file = getString("other_datasets:regcodes_file"); shiftcult_map = getString("other_datasets:shiftcult_map"); shiftcult_nc = getString("other_datasets:shiftcult_nc"); future_pasture_fracs_file = getString("other_datasets:future_pasture_fracs_file"); protected_area_file = getString("other_datasets:protected_area"); miami_biomass_file_vba = getString("other_datasets:miami_biomass_file_vba"); miami_biomass_file_vnppa = getString("other_datasets:miami_biomass_file_vnppa"); rs_forest_loss_file = getString("other_datasets:rs_forest_loss"); future_woodharvest_file = getString("woodharvest_datasets:future_woodharvest_file"); future_fuelwood_file = getString("woodharvest_datasets:future_fuelwood_file"); fertilizer_country_file = getString("management datasets:fertilizer_country_file"); fertilizer_global_file = getString("management datasets:fertilizer_global_file"); tillage_national_file = getString("management datasets:tillage_national_file"); fertilizer_national_file = getString("management datasets:fertilizer_national_file"); croprotations_national_file = getString("management datasets:croprotations_national_file"); cropbiofuels_national_file = getString("management datasets:cropbiofuels_national_file"); flooded_file = getString("management datasets:flooded_file"); fertilizer_national_file_future = getString("management datasets:fertilizer_national_file_future"); irrigation_national_file_future = getString("management datasets:irrigation_national_file_future"); c3_annual_file = getString("crop type datasets:c3_annual_file"); c4_annual_file = getString("crop type datasets:c4_annual_file"); c3_perennial_file = getString("crop type datasets:c3_perennial_file"); c4_perennial_file = getString("crop type datasets:c4_perennial_file"); n_fixing_file = getString("crop type datasets:n_fixing_file"); cft_frac_file = getString("crop type datasets:cft_frac_file"); if (strcmp("initial", runtype) == 0) { isInitialRun = true; } } int Config::getInt (const char* name, int defaultValue) { return iniparser_getint(ini, name, defaultValue); } char* Config::getString (const char* name, char* defaultValue) { return iniparser_getstring(ini, name, defaultValue); } void Config::updateOutstat(int year) { if (year >= start_year && year <= stop_year) { if (isInitialRun && year == start_year) { strcpy(outstat, "w"); } else { strcpy(outstat, "a"); } } }