Python3: Enable Python 2 to work as before

This commit is contained in:
Shahram Najm 2018-11-23 19:11:47 +00:00
parent fdb2eff4d0
commit 832ed60f3c
50 changed files with 22604 additions and 3916 deletions

View File

@ -347,7 +347,15 @@ add_subdirectory( memfs )
add_subdirectory( src )
add_subdirectory( tools )
add_subdirectory( fortran )
add_subdirectory( python )
if (PYTHON_VERSION_MAJOR GREATER 2)
ecbuild_info("Adding python3 directory ${PYTHON_VERSION_STRING}")
add_subdirectory( python3 )
set( ECCODES_PYTHON_DIR "python3" )
else()
ecbuild_info("Adding python2 directory ${PYTHON_VERSION_STRING}")
add_subdirectory( python )
set( ECCODES_PYTHON_DIR "python2" )
endif()
add_subdirectory( tests )
add_subdirectory( tigge )
add_subdirectory( examples )

View File

@ -10,7 +10,7 @@
# Description: how to encode flight dataset into BUFR
from __future__ import print_function
from datetime import datetime
import traceback
import numpy as np

View File

@ -18,7 +18,7 @@ samp_dir="@CMAKE_BINARY_DIR@/@ECCODES_SAMPLES_SUFF@"
ECCODES_SAMPLES_PATH=${samp_dir}
export ECCODES_SAMPLES_PATH
PYTHONPATH=@PROJECT_BINARY_DIR@/python:$PYTHONPATH
PYTHONPATH=@PROJECT_BINARY_DIR@/@ECCODES_PYTHON_DIR@:$PYTHONPATH
export PYTHONPATH
echo "Current directory: `pwd`"

127
python/Makefile.am Normal file
View File

@ -0,0 +1,127 @@
if WITH_PYTHON
if CREATING_SHARED_LIBS
###############################################################################
# Case when shared libraries are enabled
###############################################################################
pkgpyexec_LTLIBRARIES = _gribapi_swig.la
_gribapi_swig_la_SOURCES = gribapi_swig_wrap.c grib_interface.c grib_interface.h
_gribapi_swig_la_LIBADD = $(top_builddir)/src/libeccodes.la $(PYTHON_LIBS)
_gribapi_swig_la_LDFLAGS = -module -avoid-version $(PYTHON_LDFLAGS)
INCLUDES = $(PYTHON_INCLUDES) -I$(NUMPY_INCLUDE)
gribapi_swig_wrap.c: swig_wrap_$(PYTHON_DATA_HANDLER).c
ln -s gribapi/gribapi.py
ln -s eccodes/eccodes.py
cp -f swig_wrap_$(PYTHON_DATA_HANDLER).c gribapi_swig_wrap.c
gribapi_swig.py: swig_wrap_$(PYTHON_DATA_HANDLER).py
cp -f swig_wrap_$(PYTHON_DATA_HANDLER).py gribapi_swig.py
# Extra stuff to go into the distribution
EXTRA_DIST = grib_interface.h \
grib_interface.c \
gribapi_swig.i \
gribapi.py \
eccodes.py \
numpy.i \
grib_errors.h \
extrules.am \
dummy.am \
swig_wrap_array.c \
swig_wrap_numpy.c \
swig_wrap_array.py \
swig_wrap_numpy.py \
CMakeLists.txt
# What else I want installed
pkgpyexec_DATA = \
gribapi.py \
eccodes.py \
gribapi_swig.py
CLEANFILES = \
gribapi_swig_wrap.c \
gribapi_swig.py \
_gribapi_swig.la
include $(DEVEL_RULES)
else
###############################################################################
# When shared libraries are disabled.
# Uses the static library so must have --with-pic
###############################################################################
noinst_SCRIPTS = setup.py
CLEANFILES = $(noinst_SCRIPTS) \
gribapi_swig_wrap.c \
gribapi_swig.py \
_gribapi_swig.so
# Extra stuff to go into the distribution
EXTRA_DIST = setup.py.autotools.in \
grib_interface.h \
grib_interface.c \
gribapi_swig.i \
gribapi.py \
eccodes.py \
numpy.i \
grib_errors.h \
extrules.am \
dummy.am \
swig_wrap_array.c \
swig_wrap_numpy.c \
swig_wrap_array.py \
swig_wrap_numpy.py \
CMakeLists.txt
# What I want installed
pdir = $(libdir)/python$(PYTHON_VERSION)/site-packages/eccodes
p_DATA = \
_gribapi_swig.so \
gribapi.py \
eccodes.py \
gribapi_swig.py
do_subst = sed -e 's,[@]LIB_JASPER[@],$(LIB_JASPER),g' \
-e 's,[@]JASPER_DIR[@],$(JASPER_DIR),g' \
-e 's,[@]LIB_OPENJPEG[@],$(LIB_OPENJPEG),g' \
-e 's,[@]OPENJPEG_DIR[@],$(OPENJPEG_DIR),g' \
-e 's,[@]LIB_AEC[@],$(LIB_AEC),g' \
-e 's,[@]AEC_DIR[@],$(AEC_DIR),g' \
-e 's,[@]LIB_PNG[@],$(LIB_PNG),g' \
-e 's,[@]BUILD_DIR[@],$(top_builddir),g' \
-e 's,[@]DATA_HANDLER[@],$(PYTHON_DATA_HANDLER),g'
clean-local:
-rm -rf build
setup.py: setup.py.autotools.in
$(do_subst) < setup.py.autotools.in > setup.py
gribapi_swig_wrap.c: swig_wrap_$(PYTHON_DATA_HANDLER).c
ln -s gribapi/gribapi.py
ln -s eccodes/eccodes.py
cp -f swig_wrap_$(PYTHON_DATA_HANDLER).c gribapi_swig_wrap.c
gribapi_swig.py: swig_wrap_$(PYTHON_DATA_HANDLER).py
cp -f swig_wrap_$(PYTHON_DATA_HANDLER).py gribapi_swig.py
_gribapi_swig.so: setup.py gribapi_swig_wrap.c gribapi_swig.py
$(PYTHON) setup.py build_ext --inplace
include $(DEVEL_RULES)
endif
else
# Case when WITH_PYTHON is not defined. Must add this rule otherwise
# make dist will fail
gribapi_swig_wrap.c: swig_wrap_array.c
cp -f swig_wrap_array.c gribapi_swig_wrap.c
endif

24
python/README Executable file
View File

@ -0,0 +1,24 @@
GRIB API Python bindings
In order to enable the Python bindings in the build,
use the --enable-python configure flag.
./configure --enable-python
This will enable the build of the Python bindings with
NumPy support enabled. Python needs to be in the path
and, of course, the NumPy package installed.
To build the Python bindings without NumPy support, use
the --disable-numpy configure flag. This will result in
Python array objects being used for data handling.
On 'make install', the Python bindings will be installed under
'${GRIBAPI_install_dir}/lib/pythonX.X/site-packages/grib_api',
where X.X is the version of python used to build the bindings.
Add this folder to your PYTHONPATH and you are ready to go.
For more information on the Python bindings, please visit our
website at:
http://www.ecmwf.int/publications/manuals/grib_api/

0
python/dummy.am Normal file
View File

View File

@ -6,9 +6,9 @@ Author: Daniel Lee, DWD, 2016
"""
from .. import eccodes
import io
class CodesFile(io.IOBase):
class CodesFile(file):
"""
An abstract class to specify and/or implement common behaviour that files
@ -43,7 +43,6 @@ class CodesFile(io.IOBase):
self.message = 0
#: Open messages
self.open_messages = []
self.name = filename
def __exit__(self, exception_type, exception_value, traceback):
"""Close all open messages, release file handle and close file."""

View File

@ -1,7 +1,6 @@
# Use SWIG version 3.0.12
# Python3 support added with -py3
#
swig : gribapi_swig.i
swig -v -py3 -python -module gribapi_swig -o swig_wrap_numpy.c gribapi_swig.i
swig -python -module gribapi_swig -o swig_wrap_numpy.c gribapi_swig.i
cp gribapi_swig.py swig_wrap_numpy.py
# swig -python -module gribapi_swig -o swig_wrap_array.c gribapi_swig.i
# cp gribapi_swig.py swig_wrap_array.py

View File

@ -831,7 +831,7 @@ int grib_c_read_any_from_file(int* fid, char* buffer, int* nbytes)
}
}
int grib_c_write_file(int* fid, char* buffer, size_t* nbytes)
int grib_c_write_file(int* fid, char* buffer, int* nbytes)
{
grib_context* c;
FILE* f=get_file(*fid);
@ -839,7 +839,7 @@ int grib_c_write_file(int* fid, char* buffer, size_t* nbytes)
if (f) {
int ioerr;
c=grib_context_get_default( );
if( fwrite(buffer, 1, *nbytes, f) != *nbytes) {
if( fwrite(buffer, 1, *nbytes, f) != *nbytes) {
ioerr=errno;
grib_context_log(c,(GRIB_LOG_ERROR)|(GRIB_LOG_PERROR),"IO ERROR: %s",strerror(ioerr));
return GRIB_IO_PROBLEM;
@ -850,7 +850,7 @@ int grib_c_write_file(int* fid, char* buffer, size_t* nbytes)
}
}
int grib_c_read_file(int* fid, char* buffer, size_t* nbytes)
int grib_c_read_file(int* fid, char* buffer, int* nbytes)
{
grib_context* c;
FILE* f=get_file(*fid);
@ -1004,7 +1004,7 @@ int grib_c_keys_iterator_get_name(int* iterid,char* name,int len)
sprintf(buf,"%s",grib_keys_iterator_get_name(kiter));
lsize=strlen(buf);
if ((size_t)len < lsize) return GRIB_ARRAY_TOO_SMALL;
if (len < lsize) return GRIB_ARRAY_TOO_SMALL;
memcpy(name,buf,lsize);
name[lsize] = '\0';
@ -1073,7 +1073,7 @@ int codes_c_bufr_keys_iterator_get_name(int* iterid,char* name,int len)
sprintf(buf,"%s",codes_bufr_keys_iterator_get_name(kiter));
lsize=strlen(buf);
if ((size_t)len < lsize) return GRIB_ARRAY_TOO_SMALL;
if (len < lsize) return GRIB_ARRAY_TOO_SMALL;
memcpy(name,buf,lsize);
name[lsize] = '\0';
@ -1235,95 +1235,6 @@ int grib_c_copy_namespace(int* gidsrc,char* name,int* giddest)
return GRIB_INVALID_GRIB;
}
/* ------------------------------------------------- */
typedef struct file_info_cache_t file_info_cache_t;
struct file_info_cache_t {
file_info_cache_t* next;
int file_descriptor;
FILE* file_pointer;
};
static file_info_cache_t* file_info_cache=0;
static void store_file_info(int fd, FILE* fp)
{
file_info_cache_t* tb=(file_info_cache_t*)malloc(sizeof(file_info_cache_t));
tb->file_descriptor = fd;
tb->file_pointer = fp;
tb->next = NULL;
/*printf("store_file_info: fd=%d fp=%p\n",fd,fp);*/
if (!file_info_cache) {
file_info_cache = tb;
} else {
/*Add to end of linked list*/
file_info_cache_t* q = file_info_cache;
while(q->next) q=q->next;
q->next = tb;
}
}
static FILE* retrieve_file_info(int fd)
{
file_info_cache_t* p = file_info_cache;
/*printf("retrieve_file_info: fd=%d\n",fd);*/
while (p) {
if (p->file_descriptor == fd) {
/*printf("\t result=%p\n",p->file_pointer);*/
return p->file_pointer;
}
p = p->next;
}
/*printf("\t result=NULL\n");*/
return NULL;
}
#if 0
static int clear_file_info(int fd)
{
printf("clear_file_info: fd=%d\n",fd);
file_info_cache_t* curr = file_info_cache;
while(curr) {
if (curr->file_descriptor==fd) {
curr->file_descriptor=-1;
curr->file_pointer=NULL;
/*TODO: Should delete this node */
return GRIB_SUCCESS;
}
curr=curr->next;
}
return GRIB_INVALID_FILE;
}
#endif
static int clear_file_info(int fd)
{
/*printf("clear_file_info: fd=%d\n",fd);*/
file_info_cache_t *curr, *prev=NULL;
for(curr=file_info_cache; curr!=NULL; prev=curr, curr=curr->next) {
if (curr->file_descriptor==fd) {//found it
if(prev==NULL) {//fix head
file_info_cache = curr->next;
} else {
//Fix previous node's 'next' to skip over the removed node
prev->next = curr->next;
}
/*printf("\t Deleting entry curr (%d,%p)\n", curr->file_descriptor,curr->file_pointer);*/
free(curr);
return GRIB_SUCCESS;
}
}
return GRIB_INVALID_FILE;
}
#if DEBUG
static void dump_file_info()
{
int i=1;
file_info_cache_t* curr = file_info_cache;
if(!curr) printf("dump_file_info: EMPTY\n");
else printf("dump_file_info:\n");
while(curr) {
printf("\t %d: fd=%d fp=%p\n", i++,curr->file_descriptor,curr->file_pointer);
curr=curr->next;
}
}
#endif
/* ------------------------------------------------- */
int grib_c_count_in_file(FILE* f,int* n)
{
int err = 0;
@ -1392,26 +1303,21 @@ int grib_c_new_any_from_file(FILE* f,int headers_only,int* gid)
return GRIB_INVALID_FILE;
}
int grib_c_new_bufr_from_file(FILE* f, int fd, char* fname, int headers_only,int* gid)
int grib_c_new_bufr_from_file(FILE* f,int headers_only,int* gid)
{
grib_handle *h = NULL;
int err = 0;
if(f){
FILE* p = retrieve_file_info(fd);
if (p) {
h = codes_handle_new_from_file(0,p,PRODUCT_BUFR, &err); //use cached value
} else {
h = codes_handle_new_from_file(0,f,PRODUCT_BUFR, &err); //use FILE pointer passed in
store_file_info(fd, f); //store it for next time
}
/* h = bufr_new_from_file(0,f,headers_only,&err); */
h = codes_handle_new_from_file(0,f,PRODUCT_BUFR, &err);
if(h){
push_handle(h,gid);
return GRIB_SUCCESS;
} else {
*gid=-1;
return GRIB_END_OF_FILE;//TODO: remove element from cache
return GRIB_END_OF_FILE;
}
}
@ -1419,27 +1325,13 @@ int grib_c_new_bufr_from_file(FILE* f, int fd, char* fname, int headers_only,int
return GRIB_INVALID_FILE;
}
int grib_c_new_from_file(FILE* f, int fd, char* fname, int* gid, int headers_only)
int grib_c_new_from_file(FILE* f, int* gid, int headers_only)
{
grib_handle *h = NULL;
int err = 0;
#if 0
printf("C grib_c_new_from_file: FILE*=%p\n", f);
printf("C grib_c_new_from_file: f->fileno=%d (fd=%d)\n", f->_fileno, fd);
printf("C grib_c_new_from_file: fn=%s\n", fname);
#endif
/*dump_file_info();*/
if(f){
FILE* p = retrieve_file_info(fd);
if (p) {
/*printf("C. using CACHED value from store...%p\n",p);*/
h=grib_new_from_file(0,p,headers_only,&err);//use cached value
} else {
/*printf("C. using value from ARGS...%p\n",f);*/
h=grib_new_from_file(0,f,headers_only,&err);//use FILE pointer passed in
store_file_info(fd, f); //store it for next time
/*dump_file_info();*/
}
h=grib_new_from_file(0,f,headers_only,&err);
if(h){
push_handle(h,gid);
@ -1447,10 +1339,7 @@ int grib_c_new_from_file(FILE* f, int fd, char* fname, int* gid, int headers_onl
} else {
*gid=-1;
if (err == GRIB_SUCCESS) {
/*printf("C grib_c_new_from_file: GRIB_END_OF_FILE\n");*/
clear_file_info(fd);
/*dump_file_info();*/
return GRIB_END_OF_FILE; //TODO: remove element from cache
return GRIB_END_OF_FILE;
} else {
/* A real error occurred */
return err;
@ -1555,7 +1444,7 @@ int grib_c_print(int* gid, char* key){
int grib_c_get_error_string(int* err, char* buf, int len){
const char* err_msg = grib_get_error_message(*err);
size_t erlen = strlen(err_msg);
if( (size_t)len < erlen) return GRIB_ARRAY_TOO_SMALL;
if( len < erlen) return GRIB_ARRAY_TOO_SMALL;
strncpy(buf, err_msg,(size_t)erlen);
buf[erlen] = '\0';
@ -1681,7 +1570,7 @@ int grib_c_get_double(int* gid, char* key, double* val){
return err;
}
int grib_c_get_int_array(int* gid, char* key, int *val, size_t* size){
int grib_c_get_int_array(int* gid, char* key, int *val, int* size){
grib_handle *h = get_handle(*gid);
long* long_val = NULL;
@ -1729,7 +1618,7 @@ int grib_c_index_get_string(int* gid, char* key, char* val, int *eachsize,int* s
grib_index *h = get_index(*gid);
int err = GRIB_SUCCESS;
size_t i;
int i;
size_t lsize = *size;
char** bufval;
char* p=val;
@ -1748,7 +1637,7 @@ int grib_c_index_get_string(int* gid, char* key, char* val, int *eachsize,int* s
int j;
if (*eachsize < l ) {
grib_context_free(h->context,bufval);
printf("eachsize=%d strlen(bufval[i])=%d\n",*eachsize,(int)strlen(bufval[i]));
printf("eachsize=%d strlen(bufval[i])=%d\n",*eachsize,(unsigned int)strlen(bufval[i]));
return GRIB_ARRAY_TOO_SMALL;
}
memcpy(p,bufval[i],l);
@ -1778,7 +1667,7 @@ int grib_c_index_get_int(int* gid, char* key, int *val, int* size){
int err = GRIB_SUCCESS;
size_t lsize = *size;
long* lval=0;
size_t i;
int i;
if(!h) return GRIB_INVALID_GRIB;
@ -1804,7 +1693,7 @@ int grib_c_index_get_real8(int* gid, char* key, double *val, int* size){
return err;
}
int grib_c_set_int_array(int* gid, char* key, int* val, size_t* size){
int grib_c_set_int_array(int* gid, char* key, int* val, int* size){
grib_handle *h = get_handle(*gid);
int err = GRIB_SUCCESS;
long* long_val = NULL;
@ -1935,7 +1824,7 @@ int grib_c_get_real4_elements(int* gid, char* key,int* index, float *val,int* si
grib_handle *h = get_handle(*gid);
int err = GRIB_SUCCESS;
size_t lsize = *size;
size_t i=0;
long i=0;
double* val8 = NULL;
if(!h) return GRIB_INVALID_GRIB;
@ -1950,7 +1839,7 @@ int grib_c_get_real4_elements(int* gid, char* key,int* index, float *val,int* si
err = grib_get_double_elements(h, key, index,(long)lsize,val8);
for(i=0; i<lsize; i++)
for(i=0;i<lsize;(i)++)
val[i] = val8[i];
grib_context_free(h->context,val8);
@ -1971,7 +1860,7 @@ int grib_c_get_real4(int* gid, char* key, float* val)
return err;
}
int grib_c_get_real4_array(int* gid, char* key, float *val, size_t* size)
int grib_c_get_real4_array(int* gid, char* key, float *val, int* size)
{
grib_handle *h = get_handle(*gid);
int err = GRIB_SUCCESS;
@ -2013,7 +1902,7 @@ int grib_c_set_real4_array(int* gid, char* key, float*val, int* size)
if(!val8) return GRIB_OUT_OF_MEMORY;
for(lsize=0; lsize<(size_t)*size; lsize++)
for(lsize=0;lsize<*size;lsize++)
val8[lsize] = val[lsize];
err = grib_set_double_array(h, key, val8, lsize);
@ -2318,7 +2207,6 @@ void grib_c_check(int* err,char* call,char* str)
int grib_c_write(int* gid, FILE* f)
{
int err = 0;
grib_handle *h = get_handle(*gid);
const void* mess = NULL;
size_t mess_len = 0;
@ -2326,17 +2214,12 @@ int grib_c_write(int* gid, FILE* f)
if(!f) return GRIB_INVALID_FILE;
if (!h) return GRIB_INVALID_GRIB;
err = grib_get_message(h,&mess,&mess_len);
if (err) return err;
grib_get_message(h,&mess,&mess_len);
if(fwrite(mess,1, mess_len,f) != mess_len) {
perror("grib_write");
return GRIB_IO_PROBLEM;
}
err = fflush(f);
if(err) {
perror("write flush");
return GRIB_IO_PROBLEM;
}
return GRIB_SUCCESS;
}

View File

@ -2,8 +2,8 @@
#define GRIB_INTERFACE_H
int grib_c_read_any_from_file(int *fid, char *buffer, int *nbytes);
int grib_c_write_file(int *fid, char *buffer, size_t *nbytes);
int grib_c_read_file(int *fid, char *buffer, size_t *nbytes);
int grib_c_write_file(int *fid, char *buffer, int *nbytes);
int grib_c_read_file(int *fid, char *buffer, int *nbytes);
int grib_c_open_file(int *fid, char *name, char *op);
int grib_c_close_file(int *fid);
int grib_c_multi_support_on(void);
@ -37,13 +37,9 @@ int grib_c_bufr_new_from_samples(int *gid, char *name);
int grib_c_clone(int *gidsrc, int *giddest);
int grib_c_copy_namespace(int *gidsrc, char *name, int *giddest);
int grib_c_count_in_file(FILE *f, int *n);
int grib_c_new_from_file(FILE *f, int fd, char* fname, int *gid, int headers_only);
int grib_c_new_from_file(FILE *f, int *gid, int headers_only);
int grib_c_new_any_from_file(FILE *f, int headers_only,int *gid);
int grib_c_new_bufr_from_file(FILE *f, int fd, char* fname, int headers_only,int *gid);
int grib_c_new_bufr_from_file(FILE *f, int headers_only,int *gid);
int grib_c_new_gts_from_file(FILE *f,int headers_only, int *gid);
int grib_c_new_metar_from_file(FILE* f,int headers_only, int* gid);
int grib_c_new_from_index(int *iid, int *gid);
@ -62,13 +58,13 @@ int grib_c_index_get_size_long(int *gid, char *key, long *val);
int grib_c_get_int(int *gid, char *key, int *val);
int grib_c_get_long(int *gid, char *key, long *val);
int grib_c_get_double(int *gid, char *key, double *val);
int grib_c_get_int_array(int *gid, char *key, int *val, size_t *size);
int grib_c_get_int_array(int *gid, char *key, int *val, int *size);
int grib_c_get_long_array(int *gid, char *key, long *val, int *size);
int grib_c_index_get_string(int *gid, char *key, char *val, int *eachsize, int *size);
int grib_c_index_get_long(int *gid, char *key, long *val, int *size);
int grib_c_index_get_int(int *gid, char *key, int *val, int *size);
int grib_c_index_get_real8(int *gid, char *key, double *val, int *size);
int grib_c_set_int_array(int *gid, char *key, int *val, size_t *size);
int grib_c_set_int_array(int *gid, char *key, int *val, int *size);
int grib_c_set_long_array(int *gid, char *key, long *val, int *size);
int grib_c_set_int(int *gid, char *key, int *val);
int grib_c_set_long(int *gid, char *key, long *val);
@ -80,7 +76,7 @@ int grib_c_set_real4(int *gid, char *key, float *val);
int grib_c_get_real4_element(int *gid, char *key, int *index, float *val);
int grib_c_get_real4_elements(int *gid, char *key, int *index, float *val, int *size);
int grib_c_get_real4(int *gid, char *key, float *val);
int grib_c_get_real4_array(int *gid, char *key, float *val, size_t *size);
int grib_c_get_real4_array(int *gid, char *key, float *val, int *size);
int grib_c_set_real4_array(int *gid, char *key, float *val, int *size);
int grib_c_index_select_real8(int *gid, char *key, double *val);
int grib_c_index_select_string(int *gid, char *key, char *val);

View File

@ -2,7 +2,7 @@
Exception class hierarchy
"""
from . import gribapi_swig as _internal
import gribapi_swig as _internal
class GribInternalError(Exception):

View File

@ -22,22 +22,15 @@ When this is enabed, then the system Python will be used to build the interface.
- NumPy
"""
import gribapi_swig as _internal
# from gribapi import gribapi_swig as _internal
from . import gribapi_swig as _internal
import types
import sys
import os
from functools import wraps
# import inspect
from . import errors
from .errors import * # noqa
try:
type(file)
except NameError:
import io
file=io.IOBase
long=int
from errors import * # noqa
KEYTYPES = {
1: int,
@ -83,12 +76,12 @@ def require(**_params_):
@wraps(_func_)
# The wrapper function. Replaces the target function and receives its args
def modified(*args, **kw):
arg_names = _func_.__code__.co_varnames
arg_names = _func_.func_code.co_varnames
# argnames, varargs, kwargs, defaults = inspect.getargspec(_func_)
kw.update(zip(arg_names, args))
for name, allowed_types in _params_.items():
for name, allowed_types in _params_.iteritems():
param = kw[name]
if isinstance(allowed_types, type):
if isinstance(allowed_types, types.TypeType):
allowed_types = (allowed_types,)
assert any([isinstance(param, type1) for type1 in allowed_types]), \
"Parameter '%s' should be of type %s" % (name, " or ".join([t.__name__ for t in allowed_types]))
@ -259,9 +252,7 @@ def bufr_new_from_file(fileobj, headers_only=False):
@return id of the BUFR loaded in memory
@exception GribInternalError
"""
fd = fileobj.fileno()
fn = fileobj.name
err, bufrid = _internal.grib_c_new_bufr_from_file(fileobj, fd, fn, headers_only, 0)
err, bufrid = _internal.grib_c_new_bufr_from_file(fileobj, headers_only, 0)
if err:
if err == _internal.GRIB_END_OF_FILE:
return None
@ -293,10 +284,7 @@ def grib_new_from_file(fileobj, headers_only=False):
@return id of the grib loaded in memory
@exception GribInternalError
"""
fd = fileobj.fileno()
fn = fileobj.name
#print('Python grib_new_from_file: ', fd,' ', fn)
err, gribid = _internal.grib_c_new_from_file(fileobj, fd, fn, 0, headers_only)
err, gribid = _internal.grib_c_new_from_file(fileobj, 0, headers_only)
if err:
if err == _internal.GRIB_END_OF_FILE:
return None
@ -828,7 +816,7 @@ def grib_set_long(msgid, key, value):
except (ValueError, TypeError):
raise TypeError("Invalid type")
if value > sys.maxsize:
if value > sys.maxint:
raise TypeError("Invalid type")
GRIB_CHECK(_internal.grib_c_set_long(msgid, key, value))
@ -1491,7 +1479,7 @@ def grib_set_key_vals(gribid, key_vals):
key_vals_str += kv
elif isinstance(key_vals, dict):
# A dictionary mapping keys to values
for key in key_vals.keys():
for key in key_vals.iterkeys():
if len(key_vals_str) > 0:
key_vals_str += ','
key_vals_str += key + '=' + str(key_vals[key])
@ -1767,15 +1755,12 @@ def grib_set_array(msgid, key, value):
if isinstance(val0, float):
grib_set_double_array(msgid, key, value)
elif isinstance(val0, int):
grib_set_long_array(msgid, key, value)
elif isinstance(val0, str):
grib_set_string_array(msgid, key, value)
else:
# Note: Cannot do isinstance(val0,int) for numpy.int64
try:
n = int(val0)
except (ValueError, TypeError):
raise errors.GribInternalError("Invalid type of value when setting key '%s'." % key)
grib_set_long_array(msgid, key, value)
raise errors.GribInternalError("Invalid type of value when setting key '%s'." % key)
@require(indexid=int, key=str)

View File

@ -17,18 +17,14 @@
import_array();
%}
/* Converts a PyFile instance to a stdio FILE* for reading binary files */
/* Converts a PyFile instance to a stdio FILE* */
%typemap(in) FILE* {
int fileDescriptor = PyObject_AsFileDescriptor($input);
/*printf("swig.i fileDescriptor=%d\n", fileDescriptor);*/
if(fileDescriptor >= 0) {
/* Convert file descriptor to a FILE pointer */
$1 = fdopen(fileDescriptor,"rb"); // needs to be rb+ (or wb) for write
}
else {
PyErr_SetString(PyExc_TypeError, "$1_name must be a file type.");
return NULL;
}
if ( PyFile_Check($input) ){
$1 = PyFile_AsFile($input);
} else {
PyErr_SetString(PyExc_TypeError, "$1_name must be a file type.");
return NULL;
}
}
%pointer_class(int, intp);
@ -41,9 +37,9 @@ import_array();
%array_functions(char*, stringArray);
// creation
int grib_c_new_from_file(FILE* f, int fd, char* fname, int* INOUT, int headers_only);
int grib_c_new_from_file(FILE* f, int* INOUT, int headers_only);
int grib_c_new_any_from_file(FILE* f, int headers_only, int* INOUT);
int grib_c_new_bufr_from_file(FILE* f, int fd, char* fname, int headers_only, int* INOUT);
int grib_c_new_bufr_from_file(FILE* f, int headers_only, int* INOUT);
int grib_c_new_gts_from_file(FILE* f, int headers_only, int* INOUT);
int grib_c_new_metar_from_file(FILE* f, int headers_only, int* INOUT);
int grib_c_iterator_new(int* INPUT, int* OUTPUT, int* INPUT);
@ -68,19 +64,6 @@ int grib_c_new_from_message(int *INOUT, char *binmsg, size_t *INPUT);
int grib_c_count_in_file(FILE* f,int* OUTPUT);
// ---
/* Converts a PyFile instance to a stdio FILE* for writing binary files */
%typemap(in) FILE* {
int fileDescriptor = PyObject_AsFileDescriptor($input);
if(fileDescriptor >= 0) {
/* Convert file descriptor to a FILE pointer */
$1 = fdopen(fileDescriptor,"wb");
}
else {
PyErr_SetString(PyExc_TypeError, "$1_name must be a file type.");
return NULL;
}
}
// grib handle operations
int grib_c_release(int* gid);
int grib_c_write(int* gid, FILE* f);
@ -239,8 +222,8 @@ int grib_c_find_nearest_four_single(int* gid, int* INPUT, double* INPUT, double*
* Get the binary string message for a grib.
*
* Set the 3rd argument to nothing in 'cstring_output_allocate_size'.
* This is kind of difficult to explain, but, *msg will point directly to
* the binary message data of the current grib (which is stored in
* This is kind of difficult to explain, but, *msg will point directly to
* the binary message data of the current grib (which is stored in
* handle->buffer->data if I remember correctly) so freeing it will cause
* the binary message data in the grib_handle structure to be freed. This
* is a problem as grib_api does not know that, so it tries to free it
@ -263,3 +246,6 @@ void grib_c_gts_header_on();
void grib_c_gts_header_off();
void grib_c_set_definitions_path(const char* path);
void grib_c_set_samples_path(const char* path);

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,86 @@
#!/usr/bin/env python
from distutils.core import setup, Extension
import os,sys
attdict = dict(
sources = ['gribapi_swig_wrap.c','grib_interface.c'],
swig_opts = [],
include_dirs = ['.'],
library_dirs = ["%s/lib" % sys.prefix],
libraries = [],
extra_objects = [],
extra_link_args = [], # See GRIB-616
)
add_attribute = lambda **args: [list.append(attdict[key],value) for key,value in args.items()]
# assumes build_dir is same as source_dir -- not true for cmake builds
build_dir = '@BUILD_DIR@'
add_attribute(
include_dirs = os.path.join(build_dir,'src'),
extra_objects = os.path.join(build_dir, 'src', '.libs', 'libeccodes.a')
)
with_jasper = '@LIB_JASPER@'
if with_jasper:
jasper_dir = '@JASPER_DIR@'
if jasper_dir and jasper_dir != 'system':
add_attribute(
include_dirs = os.path.join(jasper_dir,'include'),
library_dirs = os.path.join(jasper_dir,'lib'),
extra_link_args = '-Wl,-rpath,' + os.path.join(jasper_dir,'lib')
)
add_attribute(libraries = 'jasper')
with_openjpeg = '@LIB_OPENJPEG@'
if with_openjpeg:
openjpeg_dir = '@OPENJPEG_DIR@'
if openjpeg_dir and openjpeg_dir != 'system':
add_attribute(
include_dirs = os.path.join(openjpeg_dir,'include'),
library_dirs = os.path.join(openjpeg_dir,'lib'),
extra_link_args = '-Wl,-rpath,' + os.path.join(openjpeg_dir,'lib')
)
add_attribute(libraries = 'openjpeg')
# assumes png is supplied by system paths -- may not be true
png = '@LIB_PNG@'
if png:
add_attribute(libraries = 'png')
with_aec = '@LIB_AEC@'
if with_aec:
aec_dir = '@AEC_DIR@'
if aec_dir and aec_dir != 'system':
add_attribute(
include_dirs = os.path.join(aec_dir,'include'),
library_dirs = os.path.join(aec_dir,'lib'),
extra_link_args = '-Wl,-rpath,' + os.path.join(aec_dir,'lib')
)
add_attribute(libraries = 'aec')
data_handler = '@DATA_HANDLER@'
if data_handler == "numpy":
import numpy
# Obtain the numpy include directory. This logic works across numpy versions.
try:
numpy_include = numpy.get_include()
except AttributeError:
numpy_include = numpy.get_numpy_include()
add_attribute(
include_dirs = numpy_include,
)
gribapi_module = Extension('_gribapi_swig',**attdict)
setup (name = 'gribapi',
version = '0.1',
author = 'ECMWF',
description = """Grib API SWIG module""",
ext_modules = [gribapi_module],
py_modules = ['gribapi_swig','gribapi'],
)

File diff suppressed because it is too large Load Diff

View File

@ -1,22 +1,12 @@
# This file was automatically generated by SWIG (http://www.swig.org).
# Version 3.0.12
# Version 1.3.40
#
# Do not make changes to this file unless you know what you are doing--modify
# the SWIG interface file instead.
# This file is compatible with both classic and new-style classes.
from sys import version_info as _swig_python_version_info
if _swig_python_version_info >= (2, 7, 0):
def swig_import_helper():
import importlib
pkg = __name__.rpartition('.')[0]
mname = '.'.join((pkg, '_gribapi_swig')).lstrip('.')
try:
return importlib.import_module(mname)
except ImportError:
return importlib.import_module('_gribapi_swig')
_gribapi_swig = swig_import_helper()
del swig_import_helper
elif _swig_python_version_info >= (2, 6, 0):
from sys import version_info
if version_info >= (2,6,0):
def swig_import_helper():
from os.path import dirname
import imp
@ -26,82 +16,63 @@ elif _swig_python_version_info >= (2, 6, 0):
except ImportError:
import _gribapi_swig
return _gribapi_swig
try:
_mod = imp.load_module('_gribapi_swig', fp, pathname, description)
finally:
if fp is not None:
if fp is not None:
try:
_mod = imp.load_module('_gribapi_swig', fp, pathname, description)
finally:
fp.close()
return _mod
return _mod
_gribapi_swig = swig_import_helper()
del swig_import_helper
else:
import _gribapi_swig
del _swig_python_version_info
del version_info
try:
_swig_property = property
except NameError:
pass # Python < 2.2 doesn't have 'property'.
try:
import builtins as __builtin__
except ImportError:
import __builtin__
def _swig_setattr_nondynamic(self, class_type, name, value, static=1):
if (name == "thisown"):
return self.this.own(value)
pass # Python < 2.2 doesn't have 'property'.
def _swig_setattr_nondynamic(self,class_type,name,value,static=1):
if (name == "thisown"): return self.this.own(value)
if (name == "this"):
if type(value).__name__ == 'SwigPyObject':
self.__dict__[name] = value
return
method = class_type.__swig_setmethods__.get(name, None)
if method:
return method(self, value)
if (not static):
if _newclass:
object.__setattr__(self, name, value)
else:
self.__dict__[name] = value
method = class_type.__swig_setmethods__.get(name,None)
if method: return method(self,value)
if (not static) or hasattr(self,name):
self.__dict__[name] = value
else:
raise AttributeError("You cannot add attributes to %s" % self)
def _swig_setattr(self,class_type,name,value):
return _swig_setattr_nondynamic(self,class_type,name,value,0)
def _swig_setattr(self, class_type, name, value):
return _swig_setattr_nondynamic(self, class_type, name, value, 0)
def _swig_getattr(self, class_type, name):
if (name == "thisown"):
return self.this.own()
method = class_type.__swig_getmethods__.get(name, None)
if method:
return method(self)
raise AttributeError("'%s' object has no attribute '%s'" % (class_type.__name__, name))
def _swig_getattr(self,class_type,name):
if (name == "thisown"): return self.this.own()
method = class_type.__swig_getmethods__.get(name,None)
if method: return method(self)
raise AttributeError(name)
def _swig_repr(self):
try:
strthis = "proxy of " + self.this.__repr__()
except __builtin__.Exception:
strthis = ""
try: strthis = "proxy of " + self.this.__repr__()
except: strthis = ""
return "<%s.%s; %s >" % (self.__class__.__module__, self.__class__.__name__, strthis,)
try:
_object = object
_newclass = 1
except __builtin__.Exception:
class _object:
pass
except AttributeError:
class _object : pass
_newclass = 0
def cdata(ptr: 'void *', nelements: 'size_t'=1) -> "SWIGCDATA":
return _gribapi_swig.cdata(ptr, nelements)
def cdata(*args):
return _gribapi_swig.cdata(*args)
cdata = _gribapi_swig.cdata
def memmove(data: 'void *', indata: 'void const *') -> "void":
return _gribapi_swig.memmove(data, indata)
def memmove(*args):
return _gribapi_swig.memmove(*args)
memmove = _gribapi_swig.memmove
GRIB_SUCCESS = _gribapi_swig.GRIB_SUCCESS
GRIB_END_OF_FILE = _gribapi_swig.GRIB_END_OF_FILE
@ -176,33 +147,22 @@ class intp(_object):
__swig_getmethods__ = {}
__getattr__ = lambda self, name: _swig_getattr(self, intp, name)
__repr__ = _swig_repr
def __init__(self):
def __init__(self):
this = _gribapi_swig.new_intp()
try:
self.this.append(this)
except __builtin__.Exception:
self.this = this
try: self.this.append(this)
except: self.this = this
__swig_destroy__ = _gribapi_swig.delete_intp
__del__ = lambda self: None
def assign(self, value: 'int') -> "void":
return _gribapi_swig.intp_assign(self, value)
def value(self) -> "int":
return _gribapi_swig.intp_value(self)
def cast(self) -> "int *":
return _gribapi_swig.intp_cast(self)
if _newclass:
frompointer = staticmethod(_gribapi_swig.intp_frompointer)
else:
frompointer = _gribapi_swig.intp_frompointer
__del__ = lambda self : None;
def assign(self, *args): return _gribapi_swig.intp_assign(self, *args)
def value(self): return _gribapi_swig.intp_value(self)
def cast(self): return _gribapi_swig.intp_cast(self)
__swig_getmethods__["frompointer"] = lambda x: _gribapi_swig.intp_frompointer
if _newclass:frompointer = staticmethod(_gribapi_swig.intp_frompointer)
intp_swigregister = _gribapi_swig.intp_swigregister
intp_swigregister(intp)
def intp_frompointer(t: 'int *') -> "intp *":
return _gribapi_swig.intp_frompointer(t)
def intp_frompointer(*args):
return _gribapi_swig.intp_frompointer(*args)
intp_frompointer = _gribapi_swig.intp_frompointer
class sizetp(_object):
@ -211,33 +171,22 @@ class sizetp(_object):
__swig_getmethods__ = {}
__getattr__ = lambda self, name: _swig_getattr(self, sizetp, name)
__repr__ = _swig_repr
def __init__(self):
def __init__(self):
this = _gribapi_swig.new_sizetp()
try:
self.this.append(this)
except __builtin__.Exception:
self.this = this
try: self.this.append(this)
except: self.this = this
__swig_destroy__ = _gribapi_swig.delete_sizetp
__del__ = lambda self: None
def assign(self, value: 'size_t') -> "void":
return _gribapi_swig.sizetp_assign(self, value)
def value(self) -> "size_t":
return _gribapi_swig.sizetp_value(self)
def cast(self) -> "size_t *":
return _gribapi_swig.sizetp_cast(self)
if _newclass:
frompointer = staticmethod(_gribapi_swig.sizetp_frompointer)
else:
frompointer = _gribapi_swig.sizetp_frompointer
__del__ = lambda self : None;
def assign(self, *args): return _gribapi_swig.sizetp_assign(self, *args)
def value(self): return _gribapi_swig.sizetp_value(self)
def cast(self): return _gribapi_swig.sizetp_cast(self)
__swig_getmethods__["frompointer"] = lambda x: _gribapi_swig.sizetp_frompointer
if _newclass:frompointer = staticmethod(_gribapi_swig.sizetp_frompointer)
sizetp_swigregister = _gribapi_swig.sizetp_swigregister
sizetp_swigregister(sizetp)
def sizetp_frompointer(t: 'size_t *') -> "sizetp *":
return _gribapi_swig.sizetp_frompointer(t)
def sizetp_frompointer(*args):
return _gribapi_swig.sizetp_frompointer(*args)
sizetp_frompointer = _gribapi_swig.sizetp_frompointer
class longp(_object):
@ -246,33 +195,22 @@ class longp(_object):
__swig_getmethods__ = {}
__getattr__ = lambda self, name: _swig_getattr(self, longp, name)
__repr__ = _swig_repr
def __init__(self):
def __init__(self):
this = _gribapi_swig.new_longp()
try:
self.this.append(this)
except __builtin__.Exception:
self.this = this
try: self.this.append(this)
except: self.this = this
__swig_destroy__ = _gribapi_swig.delete_longp
__del__ = lambda self: None
def assign(self, value: 'long') -> "void":
return _gribapi_swig.longp_assign(self, value)
def value(self) -> "long":
return _gribapi_swig.longp_value(self)
def cast(self) -> "long *":
return _gribapi_swig.longp_cast(self)
if _newclass:
frompointer = staticmethod(_gribapi_swig.longp_frompointer)
else:
frompointer = _gribapi_swig.longp_frompointer
__del__ = lambda self : None;
def assign(self, *args): return _gribapi_swig.longp_assign(self, *args)
def value(self): return _gribapi_swig.longp_value(self)
def cast(self): return _gribapi_swig.longp_cast(self)
__swig_getmethods__["frompointer"] = lambda x: _gribapi_swig.longp_frompointer
if _newclass:frompointer = staticmethod(_gribapi_swig.longp_frompointer)
longp_swigregister = _gribapi_swig.longp_swigregister
longp_swigregister(longp)
def longp_frompointer(t: 'long *') -> "longp *":
return _gribapi_swig.longp_frompointer(t)
def longp_frompointer(*args):
return _gribapi_swig.longp_frompointer(*args)
longp_frompointer = _gribapi_swig.longp_frompointer
class doublep(_object):
@ -281,467 +219,455 @@ class doublep(_object):
__swig_getmethods__ = {}
__getattr__ = lambda self, name: _swig_getattr(self, doublep, name)
__repr__ = _swig_repr
def __init__(self):
def __init__(self):
this = _gribapi_swig.new_doublep()
try:
self.this.append(this)
except __builtin__.Exception:
self.this = this
try: self.this.append(this)
except: self.this = this
__swig_destroy__ = _gribapi_swig.delete_doublep
__del__ = lambda self: None
def assign(self, value: 'double') -> "void":
return _gribapi_swig.doublep_assign(self, value)
def value(self) -> "double":
return _gribapi_swig.doublep_value(self)
def cast(self) -> "double *":
return _gribapi_swig.doublep_cast(self)
if _newclass:
frompointer = staticmethod(_gribapi_swig.doublep_frompointer)
else:
frompointer = _gribapi_swig.doublep_frompointer
__del__ = lambda self : None;
def assign(self, *args): return _gribapi_swig.doublep_assign(self, *args)
def value(self): return _gribapi_swig.doublep_value(self)
def cast(self): return _gribapi_swig.doublep_cast(self)
__swig_getmethods__["frompointer"] = lambda x: _gribapi_swig.doublep_frompointer
if _newclass:frompointer = staticmethod(_gribapi_swig.doublep_frompointer)
doublep_swigregister = _gribapi_swig.doublep_swigregister
doublep_swigregister(doublep)
def doublep_frompointer(t: 'double *') -> "doublep *":
return _gribapi_swig.doublep_frompointer(t)
def doublep_frompointer(*args):
return _gribapi_swig.doublep_frompointer(*args)
doublep_frompointer = _gribapi_swig.doublep_frompointer
def new_doubleArray(nelements: 'size_t') -> "double *":
return _gribapi_swig.new_doubleArray(nelements)
def new_doubleArray(*args):
return _gribapi_swig.new_doubleArray(*args)
new_doubleArray = _gribapi_swig.new_doubleArray
def delete_doubleArray(ary: 'double *') -> "void":
return _gribapi_swig.delete_doubleArray(ary)
def delete_doubleArray(*args):
return _gribapi_swig.delete_doubleArray(*args)
delete_doubleArray = _gribapi_swig.delete_doubleArray
def doubleArray_getitem(ary: 'double *', index: 'size_t') -> "double":
return _gribapi_swig.doubleArray_getitem(ary, index)
def doubleArray_getitem(*args):
return _gribapi_swig.doubleArray_getitem(*args)
doubleArray_getitem = _gribapi_swig.doubleArray_getitem
def doubleArray_setitem(ary: 'double *', index: 'size_t', value: 'double') -> "void":
return _gribapi_swig.doubleArray_setitem(ary, index, value)
def doubleArray_setitem(*args):
return _gribapi_swig.doubleArray_setitem(*args)
doubleArray_setitem = _gribapi_swig.doubleArray_setitem
def new_longArray(nelements: 'size_t') -> "long *":
return _gribapi_swig.new_longArray(nelements)
def new_longArray(*args):
return _gribapi_swig.new_longArray(*args)
new_longArray = _gribapi_swig.new_longArray
def delete_longArray(ary: 'long *') -> "void":
return _gribapi_swig.delete_longArray(ary)
def delete_longArray(*args):
return _gribapi_swig.delete_longArray(*args)
delete_longArray = _gribapi_swig.delete_longArray
def longArray_getitem(ary: 'long *', index: 'size_t') -> "long":
return _gribapi_swig.longArray_getitem(ary, index)
def longArray_getitem(*args):
return _gribapi_swig.longArray_getitem(*args)
longArray_getitem = _gribapi_swig.longArray_getitem
def longArray_setitem(ary: 'long *', index: 'size_t', value: 'long') -> "void":
return _gribapi_swig.longArray_setitem(ary, index, value)
def longArray_setitem(*args):
return _gribapi_swig.longArray_setitem(*args)
longArray_setitem = _gribapi_swig.longArray_setitem
def new_intArray(nelements: 'size_t') -> "int *":
return _gribapi_swig.new_intArray(nelements)
def new_intArray(*args):
return _gribapi_swig.new_intArray(*args)
new_intArray = _gribapi_swig.new_intArray
def delete_intArray(ary: 'int *') -> "void":
return _gribapi_swig.delete_intArray(ary)
def delete_intArray(*args):
return _gribapi_swig.delete_intArray(*args)
delete_intArray = _gribapi_swig.delete_intArray
def intArray_getitem(ary: 'int *', index: 'size_t') -> "int":
return _gribapi_swig.intArray_getitem(ary, index)
def intArray_getitem(*args):
return _gribapi_swig.intArray_getitem(*args)
intArray_getitem = _gribapi_swig.intArray_getitem
def intArray_setitem(ary: 'int *', index: 'size_t', value: 'int') -> "void":
return _gribapi_swig.intArray_setitem(ary, index, value)
def intArray_setitem(*args):
return _gribapi_swig.intArray_setitem(*args)
intArray_setitem = _gribapi_swig.intArray_setitem
def new_stringArray(nelements: 'size_t') -> "char **":
return _gribapi_swig.new_stringArray(nelements)
def new_stringArray(*args):
return _gribapi_swig.new_stringArray(*args)
new_stringArray = _gribapi_swig.new_stringArray
def delete_stringArray(ary: 'char **') -> "void":
return _gribapi_swig.delete_stringArray(ary)
def delete_stringArray(*args):
return _gribapi_swig.delete_stringArray(*args)
delete_stringArray = _gribapi_swig.delete_stringArray
def stringArray_getitem(ary: 'char **', index: 'size_t') -> "char *":
return _gribapi_swig.stringArray_getitem(ary, index)
def stringArray_getitem(*args):
return _gribapi_swig.stringArray_getitem(*args)
stringArray_getitem = _gribapi_swig.stringArray_getitem
def stringArray_setitem(ary: 'char **', index: 'size_t', value: 'char *') -> "void":
return _gribapi_swig.stringArray_setitem(ary, index, value)
def stringArray_setitem(*args):
return _gribapi_swig.stringArray_setitem(*args)
stringArray_setitem = _gribapi_swig.stringArray_setitem
def grib_c_new_from_file(f: 'FILE *', fd: 'int', fname: 'char *', INOUT: 'int *', headers_only: 'int') -> "int *":
return _gribapi_swig.grib_c_new_from_file(f, fd, fname, INOUT, headers_only)
def grib_c_new_from_file(*args):
return _gribapi_swig.grib_c_new_from_file(*args)
grib_c_new_from_file = _gribapi_swig.grib_c_new_from_file
def grib_c_new_any_from_file(f: 'FILE *', headers_only: 'int', INOUT: 'int *') -> "int *":
return _gribapi_swig.grib_c_new_any_from_file(f, headers_only, INOUT)
def grib_c_new_any_from_file(*args):
return _gribapi_swig.grib_c_new_any_from_file(*args)
grib_c_new_any_from_file = _gribapi_swig.grib_c_new_any_from_file
def grib_c_new_bufr_from_file(f: 'FILE *', fd: 'int', fname: 'char *', headers_only: 'int', INOUT: 'int *') -> "int *":
return _gribapi_swig.grib_c_new_bufr_from_file(f, fd, fname, headers_only, INOUT)
def grib_c_new_bufr_from_file(*args):
return _gribapi_swig.grib_c_new_bufr_from_file(*args)
grib_c_new_bufr_from_file = _gribapi_swig.grib_c_new_bufr_from_file
def grib_c_new_gts_from_file(f: 'FILE *', headers_only: 'int', INOUT: 'int *') -> "int *":
return _gribapi_swig.grib_c_new_gts_from_file(f, headers_only, INOUT)
def grib_c_new_gts_from_file(*args):
return _gribapi_swig.grib_c_new_gts_from_file(*args)
grib_c_new_gts_from_file = _gribapi_swig.grib_c_new_gts_from_file
def grib_c_new_metar_from_file(f: 'FILE *', headers_only: 'int', INOUT: 'int *') -> "int *":
return _gribapi_swig.grib_c_new_metar_from_file(f, headers_only, INOUT)
def grib_c_new_metar_from_file(*args):
return _gribapi_swig.grib_c_new_metar_from_file(*args)
grib_c_new_metar_from_file = _gribapi_swig.grib_c_new_metar_from_file
def grib_c_iterator_new(arg1: 'int *', arg3: 'int *') -> "int *":
return _gribapi_swig.grib_c_iterator_new(arg1, arg3)
def grib_c_iterator_new(*args):
return _gribapi_swig.grib_c_iterator_new(*args)
grib_c_iterator_new = _gribapi_swig.grib_c_iterator_new
def grib_c_keys_iterator_new(INPUT: 'int *', name_space: 'char *') -> "int *":
return _gribapi_swig.grib_c_keys_iterator_new(INPUT, name_space)
def grib_c_keys_iterator_new(*args):
return _gribapi_swig.grib_c_keys_iterator_new(*args)
grib_c_keys_iterator_new = _gribapi_swig.grib_c_keys_iterator_new
def codes_c_bufr_keys_iterator_new(INPUT: 'int *') -> "int *":
return _gribapi_swig.codes_c_bufr_keys_iterator_new(INPUT)
def codes_c_bufr_keys_iterator_new(*args):
return _gribapi_swig.codes_c_bufr_keys_iterator_new(*args)
codes_c_bufr_keys_iterator_new = _gribapi_swig.codes_c_bufr_keys_iterator_new
def grib_c_grib_new_from_samples(INOUT: 'int *', name: 'char *') -> "int *":
return _gribapi_swig.grib_c_grib_new_from_samples(INOUT, name)
def grib_c_grib_new_from_samples(*args):
return _gribapi_swig.grib_c_grib_new_from_samples(*args)
grib_c_grib_new_from_samples = _gribapi_swig.grib_c_grib_new_from_samples
def grib_c_bufr_new_from_samples(INOUT: 'int *', name: 'char *') -> "int *":
return _gribapi_swig.grib_c_bufr_new_from_samples(INOUT, name)
def grib_c_bufr_new_from_samples(*args):
return _gribapi_swig.grib_c_bufr_new_from_samples(*args)
grib_c_bufr_new_from_samples = _gribapi_swig.grib_c_bufr_new_from_samples
def grib_c_index_new_from_file(file: 'char *', keys: 'char *') -> "int *":
return _gribapi_swig.grib_c_index_new_from_file(file, keys)
def grib_c_index_new_from_file(*args):
return _gribapi_swig.grib_c_index_new_from_file(*args)
grib_c_index_new_from_file = _gribapi_swig.grib_c_index_new_from_file
def grib_c_index_add_file(INPUT: 'int *', file: 'char *') -> "int":
return _gribapi_swig.grib_c_index_add_file(INPUT, file)
def grib_c_index_add_file(*args):
return _gribapi_swig.grib_c_index_add_file(*args)
grib_c_index_add_file = _gribapi_swig.grib_c_index_add_file
def grib_c_new_from_index(INPUT: 'int *', INOUT: 'int *') -> "int *":
return _gribapi_swig.grib_c_new_from_index(INPUT, INOUT)
def grib_c_new_from_index(*args):
return _gribapi_swig.grib_c_new_from_index(*args)
grib_c_new_from_index = _gribapi_swig.grib_c_new_from_index
def grib_c_index_write(INPUT: 'int *', file: 'char *') -> "int":
return _gribapi_swig.grib_c_index_write(INPUT, file)
def grib_c_index_write(*args):
return _gribapi_swig.grib_c_index_write(*args)
grib_c_index_write = _gribapi_swig.grib_c_index_write
def grib_c_index_read(file: 'char *') -> "int *":
return _gribapi_swig.grib_c_index_read(file)
def grib_c_index_read(*args):
return _gribapi_swig.grib_c_index_read(*args)
grib_c_index_read = _gribapi_swig.grib_c_index_read
def grib_c_new_from_message(INOUT: 'int *', binmsg: 'char *', INPUT: 'size_t *') -> "int *":
return _gribapi_swig.grib_c_new_from_message(INOUT, binmsg, INPUT)
def grib_c_new_from_message(*args):
return _gribapi_swig.grib_c_new_from_message(*args)
grib_c_new_from_message = _gribapi_swig.grib_c_new_from_message
def grib_c_count_in_file(f: 'FILE *') -> "int *":
return _gribapi_swig.grib_c_count_in_file(f)
def grib_c_count_in_file(*args):
return _gribapi_swig.grib_c_count_in_file(*args)
grib_c_count_in_file = _gribapi_swig.grib_c_count_in_file
def grib_c_release(gid: 'int *') -> "int":
return _gribapi_swig.grib_c_release(gid)
def grib_c_release(*args):
return _gribapi_swig.grib_c_release(*args)
grib_c_release = _gribapi_swig.grib_c_release
def grib_c_write(gid: 'int *', f: 'FILE *') -> "int":
return _gribapi_swig.grib_c_write(gid, f)
def grib_c_write(*args):
return _gribapi_swig.grib_c_write(*args)
grib_c_write = _gribapi_swig.grib_c_write
def grib_c_get_size_long(gid: 'int *', key: 'char *') -> "long *":
return _gribapi_swig.grib_c_get_size_long(gid, key)
def grib_c_get_size_long(*args):
return _gribapi_swig.grib_c_get_size_long(*args)
grib_c_get_size_long = _gribapi_swig.grib_c_get_size_long
def grib_c_get_string_length(gid: 'int *', key: 'char *') -> "size_t *":
return _gribapi_swig.grib_c_get_string_length(gid, key)
def grib_c_get_string_length(*args):
return _gribapi_swig.grib_c_get_string_length(*args)
grib_c_get_string_length = _gribapi_swig.grib_c_get_string_length
def grib_c_clone(gid: 'int *', INOUT: 'int *') -> "int *":
return _gribapi_swig.grib_c_clone(gid, INOUT)
def grib_c_clone(*args):
return _gribapi_swig.grib_c_clone(*args)
grib_c_clone = _gribapi_swig.grib_c_clone
def grib_c_copy_namespace(gid: 'int *', name: 'char *', INPUT: 'int *') -> "int":
return _gribapi_swig.grib_c_copy_namespace(gid, name, INPUT)
def grib_c_copy_namespace(*args):
return _gribapi_swig.grib_c_copy_namespace(*args)
grib_c_copy_namespace = _gribapi_swig.grib_c_copy_namespace
def grib_c_get_message_size(gid: 'int *') -> "size_t *":
return _gribapi_swig.grib_c_get_message_size(gid)
def grib_c_get_message_size(*args):
return _gribapi_swig.grib_c_get_message_size(*args)
grib_c_get_message_size = _gribapi_swig.grib_c_get_message_size
def grib_c_get_message_offset(gid: 'int *') -> "size_t *":
return _gribapi_swig.grib_c_get_message_offset(gid)
def grib_c_get_message_offset(*args):
return _gribapi_swig.grib_c_get_message_offset(*args)
grib_c_get_message_offset = _gribapi_swig.grib_c_get_message_offset
def grib_c_get_native_type(gid: 'int *', key: 'char *') -> "int *":
return _gribapi_swig.grib_c_get_native_type(gid, key)
def grib_c_get_native_type(*args):
return _gribapi_swig.grib_c_get_native_type(*args)
grib_c_get_native_type = _gribapi_swig.grib_c_get_native_type
def grib_c_multi_new() -> "int *":
return _gribapi_swig.grib_c_multi_new()
def grib_c_multi_new():
return _gribapi_swig.grib_c_multi_new()
grib_c_multi_new = _gribapi_swig.grib_c_multi_new
def grib_c_multi_support_on() -> "int":
return _gribapi_swig.grib_c_multi_support_on()
def grib_c_multi_support_on():
return _gribapi_swig.grib_c_multi_support_on()
grib_c_multi_support_on = _gribapi_swig.grib_c_multi_support_on
def grib_c_multi_write(gid: 'int *', f: 'FILE *') -> "int":
return _gribapi_swig.grib_c_multi_write(gid, f)
def grib_c_multi_write(*args):
return _gribapi_swig.grib_c_multi_write(*args)
grib_c_multi_write = _gribapi_swig.grib_c_multi_write
def grib_c_multi_support_off() -> "int":
return _gribapi_swig.grib_c_multi_support_off()
def grib_c_multi_support_off():
return _gribapi_swig.grib_c_multi_support_off()
grib_c_multi_support_off = _gribapi_swig.grib_c_multi_support_off
def grib_c_multi_release(gid: 'int *') -> "int":
return _gribapi_swig.grib_c_multi_release(gid)
def grib_c_multi_release(*args):
return _gribapi_swig.grib_c_multi_release(*args)
grib_c_multi_release = _gribapi_swig.grib_c_multi_release
def grib_c_multi_append(arg1: 'int *', arg2: 'int *', arg3: 'int *') -> "int":
return _gribapi_swig.grib_c_multi_append(arg1, arg2, arg3)
def grib_c_multi_append(*args):
return _gribapi_swig.grib_c_multi_append(*args)
grib_c_multi_append = _gribapi_swig.grib_c_multi_append
def grib_c_gribex_mode_on() -> "int":
return _gribapi_swig.grib_c_gribex_mode_on()
def grib_c_gribex_mode_on():
return _gribapi_swig.grib_c_gribex_mode_on()
grib_c_gribex_mode_on = _gribapi_swig.grib_c_gribex_mode_on
def grib_c_gribex_mode_off() -> "int":
return _gribapi_swig.grib_c_gribex_mode_off()
def grib_c_gribex_mode_off():
return _gribapi_swig.grib_c_gribex_mode_off()
grib_c_gribex_mode_off = _gribapi_swig.grib_c_gribex_mode_off
def grib_c_keys_iterator_next(iterid: 'int *') -> "int":
return _gribapi_swig.grib_c_keys_iterator_next(iterid)
def grib_c_keys_iterator_next(*args):
return _gribapi_swig.grib_c_keys_iterator_next(*args)
grib_c_keys_iterator_next = _gribapi_swig.grib_c_keys_iterator_next
def codes_c_bufr_keys_iterator_next(iterid: 'int *') -> "int":
return _gribapi_swig.codes_c_bufr_keys_iterator_next(iterid)
def codes_c_bufr_keys_iterator_next(*args):
return _gribapi_swig.codes_c_bufr_keys_iterator_next(*args)
codes_c_bufr_keys_iterator_next = _gribapi_swig.codes_c_bufr_keys_iterator_next
def grib_c_keys_iterator_delete(iterid: 'int *') -> "int":
return _gribapi_swig.grib_c_keys_iterator_delete(iterid)
def grib_c_keys_iterator_delete(*args):
return _gribapi_swig.grib_c_keys_iterator_delete(*args)
grib_c_keys_iterator_delete = _gribapi_swig.grib_c_keys_iterator_delete
def codes_c_bufr_keys_iterator_delete(iterid: 'int *') -> "int":
return _gribapi_swig.codes_c_bufr_keys_iterator_delete(iterid)
def codes_c_bufr_keys_iterator_delete(*args):
return _gribapi_swig.codes_c_bufr_keys_iterator_delete(*args)
codes_c_bufr_keys_iterator_delete = _gribapi_swig.codes_c_bufr_keys_iterator_delete
def grib_c_skip_computed(iterid: 'int *') -> "int":
return _gribapi_swig.grib_c_skip_computed(iterid)
def grib_c_skip_computed(*args):
return _gribapi_swig.grib_c_skip_computed(*args)
grib_c_skip_computed = _gribapi_swig.grib_c_skip_computed
def grib_c_skip_coded(iterid: 'int *') -> "int":
return _gribapi_swig.grib_c_skip_coded(iterid)
def grib_c_skip_coded(*args):
return _gribapi_swig.grib_c_skip_coded(*args)
grib_c_skip_coded = _gribapi_swig.grib_c_skip_coded
def grib_c_skip_edition_specific(iterid: 'int *') -> "int":
return _gribapi_swig.grib_c_skip_edition_specific(iterid)
def grib_c_skip_edition_specific(*args):
return _gribapi_swig.grib_c_skip_edition_specific(*args)
grib_c_skip_edition_specific = _gribapi_swig.grib_c_skip_edition_specific
def grib_c_skip_duplicates(iterid: 'int *') -> "int":
return _gribapi_swig.grib_c_skip_duplicates(iterid)
def grib_c_skip_duplicates(*args):
return _gribapi_swig.grib_c_skip_duplicates(*args)
grib_c_skip_duplicates = _gribapi_swig.grib_c_skip_duplicates
def grib_c_skip_read_only(iterid: 'int *') -> "int":
return _gribapi_swig.grib_c_skip_read_only(iterid)
def grib_c_skip_read_only(*args):
return _gribapi_swig.grib_c_skip_read_only(*args)
grib_c_skip_read_only = _gribapi_swig.grib_c_skip_read_only
def grib_c_skip_function(iterid: 'int *') -> "int":
return _gribapi_swig.grib_c_skip_function(iterid)
def grib_c_skip_function(*args):
return _gribapi_swig.grib_c_skip_function(*args)
grib_c_skip_function = _gribapi_swig.grib_c_skip_function
def grib_c_keys_iterator_rewind(iterid: 'int *') -> "int":
return _gribapi_swig.grib_c_keys_iterator_rewind(iterid)
def grib_c_keys_iterator_rewind(*args):
return _gribapi_swig.grib_c_keys_iterator_rewind(*args)
grib_c_keys_iterator_rewind = _gribapi_swig.grib_c_keys_iterator_rewind
def codes_c_bufr_keys_iterator_rewind(iterid: 'int *') -> "int":
return _gribapi_swig.codes_c_bufr_keys_iterator_rewind(iterid)
def codes_c_bufr_keys_iterator_rewind(*args):
return _gribapi_swig.codes_c_bufr_keys_iterator_rewind(*args)
codes_c_bufr_keys_iterator_rewind = _gribapi_swig.codes_c_bufr_keys_iterator_rewind
def grib_c_bufr_copy_data(gid: 'int *', INOUT: 'int *') -> "int *":
return _gribapi_swig.grib_c_bufr_copy_data(gid, INOUT)
def grib_c_bufr_copy_data(*args):
return _gribapi_swig.grib_c_bufr_copy_data(*args)
grib_c_bufr_copy_data = _gribapi_swig.grib_c_bufr_copy_data
def grib_c_keys_iterator_get_name(iterid: 'int *', len: 'int') -> "char *":
return _gribapi_swig.grib_c_keys_iterator_get_name(iterid, len)
def grib_c_keys_iterator_get_name(*args):
return _gribapi_swig.grib_c_keys_iterator_get_name(*args)
grib_c_keys_iterator_get_name = _gribapi_swig.grib_c_keys_iterator_get_name
def codes_c_bufr_keys_iterator_get_name(iterid: 'int *', len: 'int') -> "char *":
return _gribapi_swig.codes_c_bufr_keys_iterator_get_name(iterid, len)
def codes_c_bufr_keys_iterator_get_name(*args):
return _gribapi_swig.codes_c_bufr_keys_iterator_get_name(*args)
codes_c_bufr_keys_iterator_get_name = _gribapi_swig.codes_c_bufr_keys_iterator_get_name
def grib_c_index_get_size_long(iid: 'int *', key: 'char *') -> "long *":
return _gribapi_swig.grib_c_index_get_size_long(iid, key)
def grib_c_index_get_size_long(*args):
return _gribapi_swig.grib_c_index_get_size_long(*args)
grib_c_index_get_size_long = _gribapi_swig.grib_c_index_get_size_long
def grib_c_index_get_long(iid: 'int *', key: 'char *', val: 'long *', size: 'int *') -> "int":
return _gribapi_swig.grib_c_index_get_long(iid, key, val, size)
def grib_c_index_get_long(*args):
return _gribapi_swig.grib_c_index_get_long(*args)
grib_c_index_get_long = _gribapi_swig.grib_c_index_get_long
def grib_c_index_get_real8(iid: 'int *', key: 'char *', val: 'double *', size: 'int *') -> "int":
return _gribapi_swig.grib_c_index_get_real8(iid, key, val, size)
def grib_c_index_get_real8(*args):
return _gribapi_swig.grib_c_index_get_real8(*args)
grib_c_index_get_real8 = _gribapi_swig.grib_c_index_get_real8
def grib_c_index_get_string(iid: 'int *', key: 'char *', INPUT: 'int *', INOUT: 'int *') -> "char *, int *":
return _gribapi_swig.grib_c_index_get_string(iid, key, INPUT, INOUT)
def grib_c_index_get_string(*args):
return _gribapi_swig.grib_c_index_get_string(*args)
grib_c_index_get_string = _gribapi_swig.grib_c_index_get_string
def grib_c_index_select_long(iid: 'int *', key: 'char *', INPUT: 'long *') -> "int":
return _gribapi_swig.grib_c_index_select_long(iid, key, INPUT)
def grib_c_index_select_long(*args):
return _gribapi_swig.grib_c_index_select_long(*args)
grib_c_index_select_long = _gribapi_swig.grib_c_index_select_long
def grib_c_index_select_real8(iid: 'int *', key: 'char *', INPUT: 'double *') -> "int":
return _gribapi_swig.grib_c_index_select_real8(iid, key, INPUT)
def grib_c_index_select_real8(*args):
return _gribapi_swig.grib_c_index_select_real8(*args)
grib_c_index_select_real8 = _gribapi_swig.grib_c_index_select_real8
def grib_c_index_select_string(iid: 'int *', key: 'char *', val: 'char *') -> "int":
return _gribapi_swig.grib_c_index_select_string(iid, key, val)
def grib_c_index_select_string(*args):
return _gribapi_swig.grib_c_index_select_string(*args)
grib_c_index_select_string = _gribapi_swig.grib_c_index_select_string
def grib_c_index_release(iid: 'int *') -> "int":
return _gribapi_swig.grib_c_index_release(iid)
def grib_c_index_release(*args):
return _gribapi_swig.grib_c_index_release(*args)
grib_c_index_release = _gribapi_swig.grib_c_index_release
def grib_c_iterator_delete(iterid: 'int *') -> "int":
return _gribapi_swig.grib_c_iterator_delete(iterid)
def grib_c_iterator_delete(*args):
return _gribapi_swig.grib_c_iterator_delete(*args)
grib_c_iterator_delete = _gribapi_swig.grib_c_iterator_delete
def grib_c_iterator_next(iterid: 'int *') -> "double *, double *, double *":
return _gribapi_swig.grib_c_iterator_next(iterid)
def grib_c_iterator_next(*args):
return _gribapi_swig.grib_c_iterator_next(*args)
grib_c_iterator_next = _gribapi_swig.grib_c_iterator_next
def grib_c_get_string(gid: 'int *', key: 'char *', string_val: 'char *') -> "size_t *":
return _gribapi_swig.grib_c_get_string(gid, key, string_val)
def grib_c_get_string(*args):
return _gribapi_swig.grib_c_get_string(*args)
grib_c_get_string = _gribapi_swig.grib_c_get_string
def grib_c_get_string_array(gid: 'int *', key: 'char *', array_string_val: 'char **', size: 'size_t *') -> "int":
return _gribapi_swig.grib_c_get_string_array(gid, key, array_string_val, size)
def grib_c_get_string_array(*args):
return _gribapi_swig.grib_c_get_string_array(*args)
grib_c_get_string_array = _gribapi_swig.grib_c_get_string_array
def grib_c_set_string(gid: 'int *', key: 'char *', sval: 'char *', len2: 'int') -> "int":
return _gribapi_swig.grib_c_set_string(gid, key, sval, len2)
def grib_c_set_string(*args):
return _gribapi_swig.grib_c_set_string(*args)
grib_c_set_string = _gribapi_swig.grib_c_set_string
def grib_c_get_long(gid: 'int *', key: 'char *') -> "long *":
return _gribapi_swig.grib_c_get_long(gid, key)
def grib_c_get_long(*args):
return _gribapi_swig.grib_c_get_long(*args)
grib_c_get_long = _gribapi_swig.grib_c_get_long
def grib_c_set_long(gid: 'int *', key: 'char *', INPUT: 'long *') -> "int":
return _gribapi_swig.grib_c_set_long(gid, key, INPUT)
def grib_c_set_long(*args):
return _gribapi_swig.grib_c_set_long(*args)
grib_c_set_long = _gribapi_swig.grib_c_set_long
def grib_c_get_double(gid: 'int *', key: 'char *') -> "double *":
return _gribapi_swig.grib_c_get_double(gid, key)
def grib_c_get_double(*args):
return _gribapi_swig.grib_c_get_double(*args)
grib_c_get_double = _gribapi_swig.grib_c_get_double
def grib_c_set_double(gid: 'int *', key: 'char *', INPUT: 'double *') -> "int":
return _gribapi_swig.grib_c_set_double(gid, key, INPUT)
def grib_c_set_double(*args):
return _gribapi_swig.grib_c_set_double(*args)
grib_c_set_double = _gribapi_swig.grib_c_set_double
def grib_c_set_real8_array(gid: 'int *', key: 'char *', val: 'double *', size: 'int *') -> "int":
return _gribapi_swig.grib_c_set_real8_array(gid, key, val, size)
def grib_c_set_real8_array(*args):
return _gribapi_swig.grib_c_set_real8_array(*args)
grib_c_set_real8_array = _gribapi_swig.grib_c_set_real8_array
def grib_c_get_real8_array(gid: 'int *', key: 'char *', val: 'double *', size: 'int *') -> "int":
return _gribapi_swig.grib_c_get_real8_array(gid, key, val, size)
def grib_c_get_real8_array(*args):
return _gribapi_swig.grib_c_get_real8_array(*args)
grib_c_get_real8_array = _gribapi_swig.grib_c_get_real8_array
def grib_c_get_long_array(gid: 'int *', key: 'char *', val: 'long *', size: 'int *') -> "int":
return _gribapi_swig.grib_c_get_long_array(gid, key, val, size)
def grib_c_get_long_array(*args):
return _gribapi_swig.grib_c_get_long_array(*args)
grib_c_get_long_array = _gribapi_swig.grib_c_get_long_array
def grib_c_set_long_array(gid: 'int *', key: 'char *', val: 'long *', size: 'int *') -> "int":
return _gribapi_swig.grib_c_set_long_array(gid, key, val, size)
def grib_c_set_long_array(*args):
return _gribapi_swig.grib_c_set_long_array(*args)
grib_c_set_long_array = _gribapi_swig.grib_c_set_long_array
def grib_c_get_real8_element(gid: 'int *', key: 'char *', INPUT: 'int *') -> "double *":
return _gribapi_swig.grib_c_get_real8_element(gid, key, INPUT)
def grib_c_get_real8_element(*args):
return _gribapi_swig.grib_c_get_real8_element(*args)
grib_c_get_real8_element = _gribapi_swig.grib_c_get_real8_element
def grib_c_get_real8_elements(gid: 'int *', key: 'char *', index: 'int *', val: 'double *', size: 'int *') -> "int":
return _gribapi_swig.grib_c_get_real8_elements(gid, key, index, val, size)
def grib_c_get_real8_elements(*args):
return _gribapi_swig.grib_c_get_real8_elements(*args)
grib_c_get_real8_elements = _gribapi_swig.grib_c_get_real8_elements
def grib_c_set_missing(gid: 'int *', key: 'char *') -> "int":
return _gribapi_swig.grib_c_set_missing(gid, key)
def grib_c_set_missing(*args):
return _gribapi_swig.grib_c_set_missing(*args)
grib_c_set_missing = _gribapi_swig.grib_c_set_missing
def grib_c_set_key_vals(gid: 'int *', keyvals: 'char *') -> "int":
return _gribapi_swig.grib_c_set_key_vals(gid, keyvals)
def grib_c_set_key_vals(*args):
return _gribapi_swig.grib_c_set_key_vals(*args)
grib_c_set_key_vals = _gribapi_swig.grib_c_set_key_vals
def grib_c_is_missing(gid: 'int *', key: 'char *') -> "int *":
return _gribapi_swig.grib_c_is_missing(gid, key)
def grib_c_is_missing(*args):
return _gribapi_swig.grib_c_is_missing(*args)
grib_c_is_missing = _gribapi_swig.grib_c_is_missing
def grib_c_is_defined(gid: 'int *', key: 'char *') -> "int *":
return _gribapi_swig.grib_c_is_defined(gid, key)
def grib_c_is_defined(*args):
return _gribapi_swig.grib_c_is_defined(*args)
grib_c_is_defined = _gribapi_swig.grib_c_is_defined
def grib_c_set_string_array(gid: 'int *', key: 'char *', val: 'char const **') -> "int":
return _gribapi_swig.grib_c_set_string_array(gid, key, val)
def grib_c_set_string_array(*args):
return _gribapi_swig.grib_c_set_string_array(*args)
grib_c_set_string_array = _gribapi_swig.grib_c_set_string_array
def grib_set_double_ndarray(gid: 'int *', key: 'char *', dpin_val: 'double *') -> "int":
return _gribapi_swig.grib_set_double_ndarray(gid, key, dpin_val)
def grib_set_double_ndarray(*args):
return _gribapi_swig.grib_set_double_ndarray(*args)
grib_set_double_ndarray = _gribapi_swig.grib_set_double_ndarray
def grib_set_long_ndarray(gid: 'int *', key: 'char *', lpin_val: 'long *') -> "int":
return _gribapi_swig.grib_set_long_ndarray(gid, key, lpin_val)
def grib_set_long_ndarray(*args):
return _gribapi_swig.grib_set_long_ndarray(*args)
grib_set_long_ndarray = _gribapi_swig.grib_set_long_ndarray
def grib_get_double_ndarray(gid: 'int *', key: 'char *', dpout_val: 'double *') -> "int":
return _gribapi_swig.grib_get_double_ndarray(gid, key, dpout_val)
def grib_get_double_ndarray(*args):
return _gribapi_swig.grib_get_double_ndarray(*args)
grib_get_double_ndarray = _gribapi_swig.grib_get_double_ndarray
def grib_get_long_ndarray(gid: 'int *', key: 'char *', lpout_val: 'long *') -> "int":
return _gribapi_swig.grib_get_long_ndarray(gid, key, lpout_val)
def grib_get_long_ndarray(*args):
return _gribapi_swig.grib_get_long_ndarray(*args)
grib_get_long_ndarray = _gribapi_swig.grib_get_long_ndarray
def grib_get_double_ndelements(gid: 'int *', key: 'char *', ipin_index: 'int *', dpout_val: 'double *') -> "int":
return _gribapi_swig.grib_get_double_ndelements(gid, key, ipin_index, dpout_val)
def grib_get_double_ndelements(*args):
return _gribapi_swig.grib_get_double_ndelements(*args)
grib_get_double_ndelements = _gribapi_swig.grib_get_double_ndelements
def grib_c_find_nearest_single(gid: 'int *', arg2: 'int *', arg3: 'double *', arg4: 'double *') -> "double *, double *, double *, double *, int *":
return _gribapi_swig.grib_c_find_nearest_single(gid, arg2, arg3, arg4)
def grib_c_find_nearest_single(*args):
return _gribapi_swig.grib_c_find_nearest_single(*args)
grib_c_find_nearest_single = _gribapi_swig.grib_c_find_nearest_single
def grib_c_find_nearest_four_single(gid: 'int *', arg2: 'int *', arg3: 'double *', arg4: 'double *', outlats: 'double *', outlons: 'double *', values: 'double *', distances: 'double *', indexes: 'int *') -> "int":
return _gribapi_swig.grib_c_find_nearest_four_single(gid, arg2, arg3, arg4, outlats, outlons, values, distances, indexes)
def grib_c_find_nearest_four_single(*args):
return _gribapi_swig.grib_c_find_nearest_four_single(*args)
grib_c_find_nearest_four_single = _gribapi_swig.grib_c_find_nearest_four_single
def grib_c_get_message(gid: 'int *') -> "size_t *":
return _gribapi_swig.grib_c_get_message(gid)
def grib_c_get_message(*args):
return _gribapi_swig.grib_c_get_message(*args)
grib_c_get_message = _gribapi_swig.grib_c_get_message
def grib_c_get_error_string(INPUT: 'int *', len: 'int') -> "char *":
return _gribapi_swig.grib_c_get_error_string(INPUT, len)
def grib_c_get_error_string(*args):
return _gribapi_swig.grib_c_get_error_string(*args)
grib_c_get_error_string = _gribapi_swig.grib_c_get_error_string
def no_fail_on_wrong_length(flag: 'int') -> "void":
return _gribapi_swig.no_fail_on_wrong_length(flag)
def no_fail_on_wrong_length(*args):
return _gribapi_swig.no_fail_on_wrong_length(*args)
no_fail_on_wrong_length = _gribapi_swig.no_fail_on_wrong_length
def grib_c_get_api_version() -> "long":
return _gribapi_swig.grib_c_get_api_version()
def grib_c_get_api_version():
return _gribapi_swig.grib_c_get_api_version()
grib_c_get_api_version = _gribapi_swig.grib_c_get_api_version
def grib_c_gts_header_on() -> "void":
return _gribapi_swig.grib_c_gts_header_on()
def grib_c_gts_header_on():
return _gribapi_swig.grib_c_gts_header_on()
grib_c_gts_header_on = _gribapi_swig.grib_c_gts_header_on
def grib_c_gts_header_off() -> "void":
return _gribapi_swig.grib_c_gts_header_off()
def grib_c_gts_header_off():
return _gribapi_swig.grib_c_gts_header_off()
grib_c_gts_header_off = _gribapi_swig.grib_c_gts_header_off
def grib_c_set_definitions_path(path: 'char const *') -> "void":
return _gribapi_swig.grib_c_set_definitions_path(path)
def grib_c_set_definitions_path(*args):
return _gribapi_swig.grib_c_set_definitions_path(*args)
grib_c_set_definitions_path = _gribapi_swig.grib_c_set_definitions_path
def grib_c_set_samples_path(path: 'char const *') -> "void":
return _gribapi_swig.grib_c_set_samples_path(path)
def grib_c_set_samples_path(*args):
return _gribapi_swig.grib_c_set_samples_path(*args)
grib_c_set_samples_path = _gribapi_swig.grib_c_set_samples_path
# This file is compatible with both classic and new-style classes.

View File

@ -12,31 +12,31 @@ while 1:
gid = grib_new_from_file(fid)
if gid is None: break
print (grib_get(gid,"centre"))
print (grib_get(gid,"centre",int))
print (grib_get(gid,"centre",float))
print (grib_get(gid,"centre",str))
print grib_get(gid,"centre")
print grib_get(gid,"centre",int)
print grib_get(gid,"centre",float)
print grib_get(gid,"centre",str)
print ("Nvalues = ",grib_get_size(gid,"values"))
print "Nvalues = ",grib_get_size(gid,"values")
values = grib_get_array(gid,"values")
print (values[:10])
print values[:10]
values = values * 2
grib_set_double_array(gid,"values",values)
values = grib_get_array(gid,"values")
print (values[:10])
print values[:10]
values = values / 2
grib_set_double_array(gid,"values",[1])
values = grib_get_values(gid)
print (values[:10])
print values[:10]
print (grib_get(gid,"bitsPerValue"))
print grib_get(gid,"bitsPerValue")
grib_set(gid,"bitsPerValue",10)
print (grib_get(gid,"bitsPerValue"))
print grib_get(gid,"bitsPerValue")
grib_write(gid,oid)

View File

@ -44,25 +44,25 @@ def test():
#grib_write_file(binstr_fid,x)
#grib_close_file(binstr_fid)
print ("Operating on file '%s'" % infile)
print "Operating on file '%s'" % infile
n = grib_count_in_file(fid)
print ("Message count ",n)
print "Message count ",n
# multi support test
grib_multi_support_on()
ismulti = "no" if (n == grib_count_in_file(fid)) else "yes"
print ("Is multi field - %s" % ismulti)
print "Is multi field - %s" % ismulti
grib_multi_support_off()
# end multi support test
# gribex support test on/off
print ("Gribex support on/off")
print "Gribex support on/off"
grib_gribex_mode_on()
grib_gribex_mode_off
# end gribex support test
print ("Browsing through messages ")
print "Browsing through messages "
for i in range(n):
gid = grib_new_from_file(fid)
@ -70,71 +70,71 @@ def test():
#grib_print(gid,"centre")
if i == 0:
print ("Message size: ",grib_get_message_size(gid))
print "Message size: ",grib_get_message_size(gid)
nval = grib_get_size(gid,"values")
print ("Number of values in message %d is %d" % (i,nval))
print "Number of values in message %d is %d" % (i,nval)
print ("== %s %s %s %d ==" % \
print "== %s %s %s %d ==" % \
( \
grib_get_string(gid,"shortName"), \
grib_get_string(gid,"name"), \
grib_get_string(gid,"typeOfLevel"), \
grib_get_long(gid,"level"), \
))
)
print ("Nearest point to 10,10: ")
print (grib_find_nearest(gid,10,10))
print "Nearest point to 10,10: "
print grib_find_nearest(gid,10,10)
print (grib_find_nearest(gid,10,10,npoints=4))
print grib_find_nearest(gid,10,10,npoints=4)
rand_list = []
for i in range(0,5):
rand_index = random.randint(1,nval)
rand_list.append(rand_index)
myval = grib_get_double_element(gid,"values",rand_index)
print ("Random index value[%d] = %.8f" % (rand_index,myval))
print "Random index value[%d] = %.8f" % (rand_index,myval)
all4rand = grib_get_double_elements(gid,"values",rand_list)
print ("All at once index values: ",all4rand)
print "All at once index values: ",all4rand
centre = grib_get_string(gid,"centre")
grib_set_string(gid,"centre","ecmf")
new_centre = grib_get_string(gid,"centre")
print ("Before/after string centre: %s/%s" % (centre,new_centre))
print "Before/after string centre: %s/%s" % (centre,new_centre)
centre = grib_get_long(gid,"centre")
grib_set_long(gid,"centre",99)
new_centre = grib_get_long(gid,"centre")
print ("Before/after numeric centre: %d/%d" % (centre,new_centre))
print "Before/after numeric centre: %d/%d" % (centre,new_centre)
centre = grib_get_double(gid,"centre")
grib_set_double(gid,"centre",9)
new_centre = grib_get_double(gid,"centre")
print ("Before/after numeric floating point centre: %f/%f" % (centre,new_centre))
print "Before/after numeric floating point centre: %f/%f" % (centre,new_centre)
vals = grib_get_double_array(gid,"values")
print ("Values before: ",vals[:10])
print "Values before: ",vals[:10]
grib_set_double_array(gid,"values",(1.0, 2.0, 3.14))
vals = grib_get_double_array(gid,"values")
print ("Values after: ",vals[:10])
print "Values after: ",vals[:10]
print ("Saving modified message to %s" % outfile)
print "Saving modified message to %s" % outfile
if WRITE: grib_write(gid,out)
print ("Creating and saving a clone to %s" % clonefile)
print "Creating and saving a clone to %s" % clonefile
clone_gid = grib_clone(gid)
if WRITE: grib_write(clone_gid,clone_fid)
grib_release(clone_gid)
Ni = grib_get(gid,"Ni")
print ("Setting Ni to missing from --> ",Ni)
print "Setting Ni to missing from --> ",Ni
grib_set_missing(gid,"Ni")
assert grib_is_missing(gid,"Ni")
miss_Ni = grib_get(gid,"Ni")
print ("Ni is now --> ",miss_Ni)
print "Ni is now --> ",miss_Ni
grib_set(gid,"Ni",Ni)
new_Ni = grib_get(gid,"Ni")
print ("Set Ni back to its original value --> ",new_Ni)
print "Set Ni back to its original value --> ",new_Ni
assert Ni == new_Ni
#grib_multi_write(gid,multi)
@ -145,7 +145,7 @@ def test():
fid.close()
out.close()
clone_fid.close()
print ("Closed file")
print "Closed file"
def main():
@ -155,13 +155,13 @@ def main():
if VERBOSE:
traceback.print_exc(file=sys.stderr)
else:
print (err.msg, file=sys.stderr)
print >>sys.stderr,err.msg
return 1
except Usage:
print ("Usage: %s infile" % sys.argv[0])
print "Usage: %s infile" % sys.argv[0]
sys.exit(2)
if __name__ == "__main__":
main()
print ("------------------------------------")
print "------------------------------------"

View File

@ -34,20 +34,20 @@ def test():
infile = sys.argv[1]
index_keys = ["shortName","level","number","step"]
print ("indexing...")
print "indexing..."
iid = grib_index_new_from_file(infile,index_keys)
print ("end indexing...")
print "end indexing..."
index_vals = []
for key in index_keys:
print ("%sSize=%d" % (
print "%sSize=%d" % (
key,
grib_index_get_size(iid,key)
))
)
key_vals = grib_index_get_string(iid,key)
print (" ".join(key_vals))
print " ".join(key_vals)
index_vals.append(key_vals)
@ -58,7 +58,7 @@ def test():
while 1:
gid = grib_new_from_index(iid)
if gid is None: break
print (" ".join(["%s=%s" % (key,grib_get_string(gid,key)) for key in index_keys]))
print " ".join(["%s=%s" % (key,grib_get_string(gid,key)) for key in index_keys])
grib_release(gid)
grib_index_release(iid)
@ -71,13 +71,13 @@ def main():
if VERBOSE:
traceback.print_exc(file=sys.stderr)
else:
print (err.msg, file=sys.stderr)
print >>sys.stderr,err.msg
return 1
except Usage:
print ("Usage: %s infile" % sys.argv[0])
print "Usage: %s infile" % sys.argv[0]
sys.exit(2)
if __name__ == "__main__":
main()
#print ("------------------------------------")
#print "------------------------------------"

View File

@ -26,12 +26,12 @@ def main():
sys.stdout.write("- %d - lat=%.6f lon=%.6f value=" % (i,lat,lon))
if value == missingValue:
print("missing")
print "missing"
else:
print("%.6f" % value)
print "%.6f" % value
i += 1
grib_iterator_delete(iterid)
grib_release(gid)

View File

@ -22,7 +22,7 @@ for i in range(count):
keyname = grib_keys_iterator_get_name(iterid)
keyval = grib_get_string(iterid,keyname)
keytype = grib_get_native_type(gid,keyname)
print ("%s = %s (%s)" % (keyname,keyval,str(keytype)))
print "%s = %s (%s)" % (keyname,keyval,str(keytype))
grib_keys_iterator_delete(iterid)
grib_release(gid)

86
python3/CMakeLists.txt Normal file
View File

@ -0,0 +1,86 @@
if( HAVE_PYTHON )
#find_package( SWIG )
#if( SWIG_FOUND )
# include( ${SWIG_USE_FILE} )
#endif()
# preparing for generating setup.py
if( HAVE_LIBJASPER )
get_filename_component(JASPER_DIR ${JASPER_INCLUDE_DIR} PATH )
endif()
if( HAVE_LIBOPENJPEG )
# Get the name of the OpenJPEG library: version dependent!
# E.g. openjpeg (version 1.5) or openjp2 (version 2.x)
get_filename_component(OPENJPEG_LIB_DIR ${OPENJPEG_LIBRARY} PATH )
get_filename_component(OJ_NAME_WE ${OPENJPEG_LIBRARY} NAME_WE )
STRING(REGEX REPLACE "^lib" "" OJ_WITHOUT_LIB ${OJ_NAME_WE})
endif()
if( HAVE_AEC )
get_filename_component(AEC_DIR ${AEC_INCLUDE_DIR} PATH )
endif()
configure_file( setup.py.in setup.py )
# compile swig interface
# set(CMAKE_SWIG_FLAGS "")
# set_source_files_properties( gribapi_swig.i PROPERTIES C ON )
# if( NUMPY_FOUND )
# set( CMAKE_SWIG_FLAGS "-DNUMPY" )
# include_directories( ${NUMPY_INCLUDE_DIRS} )
# endif()
####### Do not invoke swig. Use our own generated C wrapper file ######
set( _gribapi_swig "gribapi/_gribapi_swig${CMAKE_SHARED_LIBRARY_SUFFIX}" )
# Build the extension module for use in build tree with RPATH pointing to the build tree
add_custom_command( OUTPUT ${_gribapi_swig}
COMMAND ${PYTHON_EXECUTABLE} setup.py build_ext --inplace --rpath ${CMAKE_BINARY_DIR}/lib
DEPENDS grib_interface.h grib_interface.c swig_wrap_numpy.c setup.py.in eccodes )
add_custom_target(eccodes_build_swig_wrapper ALL DEPENDS ${_gribapi_swig})
#ecbuild_add_library(TARGET _gribapi_swig
# TYPE SHARED
# NOINSTALL
# SOURCES grib_interface.h grib_interface.c swig_wrap_numpy.c
# INCLUDES ${CMAKE_CURRENT_SOURCE_DIR} ${CMAKE_CURRENT_BINARY_DIR} ${PYTHON_INCLUDE_DIRS}
# LIBS eccodes ${PYTHON_LIBRARIES} )
# Don't use the lib prefix. This is needed for the python case where a _modulename.so is generated
#set_target_properties(_gribapi_swig PROPERTIES PREFIX "")
# Copy gribapi and eccodes python modules to build area
file( COPY eccodes gribapi DESTINATION . )
configure_file( swig_wrap_numpy.py gribapi/gribapi_swig.py COPYONLY )
# Build the extension module for use in install tree with RPATH pointing to install tree
install(CODE "message(\"Building Python extension modules:
${PYTHON_EXECUTABLE} setup.py build_ext --rpath ${CMAKE_INSTALL_PREFIX}/${INSTALL_LIB_DIR}\")
execute_process(COMMAND ${PYTHON_EXECUTABLE} setup.py build_ext --rpath ${CMAKE_INSTALL_PREFIX}/${INSTALL_LIB_DIR}
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR})")
# Library installation directory override
if( NOT INSTALL_LIB_DIR STREQUAL lib )
execute_process( COMMAND ${PYTHON_EXECUTABLE} -c "from __future__ import print_function; import sys; print(sys.version[:3], end='')"
OUTPUT_VARIABLE PYVER )
set( __install_lib "--install-lib=${ECCODES_FULL_INSTALL_LIB_DIR}/python${PYVER}/site-packages" )
endif()
# Call distutils for installation
install(CODE "if( NOT \$ENV{DESTDIR} STREQUAL \"\" )
set( __root \"--root=\$ENV{DESTDIR}\" )
endif()
message(\"Installing Python modules:
${PYTHON_EXECUTABLE} setup.py install \${__root}
${__install_lib}
--prefix=${CMAKE_INSTALL_PREFIX}
--record=${CMAKE_BINARY_DIR}/extra_install.txt\")
execute_process(COMMAND ${PYTHON_EXECUTABLE} setup.py install
\${__root}
--prefix=${CMAKE_INSTALL_PREFIX}
${__install_lib}
--record=${CMAKE_BINARY_DIR}/extra_install.txt
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR})")
endif()

5
python3/README.swig Normal file
View File

@ -0,0 +1,5 @@
# we use pre-generated files from SWIG - to recreate them use:
swig -python -module gribapi_swig -o swig_wrap_numpy.c gribapi_swig.i
cp gribapi_swig.py swig_wrap_numpy.py

111
python3/create_errors.py.sh Executable file
View File

@ -0,0 +1,111 @@
#!/usr/bin/env perl
# This script is used to generate the file "python/gribapi/errors.py"
# It reads "src/grib_errors.c" which it expects to be up-to-date with
# all the error codes.
$|=1;
my $input = '../src/grib_errors.c';
my $print_class = 1;
my %errmap = ();
# Print header
# -------------------------------------
my $header = <<'END_HEADER';
"""
Exception class hierarchy
"""
import gribapi_swig as _internal
class GribInternalError(Exception):
"""
@brief Wrap errors coming from the C API in a Python exception object.
Base class for all exceptions
"""
def __init__(self, value):
# Call the base class constructor with the parameters it needs
Exception.__init__(self, value)
if type(value) is int:
err, self.msg = _internal.grib_c_get_error_string(value, 1024)
assert err == 0
else:
self.msg = value
def __str__(self):
return self.msg
END_HEADER
print $header;
# Print the exception classes
# -------------------------------------
while (<>) {
# Example of input line
# "Passed array is too small", /* -6 GRIB_ARRAY_TOO_SMALL */
if (/^"(.*)",\s+\/\* (.*) (.*) \*\//) {
$desc = $1;
$code = $2;
$name = $3;
next if ($code == 0);
$name =~ s/GRIB_//;
$name_lc = $name;
$name_lc =~ s/_/ /g;
$name_lc = lc $name_lc;
$name_lc =~ s/(\w+)/\u$1/g;
$name_lc =~ s/ //g;
$name = $name_lc;
if ($name !~ /Error$/) {
$name = $name . "Error";
}
$name = 'FunctionNotImplementedError' if ($name eq 'NotImplementedError');
$name = 'MessageEndNotFoundError' if ($name eq '7777NotFoundError');
$name = 'IOProblemError' if ($name eq 'IoProblemError');
$name = 'MessageInvalidError' if ($name eq 'InvalidMessageError');
$name = 'GeocalculusError' if ($name eq 'GeocalculusProblemError');
$name = 'InvalidOrderByError' if ($name eq 'InvalidOrderbyError');
$name = 'InvalidBitsPerValueError' if ($name eq 'InvalidBpvError');
$name = 'KeyValueNotFoundError' if ($name eq 'NotFoundError');
$name = 'MemoryAllocationError' if ($name eq 'OutOfMemoryError');
# Print the class declaration
print "class ${name}(GribInternalError):\n";
print " \"\"\"${desc}.\"\"\"\n";
$errmap{$code} = $name; # store for later
}
}
# Print the map
# -------------------------------------
my $size = keys %errmap;
print "\nERROR_MAP = {\n";
my $i = 0;
for $key (sort { $a <=> $b } keys %errmap) {
$i++;
my $ktext = sprintf("%-3d", $key);
print " $ktext : $errmap{$key}";
print ",\n" if ($i < $size);
}
print "\n}\n\n";
# Print footer
# -------------------------------------
my $footer = <<'END_FOOTER';
def raise_grib_error(errid):
"""
Raise the GribInternalError corresponding to ``errid``.
"""
raise ERROR_MAP[errid](errid)
END_FOOTER
print $footer;

View File

@ -0,0 +1,11 @@
from __future__ import absolute_import
import sys
from .eccodes import *
from .eccodes import __version__
if sys.version_info >= (2, 6):
from .high_level.gribfile import GribFile
from .high_level.gribmessage import GribMessage
from .high_level.gribindex import GribIndex
from .high_level.bufr import BufrFile, BufrMessage

109
python3/eccodes/eccodes.py Normal file
View File

@ -0,0 +1,109 @@
from gribapi import __version__
from gribapi import GRIB_CHECK as CODES_CHECK
from gribapi import CODES_PRODUCT_GRIB
from gribapi import CODES_PRODUCT_BUFR
from gribapi import CODES_PRODUCT_ANY
from gribapi import GRIB_MISSING_DOUBLE as CODES_MISSING_DOUBLE
from gribapi import GRIB_MISSING_LONG as CODES_MISSING_LONG
from gribapi import gts_new_from_file as codes_gts_new_from_file
from gribapi import metar_new_from_file as codes_metar_new_from_file
from gribapi import codes_new_from_file
from gribapi import any_new_from_file as codes_any_new_from_file
from gribapi import bufr_new_from_file as codes_bufr_new_from_file
from gribapi import grib_new_from_file as codes_grib_new_from_file
from gribapi import grib_count_in_file as codes_count_in_file
from gribapi import grib_multi_support_on as codes_grib_multi_support_on
from gribapi import grib_multi_support_off as codes_grib_multi_support_off
from gribapi import grib_release as codes_release
from gribapi import grib_get_string as codes_get_string
from gribapi import grib_set_string as codes_set_string
from gribapi import grib_gribex_mode_on as codes_gribex_mode_on
from gribapi import grib_gribex_mode_off as codes_gribex_mode_off
from gribapi import grib_write as codes_write
from gribapi import grib_multi_write as codes_grib_multi_write
from gribapi import grib_multi_append as codes_grib_multi_append
from gribapi import grib_get_size as codes_get_size
from gribapi import grib_get_string_length as codes_get_string_length
from gribapi import grib_skip_computed as codes_skip_computed
from gribapi import grib_skip_coded as codes_skip_coded
from gribapi import grib_skip_edition_specific as codes_skip_edition_specific
from gribapi import grib_skip_duplicates as codes_skip_duplicates
from gribapi import grib_skip_read_only as codes_skip_read_only
from gribapi import grib_skip_function as codes_skip_function
from gribapi import grib_iterator_new as codes_grib_iterator_new
from gribapi import grib_iterator_delete as codes_grib_iterator_delete
from gribapi import grib_iterator_next as codes_grib_iterator_next
from gribapi import grib_keys_iterator_new as codes_keys_iterator_new
from gribapi import grib_keys_iterator_next as codes_keys_iterator_next
from gribapi import grib_keys_iterator_delete as codes_keys_iterator_delete
from gribapi import grib_keys_iterator_get_name as codes_keys_iterator_get_name
from gribapi import grib_keys_iterator_rewind as codes_keys_iterator_rewind
from gribapi import codes_bufr_keys_iterator_new
from gribapi import codes_bufr_keys_iterator_next
from gribapi import codes_bufr_keys_iterator_delete
from gribapi import codes_bufr_keys_iterator_get_name
from gribapi import codes_bufr_keys_iterator_rewind
from gribapi import grib_get_long as codes_get_long
from gribapi import grib_get_double as codes_get_double
from gribapi import grib_set_long as codes_set_long
from gribapi import grib_set_double as codes_set_double
from gribapi import grib_new_from_samples as codes_grib_new_from_samples
from gribapi import codes_bufr_new_from_samples
from gribapi import codes_new_from_samples
from gribapi import codes_bufr_copy_data
from gribapi import grib_clone as codes_clone
from gribapi import grib_set_double_array as codes_set_double_array
from gribapi import grib_get_double_array as codes_get_double_array
from gribapi import grib_get_string_array as codes_get_string_array
from gribapi import grib_set_string_array as codes_set_string_array
from gribapi import grib_set_long_array as codes_set_long_array
from gribapi import grib_get_long_array as codes_get_long_array
from gribapi import grib_multi_new as codes_grib_multi_new
from gribapi import grib_multi_release as codes_grib_multi_release
from gribapi import grib_copy_namespace as codes_copy_namespace
from gribapi import grib_index_new_from_file as codes_index_new_from_file
from gribapi import grib_index_add_file as codes_index_add_file
from gribapi import grib_index_release as codes_index_release
from gribapi import grib_index_get_size as codes_index_get_size
from gribapi import grib_index_get_long as codes_index_get_long
from gribapi import grib_index_get_string as codes_index_get_string
from gribapi import grib_index_get_double as codes_index_get_double
from gribapi import grib_index_select_long as codes_index_select_long
from gribapi import grib_index_select_double as codes_index_select_double
from gribapi import grib_index_select_string as codes_index_select_string
from gribapi import grib_new_from_index as codes_new_from_index
from gribapi import grib_get_message_size as codes_get_message_size
from gribapi import grib_get_message_offset as codes_get_message_offset
from gribapi import grib_get_double_element as codes_get_double_element
from gribapi import grib_get_double_elements as codes_get_double_elements
from gribapi import grib_get_elements as codes_get_elements
from gribapi import grib_set_missing as codes_set_missing
from gribapi import grib_set_key_vals as codes_set_key_vals
from gribapi import grib_is_missing as codes_is_missing
from gribapi import grib_is_defined as codes_is_defined
from gribapi import grib_find_nearest as codes_grib_find_nearest
from gribapi import grib_get_native_type as codes_get_native_type
from gribapi import grib_get as codes_get
from gribapi import grib_get_array as codes_get_array
from gribapi import grib_get_values as codes_get_values
from gribapi import grib_set_values as codes_set_values
from gribapi import grib_set as codes_set
from gribapi import grib_set_array as codes_set_array
from gribapi import grib_index_get as codes_index_get
from gribapi import grib_index_select as codes_index_select
from gribapi import grib_index_write as codes_index_write
from gribapi import grib_index_read as codes_index_read
from gribapi import grib_no_fail_on_wrong_length as codes_no_fail_on_wrong_length
from gribapi import grib_gts_header as codes_gts_header
from gribapi import grib_get_api_version as codes_get_api_version
from gribapi import grib_get_message as codes_get_message
from gribapi import grib_new_from_message as codes_new_from_message
from gribapi import grib_set_definitions_path as codes_set_definitions_path
from gribapi import grib_set_samples_path as codes_set_samples_path
from gribapi import GribInternalError as CodesInternalError
from gribapi.errors import *

View File

View File

@ -0,0 +1,97 @@
"""
Classes for handling BUFR with a high level interface.
``BufrFiles`` can be treated mostly as regular files and used as context
managers, as can ``BufrMessages``. Each of these classes destructs itself and
any child instances appropriately.
Author: Daniel Lee, DWD, 2016
"""
from .. import eccodes
from .codesmessage import CodesMessage
from .codesfile import CodesFile
class BufrMessage(CodesMessage):
__doc__ = "\n".join(CodesMessage.__doc__.splitlines()[4:]).format(
prod_type="BUFR", classname="BufrMessage", parent="BufrFile",
alias="bufr")
product_kind = eccodes.CODES_PRODUCT_BUFR
# Arguments included explicitly to support introspection
# TODO: Can we get this to work with an index?
def __init__(self, codes_file=None, clone=None, sample=None,
headers_only=False):
"""
Open a message and inform the GRIB file that it's been incremented.
The message is taken from ``codes_file``, cloned from ``clone`` or
``sample``, or taken from ``index``, in that order of precedence.
"""
super(self.__class__, self).__init__(codes_file, clone, sample,
headers_only)
#self._unpacked = False
#def get(self, key, ktype=None):
# """Return requested value, unpacking data values if necessary."""
# # TODO: Only do this if accessing arrays that need unpacking
# if not self._unpacked:
# self.unpacked = True
# return super(self.__class__, self).get(key, ktype)
#def missing(self, key):
# """
# Report if key is missing.#
#
# Overloaded due to confusing behaviour in ``codes_is_missing`` (SUP-1874).
# """
# return not bool(eccodes.codes_is_defined(self.codes_id, key))
def unpack(self):
"""Decode data section"""
eccodes.codes_set(self.codes_id, 'unpack', 1)
def pack(self):
"""Encode data section"""
eccodes.codes_set(self.codes_id, 'pack', 1)
def keys(self, namespace=None):
#self.unpack()
#return super(self.__class__, self).keys(namespace)
iterator = eccodes.codes_bufr_keys_iterator_new(self.codes_id)
keys = []
while eccodes.codes_bufr_keys_iterator_next(iterator):
key = eccodes.codes_bufr_keys_iterator_get_name(iterator)
keys.append(key)
eccodes.codes_bufr_keys_iterator_delete(iterator)
return keys
#@property
#def unpacked(self):
# return self._unpacked
#@unpacked.setter
#def unpacked(self, val):
# eccodes.codes_set(self.codes_id, "unpack", val)
# self._unpacked = val
#def __setitem__(self, key, value):
# """Set item and pack BUFR."""
# if not self._unpacked:
# self.unpacked = True
# super(self.__class__, self).__setitem__(key, value)
# eccodes.codes_set(self.codes_id, "pack", True)
def copy_data(self, destMsg):
"""Copy data values from this message to another message"""
return eccodes.codes_bufr_copy_data(self.codes_id, destMsg.codes_id)
class BufrFile(CodesFile):
__doc__ = "\n".join(CodesFile.__doc__.splitlines()[4:]).format(
prod_type="BUFR", classname="BufrFile", alias="bufr")
MessageClass = BufrMessage

View File

@ -0,0 +1,72 @@
"""
``CodesFile`` class that implements a file that is readable by ecCodes and
closes itself and its messages when it is no longer needed.
Author: Daniel Lee, DWD, 2016
"""
from .. import eccodes
import io
class CodesFile(io.IOBase):
"""
An abstract class to specify and/or implement common behaviour that files
read by ecCodes should implement.
A {prod_type} file handle meant for use in a context manager.
Individual messages can be accessed using the ``next`` method. Of course,
it is also possible to iterate over each message in the file::
>>> with {classname}(filename) as {alias}:
... # Print number of messages in file
... len({alias})
... # Open all messages in file
... for msg in {alias}:
... print(msg[key_name])
... len({alias}.open_messages)
>>> # When the file is closed, any open messages are closed
>>> len({alias}.open_messages)
"""
#: Type of messages belonging to this file
MessageClass = None
def __init__(self, filename, mode="r"):
"""Open file and receive codes file handle."""
#: File handle for working with actual file on disc
#: The class holds the file it works with because ecCodes'
# typechecking does not allow using inherited classes.
self.file_handle = open(filename, mode)
#: Number of message in file currently being read
self.message = 0
#: Open messages
self.open_messages = []
self.name = filename
def __exit__(self, exception_type, exception_value, traceback):
"""Close all open messages, release file handle and close file."""
while self.open_messages:
self.open_messages.pop().close()
self.file_handle.close()
def __len__(self):
"""Return total number of messages in file."""
return eccodes.codes_count_in_file(self.file_handle)
def __enter__(self):
return self
def close(self):
"""Possibility to manually close file."""
self.__exit__(None, None, None)
def __iter__(self):
return self
def next(self):
try:
return self.MessageClass(self)
except IOError:
raise StopIteration()

View File

@ -0,0 +1,186 @@
"""
``CodesMessage`` class that implements a message readable by ecCodes that
allows access to the message's key-value pairs in a dictionary-like manner
and closes the message when it is no longer needed, coordinating this with
its host file.
Author: Daniel Lee, DWD, 2016
"""
from .. import eccodes
class CodesMessage(object):
"""
An abstract class to specify and/or implement common behaviour that
messages read by ecCodes should implement.
A {prod_type} message.
Each ``{classname}`` is stored as a key/value pair in a dictionary-like
structure. It can be used in a context manager or by itself. When the
``{parent}`` it belongs to is closed, the ``{parent}`` closes any open
``{classname}``s that belong to it. If a ``{classname}`` is closed before
its ``{parent}`` is closed, it informs the ``{parent}`` of its closure.
Scalar and vector values are set appropriately through the same method.
``{classname}``s can be instantiated from a ``{parent}``, cloned from
other ``{classname}``s or taken from samples. Iterating over the members
of a ``{parent}`` extracts the ``{classname}``s it contains until the
``{parent}`` is exhausted.
Usage::
>>> with {parent}(filename) as {alias}:
... # Access a key from each message
... for msg in {alias}:
... print(msg[key_name])
... # Report number of keys in message
... len(msg)
... # Report message size in bytes
... msg.size
... # Report keys in message
... msg.keys()
... # Set scalar value
... msg[scalar_key] = 5
... # Check key's value
... msg[scalar_key]
... msg[key_name]
... # Array values are set transparently
... msg[array_key] = [1, 2, 3]
... # Messages can be written to file
... with open(testfile, "w") as test:
... msg.write(test)
... # Messages can be cloned from other messages
... msg2 = {classname}(clone=msg)
... # If desired, messages can be closed manually or used in with
... msg.close()
"""
#: ecCodes enum-like PRODUCT constant
product_kind = None
def __init__(self, codes_file=None, clone=None, sample=None,
headers_only=False, other_args_found=False):
"""
Open a message and inform the host file that it's been incremented.
If ``codes_file`` is not supplied, the message is cloned from
``CodesMessage`` ``clone``. If neither is supplied,
the ``CodesMessage`` is cloned from ``sample``.
:param codes_file: A file readable for ecCodes
:param clone: A valid ``CodesMessage``
:param sample: A valid sample path to create ``CodesMessage`` from
"""
if not other_args_found and codes_file is None and clone is None and sample is None:
raise RuntimeError("CodesMessage initialization parameters not "
"present.")
#: Unique ID, for ecCodes interface
self.codes_id = None
#: File containing message
self.codes_file = None
if codes_file is not None:
self.codes_id = eccodes.codes_new_from_file(
codes_file.file_handle, self.product_kind, headers_only)
if self.codes_id is None:
raise IOError("CodesFile %s is exhausted" % codes_file.name)
self.codes_file = codes_file
self.codes_file.message += 1
self.codes_file.open_messages.append(self)
elif clone is not None:
self.codes_id = eccodes.codes_clone(clone.codes_id)
elif sample is not None:
self.codes_id = eccodes.codes_new_from_samples(
sample, self.product_kind)
def write(self, outfile=None):
"""Write message to file."""
if not outfile:
# This is a hack because the API does not accept inheritance
outfile = self.codes_file.file_handle
eccodes.codes_write(self.codes_id, outfile)
def __setitem__(self, key, value):
"""
Set value associated with key.
Iterables and scalars are handled intelligently.
"""
# Passed key is iterable. Value has to be iterable too
if hasattr(key, "__iter__"):
if type(key) != type(value):
raise TypeError('Key must have same type as value')
if len(key) != len(value):
raise ValueError('Key array must have same size as value array')
eccodes.codes_set_key_vals(self.codes_id,",".join([str(key[i])+"="+str(value[i]) for i in range(len(key))]))
elif hasattr(value, "__iter__"):
# Passed value is iterable and not string
eccodes.codes_set_array(self.codes_id, key, value)
else:
eccodes.codes_set(self.codes_id, key, value)
def keys(self, namespace=None):
"""Get available keys in message."""
iterator = eccodes.codes_keys_iterator_new(self.codes_id,
namespace=namespace)
keys = []
while eccodes.codes_keys_iterator_next(iterator):
key = eccodes.codes_keys_iterator_get_name(iterator)
keys.append(key)
eccodes.codes_keys_iterator_delete(iterator)
return keys
def size(self):
"""Return size of message in bytes."""
return eccodes.codes_get_message_size(self.codes_id)
def dump(self):
"""Dump message's binary content."""
return eccodes.codes_get_message(self.codes_id)
def get(self, key, ktype=None):
"""Get value of a given key as its native or specified type."""
# if self.missing(key):
# raise KeyError("Value of key %s is MISSING." % key)
if eccodes.codes_get_size(self.codes_id, key) > 1:
ret = eccodes.codes_get_array(self.codes_id, key, ktype)
else:
ret = eccodes.codes_get(self.codes_id, key, ktype)
return ret
def __exit__(self, exc_type, exc_val, exc_tb):
"""Release message handle and inform host file of release."""
eccodes.codes_release(self.codes_id)
def __enter__(self):
return self
def close(self):
"""Possibility to manually close message."""
self.__exit__(None, None, None)
def __contains__(self, key):
"""Check whether a key is present in message."""
return key in self.keys()
def __len__(self):
"""Return key count."""
return len(self.keys())
def __getitem__(self, key):
"""Return value associated with key as its native type."""
return self.get(key)
def __iter__(self):
return iter(self.keys())
# Not yet implemented
# def itervalues(self):
# return self.values()
def items(self):
"""Return list of tuples of all key/value pairs."""
return [(key, self[key]) for key in self.keys()]

View File

@ -0,0 +1,17 @@
"""
``GribFile`` class that implements a GRIB file that closes itself and its
messages when it is no longer needed.
Author: Daniel Lee, DWD, 2014
"""
from .codesfile import CodesFile
from .gribmessage import GribMessage
class GribFile(CodesFile):
__doc__ = "\n".join(CodesFile.__doc__.splitlines()[4:]).format(
prod_type="GRIB", classname="GribFile", alias="grib")
MessageClass = GribMessage

View File

@ -0,0 +1,102 @@
"""
``GribIndex`` class that implements a GRIB index that allows access to
ecCodes's index functionality.
Author: Daniel Lee, DWD, 2014
"""
from .. import eccodes
from .gribmessage import GribMessage
class GribIndex(object):
"""
A GRIB index meant for use in a context manager.
Usage::
>>> # Create index from file with keys
>>> with GribIndex(filename, keys) as idx:
... # Write index to file
... idx.write(index_file)
>>> # Read index from file
>>> with GribIndex(file_index=index_file) as idx:
... # Add new file to index
... idx.add(other_filename)
... # Report number of unique values for given key
... idx.size(key)
... # Report unique values indexed by key
... idx.values(key)
... # Request GribMessage matching key, value
... msg = idx.select({key: value})
"""
def __enter__(self):
return self
def __exit__(self, exception_type, exception_value, traceback):
"""Release GRIB message handle and inform file of release."""
while self.open_messages:
self.open_messages[0].close()
eccodes.codes_index_release(self.iid)
def close(self):
"""Possibility to manually close index."""
self.__exit__(None, None, None)
def __init__(self, filename=None, keys=None, file_index=None,
grib_index=None):
"""
Create new GRIB index over ``keys`` from ``filename``.
``filename`` should be a string of the desired file's filename.
``keys`` should be a sequence of keys to index. ``file_index`` should
be a string of the file that the index should be loaded from.
``grib_index`` should be another ``GribIndex``.
If ``filename`` and ``keys`` are provided, the ``GribIndex`` is
initialized over the given keys from the given file. If they are not
provided, the ``GribIndex`` is read from ``indexfile``. If
``grib_index`` is provided, it is cloned from the given ``GribIndex``.
"""
#: Grib index ID
self.iid = None
if filename and keys:
self.iid = eccodes.codes_index_new_from_file(filename, keys)
elif file_index:
self.iid = eccodes.codes_index_read(file_index)
elif grib_index:
self.iid = eccodes.codes_new_from_index(grib_index.iid)
else:
raise RuntimeError("No source was supplied "
"(possibilities: grib_file, clone, sample).")
#: Indexed keys. Only available if GRIB is initialized from file.
self.keys = keys
#: Open GRIB messages
self.open_messages = []
def size(self, key):
"""Return number of distinct values for index key."""
return eccodes.codes_index_get_size(self.iid, key)
def values(self, key, ktype=str):
"""Return distinct values of index key."""
return eccodes.codes_index_get(self.iid, key, ktype)
def add(self, filename):
"""Add ``filename`` to the ``GribIndex``."""
eccodes.codes_index_add_file(self.iid, filename)
def write(self, outfile):
"""Write index to filename at ``outfile``."""
eccodes.codes_index_write(self.iid, outfile)
def select(self, key_value_pairs):
"""
Return message associated with given key value pairs.
``key_value_pairs`` should be passed as a dictionary.
"""
for key in key_value_pairs:
eccodes.codes_index_select(self.iid, key, key_value_pairs[key])
return GribMessage(gribindex=self)

View File

@ -0,0 +1,80 @@
"""
``GribMessage`` class that implements a GRIB message that allows access to
the message's key-value pairs in a dictionary-like manner and closes the
message when it is no longer needed, coordinating this with its host file.
Author: Daniel Lee, DWD, 2014
"""
from .codesmessage import CodesMessage
from .. import eccodes
class IndexNotSelectedError(Exception):
"""GRIB index was requested before selecting key/value pairs."""
class GribMessage(CodesMessage):
__doc__ = "\n".join(CodesMessage.__doc__.splitlines()[4:]).format(
prod_type="GRIB", classname="GribMessage", parent="GribFile",
alias="grib")
product_kind = eccodes.CODES_PRODUCT_GRIB
# Arguments included explicitly to support introspection
def __init__(self, codes_file=None, clone=None, sample=None,
headers_only=False, gribindex=None):
"""
Open a message and inform the GRIB file that it's been incremented.
The message is taken from ``codes_file``, cloned from ``clone`` or
``sample``, or taken from ``index``, in that order of precedence.
"""
grib_args_present = True
if gribindex is None:
grib_args_present = False
super(self.__class__, self).__init__(codes_file, clone, sample,
headers_only, grib_args_present)
#: GribIndex referencing message
self.grib_index = None
if gribindex is not None:
self.codes_id = eccodes.codes_new_from_index(gribindex.iid)
if not self.codes_id:
raise IndexNotSelectedError("All keys must have selected "
"values before receiving message "
"from index.")
self.grib_index = gribindex
gribindex.open_messages.append(self)
def __exit__(self, exc_type, exc_val, exc_tb):
"""Release GRIB message handle and inform file of release."""
super(self.__class__, self).__exit__(exc_type, exc_val, exc_tb)
if self.grib_index:
self.grib_index.open_messages.remove(self)
def missing(self, key):
"""Report if the value of a key is MISSING."""
return bool(eccodes.codes_is_missing(self.codes_id, key))
def set_missing(self, key):
"""Set the value of key to MISSING."""
eccodes.codes_set_missing(self.codes_id, key)
@property
def gid(self):
"""Provided for backwards compatibility."""
return self.codes_id
@property
def grib_file(self):
"""Provided for backwards compatibility."""
return self.codes_file
@gid.setter
def gid(self, val):
self.codes_id = val
@grib_file.setter
def grib_file(self, val):
self.codes_file = val

7
python3/extrules.am Normal file
View File

@ -0,0 +1,7 @@
# Use SWIG version 3.0.12
# Python3 support added with -py3
#
swig : gribapi_swig.i
swig -v -py3 -python -module gribapi_swig -o swig_wrap_numpy.c gribapi_swig.i
cp gribapi_swig.py swig_wrap_numpy.py

143
python3/grib_errors.h Normal file
View File

@ -0,0 +1,143 @@
/* This part is automatically generated by ./errors.pl, do not edit */
#ifndef grib_errors_H
#define grib_errors_H
/*! \defgroup errors Error codes
Error codes returned by the grib_api functions.
*/
/*! @{*/
/** No error */
#define GRIB_SUCCESS 0
/** End of resource reached */
#define GRIB_END_OF_FILE -1
/** Internal error */
#define GRIB_INTERNAL_ERROR -2
/** Passed buffer is too small */
#define GRIB_BUFFER_TOO_SMALL -3
/** Function not yet implemented */
#define GRIB_NOT_IMPLEMENTED -4
/** Missing 7777 at end of message */
#define GRIB_7777_NOT_FOUND -5
/** Passed array is too small */
#define GRIB_ARRAY_TOO_SMALL -6
/** File not found */
#define GRIB_FILE_NOT_FOUND -7
/** Code not found in code table */
#define GRIB_CODE_NOT_FOUND_IN_TABLE -8
/** Array size mismatch */
#define GRIB_WRONG_ARRAY_SIZE -9
/** Key/value not found */
#define GRIB_NOT_FOUND -10
/** Input output problem */
#define GRIB_IO_PROBLEM -11
/** Message invalid */
#define GRIB_INVALID_MESSAGE -12
/** Decoding invalid */
#define GRIB_DECODING_ERROR -13
/** Encoding invalid */
#define GRIB_ENCODING_ERROR -14
/** Code cannot unpack because of string too small */
#define GRIB_NO_MORE_IN_SET -15
/** Problem with calculation of geographic attributes */
#define GRIB_GEOCALCULUS_PROBLEM -16
/** Memory allocation error */
#define GRIB_OUT_OF_MEMORY -17
/** Value is read only */
#define GRIB_READ_ONLY -18
/** Invalid argument */
#define GRIB_INVALID_ARGUMENT -19
/** Null handle */
#define GRIB_NULL_HANDLE -20
/** Invalid section number */
#define GRIB_INVALID_SECTION_NUMBER -21
/** Value cannot be missing */
#define GRIB_VALUE_CANNOT_BE_MISSING -22
/** Wrong message length */
#define GRIB_WRONG_LENGTH -23
/** Invalid key type */
#define GRIB_INVALID_TYPE -24
/** Unable to set step */
#define GRIB_WRONG_STEP -25
/** Wrong units for step (step must be integer) */
#define GRIB_WRONG_STEP_UNIT -26
/** Invalid file id */
#define GRIB_INVALID_FILE -27
/** Invalid grib id */
#define GRIB_INVALID_GRIB -28
/** Invalid index id */
#define GRIB_INVALID_INDEX -29
/** Invalid iterator id */
#define GRIB_INVALID_ITERATOR -30
/** Invalid keys iterator id */
#define GRIB_INVALID_KEYS_ITERATOR -31
/** Invalid nearest id */
#define GRIB_INVALID_NEAREST -32
/** Invalid order by */
#define GRIB_INVALID_ORDERBY -33
/** Missing a key from the fieldset */
#define GRIB_MISSING_KEY -34
/** The point is out of the grid area */
#define GRIB_OUT_OF_AREA -35
/** Concept no match */
#define GRIB_CONCEPT_NO_MATCH -36
/** Hash array no match */
#define GRIB_HASH_ARRAY_NO_MATCH -37
/** Definitions files not found */
#define GRIB_NO_DEFINITIONS -38
/** Wrong type while packing */
#define GRIB_WRONG_TYPE -39
/** End of resource */
#define GRIB_END -40
/** Unable to code a field without values */
#define GRIB_NO_VALUES -41
/** Grid description is wrong or inconsistent */
#define GRIB_WRONG_GRID -42
/** End of index reached */
#define GRIB_END_OF_INDEX -43
/** Null index */
#define GRIB_NULL_INDEX -44
/** End of resource reached when reading message */
#define GRIB_PREMATURE_END_OF_FILE -45
/** An internal array is too small */
#define GRIB_INTERNAL_ARRAY_TOO_SMALL -46
/** Message is too large for the current architecture */
#define GRIB_MESSAGE_TOO_LARGE -47
/** Constant field */
#define GRIB_CONSTANT_FIELD -48
/** Switch unable to find a matching case */
#define GRIB_SWITCH_NO_MATCH -49
/** Underflow */
#define GRIB_UNDERFLOW -50
/** Message malformed */
#define GRIB_MESSAGE_MALFORMED -51
/** Index is corrupted */
#define GRIB_CORRUPTED_INDEX -52
/** Invalid number of bits per value */
#define GRIB_INVALID_BPV -53
/** Edition of two messages is different */
#define GRIB_DIFFERENT_EDITION -54
/** Value is different */
#define GRIB_VALUE_DIFFERENT -55
/** Invalid key value */
#define GRIB_INVALID_KEY_VALUE -56
/** String is smaller than requested */
#define GRIB_STRING_TOO_SMALL -57
/** Wrong type conversion */
#define GRIB_WRONG_CONVERSION -58
/** Missing BUFR table entry for descriptor */
#define GRIB_MISSING_BUFR_ENTRY -59
/** Null pointer */
#define GRIB_NULL_POINTER -60
/** Attribute is already present, cannot add */
#define GRIB_ATTRIBUTE_CLASH -61
/** Too many attributes. Increase MAX_ACCESSOR_ATTRIBUTES */
#define GRIB_TOO_MANY_ATTRIBUTES -62
/** Attribute not found. */
#define GRIB_ATTRIBUTE_NOT_FOUND -63
/** Edition not supported. */
#define GRIB_UNSUPPORTED_EDITION -64
/** Value out of coding range */
#define GRIB_OUT_OF_RANGE -65
/** Size of bitmap is incorrect */
#define GRIB_WRONG_BITMAP_SIZE -66
/*! @}*/
#endif

2462
python3/grib_interface.c Normal file

File diff suppressed because it is too large Load Diff

127
python3/grib_interface.h Normal file
View File

@ -0,0 +1,127 @@
#ifndef GRIB_INTERFACE_H
#define GRIB_INTERFACE_H
int grib_c_read_any_from_file(int *fid, char *buffer, int *nbytes);
int grib_c_write_file(int *fid, char *buffer, size_t *nbytes);
int grib_c_read_file(int *fid, char *buffer, size_t *nbytes);
int grib_c_open_file(int *fid, char *name, char *op);
int grib_c_close_file(int *fid);
int grib_c_multi_support_on(void);
int grib_c_multi_support_off(void);
int grib_c_iterator_new(int *gid, int *iterid, int *mode);
int grib_c_iterator_next(int *iterid, double *lat, double *lon, double *value);
int grib_c_iterator_delete(int *iterid);
int grib_c_keys_iterator_new(int *gid, int *iterid, char *name_space);
int grib_c_keys_iterator_next(int *iterid);
int grib_c_keys_iterator_get_name(int *iterid, char *name, int len);
int grib_c_keys_iterator_rewind(int *kiter);
int grib_c_keys_iterator_delete(int *iterid);
int codes_c_bufr_keys_iterator_new(int *gid, int *iterid);
int codes_c_bufr_keys_iterator_next(int *iterid);
int codes_c_bufr_keys_iterator_get_name(int *iterid, char *name, int len);
int codes_c_bufr_keys_iterator_rewind(int *kiter);
int codes_c_bufr_keys_iterator_delete(int *iterid);
int grib_c_gribex_mode_on(void);
int grib_c_gribex_mode_off(void);
int grib_c_skip_computed(int *iterid);
int grib_c_skip_coded(int *iterid);
int grib_c_skip_edition_specific(int *iterid);
int grib_c_skip_duplicates(int *iterid);
int grib_c_skip_read_only(int *iterid);
int grib_c_skip_function(int *iterid);
int grib_c_new_from_message(int *gid, void *buffer, size_t *bufsize);
int grib_c_new_from_message_copy(int *gid, void *buffer, size_t *bufsize);
int grib_c_grib_new_from_samples(int *gid, char *name);
int grib_c_bufr_new_from_samples(int *gid, char *name);
int grib_c_clone(int *gidsrc, int *giddest);
int grib_c_copy_namespace(int *gidsrc, char *name, int *giddest);
int grib_c_count_in_file(FILE *f, int *n);
int grib_c_new_from_file(FILE *f, int fd, char* fname, int *gid, int headers_only);
int grib_c_new_any_from_file(FILE *f, int headers_only,int *gid);
int grib_c_new_bufr_from_file(FILE *f, int fd, char* fname, int headers_only,int *gid);
int grib_c_new_gts_from_file(FILE *f,int headers_only, int *gid);
int grib_c_new_metar_from_file(FILE* f,int headers_only, int* gid);
int grib_c_new_from_index(int *iid, int *gid);
int grib_c_index_new_from_file(char *file, char *keys, int *gid);
int grib_c_index_add_file(int* iid, char* file);
int grib_c_index_release(int *hid);
int grib_c_multi_release(int *hid);
int grib_c_release(int *hid);
int grib_c_dump(int *gid);
int grib_c_print(int *gid, char *key);
int grib_c_get_error_string(int *err, char *buf, int len);
int grib_c_get_size_int(int *gid, char *key, int *val);
int grib_c_get_size_long(int *gid, char *key, long *val);
int grib_c_index_get_size_int(int *gid, char *key, int *val);
int grib_c_index_get_size_long(int *gid, char *key, long *val);
int grib_c_get_int(int *gid, char *key, int *val);
int grib_c_get_long(int *gid, char *key, long *val);
int grib_c_get_double(int *gid, char *key, double *val);
int grib_c_get_int_array(int *gid, char *key, int *val, size_t *size);
int grib_c_get_long_array(int *gid, char *key, long *val, int *size);
int grib_c_index_get_string(int *gid, char *key, char *val, int *eachsize, int *size);
int grib_c_index_get_long(int *gid, char *key, long *val, int *size);
int grib_c_index_get_int(int *gid, char *key, int *val, int *size);
int grib_c_index_get_real8(int *gid, char *key, double *val, int *size);
int grib_c_set_int_array(int *gid, char *key, int *val, size_t *size);
int grib_c_set_long_array(int *gid, char *key, long *val, int *size);
int grib_c_set_int(int *gid, char *key, int *val);
int grib_c_set_long(int *gid, char *key, long *val);
int grib_c_set_missing(int *gid, char *key);
int grib_c_set_key_vals(int* gid, char* keyvals);
int grib_c_is_missing(int *gid, char *key, int *isMissing);
int grib_c_is_defined(int *gid, char *key, int *isDefined);
int grib_c_set_real4(int *gid, char *key, float *val);
int grib_c_get_real4_element(int *gid, char *key, int *index, float *val);
int grib_c_get_real4_elements(int *gid, char *key, int *index, float *val, int *size);
int grib_c_get_real4(int *gid, char *key, float *val);
int grib_c_get_real4_array(int *gid, char *key, float *val, size_t *size);
int grib_c_set_real4_array(int *gid, char *key, float *val, int *size);
int grib_c_index_select_real8(int *gid, char *key, double *val);
int grib_c_index_select_string(int *gid, char *key, char *val);
int grib_c_index_select_int(int *gid, char *key, int *val);
int grib_c_index_select_long(int *gid, char *key, long *val);
int grib_c_set_real8(int *gid, char *key, double *val);
int grib_c_get_real8(int *gid, char *key, double *val);
int grib_c_get_real8_element(int *gid, char *key, int *index, double *val);
int grib_c_get_real8_elements(int *gid, char *key, int *index, double *val, int *size);
int grib_c_find_nearest_four_single(int *gid, int *is_lsm, double *inlat, double *inlon, double *outlats, double *outlons, double *values, double *distances, int *indexes);
int grib_c_find_nearest_single(int *gid, int *is_lsm, double *inlats, double *inlons, double *outlats, double *outlons, double *values, double *distances, int *indexes);
int grib_c_find_nearest_multiple(int *gid, int *is_lsm, double *inlats, double *inlons, double *outlats, double *outlons, double *values, double *distances, int *indexes, int *npoints);
int grib_c_get_real8_array(int *gid, char *key, double *val, int *size);
int grib_c_set_real8_array(int *gid, char *key, double *val, int *size);
int grib_c_get_string(int *gid, char *key, char *val, size_t *lsize);
int grib_c_get_string_array(int* gid, char* key, char** val, size_t *lsize);
int grib_c_set_string(int *gid, char *key, char *val, int len2);
int grib_c_set_string_array(int *gid, char *key, const char **val);
int grib_c_get_data_real4(int *gid, float *lats, float *lons, float *values, size_t *size);
/*int grib_c_get_data_real8(int *gid, double *lats, double *lons, double *values, size_t *size);*/
int grib_c_get_message_size(int *gid, size_t *len);
int grib_c_get_message_offset(int *gid, size_t *len);
int grib_c_copy_message(int *gid, void *mess, size_t *len);
int grib_c_bufr_copy_data(int *msgid_src, int *msgid_dst);
void grib_c_check(int *err, char *call, char *str);
int grib_c_write(int *gid, FILE *f);
int grib_c_multi_new(int* mgid);
int grib_c_multi_write(int *gid, FILE *f);
int grib_c_multi_append(int *ingid, int *sec, int *mgid);
int grib_c_set_double_array(int* gid, char* key, double*val, int* size);
int grib_c_set_double(int* gid, char* key, double*val);
int grib_c_get_native_type(int* gid, char* key, int* type);
int grib_c_index_write(int* gid, char* file);
int grib_c_index_read(char* file, int* gid);
void no_fail_on_wrong_length(int flag);
long grib_c_get_api_version(void);
void grib_c_gts_header_on(void);
void grib_c_gts_header_off(void);
int grib_c_get_message(int *gid, const void **msg, size_t *size);
int grib_c_get_string_length(int* gid, char* key, size_t* val);
void grib_c_set_definitions_path(const char* path);
void grib_c_set_samples_path(const char* path);
#endif

196
python3/gribapi.c Normal file
View File

@ -0,0 +1,196 @@
/*
* Copyright 2005-2018 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 "Python.h"
#include "grib_api.h"
static PyObject* Error;
PyDoc_STRVAR(gribapi__doc__,
"gribapi point evalutation kernel");
PyDoc_STRVAR(read__doc__,
"gribapi point evalutation kernel");
static PyObject *
py_new_handle_from_file(PyObject *self, PyObject *args)
{
/* TODO: Call PyFile_Check or PyFile_CheckExact */
int err = 0;
grib_handle *h;
PyObject *file;
if(!PyArg_ParseTuple(args,"O",&file))
return NULL;
h = grib_handle_new_from_file(NULL,PyFile_AsFile(file),&err);
if(err) {
/* http://www.ragestorm.net/tutorial?id=21 */
PyErr_Format(Error,"grib_api: %s",grib_get_error_message(err));
return NULL;
}
/* TODO: Do an OO version */
if(h)
return PyLong_FromVoidPtr(h);
Py_RETURN_NONE;
}
static PyObject *
py_handle_delete(PyObject *self, PyObject *args)
{
PyObject* h;
if(!PyArg_ParseTuple(args,"O",&h))
return NULL;
grib_handle_delete(PyLong_AsVoidPtr(h));
Py_INCREF(Py_None);
return Py_None;
}
static PyObject *
py_keys_iterator_delete(PyObject *self, PyObject *args)
{
PyObject* h;
if(!PyArg_ParseTuple(args,"O",&h))
return NULL;
grib_keys_iterator_delete(PyLong_AsVoidPtr(h));
Py_INCREF(Py_None);
return Py_None;
}
static PyObject *
py_get_string(PyObject *self, PyObject *args)
{
PyObject* h;
char *s;
size_t size;
char tmp[1024];
int err;
if(!PyArg_ParseTuple(args,"Os",&h,&s))
return NULL;
size = sizeof(tmp);
err = grib_get_string(PyLong_AsVoidPtr(h),s,tmp,&size);
if(err) {
/* http://www.ragestorm.net/tutorial?id=21 */
PyErr_Format(Error,"grib_api: %s %s",s,grib_get_error_message(err));
return NULL;
}
return PyString_InternFromString(tmp);
}
static PyObject *
py_keys_iterator_next(PyObject *self, PyObject *args)
{
PyObject* h;
int more;
if(!PyArg_ParseTuple(args,"O",&h))
return NULL;
more = grib_keys_iterator_next(PyLong_AsVoidPtr(h));
if(more)
{
Py_RETURN_TRUE;
}
else
{
Py_RETURN_FALSE;
}
}
static PyObject *
py_keys_iterator_get_string(PyObject *self, PyObject *args)
{
PyObject* h;
size_t size;
char tmp[1024];
int err;
if(!PyArg_ParseTuple(args,"O",&h))
return NULL;
size = sizeof(tmp);
err = grib_keys_iterator_get_string(PyLong_AsVoidPtr(h),tmp,&size);
if(err) {
/* http://www.ragestorm.net/tutorial?id=21 */
PyErr_Format(Error,"grib_api: %s",grib_get_error_message(err));
return NULL;
}
return PyString_InternFromString(tmp);
}
static PyObject *
py_keys_iterator_get_name(PyObject *self, PyObject *args)
{
PyObject* h;
if(!PyArg_ParseTuple(args,"O",&h))
return NULL;
return PyString_InternFromString(grib_keys_iterator_get_name(PyLong_AsVoidPtr(h)));
}
static PyObject *
py_keys_iterator_new(PyObject *self, PyObject *args)
{
PyObject* h;
char *s;
if(!PyArg_ParseTuple(args,"Os",&h,&s))
return NULL;
return PyLong_FromVoidPtr(grib_keys_iterator_new(PyLong_AsVoidPtr(h),GRIB_KEYS_ITERATOR_ALL_KEYS,s));
}
static PyMethodDef gribapi_methods[] = {
{"new_handle_from_file", py_new_handle_from_file, METH_VARARGS, read__doc__},
{"get_string", py_get_string, METH_VARARGS, read__doc__},
{"keys_iterator_new", py_keys_iterator_new, METH_VARARGS, read__doc__},
{"keys_iterator_delete", py_keys_iterator_delete, METH_VARARGS, read__doc__},
{"handle_delete", py_handle_delete, METH_VARARGS, read__doc__},
{"keys_iterator_get_string", py_keys_iterator_get_string, METH_VARARGS, read__doc__},
{"keys_iterator_get_name", py_keys_iterator_get_name, METH_VARARGS, read__doc__},
{"keys_iterator_next", py_keys_iterator_next, METH_VARARGS, read__doc__},
{NULL, NULL} /* sentinel */
};
PyMODINIT_FUNC
initgribapi(void)
{
PyObject* m;
/* There have been several InitModule functions over time */
m = Py_InitModule3("gribapi", gribapi_methods, gribapi__doc__);
/* TODO: Create our own exception */
Error = PyErr_NewException("grib.apierror",NULL,NULL);
Py_INCREF(Error);
PyModule_AddObject(m, "error", Error);
}

View File

@ -0,0 +1,2 @@
from .gribapi import * # noqa
from .gribapi import __version__

235
python3/gribapi/errors.py Normal file
View File

@ -0,0 +1,235 @@
"""
Exception class hierarchy
"""
from . import gribapi_swig as _internal
class GribInternalError(Exception):
"""
@brief Wrap errors coming from the C API in a Python exception object.
Base class for all exceptions
"""
def __init__(self, value):
# Call the base class constructor with the parameters it needs
Exception.__init__(self, value)
if type(value) is int:
err, self.msg = _internal.grib_c_get_error_string(value, 1024)
assert err == 0
else:
self.msg = value
def __str__(self):
return self.msg
class WrongBitmapSizeError(GribInternalError):
"""Size of bitmap is incorrect."""
class OutOfRangeError(GribInternalError):
"""Value out of coding range."""
class UnsupportedEditionError(GribInternalError):
"""Edition not supported.."""
class AttributeNotFoundError(GribInternalError):
"""Attribute not found.."""
class TooManyAttributesError(GribInternalError):
"""Too many attributes. Increase MAX_ACCESSOR_ATTRIBUTES."""
class AttributeClashError(GribInternalError):
"""Attribute is already present, cannot add."""
class NullPointerError(GribInternalError):
"""Null pointer."""
class MissingBufrEntryError(GribInternalError):
"""Missing BUFR table entry for descriptor."""
class WrongConversionError(GribInternalError):
"""Wrong type conversion."""
class StringTooSmallError(GribInternalError):
"""String is smaller than requested."""
class InvalidKeyValueError(GribInternalError):
"""Invalid key value."""
class ValueDifferentError(GribInternalError):
"""Value is different."""
class DifferentEditionError(GribInternalError):
"""Edition of two messages is different."""
class InvalidBitsPerValueError(GribInternalError):
"""Invalid number of bits per value."""
class CorruptedIndexError(GribInternalError):
"""Index is corrupted."""
class MessageMalformedError(GribInternalError):
"""Message malformed."""
class UnderflowError(GribInternalError):
"""Underflow."""
class SwitchNoMatchError(GribInternalError):
"""Switch unable to find a matching case."""
class ConstantFieldError(GribInternalError):
"""Constant field."""
class MessageTooLargeError(GribInternalError):
"""Message is too large for the current architecture."""
class InternalArrayTooSmallError(GribInternalError):
"""An internal array is too small."""
class PrematureEndOfFileError(GribInternalError):
"""End of resource reached when reading message."""
class NullIndexError(GribInternalError):
"""Null index."""
class EndOfIndexError(GribInternalError):
"""End of index reached."""
class WrongGridError(GribInternalError):
"""Grid description is wrong or inconsistent."""
class NoValuesError(GribInternalError):
"""Unable to code a field without values."""
class EndError(GribInternalError):
"""End of resource."""
class WrongTypeError(GribInternalError):
"""Wrong type while packing."""
class NoDefinitionsError(GribInternalError):
"""Definitions files not found."""
class HashArrayNoMatchError(GribInternalError):
"""Hash array no match."""
class ConceptNoMatchError(GribInternalError):
"""Concept no match."""
class OutOfAreaError(GribInternalError):
"""The point is out of the grid area."""
class MissingKeyError(GribInternalError):
"""Missing a key from the fieldset."""
class InvalidOrderByError(GribInternalError):
"""Invalid order by."""
class InvalidNearestError(GribInternalError):
"""Invalid nearest id."""
class InvalidKeysIteratorError(GribInternalError):
"""Invalid keys iterator id."""
class InvalidIteratorError(GribInternalError):
"""Invalid iterator id."""
class InvalidIndexError(GribInternalError):
"""Invalid index id."""
class InvalidGribError(GribInternalError):
"""Invalid grib id."""
class InvalidFileError(GribInternalError):
"""Invalid file id."""
class WrongStepUnitError(GribInternalError):
"""Wrong units for step (step must be integer)."""
class WrongStepError(GribInternalError):
"""Unable to set step."""
class InvalidTypeError(GribInternalError):
"""Invalid key type."""
class WrongLengthError(GribInternalError):
"""Wrong message length."""
class ValueCannotBeMissingError(GribInternalError):
"""Value cannot be missing."""
class InvalidSectionNumberError(GribInternalError):
"""Invalid section number."""
class NullHandleError(GribInternalError):
"""Null handle."""
class InvalidArgumentError(GribInternalError):
"""Invalid argument."""
class ReadOnlyError(GribInternalError):
"""Value is read only."""
class MemoryAllocationError(GribInternalError):
"""Memory allocation error."""
class GeocalculusError(GribInternalError):
"""Problem with calculation of geographic attributes."""
class NoMoreInSetError(GribInternalError):
"""Code cannot unpack because of string too small."""
class EncodingError(GribInternalError):
"""Encoding invalid."""
class DecodingError(GribInternalError):
"""Decoding invalid."""
class MessageInvalidError(GribInternalError):
"""Message invalid."""
class IOProblemError(GribInternalError):
"""Input output problem."""
class KeyValueNotFoundError(GribInternalError):
"""Key/value not found."""
class WrongArraySizeError(GribInternalError):
"""Array size mismatch."""
class CodeNotFoundInTableError(GribInternalError):
"""Code not found in code table."""
class FileNotFoundError(GribInternalError):
"""File not found."""
class ArrayTooSmallError(GribInternalError):
"""Passed array is too small."""
class MessageEndNotFoundError(GribInternalError):
"""Missing 7777 at end of message."""
class FunctionNotImplementedError(GribInternalError):
"""Function not yet implemented."""
class BufferTooSmallError(GribInternalError):
"""Passed buffer is too small."""
class InternalError(GribInternalError):
"""Internal error."""
class EndOfFileError(GribInternalError):
"""End of resource reached."""
ERROR_MAP = {
-66 : WrongBitmapSizeError,
-65 : OutOfRangeError,
-64 : UnsupportedEditionError,
-63 : AttributeNotFoundError,
-62 : TooManyAttributesError,
-61 : AttributeClashError,
-60 : NullPointerError,
-59 : MissingBufrEntryError,
-58 : WrongConversionError,
-57 : StringTooSmallError,
-56 : InvalidKeyValueError,
-55 : ValueDifferentError,
-54 : DifferentEditionError,
-53 : InvalidBitsPerValueError,
-52 : CorruptedIndexError,
-51 : MessageMalformedError,
-50 : UnderflowError,
-49 : SwitchNoMatchError,
-48 : ConstantFieldError,
-47 : MessageTooLargeError,
-46 : InternalArrayTooSmallError,
-45 : PrematureEndOfFileError,
-44 : NullIndexError,
-43 : EndOfIndexError,
-42 : WrongGridError,
-41 : NoValuesError,
-40 : EndError,
-39 : WrongTypeError,
-38 : NoDefinitionsError,
-37 : HashArrayNoMatchError,
-36 : ConceptNoMatchError,
-35 : OutOfAreaError,
-34 : MissingKeyError,
-33 : InvalidOrderByError,
-32 : InvalidNearestError,
-31 : InvalidKeysIteratorError,
-30 : InvalidIteratorError,
-29 : InvalidIndexError,
-28 : InvalidGribError,
-27 : InvalidFileError,
-26 : WrongStepUnitError,
-25 : WrongStepError,
-24 : InvalidTypeError,
-23 : WrongLengthError,
-22 : ValueCannotBeMissingError,
-21 : InvalidSectionNumberError,
-20 : NullHandleError,
-19 : InvalidArgumentError,
-18 : ReadOnlyError,
-17 : MemoryAllocationError,
-16 : GeocalculusError,
-15 : NoMoreInSetError,
-14 : EncodingError,
-13 : DecodingError,
-12 : MessageInvalidError,
-11 : IOProblemError,
-10 : KeyValueNotFoundError,
-9 : WrongArraySizeError,
-8 : CodeNotFoundInTableError,
-7 : FileNotFoundError,
-6 : ArrayTooSmallError,
-5 : MessageEndNotFoundError,
-4 : FunctionNotImplementedError,
-3 : BufferTooSmallError,
-2 : InternalError,
-1 : EndOfFileError
}
def raise_grib_error(errid):
"""
Raise the GribInternalError corresponding to ``errid``.
"""
raise ERROR_MAP[errid](errid)

1963
python3/gribapi/gribapi.py Normal file

File diff suppressed because it is too large Load Diff

265
python3/gribapi_swig.i Normal file
View File

@ -0,0 +1,265 @@
%module gribapi_swig
%include "cpointer.i"
%include "cstring.i"
%include "typemaps.i"
%include "cdata.i"
%include "carrays.i"
%include "grib_errors.h"
%{
#define SWIG_FILE_WITH_INIT
#include "grib_interface.h"
%}
%include "numpy.i"
%init %{
import_array();
%}
/* Converts a PyFile instance to a stdio FILE* for reading binary files */
%typemap(in) FILE* {
int fileDescriptor = PyObject_AsFileDescriptor($input);
/*printf("swig.i fileDescriptor=%d\n", fileDescriptor);*/
if(fileDescriptor >= 0) {
/* Convert file descriptor to a FILE pointer */
$1 = fdopen(fileDescriptor,"rb"); // needs to be rb+ (or wb) for write
}
else {
PyErr_SetString(PyExc_TypeError, "$1_name must be a file type.");
return NULL;
}
}
%pointer_class(int, intp);
%pointer_class(size_t, sizetp);
%pointer_class(long, longp);
%pointer_class(double, doublep);
%array_functions(double, doubleArray);
%array_functions(long, longArray);
%array_functions(int, intArray);
%array_functions(char*, stringArray);
// creation
int grib_c_new_from_file(FILE* f, int fd, char* fname, int* INOUT, int headers_only);
int grib_c_new_any_from_file(FILE* f, int headers_only, int* INOUT);
int grib_c_new_bufr_from_file(FILE* f, int fd, char* fname, int headers_only, int* INOUT);
int grib_c_new_gts_from_file(FILE* f, int headers_only, int* INOUT);
int grib_c_new_metar_from_file(FILE* f, int headers_only, int* INOUT);
int grib_c_iterator_new(int* INPUT, int* OUTPUT, int* INPUT);
int grib_c_keys_iterator_new(int* INPUT, int* OUTPUT, char* name_space);
int codes_c_bufr_keys_iterator_new(int* INPUT, int* OUTPUT);
int grib_c_grib_new_from_samples(int* INOUT, char* name);
int grib_c_bufr_new_from_samples(int* INOUT, char* name);
int grib_c_index_new_from_file(char* file, char* keys, int* OUTPUT);
int grib_c_index_add_file(int* INPUT, char* file);
int grib_c_new_from_index(int *INPUT, int *INOUT);
int grib_c_index_write(int* INPUT, char* file);
int grib_c_index_read(char* file, int* OUTPUT);
int grib_c_new_from_message(int *INOUT, char *binmsg, size_t *INPUT);
// ---
%apply int* INPUT { int* fid };
%apply int* INPUT { int* gid };
%apply int* INPUT { int* iterid };
%apply int* INPUT { int* iid };
// file operations
int grib_c_count_in_file(FILE* f,int* OUTPUT);
// ---
/* Converts a PyFile instance to a stdio FILE* for writing binary files */
%typemap(in) FILE* {
int fileDescriptor = PyObject_AsFileDescriptor($input);
if(fileDescriptor >= 0) {
/* Convert file descriptor to a FILE pointer */
$1 = fdopen(fileDescriptor,"wb");
}
else {
PyErr_SetString(PyExc_TypeError, "$1_name must be a file type.");
return NULL;
}
}
// grib handle operations
int grib_c_release(int* gid);
int grib_c_write(int* gid, FILE* f);
int grib_c_get_size_long(int* gid, char* key, long* OUTPUT);
int grib_c_get_string_length(int* gid, char* key, size_t* OUTPUT);
int grib_c_clone(int* gid,int* INOUT);
int grib_c_copy_namespace(int* gid, char* name, int* INPUT);
int grib_c_get_message_size(int* gid, size_t* OUTPUT);
int grib_c_get_message_offset(int* gid, size_t* OUTPUT);
int grib_c_get_native_type(int* gid, char* key, int* OUTPUT);
// ---
// multi support
int grib_c_multi_new(int* OUTPUT);
int grib_c_multi_support_on(void);
int grib_c_multi_write(int* gid, FILE* f);
int grib_c_multi_support_off(void);
int grib_c_multi_release(int* gid);
int grib_c_multi_append(int* INPUT, int* INPUT,int* INPUT);
// ---
// gribex support
int grib_c_gribex_mode_on(void);
int grib_c_gribex_mode_off(void);
// ---
// keys iterator
int grib_c_keys_iterator_next(int* iterid);
int codes_c_bufr_keys_iterator_next(int* iterid);
int grib_c_keys_iterator_delete(int* iterid);
int codes_c_bufr_keys_iterator_delete(int* iterid);
int grib_c_skip_computed(int* iterid);
int grib_c_skip_coded(int* iterid);
int grib_c_skip_edition_specific(int* iterid);
int grib_c_skip_duplicates(int* iterid);
int grib_c_skip_read_only(int* iterid);
int grib_c_skip_function(int* iterid);
int grib_c_keys_iterator_rewind(int* iterid);
int codes_c_bufr_keys_iterator_rewind(int* iterid);
int grib_c_bufr_copy_data(int* gid, int* INOUT);
%cstring_bounded_output(char* name, 1024);
int grib_c_keys_iterator_get_name(int* iterid, char* name, int len);
int codes_c_bufr_keys_iterator_get_name(int* iterid, char* name, int len);
// ---
// indexing routines
int grib_c_index_get_size_long(int* iid, char* key, long* OUTPUT);
int grib_c_index_get_long(int* iid, char* key, long* val, int* size);
int grib_c_index_get_real8(int* iid, char* key, double* val, int* size);
%cstring_bounded_output(char* index_string_output, 1024*1024);
int grib_c_index_get_string(int* iid, char* key, char* index_string_output, int* INPUT, int* INOUT);
int grib_c_index_select_long(int *iid, char *key, long *INPUT);
int grib_c_index_select_real8(int *iid, char *key, double *INPUT);
int grib_c_index_select_string(int *iid, char *key, char *val);
int grib_c_index_release(int* iid);
// ---
// values iterator
int grib_c_iterator_delete(int* iterid);
int grib_c_iterator_next(int* iterid, double* OUTPUT, double* OUTPUT, double* OUTPUT);
// ---
// getting/setting key values
%cstring_output_withsize(char* string_val, size_t* string_size)
int grib_c_get_string(int* gid, char* key, char* string_val, size_t* string_size);
int grib_c_get_string_array(int* gid, char* key, char** array_string_val, size_t* size);
int grib_c_set_string(int* gid, char* key, char* sval, int len2);
int grib_c_get_long(int* gid, char* key, long* OUTPUT);
int grib_c_set_long(int* gid, char* key, long* INPUT);
int grib_c_get_double(int* gid, char* key, double* OUTPUT);
int grib_c_set_double(int* gid, char* key, double* INPUT);
int grib_c_set_real8_array(int* gid, char* key, double* val, int* size);
int grib_c_get_real8_array(int* gid, char* key, double* val, int* size);
int grib_c_get_long_array(int* gid, char* key, long* val, int* size);
int grib_c_set_long_array(int* gid, char* key, long* val, int* size);
int grib_c_get_real8_element(int* gid, char* key, int* INPUT, double* OUTPUT);
int grib_c_get_real8_elements(int* gid, char* key, int* index, double* val, int* size);
int grib_c_set_missing(int* gid, char* key);
int grib_c_set_key_vals(int* gid, char* keyvals);
int grib_c_is_missing(int* gid, char* key, int* OUTPUT);
int grib_c_is_defined(int* gid, char* key, int* OUTPUT);
// http://www.swig.org/Doc1.3/Python.html
// This tells SWIG to treat char ** as a special case
%typemap(in) char ** {
/* Check if is a list */
if (PyList_Check($input)) {
int size = PyList_Size($input);
int i = 0;
$1 = (char **) malloc((size+1)*sizeof(char *));
for (i = 0; i < size; i++) {
PyObject *o = PyList_GetItem($input,i);
if (PyString_Check(o))
$1[i] = PyString_AsString(PyList_GetItem($input,i));
else {
PyErr_SetString(PyExc_TypeError,"list must contain strings");
free($1);
return NULL;
}
}
$1[i] = 0; /* Last entry set to NULL */
} else {
PyErr_SetString(PyExc_TypeError,"not a list");
return NULL;
}
}
// This cleans up the char ** array we malloc'd before the function call
%typemap(freearg) char ** {
free((char *) $1);
}
int grib_c_set_string_array(int *gid, char *key, const char** val);
// Numpy Support
%apply (double* IN_ARRAY1, int DIM1) {(double* dpin_val, int dpin_val_dim1)};
%apply (long* IN_ARRAY1, int DIM1) {(long* lpin_val, int lpin_val_dim1)};
%apply (int* IN_ARRAY1, int DIM1) {(int* ipin_index, int ipin_index_dim1)};
%apply (double* ARGOUT_ARRAY1, int DIM1) {(double* dpout_val, int dpout_val_dim1)};
%apply (long* ARGOUT_ARRAY1, int DIM1) {(long* lpout_val, int lpout_val_dim1)};
%inline %{
//void with_numpy() {
// return;
//}
int grib_set_double_ndarray(int* gid, char* key, double* dpin_val, int dpin_val_dim1) {
return grib_c_set_real8_array(gid,key,dpin_val,&dpin_val_dim1);
}
int grib_set_long_ndarray(int* gid, char* key, long* lpin_val, int lpin_val_dim1) {
return grib_c_set_long_array(gid,key,lpin_val,&lpin_val_dim1);
}
int grib_get_double_ndarray(int* gid, char* key, double* dpout_val, int dpout_val_dim1) {
return grib_c_get_real8_array(gid,key,dpout_val,&dpout_val_dim1);
}
int grib_get_long_ndarray(int* gid, char* key, long* lpout_val, int lpout_val_dim1) {
return grib_c_get_long_array(gid,key,lpout_val,&lpout_val_dim1);
}
int grib_get_double_ndelements(int* gid, char* key, int* ipin_index, int ipin_index_dim1, double* dpout_val, int dpout_val_dim1) {
return grib_c_get_real8_elements(gid,key,ipin_index,dpout_val,&dpout_val_dim1);
}
%}
%clear double* dpin_val, int dpin_val_dim1;
%clear long* lpin_val, int lpin_val_dim1;
%clear int* ipout_val, int ipout_val_dim1;
%clear double* dpout_val, int dpout_val_dim1;
%clear long* lpout_val, int lpout_val_dim1;
// ---
// nearest
int grib_c_find_nearest_single(int* gid, int* INPUT, double* INPUT, double* INPUT, double* OUTPUT, double* OUTPUT, double* OUTPUT, double* OUTPUT, int* OUTPUT);
int grib_c_find_nearest_four_single(int* gid, int* INPUT, double* INPUT, double* INPUT, double* outlats, double* outlons, double* values, double* distances, int* indexes);
// ---
/*
* Get the binary string message for a grib.
*
* Set the 3rd argument to nothing in 'cstring_output_allocate_size'.
* This is kind of difficult to explain, but, *msg will point directly to
* the binary message data of the current grib (which is stored in
* handle->buffer->data if I remember correctly) so freeing it will cause
* the binary message data in the grib_handle structure to be freed. This
* is a problem as grib_api does not know that, so it tries to free it
* itself (grib_release does that) resulting in a 'Segmentation fault'.
*/
%cstring_output_allocate_size(const void **binmsg, size_t *binmsglen,);
int grib_c_get_message(int *gid, const void **binmsg, size_t *binmsglen);
%clear const void **binmsg, size_t *binmsglen;
%clear int* fid;
%clear int* gid;
%clear int* iterid;
%cstring_bounded_output(char* error_message, 1024);
int grib_c_get_error_string(int* INPUT, char* error_message, int len);
void no_fail_on_wrong_length(int flag);
long grib_c_get_api_version();
void grib_c_gts_header_on();
void grib_c_gts_header_off();
void grib_c_set_definitions_path(const char* path);
void grib_c_set_samples_path(const char* path);

3183
python3/numpy.i Normal file

File diff suppressed because it is too large Load Diff

8
python3/run_tests.sh Executable file
View File

@ -0,0 +1,8 @@
#!/bin/sh
input=$1
./test_general.py $input
./test_index.py $input
./test_keysiterator.py $input
./test_iterator.py $input

77
python3/setup.py.in Normal file
View File

@ -0,0 +1,77 @@
#!/usr/bin/env python
from distutils.core import setup, Extension
import os
import sys
import numpy
# Obtain the numpy include directory. This logic works across numpy versions.
try:
numpy_include = numpy.get_include()
except AttributeError:
numpy_include = numpy.get_numpy_include()
# See ECC-644
extra_compile_args = []
cmake_c_compiler_id='@CMAKE_C_COMPILER_ID@'
if cmake_c_compiler_id == 'PGI':
extra_compile_args.append('-noswitcherror')
attdict = dict(sources=['@CMAKE_CURRENT_SOURCE_DIR@/swig_wrap_numpy.c',
'@CMAKE_CURRENT_SOURCE_DIR@/grib_interface.c'],
swig_opts=[],
include_dirs=['.', '@CMAKE_CURRENT_BINARY_DIR@/../src',
'@CMAKE_CURRENT_SOURCE_DIR@/../src',
numpy_include],
library_dirs=['@CMAKE_BINARY_DIR@/lib'],
runtime_library_dirs=[],
libraries=['eccodes'],
extra_compile_args=extra_compile_args,
extra_objects=[])
shared_libs='@BUILD_SHARED_LIBS@'
if shared_libs == 'OFF':
add_attribute = lambda **args: [list.append(attdict[key], value)
for key, value in args.items()]
if @HAVE_LIBJASPER@:
jasper_dir = '@JASPER_DIR@'
if jasper_dir and jasper_dir != 'system':
add_attribute(library_dirs=os.path.join(jasper_dir, 'lib'),
runtime_library_dirs=os.path.join(jasper_dir, 'lib'))
add_attribute(libraries='jasper')
if @HAVE_LIBOPENJPEG@:
openjpeg_lib_dir = '@OPENJPEG_LIB_DIR@'
openjpeg_libname = '@OJ_WITHOUT_LIB@'
if openjpeg_lib_dir:
add_attribute(library_dirs=openjpeg_lib_dir,
runtime_library_dirs=openjpeg_lib_dir)
add_attribute(libraries=openjpeg_libname)
# assumes png is supplied by system paths -- may not be true
if @HAVE_LIBPNG@:
add_attribute(libraries='png')
if @HAVE_MEMFS@:
add_attribute(libraries='eccodes_memfs')
if @HAVE_AEC@:
aec_dir = '@AEC_DIR@'
if aec_dir and aec_dir != 'system':
add_attribute(library_dirs=os.path.join(aec_dir, 'lib'),
runtime_library_dirs=os.path.join(aec_dir, 'lib'))
add_attribute(libraries='aec')
setup(name='eccodes',
version='@ECCODES_VERSION_STR@',
author='ECMWF',
author_email='Software.Support@ecmwf.int',
description="""Python interface for ecCodes""",
license='Apache License, Version 2.0',
url='https://software.ecmwf.int/wiki/display/ECC/ecCodes+Home',
download_url='https://software.ecmwf.int/wiki/display/ECC/Releases',
ext_modules=[Extension('gribapi._gribapi_swig', **attdict)],
packages=['eccodes', 'eccodes.high_level', 'gribapi'])

10558
python3/swig_wrap_numpy.c Normal file

File diff suppressed because it is too large Load Diff

747
python3/swig_wrap_numpy.py Normal file
View File

@ -0,0 +1,747 @@
# This file was automatically generated by SWIG (http://www.swig.org).
# Version 3.0.12
#
# Do not make changes to this file unless you know what you are doing--modify
# the SWIG interface file instead.
from sys import version_info as _swig_python_version_info
if _swig_python_version_info >= (2, 7, 0):
def swig_import_helper():
import importlib
pkg = __name__.rpartition('.')[0]
mname = '.'.join((pkg, '_gribapi_swig')).lstrip('.')
try:
return importlib.import_module(mname)
except ImportError:
return importlib.import_module('_gribapi_swig')
_gribapi_swig = swig_import_helper()
del swig_import_helper
elif _swig_python_version_info >= (2, 6, 0):
def swig_import_helper():
from os.path import dirname
import imp
fp = None
try:
fp, pathname, description = imp.find_module('_gribapi_swig', [dirname(__file__)])
except ImportError:
import _gribapi_swig
return _gribapi_swig
try:
_mod = imp.load_module('_gribapi_swig', fp, pathname, description)
finally:
if fp is not None:
fp.close()
return _mod
_gribapi_swig = swig_import_helper()
del swig_import_helper
else:
import _gribapi_swig
del _swig_python_version_info
try:
_swig_property = property
except NameError:
pass # Python < 2.2 doesn't have 'property'.
try:
import builtins as __builtin__
except ImportError:
import __builtin__
def _swig_setattr_nondynamic(self, class_type, name, value, static=1):
if (name == "thisown"):
return self.this.own(value)
if (name == "this"):
if type(value).__name__ == 'SwigPyObject':
self.__dict__[name] = value
return
method = class_type.__swig_setmethods__.get(name, None)
if method:
return method(self, value)
if (not static):
if _newclass:
object.__setattr__(self, name, value)
else:
self.__dict__[name] = value
else:
raise AttributeError("You cannot add attributes to %s" % self)
def _swig_setattr(self, class_type, name, value):
return _swig_setattr_nondynamic(self, class_type, name, value, 0)
def _swig_getattr(self, class_type, name):
if (name == "thisown"):
return self.this.own()
method = class_type.__swig_getmethods__.get(name, None)
if method:
return method(self)
raise AttributeError("'%s' object has no attribute '%s'" % (class_type.__name__, name))
def _swig_repr(self):
try:
strthis = "proxy of " + self.this.__repr__()
except __builtin__.Exception:
strthis = ""
return "<%s.%s; %s >" % (self.__class__.__module__, self.__class__.__name__, strthis,)
try:
_object = object
_newclass = 1
except __builtin__.Exception:
class _object:
pass
_newclass = 0
def cdata(ptr: 'void *', nelements: 'size_t'=1) -> "SWIGCDATA":
return _gribapi_swig.cdata(ptr, nelements)
cdata = _gribapi_swig.cdata
def memmove(data: 'void *', indata: 'void const *') -> "void":
return _gribapi_swig.memmove(data, indata)
memmove = _gribapi_swig.memmove
GRIB_SUCCESS = _gribapi_swig.GRIB_SUCCESS
GRIB_END_OF_FILE = _gribapi_swig.GRIB_END_OF_FILE
GRIB_INTERNAL_ERROR = _gribapi_swig.GRIB_INTERNAL_ERROR
GRIB_BUFFER_TOO_SMALL = _gribapi_swig.GRIB_BUFFER_TOO_SMALL
GRIB_NOT_IMPLEMENTED = _gribapi_swig.GRIB_NOT_IMPLEMENTED
GRIB_7777_NOT_FOUND = _gribapi_swig.GRIB_7777_NOT_FOUND
GRIB_ARRAY_TOO_SMALL = _gribapi_swig.GRIB_ARRAY_TOO_SMALL
GRIB_FILE_NOT_FOUND = _gribapi_swig.GRIB_FILE_NOT_FOUND
GRIB_CODE_NOT_FOUND_IN_TABLE = _gribapi_swig.GRIB_CODE_NOT_FOUND_IN_TABLE
GRIB_WRONG_ARRAY_SIZE = _gribapi_swig.GRIB_WRONG_ARRAY_SIZE
GRIB_NOT_FOUND = _gribapi_swig.GRIB_NOT_FOUND
GRIB_IO_PROBLEM = _gribapi_swig.GRIB_IO_PROBLEM
GRIB_INVALID_MESSAGE = _gribapi_swig.GRIB_INVALID_MESSAGE
GRIB_DECODING_ERROR = _gribapi_swig.GRIB_DECODING_ERROR
GRIB_ENCODING_ERROR = _gribapi_swig.GRIB_ENCODING_ERROR
GRIB_NO_MORE_IN_SET = _gribapi_swig.GRIB_NO_MORE_IN_SET
GRIB_GEOCALCULUS_PROBLEM = _gribapi_swig.GRIB_GEOCALCULUS_PROBLEM
GRIB_OUT_OF_MEMORY = _gribapi_swig.GRIB_OUT_OF_MEMORY
GRIB_READ_ONLY = _gribapi_swig.GRIB_READ_ONLY
GRIB_INVALID_ARGUMENT = _gribapi_swig.GRIB_INVALID_ARGUMENT
GRIB_NULL_HANDLE = _gribapi_swig.GRIB_NULL_HANDLE
GRIB_INVALID_SECTION_NUMBER = _gribapi_swig.GRIB_INVALID_SECTION_NUMBER
GRIB_VALUE_CANNOT_BE_MISSING = _gribapi_swig.GRIB_VALUE_CANNOT_BE_MISSING
GRIB_WRONG_LENGTH = _gribapi_swig.GRIB_WRONG_LENGTH
GRIB_INVALID_TYPE = _gribapi_swig.GRIB_INVALID_TYPE
GRIB_WRONG_STEP = _gribapi_swig.GRIB_WRONG_STEP
GRIB_WRONG_STEP_UNIT = _gribapi_swig.GRIB_WRONG_STEP_UNIT
GRIB_INVALID_FILE = _gribapi_swig.GRIB_INVALID_FILE
GRIB_INVALID_GRIB = _gribapi_swig.GRIB_INVALID_GRIB
GRIB_INVALID_INDEX = _gribapi_swig.GRIB_INVALID_INDEX
GRIB_INVALID_ITERATOR = _gribapi_swig.GRIB_INVALID_ITERATOR
GRIB_INVALID_KEYS_ITERATOR = _gribapi_swig.GRIB_INVALID_KEYS_ITERATOR
GRIB_INVALID_NEAREST = _gribapi_swig.GRIB_INVALID_NEAREST
GRIB_INVALID_ORDERBY = _gribapi_swig.GRIB_INVALID_ORDERBY
GRIB_MISSING_KEY = _gribapi_swig.GRIB_MISSING_KEY
GRIB_OUT_OF_AREA = _gribapi_swig.GRIB_OUT_OF_AREA
GRIB_CONCEPT_NO_MATCH = _gribapi_swig.GRIB_CONCEPT_NO_MATCH
GRIB_HASH_ARRAY_NO_MATCH = _gribapi_swig.GRIB_HASH_ARRAY_NO_MATCH
GRIB_NO_DEFINITIONS = _gribapi_swig.GRIB_NO_DEFINITIONS
GRIB_WRONG_TYPE = _gribapi_swig.GRIB_WRONG_TYPE
GRIB_END = _gribapi_swig.GRIB_END
GRIB_NO_VALUES = _gribapi_swig.GRIB_NO_VALUES
GRIB_WRONG_GRID = _gribapi_swig.GRIB_WRONG_GRID
GRIB_END_OF_INDEX = _gribapi_swig.GRIB_END_OF_INDEX
GRIB_NULL_INDEX = _gribapi_swig.GRIB_NULL_INDEX
GRIB_PREMATURE_END_OF_FILE = _gribapi_swig.GRIB_PREMATURE_END_OF_FILE
GRIB_INTERNAL_ARRAY_TOO_SMALL = _gribapi_swig.GRIB_INTERNAL_ARRAY_TOO_SMALL
GRIB_MESSAGE_TOO_LARGE = _gribapi_swig.GRIB_MESSAGE_TOO_LARGE
GRIB_CONSTANT_FIELD = _gribapi_swig.GRIB_CONSTANT_FIELD
GRIB_SWITCH_NO_MATCH = _gribapi_swig.GRIB_SWITCH_NO_MATCH
GRIB_UNDERFLOW = _gribapi_swig.GRIB_UNDERFLOW
GRIB_MESSAGE_MALFORMED = _gribapi_swig.GRIB_MESSAGE_MALFORMED
GRIB_CORRUPTED_INDEX = _gribapi_swig.GRIB_CORRUPTED_INDEX
GRIB_INVALID_BPV = _gribapi_swig.GRIB_INVALID_BPV
GRIB_DIFFERENT_EDITION = _gribapi_swig.GRIB_DIFFERENT_EDITION
GRIB_VALUE_DIFFERENT = _gribapi_swig.GRIB_VALUE_DIFFERENT
GRIB_INVALID_KEY_VALUE = _gribapi_swig.GRIB_INVALID_KEY_VALUE
GRIB_STRING_TOO_SMALL = _gribapi_swig.GRIB_STRING_TOO_SMALL
GRIB_WRONG_CONVERSION = _gribapi_swig.GRIB_WRONG_CONVERSION
GRIB_MISSING_BUFR_ENTRY = _gribapi_swig.GRIB_MISSING_BUFR_ENTRY
GRIB_NULL_POINTER = _gribapi_swig.GRIB_NULL_POINTER
GRIB_ATTRIBUTE_CLASH = _gribapi_swig.GRIB_ATTRIBUTE_CLASH
GRIB_TOO_MANY_ATTRIBUTES = _gribapi_swig.GRIB_TOO_MANY_ATTRIBUTES
GRIB_ATTRIBUTE_NOT_FOUND = _gribapi_swig.GRIB_ATTRIBUTE_NOT_FOUND
GRIB_UNSUPPORTED_EDITION = _gribapi_swig.GRIB_UNSUPPORTED_EDITION
GRIB_OUT_OF_RANGE = _gribapi_swig.GRIB_OUT_OF_RANGE
GRIB_WRONG_BITMAP_SIZE = _gribapi_swig.GRIB_WRONG_BITMAP_SIZE
class intp(_object):
__swig_setmethods__ = {}
__setattr__ = lambda self, name, value: _swig_setattr(self, intp, name, value)
__swig_getmethods__ = {}
__getattr__ = lambda self, name: _swig_getattr(self, intp, name)
__repr__ = _swig_repr
def __init__(self):
this = _gribapi_swig.new_intp()
try:
self.this.append(this)
except __builtin__.Exception:
self.this = this
__swig_destroy__ = _gribapi_swig.delete_intp
__del__ = lambda self: None
def assign(self, value: 'int') -> "void":
return _gribapi_swig.intp_assign(self, value)
def value(self) -> "int":
return _gribapi_swig.intp_value(self)
def cast(self) -> "int *":
return _gribapi_swig.intp_cast(self)
if _newclass:
frompointer = staticmethod(_gribapi_swig.intp_frompointer)
else:
frompointer = _gribapi_swig.intp_frompointer
intp_swigregister = _gribapi_swig.intp_swigregister
intp_swigregister(intp)
def intp_frompointer(t: 'int *') -> "intp *":
return _gribapi_swig.intp_frompointer(t)
intp_frompointer = _gribapi_swig.intp_frompointer
class sizetp(_object):
__swig_setmethods__ = {}
__setattr__ = lambda self, name, value: _swig_setattr(self, sizetp, name, value)
__swig_getmethods__ = {}
__getattr__ = lambda self, name: _swig_getattr(self, sizetp, name)
__repr__ = _swig_repr
def __init__(self):
this = _gribapi_swig.new_sizetp()
try:
self.this.append(this)
except __builtin__.Exception:
self.this = this
__swig_destroy__ = _gribapi_swig.delete_sizetp
__del__ = lambda self: None
def assign(self, value: 'size_t') -> "void":
return _gribapi_swig.sizetp_assign(self, value)
def value(self) -> "size_t":
return _gribapi_swig.sizetp_value(self)
def cast(self) -> "size_t *":
return _gribapi_swig.sizetp_cast(self)
if _newclass:
frompointer = staticmethod(_gribapi_swig.sizetp_frompointer)
else:
frompointer = _gribapi_swig.sizetp_frompointer
sizetp_swigregister = _gribapi_swig.sizetp_swigregister
sizetp_swigregister(sizetp)
def sizetp_frompointer(t: 'size_t *') -> "sizetp *":
return _gribapi_swig.sizetp_frompointer(t)
sizetp_frompointer = _gribapi_swig.sizetp_frompointer
class longp(_object):
__swig_setmethods__ = {}
__setattr__ = lambda self, name, value: _swig_setattr(self, longp, name, value)
__swig_getmethods__ = {}
__getattr__ = lambda self, name: _swig_getattr(self, longp, name)
__repr__ = _swig_repr
def __init__(self):
this = _gribapi_swig.new_longp()
try:
self.this.append(this)
except __builtin__.Exception:
self.this = this
__swig_destroy__ = _gribapi_swig.delete_longp
__del__ = lambda self: None
def assign(self, value: 'long') -> "void":
return _gribapi_swig.longp_assign(self, value)
def value(self) -> "long":
return _gribapi_swig.longp_value(self)
def cast(self) -> "long *":
return _gribapi_swig.longp_cast(self)
if _newclass:
frompointer = staticmethod(_gribapi_swig.longp_frompointer)
else:
frompointer = _gribapi_swig.longp_frompointer
longp_swigregister = _gribapi_swig.longp_swigregister
longp_swigregister(longp)
def longp_frompointer(t: 'long *') -> "longp *":
return _gribapi_swig.longp_frompointer(t)
longp_frompointer = _gribapi_swig.longp_frompointer
class doublep(_object):
__swig_setmethods__ = {}
__setattr__ = lambda self, name, value: _swig_setattr(self, doublep, name, value)
__swig_getmethods__ = {}
__getattr__ = lambda self, name: _swig_getattr(self, doublep, name)
__repr__ = _swig_repr
def __init__(self):
this = _gribapi_swig.new_doublep()
try:
self.this.append(this)
except __builtin__.Exception:
self.this = this
__swig_destroy__ = _gribapi_swig.delete_doublep
__del__ = lambda self: None
def assign(self, value: 'double') -> "void":
return _gribapi_swig.doublep_assign(self, value)
def value(self) -> "double":
return _gribapi_swig.doublep_value(self)
def cast(self) -> "double *":
return _gribapi_swig.doublep_cast(self)
if _newclass:
frompointer = staticmethod(_gribapi_swig.doublep_frompointer)
else:
frompointer = _gribapi_swig.doublep_frompointer
doublep_swigregister = _gribapi_swig.doublep_swigregister
doublep_swigregister(doublep)
def doublep_frompointer(t: 'double *') -> "doublep *":
return _gribapi_swig.doublep_frompointer(t)
doublep_frompointer = _gribapi_swig.doublep_frompointer
def new_doubleArray(nelements: 'size_t') -> "double *":
return _gribapi_swig.new_doubleArray(nelements)
new_doubleArray = _gribapi_swig.new_doubleArray
def delete_doubleArray(ary: 'double *') -> "void":
return _gribapi_swig.delete_doubleArray(ary)
delete_doubleArray = _gribapi_swig.delete_doubleArray
def doubleArray_getitem(ary: 'double *', index: 'size_t') -> "double":
return _gribapi_swig.doubleArray_getitem(ary, index)
doubleArray_getitem = _gribapi_swig.doubleArray_getitem
def doubleArray_setitem(ary: 'double *', index: 'size_t', value: 'double') -> "void":
return _gribapi_swig.doubleArray_setitem(ary, index, value)
doubleArray_setitem = _gribapi_swig.doubleArray_setitem
def new_longArray(nelements: 'size_t') -> "long *":
return _gribapi_swig.new_longArray(nelements)
new_longArray = _gribapi_swig.new_longArray
def delete_longArray(ary: 'long *') -> "void":
return _gribapi_swig.delete_longArray(ary)
delete_longArray = _gribapi_swig.delete_longArray
def longArray_getitem(ary: 'long *', index: 'size_t') -> "long":
return _gribapi_swig.longArray_getitem(ary, index)
longArray_getitem = _gribapi_swig.longArray_getitem
def longArray_setitem(ary: 'long *', index: 'size_t', value: 'long') -> "void":
return _gribapi_swig.longArray_setitem(ary, index, value)
longArray_setitem = _gribapi_swig.longArray_setitem
def new_intArray(nelements: 'size_t') -> "int *":
return _gribapi_swig.new_intArray(nelements)
new_intArray = _gribapi_swig.new_intArray
def delete_intArray(ary: 'int *') -> "void":
return _gribapi_swig.delete_intArray(ary)
delete_intArray = _gribapi_swig.delete_intArray
def intArray_getitem(ary: 'int *', index: 'size_t') -> "int":
return _gribapi_swig.intArray_getitem(ary, index)
intArray_getitem = _gribapi_swig.intArray_getitem
def intArray_setitem(ary: 'int *', index: 'size_t', value: 'int') -> "void":
return _gribapi_swig.intArray_setitem(ary, index, value)
intArray_setitem = _gribapi_swig.intArray_setitem
def new_stringArray(nelements: 'size_t') -> "char **":
return _gribapi_swig.new_stringArray(nelements)
new_stringArray = _gribapi_swig.new_stringArray
def delete_stringArray(ary: 'char **') -> "void":
return _gribapi_swig.delete_stringArray(ary)
delete_stringArray = _gribapi_swig.delete_stringArray
def stringArray_getitem(ary: 'char **', index: 'size_t') -> "char *":
return _gribapi_swig.stringArray_getitem(ary, index)
stringArray_getitem = _gribapi_swig.stringArray_getitem
def stringArray_setitem(ary: 'char **', index: 'size_t', value: 'char *') -> "void":
return _gribapi_swig.stringArray_setitem(ary, index, value)
stringArray_setitem = _gribapi_swig.stringArray_setitem
def grib_c_new_from_file(f: 'FILE *', fd: 'int', fname: 'char *', INOUT: 'int *', headers_only: 'int') -> "int *":
return _gribapi_swig.grib_c_new_from_file(f, fd, fname, INOUT, headers_only)
grib_c_new_from_file = _gribapi_swig.grib_c_new_from_file
def grib_c_new_any_from_file(f: 'FILE *', headers_only: 'int', INOUT: 'int *') -> "int *":
return _gribapi_swig.grib_c_new_any_from_file(f, headers_only, INOUT)
grib_c_new_any_from_file = _gribapi_swig.grib_c_new_any_from_file
def grib_c_new_bufr_from_file(f: 'FILE *', fd: 'int', fname: 'char *', headers_only: 'int', INOUT: 'int *') -> "int *":
return _gribapi_swig.grib_c_new_bufr_from_file(f, fd, fname, headers_only, INOUT)
grib_c_new_bufr_from_file = _gribapi_swig.grib_c_new_bufr_from_file
def grib_c_new_gts_from_file(f: 'FILE *', headers_only: 'int', INOUT: 'int *') -> "int *":
return _gribapi_swig.grib_c_new_gts_from_file(f, headers_only, INOUT)
grib_c_new_gts_from_file = _gribapi_swig.grib_c_new_gts_from_file
def grib_c_new_metar_from_file(f: 'FILE *', headers_only: 'int', INOUT: 'int *') -> "int *":
return _gribapi_swig.grib_c_new_metar_from_file(f, headers_only, INOUT)
grib_c_new_metar_from_file = _gribapi_swig.grib_c_new_metar_from_file
def grib_c_iterator_new(arg1: 'int *', arg3: 'int *') -> "int *":
return _gribapi_swig.grib_c_iterator_new(arg1, arg3)
grib_c_iterator_new = _gribapi_swig.grib_c_iterator_new
def grib_c_keys_iterator_new(INPUT: 'int *', name_space: 'char *') -> "int *":
return _gribapi_swig.grib_c_keys_iterator_new(INPUT, name_space)
grib_c_keys_iterator_new = _gribapi_swig.grib_c_keys_iterator_new
def codes_c_bufr_keys_iterator_new(INPUT: 'int *') -> "int *":
return _gribapi_swig.codes_c_bufr_keys_iterator_new(INPUT)
codes_c_bufr_keys_iterator_new = _gribapi_swig.codes_c_bufr_keys_iterator_new
def grib_c_grib_new_from_samples(INOUT: 'int *', name: 'char *') -> "int *":
return _gribapi_swig.grib_c_grib_new_from_samples(INOUT, name)
grib_c_grib_new_from_samples = _gribapi_swig.grib_c_grib_new_from_samples
def grib_c_bufr_new_from_samples(INOUT: 'int *', name: 'char *') -> "int *":
return _gribapi_swig.grib_c_bufr_new_from_samples(INOUT, name)
grib_c_bufr_new_from_samples = _gribapi_swig.grib_c_bufr_new_from_samples
def grib_c_index_new_from_file(file: 'char *', keys: 'char *') -> "int *":
return _gribapi_swig.grib_c_index_new_from_file(file, keys)
grib_c_index_new_from_file = _gribapi_swig.grib_c_index_new_from_file
def grib_c_index_add_file(INPUT: 'int *', file: 'char *') -> "int":
return _gribapi_swig.grib_c_index_add_file(INPUT, file)
grib_c_index_add_file = _gribapi_swig.grib_c_index_add_file
def grib_c_new_from_index(INPUT: 'int *', INOUT: 'int *') -> "int *":
return _gribapi_swig.grib_c_new_from_index(INPUT, INOUT)
grib_c_new_from_index = _gribapi_swig.grib_c_new_from_index
def grib_c_index_write(INPUT: 'int *', file: 'char *') -> "int":
return _gribapi_swig.grib_c_index_write(INPUT, file)
grib_c_index_write = _gribapi_swig.grib_c_index_write
def grib_c_index_read(file: 'char *') -> "int *":
return _gribapi_swig.grib_c_index_read(file)
grib_c_index_read = _gribapi_swig.grib_c_index_read
def grib_c_new_from_message(INOUT: 'int *', binmsg: 'char *', INPUT: 'size_t *') -> "int *":
return _gribapi_swig.grib_c_new_from_message(INOUT, binmsg, INPUT)
grib_c_new_from_message = _gribapi_swig.grib_c_new_from_message
def grib_c_count_in_file(f: 'FILE *') -> "int *":
return _gribapi_swig.grib_c_count_in_file(f)
grib_c_count_in_file = _gribapi_swig.grib_c_count_in_file
def grib_c_release(gid: 'int *') -> "int":
return _gribapi_swig.grib_c_release(gid)
grib_c_release = _gribapi_swig.grib_c_release
def grib_c_write(gid: 'int *', f: 'FILE *') -> "int":
return _gribapi_swig.grib_c_write(gid, f)
grib_c_write = _gribapi_swig.grib_c_write
def grib_c_get_size_long(gid: 'int *', key: 'char *') -> "long *":
return _gribapi_swig.grib_c_get_size_long(gid, key)
grib_c_get_size_long = _gribapi_swig.grib_c_get_size_long
def grib_c_get_string_length(gid: 'int *', key: 'char *') -> "size_t *":
return _gribapi_swig.grib_c_get_string_length(gid, key)
grib_c_get_string_length = _gribapi_swig.grib_c_get_string_length
def grib_c_clone(gid: 'int *', INOUT: 'int *') -> "int *":
return _gribapi_swig.grib_c_clone(gid, INOUT)
grib_c_clone = _gribapi_swig.grib_c_clone
def grib_c_copy_namespace(gid: 'int *', name: 'char *', INPUT: 'int *') -> "int":
return _gribapi_swig.grib_c_copy_namespace(gid, name, INPUT)
grib_c_copy_namespace = _gribapi_swig.grib_c_copy_namespace
def grib_c_get_message_size(gid: 'int *') -> "size_t *":
return _gribapi_swig.grib_c_get_message_size(gid)
grib_c_get_message_size = _gribapi_swig.grib_c_get_message_size
def grib_c_get_message_offset(gid: 'int *') -> "size_t *":
return _gribapi_swig.grib_c_get_message_offset(gid)
grib_c_get_message_offset = _gribapi_swig.grib_c_get_message_offset
def grib_c_get_native_type(gid: 'int *', key: 'char *') -> "int *":
return _gribapi_swig.grib_c_get_native_type(gid, key)
grib_c_get_native_type = _gribapi_swig.grib_c_get_native_type
def grib_c_multi_new() -> "int *":
return _gribapi_swig.grib_c_multi_new()
grib_c_multi_new = _gribapi_swig.grib_c_multi_new
def grib_c_multi_support_on() -> "int":
return _gribapi_swig.grib_c_multi_support_on()
grib_c_multi_support_on = _gribapi_swig.grib_c_multi_support_on
def grib_c_multi_write(gid: 'int *', f: 'FILE *') -> "int":
return _gribapi_swig.grib_c_multi_write(gid, f)
grib_c_multi_write = _gribapi_swig.grib_c_multi_write
def grib_c_multi_support_off() -> "int":
return _gribapi_swig.grib_c_multi_support_off()
grib_c_multi_support_off = _gribapi_swig.grib_c_multi_support_off
def grib_c_multi_release(gid: 'int *') -> "int":
return _gribapi_swig.grib_c_multi_release(gid)
grib_c_multi_release = _gribapi_swig.grib_c_multi_release
def grib_c_multi_append(arg1: 'int *', arg2: 'int *', arg3: 'int *') -> "int":
return _gribapi_swig.grib_c_multi_append(arg1, arg2, arg3)
grib_c_multi_append = _gribapi_swig.grib_c_multi_append
def grib_c_gribex_mode_on() -> "int":
return _gribapi_swig.grib_c_gribex_mode_on()
grib_c_gribex_mode_on = _gribapi_swig.grib_c_gribex_mode_on
def grib_c_gribex_mode_off() -> "int":
return _gribapi_swig.grib_c_gribex_mode_off()
grib_c_gribex_mode_off = _gribapi_swig.grib_c_gribex_mode_off
def grib_c_keys_iterator_next(iterid: 'int *') -> "int":
return _gribapi_swig.grib_c_keys_iterator_next(iterid)
grib_c_keys_iterator_next = _gribapi_swig.grib_c_keys_iterator_next
def codes_c_bufr_keys_iterator_next(iterid: 'int *') -> "int":
return _gribapi_swig.codes_c_bufr_keys_iterator_next(iterid)
codes_c_bufr_keys_iterator_next = _gribapi_swig.codes_c_bufr_keys_iterator_next
def grib_c_keys_iterator_delete(iterid: 'int *') -> "int":
return _gribapi_swig.grib_c_keys_iterator_delete(iterid)
grib_c_keys_iterator_delete = _gribapi_swig.grib_c_keys_iterator_delete
def codes_c_bufr_keys_iterator_delete(iterid: 'int *') -> "int":
return _gribapi_swig.codes_c_bufr_keys_iterator_delete(iterid)
codes_c_bufr_keys_iterator_delete = _gribapi_swig.codes_c_bufr_keys_iterator_delete
def grib_c_skip_computed(iterid: 'int *') -> "int":
return _gribapi_swig.grib_c_skip_computed(iterid)
grib_c_skip_computed = _gribapi_swig.grib_c_skip_computed
def grib_c_skip_coded(iterid: 'int *') -> "int":
return _gribapi_swig.grib_c_skip_coded(iterid)
grib_c_skip_coded = _gribapi_swig.grib_c_skip_coded
def grib_c_skip_edition_specific(iterid: 'int *') -> "int":
return _gribapi_swig.grib_c_skip_edition_specific(iterid)
grib_c_skip_edition_specific = _gribapi_swig.grib_c_skip_edition_specific
def grib_c_skip_duplicates(iterid: 'int *') -> "int":
return _gribapi_swig.grib_c_skip_duplicates(iterid)
grib_c_skip_duplicates = _gribapi_swig.grib_c_skip_duplicates
def grib_c_skip_read_only(iterid: 'int *') -> "int":
return _gribapi_swig.grib_c_skip_read_only(iterid)
grib_c_skip_read_only = _gribapi_swig.grib_c_skip_read_only
def grib_c_skip_function(iterid: 'int *') -> "int":
return _gribapi_swig.grib_c_skip_function(iterid)
grib_c_skip_function = _gribapi_swig.grib_c_skip_function
def grib_c_keys_iterator_rewind(iterid: 'int *') -> "int":
return _gribapi_swig.grib_c_keys_iterator_rewind(iterid)
grib_c_keys_iterator_rewind = _gribapi_swig.grib_c_keys_iterator_rewind
def codes_c_bufr_keys_iterator_rewind(iterid: 'int *') -> "int":
return _gribapi_swig.codes_c_bufr_keys_iterator_rewind(iterid)
codes_c_bufr_keys_iterator_rewind = _gribapi_swig.codes_c_bufr_keys_iterator_rewind
def grib_c_bufr_copy_data(gid: 'int *', INOUT: 'int *') -> "int *":
return _gribapi_swig.grib_c_bufr_copy_data(gid, INOUT)
grib_c_bufr_copy_data = _gribapi_swig.grib_c_bufr_copy_data
def grib_c_keys_iterator_get_name(iterid: 'int *', len: 'int') -> "char *":
return _gribapi_swig.grib_c_keys_iterator_get_name(iterid, len)
grib_c_keys_iterator_get_name = _gribapi_swig.grib_c_keys_iterator_get_name
def codes_c_bufr_keys_iterator_get_name(iterid: 'int *', len: 'int') -> "char *":
return _gribapi_swig.codes_c_bufr_keys_iterator_get_name(iterid, len)
codes_c_bufr_keys_iterator_get_name = _gribapi_swig.codes_c_bufr_keys_iterator_get_name
def grib_c_index_get_size_long(iid: 'int *', key: 'char *') -> "long *":
return _gribapi_swig.grib_c_index_get_size_long(iid, key)
grib_c_index_get_size_long = _gribapi_swig.grib_c_index_get_size_long
def grib_c_index_get_long(iid: 'int *', key: 'char *', val: 'long *', size: 'int *') -> "int":
return _gribapi_swig.grib_c_index_get_long(iid, key, val, size)
grib_c_index_get_long = _gribapi_swig.grib_c_index_get_long
def grib_c_index_get_real8(iid: 'int *', key: 'char *', val: 'double *', size: 'int *') -> "int":
return _gribapi_swig.grib_c_index_get_real8(iid, key, val, size)
grib_c_index_get_real8 = _gribapi_swig.grib_c_index_get_real8
def grib_c_index_get_string(iid: 'int *', key: 'char *', INPUT: 'int *', INOUT: 'int *') -> "char *, int *":
return _gribapi_swig.grib_c_index_get_string(iid, key, INPUT, INOUT)
grib_c_index_get_string = _gribapi_swig.grib_c_index_get_string
def grib_c_index_select_long(iid: 'int *', key: 'char *', INPUT: 'long *') -> "int":
return _gribapi_swig.grib_c_index_select_long(iid, key, INPUT)
grib_c_index_select_long = _gribapi_swig.grib_c_index_select_long
def grib_c_index_select_real8(iid: 'int *', key: 'char *', INPUT: 'double *') -> "int":
return _gribapi_swig.grib_c_index_select_real8(iid, key, INPUT)
grib_c_index_select_real8 = _gribapi_swig.grib_c_index_select_real8
def grib_c_index_select_string(iid: 'int *', key: 'char *', val: 'char *') -> "int":
return _gribapi_swig.grib_c_index_select_string(iid, key, val)
grib_c_index_select_string = _gribapi_swig.grib_c_index_select_string
def grib_c_index_release(iid: 'int *') -> "int":
return _gribapi_swig.grib_c_index_release(iid)
grib_c_index_release = _gribapi_swig.grib_c_index_release
def grib_c_iterator_delete(iterid: 'int *') -> "int":
return _gribapi_swig.grib_c_iterator_delete(iterid)
grib_c_iterator_delete = _gribapi_swig.grib_c_iterator_delete
def grib_c_iterator_next(iterid: 'int *') -> "double *, double *, double *":
return _gribapi_swig.grib_c_iterator_next(iterid)
grib_c_iterator_next = _gribapi_swig.grib_c_iterator_next
def grib_c_get_string(gid: 'int *', key: 'char *', string_val: 'char *') -> "size_t *":
return _gribapi_swig.grib_c_get_string(gid, key, string_val)
grib_c_get_string = _gribapi_swig.grib_c_get_string
def grib_c_get_string_array(gid: 'int *', key: 'char *', array_string_val: 'char **', size: 'size_t *') -> "int":
return _gribapi_swig.grib_c_get_string_array(gid, key, array_string_val, size)
grib_c_get_string_array = _gribapi_swig.grib_c_get_string_array
def grib_c_set_string(gid: 'int *', key: 'char *', sval: 'char *', len2: 'int') -> "int":
return _gribapi_swig.grib_c_set_string(gid, key, sval, len2)
grib_c_set_string = _gribapi_swig.grib_c_set_string
def grib_c_get_long(gid: 'int *', key: 'char *') -> "long *":
return _gribapi_swig.grib_c_get_long(gid, key)
grib_c_get_long = _gribapi_swig.grib_c_get_long
def grib_c_set_long(gid: 'int *', key: 'char *', INPUT: 'long *') -> "int":
return _gribapi_swig.grib_c_set_long(gid, key, INPUT)
grib_c_set_long = _gribapi_swig.grib_c_set_long
def grib_c_get_double(gid: 'int *', key: 'char *') -> "double *":
return _gribapi_swig.grib_c_get_double(gid, key)
grib_c_get_double = _gribapi_swig.grib_c_get_double
def grib_c_set_double(gid: 'int *', key: 'char *', INPUT: 'double *') -> "int":
return _gribapi_swig.grib_c_set_double(gid, key, INPUT)
grib_c_set_double = _gribapi_swig.grib_c_set_double
def grib_c_set_real8_array(gid: 'int *', key: 'char *', val: 'double *', size: 'int *') -> "int":
return _gribapi_swig.grib_c_set_real8_array(gid, key, val, size)
grib_c_set_real8_array = _gribapi_swig.grib_c_set_real8_array
def grib_c_get_real8_array(gid: 'int *', key: 'char *', val: 'double *', size: 'int *') -> "int":
return _gribapi_swig.grib_c_get_real8_array(gid, key, val, size)
grib_c_get_real8_array = _gribapi_swig.grib_c_get_real8_array
def grib_c_get_long_array(gid: 'int *', key: 'char *', val: 'long *', size: 'int *') -> "int":
return _gribapi_swig.grib_c_get_long_array(gid, key, val, size)
grib_c_get_long_array = _gribapi_swig.grib_c_get_long_array
def grib_c_set_long_array(gid: 'int *', key: 'char *', val: 'long *', size: 'int *') -> "int":
return _gribapi_swig.grib_c_set_long_array(gid, key, val, size)
grib_c_set_long_array = _gribapi_swig.grib_c_set_long_array
def grib_c_get_real8_element(gid: 'int *', key: 'char *', INPUT: 'int *') -> "double *":
return _gribapi_swig.grib_c_get_real8_element(gid, key, INPUT)
grib_c_get_real8_element = _gribapi_swig.grib_c_get_real8_element
def grib_c_get_real8_elements(gid: 'int *', key: 'char *', index: 'int *', val: 'double *', size: 'int *') -> "int":
return _gribapi_swig.grib_c_get_real8_elements(gid, key, index, val, size)
grib_c_get_real8_elements = _gribapi_swig.grib_c_get_real8_elements
def grib_c_set_missing(gid: 'int *', key: 'char *') -> "int":
return _gribapi_swig.grib_c_set_missing(gid, key)
grib_c_set_missing = _gribapi_swig.grib_c_set_missing
def grib_c_set_key_vals(gid: 'int *', keyvals: 'char *') -> "int":
return _gribapi_swig.grib_c_set_key_vals(gid, keyvals)
grib_c_set_key_vals = _gribapi_swig.grib_c_set_key_vals
def grib_c_is_missing(gid: 'int *', key: 'char *') -> "int *":
return _gribapi_swig.grib_c_is_missing(gid, key)
grib_c_is_missing = _gribapi_swig.grib_c_is_missing
def grib_c_is_defined(gid: 'int *', key: 'char *') -> "int *":
return _gribapi_swig.grib_c_is_defined(gid, key)
grib_c_is_defined = _gribapi_swig.grib_c_is_defined
def grib_c_set_string_array(gid: 'int *', key: 'char *', val: 'char const **') -> "int":
return _gribapi_swig.grib_c_set_string_array(gid, key, val)
grib_c_set_string_array = _gribapi_swig.grib_c_set_string_array
def grib_set_double_ndarray(gid: 'int *', key: 'char *', dpin_val: 'double *') -> "int":
return _gribapi_swig.grib_set_double_ndarray(gid, key, dpin_val)
grib_set_double_ndarray = _gribapi_swig.grib_set_double_ndarray
def grib_set_long_ndarray(gid: 'int *', key: 'char *', lpin_val: 'long *') -> "int":
return _gribapi_swig.grib_set_long_ndarray(gid, key, lpin_val)
grib_set_long_ndarray = _gribapi_swig.grib_set_long_ndarray
def grib_get_double_ndarray(gid: 'int *', key: 'char *', dpout_val: 'double *') -> "int":
return _gribapi_swig.grib_get_double_ndarray(gid, key, dpout_val)
grib_get_double_ndarray = _gribapi_swig.grib_get_double_ndarray
def grib_get_long_ndarray(gid: 'int *', key: 'char *', lpout_val: 'long *') -> "int":
return _gribapi_swig.grib_get_long_ndarray(gid, key, lpout_val)
grib_get_long_ndarray = _gribapi_swig.grib_get_long_ndarray
def grib_get_double_ndelements(gid: 'int *', key: 'char *', ipin_index: 'int *', dpout_val: 'double *') -> "int":
return _gribapi_swig.grib_get_double_ndelements(gid, key, ipin_index, dpout_val)
grib_get_double_ndelements = _gribapi_swig.grib_get_double_ndelements
def grib_c_find_nearest_single(gid: 'int *', arg2: 'int *', arg3: 'double *', arg4: 'double *') -> "double *, double *, double *, double *, int *":
return _gribapi_swig.grib_c_find_nearest_single(gid, arg2, arg3, arg4)
grib_c_find_nearest_single = _gribapi_swig.grib_c_find_nearest_single
def grib_c_find_nearest_four_single(gid: 'int *', arg2: 'int *', arg3: 'double *', arg4: 'double *', outlats: 'double *', outlons: 'double *', values: 'double *', distances: 'double *', indexes: 'int *') -> "int":
return _gribapi_swig.grib_c_find_nearest_four_single(gid, arg2, arg3, arg4, outlats, outlons, values, distances, indexes)
grib_c_find_nearest_four_single = _gribapi_swig.grib_c_find_nearest_four_single
def grib_c_get_message(gid: 'int *') -> "size_t *":
return _gribapi_swig.grib_c_get_message(gid)
grib_c_get_message = _gribapi_swig.grib_c_get_message
def grib_c_get_error_string(INPUT: 'int *', len: 'int') -> "char *":
return _gribapi_swig.grib_c_get_error_string(INPUT, len)
grib_c_get_error_string = _gribapi_swig.grib_c_get_error_string
def no_fail_on_wrong_length(flag: 'int') -> "void":
return _gribapi_swig.no_fail_on_wrong_length(flag)
no_fail_on_wrong_length = _gribapi_swig.no_fail_on_wrong_length
def grib_c_get_api_version() -> "long":
return _gribapi_swig.grib_c_get_api_version()
grib_c_get_api_version = _gribapi_swig.grib_c_get_api_version
def grib_c_gts_header_on() -> "void":
return _gribapi_swig.grib_c_gts_header_on()
grib_c_gts_header_on = _gribapi_swig.grib_c_gts_header_on
def grib_c_gts_header_off() -> "void":
return _gribapi_swig.grib_c_gts_header_off()
grib_c_gts_header_off = _gribapi_swig.grib_c_gts_header_off
def grib_c_set_definitions_path(path: 'char const *') -> "void":
return _gribapi_swig.grib_c_set_definitions_path(path)
grib_c_set_definitions_path = _gribapi_swig.grib_c_set_definitions_path
def grib_c_set_samples_path(path: 'char const *') -> "void":
return _gribapi_swig.grib_c_set_samples_path(path)
grib_c_set_samples_path = _gribapi_swig.grib_c_set_samples_path
# This file is compatible with both classic and new-style classes.

42
python3/test_iterator.py Executable file
View File

@ -0,0 +1,42 @@
#!/usr/bin/env python
import sys
from gribapi import *
import profile
def main():
infile = sys.argv[1]
fid = open(infile,"r")
count = grib_count_in_file(fid)
for i in range(count):
gid = grib_new_from_file(fid)
nval = grib_get_size(gid,"values")
iterid = grib_iterator_new(gid,0)
missingValue = grib_get_double(gid,"missingValue")
i=0
while 1:
result = grib_iterator_next(iterid)
if not result: break
[lat,lon,value] = result
sys.stdout.write("- %d - lat=%.6f lon=%.6f value=" % (i,lat,lon))
if value == missingValue:
print("missing")
else:
print("%.6f" % value)
i += 1
grib_iterator_delete(iterid)
grib_release(gid)
fid.close()
if __name__ == "__main__":
#profile.run('main()')
main()

View File

@ -202,7 +202,7 @@ if( HAVE_PYTHON AND ENABLE_EXTRA_TESTS )
ecbuild_add_test( TARGET eccodes_t_${test}
TYPE SCRIPT
COMMAND ${CMAKE_CURRENT_SOURCE_DIR}/${test}.sh
ENVIRONMENT PYTHON=${PYTHON_EXECUTABLE} PYTHONPATH=${PROJECT_BINARY_DIR}/python
ENVIRONMENT PYTHON=${PYTHON_EXECUTABLE} PYTHONPATH=${PROJECT_BINARY_DIR}/${ECCODES_PYTHON_DIR}
TEST_DEPENDS eccodes_download_bufrs
)
endforeach()