/Users/huttone/Devel/sedflux-new/sedflux/trunk/ew/hydrotrend/hydroclimate.c

Go to the documentation of this file.
00001 /*
00002  *  HydroClimate.c
00003  *
00004  *  Sets the annual climate values of P and T using
00005  *  the starting values, the trends and the Std. Dev.
00006  *  The climate values are assumed to be at the river
00007  *  mouth. The lapse rate is used later to calculate
00008  *  the temperature for each altitude bin.
00009  *
00010  *  Author:     M.D. Morehead   (June 1998)
00011  *  Author2:    S.D. Peckham    (December 2001)
00012  *  Author3:    A.J. Kettner    (November 2002 - January 2003)
00013  *
00014  *  Variable    Def.Location    Type    Units   Usage
00015  *  --------    ------------    ----    -----   -----
00016  *  err                 various                 int             -               error flag, halts program
00017  *  jj                  various                 int             -               temporary loop counter
00018  *  dumdbl              various                 double  -               temporary double
00019  *  sumt                HydroClimate.c  double  -               total temperature
00020  *  sump                HydroClimate.c  double  -               total precipitation
00021  *
00022  */
00023 
00024 #include "hydroclimate.h"
00025 #include "hydrotimeser.h"
00026 #include "hydroinout.h"
00027 #include "hydroparams.h"
00028 #include "hydroreadclimate.h"
00029 #include "hydrodaysmonths.h"
00030 
00031 /*-------------------------
00032  *  Start of HydroClimate
00033  *-------------------------*/
00034 int hydroclimate(gw_rainfall_etc* gw_rain)
00035 {
00036 /*-------------------
00037  *  Local Variables
00038  *-------------------*/
00039 int err, jj, ii;
00040 double dumdbl, sumt, sump;
00041 err = 0;
00042 
00043 /*----------------------------------------
00044  *  Calculate Average Annual Temperature
00045  *  Either by file or by climate generator.
00046  *----------------------------------------*/
00047 Tannual = 0.0;
00048 if ( raindatafile == 1)
00049             Tannual =gw_rain->Tperyear[yr];
00050 else{
00051         dumdbl = ranarray[nran];
00052         nran++;
00053         if (dumdbl >  Tmaxstd)
00054                 dumdbl =  Tmaxstd;
00055         if (dumdbl < -Tmaxstd)
00056                 dumdbl = -Tmaxstd;
00057         Tannual = Tstart[ep] + Tchange[ep]*(yr-syear[ep]) + dumdbl*Tstd[ep];
00058 }
00059 
00060 /*------------------------------------------
00061  *  Calculate Average Monthly Temperatures
00062  *  and scale to actual annual temperature.
00063  *  Either by file or by climate generator.
00064  *------------------------------------------*/
00065 if ( raindatafile == 1)
00066 //      for (jj=0; jj<12; jj++){
00067         for (jj=Jan; jj<=Dec; jj++){
00068                 Tmonth[jj] = 0.0;
00069 //              for( ii=daystrm[jj]-1; ii<dayendm[jj]; ii++ )
00070                 for( ii=start_of(jj)-1; ii<end_of(jj); ii++ )
00071                     Tmonth[jj] += gw_rain->T[yr-syear[ep]][ii];
00072 //              Tmonth[jj] = (Tmonth[jj]/daysim[jj]);
00073                 Tmonth[jj] = (Tmonth[jj]/days_in_month(jj));
00074         }
00075 else{
00076         sumt = 0.0;
00077 //      for (jj=0; jj<12; jj++)
00078         for (jj=Jan; jj<=Dec; jj++)
00079                 sumt += Tnominal[jj][ep] * days_in_month(jj);
00080 //      for (jj=0; jj<12; jj++)
00081         for (jj=Jan; jj<=Dec; jj++)
00082                 Tmonth[jj] = Tnominal[jj][ep] - (sumt/daysiy) + Tannual;
00083 }
00084 
00085 /*--------------------------------------------
00086  *  Calculate Total Annual Precipitation (m)
00087  *  Either by file or by climate generator. 
00088  *--------------------------------------------*/
00089 Pannual = 0.0;
00090 if ( raindatafile == 1)
00091         for (ii=0; ii < daysiy; ii++)
00092             Pannual +=gw_rain->R[yr-syear[ep]][ii];
00093 else {
00094         dumdbl = ranarray[nran];    /* Get one random value. */
00095     nran++;
00096     if (dumdbl >  Pmaxstd)
00097         dumdbl =  Pmaxstd;
00098     if (dumdbl < -Pmaxstd)
00099         dumdbl = -Pmaxstd;
00100     Pannual = Pmassbal[ep]*Pstart[ep] + Pchange[ep]*(yr-syear[ep]) + dumdbl*Pstd[ep];
00101     if (Pannual < 0)
00102         Pannual = 0.;
00103 }
00104 
00105 /*----------------------------------------------------
00106  *  Calculate Total Monthly Precipitation and
00107  *  scale to actual annual precipitation
00108  *  Pmonth (m/mnth)= (m/mth) * ((m/y-m/y) / (m/y))
00109  *  Either by file or by climate generator.
00110  *----------------------------------------------------*/
00111 if ( raindatafile == 1)
00112 //      for (jj=0; jj<12; jj++){
00113         for (jj=Jan; jj<=Dec; jj++){
00114                 Pmonth[jj] = 0.0;
00115 //              for( ii=daystrm[jj]-1; ii<dayendm[jj]; ii++ )
00116                 for( ii=start_of(jj)-1; ii<end_of(jj); ii++ )
00117                     Pmonth[jj] += gw_rain->R[yr-syear[ep]][ii];  
00118         }               
00119 else{
00120     sump = 0.0;
00121         for (jj=0; jj<12; jj++)
00122         sump += Pnominal[jj][ep];
00123         for (jj=0; jj<12; jj++)
00124         Pmonth[jj] = Pnominal[jj][ep] * (Pannual/sump);
00125 }
00126 
00127 /*------------------------------------------
00128  *  Write out debug information if desired
00129  *------------------------------------------*/
00130 #ifdef DBG
00131    fprintf( fidlog," HydroClimate: \t year = %d \t Pannual = %7f \t Tannual = %7f \n",yr,Pannual,Tannual);
00132    if (tblstart[ep] <= yr && yr <= tblend[ep]) {
00133        for (jj=0; jj<12; jj++ )
00134            fprintf( fidlog," \t month = %d \t P = %7f \t T = %7f \n",jj+1,Pmonth[jj],Tmonth[jj]);
00135    }
00136    fprintf( fidlog,"\n" );
00137 #endif
00138 
00139 return(err);
00140 }  /* end of HydroClimate */

Generated on Fri Jan 4 18:04:14 2008 for sedflux by  doxygen 1.5.2