Skip to content

Commit

Permalink
Merge pull request #83 from Burke-Lauenroth-Lab/feature_AddDocumentat…
Browse files Browse the repository at this point in the history
…ionAndTesting

- cleaner code
- defined swprintf to be used both by rSOILWAT and SOILWAT2-standalone code
- improved makefile
- eliminated (almost all) compiler warnings
- improved handling of unit tests (i.e., don't include any more source files in the unit test files as we did initially)
  • Loading branch information
dschlaep committed Nov 22, 2017
2 parents ca87d4f + 9aa08d2 commit 2a9f262
Show file tree
Hide file tree
Showing 123 changed files with 14,431 additions and 2,246 deletions.
5 changes: 2 additions & 3 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ compiler:
- clang
- gcc
script:
- make compilel
- make gtest
- ./sw_test
- make bin
- make test test_run
- make cleaner
2 changes: 1 addition & 1 deletion Doxyfile
Original file line number Diff line number Diff line change
Expand Up @@ -713,7 +713,7 @@ LAYOUT_FILE =
# LATEX_BIB_STYLE. To use this feature you need bibtex and perl available in the
# search path. See also \cite for info how to create references.

CITE_BIB_FILES =
CITE_BIB_FILES = SOILWAT2.bib

#---------------------------------------------------------------------------
# Configuration options related to warning and progress messages
Expand Down
9 changes: 9 additions & 0 deletions SOILWAT2.bib
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@

@Article{Cheng1978,
author = "R. Cheng",
title = "Generating Beta Variates with Nonintegral Shape Parameters",
journal = "Communications of the ACM",
volume = 21,
year = 1978,
pages = {317--322},
}
112 changes: 73 additions & 39 deletions SW_Control.c
Original file line number Diff line number Diff line change
Expand Up @@ -43,15 +43,18 @@
/* --------------------------------------------------- */
extern SW_MODEL SW_Model;
extern SW_VEGESTAB SW_VegEstab;
extern SW_SITE SW_Site;
extern SW_VEGPROD SW_VegProd;
#ifdef RSOILWAT
extern Bool useFiles;
extern SEXP InputData;
void SW_FLW_construct(void);
#endif


/* =================================================== */
/* Module-Level Declarations */
/* --------------------------------------------------- */
static void _read_inputs(void);
static void _begin_year(void);
static void _begin_day(void);
static void _end_day(void);
Expand All @@ -69,7 +72,7 @@ void SW_CTL_main(void) {

for (*cur_yr = SW_Model.startyr; *cur_yr <= SW_Model.endyr; (*cur_yr)++) {
SW_CTL_run_current_year();
}
}

#ifndef RSOILWAT
SW_OUT_close_files();
Expand All @@ -90,9 +93,6 @@ void SW_CTL_init_model(const char *firstfile) {
SW_OUT_construct();
SW_SWC_construct();
SW_FLW_construct();

_read_inputs();

}

void SW_CTL_run_current_year(void) {
Expand Down Expand Up @@ -154,44 +154,78 @@ static void _collect_values(void) {

}

static void _read_inputs(void) {
void SW_CTL_read_inputs_from_disk(void) {
int debug = 0;

if (debug) swprintf("'SW_CTL_read_inputs_from_disk': Read input from disk:");
SW_F_read(NULL);
if (debug) swprintf(" 'files'");

SW_MDL_read();
if (debug) swprintf(" > 'model'");

SW_WTH_read();
if (debug) swprintf(" > 'weather'");

SW_VPD_read();
if (debug) swprintf(" > 'veg'");

SW_SIT_read();
if (debug) swprintf(" > 'site'");

SW_VES_read();
if (debug) swprintf(" > 'establishment'");

SW_OUT_read();
if (debug) swprintf(" > 'ouput'");

SW_SWC_read();
if (debug) swprintf(" > 'swc'");
if (debug) swprintf(" completed.\n");
}


void SW_CTL_obtain_inputs(void) {
/*=======================================================*/

#ifndef RSOILWAT
SW_F_read(NULL );
SW_MDL_read();
SW_WTH_read();
SW_VPD_read();
SW_SIT_read();
SW_VES_read();
SW_OUT_read();
SW_SWC_read();
SW_CTL_read_inputs_from_disk();

#else
if (useFiles) { //Read in the data and set it
SW_F_read(NULL );
SW_MDL_read();
SW_WTH_read();
SW_VPD_read();
SW_SIT_read();
SW_VES_read();
SW_OUT_read();
SW_SWC_read();
if (useFiles) {
SW_CTL_read_inputs_from_disk();

} else { //Use R data to set the data
onSet_SW_F(GET_SLOT(InputData,install("files")));
//Rprintf("swFiles\n");
onSet_SW_MDL(GET_SLOT(InputData,install("years")));
//Rprintf("swYears\n");
onSet_SW_WTH(GET_SLOT(InputData,install("weather")));
//Rprintf("swWeather\n");
onSet_SW_VPD(GET_SLOT(InputData,install("prod")));
//Rprintf("swProd\n");
onSet_SW_SIT(GET_SLOT(InputData,install("site")));
//Rprintf("swSite\n");
onSet_SW_VES(GET_SLOT(InputData,install("estab")));
//Rprintf("swEstab\n");
onSet_SW_OUT(GET_SLOT(InputData,install("output")));
//Rprintf("swOutput\n");
onSet_SW_SWC(GET_SLOT(InputData,install("swc")));
//Rprintf("swSWC\n");
int debug = 0;

if (debug) swprintf("'SW_CTL_obtain_inputs': Copy input from 'InputData':");

onSet_SW_F(GET_SLOT(InputData, install("files")));
if (debug) swprintf(" 'files'");

onSet_SW_MDL(GET_SLOT(InputData, install("years")));
if (debug) swprintf(" > 'model'");

onSet_SW_WTH(GET_SLOT(InputData, install("weather")));
if (debug) swprintf(" > 'weather'");

onSet_SW_VPD(GET_SLOT(InputData, install("prod")));
if (debug) swprintf(" > 'veg'");

onSet_SW_SIT(GET_SLOT(InputData, install("site")));
if (debug) swprintf(" > 'site'");

onSet_SW_VES(GET_SLOT(InputData, install("estab")));
if (debug) swprintf(" > 'establishment'");

onSet_SW_OUT(GET_SLOT(InputData, install("output")));
if (debug) swprintf(" > 'ouput'");



onSet_SW_SWC(GET_SLOT(InputData, install("swc")));
if (debug) swprintf(" > 'swc'");
if (debug) swprintf(" completed.\n");
}
#endif
}
Expand Down
2 changes: 2 additions & 0 deletions SW_Control.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@
#define SW_CONTROL_H

void SW_CTL_init_model(const char *firstfile);
void SW_CTL_obtain_inputs(void);
void SW_CTL_read_inputs_from_disk(void);
void SW_CTL_main(void); /* main controlling loop for SOILWAT */
void SW_CTL_run_current_year(void);

Expand Down
2 changes: 1 addition & 1 deletion SW_Files.c
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ void SW_F_read(const char *s) {

if (fileno < eEndFile - 1) {
CloseFile(&f);
LogError(stdout, LOGFATAL, "Too few files (%d) in %s", fileno, MyFileName);
LogError(logfp, LOGFATAL, "Too few files (%d) in %s", fileno, MyFileName);
}

CloseFile(&f);
Expand Down
Loading

0 comments on commit 2a9f262

Please sign in to comment.