void dischargeddfopt(int iiopt, int jjopt) { for (i=firstrow; i<=lastrow; i++) /* for each row */ for (j=firstcol[i]; j<=lastcol[i]; j++) { /* for each col with drainage grids*/ if (griddgmglac[i][j] != nodata) { /*only glacierized area*/ /*WENN MIT INITIAL SNOW GERECHNET WIRD, BRAUCHT MAN VERSCHIEDENE SNOW GRIDS FUER JEDE PARAMETER CONSTELATION */ /* !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*/ negativemelt(); meltrainvol(); whichreservoir(); } /* END IF GLACIERIZED GRID */ } /* END FOR NEXT GRID POINT */ /*---------------------------------------------------------------------------*/ /*** CALCULATION OF DISCHARGE FOR ALL THREE AREAS [m3] ***/ /* only if time step = 1 hour !!! */ /*---------------------------------------------------------------------------*/ /*DISCHARGE OF EACH AREA (FIRN,SNOW,ICE) OF THE PREVIOUS STEP IS DIFFERENT FOR EACH PARAMETER CONSTELLATION, THEREFORE IT MUST BE AN ARRAY, IN ORDER NOT TO OVERWRITE THE PREVIOUS DAY VALUE OF THE FIRST PARAMETER CONSTELLATION WITH DISCHARGE OF ANOTHER PARAMETER SET */ /*convert discharge in m3/h for discharge formula below*/ qfirnopt[iiopt][jjopt] = qfirnopt[iiopt][jjopt]*3600*timestep; qsnowopt[iiopt][jjopt] = qsnowopt[iiopt][jjopt]*3600*timestep; qiceopt[iiopt][jjopt] = qiceopt[iiopt][jjopt]*3600*timestep; /**********************************************************************/ qfirnopt[iiopt][jjopt] = (qfirnopt[iiopt][jjopt]*exp(-(1/firnkons)) + sumk3 - sumk3*exp(-(1/firnkons))); qsnowopt[iiopt][jjopt] = (qsnowopt[iiopt][jjopt]*exp(-(1/snowkons)) + sumk2 - sumk2*exp(-(1/snowkons))); qiceopt[iiopt][jjopt] = (qiceopt[iiopt][jjopt]*exp(-(1/icekons)) + sumk1 - sumk1*exp(-(1/icekons))); /**********************************************************************/ /*CALCULATION OF AREAWATER/TIMESTEP [m3/s]*/ qfirnopt[iiopt][jjopt] = qfirnopt[iiopt][jjopt]/(3600*timestep); qsnowopt[iiopt][jjopt] = qsnowopt[iiopt][jjopt]/(3600*timestep); qiceopt[iiopt][jjopt] = qiceopt[iiopt][jjopt]/(3600*timestep); qdischber = (qfirnopt[iiopt][jjopt] + qsnowopt[iiopt][jjopt] + qiceopt[iiopt][jjopt]) + qground; volumeopt[iiopt][jjopt] = volumeopt[iiopt][jjopt] + qdischber; /*------------------------------------------------------------------------------*/ /* r2-CRITERIUM FOR STATISTICS */ /*------------------------------------------------------------------------------*/ sumr2(iiopt, jjopt); sumr2ln(iiopt, jjopt); /*logarithmic r2*/ /*-------------------------------------------------------------------------------*/ sumk1 = 0.; /*area sums for reservoirs of firn, snow, ice*/ sumk2 = 0.; /*must be set to 0 before next parameter set*/ sumk3 = 0.; return; }
void discharge() /*called each time step from main */ { for (i=firstrow; i<=lastrow; i++) /* for each row */ for (j=firstcol[i]; j<=lastcol[i]; j++) { /* for each col with drain grids*/ if (griddgmdrain[i][j] != nodata) { /*only calculated area*/ /*melt cannot be negative for temp index method, but function is needed to rename the variable MELT into meltwat, which is needed in next function*/ negativemelt(); /*set melt to zero, if energy balance negative*/ meltrainvol(); /*add melt and rain water*/ whichreservoir(); /*sum up water volume for each reservoir*/ } /* END IF DRAIN GRID */ } /* END FOR NEXT GRID CELL */ /*---------------------------------------------------------------------------*/ /*** CALCULATION OF DISCHARGE OF EACH RESERVOIR AND TOTAL DISCHARGE */ /*---------------------------------------------------------------------------*/ /*convert discharge in m3/timestep for discharge formula below*/ qfirnsim = qfirnsim*3600*timestep; qsnowsim = qsnowsim*3600*timestep; qicesim = qicesim*3600*timestep; qrocksim = qrocksim*3600*timestep; /*NEW Nov 2011*/ qfirnsim = (qfirnsim*exp(-(timestep/firnkons)) + sumk3 - sumk3*exp(-(timestep/firnkons))); qsnowsim = (qsnowsim*exp(-(timestep/snowkons)) + sumk2 - sumk2*exp(-(timestep/snowkons))); qicesim = (qicesim*exp(-(timestep/icekons)) + sumk1 - sumk1*exp(-(timestep/icekons))); qrocksim = (qrocksim*exp(-(timestep/rockkons)) + sumk4 - sumk4*exp(-(timestep/rockkons))); qfirnsim = qfirnsim/(3600*timestep); /*CALCULATION OF AREAWATER/TIMESTEP*/ qsnowsim = qsnowsim/(3600*timestep); /*[m3/s]*/ qicesim = qicesim/(3600*timestep); qrocksim = qrocksim/(3600*timestep); /* printf("\n qfirn= %f",qfirnsim);printf("\nsumk3= %f",sumk3); printf("\n qsnow= %f",qsnowsim);printf("\nsumk2= %f",sumk2); printf("\n qfirn= %f",qfirnsim);printf("\nsumk1= %f",sumk1); */ qdischber = (qfirnsim + qsnowsim + qicesim + qrocksim) + qground; /* in m3/s */ /* printf("\n sim sumk3 %f ",sumk3); printf("\n sim sumk1 %f ",sumk1); printf("\n sim abfl %f ",qdischber); */ /*SUMMATION OF CUMULATIVE DISCHARGE VOLUMES [m3*100000] for writing to output*/ volumesim = volumesim + qdischber*timestep*3600/100000; /*-------------------------------------------------------------------------------*/ if(disyes == 1) { /*only if discharge data available, i.e. if not 2*/ sumr2(1, 1); sumr2ln(1, 1); } writedisoutput(); /*write data of one time step to output file*/ /*-------------------------------------------------------------------------------*/ sumk1 = 0.; /*area sums of total water of firn,snow,ice reservoirs */ sumk2 = 0.; /* must be set to 0 after each timestep */ sumk3 = 0.; sumk4 = 0.; return; }
void dischargeopt() { /*------------------------------------------------------------------------------*/ /* OPTIMIZATION HEAD-LOOP for each timestep */ for (iiopt=1; iiopt<=anzahlopt1; iiopt++) { /*first parameter to optimize*/ /*-------------------------------------------------------------------------*/ /*** COPY NEW VALUE INTO OPTIMIZATION PARAMTER ***/ /*-------------------------------------------------------------------------*/ if (strcmp(optkA ,"firnk3") == 0) /* first parameter */ firnkons = (iiopt-1)*stepopt1+startopt1; if (strcmp(optkA, "snowk2") == 0) snowkons = (iiopt-1)*stepopt1+startopt1; /* increase optimization value no.1*/ if (strcmp(optkA, "icek1") == 0) icekons = (iiopt-1)*stepopt1+startopt1; if (strcmp(optkA, "qground") == 0) qground = (iiopt-1)*stepopt1+startopt1; if (strcmp(optkA, "T0") == 0) T0 = (iiopt-1)*stepopt1+startopt1; if (strcmp(optkA, "preccorr") == 0) preccorr = (iiopt-1)*stepopt1+startopt1; if (strcmp(optkA, "precgrad") == 0) precgrad = (iiopt-1)*stepopt1+startopt1; for (jjopt=1; jjopt<=anzahlopt2; jjopt++) /* second parameter to optimize */ { if (strcmp(optkB ,"firnk3") == 0) /* 2. parameter increased */ firnkons = (jjopt-1)*stepopt2+startopt2; if (strcmp(optkB, "snowk2") == 0) snowkons = (jjopt-1)*stepopt2+startopt2; if (strcmp(optkB, "icek1") == 0) icekons = (jjopt-1)*stepopt2+startopt2; if (strcmp(optkB, "qground") == 0) qground = (jjopt-1)*stepopt2+startopt2; if (strcmp(optkB, "T0") == 0) T0 = (jjopt-1)*stepopt2+startopt2; if (strcmp(optkB, "preccorr") == 0) preccorr = (jjopt-1)*stepopt2+startopt2; if (strcmp(optkB, "precgrad") == 0) precgrad = (jjopt-1)*stepopt2+startopt2; /*------- GRID LOOP - for whole glacier -----------------*/ /*CALCULATE WATER VOLUMES FOR EACH RESERVOIR FOR EVERY TIME STEP*/ for (i=firstrow; i<=lastrow; i++) /* for each row */ for (j=firstcol[i]; j<=lastcol[i]; j++) { /* for each col with glacier grids*/ if (griddgmdrain[i][j] != nodata) { /*only dgmdrain area*/ /*if precipitation parameters are optimized rain must be recalculated for any parameter constellation, if not the array calculated before for melt remains constant for one time step and it can be used*/ if ((strcmp(optkA, "T0") == 0) || (strcmp(optkA, "preccorr") == 0) || (strcmp(optkA, "precgrad") == 0) || (strcmp(optkB, "T0") == 0) || (strcmp(optkB, "preccorr") == 0) || (strcmp(optkB, "precgrad") == 0)) { precipinterpol(); /*correct and interpolate precipitation*/ if(onlyglacieryes == 1) rainoutsideglac(); } /*endif prec parameter*/ negativemelt(); /*set melt to zero, if energy balance negative*/ meltrainvol(); /*add melt and rain water*/ whichreservoir(); /*sum up water volum for each reservoir*/ } /* END IF DRAIN GRID */ } /* END FOR NEXT GRID CELL */ /*-------- end grid loop - whole grid calculated ------------*/ /*---------------------------------------------------------------------------*/ /*** CALCULATION OF DISCHARGE OF EACH RESERVOIR AND TOTAL DISCHARGE [m3] ***/ /*---------------------------------------------------------------------------*/ /*DISCHARGE OF EACH AREA (FIRN,SNOW,ICE) OF THE PREVIOUS STEP IS DIFFERENT FOR EACH PARAMETER CONSTELLATION, THEREFORE IT MUST BE AN ARRAY, IN ORDER NOT TO OVERWRITE THE PREVIOUS DAY VALUE OF THE FIRST PARAMETER CONSTELLATION WITH DISCHARGE OF ANOTHER PARAMETER SET */ qfirnopt[iiopt][jjopt] = qfirnopt [iiopt][jjopt]*3600*timestep; qsnowopt[iiopt][jjopt] = qsnowopt[iiopt][jjopt]*3600*timestep; qiceopt[iiopt][jjopt] = qiceopt[iiopt][jjopt]*3600*timestep; /*MUST HERE BE IN m3/timestep!*/ /**********************************************************************/ qfirnopt[iiopt][jjopt] = (qfirnopt [iiopt][jjopt]*exp(-(timestep/firnkons)) + sumk3 - sumk3*exp(-(timestep/firnkons))); qsnowopt[iiopt][jjopt] = (qsnowopt[iiopt][jjopt]*exp(-(timestep/snowkons)) + sumk2 - sumk2*exp(-(timestep/snowkons))); qiceopt[iiopt][jjopt] = (qiceopt[iiopt][jjopt]*exp(-(timestep/icekons)) + sumk1 - sumk1*exp(-(timestep/icekons))); /**********************************************************************/ qfirnopt[iiopt][jjopt] = qfirnopt [iiopt][jjopt]/(3600*timestep); qsnowopt[iiopt][jjopt] = qsnowopt[iiopt][jjopt]/(3600*timestep); /*[m3/s]*/ qiceopt[iiopt][jjopt] = qiceopt[iiopt][jjopt]/(3600*timestep); /* printf("\n qfirn= %f",qfirn);printf("\nsumk3= %f",sumk3); printf("\n qsnow= %f",qsnow);printf("\nsumk2= %f",sumk2); printf("\n qice= %f",qice);printf("\nsumk1= %f",sumk1);*/ /*SIMULATED DISCHARGE IN m3/s*/ qdischber = (qfirnopt[iiopt][jjopt] + qsnowopt[iiopt][jjopt] + qiceopt[iiopt][jjopt]) + qground; /*CUMULATED DISCHARGE VOLUME in m3/s : will be converted into 100000m3 in write2matriz*/ volumeopt[iiopt][jjopt] = volumeopt[iiopt][jjopt] + qdischber; /*------------------------------------------------------------------------------*/ /* summation for r2-CRITERIUM */ /*------------------------------------------------------------------------------*/ sumr2(); /* SUM UP SUMS FOR r2-CALCULATION*/ sumr2ln(); /* SUMS FOR ln r2*/ /*-------------------------------------------------------------------------------*/ /* meltwater integrated over ice, snow, firn area for one parameter constellation*/ sumk1 = 0.; /*ice area */ sumk2 = 0.; sumk3 = 0.; } /*END FOR - next parameter constellation - 2. parameter*/ if (strcmp(optkB ,"firnk3") == 0) /* 2. parameter decreased to startvalue*/ firnkons = startopt2; if (strcmp(optkB, "snowk2") == 0) snowkons = startopt2; if (strcmp(optkB, "icek1") == 0) icekons = startopt2; if (strcmp(optkB, "qground") == 0) qground = startopt2; if (strcmp(optkB, "T0") == 0) T0 = startopt2; if (strcmp(optkB, "preccorr") == 0) preccorr = startopt2; if (strcmp(optkB, "precgrad") == 0) precgrad = startopt2; } /*END FOR - next parameter constellation - 1. parameter*/ return; }