Code:
program rd_wr_binary
implicit none
integer, external :: iargc
integer :: istatus
character (len=256) :: fname
real, allocatable, dimension(:,:) :: rarray
! real, allocatable, dimension(:,:) :: rarrayIN
integer :: nx ! x-dimension of the array
integer :: ny ! y-dimension of the array
integer :: nz ! z-dimension of the array
integer :: isigned ! 0=unsigned data, 1=signed data
integer :: endian ! 0=big endian, 1=little endian
real :: scalefactor ! value to divide array elements by before truncation to integers
integer :: wordsize ! number of bytes to use for each array element
integer :: i
integer :: j
!!-----------------------------------------
if (iargc /= 1) then
write(0,*) ' '
write(0,*) 'Usage: rd_wr_binary.exe <filename>'
write(0,*) ' '
stop
end if
call getarg(1, fname)
!
! The following must be set before compiling
!
nx = 1200
ny = 1200
nz = 1
isigned = 0
endian = 0
wordsize = 4
scalefactor = 1.0
! allocate(rarrayIN(nx,ny))
allocate(rarray(nx,ny))
!
! Read data from geogrid binary format using read_geogrid()
!
! call read_geogrid(fname, len_trim(fname), rarray, nx, ny, nz, isigned, endian, scalefactor, wordsize, istatus)
! if (istatus /= 0) then
! write(0,*) 'Error while reading '//trim(fname)//'. Quitting.'
! end if
!
!
! We read formatted data instead of binary input file
!
open(10, file=trim(fname), form='formatted', status='old')
do j=1,ny
read(10,33) (rarray(i,j),i=1,nx)
write(*,*) i,j,rarray(nx,j)
end do
33 format(f6.1, 12000f7.1)
! 33 format(18500f7.1)
close(10)
! ------------ IF we need FLIP file -----
! NO FLIP file!!!!!
!----------------------------------------
! do j = 1,ny
! do i = 1,nx
! rarray(i,j) = rarrayIN(i,j)
! enddo
! write(*,*) i,j,rarray(nx,j)
! enddo
!--------------- end of FLIP/no FLIP ----
!
! Modify the field as necessary
!
!
! Write data to geogrid binary format using write_geogrid()
!
call write_geogrid(trim(fname)//'.bin', len_trim(trim(fname)//'.bin'), rarray, nx, ny, nz, isigned, endian, scalefactor, wordsize)
! deallocate(rarrayIN)
deallocate(rarray)
write(0,*) 'JOB finished OK!'
end program rd_wr_binary