subroutine addsec(idate,nvalues,incsec,ldate) c subroutine to add or subtract a time increment (input in seconds) to c a date. nvalues indicates whether idate is a 5 or 6 value input c date. c c c c Y2K checked. Works with either 2 or 4 digit years. c c for nvalues = 5 C C idate(1) = hour C idate(2) = minute C idate(3) = day C idate(4) = month C idate(5) = year C idate(6) = seconds set to 0 c c for nvalues = 6 C C idate(1) = hour C idate(2) = minute C idate(3) = sec C idate(4) = day C idate(5) = month C idate(6) = year c c for nvalues = 6 the values are remapped below to look like nvalues=5 c c C DIMENSION nday(12),idate(6),ldate(6) DATA nday/31,28,31,30,31,30,31,31,30,31,30,31/ C C ADJUST FOR LEAP YEAR. C nday(2)=28 if (MOD(idate(5),4).EQ.0) nday(2)=29 if (nvalues.eq.5) then idate(6) = 0 elseif (nvalues.eq.6) then iy = idate(6) idate(6) = idate(3) idate(3) = idate(4) idate(4) = idate(5) idate(5) = iy else write(6,'(a)') 1 ' Error - number of values in date must be 5 or 6' endif c convert 2 digit year to 4 digit year, convert back if iyrdigit.ne.4 c only works for 1950 to 2050 c if (idate(5).ge.50.and.idate(5).lt.100) then c idate(5) = idate(5) + 1900 c elseif (idate(5).lt.50) then c idate(5) = idate(5) + 2000 c else c iyrdigit = 4 c endif nsectot = idate(6) + incsec if (nsectot.lt.0) then nminsub = nsectot/60 -1 nsectot = nsectot - nminsub*60 if (nsectot.eq.60) then nsectot = 0 nminsub = nminsub + 1 endif nmintot = idate(2) + nminsub else nminadd = nsectot/60 nsectot = nsectot - nminadd*60 nmintot = idate(2) + nminadd endif if (nmintot.lt.0) then nhrsub = nmintot/60 - 1 nmintot = nmintot - nhrsub*60 if (nmintot.eq.60) then nmintot = 0 nhrsub = nhrsub + 1 endif nhrtot = idate(1) + nhrsub else nhradd = nmintot/60 nmintot = nmintot - nhradd*60 nhrtot = idate(1) + nhradd endif if (nhrtot.lt.0) then ndaysub = nhrtot/24 - 1 nhrtot = nhrtot - ndaysub*24 if (nhrtot.eq.24) then nhrtot = 0 ndaysub = ndaysub + 1 endif ndaytot = idate(3) + ndaysub else ndayadd = nhrtot/24 nhrtot = nhrtot - ndayadd*24 ndaytot = idate(3) + ndayadd endif 920 iy=idate(5) nmon=idate(4) nd=ndaytot if(nd.le.0) then nday(2)=28 if(mod(iy,4).eq.0) nday(2)=29 if(nmon.eq.1) then nmon=12 iy=iy-1 nd=31+nd else nmon=nmon-1 nd=nday(nmon)+nd endif go to 940 endif if (MOD(iy,4).eq.0) nday(2)=29 960 if (nd.le.nday(nmon)) go to 940 930 nd=nd-nday(nmon) nmon=nmon+1 if (nmon.le.12) go to 960 iy=iy+1 nday(2)=28 if (MOD(iy,4).eq.0) nday(2)=29 nmon=1 if (iy.ge.100.and.idate(5).lt.100) iy=0 go to 960 940 if (iy.lt.0) iy = 100 + iy if (nvalues.eq.5) then ldate(1) = nhrtot ldate(2) = nmintot ldate(3) = nd ldate(4) = nmon ldate(5) = iy ldate(6) = nsectot elseif (nvalues.eq.6) then ldate(1) = nhrtot ldate(2) = nmintot ldate(3) = nsectot ldate(4) = nd ldate(5) = nmon ldate(6) = iy else write(6,'(a)') 1 ' Error - number of values in date must be 5 or 6' endif return end