Created
March 30, 2016 08:49
-
-
Save tenomoto/f1d0454c55b9102007f5bad730ee303f to your computer and use it in GitHub Desktop.
Replace values in ECMWF initial condition in GRIB format
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 grd2grb | |
use grib_api | |
implicit none | |
character(len=*), parameter :: & | |
ifname = "ICMSHepc8INIT", gfname = "out.grd", ofname = "out.grb" | |
integer, parameter :: & | |
ug = 41, ntrunc = 21, nv = (ntrunc + 2) * (ntrunc + 1) | |
real*4, dimension(nv) :: sh | |
integer :: ifile, ofile | |
integer :: igrib, iret, n = 0 , i | |
open(unit = ug, file = gfname, access = "direct", & | |
status = "old", action = "read", recl = nv * 4) | |
call grib_open_file(ifile, ifname, 'R') | |
call grib_open_file(ofile, ofname, 'W') | |
do | |
call grib_new_from_file(ifile, igrib, iret) | |
if (iret == GRIB_END_OF_FILE) exit | |
n = n + 1 | |
read(unit = ug, rec = n) sh | |
print *, "message #", n, " # of values = ", nv | |
call grib_set(igrib, "values", sh, iret) | |
call grib_write(igrib, ofile) | |
call grib_release(igrib) | |
end do | |
call grib_close_file(ifile) | |
call grib_close_file(ofile) | |
close(unit = ug) | |
end program |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment