subroutine write_grads_ieee( iu, ieee_file, nx, ny, nz, nv, nt, dd )

implicit none

!-----------------------------------------------------------------------
!  Fortran unit number for writing out the GrADS data
!-----------------------------------------------------------------------
integer, intent(in) :: iu

!-----------------------------------------------------------------------
!  Output filename for constructing GrADS output file
!-----------------------------------------------------------------------
character(len=80), intent(in) :: ieee_file

!-----------------------------------------------------------------------
!  Diagnostic data dimensions
!-----------------------------------------------------------------------
!  (x,y,z,vars,t) grid dimensions
!     nx, ny = number of (x,y) grid points, respectively
!     nz     = number of vertical grid levels
!     nv     = number of variables
!     nt     = number of time-levels
!-----------------------------------------------------------------------
integer, intent(in) :: nx, ny, nz, nv, nt

!-----------------------------------------------------------------------
!  Diagnostic Data
!-----------------------------------------------------------------------
real, dimension(nx,ny,nz,nv,nt), intent(in) :: dd

!-----------------------------------------------------------------------
!  Local variables
!-----------------------------------------------------------------------
!
!  IEEE array for writing out the GrADS data
!
real(kind=4), dimension(nx,ny) :: grads_data
!
!  record number for writing out the GrADS data
!
integer :: irec
integer :: k,iv,n

!-----------------------------------------------------------------------
!  Write the diagnostic output into GrADS ieee binary data file...
!-----------------------------------------------------------------------

      print *
      print *,'Define output Unit ',iu,' for filename: ',TRIM(ieee_file)

      close(iu)
      open(iu,file=TRIM(ieee_file),form="unformatted",access="direct", &
           recl=nx*ny*4,status="unknown")

      print *,'Write GrADS ieee data to Unit: ',iu

      irec = 1          ! initialize
      do n = 1,nt
        do iv = 1,nv
          do k = 1,nz
            grads_data(:,:) = dd(:,:,k,iv,n)
            write(iu,rec=irec) grads_data
            irec = irec + 1             ! increment for next write-out record
          enddo
        enddo
      enddo
      close(iu)

end subroutine write_grads_ieee
