From 75d9b0ccc0f1b8854a16c7de9454cd92d42fbc93 Mon Sep 17 00:00:00 2001 From: Shahram Najm Date: Mon, 8 Jan 2024 13:42:39 +0000 Subject: [PATCH] Testing: Fortran read bytes --- examples/F90/CMakeLists.txt | 1 + examples/F90/grib_read_bytes.f90 | 27 +++++++++++++++++++++++++++ examples/F90/grib_read_bytes.sh | 12 ++++++++++++ fortran/grib_fortran.c | 2 ++ 4 files changed, 42 insertions(+) create mode 100644 examples/F90/grib_read_bytes.f90 create mode 100755 examples/F90/grib_read_bytes.sh diff --git a/examples/F90/CMakeLists.txt b/examples/F90/CMakeLists.txt index c8c291514..88b77e9fa 100644 --- a/examples/F90/CMakeLists.txt +++ b/examples/F90/CMakeLists.txt @@ -50,6 +50,7 @@ if( HAVE_BUILD_TOOLS ) grib_copy_namespace grib_read_message grib_read_from_file + grib_read_bytes grib_get_set_uuid grib_clone grib_ecc-1316 diff --git a/examples/F90/grib_read_bytes.f90 b/examples/F90/grib_read_bytes.f90 new file mode 100644 index 000000000..950eb2924 --- /dev/null +++ b/examples/F90/grib_read_bytes.f90 @@ -0,0 +1,27 @@ +! (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_read_bytes + use eccodes + implicit none + integer :: ifile + integer :: intsize + parameter(intsize=10000) + character, dimension(intsize) :: bufferChar + character(len=32) :: input_grib_file = '../../data/v.grib2' + + call codes_open_file(ifile, input_grib_file, 'r') + + ! First 4 chars should be 'GRIB' + call codes_read_bytes(ifile, bufferChar, 4) + print*, bufferChar(1:5) + + call codes_close_file(ifile) + +end program diff --git a/examples/F90/grib_read_bytes.sh b/examples/F90/grib_read_bytes.sh new file mode 100755 index 000000000..37858c63f --- /dev/null +++ b/examples/F90/grib_read_bytes.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_read_bytes diff --git a/fortran/grib_fortran.c b/fortran/grib_fortran.c index 2c0cbb0d4..d9ab1f459 100644 --- a/fortran/grib_fortran.c +++ b/fortran/grib_fortran.c @@ -840,6 +840,7 @@ static int clear_bufr_keys_iterator(int keys_iterator_id) } /*****************************************************************************/ +#if 0 int grib_f_read_any_headers_only_from_file_(int* fid, char* buffer, size_t* nbytes) { grib_context* c; int err=0; @@ -853,6 +854,7 @@ int grib_f_read_any_headers_only_from_file_(int* fid, char* buffer, size_t* nbyt return GRIB_INVALID_FILE; } } +#endif /*****************************************************************************/ int grib_f_read_any_from_file_(int* fid, void* buffer, size_t* nbytes) {