subroutine invtime(timestamp,yr,mon,day,hr,min) c c This subroutine will convert a minutes timestamp to a year/month c date. Based on the function convtime by Shawn Smith (COAPS). c c Written the spring of 1995, several iterations. c James N. Stricherz (stricherz@coaps.fsu.edu) c c This code returns correct results for the range of 01 Jan 1980 0000GMT c thru 31 Dec 1999 2359GMT. I know it does, because I tried each minute c of that range. c integer year(1980:2000), month(13), leap_mon(13), min_day, + min_hr, yr, mon, day, hr, min,timestamp,itime,tmon,ttime, + thour data year /0, 527040, 1052640, 1578240, 2103840, 2630880, 3156480, + 3682080, 4207680, 4734720, 5260320, 5785920, 6311520, + 6838560, 7364160, 7889760, 8415360, 8942400, 9468000, + 9993600,10519200/ data month /0, 44640, 84960, 129600, 172800, 217440, 260640, + 305280, 349920, 393120, 437760, 480960,525600/ data leap_mon /0, 44640, 86400, 131040, 174240, 218880, 262080, + 306720, 351360, 394560, 439200, 482400,527040/ data min_day, min_hr /1440, 60/ * * ok, lets inverse the effects of the years -- subtract off the * number of minutes per year until it goes negative. iyr * then gives the year that the time (in minutes) occurs... * if (timestamp.ge.year(2000)) then yr=-9999 return endif iyr=1979 itime=timestamp 10 iyr=iyr+1 ttime=itime-year(iyr) if (ttime.le.0) then if (iyr.eq.1980) iyr=iyr+1 iyr=iyr-1 itime=itime-year(iyr) else goto 10 endif * * assign the return variable * yr=iyr * * ok, the remaining time is less than one full year, so convert * by the same method as above into months: * imon=0 * * that darn leap month! * if (mod(iyr,4).ne.0) then * * increment the month, and subtract off the minutes from the * remaining time for a non-leap year * 20 imon=imon+1 tmon=itime-month(imon) if (tmon.gt.0) then goto 20 else if (tmon.lt.0) then imon=imon-1 itime=itime-month(imon) else if (imon.gt.12) then imon=imon-12 yr=yr+1 endif mon=imon day=1 hr=0 min=0 return endif else * * same thing, same code, but for a leap year * 30 imon=imon+1 tmon=itime-leap_mon(imon) if (tmon.gt.0) then goto 30 elseif (tmon.lt.0) then imon=imon-1 itime=itime-month(imon) else if (imon.gt.12) then imon=imon-12 yr=yr+1 endif mon=imon day=1 hr=0 min=0 return endif endif * * assign the return variable * mon=imon * * any remaining minutes will belong to day/hour/minutes * ok, let's get those pesky days! * iday=0 40 iday=iday+1 ttime=itime-min_day if (ttime.ge.0) then itime=ttime goto 40 endif * * assign the return variable * if (mod(iyr,4).eq.0.and.mon.gt.2) then day=iday-1 else day=iday endif * * pick off the hours of the days...remember, hours can be 0, so * we start at -1 * ihour=-1 50 ihour=ihour+1 thour=itime-min_hr if (thour.ge.0) then itime=thour goto 50 endif * * assign the return variables * hr=ihour * * the remainder at this point is the minutes, so return them directly! * min=itime return end