Last active
June 12, 2020 09:58
-
-
Save milancurcic/6590d74fbbd3e765832b823474623a27 to your computer and use it in GitHub Desktop.
Example Fortran program that reads a GrADS binary file
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Thanks @milancurcic !