diff --git a/.github/workflows/check-latest.yaml b/.github/workflows/check-latest.yaml index 6a69780..05a199b 100644 --- a/.github/workflows/check-latest.yaml +++ b/.github/workflows/check-latest.yaml @@ -30,10 +30,10 @@ jobs: env: GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }} R_KEEP_PKG_SOURCE: yes - ECCODES_VERSION: 2.29.0 + ECCODES_VERSION: 2.36.0 steps: - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 - uses: r-lib/actions/setup-pandoc@v2 diff --git a/.github/workflows/check-minimum.yaml b/.github/workflows/check-minimum.yaml index 9d1e6f7..9d0a441 100644 --- a/.github/workflows/check-minimum.yaml +++ b/.github/workflows/check-minimum.yaml @@ -33,7 +33,7 @@ jobs: ECCODES_VERSION: 2.19.0 steps: - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 - uses: r-lib/actions/setup-pandoc@v2 @@ -62,7 +62,7 @@ jobs: - name: Build eccodes from source (macOS) if: runner.os == 'macOS' env: - OPENJPEG_INCLUDE_DIR: /usr/local/include/openjpeg-2.5 + OPENJPEG_INCLUDE_DIR: /opt/homebrew/include/openjpeg-2.5 run: ./install_eccodes.sh shell: bash diff --git a/.github/workflows/check-standard.yaml b/.github/workflows/check-standard.yaml index 3d29504..961c3d4 100644 --- a/.github/workflows/check-standard.yaml +++ b/.github/workflows/check-standard.yaml @@ -33,7 +33,7 @@ jobs: R_KEEP_PKG_SOURCE: yes steps: - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 - uses: r-lib/actions/setup-pandoc@v2 diff --git a/.github/workflows/lint.yaml b/.github/workflows/lint.yaml index 79fe59c..180b461 100644 --- a/.github/workflows/lint.yaml +++ b/.github/workflows/lint.yaml @@ -19,7 +19,7 @@ jobs: env: GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }} steps: - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 - uses: r-lib/actions/setup-r@v2 with: diff --git a/.github/workflows/test-coverage.yaml b/.github/workflows/test-coverage.yaml index 688ce03..3250d40 100644 --- a/.github/workflows/test-coverage.yaml +++ b/.github/workflows/test-coverage.yaml @@ -20,7 +20,7 @@ jobs: GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }} steps: - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 - uses: r-lib/actions/setup-r@v2 with: diff --git a/DESCRIPTION b/DESCRIPTION index cf5b8f7..2feb71c 100755 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,8 +1,8 @@ Package: gribr Type: Package Title: Read GRIB Files -Version: 1.2.6 -Date: 2023-07-10 +Version: 1.2.7 +Date: 2024-07-12 Author: Nathan Wendt Maintainer: Nathan Wendt BugReports: https://github.com/nawendt/gribr/issues diff --git a/cleanup.win b/cleanup.win deleted file mode 100755 index bfa5610..0000000 --- a/cleanup.win +++ /dev/null @@ -1,3 +0,0 @@ -#!/bin/sh - -rm -f src/Makevars.win diff --git a/configure b/configure index 838c2af..3d7bfc9 100755 --- a/configure +++ b/configure @@ -1,6 +1,6 @@ #! /bin/sh # Guess values for system-dependent variables and create Makefiles. -# Generated by GNU Autoconf 2.71 for gribr 1.2.6. +# Generated by GNU Autoconf 2.71 for gribr 1.2.7. # # Report bugs to . # @@ -610,8 +610,8 @@ MAKEFLAGS= # Identity of this package. PACKAGE_NAME='gribr' PACKAGE_TARNAME='gribr' -PACKAGE_VERSION='1.2.6' -PACKAGE_STRING='gribr 1.2.6' +PACKAGE_VERSION='1.2.7' +PACKAGE_STRING='gribr 1.2.7' PACKAGE_BUGREPORT='nathan.wendt@noaa.gov' PACKAGE_URL='' @@ -1260,7 +1260,7 @@ if test "$ac_init_help" = "long"; then # Omit some internal or obsolete options to make the list less imposing. # This message is too long to be a string in the A/UX 3.1 sh. cat <<_ACEOF -\`configure' configures gribr 1.2.6 to adapt to many kinds of systems. +\`configure' configures gribr 1.2.7 to adapt to many kinds of systems. Usage: $0 [OPTION]... [VAR=VALUE]... @@ -1322,7 +1322,7 @@ fi if test -n "$ac_init_help"; then case $ac_init_help in - short | recursive ) echo "Configuration of gribr 1.2.6:";; + short | recursive ) echo "Configuration of gribr 1.2.7:";; esac cat <<\_ACEOF @@ -1406,7 +1406,7 @@ fi test -n "$ac_init_help" && exit $ac_status if $ac_init_version; then cat <<\_ACEOF -gribr configure 1.2.6 +gribr configure 1.2.7 generated by GNU Autoconf 2.71 Copyright (C) 2021 Free Software Foundation, Inc. @@ -1624,7 +1624,7 @@ cat >config.log <<_ACEOF This file contains any messages produced by compilers while running configure, to aid debugging if configure makes a mistake. -It was created by gribr $as_me 1.2.6, which was +It was created by gribr $as_me 1.2.7, which was generated by GNU Autoconf 2.71. Invocation command line was $ $0$ac_configure_args_raw @@ -4235,7 +4235,7 @@ cat >>$CONFIG_STATUS <<\_ACEOF || ac_write_fail=1 # report actual input values of CONFIG_FILES etc. instead of their # values after options handling. ac_log=" -This file was extended by gribr $as_me 1.2.6, which was +This file was extended by gribr $as_me 1.2.7, which was generated by GNU Autoconf 2.71. Invocation command line was CONFIG_FILES = $CONFIG_FILES @@ -4290,7 +4290,7 @@ ac_cs_config_escaped=`printf "%s\n" "$ac_cs_config" | sed "s/^ //; s/'/'\\\\\\\\ cat >>$CONFIG_STATUS <<_ACEOF || ac_write_fail=1 ac_cs_config='$ac_cs_config_escaped' ac_cs_version="\\ -gribr config.status 1.2.6 +gribr config.status 1.2.7 configured by $0, generated by GNU Autoconf 2.71, with options \\"\$ac_cs_config\\" diff --git a/configure.ac b/configure.ac index 2fef6e2..1770016 100644 --- a/configure.ac +++ b/configure.ac @@ -1,4 +1,4 @@ -AC_INIT([gribr],[1.2.6],[nathan.wendt@noaa.gov]) +AC_INIT([gribr],[1.2.7],[nathan.wendt@noaa.gov]) AC_CONFIG_MACRO_DIR([tools/m4]) diff --git a/configure.win b/configure.win deleted file mode 100755 index 2e94d83..0000000 --- a/configure.win +++ /dev/null @@ -1,16 +0,0 @@ -#!/bin/sh - -# This is the Windows configure script for gribr. This is included -# for those that would like to build the ecCodes on Windows using -# MinGW. This is currently experimental. - -# PKG_CFLAGS should at least contain the INCLUDE directory of your -# ecCodes build. Other pertinent compiler flags will also go here. - -# PKG_LIBS will contain the LIB directory of your ecCodes build. - -PKG_CPPFLAGS= -PKG_LIBS= - -echo "PKG_CPPFLAGS=$PKG_CPPFLAGS" > src/Makevars.win -echo "PKG_LIBS=$PKG_LIBS" >> src/Makevars.win diff --git a/src/grib_api_extra.h b/src/grib_api_extra.h deleted file mode 100644 index ece16f9..0000000 --- a/src/grib_api_extra.h +++ /dev/null @@ -1,6 +0,0 @@ -/* -* This header contains functions/structs in ecCodes that have not been -* made public via the main header but are used by gribr -*/ - -void grib_index_rewind(grib_index* index); diff --git a/src/grib_select.c b/src/grib_select.c index 19664f0..9e7f6cf 100644 --- a/src/grib_select.c +++ b/src/grib_select.c @@ -4,7 +4,6 @@ #include #include "gribr.h" -#include "grib_api_extra.h" SEXP gribr_select(SEXP gribr_filePath, SEXP gribr_fileHandle, SEXP gribr_keyList, SEXP gribr_isMulti) { int err; @@ -87,16 +86,10 @@ SEXP gribr_select(SEXP gribr_filePath, SEXP gribr_fileHandle, SEXP gribr_keyList codes_grib_multi_support_on(DEFAULT_CONTEXT); } - index = codes_index_new(DEFAULT_CONTEXT, keyString, &err); + index = codes_index_new_from_file(DEFAULT_CONTEXT, filePath, keyString, &err); if (err) { gerror("unable to create index", err); } - nfree(keyString); - - err = codes_index_add_file(index, filePath); - if (err) { - gerror("unable to add file to index", err); - } /* Have to grab handle from file first in order to get * native key types. Will not work with handle from @@ -112,37 +105,42 @@ SEXP gribr_select(SEXP gribr_filePath, SEXP gribr_fileHandle, SEXP gribr_keyList if (i % INTERRUPT_FREQ == 0) { R_CheckUserInterrupt(); } + lenKeys = xlength(VECTOR_ELT(gribr_keyList, i)); + for (j = 0; j < lenKeys; j++) { keyName = CHAR(STRING_ELT(getAttrib(VECTOR_ELT(gribr_keyList, i), R_NamesSymbol), j)); err = codes_get_native_type(h, keyName, &keyType); + if (err) { gerror("unable to get native type", err); } + switch (keyType) { - case CODES_TYPE_DOUBLE: - kd = asReal(VECTOR_ELT(VECTOR_ELT(gribr_keyList, i), j)); - codes_index_select_double(index, keyName, kd); - break; - case CODES_TYPE_LONG: - /* Need to coerce vector to integer as R list components entered - * as integers really end up being numeric (double in C). Doing - * corecion here makes the most sense as the type gets deciced in - * the get_naitve_type call. The C routines know more about the - * typing than the R routines. - */ - ki = (long)asReal(VECTOR_ELT(VECTOR_ELT(gribr_keyList, i), j)); - codes_index_select_long(index, keyName, ki); - break; - case CODES_TYPE_STRING: - ks = CHAR(asChar(VECTOR_ELT(VECTOR_ELT(gribr_keyList, i), j))); - codes_index_select_string(index, keyName, ks); - break; - default: - /* Skip other key types with no codes_select_* methods to handle them */ - break; - } + case CODES_TYPE_DOUBLE: + kd = asReal(VECTOR_ELT(VECTOR_ELT(gribr_keyList, i), j)); + codes_index_select_double(index, keyName, kd); + break; + case CODES_TYPE_LONG: + /* Need to coerce vector to integer as R list components entered + * as integers really end up being numeric (double in C). Doing + * corecion here makes the most sense as the type gets deciced in + * the get_naitve_type call. The C routines know more about the + * typing than the R routines. + */ + ki = (long)asReal(VECTOR_ELT(VECTOR_ELT(gribr_keyList, i), j)); + codes_index_select_long(index, keyName, ki); + break; + case CODES_TYPE_STRING: + ks = CHAR(asChar(VECTOR_ELT(VECTOR_ELT(gribr_keyList, i), j))); + codes_index_select_string(index, keyName, ks); + break; + default: + /* Skip other key types with no codes_select_* methods to handle them */ + break; + } } + index_count = 0; while((hi = codes_handle_new_from_index(index, &err))) { if (err) { @@ -156,10 +154,41 @@ SEXP gribr_select(SEXP gribr_filePath, SEXP gribr_fileHandle, SEXP gribr_keyList error("gribr: no messages matched"); } - grib_index_rewind(index); - REPROTECT(gribr_temp = allocVector(VECSXP, index_count), pro_temp); + /* Recreate index and redo selections. This is done as the index will have been + * consumed to figure out the size of the vector needed. grib_index_rewind is no + * longer available to do this efficiently. This will suffice until a better + * approach is developed or exposed in the public API. + */ + index = codes_index_new_from_file(DEFAULT_CONTEXT, filePath, keyString, &err); + + for (j = 0; j < lenKeys; j++) { + keyName = CHAR(STRING_ELT(getAttrib(VECTOR_ELT(gribr_keyList, i), R_NamesSymbol), j)); + err = codes_get_native_type(h, keyName, &keyType); + + if (err) { + gerror("unable to get native type", err); + } + + switch (keyType) { + case CODES_TYPE_DOUBLE: + kd = asReal(VECTOR_ELT(VECTOR_ELT(gribr_keyList, i), j)); + codes_index_select_double(index, keyName, kd); + break; + case CODES_TYPE_LONG: + ki = (long)asReal(VECTOR_ELT(VECTOR_ELT(gribr_keyList, i), j)); + codes_index_select_long(index, keyName, ki); + break; + case CODES_TYPE_STRING: + ks = CHAR(asChar(VECTOR_ELT(VECTOR_ELT(gribr_keyList, i), j))); + codes_index_select_string(index, keyName, ks); + break; + default: + break; + } + } + m = 0; while((hi = codes_handle_new_from_index(index, &err)) && m < index_count) { if (err) { @@ -174,6 +203,7 @@ SEXP gribr_select(SEXP gribr_filePath, SEXP gribr_fileHandle, SEXP gribr_keyList codes_handle_delete(h); codes_index_delete(index); + nfree(keyString); grewind(file); diff --git a/src/gribr.h b/src/gribr.h index e9ba892..f820144 100644 --- a/src/gribr.h +++ b/src/gribr.h @@ -14,7 +14,7 @@ SEXP gribr_grib_open(SEXP gribr_fileName); SEXP gribr_grib_list(SEXP gribr_fileHandle, SEXP gribr_filter, SEXP gribr_namespace, SEXP gribr_isMulti); SEXP gribr_grib_df(SEXP gribr_fileHandle, SEXP gribr_filter, - SEXP gribr_namespace, SEXP gribr_isMulti); + SEXP gribr_namespace, SEXP gribr_isMulti); SEXP gribr_grib_length(SEXP gribr_fileHandle); SEXP gribr_is_null_ptr (SEXP gribr_ptr); diff --git a/tests/testthat/test-messages.R b/tests/testthat/test-messages.R index add2428..a0ee437 100644 --- a/tests/testthat/test-messages.R +++ b/tests/testthat/test-messages.R @@ -1,6 +1,6 @@ context("GRIB message retrieval and attributes") -test_that("Incorrect message requests are handled correctly", { +test_that("Message requests are handled correctly", { g <- grib_open(system.file("extdata", "lfpw.grib1", package = "gribr")) # grib_get_message