2015-12-31 12:44:51 +00:00
|
|
|
! Copyright 2005-2016 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.
|
|
|
|
!
|
|
|
|
! 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
|
2016-06-21 13:58:04 +00:00
|
|
|
integer :: iret
|
2015-02-06 14:23:28 +00:00
|
|
|
integer :: infile,outfile
|
|
|
|
integer :: ibufr
|
|
|
|
integer :: count=0
|
|
|
|
integer(kind=4) :: centre, centreNew
|
|
|
|
|
|
|
|
! open input file
|
|
|
|
call codes_open_file(infile,'../../data/bufr/syno_multi.bufr','r')
|
|
|
|
|
|
|
|
! open output file
|
|
|
|
call codes_open_file(outfile,'bufr_set_keys_test_f.tmp.bufr','w')
|
|
|
|
|
|
|
|
! 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)
|
|
|
|
|
|
|
|
do while (iret/=CODES_END_OF_FILE)
|
|
|
|
|
|
|
|
write(*,*) 'message: ',count
|
|
|
|
|
|
|
|
! This is the place where you may wish to modify the message
|
2015-03-04 17:15:48 +00:00
|
|
|
! E.g. we change the centre
|
2015-02-06 14:23:28 +00:00
|
|
|
|
|
|
|
! set centre
|
|
|
|
centre=222
|
2015-03-04 17:15:48 +00:00
|
|
|
call codes_set(ibufr,'bufrHeaderCentre',222)
|
|
|
|
write(*,*) ' set bufrHeaderCentre to:',centre
|
2015-02-06 14:23:28 +00:00
|
|
|
|
|
|
|
! check centre's new value
|
|
|
|
centreNew=0
|
2015-03-04 17:15:48 +00:00
|
|
|
call codes_get(ibufr,'bufrHeaderCentre',centreNew)
|
|
|
|
write(*,*) ' bufrHeaderCentre''s new value:',centreNew
|
2015-02-06 14:23:28 +00:00
|
|
|
|
|
|
|
! write modified message to a file
|
|
|
|
call codes_write(ibufr,outfile)
|
|
|
|
|
|
|
|
! relase the handle
|
|
|
|
call codes_release(ibufr)
|
|
|
|
|
|
|
|
! next message from source
|
|
|
|
call codes_bufr_new_from_file(infile,ibufr,iret)
|
|
|
|
|
|
|
|
count=count+1
|
|
|
|
|
|
|
|
end do
|
|
|
|
|
|
|
|
call codes_close_file(infile)
|
|
|
|
call codes_close_file(outfile)
|
|
|
|
|
|
|
|
end program bufr_set_keys
|