Everglades Landscape Model (ELM) Home Page
Main Page | Data Structures | Directories | File List | Data Fields | Globals

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         
00016 */
00017 
00018 #include "success.h"
00019 
00020 
00023 void HabSwitch_Init(void)
00024 {
00025   int ii;
00026   
00027         /* put these habitat-specific parameters into a concise data struct for use here */
00028   for( ii = 0; ii < habNumTot; ii++) {
00029         Habi[ii].Water.Llo = HP_SfDepthLo[ii+1];
00030         Habi[ii].Water.Lhi = HP_SfDepthHi[ii+1];
00031         Habi[ii].Water.Pin = HP_SfDepthInt[ii+1];
00032         Habi[ii].Nutrient.Llo = HP_PhosLo[ii+1];
00033         Habi[ii].Nutrient.Lhi = HP_PhosHi[ii+1];
00034         Habi[ii].Nutrient.Pin = HP_PhosInt[ii+1];
00035         Habi[ii].PFin = HP_FireInt[ii+1];
00036   }
00037    
00038    alloc_hab_hist( );
00039    sprintf (msgStr, "Succession ON, module OK for %d habitats...", ii ); usrErr(msgStr); WriteMsg(msgStr,1);
00040 
00041    return; 
00042 }
00043 
00044 
00060 unsigned char HabSwitch(int ix, int iy, float *Water, float *Nutrient, int *Fire, unsigned char *HAB)
00061 {
00062  int StateW, StateN, i;
00063  int HabW[MAX_NHAB], HabN[MAX_NHAB], DW, DN;
00064  int cell =  T(ix,iy);
00065  int hab = HAB[cell];   /* current habitat in the cell */
00066 
00067  /* define the habitat type that matches the existing water conditions */
00068  
00069  /* HabHist is an array of integers : nnNssS, where nn are the two digits for the number of
00070         weeks being in the nutrient favorable conditions, N the number of days in those conditions 
00071         during the current week; similarly ss are the two digits for the number of weeks in the
00072         water level favorable conditions and S is the number of days during the current week in
00073         that state. The switching occurs when both of these histories exceed the habitat specific 
00074         periods  Pin.
00075  */
00076  for ( i = 0; i < habNumTot; i++ )
00077         {
00078          DW = HabHist[cell*habNumTot +i]%10;
00079          HabW[i] = (HabHist[cell*habNumTot +i]/10)%100;
00080          DN = (HabHist[cell*habNumTot +i]/1000)%10;
00081          HabN[i] = HabHist[cell*habNumTot +i]/10000;
00082          
00083          /* when the averaging time elapses, if #favorable days exceeds a threshold (using 4 for 7 day AV_PER), increment the period (weeks) history */
00084          if ((int)SimTime.TIME%AV_PER == 0)
00085            { 
00086                 if (DW > SW_TIME_TH_W) HabHist[cell*habNumTot +i] = HabHist[cell*habNumTot +i] - DW + 100;
00087                 else HabHist[cell*habNumTot +i] = 0;
00088                 if (DN > SW_TIME_TH_N) HabHist[cell*habNumTot +i] = HabHist[cell*habNumTot +i] - DN*1000 + 10000;
00089                 else HabHist[cell*habNumTot +i] = 0;
00090            }    
00091 
00092         /* check what habitat type the existing conditions match; increment the day# if conditions are favorable */
00093          if ( InHab (Water[cell], Habi[i].Water) )  HabHist[cell*habNumTot + i]++;
00094          if ( InHab (Nutrient[cell]*conv_kgTOmg, Habi[i].Nutrient) )  
00095                         HabHist[cell*habNumTot + i] = HabHist[cell*habNumTot + i] + 1000;
00096         } 
00097    
00098          /* check if the historical conditions for switching hold */
00099  for ( i = 0; i < habNumTot; i++ )  
00100         if ( HabW[i] >= Habi[i].Water.Pin && HabN[i] >= Habi[i].Nutrient.Pin ) 
00101                 { HabHist[cell*habNumTot +i] = 0;
00102                   return (i+1); /* returns new hab, HAB[] is offset by 1 from these array IDs */
00103                 }
00104                 
00105  return hab;    
00106 }
00107 
00112 int InHab(float Var, struct HabData Params )
00113 {
00114   if ( (Var <= Params.Lhi || Params.Lhi >= MAX_SW) && Var >= Params.Llo ) 
00115           return 1;
00116   else return 0;
00117 }
00118 
00119 
00121 void alloc_hab_hist( void )
00122 {
00123   HabHist = (unsigned long *) nalloc(sizeof(unsigned long)*(s0+2)*(s1+2)*(habNumTot),"HabHist");
00124   init_pvar(HabHist,NULL,'i',0);
00125 }
00126 
00127 
00128  /**********************/
00129  

Generated on Thu Jul 6 11:17:49 2006 for ELM source code by  doxygen 1.3.9.1