eccodes/examples/F90/bufr_set_keys.f90

59 lines
1.7 KiB
Fortran
Raw Permalink Normal View History

2020-01-28 14:32:34 +00:00
! (C) Copyright 2005- ECMWF.
2015-02-06 14:23:28 +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
!
2015-02-06 14:23:28 +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.
!
!
2021-02-23 17:14:11 +00:00
! Description: How to set different type of keys in BUFR messages.
2015-02-06 14:23:28 +00:00
!
program bufr_set_keys
use eccodes
implicit none
integer :: iret
integer :: infile, outfile
integer :: ibufr
integer :: count = 0
integer(kind=4) :: centre, centreNew
2016-09-13 16:48:52 +00:00
! Open input file
call codes_open_file(infile, '../../data/bufr/syno_multi.bufr', 'r')
2016-09-13 16:48:52 +00:00
! Open output file
call codes_open_file(outfile, 'bufr_set_keys_test_f.tmp.bufr', 'w')
2016-09-13 16:48:52 +00:00
do while (.true.)
call codes_bufr_new_from_file(infile, ibufr, iret)
if (iret == CODES_END_OF_FILE) exit
2015-02-06 14:23:28 +00:00
write (*, *) 'message: ', count
2016-09-13 16:48:52 +00:00
! This is the place where you may wish to modify the message
! E.g. change the centre
2016-09-13 16:48:52 +00:00
! Set centre
centre = 222
call codes_set(ibufr, 'bufrHeaderCentre', 222)
write (*, *) ' set bufrHeaderCentre to:', centre
2016-09-13 16:48:52 +00:00
! Check centre's new value
centreNew = 0
call codes_get(ibufr, 'bufrHeaderCentre', centreNew)
write (*, *) ' bufrHeaderCentre''s new value:', centreNew
2016-09-13 16:48:52 +00:00
! Write modified message to a file
call codes_write(ibufr, outfile)
2016-09-13 16:48:52 +00:00
! Release the handle
call codes_release(ibufr)
2016-09-13 16:48:52 +00:00
count = count + 1
end do
2016-09-13 16:48:52 +00:00
call codes_close_file(infile)
call codes_close_file(outfile)
2015-02-06 14:23:28 +00:00
end program bufr_set_keys