eccodes/examples/F90/read_message.f90

55 lines
1.5 KiB
Fortran
Raw Normal View History

2013-03-25 12:04:10 +00:00
!
2018-01-02 11:31:02 +00:00
! Copyright 2005-2018 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.
!
program read_message
2015-01-28 22:54:42 +00:00
use eccodes
2013-03-25 12:04:10 +00:00
implicit none
2013-03-25 14:23:07 +00:00
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
2017-02-06 16:45:30 +00:00
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
2017-02-06 16:45:30 +00:00
call codes_get(igrib,'step', step)
2013-03-25 12:04:10 +00:00
write(*,*) 'step=',step
call codes_get(igrib,'level',level)
2013-03-25 12:04:10 +00:00
write(*,*) 'level=',level
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
2017-02-06 16:45:30 +00:00
call codes_read_from_file(ifile,buffer,len1,iret)
2013-03-25 12:04:10 +00:00
enddo
call codes_close_file(ifile)
call codes_close_file(ofile)
2013-03-25 12:04:10 +00:00
end program read_message