eccodes/examples/F90/bufr_set_keys.f90

66 lines
2.0 KiB
Fortran
Raw 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
! The first bufr message is loaded from file,
! ibufr is the bufr id to be used in subsequent calls
call codes_bufr_new_from_file(infile, ibufr, iret)
2015-02-06 14:23:28 +00:00
do while (iret /= CODES_END_OF_FILE)
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. we 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
! Next message from source
call codes_bufr_new_from_file(infile, ibufr, iret)
2016-09-13 16:48:52 +00:00
count = count + 1
2016-09-13 16:48:52 +00:00
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