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 c This subroutine is adapted from one (see file read_ery.fc) that c performs the same task, but uses some techniques that might not c work on all platforms. 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(288,180) !returned data (288,180) will be equivalent LOGICAL success !success flag c--Local variables & constants INTEGER*4 ilat, ilon, e, m REAL*4 am 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/ INTEGER*2 buf(288) 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) c--translate the data into real values DO ilat= 1, 180 READ(lun,2,err=902) buf DO ilon= 1, 288 eryex(ilon,ilat)= fillval IF(buf(ilon) .NE. 999) THEN m= MOD(buf(ilon), 100) am= m e= (buf(ilon)-m)/100 - 1 eryex(ilon,ilat)= omag(e) * am END IF END DO END DO success=.TRUE. CLOSE(lun) RETURN 900 CONTINUE WRITE(6,*)'read_ery could not open the input file.' success=.FALSE. CLOSE(lun) RETURN 901 CONTINUE WRITE(6,*)'read_ery: error while reading header records.' success=.FALSE. CLOSE(lun) RETURN 902 CONTINUE WRITE(6,*)'read_ery: error while reading data records.' success=.FALSE. CLOSE(lun) RETURN 1 FORMAT(A) 2 FORMAT(11(1X,25I3,/),1X,13I3) END