Index: nsmodels/src/sans/models/model_func_ext.cpp
===================================================================
--- sansmodels/src/sans/models/model_func_ext.cpp	(revision 2399b2aa02ce10301917e5d3d2e5923f497c877c)
+++ 	(revision )
@@ -1,840 +1,0 @@
-#ifdef __CPLUSPLUS__
-extern "C" {
-#endif
-
-#ifndef __GNUC__
-#pragma warning(disable: 4275)
-#pragma warning(disable: 4101)
-
-#endif
-#include "Python.h"
-#include "compile.h"
-#include "frameobject.h"
-#include <complex>
-#include <math.h>
-#include <string>
-#include "scxx/object.h"
-#include "scxx/list.h"
-#include "scxx/tuple.h"
-#include "scxx/dict.h"
-#include <iostream>
-#include <stdio.h>
-#include "numpy/arrayobject.h"
-
-
-
-
-// global None value for use in functions.
-namespace py {
-object None = object(Py_None);
-}
-
-const char* find_type(PyObject* py_obj)
-{
-    if(py_obj == NULL) return "C NULL value";
-    if(PyCallable_Check(py_obj)) return "callable";
-    if(PyString_Check(py_obj)) return "string";
-    if(PyInt_Check(py_obj)) return "int";
-    if(PyFloat_Check(py_obj)) return "float";
-    if(PyDict_Check(py_obj)) return "dict";
-    if(PyList_Check(py_obj)) return "list";
-    if(PyTuple_Check(py_obj)) return "tuple";
-    if(PyFile_Check(py_obj)) return "file";
-    if(PyModule_Check(py_obj)) return "module";
-
-    //should probably do more intergation (and thinking) on these.
-    if(PyCallable_Check(py_obj) && PyInstance_Check(py_obj)) return "callable";
-    if(PyInstance_Check(py_obj)) return "instance";
-    if(PyCallable_Check(py_obj)) return "callable";
-    return "unkown type";
-}
-
-void throw_error(PyObject* exc, const char* msg)
-{
- //printf("setting python error: %s\n",msg);
-  PyErr_SetString(exc, msg);
-  //printf("throwing error\n");
-  throw 1;
-}
-
-void handle_bad_type(PyObject* py_obj, const char* good_type, const char* var_name)
-{
-    char msg[500];
-    sprintf(msg,"received '%s' type instead of '%s' for variable '%s'",
-            find_type(py_obj),good_type,var_name);
-    throw_error(PyExc_TypeError,msg);
-}
-
-void handle_conversion_error(PyObject* py_obj, const char* good_type, const char* var_name)
-{
-    char msg[500];
-    sprintf(msg,"Conversion Error:, received '%s' type instead of '%s' for variable '%s'",
-            find_type(py_obj),good_type,var_name);
-    throw_error(PyExc_TypeError,msg);
-}
-
-
-class int_handler
-{
-public:
-    int convert_to_int(PyObject* py_obj, const char* name)
-    {
-        // Incref occurs even if conversion fails so that
-        // the decref in cleanup_code has a matching incref.
-        
-        if (!py_obj || !PyInt_Check(py_obj))
-            handle_conversion_error(py_obj,"int", name);
-        return (int) PyInt_AsLong(py_obj);
-    }
-
-    int py_to_int(PyObject* py_obj, const char* name)
-    {
-        // !! Pretty sure INCREF should only be called on success since
-        // !! py_to_xxx is used by the user -- not the code generator.
-        if (!py_obj || !PyInt_Check(py_obj))
-            handle_bad_type(py_obj,"int", name);
-        
-        return (int) PyInt_AsLong(py_obj);
-    }
-};
-
-int_handler x__int_handler = int_handler();
-#define convert_to_int(py_obj,name) \
-        x__int_handler.convert_to_int(py_obj,name)
-#define py_to_int(py_obj,name) \
-        x__int_handler.py_to_int(py_obj,name)
-
-
-PyObject* int_to_py(PyObject* obj)
-{
-    return (PyObject*) obj;
-}
-
-
-class float_handler
-{
-public:
-    double convert_to_float(PyObject* py_obj, const char* name)
-    {
-        // Incref occurs even if conversion fails so that
-        // the decref in cleanup_code has a matching incref.
-        
-        if (!py_obj || !PyFloat_Check(py_obj))
-            handle_conversion_error(py_obj,"float", name);
-        return PyFloat_AsDouble(py_obj);
-    }
-
-    double py_to_float(PyObject* py_obj, const char* name)
-    {
-        // !! Pretty sure INCREF should only be called on success since
-        // !! py_to_xxx is used by the user -- not the code generator.
-        if (!py_obj || !PyFloat_Check(py_obj))
-            handle_bad_type(py_obj,"float", name);
-        
-        return PyFloat_AsDouble(py_obj);
-    }
-};
-
-float_handler x__float_handler = float_handler();
-#define convert_to_float(py_obj,name) \
-        x__float_handler.convert_to_float(py_obj,name)
-#define py_to_float(py_obj,name) \
-        x__float_handler.py_to_float(py_obj,name)
-
-
-PyObject* float_to_py(PyObject* obj)
-{
-    return (PyObject*) obj;
-}
-
-
-class complex_handler
-{
-public:
-    std::complex<double> convert_to_complex(PyObject* py_obj, const char* name)
-    {
-        // Incref occurs even if conversion fails so that
-        // the decref in cleanup_code has a matching incref.
-        
-        if (!py_obj || !PyComplex_Check(py_obj))
-            handle_conversion_error(py_obj,"complex", name);
-        return std::complex<double>(PyComplex_RealAsDouble(py_obj),PyComplex_ImagAsDouble(py_obj));
-    }
-
-    std::complex<double> py_to_complex(PyObject* py_obj, const char* name)
-    {
-        // !! Pretty sure INCREF should only be called on success since
-        // !! py_to_xxx is used by the user -- not the code generator.
-        if (!py_obj || !PyComplex_Check(py_obj))
-            handle_bad_type(py_obj,"complex", name);
-        
-        return std::complex<double>(PyComplex_RealAsDouble(py_obj),PyComplex_ImagAsDouble(py_obj));
-    }
-};
-
-complex_handler x__complex_handler = complex_handler();
-#define convert_to_complex(py_obj,name) \
-        x__complex_handler.convert_to_complex(py_obj,name)
-#define py_to_complex(py_obj,name) \
-        x__complex_handler.py_to_complex(py_obj,name)
-
-
-PyObject* complex_to_py(PyObject* obj)
-{
-    return (PyObject*) obj;
-}
-
-
-class unicode_handler
-{
-public:
-    Py_UNICODE* convert_to_unicode(PyObject* py_obj, const char* name)
-    {
-        // Incref occurs even if conversion fails so that
-        // the decref in cleanup_code has a matching incref.
-        Py_XINCREF(py_obj);
-        if (!py_obj || !PyUnicode_Check(py_obj))
-            handle_conversion_error(py_obj,"unicode", name);
-        return PyUnicode_AS_UNICODE(py_obj);
-    }
-
-    Py_UNICODE* py_to_unicode(PyObject* py_obj, const char* name)
-    {
-        // !! Pretty sure INCREF should only be called on success since
-        // !! py_to_xxx is used by the user -- not the code generator.
-        if (!py_obj || !PyUnicode_Check(py_obj))
-            handle_bad_type(py_obj,"unicode", name);
-        Py_XINCREF(py_obj);
-        return PyUnicode_AS_UNICODE(py_obj);
-    }
-};
-
-unicode_handler x__unicode_handler = unicode_handler();
-#define convert_to_unicode(py_obj,name) \
-        x__unicode_handler.convert_to_unicode(py_obj,name)
-#define py_to_unicode(py_obj,name) \
-        x__unicode_handler.py_to_unicode(py_obj,name)
-
-
-PyObject* unicode_to_py(PyObject* obj)
-{
-    return (PyObject*) obj;
-}
-
-
-class string_handler
-{
-public:
-    std::string convert_to_string(PyObject* py_obj, const char* name)
-    {
-        // Incref occurs even if conversion fails so that
-        // the decref in cleanup_code has a matching incref.
-        Py_XINCREF(py_obj);
-        if (!py_obj || !PyString_Check(py_obj))
-            handle_conversion_error(py_obj,"string", name);
-        return std::string(PyString_AsString(py_obj));
-    }
-
-    std::string py_to_string(PyObject* py_obj, const char* name)
-    {
-        // !! Pretty sure INCREF should only be called on success since
-        // !! py_to_xxx is used by the user -- not the code generator.
-        if (!py_obj || !PyString_Check(py_obj))
-            handle_bad_type(py_obj,"string", name);
-        Py_XINCREF(py_obj);
-        return std::string(PyString_AsString(py_obj));
-    }
-};
-
-string_handler x__string_handler = string_handler();
-#define convert_to_string(py_obj,name) \
-        x__string_handler.convert_to_string(py_obj,name)
-#define py_to_string(py_obj,name) \
-        x__string_handler.py_to_string(py_obj,name)
-
-
-               PyObject* string_to_py(std::string s)
-               {
-                   return PyString_FromString(s.c_str());
-               }
-               
-class list_handler
-{
-public:
-    py::list convert_to_list(PyObject* py_obj, const char* name)
-    {
-        // Incref occurs even if conversion fails so that
-        // the decref in cleanup_code has a matching incref.
-        
-        if (!py_obj || !PyList_Check(py_obj))
-            handle_conversion_error(py_obj,"list", name);
-        return py::list(py_obj);
-    }
-
-    py::list py_to_list(PyObject* py_obj, const char* name)
-    {
-        // !! Pretty sure INCREF should only be called on success since
-        // !! py_to_xxx is used by the user -- not the code generator.
-        if (!py_obj || !PyList_Check(py_obj))
-            handle_bad_type(py_obj,"list", name);
-        
-        return py::list(py_obj);
-    }
-};
-
-list_handler x__list_handler = list_handler();
-#define convert_to_list(py_obj,name) \
-        x__list_handler.convert_to_list(py_obj,name)
-#define py_to_list(py_obj,name) \
-        x__list_handler.py_to_list(py_obj,name)
-
-
-PyObject* list_to_py(PyObject* obj)
-{
-    return (PyObject*) obj;
-}
-
-
-class dict_handler
-{
-public:
-    py::dict convert_to_dict(PyObject* py_obj, const char* name)
-    {
-        // Incref occurs even if conversion fails so that
-        // the decref in cleanup_code has a matching incref.
-        
-        if (!py_obj || !PyDict_Check(py_obj))
-            handle_conversion_error(py_obj,"dict", name);
-        return py::dict(py_obj);
-    }
-
-    py::dict py_to_dict(PyObject* py_obj, const char* name)
-    {
-        // !! Pretty sure INCREF should only be called on success since
-        // !! py_to_xxx is used by the user -- not the code generator.
-        if (!py_obj || !PyDict_Check(py_obj))
-            handle_bad_type(py_obj,"dict", name);
-        
-        return py::dict(py_obj);
-    }
-};
-
-dict_handler x__dict_handler = dict_handler();
-#define convert_to_dict(py_obj,name) \
-        x__dict_handler.convert_to_dict(py_obj,name)
-#define py_to_dict(py_obj,name) \
-        x__dict_handler.py_to_dict(py_obj,name)
-
-
-PyObject* dict_to_py(PyObject* obj)
-{
-    return (PyObject*) obj;
-}
-
-
-class tuple_handler
-{
-public:
-    py::tuple convert_to_tuple(PyObject* py_obj, const char* name)
-    {
-        // Incref occurs even if conversion fails so that
-        // the decref in cleanup_code has a matching incref.
-        
-        if (!py_obj || !PyTuple_Check(py_obj))
-            handle_conversion_error(py_obj,"tuple", name);
-        return py::tuple(py_obj);
-    }
-
-    py::tuple py_to_tuple(PyObject* py_obj, const char* name)
-    {
-        // !! Pretty sure INCREF should only be called on success since
-        // !! py_to_xxx is used by the user -- not the code generator.
-        if (!py_obj || !PyTuple_Check(py_obj))
-            handle_bad_type(py_obj,"tuple", name);
-        
-        return py::tuple(py_obj);
-    }
-};
-
-tuple_handler x__tuple_handler = tuple_handler();
-#define convert_to_tuple(py_obj,name) \
-        x__tuple_handler.convert_to_tuple(py_obj,name)
-#define py_to_tuple(py_obj,name) \
-        x__tuple_handler.py_to_tuple(py_obj,name)
-
-
-PyObject* tuple_to_py(PyObject* obj)
-{
-    return (PyObject*) obj;
-}
-
-
-class file_handler
-{
-public:
-    FILE* convert_to_file(PyObject* py_obj, const char* name)
-    {
-        // Incref occurs even if conversion fails so that
-        // the decref in cleanup_code has a matching incref.
-        Py_XINCREF(py_obj);
-        if (!py_obj || !PyFile_Check(py_obj))
-            handle_conversion_error(py_obj,"file", name);
-        return PyFile_AsFile(py_obj);
-    }
-
-    FILE* py_to_file(PyObject* py_obj, const char* name)
-    {
-        // !! Pretty sure INCREF should only be called on success since
-        // !! py_to_xxx is used by the user -- not the code generator.
-        if (!py_obj || !PyFile_Check(py_obj))
-            handle_bad_type(py_obj,"file", name);
-        Py_XINCREF(py_obj);
-        return PyFile_AsFile(py_obj);
-    }
-};
-
-file_handler x__file_handler = file_handler();
-#define convert_to_file(py_obj,name) \
-        x__file_handler.convert_to_file(py_obj,name)
-#define py_to_file(py_obj,name) \
-        x__file_handler.py_to_file(py_obj,name)
-
-
-               PyObject* file_to_py(FILE* file, char* name, char* mode)
-               {
-                   return (PyObject*) PyFile_FromFile(file, name, mode, fclose);
-               }
-               
-class instance_handler
-{
-public:
-    py::object convert_to_instance(PyObject* py_obj, const char* name)
-    {
-        // Incref occurs even if conversion fails so that
-        // the decref in cleanup_code has a matching incref.
-        
-        if (!py_obj || !PyInstance_Check(py_obj))
-            handle_conversion_error(py_obj,"instance", name);
-        return py::object(py_obj);
-    }
-
-    py::object py_to_instance(PyObject* py_obj, const char* name)
-    {
-        // !! Pretty sure INCREF should only be called on success since
-        // !! py_to_xxx is used by the user -- not the code generator.
-        if (!py_obj || !PyInstance_Check(py_obj))
-            handle_bad_type(py_obj,"instance", name);
-        
-        return py::object(py_obj);
-    }
-};
-
-instance_handler x__instance_handler = instance_handler();
-#define convert_to_instance(py_obj,name) \
-        x__instance_handler.convert_to_instance(py_obj,name)
-#define py_to_instance(py_obj,name) \
-        x__instance_handler.py_to_instance(py_obj,name)
-
-
-PyObject* instance_to_py(PyObject* obj)
-{
-    return (PyObject*) obj;
-}
-
-
-class numpy_size_handler
-{
-public:
-    void conversion_numpy_check_size(PyArrayObject* arr_obj, int Ndims,
-                                     const char* name)
-    {
-        if (arr_obj->nd != Ndims)
-        {
-            char msg[500];
-            sprintf(msg,"Conversion Error: received '%d' dimensional array instead of '%d' dimensional array for variable '%s'",
-                    arr_obj->nd,Ndims,name);
-            throw_error(PyExc_TypeError,msg);
-        }
-    }
-
-    void numpy_check_size(PyArrayObject* arr_obj, int Ndims, const char* name)
-    {
-        if (arr_obj->nd != Ndims)
-        {
-            char msg[500];
-            sprintf(msg,"received '%d' dimensional array instead of '%d' dimensional array for variable '%s'",
-                    arr_obj->nd,Ndims,name);
-            throw_error(PyExc_TypeError,msg);
-        }
-    }
-};
-
-numpy_size_handler x__numpy_size_handler = numpy_size_handler();
-#define conversion_numpy_check_size x__numpy_size_handler.conversion_numpy_check_size
-#define numpy_check_size x__numpy_size_handler.numpy_check_size
-
-
-class numpy_type_handler
-{
-public:
-    void conversion_numpy_check_type(PyArrayObject* arr_obj, int numeric_type,
-                                     const char* name)
-    {
-        // Make sure input has correct numeric type.
-        int arr_type = arr_obj->descr->type_num;
-        if (PyTypeNum_ISEXTENDED(numeric_type))
-        {
-        char msg[80];
-        sprintf(msg, "Conversion Error: extended types not supported for variable '%s'",
-                name);
-        throw_error(PyExc_TypeError, msg);
-        }
-        if (!PyArray_EquivTypenums(arr_type, numeric_type))
-        {
-
-        const char* type_names[23] = {"bool", "byte", "ubyte","short", "ushort",
-                                "int", "uint", "long", "ulong", "longlong", "ulonglong",
-                                "float", "double", "longdouble", "cfloat", "cdouble",
-                                "clongdouble", "object", "string", "unicode", "void", "ntype",
-                                "unknown"};
-        char msg[500];
-        sprintf(msg,"Conversion Error: received '%s' typed array instead of '%s' typed array for variable '%s'",
-                type_names[arr_type],type_names[numeric_type],name);
-        throw_error(PyExc_TypeError,msg);
-        }
-    }
-
-    void numpy_check_type(PyArrayObject* arr_obj, int numeric_type, const char* name)
-    {
-        // Make sure input has correct numeric type.
-        int arr_type = arr_obj->descr->type_num;
-        if (PyTypeNum_ISEXTENDED(numeric_type))
-        {
-        char msg[80];
-        sprintf(msg, "Conversion Error: extended types not supported for variable '%s'",
-                name);
-        throw_error(PyExc_TypeError, msg);
-        }
-        if (!PyArray_EquivTypenums(arr_type, numeric_type))
-        {
-            const char* type_names[23] = {"bool", "byte", "ubyte","short", "ushort",
-                                    "int", "uint", "long", "ulong", "longlong", "ulonglong",
-                                    "float", "double", "longdouble", "cfloat", "cdouble",
-                                    "clongdouble", "object", "string", "unicode", "void", "ntype",
-                                    "unknown"};
-            char msg[500];
-            sprintf(msg,"received '%s' typed array instead of '%s' typed array for variable '%s'",
-                    type_names[arr_type],type_names[numeric_type],name);
-            throw_error(PyExc_TypeError,msg);
-        }
-    }
-};
-
-numpy_type_handler x__numpy_type_handler = numpy_type_handler();
-#define conversion_numpy_check_type x__numpy_type_handler.conversion_numpy_check_type
-#define numpy_check_type x__numpy_type_handler.numpy_check_type
-
-
-class numpy_handler
-{
-public:
-    PyArrayObject* convert_to_numpy(PyObject* py_obj, const char* name)
-    {
-        // Incref occurs even if conversion fails so that
-        // the decref in cleanup_code has a matching incref.
-        Py_XINCREF(py_obj);
-        if (!py_obj || !PyArray_Check(py_obj))
-            handle_conversion_error(py_obj,"numpy", name);
-        return (PyArrayObject*) py_obj;
-    }
-
-    PyArrayObject* py_to_numpy(PyObject* py_obj, const char* name)
-    {
-        // !! Pretty sure INCREF should only be called on success since
-        // !! py_to_xxx is used by the user -- not the code generator.
-        if (!py_obj || !PyArray_Check(py_obj))
-            handle_bad_type(py_obj,"numpy", name);
-        Py_XINCREF(py_obj);
-        return (PyArrayObject*) py_obj;
-    }
-};
-
-numpy_handler x__numpy_handler = numpy_handler();
-#define convert_to_numpy(py_obj,name) \
-        x__numpy_handler.convert_to_numpy(py_obj,name)
-#define py_to_numpy(py_obj,name) \
-        x__numpy_handler.py_to_numpy(py_obj,name)
-
-
-PyObject* numpy_to_py(PyObject* obj)
-{
-    return (PyObject*) obj;
-}
-
-
-class catchall_handler
-{
-public:
-    py::object convert_to_catchall(PyObject* py_obj, const char* name)
-    {
-        // Incref occurs even if conversion fails so that
-        // the decref in cleanup_code has a matching incref.
-        
-        if (!py_obj || !(py_obj))
-            handle_conversion_error(py_obj,"catchall", name);
-        return py::object(py_obj);
-    }
-
-    py::object py_to_catchall(PyObject* py_obj, const char* name)
-    {
-        // !! Pretty sure INCREF should only be called on success since
-        // !! py_to_xxx is used by the user -- not the code generator.
-        if (!py_obj || !(py_obj))
-            handle_bad_type(py_obj,"catchall", name);
-        
-        return py::object(py_obj);
-    }
-};
-
-catchall_handler x__catchall_handler = catchall_handler();
-#define convert_to_catchall(py_obj,name) \
-        x__catchall_handler.convert_to_catchall(py_obj,name)
-#define py_to_catchall(py_obj,name) \
-        x__catchall_handler.py_to_catchall(py_obj,name)
-
-
-PyObject* catchall_to_py(PyObject* obj)
-{
-    return (PyObject*) obj;
-}
-
-
-
-static PyObject* multifunctionalmodel(PyObject*self, PyObject* args, PyObject* kywds)
-{
-    py::object return_val;
-    int exception_occured = 0;
-    PyObject *py_local_dict = NULL;
-    static char *kwlist[] = {"x","n","rad_core","sld","thick","slope","fun_type","local_dict", NULL};
-    PyObject *py_x, *py_n, *py_rad_core, *py_sld, *py_thick, *py_slope, *py_fun_type;
-    int x_used, n_used, rad_core_used, sld_used, thick_used, slope_used, fun_type_used;
-    py_x = py_n = py_rad_core = py_sld = py_thick = py_slope = py_fun_type = NULL;
-    x_used= n_used= rad_core_used= sld_used= thick_used= slope_used= fun_type_used = 0;
-    
-    if(!PyArg_ParseTupleAndKeywords(args,kywds,"OOOOOOO|O:multifunctionalmodel",kwlist,&py_x, &py_n, &py_rad_core, &py_sld, &py_thick, &py_slope, &py_fun_type, &py_local_dict))
-       return NULL;
-    try                              
-    {                                
-        py_x = py_x;
-        double x = convert_to_float(py_x,"x");
-        x_used = 1;
-        py_n = py_n;
-        int n = convert_to_int(py_n,"n");
-        n_used = 1;
-        py_rad_core = py_rad_core;
-        double rad_core = convert_to_float(py_rad_core,"rad_core");
-        rad_core_used = 1;
-        py_sld = py_sld;
-        PyArrayObject* sld_array = convert_to_numpy(py_sld,"sld");
-        conversion_numpy_check_type(sld_array,PyArray_DOUBLE,"sld");
-        #define SLD1(i) (*((double*)(sld_array->data + (i)*Ssld[0])))
-        #define SLD2(i,j) (*((double*)(sld_array->data + (i)*Ssld[0] + (j)*Ssld[1])))
-        #define SLD3(i,j,k) (*((double*)(sld_array->data + (i)*Ssld[0] + (j)*Ssld[1] + (k)*Ssld[2])))
-        #define SLD4(i,j,k,l) (*((double*)(sld_array->data + (i)*Ssld[0] + (j)*Ssld[1] + (k)*Ssld[2] + (l)*Ssld[3])))
-        npy_intp* Nsld = sld_array->dimensions;
-        npy_intp* Ssld = sld_array->strides;
-        int Dsld = sld_array->nd;
-        double* sld = (double*) sld_array->data;
-        sld_used = 1;
-        py_thick = py_thick;
-        PyArrayObject* thick_array = convert_to_numpy(py_thick,"thick");
-        conversion_numpy_check_type(thick_array,PyArray_DOUBLE,"thick");
-        #define THICK1(i) (*((double*)(thick_array->data + (i)*Sthick[0])))
-        #define THICK2(i,j) (*((double*)(thick_array->data + (i)*Sthick[0] + (j)*Sthick[1])))
-        #define THICK3(i,j,k) (*((double*)(thick_array->data + (i)*Sthick[0] + (j)*Sthick[1] + (k)*Sthick[2])))
-        #define THICK4(i,j,k,l) (*((double*)(thick_array->data + (i)*Sthick[0] + (j)*Sthick[1] + (k)*Sthick[2] + (l)*Sthick[3])))
-        npy_intp* Nthick = thick_array->dimensions;
-        npy_intp* Sthick = thick_array->strides;
-        int Dthick = thick_array->nd;
-        double* thick = (double*) thick_array->data;
-        thick_used = 1;
-        py_slope = py_slope;
-        PyArrayObject* slope_array = convert_to_numpy(py_slope,"slope");
-        conversion_numpy_check_type(slope_array,PyArray_DOUBLE,"slope");
-        #define SLOPE1(i) (*((double*)(slope_array->data + (i)*Sslope[0])))
-        #define SLOPE2(i,j) (*((double*)(slope_array->data + (i)*Sslope[0] + (j)*Sslope[1])))
-        #define SLOPE3(i,j,k) (*((double*)(slope_array->data + (i)*Sslope[0] + (j)*Sslope[1] + (k)*Sslope[2])))
-        #define SLOPE4(i,j,k,l) (*((double*)(slope_array->data + (i)*Sslope[0] + (j)*Sslope[1] + (k)*Sslope[2] + (l)*Sslope[3])))
-        npy_intp* Nslope = slope_array->dimensions;
-        npy_intp* Sslope = slope_array->strides;
-        int Dslope = slope_array->nd;
-        double* slope = (double*) slope_array->data;
-        slope_used = 1;
-        py_fun_type = py_fun_type;
-        PyArrayObject* fun_type_array = convert_to_numpy(py_fun_type,"fun_type");
-        conversion_numpy_check_type(fun_type_array,PyArray_LONG,"fun_type");
-        #define FUN_TYPE1(i) (*((long*)(fun_type_array->data + (i)*Sfun_type[0])))
-        #define FUN_TYPE2(i,j) (*((long*)(fun_type_array->data + (i)*Sfun_type[0] + (j)*Sfun_type[1])))
-        #define FUN_TYPE3(i,j,k) (*((long*)(fun_type_array->data + (i)*Sfun_type[0] + (j)*Sfun_type[1] + (k)*Sfun_type[2])))
-        #define FUN_TYPE4(i,j,k,l) (*((long*)(fun_type_array->data + (i)*Sfun_type[0] + (j)*Sfun_type[1] + (k)*Sfun_type[2] + (l)*Sfun_type[3])))
-        npy_intp* Nfun_type = fun_type_array->dimensions;
-        npy_intp* Sfun_type = fun_type_array->strides;
-        int Dfun_type = fun_type_array->nd;
-        long* fun_type = (long*) fun_type_array->data;
-        fun_type_used = 1;
-        /*<function call here>*/     
-        
-                            double bes,fun,alpha,beta,f,vol,qr,r,contr,f2;
-                            double pi;
-                            int i,j;
-            
-                            pi = 4.0 * atan(1.0);  
-                            f = 0.0;
-                            r = rad_core;
-                            for (i =0; i<= n+1; i++){
-                                switch(fun_type[i])
-                                {
-                                    case 'exp' :
-                                                contr = sld[i]*exp(-slope[i]*r);
-                                                for (j=0; j<2; j++){
-                                                    if ( i == 0 && j == 0){
-                                                        continue;
-                                                        }
-                                                    if (i == n+1 && j == 1){
-                                                        continue;
-                                                        }
-                                                    if ( j == 1){
-                                                        r += thick[i];
-                                                        }
-                                                    qr = x * r;
-                                                    alpha = slope[i] * r;
-                                                    fun = 0.0;
-                                                    if(qr == 0.0){
-                                                        bes = - 1.0;
-                                                        }
-                                                    else{
-                                                        if (fabs(slope[i]) > 0.0 ){
-                                                            fun = 3.0 * ((alpha*alpha - qr * qr) * sin(beta) - 2.0 * alpha * qr * cos(qr))/ ((alpha * alpha + qr * qr) * (alpha * alpha + qr * qr) * qr);
-                                                            bes = -3.0 * (alpha * sin(qr) - qr * cos(qr)) / ((alpha * alpha + qr * qr) * qr);
-                                                            }
-                                                        else {
-                                                            bes = - 3.0 * (sin(qr) - qr * cos(qr)) / (qr * qr * qr);
-                                                            }
-                                                        }
-                                                    contr *= exp(alpha);
-                                                    if (j == 1){
-                                                        bes = - bes;
-                                                        fun = - fun;
-                                                        }                            
-                                                    vol = 4.0 * pi / 3.0 * r * r * r;
-                                                    f += vol * contr * (bes + fun); 
-                                                    }
-                                                    break;
-                                    default :
-                                                contr = sld[i]-slope[i]*r;
-                                                for (j=0; j<2; j++){
-                                                    if ( i == 0 && j == 0){
-                                                        continue;
-                                                        }
-                                                    if (i == n+1 && j == 1){
-                                                        continue;
-                                                        }
-                                                    if ( j == 1){
-                                                        r += thick[i];
-                                                        }
-                                                    qr = x * r;
-                                                    fun = 0.0;
-                                                    if(qr == 0.0){
-                                                        bes = - 1.0;
-                                                        }
-                                                    else{
-                                                        bes = - 3.0 * (sin(qr) - qr * cos(qr)) / (qr * qr * qr);
-                                                        if (fabs(slope[i]) > 0.0 ){
-                                                            fun = -3.0 * r * (2.0*qr*sin(qr)-((qr*qr)-2.0)*cos(qr))/(qr * qr * qr * qr);
-                                                            }
-                                                        }
-                                                    if (j == 1){
-                                                        bes = - bes;
-                                                        fun = - fun;
-                                                        }                            
-                                                    vol = 4.0 * pi / 3.0 * r * r * r;
-                                                    f += vol * (bes * contr + fun * slope[i]); 
-                                                    }
-                                                    break;
-        
-                                        }
-                                }  
-                            f2 = f * f / vol * 1.0e8;
-                            return_val=f2;
-        if(py_local_dict)                                  
-        {                                                  
-            py::dict local_dict = py::dict(py_local_dict); 
-        }                                                  
-    
-    }                                
-    catch(...)                       
-    {                                
-        return_val =  py::object();      
-        exception_occured = 1;       
-    }                                
-    /*cleanup code*/                     
-    if(sld_used)
-    {
-        Py_XDECREF(py_sld);
-        #undef SLD1
-        #undef SLD2
-        #undef SLD3
-        #undef SLD4
-    }
-    if(thick_used)
-    {
-        Py_XDECREF(py_thick);
-        #undef THICK1
-        #undef THICK2
-        #undef THICK3
-        #undef THICK4
-    }
-    if(slope_used)
-    {
-        Py_XDECREF(py_slope);
-        #undef SLOPE1
-        #undef SLOPE2
-        #undef SLOPE3
-        #undef SLOPE4
-    }
-    if(fun_type_used)
-    {
-        Py_XDECREF(py_fun_type);
-        #undef FUN_TYPE1
-        #undef FUN_TYPE2
-        #undef FUN_TYPE3
-        #undef FUN_TYPE4
-    }
-    if(!(PyObject*)return_val && !exception_occured)
-    {
-                                  
-        return_val = Py_None;            
-    }
-                                  
-    return return_val.disown();           
-}                                
-
-
-static PyMethodDef compiled_methods[] = 
-{
-    {"multifunctionalmodel",(PyCFunction)multifunctionalmodel , METH_VARARGS|METH_KEYWORDS},
-    {NULL,      NULL}        /* Sentinel */
-};
-
-PyMODINIT_FUNC initmodel_func_ext(void)
-{
-    
-    Py_Initialize();
-    import_array();
-    PyImport_ImportModule("numpy");
-    (void) Py_InitModule("model_func_ext", compiled_methods);
-}
-
-#ifdef __CPLUSCPLUS__
-}
-#endif
