RAVE
pyraveio.h
Go to the documentation of this file.
1/* --------------------------------------------------------------------
2Copyright (C) 2009 Swedish Meteorological and Hydrological Institute, SMHI,
3
4This file is part of RAVE.
5
6RAVE is free software: you can redistribute it and/or modify
7it under the terms of the GNU Lesser General Public License as published by
8the Free Software Foundation, either version 3 of the License, or
9(at your option) any later version.
10
11RAVE is distributed in the hope that it will be useful,
12but WITHOUT ANY WARRANTY; without even the implied warranty of
13MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14GNU Lesser General Public License for more details.
15
16You should have received a copy of the GNU Lesser General Public License
17along with RAVE. If not, see <http://www.gnu.org/licenses/>.
18------------------------------------------------------------------------*/
25#ifndef PYRAVEIO_H
26#define PYRAVEIO_H
27#include "rave_io.h"
28
32typedef struct {
33 PyObject_HEAD /* Always has to be on top */
35} PyRaveIO;
36
37#define PyRaveIO_Type_NUM 0
38
39#define PyRaveIO_GetNative_NUM 1
40#define PyRaveIO_GetNative_RETURN RaveIO_t*
41#define PyRaveIO_GetNative_PROTO (PyRaveIO*)
42
43#define PyRaveIO_New_NUM 2
44#define PyRaveIO_New_RETURN PyRaveIO*
45#define PyRaveIO_New_PROTO (RaveIO_t*)
46
47#define PyRaveIO_Open_NUM 3
48#define PyRaveIO_Open_RETURN PyRaveIO*
49#define PyRaveIO_Open_PROTO (const char* filename, int lazyLoading, const char* preloadQuantities)
50
51#define PyRaveIO_OpenFileObject_NUM 4
52#define PyRaveIO_OpenFileObject_RETURN PyRaveIO*
53#define PyRaveIO_OpenFileObject_PROTO (const char* filename, int lazyLoading, const char* preloadQuantities)
54
55
56#define PyRaveIO_API_pointers 5
57
58#define PyRaveIO_CAPSULE_NAME "_raveio._C_API"
59
60#ifdef PYRAVEIO_MODULE
62extern PyTypeObject PyRaveIO_Type;
63
65#define PyRaveIO_Check(op) ((op)->ob_type == &PyRaveIO_Type)
66
69
72
75
78
79#else
81static void **PyRaveIO_API;
82
87#define PyRaveIO_GetNative \
88 (*(PyRaveIO_GetNative_RETURN (*)PyRaveIO_GetNative_PROTO) PyRaveIO_API[PyRaveIO_GetNative_NUM])
89
97#define PyRaveIO_New \
98 (*(PyRaveIO_New_RETURN (*)PyRaveIO_New_PROTO) PyRaveIO_API[PyRaveIO_New_NUM])
99
105#define PyRaveIO_Open \
106 (*(PyRaveIO_Open_RETURN (*)PyRaveIO_Open_PROTO) PyRaveIO_API[PyRaveIO_Open_NUM])
107
113#define PyRaveIO_OpenFileObject \
114 (*(PyRaveIO_OpenFileObject_RETURN (*)PyRaveIO_OpenFileObject_PROTO) PyRaveIO_API[PyRaveIO_OpenFileObject_NUM])
115
119#define PyRaveIO_Check(op) \
120 (Py_TYPE(op) == &PyRaveIO_Type)
121
122#define PyRaveIO_Type (*(PyTypeObject*)PyRaveIO_API[PyRaveIO_Type_NUM])
123
127#define import_pyraveio() \
128 PyRaveIO_API = (void **)PyCapsule_Import(PyRaveIO_CAPSULE_NAME, 1);
129
130
131#ifdef KALLE
135#define PyRaveIO_Check(op) \
136 ((op)->ob_type == (PyTypeObject *)PyRaveIO_API[PyRaveIO_Type_NUM])
137
141static int
142import_pyraveio(void)
143{
144 PyObject *module;
145 PyObject *c_api_object;
146
147 module = PyImport_ImportModule("_raveio");
148 if (module == NULL) {
149 return -1;
150 }
151
152 c_api_object = PyObject_GetAttrString(module, "_C_API");
153 if (c_api_object == NULL) {
154 Py_DECREF(module);
155 return -1;
156 }
157 if (PyCObject_Check(c_api_object)) {
158 PyRaveIO_API = (void **)PyCObject_AsVoidPtr(c_api_object);
159 }
160 Py_DECREF(c_api_object);
161 Py_DECREF(module);
162 return 0;
163}
164#endif
165
166#endif
167
168#endif /* PYRAVEIO_H */
#define PyRaveIO_New
Creates a new rave io instance.
Definition pyraveio.h:97
#define PyRaveIO_New_PROTO
argument prototype for New
Definition pyraveio.h:45
#define PyRaveIO_Open_RETURN
return type for Open
Definition pyraveio.h:48
#define PyRaveIO_GetNative_PROTO
argument prototype for GetNative
Definition pyraveio.h:41
#define import_pyraveio()
Imports the PyRaveIO module (like import _raveio in python).
Definition pyraveio.h:127
#define PyRaveIO_GetNative
Returns a pointer to the internal rave io, remember to release the reference when done with the objec...
Definition pyraveio.h:87
#define PyRaveIO_Open_PROTO
argument prototype for Open
Definition pyraveio.h:49
#define PyRaveIO_Open
Opens a rave io instance.
Definition pyraveio.h:105
#define PyRaveIO_OpenFileObject_PROTO
argument prototype for Open
Definition pyraveio.h:53
#define PyRaveIO_New_RETURN
return type for New
Definition pyraveio.h:44
#define PyRaveIO_OpenFileObject_RETURN
return type for Open
Definition pyraveio.h:52
#define PyRaveIO_OpenFileObject
Opens a rave io instance.
Definition pyraveio.h:113
#define PyRaveIO_GetNative_RETURN
return type for GetNative
Definition pyraveio.h:40
Functions for performing rave related IO operations, mostly ODIM-formatted HDF5 files.
struct _RaveIO_t RaveIO_t
Defines a Rave IO instance.
Definition rave_io.h:50
The RaveIO.
Definition pyraveio.h:32
PyObject_HEAD RaveIO_t * raveio
the raveio instance
Definition pyraveio.h:34