Ecological Landscape Modeling: Models Pages

UnitMod.c

Go to the documentation of this file.
00001 
00038 /*###############
00039 To change among model grid scales of different resolution/extent: 
00040   no code changes are needed here or elsewhere
00041 ###############
00042 
00043  ***
00044  NOTE: The init_eqns module is not fully updated for properly
00045  turning off individual **interacting** *biological/chemical* modules at runtime.  
00046  If one *biological/chemical* module is turned off, 
00047  they all need to be turned off. 
00048 
00049  The following *biological/chemical* modules must be ON or OFF as a group:
00050  (cell_dyn2 + cell_dyn4 + cell_dyn8 + cell_dyn9 + cell_dyn12)
00051  cell_dyn13, the net settling rate module, can be turned on only when above module group is off
00052  ***
00053 
00054 */
00055 
00056   
00057 /* General NOTES on revisions to this source file:
00058         april 2000 VERSION 2.1 - output available for application for water quality performance
00059         july 2002 VERSIOIN 2.1a - first widely-available public release of code -
00060               - misc modifications, such as revising method and types of
00061               parameters that are read in (reduced number of parms in "habitat-specific" dbase);
00062               - added some more code documentation, etc.
00063         July 2003 VERSION 2.2.0 - moved declarations into header file, other similar changes
00064               to help reviewers better understand organization of codes.
00065               - Incorporated new rainfall module (highly revised rain_inp.c) that generalizes the
00066               code to better accomodate implementations of all scale; NO DATA CHANGE - passes identical data
00067               from SFWMM data file to the ELM.
00068               - Included are some specific, minor code changes (that do not alter calculations)  
00069         July 2004 VERSION 2.2.1 - improved code documentation
00070 ******        - AN ESSENTIAL COMPANION TO THIS CODE DOCUMENTATION IS NOW THE "ModelOutlist_creator_version#.xls"
00071 ******            workbook (OpenOffice/Excel).  In this workbook, all of the variables
00072 ******            that are spatial arrays (and other types) are defined/described (including their units).
00073               - In order to avoid the "clutter" of comments interspersing virtually every equation,
00074               this workbook was used to fully define the use of the variables in the model.
00075               - The code here STILL contains comments that describe the variables that may be most 
00076               important or that are better understood by explicitly stating underlying assumptions. 
00077               - Included are several specific, minor code changes (still maintaining v2.1a calcs). 
00078         Aug 2004 VERSION 2.3.0 - added bathymetry map input (dynamic boundary conditions in other src files -> version upgrade)
00079                 - added bathymetry map input
00080                 - added new spatial time series data input for dynamic boundary conditions
00081                 - version increment to 2.3 due to changes in other source files
00082         Oct 2004 VERSION 2.3.1 - internal release 
00083                 - checked that results reasonable, not fully checked
00084         Nov 2004 VERSION 2.3.2 - documentation upgrade
00085                 - removed standing detritus (was operative in v2.3.0 & earlier), consumer, and fire modules completely from code
00086                 - removed extraneous comments, inoperative variables, inoperative parameters
00087                 - added Doxygen tags in comments
00088         Apr 2005 v2.4.4: changed init maps: icMult removed, icMacBio added
00089         May 2006 v2.5.0: added some debug-level output for boundary condition stage
00090         Oct 2006 v2.6.0: added more boundary condition functionality
00091                 - reinstated the ptsl (search for "v2.6 PTSL") on-the-fly spatial time series interpolators for a non-gridIO alternative for meteorological data
00092                 - added model-experiment parameters (ModExperimParms_NOM, boundary condition experiments right now)
00093         Nov 2006 v2.6.0: added input map of atmospheric phosphorus deposition rate 
00094                 - added a P deposition method of applying temporally-constant, spatially-varying 
00095                 P depos rate (TP_AtmosDepos).  If the global parameter of TP conc in rain is >= 0.0, then
00096                 the old of method of applying P conc to rainfall is used instead.
00097         Oct 2007 v2.7.0: added functionality of calc'ing surface water flow velocities
00098                 - new variable SF_WT_VEL_mag, of net surface water flow velocity magnitude (all directions)
00099                 - fixed bug in auto-scaling of dispersion among model grids of diff sizes
00100         Nov 2007 v2.7.1: added functionality of outputting BC model water depths
00101                 - new variable BCmodel_sfwat of the BoundaryCondition model's water depth (currently the SFWMM), so
00102                 that those depths may be output (for comparison to ELM), if desired
00103         Feb 2008 v2.8.1: added functionality of salt (chloride) inputs to domain from atmosphere
00104                 - new variable SALT_Atm_Depos, calculated from rainfall and new global parm GP_CL_IN_RAIN, 
00105                 or from new input map SALT_AtmosDepos of constant total atmospheric deposition
00106                 - added this input to the salt budget (BudgStats.c)
00107         June 2008 v2.8.2: added new variables for output
00108                 - new variable HydRelDepPosNeg (stage minus land surface elevation).  
00109                 - new associated variable HydRelDepPosNegAvg added to BudgStats.c (average of HydRelDepPosNeg)
00110                 - These are for reporting purposes only; data are pos/neg, and thus map output MUST be 4 byte floats
00111         Mar 2011 v2.8.4: added new parameter
00112                 - new parameter GP_WQualMonitZ (threshold depth used to report 0.000 for salt and TP conc in surface water when below threshold depth,
00113                 used to use the hydro detention depth).  
00114         July 2011 v2.8.4: altered soil initializations
00115                 - new DEPOS_ORG_MAT initialization routines
00116                 - new initial map for TP_SEDWT_CONCACT (instead of hab-specific parameter)
00117                 - now (optionally) using hab-specific parameter of activezone depth of 10 cm (instead of 30 cm)
00118         Sept 2011 v2.8.5: added succession parm inputs for salinity, and algorithm for mac growth response 
00119                 - changed macrophyte module to alter growth in response to salinity re. existing HP_MAC_SALIN_THRESH
00120                 - see Success.c for succession module changes
00121 
00122 */
00123 
00124 #include "unitmod.h"
00125 #include "unitmod_vars.h"
00126 #include "unitmod_habparms.h"
00127 #include "unitmod_globparms.h"
00128 #include "budgstats_statvars.h"  
00129 
00150 int call_cell_dyn(int sector,int step)
00151  {
00152   int rv=0;
00153 
00154   switch(sector) {
00155 
00156     case 99: { stats(step); rv=1; } break;
00157     case 0: { horizFlow(step); rv=1; } break;
00158     case 1: { cell_dyn1(step); rv=1; } break;
00159     case 2: { cell_dyn2(step); rv=1; } break;
00160     case 4: { cell_dyn4(step); rv=1; } break;
00161     case 7: { cell_dyn7(step); rv=1; } break;
00162     case 8: { cell_dyn8(step); rv=1; } break;
00163     case 9: { cell_dyn9(step); rv=1; } break;
00164     case 10: { cell_dyn10(step); rv=1; } break;
00165     case 12: { cell_dyn12(step); rv=1; } break;
00166     case 13: { cell_dyn13(step); rv=1; } break;
00167             default:  printf("Warning, undefined sector number:%d\n",sector);
00168   }
00169   return rv;
00170 }
00171 
00172 
00173 /*###############
00174 The following modules (cell_dyn*) are the dynamic calcs for the model.
00175 They are called in the order determined by the call_cell_dyn function.
00176 ################*/
00177 
00178 
00179 /*******/
00188 /* Parameter definitions:
00189       global parameters in GlobalParms.xls OpenOffice/Excel sheet (text export=GlobalParms)
00190       habitat-specific parameters in HabParms.fmp FileMakerPro database (text export=HabParms)
00191 ******/
00192 
00193 void cell_dyn1(int step)
00194 {
00195    int fail = -1;
00196    int ix, iy, cellLoc, stat=1; 
00197    float fTemp;
00198    extern IsSubstituteModel; /* from generic_driver.h */
00199    
00200    /* v2.5 may be temporary? */
00201    FILE *boundaryFile; 
00202    char filename[40];
00203 
00204      /* SimTime.TIME is a (float) julian day counter since initialization (calc'd in main function, Generic_Driver.c source).  
00205          (SimTime.TIME includes fractions of days if the vertical DT<1.0, but it is
00206          unlikely that the vertical DT will deviate from 1 day). */
00207 
00208          if ( debug > 4 ) {
00209                 if (SimTime.TIME>60)  printf("\nDebug level is very high - you're probably getting too much output data in %s/%s/Output/Debug/! Decrease your simulation length.\n", OutputPath, ProjName); 
00210                 exit(-1); 
00211          }
00212 
00213 /* v2.6 PTSL */
00214 /* a choice of rainfall and pET input data routines */
00215     if (!isPTSL) { /* do the gridIO inputs */
00216         if (FMOD(SimTime.TIME,1.0) < 0.001) { /* daily re-mapping of coarse-grid input data */
00217                 /* remap sfwmm (or other grid) rain data to ELM grid scale */
00218           stat=rain_data_wmm(boundcond_rain); 
00219           if(stat==fail)  
00220          { 
00221                   sprintf(msgStr,"Problem with rainfall data, time = %f.\n",SimTime.TIME); 
00222                          WriteMsg(msgStr,1); 
00223                          exit(fail);    
00224          }
00225 
00226      /* remap sfwmm (or other grid) potential ET data to ELM grid scale */
00227                   stat=evap_data_wmm(boundcond_ETp); 
00228                   if(stat==-1)
00229                  {
00230                    sprintf(msgStr,"Problem with ETp data, time = %f.\n",SimTime.TIME);
00231                    WriteMsg(msgStr,1);
00232                    exit(fail);
00233                           } 
00234 
00235      /* remap sfwmm (or other grid) stage/water depth data to ELM grid scale */
00236       stat=stage_data_wmm(boundcond_depth);  
00237      if(stat==-1)
00238      {
00239        sprintf(msgStr,"Problem with stage data, time = %f.\n",SimTime.TIME);
00240        WriteMsg(msgStr,1);
00241        exit(fail);
00242      } 
00243      
00244 
00245          for ( ix = 1; ix <= s0 ; ix++ ) 
00246             for ( iy = 1 ; iy <= s1 ; iy++ )
00247                 {
00248                         cellLoc= T(ix,iy);
00249 
00250     /* v2.7.1 assign the external boundary condition model's depths to an ELM variable within the rectangular 
00251     ELM domain (i.e., on-map and off-map), for output only (this variable not used in any calcs) */
00252                         if (IsSubstituteModel == 0) BCmodel_sfwat[cellLoc] = (boundcond_depth[cellLoc] > 0.0) ? (boundcond_depth[cellLoc]) : (0.0) ;
00253                         
00254                         else { /* IsSubstituteModel is true */
00255                                 if(ON_MAP[cellLoc])  {
00256        /* v2.8 - added feature to replace all ELM hydrologic calcs, substituting the Boundary Condition Model's
00257                         "stage_minus_landElevation" variable into ELM hydro variables.
00258                         This was done in order to post-process the SFWMM or NSM using the same procedures as ELM 
00259                         At initial setup, it was determined whether the user is requesting to only run cell_dyn1 (and stats, case #99) in UnitMod.c,
00260                         which would make the IsSubstituteModel flag True */
00261 
00262                                 SURFACE_WAT[cellLoc] = (boundcond_depth[cellLoc] > 0.0) ? (boundcond_depth[cellLoc]) : (0.0) ;
00263                                 SAT_WT_HEAD[cellLoc] = (boundcond_depth[cellLoc] <= 0.0) ? (SED_ELEV[cellLoc] + boundcond_depth[cellLoc]) : (SED_ELEV[cellLoc]) ;
00264                                 HydTotHd[cellLoc]  = SAT_WT_HEAD[cellLoc]+SURFACE_WAT[cellLoc];
00265                                 SAT_WATER[cellLoc] = SAT_WT_HEAD[cellLoc] * HP_HYD_POROSITY[HAB[cellLoc]];  /* this isn't needed for current purposes, but may be of interest later */
00266                                 UNSAT_DEPTH[cellLoc] = Max(SED_ELEV[cellLoc]-SAT_WT_HEAD[cellLoc],0.0);
00267                                 UNSAT_WATER[cellLoc] = UNSAT_DEPTH[cellLoc] * HP_HYD_POROSITY[HAB[cellLoc]] * 0.0; /* assume there is no moisture in pore spaces, thus never any unsat storage */
00268               /* v2.8.2 new variable, for reporting purposes only: positive/negative water depth relative to land elevation (stage minus land elevation) */
00269                         HydRelDepPosNeg[cellLoc] =  HydTotHd[cellLoc] - SED_ELEV[cellLoc];
00270                         }
00271                         }
00272                                 
00273                         }   
00274 
00275 
00276 
00277     } /* end of mapping multi-grid, gridIO data */
00278     } /* end of !isPTSL */
00279     
00280     else { /* instead of gridIO spatial data, calculate on-the-fly spatial interpolations of rain and pET point time series data  */
00281                 /* NOTE that this option does not use gridIO stage/depth boundary condition data, and thus should be used in conjunction
00282                 with the ModExperimParms_NOM synthetic boundary condition data */
00283         fTemp = FMOD(SimTime.TIME,Timestep2*NPtTS2);
00284                 PTSL_CreatePointMap(pTSList2,boundcond_rain,'f',(int)(fTemp/Timestep2),1.0);
00285         fTemp = FMOD(SimTime.TIME,Timestep3*NPtTS3);
00286                 PTSL_CreatePointMap(pTSList3,boundcond_ETp,'f',(int)(fTemp/Timestep3),1.0);
00287     }
00288 
00289 
00290             
00291     /* the "julian" day counter within a 365 day "year"  */
00292     DAYJUL = ( FMOD(SimTime.TIME,365.0) >0.0 ) ? ( FMOD(SimTime.TIME,365.0) ) : ( 365.0);
00293     /* DAYLENGTH is not used */
00294     /* DAYLENGTH = AMPL*Sin((DAYJUL-79.0)*0.01721)+12.0; */ /* length of daylight (hours) */
00295 
00296                 
00297 /*  Nikolov & Zeller (1992) solar radiation algorithm 
00298    the algorithm and all parameters are published in the (Ecol. Mod., 61:149-168) manuscript,
00299    and the only modifiable parameters (in ELM database system) are local latitude and altitude */
00300     SOLDEC1 = 0.39785*Sin(4.868961+0.017203*DAYJUL   
00301                           +0.033446*Sin(6.224111+0.017202*DAYJUL));
00302     SOLCOSDEC = sqrt(1.0-SOLDEC1*SOLDEC1);
00303     SOLELEV_SINE = Sin(LATRAD)*SOLDEC1+Cos(LATRAD)*SOLCOSDEC;
00304     SOLALTCORR = (1.0-Exp(-0.014*(GP_ALTIT-274.0)/(SOLELEV_SINE*274.0)));
00305     SOLDEC = Arctan(SOLDEC1/sqrt(1.0-SOLDEC1*SOLDEC1));
00306     SOLRISSET_HA1 = -Tan(LATRAD)*Tan(SOLDEC);
00307     SOLRISSET_HA = ( (SOLRISSET_HA1==0.0) ) ? ( PI*0.5 ) : (   ( (SOLRISSET_HA1<0.0) ) ? 
00308                                                                ( PI+Arctan(sqrt(1.0-SOLRISSET_HA1*SOLRISSET_HA1)/SOLRISSET_HA1)  ) : 
00309                                                                (    Arctan(sqrt(1.0-SOLRISSET_HA1*SOLRISSET_HA1)/SOLRISSET_HA1)));
00310     SOLRADATMOS = 458.37*2.0*(1.0+0.033*Cos(360.0/365.0*PI/180.0*DAYJUL))
00311         * ( Cos(LATRAD)*Cos(SOLDEC)*Sin(SOLRISSET_HA) 
00312             + SOLRISSET_HA*180.0/(57.296*PI)*Sin(LATRAD)*Sin(SOLDEC));
00313             
00314   
00315         /* daily habitat switching */
00316     if ( (SimTime.TIME - (int)SimTime.TIME) < DT/2 && HabSwitchOn ) /* HabSwitchOn flag to invoke switching */
00317         for(ix=1; ix<=s0; ix++)  
00318             for(iy=1; iy<=s1; iy++)  
00319                 if(ON_MAP[cellLoc= T(ix,iy)]) { /* TPtoSoil == kg/kg */
00320                     HAB [cellLoc] = HabSwitch (ix, iy, SURFACE_WAT, TPtoSOIL, (int*)FIREdummy, SAL_SF_WT, HAB); 
00321                 } 
00322 }
00323 
00324 
00325 
00326 /*******/
00333 /*
00334   NC_ALG[cellLoc] == carbon mass of the NonCalcareous (more appropriately, the eutrophic, or non-native) periphyton community (gC/m^2)
00335   C_ALG[cellLoc] == carbon mass of the Calcareous (more appropriately, the oligotrophic, or native) periphyton community (gC/m^2)
00336 
00337   NC_ALG_P[cellLoc] == phosphorus mass of NonCalcareous (more appropriately, the eutrophic, or non-native) periphyton community (gP/m^2)
00338   C_ALG_P[cellLoc] == phosphorus mass of Calcareous (more appropriately, the oligotrophic, or native) periphyton community (gP/m^2)
00339   
00340 Parameter definitions:
00341       global parameters in GlobalParms.xls Excel sheet (text export=GlobalParms)
00342       habitat-specific parameters in HabParms.fmp FileMakerPro database (text export=HabParms)
00343 */
00344 void cell_dyn2(int step)
00345  {
00346  int ix, iy, cellLoc; 
00347  float reduc, min_litTemp,I_ISat, Z_extinct; 
00348  double PO4Pconc, PO4P;
00349  float C_ALG_thresh_CF, mortPot;
00350  
00351   for(ix=1; ix<=s0; ix++) {
00352   for(iy=1; iy<=s1; iy++) {
00353 
00354     if(ON_MAP[cellLoc= T(ix,iy)])  {
00355 
00356 /* these thresholds need updating when a habitat type of a grid cell changes */
00357      ALG_REFUGE[cellLoc] = HP_ALG_MAX[HAB[cellLoc]]*GP_ALG_REF_MULT;
00358      ALG_SAT[cellLoc] = HP_ALG_MAX[HAB[cellLoc]]*0.9;
00359 
00360      NC_ALG_AVAIL_MORT[cellLoc]  = Max(NC_ALG[cellLoc]-ALG_REFUGE[cellLoc],0);
00361      C_ALG_AVAIL_MORT[cellLoc]  = Max(C_ALG[cellLoc]-ALG_REFUGE[cellLoc],0);
00362 /* bio-avail P (PO4) is calc'd from TP, using pre-processed regression for predicting PO4 from TP */
00363 /* assume that periphyton (microbial) alkaline phosphotase activity keeps PO4 at least 10% of TP conc */
00364      PO4Pconc = Max(TP_SFWT_CONC_MG[cellLoc]*GP_PO4toTP + GP_PO4toTPint,
00365                                 0.10 * TP_SFWT_CONC_MG[cellLoc]); /* mg/L */
00366 
00367 /* light, water, temperature controls apply to both calc and non-calc */
00368      ALG_LIGHT_EXTINCT[cellLoc]  = GP_alg_light_ext_coef; 
00369                      /* algal self-shading implicit in density-dependent constraint function later */
00370      ALG_INCID_LIGHT[cellLoc]  = SOLRADGRD[cellLoc]*Exp(-MAC_LAI[cellLoc]*GP_ALG_SHADE_FACTOR);
00371      Z_extinct = SURFACE_WAT[cellLoc]*ALG_LIGHT_EXTINCT[cellLoc];
00372      I_ISat = ALG_INCID_LIGHT[cellLoc]/GP_ALG_LIGHT_SAT;
00373                      /* averaged over whole water column (based on Steele '65) */
00374      ALG_LIGHT_CF[cellLoc]  = ( Z_extinct > 0.0 ) ? 
00375                      ( 2.718/Z_extinct * (Exp(-I_ISat * Exp(-Z_extinct)) - Exp(-I_ISat)) ) :
00376                      (I_ISat*Exp(1.0-I_ISat));
00377                      /* low-water growth constraint ready for something better based on data */
00378      ALG_WAT_CF[cellLoc]  = ( SURFACE_WAT[cellLoc]>0.0 ) ? ( 1.0 ) : ( 0.0);
00379      ALG_TEMP_CF[cellLoc]  = tempCF(0, 0.20, GP_ALG_TEMP_OPT, 5.0, 40.0, H2O_TEMP[cellLoc]);
00380 
00381       min_litTemp = Min(ALG_LIGHT_CF[cellLoc],ALG_TEMP_CF[cellLoc]);
00382 
00383 /* the 2 communities have same form of growth response to avail phosphorus */
00384      NC_ALG_NUT_CF[cellLoc]  =
00385                      Exp(-GP_alg_uptake_coef * Max(GP_NC_ALG_KS_P-PO4Pconc, 0.0)/GP_NC_ALG_KS_P) ; /* mg/L */
00386      C_ALG_NUT_CF[cellLoc]  =
00387                      Exp(-GP_alg_uptake_coef * Max(GP_C_ALG_KS_P-PO4Pconc, 0.0)/GP_C_ALG_KS_P) ; /* mg/L */
00388 
00389          /* the form of the control function assumes that at very low
00390              P conc, the alkaline phosphotase activity of the microbial assemblage scavenges P, maintaining a minimum nutrient availability to community */
00391      NC_ALG_PROD_CF[cellLoc]  = Min(min_litTemp,ALG_WAT_CF[cellLoc])*Max(NC_ALG_NUT_CF[cellLoc], GP_alg_alkP_min);
00392      C_ALG_PROD_CF[cellLoc]   = Min(min_litTemp,ALG_WAT_CF[cellLoc])*Max(C_ALG_NUT_CF[cellLoc], GP_alg_alkP_min);
00393 
00394      NC_ALG_RESP_POT[cellLoc]  = 
00395          ( UNSAT_DEPTH[cellLoc]>GP_algMortDepth ) ? 
00396          ( 0.0) :
00397          ( GP_ALG_RC_RESP*ALG_TEMP_CF[cellLoc]*NC_ALG_AVAIL_MORT[cellLoc] ); 
00398      C_ALG_RESP_POT[cellLoc]  = 
00399          ( UNSAT_DEPTH[cellLoc]>GP_algMortDepth ) ? 
00400          ( 0.0) :
00401          ( GP_ALG_RC_RESP*ALG_TEMP_CF[cellLoc] *C_ALG_AVAIL_MORT[cellLoc] ); 
00402 
00403      NC_ALG_RESP[cellLoc]  =  
00404          ( NC_ALG_RESP_POT[cellLoc]*DT>NC_ALG_AVAIL_MORT[cellLoc] ) ? 
00405          ( NC_ALG_AVAIL_MORT[cellLoc]/DT ) : 
00406          ( NC_ALG_RESP_POT[cellLoc]);
00407      C_ALG_RESP[cellLoc]  =  
00408          ( C_ALG_RESP_POT[cellLoc]*DT>C_ALG_AVAIL_MORT[cellLoc] ) ? 
00409          ( C_ALG_AVAIL_MORT[cellLoc]/DT ) : 
00410          ( C_ALG_RESP_POT[cellLoc]);
00411                  
00412           /* this is the threshold control function that increases
00413               calcareous/native periph mortality (likely due to loss of calcareous sheath) as P conc. increases */
00414      C_ALG_thresh_CF = Min(exp(GP_alg_R_accel*Max( TP_SFWT_CONC_MG[cellLoc]-GP_C_ALG_threshTP,0.0)/GP_C_ALG_threshTP), 100.0);
00415 
00416      NC_ALG_MORT_POT[cellLoc]  = 
00417          ( UNSAT_DEPTH[cellLoc]>GP_algMortDepth ) ? 
00418          ( NC_ALG_AVAIL_MORT[cellLoc]*GP_ALG_RC_MORT_DRY ) : 
00419          ( NC_ALG_AVAIL_MORT[cellLoc]*GP_ALG_RC_MORT);
00420      C_ALG_MORT_POT[cellLoc]  = 
00421          ( UNSAT_DEPTH[cellLoc]>GP_algMortDepth ) ? 
00422          ( C_ALG_AVAIL_MORT[cellLoc]*GP_ALG_RC_MORT_DRY ) : 
00423          ( C_ALG_thresh_CF * C_ALG_AVAIL_MORT[cellLoc]*GP_ALG_RC_MORT);
00424 
00425      NC_ALG_MORT[cellLoc]  = 
00426          ( (NC_ALG_MORT_POT[cellLoc]+NC_ALG_RESP[cellLoc])*DT>NC_ALG_AVAIL_MORT[cellLoc] ) ? 
00427          ( (NC_ALG_AVAIL_MORT[cellLoc]-NC_ALG_RESP[cellLoc]*DT)/DT ) : 
00428          ( NC_ALG_MORT_POT[cellLoc]);
00429      C_ALG_MORT[cellLoc]  = 
00430          ( (C_ALG_MORT_POT[cellLoc]+C_ALG_RESP[cellLoc])*DT>C_ALG_AVAIL_MORT[cellLoc] ) ? 
00431          ( (C_ALG_AVAIL_MORT[cellLoc]-C_ALG_RESP[cellLoc]*DT)/DT ) : 
00432          ( C_ALG_MORT_POT[cellLoc]);
00433                  
00434 /* gross production of the 2 communities (gC/m2/d, NOT kgC/m2/d) */
00435 /* density constraint on both noncalc and calc, competition effect accentuated by calc algae */
00436 
00437      NC_ALG_GPP[cellLoc]  =  NC_ALG_PROD_CF[cellLoc]*GP_ALG_RC_PROD*NC_ALG[cellLoc]       
00438              *Max( (1.0-(GP_AlgComp*C_ALG[cellLoc]+NC_ALG[cellLoc])/HP_ALG_MAX[HAB[cellLoc]]),0.0);
00439      C_ALG_GPP[cellLoc]  =  C_ALG_PROD_CF[cellLoc]*GP_ALG_RC_PROD*C_ALG[cellLoc] 
00440        *Max( (1.0-(        C_ALG[cellLoc]+NC_ALG[cellLoc])/HP_ALG_MAX[HAB[cellLoc]]),0.0);
00441        
00442                      
00443 /* P uptake is dependent on available P and is relative to a maximum P:C ratio for the tissue
00444    (g C/m^2/d * P:Cmax * dimless * dimless = gP/m2/d (NOT kg) )*/
00445      NC_ALG_GPP_P[cellLoc] = NC_ALG_GPP[cellLoc] *GP_ALG_PC * NC_ALG_NUT_CF[cellLoc]
00446                      * Max(1.0-NC_ALG_PC[cellLoc]/GP_ALG_PC, 0.0); 
00447      C_ALG_GPP_P[cellLoc] = C_ALG_GPP[cellLoc] * GP_ALG_PC * C_ALG_NUT_CF[cellLoc]
00448                      * Max(1.0-C_ALG_PC[cellLoc]/GP_ALG_PC, 0.0); 
00449                  
00450 /* check for available P mass (the nutCF does not) */
00451      PO4P = ramp(Min(PO4Pconc * SFWT_VOL[cellLoc],  conv_kgTOg*TP_SF_WT[cellLoc]) ); /*g P available; v2.5 put in ramp (constrain non-neg) */
00452      reduc = ( (NC_ALG_GPP_P[cellLoc]+C_ALG_GPP_P[cellLoc]) > 0) ? 
00453                      (PO4P / ( (NC_ALG_GPP_P[cellLoc]+C_ALG_GPP_P[cellLoc])*CELL_SIZE*DT) ) :
00454                      (1.0);
00455     /* can have high conc, but low mass of P avail, in presence of high peri biomass and high demand */
00456     /* reduce the production proportionally if excess demand is found */
00457     if (reduc < 1.0) {
00458                      NC_ALG_GPP[cellLoc] *= reduc;   
00459                      NC_ALG_GPP_P[cellLoc] *= reduc;   
00460                      C_ALG_GPP[cellLoc] *= reduc; 
00461                      C_ALG_GPP_P[cellLoc] *= reduc; 
00462                  }
00463 
00464 /* state variables calc'd (gC/m2, NOT kgC/m2) */
00465      NC_ALG[cellLoc] =  NC_ALG[cellLoc] 
00466          + (NC_ALG_GPP[cellLoc]
00467           - NC_ALG_RESP[cellLoc] - NC_ALG_MORT[cellLoc]) * DT;
00468 
00469      C_ALG[cellLoc] =  C_ALG[cellLoc] 
00470          + (C_ALG_GPP[cellLoc] 
00471          - C_ALG_RESP[cellLoc]  - C_ALG_MORT[cellLoc]) * DT;
00472 
00473 /* carbon NPP not currently used elsewhere, only for output */
00474      NC_ALG_NPP[cellLoc]  = NC_ALG_GPP[cellLoc]-NC_ALG_RESP[cellLoc]; 
00475      C_ALG_NPP[cellLoc]  = C_ALG_GPP[cellLoc]-C_ALG_RESP[cellLoc];                 
00476 /* carbon total biomass of both communities, not currently used elsewhere, only for output */
00477      ALG_TOT[cellLoc] = NC_ALG[cellLoc] + C_ALG[cellLoc];
00478                  
00479                  
00480 /*  now calc the P  associated with the C fluxes (GPP_P already calc'd) */
00481      mortPot = (double) NC_ALG_MORT[cellLoc] * NC_ALG_PC[cellLoc];
00482      NC_ALG_MORT_P[cellLoc] = (mortPot*DT>NC_ALG_P[cellLoc]) ?
00483                      (NC_ALG_P[cellLoc]/DT) :
00484                      (mortPot);
00485      mortPot = (double) C_ALG_MORT[cellLoc] * C_ALG_PC[cellLoc];
00486      C_ALG_MORT_P[cellLoc] = (mortPot*DT>C_ALG_P[cellLoc]) ?
00487                      (C_ALG_P[cellLoc]/DT) :
00488                      (mortPot);
00489                  
00490 
00491 /* state variables calc'd (gP/m2, NOT kgP/m2) */
00492      NC_ALG_P[cellLoc] =  NC_ALG_P[cellLoc] 
00493          + (NC_ALG_GPP_P[cellLoc] - NC_ALG_MORT_P[cellLoc]) * DT;
00494 
00495      C_ALG_P[cellLoc] =  C_ALG_P[cellLoc] 
00496          + (C_ALG_GPP_P[cellLoc] - C_ALG_MORT_P[cellLoc]) * DT;
00497 
00498      NC_ALG_PC[cellLoc] = (NC_ALG[cellLoc]>0.0) ?
00499                      (NC_ALG_P[cellLoc]/ NC_ALG[cellLoc]) :
00500                      ( GP_ALG_PC * 0.03); /* default to 3% of  max P:C */
00501      C_ALG_PC[cellLoc] = (C_ALG[cellLoc]>0.0) ?
00502                      (C_ALG_P[cellLoc]/ C_ALG[cellLoc]) :
00503                      ( GP_ALG_PC * 0.03 ); /* default to 3% of max P:C */
00504      NC_ALG_PCrep[cellLoc] = (float)NC_ALG_PC[cellLoc] * conv_kgTOmg; /* variable for output _rep-orting only */
00505      C_ALG_PCrep[cellLoc] = (float)C_ALG_PC[cellLoc] * conv_kgTOmg; /* variable for output _rep-orting only */
00506 
00507      if (debug > 0 && NC_ALG[cellLoc] < -GP_MinCheck) { sprintf(msgStr,"Day %6.1f: ERROR - neg NC_ALG C biomass (%f g/m2) in cell (%d,%d)!", 
00508                               SimTime.TIME, NC_ALG[cellLoc], ix,iy ); WriteMsg( msgStr,True ); dynERRORnum++;}
00509                  if (debug > 0 && C_ALG[cellLoc] < -GP_MinCheck)  { sprintf(msgStr,"Day %6.1f: ERROR - neg C_ALG C biomass (%f g/m2) in cell (%d,%d)!", 
00510                               SimTime.TIME, C_ALG[cellLoc], ix,iy ); WriteMsg( msgStr,True ); dynERRORnum++;}
00511                  if (debug > 0 && NC_ALG_P[cellLoc] < -GP_MinCheck) { sprintf(msgStr,"Day %6.1f: ERROR - neg NC_ALG_P P biomass (%f g/m2) in cell (%d,%d)!", 
00512                               SimTime.TIME, NC_ALG_P[cellLoc], ix,iy ); WriteMsg( msgStr,True ); dynERRORnum++;}
00513                  if (debug > 0 && C_ALG_P[cellLoc] < -GP_MinCheck)  { sprintf(msgStr,"Day %6.1f: ERROR - neg C_ALG_P P biomass (%f g/m2) in cell (%d,%d)!", 
00514                               SimTime.TIME, C_ALG_P[cellLoc], ix,iy ); WriteMsg( msgStr,True ); dynERRORnum++;}
00515 
00516                      
00517      TP_SFWT_UPTAK[cellLoc]  = (NC_ALG_GPP_P[cellLoc]+C_ALG_GPP_P[cellLoc])
00518                      *0.001*CELL_SIZE; /* gP/m2 => kg P */
00519 /* recalc P in surface water state variable (kg P) */
00520      TP_SF_WT[cellLoc] = TP_SF_WT[cellLoc] - TP_SFWT_UPTAK[cellLoc] * DT;
00521      TP_SFWT_CONC[cellLoc]  = 
00522          ( SFWT_VOL[cellLoc] > 0.0 ) ? 
00523          ( TP_SF_WT[cellLoc]/SFWT_VOL[cellLoc] ) : 
00524          ( 0.0); /* used in P fluxes for mass balance */
00525      TP_SFWT_CONC_MG[cellLoc]  = 
00526          ( SURFACE_WAT[cellLoc] > GP_WQualMonitZ ) ? 
00527          (TP_SFWT_CONC[cellLoc]*conv_kgTOg) : 
00528          (0.0); /* (g/m3==mg/L) used for reporting and other modules to evaluate P conc when water is present */
00529 
00530           }
00531   }
00532   }
00533 }
00534 
00535 
00536 
00537 
00538 /*******/
00545 /*     DEPOS_ORG_MAT[cellLoc] == mass of Deposited Organic Matter (DOM/AOM) of soil zone, w/o floc layer (kg OM/m^2)
00546 
00547      DOP[cellLoc] ==  mass of Deposited Organic Phosphorus of soil zone, w/o floc layer, w/o P sorbed (kg P/m^2)
00548   
00549 Parameter definitions:
00550       global parameters in GlobalParms.xls Excel sheet (text export=GlobalParms)
00551       habitat-specific parameters in HabParms.fmp FileMakerPro database (text export=HabParms)
00552 */
00553 void cell_dyn4(int step)
00554  {
00555 int ix, iy, cellLoc;
00556  float TPsoil, TP_sedMin, TP_sfMin;
00557   
00558  
00559 
00560   for(ix=1; ix<=s0; ix++) {
00561   for(iy=1; iy<=s1; iy++) {
00562 
00563     if(ON_MAP[cellLoc= T(ix,iy)])  {
00564 
00565 
00566 /* inputs of organic matter (kg OM/m2)*/
00567      DOM_fr_nphBio[cellLoc] = nphbio_mort_OM[cellLoc];
00568      DOM_FR_FLOC[cellLoc]  =  FLOC_DEPO[cellLoc] ; 
00569 
00570 /* losses of organic matter (kg OM/m2) */
00571 
00572      DOM_QUALITY_CF[cellLoc]  =
00573           Min(Exp(-GP_DOM_decomp_coef * Max(GP_DOM_DECOMP_POPT-TP_SEDWT_CONCACTMG[cellLoc], 0.0)
00574           /GP_DOM_DECOMP_POPT),1.0) ; /* mg/L */
00575           DOM_TEMP_CF[cellLoc] = tempCF(0, 0.20, GP_DOM_DECOMP_TOPT, 5.0, 40.0, H2O_TEMP[cellLoc]);
00576      DOM_SED_AEROB_Z[cellLoc]  = Min(Max(UNSAT_DEPTH[cellLoc],HP_DOM_AEROBTHIN[HAB[cellLoc]]),HP_DOM_MAXDEPTH[HAB[cellLoc]]);
00577      DOM_SED_ANAEROB_Z[cellLoc]  = HP_DOM_MAXDEPTH[HAB[cellLoc]]-DOM_SED_AEROB_Z[cellLoc];
00578 
00579                      /* GP_calibDecomp is an adjustable calib parm  */
00580      DOM_DECOMP_POT[cellLoc]  = (double) GP_calibDecomp*GP_DOM_RCDECOMP*DOM_QUALITY_CF[cellLoc]*DOM_TEMP_CF[cellLoc]*DEPOS_ORG_MAT[cellLoc]
00581          *(Min(DOM_SED_AEROB_Z[cellLoc]/HP_DOM_MAXDEPTH[HAB[cellLoc]],1.0)*soil_MOIST_CF[cellLoc]
00582          +GP_DOM_DECOMPRED*Min(DOM_SED_ANAEROB_Z[cellLoc]/HP_DOM_MAXDEPTH[HAB[cellLoc]],1.0) );
00583      DOM_DECOMP[cellLoc]  =  
00584          ( (DOM_DECOMP_POT[cellLoc])*DT>DEPOS_ORG_MAT[cellLoc] ) ? 
00585          ( (DEPOS_ORG_MAT[cellLoc])/DT ) : 
00586          ( DOM_DECOMP_POT[cellLoc]);
00587 /* calc state var (kg OM/m2) */
00588      DEPOS_ORG_MAT[cellLoc] =  DEPOS_ORG_MAT[cellLoc] + 
00589          ( DOM_fr_nphBio[cellLoc] + DOM_FR_FLOC[cellLoc] 
00590          - DOM_DECOMP[cellLoc] ) * DT;
00591 
00592 /* soil elevation */
00593      DOM_Z[cellLoc] = (double) DEPOS_ORG_MAT[cellLoc] / DOM_BD[cellLoc] ; /* (m) organic depth  */
00594      SED_ELEV[cellLoc]  = DOM_Z[cellLoc]+Inorg_Z[cellLoc]+SED_INACT_Z[cellLoc];  /* total land surface elevation, including model GP_DATUM_DISTANCE below zero of land elev datum (NGVD/NAVD) (m) */
00595 
00596 /* P DOM stoich (kg P /m2) */
00597      DOP_nphBio[cellLoc] = nphbio_mort_P[cellLoc];    
00598      DOP_FLOC[cellLoc] = FlocP_DEPO[cellLoc]; 
00599 
00600      DOP_DECOMP[cellLoc] = (double) DOM_DECOMP[cellLoc] * DOM_P_OM[cellLoc]; 
00601 
00602 /* calc state var of total "organic" P in soil (NOT including dissolved in pore water or sorbed) (kgP/m2) */
00603      DOP[cellLoc] =  DOP[cellLoc]  
00604          + ( DOP_nphBio[cellLoc]  + DOP_FLOC[cellLoc] 
00605          - DOP_DECOMP[cellLoc]) * DT; /* kgP/m2 */
00606 
00607 /* now the P ratio */
00608      DOM_P_OM[cellLoc] = (DEPOS_ORG_MAT[cellLoc]>0.0) ? ( DOP[cellLoc] / DEPOS_ORG_MAT[cellLoc]) : (0.0); /* kgP/kgOM */
00609      TPsoil = DOP[cellLoc]*CELL_SIZE + TP_SORB[cellLoc]; /* kg TP in soil */
00610      TPtoSOIL[cellLoc] = ((DEPOS_ORG_MAT[cellLoc]*CELL_SIZE + DIM[cellLoc])>0.0) ?
00611          (  TPsoil / (DEPOS_ORG_MAT[cellLoc]*CELL_SIZE + DIM[cellLoc]) ) : (0.0); /* kgP/kgsoil */
00612      TPtoVOL[cellLoc] =  (CELL_SIZE * DOM_Z[cellLoc]>0.0) ?
00613          (TPsoil / (CELL_SIZE * DOM_Z[cellLoc]) ) :
00614          (0.0); /* kgP/m3 soil */
00615          
00616      TPtoSOIL_rep[cellLoc] = TPtoSOIL[cellLoc] * conv_kgTOmg; /* reporting purposes only (kg/kg->mg/kg) */
00617      TPtoVOL_rep[cellLoc] = TPtoVOL[cellLoc] * conv_kgTOg; /* reporting purposes only (kg/m3->g/m3 == ug/cm3) */
00618 
00619 /* now the P gain in sed water with decomp
00620  a small proportion goes into surface water P (below) */
00621      TP_sedMin  =  (1.0 - HP_DOM_AEROBTHIN[HAB[cellLoc]]  / HP_DOM_MAXDEPTH[HAB[cellLoc]] )
00622           * DOP_DECOMP[cellLoc] * CELL_SIZE;
00623                  
00624 /* calc P in sed water state variables (kg P) */
00625      TP_SED_WT[cellLoc] =  TP_SED_WT[cellLoc] + TP_sedMin * DT;
00626              /* this is the active zone, where uptake, sorption, and mineralization take place */
00627      TP_SED_WT_AZ[cellLoc] =  TP_SED_WT_AZ[cellLoc] + TP_sedMin * DT;
00628 
00629      TP_SED_CONC[cellLoc] = (HYD_SED_WAT_VOL[cellLoc]>0.0) ?
00630           (TP_SED_WT[cellLoc] / HYD_SED_WAT_VOL[cellLoc]) :
00631           (0.0);
00632      TP_SEDWT_CONCACT[cellLoc] = ( HYD_DOM_ACTWAT_PRES[cellLoc] > 0.0) ?
00633           ( TP_SED_WT_AZ[cellLoc]/HYD_DOM_ACTWAT_VOL[cellLoc] ) :
00634           (TP_SED_CONC[cellLoc]); /* g/L */
00635      TP_SEDWT_CONCACTMG[cellLoc]  = TP_SEDWT_CONCACT[cellLoc]*conv_kgTOg; /* g/m3==mg/L */
00636               
00637 /* now store the ratio of the conc in the active zone relative to total, prior to horiz fluxes
00638 ***** very simple constant, code in transition **** */              
00639      TP_Act_to_Tot[cellLoc] = 1.0 / HP_TP_CONC_GRAD[HAB[cellLoc]];
00640      TP_Act_to_TotRep[cellLoc] =  (float) TP_Act_to_Tot[cellLoc];
00641                  
00642 /* now the P gain in surface water with decomp in the very thin upper layer of the soil */
00643                      /* if there is no surface water present, assume that this
00644                         relative contribution will be an additional sorbed component that
00645                         is introduced to surface water column immediately upon hydration
00646                         with surface water */
00647      TP_sfMin  =  HP_DOM_AEROBTHIN[HAB[cellLoc]] / HP_DOM_MAXDEPTH[HAB[cellLoc]]
00648            * DOP_DECOMP[cellLoc] * CELL_SIZE;
00649                  
00650 /* calc P in surface water state variable (kg P) */
00651      TP_SF_WT[cellLoc] = TP_SF_WT[cellLoc] + TP_sfMin * DT;
00652      TP_SFWT_CONC[cellLoc]  = 
00653            ( SFWT_VOL[cellLoc] > 0.0 ) ? 
00654            ( TP_SF_WT[cellLoc]/SFWT_VOL[cellLoc] ) : 
00655            ( 0.0); /* used in P fluxes for mass balance */
00656      TP_SFWT_CONC_MG[cellLoc]  = 
00657            ( SURFACE_WAT[cellLoc] > GP_WQualMonitZ ) ? 
00658            (TP_SFWT_CONC[cellLoc]*conv_kgTOg) : 
00659            (0.0); /* (g/m3==mg/L) used for reporting and other modules to evaluate P conc when water is present */
00660 
00661 /* for reporting only: calc sum of all P storages in grid cells (budget calcs do same for Basin/Indicator-Regions) (g P /m^2) */
00662      P_SUM_CELL[cellLoc] = ( (C_ALG_P[cellLoc] + NC_ALG_P[cellLoc]) * 0.001 * CELL_SIZE + /* gP/m2 => kgP */
00663            (mac_nph_P[cellLoc] + mac_ph_P[cellLoc] )* CELL_SIZE + /* kgP/m2 => kgP */
00664            TP_SORB[cellLoc] +
00665            ( FlocP[cellLoc] + DOP[cellLoc]  ) * CELL_SIZE + /* kgP/m2 => kgP */
00666            TP_SED_WT[cellLoc] + TP_SF_WT[cellLoc] ) /* kgP */
00667            /CELL_SIZE * conv_kgTOg; /* kg P/m^2 => g P/m^2 */
00668                  
00669     }
00670   }
00671   }
00672 }
00673 
00674 
00675 /*******/
00682 void horizFlow(int step)
00683 {
00684   int it;
00685   int ix, iy; 
00686  
00687   /* v2.7.0 adding velocity output capabilities */
00688   for(ix=1; ix<=s0; ix++) {
00689     for(iy=1; iy<=s1; iy++) {
00690       if(ON_MAP[T(ix,iy)])  SF_WT_VEL_mag[T(ix,iy)]=0.0; 
00691     }
00692   }
00693 
00694   for ( it = 0; it < hyd_iter; it++ )
00695   {
00696     sprintf(msgStr,"\b\b\b%3d",it); 
00697     usrErr0(msgStr);
00698        
00699     /* horizontal raster-vector canal fluxes and water management functions
00700        Water Management switch set at runtime in Driver.parm
00701        this routine also integrates surface, unsaturated, and saturated exchanges
00702      */
00703     /* Nitrogen (DINdummy) argument is dummy argument placeholder */
00704         if (WatMgmtOn  ) {
00705       Run_Canal_Network(SURFACE_WAT,SED_ELEV,HYD_MANNINGS_N,SAT_WATER,HP_HYD_POROSITY,
00706                         HYD_RCCONDUCT, DINdummy,TP_SF_WT,SALT_SURF_WT,DINdummy,TP_SED_WT,SALT_SED_WT,
00707                         UNSAT_WATER,HP_HYD_SPEC_YIELD ); 
00708     }
00709     
00710 
00711     /* Function for horiz fluxing of surface water, no exchange with sat/unsat water */
00712     /* if the order of the solute is changed, be sure to change the mass bal info in FluxSWstuff fcn */
00713     /* Nitrogen (DINdummy) argument is dummy argument placeholder */
00714     Flux_SWater(it,SURFACE_WAT,SED_ELEV,HYD_MANNINGS_N,SALT_SURF_WT,DINdummy,TP_SF_WT,SF_WT_VEL_mag);       
00715   
00716     /* Function for horiz fluxing of ground water and its vertical itegration with unsat and surface water 
00717        It is only called every other hyd_iter iteration, and passes the realized number of gwat iterations to the function.  
00718        If the order of the solutes is changed, be sure to change the mass bal info in FluxGWstuff fcn 
00719      */
00720     /* Nitrogen (DINdummy) argument is dummy argument placeholder */
00721     if ( it%2 ) 
00722       Flux_GWater((it-1)/2, SAT_WATER, UNSAT_WATER, SURFACE_WAT, HYD_RCCONDUCT, HP_HYD_POROSITY,
00723                    HP_HYD_SPEC_YIELD, SED_ELEV, SALT_SED_WT, DINdummy, TP_SED_WT, SALT_SURF_WT, DINdummy, TP_SF_WT);  
00724 
00725   }  /* end of hyd_iter */  
00726   
00727    /* v2.7.0 adding velocity output capabilities */
00728   for(ix=1; ix<=s0; ix++) {
00729     for(iy=1; iy<=s1; iy++) {
00730        SF_WT_VEL_mag[T(ix,iy)]= SF_WT_VEL_mag[T(ix,iy)] / hyd_iter / 2.0; /* v2.8.4 - no changes, but explored the /hyd_iter/2.0 etc */
00731      }
00732   }
00733 
00734 }
00735 
00736 
00737 
00738 /*******/
00748 /*
00749   SURFACE_WAT[cellLoc] == water storage above the land surface elevation (meters)
00750   UNSAT_WATER[cellLoc] == water storage in the pore spaces of the unsaturated zone (meters)
00751   SAT_WATER[cellLoc] == water storage in the pore spaces of the saturated zone (meters)
00752   
00753 
00754 Parameter definitions:
00755       global parameters in GlobalParms.xls Excel sheet (text export=GlobalParms)
00756       habitat-specific parameters in HabParms.fmp FileMakerPro database (text export=HabParms)
00757 ******/
00758 void cell_dyn7(int step)
00759  {
00760     int ix, iy, cellLoc; 
00761     float SatWat_Root_CF, field_cap; 
00762     float mann_height, N_density, f_LAI_eff, sfwat_pr1;
00763     float cloudy=0.0;
00764     
00765 /* the horizontal raster and vector fluxes are always called before this cell_dyn */
00766     for(ix=1; ix<=s0; ix++) {
00767         for(iy=1; iy<=s1; iy++) {
00768             if(ON_MAP[cellLoc= T(ix,iy)])  {
00769 
00770               if (debug > 3) { /* these are old, relatively coarse checks - surface-ground water integration occurs in Fluxes.c */
00771                   if (SAT_WT_HEAD[cellLoc] - 0.01 > SED_ELEV[cellLoc] ) {
00772                       sprintf(msgStr,"Day %6.1f. Warning - SAT_WT_HEAD exceeds elev in cell (%d,%d) by %f.", 
00773                               SimTime.TIME, ix,iy,(SAT_WT_HEAD[cellLoc] - SED_ELEV[cellLoc]) ); 
00774                       WriteMsg( msgStr,True ); }
00775                   if (SURFACE_WAT[cellLoc] > 0.2 && UNSAT_DEPTH[cellLoc] > 0.1 ) {
00776                       sprintf(msgStr,"Day: %6.1f.  Warning - large sfwat depth (%5.2f m) in presence of unsat= %5.2f m, %4.2f %% moist, in cell (%d,%d).", 
00777                               SimTime.TIME, SURFACE_WAT[cellLoc], UNSAT_DEPTH[cellLoc],UNSAT_MOIST_PRP[cellLoc], ix,iy ); 
00778                       WriteMsg( msgStr,True );  }
00779                   if (SAT_WATER[cellLoc] < -0.01) { /* this seems unnecessary but... */
00780                       sprintf(msgStr,"Day %6.1f: capacityERR - neg SAT_WATER (%f m) in cell (%d,%d) before cell_dyn7!", 
00781                               SimTime.TIME, SAT_WATER[cellLoc], ix,iy ); 
00782                       WriteMsg( msgStr,True );  dynERRORnum++; }
00783                   if (SURFACE_WAT[cellLoc] < -0.01) {
00784                       sprintf(msgStr,"Day %6.1f: capacityERR - neg SURFACE_WAT (%f m) in cell (%d,%d) before cell_dyn7!", 
00785                               SimTime.TIME, SURFACE_WAT[cellLoc], ix,iy ); 
00786                       WriteMsg( msgStr,True );  dynERRORnum++; }
00787               }
00788 
00789 /*  note that rainfall during a time step is added to surface water storage and available */
00790 /* for runoff (horizFlow) before the calc of infiltration & ET associated with that new input */
00791 /* (infiltration/ET etc will be of avail water the next time step after a rainfall event and horiz flows) */
00792                   /* NSM/SFWMM rainfall input data, created in cell_dyn1, convert here from tenths of mm to meters */
00793               SF_WT_FROM_RAIN[cellLoc] = boundcond_rain[cellLoc]*0.0001;  /*  tenths of mm *0.0001 = m */
00794 
00795               /* solar radiation at altitude of 274m in atmosphere cal/cm2/d) */
00796               /* v2.2+, CLOUDY (cloudiness) spatiotemporal data "temporarily" unavailable, is constant in space and time, local var "cloudy" */
00797               SOLRAD274[cellLoc] = SOLRADATMOS*(SOLBETA-GP_SOLOMEGA* ( ( cloudy>0.0 ) ? ( cloudy ) : ( 0.0) ) ) -SOLALPHA;
00798               SOLRADGRD[cellLoc] = SOLRAD274[cellLoc]+((SOLRADATMOS+1.0)-SOLRAD274[cellLoc])*SOLALTCORR;
00799               H2O_TEMP[cellLoc] = AIR_TEMP[cellLoc]; /* v2.2+, temperature data "temporarily" unavailable, is constant in space and time */
00800               
00801 /******** determine new unsat potentials */
00802               SAT_WT_HEAD[cellLoc]  = SAT_WATER[cellLoc]/HP_HYD_POROSITY[HAB[cellLoc]];
00803               UNSAT_DEPTH[cellLoc]  = SED_ELEV[cellLoc]-SAT_WT_HEAD[cellLoc];
00804               UNSAT_CAP[cellLoc]  =  UNSAT_DEPTH[cellLoc]*HP_HYD_POROSITY[HAB[cellLoc]];
00805           
00806               UNSAT_MOIST_PRP[cellLoc]  = 
00807                   ( UNSAT_CAP[cellLoc]>0.0 ) ? 
00808                   ( Min(UNSAT_WATER[cellLoc]/UNSAT_CAP[cellLoc],1.0) ) : 
00809                   ( 1.0); 
00810                   /* determining the pathway of flow of surface water depending on depth
00811                      of an unsat zone relative to the surface water  */ 
00812               SAT_VS_UNSAT[cellLoc]  = 1/Exp(100.0*Max((SURFACE_WAT[cellLoc]-UNSAT_DEPTH[cellLoc]),0.0)); 
00813      /* empirical data of a (0-1) control function, the proportion of maximum vertical water infiltration rate through soil (dependent var) as a function of soil moisture proportion (0-1)  (independent var) */
00814               UNSAT_HYD_COND_CF[cellLoc]  = graph7(0x0,UNSAT_MOIST_PRP[cellLoc] ); 
00815                      /* field capacity = porosity - specific yield; spec yield== proportion of total soil vol
00816                             that represents water that can be moved by gravity */
00817               field_cap = (HP_HYD_POROSITY[HAB[cellLoc]]-HP_HYD_SPEC_YIELD[HAB[cellLoc]]);
00818                   /* unsat_avail is proportion of water in pore space available for gravitational flow (above field capacity) */
00819                   /* e.g., when moisture prop in pore space <= field_cap/pore_space, no percolation */
00820                   /* using old moisture proportion (hasn't changed unless unsat zone was replaced by sat water) */
00821               UNSAT_AVAIL[cellLoc]  = Max(UNSAT_MOIST_PRP[cellLoc]
00822                                           -(field_cap)/HP_HYD_POROSITY[HAB[cellLoc]],0.0);
00823               UNSAT_WT_POT[cellLoc]  = Max(UNSAT_CAP[cellLoc]-UNSAT_WATER[cellLoc],0.0);
00824 
00825 /******** now determine the potential total transpiration and evaporation  */
00826 /* Potential ET is input data used in SFWMM v5.4 */
00827 /* GP_calibET is an adjustable calibration parameter (close to 1.0, adjusted in global parameter input file)  */
00828              HYD_EVAP_CALC[cellLoc]  =  boundcond_ETp[cellLoc] * 0.0001*GP_calibET;  /*  tenths of mm *0.0001 = m */
00829 
00830     /*  Leaf Area Index (LAI) of emergent macrophytes: this effective LAI estimates leaf area index that is above ponded surface water  */
00831               LAI_eff[cellLoc] =  
00832                   (MAC_HEIGHT[cellLoc]>0.0) ? 
00833                   (Max(1.0 - SURFACE_WAT[cellLoc]/MAC_HEIGHT[cellLoc], 0.0)*MAC_LAI[cellLoc]) : 
00834                   (0.0)  ;
00835  
00836           /* control function (0-1) of relative magnitude of the effective Leaf Area Index  */
00837               f_LAI_eff = exp(-LAI_eff[cellLoc]); 
00838               
00839               
00840               HYD_TOT_POT_TRANSP[cellLoc]  = HYD_EVAP_CALC[cellLoc] * (1.0-f_LAI_eff); 
00841 
00842      /* 0-1 control function of saturated water available to roots - capillary draw when roots don't quite reach down to water table */
00843               SatWat_Root_CF =  Exp(-10.0* Max(UNSAT_DEPTH[cellLoc]-HP_NPHBIO_ROOTDEPTH[HAB[cellLoc]],0.0) ); 
00844      /*  HYDrologic, control function (0-1) of proportion of WATer in upper soil profile that is AVAILable for plant uptake, including unsaturated storage withdrawal, and small capillary withdrawal from saturated storage, depending on relative depths */
00845               HYD_WATER_AVAIL[cellLoc]  = (UNSAT_DEPTH[cellLoc] > HP_NPHBIO_ROOTDEPTH[HAB[cellLoc]] ) ? 
00846                   ( Max(UNSAT_MOIST_PRP[cellLoc], SatWat_Root_CF) ) :
00847                   ( 1.0 ); 
00848     /* empirical data of a (0-1) control function, the proportion of water available to plants (dependent var) as a function of proportion (0-1) of water available upper soil profile (independent var) (generally, simply 1:1 relationship) */
00849               MAC_WATER_AVAIL_CF[cellLoc]  = graph8(0x0,HYD_WATER_AVAIL[cellLoc]); 
00850 
00851 /******** next calc the potential and actual flows */
00852 /* unsatLoss(1) unsat to sat percolation */
00853   /*unsat to sat flow here only includes percolation (rising water table accomodated in update after horiz fluxes) */ 
00854               UNSAT_PERC[cellLoc]  = Min(HP_HYD_RCINFILT[HAB[cellLoc]]*UNSAT_HYD_COND_CF[cellLoc],UNSAT_AVAIL[cellLoc]*UNSAT_WATER[cellLoc]);
00855               UNSAT_TO_SAT_FL[cellLoc]  =  
00856                   ( (UNSAT_PERC[cellLoc])*DT > UNSAT_WATER[cellLoc] ) ? 
00857                   ( UNSAT_WATER[cellLoc]/DT ) : 
00858                   ( UNSAT_PERC[cellLoc]);
00859 /* unsatLoss(2) unsat to atmosph transpiration */
00860               HYD_UNSAT_POT_TRANS[cellLoc]  = (UNSAT_DEPTH[cellLoc] > HP_NPHBIO_ROOTDEPTH[HAB[cellLoc]] ) ?
00861                   ( HYD_TOT_POT_TRANSP[cellLoc]*MAC_WATER_AVAIL_CF[cellLoc] ) :
00862                   (0.0); /* no unsat transp if roots are in saturated zone */
00863               UNSAT_TRANSP[cellLoc]  = 
00864                   ( (HYD_UNSAT_POT_TRANS[cellLoc]+UNSAT_TO_SAT_FL[cellLoc])*DT>UNSAT_WATER[cellLoc] ) ? 
00865                   ( (UNSAT_WATER[cellLoc]-UNSAT_TO_SAT_FL[cellLoc]*DT)/DT ) : 
00866                   ( HYD_UNSAT_POT_TRANS[cellLoc]);
00867 
00868 /* satLoss(1) sat to deep aquifer recharge **RATE parameter IS ALWAYS SET to ZERO  *****/
00869               SAT_WT_RECHG[cellLoc]  = 
00870                   ( GP_HYD_RCRECHG*HP_HYD_SPEC_YIELD[HAB[cellLoc]]/HP_HYD_POROSITY[HAB[cellLoc]]*DT>SAT_WATER[cellLoc] ) ? 
00871                   ( SAT_WATER[cellLoc]/DT ) : 
00872                   ( GP_HYD_RCRECHG*HP_HYD_SPEC_YIELD[HAB[cellLoc]]/HP_HYD_POROSITY[HAB[cellLoc]]); 
00873                  
00874 /* sat to surf upflow  when gwater exceeds soil capacity due to lateral inflows
00875    accomodated in gwFluxes */
00876 
00877 /* satLoss(2) sat to unsat with lowering water table due to recharge loss ONLY (horiz outflows accomodated in gwFluxes)
00878    (leaves field capacity amount in unsat zone)*/
00879               SAT_TO_UNSAT_FL[cellLoc]  =  
00880                   ( SAT_WT_RECHG[cellLoc]*field_cap/HP_HYD_POROSITY[HAB[cellLoc]]*DT > SAT_WATER[cellLoc] ) ? 
00881                   ( (SAT_WATER[cellLoc])/DT ) : 
00882                   ( SAT_WT_RECHG[cellLoc]*field_cap/HP_HYD_POROSITY[HAB[cellLoc]]) ;
00883 /* satLoss(3) sat to atmosph */
00884               HYD_SAT_POT_TRANS[cellLoc]  = HYD_TOT_POT_TRANSP[cellLoc]*SatWat_Root_CF; 
00885               SAT_WT_TRANSP[cellLoc]  =  
00886                   ( (HYD_SAT_POT_TRANS[cellLoc]+SAT_TO_UNSAT_FL[cellLoc])*DT > SAT_WATER[cellLoc] ) ? 
00887                   ( (SAT_WATER[cellLoc]-SAT_TO_UNSAT_FL[cellLoc]*DT)/DT ) : 
00888                   ( HYD_SAT_POT_TRANS[cellLoc]);
00889 
00890 /* sfwatLoss(1) sf to sat */
00891                      /* downflow to saturated assumed to occur in situations with small
00892                         unsat layer overlain by significant surface water (SAT_VS_UNSAT very small),
00893                         with immediate hydraulic connectivity betweent the two storages */
00894               SF_WT_TO_SAT_DOWNFLOW[cellLoc]  = 
00895                   ( (1.0-SAT_VS_UNSAT[cellLoc])*UNSAT_WT_POT[cellLoc]*DT>SURFACE_WAT[cellLoc] ) ? 
00896                   ( SURFACE_WAT[cellLoc]/DT ) : 
00897                   ( (1.0-SAT_VS_UNSAT[cellLoc])*UNSAT_WT_POT[cellLoc]); 
00898 /* sfwatLoss(2) sf to unsat infiltration (sat_vs_unsat splits these losses to groundwater, but downflow to sat is given priority) */
00899               SF_WT_POT_INF[cellLoc]  = 
00900                   ( (SAT_VS_UNSAT[cellLoc]*HP_HYD_RCINFILT[HAB[cellLoc]]+SF_WT_TO_SAT_DOWNFLOW[cellLoc])*DT>SURFACE_WAT[cellLoc] ) ? 
00901                   ( (SURFACE_WAT[cellLoc]-SF_WT_TO_SAT_DOWNFLOW[cellLoc]*DT)/DT ) : 
00902                   ( SAT_VS_UNSAT[cellLoc]*HP_HYD_RCINFILT[HAB[cellLoc]]);
00903               SF_WT_INFILTRATION[cellLoc]  = 
00904                   ( SF_WT_POT_INF[cellLoc]*DT > (UNSAT_WT_POT[cellLoc]-SF_WT_TO_SAT_DOWNFLOW[cellLoc]*DT) ) ? 
00905                   ((UNSAT_WT_POT[cellLoc]-SF_WT_TO_SAT_DOWNFLOW[cellLoc]*DT)/DT ) : 
00906                   ( SF_WT_POT_INF[cellLoc]);
00907               sfwat_pr1 = SF_WT_INFILTRATION[cellLoc]+SF_WT_TO_SAT_DOWNFLOW[cellLoc];
00908 /* sfwatLoss(3) sf to atmosph */
00909               SF_WT_EVAP[cellLoc]  =  
00910                   ( (f_LAI_eff*HYD_EVAP_CALC[cellLoc]+sfwat_pr1 )*DT>SURFACE_WAT[cellLoc] ) ? 
00911                   ( (SURFACE_WAT[cellLoc]-sfwat_pr1*DT)/DT ) : 
00912                   ( f_LAI_eff*HYD_EVAP_CALC[cellLoc]); 
00913 
00914 
00915 /******** then update the state variable storages */
00916 
00917 /* unsat loss priority:  percolation,  transpiration */
00918 /* calc unsaturated storage state var (m) */
00919               UNSAT_WATER[cellLoc] = UNSAT_WATER[cellLoc] 
00920                   + (SAT_TO_UNSAT_FL[cellLoc] + SF_WT_INFILTRATION[cellLoc] 
00921                      - UNSAT_TO_SAT_FL[cellLoc] - UNSAT_TRANSP[cellLoc]) * DT;
00922 
00923 /* sat loss priority:  recharge to deep aquifer, re-assign to unsat with lowered water table, transpiration */
00924 /* calc saturated storage state var (m) */
00925               SAT_WATER[cellLoc] =  SAT_WATER[cellLoc] 
00926                   + (UNSAT_TO_SAT_FL[cellLoc] + SF_WT_TO_SAT_DOWNFLOW[cellLoc] 
00927                      - SAT_WT_TRANSP[cellLoc] - SAT_TO_UNSAT_FL[cellLoc] - SAT_WT_RECHG[cellLoc]) * DT;
00928 
00929 /* sfwat loss priority: downflow to replace groundwater loss, infiltration to unsat, evaporation */
00930 /* calc surface storage state var (m) */
00931               SURFACE_WAT[cellLoc] = SURFACE_WAT[cellLoc] 
00932                   + (SF_WT_FROM_RAIN[cellLoc]  
00933                      - SF_WT_EVAP[cellLoc] - SF_WT_INFILTRATION[cellLoc] - SF_WT_TO_SAT_DOWNFLOW[cellLoc]) * DT;
00934 
00935 /******** lastly, update of head calcs, unsat capacity, moisture proportion, etc.
00936  in order to calc water in diff storages for solute concentrations */
00937               SAT_WT_HEAD[cellLoc]  = SAT_WATER[cellLoc]/HP_HYD_POROSITY[HAB[cellLoc]];
00938               UNSAT_DEPTH[cellLoc]  = Max(SED_ELEV[cellLoc]-SAT_WT_HEAD[cellLoc],0.0);
00939               UNSAT_CAP[cellLoc]  =  UNSAT_DEPTH[cellLoc]*HP_HYD_POROSITY[HAB[cellLoc]];
00940 
00941               UNSAT_MOIST_PRP[cellLoc]  = 
00942                   ( UNSAT_CAP[cellLoc]>0.0 ) ? 
00943                   ( Min(UNSAT_WATER[cellLoc]/UNSAT_CAP[cellLoc],1.0) ) : 
00944                   ( 1.0); 
00945               HYD_DOM_ACTWAT_VOL[cellLoc]  = ( Min(HP_DOM_MAXDEPTH[HAB[cellLoc]],UNSAT_DEPTH[cellLoc])*UNSAT_MOIST_PRP[cellLoc] +
00946                                                Max(HP_DOM_MAXDEPTH[HAB[cellLoc]]-UNSAT_DEPTH[cellLoc], 0.0)*HP_HYD_POROSITY[HAB[cellLoc]] )
00947                   *CELL_SIZE; 
00948                   /* flag for presence of small amount of water storage in the active zone must be present */ 
00949               HYD_DOM_ACTWAT_PRES[cellLoc]  = 
00950                   ( HYD_DOM_ACTWAT_VOL[cellLoc] > CELL_SIZE*GP_DetentZ ) ? 
00951                   ( 1.0 ) : ( 0.0); 
00952               HYD_SED_WAT_VOL[cellLoc]  = (SAT_WATER[cellLoc]+UNSAT_WATER[cellLoc])*CELL_SIZE;
00953               SFWT_VOL[cellLoc]  = SURFACE_WAT[cellLoc]*CELL_SIZE;
00954 
00955               HydTotHd[cellLoc]  = SAT_WT_HEAD[cellLoc]+SURFACE_WAT[cellLoc]; /* only used for reporting purposes */
00956               /* v2.8.2 new variable, for reporting purposes only: positive/negative water depth relative to land elevation (stage minus land elevation) */
00957               HydRelDepPosNeg[cellLoc] =  HydTotHd[cellLoc] - SED_ELEV[cellLoc];
00958               
00959                   /* at the square of xx% of the macrophyte's height, the manning's n
00960                      calc will indicate the macrophyte *starting* to bend over,
00961                      starting to offer increasingly less resistance */
00962               mann_height = (GP_mann_height_coef*MAC_HEIGHT[cellLoc])*(GP_mann_height_coef*MAC_HEIGHT[cellLoc]); 
00963               N_density = Max(HP_MAC_MAXROUGH[HAB[cellLoc]] * MAC_REL_BIOM[cellLoc], HP_MAC_MINROUGH[HAB[cellLoc]] );
00964                   /* manning's n for overland (horiz) flow */
00965               mann_height = Max(mann_height,0.01); /* ensure that even in absence of veg, there is  miniscule (1 cm in model grid cell) height related to some form of veg */   
00966               HYD_MANNINGS_N[cellLoc]  = Max(-Abs((N_density-HP_MAC_MINROUGH[HAB[cellLoc]])
00967                                                   *(pow(2.0,(1.0-SURFACE_WAT[cellLoc]/mann_height))-1.0) ) 
00968                                              + N_density,HP_MAC_MINROUGH[HAB[cellLoc]]);
00969 
00970                   /* sum of transpiration for output only */
00971               HYD_TRANSP[cellLoc]  = UNSAT_TRANSP[cellLoc]+SAT_WT_TRANSP[cellLoc];
00972               HYD_ET[cellLoc]  = HYD_TRANSP[cellLoc]+SF_WT_EVAP[cellLoc];
00973 
00974             }
00975   }
00976     }
00977  }
00978 
00979 
00980 /*******/
00986 /*   MAC_NOPH_BIOMAS[cellLoc] == carbon mass of live Non-Photosynthetic tissues of macrophytes (kgC/m^2)
00987    MAC_PH_BIOMAS[cellLoc] == carbon mass of live Photosynthetic tissues of macrophytes (kgC/m^2)
00988 
00989    mac_nph_P[cellLoc] == phosphorus mass of live Non-Photosynthetic tissues of macrophytes (kgP/m^2)
00990    mac_ph_P[cellLoc] == phosphorus mass of live Photosynthetic tissues of macrophytes (kgP/m^2)
00991 
00992    mac_nph_OM[cellLoc] == organic matter mass of live Non-Photosynthetic tissues of macrophytes (kgOM/m^2)
00993    mac_ph_OM[cellLoc] == organic matter mass of live Photosynthetic tissues of macrophytes (kgOM/m^2)
00994 
00995 spatial (cell) location defines habitat ( arrayOf[HAB[cellLoc]] );
00996 habitat type can switch when global dynamic function (in cell_dyn1) calls the succession function
00997 
00998 Parameter definitions:
00999       global parameters in GlobalParms.xls Excel sheet (text export=GlobalParms)
01000       habitat-specific parameters in HabParms.fmp FileMakerPro database (text export=HabParms)
01001 */
01002 void cell_dyn8(int step)
01003  {
01004 int ix, iy, cellLoc; 
01005 float reduc, NPP_P, min_litTemp, nphbio_ddep, phbio_ddep, MAC_PHtoNPH, MAC_PHtoNPH_Init;
01006 float Sal_Mean;
01007 #define salinLow 0.1 /* v2.8.5 minimal salinity value (mg/L=ppt), below which growth isn't really affected for any macrophyre species */
01008 
01009 
01010   for(ix=1; ix<=s0; ix++) {
01011   for(iy=1; iy<=s1; iy++) {
01012 
01013     if(ON_MAP[cellLoc= T(ix,iy)])  { 
01014               
01015 /* these thresholds need updating when a habitat type of a grid cell changes */
01016       MAC_MAX_BIO[cellLoc] = HP_NPHBIO_MAX[HAB[cellLoc]]+HP_PHBIO_MAX[HAB[cellLoc]];
01017       NPHBIO_REFUGE[cellLoc] = HP_NPHBIO_MAX[HAB[cellLoc]]*GP_MAC_REFUG_MULT;
01018       NPHBIO_SAT[cellLoc] = HP_NPHBIO_MAX[HAB[cellLoc]]*0.9;
01019       PHBIO_REFUGE[cellLoc] = HP_PHBIO_MAX[HAB[cellLoc]]*GP_MAC_REFUG_MULT;
01020       PHBIO_SAT[cellLoc] = HP_PHBIO_MAX[HAB[cellLoc]]*0.9;
01021 /* various control functions for production calc */
01022      MAC_LIGHT_CF[cellLoc]  = SOLRADGRD[cellLoc]/HP_MAC_LIGHTSAT[HAB[cellLoc]]
01023          *Exp(1.0-SOLRADGRD[cellLoc]/HP_MAC_LIGHTSAT[HAB[cellLoc]]);
01024      MAC_TEMP_CF[cellLoc]  = tempCF(0, 0.20, HP_MAC_TEMPOPT[HAB[cellLoc]], 5.0, 40.0, AIR_TEMP[cellLoc]);
01025      HP_MAC_WAT_TOLER[HAB[cellLoc]] = Max(HP_MAC_WAT_TOLER[HAB[cellLoc]],0.005); /* water tolerance is supposed to be non-zero; set to 5mm if user input a 0 */
01026      MAC_WATER_CF[cellLoc]  = Min(MAC_WATER_AVAIL_CF[cellLoc], 
01027          Max(1.0-Max( (SURFACE_WAT[cellLoc]-HP_MAC_WAT_TOLER[HAB[cellLoc]])
01028          /HP_MAC_WAT_TOLER[HAB[cellLoc]],0.0),0.0));
01029      MAC_NUT_CF[cellLoc]  = 
01030                      Exp(-GP_mac_uptake_coef * Max(HP_MAC_KSP[HAB[cellLoc]]-TP_SEDWT_CONCACTMG[cellLoc], 0.0)
01031                          /HP_MAC_KSP[HAB[cellLoc]]) ; /* mg/L */
01032 /* v2.8.5, re-instituted use of salinity control on mac production */
01033 /* NOTE the placeholder salinity CF here !!! */
01034      Sal_Mean  = (SAL_SED_WT[cellLoc]+SAL_SF_WT[cellLoc])/2.0; 
01035      MAC_SALT_CF[cellLoc]  =  (Sal_Mean > HP_MAC_SALIN_THRESH[HAB[cellLoc]]) ? (Max(1.0-0.1*Sal_Mean/HP_MAC_SALIN_THRESH[HAB[cellLoc]],0.0) ) : (1.0);
01036      Max( 1.0-Max(Sal_Mean-(HP_MAC_SALIN_THRESH[HAB[cellLoc]]+salinLow),0.0)/(HP_MAC_SALIN_THRESH[HAB[cellLoc]]+salinLow), 0.0)  ; 
01037 
01038      min_litTemp = Min(MAC_LIGHT_CF[cellLoc], MAC_TEMP_CF[cellLoc]);
01039      MAC_PROD_CF[cellLoc]  = Min(min_litTemp,MAC_WATER_CF[cellLoc])
01040           *MAC_NUT_CF[cellLoc] *MAC_SALT_CF[cellLoc];
01041 /* net primary production, kg C/m2/d */
01042      PHBIO_NPP[cellLoc]  = HP_PHBIO_RCNPP[HAB[cellLoc]]*MAC_PROD_CF[cellLoc]*MAC_PH_BIOMAS[cellLoc]
01043          * Max( (1.0-MAC_TOT_BIOM[cellLoc]/MAC_MAX_BIO[cellLoc]), 0.0);
01044 /* P uptake is dependent on available P and relative to a maximum P:C ratio for the tissue (kg C/m^2/d * P:Cmax * dimless = kgP/m2/d ) */
01045      NPP_P = PHBIO_NPP[cellLoc]  * HP_PHBIO_IC_PC[HAB[cellLoc]]  * Max(MAC_NUT_CF[cellLoc]*2.0,1.0)
01046                      * Max(1.0-mac_ph_PC[cellLoc]/HP_PHBIO_IC_PC[HAB[cellLoc]], 0.0);
01047 /* check for available P mass that will be taken up from sed water in active zone (nutCF does not); v2.5 constrained TP_SED_WT_AZ to pos */
01048      reduc = (NPP_P > 0.0) ? 
01049                      (Max(TP_SED_WT_AZ[cellLoc],0.0) / ( NPP_P*CELL_SIZE*DT) ) : /* within-plant variable stoichiometry */
01050                      (1.0);
01051     /* reduce the production proportionally if excess demand is found */
01052                 /* can have high conc, but low mass of P avail, in presence of high plant biomass and high demand */
01053      if (reduc < 1.0) {
01054                      PHBIO_NPP[cellLoc] *= reduc;
01055                      NPP_P *= reduc;
01056                  }
01057                  
01058 /* losses from photobio */
01059      phbio_ddep = Max(1.0-Max( (PHBIO_SAT[cellLoc]-MAC_PH_BIOMAS[cellLoc]) 
01060                                            /(PHBIO_SAT[cellLoc]-PHBIO_REFUGE[cellLoc]),0.0),0.0);
01061      PHBIO_AVAIL[cellLoc]  = MAC_PH_BIOMAS[cellLoc]*phbio_ddep;
01062      MAC_PHtoNPH_Init = HP_PHBIO_MAX[HAB[cellLoc]] / HP_NPHBIO_MAX[HAB[cellLoc]] ; /*if habitat type changes */
01063      MAC_PHtoNPH = (MAC_NOPH_BIOMAS[cellLoc]>0.0) ? ( MAC_PH_BIOMAS[cellLoc] / MAC_NOPH_BIOMAS[cellLoc]) : (MAC_PHtoNPH_Init);
01064                  
01065      NPHBIO_TRANSLOC_POT[cellLoc]  = (MAC_PHtoNPH>MAC_PHtoNPH_Init) ?
01066                      (exp(HP_MAC_TRANSLOC_RC[HAB[cellLoc]] *(MAC_PHtoNPH-MAC_PHtoNPH_Init)) - 1.0) :
01067                      (0.0); 
01068      NPHBIO_TRANSLOC[cellLoc]  =  
01069          ( (NPHBIO_TRANSLOC_POT[cellLoc])*DT >PHBIO_AVAIL[cellLoc] ) ? 
01070          ( (PHBIO_AVAIL[cellLoc])/DT ) : 
01071          ( NPHBIO_TRANSLOC_POT[cellLoc]);
01072 
01073      PHBIO_MORT_POT[cellLoc]  = HP_PHBIO_RCMORT[HAB[cellLoc]] *PHBIO_AVAIL[cellLoc] 
01074          *(1.0 + (1.0-MAC_WATER_AVAIL_CF[cellLoc]) )/2.0;
01075      PHBIO_MORT[cellLoc]  =
01076                                 ( (PHBIO_MORT_POT[cellLoc]+NPHBIO_TRANSLOC[cellLoc])*DT>PHBIO_AVAIL[cellLoc] ) ? 
01077          ( (PHBIO_AVAIL[cellLoc]-NPHBIO_TRANSLOC[cellLoc]*DT)/DT ) : 
01078          ( PHBIO_MORT_POT[cellLoc]);
01079 
01080 
01081 /* losses from non-photobio  */
01082      nphbio_ddep = Max(1.0-Max((NPHBIO_SAT[cellLoc]-MAC_NOPH_BIOMAS[cellLoc])
01083                                           /(NPHBIO_SAT[cellLoc]-NPHBIO_REFUGE[cellLoc]),0.0),0.0);
01084      NPHBIO_AVAIL[cellLoc]  = MAC_NOPH_BIOMAS[cellLoc]*nphbio_ddep; 
01085 
01086                  PHBIO_TRANSLOC_POT[cellLoc]  = (MAC_PHtoNPH<MAC_PHtoNPH_Init) ?
01087                      (exp(HP_MAC_TRANSLOC_RC[HAB[cellLoc]] *(MAC_PHtoNPH_Init-MAC_PHtoNPH)) - 1.0) :
01088                      (0.0); 
01089      PHBIO_TRANSLOC[cellLoc]  =  
01090          ( (PHBIO_TRANSLOC_POT[cellLoc])*DT >NPHBIO_AVAIL[cellLoc] ) ? 
01091          ( (NPHBIO_AVAIL[cellLoc])/DT ) : 
01092          ( PHBIO_TRANSLOC_POT[cellLoc]);
01093      NPHBIO_MORT_POT[cellLoc]  = NPHBIO_AVAIL[cellLoc]*HP_PHBIO_RCMORT[HAB[cellLoc]]
01094                      * (1.0 + Max(1.0-MAC_PH_BIOMAS[cellLoc]/HP_PHBIO_MAX[HAB[cellLoc]],0.0) )/2.0; /* decreased mort w/ increasing photobio */
01095      NPHBIO_MORT[cellLoc]  =
01096                                 ( (PHBIO_TRANSLOC[cellLoc]+NPHBIO_MORT_POT[cellLoc])*DT>NPHBIO_AVAIL[cellLoc] ) ? 
01097          ( (NPHBIO_AVAIL[cellLoc]-PHBIO_TRANSLOC[cellLoc]*DT)/DT ) : 
01098          ( NPHBIO_MORT_POT[cellLoc]);
01099                  
01100 
01101 /* calc nonphotosynthetic biomass state var (kgC/m2) */
01102      MAC_NOPH_BIOMAS[cellLoc] =  MAC_NOPH_BIOMAS[cellLoc] 
01103                      + (NPHBIO_TRANSLOC[cellLoc] - NPHBIO_MORT[cellLoc] 
01104                         - PHBIO_TRANSLOC[cellLoc]  ) * DT;
01105                  
01106 /* calc nonphotosynthetic biomass state var (kgC/m2) */
01107      MAC_PH_BIOMAS[cellLoc] = MAC_PH_BIOMAS[cellLoc] 
01108          + (PHBIO_TRANSLOC[cellLoc] + PHBIO_NPP[cellLoc] 
01109            - PHBIO_MORT[cellLoc] - NPHBIO_TRANSLOC[cellLoc]) * DT;
01110 
01111 /* total biomass */
01112      MAC_TOT_BIOM[cellLoc]  = MAC_PH_BIOMAS[cellLoc]+MAC_NOPH_BIOMAS[cellLoc];
01113 /* book-keeping calcs used in other modules */
01114      MAC_REL_BIOM[cellLoc]  = 
01115          ( MAC_TOT_BIOM[cellLoc] > 0.0 ) ? 
01116          MAC_TOT_BIOM[cellLoc]/MAC_MAX_BIO[cellLoc] : 
01117          0.0001;
01118      MAC_HEIGHT[cellLoc]  = pow(MAC_REL_BIOM[cellLoc],0.33)*HP_MAC_MAXHT[HAB[cellLoc]];
01119      MAC_LAI[cellLoc]  = MAC_REL_BIOM[cellLoc]*HP_MAC_MAXLAI[HAB[cellLoc]];
01120 /* note that an "effective" LAI that accounts for water depth is calc'd in hydro module */
01121 
01122 /*  now calc the P and organic matter associated with the C fluxes */
01123                  phbio_npp_P[cellLoc] = NPP_P;     /* within-plant variable stoichiometry */
01124                  phbio_npp_OM[cellLoc] = PHBIO_NPP[cellLoc] / HP_PHBIO_IC_CTOOM[HAB[cellLoc]]; /* habitat-specfic stoichiometry */
01125 
01126                  phbio_mort_P[cellLoc] = PHBIO_MORT[cellLoc] * mac_ph_PC[cellLoc];
01127                  phbio_mort_OM[cellLoc] = PHBIO_MORT[cellLoc] / mac_ph_CtoOM[cellLoc];
01128 
01129                  phbio_transl_P[cellLoc] = PHBIO_TRANSLOC[cellLoc] * mac_nph_PC[cellLoc];
01130                  phbio_transl_OM[cellLoc] = PHBIO_TRANSLOC[cellLoc] / mac_nph_CtoOM[cellLoc];
01131 
01132                  nphbio_transl_P[cellLoc] = NPHBIO_TRANSLOC[cellLoc] * mac_ph_PC[cellLoc];
01133                  nphbio_transl_OM[cellLoc] = NPHBIO_TRANSLOC[cellLoc] / mac_ph_CtoOM[cellLoc];
01134                  
01135                  nphbio_mort_P[cellLoc] = NPHBIO_MORT[cellLoc] * mac_nph_PC[cellLoc];
01136                  nphbio_mort_OM[cellLoc] = NPHBIO_MORT[cellLoc] / mac_nph_CtoOM[cellLoc];
01137 
01138 
01139 /* state vars: now calc the P and OM associated with those C state vars */
01140                  mac_nph_P[cellLoc] = mac_nph_P[cellLoc]
01141                      + (nphbio_transl_P[cellLoc] - nphbio_mort_P[cellLoc]
01142                         - phbio_transl_P[cellLoc]  ) * DT;
01143                  mac_nph_PC[cellLoc] = ( (MAC_NOPH_BIOMAS[cellLoc] > 0.0) && (mac_nph_P[cellLoc] > 0.0)) ?
01144                      (mac_nph_P[cellLoc] / MAC_NOPH_BIOMAS[cellLoc]) : /* these second mass checks not needed */
01145                      0.3 * HP_NPHBIO_IC_PC[HAB[cellLoc]]; /* default to 0.3 of max for habitat */
01146                  mac_nph_PC_rep[cellLoc] = (float)mac_nph_PC[cellLoc] * conv_kgTOmg; /* variable for output _rep-orting only */
01147                  
01148 
01149                  mac_nph_OM[cellLoc] = mac_nph_OM[cellLoc]
01150                      + (nphbio_transl_OM[cellLoc] - nphbio_mort_OM[cellLoc]
01151                         - phbio_transl_OM[cellLoc] ) * DT;
01152                  mac_nph_CtoOM[cellLoc] = ( (mac_nph_OM[cellLoc] > 0.0) && (MAC_NOPH_BIOMAS[cellLoc]>0.0)) ?
01153                      (MAC_NOPH_BIOMAS[cellLoc] / mac_nph_OM[cellLoc]) :
01154                      HP_NPHBIO_IC_CTOOM[HAB[cellLoc]];
01155 
01156                  mac_ph_P[cellLoc] = mac_ph_P[cellLoc]
01157                      + (phbio_transl_P[cellLoc] + phbio_npp_P[cellLoc] - phbio_mort_P[cellLoc]
01158                         - nphbio_transl_P[cellLoc] ) * DT;
01159                  mac_ph_PC[cellLoc] = ( (MAC_PH_BIOMAS[cellLoc] > 0.0) && (mac_ph_P[cellLoc]>0.0)) ?
01160                      (mac_ph_P[cellLoc] / MAC_PH_BIOMAS[cellLoc]) :
01161                      0.3 * HP_PHBIO_IC_PC[HAB[cellLoc]]; /* default to 0.3 of max for habitat */
01162                  mac_ph_PC_rep[cellLoc] = (float)mac_ph_PC[cellLoc] * conv_kgTOmg; /* variable for output _rep-orting only */
01163 
01164                  mac_ph_OM[cellLoc] = mac_ph_OM[cellLoc]
01165                      + (phbio_transl_OM[cellLoc] + phbio_npp_OM[cellLoc] - phbio_mort_OM[cellLoc]
01166                         - nphbio_transl_OM[cellLoc]  ) * DT;
01167                  mac_ph_CtoOM[cellLoc] = ( (mac_ph_OM[cellLoc] > 0.0) && (MAC_PH_BIOMAS[cellLoc]>0.0)) ?
01168                      (MAC_PH_BIOMAS[cellLoc] / mac_ph_OM[cellLoc]) :
01169                      HP_PHBIO_IC_CTOOM[HAB[cellLoc]];
01170 
01171                  if (debug > 0 && MAC_NOPH_BIOMAS[cellLoc] < -GP_MinCheck) { sprintf(msgStr,"Day %6.1f: ERROR - neg NPhoto C biomass (%f kg) in cell (%d,%d)!", 
01172                               SimTime.TIME, MAC_NOPH_BIOMAS[cellLoc], ix,iy ); WriteMsg( msgStr,True ); dynERRORnum++;}
01173                  if (debug > 0 && MAC_PH_BIOMAS[cellLoc] < -GP_MinCheck)  { sprintf(msgStr,"Day %6.1f: ERROR - neg Photo C biomass (%f kg) in cell (%d,%d)!", 
01174                               SimTime.TIME, MAC_PH_BIOMAS[cellLoc], ix,iy ); WriteMsg( msgStr,True ); dynERRORnum++;}
01175                  if (debug > 0 && mac_nph_P[cellLoc] < -GP_MinCheck) { sprintf(msgStr,"Day %6.1f: ERROR - neg NPhoto P biomass (%f kg) in cell (%d,%d)!", 
01176                               SimTime.TIME, mac_nph_P[cellLoc], ix,iy ); WriteMsg( msgStr,True ); dynERRORnum++;}
01177                  if (debug > 0 && mac_ph_P[cellLoc] < -GP_MinCheck)  { sprintf(msgStr,"Day %6.1f: ERROR - neg Photo P biomass (%f kg) in cell (%d,%d)!", 
01178                               SimTime.TIME, mac_ph_P[cellLoc], ix,iy ); WriteMsg( msgStr,True ); dynERRORnum++;}
01179 
01180 
01181 /******** phosphorus removed from water here *************/
01182      TP_SEDWT_UPTAKE[cellLoc]  = phbio_npp_P[cellLoc]*CELL_SIZE; 
01183 /* recalc P in sed water state variable (kg P) */
01184      TP_SED_WT[cellLoc] =  TP_SED_WT[cellLoc] - (TP_SEDWT_UPTAKE[cellLoc]) * DT;
01185      TP_SED_CONC[cellLoc] = (HYD_SED_WAT_VOL[cellLoc]>0.0) ?
01186                      (TP_SED_WT[cellLoc] / HYD_SED_WAT_VOL[cellLoc]) :
01187                   (0.0);
01188                  
01189                       /* this is the active zone, where uptake, sorption, and mineralization take place */
01190                 TP_SED_WT_AZ[cellLoc] =  TP_SED_WT_AZ[cellLoc] - (TP_SEDWT_UPTAKE[cellLoc]) * DT;
01191                  TP_SEDWT_CONCACT[cellLoc] = ( HYD_DOM_ACTWAT_PRES[cellLoc] > 0.0) ?
01192                      ( TP_SED_WT_AZ[cellLoc]/HYD_DOM_ACTWAT_VOL[cellLoc] ) :
01193                      (TP_SED_CONC[cellLoc]); /* g/L */
01194                  TP_SEDWT_CONCACTMG[cellLoc]  = TP_SEDWT_CONCACT[cellLoc]*conv_kgTOg; /* g/m3==mg/L */
01195               
01196           }
01197   }
01198   }
01199 }
01200 
01201 
01202 /*******/
01209 /*
01210 TP_SF_WT[cellLoc] == mass of P in surface water (kg P)
01211 TP_SED_WT[cellLoc] == mass of P in sediment/soil (pore) water (kg P)
01212 TP_SORB[cellLoc] == mass of P sorbed to soil (kg P)
01213 
01214 Parameter definitions:
01215       global parameters in GlobalParms.xls Excel sheet (text export=GlobalParms)
01216       habitat-specific parameters in HabParms.fmp FileMakerPro database (text export=HabParms)
01217 */
01218 void cell_dyn9(int step)
01219  {
01220  int ix, iy, cellLoc; 
01221  float TPpartic, TPsettlRat, TP_settl_pot;
01222  double PO4Pconc, nonPO4Pconc;
01223  
01224   for(ix=1; ix<=s0; ix++) {
01225   for(iy=1; iy<=s1; iy++) {
01226 
01227     if(ON_MAP[cellLoc= T(ix,iy)])  {
01228 /* calc concentrations after horiz fluxes */
01229               TP_SFWT_CONC[cellLoc]  = 
01230                   ( SFWT_VOL[cellLoc] > 0.0 ) ? 
01231                   ( TP_SF_WT[cellLoc]/SFWT_VOL[cellLoc] ) : 
01232                   ( 0.0); /* used in P fluxes for mass balance */
01233              /* using regression for predicting PO4 from TP */
01234               PO4Pconc =  Max( TP_SFWT_CONC[cellLoc]*GP_PO4toTP + 0.001*GP_PO4toTPint,0.0);  /* g/l  (note that intercept may be <0)*/
01235       /* after spatial (horiz) fluxes, recalc the active zone P mass based on old active/total ratio */
01236               TP_SED_CONC[cellLoc] = (HYD_SED_WAT_VOL[cellLoc]>0.0) ?
01237                   (TP_SED_WT[cellLoc] / HYD_SED_WAT_VOL[cellLoc]) :
01238                   (0.0);
01239             /* this is the active zone, where uptake, sorption, and mineralization take place */
01240              TP_SED_WT_AZ[cellLoc] = TP_SED_CONC[cellLoc] * TP_Act_to_Tot[cellLoc] * HYD_DOM_ACTWAT_VOL[cellLoc];
01241               TP_SEDWT_CONCACT[cellLoc] =(HYD_DOM_ACTWAT_PRES[cellLoc] > 0.0) ?
01242                   ( TP_SED_WT_AZ[cellLoc]/HYD_DOM_ACTWAT_VOL[cellLoc] ) :
01243                   ( TP_SED_CONC[cellLoc]);
01244 
01245 /* inputs to surf  P (kg P)  */
01246               /* v2.6, using negative-parameter switch in v2.8:
01247                 - either use rainfall-based P deposition (parameter >= 0.0), 
01248                 or spatially varying, temporally constant, daily rate of total deposition (used if conc parameter is negative)*/
01249               /* TODO - investigate methods/data for wet and dry deposition */
01250               TP_Atm_Depos[cellLoc]  = (GP_TP_IN_RAIN < 0.0) ? (TP_AtmosDepos[cellLoc]) : (SF_WT_FROM_RAIN[cellLoc]*CELL_SIZE*GP_TP_IN_RAIN*0.001) ; /* P deposition, kgP/day */
01251 
01252 /* calc various loss and/or vertical exchange potentials (kg P) */
01253               /* diffusive flux */
01254               TP_UPFLOW_POT[cellLoc]  = /*  advective upflow has been handled in surf-ground integration in fluxes.c  */
01255                   Max((TP_SEDWT_CONCACT[cellLoc]-PO4Pconc)
01256                         *GP_TP_DIFFCOEF*8.64/GP_TP_DIFFDEPTH*CELL_SIZE,0.0); /* document this diffusion constant multiplier (involving conversion from sec/day) */
01257               TP_UPFLOW[cellLoc]  = 
01258                   ( (TP_UPFLOW_POT[cellLoc])*DT>TP_SED_WT_AZ[cellLoc] ) ? 
01259                   ( (TP_SED_WT_AZ[cellLoc])/DT ) : 
01260                   ( TP_UPFLOW_POT[cellLoc]);
01261                   /* units = mgP/L */
01262               TP_K[cellLoc]  = Max(GP_TP_K_SLOPE*TP_SORBCONC[cellLoc]+GP_TP_K_INTER,0.0);
01263 /*fix rate */
01264               TP_SORB_POT[cellLoc]  = 
01265                   ( HYD_DOM_ACTWAT_PRES[cellLoc]>0.0 ) ? 
01266                   ( (double) 0.001 
01267                     *(TP_K[cellLoc]*(pow(Max(TP_SEDWT_CONCACT[cellLoc],0.0),0.8) )
01268                       *0.001*(DEPOS_ORG_MAT[cellLoc]*CELL_SIZE+DIM[cellLoc])-TP_SORB[cellLoc] ) ) : 
01269                   ( 0.0);
01270               if (TP_SORB_POT[cellLoc]>0.0) {
01271                   TP_SORBTION[cellLoc]  =  
01272                       ( (TP_SORB_POT[cellLoc]+TP_UPFLOW[cellLoc])*DT>TP_SED_WT_AZ[cellLoc] ) ? 
01273                       ( (TP_SED_WT_AZ[cellLoc]-TP_UPFLOW[cellLoc]*DT)/DT ) : 
01274                       ( TP_SORB_POT[cellLoc]);
01275               }
01276               else { /* neg sorption, loss from sorb variable*/
01277                   TP_SORBTION[cellLoc]  =  
01278                       ( (-TP_SORB_POT[cellLoc])*DT>TP_SORB[cellLoc] ) ? 
01279                       ( (-TP_SORB[cellLoc])/DT ) : 
01280                       ( TP_SORB_POT[cellLoc]);
01281               }
01282               
01283               /* diffusive + advective flux */
01284               TP_DNFLOW_POT[cellLoc]  = (SF_WT_INFILTRATION[cellLoc]+SF_WT_TO_SAT_DOWNFLOW[cellLoc])
01285                   *CELL_SIZE*TP_SFWT_CONC[cellLoc]   
01286                   + Max((PO4Pconc-TP_SEDWT_CONCACT[cellLoc])
01287                         *GP_TP_DIFFCOEF*8.64/GP_TP_DIFFDEPTH*CELL_SIZE,0.0) ;
01288               TP_DNFLOW[cellLoc]  =  
01289                   ( ( TP_DNFLOW_POT[cellLoc])*DT > TP_SF_WT[cellLoc] ) ? 
01290                   ( ( TP_SF_WT[cellLoc])/DT ) : 
01291                   ( TP_DNFLOW_POT[cellLoc]);
01292 /* calc P in sed water state variables (kg P) */
01293               TP_SED_WT[cellLoc] =  TP_SED_WT[cellLoc] +
01294                   ( TP_DNFLOW[cellLoc] - TP_UPFLOW[cellLoc] - TP_SORBTION[cellLoc]) * DT;
01295              /* this is the active zone, where uptake, sorption, and mineralization take place */
01296               TP_SED_WT_AZ[cellLoc] =  TP_SED_WT_AZ[cellLoc] +
01297                   (TP_DNFLOW[cellLoc] - TP_UPFLOW[cellLoc] - TP_SORBTION[cellLoc]) * DT;
01298 
01299 /* calc P in surface water state variable (kg P) */
01300               TP_SF_WT[cellLoc] = TP_SF_WT[cellLoc] + 
01301                   (TP_UPFLOW[cellLoc] + TP_Atm_Depos[cellLoc] 
01302                    - TP_DNFLOW[cellLoc]) * DT;
01303 
01304 /* calc P sorbed-to-soil state variable (kg P) */
01305               TP_SORB[cellLoc] = TP_SORB[cellLoc] + (TP_SORBTION[cellLoc]) * DT;
01306 
01307               TP_SED_CONC[cellLoc] = (HYD_SED_WAT_VOL[cellLoc]>0.0) ?
01308                   (TP_SED_WT[cellLoc] / HYD_SED_WAT_VOL[cellLoc]) :
01309                   (0.0); /* g/L */
01310               TP_SEDWT_CONCACT[cellLoc] = ( HYD_DOM_ACTWAT_PRES[cellLoc] > 0.0) ?
01311                   ( TP_SED_WT_AZ[cellLoc]/HYD_DOM_ACTWAT_VOL[cellLoc] ) :
01312                   (TP_SED_CONC[cellLoc]); /* g/L */
01313               TP_SEDWT_CONCACTMG[cellLoc]  = TP_SEDWT_CONCACT[cellLoc]*conv_kgTOg; /* g/m^3==mg/L */
01314 
01315               TP_SORBCONC[cellLoc] = ((DEPOS_ORG_MAT[cellLoc]*CELL_SIZE + DIM[cellLoc])>0.0) ?
01316                   ( (double) TP_SORB[cellLoc]*conv_kgTOg / (DEPOS_ORG_MAT[cellLoc]*CELL_SIZE + DIM[cellLoc]) ) :
01317                   (0.0); /* gP/kgsoil */
01318 
01319               TP_SORBCONC_rep[cellLoc] = TP_SORBCONC[cellLoc] * conv_gTOmg; /* reporting purposes only (g/kg->mg/kg)*/
01320 
01321               TP_SFWT_CONC[cellLoc]  = 
01322                   ( SFWT_VOL[cellLoc] > 0.0 ) ? 
01323                   ( TP_SF_WT[cellLoc]/SFWT_VOL[cellLoc] ) : 
01324                   ( 0.0); /* g/L used in P fluxes for mass balance */
01325               TP_SFWT_CONC_MG[cellLoc]  = 
01326                   ( SURFACE_WAT[cellLoc] > GP_WQualMonitZ ) ? 
01327                   (TP_SFWT_CONC[cellLoc]*conv_kgTOg) : 
01328                   (0.0); /* g/m^3==mg/L used for reporting and other modules to evaluate P conc when water is present */
01329 
01330 /* the following is an empirical method to calculate settling of particulate P out of the water column
01331    into the sediments.  It uses the fixed ratio of PO4 to TP, but allows for a decreasing proportion of
01332    TP to be in (large) particulate form as TP concentration drops below a chosen threshold - the sum of
01333    the TP is considered to be dissolved plus large particulate plus small particulate (that cannot settle out) */
01334                   /* mass (kg) of particulate fraction of TP, available for settling to sediments */
01335                   /* using regression for predicting PO4 from TP */
01336               PO4Pconc =  Max(TP_SFWT_CONC_MG[cellLoc]*GP_PO4toTP + GP_PO4toTPint,0.0);  /* mg/l (note that intercept may be <0)*/
01337               nonPO4Pconc = Max(TP_SFWT_CONC_MG[cellLoc]-PO4Pconc,0.0); /* non-PO4 conc, mg/l */
01338               TPpartic = nonPO4Pconc * (1.0-exp(-nonPO4Pconc/GP_TPpart_thresh)) *0.001 * SFWT_VOL[cellLoc] ; /* kg particulate P */
01339 
01340 
01341                   /* settling rate, 1/d */
01342               TPsettlRat = ( SURFACE_WAT[cellLoc] > GP_DetentZ ) ?
01343                   (GP_settlVel/SURFACE_WAT[cellLoc]) :
01344                   0.0;
01345               
01346                   /* potential settling of particulate TP (kg/d) */
01347               TP_settl_pot = TPsettlRat * TPpartic;
01348               TP_settl[cellLoc]  =  
01349                   ( ( TP_settl_pot)*DT > TPpartic ) ? 
01350                   ( (TPpartic)/DT ) : 
01351                   ( TP_settl_pot);
01352 /* calc P in surface water state variable (kg P) */
01353               TP_SF_WT[cellLoc] = TP_SF_WT[cellLoc] - TP_settl[cellLoc] * DT;
01354 
01355 /* various book-keeping calcs used in other modules */
01356 /* conc surf and sed wat = kgP/m3==gP/L, another var calc for mg/L */
01357               TP_SFWT_CONC[cellLoc]  = 
01358                   ( SFWT_VOL[cellLoc] > 0.0 ) ? 
01359                   ( TP_SF_WT[cellLoc]/SFWT_VOL[cellLoc] ) : 
01360                   ( 0.0); /* used in P fluxes for mass balance */
01361               TP_SFWT_CONC_MG[cellLoc]  = 
01362                   ( SURFACE_WAT[cellLoc] > GP_WQualMonitZ ) ? 
01363                   (TP_SFWT_CONC[cellLoc]*conv_kgTOg) : 
01364                   (0.0); /* g/m3==mg/L used for reporting and other modules to evaluate P conc when water is present */
01365               
01366               if (debug > 0 && TP_SF_WT[cellLoc] < -GP_MinCheck) { sprintf(msgStr,"Day %6.1f: ERROR - neg TP_SF_WT (%f kg) in cell (%d,%d)!", 
01367                                                                     SimTime.TIME, TP_SF_WT[cellLoc], ix,iy ); WriteMsg( msgStr,True ); usrErr( msgStr ); dynERRORnum++; }
01368               if (debug > 0 && TP_SED_WT_AZ[cellLoc] < -GP_MinCheck)  { sprintf(msgStr,"Day %6.1f: ERROR - neg TP_SED_WT_AZ (%f kg) in cell (%d,%d)!", 
01369                                                                       SimTime.TIME, TP_SED_WT_AZ[cellLoc], ix,iy ); WriteMsg( msgStr,True ); usrErr( msgStr ); dynERRORnum++; }
01370 
01371     }
01372   }
01373   }
01374 }
01375 
01376 /*******/
01386 /*
01387 Parameter definitions:
01388       global parameters in GlobalParms.xls Excel sheet (text export=GlobalParms)
01389       habitat-specific parameters in HabParms.fmp FileMakerPro database (text export=HabParms)
01390 */
01391 void cell_dyn13(int step)
01392  {
01393  int ix, iy, cellLoc; 
01394  float TPsettlRat, TP_settl_pot;
01395  
01396   for(ix=1; ix<=s0; ix++) {
01397   for(iy=1; iy<=s1; iy++) { 
01398 
01399     if(ON_MAP[cellLoc= T(ix,iy)])  {
01400 /* concentration of P in surface water used in P fluxes for mass transfer (kgP/m3==gP/L) */
01401               TP_SFWT_CONC[cellLoc]  = 
01402                   ( SFWT_VOL[cellLoc] > 0.0 ) ? 
01403                   ( TP_SF_WT[cellLoc]/SFWT_VOL[cellLoc] ) : 
01404                   ( 0.0); 
01405 /* inputs to surf  P (kg P)  */             
01406               /* see notes on changes, in cell_dyn9 module */
01407               TP_Atm_Depos[cellLoc]  = (GP_TP_IN_RAIN < 0.0) ? (TP_AtmosDepos[cellLoc]) : (SF_WT_FROM_RAIN[cellLoc]*CELL_SIZE*GP_TP_IN_RAIN*0.001) ; /* P deposition, kgP/day */
01408 
01409 /* TP settling rate calculation (m/d) = 0 if water depth (m) less than depth threshold parm */
01410               if (SURFACE_WAT[cellLoc] > GP_WQMthresh ) {
01411                   TPsettlRat = WQMsettlVel[cellLoc];
01412                   TP_settlDays[cellLoc]++;
01413               }
01414               else
01415                   TPsettlRat = 0.0;
01416               
01417 /* before we had to put in the day accumulator*/
01418 /*               TPsettlRat = ( SURFACE_WAT[cellLoc] > GP_WQMthresh ) ?  */
01419 /*                   (WQMsettlVel[cellLoc]) : 0.0; */
01420 /* potential settling of particulate TP (m/d * m^2 * kg/m^3 = kg/d) */
01421               TP_settl_pot = TPsettlRat * CELL_SIZE * TP_SFWT_CONC[cellLoc];
01422 
01423 /*  like EWQM, shows mass bal error when ->   TP_settl[cellLoc]  =   TP_settl_pot; */
01424               
01425 /* constrain settling to be no more than kg P available in water column */
01426               TP_settl[cellLoc]  =   
01427                   ( ( TP_settl_pot)*DT > TP_SF_WT[cellLoc] ) ?  
01428                   ( (TP_SF_WT[cellLoc])/DT ) :  
01429                   ( TP_settl_pot); 
01430 /* calc P in surface water state variable (kg P) */
01431               TP_SF_WT[cellLoc] = TP_SF_WT[cellLoc] +
01432                   ( TP_Atm_Depos[cellLoc] - TP_settl[cellLoc] ) * DT;
01433 
01434 /* this was in EWQM!!! (mass balance error!):  if (TP_SF_WT[cellLoc]<0.0) TP_SF_WT[cellLoc]=0.0; */
01435               
01436 /* concentration of P in surface water used in P fluxes for mass transfer (kgP/m3==gP/L) */
01437               TP_SFWT_CONC[cellLoc]  = 
01438                   ( SFWT_VOL[cellLoc] > 0.0 ) ? 
01439                   ( TP_SF_WT[cellLoc]/SFWT_VOL[cellLoc] ) : 
01440                   ( 0.0); 
01441 /* concentration used for reporting (e.g., in maps) when water is present. 
01442    Using a new (v2.8.4) depth parm also used for all
01443    concentration reporting thresholds
01444 */
01445               TP_SFWT_CONC_MG[cellLoc]  = 
01446                   ( SURFACE_WAT[cellLoc] > GP_WQualMonitZ ) ?  
01447                   (TP_SFWT_CONC[cellLoc]*conv_kgTOg) : 
01448                   (0.0);  /* g/m3==mg/L */
01449     }
01450   }
01451   }
01452 }
01453 
01454 
01455 
01456 /*******/
01464 /*
01465 SALT_SURF_WT[cellLoc] == mass of salt dissolved in surface water (kg salt)
01466 SALT_SED_WT[cellLoc] == mass of salt dissolved in sediment/soil (pore) water (kg salt)
01467 
01468 
01469 Parameter definitions:
01470       global parameters in GlobalParms.xls Excel sheet (text export=GlobalParms)
01471       habitat-specific parameters in HabParms.fmp FileMakerPro database (text export=HabParms)
01472 */
01473 void cell_dyn10(int step)
01474  {
01475 int ix, iy, cellLoc;
01476  double SALT_SED_TO_SF_FLOW_pot;
01477  
01478 
01479   for(ix=1; ix<=s0; ix++) {
01480   for(iy=1; iy<=s1; iy++) {
01481 
01482     if(ON_MAP[cellLoc= T(ix,iy)])  {
01483      SAL_SF_WT_mb[cellLoc]  = 
01484                      ( SFWT_VOL[cellLoc] > 0.0 ) ? 
01485                      ( SALT_SURF_WT[cellLoc]/SFWT_VOL[cellLoc] ) : 
01486                      ( 0.0); /* used in salt fluxes for mass balance */
01487      SAL_SED_WT[cellLoc]  = 
01488                      ( HYD_SED_WAT_VOL[cellLoc]>0.0 ) ? 
01489                      ( SALT_SED_WT[cellLoc]/HYD_SED_WAT_VOL[cellLoc] ) : 
01490                      ( 0.0);
01491       /* v2.8:
01492          - either use rainfall-based salt (Cl) deposition (parameter >= 0.0), 
01493            or spatially varying, temporally constant, daily rate of total deposition (used if conc parameter is negative)*/
01494       /* TODO - investigate methods/data for wet and dry deposition */
01495               SALT_Atm_Depos[cellLoc]  = (GP_CL_IN_RAIN < 0.0) ? (SALT_AtmosDepos[cellLoc]) : (SF_WT_FROM_RAIN[cellLoc]*CELL_SIZE*GP_CL_IN_RAIN*0.001) ; /* chloride deposition, kgCl/day */
01496 
01497               /* diffusive + advective flux */ 
01498                  SALT_SFWAT_DOWNFL_POT[cellLoc]  = (SF_WT_INFILTRATION[cellLoc] + SF_WT_TO_SAT_DOWNFLOW[cellLoc])
01499                      * CELL_SIZE*SAL_SF_WT_mb[cellLoc]
01500                      + Max((SAL_SF_WT_mb[cellLoc]-SAL_SED_WT[cellLoc])
01501                            * GP_TP_DIFFCOEF*8.64/GP_TP_DIFFDEPTH*CELL_SIZE,0.0)  ; /* TODO: get cl diffusion parm; diffusion parms same as P */
01502      SALT_SFWAT_DOWNFL[cellLoc]  =  
01503                      ( SALT_SFWAT_DOWNFL_POT[cellLoc]*DT>SALT_SURF_WT[cellLoc] ) ? 
01504                      ( SALT_SURF_WT[cellLoc]/DT ) : 
01505                      ( SALT_SFWAT_DOWNFL_POT[cellLoc]);
01506 
01507               /* diffusive flux */  
01508                  SALT_SED_TO_SF_FLOW_pot  =  
01509                     /*  advective upflow has been handled in surf-ground integration in fluxes.c  */
01510                      Max((SAL_SED_WT[cellLoc]-SAL_SF_WT_mb[cellLoc])
01511                             *GP_TP_DIFFCOEF*8.64/GP_TP_DIFFDEPTH*CELL_SIZE,0.0)  ; /* TODO: get cl diffusion parm; diffusion parms same as P */
01512                  SALT_SED_TO_SF_FLOW[cellLoc]  =  
01513                      ( SALT_SED_TO_SF_FLOW_pot*DT>SALT_SED_WT[cellLoc] ) ? 
01514                      ( SALT_SED_WT[cellLoc]/DT ) : 
01515                      ( SALT_SED_TO_SF_FLOW_pot );
01516 /* calc state vars (kg salt) */
01517      SALT_SED_WT[cellLoc] =  SALT_SED_WT[cellLoc]  
01518                      + (SALT_SFWAT_DOWNFL[cellLoc] - SALT_SED_TO_SF_FLOW[cellLoc]) * DT;
01519 
01520      SALT_SURF_WT[cellLoc] = SALT_SURF_WT[cellLoc] 
01521                      + (SALT_Atm_Depos[cellLoc] + SALT_SED_TO_SF_FLOW[cellLoc] - SALT_SFWAT_DOWNFL[cellLoc] ) * DT;
01522 
01523 /* book-keeping concentration calcs, (kg/m3==g/L==ppt) used in other modules */
01524      SAL_SF_WT_mb[cellLoc]  = 
01525                      ( SFWT_VOL[cellLoc] > 0.0 ) ? 
01526                      ( SALT_SURF_WT[cellLoc]/SFWT_VOL[cellLoc] ) : 
01527                      ( 0.0); /* used in salt fluxes for mass balance */
01528      SAL_SF_WT[cellLoc]  = 
01529                      ( SURFACE_WAT[cellLoc] > GP_WQualMonitZ ) ? 
01530                      ( SAL_SF_WT_mb[cellLoc]  ) : 
01531                      ( 0.0); /* used for reporting and other modules to evaluate salinity when water is present */
01532      SAL_SED_WT[cellLoc]  = 
01533                      ( HYD_SED_WAT_VOL[cellLoc]>0.0 ) ? 
01534                      ( SALT_SED_WT[cellLoc]/HYD_SED_WAT_VOL[cellLoc] ) : 
01535                      ( 0.0);
01536 
01537     }
01538   }
01539   }
01540                   
01541 }
01542 
01543 
01544 
01551 /*
01552    FLOC[cellLoc] == mass of organic flocculent material at the interface between soil and surface water (kg OM/m^2) \n
01553    FlocP[cellLoc] == mass of phosphorus in the flocculent material at the interface between soil and surface water (kg P/m^2) \n
01554 
01555 This routine originally was Suspended Organic Matter; was modified to instead
01556 represent the organic matter in the flocculent sediment layer. \n
01557 
01558 Parameter definitions: \n
01559       global parameters in GlobalParms.xls Excel sheet (text export=GlobalParms) \n
01560       habitat-specific parameters in HabParms.fmp FileMakerPro database (text export=HabParms)
01561 */
01562 void cell_dyn12(int step)
01563  {
01564  int ix, iy, cellLoc; 
01565  float FlocP_DECOMP_pot, FlocP_DEPO_pot, FlocP_settl, Floc_settl;
01566  
01567   for(ix=1; ix<=s0; ix++) {
01568   for(iy=1; iy<=s1; iy++) {
01569 
01570     if(ON_MAP[cellLoc= T(ix,iy)])  {
01571 /* inputs (kg OM / m2)  */
01572                   /* all periphyton mortality goes to floc */
01573               FLOC_FR_ALGAE[cellLoc]  = (double) (C_ALG_MORT[cellLoc]+NC_ALG_MORT[cellLoc])
01574                   /GP_ALG_C_TO_OM*0.001 ; 
01575                   /* all photobiomass mortality goes to floc */
01576               Floc_fr_phBio[cellLoc]  = phbio_mort_OM[cellLoc];
01577 
01578              /* all settling from water column goes to floc */
01579               FlocP_settl = TP_settl[cellLoc] / CELL_SIZE; /* kg P/m2; */
01580                   /* the particulate P settling is assumed a fixed Redfield P:OM ratio */
01581               Floc_settl =   FlocP_settl / GP_TP_P_OM; 
01582                  
01583           
01584 /* outputs (kg OM / m2) */
01585               FLOC_DECOMP_QUAL_CF[cellLoc]  = /* use the avg conc of sed and sf water here */
01586                   Exp(-GP_DOM_decomp_coef * Max(GP_DOM_DECOMP_POPT-
01587                                  (TP_SFWT_CONC_MG[cellLoc]+TP_SEDWT_CONCACTMG[cellLoc])/2.0, 0.0)
01588                       /GP_DOM_DECOMP_POPT) ; /* mg/L */
01589 /* decomp in surface water has higher rate than in soil,
01590  assuming this stock is of much higer substrate quality than the total soil layer */
01591 /* GP_calibDecomp is an adjustable calib parm */
01592               soil_MOIST_CF[cellLoc]  =  (UNSAT_DEPTH[cellLoc]>HP_DOM_AEROBTHIN[HAB[cellLoc]]) ?
01593                      ( Max(UNSAT_MOIST_PRP[cellLoc],0.0) ) :
01594                      ( 1.0 );
01595               FLOC_DECOMP_POT[cellLoc]  = GP_calibDecomp * 10.0*GP_DOM_RCDECOMP*FLOC[cellLoc]
01596                    *DOM_TEMP_CF[cellLoc] *FLOC_DECOMP_QUAL_CF[cellLoc] * soil_MOIST_CF[cellLoc];
01597               FLOC_DECOMP[cellLoc]  = 
01598                   ( (FLOC_DECOMP_POT[cellLoc])*DT>FLOC[cellLoc] ) ? 
01599                   ( (FLOC[cellLoc])/DT ) : 
01600                   ( FLOC_DECOMP_POT[cellLoc]);
01601 
01602 /* the incorporation of the floc layer into the "true" soil layer occurs
01603    at a rate dependent on the floc depth under flooded conditions, then constant rate under dry conditions */
01604               FLOC_DEPO_POT[cellLoc]  = 
01605                   ( SURFACE_WAT[cellLoc] > GP_DetentZ ) ? 
01606                   ( FLOC_Z[cellLoc]/GP_FlocMax * FLOC[cellLoc]*GP_Floc_rcSoil ) : 
01607                   ( FLOC[cellLoc]*GP_Floc_rcSoil);
01608               FLOC_DEPO[cellLoc]  = 
01609                   ( (FLOC_DEPO_POT[cellLoc]+FLOC_DECOMP[cellLoc])*DT>FLOC[cellLoc] ) ? 
01610                   ( (FLOC[cellLoc]-FLOC_DECOMP[cellLoc]*DT)/DT ) : 
01611                   ( FLOC_DEPO_POT[cellLoc]); 
01612 /* calc the state var (kg OM / m2) */
01613               FLOC[cellLoc] =  FLOC[cellLoc] 
01614                   + ( Floc_settl + Floc_fr_phBio[cellLoc] + FLOC_FR_ALGAE[cellLoc]
01615                       - FLOC_DECOMP[cellLoc] - FLOC_DEPO[cellLoc] ) * DT;
01616 
01617 /* the depth of floc is dependent on a fixed floc bulk density */
01618               FLOC_Z[cellLoc] = (double) FLOC[cellLoc] / GP_Floc_BD ;
01619                  
01620 
01621 /* Floc phosphorus (kg P / m2)  */
01622               FlocP_FR_ALGAE[cellLoc]  = (double) (NC_ALG_MORT_P[cellLoc]
01623                                           + C_ALG_MORT_P[cellLoc])*0.001; /* kg P/m2 */
01624               FlocP_PhBio[cellLoc] = phbio_mort_P[cellLoc] ;    
01625 
01626               FlocP_DECOMP_pot =  FLOC_DECOMP[cellLoc] * FlocP_OM[cellLoc];
01627               FlocP_DECOMP[cellLoc]  = 
01628                   ( (FlocP_DECOMP_pot)*DT>FlocP[cellLoc] ) ? 
01629                   ( (FlocP[cellLoc])/DT ) : 
01630                   ( FlocP_DECOMP_pot); 
01631               FlocP_DEPO_pot =  FLOC_DEPO[cellLoc] * FlocP_OM[cellLoc];
01632               FlocP_DEPO[cellLoc]  = 
01633                   ( (FlocP_DEPO_pot+FlocP_DECOMP[cellLoc])*DT>FlocP[cellLoc] ) ? 
01634                   ( (FlocP[cellLoc]-FlocP_DECOMP[cellLoc]*DT)/DT ) : 
01635                   ( FlocP_DEPO_pot); 
01636               
01637 /* calc the state var (kg P / m2) */
01638               FlocP[cellLoc] =  FlocP[cellLoc] 
01639                   + ( FlocP_settl + FlocP_PhBio[cellLoc] + FlocP_FR_ALGAE[cellLoc]
01640                       - FlocP_DECOMP[cellLoc] - FlocP_DEPO[cellLoc] ) * DT;
01641 
01642               FlocP_OM[cellLoc] = ( FLOC[cellLoc]>0.0) ? (FlocP[cellLoc]/FLOC[cellLoc]) : (0.0); /* kgP/kgOM */
01643               FlocP_OMrep[cellLoc] = (float) FlocP_OM[cellLoc] * conv_kgTOmg; /* mgP/kgOM, variable for output _rep-orting only */
01644               
01645               if (debug > 0 && FLOC[cellLoc] < -GP_MinCheck) { sprintf(msgStr,"Day %6.1f: ERROR - neg FLOC OM biomass (%f kg/m2) in cell (%d,%d)!", 
01646                                                                     SimTime.TIME, FLOC[cellLoc], ix,iy ); WriteMsg( msgStr,True ); dynERRORnum++;}
01647               if (debug > 0 && FlocP[cellLoc] < -GP_MinCheck)  { sprintf(msgStr,"Day %6.1f: ERROR - neg FLOC P biomass (%f kg/m2) in cell (%d,%d)!", 
01648                                                                       SimTime.TIME, FlocP[cellLoc], ix,iy ); WriteMsg( msgStr,True ); dynERRORnum++;}
01649 
01650 /* now the P gain in sediment pore water with decomp - 90% goes to porewater, 10% to sfwat */
01651               TP_SED_MINER[cellLoc]  =  0.90 * FlocP_DECOMP[cellLoc] * CELL_SIZE ; 
01652 /* calc P in sed water state variables (kg P) */
01653               TP_SED_WT[cellLoc] =  TP_SED_WT[cellLoc] + 
01654                   (TP_SED_MINER[cellLoc]) * DT;
01655             /* this is the active zone, where uptake, sorption, and mineralization take place */
01656               TP_SED_WT_AZ[cellLoc] =  TP_SED_WT_AZ[cellLoc] + 
01657                   (TP_SED_MINER[cellLoc]) * DT;
01658 
01659               TP_SED_CONC[cellLoc] = (HYD_SED_WAT_VOL[cellLoc]>0.0) ?
01660                   (TP_SED_WT[cellLoc] / HYD_SED_WAT_VOL[cellLoc]) :
01661                   (0.0);
01662                TP_SEDWT_CONCACT[cellLoc] = ( HYD_DOM_ACTWAT_PRES[cellLoc] > 0.0) ?
01663                   ( TP_SED_WT_AZ[cellLoc]/HYD_DOM_ACTWAT_VOL[cellLoc] ) :
01664                   (TP_SED_CONC[cellLoc]);
01665               TP_SEDWT_CONCACTMG[cellLoc]  = TP_SEDWT_CONCACT[cellLoc]*conv_kgTOg; /* g/m3==mg/L */
01666               
01667               
01668 /* now the P gain in surface water with decomp - 90% goes to porewater, 10% to sfwat */
01669               TP_SFWT_MINER[cellLoc]  = 0.10*FlocP_DECOMP[cellLoc] * CELL_SIZE ;  
01670 /* calc P in surface water state variable (kg P) */
01671               TP_SF_WT[cellLoc] = TP_SF_WT[cellLoc] + 
01672                   (TP_SFWT_MINER[cellLoc]) * DT;
01673               TP_SFWT_CONC[cellLoc]  = 
01674                   ( SFWT_VOL[cellLoc] > 0.0 ) ? 
01675                   ( TP_SF_WT[cellLoc]/SFWT_VOL[cellLoc] ) : 
01676                   ( 0.0); /* used in P fluxes for mass balance */
01677               TP_SFWT_CONC_MG[cellLoc]  = 
01678                   ( SURFACE_WAT[cellLoc] > GP_WQualMonitZ ) ? 
01679                   (TP_SFWT_CONC[cellLoc]*conv_kgTOg) : 
01680                   (0.0); /* g/m3==mg/L used for reporting and other modules to evaluate P conc when water is present */
01681     }
01682   }
01683   }
01684 }
01685 
01686 
01697 float tempCF(int form, float c1, float topt, float tmin, float tmax, float tempC) 
01698 {
01699   if (form == 1) {
01700     /* Lassiter et al. 1975, where c1 = curvature parm */
01701     return (Exp(c1*(tempC-topt)) * pow(((tmax-tempC)/(tmax-topt)), (c1*(tmax-topt))) );
01702   }
01703   else {
01704     /* Jorgensen 1976 */
01705     return ( Exp(-2.3 * Abs((tempC-topt)/(topt-tmin))) );
01706   }
01707 }
01708 
01710 void init_static_data(void)
01711 {
01712   usrErr0("Acquiring static spatial data..."); /* console message */
01713   
01714   read_map_file("ModArea",ON_MAP,'c',4.0,0.0);            /* defines model area, dimless unsigned char attributes, value 1 set to 4, 0=0 */
01715   read_map_file("BoundCond",BCondFlow,'d',1.0,0.0);       /* boundary condition flow restrictions, dimless integer attributes */
01716             /* ONLY when running the EWQM settling rate version of ELM */
01717   if (ESPmodeON) read_map_file("basinSetVel",WQMsettlVel,'f',0.0001,0.0);       /* basin-based settling rates (data in tenths mm/d, converted to m/d) */
01718   read_map_file("basins",basn,'d',1.0,0.0);               /* Basins/Indicator-Region map, dimless integer attributes  */
01719 
01720   alloc_mem_stats (); /* allocate memory for budget & stats arrays (need to have read the Basin/Indicator-Region map first) */
01721   BIRinit(); /* Set up the Basin/Indicator-Region (BIR) linkages/inheritances */
01722   BIRoutfiles(); /* Basin/Indicator-Region output files */
01723   
01724   usrErr("Done.");
01725 } 
01726 
01727 
01729 void init_dynam_data(void)
01730 {
01731   usrErr0("Acquiring dynamic spatial data..."); /* console message */
01732   
01733   read_map_file("Elevation",ELEVATION,'f',0.01,0.0);      /*  positive elevation relative to zero of vertical datum; input data in cm, converted to m; (prior to ELMv2.8, datum was always NGVD 1929; some apps in v2.8+ are in NAVD88; datum is independent of source code ) */
01734   read_map_file("HAB",HAB,'c',1.0,0.0);                   /* habitat (veg classifications, dimless unsigned char attributes) */
01735   read_map_file("icMacBio",MAC_TOT_BIOM,'f',0.015,0.0);      /* initial total biomass of macrophytes (data in xyz, converted to kg C/m2) */
01736   read_map_file("icSfWt",SURFACE_WAT,'f',0.01,0.0);       /* initial ponded surface water (data in cm, converted to m) */
01737   read_map_file("icUnsat",UNSAT_DEPTH,'f',0.01,0.0);      /* initial depth of unsaturated zone (data in cm, converted to m) */
01738   read_map_file("soilTP",TPtoSOIL,'f',0.000001,0.0);  /* soil TP map (data in mgP/kgSoil, converted to kgP/kgSoil) */
01739   read_map_file("soilBD",BulkD,'f',1.0,0.0);         /* soil bulk dens map (data in mgSoil/cm3 == kgSoil/m3)  */
01740   read_map_file("soil_orgBD",DOM_BD,'f',1.0,0.0);    /* organic soil bulk dens map (data in mgOM/cm3 == kgOM/m3)  */
01741   read_map_file("soilTPpore",TP_SEDWT_CONCACT,'f',0.000001,0.0);    /* porewater TP concentration map (data in ug/L, converted to g/L == kg/m3)  */
01742   read_map_file("AtmosPdepos",TP_AtmosDepos,'f',1.0,0.0);    /* rate of atmospheric deposition of total phosphorus (data in mgP/m^2/yr, convert units later with eqn inits)  */
01743 
01744   /* 2 static mapps need to be here for re-initialing w/ a multiplier (sensitivity analysis) */ 
01745   read_map_file("HydrCond",HYD_RCCONDUCT,'f',1.0,0.0);   /* hydraulic conductivity (no conversion, data in m/d)  */
01746   read_map_file("Bathymetry",Bathymetry,'f',0.01,0.0);      /* positive bathymetry (depth) relative to zero of vertical datum used in land elevation surveys (i.e., positive depth below NGVD29 or NAVD88); all positive depth data in cm, converted to m) */
01747 
01748   usrErr("Done."); /* console message */
01749 } 
01750 
01751 
01757 void init_eqns(void)
01758  {
01759 int ix,iy, cellLoc;
01760 float tmp; /* used in checking nutrient availability for MichMent kinetics */
01761 float min_litTemp; /* used to determine min of temper, light cf's for alg and macs */
01762 float I_ISat, Z_extinct, PO4Pconc, PO4P;
01763 float MAC_PHtoNPH, MAC_PHtoNPH_Init;
01764 double soil_propOrg; 
01765 #define satDensity 0.9 /* assign the relative proportion (0 - 1) of a population maximum to be the saturation density for a population */
01766 
01767   usrErr0("Initializing unit model equations..."); /* console message */
01768   
01769   SimTime.TIME = 0;
01770   DAYJUL = ( FMOD(SimTime.TIME,365.0) >0.0 ) ? ( FMOD(SimTime.TIME,365.0) ) : ( 365.0);
01771   LATRAD = ((int)(GP_LATDEG)+(GP_LATDEG-(int)(GP_LATDEG))*5.0/3.0)*PI/180.0;
01772   /* AMPL = Exp(7.42+0.045*LATRAD*180.0/PI)/3600.0; */
01773   /* DAYLENGTH = AMPL*Sin((DAYJUL-79.0)*0.01721)+12.0; */
01774   SOLALPHA = 32.9835-64.884*(1.0-1.3614*Cos(LATRAD));
01775   SOLDEC1 = 0.39785*Sin(4.868961+0.017203*DAYJUL   +0.033446*Sin(6.224111+0.017202*DAYJUL));
01776   SOLCOSDEC = sqrt(1.0-pow(SOLDEC1,2.0));
01777   SOLELEV_SINE = Sin(LATRAD)*SOLDEC1+Cos(LATRAD)*SOLCOSDEC;
01778   SOLALTCORR = (1.0-Exp(-0.014*(GP_ALTIT-274.0)/(SOLELEV_SINE*274.0)));
01779   SOLBETA = 0.715-0.3183*(1.0-1.3614*Cos(LATRAD));
01780   SOLDEC = Arctan(SOLDEC1/sqrt(1.0-pow(SOLDEC1,2.0)));
01781   SOLRISSET_HA1 = -Tan(LATRAD)*Tan(SOLDEC);
01782   SOLRISSET_HA = ( (SOLRISSET_HA1==0.0) ) ? ( PI*0.5 ) : (   ( (SOLRISSET_HA1<0.0) ) ? ( PI+Arctan(sqrt(1.0-pow(SOLRISSET_HA1,2.0))/SOLRISSET_HA1)  ) : (      Arctan(sqrt(1.0-pow(SOLRISSET_HA1,2.0))/SOLRISSET_HA1)));
01783   SOLRADATMOS = 458.37*2.0*(1.0+0.033*Cos(360.0/365.0*PI/180.0*DAYJUL))* (Cos(LATRAD)*Cos(SOLDEC)*Sin(SOLRISSET_HA) + SOLRISSET_HA*180.0/(57.296*PI)*Sin(LATRAD)*Sin(SOLDEC));
01784         
01785         for(ix=0; ix<=s0+1; ix++) {
01786             for(iy=0; iy<=s1+1; iy++) { 
01787                   cellLoc = T(ix,iy);
01788                   
01789                   AIR_TEMP[cellLoc] = 25.0;  /* spatial time series unavailable after 1995; globally constant in v2.2+ */
01790 /* rainfall read from sfwmm data, remapped to ELM resolution */
01791                   boundcond_rain[cellLoc] =  SF_WT_FROM_RAIN[cellLoc] = boundcond_ETp[cellLoc] = boundcond_depth[cellLoc] = 0.0;
01792        
01793                                 /* used to have cloudiness influence on GP_SOLOMEGA, now 0 */
01794                  SOLRAD274[cellLoc] = SOLRADATMOS*(SOLBETA-GP_SOLOMEGA*0.0 )-SOLALPHA;
01795                  SOLRADGRD[cellLoc] = SOLRAD274[cellLoc]+((SOLRADATMOS+1.0)-SOLRAD274[cellLoc])*SOLALTCORR;
01796                  H2O_TEMP[cellLoc] = AIR_TEMP[cellLoc];
01797          
01798                  ALG_REFUGE[cellLoc] = HP_ALG_MAX[HAB[cellLoc]]*GP_ALG_REF_MULT;
01799                  ALG_SAT[cellLoc] = HP_ALG_MAX[HAB[cellLoc]]*0.9;
01800 
01801               /* v2.3: with southern everglades topo, put bathymetry back into the model */
01802                  ELEVATION[cellLoc] = ELEVATION[cellLoc] * GP_IC_ELEV_MULT;
01803                  Bathymetry[cellLoc] = Bathymetry[cellLoc] * GP_IC_BATHY_MULT;
01804                  SED_ELEV[cellLoc] =  ELEVATION[cellLoc] - Bathymetry[cellLoc] + GP_DATUM_DISTANCE; 
01805                  SED_INACT_Z[cellLoc] = SED_ELEV[cellLoc]-HP_DOM_MAXDEPTH[HAB[cellLoc]]; 
01806 
01807                  MAC_MAX_BIO[cellLoc] = HP_NPHBIO_MAX[HAB[cellLoc]]+HP_PHBIO_MAX[HAB[cellLoc]];
01808                  NPHBIO_REFUGE[cellLoc] = HP_NPHBIO_MAX[HAB[cellLoc]]*GP_MAC_REFUG_MULT;
01809                  NPHBIO_SAT[cellLoc] = HP_NPHBIO_MAX[HAB[cellLoc]] * satDensity;
01810                  PHBIO_REFUGE[cellLoc] = HP_PHBIO_MAX[HAB[cellLoc]]*GP_MAC_REFUG_MULT;
01811                  PHBIO_SAT[cellLoc] = HP_PHBIO_MAX[HAB[cellLoc]] * satDensity;
01812             }
01813         }
01814         for(ix=1; ix<s0+1; ix++) {
01815             for(iy=1; iy<s1+1; iy++) { cellLoc = T(ix,iy);
01816 /*initialization of major state variables */
01817 
01818               /* hydro */
01819                  HYD_RCCONDUCT[cellLoc] = HYD_RCCONDUCT[cellLoc] * GP_calibGWat;
01820 
01821 /* map */        UNSAT_DEPTH[cellLoc] = Max(UNSAT_DEPTH[cellLoc] + GP_HYD_IC_UNSAT_ADD,0.0); /* m */
01822                  SAT_WT_HEAD[cellLoc] = SED_ELEV[cellLoc]- UNSAT_DEPTH[cellLoc]; /* m */
01823                  SAT_WATER[cellLoc] = SAT_WT_HEAD[cellLoc] * HP_HYD_POROSITY[HAB[cellLoc]]; /* m */
01824 
01825                  UNSAT_WATER[cellLoc] = HP_HYD_POROSITY[HAB[cellLoc]]*UNSAT_DEPTH[cellLoc] *GP_HYD_ICUNSATMOIST; /* m */
01826                  UNSAT_CAP[cellLoc] = UNSAT_DEPTH[cellLoc]*HP_HYD_POROSITY[HAB[cellLoc]]; /* m */
01827                  UNSAT_MOIST_PRP[cellLoc]  =  /* dimless proportion, 0-1 */
01828                      ( UNSAT_CAP[cellLoc]>0.0 ) ? 
01829                      ( Min(UNSAT_WATER[cellLoc]/UNSAT_CAP[cellLoc],1.0) ) : 
01830                      ( 1.0); 
01831 
01832 /* map */        SURFACE_WAT[cellLoc] =  Max(SURFACE_WAT[cellLoc] + GP_HYD_IC_SFWAT_ADD, 0.0); /* m */
01833                  SFWT_VOL[cellLoc] = SURFACE_WAT[cellLoc]*CELL_SIZE;
01834 
01835                  HYD_DOM_ACTWAT_VOL[cellLoc] = Max(HP_DOM_MAXDEPTH[HAB[cellLoc]]-UNSAT_DEPTH[cellLoc]*
01836                                                    (1.0-UNSAT_MOIST_PRP[cellLoc]),0.0)*HP_HYD_POROSITY[HAB[cellLoc]]*CELL_SIZE;
01837                  HYD_SED_WAT_VOL[cellLoc] = (SAT_WATER[cellLoc]+UNSAT_WATER[cellLoc])*CELL_SIZE;
01838                  
01839               /* soil */
01840 /* map */        DOM_BD[cellLoc] = DOM_BD[cellLoc] * GP_IC_DOM_BD_MULT; /* kg/m3 */
01841 /* map */        BulkD[cellLoc] = BulkD[cellLoc] * GP_IC_BulkD_MULT;    /* kgOM/m3 */
01842 
01843                  soil_propOrg = (double) DOM_BD[cellLoc] / BulkD[cellLoc];
01844                  DIM[cellLoc] =   (1.0 - soil_propOrg) * BulkD[cellLoc] * HP_DOM_MAXDEPTH[HAB[cellLoc]] * CELL_SIZE; /* kg inorganic matter */
01845                  DEPOS_ORG_MAT[cellLoc] = soil_propOrg * BulkD[cellLoc] * HP_DOM_MAXDEPTH[HAB[cellLoc]] ; /* kg organic matter/m2 */
01846 //                 DEPOS_ORG_MAT[cellLoc] = soil_propOrg * BulkD[cellLoc] * HP_DOM_MAXDEPTH[HAB[cellLoc]] ; /* kg organic matter/m2 */
01847 /* v2.8.4 new DEPOS_ORG_MAT init */
01848 
01849 //                 Inorg_Z[cellLoc] = (1.0 - soil_propOrg) * HP_DOM_MAXDEPTH[HAB[cellLoc]]; /*  fixed inorganic depth (m) */
01850 //                 DOM_Z[cellLoc] =   HP_DOM_MAXDEPTH[HAB[cellLoc]] - Inorg_Z[cellLoc]; /* m */
01851                  Inorg_Z[cellLoc] = DIM[cellLoc] / BulkD[cellLoc] * (1.0-soil_propOrg)  / CELL_SIZE ; /*  kgInorg / kgSoil/m3 * proprInorg / m2 == fixed inorganic depth (m) */
01852                  DOM_Z[cellLoc] =   HP_DOM_MAXDEPTH[HAB[cellLoc]] - Inorg_Z[cellLoc]; /* m */
01853 
01854 // v2.8.4                 DEPOS_ORG_MAT[cellLoc] = DOM_BD[cellLoc]*DOM_Z[cellLoc]; /* (mgOM/cm3 ==> kgOM/m3) * m = kgOM/m2 */
01855 
01856                  DOM_SED_AEROB_Z[cellLoc] = Min(UNSAT_DEPTH[cellLoc]+HP_DOM_AEROBTHIN[HAB[cellLoc]],HP_DOM_MAXDEPTH[HAB[cellLoc]]); /* m */
01857                  DOM_SED_ANAEROB_Z[cellLoc] = HP_DOM_MAXDEPTH[HAB[cellLoc]]-DOM_SED_AEROB_Z[cellLoc]; /* m */
01858 
01859 /* map */        TPtoSOIL[cellLoc] = TPtoSOIL[cellLoc] * GP_IC_TPtoSOIL_MULT; /* kgP/kgSoil */
01860                  DOP[cellLoc] =  (double) (1.0-GP_sorbToTP) * TPtoSOIL[cellLoc] * BulkD[cellLoc] * HP_DOM_MAXDEPTH[HAB[cellLoc]] ; /* kgP/kg_soil * kg_soil/m3 * m == kgP/m2 */
01861 
01862                  TP_SORB[cellLoc] =   (double)  GP_sorbToTP * TPtoSOIL[cellLoc] * BulkD[cellLoc] * HP_DOM_MAXDEPTH[HAB[cellLoc]] * CELL_SIZE; /* dimless * kgP/kg_soil * kg_soil/m3 * m * m^2 == kgP */
01863 
01864               /* floc layer of soil */
01865                  FLOC[cellLoc] = HP_FLOC_IC[HAB[cellLoc]]; /* kg OM/m2  */
01866                  FlocP[cellLoc] = FLOC[cellLoc]*HP_FLOC_IC_PC[HAB[cellLoc]]*HP_FLOC_IC_CTOOM[HAB[cellLoc]]; /* kg P /m2 */
01867                  FLOC_Z[cellLoc] = (double) FLOC[cellLoc] / GP_Floc_BD ; /* m */
01868 
01869               /* phosphorus */
01870                  TP_AtmosDepos[cellLoc]  = (double)TP_AtmosDepos[cellLoc] * conv_mgTOkg * CELL_SIZE / 365.0; /* P deposition, mgP/m2/yr * kg/mg * m2 / daysPerYear = kgP/day */
01871 /* v2.4.4 */       TP_SFWT_CONC[cellLoc]  = GP_TP_ICSFWAT * conv_mgTOg; /* mg/L * g/mg  => g/L */
01872                  TP_SF_WT[cellLoc] =TP_SFWT_CONC[cellLoc] * SFWT_VOL[cellLoc]; /* kg P */
01873                  TP_SFWT_CONC_MG[cellLoc] = TP_SFWT_CONC[cellLoc] * conv_gTOmg; /* mg/L */
01874                       /* using regression for predicting PO4 from TP */
01875                  PO4Pconc = Max(TP_SFWT_CONC_MG[cellLoc]*GP_PO4toTP + GP_PO4toTPint, 0.10 * TP_SFWT_CONC_MG[cellLoc]); /* mg/L */
01876                  PO4P = PO4Pconc * SFWT_VOL[cellLoc] /conv_kgTOg; /*kg P available (from conc. in mg/l) */
01877 
01878 /* v2.4.4 */ //      TP_SED_CONC[cellLoc] = GP_TP_ICSEDWAT * conv_mgTOg; /* mg/L * g/mg => g/L */
01879 //                 TP_SED_WT[cellLoc] = TP_SED_CONC[cellLoc] * HYD_SED_WAT_VOL[cellLoc]; /* kg P */
01880 //                      /* this is the active zone, where uptake, sorption, and mineralization take place */
01881 //                  TP_Act_to_Tot[cellLoc] = 1.0 / HP_TP_CONC_GRAD[HAB[cellLoc]]; /* ratio of TP conc in active zone relative to total */
01882 //                  TP_SED_WT_AZ[cellLoc] = TP_SED_CONC[cellLoc] * TP_Act_to_Tot[cellLoc] * HYD_DOM_ACTWAT_VOL[cellLoc]; /* kg P */
01883 //                  TP_SEDWT_CONCACT[cellLoc] =(HYD_DOM_ACTWAT_VOL[cellLoc] > 0.0) ?
01884 //                      ( TP_SED_WT_AZ[cellLoc]/HYD_DOM_ACTWAT_VOL[cellLoc] ) :
01885 //                      ( TP_SED_CONC[cellLoc]); /* g/L */
01886 //                  TP_SEDWT_CONCACTMG[cellLoc] = TP_SEDWT_CONCACT[cellLoc]*conv_gTOmg; /* mg/L */
01887 
01888 /* v2.8.4 concentration in Active Zone (TP_SEDWT_CONCACT) is initialed by map (data here are g/L) */
01889                  TP_Act_to_Tot[cellLoc] = 1.0 / HP_TP_CONC_GRAD[HAB[cellLoc]]; /* ratio of TP conc in active zone relative to total */
01890                                  TP_SED_CONC[cellLoc] = (TP_Act_to_Tot[cellLoc]>0.0) ? (TP_SEDWT_CONCACT[cellLoc] / TP_Act_to_Tot[cellLoc]) : (0.0);
01891 /* map */        TP_SEDWT_CONCACT[cellLoc] =(HYD_DOM_ACTWAT_VOL[cellLoc] > 0.0) ?
01892                      ( TP_SEDWT_CONCACT[cellLoc] ) :
01893                      ( 0.0 ); /* g/L */
01894                  TP_SEDWT_CONCACTMG[cellLoc] = TP_SEDWT_CONCACT[cellLoc]*conv_gTOmg; /* mg/L */
01895                  TP_SED_WT[cellLoc] = TP_SED_CONC[cellLoc] * HYD_SED_WAT_VOL[cellLoc]; /* kg P */
01896                  TP_SED_WT_AZ[cellLoc] = TP_SEDWT_CONCACT[cellLoc] * HYD_DOM_ACTWAT_VOL[cellLoc]; /* kg P */
01897 
01898 
01899               /* salt */
01900                  SALT_SED_WT[cellLoc] = HYD_SED_WAT_VOL[cellLoc]*HP_SALT_ICSEDWAT[HAB[cellLoc]];
01901                  SAL_SED_WT[cellLoc] = ( HYD_SED_WAT_VOL[cellLoc]>0.0 ) ? ( SALT_SED_WT[cellLoc]/HYD_SED_WAT_VOL[cellLoc] ) : ( 0.0);
01902                  SALT_SURF_WT[cellLoc] = SFWT_VOL[cellLoc]*HP_SALT_ICSFWAT[HAB[cellLoc]];
01903                  SAL_SF_WT[cellLoc] = ( SURFACE_WAT[cellLoc] > GP_WQualMonitZ ) ? ( SALT_SURF_WT[cellLoc]/SFWT_VOL[cellLoc] ) : ( 0.0);
01904 
01905               /* periphyton */
01906 /* 2.4.4 */       NC_ALG[cellLoc] = HP_ALG_MAX[HAB[cellLoc]] * GP_ALG_IC_MULT * GP_ALG_REF_MULT ; /* start w/ low, refuge-level of non-calcareous (eutrophic) periphyton, g C/m2 */
01907 /* 2.4.4 */       C_ALG[cellLoc]  = HP_ALG_MAX[HAB[cellLoc]] * GP_ALG_IC_MULT * (1.0 - GP_ALG_REF_MULT); /* g C/m2 */
01908                  /* ic PC of periph in oligotrophic area is 3% of max P:C, varies across space via (0.1->1.0) map */
01909 /* 2.4.4 */       NC_ALG_PC[cellLoc] = GP_ALG_PC; /* gP/ gC */
01910 /* 2.4.4 */       C_ALG_PC[cellLoc]  = GP_ALG_PC; /* gP/ gC */
01911 
01912                  NC_ALG_P[cellLoc] = NC_ALG[cellLoc]*NC_ALG_PC[cellLoc];   /* g P/m2 */
01913                  C_ALG_P[cellLoc] = C_ALG[cellLoc]*C_ALG_PC[cellLoc];  /* g P/m2 */  
01914 
01915               /* macrophytes */
01916 /* 2.4.4 */       MAC_PH_BIOMAS[cellLoc] = MAC_TOT_BIOM[cellLoc] * GP_MAC_IC_MULT * HP_PHBIO_MAX[HAB[cellLoc]]/MAC_MAX_BIO[cellLoc]; /* kg C/m2 */
01917                    /*  now calc the P and OM associated with that C */
01918 /* 2.4.4 */       mac_ph_PC[cellLoc] = HP_PHBIO_IC_PC[HAB[cellLoc]]; 
01919                  mac_ph_P[cellLoc] = MAC_PH_BIOMAS[cellLoc] * mac_ph_PC[cellLoc]; /* kg P/m2 */
01920                  mac_ph_OM[cellLoc] = MAC_PH_BIOMAS[cellLoc] / HP_PHBIO_IC_CTOOM[HAB[cellLoc]];
01921                  mac_ph_CtoOM[cellLoc] = HP_PHBIO_IC_CTOOM[HAB[cellLoc]];
01922                  PHBIO_AVAIL[cellLoc] = MAC_PH_BIOMAS[cellLoc]*Max(1.0-Max((PHBIO_SAT[cellLoc]-MAC_PH_BIOMAS[cellLoc]) /(PHBIO_SAT[cellLoc]-PHBIO_REFUGE[cellLoc]),0.0),0.0);
01923 
01924 /* 2.4.4 */       MAC_NOPH_BIOMAS[cellLoc] = MAC_TOT_BIOM[cellLoc] * GP_MAC_IC_MULT * HP_NPHBIO_MAX[HAB[cellLoc]]/MAC_MAX_BIO[cellLoc]; /* kg C/m2 */
01925                    /*  now calc the P and OM associated with that C */
01926 /* 2.4.4 */       mac_nph_PC[cellLoc] = HP_NPHBIO_IC_PC[HAB[cellLoc]]; 
01927                  mac_nph_P[cellLoc] = MAC_NOPH_BIOMAS[cellLoc] * mac_nph_PC[cellLoc];  /* kg P/m2 */
01928                  mac_nph_OM[cellLoc] = MAC_NOPH_BIOMAS[cellLoc] / HP_NPHBIO_IC_CTOOM[HAB[cellLoc]];
01929                  mac_nph_CtoOM[cellLoc] = HP_NPHBIO_IC_CTOOM[HAB[cellLoc]];
01930                  NPHBIO_AVAIL[cellLoc] = MAC_NOPH_BIOMAS[cellLoc]*Max(1.0-Max((NPHBIO_SAT[cellLoc]-MAC_NOPH_BIOMAS[cellLoc])/(NPHBIO_SAT[cellLoc]-NPHBIO_REFUGE[cellLoc]),0.0),0.0);
01931 
01932                  MAC_REL_BIOM[cellLoc] = ( MAC_TOT_BIOM[cellLoc] > 0 ) ? MAC_TOT_BIOM[cellLoc]/MAC_MAX_BIO[cellLoc] : 0.0;
01933                  MAC_LAI[cellLoc] = MAC_REL_BIOM[cellLoc]*HP_MAC_MAXLAI[HAB[cellLoc]];
01934                  MAC_HEIGHT[cellLoc] = MAC_REL_BIOM[cellLoc]*HP_MAC_MAXHT[HAB[cellLoc]];
01935                  LAI_eff[cellLoc] =  (MAC_HEIGHT[cellLoc]>0.0) ? (Max(1.0 - SURFACE_WAT[cellLoc]/MAC_HEIGHT[cellLoc], 0.0)*MAC_LAI[cellLoc]) : (0.0)  ;                 
01936 
01937 /* end of initialization of major state variables */
01938                  
01939 /* *************************** */
01940 /* These are the multiple calculations used if particular modules are turned off. \n
01941  NOTE: THIS section (of init_eqns() ) is not fully updated for properly
01942  turning off individual **interacting** *biological/chemical* modules.  
01943  If one *biological/chemical* module is turned off, 
01944  they all need to be turned off. (Note that cell_dyn's 3,5,6 should always be off). \n
01945 
01946  *** \n
01947  The following *biological/chemical* modules must be ON or OFF as a group:
01948  (cell_dyn2 + cell_dyn4 + cell_dyn8 + cell_dyn9  + cell_dyn12)
01949  cell_dyn13, the net settling rate module, can be turned on only when above module group is off
01950  *** \n
01951  
01952  In particular, the budget will
01953  not properly reflect actual dynamics if those 
01954  modules are not treated as a group.
01955 */
01956      NC_ALG_MORT_POT[cellLoc] = ( UNSAT_DEPTH[cellLoc]>0.05 ) ? ( NC_ALG[cellLoc]*GP_ALG_RC_MORT_DRY ) : ( NC_ALG[cellLoc]*GP_ALG_RC_MORT);
01957                      /* calcareous periphyton */
01958      C_ALG_MORT_POT[cellLoc] = ( UNSAT_DEPTH[cellLoc]>0.05 ) ? ( C_ALG[cellLoc]*GP_ALG_RC_MORT_DRY ) : ( C_ALG[cellLoc]*GP_ALG_RC_MORT);
01959                  ALG_TEMP_CF[cellLoc]  = tempCF(0, 0.20, GP_ALG_TEMP_OPT, 5.0, 40.0, H2O_TEMP[cellLoc]);
01960      NC_ALG_RESP_POT[cellLoc]  = 
01961          ( UNSAT_DEPTH[cellLoc]<0.05 ) ? 
01962          ( GP_ALG_RC_RESP*ALG_TEMP_CF[cellLoc]*NC_ALG[cellLoc] ) : 
01963          ( 0.0);
01964      NC_ALG_RESP[cellLoc]  =  
01965          ( NC_ALG_RESP_POT[cellLoc]*DT>NC_ALG[cellLoc] ) ? 
01966          ( NC_ALG[cellLoc]/DT ) : 
01967          ( NC_ALG_RESP_POT[cellLoc]);
01968                      /* calcareous periphyton */
01969      C_ALG_RESP_POT[cellLoc]  = 
01970          ( UNSAT_DEPTH[cellLoc]<0.05 ) ? 
01971          ( GP_ALG_RC_RESP*ALG_TEMP_CF[cellLoc]*C_ALG[cellLoc] ) : 
01972          ( 0.0);
01973      C_ALG_RESP[cellLoc]  =  
01974          ( C_ALG_RESP_POT[cellLoc]*DT>C_ALG[cellLoc] ) ? 
01975          ( C_ALG[cellLoc]/DT ) : 
01976          ( C_ALG_RESP_POT[cellLoc]);
01977 
01978      NC_ALG_AVAIL_MORT[cellLoc] = NC_ALG[cellLoc]-ALG_REFUGE[cellLoc];
01979      NC_ALG_MORT[cellLoc] = ( (NC_ALG_MORT_POT[cellLoc])*DT>NC_ALG_AVAIL_MORT[cellLoc] ) ? ( (NC_ALG_AVAIL_MORT[cellLoc])/DT ) : ( NC_ALG_MORT_POT[cellLoc]);
01980                      /* calcareous periphyton */
01981      C_ALG_AVAIL_MORT[cellLoc]  = C_ALG[cellLoc]-ALG_REFUGE[cellLoc];
01982      C_ALG_MORT[cellLoc]  = ( (C_ALG_MORT_POT[cellLoc])*DT>C_ALG_AVAIL_MORT[cellLoc] ) ? ( (C_ALG_AVAIL_MORT[cellLoc])/DT ) : ( C_ALG_MORT_POT[cellLoc]);
01983 
01984 /* light, water, temperature controls apply to calc and non-calc periphyton */
01985      ALG_LIGHT_EXTINCT[cellLoc]  =  0.01; /* light extinction coef */
01986                      /* algal self-shading implicit in density-dependent constraint function later */
01987      ALG_INCID_LIGHT[cellLoc]  = SOLRADGRD[cellLoc]*Exp(-MAC_LAI[cellLoc]*GP_ALG_SHADE_FACTOR);
01988                  Z_extinct = SURFACE_WAT[cellLoc]*ALG_LIGHT_EXTINCT[cellLoc];
01989      I_ISat = ALG_INCID_LIGHT[cellLoc]/GP_ALG_LIGHT_SAT;
01990                      /*  averaged over whole water column (based on Steele '65) */
01991      ALG_LIGHT_CF[cellLoc]  = ( Z_extinct > 0.0 ) ? 
01992          ( 2.718/Z_extinct * (Exp(-I_ISat * Exp(-Z_extinct)) - Exp(-I_ISat)) ) :
01993                 (I_ISat*Exp(1.0-I_ISat));
01994                      /*  low-water growth constraint ready for something better based on data */
01995      ALG_WAT_CF[cellLoc]  = ( SURFACE_WAT[cellLoc]>0.0 ) ? ( 1.0 ) : ( 0.0);
01996 /* the 2 communities have same growth response to avail phosphorus - avail P is roughly calc'd from TP */
01997      NC_ALG_NUT_CF[cellLoc]  =  PO4Pconc/(PO4Pconc+GP_NC_ALG_KS_P) ;
01998      C_ALG_NUT_CF[cellLoc]  = PO4Pconc/(PO4Pconc+GP_C_ALG_KS_P); 
01999       min_litTemp = Min(ALG_LIGHT_CF[cellLoc],ALG_TEMP_CF[cellLoc]);
02000       NC_ALG_PROD_CF[cellLoc]  = Min(min_litTemp,ALG_WAT_CF[cellLoc])*NC_ALG_NUT_CF[cellLoc];
02001       C_ALG_PROD_CF[cellLoc]   = Min(min_litTemp,ALG_WAT_CF[cellLoc])*C_ALG_NUT_CF[cellLoc];
02002 /* gross production of the 2 communities (gC/m2, NOT kgC/m2) */
02003                      /* density constraint contains both noncalc and calc, competition effect accentuated by calc algae */
02004                      /* used to increase calc growth by factor of 10 */
02005       NC_ALG_GPP[cellLoc]  =  NC_ALG_PROD_CF[cellLoc]*GP_ALG_RC_PROD*NC_ALG[cellLoc]       
02006              *Max( (1.0-(GP_AlgComp*C_ALG[cellLoc]+NC_ALG[cellLoc])/HP_ALG_MAX[HAB[cellLoc]]),0.0);
02007      C_ALG_GPP[cellLoc]  =  C_ALG_PROD_CF[cellLoc]*GP_ALG_RC_PROD*C_ALG[cellLoc] 
02008        *Max( (1.0-(    C_ALG[cellLoc]+NC_ALG[cellLoc])/HP_ALG_MAX[HAB[cellLoc]]),0.0);
02009 /* check for available P mass (the MichMent kinetics nutCF do not) */
02010      tmp = ( (NC_ALG_GPP[cellLoc]+C_ALG_GPP[cellLoc]) > 0) ? 
02011          PO4P / ( (NC_ALG_GPP[cellLoc]+C_ALG_GPP[cellLoc]) 
02012          * 0.001*GP_ALG_PC*CELL_SIZE*DT) :
02013          1.0;
02014      if (tmp < 1.0) {
02015          NC_ALG_GPP[cellLoc] *= tmp;   
02016          C_ALG_GPP[cellLoc] *= tmp; 
02017     /* can have high conc, but low mass of P avail, in presence of high peri biomass and high demand */
02018     /* reduce the production proportionally if excess demand is found */
02019        }
02020 /* total of calc and noncalc algae available and their total NPP */
02021      NC_ALG_NPP[cellLoc]  = NC_ALG_GPP[cellLoc]-NC_ALG_RESP[cellLoc]; 
02022      C_ALG_NPP[cellLoc]  = C_ALG_GPP[cellLoc]-C_ALG_RESP[cellLoc]; 
02023 
02024 
02025      DOM_QUALITY_CF[cellLoc]  = (Max(TP_SFWT_CONC_MG[cellLoc],TP_SEDWT_CONCACTMG[cellLoc]))
02026          /GP_DOM_DECOMP_POPT; /* mg/L */
02027      DOM_TEMP_CF[cellLoc] = Exp(0.20*(H2O_TEMP[cellLoc]-GP_DOM_DECOMP_TOPT))*pow(((40.0-H2O_TEMP[cellLoc])/(40.0-GP_DOM_DECOMP_TOPT)),(0.20*(40.0-GP_DOM_DECOMP_TOPT)));
02028      soil_MOIST_CF[cellLoc] = pow(Max(UNSAT_MOIST_PRP[cellLoc],0.0),0.75);
02029      DOM_DECOMP_POT[cellLoc] = GP_DOM_RCDECOMP*DOM_QUALITY_CF[cellLoc]*DOM_TEMP_CF[cellLoc]*DEPOS_ORG_MAT[cellLoc]*(Min(DOM_SED_AEROB_Z[cellLoc]/HP_DOM_MAXDEPTH[HAB[cellLoc]],1.0)*soil_MOIST_CF[cellLoc]+GP_DOM_DECOMPRED*Min(DOM_SED_ANAEROB_Z[cellLoc]/HP_DOM_MAXDEPTH[HAB[cellLoc]],1.0));
02030      DOM_DECOMP[cellLoc] =  ( (DOM_DECOMP_POT[cellLoc])*DT>DEPOS_ORG_MAT[cellLoc] ) ? ( (DEPOS_ORG_MAT[cellLoc])/DT ) : ( DOM_DECOMP_POT[cellLoc]);
02031 /* added for P DOM stoich */
02032      DOP_DECOMP[cellLoc] = DOM_DECOMP[cellLoc] * DOM_P_OM[cellLoc]; 
02033 
02034      SAT_VS_UNSAT[cellLoc] = 1/Exp(100.0*Max((SURFACE_WAT[cellLoc]-UNSAT_DEPTH[cellLoc]),0.0));
02035      UNSAT_WT_POT[cellLoc] = Max(UNSAT_CAP[cellLoc]-UNSAT_WATER[cellLoc],0.0);
02036          SF_WT_TO_SAT_DOWNFLOW[cellLoc]  = ( (1.0-SAT_VS_UNSAT[cellLoc])*UNSAT_WT_POT[cellLoc]*DT>SURFACE_WAT[cellLoc] ) ? ( SURFACE_WAT[cellLoc]/DT ) : ( (1.0-SAT_VS_UNSAT[cellLoc])*UNSAT_WT_POT[cellLoc]); 
02037      SAT_WT_RECHG[cellLoc] = ( GP_HYD_RCRECHG*DT>SAT_WATER[cellLoc] ) ? ( SAT_WATER[cellLoc]/DT ) : ( GP_HYD_RCRECHG);
02038      SF_WT_POT_INF[cellLoc] = ( (SURFACE_WAT[cellLoc]<HP_HYD_RCINFILT[HAB[cellLoc]]*DT) ) ? ( SURFACE_WAT[cellLoc]/DT ) : ( HP_HYD_RCINFILT[HAB[cellLoc]]);
02039      SF_WT_INFILTRATION[cellLoc] = ( SF_WT_POT_INF[cellLoc]*SAT_VS_UNSAT[cellLoc]*DT>UNSAT_WT_POT[cellLoc] ) ? ( (UNSAT_WT_POT[cellLoc])/DT ) : ( SF_WT_POT_INF[cellLoc]*SAT_VS_UNSAT[cellLoc]);
02040      HYD_DOM_ACTWAT_PRES[cellLoc] = ( HYD_DOM_ACTWAT_VOL[cellLoc] > 0.01 ) ? ( 1.0 ) : ( 0.0);
02041      HYD_WATER_AVAIL[cellLoc] = Min(1.0, UNSAT_MOIST_PRP[cellLoc]+Exp(-10.0*Max(UNSAT_DEPTH[cellLoc]-HP_NPHBIO_ROOTDEPTH[HAB[cellLoc]],0.0)));
02042 
02043      MAC_LIGHT_CF[cellLoc] = SOLRADGRD[cellLoc]/HP_MAC_LIGHTSAT[HAB[cellLoc]]*Exp(1.0-SOLRADGRD[cellLoc]/HP_MAC_LIGHTSAT[HAB[cellLoc]]);
02044      MAC_TEMP_CF[cellLoc] = Exp(0.20*(AIR_TEMP[cellLoc]-HP_MAC_TEMPOPT[HAB[cellLoc]])) *pow(((40.0-AIR_TEMP[cellLoc])/(40.0-HP_MAC_TEMPOPT[HAB[cellLoc]])),(0.20*(40.0-HP_MAC_TEMPOPT[HAB[cellLoc]])));
02045      MAC_WATER_AVAIL_CF[cellLoc] = graph8(0x0,HYD_WATER_AVAIL[cellLoc]);
02046      MAC_WATER_CF[cellLoc] = Min(MAC_WATER_AVAIL_CF[cellLoc], Max(1.0-Max((SURFACE_WAT[cellLoc]-HP_MAC_WAT_TOLER[HAB[cellLoc]])/HP_MAC_WAT_TOLER[HAB[cellLoc]],0.0),0.0));
02047      MAC_NUT_CF[cellLoc] =  TP_SEDWT_CONCACT[cellLoc]/(TP_SEDWT_CONCACT[cellLoc]+HP_MAC_KSP[HAB[cellLoc]]*0.001) ;
02048 
02049      MAC_SALT_CF[cellLoc] = ( HP_MAC_SALIN_THRESH[HAB[cellLoc]]>0.0 ) ? (  Max( 1.0-Max(SAL_SED_WT[cellLoc]-HP_MAC_SALIN_THRESH[HAB[cellLoc]],0.0)/HP_MAC_SALIN_THRESH[HAB[cellLoc]],0.0) ) : ( Max(1.0-SAL_SED_WT[cellLoc],0.0));
02050      min_litTemp = Min(MAC_LIGHT_CF[cellLoc], MAC_TEMP_CF[cellLoc]);
02051      MAC_PROD_CF[cellLoc]  = Min(min_litTemp,MAC_WATER_CF[cellLoc])
02052          *MAC_NUT_CF[cellLoc]*MAC_SALT_CF[cellLoc];
02053      PHBIO_NPP[cellLoc] = HP_PHBIO_RCNPP[HAB[cellLoc]]*MAC_PROD_CF[cellLoc]*MAC_PH_BIOMAS[cellLoc]* Max( (1.0-MAC_TOT_BIOM[cellLoc]/MAC_MAX_BIO[cellLoc]), 0.0);
02054 /* check for available P mass that will be taken up (MichMent kinetics in nutCF does not) */
02055      tmp = (PHBIO_NPP[cellLoc] > 0) ? 
02056          TP_SED_WT[cellLoc] / ( PHBIO_NPP[cellLoc] * HP_NPHBIO_IC_PC[HAB[cellLoc]]*CELL_SIZE*DT) :
02057          1.0;
02058      if (tmp < 1.0) PHBIO_NPP[cellLoc] *= tmp;   
02059     /* reduce the production proportionally if excess demand is found */
02060     /* can have high conc, but low mass of P avail, in presence of high plant biomass and high demand */
02061 /* now add the P and OM associated with that C */
02062      phbio_npp_P[cellLoc] = PHBIO_NPP[cellLoc] * HP_PHBIO_IC_PC[HAB[cellLoc]];     /* habitat-specfic stoichiometry */
02063      phbio_npp_OM[cellLoc] = PHBIO_NPP[cellLoc] / HP_PHBIO_IC_CTOOM[HAB[cellLoc]]; /* habitat-specfic stoichiometry */
02064 
02065 /* init ("target") ph/nph ratio and new transloc algorithm */
02066      MAC_PHtoNPH_Init = HP_PHBIO_MAX[HAB[cellLoc]] / HP_NPHBIO_MAX[HAB[cellLoc]] ;
02067      MAC_PHtoNPH = MAC_PH_BIOMAS[cellLoc] / MAC_NOPH_BIOMAS[cellLoc];
02068 
02069      PHBIO_TRANSLOC_POT[cellLoc]  = 0.0; /* (MAC_PHtoNPH<MAC_PHtoNPH_Init) ? (exp(HP_MAC_TRANSLOC_RC[HAB[cellLoc]] *(MAC_PHtoNPH_Init-MAC_PHtoNPH)) - 1.0) : (0.0) */ 
02070 
02071      PHBIO_TRANSLOC[cellLoc] =  ( (PHBIO_TRANSLOC_POT[cellLoc])*DT >NPHBIO_AVAIL[cellLoc] ) ? ( (NPHBIO_AVAIL[cellLoc])/DT ) : ( PHBIO_TRANSLOC_POT[cellLoc]);
02072 /*  now remove the P and OM associated with that C */
02073      phbio_transl_P[cellLoc] = PHBIO_TRANSLOC[cellLoc] * mac_nph_PC[cellLoc];
02074      phbio_transl_OM[cellLoc] = PHBIO_TRANSLOC[cellLoc] / mac_nph_CtoOM[cellLoc];
02075      NPHBIO_MORT_POT[cellLoc] = NPHBIO_AVAIL[cellLoc]*HP_PHBIO_RCMORT[HAB[cellLoc]]*(1.0-MAC_PH_BIOMAS[cellLoc]/HP_PHBIO_MAX[HAB[cellLoc]]);
02076      NPHBIO_MORT[cellLoc] =  ( (PHBIO_TRANSLOC[cellLoc]+NPHBIO_MORT_POT[cellLoc])*DT>NPHBIO_AVAIL[cellLoc] ) ? ( (NPHBIO_AVAIL[cellLoc]-PHBIO_TRANSLOC[cellLoc]*DT)/DT ) : ( NPHBIO_MORT_POT[cellLoc]);
02077      PHBIO_MORT_POT[cellLoc] = HP_PHBIO_RCMORT[HAB[cellLoc]] *PHBIO_AVAIL[cellLoc] *(1.0-MAC_WATER_AVAIL_CF[cellLoc]);
02078 /* now remove the P and OM associated with that C */
02079      nphbio_mort_P[cellLoc] = NPHBIO_MORT[cellLoc] * mac_nph_PC[cellLoc];
02080      nphbio_mort_OM[cellLoc] = NPHBIO_MORT[cellLoc] / mac_nph_CtoOM[cellLoc];
02081 
02082      NPHBIO_TRANSLOC_POT[cellLoc] = 0.0; /* (MAC_PHtoNPH>MAC_PHtoNPH_Init) ? (exp(HP_MAC_TRANSLOC_RC[HAB[cellLoc]] *(MAC_PHtoNPH-MAC_PHtoNPH_Init)) - 1.0) : (0.0) */ 
02083      NPHBIO_TRANSLOC[cellLoc] = ( (NPHBIO_TRANSLOC_POT[cellLoc])*DT >MAC_PH_BIOMAS[cellLoc] ) ? ( (MAC_PH_BIOMAS[cellLoc])/DT ) : ( NPHBIO_TRANSLOC_POT[cellLoc]);
02084 /*  now remove the P and OM associated with that C */
02085      nphbio_transl_P[cellLoc] = NPHBIO_TRANSLOC[cellLoc] * mac_ph_PC[cellLoc];
02086      nphbio_transl_OM[cellLoc] = NPHBIO_TRANSLOC[cellLoc] / mac_ph_CtoOM[cellLoc];
02087      PHBIO_MORT[cellLoc] = ( (PHBIO_MORT_POT[cellLoc]+NPHBIO_TRANSLOC[cellLoc])*DT>PHBIO_AVAIL[cellLoc] ) ? ( (PHBIO_AVAIL[cellLoc]-NPHBIO_TRANSLOC[cellLoc]*DT)/DT ) : ( PHBIO_MORT_POT[cellLoc]);
02088 /*  now remove the P associated with that C */
02089      phbio_mort_P[cellLoc] = PHBIO_MORT[cellLoc] * mac_ph_PC[cellLoc];
02090      phbio_mort_OM[cellLoc] = PHBIO_MORT[cellLoc] / mac_ph_CtoOM[cellLoc];
02091 
02092 
02093      FLOC_DECOMP_QUAL_CF[cellLoc] = Min(TP_SFWT_CONC_MG[cellLoc]/GP_DOM_DECOMP_POPT,1.0) ;
02094      FLOC_DECOMP_POT[cellLoc] = GP_DOM_RCDECOMP*FLOC[cellLoc]*DOM_TEMP_CF[cellLoc] *FLOC_DECOMP_QUAL_CF[cellLoc];
02095      FLOC_DECOMP[cellLoc] = ( (FLOC_DECOMP_POT[cellLoc])*DT>FLOC[cellLoc] ) ? ( (FLOC[cellLoc])/DT ) : ( FLOC_DECOMP_POT[cellLoc]);
02096      FLOC_DEPO_POT[cellLoc] = (  SURFACE_WAT[cellLoc] > GP_DetentZ ) ? ( FLOC[cellLoc]*0.05 ) : ( FLOC[cellLoc]/DT);
02097      FLOC_DEPO[cellLoc] = ( (FLOC_DEPO_POT[cellLoc]+FLOC_DECOMP[cellLoc])*DT>FLOC[cellLoc] ) ? ( (FLOC[cellLoc]-FLOC_DECOMP[cellLoc]*DT)/DT ) : ( FLOC_DEPO_POT[cellLoc]);
02098  
02099      HYD_MANNINGS_N[cellLoc]  = Max(-Abs((HP_MAC_MAXROUGH[HAB[cellLoc]]-HP_MAC_MINROUGH[HAB[cellLoc]])*  (pow(2.0,(1.0-SURFACE_WAT[cellLoc]/MAC_HEIGHT[cellLoc]))-1.0)) + HP_MAC_MAXROUGH[HAB[cellLoc]],HP_MAC_MINROUGH[HAB[cellLoc]]);
02100   } /* spatial loop end */
02101   } /* spatial loop end */
02102   usrErr("Done.");
02103 
02104 } /* end of init_eqns */
02105 
02106 
02110 void init_canals(int irun) 
02111 {
02112    if (irun == 1) {
02113       usrErr("Initializing Water Management...");
02114       Canal_Network_Init(GP_DATUM_DISTANCE,SED_ELEV); /* WatMgmt.c - initialize the canal network topology and data */
02115       usrErr("Done Water Management.");
02116    }
02117    else {
02118       reinitCanals();
02119    }
02120 
02121 }
02122 
02124 void init_succession(void) 
02125 {
02126    HabSwitch_Init( ); 
02127 
02128 }
02129 
02131 void reinitBIR(void) 
02132 {
02133    usrErr0("Re-initializing Basin/Indicator-Region info...");
02134    BIRstats_reset(); 
02135    BIRbudg_reset(); 
02136    Cell_reset_avg(); 
02137    Cell_reset_hydper(); 
02138    usrErr("Done.");
02139 }
02140 
02142 void reinitCanals(void) 
02143 {
02144    usrErr0("Re-initializing Canal depths & constituent masses...");
02145    CanalReInit();  
02146    usrErr("Done.");
02147 }
02148 
02149 
02162 void gen_output(int step, ViewParm *view)
02163 {
02164     #define numOutputs 50000
02165     static int iw[numOutputs];
02166     int oIndex;
02167     ViewParm   *vp;
02168 
02176     static outVar_struct tgen[] = {
02177       { (float**)&TP_settlDays, "TP_settlDays", 'f' },
02178       { (float**)&FLOC, "FLOC", 'f' },
02179       { (float**)&FLOC_DECOMP, "FLOC_DECOMP", 'f' },
02180       { (float**)&FLOC_DECOMP_POT, "FLOC_DECOMP_POT", 'f' },
02181       { (float**)&FLOC_DECOMP_QUAL_CF, "FLOC_DECOMP_QUAL_CF", 'f' },
02182       { (float**)&FLOC_DEPO, "FLOC_DEPO", 'f' },
02183       { (float**)&FLOC_DEPO_POT, "FLOC_DEPO_POT", 'f' },
02184       { (float**)&FLOC_FR_ALGAE, "FLOC_FR_ALGAE", 'f' },
02185       { (float**)&FLOC_Z, "FLOC_Z", 'f' },
02186       { (float**)&FlocP_OMrep, "FlocP_OMrep", 'f' },
02187       { (float**)&soil_MOIST_CF, "soil_MOIST_CF", 'f' },
02188       { (float**)&TP_SED_MINER, "TP_SED_MINER", 'f' },
02189       { (float**)&TP_SFWT_MINER, "TP_SFWT_MINER", 'f' },
02190       { (float**)&AIR_TEMP, "AIR_TEMP", 'f' },
02191       { (unsigned char**)&HAB, "HAB", 'c' },
02192       { (float**)&SOLRAD274, "SOLRAD274", 'f' },
02193       { (float**)&SOLRADGRD, "SOLRADGRD", 'f' },
02194       { (float**)&H2O_TEMP, "H2O_TEMP", 'f' },
02195       { (float**)&HYD_DOM_ACTWAT_PRES, "HYD_DOM_ACTWAT_PRES", 'f' },
02196       { (float**)&HYD_DOM_ACTWAT_VOL, "HYD_DOM_ACTWAT_VOL", 'f' },
02197       { (float**)&HYD_ET, "HYD_ET", 'f' },
02198       { (float**)&HYD_EVAP_CALC, "HYD_EVAP_CALC", 'f' },
02199       { (float**)&HYD_MANNINGS_N, "HYD_MANNINGS_N", 'f' },
02200       { (float**)&HYD_SAT_POT_TRANS, "HYD_SAT_POT_TRANS", 'f' },
02201       { (float**)&HYD_SED_WAT_VOL, "HYD_SED_WAT_VOL", 'f' },
02202       { (float**)&HYD_TOT_POT_TRANSP, "HYD_TOT_POT_TRANSP", 'f' },
02203       { (float**)&HYD_TRANSP, "HYD_TRANSP", 'f' },
02204       { (float**)&HYD_UNSAT_POT_TRANS, "HYD_UNSAT_POT_TRANS", 'f' },
02205       { (float**)&HYD_WATER_AVAIL, "HYD_WATER_AVAIL", 'f' },
02206       { (float**)&HydTotHd, "HydTotHd", 'f' },
02207       { (float**)&HydRelDepPosNeg, "HydRelDepPosNeg", 'f' },
02208       { (float**)&LAI_eff, "LAI_eff", 'f' },
02209       { (float**)&MAC_WATER_AVAIL_CF, "MAC_WATER_AVAIL_CF", 'f' },
02210       { (float**)&SAT_TO_UNSAT_FL, "SAT_TO_UNSAT_FL", 'f' },
02211       { (float**)&SAT_VS_UNSAT, "SAT_VS_UNSAT", 'f' },
02212       { (float**)&SAT_WATER, "SAT_WATER", 'f' },
02213       { (float**)&SAT_WT_HEAD, "SAT_WT_HEAD", 'f' },
02214       { (float**)&SAT_WT_RECHG, "SAT_WT_RECHG", 'f' },
02215       { (float**)&SAT_WT_TRANSP, "SAT_WT_TRANSP", 'f' },
02216       { (float**)&SF_WT_EVAP, "SF_WT_EVAP", 'f' },
02217       { (float**)&SF_WT_FROM_RAIN, "SF_WT_FROM_RAIN", 'f' },
02218       { (float**)&SF_WT_INFILTRATION, "SF_WT_INFILTRATION", 'f' },
02219       { (float**)&SF_WT_POT_INF, "SF_WT_POT_INF", 'f' },
02220       { (float**)&SF_WT_TO_SAT_DOWNFLOW, "SF_WT_TO_SAT_DOWNFLOW", 'f' },
02221       { (float**)&SF_WT_VEL_mag, "SF_WT_VEL_mag", 'f' },
02222       { (float**)&BCmodel_sfwat, "BCmodel_sfwat", 'f' },
02223       { (float**)&SFWT_VOL, "SFWT_VOL", 'f' },
02224       { (float**)&SURFACE_WAT, "SURFACE_WAT", 'f' },
02225       { (float**)&UNSAT_AVAIL, "UNSAT_AVAIL", 'f' },
02226       { (float**)&UNSAT_CAP, "UNSAT_CAP", 'f' },
02227       { (float**)&UNSAT_DEPTH, "UNSAT_DEPTH", 'f' },
02228       { (float**)&UNSAT_HYD_COND_CF, "UNSAT_HYD_COND_CF", 'f' },
02229       { (float**)&UNSAT_MOIST_PRP, "UNSAT_MOIST_PRP", 'f' },
02230       { (float**)&UNSAT_PERC, "UNSAT_PERC", 'f' },
02231       { (float**)&UNSAT_TO_SAT_FL, "UNSAT_TO_SAT_FL", 'f' },
02232       { (float**)&UNSAT_TRANSP, "UNSAT_TRANSP", 'f' },
02233       { (float**)&UNSAT_WATER, "UNSAT_WATER", 'f' },
02234       { (float**)&UNSAT_WT_POT, "UNSAT_WT_POT", 'f' },
02235       { (float**)&ELEVATION, "ELEVATION", 'f' },
02236       { (float**)&HYD_RCCONDUCT, "HYD_RCCONDUCT", 'f' },
02237       { (unsigned char**)&ON_MAP, "ON_MAP", 'c' },
02238       { (float**)&SED_INACT_Z, "SED_INACT_Z", 'f' },
02239       { (float**)&MAC_HEIGHT, "MAC_HEIGHT", 'f' },
02240       { (float**)&MAC_LAI, "MAC_LAI", 'f' },
02241       { (float**)&MAC_LIGHT_CF, "MAC_LIGHT_CF", 'f' },
02242       { (float**)&MAC_MAX_BIO, "MAC_MAX_BIO", 'f' },
02243       { (float**)&MAC_NOPH_BIOMAS, "MAC_NOPH_BIOMAS", 'f' },
02244       { (float**)&mac_nph_PC_rep, "mac_nph_PC_rep", 'f' },
02245       { (float**)&MAC_NUT_CF, "MAC_NUT_CF", 'f' },
02246       { (float**)&MAC_PH_BIOMAS, "MAC_PH_BIOMAS", 'f' },
02247       { (float**)&mac_ph_PC_rep, "mac_ph_PC_rep", 'f' },
02248       { (float**)&MAC_PROD_CF, "MAC_PROD_CF", 'f' },
02249       { (float**)&MAC_REL_BIOM, "MAC_REL_BIOM", 'f' },
02250       { (float**)&MAC_SALT_CF, "MAC_SALT_CF", 'f' },
02251       { (float**)&MAC_TEMP_CF, "MAC_TEMP_CF", 'f' },
02252       { (float**)&MAC_TOT_BIOM, "MAC_TOT_BIOM", 'f' },
02253       { (float**)&MAC_WATER_CF, "MAC_WATER_CF", 'f' },
02254       { (float**)&NPHBIO_AVAIL, "NPHBIO_AVAIL", 'f' },
02255       { (float**)&NPHBIO_MORT, "NPHBIO_MORT", 'f' },
02256       { (float**)&NPHBIO_MORT_POT, "NPHBIO_MORT_POT", 'f' },
02257       { (float**)&NPHBIO_REFUGE, "NPHBIO_REFUGE", 'f' },
02258       { (float**)&NPHBIO_SAT, "NPHBIO_SAT", 'f' },
02259       { (float**)&NPHBIO_TRANSLOC, "NPHBIO_TRANSLOC", 'f' },
02260       { (float**)&NPHBIO_TRANSLOC_POT, "NPHBIO_TRANSLOC_POT", 'f' },
02261       { (float**)&PHBIO_AVAIL, "PHBIO_AVAIL", 'f' },
02262       { (float**)&PHBIO_MORT, "PHBIO_MORT", 'f' },
02263       { (float**)&PHBIO_MORT_POT, "PHBIO_MORT_POT", 'f' },
02264       { (float**)&PHBIO_NPP, "PHBIO_NPP", 'f' },
02265       { (float**)&PHBIO_REFUGE, "PHBIO_REFUGE", 'f' },
02266       { (float**)&PHBIO_SAT, "PHBIO_SAT", 'f' },
02267       { (float**)&PHBIO_TRANSLOC, "PHBIO_TRANSLOC", 'f' },
02268       { (float**)&PHBIO_TRANSLOC_POT, "PHBIO_TRANSLOC_POT", 'f' },
02269       { (float**)&TP_SEDWT_UPTAKE, "TP_SEDWT_UPTAKE", 'f' },
02270       { (float**)&ALG_INCID_LIGHT, "ALG_INCID_LIGHT", 'f' },
02271       { (float**)&ALG_LIGHT_CF, "ALG_LIGHT_CF", 'f' },
02272       { (float**)&ALG_LIGHT_EXTINCT, "ALG_LIGHT_EXTINCT", 'f' },
02273       { (float**)&ALG_REFUGE, "ALG_REFUGE", 'f' },
02274       { (float**)&ALG_SAT, "ALG_SAT", 'f' },
02275       { (float**)&ALG_TEMP_CF, "ALG_TEMP_CF", 'f' },
02276       { (float**)&ALG_TOT, "ALG_TOT", 'f' },
02277       { (float**)&ALG_WAT_CF, "ALG_WAT_CF", 'f' },
02278       { (float**)&C_ALG, "C_ALG", 'f' },
02279       { (float**)&C_ALG_AVAIL_MORT, "C_ALG_AVAIL_MORT", 'f' },
02280       { (float**)&C_ALG_GPP, "C_ALG_GPP", 'f' },
02281       { (float**)&C_ALG_MORT, "C_ALG_MORT", 'f' },
02282       { (float**)&C_ALG_MORT_POT, "C_ALG_MORT_POT", 'f' },
02283       { (float**)&C_ALG_NPP, "C_ALG_NPP", 'f' },
02284       { (float**)&C_ALG_NUT_CF, "C_ALG_NUT_CF", 'f' },
02285       { (float**)&C_ALG_PROD_CF, "C_ALG_PROD_CF", 'f' },
02286       { (float**)&C_ALG_RESP, "C_ALG_RESP", 'f' },
02287       { (float**)&C_ALG_RESP_POT, "C_ALG_RESP_POT", 'f' },
02288       { (float**)&NC_ALG, "NC_ALG", 'f' },
02289       { (float**)&NC_ALG_AVAIL_MORT, "NC_ALG_AVAIL_MORT", 'f' },
02290       { (float**)&NC_ALG_GPP, "NC_ALG_GPP", 'f' },
02291       { (float**)&NC_ALG_MORT, "NC_ALG_MORT", 'f' },
02292       { (float**)&NC_ALG_MORT_POT, "NC_ALG_MORT_POT", 'f' },
02293       { (float**)&NC_ALG_NPP, "NC_ALG_NPP", 'f' },
02294       { (float**)&NC_ALG_NUT_CF, "NC_ALG_NUT_CF", 'f' },
02295       { (float**)&NC_ALG_PROD_CF, "NC_ALG_PROD_CF", 'f' },
02296       { (float**)&NC_ALG_RESP, "NC_ALG_RESP", 'f' },
02297       { (float**)&NC_ALG_RESP_POT, "NC_ALG_RESP_POT", 'f' },
02298       { (float**)&TP_SFWT_UPTAK, "TP_SFWT_UPTAK", 'f' },
02299       { (float**)&TP_Act_to_TotRep, "TP_Act_to_TotRep", 'f' },
02300       { (float**)&TP_DNFLOW, "TP_DNFLOW", 'f' },
02301       { (float**)&TP_DNFLOW_POT, "TP_DNFLOW_POT", 'f' },
02302       { (float**)&TP_Atm_Depos, "TP_Atm_Depos", 'f' },
02303       { (float**)&TP_K, "TP_K", 'f' },
02304       { (double**)&TP_SED_CONC, "TP_SED_CONC", 'd' },
02305       { (double**)&TP_SED_WT, "TP_SED_WT", 'd' },
02306       { (double**)&TP_SED_WT_AZ, "TP_SED_WT_AZ", 'd' },
02307       { (double**)&TP_SEDWT_CONCACT, "TP_SEDWT_CONCACT", 'd' },
02308       { (float**)&TP_SEDWT_CONCACTMG, "TP_SEDWT_CONCACTMG", 'f' },
02309       { (float**)&TP_settl, "TP_settl", 'f' },
02310       { (double**)&TP_SF_WT, "TP_SF_WT", 'd' },
02311       { (double**)&TP_SFWT_CONC, "TP_SFWT_CONC", 'd' },
02312       { (float**)&TP_SFWT_CONC_MG, "TP_SFWT_CONC_MG", 'f' },
02313       { (double**)&TP_SORB, "TP_SORB", 'd' },
02314       { (float**)&TP_SORB_POT, "TP_SORB_POT", 'f' },
02315       { (double**)&TP_SORBCONC, "TP_SORBCONC", 'd' },
02316       { (float**)&TP_SORBCONC_rep, "TP_SORBCONC_rep", 'f' },
02317       { (float**)&TP_SORBTION, "TP_SORBTION", 'f' },
02318       { (float**)&TP_UPFLOW, "TP_UPFLOW", 'f' },
02319       { (float**)&TP_UPFLOW_POT, "TP_UPFLOW_POT", 'f' },
02320       { (double**)&SAL_SED_WT, "SAL_SED_WT", 'd' },
02321       { (float**)&SAL_SF_WT, "SAL_SF_WT", 'f' },
02322       { (float**)&SALT_SED_TO_SF_FLOW, "SALT_SED_TO_SF_FLOW", 'f' },
02323       { (double**)&SALT_SED_WT, "SALT_SED_WT", 'd' },
02324       { (float**)&SALT_SFWAT_DOWNFL, "SALT_SFWAT_DOWNFL", 'f' },
02325       { (float**)&SALT_SFWAT_DOWNFL_POT, "SALT_SFWAT_DOWNFL_POT", 'f' },
02326       { (double**)&SALT_SURF_WT, "SALT_SURF_WT", 'd' },
02327       { (float**)&SALT_Atm_Depos, "SALT_Atm_Depos", 'f' },
02328       { (double**)&DEPOS_ORG_MAT, "DEPOS_ORG_MAT", 'd' },
02329       { (float**)&DOM_DECOMP, "DOM_DECOMP", 'f' },
02330       { (float**)&DOM_DECOMP_POT, "DOM_DECOMP_POT", 'f' },
02331       { (float**)&DOM_FR_FLOC, "DOM_FR_FLOC", 'f' },
02332       { (double**)&DOM_P_OM, "DOM_P_OM", 'd' },
02333       { (float**)&DOM_QUALITY_CF, "DOM_QUALITY_CF", 'f' },
02334       { (float**)&DOM_SED_AEROB_Z, "DOM_SED_AEROB_Z", 'f' },
02335       { (float**)&DOM_SED_ANAEROB_Z, "DOM_SED_ANAEROB_Z", 'f' },
02336       { (float**)&DOM_TEMP_CF, "DOM_TEMP_CF", 'f' },
02337       { (float**)&DOM_Z, "DOM_Z", 'f' },
02338       { (double**)&DOP, "DOP", 'd' },
02339       { (float**)&DOP_DECOMP, "DOP_DECOMP", 'f' },
02340       { (float**)&P_SUM_CELL, "P_SUM_CELL", 'f' },
02341       { (float**)&SED_ELEV, "SED_ELEV", 'f' },
02342       { (float**)&TPtoSOIL_rep, "TPtoSOIL_rep", 'f' },
02343       { (float**)&Floc_fr_phBioAvg, "Floc_fr_phBioAvg", 'f' },
02344       { (float**)&TPSfMinAvg, "TPSfMinAvg", 'f' },
02345       { (float**)&ETAvg, "ETAvg", 'f' },
02346       { (float**)&EvapAvg, "EvapAvg", 'f' },
02347       { (float**)&HydPerAnn, "HydPerAnn", 'f' },
02348       { (float**)&LAI_effAvg, "LAI_effAvg", 'f' },
02349       { (float**)&Manning_nAvg, "Manning_nAvg", 'f' },
02350       { (float**)&RainAvg, "RainAvg", 'f' },
02351       { (float**)&SfWatAvg, "SfWatAvg", 'f' },
02352       { (float**)&TotHeadAvg, "TotHeadAvg", 'f' },
02353       { (float**)&HydRelDepPosNegAvg, "HydRelDepPosNegAvg", 'f' },
02354       { (float**)&TranspAvg, "TranspAvg", 'f' },
02355       { (float**)&UnsatMoistAvg, "UnsatMoistAvg", 'f' },
02356       { (float**)&UnsatZavg, "UnsatZavg", 'f' },
02357       { (float**)&SF_WT_VEL_magAvg, "SF_WT_VEL_magAvg", 'f' },
02358       { (float**)&BCmodel_sfwatAvg, "BCmodel_sfwatAvg", 'f' },
02359       { (float**)&mac_nph_PCAvg, "mac_nph_PCAvg", 'f' },
02360       { (float**)&Mac_nphBioAvg, "Mac_nphBioAvg", 'f' },
02361       { (float**)&Mac_nphMortAvg, "Mac_nphMortAvg", 'f' },
02362       { (float**)&Mac_nppAvg, "Mac_nppAvg", 'f' },
02363       { (float**)&mac_ph_PCAvg, "mac_ph_PCAvg", 'f' },
02364       { (float**)&Mac_phBioAvg, "Mac_phBioAvg", 'f' },
02365       { (float**)&Mac_phMortAvg, "Mac_phMortAvg", 'f' },
02366       { (float**)&Mac_totBioAvg, "Mac_totBioAvg", 'f' },
02367       { (float**)&MacNutCfAvg, "MacNutCfAvg", 'f' },
02368       { (float**)&MacWatCfAvg, "MacWatCfAvg", 'f' },
02369       { (float**)&TPSedUptAvg, "TPSedUptAvg", 'f' },
02370       { (float**)&C_Peri_mortAvg, "C_Peri_mortAvg", 'f' },
02371       { (float**)&C_Peri_nppAvg, "C_Peri_nppAvg", 'f' },
02372       { (float**)&C_Peri_PCAvg, "C_Peri_PCAvg", 'f' },
02373       { (float**)&C_PeriAvg, "C_PeriAvg", 'f' },
02374       { (float**)&C_PeriNutCFAvg, "C_PeriNutCFAvg", 'f' },
02375       { (float**)&C_PeriRespAvg, "C_PeriRespAvg", 'f' },
02376       { (float**)&NC_Peri_mortAvg, "NC_Peri_mortAvg", 'f' },
02377       { (float**)&NC_Peri_nppAvg, "NC_Peri_nppAvg", 'f' },
02378       { (float**)&NC_Peri_PCAvg, "NC_Peri_PCAvg", 'f' },
02379       { (float**)&NC_PeriAvg, "NC_PeriAvg", 'f' },
02380       { (float**)&NC_PeriNutCFAvg, "NC_PeriNutCFAvg", 'f' },
02381       { (float**)&NC_PeriRespAvg, "NC_PeriRespAvg", 'f' },
02382       { (float**)&PeriAvg, "PeriAvg", 'f' },
02383       { (float**)&PeriLiteCFAvg, "PeriLiteCFAvg", 'f' },
02384       { (float**)&TPSfUptAvg, "TPSfUptAvg", 'f' },
02385       { (float**)&TP_settlAvg, "TP_settlAvg", 'f' },
02386       { (float**)&TPSedWatAvg, "TPSedWatAvg", 'f' },
02387       { (float**)&TPSfWatAvg, "TPSfWatAvg", 'f' },
02388       { (float**)&SaltSedAvg, "SaltSedAvg", 'f' },
02389       { (float**)&SaltSfAvg, "SaltSfAvg", 'f' },
02390       { (float**)&SedElevAvg, "SedElevAvg", 'f' },
02391       { (float**)&TPSedMinAvg, "TPSedMinAvg", 'f' },
02392       { (float**)&TPSorbAvg, "TPSorbAvg", 'f' },
02393       { (float**)&TPtoSOILAvg, "TPtoSOILAvg", 'f' },
02394       { (float**)&TPtoVOLAvg, "TPtoVOLAvg", 'f' },
02395 
02396 
02397 
02398 
02399 
02400 
02401 
02402 
02403       { NULL, NULL, '\0' },
02404   };
02405   
02406     outVar_struct *ptable;
02407     int  i;
02408 
02409     for (i = 0, ptable = tgen; ptable->pfvar != NULL; ptable++, i++)
02410     {
02411   vp = view + i;
02412 
02413 /* TODO: develop flexible output of calendar-based and julian-based outsteps (jan 11, 2005) */
02414 if (vp->step > 0)
02415                 
02416             if (strcmp(ptable->pname,"HydPerAnn")!=0) { /* i.e., not the HydPerAnn variable */
02417                 
02418                 if  (step % vp->step == 0 && (vp->step != CalMonOut) ) {   /* standard julian-day outstep interval variables (note: the != CalMonOut needed for step=0) */ 
02419                     oIndex = iw[i]++;
02420                     write_output(oIndex, vp, *(ptable->pfvar), ptable->pname, ptable->ctype, step);
02421                 }
02422                 else if ( (avgPrint) && (vp->step == CalMonOut) ) { /* variables output at the special 1-calendar-month outstep interval */  
02423                     oIndex = iw[i]++;
02424                     write_output(oIndex, vp, *(ptable->pfvar), ptable->pname, ptable->ctype, step);
02425                 }
02426             }
02427         
02428             else
02429                 if (FMOD(DAYJUL, 273.0) ==0) { /* hydroperiod is printed at a special-case time (approximately Oct 1 every year) */
02430                     oIndex = iw[i]++;
02431                     write_output(oIndex, vp, *(ptable->pfvar), ptable->pname, ptable->ctype, step);
02432                 }
02433         
02434      
02435     }
02436 
02437         /* after printing, zero the arrays holding averages or hydroperiods (v2.2.1note using avgPrint var)*/
02438     if (avgPrint) {
02439         Cell_reset_avg();
02440     }
02441 
02442     if (FMOD(DAYJUL, 273.0) ==0) {
02443         Cell_reset_hydper();
02444     }
02445 
02446 
02447 } /* end of gen_output routine */
02448 
02449 
02463 void ReadHabParms ( char* s_parm_name, int s_parm_relval )
02464 {
02465 
02466  /* Periphyton/Algae */
02467   HP_ALG_MAX = get_hab_parm(s_parm_name, s_parm_relval, "HP_ALG_MAX"); 
02468 
02469 /* Soil */
02470   HP_DOM_MAXDEPTH = get_hab_parm(s_parm_name, s_parm_relval,"HP_DOM_MAXDEPTH");  
02471   HP_DOM_AEROBTHIN = get_hab_parm(s_parm_name, s_parm_relval,"HP_DOM_AEROBTHIN"); 
02472 
02473 /* Phosphorus */
02474   HP_TP_CONC_GRAD = get_hab_parm(s_parm_name, s_parm_relval,"HP_TP_CONC_GRAD"); 
02475 
02476 /* Salt/tracer */
02477   HP_SALT_ICSEDWAT = get_hab_parm(s_parm_name, s_parm_relval,"HP_SALT_ICSEDWAT"); 
02478   HP_SALT_ICSFWAT = get_hab_parm(s_parm_name, s_parm_relval,"HP_SALT_ICSFWAT"); 
02479         
02480 /* Macrophytes */
02481   HP_PHBIO_MAX = get_hab_parm(s_parm_name, s_parm_relval,"HP_PHBIO_MAX"); 
02482   HP_NPHBIO_MAX = get_hab_parm(s_parm_name, s_parm_relval,"HP_NPHBIO_MAX"); 
02483   HP_MAC_MAXHT = get_hab_parm(s_parm_name, s_parm_relval,"HP_MAC_MAXHT"); 
02484   HP_NPHBIO_ROOTDEPTH = get_hab_parm(s_parm_name, s_parm_relval,"HP_NPHBIO_ROOTDEPTH"); 
02485   HP_MAC_MAXROUGH = get_hab_parm(s_parm_name, s_parm_relval,"HP_MAC_MAXROUGH"); 
02486   HP_MAC_MINROUGH = get_hab_parm(s_parm_name, s_parm_relval,"HP_MAC_MINROUGH"); 
02487   HP_MAC_MAXLAI = get_hab_parm(s_parm_name, s_parm_relval,"HP_MAC_MAXLAI"); 
02488   HP_MAC_MAXCANOPCOND = get_hab_parm(s_parm_name, s_parm_relval,"HP_MAC_MAXCANOPCOND"); /* unused in ELMv2.2, 2.3 */ 
02489   HP_MAC_CANOPDECOUP = get_hab_parm(s_parm_name, s_parm_relval,"HP_MAC_CANOPDECOUP"); /* unused in ELMv2.2, 2.3 */ 
02490   HP_MAC_TEMPOPT = get_hab_parm(s_parm_name, s_parm_relval,"HP_MAC_TEMPOPT"); 
02491   HP_MAC_LIGHTSAT = get_hab_parm(s_parm_name, s_parm_relval,"HP_MAC_LIGHTSAT"); 
02492   HP_MAC_KSP = get_hab_parm(s_parm_name, s_parm_relval,"HP_MAC_KSP"); 
02493   HP_PHBIO_RCNPP = get_hab_parm(s_parm_name, s_parm_relval,"HP_PHBIO_RCNPP"); 
02494   HP_PHBIO_RCMORT = get_hab_parm(s_parm_name, s_parm_relval,"HP_PHBIO_RCMORT"); 
02495   HP_MAC_WAT_TOLER = get_hab_parm(s_parm_name, s_parm_relval,"HP_MAC_WAT_TOLER"); 
02496   HP_MAC_SALIN_THRESH = get_hab_parm(s_parm_name, s_parm_relval,"HP_MAC_SALIN_THRESH"); /* unused in ELMv2.2, 2.3 */ 
02497   HP_PHBIO_IC_CTOOM = get_hab_parm(s_parm_name, s_parm_relval,"HP_PHBIO_IC_CTOOM"); 
02498   HP_NPHBIO_IC_CTOOM = get_hab_parm(s_parm_name, s_parm_relval,"HP_NPHBIO_IC_CTOOM"); 
02499   HP_PHBIO_IC_PC = get_hab_parm(s_parm_name, s_parm_relval,"HP_PHBIO_IC_PC"); 
02500   HP_NPHBIO_IC_PC = get_hab_parm(s_parm_name, s_parm_relval,"HP_NPHBIO_IC_PC"); 
02501   HP_MAC_TRANSLOC_RC = get_hab_parm(s_parm_name, s_parm_relval,"HP_MAC_TRANSLOC_RC"); 
02502 
02503 /* Hydrology */
02504   HP_HYD_RCINFILT = get_hab_parm(s_parm_name, s_parm_relval,"HP_HYD_RCINFILT"); 
02505   HP_HYD_SPEC_YIELD = get_hab_parm(s_parm_name, s_parm_relval,"HP_HYD_SPEC_YIELD");  
02506   HP_HYD_POROSITY = get_hab_parm(s_parm_name, s_parm_relval,"HP_HYD_POROSITY"); 
02507 
02508 /* Floc */
02509   HP_FLOC_IC = get_hab_parm(s_parm_name, s_parm_relval,"HP_FLOC_IC"); 
02510   HP_FLOC_IC_CTOOM = get_hab_parm(s_parm_name, s_parm_relval,"HP_FLOC_IC_CTOOM"); 
02511   HP_FLOC_IC_PC = get_hab_parm(s_parm_name, s_parm_relval,"HP_FLOC_IC_PC"); 
02512 
02513 /* Habitat succession */
02514   HP_SfDepthLo = get_hab_parm(s_parm_name, s_parm_relval,"HP_SfDepthLo"); 
02515   HP_SfDepthHi = get_hab_parm(s_parm_name, s_parm_relval,"HP_SfDepthHi"); 
02516   HP_SfDepthInt = get_hab_parm(s_parm_name, s_parm_relval,"HP_SfDepthInt"); 
02517   HP_PhosLo = get_hab_parm(s_parm_name, s_parm_relval,"HP_PhosLo"); 
02518   HP_PhosHi = get_hab_parm(s_parm_name, s_parm_relval,"HP_PhosHi"); 
02519   HP_PhosInt = get_hab_parm(s_parm_name, s_parm_relval,"HP_PhosInt"); 
02520   HP_FireInt = get_hab_parm(s_parm_name, s_parm_relval,"HP_FireInt"); 
02521   HP_SalinLo = get_hab_parm(s_parm_name, s_parm_relval,"HP_SalinLo"); 
02522   HP_SalinHi = get_hab_parm(s_parm_name, s_parm_relval,"HP_SalinHi"); 
02523   HP_SalinInt = get_hab_parm(s_parm_name, s_parm_relval,"HP_SalinInt"); 
02524   
02525 }
02526 
02527 
02532 void ReadGlobalParms( char* s_parm_name, int s_parm_relval )
02533  {
02534      
02535 /* Geography, hydrology */
02536     GP_SOLOMEGA = get_global_parm(s_parm_name, s_parm_relval,"GP_SOLOMEGA"); 
02537     GP_ALTIT = get_global_parm(s_parm_name, s_parm_relval,"GP_ALTIT"); 
02538     GP_LATDEG = get_global_parm(s_parm_name, s_parm_relval,"GP_LATDEG"); 
02539     GP_mannDepthPow = get_global_parm(s_parm_name, s_parm_relval,"GP_mannDepthPow"); 
02540     GP_mannHeadPow = get_global_parm(s_parm_name, s_parm_relval,"GP_mannHeadPow"); 
02541     GP_calibGWat = get_global_parm(s_parm_name, s_parm_relval,"GP_calibGWat"); 
02542     GP_IDW_pow = get_global_parm(s_parm_name, s_parm_relval,"GP_IDW_pow"); 
02543     GP_calibET = get_global_parm(s_parm_name, s_parm_relval,"GP_calibET"); 
02544     GP_DATUM_DISTANCE = get_global_parm(s_parm_name, s_parm_relval,"GP_DATUM_DISTANCE"); 
02545     GP_HYD_IC_SFWAT_ADD = get_global_parm(s_parm_name, s_parm_relval,"GP_HYD_IC_SFWAT_ADD"); 
02546     GP_HYD_IC_UNSAT_ADD = get_global_parm(s_parm_name, s_parm_relval,"GP_HYD_IC_UNSAT_ADD"); 
02547     GP_HYD_RCRECHG = get_global_parm(s_parm_name, s_parm_relval,"GP_HYD_RCRECHG"); 
02548     GP_HYD_ICUNSATMOIST = get_global_parm(s_parm_name, s_parm_relval,"GP_HYD_ICUNSATMOIST"); 
02549     GP_DetentZ = get_global_parm(s_parm_name, s_parm_relval,"GP_DetentZ"); 
02550     GP_WQualMonitZ = get_global_parm(s_parm_name, s_parm_relval,"GP_WQualMonitZ"); 
02551     GP_MinCheck = get_global_parm(s_parm_name, s_parm_relval,"GP_MinCheck"); 
02552     GP_SLRise = get_global_parm(s_parm_name, s_parm_relval,"GP_SLRise"); 
02553     GP_dispLenRef = get_global_parm(s_parm_name, s_parm_relval,"GP_dispLenRef"); 
02554     GP_dispParm = get_global_parm(s_parm_name, s_parm_relval,"GP_dispParm"); 
02555  
02556  /* Periphyton/Algae */
02557     GP_ALG_IC_MULT = get_global_parm(s_parm_name, s_parm_relval,"GP_ALG_IC_MULT"); 
02558     GP_alg_uptake_coef = get_global_parm(s_parm_name, s_parm_relval,"GP_alg_uptake_coef"); 
02559     GP_ALG_SHADE_FACTOR = get_global_parm(s_parm_name, s_parm_relval,"GP_ALG_SHADE_FACTOR"); 
02560     GP_algMortDepth = get_global_parm(s_parm_name, s_parm_relval,"GP_algMortDepth"); 
02561     GP_ALG_RC_MORT_DRY = get_global_parm(s_parm_name, s_parm_relval,"GP_ALG_RC_MORT_DRY"); 
02562     GP_ALG_RC_MORT = get_global_parm(s_parm_name, s_parm_relval,"GP_ALG_RC_MORT"); 
02563     GP_ALG_RC_PROD = get_global_parm(s_parm_name, s_parm_relval,"GP_ALG_RC_PROD"); 
02564     GP_ALG_RC_RESP = get_global_parm(s_parm_name, s_parm_relval,"GP_ALG_RC_RESP"); 
02565     GP_alg_R_accel = get_global_parm(s_parm_name, s_parm_relval,"GP_alg_R_accel"); 
02566     GP_AlgComp = get_global_parm(s_parm_name, s_parm_relval,"GP_AlgComp"); 
02567     GP_ALG_REF_MULT = get_global_parm(s_parm_name, s_parm_relval,"GP_ALG_REF_MULT"); 
02568     GP_NC_ALG_KS_P = get_global_parm(s_parm_name, s_parm_relval,"GP_NC_ALG_KS_P"); 
02569     GP_alg_alkP_min = get_global_parm(s_parm_name, s_parm_relval,"GP_alg_alkP_min"); 
02570     GP_C_ALG_KS_P = get_global_parm(s_parm_name, s_parm_relval,"GP_C_ALG_KS_P"); 
02571     GP_ALG_TEMP_OPT = get_global_parm(s_parm_name, s_parm_relval,"GP_ALG_TEMP_OPT"); 
02572     GP_C_ALG_threshTP = get_global_parm(s_parm_name, s_parm_relval,"GP_C_ALG_threshTP"); 
02573     GP_ALG_C_TO_OM = get_global_parm(s_parm_name, s_parm_relval,"GP_ALG_C_TO_OM"); 
02574     GP_alg_light_ext_coef = get_global_parm(s_parm_name, s_parm_relval,"GP_alg_light_ext_coef"); 
02575     GP_ALG_LIGHT_SAT = get_global_parm(s_parm_name, s_parm_relval,"GP_ALG_LIGHT_SAT"); 
02576     GP_ALG_PC = get_global_parm(s_parm_name, s_parm_relval,"GP_ALG_PC"); 
02577 
02578 /* Soil */
02579     GP_DOM_RCDECOMP = get_global_parm(s_parm_name, s_parm_relval,"GP_DOM_RCDECOMP"); 
02580     GP_DOM_DECOMPRED = get_global_parm(s_parm_name, s_parm_relval,"GP_DOM_DECOMPRED"); 
02581     GP_calibDecomp = get_global_parm(s_parm_name, s_parm_relval,"GP_calibDecomp"); 
02582     GP_DOM_decomp_coef = get_global_parm(s_parm_name, s_parm_relval,"GP_DOM_decomp_coef"); 
02583     GP_DOM_DECOMP_POPT = get_global_parm(s_parm_name, s_parm_relval,"GP_DOM_DECOMP_POPT"); 
02584     GP_DOM_DECOMP_TOPT = get_global_parm(s_parm_name, s_parm_relval,"GP_DOM_DECOMP_TOPT"); 
02585     GP_sorbToTP = get_global_parm(s_parm_name, s_parm_relval,"GP_sorbToTP"); 
02586     GP_IC_ELEV_MULT = get_global_parm(s_parm_name, s_parm_relval,"GP_IC_ELEV_MULT"); 
02587     GP_IC_BATHY_MULT = get_global_parm(s_parm_name, s_parm_relval,"GP_IC_BATHY_MULT"); 
02588     GP_IC_DOM_BD_MULT = get_global_parm(s_parm_name, s_parm_relval,"GP_IC_DOM_BD_MULT"); 
02589     GP_IC_BulkD_MULT = get_global_parm(s_parm_name, s_parm_relval,"GP_IC_BulkD_MULT"); 
02590     GP_IC_TPtoSOIL_MULT = get_global_parm(s_parm_name, s_parm_relval,"GP_IC_TPtoSOIL_MULT"); 
02591  
02592 /* Macrophytes */
02593     GP_MAC_IC_MULT = get_global_parm(s_parm_name, s_parm_relval,"GP_MAC_IC_MULT"); 
02594     GP_MAC_REFUG_MULT = get_global_parm(s_parm_name, s_parm_relval,"GP_MAC_REFUG_MULT"); 
02595     GP_mac_uptake_coef = get_global_parm(s_parm_name, s_parm_relval,"GP_mac_uptake_coef"); 
02596     GP_mann_height_coef = get_global_parm(s_parm_name, s_parm_relval,"GP_mann_height_coef"); 
02597 
02598 /* Floc */
02599     GP_Floc_BD = get_global_parm(s_parm_name, s_parm_relval,"GP_Floc_BD"); 
02600     GP_FlocMax = get_global_parm(s_parm_name, s_parm_relval,"GP_FlocMax"); 
02601     GP_TP_P_OM = get_global_parm(s_parm_name, s_parm_relval,"GP_TP_P_OM"); 
02602     GP_Floc_rcSoil = get_global_parm(s_parm_name, s_parm_relval,"GP_Floc_rcSoil"); 
02603                 
02604 /* Phosphorus */
02605     GP_TP_DIFFCOEF = get_global_parm(s_parm_name, s_parm_relval,"GP_TP_DIFFCOEF"); 
02606     GP_TP_K_INTER = get_global_parm(s_parm_name, s_parm_relval,"GP_TP_K_INTER"); 
02607     GP_TP_K_SLOPE = get_global_parm(s_parm_name, s_parm_relval,"GP_TP_K_SLOPE"); 
02608     GP_WQMthresh = get_global_parm(s_parm_name, s_parm_relval,"GP_WQMthresh"); 
02609     GP_PO4toTP = get_global_parm(s_parm_name, s_parm_relval,"GP_PO4toTP"); 
02610     GP_TP_IN_RAIN = get_global_parm(s_parm_name, s_parm_relval,"GP_TP_IN_RAIN"); 
02611     GP_CL_IN_RAIN = get_global_parm(s_parm_name, s_parm_relval,"GP_CL_IN_RAIN"); 
02612     GP_PO4toTPint = get_global_parm(s_parm_name, s_parm_relval,"GP_PO4toTPint"); 
02613     GP_TP_ICSFWAT = get_global_parm(s_parm_name, s_parm_relval,"GP_TP_ICSFWAT"); 
02614     GP_TP_ICSEDWAT = get_global_parm(s_parm_name, s_parm_relval,"GP_TP_ICSEDWAT"); 
02615     GP_TPpart_thresh = get_global_parm(s_parm_name, s_parm_relval,"GP_TPpart_thresh"); 
02616     GP_TP_DIFFDEPTH = get_global_parm(s_parm_name, s_parm_relval,"GP_TP_DIFFDEPTH"); 
02617     GP_settlVel = get_global_parm(s_parm_name, s_parm_relval,"GP_settlVel"); 
02618     
02619 }
02620 
02636 void ReadModExperimParms( char* s_parm_name, int s_parm_relval )
02637  {
02638     if (isModExperim) {
02639                  sprintf(msgStr,"####### Reading special model experiment parameters.  \nYou should NOT be using gridIO spatial time series data for rain, pET, and SFWMM-output depth #######..."); 
02640             WriteMsg(msgStr,1); 
02641             usrErr0(msgStr);
02642             
02643         GP_BC_SfWat_add = get_modexperim_parm(s_parm_name, s_parm_relval,"GP_BC_SfWat_add"); 
02644         GP_BC_SfWat_addHi = get_modexperim_parm(s_parm_name, s_parm_relval,"GP_BC_SfWat_addHi"); 
02645         GP_BC_SatWat_add = get_modexperim_parm(s_parm_name, s_parm_relval,"GP_BC_SatWat_add"); 
02646         GP_BC_SfWat_targ = get_modexperim_parm(s_parm_name, s_parm_relval,"GP_BC_SfWat_targ"); 
02647         GP_BC_InputRow = get_modexperim_parm(s_parm_name, s_parm_relval,"GP_BC_InputRow"); 
02648         GP_BC_Pconc = get_modexperim_parm(s_parm_name, s_parm_relval,"GP_BC_Pconc"); /* ug/L */
02649         GP_BC_Sconc = get_modexperim_parm(s_parm_name, s_parm_relval,"GP_BC_Sconc"); /* g/L */
02650         
02651         GP_BC_Pconc /= conv_kgTOmg; /* convert from ug/L to g/L (same as div by the kg->mg conversion) */
02652 
02653             sprintf(msgStr,"done."); 
02654             WriteMsg(msgStr,1); 
02655             usrErr(msgStr);
02656     }
02657     else {
02658         GP_BC_SfWat_add = 0.0; /* value of 0.0 has no effect on model results (adds nothing to boundary depth/stages) */
02659         GP_BC_SfWat_addHi = 0.0; /* value of 0.0 has no effect on model results (adds nothing to boundary depth/stages) */
02660         GP_BC_SatWat_add = 0.0; /* value of 0.0 has no effect on model results (adds nothing to boundary depth/stages) */
02661         GP_BC_SfWat_targ = 0.0; /* value of 0.0 has no effect on model results (only used in Oct06 specialized model experiment - code doesn't use this parm otherwise) */
02662         GP_BC_InputRow = 0; /* value of 0 has no effect on model results (only used in Oct06 specialized model experiment - code doesn't use this parm otherwise) */
02663         GP_BC_Pconc = 0.0;
02664         GP_BC_Sconc = 0.0;
02665     }
02666  } 
02667 
02668 /* v2.6 PTSL */
02680 void PtInterp_read() 
02681 {
02682                 /* rainfall and pET point data for models that do not use gridIO inputs, but use interpolated point time series */
02683             /* final arg in PTSL_ReadLists is the column number of of the data (not incl. the 3 date columns) */
02684         usrErr0 ("\n*** WARNING: You are not using gridIO spatial time series data for rain, pET, and SFWMM-output depth.  \nReading rainfall and pET point time series data... ");
02685                 pTSList2 = PTSL_Init(50, 2);
02686                 PTSL_ReadLists(pTSList2,"rain",TIndex2++,&Timestep2,&NPtTS2, 1); /* rainfall in data-col 1 (file's col 4) */
02687         
02688         pTSList3 = PTSL_Init(50, 2);
02689         PTSL_ReadLists(pTSList3,"pET",TIndex3++,&Timestep3,&NPtTS3, 1); /* pET data in data-col 1 (file's col 4) */
02690 
02691         usrErr("done.\n");
02692 
02693         if (99 == 66) { /* never-get-here: temporary v2.6 PTSL - Below (old code frags extracted from v2.1) are left here as template for other data (or re-implementing the ELM v2.1 pET calculations if data available) */
02694         pTSList4 = PTSL_Init(50, 2);
02695         PTSL_ReadLists(pTSList4,"pET",TIndex4++,&Timestep4,&NPtTS4, 2);  /* dew point temperature data can be in data-col 2 */
02696         pTSList5 = PTSL_Init(50, 2);
02697         PTSL_ReadLists(pTSList5,"pET",TIndex5++,&Timestep5,&NPtTS5, 3);  /* wind speed data can be in data-col 3 */
02698         pTSList6 = PTSL_Init(50, 2);
02699         PTSL_ReadLists(pTSList6,"pET",TIndex6++,&Timestep6,&NPtTS6, 4);  /* cloud cover data can be in data-col 4 */
02700         }
02701 }
02702 
02703 
02707 void get_map_dims() 
02708 {
02709   read_map_dims("Elevation");
02710 }
02711 
02716 /* v2.8 a large number of variables are incorrect/inconsistent in initializing for double or float - corrected below, w/o comments */
02717 void alloc_memory() 
02718 {
02719   usrErr0("Allocating Memory...");  /* console message */
02720   
02721   ON_MAP = (unsigned char *) nalloc(sizeof(unsigned char)*(s0+2)*(s1+2),"ON_MAP");
02722   init_pvar(ON_MAP,NULL,'c',0.0);
02723 
02724   BCondFlow = (int *) nalloc(sizeof(int)*(s0+2)*(s1+2),"BCondFlow");
02725   init_pvar(BCondFlow,NULL,'d',0.0);
02726   HAB = (unsigned char *) nalloc(sizeof(unsigned char)*(s0+2)*(s1+2),"HAB");
02727   init_pvar(HAB,NULL,'c',0.0);
02728   basn = (int *) nalloc(sizeof(int)*(s0+2)*(s1+2),"basn"); /* Basin/Indicator-Region map */
02729   init_pvar(basn,NULL,'d',0.0);
02730 
02731   ALG_INCID_LIGHT = (float *) nalloc(sizeof(float)*(s0+2)*(s1+2),"ALG_INCID_LIGHT");
02732   init_pvar(ALG_INCID_LIGHT,NULL,'f',0.0);
02733   ALG_LIGHT_CF = (float *) nalloc(sizeof(float)*(s0+2)*(s1+2),"ALG_LIGHT_CF");
02734   init_pvar(ALG_LIGHT_CF,NULL,'f',0.0);
02735   ALG_LIGHT_EXTINCT = (float *) nalloc(sizeof(float)*(s0+2)*(s1+2),"ALG_LIGHT_EXTINCT");
02736   init_pvar(ALG_LIGHT_EXTINCT,NULL,'f',0.0);
02737   ALG_WAT_CF = (float *) nalloc(sizeof(float)*(s0+2)*(s1+2),"ALG_WAT_CF");
02738   init_pvar(ALG_WAT_CF,NULL,'f',0.0);
02739   ALG_TEMP_CF = (float *) nalloc(sizeof(float)*(s0+2)*(s1+2),"ALG_TEMP_CF");
02740   init_pvar(ALG_TEMP_CF,NULL,'f',0.0);
02741   ALG_REFUGE = (float *) nalloc(sizeof(float)*(s0+2)*(s1+2),"ALG_REFUGE");
02742   init_pvar(ALG_REFUGE,NULL,'f',0.0);
02743   ALG_SAT = (float *) nalloc(sizeof(float)*(s0+2)*(s1+2),"ALG_SAT");
02744   init_pvar(ALG_SAT,NULL,'f',0.0);
02745   ALG_TOT = (float *) nalloc(sizeof(float)*(s0+2)*(s1+2),"ALG_TOT");
02746   init_pvar(ALG_TOT,NULL,'f',0.0);
02747 
02748   NC_ALG_AVAIL_MORT = (float *) nalloc(sizeof(float)*(s0+2)*(s1+2),"NC_ALG_AVAIL_MORT");
02749   init_pvar(NC_ALG_AVAIL_MORT,NULL,'f',0.0);
02750   NC_ALG_GPP = (float *) nalloc(sizeof(float)*(s0+2)*(s1+2),"NC_ALG_GPP");
02751   init_pvar(NC_ALG_GPP,NULL,'f',0.0);
02752   NC_ALG_MORT = (float *) nalloc(sizeof(float)*(s0+2)*(s1+2),"NC_ALG_MORT");
02753   init_pvar(NC_ALG_MORT,NULL,'f',0.0);
02754   NC_ALG_MORT_POT = (float *) nalloc(sizeof(float)*(s0+2)*(s1+2),"NC_ALG_MORT_POT");
02755   init_pvar(NC_ALG_MORT_POT,NULL,'f',0.0);
02756   NC_ALG_NPP = (float *) nalloc(sizeof(float)*(s0+2)*(s1+2),"NC_ALG_NPP");
02757   init_pvar(NC_ALG_NPP,NULL,'f',0.0);
02758   NC_ALG_NUT_CF = (float *) nalloc(sizeof(float)*(s0+2)*(s1+2),"NC_ALG_NUT_CF");
02759   init_pvar(NC_ALG_NUT_CF,NULL,'f',0.0);
02760   NC_ALG_PROD_CF = (float *) nalloc(sizeof(float)*(s0+2)*(s1+2),"NC_ALG_PROD_CF");
02761   init_pvar(NC_ALG_PROD_CF,NULL,'f',0.0);
02762   NC_ALG_RESP = (float *) nalloc(sizeof(float)*(s0+2)*(s1+2),"NC_ALG_RESP");
02763   init_pvar(NC_ALG_RESP,NULL,'f',0.0);
02764   NC_ALG_RESP_POT = (float *) nalloc(sizeof(float)*(s0+2)*(s1+2),"NC_ALG_RESP_POT");
02765   init_pvar(NC_ALG_RESP_POT,NULL,'f',0.0);
02766   NC_ALG = (float *) nalloc(sizeof(float)*(s0+2)*(s1+2),"NC_ALG");
02767   init_pvar(NC_ALG,NULL,'f',0.0);
02768   C_ALG_AVAIL_MORT = (float *) nalloc(sizeof(float)*(s0+2)*(s1+2),"C_ALG_AVAIL_MORT");
02769   init_pvar(C_ALG_AVAIL_MORT,NULL,'f',0.0);
02770   C_ALG_GPP = (float *) nalloc(sizeof(float)*(s0+2)*(s1+2),"C_ALG_GPP");
02771   init_pvar(C_ALG_GPP,NULL,'f',0.0);
02772   C_ALG_MORT = (float *) nalloc(sizeof(float)*(s0+2)*(s1+2),"C_ALG_MORT");
02773   init_pvar(C_ALG_MORT,NULL,'f',0.0);
02774   C_ALG_MORT_POT = (float *) nalloc(sizeof(float)*(s0+2)*(s1+2),"C_ALG_MORT_POT");
02775   init_pvar(C_ALG_MORT_POT,NULL,'f',0.0);
02776   C_ALG_NPP = (float *) nalloc(sizeof(float)*(s0+2)*(s1+2),"C_ALG_NPP");
02777   init_pvar(C_ALG_NPP,NULL,'f',0.0);
02778   C_ALG_NUT_CF = (float *) nalloc(sizeof(float)*(s0+2)*(s1+2),"C_ALG_NUT_CF");
02779   init_pvar(C_ALG_NUT_CF,NULL,'f',0.0);
02780   C_ALG_PROD_CF = (float *) nalloc(sizeof(float)*(s0+2)*(s1+2),"C_ALG_PROD_CF");
02781   init_pvar(C_ALG_PROD_CF,NULL,'f',0.0);
02782   C_ALG_RESP = (float *) nalloc(sizeof(float)*(s0+2)*(s1+2),"C_ALG_RESP");
02783   init_pvar(C_ALG_RESP,NULL,'f',0.0);
02784   C_ALG_RESP_POT = (float *) nalloc(sizeof(float)*(s0+2)*(s1+2),"C_ALG_RESP_POT");
02785   init_pvar(C_ALG_RESP_POT,NULL,'f',0.0);
02786   C_ALG = (float *) nalloc(sizeof(float)*(s0+2)*(s1+2),"C_ALG");
02787   init_pvar(C_ALG,NULL,'f',0.0);
02788   NC_ALG_P = (float *) nalloc(sizeof(float)*(s0+2)*(s1+2),"NC_ALG_P");
02789   init_pvar(NC_ALG_P,NULL,'f',0.0);
02790   C_ALG_P = (float *) nalloc(sizeof(float)*(s0+2)*(s1+2),"C_ALG_P");
02791   init_pvar(C_ALG_P,NULL,'f',0.0);
02792   NC_ALG_GPP_P = (float *) nalloc(sizeof(float)*(s0+2)*(s1+2),"NC_ALG_GPP_P");
02793   init_pvar(NC_ALG_GPP_P,NULL,'f',0.0);
02794   C_ALG_GPP_P = (float *) nalloc(sizeof(float)*(s0+2)*(s1+2),"C_ALG_GPP_P");
02795   init_pvar(C_ALG_GPP_P,NULL,'f',0.0);
02796   NC_ALG_MORT_P = (float *) nalloc(sizeof(float)*(s0+2)*(s1+2),"NC_ALG_MORT_P");
02797   init_pvar(NC_ALG_MORT_P,NULL,'f',0.0);
02798   C_ALG_MORT_P = (float *) nalloc(sizeof(float)*(s0+2)*(s1+2),"C_ALG_MORT_P");
02799   init_pvar(C_ALG_MORT_P,NULL,'f',0.0);
02800   NC_ALG_PCrep = (float *) nalloc(sizeof(float)*(s0+2)*(s1+2),"NC_ALG_PCrep");
02801   init_pvar(NC_ALG_PCrep,NULL,'f',0.0);
02802   C_ALG_PCrep = (float *) nalloc(sizeof(float)*(s0+2)*(s1+2),"C_ALG_PCrep");
02803   init_pvar(C_ALG_PCrep,NULL,'f',0.0);
02804   NC_ALG_PC = (double *) nalloc(sizeof(double)*(s0+2)*(s1+2),"NC_ALG_PC");
02805   init_pvar(NC_ALG_PC,NULL,'l',0.0);
02806   C_ALG_PC = (double *) nalloc(sizeof(double)*(s0+2)*(s1+2),"C_ALG_PC");
02807   init_pvar(C_ALG_PC,NULL,'l',0.0);
02808 
02809   DEPOS_ORG_MAT = (double *) nalloc(sizeof(double)*(s0+2)*(s1+2),"DEPOS_ORG_MAT");
02810   init_pvar(DEPOS_ORG_MAT,NULL,'l',0.0);
02811         
02812   DOM_Z = (float *) nalloc(sizeof(float)*(s0+2)*(s1+2),"DOM_Z");
02813   init_pvar(DOM_Z,NULL,'f',0.0);
02814   DOM_DECOMP = (float *) nalloc(sizeof(float)*(s0+2)*(s1+2),"DOM_DECOMP");
02815   init_pvar(DOM_DECOMP,NULL,'f',0.0);
02816   DOM_DECOMP_POT = (float *) nalloc(sizeof(float)*(s0+2)*(s1+2),"DOM_DECOMP_POT");
02817   init_pvar(DOM_DECOMP_POT,NULL,'f',0.0);
02818   DOM_fr_nphBio = (float *) nalloc(sizeof(float)*(s0+2)*(s1+2),"DOM_fr_nphBio");
02819   init_pvar(DOM_fr_nphBio,NULL,'f',0.0);
02820   
02821   Floc_fr_phBio = (float *) nalloc(sizeof(float)*(s0+2)*(s1+2),"Floc_fr_phBio");
02822   init_pvar(Floc_fr_phBio,NULL,'f',0.0);
02823   DOM_FR_FLOC = (float *) nalloc(sizeof(float)*(s0+2)*(s1+2),"DOM_FR_FLOC");
02824   init_pvar(DOM_FR_FLOC,NULL,'f',0.0);
02825   soil_MOIST_CF = (float *) nalloc(sizeof(float)*(s0+2)*(s1+2),"soil_MOIST_CF");
02826   init_pvar(soil_MOIST_CF,NULL,'f',0.0);
02827   DOM_QUALITY_CF = (float *) nalloc(sizeof(float)*(s0+2)*(s1+2),"DOM_QUALITY_CF");
02828   init_pvar(DOM_QUALITY_CF,NULL,'f',0.0);
02829   DOM_SED_AEROB_Z = (float *) nalloc(sizeof(float)*(s0+2)*(s1+2),"DOM_SED_AEROB_Z");
02830   init_pvar(DOM_SED_AEROB_Z,NULL,'f',0.0);
02831   DOM_SED_ANAEROB_Z = (float *) nalloc(sizeof(float)*(s0+2)*(s1+2),"DOM_SED_ANAEROB_Z");
02832   init_pvar(DOM_SED_ANAEROB_Z,NULL,'f',0.0);
02833   DOM_TEMP_CF = (float *) nalloc(sizeof(float)*(s0+2)*(s1+2),"DOM_TEMP_CF");
02834   init_pvar(DOM_TEMP_CF,NULL,'f',0.0);
02835   ELEVATION = (float *) nalloc(sizeof(float)*(s0+2)*(s1+2),"ELEVATION");
02836   init_pvar(ELEVATION,NULL,'f',0.0);
02837   Bathymetry = (float *) nalloc(sizeof(float)*(s0+2)*(s1+2),"Bathymetry");
02838   init_pvar(Bathymetry,NULL,'f',0.0);
02839   SED_ELEV = (float *) nalloc(sizeof(float)*(s0+2)*(s1+2),"SED_ELEV");
02840   init_pvar(SED_ELEV,NULL,'f',0.0);
02841   SED_INACT_Z = (float *) nalloc(sizeof(float)*(s0+2)*(s1+2),"SED_INACT_Z");
02842   init_pvar(SED_INACT_Z,NULL,'f',0.0);
02843   DOP_FLOC = (float *) nalloc(sizeof(float)*(s0+2)*(s1+2),"DOP_FLOC");
02844   init_pvar(DOP_FLOC,NULL,'f',0.0);
02845   DOP_nphBio = (float *) nalloc(sizeof(float)*(s0+2)*(s1+2),"DOP_nphBio");
02846   init_pvar(DOP_nphBio,NULL,'f',0.0);
02847 
02848   DOM_P_OM = (double *) nalloc(sizeof(double)*(s0+2)*(s1+2),"DOM_P_OM");
02849   init_pvar(DOM_P_OM,NULL,'l',0.0);
02850 
02851   TPtoSOIL = (float *) nalloc(sizeof(float)*(s0+2)*(s1+2),"TPtoSOIL");
02852   init_pvar(TPtoSOIL,NULL,'f',0.0);
02853   TPtoSOIL_rep = (float *) nalloc(sizeof(float)*(s0+2)*(s1+2),"TPtoSOIL_rep");
02854   init_pvar(TPtoSOIL_rep,NULL,'f',0.0);
02855   TPtoVOL = (float *) nalloc(sizeof(float)*(s0+2)*(s1+2),"TPtoVOL");
02856   init_pvar(TPtoVOL,NULL,'f',0.0);
02857   TPtoVOL_rep = (float *) nalloc(sizeof(float)*(s0+2)*(s1+2),"TPtoVOL_rep");
02858   init_pvar(TPtoVOL_rep,NULL,'f',0.0);
02859   BulkD = (float *) nalloc(sizeof(float)*(s0+2)*(s1+2),"BulkD");
02860   init_pvar(BulkD,NULL,'f',0.0);
02861   DOM_BD = (float *) nalloc(sizeof(float)*(s0+2)*(s1+2),"DOM_BD");
02862   init_pvar(DOM_BD,NULL,'f',0.0);
02863   Inorg_Z = (float *) nalloc(sizeof(float)*(s0+2)*(s1+2),"Inorg_Z");
02864   init_pvar(Inorg_Z,NULL,'f',0.0);
02865   DIM = (float *) nalloc(sizeof(float)*(s0+2)*(s1+2),"DIM");
02866   init_pvar(DIM,NULL,'f',0.0);
02867   DOP_DECOMP = (float *) nalloc(sizeof(float)*(s0+2)*(s1+2),"DOP_DECOMP");
02868   init_pvar(DOP_DECOMP,NULL,'f',0.0);
02869 
02870   DOP = (double *) nalloc(sizeof(double)*(s0+2)*(s1+2),"DOP");
02871   init_pvar(DOP,NULL,'l',0.0);
02872 
02873 /* placeholder for fire */
02874   FIREdummy = (float *) nalloc(sizeof(float)*(s0+2)*(s1+2),"FIREdummy");
02875   init_pvar(FIREdummy,NULL,'f',0.0);
02876         
02877   HYD_DOM_ACTWAT_PRES = (float *) nalloc(sizeof(float)*(s0+2)*(s1+2),"HYD_DOM_ACTWAT_PRES");
02878   init_pvar(HYD_DOM_ACTWAT_PRES,NULL,'f',0.0);
02879   HYD_DOM_ACTWAT_VOL = (float *) nalloc(sizeof(float)*(s0+2)*(s1+2),"HYD_DOM_ACTWAT_VOL");
02880   init_pvar(HYD_DOM_ACTWAT_VOL,NULL,'f',0.0);
02881   HYD_EVAP_CALC = (float *) nalloc(sizeof(float)*(s0+2)*(s1+2),"HYD_EVAP_CALC");
02882   init_pvar(HYD_EVAP_CALC,NULL,'f',0.0);
02883   HYD_MANNINGS_N = (float *) nalloc(sizeof(float)*(s0+2)*(s1+2),"HYD_MANNINGS_N");
02884   init_pvar(HYD_MANNINGS_N,NULL,'f',0.0);
02885   HYD_RCCONDUCT = (float *) nalloc(sizeof(float)*(s0+2)*(s1+2),"HYD_RCCONDUCT");
02886   init_pvar(HYD_RCCONDUCT,NULL,'f',0.0);
02887   HYD_SAT_POT_TRANS = (float *) nalloc(sizeof(float)*(s0+2)*(s1+2),"HYD_SAT_POT_TRANS");
02888   init_pvar(HYD_SAT_POT_TRANS,NULL,'f',0.0);
02889   HYD_SED_WAT_VOL = (float *) nalloc(sizeof(float)*(s0+2)*(s1+2),"HYD_SED_WAT_VOL");
02890   init_pvar(HYD_SED_WAT_VOL,NULL,'f',0.0);
02891   HYD_TOT_POT_TRANSP = (float *) nalloc(sizeof(float)*(s0+2)*(s1+2),"HYD_TOT_POT_TRANSP");
02892   init_pvar(HYD_TOT_POT_TRANSP,NULL,'f',0.0);
02893   HydTotHd = (float *) nalloc(sizeof(float)*(s0+2)*(s1+2),"HydTotHd");
02894   init_pvar(HydTotHd,NULL,'f',0.0);
02895   HydRelDepPosNeg = (float *) nalloc(sizeof(float)*(s0+2)*(s1+2),"HydRelDepPosNeg");
02896   init_pvar(HydRelDepPosNeg,NULL,'f',0.0);
02897   HYD_TRANSP = (float *) nalloc(sizeof(float)*(s0+2)*(s1+2),"HYD_TRANSP");
02898   init_pvar(HYD_TRANSP,NULL,'f',0.0);
02899   HYD_ET = (float *) nalloc(sizeof(float)*(s0+2)*(s1+2),"HYD_ET");
02900   init_pvar(HYD_ET,NULL,'f',0.0);
02901   HYD_UNSAT_POT_TRANS = (float *) nalloc(sizeof(float)*(s0+2)*(s1+2),"HYD_UNSAT_POT_TRANS");
02902   init_pvar(HYD_UNSAT_POT_TRANS,NULL,'f',0.0);
02903   HYD_WATER_AVAIL = (float *) nalloc(sizeof(float)*(s0+2)*(s1+2),"HYD_WATER_AVAIL");
02904   init_pvar(HYD_WATER_AVAIL,NULL,'f',0.0);
02905 
02906 /* sfwmm rainfall, stage, and pET mapped to elm grid */
02907   boundcond_rain = (float *) nalloc(sizeof(float)*(s0+2)*(s1+2),"boundcond_rain");
02908   init_pvar(boundcond_rain,NULL,'f',0.0);
02909   boundcond_depth = (float *) nalloc(sizeof(float)*(s0+2)*(s1+2),"boundcond_depth");
02910   init_pvar(boundcond_depth,NULL,'f',0.0);
02911   boundcond_ETp = (float *) nalloc(sizeof(float)*(s0+2)*(s1+2),"boundcond_ETp");
02912   init_pvar(boundcond_ETp,NULL,'f',0.0);
02913 
02914   SAT_TO_UNSAT_FL = (float *) nalloc(sizeof(float)*(s0+2)*(s1+2),"SAT_TO_UNSAT_FL");
02915   init_pvar(SAT_TO_UNSAT_FL,NULL,'f',0.0);
02916   SAT_VS_UNSAT = (float *) nalloc(sizeof(float)*(s0+2)*(s1+2),"SAT_VS_UNSAT");
02917   init_pvar(SAT_VS_UNSAT,NULL,'f',0.0);
02918   SAT_WATER = (float *) nalloc(sizeof(float)*(s0+2)*(s1+2),"SAT_WATER");
02919   init_pvar(SAT_WATER,NULL,'f',0.0);
02920   SAT_WT_HEAD = (float *) nalloc(sizeof(float)*(s0+2)*(s1+2),"SAT_WT_HEAD");
02921   init_pvar(SAT_WT_HEAD,NULL,'f',0.0);
02922   SAT_WT_RECHG = (float *) nalloc(sizeof(float)*(s0+2)*(s1+2),"SAT_WT_RECHG");
02923   init_pvar(SAT_WT_RECHG,NULL,'f',0.0);
02924   SAT_WT_TRANSP = (float *) nalloc(sizeof(float)*(s0+2)*(s1+2),"SAT_WT_TRANSP");
02925   init_pvar(SAT_WT_TRANSP,NULL,'f',0.0);
02926   SF_WT_EVAP = (float *) nalloc(sizeof(float)*(s0+2)*(s1+2),"SF_WT_EVAP");
02927   init_pvar(SF_WT_EVAP,NULL,'f',0.0);
02928   SF_WT_FROM_RAIN = (float *) nalloc(sizeof(float)*(s0+2)*(s1+2),"SF_WT_FROM_RAIN");
02929   init_pvar(SF_WT_FROM_RAIN,NULL,'f',0.0);
02930   SF_WT_INFILTRATION = (float *) nalloc(sizeof(float)*(s0+2)*(s1+2),"SF_WT_INFILTRATION");
02931   init_pvar(SF_WT_INFILTRATION,NULL,'f',0.0);
02932   SF_WT_POT_INF = (float *) nalloc(sizeof(float)*(s0+2)*(s1+2),"SF_WT_POT_INF");
02933   init_pvar(SF_WT_POT_INF,NULL,'f',0.0);
02934   SF_WT_TO_SAT_DOWNFLOW = (float *) nalloc(sizeof(float)*(s0+2)*(s1+2),"SF_WT_TO_SAT_DOWNFLOW");
02935   init_pvar(SF_WT_TO_SAT_DOWNFLOW,NULL,'f',0.0);
02936   SFWT_VOL = (float *) nalloc(sizeof(float)*(s0+2)*(s1+2),"SFWT_VOL");
02937   init_pvar(SFWT_VOL,NULL,'f',0.0);
02938   SURFACE_WAT = (float *) nalloc(sizeof(float)*(s0+2)*(s1+2),"SURFACE_WAT");
02939   init_pvar(SURFACE_WAT,NULL,'f',0.0);
02940   SF_WT_VEL_mag = (float *) nalloc(sizeof(float)*(s0+2)*(s1+2),"SF_WT_VEL_mag");
02941   init_pvar(SF_WT_VEL_mag,NULL,'f',0.0); 
02942   BCmodel_sfwat = (float *) nalloc(sizeof(float)*(s0+2)*(s1+2),"BCmodel_sfwat");
02943   init_pvar(BCmodel_sfwat,NULL,'f',0.0); 
02944 
02945   UNSAT_AVAIL = (float *) nalloc(sizeof(float)*(s0+2)*(s1+2),"UNSAT_AVAIL");
02946   init_pvar(UNSAT_AVAIL,NULL,'f',0.0);
02947   UNSAT_CAP = (float *) nalloc(sizeof(float)*(s0+2)*(s1+2),"UNSAT_CAP");
02948   init_pvar(UNSAT_CAP,NULL,'f',0.0);
02949   UNSAT_DEPTH = (float *) nalloc(sizeof(float)*(s0+2)*(s1+2),"UNSAT_DEPTH");
02950   init_pvar(UNSAT_DEPTH,NULL,'f',0.0);
02951   UNSAT_HYD_COND_CF = (float *) nalloc(sizeof(float)*(s0+2)*(s1+2),"UNSAT_HYD_COND_CF");
02952   init_pvar(UNSAT_HYD_COND_CF,NULL,'f',0.0);
02953   UNSAT_MOIST_PRP = (float *) nalloc(sizeof(float)*(s0+2)*(s1+2),"UNSAT_MOIST_PRP");
02954   init_pvar(UNSAT_MOIST_PRP,NULL,'f',0.0);
02955   UNSAT_PERC = (float *) nalloc(sizeof(float)*(s0+2)*(s1+2),"UNSAT_PERC");
02956   init_pvar(UNSAT_PERC,NULL,'f',0.0);
02957   UNSAT_TO_SAT_FL = (float *) nalloc(sizeof(float)*(s0+2)*(s1+2),"UNSAT_TO_SAT_FL");
02958   init_pvar(UNSAT_TO_SAT_FL,NULL,'f',0.0);
02959   UNSAT_TRANSP = (float *) nalloc(sizeof(float)*(s0+2)*(s1+2),"UNSAT_TRANSP");
02960   init_pvar(UNSAT_TRANSP,NULL,'f',0.0);
02961   UNSAT_WATER = (float *) nalloc(sizeof(float)*(s0+2)*(s1+2),"UNSAT_WATER");
02962   init_pvar(UNSAT_WATER,NULL,'f',0.0);
02963   UNSAT_WT_POT = (float *) nalloc(sizeof(float)*(s0+2)*(s1+2),"UNSAT_WT_POT");
02964   init_pvar(UNSAT_WT_POT,NULL,'f',0.0);
02965 
02966   MAC_HEIGHT = (float *) nalloc(sizeof(float)*(s0+2)*(s1+2),"MAC_HEIGHT");
02967   init_pvar(MAC_HEIGHT,NULL,'f',0.0);
02968   MAC_LAI = (float *) nalloc(sizeof(float)*(s0+2)*(s1+2),"MAC_LAI");
02969   init_pvar(MAC_LAI,NULL,'f',0.0);
02970   LAI_eff = (float *) nalloc(sizeof(float)*(s0+2)*(s1+2),"LAI_eff");
02971   init_pvar(LAI_eff,NULL,'f',0.0);
02972   MAC_LIGHT_CF = (float *) nalloc(sizeof(float)*(s0+2)*(s1+2),"MAC_LIGHT_CF");
02973   init_pvar(MAC_LIGHT_CF,NULL,'f',0.0);
02974   MAC_MAX_BIO = (float *) nalloc(sizeof(float)*(s0+2)*(s1+2),"MAC_MAX_BIO");
02975   init_pvar(MAC_MAX_BIO,NULL,'f',0.0);
02976   MAC_NOPH_BIOMAS = (float *) nalloc(sizeof(float)*(s0+2)*(s1+2),"MAC_NOPH_BIOMAS");
02977   init_pvar(MAC_NOPH_BIOMAS,NULL,'f',0.0);
02978   MAC_NUT_CF = (float *) nalloc(sizeof(float)*(s0+2)*(s1+2),"MAC_NUT_CF");
02979   init_pvar(MAC_NUT_CF,NULL,'f',0.0);
02980   MAC_PH_BIOMAS = (float *) nalloc(sizeof(float)*(s0+2)*(s1+2),"MAC_PH_BIOMAS");
02981   init_pvar(MAC_PH_BIOMAS,NULL,'f',0.0);
02982   MAC_PROD_CF = (float *) nalloc(sizeof(float)*(s0+2)*(s1+2),"MAC_PROD_CF");
02983   init_pvar(MAC_PROD_CF,NULL,'f',0.0);
02984   MAC_REL_BIOM = (float *) nalloc(sizeof(float)*(s0+2)*(s1+2),"MAC_REL_BIOM");
02985   init_pvar(MAC_REL_BIOM,NULL,'f',0.0);
02986   MAC_SALT_CF = (float *) nalloc(sizeof(float)*(s0+2)*(s1+2),"MAC_SALT_CF");
02987   init_pvar(MAC_SALT_CF,NULL,'f',0.0);
02988   MAC_TEMP_CF = (float *) nalloc(sizeof(float)*(s0+2)*(s1+2),"MAC_TEMP_CF");
02989   init_pvar(MAC_TEMP_CF,NULL,'f',0.0);
02990   MAC_TOT_BIOM = (float *) nalloc(sizeof(float)*(s0+2)*(s1+2),"MAC_TOT_BIOM");
02991   init_pvar(MAC_TOT_BIOM,NULL,'f',0.0);
02992   MAC_WATER_CF = (float *) nalloc(sizeof(float)*(s0+2)*(s1+2),"MAC_WATER_CF");
02993   init_pvar(MAC_WATER_CF,NULL,'f',0.0);
02994   MAC_WATER_AVAIL_CF = (float *) nalloc(sizeof(float)*(s0+2)*(s1+2),"MAC_WATER_AVAIL_CF");
02995   init_pvar(MAC_WATER_AVAIL_CF,NULL,'f',0.0);
02996   NPHBIO_AVAIL = (float *) nalloc(sizeof(float)*(s0+2)*(s1+2),"NPHBIO_AVAIL");
02997   init_pvar(NPHBIO_AVAIL,NULL,'f',0.0);
02998   NPHBIO_MORT = (float *) nalloc(sizeof(float)*(s0+2)*(s1+2),"NPHBIO_MORT");
02999   init_pvar(NPHBIO_MORT,NULL,'f',0.0);
03000   NPHBIO_MORT_POT = (float *) nalloc(sizeof(float)*(s0+2)*(s1+2),"NPHBIO_MORT_POT");
03001   init_pvar(NPHBIO_MORT_POT,NULL,'f',0.0);
03002   NPHBIO_REFUGE = (float *) nalloc(sizeof(float)*(s0+2)*(s1+2),"NPHBIO_REFUGE");
03003   init_pvar(NPHBIO_REFUGE,NULL,'f',0.0);
03004   NPHBIO_SAT = (float *) nalloc(sizeof(float)*(s0+2)*(s1+2),"NPHBIO_SAT");
03005   init_pvar(NPHBIO_SAT,NULL,'f',0.0);
03006   NPHBIO_TRANSLOC = (float *) nalloc(sizeof(float)*(s0+2)*(s1+2),"NPHBIO_TRANSLOC");
03007   init_pvar(NPHBIO_TRANSLOC,NULL,'f',0.0);
03008   NPHBIO_TRANSLOC_POT = (float *) nalloc(sizeof(float)*(s0+2)*(s1+2),"NPHBIO_TRANSLOC_POT");
03009   init_pvar(NPHBIO_TRANSLOC_POT,NULL,'f',0.0);
03010   PHBIO_AVAIL = (float *) nalloc(sizeof(float)*(s0+2)*(s1+2),"PHBIO_AVAIL");
03011   init_pvar(PHBIO_AVAIL,NULL,'f',0.0);
03012   PHBIO_MORT = (float *) nalloc(sizeof(float)*(s0+2)*(s1+2),"PHBIO_MORT");
03013   init_pvar(PHBIO_MORT,NULL,'f',0.0);
03014   PHBIO_MORT_POT = (float *) nalloc(sizeof(float)*(s0+2)*(s1+2),"PHBIO_MORT_POT");
03015   init_pvar(PHBIO_MORT_POT,NULL,'f',0.0);
03016   PHBIO_NPP = (float *) nalloc(sizeof(float)*(s0+2)*(s1+2),"PHBIO_NPP");
03017   init_pvar(PHBIO_NPP,NULL,'f',0.0);
03018   PHBIO_REFUGE = (float *) nalloc(sizeof(float)*(s0+2)*(s1+2),"PHBIO_REFUGE");
03019   init_pvar(PHBIO_REFUGE,NULL,'f',0.0);
03020   PHBIO_SAT = (float *) nalloc(sizeof(float)*(s0+2)*(s1+2),"PHBIO_SAT");
03021   init_pvar(PHBIO_SAT,NULL,'f',0.0); 
03022   PHBIO_TRANSLOC = (float *) nalloc(sizeof(float)*(s0+2)*(s1+2),"PHBIO_TRANSLOC");
03023   init_pvar(PHBIO_TRANSLOC,NULL,'f',0.0);
03024   PHBIO_TRANSLOC_POT = (float *) nalloc(sizeof(float)*(s0+2)*(s1+2),"PHBIO_TRANSLOC_POT");
03025   init_pvar(PHBIO_TRANSLOC_POT,NULL,'f',0.0);
03026 
03027   phbio_npp_P = (double *) nalloc(sizeof(double)*(s0+2)*(s1+2),"phbio_npp_P");
03028   init_pvar(phbio_npp_P,NULL,'l',0.0);
03029   phbio_npp_OM = (double *) nalloc(sizeof(double)*(s0+2)*(s1+2),"phbio_npp_OM");
03030   init_pvar(phbio_npp_OM,NULL,'l',0.0);
03031   phbio_mort_P = (double *) nalloc(sizeof(double)*(s0+2)*(s1+2),"phbio_mort_P");
03032   init_pvar(phbio_mort_P,NULL,'l',0.0);
03033   phbio_mort_OM = (double *) nalloc(sizeof(double)*(s0+2)*(s1+2),"phbio_mort_OM");
03034   init_pvar(phbio_mort_OM,NULL,'l',0.0);
03035   phbio_transl_P = (double *) nalloc(sizeof(double)*(s0+2)*(s1+2),"phbio_transl_P");
03036   init_pvar(phbio_transl_P,NULL,'l',0.0);
03037   phbio_transl_OM = (double *) nalloc(sizeof(double)*(s0+2)*(s1+2),"phbio_transl_OM");
03038   init_pvar(phbio_transl_OM,NULL,'l',0.0);
03039   nphbio_transl_P = (double *) nalloc(sizeof(double)*(s0+2)*(s1+2),"nphbio_transl_P");
03040   init_pvar(nphbio_transl_P,NULL,'l',0.0);
03041   nphbio_transl_OM = (double *) nalloc(sizeof(double)*(s0+2)*(s1+2),"nphbio_transl_OM");
03042   init_pvar(nphbio_transl_OM,NULL,'l',0.0);
03043   nphbio_mort_P = (double *) nalloc(sizeof(double)*(s0+2)*(s1+2),"nphbio_mort_P");
03044   init_pvar(nphbio_mort_P,NULL,'l',0.0);
03045   nphbio_mort_OM = (double *) nalloc(sizeof(double)*(s0+2)*(s1+2),"nphbio_mort_OM");
03046   init_pvar(nphbio_mort_OM,NULL,'l',0.0);
03047   mac_nph_P = (double *) nalloc(sizeof(double)*(s0+2)*(s1+2),"mac_nph_P");
03048   init_pvar(mac_nph_P,NULL,'l',0.0);
03049   mac_nph_PC = (double *) nalloc(sizeof(double)*(s0+2)*(s1+2),"mac_nph_PC");
03050   init_pvar(mac_nph_PC,NULL,'l',0.0);
03051   mac_nph_OM = (double *) nalloc(sizeof(double)*(s0+2)*(s1+2),"mac_nph_OM");
03052   init_pvar(mac_nph_OM,NULL,'l',0.0);
03053   mac_nph_CtoOM = (double *) nalloc(sizeof(double)*(s0+2)*(s1+2),"mac_nph_CtoOM");
03054   init_pvar(mac_nph_CtoOM,NULL,'l',0.0);
03055   mac_ph_P = (double *) nalloc(sizeof(double)*(s0+2)*(s1+2),"mac_ph_P");
03056   init_pvar(mac_ph_P,NULL,'l',0.0);
03057   mac_ph_PC = (double *) nalloc(sizeof(double)*(s0+2)*(s1+2),"mac_ph_PC");
03058   init_pvar(mac_ph_PC,NULL,'l',0.0);
03059   mac_ph_OM = (double *) nalloc(sizeof(double)*(s0+2)*(s1+2),"mac_ph_OM");
03060   init_pvar(mac_ph_OM,NULL,'l',0.0);
03061   mac_ph_CtoOM = (double *) nalloc(sizeof(double)*(s0+2)*(s1+2),"mac_ph_CtoOM");
03062   init_pvar(mac_ph_CtoOM,NULL,'l',0.0);
03063 
03064   mac_nph_PC_rep = (float *) nalloc(sizeof(float)*(s0+2)*(s1+2),"mac_nph_PC_rep");
03065   init_pvar(mac_nph_PC_rep,NULL,'f',0.0);
03066   mac_ph_PC_rep = (float *) nalloc(sizeof(float)*(s0+2)*(s1+2),"mac_ph_PC_rep");
03067   init_pvar(mac_ph_PC_rep,NULL,'f',0.0);
03068 
03069   TP_SED_WT = (double *) nalloc(sizeof(double)*(s0+2)*(s1+2),"TP_SED_WT");
03070   init_pvar(TP_SED_WT,NULL,'l',0.0);
03071   TP_SED_CONC = (double *) nalloc(sizeof(double)*(s0+2)*(s1+2),"TP_SED_CONC");
03072   init_pvar(TP_SED_CONC,NULL,'l',0.0);
03073   TP_SEDWT_CONCACT = (double *) nalloc(sizeof(double)*(s0+2)*(s1+2),"TP_SEDWT_CONCACT");
03074   init_pvar(TP_SEDWT_CONCACT,NULL,'l',0.0);
03075   TP_SF_WT = (double *) nalloc(sizeof(double)*(s0+2)*(s1+2),"TP_SF_WT");
03076   init_pvar(TP_SF_WT,NULL,'l',0.0);
03077   TP_SFWT_CONC = (double *) nalloc(sizeof(double)*(s0+2)*(s1+2),"TP_SFWT_CONC");
03078   init_pvar(TP_SFWT_CONC,NULL,'l',0.0);
03079   TP_SORB = (double *) nalloc(sizeof(double)*(s0+2)*(s1+2),"TP_SORB");
03080   init_pvar(TP_SORB,NULL,'l',0.0);
03081   TP_SORBCONC = (double *) nalloc(sizeof(double)*(s0+2)*(s1+2),"TP_SORBCONC");
03082   init_pvar(TP_SORBCONC,NULL,'l',0.0);
03083   TP_SED_WT_AZ = (double *) nalloc(sizeof(double)*(s0+2)*(s1+2),"TP_SED_WT_AZ");
03084   init_pvar(TP_SED_WT_AZ,NULL,'l',0.0);
03085   TP_Act_to_Tot = (double *) nalloc(sizeof(double)*(s0+2)*(s1+2),"TP_Act_to_Tot");
03086   init_pvar(TP_Act_to_Tot,NULL,'l',0.0);
03087 
03088   TP_Act_to_TotRep = (float *) nalloc(sizeof(float)*(s0+2)*(s1+2),"TP_Act_to_TotRep");
03089   init_pvar(TP_Act_to_TotRep,NULL,'f',0.0);
03090   TP_SORBCONC_rep = (float *) nalloc(sizeof(float)*(s0+2)*(s1+2),"TP_SORBCONC_rep");
03091   init_pvar(TP_SORBCONC_rep,NULL,'f',0.0);
03092 
03093   TP_DNFLOW = (float *) nalloc(sizeof(float)*(s0+2)*(s1+2),"TP_DNFLOW");
03094   init_pvar(TP_DNFLOW,NULL,'f',0.0);
03095   TP_DNFLOW_POT = (float *) nalloc(sizeof(float)*(s0+2)*(s1+2),"TP_DNFLOW_POT");
03096   init_pvar(TP_DNFLOW_POT,NULL,'f',0.0);
03097   TP_Atm_Depos = (float *) nalloc(sizeof(float)*(s0+2)*(s1+2),"TP_Atm_Depos");
03098   init_pvar(TP_Atm_Depos,NULL,'f',0.0);
03099 /* v2.6 added map of atmospheric TP deposition rate */
03100   TP_AtmosDepos = (float *) nalloc(sizeof(float)*(s0+2)*(s1+2),"TP_AtmosDepos");
03101   init_pvar(TP_AtmosDepos,NULL,'f',0.0);
03102   TP_K = (float *) nalloc(sizeof(float)*(s0+2)*(s1+2),"TP_K");
03103   init_pvar(TP_K,NULL,'f',0.0);
03104   TP_SED_MINER = (float *) nalloc(sizeof(float)*(s0+2)*(s1+2),"TP_SED_MINER");
03105   init_pvar(TP_SED_MINER,NULL,'f',0.0);
03106   TP_SEDWT_CONCACTMG = (float *) nalloc(sizeof(float)*(s0+2)*(s1+2),"TP_SEDWT_CONCACTMG");
03107   init_pvar(TP_SEDWT_CONCACTMG,NULL,'f',0.0);
03108   TP_SEDWT_UPTAKE = (float *) nalloc(sizeof(float)*(s0+2)*(s1+2),"TP_SEDWT_UPTAKE");
03109   init_pvar(TP_SEDWT_UPTAKE,NULL,'f',0.0);
03110   TP_SFWT_CONC_MG = (float *) nalloc(sizeof(float)*(s0+2)*(s1+2),"TP_SFWT_CONC_MG");
03111   init_pvar(TP_SFWT_CONC_MG,NULL,'f',0.0);
03112   TP_SFWT_MINER = (float *) nalloc(sizeof(float)*(s0+2)*(s1+2),"TP_SFWT_MINER");
03113   init_pvar(TP_SFWT_MINER,NULL,'f',0.0);
03114   TP_SFWT_UPTAK = (float *) nalloc(sizeof(float)*(s0+2)*(s1+2),"TP_SFWT_UPTAK");
03115   init_pvar(TP_SFWT_UPTAK,NULL,'f',0.0);
03116   TP_settl = (float *) nalloc(sizeof(float)*(s0+2)*(s1+2),"TP_settl");
03117   init_pvar(TP_settl,NULL,'f',0.0);
03118   TP_SORB_POT = (float *) nalloc(sizeof(float)*(s0+2)*(s1+2),"TP_SORB_POT");
03119   init_pvar(TP_SORB_POT,NULL,'f',0.0);
03120   TP_SORBTION = (float *) nalloc(sizeof(float)*(s0+2)*(s1+2),"TP_SORBTION");
03121   init_pvar(TP_SORBTION,NULL,'f',0.0);
03122   TP_UPFLOW = (float *) nalloc(sizeof(float)*(s0+2)*(s1+2),"TP_UPFLOW");
03123   init_pvar(TP_UPFLOW,NULL,'f',0.0);
03124   TP_UPFLOW_POT = (float *) nalloc(sizeof(float)*(s0+2)*(s1+2),"TP_UPFLOW_POT");
03125   init_pvar(TP_UPFLOW_POT,NULL,'f',0.0);
03126   P_SUM_CELL = (float *) nalloc(sizeof(float)*(s0+2)*(s1+2),"P_SUM_CELL");
03127   init_pvar(P_SUM_CELL,NULL,'f',0.0);
03128 
03129   DINdummy = (double *) nalloc(sizeof(double)*(s0+2)*(s1+2),"DINdummy");
03130   init_pvar(DINdummy,NULL,'l',0.0);
03131 
03132   WQMsettlVel = (float *) nalloc(sizeof(float)*(s0+2)*(s1+2),"WQMsettlVel");
03133   init_pvar(WQMsettlVel,NULL,'f',0.0);
03134   TP_settlDays = (float *) nalloc(sizeof(float)*(s0+2)*(s1+2),"TP_settlDays");
03135   init_pvar(TP_settlDays,NULL,'f',0.0);
03136 
03137   SAL_SED_WT = (double *) nalloc(sizeof(double)*(s0+2)*(s1+2),"SAL_SED_WT");
03138   init_pvar(SAL_SED_WT,NULL,'l',0.0);
03139   SAL_SF_WT_mb = (double *) nalloc(sizeof(double)*(s0+2)*(s1+2),"SAL_SF_WT_mb");
03140   init_pvar(SAL_SF_WT_mb,NULL,'l',0.0);
03141   SALT_SED_WT = (double *) nalloc(sizeof(double)*(s0+2)*(s1+2),"SALT_SED_WT");
03142   init_pvar(SALT_SED_WT,NULL,'l',0.0);
03143   SALT_SURF_WT = (double *) nalloc(sizeof(double)*(s0+2)*(s1+2),"SALT_SURF_WT");
03144   init_pvar(SALT_SURF_WT,NULL,'l',0.0);
03145         
03146   SAL_SF_WT = (float *) nalloc(sizeof(float)*(s0+2)*(s1+2),"SAL_SF_WT");
03147   init_pvar(SAL_SF_WT,NULL,'f',0.0);
03148   SALT_Atm_Depos = (float *) nalloc(sizeof(float)*(s0+2)*(s1+2),"SALT_Atm_Depos");
03149   init_pvar(SALT_Atm_Depos,NULL,'f',0.0);
03150   SALT_SED_TO_SF_FLOW = (float *) nalloc(sizeof(float)*(s0+2)*(s1+2),"SALT_SED_TO_SF_FLOW");
03151   init_pvar(SALT_SED_TO_SF_FLOW,NULL,'f',0.0);
03152   SALT_SFWAT_DOWNFL = (float *) nalloc(sizeof(float)*(s0+2)*(s1+2),"SALT_SFWAT_DOWNFL");
03153   init_pvar(SALT_SFWAT_DOWNFL,NULL,'f',0.0);
03154   SALT_SFWAT_DOWNFL_POT = (float *) nalloc(sizeof(float)*(s0+2)*(s1+2),"SALT_SFWAT_DOWNFL_POT");
03155   init_pvar(SALT_SFWAT_DOWNFL_POT,NULL,'f',0.0);
03156 
03157   FLOC_DECOMP = (float *) nalloc(sizeof(float)*(s0+2)*(s1+2),"FLOC_DECOMP");
03158   init_pvar(FLOC_DECOMP,NULL,'f',0.0);
03159   FLOC_DECOMP_POT = (float *) nalloc(sizeof(float)*(s0+2)*(s1+2),"FLOC_DECOMP_POT");
03160   init_pvar(FLOC_DECOMP_POT,NULL,'f',0.0);
03161   FLOC_DECOMP_QUAL_CF = (float *) nalloc(sizeof(float)*(s0+2)*(s1+2),"FLOC_DECOMP_QUAL_CF");
03162   init_pvar(FLOC_DECOMP_QUAL_CF,NULL,'f',0.0);
03163   FLOC_Z = (float *) nalloc(sizeof(float)*(s0+2)*(s1+2),"FLOC_Z");
03164   init_pvar(FLOC_Z,NULL,'f',0.0);
03165   FLOC_DEPO = (float *) nalloc(sizeof(float)*(s0+2)*(s1+2),"FLOC_DEPO");
03166   init_pvar(FLOC_DEPO,NULL,'f',0.0);
03167   FLOC_DEPO_POT = (float *) nalloc(sizeof(float)*(s0+2)*(s1+2),"FLOC_DEPO_POT");
03168   init_pvar(FLOC_DEPO_POT,NULL,'f',0.0);
03169   FLOC_FR_ALGAE = (float *) nalloc(sizeof(float)*(s0+2)*(s1+2),"FLOC_FR_ALGAE");
03170   init_pvar(FLOC_FR_ALGAE,NULL,'f',0.0);
03171   FLOC = (float *) nalloc(sizeof(float)*(s0+2)*(s1+2),"FLOC");
03172   init_pvar(FLOC,NULL,'f',0.0);
03173   FlocP = (float *) nalloc(sizeof(float)*(s0+2)*(s1+2),"FlocP");
03174   init_pvar(FlocP,NULL,'f',0.0);
03175   FlocP_DECOMP = (float *) nalloc(sizeof(float)*(s0+2)*(s1+2),"FlocP_DECOMP");
03176   init_pvar(FlocP_DECOMP,NULL,'f',0.0);
03177   FlocP_FR_ALGAE = (float *) nalloc(sizeof(float)*(s0+2)*(s1+2),"FlocP_FR_ALGAE");
03178   init_pvar(FlocP_FR_ALGAE,NULL,'f',0.0);
03179   FlocP_PhBio = (float *) nalloc(sizeof(float)*(s0+2)*(s1+2),"FlocP_PhBio");
03180   init_pvar(FlocP_PhBio,NULL,'f',0.0);
03181   FlocP_DEPO = (float *) nalloc(sizeof(float)*(s0+2)*(s1+2),"FlocP_DEPO");
03182   init_pvar(FlocP_DEPO,NULL,'f',0.0);
03183   FlocP_OMrep = (float *) nalloc(sizeof(float)*(s0+2)*(s1+2),"FlocP_OMrep");
03184   init_pvar(FlocP_OMrep,NULL,'f',0.0);
03185   FlocP_OM = (double *) nalloc(sizeof(double)*(s0+2)*(s1+2),"FlocP_OM");
03186   init_pvar(FlocP_OM,NULL,'l',0.0);
03187 
03188   SOLRADGRD = (float *) nalloc(sizeof(float)*(s0+2)*(s1+2),"SOLRADGRD");
03189   init_pvar(SOLRADGRD,NULL,'f',0.0);
03190   SOLRAD274 = (float *) nalloc(sizeof(float)*(s0+2)*(s1+2),"SOLRAD274");
03191   init_pvar(SOLRAD274,NULL,'f',0.0);
03192   AIR_TEMP = (float *) nalloc(sizeof(float)*(s0+2)*(s1+2),"AIR_TEMP");
03193   init_pvar(AIR_TEMP,NULL,'f',0.0);
03194   H2O_TEMP = (float *) nalloc(sizeof(float)*(s0+2)*(s1+2),"H2O_TEMP");
03195   init_pvar(H2O_TEMP,NULL,'f',0.0);
03196 
03197 /* habitat-specific parameter arrays */
03198   HP_ALG_MAX = NULL;
03199 
03200   HP_DOM_MAXDEPTH = NULL;
03201   HP_DOM_AEROBTHIN = NULL;
03202 
03203   HP_TP_CONC_GRAD = NULL;
03204 
03205   HP_SALT_ICSEDWAT = NULL;
03206   HP_SALT_ICSFWAT = NULL;
03207 
03208   HP_PHBIO_MAX = NULL;
03209   HP_NPHBIO_MAX = NULL;
03210   HP_MAC_MAXHT = NULL;
03211   HP_NPHBIO_ROOTDEPTH = NULL;
03212   HP_MAC_MAXROUGH = NULL;
03213   HP_MAC_MINROUGH = NULL;
03214   HP_MAC_MAXLAI = NULL;
03215   HP_MAC_MAXCANOPCOND = NULL;
03216   HP_MAC_CANOPDECOUP = NULL;
03217   HP_MAC_TEMPOPT = NULL;
03218   HP_MAC_LIGHTSAT = NULL;
03219   HP_MAC_KSP = NULL;
03220   HP_PHBIO_RCNPP = NULL;
03221   HP_PHBIO_RCMORT = NULL;
03222   HP_MAC_WAT_TOLER = NULL;
03223   HP_MAC_SALIN_THRESH = NULL;
03224   HP_PHBIO_IC_CTOOM = NULL;
03225   HP_NPHBIO_IC_CTOOM = NULL;
03226   HP_PHBIO_IC_PC = NULL;
03227   HP_NPHBIO_IC_PC = NULL;
03228   HP_MAC_TRANSLOC_RC = NULL;
03229 
03230   HP_HYD_RCINFILT = NULL;
03231   HP_HYD_SPEC_YIELD = NULL;
03232   HP_HYD_POROSITY = NULL;
03233 
03234   HP_FLOC_IC = NULL;
03235   HP_FLOC_IC_CTOOM = NULL;
03236   HP_FLOC_IC_PC = NULL;
03237 
03238   HP_SfDepthLo = NULL;
03239   HP_SfDepthHi = NULL;
03240   HP_SfDepthInt = NULL;
03241   HP_PhosLo = NULL;
03242   HP_PhosHi = NULL;
03243   HP_PhosInt = NULL;
03244   HP_FireInt = NULL;
03245   HP_SalinLo = NULL;
03246   HP_SalinHi = NULL;
03247   HP_SalinInt = NULL;
03248   
03249   usrErr("Done."); /* console message */
03250 
03251 }
03252 
03253 
03254 /*******
03255 the remaining functions are time-series graph interpolaters
03256 ******/
03257 
03265 float graph7(unsigned char y, float x)
03266 {
03267   float s;
03268   int ig=0, Np=10;
03275   while(1) {
03276   if (x <= g7[ig][0]) { if(ig>0) ig=ig-1; else return(g7[0][1+y]);}
03277   else if (x > g7[ig][0] && x <= g7[ig+1][0]) {
03278          s =   (g7[ig+1][1+y]-g7[ig][1+y])/
03279             (g7[ig+1][0]-g7[ig][0]);
03280          return(s * (x-g7[ig][0]) + g7[ig][1+y]); }
03281     else if (x > g7[ig+1][0]) { if(ig<Np) ig=ig+1; else return(g7[Np][1+y]);}
03282   }
03283 }
03284 
03292 float graph8(unsigned char y, float x)
03293 {
03294   float s;
03295   int ig=0, Np=10;
03302   while(1) {
03303   if (x <= g8[ig][0]) { if(ig>0) ig=ig-1; else return(g8[0][1+y]);}
03304   else if (x > g8[ig][0] && x <= g8[ig+1][0]) {
03305          s =   (g8[ig+1][1+y]-g8[ig][1+y])/
03306             (g8[ig+1][0]-g8[ig][0]);
03307          return(s * (x-g8[ig][0]) + g8[ig][1+y]); }
03308     else if (x > g8[ig+1][0]) { if(ig<Np) ig=ig+1; else return(g8[Np][1+y]);}
03309   }
03310 }
03311 
03312 
03313 /***** end UnitMod.c source ***/

Generated on Sat Jan 7 14:04:16 2012 for ELM source code by  doxygen 1.5.6