SUBROUTINE read_ery(lun, eryfile, fillval, header, eryex, success) c c PURPOSE: c This subroutine opens and reads an ascii file containing the erythemal c data, and returns the header and erythemal exposure data in an array. c The array can have dimensions (288,180) in the calling program, c corresponding to 288 longitude wedges of 1.25 degrees width and 180 c latitude bands of 1.00 degree width. c c The objective of this code is to perform as few reads as possible-- c the data are all read in one gulp--since I/O can be a time-pig. c In addition, it was desireable to have a very small requirement c for the subroutine's local storage. c c Some tricks are used to extract the data from the ascii form directly c to numerical values in one bitwise-and, two multiplications, and a c single addition. These tricks rely on the FORTRAN compiler not c noticing that some of the data are stored in areas designated for c REAL*4, but are character, byte, or integer data. c c Note that some of these tricks may not work on all compilers. c IMPLICIT NONE c--Calling arguments c----INPUT INTEGER*4 lun !logical unit number to use CHARACTER*(*) eryfile !name of file to read REAL*4 fillval !fill value to use for nonexistent data c----RETURNED CHARACTER*80 header(3) !returned header lines REAL*4 eryex(51840) !returned data (288,180) will be equivalent LOGICAL success !success flag c--Local variables & constants INTEGER*4 i INTEGER*4 mask /x'0f0f0f00'/ INTEGER*4 infilval /x'39393920'/ REAL*4 omag(0:9) /1.e0, 1.e1, 1.e2, 1.e3, 1.e4, & 1.e5, 1.e6, 1.e7, 1.e8, 1.e9/ REAL*4 tr4 INTEGER*4 ti4 INTEGER*1 ti1(4) EQUIVALENCE(ti4,ti1,tr4) c--read the data from the file OPEN(UNIT=lun, FILE=eryfile,form='formatted',status='old', & err= 900) READ(lun,1,err=901) header(1) READ(lun,1,err=901) header(2) READ(lun,1,err=901) header(3) READ(lun,2,err=902) eryex CLOSE(lun) c--translate the data into real values DO i= 1, 51840 tr4= eryex(i) eryex(i)= fillval IF(ti4 .NE. infilval) THEN ti4= IAND(ti4,mask) eryex(i)= omag(ti1(1)) * (ti1(2) + 0.1*ti1(3)) ENDIF END DO success=.TRUE. RETURN 900 CONTINUE WRITE(6,*)'read_ery could not open the input file.' success=.FALSE. RETURN 901 CONTINUE WRITE(6,*)'read_ery: error while reading header records.' success=.FALSE. RETURN 902 CONTINUE WRITE(6,*)'read_ery: error while reading data records.' success=.FALSE. RETURN 1 FORMAT(A) 2 FORMAT(179(11(1X,25A3,/),1X,13A3,/),11(1X,25A3,/),1X,13A3) END