2020-01-28 14:32:34 +00:00
|
|
|
! (C) Copyright 2005- 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.
|
|
|
|
!
|
|
|
|
!
|
|
|
|
!
|
2015-12-30 16:37:45 +00:00
|
|
|
! Description: how to set a bitmap in a GRIB message
|
2016-11-21 13:10:21 +00:00
|
|
|
! to encode missing values in the data
|
2013-03-25 12:04:10 +00:00
|
|
|
!
|
|
|
|
!
|
|
|
|
program set_bitmap
|
2015-01-28 22:54:42 +00:00
|
|
|
use eccodes
|
2013-03-25 12:04:10 +00:00
|
|
|
implicit none
|
|
|
|
integer :: infile,outfile
|
|
|
|
integer :: igrib, iret
|
|
|
|
integer :: numberOfValues
|
|
|
|
real, dimension(:), allocatable :: values
|
|
|
|
real :: missingValue
|
|
|
|
logical :: grib1Example
|
|
|
|
|
|
|
|
grib1Example=.true.
|
|
|
|
|
|
|
|
if (grib1Example) then
|
|
|
|
! GRIB 1 example
|
2015-01-07 16:11:28 +00:00
|
|
|
call codes_open_file(infile,'../../data/regular_latlon_surface.grib1','r')
|
2013-03-25 12:04:10 +00:00
|
|
|
else
|
|
|
|
! GRIB 2 example
|
2015-01-07 16:11:28 +00:00
|
|
|
call codes_open_file(infile,'../../data/regular_latlon_surface.grib2','r')
|
2013-03-25 12:04:10 +00:00
|
|
|
end if
|
2017-02-06 16:45:30 +00:00
|
|
|
|
2016-01-05 14:32:24 +00:00
|
|
|
call codes_open_file(outfile,'out.set_bitmap_f.grib','w')
|
2017-02-06 16:45:30 +00:00
|
|
|
|
2015-12-30 16:37:45 +00:00
|
|
|
! A new grib message is loaded from file
|
|
|
|
! igrib is the grib id to be used in subsequent calls
|
2015-03-04 17:11:18 +00:00
|
|
|
call codes_grib_new_from_file(infile,igrib)
|
2017-02-06 16:45:30 +00:00
|
|
|
|
|
|
|
! The missingValue is not coded in the message.
|
2013-03-25 12:04:10 +00:00
|
|
|
! It is a value we define as a placeholder for a missing value
|
2015-12-30 16:37:45 +00:00
|
|
|
! at a point in the grid.
|
2017-02-06 16:45:30 +00:00
|
|
|
! It should be chosen so that it cannot be confused
|
2013-03-25 12:04:10 +00:00
|
|
|
! with a valid field value
|
|
|
|
missingValue=9999
|
2015-01-07 16:11:28 +00:00
|
|
|
call codes_set(igrib, 'missingValue',missingValue)
|
2013-03-25 12:04:10 +00:00
|
|
|
write(*,*) 'missingValue=',missingValue
|
|
|
|
|
|
|
|
! get the size of the values array
|
2015-01-07 16:11:28 +00:00
|
|
|
call codes_get_size(igrib,'values',numberOfValues)
|
2013-03-25 12:04:10 +00:00
|
|
|
write(*,*) 'numberOfValues=',numberOfValues
|
2017-02-06 16:45:30 +00:00
|
|
|
|
2013-03-25 12:04:10 +00:00
|
|
|
allocate(values(numberOfValues), stat=iret)
|
|
|
|
|
|
|
|
! get data values
|
2015-01-07 16:11:28 +00:00
|
|
|
call codes_get(igrib,'values',values)
|
2017-02-06 16:45:30 +00:00
|
|
|
|
|
|
|
! enable bitmap
|
2015-12-30 16:37:45 +00:00
|
|
|
call codes_set(igrib, 'bitmapPresent', 1)
|
2013-03-25 12:04:10 +00:00
|
|
|
|
2015-12-30 16:37:45 +00:00
|
|
|
! set some values to be missing
|
2013-03-25 12:04:10 +00:00
|
|
|
values(1:10) = missingValue
|
|
|
|
|
|
|
|
! set the values (the bitmap will be automatically built)
|
2015-01-07 16:11:28 +00:00
|
|
|
call codes_set(igrib,'values', values)
|
2013-03-25 12:04:10 +00:00
|
|
|
|
|
|
|
! write modified message to a file
|
2015-01-07 16:11:28 +00:00
|
|
|
call codes_write(igrib,outfile)
|
2017-02-06 16:45:30 +00:00
|
|
|
|
2015-12-30 16:37:45 +00:00
|
|
|
! free memory
|
2015-01-07 16:11:28 +00:00
|
|
|
call codes_release(igrib)
|
2017-02-06 16:45:30 +00:00
|
|
|
|
2015-01-07 16:11:28 +00:00
|
|
|
call codes_close_file(infile)
|
|
|
|
call codes_close_file(outfile)
|
2013-03-25 12:04:10 +00:00
|
|
|
|
|
|
|
deallocate(values)
|
|
|
|
|
|
|
|
end program set_bitmap
|