00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020 #include "hydroclimate.h"
00021 #include "hydroparams.h"
00022 #include "hydrodaysmonths.h"
00023 #include "hydrornseeds.h"
00024
00025
00026 #ifdef DBG
00027 #include "hydroinout.h"
00028 #endif
00029
00030 #define ntot (93)
00031
00032
00033
00034
00035 int hydroshuffle(int dvals[31],int mnth)
00036 {
00037
00038 float hydroran3(long *idum);
00039 float dumflt;
00040 double dummy_double;
00041 int yy, zz, ii, err;
00042
00043
00044
00045
00046 err = 0;
00047
00048 for( ii=0; ii<days_in_month(mnth); ii++ )
00049 dvals[ii] = ii+1;
00050
00051
00052
00053
00054 if ( yr == syear[ep] && mnth == 0)
00055 rnseed3 = -INIT_RAN_NUM_SEED;
00056
00057
00058 for( ii=0; ii<days_in_month(mnth) ; ii++ ) {
00059 dumflt = hydroran3(&rnseed3);
00060 if( 0 > dumflt || dumflt > 1 ){
00061 fprintf( stderr,"A function in HydroRan2 failed in HydroShuffle.c \n");
00062 fprintf( stderr," \t dumflt = %f: \t setting value to 0.5, ii = %d \n", dumflt, ii);
00063 dumflt=0.5;
00064 }
00065
00066
00067 dummy_double = dumflt*(float)days_in_month(mnth);
00068 yy = (int)rnd(dummy_double);
00069 if( yy == 0 ) yy += 1;
00070 zz = dvals[yy-1];
00071 dvals[yy-1] = dvals[ii];
00072 dvals[ii] = zz;
00073 }
00074
00075 #ifdef DBG
00076 if( tblstart[ep] <= yr && yr <= tblend[ep] && mnth == 0 ) {
00077 fprintf( fidlog, "\n HydroShuffle.c:\n");
00078
00079 fprintf( fidlog, " epoch = %d, year = %d, month = %d, daysim = %d \n",ep+1,yr,mnth+1,days_in_month(mnth));
00080
00081 for( ii=0; ii<days_in_month(mnth); ii++)
00082 fprintf( fidlog, " ii = %d, \t dvals[ii] = %d \n", ii, dvals[ii] );
00083 fprintf( fidlog, "\n");
00084 fflush( fidlog );
00085 }
00086 #endif
00087
00088 return(err);
00089 }