void SXW_Run_SOILWAT (void) {
/*======================================================*/
/* need to update the resource vectors and set up the
 * ppt and temp (environs) here before calling
 * Env_Generate() and rgroup_Establish() in main().
 *
 * 2/28/2003 - cwb - adding changes mentioned at top of file.
 * 3/31/2003 - cwb - because we're always running soilwat to
 *             emulate full-size plants, computing roots etc
 *             gets done once during init plot.
 */

#ifndef SXW_BYMAXSIZE
  GrpIndex g;
  RealF sizes[MAX_RGROUPS];
  /* compute production values for transp based on current plant sizes */
  ForEachGroup(g) sizes[g] = RGroup[g]->relsize;
  _sxw_update_root_tables(sizes);
  _sxw_sw_setup(sizes);
#endif

  SXW.aet = 0.;  /* used to be in sw_setup() but it needs clearing each run */
  _sxw_sw_run();

  /* now compute resource availability for the given plant sizes */
  _sxw_update_resource();

  /* and set environmental variables */
  _sxw_set_environs();


}
void SXW_InitPlot (void) {
/*======================================================*/
/* Call this from main::Plot_Init() after killing everything
 * so the sxw tables will be reset.
 */
#ifdef SXW_BYMAXSIZE
  GrpIndex g;
  RealF sizes[MAX_RGROUPS];
#endif

 _sxw_sw_clear_transp();
 _sxw_update_resource();


#ifdef SXW_BYMAXSIZE
/* this stuff was taken from Run_Soilwat() but we're now trying
 * to minimize the dynamic effect, so resources are always based
 * on full-sized plants.  So we only need to do this at the
 * beginning of each steppe-model iteration.
 */
  ForEachGroup(g) sizes[g] = 1.0;
  _sxw_update_root_tables(sizes);
  _sxw_sw_setup(sizes);
#endif


}
Example #3
0
void Env_Generate( void) {
/*======================================================*/
/* PURPOSE */
/* Wrapper to generate a new set of environmental factors,
   usually for the current year.  Any new environmental
   generators should be called from this subroutine.
*/
/* HISTORY */
/* Chris Bennett @ LTER-CSU 6/15/2000            */
/*------------------------------------------------------*/

  Int rg;

  switch (UseSoilwat) {
    case FALSE:
         /* clear last year's leftover resources */
         ForEachGroup(rg) RGroup[rg]->res_avail = 0.0;
         break;
    case TRUE:
         SXW_Run_SOILWAT();
         break;
  }


  _make_ppt();
  _make_temp();
  _set_ppt_reduction();
  _set_temp_reduction();
  _make_disturbance( );


}
static void _print_results(void) {
/*======================================================*/

  LyrIndex lyr;
  TimeInt pd;
  GrpIndex g;
  RealF sum;
  FILE *fp;

  fp = OpenFile("testdata.txt","w");

  LOG(fp,"===============================================\n");
  LOG(fp,"Echoing relative sizes and transpiration values.\n\n");

  ForEachGroup(g) {
    LOG(fp,"%s(%4.3f)\t", RGroup[g]->name, RGroup[g]->relsize);
  }
  LOG_NL;

  ForEachTrPeriod(pd) {
    LOG(fp,"%d", pd);
    ForEachTreeTranspLayer(lyr)
      LOG(fp,"\t%5.4f", SXW.transp[Ilp(lyr,pd)]);
    LOG_NL;
  }

  LOG(fp,"\n===============================================\n");
  LOG(fp,"     Relative rooting distributions.\n\n");
  LOG(fp,"Layer");
  ForEachGroup(g) LOG(fp,"\t%s", RGroup[g]->name);
  LOG_NL;
  ForEachTreeTranspLayer(lyr) {
    LOG(fp,"%d", lyr);
    ForEachGroup(g)
      LOG(fp, "\t%5.4f", _roots_rel[Ilg(lyr,g)]);
    LOG_NL;
  }

  LOG(fp,"\n===============================================\n");
  LOG(fp,"     Relative phenology.\n\n");
  LOG(fp,"Group");
  ForEachTrPeriod(pd) LOG(fp,"\t%d", pd);
  LOG_NL;
  ForEachGroup(g) {
    LOG(fp,"%s", RGroup[g]->name);
    ForEachTrPeriod(pd)
      LOG(fp,"\t%5.4f", _phen_grp_rel[Igp(g,pd)]);
    LOG_NL;
  }

  LOG(fp,"\n===============================================\n");
  LOG(fp,"  Check rel vals for rel phen X rel roots.\n\n");
  LOG_NL;
  ForEachGroup(g) {
    LOG(fp,"\n  ------  %s  -------\n", RGroup[g]->name);
    ForEachTrPeriod(pd) LOG(fp,"\t%d", pd);
    LOG_NL;
    ForEachTreeTranspLayer(lyr) {
      LOG(fp,"%d", lyr);
      ForEachTrPeriod(pd)
        LOG(fp,"\t%5.4f", _roots_active[Iglp(g,lyr,pd)]);
    LOG_NL;
    }
  }

  LOG(fp,"\n===============================================\n");
  LOG(fp,"  Totals for rel roots X rel phen.\n\n");
  LOG(fp,"Layer\\Mon");
  ForEachTrPeriod(pd) LOG(fp,"\t%d", pd);
  LOG_NL;
  ForEachTreeTranspLayer(lyr) {
    LOG(fp,"%d", lyr);
    ForEachTrPeriod(pd)
      LOG(fp,"\t%5.4f", _roots_phen_totals[Ilp(lyr,pd)]);
    LOG_NL;
  }

  LOG(fp,"\n===============================================\n");
  LOG(fp,"  Contribution to period's transpiration by group.\n\n");
  LOG(fp,"Group");
  ForEachTrPeriod(pd) LOG(fp,"\t%d", pd);
  LOG_NL;
  ForEachGroup(g) {
    LOG(fp,"%s", RGroup[g]->name);
    ForEachTrPeriod(pd) {
      sum = 0.;
      ForEachTreeTranspLayer(lyr) {
        sum += _roots_active[Iglp(g,lyr,pd)]
            *  SXW.transp[Ilp(lyr,pd)];
      }
      LOG(fp,"\t%5.4f", sum);
    }
    LOG_NL;
  }

  CloseFile(&fp);
}
void SXW_Init( Bool init_SW ) {
  /* read SOILWAT's input files and initialize some variables */
  /* The shorthand table dimensions are set at the point
   * at which they become defined in _read_files().
   *
   * 2/14/03 - cwb - Added the summation for each group's biomass
   *     as per the notes at the top of the file.
   */

#ifdef SXW_BYMAXSIZE
   GrpIndex rg; SppIndex sp;
   /* Sum each group's maximum biomass */
   ForEachGroup(rg) _Grp_BMass[rg] = 0.0;
   ForEachSpecies(sp)
     _Grp_BMass[Species[sp]->res_grp] += Species[sp]->mature_biomass;
   /* end code 2/14/03 */
#endif

   _files[0] = &SXW.f_times;
   _files[1] = &SXW.f_roots;
   _files[2] = &SXW.f_phen;
   _files[3] = &SXW.f_bvt;
   _files[4] = &SXW.f_prod;
   _files[5] = &SXW.f_watin;

  SXW.NGrps = Globals.grpCount;

  _read_files();
  _read_times();
  _read_watin();

  if (*SXW.debugfile) _read_debugfile();
  _write_sw_outin();

  if(init_SW) SW_CTL_init_model(SXW.f_watin);
  
  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 (*SXW.debugfile) SXW.NSoLyrs = SW_Site.n_layers;

  _make_arrays();

  _read_roots_max();
  _read_phen();
  _read_prod();
  _read_bvt();    /* 12/29/03 */


/*  _recover_names(); */

  _sxw_root_phen();



#ifdef TESTING
  _sxw_test();
  exit(0);
#endif

  _recover_names();
}