Index: ../trunk-jpl/src/c/python/python-binding.h =================================================================== --- ../trunk-jpl/src/c/python/python-binding.h (revision 13748) +++ ../trunk-jpl/src/c/python/python-binding.h (revision 13749) @@ -1,7 +0,0 @@ -#ifndef _PYTHON_BINDING_H_ -#define _PYTHON_BINDING_H_ - -#include "./io/pythonio.h" -#include "./include/python_macros.h" - -#endif Index: ../trunk-jpl/src/c/python/include/python_macros.h =================================================================== --- ../trunk-jpl/src/c/python/include/python_macros.h (revision 13748) +++ ../trunk-jpl/src/c/python/include/python_macros.h (revision 13749) @@ -1,96 +0,0 @@ -/* \file python_macros.h - * \brief: macros used for the python bindings - */ - -#ifndef _PYTHON_MACROS_H_ -#define _PYTHON_MACROS_H_ - -/*Header {{{*/ - -#ifdef HAVE_CONFIG_H - #include -#else -#error "Cannot compile with HAVE_CONFIG_H symbol! run configure first!" -#endif -/*}}}*/ - -#ifdef _HAVE_PYTHON_ -/* MODULEBOOT/MODULEEND {{{*/ - -/*The following macros hide the error exception handling in a matlab module. Just put - * MODULEBOOT(); and MODULEEND(); at the beginning and end of a module, and c++ exceptions - * will be trapped*/ -#define MODULEBOOT(); \ - PyObject *output = PyTuple_New(NLHS); \ - int nrhs = (int)PyTuple_Size(args); \ - if(!output) return NULL;\ - try{ \ - IssmComm::SetComm(-1); - -#define MODULEEND(); }\ - catch(ErrorException &exception){\ - PyErr_SetString(PyExc_TypeError,exception.PythonReport()); \ - return NULL;\ - } \ - catch (exception &e){\ - PyErr_SetString(PyExc_TypeError,exprintf("Standard exception: %s\n",e.what()));\ - return NULL;\ - }\ - catch(...){\ - PyErr_SetString(PyExc_TypeError,"An unexpected error occurred");\ - return NULL;\ - }\ - return output; -//}}} -#if _PYTHON_MAJOR_ >=3 -/* WRAPPER 3.2 {{{*/ -#define WRAPPER(modulename,...) \ -\ -static PyObject* modulename(PyObject* self,PyObject* args);\ -static PyMethodDef modulename##_funcs[] = {\ - {#modulename, (PyCFunction)modulename, METH_VARARGS, ""},\ - {NULL,NULL,0,NULL}\ -};\ -\ -static struct PyModuleDef modulename##module= {\ - PyModuleDef_HEAD_INIT,\ - #modulename, /* name of module */\ - NULL, /* module documentation, may be NULL */\ - -1, /* size of per-interpreter state of the module,\ - or -1 if the module keeps state in global variables. */\ - modulename##_funcs\ -};\ -\ -PyMODINIT_FUNC PyInit_##modulename(void){\ -\ - import_array();\ - return PyModule_Create(&modulename##module);\ -}\ -\ -static PyObject* modulename(PyObject* self,PyObject* args) -/*}}}*/ -#else -/* WRAPPER 2.7 {{{*/ -#define WRAPPER(modulename,...) \ -\ -static PyObject* modulename(PyObject* self,PyObject* args);\ -static PyMethodDef modulename##_funcs[] = {\ - {#modulename, (PyCFunction)modulename, METH_VARARGS, ""},\ - {NULL,NULL,0,NULL}\ -};\ -\ -PyMODINIT_FUNC init##modulename(void){\ -\ - import_array();\ - (void) Py_InitModule(#modulename, modulename##_funcs);\ -}\ -\ -static PyObject* modulename(PyObject* self,PyObject* args) -/*}}}*/ -#endif -/* CHECKARGUMENTS {{{*/ -#define CHECKARGUMENTS(NLHS,NRHS,functionpointer) CheckNumPythonArguments(args, NRHS,functionpointer) -/*}}}*/ -#endif - -#endif Index: ../trunk-jpl/src/c/python/io/pythonio.h =================================================================== --- ../trunk-jpl/src/c/python/io/pythonio.h (revision 13748) +++ ../trunk-jpl/src/c/python/io/pythonio.h (revision 13749) @@ -1,43 +0,0 @@ -/*\file pythonio.h - *\brief: I/O for ISSM in python mode - */ - -#ifndef _PYTHON_IO_H_ -#define _PYTHON_IO_H_ - -#ifdef HAVE_CONFIG_H -#include -#else -#error "Cannot compile with HAVE_CONFIG_H symbol! run configure first!" -#endif - -#include "../../classes/classes.h" -#include "../../Container/Container.h" -#include "../../include/include.h" - -void WriteData(PyObject* py_tuple,int index, double* matrix, int M,int N); -void WriteData(PyObject* py_tuple,int index, int integer); -void WriteData(PyObject* py_tuple,int index, char* string); -void WriteData(PyObject* py_tuple,int index); -void WriteData(PyObject* py_tuple,int index, SeqMat* matrix); -void WriteData(PyObject* py_tuple,int index, SeqVec* vector); -void WriteData(PyObject* py_tuple,int index, BamgGeom* bamggeom); -void WriteData(PyObject* py_tuple,int index, BamgMesh* bamgmesh); -void WriteData(PyObject* py_tuple,int index, RiftStruct* riftstruct); - -void FetchData(double** pvector,int* pM,PyObject* py_ref); -void FetchData(double** pmatrix,int* pM,int *pN,PyObject* py_array); -void FetchData(int** pmatrix,int* pM,int *pN,PyObject* py_matrix); -void FetchData(char** pstring,PyObject* py_unicode); -void FetchData(double* pscalar,PyObject* py_float); -void FetchData(int* pinteger,PyObject* py_long); -void FetchData(bool* pbool,PyObject* py_boolean); -void FetchData(BamgGeom** bamggeom,PyObject* py_dict); -void FetchData(BamgMesh** bamgmesh,PyObject* py_dict); -void FetchData(BamgOpts** bamgopts,PyObject* py_dict); -void FetchData(Options** poptions,int istart, int nrhs,PyObject* py_tuple); -void FetchData(DataSet** pcontours,PyObject* py_list); - -int CheckNumPythonArguments(PyObject* inputs,int NRHS, void (*function)( void )); - -#endif /* _IO_H_ */ Index: ../trunk-jpl/src/c/python/io/CheckNumPythonArguments.cpp =================================================================== --- ../trunk-jpl/src/c/python/io/CheckNumPythonArguments.cpp (revision 13748) +++ ../trunk-jpl/src/c/python/io/CheckNumPythonArguments.cpp (revision 13749) @@ -1,35 +0,0 @@ -/*!\file CheckNumPythonArguments.cpp: - * \brief: check number of arguments and report an usage error message. - */ - -#ifdef HAVE_CONFIG_H - #include -#else -#error "Cannot compile with HAVE_CONFIG_H symbol! run configure first!" -#endif - -#define PY_ARRAY_UNIQUE_SYMBOL PythonIOSymbol -#define NO_IMPORT - -#include "../../toolkits/toolkits.h" -#include "../../shared/Exceptions/exceptions.h" -#include "../../include/include.h" - -int CheckNumPythonArguments(PyObject* inputs,int NRHS, void (*function)( void )){ - - Py_ssize_t size=0; - - /*figure out size of tuple in input: */ - size=PyTuple_Size(inputs); - - /*check on requested size: */ - if (size==0){ - function(); - _error_("usage: see above"); - } - else if (size!=NRHS ) { - function(); - _error_("usage error."); - } - return 1; -} Index: ../trunk-jpl/src/c/python/io/FetchPythonData.cpp =================================================================== --- ../trunk-jpl/src/c/python/io/FetchPythonData.cpp (revision 13748) +++ ../trunk-jpl/src/c/python/io/FetchPythonData.cpp (revision 13749) @@ -1,356 +0,0 @@ -/*\file FetchData.cpp: - * \brief: general I/O interface to fetch data in python - */ - -#ifdef HAVE_CONFIG_H - #include -#else -#error "Cannot compile with HAVE_CONFIG_H symbol! run configure first!" -#endif - -#define PY_ARRAY_UNIQUE_SYMBOL PythonIOSymbol -#define NO_IMPORT - -#include "../../toolkits/toolkits.h" -#include "../../include/include.h" -#include "../../shared/shared.h" -#include "../../io/io.h" -void FetchData(char** pstring,PyObject* py_string); - -/*Primitive data types*/ -/*FUNCTION FetchData(double* pscalar,PyObject* py_float){{{*/ -void FetchData(double* pscalar,PyObject* py_float){ - - double scalar; - - /*return internal value: */ - scalar=PyFloat_AsDouble(py_float); - - /*output: */ - *pscalar=scalar; -} -/*}}}*/ -/*FUNCTION FetchData(int* pinteger,PyObject* py_long){{{*/ -void FetchData(int* pinteger, PyObject* py_long){ - - int integer; - - /*return internal value: */ - integer=(int)PyLong_AsLong(py_long); - - /*output: */ - *pinteger=integer; -} -/*}}}*/ -/*FUNCTION FetchData(bool* pboolean,PyObject* py_boolean){{{*/ -void FetchData(bool* pboolean,PyObject* py_boolean){ - - bool boolean; - - /*check this is indeed a subtype of long type: */ - if(!PyBool_Check(py_boolean))_error_("expecting a boolean in input!"); - - /*extract boolean: */ - boolean=(bool)PyLong_AsLong(py_boolean); - - /*simple copy: */ - *pboolean=boolean; - -} -/*}}}*/ -/*FUNCTION FetchData(double** pmatrix,int* pM, int* pN, PyObject* py_matrix){{{*/ -void FetchData(double** pmatrix,int* pM,int *pN,PyObject* py_matrix){ - - /*output: */ - double* dmatrix=NULL; - double* matrix=NULL; - int M,N; - int ndim; - npy_intp* dims=NULL; - - /*retrive dimensions: */ - ndim=PyArray_NDIM((const PyArrayObject*)py_matrix); - if(ndim!=2)_error_("expecting an MxN matrix in input!"); - dims=PyArray_DIMS((PyArrayObject*)py_matrix); - M=dims[0]; N=dims[1]; - - if (M && N) { - /*retrieve internal value: */ - dmatrix=(double*)PyArray_DATA((PyArrayObject*)py_matrix); - - /*copy matrix: */ - matrix=xNew(M*N); - memcpy(matrix,dmatrix,(M*N)*sizeof(double)); - } - else - matrix=NULL; - - /*output: */ - if(pM)*pM=M; - if(pN)*pN=N; - if(pmatrix)*pmatrix=matrix; -} -/*}}}*/ -/*FUNCTION FetchData(int** pmatrix,int* pM, int* pN, PyObject* py_matrix){{{*/ -void FetchData(int** pmatrix,int* pM,int *pN,PyObject* py_matrix){ - - /*output: */ - double* dmatrix=NULL; - int* matrix=NULL; - int M,N; - - /*intermediary:*/ - int i; - int ndim; - npy_intp* dims=NULL; - - /*retrive dimensions: */ - ndim=PyArray_NDIM((const PyArrayObject*)py_matrix); - if(ndim!=2)_error_("expecting an MxN matrix in input!"); - dims=PyArray_DIMS((PyArrayObject*)py_matrix); - M=dims[0]; N=dims[1]; - - if (M && N) { - /*retrieve internal value: */ - dmatrix=(double*)PyArray_DATA((PyArrayObject*)py_matrix); - - /*transform into integer matrix: */ - matrix=xNew(M*N); - for(i=0;i(M); - memcpy(vector,dvector,(M)*sizeof(double)); - } - else - vector=NULL; - - /*output: */ - if(pM)*pM=M; - if(pvector)*pvector=vector; -} -/*}}}*/ - -/*ISSM objects*/ -/*FUNCTION FetchData(BamgGeom** pbamggeom,PyObject* py_dict){{{*/ -void FetchData(BamgGeom** pbamggeom,PyObject* py_dict){ - - /*Initialize output*/ - BamgGeom* bamggeom=new BamgGeom(); - - /*Fetch all fields*/ - FetchData(&bamggeom->Vertices,&bamggeom->VerticesSize[0],&bamggeom->VerticesSize[1],PyDict_GetItemString(py_dict,"Vertices")); - FetchData(&bamggeom->Edges, &bamggeom->EdgesSize[0], &bamggeom->EdgesSize[1], PyDict_GetItemString(py_dict,"Edges")); - FetchData(&bamggeom->Corners, &bamggeom->CornersSize[0], &bamggeom->CornersSize[1], PyDict_GetItemString(py_dict,"Corners")); - FetchData(&bamggeom->RequiredVertices,&bamggeom->RequiredVerticesSize[0],&bamggeom->RequiredVerticesSize[1],PyDict_GetItemString(py_dict,"RequiredVertices")); - FetchData(&bamggeom->RequiredEdges, &bamggeom->RequiredEdgesSize[0], &bamggeom->RequiredEdgesSize[1], PyDict_GetItemString(py_dict,"RequiredEdges")); - FetchData(&bamggeom->CrackedEdges,&bamggeom->CrackedEdgesSize[0],&bamggeom->CrackedEdgesSize[1],PyDict_GetItemString(py_dict,"CrackedEdges")); - FetchData(&bamggeom->SubDomains,&bamggeom->SubDomainsSize[0],&bamggeom->SubDomainsSize[1],PyDict_GetItemString(py_dict,"SubDomains")); - - /*Assign output pointers:*/ - *pbamggeom=bamggeom; -} -/*}}}*/ -/*FUNCTION FetchData(BamgMesh** pbamgmesh,PyObject* py_dict){{{*/ -void FetchData(BamgMesh** pbamgmesh,PyObject* py_dict){ - - /*Initialize output*/ - BamgMesh* bamgmesh=new BamgMesh(); - - /*Fetch all fields*/ - FetchData(&bamgmesh->Vertices,&bamgmesh->VerticesSize[0],&bamgmesh->VerticesSize[1],PyDict_GetItemString(py_dict,"Vertices")); - FetchData(&bamgmesh->Edges, &bamgmesh->EdgesSize[0], &bamgmesh->EdgesSize[1], PyDict_GetItemString(py_dict,"Edges")); - FetchData(&bamgmesh->Triangles, &bamgmesh->TrianglesSize[0], &bamgmesh->TrianglesSize[1], PyDict_GetItemString(py_dict,"Triangles")); - FetchData(&bamgmesh->CrackedEdges,&bamgmesh->CrackedEdgesSize[0],&bamgmesh->CrackedEdgesSize[1],PyDict_GetItemString(py_dict,"CrackedEdges")); - FetchData(&bamgmesh->VerticesOnGeomEdge,&bamgmesh->VerticesOnGeomEdgeSize[0],&bamgmesh->VerticesOnGeomEdgeSize[1],PyDict_GetItemString(py_dict,"VerticesOnGeomEdge")); - FetchData(&bamgmesh->VerticesOnGeomVertex,&bamgmesh->VerticesOnGeomVertexSize[0],&bamgmesh->VerticesOnGeomVertexSize[1],PyDict_GetItemString(py_dict,"VerticesOnGeomVertex")); - FetchData(&bamgmesh->EdgesOnGeomEdge, &bamgmesh->EdgesOnGeomEdgeSize[0], &bamgmesh->EdgesOnGeomEdgeSize[1], PyDict_GetItemString(py_dict,"EdgesOnGeomEdge")); - FetchData(&bamgmesh->IssmSegments,&bamgmesh->IssmSegmentsSize[0],&bamgmesh->IssmSegmentsSize[1],PyDict_GetItemString(py_dict,"IssmSegments")); - - /*Assign output pointers:*/ - *pbamgmesh=bamgmesh; -} -/*}}}*/ -/*FUNCTION FetchData(BamgOpts** pbamgopts,PyObject* py_dict){{{*/ -void FetchData(BamgOpts** pbamgopts,PyObject* py_dict){ - - /*Initialize output*/ - BamgOpts* bamgopts=new BamgOpts(); - - /*Fetch all fields*/ - FetchData(&bamgopts->anisomax,PyDict_GetItemString(py_dict,"anisomax")); - FetchData(&bamgopts->cutoff,PyDict_GetItemString(py_dict,"cutoff")); - FetchData(&bamgopts->coeff,PyDict_GetItemString(py_dict,"coeff")); - FetchData(&bamgopts->errg,PyDict_GetItemString(py_dict,"errg")); - FetchData(&bamgopts->gradation,PyDict_GetItemString(py_dict,"gradation")); - FetchData(&bamgopts->Hessiantype,PyDict_GetItemString(py_dict,"Hessiantype")); - FetchData(&bamgopts->MaxCornerAngle,PyDict_GetItemString(py_dict,"MaxCornerAngle")); - FetchData(&bamgopts->maxnbv,PyDict_GetItemString(py_dict,"maxnbv")); - FetchData(&bamgopts->maxsubdiv,PyDict_GetItemString(py_dict,"maxsubdiv")); - FetchData(&bamgopts->Metrictype,PyDict_GetItemString(py_dict,"Metrictype")); - FetchData(&bamgopts->nbjacobi,PyDict_GetItemString(py_dict,"nbjacobi")); - FetchData(&bamgopts->nbsmooth,PyDict_GetItemString(py_dict,"nbsmooth")); - FetchData(&bamgopts->omega,PyDict_GetItemString(py_dict,"omega")); - FetchData(&bamgopts->power,PyDict_GetItemString(py_dict,"power")); - FetchData(&bamgopts->verbose,PyDict_GetItemString(py_dict,"verbose")); - - FetchData(&bamgopts->Crack,PyDict_GetItemString(py_dict,"Crack")); - FetchData(&bamgopts->geometricalmetric,PyDict_GetItemString(py_dict,"geometricalmetric")); - FetchData(&bamgopts->KeepVertices,PyDict_GetItemString(py_dict,"KeepVertices")); - FetchData(&bamgopts->splitcorners,PyDict_GetItemString(py_dict,"splitcorners")); - - FetchData(&bamgopts->hmin,PyDict_GetItemString(py_dict,"hmin")); - FetchData(&bamgopts->hmax,PyDict_GetItemString(py_dict,"hmax")); - FetchData(&bamgopts->hminVertices,&bamgopts->hminVerticesSize[0],&bamgopts->hminVerticesSize[1],PyDict_GetItemString(py_dict,"hminVertices")); - FetchData(&bamgopts->hmaxVertices,&bamgopts->hmaxVerticesSize[0],&bamgopts->hmaxVerticesSize[1],PyDict_GetItemString(py_dict,"hmaxVertices")); - FetchData(&bamgopts->hVertices,&bamgopts->hVerticesSize[0],&bamgopts->hVerticesSize[1],PyDict_GetItemString(py_dict,"hVertices")); - FetchData(&bamgopts->metric,&bamgopts->metricSize[0],&bamgopts->metricSize[1],PyDict_GetItemString(py_dict,"metric")); - FetchData(&bamgopts->field,&bamgopts->fieldSize[0],&bamgopts->fieldSize[1],PyDict_GetItemString(py_dict,"field")); - FetchData(&bamgopts->err,&bamgopts->errSize[0],&bamgopts->errSize[1],PyDict_GetItemString(py_dict,"err")); - - /*Additional checks*/ - bamgopts->Check(); - - /*Assign output pointers:*/ - *pbamgopts=bamgopts; -} -/*}}}*/ -/*FUNCTION FetchData(Options** poptions,int istart, int nrhs,PyObject* py_tuple){{{*/ -void FetchData(Options** poptions,int istart, int nrhs,PyObject* py_tuple){ - - char *name = NULL; - Option *option = NULL; - - /*Initialize output*/ - Options* options=new Options(); - - /*Fetch all options*/ - for (int i=istart; iAddOption(option); -// option=NULL; - } - - /*Assign output pointers:*/ - *poptions=options; -} -/*}}}*/ -/*FUNCTION FetchData(DataSet** pcontours,PyObject* py_list){{{*/ -void FetchData(DataSet** pcontours,PyObject* py_list){ - - int numcontours,test1,test2; - char *contourname = NULL; - DataSet *contours = NULL; - Contour *contouri = NULL; - PyObject *py_dicti = NULL; - PyObject *py_item = NULL; - - if (PyString_Check(py_list)){ - FetchData(&contourname,py_list); - contours=DomainOutlineRead(contourname); - } - else if(PyList_Check(py_list)){ - - contours=new DataSet(0); - numcontours=(int)PyList_Size(py_list); - - for(int i=0;i >(1); - py_dicti=PyList_GetItem(py_list,(Py_ssize_t)i); - - py_item = PyDict_GetItemString(py_dicti,"nods"); - if(!py_item) _error_("input structure does not have a 'nods' field"); - FetchData(&contouri->nods,py_item); - - py_item = PyDict_GetItemString(py_dicti,"x"); - if(!py_item) _error_("input structure does not have a 'x' field"); - FetchData(&contouri->x,&test1,&test2,py_item); - if(test1!=contouri->nods || test2!=1) _error_("field x should be of size ["<nods<<" 1]"); - - py_item = PyDict_GetItemString(py_dicti,"y"); - if(!py_item) _error_("input structure does not have a 'y' field"); - FetchData(&contouri->y,&test1,&test2,py_item); - if(test1!=contouri->nods || test2!=1) _error_("field y should be of size ["<nods<<" 1]"); - - contours->AddObject(contouri); - } - } - else{ - _error_("Contour is neither a string nor a structure and cannot be loaded"); - } - - /*clean-up and assign output pointer*/ - xDelete(contourname); - *pcontours=contours; -} -/*}}}*/ - -/*Python version dependent: */ -#if _PYTHON_MAJOR_ >= 3 -/*FUNCTION FetchData(char** pstring,PyObject* py_unicode){{{*/ -void FetchData(char** pstring,PyObject* py_unicode){ - - PyObject* py_bytes; - char* string=NULL; - - /*convert to bytes format: */ - PyUnicode_FSConverter(py_unicode,&py_bytes); - - /*convert from bytes to string: */ - string=PyBytes_AS_STRING(py_bytes); - - *pstring=string; -} -/*}}}*/ -#else -/*FUNCTION FetchData(char** pstring,PyObject* py_string){{{*/ -void FetchData(char** pstring,PyObject* py_string){ - - char* string=NULL; - - /*extract internal string: */ - string=PyString_AsString(py_string); - - /*copy string (note strlen does not include trailing NULL): */ - *pstring=xNew(strlen(string)+1); - memcpy(*pstring,string,(strlen(string)+1)*sizeof(char)); -} -/*}}}*/ -#endif Index: ../trunk-jpl/src/c/python/io/WritePythonData.cpp =================================================================== --- ../trunk-jpl/src/c/python/io/WritePythonData.cpp (revision 13748) +++ ../trunk-jpl/src/c/python/io/WritePythonData.cpp (revision 13749) @@ -1,198 +0,0 @@ -/* \file WriteData.c: - * \brief: general interface for writing data - */ - -#ifdef HAVE_CONFIG_H - #include -#else -#error "Cannot compile with HAVE_CONFIG_H symbol! run configure first!" -#endif - -#define PY_ARRAY_UNIQUE_SYMBOL PythonIOSymbol -#define NO_IMPORT - -#include "../../toolkits/toolkits.h" -#include "../../include/include.h" -#include "../../modules/modules.h" -#include "../../Container/Container.h" -#include "../../shared/shared.h" -#include "../../io/io.h" -#include "../../EnumDefinitions/EnumDefinitions.h" -PyObject* PyArrayFromCopiedData(int dims[2],double* data); -PyObject* PyArrayFromCopiedData(int dimi,int dimj,double* data); - -/*Primitive data types*/ -/*FUNCTION WriteData(PyObject* py_tuple,int index,int integer){{{*/ -void WriteData(PyObject* py_tuple, int index, int integer){ - - PyTuple_SetItem(py_tuple, index, PyInt_FromSsize_t((Py_ssize_t)integer)); - -}/*}}}*/ -/*FUNCTION WriteData(PyObject* py_tuple,int index,char* string){{{*/ -void WriteData(PyObject* py_tuple, int index, char* string){ - - PyTuple_SetItem(py_tuple, index, PyUnicode_FromString(string)); - -}/*}}}*/ -/*FUNCTION WriteData(PyObject* py_tuple,int index, double* matrix, int M, int N){{{*/ -void WriteData(PyObject* tuple, int index, double* matrix, int M,int N){ - - npy_intp dims[2]={0,0}; - PyObject* array=NULL; - - dims[0]=(npy_intp)M; - dims[1]=(npy_intp)N; - array=PyArray_SimpleNewFromData(2,dims,NPY_DOUBLE,matrix); - - PyTuple_SetItem(tuple, index, array); -}/*}}}*/ -/*FUNCTION WriteData(PyObject* py_tuple,int index){{{*/ -void WriteData(PyObject* py_tuple, int index){ - - PyTuple_SetItem(py_tuple, index, Py_None); - -}/*}}}*/ - -/*ISSM objects*/ -/*FUNCTION WriteData(PyObject* py_tuple,int index,BamgGeom* bamggeom){{{*/ -void WriteData(PyObject* py_tuple,int index,BamgGeom* bamggeom){ - - PyObject* dict=NULL; - - dict=PyDict_New(); - - PyDict_SetItemString(dict,"Vertices",PyArrayFromCopiedData(bamggeom->VerticesSize,bamggeom->Vertices)); - PyDict_SetItemString(dict,"Edges",PyArrayFromCopiedData(bamggeom->EdgesSize,bamggeom->Edges)); - PyDict_SetItemString(dict,"TangentAtEdges",PyArrayFromCopiedData(bamggeom->TangentAtEdgesSize,bamggeom->TangentAtEdges)); - PyDict_SetItemString(dict,"Corners",PyArrayFromCopiedData(bamggeom->CornersSize,bamggeom->Corners)); - PyDict_SetItemString(dict,"RequiredVertices",PyArrayFromCopiedData(bamggeom->RequiredVerticesSize,bamggeom->RequiredVertices)); - PyDict_SetItemString(dict,"RequiredEdges",PyArrayFromCopiedData(bamggeom->RequiredEdgesSize,bamggeom->RequiredEdges)); - PyDict_SetItemString(dict,"CrackedEdges",PyArrayFromCopiedData(bamggeom->CrackedEdgesSize,bamggeom->CrackedEdges)); - PyDict_SetItemString(dict,"SubDomains",PyArrayFromCopiedData(bamggeom->SubDomainsSize,bamggeom->SubDomains)); - - PyTuple_SetItem(py_tuple, index, dict); -} -/*}}}*/ -/*FUNCTION WriteData(PyObject* py_tuple,int index,BamgMesh* bamgmesh){{{*/ -void WriteData(PyObject* py_tuple,int index,BamgMesh* bamgmesh){ - - PyObject* dict=NULL; - - dict=PyDict_New(); - - PyDict_SetItemString(dict,"Vertices",PyArrayFromCopiedData(bamgmesh->VerticesSize,bamgmesh->Vertices)); - PyDict_SetItemString(dict,"Edges",PyArrayFromCopiedData(bamgmesh->EdgesSize,bamgmesh->Edges)); - PyDict_SetItemString(dict,"Triangles",PyArrayFromCopiedData(bamgmesh->TrianglesSize,bamgmesh->Triangles)); - PyDict_SetItemString(dict,"Quadrilaterals",PyArrayFromCopiedData(bamgmesh->QuadrilateralsSize,bamgmesh->Quadrilaterals)); - PyDict_SetItemString(dict,"IssmEdges",PyArrayFromCopiedData(bamgmesh->IssmEdgesSize,bamgmesh->IssmEdges)); - PyDict_SetItemString(dict,"IssmSegments",PyArrayFromCopiedData(bamgmesh->IssmSegmentsSize,bamgmesh->IssmSegments)); - PyDict_SetItemString(dict,"VerticesOnGeomVertex",PyArrayFromCopiedData(bamgmesh->VerticesOnGeomVertexSize,bamgmesh->VerticesOnGeomVertex)); - PyDict_SetItemString(dict,"VerticesOnGeomEdge",PyArrayFromCopiedData(bamgmesh->VerticesOnGeomEdgeSize,bamgmesh->VerticesOnGeomEdge)); - PyDict_SetItemString(dict,"EdgesOnGeomEdge",PyArrayFromCopiedData(bamgmesh->EdgesOnGeomEdgeSize,bamgmesh->EdgesOnGeomEdge)); - PyDict_SetItemString(dict,"SubDomains",PyArrayFromCopiedData(bamgmesh->SubDomainsSize,bamgmesh->SubDomains)); - PyDict_SetItemString(dict,"SubDomainsFromGeom",PyArrayFromCopiedData(bamgmesh->SubDomainsFromGeomSize,bamgmesh->SubDomainsFromGeom)); - PyDict_SetItemString(dict,"ElementConnectivity",PyArrayFromCopiedData(bamgmesh->ElementConnectivitySize,bamgmesh->ElementConnectivity)); - PyDict_SetItemString(dict,"NodalConnectivity",PyArrayFromCopiedData(bamgmesh->NodalConnectivitySize,bamgmesh->NodalConnectivity)); - PyDict_SetItemString(dict,"NodalElementConnectivity",PyArrayFromCopiedData(bamgmesh->NodalElementConnectivitySize,bamgmesh->NodalElementConnectivity)); - PyDict_SetItemString(dict,"CrackedVertices",PyArrayFromCopiedData(bamgmesh->CrackedVerticesSize,bamgmesh->CrackedVertices)); - PyDict_SetItemString(dict,"CrackedEdges",PyArrayFromCopiedData(bamgmesh->CrackedEdgesSize,bamgmesh->CrackedEdges)); - - PyTuple_SetItem(py_tuple, index, dict); -} -/*}}}*/ -/*FUNCTION WriteData(PyObject* py_tuple,int index,SeqMat* matrix){{{*/ -void WriteData(PyObject* py_tuple,int index,SeqMat* matrix){ - - int M,N; - double* buffer=NULL; - npy_intp dims[2]={0,0}; - PyObject* array=NULL; - - buffer=matrix->ToSerial(); - matrix->GetSize(&M,&N); - dims[0]=(npy_intp)M; - dims[1]=(npy_intp)N; - array=PyArray_SimpleNewFromData(2,dims,NPY_DOUBLE,buffer); - - PyTuple_SetItem(py_tuple, index, array); - -}/*}}}*/ -/*FUNCTION WriteData(PyObject* py_tuple,int index,SeqVec* vector){{{*/ -void WriteData(PyObject* py_tuple,int index,SeqVec* vector){ - - int M; - double* buffer=NULL; - npy_intp dim=10; - PyObject* array=NULL; - - buffer=vector->ToMPISerial(); - vector->GetSize(&M); - dim=(npy_intp)M; - array=PyArray_SimpleNewFromData(1,&dim,NPY_DOUBLE,buffer); - - PyTuple_SetItem(py_tuple, index, array); -} -/*}}}*/ -/*FUNCTION WriteData(PyObject* py_tuple,int index,RiftStruct* riftstruct){{{*/ -void WriteData(PyObject* py_tuple,int index,RiftStruct* riftstruct){ - - int i; - PyObject* list=NULL; - PyObject* dict=NULL; - - list=PyList_New((Py_ssize_t)0); - - for (i=0; inumrifts; i++) { - dict=PyDict_New(); - - PyDict_SetItemString(dict,"numsegs" ,PyInt_FromSsize_t((Py_ssize_t)riftstruct->riftsnumsegments[i])); - PyDict_SetItemString(dict,"segments" ,PyArrayFromCopiedData(riftstruct->riftsnumsegments[i] ,3,riftstruct->riftssegments[i])); - PyDict_SetItemString(dict,"pairs" ,PyArrayFromCopiedData(riftstruct->riftsnumpairs[i] ,2,riftstruct->riftspairs[i])); - PyDict_SetItemString(dict,"tips" ,PyArrayFromCopiedData(1 ,2,&riftstruct->riftstips[2*i])); - PyDict_SetItemString(dict,"penaltypairs" ,PyArrayFromCopiedData(riftstruct->riftsnumpenaltypairs[i],7,riftstruct->riftspenaltypairs[i])); - PyDict_SetItemString(dict,"fill" ,PyInt_FromSsize_t((Py_ssize_t)IceEnum)); - PyDict_SetItemString(dict,"friction" ,PyInt_FromSsize_t((Py_ssize_t)0)); - PyDict_SetItemString(dict,"fraction" ,PyFloat_FromDouble(0.)); - PyDict_SetItemString(dict,"fractionincrement",PyFloat_FromDouble(0.1)); - PyDict_SetItemString(dict,"state" ,PyArrayFromCopiedData(riftstruct->riftsnumpenaltypairs[i],1,riftstruct->state[i])); - - PyList_Append(list, dict); - } - - PyTuple_SetItem(py_tuple, index, list); -} -/*}}}*/ - -/*Utils*/ -/*FUNCTION PyArrayFromCopiedData(int dims[2],double* data){{{*/ -PyObject* PyArrayFromCopiedData(int dims[2],double* data){ - - double* pydata; - npy_intp pydims[2]={0,0}; - - /* note that PyArray_SimpleNewFromData does not copy the data, so that when the original - object (e.g. bamggeom,bamgmesh) is deleted, the data is gone. */ - - pydims[0]=(npy_intp)dims[0]; - pydims[1]=(npy_intp)dims[1]; - pydata=xNew(dims[0]*dims[1]); - memcpy(pydata,data,dims[0]*dims[1]*sizeof(double)); - return PyArray_SimpleNewFromData(2,pydims,NPY_DOUBLE,pydata); -} -/*}}}*/ -/*FUNCTION PyArrayFromCopiedData(int dimi,int dimj,double* data){{{*/ -PyObject* PyArrayFromCopiedData(int dimi,int dimj,double* data){ - - double* pydata; - npy_intp pydims[2]={0,0}; - - /* note that PyArray_SimpleNewFromData does not copy the data, so that when the original - object (e.g. bamggeom,bamgmesh) is deleted, the data is gone. */ - - pydims[0]=(npy_intp)dimi; - pydims[1]=(npy_intp)dimj; - pydata=xNew(dimi*dimj); - memcpy(pydata,data,dimi*dimj*sizeof(double)); - return PyArray_SimpleNewFromData(2,pydims,NPY_DOUBLE,pydata); -} -/*}}}*/ Index: ../trunk-jpl/src/c/issm-binding.h =================================================================== --- ../trunk-jpl/src/c/issm-binding.h (revision 13748) +++ ../trunk-jpl/src/c/issm-binding.h (revision 13749) @@ -1,18 +0,0 @@ -#ifndef _ISSM_BINDING_H_ -#define _ISSM_BINDING_H_ - -#ifdef HAVE_CONFIG_H - #include -#else -#error "Cannot compile with HAVE_CONFIG_H symbol! run configure first!" -#endif - -#ifdef _HAVE_MATLAB_MODULES_ -#include "./matlab/matlab-binding.h" -#endif - -#ifdef _HAVE_PYTHON_MODULES_ -#include "./python/python-binding.h" -#endif - -#endif Index: ../trunk-jpl/src/c/matlab/include/matlab_macros.h =================================================================== --- ../trunk-jpl/src/c/matlab/include/matlab_macros.h (revision 13748) +++ ../trunk-jpl/src/c/matlab/include/matlab_macros.h (revision 13749) @@ -1,44 +0,0 @@ -/* \file matlab macros.h - * \brief: macros used for the matlab bindings - */ - -/*Header {{{*/ -#ifndef _MATLAB_MACROS_H_ -#define _MATLAB_MACROS_H_ - -#ifdef HAVE_CONFIG_H - #include -#else -#error "Cannot compile with HAVE_CONFIG_H symbol! run configure first!" -#endif -/*}}}*/ - -#ifdef _HAVE_MATLAB_ -/* MODULEBOOT/MODULEEND {{{*/ - -/*The following macros hide the error exception handling in a matlab module. Just put - * MODULEBOOT(); and MODULEEND(); at the beginning and end of a module, and c++ exceptions - * will be trapped*/ -#define MODULEBOOT(); try{ \ - IssmComm::SetComm(-1); - -#define MODULEEND(); }\ - catch(ErrorException &exception){\ - mexErrMsgTxt(exception.MatlabReport()); \ - }\ - catch (exception &e){\ - mexErrMsgTxt(exprintf("Standard exception: %s\n",e.what()));\ - }\ - catch(...){\ - mexErrMsgTxt("An unexpected error occurred");\ - } -/*}}}*/ -/* WRAPPER {{{*/ -#define WRAPPER(modulename,...) void mexFunction(int nlhs, mxArray* plhs[], int nrhs, const mxArray* prhs[]) -/*}}}*/ -/* CHECKARGUMENTS {{{*/ -#define CHECKARGUMENTS(NLHS,NRHS,functionpointer) CheckNumMatlabArguments(nlhs,NLHS,nrhs,NRHS,__FUNCT__,functionpointer) -/*}}}*/ -#endif - -#endif Index: ../trunk-jpl/src/c/matlab/io/OptionParse.cpp =================================================================== --- ../trunk-jpl/src/c/matlab/io/OptionParse.cpp (revision 13748) +++ ../trunk-jpl/src/c/matlab/io/OptionParse.cpp (revision 13749) @@ -1,203 +0,0 @@ -/*\file OptionParse.c - *\brief: functions to parse the mex options. - */ -#ifdef HAVE_CONFIG_H - #include -#else -#error "Cannot compile with HAVE_CONFIG_H symbol! run configure first!" -#endif - -#include -#include -#include "../../shared/shared.h" -#include "../../io/io.h" -#include "../../include/include.h" -#include "./matlabio.h" - -GenericOption* OptionDoubleParse( char* name, const mxArray* prhs[]){ /*{{{*/ - - GenericOption *odouble = NULL; - - /*check and parse the name */ - odouble=new GenericOption(); - odouble->name =xNew(strlen(name)+1); - memcpy(odouble->name,name,(strlen(name)+1)*sizeof(char)); - FetchData(&odouble->value,prhs[0]); - odouble->numel=1; - odouble->ndims=1; - odouble->size=NULL; - - return(odouble); -}/*}}}*/ -GenericOption* OptionDoubleArrayParse( char* name, const mxArray* prhs[]){ /*{{{*/ - - GenericOption *odouble = NULL; - - /*check and parse the name */ - odouble=new GenericOption(); - odouble->name =xNew(strlen(name)+1); - memcpy(odouble->name,name,(strlen(name)+1)*sizeof(char)); - - /*check and parse the value */ - if (!mxIsClass(prhs[0],"double")){ - _error_("Value of option \"" << odouble->name << "\" must be class \"double\", not class \"" << mxGetClassName(prhs[0]) <<"\"."); - } - FetchData(&odouble->value,&odouble->numel,&odouble->ndims,&odouble->size,prhs[0]); - - return(odouble); -}/*}}}*/ -GenericOption* OptionLogicalParse( char* name, const mxArray* prhs[]){ /*{{{*/ - - GenericOption *ological = NULL; - - /*check and parse the name */ - ological=new GenericOption(); - ological->name =xNew(strlen(name)+1); - memcpy(ological->name,name,(strlen(name)+1)*sizeof(char)); - - /*check and parse the value */ - if (!mxIsClass(prhs[0],"logical")){ - _error_("Value of option \"" << ological->name << "\" must be class \"logical\", not class \"" << mxGetClassName(prhs[0]) <<"\"."); - } - FetchData(&ological->value,&ological->numel,&ological->ndims,&ological->size,prhs[0]); - - return(ological); -}/*}}}*/ -GenericOption* OptionCharParse( char* name, const mxArray* prhs[]){ /*{{{*/ - - GenericOption *ochar = NULL; - - /*check and parse the name */ - ochar=new GenericOption(); - ochar->name =xNew(strlen(name)+1); - memcpy(ochar->name,name,(strlen(name)+1)*sizeof(char)); - - /*check and parse the value */ - if (!mxIsClass(prhs[0],"char")){ - _error_("Value of option \"" << ochar->name << "\" must be class \"char\", not class \"" << mxGetClassName(prhs[0]) <<"\"."); - } - FetchData(&ochar->value,&ochar->numel,&ochar->ndims,&ochar->size,prhs[0]); - - return(ochar); -}/*}}}*/ -GenericOption* OptionStructParse( char* name, const mxArray* prhs[]){ /*{{{*/ - - int i; - char namei[161]; - Option* option = NULL; - GenericOption *ostruct = NULL; - const mwSize *ipt = NULL; - const mxArray *structi; - mwIndex sindex; - - /*check and parse the name */ - ostruct=new GenericOption(); - ostruct->name =xNew(strlen(name)+1); - memcpy(ostruct->name,name,(strlen(name)+1)*sizeof(char)); - - /*check and parse the value */ - if (!mxIsClass(prhs[0],"struct")){ - _error_("Value of option \"" << ostruct->name << "\" must be class \"struct\", not class \"" << mxGetClassName(prhs[0]) <<"\"."); - } - ostruct->numel=mxGetNumberOfElements(prhs[0]); - ostruct->ndims=mxGetNumberOfDimensions(prhs[0]); - ipt =mxGetDimensions(prhs[0]); - ostruct->size =xNew(ostruct->ndims); - for (i=0; indims; i++) ostruct->size[i]=(int)ipt[i]; - if (ostruct->numel) ostruct->value=xNew(ostruct->numel); - - /*loop through and process each element of the struct array */ - for (sindex=0; sindexnumel; sindex++) { - ostruct->value[sindex]=new Options; - - /*loop through and process each field for the element */ - for (i=0; ivalue[sindex]->AddObject((Object*)option); - option=NULL; - } - } - - return(ostruct); -}/*}}}*/ -GenericOption* OptionCellParse( char* name, const mxArray* prhs[]){ /*{{{*/ - - int i; - int *dims; - char namei[161]; - char cstr[81]; - GenericOption *ocell = NULL; - Option *option = NULL; - const mwSize *ipt = NULL; - const mxArray *celli; - mwIndex cindex; - - /*check and parse the name */ - ocell=new GenericOption(); - ocell->name =xNew(strlen(name)+1); - memcpy(ocell->name,name,(strlen(name)+1)*sizeof(char)); - - /*check and parse the value */ - if (!mxIsClass(prhs[0],"cell")){ - _error_("Value of option \"" << ocell->name << "\" must be class \"cell\", not class \"" << mxGetClassName(prhs[0]) <<"\"."); - } - - ocell->numel=mxGetNumberOfElements(prhs[0]); - ocell->ndims=mxGetNumberOfDimensions(prhs[0]); - ipt =mxGetDimensions(prhs[0]); - ocell->size =xNew(ocell->ndims); - for (i=0; indims; i++) ocell->size[i]=(int)ipt[i]; - ocell->value=new Options; - - /*loop through and process each element of the cell array */ - dims=xNew(ocell->ndims); - for (cindex=0; cindexnumel; cindex++) { - ColumnWiseDimsFromIndex(dims,(int)cindex,ocell->size,ocell->ndims); - StringFromDims(cstr,dims,ocell->ndims); - #ifdef _INTEL_WIN_ - _snprintf(namei,161,"%s%s",name,cstr); - #else - snprintf(namei,161,"%s%s",name,cstr); - #endif - celli=mxGetCell(prhs[0],cindex); - - option=(Option*)OptionParse(namei,&celli); - ocell->value->AddObject((Object*)option); - option=NULL; - } - xDelete(dims); - - return(ocell); -}/*}}}*/ -Option* OptionParse(char* name, const mxArray* prhs[]){ /*{{{*/ - - Option *option = NULL; - mxArray *lhs[1]; - - /*parse the value according to the matlab data type */ - if (mxIsClass(prhs[0],"double") && (mxGetNumberOfElements(prhs[0])==1)) - option=(Option*)OptionDoubleParse(name,prhs); - else if(mxIsClass(prhs[0],"double") && (mxGetNumberOfElements(prhs[0])!=1)) - option=(Option*)OptionDoubleArrayParse(name,prhs); - else if(mxIsClass(prhs[0],"logical")) - option=(Option*)OptionLogicalParse(name,prhs); - else if(mxIsClass(prhs[0],"char")) - option=(Option*)OptionCharParse(name,prhs); - else if(mxIsClass(prhs[0],"struct")) - option=(Option*)OptionStructParse(name,prhs); - else if(mxIsClass(prhs[0],"cell")) - option=(Option*)OptionCellParse(name,prhs); - else { - _pprintLine_(" Converting value of option \"" << name << "\" from unrecognized class \"" << mxGetClassName(prhs[0]) << "\" to class \"" << "struct" << "\"."); - if (!mexCallMATLAB(1,lhs,1,(mxArray**)prhs,"struct")) { - option=(Option*)OptionStructParse(name,(const mxArray**)lhs); - mxDestroyArray(lhs[0]); - } - else _error_("Second argument value of option \""<< name <<"\" is of unrecognized class \""<< mxGetClassName(prhs[0]) <<"\"."); - } - - return(option); -}/*}}}*/ Index: ../trunk-jpl/src/c/matlab/io/MatlabMatrixToSeqMat.cpp =================================================================== --- ../trunk-jpl/src/c/matlab/io/MatlabMatrixToSeqMat.cpp (revision 13748) +++ ../trunk-jpl/src/c/matlab/io/MatlabMatrixToSeqMat.cpp (revision 13749) @@ -1,29 +0,0 @@ -/*!\file MatlabMatrixToSeqMat.cpp - */ - -/*Headers:*/ -/*{{{*/ -#ifdef HAVE_CONFIG_H - #include -#else -#error "Cannot compile with HAVE_CONFIG_H symbol! run configure first!" -#endif - -#include -#include -#include -#include "../../toolkits/toolkits.h" -#include "../../shared/shared.h" -#include "./matlabio.h" - -/*}}}*/ - -SeqMat* MatlabMatrixToSeqMat(const mxArray* dataref){ - - SeqMat* output=NULL; - - output=new SeqMat(); - MatlabMatrixToDoubleMatrix(&output->matrix,&output->M,&output->N,dataref); - return output; - -} Index: ../trunk-jpl/src/c/matlab/io/MatlabVectorToPetscVec.cpp =================================================================== --- ../trunk-jpl/src/c/matlab/io/MatlabVectorToPetscVec.cpp (revision 13748) +++ ../trunk-jpl/src/c/matlab/io/MatlabVectorToPetscVec.cpp (revision 13749) @@ -1,108 +0,0 @@ -/* \file MatlabVectorToPetscVector.cpp - * \brief: convert a sparse or dense matlab vector to a serial Petsc vector: - */ - -#ifdef HAVE_CONFIG_H - #include -#else -#error "Cannot compile with HAVE_CONFIG_H symbol! run configure first!" -#endif - -/*Petsc includes: */ -#include "petscmat.h" -#include "petscvec.h" -#include "petscksp.h" - -/*Matlab includes: */ -#include "mex.h" - -#include "../../shared/shared.h" -#include "matlabio.h" - -PetscVec* MatlabVectorToPetscVec(const mxArray* mxvector){ - - int dummy; - PetscVec* vector=new PetscVec(); - - MatlabVectorToPetscVec(&vector->vector,&dummy, mxvector); - - return vector; -} - -int MatlabVectorToPetscVec(Vec* pvector,int* pvector_rows,const mxArray* mxvector){ - - int rows, cols; - double* mxvector_ptr=NULL; - int ierr; - int i,j; - - /*output: */ - Vec vector=NULL; - - /*matlab indices: */ - mwIndex* ir=NULL; - mwIndex* jc=NULL; - double* pr=NULL; - int count; - int nnz; - int nz; - - /*petsc indices: */ - int* idxm=NULL; - - /*Ok, first check if we are dealing with a sparse or full vector: */ - if (mxIsSparse(mxvector)){ - - /*Dealing with sparse vector: recover size first: */ - mxvector_ptr=(double*)mxGetPr(mxvector); - rows=mxGetM(mxvector); - cols=mxGetN(mxvector); - nnz=mxGetNzmax(mxvector); - nz=(int)((double)nnz/(double)rows); - - ierr=VecCreateSeq(PETSC_COMM_SELF,rows,&vector);CHKERRQ(ierr); - - /*Now, get ir,jc and pr: */ - pr=mxGetPr(mxvector); - ir=mxGetIr(mxvector); - jc=mxGetJc(mxvector); - - /*Now, start inserting data into sparse vector: */ - count=0; - for(i=0;i(rows); - - for(i=0;i -#else -#error "Cannot compile with HAVE_CONFIG_H symbol! run configure first!" -#endif - -#include - -/*Matlab includes: */ -#include "mex.h" - -#include "../../shared/shared.h" - -int MatlabVectorToDoubleVector(double** pvector,int* pvector_rows,const mxArray* mxvector){ - - int rows,cols; - double* mxvector_ptr=NULL; - int ierr; - int i,j; - - /*output: */ - double* vector=NULL; - - /*matlab indices: */ - mwIndex* ir=NULL; - mwIndex* jc=NULL; - double* pr=NULL; - int count; - int nnz; - int nz; - - /*Ok, first check if we are dealing with a sparse or full vector: */ - if (mxIsSparse(mxvector)){ - - /*Dealing with sparse vector: recover size first: */ - mxvector_ptr=(double*)mxGetPr(mxvector); - rows=mxGetM(mxvector); - cols=mxGetN(mxvector); - nnz=mxGetNzmax(mxvector); - - /*Check that input is actualy a vector*/ - if (cols!=1) _error_("input vector of size " << rows << "x" << cols << " should have only one column"); - - nz=(int)((double)nnz/(double)rows); - - if(rows){ - vector=xNewZeroInit(rows); - - /*Now, get ir,jc and pr: */ - pr=mxGetPr(mxvector); - ir=mxGetIr(mxvector); - jc=mxGetJc(mxvector); - - /*Now, start inserting data into sparse vector: */ - count=0; - for(i=0;i(rows); - memcpy(vector,mxvector_ptr,rows*sizeof(double)); - } - else{ - vector=NULL; - } - } - - /*Assign output pointer: */ - *pvector=vector; - *pvector_rows=rows; - - return 1; -} Index: ../trunk-jpl/src/c/matlab/io/FetchMatlabData.cpp =================================================================== --- ../trunk-jpl/src/c/matlab/io/FetchMatlabData.cpp (revision 13748) +++ ../trunk-jpl/src/c/matlab/io/FetchMatlabData.cpp (revision 13749) @@ -1,693 +0,0 @@ -/*\file FetchData.cpp: - * \brief: general I/O interface to fetch data in matlab - */ - -#ifdef HAVE_CONFIG_H - #include -#else -#error "Cannot compile with HAVE_CONFIG_H symbol! run configure first!" -#endif - -#include -#include "../../shared/shared.h" -#include "../../include/include.h" -#include "./matlabio.h" - -/*Primitive data types*/ -/*FUNCTION FetchData(double** pmatrix,int* pM,int *pN,const mxArray* dataref){{{*/ -void FetchData(double** pmatrix,int* pM,int *pN,const mxArray* dataref){ - - double* outmatrix=NULL; - int outmatrix_rows,outmatrix_cols; - - if(mxIsEmpty(dataref) ){ - /*Nothing to pick up. Just initialize matrix pointer to NULL: */ - outmatrix_rows=0; - outmatrix_cols=0; - outmatrix=NULL; - } - else if( mxIsClass(dataref,"double") || - mxIsClass(dataref,"single") || - mxIsClass(dataref,"int16") || - mxIsClass(dataref,"int8") || - mxIsClass(dataref,"uint8")){ - /*Check dataref is not pointing to NaN: */ - if ( mxIsNaN(*(mxGetPr(dataref))) && (mxGetM(dataref)==1) && (mxGetN(dataref)==1) ){ - outmatrix_rows=0; - outmatrix_cols=0; - outmatrix=NULL; - } - else{ - if(!mxIsClass(dataref,"double") && !mxIsClass(dataref,"single")){ - _printLine_("Warning: converting matlab data from '" << mxGetClassName(dataref) << "' to 'double'"); - } - /*Convert matlab matrix to double* matrix: */ - MatlabMatrixToDoubleMatrix(&outmatrix,&outmatrix_rows,&outmatrix_cols,dataref); - } - } - else{ - /*This is an error: we don't have the correct input!: */ - _error_("Input parameter of class " << mxGetClassName(dataref) << " not supported yet"); - } - - /*Assign output pointers:*/ - *pmatrix=outmatrix; - if (pM)*pM=outmatrix_rows; - if (pN)*pN=outmatrix_cols; - -} -/*}}}*/ -/*FUNCTION FetchData(double** pmatrix,int* pnumel,int* pndims,int** psize,const mxArray* dataref){{{*/ -void FetchData(double** pmatrix,int* pnumel,int* pndims,int** psize,const mxArray* dataref){ - - int outmatrix_numel,outmatrix_ndims; - double *outmatrix = NULL; - int *outmatrix_size = NULL; - - if(mxIsEmpty(dataref) ){ - /*Nothing to pick up. Just initialize matrix pointer to NULL: */ - outmatrix_numel = 0; - outmatrix_ndims = 0; - outmatrix_size = NULL; - outmatrix = NULL; - } - else if( mxIsClass(dataref,"double") || - mxIsClass(dataref,"single") || - mxIsClass(dataref,"int16") || - mxIsClass(dataref,"int8") || - mxIsClass(dataref,"uint8")){ - - /*Check dataref is not pointing to NaN: */ - if (mxIsNaN(*(mxGetPr(dataref))) && (mxGetNumberOfElements(dataref)==1)){ - outmatrix_numel = 0; - outmatrix_ndims = 0; - outmatrix_size = NULL; - outmatrix = NULL; - } - else{ - if(!mxIsClass(dataref,"double") && !mxIsClass(dataref,"single")){ - _printLine_("Warning: converting matlab data from '" << mxGetClassName(dataref) << "' to 'double'"); - } - /*Convert matlab n-dim array to double* matrix: */ - MatlabNArrayToNArray(&outmatrix,&outmatrix_numel,&outmatrix_ndims,&outmatrix_size,dataref); - } - } - else{ - /*This is an error: we don't have the correct input!: */ - _error_("Input parameter of class " << mxGetClassName(dataref) << " not supported yet"); - } - - /*Assign output pointers:*/ - *pmatrix=outmatrix; - if (pnumel)*pnumel=outmatrix_numel; - if (pndims)*pndims=outmatrix_ndims; - if (psize )*psize =outmatrix_size; - else xDelete(outmatrix_size); - -} -/*}}}*/ -/*FUNCTION FetchData(int** pmatrix,int* pM,int *pN,const mxArray* dataref){{{*/ -void FetchData(int** pmatrix,int* pM,int *pN,const mxArray* dataref){ - - int i,outmatrix_rows,outmatrix_cols; - double *doublematrix=NULL; - int *outmatrix=NULL; - - if(mxIsEmpty(dataref) ){ - /*Nothing to pick up. Just initialize matrix pointer to NULL: */ - outmatrix_rows=0; - outmatrix_cols=0; - outmatrix=NULL; - } - else if( mxIsClass(dataref,"double") || - mxIsClass(dataref,"single") || - mxIsClass(dataref,"int16") || - mxIsClass(dataref,"int8") || - mxIsClass(dataref,"uint8")){ - - /*Check dataref is not pointing to NaN: */ - if ( mxIsNaN(*(mxGetPr(dataref))) && (mxGetM(dataref)==1) && (mxGetN(dataref)==1) ){ - outmatrix_rows=0; - outmatrix_cols=0; - outmatrix=NULL; - } - else{ - if(!mxIsClass(dataref,"double") && !mxIsClass(dataref,"single")){ - _printLine_("Warning: converting matlab data from '" << mxGetClassName(dataref) << "' to 'double'"); - } - /*Convert matlab matrix to double* matrix: */ - MatlabMatrixToDoubleMatrix(&doublematrix,&outmatrix_rows,&outmatrix_cols,dataref); - - /*Convert double matrix into integer matrix: */ - outmatrix=xNew(outmatrix_rows*outmatrix_cols); - for(i=0;i(outmatrix_rows*outmatrix_cols); - for(i=0;i(outmatrix_numel); - for(i=0;i(doublematrix); - } - } - else{ - /*This is an error: we don't have the correct input!: */ - _error_("Input parameter of class " << mxGetClassName(dataref) << " not supported yet"); - } - - /*Assign output pointers:*/ - *pmatrix=outmatrix; - if (pnumel)*pnumel=outmatrix_numel; - if (pndims)*pndims=outmatrix_ndims; - if (psize )*psize =outmatrix_size; - else xDelete(outmatrix_size); - -} -/*}}}*/ -/*FUNCTION FetchData(double** pvector,int* pM,const mxArray* dataref){{{*/ -void FetchData(double** pvector,int* pM,const mxArray* dataref){ - - double* outvector=NULL; - int outvector_rows; - - if(mxIsEmpty(dataref)){ - /*Nothing to pick up. Just initialize matrix pointer to NULL: */ - outvector_rows=0; - outvector=NULL; - } - else if (mxIsClass(dataref,"double") ){ - - /*Convert matlab vector to double* vector: */ - MatlabVectorToDoubleVector(&outvector,&outvector_rows,dataref); - - } - else{ - /*This is an error: we don't have the correct input!: */ - _error_("Input parameter of class " << mxGetClassName(dataref) << " not supported yet"); - } - - /*Assign output pointers:*/ - *pvector=outvector; - if (pM)*pM=outvector_rows; -} -/*}}}*/ -/*FUNCTION FetchData(int** pvector,int* pM,const mxArray* dataref){{{*/ -void FetchData(int** pvector,int* pM,const mxArray* dataref){ - - int i; - double *doublevector = NULL; - int *outvector = NULL; - int outvector_rows; - - if(mxIsEmpty(dataref)){ - /*Nothing to pick up. Just initialize matrix pointer to NULL: */ - outvector_rows=0; - outvector=NULL; - } - else if (mxIsClass(dataref,"double") ){ - - /*Convert matlab vector to double* vector: */ - MatlabVectorToDoubleVector(&doublevector,&outvector_rows,dataref); - - /*Convert double vector into integer vector: */ - outvector=xNew(outvector_rows); - for(i=0;i(outvector_rows); - for(i=0;i(outvector_rows); - for(i=0;i(stringlen); - mxGetString(dataref,outstring,stringlen); - } - - /*Assign output pointers:*/ - *pstring=outstring; -}/*}}}*/ -/*FUNCTION FetchData(char** pmatrix,int* pnumel,int* pndims,int** psize,const mxArray* dataref){{{*/ -void FetchData(char** pmatrix,int* pnumel,int* pndims,int** psize,const mxArray* dataref){ - - int outmatrix_numel,outmatrix_ndims; - int* outmatrix_size=NULL; - char* outmatrix=NULL; - - if(mxIsEmpty(dataref) ){ - /*Nothing to pick up. Just initialize matrix pointer to NULL: */ - outmatrix_numel=0; - outmatrix_ndims=0; - outmatrix_size =NULL; - outmatrix=NULL; - } - else if (mxIsClass(dataref,"char") ){ - - /*Convert matlab n-dim array to char* matrix: */ - MatlabNArrayToNArray(&outmatrix,&outmatrix_numel,&outmatrix_ndims,&outmatrix_size,dataref); - } - else{ - /*This is an error: we don't have the correct input!: */ - _error_("Input parameter of class " << mxGetClassName(dataref) << " not supported yet"); - } - - /*Assign output pointers:*/ - *pmatrix=outmatrix; - if (pnumel)*pnumel=outmatrix_numel; - if (pndims)*pndims=outmatrix_ndims; - if (psize )*psize =outmatrix_size; - else xDelete(outmatrix_size); - -} -/*}}}*/ -/*FUNCTION FetchData(double* pscalar,const mxArray* dataref){{{*/ -void FetchData(double* pscalar,const mxArray* dataref){ - - double scalar; - - if (!mxIsClass(dataref,"double")){ - _error_("input data_type is not a double!"); - } - else{ - /*Recover the double: */ - scalar=mxGetScalar(dataref); - } - - /*Assign output pointers:*/ - *pscalar=scalar; -} -/*}}}*/ -/*FUNCTION FetchData(int* pinteger,const mxArray* dataref){{{*/ -void FetchData(int* pinteger,const mxArray* dataref){ - - int integer; - - if (!mxIsClass(dataref,"double")){ - _error_("input data_type is not a scalar!"); - } - else{ - /*Recover the double: */ - integer=(int)mxGetScalar(dataref); - } - - /*Assign output pointers:*/ - *pinteger=integer; -} -/*}}}*/ -/*FUNCTION FetchData(bool* pboolean,const mxArray* dataref){{{*/ -void FetchData(bool* pboolean,const mxArray* dataref){ - - bool* mxbool_ptr=NULL; - - if (mxIsClass(dataref,"logical")){ - if(mxGetM(dataref)!=1) _error_("input data is not of size 1x1"); - if(mxGetN(dataref)!=1) _error_("input data is not of size 1x1"); - mxbool_ptr=mxGetLogicals(dataref); - } - else{ - _error_("input data_type is not a bool!"); - } - - *pboolean=*mxbool_ptr; -} -/*}}}*/ - -/*ISSM objects*/ -/*FUNCTION FetchData(Matrix** pmatrix,const mxArray* dataref){{{*/ -void FetchData(Matrix** pmatrix,const mxArray* dataref){ - - Matrix* outmatrix=NULL; - int dummy=0; - - if (mxIsClass(dataref,"double") ){ - - /*Convert matlab matrix to matrix: */ - outmatrix=MatlabMatrixToMatrix(dataref); - - } - else{ - /*This is an error: we don't have the correct input!: */ - _error_("Input parameter of class " << mxGetClassName(dataref) << " not supported yet"); - } - - /*Assign output pointers:*/ - *pmatrix=outmatrix; -} -/*}}}*/ -/*FUNCTION FetchData(Vector** pvector,const mxArray* dataref){{{*/ -void FetchData(Vector** pvector,const mxArray* dataref){ - - Vector* vector=NULL; - int dummy; - - if(mxIsEmpty(dataref)){ - /*Nothing to pick up. Just initialize matrix pointer to NULL: */ - vector=new Vector(0); - } - else if (mxIsClass(dataref,"double") ){ - - /*Convert matlab vector to petsc vector: */ - vector=MatlabVectorToVector(dataref); - } - else{ - /*This is an error: we don't have the correct input!: */ - _error_("Input parameter of class " << mxGetClassName(dataref) << " not supported yet"); - } - - /*Assign output pointers:*/ - *pvector=vector; -} -/*}}}*/ -/*FUNCTION FetchData(BamgGeom** pbamggeom,const mxArray* dataref){{{*/ -void FetchData(BamgGeom** pbamggeom,const mxArray* dataref){ - - /*Initialize output*/ - BamgGeom* bamggeom=new BamgGeom(); - - /*Fetch all fields*/ - FetchData(&bamggeom->Vertices,&bamggeom->VerticesSize[0],&bamggeom->VerticesSize[1],mxGetAssignedField(dataref,0,"Vertices")); - FetchData(&bamggeom->Edges, &bamggeom->EdgesSize[0], &bamggeom->EdgesSize[1], mxGetAssignedField(dataref,0,"Edges")); - FetchData(&bamggeom->Corners, &bamggeom->CornersSize[0], &bamggeom->CornersSize[1], mxGetAssignedField(dataref,0,"Corners")); - FetchData(&bamggeom->RequiredVertices,&bamggeom->RequiredVerticesSize[0],&bamggeom->RequiredVerticesSize[1],mxGetAssignedField(dataref,0,"RequiredVertices")); - FetchData(&bamggeom->RequiredEdges, &bamggeom->RequiredEdgesSize[0], &bamggeom->RequiredEdgesSize[1], mxGetAssignedField(dataref,0,"RequiredEdges")); - FetchData(&bamggeom->CrackedEdges,&bamggeom->CrackedEdgesSize[0],&bamggeom->CrackedEdgesSize[1],mxGetAssignedField(dataref,0,"CrackedEdges")); - FetchData(&bamggeom->SubDomains,&bamggeom->SubDomainsSize[0],&bamggeom->SubDomainsSize[1],mxGetAssignedField(dataref,0,"SubDomains")); - - /*Assign output pointers:*/ - *pbamggeom=bamggeom; -} -/*}}}*/ -/*FUNCTION FetchData(BamgMesh** pbamgmesh,const mxArray* dataref){{{*/ -void FetchData(BamgMesh** pbamgmesh,const mxArray* dataref){ - - /*Initialize output*/ - BamgMesh* bamgmesh=new BamgMesh(); - - /*Fetch all fields*/ - FetchData(&bamgmesh->Vertices,&bamgmesh->VerticesSize[0],&bamgmesh->VerticesSize[1],mxGetAssignedField(dataref,0,"Vertices")); - FetchData(&bamgmesh->Edges, &bamgmesh->EdgesSize[0], &bamgmesh->EdgesSize[1], mxGetAssignedField(dataref,0,"Edges")); - FetchData(&bamgmesh->Triangles, &bamgmesh->TrianglesSize[0], &bamgmesh->TrianglesSize[1], mxGetAssignedField(dataref,0,"Triangles")); - FetchData(&bamgmesh->CrackedEdges,&bamgmesh->CrackedEdgesSize[0],&bamgmesh->CrackedEdgesSize[1],mxGetAssignedField(dataref,0,"CrackedEdges")); - FetchData(&bamgmesh->VerticesOnGeomEdge,&bamgmesh->VerticesOnGeomEdgeSize[0],&bamgmesh->VerticesOnGeomEdgeSize[1],mxGetAssignedField(dataref,0,"VerticesOnGeomEdge")); - FetchData(&bamgmesh->VerticesOnGeomVertex,&bamgmesh->VerticesOnGeomVertexSize[0],&bamgmesh->VerticesOnGeomVertexSize[1],mxGetAssignedField(dataref,0,"VerticesOnGeomVertex")); - FetchData(&bamgmesh->EdgesOnGeomEdge, &bamgmesh->EdgesOnGeomEdgeSize[0], &bamgmesh->EdgesOnGeomEdgeSize[1], mxGetAssignedField(dataref,0,"EdgesOnGeomEdge")); - FetchData(&bamgmesh->IssmSegments,&bamgmesh->IssmSegmentsSize[0],&bamgmesh->IssmSegmentsSize[1],mxGetAssignedField(dataref,0,"IssmSegments")); - - /*Assign output pointers:*/ - *pbamgmesh=bamgmesh; -} -/*}}}*/ -/*FUNCTION FetchData(BamgOpts** pbamgopts,const mxArray* dataref){{{*/ -void FetchData(BamgOpts** pbamgopts,const mxArray* dataref){ - - /*Initialize output*/ - BamgOpts* bamgopts=new BamgOpts(); - - /*Fetch all fields*/ - FetchData(&bamgopts->anisomax,mxGetField(dataref,0,"anisomax")); - FetchData(&bamgopts->cutoff,mxGetField(dataref,0,"cutoff")); - FetchData(&bamgopts->coeff,mxGetField(dataref,0,"coeff")); - FetchData(&bamgopts->errg,mxGetField(dataref,0,"errg")); - FetchData(&bamgopts->gradation,mxGetField(dataref,0,"gradation")); - FetchData(&bamgopts->Hessiantype,mxGetField(dataref,0,"Hessiantype")); - FetchData(&bamgopts->MaxCornerAngle,mxGetField(dataref,0,"MaxCornerAngle")); - FetchData(&bamgopts->maxnbv,mxGetField(dataref,0,"maxnbv")); - FetchData(&bamgopts->maxsubdiv,mxGetField(dataref,0,"maxsubdiv")); - FetchData(&bamgopts->Metrictype,mxGetField(dataref,0,"Metrictype")); - FetchData(&bamgopts->nbjacobi,mxGetField(dataref,0,"nbjacobi")); - FetchData(&bamgopts->nbsmooth,mxGetField(dataref,0,"nbsmooth")); - FetchData(&bamgopts->omega,mxGetField(dataref,0,"omega")); - FetchData(&bamgopts->power,mxGetField(dataref,0,"power")); - FetchData(&bamgopts->verbose,mxGetField(dataref,0,"verbose")); - - FetchData(&bamgopts->Crack,mxGetField(dataref,0,"Crack")); - FetchData(&bamgopts->geometricalmetric,mxGetField(dataref,0,"geometricalmetric")); - FetchData(&bamgopts->KeepVertices,mxGetField(dataref,0,"KeepVertices")); - FetchData(&bamgopts->splitcorners,mxGetField(dataref,0,"splitcorners")); - - FetchData(&bamgopts->hmin,mxGetField(dataref,0,"hmin")); - FetchData(&bamgopts->hmax,mxGetField(dataref,0,"hmax")); - FetchData(&bamgopts->hminVertices,&bamgopts->hminVerticesSize[0],&bamgopts->hminVerticesSize[1],mxGetField(dataref,0,"hminVertices")); - FetchData(&bamgopts->hmaxVertices,&bamgopts->hmaxVerticesSize[0],&bamgopts->hmaxVerticesSize[1],mxGetField(dataref,0,"hmaxVertices")); - FetchData(&bamgopts->hVertices,&bamgopts->hVerticesSize[0],&bamgopts->hVerticesSize[1],mxGetField(dataref,0,"hVertices")); - FetchData(&bamgopts->metric,&bamgopts->metricSize[0],&bamgopts->metricSize[1],mxGetField(dataref,0,"metric")); - FetchData(&bamgopts->field,&bamgopts->fieldSize[0],&bamgopts->fieldSize[1],mxGetField(dataref,0,"field")); - FetchData(&bamgopts->err,&bamgopts->errSize[0],&bamgopts->errSize[1],mxGetField(dataref,0,"err")); - - /*Additional checks*/ - bamgopts->Check(); - - /*Assign output pointers:*/ - *pbamgopts=bamgopts; -} -/*}}}*/ -/*FUNCTION FetchData(Options** poptions,const mxArray** pdataref){{{*/ -void FetchData(Options** poptions,int istart, int nrhs,const mxArray** pdataref){ - - char *name = NULL; - Option *option = NULL; - - /*Initialize output*/ - Options* options=new Options(); - - /*Fetch all options*/ - for (int i=istart; iAddOption(option); - option=NULL; - } - - /*Assign output pointers:*/ - *poptions=options; -} -/*}}}*/ -/*FUNCTION FetchData(DataSet** pcontours,const mxArray* dataref){{{*/ -void FetchData(DataSet** pcontours,const mxArray* dataref){ - - int numcontours,index,test1,test2; - char *contourname = NULL; - DataSet *contours = NULL; - Contour *contouri = NULL; - - if (mxIsClass(dataref,"char")){ - FetchData(&contourname,dataref); - contours=DomainOutlineRead(contourname); - } - else if(mxIsClass(dataref,"struct")){ - - contours=new DataSet(0); - numcontours=mxGetNumberOfElements(dataref); - - for(int i=0;i >(1); - - index = mxGetFieldNumber(dataref,"nods"); - if(index==-1) _error_("input structure does not have a 'nods' field"); - FetchData(&contouri->nods,mxGetFieldByNumber(dataref,i,index)); - - index = mxGetFieldNumber(dataref,"x"); - if(index==-1) _error_("input structure does not have a 'x' field"); - FetchData(&contouri->x,&test1,&test2,mxGetFieldByNumber(dataref,i,index)); - if(test1!=contouri->nods || test2!=1) _error_("field x should be of size ["<nods<<" 1]"); - - index = mxGetFieldNumber(dataref,"y"); - if(index==-1) _error_("input structure does not have a 'y' field"); - FetchData(&contouri->y,&test1,&test2,mxGetFieldByNumber(dataref,i,index)); - if(test1!=contouri->nods || test2!=1) _error_("field y should be of size ["<nods<<" 1]"); - - contours->AddObject(contouri); - } - } - else{ - _error_("Contour is neither a string nor a structure and cannot be loaded ("<(contourname); - *pcontours=contours; -} -/*}}}*/ Index: ../trunk-jpl/src/c/matlab/io/CheckNumMatlabArguments.cpp =================================================================== --- ../trunk-jpl/src/c/matlab/io/CheckNumMatlabArguments.cpp (revision 13748) +++ ../trunk-jpl/src/c/matlab/io/CheckNumMatlabArguments.cpp (revision 13749) @@ -1,30 +0,0 @@ -/*!\file CheckNumMatlabArguments.cpp: - * \brief: check number of arguments and report an usage error message. - */ - -#ifdef HAVE_CONFIG_H - #include -#else -#error "Cannot compile with HAVE_CONFIG_H symbol! run configure first!" -#endif - -#include "../../shared/Exceptions/exceptions.h" -#include "../../include/include.h" -#include "mex.h" - -int CheckNumMatlabArguments(int nlhs,int NLHS, int nrhs,int NRHS, const char* __FUNCT__, void (*function)( void )){ - - /*checks on arguments on the matlab side: */ - if (nrhs==0 && nlhs==0) { - /*unless NLHS=0 and NRHS=0, we are just asking for documentation: */ - if (NRHS==0 && NLHS==0)return 1; - /* special case: */ - function(); - _error_("usage: see above"); - } - else if (nlhs!=NLHS || nrhs!=NRHS ) { - function(); - _error_("usage error."); - } - return 1; -} Index: ../trunk-jpl/src/c/matlab/io/WriteMatlabData.cpp =================================================================== --- ../trunk-jpl/src/c/matlab/io/WriteMatlabData.cpp (revision 13748) +++ ../trunk-jpl/src/c/matlab/io/WriteMatlabData.cpp (revision 13749) @@ -1,390 +0,0 @@ -/* \file WriteData.c: - * \brief: general interface for writing data - */ - -#ifdef HAVE_CONFIG_H - #include -#else -#error "Cannot compile with HAVE_CONFIG_H symbol! run configure first!" -#endif - -#include -#include "../../include/include.h" -#include "../../shared/shared.h" -#include "./matlabio.h" - -/*Primitive data types*/ -/*FUNCTION WriteData(mxArray** pdataref,double* matrix, int M,int N){{{*/ -void WriteData(mxArray** pdataref,double* matrix, int M,int N){ - - mxArray *dataref = NULL; - double *tmatrix = NULL; - - if(matrix){ - /*create the matlab matrixwith Matlab's memory manager */ - tmatrix=(double*)mxMalloc(M*N*sizeof(double)); - for(int i=0;iVerticesSize[0], bamggeom->VerticesSize[1], bamggeom->Vertices); - i++; SetStructureField(dataref,"Edges", bamggeom->EdgesSize[0], bamggeom->EdgesSize[1], bamggeom->Edges); - i++; SetStructureField(dataref,"TangentAtEdges", bamggeom->TangentAtEdgesSize[0], bamggeom->TangentAtEdgesSize[1], bamggeom->TangentAtEdges); - i++; SetStructureField(dataref,"Corners", bamggeom->CornersSize[0], bamggeom->CornersSize[1], bamggeom->Corners); - i++; SetStructureField(dataref,"RequiredVertices",bamggeom->RequiredVerticesSize[0],bamggeom->RequiredVerticesSize[1],bamggeom->RequiredVertices); - i++; SetStructureField(dataref,"RequiredEdges", bamggeom->RequiredEdgesSize[0], bamggeom->RequiredEdgesSize[1], bamggeom->RequiredEdges); - i++; SetStructureField(dataref,"CrackedEdges", bamggeom->CrackedEdgesSize[0], bamggeom->CrackedEdgesSize[1], bamggeom->CrackedEdges); - i++; SetStructureField(dataref,"SubDomains", bamggeom->SubDomainsSize[0], bamggeom->SubDomainsSize[1], bamggeom->SubDomains); - _assert_(i==numfields); - - /*Assign output*/ - *pdataref=dataref; -} -/*}}}*/ -/*FUNCTION WriteData(mxArray** pdataref,BamgMesh* bamgmesh){{{*/ -void WriteData(mxArray** pdataref,BamgMesh* bamgmesh){ - - /*Intermediary*/ - int i; - mxArray *dataref = NULL; - const int numfields = 16; - const char *fnames[numfields]; - mwSize ndim = 2; - mwSize dimensions[2] = {1,1}; - - /*Initialize field names*/ - i=0; - fnames[i++] = "Vertices"; - fnames[i++] = "Edges"; - fnames[i++] = "Triangles"; - fnames[i++] = "Quadrilaterals"; - fnames[i++] = "IssmEdges"; - fnames[i++] = "IssmSegments"; - fnames[i++] = "VerticesOnGeomVertex"; - fnames[i++] = "VerticesOnGeomEdge"; - fnames[i++] = "EdgesOnGeomEdge"; - fnames[i++] = "SubDomains"; - fnames[i++] = "SubDomainsFromGeom"; - fnames[i++] = "ElementConnectivity"; - fnames[i++] = "NodalConnectivity"; - fnames[i++] = "NodalElementConnectivity"; - fnames[i++] = "CrackedVertices"; - fnames[i++] = "CrackedEdges"; - _assert_(i==numfields); - - /*Initialize Matlab structure*/ - dataref=mxCreateStructArray(ndim,dimensions,numfields,fnames); - - /*set each matlab each field*/ - i=0; - i++; SetStructureField(dataref,"Vertices",bamgmesh->VerticesSize[0], bamgmesh->VerticesSize[1],bamgmesh->Vertices); - i++; SetStructureField(dataref,"Edges", bamgmesh->EdgesSize[0],bamgmesh->EdgesSize[1], bamgmesh->Edges); - i++; SetStructureField(dataref,"Triangles", bamgmesh->TrianglesSize[0],bamgmesh->TrianglesSize[1], bamgmesh->Triangles); - i++; SetStructureField(dataref,"Quadrilaterals",bamgmesh->QuadrilateralsSize[0], bamgmesh->QuadrilateralsSize[1],bamgmesh->Quadrilaterals); - i++; SetStructureField(dataref,"IssmEdges", bamgmesh->IssmEdgesSize[0],bamgmesh->IssmEdgesSize[1], bamgmesh->IssmEdges); - i++; SetStructureField(dataref,"IssmSegments",bamgmesh->IssmSegmentsSize[0], bamgmesh->IssmSegmentsSize[1],bamgmesh->IssmSegments); - i++; SetStructureField(dataref,"VerticesOnGeomVertex",bamgmesh->VerticesOnGeomVertexSize[0],bamgmesh->VerticesOnGeomVertexSize[1], bamgmesh->VerticesOnGeomVertex); - i++; SetStructureField(dataref,"VerticesOnGeomEdge",bamgmesh->VerticesOnGeomEdgeSize[0],bamgmesh->VerticesOnGeomEdgeSize[1], bamgmesh->VerticesOnGeomEdge); - i++; SetStructureField(dataref,"EdgesOnGeomEdge", bamgmesh->EdgesOnGeomEdgeSize[0], bamgmesh->EdgesOnGeomEdgeSize[1],bamgmesh->EdgesOnGeomEdge); - i++; SetStructureField(dataref,"SubDomains",bamgmesh->SubDomainsSize[0], bamgmesh->SubDomainsSize[1],bamgmesh->SubDomains); - i++; SetStructureField(dataref,"SubDomainsFromGeom", bamgmesh->SubDomainsFromGeomSize[0], bamgmesh->SubDomainsFromGeomSize[1],bamgmesh->SubDomainsFromGeom); - i++; SetStructureField(dataref,"ElementConnectivity",bamgmesh->ElementConnectivitySize[0],bamgmesh->ElementConnectivitySize[1], bamgmesh->ElementConnectivity); - i++; SetStructureField(dataref,"NodalConnectivity",bamgmesh->NodalConnectivitySize[0],bamgmesh->NodalConnectivitySize[1], bamgmesh->NodalConnectivity); - i++; SetStructureField(dataref,"NodalElementConnectivity", bamgmesh->NodalElementConnectivitySize[0], bamgmesh->NodalElementConnectivitySize[1],bamgmesh->NodalElementConnectivity); - i++; SetStructureField(dataref,"CrackedVertices", bamgmesh->CrackedVerticesSize[0],bamgmesh->CrackedVerticesSize[1], bamgmesh->CrackedVertices); - i++; SetStructureField(dataref,"CrackedEdges",bamgmesh->CrackedEdgesSize[0], bamgmesh->CrackedEdgesSize[1],bamgmesh->CrackedEdges); - _assert_(i==numfields); - - /*Assign output*/ - *pdataref=dataref; -} -/*}}}*/ -/*FUNCTION WriteData(mxArray** pdataref,SeqMat* matrix){{{*/ -void WriteData(mxArray** pdataref,SeqMat* matrix){ - - int i,j; - int rows,cols; - mxArray *dataref = NULL; - double *matrix_ptr = NULL; - double *tmatrix_ptr = NULL; - - if(matrix){ - - matrix_ptr=matrix->ToSerial(); - matrix->GetSize(&rows,&cols); - - /*Now transpose the matrix and allocate with Matlab's memory manager: */ - tmatrix_ptr=(double*)mxMalloc(rows*cols*sizeof(double)); - for(i=0;i(matrix_ptr); - } - else{ - dataref = mxCreateDoubleMatrix(0,0,mxREAL); - } - - *pdataref=dataref; -} -/*}}}*/ -/*FUNCTION WriteData(mxArray** pdataref,SeqVec* vector){{{*/ -void WriteData(mxArray** pdataref,SeqVec* vector){ - - mxArray* dataref=NULL; - double* vector_ptr=NULL; - double* vector_matlab=NULL; - int rows; - - if(vector){ - /*call toolkit routine: */ - vector_ptr=vector->ToMPISerial(); - vector->GetSize(&rows); - - /*now create the matlab vector with Matlab's memory manager */ - vector_matlab=(double*)mxMalloc(rows*sizeof(double)); - for(int i=0;i(vector_ptr); - *pdataref=dataref; -} -/*}}}*/ -/*FUNCTION WriteData(mxArray** pdataref,RiftStruct* riftstruct){{{*/ -void WriteData(mxArray** pdataref,RiftStruct* riftstruct){ - - /*Intermediary*/ - int i; - mxArray *dataref = NULL; - const int numfields = 10; - const char *fnames[numfields]; - mwSize ndim = 2; - mwSize dimensions[2] = {1,1}; - - /*Initialize field names*/ - i=0; - fnames[i++] = "numsegs"; - fnames[i++] = "segments"; - fnames[i++] = "pairs"; - fnames[i++] = "tips"; - fnames[i++] = "penaltypairs"; - fnames[i++] = "fill"; - fnames[i++] = "friction"; - fnames[i++] = "fraction"; - fnames[i++] = "fractionincrement"; - fnames[i++] = "state"; - _assert_(i==numfields); - - /*Initialize matlab structure of dimension numrifts*/ - dimensions[0]=riftstruct->numrifts; - dataref=mxCreateStructArray(ndim,dimensions,numfields,fnames); - - /*set each matlab each field*/ - for(int i=0;inumrifts;i++){ - SetStructureFieldi(dataref,i,"numsegs" ,riftstruct->riftsnumsegments[i]); - SetStructureFieldi(dataref,i,"segments" ,riftstruct->riftsnumsegments[i] ,3,riftstruct->riftssegments[i]); - SetStructureFieldi(dataref,i,"pairs" ,riftstruct->riftsnumpairs[i] ,2,riftstruct->riftspairs[i]); - SetStructureFieldi(dataref,i,"tips" ,1 ,2,&riftstruct->riftstips[2*i]); - SetStructureFieldi(dataref,i,"penaltypairs" ,riftstruct->riftsnumpenaltypairs[i],7,riftstruct->riftspenaltypairs[i]); - SetStructureFieldi(dataref,i,"fill" ,IceEnum); - SetStructureFieldi(dataref,i,"friction" ,0); - SetStructureFieldi(dataref,i,"fraction" ,0.); - SetStructureFieldi(dataref,i,"fractionincrement",0.1); - SetStructureFieldi(dataref,i,"state" ,riftstruct->riftsnumpenaltypairs[i],1,riftstruct->state[i]); - } - - /*Assign output*/ - *pdataref=dataref; -} -/*}}}*/ - -/*Toolkit*/ -/*FUNCTION SetStructureField{{{*/ -void SetStructureField(mxArray* dataref,const char* fieldname,int M,int N,double* fieldpointer){ - - mxArray* field = NULL; - - /*Convert field*/ - WriteData(&field,fieldpointer,M,N); - - /*Assign to structure*/ - mxSetField(dataref,0,fieldname,field); -} -/*}}}*/ -/*FUNCTION SetStructureFieldi(mxArray* dataref,int i,const char* fieldname,int M,int N,double* fieldpointer){{{*/ -void SetStructureFieldi(mxArray* dataref,int i,const char* fieldname,int M,int N,double* fieldpointer){ - - mxArray* field = NULL; - - /*Convert field*/ - WriteData(&field,fieldpointer,M,N); - - /*Assign to structure*/ - mxSetField(dataref,i,fieldname,field); -} -/*}}}*/ -/*FUNCTION SetStructureFieldi(mxArray* dataref,int i,const char* fieldname,int field){{{*/ -void SetStructureFieldi(mxArray* dataref,int i,const char* fieldname,int fieldin){ - - mxArray* field = NULL; - - /*Convert field*/ - WriteData(&field,fieldin); - - /*Assign to structure*/ - mxSetField(dataref,i,fieldname,field); -} -/*}}}*/ -/*FUNCTION SetStructureFieldi(mxArray* dataref,int i,const char* fieldname,double field){{{*/ -void SetStructureFieldi(mxArray* dataref,int i,const char* fieldname,double fieldin){ - - mxArray* field = NULL; - - /*Convert field*/ - WriteData(&field,fieldin); - - /*Assign to structure*/ - mxSetField(dataref,i,fieldname,field); -} -/*}}}*/ Index: ../trunk-jpl/src/c/matlab/io/mxGetAssignedField.cpp =================================================================== --- ../trunk-jpl/src/c/matlab/io/mxGetAssignedField.cpp (revision 13748) +++ ../trunk-jpl/src/c/matlab/io/mxGetAssignedField.cpp (revision 13749) @@ -1,45 +0,0 @@ -/*!\file: mxGetAssignedField.c: - * \brief: abstract interface on parallel side for i/o, so it ressembles the serial i/o. - * - * In serial mode, this routine takes care of returning the field coming - * from the model. If largesize is 1, we are running out of core models in - * matlab, and we need to call the subsref private method from the model object - * in order to correctly load the data from disk. - */ - -#ifdef HAVE_CONFIG_H -#include -#else -#error "Cannot compile without HAVE_CONFIG_H symbol! run configure first!" -#endif - -#include "mex.h" - -mxArray* mxGetAssignedField(const mxArray* pmxa_array,int number,const char* field){ - - //output - mxArray* mxfield=NULL; - - //input - mxArray *inputs[2]; - mxArray *pindex = NULL; - const char *fnames[2]; - mwSize ndim = 2; - mwSize onebyone[2] = {1,1}; - - //We want to call the subsasgn method, and get the returned array.This ensures that if we are running - //large sized problems, the data is truly loaded from disk by the model subsasgn class method. - inputs[0]=(mxArray*)pmxa_array; //this is the model - - //create index structure used in the assignment (index.type='.' and index.subs='x' for field x for ex) - fnames[0] = "type"; - fnames[1] = "subs"; - pindex=mxCreateStructArray( ndim,onebyone,2,fnames); - mxSetField( pindex, 0, "type",mxCreateString(".")); - mxSetField( pindex, 0, "subs",mxCreateString(field)); - inputs[1]=pindex; - - mexCallMATLAB( 1, &mxfield, 2, (mxArray**)inputs, "subsref"); - - return mxfield; -} Index: ../trunk-jpl/src/c/matlab/io/MatlabMatrixToDoubleMatrix.cpp =================================================================== --- ../trunk-jpl/src/c/matlab/io/MatlabMatrixToDoubleMatrix.cpp (revision 13748) +++ ../trunk-jpl/src/c/matlab/io/MatlabMatrixToDoubleMatrix.cpp (revision 13749) @@ -1,130 +0,0 @@ -/* \file MatlabMatrixToDoubleMatrix.cpp - * \brief: convert a sparse or dense matlab matrix to a double* pointer - */ - -#ifdef HAVE_CONFIG_H - #include -#else -#error "Cannot compile with HAVE_CONFIG_H symbol! run configure first!" -#endif - -/*Matlab includes: */ -#include "mex.h" -#include "../../shared/shared.h" - -int MatlabMatrixToDoubleMatrix(double** pmatrix,int* pmatrix_rows,int* pmatrix_cols,const mxArray* mxmatrix){ - - int i,j,count,rows,cols; - - /*output: */ - double* matrix=NULL; - - /*matlab indices: */ - mwIndex* ir=NULL; - mwIndex* jc=NULL; - - /*Ok, first check if we are dealing with a sparse or full matrix: */ - if (mxIsSparse(mxmatrix)){ - - /*Dealing with sparse matrix: recover size first: */ - double* pmxmatrix=(double*)mxGetPr(mxmatrix); - rows=mxGetM(mxmatrix); - cols=mxGetN(mxmatrix); - - if(rows*cols){ - matrix=xNewZeroInit(rows*cols); - - /*Now, get ir,jc and pr: */ - ir=mxGetIr(mxmatrix); - jc=mxGetJc(mxmatrix); - - /*Now, start inserting data into double* matrix: */ - count=0; - for(i=0;i(rows*cols); - - for(i=0;i(rows*cols); - - for(i=0;i(rows*cols); - - for(i=0;i(rows*cols); - - for(i=0;i -#else -#error "Cannot compile with HAVE_CONFIG_H symbol! run configure first!" -#endif - -#include -#include -#include -#include "./matlabio.h" -#include "../../classes/classes.h" -#include "../../shared/shared.h" -#include "../../Container/Container.h" -#include "../../include/include.h" -#include "../../toolkits/toolkits.h" - -/*}}}*/ - -Vector* MatlabVectorToVector(const mxArray* mxvector){ - - int dummy; - Vector* vector=NULL; - - /*allocate vector object: */ - vector=new Vector(); - - #ifdef _HAVE_PETSC_ - vector->pvector=MatlabVectorToPetscVec(mxvector); - #else - vector->svector=MatlabVectorToSeqVec(mxvector); - #endif - - return vector; -} Index: ../trunk-jpl/src/c/matlab/io/MatlabMatrixToPetscMat.cpp =================================================================== --- ../trunk-jpl/src/c/matlab/io/MatlabMatrixToPetscMat.cpp (revision 13748) +++ ../trunk-jpl/src/c/matlab/io/MatlabMatrixToPetscMat.cpp (revision 13749) @@ -1,123 +0,0 @@ -/* \file MatlabMatrixToPetscMatrix.cpp - * \brief: convert a sparse or dense matlab matrix to a serial Petsc matrix: - */ - -#ifdef HAVE_CONFIG_H - #include -#else -#error "Cannot compile with HAVE_CONFIG_H symbol! run configure first!" -#endif -#include "../../shared/shared.h" - -/*Petsc includes: */ -#include "petscmat.h" -#include "petscvec.h" -#include "petscksp.h" - -/*Matlab includes: */ -#include "mex.h" -#include "matlabio.h" - -PetscMat* MatlabMatrixToPetscMat(const mxArray* mxmatrix){ - - int dummy; - PetscMat* matrix=new PetscMat(); - - MatlabMatrixToPetscMat(&matrix->matrix, &dummy, &dummy, mxmatrix); - - return matrix; -} -int MatlabMatrixToPetscMat(Mat* pmatrix,int* pmatrix_rows,int* pmatrix_cols,const mxArray* mxmatrix){ - - int rows, cols; - double *mxmatrix_ptr = NULL; - double *tmatrix = NULL; - int ierr; - int i,j; - - /*output: */ - Mat matrix = NULL; - - /*matlab indices: */ - mwIndex *ir = NULL; - mwIndex *jc = NULL; - double *pr = NULL; - int count; - int nnz; - int nz; - - /*petsc indices: */ - int *idxm = NULL; - int *idxn = NULL; - - /*Ok, first check if we are dealing with a sparse or full matrix: */ - if (mxIsSparse(mxmatrix)){ - - /*Dealing with sparse matrix: recover size first: */ - mxmatrix_ptr=(double*)mxGetPr(mxmatrix); - rows=mxGetM(mxmatrix); - cols=mxGetN(mxmatrix); - nnz=mxGetNzmax(mxmatrix); - if(rows){ - nz=(int)((double)nnz/(double)rows); - } - else{ - nz=0; - } - - ierr=MatCreateSeqAIJ(PETSC_COMM_SELF,rows,cols,nz,PETSC_NULL,&matrix);CHKERRQ(ierr); - - /*Now, get ir,jc and pr: */ - pr=mxGetPr(mxmatrix); - ir=mxGetIr(mxmatrix); - jc=mxGetJc(mxmatrix); - - /*Now, start inserting data into sparse matrix: */ - count=0; - for(i=0;i(rows*cols); - for(i=0;i(rows); - idxn=xNew(cols); - - for(i=0;i(tmatrix); - } - - /*Assemble matrix: */ - MatAssemblyBegin(matrix,MAT_FINAL_ASSEMBLY); - MatAssemblyEnd(matrix,MAT_FINAL_ASSEMBLY); - - /*Assign output pointer: */ - *pmatrix=matrix; - if(pmatrix_rows) *pmatrix_rows=rows; - if(pmatrix_cols) *pmatrix_cols=cols; - - return 1; -} Index: ../trunk-jpl/src/c/matlab/io/matlabio.h =================================================================== --- ../trunk-jpl/src/c/matlab/io/matlabio.h (revision 13748) +++ ../trunk-jpl/src/c/matlab/io/matlabio.h (revision 13749) @@ -1,93 +0,0 @@ -/*\file matlabio.h - *\brief: I/O for ISSM in matlab mode - */ - -#ifndef _MATLAB_IO_H_ -#define _MATLAB_IO_H_ - -#ifdef HAVE_CONFIG_H -#include -#else -#error "Cannot compile with HAVE_CONFIG_H symbol! run configure first!" -#endif - -#include -#include "../../classes/classes.h" -#include "../../Container/Container.h" -#include "../../include/include.h" - -void WriteData(mxArray** pdataref,SeqMat* matrix); -void WriteData(mxArray** pdataref,double* matrix, int M,int N); -void WriteData(mxArray** pdataref,int* matrix, int M,int N); -void WriteData(mxArray** pdataref,SeqVec* vector); -void WriteData(mxArray** pdataref,double* vector, int M); -void WriteData(mxArray** pdataref,int integer); -void WriteData(mxArray** pdataref,bool boolean); -void WriteData(mxArray** pdataref,double scalar); -void WriteData(mxArray** pdataref,char* string); -void WriteData(mxArray** pdataref); -void WriteData(mxArray** pdataref,BamgGeom* bamggeom); -void WriteData(mxArray** pdataref,BamgMesh* bamgmesh); -void WriteData(mxArray** pdataref,RiftStruct* riftstruct); - -void FetchData(double** pmatrix,int* pM,int *pN,const mxArray* dataref); -void FetchData(double** pmatrix,int* pnumel,int* pndims,int** psize,const mxArray* dataref); -void FetchData(int** pmatrix,int* pM,int *pN,const mxArray* dataref); -void FetchData(bool** pmatrix,int* pM,int *pN,const mxArray* dataref); -void FetchData(bool** pmatrix,int* pnumel,int* pndims,int** psize,const mxArray* dataref); -void FetchData(Matrix** pmatrix,const mxArray* dataref); -void FetchData(int** pvector,int* pM,const mxArray* dataref); -void FetchData(float** pvector,int* pM,const mxArray* dataref); -void FetchData(double** pvector,int* pM,const mxArray* dataref); -void FetchData(bool** pvector,int* pM,const mxArray* dataref); -void FetchData(Vector** pvector,const mxArray* dataref); -void FetchData(char** pstring,const mxArray* dataref); -void FetchData(char** pmatrix,int* pnumel,int* pndims,int** psize,const mxArray* dataref); -void FetchData(double* pscalar,const mxArray* dataref); -void FetchData(int* pinteger,const mxArray* dataref); -void FetchData(bool* pbool,const mxArray* dataref); -void FetchData(BamgGeom** bamggeom,const mxArray* dataref); -void FetchData(BamgMesh** bamgmesh,const mxArray* dataref); -void FetchData(BamgOpts** bamgopts,const mxArray* dataref); -void FetchData(Options** poptions,int istart, int nrhs,const mxArray** pdataref); -void FetchData(DataSet** pcontours,const mxArray* dataref); - -Option* OptionParse(char* name, const mxArray* prhs[]); -GenericOption* OptionDoubleParse( char* name, const mxArray* prhs[]); -GenericOption* OptionDoubleArrayParse( char* name, const mxArray* prhs[]); -GenericOption* OptionLogicalParse( char* name, const mxArray* prhs[]); -GenericOption* OptionCharParse( char* name, const mxArray* prhs[]); -GenericOption* OptionStructParse( char* name, const mxArray* prhs[]); -GenericOption* OptionCellParse( char* name, const mxArray* prhs[]); - -mxArray* mxGetAssignedField(const mxArray* pmxa_array,int number, const char* field); -void SetStructureField(mxArray* dataref,const char* fieldname,int fieldrows,int fieldcols,double* fieldpointer); -void SetStructureFieldi(mxArray* dataref,int i,const char* fieldname,int fieldrows,int fieldcols,double* fieldpointer); -void SetStructureFieldi(mxArray* dataref,int i,const char* fieldname,int field); -void SetStructureFieldi(mxArray* dataref,int i,const char* fieldname,double field); -int CheckNumMatlabArguments(int nlhs,int NLHS, int nrhs,int NRHS, const char* THISFUNCTION, void (*function)( void )); - -/*Matlab to Matrix routines: */ -Matrix* MatlabMatrixToMatrix(const mxArray* mxmatrix); -Vector* MatlabVectorToVector(const mxArray* mxvector); - -/*Matlab to double* routines: */ -int MatlabVectorToDoubleVector(double** pvector,int* pvector_rows,const mxArray* mxvector); -int MatlabMatrixToDoubleMatrix(double** pmatrix,int* pmatrix_rows,int* pmatrix_cols,const mxArray* mxmatrix); -int MatlabNArrayToNArray(double** pmatrix,int* pmatrix_numel,int* pmatrix_ndims,int** pmatrix_size,const mxArray* mxmatrix); -int MatlabNArrayToNArray(bool** pmatrix,int* pmatrix_numel,int* pmatrix_ndims,int** pmatrix_size,const mxArray* mxmatrix); -int MatlabNArrayToNArray(char** pmatrix,int* pmatrix_numel,int* pmatrix_ndims,int** pmatrix_size,const mxArray* mxmatrix); - -/*Matlab to SeqMat routines: */ -SeqMat* MatlabMatrixToSeqMat(const mxArray* dataref); -SeqVec* MatlabVectorToSeqVec(const mxArray* dataref); - -/*Matlab to Petsc routines: */ -#ifdef _HAVE_PETSC_ -int MatlabMatrixToPetscMat(Mat* matrix,int* prows,int* pcols, const mxArray* mxmatrix); -PetscMat* MatlabMatrixToPetscMat(const mxArray* mxmatrix); -int MatlabVectorToPetscVec(Vec* pvector,int* pvector_rows,const mxArray* mxvector); -PetscVec* MatlabVectorToPetscVec(const mxArray* mxvector); -#endif - -#endif /* _IO_H_ */ Index: ../trunk-jpl/src/c/matlab/io/MatlabVectorToSeqVec.cpp =================================================================== --- ../trunk-jpl/src/c/matlab/io/MatlabVectorToSeqVec.cpp (revision 13748) +++ ../trunk-jpl/src/c/matlab/io/MatlabVectorToSeqVec.cpp (revision 13749) @@ -1,29 +0,0 @@ -/*!\file MatlabVectorToSeqVec.cpp - */ - -/*Headers:*/ -/*{{{*/ -#ifdef HAVE_CONFIG_H - #include -#else -#error "Cannot compile with HAVE_CONFIG_H symbol! run configure first!" -#endif - -#include -#include -#include -#include "../../toolkits/toolkits.h" -#include "../../shared/shared.h" -#include "./matlabio.h" - -/*}}}*/ - -SeqVec* MatlabVectorToSeqVec(const mxArray* dataref){ - - SeqVec* output=NULL; - - output=new SeqVec(); - MatlabVectorToDoubleVector(&output->vector,&output->M,dataref); - return output; - -} Index: ../trunk-jpl/src/c/matlab/io/MatlabNArrayToNArray.cpp =================================================================== --- ../trunk-jpl/src/c/matlab/io/MatlabNArrayToNArray.cpp (revision 13748) +++ ../trunk-jpl/src/c/matlab/io/MatlabNArrayToNArray.cpp (revision 13749) @@ -1,251 +0,0 @@ -/* \file MatlabNArrayToNArray.cpp - * \brief: convert a sparse or dense matlab n-dimensional array to cpp n-dimensional array - */ - -#ifdef HAVE_CONFIG_H - #include -#else -#error "Cannot compile with HAVE_CONFIG_H symbol! run configure first!" -#endif - -#include "../../shared/shared.h" -#include "../../include/include.h" - -#include - -/*FUNCTION MatlabNArrayToNArray(double** pmatrix,int* pmatrix_numel,int* pmatrix_ndims,int** pmatrix_size,const mxArray* mxmatrix){{{*/ -int MatlabNArrayToNArray(double** pmatrix,int* pmatrix_numel,int* pmatrix_ndims,int** pmatrix_size,const mxArray* mxmatrix){ - - int i,j,rows,cols; - int numel,ndims; - int *size,*dims; - double* mxmatrix_ptr=NULL; - const mwSize* ipt=NULL; - - /*output: */ - double* matrix=NULL; - - /*matlab indices: */ - mwIndex *ir = NULL; - mwIndex *jc = NULL; - double *pr = NULL; - int count; - - /*get Matlab matrix information: */ - numel=mxGetNumberOfElements(mxmatrix); - ndims=mxGetNumberOfDimensions(mxmatrix); - ipt =mxGetDimensions(mxmatrix); - size =xNew(ndims); - for (i=0;i(rows*cols); - - /*Now, get ir,jc and pr: */ - ir = mxGetIr(mxmatrix); - jc = mxGetJc(mxmatrix); - pr = mxGetPr(mxmatrix); - - /*Now, start inserting data into double* matrix: */ - count=0; - for(i=0;i(numel); - - dims=xNew(ndims); - for(i=0;i(dims); - } - - /*Assign output pointer: */ - *pmatrix = matrix; - *pmatrix_numel = numel; - *pmatrix_ndims = ndims; - *pmatrix_size = size; - - return 1; -} -/*}}}*/ -/*FUNCTION MatlabNArrayToNArray(bool** pmatrix,int* pmatrix_numel,int* pmatrix_ndims,int** pmatrix_size,const mxArray* mxmatrix){{{*/ -int MatlabNArrayToNArray(bool** pmatrix,int* pmatrix_numel,int* pmatrix_ndims,int** pmatrix_size,const mxArray* mxmatrix){ - - int i,j,rows,cols; - int numel,ndims; - int *size,*dims; - bool* mxmatrix_ptr=NULL; - const mwSize* ipt=NULL; - - /*output: */ - bool* matrix=NULL; - - /*matlab indices: */ - mwIndex *ir = NULL; - mwIndex *jc = NULL; - bool *pm = NULL; - int count; - - /*get Matlab matrix information: */ - numel = mxGetNumberOfElements(mxmatrix); - ndims = mxGetNumberOfDimensions(mxmatrix); - ipt = mxGetDimensions(mxmatrix); - size = xNew(ndims); - for (i=0;i(rows*cols); - - /*Now, get ir,jc and pm: */ - ir=mxGetIr(mxmatrix); - jc=mxGetJc(mxmatrix); - pm=(bool*)mxGetData(mxmatrix); - - /*Now, start inserting data into bool* matrix: */ - count=0; - for(i=0;i(numel); - dims=xNew(ndims); - for(i=0;i(dims); - } - - /*Assign output pointer: */ - *pmatrix = matrix; - *pmatrix_numel = numel; - *pmatrix_ndims = ndims; - *pmatrix_size = size; - - return 1; -} -/*}}}*/ -/*FUNCTION MatlabNArrayToNArray(char** pmatrix,int* pmatrix_numel,int* pmatrix_ndims,int** pmatrix_size,const mxArray* mxmatrix){{{*/ -int MatlabNArrayToNArray(char** pmatrix,int* pmatrix_numel,int* pmatrix_ndims,int** pmatrix_size,const mxArray* mxmatrix){ - - int i,j,rows,cols; - int numel,ndims; - int *size , *dims; - mxChar *mxmatrix_ptr = NULL; - const mwSize *ipt = NULL; - - /*output: */ - char* matrix=NULL; - - /*matlab indices: */ - mwIndex *ir = NULL; - mwIndex *jc = NULL; - char *pm = NULL; - int count; - - /*get Matlab matrix information: */ - numel = mxGetNumberOfElements(mxmatrix); - ndims = mxGetNumberOfDimensions(mxmatrix); - ipt = mxGetDimensions(mxmatrix); - size = xNew(ndims); - for (i=0;i(rows*cols); - - /*Now, get ir,jc and pm: */ - ir = mxGetIr(mxmatrix); - jc = mxGetJc(mxmatrix); - pm = (char*)mxGetData(mxmatrix); - - /*Now, start inserting data into char* matrix: */ - count=0; - for(i=0;i(numel+1); - matrix[numel]='\0'; - - /*looping code adapted from Matlab example explore.c: */ - int elements_per_page = size[0] * size[1]; - /* total_number_of_pages = size[2] x size[3] x ... x size[N-1] */ - int total_number_of_pages = 1; - for (i=2; i -#else -#error "Cannot compile with HAVE_CONFIG_H symbol! run configure first!" -#endif - -#include -#include -#include -#include "./matlabio.h" -#include "../../classes/classes.h" -#include "../../shared/shared.h" -#include "../../Container/Container.h" -#include "../../include/include.h" -#include "../../toolkits/toolkits.h" - -/*}}}*/ - -Matrix* MatlabMatrixToMatrix(const mxArray* mxmatrix){ - - int dummy; - Matrix* matrix=NULL; - - /*allocate matrix object: */ - matrix=new Matrix(); - - #ifdef _HAVE_PETSC_ - matrix->pmatrix=MatlabMatrixToPetscMat(mxmatrix); - #else - matrix->smatrix=MatlabMatrixToSeqMat(mxmatrix); - #endif - - return matrix; -} Index: ../trunk-jpl/src/c/toolkits/python/pythonincludes.h =================================================================== --- ../trunk-jpl/src/c/toolkits/python/pythonincludes.h (revision 13748) +++ ../trunk-jpl/src/c/toolkits/python/pythonincludes.h (revision 13749) @@ -1,24 +0,0 @@ -/* \file pythonincludes.h - * \brief all includes for PYTHON layer - */ - -#ifndef _PYTHON_INCLUDES_H_ -#define _PYTHON_INCLUDES_H_ - -#ifdef HAVE_CONFIG_H - #include -#else -#error "Cannot compile with HAVE_CONFIG_H symbol! run configure first!" -#endif - -#if _PYTHON_MAJOR_ == 2 -#undef NPY_NO_DEPRECATED_API -#define NPY_NO_DEPRECATED_API NPY_1_7_API_VERSION -#else -#define NPY_NO_DEPRECATED_API -#endif - -#include "Python.h" -#include "arrayobject.h" - -#endif Index: ../trunk-jpl/src/c/toolkits/toolkits.h =================================================================== --- ../trunk-jpl/src/c/toolkits/toolkits.h (revision 13748) +++ ../trunk-jpl/src/c/toolkits/toolkits.h (revision 13749) @@ -11,10 +11,6 @@ #error "Cannot compile with HAVE_CONFIG_H symbol! run configure first!" #endif -#ifdef _HAVE_PYTHON_ -#include "./python/pythonincludes.h" -#endif - #ifdef _HAVE_PETSC_ #include "./petsc/petscincludes.h" #endif @@ -30,5 +26,4 @@ #include "./triangle/triangleincludes.h" #include "./toolkitsenums.h" #include "./issm/issmtoolkit.h" - #endif Index: ../trunk-jpl/src/c/Makefile.am =================================================================== --- ../trunk-jpl/src/c/Makefile.am (revision 13748) +++ ../trunk-jpl/src/c/Makefile.am (revision 13749) @@ -1,4 +1,4 @@ -AM_CPPFLAGS = @DAKOTAINCL@ @SHAPELIBINCL@ @PETSCINCL@ @SLEPCINCL@ @MPIINCL@ @MATLABINCL@ @METISINCL@ @CHACOINCL@ @SCOTCHINCL@ @PLAPACKINCL@ @BLASLAPACKINCL@ @MKLINCL@ @MUMPSINCL@ @TRIANGLEINCL@ @SPAIINCL@ @HYPREINCL@ @PROMETHEUSINCL@ @SUPERLUINCL@ @SPOOLESINCL@ @PASTIXINCL@ @MLINCL@ @TAOINCL@ @ADIC2INCL@ @ADOLCINCL@ @GSLINCL@ @BOOSTINCL@ @PYTHONINCL@ @PYTHON_NUMPYINCL@ +AM_CPPFLAGS = @DAKOTAINCL@ @SHAPELIBINCL@ @PETSCINCL@ @SLEPCINCL@ @MPIINCL@ @METISINCL@ @CHACOINCL@ @SCOTCHINCL@ @PLAPACKINCL@ @BLASLAPACKINCL@ @MKLINCL@ @MUMPSINCL@ @TRIANGLEINCL@ @SPAIINCL@ @HYPREINCL@ @PROMETHEUSINCL@ @SUPERLUINCL@ @SPOOLESINCL@ @PASTIXINCL@ @MLINCL@ @TAOINCL@ @ADIC2INCL@ @ADOLCINCL@ @GSLINCL@ @BOOSTINCL@ EXEEXT=$(ISSMEXT) @@ -8,15 +8,6 @@ if SHAREDLIBS lib_LTLIBRARIES = libISSMCore.la libISSMOverload.la libISSM.la endif -if PYTHON -lib_LIBRARIES += libISSMPython.a -endif -if MATLAB -if SHAREDLIBS -lib_LTLIBRARIES += libISSMMatlab.la -endif -lib_LIBRARIES += libISSMMatlab.a -endif if WRAPPERS if SHAREDLIBS lib_LTLIBRARIES += libISSMWrappers.la @@ -763,36 +754,6 @@ metis_sources= ./toolkits/metis/patches/metispatches.h\ ./toolkits/metis/patches/METIS_PartMeshNodalPatch.cpp #}}} -#Python sources {{{ -python_sources= ./python/io/pythonio.h\ - ./python/python-binding.h\ - ./python/io/WritePythonData.cpp\ - ./python/io/CheckNumPythonArguments.cpp\ - ./python/io/FetchPythonData.cpp - -#}}} -#Matlab sources {{{ -matlab_sources= ./toolkits/matlab/matlabincludes.h\ - ./matlab/matlab-binding.h\ - ./matlab/io/matlabio.h\ - ./matlab/io/MatlabNArrayToNArray.cpp\ - ./matlab/io/CheckNumMatlabArguments.cpp\ - ./matlab/io/mxGetAssignedField.cpp\ - ./matlab/io/WriteMatlabData.cpp\ - ./matlab/io/FetchMatlabData.cpp\ - ./matlab/io/OptionParse.cpp\ - ./matlab/io/MatlabMatrixToMatrix.cpp\ - ./matlab/io/MatlabVectorToVector.cpp\ - ./matlab/io/MatlabVectorToDoubleVector.cpp\ - ./matlab/io/MatlabMatrixToDoubleMatrix.cpp\ - ./matlab/io/MatlabMatrixToSeqMat.cpp\ - ./matlab/io/MatlabVectorToSeqVec.cpp -#}}} -#Matlab and Petsc sources {{{ -matlabpetsc_sources= ./matlab/io/MatlabMatrixToPetscMat.cpp\ - ./matlab/io/MatlabVectorToPetscVec.cpp - -#}}} #Wrappers sources{{{ wrapper_sources= ./shared/Threads/issm_threads.h\ ./shared/Threads/LaunchThread.cpp\ @@ -944,12 +905,6 @@ issm_sources += $(metis_sources) endif -if PETSC -if MATLAB -issm_sources += $(matlabpetsc_sources) -endif -endif - if KRIGING issm_sources += $(pkriging_sources) endif @@ -986,19 +941,6 @@ endif endif -if PYTHON -libISSMPython_a_SOURCES = $(python_sources) -libISSMPython_a_CXXFLAGS= $(ALLCXXFLAGS) -endif - -if MATLAB -libISSMMatlab_a_SOURCES = $(matlab_sources) -libISSMMatlab_a_CXXFLAGS= $(ALLCXXFLAGS) -if SHAREDLIBS -libISSMMatlab_la_SOURCES = $(libISSMMatlab_a_SOURCES) -endif -endif - if VERSION AM_LDFLAGS = else Index: ../trunk-jpl/src/wrappers/python/include/wrapper_macros.h =================================================================== --- ../trunk-jpl/src/wrappers/python/include/wrapper_macros.h (revision 0) +++ ../trunk-jpl/src/wrappers/python/include/wrapper_macros.h (revision 13749) @@ -0,0 +1,92 @@ +/* \file python_macros.h + * \brief: macros used for the python bindings + */ + +#ifndef _PY_WRAPPER_MACROS_H_ +#define _PY_WRAPPER_MACROS_H_ + +#ifdef HAVE_CONFIG_H + #include +#else +#error "Cannot compile with HAVE_CONFIG_H symbol! run configure first!" +#endif + +#ifdef _HAVE_PYTHON_ +/* MODULEBOOT/MODULEEND {{{*/ + +/*The following macros hide the error exception handling in a matlab module. Just put + * MODULEBOOT(); and MODULEEND(); at the beginning and end of a module, and c++ exceptions + * will be trapped*/ +#define MODULEBOOT(); \ + PyObject *output = PyTuple_New(NLHS); \ + int nrhs = (int)PyTuple_Size(args); \ + if(!output) return NULL;\ + try{ \ + IssmComm::SetComm(-1); + +#define MODULEEND(); }\ + catch(ErrorException &exception){\ + PyErr_SetString(PyExc_TypeError,exception.PythonReport()); \ + return NULL;\ + } \ + catch (exception &e){\ + PyErr_SetString(PyExc_TypeError,exprintf("Standard exception: %s\n",e.what()));\ + return NULL;\ + }\ + catch(...){\ + PyErr_SetString(PyExc_TypeError,"An unexpected error occurred");\ + return NULL;\ + }\ + return output; +//}}} +#if _PYTHON_MAJOR_ >=3 +/* WRAPPER 3.2 {{{*/ +#define WRAPPER(modulename,...) \ +\ +static PyObject* modulename(PyObject* self,PyObject* args);\ +static PyMethodDef modulename##_funcs[] = {\ + {#modulename, (PyCFunction)modulename, METH_VARARGS, ""},\ + {NULL,NULL,0,NULL}\ +};\ +\ +static struct PyModuleDef modulename##module= {\ + PyModuleDef_HEAD_INIT,\ + #modulename, /* name of module */\ + NULL, /* module documentation, may be NULL */\ + -1, /* size of per-interpreter state of the module,\ + or -1 if the module keeps state in global variables. */\ + modulename##_funcs\ +};\ +\ +PyMODINIT_FUNC PyInit_##modulename(void){\ +\ + import_array();\ + return PyModule_Create(&modulename##module);\ +}\ +\ +static PyObject* modulename(PyObject* self,PyObject* args) +/*}}}*/ +#else +/* WRAPPER 2.7 {{{*/ +#define WRAPPER(modulename,...) \ +\ +static PyObject* modulename(PyObject* self,PyObject* args);\ +static PyMethodDef modulename##_funcs[] = {\ + {#modulename, (PyCFunction)modulename, METH_VARARGS, ""},\ + {NULL,NULL,0,NULL}\ +};\ +\ +PyMODINIT_FUNC init##modulename(void){\ +\ + import_array();\ + (void) Py_InitModule(#modulename, modulename##_funcs);\ +}\ +\ +static PyObject* modulename(PyObject* self,PyObject* args) +/*}}}*/ +#endif +/* CHECKARGUMENTS {{{*/ +#define CHECKARGUMENTS(NLHS,NRHS,functionpointer) CheckNumPythonArguments(args, NRHS,functionpointer) +/*}}}*/ +#endif +#endif Index: ../trunk-jpl/src/wrappers/python/io/pythonio.h =================================================================== --- ../trunk-jpl/src/wrappers/python/io/pythonio.h (revision 0) +++ ../trunk-jpl/src/wrappers/python/io/pythonio.h (revision 13749) @@ -0,0 +1,48 @@ +/*\file pythonio.h + *\brief: I/O for ISSM in python mode + */ + +#ifndef _PYTHON_IO_H_ +#define _PYTHON_IO_H_ + +#ifdef HAVE_CONFIG_H +#include +#else +#error "Cannot compile with HAVE_CONFIG_H symbol! run configure first!" +#endif + +#include "../include/pythonincludes.h" +#include "../../c/classes/classes.h" +#include "../../c/Container/Container.h" +#include "../../c/include/include.h" + +void WriteData(PyObject* py_tuple,int index, double* matrix, int M,int N); +void WriteData(PyObject* py_tuple,int index, int integer); +void WriteData(PyObject* py_tuple,int index, char* string); +void WriteData(PyObject* py_tuple,int index); +void WriteData(PyObject* py_tuple,int index, SeqMat* matrix); +void WriteData(PyObject* py_tuple,int index, SeqVec* vector); +void WriteData(PyObject* py_tuple,int index, BamgGeom* bamggeom); +void WriteData(PyObject* py_tuple,int index, BamgMesh* bamgmesh); +void WriteData(PyObject* py_tuple,int index, RiftStruct* riftstruct); + +void FetchData(double** pvector,int* pM,PyObject* py_ref); +void FetchData(double** pmatrix,int* pM,int *pN,PyObject* py_array); +void FetchData(int** pmatrix,int* pM,int *pN,PyObject* py_matrix); +void FetchData(char** pstring,PyObject* py_unicode); +void FetchData(double* pscalar,PyObject* py_float); +void FetchData(int* pinteger,PyObject* py_long); +void FetchData(bool* pbool,PyObject* py_boolean); +void FetchData(BamgGeom** bamggeom,PyObject* py_dict); +void FetchData(BamgMesh** bamgmesh,PyObject* py_dict); +void FetchData(BamgOpts** bamgopts,PyObject* py_dict); +void FetchData(Options** poptions,int istart, int nrhs,PyObject* py_tuple); +void FetchData(DataSet** pcontours,PyObject* py_list); + +int CheckNumPythonArguments(PyObject* inputs,int NRHS, void (*function)( void )); + +/*Utils*/ +PyObject* PyArrayFromCopiedData(int dims[2],double* data); +PyObject* PyArrayFromCopiedData(int dimi,int dimj,double* data); + +#endif /* _IO_H_ */ Index: ../trunk-jpl/src/wrappers/python/io/CheckNumPythonArguments.cpp =================================================================== --- ../trunk-jpl/src/wrappers/python/io/CheckNumPythonArguments.cpp (revision 0) +++ ../trunk-jpl/src/wrappers/python/io/CheckNumPythonArguments.cpp (revision 13749) @@ -0,0 +1,29 @@ +/*!\file CheckNumPythonArguments.cpp: + * \brief: check number of arguments and report an usage error message. + */ + +#define PY_ARRAY_UNIQUE_SYMBOL PythonIOSymbol +#define NO_IMPORT + +#include "./pythonio.h" +#include "../../c/shared/Exceptions/exceptions.h" +#include "../../c/include/include.h" + +int CheckNumPythonArguments(PyObject* inputs,int NRHS, void (*function)( void )){ + + Py_ssize_t size=0; + + /*figure out size of tuple in input: */ + size=PyTuple_Size(inputs); + + /*check on requested size: */ + if (size==0){ + function(); + _error_("usage: see above"); + } + else if (size!=NRHS ) { + function(); + _error_("usage error."); + } + return 1; +} Index: ../trunk-jpl/src/wrappers/python/io/FetchPythonData.cpp =================================================================== --- ../trunk-jpl/src/wrappers/python/io/FetchPythonData.cpp (revision 0) +++ ../trunk-jpl/src/wrappers/python/io/FetchPythonData.cpp (revision 13749) @@ -0,0 +1,354 @@ +/*\file FetchData.cpp: + * \brief: general I/O interface to fetch data in python + */ + +#ifdef HAVE_CONFIG_H + #include +#else +#error "Cannot compile with HAVE_CONFIG_H symbol! run configure first!" +#endif + +#define PY_ARRAY_UNIQUE_SYMBOL PythonIOSymbol +#define NO_IMPORT + +#include "./pythonio.h" +#include "../../c/include/include.h" +#include "../../c/shared/shared.h" + +/*Primitive data types*/ +/*FUNCTION FetchData(double* pscalar,PyObject* py_float){{{*/ +void FetchData(double* pscalar,PyObject* py_float){ + + double scalar; + + /*return internal value: */ + scalar=PyFloat_AsDouble(py_float); + + /*output: */ + *pscalar=scalar; +} +/*}}}*/ +/*FUNCTION FetchData(int* pinteger,PyObject* py_long){{{*/ +void FetchData(int* pinteger, PyObject* py_long){ + + int integer; + + /*return internal value: */ + integer=(int)PyLong_AsLong(py_long); + + /*output: */ + *pinteger=integer; +} +/*}}}*/ +/*FUNCTION FetchData(bool* pboolean,PyObject* py_boolean){{{*/ +void FetchData(bool* pboolean,PyObject* py_boolean){ + + bool boolean; + + /*check this is indeed a subtype of long type: */ + if(!PyBool_Check(py_boolean))_error_("expecting a boolean in input!"); + + /*extract boolean: */ + boolean=(bool)PyLong_AsLong(py_boolean); + + /*simple copy: */ + *pboolean=boolean; + +} +/*}}}*/ +/*FUNCTION FetchData(double** pmatrix,int* pM, int* pN, PyObject* py_matrix){{{*/ +void FetchData(double** pmatrix,int* pM,int *pN,PyObject* py_matrix){ + + /*output: */ + double* dmatrix=NULL; + double* matrix=NULL; + int M,N; + int ndim; + npy_intp* dims=NULL; + + /*retrive dimensions: */ + ndim=PyArray_NDIM((const PyArrayObject*)py_matrix); + if(ndim!=2)_error_("expecting an MxN matrix in input!"); + dims=PyArray_DIMS((PyArrayObject*)py_matrix); + M=dims[0]; N=dims[1]; + + if (M && N) { + /*retrieve internal value: */ + dmatrix=(double*)PyArray_DATA((PyArrayObject*)py_matrix); + + /*copy matrix: */ + matrix=xNew(M*N); + memcpy(matrix,dmatrix,(M*N)*sizeof(double)); + } + else + matrix=NULL; + + /*output: */ + if(pM)*pM=M; + if(pN)*pN=N; + if(pmatrix)*pmatrix=matrix; +} +/*}}}*/ +/*FUNCTION FetchData(int** pmatrix,int* pM, int* pN, PyObject* py_matrix){{{*/ +void FetchData(int** pmatrix,int* pM,int *pN,PyObject* py_matrix){ + + /*output: */ + double* dmatrix=NULL; + int* matrix=NULL; + int M,N; + + /*intermediary:*/ + int i; + int ndim; + npy_intp* dims=NULL; + + /*retrive dimensions: */ + ndim=PyArray_NDIM((const PyArrayObject*)py_matrix); + if(ndim!=2)_error_("expecting an MxN matrix in input!"); + dims=PyArray_DIMS((PyArrayObject*)py_matrix); + M=dims[0]; N=dims[1]; + + if (M && N) { + /*retrieve internal value: */ + dmatrix=(double*)PyArray_DATA((PyArrayObject*)py_matrix); + + /*transform into integer matrix: */ + matrix=xNew(M*N); + for(i=0;i(M); + memcpy(vector,dvector,(M)*sizeof(double)); + } + else + vector=NULL; + + /*output: */ + if(pM)*pM=M; + if(pvector)*pvector=vector; +} +/*}}}*/ + +/*ISSM objects*/ +/*FUNCTION FetchData(BamgGeom** pbamggeom,PyObject* py_dict){{{*/ +void FetchData(BamgGeom** pbamggeom,PyObject* py_dict){ + + /*Initialize output*/ + BamgGeom* bamggeom=new BamgGeom(); + + /*Fetch all fields*/ + FetchData(&bamggeom->Vertices,&bamggeom->VerticesSize[0],&bamggeom->VerticesSize[1],PyDict_GetItemString(py_dict,"Vertices")); + FetchData(&bamggeom->Edges, &bamggeom->EdgesSize[0], &bamggeom->EdgesSize[1], PyDict_GetItemString(py_dict,"Edges")); + FetchData(&bamggeom->Corners, &bamggeom->CornersSize[0], &bamggeom->CornersSize[1], PyDict_GetItemString(py_dict,"Corners")); + FetchData(&bamggeom->RequiredVertices,&bamggeom->RequiredVerticesSize[0],&bamggeom->RequiredVerticesSize[1],PyDict_GetItemString(py_dict,"RequiredVertices")); + FetchData(&bamggeom->RequiredEdges, &bamggeom->RequiredEdgesSize[0], &bamggeom->RequiredEdgesSize[1], PyDict_GetItemString(py_dict,"RequiredEdges")); + FetchData(&bamggeom->CrackedEdges,&bamggeom->CrackedEdgesSize[0],&bamggeom->CrackedEdgesSize[1],PyDict_GetItemString(py_dict,"CrackedEdges")); + FetchData(&bamggeom->SubDomains,&bamggeom->SubDomainsSize[0],&bamggeom->SubDomainsSize[1],PyDict_GetItemString(py_dict,"SubDomains")); + + /*Assign output pointers:*/ + *pbamggeom=bamggeom; +} +/*}}}*/ +/*FUNCTION FetchData(BamgMesh** pbamgmesh,PyObject* py_dict){{{*/ +void FetchData(BamgMesh** pbamgmesh,PyObject* py_dict){ + + /*Initialize output*/ + BamgMesh* bamgmesh=new BamgMesh(); + + /*Fetch all fields*/ + FetchData(&bamgmesh->Vertices,&bamgmesh->VerticesSize[0],&bamgmesh->VerticesSize[1],PyDict_GetItemString(py_dict,"Vertices")); + FetchData(&bamgmesh->Edges, &bamgmesh->EdgesSize[0], &bamgmesh->EdgesSize[1], PyDict_GetItemString(py_dict,"Edges")); + FetchData(&bamgmesh->Triangles, &bamgmesh->TrianglesSize[0], &bamgmesh->TrianglesSize[1], PyDict_GetItemString(py_dict,"Triangles")); + FetchData(&bamgmesh->CrackedEdges,&bamgmesh->CrackedEdgesSize[0],&bamgmesh->CrackedEdgesSize[1],PyDict_GetItemString(py_dict,"CrackedEdges")); + FetchData(&bamgmesh->VerticesOnGeomEdge,&bamgmesh->VerticesOnGeomEdgeSize[0],&bamgmesh->VerticesOnGeomEdgeSize[1],PyDict_GetItemString(py_dict,"VerticesOnGeomEdge")); + FetchData(&bamgmesh->VerticesOnGeomVertex,&bamgmesh->VerticesOnGeomVertexSize[0],&bamgmesh->VerticesOnGeomVertexSize[1],PyDict_GetItemString(py_dict,"VerticesOnGeomVertex")); + FetchData(&bamgmesh->EdgesOnGeomEdge, &bamgmesh->EdgesOnGeomEdgeSize[0], &bamgmesh->EdgesOnGeomEdgeSize[1], PyDict_GetItemString(py_dict,"EdgesOnGeomEdge")); + FetchData(&bamgmesh->IssmSegments,&bamgmesh->IssmSegmentsSize[0],&bamgmesh->IssmSegmentsSize[1],PyDict_GetItemString(py_dict,"IssmSegments")); + + /*Assign output pointers:*/ + *pbamgmesh=bamgmesh; +} +/*}}}*/ +/*FUNCTION FetchData(BamgOpts** pbamgopts,PyObject* py_dict){{{*/ +void FetchData(BamgOpts** pbamgopts,PyObject* py_dict){ + + /*Initialize output*/ + BamgOpts* bamgopts=new BamgOpts(); + + /*Fetch all fields*/ + FetchData(&bamgopts->anisomax,PyDict_GetItemString(py_dict,"anisomax")); + FetchData(&bamgopts->cutoff,PyDict_GetItemString(py_dict,"cutoff")); + FetchData(&bamgopts->coeff,PyDict_GetItemString(py_dict,"coeff")); + FetchData(&bamgopts->errg,PyDict_GetItemString(py_dict,"errg")); + FetchData(&bamgopts->gradation,PyDict_GetItemString(py_dict,"gradation")); + FetchData(&bamgopts->Hessiantype,PyDict_GetItemString(py_dict,"Hessiantype")); + FetchData(&bamgopts->MaxCornerAngle,PyDict_GetItemString(py_dict,"MaxCornerAngle")); + FetchData(&bamgopts->maxnbv,PyDict_GetItemString(py_dict,"maxnbv")); + FetchData(&bamgopts->maxsubdiv,PyDict_GetItemString(py_dict,"maxsubdiv")); + FetchData(&bamgopts->Metrictype,PyDict_GetItemString(py_dict,"Metrictype")); + FetchData(&bamgopts->nbjacobi,PyDict_GetItemString(py_dict,"nbjacobi")); + FetchData(&bamgopts->nbsmooth,PyDict_GetItemString(py_dict,"nbsmooth")); + FetchData(&bamgopts->omega,PyDict_GetItemString(py_dict,"omega")); + FetchData(&bamgopts->power,PyDict_GetItemString(py_dict,"power")); + FetchData(&bamgopts->verbose,PyDict_GetItemString(py_dict,"verbose")); + + FetchData(&bamgopts->Crack,PyDict_GetItemString(py_dict,"Crack")); + FetchData(&bamgopts->geometricalmetric,PyDict_GetItemString(py_dict,"geometricalmetric")); + FetchData(&bamgopts->KeepVertices,PyDict_GetItemString(py_dict,"KeepVertices")); + FetchData(&bamgopts->splitcorners,PyDict_GetItemString(py_dict,"splitcorners")); + + FetchData(&bamgopts->hmin,PyDict_GetItemString(py_dict,"hmin")); + FetchData(&bamgopts->hmax,PyDict_GetItemString(py_dict,"hmax")); + FetchData(&bamgopts->hminVertices,&bamgopts->hminVerticesSize[0],&bamgopts->hminVerticesSize[1],PyDict_GetItemString(py_dict,"hminVertices")); + FetchData(&bamgopts->hmaxVertices,&bamgopts->hmaxVerticesSize[0],&bamgopts->hmaxVerticesSize[1],PyDict_GetItemString(py_dict,"hmaxVertices")); + FetchData(&bamgopts->hVertices,&bamgopts->hVerticesSize[0],&bamgopts->hVerticesSize[1],PyDict_GetItemString(py_dict,"hVertices")); + FetchData(&bamgopts->metric,&bamgopts->metricSize[0],&bamgopts->metricSize[1],PyDict_GetItemString(py_dict,"metric")); + FetchData(&bamgopts->field,&bamgopts->fieldSize[0],&bamgopts->fieldSize[1],PyDict_GetItemString(py_dict,"field")); + FetchData(&bamgopts->err,&bamgopts->errSize[0],&bamgopts->errSize[1],PyDict_GetItemString(py_dict,"err")); + + /*Additional checks*/ + bamgopts->Check(); + + /*Assign output pointers:*/ + *pbamgopts=bamgopts; +} +/*}}}*/ +/*FUNCTION FetchData(Options** poptions,int istart, int nrhs,PyObject* py_tuple){{{*/ +void FetchData(Options** poptions,int istart, int nrhs,PyObject* py_tuple){ + + char *name = NULL; + Option *option = NULL; + + /*Initialize output*/ + Options* options=new Options(); + + /*Fetch all options*/ + for (int i=istart; iAddOption(option); +// option=NULL; + } + + /*Assign output pointers:*/ + *poptions=options; +} +/*}}}*/ +/*FUNCTION FetchData(DataSet** pcontours,PyObject* py_list){{{*/ +void FetchData(DataSet** pcontours,PyObject* py_list){ + + int numcontours,test1,test2; + char *contourname = NULL; + DataSet *contours = NULL; + Contour *contouri = NULL; + PyObject *py_dicti = NULL; + PyObject *py_item = NULL; + + if (PyString_Check(py_list)){ + FetchData(&contourname,py_list); + contours=DomainOutlineRead(contourname); + } + else if(PyList_Check(py_list)){ + + contours=new DataSet(0); + numcontours=(int)PyList_Size(py_list); + + for(int i=0;i >(1); + py_dicti=PyList_GetItem(py_list,(Py_ssize_t)i); + + py_item = PyDict_GetItemString(py_dicti,"nods"); + if(!py_item) _error_("input structure does not have a 'nods' field"); + FetchData(&contouri->nods,py_item); + + py_item = PyDict_GetItemString(py_dicti,"x"); + if(!py_item) _error_("input structure does not have a 'x' field"); + FetchData(&contouri->x,&test1,&test2,py_item); + if(test1!=contouri->nods || test2!=1) _error_("field x should be of size ["<nods<<" 1]"); + + py_item = PyDict_GetItemString(py_dicti,"y"); + if(!py_item) _error_("input structure does not have a 'y' field"); + FetchData(&contouri->y,&test1,&test2,py_item); + if(test1!=contouri->nods || test2!=1) _error_("field y should be of size ["<nods<<" 1]"); + + contours->AddObject(contouri); + } + } + else{ + _error_("Contour is neither a string nor a structure and cannot be loaded"); + } + + /*clean-up and assign output pointer*/ + xDelete(contourname); + *pcontours=contours; +} +/*}}}*/ + +/*Python version dependent: */ +#if _PYTHON_MAJOR_ >= 3 +/*FUNCTION FetchData(char** pstring,PyObject* py_unicode){{{*/ +void FetchData(char** pstring,PyObject* py_unicode){ + + PyObject* py_bytes; + char* string=NULL; + + /*convert to bytes format: */ + PyUnicode_FSConverter(py_unicode,&py_bytes); + + /*convert from bytes to string: */ + string=PyBytes_AS_STRING(py_bytes); + + *pstring=string; +} +/*}}}*/ +#else +/*FUNCTION FetchData(char** pstring,PyObject* py_string){{{*/ +void FetchData(char** pstring,PyObject* py_string){ + + char* string=NULL; + + /*extract internal string: */ + string=PyString_AsString(py_string); + + /*copy string (note strlen does not include trailing NULL): */ + *pstring=xNew(strlen(string)+1); + memcpy(*pstring,string,(strlen(string)+1)*sizeof(char)); +} +/*}}}*/ +#endif Index: ../trunk-jpl/src/wrappers/python/io/WritePythonData.cpp =================================================================== --- ../trunk-jpl/src/wrappers/python/io/WritePythonData.cpp (revision 0) +++ ../trunk-jpl/src/wrappers/python/io/WritePythonData.cpp (revision 13749) @@ -0,0 +1,194 @@ +/* \file WriteData.c: + * \brief: general interface for writing data + */ + +#ifdef HAVE_CONFIG_H + #include +#else +#error "Cannot compile with HAVE_CONFIG_H symbol! run configure first!" +#endif + +#define PY_ARRAY_UNIQUE_SYMBOL PythonIOSymbol +#define NO_IMPORT + +#include "./pythonio.h" +#include "../../c/include/include.h" +#include "../../c/Container/Container.h" +#include "../../c/shared/shared.h" +#include "../../c/EnumDefinitions/EnumDefinitions.h" + +/*Primitive data types*/ +/*FUNCTION WriteData(PyObject* py_tuple,int index,int integer){{{*/ +void WriteData(PyObject* py_tuple, int index, int integer){ + + PyTuple_SetItem(py_tuple, index, PyInt_FromSsize_t((Py_ssize_t)integer)); + +}/*}}}*/ +/*FUNCTION WriteData(PyObject* py_tuple,int index,char* string){{{*/ +void WriteData(PyObject* py_tuple, int index, char* string){ + + PyTuple_SetItem(py_tuple, index, PyUnicode_FromString(string)); + +}/*}}}*/ +/*FUNCTION WriteData(PyObject* py_tuple,int index, double* matrix, int M, int N){{{*/ +void WriteData(PyObject* tuple, int index, double* matrix, int M,int N){ + + npy_intp dims[2]={0,0}; + PyObject* array=NULL; + + dims[0]=(npy_intp)M; + dims[1]=(npy_intp)N; + array=PyArray_SimpleNewFromData(2,dims,NPY_DOUBLE,matrix); + + PyTuple_SetItem(tuple, index, array); +}/*}}}*/ +/*FUNCTION WriteData(PyObject* py_tuple,int index){{{*/ +void WriteData(PyObject* py_tuple, int index){ + + PyTuple_SetItem(py_tuple, index, Py_None); + +}/*}}}*/ + +/*ISSM objects*/ +/*FUNCTION WriteData(PyObject* py_tuple,int index,BamgGeom* bamggeom){{{*/ +void WriteData(PyObject* py_tuple,int index,BamgGeom* bamggeom){ + + PyObject* dict=NULL; + + dict=PyDict_New(); + + PyDict_SetItemString(dict,"Vertices",PyArrayFromCopiedData(bamggeom->VerticesSize,bamggeom->Vertices)); + PyDict_SetItemString(dict,"Edges",PyArrayFromCopiedData(bamggeom->EdgesSize,bamggeom->Edges)); + PyDict_SetItemString(dict,"TangentAtEdges",PyArrayFromCopiedData(bamggeom->TangentAtEdgesSize,bamggeom->TangentAtEdges)); + PyDict_SetItemString(dict,"Corners",PyArrayFromCopiedData(bamggeom->CornersSize,bamggeom->Corners)); + PyDict_SetItemString(dict,"RequiredVertices",PyArrayFromCopiedData(bamggeom->RequiredVerticesSize,bamggeom->RequiredVertices)); + PyDict_SetItemString(dict,"RequiredEdges",PyArrayFromCopiedData(bamggeom->RequiredEdgesSize,bamggeom->RequiredEdges)); + PyDict_SetItemString(dict,"CrackedEdges",PyArrayFromCopiedData(bamggeom->CrackedEdgesSize,bamggeom->CrackedEdges)); + PyDict_SetItemString(dict,"SubDomains",PyArrayFromCopiedData(bamggeom->SubDomainsSize,bamggeom->SubDomains)); + + PyTuple_SetItem(py_tuple, index, dict); +} +/*}}}*/ +/*FUNCTION WriteData(PyObject* py_tuple,int index,BamgMesh* bamgmesh){{{*/ +void WriteData(PyObject* py_tuple,int index,BamgMesh* bamgmesh){ + + PyObject* dict=NULL; + + dict=PyDict_New(); + + PyDict_SetItemString(dict,"Vertices",PyArrayFromCopiedData(bamgmesh->VerticesSize,bamgmesh->Vertices)); + PyDict_SetItemString(dict,"Edges",PyArrayFromCopiedData(bamgmesh->EdgesSize,bamgmesh->Edges)); + PyDict_SetItemString(dict,"Triangles",PyArrayFromCopiedData(bamgmesh->TrianglesSize,bamgmesh->Triangles)); + PyDict_SetItemString(dict,"Quadrilaterals",PyArrayFromCopiedData(bamgmesh->QuadrilateralsSize,bamgmesh->Quadrilaterals)); + PyDict_SetItemString(dict,"IssmEdges",PyArrayFromCopiedData(bamgmesh->IssmEdgesSize,bamgmesh->IssmEdges)); + PyDict_SetItemString(dict,"IssmSegments",PyArrayFromCopiedData(bamgmesh->IssmSegmentsSize,bamgmesh->IssmSegments)); + PyDict_SetItemString(dict,"VerticesOnGeomVertex",PyArrayFromCopiedData(bamgmesh->VerticesOnGeomVertexSize,bamgmesh->VerticesOnGeomVertex)); + PyDict_SetItemString(dict,"VerticesOnGeomEdge",PyArrayFromCopiedData(bamgmesh->VerticesOnGeomEdgeSize,bamgmesh->VerticesOnGeomEdge)); + PyDict_SetItemString(dict,"EdgesOnGeomEdge",PyArrayFromCopiedData(bamgmesh->EdgesOnGeomEdgeSize,bamgmesh->EdgesOnGeomEdge)); + PyDict_SetItemString(dict,"SubDomains",PyArrayFromCopiedData(bamgmesh->SubDomainsSize,bamgmesh->SubDomains)); + PyDict_SetItemString(dict,"SubDomainsFromGeom",PyArrayFromCopiedData(bamgmesh->SubDomainsFromGeomSize,bamgmesh->SubDomainsFromGeom)); + PyDict_SetItemString(dict,"ElementConnectivity",PyArrayFromCopiedData(bamgmesh->ElementConnectivitySize,bamgmesh->ElementConnectivity)); + PyDict_SetItemString(dict,"NodalConnectivity",PyArrayFromCopiedData(bamgmesh->NodalConnectivitySize,bamgmesh->NodalConnectivity)); + PyDict_SetItemString(dict,"NodalElementConnectivity",PyArrayFromCopiedData(bamgmesh->NodalElementConnectivitySize,bamgmesh->NodalElementConnectivity)); + PyDict_SetItemString(dict,"CrackedVertices",PyArrayFromCopiedData(bamgmesh->CrackedVerticesSize,bamgmesh->CrackedVertices)); + PyDict_SetItemString(dict,"CrackedEdges",PyArrayFromCopiedData(bamgmesh->CrackedEdgesSize,bamgmesh->CrackedEdges)); + + PyTuple_SetItem(py_tuple, index, dict); +} +/*}}}*/ +/*FUNCTION WriteData(PyObject* py_tuple,int index,SeqMat* matrix){{{*/ +void WriteData(PyObject* py_tuple,int index,SeqMat* matrix){ + + int M,N; + double* buffer=NULL; + npy_intp dims[2]={0,0}; + PyObject* array=NULL; + + buffer=matrix->ToSerial(); + matrix->GetSize(&M,&N); + dims[0]=(npy_intp)M; + dims[1]=(npy_intp)N; + array=PyArray_SimpleNewFromData(2,dims,NPY_DOUBLE,buffer); + + PyTuple_SetItem(py_tuple, index, array); + +}/*}}}*/ +/*FUNCTION WriteData(PyObject* py_tuple,int index,SeqVec* vector){{{*/ +void WriteData(PyObject* py_tuple,int index,SeqVec* vector){ + + int M; + double* buffer=NULL; + npy_intp dim=10; + PyObject* array=NULL; + + buffer=vector->ToMPISerial(); + vector->GetSize(&M); + dim=(npy_intp)M; + array=PyArray_SimpleNewFromData(1,&dim,NPY_DOUBLE,buffer); + + PyTuple_SetItem(py_tuple, index, array); +} +/*}}}*/ +/*FUNCTION WriteData(PyObject* py_tuple,int index,RiftStruct* riftstruct){{{*/ +void WriteData(PyObject* py_tuple,int index,RiftStruct* riftstruct){ + + int i; + PyObject* list=NULL; + PyObject* dict=NULL; + + list=PyList_New((Py_ssize_t)0); + + for (i=0; inumrifts; i++) { + dict=PyDict_New(); + + PyDict_SetItemString(dict,"numsegs" ,PyInt_FromSsize_t((Py_ssize_t)riftstruct->riftsnumsegments[i])); + PyDict_SetItemString(dict,"segments" ,PyArrayFromCopiedData(riftstruct->riftsnumsegments[i] ,3,riftstruct->riftssegments[i])); + PyDict_SetItemString(dict,"pairs" ,PyArrayFromCopiedData(riftstruct->riftsnumpairs[i] ,2,riftstruct->riftspairs[i])); + PyDict_SetItemString(dict,"tips" ,PyArrayFromCopiedData(1 ,2,&riftstruct->riftstips[2*i])); + PyDict_SetItemString(dict,"penaltypairs" ,PyArrayFromCopiedData(riftstruct->riftsnumpenaltypairs[i],7,riftstruct->riftspenaltypairs[i])); + PyDict_SetItemString(dict,"fill" ,PyInt_FromSsize_t((Py_ssize_t)IceEnum)); + PyDict_SetItemString(dict,"friction" ,PyInt_FromSsize_t((Py_ssize_t)0)); + PyDict_SetItemString(dict,"fraction" ,PyFloat_FromDouble(0.)); + PyDict_SetItemString(dict,"fractionincrement",PyFloat_FromDouble(0.1)); + PyDict_SetItemString(dict,"state" ,PyArrayFromCopiedData(riftstruct->riftsnumpenaltypairs[i],1,riftstruct->state[i])); + + PyList_Append(list, dict); + } + + PyTuple_SetItem(py_tuple, index, list); +} +/*}}}*/ + +/*Utils*/ +/*FUNCTION PyArrayFromCopiedData(int dims[2],double* data){{{*/ +PyObject* PyArrayFromCopiedData(int dims[2],double* data){ + + double* pydata; + npy_intp pydims[2]={0,0}; + + /* note that PyArray_SimpleNewFromData does not copy the data, so that when the original + object (e.g. bamggeom,bamgmesh) is deleted, the data is gone. */ + + pydims[0]=(npy_intp)dims[0]; + pydims[1]=(npy_intp)dims[1]; + pydata=xNew(dims[0]*dims[1]); + memcpy(pydata,data,dims[0]*dims[1]*sizeof(double)); + return PyArray_SimpleNewFromData(2,pydims,NPY_DOUBLE,pydata); +} +/*}}}*/ +/*FUNCTION PyArrayFromCopiedData(int dimi,int dimj,double* data){{{*/ +PyObject* PyArrayFromCopiedData(int dimi,int dimj,double* data){ + + double* pydata; + npy_intp pydims[2]={0,0}; + + /* note that PyArray_SimpleNewFromData does not copy the data, so that when the original + object (e.g. bamggeom,bamgmesh) is deleted, the data is gone. */ + + pydims[0]=(npy_intp)dimi; + pydims[1]=(npy_intp)dimj; + pydata=xNew(dimi*dimj); + memcpy(pydata,data,dimi*dimj*sizeof(double)); + return PyArray_SimpleNewFromData(2,pydims,NPY_DOUBLE,pydata); +} +/*}}}*/ Index: ../trunk-jpl/src/wrappers/python/Makefile.am =================================================================== --- ../trunk-jpl/src/wrappers/python/Makefile.am (revision 13748) +++ ../trunk-jpl/src/wrappers/python/Makefile.am (revision 13749) @@ -1,7 +1,28 @@ -AM_CPPFLAGS = @DAKOTAINCL@ @PETSCINCL@ @MPIINCL@ @SPOOLESINCL@ @METISINCL@ @TRIANGLEINCL@ @CHACOINCL@ @SCOTCHINCL@ @SHAPELIBINCL@ @BOOSTINCL@ @PYTHONINCL@ @PYTHON_NUMPYINCL@ +AM_CPPFLAGS = @DAKOTAINCL@ @PETSCINCL@ @MPIINCL@ @SPOOLESINCL@ @METISINCL@ @TRIANGLEINCL@ @CHACOINCL@ @SCOTCHINCL@ @SHAPELIBINCL@ @PYTHONINCL@ @PYTHON_NUMPYINCL@ EXEEXT=$(PYTHONWRAPPEREXT) +#python io{{{ +lib_LIBRARIES = libISSMPython.a +if SHAREDLIBS +lib_LTLIBRARIES = libISSMPython.la +else + lib_LTLIBRARIES = +endif + +io_sources= ./include/pythonincludes.h\ + ./io/pythonio.h\ + ./io/WritePythonData.cpp\ + ./io/CheckNumPythonArguments.cpp\ + ./io/FetchPythonData.cpp + +ALLCXXFLAGS= -fPIC -D_GNU_SOURCE -fno-omit-frame-pointer -pthread -D_CPP_ $(CXXFLAGS) $(CXXOPTFLAGS) +libISSMPython_a_SOURCES = $(io_sources) +libISSMPython_a_CXXFLAGS= $(ALLCXXFLAGS) +if SHAREDLIBS +libISSMPython_la_SOURCES = $(io_sources) +endif +#}}} #Wrappers {{{ if WRAPPERS lib_LTLIBRARIES = BamgConvertMesh.la\ @@ -37,9 +58,9 @@ AM_LDFLAGS += -avoid-version endif if SHAREDLIBS -deps += ../../c/libISSMPython.la +deps += ./libISSMPython.la else -deps += ../../c/libISSMPython.a +deps += ./libISSMPython.a AM_LDFLAGS += --no-warnings endif Index: ../trunk-jpl/src/wrappers/Scotch/Scotch.h =================================================================== --- ../trunk-jpl/src/wrappers/Scotch/Scotch.h (revision 13748) +++ ../trunk-jpl/src/wrappers/Scotch/Scotch.h (revision 13749) @@ -12,7 +12,7 @@ #include "../../c/modules/modules.h" #include "../../c/Container/Container.h" #include "../../c/shared/shared.h" -#include "../../c/issm-binding.h" +#include "../bindings.h" #undef __FUNCT__ #define __FUNCT__ "Scotch" Index: ../trunk-jpl/src/wrappers/NodeConnectivity/NodeConnectivity.h =================================================================== --- ../trunk-jpl/src/wrappers/NodeConnectivity/NodeConnectivity.h (revision 13748) +++ ../trunk-jpl/src/wrappers/NodeConnectivity/NodeConnectivity.h (revision 13749) @@ -26,7 +26,7 @@ #include "../../c/modules/modules.h" #include "../../c/Container/Container.h" #include "../../c/shared/shared.h" -#include "../../c/issm-binding.h" +#include "../bindings.h" #include "../../c/io/io.h" #include "../../c/EnumDefinitions/EnumDefinitions.h" Index: ../trunk-jpl/src/wrappers/BamgConvertMesh/BamgConvertMesh.h =================================================================== --- ../trunk-jpl/src/wrappers/BamgConvertMesh/BamgConvertMesh.h (revision 13748) +++ ../trunk-jpl/src/wrappers/BamgConvertMesh/BamgConvertMesh.h (revision 13749) @@ -20,7 +20,7 @@ #include "../../c/modules/modules.h" #include "../../c/Container/Container.h" #include "../../c/shared/shared.h" -#include "../../c/issm-binding.h" +#include "../bindings.h" #include "../../c/io/io.h" #undef __FUNCT__ Index: ../trunk-jpl/src/wrappers/KMLOverlay/KMLOverlay.h =================================================================== --- ../trunk-jpl/src/wrappers/KMLOverlay/KMLOverlay.h (revision 13748) +++ ../trunk-jpl/src/wrappers/KMLOverlay/KMLOverlay.h (revision 13749) @@ -20,7 +20,7 @@ #include "../../c/modules/modules.h" #include "../../c/Container/Container.h" #include "../../c/shared/shared.h" -#include "../../c/issm-binding.h" +#include "../bindings.h" #undef __FUNCT__ #define __FUNCT__ "KMLOverlay" Index: ../trunk-jpl/src/wrappers/ContourToNodes/ContourToNodes.h =================================================================== --- ../trunk-jpl/src/wrappers/ContourToNodes/ContourToNodes.h (revision 13748) +++ ../trunk-jpl/src/wrappers/ContourToNodes/ContourToNodes.h (revision 13749) @@ -20,7 +20,7 @@ #include "../../c/modules/modules.h" #include "../../c/Container/Container.h" #include "../../c/shared/shared.h" -#include "../../c/issm-binding.h" +#include "../bindings.h" #undef __FUNCT__ #define __FUNCT__ "ContourToNodes" Index: ../trunk-jpl/src/wrappers/HoleFiller/HoleFiller.h =================================================================== --- ../trunk-jpl/src/wrappers/HoleFiller/HoleFiller.h (revision 13748) +++ ../trunk-jpl/src/wrappers/HoleFiller/HoleFiller.h (revision 13749) @@ -20,7 +20,7 @@ #include "../../c/modules/modules.h" #include "../../c/Container/Container.h" #include "../../c/shared/shared.h" -#include "../../c/issm-binding.h" +#include "../bindings.h" #undef __FUNCT__ #define __FUNCT__ "HoleFiller" Index: ../trunk-jpl/src/wrappers/MeshProfileIntersection/MeshProfileIntersection.h =================================================================== --- ../trunk-jpl/src/wrappers/MeshProfileIntersection/MeshProfileIntersection.h (revision 13748) +++ ../trunk-jpl/src/wrappers/MeshProfileIntersection/MeshProfileIntersection.h (revision 13749) @@ -20,7 +20,7 @@ #include "../../c/modules/modules.h" #include "../../c/Container/Container.h" #include "../../c/shared/shared.h" -#include "../../c/issm-binding.h" +#include "../bindings.h" #undef __FUNCT__ #define __FUNCT__ "MeshProfileIntersection" Index: ../trunk-jpl/src/wrappers/InterpFromMeshToMesh3d/InterpFromMeshToMesh3d.h =================================================================== --- ../trunk-jpl/src/wrappers/InterpFromMeshToMesh3d/InterpFromMeshToMesh3d.h (revision 13748) +++ ../trunk-jpl/src/wrappers/InterpFromMeshToMesh3d/InterpFromMeshToMesh3d.h (revision 13749) @@ -20,7 +20,7 @@ #include "../../c/modules/modules.h" #include "../../c/Container/Container.h" #include "../../c/shared/shared.h" -#include "../../c/issm-binding.h" +#include "../bindings.h" #undef __FUNCT__ #define __FUNCT__ "InterpFromMeshToMesh3d" Index: ../trunk-jpl/src/wrappers/Ll2xy/Ll2xy.h =================================================================== --- ../trunk-jpl/src/wrappers/Ll2xy/Ll2xy.h (revision 13748) +++ ../trunk-jpl/src/wrappers/Ll2xy/Ll2xy.h (revision 13749) @@ -20,7 +20,7 @@ #include "../../c/modules/modules.h" #include "../../c/Container/Container.h" #include "../../c/shared/shared.h" -#include "../../c/issm-binding.h" +#include "../bindings.h" #undef __FUNCT__ #define __FUNCT__ "Ll2xy" Index: ../trunk-jpl/src/wrappers/BamgMesher/BamgMesher.h =================================================================== --- ../trunk-jpl/src/wrappers/BamgMesher/BamgMesher.h (revision 13748) +++ ../trunk-jpl/src/wrappers/BamgMesher/BamgMesher.h (revision 13749) @@ -20,7 +20,7 @@ #include "../../c/modules/modules.h" #include "../../c/Container/Container.h" #include "../../c/shared/shared.h" -#include "../../c/issm-binding.h" +#include "../bindings.h" #undef __FUNCT__ #define __FUNCT__ "BamgMesher" Index: ../trunk-jpl/src/wrappers/InterpFromGridToMesh/InterpFromGridToMesh.h =================================================================== --- ../trunk-jpl/src/wrappers/InterpFromGridToMesh/InterpFromGridToMesh.h (revision 13748) +++ ../trunk-jpl/src/wrappers/InterpFromGridToMesh/InterpFromGridToMesh.h (revision 13749) @@ -20,7 +20,7 @@ #include "../../c/modules/modules.h" #include "../../c/Container/Container.h" #include "../../c/shared/shared.h" -#include "../../c/issm-binding.h" +#include "../bindings.h" #undef __FUNCT__ #define __FUNCT__ "InterpFromGridToMesh" Index: ../trunk-jpl/src/wrappers/InterpFromMeshToGrid/InterpFromMeshToGrid.h =================================================================== --- ../trunk-jpl/src/wrappers/InterpFromMeshToGrid/InterpFromMeshToGrid.h (revision 13748) +++ ../trunk-jpl/src/wrappers/InterpFromMeshToGrid/InterpFromMeshToGrid.h (revision 13749) @@ -20,7 +20,7 @@ #include "../../c/modules/modules.h" #include "../../c/Container/Container.h" #include "../../c/shared/shared.h" -#include "../../c/issm-binding.h" +#include "../bindings.h" #undef __FUNCT__ #define __FUNCT__ "InterpFromMeshToGrid" Index: ../trunk-jpl/src/wrappers/KMLFileRead/KMLFileRead.h =================================================================== --- ../trunk-jpl/src/wrappers/KMLFileRead/KMLFileRead.h (revision 13748) +++ ../trunk-jpl/src/wrappers/KMLFileRead/KMLFileRead.h (revision 13749) @@ -20,7 +20,7 @@ #include "../../c/modules/modules.h" #include "../../c/Container/Container.h" #include "../../c/shared/shared.h" -#include "../../c/issm-binding.h" +#include "../bindings.h" #undef __FUNCT__ #define __FUNCT__ "KMLFileRead" Index: ../trunk-jpl/src/wrappers/Shp2Kml/Shp2Kml.h =================================================================== --- ../trunk-jpl/src/wrappers/Shp2Kml/Shp2Kml.h (revision 13748) +++ ../trunk-jpl/src/wrappers/Shp2Kml/Shp2Kml.h (revision 13749) @@ -20,7 +20,7 @@ #include "../../c/modules/modules.h" #include "../../c/Container/Container.h" #include "../../c/shared/shared.h" -#include "../../c/issm-binding.h" +#include "../bindings.h" #undef __FUNCT__ #define __FUNCT__ "Shp2Kml" Index: ../trunk-jpl/src/wrappers/AverageFilter/AverageFilter.h =================================================================== --- ../trunk-jpl/src/wrappers/AverageFilter/AverageFilter.h (revision 13748) +++ ../trunk-jpl/src/wrappers/AverageFilter/AverageFilter.h (revision 13749) @@ -20,7 +20,7 @@ #include "../../c/modules/modules.h" #include "../../c/Container/Container.h" #include "../../c/shared/shared.h" -#include "../../c/issm-binding.h" +#include "../bindings.h" #undef __FUNCT__ #define __FUNCT__ "AverageFilter" Index: ../trunk-jpl/src/wrappers/TriMeshProcessRifts/TriMeshProcessRifts.h =================================================================== --- ../trunk-jpl/src/wrappers/TriMeshProcessRifts/TriMeshProcessRifts.h (revision 13748) +++ ../trunk-jpl/src/wrappers/TriMeshProcessRifts/TriMeshProcessRifts.h (revision 13749) @@ -20,7 +20,7 @@ #include "../../c/modules/modules.h" #include "../../c/Container/Container.h" #include "../../c/shared/shared.h" -#include "../../c/issm-binding.h" +#include "../bindings.h" #undef __FUNCT__ #define __FUNCT__ "TriMeshProcessRifts" Index: ../trunk-jpl/src/wrappers/Exp2Kml/Exp2Kml.h =================================================================== --- ../trunk-jpl/src/wrappers/Exp2Kml/Exp2Kml.h (revision 13748) +++ ../trunk-jpl/src/wrappers/Exp2Kml/Exp2Kml.h (revision 13749) @@ -20,7 +20,7 @@ #include "../../c/modules/modules.h" #include "../../c/Container/Container.h" #include "../../c/shared/shared.h" -#include "../../c/issm-binding.h" +#include "../bindings.h" #undef __FUNCT__ #define __FUNCT__ "Exp2Kml" Index: ../trunk-jpl/src/wrappers/Kml2Exp/Kml2Exp.h =================================================================== --- ../trunk-jpl/src/wrappers/Kml2Exp/Kml2Exp.h (revision 13748) +++ ../trunk-jpl/src/wrappers/Kml2Exp/Kml2Exp.h (revision 13749) @@ -20,7 +20,7 @@ #include "../../c/modules/modules.h" #include "../../c/Container/Container.h" #include "../../c/shared/shared.h" -#include "../../c/issm-binding.h" +#include "../bindings.h" #undef __FUNCT__ #define __FUNCT__ "Kml2Exp" Index: ../trunk-jpl/src/wrappers/PointCloudFindNeighbors/PointCloudFindNeighbors.h =================================================================== --- ../trunk-jpl/src/wrappers/PointCloudFindNeighbors/PointCloudFindNeighbors.h (revision 13748) +++ ../trunk-jpl/src/wrappers/PointCloudFindNeighbors/PointCloudFindNeighbors.h (revision 13749) @@ -20,7 +20,7 @@ #include "../../c/modules/modules.h" #include "../../c/Container/Container.h" #include "../../c/shared/shared.h" -#include "../../c/issm-binding.h" +#include "../bindings.h" #undef __FUNCT__ #define __FUNCT__ "PointCloudFindNeighbors" Index: ../trunk-jpl/src/wrappers/PropagateFlagsFromConnectivity/PropagateFlagsFromConnectivity.h =================================================================== --- ../trunk-jpl/src/wrappers/PropagateFlagsFromConnectivity/PropagateFlagsFromConnectivity.h (revision 13748) +++ ../trunk-jpl/src/wrappers/PropagateFlagsFromConnectivity/PropagateFlagsFromConnectivity.h (revision 13749) @@ -20,7 +20,7 @@ #include "../../c/modules/modules.h" #include "../../c/Container/Container.h" #include "../../c/shared/shared.h" -#include "../../c/issm-binding.h" +#include "../bindings.h" #undef __FUNCT__ #define __FUNCT__ "PropagateFlagsFromConnectivity" Index: ../trunk-jpl/src/wrappers/include/issm-binding.h =================================================================== --- ../trunk-jpl/src/wrappers/include/issm-binding.h (revision 0) +++ ../trunk-jpl/src/wrappers/include/issm-binding.h (revision 13749) @@ -0,0 +1,18 @@ +#ifndef _ISSM_BINDING_H_ +#define _ISSM_BINDING_H_ + +#ifdef HAVE_CONFIG_H + #include +#else +#error "Cannot compile with HAVE_CONFIG_H symbol! run configure first!" +#endif + +#ifdef _HAVE_MATLAB_MODULES_ +#include "../matlab/include/matlab-macros.h" +#endif + +#ifdef _HAVE_PYTHON_MODULES_ +#include "../python/include/python-macros.h" +#endif + +#endif Index: ../trunk-jpl/src/wrappers/bindings.h =================================================================== --- ../trunk-jpl/src/wrappers/bindings.h (revision 0) +++ ../trunk-jpl/src/wrappers/bindings.h (revision 13749) @@ -0,0 +1,22 @@ +#ifndef _BINDINGS_H_ +#define _BINDINGS_H_ + +#ifdef HAVE_CONFIG_H + #include +#else +#error "Cannot compile with HAVE_CONFIG_H symbol! run configure first!" +#endif + +#ifdef _HAVE_MATLAB_MODULES_ +#include "./matlab/include/matlabincludes.h" +#include "./matlab/include/wrapper_macros.h" +#include "./matlab/io/matlabio.h" +#endif + +#ifdef _HAVE_PYTHON_MODULES_ +#include "./python/include/pythonincludes.h" +#include "./python/include/wrapper_macros.h" +#include "./python/io/pythonio.h" +#endif + +#endif Index: ../trunk-jpl/src/wrappers/TriaSearch/TriaSearch.h =================================================================== --- ../trunk-jpl/src/wrappers/TriaSearch/TriaSearch.h (revision 13748) +++ ../trunk-jpl/src/wrappers/TriaSearch/TriaSearch.h (revision 13749) @@ -19,7 +19,7 @@ #include "../../c/modules/modules.h" #include "../../c/Container/Container.h" #include "../../c/shared/shared.h" -#include "../../c/issm-binding.h" +#include "../bindings.h" #undef __FUNCT__ #define __FUNCT__ "TriaSearch" Index: ../trunk-jpl/src/wrappers/InternalFront/InternalFront.h =================================================================== --- ../trunk-jpl/src/wrappers/InternalFront/InternalFront.h (revision 13748) +++ ../trunk-jpl/src/wrappers/InternalFront/InternalFront.h (revision 13749) @@ -18,7 +18,7 @@ #include "../../c/include/globals.h" #include "../../c/shared/shared.h" -#include "../../c/issm-binding.h" +#include "../bindings.h" #include "../../c/io/io.h" #undef __FUNCT__ Index: ../trunk-jpl/src/wrappers/MeshPartition/MeshPartition.h =================================================================== --- ../trunk-jpl/src/wrappers/MeshPartition/MeshPartition.h (revision 13748) +++ ../trunk-jpl/src/wrappers/MeshPartition/MeshPartition.h (revision 13749) @@ -20,7 +20,7 @@ #include "../../c/modules/modules.h" #include "../../c/Container/Container.h" #include "../../c/shared/shared.h" -#include "../../c/issm-binding.h" +#include "../bindings.h" #undef __FUNCT__ #define __FUNCT__ "MeshPartition" Index: ../trunk-jpl/src/wrappers/InterpFromMesh2d/InterpFromMesh2d.h =================================================================== --- ../trunk-jpl/src/wrappers/InterpFromMesh2d/InterpFromMesh2d.h (revision 13748) +++ ../trunk-jpl/src/wrappers/InterpFromMesh2d/InterpFromMesh2d.h (revision 13749) @@ -20,7 +20,7 @@ #include "../../c/modules/modules.h" #include "../../c/Container/Container.h" #include "../../c/shared/shared.h" -#include "../../c/issm-binding.h" +#include "../bindings.h" #undef __FUNCT__ #define __FUNCT__ "InterpFromMesh2d" Index: ../trunk-jpl/src/wrappers/ElementConnectivity/ElementConnectivity.h =================================================================== --- ../trunk-jpl/src/wrappers/ElementConnectivity/ElementConnectivity.h (revision 13748) +++ ../trunk-jpl/src/wrappers/ElementConnectivity/ElementConnectivity.h (revision 13749) @@ -23,7 +23,7 @@ #include "../../c/modules/modules.h" #include "../../c/Container/Container.h" #include "../../c/shared/shared.h" -#include "../../c/issm-binding.h" +#include "../bindings.h" #include "../../c/io/io.h" #include "../../c/EnumDefinitions/EnumDefinitions.h" Index: ../trunk-jpl/src/wrappers/Kriging/Kriging.h =================================================================== --- ../trunk-jpl/src/wrappers/Kriging/Kriging.h (revision 13748) +++ ../trunk-jpl/src/wrappers/Kriging/Kriging.h (revision 13749) @@ -19,7 +19,7 @@ #include "../../c/include/globals.h" #include "../../c/modules/modules.h" #include "../../c/shared/shared.h" -#include "../../c/issm-binding.h" +#include "../bindings.h" #undef __FUNCT__ #define __FUNCT__ "Kriging" Index: ../trunk-jpl/src/wrappers/EnumToString/EnumToString.h =================================================================== --- ../trunk-jpl/src/wrappers/EnumToString/EnumToString.h (revision 13748) +++ ../trunk-jpl/src/wrappers/EnumToString/EnumToString.h (revision 13749) @@ -21,7 +21,7 @@ #include "../../c/modules/modules.h" #include "../../c/Container/Container.h" #include "../../c/shared/shared.h" -#include "../../c/issm-binding.h" +#include "../bindings.h" #undef __FUNCT__ #define __FUNCT__ "EnumToString" Index: ../trunk-jpl/src/wrappers/StringToEnum/StringToEnum.h =================================================================== --- ../trunk-jpl/src/wrappers/StringToEnum/StringToEnum.h (revision 13748) +++ ../trunk-jpl/src/wrappers/StringToEnum/StringToEnum.h (revision 13749) @@ -21,7 +21,7 @@ #include "../../c/modules/modules.h" #include "../../c/Container/Container.h" #include "../../c/shared/shared.h" -#include "../../c/issm-binding.h" +#include "../bindings.h" #undef __FUNCT__ #define __FUNCT__ "StringToEnum" Index: ../trunk-jpl/src/wrappers/matlab/include/wrapper_macros.h =================================================================== --- ../trunk-jpl/src/wrappers/matlab/include/wrapper_macros.h (revision 0) +++ ../trunk-jpl/src/wrappers/matlab/include/wrapper_macros.h (revision 13749) @@ -0,0 +1,42 @@ +/* \file matlab macros.h + * \brief: macros used for the matlab bindings + */ + +#ifndef _MATLAB_MACROS_H_ +#define _MATLAB_MACROS_H_ + +#ifdef HAVE_CONFIG_H + #include +#else +#error "Cannot compile with HAVE_CONFIG_H symbol! run configure first!" +#endif + +#ifdef _HAVE_MATLAB_ +/* MODULEBOOT/MODULEEND {{{*/ + +/*The following macros hide the error exception handling in a matlab module. Just put + * MODULEBOOT(); and MODULEEND(); at the beginning and end of a module, and c++ exceptions + * will be trapped*/ +#define MODULEBOOT(); try{ \ + IssmComm::SetComm(-1); + +#define MODULEEND(); }\ + catch(ErrorException &exception){\ + mexErrMsgTxt(exception.MatlabReport()); \ + }\ + catch (exception &e){\ + mexErrMsgTxt(exprintf("Standard exception: %s\n",e.what()));\ + }\ + catch(...){\ + mexErrMsgTxt("An unexpected error occurred");\ + } +/*}}}*/ +/* WRAPPER {{{*/ +#define WRAPPER(modulename,...) void mexFunction(int nlhs, mxArray* plhs[], int nrhs, const mxArray* prhs[]) +/*}}}*/ +/* CHECKARGUMENTS {{{*/ +#define CHECKARGUMENTS(NLHS,NRHS,functionpointer) CheckNumMatlabArguments(nlhs,NLHS,nrhs,NRHS,__FUNCT__,functionpointer) +/*}}}*/ +#endif + +#endif Index: ../trunk-jpl/src/wrappers/matlab/io/MatlabMatrixToSeqMat.cpp =================================================================== --- ../trunk-jpl/src/wrappers/matlab/io/MatlabMatrixToSeqMat.cpp (revision 0) +++ ../trunk-jpl/src/wrappers/matlab/io/MatlabMatrixToSeqMat.cpp (revision 13749) @@ -0,0 +1,25 @@ +/*!\file MatlabMatrixToSeqMat.cpp + */ + +/*Headers:*/ +#ifdef HAVE_CONFIG_H + #include +#else +#error "Cannot compile with HAVE_CONFIG_H symbol! run configure first!" +#endif + +#include +#include +#include "./matlabio.h" +#include "../../c/toolkits/toolkits.h" +#include "../../c/shared/shared.h" + +SeqMat* MatlabMatrixToSeqMat(const mxArray* dataref){ + + SeqMat* output=NULL; + + output=new SeqMat(); + MatlabMatrixToDoubleMatrix(&output->matrix,&output->M,&output->N,dataref); + return output; + +} Index: ../trunk-jpl/src/wrappers/matlab/io/MatlabVectorToPetscVec.cpp =================================================================== --- ../trunk-jpl/src/wrappers/matlab/io/MatlabVectorToPetscVec.cpp (revision 0) +++ ../trunk-jpl/src/wrappers/matlab/io/MatlabVectorToPetscVec.cpp (revision 13749) @@ -0,0 +1,106 @@ +/* \file MatlabVectorToPetscVector.cpp + * \brief: convert a sparse or dense matlab vector to a serial Petsc vector: + */ + +#ifdef HAVE_CONFIG_H + #include +#else +#error "Cannot compile with HAVE_CONFIG_H symbol! run configure first!" +#endif + +/*Petsc includes: */ +#include +#include +#include + +/*Matlab includes: */ +#include "./matlabio.h" +#include "../../c/shared/shared.h" + +PetscVec* MatlabVectorToPetscVec(const mxArray* mxvector){ + + int dummy; + PetscVec* vector=new PetscVec(); + + MatlabVectorToPetscVec(&vector->vector,&dummy, mxvector); + + return vector; +} + +int MatlabVectorToPetscVec(Vec* pvector,int* pvector_rows,const mxArray* mxvector){ + + int rows, cols; + double* mxvector_ptr=NULL; + int ierr; + int i,j; + + /*output: */ + Vec vector=NULL; + + /*matlab indices: */ + mwIndex* ir=NULL; + mwIndex* jc=NULL; + double* pr=NULL; + int count; + int nnz; + int nz; + + /*petsc indices: */ + int* idxm=NULL; + + /*Ok, first check if we are dealing with a sparse or full vector: */ + if (mxIsSparse(mxvector)){ + + /*Dealing with sparse vector: recover size first: */ + mxvector_ptr=(double*)mxGetPr(mxvector); + rows=mxGetM(mxvector); + cols=mxGetN(mxvector); + nnz=mxGetNzmax(mxvector); + nz=(int)((double)nnz/(double)rows); + + ierr=VecCreateSeq(PETSC_COMM_SELF,rows,&vector);CHKERRQ(ierr); + + /*Now, get ir,jc and pr: */ + pr=mxGetPr(mxvector); + ir=mxGetIr(mxvector); + jc=mxGetJc(mxvector); + + /*Now, start inserting data into sparse vector: */ + count=0; + for(i=0;i(rows); + + for(i=0;i +#else +#error "Cannot compile with HAVE_CONFIG_H symbol! run configure first!" +#endif + +#include +#include "./matlabio.h" +#include "../../c/shared/shared.h" +#include "../../c/io/io.h" + +GenericOption* OptionDoubleParse( char* name, const mxArray* prhs[]){ /*{{{*/ + + GenericOption *odouble = NULL; + + /*check and parse the name */ + odouble=new GenericOption(); + odouble->name =xNew(strlen(name)+1); + memcpy(odouble->name,name,(strlen(name)+1)*sizeof(char)); + FetchData(&odouble->value,prhs[0]); + odouble->numel=1; + odouble->ndims=1; + odouble->size=NULL; + + return(odouble); +}/*}}}*/ +GenericOption* OptionDoubleArrayParse( char* name, const mxArray* prhs[]){ /*{{{*/ + + GenericOption *odouble = NULL; + + /*check and parse the name */ + odouble=new GenericOption(); + odouble->name =xNew(strlen(name)+1); + memcpy(odouble->name,name,(strlen(name)+1)*sizeof(char)); + + /*check and parse the value */ + if (!mxIsClass(prhs[0],"double")){ + _error_("Value of option \"" << odouble->name << "\" must be class \"double\", not class \"" << mxGetClassName(prhs[0]) <<"\"."); + } + FetchData(&odouble->value,&odouble->numel,&odouble->ndims,&odouble->size,prhs[0]); + + return(odouble); +}/*}}}*/ +GenericOption* OptionLogicalParse( char* name, const mxArray* prhs[]){ /*{{{*/ + + GenericOption *ological = NULL; + + /*check and parse the name */ + ological=new GenericOption(); + ological->name =xNew(strlen(name)+1); + memcpy(ological->name,name,(strlen(name)+1)*sizeof(char)); + + /*check and parse the value */ + if (!mxIsClass(prhs[0],"logical")){ + _error_("Value of option \"" << ological->name << "\" must be class \"logical\", not class \"" << mxGetClassName(prhs[0]) <<"\"."); + } + FetchData(&ological->value,&ological->numel,&ological->ndims,&ological->size,prhs[0]); + + return(ological); +}/*}}}*/ +GenericOption* OptionCharParse( char* name, const mxArray* prhs[]){ /*{{{*/ + + GenericOption *ochar = NULL; + + /*check and parse the name */ + ochar=new GenericOption(); + ochar->name =xNew(strlen(name)+1); + memcpy(ochar->name,name,(strlen(name)+1)*sizeof(char)); + + /*check and parse the value */ + if (!mxIsClass(prhs[0],"char")){ + _error_("Value of option \"" << ochar->name << "\" must be class \"char\", not class \"" << mxGetClassName(prhs[0]) <<"\"."); + } + FetchData(&ochar->value,&ochar->numel,&ochar->ndims,&ochar->size,prhs[0]); + + return(ochar); +}/*}}}*/ +GenericOption* OptionStructParse( char* name, const mxArray* prhs[]){ /*{{{*/ + + int i; + char namei[161]; + Option* option = NULL; + GenericOption *ostruct = NULL; + const mwSize *ipt = NULL; + const mxArray *structi; + mwIndex sindex; + + /*check and parse the name */ + ostruct=new GenericOption(); + ostruct->name =xNew(strlen(name)+1); + memcpy(ostruct->name,name,(strlen(name)+1)*sizeof(char)); + + /*check and parse the value */ + if (!mxIsClass(prhs[0],"struct")){ + _error_("Value of option \"" << ostruct->name << "\" must be class \"struct\", not class \"" << mxGetClassName(prhs[0]) <<"\"."); + } + ostruct->numel=mxGetNumberOfElements(prhs[0]); + ostruct->ndims=mxGetNumberOfDimensions(prhs[0]); + ipt =mxGetDimensions(prhs[0]); + ostruct->size =xNew(ostruct->ndims); + for (i=0; indims; i++) ostruct->size[i]=(int)ipt[i]; + if (ostruct->numel) ostruct->value=xNew(ostruct->numel); + + /*loop through and process each element of the struct array */ + for (sindex=0; sindexnumel; sindex++) { + ostruct->value[sindex]=new Options; + + /*loop through and process each field for the element */ + for (i=0; ivalue[sindex]->AddObject((Object*)option); + option=NULL; + } + } + + return(ostruct); +}/*}}}*/ +GenericOption* OptionCellParse( char* name, const mxArray* prhs[]){ /*{{{*/ + + int i; + int *dims; + char namei[161]; + char cstr[81]; + GenericOption *ocell = NULL; + Option *option = NULL; + const mwSize *ipt = NULL; + const mxArray *celli; + mwIndex cindex; + + /*check and parse the name */ + ocell=new GenericOption(); + ocell->name =xNew(strlen(name)+1); + memcpy(ocell->name,name,(strlen(name)+1)*sizeof(char)); + + /*check and parse the value */ + if (!mxIsClass(prhs[0],"cell")){ + _error_("Value of option \"" << ocell->name << "\" must be class \"cell\", not class \"" << mxGetClassName(prhs[0]) <<"\"."); + } + + ocell->numel=mxGetNumberOfElements(prhs[0]); + ocell->ndims=mxGetNumberOfDimensions(prhs[0]); + ipt =mxGetDimensions(prhs[0]); + ocell->size =xNew(ocell->ndims); + for (i=0; indims; i++) ocell->size[i]=(int)ipt[i]; + ocell->value=new Options; + + /*loop through and process each element of the cell array */ + dims=xNew(ocell->ndims); + for (cindex=0; cindexnumel; cindex++) { + ColumnWiseDimsFromIndex(dims,(int)cindex,ocell->size,ocell->ndims); + StringFromDims(cstr,dims,ocell->ndims); + #ifdef _INTEL_WIN_ + _snprintf(namei,161,"%s%s",name,cstr); + #else + snprintf(namei,161,"%s%s",name,cstr); + #endif + celli=mxGetCell(prhs[0],cindex); + + option=(Option*)OptionParse(namei,&celli); + ocell->value->AddObject((Object*)option); + option=NULL; + } + xDelete(dims); + + return(ocell); +}/*}}}*/ +Option* OptionParse(char* name, const mxArray* prhs[]){ /*{{{*/ + + Option *option = NULL; + mxArray *lhs[1]; + + /*parse the value according to the matlab data type */ + if (mxIsClass(prhs[0],"double") && (mxGetNumberOfElements(prhs[0])==1)) + option=(Option*)OptionDoubleParse(name,prhs); + else if(mxIsClass(prhs[0],"double") && (mxGetNumberOfElements(prhs[0])!=1)) + option=(Option*)OptionDoubleArrayParse(name,prhs); + else if(mxIsClass(prhs[0],"logical")) + option=(Option*)OptionLogicalParse(name,prhs); + else if(mxIsClass(prhs[0],"char")) + option=(Option*)OptionCharParse(name,prhs); + else if(mxIsClass(prhs[0],"struct")) + option=(Option*)OptionStructParse(name,prhs); + else if(mxIsClass(prhs[0],"cell")) + option=(Option*)OptionCellParse(name,prhs); + else { + _pprintLine_(" Converting value of option \"" << name << "\" from unrecognized class \"" << mxGetClassName(prhs[0]) << "\" to class \"" << "struct" << "\"."); + if (!mexCallMATLAB(1,lhs,1,(mxArray**)prhs,"struct")) { + option=(Option*)OptionStructParse(name,(const mxArray**)lhs); + mxDestroyArray(lhs[0]); + } + else _error_("Second argument value of option \""<< name <<"\" is of unrecognized class \""<< mxGetClassName(prhs[0]) <<"\"."); + } + + return(option); +}/*}}}*/ Index: ../trunk-jpl/src/wrappers/matlab/io/CheckNumMatlabArguments.cpp =================================================================== --- ../trunk-jpl/src/wrappers/matlab/io/CheckNumMatlabArguments.cpp (revision 0) +++ ../trunk-jpl/src/wrappers/matlab/io/CheckNumMatlabArguments.cpp (revision 13749) @@ -0,0 +1,23 @@ +/*!\file CheckNumMatlabArguments.cpp: + * \brief: check number of arguments and report an usage error message. + */ + +#include "./matlabio.h" +#include "../../c/shared/Exceptions/exceptions.h" + +int CheckNumMatlabArguments(int nlhs,int NLHS, int nrhs,int NRHS, const char* THISFUNCTION, void (*function)( void )){ + + /*checks on arguments on the matlab side: */ + if (nrhs==0 && nlhs==0) { + /*unless NLHS=0 and NRHS=0, we are just asking for documentation: */ + if (NRHS==0 && NLHS==0)return 1; + /* special case: */ + function(); + _error_("usage: see above"); + } + else if (nlhs!=NLHS || nrhs!=NRHS ) { + function(); + _error_("usage error."); + } + return 1; +} Index: ../trunk-jpl/src/wrappers/matlab/io/FetchMatlabData.cpp =================================================================== --- ../trunk-jpl/src/wrappers/matlab/io/FetchMatlabData.cpp (revision 0) +++ ../trunk-jpl/src/wrappers/matlab/io/FetchMatlabData.cpp (revision 13749) @@ -0,0 +1,691 @@ +/*\file FetchData.cpp: + * \brief: general I/O interface to fetch data in matlab + */ + +#ifdef HAVE_CONFIG_H + #include +#else +#error "Cannot compile with HAVE_CONFIG_H symbol! run configure first!" +#endif + +#include "./matlabio.h" +#include "../../c/shared/shared.h" + +/*Primitive data types*/ +/*FUNCTION FetchData(double** pmatrix,int* pM,int *pN,const mxArray* dataref){{{*/ +void FetchData(double** pmatrix,int* pM,int *pN,const mxArray* dataref){ + + double* outmatrix=NULL; + int outmatrix_rows,outmatrix_cols; + + if(mxIsEmpty(dataref) ){ + /*Nothing to pick up. Just initialize matrix pointer to NULL: */ + outmatrix_rows=0; + outmatrix_cols=0; + outmatrix=NULL; + } + else if( mxIsClass(dataref,"double") || + mxIsClass(dataref,"single") || + mxIsClass(dataref,"int16") || + mxIsClass(dataref,"int8") || + mxIsClass(dataref,"uint8")){ + /*Check dataref is not pointing to NaN: */ + if ( mxIsNaN(*(mxGetPr(dataref))) && (mxGetM(dataref)==1) && (mxGetN(dataref)==1) ){ + outmatrix_rows=0; + outmatrix_cols=0; + outmatrix=NULL; + } + else{ + if(!mxIsClass(dataref,"double") && !mxIsClass(dataref,"single")){ + _printLine_("Warning: converting matlab data from '" << mxGetClassName(dataref) << "' to 'double'"); + } + /*Convert matlab matrix to double* matrix: */ + MatlabMatrixToDoubleMatrix(&outmatrix,&outmatrix_rows,&outmatrix_cols,dataref); + } + } + else{ + /*This is an error: we don't have the correct input!: */ + _error_("Input parameter of class " << mxGetClassName(dataref) << " not supported yet"); + } + + /*Assign output pointers:*/ + *pmatrix=outmatrix; + if (pM)*pM=outmatrix_rows; + if (pN)*pN=outmatrix_cols; + +} +/*}}}*/ +/*FUNCTION FetchData(double** pmatrix,int* pnumel,int* pndims,int** psize,const mxArray* dataref){{{*/ +void FetchData(double** pmatrix,int* pnumel,int* pndims,int** psize,const mxArray* dataref){ + + int outmatrix_numel,outmatrix_ndims; + double *outmatrix = NULL; + int *outmatrix_size = NULL; + + if(mxIsEmpty(dataref) ){ + /*Nothing to pick up. Just initialize matrix pointer to NULL: */ + outmatrix_numel = 0; + outmatrix_ndims = 0; + outmatrix_size = NULL; + outmatrix = NULL; + } + else if( mxIsClass(dataref,"double") || + mxIsClass(dataref,"single") || + mxIsClass(dataref,"int16") || + mxIsClass(dataref,"int8") || + mxIsClass(dataref,"uint8")){ + + /*Check dataref is not pointing to NaN: */ + if (mxIsNaN(*(mxGetPr(dataref))) && (mxGetNumberOfElements(dataref)==1)){ + outmatrix_numel = 0; + outmatrix_ndims = 0; + outmatrix_size = NULL; + outmatrix = NULL; + } + else{ + if(!mxIsClass(dataref,"double") && !mxIsClass(dataref,"single")){ + _printLine_("Warning: converting matlab data from '" << mxGetClassName(dataref) << "' to 'double'"); + } + /*Convert matlab n-dim array to double* matrix: */ + MatlabNArrayToNArray(&outmatrix,&outmatrix_numel,&outmatrix_ndims,&outmatrix_size,dataref); + } + } + else{ + /*This is an error: we don't have the correct input!: */ + _error_("Input parameter of class " << mxGetClassName(dataref) << " not supported yet"); + } + + /*Assign output pointers:*/ + *pmatrix=outmatrix; + if (pnumel)*pnumel=outmatrix_numel; + if (pndims)*pndims=outmatrix_ndims; + if (psize )*psize =outmatrix_size; + else xDelete(outmatrix_size); + +} +/*}}}*/ +/*FUNCTION FetchData(int** pmatrix,int* pM,int *pN,const mxArray* dataref){{{*/ +void FetchData(int** pmatrix,int* pM,int *pN,const mxArray* dataref){ + + int i,outmatrix_rows,outmatrix_cols; + double *doublematrix=NULL; + int *outmatrix=NULL; + + if(mxIsEmpty(dataref) ){ + /*Nothing to pick up. Just initialize matrix pointer to NULL: */ + outmatrix_rows=0; + outmatrix_cols=0; + outmatrix=NULL; + } + else if( mxIsClass(dataref,"double") || + mxIsClass(dataref,"single") || + mxIsClass(dataref,"int16") || + mxIsClass(dataref,"int8") || + mxIsClass(dataref,"uint8")){ + + /*Check dataref is not pointing to NaN: */ + if ( mxIsNaN(*(mxGetPr(dataref))) && (mxGetM(dataref)==1) && (mxGetN(dataref)==1) ){ + outmatrix_rows=0; + outmatrix_cols=0; + outmatrix=NULL; + } + else{ + if(!mxIsClass(dataref,"double") && !mxIsClass(dataref,"single")){ + _printLine_("Warning: converting matlab data from '" << mxGetClassName(dataref) << "' to 'double'"); + } + /*Convert matlab matrix to double* matrix: */ + MatlabMatrixToDoubleMatrix(&doublematrix,&outmatrix_rows,&outmatrix_cols,dataref); + + /*Convert double matrix into integer matrix: */ + outmatrix=xNew(outmatrix_rows*outmatrix_cols); + for(i=0;i(outmatrix_rows*outmatrix_cols); + for(i=0;i(outmatrix_numel); + for(i=0;i(doublematrix); + } + } + else{ + /*This is an error: we don't have the correct input!: */ + _error_("Input parameter of class " << mxGetClassName(dataref) << " not supported yet"); + } + + /*Assign output pointers:*/ + *pmatrix=outmatrix; + if (pnumel)*pnumel=outmatrix_numel; + if (pndims)*pndims=outmatrix_ndims; + if (psize )*psize =outmatrix_size; + else xDelete(outmatrix_size); + +} +/*}}}*/ +/*FUNCTION FetchData(double** pvector,int* pM,const mxArray* dataref){{{*/ +void FetchData(double** pvector,int* pM,const mxArray* dataref){ + + double* outvector=NULL; + int outvector_rows; + + if(mxIsEmpty(dataref)){ + /*Nothing to pick up. Just initialize matrix pointer to NULL: */ + outvector_rows=0; + outvector=NULL; + } + else if (mxIsClass(dataref,"double") ){ + + /*Convert matlab vector to double* vector: */ + MatlabVectorToDoubleVector(&outvector,&outvector_rows,dataref); + + } + else{ + /*This is an error: we don't have the correct input!: */ + _error_("Input parameter of class " << mxGetClassName(dataref) << " not supported yet"); + } + + /*Assign output pointers:*/ + *pvector=outvector; + if (pM)*pM=outvector_rows; +} +/*}}}*/ +/*FUNCTION FetchData(int** pvector,int* pM,const mxArray* dataref){{{*/ +void FetchData(int** pvector,int* pM,const mxArray* dataref){ + + int i; + double *doublevector = NULL; + int *outvector = NULL; + int outvector_rows; + + if(mxIsEmpty(dataref)){ + /*Nothing to pick up. Just initialize matrix pointer to NULL: */ + outvector_rows=0; + outvector=NULL; + } + else if (mxIsClass(dataref,"double") ){ + + /*Convert matlab vector to double* vector: */ + MatlabVectorToDoubleVector(&doublevector,&outvector_rows,dataref); + + /*Convert double vector into integer vector: */ + outvector=xNew(outvector_rows); + for(i=0;i(outvector_rows); + for(i=0;i(outvector_rows); + for(i=0;i(stringlen); + mxGetString(dataref,outstring,stringlen); + } + + /*Assign output pointers:*/ + *pstring=outstring; +}/*}}}*/ +/*FUNCTION FetchData(char** pmatrix,int* pnumel,int* pndims,int** psize,const mxArray* dataref){{{*/ +void FetchData(char** pmatrix,int* pnumel,int* pndims,int** psize,const mxArray* dataref){ + + int outmatrix_numel,outmatrix_ndims; + int* outmatrix_size=NULL; + char* outmatrix=NULL; + + if(mxIsEmpty(dataref) ){ + /*Nothing to pick up. Just initialize matrix pointer to NULL: */ + outmatrix_numel=0; + outmatrix_ndims=0; + outmatrix_size =NULL; + outmatrix=NULL; + } + else if (mxIsClass(dataref,"char") ){ + + /*Convert matlab n-dim array to char* matrix: */ + MatlabNArrayToNArray(&outmatrix,&outmatrix_numel,&outmatrix_ndims,&outmatrix_size,dataref); + } + else{ + /*This is an error: we don't have the correct input!: */ + _error_("Input parameter of class " << mxGetClassName(dataref) << " not supported yet"); + } + + /*Assign output pointers:*/ + *pmatrix=outmatrix; + if (pnumel)*pnumel=outmatrix_numel; + if (pndims)*pndims=outmatrix_ndims; + if (psize )*psize =outmatrix_size; + else xDelete(outmatrix_size); + +} +/*}}}*/ +/*FUNCTION FetchData(double* pscalar,const mxArray* dataref){{{*/ +void FetchData(double* pscalar,const mxArray* dataref){ + + double scalar; + + if (!mxIsClass(dataref,"double")){ + _error_("input data_type is not a double!"); + } + else{ + /*Recover the double: */ + scalar=mxGetScalar(dataref); + } + + /*Assign output pointers:*/ + *pscalar=scalar; +} +/*}}}*/ +/*FUNCTION FetchData(int* pinteger,const mxArray* dataref){{{*/ +void FetchData(int* pinteger,const mxArray* dataref){ + + int integer; + + if (!mxIsClass(dataref,"double")){ + _error_("input data_type is not a scalar!"); + } + else{ + /*Recover the double: */ + integer=(int)mxGetScalar(dataref); + } + + /*Assign output pointers:*/ + *pinteger=integer; +} +/*}}}*/ +/*FUNCTION FetchData(bool* pboolean,const mxArray* dataref){{{*/ +void FetchData(bool* pboolean,const mxArray* dataref){ + + bool* mxbool_ptr=NULL; + + if (mxIsClass(dataref,"logical")){ + if(mxGetM(dataref)!=1) _error_("input data is not of size 1x1"); + if(mxGetN(dataref)!=1) _error_("input data is not of size 1x1"); + mxbool_ptr=mxGetLogicals(dataref); + } + else{ + _error_("input data_type is not a bool!"); + } + + *pboolean=*mxbool_ptr; +} +/*}}}*/ + +/*ISSM objects*/ +/*FUNCTION FetchData(Matrix** pmatrix,const mxArray* dataref){{{*/ +void FetchData(Matrix** pmatrix,const mxArray* dataref){ + + Matrix* outmatrix=NULL; + int dummy=0; + + if (mxIsClass(dataref,"double") ){ + + /*Convert matlab matrix to matrix: */ + outmatrix=MatlabMatrixToMatrix(dataref); + + } + else{ + /*This is an error: we don't have the correct input!: */ + _error_("Input parameter of class " << mxGetClassName(dataref) << " not supported yet"); + } + + /*Assign output pointers:*/ + *pmatrix=outmatrix; +} +/*}}}*/ +/*FUNCTION FetchData(Vector** pvector,const mxArray* dataref){{{*/ +void FetchData(Vector** pvector,const mxArray* dataref){ + + Vector* vector=NULL; + int dummy; + + if(mxIsEmpty(dataref)){ + /*Nothing to pick up. Just initialize matrix pointer to NULL: */ + vector=new Vector(0); + } + else if (mxIsClass(dataref,"double") ){ + + /*Convert matlab vector to petsc vector: */ + vector=MatlabVectorToVector(dataref); + } + else{ + /*This is an error: we don't have the correct input!: */ + _error_("Input parameter of class " << mxGetClassName(dataref) << " not supported yet"); + } + + /*Assign output pointers:*/ + *pvector=vector; +} +/*}}}*/ +/*FUNCTION FetchData(BamgGeom** pbamggeom,const mxArray* dataref){{{*/ +void FetchData(BamgGeom** pbamggeom,const mxArray* dataref){ + + /*Initialize output*/ + BamgGeom* bamggeom=new BamgGeom(); + + /*Fetch all fields*/ + FetchData(&bamggeom->Vertices,&bamggeom->VerticesSize[0],&bamggeom->VerticesSize[1],mxGetAssignedField(dataref,0,"Vertices")); + FetchData(&bamggeom->Edges, &bamggeom->EdgesSize[0], &bamggeom->EdgesSize[1], mxGetAssignedField(dataref,0,"Edges")); + FetchData(&bamggeom->Corners, &bamggeom->CornersSize[0], &bamggeom->CornersSize[1], mxGetAssignedField(dataref,0,"Corners")); + FetchData(&bamggeom->RequiredVertices,&bamggeom->RequiredVerticesSize[0],&bamggeom->RequiredVerticesSize[1],mxGetAssignedField(dataref,0,"RequiredVertices")); + FetchData(&bamggeom->RequiredEdges, &bamggeom->RequiredEdgesSize[0], &bamggeom->RequiredEdgesSize[1], mxGetAssignedField(dataref,0,"RequiredEdges")); + FetchData(&bamggeom->CrackedEdges,&bamggeom->CrackedEdgesSize[0],&bamggeom->CrackedEdgesSize[1],mxGetAssignedField(dataref,0,"CrackedEdges")); + FetchData(&bamggeom->SubDomains,&bamggeom->SubDomainsSize[0],&bamggeom->SubDomainsSize[1],mxGetAssignedField(dataref,0,"SubDomains")); + + /*Assign output pointers:*/ + *pbamggeom=bamggeom; +} +/*}}}*/ +/*FUNCTION FetchData(BamgMesh** pbamgmesh,const mxArray* dataref){{{*/ +void FetchData(BamgMesh** pbamgmesh,const mxArray* dataref){ + + /*Initialize output*/ + BamgMesh* bamgmesh=new BamgMesh(); + + /*Fetch all fields*/ + FetchData(&bamgmesh->Vertices,&bamgmesh->VerticesSize[0],&bamgmesh->VerticesSize[1],mxGetAssignedField(dataref,0,"Vertices")); + FetchData(&bamgmesh->Edges, &bamgmesh->EdgesSize[0], &bamgmesh->EdgesSize[1], mxGetAssignedField(dataref,0,"Edges")); + FetchData(&bamgmesh->Triangles, &bamgmesh->TrianglesSize[0], &bamgmesh->TrianglesSize[1], mxGetAssignedField(dataref,0,"Triangles")); + FetchData(&bamgmesh->CrackedEdges,&bamgmesh->CrackedEdgesSize[0],&bamgmesh->CrackedEdgesSize[1],mxGetAssignedField(dataref,0,"CrackedEdges")); + FetchData(&bamgmesh->VerticesOnGeomEdge,&bamgmesh->VerticesOnGeomEdgeSize[0],&bamgmesh->VerticesOnGeomEdgeSize[1],mxGetAssignedField(dataref,0,"VerticesOnGeomEdge")); + FetchData(&bamgmesh->VerticesOnGeomVertex,&bamgmesh->VerticesOnGeomVertexSize[0],&bamgmesh->VerticesOnGeomVertexSize[1],mxGetAssignedField(dataref,0,"VerticesOnGeomVertex")); + FetchData(&bamgmesh->EdgesOnGeomEdge, &bamgmesh->EdgesOnGeomEdgeSize[0], &bamgmesh->EdgesOnGeomEdgeSize[1], mxGetAssignedField(dataref,0,"EdgesOnGeomEdge")); + FetchData(&bamgmesh->IssmSegments,&bamgmesh->IssmSegmentsSize[0],&bamgmesh->IssmSegmentsSize[1],mxGetAssignedField(dataref,0,"IssmSegments")); + + /*Assign output pointers:*/ + *pbamgmesh=bamgmesh; +} +/*}}}*/ +/*FUNCTION FetchData(BamgOpts** pbamgopts,const mxArray* dataref){{{*/ +void FetchData(BamgOpts** pbamgopts,const mxArray* dataref){ + + /*Initialize output*/ + BamgOpts* bamgopts=new BamgOpts(); + + /*Fetch all fields*/ + FetchData(&bamgopts->anisomax,mxGetField(dataref,0,"anisomax")); + FetchData(&bamgopts->cutoff,mxGetField(dataref,0,"cutoff")); + FetchData(&bamgopts->coeff,mxGetField(dataref,0,"coeff")); + FetchData(&bamgopts->errg,mxGetField(dataref,0,"errg")); + FetchData(&bamgopts->gradation,mxGetField(dataref,0,"gradation")); + FetchData(&bamgopts->Hessiantype,mxGetField(dataref,0,"Hessiantype")); + FetchData(&bamgopts->MaxCornerAngle,mxGetField(dataref,0,"MaxCornerAngle")); + FetchData(&bamgopts->maxnbv,mxGetField(dataref,0,"maxnbv")); + FetchData(&bamgopts->maxsubdiv,mxGetField(dataref,0,"maxsubdiv")); + FetchData(&bamgopts->Metrictype,mxGetField(dataref,0,"Metrictype")); + FetchData(&bamgopts->nbjacobi,mxGetField(dataref,0,"nbjacobi")); + FetchData(&bamgopts->nbsmooth,mxGetField(dataref,0,"nbsmooth")); + FetchData(&bamgopts->omega,mxGetField(dataref,0,"omega")); + FetchData(&bamgopts->power,mxGetField(dataref,0,"power")); + FetchData(&bamgopts->verbose,mxGetField(dataref,0,"verbose")); + + FetchData(&bamgopts->Crack,mxGetField(dataref,0,"Crack")); + FetchData(&bamgopts->geometricalmetric,mxGetField(dataref,0,"geometricalmetric")); + FetchData(&bamgopts->KeepVertices,mxGetField(dataref,0,"KeepVertices")); + FetchData(&bamgopts->splitcorners,mxGetField(dataref,0,"splitcorners")); + + FetchData(&bamgopts->hmin,mxGetField(dataref,0,"hmin")); + FetchData(&bamgopts->hmax,mxGetField(dataref,0,"hmax")); + FetchData(&bamgopts->hminVertices,&bamgopts->hminVerticesSize[0],&bamgopts->hminVerticesSize[1],mxGetField(dataref,0,"hminVertices")); + FetchData(&bamgopts->hmaxVertices,&bamgopts->hmaxVerticesSize[0],&bamgopts->hmaxVerticesSize[1],mxGetField(dataref,0,"hmaxVertices")); + FetchData(&bamgopts->hVertices,&bamgopts->hVerticesSize[0],&bamgopts->hVerticesSize[1],mxGetField(dataref,0,"hVertices")); + FetchData(&bamgopts->metric,&bamgopts->metricSize[0],&bamgopts->metricSize[1],mxGetField(dataref,0,"metric")); + FetchData(&bamgopts->field,&bamgopts->fieldSize[0],&bamgopts->fieldSize[1],mxGetField(dataref,0,"field")); + FetchData(&bamgopts->err,&bamgopts->errSize[0],&bamgopts->errSize[1],mxGetField(dataref,0,"err")); + + /*Additional checks*/ + bamgopts->Check(); + + /*Assign output pointers:*/ + *pbamgopts=bamgopts; +} +/*}}}*/ +/*FUNCTION FetchData(Options** poptions,const mxArray** pdataref){{{*/ +void FetchData(Options** poptions,int istart, int nrhs,const mxArray** pdataref){ + + char *name = NULL; + Option *option = NULL; + + /*Initialize output*/ + Options* options=new Options(); + + /*Fetch all options*/ + for (int i=istart; iAddOption(option); + option=NULL; + } + + /*Assign output pointers:*/ + *poptions=options; +} +/*}}}*/ +/*FUNCTION FetchData(DataSet** pcontours,const mxArray* dataref){{{*/ +void FetchData(DataSet** pcontours,const mxArray* dataref){ + + int numcontours,index,test1,test2; + char *contourname = NULL; + DataSet *contours = NULL; + Contour *contouri = NULL; + + if (mxIsClass(dataref,"char")){ + FetchData(&contourname,dataref); + contours=DomainOutlineRead(contourname); + } + else if(mxIsClass(dataref,"struct")){ + + contours=new DataSet(0); + numcontours=mxGetNumberOfElements(dataref); + + for(int i=0;i >(1); + + index = mxGetFieldNumber(dataref,"nods"); + if(index==-1) _error_("input structure does not have a 'nods' field"); + FetchData(&contouri->nods,mxGetFieldByNumber(dataref,i,index)); + + index = mxGetFieldNumber(dataref,"x"); + if(index==-1) _error_("input structure does not have a 'x' field"); + FetchData(&contouri->x,&test1,&test2,mxGetFieldByNumber(dataref,i,index)); + if(test1!=contouri->nods || test2!=1) _error_("field x should be of size ["<nods<<" 1]"); + + index = mxGetFieldNumber(dataref,"y"); + if(index==-1) _error_("input structure does not have a 'y' field"); + FetchData(&contouri->y,&test1,&test2,mxGetFieldByNumber(dataref,i,index)); + if(test1!=contouri->nods || test2!=1) _error_("field y should be of size ["<nods<<" 1]"); + + contours->AddObject(contouri); + } + } + else{ + _error_("Contour is neither a string nor a structure and cannot be loaded ("<(contourname); + *pcontours=contours; +} +/*}}}*/ Index: ../trunk-jpl/src/wrappers/matlab/io/MatlabVectorToDoubleVector.cpp =================================================================== --- ../trunk-jpl/src/wrappers/matlab/io/MatlabVectorToDoubleVector.cpp (revision 0) +++ ../trunk-jpl/src/wrappers/matlab/io/MatlabVectorToDoubleVector.cpp (revision 13749) @@ -0,0 +1,93 @@ +/* \file MatlabVectorToDoubleVector.cpp + * \brief: convert a sparse or dense matlab vector to a serial vector: + */ + +#ifdef HAVE_CONFIG_H + #include +#else +#error "Cannot compile with HAVE_CONFIG_H symbol! run configure first!" +#endif + +#include + +/*Matlab includes: */ +#include "./matlabio.h" +#include "../../c/shared/shared.h" + +int MatlabVectorToDoubleVector(double** pvector,int* pvector_rows,const mxArray* mxvector){ + + int rows,cols; + double* mxvector_ptr=NULL; + int ierr; + int i,j; + + /*output: */ + double* vector=NULL; + + /*matlab indices: */ + mwIndex* ir=NULL; + mwIndex* jc=NULL; + double* pr=NULL; + int count; + int nnz; + int nz; + + /*Ok, first check if we are dealing with a sparse or full vector: */ + if (mxIsSparse(mxvector)){ + + /*Dealing with sparse vector: recover size first: */ + mxvector_ptr=(double*)mxGetPr(mxvector); + rows=mxGetM(mxvector); + cols=mxGetN(mxvector); + nnz=mxGetNzmax(mxvector); + + /*Check that input is actualy a vector*/ + if (cols!=1) _error_("input vector of size " << rows << "x" << cols << " should have only one column"); + + nz=(int)((double)nnz/(double)rows); + + if(rows){ + vector=xNewZeroInit(rows); + + /*Now, get ir,jc and pr: */ + pr=mxGetPr(mxvector); + ir=mxGetIr(mxvector); + jc=mxGetJc(mxvector); + + /*Now, start inserting data into sparse vector: */ + count=0; + for(i=0;i(rows); + memcpy(vector,mxvector_ptr,rows*sizeof(double)); + } + else{ + vector=NULL; + } + } + + /*Assign output pointer: */ + *pvector=vector; + *pvector_rows=rows; + + return 1; +} Index: ../trunk-jpl/src/wrappers/matlab/io/WriteMatlabData.cpp =================================================================== --- ../trunk-jpl/src/wrappers/matlab/io/WriteMatlabData.cpp (revision 0) +++ ../trunk-jpl/src/wrappers/matlab/io/WriteMatlabData.cpp (revision 13749) @@ -0,0 +1,388 @@ +/* \file WriteData.c: + * \brief: general interface for writing data + */ + +#ifdef HAVE_CONFIG_H + #include +#else +#error "Cannot compile with HAVE_CONFIG_H symbol! run configure first!" +#endif + +#include "./matlabio.h" +#include "../../c/shared/shared.h" + +/*Primitive data types*/ +/*FUNCTION WriteData(mxArray** pdataref,double* matrix, int M,int N){{{*/ +void WriteData(mxArray** pdataref,double* matrix, int M,int N){ + + mxArray *dataref = NULL; + double *tmatrix = NULL; + + if(matrix){ + /*create the matlab matrixwith Matlab's memory manager */ + tmatrix=(double*)mxMalloc(M*N*sizeof(double)); + for(int i=0;iVerticesSize[0], bamggeom->VerticesSize[1], bamggeom->Vertices); + i++; SetStructureField(dataref,"Edges", bamggeom->EdgesSize[0], bamggeom->EdgesSize[1], bamggeom->Edges); + i++; SetStructureField(dataref,"TangentAtEdges", bamggeom->TangentAtEdgesSize[0], bamggeom->TangentAtEdgesSize[1], bamggeom->TangentAtEdges); + i++; SetStructureField(dataref,"Corners", bamggeom->CornersSize[0], bamggeom->CornersSize[1], bamggeom->Corners); + i++; SetStructureField(dataref,"RequiredVertices",bamggeom->RequiredVerticesSize[0],bamggeom->RequiredVerticesSize[1],bamggeom->RequiredVertices); + i++; SetStructureField(dataref,"RequiredEdges", bamggeom->RequiredEdgesSize[0], bamggeom->RequiredEdgesSize[1], bamggeom->RequiredEdges); + i++; SetStructureField(dataref,"CrackedEdges", bamggeom->CrackedEdgesSize[0], bamggeom->CrackedEdgesSize[1], bamggeom->CrackedEdges); + i++; SetStructureField(dataref,"SubDomains", bamggeom->SubDomainsSize[0], bamggeom->SubDomainsSize[1], bamggeom->SubDomains); + _assert_(i==numfields); + + /*Assign output*/ + *pdataref=dataref; +} +/*}}}*/ +/*FUNCTION WriteData(mxArray** pdataref,BamgMesh* bamgmesh){{{*/ +void WriteData(mxArray** pdataref,BamgMesh* bamgmesh){ + + /*Intermediary*/ + int i; + mxArray *dataref = NULL; + const int numfields = 16; + const char *fnames[numfields]; + mwSize ndim = 2; + mwSize dimensions[2] = {1,1}; + + /*Initialize field names*/ + i=0; + fnames[i++] = "Vertices"; + fnames[i++] = "Edges"; + fnames[i++] = "Triangles"; + fnames[i++] = "Quadrilaterals"; + fnames[i++] = "IssmEdges"; + fnames[i++] = "IssmSegments"; + fnames[i++] = "VerticesOnGeomVertex"; + fnames[i++] = "VerticesOnGeomEdge"; + fnames[i++] = "EdgesOnGeomEdge"; + fnames[i++] = "SubDomains"; + fnames[i++] = "SubDomainsFromGeom"; + fnames[i++] = "ElementConnectivity"; + fnames[i++] = "NodalConnectivity"; + fnames[i++] = "NodalElementConnectivity"; + fnames[i++] = "CrackedVertices"; + fnames[i++] = "CrackedEdges"; + _assert_(i==numfields); + + /*Initialize Matlab structure*/ + dataref=mxCreateStructArray(ndim,dimensions,numfields,fnames); + + /*set each matlab each field*/ + i=0; + i++; SetStructureField(dataref,"Vertices",bamgmesh->VerticesSize[0], bamgmesh->VerticesSize[1],bamgmesh->Vertices); + i++; SetStructureField(dataref,"Edges", bamgmesh->EdgesSize[0],bamgmesh->EdgesSize[1], bamgmesh->Edges); + i++; SetStructureField(dataref,"Triangles", bamgmesh->TrianglesSize[0],bamgmesh->TrianglesSize[1], bamgmesh->Triangles); + i++; SetStructureField(dataref,"Quadrilaterals",bamgmesh->QuadrilateralsSize[0], bamgmesh->QuadrilateralsSize[1],bamgmesh->Quadrilaterals); + i++; SetStructureField(dataref,"IssmEdges", bamgmesh->IssmEdgesSize[0],bamgmesh->IssmEdgesSize[1], bamgmesh->IssmEdges); + i++; SetStructureField(dataref,"IssmSegments",bamgmesh->IssmSegmentsSize[0], bamgmesh->IssmSegmentsSize[1],bamgmesh->IssmSegments); + i++; SetStructureField(dataref,"VerticesOnGeomVertex",bamgmesh->VerticesOnGeomVertexSize[0],bamgmesh->VerticesOnGeomVertexSize[1], bamgmesh->VerticesOnGeomVertex); + i++; SetStructureField(dataref,"VerticesOnGeomEdge",bamgmesh->VerticesOnGeomEdgeSize[0],bamgmesh->VerticesOnGeomEdgeSize[1], bamgmesh->VerticesOnGeomEdge); + i++; SetStructureField(dataref,"EdgesOnGeomEdge", bamgmesh->EdgesOnGeomEdgeSize[0], bamgmesh->EdgesOnGeomEdgeSize[1],bamgmesh->EdgesOnGeomEdge); + i++; SetStructureField(dataref,"SubDomains",bamgmesh->SubDomainsSize[0], bamgmesh->SubDomainsSize[1],bamgmesh->SubDomains); + i++; SetStructureField(dataref,"SubDomainsFromGeom", bamgmesh->SubDomainsFromGeomSize[0], bamgmesh->SubDomainsFromGeomSize[1],bamgmesh->SubDomainsFromGeom); + i++; SetStructureField(dataref,"ElementConnectivity",bamgmesh->ElementConnectivitySize[0],bamgmesh->ElementConnectivitySize[1], bamgmesh->ElementConnectivity); + i++; SetStructureField(dataref,"NodalConnectivity",bamgmesh->NodalConnectivitySize[0],bamgmesh->NodalConnectivitySize[1], bamgmesh->NodalConnectivity); + i++; SetStructureField(dataref,"NodalElementConnectivity", bamgmesh->NodalElementConnectivitySize[0], bamgmesh->NodalElementConnectivitySize[1],bamgmesh->NodalElementConnectivity); + i++; SetStructureField(dataref,"CrackedVertices", bamgmesh->CrackedVerticesSize[0],bamgmesh->CrackedVerticesSize[1], bamgmesh->CrackedVertices); + i++; SetStructureField(dataref,"CrackedEdges",bamgmesh->CrackedEdgesSize[0], bamgmesh->CrackedEdgesSize[1],bamgmesh->CrackedEdges); + _assert_(i==numfields); + + /*Assign output*/ + *pdataref=dataref; +} +/*}}}*/ +/*FUNCTION WriteData(mxArray** pdataref,SeqMat* matrix){{{*/ +void WriteData(mxArray** pdataref,SeqMat* matrix){ + + int i,j; + int rows,cols; + mxArray *dataref = NULL; + double *matrix_ptr = NULL; + double *tmatrix_ptr = NULL; + + if(matrix){ + + matrix_ptr=matrix->ToSerial(); + matrix->GetSize(&rows,&cols); + + /*Now transpose the matrix and allocate with Matlab's memory manager: */ + tmatrix_ptr=(double*)mxMalloc(rows*cols*sizeof(double)); + for(i=0;i(matrix_ptr); + } + else{ + dataref = mxCreateDoubleMatrix(0,0,mxREAL); + } + + *pdataref=dataref; +} +/*}}}*/ +/*FUNCTION WriteData(mxArray** pdataref,SeqVec* vector){{{*/ +void WriteData(mxArray** pdataref,SeqVec* vector){ + + mxArray* dataref=NULL; + double* vector_ptr=NULL; + double* vector_matlab=NULL; + int rows; + + if(vector){ + /*call toolkit routine: */ + vector_ptr=vector->ToMPISerial(); + vector->GetSize(&rows); + + /*now create the matlab vector with Matlab's memory manager */ + vector_matlab=(double*)mxMalloc(rows*sizeof(double)); + for(int i=0;i(vector_ptr); + *pdataref=dataref; +} +/*}}}*/ +/*FUNCTION WriteData(mxArray** pdataref,RiftStruct* riftstruct){{{*/ +void WriteData(mxArray** pdataref,RiftStruct* riftstruct){ + + /*Intermediary*/ + int i; + mxArray *dataref = NULL; + const int numfields = 10; + const char *fnames[numfields]; + mwSize ndim = 2; + mwSize dimensions[2] = {1,1}; + + /*Initialize field names*/ + i=0; + fnames[i++] = "numsegs"; + fnames[i++] = "segments"; + fnames[i++] = "pairs"; + fnames[i++] = "tips"; + fnames[i++] = "penaltypairs"; + fnames[i++] = "fill"; + fnames[i++] = "friction"; + fnames[i++] = "fraction"; + fnames[i++] = "fractionincrement"; + fnames[i++] = "state"; + _assert_(i==numfields); + + /*Initialize matlab structure of dimension numrifts*/ + dimensions[0]=riftstruct->numrifts; + dataref=mxCreateStructArray(ndim,dimensions,numfields,fnames); + + /*set each matlab each field*/ + for(int i=0;inumrifts;i++){ + SetStructureFieldi(dataref,i,"numsegs" ,riftstruct->riftsnumsegments[i]); + SetStructureFieldi(dataref,i,"segments" ,riftstruct->riftsnumsegments[i] ,3,riftstruct->riftssegments[i]); + SetStructureFieldi(dataref,i,"pairs" ,riftstruct->riftsnumpairs[i] ,2,riftstruct->riftspairs[i]); + SetStructureFieldi(dataref,i,"tips" ,1 ,2,&riftstruct->riftstips[2*i]); + SetStructureFieldi(dataref,i,"penaltypairs" ,riftstruct->riftsnumpenaltypairs[i],7,riftstruct->riftspenaltypairs[i]); + SetStructureFieldi(dataref,i,"fill" ,IceEnum); + SetStructureFieldi(dataref,i,"friction" ,0); + SetStructureFieldi(dataref,i,"fraction" ,0.); + SetStructureFieldi(dataref,i,"fractionincrement",0.1); + SetStructureFieldi(dataref,i,"state" ,riftstruct->riftsnumpenaltypairs[i],1,riftstruct->state[i]); + } + + /*Assign output*/ + *pdataref=dataref; +} +/*}}}*/ + +/*Toolkit*/ +/*FUNCTION SetStructureField{{{*/ +void SetStructureField(mxArray* dataref,const char* fieldname,int M,int N,double* fieldpointer){ + + mxArray* field = NULL; + + /*Convert field*/ + WriteData(&field,fieldpointer,M,N); + + /*Assign to structure*/ + mxSetField(dataref,0,fieldname,field); +} +/*}}}*/ +/*FUNCTION SetStructureFieldi(mxArray* dataref,int i,const char* fieldname,int M,int N,double* fieldpointer){{{*/ +void SetStructureFieldi(mxArray* dataref,int i,const char* fieldname,int M,int N,double* fieldpointer){ + + mxArray* field = NULL; + + /*Convert field*/ + WriteData(&field,fieldpointer,M,N); + + /*Assign to structure*/ + mxSetField(dataref,i,fieldname,field); +} +/*}}}*/ +/*FUNCTION SetStructureFieldi(mxArray* dataref,int i,const char* fieldname,int field){{{*/ +void SetStructureFieldi(mxArray* dataref,int i,const char* fieldname,int fieldin){ + + mxArray* field = NULL; + + /*Convert field*/ + WriteData(&field,fieldin); + + /*Assign to structure*/ + mxSetField(dataref,i,fieldname,field); +} +/*}}}*/ +/*FUNCTION SetStructureFieldi(mxArray* dataref,int i,const char* fieldname,double field){{{*/ +void SetStructureFieldi(mxArray* dataref,int i,const char* fieldname,double fieldin){ + + mxArray* field = NULL; + + /*Convert field*/ + WriteData(&field,fieldin); + + /*Assign to structure*/ + mxSetField(dataref,i,fieldname,field); +} +/*}}}*/ Index: ../trunk-jpl/src/wrappers/matlab/io/mxGetAssignedField.cpp =================================================================== --- ../trunk-jpl/src/wrappers/matlab/io/mxGetAssignedField.cpp (revision 0) +++ ../trunk-jpl/src/wrappers/matlab/io/mxGetAssignedField.cpp (revision 13749) @@ -0,0 +1,39 @@ +/*!\file: mxGetAssignedField.c: + * \brief: abstract interface on parallel side for i/o, so it ressembles the serial i/o. + * + * In serial mode, this routine takes care of returning the field coming + * from the model. If largesize is 1, we are running out of core models in + * matlab, and we need to call the subsref private method from the model object + * in order to correctly load the data from disk. + */ + +#include "./matlabio.h" + +mxArray* mxGetAssignedField(const mxArray* pmxa_array,int number,const char* field){ + + //output + mxArray* mxfield=NULL; + + //input + mxArray *inputs[2]; + mxArray *pindex = NULL; + const char *fnames[2]; + mwSize ndim = 2; + mwSize onebyone[2] = {1,1}; + + //We want to call the subsasgn method, and get the returned array.This ensures that if we are running + //large sized problems, the data is truly loaded from disk by the model subsasgn class method. + inputs[0]=(mxArray*)pmxa_array; //this is the model + + //create index structure used in the assignment (index.type='.' and index.subs='x' for field x for ex) + fnames[0] = "type"; + fnames[1] = "subs"; + pindex=mxCreateStructArray( ndim,onebyone,2,fnames); + mxSetField( pindex, 0, "type",mxCreateString(".")); + mxSetField( pindex, 0, "subs",mxCreateString(field)); + inputs[1]=pindex; + + mexCallMATLAB( 1, &mxfield, 2, (mxArray**)inputs, "subsref"); + + return mxfield; +} Index: ../trunk-jpl/src/wrappers/matlab/io/MatlabMatrixToDoubleMatrix.cpp =================================================================== --- ../trunk-jpl/src/wrappers/matlab/io/MatlabMatrixToDoubleMatrix.cpp (revision 0) +++ ../trunk-jpl/src/wrappers/matlab/io/MatlabMatrixToDoubleMatrix.cpp (revision 13749) @@ -0,0 +1,130 @@ +/* \file MatlabMatrixToDoubleMatrix.cpp + * \brief: convert a sparse or dense matlab matrix to a double* pointer + */ + +#ifdef HAVE_CONFIG_H + #include +#else +#error "Cannot compile with HAVE_CONFIG_H symbol! run configure first!" +#endif + +/*Matlab includes: */ +#include "./matlabio.h" +#include "../../c/shared/shared.h" + +int MatlabMatrixToDoubleMatrix(double** pmatrix,int* pmatrix_rows,int* pmatrix_cols,const mxArray* mxmatrix){ + + int i,j,count,rows,cols; + + /*output: */ + double* matrix=NULL; + + /*matlab indices: */ + mwIndex* ir=NULL; + mwIndex* jc=NULL; + + /*Ok, first check if we are dealing with a sparse or full matrix: */ + if (mxIsSparse(mxmatrix)){ + + /*Dealing with sparse matrix: recover size first: */ + double* pmxmatrix=(double*)mxGetPr(mxmatrix); + rows=mxGetM(mxmatrix); + cols=mxGetN(mxmatrix); + + if(rows*cols){ + matrix=xNewZeroInit(rows*cols); + + /*Now, get ir,jc and pr: */ + ir=mxGetIr(mxmatrix); + jc=mxGetJc(mxmatrix); + + /*Now, start inserting data into double* matrix: */ + count=0; + for(i=0;i(rows*cols); + + for(i=0;i(rows*cols); + + for(i=0;i(rows*cols); + + for(i=0;i(rows*cols); + + for(i=0;i +#else +#error "Cannot compile with HAVE_CONFIG_H symbol! run configure first!" +#endif +#include "../../c/shared/shared.h" + +/*Petsc includes: */ +#include +#include +#include + +/*Matlab includes: */ +#include "./matlabio.h" + +PetscMat* MatlabMatrixToPetscMat(const mxArray* mxmatrix){ + + int dummy; + PetscMat* matrix=new PetscMat(); + + MatlabMatrixToPetscMat(&matrix->matrix, &dummy, &dummy, mxmatrix); + + return matrix; +} +int MatlabMatrixToPetscMat(Mat* pmatrix,int* pmatrix_rows,int* pmatrix_cols,const mxArray* mxmatrix){ + + int rows, cols; + double *mxmatrix_ptr = NULL; + double *tmatrix = NULL; + int ierr; + int i,j; + + /*output: */ + Mat matrix = NULL; + + /*matlab indices: */ + mwIndex *ir = NULL; + mwIndex *jc = NULL; + double *pr = NULL; + int count; + int nnz; + int nz; + + /*petsc indices: */ + int *idxm = NULL; + int *idxn = NULL; + + /*Ok, first check if we are dealing with a sparse or full matrix: */ + if (mxIsSparse(mxmatrix)){ + + /*Dealing with sparse matrix: recover size first: */ + mxmatrix_ptr=(double*)mxGetPr(mxmatrix); + rows=mxGetM(mxmatrix); + cols=mxGetN(mxmatrix); + nnz=mxGetNzmax(mxmatrix); + if(rows){ + nz=(int)((double)nnz/(double)rows); + } + else{ + nz=0; + } + + ierr=MatCreateSeqAIJ(PETSC_COMM_SELF,rows,cols,nz,PETSC_NULL,&matrix);CHKERRQ(ierr); + + /*Now, get ir,jc and pr: */ + pr=mxGetPr(mxmatrix); + ir=mxGetIr(mxmatrix); + jc=mxGetJc(mxmatrix); + + /*Now, start inserting data into sparse matrix: */ + count=0; + for(i=0;i(rows*cols); + for(i=0;i(rows); + idxn=xNew(cols); + + for(i=0;i(tmatrix); + } + + /*Assemble matrix: */ + MatAssemblyBegin(matrix,MAT_FINAL_ASSEMBLY); + MatAssemblyEnd(matrix,MAT_FINAL_ASSEMBLY); + + /*Assign output pointer: */ + *pmatrix=matrix; + if(pmatrix_rows) *pmatrix_rows=rows; + if(pmatrix_cols) *pmatrix_cols=cols; + + return 1; +} Index: ../trunk-jpl/src/wrappers/matlab/io/MatlabVectorToVector.cpp =================================================================== --- ../trunk-jpl/src/wrappers/matlab/io/MatlabVectorToVector.cpp (revision 0) +++ ../trunk-jpl/src/wrappers/matlab/io/MatlabVectorToVector.cpp (revision 13749) @@ -0,0 +1,31 @@ +/*!\file MatlabVectorToVector.cpp + */ + +/*Headers:*/ +#ifdef HAVE_CONFIG_H + #include +#else +#error "Cannot compile with HAVE_CONFIG_H symbol! run configure first!" +#endif +#include +#include +#include "./matlabio.h" +#include "../../c/shared/shared.h" +#include "../../c/toolkits/toolkits.h" + +Vector* MatlabVectorToVector(const mxArray* mxvector){ + + int dummy; + Vector* vector=NULL; + + /*allocate vector object: */ + vector=new Vector(); + + #ifdef _HAVE_PETSC_ + vector->pvector=MatlabVectorToPetscVec(mxvector); + #else + vector->svector=MatlabVectorToSeqVec(mxvector); + #endif + + return vector; +} Index: ../trunk-jpl/src/wrappers/matlab/io/MatlabMatrixToMatrix.cpp =================================================================== --- ../trunk-jpl/src/wrappers/matlab/io/MatlabMatrixToMatrix.cpp (revision 0) +++ ../trunk-jpl/src/wrappers/matlab/io/MatlabMatrixToMatrix.cpp (revision 13749) @@ -0,0 +1,31 @@ +/*!\file MatlabMatrixToMatrix.cpp + */ + +#ifdef HAVE_CONFIG_H + #include +#else +#error "Cannot compile with HAVE_CONFIG_H symbol! run configure first!" +#endif + +#include +#include +#include "./matlabio.h" +#include "../../c/shared/shared.h" +#include "../../c/toolkits/toolkits.h" + +Matrix* MatlabMatrixToMatrix(const mxArray* mxmatrix){ + + int dummy; + Matrix* matrix=NULL; + + /*allocate matrix object: */ + matrix=new Matrix(); + + #ifdef _HAVE_PETSC_ + matrix->pmatrix=MatlabMatrixToPetscMat(mxmatrix); + #else + matrix->smatrix=MatlabMatrixToSeqMat(mxmatrix); + #endif + + return matrix; +} Index: ../trunk-jpl/src/wrappers/matlab/io/MatlabNArrayToNArray.cpp =================================================================== --- ../trunk-jpl/src/wrappers/matlab/io/MatlabNArrayToNArray.cpp (revision 0) +++ ../trunk-jpl/src/wrappers/matlab/io/MatlabNArrayToNArray.cpp (revision 13749) @@ -0,0 +1,250 @@ +/* \file MatlabNArrayToNArray.cpp + * \brief: convert a sparse or dense matlab n-dimensional array to cpp n-dimensional array + */ + +#ifdef HAVE_CONFIG_H + #include +#else +#error "Cannot compile with HAVE_CONFIG_H symbol! run configure first!" +#endif + +#include "./matlabio.h" +#include "../../c/shared/shared.h" +#include "../../c/include/include.h" + +/*FUNCTION MatlabNArrayToNArray(double** pmatrix,int* pmatrix_numel,int* pmatrix_ndims,int** pmatrix_size,const mxArray* mxmatrix){{{*/ +int MatlabNArrayToNArray(double** pmatrix,int* pmatrix_numel,int* pmatrix_ndims,int** pmatrix_size,const mxArray* mxmatrix){ + + int i,j,rows,cols; + int numel,ndims; + int *size,*dims; + double* mxmatrix_ptr=NULL; + const mwSize* ipt=NULL; + + /*output: */ + double* matrix=NULL; + + /*matlab indices: */ + mwIndex *ir = NULL; + mwIndex *jc = NULL; + double *pr = NULL; + int count; + + /*get Matlab matrix information: */ + numel=mxGetNumberOfElements(mxmatrix); + ndims=mxGetNumberOfDimensions(mxmatrix); + ipt =mxGetDimensions(mxmatrix); + size =xNew(ndims); + for (i=0;i(rows*cols); + + /*Now, get ir,jc and pr: */ + ir = mxGetIr(mxmatrix); + jc = mxGetJc(mxmatrix); + pr = mxGetPr(mxmatrix); + + /*Now, start inserting data into double* matrix: */ + count=0; + for(i=0;i(numel); + + dims=xNew(ndims); + for(i=0;i(dims); + } + + /*Assign output pointer: */ + *pmatrix = matrix; + *pmatrix_numel = numel; + *pmatrix_ndims = ndims; + *pmatrix_size = size; + + return 1; +} +/*}}}*/ +/*FUNCTION MatlabNArrayToNArray(bool** pmatrix,int* pmatrix_numel,int* pmatrix_ndims,int** pmatrix_size,const mxArray* mxmatrix){{{*/ +int MatlabNArrayToNArray(bool** pmatrix,int* pmatrix_numel,int* pmatrix_ndims,int** pmatrix_size,const mxArray* mxmatrix){ + + int i,j,rows,cols; + int numel,ndims; + int *size,*dims; + bool* mxmatrix_ptr=NULL; + const mwSize* ipt=NULL; + + /*output: */ + bool* matrix=NULL; + + /*matlab indices: */ + mwIndex *ir = NULL; + mwIndex *jc = NULL; + bool *pm = NULL; + int count; + + /*get Matlab matrix information: */ + numel = mxGetNumberOfElements(mxmatrix); + ndims = mxGetNumberOfDimensions(mxmatrix); + ipt = mxGetDimensions(mxmatrix); + size = xNew(ndims); + for (i=0;i(rows*cols); + + /*Now, get ir,jc and pm: */ + ir=mxGetIr(mxmatrix); + jc=mxGetJc(mxmatrix); + pm=(bool*)mxGetData(mxmatrix); + + /*Now, start inserting data into bool* matrix: */ + count=0; + for(i=0;i(numel); + dims=xNew(ndims); + for(i=0;i(dims); + } + + /*Assign output pointer: */ + *pmatrix = matrix; + *pmatrix_numel = numel; + *pmatrix_ndims = ndims; + *pmatrix_size = size; + + return 1; +} +/*}}}*/ +/*FUNCTION MatlabNArrayToNArray(char** pmatrix,int* pmatrix_numel,int* pmatrix_ndims,int** pmatrix_size,const mxArray* mxmatrix){{{*/ +int MatlabNArrayToNArray(char** pmatrix,int* pmatrix_numel,int* pmatrix_ndims,int** pmatrix_size,const mxArray* mxmatrix){ + + int i,j,rows,cols; + int numel,ndims; + int *size , *dims; + mxChar *mxmatrix_ptr = NULL; + const mwSize *ipt = NULL; + + /*output: */ + char* matrix=NULL; + + /*matlab indices: */ + mwIndex *ir = NULL; + mwIndex *jc = NULL; + char *pm = NULL; + int count; + + /*get Matlab matrix information: */ + numel = mxGetNumberOfElements(mxmatrix); + ndims = mxGetNumberOfDimensions(mxmatrix); + ipt = mxGetDimensions(mxmatrix); + size = xNew(ndims); + for (i=0;i(rows*cols); + + /*Now, get ir,jc and pm: */ + ir = mxGetIr(mxmatrix); + jc = mxGetJc(mxmatrix); + pm = (char*)mxGetData(mxmatrix); + + /*Now, start inserting data into char* matrix: */ + count=0; + for(i=0;i(numel+1); + matrix[numel]='\0'; + + /*looping code adapted from Matlab example explore.c: */ + int elements_per_page = size[0] * size[1]; + /* total_number_of_pages = size[2] x size[3] x ... x size[N-1] */ + int total_number_of_pages = 1; + for (i=2; i +#include +#include +#include "./matlabio.h" +#include "../../c/toolkits/toolkits.h" +#include "../../c/shared/shared.h" + +SeqVec* MatlabVectorToSeqVec(const mxArray* dataref){ + + SeqVec* output=NULL; + + output=new SeqVec(); + MatlabVectorToDoubleVector(&output->vector,&output->M,dataref); + return output; + +} Index: ../trunk-jpl/src/wrappers/matlab/io/matlabio.h =================================================================== --- ../trunk-jpl/src/wrappers/matlab/io/matlabio.h (revision 0) +++ ../trunk-jpl/src/wrappers/matlab/io/matlabio.h (revision 13749) @@ -0,0 +1,93 @@ +/*\file matlabio.h + *\brief: I/O for ISSM in matlab mode + */ + +#ifndef _MATLAB_IO_H_ +#define _MATLAB_IO_H_ + +#ifdef HAVE_CONFIG_H +#include +#else +#error "Cannot compile with HAVE_CONFIG_H symbol! run configure first!" +#endif + +#include "../include/matlabincludes.h" +#include "../../c/classes/classes.h" +#include "../../c/Container/Container.h" +#include "../../c/include/include.h" + +void WriteData(mxArray** pdataref,SeqMat* matrix); +void WriteData(mxArray** pdataref,double* matrix, int M,int N); +void WriteData(mxArray** pdataref,int* matrix, int M,int N); +void WriteData(mxArray** pdataref,SeqVec* vector); +void WriteData(mxArray** pdataref,double* vector, int M); +void WriteData(mxArray** pdataref,int integer); +void WriteData(mxArray** pdataref,bool boolean); +void WriteData(mxArray** pdataref,double scalar); +void WriteData(mxArray** pdataref,char* string); +void WriteData(mxArray** pdataref); +void WriteData(mxArray** pdataref,BamgGeom* bamggeom); +void WriteData(mxArray** pdataref,BamgMesh* bamgmesh); +void WriteData(mxArray** pdataref,RiftStruct* riftstruct); + +void FetchData(double** pmatrix,int* pM,int *pN,const mxArray* dataref); +void FetchData(double** pmatrix,int* pnumel,int* pndims,int** psize,const mxArray* dataref); +void FetchData(int** pmatrix,int* pM,int *pN,const mxArray* dataref); +void FetchData(bool** pmatrix,int* pM,int *pN,const mxArray* dataref); +void FetchData(bool** pmatrix,int* pnumel,int* pndims,int** psize,const mxArray* dataref); +void FetchData(Matrix** pmatrix,const mxArray* dataref); +void FetchData(int** pvector,int* pM,const mxArray* dataref); +void FetchData(float** pvector,int* pM,const mxArray* dataref); +void FetchData(double** pvector,int* pM,const mxArray* dataref); +void FetchData(bool** pvector,int* pM,const mxArray* dataref); +void FetchData(Vector** pvector,const mxArray* dataref); +void FetchData(char** pstring,const mxArray* dataref); +void FetchData(char** pmatrix,int* pnumel,int* pndims,int** psize,const mxArray* dataref); +void FetchData(double* pscalar,const mxArray* dataref); +void FetchData(int* pinteger,const mxArray* dataref); +void FetchData(bool* pbool,const mxArray* dataref); +void FetchData(BamgGeom** bamggeom,const mxArray* dataref); +void FetchData(BamgMesh** bamgmesh,const mxArray* dataref); +void FetchData(BamgOpts** bamgopts,const mxArray* dataref); +void FetchData(Options** poptions,int istart, int nrhs,const mxArray** pdataref); +void FetchData(DataSet** pcontours,const mxArray* dataref); + +Option* OptionParse(char* name, const mxArray* prhs[]); +GenericOption* OptionDoubleParse( char* name, const mxArray* prhs[]); +GenericOption* OptionDoubleArrayParse( char* name, const mxArray* prhs[]); +GenericOption* OptionLogicalParse( char* name, const mxArray* prhs[]); +GenericOption* OptionCharParse( char* name, const mxArray* prhs[]); +GenericOption* OptionStructParse( char* name, const mxArray* prhs[]); +GenericOption* OptionCellParse( char* name, const mxArray* prhs[]); + +mxArray* mxGetAssignedField(const mxArray* pmxa_array,int number, const char* field); +void SetStructureField(mxArray* dataref,const char* fieldname,int fieldrows,int fieldcols,double* fieldpointer); +void SetStructureFieldi(mxArray* dataref,int i,const char* fieldname,int fieldrows,int fieldcols,double* fieldpointer); +void SetStructureFieldi(mxArray* dataref,int i,const char* fieldname,int field); +void SetStructureFieldi(mxArray* dataref,int i,const char* fieldname,double field); +int CheckNumMatlabArguments(int nlhs,int NLHS, int nrhs,int NRHS, const char* THISFUNCTION, void (*function)( void )); + +/*Matlab to Matrix routines: */ +Matrix* MatlabMatrixToMatrix(const mxArray* mxmatrix); +Vector* MatlabVectorToVector(const mxArray* mxvector); + +/*Matlab to double* routines: */ +int MatlabVectorToDoubleVector(double** pvector,int* pvector_rows,const mxArray* mxvector); +int MatlabMatrixToDoubleMatrix(double** pmatrix,int* pmatrix_rows,int* pmatrix_cols,const mxArray* mxmatrix); +int MatlabNArrayToNArray(double** pmatrix,int* pmatrix_numel,int* pmatrix_ndims,int** pmatrix_size,const mxArray* mxmatrix); +int MatlabNArrayToNArray(bool** pmatrix,int* pmatrix_numel,int* pmatrix_ndims,int** pmatrix_size,const mxArray* mxmatrix); +int MatlabNArrayToNArray(char** pmatrix,int* pmatrix_numel,int* pmatrix_ndims,int** pmatrix_size,const mxArray* mxmatrix); + +/*Matlab to SeqMat routines: */ +SeqMat* MatlabMatrixToSeqMat(const mxArray* dataref); +SeqVec* MatlabVectorToSeqVec(const mxArray* dataref); + +/*Matlab to Petsc routines: */ +#ifdef _HAVE_PETSC_ +int MatlabMatrixToPetscMat(Mat* matrix,int* prows,int* pcols, const mxArray* mxmatrix); +PetscMat* MatlabMatrixToPetscMat(const mxArray* mxmatrix); +int MatlabVectorToPetscVec(Vec* pvector,int* pvector_rows,const mxArray* mxvector); +PetscVec* MatlabVectorToPetscVec(const mxArray* mxvector); +#endif + +#endif /* _IO_H_ */ Index: ../trunk-jpl/src/wrappers/matlab/Makefile.am =================================================================== --- ../trunk-jpl/src/wrappers/matlab/Makefile.am (revision 13748) +++ ../trunk-jpl/src/wrappers/matlab/Makefile.am (revision 13749) @@ -1,10 +1,40 @@ -AM_CPPFLAGS = @DAKOTAINCL@ @MATLABINCL@ @PETSCINCL@ @MPIINCL@ @SPOOLESINCL@ @METISINCL@ @TRIANGLEINCL@ @CHACOINCL@ @SCOTCHINCL@ @SHAPELIBINCL@ @BOOSTINCL@ @PYTHONINCL@ @PYTHON_NUMPYINCL@ @ADOLCINCL@ +AM_CPPFLAGS = @DAKOTAINCL@ @MATLABINCL@ @PETSCINCL@ @MPIINCL@ @SPOOLESINCL@ @METISINCL@ @TRIANGLEINCL@ @CHACOINCL@ @SCOTCHINCL@ @SHAPELIBINCL@ EXEEXT=$(MATLABWRAPPEREXT) +#matlab io{{{ +lib_LIBRARIES = libISSMMatlab.a +if SHAREDLIBS +lib_LTLIBRARIES = libISSMMatlab.la +else +lib_LTLIBRARIES = +endif + +io_sources= ./include/matlabincludes.h\ + ./io/matlabio.h\ + ./io/MatlabNArrayToNArray.cpp\ + ./io/CheckNumMatlabArguments.cpp\ + ./io/mxGetAssignedField.cpp\ + ./io/WriteMatlabData.cpp\ + ./io/FetchMatlabData.cpp\ + ./io/OptionParse.cpp\ + ./io/MatlabMatrixToMatrix.cpp\ + ./io/MatlabVectorToVector.cpp\ + ./io/MatlabVectorToDoubleVector.cpp\ + ./io/MatlabMatrixToDoubleMatrix.cpp\ + ./io/MatlabMatrixToSeqMat.cpp\ + ./io/MatlabVectorToSeqVec.cpp + +ALLCXXFLAGS= -fPIC -D_GNU_SOURCE -fno-omit-frame-pointer -pthread -D_CPP_ $(CXXFLAGS) $(CXXOPTFLAGS) +libISSMMatlab_a_SOURCES = $(io_sources) +libISSMMatlab_a_CXXFLAGS= $(ALLCXXFLAGS) +if SHAREDLIBS +libISSMMatlab_la_SOURCES = $(io_sources) +endif +#}}} #Wrappers {{{ if WRAPPERS -lib_LTLIBRARIES = AverageFilter.la\ +lib_LTLIBRARIES += AverageFilter.la\ BamgMesher.la\ BamgConvertMesh.la\ BamgTriangulate.la\ @@ -45,7 +75,6 @@ Kml2Exp.la endif endif - #}}} #Flags and libraries {{{ #if SHAREDLIBS @@ -67,9 +96,9 @@ AM_LDFLAGS += -avoid-version endif if SHAREDLIBS -deps += ../../c/libISSMMatlab.la +deps += ./libISSMMatlab.la else -deps += ../../c/libISSMMatlab.a +deps += ./libISSMMatlab.a AM_LDFLAGS += --no-warnings endif Index: ../trunk-jpl/src/wrappers/BamgTriangulate/BamgTriangulate.h =================================================================== --- ../trunk-jpl/src/wrappers/BamgTriangulate/BamgTriangulate.h (revision 13748) +++ ../trunk-jpl/src/wrappers/BamgTriangulate/BamgTriangulate.h (revision 13749) @@ -20,7 +20,7 @@ #include "../../c/modules/modules.h" #include "../../c/Container/Container.h" #include "../../c/shared/shared.h" -#include "../../c/issm-binding.h" +#include "../bindings.h" #undef __FUNCT__ #define __FUNCT__ "BamgTriangulate" Index: ../trunk-jpl/src/wrappers/InterpFromMeshToMesh2d/InterpFromMeshToMesh2d.h =================================================================== --- ../trunk-jpl/src/wrappers/InterpFromMeshToMesh2d/InterpFromMeshToMesh2d.h (revision 13748) +++ ../trunk-jpl/src/wrappers/InterpFromMeshToMesh2d/InterpFromMeshToMesh2d.h (revision 13749) @@ -23,7 +23,7 @@ #include "../../c/modules/modules.h" #include "../../c/Container/Container.h" #include "../../c/shared/shared.h" -#include "../../c/issm-binding.h" +#include "../bindings.h" #include "../../c/io/io.h" #include "../../c/EnumDefinitions/EnumDefinitions.h" Index: ../trunk-jpl/src/wrappers/ContourToMesh/ContourToMesh.h =================================================================== --- ../trunk-jpl/src/wrappers/ContourToMesh/ContourToMesh.h (revision 13748) +++ ../trunk-jpl/src/wrappers/ContourToMesh/ContourToMesh.h (revision 13749) @@ -23,7 +23,7 @@ #include "../../c/modules/modules.h" #include "../../c/Container/Container.h" #include "../../c/shared/shared.h" -#include "../../c/issm-binding.h" +#include "../bindings.h" #include "../../c/io/io.h" #include "../../c/EnumDefinitions/EnumDefinitions.h" Index: ../trunk-jpl/src/wrappers/Xy2ll/Xy2ll.h =================================================================== --- ../trunk-jpl/src/wrappers/Xy2ll/Xy2ll.h (revision 13748) +++ ../trunk-jpl/src/wrappers/Xy2ll/Xy2ll.h (revision 13749) @@ -20,7 +20,7 @@ #include "../../c/modules/modules.h" #include "../../c/Container/Container.h" #include "../../c/shared/shared.h" -#include "../../c/issm-binding.h" +#include "../bindings.h" #undef __FUNCT__ #define __FUNCT__ "Xy2ll" Index: ../trunk-jpl/src/wrappers/KMLMeshWrite/KMLMeshWrite.h =================================================================== --- ../trunk-jpl/src/wrappers/KMLMeshWrite/KMLMeshWrite.h (revision 13748) +++ ../trunk-jpl/src/wrappers/KMLMeshWrite/KMLMeshWrite.h (revision 13749) @@ -20,7 +20,7 @@ #include "../../c/modules/modules.h" #include "../../c/Container/Container.h" #include "../../c/shared/shared.h" -#include "../../c/issm-binding.h" +#include "../bindings.h" #undef __FUNCT__ #define __FUNCT__ "KMLMeshWrite" Index: ../trunk-jpl/src/wrappers/TriMesh/TriMesh.h =================================================================== --- ../trunk-jpl/src/wrappers/TriMesh/TriMesh.h (revision 13748) +++ ../trunk-jpl/src/wrappers/TriMesh/TriMesh.h (revision 13749) @@ -23,7 +23,7 @@ #include "../../c/modules/modules.h" #include "../../c/Container/Container.h" #include "../../c/shared/shared.h" -#include "../../c/issm-binding.h" +#include "../bindings.h" #include "../../c/io/io.h" #include "../../c/EnumDefinitions/EnumDefinitions.h" Index: ../trunk-jpl/src/wrappers/Chaco/Chaco.h =================================================================== --- ../trunk-jpl/src/wrappers/Chaco/Chaco.h (revision 13748) +++ ../trunk-jpl/src/wrappers/Chaco/Chaco.h (revision 13749) @@ -24,7 +24,7 @@ #include "../../c/modules/modules.h" #include "../../c/Container/Container.h" #include "../../c/shared/shared.h" -#include "../../c/issm-binding.h" +#include "../bindings.h" #undef __FUNCT__ #define __FUNCT__ "Chaco"