Testing: add Fortran test for encoding with a packingType

This commit is contained in:
Shahram Najm 2021-01-13 20:52:50 +00:00
parent 2eb51e5249
commit 08af171c0a
3 changed files with 95 additions and 0 deletions

View File

@ -115,6 +115,14 @@ foreach( tool ${tests_extra} )
TEST_DEPENDS eccodes_download_gribs eccodes_download_bufrs ) TEST_DEPENDS eccodes_download_gribs eccodes_download_bufrs )
endforeach() endforeach()
# Test for CCSDS (AEC) packing
ecbuild_add_test( TARGET eccodes_f_grib_set_packing
SOURCES grib_set_packing.f90
LINKER_LANGUAGE Fortran
LIBS eccodes_f90 eccodes
CONDITION HAVE_AEC AND HAVE_FORTRAN
COMMAND ${CMAKE_CURRENT_SOURCE_DIR}/grib_set_packing.sh )
# Executables without a shell script # Executables without a shell script
# TODO # TODO
ecbuild_add_executable( TARGET eccodes_f_new_from_file ecbuild_add_executable( TARGET eccodes_f_new_from_file

View File

@ -0,0 +1,54 @@
! (C) Copyright 2005- 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.
!
! 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: set the packingType in a GRIB file
! e.g. Simple packing, CCSDS
!
program set_packing
use eccodes
implicit none
integer :: outfile
integer :: i, igrib, iret, numberOfValues, cnt
real :: d, e
real, dimension(:), allocatable :: values
integer, parameter :: max_strsize = 200
character(len=max_strsize) :: outfile_name, packing_type
call getarg(1, packing_type)
call getarg(2, outfile_name)
call codes_open_file(outfile,outfile_name,'w')
call codes_grib_new_from_samples(igrib, 'gg_sfc_grib2')
call codes_get_size(igrib,'values', numberOfValues)
allocate(values(numberOfValues), stat=iret)
d = 10e-6
e = d
cnt = 1
do i=1,numberOfValues
if (cnt>100) then
e = e*1.01
cnt=1
endif
values(i) = d
d = d + e
cnt = cnt + 1
end do
call codes_set(igrib, 'numberOfBitsContainingEachPackedValue', 16)
call codes_set(igrib, 'packingType', packing_type)
! set data values
call codes_set(igrib, 'values', values)
call codes_write(igrib, outfile)
call codes_release(igrib)
deallocate(values)
end program set_packing

View File

@ -0,0 +1,33 @@
#!/bin/sh
# (C) Copyright 2005- 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.
#
# 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.
. ./include.sh
tempSimple=temp.f_grib_set_packing.simple.grib
tempSecond=temp.f_grib_set_packing.second.grib
tempCCSDS=temp.f_grib_set_packing.ccsds.grib
${examples_dir}/eccodes_f_grib_set_packing grid_simple $tempSimple
${examples_dir}/eccodes_f_grib_set_packing grid_second_order $tempSecond
${examples_dir}/eccodes_f_grib_set_packing grid_ccsds $tempCCSDS
${tools_dir}/grib_ls -P packingType -n statistics $tempSimple $tempCCSDS $tempSecond
p=`${tools_dir}/grib_get -p packingType $tempSimple`
[ "$p" = "grid_simple" ]
p=`${tools_dir}/grib_get -p packingType $tempSecond`
[ "$p" = "grid_second_order" ]
p=`${tools_dir}/grib_get -p packingType $tempCCSDS`
[ "$p" = "grid_ccsds" ]
${tools_dir}/grib_compare -c data:n $tempSimple $tempCCSDS
${tools_dir}/grib_compare -c data:n $tempSimple $tempSecond
rm -f $tempSimple $tempCCSDS