From 0bf6d79c0d37078b08952af0d3b9ffa0fa0827ce Mon Sep 17 00:00:00 2001 From: Shahram Najm Date: Fri, 24 Jan 2020 14:27:54 +0000 Subject: [PATCH] ECC-1064: Fortran: Implement codes_get_api_version() --- examples/F90/get_product_kind.f90 | 4 ++++ examples/F90/get_product_kind.sh | 8 ++++++-- fortran/eccodes_f90_tail.f90 | 20 ++++++++++++++++++++ fortran/eccodes_visibility.h | 1 + fortran/grib_fortran.c | 12 ++++++++++++ fortran/grib_fortran_prototypes.h | 5 +++++ 6 files changed, 48 insertions(+), 2 deletions(-) diff --git a/examples/F90/get_product_kind.f90 b/examples/F90/get_product_kind.f90 index 582cfc5de..91773151a 100644 --- a/examples/F90/get_product_kind.f90 +++ b/examples/F90/get_product_kind.f90 @@ -20,6 +20,7 @@ program get_product_kind integer :: iret integer :: ihandle integer :: count=0 + integer :: version=0 character(len=32) :: product_kind character(len=120) :: infile_name @@ -27,6 +28,9 @@ program get_product_kind write(*,*) 'infile_name|',infile_name,'|' call codes_open_file(ifile,infile_name,'r') + call codes_get_api_version(version) + write(*,*) 'API version: ',version + ! the first message is loaded from file ! ihandle is the message id to be used in subsequent calls call codes_new_from_file(ifile,ihandle,CODES_PRODUCT_ANY,iret) diff --git a/examples/F90/get_product_kind.sh b/examples/F90/get_product_kind.sh index fa1dc9f61..217f5918f 100755 --- a/examples/F90/get_product_kind.sh +++ b/examples/F90/get_product_kind.sh @@ -12,10 +12,14 @@ label="get_product_kind_f" fTmp=${label}.tmp +fOut=${label}.out # Create a file containing both GRIB and BUFR messages cat ${data_dir}/sample.grib2 ${data_dir}/bufr/syno_multi.bufr >$fTmp -${examples_dir}/eccodes_f_get_product_kind $fTmp >/dev/null 2>&1 +${examples_dir}/eccodes_f_get_product_kind $fTmp > $fOut +cat $fOut +grep -q "product: BUFR" $fOut +grep -q "product: GRIB" $fOut -rm -f ${fTmp} +rm -f $fTmp $fOut diff --git a/fortran/eccodes_f90_tail.f90 b/fortran/eccodes_f90_tail.f90 index f4e81d0c3..31a8e73ee 100644 --- a/fortran/eccodes_f90_tail.f90 +++ b/fortran/eccodes_f90_tail.f90 @@ -1545,6 +1545,26 @@ subroutine codes_dump ( msgid , status) call grib_dump (msgid, status) end subroutine codes_dump + + !> Get the API version + !> + !> In case of error, if the status parameter (optional) is not given, the program will + !> exit with an error message.\n Otherwise the error message can be + !> gathered with @ref grib_get_error_string. + !> + !> @param api_version The version as an integer + !> @param status GRIB_SUCCESS if OK, integer value on error +subroutine codes_get_api_version(api_version, status) + integer(kind = kindOfInt), intent(out) :: api_version + integer(kind=kindOfInt),optional, intent(out) :: status + + call grib_f_get_api_version(api_version) + if (present(status)) then + status = CODES_SUCCESS + endif +end subroutine codes_get_api_version + + !> Get the error message given an error code !> !> @param error error code diff --git a/fortran/eccodes_visibility.h b/fortran/eccodes_visibility.h index d057f4361..ad3cf2fbd 100644 --- a/fortran/eccodes_visibility.h +++ b/fortran/eccodes_visibility.h @@ -26,6 +26,7 @@ public :: codes_new_from_message, & public :: codes_release public :: codes_dump public :: codes_get_error_string +public :: codes_get_api_version public :: codes_get_size public :: codes_get_message_size, codes_copy_message public :: codes_write, codes_grib_multi_append diff --git a/fortran/grib_fortran.c b/fortran/grib_fortran.c index f9235c5ce..a804e2c6c 100644 --- a/fortran/grib_fortran.c +++ b/fortran/grib_fortran.c @@ -2160,6 +2160,18 @@ int grib_f_get_error_string(int* err, char* buf, int len){ return grib_f_get_error_string_(err,buf,len); } +/*****************************************************************************/ +int grib_f_get_api_version_(int* apiVersion,int len){ + *apiVersion = grib_get_api_version(); + return GRIB_SUCCESS; +} +int grib_f_get_api_version__(int* apiVersion, int len){ + return grib_f_get_api_version_(apiVersion, len); +} +int grib_f_get_api_version(int* apiVersion, int len){ + return grib_f_get_api_version_(apiVersion, len); +} + /*****************************************************************************/ int grib_f_get_size_int_(int* gid, char* key, int* val, int len){ grib_handle *h = get_handle(*gid); diff --git a/fortran/grib_fortran_prototypes.h b/fortran/grib_fortran_prototypes.h index 2c3dd1698..1676eefac 100644 --- a/fortran/grib_fortran_prototypes.h +++ b/fortran/grib_fortran_prototypes.h @@ -202,6 +202,11 @@ int grib_f_dump(int *gid); int grib_f_print_(int *gid, char *key, int len); int grib_f_print__(int *gid, char *key, int len); int grib_f_print(int *gid, char *key, int len); + +int grib_f_get_api_version_(int* apiVersion,int len); +int grib_f_get_api_version__(int* apiVersion,int len); +int grib_f_get_api_version(int* apiVersion,int len); + int grib_f_get_error_string_(int *err, char *buf, int len); int grib_f_get_error_string__(int *err, char *buf, int len); int grib_f_get_error_string(int *err, char *buf, int len);