subroutine ryf1 i (x, indpar) c c Subroutine 1 of 2 to interpolate preserving the monthly means. c This is accomplished in most months by shifting the time that c the mean occurs ("pseudo-midpoint"). In months whose mean is c a local minimum or maximum, the mid-month value is shifted to c a pseudo-value and the mean is assumed to occur at two times, c one before the midpoint, and one after. c c Written 8/4/2000 by C. R. Meyer to implement an algorithm c from Daniel Yoder, and modified by George Foster in response c to C. R. Meyer's criticism of lack of a solution for minima c or maxima. The essential idea is to make the area (under the c parameter curve) above the monthly mean the same as the area c below it. This shifts the time of the mean (PMT) from the c midpoint of the month. However, for maxima and minima, it c leaves the time at the midpoint, but shifts the value (PMV). c The values at the end (and beginning) of each month (EMV) c resulting from a simple linear interpolation are utilized in c the calculations. c c From the mean value and the length of each month, calculate c the interpolated values at the month boundaries. Also calculate c the time(s) of the pseudo-midpoint, of the value. c real x(12) integer indpar c c x - 12 measured monthly average values (means, sd, skew). c indpar - index of the current parameter. c include 'cinterp.inc' c write: emv, pmt, pmv, xes c emv - End-of-the-Month Value for the monthly mean of each parameter. c pmt - Pseudo-Midpoint Time for each month, for each parameter. c pmv - Pseudo-Midpoint Value for each month, for each parameter. c xes - the monthly values (mean, SD, skew) for the 14 values. c (Set to -9999.0 if this is not a Max or Min month.) c c + + + LOCAL VARIABLES + + + integer dim(12), i real ratio, tfs, tte c c + + + LOCAL DEFINITIONS + + + c ---- dim -- Days in each Month. c c + + + DATA INITIALIZATIONS + + + data dim/31,28,31,30,31,30,31,31,30,31,30,31/ c c + + + END SPECIFICATIONS + + + c c ---- End of Month Values (EMV): do 100 i=1,11 tte = dim(i)/2.0 tfs = dim(i+1)/2.0 c--------(fraction of time between middles, from middle to end of this month) ratio = tte/(tte+tfs) emv(i,indpar) = x(i) + (x(i+1)-x(i))*ratio 100 continue c--------(December) emv(12,indpar) = (x(12)+x(1))*0.5 c--------(End of January Value, Leap Years) emv(13,indpar) = x(1) + (x(2)-x(1))*0.516667 c--------(End of February Value, Leap Years) emv(14,indpar) = x(2) + (x(3)-x(2))*0.483333 c c --- Pseudo-Midpoint Times & Values (PMT & PMV): do 200 i=2,12 c-------(3 consecutive identical monthly values) if(emv(i-1,indpar).eq.x(i).and.emv(i,indpar).eq.x(i)) then pmt(i,indpar) = dim(i)/2.0 pmv(i,indpar) = x(i) xes(i,indpar) = -9999 c-------(not a max or min) else if(emv(i-1,indpar).lt.x(i).and.emv(i,indpar).gt.x(i) .or. 1 emv(i-1,indpar).gt.x(i).and.emv(i,indpar).lt.x(i)) then pmt(i,indpar) = dim(i) * 1 (emv(i,indpar)-x(i))/(emv(i,indpar)-emv(i-1,indpar)) pmv(i,indpar) = x(i) xes(i,indpar) = -9999.0 c-------(max, min, or 1 EOM value identical to x(i)) else pmv(i,indpar) = 2.0*x(i)-(emv(i,indpar)+emv(i-1,indpar))/2.0 pmt(i,indpar) = dim(i)/2.0 xes(i,indpar) = x(i) endif 200 continue c--------(January) if(emv(12,indpar).eq.x(i).and.emv(i,indpar).eq.x(i)) then pmt(1,indpar) = dim(i)/2.0 pmv(1,indpar) = x(i) xes(1,indpar) = -9999 else if(emv(12,indpar).lt.x(1).and.emv(1,indpar).gt.x(1) .or. 1 emv(12,indpar).gt.x(1).and.emv(1,indpar).lt.x(1)) then pmt(1,indpar) = 31.0 * 1 (emv(1,indpar)-x(1))/(emv(1,indpar)-emv(12,indpar)) pmv(1,indpar) = x(1) xes(1,indpar) = -9999.0 else pmv(1,indpar) = 2.0*x(1)-(emv(1,indpar)+emv(12,indpar))/2.0 pmt(1,indpar) = 15.5 xes(1,indpar) = x(1) endif c--------(February, Leap Years) if(emv(1,indpar).eq.x(2).and.emv(2,indpar).eq.x(2)) then pmt(13,indpar) = 14.5 pmv(13,indpar) = x(2) else if(emv(1,indpar).lt.x(2).and.emv(2,indpar).gt.x(2) .or. 1 emv(1,indpar).gt.x(2).and.emv(2,indpar).lt.x(2)) then pmt(13,indpar) = 29.0 * 1 (emv(2,indpar)-x(2))/(emv(2,indpar)-emv(1,indpar)) pmv(13,indpar) = x(2) else pmv(13,indpar) = 2.0*x(2)-(emv(2,indpar)+emv(1,indpar))/2.0 pmt(13,indpar) = 14.5 endif c return end