From 8e6d1449e6b795df4775f782d5ce930e16b2afef Mon Sep 17 00:00:00 2001 From: Daniel Schlaepfer Date: Wed, 5 Oct 2022 16:18:37 -0400 Subject: [PATCH 01/15] Set SOILWAT2 to feature_read_weather - SOILWAT2 commit "Isolate "allWeather" functionality from global variables" - updated "weathsetup.in": removed obsolete "first year of historical weather" --- .gitmodules | 2 +- sw_src | 2 +- .../Stepwat_Inputs/Input/sxw/Input/weathsetup.in | 5 +---- 3 files changed, 3 insertions(+), 6 deletions(-) diff --git a/.gitmodules b/.gitmodules index ceda410d..fc721dd8 100644 --- a/.gitmodules +++ b/.gitmodules @@ -1,5 +1,5 @@ [submodule "sw_src"] path = sw_src url = https://github.com/DrylandEcology/SOILWAT2.git - branch = master + branch = feature_read_weather ignore = dirty diff --git a/sw_src b/sw_src index 436bfeb6..9ac8a0c7 160000 --- a/sw_src +++ b/sw_src @@ -1 +1 @@ -Subproject commit 436bfeb6f5d03b7dd0e616015a6227988aa7d329 +Subproject commit 9ac8a0c7d2ef2f4e8ff93951ddcc8f30c36fbb02 diff --git a/testing.sagebrush.master/Stepwat_Inputs/Input/sxw/Input/weathsetup.in b/testing.sagebrush.master/Stepwat_Inputs/Input/sxw/Input/weathsetup.in index 7c240a28..e5273ccf 100644 --- a/testing.sagebrush.master/Stepwat_Inputs/Input/sxw/Input/weathsetup.in +++ b/testing.sagebrush.master/Stepwat_Inputs/Input/sxw/Input/weathsetup.in @@ -10,14 +10,11 @@ 2 # 0 = use historical data only # 1 = use weather generator for (partially) missing weather inputs # 2 = use weather generator for all weather (don't check weather inputs) + # 3 = impute missing temperature with LOCF and missing precipitation as 0 7 # Seed random number generator for weather generator (only used if SOILWAT2) # (seed with 0 to use current time) -#--- Historical daily weather inputs --1 # first year to begin historical weather - # if -1, then use first year of simulation (see `years.in`) - #--- Monthly scaling parameters: # Month 1 = January, Month 2 = February, etc. From 755b3e96175b9610296cfeaf609d42c14f39b997 Mon Sep 17 00:00:00 2001 From: Daniel Schlaepfer Date: Wed, 5 Oct 2022 16:46:29 -0400 Subject: [PATCH 02/15] Incorporate SOILWAT2's new weather workflow - SOILWAT2 branch "feature_read_weather" isolated the handling of daily weather data and moved it from within the simulation loop to the overall setup process - STEPWAT2 needs now to handle daily weather data itself; there are two basic options: i) follow SOILWAT2's new approach and generate daily weather for all years of a simulation run (for each grid cell and iteration); this would require that each grid cell stores and handles a local copy of `SW_Weather` ii) stick with the previous approach which generated daily weather for each year - this commit follows option (ii), i.e., generate daily weather for each year ** new `_sxw_generate_weather()` handles the generation of daily weather for the current year ** `Env_Generate()` now calls `_sxw_generate_weather()` before running SOILWAT2 for the current year ** non-gridded mode needed to set RNGs for each year (so that `markov_rng` gets updated with fresh values for each year) -> this commit satisfies expectations, i.e., (script based on https://github.com/DrylandEcology/STEPWAT2/pull/528#issuecomment-1244085749) - if seed != 0 (output is reproduced among runs) ** weather is exactly identical among runs and cells ** weather is different among years, iterations and seeds - if seed == 0 (output cannot be reproduced among runs) ** weather is different among cells, years, iterations and runs --- ST_main.c | 4 ++-- sxw.c | 3 +++ sxw_module.h | 1 + sxw_soilwat.c | 43 +++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 49 insertions(+), 2 deletions(-) diff --git a/ST_main.c b/ST_main.c index 54542743..2205a708 100644 --- a/ST_main.c +++ b/ST_main.c @@ -214,8 +214,6 @@ int main(int argc, char **argv) { for (iter = 1; iter <= SuperGlobals.runModelIterations; iter++) { Plot_Initialize(); - set_all_rngs(SuperGlobals.randseed, iter, 0, 0); - Globals->currIter = iter; if (storeAllIterations) { @@ -234,6 +232,8 @@ int main(int argc, char **argv) { //printf("------------------------Repetition/year = %d / %d\n", iter, year); + set_all_rngs(SuperGlobals.randseed, iter, year, 0); + Globals->currYear = year; rgroup_Establish(); diff --git a/sxw.c b/sxw.c index 9062545f..49cb5e29 100644 --- a/sxw.c +++ b/sxw.c @@ -302,6 +302,9 @@ void SXW_Run_SOILWAT(void) { _sxw_sw_setup(sizes); + // Generate weather for current call (iteration, year, cell, ...) + _sxw_generate_weather(); + // Initialize `SXW` values for current year's run: SXW->aet = 0.; /* used to be in sw_setup() but it needs clearing each run */ diff --git a/sxw_module.h b/sxw_module.h index 3b857c2d..e560ce82 100644 --- a/sxw_module.h +++ b/sxw_module.h @@ -34,6 +34,7 @@ void _sxw_update_root_tables( RealF sizes[] ); /* These functions are found in sxw_soilwat.c */ void _sxw_sw_setup(RealF sizes[]); +void _sxw_generate_weather(void); void _sxw_sw_run(void); void _sxw_sw_clear_transp(void); diff --git a/sxw_soilwat.c b/sxw_soilwat.c index 132d16eb..6756d208 100644 --- a/sxw_soilwat.c +++ b/sxw_soilwat.c @@ -50,6 +50,7 @@ #include "sxw_module.h" #include "sxw_vars.h" #include "sw_src/SW_Control.h" +#include "sw_src/SW_Weather.h" // externs `SW_Weather` #include "sw_src/SW_Model.h" // externs `SW_Model` #include "sw_src/SW_Site.h" // externs `SW_Site` #include "sw_src/SW_SoilWater.h" @@ -85,6 +86,48 @@ void _sxw_sw_setup (RealF sizes[]) { } } +/** @brief Handle the weather generator to create new daily weather for current year + + This function takes the place of SOILWAT2's `SW_WTH_read()` and + `SW_WTH_finalize_all_weather()`. + + Note: `Env_Generate()` (via `_sxw_sw_run()`) sets SOILWAT2's "year" + (`SW_Model.year`) to `SW_Model.startyr + Globals->currYear - 1`. + SOILWAT2 expects current year's weather values at element + `SW_Model.year - SW_Weather.startYear` (see `SW_WTH_new_day()`). + + Note: As an alternative to the function here that is called by `Env_Generate()`, + STEPWAT2 could generate weather for all years at once if + each grid cell would store a local copy of `SW_Weather`. +*/ +void _sxw_generate_weather(void) { + SW_WEATHER *w = &SW_Weather; + + deallocateAllWeather(w); + w->n_years = 1; + w->startYear = SW_Model.startyr + Globals->currYear - 1; + allocateAllWeather(w); + + if (!w->use_weathergenerator_only) { + LogError( + logfp, + LOGERROR, + "STEPWAT2 expects 'use_weathergenerator_only'." + ); + } + + readAllWeather( + w->allHist, + w->startYear, + w->n_years, + swTRUE, // `use_weathergenerator_only` + w->name_prefix // not used because `use_weathergenerator_only` + ); + + finalizeAllWeather(w); // run the weather generator +} + + void _sxw_sw_run(void) { /*======================================================*/ SW_Model.year = SW_Model.startyr + Globals->currYear-1; From d641e3b325a448b5995abe64fa465b08b1d1ff50 Mon Sep 17 00:00:00 2001 From: Daniel Schlaepfer Date: Thu, 17 Nov 2022 17:07:55 -0500 Subject: [PATCH 03/15] Set SOILWAT2 to feature_veg_estimation - updated "veg.in": new input to select SOILWAT2-side method for estimation vegetation parameters from climate -> not relevant for STEPWAT2 and turned off --- .gitmodules | 2 +- sw_src | 2 +- .../Stepwat_Inputs/Input/sxw/Input/veg.in | 5 +++++ 3 files changed, 7 insertions(+), 2 deletions(-) diff --git a/.gitmodules b/.gitmodules index fc721dd8..e0854f13 100644 --- a/.gitmodules +++ b/.gitmodules @@ -1,5 +1,5 @@ [submodule "sw_src"] path = sw_src url = https://github.com/DrylandEcology/SOILWAT2.git - branch = feature_read_weather + branch = feature_veg_estimation ignore = dirty diff --git a/sw_src b/sw_src index 9ac8a0c7..3e01bb6d 160000 --- a/sw_src +++ b/sw_src @@ -1 +1 @@ -Subproject commit 9ac8a0c7d2ef2f4e8ff93951ddcc8f30c36fbb02 +Subproject commit 3e01bb6d0c646b93cfadfd6c0fd8410e5cfcf249 diff --git a/testing.sagebrush.master/Stepwat_Inputs/Input/sxw/Input/veg.in b/testing.sagebrush.master/Stepwat_Inputs/Input/sxw/Input/veg.in index 82783a4a..3caa97d6 100755 --- a/testing.sagebrush.master/Stepwat_Inputs/Input/sxw/Input/veg.in +++ b/testing.sagebrush.master/Stepwat_Inputs/Input/sxw/Input/veg.in @@ -1,6 +1,11 @@ # Plant production data file for SOILWAT2 # Location: +#---- Select method for vegetation parameters +0 # 0 - Read in the values from file + # 1 - Estimate fixed vegetation composition (fractional cover) from long-term climate conditions + + # ---- Composition of vegetation type components (0-1; must add up to 1) # Grasses Shrubs Trees Forbs BareGround 0.2 0.2 0.2 0.2 0.2 From 657153f5a7ef4c960864922766163838e41acea0 Mon Sep 17 00:00:00 2001 From: Daniel Schlaepfer Date: Tue, 6 Dec 2022 16:57:32 -0500 Subject: [PATCH 04/15] Prepare for upcoming SOILWAT2 release v7.0.0 - SOILWAT2 is preparing for major new release with several improvements and new features * milestone: https://github.com/DrylandEcology/SOILWAT2/milestone/13 * PR: https://github.com/DrylandEcology/SOILWAT2/pull/325 - the purpose of this STEPWAT2 branch is to track progress in SOILWAT2 towards that major release and add any necessary changes to the STEPWAT2/SOILWAT2 interface * one of the goals is to limit code changes required in STEPWAT2 and to reproduce previous STEPWAT2 behavior and output (new settings will be set such that they reproduce previous behavior), at least as much as possible (and document deviations) * new input: user specifies whether input soil density represents matric or bulk density (new input in `siteparam.in` with backwards compatible value of 0 = matric) --- .gitmodules | 2 +- sw_src | 2 +- .../Stepwat_Inputs/Input/sxw/Input/siteparam.in | 4 ++++ 3 files changed, 6 insertions(+), 2 deletions(-) diff --git a/.gitmodules b/.gitmodules index e0854f13..6a6c0490 100644 --- a/.gitmodules +++ b/.gitmodules @@ -1,5 +1,5 @@ [submodule "sw_src"] path = sw_src url = https://github.com/DrylandEcology/SOILWAT2.git - branch = feature_veg_estimation + branch = release/devel_v7.0.0 ignore = dirty diff --git a/sw_src b/sw_src index 3e01bb6d..9789a380 160000 --- a/sw_src +++ b/sw_src @@ -1 +1 @@ -Subproject commit 3e01bb6d0c646b93cfadfd6c0fd8410e5cfcf249 +Subproject commit 9789a380849864c535226ffe64a2dd5d07121fb5 diff --git a/testing.sagebrush.master/Stepwat_Inputs/Input/sxw/Input/siteparam.in b/testing.sagebrush.master/Stepwat_Inputs/Input/sxw/Input/siteparam.in index b1a4b1e1..2d1e1b9f 100644 --- a/testing.sagebrush.master/Stepwat_Inputs/Input/sxw/Input/siteparam.in +++ b/testing.sagebrush.master/Stepwat_Inputs/Input/sxw/Input/siteparam.in @@ -73,6 +73,10 @@ # Scenario RCP85 +# --- Soil characterization --- +# Are inputs of density representing bulk soil (type 1) or the matric component (type 0)? +0 + # ---- Transpiration regions ---- # ndx : 1=shallow, 2=medium, 3=deep, 4=very deep # layer: deepest layer number of the region. From eb67f2c16e3df8fd80f01de4796081f8075be911 Mon Sep 17 00:00:00 2001 From: Daniel Schlaepfer Date: Thu, 22 Dec 2022 07:21:51 -0500 Subject: [PATCH 05/15] Update SOILWAT2 with new SWRC functionality - SOILWAT2 has now multiple soil water release curves (SWRC) implemented - updated SOILWAT2 submodule on branch release/devel_v7.0.0 to commit a6c367aef07b746a43b459067ee0ef0139f9f60b "Merge pull request #322 from DrylandEcology/feature_swrc" -> new SOILWAT2 inputs include: swrc_name (to select a SWRC), ptf_name (to select a pedotransfer function if used), has_swrcp (logical to determine if SWRC parameters are used from new input file or calculated at run-time with selected PTF), and swrc_params (per soil layer parameters of the selected SWRC if used) -> default values (swrc_name = Campbell1974, ptf_name = Cosby1984AndOthers, has_swrcp = FALSE) re-created previous behavior (except for a small fix for when soil moisture values occur above field capacity and below saturation levels) --- sw_src | 2 +- .../Input/sxw/Input/siteparam.in | 24 ++++++++++++ .../Input/sxw/Input/swrc_params.in | 39 +++++++++++++++++++ .../Input/sxw/files_SOILWAT2.in | 1 + 4 files changed, 65 insertions(+), 1 deletion(-) create mode 100644 testing.sagebrush.master/Stepwat_Inputs/Input/sxw/Input/swrc_params.in diff --git a/sw_src b/sw_src index 9789a380..a6c367ae 160000 --- a/sw_src +++ b/sw_src @@ -1 +1 @@ -Subproject commit 9789a380849864c535226ffe64a2dd5d07121fb5 +Subproject commit a6c367aef07b746a43b459067ee0ef0139f9f60b diff --git a/testing.sagebrush.master/Stepwat_Inputs/Input/sxw/Input/siteparam.in b/testing.sagebrush.master/Stepwat_Inputs/Input/sxw/Input/siteparam.in index 2d1e1b9f..b70d2e20 100644 --- a/testing.sagebrush.master/Stepwat_Inputs/Input/sxw/Input/siteparam.in +++ b/testing.sagebrush.master/Stepwat_Inputs/Input/sxw/Input/siteparam.in @@ -77,6 +77,30 @@ RCP85 # Are inputs of density representing bulk soil (type 1) or the matric component (type 0)? 0 + + +#--- Soil water retention curve (SWRC) ------ +# +# Implemented options (`swrc_name`/`ptf_name`, see `swrc2str[]`/`ptf2str[]`): +# - ptf_name = : SWRC parameters must be provided via "swrc_params.in" +# - swrc_name = "Campbell1974" (Campbell 1974) +# * ptf_name = "Cosby1984AndOthers" (Cosby et al. 1984 but `swc_sat` by Saxton et al. 2006) +# * ptf_name = "Cosby1984" (Cosby et al. 1984) +# - swrc_name = "vanGenuchten1980" (van Genuchten 1980) +# - swrc_name = "FXW" (Fredlund and Xing 1994, Wang et al. 2018) +# +# Note: option "Campbell1974"/"Cosby1984AndOthers" was hard-coded < v7.0.0 +# Note: `rSOILWAT2` may implement additional PTFs + +Campbell1974 # Specify soil water retention curve +Cosby1984AndOthers # Specify pedotransfer function + # (if not implemented, then provide SWRC parameters via "swrc_params.in") + +0 # Has SWRC parameters (see `has_swrcp`)? + # 0: Estimate with specified pedotransfer function + # 1: Use values from "swrc_params.in" + + # ---- Transpiration regions ---- # ndx : 1=shallow, 2=medium, 3=deep, 4=very deep # layer: deepest layer number of the region. diff --git a/testing.sagebrush.master/Stepwat_Inputs/Input/sxw/Input/swrc_params.in b/testing.sagebrush.master/Stepwat_Inputs/Input/sxw/Input/swrc_params.in new file mode 100644 index 00000000..abd633a9 --- /dev/null +++ b/testing.sagebrush.master/Stepwat_Inputs/Input/sxw/Input/swrc_params.in @@ -0,0 +1,39 @@ +#------ Input for Soil Water Retention Curves (by soil layer) ------ + +# A table with up to `MAX_LAYERS` rows (soil layers) and 6 columns: +# - the soil layers must match `soils.in` +# - the interpretation of columns (SWRC parameters) depends on the +# selected SWRC (see `siteparam.in`) +# - unused columns are ignored (if selected SWRC uses fewer than 6 parameters) + +# swrc = "Campbell1974" (default values below, from "Cosby1984") +# * param1 = air-entry suction [cm] +# * param2 = saturated volumetric water content for the matric component [cm/cm] +# * param3 = b, slope of the linear log-log retention curve [-] +# * param4 = saturated hydraulic conductivity [cm/day] + +# swrc = "vanGenuchten1980" +# * param1 = residual volumetric water content for the matric component [cm/cm] +# * param2 = saturated volumetric water content for the matric component [cm/cm] +# * param3 = alpha, related to the inverse of air entry suction [cm-1] +# * param4 = n, measure of the pore-size distribution [-] +# * param5 = saturated hydraulic conductivity [cm/day] + +# swrc = "FXW" +# * param1 = saturated volumetric water content of the matric component [cm/cm] +# * param2 = alpha, shape parameter [cm-1] +# * param3 = n, shape parameter [-] +# * param4 = m, shape parameter [-] +# * param5 = saturated hydraulic conductivity [cm / day] +# * param6 = L, tortuosity/connectivity parameter [-] + + +# param1 param2 param3 param4 param5 param6 + 0.0000 0.00000 0.0000 0.000000 0.0000 0.0000 + 0.0000 0.00000 0.0000 0.000000 0.0000 0.0000 + 0.0000 0.00000 0.0000 0.000000 0.0000 0.0000 + 0.0000 0.00000 0.0000 0.000000 0.0000 0.0000 + 0.0000 0.00000 0.0000 0.000000 0.0000 0.0000 + 0.0000 0.00000 0.0000 0.000000 0.0000 0.0000 + 0.0000 0.00000 0.0000 0.000000 0.0000 0.0000 + 0.0000 0.00000 0.0000 0.000000 0.0000 0.0000 diff --git a/testing.sagebrush.master/Stepwat_Inputs/Input/sxw/files_SOILWAT2.in b/testing.sagebrush.master/Stepwat_Inputs/Input/sxw/files_SOILWAT2.in index 4e4533a4..f5da5170 100644 --- a/testing.sagebrush.master/Stepwat_Inputs/Input/sxw/files_SOILWAT2.in +++ b/testing.sagebrush.master/Stepwat_Inputs/Input/sxw/files_SOILWAT2.in @@ -8,6 +8,7 @@ Output/logfile.log # errors or important info (can also be stdout) #Site Input/siteparam.in # site parameters Input/soils.in # soil layer definitions +Input/swrc_params.in # Input for soil water retention curve (used if pdf_type = 0, i.e., pedotransfer functions are not used) #Weather & climate Input/weathsetup.in # weather parameters From 550545726922fe95821cbb1dbad7423df4474c4c Mon Sep 17 00:00:00 2001 From: Daniel Schlaepfer Date: Thu, 22 Dec 2022 16:04:09 -0500 Subject: [PATCH 06/15] Updates for new SOILWAT2 project structure - switch to SOILWAT2 branch feature_restructure - paths renamed in submodule SOILWAT2 * *.c -> src/ * *.h -> include * pcg/ -> external/pcg/ * googletest/ -> external/googletest/ - makefile gained ability to create required paths at obj/ -> remove obj/ and fixed nested folder structure -> remove nested `.gitignore` for each subfolder of obj/ -> add obj to global `.gitignore` --- .gitignore | 1 + .gitmodules | 2 +- ST_colonization.c | 4 +- ST_defines.h | 2 +- ST_grid.c | 24 ++++----- ST_grid.h | 18 +++---- ST_indivs.c | 4 +- ST_main.c | 22 ++++---- ST_mortality.c | 8 +-- ST_mortality.h | 12 ++--- ST_output.c | 6 +-- ST_params.c | 6 +-- ST_resgroups.c | 6 +-- ST_seedDispersal.c | 6 +-- ST_species.c | 6 +-- ST_spinup.c | 22 ++++---- ST_stats.c | 4 +- ST_structs.h | 2 +- makefile | 52 +++++++++++++------ obj/sqlite-amalgamation/.gitignore | 4 -- .../googletest/googletest/src/.gitignore | 4 -- obj/sw_src/pcg/.gitignore | 4 -- obj/test/.gitignore | 4 -- sw_src | 2 +- sxw.c | 32 ++++++------ sxw.h | 6 +-- sxw_environs.c | 10 ++-- sxw_main.c | 6 +-- sxw_module.h | 10 ++-- sxw_resource.c | 24 ++++----- sxw_soilwat.c | 24 ++++----- sxw_sql.c | 6 +-- test/test_ST_mortality.h | 4 +- 33 files changed, 175 insertions(+), 172 deletions(-) delete mode 100644 obj/sqlite-amalgamation/.gitignore delete mode 100644 obj/sw_src/googletest/googletest/src/.gitignore delete mode 100644 obj/sw_src/pcg/.gitignore delete mode 100644 obj/test/.gitignore diff --git a/.gitignore b/.gitignore index 74745e30..d70c98f1 100644 --- a/.gitignore +++ b/.gitignore @@ -16,6 +16,7 @@ *.exe *.o *.so +obj # Packages # ############ diff --git a/.gitmodules b/.gitmodules index 6a6c0490..da28c307 100644 --- a/.gitmodules +++ b/.gitmodules @@ -1,5 +1,5 @@ [submodule "sw_src"] path = sw_src url = https://github.com/DrylandEcology/SOILWAT2.git - branch = release/devel_v7.0.0 + branch = feature_restructure ignore = dirty diff --git a/ST_colonization.c b/ST_colonization.c index 2f4e5734..be64972c 100644 --- a/ST_colonization.c +++ b/ST_colonization.c @@ -9,8 +9,8 @@ */ #include "ST_colonization.h" -#include "sw_src/myMemory.h" -#include "sw_src/filefuncs.h" +#include "sw_src/include/myMemory.h" +#include "sw_src/include/filefuncs.h" #include "ST_functions.h" #include "ST_globals.h" diff --git a/ST_defines.h b/ST_defines.h index fab2f382..5fdab019 100644 --- a/ST_defines.h +++ b/ST_defines.h @@ -17,7 +17,7 @@ #ifndef STEPPE_DEF_H #define STEPPE_DEF_H -#include "sw_src/generic.h" +#include "sw_src/include/generic.h" /* see #include "ST_structs.h" below */ diff --git a/ST_grid.c b/ST_grid.c index 082a153b..36effaea 100644 --- a/ST_grid.c +++ b/ST_grid.c @@ -33,13 +33,13 @@ #include #include #include -#include "sw_src/generic.h" -#include "sw_src/filefuncs.h" -#include "sw_src/myMemory.h" -#include "sw_src/rands.h" -#include "sw_src/SW_SoilWater.h" // externs SW_Soilwat -#include "sw_src/SW_Weather.h" // externs SW_Weather -#include "sw_src/SW_Markov.h"// externs `markov_rng` +#include "sw_src/include/generic.h" +#include "sw_src/include/filefuncs.h" +#include "sw_src/include/myMemory.h" +#include "sw_src/include/rands.h" +#include "sw_src/include/SW_SoilWater.h" // externs SW_Soilwat +#include "sw_src/include/SW_Weather.h" // externs SW_Weather +#include "sw_src/include/SW_Markov.h"// externs `markov_rng` #include "ST_grid.h" #include "ST_steppe.h" #include "ST_globals.h" // externs `UseProgressBar` @@ -51,12 +51,12 @@ #include "ST_colonization.h" #include "ST_seedDispersal.h" // externs `UseSeedDispersal` #include "ST_mortality.h" // externs `mortality_rng`, `*_SomeKillage`, `UseCheatgrassWildfire` -#include "sw_src/SW_Output.h" -#include "sw_src/SW_Output_outtext.h" -#include "sw_src/SW_Output_outarray.h" +#include "sw_src/include/SW_Output.h" +#include "sw_src/include/SW_Output_outtext.h" +#include "sw_src/include/SW_Output_outarray.h" -#include "sw_src/SW_Flow.h" // for `SW_FLW_init_run()` -#include "sw_src/SW_Flow_lib.h" // for `SW_ST_init_run()` +#include "sw_src/include/SW_Flow.h" // for `SW_FLW_init_run()` +#include "sw_src/include/SW_Flow_lib.h" // for `SW_ST_init_run()` diff --git a/ST_grid.h b/ST_grid.h index 9b1d6f3e..abc41de3 100644 --- a/ST_grid.h +++ b/ST_grid.h @@ -17,23 +17,23 @@ /******** These modules are necessary to compile ST_grid.c ********/ #include "ST_stats.h" #include "ST_defines.h" -#include "sw_src/pcg/pcg_basic.h" +#include "sw_src/external/pcg/pcg_basic.h" #include "sxw_vars.h" -#include "sw_src/SW_Site.h" -#include "sw_src/SW_SoilWater.h" -#include "sw_src/SW_VegProd.h" -#include "sw_src/SW_Model.h" -#include "sw_src/SW_Weather.h" +#include "sw_src/include/SW_Site.h" +#include "sw_src/include/SW_SoilWater.h" +#include "sw_src/include/SW_VegProd.h" +#include "sw_src/include/SW_Model.h" +#include "sw_src/include/SW_Weather.h" #include "ST_seedDispersal.h" /*********************** Grid Structures ****************************/ -/** +/** * \brief Soil layer information for a single [cell](\ref CellType) - * + * * This struct requires dynamic memory allocation, so be carefull when * instanciating it. - * + * * \ingroup GRID */ typedef struct Soil_st diff --git a/ST_indivs.c b/ST_indivs.c index d3f6015f..f63f3bcb 100644 --- a/ST_indivs.c +++ b/ST_indivs.c @@ -21,8 +21,8 @@ #include #include "ST_steppe.h" #include "ST_globals.h" -#include "sw_src/filefuncs.h" -#include "sw_src/myMemory.h" +#include "sw_src/include/filefuncs.h" +#include "sw_src/include/myMemory.h" /******** Modular External Function Declarations ***********/ diff --git a/ST_main.c b/ST_main.c index 2205a708..249cba51 100644 --- a/ST_main.c +++ b/ST_main.c @@ -23,21 +23,21 @@ #include #include #include "ST_steppe.h" -#include "sw_src/generic.h" // externs `*logfp`, `errstr`, `EchoInits`, `QuietMode`, `logged` -#include "sw_src/filefuncs.h" // externs `inbuf` -#include "sw_src/myMemory.h" -#include "sw_src/SW_VegProd.h" -#include "sw_src/SW_Control.h" -#include "sw_src/pcg/pcg_basic.h" -#include "sw_src/SW_Markov.h"// externs `markov_rng` +#include "sw_src/include/generic.h" // externs `*logfp`, `errstr`, `EchoInits`, `QuietMode`, `logged` +#include "sw_src/include/filefuncs.h" // externs `inbuf` +#include "sw_src/include/myMemory.h" +#include "sw_src/include/SW_VegProd.h" +#include "sw_src/include/SW_Control.h" +#include "sw_src/external/pcg/pcg_basic.h" +#include "sw_src/include/SW_Markov.h"// externs `markov_rng` #include "sxw_funcs.h" #include "sxw.h" // externs `prepare_IterationSummary`, `storeAllIterations` -#include "sw_src/SW_Output.h" -#include "sw_src/SW_Output_outtext.h" // externs `print_IterationSummary` -#include "sw_src/SW_Output_outarray.h" -#include "sw_src/rands.h" +#include "sw_src/include/SW_Output.h" +#include "sw_src/include/SW_Output_outtext.h" // externs `print_IterationSummary` +#include "sw_src/include/SW_Output_outarray.h" +#include "sw_src/include/rands.h" #include "ST_functions.h" // externs `environs_rng`, `resgroups_rng`, `species_rng` #include "ST_spinup.h" #include "ST_stats.h" diff --git a/ST_mortality.c b/ST_mortality.c index 3e22ecc5..06906a24 100644 --- a/ST_mortality.c +++ b/ST_mortality.c @@ -23,12 +23,12 @@ #include #include "ST_mortality.h" -#include "sw_src/filefuncs.h" -#include "sw_src/rands.h" -#include "sw_src/myMemory.h" +#include "sw_src/include/filefuncs.h" +#include "sw_src/include/rands.h" +#include "sw_src/include/myMemory.h" #include "ST_steppe.h" #include "ST_globals.h" -#include "sw_src/pcg/pcg_basic.h" +#include "sw_src/external/pcg/pcg_basic.h" #include "sxw_vars.h" diff --git a/ST_mortality.h b/ST_mortality.h index ea161659..c514c420 100644 --- a/ST_mortality.h +++ b/ST_mortality.h @@ -10,22 +10,22 @@ #ifndef MORTALITY_H #define MORTALITY_H -#include "sw_src/generic.h" -#include "sw_src/pcg/pcg_basic.h" +#include "sw_src/include/generic.h" +#include "sw_src/external/pcg/pcg_basic.h" /* --------------------------- Exported Structs ---------------------------- */ /** * \brief Information used when simulating the cheatgrass-wildfire loop. - * + * * The biggest determinant in cheatgrass driven wildfire is precipitation, - * specifically precipitation in Spring and Winter. This struct stores the + * specifically precipitation in Spring and Winter. This struct stores the * values from previous Spring and Winter precipitation as well as the running * averages of both. - * + * * Note that "year" in this context refers to the water year, which runs from * October to September. - * + * * \sa _updateCheatgrassPrecip, where this struct is updated each year. * \author Chandler Haukap * \date 13 January 2020 diff --git a/ST_output.c b/ST_output.c index fd1285f8..4fbd5781 100644 --- a/ST_output.c +++ b/ST_output.c @@ -15,14 +15,14 @@ #include #include "ST_steppe.h" #include "ST_globals.h" -#include "sw_src/filefuncs.h" -#include "sw_src/myMemory.h" +#include "sw_src/include/filefuncs.h" +#include "sw_src/include/myMemory.h" /******** Modular External Function Declarations ***********/ /* -- truly global functions are declared in functions.h --*/ /***********************************************************/ -#include "sw_src/SW_Model.h" // externs `SW_Model` +#include "sw_src/include/SW_Model.h" // externs `SW_Model` /*------------------------------------------------------*/ diff --git a/ST_params.c b/ST_params.c index b1678669..e6f73564 100644 --- a/ST_params.c +++ b/ST_params.c @@ -23,9 +23,9 @@ #include #include #include "ST_steppe.h" -#include "sw_src/filefuncs.h" -#include "sw_src/myMemory.h" -#include "sw_src/rands.h" +#include "sw_src/include/filefuncs.h" +#include "sw_src/include/myMemory.h" +#include "sw_src/include/rands.h" #include "sxw_funcs.h" #include "ST_globals.h" #include "sxw_vars.h" diff --git a/ST_resgroups.c b/ST_resgroups.c index 4cea821b..9ae7e5c1 100644 --- a/ST_resgroups.c +++ b/ST_resgroups.c @@ -29,9 +29,9 @@ #include #include "ST_steppe.h" #include "ST_globals.h" -#include "sw_src/myMemory.h" -#include "sw_src/rands.h" -#include "sw_src/filefuncs.h" +#include "sw_src/include/myMemory.h" +#include "sw_src/include/rands.h" +#include "sw_src/include/filefuncs.h" #include "sxw_funcs.h" diff --git a/ST_seedDispersal.c b/ST_seedDispersal.c index 069b8d2a..0fd40b43 100644 --- a/ST_seedDispersal.c +++ b/ST_seedDispersal.c @@ -14,9 +14,9 @@ #include "ST_defines.h" #include "ST_grid.h" #include "ST_seedDispersal.h" -#include "sw_src/rands.h" -#include "sw_src/myMemory.h" -#include "sw_src/rands.h" +#include "sw_src/include/rands.h" +#include "sw_src/include/myMemory.h" +#include "sw_src/include/rands.h" float _distance(int x1, int y1, int x2, int y2, float cellWidth); Bool _shouldProduceSeeds(SppIndex sp); diff --git a/ST_species.c b/ST_species.c index e4687230..df78e918 100644 --- a/ST_species.c +++ b/ST_species.c @@ -22,9 +22,9 @@ #include #include "ST_steppe.h" #include "ST_globals.h" -#include "sw_src/filefuncs.h" -#include "sw_src/myMemory.h" -#include "sw_src/rands.h" +#include "sw_src/include/filefuncs.h" +#include "sw_src/include/myMemory.h" +#include "sw_src/include/rands.h" #include "ST_spinup.h" #include "ST_seedDispersal.h" // externs `UseSeedDispersal` diff --git a/ST_spinup.c b/ST_spinup.c index 48fc4ce6..fa5138c1 100644 --- a/ST_spinup.c +++ b/ST_spinup.c @@ -17,21 +17,21 @@ #include "ST_stats.h" #include "ST_globals.h" // externs UseProgressBar #include "ST_mortality.h" -#include "sw_src/rands.h" -#include "sw_src/SW_SoilWater.h" // externs SW_Soilwat -#include "sw_src/SW_Weather.h" // externs SW_Weather -#include "sw_src/SW_Site.h" // externs SW_Site -#include "sw_src/SW_VegProd.h" // externs SW_VegProd -#include "sw_src/SW_Markov.h"// externs `markov_rng` +#include "sw_src/include/rands.h" +#include "sw_src/include/SW_SoilWater.h" // externs SW_Soilwat +#include "sw_src/include/SW_Weather.h" // externs SW_Weather +#include "sw_src/include/SW_Site.h" // externs SW_Site +#include "sw_src/include/SW_VegProd.h" // externs SW_VegProd +#include "sw_src/include/SW_Markov.h"// externs `markov_rng` #include "sxw_funcs.h" -#include "sw_src/myMemory.h" -#include "sw_src/filefuncs.h" +#include "sw_src/include/myMemory.h" +#include "sw_src/include/filefuncs.h" #include "ST_progressBar.h" #include "ST_grid.h" // externs grid_rng // externs `prepare_IterationSummary`, `storeAllIterations` -#include "sw_src/SW_Output.h" -#include "sw_src/SW_Output_outtext.h" // externs `print_IterationSummary` -#include "sw_src/SW_Output_outarray.h" +#include "sw_src/include/SW_Output.h" +#include "sw_src/include/SW_Output_outtext.h" // externs `print_IterationSummary` +#include "sw_src/include/SW_Output_outarray.h" #include "ST_functions.h" // externs `environs_rng`, `resgroups_rng`, `species_rng` diff --git a/ST_stats.c b/ST_stats.c index 03e67007..5235cbed 100644 --- a/ST_stats.c +++ b/ST_stats.c @@ -40,8 +40,8 @@ #include #include "ST_steppe.h" -#include "sw_src/filefuncs.h" -#include "sw_src/myMemory.h" +#include "sw_src/include/filefuncs.h" +#include "sw_src/include/myMemory.h" #include "ST_stats.h" // Contains most of the function declarations. #include "ST_seedDispersal.h" // externs `UseSeedDispersal` #include "ST_globals.h" diff --git a/ST_structs.h b/ST_structs.h index 0e5f8aa4..ce3702c9 100644 --- a/ST_structs.h +++ b/ST_structs.h @@ -23,7 +23,7 @@ #ifndef STEPPE_STRUCT_DEF #define STEPPE_STRUCT_DEF -#include "sw_src/generic.h" +#include "sw_src/include/generic.h" #include "ST_mortality.h" /** diff --git a/makefile b/makefile index 2f783b7c..c3c52293 100644 --- a/makefile +++ b/makefile @@ -21,12 +21,16 @@ CFLAGS = \ sw2 = SOILWAT2 lib_sw2 = lib$(sw2).a path_sw2 = sw_src +path_sw2lib = $(path_sw2)/bin +# Note: `-I$(path_sw2)` is required for `#include "external/pcg/pcg_basic.h"` +# in SOILWAT2 headers that are included by STEPWAT2 code INC_DIRS = \ -I. \ -Isqlite-amalgamation \ - -I$(path_sw2)/googletest/googletest \ - -I$(path_sw2)/googletest/googletest/include \ + -I$(path_sw2) \ + -I$(path_sw2)/external/googletest/googletest \ + -I$(path_sw2)/external/googletest/googletest/include \ -Itest sources_core = \ @@ -53,49 +57,63 @@ sources_core = \ ST_colonization.c sources_test = \ - $(path_sw2)/googletest/googletest/src/gtest-all.cc \ - $(path_sw2)/googletest/googletest/src/gtest_main.cc \ + $(path_sw2)/external/googletest/googletest/src/gtest-all.cc \ + $(path_sw2)/external/googletest/googletest/src/gtest_main.cc \ test/test_ST_mortality.cc sw2_sources = \ - SW_Output_outarray.c \ - SW_Output_outtext.c + src/SW_Output_outarray.c \ + src/SW_Output_outtext.c objects_core = $(sources_core:%.c=obj/%.o) objects_core_test = $(sources_core:%.c=obj/%_TEST.o) objects_test = $(sources_test:%.cc=obj/%.o) +dir_obj = \ + obj \ + obj/sqlite-amalgamation +dir_test = \ + obj/test \ + obj/$(path_sw2)/external/googletest/googletest/src -sw_LDFLAGS = $(LDFLAGS) -L. -L$(path_sw2) +sw_LDFLAGS = $(LDFLAGS) -L. -L$(path_sw2lib) sw_LDLIBS = -l$(sw2) $(LDLIBS) -lm -all: $(path_sw2)/$(lib_sw2) stepwat stepwat_test +all: $(path_sw2lib)/$(lib_sw2) stepwat stepwat_test -$(path_sw2)/$(lib_sw2): - @(cd $(path_sw2) && $(MAKE) $(lib_sw2) \ - CC="$(CC)" CPPFLAGS="$(CPPFLAGS)" CFLAGS="$(CFLAGS)" AR="$(AR)" \ +$(path_sw2lib)/$(lib_sw2): +# Note: `-I..` is required for `#include "ST_defines.h"` +# in SOILWAT2 headers that are included by SOILWAT2 code + @(cd $(path_sw2) && $(MAKE) lib \ + CC="$(CC)" CPPFLAGS="$(CPPFLAGS) -I.." CFLAGS="$(CFLAGS)" AR="$(AR)" \ sw_sources="$(sw2_sources)") -stepwat: $(path_sw2)/$(lib_sw2) $(objects_core) +stepwat: $(path_sw2lib)/$(lib_sw2) $(objects_core) | $(dir_obj) $(CC) $(objects_core) $(CFLAGS) $(CPPFLAGS) $(sw_LDLIBS) $(sw_LDFLAGS) -o stepwat -@cp stepwat testing.sagebrush.master -@cp stepwat testing.sagebrush.master/Stepwat_Inputs -stepwat_test: $(path_sw2)/$(lib_sw2) $(objects_core_test) $(objects_test) +stepwat_test: $(path_sw2lib)/$(lib_sw2) $(objects_core_test) $(objects_test) | $(dir_obj) $(dir_test) $(CXX) $(objects_core_test) $(objects_test) $(CFLAGS) $(CPPFLAGS) $(sw_LDLIBS) $(sw_LDFLAGS) -o stepwat_test -obj/%.o: %.c +obj/%.o: %.c | $(dir_obj) $(CC) $(CFLAGS) $(CPPFLAGS) $(INC_DIRS) -c $< -o $@ -obj/%.o: %.cc +obj/%.o: %.cc | $(dir_obj) $(CXX) $(CFLAGS) $(CPPFLAGS) $(INC_DIRS) -std=gnu++11 -c $< -o $@ -obj/%_TEST.o: %.c +obj/%_TEST.o: %.c | $(dir_obj) $(dir_test) $(CC) $(CFLAGS) $(CPPFLAGS) $(INC_DIRS) -DSTDEBUG -c $< -o $@ + +#--- Create directories +$(dir_obj) $(dir_test): + -@mkdir -p $@ + + .PHONY: run_tests run_tests: stepwat_test ./stepwat_test @@ -117,7 +135,7 @@ clean: cleanobjs cleanbin documentation_clean .PHONY: cleanobjs cleanobjs: -@find . -type f -name '*.o' -delete - -@$(RM) -f $(path_sw2)/$(lib_sw2) + -@$(RM) -f $(path_sw2lib)/$(lib_sw2) .PHONY: cleanbin cleanbin: diff --git a/obj/sqlite-amalgamation/.gitignore b/obj/sqlite-amalgamation/.gitignore deleted file mode 100644 index 5e7d2734..00000000 --- a/obj/sqlite-amalgamation/.gitignore +++ /dev/null @@ -1,4 +0,0 @@ -# Ignore everything in this directory -* -# Except this file -!.gitignore diff --git a/obj/sw_src/googletest/googletest/src/.gitignore b/obj/sw_src/googletest/googletest/src/.gitignore deleted file mode 100644 index 5e7d2734..00000000 --- a/obj/sw_src/googletest/googletest/src/.gitignore +++ /dev/null @@ -1,4 +0,0 @@ -# Ignore everything in this directory -* -# Except this file -!.gitignore diff --git a/obj/sw_src/pcg/.gitignore b/obj/sw_src/pcg/.gitignore deleted file mode 100644 index 5e7d2734..00000000 --- a/obj/sw_src/pcg/.gitignore +++ /dev/null @@ -1,4 +0,0 @@ -# Ignore everything in this directory -* -# Except this file -!.gitignore diff --git a/obj/test/.gitignore b/obj/test/.gitignore deleted file mode 100644 index 5e7d2734..00000000 --- a/obj/test/.gitignore +++ /dev/null @@ -1,4 +0,0 @@ -# Ignore everything in this directory -* -# Except this file -!.gitignore diff --git a/sw_src b/sw_src index a6c367ae..2b5c7d71 160000 --- a/sw_src +++ b/sw_src @@ -1 +1 @@ -Subproject commit a6c367aef07b746a43b459067ee0ef0139f9f60b +Subproject commit 2b5c7d71f355337390a0d094d5463b2bea1ca9a7 diff --git a/sxw.c b/sxw.c index 49cb5e29..da43ffd3 100644 --- a/sxw.c +++ b/sxw.c @@ -48,27 +48,27 @@ #include #include #include -#include "sw_src/generic.h" // externs `errstr` -#include "sw_src/filefuncs.h" // externs `inbuf` -#include "sw_src/myMemory.h" +#include "sw_src/include/generic.h" // externs `errstr` +#include "sw_src/include/filefuncs.h" // externs `inbuf` +#include "sw_src/include/myMemory.h" #include "ST_steppe.h" #include "ST_globals.h" -#include "sw_src/SW_Defines.h" +#include "sw_src/include/SW_Defines.h" #include "sxw.h" #include "sxw_funcs.h" #include "sxw_module.h" -#include "sw_src/SW_Control.h" -#include "sw_src/SW_Model.h" -#include "sw_src/SW_VegProd.h" -#include "sw_src/SW_Carbon.h" -#include "sw_src/SW_Site.h" -#include "sw_src/SW_SoilWater.h" -#include "sw_src/SW_Files.h" -#include "sw_src/SW_Weather.h" -#include "sw_src/SW_Markov.h" -#include "sw_src/SW_Output.h" // externs `prepare_IterationSummary`, `storeAllIterations` -#include "sw_src/rands.h" -#include "sw_src/pcg/pcg_basic.h" +#include "sw_src/include/SW_Control.h" +#include "sw_src/include/SW_Model.h" +#include "sw_src/include/SW_VegProd.h" +#include "sw_src/include/SW_Carbon.h" +#include "sw_src/include/SW_Site.h" +#include "sw_src/include/SW_SoilWater.h" +#include "sw_src/include/SW_Files.h" +#include "sw_src/include/SW_Weather.h" +#include "sw_src/include/SW_Markov.h" +#include "sw_src/include/SW_Output.h" // externs `prepare_IterationSummary`, `storeAllIterations` +#include "sw_src/include/rands.h" +#include "sw_src/external/pcg/pcg_basic.h" /*************** Global Variable Declarations ***************/ diff --git a/sxw.h b/sxw.h index 65de23d5..14920044 100644 --- a/sxw.h +++ b/sxw.h @@ -24,10 +24,10 @@ // The number of transpiration values retained by transp_data #define MAX_WINDOW 100 -#include "sw_src/SW_Times.h" +#include "sw_src/include/SW_Times.h" #include "ST_defines.h" -#include "sw_src/SW_Defines.h" -#include "sw_src/pcg/pcg_basic.h" +#include "sw_src/include/SW_Defines.h" +#include "sw_src/external/pcg/pcg_basic.h" diff --git a/sxw_environs.c b/sxw_environs.c index cb1b14e7..b48be0c7 100644 --- a/sxw_environs.c +++ b/sxw_environs.c @@ -15,13 +15,13 @@ #include "ST_steppe.h" #include "ST_globals.h" // externs `*Env` -#include "sw_src/SW_Defines.h" +#include "sw_src/include/SW_Defines.h" #include "sxw.h" // externs `*SXW` #include "sxw_module.h" -#include "sw_src/SW_Model.h" // externs SW_Model -#include "sw_src/SW_Site.h" // externs SW_Site -#include "sw_src/SW_SoilWater.h" // externs SW_Soilwat -#include "sw_src/SW_Weather.h" // externs SW_Weather +#include "sw_src/include/SW_Model.h" // externs SW_Model +#include "sw_src/include/SW_Site.h" // externs SW_Site +#include "sw_src/include/SW_SoilWater.h" // externs SW_Soilwat +#include "sw_src/include/SW_Weather.h" // externs SW_Weather diff --git a/sxw_main.c b/sxw_main.c index 912f757e..47d80ab7 100644 --- a/sxw_main.c +++ b/sxw_main.c @@ -17,9 +17,9 @@ #include #include #include "ST_steppe.h" -#include "sw_src/generic.h" // externs `errstr` -#include "sw_src/filefuncs.h" // externs `inbuf` -#include "sw_src/myMemory.h" +#include "sw_src/include/generic.h" // externs `errstr` +#include "sw_src/include/filefuncs.h" // externs `inbuf` +#include "sw_src/include/myMemory.h" #include "sxw_funcs.h" /* for the chdir function */ diff --git a/sxw_module.h b/sxw_module.h index e560ce82..3f89593b 100644 --- a/sxw_module.h +++ b/sxw_module.h @@ -14,11 +14,11 @@ #ifndef SXW_MODULE_DEF #define SXW_MODULE_DEF -#include "sw_src/SW_Control.h" -#include "sw_src/SW_Model.h" -#include "sw_src/SW_VegProd.h" -#include "sw_src/SW_SoilWater.h" -#include "sw_src/SW_Files.h" +#include "sw_src/include/SW_Control.h" +#include "sw_src/include/SW_Model.h" +#include "sw_src/include/SW_VegProd.h" +#include "sw_src/include/SW_SoilWater.h" +#include "sw_src/include/SW_Files.h" /* some macros for the production conversion array */ #define PC_Bmass 0 diff --git a/sxw_resource.c b/sxw_resource.c index 25261d64..f19a585a 100644 --- a/sxw_resource.c +++ b/sxw_resource.c @@ -13,23 +13,23 @@ /* --------------------------------------------------- */ -#include "sw_src/generic.h" -#include "sw_src/rands.h" -#include "sw_src/filefuncs.h" -#include "sw_src/myMemory.h" +#include "sw_src/include/generic.h" +#include "sw_src/include/rands.h" +#include "sw_src/include/filefuncs.h" +#include "sw_src/include/myMemory.h" #include "ST_steppe.h" #include "ST_globals.h" -#include "sw_src/SW_Defines.h" +#include "sw_src/include/SW_Defines.h" #include "sxw.h" // externs `*SXWResources`, `transp_window`, `resource_rng` #include "sxw_module.h" #include "sxw_vars.h" -#include "sw_src/SW_Control.h" -#include "sw_src/SW_Site.h" -#include "sw_src/SW_SoilWater.h" -#include "sw_src/SW_VegProd.h" -#include "sw_src/SW_Files.h" -#include "sw_src/SW_Times.h" -#include "sw_src/pcg/pcg_basic.h" +#include "sw_src/include/SW_Control.h" +#include "sw_src/include/SW_Site.h" +#include "sw_src/include/SW_SoilWater.h" +#include "sw_src/include/SW_VegProd.h" +#include "sw_src/include/SW_Files.h" +#include "sw_src/include/SW_Times.h" +#include "sw_src/external/pcg/pcg_basic.h" diff --git a/sxw_soilwat.c b/sxw_soilwat.c index 6756d208..01e8d9ff 100644 --- a/sxw_soilwat.c +++ b/sxw_soilwat.c @@ -39,23 +39,23 @@ /* --------------------------------------------------- */ -#include "sw_src/generic.h" -#include "sw_src/filefuncs.h" -#include "sw_src/myMemory.h" -#include "sw_src/Times.h" +#include "sw_src/include/generic.h" +#include "sw_src/include/filefuncs.h" +#include "sw_src/include/myMemory.h" +#include "sw_src/include/Times.h" #include "ST_steppe.h" #include "ST_globals.h" -#include "sw_src/SW_Defines.h" +#include "sw_src/include/SW_Defines.h" #include "sxw.h" // externs `*SXWResources` #include "sxw_module.h" #include "sxw_vars.h" -#include "sw_src/SW_Control.h" -#include "sw_src/SW_Weather.h" // externs `SW_Weather` -#include "sw_src/SW_Model.h" // externs `SW_Model` -#include "sw_src/SW_Site.h" // externs `SW_Site` -#include "sw_src/SW_SoilWater.h" -#include "sw_src/SW_VegProd.h" // externs `SW_VegProd` -#include "sw_src/SW_Files.h" +#include "sw_src/include/SW_Control.h" +#include "sw_src/include/SW_Weather.h" // externs `SW_Weather` +#include "sw_src/include/SW_Model.h" // externs `SW_Model` +#include "sw_src/include/SW_Site.h" // externs `SW_Site` +#include "sw_src/include/SW_SoilWater.h" +#include "sw_src/include/SW_VegProd.h" // externs `SW_VegProd` +#include "sw_src/include/SW_Files.h" diff --git a/sxw_sql.c b/sxw_sql.c index 90f2ffd5..cfb6a606 100644 --- a/sxw_sql.c +++ b/sxw_sql.c @@ -12,9 +12,9 @@ #include #include "ST_steppe.h" #include "ST_globals.h" -#include "sw_src/SW_Model.h" // externs `SW_Model` -#include "sw_src/SW_Site.h" // externs `SW_Site` -#include "sw_src/SW_VegProd.h" // externs `SW_VegProd` +#include "sw_src/include/SW_Model.h" // externs `SW_Model` +#include "sw_src/include/SW_Site.h" // externs `SW_Site` +#include "sw_src/include/SW_VegProd.h" // externs `SW_VegProd` #include "sxw_module.h" #include "sxw.h" // externs `*SXW`, `*SXWResources` diff --git a/test/test_ST_mortality.h b/test/test_ST_mortality.h index ffefba22..2ef3a232 100644 --- a/test/test_ST_mortality.h +++ b/test/test_ST_mortality.h @@ -1,8 +1,8 @@ #ifndef TEST_ST_MORTALITY_H #define TEST_ST_MORTALITY_H -#include "sw_src/generic.h" -#include "sw_src/myMemory.h" +#include "sw_src/include/generic.h" +#include "sw_src/include/myMemory.h" #include "ST_defines.h" #include "ST_globals.h" From ec1896bf67882142efdc9740419c31fc490ca9cb Mon Sep 17 00:00:00 2001 From: Daniel Schlaepfer Date: Wed, 28 Dec 2022 18:03:55 -0500 Subject: [PATCH 07/15] Clean up "Updates for new SOILWAT2 project structure" - the previous commit (550545726922fe95821cbb1dbad7423df4474c4c) by mistake did not update a few paths -> this is not fixed --- ST_environs.c | 6 +++--- sxw.c | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/ST_environs.c b/ST_environs.c index a658575a..5b9b8a57 100644 --- a/ST_environs.c +++ b/ST_environs.c @@ -14,11 +14,11 @@ #include "ST_steppe.h" #include "ST_globals.h" -#include "sw_src/pcg/pcg_basic.h" -#include "sw_src/rands.h" +#include "sw_src/external/pcg/pcg_basic.h" +#include "sw_src/include/rands.h" #include "sxw.h" // externs `*SXW` #include "sxw_funcs.h" -#include "sw_src/filefuncs.h" +#include "sw_src/include/filefuncs.h" /*********** Locally Used Function Declarations ************/ /***********************************************************/ diff --git a/sxw.c b/sxw.c index da43ffd3..de1b1854 100644 --- a/sxw.c +++ b/sxw.c @@ -1109,7 +1109,7 @@ void _print_debuginfo(void) { #ifdef DEBUG_MEM -#include "sw_src/myMemory.h" +#include "sw_src/include/myMemory.h" /*======================================================*/ void SXW_SetMemoryRefs( void) { /* when debugging memory problems, use the bookkeeping From 912a4b0743f4596389fd45a1126f51e9d12c055a Mon Sep 17 00:00:00 2001 From: Daniel Schlaepfer Date: Thu, 29 Dec 2022 17:51:29 -0500 Subject: [PATCH 08/15] Wrap up updates for re-structured SOILWAT2 - set SOILWAT2 back to branch `release/devel_v7.0.0` (on commit 296f123e35836d29d59dbc5ec4974f7e55f9cfa7) that now includes the completed `feature_restructure` --- .gitmodules | 2 +- sw_src | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.gitmodules b/.gitmodules index da28c307..6a6c0490 100644 --- a/.gitmodules +++ b/.gitmodules @@ -1,5 +1,5 @@ [submodule "sw_src"] path = sw_src url = https://github.com/DrylandEcology/SOILWAT2.git - branch = feature_restructure + branch = release/devel_v7.0.0 ignore = dirty diff --git a/sw_src b/sw_src index 2b5c7d71..296f123e 160000 --- a/sw_src +++ b/sw_src @@ -1 +1 @@ -Subproject commit 2b5c7d71f355337390a0d094d5463b2bea1ca9a7 +Subproject commit 296f123e35836d29d59dbc5ec4974f7e55f9cfa7 From 777cf5b6495edaf7cd171be8b2fc267765fcd260 Mon Sep 17 00:00:00 2001 From: Nicholas Persley Date: Sun, 29 Jan 2023 13:18:38 -0700 Subject: [PATCH 09/15] Updated Submodule --- .gitmodules | 2 +- sw_src | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.gitmodules b/.gitmodules index 6a6c0490..afdbe41d 100644 --- a/.gitmodules +++ b/.gitmodules @@ -1,5 +1,5 @@ [submodule "sw_src"] path = sw_src url = https://github.com/DrylandEcology/SOILWAT2.git - branch = release/devel_v7.0.0 + branch = read_more_daily_input ignore = dirty diff --git a/sw_src b/sw_src index 296f123e..20e11e01 160000 --- a/sw_src +++ b/sw_src @@ -1 +1 @@ -Subproject commit 296f123e35836d29d59dbc5ec4974f7e55f9cfa7 +Subproject commit 20e11e0134fa67e0def34499b9735a7fd7ffa849 From 95b7b2fa7199b05f59d9ede69f47e72a3b23feb4 Mon Sep 17 00:00:00 2001 From: Nicholas Persley Date: Sun, 29 Jan 2023 13:45:00 -0700 Subject: [PATCH 10/15] STEPWAT2 handles more daily weather variables - The updated submodule (SOILWAT2) has the ability to read new daily weather variables in weath.YYYY. The new variables are: * Cloud cover, (maximum/minimum) relative humidity, (east/north components of) wind speed, shortwave radiation, actual vapor pressure, specific humidity, and dewpoint temperature - "sxw_soilwat.c" gains the include of "SW_Sky.h" to extern the variable, "SW_Sky" - `_sxw_generate_weather()` makes sure monthly input flags are set, so when the weather generator runs, cloud cover, humidity, and wind speed are filled with daily interpolated values from monthly input --- sxw_soilwat.c | 19 ++++++- .../Input/sxw/Input/weathsetup.in | 55 ++++++++++++++----- 2 files changed, 60 insertions(+), 14 deletions(-) mode change 100644 => 100755 testing.sagebrush.master/Stepwat_Inputs/Input/sxw/Input/weathsetup.in diff --git a/sxw_soilwat.c b/sxw_soilwat.c index 01e8d9ff..fadef7dd 100644 --- a/sxw_soilwat.c +++ b/sxw_soilwat.c @@ -56,6 +56,7 @@ #include "sw_src/include/SW_SoilWater.h" #include "sw_src/include/SW_VegProd.h" // externs `SW_VegProd` #include "sw_src/include/SW_Files.h" +#include "sw_src/include/SW_Sky.h" // externs SW_Sky @@ -102,6 +103,8 @@ void _sxw_sw_setup (RealF sizes[]) { */ void _sxw_generate_weather(void) { SW_WEATHER *w = &SW_Weather; + SW_SKY *sky = &SW_Sky; + int flag; deallocateAllWeather(w); w->n_years = 1; @@ -116,12 +119,26 @@ void _sxw_generate_weather(void) { ); } + // Make sure monthly flags are set to interpolate monthly values into daily values + w->use_humidityMonthly = swTRUE; + w->use_cloudCoverMonthly = swTRUE; + w->use_windSpeedMonthly = swTRUE; + readAllWeather( w->allHist, w->startYear, w->n_years, swTRUE, // `use_weathergenerator_only` - w->name_prefix // not used because `use_weathergenerator_only` + w->name_prefix, // not used because `use_weathergenerator_only` + w->use_cloudCoverMonthly, + w->use_humidityMonthly, + w->use_windSpeedMonthly, + w->n_input_forcings, + w->dailyInputIndices, + w->dailyInputFlags, + sky->cloudcov, + sky->windspeed, + sky->r_humidity ); finalizeAllWeather(w); // run the weather generator diff --git a/testing.sagebrush.master/Stepwat_Inputs/Input/sxw/Input/weathsetup.in b/testing.sagebrush.master/Stepwat_Inputs/Input/sxw/Input/weathsetup.in old mode 100644 new mode 100755 index e5273ccf..f5be6c05 --- a/testing.sagebrush.master/Stepwat_Inputs/Input/sxw/Input/weathsetup.in +++ b/testing.sagebrush.master/Stepwat_Inputs/Input/sxw/Input/weathsetup.in @@ -15,6 +15,33 @@ 7 # Seed random number generator for weather generator (only used if SOILWAT2) # (seed with 0 to use current time) +#--- Flags describing mean monthly climate input usage: +# 0 = Don't use mean monthly input +# 1 = Use mean monthly input (climate.in) and override respective flag for daily input, if flags conflict +1 # Sky cover +1 # Wind speed +1 # Relative humidity + + +#--- Flags describing daily weather input files "weath.YYYY": +# 0 = Variable is absent +# 1 = Daily variable present +# Note: The order of input values within input files must match the order of flags below (e.g., cloud cover cannot precede minimum temperature) +# Note: If maximum/minimum temperature or precipitation is set to 0 or a flag is set to 1, and the input data is not complete, the program will crash +1 # Maximum daily temperature [C] +1 # Minimum daily temperature [C] +1 # Precipitation [cm] +0 # Cloud cover [%] +0 # Wind speed [m/s] +0 # Wind speed eastward component [m/s] +0 # Wind speed northward component [m/s] +0 # Relative humidity [%] +0 # Maximum relative humidity [%] +0 # Minimum relative humidity [%] +0 # Specific humidity [%] +0 # Dew point temperature [C] +0 # Actual vapor pressure [kPa] +0 # Downward surface shortwave radiation [W/m2], i.e., flux density for a (hypothetical) flat horizon averaged over the daylight period of the day #--- Monthly scaling parameters: # Month 1 = January, Month 2 = February, etc. @@ -24,16 +51,18 @@ # SkyCover = additive for mean monthly sky cover [%]; min(100, max(0, scale + sky cover)) # Wind = multiplicative for mean monthly wind speed; max(0, scale * wind speed) # rH = additive for mean monthly relative humidity [%]; min(100, max(0, scale + rel. Humidity)) -#Mon PPT MaxT MinT SkyCover Wind rH -1 1.000 0.00 0.00 0.0 1.0 0.0 -2 1.000 0.00 0.00 0.0 1.0 0.0 -3 1.000 0.00 0.00 0.0 1.0 0.0 -4 1.000 0.00 0.00 0.0 1.0 0.0 -5 1.000 0.00 0.00 0.0 1.0 0.0 -6 1.000 0.00 0.00 0.0 1.0 0.0 -7 1.000 0.00 0.00 0.0 1.0 0.0 -8 1.000 0.00 0.00 0.0 1.0 0.0 -9 1.000 0.00 0.00 0.0 1.0 0.0 -10 1.000 0.00 0.00 0.0 1.0 0.0 -11 1.000 0.00 0.00 0.0 1.0 0.0 -12 1.000 0.00 0.00 0.0 1.0 0.0 +# ActVP = multiplicative for actual vapor pressure [kPa]; max(0, scale * actual vapor pressure) +# ShortWR = multiplicative for shortwave radiation [W/m2]; max(0, scale * shortwave radiation) +#Mon PPT MaxT MinT SkyCover Wind rH ActVP ShortWR +1 1.000 0.00 0.00 0.0 1.0 0.0 1.0 1.0 +2 1.000 0.00 0.00 0.0 1.0 0.0 1.0 1.0 +3 1.000 0.00 0.00 0.0 1.0 0.0 1.0 1.0 +4 1.000 0.00 0.00 0.0 1.0 0.0 1.0 1.0 +5 1.000 0.00 0.00 0.0 1.0 0.0 1.0 1.0 +6 1.000 0.00 0.00 0.0 1.0 0.0 1.0 1.0 +7 1.000 0.00 0.00 0.0 1.0 0.0 1.0 1.0 +8 1.000 0.00 0.00 0.0 1.0 0.0 1.0 1.0 +9 1.000 0.00 0.00 0.0 1.0 0.0 1.0 1.0 +10 1.000 0.00 0.00 0.0 1.0 0.0 1.0 1.0 +11 1.000 0.00 0.00 0.0 1.0 0.0 1.0 1.0 +12 1.000 0.00 0.00 0.0 1.0 0.0 1.0 1.0 From bbd3c654b2bb0ede4c6a1c1f13c1674ae3a2ca31 Mon Sep 17 00:00:00 2001 From: Nicholas Persley Date: Mon, 30 Jan 2023 20:48:15 -0700 Subject: [PATCH 11/15] Removed unnecessary "flag" in `_sxw_generate_weather()` --- sxw_soilwat.c | 1 - 1 file changed, 1 deletion(-) diff --git a/sxw_soilwat.c b/sxw_soilwat.c index fadef7dd..1058967e 100644 --- a/sxw_soilwat.c +++ b/sxw_soilwat.c @@ -104,7 +104,6 @@ void _sxw_sw_setup (RealF sizes[]) { void _sxw_generate_weather(void) { SW_WEATHER *w = &SW_Weather; SW_SKY *sky = &SW_Sky; - int flag; deallocateAllWeather(w); w->n_years = 1; From 6fcc81e3d15c418db231935db0aeb4c2036b44fa Mon Sep 17 00:00:00 2001 From: Daniel Schlaepfer Date: Thu, 23 Feb 2023 15:56:53 -0500 Subject: [PATCH 12/15] SOILWAT2 updated handling of solar radiation inputs - for details, see https://github.com/DrylandEcology/SOILWAT2/pull/345 -> "weathsetup.in" gained a new input "description of downward surface shortwave radiation" -> none of that is currently relevant or active for STEPWAT2 - this commit produces identical output to commit c974dc6d6abf9bb77389b96a3b0a151f8495cee3 on branch feature_SOILWAT2_v700_devel --- sw_src | 2 +- .../Stepwat_Inputs/Input/sxw/Input/weathsetup.in | 12 +++++++++++- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/sw_src b/sw_src index 20e11e01..2a980665 160000 --- a/sw_src +++ b/sw_src @@ -1 +1 @@ -Subproject commit 20e11e0134fa67e0def34499b9735a7fd7ffa849 +Subproject commit 2a980665f4346c955b872f0820c738bc29c16b6f diff --git a/testing.sagebrush.master/Stepwat_Inputs/Input/sxw/Input/weathsetup.in b/testing.sagebrush.master/Stepwat_Inputs/Input/sxw/Input/weathsetup.in index f5be6c05..9580ec7f 100755 --- a/testing.sagebrush.master/Stepwat_Inputs/Input/sxw/Input/weathsetup.in +++ b/testing.sagebrush.master/Stepwat_Inputs/Input/sxw/Input/weathsetup.in @@ -41,7 +41,17 @@ 0 # Specific humidity [%] 0 # Dew point temperature [C] 0 # Actual vapor pressure [kPa] -0 # Downward surface shortwave radiation [W/m2], i.e., flux density for a (hypothetical) flat horizon averaged over the daylight period of the day +0 # Downward surface shortwave radiation (see `Daily weather input descriptions`) + + +#--- Daily weather input descriptions +0 # Description of downward surface shortwave radiation + # * 0: `rsds` represents daily global horizontal irradiation [MJ / m2] + # * 1: `rsds` represents flux density [W / m2] for a + # (hypothetical) flat horizon averaged over an entire day (24 hour period) + # * 2: `rsds` represents flux density [W / m2] for a + # (hypothetical) flat horizon averaged over the daylight period of the day + #--- Monthly scaling parameters: # Month 1 = January, Month 2 = February, etc. From fa0dcd8204dfee7f7c20ddd5d2c48d3e4d01bcd3 Mon Sep 17 00:00:00 2001 From: Daniel Schlaepfer Date: Mon, 5 Jun 2023 09:07:33 -0400 Subject: [PATCH 13/15] Update SOILWAT2 to latest commit on read_more_daily_input - no change to STEPWAT2 output --- sw_src | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sw_src b/sw_src index 2a980665..62521583 160000 --- a/sw_src +++ b/sw_src @@ -1 +1 @@ -Subproject commit 2a980665f4346c955b872f0820c738bc29c16b6f +Subproject commit 62521583f21b8bd829b3b868fef20da7a7973eda From 0f1d102b9cbb95bab2583d6f632ab1676c225b8d Mon Sep 17 00:00:00 2001 From: Daniel Schlaepfer Date: Mon, 5 Jun 2023 09:28:01 -0400 Subject: [PATCH 14/15] Update SOILWAT2 to latest version on devel_v7.0.0 includes - new daily inputs --- .gitmodules | 2 +- sw_src | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.gitmodules b/.gitmodules index afdbe41d..6a6c0490 100644 --- a/.gitmodules +++ b/.gitmodules @@ -1,5 +1,5 @@ [submodule "sw_src"] path = sw_src url = https://github.com/DrylandEcology/SOILWAT2.git - branch = read_more_daily_input + branch = release/devel_v7.0.0 ignore = dirty diff --git a/sw_src b/sw_src index 62521583..073f89e3 160000 --- a/sw_src +++ b/sw_src @@ -1 +1 @@ -Subproject commit 62521583f21b8bd829b3b868fef20da7a7973eda +Subproject commit 073f89e3aa8352331ef3589fb7373a43d405d778 From 9037e906940abbdeecdbd848ac7411a6770d4583 Mon Sep 17 00:00:00 2001 From: Daniel Schlaepfer Date: Fri, 9 Jun 2023 10:19:05 -0400 Subject: [PATCH 15/15] Finalize branch with update to released SOILWAT2 v7.0.0 --- .gitmodules | 2 +- sw_src | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.gitmodules b/.gitmodules index 6a6c0490..ceda410d 100644 --- a/.gitmodules +++ b/.gitmodules @@ -1,5 +1,5 @@ [submodule "sw_src"] path = sw_src url = https://github.com/DrylandEcology/SOILWAT2.git - branch = release/devel_v7.0.0 + branch = master ignore = dirty diff --git a/sw_src b/sw_src index 073f89e3..34bd4bf6 160000 --- a/sw_src +++ b/sw_src @@ -1 +1 @@ -Subproject commit 073f89e3aa8352331ef3589fb7373a43d405d778 +Subproject commit 34bd4bf69ce9b31f94e639cb1133eeceac1df3df