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

Go to the documentation of this file.
00001 /*
00002  *  HydroGlacial.c
00003  *
00004  *  Calculates the daily ice accumulation or melt.
00005  *  Also calculates the groundwater flow and time lag.
00006  *
00007  *  Author1:    M.D. Morehead   (Original:   June 1998)
00008  *  Author2:    A.J. Kettner    (november 2003)
00009  *
00010  *  Variable    Def.Location    Type    Units   Usage
00011  *  --------    ------------    ----    -----   -----
00012  *  Mgw         HydroGlacial.c  double m^3/a Annual mass of Ice discharge going to GW
00013  * Mice         HydroGlacial.c  double  m^3/a   Annual mass of Ice derived discharge
00014  * Minput       HydroGlacial.c  double  m^3/a   Annual mass input into the Glacial routine
00015  * Mout         HydroGlacial.c  double  m^3/a   Annual mass output from the Glacial routine
00016  * Mwrap        HydroGlacial.c  double  m^3/a   Annual mass of discharge carried over from the previous year
00017  * Parea        HydroGlacial.c  double  m^2     daily area over which "ice" precipitation occurs
00018  * Tcorrection  HydroGlacial.c  double  degC    Temperature correction to ice melt applied for days with rain
00019  * Tfix         HydroGlacial.c  double  degC    Temperature correction for cold years
00020  * approxarea   HydroGlacial.c  double  m^2     the elevation binned area for the glacier
00021  * elabin       HydroGlacial.c  double  -       the closest elevbin to the ela
00022  * elaerror     HydroGlacial.c  double  m       the height difference between the actual and binned ela
00023  * err          various         int     -       error flag, halts program
00024  * glacierind   HydroGlacial.c  int     -       the elevbin index at the toe of the glacier
00025  * ii           various         int     -       temporary loop counter
00026  * indx         HydroGlacial.c  int     -       temporary elevbin index
00027  * jj           various         int     -       temporary loop counter
00028  * kk           various         int     -       temporary loop counter
00029  * massavailable        HydroGlacial.c  double  m^3     total water available for E,Q and Gw=sum(ice balance+Precip)
00030  * maxmelt      HydroGlacial.c  double  degC    warmest melt day, used to prevent oversized floods
00031  * meltday[maxday]HydroGlacial.c        double  m^3     the amount of ice melt occuring on a given day
00032  * meltflag     HydroGlacial.c  int     -       flag to check for good ice melt years
00033  * shldday[maxday]HydroGlacial.c        double  m^3     the discharge going into shoulder events
00034  * smallgapprox HydroGlacial.c  double  m^2     binned glaciated area above the elabin
00035  * totalmelt    HydroGlacial.c  double  m^3     scale factor for distributing the melt events
00036  *
00037  */
00038 
00039 #include <stdlib.h>
00040 #include "hydroclimate.h"
00041 #include "hydroparams.h"
00042 #include "hydrotimeser.h"
00043 #include "hydroinout.h"
00044 #include "hydrodaysmonths.h"
00045 
00046 /*-------------------------
00047  *  Start of HydroGlacial
00048  *-------------------------*/
00049 int hydroglacial()
00050 {
00051 
00052 /*-------------------
00053  *  Local Variables
00054  *-------------------*/
00055 #ifdef DBG
00056 FILE *fid;
00057 #endif
00058 
00059 int err, ii, jj, kk, indx, glacierind, meltflag;
00060 int dumint;
00061 
00062 double elabin, elaerror, approxarea, Parea;
00063 double massavailable, maxmelt, meltday[maxday], shldday[maxday];
00064 double smallgapprox;
00065 double totalmelt, Tcorrection, Tfix, Mice, Mgw, Mout, Mwrap, Minput;
00066 double Tmean;
00067 double Volumelast, Volumeglacierarea;
00068 double lastareakm, glacierareakm;
00069 err = 0;
00070 glacierind = 0;
00071 elabin = 0.0;
00072 Tmean = 0.0;
00073 
00074 
00075 /*---------------------------------------------------------
00076  *  Approximate the ELA and glaciated area for the
00077  *  year prior to the model run.
00078  *  If (floodtry > 0) then keep that lastela and lastarea
00079  *  from the first time through
00080  ----------------------------------------------------------*/
00081 if (floodtry == 0) {
00082     if (ep == 0 && yr == syear[ep]) {
00083         /*----------------------------------------
00084          *  Find the closest elevbin to the ela;
00085          *  this may be above or below the ela
00086          *----------------------------------------*/
00087         if (ELAstart[ep] > maxalt[ep]) {
00088             lastela = ELAstart[ep] - ELAchange[ep];
00089             elaerror = 0.0;
00090             elabin = ELAstart[ep];
00091             ELAindex = 2*nelevbins;
00092             smallg = 0.0;
00093             bigg = 0.0;
00094             lastarea = 0.0;
00095         }
00096         else {
00097               lastela  = ELAstart[ep] - ELAchange[ep];
00098               elaerror = maxalt[ep];
00099               for (kk=0; kk<nelevbins; kk++)
00100                  if (fabs(lastela - elevbins[kk]) < elaerror) {
00101                    elabin = elevbins[kk];
00102                    ELAindex = kk;
00103                    elaerror = fabs(lastela - elevbins[kk]);
00104                  }
00105 
00106          /*-------------------------------------------------
00107           *  Calculate the glaciated area above the elabin
00108           *  by summing the areas above that point
00109           *-------------------------------------------------*/
00110          smallgapprox = 0.0;
00111          for (kk=ELAindex; kk<nelevbins; kk++)
00112               smallgapprox += areabins[kk];
00113 
00114          /*---------------------------------------------------
00115           *  Determine which bin the ela actually resides in
00116           *---------------------------------------------------*/
00117          if (elabin > lastela)
00118              indx = ELAindex - 1;
00119          else
00120              indx = ELAindex;
00121 
00122          /*--------------------------------------------
00123           *  Correct the area by linear interpolation
00124           *--------------------------------------------*/
00125          smallg = smallgapprox + areabins[indx]*(elabin-lastela)/elevbinsize;
00126 
00127          /*--------------------------------------------------------
00128           *     Calculate the glaciated area below the ela
00129           *     Assume area below ela = 35% of total area
00130           *     G = 0.35*Atotal  g = 0.65*Atotal        G = (0.35/0.65)*g
00131           *--------------------------------------------------------*/
00132          bigg = (0.35/0.65)*smallg;
00133 
00134          /*------------------------------------
00135           *  Find the estimate glaciated area
00136           *------------------------------------*/
00137          lastarea = smallg + bigg;
00138 
00139       } /* end if ELA > maxalt */
00140    }
00141 
00142  /*-----------------------------------------------------------------
00143   *  Keep last years Glaciated area for Mass Balance and Discharge
00144   *-----------------------------------------------------------------*/
00145         else {
00146                 if ( ep != 0 && yr == syear[ep] && setstartmeanQandQs == 0 ){
00147                         initiallastela = ela;
00148                         initiallastarea = glacierarea;
00149                         lastela  = ela;
00150                         lastarea = glacierarea;
00151                 }
00152                 else if (ep != 0 && yr == syear[ep] && setstartmeanQandQs > 0 ){
00153                         lastela = initiallastela;
00154                         lastarea = initiallastarea;
00155                 }
00156                 else if (yr != syear[ep]){
00157                         lastela  = ela;
00158                         lastarea = glacierarea;
00159                 }
00160    }
00161 }       /* endif floodtry==0 */
00162 
00163 /*-------------------------
00164  *  Calculate the new ELA
00165  *-------------------------*/
00166 ela = ELAstart[ep] + ELAchange[ep]*((yr-syear[ep]));
00167 
00168 /*-------------------------------------
00169  *  Simulate a basin with NO glaciers
00170  *-------------------------------------*/
00171 if (ela > maxalt[ep]) {
00172     if (lastela < maxalt[ep]) {
00173         fprintf(stderr, "\nHydroGlacial WARNING: epoch = %d, year = %d \n", ep+1, yr );
00174         fprintf(stderr, "   The Glacier completely melted. \n");
00175         fprintf(stderr, "   This has not been accounted for yet. \n");
00176         fprintf(stderr, "   There will be a mass balance error for \n");
00177         fprintf(stderr, "   the remaining part of the glacier. \n");
00178     }
00179     glacierelev = maxalt[ep]+elevbinsize;  /* make sure it is above the basin */
00180     glacierarea = 0.0;
00181     approxarea = 0.0;
00182     bigg = 0.0;
00183     smallg = 0.0;
00184     smallgapprox = 0.0;
00185 }
00186 
00187 /*----------------------------------
00188  *  Simulate a basin with glaciers
00189  *----------------------------------*/
00190 else {
00191     for (ii=0; ii<maxday; ii++) {
00192         meltday[ii] = 0.0;
00193         shldday[ii] = 0.0;
00194     }
00195 
00196     /*----------------------------------------
00197      *  Find the closest elevbin to the ela;
00198      *  this may be above or below the ela
00199      *----------------------------------------*/
00200     elaerror = maxalt[ep];
00201     for (kk=0; kk<nelevbins; kk++)
00202         if (fabs(ela - elevbins[kk]) < elaerror) {
00203             elabin = elevbins[kk];
00204             ELAindex = kk;
00205             elaerror = fabs(ela - elevbins[kk]);
00206         }
00207 
00208    /*--------------------------------------------------
00209     *    Calculate the glaciated area above the elabin
00210     *    by summing the areas above that point
00211     *--------------------------------------------------*/
00212    smallgapprox = 0.0;
00213    for (kk=ELAindex; kk<nelevbins; kk++)
00214        smallgapprox += areabins[kk];
00215 
00216    /*---------------------------------------------------
00217     *  Determine which bin the ela actually resides in
00218     *---------------------------------------------------*/
00219    if (elabin > ela)
00220        indx = ELAindex - 1;
00221    else
00222        indx = ELAindex;
00223 
00224    /*--------------------------------------------
00225     *  Correct the area by linear interpolation
00226     *--------------------------------------------*/
00227    smallg = smallgapprox + areabins[indx]*(elabin-ela)/elevbinsize;
00228         
00229    /*--------------------------------------------------------
00230     *    Calculate the glaciated area below the ela
00231     *    Assume area below ela = 35% of total area
00232     *    G = 0.35*Atotal         g = 0.65*Atotal        G = (0.35/0.65)*g
00233     *--------------------------------------------------------*/
00234    bigg = (0.35/0.65)*smallg;
00235 
00236    /*--------------------------------------------------
00237     *  Find the actual glaciated area (glacierarea)
00238     *  and elevation of the glacier toe (glacierelev)
00239     *  and glacierelev's elevbins index (glacierind)
00240     *--------------------------------------------------*/
00241    glacierarea = smallg + bigg;
00242    approxarea = 0.0;
00243    kk = nelevbins-1;
00244    while (approxarea <= glacierarea) {
00245        approxarea += areabins[kk];
00246        glacierelev = elevbins[kk];
00247        glacierind = kk;
00248        kk--;
00249    }
00250 
00251    /*---------------------------------------------------------------------------
00252     *  Sum the Precip which is above BOTH:
00253     *   i) the ELA
00254     *   ii) the Freezing line altitude (FLAindex)
00255     *
00256     *   if( FLAindex == FLAflag ) then no T<0 occured on that day at any elev.
00257     *---------------------------------------------------------------------------*/
00258    MPglacial = 0.0;   
00259    for (ii=0; ii<daysiy; ii++) {
00260         /*  Find area above the ELA */
00261         if( FLAindex[ii] < ELAindex )
00262             Parea = smallgapprox;
00263         /* Find area above the FLA */
00264         else if( FLAindex[ii] < FLAflag ) {
00265             Parea = 0.0;
00266             for (kk=nelevbins-1; kk>=FLAindex[ii]; kk-- )
00267                  Parea += areabins[kk];
00268         }
00269         else{
00270          Parea = 0.0;                           /* FLA is above the basin */
00271         }
00272         MPglacial += Pdaily[ii]*Parea;
00273    }
00274 
00275    /*---------------------------------------------------------
00276     *  Track the actual changes in glacier mass so there are
00277     *  no step changes in mass between years
00278     *---------------------------------------------------------*/
00279         if (glacierarea < lastarea){
00280                 lastareakm =(lastarea/1e6);
00281                 glacierareakm =(glacierarea/1e6);
00282                 Volumelast = bethaglacier * pow(lastareakm,bethaexpo);
00283                 Volumeglacierarea = bethaglacier * pow (glacierareakm,bethaexpo);
00284                 Gmass = ((Volumelast*1e6) - (Volumeglacierarea*1e6));   
00285         }
00286         else
00287                 Gmass = 0.0;
00288         
00289    /*--------------------------------------------------------
00290     *  Calculate the total water available for E, Q, and Gw
00291     *  = sum( ice balance + Precip in )
00292     *--------------------------------------------------------*/
00293    massavailable = Gmass + MPglacial;
00294 
00295    /*-------------------------------------------------------
00296     *  Check if there is sufficient mass to grow a glacier
00297     *-------------------------------------------------------*/
00298         if( massavailable < 0.0 ) {
00299                 fprintf( stderr, "HydroGlacial ERROR: year = %d, ep =%d \n", yr, ep );
00300                 fprintf( stderr, " \t There is insufficient precipitation on the \n" );
00301                 fprintf( stderr, " \t glaciated area to grow the glacier at the \n" );
00302                 fprintf( stderr, " \t prescribed rate. \n" );
00303                 fprintf( stderr, " \t massavailable < 0.0 \n" );
00304                 fprintf( stderr, " \t massavailable = Gmass + MPglacial \n" );
00305                 fprintf( stderr, " \t massavailable \t = %e \n", massavailable );
00306                 fprintf( stderr, " \t Gmass \t = %e (m^3) \n", Gmass );
00307                 fprintf( stderr, " \t MPglacial  \t = %e (m^3) \n", MPglacial );
00308                 fprintf( stderr, " \t Gmass = (lastarea-glacierarea)*fabs(lastela-ela) \n" );
00309                 fprintf( stderr, " \t lastarea   \t = %e (m^2) \n", lastarea );
00310                 fprintf( stderr, " \t glacierarea\t = %e (m^2) \n", glacierarea );
00311                 fprintf( stderr, " \t lastela    \t = %e  \n", lastela );
00312                 fprintf( stderr, " \t ela        \t = %e  \n", ela );
00313                 fprintf( stderr, " \t Parea       \t = %e  \n", Parea);
00314                 fprintf( stderr, " \t ELAstart[ep]      \t = %e  \n", ELAstart[ep]);
00315                 fprintf( stderr, " \t ELAchange[ep]      \t = %e  \n", ELAchange[ep]);
00316                 fprintf( stderr, " \t setstartmeanQandQs  \t = %d \n", setstartmeanQandQs);
00317                 exit(-1);
00318         }
00319 
00320    /*-----------------------------------------------------------------------
00321     *  Calculate the amount of ice lost to evaporation
00322     *  divide by the glaciated area, to get units of m of water equivelant
00323     *-----------------------------------------------------------------------*/
00324    Eiceannual = massavailable*dryevap[ep]/glacierarea;
00325 
00326    /*------------------------------------------------------------------
00327     *  Loop through the year and determine the melt days
00328     *  scale each event by the Temperature and Precip
00329     *  Later the scaled days will be assigned the appropriate
00330     *  amount of runoff
00331     *
00332     *  Also check to insure that we melt enough ice, and do not flood
00333     *  the basin.  Note that meltday will be scaled down further
00334     *  by the shoulder events.
00335     *
00336     *  The ranarray factor will add some randomness to the events
00337     *  ranarry has a mean of zero and std of 1
00338     *------------------------------------------------------------------*/
00339    meltflag = 1;
00340    maxmelt = 0.0;
00341    Tfix = 0.0;
00342         while( meltflag == 1 ) {
00343                 totalmelt = 0.0;
00344                 for( ii=0; ii<daysiy; ii++ ) {
00345                         Tcorrection = 0.0;
00346                         if( Pdaily[ii] > 0.0 )
00347                                 Tcorrection = 1.0;
00348                         if( Televday[glacierind][ii]+Tfix > 0.0 ) {
00349                                 meltday[ii]=mx(Televday[glacierind][ii]+ranarray[nran]-Tcorrection+Tfix,0.0);
00350                                 nran++;
00351                                 totalmelt += meltday[ii];
00352                                 maxmelt = mx( meltday[ii], maxmelt );
00353                         }
00354                 }
00355                 if (totalmelt == 0.0 ) {
00356                         Tmean = 0.0;
00357 //                      for (ii=daystrm[5]; ii<dayendm[7]; ii++ )
00358                         for (ii=start_of(Jun); ii<end_of(Aug); ii++ )
00359                                 Tmean += Televday[glacierind][ii];
00360 //                      Tmean/=(dayendm[7]-daystrm[5]);
00361                         Tmean/=(end_of(Aug)-start_of(Jun));
00362                         Tfix += mx( -Tmean, 1.0 );      
00363                 }
00364                 else
00365                         meltflag = 0;
00366         }
00367         
00368         if (Tfix > 0.0) {
00369                 fprintf( stderr, "\n HydroGlacial Warning: epoch = %d, year = %d \n", ep+1, yr );
00370                 fprintf( stderr, " \t The basin was too cold to melt enough glacial ice. \n" );
00371                 fprintf( stderr, " \t The daily temperatures used to melt ice were increased. \n" );
00372                 fprintf( stderr, " \t Tfix = %f (degC) \n", Tfix );
00373                 fprintf( stderr, " \t Tmean = %f (degC) \n", Tmean );
00374                 fprintf( fidlog, " HydroGlacial Warning: \n" );
00375                 fprintf( fidlog, " \t The basin was too cold to melt enough glacial ice. \n" );
00376                 fprintf( fidlog, " \t The daily temperatures used to melt ice were increased. \n" );
00377                 fprintf( fidlog, " \t Tfix = %f (degC) \n", Tfix );
00378                 fprintf( fidlog, " \t Tmean = %f (degC) \n", Tmean );
00379         }       
00380 
00381    /*---------------------------------------------------------------------------
00382     *  Create the shoulder events (Murray's version of flood wave attenuation)
00383     *  there is one left (preceeding) day scaled as:
00384     *   shoulderleft*event
00385     *  the main event is scaled down to:
00386     *   shouldermain*event
00387     *  there are 1 or more right (following days) scaled to:
00388     *   shoulderright[]*event
00389     *  1.0 = Sum(shoulderleft+shouldermain+shoulderright[])
00390     *---------------------------------------------------------------------------*/
00391    ii = 0;
00392    if (meltday[ii] > 0.0) {
00393        shldday[ii] += shoulderleft*meltday[ii];
00394        for (jj=0; jj<shouldern-2; jj++)
00395             shldday[ii+jj+1] += shoulderright[jj]*meltday[ii];
00396        meltday[ii] = shouldermain*meltday[ii];
00397    }
00398 
00399    for (ii=1; ii<daysiy; ii++){
00400                 Qice[ii-1] = 0.0;
00401                 Qice[ii] = 0.0;
00402         if (meltday[ii] > 0.0) {
00403               shldday[ii-1] += shoulderleft*meltday[ii];
00404               for (jj=0; jj<shouldern-2; jj++)
00405                 shldday[ii+jj+1] += shoulderright[jj]*meltday[ii];
00406               meltday[ii] = shouldermain*meltday[ii];
00407         }
00408    }
00409 
00410    /*-----------------------------------------------------------
00411     *    Add the shoulder events and the main events
00412     *    to get the total ice derived discharge.
00413     *    Also scale the discharges to match the actual ice melt.
00414     *    Convert to m^3/s
00415     *-----------------------------------------------------------*/
00416    for (ii=0; ii<maxday-distbins[ELAindex]; ii++) {
00417 
00418       /*---------------------------------------------------------------------
00419        *  (Mark's version of routing)
00420        *  Add the time lag for the distance up the basin (distbins[elabin])
00421        *  Convert to m^3/s
00422        *---------------------------------------------------------------------*/
00423       dumint = distbins[ELAindex];
00424       Qice[ ii+dumint ] += (meltday[ii]+shldday[ii])
00425                                 *(massavailable-Eiceannual*glacierarea)
00426                                 /(totalmelt*dTOs);
00427    }
00428 
00429    /*---------------------------------------
00430     *  Add the carryover from the previous
00431     *  year and track it's mass
00432     *---------------------------------------*/
00433    Mwrap = 0.0;
00434    for (ii=0; ii<maxday-daysiy; ii++) {
00435        Qice[ii] += Qicewrap[ii];
00436        Mwrap += Qicewrap[ii]*dTOs;
00437    }
00438 
00439    /*---------------------------------------------------------
00440     *  Add to the flux to the Groundwater pool
00441     *  Actual addition to the GW pool is done in HydroRain.c
00442     *---------------------------------------------------------*/
00443    for (ii=0; ii<daysiy; ii++) {
00444        Qicetogw[ii] += percentgw[ep]*Qice[ii];
00445        Qice[ii]     -= Qicetogw[ii];
00446    }
00447 
00448    /*--------------------------
00449     *  Check the mass balance
00450     *--------------------------*/
00451    Mice = 0.0;
00452    Mgw  = 0.0;
00453    for (ii=0; ii<maxday; ii++)
00454        Mice += Qice[ii]*dTOs;
00455    for (ii=0; ii<daysiy; ii++)
00456        Mgw  += Qicetogw[ii]*dTOs;
00457 
00458    Mout = Mice + Mgw + Eiceannual*glacierarea;
00459    Minput = massavailable + Mwrap;
00460    if ( (fabs(Mout-Minput)/Minput) > masscheck ) {
00461        fprintf( stderr, "ERROR in HydroGlacial: \n");
00462        fprintf( stderr, "  Mass Balance error: Mout != Minput \n\n");
00463        fprintf( stderr, "\t fabs(Mout-Minput)/Minput > masscheck \n" );
00464        fprintf( stderr, "\t note: masscheck set in HydroParams.h \n" );
00465        fprintf( stderr, "\t masscheck = %f (%%) \n", masscheck );
00466        fprintf( stderr, "\t fabs(Mout-Minput)/Minput = %f (%%) \n\n", fabs(Mout-Minput)/Minput );
00467        fprintf( stderr, " \t Minput = massavailable + Mwrap \n" );
00468        fprintf( stderr, " \t Minput \t\t = %e \n", Minput );
00469        fprintf( stderr, " \t massavailable \t = %e \n", massavailable );
00470        fprintf( stderr, " \t Mwrap \t\t = %e \n\n", Mwrap );
00471        fprintf( stderr, " \t Mout = Mice + Mgw + Eiceannual*glacierarea \n" );
00472        fprintf( stderr, " \t Mout \t\t = %e \n", Mout );
00473        fprintf( stderr, " \t Mice \t\t = %e \n", Mice );
00474        fprintf( stderr, " \t Mgw \t\t = %e \n", Mgw );
00475        fprintf( stderr, " \t Eiceannual \t = %e \n\n", Eiceannual*glacierarea );
00476        exit(-1);
00477    }
00478 
00479 }   /* endif glacial */
00480 
00481 #if DBG
00482    fprintf( fidlog,"\n HydroGlacial: \t year = %d \n\n", yr );
00483 
00484    fprintf( fidlog," \t Mass Wrap \t = %e (m^3) \n\n", Mwrap );
00485 
00486    fprintf( fidlog," \t ela \t\t = %f (m) \n", ela );
00487    fprintf( fidlog," \t elabin \t = %f (m) \n", elabin );
00488    fprintf( fidlog," \t elevbinsize \t = %f (m) \n\n", elevbinsize );
00489 
00490    fprintf( fidlog," \t maxalt[ep] \t = %f (m) \n", maxalt[ep] );
00491    fprintf( fidlog," \t glacierelev \t = %f (m) \n\n", glacierelev );
00492 
00493    fprintf( fidlog," \t smallg \t = %e (m^2) \n", smallg );
00494    fprintf( fidlog," \t bigg \t\t = %e (m^2) \n", bigg );
00495    fprintf( fidlog," \t glacierarea \t = %e (m^2) \n", glacierarea );
00496    fprintf( fidlog," \t approxarea \t = %e (m^2) \n\n", approxarea );
00497 
00498    fprintf( fidlog," \t ela \t\t = %f (m) \n", ela );
00499    fprintf( fidlog," \t lastela \t = %f (m) \n", lastela );
00500    fprintf( fidlog," \t diff(ela) \t = %f (m) \n\n", fabs(lastela-ela) );
00501 
00502    fprintf( fidlog," \t lastarea \t = %e (m^2) \n", lastarea );
00503    fprintf( fidlog," \t glacierarea \t = %e (m^2) \n", glacierarea );
00504    fprintf( fidlog," \t diff(area) \t = %e (m^2) \n\n", lastarea-glacierarea );
00505 
00506    fprintf( fidlog," \t MPglacial \t = %e (m^3) \n", MPglacial );
00507    fprintf( fidlog," \t GMass \t\t = %e (m^3) \n", Gmass );
00508    fprintf( fidlog," \t Mass available\t = %e (m^3) \n\n", massavailable );
00509 
00510    fprintf( fidlog, " \t Mout \t\t = %e \n", Mout );
00511    fprintf( fidlog, " \t Mout = Mice + Mgw + Eiceannual*glacierarea \n" );
00512    fprintf( fidlog, " \t Mice \t\t = %e \n", Mice );
00513    fprintf( fidlog, " \t Mgw \t\t = %e \n", Mgw );
00514    fprintf( fidlog, " \t Eiceannual \t = %e \n", Eiceannual*glacierarea );
00515 
00516   /*----------------------------------------------------------------------------
00517    *  Print out glacial Q for error checking.
00518    *  The % at the begining of each text line is for a comment line in matlab.
00519    *  This enables the file to be read directly into matlab for plotting.
00520    *----------------------------------------------------------------------------*/
00521   if( tblstart[ep] <= yr && yr <= tblend[ep] ) {
00522     if( (fid = fopen("hydro.ice","a+")) == NULL) {
00523       printf("  HydroGlacial ERROR: Unable to open the Qice file hydro.ice \n");
00524       printf("     non-fatal error, continueing. \n\n");
00525     }
00526     else {
00527         fprintf( fid,"%%\n%%\n%% HydroGlacial output: \n%%\n" );
00528         fprintf( fid,"%%Daily predicted Qice for epoch %d \n%%\n", ep+1 );
00529         fprintf( fid,"%%Year \t Day \t Qice(m^3/s) \t Qicetogw(m^3/s) \n" );
00530         fprintf( fid,"%%---- \t --- \t ----------- \t ------------ \n" );
00531         for(ii=0; ii<daysiy; ii++ )
00532            fprintf( fid,"%d \t %d \t %f \t %f \n", yr, ii+1, Qice[ii], Qicetogw[ii] );
00533         for(ii=daysiy; ii<maxday; ii++ )
00534            fprintf( fid,"%d \t %d \t %f \t NaN \n", yr, ii+1, Qice[ii] );
00535         fclose(fid);
00536     }
00537   }
00538 #endif
00539 
00540 return(err);
00541 }  /* end of HydroGlacial */

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