/* Generated by Cython 0.17.4 on Fri Jan 11 07:16:35 2013 */

#define PY_SSIZE_T_CLEAN
#include "Python.h"
#ifndef Py_PYTHON_H
    #error Python headers needed to compile C extensions, please install development version of Python.
#elif PY_VERSION_HEX < 0x02040000
    #error Cython requires Python 2.4+.
#else
#include <stddef.h> /* For offsetof */
#ifndef offsetof
#define offsetof(type, member) ( (size_t) & ((type*)0) -> member )
#endif
#if !defined(WIN32) && !defined(MS_WINDOWS)
  #ifndef __stdcall
    #define __stdcall
  #endif
  #ifndef __cdecl
    #define __cdecl
  #endif
  #ifndef __fastcall
    #define __fastcall
  #endif
#endif
#ifndef DL_IMPORT
  #define DL_IMPORT(t) t
#endif
#ifndef DL_EXPORT
  #define DL_EXPORT(t) t
#endif
#ifndef PY_LONG_LONG
  #define PY_LONG_LONG LONG_LONG
#endif
#ifndef Py_HUGE_VAL
  #define Py_HUGE_VAL HUGE_VAL
#endif
#ifdef PYPY_VERSION
#define CYTHON_COMPILING_IN_PYPY 1
#define CYTHON_COMPILING_IN_CPYTHON 0
#else
#define CYTHON_COMPILING_IN_PYPY 0
#define CYTHON_COMPILING_IN_CPYTHON 1
#endif
#if PY_VERSION_HEX < 0x02050000
  typedef int Py_ssize_t;
  #define PY_SSIZE_T_MAX INT_MAX
  #define PY_SSIZE_T_MIN INT_MIN
  #define PY_FORMAT_SIZE_T ""
  #define CYTHON_FORMAT_SSIZE_T ""
  #define PyInt_FromSsize_t(z) PyInt_FromLong(z)
  #define PyInt_AsSsize_t(o)   __Pyx_PyInt_AsInt(o)
  #define PyNumber_Index(o)    ((PyNumber_Check(o) && !PyFloat_Check(o)) ? PyNumber_Int(o) : \
                                (PyErr_Format(PyExc_TypeError, \
                                              "expected index value, got %.200s", Py_TYPE(o)->tp_name), \
                                 (PyObject*)0))
  #define __Pyx_PyIndex_Check(o) (PyNumber_Check(o) && !PyFloat_Check(o) && \
                                  !PyComplex_Check(o))
  #define PyIndex_Check __Pyx_PyIndex_Check
  #define PyErr_WarnEx(category, message, stacklevel) PyErr_Warn(category, message)
  #define __PYX_BUILD_PY_SSIZE_T "i"
#else
  #define __PYX_BUILD_PY_SSIZE_T "n"
  #define CYTHON_FORMAT_SSIZE_T "z"
  #define __Pyx_PyIndex_Check PyIndex_Check
#endif
#if PY_VERSION_HEX < 0x02060000
  #define Py_REFCNT(ob) (((PyObject*)(ob))->ob_refcnt)
  #define Py_TYPE(ob)   (((PyObject*)(ob))->ob_type)
  #define Py_SIZE(ob)   (((PyVarObject*)(ob))->ob_size)
  #define PyVarObject_HEAD_INIT(type, size) \
          PyObject_HEAD_INIT(type) size,
  #define PyType_Modified(t)
  typedef struct {
     void *buf;
     PyObject *obj;
     Py_ssize_t len;
     Py_ssize_t itemsize;
     int readonly;
     int ndim;
     char *format;
     Py_ssize_t *shape;
     Py_ssize_t *strides;
     Py_ssize_t *suboffsets;
     void *internal;
  } Py_buffer;
  #define PyBUF_SIMPLE 0
  #define PyBUF_WRITABLE 0x0001
  #define PyBUF_FORMAT 0x0004
  #define PyBUF_ND 0x0008
  #define PyBUF_STRIDES (0x0010 | PyBUF_ND)
  #define PyBUF_C_CONTIGUOUS (0x0020 | PyBUF_STRIDES)
  #define PyBUF_F_CONTIGUOUS (0x0040 | PyBUF_STRIDES)
  #define PyBUF_ANY_CONTIGUOUS (0x0080 | PyBUF_STRIDES)
  #define PyBUF_INDIRECT (0x0100 | PyBUF_STRIDES)
  #define PyBUF_RECORDS (PyBUF_STRIDES | PyBUF_FORMAT | PyBUF_WRITABLE)
  #define PyBUF_FULL (PyBUF_INDIRECT | PyBUF_FORMAT | PyBUF_WRITABLE)
  typedef int (*getbufferproc)(PyObject *, Py_buffer *, int);
  typedef void (*releasebufferproc)(PyObject *, Py_buffer *);
#endif
#if PY_MAJOR_VERSION < 3
  #define __Pyx_BUILTIN_MODULE_NAME "__builtin__"
  #define __Pyx_PyCode_New(a, k, l, s, f, code, c, n, v, fv, cell, fn, name, fline, lnos) \
          PyCode_New(a, l, s, f, code, c, n, v, fv, cell, fn, name, fline, lnos)
#else
  #define __Pyx_BUILTIN_MODULE_NAME "builtins"
  #define __Pyx_PyCode_New(a, k, l, s, f, code, c, n, v, fv, cell, fn, name, fline, lnos) \
          PyCode_New(a, k, l, s, f, code, c, n, v, fv, cell, fn, name, fline, lnos)
#endif
#if PY_MAJOR_VERSION < 3 && PY_MINOR_VERSION < 6
  #define PyUnicode_FromString(s) PyUnicode_Decode(s, strlen(s), "UTF-8", "strict")
#endif
#if PY_MAJOR_VERSION >= 3
  #define Py_TPFLAGS_CHECKTYPES 0
  #define Py_TPFLAGS_HAVE_INDEX 0
#endif
#if (PY_VERSION_HEX < 0x02060000) || (PY_MAJOR_VERSION >= 3)
  #define Py_TPFLAGS_HAVE_NEWBUFFER 0
#endif
#if PY_VERSION_HEX > 0x03030000 && defined(PyUnicode_KIND)
  #define CYTHON_PEP393_ENABLED 1
  #define __Pyx_PyUnicode_READY(op)       (likely(PyUnicode_IS_READY(op)) ? \
                                              0 : _PyUnicode_Ready((PyObject *)(op)))
  #define __Pyx_PyUnicode_GET_LENGTH(u)   PyUnicode_GET_LENGTH(u)
  #define __Pyx_PyUnicode_READ_CHAR(u, i) PyUnicode_READ_CHAR(u, i)
  #define __Pyx_PyUnicode_READ(k, d, i)   PyUnicode_READ(k, d, i)
#else
  #define CYTHON_PEP393_ENABLED 0
  #define __Pyx_PyUnicode_READY(op)       (0)
  #define __Pyx_PyUnicode_GET_LENGTH(u)   PyUnicode_GET_SIZE(u)
  #define __Pyx_PyUnicode_READ_CHAR(u, i) ((Py_UCS4)(PyUnicode_AS_UNICODE(u)[i]))
  #define __Pyx_PyUnicode_READ(k, d, i)   ((k=k), (Py_UCS4)(((Py_UNICODE*)d)[i]))
#endif
#if PY_MAJOR_VERSION >= 3
  #define PyBaseString_Type            PyUnicode_Type
  #define PyStringObject               PyUnicodeObject
  #define PyString_Type                PyUnicode_Type
  #define PyString_Check               PyUnicode_Check
  #define PyString_CheckExact          PyUnicode_CheckExact
#endif
#if PY_VERSION_HEX < 0x02060000
  #define PyBytesObject                PyStringObject
  #define PyBytes_Type                 PyString_Type
  #define PyBytes_Check                PyString_Check
  #define PyBytes_CheckExact           PyString_CheckExact
  #define PyBytes_FromString           PyString_FromString
  #define PyBytes_FromStringAndSize    PyString_FromStringAndSize
  #define PyBytes_FromFormat           PyString_FromFormat
  #define PyBytes_DecodeEscape         PyString_DecodeEscape
  #define PyBytes_AsString             PyString_AsString
  #define PyBytes_AsStringAndSize      PyString_AsStringAndSize
  #define PyBytes_Size                 PyString_Size
  #define PyBytes_AS_STRING            PyString_AS_STRING
  #define PyBytes_GET_SIZE             PyString_GET_SIZE
  #define PyBytes_Repr                 PyString_Repr
  #define PyBytes_Concat               PyString_Concat
  #define PyBytes_ConcatAndDel         PyString_ConcatAndDel
#endif
#if PY_VERSION_HEX < 0x02060000
  #define PySet_Check(obj)             PyObject_TypeCheck(obj, &PySet_Type)
  #define PyFrozenSet_Check(obj)       PyObject_TypeCheck(obj, &PyFrozenSet_Type)
#endif
#ifndef PySet_CheckExact
  #define PySet_CheckExact(obj)        (Py_TYPE(obj) == &PySet_Type)
#endif
#define __Pyx_TypeCheck(obj, type) PyObject_TypeCheck(obj, (PyTypeObject *)type)
#if PY_MAJOR_VERSION >= 3
  #define PyIntObject                  PyLongObject
  #define PyInt_Type                   PyLong_Type
  #define PyInt_Check(op)              PyLong_Check(op)
  #define PyInt_CheckExact(op)         PyLong_CheckExact(op)
  #define PyInt_FromString             PyLong_FromString
  #define PyInt_FromUnicode            PyLong_FromUnicode
  #define PyInt_FromLong               PyLong_FromLong
  #define PyInt_FromSize_t             PyLong_FromSize_t
  #define PyInt_FromSsize_t            PyLong_FromSsize_t
  #define PyInt_AsLong                 PyLong_AsLong
  #define PyInt_AS_LONG                PyLong_AS_LONG
  #define PyInt_AsSsize_t              PyLong_AsSsize_t
  #define PyInt_AsUnsignedLongMask     PyLong_AsUnsignedLongMask
  #define PyInt_AsUnsignedLongLongMask PyLong_AsUnsignedLongLongMask
#endif
#if PY_MAJOR_VERSION >= 3
  #define PyBoolObject                 PyLongObject
#endif
#if PY_VERSION_HEX < 0x03020000
  typedef long Py_hash_t;
  #define __Pyx_PyInt_FromHash_t PyInt_FromLong
  #define __Pyx_PyInt_AsHash_t   PyInt_AsLong
#else
  #define __Pyx_PyInt_FromHash_t PyInt_FromSsize_t
  #define __Pyx_PyInt_AsHash_t   PyInt_AsSsize_t
#endif
#if (PY_MAJOR_VERSION < 3) || (PY_VERSION_HEX >= 0x03010300)
  #define __Pyx_PySequence_GetSlice(obj, a, b) PySequence_GetSlice(obj, a, b)
  #define __Pyx_PySequence_SetSlice(obj, a, b, value) PySequence_SetSlice(obj, a, b, value)
  #define __Pyx_PySequence_DelSlice(obj, a, b) PySequence_DelSlice(obj, a, b)
#else
  #define __Pyx_PySequence_GetSlice(obj, a, b) (unlikely(!(obj)) ? \
        (PyErr_SetString(PyExc_SystemError, "null argument to internal routine"), (PyObject*)0) : \
        (likely((obj)->ob_type->tp_as_mapping) ? (PySequence_GetSlice(obj, a, b)) : \
            (PyErr_Format(PyExc_TypeError, "'%.200s' object is unsliceable", (obj)->ob_type->tp_name), (PyObject*)0)))
  #define __Pyx_PySequence_SetSlice(obj, a, b, value) (unlikely(!(obj)) ? \
        (PyErr_SetString(PyExc_SystemError, "null argument to internal routine"), -1) : \
        (likely((obj)->ob_type->tp_as_mapping) ? (PySequence_SetSlice(obj, a, b, value)) : \
            (PyErr_Format(PyExc_TypeError, "'%.200s' object doesn't support slice assignment", (obj)->ob_type->tp_name), -1)))
  #define __Pyx_PySequence_DelSlice(obj, a, b) (unlikely(!(obj)) ? \
        (PyErr_SetString(PyExc_SystemError, "null argument to internal routine"), -1) : \
        (likely((obj)->ob_type->tp_as_mapping) ? (PySequence_DelSlice(obj, a, b)) : \
            (PyErr_Format(PyExc_TypeError, "'%.200s' object doesn't support slice deletion", (obj)->ob_type->tp_name), -1)))
#endif
#if PY_MAJOR_VERSION >= 3
  #define PyMethod_New(func, self, klass) ((self) ? PyMethod_New(func, self) : PyInstanceMethod_New(func))
#endif
#if PY_VERSION_HEX < 0x02050000
  #define __Pyx_GetAttrString(o,n)   PyObject_GetAttrString((o),((char *)(n)))
  #define __Pyx_SetAttrString(o,n,a) PyObject_SetAttrString((o),((char *)(n)),(a))
  #define __Pyx_DelAttrString(o,n)   PyObject_DelAttrString((o),((char *)(n)))
#else
  #define __Pyx_GetAttrString(o,n)   PyObject_GetAttrString((o),(n))
  #define __Pyx_SetAttrString(o,n,a) PyObject_SetAttrString((o),(n),(a))
  #define __Pyx_DelAttrString(o,n)   PyObject_DelAttrString((o),(n))
#endif
#if PY_VERSION_HEX < 0x02050000
  #define __Pyx_NAMESTR(n) ((char *)(n))
  #define __Pyx_DOCSTR(n)  ((char *)(n))
#else
  #define __Pyx_NAMESTR(n) (n)
  #define __Pyx_DOCSTR(n)  (n)
#endif


#if PY_MAJOR_VERSION >= 3
  #define __Pyx_PyNumber_Divide(x,y)         PyNumber_TrueDivide(x,y)
  #define __Pyx_PyNumber_InPlaceDivide(x,y)  PyNumber_InPlaceTrueDivide(x,y)
#else
  #define __Pyx_PyNumber_Divide(x,y)         PyNumber_Divide(x,y)
  #define __Pyx_PyNumber_InPlaceDivide(x,y)  PyNumber_InPlaceDivide(x,y)
#endif

#ifndef __PYX_EXTERN_C
  #ifdef __cplusplus
    #define __PYX_EXTERN_C extern "C"
  #else
    #define __PYX_EXTERN_C extern
  #endif
#endif

#if defined(WIN32) || defined(MS_WINDOWS)
#define _USE_MATH_DEFINES
#endif
#include <math.h>
#define __PYX_HAVE__g2clib
#define __PYX_HAVE_API__g2clib
#include "stdlib.h"
#include "inttypes.h"
#include "grib2.h"
#ifdef _OPENMP
#include <omp.h>
#endif /* _OPENMP */

#ifdef PYREX_WITHOUT_ASSERTIONS
#define CYTHON_WITHOUT_ASSERTIONS
#endif


/* inline attribute */
#ifndef CYTHON_INLINE
  #if defined(__GNUC__)
    #define CYTHON_INLINE __inline__
  #elif defined(_MSC_VER)
    #define CYTHON_INLINE __inline
  #elif defined (__STDC_VERSION__) && __STDC_VERSION__ >= 199901L
    #define CYTHON_INLINE inline
  #else
    #define CYTHON_INLINE
  #endif
#endif

/* unused attribute */
#ifndef CYTHON_UNUSED
# if defined(__GNUC__)
#   if !(defined(__cplusplus)) || (__GNUC__ > 3 || (__GNUC__ == 3 && __GNUC_MINOR__ >= 4))
#     define CYTHON_UNUSED __attribute__ ((__unused__))
#   else
#     define CYTHON_UNUSED
#   endif
# elif defined(__ICC) || (defined(__INTEL_COMPILER) && !defined(_MSC_VER))
#   define CYTHON_UNUSED __attribute__ ((__unused__))
# else
#   define CYTHON_UNUSED
# endif
#endif

typedef struct {PyObject **p; char *s; const long n; const char* encoding; const char is_unicode; const char is_str; const char intern; } __Pyx_StringTabEntry; /*proto*/


/* Type Conversion Predeclarations */

#define __Pyx_PyBytes_FromUString(s) PyBytes_FromString((char*)s)
#define __Pyx_PyBytes_AsUString(s)   ((unsigned char*) PyBytes_AsString(s))

#define __Pyx_Owned_Py_None(b) (Py_INCREF(Py_None), Py_None)
#define __Pyx_PyBool_FromLong(b) ((b) ? (Py_INCREF(Py_True), Py_True) : (Py_INCREF(Py_False), Py_False))
static CYTHON_INLINE int __Pyx_PyObject_IsTrue(PyObject*);
static CYTHON_INLINE PyObject* __Pyx_PyNumber_Int(PyObject* x);

static CYTHON_INLINE Py_ssize_t __Pyx_PyIndex_AsSsize_t(PyObject*);
static CYTHON_INLINE PyObject * __Pyx_PyInt_FromSize_t(size_t);
static CYTHON_INLINE size_t __Pyx_PyInt_AsSize_t(PyObject*);

#if CYTHON_COMPILING_IN_CPYTHON
#define __pyx_PyFloat_AsDouble(x) (PyFloat_CheckExact(x) ? PyFloat_AS_DOUBLE(x) : PyFloat_AsDouble(x))
#else
#define __pyx_PyFloat_AsDouble(x) PyFloat_AsDouble(x)
#endif
#define __pyx_PyFloat_AsFloat(x) ((float) __pyx_PyFloat_AsDouble(x))

#ifdef __GNUC__
  /* Test for GCC > 2.95 */
  #if __GNUC__ > 2 || (__GNUC__ == 2 && (__GNUC_MINOR__ > 95))
    #define likely(x)   __builtin_expect(!!(x), 1)
    #define unlikely(x) __builtin_expect(!!(x), 0)
  #else /* __GNUC__ > 2 ... */
    #define likely(x)   (x)
    #define unlikely(x) (x)
  #endif /* __GNUC__ > 2 ... */
#else /* __GNUC__ */
  #define likely(x)   (x)
  #define unlikely(x) (x)
#endif /* __GNUC__ */
    
static PyObject *__pyx_m;
static PyObject *__pyx_b;
static PyObject *__pyx_empty_tuple;
static PyObject *__pyx_empty_bytes;
static int __pyx_lineno;
static int __pyx_clineno = 0;
static const char * __pyx_cfilenm= __FILE__;
static const char *__pyx_filename;


static const char *__pyx_f[] = {
  "g2clib.pyx",
};

/*--- Type declarations ---*/
#ifndef CYTHON_REFNANNY
  #define CYTHON_REFNANNY 0
#endif
#if CYTHON_REFNANNY
  typedef struct {
    void (*INCREF)(void*, PyObject*, int);
    void (*DECREF)(void*, PyObject*, int);
    void (*GOTREF)(void*, PyObject*, int);
    void (*GIVEREF)(void*, PyObject*, int);
    void* (*SetupContext)(const char*, int, const char*);
    void (*FinishContext)(void**);
  } __Pyx_RefNannyAPIStruct;
  static __Pyx_RefNannyAPIStruct *__Pyx_RefNanny = NULL;
  static __Pyx_RefNannyAPIStruct *__Pyx_RefNannyImportAPI(const char *modname); /*proto*/
  #define __Pyx_RefNannyDeclarations void *__pyx_refnanny = NULL;
#ifdef WITH_THREAD
  #define __Pyx_RefNannySetupContext(name, acquire_gil) \
          if (acquire_gil) { \
              PyGILState_STATE __pyx_gilstate_save = PyGILState_Ensure(); \
              __pyx_refnanny = __Pyx_RefNanny->SetupContext((name), __LINE__, __FILE__); \
              PyGILState_Release(__pyx_gilstate_save); \
          } else { \
              __pyx_refnanny = __Pyx_RefNanny->SetupContext((name), __LINE__, __FILE__); \
          }
#else
  #define __Pyx_RefNannySetupContext(name, acquire_gil) \
          __pyx_refnanny = __Pyx_RefNanny->SetupContext((name), __LINE__, __FILE__)
#endif
  #define __Pyx_RefNannyFinishContext() \
          __Pyx_RefNanny->FinishContext(&__pyx_refnanny)
  #define __Pyx_INCREF(r)  __Pyx_RefNanny->INCREF(__pyx_refnanny, (PyObject *)(r), __LINE__)
  #define __Pyx_DECREF(r)  __Pyx_RefNanny->DECREF(__pyx_refnanny, (PyObject *)(r), __LINE__)
  #define __Pyx_GOTREF(r)  __Pyx_RefNanny->GOTREF(__pyx_refnanny, (PyObject *)(r), __LINE__)
  #define __Pyx_GIVEREF(r) __Pyx_RefNanny->GIVEREF(__pyx_refnanny, (PyObject *)(r), __LINE__)
  #define __Pyx_XINCREF(r)  do { if((r) != NULL) {__Pyx_INCREF(r); }} while(0)
  #define __Pyx_XDECREF(r)  do { if((r) != NULL) {__Pyx_DECREF(r); }} while(0)
  #define __Pyx_XGOTREF(r)  do { if((r) != NULL) {__Pyx_GOTREF(r); }} while(0)
  #define __Pyx_XGIVEREF(r) do { if((r) != NULL) {__Pyx_GIVEREF(r);}} while(0)
#else
  #define __Pyx_RefNannyDeclarations
  #define __Pyx_RefNannySetupContext(name, acquire_gil)
  #define __Pyx_RefNannyFinishContext()
  #define __Pyx_INCREF(r) Py_INCREF(r)
  #define __Pyx_DECREF(r) Py_DECREF(r)
  #define __Pyx_GOTREF(r)
  #define __Pyx_GIVEREF(r)
  #define __Pyx_XINCREF(r) Py_XINCREF(r)
  #define __Pyx_XDECREF(r) Py_XDECREF(r)
  #define __Pyx_XGOTREF(r)
  #define __Pyx_XGIVEREF(r)
#endif /* CYTHON_REFNANNY */
#define __Pyx_CLEAR(r)    do { PyObject* tmp = ((PyObject*)(r)); r = NULL; __Pyx_DECREF(tmp);} while(0)
#define __Pyx_XCLEAR(r)   do { if((r) != NULL) {PyObject* tmp = ((PyObject*)(r)); r = NULL; __Pyx_DECREF(tmp);}} while(0)

static PyObject *__Pyx_GetName(PyObject *dict, PyObject *name); /*proto*/

static void __Pyx_RaiseArgtupleInvalid(const char* func_name, int exact,
    Py_ssize_t num_min, Py_ssize_t num_max, Py_ssize_t num_found); /*proto*/

static void __Pyx_RaiseDoubleKeywordsError(const char* func_name, PyObject* kw_name); /*proto*/

static int __Pyx_ParseOptionalKeywords(PyObject *kwds, PyObject **argnames[], \
    PyObject *kwds2, PyObject *values[], Py_ssize_t num_pos_args, \
    const char* function_name); /*proto*/

static CYTHON_INLINE void __Pyx_ErrRestore(PyObject *type, PyObject *value, PyObject *tb); /*proto*/
static CYTHON_INLINE void __Pyx_ErrFetch(PyObject **type, PyObject **value, PyObject **tb); /*proto*/

static void __Pyx_Raise(PyObject *type, PyObject *value, PyObject *tb, PyObject *cause); /*proto*/

static CYTHON_INLINE Py_ssize_t __Pyx_div_Py_ssize_t(Py_ssize_t, Py_ssize_t); /* proto */

static CYTHON_INLINE long __Pyx_div_long(long, long); /* proto */

static CYTHON_INLINE PyObject *__Pyx_GetItemInt_Generic(PyObject *o, PyObject* j) {
    PyObject *r;
    if (!j) return NULL;
    r = PyObject_GetItem(o, j);
    Py_DECREF(j);
    return r;
}
#define __Pyx_GetItemInt_List(o, i, size, to_py_func) (((size) <= sizeof(Py_ssize_t)) ? \
                                                    __Pyx_GetItemInt_List_Fast(o, i) : \
                                                    __Pyx_GetItemInt_Generic(o, to_py_func(i)))
static CYTHON_INLINE PyObject *__Pyx_GetItemInt_List_Fast(PyObject *o, Py_ssize_t i) {
#if CYTHON_COMPILING_IN_CPYTHON
    if (likely((0 <= i) & (i < PyList_GET_SIZE(o)))) {
        PyObject *r = PyList_GET_ITEM(o, i);
        Py_INCREF(r);
        return r;
    }
    else if ((-PyList_GET_SIZE(o) <= i) & (i < 0)) {
        PyObject *r = PyList_GET_ITEM(o, PyList_GET_SIZE(o) + i);
        Py_INCREF(r);
        return r;
    }
    return __Pyx_GetItemInt_Generic(o, PyInt_FromSsize_t(i));
#else
    return PySequence_GetItem(o, i);
#endif
}
#define __Pyx_GetItemInt_Tuple(o, i, size, to_py_func) (((size) <= sizeof(Py_ssize_t)) ? \
                                                    __Pyx_GetItemInt_Tuple_Fast(o, i) : \
                                                    __Pyx_GetItemInt_Generic(o, to_py_func(i)))
static CYTHON_INLINE PyObject *__Pyx_GetItemInt_Tuple_Fast(PyObject *o, Py_ssize_t i) {
#if CYTHON_COMPILING_IN_CPYTHON
    if (likely((0 <= i) & (i < PyTuple_GET_SIZE(o)))) {
        PyObject *r = PyTuple_GET_ITEM(o, i);
        Py_INCREF(r);
        return r;
    }
    else if ((-PyTuple_GET_SIZE(o) <= i) & (i < 0)) {
        PyObject *r = PyTuple_GET_ITEM(o, PyTuple_GET_SIZE(o) + i);
        Py_INCREF(r);
        return r;
    }
    return __Pyx_GetItemInt_Generic(o, PyInt_FromSsize_t(i));
#else
    return PySequence_GetItem(o, i);
#endif
}
#define __Pyx_GetItemInt(o, i, size, to_py_func) (((size) <= sizeof(Py_ssize_t)) ? \
                                                    __Pyx_GetItemInt_Fast(o, i) : \
                                                    __Pyx_GetItemInt_Generic(o, to_py_func(i)))
static CYTHON_INLINE PyObject *__Pyx_GetItemInt_Fast(PyObject *o, Py_ssize_t i) {
#if CYTHON_COMPILING_IN_CPYTHON
    if (PyList_CheckExact(o)) {
        Py_ssize_t n = (likely(i >= 0)) ? i : i + PyList_GET_SIZE(o);
        if (likely((n >= 0) & (n < PyList_GET_SIZE(o)))) {
            PyObject *r = PyList_GET_ITEM(o, n);
            Py_INCREF(r);
            return r;
        }
    }
    else if (PyTuple_CheckExact(o)) {
        Py_ssize_t n = (likely(i >= 0)) ? i : i + PyTuple_GET_SIZE(o);
        if (likely((n >= 0) & (n < PyTuple_GET_SIZE(o)))) {
            PyObject *r = PyTuple_GET_ITEM(o, n);
            Py_INCREF(r);
            return r;
        }
    } else {  /* inlined PySequence_GetItem() */
        PySequenceMethods *m = Py_TYPE(o)->tp_as_sequence;
        if (likely(m && m->sq_item)) {
            if (unlikely(i < 0) && likely(m->sq_length)) {
                Py_ssize_t l = m->sq_length(o);
                if (unlikely(l < 0)) return NULL;
                i += l;
            }
            return m->sq_item(o, i);
        }
    }
#else
    if (PySequence_Check(o)) {
        return PySequence_GetItem(o, i);
    }
#endif
    return __Pyx_GetItemInt_Generic(o, PyInt_FromSsize_t(i));
}

static PyObject *__Pyx_Import(PyObject *name, PyObject *from_list, long level); /*proto*/

static CYTHON_INLINE PyObject *__Pyx_PyInt_to_py_int32_t(int32_t);

static int __Pyx_Print(PyObject*, PyObject *, int); /*proto*/
#if CYTHON_COMPILING_IN_PYPY || PY_MAJOR_VERSION >= 3
static PyObject* __pyx_print = 0;
static PyObject* __pyx_print_kwargs = 0;
#endif

static int __Pyx_PrintOne(PyObject* stream, PyObject *o); /*proto*/

static CYTHON_INLINE unsigned char __Pyx_PyInt_AsUnsignedChar(PyObject *);

static CYTHON_INLINE unsigned short __Pyx_PyInt_AsUnsignedShort(PyObject *);

static CYTHON_INLINE unsigned int __Pyx_PyInt_AsUnsignedInt(PyObject *);

static CYTHON_INLINE char __Pyx_PyInt_AsChar(PyObject *);

static CYTHON_INLINE short __Pyx_PyInt_AsShort(PyObject *);

static CYTHON_INLINE int __Pyx_PyInt_AsInt(PyObject *);

static CYTHON_INLINE signed char __Pyx_PyInt_AsSignedChar(PyObject *);

static CYTHON_INLINE signed short __Pyx_PyInt_AsSignedShort(PyObject *);

static CYTHON_INLINE signed int __Pyx_PyInt_AsSignedInt(PyObject *);

static CYTHON_INLINE int __Pyx_PyInt_AsLongDouble(PyObject *);

static CYTHON_INLINE unsigned long __Pyx_PyInt_AsUnsignedLong(PyObject *);

static CYTHON_INLINE unsigned PY_LONG_LONG __Pyx_PyInt_AsUnsignedLongLong(PyObject *);

static CYTHON_INLINE long __Pyx_PyInt_AsLong(PyObject *);

static CYTHON_INLINE PY_LONG_LONG __Pyx_PyInt_AsLongLong(PyObject *);

static CYTHON_INLINE signed long __Pyx_PyInt_AsSignedLong(PyObject *);

static CYTHON_INLINE signed PY_LONG_LONG __Pyx_PyInt_AsSignedLongLong(PyObject *);

static int __Pyx_check_binary_version(void);

typedef struct {
    int code_line;
    PyCodeObject* code_object;
} __Pyx_CodeObjectCacheEntry;
struct __Pyx_CodeObjectCache {
    int count;
    int max_count;
    __Pyx_CodeObjectCacheEntry* entries;
};
static struct __Pyx_CodeObjectCache __pyx_code_cache = {0,0,NULL};
static int __pyx_bisect_code_objects(__Pyx_CodeObjectCacheEntry* entries, int count, int code_line);
static PyCodeObject *__pyx_find_code_object(int code_line);
static void __pyx_insert_code_object(int code_line, PyCodeObject* code_object);

static void __Pyx_AddTraceback(const char *funcname, int c_line,
                               int py_line, const char *filename); /*proto*/

static int __Pyx_InitStrings(__Pyx_StringTabEntry *t); /*proto*/


/* Module declarations from 'g2clib' */
static PyObject *__pyx_f_6g2clib__toarray(void *, PyObject *); /*proto*/
#define __Pyx_MODULE_NAME "g2clib"
int __pyx_module_is_main_g2clib = 0;

/* Implementation of 'g2clib' */
static PyObject *__pyx_builtin_RuntimeError;
static PyObject *__pyx_pf_6g2clib_rtoi_ieee(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_rarr, PyObject *__pyx_v_iarr); /* proto */
static PyObject *__pyx_pf_6g2clib_2itor_ieee(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_iarr, PyObject *__pyx_v_rarr); /* proto */
static PyObject *__pyx_pf_6g2clib_4unpack1(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_gribmsg, PyObject *__pyx_v_ipos, PyObject *__pyx_v_zeros); /* proto */
static PyObject *__pyx_pf_6g2clib_6unpack3(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_gribmsg, PyObject *__pyx_v_ipos, PyObject *__pyx_v_zeros); /* proto */
static PyObject *__pyx_pf_6g2clib_8unpack4(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_gribmsg, PyObject *__pyx_v_ipos, PyObject *__pyx_v_zeros); /* proto */
static PyObject *__pyx_pf_6g2clib_10unpack5(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_gribmsg, PyObject *__pyx_v_ipos, PyObject *__pyx_v_zeros); /* proto */
static PyObject *__pyx_pf_6g2clib_12unpack6(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_gribmsg, PyObject *__pyx_v_ndpts, PyObject *__pyx_v_ipos, PyObject *__pyx_v_zeros); /* proto */
static PyObject *__pyx_pf_6g2clib_14unpack7(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_gribmsg, PyObject *__pyx_v_gdtnum, PyObject *__pyx_v_gdtmpl, PyObject *__pyx_v_drtnum, PyObject *__pyx_v_drtmpl, PyObject *__pyx_v_ndpts, PyObject *__pyx_v_ipos, PyObject *__pyx_v_zeros, PyObject *__pyx_v_printminmax, PyObject *__pyx_v_storageorder); /* proto */
static PyObject *__pyx_pf_6g2clib_16grib2_create(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_listsec0, PyObject *__pyx_v_listsec1); /* proto */
static PyObject *__pyx_pf_6g2clib_18grib2_end(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_gribmsg); /* proto */
static PyObject *__pyx_pf_6g2clib_20grib2_addgrid(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_gribmsg, PyObject *__pyx_v_gds, PyObject *__pyx_v_gdstmpl, PyObject *__pyx_v_deflist, CYTHON_UNUSED PyObject *__pyx_v_defnum); /* proto */
static PyObject *__pyx_pf_6g2clib_22grib2_addfield(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_gribmsg, PyObject *__pyx_v_pdsnum, PyObject *__pyx_v_pdstmpl, PyObject *__pyx_v_coordlist, PyObject *__pyx_v_drsnum, PyObject *__pyx_v_drstmpl, PyObject *__pyx_v_field, PyObject *__pyx_v_ibitmap, PyObject *__pyx_v_bitmap); /* proto */
static char __pyx_k_1[] = "error getting buffer for input real array";
static char __pyx_k_2[] = "error getting buffer for output integer array";
static char __pyx_k_3[] = "integer output array must be as least as long a real input array";
static char __pyx_k_4[] = "error getting buffer for output real array";
static char __pyx_k_5[] = "error getting buffer for input integer array";
static char __pyx_k_6[] = "real output array must be as least as long a integerinput array";
static char __pyx_k_7[] = "unknown array type %s";
static char __pyx_k_8[] = "Error unpacking section 1 - error code = %i";
static char __pyx_k_9[] = "Error unpacking section 3 - error code = %i";
static char __pyx_k_11[] = "Error unpacking section 4 - error code = %i";
static char __pyx_k_12[] = "Error unpacking section 5 - error code = %i";
static char __pyx_k_13[] = "Error unpacking section 6 - error code = %i";
static char __pyx_k_15[] = "Error unpacking section 7 - error code = %i";
static char __pyx_k_16[] = "%.";
static char __pyx_k_17[] = "min/max=";
static char __pyx_k_18[] = "/";
static char __pyx_k_19[] = " ";
static char __pyx_k_20[] = "Error in grib2_create, error code = %i";
static char __pyx_k_21[] = "        ";
static char __pyx_k_22[] = "error in grib2_end, error code = %i";
static char __pyx_k_23[] = "error in grib2_addgrid, error code = %i";
static char __pyx_k_24[] = "error in grib2_addfield, error code = %i";
static char __pyx_k_25[] = "Pyrex code to provide python interfaces to functions\nin the NCEP grib2c library. Make changes to this file, not the\nc-wrappers that Pyrex generates.";
static char __pyx_k_28[] = "/Users/jsw/python/pygrib/g2clib.pyx";
static char __pyx_k__C[] = "C";
static char __pyx_k__g[] = "g";
static char __pyx_k__i[] = "i";
static char __pyx_k__n[] = "n";
static char __pyx_k__f4[] = "f4";
static char __pyx_k__i1[] = "i1";
static char __pyx_k__i4[] = "i4";
static char __pyx_k__r1[] = "r1";
static char __pyx_k__fld[] = "fld";
static char __pyx_k__gds[] = "gds";
static char __pyx_k__ids[] = "ids";
static char __pyx_k__msg[] = "msg";
static char __pyx_k__pow[] = "pow";
static char __pyx_k__bmap[] = "bmap";
static char __pyx_k__ceil[] = "ceil";
static char __pyx_k__data[] = "data";
static char __pyx_k__iarr[] = "iarr";
static char __pyx_k__idat[] = "idat";
static char __pyx_k__ierr[] = "ierr";
static char __pyx_k__igds[] = "igds";
static char __pyx_k__ipos[] = "ipos";
static char __pyx_k__math[] = "math";
static char __pyx_k__rarr[] = "rarr";
static char __pyx_k__rdat[] = "rdat";
static char __pyx_k__rmax[] = "rmax";
static char __pyx_k__rmin[] = "rmin";
static char __pyx_k__cgrib[] = "cgrib";
static char __pyx_k__dtype[] = "dtype";
static char __pyx_k__field[] = "field";
static char __pyx_k__ibmap[] = "ibmap";
static char __pyx_k__idata[] = "idata";
static char __pyx_k__int32[] = "int32";
static char __pyx_k__iofst[] = "iofst";
static char __pyx_k__isec0[] = "isec0";
static char __pyx_k__isec1[] = "isec1";
static char __pyx_k__lgrib[] = "lgrib";
static char __pyx_k__log10[] = "log10";
static char __pyx_k__ndpts[] = "ndpts";
static char __pyx_k__ngpts[] = "ngpts";
static char __pyx_k__order[] = "order";
static char __pyx_k__rdata[] = "rdata";
static char __pyx_k__zeros[] = "zeros";
static char __pyx_k__bitmap[] = "bitmap";
static char __pyx_k__buflen[] = "buflen";
static char __pyx_k__defnum[] = "defnum";
static char __pyx_k__drsnum[] = "drsnum";
static char __pyx_k__drtmpl[] = "drtmpl";
static char __pyx_k__drtnum[] = "drtnum";
static char __pyx_k__fldmax[] = "fldmax";
static char __pyx_k__fldmin[] = "fldmin";
static char __pyx_k__format[] = "format";
static char __pyx_k__g2clib[] = "g2clib";
static char __pyx_k__gdsdat[] = "gdsdat";
static char __pyx_k__gdtmpl[] = "gdtmpl";
static char __pyx_k__gdtnum[] = "gdtnum";
static char __pyx_k__idsect[] = "idsect";
static char __pyx_k__idslen[] = "idslen";
static char __pyx_k__pdsnum[] = "pdsnum";
static char __pyx_k__pdtmpl[] = "pdtmpl";
static char __pyx_k__bufleni[] = "bufleni";
static char __pyx_k__buflenr[] = "buflenr";
static char __pyx_k__deflist[] = "deflist";
static char __pyx_k__drstmpl[] = "drstmpl";
static char __pyx_k__float32[] = "float32";
static char __pyx_k__gdstmpl[] = "gdstmpl";
static char __pyx_k__gribmsg[] = "gribmsg";
static char __pyx_k__ibitmap[] = "ibitmap";
static char __pyx_k__idefnum[] = "idefnum";
static char __pyx_k__idrsnum[] = "idrsnum";
static char __pyx_k__igdsnum[] = "igdsnum";
static char __pyx_k__ipdsnum[] = "ipdsnum";
static char __pyx_k__ngrdpts[] = "ngrdpts";
static char __pyx_k__pdstmpl[] = "pdstmpl";
static char __pyx_k__unpack1[] = "unpack1";
static char __pyx_k__unpack3[] = "unpack3";
static char __pyx_k__unpack4[] = "unpack4";
static char __pyx_k__unpack5[] = "unpack5";
static char __pyx_k__unpack6[] = "unpack6";
static char __pyx_k__unpack7[] = "unpack7";
static char __pyx_k____main__[] = "__main__";
static char __pyx_k____test__[] = "__test__";
static char __pyx_k__fielddat[] = "fielddat";
static char __pyx_k__ideflist[] = "ideflist";
static char __pyx_k__idrstmpl[] = "idrstmpl";
static char __pyx_k__igdstmpl[] = "igdstmpl";
static char __pyx_k__ipdstmpl[] = "ipdstmpl";
static char __pyx_k__listsec0[] = "listsec0";
static char __pyx_k__listsec1[] = "listsec1";
static char __pyx_k__numcoord[] = "numcoord";
static char __pyx_k__bitmapdat[] = "bitmapdat";
static char __pyx_k__coordlist[] = "coordlist";
static char __pyx_k__drtmpldat[] = "drtmpldat";
static char __pyx_k__gdtmpldat[] = "gdtmpldat";
static char __pyx_k__grib2_end[] = "grib2_end";
static char __pyx_k__itor_ieee[] = "itor_ieee";
static char __pyx_k__mapdrslen[] = "mapdrslen";
static char __pyx_k__mappdslen[] = "mappdslen";
static char __pyx_k__pdtmpldat[] = "pdtmpldat";
static char __pyx_k__rtoi_ieee[] = "rtoi_ieee";
static char __pyx_k__deflistdat[] = "deflistdat";
static char __pyx_k__fcoordlist[] = "fcoordlist";
static char __pyx_k__gdstmpldat[] = "gdstmpldat";
static char __pyx_k__icoordlist[] = "icoordlist";
static char __pyx_k__mapgridlen[] = "mapgridlen";
static char __pyx_k__listsec0dat[] = "listsec0dat";
static char __pyx_k__listsec1dat[] = "listsec1dat";
static char __pyx_k__printminmax[] = "printminmax";
static char __pyx_k__RuntimeError[] = "RuntimeError";
static char __pyx_k__coordlistdat[] = "coordlistdat";
static char __pyx_k__grib2_create[] = "grib2_create";
static char __pyx_k__minmaxstring[] = "minmaxstring";
static char __pyx_k__storageorder[] = "storageorder";
static char __pyx_k__grib2_addgrid[] = "grib2_addgrid";
static char __pyx_k__grib2_addfield[] = "grib2_addfield";
static char __pyx_k__bitsofprecision[] = "bitsofprecision";
static char __pyx_k__digitsofprecision[] = "digitsofprecision";
static PyObject *__pyx_kp_s_1;
static PyObject *__pyx_kp_s_11;
static PyObject *__pyx_kp_s_12;
static PyObject *__pyx_kp_s_13;
static PyObject *__pyx_kp_s_15;
static PyObject *__pyx_kp_s_16;
static PyObject *__pyx_kp_s_17;
static PyObject *__pyx_kp_s_18;
static PyObject *__pyx_kp_b_19;
static PyObject *__pyx_kp_s_2;
static PyObject *__pyx_kp_s_20;
static PyObject *__pyx_kp_b_21;
static PyObject *__pyx_kp_s_22;
static PyObject *__pyx_kp_s_23;
static PyObject *__pyx_kp_s_24;
static PyObject *__pyx_kp_s_28;
static PyObject *__pyx_kp_s_3;
static PyObject *__pyx_kp_s_4;
static PyObject *__pyx_kp_s_5;
static PyObject *__pyx_kp_s_6;
static PyObject *__pyx_kp_s_7;
static PyObject *__pyx_kp_s_8;
static PyObject *__pyx_kp_s_9;
static PyObject *__pyx_n_s__C;
static PyObject *__pyx_n_s__RuntimeError;
static PyObject *__pyx_n_s____main__;
static PyObject *__pyx_n_s____test__;
static PyObject *__pyx_n_s__bitmap;
static PyObject *__pyx_n_s__bitmapdat;
static PyObject *__pyx_n_s__bitsofprecision;
static PyObject *__pyx_n_s__bmap;
static PyObject *__pyx_n_s__buflen;
static PyObject *__pyx_n_s__bufleni;
static PyObject *__pyx_n_s__buflenr;
static PyObject *__pyx_n_s__ceil;
static PyObject *__pyx_n_s__cgrib;
static PyObject *__pyx_n_s__coordlist;
static PyObject *__pyx_n_s__coordlistdat;
static PyObject *__pyx_n_s__data;
static PyObject *__pyx_n_s__deflist;
static PyObject *__pyx_n_s__deflistdat;
static PyObject *__pyx_n_s__defnum;
static PyObject *__pyx_n_s__digitsofprecision;
static PyObject *__pyx_n_s__drsnum;
static PyObject *__pyx_n_s__drstmpl;
static PyObject *__pyx_n_s__drtmpl;
static PyObject *__pyx_n_s__drtmpldat;
static PyObject *__pyx_n_s__drtnum;
static PyObject *__pyx_n_s__dtype;
static PyObject *__pyx_n_s__f4;
static PyObject *__pyx_n_s__fcoordlist;
static PyObject *__pyx_n_s__field;
static PyObject *__pyx_n_s__fielddat;
static PyObject *__pyx_n_s__fld;
static PyObject *__pyx_n_s__fldmax;
static PyObject *__pyx_n_s__fldmin;
static PyObject *__pyx_n_s__float32;
static PyObject *__pyx_n_s__format;
static PyObject *__pyx_n_s__g;
static PyObject *__pyx_n_s__g2clib;
static PyObject *__pyx_n_s__gds;
static PyObject *__pyx_n_s__gdsdat;
static PyObject *__pyx_n_s__gdstmpl;
static PyObject *__pyx_n_s__gdstmpldat;
static PyObject *__pyx_n_s__gdtmpl;
static PyObject *__pyx_n_s__gdtmpldat;
static PyObject *__pyx_n_s__gdtnum;
static PyObject *__pyx_n_s__grib2_addfield;
static PyObject *__pyx_n_s__grib2_addgrid;
static PyObject *__pyx_n_s__grib2_create;
static PyObject *__pyx_n_s__grib2_end;
static PyObject *__pyx_n_s__gribmsg;
static PyObject *__pyx_n_s__i;
static PyObject *__pyx_n_s__i1;
static PyObject *__pyx_n_s__i4;
static PyObject *__pyx_n_s__iarr;
static PyObject *__pyx_n_s__ibitmap;
static PyObject *__pyx_n_s__ibmap;
static PyObject *__pyx_n_s__icoordlist;
static PyObject *__pyx_n_s__idat;
static PyObject *__pyx_n_s__idata;
static PyObject *__pyx_n_s__ideflist;
static PyObject *__pyx_n_s__idefnum;
static PyObject *__pyx_n_s__idrsnum;
static PyObject *__pyx_n_s__idrstmpl;
static PyObject *__pyx_n_s__ids;
static PyObject *__pyx_n_s__idsect;
static PyObject *__pyx_n_s__idslen;
static PyObject *__pyx_n_s__ierr;
static PyObject *__pyx_n_s__igds;
static PyObject *__pyx_n_s__igdsnum;
static PyObject *__pyx_n_s__igdstmpl;
static PyObject *__pyx_n_s__int32;
static PyObject *__pyx_n_s__iofst;
static PyObject *__pyx_n_s__ipdsnum;
static PyObject *__pyx_n_s__ipdstmpl;
static PyObject *__pyx_n_s__ipos;
static PyObject *__pyx_n_s__isec0;
static PyObject *__pyx_n_s__isec1;
static PyObject *__pyx_n_s__itor_ieee;
static PyObject *__pyx_n_s__lgrib;
static PyObject *__pyx_n_s__listsec0;
static PyObject *__pyx_n_s__listsec0dat;
static PyObject *__pyx_n_s__listsec1;
static PyObject *__pyx_n_s__listsec1dat;
static PyObject *__pyx_n_s__log10;
static PyObject *__pyx_n_s__mapdrslen;
static PyObject *__pyx_n_s__mapgridlen;
static PyObject *__pyx_n_s__mappdslen;
static PyObject *__pyx_n_s__math;
static PyObject *__pyx_n_s__minmaxstring;
static PyObject *__pyx_n_s__msg;
static PyObject *__pyx_n_s__n;
static PyObject *__pyx_n_s__ndpts;
static PyObject *__pyx_n_s__ngpts;
static PyObject *__pyx_n_s__ngrdpts;
static PyObject *__pyx_n_s__numcoord;
static PyObject *__pyx_n_s__order;
static PyObject *__pyx_n_s__pdsnum;
static PyObject *__pyx_n_s__pdstmpl;
static PyObject *__pyx_n_s__pdtmpl;
static PyObject *__pyx_n_s__pdtmpldat;
static PyObject *__pyx_n_s__pow;
static PyObject *__pyx_n_s__printminmax;
static PyObject *__pyx_n_s__r1;
static PyObject *__pyx_n_s__rarr;
static PyObject *__pyx_n_s__rdat;
static PyObject *__pyx_n_s__rdata;
static PyObject *__pyx_n_s__rmax;
static PyObject *__pyx_n_s__rmin;
static PyObject *__pyx_n_s__rtoi_ieee;
static PyObject *__pyx_n_s__storageorder;
static PyObject *__pyx_n_s__unpack1;
static PyObject *__pyx_n_s__unpack3;
static PyObject *__pyx_n_s__unpack4;
static PyObject *__pyx_n_s__unpack5;
static PyObject *__pyx_n_s__unpack6;
static PyObject *__pyx_n_s__unpack7;
static PyObject *__pyx_n_s__zeros;
static PyObject *__pyx_int_0;
static PyObject *__pyx_int_1;
static PyObject *__pyx_int_2;
static PyObject *__pyx_int_4;
static PyObject *__pyx_int_5;
static PyObject *__pyx_int_8;
static PyObject *__pyx_int_254;
static PyObject *__pyx_int_260;
static PyObject *__pyx_k_14;
static PyObject *__pyx_k_tuple_10;
static PyObject *__pyx_k_tuple_26;
static PyObject *__pyx_k_tuple_29;
static PyObject *__pyx_k_tuple_31;
static PyObject *__pyx_k_tuple_33;
static PyObject *__pyx_k_tuple_35;
static PyObject *__pyx_k_tuple_37;
static PyObject *__pyx_k_tuple_39;
static PyObject *__pyx_k_tuple_41;
static PyObject *__pyx_k_tuple_43;
static PyObject *__pyx_k_tuple_45;
static PyObject *__pyx_k_tuple_47;
static PyObject *__pyx_k_tuple_49;
static PyObject *__pyx_k_codeobj_27;
static PyObject *__pyx_k_codeobj_30;
static PyObject *__pyx_k_codeobj_32;
static PyObject *__pyx_k_codeobj_34;
static PyObject *__pyx_k_codeobj_36;
static PyObject *__pyx_k_codeobj_38;
static PyObject *__pyx_k_codeobj_40;
static PyObject *__pyx_k_codeobj_42;
static PyObject *__pyx_k_codeobj_44;
static PyObject *__pyx_k_codeobj_46;
static PyObject *__pyx_k_codeobj_48;
static PyObject *__pyx_k_codeobj_50;

/* Python wrapper */
static PyObject *__pyx_pw_6g2clib_1rtoi_ieee(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
static char __pyx_doc_6g2clib_rtoi_ieee[] = "\n Converts a float32 array into an int32 array of IEEE formatted values\n    ";
static PyMethodDef __pyx_mdef_6g2clib_1rtoi_ieee = {__Pyx_NAMESTR("rtoi_ieee"), (PyCFunction)__pyx_pw_6g2clib_1rtoi_ieee, METH_VARARGS|METH_KEYWORDS, __Pyx_DOCSTR(__pyx_doc_6g2clib_rtoi_ieee)};
static PyObject *__pyx_pw_6g2clib_1rtoi_ieee(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
  PyObject *__pyx_v_rarr = 0;
  PyObject *__pyx_v_iarr = 0;
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("rtoi_ieee (wrapper)", 0);
  {
    static PyObject **__pyx_pyargnames[] = {&__pyx_n_s__rarr,&__pyx_n_s__iarr,0};
    PyObject* values[2] = {0,0};
    if (unlikely(__pyx_kwds)) {
      Py_ssize_t kw_args;
      const Py_ssize_t pos_args = PyTuple_GET_SIZE(__pyx_args);
      switch (pos_args) {
        case  2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
        case  1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
        case  0: break;
        default: goto __pyx_L5_argtuple_error;
      }
      kw_args = PyDict_Size(__pyx_kwds);
      switch (pos_args) {
        case  0:
        if (likely((values[0] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__rarr)) != 0)) kw_args--;
        else goto __pyx_L5_argtuple_error;
        case  1:
        if (likely((values[1] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__iarr)) != 0)) kw_args--;
        else {
          __Pyx_RaiseArgtupleInvalid("rtoi_ieee", 1, 2, 2, 1); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 55; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
        }
      }
      if (unlikely(kw_args > 0)) {
        if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "rtoi_ieee") < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 55; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
      }
    } else if (PyTuple_GET_SIZE(__pyx_args) != 2) {
      goto __pyx_L5_argtuple_error;
    } else {
      values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
      values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
    }
    __pyx_v_rarr = values[0];
    __pyx_v_iarr = values[1];
  }
  goto __pyx_L4_argument_unpacking_done;
  __pyx_L5_argtuple_error:;
  __Pyx_RaiseArgtupleInvalid("rtoi_ieee", 1, 2, 2, PyTuple_GET_SIZE(__pyx_args)); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 55; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
  __pyx_L3_error:;
  __Pyx_AddTraceback("g2clib.rtoi_ieee", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __Pyx_RefNannyFinishContext();
  return NULL;
  __pyx_L4_argument_unpacking_done:;
  __pyx_r = __pyx_pf_6g2clib_rtoi_ieee(__pyx_self, __pyx_v_rarr, __pyx_v_iarr);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "g2clib.pyx":55
 * # routines for convert to/from IEEE integers.
 * 
 * def rtoi_ieee(object rarr, object iarr):             # <<<<<<<<<<<<<<
 *     """
 *  Converts a float32 array into an int32 array of IEEE formatted values
 */

static PyObject *__pyx_pf_6g2clib_rtoi_ieee(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_rarr, PyObject *__pyx_v_iarr) {
  void *__pyx_v_rdat;
  void *__pyx_v_idat;
  g2float *__pyx_v_rdata;
  g2int *__pyx_v_idata;
  Py_ssize_t __pyx_v_bufleni;
  Py_ssize_t __pyx_v_buflenr;
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  int __pyx_t_1;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("rtoi_ieee", 0);

  /* "g2clib.pyx":63
 *     cdef g2int *idata, i1
 *     cdef Py_ssize_t bufleni, buflenr
 *     if PyObject_AsReadBuffer(rarr, &rdat, &buflenr) <> 0:             # <<<<<<<<<<<<<<
 *         raise RuntimeError, 'error getting buffer for input real array'
 *     if PyObject_AsWriteBuffer(iarr, &idat, &bufleni)  <> 0 :
 */
  __pyx_t_1 = (PyObject_AsReadBuffer(__pyx_v_rarr, (&__pyx_v_rdat), (&__pyx_v_buflenr)) != 0);
  if (__pyx_t_1) {

    /* "g2clib.pyx":64
 *     cdef Py_ssize_t bufleni, buflenr
 *     if PyObject_AsReadBuffer(rarr, &rdat, &buflenr) <> 0:
 *         raise RuntimeError, 'error getting buffer for input real array'             # <<<<<<<<<<<<<<
 *     if PyObject_AsWriteBuffer(iarr, &idat, &bufleni)  <> 0 :
 *         raise RuntimeError, 'error getting buffer for output integer array'
 */
    __Pyx_Raise(__pyx_builtin_RuntimeError, ((PyObject *)__pyx_kp_s_1), 0, 0);
    {__pyx_filename = __pyx_f[0]; __pyx_lineno = 64; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    goto __pyx_L3;
  }
  __pyx_L3:;

  /* "g2clib.pyx":65
 *     if PyObject_AsReadBuffer(rarr, &rdat, &buflenr) <> 0:
 *         raise RuntimeError, 'error getting buffer for input real array'
 *     if PyObject_AsWriteBuffer(iarr, &idat, &bufleni)  <> 0 :             # <<<<<<<<<<<<<<
 *         raise RuntimeError, 'error getting buffer for output integer array'
 *     if bufleni < buflenr:
 */
  __pyx_t_1 = (PyObject_AsWriteBuffer(__pyx_v_iarr, (&__pyx_v_idat), (&__pyx_v_bufleni)) != 0);
  if (__pyx_t_1) {

    /* "g2clib.pyx":66
 *         raise RuntimeError, 'error getting buffer for input real array'
 *     if PyObject_AsWriteBuffer(iarr, &idat, &bufleni)  <> 0 :
 *         raise RuntimeError, 'error getting buffer for output integer array'             # <<<<<<<<<<<<<<
 *     if bufleni < buflenr:
 *         raise RuntimeError, 'integer output array must be as least as long a real input array'
 */
    __Pyx_Raise(__pyx_builtin_RuntimeError, ((PyObject *)__pyx_kp_s_2), 0, 0);
    {__pyx_filename = __pyx_f[0]; __pyx_lineno = 66; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    goto __pyx_L4;
  }
  __pyx_L4:;

  /* "g2clib.pyx":67
 *     if PyObject_AsWriteBuffer(iarr, &idat, &bufleni)  <> 0 :
 *         raise RuntimeError, 'error getting buffer for output integer array'
 *     if bufleni < buflenr:             # <<<<<<<<<<<<<<
 *         raise RuntimeError, 'integer output array must be as least as long a real input array'
 *     rdata = <g2float *>rdat
 */
  __pyx_t_1 = (__pyx_v_bufleni < __pyx_v_buflenr);
  if (__pyx_t_1) {

    /* "g2clib.pyx":68
 *         raise RuntimeError, 'error getting buffer for output integer array'
 *     if bufleni < buflenr:
 *         raise RuntimeError, 'integer output array must be as least as long a real input array'             # <<<<<<<<<<<<<<
 *     rdata = <g2float *>rdat
 *     idata = <g2int *>idat
 */
    __Pyx_Raise(__pyx_builtin_RuntimeError, ((PyObject *)__pyx_kp_s_3), 0, 0);
    {__pyx_filename = __pyx_f[0]; __pyx_lineno = 68; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    goto __pyx_L5;
  }
  __pyx_L5:;

  /* "g2clib.pyx":69
 *     if bufleni < buflenr:
 *         raise RuntimeError, 'integer output array must be as least as long a real input array'
 *     rdata = <g2float *>rdat             # <<<<<<<<<<<<<<
 *     idata = <g2int *>idat
 *     mkieee(rdata, idata, buflenr/4)
 */
  __pyx_v_rdata = ((g2float *)__pyx_v_rdat);

  /* "g2clib.pyx":70
 *         raise RuntimeError, 'integer output array must be as least as long a real input array'
 *     rdata = <g2float *>rdat
 *     idata = <g2int *>idat             # <<<<<<<<<<<<<<
 *     mkieee(rdata, idata, buflenr/4)
 * 
 */
  __pyx_v_idata = ((g2int *)__pyx_v_idat);

  /* "g2clib.pyx":71
 *     rdata = <g2float *>rdat
 *     idata = <g2int *>idat
 *     mkieee(rdata, idata, buflenr/4)             # <<<<<<<<<<<<<<
 * 
 * def itor_ieee(object iarr, object rarr):
 */
  mkieee(__pyx_v_rdata, __pyx_v_idata, __Pyx_div_Py_ssize_t(__pyx_v_buflenr, 4));

  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_AddTraceback("g2clib.rtoi_ieee", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* Python wrapper */
static PyObject *__pyx_pw_6g2clib_3itor_ieee(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
static char __pyx_doc_6g2clib_2itor_ieee[] = "\n Converts an int32 array of IEEE values into a float32 array.\n    ";
static PyMethodDef __pyx_mdef_6g2clib_3itor_ieee = {__Pyx_NAMESTR("itor_ieee"), (PyCFunction)__pyx_pw_6g2clib_3itor_ieee, METH_VARARGS|METH_KEYWORDS, __Pyx_DOCSTR(__pyx_doc_6g2clib_2itor_ieee)};
static PyObject *__pyx_pw_6g2clib_3itor_ieee(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
  PyObject *__pyx_v_iarr = 0;
  PyObject *__pyx_v_rarr = 0;
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("itor_ieee (wrapper)", 0);
  {
    static PyObject **__pyx_pyargnames[] = {&__pyx_n_s__iarr,&__pyx_n_s__rarr,0};
    PyObject* values[2] = {0,0};
    if (unlikely(__pyx_kwds)) {
      Py_ssize_t kw_args;
      const Py_ssize_t pos_args = PyTuple_GET_SIZE(__pyx_args);
      switch (pos_args) {
        case  2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
        case  1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
        case  0: break;
        default: goto __pyx_L5_argtuple_error;
      }
      kw_args = PyDict_Size(__pyx_kwds);
      switch (pos_args) {
        case  0:
        if (likely((values[0] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__iarr)) != 0)) kw_args--;
        else goto __pyx_L5_argtuple_error;
        case  1:
        if (likely((values[1] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__rarr)) != 0)) kw_args--;
        else {
          __Pyx_RaiseArgtupleInvalid("itor_ieee", 1, 2, 2, 1); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 73; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
        }
      }
      if (unlikely(kw_args > 0)) {
        if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "itor_ieee") < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 73; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
      }
    } else if (PyTuple_GET_SIZE(__pyx_args) != 2) {
      goto __pyx_L5_argtuple_error;
    } else {
      values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
      values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
    }
    __pyx_v_iarr = values[0];
    __pyx_v_rarr = values[1];
  }
  goto __pyx_L4_argument_unpacking_done;
  __pyx_L5_argtuple_error:;
  __Pyx_RaiseArgtupleInvalid("itor_ieee", 1, 2, 2, PyTuple_GET_SIZE(__pyx_args)); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 73; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
  __pyx_L3_error:;
  __Pyx_AddTraceback("g2clib.itor_ieee", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __Pyx_RefNannyFinishContext();
  return NULL;
  __pyx_L4_argument_unpacking_done:;
  __pyx_r = __pyx_pf_6g2clib_2itor_ieee(__pyx_self, __pyx_v_iarr, __pyx_v_rarr);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "g2clib.pyx":73
 *     mkieee(rdata, idata, buflenr/4)
 * 
 * def itor_ieee(object iarr, object rarr):             # <<<<<<<<<<<<<<
 *     """
 *  Converts an int32 array of IEEE values into a float32 array.
 */

static PyObject *__pyx_pf_6g2clib_2itor_ieee(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_iarr, PyObject *__pyx_v_rarr) {
  void *__pyx_v_rdat;
  void *__pyx_v_idat;
  g2float *__pyx_v_rdata;
  g2int *__pyx_v_idata;
  Py_ssize_t __pyx_v_bufleni;
  Py_ssize_t __pyx_v_buflenr;
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  int __pyx_t_1;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("itor_ieee", 0);

  /* "g2clib.pyx":81
 *     cdef g2int *idata
 *     cdef Py_ssize_t bufleni, buflenr
 *     if PyObject_AsReadBuffer(rarr, &rdat, &buflenr) <> 0:             # <<<<<<<<<<<<<<
 *         raise RuntimeError, 'error getting buffer for output real array'
 *     if PyObject_AsWriteBuffer(iarr, &idat, &bufleni)  <> 0 :
 */
  __pyx_t_1 = (PyObject_AsReadBuffer(__pyx_v_rarr, (&__pyx_v_rdat), (&__pyx_v_buflenr)) != 0);
  if (__pyx_t_1) {

    /* "g2clib.pyx":82
 *     cdef Py_ssize_t bufleni, buflenr
 *     if PyObject_AsReadBuffer(rarr, &rdat, &buflenr) <> 0:
 *         raise RuntimeError, 'error getting buffer for output real array'             # <<<<<<<<<<<<<<
 *     if PyObject_AsWriteBuffer(iarr, &idat, &bufleni)  <> 0 :
 *         raise RuntimeError, 'error getting buffer for input integer array'
 */
    __Pyx_Raise(__pyx_builtin_RuntimeError, ((PyObject *)__pyx_kp_s_4), 0, 0);
    {__pyx_filename = __pyx_f[0]; __pyx_lineno = 82; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    goto __pyx_L3;
  }
  __pyx_L3:;

  /* "g2clib.pyx":83
 *     if PyObject_AsReadBuffer(rarr, &rdat, &buflenr) <> 0:
 *         raise RuntimeError, 'error getting buffer for output real array'
 *     if PyObject_AsWriteBuffer(iarr, &idat, &bufleni)  <> 0 :             # <<<<<<<<<<<<<<
 *         raise RuntimeError, 'error getting buffer for input integer array'
 *     if buflenr < bufleni:
 */
  __pyx_t_1 = (PyObject_AsWriteBuffer(__pyx_v_iarr, (&__pyx_v_idat), (&__pyx_v_bufleni)) != 0);
  if (__pyx_t_1) {

    /* "g2clib.pyx":84
 *         raise RuntimeError, 'error getting buffer for output real array'
 *     if PyObject_AsWriteBuffer(iarr, &idat, &bufleni)  <> 0 :
 *         raise RuntimeError, 'error getting buffer for input integer array'             # <<<<<<<<<<<<<<
 *     if buflenr < bufleni:
 *         raise RuntimeError, 'real output array must be as least as long a integerinput array'
 */
    __Pyx_Raise(__pyx_builtin_RuntimeError, ((PyObject *)__pyx_kp_s_5), 0, 0);
    {__pyx_filename = __pyx_f[0]; __pyx_lineno = 84; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    goto __pyx_L4;
  }
  __pyx_L4:;

  /* "g2clib.pyx":85
 *     if PyObject_AsWriteBuffer(iarr, &idat, &bufleni)  <> 0 :
 *         raise RuntimeError, 'error getting buffer for input integer array'
 *     if buflenr < bufleni:             # <<<<<<<<<<<<<<
 *         raise RuntimeError, 'real output array must be as least as long a integerinput array'
 *     rdata = <g2float *>rdat
 */
  __pyx_t_1 = (__pyx_v_buflenr < __pyx_v_bufleni);
  if (__pyx_t_1) {

    /* "g2clib.pyx":86
 *         raise RuntimeError, 'error getting buffer for input integer array'
 *     if buflenr < bufleni:
 *         raise RuntimeError, 'real output array must be as least as long a integerinput array'             # <<<<<<<<<<<<<<
 *     rdata = <g2float *>rdat
 *     idata = <g2int *>idat
 */
    __Pyx_Raise(__pyx_builtin_RuntimeError, ((PyObject *)__pyx_kp_s_6), 0, 0);
    {__pyx_filename = __pyx_f[0]; __pyx_lineno = 86; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    goto __pyx_L5;
  }
  __pyx_L5:;

  /* "g2clib.pyx":87
 *     if buflenr < bufleni:
 *         raise RuntimeError, 'real output array must be as least as long a integerinput array'
 *     rdata = <g2float *>rdat             # <<<<<<<<<<<<<<
 *     idata = <g2int *>idat
 *     rdieee(idata, rdata, bufleni/4)
 */
  __pyx_v_rdata = ((g2float *)__pyx_v_rdat);

  /* "g2clib.pyx":88
 *         raise RuntimeError, 'real output array must be as least as long a integerinput array'
 *     rdata = <g2float *>rdat
 *     idata = <g2int *>idat             # <<<<<<<<<<<<<<
 *     rdieee(idata, rdata, bufleni/4)
 * 
 */
  __pyx_v_idata = ((g2int *)__pyx_v_idat);

  /* "g2clib.pyx":89
 *     rdata = <g2float *>rdat
 *     idata = <g2int *>idat
 *     rdieee(idata, rdata, bufleni/4)             # <<<<<<<<<<<<<<
 * 
 * cdef _toarray(void *items, object a):
 */
  rdieee(__pyx_v_idata, __pyx_v_rdata, __Pyx_div_Py_ssize_t(__pyx_v_bufleni, 4));

  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_AddTraceback("g2clib.itor_ieee", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "g2clib.pyx":91
 *     rdieee(idata, rdata, bufleni/4)
 * 
 * cdef _toarray(void *items, object a):             # <<<<<<<<<<<<<<
 *     """
 *  Fill a numpy array from the grib2 file.  Note that this free()s the items argument!
 */

static PyObject *__pyx_f_6g2clib__toarray(void *__pyx_v_items, PyObject *__pyx_v_a) {
  void *__pyx_v_abuf;
  Py_ssize_t __pyx_v_buflen;
  g2int *__pyx_v_idata;
  g2float *__pyx_v_fdata;
  long __pyx_v_i;
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  PyObject *__pyx_t_2 = NULL;
  int __pyx_t_3;
  Py_ssize_t __pyx_t_4;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("_toarray", 0);

  /* "g2clib.pyx":101
 * 
 *     # get pointer to data buffer.
 *     PyObject_AsWriteBuffer(a, &abuf, &buflen)             # <<<<<<<<<<<<<<
 * 
 *     if str(a.dtype) == 'int32':
 */
  PyObject_AsWriteBuffer(__pyx_v_a, (&__pyx_v_abuf), (&__pyx_v_buflen));

  /* "g2clib.pyx":103
 *     PyObject_AsWriteBuffer(a, &abuf, &buflen)
 * 
 *     if str(a.dtype) == 'int32':             # <<<<<<<<<<<<<<
 *       idata = <g2int *>abuf
 *       # fill buffer.
 */
  __pyx_t_1 = PyObject_GetAttr(__pyx_v_a, __pyx_n_s__dtype); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 103; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_2 = PyTuple_New(1); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 103; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  PyTuple_SET_ITEM(__pyx_t_2, 0, __pyx_t_1);
  __Pyx_GIVEREF(__pyx_t_1);
  __pyx_t_1 = 0;
  __pyx_t_1 = PyObject_Call(((PyObject *)((PyObject*)(&PyString_Type))), ((PyObject *)__pyx_t_2), NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 103; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_DECREF(((PyObject *)__pyx_t_2)); __pyx_t_2 = 0;
  __pyx_t_2 = PyObject_RichCompare(__pyx_t_1, ((PyObject *)__pyx_n_s__int32), Py_EQ); __Pyx_XGOTREF(__pyx_t_2); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 103; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_t_3 = __Pyx_PyObject_IsTrue(__pyx_t_2); if (unlikely(__pyx_t_3 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 103; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  if (__pyx_t_3) {

    /* "g2clib.pyx":104
 * 
 *     if str(a.dtype) == 'int32':
 *       idata = <g2int *>abuf             # <<<<<<<<<<<<<<
 *       # fill buffer.
 *       for i from 0 <= i < len(a):
 */
    __pyx_v_idata = ((g2int *)__pyx_v_abuf);

    /* "g2clib.pyx":106
 *       idata = <g2int *>abuf
 *       # fill buffer.
 *       for i from 0 <= i < len(a):             # <<<<<<<<<<<<<<
 *         idata[i] = (<g2int *>items)[i]
 *     elif str(a.dtype) == 'float32':
 */
    __pyx_t_4 = PyObject_Length(__pyx_v_a); if (unlikely(__pyx_t_4 == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 106; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    for (__pyx_v_i = 0; __pyx_v_i < __pyx_t_4; __pyx_v_i++) {

      /* "g2clib.pyx":107
 *       # fill buffer.
 *       for i from 0 <= i < len(a):
 *         idata[i] = (<g2int *>items)[i]             # <<<<<<<<<<<<<<
 *     elif str(a.dtype) == 'float32':
 *       fdata = <g2float *>abuf
 */
      (__pyx_v_idata[__pyx_v_i]) = (((g2int *)__pyx_v_items)[__pyx_v_i]);
    }
    goto __pyx_L3;
  }

  /* "g2clib.pyx":108
 *       for i from 0 <= i < len(a):
 *         idata[i] = (<g2int *>items)[i]
 *     elif str(a.dtype) == 'float32':             # <<<<<<<<<<<<<<
 *       fdata = <g2float *>abuf
 *       # fill buffer.
 */
  __pyx_t_2 = PyObject_GetAttr(__pyx_v_a, __pyx_n_s__dtype); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 108; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_1 = PyTuple_New(1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 108; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  PyTuple_SET_ITEM(__pyx_t_1, 0, __pyx_t_2);
  __Pyx_GIVEREF(__pyx_t_2);
  __pyx_t_2 = 0;
  __pyx_t_2 = PyObject_Call(((PyObject *)((PyObject*)(&PyString_Type))), ((PyObject *)__pyx_t_1), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 108; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_DECREF(((PyObject *)__pyx_t_1)); __pyx_t_1 = 0;
  __pyx_t_1 = PyObject_RichCompare(__pyx_t_2, ((PyObject *)__pyx_n_s__float32), Py_EQ); __Pyx_XGOTREF(__pyx_t_1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 108; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __pyx_t_3 = __Pyx_PyObject_IsTrue(__pyx_t_1); if (unlikely(__pyx_t_3 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 108; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  if (__pyx_t_3) {

    /* "g2clib.pyx":109
 *         idata[i] = (<g2int *>items)[i]
 *     elif str(a.dtype) == 'float32':
 *       fdata = <g2float *>abuf             # <<<<<<<<<<<<<<
 *       # fill buffer.
 *       for i from 0 <= i < len(a):
 */
    __pyx_v_fdata = ((g2float *)__pyx_v_abuf);

    /* "g2clib.pyx":111
 *       fdata = <g2float *>abuf
 *       # fill buffer.
 *       for i from 0 <= i < len(a):             # <<<<<<<<<<<<<<
 *         fdata[i] = (<g2float *>items)[i]
 *     else:
 */
    __pyx_t_4 = PyObject_Length(__pyx_v_a); if (unlikely(__pyx_t_4 == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 111; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    for (__pyx_v_i = 0; __pyx_v_i < __pyx_t_4; __pyx_v_i++) {

      /* "g2clib.pyx":112
 *       # fill buffer.
 *       for i from 0 <= i < len(a):
 *         fdata[i] = (<g2float *>items)[i]             # <<<<<<<<<<<<<<
 *     else:
 *       free(items)
 */
      (__pyx_v_fdata[__pyx_v_i]) = (((g2float *)__pyx_v_items)[__pyx_v_i]);
    }
    goto __pyx_L3;
  }
  /*else*/ {

    /* "g2clib.pyx":114
 *         fdata[i] = (<g2float *>items)[i]
 *     else:
 *       free(items)             # <<<<<<<<<<<<<<
 *       raise RuntimeError('unknown array type %s' % a.dtype)
 * 
 */
    free(__pyx_v_items);

    /* "g2clib.pyx":115
 *     else:
 *       free(items)
 *       raise RuntimeError('unknown array type %s' % a.dtype)             # <<<<<<<<<<<<<<
 * 
 *     free(items)
 */
    __pyx_t_1 = PyObject_GetAttr(__pyx_v_a, __pyx_n_s__dtype); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 115; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_1);
    __pyx_t_2 = PyNumber_Remainder(((PyObject *)__pyx_kp_s_7), __pyx_t_1); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 115; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(((PyObject *)__pyx_t_2));
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
    __pyx_t_1 = PyTuple_New(1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 115; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_1);
    PyTuple_SET_ITEM(__pyx_t_1, 0, ((PyObject *)__pyx_t_2));
    __Pyx_GIVEREF(((PyObject *)__pyx_t_2));
    __pyx_t_2 = 0;
    __pyx_t_2 = PyObject_Call(__pyx_builtin_RuntimeError, ((PyObject *)__pyx_t_1), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 115; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_2);
    __Pyx_DECREF(((PyObject *)__pyx_t_1)); __pyx_t_1 = 0;
    __Pyx_Raise(__pyx_t_2, 0, 0, 0);
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    {__pyx_filename = __pyx_f[0]; __pyx_lineno = 115; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  }
  __pyx_L3:;

  /* "g2clib.pyx":117
 *       raise RuntimeError('unknown array type %s' % a.dtype)
 * 
 *     free(items)             # <<<<<<<<<<<<<<
 *     return a
 * 
 */
  free(__pyx_v_items);

  /* "g2clib.pyx":118
 * 
 *     free(items)
 *     return a             # <<<<<<<<<<<<<<
 * 
 * 
 */
  __Pyx_XDECREF(__pyx_r);
  __Pyx_INCREF(__pyx_v_a);
  __pyx_r = __pyx_v_a;
  goto __pyx_L0;

  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_AddTraceback("g2clib._toarray", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = 0;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* Python wrapper */
static PyObject *__pyx_pw_6g2clib_5unpack1(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
static char __pyx_doc_6g2clib_4unpack1[] = "              .      .    .                                       .\n Unpacks Section 1 (Identification Section) as defined in GRIB Edition 2.\n \n idsect,ipos = unpack1(gribmsg,ipos)\n\n INPUTS:\n  gribmsg - chararcter string containing Section 1 of the GRIB2 message\n  ipos    - Byte offset for the beginning of Section 1 in gribmsg.\n  zeros   - Numeric/numpy array/scip.base zeros function (used to allocate\n            output python arrays).  Python is used to allocate the arrays\n            so no implementation-specific (Numeric, numpy array, scipy_core)\n            C API functions need to be used.  This means that any of these\n            array modules can be used simply by changing the import statement\n            in your python code.\n RETURNS:\n  ipos    - Byte offset at the end of Section 1.\n  idsect  - numpy array containing information \n            read from Section 1, the Identification section.\n            idsect[0]   = Identification of originating Centre\n                                 ( see Common Code Table C-1 )\n            idsect[1]   = Identification of originating Sub-centre\n            idsect[2]   = GRIB Master Tables Version Number\n                                 ( see Code Table 1.0 )\n            idsect[3]   = GRIB Local Tables Version Number\n                                 ( see Code Table 1.1 )\n            idsect[4]   = Significance of Reference Time (Code Table 1.2)\n            idsect[5]   = Year ( 4 digits )\n            idsect[6]   = Month\n            idsect[7]   = Day\n            idsect[8]   = Hour\n            idsect[9]   = Minute\n            idsect[10]  = Second\n            idsect[11]  = Production status of processed data\n                                 ( see Code Table 1.3 )\n            idsect[12]  = Type of processed data ( see Code Table 1.4 )\n ERROR CODES:   2 = Array passed is not section 1\n                6 = memory allocation error\n    ";
static PyMethodDef __pyx_mdef_6g2clib_5unpack1 = {__Pyx_NAMESTR("unpack1"), (PyCFunction)__pyx_pw_6g2clib_5unpack1, METH_VARARGS|METH_KEYWORDS, __Pyx_DOCSTR(__pyx_doc_6g2clib_4unpack1)};
static PyObject *__pyx_pw_6g2clib_5unpack1(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
  PyObject *__pyx_v_gribmsg = 0;
  PyObject *__pyx_v_ipos = 0;
  PyObject *__pyx_v_zeros = 0;
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("unpack1 (wrapper)", 0);
  {
    static PyObject **__pyx_pyargnames[] = {&__pyx_n_s__gribmsg,&__pyx_n_s__ipos,&__pyx_n_s__zeros,0};
    PyObject* values[3] = {0,0,0};
    if (unlikely(__pyx_kwds)) {
      Py_ssize_t kw_args;
      const Py_ssize_t pos_args = PyTuple_GET_SIZE(__pyx_args);
      switch (pos_args) {
        case  3: values[2] = PyTuple_GET_ITEM(__pyx_args, 2);
        case  2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
        case  1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
        case  0: break;
        default: goto __pyx_L5_argtuple_error;
      }
      kw_args = PyDict_Size(__pyx_kwds);
      switch (pos_args) {
        case  0:
        if (likely((values[0] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__gribmsg)) != 0)) kw_args--;
        else goto __pyx_L5_argtuple_error;
        case  1:
        if (likely((values[1] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__ipos)) != 0)) kw_args--;
        else {
          __Pyx_RaiseArgtupleInvalid("unpack1", 1, 3, 3, 1); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 123; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
        }
        case  2:
        if (likely((values[2] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__zeros)) != 0)) kw_args--;
        else {
          __Pyx_RaiseArgtupleInvalid("unpack1", 1, 3, 3, 2); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 123; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
        }
      }
      if (unlikely(kw_args > 0)) {
        if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "unpack1") < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 123; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
      }
    } else if (PyTuple_GET_SIZE(__pyx_args) != 3) {
      goto __pyx_L5_argtuple_error;
    } else {
      values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
      values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
      values[2] = PyTuple_GET_ITEM(__pyx_args, 2);
    }
    __pyx_v_gribmsg = values[0];
    __pyx_v_ipos = values[1];
    __pyx_v_zeros = values[2];
  }
  goto __pyx_L4_argument_unpacking_done;
  __pyx_L5_argtuple_error:;
  __Pyx_RaiseArgtupleInvalid("unpack1", 1, 3, 3, PyTuple_GET_SIZE(__pyx_args)); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 123; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
  __pyx_L3_error:;
  __Pyx_AddTraceback("g2clib.unpack1", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __Pyx_RefNannyFinishContext();
  return NULL;
  __pyx_L4_argument_unpacking_done:;
  __pyx_r = __pyx_pf_6g2clib_4unpack1(__pyx_self, __pyx_v_gribmsg, __pyx_v_ipos, __pyx_v_zeros);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "g2clib.pyx":123
 * # routines for reading grib2 files.
 * 
 * def unpack1(gribmsg, ipos, object zeros):             # <<<<<<<<<<<<<<
 *     """              .      .    .                                       .
 *  Unpacks Section 1 (Identification Section) as defined in GRIB Edition 2.
 */

static PyObject *__pyx_pf_6g2clib_4unpack1(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_gribmsg, PyObject *__pyx_v_ipos, PyObject *__pyx_v_zeros) {
  unsigned char *__pyx_v_cgrib;
  g2int __pyx_v_iofst;
  g2int __pyx_v_ierr;
  g2int __pyx_v_idslen;
  g2int *__pyx_v_ids;
  PyObject *__pyx_v_msg = NULL;
  PyObject *__pyx_v_idsect = NULL;
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  int __pyx_t_2;
  PyObject *__pyx_t_3 = NULL;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("unpack1", 0);

  /* "g2clib.pyx":165
 *     cdef g2int i, iofst, ierr, idslen
 *     cdef g2int *ids
 *     cgrib = <unsigned char *>PyBytes_AsString(gribmsg)             # <<<<<<<<<<<<<<
 *     iofst = <g2int>PyInt_AsLong(ipos*8)
 *     ierr = g2_unpack1(cgrib, &iofst, &ids, &idslen)
 */
  __pyx_v_cgrib = ((unsigned char *)PyBytes_AsString(__pyx_v_gribmsg));

  /* "g2clib.pyx":166
 *     cdef g2int *ids
 *     cgrib = <unsigned char *>PyBytes_AsString(gribmsg)
 *     iofst = <g2int>PyInt_AsLong(ipos*8)             # <<<<<<<<<<<<<<
 *     ierr = g2_unpack1(cgrib, &iofst, &ids, &idslen)
 *     if ierr != 0:
 */
  __pyx_t_1 = PyNumber_Multiply(__pyx_v_ipos, __pyx_int_8); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 166; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_v_iofst = ((g2int)PyInt_AsLong(__pyx_t_1));
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

  /* "g2clib.pyx":167
 *     cgrib = <unsigned char *>PyBytes_AsString(gribmsg)
 *     iofst = <g2int>PyInt_AsLong(ipos*8)
 *     ierr = g2_unpack1(cgrib, &iofst, &ids, &idslen)             # <<<<<<<<<<<<<<
 *     if ierr != 0:
 *        msg = "Error unpacking section 1 - error code = %i" % ierr
 */
  __pyx_v_ierr = g2_unpack1(__pyx_v_cgrib, (&__pyx_v_iofst), (&__pyx_v_ids), (&__pyx_v_idslen));

  /* "g2clib.pyx":168
 *     iofst = <g2int>PyInt_AsLong(ipos*8)
 *     ierr = g2_unpack1(cgrib, &iofst, &ids, &idslen)
 *     if ierr != 0:             # <<<<<<<<<<<<<<
 *        msg = "Error unpacking section 1 - error code = %i" % ierr
 *        raise RuntimeError(msg)
 */
  __pyx_t_2 = (__pyx_v_ierr != 0);
  if (__pyx_t_2) {

    /* "g2clib.pyx":169
 *     ierr = g2_unpack1(cgrib, &iofst, &ids, &idslen)
 *     if ierr != 0:
 *        msg = "Error unpacking section 1 - error code = %i" % ierr             # <<<<<<<<<<<<<<
 *        raise RuntimeError(msg)
 * 
 */
    __pyx_t_1 = __Pyx_PyInt_to_py_int32_t(__pyx_v_ierr); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 169; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_1);
    __pyx_t_3 = PyNumber_Remainder(((PyObject *)__pyx_kp_s_8), __pyx_t_1); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 169; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(((PyObject *)__pyx_t_3));
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
    __pyx_v_msg = ((PyObject *)__pyx_t_3);
    __pyx_t_3 = 0;

    /* "g2clib.pyx":170
 *     if ierr != 0:
 *        msg = "Error unpacking section 1 - error code = %i" % ierr
 *        raise RuntimeError(msg)             # <<<<<<<<<<<<<<
 * 
 *     idsect = _toarray(ids, zeros(idslen, 'i4'))
 */
    __pyx_t_3 = PyTuple_New(1); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 170; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_3);
    __Pyx_INCREF(__pyx_v_msg);
    PyTuple_SET_ITEM(__pyx_t_3, 0, __pyx_v_msg);
    __Pyx_GIVEREF(__pyx_v_msg);
    __pyx_t_1 = PyObject_Call(__pyx_builtin_RuntimeError, ((PyObject *)__pyx_t_3), NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 170; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_1);
    __Pyx_DECREF(((PyObject *)__pyx_t_3)); __pyx_t_3 = 0;
    __Pyx_Raise(__pyx_t_1, 0, 0, 0);
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
    {__pyx_filename = __pyx_f[0]; __pyx_lineno = 170; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    goto __pyx_L3;
  }
  __pyx_L3:;

  /* "g2clib.pyx":172
 *        raise RuntimeError(msg)
 * 
 *     idsect = _toarray(ids, zeros(idslen, 'i4'))             # <<<<<<<<<<<<<<
 *     return idsect,iofst/8
 * 
 */
  __pyx_t_1 = __Pyx_PyInt_to_py_int32_t(__pyx_v_idslen); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 172; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_3 = PyTuple_New(2); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 172; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  PyTuple_SET_ITEM(__pyx_t_3, 0, __pyx_t_1);
  __Pyx_GIVEREF(__pyx_t_1);
  __Pyx_INCREF(((PyObject *)__pyx_n_s__i4));
  PyTuple_SET_ITEM(__pyx_t_3, 1, ((PyObject *)__pyx_n_s__i4));
  __Pyx_GIVEREF(((PyObject *)__pyx_n_s__i4));
  __pyx_t_1 = 0;
  __pyx_t_1 = PyObject_Call(__pyx_v_zeros, ((PyObject *)__pyx_t_3), NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 172; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_DECREF(((PyObject *)__pyx_t_3)); __pyx_t_3 = 0;
  __pyx_t_3 = __pyx_f_6g2clib__toarray(__pyx_v_ids, __pyx_t_1); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 172; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_v_idsect = __pyx_t_3;
  __pyx_t_3 = 0;

  /* "g2clib.pyx":173
 * 
 *     idsect = _toarray(ids, zeros(idslen, 'i4'))
 *     return idsect,iofst/8             # <<<<<<<<<<<<<<
 * 
 * 
 */
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_3 = PyInt_FromLong(__Pyx_div_long(__pyx_v_iofst, 8)); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 173; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_t_1 = PyTuple_New(2); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 173; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_INCREF(__pyx_v_idsect);
  PyTuple_SET_ITEM(__pyx_t_1, 0, __pyx_v_idsect);
  __Pyx_GIVEREF(__pyx_v_idsect);
  PyTuple_SET_ITEM(__pyx_t_1, 1, __pyx_t_3);
  __Pyx_GIVEREF(__pyx_t_3);
  __pyx_t_3 = 0;
  __pyx_r = ((PyObject *)__pyx_t_1);
  __pyx_t_1 = 0;
  goto __pyx_L0;

  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_XDECREF(__pyx_t_3);
  __Pyx_AddTraceback("g2clib.unpack1", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XDECREF(__pyx_v_msg);
  __Pyx_XDECREF(__pyx_v_idsect);
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* Python wrapper */
static PyObject *__pyx_pw_6g2clib_7unpack3(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
static char __pyx_doc_6g2clib_6unpack3[] = "\n Unpacks Section 3 (Grid Definition Section) as defined in GRIB Edition 2.\n\n gds,gdtmpl,deflist,ipos = unpack3(gribmsg,ipos)\n \n INPUTS:\n cgrib    - Char array ontaining Section 3 of the GRIB2 message\n iofst    - Byte offset for the beginning of Section 3 in cgrib.\n zeros    - Numeric/numpy array/scip.base zeros function (used to allocate\n            output python arrays).  Python is used to allocate the arrays\n            so no implementation-specific (Numeric, numpy array, scipy_core)\n            C API functions need to be used.  This means that any of these\n            array modules can be used simply by changing the import statement\n            in your python code.\n\n RETURNS:      \n ipos     - Byte offset at the end of Section 3, returned.\n  gds     - numpy array containg information read from the appropriate GRIB Grid \n            Definition Section 3 for the field being returned.\n            gds[0]=Source of grid definition (see Code Table 3.0)\n            gds[1]=Number of grid points in the defined grid.\n            gds[2]=Number of octets needed for each \n                        additional grid points definition.  \n                        Used to define number of\n                        points in each row ( or column ) for\n                        non-regular grids.  \n                        = 0, if using regular grid.\n            gds[3]=Interpretation of list for optional points \n                        definition.  (Code Table 3.11)\n            gds[4]=Grid Definition Template Number (Code Table 3.1)\n gdstmpl -  numpy array containing the data values for \n            the specified Grid Definition\n            Template ( NN=gds[4] ).  Each element of this integer \n            array contains an entry (in the order specified) of Grid\n            Defintion Template 3.NN\n deflist -  (Used if gds[2] != 0) numpy array containing\n            the number of grid points contained in each row ( or column ).\n            (part of Sectio""n 3)\n ERROR CODES:   2 = Not Section 3\n                5 = \"GRIB\" message contains an undefined Grid Definition\n                    Template.\n                6 = memory allocation error\n    ";
static PyMethodDef __pyx_mdef_6g2clib_7unpack3 = {__Pyx_NAMESTR("unpack3"), (PyCFunction)__pyx_pw_6g2clib_7unpack3, METH_VARARGS|METH_KEYWORDS, __Pyx_DOCSTR(__pyx_doc_6g2clib_6unpack3)};
static PyObject *__pyx_pw_6g2clib_7unpack3(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
  PyObject *__pyx_v_gribmsg = 0;
  PyObject *__pyx_v_ipos = 0;
  PyObject *__pyx_v_zeros = 0;
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("unpack3 (wrapper)", 0);
  {
    static PyObject **__pyx_pyargnames[] = {&__pyx_n_s__gribmsg,&__pyx_n_s__ipos,&__pyx_n_s__zeros,0};
    PyObject* values[3] = {0,0,0};
    if (unlikely(__pyx_kwds)) {
      Py_ssize_t kw_args;
      const Py_ssize_t pos_args = PyTuple_GET_SIZE(__pyx_args);
      switch (pos_args) {
        case  3: values[2] = PyTuple_GET_ITEM(__pyx_args, 2);
        case  2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
        case  1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
        case  0: break;
        default: goto __pyx_L5_argtuple_error;
      }
      kw_args = PyDict_Size(__pyx_kwds);
      switch (pos_args) {
        case  0:
        if (likely((values[0] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__gribmsg)) != 0)) kw_args--;
        else goto __pyx_L5_argtuple_error;
        case  1:
        if (likely((values[1] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__ipos)) != 0)) kw_args--;
        else {
          __Pyx_RaiseArgtupleInvalid("unpack3", 1, 3, 3, 1); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 177; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
        }
        case  2:
        if (likely((values[2] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__zeros)) != 0)) kw_args--;
        else {
          __Pyx_RaiseArgtupleInvalid("unpack3", 1, 3, 3, 2); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 177; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
        }
      }
      if (unlikely(kw_args > 0)) {
        if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "unpack3") < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 177; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
      }
    } else if (PyTuple_GET_SIZE(__pyx_args) != 3) {
      goto __pyx_L5_argtuple_error;
    } else {
      values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
      values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
      values[2] = PyTuple_GET_ITEM(__pyx_args, 2);
    }
    __pyx_v_gribmsg = values[0];
    __pyx_v_ipos = values[1];
    __pyx_v_zeros = values[2];
  }
  goto __pyx_L4_argument_unpacking_done;
  __pyx_L5_argtuple_error:;
  __Pyx_RaiseArgtupleInvalid("unpack3", 1, 3, 3, PyTuple_GET_SIZE(__pyx_args)); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 177; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
  __pyx_L3_error:;
  __Pyx_AddTraceback("g2clib.unpack3", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __Pyx_RefNannyFinishContext();
  return NULL;
  __pyx_L4_argument_unpacking_done:;
  __pyx_r = __pyx_pf_6g2clib_6unpack3(__pyx_self, __pyx_v_gribmsg, __pyx_v_ipos, __pyx_v_zeros);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "g2clib.pyx":177
 * 
 * 
 * def unpack3(gribmsg, ipos, object zeros):             # <<<<<<<<<<<<<<
 *     """
 *  Unpacks Section 3 (Grid Definition Section) as defined in GRIB Edition 2.
 */

static PyObject *__pyx_pf_6g2clib_6unpack3(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_gribmsg, PyObject *__pyx_v_ipos, PyObject *__pyx_v_zeros) {
  unsigned char *__pyx_v_cgrib;
  g2int *__pyx_v_igds;
  g2int *__pyx_v_igdstmpl;
  g2int *__pyx_v_ideflist;
  g2int __pyx_v_mapgridlen;
  g2int __pyx_v_iofst;
  g2int __pyx_v_idefnum;
  g2int __pyx_v_ierr;
  PyObject *__pyx_v_msg = NULL;
  PyObject *__pyx_v_gdtmpl = NULL;
  PyObject *__pyx_v_gds = NULL;
  PyObject *__pyx_v_deflist = NULL;
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  int __pyx_t_2;
  PyObject *__pyx_t_3 = NULL;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("unpack3", 0);

  /* "g2clib.pyx":224
 *     cdef g2int *igds, *igdstmpl, *ideflist
 *     cdef g2int mapgridlen, iofst, idefnum, ierr
 *     cgrib = <unsigned char *>PyBytes_AsString(gribmsg)             # <<<<<<<<<<<<<<
 *     iofst = <g2int>PyInt_AsLong(ipos*8)
 *     ierr=g2_unpack3(cgrib,&iofst,&igds,&igdstmpl,&mapgridlen,&ideflist,&idefnum)
 */
  __pyx_v_cgrib = ((unsigned char *)PyBytes_AsString(__pyx_v_gribmsg));

  /* "g2clib.pyx":225
 *     cdef g2int mapgridlen, iofst, idefnum, ierr
 *     cgrib = <unsigned char *>PyBytes_AsString(gribmsg)
 *     iofst = <g2int>PyInt_AsLong(ipos*8)             # <<<<<<<<<<<<<<
 *     ierr=g2_unpack3(cgrib,&iofst,&igds,&igdstmpl,&mapgridlen,&ideflist,&idefnum)
 *     if ierr != 0:
 */
  __pyx_t_1 = PyNumber_Multiply(__pyx_v_ipos, __pyx_int_8); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 225; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_v_iofst = ((g2int)PyInt_AsLong(__pyx_t_1));
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

  /* "g2clib.pyx":226
 *     cgrib = <unsigned char *>PyBytes_AsString(gribmsg)
 *     iofst = <g2int>PyInt_AsLong(ipos*8)
 *     ierr=g2_unpack3(cgrib,&iofst,&igds,&igdstmpl,&mapgridlen,&ideflist,&idefnum)             # <<<<<<<<<<<<<<
 *     if ierr != 0:
 *        msg = "Error unpacking section 3 - error code = %i" % ierr
 */
  __pyx_v_ierr = g2_unpack3(__pyx_v_cgrib, (&__pyx_v_iofst), (&__pyx_v_igds), (&__pyx_v_igdstmpl), (&__pyx_v_mapgridlen), (&__pyx_v_ideflist), (&__pyx_v_idefnum));

  /* "g2clib.pyx":227
 *     iofst = <g2int>PyInt_AsLong(ipos*8)
 *     ierr=g2_unpack3(cgrib,&iofst,&igds,&igdstmpl,&mapgridlen,&ideflist,&idefnum)
 *     if ierr != 0:             # <<<<<<<<<<<<<<
 *        msg = "Error unpacking section 3 - error code = %i" % ierr
 *        raise RuntimeError(msg)
 */
  __pyx_t_2 = (__pyx_v_ierr != 0);
  if (__pyx_t_2) {

    /* "g2clib.pyx":228
 *     ierr=g2_unpack3(cgrib,&iofst,&igds,&igdstmpl,&mapgridlen,&ideflist,&idefnum)
 *     if ierr != 0:
 *        msg = "Error unpacking section 3 - error code = %i" % ierr             # <<<<<<<<<<<<<<
 *        raise RuntimeError(msg)
 * 
 */
    __pyx_t_1 = __Pyx_PyInt_to_py_int32_t(__pyx_v_ierr); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 228; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_1);
    __pyx_t_3 = PyNumber_Remainder(((PyObject *)__pyx_kp_s_9), __pyx_t_1); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 228; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(((PyObject *)__pyx_t_3));
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
    __pyx_v_msg = ((PyObject *)__pyx_t_3);
    __pyx_t_3 = 0;

    /* "g2clib.pyx":229
 *     if ierr != 0:
 *        msg = "Error unpacking section 3 - error code = %i" % ierr
 *        raise RuntimeError(msg)             # <<<<<<<<<<<<<<
 * 
 *     gdtmpl = _toarray(igdstmpl, zeros(mapgridlen, 'i4'))
 */
    __pyx_t_3 = PyTuple_New(1); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 229; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_3);
    __Pyx_INCREF(__pyx_v_msg);
    PyTuple_SET_ITEM(__pyx_t_3, 0, __pyx_v_msg);
    __Pyx_GIVEREF(__pyx_v_msg);
    __pyx_t_1 = PyObject_Call(__pyx_builtin_RuntimeError, ((PyObject *)__pyx_t_3), NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 229; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_1);
    __Pyx_DECREF(((PyObject *)__pyx_t_3)); __pyx_t_3 = 0;
    __Pyx_Raise(__pyx_t_1, 0, 0, 0);
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
    {__pyx_filename = __pyx_f[0]; __pyx_lineno = 229; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    goto __pyx_L3;
  }
  __pyx_L3:;

  /* "g2clib.pyx":231
 *        raise RuntimeError(msg)
 * 
 *     gdtmpl = _toarray(igdstmpl, zeros(mapgridlen, 'i4'))             # <<<<<<<<<<<<<<
 *     gds = _toarray(igds, zeros(5, 'i4'))
 *     deflist = _toarray(ideflist, zeros(idefnum, 'i4'))
 */
  __pyx_t_1 = __Pyx_PyInt_to_py_int32_t(__pyx_v_mapgridlen); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 231; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_3 = PyTuple_New(2); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 231; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  PyTuple_SET_ITEM(__pyx_t_3, 0, __pyx_t_1);
  __Pyx_GIVEREF(__pyx_t_1);
  __Pyx_INCREF(((PyObject *)__pyx_n_s__i4));
  PyTuple_SET_ITEM(__pyx_t_3, 1, ((PyObject *)__pyx_n_s__i4));
  __Pyx_GIVEREF(((PyObject *)__pyx_n_s__i4));
  __pyx_t_1 = 0;
  __pyx_t_1 = PyObject_Call(__pyx_v_zeros, ((PyObject *)__pyx_t_3), NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 231; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_DECREF(((PyObject *)__pyx_t_3)); __pyx_t_3 = 0;
  __pyx_t_3 = __pyx_f_6g2clib__toarray(__pyx_v_igdstmpl, __pyx_t_1); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 231; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_v_gdtmpl = __pyx_t_3;
  __pyx_t_3 = 0;

  /* "g2clib.pyx":232
 * 
 *     gdtmpl = _toarray(igdstmpl, zeros(mapgridlen, 'i4'))
 *     gds = _toarray(igds, zeros(5, 'i4'))             # <<<<<<<<<<<<<<
 *     deflist = _toarray(ideflist, zeros(idefnum, 'i4'))
 * 
 */
  __pyx_t_3 = PyObject_Call(__pyx_v_zeros, ((PyObject *)__pyx_k_tuple_10), NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 232; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_t_1 = __pyx_f_6g2clib__toarray(__pyx_v_igds, __pyx_t_3); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 232; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __pyx_v_gds = __pyx_t_1;
  __pyx_t_1 = 0;

  /* "g2clib.pyx":233
 *     gdtmpl = _toarray(igdstmpl, zeros(mapgridlen, 'i4'))
 *     gds = _toarray(igds, zeros(5, 'i4'))
 *     deflist = _toarray(ideflist, zeros(idefnum, 'i4'))             # <<<<<<<<<<<<<<
 * 
 *     return gds,gdtmpl,deflist,iofst/8
 */
  __pyx_t_1 = __Pyx_PyInt_to_py_int32_t(__pyx_v_idefnum); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 233; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_3 = PyTuple_New(2); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 233; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  PyTuple_SET_ITEM(__pyx_t_3, 0, __pyx_t_1);
  __Pyx_GIVEREF(__pyx_t_1);
  __Pyx_INCREF(((PyObject *)__pyx_n_s__i4));
  PyTuple_SET_ITEM(__pyx_t_3, 1, ((PyObject *)__pyx_n_s__i4));
  __Pyx_GIVEREF(((PyObject *)__pyx_n_s__i4));
  __pyx_t_1 = 0;
  __pyx_t_1 = PyObject_Call(__pyx_v_zeros, ((PyObject *)__pyx_t_3), NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 233; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_DECREF(((PyObject *)__pyx_t_3)); __pyx_t_3 = 0;
  __pyx_t_3 = __pyx_f_6g2clib__toarray(__pyx_v_ideflist, __pyx_t_1); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 233; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_v_deflist = __pyx_t_3;
  __pyx_t_3 = 0;

  /* "g2clib.pyx":235
 *     deflist = _toarray(ideflist, zeros(idefnum, 'i4'))
 * 
 *     return gds,gdtmpl,deflist,iofst/8             # <<<<<<<<<<<<<<
 * 
 * def unpack4(gribmsg,ipos,object zeros):
 */
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_3 = PyInt_FromLong(__Pyx_div_long(__pyx_v_iofst, 8)); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 235; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_t_1 = PyTuple_New(4); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 235; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_INCREF(__pyx_v_gds);
  PyTuple_SET_ITEM(__pyx_t_1, 0, __pyx_v_gds);
  __Pyx_GIVEREF(__pyx_v_gds);
  __Pyx_INCREF(__pyx_v_gdtmpl);
  PyTuple_SET_ITEM(__pyx_t_1, 1, __pyx_v_gdtmpl);
  __Pyx_GIVEREF(__pyx_v_gdtmpl);
  __Pyx_INCREF(__pyx_v_deflist);
  PyTuple_SET_ITEM(__pyx_t_1, 2, __pyx_v_deflist);
  __Pyx_GIVEREF(__pyx_v_deflist);
  PyTuple_SET_ITEM(__pyx_t_1, 3, __pyx_t_3);
  __Pyx_GIVEREF(__pyx_t_3);
  __pyx_t_3 = 0;
  __pyx_r = ((PyObject *)__pyx_t_1);
  __pyx_t_1 = 0;
  goto __pyx_L0;

  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_XDECREF(__pyx_t_3);
  __Pyx_AddTraceback("g2clib.unpack3", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XDECREF(__pyx_v_msg);
  __Pyx_XDECREF(__pyx_v_gdtmpl);
  __Pyx_XDECREF(__pyx_v_gds);
  __Pyx_XDECREF(__pyx_v_deflist);
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* Python wrapper */
static PyObject *__pyx_pw_6g2clib_9unpack4(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
static char __pyx_doc_6g2clib_8unpack4[] = "\n Unpacks Section 4 (Product Definition Section) as defined in GRIB Edition 2.\n\n pdtmpl,pdtnum,coordlist,ipos = unpack4(gribmsg,ipos)\n \n INPUTS:\n   gribmsg  - Character string containing Section 4 of the GRIB2 message\n   ipos     - Byte offset of the beginning of Section 4 in cgrib.\n   zeros    - Numeric/numpy array/scip.base zeros function (used to allocate\n              output python arrays).  Python is used to allocate the arrays\n              so no implementation-specific (Numeric, numpy array, scipy_core)\n              C API functions need to be used.  This means that any of these\n              array modules can be used simply by changing the import statement\n              in your python code.\n\n RETURNS:       \n   pdtmpl   -  numpy array containing the data values for \n               the specified Product Definition\n               Template ( N=ipdsnum ).  Each element of this integer\n               array contains an entry (in the order specified) \n               of Product Defintion Template 4.N               \n   pdtnum    - Product Definition Template Number ( see Code Table 4.0)   \n   coordlist - numpy array containing floating point values \n               intended to document\n               the vertical discretisation associated to model data\n               on hybrid coordinate vertical levels.  (part of Section 4)\n   ipos      - Byte offset of the end of Section 4, returned.\n\n ERROR CODES: 2 = Not section 4\n              5 = \"GRIB\" message contains an undefined Product Definition\n                  Template.\n              6 = memory allocation error\n    ";
static PyMethodDef __pyx_mdef_6g2clib_9unpack4 = {__Pyx_NAMESTR("unpack4"), (PyCFunction)__pyx_pw_6g2clib_9unpack4, METH_VARARGS|METH_KEYWORDS, __Pyx_DOCSTR(__pyx_doc_6g2clib_8unpack4)};
static PyObject *__pyx_pw_6g2clib_9unpack4(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
  PyObject *__pyx_v_gribmsg = 0;
  PyObject *__pyx_v_ipos = 0;
  PyObject *__pyx_v_zeros = 0;
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("unpack4 (wrapper)", 0);
  {
    static PyObject **__pyx_pyargnames[] = {&__pyx_n_s__gribmsg,&__pyx_n_s__ipos,&__pyx_n_s__zeros,0};
    PyObject* values[3] = {0,0,0};
    if (unlikely(__pyx_kwds)) {
      Py_ssize_t kw_args;
      const Py_ssize_t pos_args = PyTuple_GET_SIZE(__pyx_args);
      switch (pos_args) {
        case  3: values[2] = PyTuple_GET_ITEM(__pyx_args, 2);
        case  2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
        case  1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
        case  0: break;
        default: goto __pyx_L5_argtuple_error;
      }
      kw_args = PyDict_Size(__pyx_kwds);
      switch (pos_args) {
        case  0:
        if (likely((values[0] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__gribmsg)) != 0)) kw_args--;
        else goto __pyx_L5_argtuple_error;
        case  1:
        if (likely((values[1] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__ipos)) != 0)) kw_args--;
        else {
          __Pyx_RaiseArgtupleInvalid("unpack4", 1, 3, 3, 1); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 237; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
        }
        case  2:
        if (likely((values[2] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__zeros)) != 0)) kw_args--;
        else {
          __Pyx_RaiseArgtupleInvalid("unpack4", 1, 3, 3, 2); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 237; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
        }
      }
      if (unlikely(kw_args > 0)) {
        if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "unpack4") < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 237; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
      }
    } else if (PyTuple_GET_SIZE(__pyx_args) != 3) {
      goto __pyx_L5_argtuple_error;
    } else {
      values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
      values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
      values[2] = PyTuple_GET_ITEM(__pyx_args, 2);
    }
    __pyx_v_gribmsg = values[0];
    __pyx_v_ipos = values[1];
    __pyx_v_zeros = values[2];
  }
  goto __pyx_L4_argument_unpacking_done;
  __pyx_L5_argtuple_error:;
  __Pyx_RaiseArgtupleInvalid("unpack4", 1, 3, 3, PyTuple_GET_SIZE(__pyx_args)); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 237; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
  __pyx_L3_error:;
  __Pyx_AddTraceback("g2clib.unpack4", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __Pyx_RefNannyFinishContext();
  return NULL;
  __pyx_L4_argument_unpacking_done:;
  __pyx_r = __pyx_pf_6g2clib_8unpack4(__pyx_self, __pyx_v_gribmsg, __pyx_v_ipos, __pyx_v_zeros);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "g2clib.pyx":237
 *     return gds,gdtmpl,deflist,iofst/8
 * 
 * def unpack4(gribmsg,ipos,object zeros):             # <<<<<<<<<<<<<<
 *     """
 *  Unpacks Section 4 (Product Definition Section) as defined in GRIB Edition 2.
 */

static PyObject *__pyx_pf_6g2clib_8unpack4(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_gribmsg, PyObject *__pyx_v_ipos, PyObject *__pyx_v_zeros) {
  unsigned char *__pyx_v_cgrib;
  g2int *__pyx_v_ipdstmpl;
  g2float *__pyx_v_icoordlist;
  g2int __pyx_v_mappdslen;
  g2int __pyx_v_iofst;
  g2int __pyx_v_ipdsnum;
  g2int __pyx_v_ierr;
  g2int __pyx_v_numcoord;
  PyObject *__pyx_v_msg = NULL;
  PyObject *__pyx_v_pdtmpl = NULL;
  PyObject *__pyx_v_coordlist = NULL;
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  int __pyx_t_2;
  PyObject *__pyx_t_3 = NULL;
  PyObject *__pyx_t_4 = NULL;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("unpack4", 0);

  /* "g2clib.pyx":275
 *     cdef g2float *icoordlist
 *     cdef g2int mappdslen, iofst, ipdsnum, ierr, numcoord
 *     cgrib = <unsigned char *>PyBytes_AsString(gribmsg)             # <<<<<<<<<<<<<<
 *     iofst = <g2int>PyInt_AsLong(ipos*8)
 *     ierr=g2_unpack4(cgrib,&iofst,&ipdsnum,&ipdstmpl,&mappdslen,&icoordlist,&numcoord)
 */
  __pyx_v_cgrib = ((unsigned char *)PyBytes_AsString(__pyx_v_gribmsg));

  /* "g2clib.pyx":276
 *     cdef g2int mappdslen, iofst, ipdsnum, ierr, numcoord
 *     cgrib = <unsigned char *>PyBytes_AsString(gribmsg)
 *     iofst = <g2int>PyInt_AsLong(ipos*8)             # <<<<<<<<<<<<<<
 *     ierr=g2_unpack4(cgrib,&iofst,&ipdsnum,&ipdstmpl,&mappdslen,&icoordlist,&numcoord)
 *     if ierr != 0:
 */
  __pyx_t_1 = PyNumber_Multiply(__pyx_v_ipos, __pyx_int_8); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 276; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_v_iofst = ((g2int)PyInt_AsLong(__pyx_t_1));
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

  /* "g2clib.pyx":277
 *     cgrib = <unsigned char *>PyBytes_AsString(gribmsg)
 *     iofst = <g2int>PyInt_AsLong(ipos*8)
 *     ierr=g2_unpack4(cgrib,&iofst,&ipdsnum,&ipdstmpl,&mappdslen,&icoordlist,&numcoord)             # <<<<<<<<<<<<<<
 *     if ierr != 0:
 *        msg = "Error unpacking section 4 - error code = %i" % ierr
 */
  __pyx_v_ierr = g2_unpack4(__pyx_v_cgrib, (&__pyx_v_iofst), (&__pyx_v_ipdsnum), (&__pyx_v_ipdstmpl), (&__pyx_v_mappdslen), (&__pyx_v_icoordlist), (&__pyx_v_numcoord));

  /* "g2clib.pyx":278
 *     iofst = <g2int>PyInt_AsLong(ipos*8)
 *     ierr=g2_unpack4(cgrib,&iofst,&ipdsnum,&ipdstmpl,&mappdslen,&icoordlist,&numcoord)
 *     if ierr != 0:             # <<<<<<<<<<<<<<
 *        msg = "Error unpacking section 4 - error code = %i" % ierr
 *        raise RuntimeError(msg)
 */
  __pyx_t_2 = (__pyx_v_ierr != 0);
  if (__pyx_t_2) {

    /* "g2clib.pyx":279
 *     ierr=g2_unpack4(cgrib,&iofst,&ipdsnum,&ipdstmpl,&mappdslen,&icoordlist,&numcoord)
 *     if ierr != 0:
 *        msg = "Error unpacking section 4 - error code = %i" % ierr             # <<<<<<<<<<<<<<
 *        raise RuntimeError(msg)
 * 
 */
    __pyx_t_1 = __Pyx_PyInt_to_py_int32_t(__pyx_v_ierr); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 279; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_1);
    __pyx_t_3 = PyNumber_Remainder(((PyObject *)__pyx_kp_s_11), __pyx_t_1); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 279; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(((PyObject *)__pyx_t_3));
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
    __pyx_v_msg = ((PyObject *)__pyx_t_3);
    __pyx_t_3 = 0;

    /* "g2clib.pyx":280
 *     if ierr != 0:
 *        msg = "Error unpacking section 4 - error code = %i" % ierr
 *        raise RuntimeError(msg)             # <<<<<<<<<<<<<<
 * 
 *     pdtmpl = _toarray(ipdstmpl, zeros(mappdslen, 'i4'))
 */
    __pyx_t_3 = PyTuple_New(1); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 280; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_3);
    __Pyx_INCREF(__pyx_v_msg);
    PyTuple_SET_ITEM(__pyx_t_3, 0, __pyx_v_msg);
    __Pyx_GIVEREF(__pyx_v_msg);
    __pyx_t_1 = PyObject_Call(__pyx_builtin_RuntimeError, ((PyObject *)__pyx_t_3), NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 280; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_1);
    __Pyx_DECREF(((PyObject *)__pyx_t_3)); __pyx_t_3 = 0;
    __Pyx_Raise(__pyx_t_1, 0, 0, 0);
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
    {__pyx_filename = __pyx_f[0]; __pyx_lineno = 280; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    goto __pyx_L3;
  }
  __pyx_L3:;

  /* "g2clib.pyx":282
 *        raise RuntimeError(msg)
 * 
 *     pdtmpl = _toarray(ipdstmpl, zeros(mappdslen, 'i4'))             # <<<<<<<<<<<<<<
 *     coordlist = _toarray(icoordlist, zeros(numcoord, 'f4'))
 * 
 */
  __pyx_t_1 = __Pyx_PyInt_to_py_int32_t(__pyx_v_mappdslen); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 282; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_3 = PyTuple_New(2); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 282; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  PyTuple_SET_ITEM(__pyx_t_3, 0, __pyx_t_1);
  __Pyx_GIVEREF(__pyx_t_1);
  __Pyx_INCREF(((PyObject *)__pyx_n_s__i4));
  PyTuple_SET_ITEM(__pyx_t_3, 1, ((PyObject *)__pyx_n_s__i4));
  __Pyx_GIVEREF(((PyObject *)__pyx_n_s__i4));
  __pyx_t_1 = 0;
  __pyx_t_1 = PyObject_Call(__pyx_v_zeros, ((PyObject *)__pyx_t_3), NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 282; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_DECREF(((PyObject *)__pyx_t_3)); __pyx_t_3 = 0;
  __pyx_t_3 = __pyx_f_6g2clib__toarray(__pyx_v_ipdstmpl, __pyx_t_1); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 282; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_v_pdtmpl = __pyx_t_3;
  __pyx_t_3 = 0;

  /* "g2clib.pyx":283
 * 
 *     pdtmpl = _toarray(ipdstmpl, zeros(mappdslen, 'i4'))
 *     coordlist = _toarray(icoordlist, zeros(numcoord, 'f4'))             # <<<<<<<<<<<<<<
 * 
 *     return pdtmpl,ipdsnum,coordlist,iofst/8
 */
  __pyx_t_3 = __Pyx_PyInt_to_py_int32_t(__pyx_v_numcoord); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 283; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_t_1 = PyTuple_New(2); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 283; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  PyTuple_SET_ITEM(__pyx_t_1, 0, __pyx_t_3);
  __Pyx_GIVEREF(__pyx_t_3);
  __Pyx_INCREF(((PyObject *)__pyx_n_s__f4));
  PyTuple_SET_ITEM(__pyx_t_1, 1, ((PyObject *)__pyx_n_s__f4));
  __Pyx_GIVEREF(((PyObject *)__pyx_n_s__f4));
  __pyx_t_3 = 0;
  __pyx_t_3 = PyObject_Call(__pyx_v_zeros, ((PyObject *)__pyx_t_1), NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 283; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_DECREF(((PyObject *)__pyx_t_1)); __pyx_t_1 = 0;
  __pyx_t_1 = __pyx_f_6g2clib__toarray(__pyx_v_icoordlist, __pyx_t_3); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 283; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __pyx_v_coordlist = __pyx_t_1;
  __pyx_t_1 = 0;

  /* "g2clib.pyx":285
 *     coordlist = _toarray(icoordlist, zeros(numcoord, 'f4'))
 * 
 *     return pdtmpl,ipdsnum,coordlist,iofst/8             # <<<<<<<<<<<<<<
 * 
 * def unpack5(gribmsg,ipos,object zeros):
 */
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_1 = __Pyx_PyInt_to_py_int32_t(__pyx_v_ipdsnum); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 285; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_3 = PyInt_FromLong(__Pyx_div_long(__pyx_v_iofst, 8)); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 285; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_t_4 = PyTuple_New(4); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 285; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_4);
  __Pyx_INCREF(__pyx_v_pdtmpl);
  PyTuple_SET_ITEM(__pyx_t_4, 0, __pyx_v_pdtmpl);
  __Pyx_GIVEREF(__pyx_v_pdtmpl);
  PyTuple_SET_ITEM(__pyx_t_4, 1, __pyx_t_1);
  __Pyx_GIVEREF(__pyx_t_1);
  __Pyx_INCREF(__pyx_v_coordlist);
  PyTuple_SET_ITEM(__pyx_t_4, 2, __pyx_v_coordlist);
  __Pyx_GIVEREF(__pyx_v_coordlist);
  PyTuple_SET_ITEM(__pyx_t_4, 3, __pyx_t_3);
  __Pyx_GIVEREF(__pyx_t_3);
  __pyx_t_1 = 0;
  __pyx_t_3 = 0;
  __pyx_r = ((PyObject *)__pyx_t_4);
  __pyx_t_4 = 0;
  goto __pyx_L0;

  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_XDECREF(__pyx_t_3);
  __Pyx_XDECREF(__pyx_t_4);
  __Pyx_AddTraceback("g2clib.unpack4", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XDECREF(__pyx_v_msg);
  __Pyx_XDECREF(__pyx_v_pdtmpl);
  __Pyx_XDECREF(__pyx_v_coordlist);
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* Python wrapper */
static PyObject *__pyx_pw_6g2clib_11unpack5(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
static char __pyx_doc_6g2clib_10unpack5[] = "\n Unpacks Section 5 (Data Representation Section) as defined in GRIB Edition 2.\n\n drtmpl,drtnum,ndpts,ipos = unpack5(gribmsg,ipos)\n\n INPUTS:\n   gribmsg  - Character string containing Section 5 of the GRIB2 message\n   ipos     - Byte offset for the beginning of Section 5 in cgrib.\n   zeros   - Numeric/numpy array/scip.base zeros function (used to allocate\n             output python arrays).  Python is used to allocate the arrays\n             so no implementation-specific (Numeric, numpy array, scipy_core)\n             C API functions need to be used.  This means that any of these\n             array modules can be used simply by changing the import statement\n             in your python code.\n\n RETURNS:      \n   drtmpl  -  numpy array containing the data values for \n              the specified Data Representation\n              Template ( N=idrsnum ).  Each element of this integer\n              array contains an entry (in the order specified) of Data\n              Representation Template 5.N\n   drtnum   - Data Representation Template Number ( see Code Table 5.0)\n   ndpts    - Number of data points to be unpacked (in sxns 6 and 7).\n   ipos     - Byte offset at the end of Section 5.\n\n ERROR CODES: 2 = Not Section 5\n              6 = memory allocation error\n              7 = \"GRIB\" message contains an undefined Data\n                  Representation Template\n    ";
static PyMethodDef __pyx_mdef_6g2clib_11unpack5 = {__Pyx_NAMESTR("unpack5"), (PyCFunction)__pyx_pw_6g2clib_11unpack5, METH_VARARGS|METH_KEYWORDS, __Pyx_DOCSTR(__pyx_doc_6g2clib_10unpack5)};
static PyObject *__pyx_pw_6g2clib_11unpack5(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
  PyObject *__pyx_v_gribmsg = 0;
  PyObject *__pyx_v_ipos = 0;
  PyObject *__pyx_v_zeros = 0;
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("unpack5 (wrapper)", 0);
  {
    static PyObject **__pyx_pyargnames[] = {&__pyx_n_s__gribmsg,&__pyx_n_s__ipos,&__pyx_n_s__zeros,0};
    PyObject* values[3] = {0,0,0};
    if (unlikely(__pyx_kwds)) {
      Py_ssize_t kw_args;
      const Py_ssize_t pos_args = PyTuple_GET_SIZE(__pyx_args);
      switch (pos_args) {
        case  3: values[2] = PyTuple_GET_ITEM(__pyx_args, 2);
        case  2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
        case  1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
        case  0: break;
        default: goto __pyx_L5_argtuple_error;
      }
      kw_args = PyDict_Size(__pyx_kwds);
      switch (pos_args) {
        case  0:
        if (likely((values[0] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__gribmsg)) != 0)) kw_args--;
        else goto __pyx_L5_argtuple_error;
        case  1:
        if (likely((values[1] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__ipos)) != 0)) kw_args--;
        else {
          __Pyx_RaiseArgtupleInvalid("unpack5", 1, 3, 3, 1); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 287; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
        }
        case  2:
        if (likely((values[2] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__zeros)) != 0)) kw_args--;
        else {
          __Pyx_RaiseArgtupleInvalid("unpack5", 1, 3, 3, 2); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 287; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
        }
      }
      if (unlikely(kw_args > 0)) {
        if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "unpack5") < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 287; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
      }
    } else if (PyTuple_GET_SIZE(__pyx_args) != 3) {
      goto __pyx_L5_argtuple_error;
    } else {
      values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
      values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
      values[2] = PyTuple_GET_ITEM(__pyx_args, 2);
    }
    __pyx_v_gribmsg = values[0];
    __pyx_v_ipos = values[1];
    __pyx_v_zeros = values[2];
  }
  goto __pyx_L4_argument_unpacking_done;
  __pyx_L5_argtuple_error:;
  __Pyx_RaiseArgtupleInvalid("unpack5", 1, 3, 3, PyTuple_GET_SIZE(__pyx_args)); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 287; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
  __pyx_L3_error:;
  __Pyx_AddTraceback("g2clib.unpack5", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __Pyx_RefNannyFinishContext();
  return NULL;
  __pyx_L4_argument_unpacking_done:;
  __pyx_r = __pyx_pf_6g2clib_10unpack5(__pyx_self, __pyx_v_gribmsg, __pyx_v_ipos, __pyx_v_zeros);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "g2clib.pyx":287
 *     return pdtmpl,ipdsnum,coordlist,iofst/8
 * 
 * def unpack5(gribmsg,ipos,object zeros):             # <<<<<<<<<<<<<<
 *     """
 *  Unpacks Section 5 (Data Representation Section) as defined in GRIB Edition 2.
 */

static PyObject *__pyx_pf_6g2clib_10unpack5(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_gribmsg, PyObject *__pyx_v_ipos, PyObject *__pyx_v_zeros) {
  unsigned char *__pyx_v_cgrib;
  g2int *__pyx_v_idrstmpl;
  g2int __pyx_v_iofst;
  g2int __pyx_v_ierr;
  g2int __pyx_v_ndpts;
  g2int __pyx_v_idrsnum;
  g2int __pyx_v_mapdrslen;
  PyObject *__pyx_v_msg = NULL;
  PyObject *__pyx_v_drtmpl = NULL;
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  int __pyx_t_2;
  PyObject *__pyx_t_3 = NULL;
  PyObject *__pyx_t_4 = NULL;
  PyObject *__pyx_t_5 = NULL;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("unpack5", 0);

  /* "g2clib.pyx":321
 *     cdef g2int *idrstmpl
 *     cdef g2int iofst, ierr, ndpts, idrsnum, mapdrslen
 *     cgrib = <unsigned char *>PyBytes_AsString(gribmsg)             # <<<<<<<<<<<<<<
 *     iofst = <g2int>PyInt_AsLong(ipos*8)
 *     ierr=g2_unpack5(cgrib,&iofst,&ndpts,&idrsnum,&idrstmpl,&mapdrslen)
 */
  __pyx_v_cgrib = ((unsigned char *)PyBytes_AsString(__pyx_v_gribmsg));

  /* "g2clib.pyx":322
 *     cdef g2int iofst, ierr, ndpts, idrsnum, mapdrslen
 *     cgrib = <unsigned char *>PyBytes_AsString(gribmsg)
 *     iofst = <g2int>PyInt_AsLong(ipos*8)             # <<<<<<<<<<<<<<
 *     ierr=g2_unpack5(cgrib,&iofst,&ndpts,&idrsnum,&idrstmpl,&mapdrslen)
 *     if ierr != 0:
 */
  __pyx_t_1 = PyNumber_Multiply(__pyx_v_ipos, __pyx_int_8); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 322; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_v_iofst = ((g2int)PyInt_AsLong(__pyx_t_1));
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

  /* "g2clib.pyx":323
 *     cgrib = <unsigned char *>PyBytes_AsString(gribmsg)
 *     iofst = <g2int>PyInt_AsLong(ipos*8)
 *     ierr=g2_unpack5(cgrib,&iofst,&ndpts,&idrsnum,&idrstmpl,&mapdrslen)             # <<<<<<<<<<<<<<
 *     if ierr != 0:
 *        msg = "Error unpacking section 5 - error code = %i" % ierr
 */
  __pyx_v_ierr = g2_unpack5(__pyx_v_cgrib, (&__pyx_v_iofst), (&__pyx_v_ndpts), (&__pyx_v_idrsnum), (&__pyx_v_idrstmpl), (&__pyx_v_mapdrslen));

  /* "g2clib.pyx":324
 *     iofst = <g2int>PyInt_AsLong(ipos*8)
 *     ierr=g2_unpack5(cgrib,&iofst,&ndpts,&idrsnum,&idrstmpl,&mapdrslen)
 *     if ierr != 0:             # <<<<<<<<<<<<<<
 *        msg = "Error unpacking section 5 - error code = %i" % ierr
 *        raise RuntimeError(msg)
 */
  __pyx_t_2 = (__pyx_v_ierr != 0);
  if (__pyx_t_2) {

    /* "g2clib.pyx":325
 *     ierr=g2_unpack5(cgrib,&iofst,&ndpts,&idrsnum,&idrstmpl,&mapdrslen)
 *     if ierr != 0:
 *        msg = "Error unpacking section 5 - error code = %i" % ierr             # <<<<<<<<<<<<<<
 *        raise RuntimeError(msg)
 * 
 */
    __pyx_t_1 = __Pyx_PyInt_to_py_int32_t(__pyx_v_ierr); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 325; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_1);
    __pyx_t_3 = PyNumber_Remainder(((PyObject *)__pyx_kp_s_12), __pyx_t_1); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 325; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(((PyObject *)__pyx_t_3));
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
    __pyx_v_msg = ((PyObject *)__pyx_t_3);
    __pyx_t_3 = 0;

    /* "g2clib.pyx":326
 *     if ierr != 0:
 *        msg = "Error unpacking section 5 - error code = %i" % ierr
 *        raise RuntimeError(msg)             # <<<<<<<<<<<<<<
 * 
 *     drtmpl = _toarray(idrstmpl, zeros(mapdrslen, 'i4'))
 */
    __pyx_t_3 = PyTuple_New(1); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 326; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_3);
    __Pyx_INCREF(__pyx_v_msg);
    PyTuple_SET_ITEM(__pyx_t_3, 0, __pyx_v_msg);
    __Pyx_GIVEREF(__pyx_v_msg);
    __pyx_t_1 = PyObject_Call(__pyx_builtin_RuntimeError, ((PyObject *)__pyx_t_3), NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 326; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_1);
    __Pyx_DECREF(((PyObject *)__pyx_t_3)); __pyx_t_3 = 0;
    __Pyx_Raise(__pyx_t_1, 0, 0, 0);
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
    {__pyx_filename = __pyx_f[0]; __pyx_lineno = 326; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    goto __pyx_L3;
  }
  __pyx_L3:;

  /* "g2clib.pyx":328
 *        raise RuntimeError(msg)
 * 
 *     drtmpl = _toarray(idrstmpl, zeros(mapdrslen, 'i4'))             # <<<<<<<<<<<<<<
 *     return drtmpl,idrsnum,ndpts,iofst/8
 * 
 */
  __pyx_t_1 = __Pyx_PyInt_to_py_int32_t(__pyx_v_mapdrslen); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 328; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_3 = PyTuple_New(2); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 328; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  PyTuple_SET_ITEM(__pyx_t_3, 0, __pyx_t_1);
  __Pyx_GIVEREF(__pyx_t_1);
  __Pyx_INCREF(((PyObject *)__pyx_n_s__i4));
  PyTuple_SET_ITEM(__pyx_t_3, 1, ((PyObject *)__pyx_n_s__i4));
  __Pyx_GIVEREF(((PyObject *)__pyx_n_s__i4));
  __pyx_t_1 = 0;
  __pyx_t_1 = PyObject_Call(__pyx_v_zeros, ((PyObject *)__pyx_t_3), NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 328; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_DECREF(((PyObject *)__pyx_t_3)); __pyx_t_3 = 0;
  __pyx_t_3 = __pyx_f_6g2clib__toarray(__pyx_v_idrstmpl, __pyx_t_1); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 328; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_v_drtmpl = __pyx_t_3;
  __pyx_t_3 = 0;

  /* "g2clib.pyx":329
 * 
 *     drtmpl = _toarray(idrstmpl, zeros(mapdrslen, 'i4'))
 *     return drtmpl,idrsnum,ndpts,iofst/8             # <<<<<<<<<<<<<<
 * 
 * def unpack6(gribmsg,ndpts,ipos,object zeros):
 */
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_3 = __Pyx_PyInt_to_py_int32_t(__pyx_v_idrsnum); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 329; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_t_1 = __Pyx_PyInt_to_py_int32_t(__pyx_v_ndpts); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 329; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_4 = PyInt_FromLong(__Pyx_div_long(__pyx_v_iofst, 8)); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 329; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_4);
  __pyx_t_5 = PyTuple_New(4); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 329; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_5);
  __Pyx_INCREF(__pyx_v_drtmpl);
  PyTuple_SET_ITEM(__pyx_t_5, 0, __pyx_v_drtmpl);
  __Pyx_GIVEREF(__pyx_v_drtmpl);
  PyTuple_SET_ITEM(__pyx_t_5, 1, __pyx_t_3);
  __Pyx_GIVEREF(__pyx_t_3);
  PyTuple_SET_ITEM(__pyx_t_5, 2, __pyx_t_1);
  __Pyx_GIVEREF(__pyx_t_1);
  PyTuple_SET_ITEM(__pyx_t_5, 3, __pyx_t_4);
  __Pyx_GIVEREF(__pyx_t_4);
  __pyx_t_3 = 0;
  __pyx_t_1 = 0;
  __pyx_t_4 = 0;
  __pyx_r = ((PyObject *)__pyx_t_5);
  __pyx_t_5 = 0;
  goto __pyx_L0;

  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_XDECREF(__pyx_t_3);
  __Pyx_XDECREF(__pyx_t_4);
  __Pyx_XDECREF(__pyx_t_5);
  __Pyx_AddTraceback("g2clib.unpack5", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XDECREF(__pyx_v_msg);
  __Pyx_XDECREF(__pyx_v_drtmpl);
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* Python wrapper */
static PyObject *__pyx_pw_6g2clib_13unpack6(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
static char __pyx_doc_6g2clib_12unpack6[] = "\n Unpacks Section 6 (Bit-Map Section) as defined in GRIB Edition 2.\n\n bitmap = unpack6(gribmsg,ndpts,ipos)         \n\n INPUTS:\n   gribmsg  - String containing Section 6 of the GRIB2 message\n   ndpts    - Number of grid points specified in the bit-map (from\n              gds[1] returned by unpack3).\n   ipos     - Byte offset of the beginning of Section 6 in cgrib.\n   zeros   - Numeric/numpy array/scip.base zeros function (used to allocate\n            output python arrays).  Python is used to allocate the arrays\n            so no implementation-specific (Numeric, numpy array, scipy_core)\n            C API functions need to be used.  This means that any of these\n            array modules can be used simply by changing the import statement\n            in your python code.\n RETURNS:      \n   bmap     - numpy array array containing decoded bitmap. \n              ( if ibmap=0 ).  Otherwise None.\n   ibmap    - Bitmap indicator ( see Code Table 6.0 )\n              0 = bitmap applies and is included in Section 6.\n              1-253 = Predefined bitmap applies\n              254 = Previously defined bitmap applies to this field\n ERROR CODES: 2 = Not Section 6\n              4 = Unrecognized pre-defined bit-map.\n              6 = memory allocation error\n    ";
static PyMethodDef __pyx_mdef_6g2clib_13unpack6 = {__Pyx_NAMESTR("unpack6"), (PyCFunction)__pyx_pw_6g2clib_13unpack6, METH_VARARGS|METH_KEYWORDS, __Pyx_DOCSTR(__pyx_doc_6g2clib_12unpack6)};
static PyObject *__pyx_pw_6g2clib_13unpack6(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
  PyObject *__pyx_v_gribmsg = 0;
  PyObject *__pyx_v_ndpts = 0;
  PyObject *__pyx_v_ipos = 0;
  PyObject *__pyx_v_zeros = 0;
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("unpack6 (wrapper)", 0);
  {
    static PyObject **__pyx_pyargnames[] = {&__pyx_n_s__gribmsg,&__pyx_n_s__ndpts,&__pyx_n_s__ipos,&__pyx_n_s__zeros,0};
    PyObject* values[4] = {0,0,0,0};
    if (unlikely(__pyx_kwds)) {
      Py_ssize_t kw_args;
      const Py_ssize_t pos_args = PyTuple_GET_SIZE(__pyx_args);
      switch (pos_args) {
        case  4: values[3] = PyTuple_GET_ITEM(__pyx_args, 3);
        case  3: values[2] = PyTuple_GET_ITEM(__pyx_args, 2);
        case  2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
        case  1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
        case  0: break;
        default: goto __pyx_L5_argtuple_error;
      }
      kw_args = PyDict_Size(__pyx_kwds);
      switch (pos_args) {
        case  0:
        if (likely((values[0] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__gribmsg)) != 0)) kw_args--;
        else goto __pyx_L5_argtuple_error;
        case  1:
        if (likely((values[1] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__ndpts)) != 0)) kw_args--;
        else {
          __Pyx_RaiseArgtupleInvalid("unpack6", 1, 4, 4, 1); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 331; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
        }
        case  2:
        if (likely((values[2] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__ipos)) != 0)) kw_args--;
        else {
          __Pyx_RaiseArgtupleInvalid("unpack6", 1, 4, 4, 2); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 331; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
        }
        case  3:
        if (likely((values[3] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__zeros)) != 0)) kw_args--;
        else {
          __Pyx_RaiseArgtupleInvalid("unpack6", 1, 4, 4, 3); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 331; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
        }
      }
      if (unlikely(kw_args > 0)) {
        if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "unpack6") < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 331; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
      }
    } else if (PyTuple_GET_SIZE(__pyx_args) != 4) {
      goto __pyx_L5_argtuple_error;
    } else {
      values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
      values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
      values[2] = PyTuple_GET_ITEM(__pyx_args, 2);
      values[3] = PyTuple_GET_ITEM(__pyx_args, 3);
    }
    __pyx_v_gribmsg = values[0];
    __pyx_v_ndpts = values[1];
    __pyx_v_ipos = values[2];
    __pyx_v_zeros = values[3];
  }
  goto __pyx_L4_argument_unpacking_done;
  __pyx_L5_argtuple_error:;
  __Pyx_RaiseArgtupleInvalid("unpack6", 1, 4, 4, PyTuple_GET_SIZE(__pyx_args)); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 331; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
  __pyx_L3_error:;
  __Pyx_AddTraceback("g2clib.unpack6", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __Pyx_RefNannyFinishContext();
  return NULL;
  __pyx_L4_argument_unpacking_done:;
  __pyx_r = __pyx_pf_6g2clib_12unpack6(__pyx_self, __pyx_v_gribmsg, __pyx_v_ndpts, __pyx_v_ipos, __pyx_v_zeros);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "g2clib.pyx":331
 *     return drtmpl,idrsnum,ndpts,iofst/8
 * 
 * def unpack6(gribmsg,ndpts,ipos,object zeros):             # <<<<<<<<<<<<<<
 *     """
 *  Unpacks Section 6 (Bit-Map Section) as defined in GRIB Edition 2.
 */

static PyObject *__pyx_pf_6g2clib_12unpack6(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_gribmsg, PyObject *__pyx_v_ndpts, PyObject *__pyx_v_ipos, PyObject *__pyx_v_zeros) {
  PyObject *__pyx_v_bitmap = 0;
  unsigned char *__pyx_v_cgrib;
  g2int __pyx_v_iofst;
  g2int __pyx_v_ierr;
  g2int __pyx_v_ngpts;
  g2int __pyx_v_ibmap;
  g2int *__pyx_v_bmap;
  PyObject *__pyx_v_msg = NULL;
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  int __pyx_t_2;
  PyObject *__pyx_t_3 = NULL;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("unpack6", 0);

  /* "g2clib.pyx":363
 *     cdef g2int iofst, ierr, ngpts, ibmap
 *     cdef g2int *bmap
 *     cgrib = <unsigned char *>PyBytes_AsString(gribmsg)             # <<<<<<<<<<<<<<
 *     iofst = <g2int>PyInt_AsLong(ipos*8)
 *     ngpts = <g2int>PyInt_AsLong(ndpts)
 */
  __pyx_v_cgrib = ((unsigned char *)PyBytes_AsString(__pyx_v_gribmsg));

  /* "g2clib.pyx":364
 *     cdef g2int *bmap
 *     cgrib = <unsigned char *>PyBytes_AsString(gribmsg)
 *     iofst = <g2int>PyInt_AsLong(ipos*8)             # <<<<<<<<<<<<<<
 *     ngpts = <g2int>PyInt_AsLong(ndpts)
 *     ierr=g2_unpack6(cgrib,&iofst,ngpts,&ibmap,&bmap)
 */
  __pyx_t_1 = PyNumber_Multiply(__pyx_v_ipos, __pyx_int_8); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 364; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_v_iofst = ((g2int)PyInt_AsLong(__pyx_t_1));
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

  /* "g2clib.pyx":365
 *     cgrib = <unsigned char *>PyBytes_AsString(gribmsg)
 *     iofst = <g2int>PyInt_AsLong(ipos*8)
 *     ngpts = <g2int>PyInt_AsLong(ndpts)             # <<<<<<<<<<<<<<
 *     ierr=g2_unpack6(cgrib,&iofst,ngpts,&ibmap,&bmap)
 *     if ierr != 0:
 */
  __pyx_v_ngpts = ((g2int)PyInt_AsLong(__pyx_v_ndpts));

  /* "g2clib.pyx":366
 *     iofst = <g2int>PyInt_AsLong(ipos*8)
 *     ngpts = <g2int>PyInt_AsLong(ndpts)
 *     ierr=g2_unpack6(cgrib,&iofst,ngpts,&ibmap,&bmap)             # <<<<<<<<<<<<<<
 *     if ierr != 0:
 *         msg = "Error unpacking section 6 - error code = %i" % ierr
 */
  __pyx_v_ierr = g2_unpack6(__pyx_v_cgrib, (&__pyx_v_iofst), __pyx_v_ngpts, (&__pyx_v_ibmap), (&__pyx_v_bmap));

  /* "g2clib.pyx":367
 *     ngpts = <g2int>PyInt_AsLong(ndpts)
 *     ierr=g2_unpack6(cgrib,&iofst,ngpts,&ibmap,&bmap)
 *     if ierr != 0:             # <<<<<<<<<<<<<<
 *         msg = "Error unpacking section 6 - error code = %i" % ierr
 *         raise RuntimeError(msg)
 */
  __pyx_t_2 = (__pyx_v_ierr != 0);
  if (__pyx_t_2) {

    /* "g2clib.pyx":368
 *     ierr=g2_unpack6(cgrib,&iofst,ngpts,&ibmap,&bmap)
 *     if ierr != 0:
 *         msg = "Error unpacking section 6 - error code = %i" % ierr             # <<<<<<<<<<<<<<
 *         raise RuntimeError(msg)
 *     if ibmap == 0:
 */
    __pyx_t_1 = __Pyx_PyInt_to_py_int32_t(__pyx_v_ierr); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 368; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_1);
    __pyx_t_3 = PyNumber_Remainder(((PyObject *)__pyx_kp_s_13), __pyx_t_1); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 368; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(((PyObject *)__pyx_t_3));
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
    __pyx_v_msg = ((PyObject *)__pyx_t_3);
    __pyx_t_3 = 0;

    /* "g2clib.pyx":369
 *     if ierr != 0:
 *         msg = "Error unpacking section 6 - error code = %i" % ierr
 *         raise RuntimeError(msg)             # <<<<<<<<<<<<<<
 *     if ibmap == 0:
 *         bitmap = _toarray(bmap, zeros(ngpts, 'i4'))
 */
    __pyx_t_3 = PyTuple_New(1); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 369; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_3);
    __Pyx_INCREF(__pyx_v_msg);
    PyTuple_SET_ITEM(__pyx_t_3, 0, __pyx_v_msg);
    __Pyx_GIVEREF(__pyx_v_msg);
    __pyx_t_1 = PyObject_Call(__pyx_builtin_RuntimeError, ((PyObject *)__pyx_t_3), NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 369; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_1);
    __Pyx_DECREF(((PyObject *)__pyx_t_3)); __pyx_t_3 = 0;
    __Pyx_Raise(__pyx_t_1, 0, 0, 0);
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
    {__pyx_filename = __pyx_f[0]; __pyx_lineno = 369; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    goto __pyx_L3;
  }
  __pyx_L3:;

  /* "g2clib.pyx":370
 *         msg = "Error unpacking section 6 - error code = %i" % ierr
 *         raise RuntimeError(msg)
 *     if ibmap == 0:             # <<<<<<<<<<<<<<
 *         bitmap = _toarray(bmap, zeros(ngpts, 'i4'))
 *     else:
 */
  __pyx_t_2 = (__pyx_v_ibmap == 0);
  if (__pyx_t_2) {

    /* "g2clib.pyx":371
 *         raise RuntimeError(msg)
 *     if ibmap == 0:
 *         bitmap = _toarray(bmap, zeros(ngpts, 'i4'))             # <<<<<<<<<<<<<<
 *     else:
 *         bitmap = None
 */
    __pyx_t_1 = __Pyx_PyInt_to_py_int32_t(__pyx_v_ngpts); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 371; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_1);
    __pyx_t_3 = PyTuple_New(2); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 371; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_3);
    PyTuple_SET_ITEM(__pyx_t_3, 0, __pyx_t_1);
    __Pyx_GIVEREF(__pyx_t_1);
    __Pyx_INCREF(((PyObject *)__pyx_n_s__i4));
    PyTuple_SET_ITEM(__pyx_t_3, 1, ((PyObject *)__pyx_n_s__i4));
    __Pyx_GIVEREF(((PyObject *)__pyx_n_s__i4));
    __pyx_t_1 = 0;
    __pyx_t_1 = PyObject_Call(__pyx_v_zeros, ((PyObject *)__pyx_t_3), NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 371; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_1);
    __Pyx_DECREF(((PyObject *)__pyx_t_3)); __pyx_t_3 = 0;
    __pyx_t_3 = __pyx_f_6g2clib__toarray(__pyx_v_bmap, __pyx_t_1); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 371; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_3);
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
    __pyx_v_bitmap = __pyx_t_3;
    __pyx_t_3 = 0;
    goto __pyx_L4;
  }
  /*else*/ {

    /* "g2clib.pyx":373
 *         bitmap = _toarray(bmap, zeros(ngpts, 'i4'))
 *     else:
 *         bitmap = None             # <<<<<<<<<<<<<<
 *         free(bmap)
 *     return bitmap,ibmap
 */
    __Pyx_INCREF(Py_None);
    __pyx_v_bitmap = Py_None;

    /* "g2clib.pyx":374
 *     else:
 *         bitmap = None
 *         free(bmap)             # <<<<<<<<<<<<<<
 *     return bitmap,ibmap
 * 
 */
    free(__pyx_v_bmap);
  }
  __pyx_L4:;

  /* "g2clib.pyx":375
 *         bitmap = None
 *         free(bmap)
 *     return bitmap,ibmap             # <<<<<<<<<<<<<<
 * 
 * def unpack7(gribmsg,gdtnum,object gdtmpl,drtnum,object drtmpl,ndpts,ipos,object zeros,printminmax=False,storageorder='C'):
 */
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_3 = __Pyx_PyInt_to_py_int32_t(__pyx_v_ibmap); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 375; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_t_1 = PyTuple_New(2); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 375; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_INCREF(__pyx_v_bitmap);
  PyTuple_SET_ITEM(__pyx_t_1, 0, __pyx_v_bitmap);
  __Pyx_GIVEREF(__pyx_v_bitmap);
  PyTuple_SET_ITEM(__pyx_t_1, 1, __pyx_t_3);
  __Pyx_GIVEREF(__pyx_t_3);
  __pyx_t_3 = 0;
  __pyx_r = ((PyObject *)__pyx_t_1);
  __pyx_t_1 = 0;
  goto __pyx_L0;

  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_XDECREF(__pyx_t_3);
  __Pyx_AddTraceback("g2clib.unpack6", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XDECREF(__pyx_v_bitmap);
  __Pyx_XDECREF(__pyx_v_msg);
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* Python wrapper */
static PyObject *__pyx_pw_6g2clib_15unpack7(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
static char __pyx_doc_6g2clib_14unpack7[] = "\n Unpacks Section 7 (Data Section) as defined in GRIB Edition 2.\n\n fld,fldmin,fldmax = unpack7(gribmsg,gdtnum,gdtmpl,drtnum,drtmpl,ndpts,ipos)\n INPUTS:\n   gribmsg  - String containing Section 7 of the GRIB2 message\n   gdtnum   - Grid Definition Template Number ( see Code Table 3.0)\n              ( Only used for DRS Template 5.51 )\n   gdtmpl   - numpy array containing the data values for\n              the specified Grid Definition\n              Template ( N=igdsnum ).  Each element of this integer\n              array contains an entry (in the order specified) of Grid\n              Definition Template 3.N\n              ( Only used for DRS Template 5.51 )\n   drtnum   - Data Representation Template Number ( see Code Table 5.0)\n   drtmpl   - numpy array containing the data values for\n              the specified Data Representation\n              Template ( N=idrsnum ).  Each element of this integer\n              array contains an entry (in the order specified) of Data\n              Representation Template 5.N\n   ndpts    - Number of data points unpacked and returned.\n   ipos     - Byte offset of the beginning of Section 7 in cgrib.\n   zeros   - Numeric/numpy array/scip.base zeros function (used to allocate\n            output python arrays).  Python is used to allocate the arrays\n            so no implementation-specific (Numeric, numpy array, scipy_core)\n            C API functions need to be used.  This means that any of these\n            array modules can be used simply by changing the import statement\n            in your python code.\n   storageorder - 'C' for row-major, or 'F' for column-major (Default 'C')\n   printminmax - if True, min/max of fld is printed.\n\n RETURNS:      \n   fld      - numpy array (float32) containing the unpacked data field.\n\n ERROR CODES: 2 = Not section 7\n              4 = Unrecognized Data Representation Template\n              5 = need one of GDT 3.50 through 3.53 to decode DRT 5.51\n              6 = memory ""allocation error\n    ";
static PyMethodDef __pyx_mdef_6g2clib_15unpack7 = {__Pyx_NAMESTR("unpack7"), (PyCFunction)__pyx_pw_6g2clib_15unpack7, METH_VARARGS|METH_KEYWORDS, __Pyx_DOCSTR(__pyx_doc_6g2clib_14unpack7)};
static PyObject *__pyx_pw_6g2clib_15unpack7(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
  PyObject *__pyx_v_gribmsg = 0;
  PyObject *__pyx_v_gdtnum = 0;
  PyObject *__pyx_v_gdtmpl = 0;
  PyObject *__pyx_v_drtnum = 0;
  PyObject *__pyx_v_drtmpl = 0;
  PyObject *__pyx_v_ndpts = 0;
  PyObject *__pyx_v_ipos = 0;
  PyObject *__pyx_v_zeros = 0;
  PyObject *__pyx_v_printminmax = 0;
  PyObject *__pyx_v_storageorder = 0;
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("unpack7 (wrapper)", 0);
  {
    static PyObject **__pyx_pyargnames[] = {&__pyx_n_s__gribmsg,&__pyx_n_s__gdtnum,&__pyx_n_s__gdtmpl,&__pyx_n_s__drtnum,&__pyx_n_s__drtmpl,&__pyx_n_s__ndpts,&__pyx_n_s__ipos,&__pyx_n_s__zeros,&__pyx_n_s__printminmax,&__pyx_n_s__storageorder,0};
    PyObject* values[10] = {0,0,0,0,0,0,0,0,0,0};
    values[8] = __pyx_k_14;
    values[9] = ((PyObject *)__pyx_n_s__C);
    if (unlikely(__pyx_kwds)) {
      Py_ssize_t kw_args;
      const Py_ssize_t pos_args = PyTuple_GET_SIZE(__pyx_args);
      switch (pos_args) {
        case 10: values[9] = PyTuple_GET_ITEM(__pyx_args, 9);
        case  9: values[8] = PyTuple_GET_ITEM(__pyx_args, 8);
        case  8: values[7] = PyTuple_GET_ITEM(__pyx_args, 7);
        case  7: values[6] = PyTuple_GET_ITEM(__pyx_args, 6);
        case  6: values[5] = PyTuple_GET_ITEM(__pyx_args, 5);
        case  5: values[4] = PyTuple_GET_ITEM(__pyx_args, 4);
        case  4: values[3] = PyTuple_GET_ITEM(__pyx_args, 3);
        case  3: values[2] = PyTuple_GET_ITEM(__pyx_args, 2);
        case  2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
        case  1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
        case  0: break;
        default: goto __pyx_L5_argtuple_error;
      }
      kw_args = PyDict_Size(__pyx_kwds);
      switch (pos_args) {
        case  0:
        if (likely((values[0] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__gribmsg)) != 0)) kw_args--;
        else goto __pyx_L5_argtuple_error;
        case  1:
        if (likely((values[1] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__gdtnum)) != 0)) kw_args--;
        else {
          __Pyx_RaiseArgtupleInvalid("unpack7", 0, 8, 10, 1); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 377; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
        }
        case  2:
        if (likely((values[2] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__gdtmpl)) != 0)) kw_args--;
        else {
          __Pyx_RaiseArgtupleInvalid("unpack7", 0, 8, 10, 2); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 377; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
        }
        case  3:
        if (likely((values[3] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__drtnum)) != 0)) kw_args--;
        else {
          __Pyx_RaiseArgtupleInvalid("unpack7", 0, 8, 10, 3); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 377; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
        }
        case  4:
        if (likely((values[4] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__drtmpl)) != 0)) kw_args--;
        else {
          __Pyx_RaiseArgtupleInvalid("unpack7", 0, 8, 10, 4); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 377; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
        }
        case  5:
        if (likely((values[5] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__ndpts)) != 0)) kw_args--;
        else {
          __Pyx_RaiseArgtupleInvalid("unpack7", 0, 8, 10, 5); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 377; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
        }
        case  6:
        if (likely((values[6] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__ipos)) != 0)) kw_args--;
        else {
          __Pyx_RaiseArgtupleInvalid("unpack7", 0, 8, 10, 6); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 377; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
        }
        case  7:
        if (likely((values[7] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__zeros)) != 0)) kw_args--;
        else {
          __Pyx_RaiseArgtupleInvalid("unpack7", 0, 8, 10, 7); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 377; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
        }
        case  8:
        if (kw_args > 0) {
          PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s__printminmax);
          if (value) { values[8] = value; kw_args--; }
        }
        case  9:
        if (kw_args > 0) {
          PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s__storageorder);
          if (value) { values[9] = value; kw_args--; }
        }
      }
      if (unlikely(kw_args > 0)) {
        if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "unpack7") < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 377; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
      }
    } else {
      switch (PyTuple_GET_SIZE(__pyx_args)) {
        case 10: values[9] = PyTuple_GET_ITEM(__pyx_args, 9);
        case  9: values[8] = PyTuple_GET_ITEM(__pyx_args, 8);
        case  8: values[7] = PyTuple_GET_ITEM(__pyx_args, 7);
        values[6] = PyTuple_GET_ITEM(__pyx_args, 6);
        values[5] = PyTuple_GET_ITEM(__pyx_args, 5);
        values[4] = PyTuple_GET_ITEM(__pyx_args, 4);
        values[3] = PyTuple_GET_ITEM(__pyx_args, 3);
        values[2] = PyTuple_GET_ITEM(__pyx_args, 2);
        values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
        values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
        break;
        default: goto __pyx_L5_argtuple_error;
      }
    }
    __pyx_v_gribmsg = values[0];
    __pyx_v_gdtnum = values[1];
    __pyx_v_gdtmpl = values[2];
    __pyx_v_drtnum = values[3];
    __pyx_v_drtmpl = values[4];
    __pyx_v_ndpts = values[5];
    __pyx_v_ipos = values[6];
    __pyx_v_zeros = values[7];
    __pyx_v_printminmax = values[8];
    __pyx_v_storageorder = values[9];
  }
  goto __pyx_L4_argument_unpacking_done;
  __pyx_L5_argtuple_error:;
  __Pyx_RaiseArgtupleInvalid("unpack7", 0, 8, 10, PyTuple_GET_SIZE(__pyx_args)); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 377; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
  __pyx_L3_error:;
  __Pyx_AddTraceback("g2clib.unpack7", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __Pyx_RefNannyFinishContext();
  return NULL;
  __pyx_L4_argument_unpacking_done:;
  __pyx_r = __pyx_pf_6g2clib_14unpack7(__pyx_self, __pyx_v_gribmsg, __pyx_v_gdtnum, __pyx_v_gdtmpl, __pyx_v_drtnum, __pyx_v_drtmpl, __pyx_v_ndpts, __pyx_v_ipos, __pyx_v_zeros, __pyx_v_printminmax, __pyx_v_storageorder);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "g2clib.pyx":377
 *     return bitmap,ibmap
 * 
 * def unpack7(gribmsg,gdtnum,object gdtmpl,drtnum,object drtmpl,ndpts,ipos,object zeros,printminmax=False,storageorder='C'):             # <<<<<<<<<<<<<<
 *     """
 *  Unpacks Section 7 (Data Section) as defined in GRIB Edition 2.
 */

static PyObject *__pyx_pf_6g2clib_14unpack7(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_gribmsg, PyObject *__pyx_v_gdtnum, PyObject *__pyx_v_gdtmpl, PyObject *__pyx_v_drtnum, PyObject *__pyx_v_drtmpl, PyObject *__pyx_v_ndpts, PyObject *__pyx_v_ipos, PyObject *__pyx_v_zeros, PyObject *__pyx_v_printminmax, PyObject *__pyx_v_storageorder) {
  unsigned char *__pyx_v_cgrib;
  g2int __pyx_v_iofst;
  g2int __pyx_v_ierr;
  g2int __pyx_v_ngpts;
  g2int __pyx_v_idrsnum;
  g2int __pyx_v_igdsnum;
  g2int *__pyx_v_igdstmpl;
  g2int *__pyx_v_idrstmpl;
  g2float *__pyx_v_fld;
  void *__pyx_v_drtmpldat;
  void *__pyx_v_gdtmpldat;
  float __pyx_v_rmin;
  float __pyx_v_rmax;
  int __pyx_v_n;
  Py_ssize_t __pyx_v_buflen;
  PyObject *__pyx_v_msg = NULL;
  PyObject *__pyx_v_fldmax = NULL;
  PyObject *__pyx_v_fldmin = NULL;
  PyObject *__pyx_v_bitsofprecision = NULL;
  PyObject *__pyx_v_digitsofprecision = NULL;
  PyObject *__pyx_v_format = NULL;
  PyObject *__pyx_v_minmaxstring = NULL;
  PyObject *__pyx_v_data = NULL;
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  int __pyx_t_2;
  PyObject *__pyx_t_3 = NULL;
  int __pyx_t_4;
  PyObject *__pyx_t_5 = NULL;
  PyObject *__pyx_t_6 = NULL;
  PyObject *__pyx_t_7 = NULL;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("unpack7", 0);

  /* "g2clib.pyx":425
 *     cdef int n
 *     cdef Py_ssize_t buflen
 *     cgrib = <unsigned char *>PyBytes_AsString(gribmsg)             # <<<<<<<<<<<<<<
 *     iofst = <g2int>PyInt_AsLong(ipos*8)
 *     ngpts = <g2int>PyInt_AsLong(ndpts)
 */
  __pyx_v_cgrib = ((unsigned char *)PyBytes_AsString(__pyx_v_gribmsg));

  /* "g2clib.pyx":426
 *     cdef Py_ssize_t buflen
 *     cgrib = <unsigned char *>PyBytes_AsString(gribmsg)
 *     iofst = <g2int>PyInt_AsLong(ipos*8)             # <<<<<<<<<<<<<<
 *     ngpts = <g2int>PyInt_AsLong(ndpts)
 *     idrsnum = <g2int>PyInt_AsLong(drtnum)
 */
  __pyx_t_1 = PyNumber_Multiply(__pyx_v_ipos, __pyx_int_8); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 426; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_v_iofst = ((g2int)PyInt_AsLong(__pyx_t_1));
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

  /* "g2clib.pyx":427
 *     cgrib = <unsigned char *>PyBytes_AsString(gribmsg)
 *     iofst = <g2int>PyInt_AsLong(ipos*8)
 *     ngpts = <g2int>PyInt_AsLong(ndpts)             # <<<<<<<<<<<<<<
 *     idrsnum = <g2int>PyInt_AsLong(drtnum)
 *     igdsnum = <g2int>PyInt_AsLong(gdtnum)
 */
  __pyx_v_ngpts = ((g2int)PyInt_AsLong(__pyx_v_ndpts));

  /* "g2clib.pyx":428
 *     iofst = <g2int>PyInt_AsLong(ipos*8)
 *     ngpts = <g2int>PyInt_AsLong(ndpts)
 *     idrsnum = <g2int>PyInt_AsLong(drtnum)             # <<<<<<<<<<<<<<
 *     igdsnum = <g2int>PyInt_AsLong(gdtnum)
 *     PyObject_AsReadBuffer(drtmpl, &drtmpldat, &buflen)
 */
  __pyx_v_idrsnum = ((g2int)PyInt_AsLong(__pyx_v_drtnum));

  /* "g2clib.pyx":429
 *     ngpts = <g2int>PyInt_AsLong(ndpts)
 *     idrsnum = <g2int>PyInt_AsLong(drtnum)
 *     igdsnum = <g2int>PyInt_AsLong(gdtnum)             # <<<<<<<<<<<<<<
 *     PyObject_AsReadBuffer(drtmpl, &drtmpldat, &buflen)
 *     PyObject_AsReadBuffer(gdtmpl, &gdtmpldat, &buflen)
 */
  __pyx_v_igdsnum = ((g2int)PyInt_AsLong(__pyx_v_gdtnum));

  /* "g2clib.pyx":430
 *     idrsnum = <g2int>PyInt_AsLong(drtnum)
 *     igdsnum = <g2int>PyInt_AsLong(gdtnum)
 *     PyObject_AsReadBuffer(drtmpl, &drtmpldat, &buflen)             # <<<<<<<<<<<<<<
 *     PyObject_AsReadBuffer(gdtmpl, &gdtmpldat, &buflen)
 *     idrstmpl = <g2int *>drtmpldat
 */
  PyObject_AsReadBuffer(__pyx_v_drtmpl, (&__pyx_v_drtmpldat), (&__pyx_v_buflen));

  /* "g2clib.pyx":431
 *     igdsnum = <g2int>PyInt_AsLong(gdtnum)
 *     PyObject_AsReadBuffer(drtmpl, &drtmpldat, &buflen)
 *     PyObject_AsReadBuffer(gdtmpl, &gdtmpldat, &buflen)             # <<<<<<<<<<<<<<
 *     idrstmpl = <g2int *>drtmpldat
 *     igdstmpl = <g2int *>gdtmpldat
 */
  PyObject_AsReadBuffer(__pyx_v_gdtmpl, (&__pyx_v_gdtmpldat), (&__pyx_v_buflen));

  /* "g2clib.pyx":432
 *     PyObject_AsReadBuffer(drtmpl, &drtmpldat, &buflen)
 *     PyObject_AsReadBuffer(gdtmpl, &gdtmpldat, &buflen)
 *     idrstmpl = <g2int *>drtmpldat             # <<<<<<<<<<<<<<
 *     igdstmpl = <g2int *>gdtmpldat
 *     ierr=g2_unpack7(cgrib,&iofst,igdsnum,igdstmpl,idrsnum,idrstmpl,ngpts,&fld)
 */
  __pyx_v_idrstmpl = ((g2int *)__pyx_v_drtmpldat);

  /* "g2clib.pyx":433
 *     PyObject_AsReadBuffer(gdtmpl, &gdtmpldat, &buflen)
 *     idrstmpl = <g2int *>drtmpldat
 *     igdstmpl = <g2int *>gdtmpldat             # <<<<<<<<<<<<<<
 *     ierr=g2_unpack7(cgrib,&iofst,igdsnum,igdstmpl,idrsnum,idrstmpl,ngpts,&fld)
 *     if ierr != 0:
 */
  __pyx_v_igdstmpl = ((g2int *)__pyx_v_gdtmpldat);

  /* "g2clib.pyx":434
 *     idrstmpl = <g2int *>drtmpldat
 *     igdstmpl = <g2int *>gdtmpldat
 *     ierr=g2_unpack7(cgrib,&iofst,igdsnum,igdstmpl,idrsnum,idrstmpl,ngpts,&fld)             # <<<<<<<<<<<<<<
 *     if ierr != 0:
 *        msg = "Error unpacking section 7 - error code = %i" % ierr
 */
  __pyx_v_ierr = g2_unpack7(__pyx_v_cgrib, (&__pyx_v_iofst), __pyx_v_igdsnum, __pyx_v_igdstmpl, __pyx_v_idrsnum, __pyx_v_idrstmpl, __pyx_v_ngpts, (&__pyx_v_fld));

  /* "g2clib.pyx":435
 *     igdstmpl = <g2int *>gdtmpldat
 *     ierr=g2_unpack7(cgrib,&iofst,igdsnum,igdstmpl,idrsnum,idrstmpl,ngpts,&fld)
 *     if ierr != 0:             # <<<<<<<<<<<<<<
 *        msg = "Error unpacking section 7 - error code = %i" % ierr
 *        raise RuntimeError(msg)
 */
  __pyx_t_2 = (__pyx_v_ierr != 0);
  if (__pyx_t_2) {

    /* "g2clib.pyx":436
 *     ierr=g2_unpack7(cgrib,&iofst,igdsnum,igdstmpl,idrsnum,idrstmpl,ngpts,&fld)
 *     if ierr != 0:
 *        msg = "Error unpacking section 7 - error code = %i" % ierr             # <<<<<<<<<<<<<<
 *        raise RuntimeError(msg)
 * 
 */
    __pyx_t_1 = __Pyx_PyInt_to_py_int32_t(__pyx_v_ierr); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 436; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_1);
    __pyx_t_3 = PyNumber_Remainder(((PyObject *)__pyx_kp_s_15), __pyx_t_1); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 436; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(((PyObject *)__pyx_t_3));
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
    __pyx_v_msg = ((PyObject *)__pyx_t_3);
    __pyx_t_3 = 0;

    /* "g2clib.pyx":437
 *     if ierr != 0:
 *        msg = "Error unpacking section 7 - error code = %i" % ierr
 *        raise RuntimeError(msg)             # <<<<<<<<<<<<<<
 * 
 * 
 */
    __pyx_t_3 = PyTuple_New(1); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 437; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_3);
    __Pyx_INCREF(__pyx_v_msg);
    PyTuple_SET_ITEM(__pyx_t_3, 0, __pyx_v_msg);
    __Pyx_GIVEREF(__pyx_v_msg);
    __pyx_t_1 = PyObject_Call(__pyx_builtin_RuntimeError, ((PyObject *)__pyx_t_3), NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 437; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_1);
    __Pyx_DECREF(((PyObject *)__pyx_t_3)); __pyx_t_3 = 0;
    __Pyx_Raise(__pyx_t_1, 0, 0, 0);
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
    {__pyx_filename = __pyx_f[0]; __pyx_lineno = 437; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    goto __pyx_L3;
  }
  __pyx_L3:;

  /* "g2clib.pyx":440
 * 
 * 
 *     if printminmax:             # <<<<<<<<<<<<<<
 *         rmax=-<float>9.9e31
 *         rmin=<float>9.9e31
 */
  __pyx_t_2 = __Pyx_PyObject_IsTrue(__pyx_v_printminmax); if (unlikely(__pyx_t_2 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 440; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  if (__pyx_t_2) {

    /* "g2clib.pyx":441
 * 
 *     if printminmax:
 *         rmax=-<float>9.9e31             # <<<<<<<<<<<<<<
 *         rmin=<float>9.9e31
 *         for n from 0 <= n < ndpts:
 */
    __pyx_v_rmax = (-((float)9.9e31));

    /* "g2clib.pyx":442
 *     if printminmax:
 *         rmax=-<float>9.9e31
 *         rmin=<float>9.9e31             # <<<<<<<<<<<<<<
 *         for n from 0 <= n < ndpts:
 *             if fld[n] > rmax: rmax=fld[n]
 */
    __pyx_v_rmin = ((float)9.9e31);

    /* "g2clib.pyx":443
 *         rmax=-<float>9.9e31
 *         rmin=<float>9.9e31
 *         for n from 0 <= n < ndpts:             # <<<<<<<<<<<<<<
 *             if fld[n] > rmax: rmax=fld[n]
 *             if fld[n] < rmin: rmin=fld[n]
 */
    __pyx_t_4 = __Pyx_PyInt_AsInt(__pyx_v_ndpts); if (unlikely((__pyx_t_4 == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 443; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    for (__pyx_v_n = 0; __pyx_v_n < __pyx_t_4; __pyx_v_n++) {

      /* "g2clib.pyx":444
 *         rmin=<float>9.9e31
 *         for n from 0 <= n < ndpts:
 *             if fld[n] > rmax: rmax=fld[n]             # <<<<<<<<<<<<<<
 *             if fld[n] < rmin: rmin=fld[n]
 *         fldmax = PyFloat_FromDouble(rmax)
 */
      __pyx_t_2 = ((__pyx_v_fld[__pyx_v_n]) > __pyx_v_rmax);
      if (__pyx_t_2) {
        __pyx_v_rmax = (__pyx_v_fld[__pyx_v_n]);
        goto __pyx_L7;
      }
      __pyx_L7:;

      /* "g2clib.pyx":445
 *         for n from 0 <= n < ndpts:
 *             if fld[n] > rmax: rmax=fld[n]
 *             if fld[n] < rmin: rmin=fld[n]             # <<<<<<<<<<<<<<
 *         fldmax = PyFloat_FromDouble(rmax)
 *         fldmin = PyFloat_FromDouble(rmin)
 */
      __pyx_t_2 = ((__pyx_v_fld[__pyx_v_n]) < __pyx_v_rmin);
      if (__pyx_t_2) {
        __pyx_v_rmin = (__pyx_v_fld[__pyx_v_n]);
        goto __pyx_L8;
      }
      __pyx_L8:;
    }

    /* "g2clib.pyx":446
 *             if fld[n] > rmax: rmax=fld[n]
 *             if fld[n] < rmin: rmin=fld[n]
 *         fldmax = PyFloat_FromDouble(rmax)             # <<<<<<<<<<<<<<
 *         fldmin = PyFloat_FromDouble(rmin)
 *         bitsofprecision = drtmpl[3]
 */
    __pyx_t_1 = PyFloat_FromDouble(__pyx_v_rmax); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 446; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_1);
    __pyx_v_fldmax = __pyx_t_1;
    __pyx_t_1 = 0;

    /* "g2clib.pyx":447
 *             if fld[n] < rmin: rmin=fld[n]
 *         fldmax = PyFloat_FromDouble(rmax)
 *         fldmin = PyFloat_FromDouble(rmin)             # <<<<<<<<<<<<<<
 *         bitsofprecision = drtmpl[3]
 *         digitsofprecision = int(math.ceil(math.log10(math.pow(2,bitsofprecision))))
 */
    __pyx_t_1 = PyFloat_FromDouble(__pyx_v_rmin); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 447; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_1);
    __pyx_v_fldmin = __pyx_t_1;
    __pyx_t_1 = 0;

    /* "g2clib.pyx":448
 *         fldmax = PyFloat_FromDouble(rmax)
 *         fldmin = PyFloat_FromDouble(rmin)
 *         bitsofprecision = drtmpl[3]             # <<<<<<<<<<<<<<
 *         digitsofprecision = int(math.ceil(math.log10(math.pow(2,bitsofprecision))))
 *         format = "%."+repr(digitsofprecision+1)+"g"
 */
    __pyx_t_1 = __Pyx_GetItemInt(__pyx_v_drtmpl, 3, sizeof(long), PyInt_FromLong); if (!__pyx_t_1) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 448; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_1);
    __pyx_v_bitsofprecision = __pyx_t_1;
    __pyx_t_1 = 0;

    /* "g2clib.pyx":449
 *         fldmin = PyFloat_FromDouble(rmin)
 *         bitsofprecision = drtmpl[3]
 *         digitsofprecision = int(math.ceil(math.log10(math.pow(2,bitsofprecision))))             # <<<<<<<<<<<<<<
 *         format = "%."+repr(digitsofprecision+1)+"g"
 *         minmaxstring = 'min/max='+format+'/'+format
 */
    __pyx_t_1 = __Pyx_GetName(__pyx_m, __pyx_n_s__math); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 449; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_1);
    __pyx_t_3 = PyObject_GetAttr(__pyx_t_1, __pyx_n_s__ceil); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 449; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_3);
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
    __pyx_t_1 = __Pyx_GetName(__pyx_m, __pyx_n_s__math); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 449; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_1);
    __pyx_t_5 = PyObject_GetAttr(__pyx_t_1, __pyx_n_s__log10); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 449; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_5);
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
    __pyx_t_1 = __Pyx_GetName(__pyx_m, __pyx_n_s__math); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 449; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_1);
    __pyx_t_6 = PyObject_GetAttr(__pyx_t_1, __pyx_n_s__pow); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 449; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_6);
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
    __pyx_t_1 = PyTuple_New(2); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 449; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_1);
    __Pyx_INCREF(__pyx_int_2);
    PyTuple_SET_ITEM(__pyx_t_1, 0, __pyx_int_2);
    __Pyx_GIVEREF(__pyx_int_2);
    __Pyx_INCREF(__pyx_v_bitsofprecision);
    PyTuple_SET_ITEM(__pyx_t_1, 1, __pyx_v_bitsofprecision);
    __Pyx_GIVEREF(__pyx_v_bitsofprecision);
    __pyx_t_7 = PyObject_Call(__pyx_t_6, ((PyObject *)__pyx_t_1), NULL); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 449; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_7);
    __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
    __Pyx_DECREF(((PyObject *)__pyx_t_1)); __pyx_t_1 = 0;
    __pyx_t_1 = PyTuple_New(1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 449; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_1);
    PyTuple_SET_ITEM(__pyx_t_1, 0, __pyx_t_7);
    __Pyx_GIVEREF(__pyx_t_7);
    __pyx_t_7 = 0;
    __pyx_t_7 = PyObject_Call(__pyx_t_5, ((PyObject *)__pyx_t_1), NULL); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 449; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_7);
    __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
    __Pyx_DECREF(((PyObject *)__pyx_t_1)); __pyx_t_1 = 0;
    __pyx_t_1 = PyTuple_New(1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 449; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_1);
    PyTuple_SET_ITEM(__pyx_t_1, 0, __pyx_t_7);
    __Pyx_GIVEREF(__pyx_t_7);
    __pyx_t_7 = 0;
    __pyx_t_7 = PyObject_Call(__pyx_t_3, ((PyObject *)__pyx_t_1), NULL); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 449; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_7);
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
    __Pyx_DECREF(((PyObject *)__pyx_t_1)); __pyx_t_1 = 0;
    __pyx_t_1 = PyTuple_New(1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 449; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_1);
    PyTuple_SET_ITEM(__pyx_t_1, 0, __pyx_t_7);
    __Pyx_GIVEREF(__pyx_t_7);
    __pyx_t_7 = 0;
    __pyx_t_7 = PyObject_Call(((PyObject *)((PyObject*)(&PyInt_Type))), ((PyObject *)__pyx_t_1), NULL); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 449; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_7);
    __Pyx_DECREF(((PyObject *)__pyx_t_1)); __pyx_t_1 = 0;
    __pyx_v_digitsofprecision = __pyx_t_7;
    __pyx_t_7 = 0;

    /* "g2clib.pyx":450
 *         bitsofprecision = drtmpl[3]
 *         digitsofprecision = int(math.ceil(math.log10(math.pow(2,bitsofprecision))))
 *         format = "%."+repr(digitsofprecision+1)+"g"             # <<<<<<<<<<<<<<
 *         minmaxstring = 'min/max='+format+'/'+format
 *         minmaxstring = minmaxstring % (fldmin,fldmax)
 */
    __pyx_t_7 = PyNumber_Add(__pyx_v_digitsofprecision, __pyx_int_1); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 450; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_7);
    __pyx_t_1 = PyObject_Repr(__pyx_t_7); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 450; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_1);
    __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
    __pyx_t_7 = PyNumber_Add(((PyObject *)__pyx_kp_s_16), __pyx_t_1); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 450; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_7);
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
    __pyx_t_1 = PyNumber_Add(__pyx_t_7, ((PyObject *)__pyx_n_s__g)); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 450; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_1);
    __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
    __pyx_v_format = __pyx_t_1;
    __pyx_t_1 = 0;

    /* "g2clib.pyx":451
 *         digitsofprecision = int(math.ceil(math.log10(math.pow(2,bitsofprecision))))
 *         format = "%."+repr(digitsofprecision+1)+"g"
 *         minmaxstring = 'min/max='+format+'/'+format             # <<<<<<<<<<<<<<
 *         minmaxstring = minmaxstring % (fldmin,fldmax)
 *         print minmaxstring
 */
    __pyx_t_1 = PyNumber_Add(((PyObject *)__pyx_kp_s_17), __pyx_v_format); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 451; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_1);
    __pyx_t_7 = PyNumber_Add(__pyx_t_1, ((PyObject *)__pyx_kp_s_18)); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 451; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_7);
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
    __pyx_t_1 = PyNumber_Add(__pyx_t_7, __pyx_v_format); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 451; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_1);
    __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
    __pyx_v_minmaxstring = __pyx_t_1;
    __pyx_t_1 = 0;

    /* "g2clib.pyx":452
 *         format = "%."+repr(digitsofprecision+1)+"g"
 *         minmaxstring = 'min/max='+format+'/'+format
 *         minmaxstring = minmaxstring % (fldmin,fldmax)             # <<<<<<<<<<<<<<
 *         print minmaxstring
 * 
 */
    __pyx_t_1 = PyTuple_New(2); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 452; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_1);
    __Pyx_INCREF(__pyx_v_fldmin);
    PyTuple_SET_ITEM(__pyx_t_1, 0, __pyx_v_fldmin);
    __Pyx_GIVEREF(__pyx_v_fldmin);
    __Pyx_INCREF(__pyx_v_fldmax);
    PyTuple_SET_ITEM(__pyx_t_1, 1, __pyx_v_fldmax);
    __Pyx_GIVEREF(__pyx_v_fldmax);
    __pyx_t_7 = PyNumber_Remainder(__pyx_v_minmaxstring, ((PyObject *)__pyx_t_1)); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 452; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_7);
    __Pyx_DECREF(((PyObject *)__pyx_t_1)); __pyx_t_1 = 0;
    __Pyx_DECREF(__pyx_v_minmaxstring);
    __pyx_v_minmaxstring = __pyx_t_7;
    __pyx_t_7 = 0;

    /* "g2clib.pyx":453
 *         minmaxstring = 'min/max='+format+'/'+format
 *         minmaxstring = minmaxstring % (fldmin,fldmax)
 *         print minmaxstring             # <<<<<<<<<<<<<<
 * 
 *     data = _toarray(fld, zeros(ngpts, 'f4', order=storageorder))
 */
    if (__Pyx_PrintOne(0, __pyx_v_minmaxstring) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 453; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    goto __pyx_L4;
  }
  __pyx_L4:;

  /* "g2clib.pyx":455
 *         print minmaxstring
 * 
 *     data = _toarray(fld, zeros(ngpts, 'f4', order=storageorder))             # <<<<<<<<<<<<<<
 *     return data
 * 
 */
  __pyx_t_7 = __Pyx_PyInt_to_py_int32_t(__pyx_v_ngpts); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 455; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_7);
  __pyx_t_1 = PyTuple_New(2); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 455; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  PyTuple_SET_ITEM(__pyx_t_1, 0, __pyx_t_7);
  __Pyx_GIVEREF(__pyx_t_7);
  __Pyx_INCREF(((PyObject *)__pyx_n_s__f4));
  PyTuple_SET_ITEM(__pyx_t_1, 1, ((PyObject *)__pyx_n_s__f4));
  __Pyx_GIVEREF(((PyObject *)__pyx_n_s__f4));
  __pyx_t_7 = 0;
  __pyx_t_7 = PyDict_New(); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 455; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(((PyObject *)__pyx_t_7));
  if (PyDict_SetItem(__pyx_t_7, ((PyObject *)__pyx_n_s__order), __pyx_v_storageorder) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 455; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_t_3 = PyObject_Call(__pyx_v_zeros, ((PyObject *)__pyx_t_1), ((PyObject *)__pyx_t_7)); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 455; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_DECREF(((PyObject *)__pyx_t_1)); __pyx_t_1 = 0;
  __Pyx_DECREF(((PyObject *)__pyx_t_7)); __pyx_t_7 = 0;
  __pyx_t_7 = __pyx_f_6g2clib__toarray(__pyx_v_fld, __pyx_t_3); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 455; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_7);
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __pyx_v_data = __pyx_t_7;
  __pyx_t_7 = 0;

  /* "g2clib.pyx":456
 * 
 *     data = _toarray(fld, zeros(ngpts, 'f4', order=storageorder))
 *     return data             # <<<<<<<<<<<<<<
 * 
 * # routines for writing grib2 files.
 */
  __Pyx_XDECREF(__pyx_r);
  __Pyx_INCREF(__pyx_v_data);
  __pyx_r = __pyx_v_data;
  goto __pyx_L0;

  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_XDECREF(__pyx_t_3);
  __Pyx_XDECREF(__pyx_t_5);
  __Pyx_XDECREF(__pyx_t_6);
  __Pyx_XDECREF(__pyx_t_7);
  __Pyx_AddTraceback("g2clib.unpack7", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XDECREF(__pyx_v_msg);
  __Pyx_XDECREF(__pyx_v_fldmax);
  __Pyx_XDECREF(__pyx_v_fldmin);
  __Pyx_XDECREF(__pyx_v_bitsofprecision);
  __Pyx_XDECREF(__pyx_v_digitsofprecision);
  __Pyx_XDECREF(__pyx_v_format);
  __Pyx_XDECREF(__pyx_v_minmaxstring);
  __Pyx_XDECREF(__pyx_v_data);
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* Python wrapper */
static PyObject *__pyx_pw_6g2clib_17grib2_create(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
static char __pyx_doc_6g2clib_16grib2_create[] = "\n Initializes a new GRIB2 message and packs\n GRIB2 sections 0 (Indicator Section) and 1 (Identification Section).\n This routine is used with routines \"g2_addgrid\", \n \"grib2_addfield\", and \"grib2_gribend\" to create a complete GRIB2 message.  \n grib2_create must be called first to initialize a new GRIB2 message.\n Also, a call to grib2_gribend is required to complete GRIB2 message\n after all fields have been added.\n\n gribmsg, ierr = grib2_create(listsec0, listsec1)\n\n   INPUT ARGUMENTS:\n     \n     listsec0 - numpy array containing info needed for GRIB Indicator Section 0.\n                Must have length >= 2.\n                listsec0[0]=Discipline-GRIB Master Table Number\n                            (see Code Table 0.0)\n                listsec0[1]=GRIB Edition Number (currently 2)\n     listsec1 - numpy array containing info needed for GRIB Identification Section 1.\n                Must have len >= 13.\n                listsec1[0]=Id of orginating centre (Common Code Table C-1)\n                listsec1[1]=Id of orginating sub-centre (local table)\n                listsec1[2]=GRIB Master Tables Version Number (Code Table 1.0)\n                listsec1[3]=GRIB Local Tables Version Number (Code Table 1.1)\n                listsec1[4]=Significance of Reference Time (Code Table 1.2)\n                listsec1[5]=Reference Time - Year (4 digits)\n                listsec1[6]=Reference Time - Month\n                listsec1[7]=Reference Time - Day\n                listsec1[8]=Reference Time - Hour\n                listsec1[9]=Reference Time - Minute\n                listsec1[10]=Reference Time - Second\n                listsec1[11]=Production status of data (Code Table 1.3)\n                listsec1[12]=Type of processed data (Code Table 1.4)\n\n   OUTPUT ARGUMENTS:      \n     gribmsg  - string containing the new GRIB2 message.\n     ierr     - return code.\n              > 0 = Current size of new GRIB2 message\n               -1 = Tried to use for ver""sion other than GRIB Edition 2\n    ";
static PyMethodDef __pyx_mdef_6g2clib_17grib2_create = {__Pyx_NAMESTR("grib2_create"), (PyCFunction)__pyx_pw_6g2clib_17grib2_create, METH_VARARGS|METH_KEYWORDS, __Pyx_DOCSTR(__pyx_doc_6g2clib_16grib2_create)};
static PyObject *__pyx_pw_6g2clib_17grib2_create(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
  PyObject *__pyx_v_listsec0 = 0;
  PyObject *__pyx_v_listsec1 = 0;
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("grib2_create (wrapper)", 0);
  {
    static PyObject **__pyx_pyargnames[] = {&__pyx_n_s__listsec0,&__pyx_n_s__listsec1,0};
    PyObject* values[2] = {0,0};
    if (unlikely(__pyx_kwds)) {
      Py_ssize_t kw_args;
      const Py_ssize_t pos_args = PyTuple_GET_SIZE(__pyx_args);
      switch (pos_args) {
        case  2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
        case  1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
        case  0: break;
        default: goto __pyx_L5_argtuple_error;
      }
      kw_args = PyDict_Size(__pyx_kwds);
      switch (pos_args) {
        case  0:
        if (likely((values[0] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__listsec0)) != 0)) kw_args--;
        else goto __pyx_L5_argtuple_error;
        case  1:
        if (likely((values[1] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__listsec1)) != 0)) kw_args--;
        else {
          __Pyx_RaiseArgtupleInvalid("grib2_create", 1, 2, 2, 1); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 460; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
        }
      }
      if (unlikely(kw_args > 0)) {
        if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "grib2_create") < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 460; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
      }
    } else if (PyTuple_GET_SIZE(__pyx_args) != 2) {
      goto __pyx_L5_argtuple_error;
    } else {
      values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
      values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
    }
    __pyx_v_listsec0 = values[0];
    __pyx_v_listsec1 = values[1];
  }
  goto __pyx_L4_argument_unpacking_done;
  __pyx_L5_argtuple_error:;
  __Pyx_RaiseArgtupleInvalid("grib2_create", 1, 2, 2, PyTuple_GET_SIZE(__pyx_args)); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 460; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
  __pyx_L3_error:;
  __Pyx_AddTraceback("g2clib.grib2_create", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __Pyx_RefNannyFinishContext();
  return NULL;
  __pyx_L4_argument_unpacking_done:;
  __pyx_r = __pyx_pf_6g2clib_16grib2_create(__pyx_self, __pyx_v_listsec0, __pyx_v_listsec1);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "g2clib.pyx":460
 * # routines for writing grib2 files.
 * 
 * def grib2_create(object listsec0, object listsec1):             # <<<<<<<<<<<<<<
 *     """
 *  Initializes a new GRIB2 message and packs
 */

static PyObject *__pyx_pf_6g2clib_16grib2_create(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_listsec0, PyObject *__pyx_v_listsec1) {
  g2int *__pyx_v_isec0;
  g2int *__pyx_v_isec1;
  g2int __pyx_v_ierr;
  void *__pyx_v_listsec0dat;
  void *__pyx_v_listsec1dat;
  Py_ssize_t __pyx_v_buflen;
  unsigned char *__pyx_v_cgrib;
  PyObject *__pyx_v_lgrib = NULL;
  PyObject *__pyx_v_gribmsg = NULL;
  PyObject *__pyx_v_msg = NULL;
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  Py_ssize_t __pyx_t_1;
  Py_ssize_t __pyx_t_2;
  PyObject *__pyx_t_3 = NULL;
  int __pyx_t_4;
  PyObject *__pyx_t_5 = NULL;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("grib2_create", 0);

  /* "g2clib.pyx":506
 *     cdef unsigned char *cgrib
 *     # cgrib needs to be big enough to hold sec0 and sec1.
 *     lgrib = 4*(len(listsec0)+len(listsec1))             # <<<<<<<<<<<<<<
 *     gribmsg = lgrib*b" "
 *     cgrib = <unsigned char *>PyBytes_AsString(gribmsg)
 */
  __pyx_t_1 = PyObject_Length(__pyx_v_listsec0); if (unlikely(__pyx_t_1 == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 506; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_t_2 = PyObject_Length(__pyx_v_listsec1); if (unlikely(__pyx_t_2 == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 506; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_t_3 = PyInt_FromSsize_t((4 * (__pyx_t_1 + __pyx_t_2))); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 506; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_v_lgrib = __pyx_t_3;
  __pyx_t_3 = 0;

  /* "g2clib.pyx":507
 *     # cgrib needs to be big enough to hold sec0 and sec1.
 *     lgrib = 4*(len(listsec0)+len(listsec1))
 *     gribmsg = lgrib*b" "             # <<<<<<<<<<<<<<
 *     cgrib = <unsigned char *>PyBytes_AsString(gribmsg)
 *     PyObject_AsReadBuffer(listsec0, &listsec0dat, &buflen)
 */
  __pyx_t_3 = PyNumber_Multiply(__pyx_v_lgrib, ((PyObject *)__pyx_kp_b_19)); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 507; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_v_gribmsg = __pyx_t_3;
  __pyx_t_3 = 0;

  /* "g2clib.pyx":508
 *     lgrib = 4*(len(listsec0)+len(listsec1))
 *     gribmsg = lgrib*b" "
 *     cgrib = <unsigned char *>PyBytes_AsString(gribmsg)             # <<<<<<<<<<<<<<
 *     PyObject_AsReadBuffer(listsec0, &listsec0dat, &buflen)
 *     PyObject_AsReadBuffer(listsec1, &listsec1dat, &buflen)
 */
  __pyx_v_cgrib = ((unsigned char *)PyBytes_AsString(__pyx_v_gribmsg));

  /* "g2clib.pyx":509
 *     gribmsg = lgrib*b" "
 *     cgrib = <unsigned char *>PyBytes_AsString(gribmsg)
 *     PyObject_AsReadBuffer(listsec0, &listsec0dat, &buflen)             # <<<<<<<<<<<<<<
 *     PyObject_AsReadBuffer(listsec1, &listsec1dat, &buflen)
 *     isec0 = <g2int *>listsec0dat
 */
  PyObject_AsReadBuffer(__pyx_v_listsec0, (&__pyx_v_listsec0dat), (&__pyx_v_buflen));

  /* "g2clib.pyx":510
 *     cgrib = <unsigned char *>PyBytes_AsString(gribmsg)
 *     PyObject_AsReadBuffer(listsec0, &listsec0dat, &buflen)
 *     PyObject_AsReadBuffer(listsec1, &listsec1dat, &buflen)             # <<<<<<<<<<<<<<
 *     isec0 = <g2int *>listsec0dat
 *     isec1 = <g2int *>listsec1dat
 */
  PyObject_AsReadBuffer(__pyx_v_listsec1, (&__pyx_v_listsec1dat), (&__pyx_v_buflen));

  /* "g2clib.pyx":511
 *     PyObject_AsReadBuffer(listsec0, &listsec0dat, &buflen)
 *     PyObject_AsReadBuffer(listsec1, &listsec1dat, &buflen)
 *     isec0 = <g2int *>listsec0dat             # <<<<<<<<<<<<<<
 *     isec1 = <g2int *>listsec1dat
 *     ierr = g2_create(cgrib,isec0,isec1)
 */
  __pyx_v_isec0 = ((g2int *)__pyx_v_listsec0dat);

  /* "g2clib.pyx":512
 *     PyObject_AsReadBuffer(listsec1, &listsec1dat, &buflen)
 *     isec0 = <g2int *>listsec0dat
 *     isec1 = <g2int *>listsec1dat             # <<<<<<<<<<<<<<
 *     ierr = g2_create(cgrib,isec0,isec1)
 *     if ierr < 0:
 */
  __pyx_v_isec1 = ((g2int *)__pyx_v_listsec1dat);

  /* "g2clib.pyx":513
 *     isec0 = <g2int *>listsec0dat
 *     isec1 = <g2int *>listsec1dat
 *     ierr = g2_create(cgrib,isec0,isec1)             # <<<<<<<<<<<<<<
 *     if ierr < 0:
 *        msg = "Error in grib2_create, error code = %i" % ierr
 */
  __pyx_v_ierr = g2_create(__pyx_v_cgrib, __pyx_v_isec0, __pyx_v_isec1);

  /* "g2clib.pyx":514
 *     isec1 = <g2int *>listsec1dat
 *     ierr = g2_create(cgrib,isec0,isec1)
 *     if ierr < 0:             # <<<<<<<<<<<<<<
 *        msg = "Error in grib2_create, error code = %i" % ierr
 *        raise RuntimeError(msg)
 */
  __pyx_t_4 = (__pyx_v_ierr < 0);
  if (__pyx_t_4) {

    /* "g2clib.pyx":515
 *     ierr = g2_create(cgrib,isec0,isec1)
 *     if ierr < 0:
 *        msg = "Error in grib2_create, error code = %i" % ierr             # <<<<<<<<<<<<<<
 *        raise RuntimeError(msg)
 *     gribmsg = PyBytes_FromStringAndSize(<char *>cgrib, ierr)
 */
    __pyx_t_3 = __Pyx_PyInt_to_py_int32_t(__pyx_v_ierr); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 515; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_3);
    __pyx_t_5 = PyNumber_Remainder(((PyObject *)__pyx_kp_s_20), __pyx_t_3); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 515; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(((PyObject *)__pyx_t_5));
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
    __pyx_v_msg = ((PyObject *)__pyx_t_5);
    __pyx_t_5 = 0;

    /* "g2clib.pyx":516
 *     if ierr < 0:
 *        msg = "Error in grib2_create, error code = %i" % ierr
 *        raise RuntimeError(msg)             # <<<<<<<<<<<<<<
 *     gribmsg = PyBytes_FromStringAndSize(<char *>cgrib, ierr)
 *     return gribmsg, ierr
 */
    __pyx_t_5 = PyTuple_New(1); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 516; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_5);
    __Pyx_INCREF(__pyx_v_msg);
    PyTuple_SET_ITEM(__pyx_t_5, 0, __pyx_v_msg);
    __Pyx_GIVEREF(__pyx_v_msg);
    __pyx_t_3 = PyObject_Call(__pyx_builtin_RuntimeError, ((PyObject *)__pyx_t_5), NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 516; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_3);
    __Pyx_DECREF(((PyObject *)__pyx_t_5)); __pyx_t_5 = 0;
    __Pyx_Raise(__pyx_t_3, 0, 0, 0);
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
    {__pyx_filename = __pyx_f[0]; __pyx_lineno = 516; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    goto __pyx_L3;
  }
  __pyx_L3:;

  /* "g2clib.pyx":517
 *        msg = "Error in grib2_create, error code = %i" % ierr
 *        raise RuntimeError(msg)
 *     gribmsg = PyBytes_FromStringAndSize(<char *>cgrib, ierr)             # <<<<<<<<<<<<<<
 *     return gribmsg, ierr
 * 
 */
  __pyx_t_3 = PyBytes_FromStringAndSize(((char *)__pyx_v_cgrib), __pyx_v_ierr); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 517; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_DECREF(__pyx_v_gribmsg);
  __pyx_v_gribmsg = __pyx_t_3;
  __pyx_t_3 = 0;

  /* "g2clib.pyx":518
 *        raise RuntimeError(msg)
 *     gribmsg = PyBytes_FromStringAndSize(<char *>cgrib, ierr)
 *     return gribmsg, ierr             # <<<<<<<<<<<<<<
 * 
 * def grib2_end(gribmsg):
 */
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_3 = __Pyx_PyInt_to_py_int32_t(__pyx_v_ierr); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 518; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_t_5 = PyTuple_New(2); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 518; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_5);
  __Pyx_INCREF(__pyx_v_gribmsg);
  PyTuple_SET_ITEM(__pyx_t_5, 0, __pyx_v_gribmsg);
  __Pyx_GIVEREF(__pyx_v_gribmsg);
  PyTuple_SET_ITEM(__pyx_t_5, 1, __pyx_t_3);
  __Pyx_GIVEREF(__pyx_t_3);
  __pyx_t_3 = 0;
  __pyx_r = ((PyObject *)__pyx_t_5);
  __pyx_t_5 = 0;
  goto __pyx_L0;

  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_3);
  __Pyx_XDECREF(__pyx_t_5);
  __Pyx_AddTraceback("g2clib.grib2_create", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XDECREF(__pyx_v_lgrib);
  __Pyx_XDECREF(__pyx_v_gribmsg);
  __Pyx_XDECREF(__pyx_v_msg);
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* Python wrapper */
static PyObject *__pyx_pw_6g2clib_19grib2_end(PyObject *__pyx_self, PyObject *__pyx_v_gribmsg); /*proto*/
static char __pyx_doc_6g2clib_18grib2_end[] = "\n\n    Finalizes a GRIB2 message after all grids\n    and fields have been added.  It adds the End Section ( \"7777\" )\n    to the end of the GRIB message and calculates the length and stores\n    it in the appropriate place in Section 0.\n    This routine is used with routines \"g2_create\",  \n    \"g2_addgrid\", and \"g2_addfield\" to create a complete GRIB2 message.\n    g2_create must be called first to initialize a new GRIB2 message.\n\n  gribmsg, ierr = grib2_end(gribmsg)\n  \n    INPUT ARGUMENT:\n      gribmsg  - String containing all the data sections added\n                 be previous calls to g2_create, g2_addgrid,\n                 and g2_addfield.\n\n    OUTPUT ARGUMENTS:      \n      gribmsg  - String containing the finalized GRIB2 message\n\n    RETURN VALUES:\n      ierr     - Return code.\n               > 0 = Length of the final GRIB2 message in bytes.\n                -1 = GRIB message was not initialized.  Need to call\n                     routine g2_create first.\n                -2 = GRIB message already complete.  \n                -3 = Sum of Section byte counts doesn't add to total byte count\n                -4 = Previous Section was not 7.\n    ";
static PyMethodDef __pyx_mdef_6g2clib_19grib2_end = {__Pyx_NAMESTR("grib2_end"), (PyCFunction)__pyx_pw_6g2clib_19grib2_end, METH_O, __Pyx_DOCSTR(__pyx_doc_6g2clib_18grib2_end)};
static PyObject *__pyx_pw_6g2clib_19grib2_end(PyObject *__pyx_self, PyObject *__pyx_v_gribmsg) {
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("grib2_end (wrapper)", 0);
  __pyx_r = __pyx_pf_6g2clib_18grib2_end(__pyx_self, ((PyObject *)__pyx_v_gribmsg));
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "g2clib.pyx":520
 *     return gribmsg, ierr
 * 
 * def grib2_end(gribmsg):             # <<<<<<<<<<<<<<
 *     """
 * 
 */

static PyObject *__pyx_pf_6g2clib_18grib2_end(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_gribmsg) {
  g2int __pyx_v_ierr;
  unsigned char *__pyx_v_cgrib;
  PyObject *__pyx_v_msg = NULL;
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  int __pyx_t_2;
  PyObject *__pyx_t_3 = NULL;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("grib2_end", 0);
  __Pyx_INCREF(__pyx_v_gribmsg);

  /* "g2clib.pyx":553
 *     cdef unsigned char *cgrib
 *     # add some extra space to grib message (enough to hold section 8).
 *     gribmsg = gribmsg + b'        '             # <<<<<<<<<<<<<<
 *     cgrib = <unsigned char *>PyBytes_AsString(gribmsg)
 *     ierr = g2_gribend(cgrib)
 */
  __pyx_t_1 = PyNumber_Add(__pyx_v_gribmsg, ((PyObject *)__pyx_kp_b_21)); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 553; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_DECREF(__pyx_v_gribmsg);
  __pyx_v_gribmsg = __pyx_t_1;
  __pyx_t_1 = 0;

  /* "g2clib.pyx":554
 *     # add some extra space to grib message (enough to hold section 8).
 *     gribmsg = gribmsg + b'        '
 *     cgrib = <unsigned char *>PyBytes_AsString(gribmsg)             # <<<<<<<<<<<<<<
 *     ierr = g2_gribend(cgrib)
 *     if ierr < 0:
 */
  __pyx_v_cgrib = ((unsigned char *)PyBytes_AsString(__pyx_v_gribmsg));

  /* "g2clib.pyx":555
 *     gribmsg = gribmsg + b'        '
 *     cgrib = <unsigned char *>PyBytes_AsString(gribmsg)
 *     ierr = g2_gribend(cgrib)             # <<<<<<<<<<<<<<
 *     if ierr < 0:
 *        msg = "error in grib2_end, error code = %i" % ierr
 */
  __pyx_v_ierr = g2_gribend(__pyx_v_cgrib);

  /* "g2clib.pyx":556
 *     cgrib = <unsigned char *>PyBytes_AsString(gribmsg)
 *     ierr = g2_gribend(cgrib)
 *     if ierr < 0:             # <<<<<<<<<<<<<<
 *        msg = "error in grib2_end, error code = %i" % ierr
 *        raise RuntimeError(msg)
 */
  __pyx_t_2 = (__pyx_v_ierr < 0);
  if (__pyx_t_2) {

    /* "g2clib.pyx":557
 *     ierr = g2_gribend(cgrib)
 *     if ierr < 0:
 *        msg = "error in grib2_end, error code = %i" % ierr             # <<<<<<<<<<<<<<
 *        raise RuntimeError(msg)
 *     gribmsg = PyBytes_FromStringAndSize(<char *>cgrib, ierr)
 */
    __pyx_t_1 = __Pyx_PyInt_to_py_int32_t(__pyx_v_ierr); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 557; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_1);
    __pyx_t_3 = PyNumber_Remainder(((PyObject *)__pyx_kp_s_22), __pyx_t_1); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 557; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(((PyObject *)__pyx_t_3));
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
    __pyx_v_msg = ((PyObject *)__pyx_t_3);
    __pyx_t_3 = 0;

    /* "g2clib.pyx":558
 *     if ierr < 0:
 *        msg = "error in grib2_end, error code = %i" % ierr
 *        raise RuntimeError(msg)             # <<<<<<<<<<<<<<
 *     gribmsg = PyBytes_FromStringAndSize(<char *>cgrib, ierr)
 *     return gribmsg, ierr
 */
    __pyx_t_3 = PyTuple_New(1); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 558; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_3);
    __Pyx_INCREF(__pyx_v_msg);
    PyTuple_SET_ITEM(__pyx_t_3, 0, __pyx_v_msg);
    __Pyx_GIVEREF(__pyx_v_msg);
    __pyx_t_1 = PyObject_Call(__pyx_builtin_RuntimeError, ((PyObject *)__pyx_t_3), NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 558; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_1);
    __Pyx_DECREF(((PyObject *)__pyx_t_3)); __pyx_t_3 = 0;
    __Pyx_Raise(__pyx_t_1, 0, 0, 0);
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
    {__pyx_filename = __pyx_f[0]; __pyx_lineno = 558; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    goto __pyx_L3;
  }
  __pyx_L3:;

  /* "g2clib.pyx":559
 *        msg = "error in grib2_end, error code = %i" % ierr
 *        raise RuntimeError(msg)
 *     gribmsg = PyBytes_FromStringAndSize(<char *>cgrib, ierr)             # <<<<<<<<<<<<<<
 *     return gribmsg, ierr
 * 
 */
  __pyx_t_1 = PyBytes_FromStringAndSize(((char *)__pyx_v_cgrib), __pyx_v_ierr); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 559; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_DECREF(__pyx_v_gribmsg);
  __pyx_v_gribmsg = __pyx_t_1;
  __pyx_t_1 = 0;

  /* "g2clib.pyx":560
 *        raise RuntimeError(msg)
 *     gribmsg = PyBytes_FromStringAndSize(<char *>cgrib, ierr)
 *     return gribmsg, ierr             # <<<<<<<<<<<<<<
 * 
 * def grib2_addgrid(gribmsg,object gds,object gdstmpl,object deflist=None, defnum = 0):
 */
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_1 = __Pyx_PyInt_to_py_int32_t(__pyx_v_ierr); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 560; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_3 = PyTuple_New(2); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 560; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_INCREF(__pyx_v_gribmsg);
  PyTuple_SET_ITEM(__pyx_t_3, 0, __pyx_v_gribmsg);
  __Pyx_GIVEREF(__pyx_v_gribmsg);
  PyTuple_SET_ITEM(__pyx_t_3, 1, __pyx_t_1);
  __Pyx_GIVEREF(__pyx_t_1);
  __pyx_t_1 = 0;
  __pyx_r = ((PyObject *)__pyx_t_3);
  __pyx_t_3 = 0;
  goto __pyx_L0;

  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_XDECREF(__pyx_t_3);
  __Pyx_AddTraceback("g2clib.grib2_end", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XDECREF(__pyx_v_msg);
  __Pyx_XDECREF(__pyx_v_gribmsg);
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* Python wrapper */
static PyObject *__pyx_pw_6g2clib_21grib2_addgrid(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
static char __pyx_doc_6g2clib_20grib2_addgrid[] = "\n   Packs up a Grid Definition Section (Section 3) \n   and adds it to a GRIB2 message.  It is used with routines \"g2_create\",\n   \"g2_addfield\" and \"g2_gribend\" to create a complete GRIB2 message.\n   g2_create must be called first to initialize a new GRIB2 message.\n\n   gribmsg, ierr = grib2_addgrid(gribmsg,gds,gdstmpl,ideflist)\n \n   INPUT ARGUMENTS:\n     cgrib    - Char array that contains the GRIB2 message to which\n                section should be added.\n     gds      - Contains information needed for GRIB Grid Definition Section 3\n                Must be dimensioned >= 5.\n                gds[0]=Source of grid definition (see Code Table 3.0)\n                gds[1]=Number of grid points in the defined grid.\n                gds[2]=Number of octets needed for each \n                            additional grid points definition.  \n                            Used to define number of\n                            points in each row ( or column ) for\n                            non-regular grids.  \n                            = 0, if using regular grid.\n                gds[3]=Interpretation of list for optional points \n                            definition.  (Code Table 3.11)\n                gds[4]=Grid Definition Template Number (Code Table 3.1)\n     gdstmpl  - Contains the data values for the specified Grid Definition\n                Template ( NN=gds[4] ).  Each element of this integer \n                array contains an entry (in the order specified) of Grid\n                Defintion Template 3.NN\n     deflist  - (Used if gds[2] != 0)  This array contains the\n                number of grid points contained in each row ( or column )\n\n   OUTPUT ARGUMENTS:      \n     cgrib    - Char array to contain the updated GRIB2 message.\n                Must be allocated large enough to store the entire\n                GRIB2 message.\n\n   RETURN VALUES:\n     ierr     - Return code.\n              > 0 = Current size of updated GRIB2 message""\n               -1 = GRIB message was not initialized.  Need to call\n                    routine gribcreate first.\n               -2 = GRIB message already complete.  Cannot add new section.\n               -3 = Sum of Section byte counts doesn't add to total byte count\n               -4 = Previous Section was not 1, 2 or 7.\n               -5 = Could not find requested Grid Definition Template.\n    ";
static PyMethodDef __pyx_mdef_6g2clib_21grib2_addgrid = {__Pyx_NAMESTR("grib2_addgrid"), (PyCFunction)__pyx_pw_6g2clib_21grib2_addgrid, METH_VARARGS|METH_KEYWORDS, __Pyx_DOCSTR(__pyx_doc_6g2clib_20grib2_addgrid)};
static PyObject *__pyx_pw_6g2clib_21grib2_addgrid(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
  PyObject *__pyx_v_gribmsg = 0;
  PyObject *__pyx_v_gds = 0;
  PyObject *__pyx_v_gdstmpl = 0;
  PyObject *__pyx_v_deflist = 0;
  CYTHON_UNUSED PyObject *__pyx_v_defnum = 0;
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("grib2_addgrid (wrapper)", 0);
  {
    static PyObject **__pyx_pyargnames[] = {&__pyx_n_s__gribmsg,&__pyx_n_s__gds,&__pyx_n_s__gdstmpl,&__pyx_n_s__deflist,&__pyx_n_s__defnum,0};
    PyObject* values[5] = {0,0,0,0,0};

    /* "g2clib.pyx":562
 *     return gribmsg, ierr
 * 
 * def grib2_addgrid(gribmsg,object gds,object gdstmpl,object deflist=None, defnum = 0):             # <<<<<<<<<<<<<<
 *     """
 *    Packs up a Grid Definition Section (Section 3)
 */
    values[3] = ((PyObject *)Py_None);
    values[4] = ((PyObject *)__pyx_int_0);
    if (unlikely(__pyx_kwds)) {
      Py_ssize_t kw_args;
      const Py_ssize_t pos_args = PyTuple_GET_SIZE(__pyx_args);
      switch (pos_args) {
        case  5: values[4] = PyTuple_GET_ITEM(__pyx_args, 4);
        case  4: values[3] = PyTuple_GET_ITEM(__pyx_args, 3);
        case  3: values[2] = PyTuple_GET_ITEM(__pyx_args, 2);
        case  2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
        case  1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
        case  0: break;
        default: goto __pyx_L5_argtuple_error;
      }
      kw_args = PyDict_Size(__pyx_kwds);
      switch (pos_args) {
        case  0:
        if (likely((values[0] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__gribmsg)) != 0)) kw_args--;
        else goto __pyx_L5_argtuple_error;
        case  1:
        if (likely((values[1] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__gds)) != 0)) kw_args--;
        else {
          __Pyx_RaiseArgtupleInvalid("grib2_addgrid", 0, 3, 5, 1); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 562; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
        }
        case  2:
        if (likely((values[2] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__gdstmpl)) != 0)) kw_args--;
        else {
          __Pyx_RaiseArgtupleInvalid("grib2_addgrid", 0, 3, 5, 2); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 562; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
        }
        case  3:
        if (kw_args > 0) {
          PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s__deflist);
          if (value) { values[3] = value; kw_args--; }
        }
        case  4:
        if (kw_args > 0) {
          PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s__defnum);
          if (value) { values[4] = value; kw_args--; }
        }
      }
      if (unlikely(kw_args > 0)) {
        if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "grib2_addgrid") < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 562; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
      }
    } else {
      switch (PyTuple_GET_SIZE(__pyx_args)) {
        case  5: values[4] = PyTuple_GET_ITEM(__pyx_args, 4);
        case  4: values[3] = PyTuple_GET_ITEM(__pyx_args, 3);
        case  3: values[2] = PyTuple_GET_ITEM(__pyx_args, 2);
        values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
        values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
        break;
        default: goto __pyx_L5_argtuple_error;
      }
    }
    __pyx_v_gribmsg = values[0];
    __pyx_v_gds = values[1];
    __pyx_v_gdstmpl = values[2];
    __pyx_v_deflist = values[3];
    __pyx_v_defnum = values[4];
  }
  goto __pyx_L4_argument_unpacking_done;
  __pyx_L5_argtuple_error:;
  __Pyx_RaiseArgtupleInvalid("grib2_addgrid", 0, 3, 5, PyTuple_GET_SIZE(__pyx_args)); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 562; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
  __pyx_L3_error:;
  __Pyx_AddTraceback("g2clib.grib2_addgrid", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __Pyx_RefNannyFinishContext();
  return NULL;
  __pyx_L4_argument_unpacking_done:;
  __pyx_r = __pyx_pf_6g2clib_20grib2_addgrid(__pyx_self, __pyx_v_gribmsg, __pyx_v_gds, __pyx_v_gdstmpl, __pyx_v_deflist, __pyx_v_defnum);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

static PyObject *__pyx_pf_6g2clib_20grib2_addgrid(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_gribmsg, PyObject *__pyx_v_gds, PyObject *__pyx_v_gdstmpl, PyObject *__pyx_v_deflist, CYTHON_UNUSED PyObject *__pyx_v_defnum) {
  g2int __pyx_v_ierr;
  g2int __pyx_v_idefnum;
  g2int *__pyx_v_igds;
  g2int *__pyx_v_igdstmpl;
  g2int *__pyx_v_ideflist;
  unsigned char *__pyx_v_cgrib;
  void *__pyx_v_gdsdat;
  void *__pyx_v_deflistdat;
  void *__pyx_v_gdstmpldat;
  Py_ssize_t __pyx_v_buflen;
  PyObject *__pyx_v_msg = NULL;
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  int __pyx_t_1;
  Py_ssize_t __pyx_t_2;
  PyObject *__pyx_t_3 = NULL;
  PyObject *__pyx_t_4 = NULL;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("grib2_addgrid", 0);
  __Pyx_INCREF(__pyx_v_gribmsg);

  /* "g2clib.pyx":613
 *     cdef void *gdsdat, *deflistdat, *gdstmpldat
 *     cdef Py_ssize_t buflen
 *     PyObject_AsReadBuffer(gds, &gdsdat, &buflen)             # <<<<<<<<<<<<<<
 *     PyObject_AsReadBuffer(gdstmpl, &gdstmpldat, &buflen)
 *     igds = <g2int *>gdsdat
 */
  PyObject_AsReadBuffer(__pyx_v_gds, (&__pyx_v_gdsdat), (&__pyx_v_buflen));

  /* "g2clib.pyx":614
 *     cdef Py_ssize_t buflen
 *     PyObject_AsReadBuffer(gds, &gdsdat, &buflen)
 *     PyObject_AsReadBuffer(gdstmpl, &gdstmpldat, &buflen)             # <<<<<<<<<<<<<<
 *     igds = <g2int *>gdsdat
 *     igdstmpl = <g2int *>gdstmpldat
 */
  PyObject_AsReadBuffer(__pyx_v_gdstmpl, (&__pyx_v_gdstmpldat), (&__pyx_v_buflen));

  /* "g2clib.pyx":615
 *     PyObject_AsReadBuffer(gds, &gdsdat, &buflen)
 *     PyObject_AsReadBuffer(gdstmpl, &gdstmpldat, &buflen)
 *     igds = <g2int *>gdsdat             # <<<<<<<<<<<<<<
 *     igdstmpl = <g2int *>gdstmpldat
 *     if igds[2] != 0:
 */
  __pyx_v_igds = ((g2int *)__pyx_v_gdsdat);

  /* "g2clib.pyx":616
 *     PyObject_AsReadBuffer(gdstmpl, &gdstmpldat, &buflen)
 *     igds = <g2int *>gdsdat
 *     igdstmpl = <g2int *>gdstmpldat             # <<<<<<<<<<<<<<
 *     if igds[2] != 0:
 *        PyObject_AsReadBuffer(deflist, &deflistdat, &buflen)
 */
  __pyx_v_igdstmpl = ((g2int *)__pyx_v_gdstmpldat);

  /* "g2clib.pyx":617
 *     igds = <g2int *>gdsdat
 *     igdstmpl = <g2int *>gdstmpldat
 *     if igds[2] != 0:             # <<<<<<<<<<<<<<
 *        PyObject_AsReadBuffer(deflist, &deflistdat, &buflen)
 *        ideflist = <g2int *>deflistdat
 */
  __pyx_t_1 = ((__pyx_v_igds[2]) != 0);
  if (__pyx_t_1) {

    /* "g2clib.pyx":618
 *     igdstmpl = <g2int *>gdstmpldat
 *     if igds[2] != 0:
 *        PyObject_AsReadBuffer(deflist, &deflistdat, &buflen)             # <<<<<<<<<<<<<<
 *        ideflist = <g2int *>deflistdat
 *        idefnum = <g2int>PyInt_AsLong(len(deflist))
 */
    PyObject_AsReadBuffer(__pyx_v_deflist, (&__pyx_v_deflistdat), (&__pyx_v_buflen));

    /* "g2clib.pyx":619
 *     if igds[2] != 0:
 *        PyObject_AsReadBuffer(deflist, &deflistdat, &buflen)
 *        ideflist = <g2int *>deflistdat             # <<<<<<<<<<<<<<
 *        idefnum = <g2int>PyInt_AsLong(len(deflist))
 *     else:
 */
    __pyx_v_ideflist = ((g2int *)__pyx_v_deflistdat);

    /* "g2clib.pyx":620
 *        PyObject_AsReadBuffer(deflist, &deflistdat, &buflen)
 *        ideflist = <g2int *>deflistdat
 *        idefnum = <g2int>PyInt_AsLong(len(deflist))             # <<<<<<<<<<<<<<
 *     else:
 *        ideflist = NULL
 */
    __pyx_t_2 = PyObject_Length(__pyx_v_deflist); if (unlikely(__pyx_t_2 == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 620; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __pyx_t_3 = PyInt_FromSsize_t(__pyx_t_2); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 620; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_3);
    __pyx_v_idefnum = ((g2int)PyInt_AsLong(__pyx_t_3));
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
    goto __pyx_L3;
  }
  /*else*/ {

    /* "g2clib.pyx":622
 *        idefnum = <g2int>PyInt_AsLong(len(deflist))
 *     else:
 *        ideflist = NULL             # <<<<<<<<<<<<<<
 *        idefnum = 0
 *     gribmsg = gribmsg + 4*(256+4+gds[2]+1)*b" "
 */
    __pyx_v_ideflist = NULL;

    /* "g2clib.pyx":623
 *     else:
 *        ideflist = NULL
 *        idefnum = 0             # <<<<<<<<<<<<<<
 *     gribmsg = gribmsg + 4*(256+4+gds[2]+1)*b" "
 *     cgrib = <unsigned char *>PyBytes_AsString(gribmsg)
 */
    __pyx_v_idefnum = 0;
  }
  __pyx_L3:;

  /* "g2clib.pyx":624
 *        ideflist = NULL
 *        idefnum = 0
 *     gribmsg = gribmsg + 4*(256+4+gds[2]+1)*b" "             # <<<<<<<<<<<<<<
 *     cgrib = <unsigned char *>PyBytes_AsString(gribmsg)
 *     ierr = g2_addgrid(cgrib, igds, igdstmpl, ideflist, idefnum)
 */
  __pyx_t_3 = __Pyx_GetItemInt(__pyx_v_gds, 2, sizeof(long), PyInt_FromLong); if (!__pyx_t_3) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 624; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_t_4 = PyNumber_Add(__pyx_int_260, __pyx_t_3); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 624; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_4);
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __pyx_t_3 = PyNumber_Add(__pyx_t_4, __pyx_int_1); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 624; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  __pyx_t_4 = PyNumber_Multiply(__pyx_int_4, __pyx_t_3); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 624; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_4);
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __pyx_t_3 = PyNumber_Multiply(__pyx_t_4, ((PyObject *)__pyx_kp_b_19)); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 624; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  __pyx_t_4 = PyNumber_Add(__pyx_v_gribmsg, __pyx_t_3); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 624; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_4);
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __Pyx_DECREF(__pyx_v_gribmsg);
  __pyx_v_gribmsg = __pyx_t_4;
  __pyx_t_4 = 0;

  /* "g2clib.pyx":625
 *        idefnum = 0
 *     gribmsg = gribmsg + 4*(256+4+gds[2]+1)*b" "
 *     cgrib = <unsigned char *>PyBytes_AsString(gribmsg)             # <<<<<<<<<<<<<<
 *     ierr = g2_addgrid(cgrib, igds, igdstmpl, ideflist, idefnum)
 *     if ierr < 0:
 */
  __pyx_v_cgrib = ((unsigned char *)PyBytes_AsString(__pyx_v_gribmsg));

  /* "g2clib.pyx":626
 *     gribmsg = gribmsg + 4*(256+4+gds[2]+1)*b" "
 *     cgrib = <unsigned char *>PyBytes_AsString(gribmsg)
 *     ierr = g2_addgrid(cgrib, igds, igdstmpl, ideflist, idefnum)             # <<<<<<<<<<<<<<
 *     if ierr < 0:
 *        msg = "error in grib2_addgrid, error code = %i" % ierr
 */
  __pyx_v_ierr = g2_addgrid(__pyx_v_cgrib, __pyx_v_igds, __pyx_v_igdstmpl, __pyx_v_ideflist, __pyx_v_idefnum);

  /* "g2clib.pyx":627
 *     cgrib = <unsigned char *>PyBytes_AsString(gribmsg)
 *     ierr = g2_addgrid(cgrib, igds, igdstmpl, ideflist, idefnum)
 *     if ierr < 0:             # <<<<<<<<<<<<<<
 *        msg = "error in grib2_addgrid, error code = %i" % ierr
 *        raise RuntimeError(msg)
 */
  __pyx_t_1 = (__pyx_v_ierr < 0);
  if (__pyx_t_1) {

    /* "g2clib.pyx":628
 *     ierr = g2_addgrid(cgrib, igds, igdstmpl, ideflist, idefnum)
 *     if ierr < 0:
 *        msg = "error in grib2_addgrid, error code = %i" % ierr             # <<<<<<<<<<<<<<
 *        raise RuntimeError(msg)
 *     gribmsg = PyBytes_FromStringAndSize(<char *>cgrib, ierr)
 */
    __pyx_t_4 = __Pyx_PyInt_to_py_int32_t(__pyx_v_ierr); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 628; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_4);
    __pyx_t_3 = PyNumber_Remainder(((PyObject *)__pyx_kp_s_23), __pyx_t_4); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 628; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(((PyObject *)__pyx_t_3));
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
    __pyx_v_msg = ((PyObject *)__pyx_t_3);
    __pyx_t_3 = 0;

    /* "g2clib.pyx":629
 *     if ierr < 0:
 *        msg = "error in grib2_addgrid, error code = %i" % ierr
 *        raise RuntimeError(msg)             # <<<<<<<<<<<<<<
 *     gribmsg = PyBytes_FromStringAndSize(<char *>cgrib, ierr)
 *     return gribmsg, ierr
 */
    __pyx_t_3 = PyTuple_New(1); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 629; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_3);
    __Pyx_INCREF(__pyx_v_msg);
    PyTuple_SET_ITEM(__pyx_t_3, 0, __pyx_v_msg);
    __Pyx_GIVEREF(__pyx_v_msg);
    __pyx_t_4 = PyObject_Call(__pyx_builtin_RuntimeError, ((PyObject *)__pyx_t_3), NULL); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 629; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_4);
    __Pyx_DECREF(((PyObject *)__pyx_t_3)); __pyx_t_3 = 0;
    __Pyx_Raise(__pyx_t_4, 0, 0, 0);
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
    {__pyx_filename = __pyx_f[0]; __pyx_lineno = 629; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    goto __pyx_L4;
  }
  __pyx_L4:;

  /* "g2clib.pyx":630
 *        msg = "error in grib2_addgrid, error code = %i" % ierr
 *        raise RuntimeError(msg)
 *     gribmsg = PyBytes_FromStringAndSize(<char *>cgrib, ierr)             # <<<<<<<<<<<<<<
 *     return gribmsg, ierr
 * 
 */
  __pyx_t_4 = PyBytes_FromStringAndSize(((char *)__pyx_v_cgrib), __pyx_v_ierr); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 630; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_4);
  __Pyx_DECREF(__pyx_v_gribmsg);
  __pyx_v_gribmsg = __pyx_t_4;
  __pyx_t_4 = 0;

  /* "g2clib.pyx":631
 *        raise RuntimeError(msg)
 *     gribmsg = PyBytes_FromStringAndSize(<char *>cgrib, ierr)
 *     return gribmsg, ierr             # <<<<<<<<<<<<<<
 * 
 * 
 */
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_4 = __Pyx_PyInt_to_py_int32_t(__pyx_v_ierr); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 631; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_4);
  __pyx_t_3 = PyTuple_New(2); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 631; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_INCREF(__pyx_v_gribmsg);
  PyTuple_SET_ITEM(__pyx_t_3, 0, __pyx_v_gribmsg);
  __Pyx_GIVEREF(__pyx_v_gribmsg);
  PyTuple_SET_ITEM(__pyx_t_3, 1, __pyx_t_4);
  __Pyx_GIVEREF(__pyx_t_4);
  __pyx_t_4 = 0;
  __pyx_r = ((PyObject *)__pyx_t_3);
  __pyx_t_3 = 0;
  goto __pyx_L0;

  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_3);
  __Pyx_XDECREF(__pyx_t_4);
  __Pyx_AddTraceback("g2clib.grib2_addgrid", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XDECREF(__pyx_v_msg);
  __Pyx_XDECREF(__pyx_v_gribmsg);
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* Python wrapper */
static PyObject *__pyx_pw_6g2clib_23grib2_addfield(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
static char __pyx_doc_6g2clib_22grib2_addfield[] = "\n   Packs up Sections 4 through 7 for a given field\n   and adds them to a GRIB2 message.  They are Product Definition Section,\n   Data Representation Section, Bit-Map Section and Data Section, respectively.\n   This routine is used with routines \"g2_create\",  \n   \"g2_addgrid\", and \"g2_gribend\" to create a complete GRIB2 message.  \n   g2_create must be called first to initialize a new GRIB2 message.\n   g2_addgrid must be called after g2_create and\n   before this routine to add the appropriate grid description to\n   the GRIB2 message. A call to g2_gribend is required to complete \n   GRIB2 message after all fields have been added.\n\n   gribmsg, ierr = g2_addfield(gribmsg,pdsnum,pdstmpl,coordlist,drsnum,\n                               drstmpl,fld,ngrdpts,ibmap,bmap)\n   INPUT ARGUMENT LIST:\n     cgrib    - Char array that contains the GRIB2 message to which sections\n                4 through 7 should be added.\n     pdsnum   - Product Definition Template Number ( see Code Table 4.0)\n     pdstmpl  - numpy array with data values for the specified Product Definition\n                Template ( N=pdsnum ).  Each element of this integer \n                array contains an entry (in the order specified) of Product\n                Defintion Template 4.N\n     coordlist- numpy array (float32) containg floating point values intended to\n                document the vertical discretisation associated to model data\n                on hybrid coordinate vertical levels.\n     numcoord - number of values in array coordlist.\n     drsnum   - Data Representation Template Number ( see Code Table 5.0 )\n     drstmpl  - numpy array with data values for the specified Data Representation\n                Template ( N=drsnum ).  Each element of this integer \n                array contains an entry (in the order specified) of Data\n                Representation Template 5.N\n                Note that some values in this template (eg. reference\n                values, ""number of bits, etc...) may be changed by the\n                data packing algorithms.\n                Use this to specify scaling factors and order of\n                spatial differencing, if desired.\n     field    - numpy array (float32) of data points to pack.\n     ngrdpts  - Number of data points in grid.\n                i.e.  size of fld and bmap.\n     ibitmap  - Bitmap indicator ( see Code Table 6.0 )\n                0 = bitmap applies and is included in Section 6.\n                1-253 = Predefined bitmap applies\n                254 = Previously defined bitmap applies to this field\n                255 = Bit map does not apply to this product.\n     bitmap   - numpy array (int32) containing bitmap to be added. \n                (if ibitmap=0 or 254)\n\n   OUTPUT ARGUMENT LIST:      \n     gribmsg  - String with the updated GRIB2 message.\n                Must be allocated large enough to store the entire\n                GRIB2 message.\n\n   RETURN VALUES:\n     ierr     - Return code.\n              > 0 = Current size of updated GRIB2 message\n               -1 = GRIB message was not initialized.  Need to call\n                    routine gribcreate first.\n               -2 = GRIB message already complete.  Cannot add new section.\n               -3 = Sum of Section byte counts doesn't add to total byte count\n               -4 = Previous Section was not 3 or 7.\n               -5 = Could not find requested Product Definition Template.\n               -6 = Section 3 (GDS) not previously defined in message\n               -7 = Tried to use unsupported Data Representationi Template\n               -8 = Specified use of a previously defined bitmap, but one\n                    does not exist in the GRIB message.\n               -9 = GDT of one of 5.50 through 5.53 required to pack field \n                    using DRT 5.51.\n              -10 = Error packing data field. \n    ";
static PyMethodDef __pyx_mdef_6g2clib_23grib2_addfield = {__Pyx_NAMESTR("grib2_addfield"), (PyCFunction)__pyx_pw_6g2clib_23grib2_addfield, METH_VARARGS|METH_KEYWORDS, __Pyx_DOCSTR(__pyx_doc_6g2clib_22grib2_addfield)};
static PyObject *__pyx_pw_6g2clib_23grib2_addfield(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
  PyObject *__pyx_v_gribmsg = 0;
  PyObject *__pyx_v_pdsnum = 0;
  PyObject *__pyx_v_pdstmpl = 0;
  PyObject *__pyx_v_coordlist = 0;
  PyObject *__pyx_v_drsnum = 0;
  PyObject *__pyx_v_drstmpl = 0;
  PyObject *__pyx_v_field = 0;
  PyObject *__pyx_v_ibitmap = 0;
  PyObject *__pyx_v_bitmap = 0;
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("grib2_addfield (wrapper)", 0);
  {
    static PyObject **__pyx_pyargnames[] = {&__pyx_n_s__gribmsg,&__pyx_n_s__pdsnum,&__pyx_n_s__pdstmpl,&__pyx_n_s__coordlist,&__pyx_n_s__drsnum,&__pyx_n_s__drstmpl,&__pyx_n_s__field,&__pyx_n_s__ibitmap,&__pyx_n_s__bitmap,0};
    PyObject* values[9] = {0,0,0,0,0,0,0,0,0};
    if (unlikely(__pyx_kwds)) {
      Py_ssize_t kw_args;
      const Py_ssize_t pos_args = PyTuple_GET_SIZE(__pyx_args);
      switch (pos_args) {
        case  9: values[8] = PyTuple_GET_ITEM(__pyx_args, 8);
        case  8: values[7] = PyTuple_GET_ITEM(__pyx_args, 7);
        case  7: values[6] = PyTuple_GET_ITEM(__pyx_args, 6);
        case  6: values[5] = PyTuple_GET_ITEM(__pyx_args, 5);
        case  5: values[4] = PyTuple_GET_ITEM(__pyx_args, 4);
        case  4: values[3] = PyTuple_GET_ITEM(__pyx_args, 3);
        case  3: values[2] = PyTuple_GET_ITEM(__pyx_args, 2);
        case  2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
        case  1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
        case  0: break;
        default: goto __pyx_L5_argtuple_error;
      }
      kw_args = PyDict_Size(__pyx_kwds);
      switch (pos_args) {
        case  0:
        if (likely((values[0] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__gribmsg)) != 0)) kw_args--;
        else goto __pyx_L5_argtuple_error;
        case  1:
        if (likely((values[1] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__pdsnum)) != 0)) kw_args--;
        else {
          __Pyx_RaiseArgtupleInvalid("grib2_addfield", 1, 9, 9, 1); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 634; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
        }
        case  2:
        if (likely((values[2] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__pdstmpl)) != 0)) kw_args--;
        else {
          __Pyx_RaiseArgtupleInvalid("grib2_addfield", 1, 9, 9, 2); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 634; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
        }
        case  3:
        if (likely((values[3] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__coordlist)) != 0)) kw_args--;
        else {
          __Pyx_RaiseArgtupleInvalid("grib2_addfield", 1, 9, 9, 3); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 634; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
        }
        case  4:
        if (likely((values[4] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__drsnum)) != 0)) kw_args--;
        else {
          __Pyx_RaiseArgtupleInvalid("grib2_addfield", 1, 9, 9, 4); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 634; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
        }
        case  5:
        if (likely((values[5] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__drstmpl)) != 0)) kw_args--;
        else {
          __Pyx_RaiseArgtupleInvalid("grib2_addfield", 1, 9, 9, 5); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 634; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
        }
        case  6:
        if (likely((values[6] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__field)) != 0)) kw_args--;
        else {
          __Pyx_RaiseArgtupleInvalid("grib2_addfield", 1, 9, 9, 6); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 634; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
        }
        case  7:
        if (likely((values[7] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__ibitmap)) != 0)) kw_args--;
        else {
          __Pyx_RaiseArgtupleInvalid("grib2_addfield", 1, 9, 9, 7); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 634; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
        }
        case  8:
        if (likely((values[8] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__bitmap)) != 0)) kw_args--;
        else {
          __Pyx_RaiseArgtupleInvalid("grib2_addfield", 1, 9, 9, 8); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 634; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
        }
      }
      if (unlikely(kw_args > 0)) {
        if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "grib2_addfield") < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 634; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
      }
    } else if (PyTuple_GET_SIZE(__pyx_args) != 9) {
      goto __pyx_L5_argtuple_error;
    } else {
      values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
      values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
      values[2] = PyTuple_GET_ITEM(__pyx_args, 2);
      values[3] = PyTuple_GET_ITEM(__pyx_args, 3);
      values[4] = PyTuple_GET_ITEM(__pyx_args, 4);
      values[5] = PyTuple_GET_ITEM(__pyx_args, 5);
      values[6] = PyTuple_GET_ITEM(__pyx_args, 6);
      values[7] = PyTuple_GET_ITEM(__pyx_args, 7);
      values[8] = PyTuple_GET_ITEM(__pyx_args, 8);
    }
    __pyx_v_gribmsg = values[0];
    __pyx_v_pdsnum = values[1];
    __pyx_v_pdstmpl = values[2];
    __pyx_v_coordlist = values[3];
    __pyx_v_drsnum = values[4];
    __pyx_v_drstmpl = values[5];
    __pyx_v_field = values[6];
    __pyx_v_ibitmap = values[7];
    __pyx_v_bitmap = values[8];
  }
  goto __pyx_L4_argument_unpacking_done;
  __pyx_L5_argtuple_error:;
  __Pyx_RaiseArgtupleInvalid("grib2_addfield", 1, 9, 9, PyTuple_GET_SIZE(__pyx_args)); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 634; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
  __pyx_L3_error:;
  __Pyx_AddTraceback("g2clib.grib2_addfield", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __Pyx_RefNannyFinishContext();
  return NULL;
  __pyx_L4_argument_unpacking_done:;
  __pyx_r = __pyx_pf_6g2clib_22grib2_addfield(__pyx_self, __pyx_v_gribmsg, __pyx_v_pdsnum, __pyx_v_pdstmpl, __pyx_v_coordlist, __pyx_v_drsnum, __pyx_v_drstmpl, __pyx_v_field, __pyx_v_ibitmap, __pyx_v_bitmap);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "g2clib.pyx":634
 * 
 * 
 * def grib2_addfield(gribmsg,pdsnum,object pdstmpl,object coordlist,             # <<<<<<<<<<<<<<
 *                    drsnum,object drstmpl,object field,
 *                    ibitmap,object bitmap):
 */

static PyObject *__pyx_pf_6g2clib_22grib2_addfield(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_gribmsg, PyObject *__pyx_v_pdsnum, PyObject *__pyx_v_pdstmpl, PyObject *__pyx_v_coordlist, PyObject *__pyx_v_drsnum, PyObject *__pyx_v_drstmpl, PyObject *__pyx_v_field, PyObject *__pyx_v_ibitmap, PyObject *__pyx_v_bitmap) {
  g2int __pyx_v_ierr;
  g2int __pyx_v_ipdsnum;
  g2int __pyx_v_numcoord;
  g2int *__pyx_v_ipdstmpl;
  g2int __pyx_v_idrsnum;
  g2int *__pyx_v_idrstmpl;
  g2float *__pyx_v_fld;
  g2float *__pyx_v_fcoordlist;
  g2int *__pyx_v_bmap;
  g2int __pyx_v_ngrdpts;
  g2int __pyx_v_ibmap;
  void *__pyx_v_pdtmpldat;
  void *__pyx_v_drtmpldat;
  void *__pyx_v_coordlistdat;
  void *__pyx_v_fielddat;
  void *__pyx_v_bitmapdat;
  Py_ssize_t __pyx_v_buflen;
  unsigned char *__pyx_v_cgrib;
  PyObject *__pyx_v_msg = NULL;
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  int __pyx_t_1;
  Py_ssize_t __pyx_t_2;
  PyObject *__pyx_t_3 = NULL;
  int __pyx_t_4;
  int __pyx_t_5;
  PyObject *__pyx_t_6 = NULL;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("grib2_addfield", 0);
  __Pyx_INCREF(__pyx_v_gribmsg);

  /* "g2clib.pyx":712
 *     cdef Py_ssize_t buflen
 *     cdef unsigned char *cgrib
 *     ipdsnum = <g2int>PyInt_AsLong(pdsnum)             # <<<<<<<<<<<<<<
 *     PyObject_AsReadBuffer(pdstmpl, &pdtmpldat, &buflen)
 *     ipdstmpl = <g2int *>pdtmpldat
 */
  __pyx_v_ipdsnum = ((g2int)PyInt_AsLong(__pyx_v_pdsnum));

  /* "g2clib.pyx":713
 *     cdef unsigned char *cgrib
 *     ipdsnum = <g2int>PyInt_AsLong(pdsnum)
 *     PyObject_AsReadBuffer(pdstmpl, &pdtmpldat, &buflen)             # <<<<<<<<<<<<<<
 *     ipdstmpl = <g2int *>pdtmpldat
 *     idrsnum = <g2int>PyInt_AsLong(drsnum)
 */
  PyObject_AsReadBuffer(__pyx_v_pdstmpl, (&__pyx_v_pdtmpldat), (&__pyx_v_buflen));

  /* "g2clib.pyx":714
 *     ipdsnum = <g2int>PyInt_AsLong(pdsnum)
 *     PyObject_AsReadBuffer(pdstmpl, &pdtmpldat, &buflen)
 *     ipdstmpl = <g2int *>pdtmpldat             # <<<<<<<<<<<<<<
 *     idrsnum = <g2int>PyInt_AsLong(drsnum)
 *     PyObject_AsReadBuffer(drstmpl, &drtmpldat, &buflen)
 */
  __pyx_v_ipdstmpl = ((g2int *)__pyx_v_pdtmpldat);

  /* "g2clib.pyx":715
 *     PyObject_AsReadBuffer(pdstmpl, &pdtmpldat, &buflen)
 *     ipdstmpl = <g2int *>pdtmpldat
 *     idrsnum = <g2int>PyInt_AsLong(drsnum)             # <<<<<<<<<<<<<<
 *     PyObject_AsReadBuffer(drstmpl, &drtmpldat, &buflen)
 *     idrstmpl = <g2int *>drtmpldat
 */
  __pyx_v_idrsnum = ((g2int)PyInt_AsLong(__pyx_v_drsnum));

  /* "g2clib.pyx":716
 *     ipdstmpl = <g2int *>pdtmpldat
 *     idrsnum = <g2int>PyInt_AsLong(drsnum)
 *     PyObject_AsReadBuffer(drstmpl, &drtmpldat, &buflen)             # <<<<<<<<<<<<<<
 *     idrstmpl = <g2int *>drtmpldat
 *     if coordlist is not None:
 */
  PyObject_AsReadBuffer(__pyx_v_drstmpl, (&__pyx_v_drtmpldat), (&__pyx_v_buflen));

  /* "g2clib.pyx":717
 *     idrsnum = <g2int>PyInt_AsLong(drsnum)
 *     PyObject_AsReadBuffer(drstmpl, &drtmpldat, &buflen)
 *     idrstmpl = <g2int *>drtmpldat             # <<<<<<<<<<<<<<
 *     if coordlist is not None:
 *         PyObject_AsReadBuffer(coordlist, &coordlistdat, &buflen)
 */
  __pyx_v_idrstmpl = ((g2int *)__pyx_v_drtmpldat);

  /* "g2clib.pyx":718
 *     PyObject_AsReadBuffer(drstmpl, &drtmpldat, &buflen)
 *     idrstmpl = <g2int *>drtmpldat
 *     if coordlist is not None:             # <<<<<<<<<<<<<<
 *         PyObject_AsReadBuffer(coordlist, &coordlistdat, &buflen)
 *         fcoordlist = <g2float *>coordlistdat
 */
  __pyx_t_1 = (__pyx_v_coordlist != Py_None);
  if (__pyx_t_1) {

    /* "g2clib.pyx":719
 *     idrstmpl = <g2int *>drtmpldat
 *     if coordlist is not None:
 *         PyObject_AsReadBuffer(coordlist, &coordlistdat, &buflen)             # <<<<<<<<<<<<<<
 *         fcoordlist = <g2float *>coordlistdat
 *         numcoord = len(coordlist)
 */
    PyObject_AsReadBuffer(__pyx_v_coordlist, (&__pyx_v_coordlistdat), (&__pyx_v_buflen));

    /* "g2clib.pyx":720
 *     if coordlist is not None:
 *         PyObject_AsReadBuffer(coordlist, &coordlistdat, &buflen)
 *         fcoordlist = <g2float *>coordlistdat             # <<<<<<<<<<<<<<
 *         numcoord = len(coordlist)
 *     else:
 */
    __pyx_v_fcoordlist = ((g2float *)__pyx_v_coordlistdat);

    /* "g2clib.pyx":721
 *         PyObject_AsReadBuffer(coordlist, &coordlistdat, &buflen)
 *         fcoordlist = <g2float *>coordlistdat
 *         numcoord = len(coordlist)             # <<<<<<<<<<<<<<
 *     else:
 *         fcoordlist = NULL
 */
    __pyx_t_2 = PyObject_Length(__pyx_v_coordlist); if (unlikely(__pyx_t_2 == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 721; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __pyx_v_numcoord = __pyx_t_2;
    goto __pyx_L3;
  }
  /*else*/ {

    /* "g2clib.pyx":723
 *         numcoord = len(coordlist)
 *     else:
 *         fcoordlist = NULL             # <<<<<<<<<<<<<<
 *         numcoord = 0
 *     PyObject_AsReadBuffer(field, &fielddat, &buflen)
 */
    __pyx_v_fcoordlist = NULL;

    /* "g2clib.pyx":724
 *     else:
 *         fcoordlist = NULL
 *         numcoord = 0             # <<<<<<<<<<<<<<
 *     PyObject_AsReadBuffer(field, &fielddat, &buflen)
 *     fld = <g2float *>fielddat
 */
    __pyx_v_numcoord = 0;
  }
  __pyx_L3:;

  /* "g2clib.pyx":725
 *         fcoordlist = NULL
 *         numcoord = 0
 *     PyObject_AsReadBuffer(field, &fielddat, &buflen)             # <<<<<<<<<<<<<<
 *     fld = <g2float *>fielddat
 *     ibmap = <g2int>PyInt_AsLong(ibitmap)
 */
  PyObject_AsReadBuffer(__pyx_v_field, (&__pyx_v_fielddat), (&__pyx_v_buflen));

  /* "g2clib.pyx":726
 *         numcoord = 0
 *     PyObject_AsReadBuffer(field, &fielddat, &buflen)
 *     fld = <g2float *>fielddat             # <<<<<<<<<<<<<<
 *     ibmap = <g2int>PyInt_AsLong(ibitmap)
 *     ngrdpts = len(field)
 */
  __pyx_v_fld = ((g2float *)__pyx_v_fielddat);

  /* "g2clib.pyx":727
 *     PyObject_AsReadBuffer(field, &fielddat, &buflen)
 *     fld = <g2float *>fielddat
 *     ibmap = <g2int>PyInt_AsLong(ibitmap)             # <<<<<<<<<<<<<<
 *     ngrdpts = len(field)
 *     if ibitmap == 0 or ibitmap == 254:
 */
  __pyx_v_ibmap = ((g2int)PyInt_AsLong(__pyx_v_ibitmap));

  /* "g2clib.pyx":728
 *     fld = <g2float *>fielddat
 *     ibmap = <g2int>PyInt_AsLong(ibitmap)
 *     ngrdpts = len(field)             # <<<<<<<<<<<<<<
 *     if ibitmap == 0 or ibitmap == 254:
 *         PyObject_AsReadBuffer(bitmap, &bitmapdat, &buflen)
 */
  __pyx_t_2 = PyObject_Length(__pyx_v_field); if (unlikely(__pyx_t_2 == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 728; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_v_ngrdpts = __pyx_t_2;

  /* "g2clib.pyx":729
 *     ibmap = <g2int>PyInt_AsLong(ibitmap)
 *     ngrdpts = len(field)
 *     if ibitmap == 0 or ibitmap == 254:             # <<<<<<<<<<<<<<
 *         PyObject_AsReadBuffer(bitmap, &bitmapdat, &buflen)
 *         bmap  = <g2int *>bitmapdat
 */
  __pyx_t_3 = PyObject_RichCompare(__pyx_v_ibitmap, __pyx_int_0, Py_EQ); __Pyx_XGOTREF(__pyx_t_3); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 729; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_t_1 = __Pyx_PyObject_IsTrue(__pyx_t_3); if (unlikely(__pyx_t_1 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 729; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  if (!__pyx_t_1) {
    __pyx_t_3 = PyObject_RichCompare(__pyx_v_ibitmap, __pyx_int_254, Py_EQ); __Pyx_XGOTREF(__pyx_t_3); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 729; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __pyx_t_4 = __Pyx_PyObject_IsTrue(__pyx_t_3); if (unlikely(__pyx_t_4 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 729; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
    __pyx_t_5 = __pyx_t_4;
  } else {
    __pyx_t_5 = __pyx_t_1;
  }
  if (__pyx_t_5) {

    /* "g2clib.pyx":730
 *     ngrdpts = len(field)
 *     if ibitmap == 0 or ibitmap == 254:
 *         PyObject_AsReadBuffer(bitmap, &bitmapdat, &buflen)             # <<<<<<<<<<<<<<
 *         bmap  = <g2int *>bitmapdat
 *     else:
 */
    PyObject_AsReadBuffer(__pyx_v_bitmap, (&__pyx_v_bitmapdat), (&__pyx_v_buflen));

    /* "g2clib.pyx":731
 *     if ibitmap == 0 or ibitmap == 254:
 *         PyObject_AsReadBuffer(bitmap, &bitmapdat, &buflen)
 *         bmap  = <g2int *>bitmapdat             # <<<<<<<<<<<<<<
 *     else:
 *         bmap = NULL
 */
    __pyx_v_bmap = ((g2int *)__pyx_v_bitmapdat);
    goto __pyx_L4;
  }
  /*else*/ {

    /* "g2clib.pyx":733
 *         bmap  = <g2int *>bitmapdat
 *     else:
 *         bmap = NULL             # <<<<<<<<<<<<<<
 *     gribmsg = gribmsg + 4*(len(drstmpl)+ngrdpts+4)*b" "
 *     cgrib = <unsigned char *>PyBytes_AsString(gribmsg)
 */
    __pyx_v_bmap = NULL;
  }
  __pyx_L4:;

  /* "g2clib.pyx":734
 *     else:
 *         bmap = NULL
 *     gribmsg = gribmsg + 4*(len(drstmpl)+ngrdpts+4)*b" "             # <<<<<<<<<<<<<<
 *     cgrib = <unsigned char *>PyBytes_AsString(gribmsg)
 *     ierr = g2_addfield(cgrib,ipdsnum,ipdstmpl,fcoordlist,numcoord,idrsnum,idrstmpl,fld,ngrdpts,ibmap,bmap)
 */
  __pyx_t_2 = PyObject_Length(__pyx_v_drstmpl); if (unlikely(__pyx_t_2 == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 734; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_t_3 = PyInt_FromSsize_t((4 * ((__pyx_t_2 + __pyx_v_ngrdpts) + 4))); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 734; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_t_6 = PyNumber_Multiply(__pyx_t_3, ((PyObject *)__pyx_kp_b_19)); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 734; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_6);
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __pyx_t_3 = PyNumber_Add(__pyx_v_gribmsg, __pyx_t_6); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 734; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
  __Pyx_DECREF(__pyx_v_gribmsg);
  __pyx_v_gribmsg = __pyx_t_3;
  __pyx_t_3 = 0;

  /* "g2clib.pyx":735
 *         bmap = NULL
 *     gribmsg = gribmsg + 4*(len(drstmpl)+ngrdpts+4)*b" "
 *     cgrib = <unsigned char *>PyBytes_AsString(gribmsg)             # <<<<<<<<<<<<<<
 *     ierr = g2_addfield(cgrib,ipdsnum,ipdstmpl,fcoordlist,numcoord,idrsnum,idrstmpl,fld,ngrdpts,ibmap,bmap)
 *     if ierr < 0:
 */
  __pyx_v_cgrib = ((unsigned char *)PyBytes_AsString(__pyx_v_gribmsg));

  /* "g2clib.pyx":736
 *     gribmsg = gribmsg + 4*(len(drstmpl)+ngrdpts+4)*b" "
 *     cgrib = <unsigned char *>PyBytes_AsString(gribmsg)
 *     ierr = g2_addfield(cgrib,ipdsnum,ipdstmpl,fcoordlist,numcoord,idrsnum,idrstmpl,fld,ngrdpts,ibmap,bmap)             # <<<<<<<<<<<<<<
 *     if ierr < 0:
 *        msg = "error in grib2_addfield, error code = %i" % ierr
 */
  __pyx_v_ierr = g2_addfield(__pyx_v_cgrib, __pyx_v_ipdsnum, __pyx_v_ipdstmpl, __pyx_v_fcoordlist, __pyx_v_numcoord, __pyx_v_idrsnum, __pyx_v_idrstmpl, __pyx_v_fld, __pyx_v_ngrdpts, __pyx_v_ibmap, __pyx_v_bmap);

  /* "g2clib.pyx":737
 *     cgrib = <unsigned char *>PyBytes_AsString(gribmsg)
 *     ierr = g2_addfield(cgrib,ipdsnum,ipdstmpl,fcoordlist,numcoord,idrsnum,idrstmpl,fld,ngrdpts,ibmap,bmap)
 *     if ierr < 0:             # <<<<<<<<<<<<<<
 *        msg = "error in grib2_addfield, error code = %i" % ierr
 *        raise RuntimeError(msg)
 */
  __pyx_t_5 = (__pyx_v_ierr < 0);
  if (__pyx_t_5) {

    /* "g2clib.pyx":738
 *     ierr = g2_addfield(cgrib,ipdsnum,ipdstmpl,fcoordlist,numcoord,idrsnum,idrstmpl,fld,ngrdpts,ibmap,bmap)
 *     if ierr < 0:
 *        msg = "error in grib2_addfield, error code = %i" % ierr             # <<<<<<<<<<<<<<
 *        raise RuntimeError(msg)
 *     gribmsg = PyBytes_FromStringAndSize(<char *>cgrib, ierr)
 */
    __pyx_t_3 = __Pyx_PyInt_to_py_int32_t(__pyx_v_ierr); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 738; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_3);
    __pyx_t_6 = PyNumber_Remainder(((PyObject *)__pyx_kp_s_24), __pyx_t_3); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 738; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(((PyObject *)__pyx_t_6));
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
    __pyx_v_msg = ((PyObject *)__pyx_t_6);
    __pyx_t_6 = 0;

    /* "g2clib.pyx":739
 *     if ierr < 0:
 *        msg = "error in grib2_addfield, error code = %i" % ierr
 *        raise RuntimeError(msg)             # <<<<<<<<<<<<<<
 *     gribmsg = PyBytes_FromStringAndSize(<char *>cgrib, ierr)
 *     return gribmsg, ierr
 */
    __pyx_t_6 = PyTuple_New(1); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 739; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_6);
    __Pyx_INCREF(__pyx_v_msg);
    PyTuple_SET_ITEM(__pyx_t_6, 0, __pyx_v_msg);
    __Pyx_GIVEREF(__pyx_v_msg);
    __pyx_t_3 = PyObject_Call(__pyx_builtin_RuntimeError, ((PyObject *)__pyx_t_6), NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 739; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_3);
    __Pyx_DECREF(((PyObject *)__pyx_t_6)); __pyx_t_6 = 0;
    __Pyx_Raise(__pyx_t_3, 0, 0, 0);
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
    {__pyx_filename = __pyx_f[0]; __pyx_lineno = 739; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    goto __pyx_L5;
  }
  __pyx_L5:;

  /* "g2clib.pyx":740
 *        msg = "error in grib2_addfield, error code = %i" % ierr
 *        raise RuntimeError(msg)
 *     gribmsg = PyBytes_FromStringAndSize(<char *>cgrib, ierr)             # <<<<<<<<<<<<<<
 *     return gribmsg, ierr
 */
  __pyx_t_3 = PyBytes_FromStringAndSize(((char *)__pyx_v_cgrib), __pyx_v_ierr); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 740; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_DECREF(__pyx_v_gribmsg);
  __pyx_v_gribmsg = __pyx_t_3;
  __pyx_t_3 = 0;

  /* "g2clib.pyx":741
 *        raise RuntimeError(msg)
 *     gribmsg = PyBytes_FromStringAndSize(<char *>cgrib, ierr)
 *     return gribmsg, ierr             # <<<<<<<<<<<<<<
 */
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_3 = __Pyx_PyInt_to_py_int32_t(__pyx_v_ierr); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 741; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_t_6 = PyTuple_New(2); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 741; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_6);
  __Pyx_INCREF(__pyx_v_gribmsg);
  PyTuple_SET_ITEM(__pyx_t_6, 0, __pyx_v_gribmsg);
  __Pyx_GIVEREF(__pyx_v_gribmsg);
  PyTuple_SET_ITEM(__pyx_t_6, 1, __pyx_t_3);
  __Pyx_GIVEREF(__pyx_t_3);
  __pyx_t_3 = 0;
  __pyx_r = ((PyObject *)__pyx_t_6);
  __pyx_t_6 = 0;
  goto __pyx_L0;

  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_3);
  __Pyx_XDECREF(__pyx_t_6);
  __Pyx_AddTraceback("g2clib.grib2_addfield", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XDECREF(__pyx_v_msg);
  __Pyx_XDECREF(__pyx_v_gribmsg);
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

static PyMethodDef __pyx_methods[] = {
  {0, 0, 0, 0}
};

#if PY_MAJOR_VERSION >= 3
static struct PyModuleDef __pyx_moduledef = {
    PyModuleDef_HEAD_INIT,
    __Pyx_NAMESTR("g2clib"),
    __Pyx_DOCSTR(__pyx_k_25), /* m_doc */
    -1, /* m_size */
    __pyx_methods /* m_methods */,
    NULL, /* m_reload */
    NULL, /* m_traverse */
    NULL, /* m_clear */
    NULL /* m_free */
};
#endif

static __Pyx_StringTabEntry __pyx_string_tab[] = {
  {&__pyx_kp_s_1, __pyx_k_1, sizeof(__pyx_k_1), 0, 0, 1, 0},
  {&__pyx_kp_s_11, __pyx_k_11, sizeof(__pyx_k_11), 0, 0, 1, 0},
  {&__pyx_kp_s_12, __pyx_k_12, sizeof(__pyx_k_12), 0, 0, 1, 0},
  {&__pyx_kp_s_13, __pyx_k_13, sizeof(__pyx_k_13), 0, 0, 1, 0},
  {&__pyx_kp_s_15, __pyx_k_15, sizeof(__pyx_k_15), 0, 0, 1, 0},
  {&__pyx_kp_s_16, __pyx_k_16, sizeof(__pyx_k_16), 0, 0, 1, 0},
  {&__pyx_kp_s_17, __pyx_k_17, sizeof(__pyx_k_17), 0, 0, 1, 0},
  {&__pyx_kp_s_18, __pyx_k_18, sizeof(__pyx_k_18), 0, 0, 1, 0},
  {&__pyx_kp_b_19, __pyx_k_19, sizeof(__pyx_k_19), 0, 0, 0, 0},
  {&__pyx_kp_s_2, __pyx_k_2, sizeof(__pyx_k_2), 0, 0, 1, 0},
  {&__pyx_kp_s_20, __pyx_k_20, sizeof(__pyx_k_20), 0, 0, 1, 0},
  {&__pyx_kp_b_21, __pyx_k_21, sizeof(__pyx_k_21), 0, 0, 0, 0},
  {&__pyx_kp_s_22, __pyx_k_22, sizeof(__pyx_k_22), 0, 0, 1, 0},
  {&__pyx_kp_s_23, __pyx_k_23, sizeof(__pyx_k_23), 0, 0, 1, 0},
  {&__pyx_kp_s_24, __pyx_k_24, sizeof(__pyx_k_24), 0, 0, 1, 0},
  {&__pyx_kp_s_28, __pyx_k_28, sizeof(__pyx_k_28), 0, 0, 1, 0},
  {&__pyx_kp_s_3, __pyx_k_3, sizeof(__pyx_k_3), 0, 0, 1, 0},
  {&__pyx_kp_s_4, __pyx_k_4, sizeof(__pyx_k_4), 0, 0, 1, 0},
  {&__pyx_kp_s_5, __pyx_k_5, sizeof(__pyx_k_5), 0, 0, 1, 0},
  {&__pyx_kp_s_6, __pyx_k_6, sizeof(__pyx_k_6), 0, 0, 1, 0},
  {&__pyx_kp_s_7, __pyx_k_7, sizeof(__pyx_k_7), 0, 0, 1, 0},
  {&__pyx_kp_s_8, __pyx_k_8, sizeof(__pyx_k_8), 0, 0, 1, 0},
  {&__pyx_kp_s_9, __pyx_k_9, sizeof(__pyx_k_9), 0, 0, 1, 0},
  {&__pyx_n_s__C, __pyx_k__C, sizeof(__pyx_k__C), 0, 0, 1, 1},
  {&__pyx_n_s__RuntimeError, __pyx_k__RuntimeError, sizeof(__pyx_k__RuntimeError), 0, 0, 1, 1},
  {&__pyx_n_s____main__, __pyx_k____main__, sizeof(__pyx_k____main__), 0, 0, 1, 1},
  {&__pyx_n_s____test__, __pyx_k____test__, sizeof(__pyx_k____test__), 0, 0, 1, 1},
  {&__pyx_n_s__bitmap, __pyx_k__bitmap, sizeof(__pyx_k__bitmap), 0, 0, 1, 1},
  {&__pyx_n_s__bitmapdat, __pyx_k__bitmapdat, sizeof(__pyx_k__bitmapdat), 0, 0, 1, 1},
  {&__pyx_n_s__bitsofprecision, __pyx_k__bitsofprecision, sizeof(__pyx_k__bitsofprecision), 0, 0, 1, 1},
  {&__pyx_n_s__bmap, __pyx_k__bmap, sizeof(__pyx_k__bmap), 0, 0, 1, 1},
  {&__pyx_n_s__buflen, __pyx_k__buflen, sizeof(__pyx_k__buflen), 0, 0, 1, 1},
  {&__pyx_n_s__bufleni, __pyx_k__bufleni, sizeof(__pyx_k__bufleni), 0, 0, 1, 1},
  {&__pyx_n_s__buflenr, __pyx_k__buflenr, sizeof(__pyx_k__buflenr), 0, 0, 1, 1},
  {&__pyx_n_s__ceil, __pyx_k__ceil, sizeof(__pyx_k__ceil), 0, 0, 1, 1},
  {&__pyx_n_s__cgrib, __pyx_k__cgrib, sizeof(__pyx_k__cgrib), 0, 0, 1, 1},
  {&__pyx_n_s__coordlist, __pyx_k__coordlist, sizeof(__pyx_k__coordlist), 0, 0, 1, 1},
  {&__pyx_n_s__coordlistdat, __pyx_k__coordlistdat, sizeof(__pyx_k__coordlistdat), 0, 0, 1, 1},
  {&__pyx_n_s__data, __pyx_k__data, sizeof(__pyx_k__data), 0, 0, 1, 1},
  {&__pyx_n_s__deflist, __pyx_k__deflist, sizeof(__pyx_k__deflist), 0, 0, 1, 1},
  {&__pyx_n_s__deflistdat, __pyx_k__deflistdat, sizeof(__pyx_k__deflistdat), 0, 0, 1, 1},
  {&__pyx_n_s__defnum, __pyx_k__defnum, sizeof(__pyx_k__defnum), 0, 0, 1, 1},
  {&__pyx_n_s__digitsofprecision, __pyx_k__digitsofprecision, sizeof(__pyx_k__digitsofprecision), 0, 0, 1, 1},
  {&__pyx_n_s__drsnum, __pyx_k__drsnum, sizeof(__pyx_k__drsnum), 0, 0, 1, 1},
  {&__pyx_n_s__drstmpl, __pyx_k__drstmpl, sizeof(__pyx_k__drstmpl), 0, 0, 1, 1},
  {&__pyx_n_s__drtmpl, __pyx_k__drtmpl, sizeof(__pyx_k__drtmpl), 0, 0, 1, 1},
  {&__pyx_n_s__drtmpldat, __pyx_k__drtmpldat, sizeof(__pyx_k__drtmpldat), 0, 0, 1, 1},
  {&__pyx_n_s__drtnum, __pyx_k__drtnum, sizeof(__pyx_k__drtnum), 0, 0, 1, 1},
  {&__pyx_n_s__dtype, __pyx_k__dtype, sizeof(__pyx_k__dtype), 0, 0, 1, 1},
  {&__pyx_n_s__f4, __pyx_k__f4, sizeof(__pyx_k__f4), 0, 0, 1, 1},
  {&__pyx_n_s__fcoordlist, __pyx_k__fcoordlist, sizeof(__pyx_k__fcoordlist), 0, 0, 1, 1},
  {&__pyx_n_s__field, __pyx_k__field, sizeof(__pyx_k__field), 0, 0, 1, 1},
  {&__pyx_n_s__fielddat, __pyx_k__fielddat, sizeof(__pyx_k__fielddat), 0, 0, 1, 1},
  {&__pyx_n_s__fld, __pyx_k__fld, sizeof(__pyx_k__fld), 0, 0, 1, 1},
  {&__pyx_n_s__fldmax, __pyx_k__fldmax, sizeof(__pyx_k__fldmax), 0, 0, 1, 1},
  {&__pyx_n_s__fldmin, __pyx_k__fldmin, sizeof(__pyx_k__fldmin), 0, 0, 1, 1},
  {&__pyx_n_s__float32, __pyx_k__float32, sizeof(__pyx_k__float32), 0, 0, 1, 1},
  {&__pyx_n_s__format, __pyx_k__format, sizeof(__pyx_k__format), 0, 0, 1, 1},
  {&__pyx_n_s__g, __pyx_k__g, sizeof(__pyx_k__g), 0, 0, 1, 1},
  {&__pyx_n_s__g2clib, __pyx_k__g2clib, sizeof(__pyx_k__g2clib), 0, 0, 1, 1},
  {&__pyx_n_s__gds, __pyx_k__gds, sizeof(__pyx_k__gds), 0, 0, 1, 1},
  {&__pyx_n_s__gdsdat, __pyx_k__gdsdat, sizeof(__pyx_k__gdsdat), 0, 0, 1, 1},
  {&__pyx_n_s__gdstmpl, __pyx_k__gdstmpl, sizeof(__pyx_k__gdstmpl), 0, 0, 1, 1},
  {&__pyx_n_s__gdstmpldat, __pyx_k__gdstmpldat, sizeof(__pyx_k__gdstmpldat), 0, 0, 1, 1},
  {&__pyx_n_s__gdtmpl, __pyx_k__gdtmpl, sizeof(__pyx_k__gdtmpl), 0, 0, 1, 1},
  {&__pyx_n_s__gdtmpldat, __pyx_k__gdtmpldat, sizeof(__pyx_k__gdtmpldat), 0, 0, 1, 1},
  {&__pyx_n_s__gdtnum, __pyx_k__gdtnum, sizeof(__pyx_k__gdtnum), 0, 0, 1, 1},
  {&__pyx_n_s__grib2_addfield, __pyx_k__grib2_addfield, sizeof(__pyx_k__grib2_addfield), 0, 0, 1, 1},
  {&__pyx_n_s__grib2_addgrid, __pyx_k__grib2_addgrid, sizeof(__pyx_k__grib2_addgrid), 0, 0, 1, 1},
  {&__pyx_n_s__grib2_create, __pyx_k__grib2_create, sizeof(__pyx_k__grib2_create), 0, 0, 1, 1},
  {&__pyx_n_s__grib2_end, __pyx_k__grib2_end, sizeof(__pyx_k__grib2_end), 0, 0, 1, 1},
  {&__pyx_n_s__gribmsg, __pyx_k__gribmsg, sizeof(__pyx_k__gribmsg), 0, 0, 1, 1},
  {&__pyx_n_s__i, __pyx_k__i, sizeof(__pyx_k__i), 0, 0, 1, 1},
  {&__pyx_n_s__i1, __pyx_k__i1, sizeof(__pyx_k__i1), 0, 0, 1, 1},
  {&__pyx_n_s__i4, __pyx_k__i4, sizeof(__pyx_k__i4), 0, 0, 1, 1},
  {&__pyx_n_s__iarr, __pyx_k__iarr, sizeof(__pyx_k__iarr), 0, 0, 1, 1},
  {&__pyx_n_s__ibitmap, __pyx_k__ibitmap, sizeof(__pyx_k__ibitmap), 0, 0, 1, 1},
  {&__pyx_n_s__ibmap, __pyx_k__ibmap, sizeof(__pyx_k__ibmap), 0, 0, 1, 1},
  {&__pyx_n_s__icoordlist, __pyx_k__icoordlist, sizeof(__pyx_k__icoordlist), 0, 0, 1, 1},
  {&__pyx_n_s__idat, __pyx_k__idat, sizeof(__pyx_k__idat), 0, 0, 1, 1},
  {&__pyx_n_s__idata, __pyx_k__idata, sizeof(__pyx_k__idata), 0, 0, 1, 1},
  {&__pyx_n_s__ideflist, __pyx_k__ideflist, sizeof(__pyx_k__ideflist), 0, 0, 1, 1},
  {&__pyx_n_s__idefnum, __pyx_k__idefnum, sizeof(__pyx_k__idefnum), 0, 0, 1, 1},
  {&__pyx_n_s__idrsnum, __pyx_k__idrsnum, sizeof(__pyx_k__idrsnum), 0, 0, 1, 1},
  {&__pyx_n_s__idrstmpl, __pyx_k__idrstmpl, sizeof(__pyx_k__idrstmpl), 0, 0, 1, 1},
  {&__pyx_n_s__ids, __pyx_k__ids, sizeof(__pyx_k__ids), 0, 0, 1, 1},
  {&__pyx_n_s__idsect, __pyx_k__idsect, sizeof(__pyx_k__idsect), 0, 0, 1, 1},
  {&__pyx_n_s__idslen, __pyx_k__idslen, sizeof(__pyx_k__idslen), 0, 0, 1, 1},
  {&__pyx_n_s__ierr, __pyx_k__ierr, sizeof(__pyx_k__ierr), 0, 0, 1, 1},
  {&__pyx_n_s__igds, __pyx_k__igds, sizeof(__pyx_k__igds), 0, 0, 1, 1},
  {&__pyx_n_s__igdsnum, __pyx_k__igdsnum, sizeof(__pyx_k__igdsnum), 0, 0, 1, 1},
  {&__pyx_n_s__igdstmpl, __pyx_k__igdstmpl, sizeof(__pyx_k__igdstmpl), 0, 0, 1, 1},
  {&__pyx_n_s__int32, __pyx_k__int32, sizeof(__pyx_k__int32), 0, 0, 1, 1},
  {&__pyx_n_s__iofst, __pyx_k__iofst, sizeof(__pyx_k__iofst), 0, 0, 1, 1},
  {&__pyx_n_s__ipdsnum, __pyx_k__ipdsnum, sizeof(__pyx_k__ipdsnum), 0, 0, 1, 1},
  {&__pyx_n_s__ipdstmpl, __pyx_k__ipdstmpl, sizeof(__pyx_k__ipdstmpl), 0, 0, 1, 1},
  {&__pyx_n_s__ipos, __pyx_k__ipos, sizeof(__pyx_k__ipos), 0, 0, 1, 1},
  {&__pyx_n_s__isec0, __pyx_k__isec0, sizeof(__pyx_k__isec0), 0, 0, 1, 1},
  {&__pyx_n_s__isec1, __pyx_k__isec1, sizeof(__pyx_k__isec1), 0, 0, 1, 1},
  {&__pyx_n_s__itor_ieee, __pyx_k__itor_ieee, sizeof(__pyx_k__itor_ieee), 0, 0, 1, 1},
  {&__pyx_n_s__lgrib, __pyx_k__lgrib, sizeof(__pyx_k__lgrib), 0, 0, 1, 1},
  {&__pyx_n_s__listsec0, __pyx_k__listsec0, sizeof(__pyx_k__listsec0), 0, 0, 1, 1},
  {&__pyx_n_s__listsec0dat, __pyx_k__listsec0dat, sizeof(__pyx_k__listsec0dat), 0, 0, 1, 1},
  {&__pyx_n_s__listsec1, __pyx_k__listsec1, sizeof(__pyx_k__listsec1), 0, 0, 1, 1},
  {&__pyx_n_s__listsec1dat, __pyx_k__listsec1dat, sizeof(__pyx_k__listsec1dat), 0, 0, 1, 1},
  {&__pyx_n_s__log10, __pyx_k__log10, sizeof(__pyx_k__log10), 0, 0, 1, 1},
  {&__pyx_n_s__mapdrslen, __pyx_k__mapdrslen, sizeof(__pyx_k__mapdrslen), 0, 0, 1, 1},
  {&__pyx_n_s__mapgridlen, __pyx_k__mapgridlen, sizeof(__pyx_k__mapgridlen), 0, 0, 1, 1},
  {&__pyx_n_s__mappdslen, __pyx_k__mappdslen, sizeof(__pyx_k__mappdslen), 0, 0, 1, 1},
  {&__pyx_n_s__math, __pyx_k__math, sizeof(__pyx_k__math), 0, 0, 1, 1},
  {&__pyx_n_s__minmaxstring, __pyx_k__minmaxstring, sizeof(__pyx_k__minmaxstring), 0, 0, 1, 1},
  {&__pyx_n_s__msg, __pyx_k__msg, sizeof(__pyx_k__msg), 0, 0, 1, 1},
  {&__pyx_n_s__n, __pyx_k__n, sizeof(__pyx_k__n), 0, 0, 1, 1},
  {&__pyx_n_s__ndpts, __pyx_k__ndpts, sizeof(__pyx_k__ndpts), 0, 0, 1, 1},
  {&__pyx_n_s__ngpts, __pyx_k__ngpts, sizeof(__pyx_k__ngpts), 0, 0, 1, 1},
  {&__pyx_n_s__ngrdpts, __pyx_k__ngrdpts, sizeof(__pyx_k__ngrdpts), 0, 0, 1, 1},
  {&__pyx_n_s__numcoord, __pyx_k__numcoord, sizeof(__pyx_k__numcoord), 0, 0, 1, 1},
  {&__pyx_n_s__order, __pyx_k__order, sizeof(__pyx_k__order), 0, 0, 1, 1},
  {&__pyx_n_s__pdsnum, __pyx_k__pdsnum, sizeof(__pyx_k__pdsnum), 0, 0, 1, 1},
  {&__pyx_n_s__pdstmpl, __pyx_k__pdstmpl, sizeof(__pyx_k__pdstmpl), 0, 0, 1, 1},
  {&__pyx_n_s__pdtmpl, __pyx_k__pdtmpl, sizeof(__pyx_k__pdtmpl), 0, 0, 1, 1},
  {&__pyx_n_s__pdtmpldat, __pyx_k__pdtmpldat, sizeof(__pyx_k__pdtmpldat), 0, 0, 1, 1},
  {&__pyx_n_s__pow, __pyx_k__pow, sizeof(__pyx_k__pow), 0, 0, 1, 1},
  {&__pyx_n_s__printminmax, __pyx_k__printminmax, sizeof(__pyx_k__printminmax), 0, 0, 1, 1},
  {&__pyx_n_s__r1, __pyx_k__r1, sizeof(__pyx_k__r1), 0, 0, 1, 1},
  {&__pyx_n_s__rarr, __pyx_k__rarr, sizeof(__pyx_k__rarr), 0, 0, 1, 1},
  {&__pyx_n_s__rdat, __pyx_k__rdat, sizeof(__pyx_k__rdat), 0, 0, 1, 1},
  {&__pyx_n_s__rdata, __pyx_k__rdata, sizeof(__pyx_k__rdata), 0, 0, 1, 1},
  {&__pyx_n_s__rmax, __pyx_k__rmax, sizeof(__pyx_k__rmax), 0, 0, 1, 1},
  {&__pyx_n_s__rmin, __pyx_k__rmin, sizeof(__pyx_k__rmin), 0, 0, 1, 1},
  {&__pyx_n_s__rtoi_ieee, __pyx_k__rtoi_ieee, sizeof(__pyx_k__rtoi_ieee), 0, 0, 1, 1},
  {&__pyx_n_s__storageorder, __pyx_k__storageorder, sizeof(__pyx_k__storageorder), 0, 0, 1, 1},
  {&__pyx_n_s__unpack1, __pyx_k__unpack1, sizeof(__pyx_k__unpack1), 0, 0, 1, 1},
  {&__pyx_n_s__unpack3, __pyx_k__unpack3, sizeof(__pyx_k__unpack3), 0, 0, 1, 1},
  {&__pyx_n_s__unpack4, __pyx_k__unpack4, sizeof(__pyx_k__unpack4), 0, 0, 1, 1},
  {&__pyx_n_s__unpack5, __pyx_k__unpack5, sizeof(__pyx_k__unpack5), 0, 0, 1, 1},
  {&__pyx_n_s__unpack6, __pyx_k__unpack6, sizeof(__pyx_k__unpack6), 0, 0, 1, 1},
  {&__pyx_n_s__unpack7, __pyx_k__unpack7, sizeof(__pyx_k__unpack7), 0, 0, 1, 1},
  {&__pyx_n_s__zeros, __pyx_k__zeros, sizeof(__pyx_k__zeros), 0, 0, 1, 1},
  {0, 0, 0, 0, 0, 0, 0}
};
static int __Pyx_InitCachedBuiltins(void) {
  __pyx_builtin_RuntimeError = __Pyx_GetName(__pyx_b, __pyx_n_s__RuntimeError); if (!__pyx_builtin_RuntimeError) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 64; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  return 0;
  __pyx_L1_error:;
  return -1;
}

static int __Pyx_InitCachedConstants(void) {
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__Pyx_InitCachedConstants", 0);

  /* "g2clib.pyx":232
 * 
 *     gdtmpl = _toarray(igdstmpl, zeros(mapgridlen, 'i4'))
 *     gds = _toarray(igds, zeros(5, 'i4'))             # <<<<<<<<<<<<<<
 *     deflist = _toarray(ideflist, zeros(idefnum, 'i4'))
 * 
 */
  __pyx_k_tuple_10 = PyTuple_New(2); if (unlikely(!__pyx_k_tuple_10)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 232; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_k_tuple_10);
  __Pyx_INCREF(__pyx_int_5);
  PyTuple_SET_ITEM(__pyx_k_tuple_10, 0, __pyx_int_5);
  __Pyx_GIVEREF(__pyx_int_5);
  __Pyx_INCREF(((PyObject *)__pyx_n_s__i4));
  PyTuple_SET_ITEM(__pyx_k_tuple_10, 1, ((PyObject *)__pyx_n_s__i4));
  __Pyx_GIVEREF(((PyObject *)__pyx_n_s__i4));
  __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_10));

  /* "g2clib.pyx":55
 * # routines for convert to/from IEEE integers.
 * 
 * def rtoi_ieee(object rarr, object iarr):             # <<<<<<<<<<<<<<
 *     """
 *  Converts a float32 array into an int32 array of IEEE formatted values
 */
  __pyx_k_tuple_26 = PyTuple_New(10); if (unlikely(!__pyx_k_tuple_26)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 55; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_k_tuple_26);
  __Pyx_INCREF(((PyObject *)__pyx_n_s__rarr));
  PyTuple_SET_ITEM(__pyx_k_tuple_26, 0, ((PyObject *)__pyx_n_s__rarr));
  __Pyx_GIVEREF(((PyObject *)__pyx_n_s__rarr));
  __Pyx_INCREF(((PyObject *)__pyx_n_s__iarr));
  PyTuple_SET_ITEM(__pyx_k_tuple_26, 1, ((PyObject *)__pyx_n_s__iarr));
  __Pyx_GIVEREF(((PyObject *)__pyx_n_s__iarr));
  __Pyx_INCREF(((PyObject *)__pyx_n_s__rdat));
  PyTuple_SET_ITEM(__pyx_k_tuple_26, 2, ((PyObject *)__pyx_n_s__rdat));
  __Pyx_GIVEREF(((PyObject *)__pyx_n_s__rdat));
  __Pyx_INCREF(((PyObject *)__pyx_n_s__idat));
  PyTuple_SET_ITEM(__pyx_k_tuple_26, 3, ((PyObject *)__pyx_n_s__idat));
  __Pyx_GIVEREF(((PyObject *)__pyx_n_s__idat));
  __Pyx_INCREF(((PyObject *)__pyx_n_s__rdata));
  PyTuple_SET_ITEM(__pyx_k_tuple_26, 4, ((PyObject *)__pyx_n_s__rdata));
  __Pyx_GIVEREF(((PyObject *)__pyx_n_s__rdata));
  __Pyx_INCREF(((PyObject *)__pyx_n_s__r1));
  PyTuple_SET_ITEM(__pyx_k_tuple_26, 5, ((PyObject *)__pyx_n_s__r1));
  __Pyx_GIVEREF(((PyObject *)__pyx_n_s__r1));
  __Pyx_INCREF(((PyObject *)__pyx_n_s__idata));
  PyTuple_SET_ITEM(__pyx_k_tuple_26, 6, ((PyObject *)__pyx_n_s__idata));
  __Pyx_GIVEREF(((PyObject *)__pyx_n_s__idata));
  __Pyx_INCREF(((PyObject *)__pyx_n_s__i1));
  PyTuple_SET_ITEM(__pyx_k_tuple_26, 7, ((PyObject *)__pyx_n_s__i1));
  __Pyx_GIVEREF(((PyObject *)__pyx_n_s__i1));
  __Pyx_INCREF(((PyObject *)__pyx_n_s__bufleni));
  PyTuple_SET_ITEM(__pyx_k_tuple_26, 8, ((PyObject *)__pyx_n_s__bufleni));
  __Pyx_GIVEREF(((PyObject *)__pyx_n_s__bufleni));
  __Pyx_INCREF(((PyObject *)__pyx_n_s__buflenr));
  PyTuple_SET_ITEM(__pyx_k_tuple_26, 9, ((PyObject *)__pyx_n_s__buflenr));
  __Pyx_GIVEREF(((PyObject *)__pyx_n_s__buflenr));
  __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_26));
  __pyx_k_codeobj_27 = (PyObject*)__Pyx_PyCode_New(2, 0, 10, 0, 0, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_k_tuple_26, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_28, __pyx_n_s__rtoi_ieee, 55, __pyx_empty_bytes); if (unlikely(!__pyx_k_codeobj_27)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 55; __pyx_clineno = __LINE__; goto __pyx_L1_error;}

  /* "g2clib.pyx":73
 *     mkieee(rdata, idata, buflenr/4)
 * 
 * def itor_ieee(object iarr, object rarr):             # <<<<<<<<<<<<<<
 *     """
 *  Converts an int32 array of IEEE values into a float32 array.
 */
  __pyx_k_tuple_29 = PyTuple_New(8); if (unlikely(!__pyx_k_tuple_29)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 73; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_k_tuple_29);
  __Pyx_INCREF(((PyObject *)__pyx_n_s__iarr));
  PyTuple_SET_ITEM(__pyx_k_tuple_29, 0, ((PyObject *)__pyx_n_s__iarr));
  __Pyx_GIVEREF(((PyObject *)__pyx_n_s__iarr));
  __Pyx_INCREF(((PyObject *)__pyx_n_s__rarr));
  PyTuple_SET_ITEM(__pyx_k_tuple_29, 1, ((PyObject *)__pyx_n_s__rarr));
  __Pyx_GIVEREF(((PyObject *)__pyx_n_s__rarr));
  __Pyx_INCREF(((PyObject *)__pyx_n_s__rdat));
  PyTuple_SET_ITEM(__pyx_k_tuple_29, 2, ((PyObject *)__pyx_n_s__rdat));
  __Pyx_GIVEREF(((PyObject *)__pyx_n_s__rdat));
  __Pyx_INCREF(((PyObject *)__pyx_n_s__idat));
  PyTuple_SET_ITEM(__pyx_k_tuple_29, 3, ((PyObject *)__pyx_n_s__idat));
  __Pyx_GIVEREF(((PyObject *)__pyx_n_s__idat));
  __Pyx_INCREF(((PyObject *)__pyx_n_s__rdata));
  PyTuple_SET_ITEM(__pyx_k_tuple_29, 4, ((PyObject *)__pyx_n_s__rdata));
  __Pyx_GIVEREF(((PyObject *)__pyx_n_s__rdata));
  __Pyx_INCREF(((PyObject *)__pyx_n_s__idata));
  PyTuple_SET_ITEM(__pyx_k_tuple_29, 5, ((PyObject *)__pyx_n_s__idata));
  __Pyx_GIVEREF(((PyObject *)__pyx_n_s__idata));
  __Pyx_INCREF(((PyObject *)__pyx_n_s__bufleni));
  PyTuple_SET_ITEM(__pyx_k_tuple_29, 6, ((PyObject *)__pyx_n_s__bufleni));
  __Pyx_GIVEREF(((PyObject *)__pyx_n_s__bufleni));
  __Pyx_INCREF(((PyObject *)__pyx_n_s__buflenr));
  PyTuple_SET_ITEM(__pyx_k_tuple_29, 7, ((PyObject *)__pyx_n_s__buflenr));
  __Pyx_GIVEREF(((PyObject *)__pyx_n_s__buflenr));
  __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_29));
  __pyx_k_codeobj_30 = (PyObject*)__Pyx_PyCode_New(2, 0, 8, 0, 0, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_k_tuple_29, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_28, __pyx_n_s__itor_ieee, 73, __pyx_empty_bytes); if (unlikely(!__pyx_k_codeobj_30)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 73; __pyx_clineno = __LINE__; goto __pyx_L1_error;}

  /* "g2clib.pyx":123
 * # routines for reading grib2 files.
 * 
 * def unpack1(gribmsg, ipos, object zeros):             # <<<<<<<<<<<<<<
 *     """              .      .    .                                       .
 *  Unpacks Section 1 (Identification Section) as defined in GRIB Edition 2.
 */
  __pyx_k_tuple_31 = PyTuple_New(11); if (unlikely(!__pyx_k_tuple_31)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 123; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_k_tuple_31);
  __Pyx_INCREF(((PyObject *)__pyx_n_s__gribmsg));
  PyTuple_SET_ITEM(__pyx_k_tuple_31, 0, ((PyObject *)__pyx_n_s__gribmsg));
  __Pyx_GIVEREF(((PyObject *)__pyx_n_s__gribmsg));
  __Pyx_INCREF(((PyObject *)__pyx_n_s__ipos));
  PyTuple_SET_ITEM(__pyx_k_tuple_31, 1, ((PyObject *)__pyx_n_s__ipos));
  __Pyx_GIVEREF(((PyObject *)__pyx_n_s__ipos));
  __Pyx_INCREF(((PyObject *)__pyx_n_s__zeros));
  PyTuple_SET_ITEM(__pyx_k_tuple_31, 2, ((PyObject *)__pyx_n_s__zeros));
  __Pyx_GIVEREF(((PyObject *)__pyx_n_s__zeros));
  __Pyx_INCREF(((PyObject *)__pyx_n_s__cgrib));
  PyTuple_SET_ITEM(__pyx_k_tuple_31, 3, ((PyObject *)__pyx_n_s__cgrib));
  __Pyx_GIVEREF(((PyObject *)__pyx_n_s__cgrib));
  __Pyx_INCREF(((PyObject *)__pyx_n_s__i));
  PyTuple_SET_ITEM(__pyx_k_tuple_31, 4, ((PyObject *)__pyx_n_s__i));
  __Pyx_GIVEREF(((PyObject *)__pyx_n_s__i));
  __Pyx_INCREF(((PyObject *)__pyx_n_s__iofst));
  PyTuple_SET_ITEM(__pyx_k_tuple_31, 5, ((PyObject *)__pyx_n_s__iofst));
  __Pyx_GIVEREF(((PyObject *)__pyx_n_s__iofst));
  __Pyx_INCREF(((PyObject *)__pyx_n_s__ierr));
  PyTuple_SET_ITEM(__pyx_k_tuple_31, 6, ((PyObject *)__pyx_n_s__ierr));
  __Pyx_GIVEREF(((PyObject *)__pyx_n_s__ierr));
  __Pyx_INCREF(((PyObject *)__pyx_n_s__idslen));
  PyTuple_SET_ITEM(__pyx_k_tuple_31, 7, ((PyObject *)__pyx_n_s__idslen));
  __Pyx_GIVEREF(((PyObject *)__pyx_n_s__idslen));
  __Pyx_INCREF(((PyObject *)__pyx_n_s__ids));
  PyTuple_SET_ITEM(__pyx_k_tuple_31, 8, ((PyObject *)__pyx_n_s__ids));
  __Pyx_GIVEREF(((PyObject *)__pyx_n_s__ids));
  __Pyx_INCREF(((PyObject *)__pyx_n_s__msg));
  PyTuple_SET_ITEM(__pyx_k_tuple_31, 9, ((PyObject *)__pyx_n_s__msg));
  __Pyx_GIVEREF(((PyObject *)__pyx_n_s__msg));
  __Pyx_INCREF(((PyObject *)__pyx_n_s__idsect));
  PyTuple_SET_ITEM(__pyx_k_tuple_31, 10, ((PyObject *)__pyx_n_s__idsect));
  __Pyx_GIVEREF(((PyObject *)__pyx_n_s__idsect));
  __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_31));
  __pyx_k_codeobj_32 = (PyObject*)__Pyx_PyCode_New(3, 0, 11, 0, 0, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_k_tuple_31, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_28, __pyx_n_s__unpack1, 123, __pyx_empty_bytes); if (unlikely(!__pyx_k_codeobj_32)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 123; __pyx_clineno = __LINE__; goto __pyx_L1_error;}

  /* "g2clib.pyx":177
 * 
 * 
 * def unpack3(gribmsg, ipos, object zeros):             # <<<<<<<<<<<<<<
 *     """
 *  Unpacks Section 3 (Grid Definition Section) as defined in GRIB Edition 2.
 */
  __pyx_k_tuple_33 = PyTuple_New(15); if (unlikely(!__pyx_k_tuple_33)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 177; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_k_tuple_33);
  __Pyx_INCREF(((PyObject *)__pyx_n_s__gribmsg));
  PyTuple_SET_ITEM(__pyx_k_tuple_33, 0, ((PyObject *)__pyx_n_s__gribmsg));
  __Pyx_GIVEREF(((PyObject *)__pyx_n_s__gribmsg));
  __Pyx_INCREF(((PyObject *)__pyx_n_s__ipos));
  PyTuple_SET_ITEM(__pyx_k_tuple_33, 1, ((PyObject *)__pyx_n_s__ipos));
  __Pyx_GIVEREF(((PyObject *)__pyx_n_s__ipos));
  __Pyx_INCREF(((PyObject *)__pyx_n_s__zeros));
  PyTuple_SET_ITEM(__pyx_k_tuple_33, 2, ((PyObject *)__pyx_n_s__zeros));
  __Pyx_GIVEREF(((PyObject *)__pyx_n_s__zeros));
  __Pyx_INCREF(((PyObject *)__pyx_n_s__cgrib));
  PyTuple_SET_ITEM(__pyx_k_tuple_33, 3, ((PyObject *)__pyx_n_s__cgrib));
  __Pyx_GIVEREF(((PyObject *)__pyx_n_s__cgrib));
  __Pyx_INCREF(((PyObject *)__pyx_n_s__igds));
  PyTuple_SET_ITEM(__pyx_k_tuple_33, 4, ((PyObject *)__pyx_n_s__igds));
  __Pyx_GIVEREF(((PyObject *)__pyx_n_s__igds));
  __Pyx_INCREF(((PyObject *)__pyx_n_s__igdstmpl));
  PyTuple_SET_ITEM(__pyx_k_tuple_33, 5, ((PyObject *)__pyx_n_s__igdstmpl));
  __Pyx_GIVEREF(((PyObject *)__pyx_n_s__igdstmpl));
  __Pyx_INCREF(((PyObject *)__pyx_n_s__ideflist));
  PyTuple_SET_ITEM(__pyx_k_tuple_33, 6, ((PyObject *)__pyx_n_s__ideflist));
  __Pyx_GIVEREF(((PyObject *)__pyx_n_s__ideflist));
  __Pyx_INCREF(((PyObject *)__pyx_n_s__mapgridlen));
  PyTuple_SET_ITEM(__pyx_k_tuple_33, 7, ((PyObject *)__pyx_n_s__mapgridlen));
  __Pyx_GIVEREF(((PyObject *)__pyx_n_s__mapgridlen));
  __Pyx_INCREF(((PyObject *)__pyx_n_s__iofst));
  PyTuple_SET_ITEM(__pyx_k_tuple_33, 8, ((PyObject *)__pyx_n_s__iofst));
  __Pyx_GIVEREF(((PyObject *)__pyx_n_s__iofst));
  __Pyx_INCREF(((PyObject *)__pyx_n_s__idefnum));
  PyTuple_SET_ITEM(__pyx_k_tuple_33, 9, ((PyObject *)__pyx_n_s__idefnum));
  __Pyx_GIVEREF(((PyObject *)__pyx_n_s__idefnum));
  __Pyx_INCREF(((PyObject *)__pyx_n_s__ierr));
  PyTuple_SET_ITEM(__pyx_k_tuple_33, 10, ((PyObject *)__pyx_n_s__ierr));
  __Pyx_GIVEREF(((PyObject *)__pyx_n_s__ierr));
  __Pyx_INCREF(((PyObject *)__pyx_n_s__msg));
  PyTuple_SET_ITEM(__pyx_k_tuple_33, 11, ((PyObject *)__pyx_n_s__msg));
  __Pyx_GIVEREF(((PyObject *)__pyx_n_s__msg));
  __Pyx_INCREF(((PyObject *)__pyx_n_s__gdtmpl));
  PyTuple_SET_ITEM(__pyx_k_tuple_33, 12, ((PyObject *)__pyx_n_s__gdtmpl));
  __Pyx_GIVEREF(((PyObject *)__pyx_n_s__gdtmpl));
  __Pyx_INCREF(((PyObject *)__pyx_n_s__gds));
  PyTuple_SET_ITEM(__pyx_k_tuple_33, 13, ((PyObject *)__pyx_n_s__gds));
  __Pyx_GIVEREF(((PyObject *)__pyx_n_s__gds));
  __Pyx_INCREF(((PyObject *)__pyx_n_s__deflist));
  PyTuple_SET_ITEM(__pyx_k_tuple_33, 14, ((PyObject *)__pyx_n_s__deflist));
  __Pyx_GIVEREF(((PyObject *)__pyx_n_s__deflist));
  __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_33));
  __pyx_k_codeobj_34 = (PyObject*)__Pyx_PyCode_New(3, 0, 15, 0, 0, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_k_tuple_33, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_28, __pyx_n_s__unpack3, 177, __pyx_empty_bytes); if (unlikely(!__pyx_k_codeobj_34)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 177; __pyx_clineno = __LINE__; goto __pyx_L1_error;}

  /* "g2clib.pyx":237
 *     return gds,gdtmpl,deflist,iofst/8
 * 
 * def unpack4(gribmsg,ipos,object zeros):             # <<<<<<<<<<<<<<
 *     """
 *  Unpacks Section 4 (Product Definition Section) as defined in GRIB Edition 2.
 */
  __pyx_k_tuple_35 = PyTuple_New(14); if (unlikely(!__pyx_k_tuple_35)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 237; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_k_tuple_35);
  __Pyx_INCREF(((PyObject *)__pyx_n_s__gribmsg));
  PyTuple_SET_ITEM(__pyx_k_tuple_35, 0, ((PyObject *)__pyx_n_s__gribmsg));
  __Pyx_GIVEREF(((PyObject *)__pyx_n_s__gribmsg));
  __Pyx_INCREF(((PyObject *)__pyx_n_s__ipos));
  PyTuple_SET_ITEM(__pyx_k_tuple_35, 1, ((PyObject *)__pyx_n_s__ipos));
  __Pyx_GIVEREF(((PyObject *)__pyx_n_s__ipos));
  __Pyx_INCREF(((PyObject *)__pyx_n_s__zeros));
  PyTuple_SET_ITEM(__pyx_k_tuple_35, 2, ((PyObject *)__pyx_n_s__zeros));
  __Pyx_GIVEREF(((PyObject *)__pyx_n_s__zeros));
  __Pyx_INCREF(((PyObject *)__pyx_n_s__cgrib));
  PyTuple_SET_ITEM(__pyx_k_tuple_35, 3, ((PyObject *)__pyx_n_s__cgrib));
  __Pyx_GIVEREF(((PyObject *)__pyx_n_s__cgrib));
  __Pyx_INCREF(((PyObject *)__pyx_n_s__ipdstmpl));
  PyTuple_SET_ITEM(__pyx_k_tuple_35, 4, ((PyObject *)__pyx_n_s__ipdstmpl));
  __Pyx_GIVEREF(((PyObject *)__pyx_n_s__ipdstmpl));
  __Pyx_INCREF(((PyObject *)__pyx_n_s__icoordlist));
  PyTuple_SET_ITEM(__pyx_k_tuple_35, 5, ((PyObject *)__pyx_n_s__icoordlist));
  __Pyx_GIVEREF(((PyObject *)__pyx_n_s__icoordlist));
  __Pyx_INCREF(((PyObject *)__pyx_n_s__mappdslen));
  PyTuple_SET_ITEM(__pyx_k_tuple_35, 6, ((PyObject *)__pyx_n_s__mappdslen));
  __Pyx_GIVEREF(((PyObject *)__pyx_n_s__mappdslen));
  __Pyx_INCREF(((PyObject *)__pyx_n_s__iofst));
  PyTuple_SET_ITEM(__pyx_k_tuple_35, 7, ((PyObject *)__pyx_n_s__iofst));
  __Pyx_GIVEREF(((PyObject *)__pyx_n_s__iofst));
  __Pyx_INCREF(((PyObject *)__pyx_n_s__ipdsnum));
  PyTuple_SET_ITEM(__pyx_k_tuple_35, 8, ((PyObject *)__pyx_n_s__ipdsnum));
  __Pyx_GIVEREF(((PyObject *)__pyx_n_s__ipdsnum));
  __Pyx_INCREF(((PyObject *)__pyx_n_s__ierr));
  PyTuple_SET_ITEM(__pyx_k_tuple_35, 9, ((PyObject *)__pyx_n_s__ierr));
  __Pyx_GIVEREF(((PyObject *)__pyx_n_s__ierr));
  __Pyx_INCREF(((PyObject *)__pyx_n_s__numcoord));
  PyTuple_SET_ITEM(__pyx_k_tuple_35, 10, ((PyObject *)__pyx_n_s__numcoord));
  __Pyx_GIVEREF(((PyObject *)__pyx_n_s__numcoord));
  __Pyx_INCREF(((PyObject *)__pyx_n_s__msg));
  PyTuple_SET_ITEM(__pyx_k_tuple_35, 11, ((PyObject *)__pyx_n_s__msg));
  __Pyx_GIVEREF(((PyObject *)__pyx_n_s__msg));
  __Pyx_INCREF(((PyObject *)__pyx_n_s__pdtmpl));
  PyTuple_SET_ITEM(__pyx_k_tuple_35, 12, ((PyObject *)__pyx_n_s__pdtmpl));
  __Pyx_GIVEREF(((PyObject *)__pyx_n_s__pdtmpl));
  __Pyx_INCREF(((PyObject *)__pyx_n_s__coordlist));
  PyTuple_SET_ITEM(__pyx_k_tuple_35, 13, ((PyObject *)__pyx_n_s__coordlist));
  __Pyx_GIVEREF(((PyObject *)__pyx_n_s__coordlist));
  __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_35));
  __pyx_k_codeobj_36 = (PyObject*)__Pyx_PyCode_New(3, 0, 14, 0, 0, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_k_tuple_35, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_28, __pyx_n_s__unpack4, 237, __pyx_empty_bytes); if (unlikely(!__pyx_k_codeobj_36)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 237; __pyx_clineno = __LINE__; goto __pyx_L1_error;}

  /* "g2clib.pyx":287
 *     return pdtmpl,ipdsnum,coordlist,iofst/8
 * 
 * def unpack5(gribmsg,ipos,object zeros):             # <<<<<<<<<<<<<<
 *     """
 *  Unpacks Section 5 (Data Representation Section) as defined in GRIB Edition 2.
 */
  __pyx_k_tuple_37 = PyTuple_New(12); if (unlikely(!__pyx_k_tuple_37)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 287; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_k_tuple_37);
  __Pyx_INCREF(((PyObject *)__pyx_n_s__gribmsg));
  PyTuple_SET_ITEM(__pyx_k_tuple_37, 0, ((PyObject *)__pyx_n_s__gribmsg));
  __Pyx_GIVEREF(((PyObject *)__pyx_n_s__gribmsg));
  __Pyx_INCREF(((PyObject *)__pyx_n_s__ipos));
  PyTuple_SET_ITEM(__pyx_k_tuple_37, 1, ((PyObject *)__pyx_n_s__ipos));
  __Pyx_GIVEREF(((PyObject *)__pyx_n_s__ipos));
  __Pyx_INCREF(((PyObject *)__pyx_n_s__zeros));
  PyTuple_SET_ITEM(__pyx_k_tuple_37, 2, ((PyObject *)__pyx_n_s__zeros));
  __Pyx_GIVEREF(((PyObject *)__pyx_n_s__zeros));
  __Pyx_INCREF(((PyObject *)__pyx_n_s__cgrib));
  PyTuple_SET_ITEM(__pyx_k_tuple_37, 3, ((PyObject *)__pyx_n_s__cgrib));
  __Pyx_GIVEREF(((PyObject *)__pyx_n_s__cgrib));
  __Pyx_INCREF(((PyObject *)__pyx_n_s__idrstmpl));
  PyTuple_SET_ITEM(__pyx_k_tuple_37, 4, ((PyObject *)__pyx_n_s__idrstmpl));
  __Pyx_GIVEREF(((PyObject *)__pyx_n_s__idrstmpl));
  __Pyx_INCREF(((PyObject *)__pyx_n_s__iofst));
  PyTuple_SET_ITEM(__pyx_k_tuple_37, 5, ((PyObject *)__pyx_n_s__iofst));
  __Pyx_GIVEREF(((PyObject *)__pyx_n_s__iofst));
  __Pyx_INCREF(((PyObject *)__pyx_n_s__ierr));
  PyTuple_SET_ITEM(__pyx_k_tuple_37, 6, ((PyObject *)__pyx_n_s__ierr));
  __Pyx_GIVEREF(((PyObject *)__pyx_n_s__ierr));
  __Pyx_INCREF(((PyObject *)__pyx_n_s__ndpts));
  PyTuple_SET_ITEM(__pyx_k_tuple_37, 7, ((PyObject *)__pyx_n_s__ndpts));
  __Pyx_GIVEREF(((PyObject *)__pyx_n_s__ndpts));
  __Pyx_INCREF(((PyObject *)__pyx_n_s__idrsnum));
  PyTuple_SET_ITEM(__pyx_k_tuple_37, 8, ((PyObject *)__pyx_n_s__idrsnum));
  __Pyx_GIVEREF(((PyObject *)__pyx_n_s__idrsnum));
  __Pyx_INCREF(((PyObject *)__pyx_n_s__mapdrslen));
  PyTuple_SET_ITEM(__pyx_k_tuple_37, 9, ((PyObject *)__pyx_n_s__mapdrslen));
  __Pyx_GIVEREF(((PyObject *)__pyx_n_s__mapdrslen));
  __Pyx_INCREF(((PyObject *)__pyx_n_s__msg));
  PyTuple_SET_ITEM(__pyx_k_tuple_37, 10, ((PyObject *)__pyx_n_s__msg));
  __Pyx_GIVEREF(((PyObject *)__pyx_n_s__msg));
  __Pyx_INCREF(((PyObject *)__pyx_n_s__drtmpl));
  PyTuple_SET_ITEM(__pyx_k_tuple_37, 11, ((PyObject *)__pyx_n_s__drtmpl));
  __Pyx_GIVEREF(((PyObject *)__pyx_n_s__drtmpl));
  __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_37));
  __pyx_k_codeobj_38 = (PyObject*)__Pyx_PyCode_New(3, 0, 12, 0, 0, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_k_tuple_37, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_28, __pyx_n_s__unpack5, 287, __pyx_empty_bytes); if (unlikely(!__pyx_k_codeobj_38)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 287; __pyx_clineno = __LINE__; goto __pyx_L1_error;}

  /* "g2clib.pyx":331
 *     return drtmpl,idrsnum,ndpts,iofst/8
 * 
 * def unpack6(gribmsg,ndpts,ipos,object zeros):             # <<<<<<<<<<<<<<
 *     """
 *  Unpacks Section 6 (Bit-Map Section) as defined in GRIB Edition 2.
 */
  __pyx_k_tuple_39 = PyTuple_New(12); if (unlikely(!__pyx_k_tuple_39)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 331; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_k_tuple_39);
  __Pyx_INCREF(((PyObject *)__pyx_n_s__gribmsg));
  PyTuple_SET_ITEM(__pyx_k_tuple_39, 0, ((PyObject *)__pyx_n_s__gribmsg));
  __Pyx_GIVEREF(((PyObject *)__pyx_n_s__gribmsg));
  __Pyx_INCREF(((PyObject *)__pyx_n_s__ndpts));
  PyTuple_SET_ITEM(__pyx_k_tuple_39, 1, ((PyObject *)__pyx_n_s__ndpts));
  __Pyx_GIVEREF(((PyObject *)__pyx_n_s__ndpts));
  __Pyx_INCREF(((PyObject *)__pyx_n_s__ipos));
  PyTuple_SET_ITEM(__pyx_k_tuple_39, 2, ((PyObject *)__pyx_n_s__ipos));
  __Pyx_GIVEREF(((PyObject *)__pyx_n_s__ipos));
  __Pyx_INCREF(((PyObject *)__pyx_n_s__zeros));
  PyTuple_SET_ITEM(__pyx_k_tuple_39, 3, ((PyObject *)__pyx_n_s__zeros));
  __Pyx_GIVEREF(((PyObject *)__pyx_n_s__zeros));
  __Pyx_INCREF(((PyObject *)__pyx_n_s__bitmap));
  PyTuple_SET_ITEM(__pyx_k_tuple_39, 4, ((PyObject *)__pyx_n_s__bitmap));
  __Pyx_GIVEREF(((PyObject *)__pyx_n_s__bitmap));
  __Pyx_INCREF(((PyObject *)__pyx_n_s__cgrib));
  PyTuple_SET_ITEM(__pyx_k_tuple_39, 5, ((PyObject *)__pyx_n_s__cgrib));
  __Pyx_GIVEREF(((PyObject *)__pyx_n_s__cgrib));
  __Pyx_INCREF(((PyObject *)__pyx_n_s__iofst));
  PyTuple_SET_ITEM(__pyx_k_tuple_39, 6, ((PyObject *)__pyx_n_s__iofst));
  __Pyx_GIVEREF(((PyObject *)__pyx_n_s__iofst));
  __Pyx_INCREF(((PyObject *)__pyx_n_s__ierr));
  PyTuple_SET_ITEM(__pyx_k_tuple_39, 7, ((PyObject *)__pyx_n_s__ierr));
  __Pyx_GIVEREF(((PyObject *)__pyx_n_s__ierr));
  __Pyx_INCREF(((PyObject *)__pyx_n_s__ngpts));
  PyTuple_SET_ITEM(__pyx_k_tuple_39, 8, ((PyObject *)__pyx_n_s__ngpts));
  __Pyx_GIVEREF(((PyObject *)__pyx_n_s__ngpts));
  __Pyx_INCREF(((PyObject *)__pyx_n_s__ibmap));
  PyTuple_SET_ITEM(__pyx_k_tuple_39, 9, ((PyObject *)__pyx_n_s__ibmap));
  __Pyx_GIVEREF(((PyObject *)__pyx_n_s__ibmap));
  __Pyx_INCREF(((PyObject *)__pyx_n_s__bmap));
  PyTuple_SET_ITEM(__pyx_k_tuple_39, 10, ((PyObject *)__pyx_n_s__bmap));
  __Pyx_GIVEREF(((PyObject *)__pyx_n_s__bmap));
  __Pyx_INCREF(((PyObject *)__pyx_n_s__msg));
  PyTuple_SET_ITEM(__pyx_k_tuple_39, 11, ((PyObject *)__pyx_n_s__msg));
  __Pyx_GIVEREF(((PyObject *)__pyx_n_s__msg));
  __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_39));
  __pyx_k_codeobj_40 = (PyObject*)__Pyx_PyCode_New(4, 0, 12, 0, 0, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_k_tuple_39, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_28, __pyx_n_s__unpack6, 331, __pyx_empty_bytes); if (unlikely(!__pyx_k_codeobj_40)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 331; __pyx_clineno = __LINE__; goto __pyx_L1_error;}

  /* "g2clib.pyx":377
 *     return bitmap,ibmap
 * 
 * def unpack7(gribmsg,gdtnum,object gdtmpl,drtnum,object drtmpl,ndpts,ipos,object zeros,printminmax=False,storageorder='C'):             # <<<<<<<<<<<<<<
 *     """
 *  Unpacks Section 7 (Data Section) as defined in GRIB Edition 2.
 */
  __pyx_k_tuple_41 = PyTuple_New(33); if (unlikely(!__pyx_k_tuple_41)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 377; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_k_tuple_41);
  __Pyx_INCREF(((PyObject *)__pyx_n_s__gribmsg));
  PyTuple_SET_ITEM(__pyx_k_tuple_41, 0, ((PyObject *)__pyx_n_s__gribmsg));
  __Pyx_GIVEREF(((PyObject *)__pyx_n_s__gribmsg));
  __Pyx_INCREF(((PyObject *)__pyx_n_s__gdtnum));
  PyTuple_SET_ITEM(__pyx_k_tuple_41, 1, ((PyObject *)__pyx_n_s__gdtnum));
  __Pyx_GIVEREF(((PyObject *)__pyx_n_s__gdtnum));
  __Pyx_INCREF(((PyObject *)__pyx_n_s__gdtmpl));
  PyTuple_SET_ITEM(__pyx_k_tuple_41, 2, ((PyObject *)__pyx_n_s__gdtmpl));
  __Pyx_GIVEREF(((PyObject *)__pyx_n_s__gdtmpl));
  __Pyx_INCREF(((PyObject *)__pyx_n_s__drtnum));
  PyTuple_SET_ITEM(__pyx_k_tuple_41, 3, ((PyObject *)__pyx_n_s__drtnum));
  __Pyx_GIVEREF(((PyObject *)__pyx_n_s__drtnum));
  __Pyx_INCREF(((PyObject *)__pyx_n_s__drtmpl));
  PyTuple_SET_ITEM(__pyx_k_tuple_41, 4, ((PyObject *)__pyx_n_s__drtmpl));
  __Pyx_GIVEREF(((PyObject *)__pyx_n_s__drtmpl));
  __Pyx_INCREF(((PyObject *)__pyx_n_s__ndpts));
  PyTuple_SET_ITEM(__pyx_k_tuple_41, 5, ((PyObject *)__pyx_n_s__ndpts));
  __Pyx_GIVEREF(((PyObject *)__pyx_n_s__ndpts));
  __Pyx_INCREF(((PyObject *)__pyx_n_s__ipos));
  PyTuple_SET_ITEM(__pyx_k_tuple_41, 6, ((PyObject *)__pyx_n_s__ipos));
  __Pyx_GIVEREF(((PyObject *)__pyx_n_s__ipos));
  __Pyx_INCREF(((PyObject *)__pyx_n_s__zeros));
  PyTuple_SET_ITEM(__pyx_k_tuple_41, 7, ((PyObject *)__pyx_n_s__zeros));
  __Pyx_GIVEREF(((PyObject *)__pyx_n_s__zeros));
  __Pyx_INCREF(((PyObject *)__pyx_n_s__printminmax));
  PyTuple_SET_ITEM(__pyx_k_tuple_41, 8, ((PyObject *)__pyx_n_s__printminmax));
  __Pyx_GIVEREF(((PyObject *)__pyx_n_s__printminmax));
  __Pyx_INCREF(((PyObject *)__pyx_n_s__storageorder));
  PyTuple_SET_ITEM(__pyx_k_tuple_41, 9, ((PyObject *)__pyx_n_s__storageorder));
  __Pyx_GIVEREF(((PyObject *)__pyx_n_s__storageorder));
  __Pyx_INCREF(((PyObject *)__pyx_n_s__cgrib));
  PyTuple_SET_ITEM(__pyx_k_tuple_41, 10, ((PyObject *)__pyx_n_s__cgrib));
  __Pyx_GIVEREF(((PyObject *)__pyx_n_s__cgrib));
  __Pyx_INCREF(((PyObject *)__pyx_n_s__iofst));
  PyTuple_SET_ITEM(__pyx_k_tuple_41, 11, ((PyObject *)__pyx_n_s__iofst));
  __Pyx_GIVEREF(((PyObject *)__pyx_n_s__iofst));
  __Pyx_INCREF(((PyObject *)__pyx_n_s__ierr));
  PyTuple_SET_ITEM(__pyx_k_tuple_41, 12, ((PyObject *)__pyx_n_s__ierr));
  __Pyx_GIVEREF(((PyObject *)__pyx_n_s__ierr));
  __Pyx_INCREF(((PyObject *)__pyx_n_s__ngpts));
  PyTuple_SET_ITEM(__pyx_k_tuple_41, 13, ((PyObject *)__pyx_n_s__ngpts));
  __Pyx_GIVEREF(((PyObject *)__pyx_n_s__ngpts));
  __Pyx_INCREF(((PyObject *)__pyx_n_s__idrsnum));
  PyTuple_SET_ITEM(__pyx_k_tuple_41, 14, ((PyObject *)__pyx_n_s__idrsnum));
  __Pyx_GIVEREF(((PyObject *)__pyx_n_s__idrsnum));
  __Pyx_INCREF(((PyObject *)__pyx_n_s__igdsnum));
  PyTuple_SET_ITEM(__pyx_k_tuple_41, 15, ((PyObject *)__pyx_n_s__igdsnum));
  __Pyx_GIVEREF(((PyObject *)__pyx_n_s__igdsnum));
  __Pyx_INCREF(((PyObject *)__pyx_n_s__igdstmpl));
  PyTuple_SET_ITEM(__pyx_k_tuple_41, 16, ((PyObject *)__pyx_n_s__igdstmpl));
  __Pyx_GIVEREF(((PyObject *)__pyx_n_s__igdstmpl));
  __Pyx_INCREF(((PyObject *)__pyx_n_s__idrstmpl));
  PyTuple_SET_ITEM(__pyx_k_tuple_41, 17, ((PyObject *)__pyx_n_s__idrstmpl));
  __Pyx_GIVEREF(((PyObject *)__pyx_n_s__idrstmpl));
  __Pyx_INCREF(((PyObject *)__pyx_n_s__fld));
  PyTuple_SET_ITEM(__pyx_k_tuple_41, 18, ((PyObject *)__pyx_n_s__fld));
  __Pyx_GIVEREF(((PyObject *)__pyx_n_s__fld));
  __Pyx_INCREF(((PyObject *)__pyx_n_s__drtmpldat));
  PyTuple_SET_ITEM(__pyx_k_tuple_41, 19, ((PyObject *)__pyx_n_s__drtmpldat));
  __Pyx_GIVEREF(((PyObject *)__pyx_n_s__drtmpldat));
  __Pyx_INCREF(((PyObject *)__pyx_n_s__gdtmpldat));
  PyTuple_SET_ITEM(__pyx_k_tuple_41, 20, ((PyObject *)__pyx_n_s__gdtmpldat));
  __Pyx_GIVEREF(((PyObject *)__pyx_n_s__gdtmpldat));
  __Pyx_INCREF(((PyObject *)__pyx_n_s__rmin));
  PyTuple_SET_ITEM(__pyx_k_tuple_41, 21, ((PyObject *)__pyx_n_s__rmin));
  __Pyx_GIVEREF(((PyObject *)__pyx_n_s__rmin));
  __Pyx_INCREF(((PyObject *)__pyx_n_s__rmax));
  PyTuple_SET_ITEM(__pyx_k_tuple_41, 22, ((PyObject *)__pyx_n_s__rmax));
  __Pyx_GIVEREF(((PyObject *)__pyx_n_s__rmax));
  __Pyx_INCREF(((PyObject *)__pyx_n_s__n));
  PyTuple_SET_ITEM(__pyx_k_tuple_41, 23, ((PyObject *)__pyx_n_s__n));
  __Pyx_GIVEREF(((PyObject *)__pyx_n_s__n));
  __Pyx_INCREF(((PyObject *)__pyx_n_s__buflen));
  PyTuple_SET_ITEM(__pyx_k_tuple_41, 24, ((PyObject *)__pyx_n_s__buflen));
  __Pyx_GIVEREF(((PyObject *)__pyx_n_s__buflen));
  __Pyx_INCREF(((PyObject *)__pyx_n_s__msg));
  PyTuple_SET_ITEM(__pyx_k_tuple_41, 25, ((PyObject *)__pyx_n_s__msg));
  __Pyx_GIVEREF(((PyObject *)__pyx_n_s__msg));
  __Pyx_INCREF(((PyObject *)__pyx_n_s__fldmax));
  PyTuple_SET_ITEM(__pyx_k_tuple_41, 26, ((PyObject *)__pyx_n_s__fldmax));
  __Pyx_GIVEREF(((PyObject *)__pyx_n_s__fldmax));
  __Pyx_INCREF(((PyObject *)__pyx_n_s__fldmin));
  PyTuple_SET_ITEM(__pyx_k_tuple_41, 27, ((PyObject *)__pyx_n_s__fldmin));
  __Pyx_GIVEREF(((PyObject *)__pyx_n_s__fldmin));
  __Pyx_INCREF(((PyObject *)__pyx_n_s__bitsofprecision));
  PyTuple_SET_ITEM(__pyx_k_tuple_41, 28, ((PyObject *)__pyx_n_s__bitsofprecision));
  __Pyx_GIVEREF(((PyObject *)__pyx_n_s__bitsofprecision));
  __Pyx_INCREF(((PyObject *)__pyx_n_s__digitsofprecision));
  PyTuple_SET_ITEM(__pyx_k_tuple_41, 29, ((PyObject *)__pyx_n_s__digitsofprecision));
  __Pyx_GIVEREF(((PyObject *)__pyx_n_s__digitsofprecision));
  __Pyx_INCREF(((PyObject *)__pyx_n_s__format));
  PyTuple_SET_ITEM(__pyx_k_tuple_41, 30, ((PyObject *)__pyx_n_s__format));
  __Pyx_GIVEREF(((PyObject *)__pyx_n_s__format));
  __Pyx_INCREF(((PyObject *)__pyx_n_s__minmaxstring));
  PyTuple_SET_ITEM(__pyx_k_tuple_41, 31, ((PyObject *)__pyx_n_s__minmaxstring));
  __Pyx_GIVEREF(((PyObject *)__pyx_n_s__minmaxstring));
  __Pyx_INCREF(((PyObject *)__pyx_n_s__data));
  PyTuple_SET_ITEM(__pyx_k_tuple_41, 32, ((PyObject *)__pyx_n_s__data));
  __Pyx_GIVEREF(((PyObject *)__pyx_n_s__data));
  __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_41));
  __pyx_k_codeobj_42 = (PyObject*)__Pyx_PyCode_New(10, 0, 33, 0, 0, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_k_tuple_41, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_28, __pyx_n_s__unpack7, 377, __pyx_empty_bytes); if (unlikely(!__pyx_k_codeobj_42)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 377; __pyx_clineno = __LINE__; goto __pyx_L1_error;}

  /* "g2clib.pyx":460
 * # routines for writing grib2 files.
 * 
 * def grib2_create(object listsec0, object listsec1):             # <<<<<<<<<<<<<<
 *     """
 *  Initializes a new GRIB2 message and packs
 */
  __pyx_k_tuple_43 = PyTuple_New(12); if (unlikely(!__pyx_k_tuple_43)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 460; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_k_tuple_43);
  __Pyx_INCREF(((PyObject *)__pyx_n_s__listsec0));
  PyTuple_SET_ITEM(__pyx_k_tuple_43, 0, ((PyObject *)__pyx_n_s__listsec0));
  __Pyx_GIVEREF(((PyObject *)__pyx_n_s__listsec0));
  __Pyx_INCREF(((PyObject *)__pyx_n_s__listsec1));
  PyTuple_SET_ITEM(__pyx_k_tuple_43, 1, ((PyObject *)__pyx_n_s__listsec1));
  __Pyx_GIVEREF(((PyObject *)__pyx_n_s__listsec1));
  __Pyx_INCREF(((PyObject *)__pyx_n_s__isec0));
  PyTuple_SET_ITEM(__pyx_k_tuple_43, 2, ((PyObject *)__pyx_n_s__isec0));
  __Pyx_GIVEREF(((PyObject *)__pyx_n_s__isec0));
  __Pyx_INCREF(((PyObject *)__pyx_n_s__isec1));
  PyTuple_SET_ITEM(__pyx_k_tuple_43, 3, ((PyObject *)__pyx_n_s__isec1));
  __Pyx_GIVEREF(((PyObject *)__pyx_n_s__isec1));
  __Pyx_INCREF(((PyObject *)__pyx_n_s__ierr));
  PyTuple_SET_ITEM(__pyx_k_tuple_43, 4, ((PyObject *)__pyx_n_s__ierr));
  __Pyx_GIVEREF(((PyObject *)__pyx_n_s__ierr));
  __Pyx_INCREF(((PyObject *)__pyx_n_s__listsec0dat));
  PyTuple_SET_ITEM(__pyx_k_tuple_43, 5, ((PyObject *)__pyx_n_s__listsec0dat));
  __Pyx_GIVEREF(((PyObject *)__pyx_n_s__listsec0dat));
  __Pyx_INCREF(((PyObject *)__pyx_n_s__listsec1dat));
  PyTuple_SET_ITEM(__pyx_k_tuple_43, 6, ((PyObject *)__pyx_n_s__listsec1dat));
  __Pyx_GIVEREF(((PyObject *)__pyx_n_s__listsec1dat));
  __Pyx_INCREF(((PyObject *)__pyx_n_s__buflen));
  PyTuple_SET_ITEM(__pyx_k_tuple_43, 7, ((PyObject *)__pyx_n_s__buflen));
  __Pyx_GIVEREF(((PyObject *)__pyx_n_s__buflen));
  __Pyx_INCREF(((PyObject *)__pyx_n_s__cgrib));
  PyTuple_SET_ITEM(__pyx_k_tuple_43, 8, ((PyObject *)__pyx_n_s__cgrib));
  __Pyx_GIVEREF(((PyObject *)__pyx_n_s__cgrib));
  __Pyx_INCREF(((PyObject *)__pyx_n_s__lgrib));
  PyTuple_SET_ITEM(__pyx_k_tuple_43, 9, ((PyObject *)__pyx_n_s__lgrib));
  __Pyx_GIVEREF(((PyObject *)__pyx_n_s__lgrib));
  __Pyx_INCREF(((PyObject *)__pyx_n_s__gribmsg));
  PyTuple_SET_ITEM(__pyx_k_tuple_43, 10, ((PyObject *)__pyx_n_s__gribmsg));
  __Pyx_GIVEREF(((PyObject *)__pyx_n_s__gribmsg));
  __Pyx_INCREF(((PyObject *)__pyx_n_s__msg));
  PyTuple_SET_ITEM(__pyx_k_tuple_43, 11, ((PyObject *)__pyx_n_s__msg));
  __Pyx_GIVEREF(((PyObject *)__pyx_n_s__msg));
  __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_43));
  __pyx_k_codeobj_44 = (PyObject*)__Pyx_PyCode_New(2, 0, 12, 0, 0, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_k_tuple_43, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_28, __pyx_n_s__grib2_create, 460, __pyx_empty_bytes); if (unlikely(!__pyx_k_codeobj_44)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 460; __pyx_clineno = __LINE__; goto __pyx_L1_error;}

  /* "g2clib.pyx":520
 *     return gribmsg, ierr
 * 
 * def grib2_end(gribmsg):             # <<<<<<<<<<<<<<
 *     """
 * 
 */
  __pyx_k_tuple_45 = PyTuple_New(4); if (unlikely(!__pyx_k_tuple_45)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 520; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_k_tuple_45);
  __Pyx_INCREF(((PyObject *)__pyx_n_s__gribmsg));
  PyTuple_SET_ITEM(__pyx_k_tuple_45, 0, ((PyObject *)__pyx_n_s__gribmsg));
  __Pyx_GIVEREF(((PyObject *)__pyx_n_s__gribmsg));
  __Pyx_INCREF(((PyObject *)__pyx_n_s__ierr));
  PyTuple_SET_ITEM(__pyx_k_tuple_45, 1, ((PyObject *)__pyx_n_s__ierr));
  __Pyx_GIVEREF(((PyObject *)__pyx_n_s__ierr));
  __Pyx_INCREF(((PyObject *)__pyx_n_s__cgrib));
  PyTuple_SET_ITEM(__pyx_k_tuple_45, 2, ((PyObject *)__pyx_n_s__cgrib));
  __Pyx_GIVEREF(((PyObject *)__pyx_n_s__cgrib));
  __Pyx_INCREF(((PyObject *)__pyx_n_s__msg));
  PyTuple_SET_ITEM(__pyx_k_tuple_45, 3, ((PyObject *)__pyx_n_s__msg));
  __Pyx_GIVEREF(((PyObject *)__pyx_n_s__msg));
  __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_45));
  __pyx_k_codeobj_46 = (PyObject*)__Pyx_PyCode_New(1, 0, 4, 0, 0, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_k_tuple_45, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_28, __pyx_n_s__grib2_end, 520, __pyx_empty_bytes); if (unlikely(!__pyx_k_codeobj_46)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 520; __pyx_clineno = __LINE__; goto __pyx_L1_error;}

  /* "g2clib.pyx":562
 *     return gribmsg, ierr
 * 
 * def grib2_addgrid(gribmsg,object gds,object gdstmpl,object deflist=None, defnum = 0):             # <<<<<<<<<<<<<<
 *     """
 *    Packs up a Grid Definition Section (Section 3)
 */
  __pyx_k_tuple_47 = PyTuple_New(16); if (unlikely(!__pyx_k_tuple_47)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 562; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_k_tuple_47);
  __Pyx_INCREF(((PyObject *)__pyx_n_s__gribmsg));
  PyTuple_SET_ITEM(__pyx_k_tuple_47, 0, ((PyObject *)__pyx_n_s__gribmsg));
  __Pyx_GIVEREF(((PyObject *)__pyx_n_s__gribmsg));
  __Pyx_INCREF(((PyObject *)__pyx_n_s__gds));
  PyTuple_SET_ITEM(__pyx_k_tuple_47, 1, ((PyObject *)__pyx_n_s__gds));
  __Pyx_GIVEREF(((PyObject *)__pyx_n_s__gds));
  __Pyx_INCREF(((PyObject *)__pyx_n_s__gdstmpl));
  PyTuple_SET_ITEM(__pyx_k_tuple_47, 2, ((PyObject *)__pyx_n_s__gdstmpl));
  __Pyx_GIVEREF(((PyObject *)__pyx_n_s__gdstmpl));
  __Pyx_INCREF(((PyObject *)__pyx_n_s__deflist));
  PyTuple_SET_ITEM(__pyx_k_tuple_47, 3, ((PyObject *)__pyx_n_s__deflist));
  __Pyx_GIVEREF(((PyObject *)__pyx_n_s__deflist));
  __Pyx_INCREF(((PyObject *)__pyx_n_s__defnum));
  PyTuple_SET_ITEM(__pyx_k_tuple_47, 4, ((PyObject *)__pyx_n_s__defnum));
  __Pyx_GIVEREF(((PyObject *)__pyx_n_s__defnum));
  __Pyx_INCREF(((PyObject *)__pyx_n_s__ierr));
  PyTuple_SET_ITEM(__pyx_k_tuple_47, 5, ((PyObject *)__pyx_n_s__ierr));
  __Pyx_GIVEREF(((PyObject *)__pyx_n_s__ierr));
  __Pyx_INCREF(((PyObject *)__pyx_n_s__idefnum));
  PyTuple_SET_ITEM(__pyx_k_tuple_47, 6, ((PyObject *)__pyx_n_s__idefnum));
  __Pyx_GIVEREF(((PyObject *)__pyx_n_s__idefnum));
  __Pyx_INCREF(((PyObject *)__pyx_n_s__igds));
  PyTuple_SET_ITEM(__pyx_k_tuple_47, 7, ((PyObject *)__pyx_n_s__igds));
  __Pyx_GIVEREF(((PyObject *)__pyx_n_s__igds));
  __Pyx_INCREF(((PyObject *)__pyx_n_s__igdstmpl));
  PyTuple_SET_ITEM(__pyx_k_tuple_47, 8, ((PyObject *)__pyx_n_s__igdstmpl));
  __Pyx_GIVEREF(((PyObject *)__pyx_n_s__igdstmpl));
  __Pyx_INCREF(((PyObject *)__pyx_n_s__ideflist));
  PyTuple_SET_ITEM(__pyx_k_tuple_47, 9, ((PyObject *)__pyx_n_s__ideflist));
  __Pyx_GIVEREF(((PyObject *)__pyx_n_s__ideflist));
  __Pyx_INCREF(((PyObject *)__pyx_n_s__cgrib));
  PyTuple_SET_ITEM(__pyx_k_tuple_47, 10, ((PyObject *)__pyx_n_s__cgrib));
  __Pyx_GIVEREF(((PyObject *)__pyx_n_s__cgrib));
  __Pyx_INCREF(((PyObject *)__pyx_n_s__gdsdat));
  PyTuple_SET_ITEM(__pyx_k_tuple_47, 11, ((PyObject *)__pyx_n_s__gdsdat));
  __Pyx_GIVEREF(((PyObject *)__pyx_n_s__gdsdat));
  __Pyx_INCREF(((PyObject *)__pyx_n_s__deflistdat));
  PyTuple_SET_ITEM(__pyx_k_tuple_47, 12, ((PyObject *)__pyx_n_s__deflistdat));
  __Pyx_GIVEREF(((PyObject *)__pyx_n_s__deflistdat));
  __Pyx_INCREF(((PyObject *)__pyx_n_s__gdstmpldat));
  PyTuple_SET_ITEM(__pyx_k_tuple_47, 13, ((PyObject *)__pyx_n_s__gdstmpldat));
  __Pyx_GIVEREF(((PyObject *)__pyx_n_s__gdstmpldat));
  __Pyx_INCREF(((PyObject *)__pyx_n_s__buflen));
  PyTuple_SET_ITEM(__pyx_k_tuple_47, 14, ((PyObject *)__pyx_n_s__buflen));
  __Pyx_GIVEREF(((PyObject *)__pyx_n_s__buflen));
  __Pyx_INCREF(((PyObject *)__pyx_n_s__msg));
  PyTuple_SET_ITEM(__pyx_k_tuple_47, 15, ((PyObject *)__pyx_n_s__msg));
  __Pyx_GIVEREF(((PyObject *)__pyx_n_s__msg));
  __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_47));
  __pyx_k_codeobj_48 = (PyObject*)__Pyx_PyCode_New(5, 0, 16, 0, 0, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_k_tuple_47, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_28, __pyx_n_s__grib2_addgrid, 562, __pyx_empty_bytes); if (unlikely(!__pyx_k_codeobj_48)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 562; __pyx_clineno = __LINE__; goto __pyx_L1_error;}

  /* "g2clib.pyx":634
 * 
 * 
 * def grib2_addfield(gribmsg,pdsnum,object pdstmpl,object coordlist,             # <<<<<<<<<<<<<<
 *                    drsnum,object drstmpl,object field,
 *                    ibitmap,object bitmap):
 */
  __pyx_k_tuple_49 = PyTuple_New(28); if (unlikely(!__pyx_k_tuple_49)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 634; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_k_tuple_49);
  __Pyx_INCREF(((PyObject *)__pyx_n_s__gribmsg));
  PyTuple_SET_ITEM(__pyx_k_tuple_49, 0, ((PyObject *)__pyx_n_s__gribmsg));
  __Pyx_GIVEREF(((PyObject *)__pyx_n_s__gribmsg));
  __Pyx_INCREF(((PyObject *)__pyx_n_s__pdsnum));
  PyTuple_SET_ITEM(__pyx_k_tuple_49, 1, ((PyObject *)__pyx_n_s__pdsnum));
  __Pyx_GIVEREF(((PyObject *)__pyx_n_s__pdsnum));
  __Pyx_INCREF(((PyObject *)__pyx_n_s__pdstmpl));
  PyTuple_SET_ITEM(__pyx_k_tuple_49, 2, ((PyObject *)__pyx_n_s__pdstmpl));
  __Pyx_GIVEREF(((PyObject *)__pyx_n_s__pdstmpl));
  __Pyx_INCREF(((PyObject *)__pyx_n_s__coordlist));
  PyTuple_SET_ITEM(__pyx_k_tuple_49, 3, ((PyObject *)__pyx_n_s__coordlist));
  __Pyx_GIVEREF(((PyObject *)__pyx_n_s__coordlist));
  __Pyx_INCREF(((PyObject *)__pyx_n_s__drsnum));
  PyTuple_SET_ITEM(__pyx_k_tuple_49, 4, ((PyObject *)__pyx_n_s__drsnum));
  __Pyx_GIVEREF(((PyObject *)__pyx_n_s__drsnum));
  __Pyx_INCREF(((PyObject *)__pyx_n_s__drstmpl));
  PyTuple_SET_ITEM(__pyx_k_tuple_49, 5, ((PyObject *)__pyx_n_s__drstmpl));
  __Pyx_GIVEREF(((PyObject *)__pyx_n_s__drstmpl));
  __Pyx_INCREF(((PyObject *)__pyx_n_s__field));
  PyTuple_SET_ITEM(__pyx_k_tuple_49, 6, ((PyObject *)__pyx_n_s__field));
  __Pyx_GIVEREF(((PyObject *)__pyx_n_s__field));
  __Pyx_INCREF(((PyObject *)__pyx_n_s__ibitmap));
  PyTuple_SET_ITEM(__pyx_k_tuple_49, 7, ((PyObject *)__pyx_n_s__ibitmap));
  __Pyx_GIVEREF(((PyObject *)__pyx_n_s__ibitmap));
  __Pyx_INCREF(((PyObject *)__pyx_n_s__bitmap));
  PyTuple_SET_ITEM(__pyx_k_tuple_49, 8, ((PyObject *)__pyx_n_s__bitmap));
  __Pyx_GIVEREF(((PyObject *)__pyx_n_s__bitmap));
  __Pyx_INCREF(((PyObject *)__pyx_n_s__ierr));
  PyTuple_SET_ITEM(__pyx_k_tuple_49, 9, ((PyObject *)__pyx_n_s__ierr));
  __Pyx_GIVEREF(((PyObject *)__pyx_n_s__ierr));
  __Pyx_INCREF(((PyObject *)__pyx_n_s__ipdsnum));
  PyTuple_SET_ITEM(__pyx_k_tuple_49, 10, ((PyObject *)__pyx_n_s__ipdsnum));
  __Pyx_GIVEREF(((PyObject *)__pyx_n_s__ipdsnum));
  __Pyx_INCREF(((PyObject *)__pyx_n_s__numcoord));
  PyTuple_SET_ITEM(__pyx_k_tuple_49, 11, ((PyObject *)__pyx_n_s__numcoord));
  __Pyx_GIVEREF(((PyObject *)__pyx_n_s__numcoord));
  __Pyx_INCREF(((PyObject *)__pyx_n_s__ipdstmpl));
  PyTuple_SET_ITEM(__pyx_k_tuple_49, 12, ((PyObject *)__pyx_n_s__ipdstmpl));
  __Pyx_GIVEREF(((PyObject *)__pyx_n_s__ipdstmpl));
  __Pyx_INCREF(((PyObject *)__pyx_n_s__idrsnum));
  PyTuple_SET_ITEM(__pyx_k_tuple_49, 13, ((PyObject *)__pyx_n_s__idrsnum));
  __Pyx_GIVEREF(((PyObject *)__pyx_n_s__idrsnum));
  __Pyx_INCREF(((PyObject *)__pyx_n_s__idrstmpl));
  PyTuple_SET_ITEM(__pyx_k_tuple_49, 14, ((PyObject *)__pyx_n_s__idrstmpl));
  __Pyx_GIVEREF(((PyObject *)__pyx_n_s__idrstmpl));
  __Pyx_INCREF(((PyObject *)__pyx_n_s__fld));
  PyTuple_SET_ITEM(__pyx_k_tuple_49, 15, ((PyObject *)__pyx_n_s__fld));
  __Pyx_GIVEREF(((PyObject *)__pyx_n_s__fld));
  __Pyx_INCREF(((PyObject *)__pyx_n_s__fcoordlist));
  PyTuple_SET_ITEM(__pyx_k_tuple_49, 16, ((PyObject *)__pyx_n_s__fcoordlist));
  __Pyx_GIVEREF(((PyObject *)__pyx_n_s__fcoordlist));
  __Pyx_INCREF(((PyObject *)__pyx_n_s__bmap));
  PyTuple_SET_ITEM(__pyx_k_tuple_49, 17, ((PyObject *)__pyx_n_s__bmap));
  __Pyx_GIVEREF(((PyObject *)__pyx_n_s__bmap));
  __Pyx_INCREF(((PyObject *)__pyx_n_s__ngrdpts));
  PyTuple_SET_ITEM(__pyx_k_tuple_49, 18, ((PyObject *)__pyx_n_s__ngrdpts));
  __Pyx_GIVEREF(((PyObject *)__pyx_n_s__ngrdpts));
  __Pyx_INCREF(((PyObject *)__pyx_n_s__ibmap));
  PyTuple_SET_ITEM(__pyx_k_tuple_49, 19, ((PyObject *)__pyx_n_s__ibmap));
  __Pyx_GIVEREF(((PyObject *)__pyx_n_s__ibmap));
  __Pyx_INCREF(((PyObject *)__pyx_n_s__pdtmpldat));
  PyTuple_SET_ITEM(__pyx_k_tuple_49, 20, ((PyObject *)__pyx_n_s__pdtmpldat));
  __Pyx_GIVEREF(((PyObject *)__pyx_n_s__pdtmpldat));
  __Pyx_INCREF(((PyObject *)__pyx_n_s__drtmpldat));
  PyTuple_SET_ITEM(__pyx_k_tuple_49, 21, ((PyObject *)__pyx_n_s__drtmpldat));
  __Pyx_GIVEREF(((PyObject *)__pyx_n_s__drtmpldat));
  __Pyx_INCREF(((PyObject *)__pyx_n_s__coordlistdat));
  PyTuple_SET_ITEM(__pyx_k_tuple_49, 22, ((PyObject *)__pyx_n_s__coordlistdat));
  __Pyx_GIVEREF(((PyObject *)__pyx_n_s__coordlistdat));
  __Pyx_INCREF(((PyObject *)__pyx_n_s__fielddat));
  PyTuple_SET_ITEM(__pyx_k_tuple_49, 23, ((PyObject *)__pyx_n_s__fielddat));
  __Pyx_GIVEREF(((PyObject *)__pyx_n_s__fielddat));
  __Pyx_INCREF(((PyObject *)__pyx_n_s__bitmapdat));
  PyTuple_SET_ITEM(__pyx_k_tuple_49, 24, ((PyObject *)__pyx_n_s__bitmapdat));
  __Pyx_GIVEREF(((PyObject *)__pyx_n_s__bitmapdat));
  __Pyx_INCREF(((PyObject *)__pyx_n_s__buflen));
  PyTuple_SET_ITEM(__pyx_k_tuple_49, 25, ((PyObject *)__pyx_n_s__buflen));
  __Pyx_GIVEREF(((PyObject *)__pyx_n_s__buflen));
  __Pyx_INCREF(((PyObject *)__pyx_n_s__cgrib));
  PyTuple_SET_ITEM(__pyx_k_tuple_49, 26, ((PyObject *)__pyx_n_s__cgrib));
  __Pyx_GIVEREF(((PyObject *)__pyx_n_s__cgrib));
  __Pyx_INCREF(((PyObject *)__pyx_n_s__msg));
  PyTuple_SET_ITEM(__pyx_k_tuple_49, 27, ((PyObject *)__pyx_n_s__msg));
  __Pyx_GIVEREF(((PyObject *)__pyx_n_s__msg));
  __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_49));
  __pyx_k_codeobj_50 = (PyObject*)__Pyx_PyCode_New(9, 0, 28, 0, 0, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_k_tuple_49, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_28, __pyx_n_s__grib2_addfield, 634, __pyx_empty_bytes); if (unlikely(!__pyx_k_codeobj_50)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 634; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_RefNannyFinishContext();
  return 0;
  __pyx_L1_error:;
  __Pyx_RefNannyFinishContext();
  return -1;
}

static int __Pyx_InitGlobals(void) {
  if (__Pyx_InitStrings(__pyx_string_tab) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;};
  __pyx_int_0 = PyInt_FromLong(0); if (unlikely(!__pyx_int_0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;};
  __pyx_int_1 = PyInt_FromLong(1); if (unlikely(!__pyx_int_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;};
  __pyx_int_2 = PyInt_FromLong(2); if (unlikely(!__pyx_int_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;};
  __pyx_int_4 = PyInt_FromLong(4); if (unlikely(!__pyx_int_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;};
  __pyx_int_5 = PyInt_FromLong(5); if (unlikely(!__pyx_int_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;};
  __pyx_int_8 = PyInt_FromLong(8); if (unlikely(!__pyx_int_8)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;};
  __pyx_int_254 = PyInt_FromLong(254); if (unlikely(!__pyx_int_254)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;};
  __pyx_int_260 = PyInt_FromLong(260); if (unlikely(!__pyx_int_260)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;};
  return 0;
  __pyx_L1_error:;
  return -1;
}

#if PY_MAJOR_VERSION < 3
PyMODINIT_FUNC initg2clib(void); /*proto*/
PyMODINIT_FUNC initg2clib(void)
#else
PyMODINIT_FUNC PyInit_g2clib(void); /*proto*/
PyMODINIT_FUNC PyInit_g2clib(void)
#endif
{
  PyObject *__pyx_t_1 = NULL;
  __Pyx_RefNannyDeclarations
  #if CYTHON_REFNANNY
  __Pyx_RefNanny = __Pyx_RefNannyImportAPI("refnanny");
  if (!__Pyx_RefNanny) {
      PyErr_Clear();
      __Pyx_RefNanny = __Pyx_RefNannyImportAPI("Cython.Runtime.refnanny");
      if (!__Pyx_RefNanny)
          Py_FatalError("failed to import 'refnanny' module");
  }
  #endif
  __Pyx_RefNannySetupContext("PyMODINIT_FUNC PyInit_g2clib(void)", 0);
  if ( __Pyx_check_binary_version() < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_empty_tuple = PyTuple_New(0); if (unlikely(!__pyx_empty_tuple)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_empty_bytes = PyBytes_FromStringAndSize("", 0); if (unlikely(!__pyx_empty_bytes)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  #ifdef __Pyx_CyFunction_USED
  if (__Pyx_CyFunction_init() < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  #endif
  #ifdef __Pyx_FusedFunction_USED
  if (__pyx_FusedFunction_init() < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  #endif
  #ifdef __Pyx_Generator_USED
  if (__pyx_Generator_init() < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  #endif
  /*--- Library function declarations ---*/
  /*--- Threads initialization code ---*/
  #if defined(__PYX_FORCE_INIT_THREADS) && __PYX_FORCE_INIT_THREADS
  #ifdef WITH_THREAD /* Python build with threading support? */
  PyEval_InitThreads();
  #endif
  #endif
  /*--- Module creation code ---*/
  #if PY_MAJOR_VERSION < 3
  __pyx_m = Py_InitModule4(__Pyx_NAMESTR("g2clib"), __pyx_methods, __Pyx_DOCSTR(__pyx_k_25), 0, PYTHON_API_VERSION); Py_XINCREF(__pyx_m);
  #else
  __pyx_m = PyModule_Create(&__pyx_moduledef);
  #endif
  if (unlikely(!__pyx_m)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  #if PY_MAJOR_VERSION >= 3
  {
    PyObject *modules = PyImport_GetModuleDict(); if (unlikely(!modules)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    if (!PyDict_GetItemString(modules, "g2clib")) {
      if (unlikely(PyDict_SetItemString(modules, "g2clib", __pyx_m) < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    }
  }
  #endif
  __pyx_b = PyImport_AddModule(__Pyx_NAMESTR(__Pyx_BUILTIN_MODULE_NAME)); if (unlikely(!__pyx_b)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  #if CYTHON_COMPILING_IN_PYPY
  Py_INCREF(__pyx_b);
  #endif
  if (__Pyx_SetAttrString(__pyx_m, "__builtins__", __pyx_b) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;};
  /*--- Initialize various global constants etc. ---*/
  if (unlikely(__Pyx_InitGlobals() < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  if (__pyx_module_is_main_g2clib) {
    if (__Pyx_SetAttrString(__pyx_m, "__name__", __pyx_n_s____main__) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;};
  }
  /*--- Builtin init code ---*/
  if (unlikely(__Pyx_InitCachedBuiltins() < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  /*--- Constants init code ---*/
  if (unlikely(__Pyx_InitCachedConstants() < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  /*--- Global init code ---*/
  /*--- Variable export code ---*/
  /*--- Function export code ---*/
  /*--- Type init code ---*/
  /*--- Type import code ---*/
  /*--- Variable import code ---*/
  /*--- Function import code ---*/
  /*--- Execution code ---*/

  /* "g2clib.pyx":5
 * c-wrappers that Pyrex generates."""
 * 
 * import math             # <<<<<<<<<<<<<<
 * 
 * # Some helper routines from the Python API
 */
  __pyx_t_1 = __Pyx_Import(((PyObject *)__pyx_n_s__math), 0, -1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 5; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  if (PyObject_SetAttr(__pyx_m, __pyx_n_s__math, __pyx_t_1) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 5; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

  /* "g2clib.pyx":55
 * # routines for convert to/from IEEE integers.
 * 
 * def rtoi_ieee(object rarr, object iarr):             # <<<<<<<<<<<<<<
 *     """
 *  Converts a float32 array into an int32 array of IEEE formatted values
 */
  __pyx_t_1 = PyCFunction_NewEx(&__pyx_mdef_6g2clib_1rtoi_ieee, NULL, __pyx_n_s__g2clib); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 55; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  if (PyObject_SetAttr(__pyx_m, __pyx_n_s__rtoi_ieee, __pyx_t_1) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 55; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

  /* "g2clib.pyx":73
 *     mkieee(rdata, idata, buflenr/4)
 * 
 * def itor_ieee(object iarr, object rarr):             # <<<<<<<<<<<<<<
 *     """
 *  Converts an int32 array of IEEE values into a float32 array.
 */
  __pyx_t_1 = PyCFunction_NewEx(&__pyx_mdef_6g2clib_3itor_ieee, NULL, __pyx_n_s__g2clib); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 73; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  if (PyObject_SetAttr(__pyx_m, __pyx_n_s__itor_ieee, __pyx_t_1) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 73; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

  /* "g2clib.pyx":123
 * # routines for reading grib2 files.
 * 
 * def unpack1(gribmsg, ipos, object zeros):             # <<<<<<<<<<<<<<
 *     """              .      .    .                                       .
 *  Unpacks Section 1 (Identification Section) as defined in GRIB Edition 2.
 */
  __pyx_t_1 = PyCFunction_NewEx(&__pyx_mdef_6g2clib_5unpack1, NULL, __pyx_n_s__g2clib); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 123; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  if (PyObject_SetAttr(__pyx_m, __pyx_n_s__unpack1, __pyx_t_1) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 123; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

  /* "g2clib.pyx":177
 * 
 * 
 * def unpack3(gribmsg, ipos, object zeros):             # <<<<<<<<<<<<<<
 *     """
 *  Unpacks Section 3 (Grid Definition Section) as defined in GRIB Edition 2.
 */
  __pyx_t_1 = PyCFunction_NewEx(&__pyx_mdef_6g2clib_7unpack3, NULL, __pyx_n_s__g2clib); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 177; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  if (PyObject_SetAttr(__pyx_m, __pyx_n_s__unpack3, __pyx_t_1) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 177; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

  /* "g2clib.pyx":237
 *     return gds,gdtmpl,deflist,iofst/8
 * 
 * def unpack4(gribmsg,ipos,object zeros):             # <<<<<<<<<<<<<<
 *     """
 *  Unpacks Section 4 (Product Definition Section) as defined in GRIB Edition 2.
 */
  __pyx_t_1 = PyCFunction_NewEx(&__pyx_mdef_6g2clib_9unpack4, NULL, __pyx_n_s__g2clib); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 237; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  if (PyObject_SetAttr(__pyx_m, __pyx_n_s__unpack4, __pyx_t_1) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 237; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

  /* "g2clib.pyx":287
 *     return pdtmpl,ipdsnum,coordlist,iofst/8
 * 
 * def unpack5(gribmsg,ipos,object zeros):             # <<<<<<<<<<<<<<
 *     """
 *  Unpacks Section 5 (Data Representation Section) as defined in GRIB Edition 2.
 */
  __pyx_t_1 = PyCFunction_NewEx(&__pyx_mdef_6g2clib_11unpack5, NULL, __pyx_n_s__g2clib); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 287; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  if (PyObject_SetAttr(__pyx_m, __pyx_n_s__unpack5, __pyx_t_1) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 287; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

  /* "g2clib.pyx":331
 *     return drtmpl,idrsnum,ndpts,iofst/8
 * 
 * def unpack6(gribmsg,ndpts,ipos,object zeros):             # <<<<<<<<<<<<<<
 *     """
 *  Unpacks Section 6 (Bit-Map Section) as defined in GRIB Edition 2.
 */
  __pyx_t_1 = PyCFunction_NewEx(&__pyx_mdef_6g2clib_13unpack6, NULL, __pyx_n_s__g2clib); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 331; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  if (PyObject_SetAttr(__pyx_m, __pyx_n_s__unpack6, __pyx_t_1) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 331; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

  /* "g2clib.pyx":377
 *     return bitmap,ibmap
 * 
 * def unpack7(gribmsg,gdtnum,object gdtmpl,drtnum,object drtmpl,ndpts,ipos,object zeros,printminmax=False,storageorder='C'):             # <<<<<<<<<<<<<<
 *     """
 *  Unpacks Section 7 (Data Section) as defined in GRIB Edition 2.
 */
  __pyx_t_1 = __Pyx_PyBool_FromLong(0); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 377; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_k_14 = __pyx_t_1;
  __Pyx_GIVEREF(__pyx_t_1);
  __pyx_t_1 = 0;
  __pyx_t_1 = PyCFunction_NewEx(&__pyx_mdef_6g2clib_15unpack7, NULL, __pyx_n_s__g2clib); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 377; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  if (PyObject_SetAttr(__pyx_m, __pyx_n_s__unpack7, __pyx_t_1) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 377; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

  /* "g2clib.pyx":460
 * # routines for writing grib2 files.
 * 
 * def grib2_create(object listsec0, object listsec1):             # <<<<<<<<<<<<<<
 *     """
 *  Initializes a new GRIB2 message and packs
 */
  __pyx_t_1 = PyCFunction_NewEx(&__pyx_mdef_6g2clib_17grib2_create, NULL, __pyx_n_s__g2clib); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 460; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  if (PyObject_SetAttr(__pyx_m, __pyx_n_s__grib2_create, __pyx_t_1) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 460; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

  /* "g2clib.pyx":520
 *     return gribmsg, ierr
 * 
 * def grib2_end(gribmsg):             # <<<<<<<<<<<<<<
 *     """
 * 
 */
  __pyx_t_1 = PyCFunction_NewEx(&__pyx_mdef_6g2clib_19grib2_end, NULL, __pyx_n_s__g2clib); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 520; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  if (PyObject_SetAttr(__pyx_m, __pyx_n_s__grib2_end, __pyx_t_1) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 520; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

  /* "g2clib.pyx":562
 *     return gribmsg, ierr
 * 
 * def grib2_addgrid(gribmsg,object gds,object gdstmpl,object deflist=None, defnum = 0):             # <<<<<<<<<<<<<<
 *     """
 *    Packs up a Grid Definition Section (Section 3)
 */
  __pyx_t_1 = PyCFunction_NewEx(&__pyx_mdef_6g2clib_21grib2_addgrid, NULL, __pyx_n_s__g2clib); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 562; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  if (PyObject_SetAttr(__pyx_m, __pyx_n_s__grib2_addgrid, __pyx_t_1) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 562; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

  /* "g2clib.pyx":634
 * 
 * 
 * def grib2_addfield(gribmsg,pdsnum,object pdstmpl,object coordlist,             # <<<<<<<<<<<<<<
 *                    drsnum,object drstmpl,object field,
 *                    ibitmap,object bitmap):
 */
  __pyx_t_1 = PyCFunction_NewEx(&__pyx_mdef_6g2clib_23grib2_addfield, NULL, __pyx_n_s__g2clib); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 634; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  if (PyObject_SetAttr(__pyx_m, __pyx_n_s__grib2_addfield, __pyx_t_1) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 634; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

  /* "g2clib.pyx":1
 * """Pyrex code to provide python interfaces to functions             # <<<<<<<<<<<<<<
 * in the NCEP grib2c library. Make changes to this file, not the
 * c-wrappers that Pyrex generates."""
 */
  __pyx_t_1 = PyDict_New(); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(((PyObject *)__pyx_t_1));
  if (PyObject_SetAttr(__pyx_m, __pyx_n_s____test__, ((PyObject *)__pyx_t_1)) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(((PyObject *)__pyx_t_1)); __pyx_t_1 = 0;
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  if (__pyx_m) {
    __Pyx_AddTraceback("init g2clib", __pyx_clineno, __pyx_lineno, __pyx_filename);
    Py_DECREF(__pyx_m); __pyx_m = 0;
  } else if (!PyErr_Occurred()) {
    PyErr_SetString(PyExc_ImportError, "init g2clib");
  }
  __pyx_L0:;
  __Pyx_RefNannyFinishContext();
  #if PY_MAJOR_VERSION < 3
  return;
  #else
  return __pyx_m;
  #endif
}

/* Runtime support code */
#if CYTHON_REFNANNY
static __Pyx_RefNannyAPIStruct *__Pyx_RefNannyImportAPI(const char *modname) {
    PyObject *m = NULL, *p = NULL;
    void *r = NULL;
    m = PyImport_ImportModule((char *)modname);
    if (!m) goto end;
    p = PyObject_GetAttrString(m, (char *)"RefNannyAPI");
    if (!p) goto end;
    r = PyLong_AsVoidPtr(p);
end:
    Py_XDECREF(p);
    Py_XDECREF(m);
    return (__Pyx_RefNannyAPIStruct *)r;
}
#endif /* CYTHON_REFNANNY */

static PyObject *__Pyx_GetName(PyObject *dict, PyObject *name) {
    PyObject *result;
    result = PyObject_GetAttr(dict, name);
    if (!result) {
        if (dict != __pyx_b) {
            PyErr_Clear();
            result = PyObject_GetAttr(__pyx_b, name);
        }
        if (!result) {
            PyErr_SetObject(PyExc_NameError, name);
        }
    }
    return result;
}

static void __Pyx_RaiseArgtupleInvalid(
    const char* func_name,
    int exact,
    Py_ssize_t num_min,
    Py_ssize_t num_max,
    Py_ssize_t num_found)
{
    Py_ssize_t num_expected;
    const char *more_or_less;
    if (num_found < num_min) {
        num_expected = num_min;
        more_or_less = "at least";
    } else {
        num_expected = num_max;
        more_or_less = "at most";
    }
    if (exact) {
        more_or_less = "exactly";
    }
    PyErr_Format(PyExc_TypeError,
                 "%s() takes %s %" CYTHON_FORMAT_SSIZE_T "d positional argument%s (%" CYTHON_FORMAT_SSIZE_T "d given)",
                 func_name, more_or_less, num_expected,
                 (num_expected == 1) ? "" : "s", num_found);
}

static void __Pyx_RaiseDoubleKeywordsError(
    const char* func_name,
    PyObject* kw_name)
{
    PyErr_Format(PyExc_TypeError,
        #if PY_MAJOR_VERSION >= 3
        "%s() got multiple values for keyword argument '%U'", func_name, kw_name);
        #else
        "%s() got multiple values for keyword argument '%s'", func_name,
        PyString_AsString(kw_name));
        #endif
}

static int __Pyx_ParseOptionalKeywords(
    PyObject *kwds,
    PyObject **argnames[],
    PyObject *kwds2,
    PyObject *values[],
    Py_ssize_t num_pos_args,
    const char* function_name)
{
    PyObject *key = 0, *value = 0;
    Py_ssize_t pos = 0;
    PyObject*** name;
    PyObject*** first_kw_arg = argnames + num_pos_args;
    while (PyDict_Next(kwds, &pos, &key, &value)) {
        name = first_kw_arg;
        while (*name && (**name != key)) name++;
        if (*name) {
            values[name-argnames] = value;
            continue;
        }
        name = first_kw_arg;
        #if PY_MAJOR_VERSION < 3
        if (likely(PyString_CheckExact(key)) || likely(PyString_Check(key))) {
            while (*name) {
                if ((CYTHON_COMPILING_IN_PYPY || PyString_GET_SIZE(**name) == PyString_GET_SIZE(key))
                        && _PyString_Eq(**name, key)) {
                    values[name-argnames] = value;
                    break;
                }
                name++;
            }
            if (*name) continue;
            else {
                PyObject*** argname = argnames;
                while (argname != first_kw_arg) {
                    if ((**argname == key) || (
                            (CYTHON_COMPILING_IN_PYPY || PyString_GET_SIZE(**argname) == PyString_GET_SIZE(key))
                             && _PyString_Eq(**argname, key))) {
                        goto arg_passed_twice;
                    }
                    argname++;
                }
            }
        } else
        #endif
        if (likely(PyUnicode_Check(key))) {
            while (*name) {
                int cmp = (**name == key) ? 0 :
                #if !CYTHON_COMPILING_IN_PYPY && PY_MAJOR_VERSION >= 3
                    (PyUnicode_GET_SIZE(**name) != PyUnicode_GET_SIZE(key)) ? 1 :
                #endif
                    PyUnicode_Compare(**name, key);
                if (cmp < 0 && unlikely(PyErr_Occurred())) goto bad;
                if (cmp == 0) {
                    values[name-argnames] = value;
                    break;
                }
                name++;
            }
            if (*name) continue;
            else {
                PyObject*** argname = argnames;
                while (argname != first_kw_arg) {
                    int cmp = (**argname == key) ? 0 :
                    #if !CYTHON_COMPILING_IN_PYPY && PY_MAJOR_VERSION >= 3
                        (PyUnicode_GET_SIZE(**argname) != PyUnicode_GET_SIZE(key)) ? 1 :
                    #endif
                        PyUnicode_Compare(**argname, key);
                    if (cmp < 0 && unlikely(PyErr_Occurred())) goto bad;
                    if (cmp == 0) goto arg_passed_twice;
                    argname++;
                }
            }
        } else
            goto invalid_keyword_type;
        if (kwds2) {
            if (unlikely(PyDict_SetItem(kwds2, key, value))) goto bad;
        } else {
            goto invalid_keyword;
        }
    }
    return 0;
arg_passed_twice:
    __Pyx_RaiseDoubleKeywordsError(function_name, key);
    goto bad;
invalid_keyword_type:
    PyErr_Format(PyExc_TypeError,
        "%s() keywords must be strings", function_name);
    goto bad;
invalid_keyword:
    PyErr_Format(PyExc_TypeError,
    #if PY_MAJOR_VERSION < 3
        "%s() got an unexpected keyword argument '%s'",
        function_name, PyString_AsString(key));
    #else
        "%s() got an unexpected keyword argument '%U'",
        function_name, key);
    #endif
bad:
    return -1;
}

static CYTHON_INLINE void __Pyx_ErrRestore(PyObject *type, PyObject *value, PyObject *tb) {
#if CYTHON_COMPILING_IN_CPYTHON
    PyObject *tmp_type, *tmp_value, *tmp_tb;
    PyThreadState *tstate = PyThreadState_GET();
    tmp_type = tstate->curexc_type;
    tmp_value = tstate->curexc_value;
    tmp_tb = tstate->curexc_traceback;
    tstate->curexc_type = type;
    tstate->curexc_value = value;
    tstate->curexc_traceback = tb;
    Py_XDECREF(tmp_type);
    Py_XDECREF(tmp_value);
    Py_XDECREF(tmp_tb);
#else
    PyErr_Restore(type, value, tb);
#endif
}
static CYTHON_INLINE void __Pyx_ErrFetch(PyObject **type, PyObject **value, PyObject **tb) {
#if CYTHON_COMPILING_IN_CPYTHON
    PyThreadState *tstate = PyThreadState_GET();
    *type = tstate->curexc_type;
    *value = tstate->curexc_value;
    *tb = tstate->curexc_traceback;
    tstate->curexc_type = 0;
    tstate->curexc_value = 0;
    tstate->curexc_traceback = 0;
#else
    PyErr_Fetch(type, value, tb);
#endif
}

#if PY_MAJOR_VERSION < 3
static void __Pyx_Raise(PyObject *type, PyObject *value, PyObject *tb,
                        CYTHON_UNUSED PyObject *cause) {
    Py_XINCREF(type);
    if (!value || value == Py_None)
        value = NULL;
    else
        Py_INCREF(value);
    if (!tb || tb == Py_None)
        tb = NULL;
    else {
        Py_INCREF(tb);
        if (!PyTraceBack_Check(tb)) {
            PyErr_SetString(PyExc_TypeError,
                "raise: arg 3 must be a traceback or None");
            goto raise_error;
        }
    }
    #if PY_VERSION_HEX < 0x02050000
    if (PyClass_Check(type)) {
    #else
    if (PyType_Check(type)) {
    #endif
#if CYTHON_COMPILING_IN_PYPY
        if (!value) {
            Py_INCREF(Py_None);
            value = Py_None;
        }
#endif
        PyErr_NormalizeException(&type, &value, &tb);
    } else {
        if (value) {
            PyErr_SetString(PyExc_TypeError,
                "instance exception may not have a separate value");
            goto raise_error;
        }
        value = type;
        #if PY_VERSION_HEX < 0x02050000
            if (PyInstance_Check(type)) {
                type = (PyObject*) ((PyInstanceObject*)type)->in_class;
                Py_INCREF(type);
            }
            else {
                type = 0;
                PyErr_SetString(PyExc_TypeError,
                    "raise: exception must be an old-style class or instance");
                goto raise_error;
            }
        #else
            type = (PyObject*) Py_TYPE(type);
            Py_INCREF(type);
            if (!PyType_IsSubtype((PyTypeObject *)type, (PyTypeObject *)PyExc_BaseException)) {
                PyErr_SetString(PyExc_TypeError,
                    "raise: exception class must be a subclass of BaseException");
                goto raise_error;
            }
        #endif
    }
    __Pyx_ErrRestore(type, value, tb);
    return;
raise_error:
    Py_XDECREF(value);
    Py_XDECREF(type);
    Py_XDECREF(tb);
    return;
}
#else /* Python 3+ */
static void __Pyx_Raise(PyObject *type, PyObject *value, PyObject *tb, PyObject *cause) {
    PyObject* owned_instance = NULL;
    if (tb == Py_None) {
        tb = 0;
    } else if (tb && !PyTraceBack_Check(tb)) {
        PyErr_SetString(PyExc_TypeError,
            "raise: arg 3 must be a traceback or None");
        goto bad;
    }
    if (value == Py_None)
        value = 0;
    if (PyExceptionInstance_Check(type)) {
        if (value) {
            PyErr_SetString(PyExc_TypeError,
                "instance exception may not have a separate value");
            goto bad;
        }
        value = type;
        type = (PyObject*) Py_TYPE(value);
    } else if (PyExceptionClass_Check(type)) {
        PyObject *args;
        if (!value)
            args = PyTuple_New(0);
        else if (PyTuple_Check(value)) {
            Py_INCREF(value);
            args = value;
        }
        else
            args = PyTuple_Pack(1, value);
        if (!args)
            goto bad;
        owned_instance = PyEval_CallObject(type, args);
        Py_DECREF(args);
        if (!owned_instance)
            goto bad;
        value = owned_instance;
        if (!PyExceptionInstance_Check(value)) {
            PyErr_Format(PyExc_TypeError,
                         "calling %R should have returned an instance of "
                         "BaseException, not %R",
                         type, Py_TYPE(value));
            goto bad;
        }
    } else {
        PyErr_SetString(PyExc_TypeError,
            "raise: exception class must be a subclass of BaseException");
        goto bad;
    }
    if (cause && cause != Py_None) {
        PyObject *fixed_cause;
        if (PyExceptionClass_Check(cause)) {
            fixed_cause = PyObject_CallObject(cause, NULL);
            if (fixed_cause == NULL)
                goto bad;
        }
        else if (PyExceptionInstance_Check(cause)) {
            fixed_cause = cause;
            Py_INCREF(fixed_cause);
        }
        else {
            PyErr_SetString(PyExc_TypeError,
                            "exception causes must derive from "
                            "BaseException");
            goto bad;
        }
        PyException_SetCause(value, fixed_cause);
    }
    PyErr_SetObject(type, value);
    if (tb) {
        PyThreadState *tstate = PyThreadState_GET();
        PyObject* tmp_tb = tstate->curexc_traceback;
        if (tb != tmp_tb) {
            Py_INCREF(tb);
            tstate->curexc_traceback = tb;
            Py_XDECREF(tmp_tb);
        }
    }
bad:
    Py_XDECREF(owned_instance);
    return;
}
#endif

static CYTHON_INLINE Py_ssize_t __Pyx_div_Py_ssize_t(Py_ssize_t a, Py_ssize_t b) {
    Py_ssize_t q = a / b;
    Py_ssize_t r = a - q*b;
    q -= ((r != 0) & ((r ^ b) < 0));
    return q;
}

static CYTHON_INLINE long __Pyx_div_long(long a, long b) {
    long q = a / b;
    long r = a - q*b;
    q -= ((r != 0) & ((r ^ b) < 0));
    return q;
}

static PyObject *__Pyx_Import(PyObject *name, PyObject *from_list, long level) {
    PyObject *py_import = 0;
    PyObject *empty_list = 0;
    PyObject *module = 0;
    PyObject *global_dict = 0;
    PyObject *empty_dict = 0;
    PyObject *list;
    py_import = __Pyx_GetAttrString(__pyx_b, "__import__");
    if (!py_import)
        goto bad;
    if (from_list)
        list = from_list;
    else {
        empty_list = PyList_New(0);
        if (!empty_list)
            goto bad;
        list = empty_list;
    }
    global_dict = PyModule_GetDict(__pyx_m);
    if (!global_dict)
        goto bad;
    empty_dict = PyDict_New();
    if (!empty_dict)
        goto bad;
    #if PY_VERSION_HEX >= 0x02050000
    {
        #if PY_MAJOR_VERSION >= 3
        if (level == -1) {
            if (strchr(__Pyx_MODULE_NAME, '.')) {
                /* try package relative import first */
                PyObject *py_level = PyInt_FromLong(1);
                if (!py_level)
                    goto bad;
                module = PyObject_CallFunctionObjArgs(py_import,
                    name, global_dict, empty_dict, list, py_level, NULL);
                Py_DECREF(py_level);
                if (!module) {
                    if (!PyErr_ExceptionMatches(PyExc_ImportError))
                        goto bad;
                    PyErr_Clear();
                }
            }
            level = 0; /* try absolute import on failure */
        }
        #endif
        if (!module) {
            PyObject *py_level = PyInt_FromLong(level);
            if (!py_level)
                goto bad;
            module = PyObject_CallFunctionObjArgs(py_import,
                name, global_dict, empty_dict, list, py_level, NULL);
            Py_DECREF(py_level);
        }
    }
    #else
    if (level>0) {
        PyErr_SetString(PyExc_RuntimeError, "Relative import is not supported for Python <=2.4.");
        goto bad;
    }
    module = PyObject_CallFunctionObjArgs(py_import,
        name, global_dict, empty_dict, list, NULL);
    #endif
bad:
    Py_XDECREF(empty_list);
    Py_XDECREF(py_import);
    Py_XDECREF(empty_dict);
    return module;
}

static CYTHON_INLINE PyObject *__Pyx_PyInt_to_py_int32_t(int32_t val) {
    const int32_t neg_one = (int32_t)-1, const_zero = (int32_t)0;
    const int is_unsigned = const_zero < neg_one;
    if ((sizeof(int32_t) == sizeof(char))  ||
        (sizeof(int32_t) == sizeof(short))) {
        return PyInt_FromLong((long)val);
    } else if ((sizeof(int32_t) == sizeof(int)) ||
               (sizeof(int32_t) == sizeof(long))) {
        if (is_unsigned)
            return PyLong_FromUnsignedLong((unsigned long)val);
        else
            return PyInt_FromLong((long)val);
    } else if (sizeof(int32_t) == sizeof(PY_LONG_LONG)) {
        if (is_unsigned)
            return PyLong_FromUnsignedLongLong((unsigned PY_LONG_LONG)val);
        else
            return PyLong_FromLongLong((PY_LONG_LONG)val);
    } else {
        int one = 1; int little = (int)*(unsigned char *)&one;
        unsigned char *bytes = (unsigned char *)&val;
        return _PyLong_FromByteArray(bytes, sizeof(int32_t),
                                     little, !is_unsigned);
    }
}

#if !CYTHON_COMPILING_IN_PYPY && PY_MAJOR_VERSION < 3
static PyObject *__Pyx_GetStdout(void) {
    PyObject *f = PySys_GetObject((char *)"stdout");
    if (!f) {
        PyErr_SetString(PyExc_RuntimeError, "lost sys.stdout");
    }
    return f;
}
static int __Pyx_Print(PyObject* f, PyObject *arg_tuple, int newline) {
    int i;
    if (!f) {
        if (!(f = __Pyx_GetStdout()))
            return -1;
    }
    Py_INCREF(f);
    for (i=0; i < PyTuple_GET_SIZE(arg_tuple); i++) {
        PyObject* v;
        if (PyFile_SoftSpace(f, 1)) {
            if (PyFile_WriteString(" ", f) < 0)
                goto error;
        }
        v = PyTuple_GET_ITEM(arg_tuple, i);
        if (PyFile_WriteObject(v, f, Py_PRINT_RAW) < 0)
            goto error;
        if (PyString_Check(v)) {
            char *s = PyString_AsString(v);
            Py_ssize_t len = PyString_Size(v);
            if (len > 0 &&
                isspace(Py_CHARMASK(s[len-1])) &&
                s[len-1] != ' ')
                    PyFile_SoftSpace(f, 0);
        }
    }
    if (newline) {
        if (PyFile_WriteString("\n", f) < 0)
            goto error;
        PyFile_SoftSpace(f, 0);
    }
    Py_DECREF(f);
    return 0;
error:
    Py_DECREF(f);
    return -1;
}
#else /* Python 3 has a print function */
static int __Pyx_Print(PyObject* stream, PyObject *arg_tuple, int newline) {
    PyObject* kwargs = 0;
    PyObject* result = 0;
    PyObject* end_string;
    if (unlikely(!__pyx_print)) {
        __pyx_print = __Pyx_GetAttrString(__pyx_b, "print");
        if (!__pyx_print)
            return -1;
    }
    if (stream) {
        kwargs = PyDict_New();
        if (unlikely(!kwargs))
            return -1;
        if (unlikely(PyDict_SetItemString(kwargs, "file", stream) < 0))
            goto bad;
        if (!newline) {
            end_string = PyUnicode_FromStringAndSize(" ", 1);
            if (unlikely(!end_string))
                goto bad;
            if (PyDict_SetItemString(kwargs, "end", end_string) < 0) {
                Py_DECREF(end_string);
                goto bad;
            }
            Py_DECREF(end_string);
        }
    } else if (!newline) {
        if (unlikely(!__pyx_print_kwargs)) {
            __pyx_print_kwargs = PyDict_New();
            if (unlikely(!__pyx_print_kwargs))
                return -1;
            end_string = PyUnicode_FromStringAndSize(" ", 1);
            if (unlikely(!end_string))
                return -1;
            if (PyDict_SetItemString(__pyx_print_kwargs, "end", end_string) < 0) {
                Py_DECREF(end_string);
                return -1;
            }
            Py_DECREF(end_string);
        }
        kwargs = __pyx_print_kwargs;
    }
    result = PyObject_Call(__pyx_print, arg_tuple, kwargs);
    if (unlikely(kwargs) && (kwargs != __pyx_print_kwargs))
        Py_DECREF(kwargs);
    if (!result)
        return -1;
    Py_DECREF(result);
    return 0;
bad:
    if (kwargs != __pyx_print_kwargs)
        Py_XDECREF(kwargs);
    return -1;
}
#endif

#if !CYTHON_COMPILING_IN_PYPY && PY_MAJOR_VERSION < 3
static int __Pyx_PrintOne(PyObject* f, PyObject *o) {
    if (!f) {
        if (!(f = __Pyx_GetStdout()))
            return -1;
    }
    Py_INCREF(f);
    if (PyFile_SoftSpace(f, 0)) {
        if (PyFile_WriteString(" ", f) < 0)
            goto error;
    }
    if (PyFile_WriteObject(o, f, Py_PRINT_RAW) < 0)
        goto error;
    if (PyFile_WriteString("\n", f) < 0)
        goto error;
    Py_DECREF(f);
    return 0;
error:
    Py_DECREF(f);
    return -1;
    /* the line below is just to avoid C compiler
     * warnings about unused functions */
    return __Pyx_Print(f, NULL, 0);
}
#else /* Python 3 has a print function */
static int __Pyx_PrintOne(PyObject* stream, PyObject *o) {
    int res;
    PyObject* arg_tuple = PyTuple_Pack(1, o);
    if (unlikely(!arg_tuple))
        return -1;
    res = __Pyx_Print(stream, arg_tuple, 1);
    Py_DECREF(arg_tuple);
    return res;
}
#endif

static CYTHON_INLINE unsigned char __Pyx_PyInt_AsUnsignedChar(PyObject* x) {
    const unsigned char neg_one = (unsigned char)-1, const_zero = 0;
    const int is_unsigned = neg_one > const_zero;
    if (sizeof(unsigned char) < sizeof(long)) {
        long val = __Pyx_PyInt_AsLong(x);
        if (unlikely(val != (long)(unsigned char)val)) {
            if (!unlikely(val == -1 && PyErr_Occurred())) {
                PyErr_SetString(PyExc_OverflowError,
                    (is_unsigned && unlikely(val < 0)) ?
                    "can't convert negative value to unsigned char" :
                    "value too large to convert to unsigned char");
            }
            return (unsigned char)-1;
        }
        return (unsigned char)val;
    }
    return (unsigned char)__Pyx_PyInt_AsUnsignedLong(x);
}

static CYTHON_INLINE unsigned short __Pyx_PyInt_AsUnsignedShort(PyObject* x) {
    const unsigned short neg_one = (unsigned short)-1, const_zero = 0;
    const int is_unsigned = neg_one > const_zero;
    if (sizeof(unsigned short) < sizeof(long)) {
        long val = __Pyx_PyInt_AsLong(x);
        if (unlikely(val != (long)(unsigned short)val)) {
            if (!unlikely(val == -1 && PyErr_Occurred())) {
                PyErr_SetString(PyExc_OverflowError,
                    (is_unsigned && unlikely(val < 0)) ?
                    "can't convert negative value to unsigned short" :
                    "value too large to convert to unsigned short");
            }
            return (unsigned short)-1;
        }
        return (unsigned short)val;
    }
    return (unsigned short)__Pyx_PyInt_AsUnsignedLong(x);
}

static CYTHON_INLINE unsigned int __Pyx_PyInt_AsUnsignedInt(PyObject* x) {
    const unsigned int neg_one = (unsigned int)-1, const_zero = 0;
    const int is_unsigned = neg_one > const_zero;
    if (sizeof(unsigned int) < sizeof(long)) {
        long val = __Pyx_PyInt_AsLong(x);
        if (unlikely(val != (long)(unsigned int)val)) {
            if (!unlikely(val == -1 && PyErr_Occurred())) {
                PyErr_SetString(PyExc_OverflowError,
                    (is_unsigned && unlikely(val < 0)) ?
                    "can't convert negative value to unsigned int" :
                    "value too large to convert to unsigned int");
            }
            return (unsigned int)-1;
        }
        return (unsigned int)val;
    }
    return (unsigned int)__Pyx_PyInt_AsUnsignedLong(x);
}

static CYTHON_INLINE char __Pyx_PyInt_AsChar(PyObject* x) {
    const char neg_one = (char)-1, const_zero = 0;
    const int is_unsigned = neg_one > const_zero;
    if (sizeof(char) < sizeof(long)) {
        long val = __Pyx_PyInt_AsLong(x);
        if (unlikely(val != (long)(char)val)) {
            if (!unlikely(val == -1 && PyErr_Occurred())) {
                PyErr_SetString(PyExc_OverflowError,
                    (is_unsigned && unlikely(val < 0)) ?
                    "can't convert negative value to char" :
                    "value too large to convert to char");
            }
            return (char)-1;
        }
        return (char)val;
    }
    return (char)__Pyx_PyInt_AsLong(x);
}

static CYTHON_INLINE short __Pyx_PyInt_AsShort(PyObject* x) {
    const short neg_one = (short)-1, const_zero = 0;
    const int is_unsigned = neg_one > const_zero;
    if (sizeof(short) < sizeof(long)) {
        long val = __Pyx_PyInt_AsLong(x);
        if (unlikely(val != (long)(short)val)) {
            if (!unlikely(val == -1 && PyErr_Occurred())) {
                PyErr_SetString(PyExc_OverflowError,
                    (is_unsigned && unlikely(val < 0)) ?
                    "can't convert negative value to short" :
                    "value too large to convert to short");
            }
            return (short)-1;
        }
        return (short)val;
    }
    return (short)__Pyx_PyInt_AsLong(x);
}

static CYTHON_INLINE int __Pyx_PyInt_AsInt(PyObject* x) {
    const int neg_one = (int)-1, const_zero = 0;
    const int is_unsigned = neg_one > const_zero;
    if (sizeof(int) < sizeof(long)) {
        long val = __Pyx_PyInt_AsLong(x);
        if (unlikely(val != (long)(int)val)) {
            if (!unlikely(val == -1 && PyErr_Occurred())) {
                PyErr_SetString(PyExc_OverflowError,
                    (is_unsigned && unlikely(val < 0)) ?
                    "can't convert negative value to int" :
                    "value too large to convert to int");
            }
            return (int)-1;
        }
        return (int)val;
    }
    return (int)__Pyx_PyInt_AsLong(x);
}

static CYTHON_INLINE signed char __Pyx_PyInt_AsSignedChar(PyObject* x) {
    const signed char neg_one = (signed char)-1, const_zero = 0;
    const int is_unsigned = neg_one > const_zero;
    if (sizeof(signed char) < sizeof(long)) {
        long val = __Pyx_PyInt_AsLong(x);
        if (unlikely(val != (long)(signed char)val)) {
            if (!unlikely(val == -1 && PyErr_Occurred())) {
                PyErr_SetString(PyExc_OverflowError,
                    (is_unsigned && unlikely(val < 0)) ?
                    "can't convert negative value to signed char" :
                    "value too large to convert to signed char");
            }
            return (signed char)-1;
        }
        return (signed char)val;
    }
    return (signed char)__Pyx_PyInt_AsSignedLong(x);
}

static CYTHON_INLINE signed short __Pyx_PyInt_AsSignedShort(PyObject* x) {
    const signed short neg_one = (signed short)-1, const_zero = 0;
    const int is_unsigned = neg_one > const_zero;
    if (sizeof(signed short) < sizeof(long)) {
        long val = __Pyx_PyInt_AsLong(x);
        if (unlikely(val != (long)(signed short)val)) {
            if (!unlikely(val == -1 && PyErr_Occurred())) {
                PyErr_SetString(PyExc_OverflowError,
                    (is_unsigned && unlikely(val < 0)) ?
                    "can't convert negative value to signed short" :
                    "value too large to convert to signed short");
            }
            return (signed short)-1;
        }
        return (signed short)val;
    }
    return (signed short)__Pyx_PyInt_AsSignedLong(x);
}

static CYTHON_INLINE signed int __Pyx_PyInt_AsSignedInt(PyObject* x) {
    const signed int neg_one = (signed int)-1, const_zero = 0;
    const int is_unsigned = neg_one > const_zero;
    if (sizeof(signed int) < sizeof(long)) {
        long val = __Pyx_PyInt_AsLong(x);
        if (unlikely(val != (long)(signed int)val)) {
            if (!unlikely(val == -1 && PyErr_Occurred())) {
                PyErr_SetString(PyExc_OverflowError,
                    (is_unsigned && unlikely(val < 0)) ?
                    "can't convert negative value to signed int" :
                    "value too large to convert to signed int");
            }
            return (signed int)-1;
        }
        return (signed int)val;
    }
    return (signed int)__Pyx_PyInt_AsSignedLong(x);
}

static CYTHON_INLINE int __Pyx_PyInt_AsLongDouble(PyObject* x) {
    const int neg_one = (int)-1, const_zero = 0;
    const int is_unsigned = neg_one > const_zero;
    if (sizeof(int) < sizeof(long)) {
        long val = __Pyx_PyInt_AsLong(x);
        if (unlikely(val != (long)(int)val)) {
            if (!unlikely(val == -1 && PyErr_Occurred())) {
                PyErr_SetString(PyExc_OverflowError,
                    (is_unsigned && unlikely(val < 0)) ?
                    "can't convert negative value to int" :
                    "value too large to convert to int");
            }
            return (int)-1;
        }
        return (int)val;
    }
    return (int)__Pyx_PyInt_AsLong(x);
}

static CYTHON_INLINE unsigned long __Pyx_PyInt_AsUnsignedLong(PyObject* x) {
    const unsigned long neg_one = (unsigned long)-1, const_zero = 0;
    const int is_unsigned = neg_one > const_zero;
#if PY_VERSION_HEX < 0x03000000
    if (likely(PyInt_Check(x))) {
        long val = PyInt_AS_LONG(x);
        if (is_unsigned && unlikely(val < 0)) {
            PyErr_SetString(PyExc_OverflowError,
                            "can't convert negative value to unsigned long");
            return (unsigned long)-1;
        }
        return (unsigned long)val;
    } else
#endif
    if (likely(PyLong_Check(x))) {
        if (is_unsigned) {
            if (unlikely(Py_SIZE(x) < 0)) {
                PyErr_SetString(PyExc_OverflowError,
                                "can't convert negative value to unsigned long");
                return (unsigned long)-1;
            }
            return (unsigned long)PyLong_AsUnsignedLong(x);
        } else {
            return (unsigned long)PyLong_AsLong(x);
        }
    } else {
        unsigned long val;
        PyObject *tmp = __Pyx_PyNumber_Int(x);
        if (!tmp) return (unsigned long)-1;
        val = __Pyx_PyInt_AsUnsignedLong(tmp);
        Py_DECREF(tmp);
        return val;
    }
}

static CYTHON_INLINE unsigned PY_LONG_LONG __Pyx_PyInt_AsUnsignedLongLong(PyObject* x) {
    const unsigned PY_LONG_LONG neg_one = (unsigned PY_LONG_LONG)-1, const_zero = 0;
    const int is_unsigned = neg_one > const_zero;
#if PY_VERSION_HEX < 0x03000000
    if (likely(PyInt_Check(x))) {
        long val = PyInt_AS_LONG(x);
        if (is_unsigned && unlikely(val < 0)) {
            PyErr_SetString(PyExc_OverflowError,
                            "can't convert negative value to unsigned PY_LONG_LONG");
            return (unsigned PY_LONG_LONG)-1;
        }
        return (unsigned PY_LONG_LONG)val;
    } else
#endif
    if (likely(PyLong_Check(x))) {
        if (is_unsigned) {
            if (unlikely(Py_SIZE(x) < 0)) {
                PyErr_SetString(PyExc_OverflowError,
                                "can't convert negative value to unsigned PY_LONG_LONG");
                return (unsigned PY_LONG_LONG)-1;
            }
            return (unsigned PY_LONG_LONG)PyLong_AsUnsignedLongLong(x);
        } else {
            return (unsigned PY_LONG_LONG)PyLong_AsLongLong(x);
        }
    } else {
        unsigned PY_LONG_LONG val;
        PyObject *tmp = __Pyx_PyNumber_Int(x);
        if (!tmp) return (unsigned PY_LONG_LONG)-1;
        val = __Pyx_PyInt_AsUnsignedLongLong(tmp);
        Py_DECREF(tmp);
        return val;
    }
}

static CYTHON_INLINE long __Pyx_PyInt_AsLong(PyObject* x) {
    const long neg_one = (long)-1, const_zero = 0;
    const int is_unsigned = neg_one > const_zero;
#if PY_VERSION_HEX < 0x03000000
    if (likely(PyInt_Check(x))) {
        long val = PyInt_AS_LONG(x);
        if (is_unsigned && unlikely(val < 0)) {
            PyErr_SetString(PyExc_OverflowError,
                            "can't convert negative value to long");
            return (long)-1;
        }
        return (long)val;
    } else
#endif
    if (likely(PyLong_Check(x))) {
        if (is_unsigned) {
            if (unlikely(Py_SIZE(x) < 0)) {
                PyErr_SetString(PyExc_OverflowError,
                                "can't convert negative value to long");
                return (long)-1;
            }
            return (long)PyLong_AsUnsignedLong(x);
        } else {
            return (long)PyLong_AsLong(x);
        }
    } else {
        long val;
        PyObject *tmp = __Pyx_PyNumber_Int(x);
        if (!tmp) return (long)-1;
        val = __Pyx_PyInt_AsLong(tmp);
        Py_DECREF(tmp);
        return val;
    }
}

static CYTHON_INLINE PY_LONG_LONG __Pyx_PyInt_AsLongLong(PyObject* x) {
    const PY_LONG_LONG neg_one = (PY_LONG_LONG)-1, const_zero = 0;
    const int is_unsigned = neg_one > const_zero;
#if PY_VERSION_HEX < 0x03000000
    if (likely(PyInt_Check(x))) {
        long val = PyInt_AS_LONG(x);
        if (is_unsigned && unlikely(val < 0)) {
            PyErr_SetString(PyExc_OverflowError,
                            "can't convert negative value to PY_LONG_LONG");
            return (PY_LONG_LONG)-1;
        }
        return (PY_LONG_LONG)val;
    } else
#endif
    if (likely(PyLong_Check(x))) {
        if (is_unsigned) {
            if (unlikely(Py_SIZE(x) < 0)) {
                PyErr_SetString(PyExc_OverflowError,
                                "can't convert negative value to PY_LONG_LONG");
                return (PY_LONG_LONG)-1;
            }
            return (PY_LONG_LONG)PyLong_AsUnsignedLongLong(x);
        } else {
            return (PY_LONG_LONG)PyLong_AsLongLong(x);
        }
    } else {
        PY_LONG_LONG val;
        PyObject *tmp = __Pyx_PyNumber_Int(x);
        if (!tmp) return (PY_LONG_LONG)-1;
        val = __Pyx_PyInt_AsLongLong(tmp);
        Py_DECREF(tmp);
        return val;
    }
}

static CYTHON_INLINE signed long __Pyx_PyInt_AsSignedLong(PyObject* x) {
    const signed long neg_one = (signed long)-1, const_zero = 0;
    const int is_unsigned = neg_one > const_zero;
#if PY_VERSION_HEX < 0x03000000
    if (likely(PyInt_Check(x))) {
        long val = PyInt_AS_LONG(x);
        if (is_unsigned && unlikely(val < 0)) {
            PyErr_SetString(PyExc_OverflowError,
                            "can't convert negative value to signed long");
            return (signed long)-1;
        }
        return (signed long)val;
    } else
#endif
    if (likely(PyLong_Check(x))) {
        if (is_unsigned) {
            if (unlikely(Py_SIZE(x) < 0)) {
                PyErr_SetString(PyExc_OverflowError,
                                "can't convert negative value to signed long");
                return (signed long)-1;
            }
            return (signed long)PyLong_AsUnsignedLong(x);
        } else {
            return (signed long)PyLong_AsLong(x);
        }
    } else {
        signed long val;
        PyObject *tmp = __Pyx_PyNumber_Int(x);
        if (!tmp) return (signed long)-1;
        val = __Pyx_PyInt_AsSignedLong(tmp);
        Py_DECREF(tmp);
        return val;
    }
}

static CYTHON_INLINE signed PY_LONG_LONG __Pyx_PyInt_AsSignedLongLong(PyObject* x) {
    const signed PY_LONG_LONG neg_one = (signed PY_LONG_LONG)-1, const_zero = 0;
    const int is_unsigned = neg_one > const_zero;
#if PY_VERSION_HEX < 0x03000000
    if (likely(PyInt_Check(x))) {
        long val = PyInt_AS_LONG(x);
        if (is_unsigned && unlikely(val < 0)) {
            PyErr_SetString(PyExc_OverflowError,
                            "can't convert negative value to signed PY_LONG_LONG");
            return (signed PY_LONG_LONG)-1;
        }
        return (signed PY_LONG_LONG)val;
    } else
#endif
    if (likely(PyLong_Check(x))) {
        if (is_unsigned) {
            if (unlikely(Py_SIZE(x) < 0)) {
                PyErr_SetString(PyExc_OverflowError,
                                "can't convert negative value to signed PY_LONG_LONG");
                return (signed PY_LONG_LONG)-1;
            }
            return (signed PY_LONG_LONG)PyLong_AsUnsignedLongLong(x);
        } else {
            return (signed PY_LONG_LONG)PyLong_AsLongLong(x);
        }
    } else {
        signed PY_LONG_LONG val;
        PyObject *tmp = __Pyx_PyNumber_Int(x);
        if (!tmp) return (signed PY_LONG_LONG)-1;
        val = __Pyx_PyInt_AsSignedLongLong(tmp);
        Py_DECREF(tmp);
        return val;
    }
}

static int __Pyx_check_binary_version(void) {
    char ctversion[4], rtversion[4];
    PyOS_snprintf(ctversion, 4, "%d.%d", PY_MAJOR_VERSION, PY_MINOR_VERSION);
    PyOS_snprintf(rtversion, 4, "%s", Py_GetVersion());
    if (ctversion[0] != rtversion[0] || ctversion[2] != rtversion[2]) {
        char message[200];
        PyOS_snprintf(message, sizeof(message),
                      "compiletime version %s of module '%.100s' "
                      "does not match runtime version %s",
                      ctversion, __Pyx_MODULE_NAME, rtversion);
        #if PY_VERSION_HEX < 0x02050000
        return PyErr_Warn(NULL, message);
        #else
        return PyErr_WarnEx(NULL, message, 1);
        #endif
    }
    return 0;
}

static int __pyx_bisect_code_objects(__Pyx_CodeObjectCacheEntry* entries, int count, int code_line) {
    int start = 0, mid = 0, end = count - 1;
    if (end >= 0 && code_line > entries[end].code_line) {
        return count;
    }
    while (start < end) {
        mid = (start + end) / 2;
        if (code_line < entries[mid].code_line) {
            end = mid;
        } else if (code_line > entries[mid].code_line) {
             start = mid + 1;
        } else {
            return mid;
        }
    }
    if (code_line <= entries[mid].code_line) {
        return mid;
    } else {
        return mid + 1;
    }
}
static PyCodeObject *__pyx_find_code_object(int code_line) {
    PyCodeObject* code_object;
    int pos;
    if (unlikely(!code_line) || unlikely(!__pyx_code_cache.entries)) {
        return NULL;
    }
    pos = __pyx_bisect_code_objects(__pyx_code_cache.entries, __pyx_code_cache.count, code_line);
    if (unlikely(pos >= __pyx_code_cache.count) || unlikely(__pyx_code_cache.entries[pos].code_line != code_line)) {
        return NULL;
    }
    code_object = __pyx_code_cache.entries[pos].code_object;
    Py_INCREF(code_object);
    return code_object;
}
static void __pyx_insert_code_object(int code_line, PyCodeObject* code_object) {
    int pos, i;
    __Pyx_CodeObjectCacheEntry* entries = __pyx_code_cache.entries;
    if (unlikely(!code_line)) {
        return;
    }
    if (unlikely(!entries)) {
        entries = (__Pyx_CodeObjectCacheEntry*)PyMem_Malloc(64*sizeof(__Pyx_CodeObjectCacheEntry));
        if (likely(entries)) {
            __pyx_code_cache.entries = entries;
            __pyx_code_cache.max_count = 64;
            __pyx_code_cache.count = 1;
            entries[0].code_line = code_line;
            entries[0].code_object = code_object;
            Py_INCREF(code_object);
        }
        return;
    }
    pos = __pyx_bisect_code_objects(__pyx_code_cache.entries, __pyx_code_cache.count, code_line);
    if ((pos < __pyx_code_cache.count) && unlikely(__pyx_code_cache.entries[pos].code_line == code_line)) {
        PyCodeObject* tmp = entries[pos].code_object;
        entries[pos].code_object = code_object;
        Py_DECREF(tmp);
        return;
    }
    if (__pyx_code_cache.count == __pyx_code_cache.max_count) {
        int new_max = __pyx_code_cache.max_count + 64;
        entries = (__Pyx_CodeObjectCacheEntry*)PyMem_Realloc(
            __pyx_code_cache.entries, new_max*sizeof(__Pyx_CodeObjectCacheEntry));
        if (unlikely(!entries)) {
            return;
        }
        __pyx_code_cache.entries = entries;
        __pyx_code_cache.max_count = new_max;
    }
    for (i=__pyx_code_cache.count; i>pos; i--) {
        entries[i] = entries[i-1];
    }
    entries[pos].code_line = code_line;
    entries[pos].code_object = code_object;
    __pyx_code_cache.count++;
    Py_INCREF(code_object);
}

#include "compile.h"
#include "frameobject.h"
#include "traceback.h"
static PyCodeObject* __Pyx_CreateCodeObjectForTraceback(
            const char *funcname, int c_line,
            int py_line, const char *filename) {
    PyCodeObject *py_code = 0;
    PyObject *py_srcfile = 0;
    PyObject *py_funcname = 0;
    #if PY_MAJOR_VERSION < 3
    py_srcfile = PyString_FromString(filename);
    #else
    py_srcfile = PyUnicode_FromString(filename);
    #endif
    if (!py_srcfile) goto bad;
    if (c_line) {
        #if PY_MAJOR_VERSION < 3
        py_funcname = PyString_FromFormat( "%s (%s:%d)", funcname, __pyx_cfilenm, c_line);
        #else
        py_funcname = PyUnicode_FromFormat( "%s (%s:%d)", funcname, __pyx_cfilenm, c_line);
        #endif
    }
    else {
        #if PY_MAJOR_VERSION < 3
        py_funcname = PyString_FromString(funcname);
        #else
        py_funcname = PyUnicode_FromString(funcname);
        #endif
    }
    if (!py_funcname) goto bad;
    py_code = __Pyx_PyCode_New(
        0,            /*int argcount,*/
        0,            /*int kwonlyargcount,*/
        0,            /*int nlocals,*/
        0,            /*int stacksize,*/
        0,            /*int flags,*/
        __pyx_empty_bytes, /*PyObject *code,*/
        __pyx_empty_tuple, /*PyObject *consts,*/
        __pyx_empty_tuple, /*PyObject *names,*/
        __pyx_empty_tuple, /*PyObject *varnames,*/
        __pyx_empty_tuple, /*PyObject *freevars,*/
        __pyx_empty_tuple, /*PyObject *cellvars,*/
        py_srcfile,   /*PyObject *filename,*/
        py_funcname,  /*PyObject *name,*/
        py_line,      /*int firstlineno,*/
        __pyx_empty_bytes  /*PyObject *lnotab*/
    );
    Py_DECREF(py_srcfile);
    Py_DECREF(py_funcname);
    return py_code;
bad:
    Py_XDECREF(py_srcfile);
    Py_XDECREF(py_funcname);
    return NULL;
}
static void __Pyx_AddTraceback(const char *funcname, int c_line,
                               int py_line, const char *filename) {
    PyCodeObject *py_code = 0;
    PyObject *py_globals = 0;
    PyFrameObject *py_frame = 0;
    py_code = __pyx_find_code_object(c_line ? c_line : py_line);
    if (!py_code) {
        py_code = __Pyx_CreateCodeObjectForTraceback(
            funcname, c_line, py_line, filename);
        if (!py_code) goto bad;
        __pyx_insert_code_object(c_line ? c_line : py_line, py_code);
    }
    py_globals = PyModule_GetDict(__pyx_m);
    if (!py_globals) goto bad;
    py_frame = PyFrame_New(
        PyThreadState_GET(), /*PyThreadState *tstate,*/
        py_code,             /*PyCodeObject *code,*/
        py_globals,          /*PyObject *globals,*/
        0                    /*PyObject *locals*/
    );
    if (!py_frame) goto bad;
    py_frame->f_lineno = py_line;
    PyTraceBack_Here(py_frame);
bad:
    Py_XDECREF(py_code);
    Py_XDECREF(py_frame);
}

static int __Pyx_InitStrings(__Pyx_StringTabEntry *t) {
    while (t->p) {
        #if PY_MAJOR_VERSION < 3
        if (t->is_unicode) {
            *t->p = PyUnicode_DecodeUTF8(t->s, t->n - 1, NULL);
        } else if (t->intern) {
            *t->p = PyString_InternFromString(t->s);
        } else {
            *t->p = PyString_FromStringAndSize(t->s, t->n - 1);
        }
        #else  /* Python 3+ has unicode identifiers */
        if (t->is_unicode | t->is_str) {
            if (t->intern) {
                *t->p = PyUnicode_InternFromString(t->s);
            } else if (t->encoding) {
                *t->p = PyUnicode_Decode(t->s, t->n - 1, t->encoding, NULL);
            } else {
                *t->p = PyUnicode_FromStringAndSize(t->s, t->n - 1);
            }
        } else {
            *t->p = PyBytes_FromStringAndSize(t->s, t->n - 1);
        }
        #endif
        if (!*t->p)
            return -1;
        ++t;
    }
    return 0;
}


/* Type Conversion Functions */

static CYTHON_INLINE int __Pyx_PyObject_IsTrue(PyObject* x) {
   int is_true = x == Py_True;
   if (is_true | (x == Py_False) | (x == Py_None)) return is_true;
   else return PyObject_IsTrue(x);
}

static CYTHON_INLINE PyObject* __Pyx_PyNumber_Int(PyObject* x) {
  PyNumberMethods *m;
  const char *name = NULL;
  PyObject *res = NULL;
#if PY_VERSION_HEX < 0x03000000
  if (PyInt_Check(x) || PyLong_Check(x))
#else
  if (PyLong_Check(x))
#endif
    return Py_INCREF(x), x;
  m = Py_TYPE(x)->tp_as_number;
#if PY_VERSION_HEX < 0x03000000
  if (m && m->nb_int) {
    name = "int";
    res = PyNumber_Int(x);
  }
  else if (m && m->nb_long) {
    name = "long";
    res = PyNumber_Long(x);
  }
#else
  if (m && m->nb_int) {
    name = "int";
    res = PyNumber_Long(x);
  }
#endif
  if (res) {
#if PY_VERSION_HEX < 0x03000000
    if (!PyInt_Check(res) && !PyLong_Check(res)) {
#else
    if (!PyLong_Check(res)) {
#endif
      PyErr_Format(PyExc_TypeError,
                   "__%s__ returned non-%s (type %.200s)",
                   name, name, Py_TYPE(res)->tp_name);
      Py_DECREF(res);
      return NULL;
    }
  }
  else if (!PyErr_Occurred()) {
    PyErr_SetString(PyExc_TypeError,
                    "an integer is required");
  }
  return res;
}

static CYTHON_INLINE Py_ssize_t __Pyx_PyIndex_AsSsize_t(PyObject* b) {
  Py_ssize_t ival;
  PyObject* x = PyNumber_Index(b);
  if (!x) return -1;
  ival = PyInt_AsSsize_t(x);
  Py_DECREF(x);
  return ival;
}

static CYTHON_INLINE PyObject * __Pyx_PyInt_FromSize_t(size_t ival) {
#if PY_VERSION_HEX < 0x02050000
   if (ival <= LONG_MAX)
       return PyInt_FromLong((long)ival);
   else {
       unsigned char *bytes = (unsigned char *) &ival;
       int one = 1; int little = (int)*(unsigned char*)&one;
       return _PyLong_FromByteArray(bytes, sizeof(size_t), little, 0);
   }
#else
   return PyInt_FromSize_t(ival);
#endif
}

static CYTHON_INLINE size_t __Pyx_PyInt_AsSize_t(PyObject* x) {
   unsigned PY_LONG_LONG val = __Pyx_PyInt_AsUnsignedLongLong(x);
   if (unlikely(val == (unsigned PY_LONG_LONG)-1 && PyErr_Occurred())) {
       return (size_t)-1;
   } else if (unlikely(val != (unsigned PY_LONG_LONG)(size_t)val)) {
       PyErr_SetString(PyExc_OverflowError,
                       "value too large to convert to size_t");
       return (size_t)-1;
   }
   return (size_t)val;
}


#endif /* Py_PYTHON_H */
