Skip to content

Instantly share code, notes, and snippets.

@milancurcic
Last active June 12, 2020 09:58
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save milancurcic/6590d74fbbd3e765832b823474623a27 to your computer and use it in GitHub Desktop.
Save milancurcic/6590d74fbbd3e765832b823474623a27 to your computer and use it in GitHub Desktop.
Example Fortran program that reads a GrADS binary file
program read_grads_example
! Example program that reads a flat binary file
!
! With GNU Fortran, compile as:
!
! gfortran -fconvert=big-endian read_grads_example.f90
!
! With Intel Fortran, compile as:
!
! ifort -convert big_endian -assume byterecl read_grads_example.f90
! use portable 4-byte reals
use iso_fortran_env, only: real32
implicit none
character(len=*), parameter :: filename = 'taucw.grd' ! file to read
integer, parameter :: im = 2880, jm = 1440, nm = 60 ! grid dimensions
integer :: fileunit
integer :: record_length
real(kind=real32) :: field(im,jm,nm) ! 3-d array to store data
record_length = storage_size(field) / 8 * size(field)
open(newunit=fileunit, file=filename, access='direct', recl=record_length)
read(unit=fileunit, rec=1) field
close(fileunit)
write(*,*) 'Min / max: ', minval(field), maxval(field)
end program read_grads_example
@robetatis
Copy link

Thanks @milancurcic !

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment