      program poles_frc_read
c Functionality: 
C     FORTRAN program which demonstrates  how to read the POLES Sea Ice 
c     Model forcing data. 
c Notes:
c     The data files were written as fortran unformatted, direct access
c     files under HP-UX 10.20. Users with different operating systems
c     may have to make changes in the definition of the record length. 
c     (Some systems specify record length in longwords) and/or have to 
c     swap bytes.
c =======================================================================
      PARAMETER(NX=44,NY=43)

      integer*2 t_int(nx,ny),qa_int(nx,ny),fl_int(nx,ny),fs_int(nx,ny)
     &     ,u_int(nx-1,ny-1),v_int(nx-1,ny-1)
      real*4 temp(nx,ny),qa(nx,ny),fl(nx,ny),fs(nx,ny),oflux(nx,ny)
     &     ,u(nx-1,ny-1),v(nx-1,ny-1),uo(nx-1,ny-1),vo(nx-1,ny-1)
      open(1,file='poles_frc_therm_1979.v1',recl=44*43*2,access='direct'
     &     ,form='unformatted')
      open(2,file='poles_frc_wind_1979.v1',recl=43*42*2,access='direct'
     &     ,form='unformatted')
      open(3,file='poles_oflow')
      open(4,file='poles_oflux')

      do iday=1,365
         read(1,rec=(iday-1)*4+1)t_int
         read(1,rec=(iday-1)*4+2)qa_int
         read(1,rec=(iday-1)*4+3)fl_int
         read(1,rec=(iday-1)*4+4)fs_int         
         read(2,rec=(iday-1)*2+1)u_int
         read(2,rec=(iday-1)*2+2)v_int
         read(3,'(8f10.4)')((uo(i,j),i=1,nx-1),j=1,ny-1)
         read(3,'(8f10.4)')((vo(i,j),i=1,nx-1),j=1,ny-1)
         read(4,'(8f10.4)')((oflux(i,j),i=1,nx),j=1,ny)
         
c     apply scaling values to convert short integers back to real
c     numbers. 
         
         do i=1,nx
            do j=1,ny
               temp(i,j)=t_int(i,j)/100.0
               qa(i,j)=qa_int(i,j)/1.0e+6
               fl(i,j)=fl_int(i,j)/100.0+200.0
               fs(i,j)=fs_int(i,j)/100.0+200.0
            end do
         end do
         do i=1,nx-1
            do j=1,ny-1
               u(i,j)=u_int(i,j)/1000.0
               v(i,j)=v_int(i,j)/1000.0
            end do
         end do
      end do
      end
      

