From 96edabfea1eefc082b3f0287bc7888a2eeffc027 Mon Sep 17 00:00:00 2001 From: Shahram Najm Date: Sat, 30 Dec 2023 17:56:53 +0000 Subject: [PATCH] Testing: F90 get_elements --- examples/F90/CMakeLists.txt | 2 ++ examples/F90/grib_elements.f90 | 37 ++++++++++++++++++++++++++++++++++ examples/F90/grib_elements.sh | 12 +++++++++++ fortran/grib_f90_tail.f90 | 12 +++++------ 4 files changed, 57 insertions(+), 6 deletions(-) create mode 100644 examples/F90/grib_elements.f90 create mode 100755 examples/F90/grib_elements.sh diff --git a/examples/F90/CMakeLists.txt b/examples/F90/CMakeLists.txt index 4ef373c4c..ead88a487 100644 --- a/examples/F90/CMakeLists.txt +++ b/examples/F90/CMakeLists.txt @@ -33,6 +33,7 @@ if( HAVE_BUILD_TOOLS ) grib_keys_iterator_skip grib_multi_write grib_multi + grib_elements grib_nearest grib_nearest_single grib_precision @@ -86,6 +87,7 @@ else() grib_keys_iterator_skip grib_multi grib_nearest + grib_elements grib_nearest_single grib_precision grib_print_data diff --git a/examples/F90/grib_elements.f90 b/examples/F90/grib_elements.f90 new file mode 100644 index 000000000..f9cad8d2c --- /dev/null +++ b/examples/F90/grib_elements.f90 @@ -0,0 +1,37 @@ +! (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. +! +! +program grib_get_elements + use eccodes + implicit none + + integer :: infile + integer :: igrib, i + real(4) :: values_real4(4) + real(8) :: values_real8(4) + integer :: array_of_indexes(4) + + call codes_open_file(infile, '../../data/reduced_gaussian_pressure_level.grib1', 'r') + call codes_grib_new_from_file(infile, igrib) + + array_of_indexes = [1, 0, 2, 4] + call codes_get_element(igrib, "values", array_of_indexes, values_real4) + do i = 1, 4 + print *, i, array_of_indexes(i), values_real4(i) + end do + + call codes_get_element(igrib, "values", array_of_indexes, values_real8) + do i = 1, 4 + print *, i, array_of_indexes(i), values_real8(i) + end do + + call codes_release(igrib) + call codes_close_file(infile) + +end program diff --git a/examples/F90/grib_elements.sh b/examples/F90/grib_elements.sh new file mode 100755 index 000000000..86ad91414 --- /dev/null +++ b/examples/F90/grib_elements.sh @@ -0,0 +1,12 @@ +#!/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.ctest.sh + +${examples_dir}/eccodes_f_grib_elements diff --git a/fortran/grib_f90_tail.f90 b/fortran/grib_f90_tail.f90 index ddaad835f..c178eedbe 100644 --- a/fortran/grib_f90_tail.f90 +++ b/fortran/grib_f90_tail.f90 @@ -2316,7 +2316,7 @@ if (present(status)) then status = iret else - call grib_check(iret, 'get', key) + call grib_check(iret, 'get_real4_elements', key) end if end subroutine grib_get_real4_elements @@ -2348,7 +2348,7 @@ if (present(status)) then status = iret else - call grib_check(iret, 'get', key) + call grib_check(iret, 'get_real8_elements', key) end if end subroutine grib_get_real8_elements @@ -2649,7 +2649,7 @@ if (present(status)) then status = iret else - call grib_check(iret, 'set', key) + call grib_check(iret, 'set_force_real4_array', key) end if end subroutine grib_set_force_real4_array @@ -2680,7 +2680,7 @@ if (present(status)) then status = iret else - call grib_check(iret, 'set', key) + call grib_check(iret, 'set_force_real8_array', key) end if end subroutine grib_set_force_real8_array @@ -3057,7 +3057,7 @@ if (present(status)) then status = iret else - call grib_check(iret, 'grib_gribex_mode_on', '') + call grib_check(iret, 'gribex_mode_on', '') end if end subroutine grib_gribex_mode_on @@ -3077,7 +3077,7 @@ if (present(status)) then status = iret else - call grib_check(iret, 'grib_gribex_mode_off', '') + call grib_check(iret, 'gribex_mode_off', '') end if end subroutine grib_gribex_mode_off