      CHARACTER*32 LAB

      PARAMETER(LEVMAX=100)
      parameter (igrid=26, jgrid=22)
      parameter (ijgrid=igrid*jgrid, LEVL=18, LEVL1=LEVL+1)


      INTEGER*8 IDATE8(4)
      REAL*8 SI8( LEVL1 ), SL8( LEVL ), FHOUR8, ARR8( ijgrid )
      REAL*8 DUMMY8(2*LEVMAX+1- LEVL1 - LEVL )
     1         ,EXT8(512-(6+2*LEVMAX))



      pi=4*ATAN(1.0)
      iverbose=5

      ND=30
      N=60

      OPEN(ND,form='UNFORMATTED',status='OLD',READONLY)
      OPEN(N,form='FORMATTED',status='UNKNOWN')



      READ(ND) LAB
         if (iverbose .gt. 3 )
     *   print*,"In Lab=",LAB

*          123456789 123456789 123456789 12
      LAB='GSM/RSM_0 SEAST ASIAN SUB DOMAIN'
      WRITE(N,'(a32)') LAB


      READ(ND) FHOUR8,IDATE8,(SI8(K),K=1, LEVL1 ),(SL8(K),K=1, LEVL )
     1         ,DUMMY8,EXT8

         if (iverbose .gt. 3 ) then
          print*,'-SI-SL----------------------------'
          print*,si8
          print*,' '
          print*,sl8
          print*,'----------------------------------'
         endif

      WRITE(N,66) FHOUR8,IDATE8,(SI8(K),K=1, LEVL1 ),(SL8(K),K=1, LEVL )
c    1         ,DUMMY,EXT
   66 format(e12.6,4i5,19e12.6,18e12.6)


         if (iverbose .ge. 1 )
     *    write(6,'(a11,f10.1,4i7)')'converting ',fhour8,idate8


C GZ
      READ(ND) ARR8
      WRITE(N,'(6e12.6)') ARR8
         if (iverbose .gt. 1 )
     *   call stats8(ARR8,ijgrid,1,'OROG')

C PRESS
      READ(ND) ARR8
      WRITE(N,'(6e12.6)') ARR8
         if (iverbose .gt. 1 )
     *   call stats8(ARR8,ijgrid,1,'PRSS')


C TE
      DO 300 K=1, LEVL
         READ(ND) ARR8
         WRITE(N,'(6e12.6)') ARR8
         if (iverbose .gt. 1 )
     *   call stats8(ARR8,ijgrid,1,'VTMP')
300   CONTINUE

C UU VV
      DO 310 K=1, LEVL
         READ(ND) ARR8
         WRITE(N,'(6e12.6)') ARR8
         READ(ND) ARR8
         WRITE(N,'(6e12.6)') ARR8
310   CONTINUE

C RQ
      DO 320 K=1, LEVL
         READ(ND) ARR8
         WRITE(N,'(6e12.6)') ARR8
         if (iverbose .gt. 1 )
     *   call stats8(ARR8,ijgrid,1,'SPHM')
320   CONTINUE

C FM2 
      READ(ND) ARR8
      WRITE(N,'(6e12.6)') ARR8

C FM2X
      READ(ND) ARR8
      WRITE(N,'(6e12.6)') ARR8

C FM2Y
      READ(ND) ARR8
      WRITE(N,'(6e12.6)') ARR8

C FLAT
      READ(ND) ARR8
      WRITE(N,'(6e12.6)') ARR8
         if (iverbose .gt. 3 )
     *   write(*,*)(arr8(i)*180./pi,i=1,ijgrid,igrid)


C FLON
      READ(ND) ARR8
c     write(99,*)arr8
      WRITE(N,'(6e12.6)') ARR8
         if (iverbose .gt. 3 )
     *   write(*,*)(arr8(i)*180./pi,i=1,igrid)


C GESHEM
      READ(ND,END=99) ARR8
c     write(77,*)arr8
      WRITE(N,'(6e12.6)') ARR8
      ipoint=0
      do i=1,ijgrid
         if(ARR8(i).ne.0.)ipoint=ipoint+1
      enddo

         if (iverbose .gt. 1 )
     *   write(6,*)'wet points=',ipoint


C BENGSH
      READ(ND,END=88) ARR8
c     write(66,*)arr8
      WRITE(N,'(6e12.6)') ARR8

      STOP
c
   99 continue
         if (iverbose .gt. 2 )
     *   write(6,*)'***** no precip record ******'

      stop
   88 continue

         if (iverbose .gt. 2 )
     *   write(6,*)'***** no BENGSH record ******'

      stop
      END

      subroutine stats8(grd,nx,ny,clab)

      character*4 clab
      integer     nx,ny
      real*8      rmax,rmin,rbar,rdev
      real*8      grd(nx,ny)

      rmax=maxval(grd)
      rmin=minval(grd)
      rbar=sum(grd)/size(grd)

      if (rbar .eq. 0.0 ) then
        print*,clab//" WARNING STATS: RBAR RMIN RMAX",rbar,rmin,rmax
        return
      endif

      rdev=sqrt(sum( (grd - rbar)**2)/(size(grd)-1))

      write(*,'(a22,4(1x,f16.7))')
     * clab//" MAX MIN AVG VRC ",rmax,rmin,rbar,rdev

      return
      end

