Skip to content

Commit

Permalink
Update changed position of eLog in SOILWAT2
Browse files Browse the repository at this point in the history
- SOILWAT2 commit d20da03d196ccb344a8eefcc89df5feebaab5cb2 "Consistently clean output directory" (2025 Jan 24) modified the position of eLog in the enumerator SW_FileIndex

- onSet_SW_F() no longer copies rSOILWAT2's swFiles@InFiles to SOILWAT2's txtInFiles -- these are unused if rSOILWAT2 sets values
- sw_consts() now reflects new value of `eLog` which updates `rSW2_glovars[["kSOILWAT2"]][["InFiles"]]`

Additionally:
- Removed unused MyFileName
  • Loading branch information
dschlaep committed Jan 28, 2025
1 parent b91dc3f commit 44f66d9
Show file tree
Hide file tree
Showing 9 changed files with 22 additions and 63 deletions.
5 changes: 3 additions & 2 deletions src/SW_R_lib.c
Original file line number Diff line number Diff line change
Expand Up @@ -992,13 +992,14 @@ SEXP sw_consts(void) {
"eFirst",
"eNCIn", "eNCInAtt", "eNCOutVars",
"eDomain",
"eModel", "eLog",
"eModel",
"eSite", "eLayers", "eSWRCp",
"eWeather", "eMarkovProb", "eMarkovCov", "eSky",
"eVegProd", "eVegEstab",
"eCarbon",
"eSoilwat",
"eOutput", "eOutputDaily", "eOutputWeekly", "eOutputMonthly", "eOutputYearly",
"eOutput", "eLog",
"eOutputDaily", "eOutputWeekly", "eOutputMonthly", "eOutputYearly",
"eOutputDaily_soil", "eOutputWeekly_soil", "eOutputMonthly_soil", "eOutputYearly_soil"
};

Expand Down
19 changes: 6 additions & 13 deletions src/rSW_Domain.c
Original file line number Diff line number Diff line change
Expand Up @@ -42,11 +42,6 @@



/* =================================================== */
/* Local Variables */
/* --------------------------------------------------- */
static char *MyFileName;

/* =================================================== */
/* Global Function Definitions */
/* --------------------------------------------------- */
Expand Down Expand Up @@ -252,37 +247,35 @@ void onSet_SW_MDL(SEXP SW_MDL, LOG_INFO* LogInfo) {
TimeInt d;
char enddyval[6], errstr[MAX_ERROR];

MyFileName = SoilWatDomain.SW_PathInputs.txtInFiles[eModel];

if (!IS_S4_OBJECT(SW_MDL)) {
LogError(LogInfo, LOGERROR, "%s: No input.", MyFileName);
LogError(LogInfo, LOGERROR, "modelrun.in: missing input.");
return; // Exit function prematurely due to error
}

PROTECT(StartYear = GET_SLOT(SW_MDL, install("StartYear")));
if (INTEGER(StartYear)[0] < 0) {
LogError(LogInfo, LOGERROR, "%s: Negative start year (%d)", MyFileName, INTEGER(StartYear)[0]);
LogError(LogInfo, LOGERROR, "Negative start year (%d)", INTEGER(StartYear)[0]);

UNPROTECT(1);
return; // Exit function prematurely due to error
}
m->startyr = INTEGER(StartYear)[0];
PROTECT(EndYear = GET_SLOT(SW_MDL, install("EndYear")));
if (isNull(EndYear) || INTEGER(EndYear)[0] == NA_INTEGER) {
LogError(LogInfo, LOGERROR, "%s: Ending year not found.", MyFileName);
LogError(LogInfo, LOGERROR, "Ending year not found.");

UNPROTECT(2);
return; // Exit function prematurely due to error
}
if (INTEGER(EndYear)[0] < 0) {
LogError(LogInfo, LOGERROR, "%s: Negative ending year (%d)", MyFileName, INTEGER(EndYear)[0]);
LogError(LogInfo, LOGERROR, "Negative ending year (%d)", INTEGER(EndYear)[0]);

UNPROTECT(2);
return; // Exit function prematurely due to error
}
m->endyr = INTEGER(EndYear)[0];
if (m->endyr < m->startyr) {
LogError(LogInfo, LOGERROR, "%s: Start Year > End Year", MyFileName);
LogError(LogInfo, LOGERROR, "Start Year > End Year");

UNPROTECT(2);
return; // Exit function prematurely due to error
Expand All @@ -303,7 +296,7 @@ void onSet_SW_MDL(SEXP SW_MDL, LOG_INFO* LogInfo) {
fhemi = TRUE;

if (!(fstartdy && fenddy && fhemi)) {
snprintf(errstr, MAX_ERROR, "\nNot found in %s:\n", MyFileName);
snprintf(errstr, MAX_ERROR, "\nNot found in inputs:\n");
if (!fstartdy) {
strcat(errstr, "\tStart Day - using 1\n");
m->startstart = 1;
Expand Down
4 changes: 3 additions & 1 deletion src/rSW_Files.c
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,9 @@ void onSet_SW_F(SEXP SW_F_construct, LOG_INFO* LogInfo) {
free(SoilWatDomain.SW_PathInputs.txtInFiles[i]);
}
for (i = 0; i < j; i++) {
SoilWatDomain.SW_PathInputs.txtInFiles[i] = Str_Dup(CHAR(STRING_ELT(FilesIn,i)), LogInfo);
// txtInFiles is unused if values set by rSOILWAT2
// SoilWatDomain.SW_PathInputs.txtInFiles[i] = Str_Dup(CHAR(STRING_ELT(FilesIn,i)), LogInfo);
SoilWatDomain.SW_PathInputs.txtInFiles[i] = NULL;
if(LogInfo->stopRun) {
UNPROTECT(2); // Unprotect the two protected variables before exiting
return; // Exit function prematurely
Expand Down
7 changes: 0 additions & 7 deletions src/rSW_Output.c
Original file line number Diff line number Diff line change
Expand Up @@ -40,12 +40,6 @@



/* =================================================== */
/* Module-Level Variables */
/* --------------------------------------------------- */
static char *MyFileName;


/* =================================================== */
/* Global Function Definitions */
/* --------------------------------------------------- */
Expand All @@ -69,7 +63,6 @@ void onSet_SW_OUT(SEXP OUT, LOG_INFO* LogInfo) {
#ifdef RSWDEBUG
if (debug) sw_printf("onSet_SW_OUT: start ...");
#endif
MyFileName = SoilWatDomain.SW_PathInputs.txtInFiles[eOutput];

PROTECT(sep = GET_SLOT(OUT, install("outputSeparator")));

Expand Down
29 changes: 8 additions & 21 deletions src/rSW_Site.c
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,6 @@
/* Local Variables */
/* --------------------------------------------------- */

static char *MyFileName;


static char *cSW_SIT[] = {
"SWClimits", "ModelFlags", "ModelCoefficients",
"SnowSimulationParameters", "DrainageCoefficient", "EvaporationCoefficients",
Expand Down Expand Up @@ -126,9 +123,6 @@ static void onSet_SW_LYR(SEXP SW_LYR, LOG_INFO* LogInfo) {
soildensity, imperm, soiltemp, f_gravel, som_frac;
double *p_Layers;

/* note that Files.read() must be called prior to this. */
MyFileName = SoilWatDomain.SW_PathInputs.txtInFiles[eLayers];

j = nrows(SW_LYR);
p_Layers = REAL(SW_LYR);
columns = ncols(SW_LYR);
Expand All @@ -139,8 +133,8 @@ static void onSet_SW_LYR(SEXP SW_LYR, LOG_INFO* LogInfo) {
LogError(
LogInfo,
LOGERROR,
"%s : Too few columns in layers specified (%d).\n",
MyFileName, columns
"soils.in : Too few columns in layers specified (%d).\n",
columns
);
return; // Exit function prematurely due to error
}
Expand Down Expand Up @@ -181,9 +175,9 @@ static void onSet_SW_LYR(SEXP SW_LYR, LOG_INFO* LogInfo) {
LogError(
LogInfo,
LOGERROR,
"%s : Too many layers specified (%d).\n"
"soils.in : Too many layers specified (%d).\n"
"Maximum number of layers is %d\n",
MyFileName, lyrno + 1, MAX_LAYERS
lyrno + 1, MAX_LAYERS
);
return; // Exit function prematurely due to error
}
Expand Down Expand Up @@ -258,16 +252,13 @@ static void onSet_SW_SWRCp(SEXP SW_SWRCp, LOG_INFO* LogInfo) {
int i, k;
double *p_SWRCp;

/* note that Files.read() must be called prior to this. */
MyFileName = SoilWatDomain.SW_PathInputs.txtInFiles[eSWRCp];

/* Check that we have n = `SWRC_PARAM_NMAX` values per layer */
if (ncols(SW_SWRCp) != SWRC_PARAM_NMAX) {
LogError(
LogInfo,
LOGERROR,
"%s : Bad number of SWRC parameters %d -- must be %d.\n",
MyFileName, ncols(SW_SWRCp), SWRC_PARAM_NMAX
"swrcp.in : Bad number of SWRC parameters %d -- must be %d.\n",
ncols(SW_SWRCp), SWRC_PARAM_NMAX
);
return; // Exit function prematurely due to error
}
Expand All @@ -277,9 +268,9 @@ static void onSet_SW_SWRCp(SEXP SW_SWRCp, LOG_INFO* LogInfo) {
LogError(
LogInfo,
LOGERROR,
"%s : Number of layers with SWRC parameters (%d) "
"swrcp.in : Number of layers with SWRC parameters (%d) "
"must match number of soil layers (%d)\n",
MyFileName, nrows(SW_SWRCp), SoilWatRun.Site.n_layers
nrows(SW_SWRCp), SoilWatRun.Site.n_layers
);
return; // Exit function prematurely due to error
}
Expand Down Expand Up @@ -400,8 +391,6 @@ SEXP onGet_SW_SIT(void) {
char *cTranspirationRegions[] = { "ndx", "layer" };
int *p_transp; // ideally `LyrIndex` so that same type as `_TranspRgnBounds`, but R API INTEGER() is signed

MyFileName = SoilWatDomain.SW_PathInputs.txtInFiles[eSite];

PROTECT(swSite = MAKE_CLASS("swSite"));
PROTECT(SW_SIT = NEW_OBJECT(swSite));

Expand Down Expand Up @@ -579,8 +568,6 @@ void onSet_SW_SIT(SEXP SW_SIT, LOG_INFO* LogInfo) {
int debug = 0;
#endif

MyFileName = SoilWatDomain.SW_PathInputs.txtInFiles[eSite];

#ifdef RSWDEBUG
if (debug) sw_printf("'onSet_SW_SIT':");
#endif
Expand Down
8 changes: 0 additions & 8 deletions src/rSW_Sky.c
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,6 @@
#include <Rdefines.h>


/* =================================================== */
/* Local Variables */
/* --------------------------------------------------- */
static char *MyFileName;


/* =================================================== */
/* Global Function Definitions */
/* --------------------------------------------------- */
Expand Down Expand Up @@ -94,8 +88,6 @@ void onSet_SW_SKY(SEXP sxp_SW_SKY) {
PROTECT(sxp_SW_SKY);
p_Cloud = REAL(GET_SLOT(sxp_SW_SKY, install("Cloud")));

MyFileName = SoilWatDomain.SW_PathInputs.txtInFiles[eSky];

for (i = 0; i < 12; i++) { //i=columns
v->cloudcov[i] = p_Cloud[0 + k * i];
v->windspeed[i] = p_Cloud[1 + k * i];
Expand Down
2 changes: 0 additions & 2 deletions src/rSW_SoilWater.c
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@
/* =================================================== */
/* Local Variables */
/* --------------------------------------------------- */
static char *MyFileName;
static int swcdataIndex;


Expand Down Expand Up @@ -102,7 +101,6 @@ void onSet_SW_SWC(SEXP SWC, LOG_INFO* LogInfo) {
SEXP swcFirstYear;
SEXP swcMethod;

MyFileName = SoilWatDomain.SW_PathInputs.txtInFiles[eSoilwat];
LyrIndex i;
ForEachSoilLayer(i, SoilWatRun.Site.n_layers)
v->avgLyrTemp[i] = SoilWatRun.Site.soils.avgLyrTempInit[i];
Expand Down
5 changes: 0 additions & 5 deletions src/rSW_VegProd.c
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,6 @@ vegetation production parameter information.
/* =================================================== */
/* Local Variables */
/* --------------------------------------------------- */
static char *MyFileName;


static char *cVegProd_names[] = {
"veg_method", "Composition", "Albedo", "CanopyHeight",
"VegetationInterceptionParameters", "LitterInterceptionParameters",
Expand Down Expand Up @@ -439,8 +436,6 @@ void onSet_SW_VPD(SEXP SW_VPD, LOG_INFO* LogInfo) {
SEXP CO2Coefficients;
double *p_Grasslands, *p_Shrublands, *p_Forest, *p_Forb;

MyFileName = SoilWatDomain.SW_PathInputs.txtInFiles[eVegProd];

PROTECT(veg_method = GET_SLOT(SW_VPD, install(cVegProd_names[0])));
v->veg_method = INTEGER(veg_method)[0];

Expand Down
6 changes: 2 additions & 4 deletions src/rSW_Weather.c
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@
/* =================================================== */
/* Local Variables */
/* --------------------------------------------------- */
static char *MyFileName;

static char *cSW_WTH_names[] = {
"MonthlyScalingParams",
Expand Down Expand Up @@ -220,7 +219,6 @@ void onSet_SW_WTH_setup(SEXP SW_WTH, LOG_INFO* LogInfo) {
double *p_MonthlyValues;
int *p_dailyInputFlags;

MyFileName = SoilWatDomain.SW_PathInputs.txtInFiles[eWeather];

// Copy weather prefix from PathInfo to Weather within `SoilWatRun`
strcpy(SoilWatRun.Weather.name_prefix, SoilWatDomain.SW_PathInputs.txtWeatherPrefix);
Expand Down Expand Up @@ -286,10 +284,10 @@ void onSet_SW_WTH_setup(SEXP SW_WTH, LOG_INFO* LogInfo) {
LogError(
logfp,
LOGERROR,
"%s : Model year (%d) starts before weather files (%d)"
"Model year (%d) starts before weather files (%d)"
" and weather generator turned off.\n"
" Please synchronize the years or set up the weather generator files",
MyFileName, SW_Model.startyr, w->startYear
SW_Model.startyr, w->startYear
);
}
*/
Expand Down

0 comments on commit 44f66d9

Please sign in to comment.