      program main
c
c
c  @(#) sample_input.f  McKie  Apr-1992
c
c  This fortran program demos sample input of MAPS-related data:
c
c   [1] Latitude & longitude 2-D fields
c   [2] Terrain 2-D field
c   [3] MAPS 3-D fields for 6 variables
c
c  This program was tested on a Cray-YMP under Unicos/cft77.
c
c
      parameter( NX = 81 )           ! # grid points in x direction
      parameter( NY = 62 )           ! # grid points in y direction
      parameter( NZ = 25 )           ! # grid points in vertical  direction
      parameter( NVAR = 6 )          ! # analysis variables
      parameter( LUN = 1 )           ! input logical unit number
      parameter( HUGE = 1.e+10 )     ! relatively large real number
c
c
c  Declare arrays
c
      real rlat( NX , NY )           ! latitude
      real rlon( NX , NY )           ! longitude
      real ht( NX , NY )             ! longitude
      real f( NX , NY , NZ , NVAR )  ! field values
      real z( NZ )                   ! vertical coordinate (sigma or theta)
      character*(8) varnam( NVAR )   ! variable name
      character*(20) filnam          ! input file name
c
c
c  Input terrain height 2-D field
c
      filnam = 'mapsterrain.dat'
      open(unit=LUN,file=filnam,status='old')
      do j=1,NY
       read(LUN,'(13f10.4)') (ht(i,j),i=1,NX)
      enddo
      close(unit=LUN)
c
c
c  Compute and report min, max of terrain height field
c
      write(*,*) ' '
      htmin = HUGE
      htmax = -HUGE 
      do j=1,NY
       do i=1,NX 
        htmin = min( htmin , ht(i,j) )
        htmax = max( htmax , ht(i,j) )
       enddo
      enddo
      write(*,*) 'Terrain height min,max = ',htmin,htmax
c
c
c  Input latitude and longitude 2-D fields
c
      filnam = 'mapslatlon.dat'
      open(unit=LUN,file=filnam,status='old')
      do j=1,NY
       read(LUN,'(13f10.4)') (rlat(i,j), i=1,NX)
      enddo
      do j=1,NY
       read(LUN,'(13f10.4)') (rlon(i,j), i=1,NX)
      enddo
      close(unit=LUN)
c
c
c  Compute and report min, max of latitude and longitude fields
c
      write(*,*) ' '
      rlatmin = HUGE
      rlatmax = -HUGE 
      rlonmin = HUGE
      rlonmax = -HUGE 
      do j=1,NY
       do i=1,NX 
        rlatmin = min( rlatmin , rlat(i,j) )
        rlatmax = max( rlatmax , rlat(i,j) )
        rlonmin = min( rlonmin , rlon(i,j) )
        rlonmax = max( rlonmax , rlon(i,j) )
       enddo
      enddo
      write(*,*) 'Latitude  min,max = ',rlatmin,rlatmax
      write(*,*) 'Longitude min,max = ',rlonmin,rlonmax
c
c
c  Input MAPS 3-D fields for all variables
c
      write(*,*) ' '
      filnam = '913450000.xxx'
      open(unit=LUN,file=filnam,status='old')
      do k=1,NZ
       do m=1,NVAR
        read(LUN,'(24x,a8,12x,f4.0)') varnam(m),z(k)
        write(*,*) 'Input ',varnam(m),'  at vertical ',z(k)
        do j=1,NY
         read(LUN,'(13f10.3)') (f(i,j,k,m),i=1,NX)
        enddo
       enddo
      enddo
      close(unit=LUN)
c
c
c  Compute and report min, max of each variable's 3-D field
c
      write(*,*) ' '
      do m=1,NVAR
       fmin = HUGE
       fmax = -HUGE 
       do k=1,NZ
        do j=1,NY
         do i=1,NX
          fmin = min( fmin , f(i,j,k,m) )
          fmax = max( fmax , f(i,j,k,m) )
         enddo
        enddo
       enddo
       write(*,*) varnam(m),' min,max=',fmin,fmax 
      enddo
c
c
c  Terminate normally
c
      stop
      end
