eccodes/examples/F90/bufr_set_keys.f90

67 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.
!
2015-02-09 15:41:15 +00:00
! FORTRAN 90 implementation: bufr_set_keys
2015-02-06 14:23:28 +00:00
!
2015-02-09 15:41:15 +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
2015-02-06 14:23:28 +00:00
integer :: infile,outfile
integer :: ibufr
integer :: count=0
integer(kind=4) :: centre, centreNew
2016-09-13 16:48:52 +00:00
2016-12-29 15:53:10 +00:00
! Open input file
2015-02-06 14:23:28 +00:00
call codes_open_file(infile,'../../data/bufr/syno_multi.bufr','r')
2016-09-13 16:48:52 +00:00
2016-12-29 15:53:10 +00:00
! Open output file
2015-02-06 14:23:28 +00:00
call codes_open_file(outfile,'bufr_set_keys_test_f.tmp.bufr','w')
2016-09-13 16:48:52 +00:00
2016-12-29 15:53:10 +00:00
! The first bufr message is loaded from file,
2015-02-06 14:23:28 +00:00
! ibufr is the bufr id to be used in subsequent calls
call codes_bufr_new_from_file(infile,ibufr,iret)
do while (iret/=CODES_END_OF_FILE)
write(*,*) 'message: ',count
2016-09-13 16:48:52 +00:00
2017-02-06 16:45:30 +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
2016-12-29 15:53:10 +00:00
! Set centre
2015-02-06 14:23:28 +00:00
centre=222
call codes_set(ibufr,'bufrHeaderCentre',222)
write(*,*) ' set bufrHeaderCentre to:',centre
2016-09-13 16:48:52 +00:00
2016-12-29 15:53:10 +00:00
! Check centre's new value
2015-02-06 14:23:28 +00:00
centreNew=0
call codes_get(ibufr,'bufrHeaderCentre',centreNew)
write(*,*) ' bufrHeaderCentre''s new value:',centreNew
2016-09-13 16:48:52 +00:00
2016-12-29 15:53:10 +00:00
! Write modified message to a file
2015-02-06 14:23:28 +00:00
call codes_write(ibufr,outfile)
2016-09-13 16:48:52 +00:00
2016-12-29 15:53:10 +00:00
! Release the handle
2015-02-06 14:23:28 +00:00
call codes_release(ibufr)
2016-09-13 16:48:52 +00:00
2016-12-29 15:53:10 +00:00
! Next message from source
2015-02-06 14:23:28 +00:00
call codes_bufr_new_from_file(infile,ibufr,iret)
2016-09-13 16:48:52 +00:00
2015-02-06 14:23:28 +00:00
count=count+1
2016-09-13 16:48:52 +00:00
2015-02-06 14:23:28 +00:00
end do
2016-09-13 16:48:52 +00:00
2015-02-06 14:23:28 +00:00
call codes_close_file(infile)
call codes_close_file(outfile)
end program bufr_set_keys