Ecological Landscape Modeling: Models Pages

Success.c

Go to the documentation of this file.
00001 
00012 /* General notes on revisions to this source file. 
00013        Nov/Dec 2004 v2.3.2: documentation upgrade 
00014                 - Doxygen tags added 
00015        Sep 2011 v2.8.5: added salinity responses 
00016                 - added succession in response to salinity  
00017         
00018 */
00019 
00020 #include "success.h"
00021 
00022 
00025 void HabSwitch_Init(void)
00026 {
00027   int ii;
00028   
00029         /* put these habitat-specific parameters into a concise data struct for use here */
00030   for( ii = 0; ii < habNumTot; ii++) {
00031         Habi[ii].Water.Llo = HP_SfDepthLo[ii+1];
00032         Habi[ii].Water.Lhi = HP_SfDepthHi[ii+1];
00033         Habi[ii].Water.Pin = HP_SfDepthInt[ii+1];
00034         Habi[ii].Nutrient.Llo = HP_PhosLo[ii+1];
00035         Habi[ii].Nutrient.Lhi = HP_PhosHi[ii+1];
00036         Habi[ii].Nutrient.Pin = HP_PhosInt[ii+1];
00037         Habi[ii].PFin = HP_FireInt[ii+1];
00038         Habi[ii].Salinity.Llo = HP_SalinLo[ii+1];
00039         Habi[ii].Salinity.Lhi = HP_SalinHi[ii+1];
00040         Habi[ii].Salinity.Pin = HP_SalinInt[ii+1];
00041   }
00042    
00043    alloc_hab_hist( );
00044    sprintf (msgStr, "Succession ON, module OK for %d habitats...", ii ); usrErr(msgStr); WriteMsg(msgStr,1);
00045 
00046    return; 
00047 }
00048 
00049 
00066 unsigned char HabSwitch(int ix, int iy, float *Water, float *Nutrient, int *Fire, float *Salinity, unsigned char *HAB)
00067 {
00068  int StateW, StateN, StateS, i;
00069  int HabW[MAX_NHAB], HabN[MAX_NHAB], HabS[MAX_NHAB], DW, DN, DS;
00070  int cell =  T(ix,iy);
00071  int hab = HAB[cell];   /* current habitat in the cell */
00072 
00073  /* define the habitat type that matches the existing water conditions */
00074  
00075  /* HabHist is an array of integers : ssSnnNwwW, where 
00076     ww are the two digits for the number of weeks in the water level favorable conditions,
00077     W the number of days in those conditions during the current week;
00078     nn are the two digits for the number of weeks being in the nutrient favorable conditions, 
00079     N the number of days in those conditions during the current week; 
00080     ss are the two digits for the number of weeks in the salinity favorable conditions,
00081     S the number of days in those conditions during the current week;
00082     
00083     The switching occurs when all of these histories exceed the habitat specific 
00084         periods Pin.
00085  */
00086  for ( i = 0; i < habNumTot; i++ )
00087         {
00088          DW = HabHist[cell*habNumTot +i]%10;
00089          HabW[i] = (HabHist[cell*habNumTot +i]/10)%100;
00090          DN = (HabHist[cell*habNumTot +i]/1000)%10;
00091          HabN[i] = HabHist[cell*habNumTot +i]/10000;
00092          DS = (HabHist[cell*habNumTot +i]/1000000)%10;
00093          HabS[i] = HabHist[cell*habNumTot +i]/10000000;
00094          
00095          /* when the averaging time elapses, if #favorable days exceeds a threshold (using 4 for 7 day AV_PER), increment the period (weeks) history */
00096          if ((int)SimTime.TIME%AV_PER == 0)
00097            { 
00098                 if (DW > SW_TIME_TH_W) HabHist[cell*habNumTot +i] = HabHist[cell*habNumTot +i] - DW + 100;
00099                 else HabHist[cell*habNumTot +i] = 0;
00100                 if (DN > SW_TIME_TH_N) HabHist[cell*habNumTot +i] = HabHist[cell*habNumTot +i] - DN*1000 + 10000;
00101                 else HabHist[cell*habNumTot +i] = 0;
00102                 if (DS > SW_TIME_TH_S) HabHist[cell*habNumTot +i] = HabHist[cell*habNumTot +i] - DS*1000000 + 10000000;
00103                 else HabHist[cell*habNumTot +i] = 0;
00104            }    
00105 
00106         /* check what habitat type the existing conditions match; increment the day# if conditions are favorable */
00107          if ( InHab (Water[cell], Habi[i].Water) )                    HabHist[cell*habNumTot + i] = HabHist[cell*habNumTot + i] + 1;
00108          if ( InHab (Nutrient[cell]*conv_kgTOmg, Habi[i].Nutrient) )  HabHist[cell*habNumTot + i] = HabHist[cell*habNumTot + i] + 1000;
00109          if ( InHab (Salinity[cell], Habi[i].Salinity) )              HabHist[cell*habNumTot + i] = HabHist[cell*habNumTot + i] + 1000000;
00110         } 
00111    
00112          /* check if the historical conditions for switching hold */
00113  for ( i = 0; i < habNumTot; i++ )  
00114         if ( HabW[i] >= Habi[i].Water.Pin && HabN[i] >= Habi[i].Nutrient.Pin && HabS[i] >= Habi[i].Salinity.Pin ) 
00115                 { HabHist[cell*habNumTot +i] = 0;
00116                   return (i+1); /* returns new hab, HAB[] is offset by 1 from these array IDs */
00117                 }
00118                 
00119  return hab;    
00120 }
00121 
00122 
00123 
00128 int InHab(float Var, struct HabData Params )
00129 {
00130   if ( (Var <= Params.Lhi || Params.Lhi >= MAX_SW) && Var >= Params.Llo ) 
00131           return 1;
00132   else return 0;
00133 }
00134 
00135 
00137 void alloc_hab_hist( void )
00138 {
00139   HabHist = (unsigned long *) nalloc(sizeof(unsigned long)*(s0+2)*(s1+2)*(habNumTot),"HabHist");
00140   init_pvar(HabHist,NULL,'i',0);
00141 }
00142 
00143 
00144  /**********************/
00145  

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