eccodes/examples/F90/grib_set_gvc.f90

68 lines
1.9 KiB
Fortran
Raw Normal View History

2019-04-15 13:44:45 +00:00
! Copyright 2005-2019 ECMWF.
!
! 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
!
! 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.
!
!
!
! Description: how to set keys for a grib2 file with
! a Generalized Vertical Height Coordinate
!
!
program set
2015-01-28 22:54:42 +00:00
use eccodes
implicit none
integer :: infile,outfile
integer :: igrib
call codes_open_file(infile, '../../data/sample.grib2','r')
call codes_open_file(outfile, 'out_gvc.grib2','w')
2015-03-04 17:11:18 +00:00
call codes_grib_new_from_file(infile,igrib)
! Individual ensemble forecast
call codes_set(igrib,'productDefinitionTemplateNumber', 11)
2017-02-06 16:45:30 +00:00
! Select level type as Generalized Vertical Height Coordinate
call codes_set(igrib,'typeOfLevel', 'generalVertical')
2017-02-06 16:45:30 +00:00
! Now set keys specific to this level type
call codes_set(igrib,'nlev', 12.21)
call codes_set(igrib,'numberOfVGridUsed', 13.55)
! check integrity of GRIB message
call check_settings(igrib)
! write modified message to a file
call codes_write(igrib,outfile)
call codes_release(igrib)
call codes_close_file(infile)
call codes_close_file(outfile)
contains
!======================================
subroutine check_settings(gribid)
implicit none
integer, intent(in) :: gribid
2017-02-06 16:45:30 +00:00
integer(kind = 4) :: NV,typeOfFirstFixedSurface
call codes_get(gribid,'NV', NV)
if (NV /= 6) then
call codes_check(-2, 'NV_should_be_6', '')
end if
call codes_get(gribid,'typeOfFirstFixedSurface', typeOfFirstFixedSurface)
if (typeOfFirstFixedSurface /= 150) then
call codes_check(-2, 'typeOfFirstFixedSurface_should_be_150', '')
end if
2017-02-06 16:45:30 +00:00
end subroutine check_settings
end program set