Skip to content

Commit

Permalink
Update CI workflows (#28)
Browse files Browse the repository at this point in the history
* Update CI workflows and grib_index_rewind fix

Update actions to latest versions and check newest eccodes. Fix for grib_index_rewind being removed from public API.
  • Loading branch information
nawendt authored Jul 12, 2024
1 parent 6508d2e commit c736322
Show file tree
Hide file tree
Showing 14 changed files with 83 additions and 78 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/check-latest.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/check-minimum.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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

Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/check-standard.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/lint.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/test-coverage.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
4 changes: 2 additions & 2 deletions DESCRIPTION
Original file line number Diff line number Diff line change
@@ -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 <nathan.wendt@noaa.gov>
Maintainer: Nathan Wendt <nathan.wendt@noaa.gov>
BugReports: https://github.com/nawendt/gribr/issues
Expand Down
3 changes: 0 additions & 3 deletions cleanup.win

This file was deleted.

18 changes: 9 additions & 9 deletions configure
Original file line number Diff line number Diff line change
@@ -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 <nathan.wendt@noaa.gov>.
#
Expand Down Expand Up @@ -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=''

Expand Down Expand Up @@ -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]...
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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\\"
Expand Down
2 changes: 1 addition & 1 deletion configure.ac
Original file line number Diff line number Diff line change
@@ -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])

Expand Down
16 changes: 0 additions & 16 deletions configure.win

This file was deleted.

6 changes: 0 additions & 6 deletions src/grib_api_extra.h

This file was deleted.

94 changes: 62 additions & 32 deletions src/grib_select.c
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
#include <string.h>

#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;
Expand Down Expand Up @@ -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
Expand All @@ -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) {
Expand All @@ -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) {
Expand All @@ -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);

Expand Down
2 changes: 1 addition & 1 deletion src/gribr.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion tests/testthat/test-messages.R
Original file line number Diff line number Diff line change
@@ -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
Expand Down

0 comments on commit c736322

Please sign in to comment.