SUBROUTINE GETDST(MSGUN,ITIME,DST, ISTAT , + IWRK,IBLK,IUNPK,LREC) C GETDST returns the hourly DST index for the UT time input, C ITIME. The indicies are read from the NCAR I.S. database vsn C DST570101A. If not available for a requested time, DST is C returned as "-32767." (the standard missing data code). C Although the standard time format is input as ITIME, the C minute and centisecond are ignored; i.e., any minute of the C hour is interpreted as a request for that hour's value: C 0000 - 0059 returns same hourly value C 0100 - 0159 " " " " C . . . . . C 2300 - 2400* " " " " C * When ITIME(3)=2400, this is considered to be an "end" time C and the last value(s) of the day are returned. Although C one could argue this is inconsistant, it is easy enough to C input 0000 on the next date for the next hours indicies. C C INPUTS: C MSGUN = Fortran unit to print diagnostic messages; see C also ISTAT. C ITIME(1) = Year, four digits Universal time C ITIME(2) = Month and day, e.g. 31 Jan is 0131 C ITIME(3) = Hour and minute of day C ITIME(4) = Centisecond (hundredth second of minute) C ISTAT = 99999 on input, implies only fatal errors C will cause diagnostic messages to be printed, C nonfatal errors will be signified only by the C returned value of ISTAT (thus allowing user C control of most diagnostic print messages). C SEE ALSO RETURN ISTAT values below. C IWRK = Work array used by RDBLK6 (contains fortran unit C to read indicies, etc - see RDBLK6) C IBLK = Packed physical record buffer - see RDBLK6. C IUNPK = Unpacked block buffer - see RDBLK6. C LREC = Logical record - see RDBLK6. C RETURNS: C ISTAT = Status flag C = 0 => ok C = 1 => Bad time input C = 2 => Request time before first available C = 3 => Request time after last available C = 6 => Indicies dataset corrupted; should be C continuos, yet somehow read past ITIME C DST = The DST value for time ITIME; units are nT C (nanoTeslas) or gammas. C Formal parameter declarations: DIMENSION ITIME(4) , IWRK(*),IBLK(*),IUNPK(*),LREC(*) C Local declarations PARAMETER (MISS=-32767 , RMISS=-32767. , NOPRT=99999 , + IOFF=26,MPAR=5) C IOFF=LPROL + 2*JPAR + 2*MPAR DIMENSION LBEGT(4) , IT(4) DOUBLE PRECISION IDIF , JDIF LOGICAL ATBEGN SAVE ATBEGN,LBEGT,ISTRD DATA ATBEGN,LBEGT,ISTRD/.TRUE. , 1940,0101,0000,0000 , 0/ C Initialize returned values array to missing DST = RMISS C Check input time NOK = 0 IF(ITIME(1) .LT. 1940 .OR. ITIME(1) .GT. 2100)NOK = 1 IF(ITIME(2) .LT. 0101 .OR. ITIME(2) .GT. 1231)NOK = 1 IF(ITIME(3) .LT. 0 .OR. ITIME(3) .GT. 2400)NOK = 1 IF(NOK .GT. 0)THEN IF(ISTAT .NE. NOPRT)WRITE(MSGUN,9000)(ITIME(I),I=1,4) ISTAT = 1 RETURN ENDIF C See if already read past the requested date and hour: IT(1) = ITIME(1) IT(2) = ITIME(2) IT(3) = 0 IT(4) = 0 CALL TIMDIF(LBEGT,IT,IDIF) IF(IDIF .EQ. 0D0)GO TO 1000 IF(IDIF .GT. 0D0)THEN C Must read more but first see if already at EOD IF(ISTRD .NE. 3)GO TO 100 IF(ISTAT .NE. NOPRT)WRITE(MSGUN,9100)(ITIME(I),I=1,2), + (LREC(J),J=5,6) ISTAT = 3 RETURN ENDIF CALL REWBLK(IWRK) IWRK(7) = 1 ATBEGN = .TRUE. C Read a new lrec, compute & test the new difference 100 CALL RDBLK6(IWRK,LREC,IBLK,IUNPK,ISTRD) IF(ISTRD .EQ. 0 .AND. LREC(2) .NE. 1002)GO TO 100 LBEGT(1) = LREC(5) LBEGT(2) = LREC(6) CALL TIMDIF(LREC(5),IT,JDIF) IF(JDIF .GT. 0D0)THEN C must read more ATBEGN = .FALSE. IF(ISTRD .NE. 3)GO TO 100 IF(ISTAT .NE. NOPRT)WRITE(MSGUN,9100)(ITIME(I),I=1,2), + (LREC(J),J=5,6) ISTAT = 3 RETURN ELSEIF(JDIF .LT. 0D0)THEN C after request time IF(ATBEGN)THEN IF(ISTAT .NE. NOPRT)WRITE(MSGUN,9200)(ITIME(I),I=1,2), + (LREC(J),J=5,6) ISTAT = 2 ELSE IF(ISTAT .NE. NOPRT)WRITE(MSGUN,9500)(ITIME(I),I=1,2) ISTAT = 6 ENDIF RETURN ENDIF C Compute position of DST value for the requested hour 1000 IHR = ITIME(3)/100 IF(IHR .EQ. 24)IHR = 23 IPOS = IOFF + IHR*MPAR DST = FLOAT( LREC(IPOS) ) ISTAT = 0 RETURN C Error trap messages: 9000 FORMAT('0GETDST: Bad time input; time =',4I5) 9100 FORMAT('0GETDST: Requested time',2I5,' is after last available: ' +,2I5) 9200 FORMAT('0GETDST: Requested time',2I5,' is before first available: + ',2I5) 9500 FORMAT('0GETDST: Indicies dataset corrupted? Data should be', + ' continuous yet',/, + ' somehow read past requested time',2I5) END