From 3f7b85b614181cc90b4c0aba37dc7d70cd3fc62e Mon Sep 17 00:00:00 2001 From: Ashish Tiwari Date: Wed, 10 May 2017 17:23:28 -0600 Subject: [PATCH 001/111] Changes for adding Soilwat var output in stepwat location for all iteration --- .cproject | 102 ++++++++++++++--------------------------------------- .project | 1 + ST_main.c | 10 ++++++ ST_stats.c | 83 ++++++++++++++++++++++++++++++++++++++++++- 4 files changed, 119 insertions(+), 77 deletions(-) diff --git a/.cproject b/.cproject index b1fb9794..9d9bb911 100644 --- a/.cproject +++ b/.cproject @@ -1,87 +1,40 @@ - - + + - - + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + - - - - - - - - - - - - - @@ -102,14 +52,14 @@ + + + - - - - - - - + + + + diff --git a/.project b/.project index 1003b227..9a6898d1 100644 --- a/.project +++ b/.project @@ -22,5 +22,6 @@ org.eclipse.cdt.core.cnature org.eclipse.cdt.managedbuilder.core.managedBuildNature org.eclipse.cdt.managedbuilder.core.ScannerConfigNature + org.eclipse.cdt.core.ccnature diff --git a/ST_main.c b/ST_main.c index fe2a8eb5..2928af8e 100644 --- a/ST_main.c +++ b/ST_main.c @@ -60,6 +60,8 @@ extern Bool isPartialSoilwatOutput; void stat_Output_AllMorts( void) ; void stat_Output_AllBmass(void) ; + void stat_Output_AllSoilwatVariables(void); + void runGrid( void ); //for the grid... declared in ST_grid.c void _kill_annuals(void); @@ -280,7 +282,15 @@ int main(int argc, char **argv) { output_Mort_Yearly(); if (UseSoilwat) + { + stat_Output_AllSoilwatVariables(); + } + + if (UseSoilwat) + { SXW_Reset(); + } + } /* end model run for this iteration*/ diff --git a/ST_stats.c b/ST_stats.c index 42633934..4db0194e 100644 --- a/ST_stats.c +++ b/ST_stats.c @@ -25,6 +25,8 @@ #include "filefuncs.h" #include "myMemory.h" #include "ST_structs.h" +#include "sxw.h" + extern SXW_t SXW; /************ External Variable Declarations ***************/ /***********************************************************/ @@ -45,6 +47,10 @@ void stat_Output_YrMorts( void ) ; void stat_Output_AllMorts( void) ; void stat_Output_AllBmass(void) ; + + //adding below function for adding modified soilwat output at stepwat location + void stat_Output_AllSoilwatVariables(void); + //Adding below two functions for creating grid cells avg values output file void stat_Output_AllBmassAvg(void) ; void stat_Output_AllCellAvgBmass(const char * filename); @@ -106,6 +112,7 @@ static RealF _get_gridcell_avg( struct accumulators_grid_cell_st *p); static RealF _get_gridcell_std( struct accumulators_grid_cell_st *p); static void _make_header( char *buf); static void _make_header_with_std( char *buf); +static void _make_header_for_soilwat(char *buf); /* I'm making this a macro because it gets called a lot, but /* note that the syntax checker is obviated, so make sure @@ -1290,7 +1297,6 @@ static RealF _get_gridcell_std(struct accumulators_grid_cell_st *p) } - /***********************************************************/ static void _make_header_with_std( char *buf) { @@ -1423,6 +1429,81 @@ static void _make_header( char *buf) { } +static void _make_header_for_soilwat(char *buf) +{ + + char fields[MAX_OUTFIELDS * 2][MAX_FIELDLEN + 1]; + char tbuf[80]; + + Int i, fc = 0; + + /* Set up headers */ + if (BmassFlags.yr) + strcpy(fields[fc++], "Year"); + + strcpy(fields[fc++], "surfaceTemp"); + + /* Put header line in global variable */ + for (i = 0; i < fc - 1; i++) + { + sprintf(tbuf, "%s%c", fields[i], BmassFlags.sep); + strcat(buf, tbuf); + } + sprintf(tbuf, "%s%c\n", fields[i], BmassFlags.sep); + strcat(buf, tbuf); + +} + +void stat_Output_AllSoilwatVariables(void) +{ + char buf[2048], tbuf[80], sep = BmassFlags.sep; + IntS yr; + GrpIndex rg; + SppIndex sp; + FILE *f; + + char filename[FILENAME_MAX]; + + sprintf(filename, "%s%0*d.csv", "test_soilwat_output", + Globals.mort.suffixwidth, Globals.currIter); + + if (DirExists(DirName(filename))) + { + strcpy(inbuf, filename); + if (!RemoveFiles(inbuf)) + printf("Can't remove old biomass output files %s\n", inbuf); + + } + else if (!MkDir(DirName(filename))) + { + printf("Can't make output path for yearly biomass files: %s\n", + DirName(filename)); + } + + f = OpenFile(filename, "w"); + + buf[0] = '\0'; + + if (BmassFlags.header) + { + _make_header_for_soilwat(buf); + fprintf(f, "%s", buf); + } + + + for (yr = 1; yr <= Globals.runModelYears; yr++) + { + *buf = '\0'; + if (BmassFlags.yr) + sprintf(buf, "%d%c", yr, sep); + + sprintf(buf, "%f", SXW.surfaceTemp); + + fprintf(f, "%s\n", buf); + } /* end of foreach year */ + CloseFile(&f); +} + #ifdef DEBUG_MEM void Stat_SetMemoryRefs(void) { From a0666c9e02a5b8912fa3effafa909e34f5a4a223 Mon Sep 17 00:00:00 2001 From: Ashish Tiwari Date: Wed, 10 May 2017 17:41:04 -0600 Subject: [PATCH 002/111] more changes --- ST_stats.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/ST_stats.c b/ST_stats.c index 4db0194e..4fda3aa5 100644 --- a/ST_stats.c +++ b/ST_stats.c @@ -1456,6 +1456,8 @@ static void _make_header_for_soilwat(char *buf) void stat_Output_AllSoilwatVariables(void) { + + printf("inside stat_Output_AllSoilwatVariables \n"); char buf[2048], tbuf[80], sep = BmassFlags.sep; IntS yr; GrpIndex rg; @@ -1464,9 +1466,11 @@ void stat_Output_AllSoilwatVariables(void) char filename[FILENAME_MAX]; - sprintf(filename, "%s%0*d.csv", "test_soilwat_output", + sprintf(filename, "%s%0*d.csv", "output/test_soilwat_output", Globals.mort.suffixwidth, Globals.currIter); + printf("inside stat_Output_AllSoilwatVariables filename:%s \n",filename); + if (DirExists(DirName(filename))) { strcpy(inbuf, filename); @@ -1490,6 +1494,7 @@ void stat_Output_AllSoilwatVariables(void) fprintf(f, "%s", buf); } + printf("inside stat_Output_AllSoilwatVariables buf:%s \n",buf); for (yr = 1; yr <= Globals.runModelYears; yr++) { From c029939f916617dad4575a31c1c64a0db0754bc6 Mon Sep 17 00:00:00 2001 From: BrendenBe1 Date: Tue, 13 Jun 2017 17:03:22 -0700 Subject: [PATCH 003/111] Altered code to create proper format for soilwat CSV --- ST_main.c | 8 ++-- ST_stats.c | 119 +++++++++++++++++++++++++++++++---------------------- 2 files changed, 73 insertions(+), 54 deletions(-) diff --git a/ST_main.c b/ST_main.c index 2928af8e..46ba6578 100644 --- a/ST_main.c +++ b/ST_main.c @@ -59,7 +59,7 @@ extern Bool isPartialSoilwatOutput; //void stat_Output_YrMorts( void ) ; void stat_Output_AllMorts( void) ; void stat_Output_AllBmass(void) ; - + void stat_Output_AllSoilwatVariables(void); void runGrid( void ); //for the grid... declared in ST_grid.c @@ -229,7 +229,7 @@ int main(int argc, char **argv) { /* printf("Iter=%d, Year=%d\n", iter, year); */ Globals.currYear = year; - rgroup_Establish(); + rgroup_Establish(); Env_Generate(); @@ -279,7 +279,7 @@ int main(int argc, char **argv) { } if (MortFlags.yearly) - output_Mort_Yearly(); + output_Mort_Yearly(); // writes yearly file if (UseSoilwat) { @@ -550,7 +550,7 @@ static void check_log(void) { if (logfp != stdout) { if (logged && !QuietMode) fprintf(progfp, "\nCheck logfile for error messages.\n"); - + CloseFile(&logfp); } diff --git a/ST_stats.c b/ST_stats.c index 4fda3aa5..f26d0c20 100644 --- a/ST_stats.c +++ b/ST_stats.c @@ -24,9 +24,11 @@ #include "ST_steppe.h" #include "filefuncs.h" #include "myMemory.h" +#include "sw_src/SW_Site.h" #include "ST_structs.h" #include "sxw.h" extern SXW_t SXW; + extern SW_SITE SW_Site; /************ External Variable Declarations ***************/ /***********************************************************/ @@ -54,9 +56,9 @@ //Adding below two functions for creating grid cells avg values output file void stat_Output_AllBmassAvg(void) ; void stat_Output_AllCellAvgBmass(const char * filename); - void stat_Output_Seed_Dispersal(const char * filename, const char sep, Bool makeHeader); + void stat_Output_Seed_Dispersal(const char * filename, const char sep, Bool makeHeader); void stat_free_mem( void ) ; - + void stat_Load_Accumulators( int cell, int year ); //these accumulators were added to use in the gridded option... there overall purpose is to save/load data to allow steppe to output correctly when running multiple grid cells void stat_Save_Accumulators( int cell, int year ); void stat_Free_Accumulators( void ); @@ -77,10 +79,10 @@ struct stat_st { *_Spp, *_Indv, *_Smort, *_Sestab, *_Sreceived; typedef struct { - struct accumulators_st *dist, *temp, *ppt, **grp1, **gsize, **gpr2, + struct accumulators_st *dist, *temp, *ppt, **grp1, **gsize, **gpr2, **gmort, **gestab, **spp, **indv, **smort, **sestab, **sreceived; } accumulators_grid_st; - + accumulators_grid_st *grid_Stat; @@ -125,7 +127,7 @@ static void _make_header_for_soilwat(char *buf); } // quick macro to make life easier in the load/save accumulators functions... it just copies the data of p into v -// static void _copy_over(struct accumulators_st *p, struct accumulators_st *v) +// static void _copy_over(struct accumulators_st *p, struct accumulators_st *v) #define _copy_over(p, v) { \ (p)->sum = (v)->sum; \ (p)->sum_sq = (v)->sum_sq; \ @@ -184,7 +186,7 @@ void stat_Collect( Int year ) { RGroup[rg]->pr); } } - + if (BmassFlags.sppb) { ForEachSpecies(sp) { bmass = (double) Species_GetBiomass(sp); @@ -427,13 +429,13 @@ static void _init( void) { void stat_Init_Accumulators( void ) { //allocates memory for all of the grid accumulators grid_Stat = Mem_Calloc(Globals.nCells, sizeof(accumulators_grid_st), "stat_Init_Accumulators()"); - + int i, j; for( i = 0; i < Globals.nCells; i++) { if (BmassFlags.dist) grid_Stat[i].dist = Mem_Calloc(Globals.runModelYears, sizeof(struct accumulators_st), "stat_Init_Accumulators()"); if (BmassFlags.ppt) grid_Stat[i].ppt = Mem_Calloc(Globals.runModelYears, sizeof(struct accumulators_st), "stat_Init_Accumulators()"); if (BmassFlags.tmp) grid_Stat[i].temp = Mem_Calloc(Globals.runModelYears, sizeof(struct accumulators_st), "stat_Init_Accumulators()"); - + if (BmassFlags.grpb) { grid_Stat[i].grp1 = Mem_Calloc(Globals.runModelYears, sizeof(struct accumulators_st*), "stat_Init_Accumulators()"); // gave grp and gpr numbers attached to them so I wouldn't mix them up lol... bad (confusing) variable names on part of the original creator. if (BmassFlags.size) grid_Stat[i].gsize = Mem_Calloc(Globals.runModelYears, sizeof(struct accumulators_st), "stat_Init_Accumulators()"); @@ -462,10 +464,10 @@ void stat_Init_Accumulators( void ) { } } - if(UseSeedDispersal && UseGrid) + if(UseSeedDispersal && UseGrid) grid_Stat[i].sreceived = Mem_Calloc(Globals.runModelYears, sizeof(struct accumulators_st*), "stat_Init_Accumulators()"); - - + + for( j = 0; j < Globals.runModelYears; j++) { if (BmassFlags.grpb) { grid_Stat[i].grp1[j] = Mem_Calloc(Globals.grpCount, sizeof(struct accumulators_st), "stat_Init_Accumulators()"); @@ -493,7 +495,7 @@ void stat_Load_Accumulators(int cell, int year) { IntS age; int yr; yr = year - 1; - + if(MortFlags.species) { SppIndex sp; @@ -518,8 +520,8 @@ void stat_Load_Accumulators(int cell, int year) { if (BmassFlags.tmp) _copy_over(&_Temp.s[yr], &grid_Stat[cell].temp[yr]); if (BmassFlags.ppt) _copy_over(&_Ppt.s[yr], &grid_Stat[cell].ppt[yr]); - if (BmassFlags.dist) _copy_over(&_Dist.s[yr], &grid_Stat[cell].dist[yr]); - + if (BmassFlags.dist) _copy_over(&_Dist.s[yr], &grid_Stat[cell].dist[yr]); + if(BmassFlags.grpb) { GrpIndex c; ForEachGroup(c) { @@ -528,7 +530,7 @@ void stat_Load_Accumulators(int cell, int year) { if (BmassFlags.pr) _copy_over(&_Gpr[c].s[yr], &grid_Stat[cell].gpr2[yr][c]); } } - + if(BmassFlags.sppb) { SppIndex s; ForEachSpecies(s) { @@ -547,7 +549,7 @@ void stat_Load_Accumulators(int cell, int year) { /***********************************************************/ void stat_Save_Accumulators(int cell, int year) { //saves the accumulators for the cell at the given year - + if (firsttime) { firsttime = FALSE; _init(); @@ -555,10 +557,10 @@ void stat_Save_Accumulators(int cell, int year) { IntS age; int yr; yr = year - 1; - + if(MortFlags.species) { SppIndex sp; - + ForEachSpecies(sp) { if ( !Species[sp]->use_me) continue; _copy_over(&grid_Stat[cell].sestab[sp][0], &_Sestab[sp].s[0]); @@ -576,7 +578,7 @@ void stat_Save_Accumulators(int cell, int year) { _copy_over(&grid_Stat[cell].gmort[rg][age], &_Gmort[rg].s[age]); } } - + if (BmassFlags.tmp) _copy_over(&grid_Stat[cell].temp[yr], &_Temp.s[yr]); if (BmassFlags.ppt) _copy_over(&grid_Stat[cell].ppt[yr], &_Ppt.s[yr]); if (BmassFlags.dist) _copy_over(&grid_Stat[cell].dist[yr], &_Dist.s[yr]); @@ -589,7 +591,7 @@ void stat_Save_Accumulators(int cell, int year) { if (BmassFlags.pr) _copy_over(&grid_Stat[cell].gpr2[yr][c], &_Gpr[c].s[yr]); } } - + if(BmassFlags.sppb) { SppIndex s; ForEachSpecies(s) { @@ -625,11 +627,11 @@ void stat_Free_Accumulators( void ) { if(UseSeedDispersal && UseGrid) Mem_Free(grid_Stat[i].sreceived[j]); } - + if (BmassFlags.dist) Mem_Free(grid_Stat[i].dist); - if (BmassFlags.ppt) Mem_Free(grid_Stat[i].ppt); + if (BmassFlags.ppt) Mem_Free(grid_Stat[i].ppt); if (BmassFlags.tmp) Mem_Free(grid_Stat[i].temp); - + if(BmassFlags.grpb) { Mem_Free(grid_Stat[i].grp1);// gave grp and gpr numbers attached to them so I wouldn't mix them up lol... bad (confusing) variable names on part of the original creator. if (BmassFlags.size) Mem_Free(grid_Stat[i].gsize); @@ -669,7 +671,7 @@ void stat_free_mem( void ) { //frees memory allocated in this module GrpIndex gp; SppIndex sp; - + if(BmassFlags.grpb) ForEachGroup(gp) { Mem_Free(_Grp[gp].s); @@ -681,11 +683,11 @@ void stat_free_mem( void ) { Mem_Free(_Spp[sp].s); if(BmassFlags.indv) Mem_Free(_Indv[sp].s); } - + if (BmassFlags.dist) Mem_Free(_Dist.s); - if (BmassFlags.ppt) Mem_Free(_Ppt.s); + if (BmassFlags.ppt) Mem_Free(_Ppt.s); if (BmassFlags.tmp) Mem_Free(_Temp.s); - + if(BmassFlags.grpb) { Mem_Free(_Grp); if (BmassFlags.size) Mem_Free(_Gsize); @@ -719,7 +721,7 @@ void stat_free_mem( void ) { Mem_Free(_Sreceived); } - + } /***********************************************************/ @@ -863,7 +865,7 @@ void stat_Output_AllMorts( void) { for(age=0; age < Globals.Max_Age; age++) { fprintf(f,"%d", age+1); if (MortFlags.group) { - ForEachGroup(rg) + ForEachGroup(rg) fprintf(f,"%c%5.1f", sep, ( age < GrpMaxAge(rg) ) ? _get_avg(&_Gmort[rg].s[age]) : 0.); @@ -1215,16 +1217,16 @@ void stat_Output_Seed_Dispersal(const char * filename, const char sep, Bool make for( yr=1; yr<= Globals.runModelYears; yr++) { *buf = '\0'; - + sprintf(buf, "%d%c", yr, sep); - + ForEachSpecies(sp) { sprintf(tbuf, "%f%c%f%c", _get_avg( &_Sreceived[sp].s[yr-1]), sep, _get_std( &_Sreceived[sp].s[yr-1]), sep); strcat(buf, tbuf); } fprintf(f, "%s\n", buf); - } + } CloseFile(&f); } @@ -1429,6 +1431,7 @@ static void _make_header( char *buf) { } +// helper function called by stat_Output_AllSoilwatVariables to create the CSV column names static void _make_header_for_soilwat(char *buf) { @@ -1441,7 +1444,13 @@ static void _make_header_for_soilwat(char *buf) if (BmassFlags.yr) strcpy(fields[fc++], "Year"); - strcpy(fields[fc++], "surfaceTemp"); + // create a column for each layer in the csv + int num_layers; + for(num_layers = 1; num_layers <= SW_Site.n_layers; num_layers++){ + char colName[20]; // create array to hold string + snprintf(colName, sizeof colName, "Layer %d", num_layers); // concatenate layer number to word "layer" + strcpy(fields[fc++], colName); // store column layer + } /* Put header line in global variable */ for (i = 0; i < fc - 1; i++) @@ -1454,23 +1463,23 @@ static void _make_header_for_soilwat(char *buf) } +// store soilwat values in a csv void stat_Output_AllSoilwatVariables(void) { - printf("inside stat_Output_AllSoilwatVariables \n"); + //printf("inside stat_Output_AllSoilwatVariables \n"); char buf[2048], tbuf[80], sep = BmassFlags.sep; IntS yr; + int curYearInt; GrpIndex rg; SppIndex sp; FILE *f; char filename[FILENAME_MAX]; - sprintf(filename, "%s%0*d.csv", "output/test_soilwat_output", + sprintf(filename, "%s%0*d.csv", "output/SoilWater_output", Globals.mort.suffixwidth, Globals.currIter); - printf("inside stat_Output_AllSoilwatVariables filename:%s \n",filename); - if (DirExists(DirName(filename))) { strcpy(inbuf, filename); @@ -1490,22 +1499,32 @@ void stat_Output_AllSoilwatVariables(void) if (BmassFlags.header) { - _make_header_for_soilwat(buf); + _make_header_for_soilwat(buf); // make column names fprintf(f, "%s", buf); } - printf("inside stat_Output_AllSoilwatVariables buf:%s \n",buf); - - for (yr = 1; yr <= Globals.runModelYears; yr++) - { - *buf = '\0'; - if (BmassFlags.yr) - sprintf(buf, "%d%c", yr, sep); - - sprintf(buf, "%f", SXW.surfaceTemp); - - fprintf(f, "%s\n", buf); - } /* end of foreach year */ + int layerLoop; + // loop through amount of years + // TODO: see where it tells it to only write 5 files (1 per iteration) + for(layerLoop = 0; layerLoop < SW_Site.n_layers; layerLoop++){ + for (yr = 1; yr <= Globals.runModelYears; yr++) + { + *buf = '\0'; + + // get year to fill in year column in csv + if (BmassFlags.yr) + curYearInt = yr; + + // store soilwater values in buffer + //sprintf(buf, "%f", SXW.swc[yr]); + //SXW.swc[Ilp(i,p)] + sprintf(buf, "%f", SXW.swc[Ilp(layerLoop, yr)]); + + // write values to csv + // , in fprintf means column so %d,%s means put %d value in col 1 and %s value in col 2 + fprintf(f, "%d,%s\n", curYearInt, buf); + } /* end of foreach year */ + } CloseFile(&f); } From ffb2bb0928b4f83cc9c55bc1882b9aadedf5a071 Mon Sep 17 00:00:00 2001 From: BrendenBe1 Date: Wed, 14 Jun 2017 16:48:20 -0700 Subject: [PATCH 004/111] Changed SOILWAT output csv layout to always have max layers --- ST_stats.c | 40 +++++++++++++++++++--------------------- 1 file changed, 19 insertions(+), 21 deletions(-) diff --git a/ST_stats.c b/ST_stats.c index f26d0c20..2d350e1b 100644 --- a/ST_stats.c +++ b/ST_stats.c @@ -1446,7 +1446,7 @@ static void _make_header_for_soilwat(char *buf) // create a column for each layer in the csv int num_layers; - for(num_layers = 1; num_layers <= SW_Site.n_layers; num_layers++){ + for(num_layers = 1; num_layers <= MAX_LAYERS; num_layers++){ // create amount of columns equal to max layers for ease with inserting data char colName[20]; // create array to hold string snprintf(colName, sizeof colName, "Layer %d", num_layers); // concatenate layer number to word "layer" strcpy(fields[fc++], colName); // store column layer @@ -1504,26 +1504,24 @@ void stat_Output_AllSoilwatVariables(void) } int layerLoop; - // loop through amount of years - // TODO: see where it tells it to only write 5 files (1 per iteration) - for(layerLoop = 0; layerLoop < SW_Site.n_layers; layerLoop++){ - for (yr = 1; yr <= Globals.runModelYears; yr++) - { - *buf = '\0'; - - // get year to fill in year column in csv - if (BmassFlags.yr) - curYearInt = yr; - - // store soilwater values in buffer - //sprintf(buf, "%f", SXW.swc[yr]); - //SXW.swc[Ilp(i,p)] - sprintf(buf, "%f", SXW.swc[Ilp(layerLoop, yr)]); - - // write values to csv - // , in fprintf means column so %d,%s means put %d value in col 1 and %s value in col 2 - fprintf(f, "%d,%s\n", curYearInt, buf); - } /* end of foreach year */ + int checkVals; + + int testingLayers = 0; + + // loop for entering data to csv. for each year it gets the value at all layers then inputs data row by row + for (yr = 1; yr <= Globals.runModelYears; yr++){ + float layerVals[446]; + for(layerLoop = 0; layerLoop < SW_Site.n_layers; layerLoop++){ + layerVals[layerLoop] = SXW.swc[Ilp(layerLoop, yr)]; + testingLayers++; + } + // write to file. this is reason set layers to MAX_LAYERS instead of layers actually used since it would be too hard to format the fprintf + fprintf(f, "%d,%f,%f,%f,%f,%f,%f,%f,%f,%f,%f,%f,%f,%f,%f,%f,%f,%f,%f,%f,%f,%f,%f,%f,%f,%f\n", + yr, layerVals[0], layerVals[1], layerVals[2], layerVals[3], layerVals[4], layerVals[5], layerVals[6], + layerVals[7], layerVals[8], layerVals[9], layerVals[10], layerVals[11], layerVals[12], layerVals[13], + layerVals[14], layerVals[15], layerVals[16], layerVals[17], layerVals[18], layerVals[19], layerVals[20], + layerVals[21], layerVals[22], layerVals[23], layerVals[24]); + } CloseFile(&f); } From 0ce363afe4134f1c746ba18d65311d5d01a62479 Mon Sep 17 00:00:00 2001 From: BrendenBe1 Date: Thu, 15 Jun 2017 15:51:01 -0700 Subject: [PATCH 005/111] Added vars to sxw struct to hold SOILWAT outputs --- ST_stats.c | 59 ++++++++++++++++++++++++++++++++++++++++++++---------- sxw.h | 8 ++++++++ 2 files changed, 56 insertions(+), 11 deletions(-) diff --git a/ST_stats.c b/ST_stats.c index 2d350e1b..4fb144b6 100644 --- a/ST_stats.c +++ b/ST_stats.c @@ -114,7 +114,7 @@ static RealF _get_gridcell_avg( struct accumulators_grid_cell_st *p); static RealF _get_gridcell_std( struct accumulators_grid_cell_st *p); static void _make_header( char *buf); static void _make_header_with_std( char *buf); -static void _make_header_for_soilwat(char *buf); +static void _make_header_for_soilwat(char *buf, char *header1, char *header2); /* I'm making this a macro because it gets called a lot, but /* note that the syntax checker is obviated, so make sure @@ -1432,9 +1432,9 @@ static void _make_header( char *buf) { } // helper function called by stat_Output_AllSoilwatVariables to create the CSV column names -static void _make_header_for_soilwat(char *buf) +// pass in header1 and header2 for column labels +static void _make_header_for_soilwat(char *buf, char *header1, char *header2) { - char fields[MAX_OUTFIELDS * 2][MAX_FIELDLEN + 1]; char tbuf[80]; @@ -1442,13 +1442,14 @@ static void _make_header_for_soilwat(char *buf) /* Set up headers */ if (BmassFlags.yr) - strcpy(fields[fc++], "Year"); + strcpy(fields[fc++], header1); + //strcpy(fields[fc++], "Year"); // create a column for each layer in the csv int num_layers; for(num_layers = 1; num_layers <= MAX_LAYERS; num_layers++){ // create amount of columns equal to max layers for ease with inserting data char colName[20]; // create array to hold string - snprintf(colName, sizeof colName, "Layer %d", num_layers); // concatenate layer number to word "layer" + snprintf(colName, sizeof colName, "%s %d", header2, num_layers); // concatenate layer number to word "layer" strcpy(fields[fc++], colName); // store column layer } @@ -1466,20 +1467,24 @@ static void _make_header_for_soilwat(char *buf) // store soilwat values in a csv void stat_Output_AllSoilwatVariables(void) { - //printf("inside stat_Output_AllSoilwatVariables \n"); - char buf[2048], tbuf[80], sep = BmassFlags.sep; + char buf[2048], tbuf[80], PPTbuf[2048], sep = BmassFlags.sep; IntS yr; int curYearInt; GrpIndex rg; SppIndex sp; FILE *f; + FILE *PPTFILE; char filename[FILENAME_MAX]; + char PPTfilename[FILENAME_MAX]; sprintf(filename, "%s%0*d.csv", "output/SoilWater_output", Globals.mort.suffixwidth, Globals.currIter); + sprintf(PPTfilename, "%s%0*d.csv", "output/PPT_output", + Globals.mort.suffixwidth, Globals.currIter); + if (DirExists(DirName(filename))) { strcpy(inbuf, filename); @@ -1499,21 +1504,46 @@ void stat_Output_AllSoilwatVariables(void) if (BmassFlags.header) { - _make_header_for_soilwat(buf); // make column names + _make_header_for_soilwat(buf, "Year", "Layer"); // make column names fprintf(f, "%s", buf); } + if (DirExists(DirName(PPTfilename))) + { + strcpy(inbuf, PPTfilename); + if (!RemoveFiles(inbuf)) + printf("Can't remove old biomass output files %s\n", inbuf); + + } + else if (!MkDir(DirName(PPTfilename))) + { + printf("Can't make output path for yearly biomass files: %s\n", + DirName(PPTfilename)); + } + + PPTFILE = OpenFile(PPTfilename, "w"); + + PPTbuf[0] = '\0'; + + if (BmassFlags.header) + { + _make_header_for_soilwat(PPTbuf, "Month", "Year"); // make column names + fprintf(PPTFILE, "%s", PPTbuf); + } + + // Adding values to soil water csv // int layerLoop; int checkVals; - - int testingLayers = 0; + int overallIndex = 0; + int temp; // loop for entering data to csv. for each year it gets the value at all layers then inputs data row by row for (yr = 1; yr <= Globals.runModelYears; yr++){ float layerVals[446]; + float PPTlayerVals[446]; for(layerLoop = 0; layerLoop < SW_Site.n_layers; layerLoop++){ layerVals[layerLoop] = SXW.swc[Ilp(layerLoop, yr)]; - testingLayers++; + overallIndex++; } // write to file. this is reason set layers to MAX_LAYERS instead of layers actually used since it would be too hard to format the fprintf fprintf(f, "%d,%f,%f,%f,%f,%f,%f,%f,%f,%f,%f,%f,%f,%f,%f,%f,%f,%f,%f,%f,%f,%f,%f,%f,%f,%f\n", @@ -1522,8 +1552,15 @@ void stat_Output_AllSoilwatVariables(void) layerVals[14], layerVals[15], layerVals[16], layerVals[17], layerVals[18], layerVals[19], layerVals[20], layerVals[21], layerVals[22], layerVals[23], layerVals[24]); + // store PPT values. Only need to store one column since PPT is not a bi-layer value + // TODO: update for 12 rows and yr + 1 columns + fprintf(PPTFILE, "%d,%f\n", yr, SXW.PPTVal[yr-1]); + } + // Done adding values to soil water csv // CloseFile(&f); + CloseFile(&PPTFILE); + } diff --git a/sxw.h b/sxw.h index 1def1e4a..2af8a2bf 100644 --- a/sxw.h +++ b/sxw.h @@ -56,6 +56,14 @@ struct stepwat_st { aet; /* soilwat's evapotranspiration for the year */ RealD surfaceTemp; /* soilwat's surfaceTemp */ + // PPT variables + int yearInterval; // keep track of years + int curMonth; + RealF PPTVal[500]; // array to store ppt vals + RealF PPT_day[500]; + RealF PPT_week[500]; + RealF PPT_month[500]; + }; #define SXW_NFILES 5 From 2e188ecc2ed0dc86f47fe565edbf45aa039f68dc Mon Sep 17 00:00:00 2001 From: Brendenbe1 Date: Mon, 19 Jun 2017 16:18:02 -0700 Subject: [PATCH 006/111] Changed _make_header_for_soilwat to take input for amount of columns and changed stat_Output_AllSoilwatVariables to store PPT in month formate --- ST_stats.c | 52 ++++++++++++++++++++++++++++++++++++++++------------ 1 file changed, 40 insertions(+), 12 deletions(-) diff --git a/ST_stats.c b/ST_stats.c index 4fb144b6..916bf66b 100644 --- a/ST_stats.c +++ b/ST_stats.c @@ -114,7 +114,7 @@ static RealF _get_gridcell_avg( struct accumulators_grid_cell_st *p); static RealF _get_gridcell_std( struct accumulators_grid_cell_st *p); static void _make_header( char *buf); static void _make_header_with_std( char *buf); -static void _make_header_for_soilwat(char *buf, char *header1, char *header2); +static void _make_header_for_soilwat(char *buf, char *header1, char *header2, int colLength); /* I'm making this a macro because it gets called a lot, but /* note that the syntax checker is obviated, so make sure @@ -1433,7 +1433,7 @@ static void _make_header( char *buf) { // helper function called by stat_Output_AllSoilwatVariables to create the CSV column names // pass in header1 and header2 for column labels -static void _make_header_for_soilwat(char *buf, char *header1, char *header2) +static void _make_header_for_soilwat(char *buf, char *header1, char *header2, int colLength) { char fields[MAX_OUTFIELDS * 2][MAX_FIELDLEN + 1]; char tbuf[80]; @@ -1446,10 +1446,10 @@ static void _make_header_for_soilwat(char *buf, char *header1, char *header2) //strcpy(fields[fc++], "Year"); // create a column for each layer in the csv - int num_layers; - for(num_layers = 1; num_layers <= MAX_LAYERS; num_layers++){ // create amount of columns equal to max layers for ease with inserting data + int num_columns; + for(num_columns = 1; num_columns <= colLength; num_columns++){ // create amount of columns equal to input char colName[20]; // create array to hold string - snprintf(colName, sizeof colName, "%s %d", header2, num_layers); // concatenate layer number to word "layer" + snprintf(colName, sizeof colName, "%s %d", header2, num_columns); // concatenate column number to header 2 strcpy(fields[fc++], colName); // store column layer } @@ -1502,9 +1502,10 @@ void stat_Output_AllSoilwatVariables(void) buf[0] = '\0'; + // soil water if (BmassFlags.header) { - _make_header_for_soilwat(buf, "Year", "Layer"); // make column names + _make_header_for_soilwat(buf, "Year", "Layer", MAX_LAYERS); // make column names fprintf(f, "%s", buf); } @@ -1520,31 +1521,44 @@ void stat_Output_AllSoilwatVariables(void) printf("Can't make output path for yearly biomass files: %s\n", DirName(PPTfilename)); } + // end soil water + // PPT PPTFILE = OpenFile(PPTfilename, "w"); PPTbuf[0] = '\0'; if (BmassFlags.header) { - _make_header_for_soilwat(PPTbuf, "Month", "Year"); // make column names + _make_header_for_soilwat(PPTbuf, "Year", "Month", MAX_MONTHS); // make column names fprintf(PPTFILE, "%s", PPTbuf); } + // end PPT // Adding values to soil water csv // int layerLoop; int checkVals; - int overallIndex = 0; + //int overallIndex = 0; + int currentMonth; int temp; // loop for entering data to csv. for each year it gets the value at all layers then inputs data row by row - for (yr = 1; yr <= Globals.runModelYears; yr++){ + // Handles SWC CSV + for (yr = 1; yr <= Globals.runModelYears; yr++){ // set yr to 1 to start for proper access to Ilp array float layerVals[446]; float PPTlayerVals[446]; + + // loop for soil water for(layerLoop = 0; layerLoop < SW_Site.n_layers; layerLoop++){ layerVals[layerLoop] = SXW.swc[Ilp(layerLoop, yr)]; - overallIndex++; + //overallIndex++; + } + + // loop for PPT + for(currentMonth = 0; currentMonth < MAX_MONTHS; currentMonth++){ + PPTlayerVals[currentMonth] = SXW.PPTVal[currentMonth]; } + // write to file. this is reason set layers to MAX_LAYERS instead of layers actually used since it would be too hard to format the fprintf fprintf(f, "%d,%f,%f,%f,%f,%f,%f,%f,%f,%f,%f,%f,%f,%f,%f,%f,%f,%f,%f,%f,%f,%f,%f,%f,%f,%f\n", yr, layerVals[0], layerVals[1], layerVals[2], layerVals[3], layerVals[4], layerVals[5], layerVals[6], @@ -1552,11 +1566,25 @@ void stat_Output_AllSoilwatVariables(void) layerVals[14], layerVals[15], layerVals[16], layerVals[17], layerVals[18], layerVals[19], layerVals[20], layerVals[21], layerVals[22], layerVals[23], layerVals[24]); + fprintf(PPTFILE, "%d,%f,%f,%f,%f,%f,%f,%f,%f,%f,%f,%f,%f\n", yr, PPTlayerVals[0], PPTlayerVals[1], PPTlayerVals[2], + PPTlayerVals[3], PPTlayerVals[4], PPTlayerVals[5], PPTlayerVals[6],PPTlayerVals[7], PPTlayerVals[8], PPTlayerVals[9], + PPTlayerVals[10], PPTlayerVals[11]); + // store PPT values. Only need to store one column since PPT is not a bi-layer value // TODO: update for 12 rows and yr + 1 columns - fprintf(PPTFILE, "%d,%f\n", yr, SXW.PPTVal[yr-1]); - + //fprintf(PPTFILE, "%d,%f\n", yr, SXW.PPTVal[yr-1]); } + + /*int currentMonth; + // for loop for PPT values + for(currentMonth = 0; currentMonth < MAX_MONTHS; currentMonth++;){ + float PPTlayerVals[446]; + for(yr = 0; yr < Globals.runModelYears; yr++){ + PPTlayerVals[yr] = SXW.PPTVal[yr]; + } + fprintf(PPTFILE, "%d,%f\n", yr, SXW.PPTVal[yr-1]); + }*/ + // Done adding values to soil water csv // CloseFile(&f); CloseFile(&PPTFILE); From 961eb6d16789f56a30eb7da9813880c1f2dad905 Mon Sep 17 00:00:00 2001 From: BrendenBe1 Date: Wed, 28 Jun 2017 16:51:21 -0700 Subject: [PATCH 007/111] Passed prod.in values to struct and fixed SWC values in csv --- ST_stats.c | 45 ++++++++++++++++++++++++--------------------- sxw.c | 17 +++++++++++++---- sxw.h | 6 ++++++ 3 files changed, 43 insertions(+), 25 deletions(-) diff --git a/ST_stats.c b/ST_stats.c index 916bf66b..e2961671 100644 --- a/ST_stats.c +++ b/ST_stats.c @@ -1538,7 +1538,6 @@ void stat_Output_AllSoilwatVariables(void) // Adding values to soil water csv // int layerLoop; int checkVals; - //int overallIndex = 0; int currentMonth; int temp; @@ -1546,44 +1545,48 @@ void stat_Output_AllSoilwatVariables(void) // Handles SWC CSV for (yr = 1; yr <= Globals.runModelYears; yr++){ // set yr to 1 to start for proper access to Ilp array float layerVals[446]; + float swcVals[446]; float PPTlayerVals[446]; + // loop to convert month swc to year and write it to csv + for(currentMonth = 0; currentMonth < MAX_MONTHS; currentMonth++){ + for(layerLoop = 0; layerLoop < SW_Site.n_layers; layerLoop++){ + layerVals[layerLoop] += SXW.swc[Ilp(layerLoop, currentMonth)]; // each layer value for current month is stored in array to be averaged later + } + } + + //printf("layerVals[0]: %f\n", layerVals[0]); + // loop for soil water - for(layerLoop = 0; layerLoop < SW_Site.n_layers; layerLoop++){ + /*for(layerLoop = 0; layerLoop < SW_Site.n_layers; layerLoop++){ layerVals[layerLoop] = SXW.swc[Ilp(layerLoop, yr)]; - //overallIndex++; - } + //printf("layerVals[%d]: %f\n", layerLoop, layerVals[layerLoop]); + }*/ // loop for PPT + // TODO: currently using year values since SOILWAT does not pass any values aside from year for(currentMonth = 0; currentMonth < MAX_MONTHS; currentMonth++){ PPTlayerVals[currentMonth] = SXW.PPTVal[currentMonth]; } // write to file. this is reason set layers to MAX_LAYERS instead of layers actually used since it would be too hard to format the fprintf fprintf(f, "%d,%f,%f,%f,%f,%f,%f,%f,%f,%f,%f,%f,%f,%f,%f,%f,%f,%f,%f,%f,%f,%f,%f,%f,%f,%f\n", - yr, layerVals[0], layerVals[1], layerVals[2], layerVals[3], layerVals[4], layerVals[5], layerVals[6], - layerVals[7], layerVals[8], layerVals[9], layerVals[10], layerVals[11], layerVals[12], layerVals[13], - layerVals[14], layerVals[15], layerVals[16], layerVals[17], layerVals[18], layerVals[19], layerVals[20], - layerVals[21], layerVals[22], layerVals[23], layerVals[24]); + yr, layerVals[0]/12, layerVals[1]/12, layerVals[2]/12, layerVals[3]/12, layerVals[4]/12, layerVals[5]/12, layerVals[6]/12, + layerVals[7]/12, layerVals[8]/12, layerVals[9]/12, layerVals[10]/12, layerVals[11]/12, layerVals[12]/12, layerVals[13]/12, + layerVals[14]/12, layerVals[15]/12, layerVals[16]/12, layerVals[17]/12, layerVals[18]/12, layerVals[19]/12, layerVals[20]/12, + layerVals[21]/12, layerVals[22]/12, layerVals[23]/12, layerVals[24]/12); + // write PPT vals to csv fprintf(PPTFILE, "%d,%f,%f,%f,%f,%f,%f,%f,%f,%f,%f,%f,%f\n", yr, PPTlayerVals[0], PPTlayerVals[1], PPTlayerVals[2], PPTlayerVals[3], PPTlayerVals[4], PPTlayerVals[5], PPTlayerVals[6],PPTlayerVals[7], PPTlayerVals[8], PPTlayerVals[9], PPTlayerVals[10], PPTlayerVals[11]); - - // store PPT values. Only need to store one column since PPT is not a bi-layer value - // TODO: update for 12 rows and yr + 1 columns - //fprintf(PPTFILE, "%d,%f\n", yr, SXW.PPTVal[yr-1]); } + printf("SXW.grass_cover: %f\n", SXW.grass_cover); + printf("SXW.shrub_cover: %f\n", SXW.shrub_cover); + printf("SXW.tree_cover: %f\n", SXW.tree_cover); + printf("SXW.forbs_cover: %f\n", SXW.forbs_cover); + - /*int currentMonth; - // for loop for PPT values - for(currentMonth = 0; currentMonth < MAX_MONTHS; currentMonth++;){ - float PPTlayerVals[446]; - for(yr = 0; yr < Globals.runModelYears; yr++){ - PPTlayerVals[yr] = SXW.PPTVal[yr]; - } - fprintf(PPTFILE, "%d,%f\n", yr, SXW.PPTVal[yr-1]); - }*/ // Done adding values to soil water csv // CloseFile(&f); diff --git a/sxw.c b/sxw.c index b8ed1f49..2c878ecc 100644 --- a/sxw.c +++ b/sxw.c @@ -209,7 +209,7 @@ void SXW_Init( Bool init_SW, char *f_roots ) { _read_debugfile(); _write_sw_outin(); - + if(init_SW) { temp = strdup(SXW.f_watin); SW_CTL_init_model(temp); @@ -223,8 +223,9 @@ void SXW_Init( Bool init_SW, char *f_roots ) { SXW.NTrLyrs = SW_Site.n_transp_lyrs_grass; if(SW_Site.n_transp_lyrs_forb > SXW.NTrLyrs) SXW.NTrLyrs = SW_Site.n_transp_lyrs_forb; - + SXW.NSoLyrs = SW_Site.n_layers; + printf("Number of layers: %d\n", SW_Site.n_layers); _make_arrays(); @@ -375,6 +376,14 @@ void SXW_SW_Setup_Echo(void) { {// %u %u %u %u s->lyr[i]->my_transp_rgn_forb, s->lyr[i]->my_transp_rgn_tree, s->lyr[i]->my_transp_rgn_shrub, s->lyr[i]->my_transp_rgn_grass fprintf(f,"%6.2f %6.2f %6.2f %6.2f\n", s->lyr[i]->transp_coeff_forb, s->lyr[i]->transp_coeff_tree, s->lyr[i]->transp_coeff_shrub, s->lyr[i]->transp_coeff_grass); } + + // adding values to sxw structure for use in ST_stats.c + SXW.grass_cover = SW_VegProd.grass.conv_stcr; + SXW.shrub_cover = SW_VegProd.shrub.conv_stcr; + SXW.tree_cover = SW_VegProd.tree.conv_stcr; + SXW.forbs_cover = SW_VegProd.forb.conv_stcr; + + fprintf(f, "\n"); CloseFile(&f); } @@ -453,7 +462,7 @@ static void _read_files( void ) { if (!GetALine(fin, inbuf)) break; *_sxwfiles[i] = Str_Dup(Str_TrimLeftQ(inbuf)); } - + if (i < nfiles) { LogError(logfp, LOGFATAL, "STEPWAT: %s: Insufficient files found", MyFileName); @@ -1186,7 +1195,7 @@ void load_sxw_memory( RealD* grid_roots_max, RealD* grid_rootsXphen, RealD* grid _phen = Mem_Calloc(SXW.NGrps * MAX_MONTHS, sizeof(RealD), "load_sxw_memory()"); _prod_bmass = Mem_Calloc(SXW.NGrps * MAX_MONTHS, sizeof(RealD), "load_sxw_memory()"); _prod_pctlive = Mem_Calloc(SXW.NGrps * MAX_MONTHS, sizeof(RealD), "load_sxw_memory()"); - + memcpy(_roots_max, grid_roots_max, SXW.NGrps * SXW.NTrLyrs * sizeof(RealD)); memcpy(_rootsXphen, grid_rootsXphen, SXW.NGrps * SXW.NPds * SXW.NTrLyrs * sizeof(RealD)); memcpy(_roots_active, grid_roots_active, SXW.NGrps * SXW.NPds * SXW.NTrLyrs * sizeof(RealD)); diff --git a/sxw.h b/sxw.h index 2af8a2bf..0871cfb9 100644 --- a/sxw.h +++ b/sxw.h @@ -50,6 +50,12 @@ struct stepwat_st { *f_prod, /* biomass to prod. conv. nos. */ *f_watin; /* soilwat's input file */ + /* % Cover from prod.in */ + float grass_cover, + shrub_cover, + tree_cover, + forbs_cover; + /* DEBUG stuff */ char *debugfile; /* added in ST_Main(), read to get debug instructions */ RealF *swc, /* dynamic array(Ilp) of SWC from SOILWAT */ From afe7fb8683916fbaf5305e18a2b91de45a13e0e8 Mon Sep 17 00:00:00 2001 From: BrendenBe1 Date: Wed, 5 Jul 2017 16:56:56 -0700 Subject: [PATCH 008/111] changes for file creation for proper output --- ST_stats.c | 15 ++++++++++----- sxw.c | 8 +++++++- 2 files changed, 17 insertions(+), 6 deletions(-) diff --git a/ST_stats.c b/ST_stats.c index e2961671..7db21151 100644 --- a/ST_stats.c +++ b/ST_stats.c @@ -1465,6 +1465,7 @@ static void _make_header_for_soilwat(char *buf, char *header1, char *header2, in } // store soilwat values in a csv +// TODO: need to clean up this function... too many commented out blobs and ugly/hard to read void stat_Output_AllSoilwatVariables(void) { //printf("inside stat_Output_AllSoilwatVariables \n"); @@ -1544,14 +1545,16 @@ void stat_Output_AllSoilwatVariables(void) // loop for entering data to csv. for each year it gets the value at all layers then inputs data row by row // Handles SWC CSV for (yr = 1; yr <= Globals.runModelYears; yr++){ // set yr to 1 to start for proper access to Ilp array - float layerVals[446]; - float swcVals[446]; - float PPTlayerVals[446]; + float layerVals[104] = {0}; + float PPTlayerVals[446] = {0}; // loop to convert month swc to year and write it to csv for(currentMonth = 0; currentMonth < MAX_MONTHS; currentMonth++){ for(layerLoop = 0; layerLoop < SW_Site.n_layers; layerLoop++){ layerVals[layerLoop] += SXW.swc[Ilp(layerLoop, currentMonth)]; // each layer value for current month is stored in array to be averaged later + //printf("SWCbulk[SXW.grass_cover,layer]: %f\n", SXW.swc[SXW.grass_cover, layerLoop]); // this is what i need to do to get necessary swcbulk values + //if(layerLoop == 0) printf("layerVals[0] for month %d: %f\n", currentMonth, layerVals[0]); + //printf("SXW.swc[Ilp(%d, %d)]: %f\n", layerLoop, currentMonth, SXW.swc[Ilp(layerLoop, currentMonth)]); } } @@ -1569,6 +1572,7 @@ void stat_Output_AllSoilwatVariables(void) PPTlayerVals[currentMonth] = SXW.PPTVal[currentMonth]; } + //printf("layerVals[0]: %f\n", layerVals[0]); // write to file. this is reason set layers to MAX_LAYERS instead of layers actually used since it would be too hard to format the fprintf fprintf(f, "%d,%f,%f,%f,%f,%f,%f,%f,%f,%f,%f,%f,%f,%f,%f,%f,%f,%f,%f,%f,%f,%f,%f,%f,%f,%f\n", yr, layerVals[0]/12, layerVals[1]/12, layerVals[2]/12, layerVals[3]/12, layerVals[4]/12, layerVals[5]/12, layerVals[6]/12, @@ -1581,10 +1585,11 @@ void stat_Output_AllSoilwatVariables(void) PPTlayerVals[3], PPTlayerVals[4], PPTlayerVals[5], PPTlayerVals[6],PPTlayerVals[7], PPTlayerVals[8], PPTlayerVals[9], PPTlayerVals[10], PPTlayerVals[11]); } - printf("SXW.grass_cover: %f\n", SXW.grass_cover); + // printing out values from the outsetup.in that SOILWAT reads in to ensure passing to STEPPE correctly + /*printf("SXW.grass_cover: %f\n", SXW.grass_cover); printf("SXW.shrub_cover: %f\n", SXW.shrub_cover); printf("SXW.tree_cover: %f\n", SXW.tree_cover); - printf("SXW.forbs_cover: %f\n", SXW.forbs_cover); + printf("SXW.forbs_cover: %f\n", SXW.forbs_cover);*/ diff --git a/sxw.c b/sxw.c index 2c878ecc..544c5d69 100644 --- a/sxw.c +++ b/sxw.c @@ -227,6 +227,13 @@ void SXW_Init( Bool init_SW, char *f_roots ) { SXW.NSoLyrs = SW_Site.n_layers; printf("Number of layers: %d\n", SW_Site.n_layers); + stat_Output_Daily_CSV_Summary(); + stat_Output_Weekly_CSV_Summary(); + stat_Output_Monthly_CSV_Summary(); + stat_Output_Yearly_CSV_Summary(); + + + _make_arrays(); _read_roots_max(); @@ -318,7 +325,6 @@ void SXW_Run_SOILWAT (void) { SXW.aet = 0.; /* used to be in sw_setup() but it needs clearing each run */ //SXW_SW_Setup_Echo(); - _sxw_sw_run(); /* now compute resource availability for the given plant sizes */ From 3c4e041619ab00cb055fc450ead2b8badad39a7a Mon Sep 17 00:00:00 2001 From: BrendenBe1 Date: Thu, 6 Jul 2017 16:51:04 -0700 Subject: [PATCH 009/111] add timestep line to outsetup.in --- ST_output.c | 3 -- sxw.c | 88 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 88 insertions(+), 3 deletions(-) diff --git a/ST_output.c b/ST_output.c index b2c3f78a..0df68d6a 100644 --- a/ST_output.c +++ b/ST_output.c @@ -109,7 +109,6 @@ void output_Bmass_Yearly( Int year ) { sprintf(fields[fc++],"%d", Species[sp]->est_count); } } - sprintf(filename, "%s%0*d.csv", Parm_name(F_BMassPre), Globals.bmass.suffixwidth, Globals.currIter); @@ -185,5 +184,3 @@ void output_Mort_Yearly( void ) { CloseFile(&Globals.mort.fp_year); } - - diff --git a/sxw.c b/sxw.c index 544c5d69..e1e8e14e 100644 --- a/sxw.c +++ b/sxw.c @@ -708,6 +708,7 @@ static void _read_watin(void) { MyFileName = SXW.f_watin; f = OpenFile(MyFileName, "r"); + while( GetALine(f, inbuf) ) { if (++lineno == (eOutput + 2)) { strcpy(_swOutDefName, DirName(SXW.f_watin)); @@ -748,7 +749,94 @@ static void _write_sw_outin(void) { strcpy(pd, "DY"); break; } + + //printf("//////////////////////\n"); + FILE *zq; + zq = fopen(_swOutDefName, "r"); + int lineNum = 0; + if(zq){ + //printf("\n reading %s to check values.\n", MyFileName); + char lineLen[100]; + char timestepVals[100]; + char *timeStep_final[4]; + while(fgets(lineLen, sizeof lineLen, zq) != NULL){ + if(lineNum == 0){ + printf("%s\n", lineLen); + strcpy(timestepVals, lineLen); + + lineNum++; + } + } + + // + char ** res = NULL; + char * p = strtok (timestepVals, " "); + int n_spaces = 0, i; + + /* split string and append tokens to 'res' */ + + while (p) { + res = realloc (res, sizeof (char*) * ++n_spaces); + + if (res == NULL) + exit (-1); /* memory allocation failed */ + + res[n_spaces-1] = p; + + p = strtok (NULL, " "); + + } + + /* realloc one extra element for the last NULL */ + + res = realloc (res, sizeof (char*) * (n_spaces+1)); + res[n_spaces] = 0; + + if(strcmp(res[3],"mo")) printf("yes sir\n"); + printf("res[3]: %s\n", res[3]); + /* print the result */ + for (i = 0; i < (n_spaces); ++i){ + printf ("res[%d] = %s\n", i, res[i]); + + if(strcmp(res[i],"dy")){ + //printf("DAY\n"); + timeStep_final[0] = "dy"; + //printf("timeStep_final[0]: %s\n", timeStep_final[0]); + } + else if(strcmp(res[i],"wk")){ + //printf("WEEK\n"); + timeStep_final[1] = "wk"; + //printf("timeStep_final[1]: %s\n", timeStep_final[1]); + } + else if(strcmp(res[i],"mo")){ + //printf("MO\n"); + timeStep_final[2] = "mo"; + //printf("timeStep_final[2]: %s\n", timeStep_final[2]); + } + else if(strcmp(res[i],"yr")){ + //printf("YR\n"); + timeStep_final[3] = "yr"; + //printf("timeStep_final[3]: %s\n", timeStep_final[3]); + } + else printf("\nelse\n\n"); + } + + /*printf("timeStep_final[0]: %s\n", timeStep_final[0]); + printf("timeStep_final[1]: %s\n", timeStep_final[1]); + printf("timeStep_final[2]: %s\n", timeStep_final[2]); + printf("timeStep_final[3]: %s\n", timeStep_final[3]);*/ + + /* free the memory allocated */ + + free (res); + // + + fclose(zq); + } + //printf("//////////////////////\n"); + fp = OpenFile(_swOutDefName, "w"); + //fprintf(fp, "TIMESTEP dy wk mo yr\n"); fprintf(fp, "TRANSP SUM %s 1 end transp\n", pd); fprintf(fp, "PRECIP SUM YR 1 end precip\n"); fprintf(fp, "TEMP AVG YR 1 end temp\n"); From 7ba59be1c689478526de408d721b36719f06b8d1 Mon Sep 17 00:00:00 2001 From: BrendenBe1 Date: Tue, 11 Jul 2017 16:49:54 -0700 Subject: [PATCH 010/111] Finished SWC -> SWA conversion --- sxw.h | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/sxw.h b/sxw.h index 0871cfb9..94d415b8 100644 --- a/sxw.h +++ b/sxw.h @@ -70,6 +70,18 @@ struct stepwat_st { RealF PPT_week[500]; RealF PPT_month[500]; + // store converted SWA values + float SWAbulk_grass[366][25], // 2D array to store SWA vals ([days of year][number of layers]) + SWAbulk_shrub[366][25], + SWAbulk_tree[366][25], + SWAbulk_forb[366][25]; + + // 2D array to store 4 critical values per layer + float SWCbulk[4][8]; // TODO: first value needs to be (number of layers * plant types) - not hardcoded + + int curInterval; + int tempInt; + }; #define SXW_NFILES 5 From dcba03bc4781e1520472c865b6af4526780b712f Mon Sep 17 00:00:00 2001 From: BrendenBe1 Date: Wed, 12 Jul 2017 16:52:52 -0700 Subject: [PATCH 011/111] changes for proper file output --- sxw.c | 28 +++++++++++----------------- sxw.h | 1 + 2 files changed, 12 insertions(+), 17 deletions(-) diff --git a/sxw.c b/sxw.c index e1e8e14e..343a6e64 100644 --- a/sxw.c +++ b/sxw.c @@ -207,7 +207,7 @@ void SXW_Init( Bool init_SW, char *f_roots ) { if (SXW.debugfile) _read_debugfile(); - _write_sw_outin(); + //_write_sw_outin(); if(init_SW) { @@ -750,25 +750,26 @@ static void _write_sw_outin(void) { break; } - //printf("//////////////////////\n"); + // reading outsetup_v30.in file to get timestep values FILE *zq; zq = fopen(_swOutDefName, "r"); int lineNum = 0; if(zq){ - //printf("\n reading %s to check values.\n", MyFileName); char lineLen[100]; char timestepVals[100]; char *timeStep_final[4]; while(fgets(lineLen, sizeof lineLen, zq) != NULL){ - if(lineNum == 0){ - printf("%s\n", lineLen); - strcpy(timestepVals, lineLen); - - lineNum++; + if(lineNum == 5 || lineNum == 3){ // check both lines in case debug is turned off which would make line 3 the last line + char *timeCheck = strstr(lineLen, "TIMESTEP"); // check if this line is the one that outlines the timesteps + if(timeCheck){ + printf("%s\n", lineLen); + strcpy(timestepVals, lineLen); + } } + lineNum++; } + // done reading outsetup_v30.in file - // char ** res = NULL; char * p = strtok (timestepVals, " "); int n_spaces = 0, i; @@ -792,8 +793,6 @@ static void _write_sw_outin(void) { res = realloc (res, sizeof (char*) * (n_spaces+1)); res[n_spaces] = 0; - if(strcmp(res[3],"mo")) printf("yes sir\n"); - printf("res[3]: %s\n", res[3]); /* print the result */ for (i = 0; i < (n_spaces); ++i){ printf ("res[%d] = %s\n", i, res[i]); @@ -821,10 +820,6 @@ static void _write_sw_outin(void) { else printf("\nelse\n\n"); } - /*printf("timeStep_final[0]: %s\n", timeStep_final[0]); - printf("timeStep_final[1]: %s\n", timeStep_final[1]); - printf("timeStep_final[2]: %s\n", timeStep_final[2]); - printf("timeStep_final[3]: %s\n", timeStep_final[3]);*/ /* free the memory allocated */ @@ -833,10 +828,8 @@ static void _write_sw_outin(void) { fclose(zq); } - //printf("//////////////////////\n"); fp = OpenFile(_swOutDefName, "w"); - //fprintf(fp, "TIMESTEP dy wk mo yr\n"); fprintf(fp, "TRANSP SUM %s 1 end transp\n", pd); fprintf(fp, "PRECIP SUM YR 1 end precip\n"); fprintf(fp, "TEMP AVG YR 1 end temp\n"); @@ -844,6 +837,7 @@ static void _write_sw_outin(void) { fprintf(fp, "AET SUM YR 1 end aet\n"); fprintf(fp, "SWCBULK FIN MO 1 end swc_bulk\n"); } + fprintf(fp, "TIMESTEP dy wk mo yr\n"); CloseFile(&fp); } diff --git a/sxw.h b/sxw.h index 94d415b8..ea3a5c39 100644 --- a/sxw.h +++ b/sxw.h @@ -78,6 +78,7 @@ struct stepwat_st { // 2D array to store 4 critical values per layer float SWCbulk[4][8]; // TODO: first value needs to be (number of layers * plant types) - not hardcoded + float SWCoriginal[500][8]; // storing SWC values here instead of in *swc since that does not have enough storage for more than month timestep int curInterval; int tempInt; From 8e44ffdad4ddf8f189a359afc830c10c6dc78ac6 Mon Sep 17 00:00:00 2001 From: BrendenBe1 Date: Mon, 17 Jul 2017 14:00:11 -0700 Subject: [PATCH 012/111] Changes to some .in files --- .../Stepwat_Inputs/Input/sxw/Input/outsetup_v30.in | 1 + .../Stepwat_Inputs/Input/sxw/Input/years.in | 2 +- .../Stepwat_Inputs/Input/sxw/files_v30.in | 4 ++++ 3 files changed, 6 insertions(+), 1 deletion(-) diff --git a/testing.sagebrush.master/Stepwat_Inputs/Input/sxw/Input/outsetup_v30.in b/testing.sagebrush.master/Stepwat_Inputs/Input/sxw/Input/outsetup_v30.in index b1fb0ccc..00c0e502 100644 --- a/testing.sagebrush.master/Stepwat_Inputs/Input/sxw/Input/outsetup_v30.in +++ b/testing.sagebrush.master/Stepwat_Inputs/Input/sxw/Input/outsetup_v30.in @@ -3,3 +3,4 @@ PRECIP SUM YR 1 end precip TEMP AVG YR 1 end temp AET SUM YR 1 end aet SWCBULK FIN MO 1 end swc_bulk +TIMESTEP dy wk mo diff --git a/testing.sagebrush.master/Stepwat_Inputs/Input/sxw/Input/years.in b/testing.sagebrush.master/Stepwat_Inputs/Input/sxw/Input/years.in index 739acd21..e6aa7400 100644 --- a/testing.sagebrush.master/Stepwat_Inputs/Input/sxw/Input/years.in +++ b/testing.sagebrush.master/Stepwat_Inputs/Input/sxw/Input/years.in @@ -2,7 +2,7 @@ # Location: P1 1980 # starting year (but see weather and swc inputs) -2280 # ending year +2020 # ending year 1 # first day of first year 365 # ending day of last year N # hemisphere (N,S) diff --git a/testing.sagebrush.master/Stepwat_Inputs/Input/sxw/files_v30.in b/testing.sagebrush.master/Stepwat_Inputs/Input/sxw/files_v30.in index 8df8b8a7..21573772 100644 --- a/testing.sagebrush.master/Stepwat_Inputs/Input/sxw/files_v30.in +++ b/testing.sagebrush.master/Stepwat_Inputs/Input/sxw/files_v30.in @@ -26,3 +26,7 @@ Input/swcsetup.in # params for handling measured swc #Output Output # 'relative' path for output files: / for same directory, or e.g., Output/ Input/outsetup_v30.in # define output quantities +Output/csv/daily.csv #output +Output/csv/weekly.csv #output +Output/csv/monthly.csv #output +Output/csv/yearly.csv #output From 8fc885e835690542a33303efba0303ba23cd5d8c Mon Sep 17 00:00:00 2001 From: BrendenBe1 Date: Tue, 18 Jul 2017 16:57:06 -0700 Subject: [PATCH 013/111] Error checking SWA conversion --- ST_main.c | 4 ++-- makefile | 20 +++++++++---------- sxw_soilwat.c | 1 - .../Stepwat_Inputs/Input/model.in | 2 +- 4 files changed, 13 insertions(+), 14 deletions(-) diff --git a/ST_main.c b/ST_main.c index 46ba6578..e49e11bb 100644 --- a/ST_main.c +++ b/ST_main.c @@ -143,7 +143,7 @@ Bool UseProgressBar; */ void print_soilwat_output(char* str) { - isPartialSoilwatOutput = FALSE; + isPartialSoilwatOutput = FALSE; printf( "inside stepwat main setting files options for soilwat full output, so now isPartialSoilwatOutput=%d \n", isPartialSoilwatOutput); @@ -170,7 +170,7 @@ void print_soilwat_output(char* str) /******************** Begin Model Code *********************/ /***********************************************************/ int main(int argc, char **argv) { - IntS year, iter, incr, g, s; + IntS year, iter, incr, g, s; IndivType *i; Bool killedany; diff --git a/makefile b/makefile index 57f3dd35..ece2e609 100644 --- a/makefile +++ b/makefile @@ -16,7 +16,7 @@ CC = gcc WRES = windres #no idea what this was actually used for since it doesn't do anything... -HOMEV = +HOMEV = VPATH = $(HOMEV)/include #no idea what this was used for either... oDir = ./obj Bin = . @@ -25,8 +25,8 @@ libDirs = -Lsw_src -Lsqlite-amalgamation incDirs = -Isw_src -Isqlite-amalgamation -LIBS = -C_FLAGS = -g -O0 -Wstrict-prototypes -Wmissing-prototypes -Wimplicit -Wunused -Wformat -Wredundant-decls -Wcast-align\ +LIBS = +C_FLAGS = -g -O0 -Wstrict-prototypes -Wmissing-prototypes -Wimplicit -Wunused -Wformat -Wredundant-decls -Wcast-align\ -DSTEPWAT -lm SRCS =\ @@ -173,7 +173,7 @@ $(oDir)/sxw.o: sxw.c sw_src/generic.h sw_src/filefuncs.h \ sxw_module.h sw_src/SW_Control.h sw_src/SW_Model.h sw_src/SW_Site.h sw_src/SW_SoilWater.h \ sw_src/SW_Files.h sw_src/SW_VegProd.h $(CC) $(C_FLAGS) $(incDirs) -c -o $@ $< - + $(oDir)/sxw_sql.o: sxw_sql.c ST_steppe.h \ ST_steppe.h sw_src/SW_Defines.h sxw.h\ sw_src/SW_Times.h sxw_module.h sw_src/SW_Model.h sw_src/SW_Site.h sw_src/SW_SoilWater.h @@ -219,9 +219,9 @@ $(oDir)/sw_src/SW_Output.o: sw_src/SW_Output.c sw_src/generic.h \ sw_src/SW_Files.h sw_src/SW_Model.h sw_src/SW_Times.h sw_src/SW_Site.h sw_src/SW_SoilWater.h sw_src/SW_Output.h \ sw_src/SW_Weather.h $(CC) $(C_FLAGS) $(incDirs) -c -o $@ $< - -$(oDir)/sw_src/SW_Main_Function.o: sw_src/SW_Main_Function.c - $(CC) $(C_FLAGS) $(incDirs) -c -o $@ $< + +$(oDir)/sw_src/SW_Main_Function.o: sw_src/SW_Main_Function.c + $(CC) $(C_FLAGS) $(incDirs) -c -o $@ $< $(oDir)/sw_src/SW_Site.o: sw_src/SW_Site.c sw_src/generic.h sw_src/filefuncs.h \ sw_src/myMemory.h sw_src/SW_Defines.h sw_src/SW_Files.h sw_src/SW_Site.h @@ -311,16 +311,16 @@ $(oDir)/sxw_tester.o: sxw_tester.c sw_src/generic.h \ ST_defines.h ST_structs.h ST_functions.h ST_Globals.h sw_src/SW_Defines.h \ sw_src/SW_Site.h sxw_funcs.h sxw.h sw_src/SW_Times.h sxw_module.h sxw_vars.h $(CC) $(C_FLAGS) $(incDirs) -c -o $@ $< - + $(oDir)/sw_src/SW_VegEstab.o: sw_src/SW_VegEstab.c sw_src/generic.h sw_src/filefuncs.h sw_src/myMemory.h \ sw_src/SW_Defines.h sw_src/SW_Files.h sw_src/SW_Site.h sw_src/SW_Times.h \ sw_src/SW_Model.h sw_src/SW_SoilWater.h sw_src/SW_Weather.h sw_src/SW_VegEstab.h $(CC) $(C_FLAGS) $(incDirs) -c -o $@ $< - + $(oDir)/ST_grid.o: ST_grid.c ST_steppe.h ST_defines.h sw_src/generic.h \ ST_globals.h \ sw_src/myMemory.h ST_globals.h $(CC) $(C_FLAGS) $(incDirs) -c -o $@ $< - + $(oDir)/ST_sql.o: ST_sql.c ST_steppe.h ST_globals.h $(CC) $(C_FLAGS) $(incDirs) -c -o $@ $< diff --git a/sxw_soilwat.c b/sxw_soilwat.c index 3f8de5a7..b0700e69 100644 --- a/sxw_soilwat.c +++ b/sxw_soilwat.c @@ -315,4 +315,3 @@ static void _update_productivity(void) { } #undef Biomass } - diff --git a/testing.sagebrush.master/Stepwat_Inputs/Input/model.in b/testing.sagebrush.master/Stepwat_Inputs/Input/model.in index 16f9e88b..b043a569 100644 --- a/testing.sagebrush.master/Stepwat_Inputs/Input/model.in +++ b/testing.sagebrush.master/Stepwat_Inputs/Input/model.in @@ -19,4 +19,4 @@ # it doesn't hurt to set it to 0 always. # niter nyrs seed - 50 300 0 + 5 100 0 From fcff25b38a015762c7081b15f4925533e828d0f6 Mon Sep 17 00:00:00 2001 From: BrendenBe1 Date: Thu, 20 Jul 2017 16:51:23 -0700 Subject: [PATCH 014/111] Continuing to create timestep files --- .../Stepwat_Inputs/Input/sxw/files_v30.in | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/testing.sagebrush.master/Stepwat_Inputs/Input/sxw/files_v30.in b/testing.sagebrush.master/Stepwat_Inputs/Input/sxw/files_v30.in index 21573772..3e2c52b9 100644 --- a/testing.sagebrush.master/Stepwat_Inputs/Input/sxw/files_v30.in +++ b/testing.sagebrush.master/Stepwat_Inputs/Input/sxw/files_v30.in @@ -24,9 +24,14 @@ Input/estab.in # plant establishment start file Input/swcsetup.in # params for handling measured swc #Output -Output # 'relative' path for output files: / for same directory, or e.g., Output/ +Output/ # 'relative' path for output files: / for same directory, or e.g., Output/ Input/outsetup_v30.in # define output quantities Output/csv/daily.csv #output Output/csv/weekly.csv #output Output/csv/monthly.csv #output Output/csv/yearly.csv #output + +Output/csv/daily_soil.csv #output +Output/csv/weekly_soil.csv #output +Output/csv/monthly_soil.csv #output +Output/csv/yearly_soil.csv #output From 2dafb1639dfe8324984f401adfec21183f8b3b35 Mon Sep 17 00:00:00 2001 From: BrendenBe1 Date: Thu, 3 Aug 2017 16:53:54 -0700 Subject: [PATCH 015/111] Adding function to apply SWA values --- sxw.h | 2 +- sxw_resource.c | 57 +++++++++++++++++++++++++++++++++++++++++++++----- 2 files changed, 53 insertions(+), 6 deletions(-) diff --git a/sxw.h b/sxw.h index ea3a5c39..88b69a78 100644 --- a/sxw.h +++ b/sxw.h @@ -71,7 +71,7 @@ struct stepwat_st { RealF PPT_month[500]; // store converted SWA values - float SWAbulk_grass[366][25], // 2D array to store SWA vals ([days of year][number of layers]) + float SWAbulk_grass[366][25], // 2D array to store SWA vals ([days of year][number of max layers]) SWAbulk_shrub[366][25], SWAbulk_tree[366][25], SWAbulk_forb[366][25]; diff --git a/sxw_resource.c b/sxw_resource.c index cb2bacc5..5134179c 100644 --- a/sxw_resource.c +++ b/sxw_resource.c @@ -88,6 +88,8 @@ extern static void _transp_contribution_by_group(RealF use_by_group[]); +static void _SWA_contribution_by_group(RealF use_by_group[]); + /***********************************************************/ /****************** Begin Function Code ********************/ @@ -148,6 +150,7 @@ void _sxw_update_resource(void) { _sxw_update_root_tables(sizes); _transp_contribution_by_group(_resource_cur); + _SWA_contribution_by_group(_resource_cur); ForEachGroup(g) { @@ -234,19 +237,19 @@ static void _transp_contribution_by_group(RealF use_by_group[]) { RealD *transp; RealF sumUsedByGroup = 0., sumTranspTotal = 0., TranspRemaining = 0.; - ForEachGroup(g) + ForEachGroup(g) // steppe functional group { use_by_group[g] = 0.; /* clear */ t = RGroup[g]->veg_prod_type-1; switch(t) { case 0://Tree - transp = SXW.transpTotal; + transp = SXW.transpTotal; // want to use transpiration assigned to specific functional type break; case 1://Shrub transp = SXW.transpTotal; break; case 2://Grass - transp = SXW.transpTotal; + transp = SXW.transpTotal; // SXW.transpGrasses (if use specic type need to rescale resource space parameters) break; case 3://Forb transp = SXW.transpTotal; @@ -255,20 +258,24 @@ static void _transp_contribution_by_group(RealF use_by_group[]) { transp = SXW.transpTotal; break; } - ForEachTrPeriod(p) + ForEachTrPeriod(p) // loops thru each month and calculates a + //use by group for each steppe functional group according to whether that group has active living roots in giving layer for period { int nLyrs = getNTranspLayers(RGroup[g]->veg_prod_type); for (l = 0; l < nLyrs; l++) { - use_by_group[g] += (RealF) (_roots_active_rel[Iglp(g, l, p)] * RGroup[g]->min_res_req * transp[Ilp(l, p)]); + use_by_group[g] += (RealF) (_roots_active_rel[Iglp(g, l, p)] * RGroup[g]->min_res_req * transp[Ilp(l, p)]); //min_res_req is space parameter + // rescale space param based on indy transp //printf("for groupName= %s, layerIndex: %d after sum use_by_group[g]= %f \n",RGroup[g]->name,l,use_by_group[g] ); } } sumUsedByGroup += use_by_group[g]; } + // TODO: if redo upper part, can remove bottom part //Occasionally, extra transpiration remains and if not perfectly partitioned to RGroups. //This check makes sure any remaining transpiration is divided proportionately among Rgroups. ForEachTrPeriod(p) { + //printf("p: %d\n", p); for (t = 0; t < SXW.NSoLyrs; t++) sumTranspTotal += SXW.transpTotal[Ilp(t, p)]; } @@ -283,5 +290,45 @@ static void _transp_contribution_by_group(RealF use_by_group[]) { } } +static void _SWA_contribution_by_group(RealF use_by_group[]) { + GrpIndex g; + SppIndex s; + TimeInt p; + LyrIndex l; + int t,i; + RealD *swaNew; + RealF sumUsedByGroup = 0., sumSWATotal = 0., SWARemaining = 0.; + + ForEachGroup(g) // steppe functional group + { + use_by_group[g] = 0.; // clear + t = RGroup[g]->veg_prod_type-1; + switch(t) + { + case 0://Tree + swaNew = SXW.SWAbulk_tree; // want to use transpiration assigned to specific functional type + break; + case 1://Shrub + swaNew = SXW.SWAbulk_shrub; + break; + case 2://Grass + swaNew = SXW.SWAbulk_grass; // SXW.transpGrasses (if use specic type need to rescale resource space parameters) + break; + case 3://Forb + swaNew = SXW.SWAbulk_forb; + break; + } + ForEachTrPeriod(p) + { + for (l = 0; l < SXW.NSoLyrs; l++) { + use_by_group[g] += (RealF) (_roots_active_rel[Iglp(g, l, p)] * RGroup[g]->min_res_req * swaNew[Ilp(l, p)]); //min_res_req is space parameter + //printf("RGroup[g]->min_res_req: %f\n", RGroup[g]->min_res_req); + } + } + sumUsedByGroup += use_by_group[g]; + //printf("sumUsedByGroup: %f\n", sumUsedByGroup); + //printf("use_by_group: %f\n", use_by_group[g]); + } +} From 0b9a8e11c7d92fd9709022876b1be9e8a2dfa713 Mon Sep 17 00:00:00 2001 From: Brendenbe1 Date: Mon, 7 Aug 2017 16:58:48 -0700 Subject: [PATCH 016/111] _SWA_contribution_by_group function progress --- sxw_resource.c | 21 +++++++------------ .../Input/sxw/Input/outsetup_v30.in | 3 ++- 2 files changed, 10 insertions(+), 14 deletions(-) diff --git a/sxw_resource.c b/sxw_resource.c index 5134179c..55dfef0f 100644 --- a/sxw_resource.c +++ b/sxw_resource.c @@ -265,10 +265,10 @@ static void _transp_contribution_by_group(RealF use_by_group[]) { for (l = 0; l < nLyrs; l++) { use_by_group[g] += (RealF) (_roots_active_rel[Iglp(g, l, p)] * RGroup[g]->min_res_req * transp[Ilp(l, p)]); //min_res_req is space parameter // rescale space param based on indy transp - //printf("for groupName= %s, layerIndex: %d after sum use_by_group[g]= %f \n",RGroup[g]->name,l,use_by_group[g] ); } } sumUsedByGroup += use_by_group[g]; + //printf("sumUsedByGroup: %f\n", sumUsedByGroup); } // TODO: if redo upper part, can remove bottom part //Occasionally, extra transpiration remains and if not perfectly partitioned to RGroups. @@ -296,8 +296,8 @@ static void _SWA_contribution_by_group(RealF use_by_group[]) { TimeInt p; LyrIndex l; int t,i; - RealD *swaNew; - RealF sumUsedByGroup = 0., sumSWATotal = 0., SWARemaining = 0.; + float swaNew[366][25]; + RealF sumUsedByGroup = 0.; ForEachGroup(g) // steppe functional group { @@ -306,29 +306,24 @@ static void _SWA_contribution_by_group(RealF use_by_group[]) { switch(t) { case 0://Tree - swaNew = SXW.SWAbulk_tree; // want to use transpiration assigned to specific functional type + memcpy(swaNew, SXW.SWAbulk_tree, sizeof(swaNew)); break; case 1://Shrub - swaNew = SXW.SWAbulk_shrub; + memcpy(swaNew, SXW.SWAbulk_shrub, sizeof(swaNew)); break; case 2://Grass - swaNew = SXW.SWAbulk_grass; // SXW.transpGrasses (if use specic type need to rescale resource space parameters) + memcpy(swaNew, SXW.SWAbulk_grass, sizeof(swaNew)); break; case 3://Forb - swaNew = SXW.SWAbulk_forb; + memcpy(swaNew, SXW.SWAbulk_forb, sizeof(swaNew)); break; } - - ForEachTrPeriod(p) { for (l = 0; l < SXW.NSoLyrs; l++) { - use_by_group[g] += (RealF) (_roots_active_rel[Iglp(g, l, p)] * RGroup[g]->min_res_req * swaNew[Ilp(l, p)]); //min_res_req is space parameter - //printf("RGroup[g]->min_res_req: %f\n", RGroup[g]->min_res_req); + use_by_group[g] += (RealF) (_roots_active_rel[Iglp(g, l, p)] * RGroup[g]->min_res_req * swaNew[p][l]); //min_res_req is space parameter } } sumUsedByGroup += use_by_group[g]; - //printf("sumUsedByGroup: %f\n", sumUsedByGroup); - //printf("use_by_group: %f\n", use_by_group[g]); } } diff --git a/testing.sagebrush.master/Stepwat_Inputs/Input/sxw/Input/outsetup_v30.in b/testing.sagebrush.master/Stepwat_Inputs/Input/sxw/Input/outsetup_v30.in index 00c0e502..5727dd08 100644 --- a/testing.sagebrush.master/Stepwat_Inputs/Input/sxw/Input/outsetup_v30.in +++ b/testing.sagebrush.master/Stepwat_Inputs/Input/sxw/Input/outsetup_v30.in @@ -3,4 +3,5 @@ PRECIP SUM YR 1 end precip TEMP AVG YR 1 end temp AET SUM YR 1 end aet SWCBULK FIN MO 1 end swc_bulk -TIMESTEP dy wk mo +SWA AVG MO 1 end swa +TIMESTEP dy wk mo yr From beb78e22e975590dde6c2d7e90a88ddf46731cdd Mon Sep 17 00:00:00 2001 From: BrendenBe1 Date: Wed, 9 Aug 2017 16:52:19 -0700 Subject: [PATCH 017/111] _SWA_contribution_by_group function progress --- sxw.c | 6 +++--- sxw.h | 3 ++- sxw_resource.c | 32 ++++++++++++++++++++++---------- 3 files changed, 27 insertions(+), 14 deletions(-) diff --git a/sxw.c b/sxw.c index 343a6e64..cc9ff373 100644 --- a/sxw.c +++ b/sxw.c @@ -227,12 +227,12 @@ void SXW_Init( Bool init_SW, char *f_roots ) { SXW.NSoLyrs = SW_Site.n_layers; printf("Number of layers: %d\n", SW_Site.n_layers); - stat_Output_Daily_CSV_Summary(); + // TODO: need to see if need to have output for every run of STEPPE or only when -o parameter is called + /*stat_Output_Daily_CSV_Summary(); stat_Output_Weekly_CSV_Summary(); stat_Output_Monthly_CSV_Summary(); stat_Output_Yearly_CSV_Summary(); - - + */ _make_arrays(); diff --git a/sxw.h b/sxw.h index 88b69a78..a4ba2cbf 100644 --- a/sxw.h +++ b/sxw.h @@ -74,7 +74,8 @@ struct stepwat_st { float SWAbulk_grass[366][25], // 2D array to store SWA vals ([days of year][number of max layers]) SWAbulk_shrub[366][25], SWAbulk_tree[366][25], - SWAbulk_forb[366][25]; + SWAbulk_forb[366][25], + SWATotal[366][25]; // 2D array to store 4 critical values per layer float SWCbulk[4][8]; // TODO: first value needs to be (number of layers * plant types) - not hardcoded diff --git a/sxw_resource.c b/sxw_resource.c index 55dfef0f..6a658440 100644 --- a/sxw_resource.c +++ b/sxw_resource.c @@ -264,28 +264,23 @@ static void _transp_contribution_by_group(RealF use_by_group[]) { int nLyrs = getNTranspLayers(RGroup[g]->veg_prod_type); for (l = 0; l < nLyrs; l++) { use_by_group[g] += (RealF) (_roots_active_rel[Iglp(g, l, p)] * RGroup[g]->min_res_req * transp[Ilp(l, p)]); //min_res_req is space parameter - // rescale space param based on indy transp } } sumUsedByGroup += use_by_group[g]; - //printf("sumUsedByGroup: %f\n", sumUsedByGroup); } // TODO: if redo upper part, can remove bottom part //Occasionally, extra transpiration remains and if not perfectly partitioned to RGroups. //This check makes sure any remaining transpiration is divided proportionately among Rgroups. ForEachTrPeriod(p) { - //printf("p: %d\n", p); for (t = 0; t < SXW.NSoLyrs; t++) sumTranspTotal += SXW.transpTotal[Ilp(t, p)]; } TranspRemaining = sumTranspTotal - sumUsedByGroup; - //printf(" sumTranspTotal=%f, sumUsedByGroup=%f TranspRemaining=%f \n",sumTranspTotal,sumUsedByGroup,TranspRemaining); ForEachGroup(g) { if(!ZRO(use_by_group[g])) { use_by_group[g] += (use_by_group[g]/sumUsedByGroup) * TranspRemaining; - // printf("for groupName= %s, after sum use_by_group[g]= %f \n",RGroup[g]->name,use_by_group[g] ); } } } @@ -297,7 +292,7 @@ static void _SWA_contribution_by_group(RealF use_by_group[]) { LyrIndex l; int t,i; float swaNew[366][25]; - RealF sumUsedByGroup = 0.; + RealF sumUsedByGroup = 0., sumSWATotal = 0., SWARemaining = 0.; ForEachGroup(g) // steppe functional group { @@ -306,17 +301,19 @@ static void _SWA_contribution_by_group(RealF use_by_group[]) { switch(t) { case 0://Tree - memcpy(swaNew, SXW.SWAbulk_tree, sizeof(swaNew)); + memcpy(swaNew, SXW.SWATotal, sizeof(swaNew)); // copy values into array break; case 1://Shrub - memcpy(swaNew, SXW.SWAbulk_shrub, sizeof(swaNew)); + memcpy(swaNew, SXW.SWATotal, sizeof(swaNew)); break; case 2://Grass - memcpy(swaNew, SXW.SWAbulk_grass, sizeof(swaNew)); + memcpy(swaNew, SXW.SWATotal, sizeof(swaNew)); break; case 3://Forb - memcpy(swaNew, SXW.SWAbulk_forb, sizeof(swaNew)); + memcpy(swaNew, SXW.SWATotal, sizeof(swaNew)); break; + default: + memcpy(swaNew, SXW.SWATotal, sizeof(swaNew)); } ForEachTrPeriod(p) { @@ -326,4 +323,19 @@ static void _SWA_contribution_by_group(RealF use_by_group[]) { } sumUsedByGroup += use_by_group[g]; } + + // ############################################################## + ForEachTrPeriod(p) + { + for (t = 0; t < SXW.NSoLyrs; t++) + sumSWATotal += SXW.SWATotal[p][t]; + } + SWARemaining = sumSWATotal - sumUsedByGroup; + ForEachGroup(g) + { + if(!ZRO(use_by_group[g])) { + use_by_group[g] += (use_by_group[g]/sumUsedByGroup) * SWARemaining; + } + } + // ############################################################## } From 9be94d645986d6f9a9e7a414d4adfd3ef72f8c3a Mon Sep 17 00:00:00 2001 From: BrendenBe1 Date: Tue, 15 Aug 2017 16:53:38 -0700 Subject: [PATCH 018/111] Updated _SWA_contribution_by_group to partition space correctly --- sxw.c | 4 +-- sxw.h | 8 +++--- sxw_resource.c | 71 ++++++++++++++++++++++++++++++++++---------------- 3 files changed, 55 insertions(+), 28 deletions(-) diff --git a/sxw.c b/sxw.c index cc9ff373..b2a0a2f4 100644 --- a/sxw.c +++ b/sxw.c @@ -384,10 +384,10 @@ void SXW_SW_Setup_Echo(void) { } // adding values to sxw structure for use in ST_stats.c - SXW.grass_cover = SW_VegProd.grass.conv_stcr; + /*SXW.grass_cover = SW_VegProd.grass.conv_stcr; SXW.shrub_cover = SW_VegProd.shrub.conv_stcr; SXW.tree_cover = SW_VegProd.tree.conv_stcr; - SXW.forbs_cover = SW_VegProd.forb.conv_stcr; + SXW.forbs_cover = SW_VegProd.forb.conv_stcr;*/ fprintf(f, "\n"); diff --git a/sxw.h b/sxw.h index a4ba2cbf..4393ea6c 100644 --- a/sxw.h +++ b/sxw.h @@ -51,10 +51,11 @@ struct stepwat_st { *f_watin; /* soilwat's input file */ /* % Cover from prod.in */ - float grass_cover, + /*float grass_cover, shrub_cover, tree_cover, - forbs_cover; + forbs_cover;*/ + RealD critSoilWater[4]; // storing values in same order as defined in rgroup.in (0=tree, 1=shrub, 2=grass, 3=forb) /* DEBUG stuff */ char *debugfile; /* added in ST_Main(), read to get debug instructions */ @@ -74,8 +75,7 @@ struct stepwat_st { float SWAbulk_grass[366][25], // 2D array to store SWA vals ([days of year][number of max layers]) SWAbulk_shrub[366][25], SWAbulk_tree[366][25], - SWAbulk_forb[366][25], - SWATotal[366][25]; + SWAbulk_forb[366][25]; // 2D array to store 4 critical values per layer float SWCbulk[4][8]; // TODO: first value needs to be (number of layers * plant types) - not hardcoded diff --git a/sxw_resource.c b/sxw_resource.c index 6a658440..e81ce64c 100644 --- a/sxw_resource.c +++ b/sxw_resource.c @@ -294,48 +294,75 @@ static void _SWA_contribution_by_group(RealF use_by_group[]) { float swaNew[366][25]; RealF sumUsedByGroup = 0., sumSWATotal = 0., SWARemaining = 0.; + // values for refactored equation + RealD critSumByGroup[MAX_RGROUPS] = {0.}; + RealD refactoredCrit = 0; + + + ForEachGroup(g) + { + t = RGroup[g]->veg_prod_type-1; + critSumByGroup[t] += RGroup[g]->min_res_req; // get the critical value sums + } + + ForEachGroup(g) // steppe functional group { use_by_group[g] = 0.; // clear + float newCritSum = 0.; t = RGroup[g]->veg_prod_type-1; switch(t) { case 0://Tree - memcpy(swaNew, SXW.SWATotal, sizeof(swaNew)); // copy values into array + memcpy(swaNew, SXW.SWAbulk_tree, sizeof(swaNew)); // copy values into array + // need to include all the veg types in the range of the critical soil water potential + for(i=0; i<4; i++){ // loop through 4 times, once per veg type + if(SXW.critSoilWater[t] >= SXW.critSoilWater[i]) // if the veg type being used is bigger than the others need to include those others + newCritSum += critSumByGroup[i]; // make new sum for proper scaling + /* reason is to get the values for these to scale so they equal 1 requires getting sum of all in use and then dividing + // each individual one by the sum of all to make the total add up to 1 but retain the difference in the individual elements + // for example if shrubs critical soil water potential (csp) is -3.9 and grasses csp is -3.5 and you are running on + // grasses then you need to include all the values for shrubs and grasses since both are getting resources at that depth + */ + } + refactoredCrit = RGroup[g]->min_res_req / newCritSum; // get new critical value for use in equation below break; + case 1://Shrub - memcpy(swaNew, SXW.SWATotal, sizeof(swaNew)); + memcpy(swaNew, SXW.SWAbulk_shrub, sizeof(swaNew)); + for(i=0; i<4; i++){ + if(SXW.critSoilWater[t] >= SXW.critSoilWater[i]) + newCritSum += critSumByGroup[i]; + } + refactoredCrit = RGroup[g]->min_res_req / newCritSum; break; + case 2://Grass - memcpy(swaNew, SXW.SWATotal, sizeof(swaNew)); + memcpy(swaNew, SXW.SWAbulk_grass, sizeof(swaNew)); + for(i=0; i<4; i++){ + if(SXW.critSoilWater[t] >= SXW.critSoilWater[i]) + newCritSum += critSumByGroup[i]; + } + refactoredCrit = RGroup[g]->min_res_req / newCritSum; break; + case 3://Forb - memcpy(swaNew, SXW.SWATotal, sizeof(swaNew)); + memcpy(swaNew, SXW.SWAbulk_forb, sizeof(swaNew)); + for(i=0; i<4; i++){ + if(SXW.critSoilWater[t] >= SXW.critSoilWater[i]) + newCritSum += critSumByGroup[i]; + } + refactoredCrit = RGroup[g]->min_res_req / newCritSum; break; - default: - memcpy(swaNew, SXW.SWATotal, sizeof(swaNew)); } ForEachTrPeriod(p) { for (l = 0; l < SXW.NSoLyrs; l++) { - use_by_group[g] += (RealF) (_roots_active_rel[Iglp(g, l, p)] * RGroup[g]->min_res_req * swaNew[p][l]); //min_res_req is space parameter + use_by_group[g] += (RealF) (_roots_active_rel[Iglp(g, l, p)] * refactoredCrit * swaNew[p][l]); //min_res_req is space parameter + //printf("for groupName= %s, layerIndex: %d use_by_group[%d]= %f\n",RGroup[g]->name,l,g,use_by_group[g]); + //printf("swaNew[%d][%d]: %f\n", p,l,swaNew[p][l]); } } sumUsedByGroup += use_by_group[g]; } - - // ############################################################## - ForEachTrPeriod(p) - { - for (t = 0; t < SXW.NSoLyrs; t++) - sumSWATotal += SXW.SWATotal[p][t]; - } - SWARemaining = sumSWATotal - sumUsedByGroup; - ForEachGroup(g) - { - if(!ZRO(use_by_group[g])) { - use_by_group[g] += (use_by_group[g]/sumUsedByGroup) * SWARemaining; - } - } - // ############################################################## } From 583488d7c5885512fdaa004dab1a6f1f2f15266e Mon Sep 17 00:00:00 2001 From: BrendenBe1 Date: Thu, 17 Aug 2017 10:50:10 -0700 Subject: [PATCH 019/111] Change -o flag to write outputs as STEPPE is running --- ST_main.c | 53 +++++++++++++++++++++-------------------------------- sxw.c | 8 +------- 2 files changed, 22 insertions(+), 39 deletions(-) diff --git a/ST_main.c b/ST_main.c index e49e11bb..545ef3ea 100644 --- a/ST_main.c +++ b/ST_main.c @@ -141,7 +141,7 @@ Bool UseProgressBar; * it will work in both grid and non-grid version * */ -void print_soilwat_output(char* str) +/*void print_soilwat_output(char* str) { isPartialSoilwatOutput = FALSE; @@ -154,7 +154,7 @@ void print_soilwat_output(char* str) array[0] = "sw_v31"; //Just for name sake SOILWAT exe name given here, though it will never getting use array[1] = "-f"; array[2] = Str_Dup(str); - array[3] = NULL;/* end of array so later you can do while (array[i++]!=NULL) {...} */ + array[3] = NULL;// end of array so later you can do while (array[i++]!=NULL) {...} printf( "inside stepwat main setting files options for soilwat: argc=%d array[0]=%s ,array[1]=%s,array[2]=%s \n ", argc_soilwat, array[0], array[1], array[2]); @@ -165,7 +165,7 @@ void print_soilwat_output(char* str) printf( "Soilwat main function executed successfully and now isPartialSoilwatOutput=%d \n", isPartialSoilwatOutput); -} +}*/ /******************** Begin Model Code *********************/ /***********************************************************/ @@ -179,11 +179,11 @@ int main(int argc, char **argv) { /* provides a way to inform user that something * was logged. see generic.h */ - init_args(argc, argv); + isPartialSoilwatOutput = TRUE; // dont want to get soilwat output unless -o flag - printf("STEPWAT init_args() executed successfully \n "); + init_args(argc, argv); // if -o flag then well set isPartialSoilwatOutput to FALSE and get output - isPartialSoilwatOutput = TRUE; + printf("STEPWAT init_args() executed successfully \n "); if (UseGrid == TRUE) { runGrid(); @@ -195,9 +195,6 @@ int main(int argc, char **argv) { if (UseSoilwat) SXW_Init(TRUE, NULL); - //Connect to ST db and insert static data - //ST_connect("Output/stdebug"); - incr = (IntS) ((float) Globals.runModelIterations / 10); if (incr == 0) incr = 1; @@ -219,14 +216,8 @@ int main(int argc, char **argv) { RandSeed(Globals.randseed); Globals.currIter = iter; - /*Debug_AddByIter( iter); */ - /* ------ Begin running the model ------ */ for (year = 1; year <= Globals.runModelYears; year++) { - - /*Debug_AddByYear(year);*/ - - /* printf("Iter=%d, Year=%d\n", iter, year); */ Globals.currYear = year; rgroup_Establish(); @@ -259,20 +250,8 @@ int main(int argc, char **argv) { _kill_annuals(); proportion_Recovery(); _kill_extra_growth(); - - //ForEachGroup(g) { - // insertRGroupYearInfo(g); - //} - //ForEachSpecies(s) { - // insertSpecieYearInfo(s); - // for ((i) = Species[s]->IndvHead; (i) != NULL; (i) = (i)->Next) { - // insertIndivYearInfo(i); - // } - //} } /* end model run for this year*/ - //if (BmassFlags.yearly) //moved to output function - // CloseFile(&Globals.bmass.fp_year); if (MortFlags.summary) { stat_Collect_GMort(); stat_Collect_SMort(); @@ -300,12 +279,18 @@ int main(int argc, char **argv) { if (BmassFlags.summary) stat_Output_AllBmass(); - //Needed to disconnect from database - //ST_disconnect(); + // trying to find the proper place to write the output + if(isPartialSoilwatOutput == FALSE){ + //SW_OUT_write_today(); + //SW_OUT_flush(); + SW_OUT_close_files(); + } + #ifdef STEPWAT if (!isnull(SXW.debugfile) ) SXW_PrintDebug(1); #endif + printf("\nend program\n"); fprintf(progfp, "\n"); return 0; } @@ -406,10 +391,12 @@ static void init_args(int argc, char **argv) { * the program to write progress info (iter) to stdout. * Without the option, progress info (dots) is written to * stderr. + * 8/16/17 - BEB removed option for -o flag. Now if this flag is set the output files from + * files.in are written to. */ char str[1024], *opts[] = {"-d","-f","-q","-s","-e", "-p", "-g", "-o"}; /* valid options */ - int valopts[] = { 1, 1, 0, -1, 0, 0 , 0, 1}; /* indicates options with values */ + int valopts[] = { 1, 1, 0, -1, 0, 0 , 0, 0}; /* indicates options with values */ /* 0=none, 1=required, -1=optional */ int i, /* looper through all cmdline arguments */ a, /* current valid argument-value position */ @@ -523,11 +510,13 @@ static void init_args(int argc, char **argv) { break; /* -g */ case 7: - printf("Get all the Soilwat option called, with file=%s \n", str); + /*printf("Get all the Soilwat option called, with file=%s \n", str); if (strlen(str) > 1) { print_soilwat_output(str); - } + }*/ + printf("in flag -o\n"); + isPartialSoilwatOutput = FALSE; break; /* -o also get all the soilwat output*/ diff --git a/sxw.c b/sxw.c index b2a0a2f4..9f5e4a76 100644 --- a/sxw.c +++ b/sxw.c @@ -227,13 +227,6 @@ void SXW_Init( Bool init_SW, char *f_roots ) { SXW.NSoLyrs = SW_Site.n_layers; printf("Number of layers: %d\n", SW_Site.n_layers); - // TODO: need to see if need to have output for every run of STEPPE or only when -o parameter is called - /*stat_Output_Daily_CSV_Summary(); - stat_Output_Weekly_CSV_Summary(); - stat_Output_Monthly_CSV_Summary(); - stat_Output_Yearly_CSV_Summary(); - */ - _make_arrays(); _read_roots_max(); @@ -837,6 +830,7 @@ static void _write_sw_outin(void) { fprintf(fp, "AET SUM YR 1 end aet\n"); fprintf(fp, "SWCBULK FIN MO 1 end swc_bulk\n"); } + fprintf(fp, "SWA AVG MO 1 end swa\n"); fprintf(fp, "TIMESTEP dy wk mo yr\n"); CloseFile(&fp); From d85419916c3a98df9853a05afa227d7175599a97 Mon Sep 17 00:00:00 2001 From: BrendenBe1 Date: Thu, 17 Aug 2017 16:48:10 -0700 Subject: [PATCH 020/111] Change -o flag to write outputs as STEPPE is running --- ST_main.c | 4 ++-- .../Stepwat_Inputs/Input/sxw/Input/outsetup_v30.in | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/ST_main.c b/ST_main.c index 545ef3ea..818a323a 100644 --- a/ST_main.c +++ b/ST_main.c @@ -269,6 +269,7 @@ int main(int argc, char **argv) { { SXW_Reset(); } + SW_OUT_close_files(); } /* end model run for this iteration*/ @@ -281,9 +282,8 @@ int main(int argc, char **argv) { // trying to find the proper place to write the output if(isPartialSoilwatOutput == FALSE){ - //SW_OUT_write_today(); //SW_OUT_flush(); - SW_OUT_close_files(); + //SW_OUT_close_files(); } #ifdef STEPWAT diff --git a/testing.sagebrush.master/Stepwat_Inputs/Input/sxw/Input/outsetup_v30.in b/testing.sagebrush.master/Stepwat_Inputs/Input/sxw/Input/outsetup_v30.in index 5727dd08..5c50f06e 100644 --- a/testing.sagebrush.master/Stepwat_Inputs/Input/sxw/Input/outsetup_v30.in +++ b/testing.sagebrush.master/Stepwat_Inputs/Input/sxw/Input/outsetup_v30.in @@ -1,7 +1,7 @@ +TIMESTEP dy wk mo TRANSP SUM MO 1 end transp PRECIP SUM YR 1 end precip TEMP AVG YR 1 end temp AET SUM YR 1 end aet SWCBULK FIN MO 1 end swc_bulk SWA AVG MO 1 end swa -TIMESTEP dy wk mo yr From cbcf7d2a266458ec8ebd1943a1c920b35256734a Mon Sep 17 00:00:00 2001 From: BrendenBe1 Date: Tue, 22 Aug 2017 17:02:08 -0700 Subject: [PATCH 021/111] Altering how -o flag in STEPPE interacts with SOILWAT --- ST_main.c | 14 +++----------- 1 file changed, 3 insertions(+), 11 deletions(-) diff --git a/ST_main.c b/ST_main.c index 818a323a..2825c585 100644 --- a/ST_main.c +++ b/ST_main.c @@ -263,13 +263,10 @@ int main(int argc, char **argv) { if (UseSoilwat) { stat_Output_AllSoilwatVariables(); + SXW_Reset(); } - if (UseSoilwat) - { - SXW_Reset(); - } - SW_OUT_close_files(); + //SW_OUT_close_files(); } /* end model run for this iteration*/ @@ -280,11 +277,6 @@ int main(int argc, char **argv) { if (BmassFlags.summary) stat_Output_AllBmass(); - // trying to find the proper place to write the output - if(isPartialSoilwatOutput == FALSE){ - //SW_OUT_flush(); - //SW_OUT_close_files(); - } #ifdef STEPWAT if (!isnull(SXW.debugfile) ) SXW_PrintDebug(1); @@ -391,7 +383,7 @@ static void init_args(int argc, char **argv) { * the program to write progress info (iter) to stdout. * Without the option, progress info (dots) is written to * stderr. - * 8/16/17 - BEB removed option for -o flag. Now if this flag is set the output files from + * 8/16/17 - BEB Updated option for -o flag. Now if this flag is set the output files from * files.in are written to. */ char str[1024], From bb44cf6c28edd288b9fd712050a2e58c8cab86a4 Mon Sep 17 00:00:00 2001 From: BrendenBe1 Date: Wed, 23 Aug 2017 16:45:37 -0700 Subject: [PATCH 022/111] Altering how -o flag in STEPPE interacts with SOILWAT --- ST_main.c | 85 ++++++++----------------------------------------------- 1 file changed, 12 insertions(+), 73 deletions(-) diff --git a/ST_main.c b/ST_main.c index 2825c585..4a860df5 100644 --- a/ST_main.c +++ b/ST_main.c @@ -40,7 +40,6 @@ extern Bool isPartialSoilwatOutput; void rgroup_Establish( void) ; void rgroup_IncrAges( void); void rgroup_PartResources( void); - //void rgroup_ResPartIndiv(void); void mort_Main( Bool *killed); void mort_EndOfYear( void); @@ -56,7 +55,7 @@ extern Bool isPartialSoilwatOutput; void stat_Collect( Int year ) ; void stat_Collect_GMort ( void ) ; void stat_Collect_SMort ( void ) ; - //void stat_Output_YrMorts( void ) ; + void stat_Output_AllMorts( void) ; void stat_Output_AllBmass(void) ; @@ -87,9 +86,7 @@ extern Bool isPartialSoilwatOutput; /*************** Local Function Declarations ***************/ /***********************************************************/ void Plot_Initialize( void); -//void Debug_AddByIter( Int iter); -//void Debug_AddByYear( Int year); -/*void chkmem(void);*/ + static void usage(void) { char *s ="STEPPE plant community dynamics (SGS-LTER Jan-04).\n" "Usage: steppe [-d startdir] [-f files.in] [-q] [-s] [-e] [-o] [-g]\n" @@ -108,7 +105,6 @@ static void check_log(void); /* a couple of debugging routines */ void check_sizes(const char *); -//static void check_sizes_final(void ); Bool QuietMode; @@ -136,37 +132,6 @@ Bool DuringSpinup; Bool EchoInits; Bool UseProgressBar; -/* Added By: AKT 06/27/2016 - * Function for printing all the SOILWAT output in the STEPWAT, - * it will work in both grid and non-grid version - * - */ -/*void print_soilwat_output(char* str) -{ - isPartialSoilwatOutput = FALSE; - - printf( "inside stepwat main setting files options for soilwat full output, so now isPartialSoilwatOutput=%d \n", isPartialSoilwatOutput); - - int argc_soilwat = 3; - char **array; - array = malloc(sizeof(char*) * (argc_soilwat + 1)); - - array[0] = "sw_v31"; //Just for name sake SOILWAT exe name given here, though it will never getting use - array[1] = "-f"; - array[2] = Str_Dup(str); - array[3] = NULL;// end of array so later you can do while (array[i++]!=NULL) {...} - - printf( "inside stepwat main setting files options for soilwat: argc=%d array[0]=%s ,array[1]=%s,array[2]=%s \n ", - argc_soilwat, array[0], array[1], array[2]); - - main_function(argc_soilwat, array); - - isPartialSoilwatOutput = TRUE; - - printf( "Soilwat main function executed successfully and now isPartialSoilwatOutput=%d \n", isPartialSoilwatOutput); - -}*/ - /******************** Begin Model Code *********************/ /***********************************************************/ int main(int argc, char **argv) { @@ -201,7 +166,6 @@ int main(int argc, char **argv) { /* --- Begin a new iteration ------ */ for (iter = 1; iter <= Globals.runModelIterations; iter++) { - if (progfp == stderr) { if (iter % incr == 0) fprintf(progfp, "."); @@ -262,8 +226,12 @@ int main(int argc, char **argv) { if (UseSoilwat) { + //printf("iterating!!!!!\n"); stat_Output_AllSoilwatVariables(); - SXW_Reset(); + // printf("iterating@@@@@\n"); + if(Globals.currIter != Globals.runModelIterations) + SXW_Reset(); + //printf("RESART*&$#@!$#!@#!\n"); } //SW_OUT_close_files(); @@ -277,6 +245,9 @@ int main(int argc, char **argv) { if (BmassFlags.summary) stat_Output_AllBmass(); +// SW_OUT_read(); +// SW_OUT_write_today(); + #ifdef STEPWAT if (!isnull(SXW.debugfile) ) SXW_PrintDebug(1); @@ -384,7 +355,7 @@ static void init_args(int argc, char **argv) { * Without the option, progress info (dots) is written to * stderr. * 8/16/17 - BEB Updated option for -o flag. Now if this flag is set the output files from - * files.in are written to. + * files_v30.in are written to. */ char str[1024], *opts[] = {"-d","-f","-q","-s","-e", "-p", "-g", "-o"}; /* valid options */ @@ -502,14 +473,8 @@ static void init_args(int argc, char **argv) { break; /* -g */ case 7: - /*printf("Get all the Soilwat option called, with file=%s \n", str); - if (strlen(str) > 1) - { - print_soilwat_output(str); - }*/ - printf("in flag -o\n"); + printf("storing SOILWAT output (flag -o)\n"); isPartialSoilwatOutput = FALSE; - break; /* -o also get all the soilwat output*/ default: @@ -580,32 +545,6 @@ void check_sizes(const char *chkpt) { } - -/*static void check_sizes_final(void) { -//=================================================== - - GrpIndex rg; - SppIndex sp; - - ForEachGroup(rg) { - if (!ZRO(RGroup[rg]->relsize) ) { - LogError(stdout, LOGWARN, "(%d) Group %s relsize != 0 (%.2f)\n", - Globals.currIter, - RGroup[rg]->name, RGroup[rg]->relsize); - } - } - - ForEachSpecies(sp) { - if (!ZRO(Species[sp]->relsize) ) { - LogError(stdout, LOGWARN, "(%d) Species %s relsize != 0 (%.2f)\n", - Globals.currIter, - Species[sp]->name, Species[sp]->relsize); - } - } - -}*/ - -/*===============================================================*/ #ifdef DEBUG_MEM void CheckMemoryIntegrity(Bool flag) { // DLM - 6/6/2013 : NOTE - The dynamically allocated variables added for the new grid option are not accounted for here. I haven't bothered to add them because it would add a ton of code and I haven't been using the code to facilitate debugging of memory. Instead I have been using the valgrind program to debug my memory, as I feel like it is a better solution. If wanting to use this code to debug memory, memory references would probably have to be set up for the dynamically allocated variables in ST_grid.c as well as the new dynamically allocated grid_Stat variable in ST_stats.c. From 689c0ec1f70c4f7356ea52ee6ef5e755f05d3a63 Mon Sep 17 00:00:00 2001 From: BrendenBe1 Date: Thu, 24 Aug 2017 16:31:32 -0700 Subject: [PATCH 023/111] Implemented stepwat_transp_test into this branch and started working on averaging values over iterations --- ST_main.c | 39 +++++++++++++++++++++++++-------------- sxw.h | 4 +++- sxw_resource.c | 20 ++++++++++++++------ 3 files changed, 42 insertions(+), 21 deletions(-) diff --git a/ST_main.c b/ST_main.c index 4a860df5..2add6da9 100644 --- a/ST_main.c +++ b/ST_main.c @@ -200,7 +200,7 @@ int main(int argc, char **argv) { rgroup_IncrAges(); - // Added functions for Grazing and mort_end_year as proportional killing effect before exporting biomass end of the year + // Added functions for Grazing and mort_end_year as proportional killing effect before exporting biomass end of the year grazing_EndOfYear(); mort_EndOfYear(); @@ -210,10 +210,31 @@ int main(int argc, char **argv) { if (BmassFlags.yearly) output_Bmass_Yearly(year); - // Moved kill annual and kill extra growth after we export biomass, and recovery of biomass after fire before the next year + // Moved kill annual and kill extra growth after we export biomass, and recovery of biomass after fire before the next year _kill_annuals(); proportion_Recovery(); _kill_extra_growth(); + + /* #################################################################################### + * this is the basic algorithm for getting the average over multiple iterations + * will not remain here, will be moved into a function but this is just a testing phase + * ################################################################################## */ + int i; + float m = 0; + float swaAvg = 0; + + if(year == 1){ + for(i=0; i<12; i++){ + swaAvg += SXW.SWAbulk_forb[i][0]; + } + swaAvg /= 12; //[year][layer] + m = 1+iter; + m = 2/m; + SXW.SWAbulk_forb_avg[year][0] = (m * swaAvg + (1-m) * SXW.SWAbulk_forb_avg[year][0]); //[year][layer] + //printf("\nSWAbulk_forb_avg[1][0] = %f\n\n", SXW.SWAbulk_forb_avg[year][0]); + } + // ###################################################################################### + } /* end model run for this year*/ if (MortFlags.summary) { @@ -226,17 +247,12 @@ int main(int argc, char **argv) { if (UseSoilwat) { - //printf("iterating!!!!!\n"); stat_Output_AllSoilwatVariables(); - // printf("iterating@@@@@\n"); + // dont need to restart if last iteration finished + // this keeps it from re-writing the output folder and overwriting output files if(Globals.currIter != Globals.runModelIterations) SXW_Reset(); - //printf("RESART*&$#@!$#!@#!\n"); } - - //SW_OUT_close_files(); - - } /* end model run for this iteration*/ /*------------------------------------------------------*/ @@ -245,10 +261,6 @@ int main(int argc, char **argv) { if (BmassFlags.summary) stat_Output_AllBmass(); -// SW_OUT_read(); -// SW_OUT_write_today(); - - #ifdef STEPWAT if (!isnull(SXW.debugfile) ) SXW_PrintDebug(1); #endif @@ -278,7 +290,6 @@ void Plot_Initialize(void) { if (RGroup[Species[sp]->res_grp]->extirpated) { Species[sp]->seedling_estab_prob = Species[sp]->seedling_estab_prob_old; - } /* clear estab and kills information */ diff --git a/sxw.h b/sxw.h index 4393ea6c..99a2ab25 100644 --- a/sxw.h +++ b/sxw.h @@ -75,7 +75,9 @@ struct stepwat_st { float SWAbulk_grass[366][25], // 2D array to store SWA vals ([days of year][number of max layers]) SWAbulk_shrub[366][25], SWAbulk_tree[366][25], - SWAbulk_forb[366][25]; + SWAbulk_forb[366][25], + SWAbulk_forb_avg[366][25]; + // 2D array to store 4 critical values per layer float SWCbulk[4][8]; // TODO: first value needs to be (number of layers * plant types) - not hardcoded diff --git a/sxw_resource.c b/sxw_resource.c index e81ce64c..970c48aa 100644 --- a/sxw_resource.c +++ b/sxw_resource.c @@ -239,20 +239,21 @@ static void _transp_contribution_by_group(RealF use_by_group[]) { ForEachGroup(g) // steppe functional group { - use_by_group[g] = 0.; /* clear */ + use_by_group[g] = 0.; /* clear */ t = RGroup[g]->veg_prod_type-1; + switch(t) { case 0://Tree - transp = SXW.transpTotal; // want to use transpiration assigned to specific functional type + transp = SXW.transpTrees; break; case 1://Shrub - transp = SXW.transpTotal; + transp = SXW.transpShrubs; break; case 2://Grass - transp = SXW.transpTotal; // SXW.transpGrasses (if use specic type need to rescale resource space parameters) + transp = SXW.transpGrasses; break; case 3://Forb - transp = SXW.transpTotal; + transp = SXW.transpForbs; break; default: transp = SXW.transpTotal; @@ -263,7 +264,7 @@ static void _transp_contribution_by_group(RealF use_by_group[]) { { int nLyrs = getNTranspLayers(RGroup[g]->veg_prod_type); for (l = 0; l < nLyrs; l++) { - use_by_group[g] += (RealF) (_roots_active_rel[Iglp(g, l, p)] * RGroup[g]->min_res_req * transp[Ilp(l, p)]); //min_res_req is space parameter + use_by_group[g] += (RealF) (_roots_active_rel[Iglp(g, l, p)] * transp[Ilp(l, p)]); } } sumUsedByGroup += use_by_group[g]; @@ -365,4 +366,11 @@ static void _SWA_contribution_by_group(RealF use_by_group[]) { } sumUsedByGroup += use_by_group[g]; } + /*ForEachTrPeriod(p) + { + for (t = 0; t < SXW.NSoLyrs; t++) + sumSWATotal += SXW.transpTotal[Ilp(t, p)]; + } + SWARemaining = sumSWATotal - sumUsedByGroup; + printf("SWARemaining: %f\n", SWARemaining);*/ } From 9b8ed097fbb26f6f00e9dfd7ae75c7854d9b555c Mon Sep 17 00:00:00 2001 From: Brendenbe1 Date: Mon, 28 Aug 2017 16:41:44 -0700 Subject: [PATCH 024/111] Implementing SOILWAT variables being averaged over all iterations --- ST_main.c | 9 +++++++-- ST_stats.c | 24 ++++++++++++++++++++++-- sxw_resource.c | 34 +--------------------------------- 3 files changed, 30 insertions(+), 37 deletions(-) diff --git a/ST_main.c b/ST_main.c index 2add6da9..a11972f0 100644 --- a/ST_main.c +++ b/ST_main.c @@ -210,6 +210,8 @@ int main(int argc, char **argv) { if (BmassFlags.yearly) output_Bmass_Yearly(year); + stat_Average_SOILWAT_vars(SXW.SWAbulk_forb, SXW.SWAbulk_forb_avg); + // Moved kill annual and kill extra growth after we export biomass, and recovery of biomass after fire before the next year _kill_annuals(); proportion_Recovery(); @@ -219,7 +221,7 @@ int main(int argc, char **argv) { * this is the basic algorithm for getting the average over multiple iterations * will not remain here, will be moved into a function but this is just a testing phase * ################################################################################## */ - int i; + /*int i; float m = 0; float swaAvg = 0; @@ -232,7 +234,7 @@ int main(int argc, char **argv) { m = 2/m; SXW.SWAbulk_forb_avg[year][0] = (m * swaAvg + (1-m) * SXW.SWAbulk_forb_avg[year][0]); //[year][layer] //printf("\nSWAbulk_forb_avg[1][0] = %f\n\n", SXW.SWAbulk_forb_avg[year][0]); - } + }*/ // ###################################################################################### } /* end model run for this year*/ @@ -261,6 +263,9 @@ int main(int argc, char **argv) { if (BmassFlags.summary) stat_Output_AllBmass(); + printf("\n\n\nSWAbulk_forb_avg[1][0] = %f\n\n", SXW.SWAbulk_forb_avg[1][0]); + + #ifdef STEPWAT if (!isnull(SXW.debugfile) ) SXW_PrintDebug(1); #endif diff --git a/ST_stats.c b/ST_stats.c index 7db21151..e4bfb129 100644 --- a/ST_stats.c +++ b/ST_stats.c @@ -49,15 +49,16 @@ void stat_Output_YrMorts( void ) ; void stat_Output_AllMorts( void) ; void stat_Output_AllBmass(void) ; + void stat_Average_SOILWAT_vars(float outputVar[366][25], float outputVarAvg[366][25]) ; //adding below function for adding modified soilwat output at stepwat location void stat_Output_AllSoilwatVariables(void); //Adding below two functions for creating grid cells avg values output file - void stat_Output_AllBmassAvg(void) ; + void stat_Output_AllBmassAvg(void); void stat_Output_AllCellAvgBmass(const char * filename); void stat_Output_Seed_Dispersal(const char * filename, const char sep, Bool makeHeader); - void stat_free_mem( void ) ; + void stat_free_mem( void ); void stat_Load_Accumulators( int cell, int year ); //these accumulators were added to use in the gridded option... there overall purpose is to save/load data to allow steppe to output correctly when running multiple grid cells void stat_Save_Accumulators( int cell, int year ); @@ -828,6 +829,7 @@ void stat_Output_YrMorts( void ) { /***********************************************************/ void stat_Output_AllMorts( void) { + printf("stat_Output_AllMorts\n"); FILE *f; IntS age; GrpIndex rg; @@ -1464,6 +1466,24 @@ static void _make_header_for_soilwat(char *buf, char *header1, char *header2, in } +void stat_Average_SOILWAT_vars(float outputVar[366][25], float outputVarAvg[366][25]){ + // need to average all of the variables outlined in the outsetup file + int i; + int j; + float m = 0; + float outputAvg = 0; + + for(i=0; i<12; i++){ + outputAvg += outputVar[i][0]; + outputAvg /= 12; //[year][layer] + } + m = 1+j; + m = 2/m; + outputVarAvg[1][0] = (m * outputAvg + (1-m) * outputVarAvg[1][0]); //SXW.SWAbulk_forb_avg[year][layer] + //printf("\nSWAbulk_forb_avg[1][0] = %f(%f)\n\n", outputVarAvg[1][0], outputAvg); + printf("\nSWAbulk_forb_avg[1][0] = %f\n\n", outputVarAvg[1][0]); +} + // store soilwat values in a csv // TODO: need to clean up this function... too many commented out blobs and ugly/hard to read void stat_Output_AllSoilwatVariables(void) diff --git a/sxw_resource.c b/sxw_resource.c index 970c48aa..dcd19fc0 100644 --- a/sxw_resource.c +++ b/sxw_resource.c @@ -297,69 +297,37 @@ static void _SWA_contribution_by_group(RealF use_by_group[]) { // values for refactored equation RealD critSumByGroup[MAX_RGROUPS] = {0.}; - RealD refactoredCrit = 0; - ForEachGroup(g) - { - t = RGroup[g]->veg_prod_type-1; - critSumByGroup[t] += RGroup[g]->min_res_req; // get the critical value sums - } ForEachGroup(g) // steppe functional group { use_by_group[g] = 0.; // clear - float newCritSum = 0.; t = RGroup[g]->veg_prod_type-1; switch(t) { case 0://Tree memcpy(swaNew, SXW.SWAbulk_tree, sizeof(swaNew)); // copy values into array // need to include all the veg types in the range of the critical soil water potential - for(i=0; i<4; i++){ // loop through 4 times, once per veg type - if(SXW.critSoilWater[t] >= SXW.critSoilWater[i]) // if the veg type being used is bigger than the others need to include those others - newCritSum += critSumByGroup[i]; // make new sum for proper scaling - /* reason is to get the values for these to scale so they equal 1 requires getting sum of all in use and then dividing - // each individual one by the sum of all to make the total add up to 1 but retain the difference in the individual elements - // for example if shrubs critical soil water potential (csp) is -3.9 and grasses csp is -3.5 and you are running on - // grasses then you need to include all the values for shrubs and grasses since both are getting resources at that depth - */ - } - refactoredCrit = RGroup[g]->min_res_req / newCritSum; // get new critical value for use in equation below break; case 1://Shrub memcpy(swaNew, SXW.SWAbulk_shrub, sizeof(swaNew)); - for(i=0; i<4; i++){ - if(SXW.critSoilWater[t] >= SXW.critSoilWater[i]) - newCritSum += critSumByGroup[i]; - } - refactoredCrit = RGroup[g]->min_res_req / newCritSum; break; case 2://Grass memcpy(swaNew, SXW.SWAbulk_grass, sizeof(swaNew)); - for(i=0; i<4; i++){ - if(SXW.critSoilWater[t] >= SXW.critSoilWater[i]) - newCritSum += critSumByGroup[i]; - } - refactoredCrit = RGroup[g]->min_res_req / newCritSum; break; case 3://Forb memcpy(swaNew, SXW.SWAbulk_forb, sizeof(swaNew)); - for(i=0; i<4; i++){ - if(SXW.critSoilWater[t] >= SXW.critSoilWater[i]) - newCritSum += critSumByGroup[i]; - } - refactoredCrit = RGroup[g]->min_res_req / newCritSum; break; } ForEachTrPeriod(p) { for (l = 0; l < SXW.NSoLyrs; l++) { - use_by_group[g] += (RealF) (_roots_active_rel[Iglp(g, l, p)] * refactoredCrit * swaNew[p][l]); //min_res_req is space parameter + use_by_group[g] += (RealF) (_roots_active_rel[Iglp(g, l, p)] * swaNew[p][l]); //min_res_req is space parameter //printf("for groupName= %s, layerIndex: %d use_by_group[%d]= %f\n",RGroup[g]->name,l,g,use_by_group[g]); //printf("swaNew[%d][%d]: %f\n", p,l,swaNew[p][l]); } From 09f2007c90507b0467ddf0e9613f8dcb233bacd3 Mon Sep 17 00:00:00 2001 From: BrendenBe1 Date: Wed, 30 Aug 2017 16:51:46 -0700 Subject: [PATCH 025/111] Continuing to work on averaging iterations and swa contribution --- ST_main.c | 4 ++-- ST_stats.c | 3 +-- sxw.h | 3 +++ sxw_resource.c | 49 ++++++++++++++++++++++++++++++++++++++++--------- 4 files changed, 46 insertions(+), 13 deletions(-) diff --git a/ST_main.c b/ST_main.c index a11972f0..37a053a8 100644 --- a/ST_main.c +++ b/ST_main.c @@ -210,7 +210,7 @@ int main(int argc, char **argv) { if (BmassFlags.yearly) output_Bmass_Yearly(year); - stat_Average_SOILWAT_vars(SXW.SWAbulk_forb, SXW.SWAbulk_forb_avg); + //stat_Average_SOILWAT_vars(SXW.SWAbulk_forb, SXW.SWAbulk_forb_avg); // need to make this work // Moved kill annual and kill extra growth after we export biomass, and recovery of biomass after fire before the next year _kill_annuals(); @@ -263,7 +263,7 @@ int main(int argc, char **argv) { if (BmassFlags.summary) stat_Output_AllBmass(); - printf("\n\n\nSWAbulk_forb_avg[1][0] = %f\n\n", SXW.SWAbulk_forb_avg[1][0]); + //printf("\n\n\nSWAbulk_forb_avg[1][0] = %f\n\n", SXW.SWAbulk_forb_avg[1][0]); #ifdef STEPWAT diff --git a/ST_stats.c b/ST_stats.c index e4bfb129..33aecd10 100644 --- a/ST_stats.c +++ b/ST_stats.c @@ -829,7 +829,6 @@ void stat_Output_YrMorts( void ) { /***********************************************************/ void stat_Output_AllMorts( void) { - printf("stat_Output_AllMorts\n"); FILE *f; IntS age; GrpIndex rg; @@ -1481,7 +1480,7 @@ void stat_Average_SOILWAT_vars(float outputVar[366][25], float outputVarAvg[366] m = 2/m; outputVarAvg[1][0] = (m * outputAvg + (1-m) * outputVarAvg[1][0]); //SXW.SWAbulk_forb_avg[year][layer] //printf("\nSWAbulk_forb_avg[1][0] = %f(%f)\n\n", outputVarAvg[1][0], outputAvg); - printf("\nSWAbulk_forb_avg[1][0] = %f\n\n", outputVarAvg[1][0]); + //printf("\nSWAbulk_forb_avg[1][0] = %f\n\n", outputVarAvg[1][0]); } // store soilwat values in a csv diff --git a/sxw.h b/sxw.h index 99a2ab25..68095cc4 100644 --- a/sxw.h +++ b/sxw.h @@ -26,6 +26,7 @@ #include "generic.h" #include "SW_Times.h" +#include "ST_defines.h" int getNTranspLayers(int veg_prod_type); @@ -78,6 +79,8 @@ struct stepwat_st { SWAbulk_forb[366][25], SWAbulk_forb_avg[366][25]; + RealF transp_SWA[MAX_YEARS]; + // 2D array to store 4 critical values per layer float SWCbulk[4][8]; // TODO: first value needs to be (number of layers * plant types) - not hardcoded diff --git a/sxw_resource.c b/sxw_resource.c index dcd19fc0..9d2482cd 100644 --- a/sxw_resource.c +++ b/sxw_resource.c @@ -49,7 +49,7 @@ /* for steppe, see ST_globals.h */ //extern SW_SITE SW_Site; -//extern SW_MODEL SW_Model; +extern SW_MODEL SW_Model; //extern SW_SOILWAT SW_Soilwat; //extern SW_VEGPROD SW_VegProd; @@ -233,6 +233,7 @@ static void _transp_contribution_by_group(RealF use_by_group[]) { SppIndex s; TimeInt p; LyrIndex l; + int currentYear = SW_Model.year-SW_Model.startyr; int t,i; RealD *transp; RealF sumUsedByGroup = 0., sumTranspTotal = 0., TranspRemaining = 0.; @@ -269,6 +270,8 @@ static void _transp_contribution_by_group(RealF use_by_group[]) { } sumUsedByGroup += use_by_group[g]; } + SXW.transp_SWA[currentYear] += sumUsedByGroup; + //printf("SXW.transp_SWA[%d] = %f\n", currentYear, SXW.transp_SWA[currentYear]); // TODO: if redo upper part, can remove bottom part //Occasionally, extra transpiration remains and if not perfectly partitioned to RGroups. //This check makes sure any remaining transpiration is divided proportionately among Rgroups. @@ -291,54 +294,82 @@ static void _SWA_contribution_by_group(RealF use_by_group[]) { SppIndex s; TimeInt p; LyrIndex l; + int currentYear = SW_Model.year-SW_Model.startyr; int t,i; float swaNew[366][25]; RealF sumUsedByGroup = 0., sumSWATotal = 0., SWARemaining = 0.; // values for refactored equation RealD critSumByGroup[MAX_RGROUPS] = {0.}; + RealD refactoredCrit = 0; + ForEachGroup(g) + { + t = RGroup[g]->veg_prod_type-1; + critSumByGroup[t] += RGroup[g]->min_res_req; // get the critical value sums + } ForEachGroup(g) // steppe functional group { use_by_group[g] = 0.; // clear + float newCritSum = 0.; t = RGroup[g]->veg_prod_type-1; switch(t) { case 0://Tree memcpy(swaNew, SXW.SWAbulk_tree, sizeof(swaNew)); // copy values into array // need to include all the veg types in the range of the critical soil water potential + for(i=0; i<4; i++){ // loop through 4 times, once per veg type + if(SXW.critSoilWater[t] >= SXW.critSoilWater[i]) // if the veg type being used is bigger than the others need to include those others + newCritSum += critSumByGroup[i]; // make new sum for proper scaling + /* reason is to get the values for these to scale so they equal 1 requires getting sum of all in use and then dividing + // each individual one by the sum of all to make the total add up to 1 but retain the difference in the individual elements + // for example if shrubs critical soil water potential (csp) is -3.9 and grasses csp is -3.5 and you are running on + // grasses then you need to include all the values for shrubs and grasses since both are getting resources at that depth + */ + } + refactoredCrit = RGroup[g]->min_res_req / newCritSum; // get new critical value for use in equation below break; case 1://Shrub memcpy(swaNew, SXW.SWAbulk_shrub, sizeof(swaNew)); + for(i=0; i<4; i++){ + if(SXW.critSoilWater[t] >= SXW.critSoilWater[i]) + newCritSum += critSumByGroup[i]; + } + refactoredCrit = RGroup[g]->min_res_req / newCritSum; break; case 2://Grass memcpy(swaNew, SXW.SWAbulk_grass, sizeof(swaNew)); + for(i=0; i<4; i++){ + if(SXW.critSoilWater[t] >= SXW.critSoilWater[i]) + newCritSum += critSumByGroup[i]; + } + refactoredCrit = RGroup[g]->min_res_req / newCritSum; break; case 3://Forb memcpy(swaNew, SXW.SWAbulk_forb, sizeof(swaNew)); + for(i=0; i<4; i++){ + if(SXW.critSoilWater[t] >= SXW.critSoilWater[i]) + newCritSum += critSumByGroup[i]; + } + refactoredCrit = RGroup[g]->min_res_req / newCritSum; break; } ForEachTrPeriod(p) { for (l = 0; l < SXW.NSoLyrs; l++) { - use_by_group[g] += (RealF) (_roots_active_rel[Iglp(g, l, p)] * swaNew[p][l]); //min_res_req is space parameter + use_by_group[g] += (RealF) (_roots_active_rel[Iglp(g, l, p)] * refactoredCrit * swaNew[p][l]); //min_res_req is space parameter //printf("for groupName= %s, layerIndex: %d use_by_group[%d]= %f\n",RGroup[g]->name,l,g,use_by_group[g]); //printf("swaNew[%d][%d]: %f\n", p,l,swaNew[p][l]); } } sumUsedByGroup += use_by_group[g]; } - /*ForEachTrPeriod(p) - { - for (t = 0; t < SXW.NSoLyrs; t++) - sumSWATotal += SXW.transpTotal[Ilp(t, p)]; - } - SWARemaining = sumSWATotal - sumUsedByGroup; - printf("SWARemaining: %f\n", SWARemaining);*/ + SXW.transp_SWA[currentYear] += sumUsedByGroup; + //printf("SXW.transp_SWA[%d] = %f\n", currentYear, SXW.transp_SWA[currentYear]); } From 7bddbf16b8f72d531e56c48c8a3e302e7a13788b Mon Sep 17 00:00:00 2001 From: BrendenBe1 Date: Wed, 6 Sep 2017 16:48:38 -0700 Subject: [PATCH 026/111] Calculated SWX.transp_SWA for use in downstream functions --- ST_main.c | 14 +++++++++++++- sxw.h | 2 +- sxw_resource.c | 10 +++++++--- 3 files changed, 21 insertions(+), 5 deletions(-) diff --git a/ST_main.c b/ST_main.c index 37a053a8..fbcb1331 100644 --- a/ST_main.c +++ b/ST_main.c @@ -180,6 +180,8 @@ int main(int argc, char **argv) { RandSeed(Globals.randseed); Globals.currIter = iter; + memset(SXW.transp_SWA,0,sizeof(SXW.transp_SWA)); + /* ------ Begin running the model ------ */ for (year = 1; year <= Globals.runModelYears; year++) { Globals.currYear = year; @@ -236,7 +238,7 @@ int main(int argc, char **argv) { //printf("\nSWAbulk_forb_avg[1][0] = %f\n\n", SXW.SWAbulk_forb_avg[year][0]); }*/ // ###################################################################################### - + //printf("SXW.transp_SWA[%d] = %f\n", year, SXW.transp_SWA[year]); } /* end model run for this year*/ if (MortFlags.summary) { @@ -255,6 +257,16 @@ int main(int argc, char **argv) { if(Globals.currIter != Globals.runModelIterations) SXW_Reset(); } + printf("SXW.transp_SWA[1][0] sagebrush: %f\n", SXW.transp_SWA[1][0]); + printf("SXW.transp_SWA[1][1] a.cool.forb: %f\n", SXW.transp_SWA[1][1]); + printf("SXW.transp_SWA[1][2] a.warm.forb: %f\n", SXW.transp_SWA[1][2]); + printf("SXW.transp_SWA[1][3] p.cool.forb: %f\n", SXW.transp_SWA[1][3]); + printf("SXW.transp_SWA[1][4] p.warm.forb: %f\n", SXW.transp_SWA[1][4]); + printf("SXW.transp_SWA[1][5] a.cool.grass: %f\n", SXW.transp_SWA[1][5]); + printf("SXW.transp_SWA[1][6] p.cool.grass: %f\n", SXW.transp_SWA[1][6]); + printf("SXW.transp_SWA[1][7] p.warm.grass: %f\n", SXW.transp_SWA[1][7]); + printf("SXW.transp_SWA[1][8] shrub: %f\n", SXW.transp_SWA[1][8]); + printf("SXW.transp_SWA[1][9] succulents: %f\n\n", SXW.transp_SWA[1][9]); } /* end model run for this iteration*/ /*------------------------------------------------------*/ diff --git a/sxw.h b/sxw.h index 68095cc4..36de405a 100644 --- a/sxw.h +++ b/sxw.h @@ -79,7 +79,7 @@ struct stepwat_st { SWAbulk_forb[366][25], SWAbulk_forb_avg[366][25]; - RealF transp_SWA[MAX_YEARS]; + RealF transp_SWA[MAX_YEARS][11]; // store the sum of SWA and transp for each year and resource. transp_SWA[year][steppe_resource_group] // 2D array to store 4 critical values per layer diff --git a/sxw_resource.c b/sxw_resource.c index 9d2482cd..398edab1 100644 --- a/sxw_resource.c +++ b/sxw_resource.c @@ -242,6 +242,8 @@ static void _transp_contribution_by_group(RealF use_by_group[]) { { use_by_group[g] = 0.; /* clear */ t = RGroup[g]->veg_prod_type-1; + //printf("g: %d\n", g); + //printf("RGroup[g]->grp_num: %d\n", RGroup[g]->grp_num); switch(t) { case 0://Tree @@ -269,8 +271,9 @@ static void _transp_contribution_by_group(RealF use_by_group[]) { } } sumUsedByGroup += use_by_group[g]; + SXW.transp_SWA[currentYear][g] += sumUsedByGroup; } - SXW.transp_SWA[currentYear] += sumUsedByGroup; + //SXW.transp_SWA[currentYear][t-1] += sumUsedByGroup; //printf("SXW.transp_SWA[%d] = %f\n", currentYear, SXW.transp_SWA[currentYear]); // TODO: if redo upper part, can remove bottom part //Occasionally, extra transpiration remains and if not perfectly partitioned to RGroups. @@ -369,7 +372,8 @@ static void _SWA_contribution_by_group(RealF use_by_group[]) { } } sumUsedByGroup += use_by_group[g]; + + SXW.transp_SWA[currentYear][g] += sumUsedByGroup; + //printf("SXW.transp_SWA[%d][%d] = %f\n", currentYear, t, SXW.transp_SWA[currentYear][t-1]); } - SXW.transp_SWA[currentYear] += sumUsedByGroup; - //printf("SXW.transp_SWA[%d] = %f\n", currentYear, SXW.transp_SWA[currentYear]); } From 1c93dc7665be4cec596b8de04dbe30a2602c7006 Mon Sep 17 00:00:00 2001 From: BrendenBe1 Date: Fri, 8 Sep 2017 11:56:50 -0700 Subject: [PATCH 027/111] Passed new resource values to downstream functions --- ST_resgroups.c | 15 +++++++-------- sxw.c | 6 +++--- sxw_funcs.h | 2 +- sxw_resource.c | 4 +++- .../Stepwat_Inputs/Input/sxw/files_v30.in | 16 ++++++++-------- 5 files changed, 22 insertions(+), 21 deletions(-) diff --git a/ST_resgroups.c b/ST_resgroups.c index c43421f4..e9037ef0 100644 --- a/ST_resgroups.c +++ b/ST_resgroups.c @@ -144,7 +144,7 @@ void rgroup_PartResources(void) /* trick for later pr calc */ g->res_required = RGroup_GetBiomass(rg); - g->res_avail = SXW_GetTranspiration(rg); //1.0; + g->res_avail = SXW_GetResource(rg); //1.0; //PR limit can be really high see mort no_resource I limit to the groups estab indiv because that is what we can kill. //This was at 10 but ten might be to low or high in some cases. if(!ZRO(g->res_avail) && g->res_required / g->res_avail > g->estabs) @@ -161,13 +161,13 @@ void rgroup_PartResources(void) } //KAP:Previously, a seperate set of code was used to determine resource availability for annual species //Now, resource paritioning for annuals occurs in the same way as for perennials, by getting the RGroup Biomass - //and the resource_cur from SXW_GetTranspiration + //and the resource_cur from SXW_GetResource //Annuals seem to have a artificial limit of 20. We do Annuals here differently if(g->max_age == 1) { //{ ForEachGroupSpp(sp,rg,i) // g->res_required += Species[sp]->mature_biomass * .75;} - //g->res_avail = SXW_GetTranspiration(rg); + //g->res_avail = SXW_GetResource(rg); if(!ZRO(g->res_avail) && g->res_required / g->res_avail > 20) { g->res_required = 20; @@ -194,7 +194,7 @@ void rgroup_PartResources(void) extra resource partitioning does not occur when running SOILWAT*/ _res_part_extra(do_base, xtra_base, size_base); _res_part_extra(do_extra, xtra_obase, size_obase); - + /* reset annuals' "true" relative size here */ //KAP: formely, this call established annual species. We have moved annual establishment to the Rgroup_Establish function, //where all other resource groups establish (e.g. perennials). This function is no longer required. @@ -299,7 +299,7 @@ static RealF _add_annuals(const GrpIndex rg, const RealF g_pr, static RealF _get_annual_maxestab(SppIndex sp) { /*======================================================*/ - /* Get the maximum number of viable seeds from the seedbank that can + /* Get the maximum number of viable seeds from the seedbank that can establish this year*/ IntU i; RealF sum = 0.; @@ -722,7 +722,7 @@ void rgroup_Establish(void) * * Also, there's now a parameter to define the start year * of establishment for perennials. - * + * * KAP: Annual establishment now occurs here instead of in PartResources */ /*------------------------------------------------------*/ @@ -784,7 +784,7 @@ void rgroup_Establish(void) else { num_est = 0; - } + } //printf("num_est for annuals=%d \n",num_est); // above inserted to establish individuals for annuals @@ -1320,4 +1320,3 @@ void RGroup_SetMemoryRefs( void) creation imply that availability is not tied to relsize. */ - diff --git a/sxw.c b/sxw.c index 9f5e4a76..150fa400 100644 --- a/sxw.c +++ b/sxw.c @@ -394,7 +394,7 @@ void SXW_SW_Setup_Echo(void) { RealF SXW_GetPR( GrpIndex rg) { /*======================================================*/ /* see _sxw_update_resource() for _resource_cur[] -This function is no longer utilized, SXW_GetTranspiration has replaced it +This function is no longer utilized, SXW_GetResource has replaced it _resource_pr is no longer used as a parameter. We remain the code for the time being KAP 7/20/2016 */ @@ -403,11 +403,11 @@ KAP 7/20/2016 //return pr > 10 ? 10 : pr; } -RealF SXW_GetTranspiration( GrpIndex rg) { +RealF SXW_GetResource( GrpIndex rg) { /*======================================================*/ /* see _sxw_update_resource() for _resource_cur[] */ - //printf("SXW_GetTranspiration _resource_cur[%d] = %.5f \n", rg, _resource_cur[rg]); + //printf("SXW_GetResource _resource_cur[%d] = %.5f \n", rg, _resource_cur[rg]); return _resource_cur[rg]; } diff --git a/sxw_funcs.h b/sxw_funcs.h index ac84b4ae..b4a0e782 100644 --- a/sxw_funcs.h +++ b/sxw_funcs.h @@ -18,7 +18,7 @@ #include "sxw.h" RealF SXW_GetPR( GrpIndex rg) ; -RealF SXW_GetTranspiration( GrpIndex rg); +RealF SXW_GetResource( GrpIndex rg); RealF SXW_ResourceAvailable (void); diff --git a/sxw_resource.c b/sxw_resource.c index 398edab1..4b5d6b79 100644 --- a/sxw_resource.c +++ b/sxw_resource.c @@ -126,6 +126,7 @@ void _sxw_update_resource(void) { GrpIndex g; SppIndex sp; int i; + int currentYear = SW_Model.year-SW_Model.startyr; #ifdef SXW_BYMAXSIZE ForEachGroup(g) { @@ -154,6 +155,7 @@ void _sxw_update_resource(void) { ForEachGroup(g) { + _resource_cur[g] = SXW.transp_SWA[currentYear][g]; //_resource_pr[g] = ZRO(sizes[g]) ? 0.0 : _resource_cur[g] * _bvt / sizes[g]; _resource_cur[g] = _resource_cur[g] * _bvt; } @@ -271,7 +273,7 @@ static void _transp_contribution_by_group(RealF use_by_group[]) { } } sumUsedByGroup += use_by_group[g]; - SXW.transp_SWA[currentYear][g] += sumUsedByGroup; + SXW.transp_SWA[currentYear][g] += sumUsedByGroup; //SXW.transp_SWA[currentYear][resource_group] } //SXW.transp_SWA[currentYear][t-1] += sumUsedByGroup; //printf("SXW.transp_SWA[%d] = %f\n", currentYear, SXW.transp_SWA[currentYear]); diff --git a/testing.sagebrush.master/Stepwat_Inputs/Input/sxw/files_v30.in b/testing.sagebrush.master/Stepwat_Inputs/Input/sxw/files_v30.in index 3e2c52b9..1f2c943f 100644 --- a/testing.sagebrush.master/Stepwat_Inputs/Input/sxw/files_v30.in +++ b/testing.sagebrush.master/Stepwat_Inputs/Input/sxw/files_v30.in @@ -26,12 +26,12 @@ Input/swcsetup.in # params for handling measured swc #Output Output/ # 'relative' path for output files: / for same directory, or e.g., Output/ Input/outsetup_v30.in # define output quantities -Output/csv/daily.csv #output -Output/csv/weekly.csv #output -Output/csv/monthly.csv #output -Output/csv/yearly.csv #output +Output/csv/sw2_daily.csv #output +Output/csv/sw2_weekly.csv #output +Output/csv/sw2_monthly.csv #output +Output/csv/sw2_yearly.csv #output -Output/csv/daily_soil.csv #output -Output/csv/weekly_soil.csv #output -Output/csv/monthly_soil.csv #output -Output/csv/yearly_soil.csv #output +Output/csv/sw2_daily_slyrs.csv #output +Output/csv/sw2_weekly_slyrs.csv #output +Output/csv/sw2_monthly_slyrs.csv #output +Output/csv/sw2_yearly_slyrs.csv #output From 1768759f94e21ecbd512b6225473ccb67e466448 Mon Sep 17 00:00:00 2001 From: BrendenBe1 Date: Fri, 8 Sep 2017 13:59:09 -0700 Subject: [PATCH 028/111] Added input flag for storing output for every iteration --- ST_main.c | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/ST_main.c b/ST_main.c index fbcb1331..bcf09378 100644 --- a/ST_main.c +++ b/ST_main.c @@ -32,6 +32,7 @@ #endif extern Bool isPartialSoilwatOutput; +extern Bool storeAllIterations; /************* External Function Declarations **************/ /***********************************************************/ @@ -95,8 +96,9 @@ static void usage(void) { " -q : quiet mode, don't print message to check logfile.\n" " -s : use SOILWAT model for resource partitioning.\n" " -e : echo initialization results to logfile\n" - " -o : print all the soilwat output as well like standalone soilwat running\n" - " -g : use gridded mode\n"; + " -o : print all the soilwat output\n" + " -g : use gridded mode\n" + " -i : print SOILWAT output for each iteration\n"; // dont need to set -o flag to use this flag fprintf(stderr,"%s", s); exit(0); } @@ -145,6 +147,7 @@ int main(int argc, char **argv) { * was logged. see generic.h */ isPartialSoilwatOutput = TRUE; // dont want to get soilwat output unless -o flag + storeAllIterations = FALSE; // dont want to store all soilwat output iterations unless -i flag init_args(argc, argv); // if -o flag then well set isPartialSoilwatOutput to FALSE and get output @@ -386,8 +389,8 @@ static void init_args(int argc, char **argv) { * files_v30.in are written to. */ char str[1024], - *opts[] = {"-d","-f","-q","-s","-e", "-p", "-g", "-o"}; /* valid options */ - int valopts[] = { 1, 1, 0, -1, 0, 0 , 0, 0}; /* indicates options with values */ + *opts[] = {"-d","-f","-q","-s","-e", "-p", "-g", "-o", "-i"}; /* valid options */ + int valopts[] = { 1, 1, 0, -1, 0, 0 , 0, 0, 0}; /* indicates options with values */ /* 0=none, 1=required, -1=optional */ int i, /* looper through all cmdline arguments */ a, /* current valid argument-value position */ @@ -505,6 +508,11 @@ static void init_args(int argc, char **argv) { isPartialSoilwatOutput = FALSE; break; /* -o also get all the soilwat output*/ + case 8: + printf("storing SOILWAT output for all iterations\n"); + storeAllIterations = TRUE; + break; + default: LogError(logfp, LOGFATAL, "Programmer: bad option in main:init_args:switch"); From 98239bd8e7c4cc9837e90b7c0a8453e3b074765a Mon Sep 17 00:00:00 2001 From: BrendenBe1 Date: Mon, 11 Sep 2017 16:54:43 -0700 Subject: [PATCH 029/111] Working on issue #23, average over iterations --- ST_main.c | 40 +++++++++++++--------------------------- ST_stats.c | 21 +++++++++------------ 2 files changed, 22 insertions(+), 39 deletions(-) diff --git a/ST_main.c b/ST_main.c index bcf09378..11b4ef4f 100644 --- a/ST_main.c +++ b/ST_main.c @@ -140,6 +140,7 @@ int main(int argc, char **argv) { IntS year, iter, incr, g, s; IndivType *i; Bool killedany; + int k; logged = FALSE; atexit(check_log); @@ -215,33 +216,17 @@ int main(int argc, char **argv) { if (BmassFlags.yearly) output_Bmass_Yearly(year); - //stat_Average_SOILWAT_vars(SXW.SWAbulk_forb, SXW.SWAbulk_forb_avg); // need to make this work + // getting average over all iterations (currently works but only implemented for SXW.SWAbulk_forb currently) + if(!isPartialSoilwatOutput){ + for(k=0; k Date: Fri, 15 Sep 2017 13:51:00 -0700 Subject: [PATCH 030/111] Working on issue #23, average over iterations --- ST_main.c | 11 ++++++++++- ST_stats.c | 18 ++++++++++-------- sxw.h | 11 ++++++++++- 3 files changed, 30 insertions(+), 10 deletions(-) diff --git a/ST_main.c b/ST_main.c index 11b4ef4f..75c3b5df 100644 --- a/ST_main.c +++ b/ST_main.c @@ -219,7 +219,16 @@ int main(int argc, char **argv) { // getting average over all iterations (currently works but only implemented for SXW.SWAbulk_forb currently) if(!isPartialSoilwatOutput){ for(k=0; k Date: Mon, 18 Sep 2017 12:08:50 -0700 Subject: [PATCH 031/111] Commented out code for -i flag due to bug --- ST_main.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/ST_main.c b/ST_main.c index 75c3b5df..7b0a0b27 100644 --- a/ST_main.c +++ b/ST_main.c @@ -32,7 +32,7 @@ #endif extern Bool isPartialSoilwatOutput; -extern Bool storeAllIterations; +//extern Bool storeAllIterations; /************* External Function Declarations **************/ /***********************************************************/ @@ -148,7 +148,7 @@ int main(int argc, char **argv) { * was logged. see generic.h */ isPartialSoilwatOutput = TRUE; // dont want to get soilwat output unless -o flag - storeAllIterations = FALSE; // dont want to store all soilwat output iterations unless -i flag + //storeAllIterations = FALSE; // dont want to store all soilwat output iterations unless -i flag init_args(argc, argv); // if -o flag then well set isPartialSoilwatOutput to FALSE and get output @@ -503,10 +503,10 @@ static void init_args(int argc, char **argv) { isPartialSoilwatOutput = FALSE; break; /* -o also get all the soilwat output*/ - case 8: // -i + /*case 8: // -i printf("storing SOILWAT output for all iterations\n"); storeAllIterations = TRUE; - break; + break;*/ default: LogError(logfp, LOGFATAL, From 6fe0983eb138f41d7b21135cd74bc106b1358cb5 Mon Sep 17 00:00:00 2001 From: BrendenBe1 Date: Wed, 20 Sep 2017 16:51:44 -0700 Subject: [PATCH 032/111] Working on averaging output values over all iterations --- ST_main.c | 9 ++++++--- sxw.c | 32 ++++++++++++++++++++++++++++++++ sxw.h | 11 ++++++----- 3 files changed, 44 insertions(+), 8 deletions(-) diff --git a/ST_main.c b/ST_main.c index 7b0a0b27..52f7f2ae 100644 --- a/ST_main.c +++ b/ST_main.c @@ -248,7 +248,7 @@ int main(int argc, char **argv) { if (UseSoilwat) { - stat_Output_AllSoilwatVariables(); + //stat_Output_AllSoilwatVariables(); // dont need to restart if last iteration finished // this keeps it from re-writing the output folder and overwriting output files if(Globals.currIter != Globals.runModelIterations) @@ -273,11 +273,14 @@ int main(int argc, char **argv) { if (BmassFlags.summary) stat_Output_AllBmass(); - //printf("\n\n\nSWAbulk_forb_avg[1][0] = %f\n\n", SXW.SWAbulk_forb_avg[1][0]/Globals.runModelIterations); + //printf("\n\n\nSWAbulk_forb_avg[0][7] = %f\n\n", SXW.SWAbulk_forb_avg[0][7]/Globals.runModelIterations); #ifdef STEPWAT - if (!isnull(SXW.debugfile) ) SXW_PrintDebug(1); + if (!isnull(SXW.debugfile)){ + printf("entering debugfile\n"); + SXW_PrintDebug(1); + } #endif printf("\nend program\n"); diff --git a/sxw.c b/sxw.c index 150fa400..5211b097 100644 --- a/sxw.c +++ b/sxw.c @@ -900,6 +900,12 @@ static void _make_transp_arrays(void) { SXW.transpShrubs = (RealD *) Mem_Calloc(size, sizeof(RealD), fstr); SXW.transpForbs = (RealD *) Mem_Calloc(size, sizeof(RealD), fstr); SXW.transpGrasses = (RealD *) Mem_Calloc(size, sizeof(RealD), fstr); + + /*SXW.transpTotal_avg = (float *) Mem_Calloc(size, sizeof(float), fstr); + SXW.transpTrees_avg = (RealD *) Mem_Calloc(size, sizeof(RealD), fstr); + SXW.transpShrubs_avg = (RealD *) Mem_Calloc(size, sizeof(RealD), fstr); + SXW.transpForbs_avg = (RealD *) Mem_Calloc(size, sizeof(RealD), fstr); + SXW.transpGrasses_avg = (RealD *) Mem_Calloc(size, sizeof(RealD), fstr);*/ } @@ -1001,6 +1007,7 @@ static void _read_debugfile(void) { } void debugCleanUp() { + printf("in debugCleanUp\n"); disconnect(); } @@ -1240,16 +1247,41 @@ int getNTranspLayers(int veg_prod_type) { /***********************************************************/ void free_all_sxw_memory( void ) { free_sxw_memory(); + Mem_Free(SXW.f_files); Mem_Free(SXW.f_roots); Mem_Free(SXW.f_phen); Mem_Free(SXW.f_bvt); Mem_Free(SXW.f_prod); Mem_Free(SXW.f_watin); + Mem_Free(SXW.transpTotal); Mem_Free(SXW.transpTrees); Mem_Free(SXW.transpShrubs); Mem_Free(SXW.transpForbs); Mem_Free(SXW.transpGrasses); + /*Mem_Free(SXW.transpTotal_avg); + Mem_Free(SXW.transpTrees_avg); + Mem_Free(SXW.transpShrubs_avg); + Mem_Free(SXW.transpForbs_avg); + Mem_Free(SXW.transpGrasses_avg); + + Mem_Free(SXW.SWAbulk_grass); + Mem_Free(SXW.SWAbulk_shrub); + Mem_Free(SXW.SWAbulk_tree); + Mem_Free(SXW.SWAbulk_forb); + Mem_Free(SXW.SWAbulk_grass_avg); + Mem_Free(SXW.SWAbulk_shrub_avg); + Mem_Free(SXW.SWAbulk_tree_avg); + Mem_Free(SXW.SWAbulk_forb_avg); + + Mem_Free(SXW.SWCbulk); + Mem_Free(SXW.SWCoriginal); + Mem_Free(SXW.transp_SWA); + + Mem_Free(SXW.PPTVal); + Mem_Free(SXW.PPT_day); + Mem_Free(SXW.PPT_week); + Mem_Free(SXW.PPT_month);*/ if (SXW.debugfile || UseGrid) Mem_Free(SXW.swc); } diff --git a/sxw.h b/sxw.h index 3e14c40c..3ea6d9f7 100644 --- a/sxw.h +++ b/sxw.h @@ -36,11 +36,12 @@ struct stepwat_st { RealD *transpShrubs; RealD *transpForbs; RealD *transpGrasses; - RealD *transpTotal_avg; /* points to dynamic array indexed by Ilp() */ - RealD *transpTrees_avg; - RealD *transpShrubs_avg; - RealD *transpForbs_avg; - RealD *transpGrasses_avg; + + float transpTotal_avg[366][25], /* points to dynamic array indexed by Ilp() */ + transpTrees_avg[366][25], + transpShrubs_avg[366][25], + transpForbs_avg[366][25], + transpGrasses_avg[366][25]; RealF temp, /* soilwat's MAT */ ppt; /* soilwat's MAP */ From 69524456dedefcaf0f24ec4bcef80befc961c36f Mon Sep 17 00:00:00 2001 From: BrendenBe1 Date: Fri, 22 Sep 2017 13:54:00 -0700 Subject: [PATCH 033/111] Working on averaging output values over all iterations --- ST_main.c | 30 ------------------------------ sxw.c | 4 ++-- sxw.h | 7 ++++++- 3 files changed, 8 insertions(+), 33 deletions(-) diff --git a/ST_main.c b/ST_main.c index 52f7f2ae..fae02d3f 100644 --- a/ST_main.c +++ b/ST_main.c @@ -216,22 +216,6 @@ int main(int argc, char **argv) { if (BmassFlags.yearly) output_Bmass_Yearly(year); - // getting average over all iterations (currently works but only implemented for SXW.SWAbulk_forb currently) - if(!isPartialSoilwatOutput){ - for(k=0; k Date: Mon, 25 Sep 2017 17:04:53 -0700 Subject: [PATCH 034/111] Working on averaging output values over all iterations --- sxw.c | 21 +++++++++++++++++++-- sxw.h | 33 +++++++++++++-------------------- sxw_resource.c | 14 ++++++++++---- 3 files changed, 42 insertions(+), 26 deletions(-) diff --git a/sxw.c b/sxw.c index aa301099..08f7a324 100644 --- a/sxw.c +++ b/sxw.c @@ -149,6 +149,7 @@ static void _write_sw_outin(void); static void _read_debugfile(void); void _print_debuginfo(void); void debugCleanUp(void); +static void _make_swa_array(void); static void _make_swc_array(void); static void SXW_SW_Setup_Echo(void); //static void SXW_SW_Output_Echo(void); @@ -845,6 +846,7 @@ static void _make_arrays(void) { _make_phen_arrays(); _make_prod_arrays(); _make_transp_arrays(); + _make_swa_array(); if (SXW.debugfile || UseGrid) _make_swc_array(); } @@ -901,13 +903,28 @@ static void _make_transp_arrays(void) { SXW.transpForbs = (RealD *) Mem_Calloc(size, sizeof(RealD), fstr); SXW.transpGrasses = (RealD *) Mem_Calloc(size, sizeof(RealD), fstr); - /*SXW.transpTotal_avg = (float *) Mem_Calloc(size, sizeof(float), fstr); + SXW.transpTotal_avg = (RealD *) Mem_Calloc(size, sizeof(float), fstr); SXW.transpTrees_avg = (RealD *) Mem_Calloc(size, sizeof(RealD), fstr); SXW.transpShrubs_avg = (RealD *) Mem_Calloc(size, sizeof(RealD), fstr); SXW.transpForbs_avg = (RealD *) Mem_Calloc(size, sizeof(RealD), fstr); - SXW.transpGrasses_avg = (RealD *) Mem_Calloc(size, sizeof(RealD), fstr);*/ + SXW.transpGrasses_avg = (RealD *) Mem_Calloc(size, sizeof(RealD), fstr); + + //SXW.transp_SWA = (RealF *) Mem_Calloc(size, sizeof(RealD), fstr); } +static void _make_swa_array(void){ + char *fstr = "_make_swa_array()"; + int size = SXW.NPds * SXW.NSoLyrs; + + SXW.SWAbulk_grass = (RealF *) Mem_Calloc(size, sizeof(RealF *), fstr); + SXW.SWAbulk_shrub = (RealF *) Mem_Calloc(size, sizeof(RealF *), fstr); + SXW.SWAbulk_tree = (RealF *) Mem_Calloc(size, sizeof(RealF *), fstr); + SXW.SWAbulk_forb = (RealF *) Mem_Calloc(size, sizeof(RealF *), fstr); + SXW.SWAbulk_grass_avg = (RealF *) Mem_Calloc(size, sizeof(RealF *), fstr); + SXW.SWAbulk_shrub_avg = (RealF *) Mem_Calloc(size, sizeof(RealF *), fstr); + SXW.SWAbulk_tree_avg = (RealF *) Mem_Calloc(size, sizeof(RealF *), fstr); + SXW.SWAbulk_forb_avg = (RealF *) Mem_Calloc(size, sizeof(RealF *), fstr); +} static void _make_swc_array(void) { /*======================================================*/ diff --git a/sxw.h b/sxw.h index 997936f8..0abb54d2 100644 --- a/sxw.h +++ b/sxw.h @@ -37,11 +37,11 @@ struct stepwat_st { RealD *transpForbs; RealD *transpGrasses; - float transpTotal_avg[366][25], - transpTrees_avg[366][25], - transpShrubs_avg[366][25], - transpForbs_avg[366][25], - transpGrasses_avg[366][25]; + RealD *transpTotal_avg, + *transpTrees_avg, + *transpShrubs_avg, + *transpForbs_avg, + *transpGrasses_avg; RealF temp, /* soilwat's MAT */ ppt; /* soilwat's MAP */ @@ -58,11 +58,6 @@ struct stepwat_st { *f_prod, /* biomass to prod. conv. nos. */ *f_watin; /* soilwat's input file */ - /* % Cover from prod.in */ - /*float grass_cover, - shrub_cover, - tree_cover, - forbs_cover;*/ RealD critSoilWater[4]; // storing values in same order as defined in rgroup.in (0=tree, 1=shrub, 2=grass, 3=forb) /* DEBUG stuff */ @@ -79,15 +74,14 @@ struct stepwat_st { RealF PPT_week[500]; RealF PPT_month[500]; - // store converted SWA values - float SWAbulk_grass[366][25], // 2D array to store SWA vals ([days of year][number of max layers]) - SWAbulk_shrub[366][25], - SWAbulk_tree[366][25], - SWAbulk_forb[366][25], - SWAbulk_grass_avg[MAX_YEARS][25], // 2D array to store SWA vals ([days of year][number of max layers]) - SWAbulk_shrub_avg[MAX_YEARS][25], - SWAbulk_tree_avg[MAX_YEARS][25], - SWAbulk_forb_avg[MAX_YEARS][25]; + RealF *SWAbulk_grass, // 2D array to store SWA vals ([days of year][number of max layers]) + *SWAbulk_shrub, + *SWAbulk_tree, + *SWAbulk_forb, + *SWAbulk_grass_avg, // 2D array to store SWA vals ([days of year][number of max layers]) + *SWAbulk_shrub_avg, + *SWAbulk_tree_avg, + *SWAbulk_forb_avg; float tempMax_avg, // 2D array to store SWA vals ([days of year][number of max layers]) tempMin_avg, @@ -96,7 +90,6 @@ struct stepwat_st { RealF transp_SWA[MAX_YEARS][11]; // store the sum of SWA and transp for each year and resource. transp_SWA[year][steppe_resource_group] - // 2D array to store 4 critical values per layer float SWCbulk[4][8]; // TODO: first value needs to be (number of layers * plant types) - not hardcoded float SWCoriginal[500][8]; // storing SWC values here instead of in *swc since that does not have enough storage for more than month timestep diff --git a/sxw_resource.c b/sxw_resource.c index 4b5d6b79..c69b1638 100644 --- a/sxw_resource.c +++ b/sxw_resource.c @@ -126,7 +126,9 @@ void _sxw_update_resource(void) { GrpIndex g; SppIndex sp; int i; - int currentYear = SW_Model.year-SW_Model.startyr; + int currentYear; + if(SW_Model.year == 0) currentYear = 0; + else currentYear = SW_Model.year - SW_Model.startyr; #ifdef SXW_BYMAXSIZE ForEachGroup(g) { @@ -235,7 +237,9 @@ static void _transp_contribution_by_group(RealF use_by_group[]) { SppIndex s; TimeInt p; LyrIndex l; - int currentYear = SW_Model.year-SW_Model.startyr; + int currentYear; + if(SW_Model.year == 0) currentYear = 0; + else currentYear = SW_Model.year - SW_Model.startyr; int t,i; RealD *transp; RealF sumUsedByGroup = 0., sumTranspTotal = 0., TranspRemaining = 0.; @@ -273,7 +277,7 @@ static void _transp_contribution_by_group(RealF use_by_group[]) { } } sumUsedByGroup += use_by_group[g]; - SXW.transp_SWA[currentYear][g] += sumUsedByGroup; //SXW.transp_SWA[currentYear][resource_group] + SXW.transp_SWA[currentYear][g] += sumUsedByGroup; } //SXW.transp_SWA[currentYear][t-1] += sumUsedByGroup; //printf("SXW.transp_SWA[%d] = %f\n", currentYear, SXW.transp_SWA[currentYear]); @@ -299,7 +303,9 @@ static void _SWA_contribution_by_group(RealF use_by_group[]) { SppIndex s; TimeInt p; LyrIndex l; - int currentYear = SW_Model.year-SW_Model.startyr; + int currentYear; + if(SW_Model.year == 0) currentYear = 0; + else currentYear = SW_Model.year - SW_Model.startyr; int t,i; float swaNew[366][25]; RealF sumUsedByGroup = 0., sumSWATotal = 0., SWARemaining = 0.; From 24a9b9d0e407043f28586924193a2989ba3dbed7 Mon Sep 17 00:00:00 2001 From: BrendenBe1 Date: Wed, 27 Sep 2017 14:04:41 -0700 Subject: [PATCH 035/111] Resolving Memory Error in Iteration Average Storage --- sxw.c | 2 +- sxw_resource.c | 61 ++++++-------------------------------------------- 2 files changed, 8 insertions(+), 55 deletions(-) diff --git a/sxw.c b/sxw.c index 08f7a324..f6786925 100644 --- a/sxw.c +++ b/sxw.c @@ -903,7 +903,7 @@ static void _make_transp_arrays(void) { SXW.transpForbs = (RealD *) Mem_Calloc(size, sizeof(RealD), fstr); SXW.transpGrasses = (RealD *) Mem_Calloc(size, sizeof(RealD), fstr); - SXW.transpTotal_avg = (RealD *) Mem_Calloc(size, sizeof(float), fstr); + SXW.transpTotal_avg = (RealD *) Mem_Calloc(size, sizeof(RealD), fstr); SXW.transpTrees_avg = (RealD *) Mem_Calloc(size, sizeof(RealD), fstr); SXW.transpShrubs_avg = (RealD *) Mem_Calloc(size, sizeof(RealD), fstr); SXW.transpForbs_avg = (RealD *) Mem_Calloc(size, sizeof(RealD), fstr); diff --git a/sxw_resource.c b/sxw_resource.c index c69b1638..558a481d 100644 --- a/sxw_resource.c +++ b/sxw_resource.c @@ -248,8 +248,6 @@ static void _transp_contribution_by_group(RealF use_by_group[]) { { use_by_group[g] = 0.; /* clear */ t = RGroup[g]->veg_prod_type-1; - //printf("g: %d\n", g); - //printf("RGroup[g]->grp_num: %d\n", RGroup[g]->grp_num); switch(t) { case 0://Tree @@ -279,8 +277,6 @@ static void _transp_contribution_by_group(RealF use_by_group[]) { sumUsedByGroup += use_by_group[g]; SXW.transp_SWA[currentYear][g] += sumUsedByGroup; } - //SXW.transp_SWA[currentYear][t-1] += sumUsedByGroup; - //printf("SXW.transp_SWA[%d] = %f\n", currentYear, SXW.transp_SWA[currentYear]); // TODO: if redo upper part, can remove bottom part //Occasionally, extra transpiration remains and if not perfectly partitioned to RGroups. //This check makes sure any remaining transpiration is divided proportionately among Rgroups. @@ -307,81 +303,38 @@ static void _SWA_contribution_by_group(RealF use_by_group[]) { if(SW_Model.year == 0) currentYear = 0; else currentYear = SW_Model.year - SW_Model.startyr; int t,i; - float swaNew[366][25]; + RealF *swaNew; RealF sumUsedByGroup = 0., sumSWATotal = 0., SWARemaining = 0.; - // values for refactored equation - RealD critSumByGroup[MAX_RGROUPS] = {0.}; - RealD refactoredCrit = 0; - - - ForEachGroup(g) - { - t = RGroup[g]->veg_prod_type-1; - critSumByGroup[t] += RGroup[g]->min_res_req; // get the critical value sums - } - - ForEachGroup(g) // steppe functional group { use_by_group[g] = 0.; // clear - float newCritSum = 0.; t = RGroup[g]->veg_prod_type-1; switch(t) { case 0://Tree - memcpy(swaNew, SXW.SWAbulk_tree, sizeof(swaNew)); // copy values into array - // need to include all the veg types in the range of the critical soil water potential - for(i=0; i<4; i++){ // loop through 4 times, once per veg type - if(SXW.critSoilWater[t] >= SXW.critSoilWater[i]) // if the veg type being used is bigger than the others need to include those others - newCritSum += critSumByGroup[i]; // make new sum for proper scaling - /* reason is to get the values for these to scale so they equal 1 requires getting sum of all in use and then dividing - // each individual one by the sum of all to make the total add up to 1 but retain the difference in the individual elements - // for example if shrubs critical soil water potential (csp) is -3.9 and grasses csp is -3.5 and you are running on - // grasses then you need to include all the values for shrubs and grasses since both are getting resources at that depth - */ - } - refactoredCrit = RGroup[g]->min_res_req / newCritSum; // get new critical value for use in equation below + swaNew = SXW.SWAbulk_tree; break; case 1://Shrub - memcpy(swaNew, SXW.SWAbulk_shrub, sizeof(swaNew)); - for(i=0; i<4; i++){ - if(SXW.critSoilWater[t] >= SXW.critSoilWater[i]) - newCritSum += critSumByGroup[i]; - } - refactoredCrit = RGroup[g]->min_res_req / newCritSum; + swaNew = SXW.SWAbulk_shrub; break; case 2://Grass - memcpy(swaNew, SXW.SWAbulk_grass, sizeof(swaNew)); - for(i=0; i<4; i++){ - if(SXW.critSoilWater[t] >= SXW.critSoilWater[i]) - newCritSum += critSumByGroup[i]; - } - refactoredCrit = RGroup[g]->min_res_req / newCritSum; + swaNew = SXW.SWAbulk_grass; break; case 3://Forb - memcpy(swaNew, SXW.SWAbulk_forb, sizeof(swaNew)); - for(i=0; i<4; i++){ - if(SXW.critSoilWater[t] >= SXW.critSoilWater[i]) - newCritSum += critSumByGroup[i]; - } - refactoredCrit = RGroup[g]->min_res_req / newCritSum; - break; + swaNew = SXW.SWAbulk_forb; + break; } ForEachTrPeriod(p) { for (l = 0; l < SXW.NSoLyrs; l++) { - use_by_group[g] += (RealF) (_roots_active_rel[Iglp(g, l, p)] * refactoredCrit * swaNew[p][l]); //min_res_req is space parameter - //printf("for groupName= %s, layerIndex: %d use_by_group[%d]= %f\n",RGroup[g]->name,l,g,use_by_group[g]); - //printf("swaNew[%d][%d]: %f\n", p,l,swaNew[p][l]); + use_by_group[g] += (RealF) (_roots_active_rel[Iglp(g, l, p)] * swaNew[Ilp(l, p)]); //min_res_req is space parameter } } sumUsedByGroup += use_by_group[g]; - SXW.transp_SWA[currentYear][g] += sumUsedByGroup; - //printf("SXW.transp_SWA[%d][%d] = %f\n", currentYear, t, SXW.transp_SWA[currentYear][t-1]); } } From 595f5af5bcc1a794ba14c9b86d9888551fa339b0 Mon Sep 17 00:00:00 2001 From: BrendenBe1 Date: Wed, 27 Sep 2017 15:55:10 -0700 Subject: [PATCH 036/111] Resolving Memory Error in Iteration Average Storage --- sxw.c | 5 +++-- sxw.h | 8 +++++++- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/sxw.c b/sxw.c index f6786925..8fb1e811 100644 --- a/sxw.c +++ b/sxw.c @@ -847,7 +847,7 @@ static void _make_arrays(void) { _make_prod_arrays(); _make_transp_arrays(); _make_swa_array(); - if (SXW.debugfile || UseGrid) + //if (SXW.debugfile || UseGrid) _make_swc_array(); } @@ -1299,7 +1299,8 @@ void free_all_sxw_memory( void ) { Mem_Free(SXW.PPT_day); Mem_Free(SXW.PPT_week); Mem_Free(SXW.PPT_month); - if (SXW.debugfile || UseGrid) Mem_Free(SXW.swc); + //if (SXW.debugfile || UseGrid) + Mem_Free(SXW.swc); } /***********************************************************/ diff --git a/sxw.h b/sxw.h index 0abb54d2..557fd693 100644 --- a/sxw.h +++ b/sxw.h @@ -74,6 +74,12 @@ struct stepwat_st { RealF PPT_week[500]; RealF PPT_month[500]; + RealF PPT_sum, + PPT_rain, + PPT_snow_fall, + PPT_snow_melt, + PPT_snow_loss; + RealF *SWAbulk_grass, // 2D array to store SWA vals ([days of year][number of max layers]) *SWAbulk_shrub, *SWAbulk_tree, @@ -83,7 +89,7 @@ struct stepwat_st { *SWAbulk_tree_avg, *SWAbulk_forb_avg; - float tempMax_avg, // 2D array to store SWA vals ([days of year][number of max layers]) + float tempMax_avg, tempMin_avg, tempAvgAir_avg, tempSoilSurfaceTemp_avg; From 0fc92d1577372950a42a6cc663b8196dc5240bfa Mon Sep 17 00:00:00 2001 From: BrendenBe1 Date: Fri, 29 Sep 2017 13:51:26 -0700 Subject: [PATCH 037/111] Overhaul SWAbulk arrays --- sxw.c | 11 +++++++++-- sxw.h | 3 +++ sxw_resource.c | 18 +++++++++--------- 3 files changed, 21 insertions(+), 11 deletions(-) diff --git a/sxw.c b/sxw.c index 8fb1e811..358a30fe 100644 --- a/sxw.c +++ b/sxw.c @@ -908,8 +908,6 @@ static void _make_transp_arrays(void) { SXW.transpShrubs_avg = (RealD *) Mem_Calloc(size, sizeof(RealD), fstr); SXW.transpForbs_avg = (RealD *) Mem_Calloc(size, sizeof(RealD), fstr); SXW.transpGrasses_avg = (RealD *) Mem_Calloc(size, sizeof(RealD), fstr); - - //SXW.transp_SWA = (RealF *) Mem_Calloc(size, sizeof(RealD), fstr); } static void _make_swa_array(void){ @@ -920,10 +918,16 @@ static void _make_swa_array(void){ SXW.SWAbulk_shrub = (RealF *) Mem_Calloc(size, sizeof(RealF *), fstr); SXW.SWAbulk_tree = (RealF *) Mem_Calloc(size, sizeof(RealF *), fstr); SXW.SWAbulk_forb = (RealF *) Mem_Calloc(size, sizeof(RealF *), fstr); + SXW.SWAbulk_grass_avg = (RealF *) Mem_Calloc(size, sizeof(RealF *), fstr); SXW.SWAbulk_shrub_avg = (RealF *) Mem_Calloc(size, sizeof(RealF *), fstr); SXW.SWAbulk_tree_avg = (RealF *) Mem_Calloc(size, sizeof(RealF *), fstr); SXW.SWAbulk_forb_avg = (RealF *) Mem_Calloc(size, sizeof(RealF *), fstr); + + //4 - Grass,Frob,Tree,Shrub + size = 4 * SXW.NPds * SXW.NSoLyrs; + SXW.SWA_master = (RealF *) Mem_Calloc(size, sizeof(RealF), fstr); + SXW.dSWAbulk = (RealF *) Mem_Calloc(size, sizeof(RealF), fstr); } static void _make_swc_array(void) { @@ -1291,6 +1295,9 @@ void free_all_sxw_memory( void ) { Mem_Free(SXW.SWAbulk_tree_avg); Mem_Free(SXW.SWAbulk_forb_avg); + Mem_Free(SXW.SWA_master); + Mem_Free(SXW.dSWAbulk); + Mem_Free(SXW.SWCbulk); Mem_Free(SXW.SWCoriginal); Mem_Free(SXW.transp_SWA); diff --git a/sxw.h b/sxw.h index 557fd693..3d7c33aa 100644 --- a/sxw.h +++ b/sxw.h @@ -89,6 +89,9 @@ struct stepwat_st { *SWAbulk_tree_avg, *SWAbulk_forb_avg; + RealF *SWA_master, // 3D array + *dSWAbulk; + float tempMax_avg, tempMin_avg, tempAvgAir_avg, diff --git a/sxw_resource.c b/sxw_resource.c index 558a481d..3f6b1590 100644 --- a/sxw_resource.c +++ b/sxw_resource.c @@ -189,7 +189,7 @@ void _sxw_update_root_tables( RealF sizes[] ) { { x = _rootsXphen[Iglp(g, l, p)] * sizes[g]; _roots_active[Iglp(g, l, p)] = x; - _roots_active_sum[Itlp(t,l, p)] += x; + _roots_active_sum[Itlp(t, l, p)] += x; } } } @@ -303,35 +303,35 @@ static void _SWA_contribution_by_group(RealF use_by_group[]) { if(SW_Model.year == 0) currentYear = 0; else currentYear = SW_Model.year - SW_Model.startyr; int t,i; - RealF *swaNew; + //RealF *swaNew; RealF sumUsedByGroup = 0., sumSWATotal = 0., SWARemaining = 0.; ForEachGroup(g) // steppe functional group { use_by_group[g] = 0.; // clear t = RGroup[g]->veg_prod_type-1; - switch(t) + /*switch(t) { case 0://Tree - swaNew = SXW.SWAbulk_tree; + //swaNew = SXW.SWAbulk_tree; break; case 1://Shrub - swaNew = SXW.SWAbulk_shrub; + //swaNew = SXW.SWAbulk_shrub; break; case 2://Grass - swaNew = SXW.SWAbulk_grass; + //swaNew = SXW.SWAbulk_grass; break; case 3://Forb - swaNew = SXW.SWAbulk_forb; + //swaNew = SXW.SWAbulk_forb; break; - } + }*/ ForEachTrPeriod(p) { for (l = 0; l < SXW.NSoLyrs; l++) { - use_by_group[g] += (RealF) (_roots_active_rel[Iglp(g, l, p)] * swaNew[Ilp(l, p)]); //min_res_req is space parameter + use_by_group[g] += (RealF) (_roots_active_rel[Iglp(g, l, p)] * SXW.SWA_master[Itlp(t,l,p)]); //min_res_req is space parameter } } sumUsedByGroup += use_by_group[g]; From 1764e56ca9366f968f9030a8e0a206a5683781f8 Mon Sep 17 00:00:00 2001 From: BrendenBe1 Date: Wed, 4 Oct 2017 16:02:36 -0700 Subject: [PATCH 038/111] -i flag is functional (outputs data for each individual iteration) --- ST_main.c | 18 +++++++++--- sxw.h | 7 +++++ sxw_resource.c | 76 +++++++++++++++++++++++++++++++++++++------------- 3 files changed, 78 insertions(+), 23 deletions(-) diff --git a/ST_main.c b/ST_main.c index fae02d3f..6643a1dc 100644 --- a/ST_main.c +++ b/ST_main.c @@ -32,7 +32,7 @@ #endif extern Bool isPartialSoilwatOutput; -//extern Bool storeAllIterations; +extern Bool storeAllIterations; /************* External Function Declarations **************/ /***********************************************************/ @@ -148,7 +148,7 @@ int main(int argc, char **argv) { * was logged. see generic.h */ isPartialSoilwatOutput = TRUE; // dont want to get soilwat output unless -o flag - //storeAllIterations = FALSE; // dont want to store all soilwat output iterations unless -i flag + storeAllIterations = FALSE; // dont want to store all soilwat output iterations unless -i flag init_args(argc, argv); // if -o flag then well set isPartialSoilwatOutput to FALSE and get output @@ -177,6 +177,12 @@ int main(int argc, char **argv) { fprintf(progfp, "%d\n", iter); } + // set these to 0 for use with -i flag + SXW.col_status_dy = 0; + SXW.col_status_wk = 0; + SXW.col_status_mo = 0; + SXW.col_status_yr = 0; + if (BmassFlags.yearly || MortFlags.yearly) parm_Initialize(iter); @@ -476,10 +482,10 @@ static void init_args(int argc, char **argv) { isPartialSoilwatOutput = FALSE; break; /* -o also get all the soilwat output*/ - /*case 8: // -i + case 8: // -i printf("storing SOILWAT output for all iterations\n"); storeAllIterations = TRUE; - break;*/ + break; default: LogError(logfp, LOGFATAL, @@ -487,6 +493,10 @@ static void init_args(int argc, char **argv) { } a++; /* move to next valid option-value position */ + if(isPartialSoilwatOutput == FALSE && storeAllIterations){ + printf("\n\ncant use both -i and -o flags\n\n"); + break; + } } /* end for(i) */ diff --git a/sxw.h b/sxw.h index 3d7c33aa..392e6eb7 100644 --- a/sxw.h +++ b/sxw.h @@ -92,6 +92,8 @@ struct stepwat_st { RealF *SWA_master, // 3D array *dSWAbulk; + int rank_SWPcrits[5]; // array to store the SWP crits in order of lest negative to most negative (used in sxw_resource) + float tempMax_avg, tempMin_avg, tempAvgAir_avg, @@ -106,6 +108,11 @@ struct stepwat_st { int curInterval; int tempInt; + int col_status_dy; + int col_status_wk; + int col_status_mo; + int col_status_yr; + }; #define SXW_NFILES 5 diff --git a/sxw_resource.c b/sxw_resource.c index 3f6b1590..83954512 100644 --- a/sxw_resource.c +++ b/sxw_resource.c @@ -303,31 +303,69 @@ static void _SWA_contribution_by_group(RealF use_by_group[]) { if(SW_Model.year == 0) currentYear = 0; else currentYear = SW_Model.year - SW_Model.startyr; int t,i; - //RealF *swaNew; RealF sumUsedByGroup = 0., sumSWATotal = 0., SWARemaining = 0.; + /* + ############################################################################## + new needs to be done only 1 time + move to location where stuff is only executed on first run and first iteration + ############################################################################## + */ + int j; + float key; + RealF tempArray[4]; + tempArray[0] = SXW.critSoilWater[0]; + tempArray[1] = SXW.critSoilWater[1]; + tempArray[2] = SXW.critSoilWater[2]; + tempArray[3] = SXW.critSoilWater[3]; + + //printf("tempArray[1]%f\n", tempArray[1]); + //printf("tempArray[2]%f\n", tempArray[2]); + /*printf("%f\n", tempArray[0]); + printf("%f\n", tempArray[1]); + printf("%f\n", tempArray[2]); + printf("%f\n\n", tempArray[3]);*/ + + // -------------------------------------------------------------------------- + // insertion sort to rank the veg types and store them in their proper order + for (i = 1; i < 4; i++) + { + key = tempArray[i]; + j = i-1; + while (j >= 0 && tempArray[j] < key) + { + tempArray[j+1] = tempArray[j]; + SXW.rank_SWPcrits[j+2] = j; + //printf("j: %d\n", j); + j = j-1; + } + tempArray[j+1] = key; + SXW.rank_SWPcrits[j+2] = i; + //printf("i: %d\n", i); + } + + //printf("%d\n", SXW.rank_SWPcrits[0]); + /*printf("%d = %f\n", SXW.rank_SWPcrits[1], tempArray[0]); + printf("%d = %f\n", SXW.rank_SWPcrits[2], tempArray[1]); + printf("%d = %f\n", SXW.rank_SWPcrits[3], tempArray[2]); + printf("%d = %f\n\n", SXW.rank_SWPcrits[4], tempArray[3]);*/ + + /*printf("%f\n", tempArray[0]); + printf("%f\n", tempArray[1]); + printf("%f\n", tempArray[2]); + printf("%f\n\n", tempArray[3]);*/ + // -------------------------------------------------------------------------- + /* + ############################################################################## + end of stuff that only needs to be done once + ############################################################################## + */ + ForEachGroup(g) // steppe functional group { use_by_group[g] = 0.; // clear t = RGroup[g]->veg_prod_type-1; - /*switch(t) - { - case 0://Tree - //swaNew = SXW.SWAbulk_tree; - break; - - case 1://Shrub - //swaNew = SXW.SWAbulk_shrub; - break; - - case 2://Grass - //swaNew = SXW.SWAbulk_grass; - break; - - case 3://Forb - //swaNew = SXW.SWAbulk_forb; - break; - }*/ + ForEachTrPeriod(p) { for (l = 0; l < SXW.NSoLyrs; l++) { From 27e5b587b32bb38d34e25d2eaa0c5d9150431ab0 Mon Sep 17 00:00:00 2001 From: BrendenBe1 Date: Fri, 6 Oct 2017 13:55:26 -0700 Subject: [PATCH 039/111] Calculating dSWAbulk for use in _SWA_contribution_by_group --- README.md | 6 ++--- ST_main.c | 43 ++++++++++++++++++++++++++++++ sxw.h | 6 ++--- sxw_resource.c | 71 +++++++++----------------------------------------- 4 files changed, 61 insertions(+), 65 deletions(-) diff --git a/README.md b/README.md index a091d1b1..6d4c588e 100644 --- a/README.md +++ b/README.md @@ -34,13 +34,14 @@ Other tasks: ``` ``` -> Usage: stepwat [-d startdir] [-f files.in] [-q] [-s] [-e] [-o] [-g] +> Usage: stepwat [-d startdir] [-f files.in] [-q] [-s] [-e] [-o] [-i] [-g] > -d : supply working directory (default=.) > -f : supply list of input files (default=files.in) > -q : quiet mode, don't print message to check logfile. > -s : use SOILWAT model for resource partitioning. > -e : echo initialization results to logfile -> -o : print all the soilwat output in addition to the stepwat output +> -o : print all the soilwat output (averaged over all iterations) in addition to the stepwat output +> -i : print soilwat output for each iteration > -g : use gridded mode ``` @@ -79,4 +80,3 @@ Contributors are encouraged, however, to update local clones to [point to the ne ``` git remote set-url origin https://github.com/Burke-Lauenroth-Lab/STEPWAT2.git ``` - diff --git a/ST_main.c b/ST_main.c index 6643a1dc..fe6627f0 100644 --- a/ST_main.c +++ b/ST_main.c @@ -168,6 +168,49 @@ int main(int argc, char **argv) { if (incr == 0) incr = 1; + /*---------------------------------------------------------- + Get proper order for rank_SWPcrits + ----------------------------------------------------------*/ + int outerLoop, innerLoop; + float key; + RealF tempArray[4]; + tempArray[0] = SXW.critSoilWater[0]; + tempArray[1] = SXW.critSoilWater[1]; + tempArray[2] = SXW.critSoilWater[2]; + tempArray[3] = SXW.critSoilWater[3]; + + /*printf("%f\n", tempArray[0]); + printf("%f\n", tempArray[1]); + printf("%f\n", tempArray[2]); + printf("%f\n\n", tempArray[3]);*/ + + // insertion sort to rank the veg types and store them in their proper order + for (outerLoop = 1; outerLoop < 4; outerLoop++) + { + key = tempArray[outerLoop]; + innerLoop = outerLoop-1; + while (innerLoop >= 0 && tempArray[innerLoop] < key) + { + tempArray[innerLoop+1] = tempArray[innerLoop]; + SXW.rank_SWPcrits[innerLoop+2] = innerLoop; + //printf("innerLoop: %d\n", innerLoop); + innerLoop = innerLoop-1; + } + tempArray[innerLoop+1] = key; + SXW.rank_SWPcrits[innerLoop+2] = outerLoop; + //printf("outerLoop: %d\n", outerLoop); + } + SXW.rank_SWPcrits[0] = 0; + + /*printf("%d = %f\n", SXW.rank_SWPcrits[1], tempArray[0]); + printf("%d = %f\n", SXW.rank_SWPcrits[2], tempArray[1]); + printf("%d = %f\n", SXW.rank_SWPcrits[3], tempArray[2]); + printf("%d = %f\n\n", SXW.rank_SWPcrits[4], tempArray[3]);*/ + + /*---------------------------------------------------------- + End of rank_SWPcrits + ----------------------------------------------------------*/ + /* --- Begin a new iteration ------ */ for (iter = 1; iter <= Globals.runModelIterations; iter++) { if (progfp == stderr) { diff --git a/sxw.h b/sxw.h index 392e6eb7..4ecba802 100644 --- a/sxw.h +++ b/sxw.h @@ -104,10 +104,8 @@ struct stepwat_st { // 2D array to store 4 critical values per layer float SWCbulk[4][8]; // TODO: first value needs to be (number of layers * plant types) - not hardcoded float SWCoriginal[500][8]; // storing SWC values here instead of in *swc since that does not have enough storage for more than month timestep - - int curInterval; - int tempInt; - + + // used in SW_Output.c for creating column headers int col_status_dy; int col_status_wk; int col_status_mo; diff --git a/sxw_resource.c b/sxw_resource.c index 83954512..80782254 100644 --- a/sxw_resource.c +++ b/sxw_resource.c @@ -277,7 +277,7 @@ static void _transp_contribution_by_group(RealF use_by_group[]) { sumUsedByGroup += use_by_group[g]; SXW.transp_SWA[currentYear][g] += sumUsedByGroup; } - // TODO: if redo upper part, can remove bottom part + //Occasionally, extra transpiration remains and if not perfectly partitioned to RGroups. //This check makes sure any remaining transpiration is divided proportionately among Rgroups. ForEachTrPeriod(p) @@ -296,70 +296,15 @@ static void _transp_contribution_by_group(RealF use_by_group[]) { static void _SWA_contribution_by_group(RealF use_by_group[]) { GrpIndex g; - SppIndex s; TimeInt p; LyrIndex l; int currentYear; if(SW_Model.year == 0) currentYear = 0; else currentYear = SW_Model.year - SW_Model.startyr; - int t,i; + int t,kv,id_prev_veg; RealF sumUsedByGroup = 0., sumSWATotal = 0., SWARemaining = 0.; - /* - ############################################################################## - new needs to be done only 1 time - move to location where stuff is only executed on first run and first iteration - ############################################################################## - */ - int j; - float key; - RealF tempArray[4]; - tempArray[0] = SXW.critSoilWater[0]; - tempArray[1] = SXW.critSoilWater[1]; - tempArray[2] = SXW.critSoilWater[2]; - tempArray[3] = SXW.critSoilWater[3]; - - //printf("tempArray[1]%f\n", tempArray[1]); - //printf("tempArray[2]%f\n", tempArray[2]); - /*printf("%f\n", tempArray[0]); - printf("%f\n", tempArray[1]); - printf("%f\n", tempArray[2]); - printf("%f\n\n", tempArray[3]);*/ - - // -------------------------------------------------------------------------- - // insertion sort to rank the veg types and store them in their proper order - for (i = 1; i < 4; i++) - { - key = tempArray[i]; - j = i-1; - while (j >= 0 && tempArray[j] < key) - { - tempArray[j+1] = tempArray[j]; - SXW.rank_SWPcrits[j+2] = j; - //printf("j: %d\n", j); - j = j-1; - } - tempArray[j+1] = key; - SXW.rank_SWPcrits[j+2] = i; - //printf("i: %d\n", i); - } - - //printf("%d\n", SXW.rank_SWPcrits[0]); - /*printf("%d = %f\n", SXW.rank_SWPcrits[1], tempArray[0]); - printf("%d = %f\n", SXW.rank_SWPcrits[2], tempArray[1]); - printf("%d = %f\n", SXW.rank_SWPcrits[3], tempArray[2]); - printf("%d = %f\n\n", SXW.rank_SWPcrits[4], tempArray[3]);*/ - - /*printf("%f\n", tempArray[0]); - printf("%f\n", tempArray[1]); - printf("%f\n", tempArray[2]); - printf("%f\n\n", tempArray[3]);*/ - // -------------------------------------------------------------------------- - /* - ############################################################################## - end of stuff that only needs to be done once - ############################################################################## - */ + int index_sw_veg_types[4] = {1, 2, 3, 4}; // temp array for veg_types (need to find actual array where this info is stored) ForEachGroup(g) // steppe functional group { @@ -368,7 +313,17 @@ static void _SWA_contribution_by_group(RealF use_by_group[]) { ForEachTrPeriod(p) { + for (l = 0; l < SXW.NSoLyrs; l++) { + // loop to get dSWAbulk + for(kv=0; kv<4; kv++){ + id_prev_veg = SXW.rank_SWPcrits[kv+1]; // get prev veg type + SXW.dSWAbulk[Iglp(kv,l,p)] = SXW.SWA_master[Itlp(kv,p,l)]-SXW.SWA_master[Itlp(id_prev_veg,p,l)]; //Itlp(veg_type, timeperiod, layer) + + //printf("SXW.SWA_master[Itlp(%d,%d,%d)]: %f || SXW.SWA_master[Itlp(%d,%d,%d)]: %f\n", + //kv, p, l, SXW.SWA_master[Itlp(kv,p,l)], id_prev_veg, p, l, SXW.SWA_master[Itlp(id_prev_veg,p,l)]); + //printf("SXW.dSWAbulk[Iglp(kv,l,p)]: %f\n", SXW.dSWAbulk[Iglp(kv,l,p)]); + } use_by_group[g] += (RealF) (_roots_active_rel[Iglp(g, l, p)] * SXW.SWA_master[Itlp(t,l,p)]); //min_res_req is space parameter } } From cb93bd8b229ba25961f2b6ef200b34ad72560206 Mon Sep 17 00:00:00 2001 From: BrendenBe1 Date: Mon, 9 Oct 2017 17:14:25 -0700 Subject: [PATCH 040/111] Able to use -o & -i flags together --- ST_main.c | 23 ++++++++++------------- sxw_resource.c | 14 +------------- 2 files changed, 11 insertions(+), 26 deletions(-) diff --git a/ST_main.c b/ST_main.c index fe6627f0..581ce440 100644 --- a/ST_main.c +++ b/ST_main.c @@ -150,7 +150,7 @@ int main(int argc, char **argv) { isPartialSoilwatOutput = TRUE; // dont want to get soilwat output unless -o flag storeAllIterations = FALSE; // dont want to store all soilwat output iterations unless -i flag - init_args(argc, argv); // if -o flag then well set isPartialSoilwatOutput to FALSE and get output + init_args(argc, argv); // read input arguments and intialize proper flags printf("STEPWAT init_args() executed successfully \n "); @@ -179,6 +179,7 @@ int main(int argc, char **argv) { tempArray[2] = SXW.critSoilWater[2]; tempArray[3] = SXW.critSoilWater[3]; + // printing for testing purposes /*printf("%f\n", tempArray[0]); printf("%f\n", tempArray[1]); printf("%f\n", tempArray[2]); @@ -191,17 +192,16 @@ int main(int argc, char **argv) { innerLoop = outerLoop-1; while (innerLoop >= 0 && tempArray[innerLoop] < key) { - tempArray[innerLoop+1] = tempArray[innerLoop]; - SXW.rank_SWPcrits[innerLoop+2] = innerLoop; - //printf("innerLoop: %d\n", innerLoop); - innerLoop = innerLoop-1; + // code to switch values + SXW.rank_SWPcrits[innerLoop+2] = innerLoop; + innerLoop = innerLoop-1; } tempArray[innerLoop+1] = key; SXW.rank_SWPcrits[innerLoop+2] = outerLoop; - //printf("outerLoop: %d\n", outerLoop); } - SXW.rank_SWPcrits[0] = 0; + SXW.rank_SWPcrits[0] = 0; // setting to 0 since that is was equation calls for + // printing for testing purposes /*printf("%d = %f\n", SXW.rank_SWPcrits[1], tempArray[0]); printf("%d = %f\n", SXW.rank_SWPcrits[2], tempArray[1]); printf("%d = %f\n", SXW.rank_SWPcrits[3], tempArray[2]); @@ -220,7 +220,7 @@ int main(int argc, char **argv) { fprintf(progfp, "%d\n", iter); } - // set these to 0 for use with -i flag + // set these to 0 for use with -i flag (need to create column headers for every iteration file) SXW.col_status_dy = 0; SXW.col_status_wk = 0; SXW.col_status_mo = 0; @@ -233,7 +233,7 @@ int main(int argc, char **argv) { RandSeed(Globals.randseed); Globals.currIter = iter; - memset(SXW.transp_SWA,0,sizeof(SXW.transp_SWA)); + memset(SXW.transp_SWA,0,sizeof(SXW.transp_SWA)); // set transp_SWA to 0; needs to be reset each iteration /* ------ Begin running the model ------ */ for (year = 1; year <= Globals.runModelYears; year++) { @@ -404,6 +404,7 @@ static void init_args(int argc, char **argv) { * stderr. * 8/16/17 - BEB Updated option for -o flag. Now if this flag is set the output files from * files_v30.in are written to. + * 10/9/17 - BEB Added -i flag for writing SOILWAT output for every iteration */ char str[1024], *opts[] = {"-d","-f","-q","-s","-e", "-p", "-g", "-o", "-i"}; /* valid options */ @@ -536,10 +537,6 @@ static void init_args(int argc, char **argv) { } a++; /* move to next valid option-value position */ - if(isPartialSoilwatOutput == FALSE && storeAllIterations){ - printf("\n\ncant use both -i and -o flags\n\n"); - break; - } } /* end for(i) */ diff --git a/sxw_resource.c b/sxw_resource.c index 80782254..99d32ff2 100644 --- a/sxw_resource.c +++ b/sxw_resource.c @@ -301,11 +301,9 @@ static void _SWA_contribution_by_group(RealF use_by_group[]) { int currentYear; if(SW_Model.year == 0) currentYear = 0; else currentYear = SW_Model.year - SW_Model.startyr; - int t,kv,id_prev_veg; + int t; RealF sumUsedByGroup = 0., sumSWATotal = 0., SWARemaining = 0.; - int index_sw_veg_types[4] = {1, 2, 3, 4}; // temp array for veg_types (need to find actual array where this info is stored) - ForEachGroup(g) // steppe functional group { use_by_group[g] = 0.; // clear @@ -313,17 +311,7 @@ static void _SWA_contribution_by_group(RealF use_by_group[]) { ForEachTrPeriod(p) { - for (l = 0; l < SXW.NSoLyrs; l++) { - // loop to get dSWAbulk - for(kv=0; kv<4; kv++){ - id_prev_veg = SXW.rank_SWPcrits[kv+1]; // get prev veg type - SXW.dSWAbulk[Iglp(kv,l,p)] = SXW.SWA_master[Itlp(kv,p,l)]-SXW.SWA_master[Itlp(id_prev_veg,p,l)]; //Itlp(veg_type, timeperiod, layer) - - //printf("SXW.SWA_master[Itlp(%d,%d,%d)]: %f || SXW.SWA_master[Itlp(%d,%d,%d)]: %f\n", - //kv, p, l, SXW.SWA_master[Itlp(kv,p,l)], id_prev_veg, p, l, SXW.SWA_master[Itlp(id_prev_veg,p,l)]); - //printf("SXW.dSWAbulk[Iglp(kv,l,p)]: %f\n", SXW.dSWAbulk[Iglp(kv,l,p)]); - } use_by_group[g] += (RealF) (_roots_active_rel[Iglp(g, l, p)] * SXW.SWA_master[Itlp(t,l,p)]); //min_res_req is space parameter } } From a4be8becf1bee9a8c76c233254016d9b9a98f119 Mon Sep 17 00:00:00 2001 From: BrendenBe1 Date: Fri, 13 Oct 2017 13:45:45 -0700 Subject: [PATCH 041/111] Added index to SWA_master and dSWAbulk for critical value --- sxw.h | 11 ++++++++--- sxw_resource.c | 3 ++- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/sxw.h b/sxw.h index 4ecba802..02864680 100644 --- a/sxw.h +++ b/sxw.h @@ -89,8 +89,8 @@ struct stepwat_st { *SWAbulk_tree_avg, *SWAbulk_forb_avg; - RealF *SWA_master, // 3D array - *dSWAbulk; + RealF *SWA_master, // 3D array to store SWA for all veg_types + *dSWAbulk; // store actual available SWA int rank_SWPcrits[5]; // array to store the SWP crits in order of lest negative to most negative (used in sxw_resource) @@ -104,7 +104,7 @@ struct stepwat_st { // 2D array to store 4 critical values per layer float SWCbulk[4][8]; // TODO: first value needs to be (number of layers * plant types) - not hardcoded float SWCoriginal[500][8]; // storing SWC values here instead of in *swc since that does not have enough storage for more than month timestep - + // used in SW_Output.c for creating column headers int col_status_dy; int col_status_wk; @@ -131,6 +131,11 @@ typedef struct stepwat_st SXW_t; */ #define Itlp(t,l,p) (((t)*SXW.NTrLyrs*SXW.NPds) + ((l)*SXW.NPds) + (p)) +/* convert 4-d index to actual array index for + * veg-prod-type/crit-value/layer/phenology + */ +#define Itclp(t,c,l,p) (((t)*SXW.NTrLyrs*SXW.NPds) + ((c)*4) + ((l)*SXW.NPds) + (p)) // c*4 is because there are 4 critical values + /* convert 2d layer by period indices to layer/phenology 1D index */ #define Ilp(l,p) ((l)*SXW.NPds + (p)) diff --git a/sxw_resource.c b/sxw_resource.c index 99d32ff2..33828057 100644 --- a/sxw_resource.c +++ b/sxw_resource.c @@ -312,7 +312,8 @@ static void _SWA_contribution_by_group(RealF use_by_group[]) { ForEachTrPeriod(p) { for (l = 0; l < SXW.NSoLyrs; l++) { - use_by_group[g] += (RealF) (_roots_active_rel[Iglp(g, l, p)] * SXW.SWA_master[Itlp(t,l,p)]); //min_res_req is space parameter + // TODO: need to figure out actual value for 2nd param in Itclp + use_by_group[g] += (RealF) (_roots_active_rel[Iglp(g, l, p)] * SXW.SWA_master[Itclp(t,0,l,p)]); //min_res_req is space parameter } } sumUsedByGroup += use_by_group[g]; From e1e3b9b59860fc487df7315df19db158556b3f6b Mon Sep 17 00:00:00 2001 From: BrendenBe1 Date: Wed, 18 Oct 2017 12:22:55 -0700 Subject: [PATCH 042/111] Working on correcting a memory error --- ST_stats.c | 10 +++++----- sxw.c | 14 +++++++------- sxw.h | 4 ++-- 3 files changed, 14 insertions(+), 14 deletions(-) diff --git a/ST_stats.c b/ST_stats.c index a568a2d1..afad0e7e 100644 --- a/ST_stats.c +++ b/ST_stats.c @@ -1586,9 +1586,9 @@ void stat_Output_AllSoilwatVariables(void) // loop for PPT // TODO: currently using year values since SOILWAT does not pass any values aside from year - for(currentMonth = 0; currentMonth < MAX_MONTHS; currentMonth++){ - PPTlayerVals[currentMonth] = SXW.PPTVal[currentMonth]; - } + //for(currentMonth = 0; currentMonth < MAX_MONTHS; currentMonth++){ + //PPTlayerVals[currentMonth] = SXW.PPTVal[currentMonth]; + //} //printf("layerVals[0]: %f\n", layerVals[0]); // write to file. this is reason set layers to MAX_LAYERS instead of layers actually used since it would be too hard to format the fprintf @@ -1599,9 +1599,9 @@ void stat_Output_AllSoilwatVariables(void) layerVals[21]/12, layerVals[22]/12, layerVals[23]/12, layerVals[24]/12); // write PPT vals to csv - fprintf(PPTFILE, "%d,%f,%f,%f,%f,%f,%f,%f,%f,%f,%f,%f,%f\n", yr, PPTlayerVals[0], PPTlayerVals[1], PPTlayerVals[2], + /*fprintf(PPTFILE, "%d,%f,%f,%f,%f,%f,%f,%f,%f,%f,%f,%f,%f\n", yr, PPTlayerVals[0], PPTlayerVals[1], PPTlayerVals[2], PPTlayerVals[3], PPTlayerVals[4], PPTlayerVals[5], PPTlayerVals[6],PPTlayerVals[7], PPTlayerVals[8], PPTlayerVals[9], - PPTlayerVals[10], PPTlayerVals[11]); + PPTlayerVals[10], PPTlayerVals[11]);*/ } // printing out values from the outsetup.in that SOILWAT reads in to ensure passing to STEPPE correctly /*printf("SXW.grass_cover: %f\n", SXW.grass_cover); diff --git a/sxw.c b/sxw.c index 358a30fe..14866a0a 100644 --- a/sxw.c +++ b/sxw.c @@ -903,11 +903,11 @@ static void _make_transp_arrays(void) { SXW.transpForbs = (RealD *) Mem_Calloc(size, sizeof(RealD), fstr); SXW.transpGrasses = (RealD *) Mem_Calloc(size, sizeof(RealD), fstr); - SXW.transpTotal_avg = (RealD *) Mem_Calloc(size, sizeof(RealD), fstr); - SXW.transpTrees_avg = (RealD *) Mem_Calloc(size, sizeof(RealD), fstr); - SXW.transpShrubs_avg = (RealD *) Mem_Calloc(size, sizeof(RealD), fstr); - SXW.transpForbs_avg = (RealD *) Mem_Calloc(size, sizeof(RealD), fstr); - SXW.transpGrasses_avg = (RealD *) Mem_Calloc(size, sizeof(RealD), fstr); + SXW.transpTotal_avg = (RealF *) Mem_Calloc(size, sizeof(RealF), fstr); + SXW.transpTrees_avg = (RealF *) Mem_Calloc(size, sizeof(RealF), fstr); + SXW.transpShrubs_avg = (RealF *) Mem_Calloc(size, sizeof(RealF), fstr); + SXW.transpForbs_avg = (RealF *) Mem_Calloc(size, sizeof(RealF), fstr); + SXW.transpGrasses_avg = (RealF *) Mem_Calloc(size, sizeof(RealF), fstr); } static void _make_swa_array(void){ @@ -1302,10 +1302,10 @@ void free_all_sxw_memory( void ) { Mem_Free(SXW.SWCoriginal); Mem_Free(SXW.transp_SWA); - Mem_Free(SXW.PPTVal); + /*Mem_Free(SXW.PPTVal); Mem_Free(SXW.PPT_day); Mem_Free(SXW.PPT_week); - Mem_Free(SXW.PPT_month); + Mem_Free(SXW.PPT_month);*/ //if (SXW.debugfile || UseGrid) Mem_Free(SXW.swc); } diff --git a/sxw.h b/sxw.h index 02864680..69552b04 100644 --- a/sxw.h +++ b/sxw.h @@ -69,10 +69,10 @@ struct stepwat_st { // PPT variables int yearInterval; // keep track of years int curMonth; - RealF PPTVal[500]; // array to store ppt vals + /*RealF PPTVal[500]; // array to store ppt vals RealF PPT_day[500]; RealF PPT_week[500]; - RealF PPT_month[500]; + RealF PPT_month[500];*/ RealF PPT_sum, PPT_rain, From ba6b4c9b451d382cce836b3453f29fcb9d9b54aa Mon Sep 17 00:00:00 2001 From: BrendenBe1 Date: Wed, 18 Oct 2017 17:06:05 -0700 Subject: [PATCH 043/111] Working on correcting a memory error --- ST_main.c | 6 ++++-- sxw.c | 22 ++++++++++++++++++++++ sxw.h | 2 +- 3 files changed, 27 insertions(+), 3 deletions(-) diff --git a/ST_main.c b/ST_main.c index 581ce440..5d4ac98b 100644 --- a/ST_main.c +++ b/ST_main.c @@ -94,6 +94,7 @@ static void usage(void) { " -d : supply working directory (default=.)\n" " -f : supply list of input files (default=files.in)\n" " -q : quiet mode, don't print message to check logfile.\n" + " -p : prints progress bar\n" " -s : use SOILWAT model for resource partitioning.\n" " -e : echo initialization results to logfile\n" " -o : print all the soilwat output\n" @@ -152,7 +153,7 @@ int main(int argc, char **argv) { init_args(argc, argv); // read input arguments and intialize proper flags - printf("STEPWAT init_args() executed successfully \n "); + printf("STEPWAT init_args() executed successfully \n"); if (UseGrid == TRUE) { runGrid(); @@ -188,7 +189,7 @@ int main(int argc, char **argv) { // insertion sort to rank the veg types and store them in their proper order for (outerLoop = 1; outerLoop < 4; outerLoop++) { - key = tempArray[outerLoop]; + key = tempArray[outerLoop]; // set key equal to critical value innerLoop = outerLoop-1; while (innerLoop >= 0 && tempArray[innerLoop] < key) { @@ -213,6 +214,7 @@ int main(int argc, char **argv) { /* --- Begin a new iteration ------ */ for (iter = 1; iter <= Globals.runModelIterations; iter++) { + //printf("iter: %d\n", iter); if (progfp == stderr) { if (iter % incr == 0) fprintf(progfp, "."); diff --git a/sxw.c b/sxw.c index 14866a0a..6e103268 100644 --- a/sxw.c +++ b/sxw.c @@ -226,7 +226,10 @@ void SXW_Init( Bool init_SW, char *f_roots ) { SXW.NTrLyrs = SW_Site.n_transp_lyrs_forb; SXW.NSoLyrs = SW_Site.n_layers; + printf("Number of layers: %d\n", SW_Site.n_layers); + printf("Number of iterations: %d\n", Globals.runModelIterations); + printf("Number of years: %d\n", Globals.runModelYears); _make_arrays(); @@ -908,6 +911,13 @@ static void _make_transp_arrays(void) { SXW.transpShrubs_avg = (RealF *) Mem_Calloc(size, sizeof(RealF), fstr); SXW.transpForbs_avg = (RealF *) Mem_Calloc(size, sizeof(RealF), fstr); SXW.transpGrasses_avg = (RealF *) Mem_Calloc(size, sizeof(RealF), fstr); + + // initialize values to 0 + Mem_Set(SXW.transpTotal_avg, 0, SXW.NPds * SXW.NSoLyrs * sizeof(RealF)); + Mem_Set(SXW.transpTrees_avg, 0, SXW.NPds * SXW.NSoLyrs * sizeof(RealF)); + Mem_Set(SXW.transpShrubs_avg, 0, SXW.NPds * SXW.NSoLyrs * sizeof(RealF)); + Mem_Set(SXW.transpForbs_avg, 0, SXW.NPds * SXW.NSoLyrs * sizeof(RealF)); + Mem_Set(SXW.transpGrasses_avg, 0, SXW.NPds * SXW.NSoLyrs * sizeof(RealF)); } static void _make_swa_array(void){ @@ -924,10 +934,22 @@ static void _make_swa_array(void){ SXW.SWAbulk_tree_avg = (RealF *) Mem_Calloc(size, sizeof(RealF *), fstr); SXW.SWAbulk_forb_avg = (RealF *) Mem_Calloc(size, sizeof(RealF *), fstr); + Mem_Set(SXW.SWAbulk_grass, 0, SXW.NPds * SXW.NSoLyrs * sizeof(RealF)); + Mem_Set(SXW.SWAbulk_shrub, 0, SXW.NPds * SXW.NSoLyrs * sizeof(RealF)); + Mem_Set(SXW.SWAbulk_tree, 0, SXW.NPds * SXW.NSoLyrs * sizeof(RealF)); + Mem_Set(SXW.SWAbulk_forb, 0, SXW.NPds * SXW.NSoLyrs * sizeof(RealF)); + Mem_Set(SXW.SWAbulk_grass_avg, 0, SXW.NPds * SXW.NSoLyrs * sizeof(RealF)); + Mem_Set(SXW.SWAbulk_shrub_avg, 0, SXW.NPds * SXW.NSoLyrs * sizeof(RealF)); + Mem_Set(SXW.SWAbulk_tree_avg, 0, SXW.NPds * SXW.NSoLyrs * sizeof(RealF)); + Mem_Set(SXW.SWAbulk_forb_avg, 0, SXW.NPds * SXW.NSoLyrs * sizeof(RealF)); + //4 - Grass,Frob,Tree,Shrub size = 4 * SXW.NPds * SXW.NSoLyrs; SXW.SWA_master = (RealF *) Mem_Calloc(size, sizeof(RealF), fstr); SXW.dSWAbulk = (RealF *) Mem_Calloc(size, sizeof(RealF), fstr); + + //Mem_Set(SXW.SWA_master, 0, SXW.NPds * 4 * SXW.NSoLyrs * sizeof(RealF)); + memset(SXW.SWA_master, 0, sizeof(SXW.SWA_master)); } static void _make_swc_array(void) { diff --git a/sxw.h b/sxw.h index 69552b04..1d760924 100644 --- a/sxw.h +++ b/sxw.h @@ -89,7 +89,7 @@ struct stepwat_st { *SWAbulk_tree_avg, *SWAbulk_forb_avg; - RealF *SWA_master, // 3D array to store SWA for all veg_types + RealF *SWA_master, // 4D array to store SWA for all veg_types *dSWAbulk; // store actual available SWA int rank_SWPcrits[5]; // array to store the SWP crits in order of lest negative to most negative (used in sxw_resource) From f90e446a5ea15dc32d14657fb4b21093ee20bc14 Mon Sep 17 00:00:00 2001 From: BrendenBe1 Date: Fri, 20 Oct 2017 13:56:49 -0700 Subject: [PATCH 044/111] Working on calculating dSWAbulk to get actual soil water available --- ST_main.c | 24 +++++++++++++++++------- 1 file changed, 17 insertions(+), 7 deletions(-) diff --git a/ST_main.c b/ST_main.c index 5d4ac98b..e3890550 100644 --- a/ST_main.c +++ b/ST_main.c @@ -194,19 +194,29 @@ int main(int argc, char **argv) { while (innerLoop >= 0 && tempArray[innerLoop] < key) { // code to switch values - SXW.rank_SWPcrits[innerLoop+2] = innerLoop; + tempArray[innerLoop+1] = tempArray[innerLoop]; innerLoop = innerLoop-1; } tempArray[innerLoop+1] = key; - SXW.rank_SWPcrits[innerLoop+2] = outerLoop; } - SXW.rank_SWPcrits[0] = 0; // setting to 0 since that is was equation calls for + + // loops to compare sorted v unsorted array and find proper index + for(outerLoop = 0; outerLoop < 4; outerLoop++){ + for(innerLoop = 0; innerLoop < 4; innerLoop++){ + // compare sorted to unsorted and store index in rank_SWPcrits + if(SXW.critSoilWater[outerLoop] == tempArray[innerLoop]){ + SXW.rank_SWPcrits[outerLoop] = innerLoop; + tempArray[innerLoop] = 100; // set value to something impossible so if a duplicate a different index is picked next + break; + } + } + } // printing for testing purposes - /*printf("%d = %f\n", SXW.rank_SWPcrits[1], tempArray[0]); - printf("%d = %f\n", SXW.rank_SWPcrits[2], tempArray[1]); - printf("%d = %f\n", SXW.rank_SWPcrits[3], tempArray[2]); - printf("%d = %f\n\n", SXW.rank_SWPcrits[4], tempArray[3]);*/ + /*printf("%d = %f\n", SXW.rank_SWPcrits[0], SXW.critSoilWater[SXW.rank_SWPcrits[0]]); + printf("%d = %f\n", SXW.rank_SWPcrits[1], SXW.critSoilWater[SXW.rank_SWPcrits[1]]); + printf("%d = %f\n", SXW.rank_SWPcrits[2], SXW.critSoilWater[SXW.rank_SWPcrits[2]]); + printf("%d = %f\n\n", SXW.rank_SWPcrits[3], SXW.critSoilWater[SXW.rank_SWPcrits[3]]);*/ /*---------------------------------------------------------- End of rank_SWPcrits From 7f113433d718aed33a9fc89858b273eb81af18bf Mon Sep 17 00:00:00 2001 From: BrendenBe1 Date: Mon, 23 Oct 2017 12:18:48 -0700 Subject: [PATCH 045/111] Working on calculating dSWAbulk to get actual soil water available --- sxw.c | 13 ------------- sxw.h | 7 ++----- 2 files changed, 2 insertions(+), 18 deletions(-) diff --git a/sxw.c b/sxw.c index 6e103268..f201057f 100644 --- a/sxw.c +++ b/sxw.c @@ -924,20 +924,11 @@ static void _make_swa_array(void){ char *fstr = "_make_swa_array()"; int size = SXW.NPds * SXW.NSoLyrs; - SXW.SWAbulk_grass = (RealF *) Mem_Calloc(size, sizeof(RealF *), fstr); - SXW.SWAbulk_shrub = (RealF *) Mem_Calloc(size, sizeof(RealF *), fstr); - SXW.SWAbulk_tree = (RealF *) Mem_Calloc(size, sizeof(RealF *), fstr); - SXW.SWAbulk_forb = (RealF *) Mem_Calloc(size, sizeof(RealF *), fstr); - SXW.SWAbulk_grass_avg = (RealF *) Mem_Calloc(size, sizeof(RealF *), fstr); SXW.SWAbulk_shrub_avg = (RealF *) Mem_Calloc(size, sizeof(RealF *), fstr); SXW.SWAbulk_tree_avg = (RealF *) Mem_Calloc(size, sizeof(RealF *), fstr); SXW.SWAbulk_forb_avg = (RealF *) Mem_Calloc(size, sizeof(RealF *), fstr); - Mem_Set(SXW.SWAbulk_grass, 0, SXW.NPds * SXW.NSoLyrs * sizeof(RealF)); - Mem_Set(SXW.SWAbulk_shrub, 0, SXW.NPds * SXW.NSoLyrs * sizeof(RealF)); - Mem_Set(SXW.SWAbulk_tree, 0, SXW.NPds * SXW.NSoLyrs * sizeof(RealF)); - Mem_Set(SXW.SWAbulk_forb, 0, SXW.NPds * SXW.NSoLyrs * sizeof(RealF)); Mem_Set(SXW.SWAbulk_grass_avg, 0, SXW.NPds * SXW.NSoLyrs * sizeof(RealF)); Mem_Set(SXW.SWAbulk_shrub_avg, 0, SXW.NPds * SXW.NSoLyrs * sizeof(RealF)); Mem_Set(SXW.SWAbulk_tree_avg, 0, SXW.NPds * SXW.NSoLyrs * sizeof(RealF)); @@ -1308,10 +1299,6 @@ void free_all_sxw_memory( void ) { Mem_Free(SXW.transpForbs_avg); Mem_Free(SXW.transpGrasses_avg); - Mem_Free(SXW.SWAbulk_grass); - Mem_Free(SXW.SWAbulk_shrub); - Mem_Free(SXW.SWAbulk_tree); - Mem_Free(SXW.SWAbulk_forb); Mem_Free(SXW.SWAbulk_grass_avg); Mem_Free(SXW.SWAbulk_shrub_avg); Mem_Free(SXW.SWAbulk_tree_avg); diff --git a/sxw.h b/sxw.h index 1d760924..b0d659a7 100644 --- a/sxw.h +++ b/sxw.h @@ -59,6 +59,7 @@ struct stepwat_st { *f_watin; /* soilwat's input file */ RealD critSoilWater[4]; // storing values in same order as defined in rgroup.in (0=tree, 1=shrub, 2=grass, 3=forb) + RealD useVegType[4]; /* DEBUG stuff */ char *debugfile; /* added in ST_Main(), read to get debug instructions */ @@ -80,11 +81,7 @@ struct stepwat_st { PPT_snow_melt, PPT_snow_loss; - RealF *SWAbulk_grass, // 2D array to store SWA vals ([days of year][number of max layers]) - *SWAbulk_shrub, - *SWAbulk_tree, - *SWAbulk_forb, - *SWAbulk_grass_avg, // 2D array to store SWA vals ([days of year][number of max layers]) + RealF *SWAbulk_grass_avg, // 2D array to store SWA vals ([days of year][number of max layers]) *SWAbulk_shrub_avg, *SWAbulk_tree_avg, *SWAbulk_forb_avg; From 80b63417e7d27e7ff0d32a1e29e403408c0a3858 Mon Sep 17 00:00:00 2001 From: BrendenBe1 Date: Wed, 25 Oct 2017 11:56:33 -0700 Subject: [PATCH 046/111] Working on correcting a memory error --- ST_main.c | 13 ++++++++----- ST_resgroups.c | 4 +++- makefile | 2 +- sxw.c | 32 ++++++++++++-------------------- sxw.h | 11 ++--------- sxw_resource.c | 8 ++++---- 6 files changed, 30 insertions(+), 40 deletions(-) diff --git a/ST_main.c b/ST_main.c index e3890550..56831216 100644 --- a/ST_main.c +++ b/ST_main.c @@ -23,6 +23,7 @@ #include "generic.h" #include "filefuncs.h" #include "myMemory.h" +#include "SW_VegProd.h" #ifdef STEPWAT @@ -33,6 +34,7 @@ extern Bool isPartialSoilwatOutput; extern Bool storeAllIterations; +extern SW_VEGPROD SW_VegProd; /************* External Function Declarations **************/ /***********************************************************/ @@ -175,10 +177,10 @@ int main(int argc, char **argv) { int outerLoop, innerLoop; float key; RealF tempArray[4]; - tempArray[0] = SXW.critSoilWater[0]; - tempArray[1] = SXW.critSoilWater[1]; - tempArray[2] = SXW.critSoilWater[2]; - tempArray[3] = SXW.critSoilWater[3]; + tempArray[0] = SW_VegProd.critSoilWater[0]; + tempArray[1] = SW_VegProd.critSoilWater[1]; + tempArray[2] = SW_VegProd.critSoilWater[2]; + tempArray[3] = SW_VegProd.critSoilWater[3]; // printing for testing purposes /*printf("%f\n", tempArray[0]); @@ -204,7 +206,7 @@ int main(int argc, char **argv) { for(outerLoop = 0; outerLoop < 4; outerLoop++){ for(innerLoop = 0; innerLoop < 4; innerLoop++){ // compare sorted to unsorted and store index in rank_SWPcrits - if(SXW.critSoilWater[outerLoop] == tempArray[innerLoop]){ + if(SW_VegProd.critSoilWater[outerLoop] == tempArray[innerLoop]){ SXW.rank_SWPcrits[outerLoop] = innerLoop; tempArray[innerLoop] = 100; // set value to something impossible so if a duplicate a different index is picked next break; @@ -316,6 +318,7 @@ int main(int argc, char **argv) { printf("\nend program\n"); fprintf(progfp, "\n"); + //free_all_sxw_memory(); return 0; } /* END PROGRAM */ diff --git a/ST_resgroups.c b/ST_resgroups.c index e9037ef0..f3e2bf4d 100644 --- a/ST_resgroups.c +++ b/ST_resgroups.c @@ -461,8 +461,9 @@ void rgroup_ResPartIndiv(void) if (!g->est_count) continue; + numindvs = 0; // setting to 0 so no problems passing into RGroup_GetIndivs function /* --- allocate the temporary group-oriented arrays */ - indivs = RGroup_GetIndivs(rg, SORT_D, &numindvs); + indivs = RGroup_GetIndivs(rg, SORT_D, &numindvs); // SORT_D = sort in descending order /* ---- assign indivs' availability, not including extra ---- */ /* resource <= 1.0 is for basic growth, >= extra */ @@ -907,6 +908,7 @@ void RGroup_Update_Newsize(GrpIndex rg) } ///if (RGroup[rg]->max_age != 1) { + numindvs = 0; // set to 0 so no problems passing to function /* compute the contribution of each indiv to the group's size */ indivs = RGroup_GetIndivs(rg, SORT_0, &numindvs); for (n = 0; n < numindvs; n++) diff --git a/makefile b/makefile index ece2e609..293bc054 100644 --- a/makefile +++ b/makefile @@ -264,7 +264,7 @@ $(oDir)/ST_indivs.o: ST_indivs.c ST_steppe.h ST_defines.h \ $(oDir)/ST_main.o: ST_main.c ST_steppe.h ST_defines.h sw_src/generic.h \ ST_structs.h ST_functions.h sw_src/filefuncs.h \ - sw_src/myMemory.h + sw_src/myMemory.h sw_src/SW_VegProd.h $(CC) $(C_FLAGS) $(incDirs) -c -o $@ $< $(oDir)/ST_mortality.o: ST_mortality.c ST_steppe.h ST_defines.h \ diff --git a/sxw.c b/sxw.c index f201057f..3ea38792 100644 --- a/sxw.c +++ b/sxw.c @@ -906,18 +906,18 @@ static void _make_transp_arrays(void) { SXW.transpForbs = (RealD *) Mem_Calloc(size, sizeof(RealD), fstr); SXW.transpGrasses = (RealD *) Mem_Calloc(size, sizeof(RealD), fstr); - SXW.transpTotal_avg = (RealF *) Mem_Calloc(size, sizeof(RealF), fstr); - SXW.transpTrees_avg = (RealF *) Mem_Calloc(size, sizeof(RealF), fstr); - SXW.transpShrubs_avg = (RealF *) Mem_Calloc(size, sizeof(RealF), fstr); - SXW.transpForbs_avg = (RealF *) Mem_Calloc(size, sizeof(RealF), fstr); - SXW.transpGrasses_avg = (RealF *) Mem_Calloc(size, sizeof(RealF), fstr); + SXW.transpTotal_avg = (RealD *) Mem_Calloc(size, sizeof(RealD), fstr); + SXW.transpTrees_avg = (RealD *) Mem_Calloc(size, sizeof(RealD), fstr); + SXW.transpShrubs_avg = (RealD *) Mem_Calloc(size, sizeof(RealD), fstr); + SXW.transpForbs_avg = (RealD *) Mem_Calloc(size, sizeof(RealD), fstr); + SXW.transpGrasses_avg = (RealD *) Mem_Calloc(size, sizeof(RealD), fstr); // initialize values to 0 - Mem_Set(SXW.transpTotal_avg, 0, SXW.NPds * SXW.NSoLyrs * sizeof(RealF)); - Mem_Set(SXW.transpTrees_avg, 0, SXW.NPds * SXW.NSoLyrs * sizeof(RealF)); - Mem_Set(SXW.transpShrubs_avg, 0, SXW.NPds * SXW.NSoLyrs * sizeof(RealF)); - Mem_Set(SXW.transpForbs_avg, 0, SXW.NPds * SXW.NSoLyrs * sizeof(RealF)); - Mem_Set(SXW.transpGrasses_avg, 0, SXW.NPds * SXW.NSoLyrs * sizeof(RealF)); + Mem_Set(SXW.transpTotal_avg, 0, SXW.NPds * SXW.NSoLyrs * sizeof(RealD)); + Mem_Set(SXW.transpTrees_avg, 0, SXW.NPds * SXW.NSoLyrs * sizeof(RealD)); + Mem_Set(SXW.transpShrubs_avg, 0, SXW.NPds * SXW.NSoLyrs * sizeof(RealD)); + Mem_Set(SXW.transpForbs_avg, 0, SXW.NPds * SXW.NSoLyrs * sizeof(RealD)); + Mem_Set(SXW.transpGrasses_avg, 0, SXW.NPds * SXW.NSoLyrs * sizeof(RealD)); } static void _make_swa_array(void){ @@ -1280,7 +1280,8 @@ int getNTranspLayers(int veg_prod_type) { /***********************************************************/ void free_all_sxw_memory( void ) { - free_sxw_memory(); + printf("freeing memory\n"); + free_sxw_memory(); Mem_Free(SXW.f_files); Mem_Free(SXW.f_roots); Mem_Free(SXW.f_phen); @@ -1307,15 +1308,6 @@ void free_all_sxw_memory( void ) { Mem_Free(SXW.SWA_master); Mem_Free(SXW.dSWAbulk); - Mem_Free(SXW.SWCbulk); - Mem_Free(SXW.SWCoriginal); - Mem_Free(SXW.transp_SWA); - - /*Mem_Free(SXW.PPTVal); - Mem_Free(SXW.PPT_day); - Mem_Free(SXW.PPT_week); - Mem_Free(SXW.PPT_month);*/ - //if (SXW.debugfile || UseGrid) Mem_Free(SXW.swc); } diff --git a/sxw.h b/sxw.h index b0d659a7..9cb07cc7 100644 --- a/sxw.h +++ b/sxw.h @@ -58,9 +58,6 @@ struct stepwat_st { *f_prod, /* biomass to prod. conv. nos. */ *f_watin; /* soilwat's input file */ - RealD critSoilWater[4]; // storing values in same order as defined in rgroup.in (0=tree, 1=shrub, 2=grass, 3=forb) - RealD useVegType[4]; - /* DEBUG stuff */ char *debugfile; /* added in ST_Main(), read to get debug instructions */ RealF *swc, /* dynamic array(Ilp) of SWC from SOILWAT */ @@ -70,10 +67,6 @@ struct stepwat_st { // PPT variables int yearInterval; // keep track of years int curMonth; - /*RealF PPTVal[500]; // array to store ppt vals - RealF PPT_day[500]; - RealF PPT_week[500]; - RealF PPT_month[500];*/ RealF PPT_sum, PPT_rain, @@ -99,8 +92,8 @@ struct stepwat_st { RealF transp_SWA[MAX_YEARS][11]; // store the sum of SWA and transp for each year and resource. transp_SWA[year][steppe_resource_group] // 2D array to store 4 critical values per layer - float SWCbulk[4][8]; // TODO: first value needs to be (number of layers * plant types) - not hardcoded - float SWCoriginal[500][8]; // storing SWC values here instead of in *swc since that does not have enough storage for more than month timestep + //float SWCbulk[4][8]; // TODO: first value needs to be (number of layers * plant types) - not hardcoded + //float SWCoriginal[500][8]; // storing SWC values here instead of in *swc since that does not have enough storage for more than month timestep // used in SW_Output.c for creating column headers int col_status_dy; diff --git a/sxw_resource.c b/sxw_resource.c index 33828057..49a17448 100644 --- a/sxw_resource.c +++ b/sxw_resource.c @@ -309,14 +309,14 @@ static void _SWA_contribution_by_group(RealF use_by_group[]) { use_by_group[g] = 0.; // clear t = RGroup[g]->veg_prod_type-1; - ForEachTrPeriod(p) + /*ForEachTrPeriod(p) { for (l = 0; l < SXW.NSoLyrs; l++) { // TODO: need to figure out actual value for 2nd param in Itclp use_by_group[g] += (RealF) (_roots_active_rel[Iglp(g, l, p)] * SXW.SWA_master[Itclp(t,0,l,p)]); //min_res_req is space parameter } - } - sumUsedByGroup += use_by_group[g]; - SXW.transp_SWA[currentYear][g] += sumUsedByGroup; + }*/ + //sumUsedByGroup += use_by_group[g]; + //SXW.transp_SWA[currentYear][g] += sumUsedByGroup; } } From 9c817c6c9109433f27a2c10e9a10c201b90f988b Mon Sep 17 00:00:00 2001 From: BrendenBe1 Date: Wed, 25 Oct 2017 16:55:52 -0700 Subject: [PATCH 047/111] Finished function to calculate dSWAbulk --- ST_resgroups.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/ST_resgroups.c b/ST_resgroups.c index f3e2bf4d..dc8ee83e 100644 --- a/ST_resgroups.c +++ b/ST_resgroups.c @@ -101,8 +101,8 @@ void rgroup_PartResources(void) RealF resource, /* amt of "resource" == 1 when ppt is avg */ xtra_base = 0., /* pooled extra resource up to 1.0 */ xtra_obase = 0., /* pooled resource > 1.0 */ - size_base[MAX_RGROUPS], /* total res. contrib to base, all groups */ - size_obase[MAX_RGROUPS]; /* total res. contrib. if xtra_obase */ + size_base[MAX_RGROUPS] = {0}, /* total res. contrib to base, all groups */ + size_obase[MAX_RGROUPS] = {0}; /* total res. contrib. if xtra_obase */ Bool noplants = TRUE; const Bool do_base = FALSE, /* monikers for _res_part_extra() */ @@ -913,7 +913,7 @@ void RGroup_Update_Newsize(GrpIndex rg) indivs = RGroup_GetIndivs(rg, SORT_0, &numindvs); for (n = 0; n < numindvs; n++) indivs[n]->grp_res_prop = indivs[n]->relsize / sumsize; - Mem_Free(indivs); + //Mem_Free(indivs); // dont call free on variable unless it was initialized with malloc or calloc ///} /* double check some assumptions */ From b02ae4fc78d1aa4d01063b54e0a1f84964854aeb Mon Sep 17 00:00:00 2001 From: BrendenBe1 Date: Mon, 30 Oct 2017 11:38:37 -0700 Subject: [PATCH 048/111] Updating sw_src subrepo to correct branch and recent commits --- sw_src | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sw_src b/sw_src index cb4c789d..8c852310 160000 --- a/sw_src +++ b/sw_src @@ -1 +1 @@ -Subproject commit cb4c789d7642bb4b8eb9cccbba8717551ba97da0 +Subproject commit 8c8523109ad4a6df2d17aeaad776dfc9df584979 From f390a4bc6d2d91fa9cdac4e4664c327688606b71 Mon Sep 17 00:00:00 2001 From: BrendenBe1 Date: Mon, 30 Oct 2017 16:01:59 -0700 Subject: [PATCH 049/111] Redistributing available soilwater in get_dSWAbulk (soilwat function). Also fixed bug in loop to rank the critical values in ST_main.c where order was incorrect if more than 1 set of similar values --- ST_main.c | 38 ++++++++++++++++++++++---------------- sw_src | 2 +- sxw.c | 2 ++ sxw.h | 3 ++- 4 files changed, 27 insertions(+), 18 deletions(-) diff --git a/ST_main.c b/ST_main.c index 56831216..4d9ab834 100644 --- a/ST_main.c +++ b/ST_main.c @@ -176,17 +176,15 @@ int main(int argc, char **argv) { ----------------------------------------------------------*/ int outerLoop, innerLoop; float key; - RealF tempArray[4]; + RealF tempArray[4], tempArrayUnsorted[4]; // meed two temp arrays equal to critSoilWater since we dont want to alter the original at all tempArray[0] = SW_VegProd.critSoilWater[0]; tempArray[1] = SW_VegProd.critSoilWater[1]; tempArray[2] = SW_VegProd.critSoilWater[2]; tempArray[3] = SW_VegProd.critSoilWater[3]; - - // printing for testing purposes - /*printf("%f\n", tempArray[0]); - printf("%f\n", tempArray[1]); - printf("%f\n", tempArray[2]); - printf("%f\n\n", tempArray[3]);*/ + tempArrayUnsorted[0] = SW_VegProd.critSoilWater[0]; + tempArrayUnsorted[1] = SW_VegProd.critSoilWater[1]; + tempArrayUnsorted[2] = SW_VegProd.critSoilWater[2]; + tempArrayUnsorted[3] = SW_VegProd.critSoilWater[3]; // insertion sort to rank the veg types and store them in their proper order for (outerLoop = 1; outerLoop < 4; outerLoop++) @@ -202,23 +200,32 @@ int main(int argc, char **argv) { tempArray[innerLoop+1] = key; } + /*printf("%f\n", tempArrayUnsorted[0]); + printf("%f\n", tempArrayUnsorted[1]); + printf("%f\n", tempArrayUnsorted[2]); + printf("%f\n\n", tempArrayUnsorted[3]); + + printf("%f\n", tempArray[0]); + printf("%f\n", tempArray[1]); + printf("%f\n", tempArray[2]); + printf("%f\n\n", tempArray[3]);*/ + // loops to compare sorted v unsorted array and find proper index for(outerLoop = 0; outerLoop < 4; outerLoop++){ for(innerLoop = 0; innerLoop < 4; innerLoop++){ - // compare sorted to unsorted and store index in rank_SWPcrits - if(SW_VegProd.critSoilWater[outerLoop] == tempArray[innerLoop]){ + if(tempArray[outerLoop] == tempArrayUnsorted[innerLoop]){ SXW.rank_SWPcrits[outerLoop] = innerLoop; - tempArray[innerLoop] = 100; // set value to something impossible so if a duplicate a different index is picked next + tempArrayUnsorted[innerLoop] = 100; // set value to something impossible so if a duplicate a different index is picked next break; } } } // printing for testing purposes - /*printf("%d = %f\n", SXW.rank_SWPcrits[0], SXW.critSoilWater[SXW.rank_SWPcrits[0]]); - printf("%d = %f\n", SXW.rank_SWPcrits[1], SXW.critSoilWater[SXW.rank_SWPcrits[1]]); - printf("%d = %f\n", SXW.rank_SWPcrits[2], SXW.critSoilWater[SXW.rank_SWPcrits[2]]); - printf("%d = %f\n\n", SXW.rank_SWPcrits[3], SXW.critSoilWater[SXW.rank_SWPcrits[3]]);*/ + /*printf("%d = %f\n", SXW.rank_SWPcrits[0], SW_VegProd.critSoilWater[SXW.rank_SWPcrits[0]]); + printf("%d = %f\n", SXW.rank_SWPcrits[1], SW_VegProd.critSoilWater[SXW.rank_SWPcrits[1]]); + printf("%d = %f\n", SXW.rank_SWPcrits[2], SW_VegProd.critSoilWater[SXW.rank_SWPcrits[2]]); + printf("%d = %f\n\n", SXW.rank_SWPcrits[3], SW_VegProd.critSoilWater[SXW.rank_SWPcrits[3]]);*/ /*---------------------------------------------------------- End of rank_SWPcrits @@ -250,7 +257,7 @@ int main(int argc, char **argv) { memset(SXW.transp_SWA,0,sizeof(SXW.transp_SWA)); // set transp_SWA to 0; needs to be reset each iteration /* ------ Begin running the model ------ */ - for (year = 1; year <= Globals.runModelYears; year++) { + for (year = 1; year <= Globals.runModelYears; year++){ Globals.currYear = year; rgroup_Establish(); @@ -318,7 +325,6 @@ int main(int argc, char **argv) { printf("\nend program\n"); fprintf(progfp, "\n"); - //free_all_sxw_memory(); return 0; } /* END PROGRAM */ diff --git a/sw_src b/sw_src index 8c852310..6e859eff 160000 --- a/sw_src +++ b/sw_src @@ -1 +1 @@ -Subproject commit 8c8523109ad4a6df2d17aeaad776dfc9df584979 +Subproject commit 6e859eff5a1ab7f434f87cfda3a37a29cf2f12b7 diff --git a/sxw.c b/sxw.c index 3ea38792..686d9f18 100644 --- a/sxw.c +++ b/sxw.c @@ -938,6 +938,7 @@ static void _make_swa_array(void){ size = 4 * SXW.NPds * SXW.NSoLyrs; SXW.SWA_master = (RealF *) Mem_Calloc(size, sizeof(RealF), fstr); SXW.dSWAbulk = (RealF *) Mem_Calloc(size, sizeof(RealF), fstr); + SXW.dSWA_repartitioned = (RealF *) Mem_Calloc(size, sizeof(RealF), fstr); //Mem_Set(SXW.SWA_master, 0, SXW.NPds * 4 * SXW.NSoLyrs * sizeof(RealF)); memset(SXW.SWA_master, 0, sizeof(SXW.SWA_master)); @@ -1307,6 +1308,7 @@ void free_all_sxw_memory( void ) { Mem_Free(SXW.SWA_master); Mem_Free(SXW.dSWAbulk); + Mem_Free(SXW.dSWA_repartitioned); Mem_Free(SXW.swc); } diff --git a/sxw.h b/sxw.h index 9cb07cc7..69f08245 100644 --- a/sxw.h +++ b/sxw.h @@ -80,7 +80,8 @@ struct stepwat_st { *SWAbulk_forb_avg; RealF *SWA_master, // 4D array to store SWA for all veg_types - *dSWAbulk; // store actual available SWA + *dSWAbulk, // store actual available SWA + *dSWA_repartitioned; // store repartioned SWA values int rank_SWPcrits[5]; // array to store the SWP crits in order of lest negative to most negative (used in sxw_resource) From c5e0678f034fc60dd36c97714ddb015c79747057 Mon Sep 17 00:00:00 2001 From: BrendenBe1 Date: Wed, 1 Nov 2017 17:09:51 -0700 Subject: [PATCH 050/111] Working on issue in sw_src/SW_Output.c where a call to get_dSWAbulk causes SWA not to be output to file --- sw_src | 2 +- sxw.h | 4 ---- 2 files changed, 1 insertion(+), 5 deletions(-) diff --git a/sw_src b/sw_src index 6e859eff..4c570e75 160000 --- a/sw_src +++ b/sw_src @@ -1 +1 @@ -Subproject commit 6e859eff5a1ab7f434f87cfda3a37a29cf2f12b7 +Subproject commit 4c570e758c82d7678e1f47340fc79f873cef061b diff --git a/sxw.h b/sxw.h index 69f08245..a446af51 100644 --- a/sxw.h +++ b/sxw.h @@ -85,10 +85,6 @@ struct stepwat_st { int rank_SWPcrits[5]; // array to store the SWP crits in order of lest negative to most negative (used in sxw_resource) - float tempMax_avg, - tempMin_avg, - tempAvgAir_avg, - tempSoilSurfaceTemp_avg; RealF transp_SWA[MAX_YEARS][11]; // store the sum of SWA and transp for each year and resource. transp_SWA[year][steppe_resource_group] From 5e94de0b9d2f2d2a52976594ced355a4385f21a1 Mon Sep 17 00:00:00 2001 From: BrendenBe1 Date: Fri, 3 Nov 2017 13:52:38 -0700 Subject: [PATCH 051/111] fixed issue with output not being written to file when get_dSWAbulk was called --- sw_src | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sw_src b/sw_src index 4c570e75..7a6f70c0 160000 --- a/sw_src +++ b/sw_src @@ -1 +1 @@ -Subproject commit 4c570e758c82d7678e1f47340fc79f873cef061b +Subproject commit 7a6f70c099055085d10581803682ca987ee7839e From 2b53b06cbb1eec825afdaf9137d8a4aeb5f228af Mon Sep 17 00:00:00 2001 From: BrendenBe1 Date: Mon, 13 Nov 2017 12:37:05 -0700 Subject: [PATCH 052/111] Changes to get_dSWAbulk to fix occasional out of bounds error --- sw_src | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sw_src b/sw_src index 7a6f70c0..7995f144 160000 --- a/sw_src +++ b/sw_src @@ -1 +1 @@ -Subproject commit 7a6f70c099055085d10581803682ca987ee7839e +Subproject commit 7995f144d3efe3063d109349413d7d81089a708a From e751a3dddb516bf41774d7aaa4d00148501d3dbb Mon Sep 17 00:00:00 2001 From: BrendenBe1 Date: Mon, 13 Nov 2017 13:44:44 -0700 Subject: [PATCH 053/111] Updated structures to work with SOILWAT standalone for calculating dSWAbulk_repartitioned --- ST_main.c | 15 +-------------- sw_src | 2 +- sxw.h | 9 ++------- 3 files changed, 4 insertions(+), 22 deletions(-) diff --git a/ST_main.c b/ST_main.c index 4d9ab834..9ee5c3fa 100644 --- a/ST_main.c +++ b/ST_main.c @@ -176,7 +176,7 @@ int main(int argc, char **argv) { ----------------------------------------------------------*/ int outerLoop, innerLoop; float key; - RealF tempArray[4], tempArrayUnsorted[4]; // meed two temp arrays equal to critSoilWater since we dont want to alter the original at all + RealF tempArray[4], tempArrayUnsorted[4]; // need two temp arrays equal to critSoilWater since we dont want to alter the original at all tempArray[0] = SW_VegProd.critSoilWater[0]; tempArray[1] = SW_VegProd.critSoilWater[1]; tempArray[2] = SW_VegProd.critSoilWater[2]; @@ -200,16 +200,6 @@ int main(int argc, char **argv) { tempArray[innerLoop+1] = key; } - /*printf("%f\n", tempArrayUnsorted[0]); - printf("%f\n", tempArrayUnsorted[1]); - printf("%f\n", tempArrayUnsorted[2]); - printf("%f\n\n", tempArrayUnsorted[3]); - - printf("%f\n", tempArray[0]); - printf("%f\n", tempArray[1]); - printf("%f\n", tempArray[2]); - printf("%f\n\n", tempArray[3]);*/ - // loops to compare sorted v unsorted array and find proper index for(outerLoop = 0; outerLoop < 4; outerLoop++){ for(innerLoop = 0; innerLoop < 4; innerLoop++){ @@ -220,13 +210,10 @@ int main(int argc, char **argv) { } } } - - // printing for testing purposes /*printf("%d = %f\n", SXW.rank_SWPcrits[0], SW_VegProd.critSoilWater[SXW.rank_SWPcrits[0]]); printf("%d = %f\n", SXW.rank_SWPcrits[1], SW_VegProd.critSoilWater[SXW.rank_SWPcrits[1]]); printf("%d = %f\n", SXW.rank_SWPcrits[2], SW_VegProd.critSoilWater[SXW.rank_SWPcrits[2]]); printf("%d = %f\n\n", SXW.rank_SWPcrits[3], SW_VegProd.critSoilWater[SXW.rank_SWPcrits[3]]);*/ - /*---------------------------------------------------------- End of rank_SWPcrits ----------------------------------------------------------*/ diff --git a/sw_src b/sw_src index 7995f144..8d15bc51 160000 --- a/sw_src +++ b/sw_src @@ -1 +1 @@ -Subproject commit 7995f144d3efe3063d109349413d7d81089a708a +Subproject commit 8d15bc51ec35b81fafcc155031752602e2efb6e1 diff --git a/sxw.h b/sxw.h index a446af51..9491dac7 100644 --- a/sxw.h +++ b/sxw.h @@ -83,21 +83,16 @@ struct stepwat_st { *dSWAbulk, // store actual available SWA *dSWA_repartitioned; // store repartioned SWA values - int rank_SWPcrits[5]; // array to store the SWP crits in order of lest negative to most negative (used in sxw_resource) - + //int rank_SWPcrits[5]; // array to store the SWP crits in order of lest negative to most negative (used in sxw_resource) RealF transp_SWA[MAX_YEARS][11]; // store the sum of SWA and transp for each year and resource. transp_SWA[year][steppe_resource_group] - - // 2D array to store 4 critical values per layer - //float SWCbulk[4][8]; // TODO: first value needs to be (number of layers * plant types) - not hardcoded - //float SWCoriginal[500][8]; // storing SWC values here instead of in *swc since that does not have enough storage for more than month timestep + int rank_SWPcrits[5]; // array to store the SWP crits in order of lest negative to most negative (used in sxw_resource) // used in SW_Output.c for creating column headers int col_status_dy; int col_status_wk; int col_status_mo; int col_status_yr; - }; #define SXW_NFILES 5 From 99440a5fb4dc997a8abba136abe8f7b12526c9a7 Mon Sep 17 00:00:00 2001 From: BrendenBe1 Date: Wed, 15 Nov 2017 17:07:21 -0700 Subject: [PATCH 054/111] Summed up repartitioned soilwater --- ST_main.c | 3 ++- sw_src | 2 +- sxw.c | 14 ++++++++++---- sxw.h | 7 ++++--- 4 files changed, 17 insertions(+), 9 deletions(-) diff --git a/ST_main.c b/ST_main.c index 9ee5c3fa..40bc4551 100644 --- a/ST_main.c +++ b/ST_main.c @@ -241,7 +241,8 @@ int main(int argc, char **argv) { RandSeed(Globals.randseed); Globals.currIter = iter; - memset(SXW.transp_SWA,0,sizeof(SXW.transp_SWA)); // set transp_SWA to 0; needs to be reset each iteration + memset(SXW.transp_SWA, 0, sizeof(SXW.transp_SWA)); // set transp_SWA to 0; needs to be reset each iteration + memset(SXW.sum_dSWA_repartitioned, 0, sizeof(SXW.sum_dSWA_repartitioned)); /* ------ Begin running the model ------ */ for (year = 1; year <= Globals.runModelYears; year++){ diff --git a/sw_src b/sw_src index 8d15bc51..48509167 160000 --- a/sw_src +++ b/sw_src @@ -1 +1 @@ -Subproject commit 8d15bc51ec35b81fafcc155031752602e2efb6e1 +Subproject commit 485091672a3d9d86532057b54468b6c139951f3f diff --git a/sxw.c b/sxw.c index 686d9f18..7069e9a4 100644 --- a/sxw.c +++ b/sxw.c @@ -923,6 +923,7 @@ static void _make_transp_arrays(void) { static void _make_swa_array(void){ char *fstr = "_make_swa_array()"; int size = SXW.NPds * SXW.NSoLyrs; + //int size_3d = 4 * SXW.NPds * SXW.NSoLyrs; SXW.SWAbulk_grass_avg = (RealF *) Mem_Calloc(size, sizeof(RealF *), fstr); SXW.SWAbulk_shrub_avg = (RealF *) Mem_Calloc(size, sizeof(RealF *), fstr); @@ -934,11 +935,14 @@ static void _make_swa_array(void){ Mem_Set(SXW.SWAbulk_tree_avg, 0, SXW.NPds * SXW.NSoLyrs * sizeof(RealF)); Mem_Set(SXW.SWAbulk_forb_avg, 0, SXW.NPds * SXW.NSoLyrs * sizeof(RealF)); + //SXW.sum_dSWA_repartitioned = (RealF *) Mem_Calloc(size_3d, sizeof(RealF), fstr); + //Mem_Set(SXW.sum_dSWA_repartitioned, 0, size_3d); + //4 - Grass,Frob,Tree,Shrub - size = 4 * SXW.NPds * SXW.NSoLyrs; - SXW.SWA_master = (RealF *) Mem_Calloc(size, sizeof(RealF), fstr); - SXW.dSWAbulk = (RealF *) Mem_Calloc(size, sizeof(RealF), fstr); - SXW.dSWA_repartitioned = (RealF *) Mem_Calloc(size, sizeof(RealF), fstr); + size = 4 * 4 * SXW.NPds * SXW.NSoLyrs; + SXW.SWA_master = (RealF *) Mem_Calloc(size, sizeof(RealF), fstr); // 4D + SXW.dSWAbulk = (RealF *) Mem_Calloc(size, sizeof(RealF), fstr); // 4D + SXW.dSWA_repartitioned = (RealF *) Mem_Calloc(size, sizeof(RealF), fstr); // 4D //Mem_Set(SXW.SWA_master, 0, SXW.NPds * 4 * SXW.NSoLyrs * sizeof(RealF)); memset(SXW.SWA_master, 0, sizeof(SXW.SWA_master)); @@ -1306,6 +1310,8 @@ void free_all_sxw_memory( void ) { Mem_Free(SXW.SWAbulk_tree_avg); Mem_Free(SXW.SWAbulk_forb_avg); + //Mem_Free(SXW.sum_dSWA_repartitioned); + Mem_Free(SXW.SWA_master); Mem_Free(SXW.dSWAbulk); Mem_Free(SXW.dSWA_repartitioned); diff --git a/sxw.h b/sxw.h index 9491dac7..29f22e59 100644 --- a/sxw.h +++ b/sxw.h @@ -80,10 +80,11 @@ struct stepwat_st { *SWAbulk_forb_avg; RealF *SWA_master, // 4D array to store SWA for all veg_types - *dSWAbulk, // store actual available SWA - *dSWA_repartitioned; // store repartioned SWA values + *dSWAbulk, // 4D array to store actual available SWA + *dSWA_repartitioned; // 4D array to store repartioned SWA values - //int rank_SWPcrits[5]; // array to store the SWP crits in order of lest negative to most negative (used in sxw_resource) + // going to want to change this to Itlp array + RealF sum_dSWA_repartitioned[4][10][500]; // store the sum of dSWA_repartitioned for each veg_type, layer, timeperiod. 3D array RealF transp_SWA[MAX_YEARS][11]; // store the sum of SWA and transp for each year and resource. transp_SWA[year][steppe_resource_group] int rank_SWPcrits[5]; // array to store the SWP crits in order of lest negative to most negative (used in sxw_resource) From d21123add13af85bc4da0386302f7ddd9d2e6c81 Mon Sep 17 00:00:00 2001 From: BrendenBe1 Date: Fri, 17 Nov 2017 13:49:46 -0700 Subject: [PATCH 055/111] Using sum_dSWA_repartitioned values in sxw_resource.c --- sw_src | 2 +- sxw.c | 120 +------------------------------------------------ sxw.h | 2 +- sxw_resource.c | 12 ++--- 4 files changed, 10 insertions(+), 126 deletions(-) diff --git a/sw_src b/sw_src index 48509167..979e78b7 160000 --- a/sw_src +++ b/sw_src @@ -1 +1 @@ -Subproject commit 485091672a3d9d86532057b54468b6c139951f3f +Subproject commit 979e78b7a1af86b4a19d6b2a890022db80eb033a diff --git a/sxw.c b/sxw.c index 7069e9a4..56ec294c 100644 --- a/sxw.c +++ b/sxw.c @@ -107,6 +107,7 @@ RealD * _roots_max, /* read from root distr. file */ /* simple vectors hold the resource information for each group */ /* curr/equ gives the available/required ratio */ RealF _resource_cur[MAX_RGROUPS], /* current resource utilization */ + _resource_cur_swa[MAX_RGROUPS], _resource_pr[MAX_RGROUPS]; /* resource convertable to PR */ #ifdef SXW_BYMAXSIZE @@ -144,7 +145,6 @@ static void _make_roots_arrays(void); static void _make_phen_arrays(void); static void _make_prod_arrays(void); static void _make_transp_arrays(void); -static void _write_sw_outin(void); //static void _recover_names(void); static void _read_debugfile(void); void _print_debuginfo(void); @@ -208,7 +208,6 @@ void SXW_Init( Bool init_SW, char *f_roots ) { if (SXW.debugfile) _read_debugfile(); - //_write_sw_outin(); if(init_SW) { @@ -723,123 +722,6 @@ static void _read_watin(void) { } -static void _write_sw_outin(void) { -/*======================================================*/ -/* make sure the outsetup file for soilwat contains only - * the given information */ -/* Note that there won't actually be any output. These - * keys are required to trigger the correct part of the - * output accumulation routines. Refer to the Output.c - * module of SOILWAT for more. - */ - FILE *fp; - char pd[3]; - - switch (SXW.NPds) { - case MAX_WEEKS: - strcpy(pd, "WK"); - break; - case MAX_MONTHS: - strcpy(pd, "MO"); - break; - case MAX_DAYS: - strcpy(pd, "DY"); - break; - } - - // reading outsetup_v30.in file to get timestep values - FILE *zq; - zq = fopen(_swOutDefName, "r"); - int lineNum = 0; - if(zq){ - char lineLen[100]; - char timestepVals[100]; - char *timeStep_final[4]; - while(fgets(lineLen, sizeof lineLen, zq) != NULL){ - if(lineNum == 5 || lineNum == 3){ // check both lines in case debug is turned off which would make line 3 the last line - char *timeCheck = strstr(lineLen, "TIMESTEP"); // check if this line is the one that outlines the timesteps - if(timeCheck){ - printf("%s\n", lineLen); - strcpy(timestepVals, lineLen); - } - } - lineNum++; - } - // done reading outsetup_v30.in file - - char ** res = NULL; - char * p = strtok (timestepVals, " "); - int n_spaces = 0, i; - - /* split string and append tokens to 'res' */ - - while (p) { - res = realloc (res, sizeof (char*) * ++n_spaces); - - if (res == NULL) - exit (-1); /* memory allocation failed */ - - res[n_spaces-1] = p; - - p = strtok (NULL, " "); - - } - - /* realloc one extra element for the last NULL */ - - res = realloc (res, sizeof (char*) * (n_spaces+1)); - res[n_spaces] = 0; - - /* print the result */ - for (i = 0; i < (n_spaces); ++i){ - printf ("res[%d] = %s\n", i, res[i]); - - if(strcmp(res[i],"dy")){ - //printf("DAY\n"); - timeStep_final[0] = "dy"; - //printf("timeStep_final[0]: %s\n", timeStep_final[0]); - } - else if(strcmp(res[i],"wk")){ - //printf("WEEK\n"); - timeStep_final[1] = "wk"; - //printf("timeStep_final[1]: %s\n", timeStep_final[1]); - } - else if(strcmp(res[i],"mo")){ - //printf("MO\n"); - timeStep_final[2] = "mo"; - //printf("timeStep_final[2]: %s\n", timeStep_final[2]); - } - else if(strcmp(res[i],"yr")){ - //printf("YR\n"); - timeStep_final[3] = "yr"; - //printf("timeStep_final[3]: %s\n", timeStep_final[3]); - } - else printf("\nelse\n\n"); - } - - - /* free the memory allocated */ - - free (res); - // - - fclose(zq); - } - - fp = OpenFile(_swOutDefName, "w"); - fprintf(fp, "TRANSP SUM %s 1 end transp\n", pd); - fprintf(fp, "PRECIP SUM YR 1 end precip\n"); - fprintf(fp, "TEMP AVG YR 1 end temp\n"); - if (SXW.debugfile) { - fprintf(fp, "AET SUM YR 1 end aet\n"); - fprintf(fp, "SWCBULK FIN MO 1 end swc_bulk\n"); - } - fprintf(fp, "SWA AVG MO 1 end swa\n"); - fprintf(fp, "TIMESTEP dy wk mo yr\n"); - - CloseFile(&fp); -} - static void _make_arrays(void) { /*======================================================*/ /* central point to make all dynamically allocated arrays diff --git a/sxw.h b/sxw.h index 29f22e59..0e497489 100644 --- a/sxw.h +++ b/sxw.h @@ -84,7 +84,7 @@ struct stepwat_st { *dSWA_repartitioned; // 4D array to store repartioned SWA values // going to want to change this to Itlp array - RealF sum_dSWA_repartitioned[4][10][500]; // store the sum of dSWA_repartitioned for each veg_type, layer, timeperiod. 3D array + RealF sum_dSWA_repartitioned[4][20][500]; // [veg_type][layer][timeperiod] store the sum of dSWA_repartitioned. 3D array RealF transp_SWA[MAX_YEARS][11]; // store the sum of SWA and transp for each year and resource. transp_SWA[year][steppe_resource_group] int rank_SWPcrits[5]; // array to store the SWP crits in order of lest negative to most negative (used in sxw_resource) diff --git a/sxw_resource.c b/sxw_resource.c index 49a17448..271f4942 100644 --- a/sxw_resource.c +++ b/sxw_resource.c @@ -76,7 +76,8 @@ extern extern RealF _resource_pr[MAX_RGROUPS], /* resource convertable to pr */ - _resource_cur[MAX_RGROUPS]; /* current resource utilization */ + _resource_cur[MAX_RGROUPS], + _resource_cur_swa[MAX_RGROUPS]; /* current resource utilization */ extern RealF _bvt; @@ -153,13 +154,15 @@ void _sxw_update_resource(void) { _sxw_update_root_tables(sizes); _transp_contribution_by_group(_resource_cur); - _SWA_contribution_by_group(_resource_cur); + _SWA_contribution_by_group(_resource_cur_swa); ForEachGroup(g) { _resource_cur[g] = SXW.transp_SWA[currentYear][g]; + //_resource_cur_swa[g] = SXW.sum_dSWA_repartitioned[currentYear][1][g]; //_resource_pr[g] = ZRO(sizes[g]) ? 0.0 : _resource_cur[g] * _bvt / sizes[g]; _resource_cur[g] = _resource_cur[g] * _bvt; + //_resource_cur_swa[g] = _resource_cur_swa[g] * _bvt; } /* _print_debuginfo(); */ } @@ -234,13 +237,12 @@ static void _transp_contribution_by_group(RealF use_by_group[]) { */ GrpIndex g; - SppIndex s; TimeInt p; LyrIndex l; int currentYear; if(SW_Model.year == 0) currentYear = 0; else currentYear = SW_Model.year - SW_Model.startyr; - int t,i; + int t; RealD *transp; RealF sumUsedByGroup = 0., sumTranspTotal = 0., TranspRemaining = 0.; @@ -302,7 +304,7 @@ static void _SWA_contribution_by_group(RealF use_by_group[]) { if(SW_Model.year == 0) currentYear = 0; else currentYear = SW_Model.year - SW_Model.startyr; int t; - RealF sumUsedByGroup = 0., sumSWATotal = 0., SWARemaining = 0.; + RealF sumUsedByGroup = 0.; ForEachGroup(g) // steppe functional group { From e970e8c7d9ff9686c8f13e1a793e31193e1ff92f Mon Sep 17 00:00:00 2001 From: BrendenBe1 Date: Mon, 27 Nov 2017 13:52:00 -0700 Subject: [PATCH 056/111] Changes to sxw_resource.c --- sw_src | 2 +- sxw_resource.c | 19 +++++++------------ 2 files changed, 8 insertions(+), 13 deletions(-) diff --git a/sw_src b/sw_src index 979e78b7..69194e94 160000 --- a/sw_src +++ b/sw_src @@ -1 +1 @@ -Subproject commit 979e78b7a1af86b4a19d6b2a890022db80eb033a +Subproject commit 69194e94284f073f579bcc252aeee702b8a07e8b diff --git a/sxw_resource.c b/sxw_resource.c index 271f4942..961029da 100644 --- a/sxw_resource.c +++ b/sxw_resource.c @@ -76,8 +76,7 @@ extern extern RealF _resource_pr[MAX_RGROUPS], /* resource convertable to pr */ - _resource_cur[MAX_RGROUPS], - _resource_cur_swa[MAX_RGROUPS]; /* current resource utilization */ + _resource_cur[MAX_RGROUPS]; extern RealF _bvt; @@ -154,15 +153,12 @@ void _sxw_update_resource(void) { _sxw_update_root_tables(sizes); _transp_contribution_by_group(_resource_cur); - _SWA_contribution_by_group(_resource_cur_swa); + _SWA_contribution_by_group(SXW.sum_dSWA_repartitioned); ForEachGroup(g) { _resource_cur[g] = SXW.transp_SWA[currentYear][g]; - //_resource_cur_swa[g] = SXW.sum_dSWA_repartitioned[currentYear][1][g]; - //_resource_pr[g] = ZRO(sizes[g]) ? 0.0 : _resource_cur[g] * _bvt / sizes[g]; _resource_cur[g] = _resource_cur[g] * _bvt; - //_resource_cur_swa[g] = _resource_cur_swa[g] * _bvt; } /* _print_debuginfo(); */ } @@ -311,14 +307,13 @@ static void _SWA_contribution_by_group(RealF use_by_group[]) { use_by_group[g] = 0.; // clear t = RGroup[g]->veg_prod_type-1; - /*ForEachTrPeriod(p) + ForEachTrPeriod(p) { for (l = 0; l < SXW.NSoLyrs; l++) { - // TODO: need to figure out actual value for 2nd param in Itclp - use_by_group[g] += (RealF) (_roots_active_rel[Iglp(g, l, p)] * SXW.SWA_master[Itclp(t,0,l,p)]); //min_res_req is space parameter + use_by_group[g] += (RealF) (_roots_active_rel[Iglp(g, l, p)] * SXW.sum_dSWA_repartitioned[g][l][p]); //min_res_req is space parameter } - }*/ - //sumUsedByGroup += use_by_group[g]; - //SXW.transp_SWA[currentYear][g] += sumUsedByGroup; + } + sumUsedByGroup += use_by_group[g]; + SXW.transp_SWA[currentYear][g] += sumUsedByGroup; } } From 10d1944d6159202387f1cf4ad6cc06c7522648e3 Mon Sep 17 00:00:00 2001 From: BrendenBe1 Date: Mon, 27 Nov 2017 17:17:13 -0700 Subject: [PATCH 057/111] Working on getting values to correctly average over all iterations --- ST_stats.c | 19 ------------------- sw_src | 2 +- sxw_resource.c | 3 +++ .../Input/sxw/Input/outsetup_v30.in | 2 +- 4 files changed, 5 insertions(+), 21 deletions(-) diff --git a/ST_stats.c b/ST_stats.c index afad0e7e..45b23d8c 100644 --- a/ST_stats.c +++ b/ST_stats.c @@ -49,7 +49,6 @@ void stat_Output_YrMorts( void ) ; void stat_Output_AllMorts( void) ; void stat_Output_AllBmass(void) ; - void stat_Average_SOILWAT_vars(float *outputVar, float *outputVarAvg, int loopYear, int loopLayer) ; //adding below function for adding modified soilwat output at stepwat location void stat_Output_AllSoilwatVariables(void); @@ -1465,24 +1464,6 @@ static void _make_header_for_soilwat(char *buf, char *header1, char *header2, in } -// regular structure average structure year layer -void stat_Average_SOILWAT_vars(float *outputVar, float *outputVarAvg, int loopYear, int loopLayer){ - // need to average all of the variables outlined in the outsetup file - int i; - float outputAvg = 0; // current value - // average the months to year - for(i=0; i<12; i++){ - //outputAvg += outputVar[i][loopLayer]; - ///outputAvg += outputVar[Ilp(loopLayer,i)]; - //if(loopYear == 1)printf("outputVar[Ilp(%d,%d)]: %f\n", loopLayer, i, SXW.transpTotal[Ilp(loopLayer,i)]); - } - ///outputAvg /= 12; - //outputVarAvg[loopYear][loopLayer] += outputAvg; //[year][layer] - ///outputVarAvg[Ilp(loopLayer,loopYear)] += outputAvg; //[year][layer] - - ///printf("outputAvg: %f\n", outputAvg); -} - // store soilwat values in a csv // TODO: need to clean up this function... too many commented out blobs and ugly/hard to read void stat_Output_AllSoilwatVariables(void) diff --git a/sw_src b/sw_src index 69194e94..096034c8 160000 --- a/sw_src +++ b/sw_src @@ -1 +1 @@ -Subproject commit 69194e94284f073f579bcc252aeee702b8a07e8b +Subproject commit 096034c8d7328dc3fa11b74a1d02562d2044e3fa diff --git a/sxw_resource.c b/sxw_resource.c index 961029da..36afc3a0 100644 --- a/sxw_resource.c +++ b/sxw_resource.c @@ -158,7 +158,9 @@ void _sxw_update_resource(void) { ForEachGroup(g) { _resource_cur[g] = SXW.transp_SWA[currentYear][g]; + //printf("resource_cur prior to multiplication: %f\n", _resource_cur[g]); _resource_cur[g] = _resource_cur[g] * _bvt; + //printf("resource_cur post multiplication: %f\n\n", _resource_cur[g]); } /* _print_debuginfo(); */ } @@ -315,5 +317,6 @@ static void _SWA_contribution_by_group(RealF use_by_group[]) { } sumUsedByGroup += use_by_group[g]; SXW.transp_SWA[currentYear][g] += sumUsedByGroup; + //printf("SXW.transp_SWA[%d][%d]: %f\n", currentYear, g, SXW.transp_SWA[currentYear][g]); } } diff --git a/testing.sagebrush.master/Stepwat_Inputs/Input/sxw/Input/outsetup_v30.in b/testing.sagebrush.master/Stepwat_Inputs/Input/sxw/Input/outsetup_v30.in index 5c50f06e..0f8f3299 100644 --- a/testing.sagebrush.master/Stepwat_Inputs/Input/sxw/Input/outsetup_v30.in +++ b/testing.sagebrush.master/Stepwat_Inputs/Input/sxw/Input/outsetup_v30.in @@ -1,4 +1,4 @@ -TIMESTEP dy wk mo +TIMESTEP mo TRANSP SUM MO 1 end transp PRECIP SUM YR 1 end precip TEMP AVG YR 1 end temp From af198f6c320c20fe895393347f36a598ed5dc4be Mon Sep 17 00:00:00 2001 From: BrendenBe1 Date: Wed, 29 Nov 2017 16:54:18 -0700 Subject: [PATCH 058/111] Changed the output format for STEPPE. Now the values are only output to the file corresponding to the timeperiod that it was defined to be used with in outsetup.in. --- sw_src | 2 +- .../Stepwat_Inputs/Input/sxw/Input/outsetup_v30.in | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/sw_src b/sw_src index 096034c8..daf61eeb 160000 --- a/sw_src +++ b/sw_src @@ -1 +1 @@ -Subproject commit 096034c8d7328dc3fa11b74a1d02562d2044e3fa +Subproject commit daf61eeb4c90c67b4c42cf623271a2b704f15f24 diff --git a/testing.sagebrush.master/Stepwat_Inputs/Input/sxw/Input/outsetup_v30.in b/testing.sagebrush.master/Stepwat_Inputs/Input/sxw/Input/outsetup_v30.in index 0f8f3299..259c13ed 100644 --- a/testing.sagebrush.master/Stepwat_Inputs/Input/sxw/Input/outsetup_v30.in +++ b/testing.sagebrush.master/Stepwat_Inputs/Input/sxw/Input/outsetup_v30.in @@ -1,4 +1,4 @@ -TIMESTEP mo +TIMESTEP mo yr // output files to be created TRANSP SUM MO 1 end transp PRECIP SUM YR 1 end precip TEMP AVG YR 1 end temp From 0435537ca4518e88b41592185f67fab0e238da2c Mon Sep 17 00:00:00 2001 From: BrendenBe1 Date: Fri, 1 Dec 2017 13:52:30 -0700 Subject: [PATCH 059/111] Average of value over all iterations is fully functional and ammended code in sxw_resource.c to get resource_cur --- sxw.c | 54 +++++++++++++++++++++++++++++++++----------------- sxw.h | 14 ++++++++++++- sxw_resource.c | 4 +++- 3 files changed, 52 insertions(+), 20 deletions(-) diff --git a/sxw.c b/sxw.c index 56ec294c..bdc239ed 100644 --- a/sxw.c +++ b/sxw.c @@ -780,6 +780,7 @@ static void _make_transp_arrays(void) { */ char *fstr = "_make_transp_array()"; int size; + int avg_size; size = SXW.NPds * SXW.NSoLyrs; SXW.transpTotal = (RealD *) Mem_Calloc(size, sizeof(RealD), fstr); @@ -788,34 +789,37 @@ static void _make_transp_arrays(void) { SXW.transpForbs = (RealD *) Mem_Calloc(size, sizeof(RealD), fstr); SXW.transpGrasses = (RealD *) Mem_Calloc(size, sizeof(RealD), fstr); - SXW.transpTotal_avg = (RealD *) Mem_Calloc(size, sizeof(RealD), fstr); - SXW.transpTrees_avg = (RealD *) Mem_Calloc(size, sizeof(RealD), fstr); - SXW.transpShrubs_avg = (RealD *) Mem_Calloc(size, sizeof(RealD), fstr); - SXW.transpForbs_avg = (RealD *) Mem_Calloc(size, sizeof(RealD), fstr); - SXW.transpGrasses_avg = (RealD *) Mem_Calloc(size, sizeof(RealD), fstr); + avg_size = (SXW.NPds * SXW.NSoLyrs * Globals.runModelYears) * Globals.runModelYears; + SXW.transpTotal_avg = (RealD *) Mem_Calloc(avg_size, sizeof(RealD), fstr); + SXW.transpTrees_avg = (RealD *) Mem_Calloc(avg_size, sizeof(RealD), fstr); + SXW.transpShrubs_avg = (RealD *) Mem_Calloc(avg_size, sizeof(RealD), fstr); + SXW.transpForbs_avg = (RealD *) Mem_Calloc(avg_size, sizeof(RealD), fstr); + SXW.transpGrasses_avg = (RealD *) Mem_Calloc(avg_size, sizeof(RealD), fstr); // initialize values to 0 - Mem_Set(SXW.transpTotal_avg, 0, SXW.NPds * SXW.NSoLyrs * sizeof(RealD)); - Mem_Set(SXW.transpTrees_avg, 0, SXW.NPds * SXW.NSoLyrs * sizeof(RealD)); - Mem_Set(SXW.transpShrubs_avg, 0, SXW.NPds * SXW.NSoLyrs * sizeof(RealD)); - Mem_Set(SXW.transpForbs_avg, 0, SXW.NPds * SXW.NSoLyrs * sizeof(RealD)); - Mem_Set(SXW.transpGrasses_avg, 0, SXW.NPds * SXW.NSoLyrs * sizeof(RealD)); + Mem_Set(SXW.transpTotal_avg, 0, SXW.NPds * SXW.NSoLyrs * Globals.runModelYears * sizeof(RealD)); + Mem_Set(SXW.transpTrees_avg, 0, SXW.NPds * SXW.NSoLyrs * Globals.runModelYears * sizeof(RealD)); + Mem_Set(SXW.transpShrubs_avg, 0, SXW.NPds * SXW.NSoLyrs * Globals.runModelYears * sizeof(RealD)); + Mem_Set(SXW.transpForbs_avg, 0, SXW.NPds * SXW.NSoLyrs * Globals.runModelYears * sizeof(RealD)); + Mem_Set(SXW.transpGrasses_avg, 0, SXW.NPds * SXW.NSoLyrs * Globals.runModelYears * sizeof(RealD)); } static void _make_swa_array(void){ char *fstr = "_make_swa_array()"; int size = SXW.NPds * SXW.NSoLyrs; + int avg_size; //int size_3d = 4 * SXW.NPds * SXW.NSoLyrs; - SXW.SWAbulk_grass_avg = (RealF *) Mem_Calloc(size, sizeof(RealF *), fstr); - SXW.SWAbulk_shrub_avg = (RealF *) Mem_Calloc(size, sizeof(RealF *), fstr); - SXW.SWAbulk_tree_avg = (RealF *) Mem_Calloc(size, sizeof(RealF *), fstr); - SXW.SWAbulk_forb_avg = (RealF *) Mem_Calloc(size, sizeof(RealF *), fstr); + avg_size = (SXW.NPds * SXW.NSoLyrs * Globals.runModelYears) * Globals.runModelYears; + SXW.SWAbulk_grass_avg = (RealF *) Mem_Calloc(avg_size, sizeof(RealF *), fstr); + SXW.SWAbulk_shrub_avg = (RealF *) Mem_Calloc(avg_size, sizeof(RealF *), fstr); + SXW.SWAbulk_tree_avg = (RealF *) Mem_Calloc(avg_size, sizeof(RealF *), fstr); + SXW.SWAbulk_forb_avg = (RealF *) Mem_Calloc(avg_size, sizeof(RealF *), fstr); - Mem_Set(SXW.SWAbulk_grass_avg, 0, SXW.NPds * SXW.NSoLyrs * sizeof(RealF)); - Mem_Set(SXW.SWAbulk_shrub_avg, 0, SXW.NPds * SXW.NSoLyrs * sizeof(RealF)); - Mem_Set(SXW.SWAbulk_tree_avg, 0, SXW.NPds * SXW.NSoLyrs * sizeof(RealF)); - Mem_Set(SXW.SWAbulk_forb_avg, 0, SXW.NPds * SXW.NSoLyrs * sizeof(RealF)); + Mem_Set(SXW.SWAbulk_grass_avg, 0, SXW.NPds * SXW.NSoLyrs * Globals.runModelYears * sizeof(RealF)); + Mem_Set(SXW.SWAbulk_shrub_avg, 0, SXW.NPds * SXW.NSoLyrs * Globals.runModelYears * sizeof(RealF)); + Mem_Set(SXW.SWAbulk_tree_avg, 0, SXW.NPds * SXW.NSoLyrs * Globals.runModelYears * sizeof(RealF)); + Mem_Set(SXW.SWAbulk_forb_avg, 0, SXW.NPds * SXW.NSoLyrs * Globals.runModelYears * sizeof(RealF)); //SXW.sum_dSWA_repartitioned = (RealF *) Mem_Calloc(size_3d, sizeof(RealF), fstr); //Mem_Set(SXW.sum_dSWA_repartitioned, 0, size_3d); @@ -826,8 +830,15 @@ static void _make_swa_array(void){ SXW.dSWAbulk = (RealF *) Mem_Calloc(size, sizeof(RealF), fstr); // 4D SXW.dSWA_repartitioned = (RealF *) Mem_Calloc(size, sizeof(RealF), fstr); // 4D + //int newSize = 4*SXW.NPds * SXW.NSoLyrs; + //SXW.sum_dSWA_repartitioned = (RealF *) Mem_Calloc(newSize, sizeof(RealF *), fstr); + //Mem_Set(SXW.sum_dSWA_repartitioned, 0, SXW.NPds * SXW.NSoLyrs * 4 * sizeof(RealF)); + //Mem_Set(SXW.SWA_master, 0, SXW.NPds * 4 * SXW.NSoLyrs * sizeof(RealF)); memset(SXW.SWA_master, 0, sizeof(SXW.SWA_master)); + Mem_Set(SXW.dSWAbulk, 0, 4*4*SXW.NPds * SXW.NSoLyrs * sizeof(RealF)); + Mem_Set(SXW.dSWA_repartitioned, 0, 4*4*SXW.NPds * SXW.NSoLyrs * sizeof(RealF)); + //memset(SXW.sum_dSWA_repartitioned, 0, sizeof(SXW.sum_dSWA_repartitioned) * 5 * 20 * 500); } static void _make_swc_array(void) { @@ -838,7 +849,13 @@ static void _make_swc_array(void) { */ char *fstr = "_make_swc_array()"; int size = SXW.NPds * SXW.NSoLyrs; + int avg_size; + //int size_3d = 4 * SXW.NPds * SXW.NSoLyrs; + SXW.swc = (RealF *) Mem_Calloc(size, sizeof(RealF *), fstr); + + avg_size = (SXW.NPds * SXW.NSoLyrs * Globals.runModelYears) * Globals.runModelYears; + SXW.swc_avg = (RealF *) Mem_Calloc(avg_size, sizeof(RealF), fstr); } @@ -1199,6 +1216,7 @@ void free_all_sxw_memory( void ) { Mem_Free(SXW.dSWA_repartitioned); Mem_Free(SXW.swc); + Mem_Free(SXW.swc_avg); } /***********************************************************/ diff --git a/sxw.h b/sxw.h index 0e497489..0a3cbd8b 100644 --- a/sxw.h +++ b/sxw.h @@ -84,7 +84,8 @@ struct stepwat_st { *dSWA_repartitioned; // 4D array to store repartioned SWA values // going to want to change this to Itlp array - RealF sum_dSWA_repartitioned[4][20][500]; // [veg_type][layer][timeperiod] store the sum of dSWA_repartitioned. 3D array + RealF sum_dSWA_repartitioned[80][80][366]; // [veg_type][layer][timeperiod] store the sum of dSWA_repartitioned. 3D array + //RealF *sum_dSWA_repartitioned; RealF transp_SWA[MAX_YEARS][11]; // store the sum of SWA and transp for each year and resource. transp_SWA[year][steppe_resource_group] int rank_SWPcrits[5]; // array to store the SWP crits in order of lest negative to most negative (used in sxw_resource) @@ -94,6 +95,11 @@ struct stepwat_st { int col_status_wk; int col_status_mo; int col_status_yr; + + RealF *swc_avg; + RealF val_snowmelt_avg[1000], // set to 1000 for max years + val_snowloss_avg[1000], + aet_avg[1000]; }; #define SXW_NFILES 5 @@ -117,8 +123,14 @@ typedef struct stepwat_st SXW_t; /* convert 4-d index to actual array index for * veg-prod-type/crit-value/layer/phenology */ + //veg_type, new_critical_value, layer, timeperiod #define Itclp(t,c,l,p) (((t)*SXW.NTrLyrs*SXW.NPds) + ((c)*4) + ((l)*SXW.NPds) + (p)) // c*4 is because there are 4 critical values +// for use with avg values +#define Iylp(y,l,p) (((y)*Globals.runModelYears * SXW.NTrLyrs * SXW.NPds) + ((l)*SXW.NTrLyrs * SXW.NPds) + ((p)*SXW.NPds)) + +#define Ivlp(v,l,p) (((v)*4 * SXW.NTrLyrs * SXW.NPds) + ((l)*SXW.NTrLyrs * SXW.NPds) + ((p)*SXW.NPds)) + /* convert 2d layer by period indices to layer/phenology 1D index */ #define Ilp(l,p) ((l)*SXW.NPds + (p)) diff --git a/sxw_resource.c b/sxw_resource.c index 36afc3a0..75a803a9 100644 --- a/sxw_resource.c +++ b/sxw_resource.c @@ -308,11 +308,13 @@ static void _SWA_contribution_by_group(RealF use_by_group[]) { { use_by_group[g] = 0.; // clear t = RGroup[g]->veg_prod_type-1; + //printf("g, t || %d, %d\n", g, t); ForEachTrPeriod(p) { for (l = 0; l < SXW.NSoLyrs; l++) { - use_by_group[g] += (RealF) (_roots_active_rel[Iglp(g, l, p)] * SXW.sum_dSWA_repartitioned[g][l][p]); //min_res_req is space parameter + //printf("%d,%d,%d\n", g,l,p); + use_by_group[g] += (RealF) (_roots_active_rel[Iglp(g, l, p)] * SXW.sum_dSWA_repartitioned[t][l][p]); //min_res_req is space parameter } } sumUsedByGroup += use_by_group[g]; From e72e1d98a5a40b59d045125e065df8f7f45fe7b3 Mon Sep 17 00:00:00 2001 From: BrendenBe1 Date: Fri, 1 Dec 2017 14:00:17 -0700 Subject: [PATCH 060/111] Average of value over all iterations is fully functional and ammended code in sxw_resource.c to get resource_cur --- sw_src | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sw_src b/sw_src index daf61eeb..49f44c50 160000 --- a/sw_src +++ b/sw_src @@ -1 +1 @@ -Subproject commit daf61eeb4c90c67b4c42cf623271a2b704f15f24 +Subproject commit 49f44c5078d60d9715209f54f0aced2f0a19d298 From ed6536f47d6e70de906149ca83e7aa371685ce85 Mon Sep 17 00:00:00 2001 From: BrendenBe1 Date: Mon, 4 Dec 2017 10:00:06 -0700 Subject: [PATCH 061/111] Added print statements for testing --- sw_src | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sw_src b/sw_src index 49f44c50..e239efb8 160000 --- a/sw_src +++ b/sw_src @@ -1 +1 @@ -Subproject commit 49f44c5078d60d9715209f54f0aced2f0a19d298 +Subproject commit e239efb8f690aab995a1e8a346893cad0a38e836 From 92433b11d00f79f2cffa009a12a9099bd02a0ae8 Mon Sep 17 00:00:00 2001 From: BrendenBe1 Date: Mon, 4 Dec 2017 10:25:49 -0700 Subject: [PATCH 062/111] Added print statements for testing --- sw_src | 2 +- sxw.h | 2 ++ 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/sw_src b/sw_src index e239efb8..d3fcdf20 160000 --- a/sw_src +++ b/sw_src @@ -1 +1 @@ -Subproject commit e239efb8f690aab995a1e8a346893cad0a38e836 +Subproject commit d3fcdf202469bcf50b2123e9e09f2b3bb31b9326 diff --git a/sxw.h b/sxw.h index 0a3cbd8b..1bc55202 100644 --- a/sxw.h +++ b/sxw.h @@ -127,8 +127,10 @@ typedef struct stepwat_st SXW_t; #define Itclp(t,c,l,p) (((t)*SXW.NTrLyrs*SXW.NPds) + ((c)*4) + ((l)*SXW.NPds) + (p)) // c*4 is because there are 4 critical values // for use with avg values +// year, layer, timeperiod #define Iylp(y,l,p) (((y)*Globals.runModelYears * SXW.NTrLyrs * SXW.NPds) + ((l)*SXW.NTrLyrs * SXW.NPds) + ((p)*SXW.NPds)) +// veg type, layer, timeperiod #define Ivlp(v,l,p) (((v)*4 * SXW.NTrLyrs * SXW.NPds) + ((l)*SXW.NTrLyrs * SXW.NPds) + ((p)*SXW.NPds)) /* convert 2d layer by period indices to From e37b3a75b5fb8eeb684e1d8f203e02dbdbbfb204 Mon Sep 17 00:00:00 2001 From: BrendenBe1 Date: Mon, 4 Dec 2017 11:53:31 -0700 Subject: [PATCH 063/111] Fixed error in sum_dSWA_repartitioned calculation. Needed to reset the array to 0 every year. --- sw_src | 2 +- sxw_resource.c | 1 + .../Stepwat_Inputs/Input/sxw/Input/outsetup_v30.in | 2 +- 3 files changed, 3 insertions(+), 2 deletions(-) diff --git a/sw_src b/sw_src index d3fcdf20..a99d211a 160000 --- a/sw_src +++ b/sw_src @@ -1 +1 @@ -Subproject commit d3fcdf202469bcf50b2123e9e09f2b3bb31b9326 +Subproject commit a99d211a9f59746a8c74786205951b7a15bd5c88 diff --git a/sxw_resource.c b/sxw_resource.c index 75a803a9..61109365 100644 --- a/sxw_resource.c +++ b/sxw_resource.c @@ -315,6 +315,7 @@ static void _SWA_contribution_by_group(RealF use_by_group[]) { for (l = 0; l < SXW.NSoLyrs; l++) { //printf("%d,%d,%d\n", g,l,p); use_by_group[g] += (RealF) (_roots_active_rel[Iglp(g, l, p)] * SXW.sum_dSWA_repartitioned[t][l][p]); //min_res_req is space parameter + //use_by_group[g] += (RealF) (_roots_active_rel[Iglp(g, l, p)] * SXW.sum_dSWA_repartitioned[Ivlp(t,l,p)]); //min_res_req is space parameter } } sumUsedByGroup += use_by_group[g]; diff --git a/testing.sagebrush.master/Stepwat_Inputs/Input/sxw/Input/outsetup_v30.in b/testing.sagebrush.master/Stepwat_Inputs/Input/sxw/Input/outsetup_v30.in index 259c13ed..3824a71f 100644 --- a/testing.sagebrush.master/Stepwat_Inputs/Input/sxw/Input/outsetup_v30.in +++ b/testing.sagebrush.master/Stepwat_Inputs/Input/sxw/Input/outsetup_v30.in @@ -1,4 +1,4 @@ -TIMESTEP mo yr // output files to be created +TIMESTEP mo yr TRANSP SUM MO 1 end transp PRECIP SUM YR 1 end precip TEMP AVG YR 1 end temp From 0dbd15dbad8509f397a6d62535b29ebed900a925 Mon Sep 17 00:00:00 2001 From: BrendenBe1 Date: Mon, 4 Dec 2017 14:42:58 -0700 Subject: [PATCH 064/111] Moving call to _res_part_extra into the block where SOILWAT is not being used. This fixes a problem with PR output being NULL since this call was returning NAN values. --- ST_resgroups.c | 23 +++++++++++++++++++---- sw_src | 2 +- 2 files changed, 20 insertions(+), 5 deletions(-) diff --git a/ST_resgroups.c b/ST_resgroups.c index dc8ee83e..a7dba6af 100644 --- a/ST_resgroups.c +++ b/ST_resgroups.c @@ -136,6 +136,11 @@ void rgroup_PartResources(void) size_base[rg] = g->relsize * g->min_res_req; size_obase[rg] = (g->use_extra_res) ? size_base[rg] : 0.; + /*these functions are not used if using SOILWAT, + extra resource partitioning does not occur when running SOILWAT*/ + _res_part_extra(do_base, xtra_base, size_base); + _res_part_extra(do_extra, xtra_obase, size_obase); + /*this is how res_required and res_avail are set if SOILWAT is running*/ #ifdef STEPWAT } @@ -192,8 +197,8 @@ void rgroup_PartResources(void) /*these functions are not used if using SOILWAT, extra resource partitioning does not occur when running SOILWAT*/ - _res_part_extra(do_base, xtra_base, size_base); - _res_part_extra(do_extra, xtra_obase, size_obase); + // _res_part_extra(do_base, xtra_base, size_base); + //_res_part_extra(do_extra, xtra_obase, size_obase); /* reset annuals' "true" relative size here */ //KAP: formely, this call established annual species. We have moved annual establishment to the Rgroup_Establish function, @@ -202,6 +207,7 @@ void rgroup_PartResources(void) { g = RGroup[rg]; g->pr = ZRO(g->res_avail) ? 0. : g->res_required / g->res_avail; + //printf("pr = %f res_avail = %f res_required = %f\n", g->pr, g->res_avail, g->res_required); //if (g->max_age == 1) //{ // g->relsize = _add_annuals(rg, g->pr, add_seeds); @@ -398,12 +404,21 @@ static void _res_part_extra(Bool isextra, RealF extra, RealF size[]) continue; space = (UseSoilwat) ? 1.0 : g->min_res_req; - req_prop = size[rg] / sum_size; + // checking so dont divide by 0 + if(sum_size == 0.) + req_prop = 0.; + else + req_prop = size[rg] / sum_size; + //printf("sum_size: %f\n", sum_size); if (isextra && g->use_extra_res && GT(g->xgrow, 0)) g->res_extra = req_prop * extra / space; - else + else{ g->res_avail += req_prop * extra / space; + //printf("res_avail: %f\n", g->res_avail); + //printf("req_prop: %f\n", req_prop); + //printf("res_avail: %f\n", g->res_avail); + } } diff --git a/sw_src b/sw_src index a99d211a..301edbba 160000 --- a/sw_src +++ b/sw_src @@ -1 +1 @@ -Subproject commit a99d211a9f59746a8c74786205951b7a15bd5c88 +Subproject commit 301edbba79abc15d53926d82696f9237d80558e4 From 2671c72c1a76f45ade8af1ddaad74f1a135925a8 Mon Sep 17 00:00:00 2001 From: BrendenBe1 Date: Wed, 6 Dec 2017 16:49:07 -0700 Subject: [PATCH 065/111] Replaced SWA with sum_dSWA_repartitioned in the output file --- sw_src | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sw_src b/sw_src index 301edbba..7e6ddf07 160000 --- a/sw_src +++ b/sw_src @@ -1 +1 @@ -Subproject commit 301edbba79abc15d53926d82696f9237d80558e4 +Subproject commit 7e6ddf071ad9097a0089381f94e8c48ccd04f48f From 95dde83ce28e234a1c6341b9fd454024439b4187 Mon Sep 17 00:00:00 2001 From: BrendenBe1 Date: Mon, 11 Dec 2017 15:24:39 -0700 Subject: [PATCH 066/111] -i and -o flags work together and standard deviation is being output when -o in use --- makefile | 5 ----- sw_src | 2 +- sxw.c | 22 +++++++++++----------- sxw.h | 37 +++++++++++++++++++++++++++++-------- 4 files changed, 41 insertions(+), 25 deletions(-) diff --git a/makefile b/makefile index 293bc054..c6bb2fa7 100644 --- a/makefile +++ b/makefile @@ -46,7 +46,6 @@ SRCS =\ $(Src)/sw_src/SW_Files.c\ $(Src)/sw_src/SW_Model.c\ $(Src)/sw_src/SW_Output.c\ - $(Src)/sw_src/SW_Main_Function.c\ $(Src)/sw_src/SW_Site.c\ $(Src)/sw_src/SW_Sky.c\ $(Src)/sw_src/SW_VegProd.c\ @@ -84,7 +83,6 @@ EXOBJS =\ $(oDir)/sw_src/SW_Files.o\ $(oDir)/sw_src/SW_Model.o\ $(oDir)/sw_src/SW_Output.o\ - $(oDir)/sw_src/SW_Main_Function.o\ $(oDir)/sw_src/SW_Site.o\ $(oDir)/sw_src/SW_Sky.o\ $(oDir)/sw_src/SW_VegProd.o\ @@ -220,9 +218,6 @@ $(oDir)/sw_src/SW_Output.o: sw_src/SW_Output.c sw_src/generic.h \ sw_src/SW_Weather.h $(CC) $(C_FLAGS) $(incDirs) -c -o $@ $< -$(oDir)/sw_src/SW_Main_Function.o: sw_src/SW_Main_Function.c - $(CC) $(C_FLAGS) $(incDirs) -c -o $@ $< - $(oDir)/sw_src/SW_Site.o: sw_src/SW_Site.c sw_src/generic.h sw_src/filefuncs.h \ sw_src/myMemory.h sw_src/SW_Defines.h sw_src/SW_Files.h sw_src/SW_Site.h $(CC) $(C_FLAGS) $(incDirs) -c -o $@ $< diff --git a/sw_src b/sw_src index 7e6ddf07..03200c91 160000 --- a/sw_src +++ b/sw_src @@ -1 +1 @@ -Subproject commit 7e6ddf071ad9097a0089381f94e8c48ccd04f48f +Subproject commit 03200c915cf9c8ed1f6b55e9aa2fd8867f125288 diff --git a/sxw.c b/sxw.c index bdc239ed..8cec5478 100644 --- a/sxw.c +++ b/sxw.c @@ -789,7 +789,7 @@ static void _make_transp_arrays(void) { SXW.transpForbs = (RealD *) Mem_Calloc(size, sizeof(RealD), fstr); SXW.transpGrasses = (RealD *) Mem_Calloc(size, sizeof(RealD), fstr); - avg_size = (SXW.NPds * SXW.NSoLyrs * Globals.runModelYears) * Globals.runModelYears; + avg_size = (SXW.NPds * SXW.NSoLyrs * Globals.runModelYears * 2) * Globals.runModelYears; SXW.transpTotal_avg = (RealD *) Mem_Calloc(avg_size, sizeof(RealD), fstr); SXW.transpTrees_avg = (RealD *) Mem_Calloc(avg_size, sizeof(RealD), fstr); SXW.transpShrubs_avg = (RealD *) Mem_Calloc(avg_size, sizeof(RealD), fstr); @@ -797,11 +797,11 @@ static void _make_transp_arrays(void) { SXW.transpGrasses_avg = (RealD *) Mem_Calloc(avg_size, sizeof(RealD), fstr); // initialize values to 0 - Mem_Set(SXW.transpTotal_avg, 0, SXW.NPds * SXW.NSoLyrs * Globals.runModelYears * sizeof(RealD)); - Mem_Set(SXW.transpTrees_avg, 0, SXW.NPds * SXW.NSoLyrs * Globals.runModelYears * sizeof(RealD)); - Mem_Set(SXW.transpShrubs_avg, 0, SXW.NPds * SXW.NSoLyrs * Globals.runModelYears * sizeof(RealD)); - Mem_Set(SXW.transpForbs_avg, 0, SXW.NPds * SXW.NSoLyrs * Globals.runModelYears * sizeof(RealD)); - Mem_Set(SXW.transpGrasses_avg, 0, SXW.NPds * SXW.NSoLyrs * Globals.runModelYears * sizeof(RealD)); + Mem_Set(SXW.transpTotal_avg, 0, avg_size * sizeof(RealD)); + Mem_Set(SXW.transpTrees_avg, 0, avg_size * sizeof(RealD)); + Mem_Set(SXW.transpShrubs_avg, 0, avg_size * sizeof(RealD)); + Mem_Set(SXW.transpForbs_avg, 0, avg_size * sizeof(RealD)); + Mem_Set(SXW.transpGrasses_avg, 0, avg_size * sizeof(RealD)); } static void _make_swa_array(void){ @@ -810,16 +810,16 @@ static void _make_swa_array(void){ int avg_size; //int size_3d = 4 * SXW.NPds * SXW.NSoLyrs; - avg_size = (SXW.NPds * SXW.NSoLyrs * Globals.runModelYears) * Globals.runModelYears; + avg_size = (SXW.NPds * SXW.NSoLyrs * Globals.runModelYears * 2) * Globals.runModelYears; SXW.SWAbulk_grass_avg = (RealF *) Mem_Calloc(avg_size, sizeof(RealF *), fstr); SXW.SWAbulk_shrub_avg = (RealF *) Mem_Calloc(avg_size, sizeof(RealF *), fstr); SXW.SWAbulk_tree_avg = (RealF *) Mem_Calloc(avg_size, sizeof(RealF *), fstr); SXW.SWAbulk_forb_avg = (RealF *) Mem_Calloc(avg_size, sizeof(RealF *), fstr); - Mem_Set(SXW.SWAbulk_grass_avg, 0, SXW.NPds * SXW.NSoLyrs * Globals.runModelYears * sizeof(RealF)); - Mem_Set(SXW.SWAbulk_shrub_avg, 0, SXW.NPds * SXW.NSoLyrs * Globals.runModelYears * sizeof(RealF)); - Mem_Set(SXW.SWAbulk_tree_avg, 0, SXW.NPds * SXW.NSoLyrs * Globals.runModelYears * sizeof(RealF)); - Mem_Set(SXW.SWAbulk_forb_avg, 0, SXW.NPds * SXW.NSoLyrs * Globals.runModelYears * sizeof(RealF)); + Mem_Set(SXW.SWAbulk_grass_avg, 0, avg_size * sizeof(RealF)); + Mem_Set(SXW.SWAbulk_shrub_avg, 0, avg_size * sizeof(RealF)); + Mem_Set(SXW.SWAbulk_tree_avg, 0, avg_size * sizeof(RealF)); + Mem_Set(SXW.SWAbulk_forb_avg, 0, avg_size * sizeof(RealF)); //SXW.sum_dSWA_repartitioned = (RealF *) Mem_Calloc(size_3d, sizeof(RealF), fstr); //Mem_Set(SXW.sum_dSWA_repartitioned, 0, size_3d); diff --git a/sxw.h b/sxw.h index 1bc55202..a758cfe4 100644 --- a/sxw.h +++ b/sxw.h @@ -61,7 +61,8 @@ struct stepwat_st { /* DEBUG stuff */ char *debugfile; /* added in ST_Main(), read to get debug instructions */ RealF *swc, /* dynamic array(Ilp) of SWC from SOILWAT */ - aet; /* soilwat's evapotranspiration for the year */ + aet; + /* soilwat's evapotranspiration for the year */ RealD surfaceTemp; /* soilwat's surfaceTemp */ // PPT variables @@ -97,16 +98,36 @@ struct stepwat_st { int col_status_yr; RealF *swc_avg; - RealF val_snowmelt_avg[1000], // set to 1000 for max years - val_snowloss_avg[1000], - aet_avg[1000]; + RealF val_snowmelt_avg[1000][2], // set to 1000 for max years + val_snowloss_avg[1000][2], + aet_avg[1000][2]; }; -#define SXW_NFILES 5 - +struct soilwat_average{ + RealF *soilinfilt_avg, + *runoff_avg, + *vwcbulk_avg, + *vwcmatric, + *swamatric_avg, + *swpmatric_avg, + *surfacewater_avg, + *evapsoil_avg, + *evapsurface_avg, + *interception_avg, + *lyrdrain_avg, + *hydred_avg, + *pet_avg, + *wetday_avg, + *snowpack_avg, + *deepswc_avg, + *soiltemp_avg, + *establ_avg; +}; +#define SXW_NFILES 5 typedef struct stepwat_st SXW_t; +typedef struct soilwat_average SXW_avg; #define ForEachTrPeriod(i) for((i)=0; (i)< SXW.NPds; (i)++) @@ -127,8 +148,8 @@ typedef struct stepwat_st SXW_t; #define Itclp(t,c,l,p) (((t)*SXW.NTrLyrs*SXW.NPds) + ((c)*4) + ((l)*SXW.NPds) + (p)) // c*4 is because there are 4 critical values // for use with avg values -// year, layer, timeperiod -#define Iylp(y,l,p) (((y)*Globals.runModelYears * SXW.NTrLyrs * SXW.NPds) + ((l)*SXW.NTrLyrs * SXW.NPds) + ((p)*SXW.NPds)) +// year, layer, timeperiod, avg/std +#define Iylp(y,l,p,x) (((y)*Globals.runModelYears * SXW.NTrLyrs * SXW.NPds * 2) + ((l)*SXW.NTrLyrs * SXW.NPds * 2) + ((p)*SXW.NPds * 2) + ((x)*2)) // veg type, layer, timeperiod #define Ivlp(v,l,p) (((v)*4 * SXW.NTrLyrs * SXW.NPds) + ((l)*SXW.NTrLyrs * SXW.NPds) + ((p)*SXW.NPds)) From fd349938dd566191c2f0e0c3374470e4d3ee0b0b Mon Sep 17 00:00:00 2001 From: BrendenBe1 Date: Fri, 15 Dec 2017 11:59:07 -0700 Subject: [PATCH 067/111] Fixed seg fault when running with -o flag --- sw_src | 2 +- sxw.c | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/sw_src b/sw_src index 03200c91..9e181de4 160000 --- a/sw_src +++ b/sw_src @@ -1 +1 @@ -Subproject commit 03200c915cf9c8ed1f6b55e9aa2fd8867f125288 +Subproject commit 9e181de48a349b617ad39668d486eb4f46c314df diff --git a/sxw.c b/sxw.c index 8cec5478..61de7210 100644 --- a/sxw.c +++ b/sxw.c @@ -782,7 +782,7 @@ static void _make_transp_arrays(void) { int size; int avg_size; - size = SXW.NPds * SXW.NSoLyrs; + size = (SXW.NPds * SXW.NSoLyrs) * 365; SXW.transpTotal = (RealD *) Mem_Calloc(size, sizeof(RealD), fstr); SXW.transpTrees = (RealD *) Mem_Calloc(size, sizeof(RealD), fstr); SXW.transpShrubs = (RealD *) Mem_Calloc(size, sizeof(RealD), fstr); @@ -854,7 +854,7 @@ static void _make_swc_array(void) { SXW.swc = (RealF *) Mem_Calloc(size, sizeof(RealF *), fstr); - avg_size = (SXW.NPds * SXW.NSoLyrs * Globals.runModelYears) * Globals.runModelYears; + avg_size = (SXW.NPds * SXW.NSoLyrs * Globals.runModelYears) * 365; SXW.swc_avg = (RealF *) Mem_Calloc(avg_size, sizeof(RealF), fstr); } From 4d59848105c6e9f9256e5ddc7e9d40f8aa213348 Mon Sep 17 00:00:00 2001 From: kpalmqui Date: Fri, 15 Dec 2017 16:38:39 -0700 Subject: [PATCH 068/111] updated transp&SWA_contribution_by_group #56 Resolved issue #56: Changes to transp_contribution_by_group & SWA_contribution_by_group Also cleaned up code in these two functions. --- sxw_resource.c | 109 ++++++++++++++++++++++++++++--------------------- 1 file changed, 62 insertions(+), 47 deletions(-) diff --git a/sxw_resource.c b/sxw_resource.c index 61109365..ac02514c 100644 --- a/sxw_resource.c +++ b/sxw_resource.c @@ -158,9 +158,9 @@ void _sxw_update_resource(void) { ForEachGroup(g) { _resource_cur[g] = SXW.transp_SWA[currentYear][g]; - //printf("resource_cur prior to multiplication: %f\n", _resource_cur[g]); + //printf("for groupName= %smresource_cur prior to multiplication: %f\n",RGroup[g]->name, _resource_cur[g]); _resource_cur[g] = _resource_cur[g] * _bvt; - //printf("resource_cur post multiplication: %f\n\n", _resource_cur[g]); + //printf("for groupName= %s, resource_cur post multiplication: %f\n\n",Rgroup[g]->name, _resource_cur[g]); } /* _print_debuginfo(); */ } @@ -220,33 +220,26 @@ void _sxw_update_root_tables( RealF sizes[] ) { static void _transp_contribution_by_group(RealF use_by_group[]) { /*======================================================*/ - /* - * use_by_group is the vector to be used in the resource - * availability calculation, ie, the output. - - * must call _update_root_tables() before this. - * - */ - - /* compute each group's contribution to the - * transpiration values retrieved from SOILWAT based - * on its relative size, its root distribution, and - * its phenology (activity). - */ + /* use_by_group is the amount of transpiration (cm) assigned + * to each STEPPE functional group. + * Must call _update_root_tables() before this. + * Compute each group's amount of transpiration from SOILWAT2 + * based on its biomass, root distribution, and phenological + * activity. */ GrpIndex g; TimeInt p; LyrIndex l; - int currentYear; - if(SW_Model.year == 0) currentYear = 0; - else currentYear = SW_Model.year - SW_Model.startyr; + int currentYear; + if(SW_Model.year == 0) currentYear = 0; + else currentYear = SW_Model.year - SW_Model.startyr; int t; RealD *transp; RealF sumUsedByGroup = 0., sumTranspTotal = 0., TranspRemaining = 0.; - ForEachGroup(g) // steppe functional group + ForEachGroup(g) //Steppe functional group { - use_by_group[g] = 0.; /* clear */ + use_by_group[g] = 0.; t = RGroup[g]->veg_prod_type-1; switch(t) { @@ -266,60 +259,82 @@ static void _transp_contribution_by_group(RealF use_by_group[]) { transp = SXW.transpTotal; break; } - ForEachTrPeriod(p) // loops thru each month and calculates a - //use by group for each steppe functional group according to whether that group has active living roots in giving layer for period - { - int nLyrs = getNTranspLayers(RGroup[g]->veg_prod_type); - for (l = 0; l < nLyrs; l++) { - use_by_group[g] += (RealF) (_roots_active_rel[Iglp(g, l, p)] * transp[Ilp(l, p)]); - } - } - sumUsedByGroup += use_by_group[g]; - SXW.transp_SWA[currentYear][g] += sumUsedByGroup; + + //Loops through each month and calculates amount of transpiration for each steppe functional group + //according to whether that group has active living roots in each soil layer for each month + ForEachTrPeriod(p) + { + int nLyrs = getNTranspLayers(RGroup[g]->veg_prod_type); + for (l = 0; l < nLyrs; l++) { + use_by_group[g] += (RealF) (_roots_active_rel[Iglp(g, l, p)] * transp[Ilp(l, p)]); + } + } + //printf("for groupName= %s, use_by_group[g] in transp= %f \n",RGroup[g]->name,use_by_group[g] ); + + sumUsedByGroup += use_by_group[g]; + //printf(" sumUsedByGroup in transp=%f \n",sumUsedByGroup); } - //Occasionally, extra transpiration remains and if not perfectly partitioned to RGroups. - //This check makes sure any remaining transpiration is divided proportionately among Rgroups. + //Very small amounts of transpiration remain and not perfectly partitioned to functional groups. + //This check makes sure any remaining transpiration is divided proportionately among groups. ForEachTrPeriod(p) { for (t = 0; t < SXW.NSoLyrs; t++) sumTranspTotal += SXW.transpTotal[Ilp(t, p)]; } TranspRemaining = sumTranspTotal - sumUsedByGroup; - ForEachGroup(g) + //printf(" sumTranspTotal=%f, sumUsedByGroup=%f TranspRemaining=%f \n",sumTranspTotal,sumUsedByGroup,TranspRemaining); + + ForEachGroup(g) { if(!ZRO(use_by_group[g])) { use_by_group[g] += (use_by_group[g]/sumUsedByGroup) * TranspRemaining; - } - } + //printf("for groupName= %s, after sum use_by_group[g]= %f \n",RGroup[g]->name,use_by_group[g] ); + + SXW.transp_SWA[currentYear][g] = use_by_group[g]; + //printf("for groupName= %s, SXW.transp_SWA[g] in transp= %f \n",RGroup[g]->name,SXW.transp_SWA[currentYear][g]); + } + } } static void _SWA_contribution_by_group(RealF use_by_group[]) { + /*======================================================*/ + /* use_by_group is the amount of plant available soil water (SWA,cm) + * assigned to each STEPPE functional group. + * Must call _update_root_tables() before this. + * Compute each group's amount of SWA from SOILWAT2 + * based on its biomass, root distribution, and phenological + * activity. */ + GrpIndex g; TimeInt p; LyrIndex l; - int currentYear; - if(SW_Model.year == 0) currentYear = 0; - else currentYear = SW_Model.year - SW_Model.startyr; + int currentYear; + if(SW_Model.year == 0) currentYear = 0; + else currentYear = SW_Model.year - SW_Model.startyr; int t; RealF sumUsedByGroup = 0.; - ForEachGroup(g) // steppe functional group + ForEachGroup(g) //Steppe functional group { - use_by_group[g] = 0.; // clear + use_by_group[g] = 0.; t = RGroup[g]->veg_prod_type-1; - //printf("g, t || %d, %d\n", g, t); + //printf("g, t || %d, %d\n", g, t); ForEachTrPeriod(p) { for (l = 0; l < SXW.NSoLyrs; l++) { - //printf("%d,%d,%d\n", g,l,p); - use_by_group[g] += (RealF) (_roots_active_rel[Iglp(g, l, p)] * SXW.sum_dSWA_repartitioned[t][l][p]); //min_res_req is space parameter - //use_by_group[g] += (RealF) (_roots_active_rel[Iglp(g, l, p)] * SXW.sum_dSWA_repartitioned[Ivlp(t,l,p)]); //min_res_req is space parameter + //printf("%d,%d,%d\n", g,l,p); + use_by_group[g] += (RealF) (_roots_active_rel[Iglp(g, l, p)] * SXW.sum_dSWA_repartitioned[t][l][p]); + //printf("for groupName= %s, layerIndex: %d, month: %d, in swa loop use_by_group[g]= %f \n",RGroup[g]->name,l,p,use_by_group[g]); } } - sumUsedByGroup += use_by_group[g]; - SXW.transp_SWA[currentYear][g] += sumUsedByGroup; - //printf("SXW.transp_SWA[%d][%d]: %f\n", currentYear, g, SXW.transp_SWA[currentYear][g]); + //printf("for groupName= %s, use_by_group[g] in swa= %f \n",RGroup[g]->name,use_by_group[g]); + + sumUsedByGroup += use_by_group[g]; + //printf(" sumUsedByGroup in swa=%f \n",sumUsedByGroup); + + SXW.transp_SWA[currentYear][g] += use_by_group[g]; + //printf("SXW.transp_SWA[%d][%d]: %f\n", currentYear, g, SXW.transp_SWA[currentYear][g]); } } From 62784bb7f5bf16a19f7fa80bd1d46fe7fb76f89a Mon Sep 17 00:00:00 2001 From: BrendenBe1 Date: Wed, 20 Dec 2017 13:23:47 -0700 Subject: [PATCH 069/111] Resolved SOILWAT issue #112. All SOILWAT variables are now available in STEPPE. --- sw_src | 2 +- sxw.c | 146 +++++++++++++++++- sxw.h | 63 +++++--- .../Input/sxw/Input/outsetup_v30.in | 33 +++- 4 files changed, 214 insertions(+), 30 deletions(-) diff --git a/sw_src b/sw_src index 9e181de4..4c17c22f 160000 --- a/sw_src +++ b/sw_src @@ -1 +1 @@ -Subproject commit 9e181de48a349b617ad39668d486eb4f46c314df +Subproject commit 4c17c22f27737958e07bca0e4a9af576848d8e03 diff --git a/sxw.c b/sxw.c index 61de7210..c0a5b24e 100644 --- a/sxw.c +++ b/sxw.c @@ -73,6 +73,7 @@ /*************** Global Variable Declarations ***************/ /***********************************************************/ SXW_t SXW; +SXW_avg SXW_AVG; extern SW_SITE SW_Site; extern SW_MODEL SW_Model; @@ -145,6 +146,7 @@ static void _make_roots_arrays(void); static void _make_phen_arrays(void); static void _make_prod_arrays(void); static void _make_transp_arrays(void); +static void _make_soil_arrays(void); //static void _recover_names(void); static void _read_debugfile(void); void _print_debuginfo(void); @@ -732,8 +734,8 @@ static void _make_arrays(void) { _make_prod_arrays(); _make_transp_arrays(); _make_swa_array(); - //if (SXW.debugfile || UseGrid) - _make_swc_array(); + _make_swc_array(); + _make_soil_arrays(); } static void _make_roots_arrays(void) { @@ -810,7 +812,7 @@ static void _make_swa_array(void){ int avg_size; //int size_3d = 4 * SXW.NPds * SXW.NSoLyrs; - avg_size = (SXW.NPds * SXW.NSoLyrs * Globals.runModelYears * 2) * Globals.runModelYears; + avg_size = (SXW.NPds * SXW.NSoLyrs * Globals.runModelYears * 2) * Globals.runModelYears * Globals.runModelIterations; SXW.SWAbulk_grass_avg = (RealF *) Mem_Calloc(avg_size, sizeof(RealF *), fstr); SXW.SWAbulk_shrub_avg = (RealF *) Mem_Calloc(avg_size, sizeof(RealF *), fstr); SXW.SWAbulk_tree_avg = (RealF *) Mem_Calloc(avg_size, sizeof(RealF *), fstr); @@ -825,7 +827,7 @@ static void _make_swa_array(void){ //Mem_Set(SXW.sum_dSWA_repartitioned, 0, size_3d); //4 - Grass,Frob,Tree,Shrub - size = 4 * 4 * SXW.NPds * SXW.NSoLyrs; + size = 4 * 4 * SXW.NPds * SXW.NSoLyrs * Globals.runModelIterations; SXW.SWA_master = (RealF *) Mem_Calloc(size, sizeof(RealF), fstr); // 4D SXW.dSWAbulk = (RealF *) Mem_Calloc(size, sizeof(RealF), fstr); // 4D SXW.dSWA_repartitioned = (RealF *) Mem_Calloc(size, sizeof(RealF), fstr); // 4D @@ -858,6 +860,104 @@ static void _make_swc_array(void) { SXW.swc_avg = (RealF *) Mem_Calloc(avg_size, sizeof(RealF), fstr); } +static void _make_soil_arrays(void){ + char *fstr = "_make_soil_arrays"; + int size, layer_size; + size = (SXW.NPds * Globals.runModelYears * 2) * Globals.runModelYears; + layer_size = (SXW.NPds * SXW.NSoLyrs * Globals.runModelYears * 2) * Globals.runModelYears; + + + SXW_AVG.estab_avg = (RealF *) Mem_Calloc(size, sizeof(RealF), fstr); + SXW_AVG.vwcbulk_avg = (RealF *) Mem_Calloc(layer_size, sizeof(RealF), fstr); + SXW_AVG.vwcmatric_avg = (RealF *) Mem_Calloc(layer_size, sizeof(RealF), fstr); + SXW_AVG.swpmatric_avg = (RealF *) Mem_Calloc(layer_size, sizeof(RealF), fstr); + SXW_AVG.swabulk_avg = (RealF *) Mem_Calloc(layer_size, sizeof(RealF), fstr); + SXW_AVG.swamatric_avg = (RealF *) Mem_Calloc(layer_size, sizeof(RealF), fstr); + SXW_AVG.surfacewater_avg = (RealF *) Mem_Calloc(size, sizeof(RealF), fstr); + SXW_AVG.runoff_total_avg = (RealF *) Mem_Calloc(size, sizeof(RealF), fstr); + SXW_AVG.runoff_surface_avg = (RealF *) Mem_Calloc(size, sizeof(RealF), fstr); + SXW_AVG.runoff_snow_avg = (RealF *) Mem_Calloc(size, sizeof(RealF), fstr); + SXW_AVG.evapsoil_avg = (RealF *) Mem_Calloc(layer_size, sizeof(RealF), fstr); + SXW_AVG.evapsurface_total_avg = (RealF *) Mem_Calloc(size, sizeof(RealF), fstr); + SXW_AVG.evapsurface_tree_avg = (RealF *) Mem_Calloc(size, sizeof(RealF), fstr); + SXW_AVG.evapsurface_shrub_avg = (RealF *) Mem_Calloc(size, sizeof(RealF), fstr); + SXW_AVG.evapsurface_forb_avg = (RealF *) Mem_Calloc(size, sizeof(RealF), fstr); + SXW_AVG.evapsurface_grass_avg = (RealF *) Mem_Calloc(size, sizeof(RealF), fstr); + SXW_AVG.evapsurface_litter_avg = (RealF *) Mem_Calloc(size, sizeof(RealF), fstr); + SXW_AVG.evapsurface_water_avg = (RealF *) Mem_Calloc(size, sizeof(RealF), fstr); + + SXW_AVG.interception_total_avg = (RealF *) Mem_Calloc(size, sizeof(RealF), fstr); + SXW_AVG.interception_tree_avg = (RealF *) Mem_Calloc(size, sizeof(RealF), fstr); + SXW_AVG.interception_shrub_avg = (RealF *) Mem_Calloc(size, sizeof(RealF), fstr); + SXW_AVG.interception_forb_avg = (RealF *) Mem_Calloc(size, sizeof(RealF), fstr); + SXW_AVG.interception_grass_avg = (RealF *) Mem_Calloc(size, sizeof(RealF), fstr); + SXW_AVG.interception_litter_avg = (RealF *) Mem_Calloc(size, sizeof(RealF), fstr); + SXW_AVG.soilinfilt_avg = (RealF *) Mem_Calloc(size, sizeof(RealF), fstr); + + SXW_AVG.lyrdrain_avg = (RealF *) Mem_Calloc(layer_size, sizeof(RealF), fstr); + + SXW_AVG.hydred_total_avg = (RealF *) Mem_Calloc(layer_size, sizeof(RealF), fstr); + SXW_AVG.hydred_tree_avg = (RealF *) Mem_Calloc(layer_size, sizeof(RealF), fstr); + SXW_AVG.hydred_shrub_avg = (RealF *) Mem_Calloc(layer_size, sizeof(RealF), fstr); + SXW_AVG.hydred_forb_avg = (RealF *) Mem_Calloc(layer_size, sizeof(RealF), fstr); + SXW_AVG.hydred_grass_avg = (RealF *) Mem_Calloc(layer_size, sizeof(RealF), fstr); + + SXW_AVG.pet_avg = (RealF *) Mem_Calloc(size, sizeof(RealF), fstr); + SXW_AVG.wetday_avg = (RealF *) Mem_Calloc(layer_size, sizeof(RealF), fstr); + + SXW_AVG.snowpack_water_eqv_avg = (RealF *) Mem_Calloc(size, sizeof(RealF), fstr); + SXW_AVG.snowpack_depth_avg = (RealF *) Mem_Calloc(size, sizeof(RealF), fstr); + + SXW_AVG.deepswc_avg = (RealF *) Mem_Calloc(size, sizeof(RealF), fstr); + + SXW_AVG.soiltemp_avg = (RealF *) Mem_Calloc(layer_size, sizeof(RealF), fstr); + + Mem_Set(SXW_AVG.estab_avg, 0, size * sizeof(RealF)); + Mem_Set(SXW_AVG.vwcbulk_avg, 0, layer_size * sizeof(RealF)); + Mem_Set(SXW_AVG.vwcmatric_avg, 0, layer_size * sizeof(RealF)); + Mem_Set(SXW_AVG.swpmatric_avg, 0, layer_size * sizeof(RealF)); + Mem_Set(SXW_AVG.swabulk_avg, 0, layer_size * sizeof(RealF)); + Mem_Set(SXW_AVG.swamatric_avg, 0, layer_size * sizeof(RealF)); + Mem_Set(SXW_AVG.surfacewater_avg, 0, size * sizeof(RealF)); + Mem_Set(SXW_AVG.runoff_total_avg, 0, size * sizeof(RealF)); + Mem_Set(SXW_AVG.runoff_surface_avg, 0, size * sizeof(RealF)); + Mem_Set(SXW_AVG.runoff_snow_avg, 0, size * sizeof(RealF)); + Mem_Set(SXW_AVG.evapsoil_avg, 0, layer_size * sizeof(RealF)); + Mem_Set(SXW_AVG.evapsurface_total_avg, 0, size * sizeof(RealF)); + Mem_Set(SXW_AVG.evapsurface_tree_avg, 0, size * sizeof(RealF)); + Mem_Set(SXW_AVG.evapsurface_shrub_avg, 0, size * sizeof(RealF)); + Mem_Set(SXW_AVG.evapsurface_forb_avg, 0, size * sizeof(RealF)); + Mem_Set(SXW_AVG.evapsurface_grass_avg, 0, size * sizeof(RealF)); + Mem_Set(SXW_AVG.evapsurface_litter_avg, 0, size * sizeof(RealF)); + Mem_Set(SXW_AVG.evapsurface_water_avg, 0, size * sizeof(RealF)); + + Mem_Set(SXW_AVG.interception_total_avg, 0, size * sizeof(RealF)); + Mem_Set(SXW_AVG.interception_tree_avg, 0, size * sizeof(RealF)); + Mem_Set(SXW_AVG.interception_shrub_avg, 0, size * sizeof(RealF)); + Mem_Set(SXW_AVG.interception_forb_avg, 0, size * sizeof(RealF)); + Mem_Set(SXW_AVG.interception_grass_avg, 0, size * sizeof(RealF)); + Mem_Set(SXW_AVG.interception_litter_avg, 0, size * sizeof(RealF)); + + Mem_Set(SXW_AVG.soilinfilt_avg, 0, size * sizeof(RealF)); + Mem_Set(SXW_AVG.lyrdrain_avg, 0, layer_size * sizeof(RealF)); + + Mem_Set(SXW_AVG.hydred_total_avg, 0, layer_size * sizeof(RealF)); + Mem_Set(SXW_AVG.hydred_tree_avg, 0, layer_size * sizeof(RealF)); + Mem_Set(SXW_AVG.hydred_shrub_avg, 0, layer_size * sizeof(RealF)); + Mem_Set(SXW_AVG.hydred_forb_avg, 0, layer_size * sizeof(RealF)); + Mem_Set(SXW_AVG.hydred_grass_avg, 0, layer_size * sizeof(RealF)); + + Mem_Set(SXW_AVG.pet_avg, 0, size * sizeof(RealF)); + Mem_Set(SXW_AVG.wetday_avg, 0, layer_size * sizeof(RealF)); + + Mem_Set(SXW_AVG.snowpack_water_eqv_avg, 0, size * sizeof(RealF)); + Mem_Set(SXW_AVG.snowpack_depth_avg, 0, size * sizeof(RealF)); + + Mem_Set(SXW_AVG.deepswc_avg, 0, size * sizeof(RealF)); + + Mem_Set(SXW_AVG.soiltemp_avg, 0, layer_size * sizeof(RealF)); +} + /*static void _recover_names(void) { ====================================================== @@ -1217,6 +1317,44 @@ void free_all_sxw_memory( void ) { Mem_Free(SXW.swc); Mem_Free(SXW.swc_avg); + + Mem_Free(SXW_AVG.estab_avg); + Mem_Free(SXW_AVG.vwcbulk_avg); + Mem_Free(SXW_AVG.vwcmatric_avg); + Mem_Free(SXW_AVG.swpmatric_avg); + Mem_Free(SXW_AVG.swabulk_avg); + Mem_Free(SXW_AVG.swamatric_avg); + Mem_Free(SXW_AVG.surfacewater_avg); + Mem_Free(SXW_AVG.runoff_total_avg); + Mem_Free(SXW_AVG.runoff_surface_avg); + Mem_Free(SXW_AVG.runoff_snow_avg); + Mem_Free(SXW_AVG.evapsoil_avg); + Mem_Free(SXW_AVG.evapsurface_total_avg); + Mem_Free(SXW_AVG.evapsurface_tree_avg); + Mem_Free(SXW_AVG.evapsurface_shrub_avg); + Mem_Free(SXW_AVG.evapsurface_forb_avg); + Mem_Free(SXW_AVG.evapsurface_grass_avg); + Mem_Free(SXW_AVG.evapsurface_litter_avg); + Mem_Free(SXW_AVG.evapsurface_water_avg); + Mem_Free(SXW_AVG.interception_total_avg); + Mem_Free(SXW_AVG.interception_tree_avg); + Mem_Free(SXW_AVG.interception_shrub_avg); + Mem_Free(SXW_AVG.interception_forb_avg); + Mem_Free(SXW_AVG.interception_grass_avg); + Mem_Free(SXW_AVG.interception_litter_avg); + Mem_Free(SXW_AVG.soilinfilt_avg); + Mem_Free(SXW_AVG.lyrdrain_avg); + Mem_Free(SXW_AVG.hydred_total_avg); + Mem_Free(SXW_AVG.hydred_tree_avg); + Mem_Free(SXW_AVG.hydred_shrub_avg); + Mem_Free(SXW_AVG.hydred_forb_avg); + Mem_Free(SXW_AVG.hydred_grass_avg); + Mem_Free(SXW_AVG.pet_avg); + Mem_Free(SXW_AVG.wetday_avg); + Mem_Free(SXW_AVG.snowpack_water_eqv_avg); + Mem_Free(SXW_AVG.snowpack_depth_avg); + Mem_Free(SXW_AVG.deepswc_avg); + Mem_Free(SXW_AVG.soiltemp_avg); } /***********************************************************/ diff --git a/sxw.h b/sxw.h index a758cfe4..7d1156cf 100644 --- a/sxw.h +++ b/sxw.h @@ -104,24 +104,47 @@ struct stepwat_st { }; struct soilwat_average{ - RealF *soilinfilt_avg, - *runoff_avg, - *vwcbulk_avg, - *vwcmatric, - *swamatric_avg, - *swpmatric_avg, - *surfacewater_avg, - *evapsoil_avg, - *evapsurface_avg, - *interception_avg, - *lyrdrain_avg, - *hydred_avg, - *pet_avg, - *wetday_avg, - *snowpack_avg, - *deepswc_avg, - *soiltemp_avg, - *establ_avg; + RealF *soilinfilt_avg, // done + *runoff_total_avg,// done + *runoff_surface_avg,// done + *runoff_snow_avg,// done + *vwcbulk_avg, // done + *vwcmatric_avg, // done + *swamatric_avg, // done + *swabulk_avg, // done + *swpmatric_avg, // done + *surfacewater_avg, // done + *evapsoil_avg, // done + *evapsurface_total_avg,// done + *evapsurface_tree_avg,// done + *evapsurface_shrub_avg,// done + *evapsurface_forb_avg,// done + *evapsurface_grass_avg,// done + *evapsurface_litter_avg,// done + *evapsurface_water_avg,// done + + *interception_total_avg,// done + *interception_tree_avg,// done + *interception_shrub_avg,// done + *interception_forb_avg,// done + *interception_grass_avg,// done + *interception_litter_avg,// done + + *lyrdrain_avg, // done + + *hydred_total_avg,// done + *hydred_tree_avg,// done + *hydred_shrub_avg,// done + *hydred_forb_avg,// done + *hydred_grass_avg,// done + + *pet_avg, // done + *wetday_avg, // done + *snowpack_water_eqv_avg, // done + *snowpack_depth_avg, // done + *deepswc_avg, // done + *soiltemp_avg, // done + *estab_avg; // done }; #define SXW_NFILES 5 @@ -151,6 +174,10 @@ typedef struct soilwat_average SXW_avg; // year, layer, timeperiod, avg/std #define Iylp(y,l,p,x) (((y)*Globals.runModelYears * SXW.NTrLyrs * SXW.NPds * 2) + ((l)*SXW.NTrLyrs * SXW.NPds * 2) + ((p)*SXW.NPds * 2) + ((x)*2)) +// for soilwat average and standard deviation +// year, timeperiod, choice (avg or std) +#define Iypc(y,p,c) (((y)*Globals.runModelYears * SXW.NPds * 2) + ((p)*SXW.NPds * 2) + ((c) * 2)) + // veg type, layer, timeperiod #define Ivlp(v,l,p) (((v)*4 * SXW.NTrLyrs * SXW.NPds) + ((l)*SXW.NTrLyrs * SXW.NPds) + ((p)*SXW.NPds)) diff --git a/testing.sagebrush.master/Stepwat_Inputs/Input/sxw/Input/outsetup_v30.in b/testing.sagebrush.master/Stepwat_Inputs/Input/sxw/Input/outsetup_v30.in index 3824a71f..ebaeecaa 100644 --- a/testing.sagebrush.master/Stepwat_Inputs/Input/sxw/Input/outsetup_v30.in +++ b/testing.sagebrush.master/Stepwat_Inputs/Input/sxw/Input/outsetup_v30.in @@ -1,7 +1,26 @@ -TIMESTEP mo yr -TRANSP SUM MO 1 end transp -PRECIP SUM YR 1 end precip -TEMP AVG YR 1 end temp -AET SUM YR 1 end aet -SWCBULK FIN MO 1 end swc_bulk -SWA AVG MO 1 end swa +TIMESTEP dy wk mo yr +TRANSP SUM MO 1 end transp +PRECIP SUM YR 1 end precip +TEMP AVG YR 1 end temp +AET SUM YR 1 end aet +SWCBULK FIN MO 1 end swc_bulk +SWA AVG MO 1 end swa +ESTABL off YR 1 end estabs +VWCBULK avg MO 1 end vwc_bulk +VWCMATRIC avg YR 1 end vwc_matric +SWPMATRIC avg WK 1 end swp_matric +SWABULK AVG MO 1 end swa_bulk +SWAMATRIC avg YR 1 end swa_matric +SURFACEWATER avg DY 1 end surface_water +RUNOFF sum WK 1 end runoff +EVAPSOIL sum DY 1 end evap_soil +EVAPSURFACE sum WK 1 end evap_surface +INTERCEPTION sum MO 1 end interception +SOILINFILT sum YR 1 end infiltration +LYRDRAIN sum DY 1 end percolation +HYDRED sum WK 1 end hydred +PET sum DY 1 end pet +WETDAY sum DY 1 end wetdays +SNOWPACK avg WK 1 end snowpack +DEEPSWC sum MO 1 end deep_drain +SOILTEMP avg MO 1 end temp_soil From 01ba852b7b09a952705f6ae9925cd89f850d6075 Mon Sep 17 00:00:00 2001 From: BrendenBe1 Date: Wed, 20 Dec 2017 13:27:41 -0700 Subject: [PATCH 070/111] Resolved Issue #111. subfolder has been changed from 'csv' to 'sw_output' --- .../Stepwat_Inputs/Input/sxw/files_v30.in | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/testing.sagebrush.master/Stepwat_Inputs/Input/sxw/files_v30.in b/testing.sagebrush.master/Stepwat_Inputs/Input/sxw/files_v30.in index 1f2c943f..7c81d5e6 100644 --- a/testing.sagebrush.master/Stepwat_Inputs/Input/sxw/files_v30.in +++ b/testing.sagebrush.master/Stepwat_Inputs/Input/sxw/files_v30.in @@ -26,12 +26,12 @@ Input/swcsetup.in # params for handling measured swc #Output Output/ # 'relative' path for output files: / for same directory, or e.g., Output/ Input/outsetup_v30.in # define output quantities -Output/csv/sw2_daily.csv #output -Output/csv/sw2_weekly.csv #output -Output/csv/sw2_monthly.csv #output -Output/csv/sw2_yearly.csv #output +Output/sw_output/sw2_daily.csv #output +Output/sw_output/sw2_weekly.csv #output +Output/sw_output/sw2_monthly.csv #output +Output/sw_output/sw2_yearly.csv #output -Output/csv/sw2_daily_slyrs.csv #output -Output/csv/sw2_weekly_slyrs.csv #output -Output/csv/sw2_monthly_slyrs.csv #output -Output/csv/sw2_yearly_slyrs.csv #output +Output/sw_output/sw2_daily_slyrs.csv #output +Output/sw_output/sw2_weekly_slyrs.csv #output +Output/sw_output/sw2_monthly_slyrs.csv #output +Output/sw_output/sw2_yearly_slyrs.csv #output From e4a0eefc2092aa79bcbdc5577044cf10c95e2705 Mon Sep 17 00:00:00 2001 From: BrendenBe1 Date: Mon, 8 Jan 2018 10:27:36 -0700 Subject: [PATCH 071/111] Resolving SOILWAT issue #110. Using updated fractional values instead of fixed inputs. --- sw_src | 2 +- sxw_soilwat.c | 5 +++++ 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/sw_src b/sw_src index 4c17c22f..fd7c3e82 160000 --- a/sw_src +++ b/sw_src @@ -1 +1 @@ -Subproject commit 4c17c22f27737958e07bca0e4a9af576848d8e03 +Subproject commit fd7c3e82b45a032100321026241be861576aad00 diff --git a/sxw_soilwat.c b/sxw_soilwat.c index b0700e69..55c1573c 100644 --- a/sxw_soilwat.c +++ b/sxw_soilwat.c @@ -313,5 +313,10 @@ static void _update_productivity(void) { v->fractionForb = (0.0); v->fractionBareGround = 1; } + SW_VegProd.useVegType[0][1] = v->fractionTree; + SW_VegProd.useVegType[1][1] = v->fractionShrub; + SW_VegProd.useVegType[2][1] = v->fractionGrass; + SW_VegProd.useVegType[3][1] = v->fractionForb; + //printf("useVegType, fractiongrass: %f, %f\n", SW_VegProd.useVegType[2],v->fractionGrass); #undef Biomass } From 9e7e0b7d620294e903de1b27f8fa90b8a4b6bdca Mon Sep 17 00:00:00 2001 From: BrendenBe1 Date: Mon, 8 Jan 2018 14:13:05 -0700 Subject: [PATCH 072/111] Potentially resolving issue #57 dealing with memory leak. Also added output column for temperature standard deviation. --- sw_src | 2 +- sxw.c | 14 ++++++++++++++ sxw.h | 9 +++++++-- sxw_resource.c | 16 ++++++++-------- .../Input/sxw/Input/outsetup_v30.in | 1 + 5 files changed, 31 insertions(+), 11 deletions(-) diff --git a/sw_src b/sw_src index fd7c3e82..66c8332d 160000 --- a/sw_src +++ b/sw_src @@ -1 +1 @@ -Subproject commit fd7c3e82b45a032100321026241be861576aad00 +Subproject commit 66c8332db4476ddb724de8bf46e26cd1bff81c1d diff --git a/sxw.c b/sxw.c index c0a5b24e..7a88ac09 100644 --- a/sxw.c +++ b/sxw.c @@ -866,6 +866,10 @@ static void _make_soil_arrays(void){ size = (SXW.NPds * Globals.runModelYears * 2) * Globals.runModelYears; layer_size = (SXW.NPds * SXW.NSoLyrs * Globals.runModelYears * 2) * Globals.runModelYears; + SXW_AVG.max_temp_avg = (RealF *) Mem_Calloc(size, sizeof(RealF), fstr); + SXW_AVG.min_temp_avg = (RealF *) Mem_Calloc(size, sizeof(RealF), fstr); + SXW_AVG.avg_temp_avg = (RealF *) Mem_Calloc(size, sizeof(RealF), fstr); + SXW_AVG.surfaceTemp_avg = (RealD *) Mem_Calloc(size, sizeof(RealD), fstr); SXW_AVG.estab_avg = (RealF *) Mem_Calloc(size, sizeof(RealF), fstr); SXW_AVG.vwcbulk_avg = (RealF *) Mem_Calloc(layer_size, sizeof(RealF), fstr); @@ -912,6 +916,11 @@ static void _make_soil_arrays(void){ SXW_AVG.soiltemp_avg = (RealF *) Mem_Calloc(layer_size, sizeof(RealF), fstr); + Mem_Set(SXW_AVG.max_temp_avg, 0, size * sizeof(RealF)); + Mem_Set(SXW_AVG.min_temp_avg, 0, size * sizeof(RealF)); + Mem_Set(SXW_AVG.avg_temp_avg, 0, size * sizeof(RealF)); + Mem_Set(SXW_AVG.surfaceTemp_avg, 0, size * sizeof(RealD)); + Mem_Set(SXW_AVG.estab_avg, 0, size * sizeof(RealF)); Mem_Set(SXW_AVG.vwcbulk_avg, 0, layer_size * sizeof(RealF)); Mem_Set(SXW_AVG.vwcmatric_avg, 0, layer_size * sizeof(RealF)); @@ -1318,6 +1327,11 @@ void free_all_sxw_memory( void ) { Mem_Free(SXW.swc); Mem_Free(SXW.swc_avg); + Mem_Free(SXW_AVG.max_temp_avg); + Mem_Free(SXW_AVG.min_temp_avg); + Mem_Free(SXW_AVG.avg_temp_avg); + Mem_Free(SXW_AVG.surfaceTemp_avg); + Mem_Free(SXW_AVG.estab_avg); Mem_Free(SXW_AVG.vwcbulk_avg); Mem_Free(SXW_AVG.vwcmatric_avg); diff --git a/sxw.h b/sxw.h index 7d1156cf..37b5f671 100644 --- a/sxw.h +++ b/sxw.h @@ -144,7 +144,12 @@ struct soilwat_average{ *snowpack_depth_avg, // done *deepswc_avg, // done *soiltemp_avg, // done - *estab_avg; // done + *estab_avg, + *max_temp_avg, + *min_temp_avg, + *avg_temp_avg; // done + + RealD *surfaceTemp_avg; }; #define SXW_NFILES 5 @@ -176,7 +181,7 @@ typedef struct soilwat_average SXW_avg; // for soilwat average and standard deviation // year, timeperiod, choice (avg or std) -#define Iypc(y,p,c) (((y)*Globals.runModelYears * SXW.NPds * 2) + ((p)*SXW.NPds * 2) + ((c) * 2)) +#define Iypc(y,p,c) (((y)*Globals.runModelYears * SXW.NPds) + ((p)*SXW.NPds) + (c)) // veg type, layer, timeperiod #define Ivlp(v,l,p) (((v)*4 * SXW.NTrLyrs * SXW.NPds) + ((l)*SXW.NTrLyrs * SXW.NPds) + ((p)*SXW.NPds)) diff --git a/sxw_resource.c b/sxw_resource.c index ac02514c..840a831b 100644 --- a/sxw_resource.c +++ b/sxw_resource.c @@ -259,7 +259,7 @@ static void _transp_contribution_by_group(RealF use_by_group[]) { transp = SXW.transpTotal; break; } - + //Loops through each month and calculates amount of transpiration for each steppe functional group //according to whether that group has active living roots in each soil layer for each month ForEachTrPeriod(p) @@ -270,7 +270,7 @@ static void _transp_contribution_by_group(RealF use_by_group[]) { } } //printf("for groupName= %s, use_by_group[g] in transp= %f \n",RGroup[g]->name,use_by_group[g] ); - + sumUsedByGroup += use_by_group[g]; //printf(" sumUsedByGroup in transp=%f \n",sumUsedByGroup); } @@ -284,13 +284,13 @@ static void _transp_contribution_by_group(RealF use_by_group[]) { } TranspRemaining = sumTranspTotal - sumUsedByGroup; //printf(" sumTranspTotal=%f, sumUsedByGroup=%f TranspRemaining=%f \n",sumTranspTotal,sumUsedByGroup,TranspRemaining); - + ForEachGroup(g) { if(!ZRO(use_by_group[g])) { use_by_group[g] += (use_by_group[g]/sumUsedByGroup) * TranspRemaining; //printf("for groupName= %s, after sum use_by_group[g]= %f \n",RGroup[g]->name,use_by_group[g] ); - + SXW.transp_SWA[currentYear][g] = use_by_group[g]; //printf("for groupName= %s, SXW.transp_SWA[g] in transp= %f \n",RGroup[g]->name,SXW.transp_SWA[currentYear][g]); } @@ -305,7 +305,7 @@ static void _SWA_contribution_by_group(RealF use_by_group[]) { * Compute each group's amount of SWA from SOILWAT2 * based on its biomass, root distribution, and phenological * activity. */ - + GrpIndex g; TimeInt p; LyrIndex l; @@ -324,16 +324,16 @@ static void _SWA_contribution_by_group(RealF use_by_group[]) { ForEachTrPeriod(p) { for (l = 0; l < SXW.NSoLyrs; l++) { - //printf("%d,%d,%d\n", g,l,p); + //printf("%d,%d,%d\n", t,l,p); use_by_group[g] += (RealF) (_roots_active_rel[Iglp(g, l, p)] * SXW.sum_dSWA_repartitioned[t][l][p]); //printf("for groupName= %s, layerIndex: %d, month: %d, in swa loop use_by_group[g]= %f \n",RGroup[g]->name,l,p,use_by_group[g]); } } //printf("for groupName= %s, use_by_group[g] in swa= %f \n",RGroup[g]->name,use_by_group[g]); - + sumUsedByGroup += use_by_group[g]; //printf(" sumUsedByGroup in swa=%f \n",sumUsedByGroup); - + SXW.transp_SWA[currentYear][g] += use_by_group[g]; //printf("SXW.transp_SWA[%d][%d]: %f\n", currentYear, g, SXW.transp_SWA[currentYear][g]); } diff --git a/testing.sagebrush.master/Stepwat_Inputs/Input/sxw/Input/outsetup_v30.in b/testing.sagebrush.master/Stepwat_Inputs/Input/sxw/Input/outsetup_v30.in index ebaeecaa..d7701e9f 100644 --- a/testing.sagebrush.master/Stepwat_Inputs/Input/sxw/Input/outsetup_v30.in +++ b/testing.sagebrush.master/Stepwat_Inputs/Input/sxw/Input/outsetup_v30.in @@ -1,4 +1,5 @@ TIMESTEP dy wk mo yr + TRANSP SUM MO 1 end transp PRECIP SUM YR 1 end precip TEMP AVG YR 1 end temp From 76d49584047cbc97aa70373fbd45d8f87776a43c Mon Sep 17 00:00:00 2001 From: BrendenBe1 Date: Mon, 8 Jan 2018 16:58:33 -0700 Subject: [PATCH 073/111] Closing files to resolve issue #59 --- sw_src | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sw_src b/sw_src index 66c8332d..66d7783c 160000 --- a/sw_src +++ b/sw_src @@ -1 +1 @@ -Subproject commit 66c8332db4476ddb724de8bf46e26cd1bff81c1d +Subproject commit 66d7783c7f35dbd41803ca3085db134ca231f55e From 0e5eafcc4fe5d5914232892ff5ff4657c08ad66d Mon Sep 17 00:00:00 2001 From: BrendenBe1 Date: Tue, 9 Jan 2018 12:02:16 -0700 Subject: [PATCH 074/111] Removed useVegType array and replaced all usage with the proper fraction* value. Resolution to issue SOILWAT #110 --- sw_src | 2 +- sxw_soilwat.c | 5 ----- 2 files changed, 1 insertion(+), 6 deletions(-) diff --git a/sw_src b/sw_src index 66d7783c..329aa69a 160000 --- a/sw_src +++ b/sw_src @@ -1 +1 @@ -Subproject commit 66d7783c7f35dbd41803ca3085db134ca231f55e +Subproject commit 329aa69a0a826d9cc0b4295ad70fc960126ade6b diff --git a/sxw_soilwat.c b/sxw_soilwat.c index 55c1573c..b0700e69 100644 --- a/sxw_soilwat.c +++ b/sxw_soilwat.c @@ -313,10 +313,5 @@ static void _update_productivity(void) { v->fractionForb = (0.0); v->fractionBareGround = 1; } - SW_VegProd.useVegType[0][1] = v->fractionTree; - SW_VegProd.useVegType[1][1] = v->fractionShrub; - SW_VegProd.useVegType[2][1] = v->fractionGrass; - SW_VegProd.useVegType[3][1] = v->fractionForb; - //printf("useVegType, fractiongrass: %f, %f\n", SW_VegProd.useVegType[2],v->fractionGrass); #undef Biomass } From d1b2140a8b565f05ee0d88e33735056b9dbd9975 Mon Sep 17 00:00:00 2001 From: BrendenBe1 Date: Tue, 9 Jan 2018 14:23:44 -0700 Subject: [PATCH 075/111] Added flag to outsetup_v30.in file to use timestep or not. Resolution to SOILWAT issue #120 and SOILWAT issue #109 along with progress on issue #58 --- sw_src | 2 +- sxw.c | 82 ++++++++++--------- .../Input/sxw/Input/outsetup_v30.in | 41 ++++++++++ 3 files changed, 84 insertions(+), 41 deletions(-) diff --git a/sw_src b/sw_src index 329aa69a..cd55b71c 160000 --- a/sw_src +++ b/sw_src @@ -1 +1 @@ -Subproject commit 329aa69a0a826d9cc0b4295ad70fc960126ade6b +Subproject commit cd55b71c7afee9fa3196ca7988957bf41e2aa302 diff --git a/sxw.c b/sxw.c index 7a88ac09..be492fe7 100644 --- a/sxw.c +++ b/sxw.c @@ -82,6 +82,10 @@ extern SW_WEATHER SW_Weather; extern SW_MARKOV SW_Markov; //extern SW_SOILWAT SW_Soilwat; +extern Bool isPartialSoilwatOutput; +extern Bool storeAllIterations; + + /*************** Module/Local Variable Declarations ***************/ /***********************************************************/ @@ -735,7 +739,9 @@ static void _make_arrays(void) { _make_transp_arrays(); _make_swa_array(); _make_swc_array(); - _make_soil_arrays(); + // only make output storage if -o or -i flags + if(storeAllIterations || isPartialSoilwatOutput == FALSE) + _make_soil_arrays(); } static void _make_roots_arrays(void) { @@ -782,7 +788,7 @@ static void _make_transp_arrays(void) { */ char *fstr = "_make_transp_array()"; int size; - int avg_size; + //int avg_size; size = (SXW.NPds * SXW.NSoLyrs) * 365; SXW.transpTotal = (RealD *) Mem_Calloc(size, sizeof(RealD), fstr); @@ -790,41 +796,12 @@ static void _make_transp_arrays(void) { SXW.transpShrubs = (RealD *) Mem_Calloc(size, sizeof(RealD), fstr); SXW.transpForbs = (RealD *) Mem_Calloc(size, sizeof(RealD), fstr); SXW.transpGrasses = (RealD *) Mem_Calloc(size, sizeof(RealD), fstr); - - avg_size = (SXW.NPds * SXW.NSoLyrs * Globals.runModelYears * 2) * Globals.runModelYears; - SXW.transpTotal_avg = (RealD *) Mem_Calloc(avg_size, sizeof(RealD), fstr); - SXW.transpTrees_avg = (RealD *) Mem_Calloc(avg_size, sizeof(RealD), fstr); - SXW.transpShrubs_avg = (RealD *) Mem_Calloc(avg_size, sizeof(RealD), fstr); - SXW.transpForbs_avg = (RealD *) Mem_Calloc(avg_size, sizeof(RealD), fstr); - SXW.transpGrasses_avg = (RealD *) Mem_Calloc(avg_size, sizeof(RealD), fstr); - - // initialize values to 0 - Mem_Set(SXW.transpTotal_avg, 0, avg_size * sizeof(RealD)); - Mem_Set(SXW.transpTrees_avg, 0, avg_size * sizeof(RealD)); - Mem_Set(SXW.transpShrubs_avg, 0, avg_size * sizeof(RealD)); - Mem_Set(SXW.transpForbs_avg, 0, avg_size * sizeof(RealD)); - Mem_Set(SXW.transpGrasses_avg, 0, avg_size * sizeof(RealD)); } static void _make_swa_array(void){ char *fstr = "_make_swa_array()"; int size = SXW.NPds * SXW.NSoLyrs; int avg_size; - //int size_3d = 4 * SXW.NPds * SXW.NSoLyrs; - - avg_size = (SXW.NPds * SXW.NSoLyrs * Globals.runModelYears * 2) * Globals.runModelYears * Globals.runModelIterations; - SXW.SWAbulk_grass_avg = (RealF *) Mem_Calloc(avg_size, sizeof(RealF *), fstr); - SXW.SWAbulk_shrub_avg = (RealF *) Mem_Calloc(avg_size, sizeof(RealF *), fstr); - SXW.SWAbulk_tree_avg = (RealF *) Mem_Calloc(avg_size, sizeof(RealF *), fstr); - SXW.SWAbulk_forb_avg = (RealF *) Mem_Calloc(avg_size, sizeof(RealF *), fstr); - - Mem_Set(SXW.SWAbulk_grass_avg, 0, avg_size * sizeof(RealF)); - Mem_Set(SXW.SWAbulk_shrub_avg, 0, avg_size * sizeof(RealF)); - Mem_Set(SXW.SWAbulk_tree_avg, 0, avg_size * sizeof(RealF)); - Mem_Set(SXW.SWAbulk_forb_avg, 0, avg_size * sizeof(RealF)); - - //SXW.sum_dSWA_repartitioned = (RealF *) Mem_Calloc(size_3d, sizeof(RealF), fstr); - //Mem_Set(SXW.sum_dSWA_repartitioned, 0, size_3d); //4 - Grass,Frob,Tree,Shrub size = 4 * 4 * SXW.NPds * SXW.NSoLyrs * Globals.runModelIterations; @@ -832,10 +809,6 @@ static void _make_swa_array(void){ SXW.dSWAbulk = (RealF *) Mem_Calloc(size, sizeof(RealF), fstr); // 4D SXW.dSWA_repartitioned = (RealF *) Mem_Calloc(size, sizeof(RealF), fstr); // 4D - //int newSize = 4*SXW.NPds * SXW.NSoLyrs; - //SXW.sum_dSWA_repartitioned = (RealF *) Mem_Calloc(newSize, sizeof(RealF *), fstr); - //Mem_Set(SXW.sum_dSWA_repartitioned, 0, SXW.NPds * SXW.NSoLyrs * 4 * sizeof(RealF)); - //Mem_Set(SXW.SWA_master, 0, SXW.NPds * 4 * SXW.NSoLyrs * sizeof(RealF)); memset(SXW.SWA_master, 0, sizeof(SXW.SWA_master)); Mem_Set(SXW.dSWAbulk, 0, 4*4*SXW.NPds * SXW.NSoLyrs * sizeof(RealF)); @@ -850,22 +823,52 @@ static void _make_swc_array(void) { * specified with debugfile */ char *fstr = "_make_swc_array()"; - int size = SXW.NPds * SXW.NSoLyrs; + int size = SXW.NPds * SXW.NSoLyrs * 366; int avg_size; //int size_3d = 4 * SXW.NPds * SXW.NSoLyrs; SXW.swc = (RealF *) Mem_Calloc(size, sizeof(RealF *), fstr); - avg_size = (SXW.NPds * SXW.NSoLyrs * Globals.runModelYears) * 365; - SXW.swc_avg = (RealF *) Mem_Calloc(avg_size, sizeof(RealF), fstr); + //avg_size = (SXW.NPds * SXW.NSoLyrs * Globals.runModelYears) * 365; + //SXW.swc_avg = (RealF *) Mem_Calloc(avg_size, sizeof(RealF), fstr); } +// all memory allocation for avg values are here +// to be used with -o or -i flags +// dont need to allocate memory unless storing SOILWAT output static void _make_soil_arrays(void){ char *fstr = "_make_soil_arrays"; - int size, layer_size; + int size, layer_size, avg_size; size = (SXW.NPds * Globals.runModelYears * 2) * Globals.runModelYears; layer_size = (SXW.NPds * SXW.NSoLyrs * Globals.runModelYears * 2) * Globals.runModelYears; + avg_size = (SXW.NPds * SXW.NSoLyrs * Globals.runModelYears * 2) * Globals.runModelYears; + SXW.transpTotal_avg = (RealD *) Mem_Calloc(avg_size, sizeof(RealD), fstr); + SXW.transpTrees_avg = (RealD *) Mem_Calloc(avg_size, sizeof(RealD), fstr); + SXW.transpShrubs_avg = (RealD *) Mem_Calloc(avg_size, sizeof(RealD), fstr); + SXW.transpForbs_avg = (RealD *) Mem_Calloc(avg_size, sizeof(RealD), fstr); + SXW.transpGrasses_avg = (RealD *) Mem_Calloc(avg_size, sizeof(RealD), fstr); + + // initialize values to 0 + Mem_Set(SXW.transpTotal_avg, 0, avg_size * sizeof(RealD)); + Mem_Set(SXW.transpTrees_avg, 0, avg_size * sizeof(RealD)); + Mem_Set(SXW.transpShrubs_avg, 0, avg_size * sizeof(RealD)); + Mem_Set(SXW.transpForbs_avg, 0, avg_size * sizeof(RealD)); + Mem_Set(SXW.transpGrasses_avg, 0, avg_size * sizeof(RealD)); + + //avg_size = (SXW.NPds * SXW.NSoLyrs * Globals.runModelYears * 2) * Globals.runModelYears * Globals.runModelIterations; + SXW.SWAbulk_grass_avg = (RealF *) Mem_Calloc(avg_size, sizeof(RealF *), fstr); + SXW.SWAbulk_shrub_avg = (RealF *) Mem_Calloc(avg_size, sizeof(RealF *), fstr); + SXW.SWAbulk_tree_avg = (RealF *) Mem_Calloc(avg_size, sizeof(RealF *), fstr); + SXW.SWAbulk_forb_avg = (RealF *) Mem_Calloc(avg_size, sizeof(RealF *), fstr); + + Mem_Set(SXW.SWAbulk_grass_avg, 0, avg_size * sizeof(RealF)); + Mem_Set(SXW.SWAbulk_shrub_avg, 0, avg_size * sizeof(RealF)); + Mem_Set(SXW.SWAbulk_tree_avg, 0, avg_size * sizeof(RealF)); + Mem_Set(SXW.SWAbulk_forb_avg, 0, avg_size * sizeof(RealF)); + + SXW.swc_avg = (RealF *) Mem_Calloc(avg_size, sizeof(RealF), fstr); + SXW_AVG.max_temp_avg = (RealF *) Mem_Calloc(size, sizeof(RealF), fstr); SXW_AVG.min_temp_avg = (RealF *) Mem_Calloc(size, sizeof(RealF), fstr); SXW_AVG.avg_temp_avg = (RealF *) Mem_Calloc(size, sizeof(RealF), fstr); @@ -1293,7 +1296,6 @@ int getNTranspLayers(int veg_prod_type) { /***********************************************************/ void free_all_sxw_memory( void ) { - printf("freeing memory\n"); free_sxw_memory(); Mem_Free(SXW.f_files); Mem_Free(SXW.f_roots); diff --git a/testing.sagebrush.master/Stepwat_Inputs/Input/sxw/Input/outsetup_v30.in b/testing.sagebrush.master/Stepwat_Inputs/Input/sxw/Input/outsetup_v30.in index d7701e9f..09f2f032 100644 --- a/testing.sagebrush.master/Stepwat_Inputs/Input/sxw/Input/outsetup_v30.in +++ b/testing.sagebrush.master/Stepwat_Inputs/Input/sxw/Input/outsetup_v30.in @@ -1,5 +1,46 @@ +# Output setup file for STEPWAT +# +# Notes: +# Time periods available: DY,WK,MO,YR +# eg, if DY is chosen then 100,200 would mean to use the second hundred days +# But if YR is chosen, start and end numbers are in days so only those days +# are reported for the yearly average. +# Some keys from older versions (fortran and the c versions mimicking the fortran +# version) are not currently implemented: +# ALLH20, WTHR. +# +# ESTABL only produces yearly output, namely, DOY for each species requested. +# Thus, to minimize typo errors, all flags are ignored except the filename. +# Output is simply the day of the year establishment occurred for each species +# in each year of the model run. Refer to the estabs.in file for more info. +# +# DEEPSWC produces output only if the deepdrain flag is set in siteparam.in. +# +# Filename prefixes should not have a file extension. +# Case is unimportant. +# +# SUMTYPEs are one of the following: +# OFF - no output for this variable +# SUM - sum the variable for each day in the output period +# AVG - average the variable over the output period +# FIN - output value of final day in the period; soil water variables only. +# Note that SUM and AVG are the same if timeperiod = dy. +# +# (01/17/2013) TIMESTEP key indicates which periods you want to output. +# You can output all the periods at a time, just one, or however many +# you want. To change which periods to output type 'dy' for day, +# 'wk' for week, 'mo' for month, and 'yr' for year after TIMESTEP +# in any order. For example: "TIMESTEP mo wk" will output for month and week + +# (1/9/2018) USE_TIMESTEP: this determines if using the timestep periods or using the PERIOD defined for each individual variable (1 = use, 0 = dont use) +# If set to 0 TIMESTEP line determines which output files are to be created so need to have all the timeperiods defined in the values PERIOD +# EX: if only using TRANSP and PRECIP and the periods are MO for TRANSP and DY for PRECIP TIMESTEP needs to be "TIMESTEP dy mo" so program knows to create day and month output files +# if "USE_TIMESTEP 1" then can have any combo of periods after TIMESTEP + +USE_TIMESTEP 0 TIMESTEP dy wk mo yr +# key SUMTYPE PERIOD start end filename_prefix TRANSP SUM MO 1 end transp PRECIP SUM YR 1 end precip TEMP AVG YR 1 end temp From 320756829bc52f771b4dedc10f65c85e1059e77c Mon Sep 17 00:00:00 2001 From: BrendenBe1 Date: Tue, 9 Jan 2018 16:45:00 -0700 Subject: [PATCH 076/111] Continued work on issue #58 --- ST_main.c | 2 +- sw_src | 2 +- sxw.c | 12 ++++++++++++ sxw.h | 8 ++++---- 4 files changed, 18 insertions(+), 6 deletions(-) diff --git a/ST_main.c b/ST_main.c index 40bc4551..16f78103 100644 --- a/ST_main.c +++ b/ST_main.c @@ -242,7 +242,7 @@ int main(int argc, char **argv) { Globals.currIter = iter; memset(SXW.transp_SWA, 0, sizeof(SXW.transp_SWA)); // set transp_SWA to 0; needs to be reset each iteration - memset(SXW.sum_dSWA_repartitioned, 0, sizeof(SXW.sum_dSWA_repartitioned)); + //memset(SXW.sum_dSWA_repartitioned, 0, sizeof(SXW.sum_dSWA_repartitioned)); /* ------ Begin running the model ------ */ for (year = 1; year <= Globals.runModelYears; year++){ diff --git a/sw_src b/sw_src index cd55b71c..b7cee12b 160000 --- a/sw_src +++ b/sw_src @@ -1 +1 @@ -Subproject commit cd55b71c7afee9fa3196ca7988957bf41e2aa302 +Subproject commit b7cee12b57bc68cc9196491f4899d0c79940c242 diff --git a/sxw.c b/sxw.c index be492fe7..9c271a51 100644 --- a/sxw.c +++ b/sxw.c @@ -874,6 +874,14 @@ static void _make_soil_arrays(void){ SXW_AVG.avg_temp_avg = (RealF *) Mem_Calloc(size, sizeof(RealF), fstr); SXW_AVG.surfaceTemp_avg = (RealD *) Mem_Calloc(size, sizeof(RealD), fstr); + SXW_AVG.aet_avg = (RealD *) Mem_Calloc(size, sizeof(RealD), fstr); + SXW_AVG.val_snowloss_avg = (RealD *) Mem_Calloc(size, sizeof(RealD), fstr); + SXW_AVG.val_snowmelt_avg = (RealD *) Mem_Calloc(size, sizeof(RealD), fstr); + + Mem_Set(SXW_AVG.aet_avg, 0, size * sizeof(RealF)); + Mem_Set(SXW_AVG.val_snowloss_avg, 0, size * sizeof(RealF)); + Mem_Set(SXW_AVG.val_snowmelt_avg, 0, size * sizeof(RealF)); + SXW_AVG.estab_avg = (RealF *) Mem_Calloc(size, sizeof(RealF), fstr); SXW_AVG.vwcbulk_avg = (RealF *) Mem_Calloc(layer_size, sizeof(RealF), fstr); SXW_AVG.vwcmatric_avg = (RealF *) Mem_Calloc(layer_size, sizeof(RealF), fstr); @@ -1334,6 +1342,10 @@ void free_all_sxw_memory( void ) { Mem_Free(SXW_AVG.avg_temp_avg); Mem_Free(SXW_AVG.surfaceTemp_avg); + Mem_Free(SXW_AVG.aet_avg); + Mem_Free(SXW_AVG.val_snowmelt_avg); + Mem_Free(SXW_AVG.val_snowloss_avg); + Mem_Free(SXW_AVG.estab_avg); Mem_Free(SXW_AVG.vwcbulk_avg); Mem_Free(SXW_AVG.vwcmatric_avg); diff --git a/sxw.h b/sxw.h index 37b5f671..ecc0a27b 100644 --- a/sxw.h +++ b/sxw.h @@ -98,9 +98,6 @@ struct stepwat_st { int col_status_yr; RealF *swc_avg; - RealF val_snowmelt_avg[1000][2], // set to 1000 for max years - val_snowloss_avg[1000][2], - aet_avg[1000][2]; }; struct soilwat_average{ @@ -147,7 +144,10 @@ struct soilwat_average{ *estab_avg, *max_temp_avg, *min_temp_avg, - *avg_temp_avg; // done + *avg_temp_avg, // done + *aet_avg, + *val_snowmelt_avg, + *val_snowloss_avg; RealD *surfaceTemp_avg; }; From eb45d5a1e1c98960ac887042c105726cd1141de1 Mon Sep 17 00:00:00 2001 From: BrendenBe1 Date: Wed, 10 Jan 2018 10:39:29 -0700 Subject: [PATCH 077/111] Potential resolution to memory issue --- sw_src | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sw_src b/sw_src index b7cee12b..aec8f8c8 160000 --- a/sw_src +++ b/sw_src @@ -1 +1 @@ -Subproject commit b7cee12b57bc68cc9196491f4899d0c79940c242 +Subproject commit aec8f8c8d525a516c49f8bccb55d502408023e37 From c97615c06ecb15dbc961ec4bbe5a8057f8d9f2b6 Mon Sep 17 00:00:00 2001 From: BrendenBe1 Date: Wed, 10 Jan 2018 11:45:14 -0700 Subject: [PATCH 078/111] Working on SOILWAT issue #127 where SWA values are 0 in output files. --- README.md | 11 +++- ST_stats.c | 170 ----------------------------------------------------- sw_src | 2 +- 3 files changed, 10 insertions(+), 173 deletions(-) diff --git a/README.md b/README.md index 6d4c588e..db6821eb 100644 --- a/README.md +++ b/README.md @@ -40,8 +40,8 @@ Other tasks: > -q : quiet mode, don't print message to check logfile. > -s : use SOILWAT model for resource partitioning. > -e : echo initialization results to logfile -> -o : print all the soilwat output (averaged over all iterations) in addition to the stepwat output -> -i : print soilwat output for each iteration +> -o : write SOILWAT output to output files. Contains average over all iterations and standard deviation +> -i : write soilwat output to output files for each iteration > -g : use gridded mode ``` @@ -69,6 +69,13 @@ cd testing.sagebrush.master/Stepwat_Inputs/ ./stepwat -f files.in ``` +* Run STEPPE (get SOILWAT output for all iterations and average) + +``` +cd testing.sagebrush.master/Stepwat_Inputs/ +./stepwat -f files.in -o -i -s +``` +
diff --git a/ST_stats.c b/ST_stats.c index 45b23d8c..fec003fe 100644 --- a/ST_stats.c +++ b/ST_stats.c @@ -1418,8 +1418,6 @@ static void _make_header( char *buf) { } } - - /* Put header line in global variable */ for (i=0; i< fc-1; i++) { sprintf(tbuf,"%s%c", fields[i], BmassFlags.sep); @@ -1431,174 +1429,6 @@ static void _make_header( char *buf) { } -// helper function called by stat_Output_AllSoilwatVariables to create the CSV column names -// pass in header1 and header2 for column labels -static void _make_header_for_soilwat(char *buf, char *header1, char *header2, int colLength) -{ - char fields[MAX_OUTFIELDS * 2][MAX_FIELDLEN + 1]; - char tbuf[80]; - - Int i, fc = 0; - - /* Set up headers */ - if (BmassFlags.yr) - strcpy(fields[fc++], header1); - //strcpy(fields[fc++], "Year"); - - // create a column for each layer in the csv - int num_columns; - for(num_columns = 1; num_columns <= colLength; num_columns++){ // create amount of columns equal to input - char colName[20]; // create array to hold string - snprintf(colName, sizeof colName, "%s %d", header2, num_columns); // concatenate column number to header 2 - strcpy(fields[fc++], colName); // store column layer - } - - /* Put header line in global variable */ - for (i = 0; i < fc - 1; i++) - { - sprintf(tbuf, "%s%c", fields[i], BmassFlags.sep); - strcat(buf, tbuf); - } - sprintf(tbuf, "%s%c\n", fields[i], BmassFlags.sep); - strcat(buf, tbuf); - -} - -// store soilwat values in a csv -// TODO: need to clean up this function... too many commented out blobs and ugly/hard to read -void stat_Output_AllSoilwatVariables(void) -{ - char buf[2048], tbuf[80], PPTbuf[2048], sep = BmassFlags.sep; - IntS yr; - int curYearInt; - GrpIndex rg; - SppIndex sp; - FILE *f; - FILE *PPTFILE; - - char filename[FILENAME_MAX]; - char PPTfilename[FILENAME_MAX]; - - sprintf(filename, "%s%0*d.csv", "output/SoilWater_output", - Globals.mort.suffixwidth, Globals.currIter); - - sprintf(PPTfilename, "%s%0*d.csv", "output/PPT_output", - Globals.mort.suffixwidth, Globals.currIter); - - if (DirExists(DirName(filename))) - { - strcpy(inbuf, filename); - if (!RemoveFiles(inbuf)) - printf("Can't remove old biomass output files %s\n", inbuf); - - } - else if (!MkDir(DirName(filename))) - { - printf("Can't make output path for yearly biomass files: %s\n", - DirName(filename)); - } - - f = OpenFile(filename, "w"); - - buf[0] = '\0'; - - // soil water - if (BmassFlags.header) - { - _make_header_for_soilwat(buf, "Year", "Layer", MAX_LAYERS); // make column names - fprintf(f, "%s", buf); - } - - if (DirExists(DirName(PPTfilename))) - { - strcpy(inbuf, PPTfilename); - if (!RemoveFiles(inbuf)) - printf("Can't remove old biomass output files %s\n", inbuf); - - } - else if (!MkDir(DirName(PPTfilename))) - { - printf("Can't make output path for yearly biomass files: %s\n", - DirName(PPTfilename)); - } - // end soil water - - // PPT - PPTFILE = OpenFile(PPTfilename, "w"); - - PPTbuf[0] = '\0'; - - if (BmassFlags.header) - { - _make_header_for_soilwat(PPTbuf, "Year", "Month", MAX_MONTHS); // make column names - fprintf(PPTFILE, "%s", PPTbuf); - } - // end PPT - - // Adding values to soil water csv // - int layerLoop; - int checkVals; - int currentMonth; - int temp; - - // loop for entering data to csv. for each year it gets the value at all layers then inputs data row by row - // Handles SWC CSV - for (yr = 1; yr <= Globals.runModelYears; yr++){ // set yr to 1 to start for proper access to Ilp array - float layerVals[104] = {0}; - float PPTlayerVals[446] = {0}; - - // loop to convert month swc to year and write it to csv - for(currentMonth = 0; currentMonth < MAX_MONTHS; currentMonth++){ - for(layerLoop = 0; layerLoop < SW_Site.n_layers; layerLoop++){ - layerVals[layerLoop] += SXW.swc[Ilp(layerLoop, currentMonth)]; // each layer value for current month is stored in array to be averaged later - //printf("SWCbulk[SXW.grass_cover,layer]: %f\n", SXW.swc[SXW.grass_cover, layerLoop]); // this is what i need to do to get necessary swcbulk values - //if(layerLoop == 0) printf("layerVals[0] for month %d: %f\n", currentMonth, layerVals[0]); - //printf("SXW.swc[Ilp(%d, %d)]: %f\n", layerLoop, currentMonth, SXW.swc[Ilp(layerLoop, currentMonth)]); - } - } - - //printf("layerVals[0]: %f\n", layerVals[0]); - - // loop for soil water - /*for(layerLoop = 0; layerLoop < SW_Site.n_layers; layerLoop++){ - layerVals[layerLoop] = SXW.swc[Ilp(layerLoop, yr)]; - //printf("layerVals[%d]: %f\n", layerLoop, layerVals[layerLoop]); - }*/ - - // loop for PPT - // TODO: currently using year values since SOILWAT does not pass any values aside from year - //for(currentMonth = 0; currentMonth < MAX_MONTHS; currentMonth++){ - //PPTlayerVals[currentMonth] = SXW.PPTVal[currentMonth]; - //} - - //printf("layerVals[0]: %f\n", layerVals[0]); - // write to file. this is reason set layers to MAX_LAYERS instead of layers actually used since it would be too hard to format the fprintf - fprintf(f, "%d,%f,%f,%f,%f,%f,%f,%f,%f,%f,%f,%f,%f,%f,%f,%f,%f,%f,%f,%f,%f,%f,%f,%f,%f,%f\n", - yr, layerVals[0]/12, layerVals[1]/12, layerVals[2]/12, layerVals[3]/12, layerVals[4]/12, layerVals[5]/12, layerVals[6]/12, - layerVals[7]/12, layerVals[8]/12, layerVals[9]/12, layerVals[10]/12, layerVals[11]/12, layerVals[12]/12, layerVals[13]/12, - layerVals[14]/12, layerVals[15]/12, layerVals[16]/12, layerVals[17]/12, layerVals[18]/12, layerVals[19]/12, layerVals[20]/12, - layerVals[21]/12, layerVals[22]/12, layerVals[23]/12, layerVals[24]/12); - - // write PPT vals to csv - /*fprintf(PPTFILE, "%d,%f,%f,%f,%f,%f,%f,%f,%f,%f,%f,%f,%f\n", yr, PPTlayerVals[0], PPTlayerVals[1], PPTlayerVals[2], - PPTlayerVals[3], PPTlayerVals[4], PPTlayerVals[5], PPTlayerVals[6],PPTlayerVals[7], PPTlayerVals[8], PPTlayerVals[9], - PPTlayerVals[10], PPTlayerVals[11]);*/ - } - // printing out values from the outsetup.in that SOILWAT reads in to ensure passing to STEPPE correctly - /*printf("SXW.grass_cover: %f\n", SXW.grass_cover); - printf("SXW.shrub_cover: %f\n", SXW.shrub_cover); - printf("SXW.tree_cover: %f\n", SXW.tree_cover); - printf("SXW.forbs_cover: %f\n", SXW.forbs_cover);*/ - - - - // Done adding values to soil water csv // - CloseFile(&f); - CloseFile(&PPTFILE); - -} - - #ifdef DEBUG_MEM void Stat_SetMemoryRefs(void) { /* when debugging memory problems, use the bookkeeping diff --git a/sw_src b/sw_src index aec8f8c8..58db9435 160000 --- a/sw_src +++ b/sw_src @@ -1 +1 @@ -Subproject commit aec8f8c8d525a516c49f8bccb55d502408023e37 +Subproject commit 58db9435c0603d4ce450f996ce688f5a29c7ef6a From 3faa61b564f1d7f58d9ce2f171014b47397fca7c Mon Sep 17 00:00:00 2001 From: BrendenBe1 Date: Wed, 10 Jan 2018 16:00:00 -0700 Subject: [PATCH 079/111] Issue #120. Added another param to the output variables to avoid index override. --- sw_src | 2 +- sxw.c | 5 +++-- sxw.h | 5 +++-- 3 files changed, 7 insertions(+), 5 deletions(-) diff --git a/sw_src b/sw_src index 58db9435..5ee9783e 160000 --- a/sw_src +++ b/sw_src @@ -1 +1 @@ -Subproject commit 58db9435c0603d4ce450f996ce688f5a29c7ef6a +Subproject commit 5ee9783eab91317edbd4a93ee3d0f8011de1e5b9 diff --git a/sxw.c b/sxw.c index 9c271a51..bfe4cc18 100644 --- a/sxw.c +++ b/sxw.c @@ -839,8 +839,8 @@ static void _make_swc_array(void) { static void _make_soil_arrays(void){ char *fstr = "_make_soil_arrays"; int size, layer_size, avg_size; - size = (SXW.NPds * Globals.runModelYears * 2) * Globals.runModelYears; - layer_size = (SXW.NPds * SXW.NSoLyrs * Globals.runModelYears * 2) * Globals.runModelYears; + size = (SXW.NPds * Globals.runModelYears * 2 * 4) * Globals.runModelYears; + layer_size = (SXW.NPds * SXW.NSoLyrs * Globals.runModelYears * 2 * 4) * Globals.runModelYears; avg_size = (SXW.NPds * SXW.NSoLyrs * Globals.runModelYears * 2) * Globals.runModelYears; SXW.transpTotal_avg = (RealD *) Mem_Calloc(avg_size, sizeof(RealD), fstr); @@ -869,6 +869,7 @@ static void _make_soil_arrays(void){ SXW.swc_avg = (RealF *) Mem_Calloc(avg_size, sizeof(RealF), fstr); + SXW_AVG.max_temp_avg = (RealF *) Mem_Calloc(size, sizeof(RealF), fstr); SXW_AVG.min_temp_avg = (RealF *) Mem_Calloc(size, sizeof(RealF), fstr); SXW_AVG.avg_temp_avg = (RealF *) Mem_Calloc(size, sizeof(RealF), fstr); diff --git a/sxw.h b/sxw.h index ecc0a27b..29d48ed0 100644 --- a/sxw.h +++ b/sxw.h @@ -180,8 +180,9 @@ typedef struct soilwat_average SXW_avg; #define Iylp(y,l,p,x) (((y)*Globals.runModelYears * SXW.NTrLyrs * SXW.NPds * 2) + ((l)*SXW.NTrLyrs * SXW.NPds * 2) + ((p)*SXW.NPds * 2) + ((x)*2)) // for soilwat average and standard deviation -// year, timeperiod, choice (avg or std) -#define Iypc(y,p,c) (((y)*Globals.runModelYears * SXW.NPds) + ((p)*SXW.NPds) + (c)) +// year, timeperiod, choice (avg or std), timeperiod (dy, wk, mo, yr) +// difference between p and b is p is current period within period (ie. for day it could be 0 to 364) and b is just timeperiod (0 to 3 where 0 is day and 3 is yr) +#define Iypc(y,p,c,b) (((y)*Globals.runModelYears * SXW.NPds * 4) + ((p)*SXW.NPds * 4) + ((c) * 4) + (b)) // veg type, layer, timeperiod #define Ivlp(v,l,p) (((v)*4 * SXW.NTrLyrs * SXW.NPds) + ((l)*SXW.NTrLyrs * SXW.NPds) + ((p)*SXW.NPds)) From 958fd6f9db675be3c494fa8c2decb5443e404011 Mon Sep 17 00:00:00 2001 From: BrendenBe1 Date: Wed, 10 Jan 2018 16:52:36 -0700 Subject: [PATCH 080/111] SOILWAT Issue #120. Fixed issue with values not being written for other timeperiods --- sw_src | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sw_src b/sw_src index 5ee9783e..429f6a59 160000 --- a/sw_src +++ b/sw_src @@ -1 +1 @@ -Subproject commit 5ee9783eab91317edbd4a93ee3d0f8011de1e5b9 +Subproject commit 429f6a59efd895856c08201848d7bf8ffad2f5c3 From 8a07982f395c596fa38ad1e03e045d393e912170 Mon Sep 17 00:00:00 2001 From: kpalmqui Date: Thu, 11 Jan 2018 11:16:27 -0700 Subject: [PATCH 081/111] Updating description of outsetup_v30.in Updated description of how to utilize the two flags outsetup_v30.in file (issue #129). Also removed text on ESTABS and removed that variable from the output options as we will not want to have that as output. --- .../Input/sxw/Input/outsetup_v30.in | 71 +++++++++---------- 1 file changed, 33 insertions(+), 38 deletions(-) diff --git a/testing.sagebrush.master/Stepwat_Inputs/Input/sxw/Input/outsetup_v30.in b/testing.sagebrush.master/Stepwat_Inputs/Input/sxw/Input/outsetup_v30.in index 09f2f032..e7828f40 100644 --- a/testing.sagebrush.master/Stepwat_Inputs/Input/sxw/Input/outsetup_v30.in +++ b/testing.sagebrush.master/Stepwat_Inputs/Input/sxw/Input/outsetup_v30.in @@ -1,18 +1,10 @@ # Output setup file for STEPWAT # # Notes: -# Time periods available: DY,WK,MO,YR +# Time periods available: DY,YR # eg, if DY is chosen then 100,200 would mean to use the second hundred days # But if YR is chosen, start and end numbers are in days so only those days # are reported for the yearly average. -# Some keys from older versions (fortran and the c versions mimicking the fortran -# version) are not currently implemented: -# ALLH20, WTHR. -# -# ESTABL only produces yearly output, namely, DOY for each species requested. -# Thus, to minimize typo errors, all flags are ignored except the filename. -# Output is simply the day of the year establishment occurred for each species -# in each year of the model run. Refer to the estabs.in file for more info. # # DEEPSWC produces output only if the deepdrain flag is set in siteparam.in. # @@ -24,45 +16,48 @@ # SUM - sum the variable for each day in the output period # AVG - average the variable over the output period # FIN - output value of final day in the period; soil water variables only. -# Note that SUM and AVG are the same if timeperiod = dy. +# Note that SUM and AVG are the same if timeperiod = DY. # # (01/17/2013) TIMESTEP key indicates which periods you want to output. # You can output all the periods at a time, just one, or however many # you want. To change which periods to output type 'dy' for day, # 'wk' for week, 'mo' for month, and 'yr' for year after TIMESTEP # in any order. For example: "TIMESTEP mo wk" will output for month and week - -# (1/9/2018) USE_TIMESTEP: this determines if using the timestep periods or using the PERIOD defined for each individual variable (1 = use, 0 = dont use) -# If set to 0 TIMESTEP line determines which output files are to be created so need to have all the timeperiods defined in the values PERIOD +# +# (1/9/2018) USE_TIMESTEP: this determines if the TIMESTEP or PERIOD is used to define time periods for each individual output variable. +# If "USE_TIMESTEP = 0", then the time period for each output variable listed below will be determined by the PERIOD column. Note only 1 time period can be listed for each output variable using this option. +# Also note that all of the time periods specified in the PERIOD column must be listed after TIMESTEP, so the correct output files are generated. # EX: if only using TRANSP and PRECIP and the periods are MO for TRANSP and DY for PRECIP TIMESTEP needs to be "TIMESTEP dy mo" so program knows to create day and month output files -# if "USE_TIMESTEP 1" then can have any combo of periods after TIMESTEP +# If "USE_TIMESTEP = 1", then all output variables listed below will be outputted for the time periods specified after TIMESTEP (e.g. dy, yr). Note, this option allows for output variables to be generated for multiple time periods. +# Also note that when using this option, each variable must only be listed once in the Table below. The PERIOD column is ignored with "USE_TIMESTEP = 1". +# +# To generate SWA output, the SWCBULK variable must also be requested. -USE_TIMESTEP 0 -TIMESTEP dy wk mo yr +USE_TIMESTEP 1 +TIMESTEP dy yr # key SUMTYPE PERIOD start end filename_prefix -TRANSP SUM MO 1 end transp +TRANSP SUM YR 1 end transp PRECIP SUM YR 1 end precip TEMP AVG YR 1 end temp AET SUM YR 1 end aet -SWCBULK FIN MO 1 end swc_bulk -SWA AVG MO 1 end swa -ESTABL off YR 1 end estabs -VWCBULK avg MO 1 end vwc_bulk -VWCMATRIC avg YR 1 end vwc_matric -SWPMATRIC avg WK 1 end swp_matric -SWABULK AVG MO 1 end swa_bulk -SWAMATRIC avg YR 1 end swa_matric -SURFACEWATER avg DY 1 end surface_water -RUNOFF sum WK 1 end runoff -EVAPSOIL sum DY 1 end evap_soil -EVAPSURFACE sum WK 1 end evap_surface -INTERCEPTION sum MO 1 end interception -SOILINFILT sum YR 1 end infiltration -LYRDRAIN sum DY 1 end percolation -HYDRED sum WK 1 end hydred -PET sum DY 1 end pet -WETDAY sum DY 1 end wetdays -SNOWPACK avg WK 1 end snowpack -DEEPSWC sum MO 1 end deep_drain -SOILTEMP avg MO 1 end temp_soil +SWCBULK FIN YR 1 end swc_bulk +SWA AVG YR 1 end swa +VWCBULK avg YR 1 end vwc_bulk +VWCMATRIC avg YR 1 end vwc_matric +SWPMATRIC avg YR 1 end swp_matric +SWABULK AVG YR 1 end swa_bulk +SWAMATRIC avg YR 1 end swa_matric +SURFACEWATER avg YR 1 end surface_water +RUNOFF sum YR 1 end runoff +EVAPSOIL sum YR 1 end evap_soil +EVAPSURFACE sum YR 1 end evap_surface +INTERCEPTION sum YR 1 end interception +SOILINFILT sum YR 1 end infiltration +LYRDRAIN sum YR 1 end percolation +HYDRED sum YR 1 end hydred +PET sum YR 1 end pet +WETDAY sum YR 1 end wetdays +SNOWPACK avg YR 1 end snowpack +DEEPSWC sum YR 1 end deep_drain +SOILTEMP avg YR 1 end temp_soil From a2a1275aa6f2468387fe3a0a96671b226c76d073 Mon Sep 17 00:00:00 2001 From: BrendenBe1 Date: Thu, 11 Jan 2018 13:47:44 -0700 Subject: [PATCH 082/111] Working on SOIWLAT issue #125. For SOILWAT issue #125 functionality from SW_OUT_set_colnames has been integrated and altered to work with the new output file structure. --- sw_src | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sw_src b/sw_src index 429f6a59..908a565c 160000 --- a/sw_src +++ b/sw_src @@ -1 +1 @@ -Subproject commit 429f6a59efd895856c08201848d7bf8ffad2f5c3 +Subproject commit 908a565c1818392cccb2152fed769ab3a4b14e34 From a760a0bb7d53631285d50692b5042aaf831034f7 Mon Sep 17 00:00:00 2001 From: BrendenBe1 Date: Thu, 11 Jan 2018 15:40:51 -0700 Subject: [PATCH 083/111] Added function declarations to SW_Output.h to solve compile error. --- sw_src | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sw_src b/sw_src index 908a565c..127d39be 160000 --- a/sw_src +++ b/sw_src @@ -1 +1 @@ -Subproject commit 908a565c1818392cccb2152fed769ab3a4b14e34 +Subproject commit 127d39bee345cd5e459b8e3039d15ba3a83372e7 From 44e33b24dc9777a4f191cc7f65c6144c482e7e59 Mon Sep 17 00:00:00 2001 From: BrendenBe1 Date: Thu, 18 Jan 2018 13:15:54 -0700 Subject: [PATCH 084/111] Added memory for Carbon outputs and added timestep checks for proper output with use_timestep = 0 and use_timestep = 1 --- ST_main.c | 4 +- sw_src | 2 +- sxw.c | 46 +++++++++++++++++++ sxw.h | 25 ++++++++++ .../Input/sxw/Input/outsetup_v30.in | 39 ++++++++-------- 5 files changed, 95 insertions(+), 21 deletions(-) diff --git a/ST_main.c b/ST_main.c index e1de24aa..0ff0c301 100644 --- a/ST_main.c +++ b/ST_main.c @@ -164,8 +164,10 @@ int main(int argc, char **argv) { parm_Initialize(0); - if (UseSoilwat) + if (UseSoilwat){ SXW_Init(swTRUE, NULL); + SW_OUT_set_ncol(); // set number of columns + } incr = (IntS) ((float) Globals.runModelIterations / 10); if (incr == 0) diff --git a/sw_src b/sw_src index 35caee11..b6b77216 160000 --- a/sw_src +++ b/sw_src @@ -1 +1 @@ -Subproject commit 35caee11cee359011ca6553068ae214d538718e1 +Subproject commit b6b772164ba19ff83d29b28a5a60b060e8e96d68 diff --git a/sxw.c b/sxw.c index 4ffda21a..332bc81e 100644 --- a/sxw.c +++ b/sxw.c @@ -931,6 +931,30 @@ static void _make_soil_arrays(void){ SXW_AVG.soiltemp_avg = (RealF *) Mem_Calloc(layer_size, sizeof(RealF), fstr); + // carbon variables + SXW_AVG.biomass_grass_avg = (RealD *) Mem_Calloc(size, sizeof(RealD), fstr); + SXW_AVG.biomass_shrub_avg = (RealD *) Mem_Calloc(size, sizeof(RealD), fstr); + SXW_AVG.biomass_tree_avg = (RealD *) Mem_Calloc(size, sizeof(RealD), fstr); + SXW_AVG.biomass_forb_avg = (RealD *) Mem_Calloc(size, sizeof(RealD), fstr); + SXW_AVG.biomass_total_avg = (RealD *) Mem_Calloc(size, sizeof(RealD), fstr); + + SXW_AVG.biolive_grass_avg = (RealD *) Mem_Calloc(size, sizeof(RealD), fstr); + SXW_AVG.biolive_shrub_avg = (RealD *) Mem_Calloc(size, sizeof(RealD), fstr); + SXW_AVG.biolive_tree_avg = (RealD *) Mem_Calloc(size, sizeof(RealD), fstr); + SXW_AVG.biolive_forb_avg = (RealD *) Mem_Calloc(size, sizeof(RealD), fstr); + SXW_AVG.biolive_total_avg = (RealD *) Mem_Calloc(size, sizeof(RealD), fstr); + + SXW_AVG.bio_mult_grass_avg = (RealD *) Mem_Calloc(size, sizeof(RealD), fstr); + SXW_AVG.bio_mult_shrub_avg = (RealD *) Mem_Calloc(size, sizeof(RealD), fstr); + SXW_AVG.bio_mult_tree_avg = (RealD *) Mem_Calloc(size, sizeof(RealD), fstr); + SXW_AVG.bio_mult_forb_avg = (RealD *) Mem_Calloc(size, sizeof(RealD), fstr); + + SXW_AVG.wue_mult_grass_avg = (RealD *) Mem_Calloc(size, sizeof(RealD), fstr); + SXW_AVG.wue_mult_shrub_avg = (RealD *) Mem_Calloc(size, sizeof(RealD), fstr); + SXW_AVG.wue_mult_tree_avg = (RealD *) Mem_Calloc(size, sizeof(RealD), fstr); + SXW_AVG.wue_mult_forb_avg = (RealD *) Mem_Calloc(size, sizeof(RealD), fstr); + + Mem_Set(SXW_AVG.max_temp_avg, 0, size * sizeof(RealF)); Mem_Set(SXW_AVG.min_temp_avg, 0, size * sizeof(RealF)); Mem_Set(SXW_AVG.avg_temp_avg, 0, size * sizeof(RealF)); @@ -1387,6 +1411,28 @@ void free_all_sxw_memory( void ) { Mem_Free(SXW_AVG.snowpack_depth_avg); Mem_Free(SXW_AVG.deepswc_avg); Mem_Free(SXW_AVG.soiltemp_avg); + + Mem_Free(SXW_AVG.biomass_grass_avg); + Mem_Free(SXW_AVG.biomass_shrub_avg); + Mem_Free(SXW_AVG.biomass_tree_avg); + Mem_Free(SXW_AVG.biomass_forb_avg); + Mem_Free(SXW_AVG.biomass_total_avg); + + Mem_Free(SXW_AVG.biolive_grass_avg); + Mem_Free(SXW_AVG.biolive_shrub_avg); + Mem_Free(SXW_AVG.biolive_tree_avg); + Mem_Free(SXW_AVG.biolive_forb_avg); + Mem_Free(SXW_AVG.biolive_total_avg); + + Mem_Free(SXW_AVG.bio_mult_grass_avg); + Mem_Free(SXW_AVG.bio_mult_shrub_avg); + Mem_Free(SXW_AVG.bio_mult_tree_avg); + Mem_Free(SXW_AVG.bio_mult_forb_avg); + + Mem_Free(SXW_AVG.wue_mult_grass_avg); + Mem_Free(SXW_AVG.wue_mult_shrub_avg); + Mem_Free(SXW_AVG.wue_mult_tree_avg); + Mem_Free(SXW_AVG.wue_mult_forb_avg); } /***********************************************************/ diff --git a/sxw.h b/sxw.h index 29d48ed0..ba27c5ed 100644 --- a/sxw.h +++ b/sxw.h @@ -150,6 +150,31 @@ struct soilwat_average{ *val_snowloss_avg; RealD *surfaceTemp_avg; + + // Carbon Variables + RealD *biomass_grass_avg, + *biomass_shrub_avg, + *biomass_tree_avg, + *biomass_forb_avg, + *biomass_total_avg, + + *biolive_grass_avg, + *biolive_shrub_avg, + *biolive_tree_avg, + *biolive_forb_avg, + *biolive_total_avg, + + *bio_mult_grass_avg, + *bio_mult_shrub_avg, + *bio_mult_tree_avg, + *bio_mult_forb_avg, + + *wue_mult_grass_avg, + *wue_mult_shrub_avg, + *wue_mult_tree_avg, + *wue_mult_forb_avg; + + }; #define SXW_NFILES 5 diff --git a/testing.sagebrush.master/Stepwat_Inputs/Input/sxw/Input/outsetup_v30.in b/testing.sagebrush.master/Stepwat_Inputs/Input/sxw/Input/outsetup_v30.in index e7828f40..25689cf0 100644 --- a/testing.sagebrush.master/Stepwat_Inputs/Input/sxw/Input/outsetup_v30.in +++ b/testing.sagebrush.master/Stepwat_Inputs/Input/sxw/Input/outsetup_v30.in @@ -41,23 +41,24 @@ TRANSP SUM YR 1 end transp PRECIP SUM YR 1 end precip TEMP AVG YR 1 end temp AET SUM YR 1 end aet -SWCBULK FIN YR 1 end swc_bulk +SWCBULK FIN YR 1 end swc_bulk SWA AVG YR 1 end swa -VWCBULK avg YR 1 end vwc_bulk -VWCMATRIC avg YR 1 end vwc_matric -SWPMATRIC avg YR 1 end swp_matric -SWABULK AVG YR 1 end swa_bulk -SWAMATRIC avg YR 1 end swa_matric -SURFACEWATER avg YR 1 end surface_water -RUNOFF sum YR 1 end runoff -EVAPSOIL sum YR 1 end evap_soil -EVAPSURFACE sum YR 1 end evap_surface -INTERCEPTION sum YR 1 end interception -SOILINFILT sum YR 1 end infiltration -LYRDRAIN sum YR 1 end percolation -HYDRED sum YR 1 end hydred -PET sum YR 1 end pet -WETDAY sum YR 1 end wetdays -SNOWPACK avg YR 1 end snowpack -DEEPSWC sum YR 1 end deep_drain -SOILTEMP avg YR 1 end temp_soil +VWCBULK avg YR 1 end vwc_bulk +VWCMATRIC avg YR 1 end vwc_matric +SWPMATRIC avg YR 1 end swp_matric +SWABULK AVG YR 1 end swa_bulk +SWAMATRIC avg YR 1 end swa_matric +SURFACEWATER avg YR 1 end surface_water +RUNOFF sum YR 1 end runoff +EVAPSOIL sum YR 1 end evap_soil +EVAPSURFACE sum YR 1 end evap_surface +INTERCEPTION sum YR 1 end interception +SOILINFILT sum YR 1 end infiltration +LYRDRAIN sum YR 1 end percolation +HYDRED sum YR 1 end hydred +PET sum YR 1 end pet +WETDAY sum YR 1 end wetdays +SNOWPACK avg YR 1 end snowpack +DEEPSWC sum YR 1 end deep_drain +SOILTEMP avg YR 1 end temp_soil +CO2EFFECTS avg YR 1 end vegetation /* vegetation biomass: biomass (g/m2) for grasses, shrubs, trees, forbs, and total; live biomass (g/m2) fgrasses, shrubs, trees, forbs, and total; biomass CO2-effect (multiplier) for grasses, shrubs, trees, and forbs; WUE CO2-effect (multiplier) for grasses, shrubs, trees, and forbs From bad1a71ed57a4093724307f7330c34fabc200626 Mon Sep 17 00:00:00 2001 From: BrendenBe1 Date: Fri, 19 Jan 2018 11:44:47 -0700 Subject: [PATCH 085/111] Added call to free memory at end of run. Removed hardocoded values and replaces with respective variables (MAX_DAYS, NVEGTYPES) --- ST_main.c | 1 + sxw.c | 16 ++++++++-------- .../Stepwat_Inputs/Input/model.in | 2 +- 3 files changed, 10 insertions(+), 9 deletions(-) diff --git a/ST_main.c b/ST_main.c index 0ff0c301..7cc1d240 100644 --- a/ST_main.c +++ b/ST_main.c @@ -313,6 +313,7 @@ int main(int argc, char **argv) { } #endif + free_all_sxw_memory(); printf("\nend program\n"); fprintf(progfp, "\n"); return 0; diff --git a/sxw.c b/sxw.c index 332bc81e..2a4dcc2b 100644 --- a/sxw.c +++ b/sxw.c @@ -761,7 +761,7 @@ static void _make_roots_arrays(void) { _roots_active_rel = (RealD *) Mem_Calloc(size, sizeof(RealD), fstr); //4 - Grass,Frob,Tree,Shrub - size = 4 * SXW.NPds * SXW.NTrLyrs; + size = NVEGTYPES * SXW.NPds * SXW.NTrLyrs; _roots_active_sum = (RealD *) Mem_Calloc(size, sizeof(RealD), fstr); } @@ -793,7 +793,7 @@ static void _make_transp_arrays(void) { int size; //int avg_size; - size = (SXW.NPds * SXW.NSoLyrs) * 365; + size = (SXW.NPds * SXW.NSoLyrs) * MAX_DAYS; SXW.transpTotal = (RealD *) Mem_Calloc(size, sizeof(RealD), fstr); SXW.transpTrees = (RealD *) Mem_Calloc(size, sizeof(RealD), fstr); SXW.transpShrubs = (RealD *) Mem_Calloc(size, sizeof(RealD), fstr); @@ -807,15 +807,15 @@ static void _make_swa_array(void){ int avg_size; //4 - Grass,Frob,Tree,Shrub - size = 4 * 4 * SXW.NPds * SXW.NSoLyrs * Globals.runModelIterations; + size = NVEGTYPES * NVEGTYPES * SXW.NPds * SXW.NSoLyrs * Globals.runModelIterations; SXW.SWA_master = (RealF *) Mem_Calloc(size, sizeof(RealF), fstr); // 4D SXW.dSWAbulk = (RealF *) Mem_Calloc(size, sizeof(RealF), fstr); // 4D SXW.dSWA_repartitioned = (RealF *) Mem_Calloc(size, sizeof(RealF), fstr); // 4D //Mem_Set(SXW.SWA_master, 0, SXW.NPds * 4 * SXW.NSoLyrs * sizeof(RealF)); memset(SXW.SWA_master, 0, sizeof(SXW.SWA_master)); - Mem_Set(SXW.dSWAbulk, 0, 4*4*SXW.NPds * SXW.NSoLyrs * sizeof(RealF)); - Mem_Set(SXW.dSWA_repartitioned, 0, 4*4*SXW.NPds * SXW.NSoLyrs * sizeof(RealF)); + Mem_Set(SXW.dSWAbulk, 0, size * sizeof(RealF)); + Mem_Set(SXW.dSWA_repartitioned, 0, size * sizeof(RealF)); //memset(SXW.sum_dSWA_repartitioned, 0, sizeof(SXW.sum_dSWA_repartitioned) * 5 * 20 * 500); } @@ -826,7 +826,7 @@ static void _make_swc_array(void) { * specified with debugfile */ char *fstr = "_make_swc_array()"; - int size = SXW.NPds * SXW.NSoLyrs * 366; + int size = SXW.NPds * SXW.NSoLyrs * MAX_DAYS; int avg_size; //int size_3d = 4 * SXW.NPds * SXW.NSoLyrs; @@ -842,8 +842,8 @@ static void _make_swc_array(void) { static void _make_soil_arrays(void){ char *fstr = "_make_soil_arrays"; int size, layer_size, avg_size; - size = (SXW.NPds * Globals.runModelYears * 2 * 4) * Globals.runModelYears; - layer_size = (SXW.NPds * SXW.NSoLyrs * Globals.runModelYears * 2 * 4) * Globals.runModelYears; + size = (SXW.NPds * Globals.runModelYears * 2 * NVEGTYPES) * Globals.runModelYears; + layer_size = (SXW.NPds * SXW.NSoLyrs * Globals.runModelYears * 2 * NVEGTYPES) * Globals.runModelYears; avg_size = (SXW.NPds * SXW.NSoLyrs * Globals.runModelYears * 2) * Globals.runModelYears; SXW.transpTotal_avg = (RealD *) Mem_Calloc(avg_size, sizeof(RealD), fstr); diff --git a/testing.sagebrush.master/Stepwat_Inputs/Input/model.in b/testing.sagebrush.master/Stepwat_Inputs/Input/model.in index b043a569..16f9e88b 100644 --- a/testing.sagebrush.master/Stepwat_Inputs/Input/model.in +++ b/testing.sagebrush.master/Stepwat_Inputs/Input/model.in @@ -19,4 +19,4 @@ # it doesn't hurt to set it to 0 always. # niter nyrs seed - 5 100 0 + 50 300 0 From 0f6514dd69b5012a1244e5939b3223b1347f1216 Mon Sep 17 00:00:00 2001 From: BrendenBe1 Date: Fri, 19 Jan 2018 14:20:21 -0700 Subject: [PATCH 086/111] Altering STEPPE variables to comply with the SOILWAT issue #131 so STEPWAT works with new changes. This just consited of changes to SOILWAT SW_Output.c and adding a few values to structs in STEPWAT to store new values. --- sw_src | 2 +- sxw.c | 9 ++++--- sxw.h | 83 +++++++++++++++++++++++++++++----------------------------- 3 files changed, 49 insertions(+), 45 deletions(-) diff --git a/sw_src b/sw_src index b6b77216..91d42054 160000 --- a/sw_src +++ b/sw_src @@ -1 +1 @@ -Subproject commit b6b772164ba19ff83d29b28a5a60b060e8e96d68 +Subproject commit 91d42054d0852cbe4851a44471c4f66ac4db9b4e diff --git a/sxw.c b/sxw.c index 2a4dcc2b..21cb8dbb 100644 --- a/sxw.c +++ b/sxw.c @@ -894,7 +894,8 @@ static void _make_soil_arrays(void){ SXW_AVG.swamatric_avg = (RealF *) Mem_Calloc(layer_size, sizeof(RealF), fstr); SXW_AVG.surfacewater_avg = (RealF *) Mem_Calloc(size, sizeof(RealF), fstr); SXW_AVG.runoff_total_avg = (RealF *) Mem_Calloc(size, sizeof(RealF), fstr); - SXW_AVG.runoff_surface_avg = (RealF *) Mem_Calloc(size, sizeof(RealF), fstr); + SXW_AVG.surface_runoff_avg = (RealF *) Mem_Calloc(size, sizeof(RealF), fstr); + SXW_AVG.surface_runon_avg = (RealF *) Mem_Calloc(size, sizeof(RealF), fstr); SXW_AVG.runoff_snow_avg = (RealF *) Mem_Calloc(size, sizeof(RealF), fstr); SXW_AVG.evapsoil_avg = (RealF *) Mem_Calloc(layer_size, sizeof(RealF), fstr); SXW_AVG.evapsurface_total_avg = (RealF *) Mem_Calloc(size, sizeof(RealF), fstr); @@ -968,7 +969,8 @@ static void _make_soil_arrays(void){ Mem_Set(SXW_AVG.swamatric_avg, 0, layer_size * sizeof(RealF)); Mem_Set(SXW_AVG.surfacewater_avg, 0, size * sizeof(RealF)); Mem_Set(SXW_AVG.runoff_total_avg, 0, size * sizeof(RealF)); - Mem_Set(SXW_AVG.runoff_surface_avg, 0, size * sizeof(RealF)); + Mem_Set(SXW_AVG.surface_runoff_avg, 0, size * sizeof(RealF)); + Mem_Set(SXW_AVG.surface_runon_avg, 0, size * sizeof(RealF)); Mem_Set(SXW_AVG.runoff_snow_avg, 0, size * sizeof(RealF)); Mem_Set(SXW_AVG.evapsoil_avg, 0, layer_size * sizeof(RealF)); Mem_Set(SXW_AVG.evapsurface_total_avg, 0, size * sizeof(RealF)); @@ -1382,7 +1384,8 @@ void free_all_sxw_memory( void ) { Mem_Free(SXW_AVG.swamatric_avg); Mem_Free(SXW_AVG.surfacewater_avg); Mem_Free(SXW_AVG.runoff_total_avg); - Mem_Free(SXW_AVG.runoff_surface_avg); + Mem_Free(SXW_AVG.surface_runoff_avg); + Mem_Free(SXW_AVG.surface_runon_avg); Mem_Free(SXW_AVG.runoff_snow_avg); Mem_Free(SXW_AVG.evapsoil_avg); Mem_Free(SXW_AVG.evapsurface_total_avg); diff --git a/sxw.h b/sxw.h index ba27c5ed..b558676d 100644 --- a/sxw.h +++ b/sxw.h @@ -101,50 +101,51 @@ struct stepwat_st { }; struct soilwat_average{ - RealF *soilinfilt_avg, // done - *runoff_total_avg,// done - *runoff_surface_avg,// done - *runoff_snow_avg,// done - *vwcbulk_avg, // done - *vwcmatric_avg, // done - *swamatric_avg, // done - *swabulk_avg, // done - *swpmatric_avg, // done - *surfacewater_avg, // done - *evapsoil_avg, // done - *evapsurface_total_avg,// done - *evapsurface_tree_avg,// done - *evapsurface_shrub_avg,// done - *evapsurface_forb_avg,// done - *evapsurface_grass_avg,// done - *evapsurface_litter_avg,// done - *evapsurface_water_avg,// done - - *interception_total_avg,// done - *interception_tree_avg,// done - *interception_shrub_avg,// done - *interception_forb_avg,// done - *interception_grass_avg,// done - *interception_litter_avg,// done - - *lyrdrain_avg, // done - - *hydred_total_avg,// done - *hydred_tree_avg,// done - *hydred_shrub_avg,// done - *hydred_forb_avg,// done - *hydred_grass_avg,// done - - *pet_avg, // done - *wetday_avg, // done - *snowpack_water_eqv_avg, // done - *snowpack_depth_avg, // done - *deepswc_avg, // done - *soiltemp_avg, // done + RealF *soilinfilt_avg, + *runoff_total_avg, + *surface_runoff_avg, + *surface_runon_avg, + *runoff_snow_avg, + *vwcbulk_avg, + *vwcmatric_avg, + *swamatric_avg, + *swabulk_avg, + *swpmatric_avg, + *surfacewater_avg, + *evapsoil_avg, + *evapsurface_total_avg, + *evapsurface_tree_avg, + *evapsurface_shrub_avg, + *evapsurface_forb_avg, + *evapsurface_grass_avg, + *evapsurface_litter_avg, + *evapsurface_water_avg, + + *interception_total_avg, + *interception_tree_avg, + *interception_shrub_avg, + *interception_forb_avg, + *interception_grass_avg, + *interception_litter_avg, + + *lyrdrain_avg, + + *hydred_total_avg, + *hydred_tree_avg, + *hydred_shrub_avg, + *hydred_forb_avg, + *hydred_grass_avg, + + *pet_avg, + *wetday_avg, + *snowpack_water_eqv_avg, + *snowpack_depth_avg, + *deepswc_avg, + *soiltemp_avg, *estab_avg, *max_temp_avg, *min_temp_avg, - *avg_temp_avg, // done + *avg_temp_avg, *aet_avg, *val_snowmelt_avg, *val_snowloss_avg; From ba99709fbfe1da4feee60db06bd8a2a8d1694780 Mon Sep 17 00:00:00 2001 From: BrendenBe1 Date: Fri, 19 Jan 2018 16:14:35 -0700 Subject: [PATCH 087/111] Changes for STEPPE specific code in SW_Output.c to fix problem with USE_TIMESTEP = 0 that emerged after removing calls to .period and using timeSteps[k][i] instead --- sw_src | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sw_src b/sw_src index 91d42054..40756edb 160000 --- a/sw_src +++ b/sw_src @@ -1 +1 @@ -Subproject commit 91d42054d0852cbe4851a44471c4f66ac4db9b4e +Subproject commit 40756edb5cee2aeac61873cdd66bb75d6fb2ca1d From abce9d7140b0375aa68c3d9506f96c8a5166514b Mon Sep 17 00:00:00 2001 From: BrendenBe1 Date: Tue, 23 Jan 2018 13:40:17 -0700 Subject: [PATCH 088/111] merged sw_src with master --- sw_src | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sw_src b/sw_src index 40756edb..000d99c2 160000 --- a/sw_src +++ b/sw_src @@ -1 +1 @@ -Subproject commit 40756edb5cee2aeac61873cdd66bb75d6fb2ca1d +Subproject commit 000d99c294079fa4b1496669904f63e05b143272 From 762a1a266dea56ef749573361240e0d86dc25111 Mon Sep 17 00:00:00 2001 From: BrendenBe1 Date: Tue, 23 Jan 2018 16:26:15 -0700 Subject: [PATCH 089/111] Merged sw_src with master to overhaul veg arrays. Also changed functionality of STEPWAT to work with the new veg arrays. --- sw_src | 2 +- sxw.c | 86 ++++++++++++++++---------------- sxw_soilwat.c | 134 +++++++++++++++++++++++++------------------------- sxw_sql.c | 48 +++++++++--------- 4 files changed, 135 insertions(+), 135 deletions(-) diff --git a/sw_src b/sw_src index 000d99c2..ba94e26f 160000 --- a/sw_src +++ b/sw_src @@ -1 +1 @@ -Subproject commit 000d99c294079fa4b1496669904f63e05b143272 +Subproject commit ba94e26f2f7e2a44de7c003a9c8b52aa0882a029 diff --git a/sxw.c b/sxw.c index 21cb8dbb..e5ef9f1a 100644 --- a/sxw.c +++ b/sxw.c @@ -224,13 +224,13 @@ void SXW_Init( Bool init_SW, char *f_roots ) { free(temp); } - SXW.NTrLyrs = SW_Site.n_transp_lyrs_tree; - if(SW_Site.n_transp_lyrs_shrub > SXW.NTrLyrs) - SXW.NTrLyrs = SW_Site.n_transp_lyrs_shrub; - if(SW_Site.n_transp_lyrs_grass > SXW.NTrLyrs) - SXW.NTrLyrs = SW_Site.n_transp_lyrs_grass; - if(SW_Site.n_transp_lyrs_forb > SXW.NTrLyrs) - SXW.NTrLyrs = SW_Site.n_transp_lyrs_forb; + SXW.NTrLyrs = SW_Site.n_transp_lyrs[0]; + if(SW_Site.n_transp_lyrs[1] > SXW.NTrLyrs) + SXW.NTrLyrs = SW_Site.n_transp_lyrs[1]; + if(SW_Site.n_transp_lyrs[3] > SXW.NTrLyrs) + SXW.NTrLyrs = SW_Site.n_transp_lyrs[3]; + if(SW_Site.n_transp_lyrs[2] > SXW.NTrLyrs) + SXW.NTrLyrs = SW_Site.n_transp_lyrs[2]; SXW.NSoLyrs = SW_Site.n_layers; @@ -346,38 +346,38 @@ void SXW_SW_Setup_Echo(void) { FILE *f = OpenFile(strcat(name, ".input.out"), "a"); int i; fprintf(f, "\n================== %d =============================\n", SW_Model.year); - fprintf(f,"Fractions Grass:%f Shrub:%f Tree:%f Forb:%f BareGround:%f\n", SW_VegProd.grass.cov.fCover, SW_VegProd.shrub.cov.fCover, SW_VegProd.tree.cov.fCover, SW_VegProd.forb.cov.fCover, SW_VegProd.bare_cov.fCover); + fprintf(f,"Fractions Grass:%f Shrub:%f Tree:%f Forb:%f BareGround:%f\n", SW_VegProd.veg[3].cov.fCover, SW_VegProd.veg[1].cov.fCover, SW_VegProd.veg[0].cov.fCover, SW_VegProd.veg[2].cov.fCover, SW_VegProd.bare_cov.fCover); fprintf(f,"Monthly Production Values\n"); fprintf(f,"Grass\n"); fprintf(f,"Month\tLitter\tBiomass\tPLive\tLAI_conv\n"); for (i = 0; i < 12; i++) { - fprintf(f,"%u\t%f\t%f\t%f\t%f\n", i + 1, SW_VegProd.grass.litter[i], - SW_VegProd.grass.biomass[i], SW_VegProd.grass.pct_live[i], - SW_VegProd.grass.lai_conv[i]); + fprintf(f,"%u\t%f\t%f\t%f\t%f\n", i + 1, SW_VegProd.veg[3].litter[i], + SW_VegProd.veg[3].biomass[i], SW_VegProd.veg[3].pct_live[i], + SW_VegProd.veg[3].lai_conv[i]); } fprintf(f,"Shrub\n"); fprintf(f,"Month\tLitter\tBiomass\tPLive\tLAI_conv\n"); for (i = 0; i < 12; i++) { - fprintf(f,"%u\t%f\t%f\t%f\t%f\n", i + 1, SW_VegProd.shrub.litter[i], - SW_VegProd.shrub.biomass[i], SW_VegProd.shrub.pct_live[i], - SW_VegProd.shrub.lai_conv[i]); + fprintf(f,"%u\t%f\t%f\t%f\t%f\n", i + 1, SW_VegProd.veg[1].litter[i], + SW_VegProd.veg[1].biomass[i], SW_VegProd.veg[1].pct_live[i], + SW_VegProd.veg[1].lai_conv[i]); } fprintf(f,"Tree\n"); fprintf(f,"Month\tLitter\tBiomass\tPLive\tLAI_conv\n"); for (i = 0; i < 12; i++) { - fprintf(f,"%u\t%f\t%f\t%f\t%f\n", i + 1, SW_VegProd.tree.litter[i], - SW_VegProd.tree.biomass[i], SW_VegProd.tree.pct_live[i], - SW_VegProd.tree.lai_conv[i]); + fprintf(f,"%u\t%f\t%f\t%f\t%f\n", i + 1, SW_VegProd.veg[0].litter[i], + SW_VegProd.veg[0].biomass[i], SW_VegProd.veg[0].pct_live[i], + SW_VegProd.veg[0].lai_conv[i]); } fprintf(f,"Forb\n"); fprintf(f,"Month\tLitter\tBiomass\tPLive\tLAI_conv\n"); for (i = 0; i < 12; i++) { - fprintf(f,"%u\t%f\t%f\t%f\t%f\n", i + 1, SW_VegProd.forb.litter[i], - SW_VegProd.forb.biomass[i], SW_VegProd.forb.pct_live[i], - SW_VegProd.forb.lai_conv[i]); + fprintf(f,"%u\t%f\t%f\t%f\t%f\n", i + 1, SW_VegProd.veg[2].litter[i], + SW_VegProd.veg[2].biomass[i], SW_VegProd.veg[2].pct_live[i], + SW_VegProd.veg[2].lai_conv[i]); } SW_SITE *s = &SW_Site; @@ -385,7 +385,7 @@ void SXW_SW_Setup_Echo(void) { fprintf(f,"Forb\tTree\tShrub\tGrass\n"); ForEachSoilLayer(i) {// %u %u %u %u s->lyr[i]->my_transp_rgn_forb, s->lyr[i]->my_transp_rgn_tree, s->lyr[i]->my_transp_rgn_shrub, s->lyr[i]->my_transp_rgn_grass - fprintf(f,"%6.2f %6.2f %6.2f %6.2f\n", s->lyr[i]->transp_coeff_forb, s->lyr[i]->transp_coeff_tree, s->lyr[i]->transp_coeff_shrub, s->lyr[i]->transp_coeff_grass); + fprintf(f,"%6.2f %6.2f %6.2f %6.2f\n", s->lyr[i]->transp_coeff[2], s->lyr[i]->transp_coeff[0], s->lyr[i]->transp_coeff[1], s->lyr[i]->transp_coeff[3]); } // adding values to sxw structure for use in ST_stats.c @@ -1185,24 +1185,24 @@ void _print_debuginfo(void) { } // all the other months have 31 days for (i = doy; i < (doy + days); i++) { //accumulating the monthly values... - lai_live += (v->tree.lai_live_daily[i]) - + (v->shrub.lai_live_daily[i]) - + (v->grass.lai_live_daily[i]) - + (v->forb.lai_live_daily[i]); - vegcov += (v->tree.vegcov_daily[i]) + (v->shrub.vegcov_daily[i]) - + (v->grass.vegcov_daily[i]) + (v->forb.vegcov_daily[i]); - total_agb += (v->tree.total_agb_daily[i]) - + (v->shrub.total_agb_daily[i]) - + (v->grass.total_agb_daily[i]) - + (v->forb.total_agb_daily[i]); - pct_live += (v->tree.pct_live_daily[i]) - + (v->shrub.pct_live_daily[i]) - + (v->grass.pct_live_daily[i]) - + (v->forb.pct_live_daily[i]); - biomass += (v->tree.biomass_daily[i]) - + (v->shrub.biomass_daily[i]) - + (v->grass.biomass_daily[i]) - + (v->forb.biomass_daily[i]); + lai_live += (v->veg[0].lai_live_daily[i]) + + (v->veg[1].lai_live_daily[i]) + + (v->veg[3].lai_live_daily[i]) + + (v->veg[2].lai_live_daily[i]); + vegcov += (v->veg[0].vegcov_daily[i]) + (v->veg[1].vegcov_daily[i]) + + (v->veg[3].vegcov_daily[i]) + (v->veg[2].vegcov_daily[i]); + total_agb += (v->veg[0].total_agb_daily[i]) + + (v->veg[1].total_agb_daily[i]) + + (v->veg[3].total_agb_daily[i]) + + (v->veg[2].total_agb_daily[i]); + pct_live += (v->veg[0].pct_live_daily[i]) + + (v->veg[1].pct_live_daily[i]) + + (v->veg[3].pct_live_daily[i]) + + (v->veg[2].pct_live_daily[i]); + biomass += (v->veg[0].biomass_daily[i]) + + (v->veg[1].biomass_daily[i]) + + (v->veg[3].biomass_daily[i]) + + (v->veg[2].biomass_daily[i]); } doy += days; //updating the doy //biomass = (v->tree.biomass[p]) + (v->shrub.biomass[p]) @@ -1322,13 +1322,13 @@ void SXW_SetMemoryRefs( void) { //returns the number of transpiration layers correctly for each veg_prod_type int getNTranspLayers(int veg_prod_type) { if(veg_prod_type == 1) - return SW_Site.n_transp_lyrs_tree; + return SW_Site.n_transp_lyrs[0]; else if(veg_prod_type == 2) - return SW_Site.n_transp_lyrs_shrub; + return SW_Site.n_transp_lyrs[1]; else if(veg_prod_type == 3) - return SW_Site.n_transp_lyrs_grass; + return SW_Site.n_transp_lyrs[3]; else if(veg_prod_type == 4) - return SW_Site.n_transp_lyrs_forb; + return SW_Site.n_transp_lyrs[2]; return -1; } diff --git a/sxw_soilwat.c b/sxw_soilwat.c index 15d861d1..aff4d932 100644 --- a/sxw_soilwat.c +++ b/sxw_soilwat.c @@ -95,25 +95,25 @@ void _sxw_sw_setup (RealF sizes[]) { #ifndef SXW_BYMAXSIZE for (doy = 1; doy <= MAX_DAYS; doy++) { - v->tree.litter_daily[doy] = 0; - v->grass.litter_daily[doy] = 0; - v->shrub.litter_daily[doy] = 0; - v->forb.litter_daily[doy] = 0; - - v->tree.biomass_daily[doy] = 0; - v->grass.biomass_daily[doy] = 0; - v->shrub.biomass_daily[doy] = 0; - v->forb.biomass_daily[doy] = 0; - - v->tree.pct_live_daily[doy] = 0; - v->grass.pct_live_daily[doy] = 0; - v->shrub.pct_live_daily[doy] = 0; - v->forb.pct_live_daily[doy] = 0; - - v->tree.lai_conv_daily[doy] = 0; - v->grass.lai_conv_daily[doy] = 0; - v->shrub.lai_conv_daily[doy] = 0; - v->forb.lai_conv_daily[doy] = 0; + v->veg[0].litter_daily[doy] = 0; + v->veg[3].litter_daily[doy] = 0; + v->veg[1].litter_daily[doy] = 0; + v->veg[2].litter_daily[doy] = 0; + + v->veg[0].biomass_daily[doy] = 0; + v->veg[3].biomass_daily[doy] = 0; + v->veg[1].biomass_daily[doy] = 0; + v->veg[2].biomass_daily[doy] = 0; + + v->veg[0].pct_live_daily[doy] = 0; + v->veg[3].pct_live_daily[doy] = 0; + v->veg[1].pct_live_daily[doy] = 0; + v->veg[2].pct_live_daily[doy] = 0; + + v->veg[0].lai_conv_daily[doy] = 0; + v->veg[3].lai_conv_daily[doy] = 0; + v->veg[1].lai_conv_daily[doy] = 0; + v->veg[2].lai_conv_daily[doy] = 0; } SW_VPD_init(); @@ -153,56 +153,56 @@ static void _update_transp_coeff(RealF relsize[]) { ForEachTreeTranspLayer(t) { y = SW_Site.lyr[t]; - y->transp_coeff_tree = 0.; + y->transp_coeff[0] = 0.; ForEachGroup(g) if(RGroup[g]->veg_prod_type == 1) if (getNTranspLayers(RGroup[g]->veg_prod_type)) - y->transp_coeff_tree += (RealF) _roots_max[Ilg(t, g)] * relsize[g]; - sum1 += y->transp_coeff_tree; + y->transp_coeff[0] += (RealF) _roots_max[Ilg(t, g)] * relsize[g]; + sum1 += y->transp_coeff[0]; } ForEachShrubTranspLayer(t) { y = SW_Site.lyr[t]; - y->transp_coeff_shrub = 0.; + y->transp_coeff[1] = 0.; ForEachGroup(g) if(RGroup[g]->veg_prod_type == 2) if (getNTranspLayers(RGroup[g]->veg_prod_type)) - y->transp_coeff_shrub += (RealF) _roots_max[Ilg(t, g)] * relsize[g]; - sum2 += y->transp_coeff_shrub; + y->transp_coeff[1] += (RealF) _roots_max[Ilg(t, g)] * relsize[g]; + sum2 += y->transp_coeff[1]; } ForEachGrassTranspLayer(t) { y = SW_Site.lyr[t]; - y->transp_coeff_grass = 0.; + y->transp_coeff[3] = 0.; ForEachGroup(g) if(RGroup[g]->veg_prod_type == 3) if (getNTranspLayers(RGroup[g]->veg_prod_type)) - y->transp_coeff_grass += (RealF) _roots_max[Ilg(t, g)] * relsize[g]; - sum3 += y->transp_coeff_grass; + y->transp_coeff[3] += (RealF) _roots_max[Ilg(t, g)] * relsize[g]; + sum3 += y->transp_coeff[3]; } ForEachForbTranspLayer(t) { y = SW_Site.lyr[t]; - y->transp_coeff_forb = 0.; + y->transp_coeff[2] = 0.; ForEachGroup(g) if(RGroup[g]->veg_prod_type == 4) if (getNTranspLayers(RGroup[g]->veg_prod_type)) - y->transp_coeff_forb += (RealF) _roots_max[Ilg(t, g)] * relsize[g]; - sum4 += y->transp_coeff_forb; + y->transp_coeff[2] += (RealF) _roots_max[Ilg(t, g)] * relsize[g]; + sum4 += y->transp_coeff[2]; } /* normalize coefficients to 1.0 If sum is 0, then the transp_coeff is also 0. */ ForEachTreeTranspLayer(t) - if(!ZRO(sum1)) SW_Site.lyr[t]->transp_coeff_tree /= sum1; + if(!ZRO(sum1)) SW_Site.lyr[t]->transp_coeff[0] /= sum1; ForEachShrubTranspLayer(t) - if(!ZRO(sum2)) SW_Site.lyr[t]->transp_coeff_shrub /= sum2; + if(!ZRO(sum2)) SW_Site.lyr[t]->transp_coeff[1] /= sum2; ForEachGrassTranspLayer(t) - if(!ZRO(sum3)) SW_Site.lyr[t]->transp_coeff_grass /= sum3; + if(!ZRO(sum3)) SW_Site.lyr[t]->transp_coeff[3] /= sum3; ForEachForbTranspLayer(t) - if(!ZRO(sum4)) SW_Site.lyr[t]->transp_coeff_forb /= sum4; + if(!ZRO(sum4)) SW_Site.lyr[t]->transp_coeff[2] /= sum4; } @@ -259,58 +259,58 @@ static void _update_productivity(void) { /* compute monthly biomass, litter, and pct live per month */ ForEachMonth(m) { - v->tree.pct_live[m] = 0.; - v->tree.biomass[m] = 0.; - v->tree.litter[m] = 0.; - v->shrub.pct_live[m] = 0.; - v->shrub.biomass[m] = 0.; - v->shrub.litter[m] = 0.; - v->grass.pct_live[m] = 0.; - v->grass.biomass[m] = 0.; - v->grass.litter[m] = 0.; - v->forb.pct_live[m] = 0.; - v->forb.biomass[m] = 0.; - v->forb.litter[m] = 0.; + v->veg[0].pct_live[m] = 0.; + v->veg[0].biomass[m] = 0.; + v->veg[0].litter[m] = 0.; + v->veg[1].pct_live[m] = 0.; + v->veg[1].biomass[m] = 0.; + v->veg[1].litter[m] = 0.; + v->veg[3].pct_live[m] = 0.; + v->veg[3].biomass[m] = 0.; + v->veg[3].litter[m] = 0.; + v->veg[2].pct_live[m] = 0.; + v->veg[2].biomass[m] = 0.; + v->veg[2].litter[m] = 0.; if (GT(totbmass, 0.)) { ForEachGroup(g) { if (1 == RGroup[g]->veg_prod_type) { //tree - v->tree.pct_live[m] += _prod_pctlive[Igp(g, m)] * rgroupFractionOfVegTypeBiomass[g]; - v->tree.biomass[m] += _prod_bmass[Igp(g, m)] * bmassg[g]; + v->veg[0].pct_live[m] += _prod_pctlive[Igp(g, m)] * rgroupFractionOfVegTypeBiomass[g]; + v->veg[0].biomass[m] += _prod_bmass[Igp(g, m)] * bmassg[g]; } else if (2 == RGroup[g]->veg_prod_type) { //shrub - v->shrub.pct_live[m] += _prod_pctlive[Igp(g, m)] * rgroupFractionOfVegTypeBiomass[g]; - v->shrub.biomass[m] += _prod_bmass[Igp(g, m)] * bmassg[g]; + v->veg[1].pct_live[m] += _prod_pctlive[Igp(g, m)] * rgroupFractionOfVegTypeBiomass[g]; + v->veg[1].biomass[m] += _prod_bmass[Igp(g, m)] * bmassg[g]; } else if (3 == RGroup[g]->veg_prod_type) { //grass - v->grass.pct_live[m] += _prod_pctlive[Igp(g, m)] * rgroupFractionOfVegTypeBiomass[g]; - v->grass.biomass[m] += _prod_bmass[Igp(g, m)] * bmassg[g]; + v->veg[3].pct_live[m] += _prod_pctlive[Igp(g, m)] * rgroupFractionOfVegTypeBiomass[g]; + v->veg[3].biomass[m] += _prod_bmass[Igp(g, m)] * bmassg[g]; } else if (4 == RGroup[g]->veg_prod_type) { //forb - v->forb.pct_live[m] += _prod_pctlive[Igp(g, m)] * rgroupFractionOfVegTypeBiomass[g]; - v->forb.biomass[m] += _prod_bmass[Igp(g, m)] * bmassg[g]; + v->veg[2].pct_live[m] += _prod_pctlive[Igp(g, m)] * rgroupFractionOfVegTypeBiomass[g]; + v->veg[2].biomass[m] += _prod_bmass[Igp(g, m)] * bmassg[g]; } } - v->tree.litter[m] = (vegTypeBiomass[0] * _prod_litter[m]); - v->shrub.litter[m] = (vegTypeBiomass[1] * _prod_litter[m]); - v->grass.litter[m] = (vegTypeBiomass[2] * _prod_litter[m]); - v->forb.litter[m] = (vegTypeBiomass[3] * _prod_litter[m]); + v->veg[0].litter[m] = (vegTypeBiomass[0] * _prod_litter[m]); + v->veg[1].litter[m] = (vegTypeBiomass[1] * _prod_litter[m]); + v->veg[3].litter[m] = (vegTypeBiomass[2] * _prod_litter[m]); + v->veg[2].litter[m] = (vegTypeBiomass[3] * _prod_litter[m]); } } if (GT(totbmass, 0.)) { //if (ZRO(biomass)) // biomass = 1; - v->tree.cov.fCover = (vegTypeBiomass[0] / totbmass); - v->shrub.cov.fCover = (vegTypeBiomass[1] / totbmass); - v->grass.cov.fCover = (vegTypeBiomass[2] / totbmass); - v->forb.cov.fCover = (vegTypeBiomass[3] / totbmass); + v->veg[0].cov.fCover = (vegTypeBiomass[0] / totbmass); + v->veg[1].cov.fCover = (vegTypeBiomass[1] / totbmass); + v->veg[3].cov.fCover = (vegTypeBiomass[2] / totbmass); + v->veg[2].cov.fCover = (vegTypeBiomass[3] / totbmass); //TODO: figure how to calculate bareground fraction. v->bare_cov.fCover = 0; } else { - v->tree.cov.fCover = (0.0); - v->shrub.cov.fCover = (0.0); - v->grass.cov.fCover = (0.0); - v->forb.cov.fCover = (0.0); + v->veg[0].cov.fCover = (0.0); + v->veg[1].cov.fCover = (0.0); + v->veg[3].cov.fCover = (0.0); + v->veg[2].cov.fCover = (0.0); v->bare_cov.fCover = 1; } #undef Biomass diff --git a/sxw_sql.c b/sxw_sql.c index ee01f24a..ffc5ed26 100644 --- a/sxw_sql.c +++ b/sxw_sql.c @@ -221,7 +221,7 @@ void insertInputVars() { SW_VEGPROD *v = &SW_VegProd; beginTransaction(); - insertSXWinputVarsRow(Year, Iteration, v->grass.cov.fCover, v->shrub.cov.fCover, v->tree.cov.fCover, v->forb.cov.fCover, v->bare_cov.fCover); + insertSXWinputVarsRow(Year, Iteration, v->veg[3].cov.fCover, v->veg[1].cov.fCover, v->veg[0].cov.fCover, v->veg[2].cov.fCover, v->bare_cov.fCover); endTransaction(); } @@ -256,10 +256,10 @@ void insertInputProd() { beginTransaction(); ForEachTrPeriod(p) { - insertSXWinputProdRow(Year, Iteration, 1, p+1, v->tree.litter[p], v->tree.biomass[p], v->tree.pct_live[p], v->tree.lai_conv[p]); - insertSXWinputProdRow(Year, Iteration, 2, p+1, v->shrub.litter[p], v->shrub.biomass[p], v->shrub.pct_live[p], v->shrub.lai_conv[p]); - insertSXWinputProdRow(Year, Iteration, 3, p+1, v->grass.litter[p], v->grass.biomass[p], v->grass.pct_live[p], v->grass.lai_conv[p]); - insertSXWinputProdRow(Year, Iteration, 4, p+1, v->forb.litter[p], v->forb.biomass[p], v->forb.pct_live[p], v->forb.lai_conv[p]); + insertSXWinputProdRow(Year, Iteration, 1, p+1, v->veg[0].litter[p], v->veg[0].biomass[p], v->veg[0].pct_live[p], v->veg[0].lai_conv[p]); + insertSXWinputProdRow(Year, Iteration, 2, p+1, v->veg[1].litter[p], v->veg[1].biomass[p], v->veg[1].pct_live[p], v->veg[1].lai_conv[p]); + insertSXWinputProdRow(Year, Iteration, 3, p+1, v->veg[3].litter[p], v->veg[3].biomass[p], v->veg[3].pct_live[p], v->veg[3].lai_conv[p]); + insertSXWinputProdRow(Year, Iteration, 4, p+1, v->veg[2].litter[p], v->veg[2].biomass[p], v->veg[2].pct_live[p], v->veg[2].lai_conv[p]); } endTransaction(); } @@ -295,7 +295,7 @@ void insertInputSoils() { beginTransaction(); ForEachSoilLayer(l) { - insertSXWinputSoilsRow(Year, Iteration, l+1, s->lyr[l]->transp_coeff_tree, s->lyr[l]->transp_coeff_shrub, s->lyr[l]->transp_coeff_grass, s->lyr[l]->transp_coeff_forb); + insertSXWinputSoilsRow(Year, Iteration, l+1, s->lyr[l]->transp_coeff[0], s->lyr[l]->transp_coeff[1], s->lyr[l]->transp_coeff[3], s->lyr[l]->transp_coeff[2]); } endTransaction(); } @@ -417,24 +417,24 @@ void insertOutputProd(SW_VEGPROD *v) { } // all the other months have 31 days for (i = doy; i < (doy + days); i++) { //accumulating the monthly values... - lai_live += (v->tree.lai_live_daily[i]) - + (v->shrub.lai_live_daily[i]) - + (v->grass.lai_live_daily[i]) - + (v->forb.lai_live_daily[i]); - vegcov += (v->tree.vegcov_daily[i]) + (v->shrub.vegcov_daily[i]) - + (v->grass.vegcov_daily[i]) + (v->forb.vegcov_daily[i]); - total_agb += (v->tree.total_agb_daily[i]) - + (v->shrub.total_agb_daily[i]) - + (v->grass.total_agb_daily[i]) - + (v->forb.total_agb_daily[i]); - pct_live += (v->tree.pct_live_daily[i]) - + (v->shrub.pct_live_daily[i]) - + (v->grass.pct_live_daily[i]) - + (v->forb.pct_live_daily[i]); - biomass += (v->tree.biomass_daily[i]) - + (v->shrub.biomass_daily[i]) - + (v->grass.biomass_daily[i]) - + (v->forb.biomass_daily[i]); + lai_live += (v->veg[0].lai_live_daily[i]) + + (v->veg[1].lai_live_daily[i]) + + (v->veg[3].lai_live_daily[i]) + + (v->veg[2].lai_live_daily[i]); + vegcov += (v->veg[0].vegcov_daily[i]) + (v->veg[1].vegcov_daily[i]) + + (v->veg[3].vegcov_daily[i]) + (v->veg[2].vegcov_daily[i]); + total_agb += (v->veg[0].total_agb_daily[i]) + + (v->veg[1].total_agb_daily[i]) + + (v->veg[3].total_agb_daily[i]) + + (v->veg[2].total_agb_daily[i]); + pct_live += (v->veg[0].pct_live_daily[i]) + + (v->veg[1].pct_live_daily[i]) + + (v->veg[3].pct_live_daily[i]) + + (v->veg[2].pct_live_daily[i]); + biomass += (v->veg[0].biomass_daily[i]) + + (v->veg[1].biomass_daily[i]) + + (v->veg[3].biomass_daily[i]) + + (v->veg[2].biomass_daily[i]); } doy += days; //updating the doy From 85211fd7758894b8133bbabab33159a740863c3b Mon Sep 17 00:00:00 2001 From: BrendenBe1 Date: Thu, 25 Jan 2018 12:11:40 -0700 Subject: [PATCH 090/111] master merged into sw_src dealing with water balance --- sw_src | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sw_src b/sw_src index ba94e26f..274b3593 160000 --- a/sw_src +++ b/sw_src @@ -1 +1 @@ -Subproject commit ba94e26f2f7e2a44de7c003a9c8b52aa0882a029 +Subproject commit 274b35932b6e3d579759166736edf558fc1815a2 From cd63a53d633b37480e7897b5698094cc552c44d2 Mon Sep 17 00:00:00 2001 From: BrendenBe1 Date: Thu, 25 Jan 2018 16:00:45 -0700 Subject: [PATCH 091/111] Updated vegetation in ST_grid.c to be arrays --- ST_grid.c | 38 +++++++++++++++++++------------------- 1 file changed, 19 insertions(+), 19 deletions(-) diff --git a/ST_grid.c b/ST_grid.c index efa44d87..25b6d92d 100644 --- a/ST_grid.c +++ b/ST_grid.c @@ -2307,9 +2307,9 @@ static void _init_soil_layers(int cell, int isSpinup) Mem_Free(SW_Site.lyr); SW_Site.n_layers = grid_Soils[i].num_layers; - SW_Site.n_evap_lyrs = SW_Site.n_transp_lyrs_forb = - SW_Site.n_transp_lyrs_tree = SW_Site.n_transp_lyrs_shrub = - SW_Site.n_transp_lyrs_grass = 0; + SW_Site.n_evap_lyrs = SW_Site.n_transp_lyrs[SW_FORBS] = + SW_Site.n_transp_lyrs[SW_TREES] = SW_Site.n_transp_lyrs[SW_SHRUB] = + SW_Site.n_transp_lyrs[SW_GRASS] = 0; SW_Site.lyr = Mem_Calloc(SW_Site.n_layers + SW_Site.deepdrain, sizeof(SW_LAYER_INFO *), "_init_grid_globals()"); @@ -2362,19 +2362,19 @@ static void _init_soil_layers(int cell, int isSpinup) SW_Site.lyr[j]->soilMatric_density = grid_Soils[i].lyr[j].data[0]; SW_Site.lyr[j]->fractionVolBulk_gravel = grid_Soils[i].lyr[j].data[1]; SW_Site.lyr[j]->evap_coeff = grid_Soils[i].lyr[j].data[2]; - SW_Site.lyr[j]->transp_coeff_grass = grid_Soils[i].lyr[j].data[3]; - SW_Site.lyr[j]->transp_coeff_shrub = grid_Soils[i].lyr[j].data[4]; - SW_Site.lyr[j]->transp_coeff_tree = grid_Soils[i].lyr[j].data[5]; - SW_Site.lyr[j]->transp_coeff_forb = grid_Soils[i].lyr[j].data[6]; + SW_Site.lyr[j]->transp_coeff[3] = grid_Soils[i].lyr[j].data[3]; + SW_Site.lyr[j]->transp_coeff[1] = grid_Soils[i].lyr[j].data[4]; + SW_Site.lyr[j]->transp_coeff[0] = grid_Soils[i].lyr[j].data[5]; + SW_Site.lyr[j]->transp_coeff[2] = grid_Soils[i].lyr[j].data[6]; SW_Site.lyr[j]->fractionWeightMatric_sand = grid_Soils[i].lyr[j].data[7]; SW_Site.lyr[j]->fractionWeightMatric_clay = grid_Soils[i].lyr[j].data[8]; SW_Site.lyr[j]->impermeability = grid_Soils[i].lyr[j].data[9]; - SW_Site.lyr[j]->my_transp_rgn_tree = 0; - SW_Site.lyr[j]->my_transp_rgn_forb = 0; - SW_Site.lyr[j]->my_transp_rgn_shrub = 0; - SW_Site.lyr[j]->my_transp_rgn_grass = 0; + SW_Site.lyr[j]->my_transp_rgn[0] = 0; + SW_Site.lyr[j]->my_transp_rgn[2] = 0; + SW_Site.lyr[j]->my_transp_rgn[1] = 0; + SW_Site.lyr[j]->my_transp_rgn[3] = 0; SW_Site.lyr[j]->sTemp = grid_Soils[i].lyr[j].data[10]; if (evap_ok) @@ -2386,29 +2386,29 @@ static void _init_soil_layers(int cell, int isSpinup) } if (transp_ok_tree) { - if (GT(SW_Site.lyr[j]->transp_coeff_tree, 0.0)) - SW_Site.n_transp_lyrs_tree++; + if (GT(SW_Site.lyr[j]->transp_coeff[0], 0.0)) + SW_Site.n_transp_lyrs[SW_TREES]++; else transp_ok_tree = swFALSE; } if (transp_ok_shrub) { - if (GT(SW_Site.lyr[j]->transp_coeff_shrub, 0.0)) - SW_Site.n_transp_lyrs_shrub++; + if (GT(SW_Site.lyr[j]->transp_coeff[1], 0.0)) + SW_Site.n_transp_lyrs[SW_SHRUB]++; else transp_ok_shrub = swFALSE; } if (transp_ok_grass) { - if (GT(SW_Site.lyr[j]->transp_coeff_grass, 0.0)) - SW_Site.n_transp_lyrs_grass++; + if (GT(SW_Site.lyr[j]->transp_coeff[3], 0.0)) + SW_Site.n_transp_lyrs[SW_GRASS]++; else transp_ok_grass = swFALSE; } if (transp_ok_forb) { - if (GT(SW_Site.lyr[j]->transp_coeff_forb, 0.0)) - SW_Site.n_transp_lyrs_forb++; + if (GT(SW_Site.lyr[j]->transp_coeff[2], 0.0)) + SW_Site.n_transp_lyrs[SW_FORBS]++; else transp_ok_forb = swFALSE; } From 8a7affac1abd998c9a618797eeec79b1f9641616 Mon Sep 17 00:00:00 2001 From: BrendenBe1 Date: Thu, 25 Jan 2018 16:47:14 -0700 Subject: [PATCH 092/111] Moved running_avg and running_std functions to ST_Stats.c from SW_Output.c in sw_src --- ST_functions.h | 3 +++ ST_stats.c | 13 +++++++++++++ sw_src | 2 +- 3 files changed, 17 insertions(+), 1 deletion(-) diff --git a/ST_functions.h b/ST_functions.h index 5f3d603d..c2f501a8 100644 --- a/ST_functions.h +++ b/ST_functions.h @@ -55,6 +55,9 @@ void Indiv_SortSize( const byte sorttype, int Indiv_CompSize_A( const void *key1, const void *key2); int Indiv_CompSize_D( const void *key1, const void *key2); +float get_running_avg(float old_val, float val_to_add); +float get_running_sqr(float old_val, float val_to_add, float run_avg); + #ifdef DEBUG_MEM void RGroup_SetMemoryRefs(void); diff --git a/ST_stats.c b/ST_stats.c index 3ca96adc..9084e319 100644 --- a/ST_stats.c +++ b/ST_stats.c @@ -608,6 +608,19 @@ void stat_Save_Accumulators(int cell, int year) { } +float get_running_avg(float old_val, float val_to_add){ + float new_avg; + new_avg = old_val + (val_to_add - old_val) / Globals.currIter; + return new_avg; +} + +float get_running_sqr(float old_val, float val_to_add, float run_avg){ + float run_sqr; + run_sqr = (val_to_add-old_val) * (val_to_add-run_avg); + + return run_sqr; +} + /***********************************************************/ void stat_Free_Accumulators( void ) { //frees all the memory allocated in stat_init_Accumulators() diff --git a/sw_src b/sw_src index 274b3593..be5c521a 160000 --- a/sw_src +++ b/sw_src @@ -1 +1 @@ -Subproject commit 274b35932b6e3d579759166736edf558fc1815a2 +Subproject commit be5c521a4000798d8f8e1da7458974e3a61487f6 From c874225dd01ad28a5d51105717703137b75f52c6 Mon Sep 17 00:00:00 2001 From: BrendenBe1 Date: Thu, 25 Jan 2018 17:07:47 -0700 Subject: [PATCH 093/111] Changed order of veg types to match the veg types defined in SOILWAT --- sw_src | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sw_src b/sw_src index be5c521a..f2fea1ab 160000 --- a/sw_src +++ b/sw_src @@ -1 +1 @@ -Subproject commit be5c521a4000798d8f8e1da7458974e3a61487f6 +Subproject commit f2fea1abc482a5ef214925e416e70da85fd5e304 From 29612ecb9899872fc3b242cf90c128a440794d97 Mon Sep 17 00:00:00 2001 From: BrendenBe1 Date: Thu, 1 Feb 2018 14:27:49 -0700 Subject: [PATCH 094/111] Changed swTRUE and swFALSE back to TRUE and FALSE. Removed hardcoded values for veg types. Moved variables around to put them in locations that make the most logical sense. --- ST_defines.h | 5 +++ ST_environs.c | 14 ++++---- ST_grid.c | 58 +++++++++++++++---------------- ST_indivs.c | 10 +++--- ST_main.c | 93 +++++++++++++++----------------------------------- ST_mortality.c | 28 +++++++-------- ST_params.c | 52 ++++++++++++++-------------- ST_resgroups.c | 42 +++++++++++------------ ST_stats.c | 8 ++--- sw_src | 2 +- sxw.c | 34 ++++++++---------- sxw.h | 21 +++--------- sxw_resource.c | 2 +- 13 files changed, 160 insertions(+), 209 deletions(-) diff --git a/ST_defines.h b/ST_defines.h index 1895c7e5..e2e47f94 100644 --- a/ST_defines.h +++ b/ST_defines.h @@ -18,6 +18,11 @@ /* see #include "ST_structs.h" below */ + +// TRUE / FALSE +#define TRUE 1 +#define FALSE 0 + /*************************************************** * Basic definitions ***************************************************/ diff --git a/ST_environs.c b/ST_environs.c index fcde3548..9bf06510 100644 --- a/ST_environs.c +++ b/ST_environs.c @@ -56,11 +56,11 @@ void Env_Generate( void) { Int rg; switch (UseSoilwat) { - case swFALSE: + case FALSE: /* clear last year's leftover resources */ ForEachGroup(rg) RGroup[rg]->res_avail = 0.0; break; - case swTRUE: + case TRUE: SXW_Run_SOILWAT(); break; } @@ -241,17 +241,17 @@ static void _make_disturbance( void) { case FecalPat: if (Plot.pat_removed) { Plot.disturbed = 0; - Plot.pat_removed = swFALSE; + Plot.pat_removed = FALSE; Plot.disturbance = NoDisturb; } else { pc = Globals.pat.recol[Slope] * Plot.disturbed + Globals.pat.recol[Intcpt]; if (RandUni() <= pc) { - Plot.pat_removed = swTRUE; + Plot.pat_removed = TRUE; /* slight effects for one year*/ Plot.disturbed = 1; } else { - Plot.pat_removed = swFALSE; + Plot.pat_removed = FALSE; Plot.disturbed++; } } @@ -272,7 +272,7 @@ static void _make_disturbance( void) { event = (DisturbEvent) RandUniRange(1, LastDisturb -1); /* make sure this is off unless needed */ - Plot.pat_removed = swFALSE; + Plot.pat_removed = FALSE; switch( event) { case FecalPat: if (!Globals.pat.use) {event=NoDisturb; break;} @@ -280,7 +280,7 @@ static void _make_disturbance( void) { ? event : NoDisturb; if (event == NoDisturb) break; Plot.pat_removed = (RandUni() <= Globals.pat.removal) - ? swTRUE : swFALSE; + ? TRUE : FALSE; Plot.disturbed = 0; break; case AntMound: diff --git a/ST_grid.c b/ST_grid.c index 25b6d92d..7368eaea 100644 --- a/ST_grid.c +++ b/ST_grid.c @@ -446,7 +446,7 @@ void runGrid(void) { //for each cell //fprintf(stderr, "year: %d", year); - _load_cell(i, j, year, swTRUE); + _load_cell(i, j, year, TRUE); if (year == 1 && (sd_Option2a || sd_Option2b)) { @@ -484,7 +484,7 @@ void runGrid(void) stat_Collect(year); - _save_cell(i, j, year, swTRUE); + _save_cell(i, j, year, TRUE); // Moved kill annual and kill extra growth after we export biomass, we also doing recoverly after killing year _kill_annuals(); @@ -512,10 +512,10 @@ void runGrid(void) for (i = 1; i <= grid_Rows; i++) for (j = 1; j <= grid_Cols; j++) { - _load_cell(i, j, Globals.runModelYears, swTRUE); + _load_cell(i, j, Globals.runModelYears, TRUE); stat_Collect_GMort(); stat_Collect_SMort(); - _save_cell(i, j, Globals.runModelYears, swTRUE); + _save_cell(i, j, Globals.runModelYears, TRUE); } //reset soilwat to initial condition if (UseSoilwat) @@ -547,7 +547,7 @@ void runGrid(void) { int cell = j + ((i - 1) * grid_Cols) - 1; - _load_cell(i, j, 1, swTRUE); + _load_cell(i, j, 1, TRUE); for (year = 2; year <= Globals.runModelYears; year++) // _load_cell gets the first years accumulators loaded, so we start at 2... stat_Load_Accumulators(cell, year); @@ -602,7 +602,7 @@ static void _run_spinup(void) Bool killedany; IntS year, iter; - DuringSpinup = swTRUE; + DuringSpinup = TRUE; if (!UseSoils || !UseSoilwat) { // if we're not using inputting soils then there is simply one soil type as all the soils are the same @@ -674,7 +674,7 @@ static void _run_spinup(void) //_free_grid_globals(); //free's the grid variables that change every iter } /*end iterations */ - DuringSpinup = swFALSE; + DuringSpinup = FALSE; } /***********************************************************/ @@ -775,14 +775,14 @@ static void _init_grid_inputs(void) if (UseSoils && UseSoilwat) _read_soils_in(); - DuringSpinup = swFALSE; + DuringSpinup = FALSE; } /***********************************************************/ static void _init_SXW_inputs(Bool init_SW, char *f_roots) { SXW_Init(init_SW, f_roots); // initializes soilwat - if (init_SW == swTRUE) + if (init_SW == TRUE) { char aString[2048]; sprintf(aString, "%s/%s", grid_directories[0], SW_Weather.name_prefix); @@ -800,7 +800,7 @@ static void _init_stepwat_inputs(void) parm_Initialize(0); // loads stepwat input files if (UseSoilwat) - _init_SXW_inputs(swTRUE, NULL); + _init_SXW_inputs(TRUE, NULL); ChDir(".."); // goes back to the folder that we were in } @@ -2040,7 +2040,7 @@ static Bool GetALine2(FILE *f, char buf[], int limit) int i = 0, aChar; aChar = getc(f); if (aChar == EOF) - return swFALSE; + return FALSE; while ((i < (limit - 1)) && aChar != EOF && aChar != '\r' && aChar != '\n') { buf[i++] = (char) aChar; @@ -2051,7 +2051,7 @@ static Bool GetALine2(FILE *f, char buf[], int limit) fseek(f, -1, SEEK_CUR); //back up one character in the file because we didn't find a new-line character buf[i] = '\0'; - return swTRUE; + return TRUE; } /***********************************************************/ @@ -2295,9 +2295,9 @@ static void _init_soil_layers(int cell, int isSpinup) int i, j; i = cell; char *errtype = '\0'; - Bool evap_ok = swTRUE, transp_ok_forb = swTRUE, transp_ok_tree = swTRUE, - transp_ok_shrub = swTRUE, transp_ok_grass = swTRUE; /* mitigate gaps in layers */ - Bool fail = swFALSE; + Bool evap_ok = TRUE, transp_ok_forb = TRUE, transp_ok_tree = TRUE, + transp_ok_shrub = TRUE, transp_ok_grass = TRUE; /* mitigate gaps in layers */ + Bool fail = FALSE; RealF fval = 0; if (SW_Site.deepdrain) @@ -2317,32 +2317,32 @@ static void _init_soil_layers(int cell, int isSpinup) { if (LT(grid_Soils[i].lyr[j].data[0], 0.)) { - fail = swTRUE; + fail = TRUE; fval = grid_Soils[i].lyr[j].data[0]; errtype = Str_Dup("bulk density"); } else if (LT(grid_Soils[i].lyr[j].data[1], 0.) || GT(grid_Soils[i].lyr[j].data[1], 1)) { - fail = swTRUE; + fail = TRUE; fval = grid_Soils[i].lyr[j].data[1]; errtype = Str_Dup("gravel content"); } else if (LE(grid_Soils[i].lyr[j].data[7], 0.)) { - fail = swTRUE; + fail = TRUE; fval = grid_Soils[i].lyr[j].data[7]; errtype = Str_Dup("sand proportion"); } else if (LE(grid_Soils[i].lyr[j].data[8], 0.)) { - fail = swTRUE; + fail = TRUE; fval = grid_Soils[i].lyr[j].data[8]; errtype = Str_Dup("clay proportion"); } else if (LT(grid_Soils[i].lyr[j].data[9], 0.)) { - fail = swTRUE; + fail = TRUE; fval = grid_Soils[i].lyr[j].data[9]; errtype = Str_Dup("impermeability"); } @@ -2382,35 +2382,35 @@ static void _init_soil_layers(int cell, int isSpinup) if (GT(SW_Site.lyr[j]->evap_coeff, 0.0)) SW_Site.n_evap_lyrs++; else - evap_ok = swFALSE; + evap_ok = FALSE; } if (transp_ok_tree) { if (GT(SW_Site.lyr[j]->transp_coeff[0], 0.0)) SW_Site.n_transp_lyrs[SW_TREES]++; else - transp_ok_tree = swFALSE; + transp_ok_tree = FALSE; } if (transp_ok_shrub) { if (GT(SW_Site.lyr[j]->transp_coeff[1], 0.0)) SW_Site.n_transp_lyrs[SW_SHRUB]++; else - transp_ok_shrub = swFALSE; + transp_ok_shrub = FALSE; } if (transp_ok_grass) { if (GT(SW_Site.lyr[j]->transp_coeff[3], 0.0)) SW_Site.n_transp_lyrs[SW_GRASS]++; else - transp_ok_grass = swFALSE; + transp_ok_grass = FALSE; } if (transp_ok_forb) { if (GT(SW_Site.lyr[j]->transp_coeff[2], 0.0)) SW_Site.n_transp_lyrs[SW_FORBS]++; else - transp_ok_forb = swFALSE; + transp_ok_forb = FALSE; } water_eqn(SW_Site.lyr[j]->fractionVolBulk_gravel, SW_Site.lyr[j]->fractionWeightMatric_sand, @@ -2438,7 +2438,7 @@ static void _init_soil_layers(int cell, int isSpinup) init_site_info(); //in SW_Site.c, called to initialize layer data... free_all_sxw_memory(); - _init_SXW_inputs(swFALSE, grid_Soils[i].rootsFile); //we call this so that SXW can set the correct sizes/values up for the memory dynamically allocated in sxw.c + _init_SXW_inputs(FALSE, grid_Soils[i].rootsFile); //we call this so that SXW can set the correct sizes/values up for the memory dynamically allocated in sxw.c if (!isSpinup) { @@ -2727,7 +2727,7 @@ static void _do_seed_dispersal(void) sgerm = (grid_SD[s][i].seeds_present || grid_SD[s][i].seeds_received) && germ; //refers to whether the species has seeds available from the previous year and conditions are correct for germination this year - grid_Species[s][i].allow_growth = swFALSE; + grid_Species[s][i].allow_growth = FALSE; biomass = grid_Species[s][i].relsize * grid_Species[s][i].mature_biomass; @@ -2743,12 +2743,12 @@ static void _do_seed_dispersal(void) //will fail and allow_growth will not become TRUE, then when Globals.currYear=8 this allow_growth= FALSE will carry forward and there will no call // to other functions like Species_Update_Newsize() so new size will not be updated and last year size will carry forward so in final output year 7 and year 8 will // have same output that is not correct. - grid_Species[s][i].allow_growth = swTRUE; + grid_Species[s][i].allow_growth = TRUE; } } else if (sgerm || GT(biomass, 0.0)) - grid_Species[s][i].allow_growth = swTRUE; + grid_Species[s][i].allow_growth = TRUE; grid_Species[s][i].sd_sgerm = sgerm; //based upon whether we have received/produced seeds that germinated //if(grid_Species[s][i].allow_growth == TRUE && i == 52 && s == 0 && Globals.currIter == 1) // printf("%s allow_growth:%d year:%d sgerm:%d iter:%d\n", grid_Species[s][i].name, grid_Species[s][i].allow_growth, year, sgerm, Globals.currIter); diff --git a/ST_indivs.c b/ST_indivs.c index 6be569d2..d6ca9a42 100644 --- a/ST_indivs.c +++ b/ST_indivs.c @@ -99,7 +99,7 @@ Bool indiv_New( SppIndex sp) { p = _create(); p->id = id; p->myspecies = sp; - p->killed = swFALSE; + p->killed = FALSE; p->age = 1; p->slow_yrs = 0; p->relsize = Species[sp]->relseedlingsize; @@ -116,7 +116,7 @@ Bool indiv_New( SppIndex sp) { //if(!UseGrid) // insertIndiv(p); id++; - return( swTRUE); + return( TRUE); } /**************************************************************/ @@ -181,12 +181,12 @@ Bool indiv_Kill_Partial( MortalityType code, /*------------------------------------------------------*/ SppIndex sp; - Bool result = swFALSE; + Bool result = FALSE; sp = ndv->myspecies; if ( GT(ndv->relsize, killamt) && Species[sp]->isclonal) { - result = swTRUE; - ndv->killed = swTRUE; + result = TRUE; + ndv->killed = TRUE; ndv->relsize -= killamt; ndv->killedby = code; ndv->growthrate = 0.0; diff --git a/ST_main.c b/ST_main.c index 7cc1d240..bdaa1e4f 100644 --- a/ST_main.c +++ b/ST_main.c @@ -29,12 +29,14 @@ #ifdef STEPWAT #include "sxw_funcs.h" #include "sxw.h" + #include "sw_src/SW_Output.h" extern SXW_t SXW; #endif extern Bool isPartialSoilwatOutput; extern Bool storeAllIterations; extern SW_VEGPROD SW_VegProd; +extern SW_FILE_STATUS Sw_File_Status; /************* External Function Declarations **************/ /***********************************************************/ @@ -145,19 +147,19 @@ int main(int argc, char **argv) { Bool killedany; int k; - logged = swFALSE; + logged = FALSE; atexit(check_log); /* provides a way to inform user that something * was logged. see generic.h */ - isPartialSoilwatOutput = swTRUE; // dont want to get soilwat output unless -o flag - storeAllIterations = swFALSE; // dont want to store all soilwat output iterations unless -i flag + isPartialSoilwatOutput = TRUE; // dont want to get soilwat output unless -o flag + storeAllIterations = FALSE; // dont want to store all soilwat output iterations unless -i flag init_args(argc, argv); // read input arguments and intialize proper flags printf("STEPWAT init_args() executed successfully \n"); - if (UseGrid == swTRUE) { + if (UseGrid == TRUE) { runGrid(); return 0; } @@ -165,7 +167,7 @@ int main(int argc, char **argv) { parm_Initialize(0); if (UseSoilwat){ - SXW_Init(swTRUE, NULL); + SXW_Init(TRUE, NULL); SW_OUT_set_ncol(); // set number of columns } @@ -173,52 +175,11 @@ int main(int argc, char **argv) { if (incr == 0) incr = 1; - /*---------------------------------------------------------- - Get proper order for rank_SWPcrits - ----------------------------------------------------------*/ - int outerLoop, innerLoop; - float key; - RealF tempArray[4], tempArrayUnsorted[4]; // need two temp arrays equal to critSoilWater since we dont want to alter the original at all - tempArray[0] = SW_VegProd.critSoilWater[0]; - tempArray[1] = SW_VegProd.critSoilWater[1]; - tempArray[2] = SW_VegProd.critSoilWater[2]; - tempArray[3] = SW_VegProd.critSoilWater[3]; - tempArrayUnsorted[0] = SW_VegProd.critSoilWater[0]; - tempArrayUnsorted[1] = SW_VegProd.critSoilWater[1]; - tempArrayUnsorted[2] = SW_VegProd.critSoilWater[2]; - tempArrayUnsorted[3] = SW_VegProd.critSoilWater[3]; - - // insertion sort to rank the veg types and store them in their proper order - for (outerLoop = 1; outerLoop < 4; outerLoop++) - { - key = tempArray[outerLoop]; // set key equal to critical value - innerLoop = outerLoop-1; - while (innerLoop >= 0 && tempArray[innerLoop] < key) - { - // code to switch values - tempArray[innerLoop+1] = tempArray[innerLoop]; - innerLoop = innerLoop-1; - } - tempArray[innerLoop+1] = key; - } - - // loops to compare sorted v unsorted array and find proper index - for(outerLoop = 0; outerLoop < 4; outerLoop++){ - for(innerLoop = 0; innerLoop < 4; innerLoop++){ - if(tempArray[outerLoop] == tempArrayUnsorted[innerLoop]){ - SXW.rank_SWPcrits[outerLoop] = innerLoop; - tempArrayUnsorted[innerLoop] = 100; // set value to something impossible so if a duplicate a different index is picked next - break; - } - } - } - /*printf("%d = %f\n", SXW.rank_SWPcrits[0], SW_VegProd.critSoilWater[SXW.rank_SWPcrits[0]]); - printf("%d = %f\n", SXW.rank_SWPcrits[1], SW_VegProd.critSoilWater[SXW.rank_SWPcrits[1]]); - printf("%d = %f\n", SXW.rank_SWPcrits[2], SW_VegProd.critSoilWater[SXW.rank_SWPcrits[2]]); - printf("%d = %f\n\n", SXW.rank_SWPcrits[3], SW_VegProd.critSoilWater[SXW.rank_SWPcrits[3]]);*/ - /*---------------------------------------------------------- - End of rank_SWPcrits - ----------------------------------------------------------*/ + // set values to -1 so SW_Output.c knows first time through + Sw_File_Status.finalValue_dy = -1; + Sw_File_Status.finalValue_wk = -1; + Sw_File_Status.finalValue_mo = -1; + Sw_File_Status.finalValue_yr = -1; /* --- Begin a new iteration ------ */ for (iter = 1; iter <= Globals.runModelIterations; iter++) { @@ -231,10 +192,10 @@ int main(int argc, char **argv) { } // set these to 0 for use with -i flag (need to create column headers for every iteration file) - SXW.col_status_dy = 0; - SXW.col_status_wk = 0; - SXW.col_status_mo = 0; - SXW.col_status_yr = 0; + Sw_File_Status.col_status_dy = 0; + Sw_File_Status.col_status_wk = 0; + Sw_File_Status.col_status_mo = 0; + Sw_File_Status.col_status_yr = 0; if (BmassFlags.yearly || MortFlags.yearly) parm_Initialize(iter); @@ -382,7 +343,7 @@ void Plot_Initialize(void) { RGroup[rg]->est_count = 0; } RGroup[rg]->yrs_neg_pr = 0; - RGroup[rg]->extirpated = swFALSE; + RGroup[rg]->extirpated = FALSE; } if (UseSoilwat) @@ -426,11 +387,11 @@ static void init_args(int argc, char **argv) { a, /* current valid argument-value position */ op, /* position number of found option */ nopts=sizeof(opts)/sizeof(char *); - Bool lastop_noval = swFALSE; + Bool lastop_noval = FALSE; /* Defaults */ parm_SetFirstName( DFLT_FIRSTFILE); - UseSoilwat = QuietMode = EchoInits = UseSeedDispersal = swFALSE; + UseSoilwat = QuietMode = EchoInits = UseSeedDispersal = FALSE; SXW.debugfile = NULL; progfp = stderr; @@ -454,7 +415,7 @@ static void init_args(int argc, char **argv) { exit(-1); } if (a == argc - 1 && strlen(argv[a]) == 2) - lastop_noval = swTRUE; + lastop_noval = TRUE; *str = '\0'; /* extract value part of option-value pair */ @@ -511,36 +472,36 @@ static void init_args(int argc, char **argv) { break; /* -f */ case 2: - QuietMode = swTRUE; + QuietMode = TRUE; break; /* -q */ case 3: - UseSoilwat = swTRUE; /* -s */ + UseSoilwat = TRUE; /* -s */ if (strlen(str) > 1) SXW.debugfile = Str_Dup(str); break; case 4: - EchoInits = swTRUE; + EchoInits = TRUE; break; /* -e */ case 5: progfp = stdout; /* -p */ - UseProgressBar = swTRUE; + UseProgressBar = TRUE; break; case 6: - UseGrid = swTRUE; + UseGrid = TRUE; break; /* -g */ case 7: printf("storing SOILWAT output (flag -o)\n"); - isPartialSoilwatOutput = swFALSE; + isPartialSoilwatOutput = FALSE; break; /* -o also get all the soilwat output*/ case 8: // -i printf("storing SOILWAT output for all iterations\n"); - storeAllIterations = swTRUE; + storeAllIterations = TRUE; break; default: diff --git a/ST_mortality.c b/ST_mortality.c index 688e076f..a0de4b8f 100644 --- a/ST_mortality.c +++ b/ST_mortality.c @@ -134,7 +134,7 @@ void mort_Main( Bool *killed) { SppIndex sp; GroupType *g; - _SomeKillage = swFALSE; + _SomeKillage = FALSE; ForEachGroup(rg) { g = RGroup[rg]; @@ -392,7 +392,7 @@ static void _pat( const SppIndex sp) { } } - if (k >= 0) _SomeKillage = swTRUE; + if (k >= 0) _SomeKillage = TRUE; } @@ -407,14 +407,14 @@ static void _mound( const SppIndex sp) { /* Chris Bennett @ LTER-CSU 6/15/2000 */ /*------------------------------------------------------*/ - Bool k = swFALSE; + Bool k = FALSE; switch ( Species[sp]->disturbclass) { case VerySensitive: case Sensitive: case Insensitive: Species_Kill(sp,2); - k = swTRUE; + k = TRUE; break; case VeryInsensitive: /* unaffected*/ @@ -423,7 +423,7 @@ static void _mound( const SppIndex sp) { } - if (k) _SomeKillage = swTRUE; + if (k) _SomeKillage = TRUE; } @@ -437,7 +437,7 @@ static void _burrow( const SppIndex sp) { /* Chris Bennett @ LTER-CSU 6/15/2000 */ /*------------------------------------------------------*/ - Bool k=swFALSE; + Bool k=FALSE; switch ( Species[sp]->disturbclass) { @@ -446,10 +446,10 @@ static void _burrow( const SppIndex sp) { case Insensitive: case VeryInsensitive: Species_Kill(sp,3); - k = swTRUE; + k = TRUE; } - if (k ) _SomeKillage = swTRUE; + if (k ) _SomeKillage = TRUE; } @@ -488,7 +488,7 @@ static void _succulents( const SppIndex sp) { indiv_Kill_Complete(kills[i], 7); - if (Species[sp]->est_count) _SomeKillage = swTRUE; + if (Species[sp]->est_count) _SomeKillage = TRUE; } @@ -540,7 +540,7 @@ static void _slow_growth( const SppIndex sp) { for( n=0; n <= k; n++ ) indiv_Kill_Complete(kills[n], 8); - if (k >= 0) _SomeKillage = swTRUE; + if (k >= 0) _SomeKillage = TRUE; } /***********************************************************/ @@ -590,7 +590,7 @@ static void _age_independent( const SppIndex sp) { } - if (k >= 0) _SomeKillage = swTRUE; + if (k >= 0) _SomeKillage = TRUE; Mem_Free(kills); } @@ -641,7 +641,7 @@ static void _no_resources( GrpIndex rg) { for( i=0; i < nk; i++) indiv_Kill_Complete(indv_list[i], 10); - if (nk) _SomeKillage = swTRUE; + if (nk) _SomeKillage = TRUE; /* Check to see if this group's resources have been stretched, * and commit mortality of clonal plants which get additional @@ -710,7 +710,7 @@ static void _stretched_clonal( GrpIndex rg, Int start, Int last, indiv_Kill_Complete(clist[i], 11); } - if (nk >= 0) _SomeKillage = swTRUE; + if (nk >= 0) _SomeKillage = TRUE; /*-----------------------------------------*/ } else { /* reduce inverse-proportionally*/ @@ -742,7 +742,7 @@ static void _stretched_clonal( GrpIndex rg, Int start, Int last, indiv_reduction); } - if (np >= 0) _SomeKillage = swTRUE; + if (np >= 0) _SomeKillage = TRUE; } /* end if pm*/ } /* end if y >= 1*/ diff --git a/ST_params.c b/ST_params.c index 48c86992..1f85910d 100644 --- a/ST_params.c +++ b/ST_params.c @@ -100,7 +100,7 @@ char *MyFileName; /**************************************************************/ void parm_Initialize( Int iter) { /*======================================================*/ - static Bool beenhere = swFALSE; + static Bool beenhere = FALSE; char filename[FILENAME_MAX]; if (beenhere) { @@ -152,7 +152,7 @@ void parm_Initialize( Int iter) { RandSeed(Globals.randseed); /*_recover_names();*/ - beenhere = swTRUE; + beenhere = TRUE; } } @@ -400,7 +400,7 @@ static void _check_species( void) { runyrs = Globals.runModelYears; /* shorthand */ SppIndex sp; GrpIndex rg; - Bool tripped = swFALSE; + Bool tripped = FALSE; GroupType *g; SpeciesType *s; @@ -415,7 +415,7 @@ static void _check_species( void) { } g->max_spp = cnt; if (cnt < g->max_spp_estab) { - tripped = swTRUE; + tripped = TRUE; g->max_spp_estab = cnt; LogError(logfp, LOGNOTE, "Max_Spp_Estab > Number of Spp for %s", g->name); @@ -729,7 +729,7 @@ static void _mortflags_init( void) { MortFlags.summary = (Bool)(*s=='y'||*s=='Y'); MortFlags.yearly = (Bool)(*y=='y'||*y=='Y'); if (!(MortFlags.summary || MortFlags.yearly)) { - MortFlags.header = MortFlags.group = MortFlags.species = swFALSE; + MortFlags.header = MortFlags.group = MortFlags.species = FALSE; return; } @@ -885,10 +885,10 @@ static void _rgroup_init( void) { /* ------------------------------------------------------------*/ /* Install all the defined groups, except for dry/wet/norm parms */ - groupsok = swFALSE; + groupsok = FALSE; while( GetALine(f,inbuf)) { if (!isnull(strstr(inbuf,"[end]"))) { - groupsok = swTRUE; + groupsok = TRUE; break; } x=sscanf( inbuf, "%s %f %f %d %f %d %d %d %d %d %d %d %f %d %d %f %d %f %f %f %f %d", @@ -914,10 +914,10 @@ static void _rgroup_init( void) { /* ------------------------------------------------------------*/ /* Install dry/wet/norm parms for defined groups */ - groupsok = swFALSE; + groupsok = FALSE; while( GetALine(f,inbuf)) { if (!isnull(strstr(inbuf,"[end]"))) { - groupsok = swTRUE; + groupsok = TRUE; break; } x=sscanf( inbuf, "%s %f %f %f %f %f %f", @@ -988,7 +988,7 @@ static void _rgroup_add1( char name[], RealF space, RealF density, RGroup[rg]->proportion_grazing = prop_grazing; RGroup[rg]->grazingfreq_startyr = grazingfreq_startyr; - RGroup[rg]->extirpated = swFALSE; + RGroup[rg]->extirpated = FALSE; } @@ -1038,7 +1038,7 @@ static void _rgroup_addsucculent( char name[], LogError(logfp, LOGFATAL, "%s: Mismatched name (%s) for succulents", MyFileName, name2); } - RGroup[rg]->succulent = swTRUE; + RGroup[rg]->succulent = TRUE; Succulent.growth[Slope] = wslope; Succulent.growth[Intcpt] = wint; Succulent.mort[Slope] = dslope; @@ -1058,7 +1058,7 @@ static void _species_init( void) { /* Read parameters for each species */ FILE *f; - Bool readspp = swTRUE, sppok = swTRUE; + Bool readspp = TRUE, sppok = TRUE; /* temp vars to hold the group info*/ char name[80], /* plenty of space to read possibly long name*/ @@ -1084,9 +1084,9 @@ static void _species_init( void) { f = OpenFile(MyFileName, "r"); while( readspp) { - if( ! GetALine(f, inbuf )) {sppok=swFALSE;break;} + if( ! GetALine(f, inbuf )) {sppok=FALSE;break;} if ( ! isnull( strstr(inbuf,"[end]")) ) { - readspp=swFALSE; + readspp=FALSE; continue; } @@ -1135,7 +1135,7 @@ static void _species_init( void) { Species[sp]->max_vegunits = (Species[sp]->isclonal) ? vegi : 0; - Species[sp]->use_me = (RGroup[rg-1]->use_me) ? itob(turnon) : swFALSE ; + Species[sp]->use_me = (RGroup[rg-1]->use_me) ? itob(turnon) : FALSE ; Species[sp]->received_prob = 0; Species[sp]->cohort_surv = cohort; /* Species[sp]->ann_mort_prob = (age > 0) @@ -1155,11 +1155,11 @@ static void _species_init( void) { /* ------------------------------------------------- */ /* ------ read the additional annuals' establishment parameters */ - sppok = readspp = swTRUE; + sppok = readspp = TRUE; while( readspp) { - if( ! GetALine(f, inbuf )) {sppok=swFALSE; break;} + if( ! GetALine(f, inbuf )) {sppok=FALSE; break;} if ( ! isnull( strstr(inbuf,"[end]")) ) { - readspp=swFALSE; + readspp=FALSE; continue; } @@ -1191,11 +1191,11 @@ static void _species_init( void) { /* ------------------------------------------------- */ /* ------ read the vegetative propagation parameters */ - sppok = readspp = swTRUE; + sppok = readspp = TRUE; while( readspp) { - if( ! GetALine(f, inbuf )) {sppok=swFALSE; break;} + if( ! GetALine(f, inbuf )) {sppok=FALSE; break;} if ( ! isnull( strstr(inbuf,"[end]")) ) { - readspp=swFALSE; + readspp=FALSE; continue; } @@ -1225,11 +1225,11 @@ static void _species_init( void) { /* ------------------------------------------------- */ /* ------- read the seed dispersal parameters ------ */ - sppok = readspp = swTRUE; + sppok = readspp = TRUE; while( readspp ) { - if( !GetALine(f, inbuf) ) {sppok=swFALSE; break;} + if( !GetALine(f, inbuf) ) {sppok=FALSE; break;} if( !isnull(strstr(inbuf,"[end]")) ) { - readspp=swFALSE; + readspp=FALSE; continue; } @@ -1244,8 +1244,8 @@ static void _species_init( void) { LogError(logfp, LOGFATAL, "%s: Mismatched name (%s) for species seed dispersal inputs", MyFileName, name2); Species[sp]->use_dispersal = itob(turnondispersal); - Species[sp]->allow_growth = swTRUE; - Species[sp]->sd_sgerm = swFALSE; + Species[sp]->allow_growth = TRUE; + Species[sp]->sd_sgerm = FALSE; Species[sp]->sd_Param1 = p1; Species[sp]->sd_PPTdry = p2; diff --git a/ST_resgroups.c b/ST_resgroups.c index e4f4837d..2d425e51 100644 --- a/ST_resgroups.c +++ b/ST_resgroups.c @@ -86,10 +86,10 @@ void rgroup_PartResources(void) size_base[MAX_RGROUPS] = {0}, /* total res. contrib to base, all groups */ size_obase[MAX_RGROUPS] = {0}; /* total res. contrib. if xtra_obase */ - Bool noplants = swTRUE; - const Bool do_base = swFALSE, /* monikers for _res_part_extra() */ - do_extra = swTRUE, add_seeds = swTRUE, /* monikers for pass 1 & 2 _add_annuals() */ - no_seeds = swFALSE; + Bool noplants = TRUE; + const Bool do_base = FALSE, /* monikers for _res_part_extra() */ + do_extra = TRUE, add_seeds = TRUE, /* monikers for pass 1 & 2 _add_annuals() */ + no_seeds = FALSE; GroupType *g; /* shorthand for RGroup[rg] */ int i; @@ -164,9 +164,9 @@ void rgroup_PartResources(void) } #endif - /* If relsize>0, reset noplants from swTRUE to swFALSE and if noplants=swTRUE, exit from the loop */ + /* If relsize>0, reset noplants from TRUE to FALSE and if noplants=TRUE, exit from the loop */ if (GT(g->relsize, 0.)) - noplants = swFALSE; + noplants = FALSE; } /* End ForEachGroup(rg) */ @@ -178,7 +178,7 @@ void rgroup_PartResources(void) // _res_part_extra(do_base, xtra_base, size_base); //_res_part_extra(do_extra, xtra_obase, size_obase); - /* reset annuals' "swTRUE" relative size here */ + /* reset annuals' "TRUE" relative size here */ //KAP: formely, this call established annual species. We have moved annual establishment to the Rgroup_Establish function, //where all other resource groups establish (e.g. perennials). This function is no longer required. ForEachGroup(rg) @@ -198,10 +198,10 @@ static RealF _add_annuals(const GrpIndex rg, const RealF g_pr, /* if add_seeds==FALSE, don't add seeds to the seedbank or * add species, but do calculations required to return a * temporary group relative size for resource allocation. - * if add_seeds==swTRUE, we should have done the above and now + * if add_seeds==TRUE, we should have done the above and now * we really want to add to the biomass and seedbank. * - * check regen_ok flag. if swTRUE, apply establishment and + * check regen_ok flag. if TRUE, apply establishment and * add to seedbank. Otherwise, add 0 to seedbank and skip * adding plants this year. We also check probability of establishment to * account for introduction of propagules, in which case @@ -231,7 +231,7 @@ static RealF _add_annuals(const GrpIndex rg, const RealF g_pr, { s = Species[sp]; newsize = 0.0; - forced = swFALSE; + forced = FALSE; // printf("add_seeds=%d \n",add_seeds); if (!s->use_me) continue; @@ -239,9 +239,9 @@ static RealF _add_annuals(const GrpIndex rg, const RealF g_pr, if (!add_seeds && RandUni() <= s->seedling_estab_prob) { /* force addition of new propagules */ - //if regen_ok is swTRUE, pass the g_pr parameter, if regen_ok is False, pass -1 + //if regen_ok is TRUE, pass the g_pr parameter, if regen_ok is False, pass -1 _add_annual_seedprod(sp, (g->regen_ok) ? g_pr : -1.); - forced = swTRUE; + forced = TRUE; } //if regen_ok is T then x = values coming from _get_annual_maxestab, if regen ok is F then @@ -569,7 +569,7 @@ void rgroup_Grow(void) growth1 = s->relseedlingsize * RandUniRange(1, s->max_vegunits); rate1 = growth1 / ndv->relsize; - ndv->killed = swFALSE; + ndv->killed = FALSE; } else @@ -700,7 +700,7 @@ void rgroup_Establish(void) if (Plot.disturbed > 0) { ForEachGroup(rg) - RGroup[rg]->regen_ok = swFALSE; + RGroup[rg]->regen_ok = FALSE; return; /* skip regen for all */ } @@ -710,11 +710,11 @@ void rgroup_Establish(void) if (!g->use_me) continue; - g->regen_ok = swTRUE; /* default */ + g->regen_ok = TRUE; /* default */ if (Globals.currYear < RGroup[rg]->startyr) { - g->regen_ok = swFALSE; + g->regen_ok = FALSE; } else ///if ( g->max_age == 1 ) { @@ -1017,14 +1017,14 @@ void rgroup_DropSpecies(SppIndex sp) IntS i, j; GrpIndex rg; - Bool f = swFALSE; + Bool f = FALSE; rg = Species[sp]->res_grp; ForEachEstSpp2(rg, i) { if (RGroup[rg]->est_spp[i] == sp) { - f = swTRUE; + f = TRUE; break; } } @@ -1054,13 +1054,13 @@ void rgroup_AddSpecies(GrpIndex rg, SppIndex sp) /*------------------------------------------------------*/ Int i; - Bool f = swFALSE; + Bool f = FALSE; ForEachEstSpp2( rg, i) { if (RGroup[rg]->est_spp[i] == sp) { - f = swTRUE; + f = TRUE; break; } } @@ -1109,7 +1109,7 @@ void rgroup_Extirpate(GrpIndex rg) } } - RGroup[rg]->extirpated = swTRUE; + RGroup[rg]->extirpated = TRUE; } diff --git a/ST_stats.c b/ST_stats.c index 9084e319..610b5ffc 100644 --- a/ST_stats.c +++ b/ST_stats.c @@ -134,7 +134,7 @@ static void _make_header_for_soilwat(char *buf, char *header1, char *header2, in (p)->nobs = (v)->nobs; \ } -static Bool firsttime = swTRUE; +static Bool firsttime = TRUE; /***********************************************************/ @@ -154,7 +154,7 @@ void stat_Collect( Int year ) { double bmass; if (firsttime) { - firsttime = swFALSE; + firsttime = FALSE; _init(); } @@ -489,7 +489,7 @@ void stat_Load_Accumulators(int cell, int year) { //loads the accumulators for the cell at the given year if (firsttime) { - firsttime = swFALSE; + firsttime = FALSE; _init(); } IntS age; @@ -551,7 +551,7 @@ void stat_Save_Accumulators(int cell, int year) { //saves the accumulators for the cell at the given year if (firsttime) { - firsttime = swFALSE; + firsttime = FALSE; _init(); } IntS age; diff --git a/sw_src b/sw_src index f2fea1ab..21f9db28 160000 --- a/sw_src +++ b/sw_src @@ -1 +1 @@ -Subproject commit f2fea1abc482a5ef214925e416e70da85fd5e304 +Subproject commit 21f9db287fdbbc3781a49ba7ec64c377667e9ce1 diff --git a/sxw.c b/sxw.c index e5ef9f1a..a6b1d7b6 100644 --- a/sxw.c +++ b/sxw.c @@ -426,7 +426,7 @@ RealF SXW_GetResource( GrpIndex rg) { void SXW_PrintDebug(Bool cleanup) { /*======================================================*/ TimeInt i; - static Bool beenhere = swFALSE; + static Bool beenhere = FALSE; if(cleanup) { debugCleanUp(); @@ -439,7 +439,7 @@ void SXW_PrintDebug(Bool cleanup) { } } if (!beenhere) { - beenhere = swTRUE; + beenhere = TRUE; insertInfo(); insertSXWPhen(); insertSXWProd(); @@ -708,7 +708,7 @@ static void _read_watin(void) { */ FILE *f; int lineno = 0; - Bool found = swFALSE; + Bool found = FALSE; MyFileName = SXW.f_watin; f = OpenFile(MyFileName, "r"); @@ -718,7 +718,7 @@ static void _read_watin(void) { if (++lineno == (eOutput + 2)) { strcpy(_swOutDefName, DirName(SXW.f_watin)); strcat(_swOutDefName, inbuf); - found = swTRUE; + found = TRUE; break; } } @@ -743,7 +743,7 @@ static void _make_arrays(void) { _make_swa_array(); _make_swc_array(); // only make output storage if -o or -i flags - if(storeAllIterations || isPartialSoilwatOutput == swFALSE) + if(storeAllIterations || isPartialSoilwatOutput == FALSE) _make_soil_arrays(); } @@ -803,20 +803,19 @@ static void _make_transp_arrays(void) { static void _make_swa_array(void){ char *fstr = "_make_swa_array()"; - int size = SXW.NPds * SXW.NSoLyrs; - int avg_size; + int size = NVEGTYPES * NVEGTYPES * MAX_DAYS * SXW.NSoLyrs; + int size_sum = NVEGTYPES * MAX_DAYS * SXW.NSoLyrs; - //4 - Grass,Frob,Tree,Shrub - size = NVEGTYPES * NVEGTYPES * SXW.NPds * SXW.NSoLyrs * Globals.runModelIterations; SXW.SWA_master = (RealF *) Mem_Calloc(size, sizeof(RealF), fstr); // 4D SXW.dSWAbulk = (RealF *) Mem_Calloc(size, sizeof(RealF), fstr); // 4D SXW.dSWA_repartitioned = (RealF *) Mem_Calloc(size, sizeof(RealF), fstr); // 4D + SXW.sum_dSWA_repartitioned = (RealF *) Mem_Calloc(size_sum, sizeof(RealF), fstr); //Mem_Set(SXW.SWA_master, 0, SXW.NPds * 4 * SXW.NSoLyrs * sizeof(RealF)); memset(SXW.SWA_master, 0, sizeof(SXW.SWA_master)); Mem_Set(SXW.dSWAbulk, 0, size * sizeof(RealF)); Mem_Set(SXW.dSWA_repartitioned, 0, size * sizeof(RealF)); - //memset(SXW.sum_dSWA_repartitioned, 0, sizeof(SXW.sum_dSWA_repartitioned) * 5 * 20 * 500); + Mem_Set(SXW.sum_dSWA_repartitioned, 0, size_sum * sizeof(RealF)); } static void _make_swc_array(void) { @@ -828,12 +827,8 @@ static void _make_swc_array(void) { char *fstr = "_make_swc_array()"; int size = SXW.NPds * SXW.NSoLyrs * MAX_DAYS; int avg_size; - //int size_3d = 4 * SXW.NPds * SXW.NSoLyrs; SXW.swc = (RealF *) Mem_Calloc(size, sizeof(RealF *), fstr); - - //avg_size = (SXW.NPds * SXW.NSoLyrs * Globals.runModelYears) * 365; - //SXW.swc_avg = (RealF *) Mem_Calloc(avg_size, sizeof(RealF), fstr); } // all memory allocation for avg values are here @@ -870,7 +865,8 @@ static void _make_soil_arrays(void){ Mem_Set(SXW.SWAbulk_tree_avg, 0, avg_size * sizeof(RealF)); Mem_Set(SXW.SWAbulk_forb_avg, 0, avg_size * sizeof(RealF)); - SXW.swc_avg = (RealF *) Mem_Calloc(avg_size, sizeof(RealF), fstr); + SXW_AVG.swc_avg = (RealF *) Mem_Calloc(avg_size, sizeof(RealF), fstr); + Mem_Set(SXW_AVG.swc_avg, 0, avg_size * sizeof(RealF)); SXW_AVG.max_temp_avg = (RealF *) Mem_Calloc(size, sizeof(RealF), fstr); @@ -1111,7 +1107,7 @@ void _print_debuginfo(void) { RealF sum1 = 0.; RealF sum2 = 0.; RealF sum3 = 0.; - static Bool beenhere = swFALSE; + static Bool beenhere = FALSE; char vegProdNames[4][7]; strcpy(vegProdNames[0], "TREE"); strcpy(vegProdNames[1], "SHRUB"); @@ -1122,7 +1118,7 @@ void _print_debuginfo(void) { f = OpenFile(strcat(name, ".output.out"), "a"); if (!beenhere) { - beenhere = swTRUE; + beenhere = TRUE; fprintf(f, "\n------ Roots X Phen Array -------\n"); ForEachGroup(r) { @@ -1358,14 +1354,14 @@ void free_all_sxw_memory( void ) { Mem_Free(SXW.SWAbulk_tree_avg); Mem_Free(SXW.SWAbulk_forb_avg); - //Mem_Free(SXW.sum_dSWA_repartitioned); + Mem_Free(SXW.sum_dSWA_repartitioned); Mem_Free(SXW.SWA_master); Mem_Free(SXW.dSWAbulk); Mem_Free(SXW.dSWA_repartitioned); Mem_Free(SXW.swc); - Mem_Free(SXW.swc_avg); + Mem_Free(SXW_AVG.swc_avg); Mem_Free(SXW_AVG.max_temp_avg); Mem_Free(SXW_AVG.min_temp_avg); diff --git a/sxw.h b/sxw.h index b558676d..fc613f15 100644 --- a/sxw.h +++ b/sxw.h @@ -84,20 +84,9 @@ struct stepwat_st { *dSWAbulk, // 4D array to store actual available SWA *dSWA_repartitioned; // 4D array to store repartioned SWA values - // going to want to change this to Itlp array - RealF sum_dSWA_repartitioned[80][80][366]; // [veg_type][layer][timeperiod] store the sum of dSWA_repartitioned. 3D array - //RealF *sum_dSWA_repartitioned; + RealF *sum_dSWA_repartitioned; RealF transp_SWA[MAX_YEARS][11]; // store the sum of SWA and transp for each year and resource. transp_SWA[year][steppe_resource_group] - int rank_SWPcrits[5]; // array to store the SWP crits in order of lest negative to most negative (used in sxw_resource) - - // used in SW_Output.c for creating column headers - int col_status_dy; - int col_status_wk; - int col_status_mo; - int col_status_yr; - - RealF *swc_avg; }; struct soilwat_average{ @@ -175,7 +164,7 @@ struct soilwat_average{ *wue_mult_tree_avg, *wue_mult_forb_avg; - + RealF *swc_avg; }; #define SXW_NFILES 5 @@ -199,7 +188,7 @@ typedef struct soilwat_average SXW_avg; * veg-prod-type/crit-value/layer/phenology */ //veg_type, new_critical_value, layer, timeperiod -#define Itclp(t,c,l,p) (((t)*SXW.NTrLyrs*SXW.NPds) + ((c)*4) + ((l)*SXW.NPds) + (p)) // c*4 is because there are 4 critical values +#define Itclp(t,c,l,p) (((t)*SXW.NTrLyrs*SXW.NPds) + ((c)*NVEGTYPES) + ((l)*SXW.NPds) + (p)) // c*4 is because there are 4 critical values // for use with avg values // year, layer, timeperiod, avg/std @@ -208,10 +197,10 @@ typedef struct soilwat_average SXW_avg; // for soilwat average and standard deviation // year, timeperiod, choice (avg or std), timeperiod (dy, wk, mo, yr) // difference between p and b is p is current period within period (ie. for day it could be 0 to 364) and b is just timeperiod (0 to 3 where 0 is day and 3 is yr) -#define Iypc(y,p,c,b) (((y)*Globals.runModelYears * SXW.NPds * 4) + ((p)*SXW.NPds * 4) + ((c) * 4) + (b)) +#define Iypc(y,p,c,b) (((y)*Globals.runModelYears * SXW.NPds * NVEGTYPES) + ((p)*SXW.NPds * NVEGTYPES) + ((c) * NVEGTYPES) + (b)) // veg type, layer, timeperiod -#define Ivlp(v,l,p) (((v)*4 * SXW.NTrLyrs * SXW.NPds) + ((l)*SXW.NTrLyrs * SXW.NPds) + ((p)*SXW.NPds)) +#define Ivlp(v,l,p) (((v)*NVEGTYPES * SXW.NTrLyrs * SXW.NPds) + ((l)*SXW.NTrLyrs * SXW.NPds) + ((p)*SXW.NPds)) /* convert 2d layer by period indices to layer/phenology 1D index */ diff --git a/sxw_resource.c b/sxw_resource.c index 840a831b..627d746a 100644 --- a/sxw_resource.c +++ b/sxw_resource.c @@ -325,7 +325,7 @@ static void _SWA_contribution_by_group(RealF use_by_group[]) { { for (l = 0; l < SXW.NSoLyrs; l++) { //printf("%d,%d,%d\n", t,l,p); - use_by_group[g] += (RealF) (_roots_active_rel[Iglp(g, l, p)] * SXW.sum_dSWA_repartitioned[t][l][p]); + use_by_group[g] += (RealF) (_roots_active_rel[Iglp(g, l, p)] * SXW.sum_dSWA_repartitioned[Ivlp(t,l,p)]); //printf("for groupName= %s, layerIndex: %d, month: %d, in swa loop use_by_group[g]= %f \n",RGroup[g]->name,l,p,use_by_group[g]); } } From cbc5c9ffdf76f0c4cb776ee5da4efbc0a33ad5ce Mon Sep 17 00:00:00 2001 From: BrendenBe1 Date: Thu, 1 Feb 2018 16:41:09 -0700 Subject: [PATCH 095/111] Changed struct name Sw_File_Status to SW_File_Status. Fixed an issue where 2 extra columns were being added. --- ST_main.c | 19 +++++++++---------- sw_src | 2 +- 2 files changed, 10 insertions(+), 11 deletions(-) diff --git a/ST_main.c b/ST_main.c index bdaa1e4f..8cb2df66 100644 --- a/ST_main.c +++ b/ST_main.c @@ -36,7 +36,7 @@ extern Bool isPartialSoilwatOutput; extern Bool storeAllIterations; extern SW_VEGPROD SW_VegProd; -extern SW_FILE_STATUS Sw_File_Status; +SW_FILE_STATUS SW_File_Status; /************* External Function Declarations **************/ /***********************************************************/ @@ -176,14 +176,13 @@ int main(int argc, char **argv) { incr = 1; // set values to -1 so SW_Output.c knows first time through - Sw_File_Status.finalValue_dy = -1; - Sw_File_Status.finalValue_wk = -1; - Sw_File_Status.finalValue_mo = -1; - Sw_File_Status.finalValue_yr = -1; + SW_File_Status.finalValue_dy = -1; + SW_File_Status.finalValue_wk = -1; + SW_File_Status.finalValue_mo = -1; + SW_File_Status.finalValue_yr = -1; /* --- Begin a new iteration ------ */ for (iter = 1; iter <= Globals.runModelIterations; iter++) { - //printf("iter: %d\n", iter); if (progfp == stderr) { if (iter % incr == 0) fprintf(progfp, "."); @@ -192,10 +191,10 @@ int main(int argc, char **argv) { } // set these to 0 for use with -i flag (need to create column headers for every iteration file) - Sw_File_Status.col_status_dy = 0; - Sw_File_Status.col_status_wk = 0; - Sw_File_Status.col_status_mo = 0; - Sw_File_Status.col_status_yr = 0; + SW_File_Status.col_status_dy = 0; + SW_File_Status.col_status_wk = 0; + SW_File_Status.col_status_mo = 0; + SW_File_Status.col_status_yr = 0; if (BmassFlags.yearly || MortFlags.yearly) parm_Initialize(iter); diff --git a/sw_src b/sw_src index 21f9db28..6581f073 160000 --- a/sw_src +++ b/sw_src @@ -1 +1 @@ -Subproject commit 21f9db287fdbbc3781a49ba7ec64c377667e9ce1 +Subproject commit 6581f073d55343109b4c9d0c277d628ed074bc19 From ce3b1e1d362491538ffa77f94931a19d9dd13b1d Mon Sep 17 00:00:00 2001 From: BrendenBe1 Date: Fri, 2 Feb 2018 15:36:08 -0700 Subject: [PATCH 096/111] Resolving issues in SOILWAT and changing minor things to work with the SOILWAT changes --- ST_main.c | 6 ------ makefile | 13 ++++--------- sw_src | 2 +- sxw.c | 24 ++++++++++++------------ sxw.h | 8 ++++---- 5 files changed, 21 insertions(+), 32 deletions(-) diff --git a/ST_main.c b/ST_main.c index 8cb2df66..f92bd995 100644 --- a/ST_main.c +++ b/ST_main.c @@ -175,12 +175,6 @@ int main(int argc, char **argv) { if (incr == 0) incr = 1; - // set values to -1 so SW_Output.c knows first time through - SW_File_Status.finalValue_dy = -1; - SW_File_Status.finalValue_wk = -1; - SW_File_Status.finalValue_mo = -1; - SW_File_Status.finalValue_yr = -1; - /* --- Begin a new iteration ------ */ for (iter = 1; iter <= Globals.runModelIterations; iter++) { if (progfp == stderr) { diff --git a/makefile b/makefile index 12621bc6..1e660cea 100644 --- a/makefile +++ b/makefile @@ -46,7 +46,6 @@ SRCS =\ $(Src)/sw_src/SW_Files.c\ $(Src)/sw_src/SW_Model.c\ $(Src)/sw_src/SW_Output.c\ - $(Src)/sw_src/SW_Main_Function.c\ $(Src)/sw_src/SW_Site.c\ $(Src)/sw_src/SW_Sky.c\ $(Src)/sw_src/SW_VegProd.c\ @@ -85,7 +84,6 @@ EXOBJS =\ $(oDir)/sw_src/SW_Files.o\ $(oDir)/sw_src/SW_Model.o\ $(oDir)/sw_src/SW_Output.o\ - $(oDir)/sw_src/SW_Main_Function.o\ $(oDir)/sw_src/SW_Site.o\ $(oDir)/sw_src/SW_Sky.o\ $(oDir)/sw_src/SW_VegProd.o\ @@ -175,7 +173,7 @@ $(oDir)/sxw.o: sxw.c sw_src/generic.h sw_src/filefuncs.h \ sxw_module.h sw_src/SW_Control.h sw_src/SW_Model.h sw_src/SW_Site.h sw_src/SW_SoilWater.h \ sw_src/SW_Files.h sw_src/SW_VegProd.h sw_src/SW_Carbon.h $(CC) $(C_FLAGS) $(incDirs) -c -o $@ $< - + $(oDir)/sxw_sql.o: sxw_sql.c ST_steppe.h \ ST_steppe.h sw_src/SW_Defines.h sxw.h\ sw_src/SW_Times.h sxw_module.h sw_src/SW_Model.h sw_src/SW_Site.h sw_src/SW_SoilWater.h @@ -222,9 +220,6 @@ $(oDir)/sw_src/SW_Output.o: sw_src/SW_Output.c sw_src/generic.h \ sw_src/SW_Weather.h sw_src/SW_Carbon.h $(CC) $(C_FLAGS) $(incDirs) -c -o $@ $< -$(oDir)/sw_src/SW_Main_Function.o: sw_src/SW_Main_Function.c - $(CC) $(C_FLAGS) $(incDirs) -c -o $@ $< - $(oDir)/sw_src/SW_Site.o: sw_src/SW_Site.c sw_src/generic.h sw_src/filefuncs.h \ sw_src/myMemory.h sw_src/SW_Defines.h sw_src/SW_Files.h sw_src/SW_Site.h sw_src/SW_Carbon.h $(CC) $(C_FLAGS) $(incDirs) -c -o $@ $< @@ -318,16 +313,16 @@ $(oDir)/sxw_tester.o: sxw_tester.c sw_src/generic.h \ ST_defines.h ST_structs.h ST_functions.h ST_Globals.h sw_src/SW_Defines.h \ sw_src/SW_Site.h sxw_funcs.h sxw.h sw_src/SW_Times.h sxw_module.h sxw_vars.h $(CC) $(C_FLAGS) $(incDirs) -c -o $@ $< - + $(oDir)/sw_src/SW_VegEstab.o: sw_src/SW_VegEstab.c sw_src/generic.h sw_src/filefuncs.h sw_src/myMemory.h \ sw_src/SW_Defines.h sw_src/SW_Files.h sw_src/SW_Site.h sw_src/SW_Times.h \ sw_src/SW_Model.h sw_src/SW_SoilWater.h sw_src/SW_Weather.h sw_src/SW_VegEstab.h $(CC) $(C_FLAGS) $(incDirs) -c -o $@ $< - + $(oDir)/ST_grid.o: ST_grid.c ST_steppe.h ST_defines.h sw_src/generic.h \ ST_globals.h \ sw_src/myMemory.h ST_globals.h $(CC) $(C_FLAGS) $(incDirs) -c -o $@ $< - + $(oDir)/ST_sql.o: ST_sql.c ST_steppe.h ST_globals.h $(CC) $(C_FLAGS) $(incDirs) -c -o $@ $< diff --git a/sw_src b/sw_src index 6581f073..416c1440 160000 --- a/sw_src +++ b/sw_src @@ -1 +1 @@ -Subproject commit 6581f073d55343109b4c9d0c277d628ed074bc19 +Subproject commit 416c1440461fc1aa072082f3192c1da760cb7b0e diff --git a/sxw.c b/sxw.c index a6b1d7b6..a606622f 100644 --- a/sxw.c +++ b/sxw.c @@ -855,15 +855,15 @@ static void _make_soil_arrays(void){ Mem_Set(SXW.transpGrasses_avg, 0, avg_size * sizeof(RealD)); //avg_size = (SXW.NPds * SXW.NSoLyrs * Globals.runModelYears * 2) * Globals.runModelYears * Globals.runModelIterations; - SXW.SWAbulk_grass_avg = (RealF *) Mem_Calloc(avg_size, sizeof(RealF *), fstr); - SXW.SWAbulk_shrub_avg = (RealF *) Mem_Calloc(avg_size, sizeof(RealF *), fstr); - SXW.SWAbulk_tree_avg = (RealF *) Mem_Calloc(avg_size, sizeof(RealF *), fstr); - SXW.SWAbulk_forb_avg = (RealF *) Mem_Calloc(avg_size, sizeof(RealF *), fstr); + SXW.SWA_grass_avg = (RealF *) Mem_Calloc(avg_size, sizeof(RealF *), fstr); + SXW.SWA_shrub_avg = (RealF *) Mem_Calloc(avg_size, sizeof(RealF *), fstr); + SXW.SWA_tree_avg = (RealF *) Mem_Calloc(avg_size, sizeof(RealF *), fstr); + SXW.SWA_forb_avg = (RealF *) Mem_Calloc(avg_size, sizeof(RealF *), fstr); - Mem_Set(SXW.SWAbulk_grass_avg, 0, avg_size * sizeof(RealF)); - Mem_Set(SXW.SWAbulk_shrub_avg, 0, avg_size * sizeof(RealF)); - Mem_Set(SXW.SWAbulk_tree_avg, 0, avg_size * sizeof(RealF)); - Mem_Set(SXW.SWAbulk_forb_avg, 0, avg_size * sizeof(RealF)); + Mem_Set(SXW.SWA_grass_avg, 0, avg_size * sizeof(RealF)); + Mem_Set(SXW.SWA_shrub_avg, 0, avg_size * sizeof(RealF)); + Mem_Set(SXW.SWA_tree_avg, 0, avg_size * sizeof(RealF)); + Mem_Set(SXW.SWA_forb_avg, 0, avg_size * sizeof(RealF)); SXW_AVG.swc_avg = (RealF *) Mem_Calloc(avg_size, sizeof(RealF), fstr); Mem_Set(SXW_AVG.swc_avg, 0, avg_size * sizeof(RealF)); @@ -1349,10 +1349,10 @@ void free_all_sxw_memory( void ) { Mem_Free(SXW.transpForbs_avg); Mem_Free(SXW.transpGrasses_avg); - Mem_Free(SXW.SWAbulk_grass_avg); - Mem_Free(SXW.SWAbulk_shrub_avg); - Mem_Free(SXW.SWAbulk_tree_avg); - Mem_Free(SXW.SWAbulk_forb_avg); + Mem_Free(SXW.SWA_grass_avg); + Mem_Free(SXW.SWA_shrub_avg); + Mem_Free(SXW.SWA_tree_avg); + Mem_Free(SXW.SWA_forb_avg); Mem_Free(SXW.sum_dSWA_repartitioned); diff --git a/sxw.h b/sxw.h index fc613f15..7c1fb791 100644 --- a/sxw.h +++ b/sxw.h @@ -75,10 +75,10 @@ struct stepwat_st { PPT_snow_melt, PPT_snow_loss; - RealF *SWAbulk_grass_avg, // 2D array to store SWA vals ([days of year][number of max layers]) - *SWAbulk_shrub_avg, - *SWAbulk_tree_avg, - *SWAbulk_forb_avg; + RealF *SWA_grass_avg, // 2D array to store SWA vals ([days of year][number of max layers]) + *SWA_shrub_avg, + *SWA_tree_avg, + *SWA_forb_avg; RealF *SWA_master, // 4D array to store SWA for all veg_types *dSWAbulk, // 4D array to store actual available SWA From 2c8c28d9ee4754dd2953adf81285b4a88375aab8 Mon Sep 17 00:00:00 2001 From: BrendenBe1 Date: Fri, 2 Feb 2018 16:58:15 -0700 Subject: [PATCH 097/111] Removed the line USE_TIMESTEP from the outsetup.in file and removed some unnecessary and redundant code --- ST_main.c | 5 -- sw_src | 2 +- .../Input/sxw/Input/outsetup_v30.in | 80 ++++++++++--------- 3 files changed, 42 insertions(+), 45 deletions(-) diff --git a/ST_main.c b/ST_main.c index f92bd995..6174cd29 100644 --- a/ST_main.c +++ b/ST_main.c @@ -184,11 +184,6 @@ int main(int argc, char **argv) { fprintf(progfp, "%d\n", iter); } - // set these to 0 for use with -i flag (need to create column headers for every iteration file) - SW_File_Status.col_status_dy = 0; - SW_File_Status.col_status_wk = 0; - SW_File_Status.col_status_mo = 0; - SW_File_Status.col_status_yr = 0; if (BmassFlags.yearly || MortFlags.yearly) parm_Initialize(iter); diff --git a/sw_src b/sw_src index 416c1440..f37f08f2 160000 --- a/sw_src +++ b/sw_src @@ -1 +1 @@ -Subproject commit 416c1440461fc1aa072082f3192c1da760cb7b0e +Subproject commit f37f08f2769efbf7e0871481779c25e3e0c8d9a6 diff --git a/testing.sagebrush.master/Stepwat_Inputs/Input/sxw/Input/outsetup_v30.in b/testing.sagebrush.master/Stepwat_Inputs/Input/sxw/Input/outsetup_v30.in index 25689cf0..6b6aa4e2 100644 --- a/testing.sagebrush.master/Stepwat_Inputs/Input/sxw/Input/outsetup_v30.in +++ b/testing.sagebrush.master/Stepwat_Inputs/Input/sxw/Input/outsetup_v30.in @@ -1,10 +1,18 @@ -# Output setup file for STEPWAT +# Output setup file for SOILWAT2 # # Notes: -# Time periods available: DY,YR +# Time periods available: DY,WK,MO,YR # eg, if DY is chosen then 100,200 would mean to use the second hundred days # But if YR is chosen, start and end numbers are in days so only those days # are reported for the yearly average. +# Some keys from older versions (fortran and the c versions mimicking the fortran +# version) are not currently implemented: +# ALLH20, WTHR. +# +# ESTABL only produces yearly output, namely, DOY for each species requested. +# Thus, to minimize typo errors, all flags are ignored except the filename. +# Output is simply the day of the year establishment occurred for each species +# in each year of the model run. Refer to the estabs.in file for more info. # # DEEPSWC produces output only if the deepdrain flag is set in siteparam.in. # @@ -16,49 +24,43 @@ # SUM - sum the variable for each day in the output period # AVG - average the variable over the output period # FIN - output value of final day in the period; soil water variables only. -# Note that SUM and AVG are the same if timeperiod = DY. +# Note that SUM and AVG are the same if timeperiod = dy. # # (01/17/2013) TIMESTEP key indicates which periods you want to output. # You can output all the periods at a time, just one, or however many # you want. To change which periods to output type 'dy' for day, # 'wk' for week, 'mo' for month, and 'yr' for year after TIMESTEP -# in any order. For example: "TIMESTEP mo wk" will output for month and week -# -# (1/9/2018) USE_TIMESTEP: this determines if the TIMESTEP or PERIOD is used to define time periods for each individual output variable. -# If "USE_TIMESTEP = 0", then the time period for each output variable listed below will be determined by the PERIOD column. Note only 1 time period can be listed for each output variable using this option. -# Also note that all of the time periods specified in the PERIOD column must be listed after TIMESTEP, so the correct output files are generated. -# EX: if only using TRANSP and PRECIP and the periods are MO for TRANSP and DY for PRECIP TIMESTEP needs to be "TIMESTEP dy mo" so program knows to create day and month output files -# If "USE_TIMESTEP = 1", then all output variables listed below will be outputted for the time periods specified after TIMESTEP (e.g. dy, yr). Note, this option allows for output variables to be generated for multiple time periods. -# Also note that when using this option, each variable must only be listed once in the Table below. The PERIOD column is ignored with "USE_TIMESTEP = 1". +# in any order. For example: 'TIMESTEP mo wk' will output for month and week # # To generate SWA output, the SWCBULK variable must also be requested. -USE_TIMESTEP 1 -TIMESTEP dy yr +TIMESTEP dy yr # must be lowercase + +# key SUMTYPE PERIOD start end filename_prefix comment + TEMP AVG YR 1 end temp_air /* max., min, average temperature (C) */ + PRECIP SUM YR 1 end precip /* total precip = sum(rain, snow), rain, snow-fall, snowmelt, and snowloss (cm) */ + SOILINFILT SUM YR 1 end infiltration /* water to infiltrate in top soil layer (cm), runoff (cm); (not-intercepted rain)+(snowmelt-runoff) */ + RUNOFF SUM YR 1 end runoff /* runoff/runon (cm): net runoff, runoff from ponded water, runoff from snowmelt, runon of surface water from hypothetical upslope neighbor */ + VWCBULK AVG YR 1 end vwc_bulk /* bulk volumetric soilwater (cm / layer) */ + VWCMATRIC AVG YR 1 end vwc_matric /* matric volumetric soilwater (cm / layer) */ + SWCBULK AVG YR 1 end swc_bulk /* bulk soilwater content (cm / cm layer); swc.l1(today) = swc.l1(yesterday)+inf_soil-lyrdrain.l1-transp.l1-evap_soil.l1; swc.li(today) = swc.li(yesterday)+lyrdrain.l(i-1)-lyrdrain.li-transp.li-evap_soil.li; swc.llast(today) = swc.llast(yesterday)+lyrdrain.l(last-1)-deepswc-transp.llast-evap_soil.llast */ + SWA AVG YR 1 end swa + SWABULK AVG YR 1 end swa_bulk /* DEFUNCT: MAY BE REMOVED IN FUTURE VERSIONS; bulk available soil water (cm/layer) = swc - wilting point */ + SWAMATRIC AVG YR 1 end swa_matric /* DEFUNCT: MAY BE REMOVED IN FUTURE VERSIONS; matric available soil water (cm/layer) = swc - wilting point */ + SWPMATRIC AVG YR 1 end swp_matric /* matric soilwater potential (-bars) */ + SURFACEWATER AVG YR 1 end surface_water /* surface water (cm) */ + TRANSP SUM YR 1 end transp /* transpiration from each soil layer (cm): total, trees, shrubs, forbs, grasses */ + EVAPSOIL SUM YR 1 end evap_soil /* bare-soil evaporation from each soil layer (cm) */ + EVAPSURFACE SUM YR 1 end evap_surface /* evaporation (cm): total, trees, shrubs, forbs, grasses, litter, surface water */ + INTERCEPTION SUM YR 1 end interception /* intercepted rain (cm): total, trees, shrubs, forbs, grasses, and litter (cm) */ + LYRDRAIN SUM YR 1 end percolation /* water percolated from each layer (cm) */ + HYDRED SUM YR 1 end hydred /* hydraulic redistribution from each layer (cm): total, trees, shrubs, forbs, grasses */ + AET SUM YR 1 end aet /* actual evapotr. (cm) */ + PET SUM YR 1 end pet /* potential evaptr (cm) */ + WETDAY SUM YR 1 end wetdays /* days above swc_wet */ + SNOWPACK AVG YR 1 end snowpack /* snowpack water equivalent (cm), snowdepth (cm); since snowpack is already summed, use avg - sum sums the sums = nonsense */ + DEEPSWC SUM YR 1 end deep_drain /* deep drainage into lowest layer (cm) */ + SOILTEMP AVG YR 1 end temp_soil /* soil temperature from each soil layer (in celsius) */ + ESTABL OFF YR 1 end estabs /* yearly establishment results */ + CO2EFFECTS AVG YR 1 end vegetation /* vegetation biomass: biomass (g/m2) for grasses, shrubs, trees, forbs, and total; live biomass (g/m2) fgrasses, shrubs, trees, forbs, and total; biomass CO2-effect (multiplier) for grasses, shrubs, trees, and forbs; WUE CO2-effect (multiplier) for grasses, shrubs, trees, and forbs -# key SUMTYPE PERIOD start end filename_prefix -TRANSP SUM YR 1 end transp -PRECIP SUM YR 1 end precip -TEMP AVG YR 1 end temp -AET SUM YR 1 end aet -SWCBULK FIN YR 1 end swc_bulk -SWA AVG YR 1 end swa -VWCBULK avg YR 1 end vwc_bulk -VWCMATRIC avg YR 1 end vwc_matric -SWPMATRIC avg YR 1 end swp_matric -SWABULK AVG YR 1 end swa_bulk -SWAMATRIC avg YR 1 end swa_matric -SURFACEWATER avg YR 1 end surface_water -RUNOFF sum YR 1 end runoff -EVAPSOIL sum YR 1 end evap_soil -EVAPSURFACE sum YR 1 end evap_surface -INTERCEPTION sum YR 1 end interception -SOILINFILT sum YR 1 end infiltration -LYRDRAIN sum YR 1 end percolation -HYDRED sum YR 1 end hydred -PET sum YR 1 end pet -WETDAY sum YR 1 end wetdays -SNOWPACK avg YR 1 end snowpack -DEEPSWC sum YR 1 end deep_drain -SOILTEMP avg YR 1 end temp_soil -CO2EFFECTS avg YR 1 end vegetation /* vegetation biomass: biomass (g/m2) for grasses, shrubs, trees, forbs, and total; live biomass (g/m2) fgrasses, shrubs, trees, forbs, and total; biomass CO2-effect (multiplier) for grasses, shrubs, trees, and forbs; WUE CO2-effect (multiplier) for grasses, shrubs, trees, and forbs From 5d6ad4c3cfd0fec188da62e374afe3495522da45 Mon Sep 17 00:00:00 2001 From: BrendenBe1 Date: Tue, 6 Feb 2018 12:40:29 -0700 Subject: [PATCH 098/111] Resolving issues #73 and #78. --- ST_main.c | 4 +--- ST_resgroups.c | 57 +++++++++++++++++++++++++++++++------------------- sxw.c | 4 ++-- sxw_funcs.h | 2 +- 4 files changed, 39 insertions(+), 28 deletions(-) diff --git a/ST_main.c b/ST_main.c index 6174cd29..7ca6baa8 100644 --- a/ST_main.c +++ b/ST_main.c @@ -192,9 +192,6 @@ int main(int argc, char **argv) { RandSeed(Globals.randseed); Globals.currIter = iter; - memset(SXW.transp_SWA, 0, sizeof(SXW.transp_SWA)); // set transp_SWA to 0; needs to be reset each iteration - //memset(SXW.sum_dSWA_repartitioned, 0, sizeof(SXW.sum_dSWA_repartitioned)); - /* ------ Begin running the model ------ */ for (year = 1; year <= Globals.runModelYears; year++){ Globals.currYear = year; @@ -333,6 +330,7 @@ void Plot_Initialize(void) { RGroup[rg]->yrs_neg_pr = 0; RGroup[rg]->extirpated = FALSE; } + memset(SXW.transp_SWA, 0, sizeof(SXW.transp_SWA)); // set transp_SWA to 0; needs to be reset each iteration if (UseSoilwat) SXW_InitPlot(); diff --git a/ST_resgroups.c b/ST_resgroups.c index 2d425e51..e00e6a69 100644 --- a/ST_resgroups.c +++ b/ST_resgroups.c @@ -129,7 +129,7 @@ void rgroup_PartResources(void) else { g->res_required = RGroup_GetBiomass(rg); - g->res_avail = SXW_GetResource(rg); //1.0; + g->res_avail = SXW_GetTranspiration(rg); //1.0; //PR limit can be really high see mort no_resource I limit to the groups estab indiv because that is what we can kill. //This was at 10 but ten might be to low or high in some cases. if(!ZRO(g->res_avail) && g->res_required / g->res_avail > g->estabs) @@ -146,7 +146,7 @@ void rgroup_PartResources(void) } //KAP:Previously, a seperate set of code was used to determine resource availability for annual species //Now, resource paritioning for annuals occurs in the same way as for perennials, by getting the RGroup Biomass - //and the resource_cur from SXW_GetResource + //and the resource_cur from SXW_GetTranspiration //Annuals seem to have a artificial limit of 20. We do Annuals here differently if(g->max_age == 1) { @@ -175,8 +175,8 @@ void rgroup_PartResources(void) /*these functions are not used if using SOILWAT, extra resource partitioning does not occur when running SOILWAT*/ - // _res_part_extra(do_base, xtra_base, size_base); - //_res_part_extra(do_extra, xtra_obase, size_obase); + _res_part_extra(do_base, xtra_base, size_base); + _res_part_extra(do_extra, xtra_obase, size_obase); /* reset annuals' "TRUE" relative size here */ //KAP: formely, this call established annual species. We have moved annual establishment to the Rgroup_Establish function, @@ -397,8 +397,7 @@ static void _res_part_extra(Bool isextra, RealF extra, RealF size[]) void rgroup_ResPartIndiv(void) { /*======================================================*/ - /* PURPOSE */ - /* The PR value used in the growth loop is now at the + /* The PR value used in the growth loop is now at the individual level rather than the group level, so the resource availability for the group is divided between individuals of the group, largest to smallest. Species @@ -412,6 +411,8 @@ void rgroup_ResPartIndiv(void) GrpIndex rg; GroupType *g; /* shorthand for RGroup[rg] */ + SppIndex sp; + Int j; IndivType **indivs, /* dynamic array of indivs in RGroup[rg] */ *ndv; /* shorthand for the current indiv */ IntS numindvs, n; @@ -425,32 +426,46 @@ void rgroup_ResPartIndiv(void) if (!g->est_count) continue; - numindvs = 0; // setting to 0 so no problems passing into RGroup_GetIndivs function /* --- allocate the temporary group-oriented arrays */ - indivs = RGroup_GetIndivs(rg, SORT_D, &numindvs); // SORT_D = sort in descending order + indivs = RGroup_GetIndivs(rg, SORT_D, &numindvs); /* ---- assign indivs' availability, not including extra ---- */ /* resource <= 1.0 is for basic growth, >= extra */ /* amount of extra, if any, is kept in g->res_extra */ /* base_rem = fmin(1, g->res_avail); */ base_rem = g->res_avail; - for (n = 0; n < numindvs; n++) + + ForEachEstSpp(sp, rg, j) { - ndv = indivs[n]; - ndv->res_required = (ndv->relsize / g->max_spp) / g->estabs; - if (GT(g->pr, 1.)) + for (n = 0; n < numindvs; n++) { + ndv = indivs[n]; + + ndv->res_required = (ndv->relsize * Species [sp]->mature_biomass); + //printf("ndv->res_required = %f\n, Species = %s \n", Species[sp]->name, ndv->res_required); + + if (GT(g->pr, 1.)) + { ndv->res_avail = fmin(ndv->res_required, base_rem); + //printf("ndv->res_avail_pr>1 = %f\n", ndv->res_avail); + base_rem = fmax(base_rem - ndv->res_avail, 0.); - } - else - { + //printf("base_rem pr>1 = %f\n", base_rem); + + } + + else + { ndv->res_avail = ndv->grp_res_prop * g->res_avail; + //printf("ndv->res_avail pr <1 = %f\n", ndv->res_avail); + + } } } base_rem += fmin(0, g->res_avail - 1.0); + //printf("base_rem end = %f\n", base_rem); /* --- compute PR, but on the way, assign extra resource */ for (n = 0; n < numindvs; n++) @@ -460,23 +475,21 @@ void rgroup_ResPartIndiv(void) if (g->use_extra_res) { /* polish off any remaining resource not allocated to extra */ - ndv->res_avail += - ZRO(base_rem) ? 0. : ndv->grp_res_prop * base_rem; + ndv->res_avail += ZRO(base_rem) ? 0. : ndv->grp_res_prop * base_rem; /* extra resource gets assigned here if applicable */ if (GT(g->res_extra, 0.)) { x = 1. - ndv->relsize; - ndv->res_extra = (1. - x) * ndv->grp_res_prop - * g->res_extra; + ndv->res_extra = (1. - x) * ndv->grp_res_prop* g->res_extra; ndv->res_avail += x * ndv->grp_res_prop * g->res_extra; } } /* ---- at last! compute the PR value, or dflt to 100 */ - ndv->pr = - GT(ndv->res_avail, 0.) ? - ndv->res_required / ndv->res_avail : 100.; + ndv->pr = GT(ndv->res_avail, 0.) ? ndv->res_required / ndv->res_avail : 100.; + //printf("ndv->pr = %f\n", ndv->pr); + } Mem_Free(indivs); diff --git a/sxw.c b/sxw.c index a606622f..ca93b0d6 100644 --- a/sxw.c +++ b/sxw.c @@ -415,11 +415,11 @@ KAP 7/20/2016 //return pr > 10 ? 10 : pr; } -RealF SXW_GetResource( GrpIndex rg) { +RealF SXW_GetTranspiration( GrpIndex rg) { /*======================================================*/ /* see _sxw_update_resource() for _resource_cur[] */ - //printf("SXW_GetResource _resource_cur[%d] = %.5f \n", rg, _resource_cur[rg]); + //printf("SXW_GetTranspiration _resource_cur[%d] = %.5f \n", rg, _resource_cur[rg]); return _resource_cur[rg]; } diff --git a/sxw_funcs.h b/sxw_funcs.h index b4a0e782..ac84b4ae 100644 --- a/sxw_funcs.h +++ b/sxw_funcs.h @@ -18,7 +18,7 @@ #include "sxw.h" RealF SXW_GetPR( GrpIndex rg) ; -RealF SXW_GetResource( GrpIndex rg); +RealF SXW_GetTranspiration( GrpIndex rg); RealF SXW_ResourceAvailable (void); From 29502a0c9769223cf1b61ff04861b2d3438a79e0 Mon Sep 17 00:00:00 2001 From: kpalmqui Date: Tue, 6 Feb 2018 15:00:48 -0700 Subject: [PATCH 099/111] removed extra functions added back in accidentally MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This function (_res_part_extra) is already called above on lines 123-124 and were accidentally duplicated here. We don’t need to call it twice. --- ST_resgroups.c | 5 ----- 1 file changed, 5 deletions(-) diff --git a/ST_resgroups.c b/ST_resgroups.c index e00e6a69..dfc8d6bd 100644 --- a/ST_resgroups.c +++ b/ST_resgroups.c @@ -173,11 +173,6 @@ void rgroup_PartResources(void) if (noplants) return; - /*these functions are not used if using SOILWAT, - extra resource partitioning does not occur when running SOILWAT*/ - _res_part_extra(do_base, xtra_base, size_base); - _res_part_extra(do_extra, xtra_obase, size_obase); - /* reset annuals' "TRUE" relative size here */ //KAP: formely, this call established annual species. We have moved annual establishment to the Rgroup_Establish function, //where all other resource groups establish (e.g. perennials). This function is no longer required. From cc63437141b80de7b32ca76d776fe96f2a16fe9f Mon Sep 17 00:00:00 2001 From: BrendenBe1 Date: Thu, 8 Feb 2018 12:37:14 -0700 Subject: [PATCH 100/111] Resolving SOILWAT issue #160 and working on SOILWAT issue #157. For SOILWAT issue #157 SWA no longer requires SWCBULK to run SOILWAT or STEPWAT and is not broken if SWCBULK is set to another sumtype other than AVG. --- sw_src | 2 +- .../Stepwat_Inputs/Input/sxw/Input/outsetup_v30.in | 2 -- 2 files changed, 1 insertion(+), 3 deletions(-) diff --git a/sw_src b/sw_src index f37f08f2..3318f656 160000 --- a/sw_src +++ b/sw_src @@ -1 +1 @@ -Subproject commit f37f08f2769efbf7e0871481779c25e3e0c8d9a6 +Subproject commit 3318f65604a13e67ad9aa1e01c200ea123817d19 diff --git a/testing.sagebrush.master/Stepwat_Inputs/Input/sxw/Input/outsetup_v30.in b/testing.sagebrush.master/Stepwat_Inputs/Input/sxw/Input/outsetup_v30.in index 6b6aa4e2..ffc5c23b 100644 --- a/testing.sagebrush.master/Stepwat_Inputs/Input/sxw/Input/outsetup_v30.in +++ b/testing.sagebrush.master/Stepwat_Inputs/Input/sxw/Input/outsetup_v30.in @@ -31,8 +31,6 @@ # you want. To change which periods to output type 'dy' for day, # 'wk' for week, 'mo' for month, and 'yr' for year after TIMESTEP # in any order. For example: 'TIMESTEP mo wk' will output for month and week -# -# To generate SWA output, the SWCBULK variable must also be requested. TIMESTEP dy yr # must be lowercase From f97bef6a3d35b287c73c6cf746779e9ab0324393 Mon Sep 17 00:00:00 2001 From: BrendenBe1 Date: Fri, 9 Feb 2018 16:50:40 -0700 Subject: [PATCH 101/111] Working on SOILWAT issue #157 with moving the location of the SWA calculations. The Values need testing under the STEPWAT flag and a few variables in the structure need altering still. --- sw_src | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sw_src b/sw_src index 3318f656..80b54a23 160000 --- a/sw_src +++ b/sw_src @@ -1 +1 @@ -Subproject commit 3318f65604a13e67ad9aa1e01c200ea123817d19 +Subproject commit 80b54a23593d23e46e66494f7d5f580636d0c044 From b1af89ebbb6d3b6ab99c3f5b41ccc187db3d6683 Mon Sep 17 00:00:00 2001 From: BrendenBe1 Date: Tue, 13 Feb 2018 12:12:13 -0700 Subject: [PATCH 102/111] Removing struct variables and memory allocation that is no longer needed due to moving the SWA calculations to SOILWAT. --- sw_src | 2 +- sxw.c | 12 ------------ sxw.h | 8 ++------ 3 files changed, 3 insertions(+), 19 deletions(-) diff --git a/sw_src b/sw_src index 80b54a23..ceca10af 160000 --- a/sw_src +++ b/sw_src @@ -1 +1 @@ -Subproject commit 80b54a23593d23e46e66494f7d5f580636d0c044 +Subproject commit ceca10afe35f5f61dee84ad6d82fee6193bc4178 diff --git a/sxw.c b/sxw.c index ca93b0d6..6f23a18d 100644 --- a/sxw.c +++ b/sxw.c @@ -803,18 +803,10 @@ static void _make_transp_arrays(void) { static void _make_swa_array(void){ char *fstr = "_make_swa_array()"; - int size = NVEGTYPES * NVEGTYPES * MAX_DAYS * SXW.NSoLyrs; int size_sum = NVEGTYPES * MAX_DAYS * SXW.NSoLyrs; - SXW.SWA_master = (RealF *) Mem_Calloc(size, sizeof(RealF), fstr); // 4D - SXW.dSWAbulk = (RealF *) Mem_Calloc(size, sizeof(RealF), fstr); // 4D - SXW.dSWA_repartitioned = (RealF *) Mem_Calloc(size, sizeof(RealF), fstr); // 4D SXW.sum_dSWA_repartitioned = (RealF *) Mem_Calloc(size_sum, sizeof(RealF), fstr); - //Mem_Set(SXW.SWA_master, 0, SXW.NPds * 4 * SXW.NSoLyrs * sizeof(RealF)); - memset(SXW.SWA_master, 0, sizeof(SXW.SWA_master)); - Mem_Set(SXW.dSWAbulk, 0, size * sizeof(RealF)); - Mem_Set(SXW.dSWA_repartitioned, 0, size * sizeof(RealF)); Mem_Set(SXW.sum_dSWA_repartitioned, 0, size_sum * sizeof(RealF)); } @@ -1356,10 +1348,6 @@ void free_all_sxw_memory( void ) { Mem_Free(SXW.sum_dSWA_repartitioned); - Mem_Free(SXW.SWA_master); - Mem_Free(SXW.dSWAbulk); - Mem_Free(SXW.dSWA_repartitioned); - Mem_Free(SXW.swc); Mem_Free(SXW_AVG.swc_avg); diff --git a/sxw.h b/sxw.h index 7c1fb791..b73e84d8 100644 --- a/sxw.h +++ b/sxw.h @@ -66,8 +66,8 @@ struct stepwat_st { RealD surfaceTemp; /* soilwat's surfaceTemp */ // PPT variables - int yearInterval; // keep track of years - int curMonth; + int yearInterval, // keep track of years + curMonth; RealF PPT_sum, PPT_rain, @@ -80,10 +80,6 @@ struct stepwat_st { *SWA_tree_avg, *SWA_forb_avg; - RealF *SWA_master, // 4D array to store SWA for all veg_types - *dSWAbulk, // 4D array to store actual available SWA - *dSWA_repartitioned; // 4D array to store repartioned SWA values - RealF *sum_dSWA_repartitioned; RealF transp_SWA[MAX_YEARS][11]; // store the sum of SWA and transp for each year and resource. transp_SWA[year][steppe_resource_group] From 0b8c3cd6e0ea28297e8b149bad75348e1ad7d7e3 Mon Sep 17 00:00:00 2001 From: kpalmqui Date: Thu, 22 Feb 2018 14:18:55 -0700 Subject: [PATCH 103/111] provided comments for SWA issue#152 Updated comment on what SWA represents --- .../Stepwat_Inputs/Input/sxw/Input/outsetup_v30.in | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/testing.sagebrush.master/Stepwat_Inputs/Input/sxw/Input/outsetup_v30.in b/testing.sagebrush.master/Stepwat_Inputs/Input/sxw/Input/outsetup_v30.in index ffc5c23b..6a383045 100644 --- a/testing.sagebrush.master/Stepwat_Inputs/Input/sxw/Input/outsetup_v30.in +++ b/testing.sagebrush.master/Stepwat_Inputs/Input/sxw/Input/outsetup_v30.in @@ -42,7 +42,7 @@ TIMESTEP dy yr # must be lowercase VWCBULK AVG YR 1 end vwc_bulk /* bulk volumetric soilwater (cm / layer) */ VWCMATRIC AVG YR 1 end vwc_matric /* matric volumetric soilwater (cm / layer) */ SWCBULK AVG YR 1 end swc_bulk /* bulk soilwater content (cm / cm layer); swc.l1(today) = swc.l1(yesterday)+inf_soil-lyrdrain.l1-transp.l1-evap_soil.l1; swc.li(today) = swc.li(yesterday)+lyrdrain.l(i-1)-lyrdrain.li-transp.li-evap_soil.li; swc.llast(today) = swc.llast(yesterday)+lyrdrain.l(last-1)-deepswc-transp.llast-evap_soil.llast */ - SWA AVG YR 1 end swa + SWA AVG YR 1 end swa /* plant available soil water (cm / layer): trees, shrubs, forbs, grasses */ SWABULK AVG YR 1 end swa_bulk /* DEFUNCT: MAY BE REMOVED IN FUTURE VERSIONS; bulk available soil water (cm/layer) = swc - wilting point */ SWAMATRIC AVG YR 1 end swa_matric /* DEFUNCT: MAY BE REMOVED IN FUTURE VERSIONS; matric available soil water (cm/layer) = swc - wilting point */ SWPMATRIC AVG YR 1 end swp_matric /* matric soilwater potential (-bars) */ From 8df482a8d3c951dc952b68f960ebe04ee243964d Mon Sep 17 00:00:00 2001 From: BrendenBe1 Date: Tue, 13 Mar 2018 16:36:11 -0700 Subject: [PATCH 104/111] Resolving issue #87. Added extra index to the avg variables to keep timeperiods seperate. --- sw_src | 2 +- sxw.c | 4 ++-- sxw.h | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/sw_src b/sw_src index ceca10af..8fb8cf61 160000 --- a/sw_src +++ b/sw_src @@ -1 +1 @@ -Subproject commit ceca10afe35f5f61dee84ad6d82fee6193bc4178 +Subproject commit 8fb8cf611eb4e564fd84e9a74b8e3bb942e34890 diff --git a/sxw.c b/sxw.c index 6f23a18d..2d8aa9ec 100644 --- a/sxw.c +++ b/sxw.c @@ -832,7 +832,8 @@ static void _make_soil_arrays(void){ size = (SXW.NPds * Globals.runModelYears * 2 * NVEGTYPES) * Globals.runModelYears; layer_size = (SXW.NPds * SXW.NSoLyrs * Globals.runModelYears * 2 * NVEGTYPES) * Globals.runModelYears; - avg_size = (SXW.NPds * SXW.NSoLyrs * Globals.runModelYears * 2) * Globals.runModelYears; + avg_size = (4 * SXW.NSoLyrs * Globals.runModelYears * SXW.NPds * 2) * Globals.runModelYears; + SXW.transpTotal_avg = (RealD *) Mem_Calloc(avg_size, sizeof(RealD), fstr); SXW.transpTrees_avg = (RealD *) Mem_Calloc(avg_size, sizeof(RealD), fstr); SXW.transpShrubs_avg = (RealD *) Mem_Calloc(avg_size, sizeof(RealD), fstr); @@ -846,7 +847,6 @@ static void _make_soil_arrays(void){ Mem_Set(SXW.transpForbs_avg, 0, avg_size * sizeof(RealD)); Mem_Set(SXW.transpGrasses_avg, 0, avg_size * sizeof(RealD)); - //avg_size = (SXW.NPds * SXW.NSoLyrs * Globals.runModelYears * 2) * Globals.runModelYears * Globals.runModelIterations; SXW.SWA_grass_avg = (RealF *) Mem_Calloc(avg_size, sizeof(RealF *), fstr); SXW.SWA_shrub_avg = (RealF *) Mem_Calloc(avg_size, sizeof(RealF *), fstr); SXW.SWA_tree_avg = (RealF *) Mem_Calloc(avg_size, sizeof(RealF *), fstr); diff --git a/sxw.h b/sxw.h index b73e84d8..3c4be7c9 100644 --- a/sxw.h +++ b/sxw.h @@ -188,7 +188,7 @@ typedef struct soilwat_average SXW_avg; // for use with avg values // year, layer, timeperiod, avg/std -#define Iylp(y,l,p,x) (((y)*Globals.runModelYears * SXW.NTrLyrs * SXW.NPds * 2) + ((l)*SXW.NTrLyrs * SXW.NPds * 2) + ((p)*SXW.NPds * 2) + ((x)*2)) +#define Iylp(y,l,p,pd,x) (((y)*Globals.runModelYears * SXW.NTrLyrs * 4 * SXW.NPds * 2) + ((l)*SXW.NTrLyrs * 4 * SXW.NPds * 2) + ((p) * 4 * SXW.NPds * 2) + ((pd)*4*2) + ((x) * 2)) // for soilwat average and standard deviation // year, timeperiod, choice (avg or std), timeperiod (dy, wk, mo, yr) From 46db1c8aa935ef612f2070dc0953f5d86fc57728 Mon Sep 17 00:00:00 2001 From: BrendenBe1 Date: Thu, 15 Mar 2018 16:17:31 -0700 Subject: [PATCH 105/111] Dealing with some compiler warnings --- ST_main.c | 4 +--- sw_src | 2 +- sxw.c | 1 - sxw_resource.c | 4 ++-- 4 files changed, 4 insertions(+), 7 deletions(-) diff --git a/ST_main.c b/ST_main.c index 7ca6baa8..011469ce 100644 --- a/ST_main.c +++ b/ST_main.c @@ -142,10 +142,8 @@ Bool UseProgressBar; /******************** Begin Model Code *********************/ /***********************************************************/ int main(int argc, char **argv) { - IntS year, iter, incr, g, s; - IndivType *i; + IntS year, iter, incr; Bool killedany; - int k; logged = FALSE; atexit(check_log); diff --git a/sw_src b/sw_src index 8fb8cf61..e048d00d 160000 --- a/sw_src +++ b/sw_src @@ -1 +1 @@ -Subproject commit 8fb8cf611eb4e564fd84e9a74b8e3bb942e34890 +Subproject commit e048d00d33e9ec03d11144a84fded49093fae947 diff --git a/sxw.c b/sxw.c index 2d8aa9ec..2e0d8740 100644 --- a/sxw.c +++ b/sxw.c @@ -818,7 +818,6 @@ static void _make_swc_array(void) { */ char *fstr = "_make_swc_array()"; int size = SXW.NPds * SXW.NSoLyrs * MAX_DAYS; - int avg_size; SXW.swc = (RealF *) Mem_Calloc(size, sizeof(RealF *), fstr); } diff --git a/sxw_resource.c b/sxw_resource.c index 627d746a..a963ff94 100644 --- a/sxw_resource.c +++ b/sxw_resource.c @@ -124,13 +124,13 @@ void _sxw_update_resource(void) { RealF sizes[MAX_RGROUPS] = {0.}; GrpIndex g; - SppIndex sp; - int i; int currentYear; if(SW_Model.year == 0) currentYear = 0; else currentYear = SW_Model.year - SW_Model.startyr; #ifdef SXW_BYMAXSIZE + int i; + SppIndex sp; ForEachGroup(g) { sizes[g] = 0.; if (RGroup[g]->regen_ok) { From fe3a1324c5ebfd1cda65d1e948604d9bd49ac7df Mon Sep 17 00:00:00 2001 From: BrendenBe1 Date: Fri, 16 Mar 2018 12:46:49 -0700 Subject: [PATCH 106/111] Added average and standard deviation for precip values (ppt, rain, snow). --- sw_src | 2 +- sxw.c | 16 ++++++++++++++-- sxw.h | 3 +++ 3 files changed, 18 insertions(+), 3 deletions(-) diff --git a/sw_src b/sw_src index e048d00d..da230421 160000 --- a/sw_src +++ b/sw_src @@ -1 +1 @@ -Subproject commit e048d00d33e9ec03d11144a84fded49093fae947 +Subproject commit da2304211368411888a75261f7f7bd25fbf2c7e6 diff --git a/sxw.c b/sxw.c index 2e0d8740..095ae8b9 100644 --- a/sxw.c +++ b/sxw.c @@ -866,10 +866,18 @@ static void _make_soil_arrays(void){ SXW_AVG.surfaceTemp_avg = (RealD *) Mem_Calloc(size, sizeof(RealD), fstr); SXW_AVG.aet_avg = (RealD *) Mem_Calloc(size, sizeof(RealD), fstr); - SXW_AVG.val_snowloss_avg = (RealD *) Mem_Calloc(size, sizeof(RealD), fstr); - SXW_AVG.val_snowmelt_avg = (RealD *) Mem_Calloc(size, sizeof(RealD), fstr); Mem_Set(SXW_AVG.aet_avg, 0, size * sizeof(RealF)); + + SXW_AVG.ppt_avg = (RealF *) Mem_Calloc(size, sizeof(RealF), fstr); + SXW_AVG.val_rain_avg = (RealF *) Mem_Calloc(size, sizeof(RealF), fstr); + SXW_AVG.val_snow_avg = (RealF *) Mem_Calloc(size, sizeof(RealF), fstr); + SXW_AVG.val_snowloss_avg = (RealF *) Mem_Calloc(size, sizeof(RealF), fstr); + SXW_AVG.val_snowmelt_avg = (RealF *) Mem_Calloc(size, sizeof(RealF), fstr); + + Mem_Set(SXW_AVG.ppt_avg, 0, size * sizeof(RealF)); + Mem_Set(SXW_AVG.val_rain_avg, 0, size * sizeof(RealF)); + Mem_Set(SXW_AVG.val_snow_avg, 0, size * sizeof(RealF)); Mem_Set(SXW_AVG.val_snowloss_avg, 0, size * sizeof(RealF)); Mem_Set(SXW_AVG.val_snowmelt_avg, 0, size * sizeof(RealF)); @@ -1356,6 +1364,10 @@ void free_all_sxw_memory( void ) { Mem_Free(SXW_AVG.surfaceTemp_avg); Mem_Free(SXW_AVG.aet_avg); + + Mem_Free(SXW_AVG.ppt_avg); + Mem_Free(SXW_AVG.val_rain_avg); + Mem_Free(SXW_AVG.val_snow_avg); Mem_Free(SXW_AVG.val_snowmelt_avg); Mem_Free(SXW_AVG.val_snowloss_avg); diff --git a/sxw.h b/sxw.h index 3c4be7c9..223a68e1 100644 --- a/sxw.h +++ b/sxw.h @@ -132,6 +132,9 @@ struct soilwat_average{ *min_temp_avg, *avg_temp_avg, *aet_avg, + *ppt_avg, + *val_rain_avg, + *val_snow_avg, *val_snowmelt_avg, *val_snowloss_avg; From e4a248086ab706b01ae841d6a8c76b8883044eb2 Mon Sep 17 00:00:00 2001 From: BrendenBe1 Date: Tue, 27 Mar 2018 14:37:32 -0700 Subject: [PATCH 107/111] Resolving issue #98, First entry in yearly output files is no longer 0. Also added call to closeFile function and fixed some compiler warnings. --- ST_main.c | 3 ++- sw_src | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/ST_main.c b/ST_main.c index 011469ce..166e1dea 100644 --- a/ST_main.c +++ b/ST_main.c @@ -30,6 +30,7 @@ #include "sxw_funcs.h" #include "sxw.h" #include "sw_src/SW_Output.h" + #include "sw_src/rands.h" extern SXW_t SXW; #endif @@ -256,7 +257,7 @@ int main(int argc, char **argv) { SXW_PrintDebug(1); } #endif - + SW_OUT_close_files(); free_all_sxw_memory(); printf("\nend program\n"); fprintf(progfp, "\n"); diff --git a/sw_src b/sw_src index da230421..1fe6d1ea 160000 --- a/sw_src +++ b/sw_src @@ -1 +1 @@ -Subproject commit da2304211368411888a75261f7f7bd25fbf2c7e6 +Subproject commit 1fe6d1eac5e79715286fbc4ab3960a88da71be53 From 23adcf8a7906918316018b49655cccbdf8715b38 Mon Sep 17 00:00:00 2001 From: BrendenBe1 Date: Thu, 29 Mar 2018 16:24:13 -0700 Subject: [PATCH 108/111] Dealing with compiler warnings. Down to 11 warnings originating in ST_params.c and ST_grid.c --- .gitmodules | 2 +- ST_grid.c | 2 +- ST_mortality.c | 1 + ST_resgroups.c | 5 ++--- ST_species.c | 2 +- ST_stats.c | 1 - sw_src | 2 +- sxw.c | 3 +-- sxw.h | 1 + 9 files changed, 9 insertions(+), 10 deletions(-) diff --git a/.gitmodules b/.gitmodules index fee8063d..a14cc46e 100644 --- a/.gitmodules +++ b/.gitmodules @@ -1,5 +1,5 @@ [submodule "sw_src"] path = sw_src url = https://github.com/Burke-Lauenroth-Lab/SOILWAT2.git - branch = master + branch = soilwat_save_output ignore = dirty diff --git a/ST_grid.c b/ST_grid.c index 7368eaea..8ef16e82 100644 --- a/ST_grid.c +++ b/ST_grid.c @@ -240,7 +240,7 @@ void stat_Init_Accumulators(void); //functions from sxw.c //void free_sxw_memory( void ); -void free_all_sxw_memory(void); +//void free_all_sxw_memory(void); void load_sxw_memory(RealD * grid_roots_max, RealD* grid_rootsXphen, RealD* grid_roots_active, RealD* grid_roots_active_rel, RealD* grid_roots_active_sum, RealD* grid_phen, RealD* grid_prod_bmass, diff --git a/ST_mortality.c b/ST_mortality.c index a0de4b8f..29e23c26 100644 --- a/ST_mortality.c +++ b/ST_mortality.c @@ -21,6 +21,7 @@ #include #include +#include "sw_src/filefuncs.h" #include "generic.h" #include "rands.h" #include "myMemory.h" diff --git a/ST_resgroups.c b/ST_resgroups.c index dfc8d6bd..f60f34f0 100644 --- a/ST_resgroups.c +++ b/ST_resgroups.c @@ -25,6 +25,7 @@ #include "rands.h" #include "generic.h" +#include "sw_src/filefuncs.h" #include "ST_functions.h" #include "sxw_funcs.h" extern Bool UseSoilwat; @@ -79,7 +80,6 @@ void rgroup_PartResources(void) /*------------------------------------------------------*/ GrpIndex rg; - SppIndex sp; RealF resource, /* amt of "resource" == 1 when ppt is avg */ xtra_base = 0., /* pooled extra resource up to 1.0 */ xtra_obase = 0., /* pooled resource > 1.0 */ @@ -88,10 +88,9 @@ void rgroup_PartResources(void) Bool noplants = TRUE; const Bool do_base = FALSE, /* monikers for _res_part_extra() */ - do_extra = TRUE, add_seeds = TRUE, /* monikers for pass 1 & 2 _add_annuals() */ + do_extra = TRUE, /* monikers for pass 1 & 2 _add_annuals() */ no_seeds = FALSE; GroupType *g; /* shorthand for RGroup[rg] */ - int i; /*----------------------------------------------------*/ diff --git a/ST_species.c b/ST_species.c index b9e08a8b..3884442b 100644 --- a/ST_species.c +++ b/ST_species.c @@ -20,6 +20,7 @@ #include #include "ST_steppe.h" #include "ST_globals.h" +#include "sw_src/filefuncs.h" #include "myMemory.h" #include "rands.h" @@ -648,4 +649,3 @@ void Species_SetMemoryRefs( void) } #endif - diff --git a/ST_stats.c b/ST_stats.c index 610b5ffc..65226cb4 100644 --- a/ST_stats.c +++ b/ST_stats.c @@ -114,7 +114,6 @@ static RealF _get_gridcell_avg( struct accumulators_grid_cell_st *p); static RealF _get_gridcell_std( struct accumulators_grid_cell_st *p); static void _make_header( char *buf); static void _make_header_with_std( char *buf); -static void _make_header_for_soilwat(char *buf, char *header1, char *header2, int colLength); /* I'm making this a macro because it gets called a lot, but /* note that the syntax checker is obviated, so make sure diff --git a/sw_src b/sw_src index 1fe6d1ea..babe45a8 160000 --- a/sw_src +++ b/sw_src @@ -1 +1 @@ -Subproject commit 1fe6d1eac5e79715286fbc4ab3960a88da71be53 +Subproject commit babe45a8bb7f3afe4cb6c40e4fbb6afd61f7dd69 diff --git a/sxw.c b/sxw.c index 095ae8b9..732da509 100644 --- a/sxw.c +++ b/sxw.c @@ -165,7 +165,6 @@ static void SXW_SW_Setup_Echo(void); void load_sxw_memory( RealD * grid_roots_max, RealD* grid_rootsXphen, RealD* grid_roots_active, RealD* grid_roots_active_rel, RealD* grid_roots_active_sum, RealD* grid_phen, RealD* grid_prod_bmass, RealD* grid_prod_pctlive ); void save_sxw_memory( RealD * grid_roots_max, RealD* grid_rootsXphen, RealD* grid_roots_active, RealD* grid_roots_active_rel, RealD* grid_roots_active_sum, RealD* grid_phen, RealD* grid_prod_bmass, RealD* grid_prod_pctlive ); void free_sxw_memory( void ); -void free_all_sxw_memory( void ); /****************** Begin Function Code ********************/ /***********************************************************/ @@ -865,7 +864,7 @@ static void _make_soil_arrays(void){ SXW_AVG.avg_temp_avg = (RealF *) Mem_Calloc(size, sizeof(RealF), fstr); SXW_AVG.surfaceTemp_avg = (RealD *) Mem_Calloc(size, sizeof(RealD), fstr); - SXW_AVG.aet_avg = (RealD *) Mem_Calloc(size, sizeof(RealD), fstr); + SXW_AVG.aet_avg = (RealF *) Mem_Calloc(size, sizeof(RealF), fstr); Mem_Set(SXW_AVG.aet_avg, 0, size * sizeof(RealF)); diff --git a/sxw.h b/sxw.h index 223a68e1..0dc5a33c 100644 --- a/sxw.h +++ b/sxw.h @@ -29,6 +29,7 @@ #include "ST_defines.h" int getNTranspLayers(int veg_prod_type); +void free_all_sxw_memory( void ); struct stepwat_st { RealD *transpTotal; /* points to dynamic array indexed by Ilp() */ From 1e01b0fac0e882e9a79fa404bb9d03f4ee3fca1f Mon Sep 17 00:00:00 2001 From: BrendenBe1 Date: Fri, 30 Mar 2018 15:44:38 -0700 Subject: [PATCH 109/111] Updating submodule. New SOILWAT commits add description for how to make new variables work with STEPWAT. --- sw_src | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sw_src b/sw_src index babe45a8..98631e7f 160000 --- a/sw_src +++ b/sw_src @@ -1 +1 @@ -Subproject commit babe45a8bb7f3afe4cb6c40e4fbb6afd61f7dd69 +Subproject commit 98631e7fcc88668ee4f24ea36dc8b2eba32fc1b6 From a991ab9c7e3a60c2c5164062140357cc902e6c0b Mon Sep 17 00:00:00 2001 From: BrendenBe1 Date: Fri, 6 Apr 2018 11:41:32 -0700 Subject: [PATCH 110/111] Updating submodule --- sw_src | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sw_src b/sw_src index 98631e7f..06d52acb 160000 --- a/sw_src +++ b/sw_src @@ -1 +1 @@ -Subproject commit 98631e7fcc88668ee4f24ea36dc8b2eba32fc1b6 +Subproject commit 06d52acb66797d8fbc8d00dc871cf9c02fb54038 From 27f82d68e892a91e4196537d3e6579cb9d75e429 Mon Sep 17 00:00:00 2001 From: BrendenBe1 Date: Fri, 6 Apr 2018 13:45:30 -0700 Subject: [PATCH 111/111] Updating submodule to point to SOILWAT2 master. --- .gitmodules | 2 +- sw_src | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.gitmodules b/.gitmodules index a14cc46e..fee8063d 100644 --- a/.gitmodules +++ b/.gitmodules @@ -1,5 +1,5 @@ [submodule "sw_src"] path = sw_src url = https://github.com/Burke-Lauenroth-Lab/SOILWAT2.git - branch = soilwat_save_output + branch = master ignore = dirty diff --git a/sw_src b/sw_src index 06d52acb..f30878e8 160000 --- a/sw_src +++ b/sw_src @@ -1 +1 @@ -Subproject commit 06d52acb66797d8fbc8d00dc871cf9c02fb54038 +Subproject commit f30878e8f41fa4299e4ab006acdaba5af78082c7