[eccodes] 15/106: Port grib-api patches to eccodes

Alastair McKinstry mckinstry at moszumanska.debian.org
Fri Jul 28 09:05:01 UTC 2017


This is an automated email from the git hooks/post-receive script.

mckinstry pushed a commit to branch debian/master
in repository eccodes.

commit d0fe6c8d31246c8fc14e5ac36a0d098e7863de14
Author: Alastair McKinstry <mckinstry at debian.org>
Date:   Wed Jul 27 00:16:53 2016 +0100

    Port grib-api patches to eccodes
---
 debian/patches/disable-download-tests.patch |   50 +
 debian/patches/disable-tests.patch          |   17 +
 debian/patches/download.patch               |   22 +
 debian/patches/grib_bits.diff               |   77 +
 debian/patches/hurd.patch                   |   47 +
 debian/patches/numpy-fixes.patch            | 2673 +++++++++++++++++++++++++++
 debian/patches/openjpeg2.patch              |  379 ++++
 debian/patches/py3-fixes.patch              |  142 ++
 debian/patches/python3.patch                |  595 ++++++
 debian/patches/reproducible.patch           |  116 ++
 debian/patches/series                       |   10 +
 debian/patches/static-fix.patch             |  309 ++++
 debian/patches/static-libs.patch            |   60 +
 13 files changed, 4497 insertions(+)

diff --git a/debian/patches/disable-download-tests.patch b/debian/patches/disable-download-tests.patch
new file mode 100644
index 0000000..0e12da7
--- /dev/null
+++ b/debian/patches/disable-download-tests.patch
@@ -0,0 +1,50 @@
+Author: Alastair McKinstry <mckinstry at debian.org>
+Description: Disable downloading grib files; already present
+Last-Updated: 2016-04-27
+Forwarded: not-needed
+
+Index: eccodes-0.16.0/tests/CMakeLists.txt
+===================================================================
+--- eccodes-0.16.0.orig/tests/CMakeLists.txt
++++ eccodes-0.16.0/tests/CMakeLists.txt
+@@ -116,7 +116,7 @@ foreach( test ${tests2} )
+                   TYPE SCRIPT
+                   COMMAND ${CMAKE_CURRENT_SOURCE_DIR}/${test}.sh
+                   RESOURCES asca_139.t1.ref
+-                  TEST_DEPENDS eccodes_get_gribs eccodes_get_tigge_gribs eccodes_get_bufrs eccodes_get_metars eccodes_get_gts
++                  # TEST_DEPENDS eccodes_get_gribs eccodes_get_tigge_gribs eccodes_get_bufrs eccodes_get_metars eccodes_get_gts
+     )
+ endforeach()
+ 
+@@ -126,7 +126,7 @@ ecbuild_add_test( TARGET eccodes_t_lamb_
+                   TYPE SCRIPT
+                   COMMAND ${CMAKE_CURRENT_SOURCE_DIR}/lamb_az_eq_area.sh
+                   RESOURCES lamb_az_eq_area.ref
+-                  TEST_DEPENDS eccodes_get_gribs
++                  # TEST_DEPENDS eccodes_get_gribs
+ )
+ 
+ # These ones are conditional
+@@ -134,19 +134,19 @@ ecbuild_add_test( TARGET eccodes_t_grib_
+                   TYPE SCRIPT
+                   CONDITION HAVE_NETCDF
+                   COMMAND ${CMAKE_CURRENT_SOURCE_DIR}/grib_to_netcdf.sh
+-                  TEST_DEPENDS eccodes_get_gribs
++                  # TEST_DEPENDS eccodes_get_gribs
+ )
+ 
+ ecbuild_add_test( TARGET eccodes_t_jpeg
+                   TYPE SCRIPT
+                   CONDITION HAVE_JPEG
+                   COMMAND ${CMAKE_CURRENT_SOURCE_DIR}/jpeg.sh
+-                  TEST_DEPENDS eccodes_get_gribs
++                  # TEST_DEPENDS eccodes_get_gribs
+ )
+ 
+ ecbuild_add_test( TARGET eccodes_t_ccsds
+                   TYPE SCRIPT
+                   CONDITION HAVE_AEC
+                   COMMAND ${CMAKE_CURRENT_SOURCE_DIR}/ccsds.sh
+-                  TEST_DEPENDS eccodes_get_gribs
++                  # TEST_DEPENDS eccodes_get_gribs
+ )
diff --git a/debian/patches/disable-tests.patch b/debian/patches/disable-tests.patch
new file mode 100644
index 0000000..079edef
--- /dev/null
+++ b/debian/patches/disable-tests.patch
@@ -0,0 +1,17 @@
+Author: Alastair McKinstry <mckinstry at debian.org>
+Description: Disable known failures
+Last-Updated: 2016-02-05
+Forwarded: no
+
+Index: grib-api-1.14.7/tests/CMakeLists.txt
+===================================================================
+--- grib-api-1.14.7.orig/tests/CMakeLists.txt
++++ grib-api-1.14.7/tests/CMakeLists.txt
+@@ -37,7 +37,6 @@ list( APPEND tests2
+     grib1to2
+     grib2to1
+     badgrib
+-    ls
+     filter
+     multi
+     budg
diff --git a/debian/patches/download.patch b/debian/patches/download.patch
new file mode 100644
index 0000000..98c605e
--- /dev/null
+++ b/debian/patches/download.patch
@@ -0,0 +1,22 @@
+Index: grib-api-1.16.0/data/CMakeLists.txt
+===================================================================
+--- grib-api-1.16.0.orig/data/CMakeLists.txt
++++ grib-api-1.16.0/data/CMakeLists.txt
+@@ -13,7 +13,6 @@ endif()
+ # Download all data files doing md5 check on each
+ ecbuild_get_test_multidata( TARGET grib_api_download_gribs
+                             NAMES ${files_to_download} )
+-set_property( TEST grib_api_download_gribs APPEND PROPERTY LABELS download_data )
+ 
+ # Copy other files - e.g. reference data, text files etc from the source data dir
+ LIST(APPEND other_files
+Index: grib-api-1.16.0/data/tigge/CMakeLists.txt
+===================================================================
+--- grib-api-1.16.0.orig/data/tigge/CMakeLists.txt
++++ grib-api-1.16.0/data/tigge/CMakeLists.txt
+@@ -7,4 +7,4 @@ string(REGEX REPLACE "\n" ";" tigge_file
+ # Download all data files doing md5 check on each
+ ecbuild_get_test_multidata( TARGET grib_api_download_tigge_gribs
+                             NAMES ${tigge_files_to_download} )
+-set_property( TEST grib_api_download_tigge_gribs APPEND PROPERTY LABELS download_data )
++
diff --git a/debian/patches/grib_bits.diff b/debian/patches/grib_bits.diff
new file mode 100644
index 0000000..083a55f
--- /dev/null
+++ b/debian/patches/grib_bits.diff
@@ -0,0 +1,77 @@
+From: Dragoslav Sicarov <Dragoslav.Sicarov at imgtec.com>
+Subject: FTBFS: grib-api - tests fail for mips
+Date: Sun, 29 Dec 2013 15:13:16 +0000
+Forwarded: https://software.ecmwf.int/issues/browse/SUP-1589
+Last-Updated: 2016-07-27
+
+https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=733510
+
+FTBFS: 21 of 38 tests fail when trying to build package from source on
+mips. Part of build log has been attached.
+
+The root cause of failing tests for mips is in function
+grib_encode_unsigned_long() that is used for writing into grib message
+buffer (function is implemented differently for big-endian and
+little-endian architectures).
+
+On big-endian architectures, function uses shift operations, where in
+some corner-case situations left operand (which is of type unsigned
+long; size of long equals 4 bytes for 32bit system) is shifted right by
+32 bits.
+
+According to C standard, if the value of the right operand of shift
+operation is negative, or is greater than or equal to the width of the
+left operand, the behaviour is undefined.
+
+On 32-bit mips architecture shift operations by a variable number of
+bits are translated to/use 'srlv' and 'sllv' instructions which shift
+left operand by (right_operand mod 32) bits. In case of shifting by 32
+bits, this results in left operand being unchanged. However, in order
+for this package to function properly a result of 0 is expected.
+
+Proposed patch fixes these corner-cases by setting the result of shift
+operation to 0 if right operand is greater than or equal to size of long
+(actually, no shifting is performed, the result is set to zero).
+
+Index: eccodes-0.16.0/src/grib_bits.c
+===================================================================
+--- eccodes-0.16.0.orig/src/grib_bits.c
++++ eccodes-0.16.0/src/grib_bits.c
+@@ -24,12 +24,11 @@
+ long GRIB_MASK = -1;       /* Mask of sword bits */
+ 
+ # define VALUE(p,q,b) \
+- (((b)==max_nbits ? GRIB_MASK : ~(GRIB_MASK<<(b))) & ((p)>>(max_nbits-((q)+(b)))))
++(((b)==max_nbits ? GRIB_MASK : ~(GRIB_MASK<<(b))) & (((max_nbits-((q)+(b))) >= max_nbits) ? 0 : ((p)>>(max_nbits-((q)+(b))))))
+ 
+ # define MASKVALUE(q,b) \
+  ((b)==max_nbits ? GRIB_MASK : (~(GRIB_MASK<<(b))<<(max_nbits-((q)+(b)))))
+ 
+-
+ static unsigned long dmasks[] = { 0xFF, 0xFE, 0xFC, 0xF8, 0xF0, 0xE0, 0xC0, 0x80, 0x00, };
+ 
+ static int max_nbits = sizeof(unsigned long)*8;
+Index: eccodes-0.16.0/src/grib_bits_fast_big_endian.c
+===================================================================
+--- eccodes-0.16.0.orig/src/grib_bits_fast_big_endian.c
++++ eccodes-0.16.0/src/grib_bits_fast_big_endian.c
+@@ -123,9 +123,16 @@ int grib_encode_unsigned_long(unsigned c
+     countOfLeftmostBits = max_nbits - startBit;
+     startBit = max_nbits - remainingBits;
+     remainingBits -= countOfLeftmostBits;
+-    destination[nextWord] =
+-      ((destination[nextWord] >> countOfLeftmostBits) << countOfLeftmostBits)
+-      + (VALUE(val,startBit,countOfLeftmostBits));
++    if (countOfLeftmostBits < max_nbits)
++    {
++      destination[nextWord] =
++        ((destination[nextWord] >> countOfLeftmostBits) << countOfLeftmostBits)
++          + (VALUE(val,startBit,countOfLeftmostBits));
++    }
++    else
++    {
++      destination[nextWord] = (VALUE(val,startBit,countOfLeftmostBits));
++    }
+     startBit = 0;
+     nextWord++;
+   }
diff --git a/debian/patches/hurd.patch b/debian/patches/hurd.patch
new file mode 100644
index 0000000..abae3cf
--- /dev/null
+++ b/debian/patches/hurd.patch
@@ -0,0 +1,47 @@
+Author: Alastair McKinstry <mckinstry at debian.org>
+Description: Fix for GNU/Hurd
+Last-Updated: 2016-04-27
+Forwarded: https://software.ecmwf.int/issues/browse/SUP-1588
+
+Index: eccodes-0.16.0/src/grib_api_internal.h
+===================================================================
+--- eccodes-0.16.0.orig/src/grib_api_internal.h
++++ eccodes-0.16.0/src/grib_api_internal.h
+@@ -21,6 +21,7 @@
+ extern "C" {
+ #endif
+ 
++
+ /* cmake config header */
+ #ifdef HAVE_ECCODES_CONFIG_H 
+ #include "eccodes_config.h"
+@@ -172,11 +173,15 @@ extern "C" {
+ #endif
+ 
+ /* Compile time assertion - Thanks to Ralf Holly */
++#ifdef __GNU__
++#define COMPILE_TIME_ASSERT(condition)				\
++     extern int compile_time_assert[!!(condition) - 1]
++#else
+ #define COMPILE_TIME_ASSERT(e) \
+    do { \
+        enum { assert_static__ = 1/(e) }; \
+       } while (0)
+-
++#endif
+ 
+ #ifndef NDEBUG
+  #define DebugAssertAccess(array, index, size) \
+Index: eccodes-0.16.0/tools/grib_tools.h
+===================================================================
+--- eccodes-0.16.0.orig/tools/grib_tools.h
++++ eccodes-0.16.0/tools/grib_tools.h
+@@ -8,6 +8,8 @@
+  * virtue of its status as an intergovernmental organisation nor does it submit to any jurisdiction.
+  */
+ 
++#define _FILE_OFFSET_BITS 64 /* 64-bit offsets off_t not the default on Hurd/i386 */
++
+ #include "grib_api_internal.h"
+ #include <stdio.h>
+ #ifndef ECCODES_ON_WINDOWS
diff --git a/debian/patches/numpy-fixes.patch b/debian/patches/numpy-fixes.patch
new file mode 100644
index 0000000..d3a7b98
--- /dev/null
+++ b/debian/patches/numpy-fixes.patch
@@ -0,0 +1,2673 @@
+Author: Alastair McKinstry <mckinstry at debian.org>
+Description: Update the numpy.i from a copy in numpy.git to add
+ python3 support
+Last-Updated: 2016-06-12
+Forwarded: no
+
+Index: eccodes-0.16.0/python/numpy.i
+===================================================================
+--- eccodes-0.16.0.orig/python/numpy.i
++++ eccodes-0.16.0/python/numpy.i
+@@ -1,11 +1,46 @@
+ /* -*- C -*-  (not really, but good for syntax highlighting) */
++
++/*
++ * Copyright (c) 2005-2015, NumPy Developers.
++ * All rights reserved.
++ *
++ * Redistribution and use in source and binary forms, with or without
++ * modification, are permitted provided that the following conditions are
++ * met:
++ *
++ *     * Redistributions of source code must retain the above copyright
++ *        notice, this list of conditions and the following disclaimer.
++ *
++ *     * Redistributions in binary form must reproduce the above
++ *        copyright notice, this list of conditions and the following
++ *        disclaimer in the documentation and/or other materials provided
++ *        with the distribution.
++ *
++ *     * Neither the name of the NumPy Developers nor the names of any
++ *        contributors may be used to endorse or promote products derived
++ *        from this software without specific prior written permission.
++ *
++ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
++ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
++ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
++ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
++ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
++ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
++ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
++ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
++ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
++ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
++ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
++ */
++
+ #ifdef SWIGPYTHON
+ 
+ %{
+ #ifndef SWIG_FILE_WITH_INIT
+-#  define NO_IMPORT_ARRAY
++#define NO_IMPORT_ARRAY
+ #endif
+ #include "stdio.h"
++#define NPY_NO_DEPRECATED_API NPY_1_7_API_VERSION
+ #include <numpy/arrayobject.h>
+ %}
+ 
+@@ -13,56 +48,10 @@
+ 
+ %fragment("NumPy_Backward_Compatibility", "header")
+ {
+-/* Support older NumPy data type names
+-*/
+-%#if NDARRAY_VERSION < 0x01000000
+-%#define NPY_BOOL          PyArray_BOOL
+-%#define NPY_BYTE          PyArray_BYTE
+-%#define NPY_UBYTE         PyArray_UBYTE
+-%#define NPY_SHORT         PyArray_SHORT
+-%#define NPY_USHORT        PyArray_USHORT
+-%#define NPY_INT           PyArray_INT
+-%#define NPY_UINT          PyArray_UINT
+-%#define NPY_LONG          PyArray_LONG
+-%#define NPY_ULONG         PyArray_ULONG
+-%#define NPY_LONGLONG      PyArray_LONGLONG
+-%#define NPY_ULONGLONG     PyArray_ULONGLONG
+-%#define NPY_FLOAT         PyArray_FLOAT
+-%#define NPY_DOUBLE        PyArray_DOUBLE
+-%#define NPY_LONGDOUBLE    PyArray_LONGDOUBLE
+-%#define NPY_CFLOAT        PyArray_CFLOAT
+-%#define NPY_CDOUBLE       PyArray_CDOUBLE
+-%#define NPY_CLONGDOUBLE   PyArray_CLONGDOUBLE
+-%#define NPY_OBJECT        PyArray_OBJECT
+-%#define NPY_STRING        PyArray_STRING
+-%#define NPY_UNICODE       PyArray_UNICODE
+-%#define NPY_VOID          PyArray_VOID
+-%#define NPY_NTYPES        PyArray_NTYPES
+-%#define NPY_NOTYPE        PyArray_NOTYPE
+-%#define NPY_CHAR          PyArray_CHAR
+-%#define NPY_USERDEF       PyArray_USERDEF
+-%#define npy_intp          intp
+-
+-%#define NPY_MAX_BYTE      MAX_BYTE
+-%#define NPY_MIN_BYTE      MIN_BYTE
+-%#define NPY_MAX_UBYTE     MAX_UBYTE
+-%#define NPY_MAX_SHORT     MAX_SHORT
+-%#define NPY_MIN_SHORT     MIN_SHORT
+-%#define NPY_MAX_USHORT    MAX_USHORT
+-%#define NPY_MAX_INT       MAX_INT
+-%#define NPY_MIN_INT       MIN_INT
+-%#define NPY_MAX_UINT      MAX_UINT
+-%#define NPY_MAX_LONG      MAX_LONG
+-%#define NPY_MIN_LONG      MIN_LONG
+-%#define NPY_MAX_ULONG     MAX_ULONG
+-%#define NPY_MAX_LONGLONG  MAX_LONGLONG
+-%#define NPY_MIN_LONGLONG  MIN_LONGLONG
+-%#define NPY_MAX_ULONGLONG MAX_ULONGLONG
+-%#define NPY_MAX_INTP      MAX_INTP
+-%#define NPY_MIN_INTP      MIN_INTP
+-
+-%#define NPY_FARRAY        FARRAY
+-%#define NPY_F_CONTIGUOUS  F_CONTIGUOUS
++%#if NPY_API_VERSION < 0x00000007
++%#define NPY_ARRAY_DEFAULT NPY_DEFAULT
++%#define NPY_ARRAY_FARRAY  NPY_FARRAY
++%#define NPY_FORTRANORDER  NPY_FORTRAN
+ %#endif
+ }
+ 
+@@ -80,24 +69,45 @@
+ {
+ /* Macros to extract array attributes.
+  */
+-%#define is_array(a)            ((a) && PyArray_Check((PyArrayObject *)a))
+-%#define array_type(a)          (int)(PyArray_TYPE(a))
+-%#define array_numdims(a)       (((PyArrayObject *)a)->nd)
+-%#define array_dimensions(a)    (((PyArrayObject *)a)->dimensions)
+-%#define array_size(a,i)        (((PyArrayObject *)a)->dimensions[i])
+-%#define array_data(a)          (((PyArrayObject *)a)->data)
+-%#define array_is_contiguous(a) (PyArray_ISCONTIGUOUS(a))
+-%#define array_is_native(a)     (PyArray_ISNOTSWAPPED(a))
+-%#define array_is_fortran(a)    (PyArray_ISFORTRAN(a))
++%#if NPY_API_VERSION < 0x00000007
++%#define is_array(a)            ((a) && PyArray_Check((PyArrayObject*)a))
++%#define array_type(a)          (int)(PyArray_TYPE((PyArrayObject*)a))
++%#define array_numdims(a)       (((PyArrayObject*)a)->nd)
++%#define array_dimensions(a)    (((PyArrayObject*)a)->dimensions)
++%#define array_size(a,i)        (((PyArrayObject*)a)->dimensions[i])
++%#define array_strides(a)       (((PyArrayObject*)a)->strides)
++%#define array_stride(a,i)      (((PyArrayObject*)a)->strides[i])
++%#define array_data(a)          (((PyArrayObject*)a)->data)
++%#define array_descr(a)         (((PyArrayObject*)a)->descr)
++%#define array_flags(a)         (((PyArrayObject*)a)->flags)
++%#define array_enableflags(a,f) (((PyArrayObject*)a)->flags) = f
++%#else
++%#define is_array(a)            ((a) && PyArray_Check(a))
++%#define array_type(a)          PyArray_TYPE((PyArrayObject*)a)
++%#define array_numdims(a)       PyArray_NDIM((PyArrayObject*)a)
++%#define array_dimensions(a)    PyArray_DIMS((PyArrayObject*)a)
++%#define array_strides(a)       PyArray_STRIDES((PyArrayObject*)a)
++%#define array_stride(a,i)      PyArray_STRIDE((PyArrayObject*)a,i)
++%#define array_size(a,i)        PyArray_DIM((PyArrayObject*)a,i)
++%#define array_data(a)          PyArray_DATA((PyArrayObject*)a)
++%#define array_descr(a)         PyArray_DESCR((PyArrayObject*)a)
++%#define array_flags(a)         PyArray_FLAGS((PyArrayObject*)a)
++%#define array_enableflags(a,f) PyArray_ENABLEFLAGS((PyArrayObject*)a,f)
++%#endif
++%#define array_is_contiguous(a) (PyArray_ISCONTIGUOUS((PyArrayObject*)a))
++%#define array_is_native(a)     (PyArray_ISNOTSWAPPED((PyArrayObject*)a))
++%#define array_is_fortran(a)    (PyArray_IS_F_CONTIGUOUS((PyArrayObject*)a))
+ }
+ 
+ /**********************************************************************/
+ 
+-%fragment("NumPy_Utilities", "header")
++%fragment("NumPy_Utilities",
++          "header")
+ {
+   /* Given a PyObject, return a string describing its type.
+    */
+-  const char* pytype_string(PyObject* py_obj) {
++  const char* pytype_string(PyObject* py_obj)
++  {
+     if (py_obj == NULL          ) return "C NULL value";
+     if (py_obj == Py_None       ) return "Python None" ;
+     if (PyCallable_Check(py_obj)) return "callable"    ;
+@@ -107,40 +117,71 @@
+     if (PyDict_Check(    py_obj)) return "dict"        ;
+     if (PyList_Check(    py_obj)) return "list"        ;
+     if (PyTuple_Check(   py_obj)) return "tuple"       ;
++%#if PY_MAJOR_VERSION < 3
+     if (PyFile_Check(    py_obj)) return "file"        ;
+     if (PyModule_Check(  py_obj)) return "module"      ;
+     if (PyInstance_Check(py_obj)) return "instance"    ;
++%#endif
+ 
+     return "unknown type";
+   }
+ 
+   /* Given a NumPy typecode, return a string describing the type.
+    */
+-  const char* typecode_string(int typecode) {
+-    static const char* type_names[25] = {"bool", "byte", "unsigned byte",
+-                                   "short", "unsigned short", "int",
+-                                   "unsigned int", "long", "unsigned long",
+-                                   "long long", "unsigned long long",
+-                                   "float", "double", "long double",
+-                                   "complex float", "complex double",
+-                                   "complex long double", "object",
+-                                   "string", "unicode", "void", "ntypes",
+-                                   "notype", "char", "unknown"};
++  const char* typecode_string(int typecode)
++  {
++    static const char* type_names[25] = {"bool",
++                                         "byte",
++                                         "unsigned byte",
++                                         "short",
++                                         "unsigned short",
++                                         "int",
++                                         "unsigned int",
++                                         "long",
++                                         "unsigned long",
++                                         "long long",
++                                         "unsigned long long",
++                                         "float",
++                                         "double",
++                                         "long double",
++                                         "complex float",
++                                         "complex double",
++                                         "complex long double",
++                                         "object",
++                                         "string",
++                                         "unicode",
++                                         "void",
++                                         "ntypes",
++                                         "notype",
++                                         "char",
++                                         "unknown"};
+     return typecode < 24 ? type_names[typecode] : type_names[24];
+   }
+ 
+-  /* Make sure input has correct numpy type.  Allow character and byte
+-   * to match.  Also allow int and long to match.  This is deprecated.
+-   * You should use PyArray_EquivTypenums() instead.
++  /* Make sure input has correct numpy type.  This now just calls
++     PyArray_EquivTypenums().
+    */
+-  int type_match(int actual_type, int desired_type) {
++  int type_match(int actual_type,
++                 int desired_type)
++  {
+     return PyArray_EquivTypenums(actual_type, desired_type);
+   }
++
++%#ifdef SWIGPY_USE_CAPSULE
++  void free_cap(PyObject * cap)
++  {
++    void* array = (void*) PyCapsule_GetPointer(cap,SWIGPY_CAPSULE_NAME);
++    if (array != NULL) free(array);
++  }
++%#endif
++
++
+ }
+ 
+ /**********************************************************************/
+ 
+-%fragment("NumPy_Object_to_Array", "header",
++%fragment("NumPy_Object_to_Array",
++          "header",
+           fragment="NumPy_Backward_Compatibility",
+           fragment="NumPy_Macros",
+           fragment="NumPy_Utilities")
+@@ -149,7 +190,8 @@
+    * legal.  If not, set the python error string appropriately and
+    * return NULL.
+    */
+-  PyArrayObject* obj_to_array_no_conversion(PyObject* input, int typecode)
++  PyArrayObject* obj_to_array_no_conversion(PyObject* input,
++                                            int        typecode)
+   {
+     PyArrayObject* ary = NULL;
+     if (is_array(input) && (typecode == NPY_NOTYPE ||
+@@ -168,11 +210,12 @@
+     }
+     else
+     {
+-      const char * desired_type = typecode_string(typecode);
+-      const char * actual_type  = pytype_string(input);
++      const char* desired_type = typecode_string(typecode);
++      const char* actual_type  = pytype_string(input);
+       PyErr_Format(PyExc_TypeError,
+                    "Array of type '%s' required.  A '%s' was given",
+-                   desired_type, actual_type);
++                   desired_type,
++                   actual_type);
+       ary = NULL;
+     }
+     return ary;
+@@ -183,11 +226,12 @@
+    * correct type.  On failure, the python error string will be set and
+    * the routine returns NULL.
+    */
+-  PyArrayObject* obj_to_array_allow_conversion(PyObject* input, int typecode,
+-                                               int* is_new_object)
++  PyArrayObject* obj_to_array_allow_conversion(PyObject* input,
++                                               int       typecode,
++                                               int*      is_new_object)
+   {
+     PyArrayObject* ary = NULL;
+-    PyObject* py_obj;
++    PyObject*      py_obj;
+     if (is_array(input) && (typecode == NPY_NOTYPE ||
+                             PyArray_EquivTypenums(array_type(input),typecode)))
+     {
+@@ -196,7 +240,7 @@
+     }
+     else
+     {
+-      py_obj = PyArray_FROMANY(input, typecode, 0, 0, NPY_DEFAULT);
++      py_obj = PyArray_FROMANY(input, typecode, 0, 0, NPY_ARRAY_DEFAULT);
+       /* If NULL, PyArray_FromObject will have set python error value.*/
+       ary = (PyArrayObject*) py_obj;
+       *is_new_object = 1;
+@@ -209,8 +253,10 @@
+    * not contiguous, create a new PyArrayObject using the original data,
+    * flag it as a new object and return the pointer.
+    */
+-  PyArrayObject* make_contiguous(PyArrayObject* ary, int* is_new_object,
+-                                 int min_dims, int max_dims)
++  PyArrayObject* make_contiguous(PyArrayObject* ary,
++                                 int*           is_new_object,
++                                 int            min_dims,
++                                 int            max_dims)
+   {
+     PyArrayObject* result;
+     if (array_is_contiguous(ary))
+@@ -221,9 +267,9 @@
+     else
+     {
+       result = (PyArrayObject*) PyArray_ContiguousFromObject((PyObject*)ary,
+-                                                             array_type(ary),
+-                                                             min_dims,
+-                                                             max_dims);
++                                                              array_type(ary),
++                                                              min_dims,
++                                                              max_dims);
+       *is_new_object = 1;
+     }
+     return result;
+@@ -235,8 +281,8 @@
+    * PyArrayObject using the original data, flag it as a new object
+    * and return the pointer.
+    */
+-  PyArrayObject* make_fortran(PyArrayObject* ary, int* is_new_object,
+-                              int min_dims, int max_dims)
++  PyArrayObject* make_fortran(PyArrayObject* ary,
++                              int*           is_new_object)
+   {
+     PyArrayObject* result;
+     if (array_is_fortran(ary))
+@@ -246,8 +292,10 @@
+     }
+     else
+     {
+-      Py_INCREF(ary->descr);
+-      result = (PyArrayObject*) PyArray_FromArray(ary, ary->descr, NPY_FORTRAN);
++      Py_INCREF(array_descr(ary));
++      result = (PyArrayObject*) PyArray_FromArray(ary,
++                                                  array_descr(ary),
++                                                  NPY_ARRAY_F_CONTIGUOUS);
+       *is_new_object = 1;
+     }
+     return result;
+@@ -259,13 +307,14 @@
+    * will be set.
+    */
+   PyArrayObject* obj_to_array_contiguous_allow_conversion(PyObject* input,
+-                                                          int typecode,
+-                                                          int* is_new_object)
++                                                          int       typecode,
++                                                          int*      is_new_object)
+   {
+     int is_new1 = 0;
+     int is_new2 = 0;
+     PyArrayObject* ary2;
+-    PyArrayObject* ary1 = obj_to_array_allow_conversion(input, typecode,
++    PyArrayObject* ary1 = obj_to_array_allow_conversion(input,
++                                                        typecode,
+                                                         &is_new1);
+     if (ary1)
+     {
+@@ -286,17 +335,18 @@
+    * will be set.
+    */
+   PyArrayObject* obj_to_array_fortran_allow_conversion(PyObject* input,
+-                                                       int typecode,
+-                                                       int* is_new_object)
++                                                       int       typecode,
++                                                       int*      is_new_object)
+   {
+     int is_new1 = 0;
+     int is_new2 = 0;
+     PyArrayObject* ary2;
+-    PyArrayObject* ary1 = obj_to_array_allow_conversion(input, typecode,
++    PyArrayObject* ary1 = obj_to_array_allow_conversion(input,
++                                                        typecode,
+                                                         &is_new1);
+     if (ary1)
+     {
+-      ary2 = make_fortran(ary1, &is_new2, 0, 0);
++      ary2 = make_fortran(ary1, &is_new2);
+       if (is_new1 && is_new2)
+       {
+         Py_DECREF(ary1);
+@@ -306,13 +356,12 @@
+     *is_new_object = is_new1 || is_new2;
+     return ary1;
+   }
+-
+ } /* end fragment */
+ 
+-
+ /**********************************************************************/
+ 
+-%fragment("NumPy_Array_Requirements", "header",
++%fragment("NumPy_Array_Requirements",
++          "header",
+           fragment="NumPy_Backward_Compatibility",
+           fragment="NumPy_Macros")
+ {
+@@ -332,6 +381,22 @@
+     return contiguous;
+   }
+ 
++  /* Test whether a python object is (C_ or F_) contiguous.  If array is
++   * contiguous, return 1.  Otherwise, set the python error string and
++   * return 0.
++   */
++  int require_c_or_f_contiguous(PyArrayObject* ary)
++  {
++    int contiguous = 1;
++    if (!(array_is_contiguous(ary) || array_is_fortran(ary)))
++    {
++      PyErr_SetString(PyExc_TypeError,
++                      "Array must be contiguous (C_ or F_).  A non-contiguous array was given");
++      contiguous = 0;
++    }
++    return contiguous;
++  }
++
+   /* Require that a numpy array is not byte-swapped.  If the array is
+    * not byte-swapped, return 1.  Otherwise, set the python error string
+    * and return 0.
+@@ -353,14 +418,16 @@
+    * dimensions.  If the array has the specified number of dimensions,
+    * return 1.  Otherwise, set the python error string and return 0.
+    */
+-  int require_dimensions(PyArrayObject* ary, int exact_dimensions)
++  int require_dimensions(PyArrayObject* ary,
++                         int            exact_dimensions)
+   {
+     int success = 1;
+     if (array_numdims(ary) != exact_dimensions)
+     {
+       PyErr_Format(PyExc_TypeError,
+                    "Array must have %d dimensions.  Given array has %d dimensions",
+-                   exact_dimensions, array_numdims(ary));
++                   exact_dimensions,
++                   array_numdims(ary));
+       success = 0;
+     }
+     return success;
+@@ -371,7 +438,9 @@
+    * of dimensions, return 1.  Otherwise, set the python error string
+    * and return 0.
+    */
+-  int require_dimensions_n(PyArrayObject* ary, int* exact_dimensions, int n)
++  int require_dimensions_n(PyArrayObject* ary,
++                           int*           exact_dimensions,
++                           int            n)
+   {
+     int success = 0;
+     int i;
+@@ -395,7 +464,8 @@
+       strcat(dims_str,s);
+       PyErr_Format(PyExc_TypeError,
+                    "Array must have %s dimensions.  Given array has %d dimensions",
+-                   dims_str, array_numdims(ary));
++                   dims_str,
++                   array_numdims(ary));
+     }
+     return success;
+   }
+@@ -404,7 +474,9 @@
+    * array has the specified shape, return 1.  Otherwise, set the python
+    * error string and return 0.
+    */
+-  int require_size(PyArrayObject* ary, npy_intp* size, int n)
++  int require_size(PyArrayObject* ary,
++                   npy_intp*      size,
++                   int            n)
+   {
+     int i;
+     int success = 1;
+@@ -444,104 +516,152 @@
+       actual_dims[len-1] = ']';
+       PyErr_Format(PyExc_TypeError,
+                    "Array must have shape of %s.  Given array has shape of %s",
+-                   desired_dims, actual_dims);
++                   desired_dims,
++                   actual_dims);
+     }
+     return success;
+   }
+ 
+-  /* Require the given PyArrayObject to to be FORTRAN ordered.  If the
+-   * the PyArrayObject is already FORTRAN ordered, do nothing.  Else,
+-   * set the FORTRAN ordering flag and recompute the strides.
++  /* Require the given PyArrayObject to to be Fortran ordered.  If the
++   * the PyArrayObject is already Fortran ordered, do nothing.  Else,
++   * set the Fortran ordering flag and recompute the strides.
+    */
+   int require_fortran(PyArrayObject* ary)
+   {
+     int success = 1;
+     int nd = array_numdims(ary);
+     int i;
++    npy_intp * strides = array_strides(ary);
+     if (array_is_fortran(ary)) return success;
+-    /* Set the FORTRAN ordered flag */
+-    ary->flags = NPY_FARRAY;
++    /* Set the Fortran ordered flag */
++    array_enableflags(ary,NPY_ARRAY_FARRAY);
+     /* Recompute the strides */
+-    ary->strides[0] = ary->strides[nd-1];
++    strides[0] = strides[nd-1];
+     for (i=1; i < nd; ++i)
+-      ary->strides[i] = ary->strides[i-1] * array_size(ary,i-1);
++      strides[i] = strides[i-1] * array_size(ary,i-1);
+     return success;
+   }
+ }
+ 
+ /* Combine all NumPy fragments into one for convenience */
+-%fragment("NumPy_Fragments", "header",
++%fragment("NumPy_Fragments",
++          "header",
+           fragment="NumPy_Backward_Compatibility",
+           fragment="NumPy_Macros",
+           fragment="NumPy_Utilities",
+           fragment="NumPy_Object_to_Array",
+-          fragment="NumPy_Array_Requirements") { }
++          fragment="NumPy_Array_Requirements")
++{
++}
+ 
+ /* End John Hunter translation (with modifications by Bill Spotz)
+  */
+ 
+ /* %numpy_typemaps() macro
+  *
+- * This macro defines a family of 41 typemaps that allow C arguments
++ * This macro defines a family of 75 typemaps that allow C arguments
+  * of the form
+  *
+- *     (DATA_TYPE IN_ARRAY1[ANY])
+- *     (DATA_TYPE* IN_ARRAY1, DIM_TYPE DIM1)
+- *     (DIM_TYPE DIM1, DATA_TYPE* IN_ARRAY1)
+- *
+- *     (DATA_TYPE IN_ARRAY2[ANY][ANY])
+- *     (DATA_TYPE* IN_ARRAY2, DIM_TYPE DIM1, DIM_TYPE DIM2)
+- *     (DIM_TYPE DIM1, DIM_TYPE DIM2, DATA_TYPE* IN_ARRAY2)
+- *     (DATA_TYPE* IN_FARRAY2, DIM_TYPE DIM1, DIM_TYPE DIM2)
+- *     (DIM_TYPE DIM1, DIM_TYPE DIM2, DATA_TYPE* IN_FARRAY2)
+- *
+- *     (DATA_TYPE IN_ARRAY3[ANY][ANY][ANY])
+- *     (DATA_TYPE* IN_ARRAY3, DIM_TYPE DIM1, DIM_TYPE DIM2, DIM_TYPE DIM3)
+- *     (DIM_TYPE DIM1, DIM_TYPE DIM2, DIM_TYPE DIM3, DATA_TYPE* IN_ARRAY3)
+- *     (DATA_TYPE* IN_FARRAY3, DIM_TYPE DIM1, DIM_TYPE DIM2, DIM_TYPE DIM3)
+- *     (DIM_TYPE DIM1, DIM_TYPE DIM2, DIM_TYPE DIM3, DATA_TYPE* IN_FARRAY3)
+- *
+- *     (DATA_TYPE INPLACE_ARRAY1[ANY])
+- *     (DATA_TYPE* INPLACE_ARRAY1, DIM_TYPE DIM1)
+- *     (DIM_TYPE DIM1, DATA_TYPE* INPLACE_ARRAY1)
+- *
+- *     (DATA_TYPE INPLACE_ARRAY2[ANY][ANY])
+- *     (DATA_TYPE* INPLACE_ARRAY2, DIM_TYPE DIM1, DIM_TYPE DIM2)
+- *     (DIM_TYPE DIM1, DIM_TYPE DIM2, DATA_TYPE* INPLACE_ARRAY2)
+- *     (DATA_TYPE* INPLACE_FARRAY2, DIM_TYPE DIM1, DIM_TYPE DIM2)
+- *     (DIM_TYPE DIM1, DIM_TYPE DIM2, DATA_TYPE* INPLACE_FARRAY2)
+- *
+- *     (DATA_TYPE INPLACE_ARRAY3[ANY][ANY][ANY])
+- *     (DATA_TYPE* INPLACE_ARRAY3, DIM_TYPE DIM1, DIM_TYPE DIM2, DIM_TYPE DIM3)
+- *     (DIM_TYPE DIM1, DIM_TYPE DIM2, DIM_TYPE DIM3, DATA_TYPE* INPLACE_ARRAY3)
+- *     (DATA_TYPE* INPLACE_FARRAY3, DIM_TYPE DIM1, DIM_TYPE DIM2, DIM_TYPE DIM3)
+- *     (DIM_TYPE DIM1, DIM_TYPE DIM2, DIM_TYPE DIM3, DATA_TYPE* INPLACE_FARRAY3)
+- *
+- *     (DATA_TYPE ARGOUT_ARRAY1[ANY])
+- *     (DATA_TYPE* ARGOUT_ARRAY1, DIM_TYPE DIM1)
+- *     (DIM_TYPE DIM1, DATA_TYPE* ARGOUT_ARRAY1)
+- *
+- *     (DATA_TYPE ARGOUT_ARRAY2[ANY][ANY])
+- *
+- *     (DATA_TYPE ARGOUT_ARRAY3[ANY][ANY][ANY])
+- *
+- *     (DATA_TYPE** ARGOUTVIEW_ARRAY1, DIM_TYPE* DIM1)
+- *     (DIM_TYPE* DIM1, DATA_TYPE** ARGOUTVIEW_ARRAY1)
+- *
+- *     (DATA_TYPE** ARGOUTVIEW_ARRAY2, DIM_TYPE* DIM1, DIM_TYPE* DIM2)
+- *     (DIM_TYPE* DIM1, DIM_TYPE* DIM2, DATA_TYPE** ARGOUTVIEW_ARRAY2)
+- *     (DATA_TYPE** ARGOUTVIEW_FARRAY2, DIM_TYPE* DIM1, DIM_TYPE* DIM2)
+- *     (DIM_TYPE* DIM1, DIM_TYPE* DIM2, DATA_TYPE** ARGOUTVIEW_FARRAY2)
+- *
+- *     (DATA_TYPE** ARGOUTVIEW_ARRAY3, DIM_TYPE* DIM1, DIM_TYPE* DIM2, DIM_TYPE* DIM3)
+- *     (DIM_TYPE* DIM1, DIM_TYPE* DIM2, DIM_TYPE* DIM3, DATA_TYPE** ARGOUTVIEW_ARRAY3)
+- *     (DATA_TYPE** ARGOUTVIEW_FARRAY3, DIM_TYPE* DIM1, DIM_TYPE* DIM2, DIM_TYPE* DIM3)
+- *     (DIM_TYPE* DIM1, DIM_TYPE* DIM2, DIM_TYPE* DIM3, DATA_TYPE** ARGOUTVIEW_FARRAY3)
++ *    1. (DATA_TYPE IN_ARRAY1[ANY])
++ *    2. (DATA_TYPE* IN_ARRAY1, DIM_TYPE DIM1)
++ *    3. (DIM_TYPE DIM1, DATA_TYPE* IN_ARRAY1)
++ *
++ *    4. (DATA_TYPE IN_ARRAY2[ANY][ANY])
++ *    5. (DATA_TYPE* IN_ARRAY2, DIM_TYPE DIM1, DIM_TYPE DIM2)
++ *    6. (DIM_TYPE DIM1, DIM_TYPE DIM2, DATA_TYPE* IN_ARRAY2)
++ *    7. (DATA_TYPE* IN_FARRAY2, DIM_TYPE DIM1, DIM_TYPE DIM2)
++ *    8. (DIM_TYPE DIM1, DIM_TYPE DIM2, DATA_TYPE* IN_FARRAY2)
++ *
++ *    9. (DATA_TYPE IN_ARRAY3[ANY][ANY][ANY])
++ *   10. (DATA_TYPE* IN_ARRAY3, DIM_TYPE DIM1, DIM_TYPE DIM2, DIM_TYPE DIM3)
++ *   11. (DATA_TYPE** IN_ARRAY3, DIM_TYPE DIM1, DIM_TYPE DIM2, DIM_TYPE DIM3)
++ *   12. (DIM_TYPE DIM1, DIM_TYPE DIM2, DIM_TYPE DIM3, DATA_TYPE* IN_ARRAY3)
++ *   13. (DATA_TYPE* IN_FARRAY3, DIM_TYPE DIM1, DIM_TYPE DIM2, DIM_TYPE DIM3)
++ *   14. (DIM_TYPE DIM1, DIM_TYPE DIM2, DIM_TYPE DIM3, DATA_TYPE* IN_FARRAY3)
++ *
++ *   15. (DATA_TYPE IN_ARRAY4[ANY][ANY][ANY][ANY])
++ *   16. (DATA_TYPE* IN_ARRAY4, DIM_TYPE DIM1, DIM_TYPE DIM2, DIM_TYPE DIM3, DIM_TYPE DIM4)
++ *   17. (DATA_TYPE** IN_ARRAY4, DIM_TYPE DIM1, DIM_TYPE DIM2, DIM_TYPE DIM3, DIM_TYPE DIM4)
++ *   18. (DIM_TYPE DIM1, DIM_TYPE DIM2, DIM_TYPE DIM3, , DIM_TYPE DIM4, DATA_TYPE* IN_ARRAY4)
++ *   19. (DATA_TYPE* IN_FARRAY4, DIM_TYPE DIM1, DIM_TYPE DIM2, DIM_TYPE DIM3, DIM_TYPE DIM4)
++ *   20. (DIM_TYPE DIM1, DIM_TYPE DIM2, DIM_TYPE DIM3, DIM_TYPE DIM4, DATA_TYPE* IN_FARRAY4)
++ *
++ *   21. (DATA_TYPE INPLACE_ARRAY1[ANY])
++ *   22. (DATA_TYPE* INPLACE_ARRAY1, DIM_TYPE DIM1)
++ *   23. (DIM_TYPE DIM1, DATA_TYPE* INPLACE_ARRAY1)
++ *
++ *   24. (DATA_TYPE INPLACE_ARRAY2[ANY][ANY])
++ *   25. (DATA_TYPE* INPLACE_ARRAY2, DIM_TYPE DIM1, DIM_TYPE DIM2)
++ *   26. (DIM_TYPE DIM1, DIM_TYPE DIM2, DATA_TYPE* INPLACE_ARRAY2)
++ *   27. (DATA_TYPE* INPLACE_FARRAY2, DIM_TYPE DIM1, DIM_TYPE DIM2)
++ *   28. (DIM_TYPE DIM1, DIM_TYPE DIM2, DATA_TYPE* INPLACE_FARRAY2)
++ *
++ *   29. (DATA_TYPE INPLACE_ARRAY3[ANY][ANY][ANY])
++ *   30. (DATA_TYPE* INPLACE_ARRAY3, DIM_TYPE DIM1, DIM_TYPE DIM2, DIM_TYPE DIM3)
++ *   31. (DATA_TYPE** INPLACE_ARRAY3, DIM_TYPE DIM1, DIM_TYPE DIM2, DIM_TYPE DIM3)
++ *   32. (DIM_TYPE DIM1, DIM_TYPE DIM2, DIM_TYPE DIM3, DATA_TYPE* INPLACE_ARRAY3)
++ *   33. (DATA_TYPE* INPLACE_FARRAY3, DIM_TYPE DIM1, DIM_TYPE DIM2, DIM_TYPE DIM3)
++ *   34. (DIM_TYPE DIM1, DIM_TYPE DIM2, DIM_TYPE DIM3, DATA_TYPE* INPLACE_FARRAY3)
++ *
++ *   35. (DATA_TYPE INPLACE_ARRAY4[ANY][ANY][ANY][ANY])
++ *   36. (DATA_TYPE* INPLACE_ARRAY4, DIM_TYPE DIM1, DIM_TYPE DIM2, DIM_TYPE DIM3, DIM_TYPE DIM4)
++ *   37. (DATA_TYPE** INPLACE_ARRAY4, DIM_TYPE DIM1, DIM_TYPE DIM2, DIM_TYPE DIM3, DIM_TYPE DIM4)
++ *   38. (DIM_TYPE DIM1, DIM_TYPE DIM2, DIM_TYPE DIM3, DIM_TYPE DIM4, DATA_TYPE* INPLACE_ARRAY4)
++ *   39. (DATA_TYPE* INPLACE_FARRAY4, DIM_TYPE DIM1, DIM_TYPE DIM2, DIM_TYPE DIM3, DIM_TYPE DIM4)
++ *   40. (DIM_TYPE DIM1, DIM_TYPE DIM2, DIM_TYPE DIM3, DIM_TYPE DIM4, DATA_TYPE* INPLACE_FARRAY4)
++ *
++ *   41. (DATA_TYPE ARGOUT_ARRAY1[ANY])
++ *   42. (DATA_TYPE* ARGOUT_ARRAY1, DIM_TYPE DIM1)
++ *   43. (DIM_TYPE DIM1, DATA_TYPE* ARGOUT_ARRAY1)
++ *
++ *   44. (DATA_TYPE ARGOUT_ARRAY2[ANY][ANY])
++ *
++ *   45. (DATA_TYPE ARGOUT_ARRAY3[ANY][ANY][ANY])
++ *
++ *   46. (DATA_TYPE ARGOUT_ARRAY4[ANY][ANY][ANY][ANY])
++ *
++ *   47. (DATA_TYPE** ARGOUTVIEW_ARRAY1, DIM_TYPE* DIM1)
++ *   48. (DIM_TYPE* DIM1, DATA_TYPE** ARGOUTVIEW_ARRAY1)
++ *
++ *   49. (DATA_TYPE** ARGOUTVIEW_ARRAY2, DIM_TYPE* DIM1, DIM_TYPE* DIM2)
++ *   50. (DIM_TYPE* DIM1, DIM_TYPE* DIM2, DATA_TYPE** ARGOUTVIEW_ARRAY2)
++ *   51. (DATA_TYPE** ARGOUTVIEW_FARRAY2, DIM_TYPE* DIM1, DIM_TYPE* DIM2)
++ *   52. (DIM_TYPE* DIM1, DIM_TYPE* DIM2, DATA_TYPE** ARGOUTVIEW_FARRAY2)
++ *
++ *   53. (DATA_TYPE** ARGOUTVIEW_ARRAY3, DIM_TYPE* DIM1, DIM_TYPE* DIM2, DIM_TYPE* DIM3)
++ *   54. (DIM_TYPE* DIM1, DIM_TYPE* DIM2, DIM_TYPE* DIM3, DATA_TYPE** ARGOUTVIEW_ARRAY3)
++ *   55. (DATA_TYPE** ARGOUTVIEW_FARRAY3, DIM_TYPE* DIM1, DIM_TYPE* DIM2, DIM_TYPE* DIM3)
++ *   56. (DIM_TYPE* DIM1, DIM_TYPE* DIM2, DIM_TYPE* DIM3, DATA_TYPE** ARGOUTVIEW_FARRAY3)
++ *
++ *   57. (DATA_TYPE** ARGOUTVIEW_ARRAY4, DIM_TYPE* DIM1, DIM_TYPE* DIM2, DIM_TYPE* DIM3, DIM_TYPE* DIM4)
++ *   58. (DIM_TYPE* DIM1, DIM_TYPE* DIM2, DIM_TYPE* DIM3, DIM_TYPE* DIM4, DATA_TYPE** ARGOUTVIEW_ARRAY4)
++ *   59. (DATA_TYPE** ARGOUTVIEW_FARRAY4, DIM_TYPE* DIM1, DIM_TYPE* DIM2, DIM_TYPE* DIM3, DIM_TYPE* DIM4)
++ *   60. (DIM_TYPE* DIM1, DIM_TYPE* DIM2, DIM_TYPE* DIM3, DIM_TYPE* DIM4, DATA_TYPE** ARGOUTVIEW_FARRAY4)
++ *
++ *   61. (DATA_TYPE** ARGOUTVIEWM_ARRAY1, DIM_TYPE* DIM1)
++ *   62. (DIM_TYPE* DIM1, DATA_TYPE** ARGOUTVIEWM_ARRAY1)
++ *
++ *   63. (DATA_TYPE** ARGOUTVIEWM_ARRAY2, DIM_TYPE* DIM1, DIM_TYPE* DIM2)
++ *   64. (DIM_TYPE* DIM1, DIM_TYPE* DIM2, DATA_TYPE** ARGOUTVIEWM_ARRAY2)
++ *   65. (DATA_TYPE** ARGOUTVIEWM_FARRAY2, DIM_TYPE* DIM1, DIM_TYPE* DIM2)
++ *   66. (DIM_TYPE* DIM1, DIM_TYPE* DIM2, DATA_TYPE** ARGOUTVIEWM_FARRAY2)
++ *
++ *   67. (DATA_TYPE** ARGOUTVIEWM_ARRAY3, DIM_TYPE* DIM1, DIM_TYPE* DIM2, DIM_TYPE* DIM3)
++ *   68. (DIM_TYPE* DIM1, DIM_TYPE* DIM2, DIM_TYPE* DIM3, DATA_TYPE** ARGOUTVIEWM_ARRAY3)
++ *   69. (DATA_TYPE** ARGOUTVIEWM_FARRAY3, DIM_TYPE* DIM1, DIM_TYPE* DIM2, DIM_TYPE* DIM3)
++ *   70. (DIM_TYPE* DIM1, DIM_TYPE* DIM2, DIM_TYPE* DIM3, DATA_TYPE** ARGOUTVIEWM_FARRAY3)
++ *
++ *   71. (DATA_TYPE** ARGOUTVIEWM_ARRAY4, DIM_TYPE* DIM1, DIM_TYPE* DIM2, DIM_TYPE* DIM3, DIM_TYPE* DIM4)
++ *   72. (DIM_TYPE* DIM1, DIM_TYPE* DIM2, DIM_TYPE* DIM3, DIM_TYPE* DIM4, DATA_TYPE** ARGOUTVIEWM_ARRAY4)
++ *   73. (DATA_TYPE** ARGOUTVIEWM_FARRAY4, DIM_TYPE* DIM1, DIM_TYPE* DIM2, DIM_TYPE* DIM3, DIM_TYPE* DIM4)
++ *   74. (DIM_TYPE* DIM1, DIM_TYPE* DIM2, DIM_TYPE* DIM3, DIM_TYPE* DIM4, DATA_TYPE** ARGOUTVIEWM_FARRAY4)
++ *
++ *   75. (DATA_TYPE* INPLACE_ARRAY_FLAT, DIM_TYPE DIM_FLAT)
+  *
+  * where "DATA_TYPE" is any type supported by the NumPy module, and
+  * "DIM_TYPE" is any int-like type suitable for specifying dimensions.
+  * The difference between "ARRAY" typemaps and "FARRAY" typemaps is
+- * that the "FARRAY" typemaps expect FORTRAN ordering of
++ * that the "FARRAY" typemaps expect Fortran ordering of
+  * multidimensional arrays.  In python, the dimensions will not need
+  * to be specified (except for the "DATA_TYPE* ARGOUT_ARRAY1"
+  * typemaps).  The IN_ARRAYs can be a numpy array or any sequence that
+@@ -601,7 +721,8 @@
+   (PyArrayObject* array=NULL, int is_new_object=0)
+ {
+   npy_intp size[1] = { $1_dim0 };
+-  array = obj_to_array_contiguous_allow_conversion($input, DATA_TYPECODE,
++  array = obj_to_array_contiguous_allow_conversion($input,
++                                                   DATA_TYPECODE,
+                                                    &is_new_object);
+   if (!array || !require_dimensions(array, 1) ||
+       !require_size(array, size, 1)) SWIG_fail;
+@@ -628,7 +749,8 @@
+   (PyArrayObject* array=NULL, int is_new_object=0)
+ {
+   npy_intp size[1] = { -1 };
+-  array = obj_to_array_contiguous_allow_conversion($input, DATA_TYPECODE,
++  array = obj_to_array_contiguous_allow_conversion($input,
++                                                   DATA_TYPECODE,
+                                                    &is_new_object);
+   if (!array || !require_dimensions(array, 1) ||
+       !require_size(array, size, 1)) SWIG_fail;
+@@ -656,7 +778,8 @@
+   (PyArrayObject* array=NULL, int is_new_object=0)
+ {
+   npy_intp size[1] = {-1};
+-  array = obj_to_array_contiguous_allow_conversion($input, DATA_TYPECODE,
++  array = obj_to_array_contiguous_allow_conversion($input,
++                                                   DATA_TYPECODE,
+                                                    &is_new_object);
+   if (!array || !require_dimensions(array, 1) ||
+       !require_size(array, size, 1)) SWIG_fail;
+@@ -684,7 +807,8 @@
+   (PyArrayObject* array=NULL, int is_new_object=0)
+ {
+   npy_intp size[2] = { $1_dim0, $1_dim1 };
+-  array = obj_to_array_contiguous_allow_conversion($input, DATA_TYPECODE,
++  array = obj_to_array_contiguous_allow_conversion($input,
++                                                   DATA_TYPECODE,
+                                                    &is_new_object);
+   if (!array || !require_dimensions(array, 2) ||
+       !require_size(array, size, 2)) SWIG_fail;
+@@ -740,7 +864,8 @@
+   (PyArrayObject* array=NULL, int is_new_object=0)
+ {
+   npy_intp size[2] = { -1, -1 };
+-  array = obj_to_array_contiguous_allow_conversion($input, DATA_TYPECODE,
++  array = obj_to_array_contiguous_allow_conversion($input,
++                                                   DATA_TYPECODE,
+                                                    &is_new_object);
+   if (!array || !require_dimensions(array, 2) ||
+       !require_size(array, size, 2)) SWIG_fail;
+@@ -769,7 +894,8 @@
+   (PyArrayObject* array=NULL, int is_new_object=0)
+ {
+   npy_intp size[2] = { -1, -1 };
+-  array = obj_to_array_fortran_allow_conversion($input, DATA_TYPECODE,
++  array = obj_to_array_fortran_allow_conversion($input,
++                                                DATA_TYPECODE,
+                                                 &is_new_object);
+   if (!array || !require_dimensions(array, 2) ||
+       !require_size(array, size, 2) || !require_fortran(array)) SWIG_fail;
+@@ -798,7 +924,8 @@
+   (PyArrayObject* array=NULL, int is_new_object=0)
+ {
+   npy_intp size[2] = { -1, -1 };
+-  array = obj_to_array_contiguous_allow_conversion($input, DATA_TYPECODE,
++  array = obj_to_array_fortran_allow_conversion($input,
++                                                   DATA_TYPECODE,
+                                                    &is_new_object);
+   if (!array || !require_dimensions(array, 2) ||
+       !require_size(array, size, 2) || !require_fortran(array)) SWIG_fail;
+@@ -827,7 +954,8 @@
+   (PyArrayObject* array=NULL, int is_new_object=0)
+ {
+   npy_intp size[3] = { $1_dim0, $1_dim1, $1_dim2 };
+-  array = obj_to_array_contiguous_allow_conversion($input, DATA_TYPECODE,
++  array = obj_to_array_contiguous_allow_conversion($input,
++                                                   DATA_TYPECODE,
+                                                    &is_new_object);
+   if (!array || !require_dimensions(array, 3) ||
+       !require_size(array, size, 3)) SWIG_fail;
+@@ -871,6 +999,88 @@
+     { Py_DECREF(array$argnum); }
+ }
+ 
++/* Typemap suite for (DATA_TYPE** IN_ARRAY3, DIM_TYPE DIM1, DIM_TYPE DIM2,
++ *                    DIM_TYPE DIM3)
++ */
++%typecheck(SWIG_TYPECHECK_DOUBLE_ARRAY,
++           fragment="NumPy_Macros")
++  (DATA_TYPE** IN_ARRAY3, DIM_TYPE DIM1, DIM_TYPE DIM2, DIM_TYPE DIM3)
++{
++  /* for now, only concerned with lists */
++  $1 = PySequence_Check($input);
++}
++%typemap(in,
++         fragment="NumPy_Fragments")
++  (DATA_TYPE** IN_ARRAY3, DIM_TYPE DIM1, DIM_TYPE DIM2, DIM_TYPE DIM3)
++  (DATA_TYPE** array=NULL, PyArrayObject** object_array=NULL, int* is_new_object_array=NULL)
++{
++  npy_intp size[2] = { -1, -1 };
++  PyArrayObject* temp_array;
++  Py_ssize_t i;
++  int is_new_object;
++
++  /* length of the list */
++  $2 = PyList_Size($input);
++
++  /* the arrays */
++  array = (DATA_TYPE **)malloc($2*sizeof(DATA_TYPE *));
++  object_array = (PyArrayObject **)calloc($2,sizeof(PyArrayObject *));
++  is_new_object_array = (int *)calloc($2,sizeof(int));
++
++  if (array == NULL || object_array == NULL || is_new_object_array == NULL)
++  {
++    SWIG_fail;
++  }
++
++  for (i=0; i<$2; i++)
++  {
++    temp_array = obj_to_array_contiguous_allow_conversion(PySequence_GetItem($input,i), DATA_TYPECODE, &is_new_object);
++
++    /* the new array must be stored so that it can be destroyed in freearg */
++    object_array[i] = temp_array;
++    is_new_object_array[i] = is_new_object;
++
++    if (!temp_array || !require_dimensions(temp_array, 2)) SWIG_fail;
++
++    /* store the size of the first array in the list, then use that for comparison. */
++    if (i == 0)
++    {
++      size[0] = array_size(temp_array,0);
++      size[1] = array_size(temp_array,1);
++    }
++
++    if (!require_size(temp_array, size, 2)) SWIG_fail;
++
++    array[i] = (DATA_TYPE*) array_data(temp_array);
++  }
++
++  $1 = (DATA_TYPE**) array;
++  $3 = (DIM_TYPE) size[0];
++  $4 = (DIM_TYPE) size[1];
++}
++%typemap(freearg)
++  (DATA_TYPE** IN_ARRAY3, DIM_TYPE DIM1, DIM_TYPE DIM2, DIM_TYPE DIM3)
++{
++  Py_ssize_t i;
++
++  if (array$argnum!=NULL) free(array$argnum);
++
++  /*freeing the individual arrays if needed */
++  if (object_array$argnum!=NULL)
++  {
++    if (is_new_object_array$argnum!=NULL)
++    {
++      for (i=0; i<$2; i++)
++      {
++        if (object_array$argnum[i] != NULL && is_new_object_array$argnum[i])
++        { Py_DECREF(object_array$argnum[i]); }
++      }
++      free(is_new_object_array$argnum);
++    }
++    free(object_array$argnum);
++  }
++}
++
+ /* Typemap suite for (DIM_TYPE DIM1, DIM_TYPE DIM2, DIM_TYPE DIM3,
+  *                    DATA_TYPE* IN_ARRAY3)
+  */
+@@ -948,7 +1158,8 @@
+   (PyArrayObject* array=NULL, int is_new_object=0)
+ {
+   npy_intp size[3] = { -1, -1, -1 };
+-  array = obj_to_array_contiguous_allow_conversion($input, DATA_TYPECODE,
++  array = obj_to_array_fortran_allow_conversion($input,
++                                                   DATA_TYPECODE,
+                                                    &is_new_object);
+   if (!array || !require_dimensions(array, 3) ||
+       !require_size(array, size, 3) || !require_fortran(array)) SWIG_fail;
+@@ -964,6 +1175,245 @@
+     { Py_DECREF(array$argnum); }
+ }
+ 
++/* Typemap suite for (DATA_TYPE IN_ARRAY4[ANY][ANY][ANY][ANY])
++ */
++%typecheck(SWIG_TYPECHECK_DOUBLE_ARRAY,
++           fragment="NumPy_Macros")
++  (DATA_TYPE IN_ARRAY4[ANY][ANY][ANY][ANY])
++{
++  $1 = is_array($input) || PySequence_Check($input);
++}
++%typemap(in,
++         fragment="NumPy_Fragments")
++  (DATA_TYPE IN_ARRAY4[ANY][ANY][ANY][ANY])
++  (PyArrayObject* array=NULL, int is_new_object=0)
++{
++  npy_intp size[4] = { $1_dim0, $1_dim1, $1_dim2 , $1_dim3};
++  array = obj_to_array_contiguous_allow_conversion($input, DATA_TYPECODE,
++                                                   &is_new_object);
++  if (!array || !require_dimensions(array, 4) ||
++      !require_size(array, size, 4)) SWIG_fail;
++  $1 = ($1_ltype) array_data(array);
++}
++%typemap(freearg)
++  (DATA_TYPE IN_ARRAY4[ANY][ANY][ANY][ANY])
++{
++  if (is_new_object$argnum && array$argnum)
++    { Py_DECREF(array$argnum); }
++}
++
++/* Typemap suite for (DATA_TYPE* IN_ARRAY4, DIM_TYPE DIM1, DIM_TYPE DIM2,
++ *                    DIM_TYPE DIM3, DIM_TYPE DIM4)
++ */
++%typecheck(SWIG_TYPECHECK_DOUBLE_ARRAY,
++           fragment="NumPy_Macros")
++  (DATA_TYPE* IN_ARRAY4, DIM_TYPE DIM1, DIM_TYPE DIM2, DIM_TYPE DIM3, DIM_TYPE DIM4)
++{
++  $1 = is_array($input) || PySequence_Check($input);
++}
++%typemap(in,
++         fragment="NumPy_Fragments")
++  (DATA_TYPE* IN_ARRAY4, DIM_TYPE DIM1, DIM_TYPE DIM2, DIM_TYPE DIM3, DIM_TYPE DIM4)
++  (PyArrayObject* array=NULL, int is_new_object=0)
++{
++  npy_intp size[4] = { -1, -1, -1, -1 };
++  array = obj_to_array_contiguous_allow_conversion($input, DATA_TYPECODE,
++                                                   &is_new_object);
++  if (!array || !require_dimensions(array, 4) ||
++      !require_size(array, size, 4)) SWIG_fail;
++  $1 = (DATA_TYPE*) array_data(array);
++  $2 = (DIM_TYPE) array_size(array,0);
++  $3 = (DIM_TYPE) array_size(array,1);
++  $4 = (DIM_TYPE) array_size(array,2);
++  $5 = (DIM_TYPE) array_size(array,3);
++}
++%typemap(freearg)
++  (DATA_TYPE* IN_ARRAY4, DIM_TYPE DIM1, DIM_TYPE DIM2, DIM_TYPE DIM3, DIM_TYPE DIM4)
++{
++  if (is_new_object$argnum && array$argnum)
++    { Py_DECREF(array$argnum); }
++}
++
++/* Typemap suite for (DATA_TYPE** IN_ARRAY4, DIM_TYPE DIM1, DIM_TYPE DIM2,
++ *                    DIM_TYPE DIM3, DIM_TYPE DIM4)
++ */
++%typecheck(SWIG_TYPECHECK_DOUBLE_ARRAY,
++           fragment="NumPy_Macros")
++  (DATA_TYPE** IN_ARRAY4, DIM_TYPE DIM1, DIM_TYPE DIM2, DIM_TYPE DIM3, DIM_TYPE DIM4)
++{
++  /* for now, only concerned with lists */
++  $1 = PySequence_Check($input);
++}
++%typemap(in,
++         fragment="NumPy_Fragments")
++  (DATA_TYPE** IN_ARRAY4, DIM_TYPE DIM1, DIM_TYPE DIM2, DIM_TYPE DIM3, DIM_TYPE DIM4)
++  (DATA_TYPE** array=NULL, PyArrayObject** object_array=NULL, int* is_new_object_array=NULL)
++{
++  npy_intp size[3] = { -1, -1, -1 };
++  PyArrayObject* temp_array;
++  Py_ssize_t i;
++  int is_new_object;
++
++  /* length of the list */
++  $2 = PyList_Size($input);
++
++  /* the arrays */
++  array = (DATA_TYPE **)malloc($2*sizeof(DATA_TYPE *));
++  object_array = (PyArrayObject **)calloc($2,sizeof(PyArrayObject *));
++  is_new_object_array = (int *)calloc($2,sizeof(int));
++
++  if (array == NULL || object_array == NULL || is_new_object_array == NULL)
++  {
++    SWIG_fail;
++  }
++
++  for (i=0; i<$2; i++)
++  {
++    temp_array = obj_to_array_contiguous_allow_conversion(PySequence_GetItem($input,i), DATA_TYPECODE, &is_new_object);
++
++    /* the new array must be stored so that it can be destroyed in freearg */
++    object_array[i] = temp_array;
++    is_new_object_array[i] = is_new_object;
++
++    if (!temp_array || !require_dimensions(temp_array, 3)) SWIG_fail;
++
++    /* store the size of the first array in the list, then use that for comparison. */
++    if (i == 0)
++    {
++      size[0] = array_size(temp_array,0);
++      size[1] = array_size(temp_array,1);
++      size[2] = array_size(temp_array,2);
++    }
++
++    if (!require_size(temp_array, size, 3)) SWIG_fail;
++
++    array[i] = (DATA_TYPE*) array_data(temp_array);
++  }
++
++  $1 = (DATA_TYPE**) array;
++  $3 = (DIM_TYPE) size[0];
++  $4 = (DIM_TYPE) size[1];
++  $5 = (DIM_TYPE) size[2];
++}
++%typemap(freearg)
++  (DATA_TYPE** IN_ARRAY4, DIM_TYPE DIM1, DIM_TYPE DIM2, DIM_TYPE DIM3, DIM_TYPE DIM4)
++{
++  Py_ssize_t i;
++
++  if (array$argnum!=NULL) free(array$argnum);
++
++  /*freeing the individual arrays if needed */
++  if (object_array$argnum!=NULL)
++  {
++    if (is_new_object_array$argnum!=NULL)
++    {
++      for (i=0; i<$2; i++)
++      {
++        if (object_array$argnum[i] != NULL && is_new_object_array$argnum[i])
++        { Py_DECREF(object_array$argnum[i]); }
++      }
++      free(is_new_object_array$argnum);
++    }
++    free(object_array$argnum);
++  }
++}
++
++/* Typemap suite for (DIM_TYPE DIM1, DIM_TYPE DIM2, DIM_TYPE DIM3, DIM_TYPE DIM4,
++ *                    DATA_TYPE* IN_ARRAY4)
++ */
++%typecheck(SWIG_TYPECHECK_DOUBLE_ARRAY,
++           fragment="NumPy_Macros")
++  (DIM_TYPE DIM1, DIM_TYPE DIM2, DIM_TYPE DIM3, DIM_TYPE DIM4, DATA_TYPE* IN_ARRAY4)
++{
++  $1 = is_array($input) || PySequence_Check($input);
++}
++%typemap(in,
++         fragment="NumPy_Fragments")
++  (DIM_TYPE DIM1, DIM_TYPE DIM2, DIM_TYPE DIM3, DIM_TYPE DIM4, DATA_TYPE* IN_ARRAY4)
++  (PyArrayObject* array=NULL, int is_new_object=0)
++{
++  npy_intp size[4] = { -1, -1, -1 , -1};
++  array = obj_to_array_contiguous_allow_conversion($input, DATA_TYPECODE,
++                                                   &is_new_object);
++  if (!array || !require_dimensions(array, 4) ||
++      !require_size(array, size, 4)) SWIG_fail;
++  $1 = (DIM_TYPE) array_size(array,0);
++  $2 = (DIM_TYPE) array_size(array,1);
++  $3 = (DIM_TYPE) array_size(array,2);
++  $4 = (DIM_TYPE) array_size(array,3);
++  $5 = (DATA_TYPE*) array_data(array);
++}
++%typemap(freearg)
++  (DIM_TYPE DIM1, DIM_TYPE DIM2, DIM_TYPE DIM3, DIM_TYPE DIM4, DATA_TYPE* IN_ARRAY4)
++{
++  if (is_new_object$argnum && array$argnum)
++    { Py_DECREF(array$argnum); }
++}
++
++/* Typemap suite for (DATA_TYPE* IN_FARRAY4, DIM_TYPE DIM1, DIM_TYPE DIM2,
++ *                    DIM_TYPE DIM3, DIM_TYPE DIM4)
++ */
++%typecheck(SWIG_TYPECHECK_DOUBLE_ARRAY,
++           fragment="NumPy_Macros")
++  (DATA_TYPE* IN_FARRAY4, DIM_TYPE DIM1, DIM_TYPE DIM2, DIM_TYPE DIM3, DIM_TYPE DIM4)
++{
++  $1 = is_array($input) || PySequence_Check($input);
++}
++%typemap(in,
++         fragment="NumPy_Fragments")
++  (DATA_TYPE* IN_FARRAY4, DIM_TYPE DIM1, DIM_TYPE DIM2, DIM_TYPE DIM3, DIM_TYPE DIM4)
++  (PyArrayObject* array=NULL, int is_new_object=0)
++{
++  npy_intp size[4] = { -1, -1, -1, -1 };
++  array = obj_to_array_fortran_allow_conversion($input, DATA_TYPECODE,
++                                                &is_new_object);
++  if (!array || !require_dimensions(array, 4) ||
++      !require_size(array, size, 4) | !require_fortran(array)) SWIG_fail;
++  $1 = (DATA_TYPE*) array_data(array);
++  $2 = (DIM_TYPE) array_size(array,0);
++  $3 = (DIM_TYPE) array_size(array,1);
++  $4 = (DIM_TYPE) array_size(array,2);
++  $5 = (DIM_TYPE) array_size(array,3);
++}
++%typemap(freearg)
++  (DATA_TYPE* IN_FARRAY4, DIM_TYPE DIM1, DIM_TYPE DIM2, DIM_TYPE DIM3, DIM_TYPE DIM4)
++{
++  if (is_new_object$argnum && array$argnum)
++    { Py_DECREF(array$argnum); }
++}
++
++/* Typemap suite for (DIM_TYPE DIM1, DIM_TYPE DIM2, DIM_TYPE DIM3, DIM_TYPE DIM4,
++ *                    DATA_TYPE* IN_FARRAY4)
++ */
++%typecheck(SWIG_TYPECHECK_DOUBLE_ARRAY,
++           fragment="NumPy_Macros")
++  (DIM_TYPE DIM1, DIM_TYPE DIM2, DIM_TYPE DIM3, DIM_TYPE DIM4, DATA_TYPE* IN_FARRAY4)
++{
++  $1 = is_array($input) || PySequence_Check($input);
++}
++%typemap(in,
++         fragment="NumPy_Fragments")
++  (DIM_TYPE DIM1, DIM_TYPE DIM2, DIM_TYPE DIM3, DIM_TYPE DIM4, DATA_TYPE* IN_FARRAY4)
++  (PyArrayObject* array=NULL, int is_new_object=0)
++{
++  npy_intp size[4] = { -1, -1, -1 , -1 };
++  array = obj_to_array_fortran_allow_conversion($input, DATA_TYPECODE,
++                                                   &is_new_object);
++  if (!array || !require_dimensions(array, 4) ||
++      !require_size(array, size, 4) || !require_fortran(array)) SWIG_fail;
++  $1 = (DIM_TYPE) array_size(array,0);
++  $2 = (DIM_TYPE) array_size(array,1);
++  $3 = (DIM_TYPE) array_size(array,2);
++  $4 = (DIM_TYPE) array_size(array,3);
++  $5 = (DATA_TYPE*) array_data(array);
++}
++%typemap(freearg)
++  (DIM_TYPE DIM1, DIM_TYPE DIM2, DIM_TYPE DIM3, DIM_TYPE DIM4, DATA_TYPE* IN_FARRAY4)
++{
++  if (is_new_object$argnum && array$argnum)
++    { Py_DECREF(array$argnum); }
++}
++
+ /***************************/
+ /* In-Place Array Typemaps */
+ /***************************/
+@@ -1187,41 +1637,107 @@
+   $4 = (DIM_TYPE) array_size(array,2);
+ }
+ 
+-/* Typemap suite for (DIM_TYPE DIM1, DIM_TYPE DIM2, DIM_TYPE DIM3,
+- *                    DATA_TYPE* INPLACE_ARRAY3)
++/* Typemap suite for (DATA_TYPE** INPLACE_ARRAY3, DIM_TYPE DIM1, DIM_TYPE DIM2,
++ *                    DIM_TYPE DIM3)
+  */
+ %typecheck(SWIG_TYPECHECK_DOUBLE_ARRAY,
+            fragment="NumPy_Macros")
+-  (DIM_TYPE DIM1, DIM_TYPE DIM2, DIM_TYPE DIM3, DATA_TYPE* INPLACE_ARRAY3)
++  (DATA_TYPE** INPLACE_ARRAY3, DIM_TYPE DIM1, DIM_TYPE DIM2, DIM_TYPE DIM3)
+ {
+-  $1 = is_array($input) && PyArray_EquivTypenums(array_type($input),
+-                                                 DATA_TYPECODE);
++  $1 = PySequence_Check($input);
+ }
+ %typemap(in,
+          fragment="NumPy_Fragments")
+-  (DIM_TYPE DIM1, DIM_TYPE DIM2, DIM_TYPE DIM3, DATA_TYPE* INPLACE_ARRAY3)
+-  (PyArrayObject* array=NULL)
++  (DATA_TYPE** INPLACE_ARRAY3, DIM_TYPE DIM1, DIM_TYPE DIM2, DIM_TYPE DIM3)
++  (DATA_TYPE** array=NULL, PyArrayObject** object_array=NULL)
+ {
+-  array = obj_to_array_no_conversion($input, DATA_TYPECODE);
+-  if (!array || !require_dimensions(array,3) || !require_contiguous(array)
+-      || !require_native(array)) SWIG_fail;
+-  $1 = (DIM_TYPE) array_size(array,0);
+-  $2 = (DIM_TYPE) array_size(array,1);
+-  $3 = (DIM_TYPE) array_size(array,2);
+-  $4 = (DATA_TYPE*) array_data(array);
+-}
++  npy_intp size[2] = { -1, -1 };
++  PyArrayObject* temp_array;
++  Py_ssize_t i;
+ 
+-/* Typemap suite for (DATA_TYPE* INPLACE_FARRAY3, DIM_TYPE DIM1, DIM_TYPE DIM2,
+- *                    DIM_TYPE DIM3)
+- */
+-%typecheck(SWIG_TYPECHECK_DOUBLE_ARRAY,
+-           fragment="NumPy_Macros")
+-  (DATA_TYPE* INPLACE_FARRAY3, DIM_TYPE DIM1, DIM_TYPE DIM2, DIM_TYPE DIM3)
+-{
+-  $1 = is_array($input) && PyArray_EquivTypenums(array_type($input),
+-                                                 DATA_TYPECODE);
+-}
+-%typemap(in,
++  /* length of the list */
++  $2 = PyList_Size($input);
++
++  /* the arrays */
++  array = (DATA_TYPE **)malloc($2*sizeof(DATA_TYPE *));
++  object_array = (PyArrayObject **)calloc($2,sizeof(PyArrayObject *));
++
++  if (array == NULL || object_array == NULL)
++  {
++    SWIG_fail;
++  }
++
++  for (i=0; i<$2; i++)
++  {
++    temp_array = obj_to_array_no_conversion(PySequence_GetItem($input,i), DATA_TYPECODE);
++
++    /* the new array must be stored so that it can be destroyed in freearg */
++    object_array[i] = temp_array;
++
++    if ( !temp_array || !require_dimensions(temp_array, 2) ||
++      !require_contiguous(temp_array) ||
++      !require_native(temp_array) ||
++      !PyArray_EquivTypenums(array_type(temp_array), DATA_TYPECODE)
++    ) SWIG_fail;
++
++    /* store the size of the first array in the list, then use that for comparison. */
++    if (i == 0)
++    {
++      size[0] = array_size(temp_array,0);
++      size[1] = array_size(temp_array,1);
++    }
++
++    if (!require_size(temp_array, size, 2)) SWIG_fail;
++
++    array[i] = (DATA_TYPE*) array_data(temp_array);
++  }
++
++  $1 = (DATA_TYPE**) array;
++  $3 = (DIM_TYPE) size[0];
++  $4 = (DIM_TYPE) size[1];
++}
++%typemap(freearg)
++  (DATA_TYPE** INPLACE_ARRAY3, DIM_TYPE DIM1, DIM_TYPE DIM2, DIM_TYPE DIM3)
++{
++  if (array$argnum!=NULL) free(array$argnum);
++  if (object_array$argnum!=NULL) free(object_array$argnum);
++}
++
++/* Typemap suite for (DIM_TYPE DIM1, DIM_TYPE DIM2, DIM_TYPE DIM3,
++ *                    DATA_TYPE* INPLACE_ARRAY3)
++ */
++%typecheck(SWIG_TYPECHECK_DOUBLE_ARRAY,
++           fragment="NumPy_Macros")
++  (DIM_TYPE DIM1, DIM_TYPE DIM2, DIM_TYPE DIM3, DATA_TYPE* INPLACE_ARRAY3)
++{
++  $1 = is_array($input) && PyArray_EquivTypenums(array_type($input),
++                                                 DATA_TYPECODE);
++}
++%typemap(in,
++         fragment="NumPy_Fragments")
++  (DIM_TYPE DIM1, DIM_TYPE DIM2, DIM_TYPE DIM3, DATA_TYPE* INPLACE_ARRAY3)
++  (PyArrayObject* array=NULL)
++{
++  array = obj_to_array_no_conversion($input, DATA_TYPECODE);
++  if (!array || !require_dimensions(array,3) || !require_contiguous(array)
++      || !require_native(array)) SWIG_fail;
++  $1 = (DIM_TYPE) array_size(array,0);
++  $2 = (DIM_TYPE) array_size(array,1);
++  $3 = (DIM_TYPE) array_size(array,2);
++  $4 = (DATA_TYPE*) array_data(array);
++}
++
++/* Typemap suite for (DATA_TYPE* INPLACE_FARRAY3, DIM_TYPE DIM1, DIM_TYPE DIM2,
++ *                    DIM_TYPE DIM3)
++ */
++%typecheck(SWIG_TYPECHECK_DOUBLE_ARRAY,
++           fragment="NumPy_Macros")
++  (DATA_TYPE* INPLACE_FARRAY3, DIM_TYPE DIM1, DIM_TYPE DIM2, DIM_TYPE DIM3)
++{
++  $1 = is_array($input) && PyArray_EquivTypenums(array_type($input),
++                                                 DATA_TYPECODE);
++}
++%typemap(in,
+          fragment="NumPy_Fragments")
+   (DATA_TYPE* INPLACE_FARRAY3, DIM_TYPE DIM1, DIM_TYPE DIM2, DIM_TYPE DIM3)
+   (PyArrayObject* array=NULL)
+@@ -1259,6 +1775,195 @@
+   $4 = (DATA_TYPE*) array_data(array);
+ }
+ 
++/* Typemap suite for (DATA_TYPE INPLACE_ARRAY4[ANY][ANY][ANY][ANY])
++ */
++%typecheck(SWIG_TYPECHECK_DOUBLE_ARRAY,
++           fragment="NumPy_Macros")
++  (DATA_TYPE INPLACE_ARRAY4[ANY][ANY][ANY][ANY])
++{
++  $1 = is_array($input) && PyArray_EquivTypenums(array_type($input),
++                                                 DATA_TYPECODE);
++}
++%typemap(in,
++         fragment="NumPy_Fragments")
++  (DATA_TYPE INPLACE_ARRAY4[ANY][ANY][ANY][ANY])
++  (PyArrayObject* array=NULL)
++{
++  npy_intp size[4] = { $1_dim0, $1_dim1, $1_dim2 , $1_dim3 };
++  array = obj_to_array_no_conversion($input, DATA_TYPECODE);
++  if (!array || !require_dimensions(array,4) || !require_size(array, size, 4) ||
++      !require_contiguous(array) || !require_native(array)) SWIG_fail;
++  $1 = ($1_ltype) array_data(array);
++}
++
++/* Typemap suite for (DATA_TYPE* INPLACE_ARRAY4, DIM_TYPE DIM1, DIM_TYPE DIM2,
++ *                    DIM_TYPE DIM3, DIM_TYPE DIM4)
++ */
++%typecheck(SWIG_TYPECHECK_DOUBLE_ARRAY,
++           fragment="NumPy_Macros")
++  (DATA_TYPE* INPLACE_ARRAY4, DIM_TYPE DIM1, DIM_TYPE DIM2, DIM_TYPE DIM3, DIM_TYPE DIM4)
++{
++  $1 = is_array($input) && PyArray_EquivTypenums(array_type($input),
++                                                 DATA_TYPECODE);
++}
++%typemap(in,
++         fragment="NumPy_Fragments")
++  (DATA_TYPE* INPLACE_ARRAY4, DIM_TYPE DIM1, DIM_TYPE DIM2, DIM_TYPE DIM3, DIM_TYPE DIM4)
++  (PyArrayObject* array=NULL)
++{
++  array = obj_to_array_no_conversion($input, DATA_TYPECODE);
++  if (!array || !require_dimensions(array,4) || !require_contiguous(array) ||
++      !require_native(array)) SWIG_fail;
++  $1 = (DATA_TYPE*) array_data(array);
++  $2 = (DIM_TYPE) array_size(array,0);
++  $3 = (DIM_TYPE) array_size(array,1);
++  $4 = (DIM_TYPE) array_size(array,2);
++  $5 = (DIM_TYPE) array_size(array,3);
++}
++
++/* Typemap suite for (DATA_TYPE** INPLACE_ARRAY4, DIM_TYPE DIM1, DIM_TYPE DIM2,
++ *                    DIM_TYPE DIM3, DIM_TYPE DIM4)
++ */
++%typecheck(SWIG_TYPECHECK_DOUBLE_ARRAY,
++           fragment="NumPy_Macros")
++  (DATA_TYPE** INPLACE_ARRAY4, DIM_TYPE DIM1, DIM_TYPE DIM2, DIM_TYPE DIM3, DIM_TYPE DIM4)
++{
++  $1 = PySequence_Check($input);
++}
++%typemap(in,
++         fragment="NumPy_Fragments")
++  (DATA_TYPE** INPLACE_ARRAY4, DIM_TYPE DIM1, DIM_TYPE DIM2, DIM_TYPE DIM3, DIM_TYPE DIM4)
++  (DATA_TYPE** array=NULL, PyArrayObject** object_array=NULL)
++{
++  npy_intp size[3] = { -1, -1, -1 };
++  PyArrayObject* temp_array;
++  Py_ssize_t i;
++
++  /* length of the list */
++  $2 = PyList_Size($input);
++
++  /* the arrays */
++  array = (DATA_TYPE **)malloc($2*sizeof(DATA_TYPE *));
++  object_array = (PyArrayObject **)calloc($2,sizeof(PyArrayObject *));
++
++  if (array == NULL || object_array == NULL)
++  {
++    SWIG_fail;
++  }
++
++  for (i=0; i<$2; i++)
++  {
++    temp_array = obj_to_array_no_conversion(PySequence_GetItem($input,i), DATA_TYPECODE);
++
++    /* the new array must be stored so that it can be destroyed in freearg */
++    object_array[i] = temp_array;
++
++    if ( !temp_array || !require_dimensions(temp_array, 3) ||
++      !require_contiguous(temp_array) ||
++      !require_native(temp_array) ||
++      !PyArray_EquivTypenums(array_type(temp_array), DATA_TYPECODE)
++    ) SWIG_fail;
++
++    /* store the size of the first array in the list, then use that for comparison. */
++    if (i == 0)
++    {
++      size[0] = array_size(temp_array,0);
++      size[1] = array_size(temp_array,1);
++      size[2] = array_size(temp_array,2);
++    }
++
++    if (!require_size(temp_array, size, 3)) SWIG_fail;
++
++    array[i] = (DATA_TYPE*) array_data(temp_array);
++  }
++
++  $1 = (DATA_TYPE**) array;
++  $3 = (DIM_TYPE) size[0];
++  $4 = (DIM_TYPE) size[1];
++  $5 = (DIM_TYPE) size[2];
++}
++%typemap(freearg)
++  (DATA_TYPE** INPLACE_ARRAY4, DIM_TYPE DIM1, DIM_TYPE DIM2, DIM_TYPE DIM3, DIM_TYPE DIM4)
++{
++  if (array$argnum!=NULL) free(array$argnum);
++  if (object_array$argnum!=NULL) free(object_array$argnum);
++}
++
++/* Typemap suite for (DIM_TYPE DIM1, DIM_TYPE DIM2, DIM_TYPE DIM3, DIM_TYPE DIM4,
++ *                    DATA_TYPE* INPLACE_ARRAY4)
++ */
++%typecheck(SWIG_TYPECHECK_DOUBLE_ARRAY,
++           fragment="NumPy_Macros")
++  (DIM_TYPE DIM1, DIM_TYPE DIM2, DIM_TYPE DIM3, DIM_TYPE DIM4, DATA_TYPE* INPLACE_ARRAY4)
++{
++  $1 = is_array($input) && PyArray_EquivTypenums(array_type($input),
++                                                 DATA_TYPECODE);
++}
++%typemap(in,
++         fragment="NumPy_Fragments")
++  (DIM_TYPE DIM1, DIM_TYPE DIM2, DIM_TYPE DIM3, DIM_TYPE DIM4, DATA_TYPE* INPLACE_ARRAY4)
++  (PyArrayObject* array=NULL)
++{
++  array = obj_to_array_no_conversion($input, DATA_TYPECODE);
++  if (!array || !require_dimensions(array,4) || !require_contiguous(array)
++      || !require_native(array)) SWIG_fail;
++  $1 = (DIM_TYPE) array_size(array,0);
++  $2 = (DIM_TYPE) array_size(array,1);
++  $3 = (DIM_TYPE) array_size(array,2);
++  $4 = (DIM_TYPE) array_size(array,3);
++  $5 = (DATA_TYPE*) array_data(array);
++}
++
++/* Typemap suite for (DATA_TYPE* INPLACE_FARRAY4, DIM_TYPE DIM1, DIM_TYPE DIM2,
++ *                    DIM_TYPE DIM3, DIM_TYPE DIM4)
++ */
++%typecheck(SWIG_TYPECHECK_DOUBLE_ARRAY,
++           fragment="NumPy_Macros")
++  (DATA_TYPE* INPLACE_FARRAY4, DIM_TYPE DIM1, DIM_TYPE DIM2, DIM_TYPE DIM3, DIM_TYPE DIM4)
++{
++  $1 = is_array($input) && PyArray_EquivTypenums(array_type($input),
++                                                 DATA_TYPECODE);
++}
++%typemap(in,
++         fragment="NumPy_Fragments")
++  (DATA_TYPE* INPLACE_FARRAY4, DIM_TYPE DIM1, DIM_TYPE DIM2, DIM_TYPE DIM3, DIM_TYPE DIM4)
++  (PyArrayObject* array=NULL)
++{
++  array = obj_to_array_no_conversion($input, DATA_TYPECODE);
++  if (!array || !require_dimensions(array,4) || !require_contiguous(array) ||
++      !require_native(array) || !require_fortran(array)) SWIG_fail;
++  $1 = (DATA_TYPE*) array_data(array);
++  $2 = (DIM_TYPE) array_size(array,0);
++  $3 = (DIM_TYPE) array_size(array,1);
++  $4 = (DIM_TYPE) array_size(array,2);
++  $5 = (DIM_TYPE) array_size(array,3);
++}
++
++/* Typemap suite for (DIM_TYPE DIM1, DIM_TYPE DIM2, DIM_TYPE DIM3,
++ *                    DATA_TYPE* INPLACE_FARRAY4)
++ */
++%typecheck(SWIG_TYPECHECK_DOUBLE_ARRAY,
++           fragment="NumPy_Macros")
++  (DIM_TYPE DIM1, DIM_TYPE DIM2, DIM_TYPE DIM3, DIM_TYPE DIM4, DATA_TYPE* INPLACE_FARRAY4)
++{
++  $1 = is_array($input) && PyArray_EquivTypenums(array_type($input),
++                                                 DATA_TYPECODE);
++}
++%typemap(in,
++         fragment="NumPy_Fragments")
++  (DIM_TYPE DIM1, DIM_TYPE DIM2, DIM_TYPE DIM3, DIM_TYPE DIM4, DATA_TYPE* INPLACE_FARRAY4)
++  (PyArrayObject* array=NULL)
++{
++  array = obj_to_array_no_conversion($input, DATA_TYPECODE);
++  if (!array || !require_dimensions(array,4) || !require_contiguous(array)
++      || !require_native(array) || !require_fortran(array)) SWIG_fail;
++  $1 = (DIM_TYPE) array_size(array,0);
++  $2 = (DIM_TYPE) array_size(array,1);
++  $3 = (DIM_TYPE) array_size(array,2);
++  $4 = (DIM_TYPE) array_size(array,3);
++  $5 = (DATA_TYPE*) array_data(array);
++}
++
+ /*************************/
+ /* Argout Array Typemaps */
+ /*************************/
+@@ -1268,7 +1973,7 @@
+ %typemap(in,numinputs=0,
+          fragment="NumPy_Backward_Compatibility,NumPy_Macros")
+   (DATA_TYPE ARGOUT_ARRAY1[ANY])
+-  (PyObject * array = NULL)
++  (PyObject* array = NULL)
+ {
+   npy_intp dims[1] = { $1_dim0 };
+   array = PyArray_SimpleNew(1, dims, DATA_TYPECODE);
+@@ -1278,7 +1983,7 @@
+ %typemap(argout)
+   (DATA_TYPE ARGOUT_ARRAY1[ANY])
+ {
+-  $result = SWIG_Python_AppendOutput($result,array$argnum);
++  $result = SWIG_Python_AppendOutput($result,(PyObject*)array$argnum);
+ }
+ 
+ /* Typemap suite for (DATA_TYPE* ARGOUT_ARRAY1, DIM_TYPE DIM1)
+@@ -1286,7 +1991,7 @@
+ %typemap(in,numinputs=1,
+          fragment="NumPy_Fragments")
+   (DATA_TYPE* ARGOUT_ARRAY1, DIM_TYPE DIM1)
+-  (PyObject * array = NULL)
++  (PyObject* array = NULL)
+ {
+   npy_intp dims[1];
+   if (!PyInt_Check($input))
+@@ -1306,7 +2011,7 @@
+ %typemap(argout)
+   (DATA_TYPE* ARGOUT_ARRAY1, DIM_TYPE DIM1)
+ {
+-  $result = SWIG_Python_AppendOutput($result,array$argnum);
++  $result = SWIG_Python_AppendOutput($result,(PyObject*)array$argnum);
+ }
+ 
+ /* Typemap suite for (DIM_TYPE DIM1, DATA_TYPE* ARGOUT_ARRAY1)
+@@ -1314,7 +2019,7 @@
+ %typemap(in,numinputs=1,
+          fragment="NumPy_Fragments")
+   (DIM_TYPE DIM1, DATA_TYPE* ARGOUT_ARRAY1)
+-  (PyObject * array = NULL)
++  (PyObject* array = NULL)
+ {
+   npy_intp dims[1];
+   if (!PyInt_Check($input))
+@@ -1334,7 +2039,7 @@
+ %typemap(argout)
+   (DIM_TYPE DIM1, DATA_TYPE* ARGOUT_ARRAY1)
+ {
+-  $result = SWIG_Python_AppendOutput($result,array$argnum);
++  $result = SWIG_Python_AppendOutput($result,(PyObject*)array$argnum);
+ }
+ 
+ /* Typemap suite for (DATA_TYPE ARGOUT_ARRAY2[ANY][ANY])
+@@ -1342,7 +2047,7 @@
+ %typemap(in,numinputs=0,
+          fragment="NumPy_Backward_Compatibility,NumPy_Macros")
+   (DATA_TYPE ARGOUT_ARRAY2[ANY][ANY])
+-  (PyObject * array = NULL)
++  (PyObject* array = NULL)
+ {
+   npy_intp dims[2] = { $1_dim0, $1_dim1 };
+   array = PyArray_SimpleNew(2, dims, DATA_TYPECODE);
+@@ -1352,7 +2057,7 @@
+ %typemap(argout)
+   (DATA_TYPE ARGOUT_ARRAY2[ANY][ANY])
+ {
+-  $result = SWIG_Python_AppendOutput($result,array$argnum);
++  $result = SWIG_Python_AppendOutput($result,(PyObject*)array$argnum);
+ }
+ 
+ /* Typemap suite for (DATA_TYPE ARGOUT_ARRAY3[ANY][ANY][ANY])
+@@ -1360,7 +2065,7 @@
+ %typemap(in,numinputs=0,
+          fragment="NumPy_Backward_Compatibility,NumPy_Macros")
+   (DATA_TYPE ARGOUT_ARRAY3[ANY][ANY][ANY])
+-  (PyObject * array = NULL)
++  (PyObject* array = NULL)
+ {
+   npy_intp dims[3] = { $1_dim0, $1_dim1, $1_dim2 };
+   array = PyArray_SimpleNew(3, dims, DATA_TYPECODE);
+@@ -1370,7 +2075,25 @@
+ %typemap(argout)
+   (DATA_TYPE ARGOUT_ARRAY3[ANY][ANY][ANY])
+ {
+-  $result = SWIG_Python_AppendOutput($result,array$argnum);
++  $result = SWIG_Python_AppendOutput($result,(PyObject*)array$argnum);
++}
++
++/* Typemap suite for (DATA_TYPE ARGOUT_ARRAY4[ANY][ANY][ANY][ANY])
++ */
++%typemap(in,numinputs=0,
++         fragment="NumPy_Backward_Compatibility,NumPy_Macros")
++  (DATA_TYPE ARGOUT_ARRAY4[ANY][ANY][ANY][ANY])
++  (PyObject* array = NULL)
++{
++  npy_intp dims[4] = { $1_dim0, $1_dim1, $1_dim2, $1_dim3 };
++  array = PyArray_SimpleNew(4, dims, DATA_TYPECODE);
++  if (!array) SWIG_fail;
++  $1 = ($1_ltype) array_data(array);
++}
++%typemap(argout)
++  (DATA_TYPE ARGOUT_ARRAY4[ANY][ANY][ANY][ANY])
++{
++  $result = SWIG_Python_AppendOutput($result,(PyObject*)array$argnum);
+ }
+ 
+ /*****************************/
+@@ -1381,7 +2104,7 @@
+  */
+ %typemap(in,numinputs=0)
+   (DATA_TYPE** ARGOUTVIEW_ARRAY1, DIM_TYPE* DIM1    )
+-  (DATA_TYPE*  data_temp        , DIM_TYPE  dim_temp)
++  (DATA_TYPE*  data_temp = NULL , DIM_TYPE  dim_temp)
+ {
+   $1 = &data_temp;
+   $2 = &dim_temp;
+@@ -1391,16 +2114,18 @@
+   (DATA_TYPE** ARGOUTVIEW_ARRAY1, DIM_TYPE* DIM1)
+ {
+   npy_intp dims[1] = { *$2 };
+-  PyObject * array = PyArray_SimpleNewFromData(1, dims, DATA_TYPECODE, (void*)(*$1));
++  PyObject* obj = PyArray_SimpleNewFromData(1, dims, DATA_TYPECODE, (void*)(*$1));
++  PyArrayObject* array = (PyArrayObject*) obj;
++
+   if (!array) SWIG_fail;
+-  $result = SWIG_Python_AppendOutput($result,array);
++  $result = SWIG_Python_AppendOutput($result,obj);
+ }
+ 
+ /* Typemap suite for (DIM_TYPE* DIM1, DATA_TYPE** ARGOUTVIEW_ARRAY1)
+  */
+ %typemap(in,numinputs=0)
+   (DIM_TYPE* DIM1    , DATA_TYPE** ARGOUTVIEW_ARRAY1)
+-  (DIM_TYPE  dim_temp, DATA_TYPE*  data_temp        )
++  (DIM_TYPE  dim_temp, DATA_TYPE*  data_temp = NULL )
+ {
+   $1 = &dim_temp;
+   $2 = &data_temp;
+@@ -1410,16 +2135,18 @@
+   (DIM_TYPE* DIM1, DATA_TYPE** ARGOUTVIEW_ARRAY1)
+ {
+   npy_intp dims[1] = { *$1 };
+-  PyObject * array = PyArray_SimpleNewFromData(1, dims, DATA_TYPECODE, (void*)(*$2));
++  PyObject* obj = PyArray_SimpleNewFromData(1, dims, DATA_TYPECODE, (void*)(*$2));
++  PyArrayObject* array = (PyArrayObject*) obj;
++
+   if (!array) SWIG_fail;
+-  $result = SWIG_Python_AppendOutput($result,array);
++  $result = SWIG_Python_AppendOutput($result,obj);
+ }
+ 
+ /* Typemap suite for (DATA_TYPE** ARGOUTVIEW_ARRAY2, DIM_TYPE* DIM1, DIM_TYPE* DIM2)
+  */
+ %typemap(in,numinputs=0)
+   (DATA_TYPE** ARGOUTVIEW_ARRAY2, DIM_TYPE* DIM1     , DIM_TYPE* DIM2     )
+-  (DATA_TYPE*  data_temp        , DIM_TYPE  dim1_temp, DIM_TYPE  dim2_temp)
++  (DATA_TYPE*  data_temp = NULL , DIM_TYPE  dim1_temp, DIM_TYPE  dim2_temp)
+ {
+   $1 = &data_temp;
+   $2 = &dim1_temp;
+@@ -1430,16 +2157,18 @@
+   (DATA_TYPE** ARGOUTVIEW_ARRAY2, DIM_TYPE* DIM1, DIM_TYPE* DIM2)
+ {
+   npy_intp dims[2] = { *$2, *$3 };
+-  PyObject * array = PyArray_SimpleNewFromData(2, dims, DATA_TYPECODE, (void*)(*$1));
++  PyObject* obj = PyArray_SimpleNewFromData(2, dims, DATA_TYPECODE, (void*)(*$1));
++  PyArrayObject* array = (PyArrayObject*) obj;
++
+   if (!array) SWIG_fail;
+-  $result = SWIG_Python_AppendOutput($result,array);
++  $result = SWIG_Python_AppendOutput($result,obj);
+ }
+ 
+ /* Typemap suite for (DIM_TYPE* DIM1, DIM_TYPE* DIM2, DATA_TYPE** ARGOUTVIEW_ARRAY2)
+  */
+ %typemap(in,numinputs=0)
+   (DIM_TYPE* DIM1     , DIM_TYPE* DIM2     , DATA_TYPE** ARGOUTVIEW_ARRAY2)
+-  (DIM_TYPE  dim1_temp, DIM_TYPE  dim2_temp, DATA_TYPE*  data_temp        )
++  (DIM_TYPE  dim1_temp, DIM_TYPE  dim2_temp, DATA_TYPE*  data_temp = NULL )
+ {
+   $1 = &dim1_temp;
+   $2 = &dim2_temp;
+@@ -1450,16 +2179,18 @@
+   (DIM_TYPE* DIM1, DIM_TYPE* DIM2, DATA_TYPE** ARGOUTVIEW_ARRAY2)
+ {
+   npy_intp dims[2] = { *$1, *$2 };
+-  PyObject * array = PyArray_SimpleNewFromData(2, dims, DATA_TYPECODE, (void*)(*$3));
++  PyObject* obj = PyArray_SimpleNewFromData(2, dims, DATA_TYPECODE, (void*)(*$3));
++  PyArrayObject* array = (PyArrayObject*) obj;
++
+   if (!array) SWIG_fail;
+-  $result = SWIG_Python_AppendOutput($result,array);
++  $result = SWIG_Python_AppendOutput($result,obj);
+ }
+ 
+ /* Typemap suite for (DATA_TYPE** ARGOUTVIEW_FARRAY2, DIM_TYPE* DIM1, DIM_TYPE* DIM2)
+  */
+ %typemap(in,numinputs=0)
+   (DATA_TYPE** ARGOUTVIEW_FARRAY2, DIM_TYPE* DIM1     , DIM_TYPE* DIM2     )
+-  (DATA_TYPE*  data_temp        , DIM_TYPE  dim1_temp, DIM_TYPE  dim2_temp)
++  (DATA_TYPE*  data_temp = NULL  , DIM_TYPE  dim1_temp, DIM_TYPE  dim2_temp)
+ {
+   $1 = &data_temp;
+   $2 = &dim1_temp;
+@@ -1470,8 +2201,9 @@
+   (DATA_TYPE** ARGOUTVIEW_FARRAY2, DIM_TYPE* DIM1, DIM_TYPE* DIM2)
+ {
+   npy_intp dims[2] = { *$2, *$3 };
+-  PyObject * obj = PyArray_SimpleNewFromData(2, dims, DATA_TYPECODE, (void*)(*$1));
+-  PyArrayObject * array = (PyArrayObject*) obj;
++  PyObject* obj = PyArray_SimpleNewFromData(2, dims, DATA_TYPECODE, (void*)(*$1));
++  PyArrayObject* array = (PyArrayObject*) obj;
++
+   if (!array || !require_fortran(array)) SWIG_fail;
+   $result = SWIG_Python_AppendOutput($result,obj);
+ }
+@@ -1480,7 +2212,7 @@
+  */
+ %typemap(in,numinputs=0)
+   (DIM_TYPE* DIM1     , DIM_TYPE* DIM2     , DATA_TYPE** ARGOUTVIEW_FARRAY2)
+-  (DIM_TYPE  dim1_temp, DIM_TYPE  dim2_temp, DATA_TYPE*  data_temp        )
++  (DIM_TYPE  dim1_temp, DIM_TYPE  dim2_temp, DATA_TYPE*  data_temp = NULL  )
+ {
+   $1 = &dim1_temp;
+   $2 = &dim2_temp;
+@@ -1491,8 +2223,9 @@
+   (DIM_TYPE* DIM1, DIM_TYPE* DIM2, DATA_TYPE** ARGOUTVIEW_FARRAY2)
+ {
+   npy_intp dims[2] = { *$1, *$2 };
+-  PyObject * obj = PyArray_SimpleNewFromData(2, dims, DATA_TYPECODE, (void*)(*$3));
+-  PyArrayObject * array = (PyArrayObject*) obj;
++  PyObject* obj = PyArray_SimpleNewFromData(2, dims, DATA_TYPECODE, (void*)(*$3));
++  PyArrayObject* array = (PyArrayObject*) obj;
++
+   if (!array || !require_fortran(array)) SWIG_fail;
+   $result = SWIG_Python_AppendOutput($result,obj);
+ }
+@@ -1501,8 +2234,8 @@
+                       DIM_TYPE* DIM3)
+  */
+ %typemap(in,numinputs=0)
+-  (DATA_TYPE** ARGOUTVIEW_ARRAY3, DIM_TYPE* DIM1, DIM_TYPE* DIM2, DIM_TYPE* DIM3)
+-  (DATA_TYPE* data_temp, DIM_TYPE dim1_temp, DIM_TYPE dim2_temp, DIM_TYPE dim3_temp)
++  (DATA_TYPE** ARGOUTVIEW_ARRAY3, DIM_TYPE* DIM1    , DIM_TYPE* DIM2    , DIM_TYPE* DIM3    )
++  (DATA_TYPE* data_temp = NULL  , DIM_TYPE dim1_temp, DIM_TYPE dim2_temp, DIM_TYPE dim3_temp)
+ {
+   $1 = &data_temp;
+   $2 = &dim1_temp;
+@@ -1514,9 +2247,11 @@
+   (DATA_TYPE** ARGOUTVIEW_ARRAY3, DIM_TYPE* DIM1, DIM_TYPE* DIM2, DIM_TYPE* DIM3)
+ {
+   npy_intp dims[3] = { *$2, *$3, *$4 };
+-  PyObject * array = PyArray_SimpleNewFromData(3, dims, DATA_TYPECODE, (void*)(*$1));
++  PyObject* obj = PyArray_SimpleNewFromData(3, dims, DATA_TYPECODE, (void*)(*$1));
++  PyArrayObject* array = (PyArrayObject*) obj;
++
+   if (!array) SWIG_fail;
+-  $result = SWIG_Python_AppendOutput($result,array);
++  $result = SWIG_Python_AppendOutput($result,obj);
+ }
+ 
+ /* Typemap suite for (DIM_TYPE* DIM1, DIM_TYPE* DIM2, DIM_TYPE* DIM3,
+@@ -1524,7 +2259,7 @@
+  */
+ %typemap(in,numinputs=0)
+   (DIM_TYPE* DIM1, DIM_TYPE* DIM2, DIM_TYPE* DIM3, DATA_TYPE** ARGOUTVIEW_ARRAY3)
+-  (DIM_TYPE dim1_temp, DIM_TYPE dim2_temp, DIM_TYPE dim3_temp, DATA_TYPE* data_temp)
++  (DIM_TYPE dim1_temp, DIM_TYPE dim2_temp, DIM_TYPE dim3_temp, DATA_TYPE* data_temp = NULL)
+ {
+   $1 = &dim1_temp;
+   $2 = &dim2_temp;
+@@ -1536,17 +2271,19 @@
+   (DIM_TYPE* DIM1, DIM_TYPE* DIM2, DIM_TYPE* DIM3, DATA_TYPE** ARGOUTVIEW_ARRAY3)
+ {
+   npy_intp dims[3] = { *$1, *$2, *$3 };
+-  PyObject * array = PyArray_SimpleNewFromData(3, dims, DATA_TYPECODE, (void*)(*$3));
++  PyObject* obj = PyArray_SimpleNewFromData(3, dims, DATA_TYPECODE, (void*)(*$4));
++  PyArrayObject* array = (PyArrayObject*) obj;
++
+   if (!array) SWIG_fail;
+-  $result = SWIG_Python_AppendOutput($result,array);
++  $result = SWIG_Python_AppendOutput($result,obj);
+ }
+ 
+ /* Typemap suite for (DATA_TYPE** ARGOUTVIEW_FARRAY3, DIM_TYPE* DIM1, DIM_TYPE* DIM2,
+                       DIM_TYPE* DIM3)
+  */
+ %typemap(in,numinputs=0)
+-  (DATA_TYPE** ARGOUTVIEW_FARRAY3, DIM_TYPE* DIM1, DIM_TYPE* DIM2, DIM_TYPE* DIM3)
+-  (DATA_TYPE* data_temp, DIM_TYPE dim1_temp, DIM_TYPE dim2_temp, DIM_TYPE dim3_temp)
++  (DATA_TYPE** ARGOUTVIEW_FARRAY3, DIM_TYPE* DIM1    , DIM_TYPE* DIM2    , DIM_TYPE* DIM3    )
++  (DATA_TYPE* data_temp = NULL   , DIM_TYPE dim1_temp, DIM_TYPE dim2_temp, DIM_TYPE dim3_temp)
+ {
+   $1 = &data_temp;
+   $2 = &dim1_temp;
+@@ -1558,9 +2295,10 @@
+   (DATA_TYPE** ARGOUTVIEW_FARRAY3, DIM_TYPE* DIM1, DIM_TYPE* DIM2, DIM_TYPE* DIM3)
+ {
+   npy_intp dims[3] = { *$2, *$3, *$4 };
+-  PyObject * obj = PyArray_SimpleNewFromData(3, dims, DATA_TYPECODE, (void*)(*$1));
+-  PyArrayObject * array = (PyArrayObject*) obj;
+-  if (!array || require_fortran(array)) SWIG_fail;
++  PyObject* obj = PyArray_SimpleNewFromData(3, dims, DATA_TYPECODE, (void*)(*$1));
++  PyArrayObject* array = (PyArrayObject*) obj;
++
++  if (!array || !require_fortran(array)) SWIG_fail;
+   $result = SWIG_Python_AppendOutput($result,obj);
+ }
+ 
+@@ -1568,8 +2306,8 @@
+                       DATA_TYPE** ARGOUTVIEW_FARRAY3)
+  */
+ %typemap(in,numinputs=0)
+-  (DIM_TYPE* DIM1, DIM_TYPE* DIM2, DIM_TYPE* DIM3, DATA_TYPE** ARGOUTVIEW_FARRAY3)
+-  (DIM_TYPE dim1_temp, DIM_TYPE dim2_temp, DIM_TYPE dim3_temp, DATA_TYPE* data_temp)
++  (DIM_TYPE* DIM1    , DIM_TYPE* DIM2    , DIM_TYPE* DIM3    , DATA_TYPE** ARGOUTVIEW_FARRAY3)
++  (DIM_TYPE dim1_temp, DIM_TYPE dim2_temp, DIM_TYPE dim3_temp, DATA_TYPE* data_temp = NULL   )
+ {
+   $1 = &dim1_temp;
+   $2 = &dim2_temp;
+@@ -1581,54 +2319,843 @@
+   (DIM_TYPE* DIM1, DIM_TYPE* DIM2, DIM_TYPE* DIM3, DATA_TYPE** ARGOUTVIEW_FARRAY3)
+ {
+   npy_intp dims[3] = { *$1, *$2, *$3 };
+-  PyObject * obj = PyArray_SimpleNewFromData(3, dims, DATA_TYPECODE, (void*)(*$3));
+-  PyArrayObject * array = (PyArrayObject*) obj;
+-  if (!array || require_fortran(array)) SWIG_fail;
++  PyObject* obj = PyArray_SimpleNewFromData(3, dims, DATA_TYPECODE, (void*)(*$4));
++  PyArrayObject* array = (PyArrayObject*) obj;
++
++  if (!array || !require_fortran(array)) SWIG_fail;
+   $result = SWIG_Python_AppendOutput($result,obj);
+ }
+ 
+-%enddef    /* %numpy_typemaps() macro */
+-/* *************************************************************** */
+-
+-/* Concrete instances of the %numpy_typemaps() macro: Each invocation
+- * below applies all of the typemaps above to the specified data type.
++/* Typemap suite for (DATA_TYPE** ARGOUTVIEW_ARRAY4, DIM_TYPE* DIM1, DIM_TYPE* DIM2,
++                      DIM_TYPE* DIM3, DIM_TYPE* DIM4)
+  */
+-%numpy_typemaps(signed char       , NPY_BYTE     , int)
+-%numpy_typemaps(unsigned char     , NPY_UBYTE    , int)
+-%numpy_typemaps(short             , NPY_SHORT    , int)
+-%numpy_typemaps(unsigned short    , NPY_USHORT   , int)
+-%numpy_typemaps(int               , NPY_INT      , int)
+-%numpy_typemaps(unsigned int      , NPY_UINT     , int)
+-%numpy_typemaps(long              , NPY_LONG     , int)
+-%numpy_typemaps(unsigned long     , NPY_ULONG    , int)
+-%numpy_typemaps(long long         , NPY_LONGLONG , int)
+-%numpy_typemaps(unsigned long long, NPY_ULONGLONG, int)
+-%numpy_typemaps(float             , NPY_FLOAT    , int)
+-%numpy_typemaps(double            , NPY_DOUBLE   , int)
++%typemap(in,numinputs=0)
++  (DATA_TYPE** ARGOUTVIEW_ARRAY4, DIM_TYPE* DIM1    , DIM_TYPE* DIM2    , DIM_TYPE* DIM3    , DIM_TYPE* DIM4    )
++  (DATA_TYPE* data_temp = NULL  , DIM_TYPE dim1_temp, DIM_TYPE dim2_temp, DIM_TYPE dim3_temp, DIM_TYPE dim4_temp)
++{
++  $1 = &data_temp;
++  $2 = &dim1_temp;
++  $3 = &dim2_temp;
++  $4 = &dim3_temp;
++  $5 = &dim4_temp;
++}
++%typemap(argout,
++         fragment="NumPy_Backward_Compatibility")
++  (DATA_TYPE** ARGOUTVIEW_ARRAY4, DIM_TYPE* DIM1, DIM_TYPE* DIM2, DIM_TYPE* DIM3, DIM_TYPE* DIM4)
++{
++  npy_intp dims[4] = { *$2, *$3, *$4 , *$5 };
++  PyObject* obj = PyArray_SimpleNewFromData(4, dims, DATA_TYPECODE, (void*)(*$1));
++  PyArrayObject* array = (PyArrayObject*) obj;
+ 
+-/* ***************************************************************
+- * The follow macro expansion does not work, because C++ bool is 4
+- * bytes and NPY_BOOL is 1 byte
+- *
+- *    %numpy_typemaps(bool, NPY_BOOL, int)
+- */
++  if (!array) SWIG_fail;
++  $result = SWIG_Python_AppendOutput($result,obj);
++}
+ 
+-/* ***************************************************************
+- * On my Mac, I get the following warning for this macro expansion:
+- * 'swig/python detected a memory leak of type 'long double *', no destructor found.'
+- *
+- *    %numpy_typemaps(long double, NPY_LONGDOUBLE, int)
++/* Typemap suite for (DIM_TYPE* DIM1, DIM_TYPE* DIM2, DIM_TYPE* DIM3, DIM_TYPE* DIM4,
++                      DATA_TYPE** ARGOUTVIEW_ARRAY4)
+  */
+-
+-/* ***************************************************************
+- * Swig complains about a syntax error for the following macro
+- * expansions:
+- *
+- *    %numpy_typemaps(complex float,  NPY_CFLOAT , int)
+- *
+- *    %numpy_typemaps(complex double, NPY_CDOUBLE, int)
+- *
+- *    %numpy_typemaps(complex long double, NPY_CLONGDOUBLE, int)
++%typemap(in,numinputs=0)
++  (DIM_TYPE* DIM1    , DIM_TYPE* DIM2    , DIM_TYPE* DIM3    , DIM_TYPE* DIM4    , DATA_TYPE** ARGOUTVIEW_ARRAY4)
++  (DIM_TYPE dim1_temp, DIM_TYPE dim2_temp, DIM_TYPE dim3_temp, DIM_TYPE dim4_temp, DATA_TYPE* data_temp = NULL  )
++{
++  $1 = &dim1_temp;
++  $2 = &dim2_temp;
++  $3 = &dim3_temp;
++  $4 = &dim4_temp;
++  $5 = &data_temp;
++}
++%typemap(argout,
++         fragment="NumPy_Backward_Compatibility")
++  (DIM_TYPE* DIM1, DIM_TYPE* DIM2, DIM_TYPE* DIM3, DIM_TYPE* DIM4, DATA_TYPE** ARGOUTVIEW_ARRAY4)
++{
++  npy_intp dims[4] = { *$1, *$2, *$3 , *$4 };
++  PyObject* obj = PyArray_SimpleNewFromData(4, dims, DATA_TYPECODE, (void*)(*$5));
++  PyArrayObject* array = (PyArrayObject*) obj;
++
++  if (!array) SWIG_fail;
++  $result = SWIG_Python_AppendOutput($result,obj);
++}
++
++/* Typemap suite for (DATA_TYPE** ARGOUTVIEW_FARRAY4, DIM_TYPE* DIM1, DIM_TYPE* DIM2,
++                      DIM_TYPE* DIM3, DIM_TYPE* DIM4)
++ */
++%typemap(in,numinputs=0)
++  (DATA_TYPE** ARGOUTVIEW_FARRAY4, DIM_TYPE* DIM1    , DIM_TYPE* DIM2    , DIM_TYPE* DIM3    , DIM_TYPE* DIM4    )
++  (DATA_TYPE* data_temp = NULL   , DIM_TYPE dim1_temp, DIM_TYPE dim2_temp, DIM_TYPE dim3_temp, DIM_TYPE dim4_temp)
++{
++  $1 = &data_temp;
++  $2 = &dim1_temp;
++  $3 = &dim2_temp;
++  $4 = &dim3_temp;
++  $5 = &dim4_temp;
++}
++%typemap(argout,
++         fragment="NumPy_Backward_Compatibility,NumPy_Array_Requirements")
++  (DATA_TYPE** ARGOUTVIEW_FARRAY4, DIM_TYPE* DIM1, DIM_TYPE* DIM2, DIM_TYPE* DIM3, DIM_TYPE* DIM4)
++{
++  npy_intp dims[4] = { *$2, *$3, *$4 , *$5 };
++  PyObject* obj = PyArray_SimpleNewFromData(4, dims, DATA_TYPECODE, (void*)(*$1));
++  PyArrayObject* array = (PyArrayObject*) obj;
++
++  if (!array || !require_fortran(array)) SWIG_fail;
++  $result = SWIG_Python_AppendOutput($result,obj);
++}
++
++/* Typemap suite for (DIM_TYPE* DIM1, DIM_TYPE* DIM2, DIM_TYPE* DIM3, DIM_TYPE* DIM4,
++                      DATA_TYPE** ARGOUTVIEW_FARRAY4)
++ */
++%typemap(in,numinputs=0)
++  (DIM_TYPE* DIM1    , DIM_TYPE* DIM2    , DIM_TYPE* DIM3    , DIM_TYPE* DIM4    , DATA_TYPE** ARGOUTVIEW_FARRAY4)
++  (DIM_TYPE dim1_temp, DIM_TYPE dim2_temp, DIM_TYPE dim3_temp, DIM_TYPE dim4_temp, DATA_TYPE* data_temp = NULL   )
++{
++  $1 = &dim1_temp;
++  $2 = &dim2_temp;
++  $3 = &dim3_temp;
++  $4 = &dim4_temp;
++  $5 = &data_temp;
++}
++%typemap(argout,
++         fragment="NumPy_Backward_Compatibility,NumPy_Array_Requirements")
++  (DIM_TYPE* DIM1, DIM_TYPE* DIM2, DIM_TYPE* DIM3, DIM_TYPE* DIM4, DATA_TYPE** ARGOUTVIEW_FARRAY4)
++{
++  npy_intp dims[4] = { *$1, *$2, *$3 , *$4 };
++  PyObject* obj = PyArray_SimpleNewFromData(4, dims, DATA_TYPECODE, (void*)(*$5));
++  PyArrayObject* array = (PyArrayObject*) obj;
++
++  if (!array || !require_fortran(array)) SWIG_fail;
++  $result = SWIG_Python_AppendOutput($result,obj);
++}
++
++/*************************************/
++/* Managed Argoutview Array Typemaps */
++/*************************************/
++
++/* Typemap suite for (DATA_TYPE** ARGOUTVIEWM_ARRAY1, DIM_TYPE* DIM1)
++ */
++%typemap(in,numinputs=0)
++  (DATA_TYPE** ARGOUTVIEWM_ARRAY1, DIM_TYPE* DIM1    )
++  (DATA_TYPE*  data_temp = NULL  , DIM_TYPE  dim_temp)
++{
++  $1 = &data_temp;
++  $2 = &dim_temp;
++}
++%typemap(argout,
++         fragment="NumPy_Backward_Compatibility,NumPy_Utilities")
++  (DATA_TYPE** ARGOUTVIEWM_ARRAY1, DIM_TYPE* DIM1)
++{
++  npy_intp dims[1] = { *$2 };
++  PyObject* obj = PyArray_SimpleNewFromData(1, dims, DATA_TYPECODE, (void*)(*$1));
++  PyArrayObject* array = (PyArrayObject*) obj;
++
++  if (!array) SWIG_fail;
++
++%#ifdef SWIGPY_USE_CAPSULE
++    PyObject* cap = PyCapsule_New((void*)(*$1), SWIGPY_CAPSULE_NAME, free_cap);
++%#else
++    PyObject* cap = PyCObject_FromVoidPtr((void*)(*$1), free);
++%#endif
++
++%#if NPY_API_VERSION < 0x00000007
++  PyArray_BASE(array) = cap;
++%#else
++  PyArray_SetBaseObject(array,cap);
++%#endif
++
++  $result = SWIG_Python_AppendOutput($result,obj);
++}
++
++/* Typemap suite for (DIM_TYPE* DIM1, DATA_TYPE** ARGOUTVIEWM_ARRAY1)
++ */
++%typemap(in,numinputs=0)
++  (DIM_TYPE* DIM1    , DATA_TYPE** ARGOUTVIEWM_ARRAY1)
++  (DIM_TYPE  dim_temp, DATA_TYPE*  data_temp = NULL  )
++{
++  $1 = &dim_temp;
++  $2 = &data_temp;
++}
++%typemap(argout,
++         fragment="NumPy_Backward_Compatibility,NumPy_Utilities")
++  (DIM_TYPE* DIM1, DATA_TYPE** ARGOUTVIEWM_ARRAY1)
++{
++  npy_intp dims[1] = { *$1 };
++  PyObject* obj = PyArray_SimpleNewFromData(1, dims, DATA_TYPECODE, (void*)(*$2));
++  PyArrayObject* array = (PyArrayObject*) obj;
++
++  if (!array) SWIG_fail;
++
++%#ifdef SWIGPY_USE_CAPSULE
++    PyObject* cap = PyCapsule_New((void*)(*$1), SWIGPY_CAPSULE_NAME, free_cap);
++%#else
++    PyObject* cap = PyCObject_FromVoidPtr((void*)(*$1), free);
++%#endif
++
++%#if NPY_API_VERSION < 0x00000007
++  PyArray_BASE(array) = cap;
++%#else
++  PyArray_SetBaseObject(array,cap);
++%#endif
++
++  $result = SWIG_Python_AppendOutput($result,obj);
++}
++
++/* Typemap suite for (DATA_TYPE** ARGOUTVIEWM_ARRAY2, DIM_TYPE* DIM1, DIM_TYPE* DIM2)
++ */
++%typemap(in,numinputs=0)
++  (DATA_TYPE** ARGOUTVIEWM_ARRAY2, DIM_TYPE* DIM1     , DIM_TYPE* DIM2     )
++  (DATA_TYPE*  data_temp = NULL  , DIM_TYPE  dim1_temp, DIM_TYPE  dim2_temp)
++{
++  $1 = &data_temp;
++  $2 = &dim1_temp;
++  $3 = &dim2_temp;
++}
++%typemap(argout,
++         fragment="NumPy_Backward_Compatibility,NumPy_Utilities")
++  (DATA_TYPE** ARGOUTVIEWM_ARRAY2, DIM_TYPE* DIM1, DIM_TYPE* DIM2)
++{
++  npy_intp dims[2] = { *$2, *$3 };
++  PyObject* obj = PyArray_SimpleNewFromData(2, dims, DATA_TYPECODE, (void*)(*$1));
++  PyArrayObject* array = (PyArrayObject*) obj;
++
++  if (!array) SWIG_fail;
++
++%#ifdef SWIGPY_USE_CAPSULE
++    PyObject* cap = PyCapsule_New((void*)(*$1), SWIGPY_CAPSULE_NAME, free_cap);
++%#else
++    PyObject* cap = PyCObject_FromVoidPtr((void*)(*$1), free);
++%#endif
++
++%#if NPY_API_VERSION < 0x00000007
++  PyArray_BASE(array) = cap;
++%#else
++  PyArray_SetBaseObject(array,cap);
++%#endif
++
++  $result = SWIG_Python_AppendOutput($result,obj);
++}
++
++/* Typemap suite for (DIM_TYPE* DIM1, DIM_TYPE* DIM2, DATA_TYPE** ARGOUTVIEWM_ARRAY2)
++ */
++%typemap(in,numinputs=0)
++  (DIM_TYPE* DIM1     , DIM_TYPE* DIM2     , DATA_TYPE** ARGOUTVIEWM_ARRAY2)
++  (DIM_TYPE  dim1_temp, DIM_TYPE  dim2_temp, DATA_TYPE*  data_temp = NULL  )
++{
++  $1 = &dim1_temp;
++  $2 = &dim2_temp;
++  $3 = &data_temp;
++}
++%typemap(argout,
++         fragment="NumPy_Backward_Compatibility,NumPy_Utilities")
++  (DIM_TYPE* DIM1, DIM_TYPE* DIM2, DATA_TYPE** ARGOUTVIEWM_ARRAY2)
++{
++  npy_intp dims[2] = { *$1, *$2 };
++  PyObject* obj = PyArray_SimpleNewFromData(2, dims, DATA_TYPECODE, (void*)(*$3));
++  PyArrayObject* array = (PyArrayObject*) obj;
++
++  if (!array) SWIG_fail;
++
++%#ifdef SWIGPY_USE_CAPSULE
++    PyObject* cap = PyCapsule_New((void*)(*$1), SWIGPY_CAPSULE_NAME, free_cap);
++%#else
++    PyObject* cap = PyCObject_FromVoidPtr((void*)(*$1), free);
++%#endif
++
++%#if NPY_API_VERSION < 0x00000007
++  PyArray_BASE(array) = cap;
++%#else
++  PyArray_SetBaseObject(array,cap);
++%#endif
++
++  $result = SWIG_Python_AppendOutput($result,obj);
++}
++
++/* Typemap suite for (DATA_TYPE** ARGOUTVIEWM_FARRAY2, DIM_TYPE* DIM1, DIM_TYPE* DIM2)
++ */
++%typemap(in,numinputs=0)
++  (DATA_TYPE** ARGOUTVIEWM_FARRAY2, DIM_TYPE* DIM1     , DIM_TYPE* DIM2     )
++  (DATA_TYPE*  data_temp = NULL   , DIM_TYPE  dim1_temp, DIM_TYPE  dim2_temp)
++{
++  $1 = &data_temp;
++  $2 = &dim1_temp;
++  $3 = &dim2_temp;
++}
++%typemap(argout,
++         fragment="NumPy_Backward_Compatibility,NumPy_Array_Requirements,NumPy_Utilities")
++  (DATA_TYPE** ARGOUTVIEWM_FARRAY2, DIM_TYPE* DIM1, DIM_TYPE* DIM2)
++{
++  npy_intp dims[2] = { *$2, *$3 };
++  PyObject* obj = PyArray_SimpleNewFromData(2, dims, DATA_TYPECODE, (void*)(*$1));
++  PyArrayObject* array = (PyArrayObject*) obj;
++
++  if (!array || !require_fortran(array)) SWIG_fail;
++
++%#ifdef SWIGPY_USE_CAPSULE
++    PyObject* cap = PyCapsule_New((void*)(*$1), SWIGPY_CAPSULE_NAME, free_cap);
++%#else
++    PyObject* cap = PyCObject_FromVoidPtr((void*)(*$1), free);
++%#endif
++
++%#if NPY_API_VERSION < 0x00000007
++  PyArray_BASE(array) = cap;
++%#else
++  PyArray_SetBaseObject(array,cap);
++%#endif
++
++  $result = SWIG_Python_AppendOutput($result,obj);
++}
++
++/* Typemap suite for (DIM_TYPE* DIM1, DIM_TYPE* DIM2, DATA_TYPE** ARGOUTVIEWM_FARRAY2)
++ */
++%typemap(in,numinputs=0)
++  (DIM_TYPE* DIM1     , DIM_TYPE* DIM2     , DATA_TYPE** ARGOUTVIEWM_FARRAY2)
++  (DIM_TYPE  dim1_temp, DIM_TYPE  dim2_temp, DATA_TYPE*  data_temp = NULL   )
++{
++  $1 = &dim1_temp;
++  $2 = &dim2_temp;
++  $3 = &data_temp;
++}
++%typemap(argout,
++         fragment="NumPy_Backward_Compatibility,NumPy_Array_Requirements,NumPy_Utilities")
++  (DIM_TYPE* DIM1, DIM_TYPE* DIM2, DATA_TYPE** ARGOUTVIEWM_FARRAY2)
++{
++  npy_intp dims[2] = { *$1, *$2 };
++  PyObject* obj = PyArray_SimpleNewFromData(2, dims, DATA_TYPECODE, (void*)(*$3));
++  PyArrayObject* array = (PyArrayObject*) obj;
++
++  if (!array || !require_fortran(array)) SWIG_fail;
++
++%#ifdef SWIGPY_USE_CAPSULE
++    PyObject* cap = PyCapsule_New((void*)(*$1), SWIGPY_CAPSULE_NAME, free_cap);
++%#else
++    PyObject* cap = PyCObject_FromVoidPtr((void*)(*$1), free);
++%#endif
++
++%#if NPY_API_VERSION < 0x00000007
++  PyArray_BASE(array) = cap;
++%#else
++  PyArray_SetBaseObject(array,cap);
++%#endif
++
++  $result = SWIG_Python_AppendOutput($result,obj);
++}
++
++/* Typemap suite for (DATA_TYPE** ARGOUTVIEWM_ARRAY3, DIM_TYPE* DIM1, DIM_TYPE* DIM2,
++                      DIM_TYPE* DIM3)
++ */
++%typemap(in,numinputs=0)
++  (DATA_TYPE** ARGOUTVIEWM_ARRAY3, DIM_TYPE* DIM1    , DIM_TYPE* DIM2    , DIM_TYPE* DIM3    )
++  (DATA_TYPE* data_temp = NULL   , DIM_TYPE dim1_temp, DIM_TYPE dim2_temp, DIM_TYPE dim3_temp)
++{
++  $1 = &data_temp;
++  $2 = &dim1_temp;
++  $3 = &dim2_temp;
++  $4 = &dim3_temp;
++}
++%typemap(argout,
++         fragment="NumPy_Backward_Compatibility,NumPy_Utilities")
++  (DATA_TYPE** ARGOUTVIEWM_ARRAY3, DIM_TYPE* DIM1, DIM_TYPE* DIM2, DIM_TYPE* DIM3)
++{
++  npy_intp dims[3] = { *$2, *$3, *$4 };
++  PyObject* obj = PyArray_SimpleNewFromData(3, dims, DATA_TYPECODE, (void*)(*$1));
++  PyArrayObject* array = (PyArrayObject*) obj;
++
++  if (!array) SWIG_fail;
++
++%#ifdef SWIGPY_USE_CAPSULE
++    PyObject* cap = PyCapsule_New((void*)(*$1), SWIGPY_CAPSULE_NAME, free_cap);
++%#else
++    PyObject* cap = PyCObject_FromVoidPtr((void*)(*$1), free);
++%#endif
++
++%#if NPY_API_VERSION < 0x00000007
++  PyArray_BASE(array) = cap;
++%#else
++  PyArray_SetBaseObject(array,cap);
++%#endif
++
++  $result = SWIG_Python_AppendOutput($result,obj);
++}
++
++/* Typemap suite for (DIM_TYPE* DIM1, DIM_TYPE* DIM2, DIM_TYPE* DIM3,
++                      DATA_TYPE** ARGOUTVIEWM_ARRAY3)
++ */
++%typemap(in,numinputs=0)
++  (DIM_TYPE* DIM1    , DIM_TYPE* DIM2    , DIM_TYPE* DIM3    , DATA_TYPE** ARGOUTVIEWM_ARRAY3)
++  (DIM_TYPE dim1_temp, DIM_TYPE dim2_temp, DIM_TYPE dim3_temp, DATA_TYPE* data_temp = NULL   )
++{
++  $1 = &dim1_temp;
++  $2 = &dim2_temp;
++  $3 = &dim3_temp;
++  $4 = &data_temp;
++}
++%typemap(argout,
++         fragment="NumPy_Backward_Compatibility,NumPy_Utilities")
++  (DIM_TYPE* DIM1, DIM_TYPE* DIM2, DIM_TYPE* DIM3, DATA_TYPE** ARGOUTVIEWM_ARRAY3)
++{
++  npy_intp dims[3] = { *$1, *$2, *$3 };
++  PyObject* obj= PyArray_SimpleNewFromData(3, dims, DATA_TYPECODE, (void*)(*$4));
++  PyArrayObject* array = (PyArrayObject*) obj;
++
++  if (!array) SWIG_fail;
++
++%#ifdef SWIGPY_USE_CAPSULE
++    PyObject* cap = PyCapsule_New((void*)(*$1), SWIGPY_CAPSULE_NAME, free_cap);
++%#else
++    PyObject* cap = PyCObject_FromVoidPtr((void*)(*$1), free);
++%#endif
++
++%#if NPY_API_VERSION < 0x00000007
++  PyArray_BASE(array) = cap;
++%#else
++  PyArray_SetBaseObject(array,cap);
++%#endif
++
++  $result = SWIG_Python_AppendOutput($result,obj);
++}
++
++/* Typemap suite for (DATA_TYPE** ARGOUTVIEWM_FARRAY3, DIM_TYPE* DIM1, DIM_TYPE* DIM2,
++                      DIM_TYPE* DIM3)
+  */
++%typemap(in,numinputs=0)
++  (DATA_TYPE** ARGOUTVIEWM_FARRAY3, DIM_TYPE* DIM1    , DIM_TYPE* DIM2    , DIM_TYPE* DIM3    )
++  (DATA_TYPE* data_temp = NULL    , DIM_TYPE dim1_temp, DIM_TYPE dim2_temp, DIM_TYPE dim3_temp)
++{
++  $1 = &data_temp;
++  $2 = &dim1_temp;
++  $3 = &dim2_temp;
++  $4 = &dim3_temp;
++}
++%typemap(argout,
++         fragment="NumPy_Backward_Compatibility,NumPy_Array_Requirements,NumPy_Utilities")
++  (DATA_TYPE** ARGOUTVIEWM_FARRAY3, DIM_TYPE* DIM1, DIM_TYPE* DIM2, DIM_TYPE* DIM3)
++{
++  npy_intp dims[3] = { *$2, *$3, *$4 };
++  PyObject* obj = PyArray_SimpleNewFromData(3, dims, DATA_TYPECODE, (void*)(*$1));
++  PyArrayObject* array = (PyArrayObject*) obj;
++
++  if (!array || !require_fortran(array)) SWIG_fail;
++
++%#ifdef SWIGPY_USE_CAPSULE
++    PyObject* cap = PyCapsule_New((void*)(*$1), SWIGPY_CAPSULE_NAME, free_cap);
++%#else
++    PyObject* cap = PyCObject_FromVoidPtr((void*)(*$1), free);
++%#endif
++
++%#if NPY_API_VERSION < 0x00000007
++  PyArray_BASE(array) = cap;
++%#else
++  PyArray_SetBaseObject(array,cap);
++%#endif
++
++  $result = SWIG_Python_AppendOutput($result,obj);
++}
++
++/* Typemap suite for (DIM_TYPE* DIM1, DIM_TYPE* DIM2, DIM_TYPE* DIM3,
++                      DATA_TYPE** ARGOUTVIEWM_FARRAY3)
++ */
++%typemap(in,numinputs=0)
++  (DIM_TYPE* DIM1    , DIM_TYPE* DIM2    , DIM_TYPE* DIM3    , DATA_TYPE** ARGOUTVIEWM_FARRAY3)
++  (DIM_TYPE dim1_temp, DIM_TYPE dim2_temp, DIM_TYPE dim3_temp, DATA_TYPE* data_temp = NULL    )
++{
++  $1 = &dim1_temp;
++  $2 = &dim2_temp;
++  $3 = &dim3_temp;
++  $4 = &data_temp;
++}
++%typemap(argout,
++         fragment="NumPy_Backward_Compatibility,NumPy_Array_Requirements,NumPy_Utilities")
++  (DIM_TYPE* DIM1, DIM_TYPE* DIM2, DIM_TYPE* DIM3, DATA_TYPE** ARGOUTVIEWM_FARRAY3)
++{
++  npy_intp dims[3] = { *$1, *$2, *$3 };
++  PyObject* obj = PyArray_SimpleNewFromData(3, dims, DATA_TYPECODE, (void*)(*$4));
++  PyArrayObject* array = (PyArrayObject*) obj;
++
++  if (!array || !require_fortran(array)) SWIG_fail;
++
++%#ifdef SWIGPY_USE_CAPSULE
++    PyObject* cap = PyCapsule_New((void*)(*$1), SWIGPY_CAPSULE_NAME, free_cap);
++%#else
++    PyObject* cap = PyCObject_FromVoidPtr((void*)(*$1), free);
++%#endif
++
++%#if NPY_API_VERSION < 0x00000007
++  PyArray_BASE(array) = cap;
++%#else
++  PyArray_SetBaseObject(array,cap);
++%#endif
++
++  $result = SWIG_Python_AppendOutput($result,obj);
++}
++
++/* Typemap suite for (DATA_TYPE** ARGOUTVIEWM_ARRAY4, DIM_TYPE* DIM1, DIM_TYPE* DIM2,
++                      DIM_TYPE* DIM3, DIM_TYPE* DIM4)
++ */
++%typemap(in,numinputs=0)
++  (DATA_TYPE** ARGOUTVIEWM_ARRAY4, DIM_TYPE* DIM1    , DIM_TYPE* DIM2    , DIM_TYPE* DIM3    , DIM_TYPE* DIM4    )
++  (DATA_TYPE* data_temp = NULL   , DIM_TYPE dim1_temp, DIM_TYPE dim2_temp, DIM_TYPE dim3_temp, DIM_TYPE dim4_temp)
++{
++  $1 = &data_temp;
++  $2 = &dim1_temp;
++  $3 = &dim2_temp;
++  $4 = &dim3_temp;
++  $5 = &dim4_temp;
++}
++%typemap(argout,
++         fragment="NumPy_Backward_Compatibility,NumPy_Utilities")
++  (DATA_TYPE** ARGOUTVIEWM_ARRAY4, DIM_TYPE* DIM1, DIM_TYPE* DIM2, DIM_TYPE* DIM3, DIM_TYPE* DIM4)
++{
++  npy_intp dims[4] = { *$2, *$3, *$4 , *$5 };
++  PyObject* obj = PyArray_SimpleNewFromData(4, dims, DATA_TYPECODE, (void*)(*$1));
++  PyArrayObject* array = (PyArrayObject*) obj;
++
++  if (!array) SWIG_fail;
++
++%#ifdef SWIGPY_USE_CAPSULE
++    PyObject* cap = PyCapsule_New((void*)(*$1), SWIGPY_CAPSULE_NAME, free_cap);
++%#else
++    PyObject* cap = PyCObject_FromVoidPtr((void*)(*$1), free);
++%#endif
++
++%#if NPY_API_VERSION < 0x00000007
++  PyArray_BASE(array) = cap;
++%#else
++  PyArray_SetBaseObject(array,cap);
++%#endif
++
++  $result = SWIG_Python_AppendOutput($result,obj);
++}
++
++/* Typemap suite for (DIM_TYPE* DIM1, DIM_TYPE* DIM2, DIM_TYPE* DIM3, DIM_TYPE* DIM4,
++                      DATA_TYPE** ARGOUTVIEWM_ARRAY4)
++ */
++%typemap(in,numinputs=0)
++  (DIM_TYPE* DIM1    , DIM_TYPE* DIM2    , DIM_TYPE* DIM3    , DIM_TYPE* DIM4    , DATA_TYPE** ARGOUTVIEWM_ARRAY4)
++  (DIM_TYPE dim1_temp, DIM_TYPE dim2_temp, DIM_TYPE dim3_temp, DIM_TYPE dim4_temp, DATA_TYPE* data_temp = NULL   )
++{
++  $1 = &dim1_temp;
++  $2 = &dim2_temp;
++  $3 = &dim3_temp;
++  $4 = &dim4_temp;
++  $5 = &data_temp;
++}
++%typemap(argout,
++         fragment="NumPy_Backward_Compatibility,NumPy_Utilities")
++  (DIM_TYPE* DIM1, DIM_TYPE* DIM2, DIM_TYPE* DIM3, DIM_TYPE* DIM4, DATA_TYPE** ARGOUTVIEWM_ARRAY4)
++{
++  npy_intp dims[4] = { *$1, *$2, *$3 , *$4 };
++  PyObject* obj = PyArray_SimpleNewFromData(4, dims, DATA_TYPECODE, (void*)(*$5));
++  PyArrayObject* array = (PyArrayObject*) obj;
++
++  if (!array) SWIG_fail;
++
++%#ifdef SWIGPY_USE_CAPSULE
++    PyObject* cap = PyCapsule_New((void*)(*$1), SWIGPY_CAPSULE_NAME, free_cap);
++%#else
++    PyObject* cap = PyCObject_FromVoidPtr((void*)(*$1), free);
++%#endif
++
++%#if NPY_API_VERSION < 0x00000007
++  PyArray_BASE(array) = cap;
++%#else
++  PyArray_SetBaseObject(array,cap);
++%#endif
++
++  $result = SWIG_Python_AppendOutput($result,obj);
++}
++
++/* Typemap suite for (DATA_TYPE** ARGOUTVIEWM_FARRAY4, DIM_TYPE* DIM1, DIM_TYPE* DIM2,
++                      DIM_TYPE* DIM3, DIM_TYPE* DIM4)
++ */
++%typemap(in,numinputs=0)
++  (DATA_TYPE** ARGOUTVIEWM_FARRAY4, DIM_TYPE* DIM1    , DIM_TYPE* DIM2    , DIM_TYPE* DIM3    , DIM_TYPE* DIM4    )
++  (DATA_TYPE* data_temp = NULL    , DIM_TYPE dim1_temp, DIM_TYPE dim2_temp, DIM_TYPE dim3_temp, DIM_TYPE dim4_temp)
++{
++  $1 = &data_temp;
++  $2 = &dim1_temp;
++  $3 = &dim2_temp;
++  $4 = &dim3_temp;
++  $5 = &dim4_temp;
++}
++%typemap(argout,
++         fragment="NumPy_Backward_Compatibility,NumPy_Array_Requirements,NumPy_Utilities")
++  (DATA_TYPE** ARGOUTVIEWM_FARRAY4, DIM_TYPE* DIM1, DIM_TYPE* DIM2, DIM_TYPE* DIM3)
++{
++  npy_intp dims[4] = { *$2, *$3, *$4 , *$5 };
++  PyObject* obj = PyArray_SimpleNewFromData(4, dims, DATA_TYPECODE, (void*)(*$1));
++  PyArrayObject* array = (PyArrayObject*) obj;
++
++  if (!array || !require_fortran(array)) SWIG_fail;
++
++%#ifdef SWIGPY_USE_CAPSULE
++    PyObject* cap = PyCapsule_New((void*)(*$1), SWIGPY_CAPSULE_NAME, free_cap);
++%#else
++    PyObject* cap = PyCObject_FromVoidPtr((void*)(*$1), free);
++%#endif
++
++%#if NPY_API_VERSION < 0x00000007
++  PyArray_BASE(array) = cap;
++%#else
++  PyArray_SetBaseObject(array,cap);
++%#endif
++
++  $result = SWIG_Python_AppendOutput($result,obj);
++}
++
++/* Typemap suite for (DIM_TYPE* DIM1, DIM_TYPE* DIM2, DIM_TYPE* DIM3, DIM_TYPE* DIM4,
++                      DATA_TYPE** ARGOUTVIEWM_FARRAY4)
++ */
++%typemap(in,numinputs=0)
++  (DIM_TYPE* DIM1    , DIM_TYPE* DIM2    , DIM_TYPE* DIM3    , DIM_TYPE* DIM4    , DATA_TYPE** ARGOUTVIEWM_FARRAY4)
++  (DIM_TYPE dim1_temp, DIM_TYPE dim2_temp, DIM_TYPE dim3_temp, DIM_TYPE dim4_temp, DATA_TYPE* data_temp = NULL    )
++{
++  $1 = &dim1_temp;
++  $2 = &dim2_temp;
++  $3 = &dim3_temp;
++  $4 = &dim4_temp;
++  $5 = &data_temp;
++}
++%typemap(argout,
++         fragment="NumPy_Backward_Compatibility,NumPy_Array_Requirements,NumPy_Utilities")
++  (DIM_TYPE* DIM1, DIM_TYPE* DIM2, DIM_TYPE* DIM3, DIM_TYPE* DIM4, DATA_TYPE** ARGOUTVIEWM_FARRAY4)
++{
++  npy_intp dims[4] = { *$1, *$2, *$3 , *$4 };
++  PyObject* obj = PyArray_SimpleNewFromData(4, dims, DATA_TYPECODE, (void*)(*$5));
++  PyArrayObject* array = (PyArrayObject*) obj;
++
++  if (!array || !require_fortran(array)) SWIG_fail;
++
++%#ifdef SWIGPY_USE_CAPSULE
++    PyObject* cap = PyCapsule_New((void*)(*$1), SWIGPY_CAPSULE_NAME, free_cap);
++%#else
++    PyObject* cap = PyCObject_FromVoidPtr((void*)(*$1), free);
++%#endif
++
++%#if NPY_API_VERSION < 0x00000007
++  PyArray_BASE(array) = cap;
++%#else
++  PyArray_SetBaseObject(array,cap);
++%#endif
++
++  $result = SWIG_Python_AppendOutput($result,obj);
++}
++
++/* Typemap suite for (DATA_TYPE** ARGOUTVIEWM_ARRAY4, DIM_TYPE* DIM1, DIM_TYPE* DIM2,
++                      DIM_TYPE* DIM3, DIM_TYPE* DIM4)
++ */
++%typemap(in,numinputs=0)
++  (DATA_TYPE** ARGOUTVIEWM_ARRAY4, DIM_TYPE* DIM1    , DIM_TYPE* DIM2    , DIM_TYPE* DIM3    , DIM_TYPE* DIM4    )
++  (DATA_TYPE* data_temp = NULL   , DIM_TYPE dim1_temp, DIM_TYPE dim2_temp, DIM_TYPE dim3_temp, DIM_TYPE dim4_temp)
++{
++  $1 = &data_temp;
++  $2 = &dim1_temp;
++  $3 = &dim2_temp;
++  $4 = &dim3_temp;
++  $5 = &dim4_temp;
++}
++%typemap(argout,
++         fragment="NumPy_Backward_Compatibility,NumPy_Utilities")
++  (DATA_TYPE** ARGOUTVIEWM_ARRAY4, DIM_TYPE* DIM1, DIM_TYPE* DIM2, DIM_TYPE* DIM3, DIM_TYPE* DIM4)
++{
++  npy_intp dims[4] = { *$2, *$3, *$4 , *$5 };
++  PyObject* obj = PyArray_SimpleNewFromData(4, dims, DATA_TYPECODE, (void*)(*$1));
++  PyArrayObject* array = (PyArrayObject*) obj;
++
++  if (!array) SWIG_fail;
++
++%#ifdef SWIGPY_USE_CAPSULE
++    PyObject* cap = PyCapsule_New((void*)(*$1), SWIGPY_CAPSULE_NAME, free_cap);
++%#else
++    PyObject* cap = PyCObject_FromVoidPtr((void*)(*$1), free);
++%#endif
++
++%#if NPY_API_VERSION < 0x00000007
++  PyArray_BASE(array) = cap;
++%#else
++  PyArray_SetBaseObject(array,cap);
++%#endif
++
++  $result = SWIG_Python_AppendOutput($result,obj);
++}
++
++/* Typemap suite for (DIM_TYPE* DIM1, DIM_TYPE* DIM2, DIM_TYPE* DIM3, DIM_TYPE* DIM4,
++                      DATA_TYPE** ARGOUTVIEWM_ARRAY4)
++ */
++%typemap(in,numinputs=0)
++  (DIM_TYPE* DIM1    , DIM_TYPE* DIM2    , DIM_TYPE* DIM3    , DIM_TYPE* DIM4    , DATA_TYPE** ARGOUTVIEWM_ARRAY4)
++  (DIM_TYPE dim1_temp, DIM_TYPE dim2_temp, DIM_TYPE dim3_temp, DIM_TYPE dim4_temp, DATA_TYPE* data_temp = NULL   )
++{
++  $1 = &dim1_temp;
++  $2 = &dim2_temp;
++  $3 = &dim3_temp;
++  $4 = &dim4_temp;
++  $5 = &data_temp;
++}
++%typemap(argout,
++         fragment="NumPy_Backward_Compatibility,NumPy_Utilities")
++  (DIM_TYPE* DIM1, DIM_TYPE* DIM2, DIM_TYPE* DIM3, DIM_TYPE* DIM4, DATA_TYPE** ARGOUTVIEWM_ARRAY4)
++{
++  npy_intp dims[4] = { *$1, *$2, *$3 , *$4 };
++  PyObject* obj = PyArray_SimpleNewFromData(4, dims, DATA_TYPECODE, (void*)(*$5));
++  PyArrayObject* array = (PyArrayObject*) obj;
++
++  if (!array) SWIG_fail;
++
++%#ifdef SWIGPY_USE_CAPSULE
++    PyObject* cap = PyCapsule_New((void*)(*$1), SWIGPY_CAPSULE_NAME, free_cap);
++%#else
++    PyObject* cap = PyCObject_FromVoidPtr((void*)(*$1), free);
++%#endif
++
++%#if NPY_API_VERSION < 0x00000007
++  PyArray_BASE(array) = cap;
++%#else
++  PyArray_SetBaseObject(array,cap);
++%#endif
++
++  $result = SWIG_Python_AppendOutput($result,obj);
++}
++
++/* Typemap suite for (DATA_TYPE** ARGOUTVIEWM_FARRAY4, DIM_TYPE* DIM1, DIM_TYPE* DIM2,
++                      DIM_TYPE* DIM3, DIM_TYPE* DIM4)
++ */
++%typemap(in,numinputs=0)
++  (DATA_TYPE** ARGOUTVIEWM_FARRAY4, DIM_TYPE* DIM1    , DIM_TYPE* DIM2    , DIM_TYPE* DIM3    , DIM_TYPE* DIM4    )
++  (DATA_TYPE* data_temp = NULL    , DIM_TYPE dim1_temp, DIM_TYPE dim2_temp, DIM_TYPE dim3_temp, DIM_TYPE dim4_temp)
++{
++  $1 = &data_temp;
++  $2 = &dim1_temp;
++  $3 = &dim2_temp;
++  $4 = &dim3_temp;
++  $5 = &dim4_temp;
++}
++%typemap(argout,
++         fragment="NumPy_Backward_Compatibility,NumPy_Array_Requirements,NumPy_Utilities")
++  (DATA_TYPE** ARGOUTVIEWM_FARRAY4, DIM_TYPE* DIM1, DIM_TYPE* DIM2, DIM_TYPE* DIM3, DIM_TYPE* DIM4)
++{
++  npy_intp dims[4] = { *$2, *$3, *$4 , *$5 };
++  PyObject* obj = PyArray_SimpleNewFromData(4, dims, DATA_TYPECODE, (void*)(*$1));
++  PyArrayObject* array = (PyArrayObject*) obj;
++
++  if (!array || !require_fortran(array)) SWIG_fail;
++
++%#ifdef SWIGPY_USE_CAPSULE
++    PyObject* cap = PyCapsule_New((void*)(*$1), SWIGPY_CAPSULE_NAME, free_cap);
++%#else
++    PyObject* cap = PyCObject_FromVoidPtr((void*)(*$1), free);
++%#endif
++
++%#if NPY_API_VERSION < 0x00000007
++  PyArray_BASE(array) = cap;
++%#else
++  PyArray_SetBaseObject(array,cap);
++%#endif
++
++  $result = SWIG_Python_AppendOutput($result,obj);
++}
++
++/* Typemap suite for (DIM_TYPE* DIM1, DIM_TYPE* DIM2, DIM_TYPE* DIM3, DIM_TYPE* DIM4,
++                      DATA_TYPE** ARGOUTVIEWM_FARRAY4)
++ */
++%typemap(in,numinputs=0)
++  (DIM_TYPE* DIM1    , DIM_TYPE* DIM2    , DIM_TYPE* DIM3    , DIM_TYPE* DIM4    , DATA_TYPE** ARGOUTVIEWM_FARRAY4)
++  (DIM_TYPE dim1_temp, DIM_TYPE dim2_temp, DIM_TYPE dim3_temp, DIM_TYPE dim4_temp, DATA_TYPE* data_temp = NULL    )
++{
++  $1 = &dim1_temp;
++  $2 = &dim2_temp;
++  $3 = &dim3_temp;
++  $4 = &dim4_temp;
++  $5 = &data_temp;
++}
++%typemap(argout,
++         fragment="NumPy_Backward_Compatibility,NumPy_Array_Requirements,NumPy_Utilities")
++  (DIM_TYPE* DIM1, DIM_TYPE* DIM2, DIM_TYPE* DIM3, DIM_TYPE* DIM4, DATA_TYPE** ARGOUTVIEWM_FARRAY4)
++{
++  npy_intp dims[4] = { *$1, *$2, *$3 , *$4 };
++  PyObject* obj = PyArray_SimpleNewFromData(4, dims, DATA_TYPECODE, (void*)(*$5));
++  PyArrayObject* array = (PyArrayObject*) obj;
++
++  if (!array || !require_fortran(array)) SWIG_fail;
++
++%#ifdef SWIGPY_USE_CAPSULE
++    PyObject* cap = PyCapsule_New((void*)(*$1), SWIGPY_CAPSULE_NAME, free_cap);
++%#else
++    PyObject* cap = PyCObject_FromVoidPtr((void*)(*$1), free);
++%#endif
++
++%#if NPY_API_VERSION < 0x00000007
++  PyArray_BASE(array) = cap;
++%#else
++  PyArray_SetBaseObject(array,cap);
++%#endif
++
++  $result = SWIG_Python_AppendOutput($result,obj);
++}
++
++/**************************************/
++/* In-Place Array Typemap - flattened */
++/**************************************/
++
++/* Typemap suite for (DATA_TYPE* INPLACE_ARRAY_FLAT, DIM_TYPE DIM_FLAT)
++ */
++%typecheck(SWIG_TYPECHECK_DOUBLE_ARRAY,
++           fragment="NumPy_Macros")
++  (DATA_TYPE* INPLACE_ARRAY_FLAT, DIM_TYPE DIM_FLAT)
++{
++  $1 = is_array($input) && PyArray_EquivTypenums(array_type($input),
++                                                 DATA_TYPECODE);
++}
++%typemap(in,
++         fragment="NumPy_Fragments")
++  (DATA_TYPE* INPLACE_ARRAY_FLAT, DIM_TYPE DIM_FLAT)
++  (PyArrayObject* array=NULL, int i=1)
++{
++  array = obj_to_array_no_conversion($input, DATA_TYPECODE);
++  if (!array || !require_c_or_f_contiguous(array)
++      || !require_native(array)) SWIG_fail;
++  $1 = (DATA_TYPE*) array_data(array);
++  $2 = 1;
++  for (i=0; i < array_numdims(array); ++i) $2 *= array_size(array,i);
++}
++
++%enddef    /* %numpy_typemaps() macro */
++/* *************************************************************** */
++
++/* Concrete instances of the %numpy_typemaps() macro: Each invocation
++ * below applies all of the typemaps above to the specified data type.
++ */
++%numpy_typemaps(signed char       , NPY_BYTE     , int)
++%numpy_typemaps(unsigned char     , NPY_UBYTE    , int)
++%numpy_typemaps(short             , NPY_SHORT    , int)
++%numpy_typemaps(unsigned short    , NPY_USHORT   , int)
++%numpy_typemaps(int               , NPY_INT      , int)
++%numpy_typemaps(unsigned int      , NPY_UINT     , int)
++%numpy_typemaps(long              , NPY_LONG     , int)
++%numpy_typemaps(unsigned long     , NPY_ULONG    , int)
++%numpy_typemaps(long long         , NPY_LONGLONG , int)
++%numpy_typemaps(unsigned long long, NPY_ULONGLONG, int)
++%numpy_typemaps(float             , NPY_FLOAT    , int)
++%numpy_typemaps(double            , NPY_DOUBLE   , int)
++
++/* ***************************************************************
++ * The follow macro expansion does not work, because C++ bool is 4
++ * bytes and NPY_BOOL is 1 byte
++ *
++ *    %numpy_typemaps(bool, NPY_BOOL, int)
++ */
++
++/* ***************************************************************
++ * On my Mac, I get the following warning for this macro expansion:
++ * 'swig/python detected a memory leak of type 'long double *', no destructor found.'
++ *
++ *    %numpy_typemaps(long double, NPY_LONGDOUBLE, int)
++ */
++
++#ifdef __cplusplus
++
++%include <std_complex.i>
++
++%numpy_typemaps(std::complex<float>,  NPY_CFLOAT , int)
++%numpy_typemaps(std::complex<double>, NPY_CDOUBLE, int)
++
++#endif
+ 
+ #endif /* SWIGPYTHON */
diff --git a/debian/patches/openjpeg2.patch b/debian/patches/openjpeg2.patch
new file mode 100644
index 0000000..58475fd
--- /dev/null
+++ b/debian/patches/openjpeg2.patch
@@ -0,0 +1,379 @@
+Description: Support the openjpeg2 API
+Author: Alastair McKinstry <mckinstry at debian.org>
+Last-Update: 2016-07-24
+Forwarded: no
+
+Index: eccodes-0.16.0/cmake/FindOpenJPEG.cmake
+===================================================================
+--- eccodes-0.16.0.orig/cmake/FindOpenJPEG.cmake
++++ eccodes-0.16.0/cmake/FindOpenJPEG.cmake
+@@ -26,8 +26,14 @@ if( DEFINED OPENJPEG_PATH )
+         find_library(OPENJPEG_LIBRARY  openjpeg   PATHS ${OPENJPEG_PATH}/lib     PATH_SUFFIXES openjpeg  NO_DEFAULT_PATH)
+ endif()
+ 
+-find_path(OPENJPEG_INCLUDE_DIR  openjpeg.h PATH_SUFFIXES openjpeg )
++find_path(OPENJPEG_INCLUDE_DIR  openjpeg.h PATH_SUFFIXES openjpeg openjpeg-2.1)
++
++set( OPENJPEG_VERSION 1)
+ find_library( OPENJPEG_LIBRARY  openjpeg   PATH_SUFFIXES openjpeg )
++if( NOT OPENJPEG_LIBRARY)
++  find_library( OPENJPEG_LIBRARY  openjp2   PATH_SUFFIXES openjpeg )
++  set (OPENJPEG_VERSION 2)
++endif()
+ 
+ set( OPENJPEG_LIBRARIES    ${OPENJPEG_LIBRARY} )
+ set( OPENJPEG_INCLUDE_DIRS ${OPENJPEG_INCLUDE_DIR} )
+Index: eccodes-0.16.0/src/grib_openjpeg_encoding.c
+===================================================================
+--- eccodes-0.16.0.orig/src/grib_openjpeg_encoding.c
++++ eccodes-0.16.0/src/grib_openjpeg_encoding.c
+@@ -11,24 +11,27 @@
+ #include "grib_api_internal.h"
+ 
+ #if HAVE_LIBOPENJPEG
++
+ #include "openjpeg.h"
+ 
+-/* TODO: Strip the \n from msg */
+ static void openjpeg_warning(const char *msg, void *client_data)
+ {
+-	grib_context_log((grib_context*)client_data,GRIB_LOG_WARNING,"OPENJPEG: %s",msg);
++	grib_context_log((grib_context*)client_data,GRIB_LOG_WARNING,"openjpeg: %s",msg);
+ }
+ 
+ static void openjpeg_error(const char *msg, void *client_data)
+ {
+-	grib_context_log((grib_context*)client_data,GRIB_LOG_ERROR,"OPENJPEG: %s",msg);
++	grib_context_log((grib_context*)client_data,GRIB_LOG_ERROR,"openjpeg: %s",msg);
+ }
+ 
+ static void openjpeg_info(const char *msg, void *client_data)
+ {
+-	/* grib_context_log((grib_context*)client_data,GRIB_LOG_INFO,"openjpeg: %s",msg); */
++	/* grib_context_log((grib_context*)client_data,GRIB_LOG_INFO,"openjpeg: %s",msg);  */
+ }
+ 
++#if defined(OPENJPEG_VERSION) && OPENJPEG_VERSION < 20000
++
++
+ int grib_openjpeg_encode(grib_context *c, j2k_encode_helper *helper) {
+ 
+ 	int err = GRIB_SUCCESS;
+@@ -164,7 +167,7 @@ int grib_openjpeg_decode(grib_context *c
+ 	image = opj_decode(dinfo, cio);
+ 
+ 	if(!image) {
+-		grib_context_log(c, GRIB_LOG_ERROR, "OPENJPEG: failed to decode image");
++		grib_context_log(c, GRIB_LOG_ERROR, "openjpeg: failed to decode image");
+ 		err = GRIB_DECODING_ERROR;
+ 		goto cleanup;
+ 	}
+@@ -201,7 +204,307 @@ cleanup:
+ 	return err;
+ }
+ 
+-#else
++#else /* OPENJPEG VERSION 2 */
++
++/* OpenJPEG 2.1 version of grib_openjpeg_encoding.c */
++
++/* opj_* Helper code from https://groups.google.com/forum/#!topic/openjpeg/8cebr0u7JgY */
++typedef struct
++{
++	OPJ_UINT8* pData; 
++	OPJ_SIZE_T dataSize; 
++	OPJ_SIZE_T offset; 
++	j2k_encode_helper *helper;
++} opj_memory_stream;
++
++static OPJ_SIZE_T opj_memory_stream_read(void *buffer, OPJ_SIZE_T nb_bytes, void * p_user_data)
++{
++	opj_memory_stream* mstream = (opj_memory_stream*) p_user_data; //Our data.
++	OPJ_SIZE_T nb_bytes_read = nb_bytes;  
++
++	//Check if the current offset is outside our data buffer.
++	if (mstream->offset >= mstream->dataSize) 
++		return (OPJ_SIZE_T) -1;
++
++	//Check if we are reading more than we have.
++	if (nb_bytes > (mstream->dataSize - mstream->offset))
++			nb_bytes_read = mstream->dataSize - mstream->offset;
++
++	memcpy(buffer, &(mstream->pData[mstream->offset]), nb_bytes_read);
++	mstream->offset += nb_bytes_read; 
++	return nb_bytes_read;
++}
++
++static OPJ_SIZE_T opj_memory_stream_write(void *buffer, OPJ_SIZE_T nb_bytes, void *user_data)
++{
++	opj_memory_stream* mstream = (opj_memory_stream*) user_data; // our data
++	OPJ_SIZE_T nb_bytes_write = nb_bytes;			     
++
++	if (mstream->offset >= mstream->dataSize) 
++		return (OPJ_SIZE_T)-1;
++	if (nb_bytes > (mstream->dataSize - mstream->offset))
++		nb_bytes_write = mstream->dataSize - mstream->offset;
++
++	memcpy(&(mstream->pData[mstream->offset]), buffer, nb_bytes_write);
++	mstream->offset += nb_bytes_write;
++	return nb_bytes_write;
++}
++
++static OPJ_OFF_T opj_memory_stream_skip(OPJ_OFF_T nb_bytes, void *user_data)
++{
++	opj_memory_stream* mstream = (opj_memory_stream*) user_data;
++	OPJ_SIZE_T l_nb_bytes;
++
++	if (nb_bytes < 0) 
++		return -1;
++	l_nb_bytes = (OPJ_SIZE_T) nb_bytes;
++ 	if (l_nb_bytes > mstream->dataSize - mstream->offset)
++ 			nb_bytes = mstream->dataSize - mstream->offset;
++	mstream->offset += l_nb_bytes;
++	return l_nb_bytes;
++}
++
++static OPJ_BOOL opj_memory_stream_seek(OPJ_OFF_T nb_bytes, void * user_data)
++{
++	opj_memory_stream* mstream = (opj_memory_stream*) user_data;
++
++	if (nb_bytes < 0) 
++		return OPJ_FALSE;
++	if (nb_bytes >(OPJ_OFF_T) mstream->dataSize) 
++		return OPJ_FALSE;
++	mstream->offset = (OPJ_SIZE_T) nb_bytes;
++}
++
++
++
++static void opj_memory_stream_do_nothing(void * p_user_data)
++{
++	OPJ_ARG_NOT_USED(p_user_data);
++}
++
++// Create a stream to use memory as the input or output
++opj_stream_t* opj_stream_create_default_memory_stream(opj_memory_stream* memoryStream, OPJ_BOOL is_read_stream)
++{
++	opj_stream_t* stream;
++
++	if (!(stream = opj_stream_default_create(is_read_stream))) 
++		return (NULL);
++	if (is_read_stream)
++		opj_stream_set_read_function(stream, opj_memory_stream_read);
++	else
++		opj_stream_set_write_function(stream, opj_memory_stream_write);
++
++	opj_stream_set_seek_function(stream, opj_memory_stream_seek);
++	opj_stream_set_skip_function(stream, opj_memory_stream_skip);
++	opj_stream_set_user_data(stream, memoryStream, opj_memory_stream_do_nothing);
++	opj_stream_set_user_data_length(stream, memoryStream->dataSize);
++	return stream;
++}
++
++int grib_openjpeg_encode(grib_context *c, j2k_encode_helper *helper) {
++
++	int err = GRIB_SUCCESS;
++	const int numcomps = 1;
++	int i;
++
++	const double * values   = helper->values;
++	long  no_values        = helper->no_values;
++	double reference_value = helper->reference_value;
++	double divisor         = helper->divisor;
++	double decimal         = helper->decimal;
++	int*   data;
++
++	opj_cparameters_t parameters = {0,};	/* compression parameters */
++	opj_codec_t *codec = NULL;
++	opj_image_t *image = NULL;
++	opj_image_cmptparm_t cmptparm = {0,};
++	opj_stream_t *stream = NULL;
++	opj_memory_stream mstream;
++
++	/* set encoding parameters to default values */
++	opj_set_default_encoder_parameters(&parameters);
++
++	parameters.tcp_numlayers  = 1;
++	parameters.cp_disto_alloc = 1;
++	parameters.numresolution =  1;
++	parameters.tcp_rates[0]   = helper->compression;
++
++	/* initialize image component */  
++	cmptparm.prec = helper->bits_per_value; 
++	cmptparm.bpp  = helper->bits_per_value; /* Not sure about this one and the previous. What is the difference? */
++	cmptparm.sgnd = 0;
++	cmptparm.dx   = 1;
++	cmptparm.dy   = 1;
++	cmptparm.w    = helper->width;
++	cmptparm.h    = helper->height;
++
++	/* create the image */
++	image = opj_image_create(numcomps, &cmptparm, OPJ_CLRSPC_GRAY);
++	if(!image) {
++		err = GRIB_ENCODING_ERROR;
++		goto cleanup;
++	}
++	image->x0 = 0;
++	image->y0 = 0;
++	image->x1 = helper->width;
++	image->y1 = helper->height;
++
++	Assert(cmptparm.prec <= sizeof(image->comps[0].data[0])*8 - 1); /* BR: -1 because I don't know what happens if the sign bit is set */
++	Assert(helper->no_values ==  image->comps[0].h * image->comps[0].w);
++
++	/* Simple packing */
++	data = image->comps[0].data;
++	for(i=0;i< no_values;i++){
++		unsigned long unsigned_val = (unsigned long)((((values[i]*decimal)-(reference_value))*divisor)+0.5);
++		data[i] = unsigned_val;
++	}
++
++	/* get a J2K compressor handle */
++	codec = opj_create_compress(OPJ_CODEC_J2K);
++
++	opj_set_info_handler(codec, openjpeg_info, c);
++	opj_set_warning_handler(codec, openjpeg_warning, c);
++	opj_set_error_handler(codec, openjpeg_error,c);
++
++	/* setup the encoder parameters using the current image and user parameters */
++	if (!opj_setup_encoder(codec, &parameters, image)) {
++	  grib_context_log(c, GRIB_LOG_ERROR, "openjpeg: failed to setup encoder");
++	  err = GRIB_ENCODING_ERROR;
++	  goto cleanup;
++	}
++
++	/* open a byte stream for writing */
++	mstream.helper = helper;
++	mstream.pData = (OPJ_UINT8*) helper->jpeg_buffer;
++	mstream.offset = 0;
++	mstream.dataSize = helper->buffer_size;
++	stream = opj_stream_create_default_memory_stream( &mstream, OPJ_STREAM_WRITE);
++	if (stream == NULL) {
++	        grib_context_log(c, GRIB_LOG_ERROR, "openjpeg: failed create default memory stream");
++		err = GRIB_ENCODING_ERROR;
++		goto cleanup;
++	}
++	if (!opj_start_compress(codec, image, stream)) {
++	        grib_context_log(c, GRIB_LOG_ERROR, "openjpeg: failed to setup encoder");
++		err = GRIB_ENCODING_ERROR;
++		goto cleanup;
++	}
++
++	/* encode image */
++	if (!opj_encode(codec, stream)) {
++	       	grib_context_log(c, GRIB_LOG_ERROR, "openjpeg: opj_encode failed");
++		err = GRIB_ENCODING_ERROR;
++		goto cleanup;
++	}
++
++	if (!opj_end_compress(codec, stream)) {
++	        grib_context_log(c, GRIB_LOG_ERROR, "openjpeg: opj_end_compress failed");
++		err = GRIB_ENCODING_ERROR;
++		goto cleanup;
++	}
++	helper->jpeg_length = mstream.offset;
++
++
++cleanup:
++	if (codec)   opj_destroy_codec(codec);
++	if (stream) opj_stream_destroy(stream);
++	if (image) opj_image_destroy(image);
++
++	return err;
++}
++
++int grib_openjpeg_decode(grib_context *c, unsigned char *buf, size_t *buflen, double *val, size_t *n_vals) {
++
++	int err = GRIB_SUCCESS;
++	int i;
++	unsigned long  mask;
++	int *data;
++	size_t count;
++
++	opj_dparameters_t parameters = {0,};	/* decompression parameters */
++	opj_stream_t *stream = NULL;
++	opj_memory_stream mstream;
++	opj_image_t *image = NULL;
++	opj_codec_t *codec = NULL;
++	opj_image_comp_t comp = {0,};
++
++	/* set decoding parameters to default values */
++	opj_set_default_decoder_parameters(&parameters);
++        parameters.decod_format = 1; /* JP2_FMT */
++	/* JPEG-2000 codestream */
++
++	/* get a decoder handle */
++	codec = opj_create_decompress(OPJ_CODEC_J2K);
++
++	/* catch events using our callbacks and give a local context */
++	opj_set_info_handler(codec, openjpeg_info, c);
++	opj_set_warning_handler(codec, openjpeg_warning, c);
++	opj_set_error_handler(codec, openjpeg_error,c);
++
++	/* initialize our memory stream */
++	mstream.pData = buf;
++	mstream.dataSize = *buflen;
++	mstream.offset = 0;
++	/* open a byte stream from memory stream */
++	stream = opj_stream_create_default_memory_stream( &mstream, OPJ_STREAM_READ);
++
++	/* setup the decoder decoding parameters using user parameters */
++	if (!opj_setup_decoder(codec, &parameters)) {
++		grib_context_log(c, GRIB_LOG_ERROR, "openjpeg: failed to setup decoder");
++		err = GRIB_DECODING_ERROR;
++		goto cleanup;
++	}
++	if  (!opj_read_header(stream, codec, &image)) {
++	        grib_context_log(c, GRIB_LOG_ERROR, "openjpeg: failed to read the header");
++		err = GRIB_DECODING_ERROR;
++		goto cleanup;
++	}
++	if (!opj_decode(codec, stream, image)) {
++   	  grib_context_log(c, GRIB_LOG_ERROR, "openjpeg: failed to decode");
++	  err = GRIB_DECODING_ERROR;
++	  goto cleanup;
++	}
++	
++	if ( !(*n_vals <= image->comps[0].w * image->comps[0].h) ) {
++		err = GRIB_DECODING_ERROR;
++		goto cleanup;
++	}
++	if ( (image->numcomps != 1) || !(image->x1 * image->y1) ) {
++		err = GRIB_DECODING_ERROR;
++		goto cleanup;
++	}
++
++	Assert(image->comps[0].sgnd == 0);
++	Assert(comp.prec <= sizeof(image->comps[0].data[0])*8 - 1); /* BR: -1 because I don't know what happens if the sign bit is set */
++
++       
++	Assert(image->comps[0].prec < sizeof(mask)*8-1);
++
++	data = image->comps[0].data;
++	mask = (1 << image->comps[0].prec) - 1;
++
++	count = image->comps[0].w * image->comps[0].h;
++
++	for(i = 0; i <count ; i++)
++			val[i] = data[i] & mask;
++
++	if (!opj_end_decompress(codec, stream)) {
++	  grib_context_log(c, GRIB_LOG_ERROR, "openjpeg: failed in opj_end_decompress");
++	  err = GRIB_DECODING_ERROR;
++	}
++	  
++cleanup:
++	/* close the byte stream */
++	if (codec)   opj_destroy_codec(codec);
++	if (stream) opj_stream_destroy(stream);
++	if (image) opj_image_destroy(image);
++
++	return err;
++}
++
++#endif /* OPENJPEG_VERSION */
++
++#else /* No OpenJPEG */
+ 
+ int grib_openjpeg_decode(grib_context *c, unsigned char *buf, size_t *buflen, double *val, size_t *n_vals) {
+ 	grib_context_log(c, GRIB_LOG_ERROR,
diff --git a/debian/patches/py3-fixes.patch b/debian/patches/py3-fixes.patch
new file mode 100644
index 0000000..816fc15
--- /dev/null
+++ b/debian/patches/py3-fixes.patch
@@ -0,0 +1,142 @@
+Index: eccodes-0.16.0/python/CMakeLists.txt
+===================================================================
+--- eccodes-0.16.0.orig/python/CMakeLists.txt
++++ eccodes-0.16.0/python/CMakeLists.txt
+@@ -1,9 +1,9 @@
+ if( HAVE_PYTHON )
+ 
+-    #find_package( SWIG )
+-    #if( SWIG_FOUND )
+-    #    include( ${SWIG_USE_FILE} )
+-    #endif()
++    find_package( SWIG )
++    if( SWIG_FOUND )
++        include( ${SWIG_USE_FILE} )
++    endif()
+ 
+     # check for Numpy
+     find_package( NumPy )
+@@ -55,6 +55,9 @@ if( HAVE_PYTHON )
+         # compile swig interface
+ 
+         set(CMAKE_SWIG_FLAGS "")
++	if (${PYTHON_VERSION_MAJOR} EQUAL 3)
++	  set_source_files_properties( gribapi_swig.i PROPERTIES SWIG_FLAGS "-py3" )
++	endif()
+ 
+         include_directories( ${PYTHON_INCLUDE_PATH} )
+ 
+@@ -66,15 +69,15 @@ if( HAVE_PYTHON )
+         endif()
+ 
+         # Invoke swig to generate the C wrapper
+-        #  swig_add_module( gribapi_swig python grib_interface.h grib_interface.c gribapi_swig.i )
+-        #  swig_link_libraries( gribapi_swig grib_api ${PYTHON_LIBRARIES} )
+-
++        swig_add_module( gribapi_swig python grib_interface.h grib_interface.c gribapi_swig.i )
++        swig_link_libraries( gribapi_swig grib_api ${PYTHON_LIBRARIES} )
++	
+         ####### Do not invoke swig. Use our own generated C wrapper file ######
+-        ecbuild_add_library(TARGET    _gribapi_swig
+-                            TYPE SHARED
+-                            NOINSTALL
+-                            SOURCES   grib_interface.h grib_interface.c ${_swig_c_wrapper}
+-                            LIBS      eccodes ${PYTHON_LIBRARIES} )
++        #ecbuild_add_library(TARGET    _gribapi_swig
++        #                    TYPE SHARED
++        #                    NOINSTALL
++        #                    SOURCES   grib_interface.h grib_interface.c ${_swig_c_wrapper}
++        #                    LIBS      eccodes ${PYTHON_LIBRARIES} )
+         # Don't use the lib prefix.  This is needed for the python case where a _modulename.so is generated
+         set_target_properties(_gribapi_swig PROPERTIES PREFIX "")
+ 
+Index: eccodes-0.16.0/python/gribapi_swig.i
+===================================================================
+--- eccodes-0.16.0.orig/python/gribapi_swig.i
++++ eccodes-0.16.0/python/gribapi_swig.i
+@@ -21,14 +21,17 @@ import_array();
+ 
+ #endif
+ 
+-/* Converts a PyFile instance to a stdio FILE* */
++
++ /* FIXME: Can we make this ro/rw ? */
+ %typemap(in) FILE* {
+-    if ( PyFile_Check($input) ){
+-        $1 = PyFile_AsFile($input);
+-    } else {
+-        PyErr_SetString(PyExc_TypeError, "$1_name must be a file type.");
+-        return NULL;
+-    }
++  int fd;
++  fd = PyObject_AsFileDescriptor($input);
++  if ( fd >= 0 ) {
++    $1 = fopen(fd, "r+"); 
++  } else {
++    PyErr_SetString(PyExc_TypeError, "$1_name must be a file type.");
++    return NULL;
++  }
+ }
+ 
+ %pointer_class(int, intp);
+@@ -69,6 +72,7 @@ int grib_c_count_in_file(FILE* f,int* OU
+ // grib handle operations
+ int grib_c_release(int* gid);
+ int grib_c_write(int* gid, FILE* f);
++
+ int grib_c_get_size_long(int* gid, char* key, long* OUTPUT);
+ int grib_c_get_string_length(int* gid, char* key, size_t* OUTPUT);
+ int grib_c_clone(int* gid,int* INOUT);
+@@ -79,9 +83,9 @@ int grib_c_get_native_type(int* gid, cha
+ // ---
+ 
+ // multi support
++int grib_c_multi_write(int* gid, FILE* f);
+ int grib_c_multi_new(int* OUTPUT);
+ int grib_c_multi_support_on(void);
+-int grib_c_multi_write(int* gid, FILE* f);
+ int grib_c_multi_support_off(void);
+ int grib_c_multi_release(int* gid);
+ int grib_c_multi_append(int* INPUT, int* INPUT,int* INPUT);
+Index: eccodes-0.16.0/python/gribapi.py
+===================================================================
+--- eccodes-0.16.0.orig/python/gribapi.py
++++ eccodes-0.16.0/python/gribapi.py
+@@ -26,8 +26,10 @@ NumPy support can be disabled by using t
+ """
+ 
+ from __future__ import print_function
+-import gribapi_swig as _internal
++from . import gribapi_swig as _internal
+ #from gribapi import gribapi_swig as _internal
++from six import get_function_code
++from io import _io
+ import types
+ import sys
+ import os
+@@ -63,6 +65,9 @@ GRIB_MISSING_LONG = 2147483647
+ # environment variable is defined
+ no_type_checks = os.environ.get('GRIB_API_PYTHON_NO_TYPE_CHECKS') is not None
+ 
++if sys.version_info.major == 3:
++    file = _io.TextIOWrapper
++    long = int
+ 
+ # Function-arguments type-checking decorator
+ # inspired from http://code.activestate.com/recipes/454322-type-checking-decorator/
+@@ -77,12 +82,13 @@ def require(**_params_):
+         @wraps(_func_)
+         # The wrapper function. Replaces the target function and receives its args
+         def modified(*args, **kw):
+-            arg_names = _func_.__code__.func_code.co_varnames
++            code = get_function_code(_func_)
++            arg_names = code.co_varnames
+             # argnames, varargs, kwargs, defaults = inspect.getargspec(_func_)
+             kw.update(list(zip(arg_names, args)))
+             for name, allowed_types in _params_.items():
+                 param = kw[name]
+-                if isinstance(allowed_types, types):
++                if isinstance(allowed_types, type):
+                     allowed_types = (allowed_types,)
+                 assert any([isinstance(param, type1) for type1 in allowed_types]), \
+                     "Parameter '%s' should be of type %s" % (name, " or ".join([t.__name__ for t in allowed_types]))
diff --git a/debian/patches/python3.patch b/debian/patches/python3.patch
new file mode 100644
index 0000000..458595d
--- /dev/null
+++ b/debian/patches/python3.patch
@@ -0,0 +1,595 @@
+Author: Alastair McKinstry <mckinstry at debian.org>
+Description: Support for Python3
+Forwarded: no
+Last-Updated: 2016-04-30
+
+Index: eccodes-0.16.0/python/test_iterator.py
+===================================================================
+--- eccodes-0.16.0.orig/python/test_iterator.py
++++ eccodes-0.16.0/python/test_iterator.py
+@@ -1,7 +1,8 @@
+ #!/usr/bin/env python
+ 
++from __future__ import print_function
+ import sys
+-from gribapi import *
++from .gribapi import *
+ import profile
+ 
+ def main():
+@@ -26,12 +27,12 @@ def main():
+             sys.stdout.write("- %d - lat=%.6f lon=%.6f value=" % (i,lat,lon))
+ 
+             if value == missingValue:
+-                print "missing"
++                print("missing")
+             else:
+-                print "%.6f" % value
++                print("%.6f" % value)
+ 
+             i += 1
+-            
++
+         grib_iterator_delete(iterid)
+         grib_release(gid)
+ 
+Index: eccodes-0.16.0/python/test_index.py
+===================================================================
+--- eccodes-0.16.0.orig/python/test_index.py
++++ eccodes-0.16.0/python/test_index.py
+@@ -1,7 +1,8 @@
+ #!/usr/bin/env python
+ 
++from __future__ import print_function
+ import sys
+-from gribapi import *
++from .gribapi import *
+ from array import array
+ import random
+ import traceback
+@@ -17,7 +18,7 @@ class Usage(Exception):
+ def product(*args, **kwds):
+     # product('ABCD', 'xy') --> Ax Ay Bx By Cx Cy Dx Dy
+     # product(range(2), repeat=3) --> 000 001 010 011 100 101 110 111
+-    pools = map(tuple, args) * kwds.get('repeat', 1)
++    pools = list(map(tuple, args)) * kwds.get('repeat', 1)
+     result = [[]]
+     for pool in pools:
+         result = [x+[y] for x in result for y in pool]
+@@ -34,20 +35,20 @@ def test():
+     infile = sys.argv[1]
+     index_keys = ["shortName","level","number","step"]
+ 
+-    print "indexing..."
++    print ("indexing...")
+     iid = grib_index_new_from_file(infile,index_keys)
+-    print "end indexing..."
++    print ("end indexing...")
+ 
+     index_vals = []
+ 
+     for key in index_keys:
+-        print "%sSize=%d" % (
++        print ("%sSize=%d" % (
+             key,
+             grib_index_get_size(iid,key)
+-        )
++        ))
+ 
+         key_vals = grib_index_get_string(iid,key)
+-        print " ".join(key_vals)
++        print (" ".join(key_vals))
+ 
+         index_vals.append(key_vals)
+ 
+@@ -58,7 +59,7 @@ def test():
+         while 1:
+             gid = grib_new_from_index(iid)
+             if gid is None: break
+-            print " ".join(["%s=%s" % (key,grib_get_string(gid,key)) for key in index_keys])
++            print (" ".join(["%s=%s" % (key,grib_get_string(gid,key)) for key in index_keys]))
+             grib_release(gid)
+ 
+     grib_index_release(iid)
+@@ -67,17 +68,17 @@ def test():
+ def main():
+     try:
+         test()
+-    except GribInternalError,err:
++    except GribInternalError as err:
+         if VERBOSE:
+             traceback.print_exc(file=sys.stderr)
+         else:
+-            print >>sys.stderr,err.msg
++            print (err.msg, file=sys.stderr)
+ 
+         return 1
+     except Usage:
+-        print "Usage: %s infile" % sys.argv[0]
++        print ("Usage: %s infile" % sys.argv[0])
+         sys.exit(2)
+ 
+ if __name__ == "__main__":
+     main()
+-    #print "------------------------------------"
++    #print ("------------------------------------")
+Index: eccodes-0.16.0/python/test_keysiterator.py
+===================================================================
+--- eccodes-0.16.0.orig/python/test_keysiterator.py
++++ eccodes-0.16.0/python/test_keysiterator.py
+@@ -1,7 +1,8 @@
+ #!/usr/bin/env python
+ 
++from __future__ import print_function
+ import sys
+-from gribapi import *
++from .gribapi import *
+ 
+ infile = sys.argv[1]
+ fid = open(infile,"r")
+@@ -22,11 +23,9 @@ for i in range(count):
+         keyname = grib_keys_iterator_get_name(iterid)
+         keyval = grib_get_string(iterid,keyname)
+         keytype = grib_get_native_type(gid,keyname)
+-        print "%s = %s (%s)" % (keyname,keyval,str(keytype))
++        print ("%s = %s (%s)" % (keyname,keyval,str(keytype)))
+ 
+     grib_keys_iterator_delete(iterid)
+     grib_release(gid)
+ 
+ fid.close()
+-
+-
+Index: eccodes-0.16.0/python/test_general.py
+===================================================================
+--- eccodes-0.16.0.orig/python/test_general.py
++++ eccodes-0.16.0/python/test_general.py
+@@ -1,7 +1,8 @@
+ #!/usr/bin/env python
+ 
++from __future__ import print_function
+ import sys
+-from gribapi import *
++from .gribapi import *
+ import random
+ import traceback
+ 
+@@ -44,25 +45,25 @@ def test():
+     #grib_write_file(binstr_fid,x)
+     #grib_close_file(binstr_fid)
+ 
+-    print "Operating on file '%s'" % infile
++    print ("Operating on file '%s'" % infile)
+ 
+     n = grib_count_in_file(fid)
+-    print "Message count ",n
++    print ("Message count ",n)
+ 
+     # multi support test
+     grib_multi_support_on()
+     ismulti = "no" if (n == grib_count_in_file(fid)) else "yes"
+-    print "Is multi field - %s" % ismulti
++    print ("Is multi field - %s" % ismulti)
+     grib_multi_support_off()
+     # end multi support test
+ 
+     # gribex support test on/off
+-    print "Gribex support on/off"
++    print ("Gribex support on/off")
+     grib_gribex_mode_on()
+     grib_gribex_mode_off
+     # end gribex support test
+ 
+-    print "Browsing through messages "
++    print ("Browsing through messages ")
+     for i in range(n):
+         gid = grib_new_from_file(fid)
+ 
+@@ -70,71 +71,71 @@ def test():
+         #grib_print(gid,"centre")
+ 
+         if i == 0:
+-            print "Message size: ",grib_get_message_size(gid)
++            print ("Message size: ",grib_get_message_size(gid))
+             nval = grib_get_size(gid,"values")
+-            print "Number of values in message %d is %d" % (i,nval)
++            print ("Number of values in message %d is %d" % (i,nval))
+ 
+-            print "== %s %s %s %d ==" % \
++            print ("== %s %s %s %d ==" % \
+                 ( \
+                 grib_get_string(gid,"shortName"), \
+                 grib_get_string(gid,"name"), \
+                 grib_get_string(gid,"typeOfLevel"), \
+                 grib_get_long(gid,"level"), \
+-                )
++                ))
+ 
+-            print "Nearest point to 10,10: "
+-            print grib_find_nearest(gid,10,10)
++            print ("Nearest point to 10,10: ")
++            print (grib_find_nearest(gid,10,10))
+ 
+-            print grib_find_nearest(gid,10,10,npoints=4)
++            print (grib_find_nearest(gid,10,10,npoints=4))
+ 
+             rand_list = []
+             for i in range(0,5):
+                 rand_index = random.randint(1,nval)
+                 rand_list.append(rand_index)
+                 myval = grib_get_double_element(gid,"values",rand_index)
+-                print "Random index value[%d] = %.8f" % (rand_index,myval)
++                print ("Random index value[%d] = %.8f" % (rand_index,myval))
+ 
+             all4rand = grib_get_double_elements(gid,"values",rand_list)
+-            print "All at once index values: ",all4rand
++            print ("All at once index values: ",all4rand)
+ 
+             centre = grib_get_string(gid,"centre")
+             grib_set_string(gid,"centre","ecmf")
+             new_centre = grib_get_string(gid,"centre")
+-            print "Before/after string centre: %s/%s" % (centre,new_centre)
++            print ("Before/after string centre: %s/%s" % (centre,new_centre))
+ 
+             centre = grib_get_long(gid,"centre")
+             grib_set_long(gid,"centre",99)
+             new_centre = grib_get_long(gid,"centre")
+-            print "Before/after numeric centre: %d/%d" % (centre,new_centre)
++            print ("Before/after numeric centre: %d/%d" % (centre,new_centre))
+ 
+             centre = grib_get_double(gid,"centre")
+             grib_set_double(gid,"centre",9)
+             new_centre = grib_get_double(gid,"centre")
+-            print "Before/after numeric floating point centre: %f/%f" % (centre,new_centre)
++            print ("Before/after numeric floating point centre: %f/%f" % (centre,new_centre))
+ 
+             vals = grib_get_double_array(gid,"values")
+-            print "Values before: ",vals[:10]
++            print ("Values before: ",vals[:10])
+             grib_set_double_array(gid,"values",(1.0, 2.0, 3.14))
+             vals = grib_get_double_array(gid,"values")
+-            print "Values after: ",vals[:10]
++            print ("Values after: ",vals[:10])
+ 
+-            print "Saving modified message to %s" % outfile
++            print ("Saving modified message to %s" % outfile)
+             if WRITE: grib_write(gid,out)
+ 
+-            print "Creating and saving a clone to %s" % clonefile
++            print ("Creating and saving a clone to %s" % clonefile)
+             clone_gid = grib_clone(gid)
+             if WRITE: grib_write(clone_gid,clone_fid)
+             grib_release(clone_gid)
+ 
+             Ni = grib_get(gid,"Ni")
+-            print "Setting Ni to missing from --> ",Ni
++            print ("Setting Ni to missing from --> ",Ni)
+             grib_set_missing(gid,"Ni")
+             assert grib_is_missing(gid,"Ni")
+             miss_Ni = grib_get(gid,"Ni")
+-            print "Ni is now --> ",miss_Ni
++            print ("Ni is now --> ",miss_Ni)
+             grib_set(gid,"Ni",Ni)
+             new_Ni = grib_get(gid,"Ni")
+-            print "Set Ni back to its original value --> ",new_Ni
++            print ("Set Ni back to its original value --> ",new_Ni)
+             assert Ni == new_Ni
+ 
+             #grib_multi_write(gid,multi)
+@@ -145,23 +146,23 @@ def test():
+     fid.close()
+     out.close()
+     clone_fid.close()
+-    print "Closed file"
++    print ("Closed file")
+ 
+ 
+ def main():
+     try:
+         test()
+-    except GribInternalError,err:
++    except GribInternalError as err:
+         if VERBOSE:
+             traceback.print_exc(file=sys.stderr)
+         else:
+-            print >>sys.stderr,err.msg
++            print (err.msg, file=sys.stderr)
+ 
+         return 1
+     except Usage:
+-        print "Usage: %s infile" % sys.argv[0]
++        print ("Usage: %s infile" % sys.argv[0])
+         sys.exit(2)
+ 
+ if __name__ == "__main__":
+     main()
+-    print "------------------------------------"
++    print ("------------------------------------")
+Index: eccodes-0.16.0/python/test_extra.py
+===================================================================
+--- eccodes-0.16.0.orig/python/test_extra.py
++++ eccodes-0.16.0/python/test_extra.py
+@@ -1,6 +1,7 @@
+ #!/usr/bin/env python
+ 
+-from gribapi import *
++from __future__ import print_function
++from .gribapi import *
+ import sys
+ 
+ input=sys.argv[1]
+@@ -12,31 +13,31 @@ while 1:
+     gid = grib_new_from_file(fid)
+     if gid is None: break
+ 
+-    print grib_get(gid,"centre")
+-    print grib_get(gid,"centre",int)
+-    print grib_get(gid,"centre",float)
+-    print grib_get(gid,"centre",str)
++    print (grib_get(gid,"centre"))
++    print (grib_get(gid,"centre",int))
++    print (grib_get(gid,"centre",float))
++    print (grib_get(gid,"centre",str))
+ 
+-    print "Nvalues = ",grib_get_size(gid,"values")
++    print ("Nvalues = ",grib_get_size(gid,"values"))
+ 
+     values = grib_get_array(gid,"values")
+-    print values[:10]
++    print (values[:10])
+     values = values * 2
+ 
+     grib_set_double_array(gid,"values",values)
+ 
+     values = grib_get_array(gid,"values")
+-    print values[:10]
++    print (values[:10])
+     values = values / 2
+ 
+     grib_set_double_array(gid,"values",[1])
+ 
+     values = grib_get_values(gid)
+-    print values[:10]
++    print (values[:10])
+ 
+-    print grib_get(gid,"bitsPerValue")
++    print (grib_get(gid,"bitsPerValue"))
+     grib_set(gid,"bitsPerValue",10)
+-    print grib_get(gid,"bitsPerValue")
++    print (grib_get(gid,"bitsPerValue"))
+ 
+     grib_write(gid,oid)
+ 
+Index: eccodes-0.16.0/python/gribapi.py
+===================================================================
+--- eccodes-0.16.0.orig/python/gribapi.py
++++ eccodes-0.16.0/python/gribapi.py
+@@ -24,6 +24,8 @@ NumPy support can be disabled by using t
+     - NumPy
+ 
+ """
++
++from __future__ import print_function
+ import gribapi_swig as _internal
+ #from gribapi import gribapi_swig as _internal
+ import types
+@@ -75,12 +77,12 @@ def require(**_params_):
+         @wraps(_func_)
+         # The wrapper function. Replaces the target function and receives its args
+         def modified(*args, **kw):
+-            arg_names = _func_.func_code.co_varnames
++            arg_names = _func_.__code__.func_code.co_varnames
+             # argnames, varargs, kwargs, defaults = inspect.getargspec(_func_)
+-            kw.update(zip(arg_names, args))
+-            for name, allowed_types in _params_.iteritems():
++            kw.update(list(zip(arg_names, args)))
++            for name, allowed_types in _params_.items():
+                 param = kw[name]
+-                if isinstance(allowed_types, types.TypeType):
++                if isinstance(allowed_types, types):
+                     allowed_types = (allowed_types,)
+                 assert any([isinstance(param, type1) for type1 in allowed_types]), \
+                     "Parameter '%s' should be of type %s" % (name, " or ".join([t.__name__ for t in allowed_types]))
+@@ -133,7 +135,7 @@ class Bunch(dict):
+     def __str__(self):
+         state = ["%s=%r" % (attribute, value)
+                  for (attribute, value)
+-                 in self.__dict__.items()]
++                 in list(self.__dict__.items())]
+         return '\n'.join(state)
+ 
+ 
+@@ -774,7 +776,7 @@ def grib_set_long(gribid, key, value):
+     except (ValueError, TypeError):
+         raise TypeError("Invalid type")
+ 
+-    if value > sys.maxint:
++    if value > sys.maxintsize:
+         raise TypeError("Invalid type")
+ 
+     GRIB_CHECK(_internal.grib_c_set_long(gribid, key, value))
+@@ -1431,7 +1433,7 @@ def grib_set_key_vals(gribid, key_vals):
+             key_vals_str += kv
+     elif isinstance(key_vals, dict):
+         # A dictionary mapping keys to values
+-        for key in key_vals.iterkeys():
++        for key in key_vals.keys():
+             if len(key_vals_str) > 0:
+                 key_vals_str += ','
+             key_vals_str += key + '=' + str(key_vals[key])
+Index: eccodes-0.16.0/examples/python/keys_iterator_gts.py
+===================================================================
+--- eccodes-0.16.0.orig/examples/python/keys_iterator_gts.py
++++ eccodes-0.16.0/examples/python/keys_iterator_gts.py
+@@ -9,6 +9,7 @@
+ # nor does it submit to any jurisdiction.
+ #
+ 
++from __future__ import print_function
+ import traceback
+ import sys
+ 
+@@ -36,7 +37,7 @@ def example():
+         while codes_keys_iterator_next(iterid):
+             keyname = codes_keys_iterator_get_name(iterid)
+             keyval = codes_get_string(iterid, keyname)
+-            print "%s = %s" % (keyname, keyval)
++            print ("%s = %s" % (keyname, keyval))
+ 
+         codes_keys_iterator_delete(iterid)
+         codes_release(bid)
+@@ -47,11 +48,11 @@ def example():
+ def main():
+     try:
+         example()
+-    except CodesInternalError, err:
++    except CodesInternalError as err:
+         if VERBOSE:
+             traceback.print_exc(file=sys.stderr)
+         else:
+-            print >> sys.stderr, err.msg
++            print (err.msg, file=sys.stderr)
+ 
+         return 1
+ 
+Index: eccodes-0.16.0/examples/python/samples.py
+===================================================================
+--- eccodes-0.16.0.orig/examples/python/samples.py
++++ eccodes-0.16.0/examples/python/samples.py
+@@ -9,6 +9,7 @@
+ # nor does it submit to any jurisdiction.
+ #
+ 
++from __future__ import print_function
+ import traceback
+ import sys
+ 
+@@ -75,11 +76,11 @@ def example():
+ def main():
+     try:
+         example()
+-    except CodesInternalError, err:
++    except CodesInternalError as err:
+         if VERBOSE:
+             traceback.print_exc(file=sys.stderr)
+         else:
+-            print >>sys.stderr, err.msg
++            print (err.msg, file=sys.stderr)
+ 
+         return 1
+ 
+Index: eccodes-0.16.0/examples/python/keys_iterator_bufr.py
+===================================================================
+--- eccodes-0.16.0.orig/examples/python/keys_iterator_bufr.py
++++ eccodes-0.16.0/examples/python/keys_iterator_bufr.py
+@@ -9,6 +9,7 @@
+ # nor does it submit to any jurisdiction.
+ #
+ 
++from __future__ import print_function
+ import traceback
+ import sys
+ 
+Index: eccodes-0.16.0/examples/python/count_messages.py
+===================================================================
+--- eccodes-0.16.0.orig/examples/python/count_messages.py
++++ eccodes-0.16.0/examples/python/count_messages.py
+@@ -9,6 +9,7 @@
+ # nor does it submit to any jurisdiction.
+ #
+ 
++from __future__ import print_function
+ import traceback
+ import sys
+ 
+@@ -40,19 +41,19 @@ def example():
+     for i in range(mcount):
+         gid = gid_list[i]
+ 
+-        print "processing message number", i + 1
++        print ("processing message number", i + 1)
+ 
+         for key in keys:
+-            print '%s=%g' % (key, codes_get(gid, key))
++            print ('%s=%g' % (key, codes_get(gid, key)))
+ 
+-        print 'There are %d, average is %g, min is %g, max is %g' % (
++        print ('There are %d, average is %g, min is %g, max is %g' % (
+             codes_get_size(gid, 'values'),
+             codes_get(gid, 'average'),
+             codes_get(gid, 'min'),
+             codes_get(gid, 'max')
+-        )
++        ))
+ 
+-        print '-' * 100
++        print ('-' * 100)
+ 
+         codes_release(gid)
+ 
+@@ -60,11 +61,11 @@ def example():
+ def main():
+     try:
+         example()
+-    except CodesInternalError, err:
++    except CodesInternalError as err:
+         if VERBOSE:
+             traceback.print_exc(file=sys.stderr)
+         else:
+-            print >>sys.stderr, err.msg
++            print (err.msg, file=sys.stderr)
+ 
+         return 1
+ 
+Index: eccodes-0.16.0/examples/python/set_missing.py
+===================================================================
+--- eccodes-0.16.0.orig/examples/python/set_missing.py
++++ eccodes-0.16.0/examples/python/set_missing.py
+@@ -9,6 +9,7 @@
+ # nor does it submit to any jurisdiction.
+ #
+ 
++from __future__ import print_function
+ import traceback
+ import sys
+ 
+@@ -45,11 +46,11 @@ def example():
+ def main():
+     try:
+         example()
+-    except CodesInternalError, err:
++    except CodesInternalError as err:
+         if VERBOSE:
+             traceback.print_exc(file=sys.stderr)
+         else:
+-            print >>sys.stderr, err.msg
++            print (err.msg, file=sys.stderr)
+ 
+         return 1
+ 
+Index: eccodes-0.16.0/examples/python/binary_message.py
+===================================================================
+--- eccodes-0.16.0.orig/examples/python/binary_message.py
++++ eccodes-0.16.0/examples/python/binary_message.py
+@@ -9,6 +9,7 @@
+ # nor does it submit to any jurisdiction.
+ #
+ 
++from __future__ import print_function
+ import traceback
+ import sys
+ 
+@@ -41,11 +42,11 @@ def example():
+ def main():
+     try:
+         example()
+-    except CodesInternalError, err:
++    except CodesInternalError as err:
+         if VERBOSE:
+             traceback.print_exc(file=sys.stderr)
+         else:
+-            print >>sys.stderr, err.msg
++            print (err.msg, file=sys.stderr)
+ 
+         return 1
+ 
diff --git a/debian/patches/reproducible.patch b/debian/patches/reproducible.patch
new file mode 100644
index 0000000..a59c109
--- /dev/null
+++ b/debian/patches/reproducible.patch
@@ -0,0 +1,116 @@
+Author: Alastair McKinstry <mckinstry at debian.org>
+Description: Make builds bit-reproducible
+Last-Updated: 2016-01-08
+Forwarded: https://software.ecmwf.int/issues/browse/SUP-1590 
+
+Index: eccodes-0.16.0/CMakeLists.txt
+===================================================================
+--- eccodes-0.16.0.orig/CMakeLists.txt
++++ eccodes-0.16.0/CMakeLists.txt
+@@ -71,6 +71,12 @@ ecbuild_add_option( FEATURE FORTRAN
+     # REQUIRED_LANGUAGES Fortran # TODO
+ )
+ 
++ecbuild_add_option( FEATURE BIT_REPRODUCIBLE
++    DESCRIPTION "build bit-reproducible package"
++    DEFAULT ON
++    # Required for Debian, soon the world ...
++)
++
+ # TODO Remove this after REQUIRED_LANGUAGES
+ if( ENABLE_FORTRAN )
+     # will set EC_HAVE_FORTRAN with the result
+Index: eccodes-0.16.0/cmake/ecbuild_config.h.in
+===================================================================
+--- eccodes-0.16.0.orig/cmake/ecbuild_config.h.in
++++ eccodes-0.16.0/cmake/ecbuild_config.h.in
+@@ -142,14 +142,18 @@
+ 
+ /* config info */
+ 
+-#define @PNAME at _OS_NAME          "@CMAKE_SYSTEM@"
++#define @PNAME at _OS_NAME          "Debian"
+ #define @PNAME at _OS_BITS          @EC_OS_BITS@
+ #define @PNAME at _OS_BITS_STR      "@EC_OS_BITS@"
+ #define @PNAME at _OS_STR           "@EC_OS_NAME at .@EC_OS_BITS@"
+-#define @PNAME at _OS_VERSION       "@CMAKE_SYSTEM_VERSION@"
++#define @PNAME at _OS_VERSION       "Debian"
+ #define @PNAME at _SYS_PROCESSOR    "@CMAKE_SYSTEM_PROCESSOR@"
+ 
+-#define @PNAME at _BUILD_TIMESTAMP  "@EC_BUILD_TIMESTAMP@"
++#ifndef HAVE_BIT_REPRODUCIBLE
++   #define @PNAME at _BUILD_TIMESTAMP  "@EC_BUILD_TIMESTAMP@"
++#else
++   #define @PNAME at _BUILD_TIMESTAMP "NO-TIMESTAMP-FOR-BIT_REPRODUCIBLE-BUILD"
++#endif
+ #define @PNAME at _BUILD_TYPE       "@CMAKE_BUILD_TYPE@"
+ 
+ #define @PNAME at _C_COMPILER_ID      "@CMAKE_C_COMPILER_ID@"
+@@ -171,9 +175,6 @@
+ #define @PNAME at _INSTALL_LIB_DIR   "@CMAKE_INSTALL_PREFIX@/@INSTALL_LIB_DIR@"
+ #define @PNAME at _INSTALL_DATA_DIR  "@CMAKE_INSTALL_PREFIX@/@INSTALL_DATA_DIR@"
+ 
+-#define @PNAME at _DEVELOPER_SRC_DIR "@CMAKE_SOURCE_DIR@"
+-#define @PNAME at _DEVELOPER_BIN_DIR "@CMAKE_BINARY_DIR@"
+-
+ #cmakedefine EC_HAVE_FORTRAN
+ 
+ #ifdef EC_HAVE_FORTRAN
+Index: eccodes-0.16.0/cmake/ecbuild_print_summary.cmake
+===================================================================
+--- eccodes-0.16.0.orig/cmake/ecbuild_print_summary.cmake
++++ eccodes-0.16.0/cmake/ecbuild_print_summary.cmake
+@@ -59,7 +59,9 @@ macro( ecbuild_print_summary )
+       message( STATUS "endiness         : Little Endian -- IEEE [${IEEE_LE}]" )
+     endif()
+     message( STATUS "build type       : [${CMAKE_BUILD_TYPE}]" )
+-    message( STATUS "timestamp        : [${EC_BUILD_TIMESTAMP}]" )
++    if( NOT HAVE_BIT_REPRODUCIBLE )
++      ecbuild_info("timestamp        : [${EC_BUILD_TIMESTAMP}]" )
++    endif()
+     message( STATUS "install prefix   : [${CMAKE_INSTALL_PREFIX}]" )
+     if( EC_LINK_DIR )
+       message( STATUS "links prefix     : [${EC_LINK_DIR}]" )
+Index: eccodes-0.16.0/cmake/ecbuild_get_date.cmake
+===================================================================
+--- eccodes-0.16.0.orig/cmake/ecbuild_get_date.cmake
++++ eccodes-0.16.0/cmake/ecbuild_get_date.cmake
+@@ -20,11 +20,15 @@
+ ##############################################################################
+ 
+ macro(ecbuild_get_date RESULT)
+-    if(UNIX)
+-        execute_process(COMMAND "date" "+%d/%m/%Y" OUTPUT_VARIABLE ${RESULT})
+-        string(REGEX REPLACE "(..)/(..)/(....).*" "\\3.\\2.\\1" ${RESULT} ${${RESULT}})
++    if (HAVE_BIT_REPRODUCIBLE)
++        ecbuild_info("date not included in bit-reproducible builds")
+     else()
+-        message(SEND_ERROR "date not implemented")
++      if(UNIX)
++	execute_process(COMMAND "date" "+%d/%m/%Y" OUTPUT_VARIABLE ${RESULT})
++	string(REGEX REPLACE "(..)/(..)/(....).*" "\\3.\\2.\\1" ${RESULT} ${${RESULT}})
++      else()
++	ecbuild_error("date not implemented")
++      endif()
+     endif()
+ endmacro(ecbuild_get_date)
+ 
+@@ -42,11 +46,15 @@ endmacro(ecbuild_get_date)
+ ##############################################################################
+ 
+ macro(ecbuild_get_timestamp RESULT)
++  if (HAVE_BIT_REPRODUCIBLE)
++    ecbuild_info("timestamps not included in bit-reproducible builds")
++  else()
+     if(UNIX)
+-        execute_process(COMMAND "date" "+%Y/%m/%d/%H/%M/%S" OUTPUT_VARIABLE _timestamp)
+-        string(REGEX REPLACE "(....)/(..)/(..)/(..)/(..)/(..).*" "\\1\\2\\3\\4\\5\\6" ${RESULT} ${_timestamp})
++      execute_process(COMMAND "date" "+%Y/%m/%d/%H/%M/%S" OUTPUT_VARIABLE _timestamp)
++      string(REGEX REPLACE "(....)/(..)/(..)/(..)/(..)/(..).*" "\\1\\2\\3\\4\\5\\6" ${RESULT} ${_timestamp})
+     else()
+-        message(WARNING "This is NOT UNIX - timestamp not implemented")
++      message(WARNING "This is NOT UNIX - timestamp not implemented")
+     endif()
++  endif()
+ endmacro(ecbuild_get_timestamp)
+ 
diff --git a/debian/patches/series b/debian/patches/series
new file mode 100644
index 0000000..6da8d27
--- /dev/null
+++ b/debian/patches/series
@@ -0,0 +1,10 @@
+grib_bits.diff
+static-libs.patch
+reproducible.patch
+hurd.patch
+disable-download-tests.patch
+static-fix.patch
+python3.patch
+numpy-fixes.patch
+py3-fixes.patch
+openjpeg2.patch
diff --git a/debian/patches/static-fix.patch b/debian/patches/static-fix.patch
new file mode 100644
index 0000000..913b957
--- /dev/null
+++ b/debian/patches/static-fix.patch
@@ -0,0 +1,309 @@
+Author: Alastair McKinstry <mckinstry at debian.org>§
+Description: compile fix for shadowed function definitions
+ goto-cc compiler says multiple 'usage' functions shadow each other
+ due to including 'grib_options' when linking. Declare static.
+Bug-Upstream: https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=752732
+Last-Updated: 2016-04-27
+Forwarded: no
+
+Index: eccodes-0.16.0/tools/mars_request.c
+===================================================================
+--- eccodes-0.16.0.orig/tools/mars_request.c
++++ eccodes-0.16.0/tools/mars_request.c
+@@ -13,7 +13,7 @@
+ 
+ #include "grib_api.h"
+ 
+-void usage(const char *prog)
++static void usage(const char *prog)
+ {
+ 	fprintf(stderr,"%s: file\n",prog);
+ 	exit(1);
+Index: eccodes-0.16.0/tools/dumpload.c
+===================================================================
+--- eccodes-0.16.0.orig/tools/dumpload.c
++++ eccodes-0.16.0/tools/dumpload.c
+@@ -16,7 +16,7 @@
+ 
+ char *prog;
+ 
+-void usage(const char *prog)
++static void usage(const char *prog)
+ {
+ 	fprintf(stderr,"%s: [-l] in out\n",prog);
+ 	exit(1);
+Index: eccodes-0.16.0/tools/gaussian.c
+===================================================================
+--- eccodes-0.16.0.orig/tools/gaussian.c
++++ eccodes-0.16.0/tools/gaussian.c
+@@ -14,7 +14,7 @@
+ 
+ #include "grib_api.h"
+ 
+-void usage(const char *prog)
++static void usage(const char *prog)
+ {
+ 	fprintf(stderr,"%s: N\n",prog);
+ 	exit(1);
+Index: eccodes-0.16.0/tools/grib_check_gaussian_grid.c
+===================================================================
+--- eccodes-0.16.0.orig/tools/grib_check_gaussian_grid.c
++++ eccodes-0.16.0/tools/grib_check_gaussian_grid.c
+@@ -30,7 +30,7 @@ int DBL_EQUAL(double d1, double d2, doub
+     return fabs(d1-d2) <= tolerance;
+ }
+ 
+-void usage(const char* prog)
++static void usage(const char* prog)
+ {
+     printf("usage: %s [-f] grib_file grib_file ...\n\n",prog);
+     printf("Check geometry of GRIB fields with a Gaussian Grid.\n");
+Index: eccodes-0.16.0/tools/grib_cmp.c
+===================================================================
+--- eccodes-0.16.0.orig/tools/grib_cmp.c
++++ eccodes-0.16.0/tools/grib_cmp.c
+@@ -16,7 +16,7 @@
+  */
+ #include "grib_api_internal.h"
+ 
+-void usage(char* progname) {
++static void usage(char* progname) {
+   printf("\nUsage: %s file file\n",progname);
+   exit(1);
+ }
+Index: eccodes-0.16.0/tools/grib_corruption_check.c
+===================================================================
+--- eccodes-0.16.0.orig/tools/grib_corruption_check.c
++++ eccodes-0.16.0/tools/grib_corruption_check.c
+@@ -10,7 +10,7 @@
+ 
+ #include "grib_api.h"
+ 
+-void usage(char* prog) {
++static void usage(char* prog) {
+ 	printf("usage: %s gribfile\n",prog);
+ 	exit(1);
+ }
+Index: eccodes-0.16.0/tools/grib_diff.c
+===================================================================
+--- eccodes-0.16.0.orig/tools/grib_diff.c
++++ eccodes-0.16.0/tools/grib_diff.c
+@@ -10,7 +10,7 @@
+ 
+ #include "grib_api_internal.h"
+ 
+-void usage(const char *prog)
++static void usage(const char *prog)
+ {
+   fprintf(stderr,"%s: [-b blacklist][-e] [-p err] file1 file2\n",prog);
+   exit(1);
+Index: eccodes-0.16.0/tools/grib_distance.c
+===================================================================
+--- eccodes-0.16.0.orig/tools/grib_distance.c
++++ eccodes-0.16.0/tools/grib_distance.c
+@@ -17,7 +17,7 @@
+ 
+ #include "grib_api.h"
+ 
+-void usage(const char *prog)
++static void usage(const char *prog)
+ {
+ 	fprintf(stderr,"%s:  in1 [in2 ... ]  out\n",prog);
+ 	exit(1);
+Index: eccodes-0.16.0/tools/grib_error.c
+===================================================================
+--- eccodes-0.16.0.orig/tools/grib_error.c
++++ eccodes-0.16.0/tools/grib_error.c
+@@ -10,7 +10,7 @@
+ 
+ #include "grib_api_internal.h"
+ 
+-void usage(const char *prog)
++static void usage(const char *prog)
+ {
+   fprintf(stderr,"%s: [-d] [-e err] [-o out] file1 file2\n",prog);
+   exit(1);
+Index: eccodes-0.16.0/tools/grib_gen.c
+===================================================================
+--- eccodes-0.16.0.orig/tools/grib_gen.c
++++ eccodes-0.16.0/tools/grib_gen.c
+@@ -20,7 +20,7 @@
+ #include "grib_api_internal.h"
+ 
+ 
+-void usage( char*);
++static void usage( char*);
+ 
+ int main(int argc, char *argv[])
+ {
+Index: eccodes-0.16.0/tools/grib_moments.c
+===================================================================
+--- eccodes-0.16.0.orig/tools/grib_moments.c
++++ eccodes-0.16.0/tools/grib_moments.c
+@@ -10,7 +10,7 @@
+ 
+ #include "grib_api_internal.h"
+ 
+-void usage(char* prog) {printf("usage: %s split order interpolated.grib original.grib\n",prog);exit(1);}
++static void usage(char* prog) {printf("usage: %s split order interpolated.grib original.grib\n",prog);exit(1);}
+ 
+ int get_box(grib_handle *h,double *east,double *north,double *west,double *south) {
+ 	int ret=0;
+Index: eccodes-0.16.0/tools/grib_nearest_land.c
+===================================================================
+--- eccodes-0.16.0.orig/tools/grib_nearest_land.c
++++ eccodes-0.16.0/tools/grib_nearest_land.c
+@@ -19,7 +19,7 @@
+ 
+ #include "grib_api_internal.h"
+ 
+-void usage(char* prog) {
++static void usage(char* prog) {
+   printf("Usage: %s latlon_file grib_orography grib_file grib_file ...\n",prog);
+   exit(1);
+ }
+Index: eccodes-0.16.0/tools/grib_packing.c
+===================================================================
+--- eccodes-0.16.0.orig/tools/grib_packing.c
++++ eccodes-0.16.0/tools/grib_packing.c
+@@ -16,7 +16,7 @@
+  */
+  
+ #include "grib_api_internal.h"
+-void usage(const char* p)
++static void usage(const char* p)
+ {
+ 	printf("Usage: %s [-n minimum] [-x maximum] [-b number of bits] [-d decimal scaling] [-2] [--] [values ..]\n",p);
+ 	exit(1);
+Index: eccodes-0.16.0/tools/grib_tools.h
+===================================================================
+--- eccodes-0.16.0.orig/tools/grib_tools.h
++++ eccodes-0.16.0/tools/grib_tools.h
+@@ -179,7 +179,7 @@ int grib_tool(int argc, char **argv);
+ char* grib_options_get_help(char* id);
+ char* grib_options_get_args(char* id);
+ int grib_options_command_line(const char* id);
+-void usage();
++void grib_usage(void);
+ void usage_doxygen();
+ int grib_tool_before_getopt(grib_runtime_options* options);
+ int grib_tool_init(grib_runtime_options* options);
+Index: eccodes-0.16.0/tools/grib_compare.c
+===================================================================
+--- eccodes-0.16.0.orig/tools/grib_compare.c
++++ eccodes-0.16.0/tools/grib_compare.c
+@@ -278,7 +278,7 @@ int grib_tool_init(grib_runtime_options*
+         options->tolerance_count=MAX_KEYS;
+         ret=parse_keyval_string(grib_tool_name, sarg,1,GRIB_TYPE_DOUBLE,options->tolerance,&(options->tolerance_count));
+         if (ret == GRIB_INVALID_ARGUMENT) {
+-            usage();
++            grib_usage();
+             exit(1);
+         }
+     }
+Index: eccodes-0.16.0/tools/grib_options.c
+===================================================================
+--- eccodes-0.16.0.orig/tools/grib_options.c
++++ eccodes-0.16.0/tools/grib_options.c
+@@ -109,7 +109,7 @@ grib_options_help grib_options_help_list
+ int grib_options_help_count=sizeof(grib_options_help_list)/sizeof(grib_options_help);
+ 
+ 
+-void usage()
++void grib_usage(void)
+ {
+     int i=0;
+     printf("\nNAME \t%s\n\n",grib_tool_name);
+@@ -169,7 +169,7 @@ int grib_get_runtime_options(int argc,ch
+ 
+ 
+     while ((c = getopt (argc, argv, optstr)) != -1) {
+-        if (c == '?') usage();
++        if (c == '?') grib_usage();
+         i=0;
+         while ( i < grib_options_count && grib_options[i].id[0] != c) i++;
+         grib_options[i].on=1;
+@@ -242,7 +242,7 @@ int grib_process_runtime_options(grib_co
+     if (grib_options_on("G")) grib_gribex_mode_on(context);
+ 
+     nfiles=argc-optind;
+-    if ( nfiles < (1+has_output+has_input_extra) && !options->infile ) usage();
++    if ( nfiles < (1+has_output+has_input_extra) && !options->infile ) grib_usage();
+ 
+     if (has_input_extra) {
+         options->infile_extra=(grib_tools_file*)calloc(1,sizeof(grib_tools_file));
+@@ -300,7 +300,7 @@ int grib_process_runtime_options(grib_co
+     options->requested_print_keys_count=MAX_KEYS;
+     ret = parse_keyval_string(grib_tool_name,karg,0,GRIB_TYPE_UNDEFINED,
+             options->requested_print_keys,&(options->requested_print_keys_count));
+-    if (ret == GRIB_INVALID_ARGUMENT) usage();
++    if (ret == GRIB_INVALID_ARGUMENT) grib_usage();
+     GRIB_CHECK_NOLINE(ret,0);
+ 
+     options->strict=grib_options_on("S");
+@@ -321,14 +321,14 @@ int grib_process_runtime_options(grib_co
+         sarg=grib_options_get_option("s:");
+         options->set_values_count=MAX_KEYS;
+         ret=parse_keyval_string(grib_tool_name, sarg,1,GRIB_TYPE_UNDEFINED,options->set_values,&(options->set_values_count));
+-        if (ret == GRIB_INVALID_ARGUMENT) usage();
++        if (ret == GRIB_INVALID_ARGUMENT) grib_usage();
+     }
+ 
+     if (grib_options_on("b:")) {
+         barg=grib_options_get_option("b:");
+         options->set_values_count=MAX_KEYS;
+         ret=parse_keyval_string(grib_tool_name,barg,0,GRIB_TYPE_STRING,options->set_values,&(options->set_values_count));
+-        if (ret == GRIB_INVALID_ARGUMENT) usage();
++        if (ret == GRIB_INVALID_ARGUMENT) grib_usage();
+     }
+ 
+     if (grib_options_on("c:")) {
+@@ -336,7 +336,7 @@ int grib_process_runtime_options(grib_co
+         options->compare_count=MAX_KEYS;
+         ret=parse_keyval_string(grib_tool_name,sarg,0,GRIB_TYPE_UNDEFINED,options->compare,
+                 &(options->compare_count));
+-        if (ret == GRIB_INVALID_ARGUMENT) usage();
++        if (ret == GRIB_INVALID_ARGUMENT) grib_usage();
+     }
+     if (grib_options_on("e")) {
+         for (i=0;i<names_count; i++) {
+@@ -351,7 +351,7 @@ int grib_process_runtime_options(grib_co
+     options->constraints_count=MAX_KEYS;
+     ret=parse_keyval_string(grib_tool_name,warg,1,GRIB_TYPE_UNDEFINED,
+             options->constraints,&(options->constraints_count));
+-    if (ret == GRIB_INVALID_ARGUMENT) usage();
++    if (ret == GRIB_INVALID_ARGUMENT) grib_usage();
+ 
+     return GRIB_SUCCESS;
+ }
+Index: eccodes-0.16.0/tools/grib_to_netcdf.c
+===================================================================
+--- eccodes-0.16.0.orig/tools/grib_to_netcdf.c
++++ eccodes-0.16.0/tools/grib_to_netcdf.c
+@@ -3962,7 +3962,7 @@ int grib_tool_init(grib_runtime_options*
+         }
+         if (kvalue->name == NULL) {
+             fprintf(stderr, "Invalid format: %s", kind_name);
+-            usage();
++            grib_usage();
+             exit(1);
+         }
+     }
+@@ -3972,7 +3972,7 @@ int grib_tool_init(grib_runtime_options*
+         char* theArg = grib_options_get_option("R:");
+         if (!is_number(theArg)) {
+             fprintf(stderr, "Invalid reference date: %s\n", theArg);
+-            usage();
++            grib_usage();
+             exit(1);
+         }
+         set_value(user_r, "referencedate", theArg);
+@@ -4146,7 +4146,7 @@ int grib_tool_finalise_action(grib_runti
+ 
+     if(options->outfile==NULL || options->outfile->name==NULL)
+     {
+-        usage();
++        grib_usage();
+         exit(1);
+     }
+ 
diff --git a/debian/patches/static-libs.patch b/debian/patches/static-libs.patch
new file mode 100644
index 0000000..934b27c
--- /dev/null
+++ b/debian/patches/static-libs.patch
@@ -0,0 +1,60 @@
+Author: Alastair McKinstry <mckinstry at debian.org>
+Description: Build both static and dynamic libraries for Debian;
+ Add SONAME support for the dynamic libraries
+Last-Updated: 2016-04-27
+Forwarded: no
+
+Index: eccodes-0.16.0/fortran/CMakeLists.txt
+===================================================================
+--- eccodes-0.16.0.orig/fortran/CMakeLists.txt
++++ eccodes-0.16.0/fortran/CMakeLists.txt
+@@ -43,8 +43,18 @@ if( HAVE_FORTRAN )
+     ecbuild_add_library( TARGET     eccodes_f90
+                          SOURCES    grib_fortran.c grib_f90.f90 eccodes_f90.f90 grib_kinds.h
+                          GENERATED  grib_f90.f90 eccodes_f90.f90
++			 CFLAGS     ${CFLAGS}
++			 VERSION    0 
+                          LIBS       eccodes )
+ 
++    ecbuild_add_library( TARGET     grib_api_f90_static
++                         OUTPUT_NAME "eccodes_f90"
++                         TYPE       STATIC
++                         SOURCES    grib_fortran.c grib_f90.f90 eccodes_f90.f90 grib_kinds.h
++                         GENERATED  grib_f90.f90 eccodes_f90.f90
++			 CFLAGS     ${CFLAGS}
++			 LIB        eccodes )
++		      
+     # Add the eccodes module file as well
+     #set(_eccodes_mod "${CMAKE_Fortran_MODULE_DIRECTORY}/eccodes.mod" )
+ 
+Index: eccodes-0.16.0/src/CMakeLists.txt
+===================================================================
+--- eccodes-0.16.0.orig/src/CMakeLists.txt
++++ eccodes-0.16.0/src/CMakeLists.txt
+@@ -394,12 +394,25 @@ ecbuild_add_library(TARGET    eccodes
+                     SOURCES   grib_api_version.c
+                               # griby.c gribl.c
+                              ${grib_api_srcs}
+-                    GENERATED grib_api_version.c
++		    GENERATED grib_api_version.c
++		    VERSION   0
++		    CFLAGS    ${CFLAGS}
+                     LIBS      ${ECCODES_EXTRA_LIBRARIES} ${CMAKE_THREAD_LIBS_INIT}
+                     TEMPLATES ${grib_api_extra_srcs}
+                     ${CMATH_LIBRARIES}  )
+ 
++ecbuild_add_library(TARGET    eccodes_static
++                    TYPE      STATIC
++                    SOURCES   grib_api_version.c
++                              # griby.c gribl.c
++                             ${grib_api_srcs}
++		    GENERATED grib_api_version.c
++		    CFLAGS    ${CFLAGS}
++                    LIBS      ${ECCODES_EXTRA_LIBRARIES} ${CMAKE_THREAD_LIBS_INIT}
++                    TEMPLATES ${grib_api_extra_srcs}
++                    ${CMATH_LIBRARIES}  )
+ 
++		  
+ install( FILES grib_api.h eccodes.h eccodes_windef.h DESTINATION ${INSTALL_INCLUDE_DIR} )
+ install( FILES ${CMAKE_CURRENT_BINARY_DIR}/eccodes_version.h DESTINATION ${INSTALL_INCLUDE_DIR} )
+ 

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/debian-science/packages/eccodes.git



More information about the debian-science-commits mailing list