From 09eaafa108be5ffffec2692cd5252f66daa9d722 Mon Sep 17 00:00:00 2001 From: Nicholas Persley Date: Wed, 26 Jun 2024 22:09:00 -0400 Subject: [PATCH 01/19] Rename SW_ALL to SW_RUN --- include/SW_Control.h | 26 +-- include/SW_Flow.h | 4 +- include/SW_Output.h | 246 +++++++++++------------ include/SW_SoilWater.h | 4 +- include/SW_datastructs.h | 10 +- include/SW_netCDF.h | 2 +- src/SW_Control.c | 66 +++---- src/SW_Flow.c | 4 +- src/SW_Main.c | 4 +- src/SW_Output.c | 276 +++++++++++++------------- src/SW_Output_get_functions.c | 352 ++++++++++++++++----------------- src/SW_SoilWater.c | 6 +- src/SW_netCDF.c | 4 +- tests/gtests/sw_testhelpers.cc | 2 +- tests/gtests/sw_testhelpers.h | 6 +- tests/gtests/test_SW_SpinUp.cc | 4 +- 16 files changed, 508 insertions(+), 508 deletions(-) diff --git a/include/SW_Control.h b/include/SW_Control.h index 0dd5b76e4..08a721385 100644 --- a/include/SW_Control.h +++ b/include/SW_Control.h @@ -19,7 +19,7 @@ #define SW_CONTROL_H #include "include/generic.h" // for Bool -#include "include/SW_datastructs.h" // for SW_ALL, LOG_INFO, SW_DOMAIN, SW_OU... +#include "include/SW_datastructs.h" // for SW_RUN, LOG_INFO, SW_DOMAIN, SW_OU... #ifdef __cplusplus extern "C" { @@ -28,34 +28,34 @@ extern "C" { /* =================================================== */ /* Global Function Declarations */ /* --------------------------------------------------- */ -void SW_CTL_init_ptrs(SW_ALL *sw); +void SW_CTL_init_ptrs(SW_RUN *sw); -void SW_CTL_alloc_outptrs(SW_ALL *sw, LOG_INFO *LogInfo); +void SW_CTL_alloc_outptrs(SW_RUN *sw, LOG_INFO *LogInfo); -void SW_ALL_deepCopy(SW_ALL *source, SW_ALL *dest, LOG_INFO *LogInfo); +void SW_ALL_deepCopy(SW_RUN *source, SW_RUN *dest, LOG_INFO *LogInfo); void SW_CTL_setup_domain( unsigned long userSUID, SW_DOMAIN *SW_Domain, LOG_INFO *LogInfo ); void SW_CTL_setup_model( - SW_ALL *sw, SW_OUTPUT_POINTERS *SW_OutputPtrs, LOG_INFO *LogInfo + SW_RUN *sw, SW_OUTPUT_POINTERS *SW_OutputPtrs, LOG_INFO *LogInfo ); -void SW_CTL_clear_model(Bool full_reset, SW_ALL *sw); +void SW_CTL_clear_model(Bool full_reset, SW_RUN *sw); -void SW_CTL_init_run(SW_ALL *sw, LOG_INFO *LogInfo); +void SW_CTL_init_run(SW_RUN *sw, LOG_INFO *LogInfo); void SW_CTL_read_inputs_from_disk( - SW_ALL *sw, PATH_INFO *PathInfo, LOG_INFO *LogInfo + SW_RUN *sw, PATH_INFO *PathInfo, LOG_INFO *LogInfo ); void SW_CTL_main( - SW_ALL *sw, SW_OUTPUT_POINTERS *SW_OutputPtrs, LOG_INFO *LogInfo + SW_RUN *sw, SW_OUTPUT_POINTERS *SW_OutputPtrs, LOG_INFO *LogInfo ); void SW_CTL_RunSimSet( - SW_ALL *sw_template, + SW_RUN *sw_template, SW_OUTPUT_POINTERS SW_OutputPtrs[], SW_DOMAIN *SW_Domain, SW_WALLTIME *SW_WallTime, @@ -63,13 +63,13 @@ void SW_CTL_RunSimSet( ); void SW_CTL_run_current_year( - SW_ALL *sw, SW_OUTPUT_POINTERS *SW_OutputPtrs, LOG_INFO *LogInfo + SW_RUN *sw, SW_OUTPUT_POINTERS *SW_OutputPtrs, LOG_INFO *LogInfo ); -void SW_CTL_run_spinup(SW_ALL *sw, LOG_INFO *LogInfo); +void SW_CTL_run_spinup(SW_RUN *sw, LOG_INFO *LogInfo); void SW_CTL_run_sw( - SW_ALL *sw_template, + SW_RUN *sw_template, SW_DOMAIN *SW_Domain, unsigned long ncSuid[], SW_OUTPUT_POINTERS SW_OutputPtrs[], diff --git a/include/SW_Flow.h b/include/SW_Flow.h index b4b88e147..a9b3e2991 100644 --- a/include/SW_Flow.h +++ b/include/SW_Flow.h @@ -1,7 +1,7 @@ #ifndef SW_FLOW_H #define SW_FLOW_H -#include "include/SW_datastructs.h" // for SW_ALL, SW_SOILWAT, LOG_INFO +#include "include/SW_datastructs.h" // for SW_RUN, SW_SOILWAT, LOG_INFO #ifdef __cplusplus extern "C" { @@ -12,7 +12,7 @@ extern "C" { /* --------------------------------------------------- */ void SW_FLW_init_run(SW_SOILWAT *SW_SoilWat); -void SW_Water_Flow(SW_ALL *sw, LOG_INFO *LogInfo); +void SW_Water_Flow(SW_RUN *sw, LOG_INFO *LogInfo); #ifdef __cplusplus diff --git a/include/SW_Output.h b/include/SW_Output.h index 6e5f83ca6..cdd265dbc 100644 --- a/include/SW_Output.h +++ b/include/SW_Output.h @@ -76,7 +76,7 @@ #define SW_OUTPUT_H #include "include/generic.h" // for Bool, IntUS -#include "include/SW_datastructs.h" // for SW_ALL, eSW_LastKey, eSW_NoKey +#include "include/SW_datastructs.h" // for SW_RUN, eSW_LastKey, eSW_NoKey #include "include/SW_Defines.h" // for OutPeriod, TimeInt, SW_OUTNMAXVARS #include // for size_t @@ -170,7 +170,7 @@ void SW_OUT_construct( LOG_INFO *LogInfo ); -void SW_OUT_deconstruct(Bool full_reset, SW_ALL *sw); +void SW_OUT_deconstruct(Bool full_reset, SW_RUN *sw); void SW_OUT_set_ncol( int tLayers, @@ -214,7 +214,7 @@ int SW_OUT_read_onekey( ); void SW_OUT_read( - SW_ALL *sw, + SW_RUN *sw, char *InFiles[], OutPeriod timeSteps[][SW_OUTNPERIODS], IntUS *used_OUTNPERIODS, @@ -222,7 +222,7 @@ void SW_OUT_read( ); void SW_OUT_sum_today( - SW_ALL *sw, + SW_RUN *sw, ObjType otyp, Bool bFlush_output, TimeInt tOffset, @@ -230,7 +230,7 @@ void SW_OUT_sum_today( ); void SW_OUT_write_today( - SW_ALL *sw, + SW_RUN *sw, SW_OUTPUT_POINTERS *SW_OutputPtrs, Bool bFlush_output, TimeInt tOffset @@ -239,11 +239,11 @@ void SW_OUT_write_today( void SW_OUT_write_year(void); void SW_OUT_flush( - SW_ALL *sw, SW_OUTPUT_POINTERS *SW_OutputPtrs, LOG_INFO *LogInfo + SW_RUN *sw, SW_OUTPUT_POINTERS *SW_OutputPtrs, LOG_INFO *LogInfo ); void _collect_values( - SW_ALL *sw, + SW_RUN *sw, SW_OUTPUT_POINTERS *SW_OutputPtrs, Bool bFlush_output, TimeInt tOffset, @@ -262,9 +262,9 @@ void SW_OUT_create_files( LOG_INFO *LogInfo ); -void _echo_outputs(SW_ALL *sw); +void _echo_outputs(SW_RUN *sw); -void _echo_all_inputs(SW_ALL *sw); +void _echo_all_inputs(SW_RUN *sw); void find_OutPeriods_inUse(SW_GEN_OUT *GenOutput, SW_OUTPUT *SW_Output); @@ -323,127 +323,127 @@ void SW_OUT_deepCopy( * 05-Mar-03 (cwb) Added code for max,min,avg. Previously, only avg was output. * 22 June-15 (akt) Added code for adding surfaceAvg at output */ -void get_none(OutPeriod pd, SW_ALL *sw); /* default until defined */ +void get_none(OutPeriod pd, SW_RUN *sw); /* default until defined */ #if defined(SW_OUTTEXT) && !defined(SWNETCDF) -void get_temp_text(OutPeriod pd, SW_ALL *sw); -void get_precip_text(OutPeriod pd, SW_ALL *sw); -void get_vwcBulk_text(OutPeriod pd, SW_ALL *sw); -void get_vwcMatric_text(OutPeriod pd, SW_ALL *sw); -void get_swcBulk_text(OutPeriod pd, SW_ALL *sw); -void get_swpMatric_text(OutPeriod pd, SW_ALL *sw); -void get_swaBulk_text(OutPeriod pd, SW_ALL *sw); -void get_swaMatric_text(OutPeriod pd, SW_ALL *sw); -void get_swa_text(OutPeriod pd, SW_ALL *sw); -void get_surfaceWater_text(OutPeriod pd, SW_ALL *sw); -void get_runoffrunon_text(OutPeriod pd, SW_ALL *sw); -void get_transp_text(OutPeriod pd, SW_ALL *sw); -void get_evapSoil_text(OutPeriod pd, SW_ALL *sw); -void get_evapSurface_text(OutPeriod pd, SW_ALL *sw); -void get_interception_text(OutPeriod pd, SW_ALL *sw); -void get_soilinf_text(OutPeriod pd, SW_ALL *sw); -void get_lyrdrain_text(OutPeriod pd, SW_ALL *sw); -void get_hydred_text(OutPeriod pd, SW_ALL *sw); -void get_aet_text(OutPeriod pd, SW_ALL *sw); -void get_pet_text(OutPeriod pd, SW_ALL *sw); -void get_wetdays_text(OutPeriod pd, SW_ALL *sw); -void get_snowpack_text(OutPeriod pd, SW_ALL *sw); -void get_deepswc_text(OutPeriod pd, SW_ALL *sw); -void get_estab_text(OutPeriod pd, SW_ALL *sw); -void get_soiltemp_text(OutPeriod pd, SW_ALL *sw); -void get_frozen_text(OutPeriod pd, SW_ALL *sw); -void get_co2effects_text(OutPeriod pd, SW_ALL *sw); -void get_biomass_text(OutPeriod pd, SW_ALL *sw); +void get_temp_text(OutPeriod pd, SW_RUN *sw); +void get_precip_text(OutPeriod pd, SW_RUN *sw); +void get_vwcBulk_text(OutPeriod pd, SW_RUN *sw); +void get_vwcMatric_text(OutPeriod pd, SW_RUN *sw); +void get_swcBulk_text(OutPeriod pd, SW_RUN *sw); +void get_swpMatric_text(OutPeriod pd, SW_RUN *sw); +void get_swaBulk_text(OutPeriod pd, SW_RUN *sw); +void get_swaMatric_text(OutPeriod pd, SW_RUN *sw); +void get_swa_text(OutPeriod pd, SW_RUN *sw); +void get_surfaceWater_text(OutPeriod pd, SW_RUN *sw); +void get_runoffrunon_text(OutPeriod pd, SW_RUN *sw); +void get_transp_text(OutPeriod pd, SW_RUN *sw); +void get_evapSoil_text(OutPeriod pd, SW_RUN *sw); +void get_evapSurface_text(OutPeriod pd, SW_RUN *sw); +void get_interception_text(OutPeriod pd, SW_RUN *sw); +void get_soilinf_text(OutPeriod pd, SW_RUN *sw); +void get_lyrdrain_text(OutPeriod pd, SW_RUN *sw); +void get_hydred_text(OutPeriod pd, SW_RUN *sw); +void get_aet_text(OutPeriod pd, SW_RUN *sw); +void get_pet_text(OutPeriod pd, SW_RUN *sw); +void get_wetdays_text(OutPeriod pd, SW_RUN *sw); +void get_snowpack_text(OutPeriod pd, SW_RUN *sw); +void get_deepswc_text(OutPeriod pd, SW_RUN *sw); +void get_estab_text(OutPeriod pd, SW_RUN *sw); +void get_soiltemp_text(OutPeriod pd, SW_RUN *sw); +void get_frozen_text(OutPeriod pd, SW_RUN *sw); +void get_co2effects_text(OutPeriod pd, SW_RUN *sw); +void get_biomass_text(OutPeriod pd, SW_RUN *sw); #endif #if defined(RSOILWAT) || defined(SWNETCDF) -void get_temp_mem(OutPeriod pd, SW_ALL *sw); -void get_precip_mem(OutPeriod pd, SW_ALL *sw); -void get_vwcBulk_mem(OutPeriod pd, SW_ALL *sw); -void get_vwcMatric_mem(OutPeriod pd, SW_ALL *sw); -void get_swcBulk_mem(OutPeriod pd, SW_ALL *sw); -void get_swpMatric_mem(OutPeriod pd, SW_ALL *sw); -void get_swaBulk_mem(OutPeriod pd, SW_ALL *sw); -void get_swaMatric_mem(OutPeriod pd, SW_ALL *sw); -void get_swa_mem(OutPeriod pd, SW_ALL *sw); -void get_surfaceWater_mem(OutPeriod pd, SW_ALL *sw); -void get_runoffrunon_mem(OutPeriod pd, SW_ALL *sw); -void get_transp_mem(OutPeriod pd, SW_ALL *sw); -void get_evapSoil_mem(OutPeriod pd, SW_ALL *sw); -void get_evapSurface_mem(OutPeriod pd, SW_ALL *sw); -void get_interception_mem(OutPeriod pd, SW_ALL *sw); -void get_soilinf_mem(OutPeriod pd, SW_ALL *sw); -void get_lyrdrain_mem(OutPeriod pd, SW_ALL *sw); -void get_hydred_mem(OutPeriod pd, SW_ALL *sw); -void get_aet_mem(OutPeriod pd, SW_ALL *sw); -void get_pet_mem(OutPeriod pd, SW_ALL *sw); -void get_wetdays_mem(OutPeriod pd, SW_ALL *sw); -void get_snowpack_mem(OutPeriod pd, SW_ALL *sw); -void get_deepswc_mem(OutPeriod pd, SW_ALL *sw); -void get_estab_mem(OutPeriod pd, SW_ALL *sw); -void get_soiltemp_mem(OutPeriod pd, SW_ALL *sw); -void get_frozen_mem(OutPeriod pd, SW_ALL *sw); -void get_co2effects_mem(OutPeriod pd, SW_ALL *sw); -void get_biomass_mem(OutPeriod pd, SW_ALL *sw); +void get_temp_mem(OutPeriod pd, SW_RUN *sw); +void get_precip_mem(OutPeriod pd, SW_RUN *sw); +void get_vwcBulk_mem(OutPeriod pd, SW_RUN *sw); +void get_vwcMatric_mem(OutPeriod pd, SW_RUN *sw); +void get_swcBulk_mem(OutPeriod pd, SW_RUN *sw); +void get_swpMatric_mem(OutPeriod pd, SW_RUN *sw); +void get_swaBulk_mem(OutPeriod pd, SW_RUN *sw); +void get_swaMatric_mem(OutPeriod pd, SW_RUN *sw); +void get_swa_mem(OutPeriod pd, SW_RUN *sw); +void get_surfaceWater_mem(OutPeriod pd, SW_RUN *sw); +void get_runoffrunon_mem(OutPeriod pd, SW_RUN *sw); +void get_transp_mem(OutPeriod pd, SW_RUN *sw); +void get_evapSoil_mem(OutPeriod pd, SW_RUN *sw); +void get_evapSurface_mem(OutPeriod pd, SW_RUN *sw); +void get_interception_mem(OutPeriod pd, SW_RUN *sw); +void get_soilinf_mem(OutPeriod pd, SW_RUN *sw); +void get_lyrdrain_mem(OutPeriod pd, SW_RUN *sw); +void get_hydred_mem(OutPeriod pd, SW_RUN *sw); +void get_aet_mem(OutPeriod pd, SW_RUN *sw); +void get_pet_mem(OutPeriod pd, SW_RUN *sw); +void get_wetdays_mem(OutPeriod pd, SW_RUN *sw); +void get_snowpack_mem(OutPeriod pd, SW_RUN *sw); +void get_deepswc_mem(OutPeriod pd, SW_RUN *sw); +void get_estab_mem(OutPeriod pd, SW_RUN *sw); +void get_soiltemp_mem(OutPeriod pd, SW_RUN *sw); +void get_frozen_mem(OutPeriod pd, SW_RUN *sw); +void get_co2effects_mem(OutPeriod pd, SW_RUN *sw); +void get_biomass_mem(OutPeriod pd, SW_RUN *sw); #elif defined(STEPWAT) -void get_temp_agg(OutPeriod pd, SW_ALL *sw); -void get_precip_agg(OutPeriod pd, SW_ALL *sw); -void get_vwcBulk_agg(OutPeriod pd, SW_ALL *sw); -void get_vwcMatric_agg(OutPeriod pd, SW_ALL *sw); -void get_swcBulk_agg(OutPeriod pd, SW_ALL *sw); -void get_swpMatric_agg(OutPeriod pd, SW_ALL *sw); -void get_swaBulk_agg(OutPeriod pd, SW_ALL *sw); -void get_swaMatric_agg(OutPeriod pd, SW_ALL *sw); -void get_swa_agg(OutPeriod pd, SW_ALL *sw); -void get_surfaceWater_agg(OutPeriod pd, SW_ALL *sw); -void get_runoffrunon_agg(OutPeriod pd, SW_ALL *sw); -void get_transp_agg(OutPeriod pd, SW_ALL *sw); -void get_evapSoil_agg(OutPeriod pd, SW_ALL *sw); -void get_evapSurface_agg(OutPeriod pd, SW_ALL *sw); -void get_interception_agg(OutPeriod pd, SW_ALL *sw); -void get_soilinf_agg(OutPeriod pd, SW_ALL *sw); -void get_lyrdrain_agg(OutPeriod pd, SW_ALL *sw); -void get_hydred_agg(OutPeriod pd, SW_ALL *sw); -void get_aet_agg(OutPeriod pd, SW_ALL *sw); -void get_pet_agg(OutPeriod pd, SW_ALL *sw); -void get_wetdays_agg(OutPeriod pd, SW_ALL *sw); -void get_snowpack_agg(OutPeriod pd, SW_ALL *sw); -void get_deepswc_agg(OutPeriod pd, SW_ALL *sw); -void get_estab_agg(OutPeriod pd, SW_ALL *sw); -void get_soiltemp_agg(OutPeriod pd, SW_ALL *sw); -void get_frozen_agg(OutPeriod pd, SW_ALL *sw); -void get_co2effects_agg(OutPeriod pd, SW_ALL *sw); -void get_biomass_agg(OutPeriod pd, SW_ALL *sw); - -void get_temp_SXW(OutPeriod pd, SW_ALL *sw); -void get_precip_SXW(OutPeriod pd, SW_ALL *sw); -void get_vwcBulk_SXW(OutPeriod pd, SW_ALL *sw); -void get_vwcMatric_SXW(OutPeriod pd, SW_ALL *sw); -void get_swcBulk_SXW(OutPeriod pd, SW_ALL *sw); -void get_swpMatric_SXW(OutPeriod pd, SW_ALL *sw); -void get_swaBulk_SXW(OutPeriod pd, SW_ALL *sw); -void get_swaMatric_SXW(OutPeriod pd, SW_ALL *sw); -void get_swa_SXW(OutPeriod pd, SW_ALL *sw); -void get_surfaceWater_SXW(OutPeriod pd, SW_ALL *sw); -void get_runoffrunon_SXW(OutPeriod pd, SW_ALL *sw); -void get_transp_SXW(OutPeriod pd, SW_ALL *sw); -void get_evapSoil_SXW(OutPeriod pd, SW_ALL *sw); -void get_evapSurface_SXW(OutPeriod pd, SW_ALL *sw); -void get_interception_SXW(OutPeriod pd, SW_ALL *sw); -void get_soilinf_SXW(OutPeriod pd, SW_ALL *sw); -void get_lyrdrain_SXW(OutPeriod pd, SW_ALL *sw); -void get_hydred_SXW(OutPeriod pd, SW_ALL *sw); -void get_aet_SXW(OutPeriod pd, SW_ALL *sw); -void get_pet_SXW(OutPeriod pd, SW_ALL *sw); -void get_wetdays_SXW(OutPeriod pd, SW_ALL *sw); -void get_snowpack_SXW(OutPeriod pd, SW_ALL *sw); -void get_deepswc_SXW(OutPeriod pd, SW_ALL *sw); -void get_estab_SXW(OutPeriod pd, SW_ALL *sw); -void get_soiltemp_SXW(OutPeriod pd, SW_ALL *sw); -void get_frozen_SXW(OutPeriod pd, SW_ALL *sw); -void get_co2effects_SXW(OutPeriod pd, SW_ALL *sw); -void get_biomass_SXW(OutPeriod pd, SW_ALL *sw); +void get_temp_agg(OutPeriod pd, SW_RUN *sw); +void get_precip_agg(OutPeriod pd, SW_RUN *sw); +void get_vwcBulk_agg(OutPeriod pd, SW_RUN *sw); +void get_vwcMatric_agg(OutPeriod pd, SW_RUN *sw); +void get_swcBulk_agg(OutPeriod pd, SW_RUN *sw); +void get_swpMatric_agg(OutPeriod pd, SW_RUN *sw); +void get_swaBulk_agg(OutPeriod pd, SW_RUN *sw); +void get_swaMatric_agg(OutPeriod pd, SW_RUN *sw); +void get_swa_agg(OutPeriod pd, SW_RUN *sw); +void get_surfaceWater_agg(OutPeriod pd, SW_RUN *sw); +void get_runoffrunon_agg(OutPeriod pd, SW_RUN *sw); +void get_transp_agg(OutPeriod pd, SW_RUN *sw); +void get_evapSoil_agg(OutPeriod pd, SW_RUN *sw); +void get_evapSurface_agg(OutPeriod pd, SW_RUN *sw); +void get_interception_agg(OutPeriod pd, SW_RUN *sw); +void get_soilinf_agg(OutPeriod pd, SW_RUN *sw); +void get_lyrdrain_agg(OutPeriod pd, SW_RUN *sw); +void get_hydred_agg(OutPeriod pd, SW_RUN *sw); +void get_aet_agg(OutPeriod pd, SW_RUN *sw); +void get_pet_agg(OutPeriod pd, SW_RUN *sw); +void get_wetdays_agg(OutPeriod pd, SW_RUN *sw); +void get_snowpack_agg(OutPeriod pd, SW_RUN *sw); +void get_deepswc_agg(OutPeriod pd, SW_RUN *sw); +void get_estab_agg(OutPeriod pd, SW_RUN *sw); +void get_soiltemp_agg(OutPeriod pd, SW_RUN *sw); +void get_frozen_agg(OutPeriod pd, SW_RUN *sw); +void get_co2effects_agg(OutPeriod pd, SW_RUN *sw); +void get_biomass_agg(OutPeriod pd, SW_RUN *sw); + +void get_temp_SXW(OutPeriod pd, SW_RUN *sw); +void get_precip_SXW(OutPeriod pd, SW_RUN *sw); +void get_vwcBulk_SXW(OutPeriod pd, SW_RUN *sw); +void get_vwcMatric_SXW(OutPeriod pd, SW_RUN *sw); +void get_swcBulk_SXW(OutPeriod pd, SW_RUN *sw); +void get_swpMatric_SXW(OutPeriod pd, SW_RUN *sw); +void get_swaBulk_SXW(OutPeriod pd, SW_RUN *sw); +void get_swaMatric_SXW(OutPeriod pd, SW_RUN *sw); +void get_swa_SXW(OutPeriod pd, SW_RUN *sw); +void get_surfaceWater_SXW(OutPeriod pd, SW_RUN *sw); +void get_runoffrunon_SXW(OutPeriod pd, SW_RUN *sw); +void get_transp_SXW(OutPeriod pd, SW_RUN *sw); +void get_evapSoil_SXW(OutPeriod pd, SW_RUN *sw); +void get_evapSurface_SXW(OutPeriod pd, SW_RUN *sw); +void get_interception_SXW(OutPeriod pd, SW_RUN *sw); +void get_soilinf_SXW(OutPeriod pd, SW_RUN *sw); +void get_lyrdrain_SXW(OutPeriod pd, SW_RUN *sw); +void get_hydred_SXW(OutPeriod pd, SW_RUN *sw); +void get_aet_SXW(OutPeriod pd, SW_RUN *sw); +void get_pet_SXW(OutPeriod pd, SW_RUN *sw); +void get_wetdays_SXW(OutPeriod pd, SW_RUN *sw); +void get_snowpack_SXW(OutPeriod pd, SW_RUN *sw); +void get_deepswc_SXW(OutPeriod pd, SW_RUN *sw); +void get_estab_SXW(OutPeriod pd, SW_RUN *sw); +void get_soiltemp_SXW(OutPeriod pd, SW_RUN *sw); +void get_frozen_SXW(OutPeriod pd, SW_RUN *sw); +void get_co2effects_SXW(OutPeriod pd, SW_RUN *sw); +void get_biomass_SXW(OutPeriod pd, SW_RUN *sw); #endif diff --git a/include/SW_SoilWater.h b/include/SW_SoilWater.h index 126e8e681..36d5b0749 100644 --- a/include/SW_SoilWater.h +++ b/include/SW_SoilWater.h @@ -144,7 +144,7 @@ void _read_swc_hist( SW_SOILWAT_HIST *SoilWat_hist, TimeInt year, LOG_INFO *LogInfo ); -void SW_SWC_water_flow(SW_ALL *sw, LOG_INFO *LogInfo); +void SW_SWC_water_flow(SW_RUN *sw, LOG_INFO *LogInfo); void calculate_repartitioned_soilwater( SW_SOILWAT *SW_SoilWat, @@ -255,7 +255,7 @@ double SWRC_SWPtoSWC_FXW( ); #ifdef SWDEBUG -void SW_WaterBalance_Checks(SW_ALL *sw, LOG_INFO *LogInfo); +void SW_WaterBalance_Checks(SW_RUN *sw, LOG_INFO *LogInfo); #endif diff --git a/include/SW_datastructs.h b/include/SW_datastructs.h index 0a21ef1ab..117a274ae 100644 --- a/include/SW_datastructs.h +++ b/include/SW_datastructs.h @@ -1351,7 +1351,7 @@ typedef struct { SW_ATMD AtmDemand; SW_GEN_OUT GenOutput; -} SW_ALL; +} SW_RUN; /* =================================================== */ /* Output struct/enums */ @@ -1361,19 +1361,19 @@ typedef struct { #if defined(SW_OUTTEXT) /** pointer to output routine for text output */ - void (*pfunc_text)(OutPeriod, SW_ALL *); + void (*pfunc_text)(OutPeriod, SW_RUN *); #endif #if defined(RSOILWAT) || defined(SWNETCDF) /** pointer to output routine for array output */ - void (*pfunc_mem)(OutPeriod, SW_ALL *); + void (*pfunc_mem)(OutPeriod, SW_RUN *); #elif defined(STEPWAT) /** pointer to output routine for aggregated output across STEPWAT * iterations */ - void (*pfunc_agg)(OutPeriod, SW_ALL *); + void (*pfunc_agg)(OutPeriod, SW_RUN *); /** pointer to output routine for STEPWAT in-memory output */ - void (*pfunc_SXW)(OutPeriod, SW_ALL *); + void (*pfunc_SXW)(OutPeriod, SW_RUN *); #endif } SW_OUTPUT_POINTERS; diff --git a/include/SW_netCDF.h b/include/SW_netCDF.h index fc2a40dd8..e86cbae0e 100644 --- a/include/SW_netCDF.h +++ b/include/SW_netCDF.h @@ -123,7 +123,7 @@ Bool SW_NC_check_progress( ); void SW_NC_read_inputs( - SW_ALL *sw, SW_DOMAIN *SW_Domain, size_t ncSUID[], LOG_INFO *LogInfo + SW_RUN *sw, SW_DOMAIN *SW_Domain, size_t ncSUID[], LOG_INFO *LogInfo ); void SW_NC_check_input_files(SW_DOMAIN *SW_Domain, LOG_INFO *LogInfo); diff --git a/src/SW_Control.c b/src/SW_Control.c index 869eaff0d..7ec1d7989 100644 --- a/src/SW_Control.c +++ b/src/SW_Control.c @@ -33,7 +33,7 @@ #include "include/myMemory.h" // for Mem_Malloc #include "include/rands.h" // for RandUniIntRange #include "include/SW_Carbon.h" // for SW_CBN_construct, SW_CBN_decons... -#include "include/SW_datastructs.h" // for SW_ALL, LOG_INFO, SW_OUTPUT_POI... +#include "include/SW_datastructs.h" // for SW_RUN, LOG_INFO, SW_OUTPUT_POI... #include "include/SW_Defines.h" // for TimeInt, WallTimeSpec, SW_WRAPU... #include "include/SW_Domain.h" // for SW_DOM_CheckProgress, SW_DOM_Cr... #include "include/SW_Files.h" // for SW_F_construct, SW_F_read, eFirst @@ -69,11 +69,11 @@ In addition to the timekeeper (Model), usually only modules that read input yearly or produce output need to have this call. -@param[in,out] sw Comprehensive struct of type SW_ALL containing all +@param[in,out] sw Comprehensive struct of type SW_RUN containing all information in the simulation @param[out] LogInfo Holds information on warnings and errors */ -static void _begin_year(SW_ALL *sw, LOG_INFO *LogInfo) { +static void _begin_year(SW_RUN *sw, LOG_INFO *LogInfo) { // SW_F_new_year() not needed // call SW_MDL_new_year() first to set up time-related arrays for this year @@ -104,7 +104,7 @@ static void _begin_year(SW_ALL *sw, LOG_INFO *LogInfo) { SW_OUT_new_year(sw->Model.firstdoy, sw->Model.lastdoy, sw->Output); } -static void _begin_day(SW_ALL *sw, LOG_INFO *LogInfo) { +static void _begin_day(SW_RUN *sw, LOG_INFO *LogInfo) { SW_MDL_new_day(&sw->Model); SW_WTH_new_day( &sw->Weather, @@ -117,7 +117,7 @@ static void _begin_day(SW_ALL *sw, LOG_INFO *LogInfo) { } static void _end_day( - SW_ALL *sw, SW_OUTPUT_POINTERS *SW_OutputPtrs, LOG_INFO *LogInfo + SW_RUN *sw, SW_OUTPUT_POINTERS *SW_OutputPtrs, LOG_INFO *LogInfo ) { int localTOffset = 1; // tOffset is one when called from this function @@ -132,13 +132,13 @@ static void _end_day( } /** -@brief Copy dynamic memory from a template SW_ALL to a new instance +@brief Copy dynamic memory from a template SW_RUN to a new instance -@param[in] source Source struct of type SW_ALL to copy -@param[out] dest Destination struct of type SW_ALL to be copied into +@param[in] source Source struct of type SW_RUN to copy +@param[out] dest Destination struct of type SW_RUN to be copied into @param[out] LogInfo Holds information on warnings and errors */ -void SW_ALL_deepCopy(SW_ALL *source, SW_ALL *dest, LOG_INFO *LogInfo) { +void SW_ALL_deepCopy(SW_RUN *source, SW_RUN *dest, LOG_INFO *LogInfo) { memcpy(dest, source, sizeof(*dest)); /* Allocate memory for output pointers */ @@ -229,7 +229,7 @@ void SW_ALL_deepCopy(SW_ALL *source, SW_ALL *dest, LOG_INFO *LogInfo) { @brief Calls 'SW_CTL_run_current_year' for each year which calls 'SW_SWC_water_flow' for each day. -@param[in,out] sw Comprehensive struct of type SW_ALL containing all +@param[in,out] sw Comprehensive struct of type SW_RUN containing all information in the simulation @param[in,out] SW_OutputPtrs SW_OUTPUT_POINTERS of size SW_OUTNKEYS which hold pointers to subroutines for output keys @@ -237,7 +237,7 @@ void SW_ALL_deepCopy(SW_ALL *source, SW_ALL *dest, LOG_INFO *LogInfo) { */ void SW_CTL_main( - SW_ALL *sw, SW_OUTPUT_POINTERS *SW_OutputPtrs, LOG_INFO *LogInfo + SW_RUN *sw, SW_OUTPUT_POINTERS *SW_OutputPtrs, LOG_INFO *LogInfo ) { #ifdef SWDEBUG int debug = 0; @@ -260,7 +260,7 @@ void SW_CTL_main( } /******* End Main Loop *********/ void SW_CTL_RunSimSet( - SW_ALL *sw_template, + SW_RUN *sw_template, SW_OUTPUT_POINTERS SW_OutputPtrs[], SW_DOMAIN *SW_Domain, SW_WALLTIME *SW_WallTime, @@ -370,10 +370,10 @@ void SW_CTL_RunSimSet( @brief Initialize all possible pointers to NULL incase of an unexpected program exit -@param[in,out] sw Comprehensive struct of type SW_ALL containing +@param[in,out] sw Comprehensive struct of type SW_RUN containing all information in the simulation */ -void SW_CTL_init_ptrs(SW_ALL *sw) { +void SW_CTL_init_ptrs(SW_RUN *sw) { SW_WTH_init_ptrs(&sw->Weather); SW_MKV_init_ptrs(&sw->Markov); SW_VES_init_ptrs(&sw->VegEstab); @@ -386,11 +386,11 @@ void SW_CTL_init_ptrs(SW_ALL *sw) { /** @brief Allocate dynamic memory for output aggregate and accumulation pointers -@param[out] sw Comprehensive struct of type SW_ALL containing +@param[out] sw Comprehensive struct of type SW_RUN containing all information in the simulation @param[out] LogInfo Holds information on warnings and errors */ -void SW_CTL_alloc_outptrs(SW_ALL *sw, LOG_INFO *LogInfo) { +void SW_CTL_alloc_outptrs(SW_RUN *sw, LOG_INFO *LogInfo) { SW_VPD_alloc_outptrs(&sw->VegProd, LogInfo); if (LogInfo->stopRun) { return; // Exit prematurely due to error @@ -501,14 +501,14 @@ void SW_CTL_setup_domain( /** @brief Setup and construct model (independent of inputs) -@param[in,out] sw Comprehensive struct of type SW_ALL containing all +@param[in,out] sw Comprehensive struct of type SW_RUN containing all information in the simulation @param[in,out] SW_OutputPtrs SW_OUTPUT_POINTERS of size SW_OUTNKEYS which hold pointers to subroutines for output keys @param[out] LogInfo Holds information on warnings and errors */ void SW_CTL_setup_model( - SW_ALL *sw, SW_OUTPUT_POINTERS *SW_OutputPtrs, LOG_INFO *LogInfo + SW_RUN *sw, SW_OUTPUT_POINTERS *SW_OutputPtrs, LOG_INFO *LogInfo ) { SW_MDL_construct(&sw->Model); SW_WTH_construct(&sw->Weather); @@ -536,7 +536,7 @@ void SW_CTL_setup_model( } /** -@brief Free allocated memory for an SW_ALL instance +@brief Free allocated memory for an SW_RUN instance @param full_reset * If `FALSE`, de-allocate memory for `SOILWAT2` variables, but @@ -547,7 +547,7 @@ void SW_CTL_setup_model( @param[in,out] sw Comprehensive structure holding all information dealt with in SOILWAT2 */ -void SW_CTL_clear_model(Bool full_reset, SW_ALL *sw) { +void SW_CTL_clear_model(Bool full_reset, SW_RUN *sw) { SW_OUT_deconstruct(full_reset, sw); @@ -573,7 +573,7 @@ i.e., after calling _begin_year() dealt with in SOILWAT2 @param[out] LogInfo Holds information on warnings and errors */ -void SW_CTL_init_run(SW_ALL *sw, LOG_INFO *LogInfo) { +void SW_CTL_init_run(SW_RUN *sw, LOG_INFO *LogInfo) { // SW_F_init_run() not needed // SW_MDL_init_run() not needed @@ -614,14 +614,14 @@ void SW_CTL_init_run(SW_ALL *sw, LOG_INFO *LogInfo) { /** @brief Calls 'SW_SWC_water_flow' for each day. -@param[in,out] sw Comprehensive struct of type SW_ALL containing +@param[in,out] sw Comprehensive struct of type SW_RUN containing all information in the simulation @param[in,out] SW_OutputPtrs SW_OUTPUT_POINTERS of size SW_OUTNKEYS which hold pointers to subroutines for output keys @param[out] LogInfo Holds information on warnings and errors */ void SW_CTL_run_current_year( - SW_ALL *sw, SW_OUTPUT_POINTERS *SW_OutputPtrs, LOG_INFO *LogInfo + SW_RUN *sw, SW_OUTPUT_POINTERS *SW_OutputPtrs, LOG_INFO *LogInfo ) { /*=======================================================*/ TimeInt *doy = &sw->Model.doy; // base1 @@ -731,11 +731,11 @@ void SW_CTL_run_current_year( A spin-up duration of 0 returns immediately (no spin-up). -@param[in,out] sw Comprehensive struct of type SW_ALL containing all +@param[in,out] sw Comprehensive struct of type SW_RUN containing all information in the simulation @param[out] LogInfo Holds information dealing with logfile output */ -void SW_CTL_run_spinup(SW_ALL *sw, LOG_INFO *LogInfo) { +void SW_CTL_run_spinup(SW_RUN *sw, LOG_INFO *LogInfo) { if (sw->Model.SW_SpinUp.duration <= 0) { return; @@ -848,14 +848,14 @@ reSet: { @brief Reads inputs from disk and makes a print statement if there is an error in doing so. -@param[in,out] sw Comprehensive struct of type SW_ALL containing +@param[in,out] sw Comprehensive struct of type SW_RUN containing all information in the simulation @param[in,out] PathInfo Struct holding all information about the programs path/files @param[out] LogInfo Holds information on warnings and errors */ void SW_CTL_read_inputs_from_disk( - SW_ALL *sw, PATH_INFO *PathInfo, LOG_INFO *LogInfo + SW_RUN *sw, PATH_INFO *PathInfo, LOG_INFO *LogInfo ) { #ifdef SWDEBUG int debug = 0; @@ -1021,8 +1021,8 @@ void SW_CTL_read_inputs_from_disk( @brief Do an (independent) model simulation run; Don’t fail/crash on error but end early and report to caller -@param[in] sw_template Template SW_ALL for the function to use as a - reference for local versions of SW_ALL +@param[in] sw_template Template SW_RUN for the function to use as a + reference for local versions of SW_RUN @param[in] SW_Domain Struct of type SW_DOMAIN holding constant temporal/spatial information for a set of simulation runs @param[in] ncSuid Unique indentifier of the first suid to run @@ -1032,7 +1032,7 @@ on error but end early and report to caller @param[out] LogInfo Holds information on warnings and errors */ void SW_CTL_run_sw( - SW_ALL *sw_template, + SW_RUN *sw_template, SW_DOMAIN *SW_Domain, unsigned long ncSuid[], SW_OUTPUT_POINTERS SW_OutputPtrs[], @@ -1043,9 +1043,9 @@ void SW_CTL_run_sw( int debug = 0; #endif - SW_ALL local_sw; + SW_RUN local_sw; - // Copy template SW_ALL to local instance + // Copy template SW_RUN to local instance SW_ALL_deepCopy(sw_template, &local_sw, LogInfo); if (LogInfo->stopRun) { goto freeMem; // Free memory and skip simulation run @@ -1093,7 +1093,7 @@ void SW_CTL_run_sw( ); #endif -// Clear local instance of SW_ALL +// Clear local instance of SW_RUN freeMem: SW_CTL_clear_model(swTRUE, &local_sw); diff --git a/src/SW_Flow.c b/src/SW_Flow.c index d9854d5a3..0a99bbdd6 100644 --- a/src/SW_Flow.c +++ b/src/SW_Flow.c @@ -205,7 +205,7 @@ /* --------------------------------------------------- */ #include "include/SW_Flow.h" // for SW_FLW_init_run, SW_Water_Flow #include "include/generic.h" // for RealD, GT, fmax, EQ, fmin -#include "include/SW_datastructs.h" // for LOG_INFO, SW_ALL, SW_SOILWAT +#include "include/SW_datastructs.h" // for LOG_INFO, SW_RUN, SW_SOILWAT #include "include/SW_Defines.h" // for ForEachVegType, NVEGTYPES, ForE... #include "include/SW_Flow_lib.h" // for evap_fromSurface, remove_from_soil #include "include/SW_Flow_lib_PET.h" // for petfunc, solar_radiation @@ -259,7 +259,7 @@ void SW_FLW_init_run(SW_SOILWAT *SW_SoilWat) { /* *************************************************** */ /* The Water Flow */ /* --------------------------------------------------- */ -void SW_Water_Flow(SW_ALL *sw, LOG_INFO *LogInfo) { +void SW_Water_Flow(SW_RUN *sw, LOG_INFO *LogInfo) { #ifdef SWDEBUG IntUS debug = 0, debug_year = 1980, debug_doy = 350; double Eveg, Tveg, HRveg; diff --git a/src/SW_Main.c b/src/SW_Main.c index c4fd7d626..d1eb4074f 100644 --- a/src/SW_Main.c +++ b/src/SW_Main.c @@ -18,7 +18,7 @@ #include "include/filefuncs.h" // for sw_message #include "include/generic.h" // for Bool, swFALSE, swTRUE #include "include/SW_Control.h" // for SW_CTL_RunSimSet, SW_CTL_clear_m... -#include "include/SW_datastructs.h" // for LOG_INFO, SW_ALL, SW_DOMAIN, SW_... +#include "include/SW_datastructs.h" // for LOG_INFO, SW_RUN, SW_DOMAIN, SW_... #include "include/SW_Defines.h" // for SW_OUTNKEYS #include "include/SW_Domain.h" // for SW_DOM_deconstruct, SW_DOM_init_... #include "include/SW_Files.h" // for eFirst @@ -48,7 +48,7 @@ int main(int argc, char **argv) { /* =================================================== */ SW_WALLTIME SW_WallTime; - SW_ALL sw_template; + SW_RUN sw_template; SW_DOMAIN SW_Domain; SW_OUTPUT_POINTERS SW_OutputPtrs[SW_OUTNKEYS]; LOG_INFO LogInfo; diff --git a/src/SW_Output.c b/src/SW_Output.c index 35c04c2f8..4e001e4cf 100644 --- a/src/SW_Output.c +++ b/src/SW_Output.c @@ -35,7 +35,7 @@ See the \ref out_algo "output algorithm documentation" for details. #include "include/filefuncs.h" // for LogError, CloseFile, GetALine #include "include/generic.h" // for IntUS, Bool, LOGERROR, MAX, Str_Co... #include "include/myMemory.h" // for Str_Dup -#include "include/SW_datastructs.h" // for SW_ALL, SW_OUTTEXT, LOG_INFO +#include "include/SW_datastructs.h" // for SW_RUN, SW_OUTTEXT, LOG_INFO #include "include/SW_Defines.h" // for eSWC, OutPeriod, NVEGTYPES #include "include/SW_Files.h" // for eOutput, eSite #include "include/SW_Site.h" // for _echo_inputs @@ -176,7 +176,7 @@ static OutKey str2key(char *s, LOG_INFO *LogInfo); static OutSum str2stype(char *s, LOG_INFO *LogInfo); static void collect_sums( - SW_ALL *sw, + SW_RUN *sw, ObjType otyp, OutPeriod op, OutPeriod timeSteps[][SW_OUTNPERIODS], @@ -207,7 +207,7 @@ static void sumof_vpd( ); static void average_for( - SW_ALL *sw, + SW_RUN *sw, ObjType otyp, OutPeriod pd, Bool bFlush_output, @@ -582,7 +582,7 @@ Enter this routine just after the summary period is completed, so the current week and month will be one greater than the period being summarized. -@param[in,out] sw Comprehensive struct of type SW_ALL containing +@param[in,out] sw Comprehensive struct of type SW_RUN containing all information in the simulation. @param[in] otyp Identifies the current module/object @param[in] pd Time period in simulation output (day/week/month/year) @@ -592,7 +592,7 @@ one greater than the period being summarized. @param[out] LogInfo Holds information on warnings and errors */ static void average_for( - SW_ALL *sw, + SW_RUN *sw, ObjType otyp, OutPeriod pd, Bool bFlush_output, @@ -978,7 +978,7 @@ static void average_for( } static void collect_sums( - SW_ALL *sw, + SW_RUN *sw, ObjType otyp, OutPeriod op, OutPeriod timeSteps[][SW_OUTNPERIODS], @@ -1428,464 +1428,464 @@ void SW_OUT_construct( case eSW_Temp: #if defined(SW_OUTTEXT) SW_OutputPtrs[k].pfunc_text = - (void (*)(OutPeriod, SW_ALL *)) get_temp_text; + (void (*)(OutPeriod, SW_RUN *)) get_temp_text; #endif #if defined(RSOILWAT) || defined(SWNETCDF) SW_OutputPtrs[k].pfunc_mem = - (void (*)(OutPeriod, SW_ALL *)) get_temp_mem; + (void (*)(OutPeriod, SW_RUN *)) get_temp_mem; #elif defined(STEPWAT) SW_OutputPtrs[k].pfunc_agg = - (void (*)(OutPeriod, SW_ALL *)) get_temp_agg; + (void (*)(OutPeriod, SW_RUN *)) get_temp_agg; SW_OutputPtrs[k].pfunc_SXW = - (void (*)(OutPeriod, SW_ALL *)) get_temp_SXW; + (void (*)(OutPeriod, SW_RUN *)) get_temp_SXW; #endif break; case eSW_Precip: #if defined(SW_OUTTEXT) SW_OutputPtrs[k].pfunc_text = - (void (*)(OutPeriod, SW_ALL *)) get_precip_text; + (void (*)(OutPeriod, SW_RUN *)) get_precip_text; #endif #if defined(RSOILWAT) || defined(SWNETCDF) SW_OutputPtrs[k].pfunc_mem = - (void (*)(OutPeriod, SW_ALL *)) get_precip_mem; + (void (*)(OutPeriod, SW_RUN *)) get_precip_mem; #elif defined(STEPWAT) SW_OutputPtrs[k].pfunc_agg = - (void (*)(OutPeriod, SW_ALL *)) get_precip_agg; + (void (*)(OutPeriod, SW_RUN *)) get_precip_agg; SW_OutputPtrs[k].pfunc_SXW = - (void (*)(OutPeriod, SW_ALL *)) get_precip_SXW; + (void (*)(OutPeriod, SW_RUN *)) get_precip_SXW; #endif break; case eSW_VWCBulk: #if defined(SW_OUTTEXT) SW_OutputPtrs[k].pfunc_text = - (void (*)(OutPeriod, SW_ALL *)) get_vwcBulk_text; + (void (*)(OutPeriod, SW_RUN *)) get_vwcBulk_text; #endif #if defined(RSOILWAT) || defined(SWNETCDF) SW_OutputPtrs[k].pfunc_mem = - (void (*)(OutPeriod, SW_ALL *)) get_vwcBulk_mem; + (void (*)(OutPeriod, SW_RUN *)) get_vwcBulk_mem; #elif defined(STEPWAT) SW_OutputPtrs[k].pfunc_agg = - (void (*)(OutPeriod, SW_ALL *)) get_vwcBulk_agg; + (void (*)(OutPeriod, SW_RUN *)) get_vwcBulk_agg; SW_OutputPtrs[k].pfunc_SXW = - (void (*)(OutPeriod, SW_ALL *)) get_none; + (void (*)(OutPeriod, SW_RUN *)) get_none; #endif break; case eSW_VWCMatric: #if defined(SW_OUTTEXT) SW_OutputPtrs[k].pfunc_text = - (void (*)(OutPeriod, SW_ALL *)) get_vwcMatric_text; + (void (*)(OutPeriod, SW_RUN *)) get_vwcMatric_text; #endif #if defined(RSOILWAT) || defined(SWNETCDF) SW_OutputPtrs[k].pfunc_mem = - (void (*)(OutPeriod, SW_ALL *)) get_vwcMatric_mem; + (void (*)(OutPeriod, SW_RUN *)) get_vwcMatric_mem; #elif defined(STEPWAT) SW_OutputPtrs[k].pfunc_agg = - (void (*)(OutPeriod, SW_ALL *)) get_vwcMatric_agg; + (void (*)(OutPeriod, SW_RUN *)) get_vwcMatric_agg; SW_OutputPtrs[k].pfunc_SXW = - (void (*)(OutPeriod, SW_ALL *)) get_none; + (void (*)(OutPeriod, SW_RUN *)) get_none; #endif break; case eSW_SWCBulk: #if defined(SW_OUTTEXT) SW_OutputPtrs[k].pfunc_text = - (void (*)(OutPeriod, SW_ALL *)) get_swcBulk_text; + (void (*)(OutPeriod, SW_RUN *)) get_swcBulk_text; #endif #if defined(RSOILWAT) || defined(SWNETCDF) SW_OutputPtrs[k].pfunc_mem = - (void (*)(OutPeriod, SW_ALL *)) get_swcBulk_mem; + (void (*)(OutPeriod, SW_RUN *)) get_swcBulk_mem; #elif defined(STEPWAT) SW_OutputPtrs[k].pfunc_agg = - (void (*)(OutPeriod, SW_ALL *)) get_swcBulk_agg; + (void (*)(OutPeriod, SW_RUN *)) get_swcBulk_agg; SW_OutputPtrs[k].pfunc_SXW = - (void (*)(OutPeriod, SW_ALL *)) get_swcBulk_SXW; + (void (*)(OutPeriod, SW_RUN *)) get_swcBulk_SXW; #endif break; case eSW_SWPMatric: #if defined(SW_OUTTEXT) SW_OutputPtrs[k].pfunc_text = - (void (*)(OutPeriod, SW_ALL *)) get_swpMatric_text; + (void (*)(OutPeriod, SW_RUN *)) get_swpMatric_text; #endif #if defined(RSOILWAT) || defined(SWNETCDF) SW_OutputPtrs[k].pfunc_mem = - (void (*)(OutPeriod, SW_ALL *)) get_swpMatric_mem; + (void (*)(OutPeriod, SW_RUN *)) get_swpMatric_mem; #elif defined(STEPWAT) SW_OutputPtrs[k].pfunc_agg = - (void (*)(OutPeriod, SW_ALL *)) get_swpMatric_agg; + (void (*)(OutPeriod, SW_RUN *)) get_swpMatric_agg; SW_OutputPtrs[k].pfunc_SXW = - (void (*)(OutPeriod, SW_ALL *)) get_none; + (void (*)(OutPeriod, SW_RUN *)) get_none; #endif break; case eSW_SWABulk: #if defined(SW_OUTTEXT) SW_OutputPtrs[k].pfunc_text = - (void (*)(OutPeriod, SW_ALL *)) get_swaBulk_text; + (void (*)(OutPeriod, SW_RUN *)) get_swaBulk_text; #endif #if defined(RSOILWAT) || defined(SWNETCDF) SW_OutputPtrs[k].pfunc_mem = - (void (*)(OutPeriod, SW_ALL *)) get_swaBulk_mem; + (void (*)(OutPeriod, SW_RUN *)) get_swaBulk_mem; #elif defined(STEPWAT) SW_OutputPtrs[k].pfunc_agg = - (void (*)(OutPeriod, SW_ALL *)) get_swaBulk_agg; + (void (*)(OutPeriod, SW_RUN *)) get_swaBulk_agg; SW_OutputPtrs[k].pfunc_SXW = - (void (*)(OutPeriod, SW_ALL *)) get_none; + (void (*)(OutPeriod, SW_RUN *)) get_none; #endif break; case eSW_SWAMatric: #if defined(SW_OUTTEXT) SW_OutputPtrs[k].pfunc_text = - (void (*)(OutPeriod, SW_ALL *)) get_swaMatric_text; + (void (*)(OutPeriod, SW_RUN *)) get_swaMatric_text; #endif #if defined(RSOILWAT) || defined(SWNETCDF) SW_OutputPtrs[k].pfunc_mem = - (void (*)(OutPeriod, SW_ALL *)) get_swaMatric_mem; + (void (*)(OutPeriod, SW_RUN *)) get_swaMatric_mem; #elif defined(STEPWAT) SW_OutputPtrs[k].pfunc_agg = - (void (*)(OutPeriod, SW_ALL *)) get_swaMatric_agg; + (void (*)(OutPeriod, SW_RUN *)) get_swaMatric_agg; SW_OutputPtrs[k].pfunc_SXW = - (void (*)(OutPeriod, SW_ALL *)) get_none; + (void (*)(OutPeriod, SW_RUN *)) get_none; #endif break; case eSW_SWA: #if defined(SW_OUTTEXT) SW_OutputPtrs[k].pfunc_text = - (void (*)(OutPeriod, SW_ALL *)) get_swa_text; + (void (*)(OutPeriod, SW_RUN *)) get_swa_text; #endif #if defined(RSOILWAT) || defined(SWNETCDF) SW_OutputPtrs[k].pfunc_mem = - (void (*)(OutPeriod, SW_ALL *)) get_swa_mem; + (void (*)(OutPeriod, SW_RUN *)) get_swa_mem; #elif defined(STEPWAT) SW_OutputPtrs[k].pfunc_agg = - (void (*)(OutPeriod, SW_ALL *)) get_swa_agg; + (void (*)(OutPeriod, SW_RUN *)) get_swa_agg; SW_OutputPtrs[k].pfunc_SXW = - (void (*)(OutPeriod, SW_ALL *)) get_none; + (void (*)(OutPeriod, SW_RUN *)) get_none; #endif break; case eSW_SurfaceWater: #if defined(SW_OUTTEXT) SW_OutputPtrs[k].pfunc_text = - (void (*)(OutPeriod, SW_ALL *)) get_surfaceWater_text; + (void (*)(OutPeriod, SW_RUN *)) get_surfaceWater_text; #endif #if defined(RSOILWAT) || defined(SWNETCDF) SW_OutputPtrs[k].pfunc_mem = - (void (*)(OutPeriod, SW_ALL *)) get_surfaceWater_mem; + (void (*)(OutPeriod, SW_RUN *)) get_surfaceWater_mem; #elif defined(STEPWAT) SW_OutputPtrs[k].pfunc_agg = - (void (*)(OutPeriod, SW_ALL *)) get_surfaceWater_agg; + (void (*)(OutPeriod, SW_RUN *)) get_surfaceWater_agg; SW_OutputPtrs[k].pfunc_SXW = - (void (*)(OutPeriod, SW_ALL *)) get_none; + (void (*)(OutPeriod, SW_RUN *)) get_none; #endif break; case eSW_Runoff: #if defined(SW_OUTTEXT) SW_OutputPtrs[k].pfunc_text = - (void (*)(OutPeriod, SW_ALL *)) get_runoffrunon_text; + (void (*)(OutPeriod, SW_RUN *)) get_runoffrunon_text; #endif #if defined(RSOILWAT) || defined(SWNETCDF) SW_OutputPtrs[k].pfunc_mem = - (void (*)(OutPeriod, SW_ALL *)) get_runoffrunon_mem; + (void (*)(OutPeriod, SW_RUN *)) get_runoffrunon_mem; #elif defined(STEPWAT) SW_OutputPtrs[k].pfunc_agg = - (void (*)(OutPeriod, SW_ALL *)) get_runoffrunon_agg; + (void (*)(OutPeriod, SW_RUN *)) get_runoffrunon_agg; SW_OutputPtrs[k].pfunc_SXW = - (void (*)(OutPeriod, SW_ALL *)) get_none; + (void (*)(OutPeriod, SW_RUN *)) get_none; #endif break; case eSW_Transp: #if defined(SW_OUTTEXT) SW_OutputPtrs[k].pfunc_text = - (void (*)(OutPeriod, SW_ALL *)) get_transp_text; + (void (*)(OutPeriod, SW_RUN *)) get_transp_text; #endif #if defined(RSOILWAT) || defined(SWNETCDF) SW_OutputPtrs[k].pfunc_mem = - (void (*)(OutPeriod, SW_ALL *)) get_transp_mem; + (void (*)(OutPeriod, SW_RUN *)) get_transp_mem; #elif defined(STEPWAT) SW_OutputPtrs[k].pfunc_agg = - (void (*)(OutPeriod, SW_ALL *)) get_transp_agg; + (void (*)(OutPeriod, SW_RUN *)) get_transp_agg; SW_OutputPtrs[k].pfunc_SXW = - (void (*)(OutPeriod, SW_ALL *)) get_transp_SXW; + (void (*)(OutPeriod, SW_RUN *)) get_transp_SXW; #endif break; case eSW_EvapSoil: #if defined(SW_OUTTEXT) SW_OutputPtrs[k].pfunc_text = - (void (*)(OutPeriod, SW_ALL *)) get_evapSoil_text; + (void (*)(OutPeriod, SW_RUN *)) get_evapSoil_text; #endif #if defined(RSOILWAT) || defined(SWNETCDF) SW_OutputPtrs[k].pfunc_mem = - (void (*)(OutPeriod, SW_ALL *)) get_evapSoil_mem; + (void (*)(OutPeriod, SW_RUN *)) get_evapSoil_mem; #elif defined(STEPWAT) SW_OutputPtrs[k].pfunc_agg = - (void (*)(OutPeriod, SW_ALL *)) get_evapSoil_agg; + (void (*)(OutPeriod, SW_RUN *)) get_evapSoil_agg; SW_OutputPtrs[k].pfunc_SXW = - (void (*)(OutPeriod, SW_ALL *)) get_none; + (void (*)(OutPeriod, SW_RUN *)) get_none; #endif break; case eSW_EvapSurface: #if defined(SW_OUTTEXT) SW_OutputPtrs[k].pfunc_text = - (void (*)(OutPeriod, SW_ALL *)) get_evapSurface_text; + (void (*)(OutPeriod, SW_RUN *)) get_evapSurface_text; #endif #if defined(RSOILWAT) || defined(SWNETCDF) SW_OutputPtrs[k].pfunc_mem = - (void (*)(OutPeriod, SW_ALL *)) get_evapSurface_mem; + (void (*)(OutPeriod, SW_RUN *)) get_evapSurface_mem; #elif defined(STEPWAT) SW_OutputPtrs[k].pfunc_agg = - (void (*)(OutPeriod, SW_ALL *)) get_evapSurface_agg; + (void (*)(OutPeriod, SW_RUN *)) get_evapSurface_agg; SW_OutputPtrs[k].pfunc_SXW = - (void (*)(OutPeriod, SW_ALL *)) get_none; + (void (*)(OutPeriod, SW_RUN *)) get_none; #endif break; case eSW_Interception: #if defined(SW_OUTTEXT) SW_OutputPtrs[k].pfunc_text = - (void (*)(OutPeriod, SW_ALL *)) get_interception_text; + (void (*)(OutPeriod, SW_RUN *)) get_interception_text; #endif #if defined(RSOILWAT) || defined(SWNETCDF) SW_OutputPtrs[k].pfunc_mem = - (void (*)(OutPeriod, SW_ALL *)) get_interception_mem; + (void (*)(OutPeriod, SW_RUN *)) get_interception_mem; #elif defined(STEPWAT) SW_OutputPtrs[k].pfunc_agg = - (void (*)(OutPeriod, SW_ALL *)) get_interception_agg; + (void (*)(OutPeriod, SW_RUN *)) get_interception_agg; SW_OutputPtrs[k].pfunc_SXW = - (void (*)(OutPeriod, SW_ALL *)) get_none; + (void (*)(OutPeriod, SW_RUN *)) get_none; #endif break; case eSW_SoilInf: #if defined(SW_OUTTEXT) SW_OutputPtrs[k].pfunc_text = - (void (*)(OutPeriod, SW_ALL *)) get_soilinf_text; + (void (*)(OutPeriod, SW_RUN *)) get_soilinf_text; #endif #if defined(RSOILWAT) || defined(SWNETCDF) SW_OutputPtrs[k].pfunc_mem = - (void (*)(OutPeriod, SW_ALL *)) get_soilinf_mem; + (void (*)(OutPeriod, SW_RUN *)) get_soilinf_mem; #elif defined(STEPWAT) SW_OutputPtrs[k].pfunc_agg = - (void (*)(OutPeriod, SW_ALL *)) get_soilinf_agg; + (void (*)(OutPeriod, SW_RUN *)) get_soilinf_agg; SW_OutputPtrs[k].pfunc_SXW = - (void (*)(OutPeriod, SW_ALL *)) get_none; + (void (*)(OutPeriod, SW_RUN *)) get_none; #endif break; case eSW_LyrDrain: #if defined(SW_OUTTEXT) SW_OutputPtrs[k].pfunc_text = - (void (*)(OutPeriod, SW_ALL *)) get_lyrdrain_text; + (void (*)(OutPeriod, SW_RUN *)) get_lyrdrain_text; #endif #if defined(RSOILWAT) || defined(SWNETCDF) SW_OutputPtrs[k].pfunc_mem = - (void (*)(OutPeriod, SW_ALL *)) get_lyrdrain_mem; + (void (*)(OutPeriod, SW_RUN *)) get_lyrdrain_mem; #elif defined(STEPWAT) SW_OutputPtrs[k].pfunc_agg = - (void (*)(OutPeriod, SW_ALL *)) get_lyrdrain_agg; + (void (*)(OutPeriod, SW_RUN *)) get_lyrdrain_agg; SW_OutputPtrs[k].pfunc_SXW = - (void (*)(OutPeriod, SW_ALL *)) get_none; + (void (*)(OutPeriod, SW_RUN *)) get_none; #endif break; case eSW_HydRed: #if defined(SW_OUTTEXT) SW_OutputPtrs[k].pfunc_text = - (void (*)(OutPeriod, SW_ALL *)) get_hydred_text; + (void (*)(OutPeriod, SW_RUN *)) get_hydred_text; #endif #if defined(RSOILWAT) || defined(SWNETCDF) SW_OutputPtrs[k].pfunc_mem = - (void (*)(OutPeriod, SW_ALL *)) get_hydred_mem; + (void (*)(OutPeriod, SW_RUN *)) get_hydred_mem; #elif defined(STEPWAT) SW_OutputPtrs[k].pfunc_agg = - (void (*)(OutPeriod, SW_ALL *)) get_hydred_agg; + (void (*)(OutPeriod, SW_RUN *)) get_hydred_agg; SW_OutputPtrs[k].pfunc_SXW = - (void (*)(OutPeriod, SW_ALL *)) get_none; + (void (*)(OutPeriod, SW_RUN *)) get_none; #endif break; case eSW_AET: #if defined(SW_OUTTEXT) SW_OutputPtrs[k].pfunc_text = - (void (*)(OutPeriod, SW_ALL *)) get_aet_text; + (void (*)(OutPeriod, SW_RUN *)) get_aet_text; #endif #if defined(RSOILWAT) || defined(SWNETCDF) SW_OutputPtrs[k].pfunc_mem = - (void (*)(OutPeriod, SW_ALL *)) get_aet_mem; + (void (*)(OutPeriod, SW_RUN *)) get_aet_mem; #elif defined(STEPWAT) SW_OutputPtrs[k].pfunc_agg = - (void (*)(OutPeriod, SW_ALL *)) get_aet_agg; + (void (*)(OutPeriod, SW_RUN *)) get_aet_agg; SW_OutputPtrs[k].pfunc_SXW = - (void (*)(OutPeriod, SW_ALL *)) get_aet_SXW; + (void (*)(OutPeriod, SW_RUN *)) get_aet_SXW; #endif break; case eSW_PET: #if defined(SW_OUTTEXT) SW_OutputPtrs[k].pfunc_text = - (void (*)(OutPeriod, SW_ALL *)) get_pet_text; + (void (*)(OutPeriod, SW_RUN *)) get_pet_text; #endif #if defined(RSOILWAT) || defined(SWNETCDF) SW_OutputPtrs[k].pfunc_mem = - (void (*)(OutPeriod, SW_ALL *)) get_pet_mem; + (void (*)(OutPeriod, SW_RUN *)) get_pet_mem; #elif defined(STEPWAT) SW_OutputPtrs[k].pfunc_agg = - (void (*)(OutPeriod, SW_ALL *)) get_pet_agg; + (void (*)(OutPeriod, SW_RUN *)) get_pet_agg; SW_OutputPtrs[k].pfunc_SXW = - (void (*)(OutPeriod, SW_ALL *)) get_none; + (void (*)(OutPeriod, SW_RUN *)) get_none; #endif break; case eSW_WetDays: #if defined(SW_OUTTEXT) SW_OutputPtrs[k].pfunc_text = - (void (*)(OutPeriod, SW_ALL *)) get_wetdays_text; + (void (*)(OutPeriod, SW_RUN *)) get_wetdays_text; #endif #if defined(RSOILWAT) || defined(SWNETCDF) SW_OutputPtrs[k].pfunc_mem = - (void (*)(OutPeriod, SW_ALL *)) get_wetdays_mem; + (void (*)(OutPeriod, SW_RUN *)) get_wetdays_mem; #elif defined(STEPWAT) SW_OutputPtrs[k].pfunc_agg = - (void (*)(OutPeriod, SW_ALL *)) get_wetdays_agg; + (void (*)(OutPeriod, SW_RUN *)) get_wetdays_agg; SW_OutputPtrs[k].pfunc_SXW = - (void (*)(OutPeriod, SW_ALL *)) get_none; + (void (*)(OutPeriod, SW_RUN *)) get_none; #endif break; case eSW_SnowPack: #if defined(SW_OUTTEXT) SW_OutputPtrs[k].pfunc_text = - (void (*)(OutPeriod, SW_ALL *)) get_snowpack_text; + (void (*)(OutPeriod, SW_RUN *)) get_snowpack_text; #endif #if defined(RSOILWAT) || defined(SWNETCDF) SW_OutputPtrs[k].pfunc_mem = - (void (*)(OutPeriod, SW_ALL *)) get_snowpack_mem; + (void (*)(OutPeriod, SW_RUN *)) get_snowpack_mem; #elif defined(STEPWAT) SW_OutputPtrs[k].pfunc_agg = - (void (*)(OutPeriod, SW_ALL *)) get_snowpack_agg; + (void (*)(OutPeriod, SW_RUN *)) get_snowpack_agg; SW_OutputPtrs[k].pfunc_SXW = - (void (*)(OutPeriod, SW_ALL *)) get_none; + (void (*)(OutPeriod, SW_RUN *)) get_none; #endif break; case eSW_DeepSWC: #if defined(SW_OUTTEXT) SW_OutputPtrs[k].pfunc_text = - (void (*)(OutPeriod, SW_ALL *)) get_deepswc_text; + (void (*)(OutPeriod, SW_RUN *)) get_deepswc_text; #endif #if defined(RSOILWAT) || defined(SWNETCDF) SW_OutputPtrs[k].pfunc_mem = - (void (*)(OutPeriod, SW_ALL *)) get_deepswc_mem; + (void (*)(OutPeriod, SW_RUN *)) get_deepswc_mem; #elif defined(STEPWAT) SW_OutputPtrs[k].pfunc_agg = - (void (*)(OutPeriod, SW_ALL *)) get_deepswc_agg; + (void (*)(OutPeriod, SW_RUN *)) get_deepswc_agg; SW_OutputPtrs[k].pfunc_SXW = - (void (*)(OutPeriod, SW_ALL *)) get_none; + (void (*)(OutPeriod, SW_RUN *)) get_none; #endif break; case eSW_SoilTemp: #if defined(SW_OUTTEXT) SW_OutputPtrs[k].pfunc_text = - (void (*)(OutPeriod, SW_ALL *)) get_soiltemp_text; + (void (*)(OutPeriod, SW_RUN *)) get_soiltemp_text; #endif #if defined(RSOILWAT) || defined(SWNETCDF) SW_OutputPtrs[k].pfunc_mem = - (void (*)(OutPeriod, SW_ALL *)) get_soiltemp_mem; + (void (*)(OutPeriod, SW_RUN *)) get_soiltemp_mem; #elif defined(STEPWAT) SW_OutputPtrs[k].pfunc_agg = - (void (*)(OutPeriod, SW_ALL *)) get_soiltemp_agg; + (void (*)(OutPeriod, SW_RUN *)) get_soiltemp_agg; SW_OutputPtrs[k].pfunc_SXW = - (void (*)(OutPeriod, SW_ALL *)) get_none; + (void (*)(OutPeriod, SW_RUN *)) get_none; #endif break; case eSW_Frozen: #if defined(SW_OUTTEXT) SW_OutputPtrs[k].pfunc_text = - (void (*)(OutPeriod, SW_ALL *)) get_frozen_text; + (void (*)(OutPeriod, SW_RUN *)) get_frozen_text; #endif #if defined(RSOILWAT) || defined(SWNETCDF) SW_OutputPtrs[k].pfunc_mem = - (void (*)(OutPeriod, SW_ALL *)) get_frozen_mem; + (void (*)(OutPeriod, SW_RUN *)) get_frozen_mem; #elif defined(STEPWAT) SW_OutputPtrs[k].pfunc_agg = - (void (*)(OutPeriod, SW_ALL *)) get_frozen_agg; + (void (*)(OutPeriod, SW_RUN *)) get_frozen_agg; SW_OutputPtrs[k].pfunc_SXW = - (void (*)(OutPeriod, SW_ALL *)) get_none; + (void (*)(OutPeriod, SW_RUN *)) get_none; #endif break; case eSW_Estab: #if defined(SW_OUTTEXT) SW_OutputPtrs[k].pfunc_text = - (void (*)(OutPeriod, SW_ALL *)) get_estab_text; + (void (*)(OutPeriod, SW_RUN *)) get_estab_text; #endif #if defined(RSOILWAT) || defined(SWNETCDF) SW_OutputPtrs[k].pfunc_mem = - (void (*)(OutPeriod, SW_ALL *)) get_estab_mem; + (void (*)(OutPeriod, SW_RUN *)) get_estab_mem; #elif defined(STEPWAT) SW_OutputPtrs[k].pfunc_agg = - (void (*)(OutPeriod, SW_ALL *)) get_estab_agg; + (void (*)(OutPeriod, SW_RUN *)) get_estab_agg; SW_OutputPtrs[k].pfunc_SXW = - (void (*)(OutPeriod, SW_ALL *)) get_none; + (void (*)(OutPeriod, SW_RUN *)) get_none; #endif break; case eSW_CO2Effects: #if defined(SW_OUTTEXT) SW_OutputPtrs[k].pfunc_text = - (void (*)(OutPeriod, SW_ALL *)) get_co2effects_text; + (void (*)(OutPeriod, SW_RUN *)) get_co2effects_text; #endif #if defined(RSOILWAT) || defined(SWNETCDF) SW_OutputPtrs[k].pfunc_mem = - (void (*)(OutPeriod, SW_ALL *)) get_co2effects_mem; + (void (*)(OutPeriod, SW_RUN *)) get_co2effects_mem; #elif defined(STEPWAT) SW_OutputPtrs[k].pfunc_agg = - (void (*)(OutPeriod, SW_ALL *)) get_co2effects_agg; + (void (*)(OutPeriod, SW_RUN *)) get_co2effects_agg; SW_OutputPtrs[k].pfunc_SXW = - (void (*)(OutPeriod, SW_ALL *)) get_none; + (void (*)(OutPeriod, SW_RUN *)) get_none; #endif break; case eSW_Biomass: #if defined(SW_OUTTEXT) SW_OutputPtrs[k].pfunc_text = - (void (*)(OutPeriod, SW_ALL *)) get_biomass_text; + (void (*)(OutPeriod, SW_RUN *)) get_biomass_text; #endif #if defined(RSOILWAT) || defined(SWNETCDF) SW_OutputPtrs[k].pfunc_mem = - (void (*)(OutPeriod, SW_ALL *)) get_biomass_mem; + (void (*)(OutPeriod, SW_RUN *)) get_biomass_mem; #elif defined(STEPWAT) SW_OutputPtrs[k].pfunc_agg = - (void (*)(OutPeriod, SW_ALL *)) get_biomass_agg; + (void (*)(OutPeriod, SW_RUN *)) get_biomass_agg; SW_OutputPtrs[k].pfunc_SXW = - (void (*)(OutPeriod, SW_ALL *)) get_none; + (void (*)(OutPeriod, SW_RUN *)) get_none; #endif break; default: #if defined(SW_OUTTEXT) SW_OutputPtrs[k].pfunc_text = - (void (*)(OutPeriod, SW_ALL *)) get_none; + (void (*)(OutPeriod, SW_RUN *)) get_none; #endif #if defined(RSOILWAT) || defined(SWNETCDF) SW_OutputPtrs[k].pfunc_mem = - (void (*)(OutPeriod, SW_ALL *)) get_none; + (void (*)(OutPeriod, SW_RUN *)) get_none; #elif defined(STEPWAT) SW_OutputPtrs[k].pfunc_agg = - (void (*)(OutPeriod, SW_ALL *)) get_none; + (void (*)(OutPeriod, SW_RUN *)) get_none; SW_OutputPtrs[k].pfunc_SXW = - (void (*)(OutPeriod, SW_ALL *)) get_none; + (void (*)(OutPeriod, SW_RUN *)) get_none; #endif break; } @@ -1903,7 +1903,7 @@ void SW_OUT_construct( #endif } -void SW_OUT_deconstruct(Bool full_reset, SW_ALL *sw) { +void SW_OUT_deconstruct(Bool full_reset, SW_RUN *sw) { IntUS k, i; ForEachOutKey(k) { @@ -2802,7 +2802,7 @@ We have two options to specify time steps: @param[out] LogInfo Holds information on warnings and errors */ void SW_OUT_read( - SW_ALL *sw, + SW_RUN *sw, char *InFiles[], OutPeriod timeSteps[][SW_OUTNPERIODS], IntUS *used_OUTNPERIODS, @@ -3028,7 +3028,7 @@ void SW_OUT_read( } void _collect_values( - SW_ALL *sw, + SW_RUN *sw, SW_OUTPUT_POINTERS *SW_OutputPtrs, Bool bFlush_output, TimeInt tOffset, @@ -3063,14 +3063,14 @@ void _collect_values( This sets two flags: bFlush_output and tOffset to be used in the appropriate subs. -@param[in,out] sw Comprehensive struct of type SW_ALL containing +@param[in,out] sw Comprehensive struct of type SW_RUN containing all information in the simulation @param[in] SW_OutputPtrs SW_OUTPUT_POINTERS of size SW_OUTNKEYS which hold pointers to subroutines for output keys @param[out] LogInfo Holds information on warnings and errors */ void SW_OUT_flush( - SW_ALL *sw, SW_OUTPUT_POINTERS *SW_OutputPtrs, LOG_INFO *LogInfo + SW_RUN *sw, SW_OUTPUT_POINTERS *SW_OutputPtrs, LOG_INFO *LogInfo ) { TimeInt localTOffset = 0; // tOffset is zero when called from this function @@ -3087,7 +3087,7 @@ function. It's more logical to update yesterday just prior to today's calculations, but there's no logical need to perform _new_day() on the soilwater. -@param[in,out] sw Comprehensive struct of type SW_ALL containing +@param[in,out] sw Comprehensive struct of type SW_RUN containing all information in the simulation @param[in] otyp Identifies the current module/object @param[in] bFlush_output Determines if output should be created for @@ -3096,7 +3096,7 @@ need to perform _new_day() on the soilwater. @param[out] LogInfo Holds information on warnings and errors */ void SW_OUT_sum_today( - SW_ALL *sw, + SW_RUN *sw, ObjType otyp, Bool bFlush_output, TimeInt tOffset, @@ -3163,7 +3163,7 @@ void SW_OUT_sum_today( - `SW_OUT_flush` at the end of every year with values of `bFlush_output` set to TRUE and `tOffset` set to 0 -@param[in] sw Comprehensive struct of type SW_ALL containing all +@param[in] sw Comprehensive struct of type SW_RUN containing all information in the simulation @param[in] SW_OutputPtrs SW_OUTPUT_POINTERS of size SW_OUTNKEYS which hold pointers to subroutines for output keys @@ -3172,7 +3172,7 @@ void SW_OUT_sum_today( @param[in] tOffset Offset describing with the previous or current period */ void SW_OUT_write_today( - SW_ALL *sw, + SW_RUN *sw, SW_OUTPUT_POINTERS *SW_OutputPtrs, Bool bFlush_output, TimeInt tOffset @@ -3310,7 +3310,7 @@ void SW_OUT_write_today( } #endif - ((void (*)(OutPeriod, SW_ALL *)) SW_OutputPtrs[k].pfunc_text)( + ((void (*)(OutPeriod, SW_RUN *)) SW_OutputPtrs[k].pfunc_text)( outPeriod, sw ); @@ -3322,7 +3322,7 @@ void SW_OUT_write_today( ); } #endif - ((void (*)(OutPeriod, SW_ALL *)) SW_OutputPtrs[k].pfunc_mem)( + ((void (*)(OutPeriod, SW_RUN *)) SW_OutputPtrs[k].pfunc_mem)( outPeriod, sw ); @@ -3337,7 +3337,7 @@ void SW_OUT_write_today( ); } #endif - ((void (*)(OutPeriod, SW_ALL *)) SW_OutputPtrs[k].pfunc_SXW)( + ((void (*)(OutPeriod, SW_RUN *)) SW_OutputPtrs[k].pfunc_SXW)( sw->GenOutput.timeSteps_SXW[k][i], sw ); } @@ -3355,7 +3355,7 @@ void SW_OUT_write_today( ); } #endif - ((void (*)(OutPeriod, SW_ALL *)) SW_OutputPtrs[k] + ((void (*)(OutPeriod, SW_RUN *)) SW_OutputPtrs[k] .pfunc_agg)(outPeriod, sw); } @@ -3370,7 +3370,7 @@ void SW_OUT_write_today( ); } #endif - ((void (*)(OutPeriod, SW_ALL *)) SW_OutputPtrs[k] + ((void (*)(OutPeriod, SW_RUN *)) SW_OutputPtrs[k] .pfunc_text)(outPeriod, sw); } } @@ -3579,7 +3579,7 @@ void SW_OUT_close_files( #endif } -void _echo_outputs(SW_ALL *sw) { +void _echo_outputs(SW_RUN *sw) { IntUS k; char str[OUTSTRLEN], errstr[MAX_ERROR]; @@ -3612,7 +3612,7 @@ void _echo_outputs(SW_ALL *sw) { printf("%s\n", errstr); } -void _echo_all_inputs(SW_ALL *sw) { +void _echo_all_inputs(SW_RUN *sw) { if (!sw->VegEstab.use) { printf("Establishment not used.\n"); diff --git a/src/SW_Output_get_functions.c b/src/SW_Output_get_functions.c index 03ec0f9d3..f674ad036 100644 --- a/src/SW_Output_get_functions.c +++ b/src/SW_Output_get_functions.c @@ -19,7 +19,7 @@ See the \ref out_algo "output algorithm documentation" for details. /* --------------------------------------------------- */ #include "include/generic.h" // for RealD, IntU -#include "include/SW_datastructs.h" // for SW_ALL, SW_OUTTEXT, SW_GEN_OUT +#include "include/SW_datastructs.h" // for SW_RUN, SW_OUTTEXT, SW_GEN_OUT #include "include/SW_Defines.h" // for _OUTSEP, OUT_DIGITS, OUTSTRLEN #include "include/SW_Output.h" // for get_aet_text, get_biomass_text #include "include/SW_SoilWater.h" // for SW_SWRC_SWCtoSWP @@ -46,7 +46,7 @@ See the \ref out_algo "output algorithm documentation" for details. #ifdef STEPWAT static void format_IterationSummary( - RealD *p, RealD *psd, OutPeriod pd, IntUS N, SW_ALL *sw + RealD *p, RealD *psd, OutPeriod pd, IntUS N, SW_RUN *sw ) { IntUS i; size_t n; @@ -74,7 +74,7 @@ static void format_IterationSummary( } static void format_IterationSummary2( - RealD *p, RealD *psd, OutPeriod pd, IntUS N1, IntUS offset, SW_ALL *sw + RealD *p, RealD *psd, OutPeriod pd, IntUS N1, IntUS offset, SW_RUN *sw ) { IntUS k, i; size_t n; @@ -120,10 +120,10 @@ This just gives the main output loop something to call, rather than an empty pointer. @param[in] pd Time period in simulation output (day/week/month/year) -@param[in] sw Comprehensive struct of type SW_ALL containing all information +@param[in] sw Comprehensive struct of type SW_RUN containing all information in the simulation. */ -void get_none(OutPeriod pd, SW_ALL *sw) { +void get_none(OutPeriod pd, SW_RUN *sw) { (void) pd; (void) sw; // Coerce to void to silence compiler } @@ -136,10 +136,10 @@ void get_none(OutPeriod pd, SW_ALL *sw) { dealing with OUTTEXT. @param[in] pd Time period in simulation output (day/week/month/year) -@param[in] sw Comprehensive struct of type SW_ALL containing all information +@param[in] sw Comprehensive struct of type SW_RUN containing all information in the simulation. */ -void get_co2effects_text(OutPeriod pd, SW_ALL *sw) { +void get_co2effects_text(OutPeriod pd, SW_RUN *sw) { int k; SW_GEN_OUT *go = &sw->GenOutput; @@ -175,7 +175,7 @@ void get_co2effects_text(OutPeriod pd, SW_ALL *sw) { #endif #if defined(RSOILWAT) || defined(SWNETCDF) -void get_co2effects_mem(OutPeriod pd, SW_ALL *sw) { +void get_co2effects_mem(OutPeriod pd, SW_RUN *sw) { int k; size_t iOUTIndex = 0; SW_GEN_OUT *go = &sw->GenOutput; @@ -220,7 +220,7 @@ void get_co2effects_mem(OutPeriod pd, SW_ALL *sw) { } #elif defined(STEPWAT) -void get_co2effects_agg(OutPeriod pd, SW_ALL *sw) { +void get_co2effects_agg(OutPeriod pd, SW_RUN *sw) { int k; size_t iOUTIndex = 0; SW_GEN_OUT *go = &sw->GenOutput; @@ -261,7 +261,7 @@ void get_co2effects_agg(OutPeriod pd, SW_ALL *sw) { //------ eSW_Biomass #ifdef SW_OUTTEXT -void get_biomass_text(OutPeriod pd, SW_ALL *sw) { +void get_biomass_text(OutPeriod pd, SW_RUN *sw) { int k; SW_VEGPROD_OUTPUTS *vo = sw->VegProd.p_oagg[pd]; SW_GEN_OUT *go = &sw->GenOutput; @@ -330,7 +330,7 @@ void get_biomass_text(OutPeriod pd, SW_ALL *sw) { #endif #if defined(RSOILWAT) || defined(SWNETCDF) -void get_biomass_mem(OutPeriod pd, SW_ALL *sw) { +void get_biomass_mem(OutPeriod pd, SW_RUN *sw) { int k; SW_VEGPROD_OUTPUTS *vo = sw->VegProd.p_oagg[pd]; size_t iOUTIndex = 0; @@ -473,7 +473,7 @@ void get_biomass_mem(OutPeriod pd, SW_ALL *sw) { } #elif defined(STEPWAT) -void get_biomass_agg(OutPeriod pd, SW_ALL *sw) { +void get_biomass_agg(OutPeriod pd, SW_RUN *sw) { int k, i; SW_VEGPROD_OUTPUTS *vo = sw->VegProd.p_oagg[pd]; size_t iOUTIndex = 0; @@ -559,10 +559,10 @@ The value will be the day that the species established, or - if it didn't establish this year. This check is for OUTTEXT. @param[in] pd Time period in simulation output (day/week/month/year) -@param[in] sw Comprehensive struct of type SW_ALL containing all information +@param[in] sw Comprehensive struct of type SW_RUN containing all information in the simulation. */ -void get_estab_text(OutPeriod pd, SW_ALL *sw) { +void get_estab_text(OutPeriod pd, SW_RUN *sw) { IntU i; SW_GEN_OUT *go = &sw->GenOutput; @@ -591,10 +591,10 @@ The value will be the day that the species established, or - if it didn't establish this year. This check is for RSOILWAT. @param[in] pd Time period in simulation output (day/week/month/year) -@param[in] sw Comprehensive struct of type SW_ALL containing all information +@param[in] sw Comprehensive struct of type SW_RUN containing all information in the simulation. */ -void get_estab_mem(OutPeriod pd, SW_ALL *sw) { +void get_estab_mem(OutPeriod pd, SW_RUN *sw) { IntU i; size_t iOUTIndex = 0; SW_GEN_OUT *go = &sw->GenOutput; @@ -632,10 +632,10 @@ The value will be the day that the species established, or - if it didn't establish this year. This check is for STEPWAT. @param[in] pd Time period in simulation output (day/week/month/year) -@param[in] sw Comprehensive struct of type SW_ALL containing all information +@param[in] sw Comprehensive struct of type SW_RUN containing all information in the simulation. */ -void get_estab_agg(OutPeriod pd, SW_ALL *sw) { +void get_estab_agg(OutPeriod pd, SW_RUN *sw) { IntU i; size_t iOUTIndex = 0; SW_GEN_OUT *go = &sw->GenOutput; @@ -665,10 +665,10 @@ void get_estab_agg(OutPeriod pd, SW_ALL *sw) { @brief Gets temp text from SW_WEATHER_OUTPUTS when dealing with OUTTEXT. @param[in] pd Time period in simulation output (day/week/month/year) -@param[in] sw Comprehensive struct of type SW_ALL containing all information +@param[in] sw Comprehensive struct of type SW_RUN containing all information in the simulation */ -void get_temp_text(OutPeriod pd, SW_ALL *sw) { +void get_temp_text(OutPeriod pd, SW_RUN *sw) { SW_WEATHER_OUTPUTS *vo = sw->Weather.p_oagg[pd]; SW_GEN_OUT *go = &sw->GenOutput; @@ -705,10 +705,10 @@ void get_temp_text(OutPeriod pd, SW_ALL *sw) { @brief Gets temp text from SW_WEATHER_OUTPUTS when dealing with RSOILWAT. @param pd Period. -@param[in] sw Comprehensive struct of type SW_ALL containing all information +@param[in] sw Comprehensive struct of type SW_RUN containing all information in the simulation */ -void get_temp_mem(OutPeriod pd, SW_ALL *sw) { +void get_temp_mem(OutPeriod pd, SW_RUN *sw) { SW_WEATHER_OUTPUTS *vo = sw->Weather.p_oagg[pd]; size_t iOUTIndex = 0; SW_GEN_OUT *go = &sw->GenOutput; @@ -793,10 +793,10 @@ void get_temp_mem(OutPeriod pd, SW_ALL *sw) { @brief Gets temp text from SW_WEATHER_OUTPUTS when dealing with STEPWAT. @param[in] pd Time period in simulation output (day/week/month/year) -@param[in] sw Comprehensive struct of type SW_ALL containing all information +@param[in] sw Comprehensive struct of type SW_RUN containing all information in the simulation. */ -void get_temp_agg(OutPeriod pd, SW_ALL *sw) { +void get_temp_agg(OutPeriod pd, SW_RUN *sw) { SW_WEATHER_OUTPUTS *vo = sw->Weather.p_oagg[pd]; size_t iOUTIndex = 0; SW_GEN_OUT *go = &sw->GenOutput; @@ -831,10 +831,10 @@ void get_temp_agg(OutPeriod pd, SW_ALL *sw) { @brief STEPWAT2 expects annual mean air temperature @param[in] pd Time period in simulation output (day/week/month/year) -@param[in] sw Comprehensive struct of type SW_ALL containing all information +@param[in] sw Comprehensive struct of type SW_RUN containing all information in the simulation. */ -void get_temp_SXW(OutPeriod pd, SW_ALL *sw) { +void get_temp_SXW(OutPeriod pd, SW_RUN *sw) { TimeInt tOffset; if (pd == eSW_Month || pd == eSW_Year) { @@ -860,10 +860,10 @@ void get_temp_SXW(OutPeriod pd, SW_ALL *sw) { OUTTEXT. @param[in] pd Time period in simulation output (day/week/month/year) -@param[in] sw Comprehensive struct of type SW_ALL containing all information +@param[in] sw Comprehensive struct of type SW_RUN containing all information in the simulation. */ -void get_precip_text(OutPeriod pd, SW_ALL *sw) { +void get_precip_text(OutPeriod pd, SW_RUN *sw) { SW_WEATHER_OUTPUTS *vo = sw->Weather.p_oagg[pd]; SW_GEN_OUT *go = &sw->GenOutput; @@ -898,10 +898,10 @@ void get_precip_text(OutPeriod pd, SW_ALL *sw) { RSOILWAT. @param[in] pd Time period in simulation output (day/week/month/year) -@param[in] sw Comprehensive struct of type SW_ALL containing all information +@param[in] sw Comprehensive struct of type SW_RUN containing all information in the simulation. */ -void get_precip_mem(OutPeriod pd, SW_ALL *sw) { +void get_precip_mem(OutPeriod pd, SW_RUN *sw) { SW_WEATHER_OUTPUTS *vo = sw->Weather.p_oagg[pd]; size_t iOUTIndex = 0; SW_GEN_OUT *go = &sw->GenOutput; @@ -976,10 +976,10 @@ void get_precip_mem(OutPeriod pd, SW_ALL *sw) { STEPWAT. @param[in] pd Time period in simulation output (day/week/month/year) -@param[in] sw Comprehensive struct of type SW_ALL containing all information +@param[in] sw Comprehensive struct of type SW_RUN containing all information in the simulation. */ -void get_precip_agg(OutPeriod pd, SW_ALL *sw) { +void get_precip_agg(OutPeriod pd, SW_RUN *sw) { SW_WEATHER_OUTPUTS *vo = sw->Weather.p_oagg[pd]; size_t iOUTIndex = 0; SW_GEN_OUT *go = &sw->GenOutput; @@ -1011,10 +1011,10 @@ void get_precip_agg(OutPeriod pd, SW_ALL *sw) { @brief STEPWAT2 expects monthly and annual sum of precipitation @param[in] pd Time period in simulation output (day/week/month/year) -@param[in] sw Comprehensive struct of type SW_ALL containing all information +@param[in] sw Comprehensive struct of type SW_RUN containing all information in the simulation. */ -void get_precip_SXW(OutPeriod pd, SW_ALL *sw) { +void get_precip_SXW(OutPeriod pd, SW_RUN *sw) { TimeInt tOffset; if (pd == eSW_Month || pd == eSW_Year) { @@ -1038,10 +1038,10 @@ void get_precip_SXW(OutPeriod pd, SW_ALL *sw) { @brief Gets vwcBulk text from SW_SOILWAT_OUTPUTS when dealing with OUTTEXT. @param[in] pd Time period in simulation output (day/week/month/year) -@param[in] sw Comprehensive struct of type SW_ALL containing all information +@param[in] sw Comprehensive struct of type SW_RUN containing all information in the simulation. */ -void get_vwcBulk_text(OutPeriod pd, SW_ALL *sw) { +void get_vwcBulk_text(OutPeriod pd, SW_RUN *sw) { LyrIndex i; SW_SOILWAT_OUTPUTS *vo = sw->SoilWat.p_oagg[pd]; SW_GEN_OUT *go = &sw->GenOutput; @@ -1070,10 +1070,10 @@ void get_vwcBulk_text(OutPeriod pd, SW_ALL *sw) { @brief Gets vwcBulk text from SW_SOILWAT_OUTPUTS when dealing with RSOILWAT. @param[in] pd Time period in simulation output (day/week/month/year) -@param[in] sw Comprehensive struct of type SW_ALL containing all information +@param[in] sw Comprehensive struct of type SW_RUN containing all information in the simulation. */ -void get_vwcBulk_mem(OutPeriod pd, SW_ALL *sw) { +void get_vwcBulk_mem(OutPeriod pd, SW_RUN *sw) { LyrIndex i; SW_SOILWAT_OUTPUTS *vo = sw->SoilWat.p_oagg[pd]; size_t iOUTIndex = 0; @@ -1119,10 +1119,10 @@ void get_vwcBulk_mem(OutPeriod pd, SW_ALL *sw) { @brief Gets vwcBulk text from SW_SOILWAT_OUTPUTS when dealing with STEPWAT. @param[in] pd Time period in simulation output (day/week/month/year) -@param[in] sw Comprehensive struct of type SW_ALL containing all information +@param[in] sw Comprehensive struct of type SW_RUN containing all information in the simulation. */ -void get_vwcBulk_agg(OutPeriod pd, SW_ALL *sw) { +void get_vwcBulk_agg(OutPeriod pd, SW_RUN *sw) { LyrIndex i; SW_SOILWAT_OUTPUTS *vo = sw->SoilWat.p_oagg[pd]; size_t iOUTIndex = 0; @@ -1154,10 +1154,10 @@ void get_vwcBulk_agg(OutPeriod pd, SW_ALL *sw) { @brief Gets vwcMatric text from SW_SOILWAT_OUTPUTS when dealing with OUTTEXT. @param[in] pd Time period in simulation output (day/week/month/year) -@param[in] sw Comprehensive struct of type SW_ALL containing all information +@param[in] sw Comprehensive struct of type SW_RUN containing all information in the simulation. */ -void get_vwcMatric_text(OutPeriod pd, SW_ALL *sw) { +void get_vwcMatric_text(OutPeriod pd, SW_RUN *sw) { LyrIndex i; RealD convert; SW_SOILWAT_OUTPUTS *vo = sw->SoilWat.p_oagg[pd]; @@ -1190,10 +1190,10 @@ void get_vwcMatric_text(OutPeriod pd, SW_ALL *sw) { @brief Gets vwcMatric text from SW_SOILWAT_OUTPUTS when dealing with RSOILWAT. @param[in] pd Time period in simulation output (day/week/month/year) -@param[in] sw Comprehensive struct of type SW_ALL containing all information +@param[in] sw Comprehensive struct of type SW_RUN containing all information in the simulation. */ -void get_vwcMatric_mem(OutPeriod pd, SW_ALL *sw) { +void get_vwcMatric_mem(OutPeriod pd, SW_RUN *sw) { LyrIndex i; RealD convert; SW_SOILWAT_OUTPUTS *vo = sw->SoilWat.p_oagg[pd]; @@ -1242,10 +1242,10 @@ void get_vwcMatric_mem(OutPeriod pd, SW_ALL *sw) { @brief Gets vwcMatric text from SW_SOILWAT_OUTPUTS when dealing with STEPWAT. @param[in] pd Time period in simulation output (day/week/month/year) -@param[in] sw Comprehensive struct of type SW_ALL containing all information +@param[in] sw Comprehensive struct of type SW_RUN containing all information in the simulation. */ -void get_vwcMatric_agg(OutPeriod pd, SW_ALL *sw) { +void get_vwcMatric_agg(OutPeriod pd, SW_RUN *sw) { LyrIndex i; RealD convert; SW_SOILWAT_OUTPUTS *vo = sw->SoilWat.p_oagg[pd]; @@ -1282,10 +1282,10 @@ void get_vwcMatric_agg(OutPeriod pd, SW_ALL *sw) { @brief Gets SWA text from SW_SOILWAT_OUTPUTS when dealing with OUTTEXT. @param[in] pd Time period in simulation output (day/week/month/year) -@param[in] sw Comprehensive struct of type SW_ALL containing all information +@param[in] sw Comprehensive struct of type SW_RUN containing all information in the simulation. */ -void get_swa_text(OutPeriod pd, SW_ALL *sw) { +void get_swa_text(OutPeriod pd, SW_RUN *sw) { /* added 21-Oct-03, cwb */ LyrIndex i; int k; @@ -1317,10 +1317,10 @@ void get_swa_text(OutPeriod pd, SW_ALL *sw) { @brief Gets SWA text from SW_SOILWAT_OUTPUTS when dealing with RSOILWAT. @param[in] pd Time period in simulation output (day/week/month/year) -@param[in] sw Comprehensive struct of type SW_ALL containing all information +@param[in] sw Comprehensive struct of type SW_RUN containing all information in the simulation. */ -void get_swa_mem(OutPeriod pd, SW_ALL *sw) { +void get_swa_mem(OutPeriod pd, SW_RUN *sw) { LyrIndex i; int k; SW_SOILWAT_OUTPUTS *vo = sw->SoilWat.p_oagg[pd]; @@ -1379,10 +1379,10 @@ void get_swa_mem(OutPeriod pd, SW_ALL *sw) { @brief Gets SWA text from SW_SOILWAT_OUTPUTS when dealing with STEPWAT. @param[in] pd Time period in simulation output (day/week/month/year) -@param[in] sw Comprehensive struct of type SW_ALL containing all information +@param[in] sw Comprehensive struct of type SW_RUN containing all information in the simulation. */ -void get_swa_agg(OutPeriod pd, SW_ALL *sw) { +void get_swa_agg(OutPeriod pd, SW_RUN *sw) { LyrIndex i; int k; SW_SOILWAT_OUTPUTS *vo = sw->SoilWat.p_oagg[pd]; @@ -1415,10 +1415,10 @@ void get_swa_agg(OutPeriod pd, SW_ALL *sw) { @brief Gets swcBulk text from SW_SOILWAT_OUTPUTS when dealing with OUTTEXT. @param[in] pd Time period in simulation output (day/week/month/year) -@param[in] sw Comprehensive struct of type SW_ALL containing all information +@param[in] sw Comprehensive struct of type SW_RUN containing all information in the simulation. */ -void get_swcBulk_text(OutPeriod pd, SW_ALL *sw) { +void get_swcBulk_text(OutPeriod pd, SW_RUN *sw) { /* added 21-Oct-03, cwb */ LyrIndex i; SW_SOILWAT_OUTPUTS *vo = sw->SoilWat.p_oagg[pd]; @@ -1440,10 +1440,10 @@ void get_swcBulk_text(OutPeriod pd, SW_ALL *sw) { @brief Gets swcBulk text from SW_SOILWAT_OUTPUTS when dealing with RSOILWAT. @param[in] pd Time period in simulation output (day/week/month/year) -@param[in] sw Comprehensive struct of type SW_ALL containing all information +@param[in] sw Comprehensive struct of type SW_RUN containing all information in the simulation. */ -void get_swcBulk_mem(OutPeriod pd, SW_ALL *sw) { +void get_swcBulk_mem(OutPeriod pd, SW_RUN *sw) { LyrIndex i; SW_SOILWAT_OUTPUTS *vo = sw->SoilWat.p_oagg[pd]; size_t iOUTIndex = 0; @@ -1488,10 +1488,10 @@ void get_swcBulk_mem(OutPeriod pd, SW_ALL *sw) { @brief Gets swcBulk text from SW_SOILWAT_OUTPUTS when dealing with STEPWAT. @param[in] pd Time period in simulation output (day/week/month/year) -@param[in] sw Comprehensive struct of type SW_ALL containing all information +@param[in] sw Comprehensive struct of type SW_RUN containing all information in the simulation. */ -void get_swcBulk_agg(OutPeriod pd, SW_ALL *sw) { +void get_swcBulk_agg(OutPeriod pd, SW_RUN *sw) { LyrIndex i; SW_SOILWAT_OUTPUTS *vo = sw->SoilWat.p_oagg[pd]; size_t iOUTIndex = 0; @@ -1515,10 +1515,10 @@ void get_swcBulk_agg(OutPeriod pd, SW_ALL *sw) { @brief STEPWAT2 expects monthly mean SWCbulk by soil layer. @param[in] pd Time period in simulation output (day/week/month/year) -@param[in] sw Comprehensive struct of type SW_ALL containing all information +@param[in] sw Comprehensive struct of type SW_RUN containing all information in the simulation. */ -void get_swcBulk_SXW(OutPeriod pd, SW_ALL *sw) { +void get_swcBulk_SXW(OutPeriod pd, SW_RUN *sw) { TimeInt month; if (pd == eSW_Month) { @@ -1545,10 +1545,10 @@ other average is better and fix this) we're not averaging swp but converting the averged swc. This also avoids converting for each day. added 12-Oct-03, cwb @param[in] pd Time period in simulation output (day/week/month/year) -@param[in] sw Comprehensive struct of type SW_ALL containing all information +@param[in] sw Comprehensive struct of type SW_RUN containing all information in the simulation. */ -void get_swpMatric_text(OutPeriod pd, SW_ALL *sw) { +void get_swpMatric_text(OutPeriod pd, SW_RUN *sw) { RealD val; LyrIndex i; SW_SOILWAT_OUTPUTS *vo = sw->SoilWat.p_oagg[pd]; @@ -1578,10 +1578,10 @@ void get_swpMatric_text(OutPeriod pd, SW_ALL *sw) { @brief Gets swpMatric when dealing with RSOILWAT @param[in] pd Time period in simulation output (day/week/month/year) -@param[in] sw Comprehensive struct of type SW_ALL containing all information +@param[in] sw Comprehensive struct of type SW_RUN containing all information in the simulation. */ -void get_swpMatric_mem(OutPeriod pd, SW_ALL *sw) { +void get_swpMatric_mem(OutPeriod pd, SW_RUN *sw) { LyrIndex i; SW_SOILWAT_OUTPUTS *vo = sw->SoilWat.p_oagg[pd]; LOG_INFO local_log; @@ -1629,10 +1629,10 @@ void get_swpMatric_mem(OutPeriod pd, SW_ALL *sw) { @brief Gets swpMatric when dealing with STEPWAT. @param[in] pd Time period in simulation output (day/week/month/year) -@param[in] sw Comprehensive struct of type SW_ALL containing all information +@param[in] sw Comprehensive struct of type SW_RUN containing all information in the simulation. */ -void get_swpMatric_agg(OutPeriod pd, SW_ALL *sw) { +void get_swpMatric_agg(OutPeriod pd, SW_RUN *sw) { RealD val; LyrIndex i; SW_SOILWAT_OUTPUTS *vo = sw->SoilWat.p_oagg[pd]; @@ -1667,10 +1667,10 @@ void get_swpMatric_agg(OutPeriod pd, SW_ALL *sw) { @brief gets swaBulk when dealing with OUTTEXT. @param[in] pd Time period in simulation output (day/week/month/year) -@param[in] sw Comprehensive struct of type SW_ALL containing all information +@param[in] sw Comprehensive struct of type SW_RUN containing all information in the simulation. */ -void get_swaBulk_text(OutPeriod pd, SW_ALL *sw) { +void get_swaBulk_text(OutPeriod pd, SW_RUN *sw) { LyrIndex i; SW_SOILWAT_OUTPUTS *vo = sw->SoilWat.p_oagg[pd]; SW_GEN_OUT *go = &sw->GenOutput; @@ -1691,10 +1691,10 @@ void get_swaBulk_text(OutPeriod pd, SW_ALL *sw) { @brief Gets swaBulk when dealing with RSOILWAT. @param[in] pd Time period in simulation output (day/week/month/year) -@param[in] sw Comprehensive struct of type SW_ALL containing all information +@param[in] sw Comprehensive struct of type SW_RUN containing all information in the simulation. */ -void get_swaBulk_mem(OutPeriod pd, SW_ALL *sw) { +void get_swaBulk_mem(OutPeriod pd, SW_RUN *sw) { LyrIndex i; SW_SOILWAT_OUTPUTS *vo = sw->SoilWat.p_oagg[pd]; size_t iOUTIndex = 0; @@ -1739,10 +1739,10 @@ void get_swaBulk_mem(OutPeriod pd, SW_ALL *sw) { @brief Gets swaBulk when dealing with STEPWAT. @param[in] pd Time period in simulation output (day/week/month/year) -@param[in] sw Comprehensive struct of type SW_ALL containing all information +@param[in] sw Comprehensive struct of type SW_RUN containing all information in the simulation. */ -void get_swaBulk_agg(OutPeriod pd, SW_ALL *sw) { +void get_swaBulk_agg(OutPeriod pd, SW_RUN *sw) { LyrIndex i; SW_SOILWAT_OUTPUTS *vo = sw->SoilWat.p_oagg[pd]; size_t iOUTIndex = 0; @@ -1770,10 +1770,10 @@ void get_swaBulk_agg(OutPeriod pd, SW_ALL *sw) { @brief Gets swaMatric when dealing with OUTTEXT. @param[in] pd Time period in simulation output (day/week/month/year) -@param[in] sw Comprehensive struct of type SW_ALL containing all information +@param[in] sw Comprehensive struct of type SW_RUN containing all information in the simulation. */ -void get_swaMatric_text(OutPeriod pd, SW_ALL *sw) { +void get_swaMatric_text(OutPeriod pd, SW_RUN *sw) { LyrIndex i; RealD convert; SW_SOILWAT_OUTPUTS *vo = sw->SoilWat.p_oagg[pd]; @@ -1805,10 +1805,10 @@ void get_swaMatric_text(OutPeriod pd, SW_ALL *sw) { @brief Gets swaMatric when dealing with RSOILWAT. @param[in] pd Time period in simulation output (day/week/month/year) -@param[in] sw Comprehensive struct of type SW_ALL containing all information +@param[in] sw Comprehensive struct of type SW_RUN containing all information in the simulation. */ -void get_swaMatric_mem(OutPeriod pd, SW_ALL *sw) { +void get_swaMatric_mem(OutPeriod pd, SW_RUN *sw) { LyrIndex i; RealD convert; SW_SOILWAT_OUTPUTS *vo = sw->SoilWat.p_oagg[pd]; @@ -1856,10 +1856,10 @@ void get_swaMatric_mem(OutPeriod pd, SW_ALL *sw) { @brief Gets swaMatric when dealing with STEPWAT. @param[in] pd Time period in simulation output (day/week/month/year) -@param[in] sw Comprehensive struct of type SW_ALL containing all information +@param[in] sw Comprehensive struct of type SW_RUN containing all information in the simulation. */ -void get_swaMatric_agg(OutPeriod pd, SW_ALL *sw) { +void get_swaMatric_agg(OutPeriod pd, SW_RUN *sw) { LyrIndex i; RealD convert; SW_SOILWAT_OUTPUTS *vo = sw->SoilWat.p_oagg[pd]; @@ -1895,10 +1895,10 @@ void get_swaMatric_agg(OutPeriod pd, SW_ALL *sw) { @brief Gets surfaceWater when dealing with OUTTEXT. @param[in] pd Time period in simulation output (day/week/month/year) -@param[in] sw Comprehensive struct of type SW_ALL containing all information +@param[in] sw Comprehensive struct of type SW_RUN containing all information in the simulation. */ -void get_surfaceWater_text(OutPeriod pd, SW_ALL *sw) { +void get_surfaceWater_text(OutPeriod pd, SW_RUN *sw) { SW_SOILWAT_OUTPUTS *vo = sw->SoilWat.p_oagg[pd]; SW_GEN_OUT *go = &sw->GenOutput; @@ -1920,10 +1920,10 @@ void get_surfaceWater_text(OutPeriod pd, SW_ALL *sw) { @brief Gets surfaceWater when dealing with RSOILWAT. @param[in] pd Time period in simulation output (day/week/month/year) -@param[in] sw Comprehensive struct of type SW_ALL containing all information +@param[in] sw Comprehensive struct of type SW_RUN containing all information in the simulation. */ -void get_surfaceWater_mem(OutPeriod pd, SW_ALL *sw) { +void get_surfaceWater_mem(OutPeriod pd, SW_RUN *sw) { SW_SOILWAT_OUTPUTS *vo = sw->SoilWat.p_oagg[pd]; size_t iOUTIndex = 0; SW_GEN_OUT *go = &sw->GenOutput; @@ -1953,10 +1953,10 @@ void get_surfaceWater_mem(OutPeriod pd, SW_ALL *sw) { @brief Gets surfaceWater when dealing with STEPWAT. @param[in] pd Time period in simulation output (day/week/month/year) -@param[in] sw Comprehensive struct of type SW_ALL containing all information +@param[in] sw Comprehensive struct of type SW_RUN containing all information in the simulation. */ -void get_surfaceWater_agg(OutPeriod pd, SW_ALL *sw) { +void get_surfaceWater_agg(OutPeriod pd, SW_RUN *sw) { SW_SOILWAT_OUTPUTS *vo = sw->SoilWat.p_oagg[pd]; size_t iOUTIndex = 0; SW_GEN_OUT *go = &sw->GenOutput; @@ -1983,10 +1983,10 @@ void get_surfaceWater_agg(OutPeriod pd, SW_ALL *sw) { OUTTEXT. @param[in] pd Time period in simulation output (day/week/month/year) -@param[in] sw Comprehensive struct of type SW_ALL containing all information +@param[in] sw Comprehensive struct of type SW_RUN containing all information in the simulation. */ -void get_runoffrunon_text(OutPeriod pd, SW_ALL *sw) { +void get_runoffrunon_text(OutPeriod pd, SW_RUN *sw) { RealD net; SW_WEATHER_OUTPUTS *vo = sw->Weather.p_oagg[pd]; SW_GEN_OUT *go = &sw->GenOutput; @@ -2021,10 +2021,10 @@ void get_runoffrunon_text(OutPeriod pd, SW_ALL *sw) { RSOILWAT. @param[in] pd Time period in simulation output (day/week/month/year) -@param[in] sw Comprehensive struct of type SW_ALL containing all information +@param[in] sw Comprehensive struct of type SW_RUN containing all information in the simulation. */ -void get_runoffrunon_mem(OutPeriod pd, SW_ALL *sw) { +void get_runoffrunon_mem(OutPeriod pd, SW_RUN *sw) { SW_WEATHER_OUTPUTS *vo = sw->Weather.p_oagg[pd]; size_t iOUTIndex = 0; SW_GEN_OUT *go = &sw->GenOutput; @@ -2088,10 +2088,10 @@ void get_runoffrunon_mem(OutPeriod pd, SW_ALL *sw) { STEPWAT. @param[in] pd Time period in simulation output (day/week/month/year) -@param[in] sw Comprehensive struct of type SW_ALL containing all information +@param[in] sw Comprehensive struct of type SW_RUN containing all information in the simulation. */ -void get_runoffrunon_agg(OutPeriod pd, SW_ALL *sw) { +void get_runoffrunon_agg(OutPeriod pd, SW_RUN *sw) { RealD net; SW_WEATHER_OUTPUTS *vo = sw->Weather.p_oagg[pd]; size_t iOUTIndex = 0; @@ -2127,10 +2127,10 @@ void get_runoffrunon_agg(OutPeriod pd, SW_ALL *sw) { @brief Gets transp_total when dealing with OUTTEXT. @param[in] pd Time period in simulation output (day/week/month/year) -@param[in] sw Comprehensive struct of type SW_ALL containing all information +@param[in] sw Comprehensive struct of type SW_RUN containing all information in the simulation. */ -void get_transp_text(OutPeriod pd, SW_ALL *sw) { +void get_transp_text(OutPeriod pd, SW_RUN *sw) { LyrIndex i, n_layers = sw->Site.n_layers; int k; SW_SOILWAT_OUTPUTS *vo = sw->SoilWat.p_oagg[pd]; @@ -2165,10 +2165,10 @@ void get_transp_text(OutPeriod pd, SW_ALL *sw) { @brief Gets transp_total when dealing with RSOILWAT. @param[in] pd Time period in simulation output (day/week/month/year) -@param[in] sw Comprehensive struct of type SW_ALL containing all information +@param[in] sw Comprehensive struct of type SW_RUN containing all information in the simulation. */ -void get_transp_mem(OutPeriod pd, SW_ALL *sw) { +void get_transp_mem(OutPeriod pd, SW_RUN *sw) { LyrIndex i, n_layers = sw->Site.n_layers; int k; SW_SOILWAT_OUTPUTS *vo = sw->SoilWat.p_oagg[pd]; @@ -2255,10 +2255,10 @@ void get_transp_mem(OutPeriod pd, SW_ALL *sw) { @brief Gets transp_total when dealing with STEPWAT. @param[in] pd Time period in simulation output (day/week/month/year) -@param[in] sw Comprehensive struct of type SW_ALL containing all information +@param[in] sw Comprehensive struct of type SW_RUN containing all information in the simulation. */ -void get_transp_agg(OutPeriod pd, SW_ALL *sw) { +void get_transp_agg(OutPeriod pd, SW_RUN *sw) { LyrIndex i, n_layers = sw->Site.n_layers; int k; SW_SOILWAT_OUTPUTS *vo = sw->SoilWat.p_oagg[pd]; @@ -2299,10 +2299,10 @@ void get_transp_agg(OutPeriod pd, SW_ALL *sw) { see function '_transp_contribution_by_group' @param[in] pd Time period in simulation output (day/week/month/year) -@param[in] sw Comprehensive struct of type SW_ALL containing all information +@param[in] sw Comprehensive struct of type SW_RUN containing all information in the simulation. */ -void get_transp_SXW(OutPeriod pd, SW_ALL *sw) { +void get_transp_SXW(OutPeriod pd, SW_RUN *sw) { TimeInt month; if (pd == eSW_Month) { @@ -2336,7 +2336,7 @@ void get_transp_SXW(OutPeriod pd, SW_ALL *sw) { @brief pd Period. */ -void get_evapSoil_text(OutPeriod pd, SW_ALL *sw) { +void get_evapSoil_text(OutPeriod pd, SW_RUN *sw) { LyrIndex i; SW_SOILWAT_OUTPUTS *vo = sw->SoilWat.p_oagg[pd]; SW_GEN_OUT *go = &sw->GenOutput; @@ -2359,10 +2359,10 @@ void get_evapSoil_text(OutPeriod pd, SW_ALL *sw) { @brief Gets evap when dealing with RSOILWAT. @param[in] pd Time period in simulation output (day/week/month/year) -@param[in] sw Comprehensive struct of type SW_ALL containing all information +@param[in] sw Comprehensive struct of type SW_RUN containing all information in the simulation. */ -void get_evapSoil_mem(OutPeriod pd, SW_ALL *sw) { +void get_evapSoil_mem(OutPeriod pd, SW_RUN *sw) { LyrIndex i; SW_SOILWAT_OUTPUTS *vo = sw->SoilWat.p_oagg[pd]; size_t iOUTIndex = 0; @@ -2407,10 +2407,10 @@ void get_evapSoil_mem(OutPeriod pd, SW_ALL *sw) { @brief Gets evap when dealing with STEPWAT. @param[in] pd Time period in simulation output (day/week/month/year) -@param[in] sw Comprehensive struct of type SW_ALL containing all information +@param[in] sw Comprehensive struct of type SW_RUN containing all information in the simulation. */ -void get_evapSoil_agg(OutPeriod pd, SW_ALL *sw) { +void get_evapSoil_agg(OutPeriod pd, SW_RUN *sw) { LyrIndex i; SW_SOILWAT_OUTPUTS *vo = sw->SoilWat.p_oagg[pd]; size_t iOUTIndex = 0; @@ -2440,10 +2440,10 @@ void get_evapSoil_agg(OutPeriod pd, SW_ALL *sw) { @brief Gets evapSurface when dealing with OUTTEXT. @param[in] pd Time period in simulation output (day/week/month/year) -@param[in] sw Comprehensive struct of type SW_ALL containing all information +@param[in] sw Comprehensive struct of type SW_RUN containing all information in the simulation. */ -void get_evapSurface_text(OutPeriod pd, SW_ALL *sw) { +void get_evapSurface_text(OutPeriod pd, SW_RUN *sw) { int k; SW_SOILWAT_OUTPUTS *vo = sw->SoilWat.p_oagg[pd]; SW_GEN_OUT *go = &sw->GenOutput; @@ -2488,10 +2488,10 @@ void get_evapSurface_text(OutPeriod pd, SW_ALL *sw) { @brief Gets evapSurface when dealing with RSOILWAT. @param[in] pd Time period in simulation output (day/week/month/year) -@param[in] sw Comprehensive struct of type SW_ALL containing all information +@param[in] sw Comprehensive struct of type SW_RUN containing all information in the simulation. */ -void get_evapSurface_mem(OutPeriod pd, SW_ALL *sw) { +void get_evapSurface_mem(OutPeriod pd, SW_RUN *sw) { int k; SW_SOILWAT_OUTPUTS *vo = sw->SoilWat.p_oagg[pd]; size_t iOUTIndex = 0; @@ -2563,10 +2563,10 @@ void get_evapSurface_mem(OutPeriod pd, SW_ALL *sw) { @brief Gets evapSurface when dealing with STEPWAT. @param[in] pd Time period in simulation output (day/week/month/year) -@param[in] sw Comprehensive struct of type SW_ALL containing all information +@param[in] sw Comprehensive struct of type SW_RUN containing all information in the simulation. */ -void get_evapSurface_agg(OutPeriod pd, SW_ALL *sw) { +void get_evapSurface_agg(OutPeriod pd, SW_RUN *sw) { int k; SW_SOILWAT_OUTPUTS *vo = sw->SoilWat.p_oagg[pd]; size_t iOUTIndex = 0; @@ -2608,10 +2608,10 @@ void get_evapSurface_agg(OutPeriod pd, SW_ALL *sw) { @brief Gets total_int, int_veg, and litter_int when dealing with OUTTEXT. @param[in] pd Time period in simulation output (day/week/month/year) -@param[in] sw Comprehensive struct of type SW_ALL containing all information +@param[in] sw Comprehensive struct of type SW_RUN containing all information in the simulation. */ -void get_interception_text(OutPeriod pd, SW_ALL *sw) { +void get_interception_text(OutPeriod pd, SW_RUN *sw) { int k; SW_SOILWAT_OUTPUTS *vo = sw->SoilWat.p_oagg[pd]; SW_GEN_OUT *go = &sw->GenOutput; @@ -2644,10 +2644,10 @@ void get_interception_text(OutPeriod pd, SW_ALL *sw) { @brief Gets total_int, int_veg, and litter_int when dealing with RSOILWAT. @param[in] pd Time period in simulation output (day/week/month/year) -@param[in] sw Comprehensive struct of type SW_ALL containing all information +@param[in] sw Comprehensive struct of type SW_RUN containing all information in the simulation. */ -void get_interception_mem(OutPeriod pd, SW_ALL *sw) { +void get_interception_mem(OutPeriod pd, SW_RUN *sw) { int k; SW_SOILWAT_OUTPUTS *vo = sw->SoilWat.p_oagg[pd]; size_t iOUTIndex = 0; @@ -2708,10 +2708,10 @@ void get_interception_mem(OutPeriod pd, SW_ALL *sw) { @brief Gets total_int, int_veg, and litter_int when dealing with STEPWAT. @param[in] pd Time period in simulation output (day/week/month/year) -@param[in] sw Comprehensive struct of type SW_ALL containing all information +@param[in] sw Comprehensive struct of type SW_RUN containing all information in the simulation. */ -void get_interception_agg(OutPeriod pd, SW_ALL *sw) { +void get_interception_agg(OutPeriod pd, SW_RUN *sw) { int k; SW_SOILWAT_OUTPUTS *vo = sw->SoilWat.p_oagg[pd]; size_t iOUTIndex = 0; @@ -2748,10 +2748,10 @@ void get_interception_agg(OutPeriod pd, SW_ALL *sw) { @brief Gets soil_inf when dealing with OUTTEXT. @param[in] pd Time period in simulation output (day/week/month/year) -@param[in] sw Comprehensive struct of type SW_ALL containing all information +@param[in] sw Comprehensive struct of type SW_RUN containing all information in the simulation. */ -void get_soilinf_text(OutPeriod pd, SW_ALL *sw) { +void get_soilinf_text(OutPeriod pd, SW_RUN *sw) { /* 20100202 (drs) added */ /* 20110219 (drs) added runoff */ /* 12/13/2012 (clk) moved runoff, now named snowRunoff, to @@ -2777,10 +2777,10 @@ void get_soilinf_text(OutPeriod pd, SW_ALL *sw) { @brief Gets soil_inf when dealing with RSOILWAT. @param[in] pd Time period in simulation output (day/week/month/year) -@param[in] sw Comprehensive struct of type SW_ALL containing all information +@param[in] sw Comprehensive struct of type SW_RUN containing all information in the simulation. */ -void get_soilinf_mem(OutPeriod pd, SW_ALL *sw) { +void get_soilinf_mem(OutPeriod pd, SW_RUN *sw) { SW_WEATHER_OUTPUTS *vo = sw->Weather.p_oagg[pd]; size_t iOUTIndex = 0; SW_GEN_OUT *go = &sw->GenOutput; @@ -2810,10 +2810,10 @@ void get_soilinf_mem(OutPeriod pd, SW_ALL *sw) { @brief Gets soil_inf when dealing with STEPWAT. @param[in] pd Time period in simulation output (day/week/month/year) -@param[in] sw Comprehensive struct of type SW_ALL containing all information +@param[in] sw Comprehensive struct of type SW_RUN containing all information in the simulation. */ -void get_soilinf_agg(OutPeriod pd, SW_ALL *sw) { +void get_soilinf_agg(OutPeriod pd, SW_RUN *sw) { SW_WEATHER_OUTPUTS *vo = sw->Weather.p_oagg[pd]; size_t iOUTIndex = 0; SW_GEN_OUT *go = &sw->GenOutput; @@ -2838,10 +2838,10 @@ void get_soilinf_agg(OutPeriod pd, SW_ALL *sw) { @brief Gets lyrdrain when dealing with OUTTEXT. @param[in] pd Time period in simulation output (day/week/month/year) -@param[in] sw Comprehensive struct of type SW_ALL containing all information +@param[in] sw Comprehensive struct of type SW_RUN containing all information in the simulation. */ -void get_lyrdrain_text(OutPeriod pd, SW_ALL *sw) { +void get_lyrdrain_text(OutPeriod pd, SW_RUN *sw) { /* 20100202 (drs) added */ LyrIndex i; SW_SOILWAT_OUTPUTS *vo = sw->SoilWat.p_oagg[pd]; @@ -2865,10 +2865,10 @@ void get_lyrdrain_text(OutPeriod pd, SW_ALL *sw) { @brief Gets lyrdrain when dealing with RSOILWAT. @param[in] pd Time period in simulation output (day/week/month/year) -@param[in] sw Comprehensive struct of type SW_ALL containing all information +@param[in] sw Comprehensive struct of type SW_RUN containing all information in the simulation. */ -void get_lyrdrain_mem(OutPeriod pd, SW_ALL *sw) { +void get_lyrdrain_mem(OutPeriod pd, SW_RUN *sw) { LyrIndex i; SW_SOILWAT_OUTPUTS *vo = sw->SoilWat.p_oagg[pd]; size_t iOUTIndex = 0; @@ -2913,10 +2913,10 @@ void get_lyrdrain_mem(OutPeriod pd, SW_ALL *sw) { @brief Gets lyrdrain when dealing with STEPWAT. @param[in] pd Time period in simulation output (day/week/month/year) -@param[in] sw Comprehensive struct of type SW_ALL containing all information +@param[in] sw Comprehensive struct of type SW_RUN containing all information in the simulation. */ -void get_lyrdrain_agg(OutPeriod pd, SW_ALL *sw) { +void get_lyrdrain_agg(OutPeriod pd, SW_RUN *sw) { LyrIndex i; SW_SOILWAT_OUTPUTS *vo = sw->SoilWat.p_oagg[pd]; size_t iOUTIndex = 0; @@ -2946,10 +2946,10 @@ void get_lyrdrain_agg(OutPeriod pd, SW_ALL *sw) { @brief Gets hydred and hydred_total when dealing with OUTTEXT. @param[in] pd Time period in simulation output (day/week/month/year) -@param[in] sw Comprehensive struct of type SW_ALL containing all information +@param[in] sw Comprehensive struct of type SW_RUN containing all information in the simulation. */ -void get_hydred_text(OutPeriod pd, SW_ALL *sw) { +void get_hydred_text(OutPeriod pd, SW_RUN *sw) { /* 20101020 (drs) added */ LyrIndex i, n_layers = sw->Site.n_layers; int k; @@ -2985,10 +2985,10 @@ void get_hydred_text(OutPeriod pd, SW_ALL *sw) { @brief Gets hydred and hydred_total when dealing with RSOILWAT. @param[in] pd Time period in simulation output (day/week/month/year) -@param[in] sw Comprehensive struct of type SW_ALL containing all information +@param[in] sw Comprehensive struct of type SW_RUN containing all information in the simulation. */ -void get_hydred_mem(OutPeriod pd, SW_ALL *sw) { +void get_hydred_mem(OutPeriod pd, SW_RUN *sw) { LyrIndex i, n_layers = sw->Site.n_layers; int k; SW_SOILWAT_OUTPUTS *vo = sw->SoilWat.p_oagg[pd]; @@ -3076,10 +3076,10 @@ void get_hydred_mem(OutPeriod pd, SW_ALL *sw) { @brief Gets hydred and hydred_total when dealing with STEPWAT. @param[in] pd Time period in simulation output (day/week/month/year) -@param[in] sw Comprehensive struct of type SW_ALL containing all information +@param[in] sw Comprehensive struct of type SW_RUN containing all information in the simulation. */ -void get_hydred_agg(OutPeriod pd, SW_ALL *sw) { +void get_hydred_agg(OutPeriod pd, SW_RUN *sw) { LyrIndex i, n_layers = sw->Site.n_layers; int k; SW_SOILWAT_OUTPUTS *vo = sw->SoilWat.p_oagg[pd]; @@ -3124,10 +3124,10 @@ void get_hydred_agg(OutPeriod pd, SW_ALL *sw) { @brief Gets actual evapotranspiration when dealing with OUTTEXT. @param[in] pd Time period in simulation output (day/week/month/year) -@param[in] sw Comprehensive struct of type SW_ALL containing all information +@param[in] sw Comprehensive struct of type SW_RUN containing all information in the simulation. */ -void get_aet_text(OutPeriod pd, SW_ALL *sw) { +void get_aet_text(OutPeriod pd, SW_RUN *sw) { SW_SOILWAT_OUTPUTS *vo = sw->SoilWat.p_oagg[pd]; SW_WEATHER_OUTPUTS *vo2 = sw->Weather.p_oagg[pd]; SW_GEN_OUT *go = &sw->GenOutput; @@ -3165,10 +3165,10 @@ void get_aet_text(OutPeriod pd, SW_ALL *sw) { @brief Gets actual evapotranspiration when dealing with RSOILWAT. @param[in] pd Time period in simulation output (day/week/month/year) -@param[in] sw Comprehensive struct of type SW_ALL containing all information +@param[in] sw Comprehensive struct of type SW_RUN containing all information in the simulation. */ -void get_aet_mem(OutPeriod pd, SW_ALL *sw) { +void get_aet_mem(OutPeriod pd, SW_RUN *sw) { SW_SOILWAT_OUTPUTS *vo = sw->SoilWat.p_oagg[pd]; SW_WEATHER_OUTPUTS *vo2 = sw->Weather.p_oagg[pd]; size_t iOUTIndex = 0; @@ -3254,10 +3254,10 @@ void get_aet_mem(OutPeriod pd, SW_ALL *sw) { @brief Gets actual evapotranspiration when dealing with STEPWAT. @param[in] pd Time period in simulation output (day/week/month/year) -@param[in] sw Comprehensive struct of type SW_ALL containing all information +@param[in] sw Comprehensive struct of type SW_RUN containing all information in the simulation. */ -void get_aet_agg(OutPeriod pd, SW_ALL *sw) { +void get_aet_agg(OutPeriod pd, SW_RUN *sw) { SW_SOILWAT_OUTPUTS *vo = sw->SoilWat.p_oagg[pd]; SW_WEATHER_OUTPUTS *vo2 = sw->Weather.p_oagg[pd]; size_t iOUTIndex = 0; @@ -3294,10 +3294,10 @@ void get_aet_agg(OutPeriod pd, SW_ALL *sw) { @brief STEPWAT2 expects annual sum of actual evapotranspiration @param[in] pd Time period in simulation output (day/week/month/year) -@param[in] sw Comprehensive struct of type SW_ALL containing all information +@param[in] sw Comprehensive struct of type SW_RUN containing all information in the simulation. */ -void get_aet_SXW(OutPeriod pd, SW_ALL *sw) { +void get_aet_SXW(OutPeriod pd, SW_RUN *sw) { if (pd == eSW_Year) { SW_SOILWAT_OUTPUTS *vo = sw->SoilWat.p_oagg[pd]; SW_GEN_OUT *go = &sw->GenOutput; @@ -3315,10 +3315,10 @@ void get_aet_SXW(OutPeriod pd, SW_ALL *sw) { @brief Gets potential evapotranspiration and radiation when dealing with OUTTEXT @param[in] pd Time period in simulation output (day/week/month/year) -@param[in] sw Comprehensive struct of type SW_ALL containing all information +@param[in] sw Comprehensive struct of type SW_RUN containing all information in the simulation. */ -void get_pet_text(OutPeriod pd, SW_ALL *sw) { +void get_pet_text(OutPeriod pd, SW_RUN *sw) { SW_SOILWAT_OUTPUTS *vo = sw->SoilWat.p_oagg[pd]; SW_GEN_OUT *go = &sw->GenOutput; @@ -3352,10 +3352,10 @@ void get_pet_text(OutPeriod pd, SW_ALL *sw) { @brief Gets potential evapotranspiration and radiation @param[in] pd Time period in simulation output (day/week/month/year) -@param[in] sw Comprehensive struct of type SW_ALL containing all information +@param[in] sw Comprehensive struct of type SW_RUN containing all information in the simulation. */ -void get_pet_mem(OutPeriod pd, SW_ALL *sw) { +void get_pet_mem(OutPeriod pd, SW_RUN *sw) { SW_SOILWAT_OUTPUTS *vo = sw->SoilWat.p_oagg[pd]; size_t iOUTIndex = 0; SW_GEN_OUT *go = &sw->GenOutput; @@ -3428,7 +3428,7 @@ void get_pet_mem(OutPeriod pd, SW_ALL *sw) { /** @brief Gets potential evapotranspiration and radiation */ -void get_pet_agg(OutPeriod pd, SW_ALL *sw) { +void get_pet_agg(OutPeriod pd, SW_RUN *sw) { SW_SOILWAT_OUTPUTS *vo = sw->SoilWat.p_oagg[pd]; size_t iOUTIndex = 0; SW_GEN_OUT *go = &sw->GenOutput; @@ -3465,10 +3465,10 @@ void get_pet_agg(OutPeriod pd, SW_ALL *sw) { @brief Gets is_wet and wetdays when dealing with OUTTEXT. @param[in] pd Time period in simulation output (day/week/month/year) -@param[in] sw Comprehensive struct of type SW_ALL containing all information +@param[in] sw Comprehensive struct of type SW_RUN containing all information in the simulation. */ -void get_wetdays_text(OutPeriod pd, SW_ALL *sw) { +void get_wetdays_text(OutPeriod pd, SW_RUN *sw) { LyrIndex i, n_layers = sw->Site.n_layers; SW_GEN_OUT *go = &sw->GenOutput; @@ -3500,10 +3500,10 @@ void get_wetdays_text(OutPeriod pd, SW_ALL *sw) { @brief Gets is_wet and wetdays when dealing with RSOILWAT. @param[in] pd Time period in simulation output (day/week/month/year) -@param[in] sw Comprehensive struct of type SW_ALL containing all information +@param[in] sw Comprehensive struct of type SW_RUN containing all information in the simulation. */ -void get_wetdays_mem(OutPeriod pd, SW_ALL *sw) { +void get_wetdays_mem(OutPeriod pd, SW_RUN *sw) { LyrIndex i; size_t iOUTIndex = 0; SW_GEN_OUT *go = &sw->GenOutput; @@ -3552,10 +3552,10 @@ void get_wetdays_mem(OutPeriod pd, SW_ALL *sw) { @brief Gets is_wet and wetdays when dealing with RSOILWAT. @param[in] pd Time period in simulation output (day/week/month/year) -@param[in] sw Comprehensive struct of type SW_ALL containing all information +@param[in] sw Comprehensive struct of type SW_RUN containing all information in the simulation. */ -void get_wetdays_agg(OutPeriod pd, SW_ALL *sw) { +void get_wetdays_agg(OutPeriod pd, SW_RUN *sw) { LyrIndex i; size_t iOUTIndex = 0; SW_GEN_OUT *go = &sw->GenOutput; @@ -3596,10 +3596,10 @@ void get_wetdays_agg(OutPeriod pd, SW_ALL *sw) { @brief Gets snowpack and snowdepth when dealing with OUTTEXT. @param[in] pd Time period in simulation output (day/week/month/year) -@param[in] sw Comprehensive struct of type SW_ALL containing all information +@param[in] sw Comprehensive struct of type SW_RUN containing all information in the simulation. */ -void get_snowpack_text(OutPeriod pd, SW_ALL *sw) { +void get_snowpack_text(OutPeriod pd, SW_RUN *sw) { SW_SOILWAT_OUTPUTS *vo = sw->SoilWat.p_oagg[pd]; SW_GEN_OUT *go = &sw->GenOutput; @@ -3624,10 +3624,10 @@ void get_snowpack_text(OutPeriod pd, SW_ALL *sw) { @brief Gets snowpack and snowdepth when dealing with OUTTEXT. @param[in] pd Time period in simulation output (day/week/month/year) -@param[in] sw Comprehensive struct of type SW_ALL containing all information +@param[in] sw Comprehensive struct of type SW_RUN containing all information in the simulation. */ -void get_snowpack_mem(OutPeriod pd, SW_ALL *sw) { +void get_snowpack_mem(OutPeriod pd, SW_RUN *sw) { SW_SOILWAT_OUTPUTS *vo = sw->SoilWat.p_oagg[pd]; size_t iOUTIndex = 0; SW_GEN_OUT *go = &sw->GenOutput; @@ -3668,10 +3668,10 @@ void get_snowpack_mem(OutPeriod pd, SW_ALL *sw) { @brief Gets snowpack and snowdepth when dealing with STEPWAT. @param[in] pd Time period in simulation output (day/week/month/year) -@param[in] sw Comprehensive struct of type SW_ALL containing all information +@param[in] sw Comprehensive struct of type SW_RUN containing all information in the simulation. */ -void get_snowpack_agg(OutPeriod pd, SW_ALL *sw) { +void get_snowpack_agg(OutPeriod pd, SW_RUN *sw) { SW_SOILWAT_OUTPUTS *vo = sw->SoilWat.p_oagg[pd]; size_t iOUTIndex = 0; SW_GEN_OUT *go = &sw->GenOutput; @@ -3700,10 +3700,10 @@ void get_snowpack_agg(OutPeriod pd, SW_ALL *sw) { @brief Gets deep for when dealing with OUTTEXT. @param[in] pd Time period in simulation output (day/week/month/year) -@param[in] sw Comprehensive struct of type SW_ALL containing all information +@param[in] sw Comprehensive struct of type SW_RUN containing all information in the simulation. */ -void get_deepswc_text(OutPeriod pd, SW_ALL *sw) { +void get_deepswc_text(OutPeriod pd, SW_RUN *sw) { SW_SOILWAT_OUTPUTS *vo = sw->SoilWat.p_oagg[pd]; SW_GEN_OUT *go = &sw->GenOutput; @@ -3725,10 +3725,10 @@ void get_deepswc_text(OutPeriod pd, SW_ALL *sw) { @brief Gets deep for when dealing with RSOILWAT. @param[in] pd Time period in simulation output (day/week/month/year) -@param[in] sw Comprehensive struct of type SW_ALL containing all information +@param[in] sw Comprehensive struct of type SW_RUN containing all information in the simulation. */ -void get_deepswc_mem(OutPeriod pd, SW_ALL *sw) { +void get_deepswc_mem(OutPeriod pd, SW_RUN *sw) { SW_SOILWAT_OUTPUTS *vo = sw->SoilWat.p_oagg[pd]; size_t iOUTIndex = 0; SW_GEN_OUT *go = &sw->GenOutput; @@ -3758,10 +3758,10 @@ void get_deepswc_mem(OutPeriod pd, SW_ALL *sw) { @brief Gets deep for when dealing with STEPWAT. @param[in] pd Time period in simulation output (day/week/month/year) -@param[in] sw Comprehensive struct of type SW_ALL containing all information +@param[in] sw Comprehensive struct of type SW_RUN containing all information in the simulation. */ -void get_deepswc_agg(OutPeriod pd, SW_ALL *sw) { +void get_deepswc_agg(OutPeriod pd, SW_RUN *sw) { SW_SOILWAT_OUTPUTS *vo = sw->SoilWat.p_oagg[pd]; size_t iOUTIndex = 0; SW_GEN_OUT *go = &sw->GenOutput; @@ -3786,10 +3786,10 @@ void get_deepswc_agg(OutPeriod pd, SW_ALL *sw) { @brief Gets soil temperature for when dealing with OUTTEXT. @param[in] pd Time period in simulation output (day/week/month/year) -@param[in] sw Comprehensive struct of type SW_ALL containing all information +@param[in] sw Comprehensive struct of type SW_RUN containing all information in the simulation. */ -void get_soiltemp_text(OutPeriod pd, SW_ALL *sw) { +void get_soiltemp_text(OutPeriod pd, SW_RUN *sw) { LyrIndex i; SW_SOILWAT_OUTPUTS *vo = sw->SoilWat.p_oagg[pd]; SW_GEN_OUT *go = &sw->GenOutput; @@ -3832,10 +3832,10 @@ void get_soiltemp_text(OutPeriod pd, SW_ALL *sw) { @brief Gets soil temperature for when dealing with RSOILWAT. @param[in] pd Time period in simulation output (day/week/month/year) -@param[in] sw Comprehensive struct of type SW_ALL containing all information +@param[in] sw Comprehensive struct of type SW_RUN containing all information in the simulation. */ -void get_soiltemp_mem(OutPeriod pd, SW_ALL *sw) { +void get_soiltemp_mem(OutPeriod pd, SW_RUN *sw) { LyrIndex i; SW_SOILWAT_OUTPUTS *vo = sw->SoilWat.p_oagg[pd]; size_t iOUTIndex = 0; @@ -3918,10 +3918,10 @@ void get_soiltemp_mem(OutPeriod pd, SW_ALL *sw) { @brief Gets soil temperature for when dealing with STEPWAT. @param[in] pd Time period in simulation output (day/week/month/year) -@param[in] sw Comprehensive struct of type SW_ALL containing all information +@param[in] sw Comprehensive struct of type SW_RUN containing all information in the simulation. */ -void get_soiltemp_agg(OutPeriod pd, SW_ALL *sw) { +void get_soiltemp_agg(OutPeriod pd, SW_RUN *sw) { LyrIndex i; SW_SOILWAT_OUTPUTS *vo = sw->SoilWat.p_oagg[pd]; size_t iOUTIndex = 0; @@ -3965,10 +3965,10 @@ void get_soiltemp_agg(OutPeriod pd, SW_ALL *sw) { OUTTEXT. @param[in] pd Time period in simulation output (day/week/month/year) -@param[in] sw Comprehensive struct of type SW_ALL containing all information +@param[in] sw Comprehensive struct of type SW_RUN containing all information in the simulation. */ -void get_frozen_text(OutPeriod pd, SW_ALL *sw) { +void get_frozen_text(OutPeriod pd, SW_RUN *sw) { LyrIndex i; SW_SOILWAT_OUTPUTS *vo = sw->SoilWat.p_oagg[pd]; SW_GEN_OUT *go = &sw->GenOutput; @@ -3991,10 +3991,10 @@ void get_frozen_text(OutPeriod pd, SW_ALL *sw) { @brief Gets soil state (frozen/unfrozen) for when dealing with RSOILWAT. @param[in] pd Time period in simulation output (day/week/month/year) -@param[in] sw Comprehensive struct of type SW_ALL containing all information +@param[in] sw Comprehensive struct of type SW_RUN containing all information in the simulation. */ -void get_frozen_mem(OutPeriod pd, SW_ALL *sw) { +void get_frozen_mem(OutPeriod pd, SW_RUN *sw) { LyrIndex i; SW_SOILWAT_OUTPUTS *vo = sw->SoilWat.p_oagg[pd]; size_t iOUTIndex = 0; @@ -4039,10 +4039,10 @@ void get_frozen_mem(OutPeriod pd, SW_ALL *sw) { @brief Gets soil temperature for when dealing with STEPWAT. @param[in] pd Time period in simulation output (day/week/month/year) -@param[in] sw Comprehensive struct of type SW_ALL containing all information +@param[in] sw Comprehensive struct of type SW_RUN containing all information in the simulation. */ -void get_frozen_agg(OutPeriod pd, SW_ALL *sw) { +void get_frozen_agg(OutPeriod pd, SW_RUN *sw) { LyrIndex i; SW_SOILWAT_OUTPUTS *vo = sw->SoilWat.p_oagg[pd]; size_t iOUTIndex = 0; diff --git a/src/SW_SoilWater.c b/src/SW_SoilWater.c index 75c11f1d7..33434389d 100644 --- a/src/SW_SoilWater.c +++ b/src/SW_SoilWater.c @@ -376,7 +376,7 @@ static double itp_FXW_for_phi(double theta, double *swrcp, LOG_INFO *LogInfo) { /* --------------------------------------------------- */ #ifdef SWDEBUG -void SW_WaterBalance_Checks(SW_ALL *sw, LOG_INFO *LogInfo) { +void SW_WaterBalance_Checks(SW_RUN *sw, LOG_INFO *LogInfo) { IntUS i, k; int debugi[N_WBCHECKS] = { @@ -831,11 +831,11 @@ void SW_SWC_deconstruct(SW_SOILWAT *SW_SoilWat) { @brief Adjust SWC according to historical (measured) data if available, compute water flow, and check if swc is above threshold for "wet" condition. -@param[in,out] sw Comprehensive struct of type SW_ALL containing all information +@param[in,out] sw Comprehensive struct of type SW_RUN containing all information in the simulation. @param[out] LogInfo Holds information on warnings and errors */ -void SW_SWC_water_flow(SW_ALL *sw, LOG_INFO *LogInfo) { +void SW_SWC_water_flow(SW_RUN *sw, LOG_INFO *LogInfo) { /* =================================================== */ diff --git a/src/SW_netCDF.c b/src/SW_netCDF.c index 2db682eea..7aaa8399c 100644 --- a/src/SW_netCDF.c +++ b/src/SW_netCDF.c @@ -4487,7 +4487,7 @@ Bool SW_NC_check_progress( @brief Read values from netCDF input files for available variables and copy to SW_All -@param[in,out] sw Comprehensive struct of type SW_ALL containing +@param[in,out] sw Comprehensive struct of type SW_RUN containing all information in the simulation @param[in] SW_Domain Struct of type SW_DOMAIN holding constant temporal/spatial information for a set of simulation runs @@ -4496,7 +4496,7 @@ to SW_All @param[out] LogInfo Holds information on warnings and errors */ void SW_NC_read_inputs( - SW_ALL *sw, SW_DOMAIN *SW_Domain, size_t ncSUID[], LOG_INFO *LogInfo + SW_RUN *sw, SW_DOMAIN *SW_Domain, size_t ncSUID[], LOG_INFO *LogInfo ) { int file, varNum; diff --git a/tests/gtests/sw_testhelpers.cc b/tests/gtests/sw_testhelpers.cc index d7f1993bf..6cbdde514 100644 --- a/tests/gtests/sw_testhelpers.cc +++ b/tests/gtests/sw_testhelpers.cc @@ -13,7 +13,7 @@ #include // for strcpy -SW_ALL template_SW_All; +SW_RUN template_SW_All; SW_DOMAIN template_SW_Domain; SW_OUTPUT_POINTERS template_SW_OutputPtrs[SW_OUTNKEYS]; diff --git a/tests/gtests/sw_testhelpers.h b/tests/gtests/sw_testhelpers.h index 811360676..45875526b 100644 --- a/tests/gtests/sw_testhelpers.h +++ b/tests/gtests/sw_testhelpers.h @@ -1,6 +1,6 @@ #include "include/generic.h" // for EQ, swTRUE #include "include/SW_Control.h" // for SW_ALL_deepCopy, SW_CTL_clear_model -#include "include/SW_datastructs.h" // for LOG_INFO, SW_ALL, SW_DOMAIN, SW_... +#include "include/SW_datastructs.h" // for LOG_INFO, SW_RUN, SW_DOMAIN, SW_... #include "include/SW_Defines.h" // for SW_OUTNKEYS, SW_MISSING #include "include/SW_Domain.h" // for SW_DOM_deconstruct, SW_DOM_deepCopy #include "include/SW_Main_lib.h" // for sw_fail_on_error, sw_init_logs @@ -8,7 +8,7 @@ #include // for memcpy, NULL -extern SW_ALL template_SW_All; +extern SW_RUN template_SW_All; extern SW_DOMAIN template_SW_Domain; extern SW_OUTPUT_POINTERS template_SW_OutputPtrs[SW_OUTNKEYS]; @@ -55,7 +55,7 @@ void teardown_testGlobalSoilwatTemplate(); */ class AllTestFixture : public ::testing::Test { protected: - SW_ALL SW_All; + SW_RUN SW_All; SW_DOMAIN SW_Domain; LOG_INFO LogInfo; SW_OUTPUT_POINTERS SW_OutputPtrs[SW_OUTNKEYS]; diff --git a/tests/gtests/test_SW_SpinUp.cc b/tests/gtests/test_SW_SpinUp.cc index a9fa20cde..953441cda 100644 --- a/tests/gtests/test_SW_SpinUp.cc +++ b/tests/gtests/test_SW_SpinUp.cc @@ -7,7 +7,7 @@ #if defined(SW2_SpinupEvaluation) #include "include/filefuncs.h" // for OpenFile, CloseFile -#include "include/SW_datastructs.h" // for SW_ALL, LOG_INFO +#include "include/SW_datastructs.h" // for SW_RUN, LOG_INFO #include "include/SW_Site.h" // for SW_SIT_init_run #include "include/SW_SoilWater.h" // for SW_SWC_init_run #include // for fprintf, fflush, FILE @@ -307,7 +307,7 @@ TEST_F(SpinUpTest, Mode2WithScopeLessThanDuration) { // ``` TEST_F(SpinUpTest, SpinupEvaluation) { - SW_ALL local_sw; + SW_RUN local_sw; LOG_INFO local_LogInfo; FILE *fp; From 88c6d6a835d1d68c857f196d71a9cd9de5a7bbdf Mon Sep 17 00:00:00 2001 From: Nicholas Persley Date: Tue, 2 Jul 2024 16:14:35 -0400 Subject: [PATCH 02/19] Split output data structs into SW_OUT_DOM/RUN Motivation: Reduce the constant copying of constant output information between simulation runs Solution: - Move information from output structs to new structures, only copying information that may change during simulation runs - See https://github.com/DrylandEcology/SOILWAT2/issues/395 for more information SW_datastructs.h - New structures * SW_OUT_DOM - Contains information from SW_GEN_OUT that are consistent throughout simulation runs - Contains all information from SW_OUTPUT_POINTERS - Contains most information from SW_OUTPUT - excludes "first" and "last" * SW_OUT_RUN - Contains "first" and "last" from SW_OUTPUT - Contains the rest of the information of SW_GEN_OUT - Removed structs SW_OUTPUT, SW_OUTPUT_POINTERS, and SW_GEN_OUT - Converted all SW_OUTPUT and SW_OUTPUT_POINTERS information into arrays to eliminate the need for an array of structs - Modify SW_RUN and SW_OUT_DOM definition so that SW_OUT_DOM and SW_DOMAIN sees them * Move typedef to top of file and initialize later in file --- include/SW_datastructs.h | 312 ++++++++++++++++++++------------------- 1 file changed, 163 insertions(+), 149 deletions(-) diff --git a/include/SW_datastructs.h b/include/SW_datastructs.h index 117a274ae..2b59fd0f8 100644 --- a/include/SW_datastructs.h +++ b/include/SW_datastructs.h @@ -30,6 +30,10 @@ #define SW_NFILES 27 // For `InFiles` #define SW_NVARNC 2 // For `InFilesNC` +/* Declare SW_RUN & SW_OUT_DOM structs for SW_OUT_DOM and SW_DOMAIN to see */ +typedef struct SW_RUN SW_RUN; +typedef struct SW_OUT_DOM SW_OUT_DOM; + /* =================================================== */ /* Carbon structs */ /* --------------------------------------------------- */ @@ -1086,39 +1090,55 @@ typedef enum { eSW_LastKey /* make sure this is the last one */ } OutKey; +/* =================================================== */ +/* Coordinate Reference System struct */ +/* --------------------------------------------------- */ + typedef struct { - OutKey mykey; - ObjType myobj; - OutSum sumtype; - Bool use, // TRUE if output is requested - has_sl; // TRUE if output key/type produces output for each soil layer - TimeInt first, - last, /* first/last doy of current year, i.e., updated for each year */ - first_orig, - last_orig; /* first/last doy that were originally requested */ + char *long_name, *grid_mapping_name, *crs_wkt; + double longitude_of_prime_meridian, semi_major_axis, inverse_flattening; -#if defined(RSOILWAT) - char *outfile; /* name of output */ // could probably be removed -#endif + // Possible attributes if the type is "projected" + char *datum, *units; + double standard_parallel[2]; // first and second standard parallels; 2nd may + // be missing (NAN) + double longitude_of_central_meridian, latitude_of_projection_origin, + false_easting, false_northing; +} SW_CRS; -#if defined(SWNETCDF) - Bool *reqOutputVars; /**< Do/don't output a variable in the netCDF output - files (dynamically allocated array over output - variables) */ - char ***outputVarInfo; /**< Attributes of output variables in netCDF output - files (dynamically allcoated 2-d array: - `[varIndex][attIndex]`) */ - char **units_sw; /**< Units internally utilized by SOILWAT2 (dynamically - allocated array over output variables) */ - sw_converter_t **uconv; /**< udunits2 unit converter from internal SOILWAT2 - units to user-requested units (dynamically - allocated array over output variables) */ -#endif -} SW_OUTPUT; +/* =================================================== */ +/* SOILWAT2 netCDF struct */ +/* --------------------------------------------------- */ typedef struct { - TimeInt tOffset; /* 1 or 0 means we're writing previous or current period */ + char *title, *author, *institution, *comment, *coordinate_system; + Bool primary_crs_is_geographic; + + SW_CRS crs_geogsc, crs_projsc; + + char *varNC[SW_NVARNC]; + char *InFilesNC[SW_NVARNC]; + + /** Should a domain template netCDF file be automatically renamed + to provided file name for domain? */ + Bool renameDomainTemplateNC; + + int ncFileIDs[SW_NVARNC]; + int ncVarIDs[SW_NVARNC]; + + int strideOutYears; /**< How many years to write out in a single output + netCDF -- 1, X (e.g., 10) or Inf (-1) */ + int baseCalendarYear; /**< Calendar year that is the reference basis of the + time units (e.g., days since YYYY-01-01) of every + output netCDFs */ + + char *outputVarsFileName; +} SW_NETCDF; + +struct SW_OUT_DOM { + + /* Output information */ // Variables describing output periods: /** `timeSteps` is the array that keeps track of the output time periods @@ -1135,7 +1155,6 @@ typedef struct { /** TRUE if time step/period is active for any output key. */ Bool use_OutPeriod[SW_OUTNPERIODS]; - // Variables describing size and names of output /** names of output columns for each output key; number is an expensive * guess */ @@ -1154,19 +1173,9 @@ typedef struct { Bool print_IterationSummary; Bool print_SW_Output; - char sw_outstr[MAX_LAYERS * OUTSTRLEN]; #if defined(SW_OUTARRAY) - /** - @brief A 2-dim array of pointers to output arrays. - - The variable p_OUT used by rSOILWAT2 for output and by STEPWAT2 for - mean aggregation. - */ - RealD *p_OUT[SW_OUTNKEYS][SW_OUTNPERIODS]; - size_t nrow_OUT[SW_OUTNPERIODS]; /**< number of output time steps */ - size_t irow_OUT[SW_OUTNPERIODS]; /**< current output time step index */ #endif #if defined(SWNETCDF) @@ -1175,96 +1184,58 @@ typedef struct { for indexing p_OUT */ #endif -#ifdef STEPWAT - RealD *p_OUTsd[SW_OUTNKEYS][SW_OUTNPERIODS]; + OutKey mykey[SW_OUTNKEYS]; + ObjType myobj[SW_OUTNKEYS]; + OutSum sumtype[SW_OUTNKEYS]; + Bool use[SW_OUTNKEYS], // TRUE if output is requested + has_sl[SW_OUTNKEYS]; // TRUE if output key/type produces output for each + // soil layer + TimeInt first_orig[SW_OUTNKEYS], + last_orig[SW_OUTNKEYS]; /* first/last doy that were originally requested + */ - char sw_outstr_agg[MAX_LAYERS * OUTSTRLEN]; - - /** `timeSteps_SXW` is the array that keeps track of the output time periods - that are required for `SXW` in-memory output for each output key. - Compare with `timeSteps` */ - OutPeriod timeSteps_SXW[SW_OUTNKEYS][SW_OUTNPERIODS]; - - /** `storeAllIterations` is set to TRUE if STEPWAT2 is called with `-i` flag - if TRUE, then write to disk the SOILWAT2 output - for each STEPWAT2 iteration/repeat to separate files */ - Bool storeAllIterations; - - /** `prepare_IterationSummary` is set to TRUE if STEPWAT2 is called with - `-o` flag; if TRUE, then calculate/write to disk the running mean - and sd across iterations/repeats */ - Bool prepare_IterationSummary; - - /** Variable from ModelType (STEPWAT2) used in SOILWAT2 */ - IntUS currIter; - - /* Variables from SXW_t (STEPWAT2) used in SOILWAT2 */ - // transpXXX: monthly sum of soilwat's transpiration by soil layer - // * these are dynamic arrays that are indexed by Ilp() - RealD transpTotal[MAX_LAYERS][MAX_MONTHS], // total transpiration, i.e., sum - // across vegetation types - transpVeg[NVEGTYPES][MAX_LAYERS] - [MAX_MONTHS]; // transpiration as contributed by vegetation - // types - RealF swc[MAX_LAYERS] - [MAX_MONTHS]; // monthly mean SWCbulk for each soil layer - - // fixed monthly array: - RealF ppt_monthly[MAX_MONTHS]; // monthly sum of soilwat's precipitation - RealF temp_monthly[MAX_MONTHS]; // monthly mean soilwat's air temperature - - // annual values: - RealF temp, // annual mean soilwat's air temperature - ppt, // annual sum of soilwat's precipitation - aet; // annual sum of soilwat's evapotranspiration +#if defined(RSOILWAT) + char *outfile[SW_OUTNKEYS]; + /* name of output */ // could probably be removed #endif -} SW_GEN_OUT; - -/* =================================================== */ -/* Coordinate Reference System struct */ -/* --------------------------------------------------- */ - -typedef struct { - char *long_name, *grid_mapping_name, *crs_wkt; - double longitude_of_prime_meridian, semi_major_axis, inverse_flattening; - - // Possible attributes if the type is "projected" - char *datum, *units; - double standard_parallel[2]; // first and second standard parallels; 2nd may - // be missing (NAN) - double longitude_of_central_meridian, latitude_of_projection_origin, - false_easting, false_northing; -} SW_CRS; - -/* =================================================== */ -/* SOILWAT2 netCDF struct */ -/* --------------------------------------------------- */ - -typedef struct { - char *title, *author, *institution, *comment, *coordinate_system; - Bool primary_crs_is_geographic; +#if defined(SWNETCDF) + Bool *reqOutputVars[SW_OUTNKEYS]; /**< Do/don't output a variable in the + netCDF output files (dynamically allocated array + over output variables) */ + char ** + *outputVarInfo[SW_OUTNKEYS]; /**< Attributes of output variables in + netCDF output files (dynamically allcoated 2-d array: + `[varIndex][attIndex]`) */ + char * + *units_sw[SW_OUTNKEYS]; /**< Units internally utilized by SOILWAT2 + (dynamically allocated array over output variables) */ + sw_converter_t * + *uconv[SW_OUTNKEYS]; /**< udunits2 unit converter from internal SOILWAT2 + units to user-requested units (dynamically + allocated array over output variables) */ +#endif - SW_CRS crs_geogsc, crs_projsc; - char *varNC[SW_NVARNC]; - char *InFilesNC[SW_NVARNC]; + /* Output function pointers */ - /** Should a domain template netCDF file be automatically renamed - to provided file name for domain? */ - Bool renameDomainTemplateNC; - - int ncFileIDs[SW_NVARNC]; - int ncVarIDs[SW_NVARNC]; +#if defined(SW_OUTTEXT) + /** pointer to output routine for text output */ + void (*pfunc_text[SW_OUTNKEYS])(OutPeriod, SW_RUN *); +#endif - int strideOutYears; /**< How many years to write out in a single output - netCDF -- 1, X (e.g., 10) or Inf (-1) */ - int baseCalendarYear; /**< Calendar year that is the reference basis of the - time units (e.g., days since YYYY-01-01) of every - output netCDFs */ +#if defined(RSOILWAT) || defined(SWNETCDF) + /** pointer to output routine for array output */ + void (*pfunc_mem[SW_OUTNKEYS])(OutPeriod, SW_RUN *, SW_OUT_DOM *); - char *outputVarsFileName; -} SW_NETCDF; +#elif defined(STEPWAT) + /** pointer to output routine for aggregated output across STEPWAT + * iterations */ + void (*pfunc_agg[SW_OUTNKEYS])(OutPeriod, SW_RUN *, SW_OUT_DOM *); + /** pointer to output routine for STEPWAT in-memory output */ + void (*pfunc_SXW[SW_OUTNKEYS])(OutPeriod, SW_RUN *, SW_OUT_DOM *); +#endif +}; /* =================================================== */ /* Domain structs */ @@ -1328,13 +1299,82 @@ typedef struct { // Information dealing with netCDFs SW_NETCDF netCDFInfo; + + // Information that is constant through simulation runs + SW_OUT_DOM OutDom; } SW_DOMAIN; /* =================================================== */ -/* Comprehensive struct */ +/* Simulation Run Structs */ /* --------------------------------------------------- */ typedef struct { + + TimeInt tOffset; /* 1 or 0 means we're writing previous or current period */ + + char sw_outstr[MAX_LAYERS * OUTSTRLEN]; + + /* Output first/last days of current year i.e., updated for each year */ + TimeInt first[SW_OUTNKEYS], last[SW_OUTNKEYS]; + +#ifdef SW_OUTARRAY + /** + @brief A 2-dim array of pointers to output arrays. + + The variable p_OUT used by rSOILWAT2 for output, by STEPWAT2 for + mean aggregation, and by SOILWAT2 when user requests netCDF output files. + */ + RealD *p_OUT[SW_OUTNKEYS][SW_OUTNPERIODS]; + + size_t irow_OUT[SW_OUTNPERIODS]; /**< current output time step index */ +#endif + +#ifdef STEPWAT + RealD *p_OUTsd[SW_OUTNKEYS][SW_OUTNPERIODS]; + + char sw_outstr_agg[MAX_LAYERS * OUTSTRLEN]; + + /** `timeSteps_SXW` is the array that keeps track of the output time periods + that are required for `SXW` in-memory output for each output key. + Compare with `timeSteps` */ + OutPeriod timeSteps_SXW[SW_OUTNKEYS][SW_OUTNPERIODS]; + + /** `storeAllIterations` is set to TRUE if STEPWAT2 is called with `-i` flag + if TRUE, then write to disk the SOILWAT2 output + for each STEPWAT2 iteration/repeat to separate files */ + Bool storeAllIterations; + + /** `prepare_IterationSummary` is set to TRUE if STEPWAT2 is called with + `-o` flag; if TRUE, then calculate/write to disk the running mean + and sd across iterations/repeats */ + Bool prepare_IterationSummary; + + /** Variable from ModelType (STEPWAT2) used in SOILWAT2 */ + IntUS currIter; + + /* Variables from SXW_t (STEPWAT2) used in SOILWAT2 */ + // transpXXX: monthly sum of soilwat's transpiration by soil layer + // * these are dynamic arrays that are indexed by Ilp() + RealD transpTotal[MAX_LAYERS][MAX_MONTHS], // total transpiration, i.e., sum + // across vegetation types + transpVeg[NVEGTYPES][MAX_LAYERS] + [MAX_MONTHS]; // transpiration as contributed by vegetation + // types + RealF swc[MAX_LAYERS] + [MAX_MONTHS]; // monthly mean SWCbulk for each soil layer + + // fixed monthly array: + RealF ppt_monthly[MAX_MONTHS]; // monthly sum of soilwat's precipitation + RealF temp_monthly[MAX_MONTHS]; // monthly mean soilwat's air temperature + + // annual values: + RealF temp, // annual mean soilwat's air temperature + ppt, // annual sum of soilwat's precipitation + aet; // annual sum of soilwat's evapotranspiration +#endif +} SW_OUT_RUN; + +struct SW_RUN { SW_VEGPROD VegProd; SW_WEATHER Weather; SW_SOILWAT SoilWat; @@ -1346,35 +1386,9 @@ typedef struct { ST_RGR_VALUES StRegValues; SW_FILE_STATUS FileStatus; SW_MARKOV Markov; - SW_OUTPUT Output[SW_OUTNKEYS]; + SW_OUT_RUN OutRun; SW_ATMD AtmDemand; - SW_GEN_OUT GenOutput; - -} SW_RUN; - -/* =================================================== */ -/* Output struct/enums */ -/* --------------------------------------------------- */ - -typedef struct { - -#if defined(SW_OUTTEXT) - /** pointer to output routine for text output */ - void (*pfunc_text)(OutPeriod, SW_RUN *); -#endif - -#if defined(RSOILWAT) || defined(SWNETCDF) - /** pointer to output routine for array output */ - void (*pfunc_mem)(OutPeriod, SW_RUN *); - -#elif defined(STEPWAT) - /** pointer to output routine for aggregated output across STEPWAT - * iterations */ - void (*pfunc_agg)(OutPeriod, SW_RUN *); - /** pointer to output routine for STEPWAT in-memory output */ - void (*pfunc_SXW)(OutPeriod, SW_RUN *); -#endif -} SW_OUTPUT_POINTERS; +}; #endif // DATATYPES_H From 5fe65df954537d6d25e5d932908bca00c2584d6f Mon Sep 17 00:00:00 2001 From: Nicholas Persley Date: Tue, 2 Jul 2024 22:04:40 -0400 Subject: [PATCH 03/19] Match code to new structs Commit following 88c6d6a - Update interfaces to match the removal of SW_OUTPUT, SW_OUTPUT_POINTERS, and SW_GEN_OUT including STEPWAT2 and rSOILWAT2 - SW_Output_get_functions.c output functions that do not deal with SOILWAT2 have been updated to accept a new parameter - SW_OUT_DOM SW_Output - Move the initialization/constructs information pertaining to SW_OUT_DOM and only does so to information within SW_OUT_RUN - Moved constant array "key2obj" to SW_Domain.c - Moved destruction of SW_OUT_DOM from SW_OUT_deconstruct to SW_DOM_deconstruct - Updated instance of '\ref ...' within SW_Output_outtext.c - Uses of information previously contained in SW_OUTPUT now index variable instead of specific struct in an array Tests - Same changes as within the source code * Removed instance of SW_OUTPUT_POINTERS * Update of interfaces/calls --- include/SW_Control.h | 22 +- include/SW_Output.h | 253 ++-- include/SW_Output_outarray.h | 6 +- include/SW_Output_outtext.h | 18 +- include/SW_netCDF.h | 24 +- src/SW_Control.c | 123 +- src/SW_Domain.c | 614 +++++++- src/SW_Main.c | 34 +- src/SW_Markov.c | 3 +- src/SW_Output.c | 1171 +++------------ src/SW_Output_get_functions.c | 2289 +++++++++++++++++------------ src/SW_Output_outarray.c | 50 +- src/SW_Output_outtext.c | 102 +- src/SW_netCDF.c | 244 ++- tests/gtests/sw_testhelpers.cc | 13 +- tests/gtests/sw_testhelpers.h | 20 +- tests/gtests/test_SW_SpinUp.cc | 26 +- tests/gtests/test_SW_VegEstab.cc | 2 +- tests/gtests/test_WaterBalance.cc | 32 +- 19 files changed, 2663 insertions(+), 2383 deletions(-) diff --git a/include/SW_Control.h b/include/SW_Control.h index 08a721385..fd92f9268 100644 --- a/include/SW_Control.h +++ b/include/SW_Control.h @@ -32,47 +32,41 @@ void SW_CTL_init_ptrs(SW_RUN *sw); void SW_CTL_alloc_outptrs(SW_RUN *sw, LOG_INFO *LogInfo); -void SW_ALL_deepCopy(SW_RUN *source, SW_RUN *dest, LOG_INFO *LogInfo); +void SW_ALL_deepCopy( + SW_RUN *source, SW_RUN *dest, SW_OUT_DOM *DomRun, LOG_INFO *LogInfo +); void SW_CTL_setup_domain( unsigned long userSUID, SW_DOMAIN *SW_Domain, LOG_INFO *LogInfo ); -void SW_CTL_setup_model( - SW_RUN *sw, SW_OUTPUT_POINTERS *SW_OutputPtrs, LOG_INFO *LogInfo -); +void SW_CTL_setup_model(SW_RUN *sw, SW_OUT_DOM *OutDom, LOG_INFO *LogInfo); void SW_CTL_clear_model(Bool full_reset, SW_RUN *sw); void SW_CTL_init_run(SW_RUN *sw, LOG_INFO *LogInfo); void SW_CTL_read_inputs_from_disk( - SW_RUN *sw, PATH_INFO *PathInfo, LOG_INFO *LogInfo + SW_RUN *sw, SW_OUT_DOM *OutDom, PATH_INFO *PathInfo, LOG_INFO *LogInfo ); -void SW_CTL_main( - SW_RUN *sw, SW_OUTPUT_POINTERS *SW_OutputPtrs, LOG_INFO *LogInfo -); +void SW_CTL_main(SW_RUN *sw, SW_OUT_DOM *OutDom, LOG_INFO *LogInfo); void SW_CTL_RunSimSet( SW_RUN *sw_template, - SW_OUTPUT_POINTERS SW_OutputPtrs[], SW_DOMAIN *SW_Domain, SW_WALLTIME *SW_WallTime, LOG_INFO *main_LogInfo ); -void SW_CTL_run_current_year( - SW_RUN *sw, SW_OUTPUT_POINTERS *SW_OutputPtrs, LOG_INFO *LogInfo -); +void SW_CTL_run_current_year(SW_RUN *sw, SW_OUT_DOM *OutDom, LOG_INFO *LogInfo); -void SW_CTL_run_spinup(SW_RUN *sw, LOG_INFO *LogInfo); +void SW_CTL_run_spinup(SW_RUN *sw, SW_OUT_DOM *OutDom, LOG_INFO *LogInfo); void SW_CTL_run_sw( SW_RUN *sw_template, SW_DOMAIN *SW_Domain, unsigned long ncSuid[], - SW_OUTPUT_POINTERS SW_OutputPtrs[], LOG_INFO *LogInfo ); diff --git a/include/SW_Output.h b/include/SW_Output.h index cdd265dbc..6738b31ed 100644 --- a/include/SW_Output.h +++ b/include/SW_Output.h @@ -156,17 +156,14 @@ extern char const *styp2longstr[]; /* Global Function Declarations */ /* --------------------------------------------------- */ -void SW_OUT_init_ptrs(SW_OUTPUT *SW_Output); - -void SW_GENOUT_init_ptrs(SW_GEN_OUT *GenOutput); +void SW_OUT_init_ptrs(SW_OUT_RUN *OutRun); void SW_OUT_construct( Bool make_soil[], Bool make_regular[], - SW_OUTPUT_POINTERS *SW_OutputPtrs, - SW_OUTPUT *SW_Output, + SW_OUT_DOM *OutDom, + SW_OUT_RUN *OutRun, LyrIndex n_layers, - SW_GEN_OUT *GenOutput, LOG_INFO *LogInfo ); @@ -194,13 +191,20 @@ void SW_OUT_setup_output( int tLayers, int n_evap_lyrs, SW_VEGESTAB *SW_VegEstab, - SW_GEN_OUT *SW_GenOutput, + SW_OUT_DOM *OutDom, LOG_INFO *LogInfo ); -void SW_OUT_new_year(TimeInt firstdoy, TimeInt lastdoy, SW_OUTPUT *SW_Output); +void SW_OUT_new_year( + TimeInt firstdoy, + TimeInt lastdoy, + SW_OUT_DOM *OutDom, + TimeInt first[], + TimeInt last[] +); int SW_OUT_read_onekey( + SW_OUT_DOM *OutDom, OutKey k, OutSum sumtype, int first, @@ -209,20 +213,16 @@ int SW_OUT_read_onekey( size_t sizeof_msg, Bool *VegProd_use_SWA, Bool deepdrain, - SW_OUTPUT *SW_Output, char *InFiles[] ); void SW_OUT_read( - SW_RUN *sw, - char *InFiles[], - OutPeriod timeSteps[][SW_OUTNPERIODS], - IntUS *used_OUTNPERIODS, - LOG_INFO *LogInfo + SW_RUN *sw, SW_OUT_DOM *OutDom, char *InFiles[], LOG_INFO *LogInfo ); void SW_OUT_sum_today( SW_RUN *sw, + SW_OUT_DOM *OutDom, ObjType otyp, Bool bFlush_output, TimeInt tOffset, @@ -230,43 +230,34 @@ void SW_OUT_sum_today( ); void SW_OUT_write_today( - SW_RUN *sw, - SW_OUTPUT_POINTERS *SW_OutputPtrs, - Bool bFlush_output, - TimeInt tOffset + SW_RUN *sw, SW_OUT_DOM *OutDom, Bool bFlush_output, TimeInt tOffset ); void SW_OUT_write_year(void); -void SW_OUT_flush( - SW_RUN *sw, SW_OUTPUT_POINTERS *SW_OutputPtrs, LOG_INFO *LogInfo -); +void SW_OUT_flush(SW_RUN *sw, SW_OUT_DOM *OutDom, LOG_INFO *LogInfo); void _collect_values( SW_RUN *sw, - SW_OUTPUT_POINTERS *SW_OutputPtrs, + SW_OUT_DOM *OutDom, Bool bFlush_output, TimeInt tOffset, LOG_INFO *LogInfo ); void SW_OUT_close_files( - SW_FILE_STATUS *SW_FileStatus, SW_GEN_OUT *GenOutput, LOG_INFO *LogInfo + SW_FILE_STATUS *SW_FileStatus, SW_OUT_DOM *OutDom, LOG_INFO *LogInfo ); void SW_OUT_create_files( - SW_FILE_STATUS *SW_FileStatus, - SW_DOMAIN *SW_Domain, - SW_OUTPUT *SW_Output, - SW_GEN_OUT *GenOutput, - LOG_INFO *LogInfo + SW_FILE_STATUS *SW_FileStatus, SW_DOMAIN *SW_Domain, LOG_INFO *LogInfo ); -void _echo_outputs(SW_RUN *sw); +void _echo_outputs(SW_OUT_DOM *OutDom); -void _echo_all_inputs(SW_RUN *sw); +void _echo_all_inputs(SW_RUN *sw, SW_OUT_DOM *OutDom); -void find_OutPeriods_inUse(SW_GEN_OUT *GenOutput, SW_OUTPUT *SW_Output); +void find_OutPeriods_inUse(SW_OUT_DOM *OutDom); Bool has_OutPeriod_inUse( OutPeriod pd, @@ -280,50 +271,40 @@ Bool has_keyname_soillayers(const char *var); Bool has_key_soillayers(OutKey k); #ifdef STEPWAT -Bool has_OutPeriod_inUse2(OutPeriod pd, OutKey k, SW_GEN_OUT *GenOutput); +Bool has_OutPeriod_inUse2(OutPeriod pd, OutKey k, SW_OUT_DOM *OutDom); void SW_OUT_set_SXWrequests( + SW_OUT_DOM *OutDom, OutPeriod timeSteps_SXW[][SW_OUTNPERIODS], - IntUS *used_OUTNPERIODS, - SW_OUTPUT *SW_Output, LOG_INFO *LogInfo ); #endif -void SW_GENOUT_deepCopy( - SW_GEN_OUT *dest, - SW_GEN_OUT *source, - SW_OUTPUT *SW_Output, - LOG_INFO *LogInfo -); - #if defined(SWNETCDF) void SW_OUT_deepCopy( - SW_OUTPUT *dest_out, - SW_OUTPUT *source_out, SW_FILE_STATUS *dest_files, SW_FILE_STATUS *source_files, - Bool useOutPeriods[], - IntUS nvar_OUT[], + SW_OUT_DOM *OutDom, LOG_INFO *LogInfo ); #endif - // Functions that format the output in `sw_outstr` for printing /* --------------------------------------------------- */ /* each of these get_ -type funcs return a * formatted string of the appropriate type and are - * pointed to by SW_Output[k].pfunc so they can be called - * anonymously by looping over the Output[k] list - * (see _output_today() for usage.) - * they all use the global-level string sw_outstr[]. + * pointed to by OutDom.pfunc[k] so they can be called + * anonymously by looping over the list of output functions + * in OutDom (SW_OUT_DOM) they all use the simulation-level + * string sw_outstr[] (SW_OUT_RUN). */ /* 10-May-02 (cwb) Added conditionals for interfacing with STEPPE * 05-Mar-03 (cwb) Added code for max,min,avg. Previously, only avg was output. * 22 June-15 (akt) Added code for adding surfaceAvg at output */ -void get_none(OutPeriod pd, SW_RUN *sw); /* default until defined */ +void get_none( + OutPeriod pd, SW_RUN *sw, SW_OUT_DOM *OutDom +); /* default until defined */ #if defined(SW_OUTTEXT) && !defined(SWNETCDF) void get_temp_text(OutPeriod pd, SW_RUN *sw); @@ -357,93 +338,93 @@ void get_biomass_text(OutPeriod pd, SW_RUN *sw); #endif #if defined(RSOILWAT) || defined(SWNETCDF) -void get_temp_mem(OutPeriod pd, SW_RUN *sw); -void get_precip_mem(OutPeriod pd, SW_RUN *sw); -void get_vwcBulk_mem(OutPeriod pd, SW_RUN *sw); -void get_vwcMatric_mem(OutPeriod pd, SW_RUN *sw); -void get_swcBulk_mem(OutPeriod pd, SW_RUN *sw); -void get_swpMatric_mem(OutPeriod pd, SW_RUN *sw); -void get_swaBulk_mem(OutPeriod pd, SW_RUN *sw); -void get_swaMatric_mem(OutPeriod pd, SW_RUN *sw); -void get_swa_mem(OutPeriod pd, SW_RUN *sw); -void get_surfaceWater_mem(OutPeriod pd, SW_RUN *sw); -void get_runoffrunon_mem(OutPeriod pd, SW_RUN *sw); -void get_transp_mem(OutPeriod pd, SW_RUN *sw); -void get_evapSoil_mem(OutPeriod pd, SW_RUN *sw); -void get_evapSurface_mem(OutPeriod pd, SW_RUN *sw); -void get_interception_mem(OutPeriod pd, SW_RUN *sw); -void get_soilinf_mem(OutPeriod pd, SW_RUN *sw); -void get_lyrdrain_mem(OutPeriod pd, SW_RUN *sw); -void get_hydred_mem(OutPeriod pd, SW_RUN *sw); -void get_aet_mem(OutPeriod pd, SW_RUN *sw); -void get_pet_mem(OutPeriod pd, SW_RUN *sw); -void get_wetdays_mem(OutPeriod pd, SW_RUN *sw); -void get_snowpack_mem(OutPeriod pd, SW_RUN *sw); -void get_deepswc_mem(OutPeriod pd, SW_RUN *sw); -void get_estab_mem(OutPeriod pd, SW_RUN *sw); -void get_soiltemp_mem(OutPeriod pd, SW_RUN *sw); -void get_frozen_mem(OutPeriod pd, SW_RUN *sw); -void get_co2effects_mem(OutPeriod pd, SW_RUN *sw); -void get_biomass_mem(OutPeriod pd, SW_RUN *sw); +void get_temp_mem(OutPeriod pd, SW_RUN *sw, SW_OUT_DOM *OutDom); +void get_precip_mem(OutPeriod pd, SW_RUN *sw, SW_OUT_DOM *OutDom); +void get_vwcBulk_mem(OutPeriod pd, SW_RUN *sw, SW_OUT_DOM *OutDom); +void get_vwcMatric_mem(OutPeriod pd, SW_RUN *sw, SW_OUT_DOM *OutDom); +void get_swcBulk_mem(OutPeriod pd, SW_RUN *sw, SW_OUT_DOM *OutDom); +void get_swpMatric_mem(OutPeriod pd, SW_RUN *sw, SW_OUT_DOM *OutDom); +void get_swaBulk_mem(OutPeriod pd, SW_RUN *sw, SW_OUT_DOM *OutDom); +void get_swaMatric_mem(OutPeriod pd, SW_RUN *sw, SW_OUT_DOM *OutDom); +void get_swa_mem(OutPeriod pd, SW_RUN *sw, SW_OUT_DOM *OutDom); +void get_surfaceWater_mem(OutPeriod pd, SW_RUN *sw, SW_OUT_DOM *OutDom); +void get_runoffrunon_mem(OutPeriod pd, SW_RUN *sw, SW_OUT_DOM *OutDom); +void get_transp_mem(OutPeriod pd, SW_RUN *sw, SW_OUT_DOM *OutDom); +void get_evapSoil_mem(OutPeriod pd, SW_RUN *sw, SW_OUT_DOM *OutDom); +void get_evapSurface_mem(OutPeriod pd, SW_RUN *sw, SW_OUT_DOM *OutDom); +void get_interception_mem(OutPeriod pd, SW_RUN *sw, SW_OUT_DOM *OutDom); +void get_soilinf_mem(OutPeriod pd, SW_RUN *sw, SW_OUT_DOM *OutDom); +void get_lyrdrain_mem(OutPeriod pd, SW_RUN *sw, SW_OUT_DOM *OutDom); +void get_hydred_mem(OutPeriod pd, SW_RUN *sw, SW_OUT_DOM *OutDom); +void get_aet_mem(OutPeriod pd, SW_RUN *sw, SW_OUT_DOM *OutDom); +void get_pet_mem(OutPeriod pd, SW_RUN *sw, SW_OUT_DOM *OutDom); +void get_wetdays_mem(OutPeriod pd, SW_RUN *sw, SW_OUT_DOM *OutDom); +void get_snowpack_mem(OutPeriod pd, SW_RUN *sw, SW_OUT_DOM *OutDom); +void get_deepswc_mem(OutPeriod pd, SW_RUN *sw, SW_OUT_DOM *OutDom); +void get_estab_mem(OutPeriod pd, SW_RUN *sw, SW_OUT_DOM *OutDom); +void get_soiltemp_mem(OutPeriod pd, SW_RUN *sw, SW_OUT_DOM *OutDom); +void get_frozen_mem(OutPeriod pd, SW_RUN *sw, SW_OUT_DOM *OutDom); +void get_co2effects_mem(OutPeriod pd, SW_RUN *sw, SW_OUT_DOM *OutDom); +void get_biomass_mem(OutPeriod pd, SW_RUN *sw, SW_OUT_DOM *OutDom); #elif defined(STEPWAT) -void get_temp_agg(OutPeriod pd, SW_RUN *sw); -void get_precip_agg(OutPeriod pd, SW_RUN *sw); -void get_vwcBulk_agg(OutPeriod pd, SW_RUN *sw); -void get_vwcMatric_agg(OutPeriod pd, SW_RUN *sw); -void get_swcBulk_agg(OutPeriod pd, SW_RUN *sw); -void get_swpMatric_agg(OutPeriod pd, SW_RUN *sw); -void get_swaBulk_agg(OutPeriod pd, SW_RUN *sw); -void get_swaMatric_agg(OutPeriod pd, SW_RUN *sw); -void get_swa_agg(OutPeriod pd, SW_RUN *sw); -void get_surfaceWater_agg(OutPeriod pd, SW_RUN *sw); -void get_runoffrunon_agg(OutPeriod pd, SW_RUN *sw); -void get_transp_agg(OutPeriod pd, SW_RUN *sw); -void get_evapSoil_agg(OutPeriod pd, SW_RUN *sw); -void get_evapSurface_agg(OutPeriod pd, SW_RUN *sw); -void get_interception_agg(OutPeriod pd, SW_RUN *sw); -void get_soilinf_agg(OutPeriod pd, SW_RUN *sw); -void get_lyrdrain_agg(OutPeriod pd, SW_RUN *sw); -void get_hydred_agg(OutPeriod pd, SW_RUN *sw); -void get_aet_agg(OutPeriod pd, SW_RUN *sw); -void get_pet_agg(OutPeriod pd, SW_RUN *sw); -void get_wetdays_agg(OutPeriod pd, SW_RUN *sw); -void get_snowpack_agg(OutPeriod pd, SW_RUN *sw); -void get_deepswc_agg(OutPeriod pd, SW_RUN *sw); -void get_estab_agg(OutPeriod pd, SW_RUN *sw); -void get_soiltemp_agg(OutPeriod pd, SW_RUN *sw); -void get_frozen_agg(OutPeriod pd, SW_RUN *sw); -void get_co2effects_agg(OutPeriod pd, SW_RUN *sw); -void get_biomass_agg(OutPeriod pd, SW_RUN *sw); - -void get_temp_SXW(OutPeriod pd, SW_RUN *sw); -void get_precip_SXW(OutPeriod pd, SW_RUN *sw); -void get_vwcBulk_SXW(OutPeriod pd, SW_RUN *sw); -void get_vwcMatric_SXW(OutPeriod pd, SW_RUN *sw); -void get_swcBulk_SXW(OutPeriod pd, SW_RUN *sw); -void get_swpMatric_SXW(OutPeriod pd, SW_RUN *sw); -void get_swaBulk_SXW(OutPeriod pd, SW_RUN *sw); -void get_swaMatric_SXW(OutPeriod pd, SW_RUN *sw); -void get_swa_SXW(OutPeriod pd, SW_RUN *sw); -void get_surfaceWater_SXW(OutPeriod pd, SW_RUN *sw); -void get_runoffrunon_SXW(OutPeriod pd, SW_RUN *sw); -void get_transp_SXW(OutPeriod pd, SW_RUN *sw); -void get_evapSoil_SXW(OutPeriod pd, SW_RUN *sw); -void get_evapSurface_SXW(OutPeriod pd, SW_RUN *sw); -void get_interception_SXW(OutPeriod pd, SW_RUN *sw); -void get_soilinf_SXW(OutPeriod pd, SW_RUN *sw); -void get_lyrdrain_SXW(OutPeriod pd, SW_RUN *sw); -void get_hydred_SXW(OutPeriod pd, SW_RUN *sw); -void get_aet_SXW(OutPeriod pd, SW_RUN *sw); -void get_pet_SXW(OutPeriod pd, SW_RUN *sw); -void get_wetdays_SXW(OutPeriod pd, SW_RUN *sw); -void get_snowpack_SXW(OutPeriod pd, SW_RUN *sw); -void get_deepswc_SXW(OutPeriod pd, SW_RUN *sw); -void get_estab_SXW(OutPeriod pd, SW_RUN *sw); -void get_soiltemp_SXW(OutPeriod pd, SW_RUN *sw); -void get_frozen_SXW(OutPeriod pd, SW_RUN *sw); -void get_co2effects_SXW(OutPeriod pd, SW_RUN *sw); -void get_biomass_SXW(OutPeriod pd, SW_RUN *sw); +void get_temp_agg(OutPeriod pd, SW_RUN *sw, SW_OUT_DOM *OutDom); +void get_precip_agg(OutPeriod pd, SW_RUN *sw, SW_OUT_DOM *OutDom); +void get_vwcBulk_agg(OutPeriod pd, SW_RUN *sw, SW_OUT_DOM *OutDom); +void get_vwcMatric_agg(OutPeriod pd, SW_RUN *sw, SW_OUT_DOM *OutDom); +void get_swcBulk_agg(OutPeriod pd, SW_RUN *sw, SW_OUT_DOM *OutDom); +void get_swpMatric_agg(OutPeriod pd, SW_RUN *sw, SW_OUT_DOM *OutDom); +void get_swaBulk_agg(OutPeriod pd, SW_RUN *sw, SW_OUT_DOM *OutDom); +void get_swaMatric_agg(OutPeriod pd, SW_RUN *sw, SW_OUT_DOM *OutDom); +void get_swa_agg(OutPeriod pd, SW_RUN *sw, SW_OUT_DOM *OutDom); +void get_surfaceWater_agg(OutPeriod pd, SW_RUN *sw, SW_OUT_DOM *OutDom); +void get_runoffrunon_agg(OutPeriod pd, SW_RUN *sw, SW_OUT_DOM *OutDom); +void get_transp_agg(OutPeriod pd, SW_RUN *sw, SW_OUT_DOM *OutDom); +void get_evapSoil_agg(OutPeriod pd, SW_RUN *sw, SW_OUT_DOM *OutDom); +void get_evapSurface_agg(OutPeriod pd, SW_RUN *sw, SW_OUT_DOM *OutDom); +void get_interception_agg(OutPeriod pd, SW_RUN *sw, SW_OUT_DOM *OutDom); +void get_soilinf_agg(OutPeriod pd, SW_RUN *sw, SW_OUT_DOM *OutDom); +void get_lyrdrain_agg(OutPeriod pd, SW_RUN *sw, SW_OUT_DOM *OutDom); +void get_hydred_agg(OutPeriod pd, SW_RUN *sw, SW_OUT_DOM *OutDom); +void get_aet_agg(OutPeriod pd, SW_RUN *sw, SW_OUT_DOM *OutDom); +void get_pet_agg(OutPeriod pd, SW_RUN *sw, SW_OUT_DOM *OutDom); +void get_wetdays_agg(OutPeriod pd, SW_RUN *sw, SW_OUT_DOM *OutDom); +void get_snowpack_agg(OutPeriod pd, SW_RUN *sw, SW_OUT_DOM *OutDom); +void get_deepswc_agg(OutPeriod pd, SW_RUN *sw, SW_OUT_DOM *OutDom); +void get_estab_agg(OutPeriod pd, SW_RUN *sw, SW_OUT_DOM *OutDom); +void get_soiltemp_agg(OutPeriod pd, SW_RUN *sw, SW_OUT_DOM *OutDom); +void get_frozen_agg(OutPeriod pd, SW_RUN *sw, SW_OUT_DOM *OutDom); +void get_co2effects_agg(OutPeriod pd, SW_RUN *sw, SW_OUT_DOM *OutDom); +void get_biomass_agg(OutPeriod pd, SW_RUN *sw, SW_OUT_DOM *OutDom); + +void get_temp_SXW(OutPeriod pd, SW_RUN *sw, SW_OUT_DOM *OutDom); +void get_precip_SXW(OutPeriod pd, SW_RUN *sw, SW_OUT_DOM *OutDom); +void get_vwcBulk_SXW(OutPeriod pd, SW_RUN *sw, SW_OUT_DOM *OutDom); +void get_vwcMatric_SXW(OutPeriod pd, SW_RUN *sw, SW_OUT_DOM *OutDom); +void get_swcBulk_SXW(OutPeriod pd, SW_RUN *sw, SW_OUT_DOM *OutDom); +void get_swpMatric_SXW(OutPeriod pd, SW_RUN *sw, SW_OUT_DOM *OutDom); +void get_swaBulk_SXW(OutPeriod pd, SW_RUN *sw, SW_OUT_DOM *OutDom); +void get_swaMatric_SXW(OutPeriod pd, SW_RUN *sw, SW_OUT_DOM *OutDom); +void get_swa_SXW(OutPeriod pd, SW_RUN *sw, SW_OUT_DOM *OutDom); +void get_surfaceWater_SXW(OutPeriod pd, SW_RUN *sw, SW_OUT_DOM *OutDom); +void get_runoffrunon_SXW(OutPeriod pd, SW_RUN *sw, SW_OUT_DOM *OutDom); +void get_transp_SXW(OutPeriod pd, SW_RUN *sw, SW_OUT_DOM *OutDom); +void get_evapSoil_SXW(OutPeriod pd, SW_RUN *sw, SW_OUT_DOM *OutDom); +void get_evapSurface_SXW(OutPeriod pd, SW_RUN *sw, SW_OUT_DOM *OutDom); +void get_interception_SXW(OutPeriod pd, SW_RUN *sw, SW_OUT_DOM *OutDom); +void get_soilinf_SXW(OutPeriod pd, SW_RUN *sw, SW_OUT_DOM *OutDom); +void get_lyrdrain_SXW(OutPeriod pd, SW_RUN *sw, SW_OUT_DOM *OutDom); +void get_hydred_SXW(OutPeriod pd, SW_RUN *sw, SW_OUT_DOM *OutDom); +void get_aet_SXW(OutPeriod pd, SW_RUN *sw, SW_OUT_DOM *OutDom); +void get_pet_SXW(OutPeriod pd, SW_RUN *sw, SW_OUT_DOM *OutDom); +void get_wetdays_SXW(OutPeriod pd, SW_RUN *sw, SW_OUT_DOM *OutDom); +void get_snowpack_SXW(OutPeriod pd, SW_RUN *sw, SW_OUT_DOM *OutDom); +void get_deepswc_SXW(OutPeriod pd, SW_RUN *sw, SW_OUT_DOM *OutDom); +void get_estab_SXW(OutPeriod pd, SW_RUN *sw, SW_OUT_DOM *OutDom); +void get_soiltemp_SXW(OutPeriod pd, SW_RUN *sw, SW_OUT_DOM *OutDom); +void get_frozen_SXW(OutPeriod pd, SW_RUN *sw, SW_OUT_DOM *OutDom); +void get_co2effects_SXW(OutPeriod pd, SW_RUN *sw, SW_OUT_DOM *OutDom); +void get_biomass_SXW(OutPeriod pd, SW_RUN *sw, SW_OUT_DOM *OutDom); #endif diff --git a/include/SW_Output_outarray.h b/include/SW_Output_outarray.h index 3f9b4505b..ffd22c232 100644 --- a/include/SW_Output_outarray.h +++ b/include/SW_Output_outarray.h @@ -17,7 +17,7 @@ #define SW_OUTPUT_ARRAY_H #include "include/generic.h" // for Bool, RealD -#include "include/SW_datastructs.h" // for SW_MODEL, SW_OUTPUT, SW_GEN_OUT, L... +#include "include/SW_datastructs.h" // for SW_MODEL, L... #include "include/SW_Defines.h" // for OutPeriod, SW_OUTNPERIODS, SW_OUTN... #include // for size_t @@ -114,10 +114,10 @@ void SW_OUT_set_nrow( ); void SW_OUT_construct_outarray( - SW_GEN_OUT *GenOutput, SW_OUTPUT *SW_Output, LOG_INFO *LogInfo + SW_OUT_DOM *OutDom, SW_OUT_RUN *OutRun, LOG_INFO *LogInfo ); -void SW_OUT_deconstruct_outarray(SW_GEN_OUT *GenOutput); +void SW_OUT_deconstruct_outarray(SW_OUT_RUN *OutRun); #ifdef RSOILWAT void get_outvalleader( diff --git a/include/SW_Output_outtext.h b/include/SW_Output_outtext.h index dfcf08a69..43a1557be 100644 --- a/include/SW_Output_outtext.h +++ b/include/SW_Output_outtext.h @@ -17,7 +17,7 @@ #define SW_OUTPUT_TXT_H #include "include/generic.h" // for Bool -#include "include/SW_datastructs.h" // for SW_FILE_STATUS, SW_OUTPUT, LOG_INFO +#include "include/SW_datastructs.h" // for SW_FILE_STATUS, LOG_INFO #include "include/SW_Defines.h" // for SW_OUTNPERIODS #include // for size_t @@ -30,29 +30,26 @@ extern "C" { /* --------------------------------------------------- */ #if defined(SOILWAT) void SW_OUT_create_textfiles( + SW_OUT_DOM *OutDom, SW_FILE_STATUS *SW_FileStatus, - SW_OUTPUT *SW_Output, LyrIndex n_layers, char *InFiles[], - SW_GEN_OUT *GenOutput, LOG_INFO *LogInfo ); #elif defined(STEPWAT) void SW_OUT_create_summary_files( + SW_OUT_DOM *OutDom, SW_FILE_STATUS *SW_FileStatus, - SW_OUTPUT *SW_Output, - SW_GEN_OUT *GenOutput, char *InFiles[], LyrIndex n_layers, LOG_INFO *LogInfo ); void SW_OUT_create_iteration_files( + SW_OUT_DOM *OutDom, SW_FILE_STATUS *SW_FileStatus, - SW_OUTPUT *SW_Output, int iteration, - SW_GEN_OUT *GenOutput, char *InFiles[], LyrIndex n_layers, LOG_INFO *LogInfo @@ -68,28 +65,27 @@ void get_outstrleader( ); void write_headers_to_csv( + SW_OUT_DOM *OutDom, OutPeriod pd, FILE *fp_reg, FILE *fp_soil, Bool does_agg, Bool make_regular[], Bool make_soil[], - SW_OUTPUT *SW_Output, LyrIndex n_layers, - SW_GEN_OUT *GenOutput, LOG_INFO *LogInfo ); void find_TXToutputSoilReg_inUse( Bool make_soil[], Bool make_regular[], - SW_OUTPUT *SW_Output, + Bool has_sl[], OutPeriod timeSteps[][SW_OUTNPERIODS], IntUS used_OUTNPERIODS ); void SW_OUT_close_textfiles( - SW_FILE_STATUS *SW_FileStatus, SW_GEN_OUT *GenOutput, LOG_INFO *LogInfo + SW_FILE_STATUS *SW_FileStatus, SW_OUT_DOM *OutDom, LOG_INFO *LogInfo ); diff --git a/include/SW_netCDF.h b/include/SW_netCDF.h index e86cbae0e..67758feaf 100644 --- a/include/SW_netCDF.h +++ b/include/SW_netCDF.h @@ -2,7 +2,7 @@ #define SWNETCDF_H #include "include/generic.h" // for Bool, IntUS -#include "include/SW_datastructs.h" // for SW_DOMAIN, SW_NETCDF, SW_OUTPUT, S... +#include "include/SW_datastructs.h" // for SW_DOMAIN, SW_NETCDF, S... #include "include/SW_Defines.h" // for OutPeriod, SW_OUTNPERIODS, SW_OUTN... #include // for size_t @@ -47,8 +47,8 @@ extern "C" { /* Global Function Declarations */ /* --------------------------------------------------- */ void SW_NC_write_output( - SW_OUTPUT *SW_Output, - SW_GEN_OUT *GenOutput, + SW_OUT_DOM *OutDom, + RealD *p_OUT[][SW_OUTNPERIODS], int numFilesPerKey, char **ncOutFileNames[][SW_OUTNPERIODS], size_t ncSuid[], @@ -61,7 +61,6 @@ void SW_NC_create_output_files( const char *domType, const char *output_prefix, SW_DOMAIN *SW_Domain, - SW_OUTPUT *SW_Output, OutPeriod timeSteps[][SW_OUTNPERIODS], IntUS used_OUTNPERIODS, IntUS nvar_OUT[], @@ -131,16 +130,13 @@ void SW_NC_check_input_files(SW_DOMAIN *SW_Domain, LOG_INFO *LogInfo); void SW_NC_read(SW_NETCDF *SW_netCDF, PATH_INFO *PathInfo, LOG_INFO *LogInfo); void SW_NC_read_out_vars( - SW_OUTPUT *SW_Output, - SW_GEN_OUT *GenOutput, + SW_OUT_DOM *OutDom, char *InFiles[], SW_VEGESTAB_INFO **parms, LOG_INFO *LogInfo ); -void SW_NC_create_units_converters( - SW_OUTPUT *SW_Output, IntUS *nVars, LOG_INFO *LogInfo -); +void SW_NC_create_units_converters(SW_OUT_DOM *OutDom, LOG_INFO *LogInfo); void SW_NC_init_ptrs(SW_NETCDF *SW_netCDF); @@ -152,16 +148,12 @@ void SW_NC_close_files(SW_NETCDF *SW_netCDF); void SW_NC_deepCopy(SW_NETCDF *source, SW_NETCDF *dest, LOG_INFO *LogInfo); -void SW_NC_dealloc_outputkey_var_info( - SW_OUTPUT *SW_Output, IntUS k, IntUS *nVars -); +void SW_NC_dealloc_outputkey_var_info(SW_OUT_DOM *OutDom, IntUS k); -void SW_NC_alloc_output_var_info( - SW_OUTPUT *SW_Output, IntUS *nVars, LOG_INFO *LogInfo -); +void SW_NC_alloc_output_var_info(SW_OUT_DOM *OutDom, LOG_INFO *LogInfo); void SW_NC_alloc_outputkey_var_info( - SW_OUTPUT *currOut, IntUS nVar, LOG_INFO *LogInfo + SW_OUT_DOM *OutDom, int key, LOG_INFO *LogInfo ); void SW_NC_alloc_files(char ***ncOutFiles, int numFiles, LOG_INFO *LogInfo); diff --git a/src/SW_Control.c b/src/SW_Control.c index 7ec1d7989..4a63140ba 100644 --- a/src/SW_Control.c +++ b/src/SW_Control.c @@ -58,6 +58,7 @@ #if defined(SWNETCDF) #include "include/SW_netCDF.h" +#include "include/SW_Output_outarray.h" #endif @@ -71,9 +72,11 @@ @param[in,out] sw Comprehensive struct of type SW_RUN containing all information in the simulation +@param[in] OutDom Struct of type SW_OUT_DOM that holds output + information that do not change throughout simulation runs @param[out] LogInfo Holds information on warnings and errors */ -static void _begin_year(SW_RUN *sw, LOG_INFO *LogInfo) { +static void _begin_year(SW_RUN *sw, SW_OUT_DOM *OutDom, LOG_INFO *LogInfo) { // SW_F_new_year() not needed // call SW_MDL_new_year() first to set up time-related arrays for this year @@ -101,7 +104,13 @@ static void _begin_year(SW_RUN *sw, LOG_INFO *LogInfo) { } // SW_CBN_new_year() not needed - SW_OUT_new_year(sw->Model.firstdoy, sw->Model.lastdoy, sw->Output); + SW_OUT_new_year( + sw->Model.firstdoy, + sw->Model.lastdoy, + OutDom, + sw->OutRun.first, + sw->OutRun.last + ); } static void _begin_day(SW_RUN *sw, LOG_INFO *LogInfo) { @@ -116,13 +125,11 @@ static void _begin_day(SW_RUN *sw, LOG_INFO *LogInfo) { ); } -static void _end_day( - SW_RUN *sw, SW_OUTPUT_POINTERS *SW_OutputPtrs, LOG_INFO *LogInfo -) { +static void _end_day(SW_RUN *sw, SW_OUT_DOM *OutDom, LOG_INFO *LogInfo) { int localTOffset = 1; // tOffset is one when called from this function if (sw->Model.doOutput) { - _collect_values(sw, SW_OutputPtrs, swFALSE, localTOffset, LogInfo); + _collect_values(sw, OutDom, swFALSE, localTOffset, LogInfo); if (LogInfo->stopRun) { return; // Exit function prematurely due to error } @@ -136,9 +143,14 @@ static void _end_day( @param[in] source Source struct of type SW_RUN to copy @param[out] dest Destination struct of type SW_RUN to be copied into +@param[in] OutDom Struct of type SW_OUT_DOM that holds output + information that do not change throughout simulation runs @param[out] LogInfo Holds information on warnings and errors */ -void SW_ALL_deepCopy(SW_RUN *source, SW_RUN *dest, LOG_INFO *LogInfo) { +void SW_ALL_deepCopy( + SW_RUN *source, SW_RUN *dest, SW_OUT_DOM *OutDom, LOG_INFO *LogInfo +) { + memcpy(dest, source, sizeof(*dest)); /* Allocate memory for output pointers */ @@ -202,24 +214,12 @@ void SW_ALL_deepCopy(SW_RUN *source, SW_RUN *dest, LOG_INFO *LogInfo) { return; // Exit function prematurely due to error } -#if defined(SWNETCDF) - SW_OUT_deepCopy( - dest->Output, - source->Output, - &dest->FileStatus, - &source->FileStatus, - source->GenOutput.use_OutPeriod, - source->GenOutput.nvar_OUT, - LogInfo - ); - if (LogInfo->stopRun) { - return; // Exit function prematurely due to error - } +#ifdef SWNETCDF + SW_OUT_deepCopy(&dest->FileStatus, &source->FileStatus, OutDom, LogInfo); + SW_OUT_construct_outarray(OutDom, &dest->OutRun, LogInfo); +#else + (void) OutDom; #endif - - SW_GENOUT_deepCopy( - &dest->GenOutput, &source->GenOutput, source->Output, LogInfo - ); } /* =================================================== */ @@ -231,14 +231,12 @@ void SW_ALL_deepCopy(SW_RUN *source, SW_RUN *dest, LOG_INFO *LogInfo) { @param[in,out] sw Comprehensive struct of type SW_RUN containing all information in the simulation -@param[in,out] SW_OutputPtrs SW_OUTPUT_POINTERS of size SW_OUTNKEYS which - hold pointers to subroutines for output keys +@param[in,out] OutDom Struct of type SW_OUT_DOM that holds output + information that do not change throughout simulation runs @param[out] LogInfo Holds information on warnings and errors */ -void SW_CTL_main( - SW_RUN *sw, SW_OUTPUT_POINTERS *SW_OutputPtrs, LOG_INFO *LogInfo -) { +void SW_CTL_main(SW_RUN *sw, SW_OUT_DOM *OutDom, LOG_INFO *LogInfo) { #ifdef SWDEBUG int debug = 0; #endif @@ -252,7 +250,7 @@ void SW_CTL_main( } #endif - SW_CTL_run_current_year(sw, SW_OutputPtrs, LogInfo); + SW_CTL_run_current_year(sw, OutDom, LogInfo); if (LogInfo->stopRun) { return; // Exit function prematurely due to error } @@ -261,7 +259,6 @@ void SW_CTL_main( void SW_CTL_RunSimSet( SW_RUN *sw_template, - SW_OUTPUT_POINTERS SW_OutputPtrs[], SW_DOMAIN *SW_Domain, SW_WALLTIME *SW_WallTime, LOG_INFO *main_LogInfo @@ -319,9 +316,7 @@ void SW_CTL_RunSimSet( /* Simulate suid */ set_walltime(&tsr, &ok_tsr); - SW_CTL_run_sw( - sw_template, SW_Domain, ncSuid, SW_OutputPtrs, &local_LogInfo - ); + SW_CTL_run_sw(sw_template, SW_Domain, ncSuid, &local_LogInfo); SW_WT_TimeRun(tsr, ok_tsr, SW_WallTime); /* Report progress for suid */ @@ -378,8 +373,7 @@ void SW_CTL_init_ptrs(SW_RUN *sw) { SW_MKV_init_ptrs(&sw->Markov); SW_VES_init_ptrs(&sw->VegEstab); SW_VPD_init_ptrs(&sw->VegProd); - SW_OUT_init_ptrs(sw->Output); - SW_GENOUT_init_ptrs(&sw->GenOutput); + SW_OUT_init_ptrs(&sw->OutRun); SW_SWC_init_ptrs(&sw->SoilWat); } @@ -503,13 +497,11 @@ void SW_CTL_setup_domain( @param[in,out] sw Comprehensive struct of type SW_RUN containing all information in the simulation -@param[in,out] SW_OutputPtrs SW_OUTPUT_POINTERS of size SW_OUTNKEYS which - hold pointers to subroutines for output keys +@param[in,out] OutDom Struct of type SW_OUT_DOM that holds output + information that do not change throughout simulation runs @param[out] LogInfo Holds information on warnings and errors */ -void SW_CTL_setup_model( - SW_RUN *sw, SW_OUTPUT_POINTERS *SW_OutputPtrs, LOG_INFO *LogInfo -) { +void SW_CTL_setup_model(SW_RUN *sw, SW_OUT_DOM *OutDom, LOG_INFO *LogInfo) { SW_MDL_construct(&sw->Model); SW_WTH_construct(&sw->Weather); @@ -522,10 +514,9 @@ void SW_CTL_setup_model( SW_OUT_construct( sw->FileStatus.make_soil, sw->FileStatus.make_regular, - SW_OutputPtrs, - sw->Output, + OutDom, + &sw->OutRun, sw->Site.n_layers, - &sw->GenOutput, LogInfo ); if (LogInfo->stopRun) { @@ -616,12 +607,12 @@ void SW_CTL_init_run(SW_RUN *sw, LOG_INFO *LogInfo) { @param[in,out] sw Comprehensive struct of type SW_RUN containing all information in the simulation -@param[in,out] SW_OutputPtrs SW_OUTPUT_POINTERS of size SW_OUTNKEYS which - hold pointers to subroutines for output keys +@param[in,out] OutDom Struct of type SW_OUT_DOM that holds output + information that do not change throughout simulation runs @param[out] LogInfo Holds information on warnings and errors */ void SW_CTL_run_current_year( - SW_RUN *sw, SW_OUTPUT_POINTERS *SW_OutputPtrs, LOG_INFO *LogInfo + SW_RUN *sw, SW_OUT_DOM *OutDom, LOG_INFO *LogInfo ) { /*=======================================================*/ TimeInt *doy = &sw->Model.doy; // base1 @@ -634,7 +625,7 @@ void SW_CTL_run_current_year( sw_printf("\n'SW_CTL_run_current_year': begin new year\n"); } #endif - _begin_year(sw, LogInfo); + _begin_year(sw, OutDom, LogInfo); if (LogInfo->stopRun) { return; // Exit function prematurely due to error } @@ -686,7 +677,7 @@ void SW_CTL_run_current_year( sw_printf("ending day ... "); } #endif - _end_day(sw, SW_OutputPtrs, LogInfo); + _end_day(sw, OutDom, LogInfo); if (LogInfo->stopRun) { return; // Exit function prematurely due to error } @@ -704,7 +695,7 @@ void SW_CTL_run_current_year( } #endif if (sw->Model.doOutput) { - SW_OUT_flush(sw, SW_OutputPtrs, LogInfo); + SW_OUT_flush(sw, OutDom, LogInfo); } #ifdef SWDEBUG @@ -733,9 +724,11 @@ void SW_CTL_run_current_year( @param[in,out] sw Comprehensive struct of type SW_RUN containing all information in the simulation +@param[in] OutDom Struct of type SW_OUT_DOM that holds output + information that do not change throughout simulation runs @param[out] LogInfo Holds information dealing with logfile output */ -void SW_CTL_run_spinup(SW_RUN *sw, LOG_INFO *LogInfo) { +void SW_CTL_run_spinup(SW_RUN *sw, SW_OUT_DOM *OutDom, LOG_INFO *LogInfo) { if (sw->Model.SW_SpinUp.duration <= 0) { return; @@ -749,7 +742,6 @@ void SW_CTL_run_spinup(SW_RUN *sw, LOG_INFO *LogInfo) { TimeInt finalyr = sw->Model.startyr + scope - 1; TimeInt *years; Bool prev_doOut = sw->Model.doOutput; - years = (TimeInt *) Mem_Malloc( sizeof(TimeInt) * duration, "SW_CTL_run_spinup()", LogInfo ); @@ -830,7 +822,7 @@ void SW_CTL_run_spinup(SW_RUN *sw, LOG_INFO *LogInfo) { } #endif - SW_CTL_run_current_year(sw, NULL, LogInfo); + SW_CTL_run_current_year(sw, OutDom, LogInfo); if (LogInfo->stopRun) { goto reSet; // Exit function prematurely due to error } @@ -850,12 +842,14 @@ reSet: { @param[in,out] sw Comprehensive struct of type SW_RUN containing all information in the simulation +@param[in,out] OutDom Struct of type SW_OUT_DOM that holds output + information that do not change throughout simulation runs @param[in,out] PathInfo Struct holding all information about the programs path/files @param[out] LogInfo Holds information on warnings and errors */ void SW_CTL_read_inputs_from_disk( - SW_RUN *sw, PATH_INFO *PathInfo, LOG_INFO *LogInfo + SW_RUN *sw, SW_OUT_DOM *OutDom, PATH_INFO *PathInfo, LOG_INFO *LogInfo ) { #ifdef SWDEBUG int debug = 0; @@ -977,13 +971,7 @@ void SW_CTL_read_inputs_from_disk( } #endif - SW_OUT_read( - sw, - PathInfo->InFiles, - sw->GenOutput.timeSteps, - &sw->GenOutput.used_OUTNPERIODS, - LogInfo - ); + SW_OUT_read(sw, OutDom, PathInfo->InFiles, LogInfo); if (LogInfo->stopRun) { return; // Exit function prematurely due to error } @@ -1027,15 +1015,12 @@ on error but end early and report to caller temporal/spatial information for a set of simulation runs @param[in] ncSuid Unique indentifier of the first suid to run in relation to netCDF gridcells/sites -@param[in,out] SW_OutputPtrs SW_OUTPUT_POINTERS of size SW_OUTNKEYS which - hold pointers to subroutines for output keys @param[out] LogInfo Holds information on warnings and errors */ void SW_CTL_run_sw( SW_RUN *sw_template, SW_DOMAIN *SW_Domain, unsigned long ncSuid[], - SW_OUTPUT_POINTERS SW_OutputPtrs[], LOG_INFO *LogInfo ) { @@ -1046,7 +1031,7 @@ void SW_CTL_run_sw( SW_RUN local_sw; // Copy template SW_RUN to local instance - SW_ALL_deepCopy(sw_template, &local_sw, LogInfo); + SW_ALL_deepCopy(sw_template, &local_sw, &SW_Domain->OutDom, LogInfo); if (LogInfo->stopRun) { goto freeMem; // Free memory and skip simulation run } @@ -1073,18 +1058,18 @@ void SW_CTL_run_sw( #endif if (SW_Domain->SW_SpinUp.spinup) { - SW_CTL_run_spinup(&local_sw, LogInfo); + SW_CTL_run_spinup(&local_sw, &SW_Domain->OutDom, LogInfo); } - SW_CTL_main(&local_sw, SW_OutputPtrs, LogInfo); + SW_CTL_main(&local_sw, &SW_Domain->OutDom, LogInfo); if (LogInfo->stopRun) { goto freeMem; // Free memory and exit function prematurely due to error } #if defined(SWNETCDF) SW_NC_write_output( - local_sw.Output, - &local_sw.GenOutput, + &SW_Domain->OutDom, + local_sw.OutRun.p_OUT, local_sw.FileStatus.numOutFiles, local_sw.FileStatus.ncOutFiles, ncSuid, diff --git a/src/SW_Domain.c b/src/SW_Domain.c index c2042e6d3..842ec59a9 100644 --- a/src/SW_Domain.c +++ b/src/SW_Domain.c @@ -5,9 +5,11 @@ #include "include/SW_Domain.h" // for SW_DOM_CheckProgress, SW_DOM_Cre... #include "include/filefuncs.h" // for LogError, CloseFile, key_to_id #include "include/generic.h" // for swTRUE, LOGERROR, swFALSE, Bool +#include "include/myMemory.h" // for Str_Dup #include "include/SW_datastructs.h" // for SW_DOMAIN, LOG_INFO #include "include/SW_Defines.h" // for LyrIndex, LARGE_VALUE, TimeInt #include "include/SW_Files.h" // for SW_F_deconstruct, SW_F_deepCopy +#include "include/SW_Output.h" // for ForEachOutKey #include "include/Times.h" // for yearto4digit, Time_get_lastdoy_y #include // for sscanf, FILE #include // for atoi, atof @@ -21,6 +23,48 @@ #include "include/rands.h" // for RandSeed #endif +/* converts an enum output key (OutKey type) to a module */ +/* or object type. see SW_Output.h for OutKey order. */ +/* MUST be SW_OUTNKEYS of these */ +ObjType key2obj[] = { + // weather/atmospheric quantities: + eWTH, + eWTH, + eWTH, + eWTH, + eWTH, + // soil related water quantities: + eSWC, + eSWC, + eSWC, + eSWC, + eSWC, + eSWC, + eSWC, + eSWC, + eSWC, + eSWC, + eSWC, + eSWC, + eSWC, + eSWC, + eSWC, + eSWC, + eSWC, + eSWC, + eSWC, + eSWC, + eSWC, + eSWC, + eSWC, + // vegetation quantities: + eVES, + eVES, + // vegetation other: + eVPD, + eVPD +}; + /* =================================================== */ /* Local Defines */ @@ -116,7 +160,8 @@ void SW_DOM_CreateProgress(SW_DOMAIN *SW_Domain, LOG_INFO *LogInfo) { } /** -@brief Domain constructor for global variables. +@brief Domain constructor for global variables which are constant between + simulation runs. @param[in] rng_seed Initial state for spinup RNG @param[out] SW_Domain Struct of type SW_DOMAIN which @@ -124,6 +169,11 @@ void SW_DOM_CreateProgress(SW_DOMAIN *SW_Domain, LOG_INFO *LogInfo) { */ void SW_DOM_construct(unsigned long rng_seed, SW_DOMAIN *SW_Domain) { + IntUS k; + OutPeriod p; + + SW_OUT_DOM *OutDom = &SW_Domain->OutDom; + /* Set seed of `spinup_rng` - SOILWAT2: set seed here - STEPWAT2: `main()` uses `Globals.randseed` to (re-)set for each iteration @@ -135,7 +185,6 @@ void SW_DOM_construct(unsigned long rng_seed, SW_DOMAIN *SW_Domain) { (void) rng_seed; // Silence compiler flag `-Wunused-parameter` #endif - SW_Domain->nMaxSoilLayers = 0; SW_Domain->nMaxEvapLayers = 0; SW_Domain->hasConsistentSoilLayerDepths = swFALSE; @@ -144,6 +193,519 @@ void SW_DOM_construct(unsigned long rng_seed, SW_DOMAIN *SW_Domain) { 0., sizeof(&SW_Domain->depthsAllSoilLayers[0]) * MAX_LAYERS ); + +#if defined(SOILWAT) + OutDom->print_SW_Output = swTRUE; + OutDom->print_IterationSummary = swFALSE; +#elif defined(STEPWAT) + OutDom->print_SW_Output = (Bool) OutDom->storeAllIterations; +// `print_IterationSummary` is set by STEPWAT2's `main` function +#endif + +#if defined(SW_OUTARRAY) + ForEachOutPeriod(p) { + OutDom->nrow_OUT[p] = 0; + } +#endif + + /* attach the printing functions for each output + * quantity to the appropriate element in the + * output structure. Using a loop makes it convenient + * to simply add a line as new quantities are + * implemented and leave the default case for every + * thing else. + */ + ForEachOutKey(k) { + ForEachOutPeriod(p) { + OutDom->timeSteps[k][p] = eSW_NoTime; + +#ifdef STEPWAT + OutDom->timeSteps_SXW[k][p] = eSW_NoTime; +#endif + } + + // default values for `SW_Output`: + OutDom->use[k] = swFALSE; + OutDom->mykey[k] = (OutKey) k; + OutDom->myobj[k] = key2obj[k]; + OutDom->sumtype[k] = eSW_Off; + OutDom->has_sl[k] = has_key_soillayers((OutKey) k); + OutDom->first_orig[k] = 1; + OutDom->last_orig[k] = 366; + +#if defined(SWNETCDF) + OutDom->outputVarInfo[k] = NULL; + OutDom->reqOutputVars[k] = NULL; + OutDom->units_sw[k] = NULL; + OutDom->uconv[k] = NULL; +#endif + + // assign `get_XXX` functions + switch (k) { + case eSW_Temp: +#if defined(SW_OUTTEXT) + OutDom->pfunc_text[k] = + (void (*)(OutPeriod, SW_RUN *)) get_temp_text; +#endif +#if defined(RSOILWAT) || defined(SWNETCDF) + OutDom->pfunc_mem[k] = + (void (*)(OutPeriod, SW_RUN *, SW_OUT_DOM *)) get_temp_mem; +#elif defined(STEPWAT) + OutDom->pfunc_agg[k] = + (void (*)(OutPeriod, SW_RUN *, SW_OUT_DOM *)) get_temp_agg; + OutDom->pfunc_SXW[k] = + (void (*)(OutPeriod, SW_RUN *, SW_OUT_DOM *)) get_temp_SXW; +#endif + break; + + case eSW_Precip: +#if defined(SW_OUTTEXT) + OutDom->pfunc_text[k] = + (void (*)(OutPeriod, SW_RUN *)) get_precip_text; +#endif +#if defined(RSOILWAT) || defined(SWNETCDF) + OutDom->pfunc_mem[k] = + (void (*)(OutPeriod, SW_RUN *, SW_OUT_DOM *)) get_precip_mem; +#elif defined(STEPWAT) + OutDom->pfunc_agg[k] = + (void (*)(OutPeriod, SW_RUN *, SW_OUT_DOM *)) get_precip_agg; + OutDom->pfunc_SXW[k] = + (void (*)(OutPeriod, SW_RUN *, SW_OUT_DOM *)) get_precip_SXW; +#endif + break; + + case eSW_VWCBulk: +#if defined(SW_OUTTEXT) + OutDom->pfunc_text[k] = + (void (*)(OutPeriod, SW_RUN *)) get_vwcBulk_text; +#endif +#if defined(RSOILWAT) || defined(SWNETCDF) + OutDom->pfunc_mem[k] = + (void (*)(OutPeriod, SW_RUN *, SW_OUT_DOM *)) get_vwcBulk_mem; +#elif defined(STEPWAT) + OutDom->pfunc_agg[k] = + (void (*)(OutPeriod, SW_RUN *, SW_OUT_DOM *)) get_vwcBulk_agg; + OutDom->pfunc_SXW[k] = + (void (*)(OutPeriod, SW_RUN *, SW_OUT_DOM *)) get_none; +#endif + break; + + case eSW_VWCMatric: +#if defined(SW_OUTTEXT) + OutDom->pfunc_text[k] = + (void (*)(OutPeriod, SW_RUN *)) get_vwcMatric_text; +#endif +#if defined(RSOILWAT) || defined(SWNETCDF) + OutDom->pfunc_mem[k] = + (void (*)(OutPeriod, SW_RUN *, SW_OUT_DOM *)) get_vwcMatric_mem; +#elif defined(STEPWAT) + OutDom->pfunc_agg[k] = + (void (*)(OutPeriod, SW_RUN *, SW_OUT_DOM *)) get_vwcMatric_agg; + OutDom->pfunc_SXW[k] = + (void (*)(OutPeriod, SW_RUN *, SW_OUT_DOM *)) get_none; +#endif + break; + + case eSW_SWCBulk: +#if defined(SW_OUTTEXT) + OutDom->pfunc_text[k] = + (void (*)(OutPeriod, SW_RUN *)) get_swcBulk_text; +#endif +#if defined(RSOILWAT) || defined(SWNETCDF) + OutDom->pfunc_mem[k] = + (void (*)(OutPeriod, SW_RUN *, SW_OUT_DOM *)) get_swcBulk_mem; +#elif defined(STEPWAT) + OutDom->pfunc_agg[k] = + (void (*)(OutPeriod, SW_RUN *, SW_OUT_DOM *)) get_swcBulk_agg; + OutDom->pfunc_SXW[k] = + (void (*)(OutPeriod, SW_RUN *, SW_OUT_DOM *)) get_swcBulk_SXW; +#endif + break; + + case eSW_SWPMatric: +#if defined(SW_OUTTEXT) + OutDom->pfunc_text[k] = + (void (*)(OutPeriod, SW_RUN *)) get_swpMatric_text; +#endif +#if defined(RSOILWAT) || defined(SWNETCDF) + OutDom->pfunc_mem[k] = + (void (*)(OutPeriod, SW_RUN *, SW_OUT_DOM *)) get_swpMatric_mem; +#elif defined(STEPWAT) + OutDom->pfunc_agg[k] = + (void (*)(OutPeriod, SW_RUN *, SW_OUT_DOM *)) get_swpMatric_agg; + OutDom->pfunc_SXW[k] = + (void (*)(OutPeriod, SW_RUN *, SW_OUT_DOM *)) get_none; +#endif + break; + + case eSW_SWABulk: +#if defined(SW_OUTTEXT) + OutDom->pfunc_text[k] = + (void (*)(OutPeriod, SW_RUN *)) get_swaBulk_text; +#endif +#if defined(RSOILWAT) || defined(SWNETCDF) + OutDom->pfunc_mem[k] = + (void (*)(OutPeriod, SW_RUN *, SW_OUT_DOM *)) get_swaBulk_mem; +#elif defined(STEPWAT) + OutDom->pfunc_agg[k] = + (void (*)(OutPeriod, SW_RUN *, SW_OUT_DOM *)) get_swaBulk_agg; + OutDom->pfunc_SXW[k] = + (void (*)(OutPeriod, SW_RUN *, SW_OUT_DOM *)) get_none; +#endif + break; + + case eSW_SWAMatric: +#if defined(SW_OUTTEXT) + OutDom->pfunc_text[k] = + (void (*)(OutPeriod, SW_RUN *)) get_swaMatric_text; +#endif +#if defined(RSOILWAT) || defined(SWNETCDF) + OutDom->pfunc_mem[k] = + (void (*)(OutPeriod, SW_RUN *, SW_OUT_DOM *)) get_swaMatric_mem; +#elif defined(STEPWAT) + OutDom->pfunc_agg[k] = + (void (*)(OutPeriod, SW_RUN *, SW_OUT_DOM *)) get_swaMatric_agg; + OutDom->pfunc_SXW[k] = + (void (*)(OutPeriod, SW_RUN *, SW_OUT_DOM *)) get_none; +#endif + break; + + case eSW_SWA: +#if defined(SW_OUTTEXT) + OutDom->pfunc_text[k] = + (void (*)(OutPeriod, SW_RUN *)) get_swa_text; +#endif +#if defined(RSOILWAT) || defined(SWNETCDF) + OutDom->pfunc_mem[k] = + (void (*)(OutPeriod, SW_RUN *, SW_OUT_DOM *)) get_swa_mem; +#elif defined(STEPWAT) + OutDom->pfunc_agg[k] = + (void (*)(OutPeriod, SW_RUN *, SW_OUT_DOM *)) get_swa_agg; + OutDom->pfunc_SXW[k] = + (void (*)(OutPeriod, SW_RUN *, SW_OUT_DOM *)) get_none; +#endif + break; + + case eSW_SurfaceWater: +#if defined(SW_OUTTEXT) + OutDom->pfunc_text[k] = + (void (*)(OutPeriod, SW_RUN *)) get_surfaceWater_text; +#endif +#if defined(RSOILWAT) || defined(SWNETCDF) + OutDom->pfunc_mem[k] = (void (*)(OutPeriod, SW_RUN *, SW_OUT_DOM *) + ) get_surfaceWater_mem; +#elif defined(STEPWAT) + OutDom->pfunc_agg[k] = (void (*)(OutPeriod, SW_RUN *, SW_OUT_DOM *) + ) get_surfaceWater_agg; + OutDom->pfunc_SXW[k] = + (void (*)(OutPeriod, SW_RUN *, SW_OUT_DOM *)) get_none; +#endif + break; + + case eSW_Runoff: +#if defined(SW_OUTTEXT) + OutDom->pfunc_text[k] = + (void (*)(OutPeriod, SW_RUN *)) get_runoffrunon_text; +#endif +#if defined(RSOILWAT) || defined(SWNETCDF) + OutDom->pfunc_mem[k] = (void (*)(OutPeriod, SW_RUN *, SW_OUT_DOM *) + ) get_runoffrunon_mem; +#elif defined(STEPWAT) + OutDom->pfunc_agg[k] = (void (*)(OutPeriod, SW_RUN *, SW_OUT_DOM *) + ) get_runoffrunon_agg; + OutDom->pfunc_SXW[k] = + (void (*)(OutPeriod, SW_RUN *, SW_OUT_DOM *)) get_none; +#endif + break; + + case eSW_Transp: +#if defined(SW_OUTTEXT) + OutDom->pfunc_text[k] = + (void (*)(OutPeriod, SW_RUN *)) get_transp_text; +#endif +#if defined(RSOILWAT) || defined(SWNETCDF) + OutDom->pfunc_mem[k] = + (void (*)(OutPeriod, SW_RUN *, SW_OUT_DOM *)) get_transp_mem; +#elif defined(STEPWAT) + OutDom->pfunc_agg[k] = + (void (*)(OutPeriod, SW_RUN *, SW_OUT_DOM *)) get_transp_agg; + OutDom->pfunc_SXW[k] = + (void (*)(OutPeriod, SW_RUN *, SW_OUT_DOM *)) get_transp_SXW; +#endif + break; + + case eSW_EvapSoil: +#if defined(SW_OUTTEXT) + OutDom->pfunc_text[k] = + (void (*)(OutPeriod, SW_RUN *)) get_evapSoil_text; +#endif +#if defined(RSOILWAT) || defined(SWNETCDF) + OutDom->pfunc_mem[k] = + (void (*)(OutPeriod, SW_RUN *, SW_OUT_DOM *)) get_evapSoil_mem; +#elif defined(STEPWAT) + OutDom->pfunc_agg[k] = + (void (*)(OutPeriod, SW_RUN *, SW_OUT_DOM *)) get_evapSoil_agg; + OutDom->pfunc_SXW[k] = + (void (*)(OutPeriod, SW_RUN *, SW_OUT_DOM *)) get_none; +#endif + break; + + case eSW_EvapSurface: +#if defined(SW_OUTTEXT) + OutDom->pfunc_text[k] = + (void (*)(OutPeriod, SW_RUN *)) get_evapSurface_text; +#endif +#if defined(RSOILWAT) || defined(SWNETCDF) + OutDom->pfunc_mem[k] = (void (*)(OutPeriod, SW_RUN *, SW_OUT_DOM *) + ) get_evapSurface_mem; +#elif defined(STEPWAT) + OutDom->pfunc_agg[k] = (void (*)(OutPeriod, SW_RUN *, SW_OUT_DOM *) + ) get_evapSurface_agg; + OutDom->pfunc_SXW[k] = + (void (*)(OutPeriod, SW_RUN *, SW_OUT_DOM *)) get_none; +#endif + break; + + case eSW_Interception: +#if defined(SW_OUTTEXT) + OutDom->pfunc_text[k] = + (void (*)(OutPeriod, SW_RUN *)) get_interception_text; +#endif +#if defined(RSOILWAT) || defined(SWNETCDF) + OutDom->pfunc_mem[k] = (void (*)(OutPeriod, SW_RUN *, SW_OUT_DOM *) + ) get_interception_mem; +#elif defined(STEPWAT) + OutDom->pfunc_agg[k] = (void (*)(OutPeriod, SW_RUN *, SW_OUT_DOM *) + ) get_interception_agg; + OutDom->pfunc_SXW[k] = + (void (*)(OutPeriod, SW_RUN *, SW_OUT_DOM *)) get_none; +#endif + break; + + case eSW_SoilInf: +#if defined(SW_OUTTEXT) + OutDom->pfunc_text[k] = + (void (*)(OutPeriod, SW_RUN *)) get_soilinf_text; +#endif +#if defined(RSOILWAT) || defined(SWNETCDF) + OutDom->pfunc_mem[k] = + (void (*)(OutPeriod, SW_RUN *, SW_OUT_DOM *)) get_soilinf_mem; +#elif defined(STEPWAT) + OutDom->pfunc_agg[k] = + (void (*)(OutPeriod, SW_RUN *, SW_OUT_DOM *)) get_soilinf_agg; + OutDom->pfunc_SXW[k] = + (void (*)(OutPeriod, SW_RUN *, SW_OUT_DOM *)) get_none; +#endif + break; + + case eSW_LyrDrain: +#if defined(SW_OUTTEXT) + OutDom->pfunc_text[k] = + (void (*)(OutPeriod, SW_RUN *)) get_lyrdrain_text; +#endif +#if defined(RSOILWAT) || defined(SWNETCDF) + OutDom->pfunc_mem[k] = + (void (*)(OutPeriod, SW_RUN *, SW_OUT_DOM *)) get_lyrdrain_mem; +#elif defined(STEPWAT) + OutDom->pfunc_agg[k] = + (void (*)(OutPeriod, SW_RUN *, SW_OUT_DOM *)) get_lyrdrain_agg; + OutDom->pfunc_SXW[k] = + (void (*)(OutPeriod, SW_RUN *, SW_OUT_DOM *)) get_none; +#endif + break; + + case eSW_HydRed: +#if defined(SW_OUTTEXT) + OutDom->pfunc_text[k] = + (void (*)(OutPeriod, SW_RUN *)) get_hydred_text; +#endif +#if defined(RSOILWAT) || defined(SWNETCDF) + OutDom->pfunc_mem[k] = + (void (*)(OutPeriod, SW_RUN *, SW_OUT_DOM *)) get_hydred_mem; +#elif defined(STEPWAT) + OutDom->pfunc_agg[k] = + (void (*)(OutPeriod, SW_RUN *, SW_OUT_DOM *)) get_hydred_agg; + OutDom->pfunc_SXW[k] = + (void (*)(OutPeriod, SW_RUN *, SW_OUT_DOM *)) get_none; +#endif + break; + + case eSW_AET: +#if defined(SW_OUTTEXT) + OutDom->pfunc_text[k] = + (void (*)(OutPeriod, SW_RUN *)) get_aet_text; +#endif +#if defined(RSOILWAT) || defined(SWNETCDF) + OutDom->pfunc_mem[k] = + (void (*)(OutPeriod, SW_RUN *, SW_OUT_DOM *)) get_aet_mem; +#elif defined(STEPWAT) + OutDom->pfunc_agg[k] = + (void (*)(OutPeriod, SW_RUN *, SW_OUT_DOM *)) get_aet_agg; + OutDom->pfunc_SXW[k] = + (void (*)(OutPeriod, SW_RUN *, SW_OUT_DOM *)) get_aet_SXW; +#endif + break; + + case eSW_PET: +#if defined(SW_OUTTEXT) + OutDom->pfunc_text[k] = + (void (*)(OutPeriod, SW_RUN *)) get_pet_text; +#endif +#if defined(RSOILWAT) || defined(SWNETCDF) + OutDom->pfunc_mem[k] = + (void (*)(OutPeriod, SW_RUN *, SW_OUT_DOM *)) get_pet_mem; +#elif defined(STEPWAT) + OutDom->pfunc_agg[k] = + (void (*)(OutPeriod, SW_RUN *, SW_OUT_DOM *)) get_pet_agg; + OutDom->pfunc_SXW[k] = + (void (*)(OutPeriod, SW_RUN *, SW_OUT_DOM *)) get_none; +#endif + break; + + case eSW_WetDays: +#if defined(SW_OUTTEXT) + OutDom->pfunc_text[k] = + (void (*)(OutPeriod, SW_RUN *)) get_wetdays_text; +#endif +#if defined(RSOILWAT) || defined(SWNETCDF) + OutDom->pfunc_mem[k] = + (void (*)(OutPeriod, SW_RUN *, SW_OUT_DOM *)) get_wetdays_mem; +#elif defined(STEPWAT) + OutDom->pfunc_agg[k] = + (void (*)(OutPeriod, SW_RUN *, SW_OUT_DOM *)) get_wetdays_agg; + OutDom->pfunc_SXW[k] = + (void (*)(OutPeriod, SW_RUN *, SW_OUT_DOM *)) get_none; +#endif + break; + + case eSW_SnowPack: +#if defined(SW_OUTTEXT) + OutDom->pfunc_text[k] = + (void (*)(OutPeriod, SW_RUN *)) get_snowpack_text; +#endif +#if defined(RSOILWAT) || defined(SWNETCDF) + OutDom->pfunc_mem[k] = + (void (*)(OutPeriod, SW_RUN *, SW_OUT_DOM *)) get_snowpack_mem; +#elif defined(STEPWAT) + OutDom->pfunc_agg[k] = + (void (*)(OutPeriod, SW_RUN *, SW_OUT_DOM *)) get_snowpack_agg; + OutDom->pfunc_SXW[k] = + (void (*)(OutPeriod, SW_RUN *, SW_OUT_DOM *)) get_none; +#endif + break; + + case eSW_DeepSWC: +#if defined(SW_OUTTEXT) + OutDom->pfunc_text[k] = + (void (*)(OutPeriod, SW_RUN *)) get_deepswc_text; +#endif +#if defined(RSOILWAT) || defined(SWNETCDF) + OutDom->pfunc_mem[k] = + (void (*)(OutPeriod, SW_RUN *, SW_OUT_DOM *)) get_deepswc_mem; +#elif defined(STEPWAT) + OutDom->pfunc_agg[k] = + (void (*)(OutPeriod, SW_RUN *, SW_OUT_DOM *)) get_deepswc_agg; + OutDom->pfunc_SXW[k] = + (void (*)(OutPeriod, SW_RUN *, SW_OUT_DOM *)) get_none; +#endif + break; + + case eSW_SoilTemp: +#if defined(SW_OUTTEXT) + OutDom->pfunc_text[k] = + (void (*)(OutPeriod, SW_RUN *)) get_soiltemp_text; +#endif +#if defined(RSOILWAT) || defined(SWNETCDF) + OutDom->pfunc_mem[k] = + (void (*)(OutPeriod, SW_RUN *, SW_OUT_DOM *)) get_soiltemp_mem; +#elif defined(STEPWAT) + OutDom->pfunc_agg[k] = + (void (*)(OutPeriod, SW_RUN *, SW_OUT_DOM *)) get_soiltemp_agg; + OutDom->pfunc_SXW[k] = + (void (*)(OutPeriod, SW_RUN *, SW_OUT_DOM *)) get_none; +#endif + break; + + case eSW_Frozen: +#if defined(SW_OUTTEXT) + OutDom->pfunc_text[k] = + (void (*)(OutPeriod, SW_RUN *)) get_frozen_text; +#endif +#if defined(RSOILWAT) || defined(SWNETCDF) + OutDom->pfunc_mem[k] = + (void (*)(OutPeriod, SW_RUN *, SW_OUT_DOM *)) get_frozen_mem; +#elif defined(STEPWAT) + OutDom->pfunc_agg[k] = + (void (*)(OutPeriod, SW_RUN *, SW_OUT_DOM *)) get_frozen_agg; + OutDom->pfunc_SXW[k] = + (void (*)(OutPeriod, SW_RUN *, SW_OUT_DOM *)) get_none; +#endif + break; + + case eSW_Estab: +#if defined(SW_OUTTEXT) + OutDom->pfunc_text[k] = + (void (*)(OutPeriod, SW_RUN *)) get_estab_text; +#endif +#if defined(RSOILWAT) || defined(SWNETCDF) + OutDom->pfunc_mem[k] = + (void (*)(OutPeriod, SW_RUN *, SW_OUT_DOM *)) get_estab_mem; +#elif defined(STEPWAT) + OutDom->pfunc_agg[k] = + (void (*)(OutPeriod, SW_RUN *, SW_OUT_DOM *)) get_estab_agg; + OutDom->pfunc_SXW[k] = + (void (*)(OutPeriod, SW_RUN *, SW_OUT_DOM *)) get_none; +#endif + break; + + case eSW_CO2Effects: +#if defined(SW_OUTTEXT) + OutDom->pfunc_text[k] = + (void (*)(OutPeriod, SW_RUN *)) get_co2effects_text; +#endif +#if defined(RSOILWAT) || defined(SWNETCDF) + OutDom->pfunc_mem[k] = (void (*)(OutPeriod, SW_RUN *, SW_OUT_DOM *) + ) get_co2effects_mem; +#elif defined(STEPWAT) + OutDom->pfunc_agg[k] = (void (*)(OutPeriod, SW_RUN *, SW_OUT_DOM *) + ) get_co2effects_agg; + OutDom->pfunc_SXW[k] = + (void (*)(OutPeriod, SW_RUN *, SW_OUT_DOM *)) get_none; +#endif + break; + + case eSW_Biomass: +#if defined(SW_OUTTEXT) + OutDom->pfunc_text[k] = + (void (*)(OutPeriod, SW_RUN *)) get_biomass_text; +#endif +#if defined(RSOILWAT) || defined(SWNETCDF) + OutDom->pfunc_mem[k] = + (void (*)(OutPeriod, SW_RUN *, SW_OUT_DOM *)) get_biomass_mem; +#elif defined(STEPWAT) + OutDom->pfunc_agg[k] = + (void (*)(OutPeriod, SW_RUN *, SW_OUT_DOM *)) get_biomass_agg; + OutDom->pfunc_SXW[k] = + (void (*)(OutPeriod, SW_RUN *, SW_OUT_DOM *)) get_none; +#endif + break; + + default: +#if defined(SW_OUTTEXT) + OutDom->pfunc_text[k] = (void (*)(OutPeriod, SW_RUN *)) get_none; +#endif +#if defined(RSOILWAT) || defined(SWNETCDF) + OutDom->pfunc_mem[k] = + (void (*)(OutPeriod, SW_RUN *, SW_OUT_DOM *)) get_none; +#elif defined(STEPWAT) + OutDom->pfunc_agg[k] = + (void (*)(OutPeriod, SW_RUN *, SW_OUT_DOM *)) get_none; + OutDom->pfunc_SXW[k] = + (void (*)(OutPeriod, SW_RUN *, SW_OUT_DOM *)) get_none; +#endif + break; + } + } // end of loop across output keys } /** @@ -504,6 +1066,8 @@ void SW_DOM_SimSet( } void SW_DOM_deepCopy(SW_DOMAIN *source, SW_DOMAIN *dest, LOG_INFO *LogInfo) { + IntUS k, i; + memcpy(dest, source, sizeof(*dest)); SW_F_deepCopy(&dest->PathInfo, &source->PathInfo, LogInfo); @@ -511,23 +1075,69 @@ void SW_DOM_deepCopy(SW_DOMAIN *source, SW_DOMAIN *dest, LOG_INFO *LogInfo) { #if defined(SWNETCDF) SW_NC_deepCopy(&dest->netCDFInfo, &source->netCDFInfo, LogInfo); #endif + + ForEachOutKey(k) { + for (i = 0; i < 5 * NVEGTYPES + MAX_LAYERS; i++) { + if (!isnull(source->OutDom.colnames_OUT[k][i])) { + + dest->OutDom.colnames_OUT[k][i] = + Str_Dup(source->OutDom.colnames_OUT[k][i], LogInfo); + if (LogInfo->stopRun) { + return; // Exit function prematurely due to error + } + } + } + } } void SW_DOM_init_ptrs(SW_DOMAIN *SW_Domain) { + IntUS key, column; + + ForEachOutKey(key) { + for (column = 0; column < 5 * NVEGTYPES + MAX_LAYERS; column++) { + SW_Domain->OutDom.colnames_OUT[key][column] = NULL; + } + } + SW_F_init_ptrs(SW_Domain->PathInfo.InFiles); +#ifdef RSOILWAT + ForEachOutKey(key) { OutDom->outfile[key] = NULL; } +#endif + #if defined(SWNETCDF) SW_NC_init_ptrs(&SW_Domain->netCDFInfo); #endif } void SW_DOM_deconstruct(SW_DOMAIN *SW_Domain) { + IntUS k, i; + SW_F_deconstruct(SW_Domain->PathInfo.InFiles); #if defined(SWNETCDF) + SW_NC_deconstruct(&SW_Domain->netCDFInfo); SW_NC_close_files(&SW_Domain->netCDFInfo); + + ForEachOutKey(k) { + SW_NC_dealloc_outputkey_var_info(&SW_Domain->OutDom, k); + } #endif + ForEachOutKey(k) { + for (i = 0; i < 5 * NVEGTYPES + MAX_LAYERS; i++) { + if (!isnull(SW_Domain->OutDom.colnames_OUT[k][i])) { + free(SW_Domain->OutDom.colnames_OUT[k][i]); + SW_Domain->OutDom.colnames_OUT[k][i] = NULL; + } + } +#ifdef RSOILWAT + if (!isnull(SW_Domain->OutDom.outfile[k])) { + free(SW_Domain->OutDom.outfile[k]); + SW_Domain->OutDom.outfile[k] = NULL; + } +#endif + } } /** Identify soil profile information across simulation domain diff --git a/src/SW_Main.c b/src/SW_Main.c index d1eb4074f..04cd2e100 100644 --- a/src/SW_Main.c +++ b/src/SW_Main.c @@ -50,7 +50,6 @@ int main(int argc, char **argv) { SW_WALLTIME SW_WallTime; SW_RUN sw_template; SW_DOMAIN SW_Domain; - SW_OUTPUT_POINTERS SW_OutputPtrs[SW_OUTNKEYS]; LOG_INFO LogInfo; Bool EchoInits = swFALSE; @@ -96,7 +95,7 @@ int main(int argc, char **argv) { } // setup and construct model template (independent of inputs) - SW_CTL_setup_model(&sw_template, SW_OutputPtrs, &LogInfo); + SW_CTL_setup_model(&sw_template, &SW_Domain.OutDom, &LogInfo); if (LogInfo.stopRun) { goto finishProgram; } @@ -108,7 +107,9 @@ int main(int argc, char **argv) { } // read user inputs - SW_CTL_read_inputs_from_disk(&sw_template, &SW_Domain.PathInfo, &LogInfo); + SW_CTL_read_inputs_from_disk( + &sw_template, &SW_Domain.OutDom, &SW_Domain.PathInfo, &LogInfo + ); if (LogInfo.stopRun) { goto finishProgram; } @@ -155,7 +156,7 @@ int main(int argc, char **argv) { SW_Domain.nMaxSoilLayers, SW_Domain.nMaxEvapLayers, &sw_template.VegEstab, - &sw_template.GenOutput, + &SW_Domain.OutDom, &LogInfo ); if (LogInfo.stopRun) { @@ -164,8 +165,7 @@ int main(int argc, char **argv) { #if defined(SWNETCDF) SW_NC_read_out_vars( - sw_template.Output, - &sw_template.GenOutput, + &SW_Domain.OutDom, SW_Domain.PathInfo.InFiles, sw_template.VegEstab.parms, &LogInfo @@ -173,39 +173,27 @@ int main(int argc, char **argv) { if (LogInfo.stopRun) { goto finishProgram; } - SW_NC_create_units_converters( - sw_template.Output, sw_template.GenOutput.nvar_OUT, &LogInfo - ); + SW_NC_create_units_converters(&SW_Domain.OutDom, &LogInfo); if (LogInfo.stopRun) { goto finishProgram; } #endif // SWNETCDF - SW_OUT_create_files( - &sw_template.FileStatus, - &SW_Domain, - sw_template.Output, - &sw_template.GenOutput, - &LogInfo - ); + SW_OUT_create_files(&sw_template.FileStatus, &SW_Domain, &LogInfo); if (LogInfo.stopRun) { goto closeFiles; } if (EchoInits) { - _echo_all_inputs(&sw_template); + _echo_all_inputs(&sw_template, &SW_Domain.OutDom); } // run simulations: loop over simulation set - SW_CTL_RunSimSet( - &sw_template, SW_OutputPtrs, &SW_Domain, &SW_WallTime, &LogInfo - ); + SW_CTL_RunSimSet(&sw_template, &SW_Domain, &SW_WallTime, &LogInfo); closeFiles: { // finish-up output (not used with rSOILWAT2) - SW_OUT_close_files( - &sw_template.FileStatus, &sw_template.GenOutput, &LogInfo - ); + SW_OUT_close_files(&sw_template.FileStatus, &SW_Domain.OutDom, &LogInfo); } finishProgram: { diff --git a/src/SW_Markov.c b/src/SW_Markov.c index 612744fa0..fa430d365 100644 --- a/src/SW_Markov.c +++ b/src/SW_Markov.c @@ -206,8 +206,7 @@ void (*test_mvnorm)(RealD *, RealD *, RealD, RealD, RealD, RealD, RealD, sw_rand /* --------------------------------------------------- */ /** -@brief Initialize all possible pointers in the array, SW_OUTPUT, and -SW_GEN_OUT to NULL +@brief Initialize all possible markov pointers to NULL @param[in,out] SW_Markov Struct of type SW_MARKOV which holds values related to temperature and weather generator diff --git a/src/SW_Output.c b/src/SW_Output.c index 4e001e4cf..d3e5c831d 100644 --- a/src/SW_Output.c +++ b/src/SW_Output.c @@ -112,48 +112,6 @@ char const *key2str[] = { SW_BIOMASS }; -/* converts an enum output key (OutKey type) to a module */ -/* or object type. see SW_Output.h for OutKey order. */ -/* MUST be SW_OUTNKEYS of these */ -ObjType key2obj[] = { - // weather/atmospheric quantities: - eWTH, - eWTH, - eWTH, - eWTH, - eWTH, - // soil related water quantities: - eSWC, - eSWC, - eSWC, - eSWC, - eSWC, - eSWC, - eSWC, - eSWC, - eSWC, - eSWC, - eSWC, - eSWC, - eSWC, - eSWC, - eSWC, - eSWC, - eSWC, - eSWC, - eSWC, - eSWC, - eSWC, - eSWC, - eSWC, - // vegetation quantities: - eVES, - eVES, - // vegetation other: - eVPD, - eVPD -}; - char const *pd2str[] = {SW_DAY, SW_WEEK, SW_MONTH, SW_YEAR}; char const *pd2longstr[] = { @@ -177,10 +135,9 @@ static OutSum str2stype(char *s, LOG_INFO *LogInfo); static void collect_sums( SW_RUN *sw, + SW_OUT_DOM *OutDom, ObjType otyp, OutPeriod op, - OutPeriod timeSteps[][SW_OUTNPERIODS], - IntUS used_OUTNPERIODS, LOG_INFO *LogInfo ); @@ -208,6 +165,7 @@ static void sumof_vpd( static void average_for( SW_RUN *sw, + SW_OUT_DOM *OutDom, ObjType otyp, OutPeriod pd, Bool bFlush_output, @@ -217,11 +175,11 @@ static void average_for( #ifdef STEPWAT static void _set_SXWrequests_helper( + SW_OUT_DOM *OutDom, OutKey k, OutPeriod pd, OutSum aggfun, const char *str, - SW_OUTPUT *SW_Output, OutPeriod timeSteps_SXW[][SW_OUTNPERIODS], LOG_INFO *LogInfo ); @@ -584,6 +542,8 @@ one greater than the period being summarized. @param[in,out] sw Comprehensive struct of type SW_RUN containing all information in the simulation. +@param[in] OutDom Struct of type SW_OUT_DOM that holds output + information that do not change throughout simulation runs @param[in] otyp Identifies the current module/object @param[in] pd Time period in simulation output (day/week/month/year) @param[in] bFlush_output Determines if output should be created for @@ -593,6 +553,7 @@ one greater than the period being summarized. */ static void average_for( SW_RUN *sw, + SW_OUT_DOM *OutDom, ObjType otyp, OutPeriod pd, Bool bFlush_output, @@ -638,7 +599,7 @@ static void average_for( // carefully aggregate for specific time period and aggregation type // (mean, sum, final value) ForEachOutKey(k) { - if (!sw->Output[k].use) { + if (!OutDom->use[k]) { continue; } @@ -656,8 +617,8 @@ static void average_for( break; case eSW_Year: - curr_pd = sw->Output[k].first; - div = sw->Output[k].last - sw->Output[k].first + 1; + curr_pd = sw->OutRun.first[k]; + div = sw->OutRun.last[k] - sw->OutRun.first[k] + 1; break; default: @@ -670,12 +631,12 @@ static void average_for( break; } /* end switch(pd) */ - if (sw->Output[k].myobj != otyp || curr_pd < sw->Output[k].first || - curr_pd > sw->Output[k].last) { + if (OutDom->myobj[k] != otyp || curr_pd < sw->OutRun.first[k] || + curr_pd > sw->OutRun.last[k]) { continue; } - if (sw->Output[k].sumtype == eSW_Sum) { + if (OutDom->sumtype[k] == eSW_Sum) { div = 1.; } @@ -726,15 +687,15 @@ static void average_for( case eSW_SoilTemp: ForEachSoilLayer(i, n_layers) { sw->SoilWat.p_oagg[pd]->avgLyrTemp[i] = - (sw->Output[k].sumtype == eSW_Fnl) ? + (OutDom->sumtype[k] == eSW_Fnl) ? sw->SoilWat.avgLyrTemp[i] : sw->SoilWat.p_accu[pd]->avgLyrTemp[i] / div; sw->SoilWat.p_oagg[pd]->maxLyrTemperature[i] = - (sw->Output[k].sumtype == eSW_Fnl) ? + (OutDom->sumtype[k] == eSW_Fnl) ? sw->SoilWat.maxLyrTemperature[i] : sw->SoilWat.p_accu[pd]->maxLyrTemperature[i] / div; sw->SoilWat.p_oagg[pd]->minLyrTemperature[i] = - (sw->Output[k].sumtype == eSW_Fnl) ? + (OutDom->sumtype[k] == eSW_Fnl) ? sw->SoilWat.minLyrTemperature[i] : sw->SoilWat.p_accu[pd]->minLyrTemperature[i] / div; } @@ -743,7 +704,7 @@ static void average_for( case eSW_Frozen: ForEachSoilLayer(i, n_layers) { sw->SoilWat.p_oagg[pd]->lyrFrozen[i] = - (sw->Output[k].sumtype == eSW_Fnl) ? + (OutDom->sumtype[k] == eSW_Fnl) ? sw->SoilWat.lyrFrozen[i] : sw->SoilWat.p_accu[pd]->lyrFrozen[i] / div; } @@ -753,7 +714,7 @@ static void average_for( /* vwcBulk at this point is identical to swcBulk */ ForEachSoilLayer(i, n_layers) { sw->SoilWat.p_oagg[pd]->vwcBulk[i] = - (sw->Output[k].sumtype == eSW_Fnl) ? + (OutDom->sumtype[k] == eSW_Fnl) ? sw->SoilWat.swcBulk[Yesterday][i] : sw->SoilWat.p_accu[pd]->vwcBulk[i] / div; } @@ -763,7 +724,7 @@ static void average_for( /* vwcMatric at this point is identical to swcBulk */ ForEachSoilLayer(i, n_layers) { sw->SoilWat.p_oagg[pd]->vwcMatric[i] = - (sw->Output[k].sumtype == eSW_Fnl) ? + (OutDom->sumtype[k] == eSW_Fnl) ? sw->SoilWat.swcBulk[Yesterday][i] : sw->SoilWat.p_accu[pd]->vwcMatric[i] / div; } @@ -772,7 +733,7 @@ static void average_for( case eSW_SWCBulk: ForEachSoilLayer(i, n_layers) { sw->SoilWat.p_oagg[pd]->swcBulk[i] = - (sw->Output[k].sumtype == eSW_Fnl) ? + (OutDom->sumtype[k] == eSW_Fnl) ? sw->SoilWat.swcBulk[Yesterday][i] : sw->SoilWat.p_accu[pd]->swcBulk[i] / div; } @@ -782,7 +743,7 @@ static void average_for( /* swpMatric at this point is identical to swcBulk */ ForEachSoilLayer(i, n_layers) { sw->SoilWat.p_oagg[pd]->swpMatric[i] = - (sw->Output[k].sumtype == eSW_Fnl) ? + (OutDom->sumtype[k] == eSW_Fnl) ? sw->SoilWat.swcBulk[Yesterday][i] : sw->SoilWat.p_accu[pd]->swpMatric[i] / div; } @@ -791,7 +752,7 @@ static void average_for( case eSW_SWABulk: ForEachSoilLayer(i, n_layers) { sw->SoilWat.p_oagg[pd]->swaBulk[i] = - (sw->Output[k].sumtype == eSW_Fnl) ? + (OutDom->sumtype[k] == eSW_Fnl) ? fmax( sw->SoilWat.swcBulk[Yesterday][i] - sw->Site.swcBulk_wiltpt[i], @@ -805,7 +766,7 @@ static void average_for( /* swaMatric at this point is identical to swaBulk */ ForEachSoilLayer(i, n_layers) { sw->SoilWat.p_oagg[pd]->swaMatric[i] = - (sw->Output[k].sumtype == eSW_Fnl) ? + (OutDom->sumtype[k] == eSW_Fnl) ? fmax( sw->SoilWat.swcBulk[Yesterday][i] - sw->Site.swcBulk_wiltpt[i], @@ -819,7 +780,7 @@ static void average_for( ForEachSoilLayer(i, n_layers) { ForEachVegType(j) { sw->SoilWat.p_oagg[pd]->SWA_VegType[j][i] = - (sw->Output[k].sumtype == eSW_Fnl) ? + (OutDom->sumtype[k] == eSW_Fnl) ? sw->SoilWat.dSWA_repartitioned_sum[j][i] : sw->SoilWat.p_accu[pd]->SWA_VegType[j][i] / div; } @@ -829,7 +790,7 @@ static void average_for( case eSW_DeepSWC: // deepest percolation == deep drainage sw->SoilWat.p_oagg[pd]->deep = - (sw->Output[k].sumtype == eSW_Fnl) ? + (OutDom->sumtype[k] == eSW_Fnl) ? sw->SoilWat.drain[sw->Site.deep_lyr] : sw->SoilWat.p_accu[pd]->deep / div; break; @@ -979,10 +940,9 @@ static void average_for( static void collect_sums( SW_RUN *sw, + SW_OUT_DOM *OutDom, ObjType otyp, OutPeriod op, - OutPeriod timeSteps[][SW_OUTNPERIODS], - IntUS used_OUTNPERIODS, LOG_INFO *LogInfo ) { TimeInt pd = 0; @@ -1014,15 +974,15 @@ static void collect_sums( // for those output keys that belong to the output type `otyp` (eSWC, eWTH, // eVES, eVPD) ForEachOutKey(k) { - if (otyp != sw->Output[k].myobj || !sw->Output[k].use) { + if (otyp != OutDom->myobj[k] || !OutDom->use[k]) { continue; } /* determine whether output period op is active for current output key k */ use_KeyPeriodCombo = swFALSE; - for (i = 0; i < used_OUTNPERIODS; i++) { - use_help = (Bool) (op == timeSteps[k][i]); + for (i = 0; i < OutDom->used_OUTNPERIODS; i++) { + use_help = (Bool) (op == OutDom->timeSteps[k][i]); #ifdef STEPWAT use_help = @@ -1035,8 +995,8 @@ static void collect_sums( } } - if (use_KeyPeriodCombo && pd >= sw->Output[k].first && - pd <= sw->Output[k].last) { + if (use_KeyPeriodCombo && pd >= sw->OutRun.first[k] && + pd <= sw->OutRun.last[k]) { switch (otyp) { case eSWC: sumof_swc( @@ -1091,23 +1051,23 @@ static void collect_sums( #ifdef STEPWAT static void _set_SXWrequests_helper( + SW_OUT_DOM *OutDom, OutKey k, OutPeriod pd, OutSum aggfun, const char *str, - SW_OUTPUT *SW_Output, OutPeriod timeSteps_SXW[][SW_OUTNPERIODS], LOG_INFO *LogInfo ) { - Bool warn = SW_Output[k].use; + Bool warn = OutDom.use[k]; timeSteps_SXW[k][0] = pd; - SW_Output[k].use = swTRUE; - SW_Output[k].first_orig = 1; - SW_Output[k].last_orig = 366; + OutDom->use[k] = swTRUE; + OutDom->first_orig[k] = 1; + OutDom->last_orig[k] = 366; - if (SW_Output[k].sumtype != aggfun) { - if (warn && SW_Output[k].sumtype != eSW_Off) { + if (OutDom->sumtype[k] != aggfun) { + if (warn && OutDom->sumtype[k] != eSW_Off) { LogError( LogInfo, LOGWARN, @@ -1115,12 +1075,12 @@ static void _set_SXWrequests_helper( "but this is currently set to '%s': changed to '%s'.", styp2str[aggfun], str, - styp2str[SW_Output[k].sumtype], + styp2str[OutDom->sumtype[k]], styp2str[aggfun] ); } - SW_Output[k].sumtype = aggfun; + OutDom->sumtype[k] = aggfun; } } #endif @@ -1135,26 +1095,25 @@ static void _set_SXWrequests_helper( @brief Tally for which output time periods at least one output key/type is active -@param[in,out] GenOutput Holds general variables that deal with output -@param[in] SW_Output SW_OUTPUT array of size SW_OUTNKEYS which holds - basic output information for all output keys +@param[in,out] OutDom Struct of type SW_OUT_DOM that holds output + information that do not change throughout simulation runs @sideeffect Uses global variables SW_Output.use and timeSteps to set elements of use_OutPeriod */ -void find_OutPeriods_inUse(SW_GEN_OUT *GenOutput, SW_OUTPUT *SW_Output) { +void find_OutPeriods_inUse(SW_OUT_DOM *OutDom) { OutPeriod p; IntUS k, i, timeStepInd; - ForEachOutPeriod(p) { GenOutput->use_OutPeriod[p] = swFALSE; } + ForEachOutPeriod(p) { OutDom->use_OutPeriod[p] = swFALSE; } ForEachOutKey(k) { - for (i = 0; i < GenOutput->used_OUTNPERIODS; i++) { - if (SW_Output[k].use) { - if (GenOutput->timeSteps[k][i] != eSW_NoTime) { - timeStepInd = GenOutput->timeSteps[k][i]; + for (i = 0; i < OutDom->used_OUTNPERIODS; i++) { + if (OutDom->use[k]) { + if (OutDom->timeSteps[k][i] != eSW_NoTime) { + timeStepInd = OutDom->timeSteps[k][i]; - GenOutput->use_OutPeriod[timeStepInd] = swTRUE; + OutDom->use_OutPeriod[timeStepInd] = swTRUE; } } } @@ -1183,16 +1142,16 @@ Bool has_OutPeriod_inUse( /** Determine whether output period `pd` is active for output key `k` while accounting for output needs of `SXW` */ -Bool has_OutPeriod_inUse2(OutPeriod pd, OutKey k, SW_GEN_OUT *GenOutput) { +Bool has_OutPeriod_inUse2(OutPeriod pd, OutKey k, SW_OUT_DOM *OutDom) { int i; Bool has_timeStep2 = has_OutPeriod_inUse( - pd, k, GenOutput->used_OUTNPERIODS, GenOutput->timeSteps_SXW + pd, k, OutDom->used_OUTNPERIODS, OutDom->timeSteps_SXW ); if (!has_timeStep2) { - for (i = 0; i < GenOutput->used_OUTNPERIODS; i++) { + for (i = 0; i < OutDom->used_OUTNPERIODS; i++) { has_timeStep2 = - (Bool) (has_timeStep2 || GenOutput->timeSteps_SXW[k][i] == pd); + (Bool) (has_timeStep2 || OutDom->timeSteps_SXW[k][i] == pd); } } @@ -1216,22 +1175,21 @@ Currently implemented: `first_orig`, and `last_orig` of `SW_Output`. */ void SW_OUT_set_SXWrequests( + SW_OUT_DOM *OutDom, OutPeriod timeSteps_SXW[][SW_OUTNPERIODS], - IntUS *used_OUTNPERIODS, - SW_OUTPUT *SW_Output, LOG_INFO *LogInfo ) { // Update `used_OUTNPERIODS`: // SXW uses up to 2 time periods for the same output key: monthly and yearly - *used_OUTNPERIODS = MAX(2, *used_OUTNPERIODS); + OutDom->used_OUTNPERIODS = MAX(2, OutDom->used_OUTNPERIODS); // STEPWAT2 requires monthly summed transpiration _set_SXWrequests_helper( + OutDom, eSW_Transp, eSW_Month, eSW_Sum, "monthly transpiration", - SW_Output, timeSteps_SXW, LogInfo ); @@ -1241,11 +1199,11 @@ void SW_OUT_set_SXWrequests( // STEPWAT2 requires monthly mean bulk soil water content _set_SXWrequests_helper( - eSW_SWCBulk, + OutDom, + SW_SWCBulk, eSW_Month, eSW_Avg, "monthly bulk soil water content", - SW_Output, timeSteps_SXW, LogInfo ); @@ -1255,11 +1213,11 @@ void SW_OUT_set_SXWrequests( // STEPWAT2 requires annual and monthly mean air temperature _set_SXWrequests_helper( + OutDom, eSW_Temp, eSW_Month, eSW_Avg, "annual and monthly air temperature", - SW_Output, timeSteps_SXW, LogInfo ); @@ -1270,11 +1228,11 @@ void SW_OUT_set_SXWrequests( // STEPWAT2 requires annual and monthly precipitation sum _set_SXWrequests_helper( + OutDom, eSW_Precip, eSW_Month, eSW_Sum, "annual and monthly precipitation", - SW_Output, timeSteps_SXW, LogInfo ); @@ -1285,11 +1243,11 @@ void SW_OUT_set_SXWrequests( // STEPWAT2 requires annual sum of AET _set_SXWrequests_helper( + OutDom, eSW_AET, eSW_Year, eSW_Sum, "annual AET", - SW_Output, timeSteps_SXW, LogInfo ); @@ -1300,66 +1258,43 @@ void SW_OUT_set_SXWrequests( #endif /** -@brief Initialize all possible pointers in the array SW_OUTPUT to NULL -*/ -void SW_OUT_init_ptrs(SW_OUTPUT *SW_Output) { -#ifdef RSOILWAT - IntUS key; +@brief Initialize all possible pointers in the struct SW_OUT_RUN to NULL - ForEachOutKey(key) { SW_Output[key].outfile = NULL; } -#else - (void) SW_Output; -#endif -} - -/** -@brief Initialize all possible pointers in SW_GEN_OUT to NULL +@param[out] OutRun Struct of type SW_OUT_RUN that holds output + information that may change throughout simulation runs */ -void SW_GENOUT_init_ptrs(SW_GEN_OUT *GenOutput) { - IntUS key, column; - - ForEachOutKey(key) { - for (column = 0; column < 5 * NVEGTYPES + MAX_LAYERS; column++) { - GenOutput->colnames_OUT[key][column] = NULL; - } - } +void SW_OUT_init_ptrs(SW_OUT_RUN *OutRun) { #if defined(SW_OUTARRAY) + IntUS key, column; ForEachOutKey(key) { for (column = 0; column < SW_OUTNPERIODS; column++) { - GenOutput->p_OUT[key][column] = NULL; - + OutRun->p_OUT[key][column] = NULL; #ifdef STEPWAT - GenOutput->p_OUTsd[key][column] = NULL; + OutRun->p_OUTsd[key][column] = NULL; #endif } } +#else + (void) OutRun; #endif } void SW_OUT_construct( Bool make_soil[], Bool make_regular[], - SW_OUTPUT_POINTERS *SW_OutputPtrs, - SW_OUTPUT *SW_Output, + SW_OUT_DOM *OutDom, + SW_OUT_RUN *OutRun, LyrIndex n_layers, - SW_GEN_OUT *GenOutput, LOG_INFO *LogInfo ) { /* =================================================== */ - IntUS k; - OutPeriod p; LyrIndex i; + OutPeriod p; SW_SOILWAT_OUTPUTS *s = NULL; int j; -#if defined(SOILWAT) - GenOutput->print_SW_Output = swTRUE; - GenOutput->print_IterationSummary = swFALSE; -#elif defined(STEPWAT) - GenOutput->print_SW_Output = (Bool) GenOutput->storeAllIterations; -// `print_IterationSummary` is set by STEPWAT2's `main` function -#endif + memset(OutRun, 0, sizeof(SW_OUT_RUN)); #if defined(SW_OUTTEXT) ForEachOutPeriod(p) { @@ -1370,7 +1305,6 @@ void SW_OUT_construct( /* Silence compiler */ (void) make_soil; (void) make_regular; - (void) SW_OutputPtrs; #endif ForEachSoilLayer(i, n_layers) { @@ -1379,564 +1313,38 @@ void SW_OUT_construct( #if defined(SW_OUTARRAY) ForEachOutPeriod(p) { - GenOutput->nrow_OUT[p] = 0; - GenOutput->irow_OUT[p] = 0; + OutRun->irow_OUT[p] = 0; } +#else + (void) OutRun; #endif - /* note that an initializer that is called during - * execution (better called clean() or something) - * will need to free all allocated memory first - * before clearing structure. - */ - memset(SW_Output, 0, sizeof(SW_OUTPUT)); - - /* attach the printing functions for each output - * quantity to the appropriate element in the - * output structure. Using a loop makes it convenient - * to simply add a line as new quantities are - * implemented and leave the default case for every - * thing else. - */ - ForEachOutKey(k) { - ForEachOutPeriod(p) { - GenOutput->timeSteps[k][p] = eSW_NoTime; - -#ifdef STEPWAT - GenOutput->timeSteps_SXW[k][p] = eSW_NoTime; -#endif - } - - // default values for `SW_Output`: - SW_Output[k].use = swFALSE; - SW_Output[k].mykey = (OutKey) k; - SW_Output[k].myobj = key2obj[k]; - SW_Output[k].sumtype = eSW_Off; - SW_Output[k].has_sl = has_key_soillayers((OutKey) k); - SW_Output[k].first_orig = 1; - SW_Output[k].last_orig = 366; - -#if defined(SWNETCDF) - SW_Output[k].outputVarInfo = NULL; - SW_Output[k].reqOutputVars = NULL; - SW_Output[k].units_sw = NULL; - SW_Output[k].uconv = NULL; -#endif - - // assign `get_XXX` functions - switch (k) { - case eSW_Temp: -#if defined(SW_OUTTEXT) - SW_OutputPtrs[k].pfunc_text = - (void (*)(OutPeriod, SW_RUN *)) get_temp_text; -#endif -#if defined(RSOILWAT) || defined(SWNETCDF) - SW_OutputPtrs[k].pfunc_mem = - (void (*)(OutPeriod, SW_RUN *)) get_temp_mem; -#elif defined(STEPWAT) - SW_OutputPtrs[k].pfunc_agg = - (void (*)(OutPeriod, SW_RUN *)) get_temp_agg; - SW_OutputPtrs[k].pfunc_SXW = - (void (*)(OutPeriod, SW_RUN *)) get_temp_SXW; -#endif - break; - - case eSW_Precip: -#if defined(SW_OUTTEXT) - SW_OutputPtrs[k].pfunc_text = - (void (*)(OutPeriod, SW_RUN *)) get_precip_text; -#endif -#if defined(RSOILWAT) || defined(SWNETCDF) - SW_OutputPtrs[k].pfunc_mem = - (void (*)(OutPeriod, SW_RUN *)) get_precip_mem; -#elif defined(STEPWAT) - SW_OutputPtrs[k].pfunc_agg = - (void (*)(OutPeriod, SW_RUN *)) get_precip_agg; - SW_OutputPtrs[k].pfunc_SXW = - (void (*)(OutPeriod, SW_RUN *)) get_precip_SXW; -#endif - break; - - case eSW_VWCBulk: -#if defined(SW_OUTTEXT) - SW_OutputPtrs[k].pfunc_text = - (void (*)(OutPeriod, SW_RUN *)) get_vwcBulk_text; -#endif -#if defined(RSOILWAT) || defined(SWNETCDF) - SW_OutputPtrs[k].pfunc_mem = - (void (*)(OutPeriod, SW_RUN *)) get_vwcBulk_mem; -#elif defined(STEPWAT) - SW_OutputPtrs[k].pfunc_agg = - (void (*)(OutPeriod, SW_RUN *)) get_vwcBulk_agg; - SW_OutputPtrs[k].pfunc_SXW = - (void (*)(OutPeriod, SW_RUN *)) get_none; -#endif - break; - - case eSW_VWCMatric: -#if defined(SW_OUTTEXT) - SW_OutputPtrs[k].pfunc_text = - (void (*)(OutPeriod, SW_RUN *)) get_vwcMatric_text; -#endif -#if defined(RSOILWAT) || defined(SWNETCDF) - SW_OutputPtrs[k].pfunc_mem = - (void (*)(OutPeriod, SW_RUN *)) get_vwcMatric_mem; -#elif defined(STEPWAT) - SW_OutputPtrs[k].pfunc_agg = - (void (*)(OutPeriod, SW_RUN *)) get_vwcMatric_agg; - SW_OutputPtrs[k].pfunc_SXW = - (void (*)(OutPeriod, SW_RUN *)) get_none; -#endif - break; - - case eSW_SWCBulk: -#if defined(SW_OUTTEXT) - SW_OutputPtrs[k].pfunc_text = - (void (*)(OutPeriod, SW_RUN *)) get_swcBulk_text; -#endif -#if defined(RSOILWAT) || defined(SWNETCDF) - SW_OutputPtrs[k].pfunc_mem = - (void (*)(OutPeriod, SW_RUN *)) get_swcBulk_mem; -#elif defined(STEPWAT) - SW_OutputPtrs[k].pfunc_agg = - (void (*)(OutPeriod, SW_RUN *)) get_swcBulk_agg; - SW_OutputPtrs[k].pfunc_SXW = - (void (*)(OutPeriod, SW_RUN *)) get_swcBulk_SXW; -#endif - break; - - case eSW_SWPMatric: -#if defined(SW_OUTTEXT) - SW_OutputPtrs[k].pfunc_text = - (void (*)(OutPeriod, SW_RUN *)) get_swpMatric_text; -#endif -#if defined(RSOILWAT) || defined(SWNETCDF) - SW_OutputPtrs[k].pfunc_mem = - (void (*)(OutPeriod, SW_RUN *)) get_swpMatric_mem; -#elif defined(STEPWAT) - SW_OutputPtrs[k].pfunc_agg = - (void (*)(OutPeriod, SW_RUN *)) get_swpMatric_agg; - SW_OutputPtrs[k].pfunc_SXW = - (void (*)(OutPeriod, SW_RUN *)) get_none; -#endif - break; - - case eSW_SWABulk: -#if defined(SW_OUTTEXT) - SW_OutputPtrs[k].pfunc_text = - (void (*)(OutPeriod, SW_RUN *)) get_swaBulk_text; -#endif -#if defined(RSOILWAT) || defined(SWNETCDF) - SW_OutputPtrs[k].pfunc_mem = - (void (*)(OutPeriod, SW_RUN *)) get_swaBulk_mem; -#elif defined(STEPWAT) - SW_OutputPtrs[k].pfunc_agg = - (void (*)(OutPeriod, SW_RUN *)) get_swaBulk_agg; - SW_OutputPtrs[k].pfunc_SXW = - (void (*)(OutPeriod, SW_RUN *)) get_none; -#endif - break; - - case eSW_SWAMatric: -#if defined(SW_OUTTEXT) - SW_OutputPtrs[k].pfunc_text = - (void (*)(OutPeriod, SW_RUN *)) get_swaMatric_text; -#endif -#if defined(RSOILWAT) || defined(SWNETCDF) - SW_OutputPtrs[k].pfunc_mem = - (void (*)(OutPeriod, SW_RUN *)) get_swaMatric_mem; -#elif defined(STEPWAT) - SW_OutputPtrs[k].pfunc_agg = - (void (*)(OutPeriod, SW_RUN *)) get_swaMatric_agg; - SW_OutputPtrs[k].pfunc_SXW = - (void (*)(OutPeriod, SW_RUN *)) get_none; -#endif - break; - - case eSW_SWA: -#if defined(SW_OUTTEXT) - SW_OutputPtrs[k].pfunc_text = - (void (*)(OutPeriod, SW_RUN *)) get_swa_text; -#endif -#if defined(RSOILWAT) || defined(SWNETCDF) - SW_OutputPtrs[k].pfunc_mem = - (void (*)(OutPeriod, SW_RUN *)) get_swa_mem; -#elif defined(STEPWAT) - SW_OutputPtrs[k].pfunc_agg = - (void (*)(OutPeriod, SW_RUN *)) get_swa_agg; - SW_OutputPtrs[k].pfunc_SXW = - (void (*)(OutPeriod, SW_RUN *)) get_none; -#endif - break; - - case eSW_SurfaceWater: -#if defined(SW_OUTTEXT) - SW_OutputPtrs[k].pfunc_text = - (void (*)(OutPeriod, SW_RUN *)) get_surfaceWater_text; -#endif -#if defined(RSOILWAT) || defined(SWNETCDF) - SW_OutputPtrs[k].pfunc_mem = - (void (*)(OutPeriod, SW_RUN *)) get_surfaceWater_mem; -#elif defined(STEPWAT) - SW_OutputPtrs[k].pfunc_agg = - (void (*)(OutPeriod, SW_RUN *)) get_surfaceWater_agg; - SW_OutputPtrs[k].pfunc_SXW = - (void (*)(OutPeriod, SW_RUN *)) get_none; -#endif - break; - - case eSW_Runoff: -#if defined(SW_OUTTEXT) - SW_OutputPtrs[k].pfunc_text = - (void (*)(OutPeriod, SW_RUN *)) get_runoffrunon_text; -#endif -#if defined(RSOILWAT) || defined(SWNETCDF) - SW_OutputPtrs[k].pfunc_mem = - (void (*)(OutPeriod, SW_RUN *)) get_runoffrunon_mem; -#elif defined(STEPWAT) - SW_OutputPtrs[k].pfunc_agg = - (void (*)(OutPeriod, SW_RUN *)) get_runoffrunon_agg; - SW_OutputPtrs[k].pfunc_SXW = - (void (*)(OutPeriod, SW_RUN *)) get_none; -#endif - break; - - case eSW_Transp: -#if defined(SW_OUTTEXT) - SW_OutputPtrs[k].pfunc_text = - (void (*)(OutPeriod, SW_RUN *)) get_transp_text; -#endif -#if defined(RSOILWAT) || defined(SWNETCDF) - SW_OutputPtrs[k].pfunc_mem = - (void (*)(OutPeriod, SW_RUN *)) get_transp_mem; -#elif defined(STEPWAT) - SW_OutputPtrs[k].pfunc_agg = - (void (*)(OutPeriod, SW_RUN *)) get_transp_agg; - SW_OutputPtrs[k].pfunc_SXW = - (void (*)(OutPeriod, SW_RUN *)) get_transp_SXW; -#endif - break; - - case eSW_EvapSoil: -#if defined(SW_OUTTEXT) - SW_OutputPtrs[k].pfunc_text = - (void (*)(OutPeriod, SW_RUN *)) get_evapSoil_text; -#endif -#if defined(RSOILWAT) || defined(SWNETCDF) - SW_OutputPtrs[k].pfunc_mem = - (void (*)(OutPeriod, SW_RUN *)) get_evapSoil_mem; -#elif defined(STEPWAT) - SW_OutputPtrs[k].pfunc_agg = - (void (*)(OutPeriod, SW_RUN *)) get_evapSoil_agg; - SW_OutputPtrs[k].pfunc_SXW = - (void (*)(OutPeriod, SW_RUN *)) get_none; -#endif - break; - - case eSW_EvapSurface: -#if defined(SW_OUTTEXT) - SW_OutputPtrs[k].pfunc_text = - (void (*)(OutPeriod, SW_RUN *)) get_evapSurface_text; -#endif -#if defined(RSOILWAT) || defined(SWNETCDF) - SW_OutputPtrs[k].pfunc_mem = - (void (*)(OutPeriod, SW_RUN *)) get_evapSurface_mem; -#elif defined(STEPWAT) - SW_OutputPtrs[k].pfunc_agg = - (void (*)(OutPeriod, SW_RUN *)) get_evapSurface_agg; - SW_OutputPtrs[k].pfunc_SXW = - (void (*)(OutPeriod, SW_RUN *)) get_none; -#endif - break; - - case eSW_Interception: -#if defined(SW_OUTTEXT) - SW_OutputPtrs[k].pfunc_text = - (void (*)(OutPeriod, SW_RUN *)) get_interception_text; -#endif -#if defined(RSOILWAT) || defined(SWNETCDF) - SW_OutputPtrs[k].pfunc_mem = - (void (*)(OutPeriod, SW_RUN *)) get_interception_mem; -#elif defined(STEPWAT) - SW_OutputPtrs[k].pfunc_agg = - (void (*)(OutPeriod, SW_RUN *)) get_interception_agg; - SW_OutputPtrs[k].pfunc_SXW = - (void (*)(OutPeriod, SW_RUN *)) get_none; -#endif - break; - - case eSW_SoilInf: -#if defined(SW_OUTTEXT) - SW_OutputPtrs[k].pfunc_text = - (void (*)(OutPeriod, SW_RUN *)) get_soilinf_text; -#endif -#if defined(RSOILWAT) || defined(SWNETCDF) - SW_OutputPtrs[k].pfunc_mem = - (void (*)(OutPeriod, SW_RUN *)) get_soilinf_mem; -#elif defined(STEPWAT) - SW_OutputPtrs[k].pfunc_agg = - (void (*)(OutPeriod, SW_RUN *)) get_soilinf_agg; - SW_OutputPtrs[k].pfunc_SXW = - (void (*)(OutPeriod, SW_RUN *)) get_none; -#endif - break; - - case eSW_LyrDrain: -#if defined(SW_OUTTEXT) - SW_OutputPtrs[k].pfunc_text = - (void (*)(OutPeriod, SW_RUN *)) get_lyrdrain_text; -#endif -#if defined(RSOILWAT) || defined(SWNETCDF) - SW_OutputPtrs[k].pfunc_mem = - (void (*)(OutPeriod, SW_RUN *)) get_lyrdrain_mem; -#elif defined(STEPWAT) - SW_OutputPtrs[k].pfunc_agg = - (void (*)(OutPeriod, SW_RUN *)) get_lyrdrain_agg; - SW_OutputPtrs[k].pfunc_SXW = - (void (*)(OutPeriod, SW_RUN *)) get_none; -#endif - break; - - case eSW_HydRed: -#if defined(SW_OUTTEXT) - SW_OutputPtrs[k].pfunc_text = - (void (*)(OutPeriod, SW_RUN *)) get_hydred_text; -#endif -#if defined(RSOILWAT) || defined(SWNETCDF) - SW_OutputPtrs[k].pfunc_mem = - (void (*)(OutPeriod, SW_RUN *)) get_hydred_mem; -#elif defined(STEPWAT) - SW_OutputPtrs[k].pfunc_agg = - (void (*)(OutPeriod, SW_RUN *)) get_hydred_agg; - SW_OutputPtrs[k].pfunc_SXW = - (void (*)(OutPeriod, SW_RUN *)) get_none; -#endif - break; - - case eSW_AET: -#if defined(SW_OUTTEXT) - SW_OutputPtrs[k].pfunc_text = - (void (*)(OutPeriod, SW_RUN *)) get_aet_text; -#endif -#if defined(RSOILWAT) || defined(SWNETCDF) - SW_OutputPtrs[k].pfunc_mem = - (void (*)(OutPeriod, SW_RUN *)) get_aet_mem; -#elif defined(STEPWAT) - SW_OutputPtrs[k].pfunc_agg = - (void (*)(OutPeriod, SW_RUN *)) get_aet_agg; - SW_OutputPtrs[k].pfunc_SXW = - (void (*)(OutPeriod, SW_RUN *)) get_aet_SXW; -#endif - break; - - case eSW_PET: -#if defined(SW_OUTTEXT) - SW_OutputPtrs[k].pfunc_text = - (void (*)(OutPeriod, SW_RUN *)) get_pet_text; -#endif -#if defined(RSOILWAT) || defined(SWNETCDF) - SW_OutputPtrs[k].pfunc_mem = - (void (*)(OutPeriod, SW_RUN *)) get_pet_mem; -#elif defined(STEPWAT) - SW_OutputPtrs[k].pfunc_agg = - (void (*)(OutPeriod, SW_RUN *)) get_pet_agg; - SW_OutputPtrs[k].pfunc_SXW = - (void (*)(OutPeriod, SW_RUN *)) get_none; -#endif - break; - - case eSW_WetDays: -#if defined(SW_OUTTEXT) - SW_OutputPtrs[k].pfunc_text = - (void (*)(OutPeriod, SW_RUN *)) get_wetdays_text; -#endif -#if defined(RSOILWAT) || defined(SWNETCDF) - SW_OutputPtrs[k].pfunc_mem = - (void (*)(OutPeriod, SW_RUN *)) get_wetdays_mem; -#elif defined(STEPWAT) - SW_OutputPtrs[k].pfunc_agg = - (void (*)(OutPeriod, SW_RUN *)) get_wetdays_agg; - SW_OutputPtrs[k].pfunc_SXW = - (void (*)(OutPeriod, SW_RUN *)) get_none; -#endif - break; - - case eSW_SnowPack: -#if defined(SW_OUTTEXT) - SW_OutputPtrs[k].pfunc_text = - (void (*)(OutPeriod, SW_RUN *)) get_snowpack_text; -#endif -#if defined(RSOILWAT) || defined(SWNETCDF) - SW_OutputPtrs[k].pfunc_mem = - (void (*)(OutPeriod, SW_RUN *)) get_snowpack_mem; -#elif defined(STEPWAT) - SW_OutputPtrs[k].pfunc_agg = - (void (*)(OutPeriod, SW_RUN *)) get_snowpack_agg; - SW_OutputPtrs[k].pfunc_SXW = - (void (*)(OutPeriod, SW_RUN *)) get_none; -#endif - break; - - case eSW_DeepSWC: -#if defined(SW_OUTTEXT) - SW_OutputPtrs[k].pfunc_text = - (void (*)(OutPeriod, SW_RUN *)) get_deepswc_text; -#endif -#if defined(RSOILWAT) || defined(SWNETCDF) - SW_OutputPtrs[k].pfunc_mem = - (void (*)(OutPeriod, SW_RUN *)) get_deepswc_mem; -#elif defined(STEPWAT) - SW_OutputPtrs[k].pfunc_agg = - (void (*)(OutPeriod, SW_RUN *)) get_deepswc_agg; - SW_OutputPtrs[k].pfunc_SXW = - (void (*)(OutPeriod, SW_RUN *)) get_none; -#endif - break; - - case eSW_SoilTemp: -#if defined(SW_OUTTEXT) - SW_OutputPtrs[k].pfunc_text = - (void (*)(OutPeriod, SW_RUN *)) get_soiltemp_text; -#endif -#if defined(RSOILWAT) || defined(SWNETCDF) - SW_OutputPtrs[k].pfunc_mem = - (void (*)(OutPeriod, SW_RUN *)) get_soiltemp_mem; -#elif defined(STEPWAT) - SW_OutputPtrs[k].pfunc_agg = - (void (*)(OutPeriod, SW_RUN *)) get_soiltemp_agg; - SW_OutputPtrs[k].pfunc_SXW = - (void (*)(OutPeriod, SW_RUN *)) get_none; -#endif - break; - - case eSW_Frozen: -#if defined(SW_OUTTEXT) - SW_OutputPtrs[k].pfunc_text = - (void (*)(OutPeriod, SW_RUN *)) get_frozen_text; -#endif -#if defined(RSOILWAT) || defined(SWNETCDF) - SW_OutputPtrs[k].pfunc_mem = - (void (*)(OutPeriod, SW_RUN *)) get_frozen_mem; -#elif defined(STEPWAT) - SW_OutputPtrs[k].pfunc_agg = - (void (*)(OutPeriod, SW_RUN *)) get_frozen_agg; - SW_OutputPtrs[k].pfunc_SXW = - (void (*)(OutPeriod, SW_RUN *)) get_none; -#endif - break; - - case eSW_Estab: -#if defined(SW_OUTTEXT) - SW_OutputPtrs[k].pfunc_text = - (void (*)(OutPeriod, SW_RUN *)) get_estab_text; -#endif -#if defined(RSOILWAT) || defined(SWNETCDF) - SW_OutputPtrs[k].pfunc_mem = - (void (*)(OutPeriod, SW_RUN *)) get_estab_mem; -#elif defined(STEPWAT) - SW_OutputPtrs[k].pfunc_agg = - (void (*)(OutPeriod, SW_RUN *)) get_estab_agg; - SW_OutputPtrs[k].pfunc_SXW = - (void (*)(OutPeriod, SW_RUN *)) get_none; -#endif - break; - - case eSW_CO2Effects: -#if defined(SW_OUTTEXT) - SW_OutputPtrs[k].pfunc_text = - (void (*)(OutPeriod, SW_RUN *)) get_co2effects_text; -#endif -#if defined(RSOILWAT) || defined(SWNETCDF) - SW_OutputPtrs[k].pfunc_mem = - (void (*)(OutPeriod, SW_RUN *)) get_co2effects_mem; -#elif defined(STEPWAT) - SW_OutputPtrs[k].pfunc_agg = - (void (*)(OutPeriod, SW_RUN *)) get_co2effects_agg; - SW_OutputPtrs[k].pfunc_SXW = - (void (*)(OutPeriod, SW_RUN *)) get_none; -#endif - break; - - case eSW_Biomass: -#if defined(SW_OUTTEXT) - SW_OutputPtrs[k].pfunc_text = - (void (*)(OutPeriod, SW_RUN *)) get_biomass_text; -#endif -#if defined(RSOILWAT) || defined(SWNETCDF) - SW_OutputPtrs[k].pfunc_mem = - (void (*)(OutPeriod, SW_RUN *)) get_biomass_mem; -#elif defined(STEPWAT) - SW_OutputPtrs[k].pfunc_agg = - (void (*)(OutPeriod, SW_RUN *)) get_biomass_agg; - SW_OutputPtrs[k].pfunc_SXW = - (void (*)(OutPeriod, SW_RUN *)) get_none; -#endif - break; - - default: -#if defined(SW_OUTTEXT) - SW_OutputPtrs[k].pfunc_text = - (void (*)(OutPeriod, SW_RUN *)) get_none; -#endif -#if defined(RSOILWAT) || defined(SWNETCDF) - SW_OutputPtrs[k].pfunc_mem = - (void (*)(OutPeriod, SW_RUN *)) get_none; -#elif defined(STEPWAT) - SW_OutputPtrs[k].pfunc_agg = - (void (*)(OutPeriod, SW_RUN *)) get_none; - SW_OutputPtrs[k].pfunc_SXW = - (void (*)(OutPeriod, SW_RUN *)) get_none; -#endif - break; - } - } // end of loop across output keys - - #if defined(SWNETCDF) - SW_OUT_construct_outarray(GenOutput, SW_Output, LogInfo); + SW_OUT_construct_outarray(OutDom, OutRun, LogInfo); if (LogInfo->stopRun) { return; // Exit function prematurely due to error } #else (void) LogInfo; + (void) OutDom; #endif } void SW_OUT_deconstruct(Bool full_reset, SW_RUN *sw) { - IntUS k, i; - - ForEachOutKey(k) { - if (full_reset) { - for (i = 0; i < 5 * NVEGTYPES + MAX_LAYERS; i++) { - if (!isnull(sw->GenOutput.colnames_OUT[k][i])) { - free(sw->GenOutput.colnames_OUT[k][i]); - sw->GenOutput.colnames_OUT[k][i] = NULL; - } - } - } - -#ifdef RSOILWAT - if (!isnull(sw->Output[k].outfile)) { - free(sw->Output[k].outfile); - sw->Output[k].outfile = NULL; - } -#endif - -#if defined(SWNETCDF) - SW_NC_dealloc_outputkey_var_info(sw->Output, k, sw->GenOutput.nvar_OUT); -#endif - } #if defined(SW_OUTARRAY) if (full_reset) { - SW_OUT_deconstruct_outarray(&sw->GenOutput); + SW_OUT_deconstruct_outarray(&sw->OutRun); } +#else + (void) sw; + (void) full_reset; #endif - #if defined(SWNETCDF) OutPeriod pd; + IntUS k; ForEachOutKey(k) { ForEachOutPeriod(pd) { @@ -2607,33 +2015,34 @@ void SW_OUT_set_colnames( @param[in] tLayers Number of soil layers @param[in] n_evap_lyrs Number of soil layers with evaporation @param[in] SW_VegEstab Struct for vegetation establishment -@param[out] SW_GenOutput Holds general variables that deal with output +@param[out] OutDom Struct of type SW_OUT_DOM that holds output + information that do not change throughout simulation runs @param[out] LogInfo Holds information on warnings and errors */ void SW_OUT_setup_output( int tLayers, int n_evap_lyrs, SW_VEGESTAB *SW_VegEstab, - SW_GEN_OUT *SW_GenOutput, + SW_OUT_DOM *OutDom, LOG_INFO *LogInfo ) { SW_OUT_set_ncol( tLayers, n_evap_lyrs, SW_VegEstab->count, - SW_GenOutput->ncol_OUT, - SW_GenOutput->nvar_OUT, - SW_GenOutput->nsl_OUT, - SW_GenOutput->npft_OUT + OutDom->ncol_OUT, + OutDom->nvar_OUT, + OutDom->nsl_OUT, + OutDom->npft_OUT ); #if defined(SWNETCDF) SW_OUT_calc_iOUToffset( - SW_GenOutput->nrow_OUT, - SW_GenOutput->nvar_OUT, - SW_GenOutput->nsl_OUT, - SW_GenOutput->npft_OUT, - SW_GenOutput->iOUToffset + OutDom->nrow_OUT, + OutDom->nvar_OUT, + OutDom->nsl_OUT, + OutDom->npft_OUT, + OutDom->iOUToffset ); (void) LogInfo; @@ -2641,39 +2050,46 @@ void SW_OUT_setup_output( SW_OUT_set_colnames( tLayers, SW_VegEstab->parms, - SW_GenOutput->ncol_OUT, - SW_GenOutput->colnames_OUT, + OutDom->ncol_OUT, + OutDom->colnames_OUT, LogInfo ); #endif // !SWNETCDF } -void SW_OUT_new_year(TimeInt firstdoy, TimeInt lastdoy, SW_OUTPUT *SW_Output) { +void SW_OUT_new_year( + TimeInt firstdoy, + TimeInt lastdoy, + SW_OUT_DOM *OutDom, + TimeInt first[], + TimeInt last[] +) { /* =================================================== */ /* reset the terminal output days each year */ IntUS k; ForEachOutKey(k) { - if (!SW_Output[k].use) { + if (!OutDom->use[k]) { continue; } - if (SW_Output[k].first_orig <= firstdoy) { - SW_Output[k].first = firstdoy; + if (OutDom->first_orig[k] <= firstdoy) { + first[k] = firstdoy; } else { - SW_Output[k].first = SW_Output[k].first_orig; + first[k] = OutDom->first_orig[k]; } - if (SW_Output[k].last_orig >= lastdoy) { - SW_Output[k].last = lastdoy; + if (OutDom->last_orig[k] >= lastdoy) { + last[k] = lastdoy; } else { - SW_Output[k].last = SW_Output[k].last_orig; + last[k] = OutDom->last_orig[k]; } } } int SW_OUT_read_onekey( + SW_OUT_DOM *OutDom, OutKey k, OutSum sumtype, int first, @@ -2682,7 +2098,6 @@ int SW_OUT_read_onekey( size_t sizeof_msg, Bool *VegProd_use_SWA, Bool deepdrain, - SW_OUTPUT *SW_Output, char *InFiles[] ) { int res = 0; // return value indicating type of message if any @@ -2691,18 +2106,18 @@ int SW_OUT_read_onekey( msg[0] = '\0'; // Convert strings to index numbers - SW_Output[k].sumtype = sumtype; + OutDom->sumtype[k] = sumtype; - SW_Output[k].use = (Bool) (sumtype != eSW_Off); + OutDom->use[k] = (Bool) (sumtype != eSW_Off); // Proceed to next line if output key/type is turned off - if (!SW_Output[k].use) { + if (!OutDom->use[k]) { return (-1); // return and read next line of `outsetup.in` } /* check validity of summary type */ - if (SW_Output[k].sumtype == eSW_Fnl && !SW_Output[k].has_sl) { - SW_Output[k].sumtype = eSW_Avg; + if (OutDom->sumtype[k] == eSW_Fnl && !OutDom->has_sl[k]) { + OutDom->sumtype[k] = eSW_Avg; snprintf( msg, @@ -2725,13 +2140,13 @@ int SW_OUT_read_onekey( /* Check validity of output key */ if (k == eSW_Estab) { - SW_Output[k].sumtype = eSW_Sum; + OutDom->sumtype[k] = eSW_Sum; first = 1; last = 366; } else if ((k == eSW_AllVeg || k == eSW_ET || k == eSW_AllWthr || k == eSW_AllH2O)) { - SW_Output[k].use = swFALSE; + OutDom->use[k] = swFALSE; snprintf( msg, @@ -2744,8 +2159,8 @@ int SW_OUT_read_onekey( } /* verify deep drainage parameters */ - if (k == eSW_DeepSWC && SW_Output[k].sumtype != eSW_Off && !deepdrain) { - SW_Output[k].use = swFALSE; + if (k == eSW_DeepSWC && OutDom->sumtype[k] != eSW_Off && !deepdrain) { + OutDom->use[k] = swFALSE; snprintf( msg, @@ -2758,11 +2173,11 @@ int SW_OUT_read_onekey( return (LOGWARN); } - // Set remaining values of `SW_Output[k]` - SW_Output[k].first_orig = first; - SW_Output[k].last_orig = last; + // Set remaining values of `OutDom->...[k]` + OutDom->first_orig[k] = first; + OutDom->last_orig[k] = last; - if (SW_Output[k].last_orig == 0) { + if (OutDom->last_orig[k] == 0) { snprintf( msg, sizeof_msg, @@ -2794,19 +2209,13 @@ We have two options to specify time steps: @param[in,out] sw Comprehensive structure holding all information dealt with in SOILWAT2 +@param[in,out] OutDom Struct of type SW_OUT_DOM that holds output + information that do not change throughout simulation runs @param[in] InFiles Array of program in/output files -@param[in] timeSteps Keeps track of the output time periods that - are required for each output key -@param[out] used_OUTNPERIODS The number of different time steps/periods - that are used/requested @param[out] LogInfo Holds information on warnings and errors */ void SW_OUT_read( - SW_RUN *sw, - char *InFiles[], - OutPeriod timeSteps[][SW_OUTNPERIODS], - IntUS *used_OUTNPERIODS, - LOG_INFO *LogInfo + SW_RUN *sw, SW_OUT_DOM *OutDom, char *InFiles[], LOG_INFO *LogInfo ) { /* =================================================== */ /* read input file for output parameter setup info. @@ -2824,6 +2233,7 @@ void SW_OUT_read( int x, itemno, msg_type; IntUS i; Bool useTimeStep = swFALSE; + IntUS *used_OUTNPERIODS = &OutDom->used_OUTNPERIODS; /* these dims come from the orig format str */ /* except for the uppercase space. */ @@ -2964,6 +2374,7 @@ void SW_OUT_read( // Fill information into `sw->Output[k]` msg_type = SW_OUT_read_onekey( + OutDom, k, str2stype(Str_ToUpper(sumtype, upsum), LogInfo), first, @@ -2973,7 +2384,6 @@ void SW_OUT_read( sizeof msg, &sw->VegProd.use_SWA, sw->Site.deepdrain, - sw->Output, InFiles ); @@ -2988,16 +2398,17 @@ void SW_OUT_read( // Specify which output time periods are requested for this output // key/type - if (sw->Output[k].use) { + if (OutDom->use[k]) { if (useTimeStep) { // `timeStep` was read in earlier on the `TIMESTEP` line; ignore // `period` for (i = 0; i < *used_OUTNPERIODS; i++) { - timeSteps[k][i] = str2period(Str_ToUpper(timeStep[i], ext)); + OutDom->timeSteps[k][i] = + str2period(Str_ToUpper(timeStep[i], ext)); } } else { - timeSteps[k][0] = str2period(Str_ToUpper(period, ext)); + OutDom->timeSteps[k][0] = str2period(Str_ToUpper(period, ext)); } } } // end of while-loop @@ -3005,7 +2416,7 @@ void SW_OUT_read( CloseFile(&f, LogInfo); // Determine which output periods are turned on for at least one output key - find_OutPeriods_inUse(&sw->GenOutput, sw->Output); + find_OutPeriods_inUse(OutDom); #if defined(SW_OUTTEXT) // Determine for which output periods text output per soil layer or @@ -3013,49 +2424,47 @@ void SW_OUT_read( find_TXToutputSoilReg_inUse( sw->FileStatus.make_soil, sw->FileStatus.make_regular, - sw->Output, - sw->GenOutput.timeSteps, - sw->GenOutput.used_OUTNPERIODS + OutDom->has_sl, + OutDom->timeSteps, + OutDom->used_OUTNPERIODS ); #endif #if defined(STEPWAT) || defined(SWNETCDF) // Determine number of used years/months/weeks/days in simulation period - SW_OUT_set_nrow( - &sw->Model, sw->GenOutput.use_OutPeriod, sw->GenOutput.nrow_OUT - ); + SW_OUT_set_nrow(&sw->Model, OutDom->use_OutPeriod, OutDom->nrow_OUT); #endif } void _collect_values( SW_RUN *sw, - SW_OUTPUT_POINTERS *SW_OutputPtrs, + SW_OUT_DOM *OutDom, Bool bFlush_output, TimeInt tOffset, LOG_INFO *LogInfo ) { - SW_OUT_sum_today(sw, eSWC, bFlush_output, tOffset, LogInfo); + SW_OUT_sum_today(sw, OutDom, eSWC, bFlush_output, tOffset, LogInfo); if (LogInfo->stopRun) { return; // Exit function prematurely due to error } - SW_OUT_sum_today(sw, eWTH, bFlush_output, tOffset, LogInfo); + SW_OUT_sum_today(sw, OutDom, eWTH, bFlush_output, tOffset, LogInfo); if (LogInfo->stopRun) { return; // Exit function prematurely due to error } - SW_OUT_sum_today(sw, eVES, bFlush_output, tOffset, LogInfo); + SW_OUT_sum_today(sw, OutDom, eVES, bFlush_output, tOffset, LogInfo); if (LogInfo->stopRun) { return; // Exit function prematurely due to error } - SW_OUT_sum_today(sw, eVPD, bFlush_output, tOffset, LogInfo); + SW_OUT_sum_today(sw, OutDom, eVPD, bFlush_output, tOffset, LogInfo); if (LogInfo->stopRun) { return; // Exit function prematurely due to error } - SW_OUT_write_today(sw, SW_OutputPtrs, bFlush_output, tOffset); + SW_OUT_write_today(sw, OutDom, bFlush_output, tOffset); } /** called at year end to process the remainder of the output period. @@ -3065,16 +2474,14 @@ subs. @param[in,out] sw Comprehensive struct of type SW_RUN containing all information in the simulation -@param[in] SW_OutputPtrs SW_OUTPUT_POINTERS of size SW_OUTNKEYS which - hold pointers to subroutines for output keys +@param[in] OutDom Struct of type SW_OUT_DOM that holds output + information that do not change throughout simulation runs @param[out] LogInfo Holds information on warnings and errors */ -void SW_OUT_flush( - SW_RUN *sw, SW_OUTPUT_POINTERS *SW_OutputPtrs, LOG_INFO *LogInfo -) { +void SW_OUT_flush(SW_RUN *sw, SW_OUT_DOM *OutDom, LOG_INFO *LogInfo) { TimeInt localTOffset = 0; // tOffset is zero when called from this function - _collect_values(sw, SW_OutputPtrs, swTRUE, localTOffset, LogInfo); + _collect_values(sw, OutDom, swTRUE, localTOffset, LogInfo); } /** adds today's output values to week, month and year @@ -3089,6 +2496,8 @@ need to perform _new_day() on the soilwater. @param[in,out] sw Comprehensive struct of type SW_RUN containing all information in the simulation +@param[in,out] OutDom Struct of type SW_OUT_DOM that holds output + information that do not change throughout simulation runs @param[in] otyp Identifies the current module/object @param[in] bFlush_output Determines if output should be created for a specific output key @@ -3097,6 +2506,7 @@ need to perform _new_day() on the soilwater. */ void SW_OUT_sum_today( SW_RUN *sw, + SW_OUT_DOM *OutDom, ObjType otyp, Bool bFlush_output, TimeInt tOffset, @@ -3109,7 +2519,7 @@ void SW_OUT_sum_today( ForEachOutPeriod(pd) { // `newperiod[eSW_Day]` is always TRUE if (bFlush_output || sw->Model.newperiod[pd]) { - average_for(sw, otyp, pd, bFlush_output, tOffset, LogInfo); + average_for(sw, OutDom, otyp, pd, bFlush_output, tOffset, LogInfo); if (LogInfo->stopRun) { return; // Exit function prematurely due to error @@ -3140,14 +2550,7 @@ void SW_OUT_sum_today( if (!bFlush_output) { ForEachOutPeriod(pd) { - collect_sums( - sw, - otyp, - pd, - sw->GenOutput.timeSteps, - sw->GenOutput.used_OUTNPERIODS, - LogInfo - ); + collect_sums(sw, OutDom, otyp, pd, LogInfo); if (LogInfo->stopRun) { return; // Exit function prematurely due to error @@ -3165,17 +2568,14 @@ void SW_OUT_sum_today( @param[in] sw Comprehensive struct of type SW_RUN containing all information in the simulation -@param[in] SW_OutputPtrs SW_OUTPUT_POINTERS of size SW_OUTNKEYS which - hold pointers to subroutines for output keys +@param[in] OutDom Struct of type SW_OUT_DOM that holds output + information that do not change throughout simulation runs @param[in] bFlush_output Determines if output should be created for a specific output key @param[in] tOffset Offset describing with the previous or current period */ void SW_OUT_write_today( - SW_RUN *sw, - SW_OUTPUT_POINTERS *SW_OutputPtrs, - Bool bFlush_output, - TimeInt tOffset + SW_RUN *sw, SW_OUT_DOM *OutDom, Bool bFlush_output, TimeInt tOffset ) { /* --------------------------------------------------- */ /* all output values must have been summed, averaged or @@ -3215,8 +2615,8 @@ void SW_OUT_write_today( #endif IntUS k, i, outPeriod; - /* Update `tOffset` within SW_GEN_OUT for output functions */ - sw->GenOutput.tOffset = tOffset; + /* Update `tOffset` within SW_OUT_RUN for output functions */ + sw->OutRun.tOffset = tOffset; #ifdef SWDEBUG int debug = 0; @@ -3257,7 +2657,7 @@ void SW_OUT_write_today( // `csv`-files assume anyhow that first/last are identical for every output // type/key writeit[eSW_Day] = - (Bool) (t < sw->Output[0].first || t > sw->Output[0].last); + (Bool) (t < sw->OutRun.first[0] || t > sw->OutRun.last[0]); writeit[eSW_Week] = (Bool) (writeit[eSW_Day] && (sw->Model.newperiod[eSW_Week] || bFlush_output)); @@ -3281,19 +2681,18 @@ void SW_OUT_write_today( } #endif - if (!sw->Output[k].use) { + if (!OutDom->use[k]) { continue; } - for (i = 0; i < sw->GenOutput.used_OUTNPERIODS; i++) { - outPeriod = sw->GenOutput.timeSteps[k][i]; + for (i = 0; i < OutDom->used_OUTNPERIODS; i++) { + outPeriod = OutDom->timeSteps[k][i]; use_help = (Bool) (outPeriod != eSW_NoTime && writeit[outPeriod]); #ifdef STEPWAT use_help_txt = use_help; - use_help_SXW = - (Bool) (sw->GenOutput.timeSteps_SXW[k][i] != eSW_NoTime && - writeit[sw->GenOutput.timeSteps_SXW[k][i]]); + use_help_SXW = (Bool) (OutDom->timeSteps_SXW[k][i] != eSW_NoTime && + writeit[OutDom->timeSteps_SXW[k][i]]); use_help = (Bool) (use_help_txt || use_help_SXW); #endif @@ -3310,9 +2709,8 @@ void SW_OUT_write_today( } #endif - ((void (*)(OutPeriod, SW_RUN *)) SW_OutputPtrs[k].pfunc_text)( - outPeriod, sw - ); + ((void (*)(OutPeriod, SW_RUN *) + ) OutDom->pfunc_text[k])(outPeriod, sw); #elif defined(RSOILWAT) || defined(SWNETCDF) #ifdef SWDEBUG @@ -3322,9 +2720,8 @@ void SW_OUT_write_today( ); } #endif - ((void (*)(OutPeriod, SW_RUN *)) SW_OutputPtrs[k].pfunc_mem)( - outPeriod, sw - ); + ((void (*)(OutPeriod, SW_RUN *, SW_OUT_DOM *) + ) OutDom->pfunc_mem[k])(outPeriod, sw, OutDom); #elif defined(STEPWAT) if (use_help_SXW) { @@ -3332,20 +2729,21 @@ void SW_OUT_write_today( if (debug) { sw_printf( " call pfunc_SXW(%d=%s))", - sw->GenOutput.timeSteps_SXW[k][i], - pd2str[sw->GenOutput.timeSteps_SXW[k][i]] + OutDom->timeSteps_SXW[k][i], + pd2str[OutDom->timeSteps_SXW[k][i]] ); } #endif - ((void (*)(OutPeriod, SW_RUN *)) SW_OutputPtrs[k].pfunc_SXW)( - sw->GenOutput.timeSteps_SXW[k][i], sw + ((void (*)(OutPeriod, SW_RUN *, SW_OUT_DOM *) + ) OutDom->pfunc_SXW[k])( + OutDom->timeSteps_SXW[k][i], sw, OutDom ); } if (!use_help_txt) { continue; // SXW output complete; skip to next output period } else { - if (sw->GenOutput.prepare_IterationSummary) { + if (sw->OutRun.prepare_IterationSummary) { #ifdef SWDEBUG if (debug) { sw_printf( @@ -3355,12 +2753,12 @@ void SW_OUT_write_today( ); } #endif - ((void (*)(OutPeriod, SW_RUN *)) SW_OutputPtrs[k] - .pfunc_agg)(outPeriod, sw); + ((void (*)(OutPeriod, SW_RUN *, SW_OUT_DOM *) + ) OutDom->pfunc_agg[k])(outPeriod, sw, OutDom); } - if (sw->GenOutput.print_SW_Output) { - outPeriod = sw->GenOutput.timeSteps[k][i]; + if (OutDom->print_SW_Output) { + outPeriod = OutDom->timeSteps[k][i]; #ifdef SWDEBUG if (debug) { sw_printf( @@ -3370,8 +2768,8 @@ void SW_OUT_write_today( ); } #endif - ((void (*)(OutPeriod, SW_RUN *)) SW_OutputPtrs[k] - .pfunc_text)(outPeriod, sw); + ((void (*)(OutPeriod, SW_RUN *, SW_OUT_DOM *) + ) OutDom->pfunc_text[k])(outPeriod, sw, OutDom); } } #endif @@ -3384,9 +2782,9 @@ void SW_OUT_write_today( #if defined(SW_OUTTEXT) /* concatenate formatted output for one row of `csv`- files */ - if (sw->GenOutput.print_SW_Output) { - strcpy(tempstr, sw->GenOutput.sw_outstr); - if (sw->Output[k].has_sl) { + if (OutDom->print_SW_Output) { + strcpy(tempstr, sw->OutRun.sw_outstr); + if (OutDom->has_sl[k]) { strcat(sw->FileStatus.buf_soil[outPeriod], tempstr); } else { strcat(sw->FileStatus.buf_reg[outPeriod], tempstr); @@ -3394,9 +2792,9 @@ void SW_OUT_write_today( } #ifdef STEPWAT - if (sw->GenOutput.print_IterationSummary) { - strcpy(tempstr, sw->GenOutput.sw_outstr_agg); - if (sw->Output[k].has_sl) { + if (OutDom->print_IterationSummary) { + strcpy(tempstr, sw->OutRun.sw_outstr_agg); + if (OutDom->has_sl[k]) { strcat(sw->FileStatus.buf_soil_agg[outPeriod], tempstr); } else { strcat(sw->FileStatus.buf_reg_agg[outPeriod], tempstr); @@ -3412,11 +2810,11 @@ void SW_OUT_write_today( #if defined(SW_OUTTEXT) // write formatted output to csv-files ForEachOutPeriod(p) { - if (sw->GenOutput.use_OutPeriod[p] && writeit[p]) { + if (OutDom->use_OutPeriod[p] && writeit[p]) { get_outstrleader(p, sizeof str_time, &sw->Model, tOffset, str_time); if (sw->FileStatus.make_regular[p]) { - if (sw->GenOutput.print_SW_Output) { + if (OutDom->print_SW_Output) { fprintf( sw->FileStatus.fp_reg[p], "%s%s\n", @@ -3430,7 +2828,7 @@ void SW_OUT_write_today( } #ifdef STEPWAT - if (sw->GenOutput.print_IterationSummary) { + if (OutDom->print_IterationSummary) { fprintf( sw->FileStatus.fp_reg_agg[p], "%s%s\n", @@ -3442,7 +2840,7 @@ void SW_OUT_write_today( } if (sw->FileStatus.make_soil[p]) { - if (sw->GenOutput.print_SW_Output) { + if (OutDom->print_SW_Output) { fprintf( sw->FileStatus.fp_soil[p], "%s%s\n", @@ -3452,7 +2850,7 @@ void SW_OUT_write_today( } #ifdef STEPWAT - if (sw->GenOutput.print_IterationSummary) { + if (OutDom->print_IterationSummary) { fprintf( sw->FileStatus.fp_soil_agg[p], "%s%s\n", @@ -3464,16 +2862,13 @@ void SW_OUT_write_today( } } } -#else - (void) tOffset; - (void) SW_OutputPtrs; #endif #if defined(SW_OUTARRAY) // increment row counts ForEachOutPeriod(p) { - if (sw->GenOutput.use_OutPeriod[p] && writeit[p]) { - sw->GenOutput.irow_OUT[p]++; + if (OutDom->use_OutPeriod[p] && writeit[p]) { + sw->OutRun.irow_OUT[p]++; } } #endif @@ -3492,20 +2887,13 @@ void SW_OUT_write_today( information about output files and values @param[in] SW_Domain Struct of type SW_DOMAIN holding constant temporal/spatial information for a set of simulation runs -@param[in] SW_Output SW_OUTPUT array of size SW_OUTNKEYS which holds - basic output information for all output keys -@param[in] GenOutput Holds general variables that deal with output @param[out] LogInfo Holds information on warnings and errors @note Call this routine at the beginning of the main program run, but after SW_OUT_read() which sets the global variable use_OutPeriod. */ void SW_OUT_create_files( - SW_FILE_STATUS *SW_FileStatus, - SW_DOMAIN *SW_Domain, - SW_OUTPUT *SW_Output, - SW_GEN_OUT *GenOutput, - LOG_INFO *LogInfo + SW_FILE_STATUS *SW_FileStatus, SW_DOMAIN *SW_Domain, LOG_INFO *LogInfo ) { #if defined(SOILWAT) @@ -3516,11 +2904,10 @@ void SW_OUT_create_files( #if defined(SOILWAT) && defined(SW_OUTTEXT) SW_OUT_create_textfiles( + &SW_Domain->OutDom, SW_FileStatus, - SW_Output, SW_Domain->nMaxSoilLayers, SW_Domain->PathInfo.InFiles, - GenOutput, LogInfo ); @@ -3530,12 +2917,11 @@ void SW_OUT_create_files( SW_Domain->DomainType, SW_Domain->PathInfo.output_prefix, SW_Domain, - SW_Output, - GenOutput->timeSteps, - GenOutput->used_OUTNPERIODS, - GenOutput->nvar_OUT, - GenOutput->nsl_OUT, - GenOutput->npft_OUT, + SW_Domain->OutDom.timeSteps, + SW_Domain->OutDom.used_OUTNPERIODS, + SW_Domain->OutDom.nvar_OUT, + SW_Domain->OutDom.nsl_OUT, + SW_Domain->OutDom.npft_OUT, SW_Domain->hasConsistentSoilLayerDepths, SW_Domain->depthsAllSoilLayers, SW_Domain->netCDFInfo.strideOutYears, @@ -3550,8 +2936,6 @@ void SW_OUT_create_files( #else (void) SW_FileStatus; (void) SW_Domain; - (void) SW_Output; - (void) GenOutput; (void) LogInfo; #endif } @@ -3563,23 +2947,24 @@ call this routine at the end of the program run. @param[in,out] SW_FileStatus Struct of type SW_FILE_STATUS which holds basic information about output files and values -@param[in] GenOutput Holds general variables that deal with output +@param[in] OutDom Struct of type SW_OUT_DOM that holds output + information that do not change throughout simulation runs @param[out] LogInfo Holds information on warnings and errors */ void SW_OUT_close_files( - SW_FILE_STATUS *SW_FileStatus, SW_GEN_OUT *GenOutput, LOG_INFO *LogInfo + SW_FILE_STATUS *SW_FileStatus, SW_OUT_DOM *OutDom, LOG_INFO *LogInfo ) { #if defined(SW_OUTTEXT) - SW_OUT_close_textfiles(SW_FileStatus, GenOutput, LogInfo); + SW_OUT_close_textfiles(SW_FileStatus, OutDom, LogInfo); #else (void) SW_FileStatus; - (void) GenOutput; + (void) OutDom; (void) LogInfo; #endif } -void _echo_outputs(SW_RUN *sw) { +void _echo_outputs(SW_OUT_DOM *OutDom) { IntUS k; char str[OUTSTRLEN], errstr[MAX_ERROR]; @@ -3590,20 +2975,16 @@ void _echo_outputs(SW_RUN *sw) { ); ForEachOutKey(k) { - if (!sw->Output[k].use) { + if (!OutDom->use[k]) { continue; } strcat(errstr, "---------------------------\nKey "); strcat(errstr, key2str[k]); strcat(errstr, "\n\tSummary Type: "); - strcat(errstr, styp2str[sw->Output[k].sumtype]); - snprintf( - str, OUTSTRLEN, "\n\tStart period: %d", sw->Output[k].first_orig - ); + strcat(errstr, styp2str[OutDom->sumtype[k]]); + snprintf(str, OUTSTRLEN, "\n\tStart period: %d", OutDom->first_orig[k]); strcat(errstr, str); - snprintf( - str, OUTSTRLEN, "\n\tEnd period : %d", sw->Output[k].last_orig - ); + snprintf(str, OUTSTRLEN, "\n\tEnd period : %d", OutDom->last_orig[k]); strcat(errstr, str); strcat(errstr, "\n"); } @@ -3612,7 +2993,7 @@ void _echo_outputs(SW_RUN *sw) { printf("%s\n", errstr); } -void _echo_all_inputs(SW_RUN *sw) { +void _echo_all_inputs(SW_RUN *sw, SW_OUT_DOM *OutDom) { if (!sw->VegEstab.use) { printf("Establishment not used.\n"); @@ -3621,90 +3002,37 @@ void _echo_all_inputs(SW_RUN *sw) { _echo_inputs(&sw->Site, &sw->Model); _echo_VegEstab(sw->Site.width, sw->VegEstab.parms, sw->VegEstab.count); _echo_VegProd(sw->VegProd.veg, sw->VegProd.bare_cov); - _echo_outputs(sw); -} - -/** -@brief Deep copy a source instance of SW_GEN_OUT into a destination instance - -Source values of p_OUT and p_OUTsd are not copied to destination. - -@param[out] dest Destination struct of type SW_GEN_OUT to be copied into -@param[in] source Source struct of type SW_GEN_OUT to copy -@param[in] SW_Output Passed as input argument. -@param[out] LogInfo Holds information on warnings and errors -*/ -void SW_GENOUT_deepCopy( - SW_GEN_OUT *dest, - SW_GEN_OUT *source, - SW_OUTPUT *SW_Output, - LOG_INFO *LogInfo -) { - - IntUS key, icol; - - memcpy(dest, source, sizeof(*dest)); - - SW_GENOUT_init_ptrs(dest); - - /* allocate and copy colnames_OUT */ - ForEachOutKey(key) { - for (icol = 0; icol < 5 * NVEGTYPES + MAX_LAYERS; icol++) { - if (!isnull(source->colnames_OUT[key][icol])) { - - dest->colnames_OUT[key][icol] = - Str_Dup(source->colnames_OUT[key][icol], LogInfo); - if (LogInfo->stopRun) { - return; // Exit function prematurely due to error - } - } - } - } - -/* allocate p_OUT and p_OUTsd -- but don't copy values */ -#ifdef SW_OUTARRAY - SW_OUT_construct_outarray(dest, SW_Output, LogInfo); -#else - (void) SW_Output; -#endif + _echo_outputs(OutDom); } - #if defined(SWNETCDF) /** -@brief Deep copy SW_OUTPUT instances with information in regards to -netCDFs along with netCDF output files stored in SW_FILE_STATUS +@brief Deep copy instances with information in regards to +netCDF output files stored in SW_FILE_STATUS -@param[out] dest_out Destination instances of SW_OUTPUT -@param[in] source_out Source instances of SW_OUTPUT @param[out] dest_files Destination instance of netCDF files (SW_FILE_STATUS) @param[in] source_files Source instance of netCDF files (SW_FILE_STATUS) -@param[in] useOutPeriods Specify which output periods were requested to output -@param[in] nvar_OUT Number of output variables (array of length SW_OUTNPERIODS) +@param[in] OutDom Struct of type SW_OUT_DOM that holds output + information that do not change throughout simulation runs @param[out] LogInfo Holds information on warnings and errors */ void SW_OUT_deepCopy( - SW_OUTPUT *dest_out, - SW_OUTPUT *source_out, SW_FILE_STATUS *dest_files, SW_FILE_STATUS *source_files, - Bool useOutPeriods[], - IntUS nvar_OUT[], + SW_OUT_DOM *OutDom, LOG_INFO *LogInfo ) { IntUS key; OutPeriod pd; - int varNum, attNum, fileNum; + int fileNum; int numFiles = source_files->numOutFiles; char **destFile = NULL, *srcFile = NULL; ForEachOutKey(key) { - memcpy(&dest_out[key], &source_out[key], sizeof(SW_OUTPUT)); - - if (nvar_OUT[key] > 0 && source_out[key].use) { + if (OutDom->nvar_OUT[key] > 0 && OutDom->use[key]) { ForEachOutPeriod(pd) { - if (useOutPeriods[pd]) { + if (OutDom->use_OutPeriod[pd]) { SW_NC_alloc_files( &dest_files->ncOutFiles[key][pd], numFiles, LogInfo ); @@ -3728,60 +3056,11 @@ void SW_OUT_deepCopy( } } } - - SW_NC_alloc_outputkey_var_info( - &dest_out[key], nvar_OUT[key], LogInfo - ); - if (LogInfo->stopRun) { - return; // Exit function prematurely due to error - } - - if (!isnull(source_out[key].reqOutputVars)) { - for (varNum = 0; varNum < nvar_OUT[key]; varNum++) { - dest_out[key].reqOutputVars[varNum] = - source_out[key].reqOutputVars[varNum]; - - if (dest_out[key].reqOutputVars[varNum]) { - for (attNum = 0; attNum < MAX_NATTS; attNum++) { - if (!isnull(source_out[key] - .outputVarInfo[varNum][attNum])) { - dest_out[key].outputVarInfo[varNum][attNum] = - Str_Dup( - source_out[key] - .outputVarInfo[varNum][attNum], - LogInfo - ); - if (LogInfo->stopRun) { - return; // Exit function prematurely due to - // error - } - } - } - - dest_out[key].units_sw[varNum] = - Str_Dup(source_out[key].units_sw[varNum], LogInfo); - if (LogInfo->stopRun) { - return; // Exit function prematurely due to error - } - } - } - } - - } else { - dest_out[key].reqOutputVars = NULL; - dest_out[key].outputVarInfo = NULL; - dest_out[key].units_sw = NULL; - dest_out[key].uconv = NULL; } } - -#if defined(SWNETCDF) - SW_NC_create_units_converters(dest_out, nvar_OUT, LogInfo); -#endif } #endif - /*==================================================================*/ /** @defgroup out_algo Description of the output algorithm @@ -3827,7 +3106,7 @@ void SW_OUT_deepCopy( functions `get_XXX` in file \ref SW_Output_get_functions.c - output to text files of current simulation: - output formatter function such as `get_XXX_text` which prepare a - formatted text string in the global variable \ref SW_GEN_OUT.sw_outstr + formatted text string in the global variable \ref SW_OUT_RUN.sw_outstr which is concatenated and written to the text files by SW_OUT_write_today() - these output formatter functions are assigned to pointers `SW_Output[k].pfunc_text` and called by SW_OUT_write_today() @@ -3838,8 +3117,8 @@ void SW_OUT_deepCopy( simulations (mean and SD of values) - output formatter function such as `get_XXX_agg` which - calculate a cumulative running mean and SD for the output values in - the pointer array variables `SW_GEN_OUT.p_OUT` and - `SW_GEN_OUT.p_OUTsd` + the pointer array variables `SW_OUT_RUN.p_OUT` and + `SW_OUT_RUN.p_OUTsd` - if `print_IterationSummary` is `TRUE` (i.e., for the last simulation run = last iteration in `STEPWAT2` terminology), prepare a formatted text string in the global variable @@ -3863,7 +3142,7 @@ void SW_OUT_deepCopy( - in-memory output via pointer array variable `p_OUT` - output formatter function such as `get_XXX_mem` which store the correct - values directly in the appropriate elements of `SW_GEN_OUT.p_OUT` + values directly in the appropriate elements of `SW_OUT_RUN.p_OUT` - these output formatter functions are assigned to pointers `SW_Output[k].pfunc_mem` and called by SW_OUT_write_today() - currently used by `rSOILWAT2` diff --git a/src/SW_Output_get_functions.c b/src/SW_Output_get_functions.c index f674ad036..b6c161cfb 100644 --- a/src/SW_Output_get_functions.c +++ b/src/SW_Output_get_functions.c @@ -19,7 +19,7 @@ See the \ref out_algo "output algorithm documentation" for details. /* --------------------------------------------------- */ #include "include/generic.h" // for RealD, IntU -#include "include/SW_datastructs.h" // for SW_RUN, SW_OUTTEXT, SW_GEN_OUT +#include "include/SW_datastructs.h" // for SW_RUN, SW_OUTTEXT #include "include/SW_Defines.h" // for _OUTSEP, OUT_DIGITS, OUTSTRLEN #include "include/SW_Output.h" // for get_aet_text, get_biomass_text #include "include/SW_SoilWater.h" // for SW_SWRC_SWCtoSWP @@ -52,10 +52,12 @@ static void format_IterationSummary( size_t n; RealD sd; char str[OUTSTRLEN]; - SW_GEN_OUT *go = &sw->GenOutput; + SW_OUT_RUN *OutRun = &sw->OutRun; for (i = 0; i < N; i++) { - n = iOUT(i, go->irow_OUT[pd], go->nrow_OUT[pd], ncol_TimeOUT[pd]); + n = iOUT( + i, OutRun->irow_OUT[pd], OutDom->nrow_OUT[pd], ncol_TimeOUT[pd] + ); sd = final_running_sd(sw->Model.runModelIterations, psd[n]); snprintf( @@ -69,7 +71,7 @@ static void format_IterationSummary( OUT_DIGITS, sd ); - strcat(go->sw_outstr_agg, str); + strcat(OutRun->sw_outstr_agg, str); } } @@ -80,12 +82,17 @@ static void format_IterationSummary2( size_t n; RealD sd; char str[OUTSTRLEN]; - SW_GEN_OUT *go = &sw->GenOutput; + SW_OUT_RUN *OutRun = &sw->OutRun; for (k = 0; k < N1; k++) { for (i = 0; i < sw->Site.n_layers; i++) { n = iOUT2( - i, k + offset, pd, go->irow_OUT, go->nrow_OUT, sw->Site.n_layers + i, + k + offset, + pd, + OutRun->irow_OUT, + OutRun->nrow_OUT, + sw->Site.n_layers ); sd = final_running_sd(sw->Model.runModelIterations, psd[n]); @@ -100,7 +107,7 @@ static void format_IterationSummary2( OUT_DIGITS, sd ); - strcat(go->sw_outstr_agg, str); + strcat(OutRun->sw_outstr_agg, str); } } } @@ -122,10 +129,13 @@ rather than an empty pointer. @param[in] pd Time period in simulation output (day/week/month/year) @param[in] sw Comprehensive struct of type SW_RUN containing all information in the simulation. +@param[in] OutDom Struct of type SW_OUT_DOM that holds output + information that do not change throughout simulation runs */ -void get_none(OutPeriod pd, SW_RUN *sw) { +void get_none(OutPeriod pd, SW_RUN *sw, SW_OUT_DOM *OutDom) { (void) pd; (void) sw; // Coerce to void to silence compiler + (void) OutDom; } //------ eSW_CO2Effects @@ -138,13 +148,15 @@ dealing with OUTTEXT. @param[in] pd Time period in simulation output (day/week/month/year) @param[in] sw Comprehensive struct of type SW_RUN containing all information in the simulation. +@param[in] OutDom Struct of type SW_OUT_DOM that holds output + information that do not change throughout simulation runs */ void get_co2effects_text(OutPeriod pd, SW_RUN *sw) { int k; - SW_GEN_OUT *go = &sw->GenOutput; + SW_OUT_RUN *OutRun = &sw->OutRun; char str[OUTSTRLEN]; - go->sw_outstr[0] = '\0'; + OutRun->sw_outstr[0] = '\0'; TimeInt simyear = sw->Model.simyear; (void) pd; // hack to silence "-Wunused-parameter" @@ -158,7 +170,7 @@ void get_co2effects_text(OutPeriod pd, SW_RUN *sw) { OUT_DIGITS, sw->VegProd.veg[k].co2_multipliers[BIO_INDEX][simyear] ); - strcat(go->sw_outstr, str); + strcat(OutRun->sw_outstr, str); } ForEachVegType(k) { snprintf( @@ -169,34 +181,40 @@ void get_co2effects_text(OutPeriod pd, SW_RUN *sw) { OUT_DIGITS, sw->VegProd.veg[k].co2_multipliers[WUE_INDEX][simyear] ); - strcat(go->sw_outstr, str); + strcat(OutRun->sw_outstr, str); } } #endif #if defined(RSOILWAT) || defined(SWNETCDF) -void get_co2effects_mem(OutPeriod pd, SW_RUN *sw) { +void get_co2effects_mem(OutPeriod pd, SW_RUN *sw, SW_OUT_DOM *OutDom) { int k; size_t iOUTIndex = 0; - SW_GEN_OUT *go = &sw->GenOutput; - RealD *p = go->p_OUT[eSW_CO2Effects][pd]; + SW_OUT_RUN *OutRun = &sw->OutRun; + RealD *p = OutRun->p_OUT[eSW_CO2Effects][pd]; #if defined(RSOILWAT) get_outvalleader( - &sw->Model, pd, go->irow_OUT, go->nrow_OUT, go->tOffset, p + &sw->Model, pd, OutRun->irow_OUT, OutRun->nrow_OUT, OutRun->tOffset, p ); #endif - // No averaging or summing required: + // No averaging OutRun summing required: ForEachVegType(k) { #if defined(RSOILWAT) - iOUTIndex = - iOUT(k, go->irow_OUT[pd], go->nrow_OUT[pd], ncol_TimeOUT[pd]); + iOUTIndex = iOUT( + k, OutRun->irow_OUT[pd], OutDom->nrow_OUT[pd], ncol_TimeOUT[pd] + ); #elif defined(SWNETCDF) - iOUTIndex = - go->iOUToffset[eSW_CO2Effects][pd][0] + - iOUTnc(go->irow_OUT[pd], 0, k, 1, go->npft_OUT[eSW_CO2Effects][0]); + iOUTIndex = OutDom->iOUToffset[eSW_CO2Effects][pd][0] + + iOUTnc( + OutRun->irow_OUT[pd], + 0, + k, + 1, + OutDom->npft_OUT[eSW_CO2Effects][0] + ); #endif p[iOUTIndex] = @@ -205,13 +223,21 @@ void get_co2effects_mem(OutPeriod pd, SW_RUN *sw) { #if defined(RSOILWAT) iOUTIndex = iOUT( - k + NVEGTYPES, go->irow_OUT[pd], go->nrow_OUT[pd], ncol_TimeOUT[pd] + k + NVEGTYPES, + OutRun->irow_OUT[pd], + OutDom->nrow_OUT[pd], + ncol_TimeOUT[pd] ); #elif defined(SWNETCDF) - iOUTIndex = - go->iOUToffset[eSW_CO2Effects][pd][1] + - iOUTnc(go->irow_OUT[pd], 0, k, 1, go->npft_OUT[eSW_CO2Effects][1]); + iOUTIndex = OutDom->iOUToffset[eSW_CO2Effects][pd][1] + + iOUTnc( + OutRun->irow_OUT[pd], + 0, + k, + 1, + OutDom->npft_OUT[eSW_CO2Effects][1] + ); #endif p[iOUTIndex] = @@ -220,40 +246,46 @@ void get_co2effects_mem(OutPeriod pd, SW_RUN *sw) { } #elif defined(STEPWAT) -void get_co2effects_agg(OutPeriod pd, SW_RUN *sw) { +void get_co2effects_agg(OutPeriod pd, SW_RUN *sw, SW_OUT_DOM *OutDom) { int k; size_t iOUTIndex = 0; - SW_GEN_OUT *go = &sw->GenOutput; + SW_OUT_RUN *OutRun = &sw->OutRun; - RealD *p = go->p_OUT[eSW_CO2Effects][pd], - *psd = go->p_OUTsd[eSW_CO2Effects][pd]; + RealD *p = OutRun->p_OUT[eSW_CO2Effects][pd], + *psd = OutRun->p_OUTsd[eSW_CO2Effects][pd]; ForEachVegType(k) { - iOUTIndex = - iOUT(k, go->irow_OUT[pd], go->nrow_OUT[pd], ncol_TimeOUT[pd]); + iOUTIndex = iOUT( + k, OutRun->irow_OUT[pd], OutDom->nrow_OUT[pd], ncol_TimeOUT[pd] + ); do_running_agg( p, psd, iOUTIndex, - go->currIter, + OutRun->currIter, sw->VegProd.veg[k].co2_multipliers[BIO_INDEX][sw->Model.simyear] ); iOUTIndex = iOUT( - k + NVEGTYPES, go->irow_OUT[pd], go->nrow_OUT[pd], ncol_TimeOUT[pd] + k + NVEGTYPES, + OutRun->irow_OUT[pd], + OutDom->nrow_OUT[pd], + ncol_TimeOUT[pd] ); do_running_agg( p, psd, iOUTIndex, - go->currIter, + OutRun->currIter, sw->VegProd.veg[k].co2_multipliers[WUE_INDEX][sw->Model.simyear] ); } - if (go->print_IterationSummary) { - go->sw_outstr_agg[0] = '\0'; - format_IterationSummary(p, psd, pd, go->ncol_OUT[eSW_CO2Effects], sw); + if (OutRun->print_IterationSummary) { + OutRun->sw_outstr_agg[0] = '\0'; + format_IterationSummary( + p, psd, pd, OutRun->ncol_OUT[eSW_CO2Effects], sw + ); } } #endif @@ -264,10 +296,10 @@ void get_co2effects_agg(OutPeriod pd, SW_RUN *sw) { void get_biomass_text(OutPeriod pd, SW_RUN *sw) { int k; SW_VEGPROD_OUTPUTS *vo = sw->VegProd.p_oagg[pd]; - SW_GEN_OUT *go = &sw->GenOutput; + SW_OUT_RUN *OutRun = &sw->OutRun; char str[OUTSTRLEN]; - go->sw_outstr[0] = '\0'; + OutRun->sw_outstr[0] = '\0'; // fCover for NVEGTYPES plus bare-ground snprintf( @@ -278,7 +310,7 @@ void get_biomass_text(OutPeriod pd, SW_RUN *sw) { OUT_DIGITS, sw->VegProd.bare_cov.fCover ); - strcat(go->sw_outstr, str); + strcat(OutRun->sw_outstr, str); ForEachVegType(k) { snprintf( str, @@ -288,12 +320,12 @@ void get_biomass_text(OutPeriod pd, SW_RUN *sw) { OUT_DIGITS, sw->VegProd.veg[k].cov.fCover ); - strcat(go->sw_outstr, str); + strcat(OutRun->sw_outstr, str); } // biomass (g/m2 as component of total) for NVEGTYPES plus totals and litter snprintf(str, OUTSTRLEN, "%c%.*f", _OUTSEP, OUT_DIGITS, vo->biomass_total); - strcat(go->sw_outstr, str); + strcat(OutRun->sw_outstr, str); ForEachVegType(k) { snprintf( str, @@ -303,14 +335,14 @@ void get_biomass_text(OutPeriod pd, SW_RUN *sw) { OUT_DIGITS, vo->veg[k].biomass_inveg ); - strcat(go->sw_outstr, str); + strcat(OutRun->sw_outstr, str); } snprintf(str, OUTSTRLEN, "%c%.*f", _OUTSEP, OUT_DIGITS, vo->litter_total); - strcat(go->sw_outstr, str); + strcat(OutRun->sw_outstr, str); // biolive (g/m2 as component of total) for NVEGTYPES plus totals snprintf(str, OUTSTRLEN, "%c%.*f", _OUTSEP, OUT_DIGITS, vo->biolive_total); - strcat(go->sw_outstr, str); + strcat(OutRun->sw_outstr, str); ForEachVegType(k) { snprintf( str, @@ -320,38 +352,39 @@ void get_biomass_text(OutPeriod pd, SW_RUN *sw) { OUT_DIGITS, vo->veg[k].biolive_inveg ); - strcat(go->sw_outstr, str); + strcat(OutRun->sw_outstr, str); } // leaf area index [m2/m2] snprintf(str, OUTSTRLEN, "%c%.*f", _OUTSEP, OUT_DIGITS, vo->LAI); - strcat(go->sw_outstr, str); + strcat(OutRun->sw_outstr, str); } #endif #if defined(RSOILWAT) || defined(SWNETCDF) -void get_biomass_mem(OutPeriod pd, SW_RUN *sw) { +void get_biomass_mem(OutPeriod pd, SW_RUN *sw, SW_OUT_DOM *OutDom) { int k; SW_VEGPROD_OUTPUTS *vo = sw->VegProd.p_oagg[pd]; size_t iOUTIndex = 0; - SW_GEN_OUT *go = &sw->GenOutput; + SW_OUT_RUN *OutRun = &sw->OutRun; - RealD *p = go->p_OUT[eSW_Biomass][pd]; + RealD *p = OutRun->p_OUT[eSW_Biomass][pd]; #if defined(RSOILWAT) int i; get_outvalleader( - &sw->Model, pd, go->irow_OUT, go->nrow_OUT, go->tOffset, p + &sw->Model, pd, OutRun->irow_OUT, OutRun->nrow_OUT, OutRun->tOffset, p ); #endif // fCover of bare-ground #if defined(RSOILWAT) - iOUTIndex = iOUT(0, go->irow_OUT[pd], go->nrow_OUT[pd], ncol_TimeOUT[pd]); + iOUTIndex = + iOUT(0, OutRun->irow_OUT[pd], OutDom->nrow_OUT[pd], ncol_TimeOUT[pd]); #elif defined(SWNETCDF) - iOUTIndex = go->iOUToffset[eSW_Biomass][pd][0] + - iOUTnc(go->irow_OUT[pd], 0, 0, 1, 1); + iOUTIndex = OutDom->iOUToffset[eSW_Biomass][pd][0] + + iOUTnc(OutRun->irow_OUT[pd], 0, 0, 1, 1); #endif p[iOUTIndex] = sw->VegProd.bare_cov.fCover; @@ -364,13 +397,16 @@ void get_biomass_mem(OutPeriod pd, SW_RUN *sw) { ForEachVegType(k) { #if defined(RSOILWAT) - iOUTIndex = - iOUT(i + k, go->irow_OUT[pd], go->nrow_OUT[pd], ncol_TimeOUT[pd]); + iOUTIndex = iOUT( + i + k, OutRun->irow_OUT[pd], OutDom->nrow_OUT[pd], ncol_TimeOUT[pd] + ); #elif defined(SWNETCDF) iOUTIndex = - go->iOUToffset[eSW_Biomass][pd][1] + - iOUTnc(go->irow_OUT[pd], 0, k, 1, go->npft_OUT[eSW_Biomass][1]); + OutDom->iOUToffset[eSW_Biomass][pd][1] + + iOUTnc( + OutRun->irow_OUT[pd], 0, k, 1, OutDom->npft_OUT[eSW_Biomass][1] + ); #endif p[iOUTIndex] = sw->VegProd.veg[k].cov.fCover; @@ -379,12 +415,15 @@ void get_biomass_mem(OutPeriod pd, SW_RUN *sw) { // biomass (g/m2 as component of total) totals #if defined(RSOILWAT) iOUTIndex = iOUT( - i + NVEGTYPES, go->irow_OUT[pd], go->nrow_OUT[pd], ncol_TimeOUT[pd] + i + NVEGTYPES, + OutRun->irow_OUT[pd], + OutDom->nrow_OUT[pd], + ncol_TimeOUT[pd] ); #elif defined(SWNETCDF) - iOUTIndex = go->iOUToffset[eSW_Biomass][pd][2] + - iOUTnc(go->irow_OUT[pd], 0, 0, 1, 1); + iOUTIndex = OutDom->iOUToffset[eSW_Biomass][pd][2] + + iOUTnc(OutRun->irow_OUT[pd], 0, 0, 1, 1); #endif p[iOUTIndex] = vo->biomass_total; @@ -397,13 +436,16 @@ void get_biomass_mem(OutPeriod pd, SW_RUN *sw) { ForEachVegType(k) { #if defined(RSOILWAT) - iOUTIndex = - iOUT(i + k, go->irow_OUT[pd], go->nrow_OUT[pd], ncol_TimeOUT[pd]); + iOUTIndex = iOUT( + i + k, OutRun->irow_OUT[pd], OutDom->nrow_OUT[pd], ncol_TimeOUT[pd] + ); #elif defined(SWNETCDF) iOUTIndex = - go->iOUToffset[eSW_Biomass][pd][3] + - iOUTnc(go->irow_OUT[pd], 0, k, 1, go->npft_OUT[eSW_Biomass][3]); + OutDom->iOUToffset[eSW_Biomass][pd][3] + + iOUTnc( + OutRun->irow_OUT[pd], 0, k, 1, OutDom->npft_OUT[eSW_Biomass][3] + ); #endif p[iOUTIndex] = vo->veg[k].biomass_inveg; @@ -413,12 +455,15 @@ void get_biomass_mem(OutPeriod pd, SW_RUN *sw) { // biomass (g/m2 as component of total) of litter #if defined(RSOILWAT) iOUTIndex = iOUT( - i + NVEGTYPES, go->irow_OUT[pd], go->nrow_OUT[pd], ncol_TimeOUT[pd] + i + NVEGTYPES, + OutRun->irow_OUT[pd], + OutDom->nrow_OUT[pd], + ncol_TimeOUT[pd] ); #elif defined(SWNETCDF) - iOUTIndex = go->iOUToffset[eSW_Biomass][pd][4] + - iOUTnc(go->irow_OUT[pd], 0, 0, 1, 1); + iOUTIndex = OutDom->iOUToffset[eSW_Biomass][pd][4] + + iOUTnc(OutRun->irow_OUT[pd], 0, 0, 1, 1); #endif p[iOUTIndex] = vo->litter_total; @@ -427,12 +472,15 @@ void get_biomass_mem(OutPeriod pd, SW_RUN *sw) { // biolive (g/m2 as component of total) total #if defined(RSOILWAT) iOUTIndex = iOUT( - i + NVEGTYPES + 1, go->irow_OUT[pd], go->nrow_OUT[pd], ncol_TimeOUT[pd] + i + NVEGTYPES + 1, + OutRun->irow_OUT[pd], + OutDom->nrow_OUT[pd], + ncol_TimeOUT[pd] ); #elif defined(SWNETCDF) - iOUTIndex = go->iOUToffset[eSW_Biomass][pd][5] + - iOUTnc(go->irow_OUT[pd], 0, 0, 1, 1); + iOUTIndex = OutDom->iOUToffset[eSW_Biomass][pd][5] + + iOUTnc(OutRun->irow_OUT[pd], 0, 0, 1, 1); #endif p[iOUTIndex] = vo->biolive_total; @@ -445,13 +493,16 @@ void get_biomass_mem(OutPeriod pd, SW_RUN *sw) { ForEachVegType(k) { #if defined(RSOILWAT) - iOUTIndex = - iOUT(i + k, go->irow_OUT[pd], go->nrow_OUT[pd], ncol_TimeOUT[pd]); + iOUTIndex = iOUT( + i + k, OutRun->irow_OUT[pd], OutDom->nrow_OUT[pd], ncol_TimeOUT[pd] + ); #elif defined(SWNETCDF) iOUTIndex = - go->iOUToffset[eSW_Biomass][pd][6] + - iOUTnc(go->irow_OUT[pd], 0, k, 1, go->npft_OUT[eSW_Biomass][6]); + OutDom->iOUToffset[eSW_Biomass][pd][6] + + iOUTnc( + OutRun->irow_OUT[pd], 0, k, 1, OutDom->npft_OUT[eSW_Biomass][6] + ); #endif p[iOUTIndex] = vo->veg[k].biolive_inveg; @@ -461,84 +512,104 @@ void get_biomass_mem(OutPeriod pd, SW_RUN *sw) { // leaf area index [m2/m2] #if defined(RSOILWAT) iOUTIndex = iOUT( - i + NVEGTYPES, go->irow_OUT[pd], go->nrow_OUT[pd], ncol_TimeOUT[pd] + i + NVEGTYPES, + OutRun->irow_OUT[pd], + OutDom->nrow_OUT[pd], + ncol_TimeOUT[pd] ); #elif defined(SWNETCDF) - iOUTIndex = go->iOUToffset[eSW_Biomass][pd][7] + - iOUTnc(go->irow_OUT[pd], 0, 0, 1, 1); + iOUTIndex = OutDom->iOUToffset[eSW_Biomass][pd][7] + + iOUTnc(OutRun->irow_OUT[pd], 0, 0, 1, 1); #endif p[iOUTIndex] = vo->LAI; } #elif defined(STEPWAT) -void get_biomass_agg(OutPeriod pd, SW_RUN *sw) { +void get_biomass_agg(OutPeriod pd, SW_RUN *sw, SW_OUT_DOM *OutDom) { int k, i; SW_VEGPROD_OUTPUTS *vo = sw->VegProd.p_oagg[pd]; size_t iOUTIndex = 0; - SW_GEN_OUT *go = &sw->GenOutput; + SW_OUT_RUN *OutRun = &sw->OutRun; - RealD *p = go->p_OUT[eSW_Biomass][pd], *psd = go->p_OUTsd[eSW_Biomass][pd]; + RealD *p = OutRun->p_OUT[eSW_Biomass][pd], + *psd = OutRun->p_OUTsd[eSW_Biomass][pd]; // fCover for NVEGTYPES plus bare-ground - iOUTIndex = iOUT(0, go->irow_OUT[pd], go->nrow_OUT[pd], ncol_TimeOUT[pd]); + iOUTIndex = + iOUT(0, OutRun->irow_OUT[pd], OutDom->nrow_OUT[pd], ncol_TimeOUT[pd]); do_running_agg( - p, psd, iOUTIndex, go->currIter, sw->VegProd.bare_cov.fCover + p, psd, iOUTIndex, OutRun->currIter, sw->VegProd.bare_cov.fCover ); i = 1; ForEachVegType(k) { - iOUTIndex = - iOUT(i + k, go->irow_OUT[pd], go->nrow_OUT[pd], ncol_TimeOUT[pd]); + iOUTIndex = iOUT( + i + k, OutRun->irow_OUT[pd], OutDom->nrow_OUT[pd], ncol_TimeOUT[pd] + ); do_running_agg( - p, psd, iOUTIndex, go->currIter, sw->VegProd.veg[k].cov.fCover + p, psd, iOUTIndex, OutRun->currIter, sw->VegProd.veg[k].cov.fCover ); } // biomass (g/m2 as component of total) for NVEGTYPES plus totals and litter iOUTIndex = iOUT( - i + NVEGTYPES, go->irow_OUT[pd], go->nrow_OUT[pd], ncol_TimeOUT[pd] + i + NVEGTYPES, + OutRun->irow_OUT[pd], + OutDom->nrow_OUT[pd], + ncol_TimeOUT[pd] ); - do_running_agg(p, psd, iOUTIndex, go->currIter, vo->biomass_total); + do_running_agg(p, psd, iOUTIndex, OutRun->currIter, vo->biomass_total); i += NVEGTYPES + 1; ForEachVegType(k) { - iOUTIndex = - iOUT(i + k, go->irow_OUT[pd], go->nrow_OUT[pd], ncol_TimeOUT[pd]); + iOUTIndex = iOUT( + i + k, OutRun->irow_OUT[pd], OutDom->nrow_OUT[pd], ncol_TimeOUT[pd] + ); do_running_agg( - p, psd, iOUTIndex, go->currIter, vo->veg[k].biomass_inveg + p, psd, iOUTIndex, OutRun->currIter, vo->veg[k].biomass_inveg ); } iOUTIndex = iOUT( - i + NVEGTYPES, go->irow_OUT[pd], go->nrow_OUT[pd], ncol_TimeOUT[pd] + i + NVEGTYPES, + OutRun->irow_OUT[pd], + OutDom->nrow_OUT[pd], + ncol_TimeOUT[pd] ); - do_running_agg(p, psd, iOUTIndex, go->currIter, vo->litter_total); + do_running_agg(p, psd, iOUTIndex, OutRun->currIter, vo->litter_total); // biolive (g/m2 as component of total) for NVEGTYPES plus totals iOUTIndex = iOUT( - i + NVEGTYPES + 1, go->irow_OUT[pd], go->nrow_OUT[pd], ncol_TimeOUT[pd] + i + NVEGTYPES + 1, + OutRun->irow_OUT[pd], + OutDom->nrow_OUT[pd], + ncol_TimeOUT[pd] ); - do_running_agg(p, psd, iOUTIndex, go->currIter, vo->biolive_total); + do_running_agg(p, psd, iOUTIndex, OutRun->currIter, vo->biolive_total); i += NVEGTYPES + 2; ForEachVegType(k) { - iOUTIndex = - iOUT(i + k, go->irow_OUT[pd], go->nrow_OUT[pd], ncol_TimeOUT[pd]); + iOUTIndex = iOUT( + i + k, OutRun->irow_OUT[pd], OutDom->nrow_OUT[pd], ncol_TimeOUT[pd] + ); do_running_agg( - p, psd, iOUTIndex, go->currIter, vo->veg[k].biolive_inveg + p, psd, iOUTIndex, OutRun->currIter, vo->veg[k].biolive_inveg ); } // leaf area index [m2/m2] iOUTIndex = iOUT( - i + NVEGTYPES, go->irow_OUT[pd], go->nrow_OUT[pd], ncol_TimeOUT[pd] + i + NVEGTYPES, + OutRun->irow_OUT[pd], + OutDom->nrow_OUT[pd], + ncol_TimeOUT[pd] ); - do_running_agg(p, psd, iOUTIndex, go->currIter, vo->LAI); + do_running_agg(p, psd, iOUTIndex, OutRun->currIter, vo->LAI); - if (go->print_IterationSummary) { - go->sw_outstr_agg[0] = '\0'; - format_IterationSummary(p, psd, pd, go->ncol_OUT[eSW_Biomass], sw); + if (OutRun->print_IterationSummary) { + OutRun->sw_outstr_agg[0] = '\0'; + format_IterationSummary(p, psd, pd, OutRun->ncol_OUT[eSW_Biomass], sw); } } #endif @@ -555,19 +626,21 @@ a day of year >= 0 that the species established itself in the current year. The output will be a single row of numbers for each year. Each column represents a species in order it was entered in the stabs.in file. -The value will be the day that the species established, or - if it didn't +The value will be the day that the species established, OutRun - if it didn't establish this year. This check is for OUTTEXT. @param[in] pd Time period in simulation output (day/week/month/year) @param[in] sw Comprehensive struct of type SW_RUN containing all information in the simulation. +@param[in] OutDom Struct of type SW_OUT_DOM that holds output + information that do not change throughout simulation runs */ void get_estab_text(OutPeriod pd, SW_RUN *sw) { IntU i; - SW_GEN_OUT *go = &sw->GenOutput; + SW_OUT_RUN *OutRun = &sw->OutRun; char str[OUTSTRLEN]; - go->sw_outstr[0] = '\0'; + OutRun->sw_outstr[0] = '\0'; i = (IntU) pd; // silence `-Wunused-parameter` @@ -575,7 +648,7 @@ void get_estab_text(OutPeriod pd, SW_RUN *sw) { snprintf( str, OUTSTRLEN, "%c%d", _OUTSEP, sw->VegEstab.parms[i]->estab_doy ); - strcat(go->sw_outstr, str); + strcat(OutRun->sw_outstr, str); } } #endif @@ -587,34 +660,37 @@ a day of year >= 0 that the species established itself in the current year. The output will be a single row of numbers for each year. Each column represents a species in order it was entered in the stabs.in file. -The value will be the day that the species established, or - if it didn't +The value will be the day that the species established, OutRun - if it didn't establish this year. This check is for RSOILWAT. @param[in] pd Time period in simulation output (day/week/month/year) @param[in] sw Comprehensive struct of type SW_RUN containing all information in the simulation. +@param[in] OutDom Struct of type SW_OUT_DOM that holds output + information that do not change throughout simulation runs */ -void get_estab_mem(OutPeriod pd, SW_RUN *sw) { +void get_estab_mem(OutPeriod pd, SW_RUN *sw, SW_OUT_DOM *OutDom) { IntU i; size_t iOUTIndex = 0; - SW_GEN_OUT *go = &sw->GenOutput; + SW_OUT_RUN *OutRun = &sw->OutRun; - RealD *p = go->p_OUT[eSW_Estab][pd]; + RealD *p = OutRun->p_OUT[eSW_Estab][pd]; #if defined(RSOILWAT) get_outvalleader( - &sw->Model, pd, go->irow_OUT, go->nrow_OUT, go->tOffset, p + &sw->Model, pd, OutRun->irow_OUT, OutRun->nrow_OUT, OutRun->tOffset, p ); #endif for (i = 0; i < sw->VegEstab.count; i++) { #if defined(RSOILWAT) - iOUTIndex = - iOUT(i, go->irow_OUT[pd], go->nrow_OUT[pd], ncol_TimeOUT[pd]); + iOUTIndex = iOUT( + i, OutRun->irow_OUT[pd], OutDom->nrow_OUT[pd], ncol_TimeOUT[pd] + ); #elif defined(SWNETCDF) - iOUTIndex = go->iOUToffset[eSW_Estab][pd][i] + - iOUTnc(go->irow_OUT[pd], 0, 0, 1, 1); + iOUTIndex = OutDom->iOUToffset[eSW_Estab][pd][i] + + iOUTnc(OutRun->irow_OUT[pd], 0, 0, 1, 1); #endif p[iOUTIndex] = sw->VegEstab.parms[i]->estab_doy; @@ -628,31 +704,39 @@ a day of year >= 0 that the species established itself in the current year. The output will be a single row of numbers for each year. Each column represents a species in order it was entered in the stabs.in file. -The value will be the day that the species established, or - if it didn't +The value will be the day that the species established, OutRun - if it didn't establish this year. This check is for STEPWAT. @param[in] pd Time period in simulation output (day/week/month/year) @param[in] sw Comprehensive struct of type SW_RUN containing all information in the simulation. +@param[in] OutDom Struct of type SW_OUT_DOM that holds output + information that do not change throughout simulation runs */ -void get_estab_agg(OutPeriod pd, SW_RUN *sw) { +void get_estab_agg(OutPeriod pd, SW_RUN *sw, SW_OUT_DOM *OutDom) { IntU i; size_t iOUTIndex = 0; - SW_GEN_OUT *go = &sw->GenOutput; + SW_OUT_RUN *OutRun = &sw->OutRun; - RealD *p = go->p_OUT[eSW_Estab][pd], *psd = go->p_OUTsd[eSW_Estab][pd]; + RealD *p = OutRun->p_OUT[eSW_Estab][pd], + *psd = OutRun->p_OUTsd[eSW_Estab][pd]; for (i = 0; i < sw->VegEstab.count; i++) { - iOUTIndex = - iOUT(i, go->irow_OUT[pd], go->nrow_OUT[pd], ncol_TimeOUT[pd]); + iOUTIndex = iOUT( + i, OutRun->irow_OUT[pd], OutDom->nrow_OUT[pd], ncol_TimeOUT[pd] + ); do_running_agg( - p, psd, iOUTIndex, go->currIter, sw->VegEstab.parms[i]->estab_doy + p, + psd, + iOUTIndex, + OutRun->currIter, + sw->VegEstab.parms[i]->estab_doy ); } - if (go->print_IterationSummary) { - go->sw_outstr_agg[0] = '\0'; - format_IterationSummary(p, psd, pd, go->ncol_OUT[eSW_Estab], sw); + if (OutRun->print_IterationSummary) { + OutRun->sw_outstr_agg[0] = '\0'; + format_IterationSummary(p, psd, pd, OutRun->ncol_OUT[eSW_Estab], sw); } } #endif @@ -670,12 +754,12 @@ void get_estab_agg(OutPeriod pd, SW_RUN *sw) { */ void get_temp_text(OutPeriod pd, SW_RUN *sw) { SW_WEATHER_OUTPUTS *vo = sw->Weather.p_oagg[pd]; - SW_GEN_OUT *go = &sw->GenOutput; + SW_OUT_RUN *OutRun = &sw->OutRun; - go->sw_outstr[0] = '\0'; + OutRun->sw_outstr[0] = '\0'; snprintf( - go->sw_outstr, - sizeof go->sw_outstr, + OutRun->sw_outstr, + sizeof OutRun->sw_outstr, "%c%.*f%c%.*f%c%.*f%c%.*f%c%.*f%c%.*f", _OUTSEP, OUT_DIGITS, @@ -706,82 +790,90 @@ void get_temp_text(OutPeriod pd, SW_RUN *sw) { @param pd Period. @param[in] sw Comprehensive struct of type SW_RUN containing all information - in the simulation + in the simulation +@param[in] OutDom Struct of type SW_OUT_DOM that holds output + information that do not change throughout simulation runs */ -void get_temp_mem(OutPeriod pd, SW_RUN *sw) { +void get_temp_mem(OutPeriod pd, SW_RUN *sw, SW_OUT_DOM *OutDom) { SW_WEATHER_OUTPUTS *vo = sw->Weather.p_oagg[pd]; size_t iOUTIndex = 0; - SW_GEN_OUT *go = &sw->GenOutput; + SW_OUT_RUN *OutRun = &sw->OutRun; - RealD *p = go->p_OUT[eSW_Temp][pd]; + RealD *p = OutRun->p_OUT[eSW_Temp][pd]; #if defined(RSOILWAT) get_outvalleader( - &sw->Model, pd, go->irow_OUT, go->nrow_OUT, go->tOffset, p + &sw->Model, pd, OutRun->irow_OUT, OutRun->nrow_OUT, OutRun->tOffset, p ); #endif #if defined(RSOILWAT) - iOUTIndex = iOUT(0, go->irow_OUT[pd], go->nrow_OUT[pd], ncol_TimeOUT[pd]); + iOUTIndex = + iOUT(0, OutRun->irow_OUT[pd], OutDom->nrow_OUT[pd], ncol_TimeOUT[pd]); #elif defined(SWNETCDF) - iOUTIndex = - go->iOUToffset[eSW_Temp][pd][0] + iOUTnc(go->irow_OUT[pd], 0, 0, 1, 1); + iOUTIndex = OutDom->iOUToffset[eSW_Temp][pd][0] + + iOUTnc(OutRun->irow_OUT[pd], 0, 0, 1, 1); #endif p[iOUTIndex] = vo->temp_max; #if defined(RSOILWAT) - iOUTIndex = iOUT(1, go->irow_OUT[pd], go->nrow_OUT[pd], ncol_TimeOUT[pd]); + iOUTIndex = + iOUT(1, OutRun->irow_OUT[pd], OutDom->nrow_OUT[pd], ncol_TimeOUT[pd]); #elif defined(SWNETCDF) - iOUTIndex = - go->iOUToffset[eSW_Temp][pd][1] + iOUTnc(go->irow_OUT[pd], 0, 0, 1, 1); + iOUTIndex = OutDom->iOUToffset[eSW_Temp][pd][1] + + iOUTnc(OutRun->irow_OUT[pd], 0, 0, 1, 1); #endif p[iOUTIndex] = vo->temp_min; #if defined(RSOILWAT) - iOUTIndex = iOUT(2, go->irow_OUT[pd], go->nrow_OUT[pd], ncol_TimeOUT[pd]); + iOUTIndex = + iOUT(2, OutRun->irow_OUT[pd], OutDom->nrow_OUT[pd], ncol_TimeOUT[pd]); #elif defined(SWNETCDF) - iOUTIndex = - go->iOUToffset[eSW_Temp][pd][2] + iOUTnc(go->irow_OUT[pd], 0, 0, 1, 1); + iOUTIndex = OutDom->iOUToffset[eSW_Temp][pd][2] + + iOUTnc(OutRun->irow_OUT[pd], 0, 0, 1, 1); #endif p[iOUTIndex] = vo->temp_avg; #if defined(RSOILWAT) - iOUTIndex = iOUT(3, go->irow_OUT[pd], go->nrow_OUT[pd], ncol_TimeOUT[pd]); + iOUTIndex = + iOUT(3, OutRun->irow_OUT[pd], OutDom->nrow_OUT[pd], ncol_TimeOUT[pd]); #elif defined(SWNETCDF) - iOUTIndex = - go->iOUToffset[eSW_Temp][pd][3] + iOUTnc(go->irow_OUT[pd], 0, 0, 1, 1); + iOUTIndex = OutDom->iOUToffset[eSW_Temp][pd][3] + + iOUTnc(OutRun->irow_OUT[pd], 0, 0, 1, 1); #endif p[iOUTIndex] = vo->surfaceMax; #if defined(RSOILWAT) - iOUTIndex = iOUT(4, go->irow_OUT[pd], go->nrow_OUT[pd], ncol_TimeOUT[pd]); + iOUTIndex = + iOUT(4, OutRun->irow_OUT[pd], OutDom->nrow_OUT[pd], ncol_TimeOUT[pd]); #elif defined(SWNETCDF) - iOUTIndex = - go->iOUToffset[eSW_Temp][pd][4] + iOUTnc(go->irow_OUT[pd], 0, 0, 1, 1); + iOUTIndex = OutDom->iOUToffset[eSW_Temp][pd][4] + + iOUTnc(OutRun->irow_OUT[pd], 0, 0, 1, 1); #endif p[iOUTIndex] = vo->surfaceMin; #if defined(RSOILWAT) - iOUTIndex = iOUT(5, go->irow_OUT[pd], go->nrow_OUT[pd], ncol_TimeOUT[pd]); + iOUTIndex = + iOUT(5, OutRun->irow_OUT[pd], OutDom->nrow_OUT[pd], ncol_TimeOUT[pd]); #elif defined(SWNETCDF) - iOUTIndex = - go->iOUToffset[eSW_Temp][pd][5] + iOUTnc(go->irow_OUT[pd], 0, 0, 1, 1); + iOUTIndex = OutDom->iOUToffset[eSW_Temp][pd][5] + + iOUTnc(OutRun->irow_OUT[pd], 0, 0, 1, 1); #endif p[iOUTIndex] = vo->surfaceAvg; @@ -795,35 +887,44 @@ void get_temp_mem(OutPeriod pd, SW_RUN *sw) { @param[in] pd Time period in simulation output (day/week/month/year) @param[in] sw Comprehensive struct of type SW_RUN containing all information in the simulation. +@param[in] OutDom Struct of type SW_OUT_DOM that holds output + information that do not change throughout simulation runs */ -void get_temp_agg(OutPeriod pd, SW_RUN *sw) { +void get_temp_agg(OutPeriod pd, SW_RUN *sw, SW_OUT_DOM *OutDom) { SW_WEATHER_OUTPUTS *vo = sw->Weather.p_oagg[pd]; size_t iOUTIndex = 0; - SW_GEN_OUT *go = &sw->GenOutput; + SW_OUT_RUN *OutRun = &sw->OutRun; - RealD *p = go->p_OUT[eSW_Temp][pd], *psd = go->p_OUTsd[eSW_Temp][pd]; + RealD *p = OutRun->p_OUT[eSW_Temp][pd], + *psd = OutRun->p_OUTsd[eSW_Temp][pd]; - iOUTIndex = iOUT(0, go->irow_OUT[pd], go->nrow_OUT[pd], ncol_TimeOUT[pd]); - do_running_agg(p, psd, iOUTIndex, go->currIter, vo->temp_max); + iOUTIndex = + iOUT(0, OutRun->irow_OUT[pd], OutDom->nrow_OUT[pd], ncol_TimeOUT[pd]); + do_running_agg(p, psd, iOUTIndex, OutRun->currIter, vo->temp_max); - iOUTIndex = iOUT(1, go->irow_OUT[pd], go->nrow_OUT[pd], ncol_TimeOUT[pd]); - do_running_agg(p, psd, iOUTIndex, go->currIter, vo->temp_min); + iOUTIndex = + iOUT(1, OutRun->irow_OUT[pd], OutDom->nrow_OUT[pd], ncol_TimeOUT[pd]); + do_running_agg(p, psd, iOUTIndex, OutRun->currIter, vo->temp_min); - iOUTIndex = iOUT(2, go->irow_OUT[pd], go->nrow_OUT[pd], ncol_TimeOUT[pd]); - do_running_agg(p, psd, iOUTIndex, go->currIter, vo->temp_avg); + iOUTIndex = + iOUT(2, OutRun->irow_OUT[pd], OutDom->nrow_OUT[pd], ncol_TimeOUT[pd]); + do_running_agg(p, psd, iOUTIndex, OutRun->currIter, vo->temp_avg); - iOUTIndex = iOUT(3, go->irow_OUT[pd], go->nrow_OUT[pd], ncol_TimeOUT[pd]); - do_running_agg(p, psd, iOUTIndex, go->currIter, vo->surfaceMax); + iOUTIndex = + iOUT(3, OutRun->irow_OUT[pd], OutDom->nrow_OUT[pd], ncol_TimeOUT[pd]); + do_running_agg(p, psd, iOUTIndex, OutRun->currIter, vo->surfaceMax); - iOUTIndex = iOUT(4, go->irow_OUT[pd], go->nrow_OUT[pd], ncol_TimeOUT[pd]); - do_running_agg(p, psd, iOUTIndex, go->currIter, vo->surfaceMin); + iOUTIndex = + iOUT(4, OutRun->irow_OUT[pd], OutDom->nrow_OUT[pd], ncol_TimeOUT[pd]); + do_running_agg(p, psd, iOUTIndex, OutRun->currIter, vo->surfaceMin); - iOUTIndex = iOUT(5, go->irow_OUT[pd], go->nrow_OUT[pd], ncol_TimeOUT[pd]); - do_running_agg(p, psd, iOUTIndex, go->currIter, vo->surfaceAvg); + iOUTIndex = + iOUT(5, OutRun->irow_OUT[pd], OutDom->nrow_OUT[pd], ncol_TimeOUT[pd]); + do_running_agg(p, psd, iOUTIndex, OutRun->currIter, vo->surfaceAvg); - if (go->print_IterationSummary) { - go->sw_outstr_agg[0] = '\0'; - format_IterationSummary(p, psd, pd, go->ncol_OUT[eSW_Temp], sw); + if (OutRun->print_IterationSummary) { + OutRun->sw_outstr_agg[0] = '\0'; + format_IterationSummary(p, psd, pd, OutRun->ncol_OUT[eSW_Temp], sw); } } @@ -833,19 +934,20 @@ void get_temp_agg(OutPeriod pd, SW_RUN *sw) { @param[in] pd Time period in simulation output (day/week/month/year) @param[in] sw Comprehensive struct of type SW_RUN containing all information in the simulation. +@param[in] OutDom Struct of type SW_OUT_DOM that holds output + information that do not change throughout simulation runs */ -void get_temp_SXW(OutPeriod pd, SW_RUN *sw) { +void get_temp_SXW(OutPeriod pd, SW_RUN *sw, SW_OUT_DOM *OutDom) { TimeInt tOffset; if (pd == eSW_Month || pd == eSW_Year) { SW_WEATHER_OUTPUTS *vo = sw->Weather.p_oagg[pd]; - SW_GEN_OUT *go = &sw->GenOutput; - tOffset = go->tOffset; + tOffset = OutRun->tOffset; if (pd == eSW_Month) { - go->temp_monthly[sw->Model.month - tOffset] = vo->temp_avg; + OutRun->temp_monthly[sw->Model.month - tOffset] = vo->temp_avg; } else if (pd == eSW_Year) { - go->temp = vo->temp_avg; + OutRun->temp = vo->temp_avg; } } } @@ -862,15 +964,17 @@ OUTTEXT. @param[in] pd Time period in simulation output (day/week/month/year) @param[in] sw Comprehensive struct of type SW_RUN containing all information in the simulation. +@param[in] OutDom Struct of type SW_OUT_DOM that holds output + information that do not change throughout simulation runs */ void get_precip_text(OutPeriod pd, SW_RUN *sw) { SW_WEATHER_OUTPUTS *vo = sw->Weather.p_oagg[pd]; - SW_GEN_OUT *go = &sw->GenOutput; + SW_OUT_RUN *OutRun = &sw->OutRun; - go->sw_outstr[0] = '\0'; + OutRun->sw_outstr[0] = '\0'; snprintf( - go->sw_outstr, - sizeof go->sw_outstr, + OutRun->sw_outstr, + sizeof OutRun->sw_outstr, "%c%.*f%c%.*f%c%.*f%c%.*f%c%.*f", _OUTSEP, OUT_DIGITS, @@ -900,70 +1004,77 @@ RSOILWAT. @param[in] pd Time period in simulation output (day/week/month/year) @param[in] sw Comprehensive struct of type SW_RUN containing all information in the simulation. +@param[in] OutDom Struct of type SW_OUT_DOM that holds output + information that do not change throughout simulation runs */ -void get_precip_mem(OutPeriod pd, SW_RUN *sw) { +void get_precip_mem(OutPeriod pd, SW_RUN *sw, SW_OUT_DOM *OutDom) { SW_WEATHER_OUTPUTS *vo = sw->Weather.p_oagg[pd]; size_t iOUTIndex = 0; - SW_GEN_OUT *go = &sw->GenOutput; + SW_OUT_RUN *OutRun = &sw->OutRun; - RealD *p = go->p_OUT[eSW_Precip][pd]; + RealD *p = OutRun->p_OUT[eSW_Precip][pd]; #if defined(RSOILWAT) get_outvalleader( - &sw->Model, pd, go->irow_OUT, go->nrow_OUT, go->tOffset, p + &sw->Model, pd, OutRun->irow_OUT, OutRun->nrow_OUT, OutRun->tOffset, p ); #endif #if defined(RSOILWAT) - iOUTIndex = iOUT(0, go->irow_OUT[pd], go->nrow_OUT[pd], ncol_TimeOUT[pd]); + iOUTIndex = + iOUT(0, OutRun->irow_OUT[pd], OutDom->nrow_OUT[pd], ncol_TimeOUT[pd]); #elif defined(SWNETCDF) - iOUTIndex = go->iOUToffset[eSW_Precip][pd][0] + - iOUTnc(go->irow_OUT[pd], 0, 0, 1, 1); + iOUTIndex = OutDom->iOUToffset[eSW_Precip][pd][0] + + iOUTnc(OutRun->irow_OUT[pd], 0, 0, 1, 1); #endif p[iOUTIndex] = vo->ppt; #if defined(RSOILWAT) - iOUTIndex = iOUT(1, go->irow_OUT[pd], go->nrow_OUT[pd], ncol_TimeOUT[pd]); + iOUTIndex = + iOUT(1, OutRun->irow_OUT[pd], OutDom->nrow_OUT[pd], ncol_TimeOUT[pd]); #elif defined(SWNETCDF) - iOUTIndex = go->iOUToffset[eSW_Precip][pd][1] + - iOUTnc(go->irow_OUT[pd], 0, 0, 1, 1); + iOUTIndex = OutDom->iOUToffset[eSW_Precip][pd][1] + + iOUTnc(OutRun->irow_OUT[pd], 0, 0, 1, 1); #endif p[iOUTIndex] = vo->rain; #if defined(RSOILWAT) - iOUTIndex = iOUT(2, go->irow_OUT[pd], go->nrow_OUT[pd], ncol_TimeOUT[pd]); + iOUTIndex = + iOUT(2, OutRun->irow_OUT[pd], OutDom->nrow_OUT[pd], ncol_TimeOUT[pd]); #elif defined(SWNETCDF) - iOUTIndex = go->iOUToffset[eSW_Precip][pd][2] + - iOUTnc(go->irow_OUT[pd], 0, 0, 1, 1); + iOUTIndex = OutDom->iOUToffset[eSW_Precip][pd][2] + + iOUTnc(OutRun->irow_OUT[pd], 0, 0, 1, 1); #endif p[iOUTIndex] = vo->snow; #if defined(RSOILWAT) - iOUTIndex = iOUT(3, go->irow_OUT[pd], go->nrow_OUT[pd], ncol_TimeOUT[pd]); + iOUTIndex = + iOUT(3, OutRun->irow_OUT[pd], OutDom->nrow_OUT[pd], ncol_TimeOUT[pd]); #elif defined(SWNETCDF) - iOUTIndex = go->iOUToffset[eSW_Precip][pd][3] + - iOUTnc(go->irow_OUT[pd], 0, 0, 1, 1); + iOUTIndex = OutDom->iOUToffset[eSW_Precip][pd][3] + + iOUTnc(OutRun->irow_OUT[pd], 0, 0, 1, 1); #endif p[iOUTIndex] = vo->snowmelt; #if defined(RSOILWAT) - iOUTIndex = iOUT(4, go->irow_OUT[pd], go->nrow_OUT[pd], ncol_TimeOUT[pd]); + iOUTIndex = + iOUT(4, OutRun->irow_OUT[pd], OutDom->nrow_OUT[pd], ncol_TimeOUT[pd]); #elif defined(SWNETCDF) - iOUTIndex = go->iOUToffset[eSW_Precip][pd][4] + - iOUTnc(go->irow_OUT[pd], 0, 0, 1, 1); + iOUTIndex = OutDom->iOUToffset[eSW_Precip][pd][4] + + iOUTnc(OutRun->irow_OUT[pd], 0, 0, 1, 1); #endif p[iOUTIndex] = vo->snowloss; @@ -978,32 +1089,40 @@ STEPWAT. @param[in] pd Time period in simulation output (day/week/month/year) @param[in] sw Comprehensive struct of type SW_RUN containing all information in the simulation. +@param[in] OutDom Struct of type SW_OUT_DOM that holds output + information that do not change throughout simulation runs */ -void get_precip_agg(OutPeriod pd, SW_RUN *sw) { +void get_precip_agg(OutPeriod pd, SW_RUN *sw, SW_OUT_DOM *OutDom) { SW_WEATHER_OUTPUTS *vo = sw->Weather.p_oagg[pd]; size_t iOUTIndex = 0; - SW_GEN_OUT *go = &sw->GenOutput; + SW_OUT_RUN *OutRun = &sw->OutRun; - RealD *p = go->p_OUT[eSW_Precip][pd], *psd = go->p_OUTsd[eSW_Precip][pd]; + RealD *p = OutRun->p_OUT[eSW_Precip][pd], + *psd = OutRun->p_OUTsd[eSW_Precip][pd]; - iOUTIndex = iOUT(0, go->irow_OUT[pd], go->nrow_OUT[pd], ncol_TimeOUT[pd]); - do_running_agg(p, psd, iOUTIndex, go->currIter, vo->ppt); + iOUTIndex = + iOUT(0, OutRun->irow_OUT[pd], OutDom->nrow_OUT[pd], ncol_TimeOUT[pd]); + do_running_agg(p, psd, iOUTIndex, OutRun->currIter, vo->ppt); - iOUTIndex = iOUT(1, go->irow_OUT[pd], go->nrow_OUT[pd], ncol_TimeOUT[pd]); - do_running_agg(p, psd, iOUTIndex, go->currIter, vo->rain); + iOUTIndex = + iOUT(1, OutRun->irow_OUT[pd], OutDom->nrow_OUT[pd], ncol_TimeOUT[pd]); + do_running_agg(p, psd, iOUTIndex, OutRun->currIter, vo->rain); - iOUTIndex = iOUT(2, go->irow_OUT[pd], go->nrow_OUT[pd], ncol_TimeOUT[pd]); - do_running_agg(p, psd, iOUTIndex, go->currIter, vo->snow); + iOUTIndex = + iOUT(2, OutRun->irow_OUT[pd], OutDom->nrow_OUT[pd], ncol_TimeOUT[pd]); + do_running_agg(p, psd, iOUTIndex, OutRun->currIter, vo->snow); - iOUTIndex = iOUT(3, go->irow_OUT[pd], go->nrow_OUT[pd], ncol_TimeOUT[pd]); - do_running_agg(p, psd, iOUTIndex, go->currIter, vo->snowmelt); + iOUTIndex = + iOUT(3, OutRun->irow_OUT[pd], OutDom->nrow_OUT[pd], ncol_TimeOUT[pd]); + do_running_agg(p, psd, iOUTIndex, OutRun->currIter, vo->snowmelt); - iOUTIndex = iOUT(4, go->irow_OUT[pd], go->nrow_OUT[pd], ncol_TimeOUT[pd]); - do_running_agg(p, psd, iOUTIndex, go->currIter, vo->snowloss); + iOUTIndex = + iOUT(4, OutRun->irow_OUT[pd], OutDom->nrow_OUT[pd], ncol_TimeOUT[pd]); + do_running_agg(p, psd, iOUTIndex, OutRun->currIter, vo->snowloss); - if (go->print_IterationSummary) { - go->sw_outstr_agg[0] = '\0'; - format_IterationSummary(p, psd, pd, go->ncol_OUT[eSW_Precip], sw); + if (OutRun->print_IterationSummary) { + OutRun->sw_outstr_agg[0] = '\0'; + format_IterationSummary(p, psd, pd, OutRun->ncol_OUT[eSW_Precip], sw); } } @@ -1013,19 +1132,20 @@ void get_precip_agg(OutPeriod pd, SW_RUN *sw) { @param[in] pd Time period in simulation output (day/week/month/year) @param[in] sw Comprehensive struct of type SW_RUN containing all information in the simulation. +@param[in] OutDom Struct of type SW_OUT_DOM that holds output + information that do not change throughout simulation runs */ -void get_precip_SXW(OutPeriod pd, SW_RUN *sw) { +void get_precip_SXW(OutPeriod pd, SW_RUN *sw, SW_OUT_DOM *OutDom) { TimeInt tOffset; if (pd == eSW_Month || pd == eSW_Year) { SW_WEATHER_OUTPUTS *vo = sw->Weather.p_oagg[pd]; - SW_GEN_OUT *go = &sw->GenOutput; - tOffset = go->tOffset; + tOffset = OutRun->tOffset; if (pd == eSW_Month) { - go->ppt_monthly[sw->Model.month - tOffset] = vo->ppt; + OutRun->ppt_monthly[sw->Model.month - tOffset] = vo->ppt; } else if (pd == eSW_Year) { - go->ppt = vo->ppt; + OutRun->ppt = vo->ppt; } } } @@ -1040,14 +1160,16 @@ void get_precip_SXW(OutPeriod pd, SW_RUN *sw) { @param[in] pd Time period in simulation output (day/week/month/year) @param[in] sw Comprehensive struct of type SW_RUN containing all information in the simulation. +@param[in] OutDom Struct of type SW_OUT_DOM that holds output + information that do not change throughout simulation runs */ void get_vwcBulk_text(OutPeriod pd, SW_RUN *sw) { LyrIndex i; SW_SOILWAT_OUTPUTS *vo = sw->SoilWat.p_oagg[pd]; - SW_GEN_OUT *go = &sw->GenOutput; + SW_OUT_RUN *OutRun = &sw->OutRun; char str[OUTSTRLEN]; - go->sw_outstr[0] = '\0'; + OutRun->sw_outstr[0] = '\0'; ForEachSoilLayer(i, sw->Site.n_layers) { /* vwcBulk at this point is identical to swcBulk */ @@ -1059,7 +1181,7 @@ void get_vwcBulk_text(OutPeriod pd, SW_RUN *sw) { OUT_DIGITS, vo->vwcBulk[i] / sw->Site.width[i] ); - strcat(go->sw_outstr, str); + strcat(OutRun->sw_outstr, str); } } #endif @@ -1072,30 +1194,35 @@ void get_vwcBulk_text(OutPeriod pd, SW_RUN *sw) { @param[in] pd Time period in simulation output (day/week/month/year) @param[in] sw Comprehensive struct of type SW_RUN containing all information in the simulation. +@param[in] OutDom Struct of type SW_OUT_DOM that holds output + information that do not change throughout simulation runs */ -void get_vwcBulk_mem(OutPeriod pd, SW_RUN *sw) { +void get_vwcBulk_mem(OutPeriod pd, SW_RUN *sw, SW_OUT_DOM *OutDom) { LyrIndex i; SW_SOILWAT_OUTPUTS *vo = sw->SoilWat.p_oagg[pd]; size_t iOUTIndex = 0; - SW_GEN_OUT *go = &sw->GenOutput; + SW_OUT_RUN *OutRun = &sw->OutRun; - RealD *p = go->p_OUT[eSW_VWCBulk][pd]; + RealD *p = OutRun->p_OUT[eSW_VWCBulk][pd]; #if defined(RSOILWAT) get_outvalleader( - &sw->Model, pd, go->irow_OUT, go->nrow_OUT, go->tOffset, p + &sw->Model, pd, OutRun->irow_OUT, OutRun->nrow_OUT, OutRun->tOffset, p ); #endif ForEachSoilLayer(i, sw->Site.n_layers) { #if defined(RSOILWAT) - iOUTIndex = - iOUT(i, go->irow_OUT[pd], go->nrow_OUT[pd], ncol_TimeOUT[pd]); + iOUTIndex = iOUT( + i, OutRun->irow_OUT[pd], OutDom->nrow_OUT[pd], ncol_TimeOUT[pd] + ); #elif defined(SWNETCDF) iOUTIndex = - go->iOUToffset[eSW_VWCBulk][pd][0] + - iOUTnc(go->irow_OUT[pd], i, 0, go->nsl_OUT[eSW_VWCBulk][0], 1); + OutDom->iOUToffset[eSW_VWCBulk][pd][0] + + iOUTnc( + OutRun->irow_OUT[pd], i, 0, OutDom->nsl_OUT[eSW_VWCBulk][0], 1 + ); #endif /* vwcBulk at this point is identical to swcBulk */ @@ -1104,10 +1231,12 @@ void get_vwcBulk_mem(OutPeriod pd, SW_RUN *sw) { #if defined(SWNETCDF) /* Set extra soil layers to missing/fill value (up to domain-wide max) */ - for (i = sw->Site.n_layers; i < go->nsl_OUT[eSW_VWCBulk][0]; i++) { + for (i = sw->Site.n_layers; i < OutDom->nsl_OUT[eSW_VWCBulk][0]; i++) { iOUTIndex = - go->iOUToffset[eSW_VWCBulk][pd][0] + - iOUTnc(go->irow_OUT[pd], i, 0, go->nsl_OUT[eSW_VWCBulk][0], 1); + OutDom->iOUToffset[eSW_VWCBulk][pd][0] + + iOUTnc( + OutRun->irow_OUT[pd], i, 0, OutDom->nsl_OUT[eSW_VWCBulk][0], 1 + ); p[iOUTIndex] = NC_FILL_DOUBLE; } #endif // SWNETCDF @@ -1121,27 +1250,35 @@ void get_vwcBulk_mem(OutPeriod pd, SW_RUN *sw) { @param[in] pd Time period in simulation output (day/week/month/year) @param[in] sw Comprehensive struct of type SW_RUN containing all information in the simulation. +@param[in] OutDom Struct of type SW_OUT_DOM that holds output + information that do not change throughout simulation runs */ -void get_vwcBulk_agg(OutPeriod pd, SW_RUN *sw) { +void get_vwcBulk_agg(OutPeriod pd, SW_RUN *sw, SW_OUT_DOM *OutDom) { LyrIndex i; SW_SOILWAT_OUTPUTS *vo = sw->SoilWat.p_oagg[pd]; size_t iOUTIndex = 0; - SW_GEN_OUT *go = &sw->GenOutput; + SW_OUT_RUN *OutRun = &sw->OutRun; - RealD *p = go->p_OUT[eSW_VWCBulk][pd], *psd = go->p_OUTsd[eSW_VWCBulk][pd]; + RealD *p = OutRun->p_OUT[eSW_VWCBulk][pd], + *psd = OutRun->p_OUTsd[eSW_VWCBulk][pd]; ForEachSoilLayer(i, sw->Site.n_layers) { /* vwcBulk at this point is identical to swcBulk */ - iOUTIndex = - iOUT(i, go->irow_OUT[pd], go->nrow_OUT[pd], ncol_TimeOUT[pd]); + iOUTIndex = iOUT( + i, OutRun->irow_OUT[pd], OutDom->nrow_OUT[pd], ncol_TimeOUT[pd] + ); do_running_agg( - p, psd, iOUTIndex, go->currIter, vo->vwcBulk[i] / sw->Site.width[i] + p, + psd, + iOUTIndex, + OutRun->currIter, + vo->vwcBulk[i] / sw->Site.width[i] ); } - if (go->print_IterationSummary) { - go->sw_outstr_agg[0] = '\0'; - format_IterationSummary(p, psd, pd, go->ncol_OUT[eSW_VWCBulk], sw); + if (OutRun->print_IterationSummary) { + OutRun->sw_outstr_agg[0] = '\0'; + format_IterationSummary(p, psd, pd, OutRun->ncol_OUT[eSW_VWCBulk], sw); } } #endif @@ -1156,15 +1293,17 @@ void get_vwcBulk_agg(OutPeriod pd, SW_RUN *sw) { @param[in] pd Time period in simulation output (day/week/month/year) @param[in] sw Comprehensive struct of type SW_RUN containing all information in the simulation. +@param[in] OutDom Struct of type SW_OUT_DOM that holds output + information that do not change throughout simulation runs */ void get_vwcMatric_text(OutPeriod pd, SW_RUN *sw) { LyrIndex i; RealD convert; SW_SOILWAT_OUTPUTS *vo = sw->SoilWat.p_oagg[pd]; - SW_GEN_OUT *go = &sw->GenOutput; + SW_OUT_RUN *OutRun = &sw->OutRun; char str[OUTSTRLEN]; - go->sw_outstr[0] = '\0'; + OutRun->sw_outstr[0] = '\0'; ForEachSoilLayer(i, sw->Site.n_layers) { /* vwcMatric at this point is identical to swcBulk */ @@ -1179,7 +1318,7 @@ void get_vwcMatric_text(OutPeriod pd, SW_RUN *sw) { OUT_DIGITS, vo->vwcMatric[i] * convert ); - strcat(go->sw_outstr, str); + strcat(OutRun->sw_outstr, str); } } #endif @@ -1192,31 +1331,36 @@ void get_vwcMatric_text(OutPeriod pd, SW_RUN *sw) { @param[in] pd Time period in simulation output (day/week/month/year) @param[in] sw Comprehensive struct of type SW_RUN containing all information in the simulation. +@param[in] OutDom Struct of type SW_OUT_DOM that holds output + information that do not change throughout simulation runs */ -void get_vwcMatric_mem(OutPeriod pd, SW_RUN *sw) { +void get_vwcMatric_mem(OutPeriod pd, SW_RUN *sw, SW_OUT_DOM *OutDom) { LyrIndex i; RealD convert; SW_SOILWAT_OUTPUTS *vo = sw->SoilWat.p_oagg[pd]; size_t iOUTIndex = 0; - SW_GEN_OUT *go = &sw->GenOutput; + SW_OUT_RUN *OutRun = &sw->OutRun; - RealD *p = go->p_OUT[eSW_VWCMatric][pd]; + RealD *p = OutRun->p_OUT[eSW_VWCMatric][pd]; #if defined(RSOILWAT) get_outvalleader( - &sw->Model, pd, go->irow_OUT, go->nrow_OUT, go->tOffset, p + &sw->Model, pd, OutRun->irow_OUT, OutRun->nrow_OUT, OutRun->tOffset, p ); #endif ForEachSoilLayer(i, sw->Site.n_layers) { #if defined(RSOILWAT) - iOUTIndex = - iOUT(i, go->irow_OUT[pd], go->nrow_OUT[pd], ncol_TimeOUT[pd]); + iOUTIndex = iOUT( + i, OutRun->irow_OUT[pd], OutDom->nrow_OUT[pd], ncol_TimeOUT[pd] + ); #elif defined(SWNETCDF) iOUTIndex = - go->iOUToffset[eSW_VWCMatric][pd][0] + - iOUTnc(go->irow_OUT[pd], i, 0, go->nsl_OUT[eSW_VWCMatric][0], 1); + OutDom->iOUToffset[eSW_VWCMatric][pd][0] + + iOUTnc( + OutRun->irow_OUT[pd], i, 0, OutDom->nsl_OUT[eSW_VWCMatric][0], 1 + ); #endif /* vwcMatric at this point is identical to swcBulk */ @@ -1227,10 +1371,12 @@ void get_vwcMatric_mem(OutPeriod pd, SW_RUN *sw) { #if defined(SWNETCDF) /* Set extra soil layers to missing/fill value (up to domain-wide max) */ - for (i = sw->Site.n_layers; i < go->nsl_OUT[eSW_VWCMatric][0]; i++) { + for (i = sw->Site.n_layers; i < OutDom->nsl_OUT[eSW_VWCMatric][0]; i++) { iOUTIndex = - go->iOUToffset[eSW_VWCMatric][pd][0] + - iOUTnc(go->irow_OUT[pd], i, 0, go->nsl_OUT[eSW_VWCMatric][0], 1); + OutDom->iOUToffset[eSW_VWCMatric][pd][0] + + iOUTnc( + OutRun->irow_OUT[pd], i, 0, OutDom->nsl_OUT[eSW_VWCMatric][0], 1 + ); p[iOUTIndex] = NC_FILL_DOUBLE; } #endif // SWNETCDF @@ -1244,32 +1390,37 @@ void get_vwcMatric_mem(OutPeriod pd, SW_RUN *sw) { @param[in] pd Time period in simulation output (day/week/month/year) @param[in] sw Comprehensive struct of type SW_RUN containing all information in the simulation. +@param[in] OutDom Struct of type SW_OUT_DOM that holds output + information that do not change throughout simulation runs */ -void get_vwcMatric_agg(OutPeriod pd, SW_RUN *sw) { +void get_vwcMatric_agg(OutPeriod pd, SW_RUN *sw, SW_OUT_DOM *OutDom) { LyrIndex i; RealD convert; SW_SOILWAT_OUTPUTS *vo = sw->SoilWat.p_oagg[pd]; size_t iOUTIndex = 0; - SW_GEN_OUT *go = &sw->GenOutput; + SW_OUT_RUN *OutRun = &sw->OutRun; - RealD *p = go->p_OUT[eSW_VWCMatric][pd], - *psd = go->p_OUTsd[eSW_VWCMatric][pd]; + RealD *p = OutRun->p_OUT[eSW_VWCMatric][pd], + *psd = OutRun->p_OUTsd[eSW_VWCMatric][pd]; ForEachSoilLayer(i, sw->Site.n_layers) { /* vwcMatric at this point is identical to swcBulk */ convert = 1. / (1. - sw->Site.fractionVolBulk_gravel[i]) / sw->Site.width[i]; - iOUTIndex = - iOUT(i, go->irow_OUT[pd], go->nrow_OUT[pd], ncol_TimeOUT[pd]); + iOUTIndex = iOUT( + i, OutRun->irow_OUT[pd], OutDom->nrow_OUT[pd], ncol_TimeOUT[pd] + ); do_running_agg( - p, psd, iOUTIndex, go->currIter, vo->vwcMatric[i] * convert + p, psd, iOUTIndex, OutRun->currIter, vo->vwcMatric[i] * convert ); } - if (go->print_IterationSummary) { - go->sw_outstr_agg[0] = '\0'; - format_IterationSummary(p, psd, pd, go->ncol_OUT[eSW_VWCMatric], sw); + if (OutRun->print_IterationSummary) { + OutRun->sw_outstr_agg[0] = '\0'; + format_IterationSummary( + p, psd, pd, OutRun->ncol_OUT[eSW_VWCMatric], sw + ); } } #endif @@ -1284,16 +1435,18 @@ void get_vwcMatric_agg(OutPeriod pd, SW_RUN *sw) { @param[in] pd Time period in simulation output (day/week/month/year) @param[in] sw Comprehensive struct of type SW_RUN containing all information in the simulation. +@param[in] OutDom Struct of type SW_OUT_DOM that holds output + information that do not change throughout simulation runs */ void get_swa_text(OutPeriod pd, SW_RUN *sw) { /* added 21-Oct-03, cwb */ LyrIndex i; int k; SW_SOILWAT_OUTPUTS *vo = sw->SoilWat.p_oagg[pd]; - SW_GEN_OUT *go = &sw->GenOutput; + SW_OUT_RUN *OutRun = &sw->OutRun; char str[OUTSTRLEN]; - go->sw_outstr[0] = '\0'; + OutRun->sw_outstr[0] = '\0'; ForEachVegType(k) { ForEachSoilLayer(i, sw->Site.n_layers) { @@ -1305,7 +1458,7 @@ void get_swa_text(OutPeriod pd, SW_RUN *sw) { OUT_DIGITS, vo->SWA_VegType[k][i] ); - strcat(go->sw_outstr, str); + strcat(OutRun->sw_outstr, str); } } } @@ -1319,37 +1472,40 @@ void get_swa_text(OutPeriod pd, SW_RUN *sw) { @param[in] pd Time period in simulation output (day/week/month/year) @param[in] sw Comprehensive struct of type SW_RUN containing all information in the simulation. +@param[in] OutDom Struct of type SW_OUT_DOM that holds output + information that do not change throughout simulation runs */ -void get_swa_mem(OutPeriod pd, SW_RUN *sw) { +void get_swa_mem(OutPeriod pd, SW_RUN *sw, SW_OUT_DOM *OutDom) { LyrIndex i; int k; SW_SOILWAT_OUTPUTS *vo = sw->SoilWat.p_oagg[pd]; size_t iOUTIndex = 0; - SW_GEN_OUT *go = &sw->GenOutput; + SW_OUT_RUN *OutRun = &sw->OutRun; - RealD *p = go->p_OUT[eSW_SWA][pd]; + RealD *p = OutRun->p_OUT[eSW_SWA][pd]; #if defined(RSOILWAT) get_outvalleader( - &sw->Model, pd, go->irow_OUT, go->nrow_OUT, go->tOffset, p + &sw->Model, pd, OutRun->irow_OUT, OutRun->nrow_OUT, OutRun->tOffset, p ); #endif ForEachVegType(k) { ForEachSoilLayer(i, sw->Site.n_layers) { #if defined(RSOILWAT) - iOUTIndex = - iOUT2(i, k, pd, go->irow_OUT, go->nrow_OUT, sw->Site.n_layers); + iOUTIndex = iOUT2( + i, k, pd, OutRun->irow_OUT, OutRun->nrow_OUT, sw->Site.n_layers + ); #elif defined(SWNETCDF) - iOUTIndex = - go->iOUToffset[eSW_SWA][pd][0] + iOUTnc( - go->irow_OUT[pd], - i, - k, - go->nsl_OUT[eSW_SWA][0], - go->npft_OUT[eSW_SWA][0] - ); + iOUTIndex = OutDom->iOUToffset[eSW_SWA][pd][0] + + iOUTnc( + OutRun->irow_OUT[pd], + i, + k, + OutDom->nsl_OUT[eSW_SWA][0], + OutDom->npft_OUT[eSW_SWA][0] + ); #endif p[iOUTIndex] = vo->SWA_VegType[k][i]; @@ -1358,15 +1514,15 @@ void get_swa_mem(OutPeriod pd, SW_RUN *sw) { #if defined(SWNETCDF) /* Set extra soil layers to missing/fill value (up to domain-wide max) */ - for (i = sw->Site.n_layers; i < go->nsl_OUT[eSW_SWA][0]; i++) { - iOUTIndex = - go->iOUToffset[eSW_SWA][pd][0] + iOUTnc( - go->irow_OUT[pd], - i, - k, - go->nsl_OUT[eSW_SWA][0], - go->npft_OUT[eSW_SWA][0] - ); + for (i = sw->Site.n_layers; i < OutDom->nsl_OUT[eSW_SWA][0]; i++) { + iOUTIndex = OutDom->iOUToffset[eSW_SWA][pd][0] + + iOUTnc( + OutRun->irow_OUT[pd], + i, + k, + OutDom->nsl_OUT[eSW_SWA][0], + OutDom->npft_OUT[eSW_SWA][0] + ); p[iOUTIndex] = NC_FILL_DOUBLE; } #endif // SWNETCDF @@ -1381,28 +1537,31 @@ void get_swa_mem(OutPeriod pd, SW_RUN *sw) { @param[in] pd Time period in simulation output (day/week/month/year) @param[in] sw Comprehensive struct of type SW_RUN containing all information in the simulation. +@param[in] OutDom Struct of type SW_OUT_DOM that holds output + information that do not change throughout simulation runs */ -void get_swa_agg(OutPeriod pd, SW_RUN *sw) { +void get_swa_agg(OutPeriod pd, SW_RUN *sw, SW_OUT_DOM *OutDom) { LyrIndex i; int k; SW_SOILWAT_OUTPUTS *vo = sw->SoilWat.p_oagg[pd]; size_t iOUTIndex = 0; - SW_GEN_OUT *go = &sw->GenOutput; + SW_OUT_RUN *OutRun = &sw->OutRun; - RealD *p = go->p_OUT[eSW_SWA][pd], *psd = go->p_OUTsd[eSW_SWA][pd]; + RealD *p = OutRun->p_OUT[eSW_SWA][pd], *psd = OutRun->p_OUTsd[eSW_SWA][pd]; ForEachVegType(k) { ForEachSoilLayer(i, sw->Site.n_layers) { - iOUTIndex = - iOUT2(i, k, pd, go->irow_OUT, go->nrow_OUT, sw->Site.n_layers); + iOUTIndex = iOUT2( + i, k, pd, OutRun->irow_OUT, OutRun->nrow_OUT, sw->Site.n_layers + ); do_running_agg( - p, psd, iOUTIndex, go->currIter, vo->SWA_VegType[k][i] + p, psd, iOUTIndex, OutRun->currIter, vo->SWA_VegType[k][i] ); } } - if (go->print_IterationSummary) { - go->sw_outstr_agg[0] = '\0'; + if (OutRun->print_IterationSummary) { + OutRun->sw_outstr_agg[0] = '\0'; format_IterationSummary2(p, psd, pd, NVEGTYPES, 0, sw); } } @@ -1417,19 +1576,21 @@ void get_swa_agg(OutPeriod pd, SW_RUN *sw) { @param[in] pd Time period in simulation output (day/week/month/year) @param[in] sw Comprehensive struct of type SW_RUN containing all information in the simulation. +@param[in] OutDom Struct of type SW_OUT_DOM that holds output + information that do not change throughout simulation runs */ void get_swcBulk_text(OutPeriod pd, SW_RUN *sw) { /* added 21-Oct-03, cwb */ LyrIndex i; SW_SOILWAT_OUTPUTS *vo = sw->SoilWat.p_oagg[pd]; - SW_GEN_OUT *go = &sw->GenOutput; + SW_OUT_RUN *OutRun = &sw->OutRun; char str[OUTSTRLEN]; - go->sw_outstr[0] = '\0'; + OutRun->sw_outstr[0] = '\0'; ForEachSoilLayer(i, sw->Site.n_layers) { snprintf(str, OUTSTRLEN, "%c%.*f", _OUTSEP, OUT_DIGITS, vo->swcBulk[i]); - strcat(go->sw_outstr, str); + strcat(OutRun->sw_outstr, str); } } #endif @@ -1442,30 +1603,35 @@ void get_swcBulk_text(OutPeriod pd, SW_RUN *sw) { @param[in] pd Time period in simulation output (day/week/month/year) @param[in] sw Comprehensive struct of type SW_RUN containing all information in the simulation. +@param[in] OutDom Struct of type SW_OUT_DOM that holds output + information that do not change throughout simulation runs */ -void get_swcBulk_mem(OutPeriod pd, SW_RUN *sw) { +void get_swcBulk_mem(OutPeriod pd, SW_RUN *sw, SW_OUT_DOM *OutDom) { LyrIndex i; SW_SOILWAT_OUTPUTS *vo = sw->SoilWat.p_oagg[pd]; size_t iOUTIndex = 0; - SW_GEN_OUT *go = &sw->GenOutput; + SW_OUT_RUN *OutRun = &sw->OutRun; - RealD *p = go->p_OUT[eSW_SWCBulk][pd]; + RealD *p = OutRun->p_OUT[eSW_SWCBulk][pd]; #if defined(RSOILWAT) get_outvalleader( - &sw->Model, pd, go->irow_OUT, go->nrow_OUT, go->tOffset, p + &sw->Model, pd, OutRun->irow_OUT, OutRun->nrow_OUT, OutRun->tOffset, p ); #endif ForEachSoilLayer(i, sw->Site.n_layers) { #if defined(RSOILWAT) - iOUTIndex = - iOUT(i, go->irow_OUT[pd], go->nrow_OUT[pd], ncol_TimeOUT[pd]); + iOUTIndex = iOUT( + i, OutRun->irow_OUT[pd], OutDom->nrow_OUT[pd], ncol_TimeOUT[pd] + ); #elif defined(SWNETCDF) iOUTIndex = - go->iOUToffset[eSW_SWCBulk][pd][0] + - iOUTnc(go->irow_OUT[pd], i, 0, go->nsl_OUT[eSW_SWCBulk][0], 1); + OutDom->iOUToffset[eSW_SWCBulk][pd][0] + + iOUTnc( + OutRun->irow_OUT[pd], i, 0, OutDom->nsl_OUT[eSW_SWCBulk][0], 1 + ); #endif p[iOUTIndex] = vo->swcBulk[i]; @@ -1473,10 +1639,12 @@ void get_swcBulk_mem(OutPeriod pd, SW_RUN *sw) { #if defined(SWNETCDF) /* Set extra soil layers to missing/fill value (up to domain-wide max) */ - for (i = sw->Site.n_layers; i < go->nsl_OUT[eSW_SWCBulk][0]; i++) { + for (i = sw->Site.n_layers; i < OutDom->nsl_OUT[eSW_SWCBulk][0]; i++) { iOUTIndex = - go->iOUToffset[eSW_SWCBulk][pd][0] + - iOUTnc(go->irow_OUT[pd], i, 0, go->nsl_OUT[eSW_SWCBulk][0], 1); + OutDom->iOUToffset[eSW_SWCBulk][pd][0] + + iOUTnc( + OutRun->irow_OUT[pd], i, 0, OutDom->nsl_OUT[eSW_SWCBulk][0], 1 + ); p[iOUTIndex] = NC_FILL_DOUBLE; } #endif // SWNETCDF @@ -1490,24 +1658,28 @@ void get_swcBulk_mem(OutPeriod pd, SW_RUN *sw) { @param[in] pd Time period in simulation output (day/week/month/year) @param[in] sw Comprehensive struct of type SW_RUN containing all information in the simulation. +@param[in] OutDom Struct of type SW_OUT_DOM that holds output + information that do not change throughout simulation runs */ -void get_swcBulk_agg(OutPeriod pd, SW_RUN *sw) { +void get_swcBulk_agg(OutPeriod pd, SW_RUN *sw, SW_OUT_DOM *OutDom) { LyrIndex i; SW_SOILWAT_OUTPUTS *vo = sw->SoilWat.p_oagg[pd]; size_t iOUTIndex = 0; - SW_GEN_OUT *go = &sw->GenOutput; + SW_OUT_RUN *OutRun = &sw->OutRun; - RealD *p = go->p_OUT[eSW_SWCBulk][pd], *psd = go->p_OUTsd[eSW_SWCBulk][pd]; + RealD *p = OutRun->p_OUT[eSW_SWCBulk][pd], + *psd = OutRun->p_OUTsd[eSW_SWCBulk][pd]; ForEachSoilLayer(i, sw->Site.n_layers) { - iOUTIndex = - iOUT(i, go->irow_OUT[pd], go->nrow_OUT[pd], ncol_TimeOUT[pd]); - do_running_agg(p, psd, iOUTIndex, go->currIter, vo->swcBulk[i]); + iOUTIndex = iOUT( + i, OutRun->irow_OUT[pd], OutDom->nrow_OUT[pd], ncol_TimeOUT[pd] + ); + do_running_agg(p, psd, iOUTIndex, OutRun->currIter, vo->swcBulk[i]); } - if (go->print_IterationSummary) { - go->sw_outstr_agg[0] = '\0'; - format_IterationSummary(p, psd, pd, go->ncol_OUT[eSW_SWCBulk], sw); + if (OutRun->print_IterationSummary) { + OutRun->sw_outstr_agg[0] = '\0'; + format_IterationSummary(p, psd, pd, OutRun->ncol_OUT[eSW_SWCBulk], sw); } } @@ -1517,18 +1689,19 @@ void get_swcBulk_agg(OutPeriod pd, SW_RUN *sw) { @param[in] pd Time period in simulation output (day/week/month/year) @param[in] sw Comprehensive struct of type SW_RUN containing all information in the simulation. +@param[in] OutDom Struct of type SW_OUT_DOM that holds output + information that do not change throughout simulation runs */ -void get_swcBulk_SXW(OutPeriod pd, SW_RUN *sw) { +void get_swcBulk_SXW(OutPeriod pd, SW_RUN *sw, SW_OUT_DOM *OutDom) { TimeInt month; if (pd == eSW_Month) { LyrIndex i; SW_SOILWAT_OUTPUTS *vo = sw->SoilWat.p_oagg[pd]; - SW_GEN_OUT *go = &sw->GenOutput; - month = sw->Model.month - go->tOffset; + month = sw->Model.month - OutRun->tOffset; ForEachSoilLayer(i, sw->Site.n_layers) { - go->swc[i][month] = vo->swcBulk[i]; + OutRun->swc[i][month] = vo->swcBulk[i]; } } } @@ -1540,26 +1713,29 @@ void get_swcBulk_SXW(OutPeriod pd, SW_RUN *sw) { /** @brief eSW_SWPMatric Can't take arithmetic average of swp vecause its -exponentail. At this time (until I rewmember to look up whether harmonic or some -other average is better and fix this) we're not averaging swp but converting the -averged swc. This also avoids converting for each day. added 12-Oct-03, cwb +exponentail. At this time (until I rewmember to look up whether harmonic OutRun +some other average is better and fix this) we're not averaging swp but +converting the averged swc. This also avoids converting for each day. added +12-Oct-03, cwb @param[in] pd Time period in simulation output (day/week/month/year) @param[in] sw Comprehensive struct of type SW_RUN containing all information in the simulation. +@param[in] OutDom Struct of type SW_OUT_DOM that holds output + information that do not change throughout simulation runs */ void get_swpMatric_text(OutPeriod pd, SW_RUN *sw) { RealD val; LyrIndex i; SW_SOILWAT_OUTPUTS *vo = sw->SoilWat.p_oagg[pd]; - SW_GEN_OUT *go = &sw->GenOutput; + SW_OUT_RUN *OutRun = &sw->OutRun; /* Local LOG_INFO only because `SW_SWRC_SWCtoSWP()` requires it */ LOG_INFO local_log; local_log.logfp = NULL; char str[OUTSTRLEN]; - go->sw_outstr[0] = '\0'; + OutRun->sw_outstr[0] = '\0'; ForEachSoilLayer(i, sw->Site.n_layers) { /* swpMatric at this point is identical to swcBulk */ @@ -1567,7 +1743,7 @@ void get_swpMatric_text(OutPeriod pd, SW_RUN *sw) { snprintf(str, OUTSTRLEN, "%c%.*f", _OUTSEP, OUT_DIGITS, val); - strcat(go->sw_outstr, str); + strcat(OutRun->sw_outstr, str); } } #endif @@ -1580,31 +1756,36 @@ void get_swpMatric_text(OutPeriod pd, SW_RUN *sw) { @param[in] pd Time period in simulation output (day/week/month/year) @param[in] sw Comprehensive struct of type SW_RUN containing all information in the simulation. +@param[in] OutDom Struct of type SW_OUT_DOM that holds output + information that do not change throughout simulation runs */ -void get_swpMatric_mem(OutPeriod pd, SW_RUN *sw) { +void get_swpMatric_mem(OutPeriod pd, SW_RUN *sw, SW_OUT_DOM *OutDom) { LyrIndex i; SW_SOILWAT_OUTPUTS *vo = sw->SoilWat.p_oagg[pd]; LOG_INFO local_log; size_t iOUTIndex = 0; - SW_GEN_OUT *go = &sw->GenOutput; + SW_OUT_RUN *OutRun = &sw->OutRun; - RealD *p = go->p_OUT[eSW_SWPMatric][pd]; + RealD *p = OutRun->p_OUT[eSW_SWPMatric][pd]; #if defined(RSOILWAT) get_outvalleader( - &sw->Model, pd, go->irow_OUT, go->nrow_OUT, go->tOffset, p + &sw->Model, pd, OutRun->irow_OUT, OutRun->nrow_OUT, OutRun->tOffset, p ); #endif ForEachSoilLayer(i, sw->Site.n_layers) { #if defined(RSOILWAT) - iOUTIndex = - iOUT(i, go->irow_OUT[pd], go->nrow_OUT[pd], ncol_TimeOUT[pd]); + iOUTIndex = iOUT( + i, OutRun->irow_OUT[pd], OutDom->nrow_OUT[pd], ncol_TimeOUT[pd] + ); #elif defined(SWNETCDF) iOUTIndex = - go->iOUToffset[eSW_SWPMatric][pd][0] + - iOUTnc(go->irow_OUT[pd], i, 0, go->nsl_OUT[eSW_SWPMatric][0], 1); + OutDom->iOUToffset[eSW_SWPMatric][pd][0] + + iOUTnc( + OutRun->irow_OUT[pd], i, 0, OutDom->nsl_OUT[eSW_SWPMatric][0], 1 + ); #endif /* swpMatric at this point is identical to swcBulk */ @@ -1614,10 +1795,12 @@ void get_swpMatric_mem(OutPeriod pd, SW_RUN *sw) { #if defined(SWNETCDF) /* Set extra soil layers to missing/fill value (up to domain-wide max) */ - for (i = sw->Site.n_layers; i < go->nsl_OUT[eSW_SWPMatric][0]; i++) { + for (i = sw->Site.n_layers; i < OutDom->nsl_OUT[eSW_SWPMatric][0]; i++) { iOUTIndex = - go->iOUToffset[eSW_SWPMatric][pd][0] + - iOUTnc(go->irow_OUT[pd], i, 0, go->nsl_OUT[eSW_SWPMatric][0], 1); + OutDom->iOUToffset[eSW_SWPMatric][pd][0] + + iOUTnc( + OutRun->irow_OUT[pd], i, 0, OutDom->nsl_OUT[eSW_SWPMatric][0], 1 + ); p[iOUTIndex] = NC_FILL_DOUBLE; } #endif // SWNETCDF @@ -1631,30 +1814,35 @@ void get_swpMatric_mem(OutPeriod pd, SW_RUN *sw) { @param[in] pd Time period in simulation output (day/week/month/year) @param[in] sw Comprehensive struct of type SW_RUN containing all information in the simulation. +@param[in] OutDom Struct of type SW_OUT_DOM that holds output + information that do not change throughout simulation runs */ -void get_swpMatric_agg(OutPeriod pd, SW_RUN *sw) { +void get_swpMatric_agg(OutPeriod pd, SW_RUN *sw, SW_OUT_DOM *OutDom) { RealD val; LyrIndex i; SW_SOILWAT_OUTPUTS *vo = sw->SoilWat.p_oagg[pd]; LOG_INFO local_log; size_t iOUTIndex = 0; - SW_GEN_OUT *go = &sw->GenOutput; + SW_OUT_RUN *OutRun = &sw->OutRun; - RealD *p = go->p_OUT[eSW_SWPMatric][pd], - *psd = go->p_OUTsd[eSW_SWPMatric][pd]; + RealD *p = OutRun->p_OUT[eSW_SWPMatric][pd], + *psd = OutRun->p_OUTsd[eSW_SWPMatric][pd]; ForEachSoilLayer(i, sw->Site.n_layers) { /* swpMatric at this point is identical to swcBulk */ val = SW_SWRC_SWCtoSWP(vo->swpMatric[i], &sw->Site, i, &local_log); - iOUTIndex = - iOUT(i, go->irow_OUT[pd], go->nrow_OUT[pd], ncol_TimeOUT[pd]); - do_running_agg(p, psd, iOUTIndex, go->currIter, val); + iOUTIndex = iOUT( + i, OutRun->irow_OUT[pd], OutDom->nrow_OUT[pd], ncol_TimeOUT[pd] + ); + do_running_agg(p, psd, iOUTIndex, OutRun->currIter, val); } - if (go->print_IterationSummary) { - go->sw_outstr_agg[0] = '\0'; - format_IterationSummary(p, psd, pd, go->ncol_OUT[eSW_SWPMatric], sw); + if (OutRun->print_IterationSummary) { + OutRun->sw_outstr_agg[0] = '\0'; + format_IterationSummary( + p, psd, pd, OutRun->ncol_OUT[eSW_SWPMatric], sw + ); } } #endif @@ -1669,18 +1857,20 @@ void get_swpMatric_agg(OutPeriod pd, SW_RUN *sw) { @param[in] pd Time period in simulation output (day/week/month/year) @param[in] sw Comprehensive struct of type SW_RUN containing all information in the simulation. +@param[in] OutDom Struct of type SW_OUT_DOM that holds output + information that do not change throughout simulation runs */ void get_swaBulk_text(OutPeriod pd, SW_RUN *sw) { LyrIndex i; SW_SOILWAT_OUTPUTS *vo = sw->SoilWat.p_oagg[pd]; - SW_GEN_OUT *go = &sw->GenOutput; + SW_OUT_RUN *OutRun = &sw->OutRun; char str[OUTSTRLEN]; - go->sw_outstr[0] = '\0'; + OutRun->sw_outstr[0] = '\0'; ForEachSoilLayer(i, sw->Site.n_layers) { snprintf(str, OUTSTRLEN, "%c%.*f", _OUTSEP, OUT_DIGITS, vo->swaBulk[i]); - strcat(go->sw_outstr, str); + strcat(OutRun->sw_outstr, str); } } #endif @@ -1693,30 +1883,35 @@ void get_swaBulk_text(OutPeriod pd, SW_RUN *sw) { @param[in] pd Time period in simulation output (day/week/month/year) @param[in] sw Comprehensive struct of type SW_RUN containing all information in the simulation. +@param[in] OutDom Struct of type SW_OUT_DOM that holds output + information that do not change throughout simulation runs */ -void get_swaBulk_mem(OutPeriod pd, SW_RUN *sw) { +void get_swaBulk_mem(OutPeriod pd, SW_RUN *sw, SW_OUT_DOM *OutDom) { LyrIndex i; SW_SOILWAT_OUTPUTS *vo = sw->SoilWat.p_oagg[pd]; size_t iOUTIndex = 0; - SW_GEN_OUT *go = &sw->GenOutput; + SW_OUT_RUN *OutRun = &sw->OutRun; - RealD *p = go->p_OUT[eSW_SWABulk][pd]; + RealD *p = OutRun->p_OUT[eSW_SWABulk][pd]; #if defined(RSOILWAT) get_outvalleader( - &sw->Model, pd, go->irow_OUT, go->nrow_OUT, go->tOffset, p + &sw->Model, pd, OutRun->irow_OUT, OutRun->nrow_OUT, OutRun->tOffset, p ); #endif ForEachSoilLayer(i, sw->Site.n_layers) { #if defined(RSOILWAT) - iOUTIndex = - iOUT(i, go->irow_OUT[pd], go->nrow_OUT[pd], ncol_TimeOUT[pd]); + iOUTIndex = iOUT( + i, OutRun->irow_OUT[pd], OutDom->nrow_OUT[pd], ncol_TimeOUT[pd] + ); #elif defined(SWNETCDF) iOUTIndex = - go->iOUToffset[eSW_SWABulk][pd][0] + - iOUTnc(go->irow_OUT[pd], i, 0, go->nsl_OUT[eSW_SWABulk][0], 1); + OutDom->iOUToffset[eSW_SWABulk][pd][0] + + iOUTnc( + OutRun->irow_OUT[pd], i, 0, OutDom->nsl_OUT[eSW_SWABulk][0], 1 + ); #endif p[iOUTIndex] = vo->swaBulk[i]; @@ -1724,10 +1919,12 @@ void get_swaBulk_mem(OutPeriod pd, SW_RUN *sw) { #if defined(SWNETCDF) /* Set extra soil layers to missing/fill value (up to domain-wide max) */ - for (i = sw->Site.n_layers; i < go->nsl_OUT[eSW_SWABulk][0]; i++) { + for (i = sw->Site.n_layers; i < OutDom->nsl_OUT[eSW_SWABulk][0]; i++) { iOUTIndex = - go->iOUToffset[eSW_SWABulk][pd][0] + - iOUTnc(go->irow_OUT[pd], i, 0, go->nsl_OUT[eSW_SWABulk][0], 1); + OutDom->iOUToffset[eSW_SWABulk][pd][0] + + iOUTnc( + OutRun->irow_OUT[pd], i, 0, OutDom->nsl_OUT[eSW_SWABulk][0], 1 + ); p[iOUTIndex] = NC_FILL_DOUBLE; } #endif // SWNETCDF @@ -1741,24 +1938,28 @@ void get_swaBulk_mem(OutPeriod pd, SW_RUN *sw) { @param[in] pd Time period in simulation output (day/week/month/year) @param[in] sw Comprehensive struct of type SW_RUN containing all information in the simulation. +@param[in] OutDom Struct of type SW_OUT_DOM that holds output + information that do not change throughout simulation runs */ -void get_swaBulk_agg(OutPeriod pd, SW_RUN *sw) { +void get_swaBulk_agg(OutPeriod pd, SW_RUN *sw, SW_OUT_DOM *OutDom) { LyrIndex i; SW_SOILWAT_OUTPUTS *vo = sw->SoilWat.p_oagg[pd]; size_t iOUTIndex = 0; - SW_GEN_OUT *go = &sw->GenOutput; + SW_OUT_RUN *OutRun = &sw->OutRun; - RealD *p = go->p_OUT[eSW_SWABulk][pd], *psd = go->p_OUTsd[eSW_SWABulk][pd]; + RealD *p = OutRun->p_OUT[eSW_SWABulk][pd], + *psd = OutRun->p_OUTsd[eSW_SWABulk][pd]; ForEachSoilLayer(i, sw->Site.n_layers) { - iOUTIndex = - iOUT(i, go->irow_OUT[pd], go->nrow_OUT[pd], ncol_TimeOUT[pd]); - do_running_agg(p, psd, iOUTIndex, go->currIter, vo->swaBulk[i]); + iOUTIndex = iOUT( + i, OutRun->irow_OUT[pd], OutDom->nrow_OUT[pd], ncol_TimeOUT[pd] + ); + do_running_agg(p, psd, iOUTIndex, OutRun->currIter, vo->swaBulk[i]); } - if (go->print_IterationSummary) { - go->sw_outstr_agg[0] = '\0'; - format_IterationSummary(p, psd, pd, go->ncol_OUT[eSW_SWABulk], sw); + if (OutRun->print_IterationSummary) { + OutRun->sw_outstr_agg[0] = '\0'; + format_IterationSummary(p, psd, pd, OutRun->ncol_OUT[eSW_SWABulk], sw); } } #endif @@ -1772,15 +1973,17 @@ void get_swaBulk_agg(OutPeriod pd, SW_RUN *sw) { @param[in] pd Time period in simulation output (day/week/month/year) @param[in] sw Comprehensive struct of type SW_RUN containing all information in the simulation. +@param[in] OutDom Struct of type SW_OUT_DOM that holds output + information that do not change throughout simulation runs */ void get_swaMatric_text(OutPeriod pd, SW_RUN *sw) { LyrIndex i; RealD convert; SW_SOILWAT_OUTPUTS *vo = sw->SoilWat.p_oagg[pd]; - SW_GEN_OUT *go = &sw->GenOutput; + SW_OUT_RUN *OutRun = &sw->OutRun; char str[OUTSTRLEN]; - go->sw_outstr[0] = '\0'; + OutRun->sw_outstr[0] = '\0'; ForEachSoilLayer(i, sw->Site.n_layers) { /* swaMatric at this point is identical to swaBulk */ @@ -1794,7 +1997,7 @@ void get_swaMatric_text(OutPeriod pd, SW_RUN *sw) { OUT_DIGITS, vo->swaMatric[i] * convert ); - strcat(go->sw_outstr, str); + strcat(OutRun->sw_outstr, str); } } #endif @@ -1807,31 +2010,36 @@ void get_swaMatric_text(OutPeriod pd, SW_RUN *sw) { @param[in] pd Time period in simulation output (day/week/month/year) @param[in] sw Comprehensive struct of type SW_RUN containing all information in the simulation. +@param[in] OutDom Struct of type SW_OUT_DOM that holds output + information that do not change throughout simulation runs */ -void get_swaMatric_mem(OutPeriod pd, SW_RUN *sw) { +void get_swaMatric_mem(OutPeriod pd, SW_RUN *sw, SW_OUT_DOM *OutDom) { LyrIndex i; RealD convert; SW_SOILWAT_OUTPUTS *vo = sw->SoilWat.p_oagg[pd]; size_t iOUTIndex = 0; - SW_GEN_OUT *go = &sw->GenOutput; + SW_OUT_RUN *OutRun = &sw->OutRun; - RealD *p = go->p_OUT[eSW_SWAMatric][pd]; + RealD *p = OutRun->p_OUT[eSW_SWAMatric][pd]; #if defined(RSOILWAT) get_outvalleader( - &sw->Model, pd, go->irow_OUT, go->nrow_OUT, go->tOffset, p + &sw->Model, pd, OutRun->irow_OUT, OutRun->nrow_OUT, OutRun->tOffset, p ); #endif ForEachSoilLayer(i, sw->Site.n_layers) { #if defined(RSOILWAT) - iOUTIndex = - iOUT(i, go->irow_OUT[pd], go->nrow_OUT[pd], ncol_TimeOUT[pd]); + iOUTIndex = iOUT( + i, OutRun->irow_OUT[pd], OutDom->nrow_OUT[pd], ncol_TimeOUT[pd] + ); #elif defined(SWNETCDF) iOUTIndex = - go->iOUToffset[eSW_SWAMatric][pd][0] + - iOUTnc(go->irow_OUT[pd], i, 0, go->nsl_OUT[eSW_SWAMatric][0], 1); + OutDom->iOUToffset[eSW_SWAMatric][pd][0] + + iOUTnc( + OutRun->irow_OUT[pd], i, 0, OutDom->nsl_OUT[eSW_SWAMatric][0], 1 + ); #endif /* swaMatric at this point is identical to swaBulk */ @@ -1841,10 +2049,12 @@ void get_swaMatric_mem(OutPeriod pd, SW_RUN *sw) { #if defined(SWNETCDF) /* Set extra soil layers to missing/fill value (up to domain-wide max) */ - for (i = sw->Site.n_layers; i < go->nsl_OUT[eSW_SWAMatric][0]; i++) { + for (i = sw->Site.n_layers; i < OutDom->nsl_OUT[eSW_SWAMatric][0]; i++) { iOUTIndex = - go->iOUToffset[eSW_SWAMatric][pd][0] + - iOUTnc(go->irow_OUT[pd], i, 0, go->nsl_OUT[eSW_SWAMatric][0], 1); + OutDom->iOUToffset[eSW_SWAMatric][pd][0] + + iOUTnc( + OutRun->irow_OUT[pd], i, 0, OutDom->nsl_OUT[eSW_SWAMatric][0], 1 + ); p[iOUTIndex] = NC_FILL_DOUBLE; } #endif // SWNETCDF @@ -1858,31 +2068,36 @@ void get_swaMatric_mem(OutPeriod pd, SW_RUN *sw) { @param[in] pd Time period in simulation output (day/week/month/year) @param[in] sw Comprehensive struct of type SW_RUN containing all information in the simulation. +@param[in] OutDom Struct of type SW_OUT_DOM that holds output + information that do not change throughout simulation runs */ -void get_swaMatric_agg(OutPeriod pd, SW_RUN *sw) { +void get_swaMatric_agg(OutPeriod pd, SW_RUN *sw, SW_OUT_DOM *OutDom) { LyrIndex i; RealD convert; SW_SOILWAT_OUTPUTS *vo = sw->SoilWat.p_oagg[pd]; size_t iOUTIndex = 0; - SW_GEN_OUT *go = &sw->GenOutput; + SW_OUT_RUN *OutRun = &sw->OutRun; - RealD *p = go->p_OUT[eSW_SWAMatric][pd], - *psd = go->p_OUTsd[eSW_SWAMatric][pd]; + RealD *p = OutRun->p_OUT[eSW_SWAMatric][pd], + *psd = OutRun->p_OUTsd[eSW_SWAMatric][pd]; ForEachSoilLayer(i, sw->Site.n_layers) { /* swaMatric at this point is identical to swaBulk */ convert = 1. / (1. - sw->Site.fractionVolBulk_gravel[i]); - iOUTIndex = - iOUT(i, go->irow_OUT[pd], go->nrow_OUT[pd], ncol_TimeOUT[pd]); + iOUTIndex = iOUT( + i, OutRun->irow_OUT[pd], OutDom->nrow_OUT[pd], ncol_TimeOUT[pd] + ); do_running_agg( - p, psd, iOUTIndex, go->currIter, vo->swaMatric[i] * convert + p, psd, iOUTIndex, OutRun->currIter, vo->swaMatric[i] * convert ); } - if (go->print_IterationSummary) { - go->sw_outstr_agg[0] = '\0'; - format_IterationSummary(p, psd, pd, go->ncol_OUT[eSW_SWAMatric], sw); + if (OutRun->print_IterationSummary) { + OutRun->sw_outstr_agg[0] = '\0'; + format_IterationSummary( + p, psd, pd, OutRun->ncol_OUT[eSW_SWAMatric], sw + ); } } #endif @@ -1897,15 +2112,17 @@ void get_swaMatric_agg(OutPeriod pd, SW_RUN *sw) { @param[in] pd Time period in simulation output (day/week/month/year) @param[in] sw Comprehensive struct of type SW_RUN containing all information in the simulation. +@param[in] OutDom Struct of type SW_OUT_DOM that holds output + information that do not change throughout simulation runs */ void get_surfaceWater_text(OutPeriod pd, SW_RUN *sw) { SW_SOILWAT_OUTPUTS *vo = sw->SoilWat.p_oagg[pd]; - SW_GEN_OUT *go = &sw->GenOutput; + SW_OUT_RUN *OutRun = &sw->OutRun; - go->sw_outstr[0] = '\0'; + OutRun->sw_outstr[0] = '\0'; snprintf( - go->sw_outstr, - sizeof go->sw_outstr, + OutRun->sw_outstr, + sizeof OutRun->sw_outstr, "%c%.*f", _OUTSEP, OUT_DIGITS, @@ -1922,26 +2139,29 @@ void get_surfaceWater_text(OutPeriod pd, SW_RUN *sw) { @param[in] pd Time period in simulation output (day/week/month/year) @param[in] sw Comprehensive struct of type SW_RUN containing all information in the simulation. +@param[in] OutDom Struct of type SW_OUT_DOM that holds output + information that do not change throughout simulation runs */ -void get_surfaceWater_mem(OutPeriod pd, SW_RUN *sw) { +void get_surfaceWater_mem(OutPeriod pd, SW_RUN *sw, SW_OUT_DOM *OutDom) { SW_SOILWAT_OUTPUTS *vo = sw->SoilWat.p_oagg[pd]; size_t iOUTIndex = 0; - SW_GEN_OUT *go = &sw->GenOutput; + SW_OUT_RUN *OutRun = &sw->OutRun; - RealD *p = go->p_OUT[eSW_SurfaceWater][pd]; + RealD *p = OutRun->p_OUT[eSW_SurfaceWater][pd]; #if defined(RSOILWAT) get_outvalleader( - &sw->Model, pd, go->irow_OUT, go->nrow_OUT, go->tOffset, p + &sw->Model, pd, OutRun->irow_OUT, OutRun->nrow_OUT, OutRun->tOffset, p ); #endif #if defined(RSOILWAT) - iOUTIndex = iOUT(0, go->irow_OUT[pd], go->nrow_OUT[pd], ncol_TimeOUT[pd]); + iOUTIndex = + iOUT(0, OutRun->irow_OUT[pd], OutDom->nrow_OUT[pd], ncol_TimeOUT[pd]); #elif defined(SWNETCDF) - iOUTIndex = go->iOUToffset[eSW_SurfaceWater][pd][0] + - iOUTnc(go->irow_OUT[pd], 0, 0, 1, 1); + iOUTIndex = OutDom->iOUToffset[eSW_SurfaceWater][pd][0] + + iOUTnc(OutRun->irow_OUT[pd], 0, 0, 1, 1); #endif p[iOUTIndex] = vo->surfaceWater; @@ -1955,21 +2175,26 @@ void get_surfaceWater_mem(OutPeriod pd, SW_RUN *sw) { @param[in] pd Time period in simulation output (day/week/month/year) @param[in] sw Comprehensive struct of type SW_RUN containing all information in the simulation. +@param[in] OutDom Struct of type SW_OUT_DOM that holds output + information that do not change throughout simulation runs */ -void get_surfaceWater_agg(OutPeriod pd, SW_RUN *sw) { +void get_surfaceWater_agg(OutPeriod pd, SW_RUN *sw, SW_OUT_DOM *OutDom) { SW_SOILWAT_OUTPUTS *vo = sw->SoilWat.p_oagg[pd]; size_t iOUTIndex = 0; - SW_GEN_OUT *go = &sw->GenOutput; + SW_OUT_RUN *OutRun = &sw->OutRun; - RealD *p = go->p_OUT[eSW_SurfaceWater][pd], - *psd = go->p_OUTsd[eSW_SurfaceWater][pd]; + RealD *p = OutRun->p_OUT[eSW_SurfaceWater][pd], + *psd = OutRun->p_OUTsd[eSW_SurfaceWater][pd]; - iOUTIndex = iOUT(0, go->irow_OUT[pd], go->nrow_OUT[pd], ncol_TimeOUT[pd]); - do_running_agg(p, psd, iOUTIndex, go->currIter, vo->surfaceWater); + iOUTIndex = + iOUT(0, OutRun->irow_OUT[pd], OutDom->nrow_OUT[pd], ncol_TimeOUT[pd]); + do_running_agg(p, psd, iOUTIndex, OutRun->currIter, vo->surfaceWater); - if (go->print_IterationSummary) { - go->sw_outstr_agg[0] = '\0'; - format_IterationSummary(p, psd, pd, go->ncol_OUT[eSW_SurfaceWater], sw); + if (OutRun->print_IterationSummary) { + OutRun->sw_outstr_agg[0] = '\0'; + format_IterationSummary( + p, psd, pd, OutRun->ncol_OUT[eSW_SurfaceWater], sw + ); } } #endif @@ -1985,18 +2210,20 @@ OUTTEXT. @param[in] pd Time period in simulation output (day/week/month/year) @param[in] sw Comprehensive struct of type SW_RUN containing all information in the simulation. +@param[in] OutDom Struct of type SW_OUT_DOM that holds output + information that do not change throughout simulation runs */ void get_runoffrunon_text(OutPeriod pd, SW_RUN *sw) { RealD net; SW_WEATHER_OUTPUTS *vo = sw->Weather.p_oagg[pd]; - SW_GEN_OUT *go = &sw->GenOutput; + SW_OUT_RUN *OutRun = &sw->OutRun; net = vo->surfaceRunoff + vo->snowRunoff - vo->surfaceRunon; - go->sw_outstr[0] = '\0'; + OutRun->sw_outstr[0] = '\0'; snprintf( - go->sw_outstr, - sizeof go->sw_outstr, + OutRun->sw_outstr, + sizeof OutRun->sw_outstr, "%c%.*f%c%.*f%c%.*f%c%.*f", _OUTSEP, OUT_DIGITS, @@ -2023,59 +2250,65 @@ RSOILWAT. @param[in] pd Time period in simulation output (day/week/month/year) @param[in] sw Comprehensive struct of type SW_RUN containing all information in the simulation. +@param[in] OutDom Struct of type SW_OUT_DOM that holds output + information that do not change throughout simulation runs */ -void get_runoffrunon_mem(OutPeriod pd, SW_RUN *sw) { +void get_runoffrunon_mem(OutPeriod pd, SW_RUN *sw, SW_OUT_DOM *OutDom) { SW_WEATHER_OUTPUTS *vo = sw->Weather.p_oagg[pd]; size_t iOUTIndex = 0; - SW_GEN_OUT *go = &sw->GenOutput; + SW_OUT_RUN *OutRun = &sw->OutRun; - RealD *p = go->p_OUT[eSW_Runoff][pd]; + RealD *p = OutRun->p_OUT[eSW_Runoff][pd]; #if defined(RSOILWAT) get_outvalleader( - &sw->Model, pd, go->irow_OUT, go->nrow_OUT, go->tOffset, p + &sw->Model, pd, OutRun->irow_OUT, OutRun->nrow_OUT, OutRun->tOffset, p ); #endif #if defined(RSOILWAT) - iOUTIndex = iOUT(0, go->irow_OUT[pd], go->nrow_OUT[pd], ncol_TimeOUT[pd]); + iOUTIndex = + iOUT(0, OutRun->irow_OUT[pd], OutDom->nrow_OUT[pd], ncol_TimeOUT[pd]); #elif defined(SWNETCDF) - iOUTIndex = go->iOUToffset[eSW_Runoff][pd][0] + - iOUTnc(go->irow_OUT[pd], 0, 0, 1, 1); + iOUTIndex = OutDom->iOUToffset[eSW_Runoff][pd][0] + + iOUTnc(OutRun->irow_OUT[pd], 0, 0, 1, 1); #endif p[iOUTIndex] = vo->surfaceRunoff + vo->snowRunoff - vo->surfaceRunon; #if defined(RSOILWAT) - iOUTIndex = iOUT(1, go->irow_OUT[pd], go->nrow_OUT[pd], ncol_TimeOUT[pd]); + iOUTIndex = + iOUT(1, OutRun->irow_OUT[pd], OutDom->nrow_OUT[pd], ncol_TimeOUT[pd]); #elif defined(SWNETCDF) - iOUTIndex = go->iOUToffset[eSW_Runoff][pd][1] + - iOUTnc(go->irow_OUT[pd], 0, 0, 1, 1); + iOUTIndex = OutDom->iOUToffset[eSW_Runoff][pd][1] + + iOUTnc(OutRun->irow_OUT[pd], 0, 0, 1, 1); #endif p[iOUTIndex] = vo->surfaceRunoff; #if defined(RSOILWAT) - iOUTIndex = iOUT(2, go->irow_OUT[pd], go->nrow_OUT[pd], ncol_TimeOUT[pd]); + iOUTIndex = + iOUT(2, OutRun->irow_OUT[pd], OutDom->nrow_OUT[pd], ncol_TimeOUT[pd]); #elif defined(SWNETCDF) - iOUTIndex = go->iOUToffset[eSW_Runoff][pd][2] + - iOUTnc(go->irow_OUT[pd], 0, 0, 1, 1); + iOUTIndex = OutDom->iOUToffset[eSW_Runoff][pd][2] + + iOUTnc(OutRun->irow_OUT[pd], 0, 0, 1, 1); #endif p[iOUTIndex] = vo->snowRunoff; #if defined(RSOILWAT) - iOUTIndex = iOUT(3, go->irow_OUT[pd], go->nrow_OUT[pd], ncol_TimeOUT[pd]); + iOUTIndex = + iOUT(3, OutRun->irow_OUT[pd], OutDom->nrow_OUT[pd], ncol_TimeOUT[pd]); #elif defined(SWNETCDF) - iOUTIndex = go->iOUToffset[eSW_Runoff][pd][3] + - iOUTnc(go->irow_OUT[pd], 0, 0, 1, 1); + iOUTIndex = OutDom->iOUToffset[eSW_Runoff][pd][3] + + iOUTnc(OutRun->irow_OUT[pd], 0, 0, 1, 1); #endif p[iOUTIndex] = vo->surfaceRunon; @@ -2090,32 +2323,39 @@ STEPWAT. @param[in] pd Time period in simulation output (day/week/month/year) @param[in] sw Comprehensive struct of type SW_RUN containing all information in the simulation. +@param[in] OutDom Struct of type SW_OUT_DOM that holds output + information that do not change throughout simulation runs */ -void get_runoffrunon_agg(OutPeriod pd, SW_RUN *sw) { +void get_runoffrunon_agg(OutPeriod pd, SW_RUN *sw, SW_OUT_DOM *OutDom) { RealD net; SW_WEATHER_OUTPUTS *vo = sw->Weather.p_oagg[pd]; size_t iOUTIndex = 0; - SW_GEN_OUT *go = &sw->GenOutput; + SW_OUT_RUN *OutRun = &sw->OutRun; - RealD *p = go->p_OUT[eSW_Runoff][pd], *psd = go->p_OUTsd[eSW_Runoff][pd]; + RealD *p = OutRun->p_OUT[eSW_Runoff][pd], + *psd = OutRun->p_OUTsd[eSW_Runoff][pd]; net = vo->surfaceRunoff + vo->snowRunoff - vo->surfaceRunon; - iOUTIndex = iOUT(0, go->irow_OUT[pd], go->nrow_OUT[pd], ncol_TimeOUT[pd]); - do_running_agg(p, psd, iOUTIndex, go->currIter, net); + iOUTIndex = + iOUT(0, OutRun->irow_OUT[pd], OutDom->nrow_OUT[pd], ncol_TimeOUT[pd]); + do_running_agg(p, psd, iOUTIndex, OutRun->currIter, net); - iOUTIndex = iOUT(1, go->irow_OUT[pd], go->nrow_OUT[pd], ncol_TimeOUT[pd]); - do_running_agg(p, psd, iOUTIndex, go->currIter, vo->surfaceRunoff); + iOUTIndex = + iOUT(1, OutRun->irow_OUT[pd], OutDom->nrow_OUT[pd], ncol_TimeOUT[pd]); + do_running_agg(p, psd, iOUTIndex, OutRun->currIter, vo->surfaceRunoff); - iOUTIndex = iOUT(2, go->irow_OUT[pd], go->nrow_OUT[pd], ncol_TimeOUT[pd]); - do_running_agg(p, psd, iOUTIndex, go->currIter, vo->snowRunoff); + iOUTIndex = + iOUT(2, OutRun->irow_OUT[pd], OutDom->nrow_OUT[pd], ncol_TimeOUT[pd]); + do_running_agg(p, psd, iOUTIndex, OutRun->currIter, vo->snowRunoff); - iOUTIndex = iOUT(3, go->irow_OUT[pd], go->nrow_OUT[pd], ncol_TimeOUT[pd]); - do_running_agg(p, psd, iOUTIndex, go->currIter, vo->surfaceRunon); + iOUTIndex = + iOUT(3, OutRun->irow_OUT[pd], OutDom->nrow_OUT[pd], ncol_TimeOUT[pd]); + do_running_agg(p, psd, iOUTIndex, OutRun->currIter, vo->surfaceRunon); - if (go->print_IterationSummary) { - go->sw_outstr_agg[0] = '\0'; - format_IterationSummary(p, psd, pd, go->ncol_OUT[eSW_Runoff], sw); + if (OutRun->print_IterationSummary) { + OutRun->sw_outstr_agg[0] = '\0'; + format_IterationSummary(p, psd, pd, OutRun->ncol_OUT[eSW_Runoff], sw); } } #endif @@ -2129,22 +2369,24 @@ void get_runoffrunon_agg(OutPeriod pd, SW_RUN *sw) { @param[in] pd Time period in simulation output (day/week/month/year) @param[in] sw Comprehensive struct of type SW_RUN containing all information in the simulation. +@param[in] OutDom Struct of type SW_OUT_DOM that holds output + information that do not change throughout simulation runs */ void get_transp_text(OutPeriod pd, SW_RUN *sw) { LyrIndex i, n_layers = sw->Site.n_layers; int k; SW_SOILWAT_OUTPUTS *vo = sw->SoilWat.p_oagg[pd]; - SW_GEN_OUT *go = &sw->GenOutput; + SW_OUT_RUN *OutRun = &sw->OutRun; char str[OUTSTRLEN]; - go->sw_outstr[0] = '\0'; + OutRun->sw_outstr[0] = '\0'; /* total transpiration */ ForEachSoilLayer(i, n_layers) { snprintf( str, OUTSTRLEN, "%c%.*f", _OUTSEP, OUT_DIGITS, vo->transp_total[i] ); - strcat(go->sw_outstr, str); + strcat(OutRun->sw_outstr, str); } /* transpiration for each vegetation type */ @@ -2153,7 +2395,7 @@ void get_transp_text(OutPeriod pd, SW_RUN *sw) { snprintf( str, OUTSTRLEN, "%c%.*f", _OUTSEP, OUT_DIGITS, vo->transp[k][i] ); - strcat(go->sw_outstr, str); + strcat(OutRun->sw_outstr, str); } } } @@ -2167,32 +2409,37 @@ void get_transp_text(OutPeriod pd, SW_RUN *sw) { @param[in] pd Time period in simulation output (day/week/month/year) @param[in] sw Comprehensive struct of type SW_RUN containing all information in the simulation. +@param[in] OutDom Struct of type SW_OUT_DOM that holds output + information that do not change throughout simulation runs */ -void get_transp_mem(OutPeriod pd, SW_RUN *sw) { +void get_transp_mem(OutPeriod pd, SW_RUN *sw, SW_OUT_DOM *OutDom) { LyrIndex i, n_layers = sw->Site.n_layers; int k; SW_SOILWAT_OUTPUTS *vo = sw->SoilWat.p_oagg[pd]; size_t iOUTIndex = 0; - SW_GEN_OUT *go = &sw->GenOutput; + SW_OUT_RUN *OutRun = &sw->OutRun; - RealD *p = go->p_OUT[eSW_Transp][pd]; + RealD *p = OutRun->p_OUT[eSW_Transp][pd]; #if defined(RSOILWAT) get_outvalleader( - &sw->Model, pd, go->irow_OUT, go->nrow_OUT, go->tOffset, p + &sw->Model, pd, OutRun->irow_OUT, OutRun->nrow_OUT, OutRun->tOffset, p ); #endif /* total transpiration */ ForEachSoilLayer(i, n_layers) { #if defined(RSOILWAT) - iOUTIndex = - iOUT(i, go->irow_OUT[pd], go->nrow_OUT[pd], ncol_TimeOUT[pd]); + iOUTIndex = iOUT( + i, OutRun->irow_OUT[pd], OutDom->nrow_OUT[pd], ncol_TimeOUT[pd] + ); #elif defined(SWNETCDF) iOUTIndex = - go->iOUToffset[eSW_Transp][pd][0] + - iOUTnc(go->irow_OUT[pd], i, 0, go->nsl_OUT[eSW_Transp][0], 1); + OutDom->iOUToffset[eSW_Transp][pd][0] + + iOUTnc( + OutRun->irow_OUT[pd], i, 0, OutDom->nsl_OUT[eSW_Transp][0], 1 + ); #endif p[iOUTIndex] = vo->transp_total[i]; @@ -2200,10 +2447,12 @@ void get_transp_mem(OutPeriod pd, SW_RUN *sw) { #if defined(SWNETCDF) /* Set extra soil layers to missing/fill value (up to domain-wide max) */ - for (i = sw->Site.n_layers; i < go->nsl_OUT[eSW_Transp][0]; i++) { + for (i = sw->Site.n_layers; i < OutDom->nsl_OUT[eSW_Transp][0]; i++) { iOUTIndex = - go->iOUToffset[eSW_Transp][pd][0] + - iOUTnc(go->irow_OUT[pd], i, 0, go->nsl_OUT[eSW_Transp][0], 1); + OutDom->iOUToffset[eSW_Transp][pd][0] + + iOUTnc( + OutRun->irow_OUT[pd], i, 0, OutDom->nsl_OUT[eSW_Transp][0], 1 + ); p[iOUTIndex] = NC_FILL_DOUBLE; } #endif // SWNETCDF @@ -2214,17 +2463,18 @@ void get_transp_mem(OutPeriod pd, SW_RUN *sw) { ForEachSoilLayer(i, n_layers) { #if defined(RSOILWAT) // k + 1 because of total transp. - iOUTIndex = - iOUT2(i, k + 1, pd, go->irow_OUT, go->nrow_OUT, n_layers); + iOUTIndex = iOUT2( + i, k + 1, pd, OutRun->irow_OUT, OutRun->nrow_OUT, n_layers + ); #elif defined(SWNETCDF) - iOUTIndex = go->iOUToffset[eSW_Transp][pd][1] + + iOUTIndex = OutDom->iOUToffset[eSW_Transp][pd][1] + iOUTnc( - go->irow_OUT[pd], + OutRun->irow_OUT[pd], i, k, - go->nsl_OUT[eSW_Transp][1], - go->npft_OUT[eSW_Transp][1] + OutDom->nsl_OUT[eSW_Transp][1], + OutDom->npft_OUT[eSW_Transp][1] ); #endif @@ -2234,14 +2484,14 @@ void get_transp_mem(OutPeriod pd, SW_RUN *sw) { #if defined(SWNETCDF) /* Set extra soil layers to missing/fill value (up to domain-wide max) */ - for (i = sw->Site.n_layers; i < go->nsl_OUT[eSW_Transp][1]; i++) { - iOUTIndex = go->iOUToffset[eSW_Transp][pd][1] + + for (i = sw->Site.n_layers; i < OutDom->nsl_OUT[eSW_Transp][1]; i++) { + iOUTIndex = OutDom->iOUToffset[eSW_Transp][pd][1] + iOUTnc( - go->irow_OUT[pd], + OutRun->irow_OUT[pd], i, k, - go->nsl_OUT[eSW_Transp][1], - go->npft_OUT[eSW_Transp][1] + OutDom->nsl_OUT[eSW_Transp][1], + OutDom->npft_OUT[eSW_Transp][1] ); p[iOUTIndex] = NC_FILL_DOUBLE; } @@ -2257,25 +2507,31 @@ void get_transp_mem(OutPeriod pd, SW_RUN *sw) { @param[in] pd Time period in simulation output (day/week/month/year) @param[in] sw Comprehensive struct of type SW_RUN containing all information in the simulation. +@param[in] OutDom Struct of type SW_OUT_DOM that holds output + information that do not change throughout simulation runs */ -void get_transp_agg(OutPeriod pd, SW_RUN *sw) { +void get_transp_agg(OutPeriod pd, SW_RUN *sw, SW_OUT_DOM *OutDom) { LyrIndex i, n_layers = sw->Site.n_layers; int k; SW_SOILWAT_OUTPUTS *vo = sw->SoilWat.p_oagg[pd]; size_t iOUTIndex = 0; - SW_GEN_OUT *go = &sw->GenOutput; + SW_OUT_RUN *OutRun = &sw->OutRun; - RealD *p = go->p_OUT[eSW_Transp][pd], *psd = go->p_OUTsd[eSW_Transp][pd]; + RealD *p = OutRun->p_OUT[eSW_Transp][pd], + *psd = OutRun->p_OUTsd[eSW_Transp][pd]; /* total transpiration */ ForEachSoilLayer(i, n_layers) { - iOUTIndex = - iOUT(i, go->irow_OUT[pd], go->nrow_OUT[pd], ncol_TimeOUT[pd]); - do_running_agg(p, psd, iOUTIndex, go->currIter, vo->transp_total[i]); + iOUTIndex = iOUT( + i, OutRun->irow_OUT[pd], OutDom->nrow_OUT[pd], ncol_TimeOUT[pd] + ); + do_running_agg( + p, psd, iOUTIndex, OutRun->currIter, vo->transp_total[i] + ); } - if (go->print_IterationSummary) { - go->sw_outstr_agg[0] = '\0'; + if (OutRun->print_IterationSummary) { + OutRun->sw_outstr_agg[0] = '\0'; format_IterationSummary(p, psd, pd, n_layers, sw); } @@ -2283,13 +2539,16 @@ void get_transp_agg(OutPeriod pd, SW_RUN *sw) { ForEachVegType(k) { ForEachSoilLayer(i, n_layers) { // k + 1 because of total transp. - iOUTIndex = - iOUT2(i, k + 1, pd, go->irow_OUT, go->nrow_OUT, n_layers); - do_running_agg(p, psd, iOUTIndex, go->currIter, vo->transp[k][i]); + iOUTIndex = iOUT2( + i, k + 1, pd, OutRun->irow_OUT, OutRun->nrow_OUT, n_layers + ); + do_running_agg( + p, psd, iOUTIndex, OutRun->currIter, vo->transp[k][i] + ); } } - if (go->print_IterationSummary) { + if (OutRun->print_IterationSummary) { format_IterationSummary2(p, psd, pd, NVEGTYPES, 1, sw); } } @@ -2301,26 +2560,27 @@ void get_transp_agg(OutPeriod pd, SW_RUN *sw) { @param[in] pd Time period in simulation output (day/week/month/year) @param[in] sw Comprehensive struct of type SW_RUN containing all information in the simulation. +@param[in] OutDom Struct of type SW_OUT_DOM that holds output + information that do not change throughout simulation runs */ -void get_transp_SXW(OutPeriod pd, SW_RUN *sw) { +void get_transp_SXW(OutPeriod pd, SW_RUN *sw, SW_OUT_DOM *OutDom) { TimeInt month; if (pd == eSW_Month) { LyrIndex i; int k; SW_SOILWAT_OUTPUTS *vo = sw->SoilWat.p_oagg[pd]; - SW_GEN_OUT *go = &sw->GenOutput; - month = sw->Model.month - go->tOffset; + month = sw->Model.month - OutRun->tOffset; /* total transpiration */ ForEachSoilLayer(i, sw->Site.n_layers) { - go->transpTotal[i][month] = vo->transp_total[i]; + OutRun->transpTotal[i][month] = vo->transp_total[i]; } /* transpiration for each vegetation type */ ForEachVegType(k) { ForEachSoilLayer(i, sw->Site.n_layers) { - go->transpVeg[k][i][month] = vo->transp[k][i]; + OutRun->transpVeg[k][i][month] = vo->transp[k][i]; } } } @@ -2339,16 +2599,16 @@ void get_transp_SXW(OutPeriod pd, SW_RUN *sw) { void get_evapSoil_text(OutPeriod pd, SW_RUN *sw) { LyrIndex i; SW_SOILWAT_OUTPUTS *vo = sw->SoilWat.p_oagg[pd]; - SW_GEN_OUT *go = &sw->GenOutput; + SW_OUT_RUN *OutRun = &sw->OutRun; char str[OUTSTRLEN]; - go->sw_outstr[0] = '\0'; + OutRun->sw_outstr[0] = '\0'; ForEachEvapLayer(i, sw->Site.n_evap_lyrs) { snprintf( str, OUTSTRLEN, "%c%.*f", _OUTSEP, OUT_DIGITS, vo->evap_baresoil[i] ); - strcat(go->sw_outstr, str); + strcat(OutRun->sw_outstr, str); } } #endif @@ -2361,30 +2621,35 @@ void get_evapSoil_text(OutPeriod pd, SW_RUN *sw) { @param[in] pd Time period in simulation output (day/week/month/year) @param[in] sw Comprehensive struct of type SW_RUN containing all information in the simulation. +@param[in] OutDom Struct of type SW_OUT_DOM that holds output + information that do not change throughout simulation runs */ -void get_evapSoil_mem(OutPeriod pd, SW_RUN *sw) { +void get_evapSoil_mem(OutPeriod pd, SW_RUN *sw, SW_OUT_DOM *OutDom) { LyrIndex i; SW_SOILWAT_OUTPUTS *vo = sw->SoilWat.p_oagg[pd]; size_t iOUTIndex = 0; - SW_GEN_OUT *go = &sw->GenOutput; + SW_OUT_RUN *OutRun = &sw->OutRun; - RealD *p = go->p_OUT[eSW_EvapSoil][pd]; + RealD *p = OutRun->p_OUT[eSW_EvapSoil][pd]; #if defined(RSOILWAT) get_outvalleader( - &sw->Model, pd, go->irow_OUT, go->nrow_OUT, go->tOffset, p + &sw->Model, pd, OutRun->irow_OUT, OutRun->nrow_OUT, OutRun->tOffset, p ); #endif ForEachEvapLayer(i, sw->Site.n_evap_lyrs) { #if defined(RSOILWAT) - iOUTIndex = - iOUT(i, go->irow_OUT[pd], go->nrow_OUT[pd], ncol_TimeOUT[pd]); + iOUTIndex = iOUT( + i, OutRun->irow_OUT[pd], OutDom->nrow_OUT[pd], ncol_TimeOUT[pd] + ); #elif defined(SWNETCDF) iOUTIndex = - go->iOUToffset[eSW_EvapSoil][pd][0] + - iOUTnc(go->irow_OUT[pd], i, 0, go->nsl_OUT[eSW_EvapSoil][0], 1); + OutDom->iOUToffset[eSW_EvapSoil][pd][0] + + iOUTnc( + OutRun->irow_OUT[pd], i, 0, OutDom->nsl_OUT[eSW_EvapSoil][0], 1 + ); #endif p[iOUTIndex] = vo->evap_baresoil[i]; @@ -2392,10 +2657,12 @@ void get_evapSoil_mem(OutPeriod pd, SW_RUN *sw) { #if defined(SWNETCDF) /* Set extra soil layers to missing/fill value (up to domain-wide max) */ - for (i = sw->Site.n_evap_lyrs; i < go->nsl_OUT[eSW_EvapSoil][0]; i++) { + for (i = sw->Site.n_evap_lyrs; i < OutDom->nsl_OUT[eSW_EvapSoil][0]; i++) { iOUTIndex = - go->iOUToffset[eSW_EvapSoil][pd][0] + - iOUTnc(go->irow_OUT[pd], i, 0, go->nsl_OUT[eSW_EvapSoil][0], 1); + OutDom->iOUToffset[eSW_EvapSoil][pd][0] + + iOUTnc( + OutRun->irow_OUT[pd], i, 0, OutDom->nsl_OUT[eSW_EvapSoil][0], 1 + ); p[iOUTIndex] = NC_FILL_DOUBLE; } #endif // SWNETCDF @@ -2409,25 +2676,30 @@ void get_evapSoil_mem(OutPeriod pd, SW_RUN *sw) { @param[in] pd Time period in simulation output (day/week/month/year) @param[in] sw Comprehensive struct of type SW_RUN containing all information in the simulation. +@param[in] OutDom Struct of type SW_OUT_DOM that holds output + information that do not change throughout simulation runs */ -void get_evapSoil_agg(OutPeriod pd, SW_RUN *sw) { +void get_evapSoil_agg(OutPeriod pd, SW_RUN *sw, SW_OUT_DOM *OutDom) { LyrIndex i; SW_SOILWAT_OUTPUTS *vo = sw->SoilWat.p_oagg[pd]; size_t iOUTIndex = 0; - SW_GEN_OUT *go = &sw->GenOutput; + SW_OUT_RUN *OutRun = &sw->OutRun; - RealD *p = go->p_OUT[eSW_EvapSoil][pd], - *psd = go->p_OUTsd[eSW_EvapSoil][pd]; + RealD *p = OutRun->p_OUT[eSW_EvapSoil][pd], + *psd = OutRun->p_OUTsd[eSW_EvapSoil][pd]; ForEachEvapLayer(i, sw->Site.n_evap_lyrs) { - iOUTIndex = - iOUT(i, go->irow_OUT[pd], go->nrow_OUT[pd], ncol_TimeOUT[pd]); - do_running_agg(p, psd, iOUTIndex, go->currIter, vo->evap_baresoil[i]); + iOUTIndex = iOUT( + i, OutRun->irow_OUT[pd], OutDom->nrow_OUT[pd], ncol_TimeOUT[pd] + ); + do_running_agg( + p, psd, iOUTIndex, OutRun->currIter, vo->evap_baresoil[i] + ); } - if (go->print_IterationSummary) { - go->sw_outstr_agg[0] = '\0'; - format_IterationSummary(p, psd, pd, go->ncol_OUT[eSW_EvapSoil], sw); + if (OutRun->print_IterationSummary) { + OutRun->sw_outstr_agg[0] = '\0'; + format_IterationSummary(p, psd, pd, OutRun->ncol_OUT[eSW_EvapSoil], sw); } } #endif @@ -2442,18 +2714,20 @@ void get_evapSoil_agg(OutPeriod pd, SW_RUN *sw) { @param[in] pd Time period in simulation output (day/week/month/year) @param[in] sw Comprehensive struct of type SW_RUN containing all information in the simulation. +@param[in] OutDom Struct of type SW_OUT_DOM that holds output + information that do not change throughout simulation runs */ void get_evapSurface_text(OutPeriod pd, SW_RUN *sw) { int k; SW_SOILWAT_OUTPUTS *vo = sw->SoilWat.p_oagg[pd]; - SW_GEN_OUT *go = &sw->GenOutput; + SW_OUT_RUN *OutRun = &sw->OutRun; char str[OUTSTRLEN]; - go->sw_outstr[0] = '\0'; + OutRun->sw_outstr[0] = '\0'; snprintf( - go->sw_outstr, - sizeof go->sw_outstr, + OutRun->sw_outstr, + sizeof OutRun->sw_outstr, "%c%.*f", _OUTSEP, OUT_DIGITS, @@ -2464,7 +2738,7 @@ void get_evapSurface_text(OutPeriod pd, SW_RUN *sw) { snprintf( str, OUTSTRLEN, "%c%.*f", _OUTSEP, OUT_DIGITS, vo->evap_veg[k] ); - strcat(go->sw_outstr, str); + strcat(OutRun->sw_outstr, str); } snprintf( @@ -2478,7 +2752,7 @@ void get_evapSurface_text(OutPeriod pd, SW_RUN *sw) { OUT_DIGITS, vo->surfaceWater_evap ); - strcat(go->sw_outstr, str); + strcat(OutRun->sw_outstr, str); } #endif @@ -2490,27 +2764,30 @@ void get_evapSurface_text(OutPeriod pd, SW_RUN *sw) { @param[in] pd Time period in simulation output (day/week/month/year) @param[in] sw Comprehensive struct of type SW_RUN containing all information in the simulation. +@param[in] OutDom Struct of type SW_OUT_DOM that holds output + information that do not change throughout simulation runs */ -void get_evapSurface_mem(OutPeriod pd, SW_RUN *sw) { +void get_evapSurface_mem(OutPeriod pd, SW_RUN *sw, SW_OUT_DOM *OutDom) { int k; SW_SOILWAT_OUTPUTS *vo = sw->SoilWat.p_oagg[pd]; size_t iOUTIndex = 0; - SW_GEN_OUT *go = &sw->GenOutput; + SW_OUT_RUN *OutRun = &sw->OutRun; - RealD *p = go->p_OUT[eSW_EvapSurface][pd]; + RealD *p = OutRun->p_OUT[eSW_EvapSurface][pd]; #if defined(RSOILWAT) get_outvalleader( - &sw->Model, pd, go->irow_OUT, go->nrow_OUT, go->tOffset, p + &sw->Model, pd, OutRun->irow_OUT, OutRun->nrow_OUT, OutRun->tOffset, p ); #endif #if defined(RSOILWAT) - iOUTIndex = iOUT(0, go->irow_OUT[pd], go->nrow_OUT[pd], ncol_TimeOUT[pd]); + iOUTIndex = + iOUT(0, OutRun->irow_OUT[pd], OutDom->nrow_OUT[pd], ncol_TimeOUT[pd]); #elif defined(SWNETCDF) - iOUTIndex = go->iOUToffset[eSW_EvapSurface][pd][0] + - iOUTnc(go->irow_OUT[pd], 0, 0, 1, 1); + iOUTIndex = OutDom->iOUToffset[eSW_EvapSurface][pd][0] + + iOUTnc(OutRun->irow_OUT[pd], 0, 0, 1, 1); #endif p[iOUTIndex] = vo->total_evap; @@ -2518,13 +2795,19 @@ void get_evapSurface_mem(OutPeriod pd, SW_RUN *sw) { ForEachVegType(k) { #if defined(RSOILWAT) - iOUTIndex = - iOUT(k + 1, go->irow_OUT[pd], go->nrow_OUT[pd], ncol_TimeOUT[pd]); + iOUTIndex = iOUT( + k + 1, OutRun->irow_OUT[pd], OutDom->nrow_OUT[pd], ncol_TimeOUT[pd] + ); #elif defined(SWNETCDF) - iOUTIndex = - go->iOUToffset[eSW_EvapSurface][pd][1] + - iOUTnc(go->irow_OUT[pd], 0, k, 1, go->npft_OUT[eSW_EvapSurface][1]); + iOUTIndex = OutDom->iOUToffset[eSW_EvapSurface][pd][1] + + iOUTnc( + OutRun->irow_OUT[pd], + 0, + k, + 1, + OutDom->npft_OUT[eSW_EvapSurface][1] + ); #endif p[iOUTIndex] = vo->evap_veg[k]; @@ -2533,12 +2816,15 @@ void get_evapSurface_mem(OutPeriod pd, SW_RUN *sw) { #if defined(RSOILWAT) iOUTIndex = iOUT( - NVEGTYPES + 1, go->irow_OUT[pd], go->nrow_OUT[pd], ncol_TimeOUT[pd] + NVEGTYPES + 1, + OutRun->irow_OUT[pd], + OutDom->nrow_OUT[pd], + ncol_TimeOUT[pd] ); #elif defined(SWNETCDF) - iOUTIndex = go->iOUToffset[eSW_EvapSurface][pd][2] + - iOUTnc(go->irow_OUT[pd], 0, 0, 1, 1); + iOUTIndex = OutDom->iOUToffset[eSW_EvapSurface][pd][2] + + iOUTnc(OutRun->irow_OUT[pd], 0, 0, 1, 1); #endif p[iOUTIndex] = vo->litter_evap; @@ -2546,12 +2832,15 @@ void get_evapSurface_mem(OutPeriod pd, SW_RUN *sw) { #if defined(RSOILWAT) iOUTIndex = iOUT( - NVEGTYPES + 2, go->irow_OUT[pd], go->nrow_OUT[pd], ncol_TimeOUT[pd] + NVEGTYPES + 2, + OutRun->irow_OUT[pd], + OutDom->nrow_OUT[pd], + ncol_TimeOUT[pd] ); #elif defined(SWNETCDF) - iOUTIndex = go->iOUToffset[eSW_EvapSurface][pd][3] + - iOUTnc(go->irow_OUT[pd], 0, 0, 1, 1); + iOUTIndex = OutDom->iOUToffset[eSW_EvapSurface][pd][3] + + iOUTnc(OutRun->irow_OUT[pd], 0, 0, 1, 1); #endif p[iOUTIndex] = vo->surfaceWater_evap; @@ -2565,38 +2854,50 @@ void get_evapSurface_mem(OutPeriod pd, SW_RUN *sw) { @param[in] pd Time period in simulation output (day/week/month/year) @param[in] sw Comprehensive struct of type SW_RUN containing all information in the simulation. +@param[in] OutDom Struct of type SW_OUT_DOM that holds output + information that do not change throughout simulation runs */ -void get_evapSurface_agg(OutPeriod pd, SW_RUN *sw) { +void get_evapSurface_agg(OutPeriod pd, SW_RUN *sw, SW_OUT_DOM *OutDom) { int k; SW_SOILWAT_OUTPUTS *vo = sw->SoilWat.p_oagg[pd]; size_t iOUTIndex = 0; - SW_GEN_OUT *go = &sw->GenOutput; + SW_OUT_RUN *OutRun = &sw->OutRun; - RealD *p = go->p_OUT[eSW_EvapSurface][pd], - *psd = go->p_OUTsd[eSW_EvapSurface][pd]; + RealD *p = OutRun->p_OUT[eSW_EvapSurface][pd], + *psd = OutRun->p_OUTsd[eSW_EvapSurface][pd]; - iOUTIndex = iOUT(0, go->irow_OUT[pd], go->nrow_OUT[pd], ncol_TimeOUT[pd]); - do_running_agg(p, psd, iOUTIndex, go->currIter, vo->total_evap); + iOUTIndex = + iOUT(0, OutRun->irow_OUT[pd], OutDom->nrow_OUT[pd], ncol_TimeOUT[pd]); + do_running_agg(p, psd, iOUTIndex, OutRun->currIter, vo->total_evap); ForEachVegType(k) { - iOUTIndex = - iOUT(k + 1, go->irow_OUT[pd], go->nrow_OUT[pd], ncol_TimeOUT[pd]); - do_running_agg(p, psd, iOUTIndex, go->currIter, vo->evap_veg[k]); + iOUTIndex = iOUT( + k + 1, OutRun->irow_OUT[pd], OutDom->nrow_OUT[pd], ncol_TimeOUT[pd] + ); + do_running_agg(p, psd, iOUTIndex, OutRun->currIter, vo->evap_veg[k]); } iOUTIndex = iOUT( - NVEGTYPES + 1, go->irow_OUT[pd], go->nrow_OUT[pd], ncol_TimeOUT[pd] + NVEGTYPES + 1, + OutRun->irow_OUT[pd], + OutDom->nrow_OUT[pd], + ncol_TimeOUT[pd] ); - do_running_agg(p, psd, iOUTIndex, go->currIter, vo->litter_evap); + do_running_agg(p, psd, iOUTIndex, OutRun->currIter, vo->litter_evap); iOUTIndex = iOUT( - NVEGTYPES + 2, go->irow_OUT[pd], go->nrow_OUT[pd], ncol_TimeOUT[pd] + NVEGTYPES + 2, + OutRun->irow_OUT[pd], + OutDom->nrow_OUT[pd], + ncol_TimeOUT[pd] ); - do_running_agg(p, psd, iOUTIndex, go->currIter, vo->surfaceWater_evap); + do_running_agg(p, psd, iOUTIndex, OutRun->currIter, vo->surfaceWater_evap); - if (go->print_IterationSummary) { - go->sw_outstr_agg[0] = '\0'; - format_IterationSummary(p, psd, pd, go->ncol_OUT[eSW_EvapSurface], sw); + if (OutRun->print_IterationSummary) { + OutRun->sw_outstr_agg[0] = '\0'; + format_IterationSummary( + p, psd, pd, OutRun->ncol_OUT[eSW_EvapSurface], sw + ); } } #endif @@ -2610,18 +2911,20 @@ void get_evapSurface_agg(OutPeriod pd, SW_RUN *sw) { @param[in] pd Time period in simulation output (day/week/month/year) @param[in] sw Comprehensive struct of type SW_RUN containing all information in the simulation. +@param[in] OutDom Struct of type SW_OUT_DOM that holds output + information that do not change throughout simulation runs */ void get_interception_text(OutPeriod pd, SW_RUN *sw) { int k; SW_SOILWAT_OUTPUTS *vo = sw->SoilWat.p_oagg[pd]; - SW_GEN_OUT *go = &sw->GenOutput; + SW_OUT_RUN *OutRun = &sw->OutRun; char str[OUTSTRLEN]; - go->sw_outstr[0] = '\0'; + OutRun->sw_outstr[0] = '\0'; snprintf( - go->sw_outstr, - sizeof go->sw_outstr, + OutRun->sw_outstr, + sizeof OutRun->sw_outstr, "%c%.*f", _OUTSEP, OUT_DIGITS, @@ -2630,11 +2933,11 @@ void get_interception_text(OutPeriod pd, SW_RUN *sw) { ForEachVegType(k) { snprintf(str, OUTSTRLEN, "%c%.*f", _OUTSEP, OUT_DIGITS, vo->int_veg[k]); - strcat(go->sw_outstr, str); + strcat(OutRun->sw_outstr, str); } snprintf(str, OUTSTRLEN, "%c%.*f", _OUTSEP, OUT_DIGITS, vo->litter_int); - strcat(go->sw_outstr, str); + strcat(OutRun->sw_outstr, str); } #endif @@ -2646,27 +2949,30 @@ void get_interception_text(OutPeriod pd, SW_RUN *sw) { @param[in] pd Time period in simulation output (day/week/month/year) @param[in] sw Comprehensive struct of type SW_RUN containing all information in the simulation. +@param[in] OutDom Struct of type SW_OUT_DOM that holds output + information that do not change throughout simulation runs */ -void get_interception_mem(OutPeriod pd, SW_RUN *sw) { +void get_interception_mem(OutPeriod pd, SW_RUN *sw, SW_OUT_DOM *OutDom) { int k; SW_SOILWAT_OUTPUTS *vo = sw->SoilWat.p_oagg[pd]; size_t iOUTIndex = 0; - SW_GEN_OUT *go = &sw->GenOutput; + SW_OUT_RUN *OutRun = &sw->OutRun; - RealD *p = go->p_OUT[eSW_Interception][pd]; + RealD *p = OutRun->p_OUT[eSW_Interception][pd]; #if defined(RSOILWAT) get_outvalleader( - &sw->Model, pd, go->irow_OUT, go->nrow_OUT, go->tOffset, p + &sw->Model, pd, OutRun->irow_OUT, OutRun->nrow_OUT, OutRun->tOffset, p ); #endif #if defined(RSOILWAT) - iOUTIndex = iOUT(0, go->irow_OUT[pd], go->nrow_OUT[pd], ncol_TimeOUT[pd]); + iOUTIndex = + iOUT(0, OutRun->irow_OUT[pd], OutDom->nrow_OUT[pd], ncol_TimeOUT[pd]); #elif defined(SWNETCDF) - iOUTIndex = go->iOUToffset[eSW_Interception][pd][0] + - iOUTnc(go->irow_OUT[pd], 0, 0, 1, 1); + iOUTIndex = OutDom->iOUToffset[eSW_Interception][pd][0] + + iOUTnc(OutRun->irow_OUT[pd], 0, 0, 1, 1); #endif p[iOUTIndex] = vo->total_int; @@ -2674,15 +2980,19 @@ void get_interception_mem(OutPeriod pd, SW_RUN *sw) { ForEachVegType(k) { #if defined(RSOILWAT) - iOUTIndex = - iOUT(k + 1, go->irow_OUT[pd], go->nrow_OUT[pd], ncol_TimeOUT[pd]); + iOUTIndex = iOUT( + k + 1, OutRun->irow_OUT[pd], OutDom->nrow_OUT[pd], ncol_TimeOUT[pd] + ); #elif defined(SWNETCDF) - iOUTIndex = - go->iOUToffset[eSW_Interception][pd][1] + - iOUTnc( - go->irow_OUT[pd], 0, k, 1, go->npft_OUT[eSW_Interception][1] - ); + iOUTIndex = OutDom->iOUToffset[eSW_Interception][pd][1] + + iOUTnc( + OutRun->irow_OUT[pd], + 0, + k, + 1, + OutDom->npft_OUT[eSW_Interception][1] + ); #endif p[iOUTIndex] = vo->int_veg[k]; @@ -2691,12 +3001,15 @@ void get_interception_mem(OutPeriod pd, SW_RUN *sw) { #if defined(RSOILWAT) iOUTIndex = iOUT( - NVEGTYPES + 1, go->irow_OUT[pd], go->nrow_OUT[pd], ncol_TimeOUT[pd] + NVEGTYPES + 1, + OutRun->irow_OUT[pd], + OutDom->nrow_OUT[pd], + ncol_TimeOUT[pd] ); #elif defined(SWNETCDF) - iOUTIndex = go->iOUToffset[eSW_Interception][pd][2] + - iOUTnc(go->irow_OUT[pd], 0, 0, 1, 1); + iOUTIndex = OutDom->iOUToffset[eSW_Interception][pd][2] + + iOUTnc(OutRun->irow_OUT[pd], 0, 0, 1, 1); #endif p[iOUTIndex] = vo->litter_int; @@ -2710,33 +3023,42 @@ void get_interception_mem(OutPeriod pd, SW_RUN *sw) { @param[in] pd Time period in simulation output (day/week/month/year) @param[in] sw Comprehensive struct of type SW_RUN containing all information in the simulation. +@param[in] OutDom Struct of type SW_OUT_DOM that holds output + information that do not change throughout simulation runs */ -void get_interception_agg(OutPeriod pd, SW_RUN *sw) { +void get_interception_agg(OutPeriod pd, SW_RUN *sw, SW_OUT_DOM *OutDom) { int k; SW_SOILWAT_OUTPUTS *vo = sw->SoilWat.p_oagg[pd]; size_t iOUTIndex = 0; - SW_GEN_OUT *go = &sw->GenOutput; + SW_OUT_RUN *OutRun = &sw->OutRun; - RealD *p = go->p_OUT[eSW_Interception][pd], - *psd = go->p_OUTsd[eSW_Interception][pd]; + RealD *p = OutRun->p_OUT[eSW_Interception][pd], + *psd = OutRun->p_OUTsd[eSW_Interception][pd]; - iOUTIndex = iOUT(0, go->irow_OUT[pd], go->nrow_OUT[pd], ncol_TimeOUT[pd]); - do_running_agg(p, psd, iOUTIndex, go->currIter, vo->total_int); + iOUTIndex = + iOUT(0, OutRun->irow_OUT[pd], OutDom->nrow_OUT[pd], ncol_TimeOUT[pd]); + do_running_agg(p, psd, iOUTIndex, OutRun->currIter, vo->total_int); ForEachVegType(k) { - iOUTIndex = - iOUT(k + 1, go->irow_OUT[pd], go->nrow_OUT[pd], ncol_TimeOUT[pd]); - do_running_agg(p, psd, iOUTIndex, go->currIter, vo->int_veg[k]); + iOUTIndex = iOUT( + k + 1, OutRun->irow_OUT[pd], OutDom->nrow_OUT[pd], ncol_TimeOUT[pd] + ); + do_running_agg(p, psd, iOUTIndex, OutRun->currIter, vo->int_veg[k]); } iOUTIndex = iOUT( - NVEGTYPES + 1, go->irow_OUT[pd], go->nrow_OUT[pd], ncol_TimeOUT[pd] + NVEGTYPES + 1, + OutRun->irow_OUT[pd], + OutDom->nrow_OUT[pd], + ncol_TimeOUT[pd] ); - do_running_agg(p, psd, iOUTIndex, go->currIter, vo->litter_int); + do_running_agg(p, psd, iOUTIndex, OutRun->currIter, vo->litter_int); - if (go->print_IterationSummary) { - go->sw_outstr_agg[0] = '\0'; - format_IterationSummary(p, psd, pd, go->ncol_OUT[eSW_Interception], sw); + if (OutRun->print_IterationSummary) { + OutRun->sw_outstr_agg[0] = '\0'; + format_IterationSummary( + p, psd, pd, OutRun->ncol_OUT[eSW_Interception], sw + ); } } #endif @@ -2750,6 +3072,8 @@ void get_interception_agg(OutPeriod pd, SW_RUN *sw) { @param[in] pd Time period in simulation output (day/week/month/year) @param[in] sw Comprehensive struct of type SW_RUN containing all information in the simulation. +@param[in] OutDom Struct of type SW_OUT_DOM that holds output + information that do not change throughout simulation runs */ void get_soilinf_text(OutPeriod pd, SW_RUN *sw) { /* 20100202 (drs) added */ @@ -2757,12 +3081,12 @@ void get_soilinf_text(OutPeriod pd, SW_RUN *sw) { /* 12/13/2012 (clk) moved runoff, now named snowRunoff, to * get_runoffrunon(); */ SW_WEATHER_OUTPUTS *vo = sw->Weather.p_oagg[pd]; - SW_GEN_OUT *go = &sw->GenOutput; + SW_OUT_RUN *OutRun = &sw->OutRun; - go->sw_outstr[0] = '\0'; + OutRun->sw_outstr[0] = '\0'; snprintf( - go->sw_outstr, - sizeof go->sw_outstr, + OutRun->sw_outstr, + sizeof OutRun->sw_outstr, "%c%.*f", _OUTSEP, OUT_DIGITS, @@ -2779,26 +3103,29 @@ void get_soilinf_text(OutPeriod pd, SW_RUN *sw) { @param[in] pd Time period in simulation output (day/week/month/year) @param[in] sw Comprehensive struct of type SW_RUN containing all information in the simulation. +@param[in] OutDom Struct of type SW_OUT_DOM that holds output + information that do not change throughout simulation runs */ -void get_soilinf_mem(OutPeriod pd, SW_RUN *sw) { +void get_soilinf_mem(OutPeriod pd, SW_RUN *sw, SW_OUT_DOM *OutDom) { SW_WEATHER_OUTPUTS *vo = sw->Weather.p_oagg[pd]; size_t iOUTIndex = 0; - SW_GEN_OUT *go = &sw->GenOutput; + SW_OUT_RUN *OutRun = &sw->OutRun; - RealD *p = go->p_OUT[eSW_SoilInf][pd]; + RealD *p = OutRun->p_OUT[eSW_SoilInf][pd]; #if defined(RSOILWAT) get_outvalleader( - &sw->Model, pd, go->irow_OUT, go->nrow_OUT, go->tOffset, p + &sw->Model, pd, OutRun->irow_OUT, OutRun->nrow_OUT, OutRun->tOffset, p ); #endif #if defined(RSOILWAT) - iOUTIndex = iOUT(0, go->irow_OUT[pd], go->nrow_OUT[pd], ncol_TimeOUT[pd]); + iOUTIndex = + iOUT(0, OutRun->irow_OUT[pd], OutDom->nrow_OUT[pd], ncol_TimeOUT[pd]); #elif defined(SWNETCDF) - iOUTIndex = go->iOUToffset[eSW_SoilInf][pd][0] + - iOUTnc(go->irow_OUT[pd], 0, 0, 1, 1); + iOUTIndex = OutDom->iOUToffset[eSW_SoilInf][pd][0] + + iOUTnc(OutRun->irow_OUT[pd], 0, 0, 1, 1); #endif p[iOUTIndex] = vo->soil_inf; @@ -2812,20 +3139,24 @@ void get_soilinf_mem(OutPeriod pd, SW_RUN *sw) { @param[in] pd Time period in simulation output (day/week/month/year) @param[in] sw Comprehensive struct of type SW_RUN containing all information in the simulation. +@param[in] OutDom Struct of type SW_OUT_DOM that holds output + information that do not change throughout simulation runs */ -void get_soilinf_agg(OutPeriod pd, SW_RUN *sw) { +void get_soilinf_agg(OutPeriod pd, SW_RUN *sw, SW_OUT_DOM *OutDom) { SW_WEATHER_OUTPUTS *vo = sw->Weather.p_oagg[pd]; size_t iOUTIndex = 0; - SW_GEN_OUT *go = &sw->GenOutput; + SW_OUT_RUN *OutRun = &sw->OutRun; - RealD *p = go->p_OUT[eSW_SoilInf][pd], *psd = go->p_OUTsd[eSW_SoilInf][pd]; + RealD *p = OutRun->p_OUT[eSW_SoilInf][pd], + *psd = OutRun->p_OUTsd[eSW_SoilInf][pd]; - iOUTIndex = iOUT(0, go->irow_OUT[pd], go->nrow_OUT[pd], ncol_TimeOUT[pd]); - do_running_agg(p, psd, iOUTIndex, go->currIter, vo->soil_inf); + iOUTIndex = + iOUT(0, OutRun->irow_OUT[pd], OutDom->nrow_OUT[pd], ncol_TimeOUT[pd]); + do_running_agg(p, psd, iOUTIndex, OutRun->currIter, vo->soil_inf); - if (go->print_IterationSummary) { - go->sw_outstr_agg[0] = '\0'; - format_IterationSummary(p, psd, pd, go->ncol_OUT[eSW_SoilInf], sw); + if (OutRun->print_IterationSummary) { + OutRun->sw_outstr_agg[0] = '\0'; + format_IterationSummary(p, psd, pd, OutRun->ncol_OUT[eSW_SoilInf], sw); } } #endif @@ -2840,21 +3171,23 @@ void get_soilinf_agg(OutPeriod pd, SW_RUN *sw) { @param[in] pd Time period in simulation output (day/week/month/year) @param[in] sw Comprehensive struct of type SW_RUN containing all information in the simulation. +@param[in] OutDom Struct of type SW_OUT_DOM that holds output + information that do not change throughout simulation runs */ void get_lyrdrain_text(OutPeriod pd, SW_RUN *sw) { /* 20100202 (drs) added */ LyrIndex i; SW_SOILWAT_OUTPUTS *vo = sw->SoilWat.p_oagg[pd]; - SW_GEN_OUT *go = &sw->GenOutput; + SW_OUT_RUN *OutRun = &sw->OutRun; char str[OUTSTRLEN]; - go->sw_outstr[0] = '\0'; + OutRun->sw_outstr[0] = '\0'; for (i = 0; i < sw->Site.n_layers - 1; i++) { snprintf( str, OUTSTRLEN, "%c%.*f", _OUTSEP, OUT_DIGITS, vo->lyrdrain[i] ); - strcat(go->sw_outstr, str); + strcat(OutRun->sw_outstr, str); } } #endif @@ -2867,30 +3200,35 @@ void get_lyrdrain_text(OutPeriod pd, SW_RUN *sw) { @param[in] pd Time period in simulation output (day/week/month/year) @param[in] sw Comprehensive struct of type SW_RUN containing all information in the simulation. +@param[in] OutDom Struct of type SW_OUT_DOM that holds output + information that do not change throughout simulation runs */ -void get_lyrdrain_mem(OutPeriod pd, SW_RUN *sw) { +void get_lyrdrain_mem(OutPeriod pd, SW_RUN *sw, SW_OUT_DOM *OutDom) { LyrIndex i; SW_SOILWAT_OUTPUTS *vo = sw->SoilWat.p_oagg[pd]; size_t iOUTIndex = 0; - SW_GEN_OUT *go = &sw->GenOutput; + SW_OUT_RUN *OutRun = &sw->OutRun; - RealD *p = go->p_OUT[eSW_LyrDrain][pd]; + RealD *p = OutRun->p_OUT[eSW_LyrDrain][pd]; #if defined(RSOILWAT) get_outvalleader( - &sw->Model, pd, go->irow_OUT, go->nrow_OUT, go->tOffset, p + &sw->Model, pd, OutRun->irow_OUT, OutRun->nrow_OUT, OutRun->tOffset, p ); #endif for (i = 0; i < sw->Site.n_layers - 1; i++) { #if defined(RSOILWAT) - iOUTIndex = - iOUT(i, go->irow_OUT[pd], go->nrow_OUT[pd], ncol_TimeOUT[pd]); + iOUTIndex = iOUT( + i, OutRun->irow_OUT[pd], OutDom->nrow_OUT[pd], ncol_TimeOUT[pd] + ); #elif defined(SWNETCDF) iOUTIndex = - go->iOUToffset[eSW_LyrDrain][pd][0] + - iOUTnc(go->irow_OUT[pd], i, 0, go->nsl_OUT[eSW_LyrDrain][0], 1); + OutDom->iOUToffset[eSW_LyrDrain][pd][0] + + iOUTnc( + OutRun->irow_OUT[pd], i, 0, OutDom->nsl_OUT[eSW_LyrDrain][0], 1 + ); #endif p[iOUTIndex] = vo->lyrdrain[i]; @@ -2898,10 +3236,12 @@ void get_lyrdrain_mem(OutPeriod pd, SW_RUN *sw) { #if defined(SWNETCDF) /* Set extra soil layers to missing/fill value (up to domain-wide max) */ - for (i = sw->Site.n_layers - 1; i < go->nsl_OUT[eSW_LyrDrain][0]; i++) { + for (i = sw->Site.n_layers - 1; i < OutDom->nsl_OUT[eSW_LyrDrain][0]; i++) { iOUTIndex = - go->iOUToffset[eSW_LyrDrain][pd][0] + - iOUTnc(go->irow_OUT[pd], i, 0, go->nsl_OUT[eSW_LyrDrain][0], 1); + OutDom->iOUToffset[eSW_LyrDrain][pd][0] + + iOUTnc( + OutRun->irow_OUT[pd], i, 0, OutDom->nsl_OUT[eSW_LyrDrain][0], 1 + ); p[iOUTIndex] = NC_FILL_DOUBLE; } #endif // SWNETCDF @@ -2915,25 +3255,28 @@ void get_lyrdrain_mem(OutPeriod pd, SW_RUN *sw) { @param[in] pd Time period in simulation output (day/week/month/year) @param[in] sw Comprehensive struct of type SW_RUN containing all information in the simulation. +@param[in] OutDom Struct of type SW_OUT_DOM that holds output + information that do not change throughout simulation runs */ -void get_lyrdrain_agg(OutPeriod pd, SW_RUN *sw) { +void get_lyrdrain_agg(OutPeriod pd, SW_RUN *sw, SW_OUT_DOM *OutDom) { LyrIndex i; SW_SOILWAT_OUTPUTS *vo = sw->SoilWat.p_oagg[pd]; size_t iOUTIndex = 0; - SW_GEN_OUT *go = &sw->GenOutput; + SW_OUT_RUN *OutRun = &sw->OutRun; - RealD *p = go->p_OUT[eSW_LyrDrain][pd], - *psd = go->p_OUTsd[eSW_LyrDrain][pd]; + RealD *p = OutRun->p_OUT[eSW_LyrDrain][pd], + *psd = OutRun->p_OUTsd[eSW_LyrDrain][pd]; for (i = 0; i < sw->Site.n_layers - 1; i++) { - iOUTIndex = - iOUT(i, go->irow_OUT[pd], go->nrow_OUT[pd], ncol_TimeOUT[pd]); - do_running_agg(p, psd, iOUTIndex, go->currIter, vo->lyrdrain[i]); + iOUTIndex = iOUT( + i, OutRun->irow_OUT[pd], OutDom->nrow_OUT[pd], ncol_TimeOUT[pd] + ); + do_running_agg(p, psd, iOUTIndex, OutRun->currIter, vo->lyrdrain[i]); } - if (go->print_IterationSummary) { - go->sw_outstr_agg[0] = '\0'; - format_IterationSummary(p, psd, pd, go->ncol_OUT[eSW_LyrDrain], sw); + if (OutRun->print_IterationSummary) { + OutRun->sw_outstr_agg[0] = '\0'; + format_IterationSummary(p, psd, pd, OutRun->ncol_OUT[eSW_LyrDrain], sw); } } #endif @@ -2948,23 +3291,25 @@ void get_lyrdrain_agg(OutPeriod pd, SW_RUN *sw) { @param[in] pd Time period in simulation output (day/week/month/year) @param[in] sw Comprehensive struct of type SW_RUN containing all information in the simulation. +@param[in] OutDom Struct of type SW_OUT_DOM that holds output + information that do not change throughout simulation runs */ void get_hydred_text(OutPeriod pd, SW_RUN *sw) { /* 20101020 (drs) added */ LyrIndex i, n_layers = sw->Site.n_layers; int k; SW_SOILWAT_OUTPUTS *vo = sw->SoilWat.p_oagg[pd]; - SW_GEN_OUT *go = &sw->GenOutput; + SW_OUT_RUN *OutRun = &sw->OutRun; char str[OUTSTRLEN]; - go->sw_outstr[0] = '\0'; + OutRun->sw_outstr[0] = '\0'; /* total hydraulic redistribution */ ForEachSoilLayer(i, n_layers) { snprintf( str, OUTSTRLEN, "%c%.*f", _OUTSEP, OUT_DIGITS, vo->hydred_total[i] ); - strcat(go->sw_outstr, str); + strcat(OutRun->sw_outstr, str); } /* hydraulic redistribution for each vegetation type */ @@ -2973,7 +3318,7 @@ void get_hydred_text(OutPeriod pd, SW_RUN *sw) { snprintf( str, OUTSTRLEN, "%c%.*f", _OUTSEP, OUT_DIGITS, vo->hydred[k][i] ); - strcat(go->sw_outstr, str); + strcat(OutRun->sw_outstr, str); } } } @@ -2987,32 +3332,37 @@ void get_hydred_text(OutPeriod pd, SW_RUN *sw) { @param[in] pd Time period in simulation output (day/week/month/year) @param[in] sw Comprehensive struct of type SW_RUN containing all information in the simulation. +@param[in] OutDom Struct of type SW_OUT_DOM that holds output + information that do not change throughout simulation runs */ -void get_hydred_mem(OutPeriod pd, SW_RUN *sw) { +void get_hydred_mem(OutPeriod pd, SW_RUN *sw, SW_OUT_DOM *OutDom) { LyrIndex i, n_layers = sw->Site.n_layers; int k; SW_SOILWAT_OUTPUTS *vo = sw->SoilWat.p_oagg[pd]; size_t iOUTIndex = 0; - SW_GEN_OUT *go = &sw->GenOutput; + SW_OUT_RUN *OutRun = &sw->OutRun; - RealD *p = go->p_OUT[eSW_HydRed][pd]; + RealD *p = OutRun->p_OUT[eSW_HydRed][pd]; #if defined(RSOILWAT) get_outvalleader( - &sw->Model, pd, go->irow_OUT, go->nrow_OUT, go->tOffset, p + &sw->Model, pd, OutRun->irow_OUT, OutRun->nrow_OUT, OutRun->tOffset, p ); #endif /* total hydraulic redistribution */ ForEachSoilLayer(i, n_layers) { #if defined(RSOILWAT) - iOUTIndex = - iOUT(i, go->irow_OUT[pd], go->nrow_OUT[pd], ncol_TimeOUT[pd]); + iOUTIndex = iOUT( + i, OutRun->irow_OUT[pd], OutDom->nrow_OUT[pd], ncol_TimeOUT[pd] + ); #elif defined(SWNETCDF) iOUTIndex = - go->iOUToffset[eSW_HydRed][pd][0] + - iOUTnc(go->irow_OUT[pd], i, 0, go->nsl_OUT[eSW_HydRed][0], 1); + OutDom->iOUToffset[eSW_HydRed][pd][0] + + iOUTnc( + OutRun->irow_OUT[pd], i, 0, OutDom->nsl_OUT[eSW_HydRed][0], 1 + ); #endif p[iOUTIndex] = vo->hydred_total[i]; @@ -3020,10 +3370,12 @@ void get_hydred_mem(OutPeriod pd, SW_RUN *sw) { #if defined(SWNETCDF) /* Set extra soil layers to missing/fill value (up to domain-wide max) */ - for (i = sw->Site.n_layers; i < go->nsl_OUT[eSW_HydRed][0]; i++) { + for (i = sw->Site.n_layers; i < OutDom->nsl_OUT[eSW_HydRed][0]; i++) { iOUTIndex = - go->iOUToffset[eSW_HydRed][pd][0] + - iOUTnc(go->irow_OUT[pd], i, 0, go->nsl_OUT[eSW_HydRed][0], 1); + OutDom->iOUToffset[eSW_HydRed][pd][0] + + iOUTnc( + OutRun->irow_OUT[pd], i, 0, OutDom->nsl_OUT[eSW_HydRed][0], 1 + ); p[iOUTIndex] = NC_FILL_DOUBLE; } #endif // SWNETCDF @@ -3035,17 +3387,22 @@ void get_hydred_mem(OutPeriod pd, SW_RUN *sw) { #if defined(RSOILWAT) // k + 1 because of total hydred iOUTIndex = iOUT2( - i, k + 1, pd, go->irow_OUT, go->nrow_OUT, sw->Site.n_layers + i, + k + 1, + pd, + OutRun->irow_OUT, + OutRun->nrow_OUT, + sw->Site.n_layers ); #elif defined(SWNETCDF) - iOUTIndex = go->iOUToffset[eSW_HydRed][pd][1] + + iOUTIndex = OutDom->iOUToffset[eSW_HydRed][pd][1] + iOUTnc( - go->irow_OUT[pd], + OutRun->irow_OUT[pd], i, k, - go->nsl_OUT[eSW_HydRed][1], - go->npft_OUT[eSW_HydRed][1] + OutDom->nsl_OUT[eSW_HydRed][1], + OutDom->npft_OUT[eSW_HydRed][1] ); #endif @@ -3055,14 +3412,14 @@ void get_hydred_mem(OutPeriod pd, SW_RUN *sw) { #if defined(SWNETCDF) /* Set extra soil layers to missing/fill value (up to domain-wide max) */ - for (i = sw->Site.n_layers; i < go->nsl_OUT[eSW_HydRed][0]; i++) { - iOUTIndex = go->iOUToffset[eSW_HydRed][pd][1] + + for (i = sw->Site.n_layers; i < OutDom->nsl_OUT[eSW_HydRed][0]; i++) { + iOUTIndex = OutDom->iOUToffset[eSW_HydRed][pd][1] + iOUTnc( - go->irow_OUT[pd], + OutRun->irow_OUT[pd], i, k, - go->nsl_OUT[eSW_HydRed][1], - go->npft_OUT[eSW_HydRed][1] + OutDom->nsl_OUT[eSW_HydRed][1], + OutDom->npft_OUT[eSW_HydRed][1] ); p[iOUTIndex] = NC_FILL_DOUBLE; } @@ -3078,25 +3435,31 @@ void get_hydred_mem(OutPeriod pd, SW_RUN *sw) { @param[in] pd Time period in simulation output (day/week/month/year) @param[in] sw Comprehensive struct of type SW_RUN containing all information in the simulation. +@param[in] OutDom Struct of type SW_OUT_DOM that holds output + information that do not change throughout simulation runs */ -void get_hydred_agg(OutPeriod pd, SW_RUN *sw) { +void get_hydred_agg(OutPeriod pd, SW_RUN *sw, SW_OUT_DOM *OutDom) { LyrIndex i, n_layers = sw->Site.n_layers; int k; SW_SOILWAT_OUTPUTS *vo = sw->SoilWat.p_oagg[pd]; size_t iOUTIndex = 0; - SW_GEN_OUT *go = &sw->GenOutput; + SW_OUT_RUN *OutRun = &sw->OutRun; - RealD *p = go->p_OUT[eSW_HydRed][pd], *psd = go->p_OUTsd[eSW_HydRed][pd]; + RealD *p = OutRun->p_OUT[eSW_HydRed][pd], + *psd = OutRun->p_OUTsd[eSW_HydRed][pd]; /* total hydraulic redistribution */ ForEachSoilLayer(i, n_layers) { - iOUTIndex = - iOUT(i, go->irow_OUT[pd], go->nrow_OUT[pd], ncol_TimeOUT[pd]); - do_running_agg(p, psd, iOUTIndex, go->currIter, vo->hydred_total[i]); + iOUTIndex = iOUT( + i, OutRun->irow_OUT[pd], OutDom->nrow_OUT[pd], ncol_TimeOUT[pd] + ); + do_running_agg( + p, psd, iOUTIndex, OutRun->currIter, vo->hydred_total[i] + ); } - if (go->print_IterationSummary) { - go->sw_outstr_agg[0] = '\0'; + if (OutRun->print_IterationSummary) { + OutRun->sw_outstr_agg[0] = '\0'; format_IterationSummary(p, psd, pd, n_layers, sw); } @@ -3104,13 +3467,16 @@ void get_hydred_agg(OutPeriod pd, SW_RUN *sw) { ForEachVegType(k) { ForEachSoilLayer(i, n_layers) { // k + 1 because of total hydred - iOUTIndex = - iOUT2(i, k + 1, pd, go->irow_OUT, go->nrow_OUT, n_layers); - do_running_agg(p, psd, iOUTIndex, go->currIter, vo->hydred[k][i]); + iOUTIndex = iOUT2( + i, k + 1, pd, OutRun->irow_OUT, OutRun->nrow_OUT, n_layers + ); + do_running_agg( + p, psd, iOUTIndex, OutRun->currIter, vo->hydred[k][i] + ); } } - if (go->print_IterationSummary) { + if (OutRun->print_IterationSummary) { format_IterationSummary2(p, psd, pd, NVEGTYPES, 1, sw); } } @@ -3126,16 +3492,18 @@ void get_hydred_agg(OutPeriod pd, SW_RUN *sw) { @param[in] pd Time period in simulation output (day/week/month/year) @param[in] sw Comprehensive struct of type SW_RUN containing all information in the simulation. +@param[in] OutDom Struct of type SW_OUT_DOM that holds output + information that do not change throughout simulation runs */ void get_aet_text(OutPeriod pd, SW_RUN *sw) { SW_SOILWAT_OUTPUTS *vo = sw->SoilWat.p_oagg[pd]; SW_WEATHER_OUTPUTS *vo2 = sw->Weather.p_oagg[pd]; - SW_GEN_OUT *go = &sw->GenOutput; + SW_OUT_RUN *OutRun = &sw->OutRun; - go->sw_outstr[0] = '\0'; + OutRun->sw_outstr[0] = '\0'; snprintf( - go->sw_outstr, - sizeof go->sw_outstr, + OutRun->sw_outstr, + sizeof OutRun->sw_outstr, "%c%.*f%c%.*f%c%.*f%c%.*f%c%.*f%c%.*f", _OUTSEP, OUT_DIGITS, @@ -3167,82 +3535,90 @@ void get_aet_text(OutPeriod pd, SW_RUN *sw) { @param[in] pd Time period in simulation output (day/week/month/year) @param[in] sw Comprehensive struct of type SW_RUN containing all information in the simulation. +@param[in] OutDom Struct of type SW_OUT_DOM that holds output + information that do not change throughout simulation runs */ -void get_aet_mem(OutPeriod pd, SW_RUN *sw) { +void get_aet_mem(OutPeriod pd, SW_RUN *sw, SW_OUT_DOM *OutDom) { SW_SOILWAT_OUTPUTS *vo = sw->SoilWat.p_oagg[pd]; SW_WEATHER_OUTPUTS *vo2 = sw->Weather.p_oagg[pd]; size_t iOUTIndex = 0; - SW_GEN_OUT *go = &sw->GenOutput; + SW_OUT_RUN *OutRun = &sw->OutRun; - RealD *p = go->p_OUT[eSW_AET][pd]; + RealD *p = OutRun->p_OUT[eSW_AET][pd]; #if defined(RSOILWAT) get_outvalleader( - &sw->Model, pd, go->irow_OUT, go->nrow_OUT, go->tOffset, p + &sw->Model, pd, OutRun->irow_OUT, OutRun->nrow_OUT, OutRun->tOffset, p ); #endif #if defined(RSOILWAT) - iOUTIndex = iOUT(0, go->irow_OUT[pd], go->nrow_OUT[pd], ncol_TimeOUT[pd]); + iOUTIndex = + iOUT(0, OutRun->irow_OUT[pd], OutDom->nrow_OUT[pd], ncol_TimeOUT[pd]); #elif defined(SWNETCDF) - iOUTIndex = - go->iOUToffset[eSW_AET][pd][0] + iOUTnc(go->irow_OUT[pd], 0, 0, 1, 1); + iOUTIndex = OutDom->iOUToffset[eSW_AET][pd][0] + + iOUTnc(OutRun->irow_OUT[pd], 0, 0, 1, 1); #endif p[iOUTIndex] = vo->aet; #if defined(RSOILWAT) - iOUTIndex = iOUT(1, go->irow_OUT[pd], go->nrow_OUT[pd], ncol_TimeOUT[pd]); + iOUTIndex = + iOUT(1, OutRun->irow_OUT[pd], OutDom->nrow_OUT[pd], ncol_TimeOUT[pd]); #elif defined(SWNETCDF) - iOUTIndex = - go->iOUToffset[eSW_AET][pd][1] + iOUTnc(go->irow_OUT[pd], 0, 0, 1, 1); + iOUTIndex = OutDom->iOUToffset[eSW_AET][pd][1] + + iOUTnc(OutRun->irow_OUT[pd], 0, 0, 1, 1); #endif p[iOUTIndex] = vo->tran; #if defined(RSOILWAT) - iOUTIndex = iOUT(2, go->irow_OUT[pd], go->nrow_OUT[pd], ncol_TimeOUT[pd]); + iOUTIndex = + iOUT(2, OutRun->irow_OUT[pd], OutDom->nrow_OUT[pd], ncol_TimeOUT[pd]); #elif defined(SWNETCDF) - iOUTIndex = - go->iOUToffset[eSW_AET][pd][2] + iOUTnc(go->irow_OUT[pd], 0, 0, 1, 1); + iOUTIndex = OutDom->iOUToffset[eSW_AET][pd][2] + + iOUTnc(OutRun->irow_OUT[pd], 0, 0, 1, 1); #endif p[iOUTIndex] = vo->esoil; #if defined(RSOILWAT) - iOUTIndex = iOUT(3, go->irow_OUT[pd], go->nrow_OUT[pd], ncol_TimeOUT[pd]); + iOUTIndex = + iOUT(3, OutRun->irow_OUT[pd], OutDom->nrow_OUT[pd], ncol_TimeOUT[pd]); #elif defined(SWNETCDF) - iOUTIndex = - go->iOUToffset[eSW_AET][pd][3] + iOUTnc(go->irow_OUT[pd], 0, 0, 1, 1); + iOUTIndex = OutDom->iOUToffset[eSW_AET][pd][3] + + iOUTnc(OutRun->irow_OUT[pd], 0, 0, 1, 1); #endif p[iOUTIndex] = vo->ecnw; #if defined(RSOILWAT) - iOUTIndex = iOUT(4, go->irow_OUT[pd], go->nrow_OUT[pd], ncol_TimeOUT[pd]); + iOUTIndex = + iOUT(4, OutRun->irow_OUT[pd], OutDom->nrow_OUT[pd], ncol_TimeOUT[pd]); #elif defined(SWNETCDF) - iOUTIndex = - go->iOUToffset[eSW_AET][pd][4] + iOUTnc(go->irow_OUT[pd], 0, 0, 1, 1); + iOUTIndex = OutDom->iOUToffset[eSW_AET][pd][4] + + iOUTnc(OutRun->irow_OUT[pd], 0, 0, 1, 1); #endif p[iOUTIndex] = vo->esurf; #if defined(RSOILWAT) - iOUTIndex = iOUT(5, go->irow_OUT[pd], go->nrow_OUT[pd], ncol_TimeOUT[pd]); + iOUTIndex = + iOUT(5, OutRun->irow_OUT[pd], OutDom->nrow_OUT[pd], ncol_TimeOUT[pd]); #elif defined(SWNETCDF) - iOUTIndex = - go->iOUToffset[eSW_AET][pd][5] + iOUTnc(go->irow_OUT[pd], 0, 0, 1, 1); + iOUTIndex = OutDom->iOUToffset[eSW_AET][pd][5] + + iOUTnc(OutRun->irow_OUT[pd], 0, 0, 1, 1); #endif p[iOUTIndex] = vo2->snowloss; // should be `vo->esnow` @@ -3256,37 +3632,45 @@ void get_aet_mem(OutPeriod pd, SW_RUN *sw) { @param[in] pd Time period in simulation output (day/week/month/year) @param[in] sw Comprehensive struct of type SW_RUN containing all information in the simulation. +@param[in] OutDom Struct of type SW_OUT_DOM that holds output + information that do not change throughout simulation runs */ -void get_aet_agg(OutPeriod pd, SW_RUN *sw) { +void get_aet_agg(OutPeriod pd, SW_RUN *sw, SW_OUT_DOM *OutDom) { SW_SOILWAT_OUTPUTS *vo = sw->SoilWat.p_oagg[pd]; SW_WEATHER_OUTPUTS *vo2 = sw->Weather.p_oagg[pd]; size_t iOUTIndex = 0; - SW_GEN_OUT *go = &sw->GenOutput; + SW_OUT_RUN *OutRun = &sw->OutRun; - RealD *p = go->p_OUT[eSW_AET][pd], *psd = go->p_OUTsd[eSW_AET][pd]; + RealD *p = OutRun->p_OUT[eSW_AET][pd], *psd = OutRun->p_OUTsd[eSW_AET][pd]; - iOUTIndex = iOUT(0, go->irow_OUT[pd], go->nrow_OUT[pd], ncol_TimeOUT[pd]); - do_running_agg(p, psd, iOUTIndex, go->currIter, vo->aet); + iOUTIndex = + iOUT(0, OutRun->irow_OUT[pd], OutDom->nrow_OUT[pd], ncol_TimeOUT[pd]); + do_running_agg(p, psd, iOUTIndex, OutRun->currIter, vo->aet); - iOUTIndex = iOUT(1, go->irow_OUT[pd], go->nrow_OUT[pd], ncol_TimeOUT[pd]); - do_running_agg(p, psd, iOUTIndex, go->currIter, vo->tran); + iOUTIndex = + iOUT(1, OutRun->irow_OUT[pd], OutDom->nrow_OUT[pd], ncol_TimeOUT[pd]); + do_running_agg(p, psd, iOUTIndex, OutRun->currIter, vo->tran); - iOUTIndex = iOUT(2, go->irow_OUT[pd], go->nrow_OUT[pd], ncol_TimeOUT[pd]); - do_running_agg(p, psd, iOUTIndex, go->currIter, vo->esoil); + iOUTIndex = + iOUT(2, OutRun->irow_OUT[pd], OutDom->nrow_OUT[pd], ncol_TimeOUT[pd]); + do_running_agg(p, psd, iOUTIndex, OutRun->currIter, vo->esoil); - iOUTIndex = iOUT(3, go->irow_OUT[pd], go->nrow_OUT[pd], ncol_TimeOUT[pd]); - do_running_agg(p, psd, iOUTIndex, go->currIter, vo->ecnw); + iOUTIndex = + iOUT(3, OutRun->irow_OUT[pd], OutDom->nrow_OUT[pd], ncol_TimeOUT[pd]); + do_running_agg(p, psd, iOUTIndex, OutRun->currIter, vo->ecnw); - iOUTIndex = iOUT(4, go->irow_OUT[pd], go->nrow_OUT[pd], ncol_TimeOUT[pd]); - do_running_agg(p, psd, iOUTIndex, go->currIter, vo->esurf); + iOUTIndex = + iOUT(4, OutRun->irow_OUT[pd], OutDom->nrow_OUT[pd], ncol_TimeOUT[pd]); + do_running_agg(p, psd, iOUTIndex, OutRun->currIter, vo->esurf); // should be `vo->esnow` - iOUTIndex = iOUT(5, go->irow_OUT[pd], go->nrow_OUT[pd], ncol_TimeOUT[pd]); - do_running_agg(p, psd, iOUTIndex, go->currIter, vo2->snowloss); + iOUTIndex = + iOUT(5, OutRun->irow_OUT[pd], OutDom->nrow_OUT[pd], ncol_TimeOUT[pd]); + do_running_agg(p, psd, iOUTIndex, OutRun->currIter, vo2->snowloss); - if (go->print_IterationSummary) { - go->sw_outstr_agg[0] = '\0'; - format_IterationSummary(p, psd, pd, go->ncol_OUT[eSW_AET], sw); + if (OutRun->print_IterationSummary) { + OutRun->sw_outstr_agg[0] = '\0'; + format_IterationSummary(p, psd, pd, OutRun->ncol_OUT[eSW_AET], sw); } } @@ -3296,13 +3680,14 @@ void get_aet_agg(OutPeriod pd, SW_RUN *sw) { @param[in] pd Time period in simulation output (day/week/month/year) @param[in] sw Comprehensive struct of type SW_RUN containing all information in the simulation. +@param[in] OutDom Struct of type SW_OUT_DOM that holds output + information that do not change throughout simulation runs */ -void get_aet_SXW(OutPeriod pd, SW_RUN *sw) { +void get_aet_SXW(OutPeriod pd, SW_RUN *sw, SW_OUT_DOM *OutDom) { if (pd == eSW_Year) { SW_SOILWAT_OUTPUTS *vo = sw->SoilWat.p_oagg[pd]; - SW_GEN_OUT *go = &sw->GenOutput; - go->aet = vo->aet; + OutRun->aet = vo->aet; } } #endif @@ -3317,15 +3702,17 @@ void get_aet_SXW(OutPeriod pd, SW_RUN *sw) { @param[in] pd Time period in simulation output (day/week/month/year) @param[in] sw Comprehensive struct of type SW_RUN containing all information in the simulation. +@param[in] OutDom Struct of type SW_OUT_DOM that holds output + information that do not change throughout simulation runs */ void get_pet_text(OutPeriod pd, SW_RUN *sw) { SW_SOILWAT_OUTPUTS *vo = sw->SoilWat.p_oagg[pd]; - SW_GEN_OUT *go = &sw->GenOutput; + SW_OUT_RUN *OutRun = &sw->OutRun; - go->sw_outstr[0] = '\0'; + OutRun->sw_outstr[0] = '\0'; snprintf( - go->sw_outstr, - sizeof go->sw_outstr, + OutRun->sw_outstr, + sizeof OutRun->sw_outstr, "%c%.*f%c%.*f%c%.*f%c%.*f%c%.*f", _OUTSEP, OUT_DIGITS, @@ -3354,70 +3741,77 @@ void get_pet_text(OutPeriod pd, SW_RUN *sw) { @param[in] pd Time period in simulation output (day/week/month/year) @param[in] sw Comprehensive struct of type SW_RUN containing all information in the simulation. +@param[in] OutDom Struct of type SW_OUT_DOM that holds output + information that do not change throughout simulation runs */ -void get_pet_mem(OutPeriod pd, SW_RUN *sw) { +void get_pet_mem(OutPeriod pd, SW_RUN *sw, SW_OUT_DOM *OutDom) { SW_SOILWAT_OUTPUTS *vo = sw->SoilWat.p_oagg[pd]; size_t iOUTIndex = 0; - SW_GEN_OUT *go = &sw->GenOutput; + SW_OUT_RUN *OutRun = &sw->OutRun; - RealD *p = go->p_OUT[eSW_PET][pd]; + RealD *p = OutRun->p_OUT[eSW_PET][pd]; #if defined(RSOILWAT) get_outvalleader( - &sw->Model, pd, go->irow_OUT, go->nrow_OUT, go->tOffset, p + &sw->Model, pd, OutRun->irow_OUT, OutRun->nrow_OUT, OutRun->tOffset, p ); #endif #if defined(RSOILWAT) - iOUTIndex = iOUT(0, go->irow_OUT[pd], go->nrow_OUT[pd], ncol_TimeOUT[pd]); + iOUTIndex = + iOUT(0, OutRun->irow_OUT[pd], OutDom->nrow_OUT[pd], ncol_TimeOUT[pd]); #elif defined(SWNETCDF) - iOUTIndex = - go->iOUToffset[eSW_PET][pd][0] + iOUTnc(go->irow_OUT[pd], 0, 0, 1, 1); + iOUTIndex = OutDom->iOUToffset[eSW_PET][pd][0] + + iOUTnc(OutRun->irow_OUT[pd], 0, 0, 1, 1); #endif p[iOUTIndex] = vo->pet; #if defined(RSOILWAT) - iOUTIndex = iOUT(1, go->irow_OUT[pd], go->nrow_OUT[pd], ncol_TimeOUT[pd]); + iOUTIndex = + iOUT(1, OutRun->irow_OUT[pd], OutDom->nrow_OUT[pd], ncol_TimeOUT[pd]); #elif defined(SWNETCDF) - iOUTIndex = - go->iOUToffset[eSW_PET][pd][1] + iOUTnc(go->irow_OUT[pd], 0, 0, 1, 1); + iOUTIndex = OutDom->iOUToffset[eSW_PET][pd][1] + + iOUTnc(OutRun->irow_OUT[pd], 0, 0, 1, 1); #endif p[iOUTIndex] = vo->H_oh; #if defined(RSOILWAT) - iOUTIndex = iOUT(2, go->irow_OUT[pd], go->nrow_OUT[pd], ncol_TimeOUT[pd]); + iOUTIndex = + iOUT(2, OutRun->irow_OUT[pd], OutDom->nrow_OUT[pd], ncol_TimeOUT[pd]); #elif defined(SWNETCDF) - iOUTIndex = - go->iOUToffset[eSW_PET][pd][2] + iOUTnc(go->irow_OUT[pd], 0, 0, 1, 1); + iOUTIndex = OutDom->iOUToffset[eSW_PET][pd][2] + + iOUTnc(OutRun->irow_OUT[pd], 0, 0, 1, 1); #endif p[iOUTIndex] = vo->H_ot; #if defined(RSOILWAT) - iOUTIndex = iOUT(3, go->irow_OUT[pd], go->nrow_OUT[pd], ncol_TimeOUT[pd]); + iOUTIndex = + iOUT(3, OutRun->irow_OUT[pd], OutDom->nrow_OUT[pd], ncol_TimeOUT[pd]); #elif defined(SWNETCDF) - iOUTIndex = - go->iOUToffset[eSW_PET][pd][3] + iOUTnc(go->irow_OUT[pd], 0, 0, 1, 1); + iOUTIndex = OutDom->iOUToffset[eSW_PET][pd][3] + + iOUTnc(OutRun->irow_OUT[pd], 0, 0, 1, 1); #endif p[iOUTIndex] = vo->H_gh; #if defined(RSOILWAT) - iOUTIndex = iOUT(4, go->irow_OUT[pd], go->nrow_OUT[pd], ncol_TimeOUT[pd]); + iOUTIndex = + iOUT(4, OutRun->irow_OUT[pd], OutDom->nrow_OUT[pd], ncol_TimeOUT[pd]); #elif defined(SWNETCDF) - iOUTIndex = - go->iOUToffset[eSW_PET][pd][4] + iOUTnc(go->irow_OUT[pd], 0, 0, 1, 1); + iOUTIndex = OutDom->iOUToffset[eSW_PET][pd][4] + + iOUTnc(OutRun->irow_OUT[pd], 0, 0, 1, 1); #endif p[iOUTIndex] = vo->H_gt; @@ -3428,31 +3822,36 @@ void get_pet_mem(OutPeriod pd, SW_RUN *sw) { /** @brief Gets potential evapotranspiration and radiation */ -void get_pet_agg(OutPeriod pd, SW_RUN *sw) { +void get_pet_agg(OutPeriod pd, SW_RUN *sw, SW_OUT_DOM *OutDom) { SW_SOILWAT_OUTPUTS *vo = sw->SoilWat.p_oagg[pd]; size_t iOUTIndex = 0; - SW_GEN_OUT *go = &sw->GenOutput; + SW_OUT_RUN *OutRun = &sw->OutRun; - RealD *p = go->p_OUT[eSW_PET][pd], *psd = go->p_OUTsd[eSW_PET][pd]; + RealD *p = OutRun->p_OUT[eSW_PET][pd], *psd = OutRun->p_OUTsd[eSW_PET][pd]; - iOUTIndex = iOUT(0, go->irow_OUT[pd], go->nrow_OUT[pd], ncol_TimeOUT[pd]); - do_running_agg(p, psd, iOUTIndex, go->currIter, vo->pet); + iOUTIndex = + iOUT(0, OutRun->irow_OUT[pd], OutDom->nrow_OUT[pd], ncol_TimeOUT[pd]); + do_running_agg(p, psd, iOUTIndex, OutRun->currIter, vo->pet); - iOUTIndex = iOUT(1, go->irow_OUT[pd], go->nrow_OUT[pd], ncol_TimeOUT[pd]); - do_running_agg(p, psd, iOUTIndex, go->currIter, vo->H_oh); + iOUTIndex = + iOUT(1, OutRun->irow_OUT[pd], OutDom->nrow_OUT[pd], ncol_TimeOUT[pd]); + do_running_agg(p, psd, iOUTIndex, OutRun->currIter, vo->H_oh); - iOUTIndex = iOUT(2, go->irow_OUT[pd], go->nrow_OUT[pd], ncol_TimeOUT[pd]); - do_running_agg(p, psd, iOUTIndex, go->currIter, vo->H_ot); + iOUTIndex = + iOUT(2, OutRun->irow_OUT[pd], OutDom->nrow_OUT[pd], ncol_TimeOUT[pd]); + do_running_agg(p, psd, iOUTIndex, OutRun->currIter, vo->H_ot); - iOUTIndex = iOUT(3, go->irow_OUT[pd], go->nrow_OUT[pd], ncol_TimeOUT[pd]); - do_running_agg(p, psd, iOUTIndex, go->currIter, vo->H_gh); + iOUTIndex = + iOUT(3, OutRun->irow_OUT[pd], OutDom->nrow_OUT[pd], ncol_TimeOUT[pd]); + do_running_agg(p, psd, iOUTIndex, OutRun->currIter, vo->H_gh); - iOUTIndex = iOUT(4, go->irow_OUT[pd], go->nrow_OUT[pd], ncol_TimeOUT[pd]); - do_running_agg(p, psd, iOUTIndex, go->currIter, vo->H_gt); + iOUTIndex = + iOUT(4, OutRun->irow_OUT[pd], OutDom->nrow_OUT[pd], ncol_TimeOUT[pd]); + do_running_agg(p, psd, iOUTIndex, OutRun->currIter, vo->H_gt); - if (go->print_IterationSummary) { - go->sw_outstr_agg[0] = '\0'; - format_IterationSummary(p, psd, pd, go->ncol_OUT[eSW_PET], sw); + if (OutRun->print_IterationSummary) { + OutRun->sw_outstr_agg[0] = '\0'; + format_IterationSummary(p, psd, pd, OutRun->ncol_OUT[eSW_PET], sw); } } #endif @@ -3467,20 +3866,22 @@ void get_pet_agg(OutPeriod pd, SW_RUN *sw) { @param[in] pd Time period in simulation output (day/week/month/year) @param[in] sw Comprehensive struct of type SW_RUN containing all information in the simulation. +@param[in] OutDom Struct of type SW_OUT_DOM that holds output + information that do not change throughout simulation runs */ void get_wetdays_text(OutPeriod pd, SW_RUN *sw) { LyrIndex i, n_layers = sw->Site.n_layers; - SW_GEN_OUT *go = &sw->GenOutput; + SW_OUT_RUN *OutRun = &sw->OutRun; char str[OUTSTRLEN]; - go->sw_outstr[0] = '\0'; + OutRun->sw_outstr[0] = '\0'; if (pd == eSW_Day) { ForEachSoilLayer(i, n_layers) { snprintf( str, OUTSTRLEN, "%c%i", _OUTSEP, (sw->SoilWat.is_wet[i]) ? 1 : 0 ); - strcat(go->sw_outstr, str); + strcat(OutRun->sw_outstr, str); } } else { @@ -3488,7 +3889,7 @@ void get_wetdays_text(OutPeriod pd, SW_RUN *sw) { ForEachSoilLayer(i, n_layers) { snprintf(str, OUTSTRLEN, "%c%i", _OUTSEP, (int) vo->wetdays[i]); - strcat(go->sw_outstr, str); + strcat(OutRun->sw_outstr, str); } } } @@ -3502,30 +3903,35 @@ void get_wetdays_text(OutPeriod pd, SW_RUN *sw) { @param[in] pd Time period in simulation output (day/week/month/year) @param[in] sw Comprehensive struct of type SW_RUN containing all information in the simulation. +@param[in] OutDom Struct of type SW_OUT_DOM that holds output + information that do not change throughout simulation runs */ -void get_wetdays_mem(OutPeriod pd, SW_RUN *sw) { +void get_wetdays_mem(OutPeriod pd, SW_RUN *sw, SW_OUT_DOM *OutDom) { LyrIndex i; size_t iOUTIndex = 0; - SW_GEN_OUT *go = &sw->GenOutput; + SW_OUT_RUN *OutRun = &sw->OutRun; - RealD *p = go->p_OUT[eSW_WetDays][pd]; + RealD *p = OutRun->p_OUT[eSW_WetDays][pd]; SW_SOILWAT_OUTPUTS *vo = sw->SoilWat.p_oagg[pd]; #if defined(RSOILWAT) get_outvalleader( - &sw->Model, pd, go->irow_OUT, go->nrow_OUT, go->tOffset, p + &sw->Model, pd, OutRun->irow_OUT, OutRun->nrow_OUT, OutRun->tOffset, p ); #endif ForEachSoilLayer(i, sw->Site.n_layers) { #if defined(RSOILWAT) - iOUTIndex = - iOUT(i, go->irow_OUT[pd], go->nrow_OUT[pd], ncol_TimeOUT[pd]); + iOUTIndex = iOUT( + i, OutRun->irow_OUT[pd], OutDom->nrow_OUT[pd], ncol_TimeOUT[pd] + ); #elif defined(SWNETCDF) iOUTIndex = - go->iOUToffset[eSW_WetDays][pd][0] + - iOUTnc(go->irow_OUT[pd], i, 0, go->nsl_OUT[eSW_WetDays][0], 1); + OutDom->iOUToffset[eSW_WetDays][pd][0] + + iOUTnc( + OutRun->irow_OUT[pd], i, 0, OutDom->nsl_OUT[eSW_WetDays][0], 1 + ); #endif if (pd == eSW_Day) { @@ -3537,10 +3943,12 @@ void get_wetdays_mem(OutPeriod pd, SW_RUN *sw) { #if defined(SWNETCDF) /* Set extra soil layers to missing/fill value (up to domain-wide max) */ - for (i = sw->Site.n_layers; i < go->nsl_OUT[eSW_WetDays][0]; i++) { + for (i = sw->Site.n_layers; i < OutDom->nsl_OUT[eSW_WetDays][0]; i++) { iOUTIndex = - go->iOUToffset[eSW_WetDays][pd][0] + - iOUTnc(go->irow_OUT[pd], i, 0, go->nsl_OUT[eSW_WetDays][0], 1); + OutDom->iOUToffset[eSW_WetDays][pd][0] + + iOUTnc( + OutRun->irow_OUT[pd], i, 0, OutDom->nsl_OUT[eSW_WetDays][0], 1 + ); p[iOUTIndex] = NC_FILL_DOUBLE; } #endif // SWNETCDF @@ -3554,20 +3962,28 @@ void get_wetdays_mem(OutPeriod pd, SW_RUN *sw) { @param[in] pd Time period in simulation output (day/week/month/year) @param[in] sw Comprehensive struct of type SW_RUN containing all information in the simulation. +@param[in] OutDom Struct of type SW_OUT_DOM that holds output + information that do not change throughout simulation runs */ -void get_wetdays_agg(OutPeriod pd, SW_RUN *sw) { +void get_wetdays_agg(OutPeriod pd, SW_RUN *sw, SW_OUT_DOM *OutDom) { LyrIndex i; size_t iOUTIndex = 0; - SW_GEN_OUT *go = &sw->GenOutput; + SW_OUT_RUN *OutRun = &sw->OutRun; - RealD *p = go->p_OUT[eSW_WetDays][pd], *psd = go->p_OUTsd[eSW_WetDays][pd]; + RealD *p = OutRun->p_OUT[eSW_WetDays][pd], + *psd = OutRun->p_OUTsd[eSW_WetDays][pd]; if (pd == eSW_Day) { ForEachSoilLayer(i, sw->Site.n_layers) { - iOUTIndex = - iOUT(i, go->irow_OUT[pd], go->nrow_OUT[pd], ncol_TimeOUT[pd]); + iOUTIndex = iOUT( + i, OutRun->irow_OUT[pd], OutDom->nrow_OUT[pd], ncol_TimeOUT[pd] + ); do_running_agg( - p, psd, iOUTIndex, go->currIter, (sw->SoilWat.is_wet[i]) ? 1 : 0 + p, + psd, + iOUTIndex, + OutRun->currIter, + (sw->SoilWat.is_wet[i]) ? 1 : 0 ); } @@ -3575,15 +3991,16 @@ void get_wetdays_agg(OutPeriod pd, SW_RUN *sw) { SW_SOILWAT_OUTPUTS *vo = sw->SoilWat.p_oagg[pd]; ForEachSoilLayer(i, sw->Site.n_layers) { - iOUTIndex = - iOUT(i, go->irow_OUT[pd], go->nrow_OUT[pd], ncol_TimeOUT[pd]); - do_running_agg(p, psd, iOUTIndex, go->currIter, vo->wetdays[i]); + iOUTIndex = iOUT( + i, OutRun->irow_OUT[pd], OutDom->nrow_OUT[pd], ncol_TimeOUT[pd] + ); + do_running_agg(p, psd, iOUTIndex, OutRun->currIter, vo->wetdays[i]); } } - if (go->print_IterationSummary) { - go->sw_outstr_agg[0] = '\0'; - format_IterationSummary(p, psd, pd, go->ncol_OUT[eSW_WetDays], sw); + if (OutRun->print_IterationSummary) { + OutRun->sw_outstr_agg[0] = '\0'; + format_IterationSummary(p, psd, pd, OutRun->ncol_OUT[eSW_WetDays], sw); } } #endif @@ -3598,15 +4015,17 @@ void get_wetdays_agg(OutPeriod pd, SW_RUN *sw) { @param[in] pd Time period in simulation output (day/week/month/year) @param[in] sw Comprehensive struct of type SW_RUN containing all information in the simulation. +@param[in] OutDom Struct of type SW_OUT_DOM that holds output + information that do not change throughout simulation runs */ void get_snowpack_text(OutPeriod pd, SW_RUN *sw) { SW_SOILWAT_OUTPUTS *vo = sw->SoilWat.p_oagg[pd]; - SW_GEN_OUT *go = &sw->GenOutput; + SW_OUT_RUN *OutRun = &sw->OutRun; - go->sw_outstr[0] = '\0'; + OutRun->sw_outstr[0] = '\0'; snprintf( - go->sw_outstr, - sizeof go->sw_outstr, + OutRun->sw_outstr, + sizeof OutRun->sw_outstr, "%c%.*f%c%.*f", _OUTSEP, OUT_DIGITS, @@ -3626,37 +4045,41 @@ void get_snowpack_text(OutPeriod pd, SW_RUN *sw) { @param[in] pd Time period in simulation output (day/week/month/year) @param[in] sw Comprehensive struct of type SW_RUN containing all information in the simulation. +@param[in] OutDom Struct of type SW_OUT_DOM that holds output + information that do not change throughout simulation runs */ -void get_snowpack_mem(OutPeriod pd, SW_RUN *sw) { +void get_snowpack_mem(OutPeriod pd, SW_RUN *sw, SW_OUT_DOM *OutDom) { SW_SOILWAT_OUTPUTS *vo = sw->SoilWat.p_oagg[pd]; size_t iOUTIndex = 0; - SW_GEN_OUT *go = &sw->GenOutput; + SW_OUT_RUN *OutRun = &sw->OutRun; - RealD *p = go->p_OUT[eSW_SnowPack][pd]; + RealD *p = OutRun->p_OUT[eSW_SnowPack][pd]; #if defined(RSOILWAT) get_outvalleader( - &sw->Model, pd, go->irow_OUT, go->nrow_OUT, go->tOffset, p + &sw->Model, pd, OutRun->irow_OUT, OutRun->nrow_OUT, OutRun->tOffset, p ); #endif #if defined(RSOILWAT) - iOUTIndex = iOUT(0, go->irow_OUT[pd], go->nrow_OUT[pd], ncol_TimeOUT[pd]); + iOUTIndex = + iOUT(0, OutRun->irow_OUT[pd], OutDom->nrow_OUT[pd], ncol_TimeOUT[pd]); #elif defined(SWNETCDF) - iOUTIndex = go->iOUToffset[eSW_SnowPack][pd][0] + - iOUTnc(go->irow_OUT[pd], 0, 0, 1, 1); + iOUTIndex = OutDom->iOUToffset[eSW_SnowPack][pd][0] + + iOUTnc(OutRun->irow_OUT[pd], 0, 0, 1, 1); #endif p[iOUTIndex] = vo->snowpack; #if defined(RSOILWAT) - iOUTIndex = iOUT(1, go->irow_OUT[pd], go->nrow_OUT[pd], ncol_TimeOUT[pd]); + iOUTIndex = + iOUT(1, OutRun->irow_OUT[pd], OutDom->nrow_OUT[pd], ncol_TimeOUT[pd]); #elif defined(SWNETCDF) - iOUTIndex = go->iOUToffset[eSW_SnowPack][pd][1] + - iOUTnc(go->irow_OUT[pd], 0, 0, 1, 1); + iOUTIndex = OutDom->iOUToffset[eSW_SnowPack][pd][1] + + iOUTnc(OutRun->irow_OUT[pd], 0, 0, 1, 1); #endif p[iOUTIndex] = vo->snowdepth; @@ -3670,24 +4093,28 @@ void get_snowpack_mem(OutPeriod pd, SW_RUN *sw) { @param[in] pd Time period in simulation output (day/week/month/year) @param[in] sw Comprehensive struct of type SW_RUN containing all information in the simulation. +@param[in] OutDom Struct of type SW_OUT_DOM that holds output + information that do not change throughout simulation runs */ -void get_snowpack_agg(OutPeriod pd, SW_RUN *sw) { +void get_snowpack_agg(OutPeriod pd, SW_RUN *sw, SW_OUT_DOM *OutDom) { SW_SOILWAT_OUTPUTS *vo = sw->SoilWat.p_oagg[pd]; size_t iOUTIndex = 0; - SW_GEN_OUT *go = &sw->GenOutput; + SW_OUT_RUN *OutRun = &sw->OutRun; - RealD *p = go->p_OUT[eSW_SnowPack][pd], - *psd = go->p_OUTsd[eSW_SnowPack][pd]; + RealD *p = OutRun->p_OUT[eSW_SnowPack][pd], + *psd = OutRun->p_OUTsd[eSW_SnowPack][pd]; - iOUTIndex = iOUT(0, go->irow_OUT[pd], go->nrow_OUT[pd], ncol_TimeOUT[pd]); - do_running_agg(p, psd, iOUTIndex, go->currIter, vo->snowpack); + iOUTIndex = + iOUT(0, OutRun->irow_OUT[pd], OutDom->nrow_OUT[pd], ncol_TimeOUT[pd]); + do_running_agg(p, psd, iOUTIndex, OutRun->currIter, vo->snowpack); - iOUTIndex = iOUT(1, go->irow_OUT[pd], go->nrow_OUT[pd], ncol_TimeOUT[pd]); - do_running_agg(p, psd, iOUTIndex, go->currIter, vo->snowdepth); + iOUTIndex = + iOUT(1, OutRun->irow_OUT[pd], OutDom->nrow_OUT[pd], ncol_TimeOUT[pd]); + do_running_agg(p, psd, iOUTIndex, OutRun->currIter, vo->snowdepth); - if (go->print_IterationSummary) { - go->sw_outstr_agg[0] = '\0'; - format_IterationSummary(p, psd, pd, go->ncol_OUT[eSW_SnowPack], sw); + if (OutRun->print_IterationSummary) { + OutRun->sw_outstr_agg[0] = '\0'; + format_IterationSummary(p, psd, pd, OutRun->ncol_OUT[eSW_SnowPack], sw); } } #endif @@ -3702,15 +4129,17 @@ void get_snowpack_agg(OutPeriod pd, SW_RUN *sw) { @param[in] pd Time period in simulation output (day/week/month/year) @param[in] sw Comprehensive struct of type SW_RUN containing all information in the simulation. +@param[in] OutDom Struct of type SW_OUT_DOM that holds output + information that do not change throughout simulation runs */ void get_deepswc_text(OutPeriod pd, SW_RUN *sw) { SW_SOILWAT_OUTPUTS *vo = sw->SoilWat.p_oagg[pd]; - SW_GEN_OUT *go = &sw->GenOutput; + SW_OUT_RUN *OutRun = &sw->OutRun; - go->sw_outstr[0] = '\0'; + OutRun->sw_outstr[0] = '\0'; snprintf( - go->sw_outstr, - sizeof go->sw_outstr, + OutRun->sw_outstr, + sizeof OutRun->sw_outstr, "%c%.*f", _OUTSEP, OUT_DIGITS, @@ -3727,26 +4156,29 @@ void get_deepswc_text(OutPeriod pd, SW_RUN *sw) { @param[in] pd Time period in simulation output (day/week/month/year) @param[in] sw Comprehensive struct of type SW_RUN containing all information in the simulation. +@param[in] OutDom Struct of type SW_OUT_DOM that holds output + information that do not change throughout simulation runs */ -void get_deepswc_mem(OutPeriod pd, SW_RUN *sw) { +void get_deepswc_mem(OutPeriod pd, SW_RUN *sw, SW_OUT_DOM *OutDom) { SW_SOILWAT_OUTPUTS *vo = sw->SoilWat.p_oagg[pd]; size_t iOUTIndex = 0; - SW_GEN_OUT *go = &sw->GenOutput; + SW_OUT_RUN *OutRun = &sw->OutRun; - RealD *p = go->p_OUT[eSW_DeepSWC][pd]; + RealD *p = OutRun->p_OUT[eSW_DeepSWC][pd]; #if defined(RSOILWAT) get_outvalleader( - &sw->Model, pd, go->irow_OUT, go->nrow_OUT, go->tOffset, p + &sw->Model, pd, OutRun->irow_OUT, OutRun->nrow_OUT, OutRun->tOffset, p ); #endif #if defined(RSOILWAT) - iOUTIndex = iOUT(0, go->irow_OUT[pd], go->nrow_OUT[pd], ncol_TimeOUT[pd]); + iOUTIndex = + iOUT(0, OutRun->irow_OUT[pd], OutDom->nrow_OUT[pd], ncol_TimeOUT[pd]); #elif defined(SWNETCDF) - iOUTIndex = go->iOUToffset[eSW_DeepSWC][pd][0] + - iOUTnc(go->irow_OUT[pd], 0, 0, 1, 1); + iOUTIndex = OutDom->iOUToffset[eSW_DeepSWC][pd][0] + + iOUTnc(OutRun->irow_OUT[pd], 0, 0, 1, 1); #endif p[iOUTIndex] = vo->deep; @@ -3760,20 +4192,24 @@ void get_deepswc_mem(OutPeriod pd, SW_RUN *sw) { @param[in] pd Time period in simulation output (day/week/month/year) @param[in] sw Comprehensive struct of type SW_RUN containing all information in the simulation. +@param[in] OutDom Struct of type SW_OUT_DOM that holds output + information that do not change throughout simulation runs */ -void get_deepswc_agg(OutPeriod pd, SW_RUN *sw) { +void get_deepswc_agg(OutPeriod pd, SW_RUN *sw, SW_OUT_DOM *OutDom) { SW_SOILWAT_OUTPUTS *vo = sw->SoilWat.p_oagg[pd]; size_t iOUTIndex = 0; - SW_GEN_OUT *go = &sw->GenOutput; + SW_OUT_RUN *OutRun = &sw->OutRun; - RealD *p = go->p_OUT[eSW_DeepSWC][pd], *psd = go->p_OUTsd[eSW_DeepSWC][pd]; + RealD *p = OutRun->p_OUT[eSW_DeepSWC][pd], + *psd = OutRun->p_OUTsd[eSW_DeepSWC][pd]; - iOUTIndex = iOUT(0, go->irow_OUT[pd], go->nrow_OUT[pd], ncol_TimeOUT[pd]); - do_running_agg(p, psd, iOUTIndex, go->currIter, vo->deep); + iOUTIndex = + iOUT(0, OutRun->irow_OUT[pd], OutDom->nrow_OUT[pd], ncol_TimeOUT[pd]); + do_running_agg(p, psd, iOUTIndex, OutRun->currIter, vo->deep); - if (go->print_IterationSummary) { - go->sw_outstr_agg[0] = '\0'; - format_IterationSummary(p, psd, pd, go->ncol_OUT[eSW_DeepSWC], sw); + if (OutRun->print_IterationSummary) { + OutRun->sw_outstr_agg[0] = '\0'; + format_IterationSummary(p, psd, pd, OutRun->ncol_OUT[eSW_DeepSWC], sw); } } #endif @@ -3788,14 +4224,16 @@ void get_deepswc_agg(OutPeriod pd, SW_RUN *sw) { @param[in] pd Time period in simulation output (day/week/month/year) @param[in] sw Comprehensive struct of type SW_RUN containing all information in the simulation. +@param[in] OutDom Struct of type SW_OUT_DOM that holds output + information that do not change throughout simulation runs */ void get_soiltemp_text(OutPeriod pd, SW_RUN *sw) { LyrIndex i; SW_SOILWAT_OUTPUTS *vo = sw->SoilWat.p_oagg[pd]; - SW_GEN_OUT *go = &sw->GenOutput; + SW_OUT_RUN *OutRun = &sw->OutRun; char str[OUTSTRLEN]; - go->sw_outstr[0] = '\0'; + OutRun->sw_outstr[0] = '\0'; ForEachSoilLayer(i, sw->Site.n_layers) { snprintf( @@ -3806,7 +4244,7 @@ void get_soiltemp_text(OutPeriod pd, SW_RUN *sw) { OUT_DIGITS, vo->maxLyrTemperature[i] ); - strcat(go->sw_outstr, str); + strcat(OutRun->sw_outstr, str); snprintf( str, @@ -3816,12 +4254,12 @@ void get_soiltemp_text(OutPeriod pd, SW_RUN *sw) { OUT_DIGITS, vo->minLyrTemperature[i] ); - strcat(go->sw_outstr, str); + strcat(OutRun->sw_outstr, str); snprintf( str, OUTSTRLEN, "%c%.*f", _OUTSEP, OUT_DIGITS, vo->avgLyrTemp[i] ); - strcat(go->sw_outstr, str); + strcat(OutRun->sw_outstr, str); } } #endif @@ -3834,30 +4272,38 @@ void get_soiltemp_text(OutPeriod pd, SW_RUN *sw) { @param[in] pd Time period in simulation output (day/week/month/year) @param[in] sw Comprehensive struct of type SW_RUN containing all information in the simulation. +@param[in] OutDom Struct of type SW_OUT_DOM that holds output + information that do not change throughout simulation runs */ -void get_soiltemp_mem(OutPeriod pd, SW_RUN *sw) { +void get_soiltemp_mem(OutPeriod pd, SW_RUN *sw, SW_OUT_DOM *OutDom) { LyrIndex i; SW_SOILWAT_OUTPUTS *vo = sw->SoilWat.p_oagg[pd]; size_t iOUTIndex = 0; - SW_GEN_OUT *go = &sw->GenOutput; + SW_OUT_RUN *OutRun = &sw->OutRun; - RealD *p = go->p_OUT[eSW_SoilTemp][pd]; + RealD *p = OutRun->p_OUT[eSW_SoilTemp][pd]; #if defined(RSOILWAT) get_outvalleader( - &sw->Model, pd, go->irow_OUT, go->nrow_OUT, go->tOffset, p + &sw->Model, pd, OutRun->irow_OUT, OutRun->nrow_OUT, OutRun->tOffset, p ); #endif ForEachSoilLayer(i, sw->Site.n_layers) { #if defined(RSOILWAT) - iOUTIndex = - iOUT((i * 3), go->irow_OUT[pd], go->nrow_OUT[pd], ncol_TimeOUT[pd]); + iOUTIndex = iOUT( + (i * 3), + OutRun->irow_OUT[pd], + OutDom->nrow_OUT[pd], + ncol_TimeOUT[pd] + ); #elif defined(SWNETCDF) iOUTIndex = - go->iOUToffset[eSW_SoilTemp][pd][0] + - iOUTnc(go->irow_OUT[pd], i, 0, go->nsl_OUT[eSW_SoilTemp][0], 1); + OutDom->iOUToffset[eSW_SoilTemp][pd][0] + + iOUTnc( + OutRun->irow_OUT[pd], i, 0, OutDom->nsl_OUT[eSW_SoilTemp][0], 1 + ); #endif p[iOUTIndex] = vo->maxLyrTemperature[i]; @@ -3865,13 +4311,18 @@ void get_soiltemp_mem(OutPeriod pd, SW_RUN *sw) { #if defined(RSOILWAT) iOUTIndex = iOUT( - (i * 3) + 1, go->irow_OUT[pd], go->nrow_OUT[pd], ncol_TimeOUT[pd] + (i * 3) + 1, + OutRun->irow_OUT[pd], + OutDom->nrow_OUT[pd], + ncol_TimeOUT[pd] ); #elif defined(SWNETCDF) iOUTIndex = - go->iOUToffset[eSW_SoilTemp][pd][1] + - iOUTnc(go->irow_OUT[pd], i, 0, go->nsl_OUT[eSW_SoilTemp][1], 1); + OutDom->iOUToffset[eSW_SoilTemp][pd][1] + + iOUTnc( + OutRun->irow_OUT[pd], i, 0, OutDom->nsl_OUT[eSW_SoilTemp][1], 1 + ); #endif p[iOUTIndex] = vo->minLyrTemperature[i]; @@ -3879,13 +4330,18 @@ void get_soiltemp_mem(OutPeriod pd, SW_RUN *sw) { #if defined(RSOILWAT) iOUTIndex = iOUT( - (i * 3) + 2, go->irow_OUT[pd], go->nrow_OUT[pd], ncol_TimeOUT[pd] + (i * 3) + 2, + OutRun->irow_OUT[pd], + OutDom->nrow_OUT[pd], + ncol_TimeOUT[pd] ); #elif defined(SWNETCDF) iOUTIndex = - go->iOUToffset[eSW_SoilTemp][pd][2] + - iOUTnc(go->irow_OUT[pd], i, 0, go->nsl_OUT[eSW_SoilTemp][2], 1); + OutDom->iOUToffset[eSW_SoilTemp][pd][2] + + iOUTnc( + OutRun->irow_OUT[pd], i, 0, OutDom->nsl_OUT[eSW_SoilTemp][2], 1 + ); #endif p[iOUTIndex] = vo->avgLyrTemp[i]; @@ -3893,20 +4349,26 @@ void get_soiltemp_mem(OutPeriod pd, SW_RUN *sw) { #if defined(SWNETCDF) /* Set extra soil layers to missing/fill value (up to domain-wide max) */ - for (i = sw->Site.n_layers; i < go->nsl_OUT[eSW_SoilTemp][0]; i++) { + for (i = sw->Site.n_layers; i < OutDom->nsl_OUT[eSW_SoilTemp][0]; i++) { iOUTIndex = - go->iOUToffset[eSW_SoilTemp][pd][0] + - iOUTnc(go->irow_OUT[pd], i, 0, go->nsl_OUT[eSW_SoilTemp][0], 1); + OutDom->iOUToffset[eSW_SoilTemp][pd][0] + + iOUTnc( + OutRun->irow_OUT[pd], i, 0, OutDom->nsl_OUT[eSW_SoilTemp][0], 1 + ); p[iOUTIndex] = NC_FILL_DOUBLE; iOUTIndex = - go->iOUToffset[eSW_SoilTemp][pd][1] + - iOUTnc(go->irow_OUT[pd], i, 0, go->nsl_OUT[eSW_SoilTemp][1], 1); + OutDom->iOUToffset[eSW_SoilTemp][pd][1] + + iOUTnc( + OutRun->irow_OUT[pd], i, 0, OutDom->nsl_OUT[eSW_SoilTemp][1], 1 + ); p[iOUTIndex] = NC_FILL_DOUBLE; iOUTIndex = - go->iOUToffset[eSW_SoilTemp][pd][2] + - iOUTnc(go->irow_OUT[pd], i, 0, go->nsl_OUT[eSW_SoilTemp][2], 1); + OutDom->iOUToffset[eSW_SoilTemp][pd][2] + + iOUTnc( + OutRun->irow_OUT[pd], i, 0, OutDom->nsl_OUT[eSW_SoilTemp][2], 1 + ); p[iOUTIndex] = NC_FILL_DOUBLE; } #endif // SWNETCDF @@ -3920,39 +4382,51 @@ void get_soiltemp_mem(OutPeriod pd, SW_RUN *sw) { @param[in] pd Time period in simulation output (day/week/month/year) @param[in] sw Comprehensive struct of type SW_RUN containing all information in the simulation. +@param[in] OutDom Struct of type SW_OUT_DOM that holds output + information that do not change throughout simulation runs */ -void get_soiltemp_agg(OutPeriod pd, SW_RUN *sw) { +void get_soiltemp_agg(OutPeriod pd, SW_RUN *sw, SW_OUT_DOM *OutDom) { LyrIndex i; SW_SOILWAT_OUTPUTS *vo = sw->SoilWat.p_oagg[pd]; size_t iOUTIndex = 0; - SW_GEN_OUT *go = &sw->GenOutput; + SW_OUT_RUN *OutRun = &sw->OutRun; - RealD *p = go->p_OUT[eSW_SoilTemp][pd], - *psd = go->p_OUTsd[eSW_SoilTemp][pd]; + RealD *p = OutRun->p_OUT[eSW_SoilTemp][pd], + *psd = OutRun->p_OUTsd[eSW_SoilTemp][pd]; ForEachSoilLayer(i, sw->Site.n_layers) { - iOUTIndex = - iOUT((i * 3), go->irow_OUT[pd], go->nrow_OUT[pd], ncol_TimeOUT[pd]); + iOUTIndex = iOUT( + (i * 3), + OutRun->irow_OUT[pd], + OutDom->nrow_OUT[pd], + ncol_TimeOUT[pd] + ); do_running_agg( - p, psd, iOUTIndex, go->currIter, vo->maxLyrTemperature[i] + p, psd, iOUTIndex, OutRun->currIter, vo->maxLyrTemperature[i] ); iOUTIndex = iOUT( - (i * 3) + 1, go->irow_OUT[pd], go->nrow_OUT[pd], ncol_TimeOUT[pd] + (i * 3) + 1, + OutRun->irow_OUT[pd], + OutDom->nrow_OUT[pd], + ncol_TimeOUT[pd] ); do_running_agg( - p, psd, iOUTIndex, go->currIter, vo->minLyrTemperature[i] + p, psd, iOUTIndex, OutRun->currIter, vo->minLyrTemperature[i] ); iOUTIndex = iOUT( - (i * 3) + 2, go->irow_OUT[pd], go->nrow_OUT[pd], ncol_TimeOUT[pd] + (i * 3) + 2, + OutRun->irow_OUT[pd], + OutDom->nrow_OUT[pd], + ncol_TimeOUT[pd] ); - do_running_agg(p, psd, iOUTIndex, go->currIter, vo->avgLyrTemp[i]); + do_running_agg(p, psd, iOUTIndex, OutRun->currIter, vo->avgLyrTemp[i]); } - if (go->print_IterationSummary) { - go->sw_outstr_agg[0] = '\0'; - format_IterationSummary(p, psd, pd, go->ncol_OUT[eSW_SoilTemp], sw); + if (OutRun->print_IterationSummary) { + OutRun->sw_outstr_agg[0] = '\0'; + format_IterationSummary(p, psd, pd, OutRun->ncol_OUT[eSW_SoilTemp], sw); } } #endif @@ -3967,20 +4441,22 @@ OUTTEXT. @param[in] pd Time period in simulation output (day/week/month/year) @param[in] sw Comprehensive struct of type SW_RUN containing all information in the simulation. +@param[in] OutDom Struct of type SW_OUT_DOM that holds output + information that do not change throughout simulation runs */ void get_frozen_text(OutPeriod pd, SW_RUN *sw) { LyrIndex i; SW_SOILWAT_OUTPUTS *vo = sw->SoilWat.p_oagg[pd]; - SW_GEN_OUT *go = &sw->GenOutput; + SW_OUT_RUN *OutRun = &sw->OutRun; char str[OUTSTRLEN]; - go->sw_outstr[0] = '\0'; + OutRun->sw_outstr[0] = '\0'; ForEachSoilLayer(i, sw->Site.n_layers) { snprintf( str, OUTSTRLEN, "%c%.*f", _OUTSEP, OUT_DIGITS, vo->lyrFrozen[i] ); - strcat(go->sw_outstr, str); + strcat(OutRun->sw_outstr, str); } } #endif @@ -3993,30 +4469,35 @@ void get_frozen_text(OutPeriod pd, SW_RUN *sw) { @param[in] pd Time period in simulation output (day/week/month/year) @param[in] sw Comprehensive struct of type SW_RUN containing all information in the simulation. +@param[in] OutDom Struct of type SW_OUT_DOM that holds output + information that do not change throughout simulation runs */ -void get_frozen_mem(OutPeriod pd, SW_RUN *sw) { +void get_frozen_mem(OutPeriod pd, SW_RUN *sw, SW_OUT_DOM *OutDom) { LyrIndex i; SW_SOILWAT_OUTPUTS *vo = sw->SoilWat.p_oagg[pd]; size_t iOUTIndex = 0; - SW_GEN_OUT *go = &sw->GenOutput; + SW_OUT_RUN *OutRun = &sw->OutRun; - RealD *p = go->p_OUT[eSW_Frozen][pd]; + RealD *p = OutRun->p_OUT[eSW_Frozen][pd]; #if defined(RSOILWAT) get_outvalleader( - &sw->Model, pd, go->irow_OUT, go->nrow_OUT, go->tOffset, p + &sw->Model, pd, OutRun->irow_OUT, OutRun->nrow_OUT, OutRun->tOffset, p ); #endif ForEachSoilLayer(i, sw->Site.n_layers) { #if defined(RSOILWAT) - iOUTIndex = - iOUT(i, go->irow_OUT[pd], go->nrow_OUT[pd], ncol_TimeOUT[pd]); + iOUTIndex = iOUT( + i, OutRun->irow_OUT[pd], OutDom->nrow_OUT[pd], ncol_TimeOUT[pd] + ); #elif defined(SWNETCDF) iOUTIndex = - go->iOUToffset[eSW_Frozen][pd][0] + - iOUTnc(go->irow_OUT[pd], i, 0, go->nsl_OUT[eSW_Frozen][0], 1); + OutDom->iOUToffset[eSW_Frozen][pd][0] + + iOUTnc( + OutRun->irow_OUT[pd], i, 0, OutDom->nsl_OUT[eSW_Frozen][0], 1 + ); #endif p[iOUTIndex] = vo->lyrFrozen[i]; @@ -4024,10 +4505,12 @@ void get_frozen_mem(OutPeriod pd, SW_RUN *sw) { #if defined(SWNETCDF) /* Set extra soil layers to missing/fill value (up to domain-wide max) */ - for (i = sw->Site.n_layers; i < go->nsl_OUT[eSW_Frozen][0]; i++) { + for (i = sw->Site.n_layers; i < OutDom->nsl_OUT[eSW_Frozen][0]; i++) { iOUTIndex = - go->iOUToffset[eSW_Frozen][pd][0] + - iOUTnc(go->irow_OUT[pd], i, 0, go->nsl_OUT[eSW_Frozen][0], 1); + OutDom->iOUToffset[eSW_Frozen][pd][0] + + iOUTnc( + OutRun->irow_OUT[pd], i, 0, OutDom->nsl_OUT[eSW_Frozen][0], 1 + ); p[iOUTIndex] = NC_FILL_DOUBLE; } #endif // SWNETCDF @@ -4041,24 +4524,28 @@ void get_frozen_mem(OutPeriod pd, SW_RUN *sw) { @param[in] pd Time period in simulation output (day/week/month/year) @param[in] sw Comprehensive struct of type SW_RUN containing all information in the simulation. +@param[in] OutDom Struct of type SW_OUT_DOM that holds output + information that do not change throughout simulation runs */ -void get_frozen_agg(OutPeriod pd, SW_RUN *sw) { +void get_frozen_agg(OutPeriod pd, SW_RUN *sw, SW_OUT_DOM *OutDom) { LyrIndex i; SW_SOILWAT_OUTPUTS *vo = sw->SoilWat.p_oagg[pd]; size_t iOUTIndex = 0; - SW_GEN_OUT *go = &sw->GenOutput; + SW_OUT_RUN *OutRun = &sw->OutRun; - RealD *p = go->p_OUT[eSW_Frozen][pd], *psd = go->p_OUTsd[eSW_Frozen][pd]; + RealD *p = OutRun->p_OUT[eSW_Frozen][pd], + *psd = OutRun->p_OUTsd[eSW_Frozen][pd]; ForEachSoilLayer(i, sw->Site.n_layers) { - iOUTIndex = - iOUT(i, go->irow_OUT[pd], go->nrow_OUT[pd], ncol_TimeOUT[pd]); - do_running_agg(p, psd, iOUTIndex, go->currIter, vo->lyrFrozen[i]); + iOUTIndex = iOUT( + i, OutRun->irow_OUT[pd], OutDom->nrow_OUT[pd], ncol_TimeOUT[pd] + ); + do_running_agg(p, psd, iOUTIndex, OutRun->currIter, vo->lyrFrozen[i]); } - if (go->print_IterationSummary) { - go->sw_outstr_agg[0] = '\0'; - format_IterationSummary(p, psd, pd, go->ncol_OUT[eSW_Frozen], sw); + if (OutRun->print_IterationSummary) { + OutRun->sw_outstr_agg[0] = '\0'; + format_IterationSummary(p, psd, pd, OutRun->ncol_OUT[eSW_Frozen], sw); } } #endif diff --git a/src/SW_Output_outarray.c b/src/SW_Output_outarray.c index 27d1497a5..99569f8f9 100644 --- a/src/SW_Output_outarray.c +++ b/src/SW_Output_outarray.c @@ -19,7 +19,7 @@ See the \ref out_algo "output algorithm documentation" for details. #include "include/SW_Output_outarray.h" // for SW_OUT_calc_iOUToffset, SW_O... #include "include/generic.h" // for IntUS, IntU, Bool, RealD -#include "include/SW_datastructs.h" // for SW_GEN_OUT, LOG_INFO, SW_MODEL +#include "include/SW_datastructs.h" // for LOG_INFO, SW_MODEL #include "include/SW_Defines.h" // for eSW_Day, SW_OUTNMAXVARS, SW_... #include "include/SW_Output.h" // for ForEachOutKey #include "include/Times.h" // for Time_get_lastdoy_y @@ -42,7 +42,7 @@ See the \ref out_algo "output algorithm documentation" for details. and thus have `static storage duration`. The variable p_OUTsd is used by STEPWAT2 for standard-deviation during -aggregation. See also `SW_GEN_OUT.p_OUT` +aggregation. See also `SW_OUT_RUN.p_OUT` */ #define p_OUTsd #undef p_OUTsd @@ -130,31 +130,32 @@ void SW_OUT_set_nrow( /** @brief For each out key, the p_OUT array is set to NULL. -@param[in,out] GenOutput Holds general variables that deal with output +@param[in,out] OutRun Struct of type SW_OUT_RUN that holds output + information that may change throughout simulation runs */ -void SW_OUT_deconstruct_outarray(SW_GEN_OUT *GenOutput) { +void SW_OUT_deconstruct_outarray(SW_OUT_RUN *OutRun) { IntUS i, k; ForEachOutKey(k) { for (i = 0; i < SW_OUTNPERIODS; i++) { #if defined(SW_OUTARRAY) - if (!isnull(GenOutput->p_OUT[k][i])) { - free(GenOutput->p_OUT[k][i]); - GenOutput->p_OUT[k][i] = NULL; + if (!isnull(OutRun->p_OUT[k][i])) { + free(OutRun->p_OUT[k][i]); + OutRun->p_OUT[k][i] = NULL; } #endif #ifdef STEPWAT - if (!isnull(GenOutput->p_OUTsd[k][i])) { - free(GenOutput->p_OUTsd[k][i]); - GenOutput->p_OUTsd[k][i] = NULL; + if (!isnull(OutRun->p_OUTsd[k][i])) { + free(OutRun->p_OUTsd[k][i]); + OutRun->p_OUTsd[k][i] = NULL; } #endif } } #if !defined(SW_OUTARRAY) && !defined(STEPWAT) - (void) *GenOutput; + (void) *OutRun; #endif } @@ -228,36 +229,36 @@ void do_running_agg(RealD *p, RealD *psd, size_t k, IntU n, RealD x) { /** Allocate p_OUT and p_OUTsd -@param[in] SW_Output SW_OUTPUT array of size SW_OUTNKEYS which holds - basic output information for all output keys -@param[out] GenOutput Holds general variables that deal with output +@param[in] OutDom Struct of type SW_OUT_DOM that holds output + information that do not change throughout simulation runs +@param[out] OutRun Struct of type SW_OUT_RUN that holds output + information that may change throughout simulation runs @param[out] LogInfo Holds information on warnings and errors Note: Compare with function `setGlobalrSOILWAT2_OutputVariables` in `rSW_Output.c` -@sideeffect: `GenOutput->p_OUT` and `GenOutput->p_OUTsd` pointing to +@sideeffect: `OutRun->p_OUT` and `OutRun->p_OUTsd` pointing to allocated arrays for each output period and output key. */ void SW_OUT_construct_outarray( - SW_GEN_OUT *GenOutput, SW_OUTPUT *SW_Output, LOG_INFO *LogInfo + SW_OUT_DOM *OutDom, SW_OUT_RUN *OutRun, LOG_INFO *LogInfo ) { IntUS i, k; size_t size, s = sizeof(RealD); OutPeriod timeStepOutPeriod; ForEachOutKey(k) { - for (i = 0; i < GenOutput->used_OUTNPERIODS; i++) { - timeStepOutPeriod = GenOutput->timeSteps[k][i]; + for (i = 0; i < OutDom->used_OUTNPERIODS; i++) { + timeStepOutPeriod = OutDom->timeSteps[k][i]; - if (SW_Output[k].use && timeStepOutPeriod != eSW_NoTime) { + if (OutDom->use[k] && timeStepOutPeriod != eSW_NoTime) { #if defined(SW_OUTARRAY) - size = - GenOutput->nrow_OUT[timeStepOutPeriod] * - (GenOutput->ncol_OUT[k] + ncol_TimeOUT[timeStepOutPeriod]); + size = OutDom->nrow_OUT[timeStepOutPeriod] * + (OutDom->ncol_OUT[k] + ncol_TimeOUT[timeStepOutPeriod]); - GenOutput->p_OUT[k][timeStepOutPeriod] = (RealD *) Mem_Calloc( + OutRun->p_OUT[k][timeStepOutPeriod] = (RealD *) Mem_Calloc( size, s, "SW_OUT_construct_outarray()", LogInfo ); if (LogInfo->stopRun) { @@ -266,7 +267,7 @@ void SW_OUT_construct_outarray( #endif #if defined(STEPWAT) - GenOutput->p_OUTsd[k][timeStepOutPeriod] = (RealD *) Mem_Calloc( + OutRun->p_OUTsd[k][timeStepOutPeriod] = (RealD *) Mem_Calloc( size, s, "SW_OUT_construct_outarray()", LogInfo ); if (LogInfo->stopRun) { @@ -282,6 +283,7 @@ void SW_OUT_construct_outarray( (void) *LogInfo; (void) s; (void) size; + (void) OutRun; #endif } diff --git a/src/SW_Output_outtext.c b/src/SW_Output_outtext.c index b23e08364..b52a042f8 100644 --- a/src/SW_Output_outtext.c +++ b/src/SW_Output_outtext.c @@ -22,7 +22,7 @@ See the \ref out_algo "output algorithm documentation" for details. #include "include/filefuncs.h" // for CloseFile, OpenFile, LogError #include "include/generic.h" // for Bool, swFALSE, SOILWAT, IntUS #include "include/myMemory.h" // for Mem_Malloc -#include "include/SW_datastructs.h" // for LOG_INFO, SW_GEN_OUT, SW_OUTPUT +#include "include/SW_datastructs.h" // for LOG_INFO #include "include/SW_Defines.h" // for _OUTSEP, OutPeriod, ForEachOu... #include "include/SW_Output.h" // for pd2longstr, ForEachOutKey #include // for snprintf, fflush, fprintf @@ -42,7 +42,7 @@ Defined as char `sw_outstr_agg[MAX_LAYERS * OUTSTRLEN];` Used for output as returned from any function `get_XXX_agg` which aggregates output across iterations/repeats for STEPWAT2 -Active if \ref SW_GEN_OUT.print_IterationSummary is TRUE +Active if @ref SW_OUT_DOM.print_IterationSummary is TRUE */ #define sw_outstr_agg #undef sw_outstr_agg @@ -57,13 +57,12 @@ Active if \ref SW_GEN_OUT.print_IterationSummary is TRUE /* --------------------------------------------------- */ static void _create_csv_headers( + SW_OUT_DOM *OutDom, OutPeriod pd, char *str_reg, char *str_soil, Bool does_agg, LyrIndex n_layers, - SW_OUTPUT *SW_Output, - SW_GEN_OUT *GenOutput, LOG_INFO *LogInfo ) { @@ -106,17 +105,17 @@ static void _create_csv_headers( str_soil[0] = (char) '\0'; ForEachOutKey(k) { - isTrue = (Bool) (SW_Output[k].use && has_OutPeriod_inUse( - pd, - (OutKey) k, - GenOutput->used_OUTNPERIODS, - GenOutput->timeSteps - )); + isTrue = (Bool) (OutDom->use[k] && has_OutPeriod_inUse( + pd, + (OutKey) k, + OutDom->used_OUTNPERIODS, + OutDom->timeSteps + )); if (isTrue) { strcpy(key, key2str[k]); str_help2[0] = '\0'; - for (i = 0; i < GenOutput->ncol_OUT[k]; i++) { + for (i = 0; i < OutDom->ncol_OUT[k]; i++) { if (does_agg) { snprintf( str_help1, @@ -124,10 +123,10 @@ static void _create_csv_headers( "%c%s_%s_Mean%c%s_%s_SD", _OUTSEP, key, - GenOutput->colnames_OUT[k][i], + OutDom->colnames_OUT[k][i], _OUTSEP, key, - GenOutput->colnames_OUT[k][i] + OutDom->colnames_OUT[k][i] ); } else { snprintf( @@ -136,14 +135,14 @@ static void _create_csv_headers( "%c%s_%s", _OUTSEP, key, - GenOutput->colnames_OUT[k][i] + OutDom->colnames_OUT[k][i] ); } strcat(str_help2, str_help1); } - if (SW_Output[k].has_sl) { + if (OutDom->has_sl[k]) { strcat((char *) str_soil, str_help2); } else { strcat((char *) str_reg, str_help2); @@ -402,43 +401,38 @@ static void _create_csv_file_ST( /** @brief create all of the user-specified output text files. +@param[in] OutDom Struct of type SW_OUT_DOM that holds output + information that do not change throughout simulation runs @param[in,out] SW_FileStatus Struct of type SW_FILE_STATUS which holds basic information about output files and values -@param[in] SW_Output SW_OUTPUT array of size SW_OUTNKEYS which holds - basic output information for all output keys @param[in] n_layers Number of layers of soil within the simulation run @param[in] InFiles Array of program in/output files -@param[in] GenOutput Holds general variables that deal with output @param[out] LogInfo Holds information on warnings and errors */ void SW_OUT_create_textfiles( + SW_OUT_DOM *OutDom, SW_FILE_STATUS *SW_FileStatus, - SW_OUTPUT *SW_Output, LyrIndex n_layers, char *InFiles[], - SW_GEN_OUT *GenOutput, LOG_INFO *LogInfo ) { OutPeriod pd; ForEachOutPeriod(pd) { - if (GenOutput->use_OutPeriod[pd]) { + if (OutDom->use_OutPeriod[pd]) { _create_csv_files(SW_FileStatus, pd, InFiles, LogInfo); if (LogInfo->stopRun) { return; // Exit function prematurely due to error } write_headers_to_csv( + OutDom, pd, SW_FileStatus->fp_reg[pd], SW_FileStatus->fp_soil[pd], swFALSE, - SW_FileStatus->make_regular, - SW_FileStatus->make_soil, - SW_Output, n_layers, - GenOutput, LogInfo ); if (LogInfo->stopRun) { @@ -451,9 +445,8 @@ void SW_OUT_create_textfiles( #elif defined(STEPWAT) void SW_OUT_create_summary_files( + SW_OUT_DOM *OutDom, SW_FILE_STATUS *SW_FileStatus, - SW_OUTPUT *SW_Output, - SW_GEN_OUT *GenOutput, char *InFiles[], LyrIndex n_layers, LOG_INFO *LogInfo @@ -469,15 +462,12 @@ void SW_OUT_create_summary_files( } write_headers_to_csv( + OutDom, p, SW_FileStatus->fp_reg_agg[p], SW_FileStatus->fp_soil_agg[p], swTRUE, - SW_FileStatus->make_regular, - SW_FileStatus->make_soil, - SW_Output, n_layers, - GenOutput, LogInfo ); if (LogInfo->stopRun) { @@ -488,10 +478,9 @@ void SW_OUT_create_summary_files( } void SW_OUT_create_iteration_files( + SW_OUT_DOM *OutDom, SW_FILE_STATUS *SW_FileStatus, - SW_OUTPUT *SW_Output, int iteration, - SW_GEN_OUT *GenOutput, char *InFiles[], LyrIndex n_layers, LOG_INFO *LogInfo @@ -507,15 +496,12 @@ void SW_OUT_create_iteration_files( } write_headers_to_csv( + OutDom, p, SW_FileStatus->fp_reg[p], SW_FileStatus->fp_soil[p], swFALSE, - SW_FileStatus->make_regular, - SW_FileStatus->make_soil, - SW_Output, n_layers, - GenOutput, LogInfo ); if (LogInfo->stopRun) { @@ -593,31 +579,23 @@ header in the output file. be called before _create_csv_headers(); otherwise, `ncol_OUT` and `colnames_OUT` are not set. +@param OutDom Struct of type SW_OUT_DOM that holds output + information that do not change throughout simulation runs @param pd timeperiod so it can write headers to correct output file. @param fp_reg name of file. @param fp_soil name of file. @param does_agg Indicate whether output is aggregated (`-o` option) or for each SOILWAT2 run (`-i` option) @param n_layers Number of soil layers being dealt with in a simulation -@param make_regular Array of size SW_OUTNPERIODS which holds boolean values - specifying to output "regular" header names -@param make_soil Array of size SW_OUTNPERIODS which holds boolean values - specifying to output a soil-related header names -@param SW_Output SW_OUTPUT array of size SW_OUTNKEYS which holds basic output - information for all output keys -@param GenOutput Holds general variables that deal with output @param LogInfo Holds information on warnings and errors */ void write_headers_to_csv( + SW_OUT_DOM *OutDom, OutPeriod pd, FILE *fp_reg, FILE *fp_soil, Bool does_agg, - Bool make_regular[], - Bool make_soil[], - SW_OUTPUT *SW_Output, LyrIndex n_layers, - SW_GEN_OUT *GenOutput, LOG_INFO *LogInfo ) { @@ -641,14 +619,7 @@ void write_headers_to_csv( // Acquire headers get_outstrheader(pd, str_time, sizeof str_time); _create_csv_headers( - pd, - header_reg, - header_soil, - does_agg, - n_layers, - SW_Output, - GenOutput, - LogInfo + OutDom, pd, header_reg, header_soil, does_agg, n_layers, LogInfo ); if (LogInfo->stopRun) { free(header_soil); @@ -672,7 +643,7 @@ void write_headers_to_csv( void find_TXToutputSoilReg_inUse( Bool make_soil[], Bool make_regular[], - SW_OUTPUT *SW_Output, + Bool has_sl[], OutPeriod timeSteps[][SW_OUTNPERIODS], IntUS used_OUTNPERIODS ) { @@ -686,7 +657,7 @@ void find_TXToutputSoilReg_inUse( ForEachOutKey(k) { for (i = 0; i < used_OUTNPERIODS; i++) { if (timeSteps[k][i] != eSW_NoTime) { - if (SW_Output[k].has_sl) { + if (has_sl[k]) { make_soil[timeSteps[k][i]] = swTRUE; } else { make_regular[timeSteps[k][i]] = swTRUE; @@ -703,11 +674,12 @@ call this routine at the end of the program run. @param[in,out] SW_FileStatus Struct of type SW_FILE_STATUS which holds basic information about output files and values -@param[in] GenOutput Holds general variables that deal with output +@param[in] OutDom Struct of type SW_OUT_DOM that holds output + information that do not change throughout simulation runs @param[out] LogInfo Holds information on warnings and errors */ void SW_OUT_close_textfiles( - SW_FILE_STATUS *SW_FileStatus, SW_GEN_OUT *GenOutput, LOG_INFO *LogInfo + SW_FILE_STATUS *SW_FileStatus, SW_OUT_DOM *OutDom, LOG_INFO *LogInfo ) { Bool close_regular = swFALSE, close_layers = swFALSE, close_aggs = swFALSE; @@ -722,16 +694,16 @@ void SW_OUT_close_textfiles( #elif defined(STEPWAT) close_regular = (Bool) (SW_FileStatus->make_regular[p] && - GenOutput->storeAllIterations); - close_layers = (Bool) (SW_FileStatus->make_soil[p] && - GenOutput->storeAllIterations); + OutDom->storeAllIterations); + close_layers = + (Bool) (SW_FileStatus->make_soil[p] && OutDom->storeAllIterations); close_aggs = (Bool) ((SW_FileStatus->make_regular[p] || SW_FileStatus->make_soil[p]) && - GenOutput->prepare_IterationSummary); + OutDom->prepare_IterationSummary); #endif - if (GenOutput->use_OutPeriod[p]) { + if (OutDom->use_OutPeriod[p]) { if (close_regular) { CloseFile(&SW_FileStatus->fp_reg[p], LogInfo); } diff --git a/src/SW_netCDF.c b/src/SW_netCDF.c index 7aaa8399c..59e359e5b 100644 --- a/src/SW_netCDF.c +++ b/src/SW_netCDF.c @@ -1320,7 +1320,7 @@ static void alloc_netCDF_domain_vars( /** @brief Allocate memory for information in regards to output variables -respective to SW_OUTPUT instances +within SW_OUT_DOM @param[out] outkeyVars Holds all information about output variables in netCDFs (e.g., output variable name) @@ -1381,7 +1381,7 @@ static void alloc_outReq(Bool **reqOutVar, int nVar, LOG_INFO *LogInfo) { if (nVar > 0) { - // Initialize the variable within SW_OUTPUT which specifies if a + // Initialize the variable within SW_OUT_DOM which specifies if a // variable is to be written out or not *reqOutVar = (Bool *) Mem_Malloc(sizeof(Bool) * nVar, "alloc_outReq()", LogInfo); @@ -1408,7 +1408,7 @@ static void alloc_unitssw(char ***units_sw, int nVar, LOG_INFO *LogInfo) { if (nVar > 0) { - // Initialize the variable within SW_OUTPUT + // Initialize the variable within SW_OUT_DOM *units_sw = (char **) Mem_Malloc( sizeof(char *) * nVar, "alloc_unitssw()", LogInfo ); @@ -2998,8 +2998,7 @@ is represented by - soil layer depths (if entire domain has the same soil layer profile) - soil layer number (if soil layer profile varies across domain) -@param[in] SW_Output SW_OUTPUT array of size SW_OUTNKEYS which holds - basic output information for all output keys +@param[in] OutDom @param[in] domFile Domain netCDF file name @param[in] domType Type of domain in which simulations are running (gridcell/sites) @@ -3027,7 +3026,7 @@ SW_OUTNPERIODS). @param[in] LogInfo Holds information on warnings and errors */ static void create_output_file( - SW_OUTPUT *SW_Output, + SW_OUT_DOM *OutDom, const char *domFile, const char *domType, const char *newFileName, @@ -3056,7 +3055,7 @@ static void create_output_file( "units_metadata" }; char *attVals[MAX_NATTS] = {NULL}; - OutSum sumType = SW_Output->sumtype; + OutSum sumType = OutDom->sumtype[key]; int numAtts = 0; const int nameAtt = 0; @@ -3090,9 +3089,9 @@ static void create_output_file( // Add output variables for (index = 0; index < nVar; index++) { - if (SW_Output->reqOutputVars[index]) { - varInfo = SW_Output->outputVarInfo[index]; - varName = SW_Output->outputVarInfo[index][VARNAME_INDEX]; + if (OutDom->reqOutputVars[key][index]) { + varInfo = OutDom->outputVarInfo[key][index]; + varName = OutDom->outputVarInfo[key][index][VARNAME_INDEX]; numAtts = gather_var_attributes( varInfo, key, pd, index, attVals, sumType, LogInfo @@ -3336,9 +3335,10 @@ static void check_counts_against_vardim( @brief Write values to output variables in previously-created output netCDF files -@param[in] SW_Output SW_OUTPUT array of size SW_OUTNKEYS which holds - basic output information for all output keys -@param[in] GenOutput Holds general variables that deal with output +@param[in] OutDom Struct of type SW_OUT_DOM that holds output + information that do not change throughout simulation runs +@param[in] p_OUT Array of accumulated output values throughout + simulation years @param[in] numFilesPerKey Number of output netCDFs each output key will have (same amount for each key) @param[in] ncOutFileNames A list of the generated output netCDF file names @@ -3348,8 +3348,8 @@ output netCDF files @param[out] LogInfo Holds information on warnings and errors */ void SW_NC_write_output( - SW_OUTPUT *SW_Output, - SW_GEN_OUT *GenOutput, + SW_OUT_DOM *OutDom, + RealD *p_OUT[][SW_OUTNPERIODS], int numFilesPerKey, char **ncOutFileNames[][SW_OUTNPERIODS], size_t ncSuid[], @@ -3373,12 +3373,12 @@ void SW_NC_write_output( ForEachOutPeriod(pd) { - if (!GenOutput->use_OutPeriod[pd]) { + if (!OutDom->use_OutPeriod[pd]) { continue; // Skip period iteration } ForEachOutKey(key) { - if (GenOutput->nvar_OUT[key] == 0 || !SW_Output[key].use) { + if (OutDom->nvar_OUT[key] == 0 || !OutDom->use[key]) { continue; // Skip key iteration } @@ -3412,13 +3412,12 @@ void SW_NC_write_output( } - for (varNum = 0; varNum < GenOutput->nvar_OUT[key]; varNum++) { - if (!SW_Output[key].reqOutputVars[varNum]) { + for (varNum = 0; varNum < OutDom->nvar_OUT[key]; varNum++) { + if (!OutDom->reqOutputVars[key][varNum]) { continue; // Skip variable iteration } - varName = - SW_Output[key].outputVarInfo[varNum][VARNAME_INDEX]; + varName = OutDom->outputVarInfo[key][varNum][VARNAME_INDEX]; // Locate correct slice in netCDF to write to get_var_identifier(currFileID, varName, &varID, LogInfo); @@ -3429,8 +3428,8 @@ void SW_NC_write_output( get_vardim_write_counts( domType, timeSize, - GenOutput->nsl_OUT[key][varNum], - GenOutput->npft_OUT[key][varNum], + OutDom->nsl_OUT[key][varNum], + OutDom->npft_OUT[key][varNum], count, &countTotal ); @@ -3448,28 +3447,28 @@ void SW_NC_write_output( /* Point to contiguous memory where values change fastest for vegtypes, then soil layers, then time, then variables */ - pOUTIndex = GenOutput->iOUToffset[key][pd][varNum]; + pOUTIndex = OutDom->iOUToffset[key][pd][varNum]; if (startTime > 0) { // 1 if no soil layers - vertSize = (GenOutput->nsl_OUT[key][varNum] > 0) ? - GenOutput->nsl_OUT[key][varNum] : + vertSize = (OutDom->nsl_OUT[key][varNum] > 0) ? + OutDom->nsl_OUT[key][varNum] : 1; // 1 if no vegtypes - pftSize = (GenOutput->npft_OUT[key][varNum] > 0) ? - GenOutput->npft_OUT[key][varNum] : + pftSize = (OutDom->npft_OUT[key][varNum] > 0) ? + OutDom->npft_OUT[key][varNum] : 1; pOUTIndex += iOUTnc(startTime, 0, 0, vertSize, pftSize); } - p_OUTValPtr = &GenOutput->p_OUT[key][pd][pOUTIndex]; + p_OUTValPtr = &p_OUT[key][pd][pOUTIndex]; /* Convert units if udunits2 and if converter available */ #if defined(SWUDUNITS) - if (!isnull(SW_Output[key].uconv[varNum])) { + if (!isnull(OutDom->uconv[key][varNum])) { cv_convert_doubles( - SW_Output[key].uconv[varNum], + OutDom->uconv[key][varNum], p_OUTValPtr, countTotal, p_OUTValPtr @@ -3519,8 +3518,6 @@ is represented by @param[in] output_prefix Directory path of output files. @param[in] SW_Domain Struct of type SW_DOMAIN holding constant temporal/spatial information for a set of simulation runs -@param[in] SW_Output SW_OUTPUT array of size SW_OUTNKEYS which holds - basic output information for all output keys @param[in] timeSteps Requested time steps @param[in] used_OUTNPERIODS Determine which output periods to output @param[in] nvar_OUT Number of output variables (array of length @@ -3547,7 +3544,6 @@ void SW_NC_create_output_files( const char *domType, const char *output_prefix, SW_DOMAIN *SW_Domain, - SW_OUTPUT *SW_Output, OutPeriod timeSteps[][SW_OUTNPERIODS], IntUS used_OUTNPERIODS, IntUS nvar_OUT[], @@ -3586,7 +3582,7 @@ void SW_NC_create_output_files( yearFormat = (strideOutYears == 1) ? (char *) "%d" : (char *) "%d-%d"; ForEachOutKey(key) { - if (nvar_OUT[key] > 0 && SW_Output[key].use) { + if (nvar_OUT[key] > 0 && SW_Domain->OutDom.use[key]) { // Loop over requested output periods (which may vary for each // outkey) @@ -3646,7 +3642,7 @@ void SW_NC_create_output_files( ); create_output_file( - &SW_Output[key], + &SW_Domain->OutDom, domFile, domType, fileNameBuf, @@ -4648,17 +4644,15 @@ This function requires previous calls to - SW_VES_read2() to set parms - SW_OUT_setup_output() to set GenOutput.nvar_OUT -@param[in,out] SW_Output SW_OUTPUT array of size SW_OUTNKEYS which holds - basic output information for all output keys -@param[in] GenOutput Holds general variables that deal with output +@param[in,out] OutDom Struct of type SW_OUT_DOM that holds output + information that do not change throughout simulation runs @param[in] InFiles Array of program in/output files @param[in] parms Array of type SW_VEGESTAB_INFO holding information about species @param[out] LogInfo Holds information on warnings and errors */ void SW_NC_read_out_vars( - SW_OUTPUT *SW_Output, - SW_GEN_OUT *GenOutput, + SW_OUT_DOM *OutDom, char *InFiles[], SW_VEGESTAB_INFO **parms, LOG_INFO *LogInfo @@ -4666,7 +4660,6 @@ void SW_NC_read_out_vars( FILE *f; OutKey currOutKey; - SW_OUTPUT *currOut; char inbuf[MAX_FILENAMESIZE], *MyFileName; char varKey[MAX_FILENAMESIZE]; int varNum = 0, lineno = 0; @@ -4696,7 +4689,7 @@ void SW_NC_read_out_vars( return; // Exit prematurely due to error } - SW_NC_alloc_output_var_info(SW_Output, GenOutput->nvar_OUT, LogInfo); + SW_NC_alloc_output_var_info(OutDom, LogInfo); if (LogInfo->stopRun) { return; // Exit prematurely due to error } @@ -4751,9 +4744,7 @@ void SW_NC_read_out_vars( input[SWVarNameInd] ); - get_2d_output_key( - varKey, &currOutKey, &varNum, GenOutput->nvar_OUT - ); + get_2d_output_key(varKey, &currOutKey, &varNum, OutDom->nvar_OUT); if (currOutKey == eSW_NoKey) { LogError( @@ -4769,9 +4760,7 @@ void SW_NC_read_out_vars( continue; } - currOut = &SW_Output[currOutKey]; - - if (!currOut->use) { + if (!OutDom->use[currOutKey]) { // key not in use // don't output any of the variables within that outkey group continue; @@ -4822,14 +4811,14 @@ void SW_NC_read_out_vars( estabFound = swTRUE; varNum = 0; - if (GenOutput->nvar_OUT[currOutKey] == 0) { + if (OutDom->nvar_OUT[currOutKey] == 0) { // outsetup.in and nc-out request ESTAB but no taxon // available continue; } } - currOut->reqOutputVars[varNum] = swTRUE; + OutDom->reqOutputVars[currOutKey][varNum] = swTRUE; // Read in the rest of the attributes // Output variable name, long name, comment, units, and cell_method @@ -4859,13 +4848,13 @@ void SW_NC_read_out_vars( // into `count` amount of variables and give the // correct 's if (currOutKey == eSW_Estab) { - for (estVar = 0; estVar < GenOutput->nvar_OUT[currOutKey]; + for (estVar = 0; estVar < OutDom->nvar_OUT[currOutKey]; estVar++) { switch (index) { case VARNAME_INDEX: - currOut->reqOutputVars[estVar] = swTRUE; - currOut->outputVarInfo[estVar][index] = + OutDom->reqOutputVars[currOutKey][estVar] = swTRUE; + OutDom->outputVarInfo[currOutKey][estVar][index] = Str_Dup(parms[estVar]->sppname, LogInfo); break; @@ -4876,12 +4865,12 @@ void SW_NC_read_out_vars( copyStr, parms[estVar]->sppname ); - currOut->outputVarInfo[estVar][index] = + OutDom->outputVarInfo[currOutKey][estVar][index] = Str_Dup(establn, LogInfo); break; default: - currOut->outputVarInfo[estVar][index] = + OutDom->outputVarInfo[currOutKey][estVar][index] = Str_Dup(copyStr, LogInfo); break; } @@ -4891,7 +4880,7 @@ void SW_NC_read_out_vars( } } } else { - currOut->outputVarInfo[varNum][index] = + OutDom->outputVarInfo[currOutKey][varNum][index] = Str_Dup(copyStr, LogInfo); if (LogInfo->stopRun) { return; // Exit function prematurely due to error @@ -4902,16 +4891,16 @@ void SW_NC_read_out_vars( // Copy SW units for later use if (currOutKey == eSW_Estab) { - for (estVar = 0; estVar < GenOutput->nvar_OUT[currOutKey]; + for (estVar = 0; estVar < OutDom->nvar_OUT[currOutKey]; estVar++) { - currOut->units_sw[estVar] = + OutDom->units_sw[currOutKey][estVar] = Str_Dup(SWVarUnits[currOutKey][varNumUnits], LogInfo); if (LogInfo->stopRun) { return; // Exit function prematurely due to error } } } else { - currOut->units_sw[varNum] = + OutDom->units_sw[currOutKey][varNum] = Str_Dup(SWVarUnits[currOutKey][varNumUnits], LogInfo); if (LogInfo->stopRun) { return; // Exit function prematurely due to error @@ -4924,7 +4913,7 @@ void SW_NC_read_out_vars( // Update "use": turn off if no variable of an outkey group is requested ForEachOutKey(index) { if (!used_OutKeys[index]) { - SW_Output[index].use = swFALSE; + OutDom->use[index] = swFALSE; } } } @@ -4937,14 +4926,11 @@ This function requires previous calls to - SW_NC_read_out_vars() to obtain user requested output units - SW_OUT_setup_output() to set GenOutput.nvar_OUT for argument nVars -@param[in,out] SW_Output SW_OUTPUT array of size SW_OUTNKEYS which holds - basic output information for all output keys -@param[in] nVars Array with number of output variables +@param[in,out] OutDom Struct of type SW_OUT_DOM that holds output + information that do not change throughout simulation runs @param[out] LogInfo Holds information on warnings and errors */ -void SW_NC_create_units_converters( - SW_OUTPUT *SW_Output, IntUS *nVars, LOG_INFO *LogInfo -) { +void SW_NC_create_units_converters(SW_OUT_DOM *OutDom, LOG_INFO *LogInfo) { int varIndex, key; #if defined(SWUDUNITS) @@ -4959,34 +4945,33 @@ void SW_NC_create_units_converters( #endif ForEachOutKey(key) { - if (!SW_Output[key].use) { + if (!OutDom->use[key]) { continue; // Skip key iteration } - for (varIndex = 0; varIndex < nVars[key]; varIndex++) { - if (!SW_Output[key].reqOutputVars[varIndex]) { + for (varIndex = 0; varIndex < OutDom->nvar_OUT[key]; varIndex++) { + if (!OutDom->reqOutputVars[key][varIndex]) { continue; // Skip variable iteration } #if defined(SWUDUNITS) - if (!isnull(SW_Output[key].units_sw[varIndex])) { - unitFrom = ut_parse( - system, SW_Output[key].units_sw[varIndex], UT_UTF8 - ); + if (!isnull(OutDom->units_sw[key][varIndex])) { + unitFrom = + ut_parse(system, OutDom->units_sw[key][varIndex], UT_UTF8); unitTo = ut_parse( system, - SW_Output[key].outputVarInfo[varIndex][UNITS_INDEX], + OutDom->outputVarInfo[key][varIndex][UNITS_INDEX], UT_UTF8 ); if (ut_are_convertible(unitFrom, unitTo)) { - // SW_Output[key].uconv[varIndex] was previously initialized + // OutDom.uconv[key][varIndex] was previously initialized // to NULL - SW_Output[key].uconv[varIndex] = + OutDom->uconv[key][varIndex] = ut_get_converter(unitFrom, unitTo); } - if (isnull(SW_Output[key].uconv[varIndex])) { + if (isnull(OutDom->uconv[key][varIndex])) { // ut_are_convertible() is false or ut_get_converter() // failed LogError( @@ -4995,15 +4980,15 @@ void SW_NC_create_units_converters( "Units of variable '%s' cannot get converted from " "internal '%s' to requested '%s'. " "Output will use internal units.", - SW_Output[key].outputVarInfo[varIndex][VARNAME_INDEX], - SW_Output[key].units_sw[varIndex], - SW_Output[key].outputVarInfo[varIndex][UNITS_INDEX] + OutDom->outputVarInfo[key][varIndex][VARNAME_INDEX], + OutDom->units_sw[key][varIndex], + OutDom->outputVarInfo[key][varIndex][UNITS_INDEX] ); /* converter is not available: output in internal units */ - free(SW_Output[key].outputVarInfo[varIndex][UNITS_INDEX]); - SW_Output[key].outputVarInfo[varIndex][UNITS_INDEX] = - Str_Dup(SW_Output[key].units_sw[varIndex], LogInfo); + free(OutDom->outputVarInfo[key][varIndex][UNITS_INDEX]); + OutDom->outputVarInfo[key][varIndex][UNITS_INDEX] = + Str_Dup(OutDom->units_sw[key][varIndex], LogInfo); } ut_free(unitFrom); @@ -5012,10 +4997,10 @@ void SW_NC_create_units_converters( #else /* udunits2 is not available: output in internal units */ - free(SW_Output[key].outputVarInfo[varIndex][UNITS_INDEX]); - if (!isnull(SW_Output[key].units_sw[varIndex])) { - SW_Output[key].outputVarInfo[varIndex][UNITS_INDEX] = - Str_Dup(SW_Output[key].units_sw[varIndex], LogInfo); + free(OutDom->outputVarInfo[key][varIndex][UNITS_INDEX]); + if (!isnull(OutDom->units_sw[key][varIndex])) { + OutDom->outputVarInfo[key][varIndex][UNITS_INDEX] = + Str_Dup(OutDom->units_sw[key][varIndex], LogInfo); } #endif @@ -5256,18 +5241,17 @@ void SW_NC_deepCopy(SW_NETCDF *source, SW_NETCDF *dest, LOG_INFO *LogInfo) { @brief Wrapper function to allocate output request variables and output variable information -@param[out] SW_Output SW_OUTPUT array of size SW_OUTNKEYS which holds - basic output information for all output keys -@param[in] nVars Array with number of output variables +@param[out] OutDom Struct of type SW_OUT_DOM that holds output + information that do not change throughout simulation runs @param[out] LogInfo Holds information on warnings and errors */ -void SW_NC_alloc_output_var_info( - SW_OUTPUT *SW_Output, IntUS *nVars, LOG_INFO *LogInfo -) { +void SW_NC_alloc_output_var_info(SW_OUT_DOM *OutDom, LOG_INFO *LogInfo) { int key; ForEachOutKey(key) { - SW_NC_alloc_outputkey_var_info(&SW_Output[key], nVars[key], LogInfo); + SW_NC_alloc_outputkey_var_info( + OutDom, key, LogInfo + ); if (LogInfo->stopRun) { return; // Exit function prematurely due to error } @@ -5275,87 +5259,85 @@ void SW_NC_alloc_output_var_info( } void SW_NC_alloc_outputkey_var_info( - SW_OUTPUT *currOut, IntUS nVar, LOG_INFO *LogInfo + SW_OUT_DOM *OutDom, int key, LOG_INFO *LogInfo ) { - alloc_outReq(&currOut->reqOutputVars, nVar, LogInfo); + alloc_outReq(&OutDom->reqOutputVars[key], OutDom->nvar_OUT[key], LogInfo); if (LogInfo->stopRun) { return; // Exit function prematurely due to error } - alloc_outvars(&currOut->outputVarInfo, nVar, LogInfo); + alloc_outvars(&OutDom->outputVarInfo[key], OutDom->nvar_OUT[key], LogInfo); if (LogInfo->stopRun) { return; // Exit function prematurely due to error } - alloc_unitssw(&currOut->units_sw, nVar, LogInfo); + alloc_unitssw(&OutDom->units_sw[key], OutDom->nvar_OUT[key], LogInfo); if (LogInfo->stopRun) { return; // Exit function prematurely due to error } - alloc_uconv(&currOut->uconv, nVar, LogInfo); + alloc_uconv(&OutDom->uconv[key], OutDom->nvar_OUT[key], LogInfo); if (LogInfo->stopRun) { return; // Exit function prematurely due to error } } -void SW_NC_dealloc_outputkey_var_info( - SW_OUTPUT *SW_Output, IntUS k, IntUS *nVars -) { - if (!isnull(SW_Output[k].outputVarInfo)) { +void SW_NC_dealloc_outputkey_var_info(SW_OUT_DOM *OutDom, IntUS k) { + if (!isnull(OutDom->outputVarInfo[k])) { - for (int varNum = 0; varNum < nVars[k]; varNum++) { + for (int varNum = 0; varNum < OutDom->nvar_OUT[k]; varNum++) { - if (!isnull(SW_Output[k].outputVarInfo[varNum])) { + if (!isnull(OutDom->outputVarInfo[k][varNum])) { for (int attNum = 0; attNum < NUM_OUTPUT_INFO; attNum++) { - if (!isnull(SW_Output[k].outputVarInfo[varNum][attNum])) { - free(SW_Output[k].outputVarInfo[varNum][attNum]); - SW_Output[k].outputVarInfo[varNum][attNum] = NULL; + if (!isnull(OutDom->outputVarInfo[k][varNum][attNum])) { + free(OutDom->outputVarInfo[k][varNum][attNum]); + OutDom->outputVarInfo[k][varNum][attNum] = NULL; } } - free(SW_Output[k].outputVarInfo[varNum]); - SW_Output[k].outputVarInfo[varNum] = NULL; + free(OutDom->outputVarInfo[k][varNum]); + OutDom->outputVarInfo[k][varNum] = NULL; } } - free(SW_Output[k].outputVarInfo); - SW_Output[k].outputVarInfo = NULL; + free(OutDom->outputVarInfo[k]); + OutDom->outputVarInfo[k] = NULL; } - if (!isnull(SW_Output[k].units_sw)) { - for (int varNum = 0; varNum < nVars[k]; varNum++) { - if (!isnull(SW_Output[k].units_sw[varNum])) { - free(SW_Output[k].units_sw[varNum]); - SW_Output[k].units_sw[varNum] = NULL; + if (!isnull(OutDom->units_sw[k])) { + for (int varNum = 0; varNum < OutDom->nvar_OUT[k]; varNum++) { + if (!isnull(OutDom->units_sw[k][varNum])) { + free(OutDom->units_sw[k][varNum]); + OutDom->units_sw[k][varNum] = NULL; } } - free(SW_Output[k].units_sw); - SW_Output[k].units_sw = NULL; + free(OutDom->units_sw[k]); + OutDom->units_sw[k] = NULL; } - if (!isnull(SW_Output[k].uconv)) { - for (int varNum = 0; varNum < nVars[k]; varNum++) { - if (!isnull(SW_Output[k].uconv[varNum])) { + if (!isnull(OutDom->uconv[k])) { + for (int varNum = 0; varNum < OutDom->nvar_OUT[k]; varNum++) { + if (!isnull(OutDom->uconv[k][varNum])) { #if defined(SWNETCDF) && defined(SWUDUNITS) - cv_free(SW_Output[k].uconv[varNum]); + cv_free(OutDom->uconv[k][varNum]); #else - free(SW_Output[k].uconv[varNum]); + free(OutDom->uconv[k][varNum]); #endif - SW_Output[k].uconv[varNum] = NULL; + OutDom->uconv[k][varNum] = NULL; } } - free(SW_Output[k].uconv); - SW_Output[k].uconv = NULL; + free(OutDom->uconv[k]); + OutDom->uconv[k] = NULL; } - if (!isnull(SW_Output[k].reqOutputVars)) { - free(SW_Output[k].reqOutputVars); - SW_Output[k].reqOutputVars = NULL; + if (!isnull(OutDom->reqOutputVars[k])) { + free(OutDom->reqOutputVars[k]); + OutDom->reqOutputVars[k] = NULL; } } diff --git a/tests/gtests/sw_testhelpers.cc b/tests/gtests/sw_testhelpers.cc index 6cbdde514..471f8ec86 100644 --- a/tests/gtests/sw_testhelpers.cc +++ b/tests/gtests/sw_testhelpers.cc @@ -15,7 +15,6 @@ SW_RUN template_SW_All; SW_DOMAIN template_SW_Domain; -SW_OUTPUT_POINTERS template_SW_OutputPtrs[SW_OUTNKEYS]; /** @brief Creates soil layers based on function arguments (instead of reading @@ -141,8 +140,7 @@ void setup_SW_Site_for_tests(SW_SITE *SW_Site) { /* Set up global variables for testing and read in values from SOILWAT2 example - Prepares global variables `template_SW_Domain`, `template_SW_All`, and - `template_SW_OutputPtrs`. + Prepares global variables `template_SW_Domain`, `template_SW_All`. The purpose is to read in text files once, and then have `AllTestFixture` create deep copies for each test. @@ -177,7 +175,7 @@ int setup_testGlobalSoilwatTemplate() { goto finishProgram; } - SW_CTL_setup_model(&template_SW_All, template_SW_OutputPtrs, &LogInfo); + SW_CTL_setup_model(&template_SW_All, &template_SW_Domain.OutDom, &LogInfo); if (LogInfo.stopRun) { goto finishProgram; } @@ -197,7 +195,10 @@ int setup_testGlobalSoilwatTemplate() { } SW_CTL_read_inputs_from_disk( - &template_SW_All, &template_SW_Domain.PathInfo, &LogInfo + &template_SW_All, + &template_SW_Domain.OutDom, + &template_SW_Domain.PathInfo, + &LogInfo ); if (LogInfo.stopRun) { goto finishProgram; @@ -234,7 +235,7 @@ int setup_testGlobalSoilwatTemplate() { template_SW_All.Site.n_layers, template_SW_All.Site.n_evap_lyrs, &template_SW_All.VegEstab, - &template_SW_All.GenOutput, + &template_SW_Domain.OutDom, &LogInfo ); if (LogInfo.stopRun) { diff --git a/tests/gtests/sw_testhelpers.h b/tests/gtests/sw_testhelpers.h index 45875526b..92aabe539 100644 --- a/tests/gtests/sw_testhelpers.h +++ b/tests/gtests/sw_testhelpers.h @@ -10,7 +10,6 @@ extern SW_RUN template_SW_All; extern SW_DOMAIN template_SW_Domain; -extern SW_OUTPUT_POINTERS template_SW_OutputPtrs[SW_OUTNKEYS]; // get length of an array @@ -58,7 +57,6 @@ class AllTestFixture : public ::testing::Test { SW_RUN SW_All; SW_DOMAIN SW_Domain; LOG_INFO LogInfo; - SW_OUTPUT_POINTERS SW_OutputPtrs[SW_OUTNKEYS]; // Deep copy global test variables // (that were set up by `setup_testGlobalSoilwatTemplate()`) to @@ -66,12 +64,26 @@ class AllTestFixture : public ::testing::Test { void SetUp() override { sw_init_logs(NULL, &LogInfo); - memcpy(&SW_OutputPtrs, &template_SW_OutputPtrs, sizeof(SW_OutputPtrs)); +#if defined(SWNETCDF) + memcpy( + SW_Domain.OutDom.pfunc_mem, + template_SW_Domain.OutDom.pfunc_mem, + sizeof(void *) * SW_OUTNKEYS + ); +#else + memcpy( + SW_Domain.OutDom.pfunc_text, + template_SW_Domain.OutDom.pfunc_text, + sizeof(void *) * SW_OUTNKEYS + ); +#endif SW_DOM_deepCopy(&template_SW_Domain, &SW_Domain, &LogInfo); sw_fail_on_error(&LogInfo); - SW_ALL_deepCopy(&template_SW_All, &SW_All, &LogInfo); + SW_ALL_deepCopy( + &template_SW_All, &SW_All, &template_SW_Domain.OutDom, &LogInfo + ); sw_fail_on_error(&LogInfo); } diff --git a/tests/gtests/test_SW_SpinUp.cc b/tests/gtests/test_SW_SpinUp.cc index 953441cda..3d38d849f 100644 --- a/tests/gtests/test_SW_SpinUp.cc +++ b/tests/gtests/test_SW_SpinUp.cc @@ -36,13 +36,13 @@ TEST_F(SpinUpTest, Mode1WithScopeGreaterThanDuration) { SW_All.Model.SW_SpinUp.spinup = swTRUE; // Run the spinup - SW_CTL_run_spinup(&SW_All, &LogInfo); + SW_CTL_run_spinup(&SW_All, &SW_Domain.OutDom, &LogInfo); sw_fail_on_error(&LogInfo); // Run (a short) simulation SW_All.Model.startyr = 1980; SW_All.Model.endyr = 1981; - SW_CTL_main(&SW_All, SW_OutputPtrs, &LogInfo); + SW_CTL_main(&SW_All, &SW_Domain.OutDom, &LogInfo); sw_fail_on_error(&LogInfo); // exit test program if unexpected error for (i = 0; i < n; i++) { @@ -82,13 +82,13 @@ TEST_F(SpinUpTest, Mode1WithScopeEqualToDuration) { SW_All.Model.SW_SpinUp.spinup = swTRUE; // Run the spinup - SW_CTL_run_spinup(&SW_All, &LogInfo); + SW_CTL_run_spinup(&SW_All, &SW_Domain.OutDom, &LogInfo); sw_fail_on_error(&LogInfo); // Run (a short) simulation SW_All.Model.startyr = 1980; SW_All.Model.endyr = 1981; - SW_CTL_main(&SW_All, SW_OutputPtrs, &LogInfo); + SW_CTL_main(&SW_All, &SW_Domain.OutDom, &LogInfo); sw_fail_on_error(&LogInfo); // exit test program if unexpected error for (i = 0; i < n; i++) { @@ -128,13 +128,13 @@ TEST_F(SpinUpTest, Mode1WithScopeLessThanDuration) { SW_All.Model.SW_SpinUp.spinup = swTRUE; // Run the spinup - SW_CTL_run_spinup(&SW_All, &LogInfo); + SW_CTL_run_spinup(&SW_All, &SW_Domain.OutDom, &LogInfo); sw_fail_on_error(&LogInfo); // Run (a short) simulation SW_All.Model.startyr = 1980; SW_All.Model.endyr = 1981; - SW_CTL_main(&SW_All, SW_OutputPtrs, &LogInfo); + SW_CTL_main(&SW_All, &SW_Domain.OutDom, &LogInfo); sw_fail_on_error(&LogInfo); // exit test program if unexpected error for (i = 0; i < n; i++) { @@ -174,13 +174,13 @@ TEST_F(SpinUpTest, Mode2WithScopeGreaterThanDuration) { SW_All.Model.SW_SpinUp.spinup = swTRUE; // Run the spinup - SW_CTL_run_spinup(&SW_All, &LogInfo); + SW_CTL_run_spinup(&SW_All, &SW_Domain.OutDom, &LogInfo); sw_fail_on_error(&LogInfo); // Run (a short) simulation SW_All.Model.startyr = 1980; SW_All.Model.endyr = 1981; - SW_CTL_main(&SW_All, SW_OutputPtrs, &LogInfo); + SW_CTL_main(&SW_All, &SW_Domain.OutDom, &LogInfo); sw_fail_on_error(&LogInfo); // exit test program if unexpected error for (i = 0; i < n; i++) { @@ -220,13 +220,13 @@ TEST_F(SpinUpTest, Mode2WithScopeEqualToDuration) { SW_All.Model.SW_SpinUp.spinup = swTRUE; // Run the spinup - SW_CTL_run_spinup(&SW_All, &LogInfo); + SW_CTL_run_spinup(&SW_All, &SW_Domain.OutDom, &LogInfo); sw_fail_on_error(&LogInfo); // Run (a short) simulation SW_All.Model.startyr = 1980; SW_All.Model.endyr = 1981; - SW_CTL_main(&SW_All, SW_OutputPtrs, &LogInfo); + SW_CTL_main(&SW_All, &SW_Domain.OutDom, &LogInfo); sw_fail_on_error(&LogInfo); // exit test program if unexpected error for (i = 0; i < n; i++) { @@ -266,13 +266,13 @@ TEST_F(SpinUpTest, Mode2WithScopeLessThanDuration) { SW_All.Model.SW_SpinUp.spinup = swTRUE; // Run the spinup - SW_CTL_run_spinup(&SW_All, &LogInfo); + SW_CTL_run_spinup(&SW_All, &SW_Domain.OutDom, &LogInfo); sw_fail_on_error(&LogInfo); // Run (a short) simulation SW_All.Model.startyr = 1980; SW_All.Model.endyr = 1981; - SW_CTL_main(&SW_All, SW_OutputPtrs, &LogInfo); + SW_CTL_main(&SW_All, &SW_Domain.OutDom, &LogInfo); sw_fail_on_error(&LogInfo); // exit test program if unexpected error for (i = 0; i < n; i++) { @@ -431,7 +431,7 @@ TEST_F(SpinUpTest, SpinupEvaluation) { // Run (a short) simulation local_sw.Model.startyr = 1980; local_sw.Model.endyr = 1980; - SW_CTL_main(&local_sw, SW_OutputPtrs, &local_LogInfo); + SW_CTL_main(&SW_All, &SW_Domain.OutDom, &LogInfo); // exit test program if unexpected error sw_fail_on_error(&local_LogInfo); diff --git a/tests/gtests/test_SW_VegEstab.cc b/tests/gtests/test_SW_VegEstab.cc index 0de183b26..9f03d0ce0 100644 --- a/tests/gtests/test_SW_VegEstab.cc +++ b/tests/gtests/test_SW_VegEstab.cc @@ -23,7 +23,7 @@ TEST_F(VegEstabFixtureTest, SimulateWithVegEstab) { EXPECT_GT(SW_All.VegEstab.count, 0); // Run the simulation - SW_CTL_main(&SW_All, SW_OutputPtrs, &LogInfo); + SW_CTL_main(&SW_All, &SW_Domain.OutDom, &LogInfo); sw_fail_on_error(&LogInfo); // exit test program if unexpected error diff --git a/tests/gtests/test_WaterBalance.cc b/tests/gtests/test_WaterBalance.cc index 931a3eff5..a3d28b79f 100644 --- a/tests/gtests/test_WaterBalance.cc +++ b/tests/gtests/test_WaterBalance.cc @@ -30,7 +30,7 @@ TEST_F(WaterBalanceFixtureTest, WaterBalanceExample1) { int i; // Run the simulation - SW_CTL_main(&SW_All, SW_OutputPtrs, &LogInfo); + SW_CTL_main(&SW_All, &SW_Domain.OutDom, &LogInfo); sw_fail_on_error(&LogInfo); // exit test program if unexpected error // Collect and output from daily checks @@ -48,7 +48,7 @@ TEST_F(WaterBalanceFixtureTest, WaterBalanceWithSoilTemperature) { SW_All.Site.use_soil_temp = swTRUE; // Run the simulation - SW_CTL_main(&SW_All, SW_OutputPtrs, &LogInfo); + SW_CTL_main(&SW_All, &SW_Domain.OutDom, &LogInfo); sw_fail_on_error(&LogInfo); // exit test program if unexpected error // Collect and output from daily checks @@ -68,7 +68,7 @@ TEST_F(WaterBalanceFixtureTest, WaterBalanceWithPondedWaterRunonRunoff) { SW_All.Site.percentRunon = 1.25; // Run the simulation - SW_CTL_main(&SW_All, SW_OutputPtrs, &LogInfo); + SW_CTL_main(&SW_All, &SW_Domain.OutDom, &LogInfo); sw_fail_on_error(&LogInfo); // exit test program if unexpected error // Collect and output from daily checks @@ -113,7 +113,7 @@ TEST_F(WaterBalanceFixtureTest, WaterBalanceWithWeatherGeneratorOnly) { sw_fail_on_error(&LogInfo); // exit test program if unexpected error // Run the simulation - SW_CTL_main(&SW_All, SW_OutputPtrs, &LogInfo); + SW_CTL_main(&SW_All, &SW_Domain.OutDom, &LogInfo); sw_fail_on_error(&LogInfo); // exit test program if unexpected error // Collect and output from daily checks @@ -160,7 +160,7 @@ TEST_F( sw_fail_on_error(&LogInfo); // exit test program if unexpected error // Run the simulation - SW_CTL_main(&SW_All, SW_OutputPtrs, &LogInfo); + SW_CTL_main(&SW_All, &SW_Domain.OutDom, &LogInfo); sw_fail_on_error(&LogInfo); // exit test program if unexpected error // Collect and output from daily checks @@ -185,7 +185,7 @@ TEST_F(WaterBalanceFixtureTest, WaterBalanceWithHighGravelVolume) { sw_fail_on_error(&LogInfo); // exit test program if unexpected error // Run the simulation - SW_CTL_main(&SW_All, SW_OutputPtrs, &LogInfo); + SW_CTL_main(&SW_All, &SW_Domain.OutDom, &LogInfo); sw_fail_on_error(&LogInfo); // exit test program if unexpected error // Collect and output from daily checks @@ -207,7 +207,7 @@ TEST_F(WaterBalanceFixtureTest, WaterBalanceWithOneSoilLayer) { SW_SWC_init_run(&SW_All.SoilWat, &SW_All.Site, &SW_All.Weather.temp_snow); // Run the simulation - SW_CTL_main(&SW_All, SW_OutputPtrs, &LogInfo); + SW_CTL_main(&SW_All, &SW_Domain.OutDom, &LogInfo); sw_fail_on_error(&LogInfo); // exit test program if unexpected error // Collect and output from daily checks @@ -229,7 +229,7 @@ TEST_F(WaterBalanceFixtureTest, WaterBalanceWithMaxSoilLayers) { SW_SWC_init_run(&SW_All.SoilWat, &SW_All.Site, &SW_All.Weather.temp_snow); // Run the simulation - SW_CTL_main(&SW_All, SW_OutputPtrs, &LogInfo); + SW_CTL_main(&SW_All, &SW_Domain.OutDom, &LogInfo); sw_fail_on_error(&LogInfo); // exit test program if unexpected error // Collect and output from daily checks @@ -251,7 +251,7 @@ TEST_F(WaterBalanceFixtureTest, WaterBalanceWithVegetationFromClimate1) { sw_fail_on_error(&LogInfo); // Run the simulation - SW_CTL_main(&SW_All, SW_OutputPtrs, &LogInfo); + SW_CTL_main(&SW_All, &SW_Domain.OutDom, &LogInfo); sw_fail_on_error(&LogInfo); // exit test program if unexpected error // Collect and output from daily checks @@ -288,7 +288,7 @@ TEST_F(WaterBalanceFixtureTest, WaterBalanceWithSWRCvanGenuchten1980) { sw_fail_on_error(&LogInfo); // exit test program if unexpected error // Run the simulation - SW_CTL_main(&SW_All, SW_OutputPtrs, &LogInfo); + SW_CTL_main(&SW_All, &SW_Domain.OutDom, &LogInfo); sw_fail_on_error(&LogInfo); // exit test program if unexpected error // Collect and output from daily checks @@ -325,7 +325,7 @@ TEST_F(WaterBalanceFixtureTest, WaterBalanceWithSWRCFXW) { sw_fail_on_error(&LogInfo); // exit test program if unexpected error // Run the simulation - SW_CTL_main(&SW_All, SW_OutputPtrs, &LogInfo); + SW_CTL_main(&SW_All, &SW_Domain.OutDom, &LogInfo); sw_fail_on_error(&LogInfo); // exit test program if unexpected error // Collect and output from daily checks @@ -373,7 +373,7 @@ TEST_F(WaterBalanceFixtureTest, WaterBalanceWithDaymet) { sw_fail_on_error(&LogInfo); // exit test program if unexpected error // Run the simulation - SW_CTL_main(&SW_All, SW_OutputPtrs, &LogInfo); + SW_CTL_main(&SW_All, &SW_Domain.OutDom, &LogInfo); sw_fail_on_error(&LogInfo); // exit test program if unexpected error // Collect and output from daily checks @@ -424,7 +424,7 @@ TEST_F(WaterBalanceFixtureTest, WaterBalanceWithGRIDMET) { sw_fail_on_error(&LogInfo); // exit test program if unexpected error // Run the simulation - SW_CTL_main(&SW_All, SW_OutputPtrs, &LogInfo); + SW_CTL_main(&SW_All, &SW_Domain.OutDom, &LogInfo); sw_fail_on_error(&LogInfo); // exit test program if unexpected error // Collect and output from daily checks @@ -477,7 +477,7 @@ TEST_F(WaterBalanceFixtureTest, WaterBalanceWithMACA) { sw_fail_on_error(&LogInfo); // exit test program if unexpected error // Run the simulation - SW_CTL_main(&SW_All, SW_OutputPtrs, &LogInfo); + SW_CTL_main(&SW_All, &SW_Domain.OutDom, &LogInfo); sw_fail_on_error(&LogInfo); // exit test program if unexpected error // Collect and output from daily checks @@ -499,10 +499,10 @@ TEST_F(WaterBalanceFixtureTest, WaterBalanceWithSpinup) { SW_All.Model.SW_SpinUp.scope = 8; // Run the spinup & deactivate - SW_CTL_run_spinup(&SW_All, &LogInfo); + SW_CTL_run_spinup(&SW_All, &SW_Domain.OutDom, &LogInfo); // Run the simulation - SW_CTL_main(&SW_All, SW_OutputPtrs, &LogInfo); + SW_CTL_main(&SW_All, &SW_Domain.OutDom, &LogInfo); sw_fail_on_error(&LogInfo); // exit test program if unexpected error // Collect and output from daily checks From e554cf15e7234f81584c195ee43ab260ab6053fb Mon Sep 17 00:00:00 2001 From: Nicholas Persley Date: Tue, 2 Jul 2024 22:34:44 -0400 Subject: [PATCH 04/19] Fix `write_headers_to_csv()` error - `write_headers_to_csv()` regains parameters `make_regular` and `make_soil` as they cannot be reached through another parameter --- src/SW_Output_outtext.c | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/src/SW_Output_outtext.c b/src/SW_Output_outtext.c index b52a042f8..8f61bf97e 100644 --- a/src/SW_Output_outtext.c +++ b/src/SW_Output_outtext.c @@ -432,6 +432,8 @@ void SW_OUT_create_textfiles( SW_FileStatus->fp_reg[pd], SW_FileStatus->fp_soil[pd], swFALSE, + SW_FileStatus->make_regular, + SW_FileStatus->make_soil, n_layers, LogInfo ); @@ -467,6 +469,8 @@ void SW_OUT_create_summary_files( SW_FileStatus->fp_reg_agg[p], SW_FileStatus->fp_soil_agg[p], swTRUE, + SW_FileStatus->make_regular, + SW_FileStatus->make_soil, n_layers, LogInfo ); @@ -501,6 +505,8 @@ void SW_OUT_create_iteration_files( SW_FileStatus->fp_reg[p], SW_FileStatus->fp_soil[p], swFALSE, + SW_FileStatus->make_regular, + SW_FileStatus->make_soil, n_layers, LogInfo ); @@ -586,6 +592,10 @@ be called before _create_csv_headers(); otherwise, `ncol_OUT` and @param fp_soil name of file. @param does_agg Indicate whether output is aggregated (`-o` option) or for each SOILWAT2 run (`-i` option) +@param make_regular Array of size SW_OUTNPERIODS which holds boolean values + specifying to output "regular" header names +@param make_soil Array of size SW_OUTNPERIODS which holds boolean values + specifying to output a soil-related header names @param n_layers Number of soil layers being dealt with in a simulation @param LogInfo Holds information on warnings and errors */ @@ -595,6 +605,8 @@ void write_headers_to_csv( FILE *fp_reg, FILE *fp_soil, Bool does_agg, + Bool make_regular[], + Bool make_soil[], LyrIndex n_layers, LOG_INFO *LogInfo ) { From c311fab9ce9b199224bc2db79de5b528251cc722 Mon Sep 17 00:00:00 2001 From: Nicholas Persley Date: Tue, 2 Jul 2024 22:36:36 -0400 Subject: [PATCH 05/19] Update code to match clang format --- src/SW_Domain.c | 4 +--- src/SW_Output.c | 12 ++---------- src/SW_netCDF.c | 4 +--- 3 files changed, 4 insertions(+), 16 deletions(-) diff --git a/src/SW_Domain.c b/src/SW_Domain.c index 842ec59a9..822d40258 100644 --- a/src/SW_Domain.c +++ b/src/SW_Domain.c @@ -203,9 +203,7 @@ void SW_DOM_construct(unsigned long rng_seed, SW_DOMAIN *SW_Domain) { #endif #if defined(SW_OUTARRAY) - ForEachOutPeriod(p) { - OutDom->nrow_OUT[p] = 0; - } + ForEachOutPeriod(p) { OutDom->nrow_OUT[p] = 0; } #endif /* attach the printing functions for each output diff --git a/src/SW_Output.c b/src/SW_Output.c index d3e5c831d..fd63c3a29 100644 --- a/src/SW_Output.c +++ b/src/SW_Output.c @@ -1243,13 +1243,7 @@ void SW_OUT_set_SXWrequests( // STEPWAT2 requires annual sum of AET _set_SXWrequests_helper( - OutDom, - eSW_AET, - eSW_Year, - eSW_Sum, - "annual AET", - timeSteps_SXW, - LogInfo + OutDom, eSW_AET, eSW_Year, eSW_Sum, "annual AET", timeSteps_SXW, LogInfo ); if (LogInfo->stopRun) { return; // Exit function prematurely due to error @@ -1312,9 +1306,7 @@ void SW_OUT_construct( } #if defined(SW_OUTARRAY) - ForEachOutPeriod(p) { - OutRun->irow_OUT[p] = 0; - } + ForEachOutPeriod(p) { OutRun->irow_OUT[p] = 0; } #else (void) OutRun; #endif diff --git a/src/SW_netCDF.c b/src/SW_netCDF.c index 59e359e5b..2db020db2 100644 --- a/src/SW_netCDF.c +++ b/src/SW_netCDF.c @@ -5249,9 +5249,7 @@ void SW_NC_alloc_output_var_info(SW_OUT_DOM *OutDom, LOG_INFO *LogInfo) { int key; ForEachOutKey(key) { - SW_NC_alloc_outputkey_var_info( - OutDom, key, LogInfo - ); + SW_NC_alloc_outputkey_var_info(OutDom, key, LogInfo); if (LogInfo->stopRun) { return; // Exit function prematurely due to error } From 018c00ec83d6201d873f441737744a0ee701d3f9 Mon Sep 17 00:00:00 2001 From: Nicholas Persley Date: Tue, 2 Jul 2024 23:16:11 -0400 Subject: [PATCH 06/19] Correct STEPWAT2/rSOILWAT2 code --- include/SW_datastructs.h | 64 ++--- src/SW_Domain.c | 2 +- src/SW_Output.c | 13 +- src/SW_Output_get_functions.c | 425 ++++++++++++++++++++++++---------- src/SW_Output_outtext.c | 4 +- 5 files changed, 349 insertions(+), 159 deletions(-) diff --git a/include/SW_datastructs.h b/include/SW_datastructs.h index 2b59fd0f8..6c615d702 100644 --- a/include/SW_datastructs.h +++ b/include/SW_datastructs.h @@ -1174,6 +1174,23 @@ struct SW_OUT_DOM { Bool print_IterationSummary; Bool print_SW_Output; +#if defined(STEPWAT) + /** `timeSteps_SXW` is the array that keeps track of the output time periods + that are required for `SXW` in-memory output for each output key. + Compare with `timeSteps` */ + OutPeriod timeSteps_SXW[SW_OUTNKEYS][SW_OUTNPERIODS]; + + /** `storeAllIterations` is set to TRUE if STEPWAT2 is called with `-i` flag + if TRUE, then write to disk the SOILWAT2 output + for each STEPWAT2 iteration/repeat to separate files */ + Bool storeAllIterations; + + /** `prepare_IterationSummary` is set to TRUE if STEPWAT2 is called with + `-o` flag; if TRUE, then calculate/write to disk the running mean + and sd across iterations/repeats */ + Bool prepare_IterationSummary; +#endif + #if defined(SW_OUTARRAY) size_t nrow_OUT[SW_OUTNPERIODS]; /**< number of output time steps */ #endif @@ -1182,24 +1199,7 @@ struct SW_OUT_DOM { size_t iOUToffset[SW_OUTNKEYS][SW_OUTNPERIODS] [SW_OUTNMAXVARS]; /**< offset positions of output variables for indexing p_OUT */ -#endif - - OutKey mykey[SW_OUTNKEYS]; - ObjType myobj[SW_OUTNKEYS]; - OutSum sumtype[SW_OUTNKEYS]; - Bool use[SW_OUTNKEYS], // TRUE if output is requested - has_sl[SW_OUTNKEYS]; // TRUE if output key/type produces output for each - // soil layer - TimeInt first_orig[SW_OUTNKEYS], - last_orig[SW_OUTNKEYS]; /* first/last doy that were originally requested - */ - -#if defined(RSOILWAT) - char *outfile[SW_OUTNKEYS]; - /* name of output */ // could probably be removed -#endif -#if defined(SWNETCDF) Bool *reqOutputVars[SW_OUTNKEYS]; /**< Do/don't output a variable in the netCDF output files (dynamically allocated array over output variables) */ @@ -1216,6 +1216,21 @@ struct SW_OUT_DOM { allocated array over output variables) */ #endif + OutKey mykey[SW_OUTNKEYS]; + ObjType myobj[SW_OUTNKEYS]; + OutSum sumtype[SW_OUTNKEYS]; + Bool use[SW_OUTNKEYS], // TRUE if output is requested + has_sl[SW_OUTNKEYS]; // TRUE if output key/type produces output for each + // soil layer + TimeInt first_orig[SW_OUTNKEYS], + last_orig[SW_OUTNKEYS]; /* first/last doy that were originally requested + */ + +#if defined(RSOILWAT) + char *outfile[SW_OUTNKEYS]; + /* name of output */ // could probably be removed +#endif + /* Output function pointers */ @@ -1334,21 +1349,6 @@ typedef struct { char sw_outstr_agg[MAX_LAYERS * OUTSTRLEN]; - /** `timeSteps_SXW` is the array that keeps track of the output time periods - that are required for `SXW` in-memory output for each output key. - Compare with `timeSteps` */ - OutPeriod timeSteps_SXW[SW_OUTNKEYS][SW_OUTNPERIODS]; - - /** `storeAllIterations` is set to TRUE if STEPWAT2 is called with `-i` flag - if TRUE, then write to disk the SOILWAT2 output - for each STEPWAT2 iteration/repeat to separate files */ - Bool storeAllIterations; - - /** `prepare_IterationSummary` is set to TRUE if STEPWAT2 is called with - `-o` flag; if TRUE, then calculate/write to disk the running mean - and sd across iterations/repeats */ - Bool prepare_IterationSummary; - /** Variable from ModelType (STEPWAT2) used in SOILWAT2 */ IntUS currIter; diff --git a/src/SW_Domain.c b/src/SW_Domain.c index 822d40258..82df79a2f 100644 --- a/src/SW_Domain.c +++ b/src/SW_Domain.c @@ -1100,7 +1100,7 @@ void SW_DOM_init_ptrs(SW_DOMAIN *SW_Domain) { SW_F_init_ptrs(SW_Domain->PathInfo.InFiles); #ifdef RSOILWAT - ForEachOutKey(key) { OutDom->outfile[key] = NULL; } + ForEachOutKey(key) { SW_Domain->OutDom.outfile[key] = NULL; } #endif #if defined(SWNETCDF) diff --git a/src/SW_Output.c b/src/SW_Output.c index fd63c3a29..a4bae7dce 100644 --- a/src/SW_Output.c +++ b/src/SW_Output.c @@ -985,8 +985,7 @@ static void collect_sums( use_help = (Bool) (op == OutDom->timeSteps[k][i]); #ifdef STEPWAT - use_help = - (Bool) (use_help || op == sw->GenOutput.timeSteps_SXW[k][i]); + use_help = (Bool) (use_help || op == OutDom->timeSteps_SXW[k][i]); #endif if (use_help) { @@ -1059,7 +1058,7 @@ static void _set_SXWrequests_helper( OutPeriod timeSteps_SXW[][SW_OUTNPERIODS], LOG_INFO *LogInfo ) { - Bool warn = OutDom.use[k]; + Bool warn = OutDom->use[k]; timeSteps_SXW[k][0] = pd; OutDom->use[k] = swTRUE; @@ -1200,7 +1199,7 @@ void SW_OUT_set_SXWrequests( // STEPWAT2 requires monthly mean bulk soil water content _set_SXWrequests_helper( OutDom, - SW_SWCBulk, + eSW_SWCBulk, eSW_Month, eSW_Avg, "monthly bulk soil water content", @@ -2353,9 +2352,9 @@ void SW_OUT_read( } // For now: rSOILWAT2's function `onGet_SW_OUT` requires that -// `sw->Output[k].outfile` is allocated here +// `OutDom->outfile[k]` is allocated here #if defined(RSOILWAT) - sw->Output[k].outfile = (char *) Str_Dup(outfile, LogInfo); + OutDom->outfile[k] = (char *) Str_Dup(outfile, LogInfo); if (LogInfo->stopRun) { CloseFile(&f, LogInfo); return; // Exit function prematurely due to error @@ -2735,7 +2734,7 @@ void SW_OUT_write_today( if (!use_help_txt) { continue; // SXW output complete; skip to next output period } else { - if (sw->OutRun.prepare_IterationSummary) { + if (OutDom->prepare_IterationSummary) { #ifdef SWDEBUG if (debug) { sw_printf( diff --git a/src/SW_Output_get_functions.c b/src/SW_Output_get_functions.c index b6c161cfb..efb0051ed 100644 --- a/src/SW_Output_get_functions.c +++ b/src/SW_Output_get_functions.c @@ -46,7 +46,7 @@ See the \ref out_algo "output algorithm documentation" for details. #ifdef STEPWAT static void format_IterationSummary( - RealD *p, RealD *psd, OutPeriod pd, IntUS N, SW_RUN *sw + RealD *p, RealD *psd, OutPeriod pd, IntUS N, SW_RUN *sw, size_t nrow_OUT[] ) { IntUS i; size_t n; @@ -55,9 +55,7 @@ static void format_IterationSummary( SW_OUT_RUN *OutRun = &sw->OutRun; for (i = 0; i < N; i++) { - n = iOUT( - i, OutRun->irow_OUT[pd], OutDom->nrow_OUT[pd], ncol_TimeOUT[pd] - ); + n = iOUT(i, OutRun->irow_OUT[pd], nrow_OUT[pd], ncol_TimeOUT[pd]); sd = final_running_sd(sw->Model.runModelIterations, psd[n]); snprintf( @@ -76,7 +74,13 @@ static void format_IterationSummary( } static void format_IterationSummary2( - RealD *p, RealD *psd, OutPeriod pd, IntUS N1, IntUS offset, SW_RUN *sw + RealD *p, + RealD *psd, + OutPeriod pd, + IntUS N1, + IntUS offset, + SW_RUN *sw, + size_t nrow_OUT[] ) { IntUS k, i; size_t n; @@ -87,12 +91,7 @@ static void format_IterationSummary2( for (k = 0; k < N1; k++) { for (i = 0; i < sw->Site.n_layers; i++) { n = iOUT2( - i, - k + offset, - pd, - OutRun->irow_OUT, - OutRun->nrow_OUT, - sw->Site.n_layers + i, k + offset, pd, OutRun->irow_OUT, nrow_OUT, sw->Site.n_layers ); sd = final_running_sd(sw->Model.runModelIterations, psd[n]); @@ -195,7 +194,12 @@ void get_co2effects_mem(OutPeriod pd, SW_RUN *sw, SW_OUT_DOM *OutDom) { #if defined(RSOILWAT) get_outvalleader( - &sw->Model, pd, OutRun->irow_OUT, OutRun->nrow_OUT, OutRun->tOffset, p + &sw->Model, + pd, + OutRun->irow_OUT, + OutDom->nrow_OUT, + sw->OutRun.tOffset, + p ); #endif @@ -281,10 +285,10 @@ void get_co2effects_agg(OutPeriod pd, SW_RUN *sw, SW_OUT_DOM *OutDom) { ); } - if (OutRun->print_IterationSummary) { + if (OutDom->print_IterationSummary) { OutRun->sw_outstr_agg[0] = '\0'; format_IterationSummary( - p, psd, pd, OutRun->ncol_OUT[eSW_CO2Effects], sw + p, psd, pd, OutDom->ncol_OUT[eSW_CO2Effects], sw, OutDom->nrow_OUT ); } } @@ -373,7 +377,12 @@ void get_biomass_mem(OutPeriod pd, SW_RUN *sw, SW_OUT_DOM *OutDom) { #if defined(RSOILWAT) int i; get_outvalleader( - &sw->Model, pd, OutRun->irow_OUT, OutRun->nrow_OUT, OutRun->tOffset, p + &sw->Model, + pd, + OutRun->irow_OUT, + OutDom->nrow_OUT, + sw->OutRun.tOffset, + p ); #endif @@ -607,9 +616,11 @@ void get_biomass_agg(OutPeriod pd, SW_RUN *sw, SW_OUT_DOM *OutDom) { ); do_running_agg(p, psd, iOUTIndex, OutRun->currIter, vo->LAI); - if (OutRun->print_IterationSummary) { + if (OutDom->print_IterationSummary) { OutRun->sw_outstr_agg[0] = '\0'; - format_IterationSummary(p, psd, pd, OutRun->ncol_OUT[eSW_Biomass], sw); + format_IterationSummary( + p, psd, pd, OutDom->ncol_OUT[eSW_Biomass], sw, OutDom->nrow_OUT + ); } } #endif @@ -678,7 +689,12 @@ void get_estab_mem(OutPeriod pd, SW_RUN *sw, SW_OUT_DOM *OutDom) { #if defined(RSOILWAT) get_outvalleader( - &sw->Model, pd, OutRun->irow_OUT, OutRun->nrow_OUT, OutRun->tOffset, p + &sw->Model, + pd, + OutRun->irow_OUT, + OutDom->nrow_OUT, + sw->OutRun.tOffset, + p ); #endif @@ -734,9 +750,11 @@ void get_estab_agg(OutPeriod pd, SW_RUN *sw, SW_OUT_DOM *OutDom) { ); } - if (OutRun->print_IterationSummary) { + if (OutDom->print_IterationSummary) { OutRun->sw_outstr_agg[0] = '\0'; - format_IterationSummary(p, psd, pd, OutRun->ncol_OUT[eSW_Estab], sw); + format_IterationSummary( + p, psd, pd, OutDom->ncol_OUT[eSW_Estab], sw, OutDom->nrow_OUT + ); } } #endif @@ -803,7 +821,12 @@ void get_temp_mem(OutPeriod pd, SW_RUN *sw, SW_OUT_DOM *OutDom) { #if defined(RSOILWAT) get_outvalleader( - &sw->Model, pd, OutRun->irow_OUT, OutRun->nrow_OUT, OutRun->tOffset, p + &sw->Model, + pd, + OutRun->irow_OUT, + OutDom->nrow_OUT, + sw->OutRun.tOffset, + p ); #endif @@ -922,9 +945,11 @@ void get_temp_agg(OutPeriod pd, SW_RUN *sw, SW_OUT_DOM *OutDom) { iOUT(5, OutRun->irow_OUT[pd], OutDom->nrow_OUT[pd], ncol_TimeOUT[pd]); do_running_agg(p, psd, iOUTIndex, OutRun->currIter, vo->surfaceAvg); - if (OutRun->print_IterationSummary) { + if (OutDom->print_IterationSummary) { OutRun->sw_outstr_agg[0] = '\0'; - format_IterationSummary(p, psd, pd, OutRun->ncol_OUT[eSW_Temp], sw); + format_IterationSummary( + p, psd, pd, OutDom->ncol_OUT[eSW_Temp], sw, OutDom->nrow_OUT + ); } } @@ -942,14 +967,16 @@ void get_temp_SXW(OutPeriod pd, SW_RUN *sw, SW_OUT_DOM *OutDom) { if (pd == eSW_Month || pd == eSW_Year) { SW_WEATHER_OUTPUTS *vo = sw->Weather.p_oagg[pd]; - tOffset = OutRun->tOffset; + tOffset = sw->OutRun.tOffset; if (pd == eSW_Month) { - OutRun->temp_monthly[sw->Model.month - tOffset] = vo->temp_avg; + sw->OutRun.temp_monthly[sw->Model.month - tOffset] = vo->temp_avg; } else if (pd == eSW_Year) { - OutRun->temp = vo->temp_avg; + sw->OutRun.temp = vo->temp_avg; } } + + (void) OutDom; } #endif @@ -1016,7 +1043,12 @@ void get_precip_mem(OutPeriod pd, SW_RUN *sw, SW_OUT_DOM *OutDom) { #if defined(RSOILWAT) get_outvalleader( - &sw->Model, pd, OutRun->irow_OUT, OutRun->nrow_OUT, OutRun->tOffset, p + &sw->Model, + pd, + OutRun->irow_OUT, + OutDom->nrow_OUT, + sw->OutRun.tOffset, + p ); #endif @@ -1120,9 +1152,11 @@ void get_precip_agg(OutPeriod pd, SW_RUN *sw, SW_OUT_DOM *OutDom) { iOUT(4, OutRun->irow_OUT[pd], OutDom->nrow_OUT[pd], ncol_TimeOUT[pd]); do_running_agg(p, psd, iOUTIndex, OutRun->currIter, vo->snowloss); - if (OutRun->print_IterationSummary) { + if (OutDom->print_IterationSummary) { OutRun->sw_outstr_agg[0] = '\0'; - format_IterationSummary(p, psd, pd, OutRun->ncol_OUT[eSW_Precip], sw); + format_IterationSummary( + p, psd, pd, OutDom->ncol_OUT[eSW_Precip], sw, OutDom->nrow_OUT + ); } } @@ -1140,14 +1174,16 @@ void get_precip_SXW(OutPeriod pd, SW_RUN *sw, SW_OUT_DOM *OutDom) { if (pd == eSW_Month || pd == eSW_Year) { SW_WEATHER_OUTPUTS *vo = sw->Weather.p_oagg[pd]; - tOffset = OutRun->tOffset; + tOffset = sw->OutRun.tOffset; if (pd == eSW_Month) { - OutRun->ppt_monthly[sw->Model.month - tOffset] = vo->ppt; + sw->OutRun.ppt_monthly[sw->Model.month - tOffset] = vo->ppt; } else if (pd == eSW_Year) { - OutRun->ppt = vo->ppt; + sw->OutRun.ppt = vo->ppt; } } + + (void) OutDom; } #endif @@ -1207,7 +1243,12 @@ void get_vwcBulk_mem(OutPeriod pd, SW_RUN *sw, SW_OUT_DOM *OutDom) { #if defined(RSOILWAT) get_outvalleader( - &sw->Model, pd, OutRun->irow_OUT, OutRun->nrow_OUT, OutRun->tOffset, p + &sw->Model, + pd, + OutRun->irow_OUT, + OutDom->nrow_OUT, + sw->OutRun.tOffset, + p ); #endif @@ -1276,9 +1317,11 @@ void get_vwcBulk_agg(OutPeriod pd, SW_RUN *sw, SW_OUT_DOM *OutDom) { ); } - if (OutRun->print_IterationSummary) { + if (OutDom->print_IterationSummary) { OutRun->sw_outstr_agg[0] = '\0'; - format_IterationSummary(p, psd, pd, OutRun->ncol_OUT[eSW_VWCBulk], sw); + format_IterationSummary( + p, psd, pd, OutDom->ncol_OUT[eSW_VWCBulk], sw, OutDom->nrow_OUT + ); } } #endif @@ -1345,7 +1388,12 @@ void get_vwcMatric_mem(OutPeriod pd, SW_RUN *sw, SW_OUT_DOM *OutDom) { #if defined(RSOILWAT) get_outvalleader( - &sw->Model, pd, OutRun->irow_OUT, OutRun->nrow_OUT, OutRun->tOffset, p + &sw->Model, + pd, + OutRun->irow_OUT, + OutDom->nrow_OUT, + sw->OutRun.tOffset, + p ); #endif @@ -1416,10 +1464,10 @@ void get_vwcMatric_agg(OutPeriod pd, SW_RUN *sw, SW_OUT_DOM *OutDom) { ); } - if (OutRun->print_IterationSummary) { + if (OutDom->print_IterationSummary) { OutRun->sw_outstr_agg[0] = '\0'; format_IterationSummary( - p, psd, pd, OutRun->ncol_OUT[eSW_VWCMatric], sw + p, psd, pd, OutDom->ncol_OUT[eSW_VWCMatric], sw, OutDom->nrow_OUT ); } } @@ -1486,7 +1534,12 @@ void get_swa_mem(OutPeriod pd, SW_RUN *sw, SW_OUT_DOM *OutDom) { #if defined(RSOILWAT) get_outvalleader( - &sw->Model, pd, OutRun->irow_OUT, OutRun->nrow_OUT, OutRun->tOffset, p + &sw->Model, + pd, + OutRun->irow_OUT, + OutDom->nrow_OUT, + sw->OutRun.tOffset, + p ); #endif @@ -1494,7 +1547,7 @@ void get_swa_mem(OutPeriod pd, SW_RUN *sw, SW_OUT_DOM *OutDom) { ForEachSoilLayer(i, sw->Site.n_layers) { #if defined(RSOILWAT) iOUTIndex = iOUT2( - i, k, pd, OutRun->irow_OUT, OutRun->nrow_OUT, sw->Site.n_layers + i, k, pd, OutRun->irow_OUT, OutDom->nrow_OUT, sw->Site.n_layers ); #elif defined(SWNETCDF) @@ -1552,7 +1605,7 @@ void get_swa_agg(OutPeriod pd, SW_RUN *sw, SW_OUT_DOM *OutDom) { ForEachVegType(k) { ForEachSoilLayer(i, sw->Site.n_layers) { iOUTIndex = iOUT2( - i, k, pd, OutRun->irow_OUT, OutRun->nrow_OUT, sw->Site.n_layers + i, k, pd, OutRun->irow_OUT, OutDom->nrow_OUT, sw->Site.n_layers ); do_running_agg( p, psd, iOUTIndex, OutRun->currIter, vo->SWA_VegType[k][i] @@ -1560,9 +1613,11 @@ void get_swa_agg(OutPeriod pd, SW_RUN *sw, SW_OUT_DOM *OutDom) { } } - if (OutRun->print_IterationSummary) { + if (OutDom->print_IterationSummary) { OutRun->sw_outstr_agg[0] = '\0'; - format_IterationSummary2(p, psd, pd, NVEGTYPES, 0, sw); + format_IterationSummary2( + p, psd, pd, NVEGTYPES, 0, sw, OutDom->nrow_OUT + ); } } #endif @@ -1616,7 +1671,12 @@ void get_swcBulk_mem(OutPeriod pd, SW_RUN *sw, SW_OUT_DOM *OutDom) { #if defined(RSOILWAT) get_outvalleader( - &sw->Model, pd, OutRun->irow_OUT, OutRun->nrow_OUT, OutRun->tOffset, p + &sw->Model, + pd, + OutRun->irow_OUT, + OutDom->nrow_OUT, + sw->OutRun.tOffset, + p ); #endif @@ -1677,9 +1737,11 @@ void get_swcBulk_agg(OutPeriod pd, SW_RUN *sw, SW_OUT_DOM *OutDom) { do_running_agg(p, psd, iOUTIndex, OutRun->currIter, vo->swcBulk[i]); } - if (OutRun->print_IterationSummary) { + if (OutDom->print_IterationSummary) { OutRun->sw_outstr_agg[0] = '\0'; - format_IterationSummary(p, psd, pd, OutRun->ncol_OUT[eSW_SWCBulk], sw); + format_IterationSummary( + p, psd, pd, OutDom->ncol_OUT[eSW_SWCBulk], sw, OutDom->nrow_OUT + ); } } @@ -1698,12 +1760,14 @@ void get_swcBulk_SXW(OutPeriod pd, SW_RUN *sw, SW_OUT_DOM *OutDom) { if (pd == eSW_Month) { LyrIndex i; SW_SOILWAT_OUTPUTS *vo = sw->SoilWat.p_oagg[pd]; - month = sw->Model.month - OutRun->tOffset; + month = sw->Model.month - sw->OutRun.tOffset; ForEachSoilLayer(i, sw->Site.n_layers) { - OutRun->swc[i][month] = vo->swcBulk[i]; + sw->OutRun.swc[i][month] = vo->swcBulk[i]; } } + + (void) OutDom; } #endif @@ -1770,7 +1834,12 @@ void get_swpMatric_mem(OutPeriod pd, SW_RUN *sw, SW_OUT_DOM *OutDom) { #if defined(RSOILWAT) get_outvalleader( - &sw->Model, pd, OutRun->irow_OUT, OutRun->nrow_OUT, OutRun->tOffset, p + &sw->Model, + pd, + OutRun->irow_OUT, + OutDom->nrow_OUT, + sw->OutRun.tOffset, + p ); #endif @@ -1838,10 +1907,10 @@ void get_swpMatric_agg(OutPeriod pd, SW_RUN *sw, SW_OUT_DOM *OutDom) { do_running_agg(p, psd, iOUTIndex, OutRun->currIter, val); } - if (OutRun->print_IterationSummary) { + if (OutDom->print_IterationSummary) { OutRun->sw_outstr_agg[0] = '\0'; format_IterationSummary( - p, psd, pd, OutRun->ncol_OUT[eSW_SWPMatric], sw + p, psd, pd, OutDom->ncol_OUT[eSW_SWPMatric], sw, OutDom->nrow_OUT ); } } @@ -1896,7 +1965,12 @@ void get_swaBulk_mem(OutPeriod pd, SW_RUN *sw, SW_OUT_DOM *OutDom) { #if defined(RSOILWAT) get_outvalleader( - &sw->Model, pd, OutRun->irow_OUT, OutRun->nrow_OUT, OutRun->tOffset, p + &sw->Model, + pd, + OutRun->irow_OUT, + OutDom->nrow_OUT, + sw->OutRun.tOffset, + p ); #endif @@ -1957,9 +2031,11 @@ void get_swaBulk_agg(OutPeriod pd, SW_RUN *sw, SW_OUT_DOM *OutDom) { do_running_agg(p, psd, iOUTIndex, OutRun->currIter, vo->swaBulk[i]); } - if (OutRun->print_IterationSummary) { + if (OutDom->print_IterationSummary) { OutRun->sw_outstr_agg[0] = '\0'; - format_IterationSummary(p, psd, pd, OutRun->ncol_OUT[eSW_SWABulk], sw); + format_IterationSummary( + p, psd, pd, OutDom->ncol_OUT[eSW_SWABulk], sw, OutDom->nrow_OUT + ); } } #endif @@ -2024,7 +2100,12 @@ void get_swaMatric_mem(OutPeriod pd, SW_RUN *sw, SW_OUT_DOM *OutDom) { #if defined(RSOILWAT) get_outvalleader( - &sw->Model, pd, OutRun->irow_OUT, OutRun->nrow_OUT, OutRun->tOffset, p + &sw->Model, + pd, + OutRun->irow_OUT, + OutDom->nrow_OUT, + sw->OutRun.tOffset, + p ); #endif @@ -2093,10 +2174,10 @@ void get_swaMatric_agg(OutPeriod pd, SW_RUN *sw, SW_OUT_DOM *OutDom) { ); } - if (OutRun->print_IterationSummary) { + if (OutDom->print_IterationSummary) { OutRun->sw_outstr_agg[0] = '\0'; format_IterationSummary( - p, psd, pd, OutRun->ncol_OUT[eSW_SWAMatric], sw + p, psd, pd, OutDom->ncol_OUT[eSW_SWAMatric], sw, OutDom->nrow_OUT ); } } @@ -2151,7 +2232,12 @@ void get_surfaceWater_mem(OutPeriod pd, SW_RUN *sw, SW_OUT_DOM *OutDom) { #if defined(RSOILWAT) get_outvalleader( - &sw->Model, pd, OutRun->irow_OUT, OutRun->nrow_OUT, OutRun->tOffset, p + &sw->Model, + pd, + OutRun->irow_OUT, + OutDom->nrow_OUT, + sw->OutRun.tOffset, + p ); #endif @@ -2190,10 +2276,10 @@ void get_surfaceWater_agg(OutPeriod pd, SW_RUN *sw, SW_OUT_DOM *OutDom) { iOUT(0, OutRun->irow_OUT[pd], OutDom->nrow_OUT[pd], ncol_TimeOUT[pd]); do_running_agg(p, psd, iOUTIndex, OutRun->currIter, vo->surfaceWater); - if (OutRun->print_IterationSummary) { + if (OutDom->print_IterationSummary) { OutRun->sw_outstr_agg[0] = '\0'; format_IterationSummary( - p, psd, pd, OutRun->ncol_OUT[eSW_SurfaceWater], sw + p, psd, pd, OutDom->ncol_OUT[eSW_SurfaceWater], sw, OutDom->nrow_OUT ); } } @@ -2262,7 +2348,12 @@ void get_runoffrunon_mem(OutPeriod pd, SW_RUN *sw, SW_OUT_DOM *OutDom) { #if defined(RSOILWAT) get_outvalleader( - &sw->Model, pd, OutRun->irow_OUT, OutRun->nrow_OUT, OutRun->tOffset, p + &sw->Model, + pd, + OutRun->irow_OUT, + OutDom->nrow_OUT, + sw->OutRun.tOffset, + p ); #endif @@ -2353,9 +2444,11 @@ void get_runoffrunon_agg(OutPeriod pd, SW_RUN *sw, SW_OUT_DOM *OutDom) { iOUT(3, OutRun->irow_OUT[pd], OutDom->nrow_OUT[pd], ncol_TimeOUT[pd]); do_running_agg(p, psd, iOUTIndex, OutRun->currIter, vo->surfaceRunon); - if (OutRun->print_IterationSummary) { + if (OutDom->print_IterationSummary) { OutRun->sw_outstr_agg[0] = '\0'; - format_IterationSummary(p, psd, pd, OutRun->ncol_OUT[eSW_Runoff], sw); + format_IterationSummary( + p, psd, pd, OutDom->ncol_OUT[eSW_Runoff], sw, OutDom->nrow_OUT + ); } } #endif @@ -2423,7 +2516,12 @@ void get_transp_mem(OutPeriod pd, SW_RUN *sw, SW_OUT_DOM *OutDom) { #if defined(RSOILWAT) get_outvalleader( - &sw->Model, pd, OutRun->irow_OUT, OutRun->nrow_OUT, OutRun->tOffset, p + &sw->Model, + pd, + OutRun->irow_OUT, + OutDom->nrow_OUT, + sw->OutRun.tOffset, + p ); #endif @@ -2464,7 +2562,7 @@ void get_transp_mem(OutPeriod pd, SW_RUN *sw, SW_OUT_DOM *OutDom) { #if defined(RSOILWAT) // k + 1 because of total transp. iOUTIndex = iOUT2( - i, k + 1, pd, OutRun->irow_OUT, OutRun->nrow_OUT, n_layers + i, k + 1, pd, OutRun->irow_OUT, OutDom->nrow_OUT, n_layers ); #elif defined(SWNETCDF) @@ -2530,9 +2628,9 @@ void get_transp_agg(OutPeriod pd, SW_RUN *sw, SW_OUT_DOM *OutDom) { ); } - if (OutRun->print_IterationSummary) { + if (OutDom->print_IterationSummary) { OutRun->sw_outstr_agg[0] = '\0'; - format_IterationSummary(p, psd, pd, n_layers, sw); + format_IterationSummary(p, psd, pd, n_layers, sw, OutDom->nrow_OUT); } /* transpiration for each vegetation type */ @@ -2540,7 +2638,7 @@ void get_transp_agg(OutPeriod pd, SW_RUN *sw, SW_OUT_DOM *OutDom) { ForEachSoilLayer(i, n_layers) { // k + 1 because of total transp. iOUTIndex = iOUT2( - i, k + 1, pd, OutRun->irow_OUT, OutRun->nrow_OUT, n_layers + i, k + 1, pd, OutRun->irow_OUT, OutDom->nrow_OUT, n_layers ); do_running_agg( p, psd, iOUTIndex, OutRun->currIter, vo->transp[k][i] @@ -2548,8 +2646,10 @@ void get_transp_agg(OutPeriod pd, SW_RUN *sw, SW_OUT_DOM *OutDom) { } } - if (OutRun->print_IterationSummary) { - format_IterationSummary2(p, psd, pd, NVEGTYPES, 1, sw); + if (OutDom->print_IterationSummary) { + format_IterationSummary2( + p, psd, pd, NVEGTYPES, 1, sw, OutDom->nrow_OUT + ); } } @@ -2570,20 +2670,22 @@ void get_transp_SXW(OutPeriod pd, SW_RUN *sw, SW_OUT_DOM *OutDom) { LyrIndex i; int k; SW_SOILWAT_OUTPUTS *vo = sw->SoilWat.p_oagg[pd]; - month = sw->Model.month - OutRun->tOffset; + month = sw->Model.month - sw->OutRun.tOffset; /* total transpiration */ ForEachSoilLayer(i, sw->Site.n_layers) { - OutRun->transpTotal[i][month] = vo->transp_total[i]; + sw->OutRun.transpTotal[i][month] = vo->transp_total[i]; } /* transpiration for each vegetation type */ ForEachVegType(k) { ForEachSoilLayer(i, sw->Site.n_layers) { - OutRun->transpVeg[k][i][month] = vo->transp[k][i]; + sw->OutRun.transpVeg[k][i][month] = vo->transp[k][i]; } } } + + (void) OutDom; } #endif @@ -2634,7 +2736,12 @@ void get_evapSoil_mem(OutPeriod pd, SW_RUN *sw, SW_OUT_DOM *OutDom) { #if defined(RSOILWAT) get_outvalleader( - &sw->Model, pd, OutRun->irow_OUT, OutRun->nrow_OUT, OutRun->tOffset, p + &sw->Model, + pd, + OutRun->irow_OUT, + OutDom->nrow_OUT, + sw->OutRun.tOffset, + p ); #endif @@ -2697,9 +2804,11 @@ void get_evapSoil_agg(OutPeriod pd, SW_RUN *sw, SW_OUT_DOM *OutDom) { ); } - if (OutRun->print_IterationSummary) { + if (OutDom->print_IterationSummary) { OutRun->sw_outstr_agg[0] = '\0'; - format_IterationSummary(p, psd, pd, OutRun->ncol_OUT[eSW_EvapSoil], sw); + format_IterationSummary( + p, psd, pd, OutDom->ncol_OUT[eSW_EvapSoil], sw, OutDom->nrow_OUT + ); } } #endif @@ -2777,7 +2886,12 @@ void get_evapSurface_mem(OutPeriod pd, SW_RUN *sw, SW_OUT_DOM *OutDom) { #if defined(RSOILWAT) get_outvalleader( - &sw->Model, pd, OutRun->irow_OUT, OutRun->nrow_OUT, OutRun->tOffset, p + &sw->Model, + pd, + OutRun->irow_OUT, + OutDom->nrow_OUT, + sw->OutRun.tOffset, + p ); #endif @@ -2893,10 +3007,10 @@ void get_evapSurface_agg(OutPeriod pd, SW_RUN *sw, SW_OUT_DOM *OutDom) { ); do_running_agg(p, psd, iOUTIndex, OutRun->currIter, vo->surfaceWater_evap); - if (OutRun->print_IterationSummary) { + if (OutDom->print_IterationSummary) { OutRun->sw_outstr_agg[0] = '\0'; format_IterationSummary( - p, psd, pd, OutRun->ncol_OUT[eSW_EvapSurface], sw + p, psd, pd, OutDom->ncol_OUT[eSW_EvapSurface], sw, OutDom->nrow_OUT ); } } @@ -2962,7 +3076,12 @@ void get_interception_mem(OutPeriod pd, SW_RUN *sw, SW_OUT_DOM *OutDom) { #if defined(RSOILWAT) get_outvalleader( - &sw->Model, pd, OutRun->irow_OUT, OutRun->nrow_OUT, OutRun->tOffset, p + &sw->Model, + pd, + OutRun->irow_OUT, + OutDom->nrow_OUT, + sw->OutRun.tOffset, + p ); #endif @@ -3054,10 +3173,10 @@ void get_interception_agg(OutPeriod pd, SW_RUN *sw, SW_OUT_DOM *OutDom) { ); do_running_agg(p, psd, iOUTIndex, OutRun->currIter, vo->litter_int); - if (OutRun->print_IterationSummary) { + if (OutDom->print_IterationSummary) { OutRun->sw_outstr_agg[0] = '\0'; format_IterationSummary( - p, psd, pd, OutRun->ncol_OUT[eSW_Interception], sw + p, psd, pd, OutDom->ncol_OUT[eSW_Interception], sw, OutDom->nrow_OUT ); } } @@ -3115,7 +3234,12 @@ void get_soilinf_mem(OutPeriod pd, SW_RUN *sw, SW_OUT_DOM *OutDom) { #if defined(RSOILWAT) get_outvalleader( - &sw->Model, pd, OutRun->irow_OUT, OutRun->nrow_OUT, OutRun->tOffset, p + &sw->Model, + pd, + OutRun->irow_OUT, + OutDom->nrow_OUT, + sw->OutRun.tOffset, + p ); #endif @@ -3154,9 +3278,11 @@ void get_soilinf_agg(OutPeriod pd, SW_RUN *sw, SW_OUT_DOM *OutDom) { iOUT(0, OutRun->irow_OUT[pd], OutDom->nrow_OUT[pd], ncol_TimeOUT[pd]); do_running_agg(p, psd, iOUTIndex, OutRun->currIter, vo->soil_inf); - if (OutRun->print_IterationSummary) { + if (OutDom->print_IterationSummary) { OutRun->sw_outstr_agg[0] = '\0'; - format_IterationSummary(p, psd, pd, OutRun->ncol_OUT[eSW_SoilInf], sw); + format_IterationSummary( + p, psd, pd, OutDom->ncol_OUT[eSW_SoilInf], sw, OutDom->nrow_OUT + ); } } #endif @@ -3213,7 +3339,12 @@ void get_lyrdrain_mem(OutPeriod pd, SW_RUN *sw, SW_OUT_DOM *OutDom) { #if defined(RSOILWAT) get_outvalleader( - &sw->Model, pd, OutRun->irow_OUT, OutRun->nrow_OUT, OutRun->tOffset, p + &sw->Model, + pd, + OutRun->irow_OUT, + OutDom->nrow_OUT, + sw->OutRun.tOffset, + p ); #endif @@ -3274,9 +3405,11 @@ void get_lyrdrain_agg(OutPeriod pd, SW_RUN *sw, SW_OUT_DOM *OutDom) { do_running_agg(p, psd, iOUTIndex, OutRun->currIter, vo->lyrdrain[i]); } - if (OutRun->print_IterationSummary) { + if (OutDom->print_IterationSummary) { OutRun->sw_outstr_agg[0] = '\0'; - format_IterationSummary(p, psd, pd, OutRun->ncol_OUT[eSW_LyrDrain], sw); + format_IterationSummary( + p, psd, pd, OutDom->ncol_OUT[eSW_LyrDrain], sw, OutDom->nrow_OUT + ); } } #endif @@ -3346,7 +3479,12 @@ void get_hydred_mem(OutPeriod pd, SW_RUN *sw, SW_OUT_DOM *OutDom) { #if defined(RSOILWAT) get_outvalleader( - &sw->Model, pd, OutRun->irow_OUT, OutRun->nrow_OUT, OutRun->tOffset, p + &sw->Model, + pd, + OutRun->irow_OUT, + OutDom->nrow_OUT, + sw->OutRun.tOffset, + p ); #endif @@ -3391,7 +3529,7 @@ void get_hydred_mem(OutPeriod pd, SW_RUN *sw, SW_OUT_DOM *OutDom) { k + 1, pd, OutRun->irow_OUT, - OutRun->nrow_OUT, + OutDom->nrow_OUT, sw->Site.n_layers ); @@ -3458,9 +3596,9 @@ void get_hydred_agg(OutPeriod pd, SW_RUN *sw, SW_OUT_DOM *OutDom) { ); } - if (OutRun->print_IterationSummary) { + if (OutDom->print_IterationSummary) { OutRun->sw_outstr_agg[0] = '\0'; - format_IterationSummary(p, psd, pd, n_layers, sw); + format_IterationSummary(p, psd, pd, n_layers, sw, OutDom->nrow_OUT); } /* hydraulic redistribution for each vegetation type */ @@ -3468,7 +3606,7 @@ void get_hydred_agg(OutPeriod pd, SW_RUN *sw, SW_OUT_DOM *OutDom) { ForEachSoilLayer(i, n_layers) { // k + 1 because of total hydred iOUTIndex = iOUT2( - i, k + 1, pd, OutRun->irow_OUT, OutRun->nrow_OUT, n_layers + i, k + 1, pd, OutRun->irow_OUT, OutDom->nrow_OUT, n_layers ); do_running_agg( p, psd, iOUTIndex, OutRun->currIter, vo->hydred[k][i] @@ -3476,8 +3614,10 @@ void get_hydred_agg(OutPeriod pd, SW_RUN *sw, SW_OUT_DOM *OutDom) { } } - if (OutRun->print_IterationSummary) { - format_IterationSummary2(p, psd, pd, NVEGTYPES, 1, sw); + if (OutDom->print_IterationSummary) { + format_IterationSummary2( + p, psd, pd, NVEGTYPES, 1, sw, OutDom->nrow_OUT + ); } } #endif @@ -3548,7 +3688,12 @@ void get_aet_mem(OutPeriod pd, SW_RUN *sw, SW_OUT_DOM *OutDom) { #if defined(RSOILWAT) get_outvalleader( - &sw->Model, pd, OutRun->irow_OUT, OutRun->nrow_OUT, OutRun->tOffset, p + &sw->Model, + pd, + OutRun->irow_OUT, + OutDom->nrow_OUT, + sw->OutRun.tOffset, + p ); #endif @@ -3668,9 +3813,11 @@ void get_aet_agg(OutPeriod pd, SW_RUN *sw, SW_OUT_DOM *OutDom) { iOUT(5, OutRun->irow_OUT[pd], OutDom->nrow_OUT[pd], ncol_TimeOUT[pd]); do_running_agg(p, psd, iOUTIndex, OutRun->currIter, vo2->snowloss); - if (OutRun->print_IterationSummary) { + if (OutDom->print_IterationSummary) { OutRun->sw_outstr_agg[0] = '\0'; - format_IterationSummary(p, psd, pd, OutRun->ncol_OUT[eSW_AET], sw); + format_IterationSummary( + p, psd, pd, OutDom->ncol_OUT[eSW_AET], sw, OutDom->nrow_OUT + ); } } @@ -3687,8 +3834,10 @@ void get_aet_SXW(OutPeriod pd, SW_RUN *sw, SW_OUT_DOM *OutDom) { if (pd == eSW_Year) { SW_SOILWAT_OUTPUTS *vo = sw->SoilWat.p_oagg[pd]; - OutRun->aet = vo->aet; + sw->OutRun.aet = vo->aet; } + + (void) OutDom; } #endif @@ -3753,7 +3902,12 @@ void get_pet_mem(OutPeriod pd, SW_RUN *sw, SW_OUT_DOM *OutDom) { #if defined(RSOILWAT) get_outvalleader( - &sw->Model, pd, OutRun->irow_OUT, OutRun->nrow_OUT, OutRun->tOffset, p + &sw->Model, + pd, + OutRun->irow_OUT, + OutDom->nrow_OUT, + sw->OutRun.tOffset, + p ); #endif @@ -3849,9 +4003,11 @@ void get_pet_agg(OutPeriod pd, SW_RUN *sw, SW_OUT_DOM *OutDom) { iOUT(4, OutRun->irow_OUT[pd], OutDom->nrow_OUT[pd], ncol_TimeOUT[pd]); do_running_agg(p, psd, iOUTIndex, OutRun->currIter, vo->H_gt); - if (OutRun->print_IterationSummary) { + if (OutDom->print_IterationSummary) { OutRun->sw_outstr_agg[0] = '\0'; - format_IterationSummary(p, psd, pd, OutRun->ncol_OUT[eSW_PET], sw); + format_IterationSummary( + p, psd, pd, OutDom->ncol_OUT[eSW_PET], sw, OutDom->nrow_OUT + ); } } #endif @@ -3916,7 +4072,12 @@ void get_wetdays_mem(OutPeriod pd, SW_RUN *sw, SW_OUT_DOM *OutDom) { #if defined(RSOILWAT) get_outvalleader( - &sw->Model, pd, OutRun->irow_OUT, OutRun->nrow_OUT, OutRun->tOffset, p + &sw->Model, + pd, + OutRun->irow_OUT, + OutDom->nrow_OUT, + sw->OutRun.tOffset, + p ); #endif @@ -3998,9 +4159,11 @@ void get_wetdays_agg(OutPeriod pd, SW_RUN *sw, SW_OUT_DOM *OutDom) { } } - if (OutRun->print_IterationSummary) { + if (OutDom->print_IterationSummary) { OutRun->sw_outstr_agg[0] = '\0'; - format_IterationSummary(p, psd, pd, OutRun->ncol_OUT[eSW_WetDays], sw); + format_IterationSummary( + p, psd, pd, OutDom->ncol_OUT[eSW_WetDays], sw, OutDom->nrow_OUT + ); } } #endif @@ -4057,7 +4220,12 @@ void get_snowpack_mem(OutPeriod pd, SW_RUN *sw, SW_OUT_DOM *OutDom) { #if defined(RSOILWAT) get_outvalleader( - &sw->Model, pd, OutRun->irow_OUT, OutRun->nrow_OUT, OutRun->tOffset, p + &sw->Model, + pd, + OutRun->irow_OUT, + OutDom->nrow_OUT, + sw->OutRun.tOffset, + p ); #endif @@ -4112,9 +4280,11 @@ void get_snowpack_agg(OutPeriod pd, SW_RUN *sw, SW_OUT_DOM *OutDom) { iOUT(1, OutRun->irow_OUT[pd], OutDom->nrow_OUT[pd], ncol_TimeOUT[pd]); do_running_agg(p, psd, iOUTIndex, OutRun->currIter, vo->snowdepth); - if (OutRun->print_IterationSummary) { + if (OutDom->print_IterationSummary) { OutRun->sw_outstr_agg[0] = '\0'; - format_IterationSummary(p, psd, pd, OutRun->ncol_OUT[eSW_SnowPack], sw); + format_IterationSummary( + p, psd, pd, OutDom->ncol_OUT[eSW_SnowPack], sw, OutDom->nrow_OUT + ); } } #endif @@ -4168,7 +4338,12 @@ void get_deepswc_mem(OutPeriod pd, SW_RUN *sw, SW_OUT_DOM *OutDom) { #if defined(RSOILWAT) get_outvalleader( - &sw->Model, pd, OutRun->irow_OUT, OutRun->nrow_OUT, OutRun->tOffset, p + &sw->Model, + pd, + OutRun->irow_OUT, + OutDom->nrow_OUT, + sw->OutRun.tOffset, + p ); #endif @@ -4207,9 +4382,11 @@ void get_deepswc_agg(OutPeriod pd, SW_RUN *sw, SW_OUT_DOM *OutDom) { iOUT(0, OutRun->irow_OUT[pd], OutDom->nrow_OUT[pd], ncol_TimeOUT[pd]); do_running_agg(p, psd, iOUTIndex, OutRun->currIter, vo->deep); - if (OutRun->print_IterationSummary) { + if (OutDom->print_IterationSummary) { OutRun->sw_outstr_agg[0] = '\0'; - format_IterationSummary(p, psd, pd, OutRun->ncol_OUT[eSW_DeepSWC], sw); + format_IterationSummary( + p, psd, pd, OutDom->ncol_OUT[eSW_DeepSWC], sw, OutDom->nrow_OUT + ); } } #endif @@ -4285,7 +4462,12 @@ void get_soiltemp_mem(OutPeriod pd, SW_RUN *sw, SW_OUT_DOM *OutDom) { #if defined(RSOILWAT) get_outvalleader( - &sw->Model, pd, OutRun->irow_OUT, OutRun->nrow_OUT, OutRun->tOffset, p + &sw->Model, + pd, + OutRun->irow_OUT, + OutDom->nrow_OUT, + sw->OutRun.tOffset, + p ); #endif @@ -4424,9 +4606,11 @@ void get_soiltemp_agg(OutPeriod pd, SW_RUN *sw, SW_OUT_DOM *OutDom) { do_running_agg(p, psd, iOUTIndex, OutRun->currIter, vo->avgLyrTemp[i]); } - if (OutRun->print_IterationSummary) { + if (OutDom->print_IterationSummary) { OutRun->sw_outstr_agg[0] = '\0'; - format_IterationSummary(p, psd, pd, OutRun->ncol_OUT[eSW_SoilTemp], sw); + format_IterationSummary( + p, psd, pd, OutDom->ncol_OUT[eSW_SoilTemp], sw, OutDom->nrow_OUT + ); } } #endif @@ -4482,7 +4666,12 @@ void get_frozen_mem(OutPeriod pd, SW_RUN *sw, SW_OUT_DOM *OutDom) { #if defined(RSOILWAT) get_outvalleader( - &sw->Model, pd, OutRun->irow_OUT, OutRun->nrow_OUT, OutRun->tOffset, p + &sw->Model, + pd, + OutRun->irow_OUT, + OutDom->nrow_OUT, + sw->OutRun.tOffset, + p ); #endif @@ -4543,9 +4732,11 @@ void get_frozen_agg(OutPeriod pd, SW_RUN *sw, SW_OUT_DOM *OutDom) { do_running_agg(p, psd, iOUTIndex, OutRun->currIter, vo->lyrFrozen[i]); } - if (OutRun->print_IterationSummary) { + if (OutDom->print_IterationSummary) { OutRun->sw_outstr_agg[0] = '\0'; - format_IterationSummary(p, psd, pd, OutRun->ncol_OUT[eSW_Frozen], sw); + format_IterationSummary( + p, psd, pd, OutDom->ncol_OUT[eSW_Frozen], sw, OutDom->nrow_OUT + ); } } #endif diff --git a/src/SW_Output_outtext.c b/src/SW_Output_outtext.c index 8f61bf97e..559e2ae3d 100644 --- a/src/SW_Output_outtext.c +++ b/src/SW_Output_outtext.c @@ -457,7 +457,7 @@ void SW_OUT_create_summary_files( OutPeriod p; ForEachOutPeriod(p) { - if (GenOutput->use_OutPeriod[p]) { + if (OutDom->use_OutPeriod[p]) { _create_csv_file_ST(-1, p, InFiles, SW_FileStatus, LogInfo); if (LogInfo->stopRun) { return; // Exit function prematurely due to error @@ -493,7 +493,7 @@ void SW_OUT_create_iteration_files( OutPeriod p; ForEachOutPeriod(p) { - if (GenOutput->use_OutPeriod[p]) { + if (OutDom->use_OutPeriod[p]) { _create_csv_file_ST(iteration, p, InFiles, SW_FileStatus, LogInfo); if (LogInfo->stopRun) { return; // Exit function prematurely due to error From 2221988fe396b634f7b4a60dcca36ddb7f7c8884 Mon Sep 17 00:00:00 2001 From: Nicholas Persley Date: Tue, 2 Jul 2024 23:28:25 -0400 Subject: [PATCH 07/19] Split `get_none()` into `get_none_text()` & `get_none_outarray()` - Match the correct parameters of `get_none()` when * Only SOILWAT2 is defined (`get_none_text(OutPeriod, SW_RUN)`) * When outarray is defined (`get_none_outarray(OutPeriod, SW_RUN, SW_OUT_DOM)`) --- include/SW_Output.h | 7 +++-- src/SW_Domain.c | 55 ++++++++++++++++++----------------- src/SW_Output_get_functions.c | 21 +++++++++++-- 3 files changed, 52 insertions(+), 31 deletions(-) diff --git a/include/SW_Output.h b/include/SW_Output.h index 6738b31ed..3b22b97e0 100644 --- a/include/SW_Output.h +++ b/include/SW_Output.h @@ -302,9 +302,12 @@ void SW_OUT_deepCopy( * 05-Mar-03 (cwb) Added code for max,min,avg. Previously, only avg was output. * 22 June-15 (akt) Added code for adding surfaceAvg at output */ -void get_none( +void get_none_outarray( OutPeriod pd, SW_RUN *sw, SW_OUT_DOM *OutDom -); /* default until defined */ +); /* default until defined for outarray output */ +void get_none_text( + OutPeriod pd, SW_RUN *sw +); /* default until defined for text */ #if defined(SW_OUTTEXT) && !defined(SWNETCDF) void get_temp_text(OutPeriod pd, SW_RUN *sw); diff --git a/src/SW_Domain.c b/src/SW_Domain.c index 82df79a2f..e2d7b3cc3 100644 --- a/src/SW_Domain.c +++ b/src/SW_Domain.c @@ -284,7 +284,7 @@ void SW_DOM_construct(unsigned long rng_seed, SW_DOMAIN *SW_Domain) { OutDom->pfunc_agg[k] = (void (*)(OutPeriod, SW_RUN *, SW_OUT_DOM *)) get_vwcBulk_agg; OutDom->pfunc_SXW[k] = - (void (*)(OutPeriod, SW_RUN *, SW_OUT_DOM *)) get_none; + (void (*)(OutPeriod, SW_RUN *, SW_OUT_DOM *)) get_none_outarray; #endif break; @@ -300,7 +300,7 @@ void SW_DOM_construct(unsigned long rng_seed, SW_DOMAIN *SW_Domain) { OutDom->pfunc_agg[k] = (void (*)(OutPeriod, SW_RUN *, SW_OUT_DOM *)) get_vwcMatric_agg; OutDom->pfunc_SXW[k] = - (void (*)(OutPeriod, SW_RUN *, SW_OUT_DOM *)) get_none; + (void (*)(OutPeriod, SW_RUN *, SW_OUT_DOM *)) get_none_outarray; #endif break; @@ -332,7 +332,7 @@ void SW_DOM_construct(unsigned long rng_seed, SW_DOMAIN *SW_Domain) { OutDom->pfunc_agg[k] = (void (*)(OutPeriod, SW_RUN *, SW_OUT_DOM *)) get_swpMatric_agg; OutDom->pfunc_SXW[k] = - (void (*)(OutPeriod, SW_RUN *, SW_OUT_DOM *)) get_none; + (void (*)(OutPeriod, SW_RUN *, SW_OUT_DOM *)) get_none_outarray; #endif break; @@ -348,7 +348,7 @@ void SW_DOM_construct(unsigned long rng_seed, SW_DOMAIN *SW_Domain) { OutDom->pfunc_agg[k] = (void (*)(OutPeriod, SW_RUN *, SW_OUT_DOM *)) get_swaBulk_agg; OutDom->pfunc_SXW[k] = - (void (*)(OutPeriod, SW_RUN *, SW_OUT_DOM *)) get_none; + (void (*)(OutPeriod, SW_RUN *, SW_OUT_DOM *)) get_none_outarray; #endif break; @@ -364,7 +364,7 @@ void SW_DOM_construct(unsigned long rng_seed, SW_DOMAIN *SW_Domain) { OutDom->pfunc_agg[k] = (void (*)(OutPeriod, SW_RUN *, SW_OUT_DOM *)) get_swaMatric_agg; OutDom->pfunc_SXW[k] = - (void (*)(OutPeriod, SW_RUN *, SW_OUT_DOM *)) get_none; + (void (*)(OutPeriod, SW_RUN *, SW_OUT_DOM *)) get_none_outarray; #endif break; @@ -380,7 +380,7 @@ void SW_DOM_construct(unsigned long rng_seed, SW_DOMAIN *SW_Domain) { OutDom->pfunc_agg[k] = (void (*)(OutPeriod, SW_RUN *, SW_OUT_DOM *)) get_swa_agg; OutDom->pfunc_SXW[k] = - (void (*)(OutPeriod, SW_RUN *, SW_OUT_DOM *)) get_none; + (void (*)(OutPeriod, SW_RUN *, SW_OUT_DOM *)) get_none_outarray; #endif break; @@ -396,7 +396,7 @@ void SW_DOM_construct(unsigned long rng_seed, SW_DOMAIN *SW_Domain) { OutDom->pfunc_agg[k] = (void (*)(OutPeriod, SW_RUN *, SW_OUT_DOM *) ) get_surfaceWater_agg; OutDom->pfunc_SXW[k] = - (void (*)(OutPeriod, SW_RUN *, SW_OUT_DOM *)) get_none; + (void (*)(OutPeriod, SW_RUN *, SW_OUT_DOM *)) get_none_outarray; #endif break; @@ -412,7 +412,7 @@ void SW_DOM_construct(unsigned long rng_seed, SW_DOMAIN *SW_Domain) { OutDom->pfunc_agg[k] = (void (*)(OutPeriod, SW_RUN *, SW_OUT_DOM *) ) get_runoffrunon_agg; OutDom->pfunc_SXW[k] = - (void (*)(OutPeriod, SW_RUN *, SW_OUT_DOM *)) get_none; + (void (*)(OutPeriod, SW_RUN *, SW_OUT_DOM *)) get_none_outarray; #endif break; @@ -444,7 +444,7 @@ void SW_DOM_construct(unsigned long rng_seed, SW_DOMAIN *SW_Domain) { OutDom->pfunc_agg[k] = (void (*)(OutPeriod, SW_RUN *, SW_OUT_DOM *)) get_evapSoil_agg; OutDom->pfunc_SXW[k] = - (void (*)(OutPeriod, SW_RUN *, SW_OUT_DOM *)) get_none; + (void (*)(OutPeriod, SW_RUN *, SW_OUT_DOM *)) get_none_outarray; #endif break; @@ -460,7 +460,7 @@ void SW_DOM_construct(unsigned long rng_seed, SW_DOMAIN *SW_Domain) { OutDom->pfunc_agg[k] = (void (*)(OutPeriod, SW_RUN *, SW_OUT_DOM *) ) get_evapSurface_agg; OutDom->pfunc_SXW[k] = - (void (*)(OutPeriod, SW_RUN *, SW_OUT_DOM *)) get_none; + (void (*)(OutPeriod, SW_RUN *, SW_OUT_DOM *)) get_none_outarray; #endif break; @@ -476,7 +476,7 @@ void SW_DOM_construct(unsigned long rng_seed, SW_DOMAIN *SW_Domain) { OutDom->pfunc_agg[k] = (void (*)(OutPeriod, SW_RUN *, SW_OUT_DOM *) ) get_interception_agg; OutDom->pfunc_SXW[k] = - (void (*)(OutPeriod, SW_RUN *, SW_OUT_DOM *)) get_none; + (void (*)(OutPeriod, SW_RUN *, SW_OUT_DOM *)) get_none_outarray; #endif break; @@ -492,7 +492,7 @@ void SW_DOM_construct(unsigned long rng_seed, SW_DOMAIN *SW_Domain) { OutDom->pfunc_agg[k] = (void (*)(OutPeriod, SW_RUN *, SW_OUT_DOM *)) get_soilinf_agg; OutDom->pfunc_SXW[k] = - (void (*)(OutPeriod, SW_RUN *, SW_OUT_DOM *)) get_none; + (void (*)(OutPeriod, SW_RUN *, SW_OUT_DOM *)) get_none_outarray; #endif break; @@ -508,7 +508,7 @@ void SW_DOM_construct(unsigned long rng_seed, SW_DOMAIN *SW_Domain) { OutDom->pfunc_agg[k] = (void (*)(OutPeriod, SW_RUN *, SW_OUT_DOM *)) get_lyrdrain_agg; OutDom->pfunc_SXW[k] = - (void (*)(OutPeriod, SW_RUN *, SW_OUT_DOM *)) get_none; + (void (*)(OutPeriod, SW_RUN *, SW_OUT_DOM *)) get_none_outarray; #endif break; @@ -524,7 +524,7 @@ void SW_DOM_construct(unsigned long rng_seed, SW_DOMAIN *SW_Domain) { OutDom->pfunc_agg[k] = (void (*)(OutPeriod, SW_RUN *, SW_OUT_DOM *)) get_hydred_agg; OutDom->pfunc_SXW[k] = - (void (*)(OutPeriod, SW_RUN *, SW_OUT_DOM *)) get_none; + (void (*)(OutPeriod, SW_RUN *, SW_OUT_DOM *)) get_none_outarray; #endif break; @@ -556,7 +556,7 @@ void SW_DOM_construct(unsigned long rng_seed, SW_DOMAIN *SW_Domain) { OutDom->pfunc_agg[k] = (void (*)(OutPeriod, SW_RUN *, SW_OUT_DOM *)) get_pet_agg; OutDom->pfunc_SXW[k] = - (void (*)(OutPeriod, SW_RUN *, SW_OUT_DOM *)) get_none; + (void (*)(OutPeriod, SW_RUN *, SW_OUT_DOM *)) get_none_outarray; #endif break; @@ -572,7 +572,7 @@ void SW_DOM_construct(unsigned long rng_seed, SW_DOMAIN *SW_Domain) { OutDom->pfunc_agg[k] = (void (*)(OutPeriod, SW_RUN *, SW_OUT_DOM *)) get_wetdays_agg; OutDom->pfunc_SXW[k] = - (void (*)(OutPeriod, SW_RUN *, SW_OUT_DOM *)) get_none; + (void (*)(OutPeriod, SW_RUN *, SW_OUT_DOM *)) get_none_outarray; #endif break; @@ -588,7 +588,7 @@ void SW_DOM_construct(unsigned long rng_seed, SW_DOMAIN *SW_Domain) { OutDom->pfunc_agg[k] = (void (*)(OutPeriod, SW_RUN *, SW_OUT_DOM *)) get_snowpack_agg; OutDom->pfunc_SXW[k] = - (void (*)(OutPeriod, SW_RUN *, SW_OUT_DOM *)) get_none; + (void (*)(OutPeriod, SW_RUN *, SW_OUT_DOM *)) get_none_outarray; #endif break; @@ -604,7 +604,7 @@ void SW_DOM_construct(unsigned long rng_seed, SW_DOMAIN *SW_Domain) { OutDom->pfunc_agg[k] = (void (*)(OutPeriod, SW_RUN *, SW_OUT_DOM *)) get_deepswc_agg; OutDom->pfunc_SXW[k] = - (void (*)(OutPeriod, SW_RUN *, SW_OUT_DOM *)) get_none; + (void (*)(OutPeriod, SW_RUN *, SW_OUT_DOM *)) get_none_outarray; #endif break; @@ -620,7 +620,7 @@ void SW_DOM_construct(unsigned long rng_seed, SW_DOMAIN *SW_Domain) { OutDom->pfunc_agg[k] = (void (*)(OutPeriod, SW_RUN *, SW_OUT_DOM *)) get_soiltemp_agg; OutDom->pfunc_SXW[k] = - (void (*)(OutPeriod, SW_RUN *, SW_OUT_DOM *)) get_none; + (void (*)(OutPeriod, SW_RUN *, SW_OUT_DOM *)) get_none_outarray; #endif break; @@ -636,7 +636,7 @@ void SW_DOM_construct(unsigned long rng_seed, SW_DOMAIN *SW_Domain) { OutDom->pfunc_agg[k] = (void (*)(OutPeriod, SW_RUN *, SW_OUT_DOM *)) get_frozen_agg; OutDom->pfunc_SXW[k] = - (void (*)(OutPeriod, SW_RUN *, SW_OUT_DOM *)) get_none; + (void (*)(OutPeriod, SW_RUN *, SW_OUT_DOM *)) get_none_outarray; #endif break; @@ -652,7 +652,7 @@ void SW_DOM_construct(unsigned long rng_seed, SW_DOMAIN *SW_Domain) { OutDom->pfunc_agg[k] = (void (*)(OutPeriod, SW_RUN *, SW_OUT_DOM *)) get_estab_agg; OutDom->pfunc_SXW[k] = - (void (*)(OutPeriod, SW_RUN *, SW_OUT_DOM *)) get_none; + (void (*)(OutPeriod, SW_RUN *, SW_OUT_DOM *)) get_none_outarray; #endif break; @@ -668,7 +668,7 @@ void SW_DOM_construct(unsigned long rng_seed, SW_DOMAIN *SW_Domain) { OutDom->pfunc_agg[k] = (void (*)(OutPeriod, SW_RUN *, SW_OUT_DOM *) ) get_co2effects_agg; OutDom->pfunc_SXW[k] = - (void (*)(OutPeriod, SW_RUN *, SW_OUT_DOM *)) get_none; + (void (*)(OutPeriod, SW_RUN *, SW_OUT_DOM *)) get_none_outarray; #endif break; @@ -684,22 +684,23 @@ void SW_DOM_construct(unsigned long rng_seed, SW_DOMAIN *SW_Domain) { OutDom->pfunc_agg[k] = (void (*)(OutPeriod, SW_RUN *, SW_OUT_DOM *)) get_biomass_agg; OutDom->pfunc_SXW[k] = - (void (*)(OutPeriod, SW_RUN *, SW_OUT_DOM *)) get_none; + (void (*)(OutPeriod, SW_RUN *, SW_OUT_DOM *)) get_none_outarray; #endif break; default: #if defined(SW_OUTTEXT) - OutDom->pfunc_text[k] = (void (*)(OutPeriod, SW_RUN *)) get_none; + OutDom->pfunc_text[k] = + (void (*)(OutPeriod, SW_RUN *)) get_none_text; #endif #if defined(RSOILWAT) || defined(SWNETCDF) OutDom->pfunc_mem[k] = - (void (*)(OutPeriod, SW_RUN *, SW_OUT_DOM *)) get_none; + (void (*)(OutPeriod, SW_RUN *, SW_OUT_DOM *)) get_none_outarray; #elif defined(STEPWAT) OutDom->pfunc_agg[k] = - (void (*)(OutPeriod, SW_RUN *, SW_OUT_DOM *)) get_none; + (void (*)(OutPeriod, SW_RUN *, SW_OUT_DOM *)) get_none_outarray; OutDom->pfunc_SXW[k] = - (void (*)(OutPeriod, SW_RUN *, SW_OUT_DOM *)) get_none; + (void (*)(OutPeriod, SW_RUN *, SW_OUT_DOM *)) get_none_outarray; #endif break; } diff --git a/src/SW_Output_get_functions.c b/src/SW_Output_get_functions.c index efb0051ed..ac8fb8268 100644 --- a/src/SW_Output_get_functions.c +++ b/src/SW_Output_get_functions.c @@ -120,7 +120,8 @@ static void format_IterationSummary2( /* --------------------------------------------------- */ /** -@brief Output routine for quantities that aren't yet implemented. +@brief Output routine for quantities that aren't yet implemented +for outarray output. This just gives the main output loop something to call, rather than an empty pointer. @@ -131,12 +132,28 @@ rather than an empty pointer. @param[in] OutDom Struct of type SW_OUT_DOM that holds output information that do not change throughout simulation runs */ -void get_none(OutPeriod pd, SW_RUN *sw, SW_OUT_DOM *OutDom) { +void get_none_outarray(OutPeriod pd, SW_RUN *sw, SW_OUT_DOM *OutDom) { (void) pd; (void) sw; // Coerce to void to silence compiler (void) OutDom; } +/** +@brief Output routine for quantities that aren't yet implemented +for text output. + +This just gives the main output loop something to call, +rather than an empty pointer. + +@param[in] pd Time period in simulation output (day/week/month/year) +@param[in] sw Comprehensive struct of type SW_RUN containing all information + in the simulation. +*/ +void get_none_text(OutPeriod pd, SW_RUN *sw) { + (void) pd; + (void) sw; // Coerce to void to silence compiler +} + //------ eSW_CO2Effects #ifdef SW_OUTTEXT From a348ddac9b5c19712ac21b1a008b7f838d9ca84b Mon Sep 17 00:00:00 2001 From: Nicholas Persley Date: Fri, 5 Jul 2024 13:01:03 -0400 Subject: [PATCH 08/19] Finish renaming of SW_ALL to SW_RUN - Rename `template_SW_All` to `template_SW_Run` in tests - Rename `SW_ALL_deepCopy()` to `SW_RUN_deepCopy()` --- include/SW_Control.h | 2 +- src/SW_Control.c | 6 +- src/SW_netCDF.c | 2 +- tests/gtests/sw_testhelpers.cc | 34 +- tests/gtests/sw_testhelpers.h | 12 +- tests/gtests/test_SW_Carbon.cc | 50 +-- tests/gtests/test_SW_Flow_lib_temp.cc | 2 +- tests/gtests/test_SW_Site.cc | 54 ++-- tests/gtests/test_SW_SoilWater.cc | 12 +- tests/gtests/test_SW_SpinUp.cc | 184 +++++------ tests/gtests/test_SW_VegEstab.cc | 14 +- tests/gtests/test_SW_VegProd.cc | 118 +++---- tests/gtests/test_SW_Weather.cc | 432 +++++++++++++------------- tests/gtests/test_WaterBalance.cc | 328 +++++++++---------- 14 files changed, 625 insertions(+), 625 deletions(-) diff --git a/include/SW_Control.h b/include/SW_Control.h index fd92f9268..4f1cc760f 100644 --- a/include/SW_Control.h +++ b/include/SW_Control.h @@ -32,7 +32,7 @@ void SW_CTL_init_ptrs(SW_RUN *sw); void SW_CTL_alloc_outptrs(SW_RUN *sw, LOG_INFO *LogInfo); -void SW_ALL_deepCopy( +void SW_RUN_deepCopy( SW_RUN *source, SW_RUN *dest, SW_OUT_DOM *DomRun, LOG_INFO *LogInfo ); diff --git a/src/SW_Control.c b/src/SW_Control.c index 4a63140ba..dd5b942bf 100644 --- a/src/SW_Control.c +++ b/src/SW_Control.c @@ -27,7 +27,7 @@ /* INCLUDES / DEFINES */ /* --------------------------------------------------- */ -#include "include/SW_Control.h" // for SW_ALL_deepCopy, SW_CTL_RunSimSet +#include "include/SW_Control.h" // for SW_RUN_deepCopy, SW_CTL_RunSimSet #include "include/filefuncs.h" // for LogError, sw_message #include "include/generic.h" // for swTRUE, Bool, swFALSE, GT, IntU #include "include/myMemory.h" // for Mem_Malloc @@ -147,7 +147,7 @@ static void _end_day(SW_RUN *sw, SW_OUT_DOM *OutDom, LOG_INFO *LogInfo) { information that do not change throughout simulation runs @param[out] LogInfo Holds information on warnings and errors */ -void SW_ALL_deepCopy( +void SW_RUN_deepCopy( SW_RUN *source, SW_RUN *dest, SW_OUT_DOM *OutDom, LOG_INFO *LogInfo ) { @@ -1031,7 +1031,7 @@ void SW_CTL_run_sw( SW_RUN local_sw; // Copy template SW_RUN to local instance - SW_ALL_deepCopy(sw_template, &local_sw, &SW_Domain->OutDom, LogInfo); + SW_RUN_deepCopy(sw_template, &local_sw, &SW_Domain->OutDom, LogInfo); if (LogInfo->stopRun) { goto freeMem; // Free memory and skip simulation run } diff --git a/src/SW_netCDF.c b/src/SW_netCDF.c index 2db020db2..5db95833c 100644 --- a/src/SW_netCDF.c +++ b/src/SW_netCDF.c @@ -4481,7 +4481,7 @@ Bool SW_NC_check_progress( /** @brief Read values from netCDF input files for available variables and copy -to SW_All +to SW_Run @param[in,out] sw Comprehensive struct of type SW_RUN containing all information in the simulation diff --git a/tests/gtests/sw_testhelpers.cc b/tests/gtests/sw_testhelpers.cc index 471f8ec86..f8a31fef3 100644 --- a/tests/gtests/sw_testhelpers.cc +++ b/tests/gtests/sw_testhelpers.cc @@ -13,7 +13,7 @@ #include // for strcpy -SW_RUN template_SW_All; +SW_RUN template_SW_Run; SW_DOMAIN template_SW_Domain; /** @@ -140,7 +140,7 @@ void setup_SW_Site_for_tests(SW_SITE *SW_Site) { /* Set up global variables for testing and read in values from SOILWAT2 example - Prepares global variables `template_SW_Domain`, `template_SW_All`. + Prepares global variables `template_SW_Domain`, `template_SW_Run`. The purpose is to read in text files once, and then have `AllTestFixture` create deep copies for each test. @@ -157,7 +157,7 @@ int setup_testGlobalSoilwatTemplate() { sw_init_logs(NULL, &LogInfo); SW_DOM_init_ptrs(&template_SW_Domain); - SW_CTL_init_ptrs(&template_SW_All); + SW_CTL_init_ptrs(&template_SW_Run); template_SW_Domain.netCDFInfo.renameDomainTemplateNC = swTRUE; @@ -175,27 +175,27 @@ int setup_testGlobalSoilwatTemplate() { goto finishProgram; } - SW_CTL_setup_model(&template_SW_All, &template_SW_Domain.OutDom, &LogInfo); + SW_CTL_setup_model(&template_SW_Run, &template_SW_Domain.OutDom, &LogInfo); if (LogInfo.stopRun) { goto finishProgram; } - template_SW_All.Model.doOutput = swFALSE; /* turn off output during tests */ + template_SW_Run.Model.doOutput = swFALSE; /* turn off output during tests */ SW_MDL_get_ModelRun( - &template_SW_All.Model, &template_SW_Domain, NULL, &LogInfo + &template_SW_Run.Model, &template_SW_Domain, NULL, &LogInfo ); if (LogInfo.stopRun) { goto finishProgram; } /* allocate memory for output pointers */ - SW_CTL_alloc_outptrs(&template_SW_All, &LogInfo); + SW_CTL_alloc_outptrs(&template_SW_Run, &LogInfo); if (LogInfo.stopRun) { goto finishProgram; } SW_CTL_read_inputs_from_disk( - &template_SW_All, + &template_SW_Run, &template_SW_Domain.OutDom, &template_SW_Domain.PathInfo, &LogInfo @@ -216,25 +216,25 @@ int setup_testGlobalSoilwatTemplate() { sw_init_logs(NULL, &LogInfo); SW_WTH_finalize_all_weather( - &template_SW_All.Markov, - &template_SW_All.Weather, - template_SW_All.Model.cum_monthdays, - template_SW_All.Model.days_in_month, + &template_SW_Run.Markov, + &template_SW_Run.Weather, + template_SW_Run.Model.cum_monthdays, + template_SW_Run.Model.days_in_month, &LogInfo ); if (LogInfo.stopRun) { goto finishProgram; } - SW_CTL_init_run(&template_SW_All, &LogInfo); + SW_CTL_init_run(&template_SW_Run, &LogInfo); if (LogInfo.stopRun) { goto finishProgram; } SW_OUT_setup_output( - template_SW_All.Site.n_layers, - template_SW_All.Site.n_evap_lyrs, - &template_SW_All.VegEstab, + template_SW_Run.Site.n_layers, + template_SW_Run.Site.n_evap_lyrs, + &template_SW_Run.VegEstab, &template_SW_Domain.OutDom, &LogInfo ); @@ -254,5 +254,5 @@ finishProgram: { */ void teardown_testGlobalSoilwatTemplate() { SW_DOM_deconstruct(&template_SW_Domain); - SW_CTL_clear_model(swTRUE, &template_SW_All); + SW_CTL_clear_model(swTRUE, &template_SW_Run); } diff --git a/tests/gtests/sw_testhelpers.h b/tests/gtests/sw_testhelpers.h index 92aabe539..6c737112f 100644 --- a/tests/gtests/sw_testhelpers.h +++ b/tests/gtests/sw_testhelpers.h @@ -1,5 +1,5 @@ #include "include/generic.h" // for EQ, swTRUE -#include "include/SW_Control.h" // for SW_ALL_deepCopy, SW_CTL_clear_model +#include "include/SW_Control.h" // for SW_RUN_deepCopy, SW_CTL_clear_model #include "include/SW_datastructs.h" // for LOG_INFO, SW_RUN, SW_DOMAIN, SW_... #include "include/SW_Defines.h" // for SW_OUTNKEYS, SW_MISSING #include "include/SW_Domain.h" // for SW_DOM_deconstruct, SW_DOM_deepCopy @@ -8,7 +8,7 @@ #include // for memcpy, NULL -extern SW_RUN template_SW_All; +extern SW_RUN template_SW_Run; extern SW_DOMAIN template_SW_Domain; @@ -54,7 +54,7 @@ void teardown_testGlobalSoilwatTemplate(); */ class AllTestFixture : public ::testing::Test { protected: - SW_RUN SW_All; + SW_RUN SW_Run; SW_DOMAIN SW_Domain; LOG_INFO LogInfo; @@ -81,8 +81,8 @@ class AllTestFixture : public ::testing::Test { SW_DOM_deepCopy(&template_SW_Domain, &SW_Domain, &LogInfo); sw_fail_on_error(&LogInfo); - SW_ALL_deepCopy( - &template_SW_All, &SW_All, &template_SW_Domain.OutDom, &LogInfo + SW_RUN_deepCopy( + &template_SW_Run, &SW_Run, &template_SW_Domain.OutDom, &LogInfo ); sw_fail_on_error(&LogInfo); } @@ -90,7 +90,7 @@ class AllTestFixture : public ::testing::Test { // Free allocated memory in test fixture local variables void TearDown() override { SW_DOM_deconstruct(&SW_Domain); - SW_CTL_clear_model(swTRUE, &SW_All); + SW_CTL_clear_model(swTRUE, &SW_Run); } }; diff --git a/tests/gtests/test_SW_Carbon.cc b/tests/gtests/test_SW_Carbon.cc index ad42d5940..2657c45c8 100644 --- a/tests/gtests/test_SW_Carbon.cc +++ b/tests/gtests/test_SW_Carbon.cc @@ -22,74 +22,74 @@ TEST(CarbonTest, CarbonConstructor) { // Test reading yearly CO2 data from disk file TEST_F(CarbonFixtureTest, CarbonReadInputFile) { - TimeInt year, simendyr = SW_All.Model.endyr + SW_All.Model.addtl_yr; + TimeInt year, simendyr = SW_Run.Model.endyr + SW_Run.Model.addtl_yr; double sum_CO2; // Test if CO2-effects are turned off -> no CO2 concentration data are read // from file - SW_CBN_construct(&SW_All.Carbon); - SW_All.Carbon.use_wue_mult = 0; - SW_All.Carbon.use_bio_mult = 0; + SW_CBN_construct(&SW_Run.Carbon); + SW_Run.Carbon.use_wue_mult = 0; + SW_Run.Carbon.use_bio_mult = 0; SW_CBN_read( - &SW_All.Carbon, &SW_All.Model, SW_Domain.PathInfo.InFiles, &LogInfo + &SW_Run.Carbon, &SW_Run.Model, SW_Domain.PathInfo.InFiles, &LogInfo ); sw_fail_on_error(&LogInfo); // exit test program if unexpected error sum_CO2 = 0.; for (year = 0; year < MAX_NYEAR; year++) { - sum_CO2 += SW_All.Carbon.ppm[year]; + sum_CO2 += SW_Run.Carbon.ppm[year]; } EXPECT_DOUBLE_EQ(sum_CO2, 0.); // Test if CO2-effects are turned on -> CO2 concentration data are read from // file - SW_CBN_construct(&SW_All.Carbon); - strcpy(SW_All.Carbon.scenario, "RCP85"); - SW_All.Carbon.use_wue_mult = 1; - SW_All.Carbon.use_bio_mult = 1; - SW_All.Model.addtl_yr = 0; + SW_CBN_construct(&SW_Run.Carbon); + strcpy(SW_Run.Carbon.scenario, "RCP85"); + SW_Run.Carbon.use_wue_mult = 1; + SW_Run.Carbon.use_bio_mult = 1; + SW_Run.Model.addtl_yr = 0; SW_CBN_read( - &SW_All.Carbon, &SW_All.Model, SW_Domain.PathInfo.InFiles, &LogInfo + &SW_Run.Carbon, &SW_Run.Model, SW_Domain.PathInfo.InFiles, &LogInfo ); sw_fail_on_error(&LogInfo); // exit test program if unexpected error - for (year = SW_All.Model.startyr + SW_All.Model.addtl_yr; year <= simendyr; + for (year = SW_Run.Model.startyr + SW_Run.Model.addtl_yr; year <= simendyr; year++) { - EXPECT_GT(SW_All.Carbon.ppm[year], 0.); + EXPECT_GT(SW_Run.Carbon.ppm[year], 0.); } } // Test the calculation of CO2-effect multipliers TEST_F(CarbonFixtureTest, CarbonCO2multipliers) { - TimeInt year, simendyr = SW_All.Model.endyr + SW_All.Model.addtl_yr; + TimeInt year, simendyr = SW_Run.Model.endyr + SW_Run.Model.addtl_yr; int k; - SW_CBN_construct(&SW_All.Carbon); - strcpy(SW_All.Carbon.scenario, "RCP85"); - SW_All.Carbon.use_wue_mult = 1; - SW_All.Carbon.use_bio_mult = 1; - SW_All.Model.addtl_yr = 0; + SW_CBN_construct(&SW_Run.Carbon); + strcpy(SW_Run.Carbon.scenario, "RCP85"); + SW_Run.Carbon.use_wue_mult = 1; + SW_Run.Carbon.use_bio_mult = 1; + SW_Run.Model.addtl_yr = 0; SW_CBN_read( - &SW_All.Carbon, &SW_All.Model, SW_Domain.PathInfo.InFiles, &LogInfo + &SW_Run.Carbon, &SW_Run.Model, SW_Domain.PathInfo.InFiles, &LogInfo ); sw_fail_on_error(&LogInfo); // exit test program if unexpected error SW_CBN_init_run( - SW_All.VegProd.veg, &SW_All.Model, &SW_All.Carbon, &LogInfo + SW_Run.VegProd.veg, &SW_Run.Model, &SW_Run.Carbon, &LogInfo ); sw_fail_on_error(&LogInfo); // exit test program if unexpected error - for (year = SW_All.Model.startyr + SW_All.Model.addtl_yr; year <= simendyr; + for (year = SW_Run.Model.startyr + SW_Run.Model.addtl_yr; year <= simendyr; year++) { ForEachVegType(k) { EXPECT_GT( - SW_All.VegProd.veg[k].co2_multipliers[BIO_INDEX][year], 0. + SW_Run.VegProd.veg[k].co2_multipliers[BIO_INDEX][year], 0. ); EXPECT_GT( - SW_All.VegProd.veg[k].co2_multipliers[WUE_INDEX][year], 0. + SW_Run.VegProd.veg[k].co2_multipliers[WUE_INDEX][year], 0. ); } } diff --git a/tests/gtests/test_SW_Flow_lib_temp.cc b/tests/gtests/test_SW_Flow_lib_temp.cc index df0e29669..0e12b7bb5 100644 --- a/tests/gtests/test_SW_Flow_lib_temp.cc +++ b/tests/gtests/test_SW_Flow_lib_temp.cc @@ -1232,7 +1232,7 @@ TEST(SWFlowTempTest, SWFlowTempMainSoilTemperatureFunction_LyrMAX) { // Expect that sTempInitR is updated to sTempR for the next day for (k = 0; k <= nRgr + 1; k++) { // sw_printf("\n k %u, newoldtempR %f", k, - // SW_All.StRegValues.oldavgLyrTempR[k]); + // SW_Run.StRegValues.oldavgLyrTempR[k]); EXPECT_NE(SW_StRegValues.oldavgLyrTempR[k], SW_MISSING); } diff --git a/tests/gtests/test_SW_Site.cc b/tests/gtests/test_SW_Site.cc index 39bbc1c10..8fbea3360 100644 --- a/tests/gtests/test_SW_Site.cc +++ b/tests/gtests/test_SW_Site.cc @@ -433,9 +433,9 @@ TEST_F(SiteFixtureTest, SiteSoilEvaporationParametersDeathTest) { // Check error for bad bare-soil evaporation coefficient (should be [0-1]) - SW_All.Site.evap_coeff[0] = -0.5; + SW_Run.Site.evap_coeff[0] = -0.5; - SW_SIT_init_run(&SW_All.VegProd, &SW_All.Site, &LogInfo); + SW_SIT_init_run(&SW_Run.VegProd, &SW_Run.Site, &LogInfo); // expect error: don't exit test program via `sw_fail_on_error(&LogInfo)` // Detect failure by error message @@ -449,8 +449,8 @@ TEST_F(SiteFixtureTest, SiteSoilTranspirationParametersDeathTest) { // Check error for bad transpiration coefficient (should be [0-1]) - SW_All.Site.transp_coeff[SW_GRASS][1] = 1.5; - SW_SIT_init_run(&SW_All.VegProd, &SW_All.Site, &LogInfo); + SW_Run.Site.transp_coeff[SW_GRASS][1] = 1.5; + SW_SIT_init_run(&SW_Run.VegProd, &SW_Run.Site, &LogInfo); // expect error: don't exit test program via `sw_fail_on_error(&LogInfo)` // Detect failure by error message @@ -471,24 +471,24 @@ TEST_F(SiteFixtureTest, SiteSoilTranspirationRegions) { RealD soildepth; for (i = 0; i < MAX_TRANSP_REGIONS; ++i) { - prev_TranspRgnBounds[i] = SW_All.Site._TranspRgnBounds[i]; + prev_TranspRgnBounds[i] = SW_Run.Site._TranspRgnBounds[i]; } // Check that "default" values do not change region bounds nRegions = 3; RealD regionLowerBounds1[] = {20., 40., 100.}; - derive_soilRegions(&SW_All.Site, nRegions, regionLowerBounds1, &LogInfo); + derive_soilRegions(&SW_Run.Site, nRegions, regionLowerBounds1, &LogInfo); sw_fail_on_error(&LogInfo); // exit test program if unexpected error for (i = 0; i < nRegions; ++i) { // Quickly calculate soil depth for current region as output information soildepth = 0.; - for (id = 0; id <= SW_All.Site._TranspRgnBounds[i]; ++id) { - soildepth += SW_All.Site.width[id]; + for (id = 0; id <= SW_Run.Site._TranspRgnBounds[i]; ++id) { + soildepth += SW_Run.Site.width[id]; } - EXPECT_EQ(prev_TranspRgnBounds[i], SW_All.Site._TranspRgnBounds[i]) + EXPECT_EQ(prev_TranspRgnBounds[i], SW_Run.Site._TranspRgnBounds[i]) << "for transpiration region = " << i + 1 << " at a soil depth of " << soildepth << " cm"; } @@ -497,24 +497,24 @@ TEST_F(SiteFixtureTest, SiteSoilTranspirationRegions) { // Check that setting one region for all soil layers works nRegions = 1; RealD regionLowerBounds2[] = {100.}; - derive_soilRegions(&SW_All.Site, nRegions, regionLowerBounds2, &LogInfo); + derive_soilRegions(&SW_Run.Site, nRegions, regionLowerBounds2, &LogInfo); sw_fail_on_error(&LogInfo); // exit test program if unexpected error for (i = 0; i < nRegions; ++i) { - EXPECT_EQ(SW_All.Site.n_layers - 1, SW_All.Site._TranspRgnBounds[i]) + EXPECT_EQ(SW_Run.Site.n_layers - 1, SW_Run.Site._TranspRgnBounds[i]) << "for a single transpiration region across all soil layers"; } // Check that setting one region for one soil layer works nRegions = 1; - RealD regionLowerBounds3[] = {SW_All.Site.width[0]}; - derive_soilRegions(&SW_All.Site, nRegions, regionLowerBounds3, &LogInfo); + RealD regionLowerBounds3[] = {SW_Run.Site.width[0]}; + derive_soilRegions(&SW_Run.Site, nRegions, regionLowerBounds3, &LogInfo); sw_fail_on_error(&LogInfo); // exit test program if unexpected error for (i = 0; i < nRegions; ++i) { EXPECT_EQ( - 0, SW_All.Site._TranspRgnBounds[i] + 0, SW_Run.Site._TranspRgnBounds[i] ) << "for a single transpiration region for the shallowest soil layer"; } @@ -525,14 +525,14 @@ TEST_F(SiteFixtureTest, SiteSoilTranspirationRegions) { // Example: one region each for the topmost soil layers soildepth = 0.; for (i = 0; i < nRegions; ++i) { - soildepth += SW_All.Site.width[i]; + soildepth += SW_Run.Site.width[i]; regionLowerBounds4[i] = soildepth; } - derive_soilRegions(&SW_All.Site, nRegions, regionLowerBounds4, &LogInfo); + derive_soilRegions(&SW_Run.Site, nRegions, regionLowerBounds4, &LogInfo); sw_fail_on_error(&LogInfo); // exit test program if unexpected error for (i = 0; i < nRegions; ++i) { - EXPECT_EQ(i, SW_All.Site._TranspRgnBounds[i]) + EXPECT_EQ(i, SW_Run.Site._TranspRgnBounds[i]) << "for transpiration region for the " << i + 1 << "-th soil layer"; } @@ -589,24 +589,24 @@ TEST_F(SiteFixtureTest, SiteSoilDensityTypes) { double fcoarse = 0.1; // Inputs represent matric density - SW_All.Site.type_soilDensityInput = SW_MATRIC; - SW_All.Site.fractionVolBulk_gravel[0] = fcoarse; - SW_SIT_init_run(&SW_All.VegProd, &SW_All.Site, &LogInfo); + SW_Run.Site.type_soilDensityInput = SW_MATRIC; + SW_Run.Site.fractionVolBulk_gravel[0] = fcoarse; + SW_SIT_init_run(&SW_Run.VegProd, &SW_Run.Site, &LogInfo); sw_fail_on_error(&LogInfo); // exit test program if unexpected error EXPECT_GT( - SW_All.Site.soilBulk_density[0], SW_All.Site.soilMatric_density[0] + SW_Run.Site.soilBulk_density[0], SW_Run.Site.soilMatric_density[0] ); // Inputs represent bulk density - SW_All.Site.type_soilDensityInput = SW_BULK; - SW_All.Site.fractionVolBulk_gravel[0] = fcoarse; - SW_SIT_init_run(&SW_All.VegProd, &SW_All.Site, &LogInfo); + SW_Run.Site.type_soilDensityInput = SW_BULK; + SW_Run.Site.fractionVolBulk_gravel[0] = fcoarse; + SW_SIT_init_run(&SW_Run.VegProd, &SW_Run.Site, &LogInfo); sw_fail_on_error(&LogInfo); // exit test program if unexpected error EXPECT_GT( - SW_All.Site.soilBulk_density[0], SW_All.Site.soilMatric_density[0] + SW_Run.Site.soilBulk_density[0], SW_Run.Site.soilMatric_density[0] ); } @@ -627,9 +627,9 @@ TEST(SiteTest, SiteSoilDensityTooLowDeathTest) { TEST_F(SiteFixtureTest, SiteSoilDensityMissingDeathTest) { // Create an error if type_soilDensityInput not implemented - SW_All.Site.type_soilDensityInput = SW_MISSING; + SW_Run.Site.type_soilDensityInput = SW_MISSING; - SW_SIT_init_run(&SW_All.VegProd, &SW_All.Site, &LogInfo); + SW_SIT_init_run(&SW_Run.VegProd, &SW_Run.Site, &LogInfo); // Detect failure by error message EXPECT_THAT( diff --git a/tests/gtests/test_SW_SoilWater.cc b/tests/gtests/test_SW_SoilWater.cc index 526544c56..ee93359dd 100644 --- a/tests/gtests/test_SW_SoilWater.cc +++ b/tests/gtests/test_SW_SoilWater.cc @@ -47,10 +47,10 @@ TEST(SoilWaterTest, SoilWaterSWCadjustSnow) { // when average temperature >= SW_Site.TminAccu2, we expect rain == ppt EXPECT_EQ(rain, 1); - // when average temperature >= SW_All.Site.TminAccu2, we expect snow == 0 + // when average temperature >= SW_Run.Site.TminAccu2, we expect snow == 0 EXPECT_EQ(snow, 0); - // when temp_snow <= SW_All.Site.TmaxCrit, we expect snowmelt == 0 + // when temp_snow <= SW_Run.Site.TmaxCrit, we expect snowmelt == 0 EXPECT_EQ(snowmelt, 0); SW_Site.TminAccu2 = 6; @@ -71,10 +71,10 @@ TEST(SoilWaterTest, SoilWaterSWCadjustSnow) { // when average temperature < SW_Site.TminAccu2, we expect rain == 0 EXPECT_EQ(rain, 0); - // when average temperature < SW_All.Site.TminAccu2, we expect snow == ppt + // when average temperature < SW_Run.Site.TminAccu2, we expect snow == ppt EXPECT_EQ(snow, 1); - // when temp_snow > SW_All.Site.TmaxCrit, we expect snowmelt == fmax(0, + // when temp_snow > SW_Run.Site.TmaxCrit, we expect snowmelt == fmax(0, // *snowpack - *snowmelt ) EXPECT_EQ(snowmelt, 0); } @@ -108,10 +108,10 @@ TEST(SoilWaterTest, SoilWaterSWCadjustSnow2) { // when average temperature >= SW_Site.TminAccu2, we expect rain == ppt EXPECT_EQ(rain, 1); - // when average temperature >= SW_All.Site.TminAccu2, we expect snow == 0 + // when average temperature >= SW_Run.Site.TminAccu2, we expect snow == 0 EXPECT_EQ(snow, 0); - // when temp_snow > SW_All.Site.TmaxCrit, we expect snowmelt == 0 + // when temp_snow > SW_Run.Site.TmaxCrit, we expect snowmelt == 0 EXPECT_EQ(snowmelt, 0); } diff --git a/tests/gtests/test_SW_SpinUp.cc b/tests/gtests/test_SW_SpinUp.cc index 3d38d849f..b00aac8f0 100644 --- a/tests/gtests/test_SW_SpinUp.cc +++ b/tests/gtests/test_SW_SpinUp.cc @@ -21,40 +21,40 @@ TEST_F(SpinUpTest, Mode1WithScopeGreaterThanDuration) { int i, n = 4; // n = number of soil layers to test RealD *prevTemp = new double[n], *prevMoist = new double[n]; - SW_All.Model.SW_SpinUp.mode = 1; - SW_All.Model.SW_SpinUp.scope = 27; - SW_All.Model.SW_SpinUp.duration = 3; + SW_Run.Model.SW_SpinUp.mode = 1; + SW_Run.Model.SW_SpinUp.scope = 27; + SW_Run.Model.SW_SpinUp.duration = 3; // Turn on soil temperature simulations - SW_All.Site.use_soil_temp = swTRUE; + SW_Run.Site.use_soil_temp = swTRUE; // Get initial soil temp and soil moisture levels for (i = 0; i < n; i++) { - prevTemp[i] = SW_All.Site.avgLyrTempInit[i]; - prevMoist[i] = SW_All.SoilWat.swcBulk[Today][i]; + prevTemp[i] = SW_Run.Site.avgLyrTempInit[i]; + prevMoist[i] = SW_Run.SoilWat.swcBulk[Today][i]; } // Turn on spinup flag - SW_All.Model.SW_SpinUp.spinup = swTRUE; + SW_Run.Model.SW_SpinUp.spinup = swTRUE; // Run the spinup - SW_CTL_run_spinup(&SW_All, &SW_Domain.OutDom, &LogInfo); + SW_CTL_run_spinup(&SW_Run, &SW_Domain.OutDom, &LogInfo); sw_fail_on_error(&LogInfo); // Run (a short) simulation - SW_All.Model.startyr = 1980; - SW_All.Model.endyr = 1981; - SW_CTL_main(&SW_All, &SW_Domain.OutDom, &LogInfo); + SW_Run.Model.startyr = 1980; + SW_Run.Model.endyr = 1981; + SW_CTL_main(&SW_Run, &SW_Domain.OutDom, &LogInfo); sw_fail_on_error(&LogInfo); // exit test program if unexpected error for (i = 0; i < n; i++) { // Check soil temp after spinup - EXPECT_NE(prevTemp[i], SW_All.SoilWat.avgLyrTemp[i]) + EXPECT_NE(prevTemp[i], SW_Run.SoilWat.avgLyrTemp[i]) << "Soil temp error in test " << i << ": " - << SW_All.SoilWat.avgLyrTemp[i]; + << SW_Run.SoilWat.avgLyrTemp[i]; // Check soil moisture after spinup - EXPECT_NE(prevMoist[i], SW_All.SoilWat.swcBulk[Today][i]) + EXPECT_NE(prevMoist[i], SW_Run.SoilWat.swcBulk[Today][i]) << "Soil moisture error in test " << i << ": " - << SW_All.SoilWat.swcBulk[Today][i]; + << SW_Run.SoilWat.swcBulk[Today][i]; } // Deallocate arrays @@ -67,40 +67,40 @@ TEST_F(SpinUpTest, Mode1WithScopeEqualToDuration) { int i, n = 4; // n = number of soil layers to test RealD *prevTemp = new double[n], *prevMoist = new double[n]; - SW_All.Model.SW_SpinUp.mode = 1; - SW_All.Model.SW_SpinUp.scope = 3; - SW_All.Model.SW_SpinUp.duration = 3; + SW_Run.Model.SW_SpinUp.mode = 1; + SW_Run.Model.SW_SpinUp.scope = 3; + SW_Run.Model.SW_SpinUp.duration = 3; // Turn on soil temperature simulations - SW_All.Site.use_soil_temp = swTRUE; + SW_Run.Site.use_soil_temp = swTRUE; // Get initial soil temp and soil moisture levels for (i = 0; i < n; i++) { - prevTemp[i] = SW_All.Site.avgLyrTempInit[i]; - prevMoist[i] = SW_All.SoilWat.swcBulk[Today][i]; + prevTemp[i] = SW_Run.Site.avgLyrTempInit[i]; + prevMoist[i] = SW_Run.SoilWat.swcBulk[Today][i]; } // Turn on spinup flag - SW_All.Model.SW_SpinUp.spinup = swTRUE; + SW_Run.Model.SW_SpinUp.spinup = swTRUE; // Run the spinup - SW_CTL_run_spinup(&SW_All, &SW_Domain.OutDom, &LogInfo); + SW_CTL_run_spinup(&SW_Run, &SW_Domain.OutDom, &LogInfo); sw_fail_on_error(&LogInfo); // Run (a short) simulation - SW_All.Model.startyr = 1980; - SW_All.Model.endyr = 1981; - SW_CTL_main(&SW_All, &SW_Domain.OutDom, &LogInfo); + SW_Run.Model.startyr = 1980; + SW_Run.Model.endyr = 1981; + SW_CTL_main(&SW_Run, &SW_Domain.OutDom, &LogInfo); sw_fail_on_error(&LogInfo); // exit test program if unexpected error for (i = 0; i < n; i++) { // Check soil temp after spinup - EXPECT_NE(prevTemp[i], SW_All.SoilWat.avgLyrTemp[i]) + EXPECT_NE(prevTemp[i], SW_Run.SoilWat.avgLyrTemp[i]) << "Soil temp error in test " << i << ": " - << SW_All.SoilWat.avgLyrTemp[i]; + << SW_Run.SoilWat.avgLyrTemp[i]; // Check soil moisture after spinup - EXPECT_NE(prevMoist[i], SW_All.SoilWat.swcBulk[Today][i]) + EXPECT_NE(prevMoist[i], SW_Run.SoilWat.swcBulk[Today][i]) << "Soil moisture error in test " << i << ": " - << SW_All.SoilWat.swcBulk[Today][i]; + << SW_Run.SoilWat.swcBulk[Today][i]; } // Deallocate arrays @@ -113,40 +113,40 @@ TEST_F(SpinUpTest, Mode1WithScopeLessThanDuration) { int i, n = 4; // n = number of soil layers to test RealD *prevTemp = new double[n], *prevMoist = new double[n]; - SW_All.Model.SW_SpinUp.mode = 1; - SW_All.Model.SW_SpinUp.scope = 1; - SW_All.Model.SW_SpinUp.duration = 3; + SW_Run.Model.SW_SpinUp.mode = 1; + SW_Run.Model.SW_SpinUp.scope = 1; + SW_Run.Model.SW_SpinUp.duration = 3; // Turn on soil temperature simulations - SW_All.Site.use_soil_temp = swTRUE; + SW_Run.Site.use_soil_temp = swTRUE; // Get initial soil temp and soil moisture levels for (i = 0; i < n; i++) { - prevTemp[i] = SW_All.Site.avgLyrTempInit[i]; - prevMoist[i] = SW_All.SoilWat.swcBulk[Today][i]; + prevTemp[i] = SW_Run.Site.avgLyrTempInit[i]; + prevMoist[i] = SW_Run.SoilWat.swcBulk[Today][i]; } // Turn on spinup flag - SW_All.Model.SW_SpinUp.spinup = swTRUE; + SW_Run.Model.SW_SpinUp.spinup = swTRUE; // Run the spinup - SW_CTL_run_spinup(&SW_All, &SW_Domain.OutDom, &LogInfo); + SW_CTL_run_spinup(&SW_Run, &SW_Domain.OutDom, &LogInfo); sw_fail_on_error(&LogInfo); // Run (a short) simulation - SW_All.Model.startyr = 1980; - SW_All.Model.endyr = 1981; - SW_CTL_main(&SW_All, &SW_Domain.OutDom, &LogInfo); + SW_Run.Model.startyr = 1980; + SW_Run.Model.endyr = 1981; + SW_CTL_main(&SW_Run, &SW_Domain.OutDom, &LogInfo); sw_fail_on_error(&LogInfo); // exit test program if unexpected error for (i = 0; i < n; i++) { // Check soil temp after spinup - EXPECT_NE(prevTemp[i], SW_All.SoilWat.avgLyrTemp[i]) + EXPECT_NE(prevTemp[i], SW_Run.SoilWat.avgLyrTemp[i]) << "Soil temp error in test " << i << ": " - << SW_All.SoilWat.avgLyrTemp[i]; + << SW_Run.SoilWat.avgLyrTemp[i]; // Check soil moisture after spinup - EXPECT_NE(prevMoist[i], SW_All.SoilWat.swcBulk[Today][i]) + EXPECT_NE(prevMoist[i], SW_Run.SoilWat.swcBulk[Today][i]) << "Soil moisture error in test " << i << ": " - << SW_All.SoilWat.swcBulk[Today][i]; + << SW_Run.SoilWat.swcBulk[Today][i]; } // Deallocate arrays @@ -159,40 +159,40 @@ TEST_F(SpinUpTest, Mode2WithScopeGreaterThanDuration) { int i, n = 4; // n = number of soil layers to test RealD *prevTemp = new double[n], *prevMoist = new double[n]; - SW_All.Model.SW_SpinUp.mode = 2; - SW_All.Model.SW_SpinUp.scope = 27; - SW_All.Model.SW_SpinUp.duration = 3; + SW_Run.Model.SW_SpinUp.mode = 2; + SW_Run.Model.SW_SpinUp.scope = 27; + SW_Run.Model.SW_SpinUp.duration = 3; // Turn on soil temperature simulations - SW_All.Site.use_soil_temp = swTRUE; + SW_Run.Site.use_soil_temp = swTRUE; // Get initial soil temp and soil moisture levels for (i = 0; i < n; i++) { - prevTemp[i] = SW_All.Site.avgLyrTempInit[i]; - prevMoist[i] = SW_All.SoilWat.swcBulk[Today][i]; + prevTemp[i] = SW_Run.Site.avgLyrTempInit[i]; + prevMoist[i] = SW_Run.SoilWat.swcBulk[Today][i]; } // Turn on spinup flag - SW_All.Model.SW_SpinUp.spinup = swTRUE; + SW_Run.Model.SW_SpinUp.spinup = swTRUE; // Run the spinup - SW_CTL_run_spinup(&SW_All, &SW_Domain.OutDom, &LogInfo); + SW_CTL_run_spinup(&SW_Run, &SW_Domain.OutDom, &LogInfo); sw_fail_on_error(&LogInfo); // Run (a short) simulation - SW_All.Model.startyr = 1980; - SW_All.Model.endyr = 1981; - SW_CTL_main(&SW_All, &SW_Domain.OutDom, &LogInfo); + SW_Run.Model.startyr = 1980; + SW_Run.Model.endyr = 1981; + SW_CTL_main(&SW_Run, &SW_Domain.OutDom, &LogInfo); sw_fail_on_error(&LogInfo); // exit test program if unexpected error for (i = 0; i < n; i++) { // Check soil temp after spinup - EXPECT_NE(prevTemp[i], SW_All.SoilWat.avgLyrTemp[i]) + EXPECT_NE(prevTemp[i], SW_Run.SoilWat.avgLyrTemp[i]) << "Soil temp error in test " << i << ": " - << SW_All.SoilWat.avgLyrTemp[i]; + << SW_Run.SoilWat.avgLyrTemp[i]; // Check soil moisture after spinup - EXPECT_NE(prevMoist[i], SW_All.SoilWat.swcBulk[Today][i]) + EXPECT_NE(prevMoist[i], SW_Run.SoilWat.swcBulk[Today][i]) << "Soil moisture error in test " << i << ": " - << SW_All.SoilWat.swcBulk[Today][i]; + << SW_Run.SoilWat.swcBulk[Today][i]; } // Deallocate arrays @@ -205,40 +205,40 @@ TEST_F(SpinUpTest, Mode2WithScopeEqualToDuration) { int i, n = 4; // n = number of soil layers to test RealD *prevTemp = new double[n], *prevMoist = new double[n]; - SW_All.Model.SW_SpinUp.mode = 2; - SW_All.Model.SW_SpinUp.scope = 3; - SW_All.Model.SW_SpinUp.duration = 3; + SW_Run.Model.SW_SpinUp.mode = 2; + SW_Run.Model.SW_SpinUp.scope = 3; + SW_Run.Model.SW_SpinUp.duration = 3; // Turn on soil temperature simulations - SW_All.Site.use_soil_temp = swTRUE; + SW_Run.Site.use_soil_temp = swTRUE; // Get initial soil temp and soil moisture levels for (i = 0; i < n; i++) { - prevTemp[i] = SW_All.Site.avgLyrTempInit[i]; - prevMoist[i] = SW_All.SoilWat.swcBulk[Today][i]; + prevTemp[i] = SW_Run.Site.avgLyrTempInit[i]; + prevMoist[i] = SW_Run.SoilWat.swcBulk[Today][i]; } // Turn on spinup flag - SW_All.Model.SW_SpinUp.spinup = swTRUE; + SW_Run.Model.SW_SpinUp.spinup = swTRUE; // Run the spinup - SW_CTL_run_spinup(&SW_All, &SW_Domain.OutDom, &LogInfo); + SW_CTL_run_spinup(&SW_Run, &SW_Domain.OutDom, &LogInfo); sw_fail_on_error(&LogInfo); // Run (a short) simulation - SW_All.Model.startyr = 1980; - SW_All.Model.endyr = 1981; - SW_CTL_main(&SW_All, &SW_Domain.OutDom, &LogInfo); + SW_Run.Model.startyr = 1980; + SW_Run.Model.endyr = 1981; + SW_CTL_main(&SW_Run, &SW_Domain.OutDom, &LogInfo); sw_fail_on_error(&LogInfo); // exit test program if unexpected error for (i = 0; i < n; i++) { // Check soil temp after spinup - EXPECT_NE(prevTemp[i], SW_All.SoilWat.avgLyrTemp[i]) + EXPECT_NE(prevTemp[i], SW_Run.SoilWat.avgLyrTemp[i]) << "Soil temp error in test " << i << ": " - << SW_All.SoilWat.avgLyrTemp[i]; + << SW_Run.SoilWat.avgLyrTemp[i]; // Check soil moisture after spinup - EXPECT_NE(prevMoist[i], SW_All.SoilWat.swcBulk[Today][i]) + EXPECT_NE(prevMoist[i], SW_Run.SoilWat.swcBulk[Today][i]) << "Soil moisture error in test " << i << ": " - << SW_All.SoilWat.swcBulk[Today][i]; + << SW_Run.SoilWat.swcBulk[Today][i]; } // Deallocate arrays @@ -251,40 +251,40 @@ TEST_F(SpinUpTest, Mode2WithScopeLessThanDuration) { int i, n = 4; // n = number of soil layers to test RealD *prevTemp = new double[n], *prevMoist = new double[n]; - SW_All.Model.SW_SpinUp.mode = 2; - SW_All.Model.SW_SpinUp.scope = 1; - SW_All.Model.SW_SpinUp.duration = 3; + SW_Run.Model.SW_SpinUp.mode = 2; + SW_Run.Model.SW_SpinUp.scope = 1; + SW_Run.Model.SW_SpinUp.duration = 3; // Turn on soil temperature simulations - SW_All.Site.use_soil_temp = swTRUE; + SW_Run.Site.use_soil_temp = swTRUE; // Get initial soil temp and soil moisture levels for (i = 0; i < n; i++) { - prevTemp[i] = SW_All.Site.avgLyrTempInit[i]; - prevMoist[i] = SW_All.SoilWat.swcBulk[Today][i]; + prevTemp[i] = SW_Run.Site.avgLyrTempInit[i]; + prevMoist[i] = SW_Run.SoilWat.swcBulk[Today][i]; } // Turn on spinup flag - SW_All.Model.SW_SpinUp.spinup = swTRUE; + SW_Run.Model.SW_SpinUp.spinup = swTRUE; // Run the spinup - SW_CTL_run_spinup(&SW_All, &SW_Domain.OutDom, &LogInfo); + SW_CTL_run_spinup(&SW_Run, &SW_Domain.OutDom, &LogInfo); sw_fail_on_error(&LogInfo); // Run (a short) simulation - SW_All.Model.startyr = 1980; - SW_All.Model.endyr = 1981; - SW_CTL_main(&SW_All, &SW_Domain.OutDom, &LogInfo); + SW_Run.Model.startyr = 1980; + SW_Run.Model.endyr = 1981; + SW_CTL_main(&SW_Run, &SW_Domain.OutDom, &LogInfo); sw_fail_on_error(&LogInfo); // exit test program if unexpected error for (i = 0; i < n; i++) { // Check soil temp after spinup - EXPECT_NE(prevTemp[i], SW_All.SoilWat.avgLyrTemp[i]) + EXPECT_NE(prevTemp[i], SW_Run.SoilWat.avgLyrTemp[i]) << "Soil temp error in test " << i << ": " - << SW_All.SoilWat.avgLyrTemp[i]; + << SW_Run.SoilWat.avgLyrTemp[i]; // Check soil moisture after spinup - EXPECT_NE(prevMoist[i], SW_All.SoilWat.swcBulk[Today][i]) + EXPECT_NE(prevMoist[i], SW_Run.SoilWat.swcBulk[Today][i]) << "Soil moisture error in test " << i << ": " - << SW_All.SoilWat.swcBulk[Today][i]; + << SW_Run.SoilWat.swcBulk[Today][i]; } // Deallocate arrays @@ -347,7 +347,7 @@ TEST_F(SpinUpTest, SpinupEvaluation) { sw_init_logs(NULL, &local_LogInfo); // deep copy of template - SW_ALL_deepCopy(&SW_All, &local_sw, &local_LogInfo); + SW_RUN_deepCopy(&SW_Run, &local_sw, &local_LogInfo); // exit test program if unexpected error sw_fail_on_error(&local_LogInfo); @@ -431,7 +431,7 @@ TEST_F(SpinUpTest, SpinupEvaluation) { // Run (a short) simulation local_sw.Model.startyr = 1980; local_sw.Model.endyr = 1980; - SW_CTL_main(&SW_All, &SW_Domain.OutDom, &LogInfo); + SW_CTL_main(&SW_Run, &SW_Domain.OutDom, &LogInfo); // exit test program if unexpected error sw_fail_on_error(&local_LogInfo); diff --git a/tests/gtests/test_SW_VegEstab.cc b/tests/gtests/test_SW_VegEstab.cc index 9f03d0ce0..6954778f6 100644 --- a/tests/gtests/test_SW_VegEstab.cc +++ b/tests/gtests/test_SW_VegEstab.cc @@ -10,7 +10,7 @@ namespace { TEST_F(VegEstabFixtureTest, SimulateWithVegEstab) { // Turn on vegetation establishment and process inputs (but ignore use flag) SW_VES_read2( - &SW_All.VegEstab, + &SW_Run.VegEstab, swTRUE, swFALSE, SW_Domain.PathInfo.InFiles, @@ -19,20 +19,20 @@ TEST_F(VegEstabFixtureTest, SimulateWithVegEstab) { ); // Expect that vegetation establishment is turn on and contains species - EXPECT_TRUE(SW_All.VegEstab.use); - EXPECT_GT(SW_All.VegEstab.count, 0); + EXPECT_TRUE(SW_Run.VegEstab.use); + EXPECT_GT(SW_Run.VegEstab.count, 0); // Run the simulation - SW_CTL_main(&SW_All, &SW_Domain.OutDom, &LogInfo); + SW_CTL_main(&SW_Run, &SW_Domain.OutDom, &LogInfo); sw_fail_on_error(&LogInfo); // exit test program if unexpected error // Expect valid 'day of year' 1-366 output for each species from the // vegetation establishment calculations // note: estab_doy == 0 means no establishment - for (unsigned int i = 0; i < SW_All.VegEstab.count; i++) { - EXPECT_GE(SW_All.VegEstab.parms[i]->estab_doy, 0); - EXPECT_LE(SW_All.VegEstab.parms[i]->estab_doy, 366); + for (unsigned int i = 0; i < SW_Run.VegEstab.count; i++) { + EXPECT_GE(SW_Run.VegEstab.parms[i]->estab_doy, 0); + EXPECT_LE(SW_Run.VegEstab.parms[i]->estab_doy, 366); } } } // namespace diff --git a/tests/gtests/test_SW_VegProd.cc b/tests/gtests/test_SW_VegProd.cc index 838768368..78d4e975e 100644 --- a/tests/gtests/test_SW_VegProd.cc +++ b/tests/gtests/test_SW_VegProd.cc @@ -87,7 +87,7 @@ int k; TEST_F(VegProdFixtureTest, VegProdConstructor) { // This test requires a local copy of SW_VEGPROD to avoid a memory leak // (see issue #205) - // -- If using `SW_All.VegProd` or a global variable + // -- If using `SW_Run.VegProd` or a global variable // (for which `SW_VPD_construct()` has already been called once, e.g., // during the test fixture's `SetUp()`), then this (second) call to // `SW_VPD_construct()` would allocate memory a second time @@ -102,7 +102,7 @@ TEST_F(VegProdFixtureTest, VegProdConstructor) { SW_VPD_alloc_outptrs(&SW_VegProd, &LogInfo); sw_fail_on_error(&LogInfo); // exit test program if unexpected error - SW_VPD_init_run(&SW_VegProd, &SW_All.Weather, &SW_All.Model, &LogInfo); + SW_VPD_init_run(&SW_VegProd, &SW_Run.Weather, &SW_Run.Model, &LogInfo); sw_fail_on_error(&LogInfo); // exit test program if unexpected error ForEachVegType(k) { @@ -162,29 +162,29 @@ TEST(VegProdTest, VegProdSumming) { TEST_F(VegProdFixtureTest, VegProdrank) { int k; // Check `get_critical_rank` for normal inputs, e.g., -2.0, -2.0, -3.5, -3.9 - get_critical_rank(&SW_All.VegProd); - assert_decreasing_SWPcrit(&SW_All.VegProd); + get_critical_rank(&SW_Run.VegProd); + assert_decreasing_SWPcrit(&SW_Run.VegProd); // Check `get_critical_rank` for constant values - ForEachVegType(k) { SW_All.VegProd.critSoilWater[k] = 0.; } + ForEachVegType(k) { SW_Run.VegProd.critSoilWater[k] = 0.; } - get_critical_rank(&SW_All.VegProd); - assert_decreasing_SWPcrit(&SW_All.VegProd); + get_critical_rank(&SW_Run.VegProd); + assert_decreasing_SWPcrit(&SW_Run.VegProd); // Check `get_critical_rank` for increasing values - ForEachVegType(k) { SW_All.VegProd.critSoilWater[k] = k; } + ForEachVegType(k) { SW_Run.VegProd.critSoilWater[k] = k; } - get_critical_rank(&SW_All.VegProd); - assert_decreasing_SWPcrit(&SW_All.VegProd); + get_critical_rank(&SW_Run.VegProd); + assert_decreasing_SWPcrit(&SW_Run.VegProd); // Check `get_critical_rank` for decreasing values - ForEachVegType(k) { SW_All.VegProd.critSoilWater[k] = NVEGTYPES - k; } + ForEachVegType(k) { SW_Run.VegProd.critSoilWater[k] = NVEGTYPES - k; } - get_critical_rank(&SW_All.VegProd); - assert_decreasing_SWPcrit(&SW_All.VegProd); + get_critical_rank(&SW_Run.VegProd); + assert_decreasing_SWPcrit(&SW_Run.VegProd); } TEST_F(VegProdFixtureTest, VegProdEstimateVegNotFullVegetation) { @@ -229,21 +229,21 @@ TEST_F(VegProdFixtureTest, VegProdEstimateVegNotFullVegetation) { double RelAbundanceL1Expected[5]; double grassOutputExpected[3]; - SW_All.Model.startyr = 1980; - SW_All.Model.endyr = 2010; + SW_Run.Model.startyr = 1980; + SW_Run.Model.endyr = 2010; - SW_All.VegProd.veg_method = 1; - SW_All.Model.latitude = 90.0; + SW_Run.VegProd.veg_method = 1; + SW_Run.Model.latitude = 90.0; - // Reset "SW_All.Weather.allHist" - SW_WTH_read(&SW_All.Weather, &SW_All.Sky, &SW_All.Model, &LogInfo); + // Reset "SW_Run.Weather.allHist" + SW_WTH_read(&SW_Run.Weather, &SW_Run.Sky, &SW_Run.Model, &LogInfo); sw_fail_on_error(&LogInfo); // exit test program if unexpected error finalizeAllWeather( - &SW_All.Markov, - &SW_All.Weather, - SW_All.Model.cum_monthdays, - SW_All.Model.days_in_month, + &SW_Run.Markov, + &SW_Run.Weather, + SW_Run.Model.cum_monthdays, + SW_Run.Model.days_in_month, &LogInfo ); sw_fail_on_error(&LogInfo); // exit test program if unexpected error @@ -255,9 +255,9 @@ TEST_F(VegProdFixtureTest, VegProdEstimateVegNotFullVegetation) { // Calculate climate of the site and add results to "climateOutput" calcSiteClimate( - SW_All.Weather.allHist, - SW_All.Model.cum_monthdays, - SW_All.Model.days_in_month, + SW_Run.Weather.allHist, + SW_Run.Model.cum_monthdays, + SW_Run.Model.days_in_month, 31, 1980, inNorthHem, @@ -560,21 +560,21 @@ TEST_F(VegProdFixtureTest, VegProdEstimateVegNotFullVegetation) { estimateVegetationFromClimate( - &SW_All.VegProd, SW_All.Weather.allHist, &SW_All.Model, &LogInfo + &SW_Run.VegProd, SW_Run.Weather.allHist, &SW_Run.Model, &LogInfo ); sw_fail_on_error(&LogInfo); // exit test program if unexpected error // Loop through RelAbundanceL1 and test results for (index = 0; index < 4; index++) { EXPECT_NEAR( - SW_All.VegProd.veg[index].cov.fCover, + SW_Run.VegProd.veg[index].cov.fCover, RelAbundanceL1Expected[index], tol6 ); } EXPECT_NEAR( - SW_All.VegProd.bare_cov.fCover, + SW_Run.VegProd.bare_cov.fCover, RelAbundanceL1Expected[bareGroundL1], tol6 ); @@ -596,9 +596,9 @@ TEST_F(VegProdFixtureTest, VegProdEstimateVegNotFullVegetation) { // "climateOutput" inNorthHem = swFALSE; calcSiteClimate( - SW_All.Weather.allHist, - SW_All.Model.cum_monthdays, - SW_All.Model.days_in_month, + SW_Run.Weather.allHist, + SW_Run.Model.cum_monthdays, + SW_Run.Model.days_in_month, 31, 1980, inNorthHem, @@ -813,15 +813,15 @@ TEST_F(VegProdFixtureTest, VegProdEstimateVegFullVegetation) { Bool fixBareGround = swTRUE; - // Reset "SW_All.Weather.allHist" - SW_WTH_read(&SW_All.Weather, &SW_All.Sky, &SW_All.Model, &LogInfo); + // Reset "SW_Run.Weather.allHist" + SW_WTH_read(&SW_Run.Weather, &SW_Run.Sky, &SW_Run.Model, &LogInfo); sw_fail_on_error(&LogInfo); // exit test program if unexpected error finalizeAllWeather( - &SW_All.Markov, - &SW_All.Weather, - SW_All.Model.cum_monthdays, - SW_All.Model.days_in_month, + &SW_Run.Markov, + &SW_Run.Weather, + SW_Run.Model.cum_monthdays, + SW_Run.Model.days_in_month, &LogInfo ); sw_fail_on_error(&LogInfo); // exit test program if unexpected error @@ -833,9 +833,9 @@ TEST_F(VegProdFixtureTest, VegProdEstimateVegFullVegetation) { // Calculate climate of the site and add results to "climateOutput" calcSiteClimate( - SW_All.Weather.allHist, - SW_All.Model.cum_monthdays, - SW_All.Model.days_in_month, + SW_Run.Weather.allHist, + SW_Run.Model.cum_monthdays, + SW_Run.Model.days_in_month, 31, 1980, inNorthHem, @@ -1396,24 +1396,24 @@ TEST_F(VegProdFixtureTest, EstimateVegInputGreaterThanOne1DeathTest) { =============================================================== */ - // Reset "SW_All.Weather.allHist" - SW_WTH_read(&SW_All.Weather, &SW_All.Sky, &SW_All.Model, &LogInfo); + // Reset "SW_Run.Weather.allHist" + SW_WTH_read(&SW_Run.Weather, &SW_Run.Sky, &SW_Run.Model, &LogInfo); sw_fail_on_error(&LogInfo); // exit test program if unexpected error finalizeAllWeather( - &SW_All.Markov, - &SW_All.Weather, - SW_All.Model.cum_monthdays, - SW_All.Model.days_in_month, + &SW_Run.Markov, + &SW_Run.Weather, + SW_Run.Model.cum_monthdays, + SW_Run.Model.days_in_month, &LogInfo ); sw_fail_on_error(&LogInfo); // exit test program if unexpected error // Calculate climate of the site and add results to "climateOutput" calcSiteClimate( - SW_All.Weather.allHist, - SW_All.Model.cum_monthdays, - SW_All.Model.days_in_month, + SW_Run.Weather.allHist, + SW_Run.Model.cum_monthdays, + SW_Run.Model.days_in_month, 31, 1980, inNorthHem, @@ -1510,15 +1510,15 @@ TEST_F(VegProdFixtureTest, EstimateVegInputGreaterThanOne2DeathTest) { initial input sum =============================================================== */ - // Reset "SW_All.Weather.allHist" - SW_WTH_read(&SW_All.Weather, &SW_All.Sky, &SW_All.Model, &LogInfo); + // Reset "SW_Run.Weather.allHist" + SW_WTH_read(&SW_Run.Weather, &SW_Run.Sky, &SW_Run.Model, &LogInfo); sw_fail_on_error(&LogInfo); // exit test program if unexpected error finalizeAllWeather( - &SW_All.Markov, - &SW_All.Weather, - SW_All.Model.cum_monthdays, - SW_All.Model.days_in_month, + &SW_Run.Markov, + &SW_Run.Weather, + SW_Run.Model.cum_monthdays, + SW_Run.Model.days_in_month, &LogInfo ); sw_fail_on_error(&LogInfo); // exit test program if unexpected error @@ -1526,9 +1526,9 @@ TEST_F(VegProdFixtureTest, EstimateVegInputGreaterThanOne2DeathTest) { // Calculate climate of the site and add results to "climateOutput" calcSiteClimate( - SW_All.Weather.allHist, - SW_All.Model.cum_monthdays, - SW_All.Model.days_in_month, + SW_Run.Weather.allHist, + SW_Run.Model.cum_monthdays, + SW_Run.Model.days_in_month, 31, 1980, inNorthHem, diff --git a/tests/gtests/test_SW_Weather.cc b/tests/gtests/test_SW_Weather.cc index 5ad0f4ce9..c61c73966 100644 --- a/tests/gtests/test_SW_Weather.cc +++ b/tests/gtests/test_SW_Weather.cc @@ -20,78 +20,78 @@ namespace { TEST_F(WeatherFixtureTest, WeatherDefaultValues) { // Testing to fill allHist from `SW_Weather` - SW_SKY_read(SW_Domain.PathInfo.InFiles, &SW_All.Sky, &LogInfo); + SW_SKY_read(SW_Domain.PathInfo.InFiles, &SW_Run.Sky, &LogInfo); sw_fail_on_error(&LogInfo); // exit test program if unexpected error readAllWeather( - SW_All.Weather.allHist, + SW_Run.Weather.allHist, 1980, - SW_All.Weather.n_years, - SW_All.Weather.use_weathergenerator_only, - SW_All.Weather.name_prefix, - SW_All.Weather.use_cloudCoverMonthly, - SW_All.Weather.use_humidityMonthly, - SW_All.Weather.use_windSpeedMonthly, - SW_All.Weather.n_input_forcings, - SW_All.Weather.dailyInputIndices, - SW_All.Weather.dailyInputFlags, - SW_All.Sky.cloudcov, - SW_All.Sky.windspeed, - SW_All.Sky.r_humidity, - SW_All.Model.cum_monthdays, - SW_All.Model.days_in_month, + SW_Run.Weather.n_years, + SW_Run.Weather.use_weathergenerator_only, + SW_Run.Weather.name_prefix, + SW_Run.Weather.use_cloudCoverMonthly, + SW_Run.Weather.use_humidityMonthly, + SW_Run.Weather.use_windSpeedMonthly, + SW_Run.Weather.n_input_forcings, + SW_Run.Weather.dailyInputIndices, + SW_Run.Weather.dailyInputFlags, + SW_Run.Sky.cloudcov, + SW_Run.Sky.windspeed, + SW_Run.Sky.r_humidity, + SW_Run.Model.cum_monthdays, + SW_Run.Model.days_in_month, &LogInfo ); sw_fail_on_error(&LogInfo); // exit test program if unexpected error // Test first day of first year in `allHist` to make sure correct // temperature max/min/avg and precipitation values - EXPECT_NEAR(SW_All.Weather.allHist[0]->temp_max[0], -0.520000, tol6); - EXPECT_NEAR(SW_All.Weather.allHist[0]->temp_avg[0], -8.095000, tol6); - EXPECT_NEAR(SW_All.Weather.allHist[0]->temp_min[0], -15.670000, tol6); - EXPECT_NEAR(SW_All.Weather.allHist[0]->ppt[0], .220000, tol6); + EXPECT_NEAR(SW_Run.Weather.allHist[0]->temp_max[0], -0.520000, tol6); + EXPECT_NEAR(SW_Run.Weather.allHist[0]->temp_avg[0], -8.095000, tol6); + EXPECT_NEAR(SW_Run.Weather.allHist[0]->temp_min[0], -15.670000, tol6); + EXPECT_NEAR(SW_Run.Weather.allHist[0]->ppt[0], .220000, tol6); } TEST_F(WeatherFixtureTest, WeatherNoMemoryLeakIfDecreasedNumberOfYears) { // Default number of years is 31 - EXPECT_EQ(SW_All.Weather.n_years, 31); + EXPECT_EQ(SW_Run.Weather.n_years, 31); // Decrease number of years - SW_All.Model.startyr = 1981; - SW_All.Model.endyr = 1982; + SW_Run.Model.startyr = 1981; + SW_Run.Model.endyr = 1982; // Real expectation is that there is no memory leak for `allHist` - SW_WTH_read(&SW_All.Weather, &SW_All.Sky, &SW_All.Model, &LogInfo); + SW_WTH_read(&SW_Run.Weather, &SW_Run.Sky, &SW_Run.Model, &LogInfo); sw_fail_on_error(&LogInfo); // exit test program if unexpected error - EXPECT_EQ(SW_All.Weather.n_years, 2); + EXPECT_EQ(SW_Run.Weather.n_years, 2); } TEST_F(WeatherFixtureTest, WeatherSomeMissingValuesDays) { - SW_All.Weather.generateWeatherMethod = 2; + SW_Run.Weather.generateWeatherMethod = 2; // Change directory to get input files with some missing data - strcpy(SW_All.Weather.name_prefix, "Input/data_weather_missing/weath"); + strcpy(SW_Run.Weather.name_prefix, "Input/data_weather_missing/weath"); SW_MKV_setup( - &SW_All.Markov, - SW_All.Weather.rng_seed, - SW_All.Weather.generateWeatherMethod, + &SW_Run.Markov, + SW_Run.Weather.rng_seed, + SW_Run.Weather.generateWeatherMethod, SW_Domain.PathInfo.InFiles, &LogInfo ); sw_fail_on_error(&LogInfo); // exit test program if unexpected error - SW_WTH_read(&SW_All.Weather, &SW_All.Sky, &SW_All.Model, &LogInfo); + SW_WTH_read(&SW_Run.Weather, &SW_Run.Sky, &SW_Run.Model, &LogInfo); sw_fail_on_error(&LogInfo); // exit test program if unexpected error SW_WTH_finalize_all_weather( - &SW_All.Markov, - &SW_All.Weather, - SW_All.Model.cum_monthdays, - SW_All.Model.days_in_month, + &SW_Run.Markov, + &SW_Run.Weather, + SW_Run.Model.cum_monthdays, + SW_Run.Model.days_in_month, &LogInfo ); sw_fail_on_error(&LogInfo); // exit test program if unexpected error @@ -99,42 +99,42 @@ TEST_F(WeatherFixtureTest, WeatherSomeMissingValuesDays) { // Expect that missing input values (from 1980) are filled by the weather // generator - EXPECT_FALSE(missing(SW_All.Weather.allHist[0]->temp_max[0])); - EXPECT_FALSE(missing(SW_All.Weather.allHist[0]->temp_max[1])); - EXPECT_FALSE(missing(SW_All.Weather.allHist[0]->temp_min[0])); - EXPECT_FALSE(missing(SW_All.Weather.allHist[0]->temp_min[2])); - EXPECT_FALSE(missing(SW_All.Weather.allHist[0]->ppt[0])); - EXPECT_FALSE(missing(SW_All.Weather.allHist[0]->ppt[3])); + EXPECT_FALSE(missing(SW_Run.Weather.allHist[0]->temp_max[0])); + EXPECT_FALSE(missing(SW_Run.Weather.allHist[0]->temp_max[1])); + EXPECT_FALSE(missing(SW_Run.Weather.allHist[0]->temp_min[0])); + EXPECT_FALSE(missing(SW_Run.Weather.allHist[0]->temp_min[2])); + EXPECT_FALSE(missing(SW_Run.Weather.allHist[0]->ppt[0])); + EXPECT_FALSE(missing(SW_Run.Weather.allHist[0]->ppt[3])); } TEST_F(WeatherFixtureTest, WeatherSomeMissingValuesYears) { int year, day; - SW_All.Weather.generateWeatherMethod = 2; + SW_Run.Weather.generateWeatherMethod = 2; // Change directory to get input files with some missing data - strcpy(SW_All.Weather.name_prefix, "Input/data_weather_missing/weath"); + strcpy(SW_Run.Weather.name_prefix, "Input/data_weather_missing/weath"); SW_MKV_setup( - &SW_All.Markov, - SW_All.Weather.rng_seed, - SW_All.Weather.generateWeatherMethod, + &SW_Run.Markov, + SW_Run.Weather.rng_seed, + SW_Run.Weather.generateWeatherMethod, SW_Domain.PathInfo.InFiles, &LogInfo ); sw_fail_on_error(&LogInfo); // exit test program if unexpected error - SW_All.Model.startyr = 1981; - SW_All.Model.endyr = 1982; + SW_Run.Model.startyr = 1981; + SW_Run.Model.endyr = 1982; - SW_WTH_read(&SW_All.Weather, &SW_All.Sky, &SW_All.Model, &LogInfo); + SW_WTH_read(&SW_Run.Weather, &SW_Run.Sky, &SW_Run.Model, &LogInfo); sw_fail_on_error(&LogInfo); // exit test program if unexpected error SW_WTH_finalize_all_weather( - &SW_All.Markov, - &SW_All.Weather, - SW_All.Model.cum_monthdays, - SW_All.Model.days_in_month, + &SW_Run.Markov, + &SW_Run.Weather, + SW_Run.Model.cum_monthdays, + SW_Run.Model.days_in_month, &LogInfo ); sw_fail_on_error(&LogInfo); // exit test program if unexpected error @@ -143,7 +143,7 @@ TEST_F(WeatherFixtureTest, WeatherSomeMissingValuesYears) { // Check everyday's value and test if it's `MISSING` for (year = 0; year < 2; year++) { for (day = 0; day < 365; day++) { - EXPECT_TRUE(!missing(SW_All.Weather.allHist[year]->temp_max[day])); + EXPECT_TRUE(!missing(SW_Run.Weather.allHist[year]->temp_max[day])); } } } @@ -152,29 +152,29 @@ TEST_F(WeatherFixtureTest, WeatherWeatherGeneratorOnly) { int year, day; - SW_All.Weather.generateWeatherMethod = 2; - SW_All.Weather.use_weathergenerator_only = swTRUE; + SW_Run.Weather.generateWeatherMethod = 2; + SW_Run.Weather.use_weathergenerator_only = swTRUE; SW_MKV_setup( - &SW_All.Markov, - SW_All.Weather.rng_seed, - SW_All.Weather.generateWeatherMethod, + &SW_Run.Markov, + SW_Run.Weather.rng_seed, + SW_Run.Weather.generateWeatherMethod, SW_Domain.PathInfo.InFiles, &LogInfo ); sw_fail_on_error(&LogInfo); // exit test program if unexpected error // Change directory to get input files with some missing data - strcpy(SW_All.Weather.name_prefix, "Input/data_weather_nonexisting/weath"); + strcpy(SW_Run.Weather.name_prefix, "Input/data_weather_nonexisting/weath"); - SW_WTH_read(&SW_All.Weather, &SW_All.Sky, &SW_All.Model, &LogInfo); + SW_WTH_read(&SW_Run.Weather, &SW_Run.Sky, &SW_Run.Model, &LogInfo); sw_fail_on_error(&LogInfo); // exit test program if unexpected error SW_WTH_finalize_all_weather( - &SW_All.Markov, - &SW_All.Weather, - SW_All.Model.cum_monthdays, - SW_All.Model.days_in_month, + &SW_Run.Markov, + &SW_Run.Weather, + SW_Run.Model.cum_monthdays, + SW_Run.Model.days_in_month, &LogInfo ); sw_fail_on_error(&LogInfo); // exit test program if unexpected error @@ -182,7 +182,7 @@ TEST_F(WeatherFixtureTest, WeatherWeatherGeneratorOnly) { // Check everyday's value and test if it's `MISSING` for (year = 0; year < 31; year++) { for (day = 0; day < 365; day++) { - EXPECT_TRUE(!missing(SW_All.Weather.allHist[year]->temp_max[day])); + EXPECT_TRUE(!missing(SW_Run.Weather.allHist[year]->temp_max[day])); } } } @@ -192,22 +192,22 @@ TEST_F(WeatherFixtureTest, ReadAllWeatherTooManyMissingForLOCFDeathTest) { // Error: too many missing values and weather generator turned off // Change to directory without input files - strcpy(SW_All.Weather.name_prefix, "Input/data_weather_nonexisting/weath"); + strcpy(SW_Run.Weather.name_prefix, "Input/data_weather_nonexisting/weath"); // Set LOCF (temp) + 0 (PPT) method - SW_All.Weather.generateWeatherMethod = 1; + SW_Run.Weather.generateWeatherMethod = 1; - SW_All.Model.startyr = 1981; - SW_All.Model.endyr = 1981; + SW_Run.Model.startyr = 1981; + SW_Run.Model.endyr = 1981; - SW_WTH_read(&SW_All.Weather, &SW_All.Sky, &SW_All.Model, &LogInfo); + SW_WTH_read(&SW_Run.Weather, &SW_Run.Sky, &SW_Run.Model, &LogInfo); sw_fail_on_error(&LogInfo); // exit test program if unexpected error SW_WTH_finalize_all_weather( - &SW_All.Markov, - &SW_All.Weather, - SW_All.Model.cum_monthdays, - SW_All.Model.days_in_month, + &SW_Run.Markov, + &SW_Run.Weather, + SW_Run.Model.cum_monthdays, + SW_Run.Model.days_in_month, &LogInfo ); // expect error: don't exit test program via `sw_fail_on_error(&LogInfo)` @@ -252,9 +252,9 @@ TEST_F(WeatherFixtureTest, ClimateVariableClimateFromDefaultWeather) { */ calcSiteClimate( - SW_All.Weather.allHist, - SW_All.Model.cum_monthdays, - SW_All.Model.days_in_month, + SW_Run.Weather.allHist, + SW_Run.Model.cum_monthdays, + SW_Run.Model.days_in_month, 31, 1980, inNorthHem, @@ -360,9 +360,9 @@ TEST_F(WeatherFixtureTest, ClimateVariableClimateFromOneYearWeather) { */ calcSiteClimate( - SW_All.Weather.allHist, - SW_All.Model.cum_monthdays, - SW_All.Model.days_in_month, + SW_Run.Weather.allHist, + SW_Run.Model.cum_monthdays, + SW_Run.Model.days_in_month, 1, 1980, inNorthHem, @@ -491,9 +491,9 @@ TEST_F(WeatherFixtureTest, ClimateFromDefaultWeatherSouth) { */ calcSiteClimate( - SW_All.Weather.allHist, - SW_All.Model.cum_monthdays, - SW_All.Model.days_in_month, + SW_Run.Weather.allHist, + SW_Run.Model.cum_monthdays, + SW_Run.Model.days_in_month, 31, 1980, inSouthHem, @@ -612,8 +612,8 @@ TEST_F(WeatherFixtureTest, ClimateVariableClimateFromConstantWeather) { // --- Annual time-series of climate variables ------ calcSiteClimate( allHist, - SW_All.Model.cum_monthdays, - SW_All.Model.days_in_month, + SW_Run.Model.cum_monthdays, + SW_Run.Model.days_in_month, n_years, 1980, inNorthHem, @@ -754,10 +754,10 @@ TEST_F( TEST_F(WeatherFixtureTest, WeatherReadInitialization) { - SW_WTH_read(&SW_All.Weather, &SW_All.Sky, &SW_All.Model, &LogInfo); + SW_WTH_read(&SW_Run.Weather, &SW_Run.Sky, &SW_Run.Model, &LogInfo); sw_fail_on_error(&LogInfo); // exit test program if unexpected error - EXPECT_FLOAT_EQ(SW_All.Weather.allHist[0]->temp_max[0], -.52); + EXPECT_FLOAT_EQ(SW_Run.Weather.allHist[0]->temp_max[0], -.52); } TEST_F(WeatherFixtureTest, WeatherMonthlyInputPrioritization) { @@ -771,7 +771,7 @@ TEST_F(WeatherFixtureTest, WeatherMonthlyInputPrioritization) { /* Test if monthly values are not being used */ SW_WTH_setup( - &SW_All.Weather, + &SW_Run.Weather, SW_Domain.PathInfo.InFiles, SW_Domain.PathInfo.weather_prefix, &LogInfo @@ -779,27 +779,27 @@ TEST_F(WeatherFixtureTest, WeatherMonthlyInputPrioritization) { sw_fail_on_error(&LogInfo); // exit test program if unexpected error // Read in all weather - SW_WTH_read(&SW_All.Weather, &SW_All.Sky, &SW_All.Model, &LogInfo); + SW_WTH_read(&SW_Run.Weather, &SW_Run.Sky, &SW_Run.Model, &LogInfo); sw_fail_on_error(&LogInfo); // exit test program if unexpected error // Test the middle of January in year 1980 and see if it's not equal to - // SW_All.Sky.r_humidity[0], SW_All.Sky.cloudcov[0], and - // SW_All.Sky.windspeed[0] Note: Daily interpolated values in the middle of + // SW_Run.Sky.r_humidity[0], SW_Run.Sky.cloudcov[0], and + // SW_Run.Sky.windspeed[0] Note: Daily interpolated values in the middle of // a month are equal to the original monthly values from which they were // interpolated EXPECT_NEAR( - SW_All.Weather.allHist[yearIndex]->r_humidity_daily[midJanDay], - SW_All.Sky.r_humidity[0], + SW_Run.Weather.allHist[yearIndex]->r_humidity_daily[midJanDay], + SW_Run.Sky.r_humidity[0], tol6 ); EXPECT_NEAR( - SW_All.Weather.allHist[yearIndex]->cloudcov_daily[midJanDay], - SW_All.Sky.cloudcov[0], + SW_Run.Weather.allHist[yearIndex]->cloudcov_daily[midJanDay], + SW_Run.Sky.cloudcov[0], tol6 ); EXPECT_NEAR( - SW_All.Weather.allHist[yearIndex]->windspeed_daily[midJanDay], - SW_All.Sky.windspeed[0], + SW_Run.Weather.allHist[yearIndex]->windspeed_daily[midJanDay], + SW_Run.Sky.windspeed[0], tol6 ); } @@ -819,7 +819,7 @@ TEST_F(WeatherFixtureTest, WeatherInputDailyGridMet) { /* Test correct priority is being given to input values from DAYMET */ SW_WTH_setup( - &SW_All.Weather, + &SW_Run.Weather, SW_Domain.PathInfo.InFiles, SW_Domain.PathInfo.weather_prefix, &LogInfo @@ -827,44 +827,44 @@ TEST_F(WeatherFixtureTest, WeatherInputDailyGridMet) { sw_fail_on_error(&LogInfo); // exit test program if unexpected error // Switch directory to gridmet input folder - strcpy(SW_All.Weather.name_prefix, "Input/data_weather_gridmet/weath"); + strcpy(SW_Run.Weather.name_prefix, "Input/data_weather_gridmet/weath"); // Turn off monthly flags - SW_All.Weather.use_cloudCoverMonthly = swFALSE; - SW_All.Weather.use_windSpeedMonthly = swFALSE; - SW_All.Weather.use_humidityMonthly = swFALSE; + SW_Run.Weather.use_cloudCoverMonthly = swFALSE; + SW_Run.Weather.use_windSpeedMonthly = swFALSE; + SW_Run.Weather.use_humidityMonthly = swFALSE; // Manually edit index/flag arrays in SW_WEATHER to make test as // realistic as possible // Note: Indices are based on the directory: // Input/data_weather_gridmet/weath.1980 - SW_All.Weather.dailyInputIndices[WIND_SPEED] = 3; - SW_All.Weather.dailyInputIndices[REL_HUMID_MAX] = 4; - SW_All.Weather.dailyInputIndices[REL_HUMID_MIN] = 5; - SW_All.Weather.dailyInputIndices[SHORT_WR] = 6; - SW_All.Weather.dailyInputFlags[WIND_SPEED] = swTRUE; - SW_All.Weather.dailyInputFlags[REL_HUMID_MAX] = swTRUE; - SW_All.Weather.dailyInputFlags[REL_HUMID_MIN] = swTRUE; - SW_All.Weather.dailyInputFlags[SHORT_WR] = swTRUE; - SW_All.Weather.n_input_forcings = 7; - SW_All.Weather.desc_rsds = 1; // gridMET rsds is flux density over 24 hours + SW_Run.Weather.dailyInputIndices[WIND_SPEED] = 3; + SW_Run.Weather.dailyInputIndices[REL_HUMID_MAX] = 4; + SW_Run.Weather.dailyInputIndices[REL_HUMID_MIN] = 5; + SW_Run.Weather.dailyInputIndices[SHORT_WR] = 6; + SW_Run.Weather.dailyInputFlags[WIND_SPEED] = swTRUE; + SW_Run.Weather.dailyInputFlags[REL_HUMID_MAX] = swTRUE; + SW_Run.Weather.dailyInputFlags[REL_HUMID_MIN] = swTRUE; + SW_Run.Weather.dailyInputFlags[SHORT_WR] = swTRUE; + SW_Run.Weather.n_input_forcings = 7; + SW_Run.Weather.desc_rsds = 1; // gridMET rsds is flux density over 24 hours // Reset daily weather values - _clear_hist_weather(SW_All.Weather.allHist[0]); + _clear_hist_weather(SW_Run.Weather.allHist[0]); // Using the new inputs folder, read in year = 1980 _read_weather_hist( year, - SW_All.Weather.allHist[0], - SW_All.Weather.name_prefix, - SW_All.Weather.n_input_forcings, - SW_All.Weather.dailyInputIndices, - SW_All.Weather.dailyInputFlags, + SW_Run.Weather.allHist[0], + SW_Run.Weather.name_prefix, + SW_Run.Weather.n_input_forcings, + SW_Run.Weather.dailyInputIndices, + SW_Run.Weather.dailyInputFlags, &LogInfo ); sw_fail_on_error(&LogInfo); // exit test program if unexpected error - result = SW_All.Weather.allHist[yearIndex]->r_humidity_daily[0]; + result = SW_Run.Weather.allHist[yearIndex]->r_humidity_daily[0]; // Get expected average from Input/data_weather_gridmet/weath.1980 day 1 // hursmax_pct and hursmin_pct @@ -877,17 +877,17 @@ TEST_F(WeatherFixtureTest, WeatherInputDailyGridMet) { // Expect that daily relative humidity is derived from hursmax_pct and // hursmin_pct (and is not interpolated from mean monthly values) EXPECT_NEAR( - SW_All.Weather.allHist[yearIndex]->r_humidity_daily[midJanDay], + SW_Run.Weather.allHist[yearIndex]->r_humidity_daily[midJanDay], (88.35 + 34.35) / 2., tol6 ); EXPECT_NE( - SW_All.Weather.allHist[yearIndex]->r_humidity_daily[midJanDay], - SW_All.Sky.r_humidity[0] + SW_Run.Weather.allHist[yearIndex]->r_humidity_daily[midJanDay], + SW_Run.Sky.r_humidity[0] ); - result = SW_All.Weather.allHist[yearIndex]->actualVaporPressure[0]; + result = SW_Run.Weather.allHist[yearIndex]->actualVaporPressure[0]; // Get expected result from Input/data_weather_gridmet/weath.1980 day 1 // hursmax_pct, hursmin_pct, Tmax_C, and Tmin_C @@ -899,12 +899,12 @@ TEST_F(WeatherFixtureTest, WeatherInputDailyGridMet) { // We have observed radiation and missing cloud cover - EXPECT_FALSE(missing(SW_All.Weather.allHist[yearIndex]->shortWaveRad[0])); - EXPECT_TRUE(missing(SW_All.Weather.allHist[yearIndex]->cloudcov_daily[0])); + EXPECT_FALSE(missing(SW_Run.Weather.allHist[yearIndex]->shortWaveRad[0])); + EXPECT_TRUE(missing(SW_Run.Weather.allHist[yearIndex]->cloudcov_daily[0])); // Make sure calculations and set input values are within reasonable range - checkAllWeather(&SW_All.Weather, &LogInfo); + checkAllWeather(&SW_Run.Weather, &LogInfo); sw_fail_on_error(&LogInfo); // exit test program if unexpected error } @@ -926,7 +926,7 @@ TEST_F(WeatherFixtureTest, WeatherInputDayMet) { /* Test correct priority is being given to input values from DAYMET */ SW_WTH_setup( - &SW_All.Weather, + &SW_Run.Weather, SW_Domain.PathInfo.InFiles, SW_Domain.PathInfo.weather_prefix, &LogInfo @@ -934,41 +934,41 @@ TEST_F(WeatherFixtureTest, WeatherInputDayMet) { sw_fail_on_error(&LogInfo); // exit test program if unexpected error // Switch directory to daymet input folder - strcpy(SW_All.Weather.name_prefix, "Input/data_weather_daymet/weath"); + strcpy(SW_Run.Weather.name_prefix, "Input/data_weather_daymet/weath"); // Turn off monthly flags - SW_All.Weather.use_cloudCoverMonthly = swFALSE; - SW_All.Weather.use_windSpeedMonthly = swFALSE; - SW_All.Weather.use_humidityMonthly = swFALSE; + SW_Run.Weather.use_cloudCoverMonthly = swFALSE; + SW_Run.Weather.use_windSpeedMonthly = swFALSE; + SW_Run.Weather.use_humidityMonthly = swFALSE; // Manually edit index/flag arrays in SW_WEATHER to make test as // realistic as possible // Note: Indices are based on the directory: // Input/data_weather_daymet/weath.1980 - SW_All.Weather.dailyInputIndices[ACTUAL_VP] = 3; - SW_All.Weather.dailyInputIndices[SHORT_WR] = 4; - SW_All.Weather.dailyInputFlags[ACTUAL_VP] = swTRUE; - SW_All.Weather.dailyInputFlags[SHORT_WR] = swTRUE; - SW_All.Weather.n_input_forcings = 5; + SW_Run.Weather.dailyInputIndices[ACTUAL_VP] = 3; + SW_Run.Weather.dailyInputIndices[SHORT_WR] = 4; + SW_Run.Weather.dailyInputFlags[ACTUAL_VP] = swTRUE; + SW_Run.Weather.dailyInputFlags[SHORT_WR] = swTRUE; + SW_Run.Weather.n_input_forcings = 5; // DayMet rsds is flux density over daylight period - SW_All.Weather.desc_rsds = 2; + SW_Run.Weather.desc_rsds = 2; // Reset daily weather values - _clear_hist_weather(SW_All.Weather.allHist[0]); + _clear_hist_weather(SW_Run.Weather.allHist[0]); // Using the new inputs folder, read in year = 1980 _read_weather_hist( year, - SW_All.Weather.allHist[0], - SW_All.Weather.name_prefix, - SW_All.Weather.n_input_forcings, - SW_All.Weather.dailyInputIndices, - SW_All.Weather.dailyInputFlags, + SW_Run.Weather.allHist[0], + SW_Run.Weather.name_prefix, + SW_Run.Weather.n_input_forcings, + SW_Run.Weather.dailyInputIndices, + SW_Run.Weather.dailyInputFlags, &LogInfo ); sw_fail_on_error(&LogInfo); // exit test program if unexpected error - result = SW_All.Weather.allHist[yearIndex]->actualVaporPressure[0]; + result = SW_Run.Weather.allHist[yearIndex]->actualVaporPressure[0]; // Get expected result from Input/data_weather_daymet/weath.1980 day 1 // vp_kPa @@ -978,7 +978,7 @@ TEST_F(WeatherFixtureTest, WeatherInputDayMet) { // input value from Input/data_weather_daymet/weath.1980 day 1 EXPECT_NEAR(result, expectedResult, tol6); - result = SW_All.Weather.allHist[yearIndex]->r_humidity_daily[0]; + result = SW_Run.Weather.allHist[yearIndex]->r_humidity_daily[0]; // Get expected result from Input/data_weather_daymet/weath.1980 day 1 // Tmax_C = -.37, Tmin_C = -9.2, and vp_kPa = .3 @@ -997,23 +997,23 @@ TEST_F(WeatherFixtureTest, WeatherInputDayMet) { expectedResult = .29 / expectedResult; EXPECT_NEAR( - SW_All.Weather.allHist[yearIndex]->r_humidity_daily[midJanDay], + SW_Run.Weather.allHist[yearIndex]->r_humidity_daily[midJanDay], expectedResult, tol6 ); EXPECT_NE( - SW_All.Weather.allHist[yearIndex]->r_humidity_daily[midJanDay], - SW_All.Sky.r_humidity[0] + SW_Run.Weather.allHist[yearIndex]->r_humidity_daily[midJanDay], + SW_Run.Sky.r_humidity[0] ); // We have observed radiation and missing cloud cover - EXPECT_FALSE(missing(SW_All.Weather.allHist[yearIndex]->shortWaveRad[0])); - EXPECT_TRUE(missing(SW_All.Weather.allHist[yearIndex]->cloudcov_daily[0])); + EXPECT_FALSE(missing(SW_Run.Weather.allHist[yearIndex]->shortWaveRad[0])); + EXPECT_TRUE(missing(SW_Run.Weather.allHist[yearIndex]->cloudcov_daily[0])); // Make sure calculations and set input values are within reasonable range - checkAllWeather(&SW_All.Weather, &LogInfo); + checkAllWeather(&SW_Run.Weather, &LogInfo); sw_fail_on_error(&LogInfo); // exit test program if unexpected error } @@ -1033,7 +1033,7 @@ TEST_F(WeatherFixtureTest, WeatherInputMACA) { /* Test correct priority is being given to input values from MACA */ SW_WTH_setup( - &SW_All.Weather, + &SW_Run.Weather, SW_Domain.PathInfo.InFiles, SW_Domain.PathInfo.weather_prefix, &LogInfo @@ -1041,46 +1041,46 @@ TEST_F(WeatherFixtureTest, WeatherInputMACA) { sw_fail_on_error(&LogInfo); // exit test program if unexpected error // Switch directory to daymet input folder - strcpy(SW_All.Weather.name_prefix, "Input/data_weather_maca/weath"); + strcpy(SW_Run.Weather.name_prefix, "Input/data_weather_maca/weath"); // Turn off monthly flags - SW_All.Weather.use_cloudCoverMonthly = swFALSE; - SW_All.Weather.use_windSpeedMonthly = swFALSE; - SW_All.Weather.use_humidityMonthly = swFALSE; + SW_Run.Weather.use_cloudCoverMonthly = swFALSE; + SW_Run.Weather.use_windSpeedMonthly = swFALSE; + SW_Run.Weather.use_humidityMonthly = swFALSE; // Manually edit index/flag arrays in SW_WEATHER to make test as // realistic as possible // Note: Indices are based on the directory: // Input/data_weather_maca/weath.1980 - SW_All.Weather.dailyInputIndices[WIND_EAST] = 3; - SW_All.Weather.dailyInputIndices[WIND_NORTH] = 4; - SW_All.Weather.dailyInputIndices[REL_HUMID_MAX] = 5; - SW_All.Weather.dailyInputIndices[REL_HUMID_MIN] = 6; - SW_All.Weather.dailyInputIndices[SHORT_WR] = 7; - SW_All.Weather.dailyInputFlags[WIND_EAST] = swTRUE; - SW_All.Weather.dailyInputFlags[WIND_NORTH] = swTRUE; - SW_All.Weather.dailyInputFlags[REL_HUMID_MAX] = swTRUE; - SW_All.Weather.dailyInputFlags[REL_HUMID_MIN] = swTRUE; - SW_All.Weather.dailyInputFlags[SHORT_WR] = swTRUE; - SW_All.Weather.n_input_forcings = 8; - SW_All.Weather.desc_rsds = 1; // MACA rsds is flux density over 24 hours + SW_Run.Weather.dailyInputIndices[WIND_EAST] = 3; + SW_Run.Weather.dailyInputIndices[WIND_NORTH] = 4; + SW_Run.Weather.dailyInputIndices[REL_HUMID_MAX] = 5; + SW_Run.Weather.dailyInputIndices[REL_HUMID_MIN] = 6; + SW_Run.Weather.dailyInputIndices[SHORT_WR] = 7; + SW_Run.Weather.dailyInputFlags[WIND_EAST] = swTRUE; + SW_Run.Weather.dailyInputFlags[WIND_NORTH] = swTRUE; + SW_Run.Weather.dailyInputFlags[REL_HUMID_MAX] = swTRUE; + SW_Run.Weather.dailyInputFlags[REL_HUMID_MIN] = swTRUE; + SW_Run.Weather.dailyInputFlags[SHORT_WR] = swTRUE; + SW_Run.Weather.n_input_forcings = 8; + SW_Run.Weather.desc_rsds = 1; // MACA rsds is flux density over 24 hours // Reset daily weather values - _clear_hist_weather(SW_All.Weather.allHist[0]); + _clear_hist_weather(SW_Run.Weather.allHist[0]); // Using the new inputs folder, read in year = 1980 _read_weather_hist( year, - SW_All.Weather.allHist[0], - SW_All.Weather.name_prefix, - SW_All.Weather.n_input_forcings, - SW_All.Weather.dailyInputIndices, - SW_All.Weather.dailyInputFlags, + SW_Run.Weather.allHist[0], + SW_Run.Weather.name_prefix, + SW_Run.Weather.n_input_forcings, + SW_Run.Weather.dailyInputIndices, + SW_Run.Weather.dailyInputFlags, &LogInfo ); sw_fail_on_error(&LogInfo); // exit test program if unexpected error - result = SW_All.Weather.allHist[yearIndex]->windspeed_daily[0]; + result = SW_Run.Weather.allHist[yearIndex]->windspeed_daily[0]; // Get expected result from Input/data_weather_maca/weath.1980 day 1 // uas_mPERs = 3.31 and vas_mPERs = -.85 @@ -1095,36 +1095,36 @@ TEST_F(WeatherFixtureTest, WeatherInputMACA) { expectedResult = sqrt(squared(2.82) + squared(-.4)); EXPECT_NEAR( - SW_All.Weather.allHist[yearIndex]->windspeed_daily[midJanDay], + SW_Run.Weather.allHist[yearIndex]->windspeed_daily[midJanDay], expectedResult, tol6 ); EXPECT_NE( - SW_All.Weather.allHist[yearIndex]->windspeed_daily[midJanDay], - SW_All.Sky.windspeed[0] + SW_Run.Weather.allHist[yearIndex]->windspeed_daily[midJanDay], + SW_Run.Sky.windspeed[0] ); // Expect that daily relative humidity is derived from hursmax_pct and // hursmin_pct (and is not interpolated from mean monthly values) EXPECT_NEAR( - SW_All.Weather.allHist[yearIndex]->r_humidity_daily[midJanDay], + SW_Run.Weather.allHist[yearIndex]->r_humidity_daily[midJanDay], (80.55 + 32.28) / 2., tol6 ); EXPECT_NE( - SW_All.Weather.allHist[yearIndex]->r_humidity_daily[midJanDay], - SW_All.Sky.r_humidity[0] + SW_Run.Weather.allHist[yearIndex]->r_humidity_daily[midJanDay], + SW_Run.Sky.r_humidity[0] ); // We have observed radiation and missing cloud cover - EXPECT_FALSE(missing(SW_All.Weather.allHist[yearIndex]->shortWaveRad[0])); - EXPECT_TRUE(missing(SW_All.Weather.allHist[yearIndex]->cloudcov_daily[0])); + EXPECT_FALSE(missing(SW_Run.Weather.allHist[yearIndex]->shortWaveRad[0])); + EXPECT_TRUE(missing(SW_Run.Weather.allHist[yearIndex]->cloudcov_daily[0])); // Make sure calculations and set input values are within reasonable range - checkAllWeather(&SW_All.Weather, &LogInfo); + checkAllWeather(&SW_Run.Weather, &LogInfo); sw_fail_on_error(&LogInfo); // exit test program if unexpected error } @@ -1144,7 +1144,7 @@ TEST_F(WeatherFixtureTest, WeatherDailyLOCFInputValues) { // Setup and read in weather SW_WTH_setup( - &SW_All.Weather, + &SW_Run.Weather, SW_Domain.PathInfo.InFiles, SW_Domain.PathInfo.weather_prefix, &LogInfo @@ -1154,26 +1154,26 @@ TEST_F(WeatherFixtureTest, WeatherDailyLOCFInputValues) { // Turn off flags for monthly values along with daily flags // so all daily variables aside from max/min temperature and precipiation // are set to SW_MISSING - SW_All.Weather.use_cloudCoverMonthly = swFALSE; - SW_All.Weather.use_humidityMonthly = swFALSE; - SW_All.Weather.use_windSpeedMonthly = swFALSE; + SW_Run.Weather.use_cloudCoverMonthly = swFALSE; + SW_Run.Weather.use_humidityMonthly = swFALSE; + SW_Run.Weather.use_windSpeedMonthly = swFALSE; - SW_WTH_read(&SW_All.Weather, &SW_All.Sky, &SW_All.Model, &LogInfo); + SW_WTH_read(&SW_Run.Weather, &SW_Run.Sky, &SW_Run.Model, &LogInfo); sw_fail_on_error(&LogInfo); // exit test program if unexpected error // Setup values/flags for `generateMissingWeather()` to deal with - SW_All.Weather.generateWeatherMethod = 1; - SW_All.Weather.allHist[yearIndex]->cloudcov_daily[0] = cloudCovTestVal; - SW_All.Weather.allHist[yearIndex]->actualVaporPressure[0] = + SW_Run.Weather.generateWeatherMethod = 1; + SW_Run.Weather.allHist[yearIndex]->cloudcov_daily[0] = cloudCovTestVal; + SW_Run.Weather.allHist[yearIndex]->actualVaporPressure[0] = actVapPressTestVal; - SW_All.Weather.allHist[yearIndex]->windspeed_daily[0] = windSpeedTestVal; + SW_Run.Weather.allHist[yearIndex]->windspeed_daily[0] = windSpeedTestVal; generateMissingWeather( - &SW_All.Markov, - SW_All.Weather.allHist, + &SW_Run.Markov, + SW_Run.Weather.allHist, 1980, 1, - SW_All.Weather.generateWeatherMethod, + SW_Run.Weather.generateWeatherMethod, numDaysLOCFTolerance, &LogInfo ); @@ -1184,15 +1184,15 @@ TEST_F(WeatherFixtureTest, WeatherDailyLOCFInputValues) { // and windSpeedTestVal, respectively for (day = 0; day < MAX_DAYS; day++) { EXPECT_EQ( - SW_All.Weather.allHist[yearIndex]->cloudcov_daily[day], + SW_Run.Weather.allHist[yearIndex]->cloudcov_daily[day], cloudCovTestVal ); EXPECT_EQ( - SW_All.Weather.allHist[yearIndex]->actualVaporPressure[day], + SW_Run.Weather.allHist[yearIndex]->actualVaporPressure[day], actVapPressTestVal ); EXPECT_EQ( - SW_All.Weather.allHist[yearIndex]->windspeed_daily[day], + SW_Run.Weather.allHist[yearIndex]->windspeed_daily[day], windSpeedTestVal ); } @@ -1217,20 +1217,20 @@ TEST_F(WeatherFixtureTest, WeatherDailyInputWrongColumnNumberDeathTest) { /* Not the same number of flags as columns */ // Run weather functions and expect an failure (error) - SW_WTH_read(&SW_All.Weather, &SW_All.Sky, &SW_All.Model, &LogInfo); + SW_WTH_read(&SW_Run.Weather, &SW_Run.Sky, &SW_Run.Model, &LogInfo); sw_fail_on_error(&LogInfo); // exit test program if unexpected error // Set SW_WEATHER's n_input_forcings to a number that is // not the columns being read in - SW_All.Weather.n_input_forcings = 0; + SW_Run.Weather.n_input_forcings = 0; _read_weather_hist( year, - SW_All.Weather.allHist[0], - SW_All.Weather.name_prefix, - SW_All.Weather.n_input_forcings, - SW_All.Weather.dailyInputIndices, - SW_All.Weather.dailyInputFlags, + SW_Run.Weather.allHist[0], + SW_Run.Weather.name_prefix, + SW_Run.Weather.n_input_forcings, + SW_Run.Weather.dailyInputIndices, + SW_Run.Weather.dailyInputFlags, &LogInfo ); // expect error: don't exit test program via `sw_fail_on_error(&LogInfo)` @@ -1245,13 +1245,13 @@ TEST_F(WeatherFixtureTest, WeatherDailyInputBadTemperatureDeathTest) { // Edit SW_WEATHER_HIST values from their original value - SW_WTH_read(&SW_All.Weather, &SW_All.Sky, &SW_All.Model, &LogInfo); + SW_WTH_read(&SW_Run.Weather, &SW_Run.Sky, &SW_Run.Model, &LogInfo); sw_fail_on_error(&LogInfo); // exit test program if unexpected error // Make temperature unreasonable (not within [-100, 100]) - SW_All.Weather.allHist[0]->temp_max[0] = -102.; + SW_Run.Weather.allHist[0]->temp_max[0] = -102.; - checkAllWeather(&SW_All.Weather, &LogInfo); + checkAllWeather(&SW_Run.Weather, &LogInfo); // expect error: don't exit test program via `sw_fail_on_error(&LogInfo)` // Detect failure by error message @@ -1269,13 +1269,13 @@ TEST_F(WeatherFixtureTest, WeatherDailyInputBadPrecipitationDeathTest) { // Edit SW_WEATHER_HIST values from their original value - SW_WTH_read(&SW_All.Weather, &SW_All.Sky, &SW_All.Model, &LogInfo); + SW_WTH_read(&SW_Run.Weather, &SW_Run.Sky, &SW_Run.Model, &LogInfo); sw_fail_on_error(&LogInfo); // exit test program if unexpected error // Make precipitation unresonable (< 0) - SW_All.Weather.allHist[0]->ppt[0] = -1.; + SW_Run.Weather.allHist[0]->ppt[0] = -1.; - checkAllWeather(&SW_All.Weather, &LogInfo); + checkAllWeather(&SW_Run.Weather, &LogInfo); // expect error: don't exit test program via `sw_fail_on_error(&LogInfo)` // Detect failure by error message @@ -1290,13 +1290,13 @@ TEST_F(WeatherFixtureTest, WeatherDailyInputBadHumidityDeathTest) { // Edit SW_WEATHER_HIST values from their original value - SW_WTH_read(&SW_All.Weather, &SW_All.Sky, &SW_All.Model, &LogInfo); + SW_WTH_read(&SW_Run.Weather, &SW_Run.Sky, &SW_Run.Model, &LogInfo); sw_fail_on_error(&LogInfo); // exit test program if unexpected error // Make relative humidity unreasonable (< 0%) - SW_All.Weather.allHist[0]->r_humidity_daily[0] = -.1252; + SW_Run.Weather.allHist[0]->r_humidity_daily[0] = -.1252; - checkAllWeather(&SW_All.Weather, &LogInfo); + checkAllWeather(&SW_Run.Weather, &LogInfo); // expect error: don't exit test program via `sw_fail_on_error(&LogInfo)` // Detect failure by error message diff --git a/tests/gtests/test_WaterBalance.cc b/tests/gtests/test_WaterBalance.cc index a3d28b79f..1db149c2e 100644 --- a/tests/gtests/test_WaterBalance.cc +++ b/tests/gtests/test_WaterBalance.cc @@ -30,14 +30,14 @@ TEST_F(WaterBalanceFixtureTest, WaterBalanceExample1) { int i; // Run the simulation - SW_CTL_main(&SW_All, &SW_Domain.OutDom, &LogInfo); + SW_CTL_main(&SW_Run, &SW_Domain.OutDom, &LogInfo); sw_fail_on_error(&LogInfo); // exit test program if unexpected error // Collect and output from daily checks for (i = 0; i < N_WBCHECKS; i++) { - EXPECT_EQ(0, SW_All.SoilWat.wbError[i]) + EXPECT_EQ(0, SW_Run.SoilWat.wbError[i]) << "Water balance error in test " << i << ": " - << (char *) SW_All.SoilWat.wbErrorNames[i]; + << (char *) SW_Run.SoilWat.wbErrorNames[i]; } } @@ -45,17 +45,17 @@ TEST_F(WaterBalanceFixtureTest, WaterBalanceWithSoilTemperature) { int i; // Turn on soil temperature simulations - SW_All.Site.use_soil_temp = swTRUE; + SW_Run.Site.use_soil_temp = swTRUE; // Run the simulation - SW_CTL_main(&SW_All, &SW_Domain.OutDom, &LogInfo); + SW_CTL_main(&SW_Run, &SW_Domain.OutDom, &LogInfo); sw_fail_on_error(&LogInfo); // exit test program if unexpected error // Collect and output from daily checks for (i = 0; i < N_WBCHECKS; i++) { - EXPECT_EQ(0, SW_All.SoilWat.wbError[i]) + EXPECT_EQ(0, SW_Run.SoilWat.wbError[i]) << "Water balance error in test " << i << ": " - << (char *) SW_All.SoilWat.wbErrorNames[i]; + << (char *) SW_Run.SoilWat.wbErrorNames[i]; } } @@ -63,19 +63,19 @@ TEST_F(WaterBalanceFixtureTest, WaterBalanceWithPondedWaterRunonRunoff) { int i; // Turn on impermeability of first soil layer, runon, and runoff - SW_All.Site.impermeability[0] = 0.95; - SW_All.Site.percentRunoff = 0.5; - SW_All.Site.percentRunon = 1.25; + SW_Run.Site.impermeability[0] = 0.95; + SW_Run.Site.percentRunoff = 0.5; + SW_Run.Site.percentRunon = 1.25; // Run the simulation - SW_CTL_main(&SW_All, &SW_Domain.OutDom, &LogInfo); + SW_CTL_main(&SW_Run, &SW_Domain.OutDom, &LogInfo); sw_fail_on_error(&LogInfo); // exit test program if unexpected error // Collect and output from daily checks for (i = 0; i < N_WBCHECKS; i++) { - EXPECT_EQ(0, SW_All.SoilWat.wbError[i]) + EXPECT_EQ(0, SW_Run.SoilWat.wbError[i]) << "Water balance error in test " << i << ": " - << (char *) SW_All.SoilWat.wbErrorNames[i]; + << (char *) SW_Run.SoilWat.wbErrorNames[i]; } } @@ -83,44 +83,44 @@ TEST_F(WaterBalanceFixtureTest, WaterBalanceWithWeatherGeneratorOnly) { int i; // Turn on Markov weather generator (and turn off use of historical weather) - SW_All.Weather.generateWeatherMethod = 2; - SW_All.Weather.use_weathergenerator_only = swTRUE; + SW_Run.Weather.generateWeatherMethod = 2; + SW_Run.Weather.use_weathergenerator_only = swTRUE; // Read Markov weather generator input files (they are not normally read) SW_MKV_setup( - &SW_All.Markov, - SW_All.Weather.rng_seed, - SW_All.Weather.generateWeatherMethod, + &SW_Run.Markov, + SW_Run.Weather.rng_seed, + SW_Run.Weather.generateWeatherMethod, SW_Domain.PathInfo.InFiles, &LogInfo ); sw_fail_on_error(&LogInfo); // exit test program if unexpected error // Point to nonexisting weather data - strcpy(SW_All.Weather.name_prefix, "Input/data_weather_nonexisting/weath"); + strcpy(SW_Run.Weather.name_prefix, "Input/data_weather_nonexisting/weath"); // Prepare weather data - SW_WTH_read(&SW_All.Weather, &SW_All.Sky, &SW_All.Model, &LogInfo); + SW_WTH_read(&SW_Run.Weather, &SW_Run.Sky, &SW_Run.Model, &LogInfo); sw_fail_on_error(&LogInfo); // exit test program if unexpected error SW_WTH_finalize_all_weather( - &SW_All.Markov, - &SW_All.Weather, - SW_All.Model.cum_monthdays, - SW_All.Model.days_in_month, + &SW_Run.Markov, + &SW_Run.Weather, + SW_Run.Model.cum_monthdays, + SW_Run.Model.days_in_month, &LogInfo ); sw_fail_on_error(&LogInfo); // exit test program if unexpected error // Run the simulation - SW_CTL_main(&SW_All, &SW_Domain.OutDom, &LogInfo); + SW_CTL_main(&SW_Run, &SW_Domain.OutDom, &LogInfo); sw_fail_on_error(&LogInfo); // exit test program if unexpected error // Collect and output from daily checks for (i = 0; i < N_WBCHECKS; i++) { - EXPECT_EQ(0, SW_All.SoilWat.wbError[i]) + EXPECT_EQ(0, SW_Run.SoilWat.wbError[i]) << "Water balance error in test " << i << ": " - << (char *) SW_All.SoilWat.wbErrorNames[i]; + << (char *) SW_Run.SoilWat.wbErrorNames[i]; } } @@ -131,43 +131,43 @@ TEST_F( int i; // Turn on Markov weather generator - SW_All.Weather.generateWeatherMethod = 2; + SW_Run.Weather.generateWeatherMethod = 2; // Point to partial weather data - strcpy(SW_All.Weather.name_prefix, "Input/data_weather_missing/weath"); + strcpy(SW_Run.Weather.name_prefix, "Input/data_weather_missing/weath"); // Read Markov weather generator input files (they are not normally read) SW_MKV_setup( - &SW_All.Markov, - SW_All.Weather.rng_seed, - SW_All.Weather.generateWeatherMethod, + &SW_Run.Markov, + SW_Run.Weather.rng_seed, + SW_Run.Weather.generateWeatherMethod, SW_Domain.PathInfo.InFiles, &LogInfo ); sw_fail_on_error(&LogInfo); // exit test program if unexpected error // Prepare weather data - SW_WTH_read(&SW_All.Weather, &SW_All.Sky, &SW_All.Model, &LogInfo); + SW_WTH_read(&SW_Run.Weather, &SW_Run.Sky, &SW_Run.Model, &LogInfo); sw_fail_on_error(&LogInfo); // exit test program if unexpected error SW_WTH_finalize_all_weather( - &SW_All.Markov, - &SW_All.Weather, - SW_All.Model.cum_monthdays, - SW_All.Model.days_in_month, + &SW_Run.Markov, + &SW_Run.Weather, + SW_Run.Model.cum_monthdays, + SW_Run.Model.days_in_month, &LogInfo ); sw_fail_on_error(&LogInfo); // exit test program if unexpected error // Run the simulation - SW_CTL_main(&SW_All, &SW_Domain.OutDom, &LogInfo); + SW_CTL_main(&SW_Run, &SW_Domain.OutDom, &LogInfo); sw_fail_on_error(&LogInfo); // exit test program if unexpected error // Collect and output from daily checks for (i = 0; i < N_WBCHECKS; i++) { - EXPECT_EQ(0, SW_All.SoilWat.wbError[i]) + EXPECT_EQ(0, SW_Run.SoilWat.wbError[i]) << "Water balance error in test " << i << ": " - << (char *) SW_All.SoilWat.wbErrorNames[i]; + << (char *) SW_Run.SoilWat.wbErrorNames[i]; } } @@ -176,23 +176,23 @@ TEST_F(WaterBalanceFixtureTest, WaterBalanceWithHighGravelVolume) { LyrIndex s; // Set high gravel volume in all soil layers - ForEachSoilLayer(s, SW_All.Site.n_layers) { - SW_All.Site.fractionVolBulk_gravel[s] = 0.99; + ForEachSoilLayer(s, SW_Run.Site.n_layers) { + SW_Run.Site.fractionVolBulk_gravel[s] = 0.99; } // Re-calculate soils - SW_SIT_init_run(&SW_All.VegProd, &SW_All.Site, &LogInfo); + SW_SIT_init_run(&SW_Run.VegProd, &SW_Run.Site, &LogInfo); sw_fail_on_error(&LogInfo); // exit test program if unexpected error // Run the simulation - SW_CTL_main(&SW_All, &SW_Domain.OutDom, &LogInfo); + SW_CTL_main(&SW_Run, &SW_Domain.OutDom, &LogInfo); sw_fail_on_error(&LogInfo); // exit test program if unexpected error // Collect and output from daily checks for (i = 0; i < N_WBCHECKS; i++) { - EXPECT_EQ(0, SW_All.SoilWat.wbError[i]) + EXPECT_EQ(0, SW_Run.SoilWat.wbError[i]) << "Water balance error in test " << i << ": " - << (char *) SW_All.SoilWat.wbErrorNames[i]; + << (char *) SW_Run.SoilWat.wbErrorNames[i]; } } @@ -200,21 +200,21 @@ TEST_F(WaterBalanceFixtureTest, WaterBalanceWithOneSoilLayer) { int i; // Setup one soil layer - create_test_soillayers(1, &SW_All.VegProd, &SW_All.Site, &LogInfo); + create_test_soillayers(1, &SW_Run.VegProd, &SW_Run.Site, &LogInfo); sw_fail_on_error(&LogInfo); // exit test program if unexpected error // Initialize `swcBulk` based on new soil layers - SW_SWC_init_run(&SW_All.SoilWat, &SW_All.Site, &SW_All.Weather.temp_snow); + SW_SWC_init_run(&SW_Run.SoilWat, &SW_Run.Site, &SW_Run.Weather.temp_snow); // Run the simulation - SW_CTL_main(&SW_All, &SW_Domain.OutDom, &LogInfo); + SW_CTL_main(&SW_Run, &SW_Domain.OutDom, &LogInfo); sw_fail_on_error(&LogInfo); // exit test program if unexpected error // Collect and output from daily checks for (i = 0; i < N_WBCHECKS; i++) { - EXPECT_EQ(0, SW_All.SoilWat.wbError[i]) + EXPECT_EQ(0, SW_Run.SoilWat.wbError[i]) << "Water balance error in test " << i << ": " - << (char *) SW_All.SoilWat.wbErrorNames[i]; + << (char *) SW_Run.SoilWat.wbErrorNames[i]; } } @@ -222,21 +222,21 @@ TEST_F(WaterBalanceFixtureTest, WaterBalanceWithMaxSoilLayers) { int i; // Setup maximum number of soil layers - create_test_soillayers(MAX_LAYERS, &SW_All.VegProd, &SW_All.Site, &LogInfo); + create_test_soillayers(MAX_LAYERS, &SW_Run.VegProd, &SW_Run.Site, &LogInfo); sw_fail_on_error(&LogInfo); // exit test program if unexpected error // Initialize `swcBulk` based on new soil layers - SW_SWC_init_run(&SW_All.SoilWat, &SW_All.Site, &SW_All.Weather.temp_snow); + SW_SWC_init_run(&SW_Run.SoilWat, &SW_Run.Site, &SW_Run.Weather.temp_snow); // Run the simulation - SW_CTL_main(&SW_All, &SW_Domain.OutDom, &LogInfo); + SW_CTL_main(&SW_Run, &SW_Domain.OutDom, &LogInfo); sw_fail_on_error(&LogInfo); // exit test program if unexpected error // Collect and output from daily checks for (i = 0; i < N_WBCHECKS; i++) { - EXPECT_EQ(0, SW_All.SoilWat.wbError[i]) + EXPECT_EQ(0, SW_Run.SoilWat.wbError[i]) << "Water balance error in test " << i << ": " - << (char *) SW_All.SoilWat.wbErrorNames[i]; + << (char *) SW_Run.SoilWat.wbErrorNames[i]; } } @@ -244,21 +244,21 @@ TEST_F(WaterBalanceFixtureTest, WaterBalanceWithVegetationFromClimate1) { int i; // Select method to estimate vegetation from long-term climate - SW_All.VegProd.veg_method = 1; + SW_Run.VegProd.veg_method = 1; // Re-calculate vegetation - SW_VPD_init_run(&SW_All.VegProd, &SW_All.Weather, &SW_All.Model, &LogInfo); + SW_VPD_init_run(&SW_Run.VegProd, &SW_Run.Weather, &SW_Run.Model, &LogInfo); sw_fail_on_error(&LogInfo); // Run the simulation - SW_CTL_main(&SW_All, &SW_Domain.OutDom, &LogInfo); + SW_CTL_main(&SW_Run, &SW_Domain.OutDom, &LogInfo); sw_fail_on_error(&LogInfo); // exit test program if unexpected error // Collect and output from daily checks for (i = 0; i < N_WBCHECKS; i++) { - EXPECT_EQ(0, SW_All.SoilWat.wbError[i]) + EXPECT_EQ(0, SW_Run.SoilWat.wbError[i]) << "Water balance error in test " << i << ": " - << (char *) SW_All.SoilWat.wbErrorNames[i]; + << (char *) SW_Run.SoilWat.wbErrorNames[i]; } } @@ -266,13 +266,13 @@ TEST_F(WaterBalanceFixtureTest, WaterBalanceWithSWRCvanGenuchten1980) { int i; // Set SWRC and PTF (and SWRC parameter input filename) - strcpy(SW_All.Site.site_swrc_name, (char *) "vanGenuchten1980"); - SW_All.Site.site_swrc_type = - encode_str2swrc(SW_All.Site.site_swrc_name, &LogInfo); + strcpy(SW_Run.Site.site_swrc_name, (char *) "vanGenuchten1980"); + SW_Run.Site.site_swrc_type = + encode_str2swrc(SW_Run.Site.site_swrc_name, &LogInfo); sw_fail_on_error(&LogInfo); // exit test program if unexpected error - strcpy(SW_All.Site.site_ptf_name, (char *) "Rosetta3"); - SW_All.Site.site_ptf_type = encode_str2ptf(SW_All.Site.site_ptf_name); - SW_All.Site.site_has_swrcp = swTRUE; + strcpy(SW_Run.Site.site_ptf_name, (char *) "Rosetta3"); + SW_Run.Site.site_ptf_type = encode_str2ptf(SW_Run.Site.site_ptf_name); + SW_Run.Site.site_has_swrcp = swTRUE; free(SW_Domain.PathInfo.InFiles[eSWRCp]); SW_Domain.PathInfo.InFiles[eSWRCp] = @@ -280,22 +280,22 @@ TEST_F(WaterBalanceFixtureTest, WaterBalanceWithSWRCvanGenuchten1980) { sw_fail_on_error(&LogInfo); // exit test program if unexpected error // Read SWRC parameter input file (which is not read by default) - SW_SWRC_read(&SW_All.Site, SW_Domain.PathInfo.InFiles, &LogInfo); + SW_SWRC_read(&SW_Run.Site, SW_Domain.PathInfo.InFiles, &LogInfo); sw_fail_on_error(&LogInfo); // exit test program if unexpected error // Update soils - SW_SIT_init_run(&SW_All.VegProd, &SW_All.Site, &LogInfo); + SW_SIT_init_run(&SW_Run.VegProd, &SW_Run.Site, &LogInfo); sw_fail_on_error(&LogInfo); // exit test program if unexpected error // Run the simulation - SW_CTL_main(&SW_All, &SW_Domain.OutDom, &LogInfo); + SW_CTL_main(&SW_Run, &SW_Domain.OutDom, &LogInfo); sw_fail_on_error(&LogInfo); // exit test program if unexpected error // Collect and output from daily checks for (i = 0; i < N_WBCHECKS; i++) { - EXPECT_EQ(0, SW_All.SoilWat.wbError[i]) + EXPECT_EQ(0, SW_Run.SoilWat.wbError[i]) << "Water balance error in test " << i << ": " - << (char *) SW_All.SoilWat.wbErrorNames[i]; + << (char *) SW_Run.SoilWat.wbErrorNames[i]; } } @@ -303,13 +303,13 @@ TEST_F(WaterBalanceFixtureTest, WaterBalanceWithSWRCFXW) { int i; // Set SWRC and PTF (and SWRC parameter input filename) - strcpy(SW_All.Site.site_swrc_name, (char *) "FXW"); - SW_All.Site.site_swrc_type = - encode_str2swrc(SW_All.Site.site_swrc_name, &LogInfo); + strcpy(SW_Run.Site.site_swrc_name, (char *) "FXW"); + SW_Run.Site.site_swrc_type = + encode_str2swrc(SW_Run.Site.site_swrc_name, &LogInfo); sw_fail_on_error(&LogInfo); // exit test program if unexpected error - strcpy(SW_All.Site.site_ptf_name, (char *) "neuroFX2021"); - SW_All.Site.site_ptf_type = encode_str2ptf(SW_All.Site.site_ptf_name); - SW_All.Site.site_has_swrcp = swTRUE; + strcpy(SW_Run.Site.site_ptf_name, (char *) "neuroFX2021"); + SW_Run.Site.site_ptf_type = encode_str2ptf(SW_Run.Site.site_ptf_name); + SW_Run.Site.site_has_swrcp = swTRUE; free(SW_Domain.PathInfo.InFiles[eSWRCp]); SW_Domain.PathInfo.InFiles[eSWRCp] = @@ -317,22 +317,22 @@ TEST_F(WaterBalanceFixtureTest, WaterBalanceWithSWRCFXW) { sw_fail_on_error(&LogInfo); // exit test program if unexpected error // Read SWRC parameter input file (which is not read by default) - SW_SWRC_read(&SW_All.Site, SW_Domain.PathInfo.InFiles, &LogInfo); + SW_SWRC_read(&SW_Run.Site, SW_Domain.PathInfo.InFiles, &LogInfo); sw_fail_on_error(&LogInfo); // exit test program if unexpected error // Update soils - SW_SIT_init_run(&SW_All.VegProd, &SW_All.Site, &LogInfo); + SW_SIT_init_run(&SW_Run.VegProd, &SW_Run.Site, &LogInfo); sw_fail_on_error(&LogInfo); // exit test program if unexpected error // Run the simulation - SW_CTL_main(&SW_All, &SW_Domain.OutDom, &LogInfo); + SW_CTL_main(&SW_Run, &SW_Domain.OutDom, &LogInfo); sw_fail_on_error(&LogInfo); // exit test program if unexpected error // Collect and output from daily checks for (i = 0; i < N_WBCHECKS; i++) { - EXPECT_EQ(0, SW_All.SoilWat.wbError[i]) + EXPECT_EQ(0, SW_Run.SoilWat.wbError[i]) << "Water balance error in test " << i << ": " - << (char *) SW_All.SoilWat.wbErrorNames[i]; + << (char *) SW_Run.SoilWat.wbErrorNames[i]; } } @@ -340,47 +340,47 @@ TEST_F(WaterBalanceFixtureTest, WaterBalanceWithDaymet) { int i; // Point to Daymet weather data - strcpy(SW_All.Weather.name_prefix, "Input/data_weather_daymet/weath"); + strcpy(SW_Run.Weather.name_prefix, "Input/data_weather_daymet/weath"); // Adjust simulation years: we have 2 years of Daymet inputs - SW_All.Model.startyr = 1980; - SW_All.Model.endyr = 1981; + SW_Run.Model.startyr = 1980; + SW_Run.Model.endyr = 1981; // Describe daily Daymet inputs - SW_All.Weather.use_cloudCoverMonthly = swFALSE; - SW_All.Weather.use_windSpeedMonthly = swTRUE; - SW_All.Weather.use_humidityMonthly = swFALSE; - - SW_All.Weather.dailyInputIndices[ACTUAL_VP] = 3; - SW_All.Weather.dailyInputIndices[SHORT_WR] = 4; - SW_All.Weather.dailyInputFlags[ACTUAL_VP] = swTRUE; - SW_All.Weather.dailyInputFlags[SHORT_WR] = swTRUE; - SW_All.Weather.n_input_forcings = 5; + SW_Run.Weather.use_cloudCoverMonthly = swFALSE; + SW_Run.Weather.use_windSpeedMonthly = swTRUE; + SW_Run.Weather.use_humidityMonthly = swFALSE; + + SW_Run.Weather.dailyInputIndices[ACTUAL_VP] = 3; + SW_Run.Weather.dailyInputIndices[SHORT_WR] = 4; + SW_Run.Weather.dailyInputFlags[ACTUAL_VP] = swTRUE; + SW_Run.Weather.dailyInputFlags[SHORT_WR] = swTRUE; + SW_Run.Weather.n_input_forcings = 5; // Daymet rsds is flux density over daylight period - SW_All.Weather.desc_rsds = 2; + SW_Run.Weather.desc_rsds = 2; // Prepare weather data - SW_WTH_read(&SW_All.Weather, &SW_All.Sky, &SW_All.Model, &LogInfo); + SW_WTH_read(&SW_Run.Weather, &SW_Run.Sky, &SW_Run.Model, &LogInfo); sw_fail_on_error(&LogInfo); // exit test program if unexpected error SW_WTH_finalize_all_weather( - &SW_All.Markov, - &SW_All.Weather, - SW_All.Model.cum_monthdays, - SW_All.Model.days_in_month, + &SW_Run.Markov, + &SW_Run.Weather, + SW_Run.Model.cum_monthdays, + SW_Run.Model.days_in_month, &LogInfo ); sw_fail_on_error(&LogInfo); // exit test program if unexpected error // Run the simulation - SW_CTL_main(&SW_All, &SW_Domain.OutDom, &LogInfo); + SW_CTL_main(&SW_Run, &SW_Domain.OutDom, &LogInfo); sw_fail_on_error(&LogInfo); // exit test program if unexpected error // Collect and output from daily checks for (i = 0; i < N_WBCHECKS; i++) { - EXPECT_EQ(0, SW_All.SoilWat.wbError[i]) + EXPECT_EQ(0, SW_Run.SoilWat.wbError[i]) << "Water balance error in test " << i << ": " - << (char *) SW_All.SoilWat.wbErrorNames[i]; + << (char *) SW_Run.SoilWat.wbErrorNames[i]; } } @@ -388,50 +388,50 @@ TEST_F(WaterBalanceFixtureTest, WaterBalanceWithGRIDMET) { int i; // Point to gridMET weather data - strcpy(SW_All.Weather.name_prefix, "Input/data_weather_gridmet/weath"); + strcpy(SW_Run.Weather.name_prefix, "Input/data_weather_gridmet/weath"); // Adjust simulation years: we have 2 years of gridMET inputs - SW_All.Model.startyr = 1980; - SW_All.Model.endyr = 1981; + SW_Run.Model.startyr = 1980; + SW_Run.Model.endyr = 1981; // Describe daily gridMET inputs - SW_All.Weather.use_cloudCoverMonthly = swFALSE; - SW_All.Weather.use_windSpeedMonthly = swFALSE; - SW_All.Weather.use_humidityMonthly = swFALSE; - - SW_All.Weather.dailyInputIndices[WIND_SPEED] = 3; - SW_All.Weather.dailyInputIndices[REL_HUMID_MAX] = 4; - SW_All.Weather.dailyInputIndices[REL_HUMID_MIN] = 5; - SW_All.Weather.dailyInputIndices[SHORT_WR] = 6; - SW_All.Weather.dailyInputFlags[REL_HUMID_MAX] = swTRUE; - SW_All.Weather.dailyInputFlags[REL_HUMID_MIN] = swTRUE; - SW_All.Weather.dailyInputFlags[WIND_SPEED] = swTRUE; - SW_All.Weather.dailyInputFlags[SHORT_WR] = swTRUE; - SW_All.Weather.n_input_forcings = 7; - SW_All.Weather.desc_rsds = 1; // gridMET rsds is flux density over 24 hours + SW_Run.Weather.use_cloudCoverMonthly = swFALSE; + SW_Run.Weather.use_windSpeedMonthly = swFALSE; + SW_Run.Weather.use_humidityMonthly = swFALSE; + + SW_Run.Weather.dailyInputIndices[WIND_SPEED] = 3; + SW_Run.Weather.dailyInputIndices[REL_HUMID_MAX] = 4; + SW_Run.Weather.dailyInputIndices[REL_HUMID_MIN] = 5; + SW_Run.Weather.dailyInputIndices[SHORT_WR] = 6; + SW_Run.Weather.dailyInputFlags[REL_HUMID_MAX] = swTRUE; + SW_Run.Weather.dailyInputFlags[REL_HUMID_MIN] = swTRUE; + SW_Run.Weather.dailyInputFlags[WIND_SPEED] = swTRUE; + SW_Run.Weather.dailyInputFlags[SHORT_WR] = swTRUE; + SW_Run.Weather.n_input_forcings = 7; + SW_Run.Weather.desc_rsds = 1; // gridMET rsds is flux density over 24 hours // Prepare weather data - SW_WTH_read(&SW_All.Weather, &SW_All.Sky, &SW_All.Model, &LogInfo); + SW_WTH_read(&SW_Run.Weather, &SW_Run.Sky, &SW_Run.Model, &LogInfo); sw_fail_on_error(&LogInfo); // exit test program if unexpected error SW_WTH_finalize_all_weather( - &SW_All.Markov, - &SW_All.Weather, - SW_All.Model.cum_monthdays, - SW_All.Model.days_in_month, + &SW_Run.Markov, + &SW_Run.Weather, + SW_Run.Model.cum_monthdays, + SW_Run.Model.days_in_month, &LogInfo ); sw_fail_on_error(&LogInfo); // exit test program if unexpected error // Run the simulation - SW_CTL_main(&SW_All, &SW_Domain.OutDom, &LogInfo); + SW_CTL_main(&SW_Run, &SW_Domain.OutDom, &LogInfo); sw_fail_on_error(&LogInfo); // exit test program if unexpected error // Collect and output from daily checks for (i = 0; i < N_WBCHECKS; i++) { - EXPECT_EQ(0, SW_All.SoilWat.wbError[i]) + EXPECT_EQ(0, SW_Run.SoilWat.wbError[i]) << "Water balance error in test " << i << ": " - << (char *) SW_All.SoilWat.wbErrorNames[i]; + << (char *) SW_Run.SoilWat.wbErrorNames[i]; } } @@ -439,52 +439,52 @@ TEST_F(WaterBalanceFixtureTest, WaterBalanceWithMACA) { int i; // Point to MACA weather data - strcpy(SW_All.Weather.name_prefix, "Input/data_weather_maca/weath"); + strcpy(SW_Run.Weather.name_prefix, "Input/data_weather_maca/weath"); // Adjust simulation years: we have 2 years of MACA inputs - SW_All.Model.startyr = 1980; - SW_All.Model.endyr = 1981; + SW_Run.Model.startyr = 1980; + SW_Run.Model.endyr = 1981; // Describe daily MACA inputs - SW_All.Weather.use_cloudCoverMonthly = swFALSE; - SW_All.Weather.use_windSpeedMonthly = swFALSE; - SW_All.Weather.use_humidityMonthly = swFALSE; - - SW_All.Weather.dailyInputIndices[WIND_EAST] = 3; - SW_All.Weather.dailyInputIndices[WIND_NORTH] = 4; - SW_All.Weather.dailyInputIndices[REL_HUMID_MAX] = 5; - SW_All.Weather.dailyInputIndices[REL_HUMID_MIN] = 6; - SW_All.Weather.dailyInputIndices[SHORT_WR] = 7; - SW_All.Weather.dailyInputFlags[WIND_EAST] = swTRUE; - SW_All.Weather.dailyInputFlags[WIND_NORTH] = swTRUE; - SW_All.Weather.dailyInputFlags[REL_HUMID_MAX] = swTRUE; - SW_All.Weather.dailyInputFlags[REL_HUMID_MIN] = swTRUE; - SW_All.Weather.dailyInputFlags[SHORT_WR] = swTRUE; - SW_All.Weather.n_input_forcings = 8; - SW_All.Weather.desc_rsds = 1; // MACA rsds is flux density over 24 hours + SW_Run.Weather.use_cloudCoverMonthly = swFALSE; + SW_Run.Weather.use_windSpeedMonthly = swFALSE; + SW_Run.Weather.use_humidityMonthly = swFALSE; + + SW_Run.Weather.dailyInputIndices[WIND_EAST] = 3; + SW_Run.Weather.dailyInputIndices[WIND_NORTH] = 4; + SW_Run.Weather.dailyInputIndices[REL_HUMID_MAX] = 5; + SW_Run.Weather.dailyInputIndices[REL_HUMID_MIN] = 6; + SW_Run.Weather.dailyInputIndices[SHORT_WR] = 7; + SW_Run.Weather.dailyInputFlags[WIND_EAST] = swTRUE; + SW_Run.Weather.dailyInputFlags[WIND_NORTH] = swTRUE; + SW_Run.Weather.dailyInputFlags[REL_HUMID_MAX] = swTRUE; + SW_Run.Weather.dailyInputFlags[REL_HUMID_MIN] = swTRUE; + SW_Run.Weather.dailyInputFlags[SHORT_WR] = swTRUE; + SW_Run.Weather.n_input_forcings = 8; + SW_Run.Weather.desc_rsds = 1; // MACA rsds is flux density over 24 hours // Prepare weather data - SW_WTH_read(&SW_All.Weather, &SW_All.Sky, &SW_All.Model, &LogInfo); + SW_WTH_read(&SW_Run.Weather, &SW_Run.Sky, &SW_Run.Model, &LogInfo); sw_fail_on_error(&LogInfo); // exit test program if unexpected error SW_WTH_finalize_all_weather( - &SW_All.Markov, - &SW_All.Weather, - SW_All.Model.cum_monthdays, - SW_All.Model.days_in_month, + &SW_Run.Markov, + &SW_Run.Weather, + SW_Run.Model.cum_monthdays, + SW_Run.Model.days_in_month, &LogInfo ); sw_fail_on_error(&LogInfo); // exit test program if unexpected error // Run the simulation - SW_CTL_main(&SW_All, &SW_Domain.OutDom, &LogInfo); + SW_CTL_main(&SW_Run, &SW_Domain.OutDom, &LogInfo); sw_fail_on_error(&LogInfo); // exit test program if unexpected error // Collect and output from daily checks for (i = 0; i < N_WBCHECKS; i++) { - EXPECT_EQ(0, SW_All.SoilWat.wbError[i]) + EXPECT_EQ(0, SW_Run.SoilWat.wbError[i]) << "Water balance error in test " << i << ": " - << (char *) SW_All.SoilWat.wbErrorNames[i]; + << (char *) SW_Run.SoilWat.wbErrorNames[i]; } } @@ -492,24 +492,24 @@ TEST_F(WaterBalanceFixtureTest, WaterBalanceWithSpinup) { int i; // Turn on spinup simulation - SW_All.Model.SW_SpinUp.spinup = swTRUE; + SW_Run.Model.SW_SpinUp.spinup = swTRUE; // Set spinup variables - SW_All.Model.SW_SpinUp.mode = 1; - SW_All.Model.SW_SpinUp.duration = 5; - SW_All.Model.SW_SpinUp.scope = 8; + SW_Run.Model.SW_SpinUp.mode = 1; + SW_Run.Model.SW_SpinUp.duration = 5; + SW_Run.Model.SW_SpinUp.scope = 8; // Run the spinup & deactivate - SW_CTL_run_spinup(&SW_All, &SW_Domain.OutDom, &LogInfo); + SW_CTL_run_spinup(&SW_Run, &SW_Domain.OutDom, &LogInfo); // Run the simulation - SW_CTL_main(&SW_All, &SW_Domain.OutDom, &LogInfo); + SW_CTL_main(&SW_Run, &SW_Domain.OutDom, &LogInfo); sw_fail_on_error(&LogInfo); // exit test program if unexpected error // Collect and output from daily checks for (i = 0; i < N_WBCHECKS; i++) { - EXPECT_EQ(0, SW_All.SoilWat.wbError[i]) + EXPECT_EQ(0, SW_Run.SoilWat.wbError[i]) << "Water balance error in test " << i << ": " - << (char *) SW_All.SoilWat.wbErrorNames[i]; + << (char *) SW_Run.SoilWat.wbErrorNames[i]; } } } // namespace From e60d67ef8fef7a496f81a859b5d6fe67e4ff1ba3 Mon Sep 17 00:00:00 2001 From: Nicholas Persley Date: Fri, 5 Jul 2024 13:06:43 -0400 Subject: [PATCH 09/19] Rename `SW_OUT_deepCopy()` to `SW_FILESTATUS_deepCopy()` --- include/SW_Output.h | 2 +- src/SW_Control.c | 4 +++- src/SW_Output.c | 2 +- 3 files changed, 5 insertions(+), 3 deletions(-) diff --git a/include/SW_Output.h b/include/SW_Output.h index 3b22b97e0..1995f6def 100644 --- a/include/SW_Output.h +++ b/include/SW_Output.h @@ -281,7 +281,7 @@ void SW_OUT_set_SXWrequests( #endif #if defined(SWNETCDF) -void SW_OUT_deepCopy( +void SW_FILESTATUS_deepCopy( SW_FILE_STATUS *dest_files, SW_FILE_STATUS *source_files, SW_OUT_DOM *OutDom, diff --git a/src/SW_Control.c b/src/SW_Control.c index dd5b942bf..c084da0ac 100644 --- a/src/SW_Control.c +++ b/src/SW_Control.c @@ -215,7 +215,9 @@ void SW_RUN_deepCopy( } #ifdef SWNETCDF - SW_OUT_deepCopy(&dest->FileStatus, &source->FileStatus, OutDom, LogInfo); + SW_FILESTATUS_deepCopy( + &dest->FileStatus, &source->FileStatus, OutDom, LogInfo + ); SW_OUT_construct_outarray(OutDom, &dest->OutRun, LogInfo); #else (void) OutDom; diff --git a/src/SW_Output.c b/src/SW_Output.c index a4bae7dce..f41cbcd59 100644 --- a/src/SW_Output.c +++ b/src/SW_Output.c @@ -3007,7 +3007,7 @@ netCDF output files stored in SW_FILE_STATUS information that do not change throughout simulation runs @param[out] LogInfo Holds information on warnings and errors */ -void SW_OUT_deepCopy( +void SW_FILESTATUS_deepCopy( SW_FILE_STATUS *dest_files, SW_FILE_STATUS *source_files, SW_OUT_DOM *OutDom, From bc5ffac20bb2be6f46a2801c67944c23025ec014 Mon Sep 17 00:00:00 2001 From: Nicholas Persley Date: Fri, 5 Jul 2024 16:12:35 -0400 Subject: [PATCH 10/19] Simplify interfaces of `SW_OUT_set_SXWrequests` & `_set_SXWrequests_helper` - Remove the explicit mention of `timeSteps_SXW` in the interfaces of `SW_OUT_set_SXWrequests()` and `_set_SXWrequests_helper()` --- include/SW_Output.h | 6 +----- src/SW_Output.c | 21 +++------------------ 2 files changed, 4 insertions(+), 23 deletions(-) diff --git a/include/SW_Output.h b/include/SW_Output.h index 1995f6def..596cdf47b 100644 --- a/include/SW_Output.h +++ b/include/SW_Output.h @@ -273,11 +273,7 @@ Bool has_key_soillayers(OutKey k); #ifdef STEPWAT Bool has_OutPeriod_inUse2(OutPeriod pd, OutKey k, SW_OUT_DOM *OutDom); -void SW_OUT_set_SXWrequests( - SW_OUT_DOM *OutDom, - OutPeriod timeSteps_SXW[][SW_OUTNPERIODS], - LOG_INFO *LogInfo -); +void SW_OUT_set_SXWrequests(SW_OUT_DOM *OutDom, LOG_INFO *LogInfo); #endif #if defined(SWNETCDF) diff --git a/src/SW_Output.c b/src/SW_Output.c index f41cbcd59..f157df238 100644 --- a/src/SW_Output.c +++ b/src/SW_Output.c @@ -180,7 +180,6 @@ static void _set_SXWrequests_helper( OutPeriod pd, OutSum aggfun, const char *str, - OutPeriod timeSteps_SXW[][SW_OUTNPERIODS], LOG_INFO *LogInfo ); #endif @@ -1055,7 +1054,6 @@ static void _set_SXWrequests_helper( OutPeriod pd, OutSum aggfun, const char *str, - OutPeriod timeSteps_SXW[][SW_OUTNPERIODS], LOG_INFO *LogInfo ) { Bool warn = OutDom->use[k]; @@ -1173,24 +1171,14 @@ Currently implemented: `used_OUTNPERIODS`, and adjusts variables `use`, `sumtype` (with a warning), `first_orig`, and `last_orig` of `SW_Output`. */ -void SW_OUT_set_SXWrequests( - SW_OUT_DOM *OutDom, - OutPeriod timeSteps_SXW[][SW_OUTNPERIODS], - LOG_INFO *LogInfo -) { +void SW_OUT_set_SXWrequests(SW_OUT_DOM *OutDom, LOG_INFO *LogInfo) { // Update `used_OUTNPERIODS`: // SXW uses up to 2 time periods for the same output key: monthly and yearly OutDom->used_OUTNPERIODS = MAX(2, OutDom->used_OUTNPERIODS); // STEPWAT2 requires monthly summed transpiration _set_SXWrequests_helper( - OutDom, - eSW_Transp, - eSW_Month, - eSW_Sum, - "monthly transpiration", - timeSteps_SXW, - LogInfo + OutDom, eSW_Transp, eSW_Month, eSW_Sum, "monthly transpiration", LogInfo ); if (LogInfo->stopRun) { return; // Exit function prematurely due to error @@ -1203,7 +1191,6 @@ void SW_OUT_set_SXWrequests( eSW_Month, eSW_Avg, "monthly bulk soil water content", - timeSteps_SXW, LogInfo ); if (LogInfo->stopRun) { @@ -1217,7 +1204,6 @@ void SW_OUT_set_SXWrequests( eSW_Month, eSW_Avg, "annual and monthly air temperature", - timeSteps_SXW, LogInfo ); if (LogInfo->stopRun) { @@ -1232,7 +1218,6 @@ void SW_OUT_set_SXWrequests( eSW_Month, eSW_Sum, "annual and monthly precipitation", - timeSteps_SXW, LogInfo ); if (LogInfo->stopRun) { @@ -1242,7 +1227,7 @@ void SW_OUT_set_SXWrequests( // STEPWAT2 requires annual sum of AET _set_SXWrequests_helper( - OutDom, eSW_AET, eSW_Year, eSW_Sum, "annual AET", timeSteps_SXW, LogInfo + OutDom, eSW_AET, eSW_Year, eSW_Sum, "annual AET", LogInfo ); if (LogInfo->stopRun) { return; // Exit function prematurely due to error From 5cfebb3ca0ca832e8e23721a2510a69a08a1690b Mon Sep 17 00:00:00 2001 From: Nicholas Persley Date: Fri, 5 Jul 2024 16:30:11 -0400 Subject: [PATCH 11/19] New function `SW_OUTDOM_construct()` - Move the initialization of output information explicitly to the the function like * Output function pointers * Output use, key, etc. - Call `SW_OUTDOM_construct()` from `SW_OUT_construct()` - Move key2obj back into SW_Output.c --- include/SW_Output.h | 2 + src/SW_Domain.c | 559 +------------------------------------------ src/SW_Output.c | 572 +++++++++++++++++++++++++++++++++++++++++++- 3 files changed, 572 insertions(+), 561 deletions(-) diff --git a/include/SW_Output.h b/include/SW_Output.h index 596cdf47b..94a24c47b 100644 --- a/include/SW_Output.h +++ b/include/SW_Output.h @@ -158,6 +158,8 @@ extern char const *styp2longstr[]; void SW_OUT_init_ptrs(SW_OUT_RUN *OutRun); +void SW_OUTDOM_construct(SW_OUT_DOM *OutDom); + void SW_OUT_construct( Bool make_soil[], Bool make_regular[], diff --git a/src/SW_Domain.c b/src/SW_Domain.c index e2d7b3cc3..189c86aea 100644 --- a/src/SW_Domain.c +++ b/src/SW_Domain.c @@ -23,48 +23,6 @@ #include "include/rands.h" // for RandSeed #endif -/* converts an enum output key (OutKey type) to a module */ -/* or object type. see SW_Output.h for OutKey order. */ -/* MUST be SW_OUTNKEYS of these */ -ObjType key2obj[] = { - // weather/atmospheric quantities: - eWTH, - eWTH, - eWTH, - eWTH, - eWTH, - // soil related water quantities: - eSWC, - eSWC, - eSWC, - eSWC, - eSWC, - eSWC, - eSWC, - eSWC, - eSWC, - eSWC, - eSWC, - eSWC, - eSWC, - eSWC, - eSWC, - eSWC, - eSWC, - eSWC, - eSWC, - eSWC, - eSWC, - eSWC, - eSWC, - // vegetation quantities: - eVES, - eVES, - // vegetation other: - eVPD, - eVPD -}; - /* =================================================== */ /* Local Defines */ @@ -169,11 +127,6 @@ void SW_DOM_CreateProgress(SW_DOMAIN *SW_Domain, LOG_INFO *LogInfo) { */ void SW_DOM_construct(unsigned long rng_seed, SW_DOMAIN *SW_Domain) { - IntUS k; - OutPeriod p; - - SW_OUT_DOM *OutDom = &SW_Domain->OutDom; - /* Set seed of `spinup_rng` - SOILWAT2: set seed here - STEPWAT2: `main()` uses `Globals.randseed` to (re-)set for each iteration @@ -194,517 +147,7 @@ void SW_DOM_construct(unsigned long rng_seed, SW_DOMAIN *SW_Domain) { sizeof(&SW_Domain->depthsAllSoilLayers[0]) * MAX_LAYERS ); -#if defined(SOILWAT) - OutDom->print_SW_Output = swTRUE; - OutDom->print_IterationSummary = swFALSE; -#elif defined(STEPWAT) - OutDom->print_SW_Output = (Bool) OutDom->storeAllIterations; -// `print_IterationSummary` is set by STEPWAT2's `main` function -#endif - -#if defined(SW_OUTARRAY) - ForEachOutPeriod(p) { OutDom->nrow_OUT[p] = 0; } -#endif - - /* attach the printing functions for each output - * quantity to the appropriate element in the - * output structure. Using a loop makes it convenient - * to simply add a line as new quantities are - * implemented and leave the default case for every - * thing else. - */ - ForEachOutKey(k) { - ForEachOutPeriod(p) { - OutDom->timeSteps[k][p] = eSW_NoTime; - -#ifdef STEPWAT - OutDom->timeSteps_SXW[k][p] = eSW_NoTime; -#endif - } - - // default values for `SW_Output`: - OutDom->use[k] = swFALSE; - OutDom->mykey[k] = (OutKey) k; - OutDom->myobj[k] = key2obj[k]; - OutDom->sumtype[k] = eSW_Off; - OutDom->has_sl[k] = has_key_soillayers((OutKey) k); - OutDom->first_orig[k] = 1; - OutDom->last_orig[k] = 366; - -#if defined(SWNETCDF) - OutDom->outputVarInfo[k] = NULL; - OutDom->reqOutputVars[k] = NULL; - OutDom->units_sw[k] = NULL; - OutDom->uconv[k] = NULL; -#endif - - // assign `get_XXX` functions - switch (k) { - case eSW_Temp: -#if defined(SW_OUTTEXT) - OutDom->pfunc_text[k] = - (void (*)(OutPeriod, SW_RUN *)) get_temp_text; -#endif -#if defined(RSOILWAT) || defined(SWNETCDF) - OutDom->pfunc_mem[k] = - (void (*)(OutPeriod, SW_RUN *, SW_OUT_DOM *)) get_temp_mem; -#elif defined(STEPWAT) - OutDom->pfunc_agg[k] = - (void (*)(OutPeriod, SW_RUN *, SW_OUT_DOM *)) get_temp_agg; - OutDom->pfunc_SXW[k] = - (void (*)(OutPeriod, SW_RUN *, SW_OUT_DOM *)) get_temp_SXW; -#endif - break; - - case eSW_Precip: -#if defined(SW_OUTTEXT) - OutDom->pfunc_text[k] = - (void (*)(OutPeriod, SW_RUN *)) get_precip_text; -#endif -#if defined(RSOILWAT) || defined(SWNETCDF) - OutDom->pfunc_mem[k] = - (void (*)(OutPeriod, SW_RUN *, SW_OUT_DOM *)) get_precip_mem; -#elif defined(STEPWAT) - OutDom->pfunc_agg[k] = - (void (*)(OutPeriod, SW_RUN *, SW_OUT_DOM *)) get_precip_agg; - OutDom->pfunc_SXW[k] = - (void (*)(OutPeriod, SW_RUN *, SW_OUT_DOM *)) get_precip_SXW; -#endif - break; - - case eSW_VWCBulk: -#if defined(SW_OUTTEXT) - OutDom->pfunc_text[k] = - (void (*)(OutPeriod, SW_RUN *)) get_vwcBulk_text; -#endif -#if defined(RSOILWAT) || defined(SWNETCDF) - OutDom->pfunc_mem[k] = - (void (*)(OutPeriod, SW_RUN *, SW_OUT_DOM *)) get_vwcBulk_mem; -#elif defined(STEPWAT) - OutDom->pfunc_agg[k] = - (void (*)(OutPeriod, SW_RUN *, SW_OUT_DOM *)) get_vwcBulk_agg; - OutDom->pfunc_SXW[k] = - (void (*)(OutPeriod, SW_RUN *, SW_OUT_DOM *)) get_none_outarray; -#endif - break; - - case eSW_VWCMatric: -#if defined(SW_OUTTEXT) - OutDom->pfunc_text[k] = - (void (*)(OutPeriod, SW_RUN *)) get_vwcMatric_text; -#endif -#if defined(RSOILWAT) || defined(SWNETCDF) - OutDom->pfunc_mem[k] = - (void (*)(OutPeriod, SW_RUN *, SW_OUT_DOM *)) get_vwcMatric_mem; -#elif defined(STEPWAT) - OutDom->pfunc_agg[k] = - (void (*)(OutPeriod, SW_RUN *, SW_OUT_DOM *)) get_vwcMatric_agg; - OutDom->pfunc_SXW[k] = - (void (*)(OutPeriod, SW_RUN *, SW_OUT_DOM *)) get_none_outarray; -#endif - break; - - case eSW_SWCBulk: -#if defined(SW_OUTTEXT) - OutDom->pfunc_text[k] = - (void (*)(OutPeriod, SW_RUN *)) get_swcBulk_text; -#endif -#if defined(RSOILWAT) || defined(SWNETCDF) - OutDom->pfunc_mem[k] = - (void (*)(OutPeriod, SW_RUN *, SW_OUT_DOM *)) get_swcBulk_mem; -#elif defined(STEPWAT) - OutDom->pfunc_agg[k] = - (void (*)(OutPeriod, SW_RUN *, SW_OUT_DOM *)) get_swcBulk_agg; - OutDom->pfunc_SXW[k] = - (void (*)(OutPeriod, SW_RUN *, SW_OUT_DOM *)) get_swcBulk_SXW; -#endif - break; - - case eSW_SWPMatric: -#if defined(SW_OUTTEXT) - OutDom->pfunc_text[k] = - (void (*)(OutPeriod, SW_RUN *)) get_swpMatric_text; -#endif -#if defined(RSOILWAT) || defined(SWNETCDF) - OutDom->pfunc_mem[k] = - (void (*)(OutPeriod, SW_RUN *, SW_OUT_DOM *)) get_swpMatric_mem; -#elif defined(STEPWAT) - OutDom->pfunc_agg[k] = - (void (*)(OutPeriod, SW_RUN *, SW_OUT_DOM *)) get_swpMatric_agg; - OutDom->pfunc_SXW[k] = - (void (*)(OutPeriod, SW_RUN *, SW_OUT_DOM *)) get_none_outarray; -#endif - break; - - case eSW_SWABulk: -#if defined(SW_OUTTEXT) - OutDom->pfunc_text[k] = - (void (*)(OutPeriod, SW_RUN *)) get_swaBulk_text; -#endif -#if defined(RSOILWAT) || defined(SWNETCDF) - OutDom->pfunc_mem[k] = - (void (*)(OutPeriod, SW_RUN *, SW_OUT_DOM *)) get_swaBulk_mem; -#elif defined(STEPWAT) - OutDom->pfunc_agg[k] = - (void (*)(OutPeriod, SW_RUN *, SW_OUT_DOM *)) get_swaBulk_agg; - OutDom->pfunc_SXW[k] = - (void (*)(OutPeriod, SW_RUN *, SW_OUT_DOM *)) get_none_outarray; -#endif - break; - - case eSW_SWAMatric: -#if defined(SW_OUTTEXT) - OutDom->pfunc_text[k] = - (void (*)(OutPeriod, SW_RUN *)) get_swaMatric_text; -#endif -#if defined(RSOILWAT) || defined(SWNETCDF) - OutDom->pfunc_mem[k] = - (void (*)(OutPeriod, SW_RUN *, SW_OUT_DOM *)) get_swaMatric_mem; -#elif defined(STEPWAT) - OutDom->pfunc_agg[k] = - (void (*)(OutPeriod, SW_RUN *, SW_OUT_DOM *)) get_swaMatric_agg; - OutDom->pfunc_SXW[k] = - (void (*)(OutPeriod, SW_RUN *, SW_OUT_DOM *)) get_none_outarray; -#endif - break; - - case eSW_SWA: -#if defined(SW_OUTTEXT) - OutDom->pfunc_text[k] = - (void (*)(OutPeriod, SW_RUN *)) get_swa_text; -#endif -#if defined(RSOILWAT) || defined(SWNETCDF) - OutDom->pfunc_mem[k] = - (void (*)(OutPeriod, SW_RUN *, SW_OUT_DOM *)) get_swa_mem; -#elif defined(STEPWAT) - OutDom->pfunc_agg[k] = - (void (*)(OutPeriod, SW_RUN *, SW_OUT_DOM *)) get_swa_agg; - OutDom->pfunc_SXW[k] = - (void (*)(OutPeriod, SW_RUN *, SW_OUT_DOM *)) get_none_outarray; -#endif - break; - - case eSW_SurfaceWater: -#if defined(SW_OUTTEXT) - OutDom->pfunc_text[k] = - (void (*)(OutPeriod, SW_RUN *)) get_surfaceWater_text; -#endif -#if defined(RSOILWAT) || defined(SWNETCDF) - OutDom->pfunc_mem[k] = (void (*)(OutPeriod, SW_RUN *, SW_OUT_DOM *) - ) get_surfaceWater_mem; -#elif defined(STEPWAT) - OutDom->pfunc_agg[k] = (void (*)(OutPeriod, SW_RUN *, SW_OUT_DOM *) - ) get_surfaceWater_agg; - OutDom->pfunc_SXW[k] = - (void (*)(OutPeriod, SW_RUN *, SW_OUT_DOM *)) get_none_outarray; -#endif - break; - - case eSW_Runoff: -#if defined(SW_OUTTEXT) - OutDom->pfunc_text[k] = - (void (*)(OutPeriod, SW_RUN *)) get_runoffrunon_text; -#endif -#if defined(RSOILWAT) || defined(SWNETCDF) - OutDom->pfunc_mem[k] = (void (*)(OutPeriod, SW_RUN *, SW_OUT_DOM *) - ) get_runoffrunon_mem; -#elif defined(STEPWAT) - OutDom->pfunc_agg[k] = (void (*)(OutPeriod, SW_RUN *, SW_OUT_DOM *) - ) get_runoffrunon_agg; - OutDom->pfunc_SXW[k] = - (void (*)(OutPeriod, SW_RUN *, SW_OUT_DOM *)) get_none_outarray; -#endif - break; - - case eSW_Transp: -#if defined(SW_OUTTEXT) - OutDom->pfunc_text[k] = - (void (*)(OutPeriod, SW_RUN *)) get_transp_text; -#endif -#if defined(RSOILWAT) || defined(SWNETCDF) - OutDom->pfunc_mem[k] = - (void (*)(OutPeriod, SW_RUN *, SW_OUT_DOM *)) get_transp_mem; -#elif defined(STEPWAT) - OutDom->pfunc_agg[k] = - (void (*)(OutPeriod, SW_RUN *, SW_OUT_DOM *)) get_transp_agg; - OutDom->pfunc_SXW[k] = - (void (*)(OutPeriod, SW_RUN *, SW_OUT_DOM *)) get_transp_SXW; -#endif - break; - - case eSW_EvapSoil: -#if defined(SW_OUTTEXT) - OutDom->pfunc_text[k] = - (void (*)(OutPeriod, SW_RUN *)) get_evapSoil_text; -#endif -#if defined(RSOILWAT) || defined(SWNETCDF) - OutDom->pfunc_mem[k] = - (void (*)(OutPeriod, SW_RUN *, SW_OUT_DOM *)) get_evapSoil_mem; -#elif defined(STEPWAT) - OutDom->pfunc_agg[k] = - (void (*)(OutPeriod, SW_RUN *, SW_OUT_DOM *)) get_evapSoil_agg; - OutDom->pfunc_SXW[k] = - (void (*)(OutPeriod, SW_RUN *, SW_OUT_DOM *)) get_none_outarray; -#endif - break; - - case eSW_EvapSurface: -#if defined(SW_OUTTEXT) - OutDom->pfunc_text[k] = - (void (*)(OutPeriod, SW_RUN *)) get_evapSurface_text; -#endif -#if defined(RSOILWAT) || defined(SWNETCDF) - OutDom->pfunc_mem[k] = (void (*)(OutPeriod, SW_RUN *, SW_OUT_DOM *) - ) get_evapSurface_mem; -#elif defined(STEPWAT) - OutDom->pfunc_agg[k] = (void (*)(OutPeriod, SW_RUN *, SW_OUT_DOM *) - ) get_evapSurface_agg; - OutDom->pfunc_SXW[k] = - (void (*)(OutPeriod, SW_RUN *, SW_OUT_DOM *)) get_none_outarray; -#endif - break; - - case eSW_Interception: -#if defined(SW_OUTTEXT) - OutDom->pfunc_text[k] = - (void (*)(OutPeriod, SW_RUN *)) get_interception_text; -#endif -#if defined(RSOILWAT) || defined(SWNETCDF) - OutDom->pfunc_mem[k] = (void (*)(OutPeriod, SW_RUN *, SW_OUT_DOM *) - ) get_interception_mem; -#elif defined(STEPWAT) - OutDom->pfunc_agg[k] = (void (*)(OutPeriod, SW_RUN *, SW_OUT_DOM *) - ) get_interception_agg; - OutDom->pfunc_SXW[k] = - (void (*)(OutPeriod, SW_RUN *, SW_OUT_DOM *)) get_none_outarray; -#endif - break; - - case eSW_SoilInf: -#if defined(SW_OUTTEXT) - OutDom->pfunc_text[k] = - (void (*)(OutPeriod, SW_RUN *)) get_soilinf_text; -#endif -#if defined(RSOILWAT) || defined(SWNETCDF) - OutDom->pfunc_mem[k] = - (void (*)(OutPeriod, SW_RUN *, SW_OUT_DOM *)) get_soilinf_mem; -#elif defined(STEPWAT) - OutDom->pfunc_agg[k] = - (void (*)(OutPeriod, SW_RUN *, SW_OUT_DOM *)) get_soilinf_agg; - OutDom->pfunc_SXW[k] = - (void (*)(OutPeriod, SW_RUN *, SW_OUT_DOM *)) get_none_outarray; -#endif - break; - - case eSW_LyrDrain: -#if defined(SW_OUTTEXT) - OutDom->pfunc_text[k] = - (void (*)(OutPeriod, SW_RUN *)) get_lyrdrain_text; -#endif -#if defined(RSOILWAT) || defined(SWNETCDF) - OutDom->pfunc_mem[k] = - (void (*)(OutPeriod, SW_RUN *, SW_OUT_DOM *)) get_lyrdrain_mem; -#elif defined(STEPWAT) - OutDom->pfunc_agg[k] = - (void (*)(OutPeriod, SW_RUN *, SW_OUT_DOM *)) get_lyrdrain_agg; - OutDom->pfunc_SXW[k] = - (void (*)(OutPeriod, SW_RUN *, SW_OUT_DOM *)) get_none_outarray; -#endif - break; - - case eSW_HydRed: -#if defined(SW_OUTTEXT) - OutDom->pfunc_text[k] = - (void (*)(OutPeriod, SW_RUN *)) get_hydred_text; -#endif -#if defined(RSOILWAT) || defined(SWNETCDF) - OutDom->pfunc_mem[k] = - (void (*)(OutPeriod, SW_RUN *, SW_OUT_DOM *)) get_hydred_mem; -#elif defined(STEPWAT) - OutDom->pfunc_agg[k] = - (void (*)(OutPeriod, SW_RUN *, SW_OUT_DOM *)) get_hydred_agg; - OutDom->pfunc_SXW[k] = - (void (*)(OutPeriod, SW_RUN *, SW_OUT_DOM *)) get_none_outarray; -#endif - break; - - case eSW_AET: -#if defined(SW_OUTTEXT) - OutDom->pfunc_text[k] = - (void (*)(OutPeriod, SW_RUN *)) get_aet_text; -#endif -#if defined(RSOILWAT) || defined(SWNETCDF) - OutDom->pfunc_mem[k] = - (void (*)(OutPeriod, SW_RUN *, SW_OUT_DOM *)) get_aet_mem; -#elif defined(STEPWAT) - OutDom->pfunc_agg[k] = - (void (*)(OutPeriod, SW_RUN *, SW_OUT_DOM *)) get_aet_agg; - OutDom->pfunc_SXW[k] = - (void (*)(OutPeriod, SW_RUN *, SW_OUT_DOM *)) get_aet_SXW; -#endif - break; - - case eSW_PET: -#if defined(SW_OUTTEXT) - OutDom->pfunc_text[k] = - (void (*)(OutPeriod, SW_RUN *)) get_pet_text; -#endif -#if defined(RSOILWAT) || defined(SWNETCDF) - OutDom->pfunc_mem[k] = - (void (*)(OutPeriod, SW_RUN *, SW_OUT_DOM *)) get_pet_mem; -#elif defined(STEPWAT) - OutDom->pfunc_agg[k] = - (void (*)(OutPeriod, SW_RUN *, SW_OUT_DOM *)) get_pet_agg; - OutDom->pfunc_SXW[k] = - (void (*)(OutPeriod, SW_RUN *, SW_OUT_DOM *)) get_none_outarray; -#endif - break; - - case eSW_WetDays: -#if defined(SW_OUTTEXT) - OutDom->pfunc_text[k] = - (void (*)(OutPeriod, SW_RUN *)) get_wetdays_text; -#endif -#if defined(RSOILWAT) || defined(SWNETCDF) - OutDom->pfunc_mem[k] = - (void (*)(OutPeriod, SW_RUN *, SW_OUT_DOM *)) get_wetdays_mem; -#elif defined(STEPWAT) - OutDom->pfunc_agg[k] = - (void (*)(OutPeriod, SW_RUN *, SW_OUT_DOM *)) get_wetdays_agg; - OutDom->pfunc_SXW[k] = - (void (*)(OutPeriod, SW_RUN *, SW_OUT_DOM *)) get_none_outarray; -#endif - break; - - case eSW_SnowPack: -#if defined(SW_OUTTEXT) - OutDom->pfunc_text[k] = - (void (*)(OutPeriod, SW_RUN *)) get_snowpack_text; -#endif -#if defined(RSOILWAT) || defined(SWNETCDF) - OutDom->pfunc_mem[k] = - (void (*)(OutPeriod, SW_RUN *, SW_OUT_DOM *)) get_snowpack_mem; -#elif defined(STEPWAT) - OutDom->pfunc_agg[k] = - (void (*)(OutPeriod, SW_RUN *, SW_OUT_DOM *)) get_snowpack_agg; - OutDom->pfunc_SXW[k] = - (void (*)(OutPeriod, SW_RUN *, SW_OUT_DOM *)) get_none_outarray; -#endif - break; - - case eSW_DeepSWC: -#if defined(SW_OUTTEXT) - OutDom->pfunc_text[k] = - (void (*)(OutPeriod, SW_RUN *)) get_deepswc_text; -#endif -#if defined(RSOILWAT) || defined(SWNETCDF) - OutDom->pfunc_mem[k] = - (void (*)(OutPeriod, SW_RUN *, SW_OUT_DOM *)) get_deepswc_mem; -#elif defined(STEPWAT) - OutDom->pfunc_agg[k] = - (void (*)(OutPeriod, SW_RUN *, SW_OUT_DOM *)) get_deepswc_agg; - OutDom->pfunc_SXW[k] = - (void (*)(OutPeriod, SW_RUN *, SW_OUT_DOM *)) get_none_outarray; -#endif - break; - - case eSW_SoilTemp: -#if defined(SW_OUTTEXT) - OutDom->pfunc_text[k] = - (void (*)(OutPeriod, SW_RUN *)) get_soiltemp_text; -#endif -#if defined(RSOILWAT) || defined(SWNETCDF) - OutDom->pfunc_mem[k] = - (void (*)(OutPeriod, SW_RUN *, SW_OUT_DOM *)) get_soiltemp_mem; -#elif defined(STEPWAT) - OutDom->pfunc_agg[k] = - (void (*)(OutPeriod, SW_RUN *, SW_OUT_DOM *)) get_soiltemp_agg; - OutDom->pfunc_SXW[k] = - (void (*)(OutPeriod, SW_RUN *, SW_OUT_DOM *)) get_none_outarray; -#endif - break; - - case eSW_Frozen: -#if defined(SW_OUTTEXT) - OutDom->pfunc_text[k] = - (void (*)(OutPeriod, SW_RUN *)) get_frozen_text; -#endif -#if defined(RSOILWAT) || defined(SWNETCDF) - OutDom->pfunc_mem[k] = - (void (*)(OutPeriod, SW_RUN *, SW_OUT_DOM *)) get_frozen_mem; -#elif defined(STEPWAT) - OutDom->pfunc_agg[k] = - (void (*)(OutPeriod, SW_RUN *, SW_OUT_DOM *)) get_frozen_agg; - OutDom->pfunc_SXW[k] = - (void (*)(OutPeriod, SW_RUN *, SW_OUT_DOM *)) get_none_outarray; -#endif - break; - - case eSW_Estab: -#if defined(SW_OUTTEXT) - OutDom->pfunc_text[k] = - (void (*)(OutPeriod, SW_RUN *)) get_estab_text; -#endif -#if defined(RSOILWAT) || defined(SWNETCDF) - OutDom->pfunc_mem[k] = - (void (*)(OutPeriod, SW_RUN *, SW_OUT_DOM *)) get_estab_mem; -#elif defined(STEPWAT) - OutDom->pfunc_agg[k] = - (void (*)(OutPeriod, SW_RUN *, SW_OUT_DOM *)) get_estab_agg; - OutDom->pfunc_SXW[k] = - (void (*)(OutPeriod, SW_RUN *, SW_OUT_DOM *)) get_none_outarray; -#endif - break; - - case eSW_CO2Effects: -#if defined(SW_OUTTEXT) - OutDom->pfunc_text[k] = - (void (*)(OutPeriod, SW_RUN *)) get_co2effects_text; -#endif -#if defined(RSOILWAT) || defined(SWNETCDF) - OutDom->pfunc_mem[k] = (void (*)(OutPeriod, SW_RUN *, SW_OUT_DOM *) - ) get_co2effects_mem; -#elif defined(STEPWAT) - OutDom->pfunc_agg[k] = (void (*)(OutPeriod, SW_RUN *, SW_OUT_DOM *) - ) get_co2effects_agg; - OutDom->pfunc_SXW[k] = - (void (*)(OutPeriod, SW_RUN *, SW_OUT_DOM *)) get_none_outarray; -#endif - break; - - case eSW_Biomass: -#if defined(SW_OUTTEXT) - OutDom->pfunc_text[k] = - (void (*)(OutPeriod, SW_RUN *)) get_biomass_text; -#endif -#if defined(RSOILWAT) || defined(SWNETCDF) - OutDom->pfunc_mem[k] = - (void (*)(OutPeriod, SW_RUN *, SW_OUT_DOM *)) get_biomass_mem; -#elif defined(STEPWAT) - OutDom->pfunc_agg[k] = - (void (*)(OutPeriod, SW_RUN *, SW_OUT_DOM *)) get_biomass_agg; - OutDom->pfunc_SXW[k] = - (void (*)(OutPeriod, SW_RUN *, SW_OUT_DOM *)) get_none_outarray; -#endif - break; - - default: -#if defined(SW_OUTTEXT) - OutDom->pfunc_text[k] = - (void (*)(OutPeriod, SW_RUN *)) get_none_text; -#endif -#if defined(RSOILWAT) || defined(SWNETCDF) - OutDom->pfunc_mem[k] = - (void (*)(OutPeriod, SW_RUN *, SW_OUT_DOM *)) get_none_outarray; -#elif defined(STEPWAT) - OutDom->pfunc_agg[k] = - (void (*)(OutPeriod, SW_RUN *, SW_OUT_DOM *)) get_none_outarray; - OutDom->pfunc_SXW[k] = - (void (*)(OutPeriod, SW_RUN *, SW_OUT_DOM *)) get_none_outarray; -#endif - break; - } - } // end of loop across output keys + SW_OUTDOM_construct(&SW_Domain->OutDom); } /** diff --git a/src/SW_Output.c b/src/SW_Output.c index f157df238..76f49ec8f 100644 --- a/src/SW_Output.c +++ b/src/SW_Output.c @@ -65,6 +65,48 @@ See the \ref out_algo "output algorithm documentation" for details. and defined/implemented in 'SW_Output_get_functions.c" */ +/* converts an enum output key (OutKey type) to a module */ +/* or object type. see SW_Output.h for OutKey order. */ +/* MUST be SW_OUTNKEYS of these */ +ObjType key2obj[] = { + // weather/atmospheric quantities: + eWTH, + eWTH, + eWTH, + eWTH, + eWTH, + // soil related water quantities: + eSWC, + eSWC, + eSWC, + eSWC, + eSWC, + eSWC, + eSWC, + eSWC, + eSWC, + eSWC, + eSWC, + eSWC, + eSWC, + eSWC, + eSWC, + eSWC, + eSWC, + eSWC, + eSWC, + eSWC, + eSWC, + eSWC, + eSWC, + // vegetation quantities: + eVES, + eVES, + // vegetation other: + eVPD, + eVPD +}; + /* =================================================== */ /* Global Variables */ @@ -1058,7 +1100,7 @@ static void _set_SXWrequests_helper( ) { Bool warn = OutDom->use[k]; - timeSteps_SXW[k][0] = pd; + OutDom->timeSteps_SXW[k][0] = pd; OutDom->use[k] = swTRUE; OutDom->first_orig[k] = 1; OutDom->last_orig[k] = 366; @@ -1209,7 +1251,7 @@ void SW_OUT_set_SXWrequests(SW_OUT_DOM *OutDom, LOG_INFO *LogInfo) { if (LogInfo->stopRun) { return; // Exit function prematurely due to error } - timeSteps_SXW[eSW_Temp][1] = eSW_Year; + OutDom->timeSteps_SXW[eSW_Temp][1] = eSW_Year; // STEPWAT2 requires annual and monthly precipitation sum _set_SXWrequests_helper( @@ -1223,7 +1265,7 @@ void SW_OUT_set_SXWrequests(SW_OUT_DOM *OutDom, LOG_INFO *LogInfo) { if (LogInfo->stopRun) { return; // Exit function prematurely due to error } - timeSteps_SXW[eSW_Precip][1] = eSW_Year; + OutDom->timeSteps_SXW[eSW_Precip][1] = eSW_Year; // STEPWAT2 requires annual sum of AET _set_SXWrequests_helper( @@ -1258,6 +1300,530 @@ void SW_OUT_init_ptrs(SW_OUT_RUN *OutRun) { #endif } +/** + * @brief Initialize output values that live in the domain-level + * (contained in SW_OUT_DOM) + * + * @param[out] OutDom OutDom Struct of type SW_OUT_DOM that holds output + * information that do not change throughout simulation runs + */ +void SW_OUTDOM_construct(SW_OUT_DOM *OutDom) { + + IntUS k; + OutPeriod p; + +#if defined(SOILWAT) + OutDom->print_SW_Output = swTRUE; +#elif defined(STEPWAT) + OutDom->print_SW_Output = (Bool) OutDom->storeAllIterations; +// `print_IterationSummary` is set by STEPWAT2's `main` function +#endif + +#if defined(SW_OUTARRAY) + ForEachOutPeriod(p) { OutDom->nrow_OUT[p] = 0; } +#endif + + /* attach the printing functions for each output + * quantity to the appropriate element in the + * output structure. Using a loop makes it convenient + * to simply add a line as new quantities are + * implemented and leave the default case for every + * thing else. + */ + ForEachOutKey(k) { + ForEachOutPeriod(p) { + OutDom->timeSteps[k][p] = eSW_NoTime; + +#ifdef STEPWAT + OutDom->timeSteps_SXW[k][p] = eSW_NoTime; +#endif + } + + // default values for `SW_Output`: + OutDom->use[k] = swFALSE; + OutDom->mykey[k] = (OutKey) k; + OutDom->myobj[k] = key2obj[k]; + OutDom->sumtype[k] = eSW_Off; + OutDom->has_sl[k] = has_key_soillayers((OutKey) k); + OutDom->first_orig[k] = 1; + OutDom->last_orig[k] = 366; + +#if defined(SWNETCDF) + OutDom->outputVarInfo[k] = NULL; + OutDom->reqOutputVars[k] = NULL; + OutDom->units_sw[k] = NULL; + OutDom->uconv[k] = NULL; +#endif + + // assign `get_XXX` functions + switch (k) { + case eSW_Temp: +#if defined(SW_OUTTEXT) + OutDom->pfunc_text[k] = + (void (*)(OutPeriod, SW_RUN *)) get_temp_text; +#endif +#if defined(RSOILWAT) || defined(SWNETCDF) + OutDom->pfunc_mem[k] = + (void (*)(OutPeriod, SW_RUN *, SW_OUT_DOM *)) get_temp_mem; +#elif defined(STEPWAT) + OutDom->pfunc_agg[k] = + (void (*)(OutPeriod, SW_RUN *, SW_OUT_DOM *)) get_temp_agg; + OutDom->pfunc_SXW[k] = + (void (*)(OutPeriod, SW_RUN *, SW_OUT_DOM *)) get_temp_SXW; +#endif + break; + + case eSW_Precip: +#if defined(SW_OUTTEXT) + OutDom->pfunc_text[k] = + (void (*)(OutPeriod, SW_RUN *)) get_precip_text; +#endif +#if defined(RSOILWAT) || defined(SWNETCDF) + OutDom->pfunc_mem[k] = + (void (*)(OutPeriod, SW_RUN *, SW_OUT_DOM *)) get_precip_mem; +#elif defined(STEPWAT) + OutDom->pfunc_agg[k] = + (void (*)(OutPeriod, SW_RUN *, SW_OUT_DOM *)) get_precip_agg; + OutDom->pfunc_SXW[k] = + (void (*)(OutPeriod, SW_RUN *, SW_OUT_DOM *)) get_precip_SXW; +#endif + break; + + case eSW_VWCBulk: +#if defined(SW_OUTTEXT) + OutDom->pfunc_text[k] = + (void (*)(OutPeriod, SW_RUN *)) get_vwcBulk_text; +#endif +#if defined(RSOILWAT) || defined(SWNETCDF) + OutDom->pfunc_mem[k] = + (void (*)(OutPeriod, SW_RUN *, SW_OUT_DOM *)) get_vwcBulk_mem; +#elif defined(STEPWAT) + OutDom->pfunc_agg[k] = + (void (*)(OutPeriod, SW_RUN *, SW_OUT_DOM *)) get_vwcBulk_agg; + OutDom->pfunc_SXW[k] = + (void (*)(OutPeriod, SW_RUN *, SW_OUT_DOM *)) get_none_outarray; +#endif + break; + + case eSW_VWCMatric: +#if defined(SW_OUTTEXT) + OutDom->pfunc_text[k] = + (void (*)(OutPeriod, SW_RUN *)) get_vwcMatric_text; +#endif +#if defined(RSOILWAT) || defined(SWNETCDF) + OutDom->pfunc_mem[k] = + (void (*)(OutPeriod, SW_RUN *, SW_OUT_DOM *)) get_vwcMatric_mem; +#elif defined(STEPWAT) + OutDom->pfunc_agg[k] = + (void (*)(OutPeriod, SW_RUN *, SW_OUT_DOM *)) get_vwcMatric_agg; + OutDom->pfunc_SXW[k] = + (void (*)(OutPeriod, SW_RUN *, SW_OUT_DOM *)) get_none_outarray; +#endif + break; + + case eSW_SWCBulk: +#if defined(SW_OUTTEXT) + OutDom->pfunc_text[k] = + (void (*)(OutPeriod, SW_RUN *)) get_swcBulk_text; +#endif +#if defined(RSOILWAT) || defined(SWNETCDF) + OutDom->pfunc_mem[k] = + (void (*)(OutPeriod, SW_RUN *, SW_OUT_DOM *)) get_swcBulk_mem; +#elif defined(STEPWAT) + OutDom->pfunc_agg[k] = + (void (*)(OutPeriod, SW_RUN *, SW_OUT_DOM *)) get_swcBulk_agg; + OutDom->pfunc_SXW[k] = + (void (*)(OutPeriod, SW_RUN *, SW_OUT_DOM *)) get_swcBulk_SXW; +#endif + break; + + case eSW_SWPMatric: +#if defined(SW_OUTTEXT) + OutDom->pfunc_text[k] = + (void (*)(OutPeriod, SW_RUN *)) get_swpMatric_text; +#endif +#if defined(RSOILWAT) || defined(SWNETCDF) + OutDom->pfunc_mem[k] = + (void (*)(OutPeriod, SW_RUN *, SW_OUT_DOM *)) get_swpMatric_mem; +#elif defined(STEPWAT) + OutDom->pfunc_agg[k] = + (void (*)(OutPeriod, SW_RUN *, SW_OUT_DOM *)) get_swpMatric_agg; + OutDom->pfunc_SXW[k] = + (void (*)(OutPeriod, SW_RUN *, SW_OUT_DOM *)) get_none_outarray; +#endif + break; + + case eSW_SWABulk: +#if defined(SW_OUTTEXT) + OutDom->pfunc_text[k] = + (void (*)(OutPeriod, SW_RUN *)) get_swaBulk_text; +#endif +#if defined(RSOILWAT) || defined(SWNETCDF) + OutDom->pfunc_mem[k] = + (void (*)(OutPeriod, SW_RUN *, SW_OUT_DOM *)) get_swaBulk_mem; +#elif defined(STEPWAT) + OutDom->pfunc_agg[k] = + (void (*)(OutPeriod, SW_RUN *, SW_OUT_DOM *)) get_swaBulk_agg; + OutDom->pfunc_SXW[k] = + (void (*)(OutPeriod, SW_RUN *, SW_OUT_DOM *)) get_none_outarray; +#endif + break; + + case eSW_SWAMatric: +#if defined(SW_OUTTEXT) + OutDom->pfunc_text[k] = + (void (*)(OutPeriod, SW_RUN *)) get_swaMatric_text; +#endif +#if defined(RSOILWAT) || defined(SWNETCDF) + OutDom->pfunc_mem[k] = + (void (*)(OutPeriod, SW_RUN *, SW_OUT_DOM *)) get_swaMatric_mem; +#elif defined(STEPWAT) + OutDom->pfunc_agg[k] = + (void (*)(OutPeriod, SW_RUN *, SW_OUT_DOM *)) get_swaMatric_agg; + OutDom->pfunc_SXW[k] = + (void (*)(OutPeriod, SW_RUN *, SW_OUT_DOM *)) get_none_outarray; +#endif + break; + + case eSW_SWA: +#if defined(SW_OUTTEXT) + OutDom->pfunc_text[k] = + (void (*)(OutPeriod, SW_RUN *)) get_swa_text; +#endif +#if defined(RSOILWAT) || defined(SWNETCDF) + OutDom->pfunc_mem[k] = + (void (*)(OutPeriod, SW_RUN *, SW_OUT_DOM *)) get_swa_mem; +#elif defined(STEPWAT) + OutDom->pfunc_agg[k] = + (void (*)(OutPeriod, SW_RUN *, SW_OUT_DOM *)) get_swa_agg; + OutDom->pfunc_SXW[k] = + (void (*)(OutPeriod, SW_RUN *, SW_OUT_DOM *)) get_none_outarray; +#endif + break; + + case eSW_SurfaceWater: +#if defined(SW_OUTTEXT) + OutDom->pfunc_text[k] = + (void (*)(OutPeriod, SW_RUN *)) get_surfaceWater_text; +#endif +#if defined(RSOILWAT) || defined(SWNETCDF) + OutDom->pfunc_mem[k] = (void (*)(OutPeriod, SW_RUN *, SW_OUT_DOM *) + ) get_surfaceWater_mem; +#elif defined(STEPWAT) + OutDom->pfunc_agg[k] = (void (*)(OutPeriod, SW_RUN *, SW_OUT_DOM *) + ) get_surfaceWater_agg; + OutDom->pfunc_SXW[k] = + (void (*)(OutPeriod, SW_RUN *, SW_OUT_DOM *)) get_none_outarray; +#endif + break; + + case eSW_Runoff: +#if defined(SW_OUTTEXT) + OutDom->pfunc_text[k] = + (void (*)(OutPeriod, SW_RUN *)) get_runoffrunon_text; +#endif +#if defined(RSOILWAT) || defined(SWNETCDF) + OutDom->pfunc_mem[k] = (void (*)(OutPeriod, SW_RUN *, SW_OUT_DOM *) + ) get_runoffrunon_mem; +#elif defined(STEPWAT) + OutDom->pfunc_agg[k] = (void (*)(OutPeriod, SW_RUN *, SW_OUT_DOM *) + ) get_runoffrunon_agg; + OutDom->pfunc_SXW[k] = + (void (*)(OutPeriod, SW_RUN *, SW_OUT_DOM *)) get_none_outarray; +#endif + break; + + case eSW_Transp: +#if defined(SW_OUTTEXT) + OutDom->pfunc_text[k] = + (void (*)(OutPeriod, SW_RUN *)) get_transp_text; +#endif +#if defined(RSOILWAT) || defined(SWNETCDF) + OutDom->pfunc_mem[k] = + (void (*)(OutPeriod, SW_RUN *, SW_OUT_DOM *)) get_transp_mem; +#elif defined(STEPWAT) + OutDom->pfunc_agg[k] = + (void (*)(OutPeriod, SW_RUN *, SW_OUT_DOM *)) get_transp_agg; + OutDom->pfunc_SXW[k] = + (void (*)(OutPeriod, SW_RUN *, SW_OUT_DOM *)) get_transp_SXW; +#endif + break; + + case eSW_EvapSoil: +#if defined(SW_OUTTEXT) + OutDom->pfunc_text[k] = + (void (*)(OutPeriod, SW_RUN *)) get_evapSoil_text; +#endif +#if defined(RSOILWAT) || defined(SWNETCDF) + OutDom->pfunc_mem[k] = + (void (*)(OutPeriod, SW_RUN *, SW_OUT_DOM *)) get_evapSoil_mem; +#elif defined(STEPWAT) + OutDom->pfunc_agg[k] = + (void (*)(OutPeriod, SW_RUN *, SW_OUT_DOM *)) get_evapSoil_agg; + OutDom->pfunc_SXW[k] = + (void (*)(OutPeriod, SW_RUN *, SW_OUT_DOM *)) get_none_outarray; +#endif + break; + + case eSW_EvapSurface: +#if defined(SW_OUTTEXT) + OutDom->pfunc_text[k] = + (void (*)(OutPeriod, SW_RUN *)) get_evapSurface_text; +#endif +#if defined(RSOILWAT) || defined(SWNETCDF) + OutDom->pfunc_mem[k] = (void (*)(OutPeriod, SW_RUN *, SW_OUT_DOM *) + ) get_evapSurface_mem; +#elif defined(STEPWAT) + OutDom->pfunc_agg[k] = (void (*)(OutPeriod, SW_RUN *, SW_OUT_DOM *) + ) get_evapSurface_agg; + OutDom->pfunc_SXW[k] = + (void (*)(OutPeriod, SW_RUN *, SW_OUT_DOM *)) get_none_outarray; +#endif + break; + + case eSW_Interception: +#if defined(SW_OUTTEXT) + OutDom->pfunc_text[k] = + (void (*)(OutPeriod, SW_RUN *)) get_interception_text; +#endif +#if defined(RSOILWAT) || defined(SWNETCDF) + OutDom->pfunc_mem[k] = (void (*)(OutPeriod, SW_RUN *, SW_OUT_DOM *) + ) get_interception_mem; +#elif defined(STEPWAT) + OutDom->pfunc_agg[k] = (void (*)(OutPeriod, SW_RUN *, SW_OUT_DOM *) + ) get_interception_agg; + OutDom->pfunc_SXW[k] = + (void (*)(OutPeriod, SW_RUN *, SW_OUT_DOM *)) get_none_outarray; +#endif + break; + + case eSW_SoilInf: +#if defined(SW_OUTTEXT) + OutDom->pfunc_text[k] = + (void (*)(OutPeriod, SW_RUN *)) get_soilinf_text; +#endif +#if defined(RSOILWAT) || defined(SWNETCDF) + OutDom->pfunc_mem[k] = + (void (*)(OutPeriod, SW_RUN *, SW_OUT_DOM *)) get_soilinf_mem; +#elif defined(STEPWAT) + OutDom->pfunc_agg[k] = + (void (*)(OutPeriod, SW_RUN *, SW_OUT_DOM *)) get_soilinf_agg; + OutDom->pfunc_SXW[k] = + (void (*)(OutPeriod, SW_RUN *, SW_OUT_DOM *)) get_none_outarray; +#endif + break; + + case eSW_LyrDrain: +#if defined(SW_OUTTEXT) + OutDom->pfunc_text[k] = + (void (*)(OutPeriod, SW_RUN *)) get_lyrdrain_text; +#endif +#if defined(RSOILWAT) || defined(SWNETCDF) + OutDom->pfunc_mem[k] = + (void (*)(OutPeriod, SW_RUN *, SW_OUT_DOM *)) get_lyrdrain_mem; +#elif defined(STEPWAT) + OutDom->pfunc_agg[k] = + (void (*)(OutPeriod, SW_RUN *, SW_OUT_DOM *)) get_lyrdrain_agg; + OutDom->pfunc_SXW[k] = + (void (*)(OutPeriod, SW_RUN *, SW_OUT_DOM *)) get_none_outarray; +#endif + break; + + case eSW_HydRed: +#if defined(SW_OUTTEXT) + OutDom->pfunc_text[k] = + (void (*)(OutPeriod, SW_RUN *)) get_hydred_text; +#endif +#if defined(RSOILWAT) || defined(SWNETCDF) + OutDom->pfunc_mem[k] = + (void (*)(OutPeriod, SW_RUN *, SW_OUT_DOM *)) get_hydred_mem; +#elif defined(STEPWAT) + OutDom->pfunc_agg[k] = + (void (*)(OutPeriod, SW_RUN *, SW_OUT_DOM *)) get_hydred_agg; + OutDom->pfunc_SXW[k] = + (void (*)(OutPeriod, SW_RUN *, SW_OUT_DOM *)) get_none_outarray; +#endif + break; + + case eSW_AET: +#if defined(SW_OUTTEXT) + OutDom->pfunc_text[k] = + (void (*)(OutPeriod, SW_RUN *)) get_aet_text; +#endif +#if defined(RSOILWAT) || defined(SWNETCDF) + OutDom->pfunc_mem[k] = + (void (*)(OutPeriod, SW_RUN *, SW_OUT_DOM *)) get_aet_mem; +#elif defined(STEPWAT) + OutDom->pfunc_agg[k] = + (void (*)(OutPeriod, SW_RUN *, SW_OUT_DOM *)) get_aet_agg; + OutDom->pfunc_SXW[k] = + (void (*)(OutPeriod, SW_RUN *, SW_OUT_DOM *)) get_aet_SXW; +#endif + break; + + case eSW_PET: +#if defined(SW_OUTTEXT) + OutDom->pfunc_text[k] = + (void (*)(OutPeriod, SW_RUN *)) get_pet_text; +#endif +#if defined(RSOILWAT) || defined(SWNETCDF) + OutDom->pfunc_mem[k] = + (void (*)(OutPeriod, SW_RUN *, SW_OUT_DOM *)) get_pet_mem; +#elif defined(STEPWAT) + OutDom->pfunc_agg[k] = + (void (*)(OutPeriod, SW_RUN *, SW_OUT_DOM *)) get_pet_agg; + OutDom->pfunc_SXW[k] = + (void (*)(OutPeriod, SW_RUN *, SW_OUT_DOM *)) get_none_outarray; +#endif + break; + + case eSW_WetDays: +#if defined(SW_OUTTEXT) + OutDom->pfunc_text[k] = + (void (*)(OutPeriod, SW_RUN *)) get_wetdays_text; +#endif +#if defined(RSOILWAT) || defined(SWNETCDF) + OutDom->pfunc_mem[k] = + (void (*)(OutPeriod, SW_RUN *, SW_OUT_DOM *)) get_wetdays_mem; +#elif defined(STEPWAT) + OutDom->pfunc_agg[k] = + (void (*)(OutPeriod, SW_RUN *, SW_OUT_DOM *)) get_wetdays_agg; + OutDom->pfunc_SXW[k] = + (void (*)(OutPeriod, SW_RUN *, SW_OUT_DOM *)) get_none_outarray; +#endif + break; + + case eSW_SnowPack: +#if defined(SW_OUTTEXT) + OutDom->pfunc_text[k] = + (void (*)(OutPeriod, SW_RUN *)) get_snowpack_text; +#endif +#if defined(RSOILWAT) || defined(SWNETCDF) + OutDom->pfunc_mem[k] = + (void (*)(OutPeriod, SW_RUN *, SW_OUT_DOM *)) get_snowpack_mem; +#elif defined(STEPWAT) + OutDom->pfunc_agg[k] = + (void (*)(OutPeriod, SW_RUN *, SW_OUT_DOM *)) get_snowpack_agg; + OutDom->pfunc_SXW[k] = + (void (*)(OutPeriod, SW_RUN *, SW_OUT_DOM *)) get_none_outarray; +#endif + break; + + case eSW_DeepSWC: +#if defined(SW_OUTTEXT) + OutDom->pfunc_text[k] = + (void (*)(OutPeriod, SW_RUN *)) get_deepswc_text; +#endif +#if defined(RSOILWAT) || defined(SWNETCDF) + OutDom->pfunc_mem[k] = + (void (*)(OutPeriod, SW_RUN *, SW_OUT_DOM *)) get_deepswc_mem; +#elif defined(STEPWAT) + OutDom->pfunc_agg[k] = + (void (*)(OutPeriod, SW_RUN *, SW_OUT_DOM *)) get_deepswc_agg; + OutDom->pfunc_SXW[k] = + (void (*)(OutPeriod, SW_RUN *, SW_OUT_DOM *)) get_none_outarray; +#endif + break; + + case eSW_SoilTemp: +#if defined(SW_OUTTEXT) + OutDom->pfunc_text[k] = + (void (*)(OutPeriod, SW_RUN *)) get_soiltemp_text; +#endif +#if defined(RSOILWAT) || defined(SWNETCDF) + OutDom->pfunc_mem[k] = + (void (*)(OutPeriod, SW_RUN *, SW_OUT_DOM *)) get_soiltemp_mem; +#elif defined(STEPWAT) + OutDom->pfunc_agg[k] = + (void (*)(OutPeriod, SW_RUN *, SW_OUT_DOM *)) get_soiltemp_agg; + OutDom->pfunc_SXW[k] = + (void (*)(OutPeriod, SW_RUN *, SW_OUT_DOM *)) get_none_outarray; +#endif + break; + + case eSW_Frozen: +#if defined(SW_OUTTEXT) + OutDom->pfunc_text[k] = + (void (*)(OutPeriod, SW_RUN *)) get_frozen_text; +#endif +#if defined(RSOILWAT) || defined(SWNETCDF) + OutDom->pfunc_mem[k] = + (void (*)(OutPeriod, SW_RUN *, SW_OUT_DOM *)) get_frozen_mem; +#elif defined(STEPWAT) + OutDom->pfunc_agg[k] = + (void (*)(OutPeriod, SW_RUN *, SW_OUT_DOM *)) get_frozen_agg; + OutDom->pfunc_SXW[k] = + (void (*)(OutPeriod, SW_RUN *, SW_OUT_DOM *)) get_none_outarray; +#endif + break; + + case eSW_Estab: +#if defined(SW_OUTTEXT) + OutDom->pfunc_text[k] = + (void (*)(OutPeriod, SW_RUN *)) get_estab_text; +#endif +#if defined(RSOILWAT) || defined(SWNETCDF) + OutDom->pfunc_mem[k] = + (void (*)(OutPeriod, SW_RUN *, SW_OUT_DOM *)) get_estab_mem; +#elif defined(STEPWAT) + OutDom->pfunc_agg[k] = + (void (*)(OutPeriod, SW_RUN *, SW_OUT_DOM *)) get_estab_agg; + OutDom->pfunc_SXW[k] = + (void (*)(OutPeriod, SW_RUN *, SW_OUT_DOM *)) get_none_outarray; +#endif + break; + + case eSW_CO2Effects: +#if defined(SW_OUTTEXT) + OutDom->pfunc_text[k] = + (void (*)(OutPeriod, SW_RUN *)) get_co2effects_text; +#endif +#if defined(RSOILWAT) || defined(SWNETCDF) + OutDom->pfunc_mem[k] = (void (*)(OutPeriod, SW_RUN *, SW_OUT_DOM *) + ) get_co2effects_mem; +#elif defined(STEPWAT) + OutDom->pfunc_agg[k] = (void (*)(OutPeriod, SW_RUN *, SW_OUT_DOM *) + ) get_co2effects_agg; + OutDom->pfunc_SXW[k] = + (void (*)(OutPeriod, SW_RUN *, SW_OUT_DOM *)) get_none_outarray; +#endif + break; + + case eSW_Biomass: +#if defined(SW_OUTTEXT) + OutDom->pfunc_text[k] = + (void (*)(OutPeriod, SW_RUN *)) get_biomass_text; +#endif +#if defined(RSOILWAT) || defined(SWNETCDF) + OutDom->pfunc_mem[k] = + (void (*)(OutPeriod, SW_RUN *, SW_OUT_DOM *)) get_biomass_mem; +#elif defined(STEPWAT) + OutDom->pfunc_agg[k] = + (void (*)(OutPeriod, SW_RUN *, SW_OUT_DOM *)) get_biomass_agg; + OutDom->pfunc_SXW[k] = + (void (*)(OutPeriod, SW_RUN *, SW_OUT_DOM *)) get_none_outarray; +#endif + break; + + default: +#if defined(SW_OUTTEXT) + OutDom->pfunc_text[k] = + (void (*)(OutPeriod, SW_RUN *)) get_none_text; +#endif +#if defined(RSOILWAT) || defined(SWNETCDF) + OutDom->pfunc_mem[k] = + (void (*)(OutPeriod, SW_RUN *, SW_OUT_DOM *)) get_none_outarray; +#elif defined(STEPWAT) + OutDom->pfunc_agg[k] = + (void (*)(OutPeriod, SW_RUN *, SW_OUT_DOM *)) get_none_outarray; + OutDom->pfunc_SXW[k] = + (void (*)(OutPeriod, SW_RUN *, SW_OUT_DOM *)) get_none_outarray; +#endif + break; + } + } // end of loop across output keys +} + void SW_OUT_construct( Bool make_soil[], Bool make_regular[], From 43703e745912de52744a878cf398b4811f1bf980 Mon Sep 17 00:00:00 2001 From: Nicholas Persley Date: Fri, 5 Jul 2024 16:31:54 -0400 Subject: [PATCH 12/19] Change preprocessor conditions for `print_IterationSummary` and `sw_outstr` --- include/SW_datastructs.h | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/include/SW_datastructs.h b/include/SW_datastructs.h index 6c615d702..0816417cb 100644 --- a/include/SW_datastructs.h +++ b/include/SW_datastructs.h @@ -1171,7 +1171,9 @@ struct SW_OUT_DOM { (vegtype) */ +#if defined(STEPWAT) Bool print_IterationSummary; +#endif Bool print_SW_Output; #if defined(STEPWAT) @@ -1325,9 +1327,11 @@ typedef struct { typedef struct { - TimeInt tOffset; /* 1 or 0 means we're writing previous or current period */ - +#if defined(SW_OUTTEXT) char sw_outstr[MAX_LAYERS * OUTSTRLEN]; +#endif + + TimeInt tOffset; /* 1 or 0 means we're writing previous or current period */ /* Output first/last days of current year i.e., updated for each year */ TimeInt first[SW_OUTNKEYS], last[SW_OUTNKEYS]; From ffa0e45ed5b1437233a3e81f04aff009e9763552 Mon Sep 17 00:00:00 2001 From: Nicholas Persley Date: Fri, 5 Jul 2024 16:53:43 -0400 Subject: [PATCH 13/19] Properly use `OutRun` not `sw->OutRun` in output functions --- src/SW_Output_get_functions.c | 85 ++++++++++++++++++----------------- 1 file changed, 45 insertions(+), 40 deletions(-) diff --git a/src/SW_Output_get_functions.c b/src/SW_Output_get_functions.c index ac8fb8268..de8064e7b 100644 --- a/src/SW_Output_get_functions.c +++ b/src/SW_Output_get_functions.c @@ -215,7 +215,7 @@ void get_co2effects_mem(OutPeriod pd, SW_RUN *sw, SW_OUT_DOM *OutDom) { pd, OutRun->irow_OUT, OutDom->nrow_OUT, - sw->OutRun.tOffset, + OutRun->tOffset, p ); #endif @@ -398,7 +398,7 @@ void get_biomass_mem(OutPeriod pd, SW_RUN *sw, SW_OUT_DOM *OutDom) { pd, OutRun->irow_OUT, OutDom->nrow_OUT, - sw->OutRun.tOffset, + OutRun->tOffset, p ); #endif @@ -710,7 +710,7 @@ void get_estab_mem(OutPeriod pd, SW_RUN *sw, SW_OUT_DOM *OutDom) { pd, OutRun->irow_OUT, OutDom->nrow_OUT, - sw->OutRun.tOffset, + OutRun->tOffset, p ); #endif @@ -842,7 +842,7 @@ void get_temp_mem(OutPeriod pd, SW_RUN *sw, SW_OUT_DOM *OutDom) { pd, OutRun->irow_OUT, OutDom->nrow_OUT, - sw->OutRun.tOffset, + OutRun->tOffset, p ); #endif @@ -984,12 +984,13 @@ void get_temp_SXW(OutPeriod pd, SW_RUN *sw, SW_OUT_DOM *OutDom) { if (pd == eSW_Month || pd == eSW_Year) { SW_WEATHER_OUTPUTS *vo = sw->Weather.p_oagg[pd]; - tOffset = sw->OutRun.tOffset; + SW_OUT_RUN *OutRun = &sw->OutRun; + tOffset = OutRun->tOffset; if (pd == eSW_Month) { - sw->OutRun.temp_monthly[sw->Model.month - tOffset] = vo->temp_avg; + OutRun->temp_monthly[sw->Model.month - tOffset] = vo->temp_avg; } else if (pd == eSW_Year) { - sw->OutRun.temp = vo->temp_avg; + OutRun->temp = vo->temp_avg; } } @@ -1064,7 +1065,7 @@ void get_precip_mem(OutPeriod pd, SW_RUN *sw, SW_OUT_DOM *OutDom) { pd, OutRun->irow_OUT, OutDom->nrow_OUT, - sw->OutRun.tOffset, + OutRun->tOffset, p ); #endif @@ -1191,12 +1192,13 @@ void get_precip_SXW(OutPeriod pd, SW_RUN *sw, SW_OUT_DOM *OutDom) { if (pd == eSW_Month || pd == eSW_Year) { SW_WEATHER_OUTPUTS *vo = sw->Weather.p_oagg[pd]; - tOffset = sw->OutRun.tOffset; + SW_OUT_RUN *OutRun = &sw->OutRun; + tOffset = OutRun->tOffset; if (pd == eSW_Month) { - sw->OutRun.ppt_monthly[sw->Model.month - tOffset] = vo->ppt; + OutRun->ppt_monthly[sw->Model.month - tOffset] = vo->ppt; } else if (pd == eSW_Year) { - sw->OutRun.ppt = vo->ppt; + OutRun->ppt = vo->ppt; } } @@ -1264,7 +1266,7 @@ void get_vwcBulk_mem(OutPeriod pd, SW_RUN *sw, SW_OUT_DOM *OutDom) { pd, OutRun->irow_OUT, OutDom->nrow_OUT, - sw->OutRun.tOffset, + OutRun->tOffset, p ); #endif @@ -1409,7 +1411,7 @@ void get_vwcMatric_mem(OutPeriod pd, SW_RUN *sw, SW_OUT_DOM *OutDom) { pd, OutRun->irow_OUT, OutDom->nrow_OUT, - sw->OutRun.tOffset, + OutRun->tOffset, p ); #endif @@ -1555,7 +1557,7 @@ void get_swa_mem(OutPeriod pd, SW_RUN *sw, SW_OUT_DOM *OutDom) { pd, OutRun->irow_OUT, OutDom->nrow_OUT, - sw->OutRun.tOffset, + OutRun->tOffset, p ); #endif @@ -1692,7 +1694,7 @@ void get_swcBulk_mem(OutPeriod pd, SW_RUN *sw, SW_OUT_DOM *OutDom) { pd, OutRun->irow_OUT, OutDom->nrow_OUT, - sw->OutRun.tOffset, + OutRun->tOffset, p ); #endif @@ -1777,10 +1779,11 @@ void get_swcBulk_SXW(OutPeriod pd, SW_RUN *sw, SW_OUT_DOM *OutDom) { if (pd == eSW_Month) { LyrIndex i; SW_SOILWAT_OUTPUTS *vo = sw->SoilWat.p_oagg[pd]; - month = sw->Model.month - sw->OutRun.tOffset; + SW_OUT_RUN *OutRun = &sw->OutRun; + month = sw->Model.month - OutRun->tOffset; ForEachSoilLayer(i, sw->Site.n_layers) { - sw->OutRun.swc[i][month] = vo->swcBulk[i]; + OutRun->swc[i][month] = vo->swcBulk[i]; } } @@ -1855,7 +1858,7 @@ void get_swpMatric_mem(OutPeriod pd, SW_RUN *sw, SW_OUT_DOM *OutDom) { pd, OutRun->irow_OUT, OutDom->nrow_OUT, - sw->OutRun.tOffset, + OutRun->tOffset, p ); #endif @@ -1986,7 +1989,7 @@ void get_swaBulk_mem(OutPeriod pd, SW_RUN *sw, SW_OUT_DOM *OutDom) { pd, OutRun->irow_OUT, OutDom->nrow_OUT, - sw->OutRun.tOffset, + OutRun->tOffset, p ); #endif @@ -2121,7 +2124,7 @@ void get_swaMatric_mem(OutPeriod pd, SW_RUN *sw, SW_OUT_DOM *OutDom) { pd, OutRun->irow_OUT, OutDom->nrow_OUT, - sw->OutRun.tOffset, + OutRun->tOffset, p ); #endif @@ -2253,7 +2256,7 @@ void get_surfaceWater_mem(OutPeriod pd, SW_RUN *sw, SW_OUT_DOM *OutDom) { pd, OutRun->irow_OUT, OutDom->nrow_OUT, - sw->OutRun.tOffset, + OutRun->tOffset, p ); #endif @@ -2369,7 +2372,7 @@ void get_runoffrunon_mem(OutPeriod pd, SW_RUN *sw, SW_OUT_DOM *OutDom) { pd, OutRun->irow_OUT, OutDom->nrow_OUT, - sw->OutRun.tOffset, + OutRun->tOffset, p ); #endif @@ -2537,7 +2540,7 @@ void get_transp_mem(OutPeriod pd, SW_RUN *sw, SW_OUT_DOM *OutDom) { pd, OutRun->irow_OUT, OutDom->nrow_OUT, - sw->OutRun.tOffset, + OutRun->tOffset, p ); #endif @@ -2687,17 +2690,18 @@ void get_transp_SXW(OutPeriod pd, SW_RUN *sw, SW_OUT_DOM *OutDom) { LyrIndex i; int k; SW_SOILWAT_OUTPUTS *vo = sw->SoilWat.p_oagg[pd]; - month = sw->Model.month - sw->OutRun.tOffset; + SW_OUT_RUN *OutRun = &sw->OutRun; + month = sw->Model.month - OutRun->tOffset; /* total transpiration */ ForEachSoilLayer(i, sw->Site.n_layers) { - sw->OutRun.transpTotal[i][month] = vo->transp_total[i]; + OutRun->transpTotal[i][month] = vo->transp_total[i]; } /* transpiration for each vegetation type */ ForEachVegType(k) { ForEachSoilLayer(i, sw->Site.n_layers) { - sw->OutRun.transpVeg[k][i][month] = vo->transp[k][i]; + OutRun->transpVeg[k][i][month] = vo->transp[k][i]; } } } @@ -2757,7 +2761,7 @@ void get_evapSoil_mem(OutPeriod pd, SW_RUN *sw, SW_OUT_DOM *OutDom) { pd, OutRun->irow_OUT, OutDom->nrow_OUT, - sw->OutRun.tOffset, + OutRun->tOffset, p ); #endif @@ -2907,7 +2911,7 @@ void get_evapSurface_mem(OutPeriod pd, SW_RUN *sw, SW_OUT_DOM *OutDom) { pd, OutRun->irow_OUT, OutDom->nrow_OUT, - sw->OutRun.tOffset, + OutRun->tOffset, p ); #endif @@ -3097,7 +3101,7 @@ void get_interception_mem(OutPeriod pd, SW_RUN *sw, SW_OUT_DOM *OutDom) { pd, OutRun->irow_OUT, OutDom->nrow_OUT, - sw->OutRun.tOffset, + OutRun->tOffset, p ); #endif @@ -3255,7 +3259,7 @@ void get_soilinf_mem(OutPeriod pd, SW_RUN *sw, SW_OUT_DOM *OutDom) { pd, OutRun->irow_OUT, OutDom->nrow_OUT, - sw->OutRun.tOffset, + OutRun->tOffset, p ); #endif @@ -3360,7 +3364,7 @@ void get_lyrdrain_mem(OutPeriod pd, SW_RUN *sw, SW_OUT_DOM *OutDom) { pd, OutRun->irow_OUT, OutDom->nrow_OUT, - sw->OutRun.tOffset, + OutRun->tOffset, p ); #endif @@ -3500,7 +3504,7 @@ void get_hydred_mem(OutPeriod pd, SW_RUN *sw, SW_OUT_DOM *OutDom) { pd, OutRun->irow_OUT, OutDom->nrow_OUT, - sw->OutRun.tOffset, + OutRun->tOffset, p ); #endif @@ -3709,7 +3713,7 @@ void get_aet_mem(OutPeriod pd, SW_RUN *sw, SW_OUT_DOM *OutDom) { pd, OutRun->irow_OUT, OutDom->nrow_OUT, - sw->OutRun.tOffset, + OutRun->tOffset, p ); #endif @@ -3850,8 +3854,9 @@ void get_aet_agg(OutPeriod pd, SW_RUN *sw, SW_OUT_DOM *OutDom) { void get_aet_SXW(OutPeriod pd, SW_RUN *sw, SW_OUT_DOM *OutDom) { if (pd == eSW_Year) { SW_SOILWAT_OUTPUTS *vo = sw->SoilWat.p_oagg[pd]; + SW_OUT_RUN *OutRun = &sw->OutRun; - sw->OutRun.aet = vo->aet; + OutRun->aet = vo->aet; } (void) OutDom; @@ -3923,7 +3928,7 @@ void get_pet_mem(OutPeriod pd, SW_RUN *sw, SW_OUT_DOM *OutDom) { pd, OutRun->irow_OUT, OutDom->nrow_OUT, - sw->OutRun.tOffset, + OutRun->tOffset, p ); #endif @@ -4093,7 +4098,7 @@ void get_wetdays_mem(OutPeriod pd, SW_RUN *sw, SW_OUT_DOM *OutDom) { pd, OutRun->irow_OUT, OutDom->nrow_OUT, - sw->OutRun.tOffset, + OutRun->tOffset, p ); #endif @@ -4241,7 +4246,7 @@ void get_snowpack_mem(OutPeriod pd, SW_RUN *sw, SW_OUT_DOM *OutDom) { pd, OutRun->irow_OUT, OutDom->nrow_OUT, - sw->OutRun.tOffset, + OutRun->tOffset, p ); #endif @@ -4359,7 +4364,7 @@ void get_deepswc_mem(OutPeriod pd, SW_RUN *sw, SW_OUT_DOM *OutDom) { pd, OutRun->irow_OUT, OutDom->nrow_OUT, - sw->OutRun.tOffset, + OutRun->tOffset, p ); #endif @@ -4483,7 +4488,7 @@ void get_soiltemp_mem(OutPeriod pd, SW_RUN *sw, SW_OUT_DOM *OutDom) { pd, OutRun->irow_OUT, OutDom->nrow_OUT, - sw->OutRun.tOffset, + OutRun->tOffset, p ); #endif @@ -4687,7 +4692,7 @@ void get_frozen_mem(OutPeriod pd, SW_RUN *sw, SW_OUT_DOM *OutDom) { pd, OutRun->irow_OUT, OutDom->nrow_OUT, - sw->OutRun.tOffset, + OutRun->tOffset, p ); #endif From 2c8b1e3365685d1d0d7d815a8b5c0da7f3d97e18 Mon Sep 17 00:00:00 2001 From: Nicholas Persley Date: Fri, 5 Jul 2024 20:22:09 -0400 Subject: [PATCH 14/19] Clang format output `SW_Output_get_functions.c` --- src/SW_Output_get_functions.c | 196 +++++----------------------------- 1 file changed, 28 insertions(+), 168 deletions(-) diff --git a/src/SW_Output_get_functions.c b/src/SW_Output_get_functions.c index de8064e7b..d2e4d5f98 100644 --- a/src/SW_Output_get_functions.c +++ b/src/SW_Output_get_functions.c @@ -211,12 +211,7 @@ void get_co2effects_mem(OutPeriod pd, SW_RUN *sw, SW_OUT_DOM *OutDom) { #if defined(RSOILWAT) get_outvalleader( - &sw->Model, - pd, - OutRun->irow_OUT, - OutDom->nrow_OUT, - OutRun->tOffset, - p + &sw->Model, pd, OutRun->irow_OUT, OutDom->nrow_OUT, OutRun->tOffset, p ); #endif @@ -394,12 +389,7 @@ void get_biomass_mem(OutPeriod pd, SW_RUN *sw, SW_OUT_DOM *OutDom) { #if defined(RSOILWAT) int i; get_outvalleader( - &sw->Model, - pd, - OutRun->irow_OUT, - OutDom->nrow_OUT, - OutRun->tOffset, - p + &sw->Model, pd, OutRun->irow_OUT, OutDom->nrow_OUT, OutRun->tOffset, p ); #endif @@ -706,12 +696,7 @@ void get_estab_mem(OutPeriod pd, SW_RUN *sw, SW_OUT_DOM *OutDom) { #if defined(RSOILWAT) get_outvalleader( - &sw->Model, - pd, - OutRun->irow_OUT, - OutDom->nrow_OUT, - OutRun->tOffset, - p + &sw->Model, pd, OutRun->irow_OUT, OutDom->nrow_OUT, OutRun->tOffset, p ); #endif @@ -838,12 +823,7 @@ void get_temp_mem(OutPeriod pd, SW_RUN *sw, SW_OUT_DOM *OutDom) { #if defined(RSOILWAT) get_outvalleader( - &sw->Model, - pd, - OutRun->irow_OUT, - OutDom->nrow_OUT, - OutRun->tOffset, - p + &sw->Model, pd, OutRun->irow_OUT, OutDom->nrow_OUT, OutRun->tOffset, p ); #endif @@ -1061,12 +1041,7 @@ void get_precip_mem(OutPeriod pd, SW_RUN *sw, SW_OUT_DOM *OutDom) { #if defined(RSOILWAT) get_outvalleader( - &sw->Model, - pd, - OutRun->irow_OUT, - OutDom->nrow_OUT, - OutRun->tOffset, - p + &sw->Model, pd, OutRun->irow_OUT, OutDom->nrow_OUT, OutRun->tOffset, p ); #endif @@ -1262,12 +1237,7 @@ void get_vwcBulk_mem(OutPeriod pd, SW_RUN *sw, SW_OUT_DOM *OutDom) { #if defined(RSOILWAT) get_outvalleader( - &sw->Model, - pd, - OutRun->irow_OUT, - OutDom->nrow_OUT, - OutRun->tOffset, - p + &sw->Model, pd, OutRun->irow_OUT, OutDom->nrow_OUT, OutRun->tOffset, p ); #endif @@ -1407,12 +1377,7 @@ void get_vwcMatric_mem(OutPeriod pd, SW_RUN *sw, SW_OUT_DOM *OutDom) { #if defined(RSOILWAT) get_outvalleader( - &sw->Model, - pd, - OutRun->irow_OUT, - OutDom->nrow_OUT, - OutRun->tOffset, - p + &sw->Model, pd, OutRun->irow_OUT, OutDom->nrow_OUT, OutRun->tOffset, p ); #endif @@ -1553,12 +1518,7 @@ void get_swa_mem(OutPeriod pd, SW_RUN *sw, SW_OUT_DOM *OutDom) { #if defined(RSOILWAT) get_outvalleader( - &sw->Model, - pd, - OutRun->irow_OUT, - OutDom->nrow_OUT, - OutRun->tOffset, - p + &sw->Model, pd, OutRun->irow_OUT, OutDom->nrow_OUT, OutRun->tOffset, p ); #endif @@ -1690,12 +1650,7 @@ void get_swcBulk_mem(OutPeriod pd, SW_RUN *sw, SW_OUT_DOM *OutDom) { #if defined(RSOILWAT) get_outvalleader( - &sw->Model, - pd, - OutRun->irow_OUT, - OutDom->nrow_OUT, - OutRun->tOffset, - p + &sw->Model, pd, OutRun->irow_OUT, OutDom->nrow_OUT, OutRun->tOffset, p ); #endif @@ -1854,12 +1809,7 @@ void get_swpMatric_mem(OutPeriod pd, SW_RUN *sw, SW_OUT_DOM *OutDom) { #if defined(RSOILWAT) get_outvalleader( - &sw->Model, - pd, - OutRun->irow_OUT, - OutDom->nrow_OUT, - OutRun->tOffset, - p + &sw->Model, pd, OutRun->irow_OUT, OutDom->nrow_OUT, OutRun->tOffset, p ); #endif @@ -1985,12 +1935,7 @@ void get_swaBulk_mem(OutPeriod pd, SW_RUN *sw, SW_OUT_DOM *OutDom) { #if defined(RSOILWAT) get_outvalleader( - &sw->Model, - pd, - OutRun->irow_OUT, - OutDom->nrow_OUT, - OutRun->tOffset, - p + &sw->Model, pd, OutRun->irow_OUT, OutDom->nrow_OUT, OutRun->tOffset, p ); #endif @@ -2120,12 +2065,7 @@ void get_swaMatric_mem(OutPeriod pd, SW_RUN *sw, SW_OUT_DOM *OutDom) { #if defined(RSOILWAT) get_outvalleader( - &sw->Model, - pd, - OutRun->irow_OUT, - OutDom->nrow_OUT, - OutRun->tOffset, - p + &sw->Model, pd, OutRun->irow_OUT, OutDom->nrow_OUT, OutRun->tOffset, p ); #endif @@ -2252,12 +2192,7 @@ void get_surfaceWater_mem(OutPeriod pd, SW_RUN *sw, SW_OUT_DOM *OutDom) { #if defined(RSOILWAT) get_outvalleader( - &sw->Model, - pd, - OutRun->irow_OUT, - OutDom->nrow_OUT, - OutRun->tOffset, - p + &sw->Model, pd, OutRun->irow_OUT, OutDom->nrow_OUT, OutRun->tOffset, p ); #endif @@ -2368,12 +2303,7 @@ void get_runoffrunon_mem(OutPeriod pd, SW_RUN *sw, SW_OUT_DOM *OutDom) { #if defined(RSOILWAT) get_outvalleader( - &sw->Model, - pd, - OutRun->irow_OUT, - OutDom->nrow_OUT, - OutRun->tOffset, - p + &sw->Model, pd, OutRun->irow_OUT, OutDom->nrow_OUT, OutRun->tOffset, p ); #endif @@ -2536,12 +2466,7 @@ void get_transp_mem(OutPeriod pd, SW_RUN *sw, SW_OUT_DOM *OutDom) { #if defined(RSOILWAT) get_outvalleader( - &sw->Model, - pd, - OutRun->irow_OUT, - OutDom->nrow_OUT, - OutRun->tOffset, - p + &sw->Model, pd, OutRun->irow_OUT, OutDom->nrow_OUT, OutRun->tOffset, p ); #endif @@ -2757,12 +2682,7 @@ void get_evapSoil_mem(OutPeriod pd, SW_RUN *sw, SW_OUT_DOM *OutDom) { #if defined(RSOILWAT) get_outvalleader( - &sw->Model, - pd, - OutRun->irow_OUT, - OutDom->nrow_OUT, - OutRun->tOffset, - p + &sw->Model, pd, OutRun->irow_OUT, OutDom->nrow_OUT, OutRun->tOffset, p ); #endif @@ -2907,12 +2827,7 @@ void get_evapSurface_mem(OutPeriod pd, SW_RUN *sw, SW_OUT_DOM *OutDom) { #if defined(RSOILWAT) get_outvalleader( - &sw->Model, - pd, - OutRun->irow_OUT, - OutDom->nrow_OUT, - OutRun->tOffset, - p + &sw->Model, pd, OutRun->irow_OUT, OutDom->nrow_OUT, OutRun->tOffset, p ); #endif @@ -3097,12 +3012,7 @@ void get_interception_mem(OutPeriod pd, SW_RUN *sw, SW_OUT_DOM *OutDom) { #if defined(RSOILWAT) get_outvalleader( - &sw->Model, - pd, - OutRun->irow_OUT, - OutDom->nrow_OUT, - OutRun->tOffset, - p + &sw->Model, pd, OutRun->irow_OUT, OutDom->nrow_OUT, OutRun->tOffset, p ); #endif @@ -3255,12 +3165,7 @@ void get_soilinf_mem(OutPeriod pd, SW_RUN *sw, SW_OUT_DOM *OutDom) { #if defined(RSOILWAT) get_outvalleader( - &sw->Model, - pd, - OutRun->irow_OUT, - OutDom->nrow_OUT, - OutRun->tOffset, - p + &sw->Model, pd, OutRun->irow_OUT, OutDom->nrow_OUT, OutRun->tOffset, p ); #endif @@ -3360,12 +3265,7 @@ void get_lyrdrain_mem(OutPeriod pd, SW_RUN *sw, SW_OUT_DOM *OutDom) { #if defined(RSOILWAT) get_outvalleader( - &sw->Model, - pd, - OutRun->irow_OUT, - OutDom->nrow_OUT, - OutRun->tOffset, - p + &sw->Model, pd, OutRun->irow_OUT, OutDom->nrow_OUT, OutRun->tOffset, p ); #endif @@ -3500,12 +3400,7 @@ void get_hydred_mem(OutPeriod pd, SW_RUN *sw, SW_OUT_DOM *OutDom) { #if defined(RSOILWAT) get_outvalleader( - &sw->Model, - pd, - OutRun->irow_OUT, - OutDom->nrow_OUT, - OutRun->tOffset, - p + &sw->Model, pd, OutRun->irow_OUT, OutDom->nrow_OUT, OutRun->tOffset, p ); #endif @@ -3709,12 +3604,7 @@ void get_aet_mem(OutPeriod pd, SW_RUN *sw, SW_OUT_DOM *OutDom) { #if defined(RSOILWAT) get_outvalleader( - &sw->Model, - pd, - OutRun->irow_OUT, - OutDom->nrow_OUT, - OutRun->tOffset, - p + &sw->Model, pd, OutRun->irow_OUT, OutDom->nrow_OUT, OutRun->tOffset, p ); #endif @@ -3924,12 +3814,7 @@ void get_pet_mem(OutPeriod pd, SW_RUN *sw, SW_OUT_DOM *OutDom) { #if defined(RSOILWAT) get_outvalleader( - &sw->Model, - pd, - OutRun->irow_OUT, - OutDom->nrow_OUT, - OutRun->tOffset, - p + &sw->Model, pd, OutRun->irow_OUT, OutDom->nrow_OUT, OutRun->tOffset, p ); #endif @@ -4094,12 +3979,7 @@ void get_wetdays_mem(OutPeriod pd, SW_RUN *sw, SW_OUT_DOM *OutDom) { #if defined(RSOILWAT) get_outvalleader( - &sw->Model, - pd, - OutRun->irow_OUT, - OutDom->nrow_OUT, - OutRun->tOffset, - p + &sw->Model, pd, OutRun->irow_OUT, OutDom->nrow_OUT, OutRun->tOffset, p ); #endif @@ -4242,12 +4122,7 @@ void get_snowpack_mem(OutPeriod pd, SW_RUN *sw, SW_OUT_DOM *OutDom) { #if defined(RSOILWAT) get_outvalleader( - &sw->Model, - pd, - OutRun->irow_OUT, - OutDom->nrow_OUT, - OutRun->tOffset, - p + &sw->Model, pd, OutRun->irow_OUT, OutDom->nrow_OUT, OutRun->tOffset, p ); #endif @@ -4360,12 +4235,7 @@ void get_deepswc_mem(OutPeriod pd, SW_RUN *sw, SW_OUT_DOM *OutDom) { #if defined(RSOILWAT) get_outvalleader( - &sw->Model, - pd, - OutRun->irow_OUT, - OutDom->nrow_OUT, - OutRun->tOffset, - p + &sw->Model, pd, OutRun->irow_OUT, OutDom->nrow_OUT, OutRun->tOffset, p ); #endif @@ -4484,12 +4354,7 @@ void get_soiltemp_mem(OutPeriod pd, SW_RUN *sw, SW_OUT_DOM *OutDom) { #if defined(RSOILWAT) get_outvalleader( - &sw->Model, - pd, - OutRun->irow_OUT, - OutDom->nrow_OUT, - OutRun->tOffset, - p + &sw->Model, pd, OutRun->irow_OUT, OutDom->nrow_OUT, OutRun->tOffset, p ); #endif @@ -4688,12 +4553,7 @@ void get_frozen_mem(OutPeriod pd, SW_RUN *sw, SW_OUT_DOM *OutDom) { #if defined(RSOILWAT) get_outvalleader( - &sw->Model, - pd, - OutRun->irow_OUT, - OutDom->nrow_OUT, - OutRun->tOffset, - p + &sw->Model, pd, OutRun->irow_OUT, OutDom->nrow_OUT, OutRun->tOffset, p ); #endif From 9c3404512f94e193ad8232110996d53dca0f187c Mon Sep 17 00:00:00 2001 From: Nicholas Persley Date: Sat, 6 Jul 2024 15:47:42 -0400 Subject: [PATCH 15/19] Zero out SW_OUT_DOM in `SW_OUTDOM_construct()` --- src/SW_Output.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/SW_Output.c b/src/SW_Output.c index 76f49ec8f..dd9f82909 100644 --- a/src/SW_Output.c +++ b/src/SW_Output.c @@ -1312,6 +1312,8 @@ void SW_OUTDOM_construct(SW_OUT_DOM *OutDom) { IntUS k; OutPeriod p; + memset(OutDom, 0, sizeof(SW_OUT_DOM)); + #if defined(SOILWAT) OutDom->print_SW_Output = swTRUE; #elif defined(STEPWAT) From 9f50109f9cd6c04cbd887e71d5f14a3b81c69e1b Mon Sep 17 00:00:00 2001 From: Nicholas Persley Date: Sat, 6 Jul 2024 15:49:29 -0400 Subject: [PATCH 16/19] Update output description in SW_Output.c --- src/SW_Output.c | 71 ++++++++++++++++++++++++++++--------------------- 1 file changed, 41 insertions(+), 30 deletions(-) diff --git a/src/SW_Output.c b/src/SW_Output.c index dd9f82909..c7e8cf5fe 100644 --- a/src/SW_Output.c +++ b/src/SW_Output.c @@ -3643,17 +3643,17 @@ void SW_FILESTATUS_deepCopy( loops over each \ref OutPeriod `pd` and, depending on application (see details below): - calls the appropriate output formatter function `get_XXX` via its - pointer stored in `SW_Output[k].pfunc_XXX` + pointer stored in `OutDom.pfunc_XXX` - writes output to file(s) and/or passes output in-memory There are four types of outputs and thus four types of output formatter functions `get_XXX` in file \ref SW_Output_get_functions.c - output to text files of current simulation: - - output formatter function such as `get_XXX_text` which prepare a - formatted text string in the global variable \ref SW_OUT_RUN.sw_outstr + - output formatter function such as `get_XXX_text` which prepares a + formatted text string in the variable sw_outstr found in SW_OUT_RUN which is concatenated and written to the text files by SW_OUT_write_today() - these output formatter functions are assigned to pointers - `SW_Output[k].pfunc_text` and called by SW_OUT_write_today() + `OutDom.pfunc_text[k]` and called by SW_OUT_write_today() - currently used by `SOILWAT2-standalone` and by `STEPWAT2` if executed with its `-i flag` @@ -3669,7 +3669,7 @@ void SW_FILESTATUS_deepCopy( \ref sw_outstr_agg which is concatenated and written to the text files by SW_OUT_write_today() - these output formatter functions are assigned to pointers - `SW_Output[k].pfunc_agg` and called by SW_OUT_write_today() + `OutDom.pfunc_agg[k]` and called by SW_OUT_write_today() - currently used by `STEPWAT2` if executed with its `-o flag` - in-memory output via `STEPWAT2` variable `SXW` @@ -3680,7 +3680,7 @@ void SW_FILESTATUS_deepCopy( values directly in the appropriate slots of `SXW` for the correct time step - these output formatter functions are assigned to pointers - `SW_Output[k].pfunc_SXW` and called by SW_OUT_write_today() + `OutDom.pfunc_SXW[k]` and called by SW_OUT_write_today() - currently used by `STEPWAT2` if executed with its `-s flag`, i.e., whenever `STEPWAT2` is run with `SOILWAT2` @@ -3688,7 +3688,7 @@ void SW_FILESTATUS_deepCopy( - output formatter function such as `get_XXX_mem` which store the correct values directly in the appropriate elements of `SW_OUT_RUN.p_OUT` - these output formatter functions are assigned to pointers - `SW_Output[k].pfunc_mem` and called by SW_OUT_write_today() + `OutDom.pfunc_mem[k]` and called by SW_OUT_write_today() - currently used by `rSOILWAT2` @@ -3696,28 +3696,39 @@ void SW_FILESTATUS_deepCopy( In detail: - There is a structure array (SW_OUTPUT) that contains the - information from the outsetup.in file. This structure is filled in - the initialization process by matching defined macros of valid keys - with enumeration variables used as indices into the structure - array. A similar combination of text macros and enumeration - constants handles the TIMEPERIOD conversion from text to numeric - index. - - Each structure element of the array contains the output period - code, start and end values, output file name, opened file pointer - for output, on/off status, and a pointer to the function that - prepares a complete line of formatted output per output period. - - A _construct() function clears the entire structure array to set - values and flags to zero. Those output objects that are - turned off are ignored. - Thus, to add a new output variable, a new get_function must be added to - in addition to adding the new macro and enumeration keys - for it. Oh, and a line or two of summarizing code. - - After initialization, each valid output key has an element in the - structure array that "knows" its parameters and whether it is on or + There are two output structures - SW_OUT_DOM & SW_OUT_RUN. + + The main structure used in SOILWAT2 is SW_OUT_DOM which holds output + information that is consistent through domain simulations. This includes: + 1) Information from outsetup.in (array, an element per output key) + 2) Output function pointers (array, an element per output key) + 3) Other output information like output column names and time steps + + SW_OUT_RUN holds a small amount of output information in SOILWAT2 + the main information is + 1) First and last day of the current year during simulation + 2) Formatted output string for output files + + The output arrays in SW_OUT_DOM (e.g., mykey) are filled in by + initialization process by matching defined macros of valid keys + with enumeration variables used as indices into the arrays of + information it contains. A similar combination of text macros + and enumeration constants handles the TIMEPERIOD conversion + from text to numeric index. + + The arrays being spoke of hold the output period code, start + and end values, output file name, opened file pointer for output, + on/off status, and a pointer to the function that prepares a complete + line of formatted output per output period. + + A _construct() function clears the SW_OUT_DOM in it's entirety to set + values and flags to zero. Those output objects that are turned off + are ignored. Thus, to add a new output variable, a new get_function + must be added to in addition to adding the new macro and enumeration + keys for it. Oh, and a line or two of summarizing code. + + After initialization, each valid output key has an element in + SW_OUT_DOM that "knows" its parameters and whether it is on or off. There is still space allocated for the "off" keys but they are ignored by the use flag. @@ -3777,7 +3788,7 @@ void SW_FILESTATUS_deepCopy( - Create and declare a get_*() function that returns the correctly formatted string for output. - Add a line to link the get_ function to the appropriate element in - the SW_OUTPUT array in _construct(). + the SW_OUT_DOM output function array in _construct(). - Add new code to the switch statement in sumof_*() to handle the new key. - Add new code to the switch statement in average_for() to do the From f96fb86acd5930d8294e6718471b79bf9f4f49be Mon Sep 17 00:00:00 2001 From: Nicholas Persley Date: Mon, 8 Jul 2024 12:25:10 -0400 Subject: [PATCH 17/19] Return if `SW_FILESTATUS_deepCopy()` fails --- src/SW_Control.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/SW_Control.c b/src/SW_Control.c index c084da0ac..2a9615c17 100644 --- a/src/SW_Control.c +++ b/src/SW_Control.c @@ -218,6 +218,9 @@ void SW_RUN_deepCopy( SW_FILESTATUS_deepCopy( &dest->FileStatus, &source->FileStatus, OutDom, LogInfo ); + if(LogInfo->stopRun) { + return; // Exit prematurely due to error + } SW_OUT_construct_outarray(OutDom, &dest->OutRun, LogInfo); #else (void) OutDom; From b9065e8bc9becf34da14a44df115de1e642114bc Mon Sep 17 00:00:00 2001 From: Nicholas Persley Date: Mon, 8 Jul 2024 12:57:08 -0400 Subject: [PATCH 18/19] New functions - `SW_OUTDOM_init_ptrs` & `SW_OUTDOM_deepCopy` - SW_OUTDOM_init_ptrs - Initialize pointers found in SW_OUT_DOM - SW_OUTDOM_deepCopy - Copies all pointers within SW_OUT_DOM, including SW_NETCDF information if defined --- include/SW_Output.h | 6 ++ src/SW_Control.c | 2 +- src/SW_Domain.c | 33 +++-------- src/SW_Output.c | 108 +++++++++++++++++++++++++++++++--- tests/gtests/sw_testhelpers.h | 14 ----- 5 files changed, 117 insertions(+), 46 deletions(-) diff --git a/include/SW_Output.h b/include/SW_Output.h index 94a24c47b..00978cff7 100644 --- a/include/SW_Output.h +++ b/include/SW_Output.h @@ -158,6 +158,8 @@ extern char const *styp2longstr[]; void SW_OUT_init_ptrs(SW_OUT_RUN *OutRun); +void SW_OUTDOM_init_ptrs(SW_OUT_DOM *OutDom); + void SW_OUTDOM_construct(SW_OUT_DOM *OutDom); void SW_OUT_construct( @@ -287,6 +289,10 @@ void SW_FILESTATUS_deepCopy( ); #endif +void SW_OUTDOM_deepCopy( + SW_OUT_DOM *source, SW_OUT_DOM *dest, LOG_INFO *LogInfo +); + // Functions that format the output in `sw_outstr` for printing /* --------------------------------------------------- */ /* each of these get_ -type funcs return a diff --git a/src/SW_Control.c b/src/SW_Control.c index 2a9615c17..2dc4f8501 100644 --- a/src/SW_Control.c +++ b/src/SW_Control.c @@ -218,7 +218,7 @@ void SW_RUN_deepCopy( SW_FILESTATUS_deepCopy( &dest->FileStatus, &source->FileStatus, OutDom, LogInfo ); - if(LogInfo->stopRun) { + if (LogInfo->stopRun) { return; // Exit prematurely due to error } SW_OUT_construct_outarray(OutDom, &dest->OutRun, LogInfo); diff --git a/src/SW_Domain.c b/src/SW_Domain.c index 189c86aea..3ff119eb1 100644 --- a/src/SW_Domain.c +++ b/src/SW_Domain.c @@ -508,45 +508,30 @@ void SW_DOM_SimSet( } void SW_DOM_deepCopy(SW_DOMAIN *source, SW_DOMAIN *dest, LOG_INFO *LogInfo) { - IntUS k, i; memcpy(dest, source, sizeof(*dest)); + SW_OUTDOM_deepCopy(&source->OutDom, &dest->OutDom, LogInfo); + SW_F_deepCopy(&dest->PathInfo, &source->PathInfo, LogInfo); + if (LogInfo->stopRun) { + return; // Exit function prematurely due to error + } #if defined(SWNETCDF) SW_NC_deepCopy(&dest->netCDFInfo, &source->netCDFInfo, LogInfo); -#endif - - ForEachOutKey(k) { - for (i = 0; i < 5 * NVEGTYPES + MAX_LAYERS; i++) { - if (!isnull(source->OutDom.colnames_OUT[k][i])) { - - dest->OutDom.colnames_OUT[k][i] = - Str_Dup(source->OutDom.colnames_OUT[k][i], LogInfo); - if (LogInfo->stopRun) { - return; // Exit function prematurely due to error - } - } - } + if (LogInfo->stopRun) { + return; // Exit function prematurely due to error } +#endif } void SW_DOM_init_ptrs(SW_DOMAIN *SW_Domain) { - IntUS key, column; - ForEachOutKey(key) { - for (column = 0; column < 5 * NVEGTYPES + MAX_LAYERS; column++) { - SW_Domain->OutDom.colnames_OUT[key][column] = NULL; - } - } + SW_OUTDOM_init_ptrs(&SW_Domain->OutDom); SW_F_init_ptrs(SW_Domain->PathInfo.InFiles); -#ifdef RSOILWAT - ForEachOutKey(key) { SW_Domain->OutDom.outfile[key] = NULL; } -#endif - #if defined(SWNETCDF) SW_NC_init_ptrs(&SW_Domain->netCDFInfo); #endif diff --git a/src/SW_Output.c b/src/SW_Output.c index c7e8cf5fe..61c50a572 100644 --- a/src/SW_Output.c +++ b/src/SW_Output.c @@ -1300,6 +1300,29 @@ void SW_OUT_init_ptrs(SW_OUT_RUN *OutRun) { #endif } +void SW_OUTDOM_init_ptrs(SW_OUT_DOM *OutDom) { + IntUS key, column; + + ForEachOutKey(key) { + for (column = 0; column < 5 * NVEGTYPES + MAX_LAYERS; column++) { + OutDom->colnames_OUT[key][column] = NULL; + } + } + +#if defined(SWNETCDF) + ForEachOutKey(key) { + OutDom->outputVarInfo[key] = NULL; + OutDom->reqOutputVars[key] = NULL; + OutDom->units_sw[key] = NULL; + OutDom->uconv[key] = NULL; + } +#endif + +#ifdef RSOILWAT + ForEachOutKey(key) { OutDom->outfile[key] = NULL; } +#endif +} + /** * @brief Initialize output values that live in the domain-level * (contained in SW_OUT_DOM) @@ -1350,13 +1373,6 @@ void SW_OUTDOM_construct(SW_OUT_DOM *OutDom) { OutDom->first_orig[k] = 1; OutDom->last_orig[k] = 366; -#if defined(SWNETCDF) - OutDom->outputVarInfo[k] = NULL; - OutDom->reqOutputVars[k] = NULL; - OutDom->units_sw[k] = NULL; - OutDom->uconv[k] = NULL; -#endif - // assign `get_XXX` functions switch (k) { case eSW_Temp: @@ -3605,6 +3621,84 @@ void SW_FILESTATUS_deepCopy( } #endif +/** + * @brief Deep copy the struct SW_OUT_DOM + * + * @param[in] source Source instance of SW_OUT_DOM + * @param[out] dest Destination instance of SW_OUT_DOM + * @param[out] LogInfo Holds information on warnings and errors + */ +void SW_OUTDOM_deepCopy( + SW_OUT_DOM *source, SW_OUT_DOM *dest, LOG_INFO *LogInfo +) { + + IntUS k, i; + + /* Copies output pointers as well */ + memcpy(source, dest, sizeof(*dest)); + + ForEachOutKey(k) { + for (i = 0; i < 5 * NVEGTYPES + MAX_LAYERS; i++) { + if (!isnull(source->colnames_OUT[k][i])) { + + dest->colnames_OUT[k][i] = + Str_Dup(source->colnames_OUT[k][i], LogInfo); + if (LogInfo->stopRun) { + return; // Exit function prematurely due to error + } + } + } + +#if defined(SWNETCDF) + int varNum, attNum; + + if (source->nvar_OUT[k] > 0 && source->use[k]) { + + SW_NC_alloc_outputkey_var_info(dest, k, LogInfo); + if (LogInfo->stopRun) { + return; // Exit function prematurely due to error + } + + if (!isnull(source->reqOutputVars[k])) { + for (varNum = 0; varNum < source->nvar_OUT[k]; varNum++) { + dest->reqOutputVars[k][varNum] = + source->reqOutputVars[k][varNum]; + + if (dest->reqOutputVars[k][varNum]) { + for (attNum = 0; attNum < MAX_NATTS; attNum++) { + if (!isnull(source->outputVarInfo[k][varNum][attNum] + )) { + dest->outputVarInfo[k][varNum] + [attNum] = Str_Dup( + source->outputVarInfo[k][varNum][attNum], + LogInfo + ); + if (LogInfo->stopRun) { + return; // Exit function prematurely due to + // error + } + } + } + + dest[k].units_sw[k][varNum] = + Str_Dup(source->units_sw[k][varNum], LogInfo); + if (LogInfo->stopRun) { + return; // Exit function prematurely due to error + } + } + } + } + + } else { + dest->reqOutputVars[k] = NULL; + dest->outputVarInfo[k] = NULL; + dest->units_sw[k] = NULL; + dest->uconv[k] = NULL; + } +#endif + } +} + /*==================================================================*/ /** @defgroup out_algo Description of the output algorithm diff --git a/tests/gtests/sw_testhelpers.h b/tests/gtests/sw_testhelpers.h index 6c737112f..4e32b1fa4 100644 --- a/tests/gtests/sw_testhelpers.h +++ b/tests/gtests/sw_testhelpers.h @@ -64,20 +64,6 @@ class AllTestFixture : public ::testing::Test { void SetUp() override { sw_init_logs(NULL, &LogInfo); -#if defined(SWNETCDF) - memcpy( - SW_Domain.OutDom.pfunc_mem, - template_SW_Domain.OutDom.pfunc_mem, - sizeof(void *) * SW_OUTNKEYS - ); -#else - memcpy( - SW_Domain.OutDom.pfunc_text, - template_SW_Domain.OutDom.pfunc_text, - sizeof(void *) * SW_OUTNKEYS - ); -#endif - SW_DOM_deepCopy(&template_SW_Domain, &SW_Domain, &LogInfo); sw_fail_on_error(&LogInfo); From 0b334f1dbe25cb37dcc7490a8ca64db191ba051b Mon Sep 17 00:00:00 2001 From: Nicholas Persley Date: Mon, 8 Jul 2024 13:22:20 -0400 Subject: [PATCH 19/19] Swap dest and source for `memcpy()` in `SW_OUTDOM_deepCopy()` --- src/SW_Output.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/SW_Output.c b/src/SW_Output.c index 61c50a572..3dee18b7e 100644 --- a/src/SW_Output.c +++ b/src/SW_Output.c @@ -3635,7 +3635,7 @@ void SW_OUTDOM_deepCopy( IntUS k, i; /* Copies output pointers as well */ - memcpy(source, dest, sizeof(*dest)); + memcpy(dest, source, sizeof(*dest)); ForEachOutKey(k) { for (i = 0; i < 5 * NVEGTYPES + MAX_LAYERS; i++) {