eccodes/examples/F90/grib_read_message.f90

54 lines
1.6 KiB
Fortran
Raw Normal View History

2020-01-28 14:32:34 +00:00
! (C) Copyright 2005- ECMWF.
2013-03-25 12:04:10 +00:00
!
! This software is licensed under the terms of the Apache Licence Version 2.0
! which can be obtained at http://www.apache.org/licenses/LICENSE-2.0.
2017-02-06 16:45:30 +00:00
!
2013-03-25 12:04:10 +00:00
! In applying this licence, ECMWF does not waive the privileges and immunities granted to it by
! virtue of its status as an intergovernmental organisation nor does it submit to any jurisdiction.
!
! Description: how to get values using keys.
!
2020-10-20 17:04:01 +00:00
program grib_read_message
use eccodes
implicit none
integer :: ifile, ofile
integer :: iret, igrib
integer, dimension(50000) :: buffer
integer(kind=kindOfSize_t) :: len1
integer :: step, level
2013-03-25 12:04:10 +00:00
call codes_open_file(ifile, '../../data/index.grib', 'r')
call codes_open_file(ofile, 'out.readmsg.grib', 'w')
2017-02-06 16:45:30 +00:00
2013-03-25 12:04:10 +00:00
! a grib message is read from file into buffer
len1 = size(buffer)*4
call codes_read_from_file(ifile, buffer, len1, iret)
2013-03-25 12:04:10 +00:00
do while (iret /= CODES_END_OF_FILE)
2013-03-25 12:04:10 +00:00
! a new grib message is created from buffer
call codes_new_from_message(igrib, buffer)
2013-03-25 12:04:10 +00:00
! get as a integer
call codes_get(igrib, 'step', step)
write (*, *) 'step=', step
2013-03-25 12:04:10 +00:00
call codes_get(igrib, 'level', level)
write (*, *) 'level=', level
2013-03-25 12:04:10 +00:00
call codes_release(igrib)
2013-03-25 12:04:10 +00:00
call codes_write_bytes(ofile, buffer, len1)
2013-03-25 12:04:10 +00:00
! a grib message is read from file into buffer
len1 = size(buffer)*4
call codes_read_from_file(ifile, buffer, len1, iret)
2013-03-25 12:04:10 +00:00
end do
2013-03-25 12:04:10 +00:00
call codes_close_file(ifile)
call codes_close_file(ofile)
2013-03-25 12:04:10 +00:00
2020-10-20 17:04:01 +00:00
end program grib_read_message
2013-03-25 12:04:10 +00:00