!
! read dmp data of CatsEye a sample of CRESS
!   2007 Oct. I. Tamagawa 
!	Oct.22 modified

implicit none

integer, parameter ::  itemnum=9
integer, parameter ::  xdim=99, ydim=4, zdim=139
real, parameter    ::  dx=10.0, dy=10.0, dz=5.0
character :: file*1024
integer :: i, j, k, l, recdmp
real :: var(itemnum, xdim, ydim, zdim)

!    Dumped the 3-d variable, base state x components of velocity [m/s].
!    Dumped the 3-d variable, x components of velocity [m/s].
!    Dumped the 3-d variable, base state y components of velocity [m/s].
!    Dumped the 3-d variable, y components of velocity [m/s].
!    Dumped the 3-d variable, z components of velocity [m/s].
!    Dumped the 3-d variable, base state pressure [Pa].
!    Dumped the 3-d variable, pressure perturbation [Pa].
!    Dumped the 3-d variable, base state potential temperature [K].
!    Dumped the 3-d variable, potential temperature perturbation [K].


  write(0,*) 'dmp file name'
  read(*,*) file

  write(0,*) 'read data from', file

  open(10, file=file, form='unformatted', &
     recl=(xdim-3)*(ydim-3)*4, access='direct') 
!			 recl=(xdim-3)*(ydim-3) in Some compiler

   recdmp = 1
   do l=1, itemnum

     do k=2, zdim-2
       read(10, rec=recdmp, err=999) &
          (( var(l,i,j,k), i=2,xdim-2),j=2,ydim-2)
     recdmp = recdmp + 1
     end do

   end do

   close(10)

!  OUTPUT part should be changed by yourself
!  the followings are just sample
!

  j = 2
!   output  potential temp. in x-z plane

   do k=2, zdim-2
    do i=2, xdim-2
     write(*,*) i*dx, k*dz, var(8,i,j,k)+var(9,i,j,k)
    end do
   end do


!
stop

999 write(0,*) ' READ ERROR!!! '
end

