! module readmgcm integer,parameter :: nlon=72, nlat=36, nflds=4 real,parameter :: glon1=-180., dlon=5., glat1=-87.5, dlat=5. real :: frd(nlon,nlat,nflds) ! global fields to be read (z,t,u,v) real :: xls,time real :: glat(nlat),glon(nlon) character(len=120) :: sourcefile contains !----------------------------------------------------------------------- subroutine rdmgcm(filein,eof) ! ! Read a record from input file filein. Return eof==1 if EOF is encountered ! on this file. On first call, open the file. If eof encountered, close the file. ! implicit none ! ! Args: character(len=*),intent(in) :: filein integer,intent(out) :: eof ! ! Local: integer :: luread=20 integer :: ier,ios,j,i integer :: nlonrd,nlatrd,nbinrd character(len=120) :: cmd logical :: exists,isopen real :: rdnlon,rdnlat,rdnbin integer,save :: ncalls=0,nrec=0 ! ncalls = ncalls+1 eof = 0 ! ! Check for existence of input file: if (ncalls == 1) then write(6,"(/,'rdmgcm: Input Filename = ',a)") trim(filein) inquire(file=filein,exist=exists) if (exists) then write(6,"('File ',a,' exists.')") trim(filein) else write(6,"('>>> Cannot find file ',a)") trim(filein) stop 'mkcdf' endif sourcefile = filein ! ! Close luread if necessary: inquire(unit=luread,opened=isopen) if (isopen) then close(luread) write(6,"('Closed alread open unit ',i3)") luread endif ! ! Open for reading: open(unit=luread,file=trim(filein),status='OLD', | form='UNFORMATTED',iostat=ios) if (ios /= 0) then write(6,"('>>> mkcdf: Error opening input file ',a, | ' for reading: ios=',i4)") trim(filein),ios stop 'mkcdf' else write(6,"('Opened file ',a,' with luread=',i3)") | trim(filein),luread endif ! ! Define tgcm 5x5 degree grid: do j=1,nlat glat(j) = glat1+(j-1)*dlat enddo do i=1,nlon glon(i) = glon1+(i-1)*dlon enddo endif ! ncalls > 0 ! ! 5/03 bf: Originally, these 4 floats were read from the 1st record, ! but no longer appears to be correct. ! ! read(luread) rdnlon,rdnlat,rdnbin,xls ! write(6,"('Read input file header: rdnlon=',f8.2,' rdnlat=',f8.2, ! | ' rdnbin=',f8.2,' xls=',f8.2)") rdnlon,rdnlat,rdnbin,xls ! nlonrd = int(rdnlon) ! nlatrd = int(rdnlat) ! nbinrd= int(rdnbin) read(luread,end=900) frd,xls,time nrec = nrec+1 ! write(6,"('nrec=',i4,' xls=',e12.4,' time=',e12.4)") ! | nrec,xls,time ! do j=1,nlat ! write(6,"('f (z) at j=',i3,/,(6e12.4))") j,frd(:,j,1) ! enddo ! do j=1,nlat ! write(6,"('f (t) at j=',i3,/,(6e12.4))") j,frd(:,j,2) ! enddo ! do j=1,nlat ! write(6,"('f (u) at j=',i3,/,(6e12.4))") j,frd(:,j,3) ! enddo ! do j=1,nlat ! write(6,"('f (v) at j=',i3,/,(6e12.4))") j,frd(:,j,4) ! enddo return 900 continue write(6,"('EOF encountered on input file ',a,' nrec=',i4)") | trim(filein),nrec eof = 1 close(luread) end subroutine rdmgcm end module readmgcm