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

Go to the documentation of this file.
00001 /*
00002  *  HydroShoulder.c
00003 
00004  *  Calculates the flood wave shoulder parameters.
00005  *  The shoulder's simulate the dispersion of a flood
00006  *  wave as it propagates down channel.
00007  *
00008  *  Author:    M. Nicholson in river.f
00009  *  Modified:  M.D. Morehead for HydroTrend.c
00010  *  Original:  Jan 1999
00011  *
00012  * Variable             Def.Location    Type    Units   Usage
00013  * --------             ------------    ----    -----   -----
00014  * err                  various                 int             -               errorflag, halts program
00015  * daysum               HydroShoulder.c double  -               used for shoulder event calculation
00016  * diff12               HydroShoulder.c double  -               used for shoulder event calculation
00017  * dumdbl               various                 double  -               temporary double
00018  * jj                   various                 int             -               temporary loop counter
00019  * dayoffset    HydroShoulder.c double  -               used for shoulder event calculation
00020  * leftpercent  HydroShoulder.c double  -               used for shoulder event calculation
00021  * maxpercent   HydroShoulder.c double  -               used for shoulder event calculation
00022  *
00023  */
00024 
00025 #include <math.h>
00026 
00027 #include "hydroclimate.h"
00028 #include "hydroparams.h"
00029 
00030 #ifdef DBG
00031 #include "hydroinout.h"
00032 #endif
00033 
00034 /*--------------------------
00035  *  Start of HydroShoulder
00036  *--------------------------*/
00037 int hydroshoulder()
00038 {
00039 
00040 /*-------------------
00041  *  Local Variables
00042  *-------------------*/
00043 int err, jj;
00044 double  diff12, daysum, dumdbl;
00045 double  dayoffset, leftpercent, maxpercent;
00046 
00047 err = 0;
00048 
00049 /*--------------------------------------------------------------------
00050  *  Set the Shoulder parameters
00051  *
00052  *  dayoffset is the minimum number of days to spread the event over
00053  *  leftpercent is a scaled version of how much goes to the day
00054  *    prior to the main event (if dayoffset = 3)
00055  *  maxpercent is a scaled values of how much goes to the main event
00056  *
00057  *  should.m is a matlab script that can be used to investigate how
00058  *  this function works.
00059  *
00060  *  NOTE: some values will cause negative flows!!!
00061  *
00062  *  Original values from Murray Nicholson are:
00063  *    dayoffset = 3.0;
00064  *    leftpercent       = 0.4;
00065  *    maxpercent        = 1.0;
00066  *--------------------------------------------------------------------*/
00067 dayoffset       = 3.0;
00068 leftpercent     = 0.65;
00069 maxpercent      = 0.7;
00070 
00071 /*-------------------------------------------------------------
00072  *  Calculate the event shoulder numbers
00073  *  These depend on variables that only change with the epoch
00074  *  Might move this into a subroutine
00075  *-------------------------------------------------------------*/
00076 for( jj=0; jj<maxshoulder; jj++ )
00077    shoulderright[jj] = 0.0;
00078 
00079 /*----------------------------------------------------------------
00080  *  Compute the number of days required for a flow to travel the
00081  *  length of the basin, set 3 as the minimum
00082  *----------------------------------------------------------------*/
00083 shouldern = mx( (int)( basinlength[ep]/(avgvel[ep]*dTOs) ), 3 );
00084 
00085 /*------------------------------------------------------------
00086  *  account for lag due the % of the drainage basin as lakes
00087  *    if( Rvol > 0.0 && < 0.5 ) shouldern += 1
00088  *    if( Rvol >= 0.5 ) shouldern += 2
00089  *------------------------------------------------------------*/
00090 if (Rvol[ep] > 0.0 && Rvol[ep] < 0.5)
00091         shouldern += (int)floor(.4*3.3333);
00092 if (Rvol[ep] >= 0.5)
00093         shouldern += (int)floor(.8*3.3333);
00094         
00095 /*-------------------------------------------------
00096  *  assign percentage values to modulate the flow
00097  *-------------------------------------------------*/
00098 shoulderleft = sin(PI/((double)shouldern + dayoffset)) * leftpercent;
00099 shouldermain = sin(PI/((double)shouldern + dayoffset)) * maxpercent;
00100 diff12 = 1.00 - (shouldermain + shoulderleft);
00101 
00102 daysum = 0;
00103 for( jj=1; jj<shouldern-1; jj++ )
00104    daysum += jj;
00105 for( jj=0; jj<shouldern-2; jj++ )
00106    shoulderright[jj] = diff12 * (double)((shouldern-2-jj)/daysum);
00107 
00108 #ifdef DBG
00109    fprintf( fidlog,"\t HydroShoulder: \n" );
00110    fprintf( fidlog,"\t\t dayoffset     = %f \n", dayoffset );
00111    fprintf( fidlog,"\t\t leftpercent   = %f \n", leftpercent );
00112    fprintf( fidlog,"\t\t maxpercent    = %f \n", maxpercent );
00113    fprintf( fidlog,"\t\t shouldern     = %d \n", shouldern );
00114    fprintf( fidlog,"\t\t shoulderleft  = %f \n", shoulderleft );
00115    fprintf( fidlog,"\t\t shouldermain  = %f \n", shouldermain );
00116    for( jj=0; jj<shouldern-2; jj++ )
00117       fprintf( fidlog,"\t\t shoulderright[jj]  = %f \n", shoulderright[jj] );
00118 #endif
00119 
00120 /*-----------------------------------------------------
00121  *  Sum the shoulder values to insure they add to one
00122  *-----------------------------------------------------*/
00123 dumdbl = 0.0;
00124 for( jj=0; jj<shouldern-2; jj++ )
00125    dumdbl += shoulderright[jj];
00126 dumdbl += shoulderleft + shouldermain;
00127 if( fabs(dumdbl-1.0) > 0.000001 ) {
00128    fprintf( stderr, "ERROR in HydroShoulder.c: \n");
00129    fprintf( stderr, "   The shoulder events do not sum to 1.0 \n");
00130    fprintf( stderr, "   sum(shoulder) = %f \n", dumdbl );
00131    fprintf( stderr, "   shoulderleft  = %f \n", shoulderleft );
00132    fprintf( stderr, "   shouldermain  = %f \n", shouldermain );
00133    for( jj=0; jj<shouldern-2; jj++ )
00134       fprintf( stderr, "   shoulderright[jj] = %f \n", shoulderright[jj] );
00135    err = 1;
00136 }
00137 
00138 return(err);
00139 }       /* end of HydroShoulder.c */
00140 

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