*--------------------------------*/ int hydrooutletfraction (int x) { /*------------------- * Local Variables *-------------------*/ int err, p; double *tempfrac, *Qpowtempf; double fdistance, Qtempfractot, totalpct, check; /*------------------------ * Initialize variables *------------------------*/ err = 0; Qtempfractot = 0.0; totalpct = 0.0; /*--------------------------------------- * Allocate memory for multiple outlet *---------------------------------------*/ tempfrac = malloc1d (maxnoutlet, double); Qpowtempf = malloc1d (maxnoutlet, double); /*---------------------------------- * Set outlet fraction per outlet *----------------------------------*/ for (p = 0; p < maxnoutlet; p++) tempfrac[p] = 0.0; fdistance = 1.0 / (noutlet + 1); for (p = 0; p < noutlet; p++) { tempfrac[p] = fdistance * (1 + p); Qpowtempf[p] = pow (tempfrac[p], 2); Qtempfractot += Qpowtempf[p]; } for (p = 0; p < noutlet; p++) {
/*------------------------ * Start of HydroRandom *------------------------*/ int hydrorandom() { /*------------------- * Local Variables *-------------------*/ float hydroran2(long *idum); float fac, rsq, v1, v2, *unival; double rsum; int err, ii, jj; err = 0; /*-------------------------- * Reset the nran counter *--------------------------*/ nran = 0; /* * First generate a set of uniform random numbers in [0.0, 1.0]. * ran2 is from "Numerical Recipes in C", p282, 2nd ed. * For the first deviate, use rnseed as the seed, making sure that * it is negative, this initializes ran2 appropriately. * For subsequent years, use the generated seed; dumlong should not * be altered between successive deviates in a sequence. */ if (yr == syear[ep] ){ rnseed = -INIT_RAN_NUM_SEED; } unival = malloc1d( 2*maxran, float ); for (ii=0; ii<2*maxran; ii++) { unival[ii] = hydroran2(&rnseed); } /* * Next generate Gaussian distributed deviates. * The routine returns two random numbers for each pass, * so loop through the array at a step of 2. * GASDEV, From "Numerical Recipes in C", p.289, 2nd ed. */ jj = 0; for (ii=0; ii<maxran-1; ii+=2){ do { v1 = 2.0 * unival[jj] - 1.0; v2 = 2.0 * unival[jj+1] - 1.0; rsq = sq(v1) + sq(v2); jj+=2; } while( rsq >= 1.0 || rsq == 0.0 ); fac = sqrt(-2.0*log(rsq)/rsq); ranarray[ii] = (double)v1*fac; ranarray[ii+1] = (double)v2*fac; } /*------------------- * Check the stats *-------------------*/ rmin = 0; rmax = 0; rsum = 0; for (ii=0; ii<maxran-1; ii+=2) { rmin = mn(rmin, ranarray[ii]); rmax = mx(rmax, ranarray[ii]); rsum += ranarray[ii]; } /*------------------- * Optional report *-------------------*/ #ifdef DBG fprintf(fidlog," HydroRandom.c: Random Number generator statistics for year %d. \n",yr ); fprintf(fidlog," number of values generated \t = %d \n", dumlong*0.5); fprintf(fidlog," minimum value generated \t = %f \n", rmin); fprintf(fidlog," maximum value generated \t = %f \n", rmax); fprintf(fidlog," mean value generated \t = %f \n\n", rsum/(double)dumlong*0.5); #endif freematrix1D( (void*) unival ); return(err); } /* end of HydroRandom */
dumint = (int) (dumdbl); if (err > 1) { fprintf (stderr, " ERROR in HydroSetNumberOutlet (HydroOutlet).\n"); fprintf (stderr, "\t Randomnummer generator failed twice: HydroTrend Aborted \n\n"); fprintf (fidlog, " ERROR in HydroSetNumberOutlet (HydroOutlet).\n"); fprintf (fidlog, "\t Randomnummer generator failed twice: HydroTrend Aborted \n\n"); exit (1); } } noutletoption = dumint; return (noutletoption); } /* end of hydrosetnumberoutlet */ /*------------------------------------------------------------------------------------------- * * 3) Hydroqfractionshuffle * * Randomly shuffles the outletfractions. * * * Variable Def.Location Type Units Usage * -------- ------------ ---- ----- ----- * dumflt Hydroqfractionshuffle float - temporary float * dvals[31] Hydroqfractionshuffle int - shuffled array of daily index values * err Hydroqfractionshuffle int - error flag, halts program * ii Hydroqfractionshuffle int - temporary loop counter * mnth Hydroqfractionshuffle int - month of the year * yy Hydroqfractionshuffle int - temporary integer * pp Hydroqfractionshuffle int - temporary integer * *-------------------------------------------------------------------------------------------*/ /*------------------------------------ * Start of Hydroqfractionshuffle.c *------------------------------------*/ int hydroqfractionshuffle (int k) { float hydroran5 (long *idumd); double dumdbl; double dummy_double, *dummyoutletpct; int yy, ii, err, *nvals, pp, *dummyvals, a; /*--------------------------------------- * Allocate memory for multiple outlet *---------------------------------------*/ dummyoutletpct = malloc1d (maxnoutlet, double); nvals = malloc1d (maxnoutlet, int); dummyvals = malloc1d (maxnoutlet, int); /*------------------------ * Initialize variables *------------------------*/ err = 0; dumdbl = 0.5;