source:
issm/oecreview/Archive/13393-13976/ISSM-13748-13749.diff@
14312
Last change on this file since 14312 was 13980, checked in by , 12 years ago | |
---|---|
File size: 234.7 KB |
-
../trunk-jpl/src/c/python/python-binding.h
1 #ifndef _PYTHON_BINDING_H_2 #define _PYTHON_BINDING_H_3 4 #include "./io/pythonio.h"5 #include "./include/python_macros.h"6 7 #endif -
../trunk-jpl/src/c/python/include/python_macros.h
1 /* \file python_macros.h2 * \brief: macros used for the python bindings3 */4 5 #ifndef _PYTHON_MACROS_H_6 #define _PYTHON_MACROS_H_7 8 /*Header {{{*/9 10 #ifdef HAVE_CONFIG_H11 #include <config.h>12 #else13 #error "Cannot compile with HAVE_CONFIG_H symbol! run configure first!"14 #endif15 /*}}}*/16 17 #ifdef _HAVE_PYTHON_18 /* MODULEBOOT/MODULEEND {{{*/19 20 /*The following macros hide the error exception handling in a matlab module. Just put21 * MODULEBOOT(); and MODULEEND(); at the beginning and end of a module, and c++ exceptions22 * will be trapped*/23 #define MODULEBOOT(); \24 PyObject *output = PyTuple_New(NLHS); \25 int nrhs = (int)PyTuple_Size(args); \26 if(!output) return NULL;\27 try{ \28 IssmComm::SetComm(-1);29 30 #define MODULEEND(); }\31 catch(ErrorException &exception){\32 PyErr_SetString(PyExc_TypeError,exception.PythonReport()); \33 return NULL;\34 } \35 catch (exception &e){\36 PyErr_SetString(PyExc_TypeError,exprintf("Standard exception: %s\n",e.what()));\37 return NULL;\38 }\39 catch(...){\40 PyErr_SetString(PyExc_TypeError,"An unexpected error occurred");\41 return NULL;\42 }\43 return output;44 //}}}45 #if _PYTHON_MAJOR_ >=346 /* WRAPPER 3.2 {{{*/47 #define WRAPPER(modulename,...) \48 \49 static PyObject* modulename(PyObject* self,PyObject* args);\50 static PyMethodDef modulename##_funcs[] = {\51 {#modulename, (PyCFunction)modulename, METH_VARARGS, ""},\52 {NULL,NULL,0,NULL}\53 };\54 \55 static struct PyModuleDef modulename##module= {\56 PyModuleDef_HEAD_INIT,\57 #modulename, /* name of module */\58 NULL, /* module documentation, may be NULL */\59 -1, /* size of per-interpreter state of the module,\60 or -1 if the module keeps state in global variables. */\61 modulename##_funcs\62 };\63 \64 PyMODINIT_FUNC PyInit_##modulename(void){\65 \66 import_array();\67 return PyModule_Create(&modulename##module);\68 }\69 \70 static PyObject* modulename(PyObject* self,PyObject* args)71 /*}}}*/72 #else73 /* WRAPPER 2.7 {{{*/74 #define WRAPPER(modulename,...) \75 \76 static PyObject* modulename(PyObject* self,PyObject* args);\77 static PyMethodDef modulename##_funcs[] = {\78 {#modulename, (PyCFunction)modulename, METH_VARARGS, ""},\79 {NULL,NULL,0,NULL}\80 };\81 \82 PyMODINIT_FUNC init##modulename(void){\83 \84 import_array();\85 (void) Py_InitModule(#modulename, modulename##_funcs);\86 }\87 \88 static PyObject* modulename(PyObject* self,PyObject* args)89 /*}}}*/90 #endif91 /* CHECKARGUMENTS {{{*/92 #define CHECKARGUMENTS(NLHS,NRHS,functionpointer) CheckNumPythonArguments(args, NRHS,functionpointer)93 /*}}}*/94 #endif95 96 #endif -
../trunk-jpl/src/c/python/io/pythonio.h
1 /*\file pythonio.h2 *\brief: I/O for ISSM in python mode3 */4 5 #ifndef _PYTHON_IO_H_6 #define _PYTHON_IO_H_7 8 #ifdef HAVE_CONFIG_H9 #include <config.h>10 #else11 #error "Cannot compile with HAVE_CONFIG_H symbol! run configure first!"12 #endif13 14 #include "../../classes/classes.h"15 #include "../../Container/Container.h"16 #include "../../include/include.h"17 18 void WriteData(PyObject* py_tuple,int index, double* matrix, int M,int N);19 void WriteData(PyObject* py_tuple,int index, int integer);20 void WriteData(PyObject* py_tuple,int index, char* string);21 void WriteData(PyObject* py_tuple,int index);22 void WriteData(PyObject* py_tuple,int index, SeqMat<double>* matrix);23 void WriteData(PyObject* py_tuple,int index, SeqVec<double>* vector);24 void WriteData(PyObject* py_tuple,int index, BamgGeom* bamggeom);25 void WriteData(PyObject* py_tuple,int index, BamgMesh* bamgmesh);26 void WriteData(PyObject* py_tuple,int index, RiftStruct* riftstruct);27 28 void FetchData(double** pvector,int* pM,PyObject* py_ref);29 void FetchData(double** pmatrix,int* pM,int *pN,PyObject* py_array);30 void FetchData(int** pmatrix,int* pM,int *pN,PyObject* py_matrix);31 void FetchData(char** pstring,PyObject* py_unicode);32 void FetchData(double* pscalar,PyObject* py_float);33 void FetchData(int* pinteger,PyObject* py_long);34 void FetchData(bool* pbool,PyObject* py_boolean);35 void FetchData(BamgGeom** bamggeom,PyObject* py_dict);36 void FetchData(BamgMesh** bamgmesh,PyObject* py_dict);37 void FetchData(BamgOpts** bamgopts,PyObject* py_dict);38 void FetchData(Options** poptions,int istart, int nrhs,PyObject* py_tuple);39 void FetchData(DataSet** pcontours,PyObject* py_list);40 41 int CheckNumPythonArguments(PyObject* inputs,int NRHS, void (*function)( void ));42 43 #endif /* _IO_H_ */ -
../trunk-jpl/src/c/python/io/CheckNumPythonArguments.cpp
1 /*!\file CheckNumPythonArguments.cpp:2 * \brief: check number of arguments and report an usage error message.3 */4 5 #ifdef HAVE_CONFIG_H6 #include <config.h>7 #else8 #error "Cannot compile with HAVE_CONFIG_H symbol! run configure first!"9 #endif10 11 #define PY_ARRAY_UNIQUE_SYMBOL PythonIOSymbol12 #define NO_IMPORT13 14 #include "../../toolkits/toolkits.h"15 #include "../../shared/Exceptions/exceptions.h"16 #include "../../include/include.h"17 18 int CheckNumPythonArguments(PyObject* inputs,int NRHS, void (*function)( void )){19 20 Py_ssize_t size=0;21 22 /*figure out size of tuple in input: */23 size=PyTuple_Size(inputs);24 25 /*check on requested size: */26 if (size==0){27 function();28 _error_("usage: see above");29 }30 else if (size!=NRHS ) {31 function();32 _error_("usage error.");33 }34 return 1;35 } -
../trunk-jpl/src/c/python/io/FetchPythonData.cpp
1 /*\file FetchData.cpp:2 * \brief: general I/O interface to fetch data in python3 */4 5 #ifdef HAVE_CONFIG_H6 #include <config.h>7 #else8 #error "Cannot compile with HAVE_CONFIG_H symbol! run configure first!"9 #endif10 11 #define PY_ARRAY_UNIQUE_SYMBOL PythonIOSymbol12 #define NO_IMPORT13 14 #include "../../toolkits/toolkits.h"15 #include "../../include/include.h"16 #include "../../shared/shared.h"17 #include "../../io/io.h"18 void FetchData(char** pstring,PyObject* py_string);19 20 /*Primitive data types*/21 /*FUNCTION FetchData(double* pscalar,PyObject* py_float){{{*/22 void FetchData(double* pscalar,PyObject* py_float){23 24 double scalar;25 26 /*return internal value: */27 scalar=PyFloat_AsDouble(py_float);28 29 /*output: */30 *pscalar=scalar;31 }32 /*}}}*/33 /*FUNCTION FetchData(int* pinteger,PyObject* py_long){{{*/34 void FetchData(int* pinteger, PyObject* py_long){35 36 int integer;37 38 /*return internal value: */39 integer=(int)PyLong_AsLong(py_long);40 41 /*output: */42 *pinteger=integer;43 }44 /*}}}*/45 /*FUNCTION FetchData(bool* pboolean,PyObject* py_boolean){{{*/46 void FetchData(bool* pboolean,PyObject* py_boolean){47 48 bool boolean;49 50 /*check this is indeed a subtype of long type: */51 if(!PyBool_Check(py_boolean))_error_("expecting a boolean in input!");52 53 /*extract boolean: */54 boolean=(bool)PyLong_AsLong(py_boolean);55 56 /*simple copy: */57 *pboolean=boolean;58 59 }60 /*}}}*/61 /*FUNCTION FetchData(double** pmatrix,int* pM, int* pN, PyObject* py_matrix){{{*/62 void FetchData(double** pmatrix,int* pM,int *pN,PyObject* py_matrix){63 64 /*output: */65 double* dmatrix=NULL;66 double* matrix=NULL;67 int M,N;68 int ndim;69 npy_intp* dims=NULL;70 71 /*retrive dimensions: */72 ndim=PyArray_NDIM((const PyArrayObject*)py_matrix);73 if(ndim!=2)_error_("expecting an MxN matrix in input!");74 dims=PyArray_DIMS((PyArrayObject*)py_matrix);75 M=dims[0]; N=dims[1];76 77 if (M && N) {78 /*retrieve internal value: */79 dmatrix=(double*)PyArray_DATA((PyArrayObject*)py_matrix);80 81 /*copy matrix: */82 matrix=xNew<double>(M*N);83 memcpy(matrix,dmatrix,(M*N)*sizeof(double));84 }85 else86 matrix=NULL;87 88 /*output: */89 if(pM)*pM=M;90 if(pN)*pN=N;91 if(pmatrix)*pmatrix=matrix;92 }93 /*}}}*/94 /*FUNCTION FetchData(int** pmatrix,int* pM, int* pN, PyObject* py_matrix){{{*/95 void FetchData(int** pmatrix,int* pM,int *pN,PyObject* py_matrix){96 97 /*output: */98 double* dmatrix=NULL;99 int* matrix=NULL;100 int M,N;101 102 /*intermediary:*/103 int i;104 int ndim;105 npy_intp* dims=NULL;106 107 /*retrive dimensions: */108 ndim=PyArray_NDIM((const PyArrayObject*)py_matrix);109 if(ndim!=2)_error_("expecting an MxN matrix in input!");110 dims=PyArray_DIMS((PyArrayObject*)py_matrix);111 M=dims[0]; N=dims[1];112 113 if (M && N) {114 /*retrieve internal value: */115 dmatrix=(double*)PyArray_DATA((PyArrayObject*)py_matrix);116 117 /*transform into integer matrix: */118 matrix=xNew<int>(M*N);119 for(i=0;i<M*N;i++)matrix[i]=(int)dmatrix[i];120 }121 else122 matrix=NULL;123 124 /*output: */125 if(pM)*pM=M;126 if(pN)*pN=N;127 if(pmatrix)*pmatrix=matrix;128 }129 /*}}}*/130 /*FUNCTION FetchData(double** pvector,int* pM, PyObject* py_vector){{{*/131 void FetchData(double** pvector,int* pM,PyObject* py_vector){132 133 /*output: */134 double* dvector=NULL;135 double* vector=NULL;136 int M;137 int ndim;138 npy_intp* dims=NULL;139 140 /*retrive dimensions: */141 ndim=PyArray_NDIM((const PyArrayObject*)py_vector);142 if(ndim!=1)_error_("expecting an Mx1 vector in input!");143 dims=PyArray_DIMS((PyArrayObject*)py_vector);144 M=dims[0];145 146 if (M) {147 /*retrieve internal value: */148 dvector=(double*)PyArray_DATA((PyArrayObject*)py_vector);149 150 /*copy vector: */151 vector=xNew<double>(M);152 memcpy(vector,dvector,(M)*sizeof(double));153 }154 else155 vector=NULL;156 157 /*output: */158 if(pM)*pM=M;159 if(pvector)*pvector=vector;160 }161 /*}}}*/162 163 /*ISSM objects*/164 /*FUNCTION FetchData(BamgGeom** pbamggeom,PyObject* py_dict){{{*/165 void FetchData(BamgGeom** pbamggeom,PyObject* py_dict){166 167 /*Initialize output*/168 BamgGeom* bamggeom=new BamgGeom();169 170 /*Fetch all fields*/171 FetchData(&bamggeom->Vertices,&bamggeom->VerticesSize[0],&bamggeom->VerticesSize[1],PyDict_GetItemString(py_dict,"Vertices"));172 FetchData(&bamggeom->Edges, &bamggeom->EdgesSize[0], &bamggeom->EdgesSize[1], PyDict_GetItemString(py_dict,"Edges"));173 FetchData(&bamggeom->Corners, &bamggeom->CornersSize[0], &bamggeom->CornersSize[1], PyDict_GetItemString(py_dict,"Corners"));174 FetchData(&bamggeom->RequiredVertices,&bamggeom->RequiredVerticesSize[0],&bamggeom->RequiredVerticesSize[1],PyDict_GetItemString(py_dict,"RequiredVertices"));175 FetchData(&bamggeom->RequiredEdges, &bamggeom->RequiredEdgesSize[0], &bamggeom->RequiredEdgesSize[1], PyDict_GetItemString(py_dict,"RequiredEdges"));176 FetchData(&bamggeom->CrackedEdges,&bamggeom->CrackedEdgesSize[0],&bamggeom->CrackedEdgesSize[1],PyDict_GetItemString(py_dict,"CrackedEdges"));177 FetchData(&bamggeom->SubDomains,&bamggeom->SubDomainsSize[0],&bamggeom->SubDomainsSize[1],PyDict_GetItemString(py_dict,"SubDomains"));178 179 /*Assign output pointers:*/180 *pbamggeom=bamggeom;181 }182 /*}}}*/183 /*FUNCTION FetchData(BamgMesh** pbamgmesh,PyObject* py_dict){{{*/184 void FetchData(BamgMesh** pbamgmesh,PyObject* py_dict){185 186 /*Initialize output*/187 BamgMesh* bamgmesh=new BamgMesh();188 189 /*Fetch all fields*/190 FetchData(&bamgmesh->Vertices,&bamgmesh->VerticesSize[0],&bamgmesh->VerticesSize[1],PyDict_GetItemString(py_dict,"Vertices"));191 FetchData(&bamgmesh->Edges, &bamgmesh->EdgesSize[0], &bamgmesh->EdgesSize[1], PyDict_GetItemString(py_dict,"Edges"));192 FetchData(&bamgmesh->Triangles, &bamgmesh->TrianglesSize[0], &bamgmesh->TrianglesSize[1], PyDict_GetItemString(py_dict,"Triangles"));193 FetchData(&bamgmesh->CrackedEdges,&bamgmesh->CrackedEdgesSize[0],&bamgmesh->CrackedEdgesSize[1],PyDict_GetItemString(py_dict,"CrackedEdges"));194 FetchData(&bamgmesh->VerticesOnGeomEdge,&bamgmesh->VerticesOnGeomEdgeSize[0],&bamgmesh->VerticesOnGeomEdgeSize[1],PyDict_GetItemString(py_dict,"VerticesOnGeomEdge"));195 FetchData(&bamgmesh->VerticesOnGeomVertex,&bamgmesh->VerticesOnGeomVertexSize[0],&bamgmesh->VerticesOnGeomVertexSize[1],PyDict_GetItemString(py_dict,"VerticesOnGeomVertex"));196 FetchData(&bamgmesh->EdgesOnGeomEdge, &bamgmesh->EdgesOnGeomEdgeSize[0], &bamgmesh->EdgesOnGeomEdgeSize[1], PyDict_GetItemString(py_dict,"EdgesOnGeomEdge"));197 FetchData(&bamgmesh->IssmSegments,&bamgmesh->IssmSegmentsSize[0],&bamgmesh->IssmSegmentsSize[1],PyDict_GetItemString(py_dict,"IssmSegments"));198 199 /*Assign output pointers:*/200 *pbamgmesh=bamgmesh;201 }202 /*}}}*/203 /*FUNCTION FetchData(BamgOpts** pbamgopts,PyObject* py_dict){{{*/204 void FetchData(BamgOpts** pbamgopts,PyObject* py_dict){205 206 /*Initialize output*/207 BamgOpts* bamgopts=new BamgOpts();208 209 /*Fetch all fields*/210 FetchData(&bamgopts->anisomax,PyDict_GetItemString(py_dict,"anisomax"));211 FetchData(&bamgopts->cutoff,PyDict_GetItemString(py_dict,"cutoff"));212 FetchData(&bamgopts->coeff,PyDict_GetItemString(py_dict,"coeff"));213 FetchData(&bamgopts->errg,PyDict_GetItemString(py_dict,"errg"));214 FetchData(&bamgopts->gradation,PyDict_GetItemString(py_dict,"gradation"));215 FetchData(&bamgopts->Hessiantype,PyDict_GetItemString(py_dict,"Hessiantype"));216 FetchData(&bamgopts->MaxCornerAngle,PyDict_GetItemString(py_dict,"MaxCornerAngle"));217 FetchData(&bamgopts->maxnbv,PyDict_GetItemString(py_dict,"maxnbv"));218 FetchData(&bamgopts->maxsubdiv,PyDict_GetItemString(py_dict,"maxsubdiv"));219 FetchData(&bamgopts->Metrictype,PyDict_GetItemString(py_dict,"Metrictype"));220 FetchData(&bamgopts->nbjacobi,PyDict_GetItemString(py_dict,"nbjacobi"));221 FetchData(&bamgopts->nbsmooth,PyDict_GetItemString(py_dict,"nbsmooth"));222 FetchData(&bamgopts->omega,PyDict_GetItemString(py_dict,"omega"));223 FetchData(&bamgopts->power,PyDict_GetItemString(py_dict,"power"));224 FetchData(&bamgopts->verbose,PyDict_GetItemString(py_dict,"verbose"));225 226 FetchData(&bamgopts->Crack,PyDict_GetItemString(py_dict,"Crack"));227 FetchData(&bamgopts->geometricalmetric,PyDict_GetItemString(py_dict,"geometricalmetric"));228 FetchData(&bamgopts->KeepVertices,PyDict_GetItemString(py_dict,"KeepVertices"));229 FetchData(&bamgopts->splitcorners,PyDict_GetItemString(py_dict,"splitcorners"));230 231 FetchData(&bamgopts->hmin,PyDict_GetItemString(py_dict,"hmin"));232 FetchData(&bamgopts->hmax,PyDict_GetItemString(py_dict,"hmax"));233 FetchData(&bamgopts->hminVertices,&bamgopts->hminVerticesSize[0],&bamgopts->hminVerticesSize[1],PyDict_GetItemString(py_dict,"hminVertices"));234 FetchData(&bamgopts->hmaxVertices,&bamgopts->hmaxVerticesSize[0],&bamgopts->hmaxVerticesSize[1],PyDict_GetItemString(py_dict,"hmaxVertices"));235 FetchData(&bamgopts->hVertices,&bamgopts->hVerticesSize[0],&bamgopts->hVerticesSize[1],PyDict_GetItemString(py_dict,"hVertices"));236 FetchData(&bamgopts->metric,&bamgopts->metricSize[0],&bamgopts->metricSize[1],PyDict_GetItemString(py_dict,"metric"));237 FetchData(&bamgopts->field,&bamgopts->fieldSize[0],&bamgopts->fieldSize[1],PyDict_GetItemString(py_dict,"field"));238 FetchData(&bamgopts->err,&bamgopts->errSize[0],&bamgopts->errSize[1],PyDict_GetItemString(py_dict,"err"));239 240 /*Additional checks*/241 bamgopts->Check();242 243 /*Assign output pointers:*/244 *pbamgopts=bamgopts;245 }246 /*}}}*/247 /*FUNCTION FetchData(Options** poptions,int istart, int nrhs,PyObject* py_tuple){{{*/248 void FetchData(Options** poptions,int istart, int nrhs,PyObject* py_tuple){249 250 char *name = NULL;251 Option *option = NULL;252 253 /*Initialize output*/254 Options* options=new Options();255 256 /*Fetch all options*/257 for (int i=istart; i<nrhs; i=i+2){258 if (!PyString_Check(PyTuple_GetItem(py_tuple,(Py_ssize_t)i))) _error_("Argument " << i+1 << " must be name of option");259 260 FetchData(&name,PyTuple_GetItem(py_tuple,(Py_ssize_t)i));261 if(i+1 == nrhs) _error_("Argument " << i+2 << " must exist and be value of option \"" << name << "\".");262 263 _pprintLine_("FetchData for Options not implemented yet, ignoring option \"" << name << "\"!");264 265 // option=(Option*)OptionParse(name,&PyTuple_GetItem(py_tuple,(Py_ssize_t)(i+1)));266 // options->AddOption(option);267 // option=NULL;268 }269 270 /*Assign output pointers:*/271 *poptions=options;272 }273 /*}}}*/274 /*FUNCTION FetchData(DataSet** pcontours,PyObject* py_list){{{*/275 void FetchData(DataSet** pcontours,PyObject* py_list){276 277 int numcontours,test1,test2;278 char *contourname = NULL;279 DataSet *contours = NULL;280 Contour<double> *contouri = NULL;281 PyObject *py_dicti = NULL;282 PyObject *py_item = NULL;283 284 if (PyString_Check(py_list)){285 FetchData(&contourname,py_list);286 contours=DomainOutlineRead<double>(contourname);287 }288 else if(PyList_Check(py_list)){289 290 contours=new DataSet(0);291 numcontours=(int)PyList_Size(py_list);292 293 for(int i=0;i<numcontours;i++){294 295 contouri=xNew<Contour<double> >(1);296 py_dicti=PyList_GetItem(py_list,(Py_ssize_t)i);297 298 py_item = PyDict_GetItemString(py_dicti,"nods");299 if(!py_item) _error_("input structure does not have a 'nods' field");300 FetchData(&contouri->nods,py_item);301 302 py_item = PyDict_GetItemString(py_dicti,"x");303 if(!py_item) _error_("input structure does not have a 'x' field");304 FetchData(&contouri->x,&test1,&test2,py_item);305 if(test1!=contouri->nods || test2!=1) _error_("field x should be of size ["<<contouri->nods<<" 1]");306 307 py_item = PyDict_GetItemString(py_dicti,"y");308 if(!py_item) _error_("input structure does not have a 'y' field");309 FetchData(&contouri->y,&test1,&test2,py_item);310 if(test1!=contouri->nods || test2!=1) _error_("field y should be of size ["<<contouri->nods<<" 1]");311 312 contours->AddObject(contouri);313 }314 }315 else{316 _error_("Contour is neither a string nor a structure and cannot be loaded");317 }318 319 /*clean-up and assign output pointer*/320 xDelete<char>(contourname);321 *pcontours=contours;322 }323 /*}}}*/324 325 /*Python version dependent: */326 #if _PYTHON_MAJOR_ >= 3327 /*FUNCTION FetchData(char** pstring,PyObject* py_unicode){{{*/328 void FetchData(char** pstring,PyObject* py_unicode){329 330 PyObject* py_bytes;331 char* string=NULL;332 333 /*convert to bytes format: */334 PyUnicode_FSConverter(py_unicode,&py_bytes);335 336 /*convert from bytes to string: */337 string=PyBytes_AS_STRING(py_bytes);338 339 *pstring=string;340 }341 /*}}}*/342 #else343 /*FUNCTION FetchData(char** pstring,PyObject* py_string){{{*/344 void FetchData(char** pstring,PyObject* py_string){345 346 char* string=NULL;347 348 /*extract internal string: */349 string=PyString_AsString(py_string);350 351 /*copy string (note strlen does not include trailing NULL): */352 *pstring=xNew<char>(strlen(string)+1);353 memcpy(*pstring,string,(strlen(string)+1)*sizeof(char));354 }355 /*}}}*/356 #endif -
../trunk-jpl/src/c/python/io/WritePythonData.cpp
1 /* \file WriteData.c:2 * \brief: general interface for writing data3 */4 5 #ifdef HAVE_CONFIG_H6 #include <config.h>7 #else8 #error "Cannot compile with HAVE_CONFIG_H symbol! run configure first!"9 #endif10 11 #define PY_ARRAY_UNIQUE_SYMBOL PythonIOSymbol12 #define NO_IMPORT13 14 #include "../../toolkits/toolkits.h"15 #include "../../include/include.h"16 #include "../../modules/modules.h"17 #include "../../Container/Container.h"18 #include "../../shared/shared.h"19 #include "../../io/io.h"20 #include "../../EnumDefinitions/EnumDefinitions.h"21 PyObject* PyArrayFromCopiedData(int dims[2],double* data);22 PyObject* PyArrayFromCopiedData(int dimi,int dimj,double* data);23 24 /*Primitive data types*/25 /*FUNCTION WriteData(PyObject* py_tuple,int index,int integer){{{*/26 void WriteData(PyObject* py_tuple, int index, int integer){27 28 PyTuple_SetItem(py_tuple, index, PyInt_FromSsize_t((Py_ssize_t)integer));29 30 }/*}}}*/31 /*FUNCTION WriteData(PyObject* py_tuple,int index,char* string){{{*/32 void WriteData(PyObject* py_tuple, int index, char* string){33 34 PyTuple_SetItem(py_tuple, index, PyUnicode_FromString(string));35 36 }/*}}}*/37 /*FUNCTION WriteData(PyObject* py_tuple,int index, double* matrix, int M, int N){{{*/38 void WriteData(PyObject* tuple, int index, double* matrix, int M,int N){39 40 npy_intp dims[2]={0,0};41 PyObject* array=NULL;42 43 dims[0]=(npy_intp)M;44 dims[1]=(npy_intp)N;45 array=PyArray_SimpleNewFromData(2,dims,NPY_DOUBLE,matrix);46 47 PyTuple_SetItem(tuple, index, array);48 }/*}}}*/49 /*FUNCTION WriteData(PyObject* py_tuple,int index){{{*/50 void WriteData(PyObject* py_tuple, int index){51 52 PyTuple_SetItem(py_tuple, index, Py_None);53 54 }/*}}}*/55 56 /*ISSM objects*/57 /*FUNCTION WriteData(PyObject* py_tuple,int index,BamgGeom* bamggeom){{{*/58 void WriteData(PyObject* py_tuple,int index,BamgGeom* bamggeom){59 60 PyObject* dict=NULL;61 62 dict=PyDict_New();63 64 PyDict_SetItemString(dict,"Vertices",PyArrayFromCopiedData(bamggeom->VerticesSize,bamggeom->Vertices));65 PyDict_SetItemString(dict,"Edges",PyArrayFromCopiedData(bamggeom->EdgesSize,bamggeom->Edges));66 PyDict_SetItemString(dict,"TangentAtEdges",PyArrayFromCopiedData(bamggeom->TangentAtEdgesSize,bamggeom->TangentAtEdges));67 PyDict_SetItemString(dict,"Corners",PyArrayFromCopiedData(bamggeom->CornersSize,bamggeom->Corners));68 PyDict_SetItemString(dict,"RequiredVertices",PyArrayFromCopiedData(bamggeom->RequiredVerticesSize,bamggeom->RequiredVertices));69 PyDict_SetItemString(dict,"RequiredEdges",PyArrayFromCopiedData(bamggeom->RequiredEdgesSize,bamggeom->RequiredEdges));70 PyDict_SetItemString(dict,"CrackedEdges",PyArrayFromCopiedData(bamggeom->CrackedEdgesSize,bamggeom->CrackedEdges));71 PyDict_SetItemString(dict,"SubDomains",PyArrayFromCopiedData(bamggeom->SubDomainsSize,bamggeom->SubDomains));72 73 PyTuple_SetItem(py_tuple, index, dict);74 }75 /*}}}*/76 /*FUNCTION WriteData(PyObject* py_tuple,int index,BamgMesh* bamgmesh){{{*/77 void WriteData(PyObject* py_tuple,int index,BamgMesh* bamgmesh){78 79 PyObject* dict=NULL;80 81 dict=PyDict_New();82 83 PyDict_SetItemString(dict,"Vertices",PyArrayFromCopiedData(bamgmesh->VerticesSize,bamgmesh->Vertices));84 PyDict_SetItemString(dict,"Edges",PyArrayFromCopiedData(bamgmesh->EdgesSize,bamgmesh->Edges));85 PyDict_SetItemString(dict,"Triangles",PyArrayFromCopiedData(bamgmesh->TrianglesSize,bamgmesh->Triangles));86 PyDict_SetItemString(dict,"Quadrilaterals",PyArrayFromCopiedData(bamgmesh->QuadrilateralsSize,bamgmesh->Quadrilaterals));87 PyDict_SetItemString(dict,"IssmEdges",PyArrayFromCopiedData(bamgmesh->IssmEdgesSize,bamgmesh->IssmEdges));88 PyDict_SetItemString(dict,"IssmSegments",PyArrayFromCopiedData(bamgmesh->IssmSegmentsSize,bamgmesh->IssmSegments));89 PyDict_SetItemString(dict,"VerticesOnGeomVertex",PyArrayFromCopiedData(bamgmesh->VerticesOnGeomVertexSize,bamgmesh->VerticesOnGeomVertex));90 PyDict_SetItemString(dict,"VerticesOnGeomEdge",PyArrayFromCopiedData(bamgmesh->VerticesOnGeomEdgeSize,bamgmesh->VerticesOnGeomEdge));91 PyDict_SetItemString(dict,"EdgesOnGeomEdge",PyArrayFromCopiedData(bamgmesh->EdgesOnGeomEdgeSize,bamgmesh->EdgesOnGeomEdge));92 PyDict_SetItemString(dict,"SubDomains",PyArrayFromCopiedData(bamgmesh->SubDomainsSize,bamgmesh->SubDomains));93 PyDict_SetItemString(dict,"SubDomainsFromGeom",PyArrayFromCopiedData(bamgmesh->SubDomainsFromGeomSize,bamgmesh->SubDomainsFromGeom));94 PyDict_SetItemString(dict,"ElementConnectivity",PyArrayFromCopiedData(bamgmesh->ElementConnectivitySize,bamgmesh->ElementConnectivity));95 PyDict_SetItemString(dict,"NodalConnectivity",PyArrayFromCopiedData(bamgmesh->NodalConnectivitySize,bamgmesh->NodalConnectivity));96 PyDict_SetItemString(dict,"NodalElementConnectivity",PyArrayFromCopiedData(bamgmesh->NodalElementConnectivitySize,bamgmesh->NodalElementConnectivity));97 PyDict_SetItemString(dict,"CrackedVertices",PyArrayFromCopiedData(bamgmesh->CrackedVerticesSize,bamgmesh->CrackedVertices));98 PyDict_SetItemString(dict,"CrackedEdges",PyArrayFromCopiedData(bamgmesh->CrackedEdgesSize,bamgmesh->CrackedEdges));99 100 PyTuple_SetItem(py_tuple, index, dict);101 }102 /*}}}*/103 /*FUNCTION WriteData(PyObject* py_tuple,int index,SeqMat<double>* matrix){{{*/104 void WriteData(PyObject* py_tuple,int index,SeqMat<double>* matrix){105 106 int M,N;107 double* buffer=NULL;108 npy_intp dims[2]={0,0};109 PyObject* array=NULL;110 111 buffer=matrix->ToSerial();112 matrix->GetSize(&M,&N);113 dims[0]=(npy_intp)M;114 dims[1]=(npy_intp)N;115 array=PyArray_SimpleNewFromData(2,dims,NPY_DOUBLE,buffer);116 117 PyTuple_SetItem(py_tuple, index, array);118 119 }/*}}}*/120 /*FUNCTION WriteData(PyObject* py_tuple,int index,SeqVec<double>* vector){{{*/121 void WriteData(PyObject* py_tuple,int index,SeqVec<double>* vector){122 123 int M;124 double* buffer=NULL;125 npy_intp dim=10;126 PyObject* array=NULL;127 128 buffer=vector->ToMPISerial();129 vector->GetSize(&M);130 dim=(npy_intp)M;131 array=PyArray_SimpleNewFromData(1,&dim,NPY_DOUBLE,buffer);132 133 PyTuple_SetItem(py_tuple, index, array);134 }135 /*}}}*/136 /*FUNCTION WriteData(PyObject* py_tuple,int index,RiftStruct* riftstruct){{{*/137 void WriteData(PyObject* py_tuple,int index,RiftStruct* riftstruct){138 139 int i;140 PyObject* list=NULL;141 PyObject* dict=NULL;142 143 list=PyList_New((Py_ssize_t)0);144 145 for (i=0; i<riftstruct->numrifts; i++) {146 dict=PyDict_New();147 148 PyDict_SetItemString(dict,"numsegs" ,PyInt_FromSsize_t((Py_ssize_t)riftstruct->riftsnumsegments[i]));149 PyDict_SetItemString(dict,"segments" ,PyArrayFromCopiedData(riftstruct->riftsnumsegments[i] ,3,riftstruct->riftssegments[i]));150 PyDict_SetItemString(dict,"pairs" ,PyArrayFromCopiedData(riftstruct->riftsnumpairs[i] ,2,riftstruct->riftspairs[i]));151 PyDict_SetItemString(dict,"tips" ,PyArrayFromCopiedData(1 ,2,&riftstruct->riftstips[2*i]));152 PyDict_SetItemString(dict,"penaltypairs" ,PyArrayFromCopiedData(riftstruct->riftsnumpenaltypairs[i],7,riftstruct->riftspenaltypairs[i]));153 PyDict_SetItemString(dict,"fill" ,PyInt_FromSsize_t((Py_ssize_t)IceEnum));154 PyDict_SetItemString(dict,"friction" ,PyInt_FromSsize_t((Py_ssize_t)0));155 PyDict_SetItemString(dict,"fraction" ,PyFloat_FromDouble(0.));156 PyDict_SetItemString(dict,"fractionincrement",PyFloat_FromDouble(0.1));157 PyDict_SetItemString(dict,"state" ,PyArrayFromCopiedData(riftstruct->riftsnumpenaltypairs[i],1,riftstruct->state[i]));158 159 PyList_Append(list, dict);160 }161 162 PyTuple_SetItem(py_tuple, index, list);163 }164 /*}}}*/165 166 /*Utils*/167 /*FUNCTION PyArrayFromCopiedData(int dims[2],double* data){{{*/168 PyObject* PyArrayFromCopiedData(int dims[2],double* data){169 170 double* pydata;171 npy_intp pydims[2]={0,0};172 173 /* note that PyArray_SimpleNewFromData does not copy the data, so that when the original174 object (e.g. bamggeom,bamgmesh) is deleted, the data is gone. */175 176 pydims[0]=(npy_intp)dims[0];177 pydims[1]=(npy_intp)dims[1];178 pydata=xNew<IssmDouble>(dims[0]*dims[1]);179 memcpy(pydata,data,dims[0]*dims[1]*sizeof(double));180 return PyArray_SimpleNewFromData(2,pydims,NPY_DOUBLE,pydata);181 }182 /*}}}*/183 /*FUNCTION PyArrayFromCopiedData(int dimi,int dimj,double* data){{{*/184 PyObject* PyArrayFromCopiedData(int dimi,int dimj,double* data){185 186 double* pydata;187 npy_intp pydims[2]={0,0};188 189 /* note that PyArray_SimpleNewFromData does not copy the data, so that when the original190 object (e.g. bamggeom,bamgmesh) is deleted, the data is gone. */191 192 pydims[0]=(npy_intp)dimi;193 pydims[1]=(npy_intp)dimj;194 pydata=xNew<IssmDouble>(dimi*dimj);195 memcpy(pydata,data,dimi*dimj*sizeof(double));196 return PyArray_SimpleNewFromData(2,pydims,NPY_DOUBLE,pydata);197 }198 /*}}}*/ -
../trunk-jpl/src/c/issm-binding.h
1 #ifndef _ISSM_BINDING_H_2 #define _ISSM_BINDING_H_3 4 #ifdef HAVE_CONFIG_H5 #include <config.h>6 #else7 #error "Cannot compile with HAVE_CONFIG_H symbol! run configure first!"8 #endif9 10 #ifdef _HAVE_MATLAB_MODULES_11 #include "./matlab/matlab-binding.h"12 #endif13 14 #ifdef _HAVE_PYTHON_MODULES_15 #include "./python/python-binding.h"16 #endif17 18 #endif -
../trunk-jpl/src/c/matlab/include/matlab_macros.h
1 /* \file matlab macros.h2 * \brief: macros used for the matlab bindings3 */4 5 /*Header {{{*/6 #ifndef _MATLAB_MACROS_H_7 #define _MATLAB_MACROS_H_8 9 #ifdef HAVE_CONFIG_H10 #include <config.h>11 #else12 #error "Cannot compile with HAVE_CONFIG_H symbol! run configure first!"13 #endif14 /*}}}*/15 16 #ifdef _HAVE_MATLAB_17 /* MODULEBOOT/MODULEEND {{{*/18 19 /*The following macros hide the error exception handling in a matlab module. Just put20 * MODULEBOOT(); and MODULEEND(); at the beginning and end of a module, and c++ exceptions21 * will be trapped*/22 #define MODULEBOOT(); try{ \23 IssmComm::SetComm(-1);24 25 #define MODULEEND(); }\26 catch(ErrorException &exception){\27 mexErrMsgTxt(exception.MatlabReport()); \28 }\29 catch (exception &e){\30 mexErrMsgTxt(exprintf("Standard exception: %s\n",e.what()));\31 }\32 catch(...){\33 mexErrMsgTxt("An unexpected error occurred");\34 }35 /*}}}*/36 /* WRAPPER {{{*/37 #define WRAPPER(modulename,...) void mexFunction(int nlhs, mxArray* plhs[], int nrhs, const mxArray* prhs[])38 /*}}}*/39 /* CHECKARGUMENTS {{{*/40 #define CHECKARGUMENTS(NLHS,NRHS,functionpointer) CheckNumMatlabArguments(nlhs,NLHS,nrhs,NRHS,__FUNCT__,functionpointer)41 /*}}}*/42 #endif43 44 #endif -
../trunk-jpl/src/c/matlab/io/OptionParse.cpp
1 /*\file OptionParse.c2 *\brief: functions to parse the mex options.3 */4 #ifdef HAVE_CONFIG_H5 #include <config.h>6 #else7 #error "Cannot compile with HAVE_CONFIG_H symbol! run configure first!"8 #endif9 10 #include <cstring>11 #include <mex.h>12 #include "../../shared/shared.h"13 #include "../../io/io.h"14 #include "../../include/include.h"15 #include "./matlabio.h"16 17 GenericOption<double>* OptionDoubleParse( char* name, const mxArray* prhs[]){ /*{{{*/18 19 GenericOption<double> *odouble = NULL;20 21 /*check and parse the name */22 odouble=new GenericOption<double>();23 odouble->name =xNew<char>(strlen(name)+1);24 memcpy(odouble->name,name,(strlen(name)+1)*sizeof(char));25 FetchData(&odouble->value,prhs[0]);26 odouble->numel=1;27 odouble->ndims=1;28 odouble->size=NULL;29 30 return(odouble);31 }/*}}}*/32 GenericOption<double*>* OptionDoubleArrayParse( char* name, const mxArray* prhs[]){ /*{{{*/33 34 GenericOption<double*> *odouble = NULL;35 36 /*check and parse the name */37 odouble=new GenericOption<double*>();38 odouble->name =xNew<char>(strlen(name)+1);39 memcpy(odouble->name,name,(strlen(name)+1)*sizeof(char));40 41 /*check and parse the value */42 if (!mxIsClass(prhs[0],"double")){43 _error_("Value of option \"" << odouble->name << "\" must be class \"double\", not class \"" << mxGetClassName(prhs[0]) <<"\".");44 }45 FetchData(&odouble->value,&odouble->numel,&odouble->ndims,&odouble->size,prhs[0]);46 47 return(odouble);48 }/*}}}*/49 GenericOption<bool*>* OptionLogicalParse( char* name, const mxArray* prhs[]){ /*{{{*/50 51 GenericOption<bool*> *ological = NULL;52 53 /*check and parse the name */54 ological=new GenericOption<bool*>();55 ological->name =xNew<char>(strlen(name)+1);56 memcpy(ological->name,name,(strlen(name)+1)*sizeof(char));57 58 /*check and parse the value */59 if (!mxIsClass(prhs[0],"logical")){60 _error_("Value of option \"" << ological->name << "\" must be class \"logical\", not class \"" << mxGetClassName(prhs[0]) <<"\".");61 }62 FetchData(&ological->value,&ological->numel,&ological->ndims,&ological->size,prhs[0]);63 64 return(ological);65 }/*}}}*/66 GenericOption<char*>* OptionCharParse( char* name, const mxArray* prhs[]){ /*{{{*/67 68 GenericOption<char*> *ochar = NULL;69 70 /*check and parse the name */71 ochar=new GenericOption<char*>();72 ochar->name =xNew<char>(strlen(name)+1);73 memcpy(ochar->name,name,(strlen(name)+1)*sizeof(char));74 75 /*check and parse the value */76 if (!mxIsClass(prhs[0],"char")){77 _error_("Value of option \"" << ochar->name << "\" must be class \"char\", not class \"" << mxGetClassName(prhs[0]) <<"\".");78 }79 FetchData(&ochar->value,&ochar->numel,&ochar->ndims,&ochar->size,prhs[0]);80 81 return(ochar);82 }/*}}}*/83 GenericOption<Options**>* OptionStructParse( char* name, const mxArray* prhs[]){ /*{{{*/84 85 int i;86 char namei[161];87 Option* option = NULL;88 GenericOption<Options**> *ostruct = NULL;89 const mwSize *ipt = NULL;90 const mxArray *structi;91 mwIndex sindex;92 93 /*check and parse the name */94 ostruct=new GenericOption<Options**>();95 ostruct->name =xNew<char>(strlen(name)+1);96 memcpy(ostruct->name,name,(strlen(name)+1)*sizeof(char));97 98 /*check and parse the value */99 if (!mxIsClass(prhs[0],"struct")){100 _error_("Value of option \"" << ostruct->name << "\" must be class \"struct\", not class \"" << mxGetClassName(prhs[0]) <<"\".");101 }102 ostruct->numel=mxGetNumberOfElements(prhs[0]);103 ostruct->ndims=mxGetNumberOfDimensions(prhs[0]);104 ipt =mxGetDimensions(prhs[0]);105 ostruct->size =xNew<int>(ostruct->ndims);106 for (i=0; i<ostruct->ndims; i++) ostruct->size[i]=(int)ipt[i];107 if (ostruct->numel) ostruct->value=xNew<Options*>(ostruct->numel);108 109 /*loop through and process each element of the struct array */110 for (sindex=0; sindex<ostruct->numel; sindex++) {111 ostruct->value[sindex]=new Options;112 113 /*loop through and process each field for the element */114 for (i=0; i<mxGetNumberOfFields(prhs[0]); i++) {115 sprintf(namei,"%s.%s",name,mxGetFieldNameByNumber(prhs[0],i));116 structi=mxGetFieldByNumber(prhs[0],sindex,i);117 118 option=(Option*)OptionParse(namei,&structi);119 ostruct->value[sindex]->AddObject((Object*)option);120 option=NULL;121 }122 }123 124 return(ostruct);125 }/*}}}*/126 GenericOption<Options*>* OptionCellParse( char* name, const mxArray* prhs[]){ /*{{{*/127 128 int i;129 int *dims;130 char namei[161];131 char cstr[81];132 GenericOption<Options*> *ocell = NULL;133 Option *option = NULL;134 const mwSize *ipt = NULL;135 const mxArray *celli;136 mwIndex cindex;137 138 /*check and parse the name */139 ocell=new GenericOption<Options*>();140 ocell->name =xNew<char>(strlen(name)+1);141 memcpy(ocell->name,name,(strlen(name)+1)*sizeof(char));142 143 /*check and parse the value */144 if (!mxIsClass(prhs[0],"cell")){145 _error_("Value of option \"" << ocell->name << "\" must be class \"cell\", not class \"" << mxGetClassName(prhs[0]) <<"\".");146 }147 148 ocell->numel=mxGetNumberOfElements(prhs[0]);149 ocell->ndims=mxGetNumberOfDimensions(prhs[0]);150 ipt =mxGetDimensions(prhs[0]);151 ocell->size =xNew<int>(ocell->ndims);152 for (i=0; i<ocell->ndims; i++) ocell->size[i]=(int)ipt[i];153 ocell->value=new Options;154 155 /*loop through and process each element of the cell array */156 dims=xNew<int>(ocell->ndims);157 for (cindex=0; cindex<ocell->numel; cindex++) {158 ColumnWiseDimsFromIndex(dims,(int)cindex,ocell->size,ocell->ndims);159 StringFromDims(cstr,dims,ocell->ndims);160 #ifdef _INTEL_WIN_161 _snprintf(namei,161,"%s%s",name,cstr);162 #else163 snprintf(namei,161,"%s%s",name,cstr);164 #endif165 celli=mxGetCell(prhs[0],cindex);166 167 option=(Option*)OptionParse(namei,&celli);168 ocell->value->AddObject((Object*)option);169 option=NULL;170 }171 xDelete<int>(dims);172 173 return(ocell);174 }/*}}}*/175 Option* OptionParse(char* name, const mxArray* prhs[]){ /*{{{*/176 177 Option *option = NULL;178 mxArray *lhs[1];179 180 /*parse the value according to the matlab data type */181 if (mxIsClass(prhs[0],"double") && (mxGetNumberOfElements(prhs[0])==1))182 option=(Option*)OptionDoubleParse(name,prhs);183 else if(mxIsClass(prhs[0],"double") && (mxGetNumberOfElements(prhs[0])!=1))184 option=(Option*)OptionDoubleArrayParse(name,prhs);185 else if(mxIsClass(prhs[0],"logical"))186 option=(Option*)OptionLogicalParse(name,prhs);187 else if(mxIsClass(prhs[0],"char"))188 option=(Option*)OptionCharParse(name,prhs);189 else if(mxIsClass(prhs[0],"struct"))190 option=(Option*)OptionStructParse(name,prhs);191 else if(mxIsClass(prhs[0],"cell"))192 option=(Option*)OptionCellParse(name,prhs);193 else {194 _pprintLine_(" Converting value of option \"" << name << "\" from unrecognized class \"" << mxGetClassName(prhs[0]) << "\" to class \"" << "struct" << "\".");195 if (!mexCallMATLAB(1,lhs,1,(mxArray**)prhs,"struct")) {196 option=(Option*)OptionStructParse(name,(const mxArray**)lhs);197 mxDestroyArray(lhs[0]);198 }199 else _error_("Second argument value of option \""<< name <<"\" is of unrecognized class \""<< mxGetClassName(prhs[0]) <<"\".");200 }201 202 return(option);203 }/*}}}*/ -
../trunk-jpl/src/c/matlab/io/MatlabMatrixToSeqMat.cpp
1 /*!\file MatlabMatrixToSeqMat.cpp2 */3 4 /*Headers:*/5 /*{{{*/6 #ifdef HAVE_CONFIG_H7 #include <config.h>8 #else9 #error "Cannot compile with HAVE_CONFIG_H symbol! run configure first!"10 #endif11 12 #include <mex.h>13 #include <stdio.h>14 #include <string.h>15 #include "../../toolkits/toolkits.h"16 #include "../../shared/shared.h"17 #include "./matlabio.h"18 19 /*}}}*/20 21 SeqMat<double>* MatlabMatrixToSeqMat(const mxArray* dataref){22 23 SeqMat<double>* output=NULL;24 25 output=new SeqMat<double>();26 MatlabMatrixToDoubleMatrix(&output->matrix,&output->M,&output->N,dataref);27 return output;28 29 } -
../trunk-jpl/src/c/matlab/io/MatlabVectorToPetscVec.cpp
1 /* \file MatlabVectorToPetscVector.cpp2 * \brief: convert a sparse or dense matlab vector to a serial Petsc vector:3 */4 5 #ifdef HAVE_CONFIG_H6 #include <config.h>7 #else8 #error "Cannot compile with HAVE_CONFIG_H symbol! run configure first!"9 #endif10 11 /*Petsc includes: */12 #include "petscmat.h"13 #include "petscvec.h"14 #include "petscksp.h"15 16 /*Matlab includes: */17 #include "mex.h"18 19 #include "../../shared/shared.h"20 #include "matlabio.h"21 22 PetscVec* MatlabVectorToPetscVec(const mxArray* mxvector){23 24 int dummy;25 PetscVec* vector=new PetscVec();26 27 MatlabVectorToPetscVec(&vector->vector,&dummy, mxvector);28 29 return vector;30 }31 32 int MatlabVectorToPetscVec(Vec* pvector,int* pvector_rows,const mxArray* mxvector){33 34 int rows, cols;35 double* mxvector_ptr=NULL;36 int ierr;37 int i,j;38 39 /*output: */40 Vec vector=NULL;41 42 /*matlab indices: */43 mwIndex* ir=NULL;44 mwIndex* jc=NULL;45 double* pr=NULL;46 int count;47 int nnz;48 int nz;49 50 /*petsc indices: */51 int* idxm=NULL;52 53 /*Ok, first check if we are dealing with a sparse or full vector: */54 if (mxIsSparse(mxvector)){55 56 /*Dealing with sparse vector: recover size first: */57 mxvector_ptr=(double*)mxGetPr(mxvector);58 rows=mxGetM(mxvector);59 cols=mxGetN(mxvector);60 nnz=mxGetNzmax(mxvector);61 nz=(int)((double)nnz/(double)rows);62 63 ierr=VecCreateSeq(PETSC_COMM_SELF,rows,&vector);CHKERRQ(ierr);64 65 /*Now, get ir,jc and pr: */66 pr=mxGetPr(mxvector);67 ir=mxGetIr(mxvector);68 jc=mxGetJc(mxvector);69 70 /*Now, start inserting data into sparse vector: */71 count=0;72 for(i=0;i<cols;i++){73 for(j=0;j<(jc[i+1]-jc[i]);j++){74 VecSetValue(vector,ir[count],pr[count],INSERT_VALUES);75 count++;76 }77 }78 79 }80 else{81 82 /*Dealing with dense vector: recover pointer and size: */83 mxvector_ptr=(double*)mxGetPr(mxvector);84 rows=mxGetM(mxvector);85 cols=mxGetN(mxvector);86 87 /*Create serial vector: */88 ierr=VecCreateSeq(PETSC_COMM_SELF,rows,&vector);CHKERRQ(ierr);89 90 /*Insert mxvector_ptr values into petsc vector: */91 idxm=xNew<int>(rows);92 93 for(i=0;i<rows;i++)idxm[i]=i;94 95 ierr=VecSetValues(vector,rows,idxm,mxvector_ptr,INSERT_VALUES);CHKERRQ(ierr);96 97 }98 99 /*Assemble vector: */100 VecAssemblyBegin(vector);101 VecAssemblyEnd(vector);102 103 /*Assign output pointer: */104 *pvector=vector;105 *pvector_rows=rows;106 107 return 1;108 } -
../trunk-jpl/src/c/matlab/io/MatlabVectorToDoubleVector.cpp
1 /* \file MatlabVectorToDoubleVector.cpp2 * \brief: convert a sparse or dense matlab vector to a serial vector:3 */4 5 #ifdef HAVE_CONFIG_H6 #include <config.h>7 #else8 #error "Cannot compile with HAVE_CONFIG_H symbol! run configure first!"9 #endif10 11 #include <string.h>12 13 /*Matlab includes: */14 #include "mex.h"15 16 #include "../../shared/shared.h"17 18 int MatlabVectorToDoubleVector(double** pvector,int* pvector_rows,const mxArray* mxvector){19 20 int rows,cols;21 double* mxvector_ptr=NULL;22 int ierr;23 int i,j;24 25 /*output: */26 double* vector=NULL;27 28 /*matlab indices: */29 mwIndex* ir=NULL;30 mwIndex* jc=NULL;31 double* pr=NULL;32 int count;33 int nnz;34 int nz;35 36 /*Ok, first check if we are dealing with a sparse or full vector: */37 if (mxIsSparse(mxvector)){38 39 /*Dealing with sparse vector: recover size first: */40 mxvector_ptr=(double*)mxGetPr(mxvector);41 rows=mxGetM(mxvector);42 cols=mxGetN(mxvector);43 nnz=mxGetNzmax(mxvector);44 45 /*Check that input is actualy a vector*/46 if (cols!=1) _error_("input vector of size " << rows << "x" << cols << " should have only one column");47 48 nz=(int)((double)nnz/(double)rows);49 50 if(rows){51 vector=xNewZeroInit<double>(rows);52 53 /*Now, get ir,jc and pr: */54 pr=mxGetPr(mxvector);55 ir=mxGetIr(mxvector);56 jc=mxGetJc(mxvector);57 58 /*Now, start inserting data into sparse vector: */59 count=0;60 for(i=0;i<cols;i++){61 for(j=0;j<(jc[i+1]-jc[i]);j++){62 vector[ir[count]]=pr[count];63 count++;64 }65 }66 }67 68 }69 else{70 71 /*Dealing with dense vector: recover pointer and size: */72 mxvector_ptr=(double*)mxGetPr(mxvector);73 rows=mxGetM(mxvector);74 cols=mxGetN(mxvector);75 76 /*Check that input is actualy a vector*/77 if (cols!=1) _error_("input vector of size " << rows << "x" << cols << " should have only one column");78 79 /*allocate and memcpy*/80 if(rows){81 vector=xNew<double>(rows);82 memcpy(vector,mxvector_ptr,rows*sizeof(double));83 }84 else{85 vector=NULL;86 }87 }88 89 /*Assign output pointer: */90 *pvector=vector;91 *pvector_rows=rows;92 93 return 1;94 } -
../trunk-jpl/src/c/matlab/io/FetchMatlabData.cpp
1 /*\file FetchData.cpp:2 * \brief: general I/O interface to fetch data in matlab3 */4 5 #ifdef HAVE_CONFIG_H6 #include <config.h>7 #else8 #error "Cannot compile with HAVE_CONFIG_H symbol! run configure first!"9 #endif10 11 #include <mex.h>12 #include "../../shared/shared.h"13 #include "../../include/include.h"14 #include "./matlabio.h"15 16 /*Primitive data types*/17 /*FUNCTION FetchData(double** pmatrix,int* pM,int *pN,const mxArray* dataref){{{*/18 void FetchData(double** pmatrix,int* pM,int *pN,const mxArray* dataref){19 20 double* outmatrix=NULL;21 int outmatrix_rows,outmatrix_cols;22 23 if(mxIsEmpty(dataref) ){24 /*Nothing to pick up. Just initialize matrix pointer to NULL: */25 outmatrix_rows=0;26 outmatrix_cols=0;27 outmatrix=NULL;28 }29 else if( mxIsClass(dataref,"double") ||30 mxIsClass(dataref,"single") ||31 mxIsClass(dataref,"int16") ||32 mxIsClass(dataref,"int8") ||33 mxIsClass(dataref,"uint8")){34 /*Check dataref is not pointing to NaN: */35 if ( mxIsNaN(*(mxGetPr(dataref))) && (mxGetM(dataref)==1) && (mxGetN(dataref)==1) ){36 outmatrix_rows=0;37 outmatrix_cols=0;38 outmatrix=NULL;39 }40 else{41 if(!mxIsClass(dataref,"double") && !mxIsClass(dataref,"single")){42 _printLine_("Warning: converting matlab data from '" << mxGetClassName(dataref) << "' to 'double'");43 }44 /*Convert matlab matrix to double* matrix: */45 MatlabMatrixToDoubleMatrix(&outmatrix,&outmatrix_rows,&outmatrix_cols,dataref);46 }47 }48 else{49 /*This is an error: we don't have the correct input!: */50 _error_("Input parameter of class " << mxGetClassName(dataref) << " not supported yet");51 }52 53 /*Assign output pointers:*/54 *pmatrix=outmatrix;55 if (pM)*pM=outmatrix_rows;56 if (pN)*pN=outmatrix_cols;57 58 }59 /*}}}*/60 /*FUNCTION FetchData(double** pmatrix,int* pnumel,int* pndims,int** psize,const mxArray* dataref){{{*/61 void FetchData(double** pmatrix,int* pnumel,int* pndims,int** psize,const mxArray* dataref){62 63 int outmatrix_numel,outmatrix_ndims;64 double *outmatrix = NULL;65 int *outmatrix_size = NULL;66 67 if(mxIsEmpty(dataref) ){68 /*Nothing to pick up. Just initialize matrix pointer to NULL: */69 outmatrix_numel = 0;70 outmatrix_ndims = 0;71 outmatrix_size = NULL;72 outmatrix = NULL;73 }74 else if( mxIsClass(dataref,"double") ||75 mxIsClass(dataref,"single") ||76 mxIsClass(dataref,"int16") ||77 mxIsClass(dataref,"int8") ||78 mxIsClass(dataref,"uint8")){79 80 /*Check dataref is not pointing to NaN: */81 if (mxIsNaN(*(mxGetPr(dataref))) && (mxGetNumberOfElements(dataref)==1)){82 outmatrix_numel = 0;83 outmatrix_ndims = 0;84 outmatrix_size = NULL;85 outmatrix = NULL;86 }87 else{88 if(!mxIsClass(dataref,"double") && !mxIsClass(dataref,"single")){89 _printLine_("Warning: converting matlab data from '" << mxGetClassName(dataref) << "' to 'double'");90 }91 /*Convert matlab n-dim array to double* matrix: */92 MatlabNArrayToNArray(&outmatrix,&outmatrix_numel,&outmatrix_ndims,&outmatrix_size,dataref);93 }94 }95 else{96 /*This is an error: we don't have the correct input!: */97 _error_("Input parameter of class " << mxGetClassName(dataref) << " not supported yet");98 }99 100 /*Assign output pointers:*/101 *pmatrix=outmatrix;102 if (pnumel)*pnumel=outmatrix_numel;103 if (pndims)*pndims=outmatrix_ndims;104 if (psize )*psize =outmatrix_size;105 else xDelete<int>(outmatrix_size);106 107 }108 /*}}}*/109 /*FUNCTION FetchData(int** pmatrix,int* pM,int *pN,const mxArray* dataref){{{*/110 void FetchData(int** pmatrix,int* pM,int *pN,const mxArray* dataref){111 112 int i,outmatrix_rows,outmatrix_cols;113 double *doublematrix=NULL;114 int *outmatrix=NULL;115 116 if(mxIsEmpty(dataref) ){117 /*Nothing to pick up. Just initialize matrix pointer to NULL: */118 outmatrix_rows=0;119 outmatrix_cols=0;120 outmatrix=NULL;121 }122 else if( mxIsClass(dataref,"double") ||123 mxIsClass(dataref,"single") ||124 mxIsClass(dataref,"int16") ||125 mxIsClass(dataref,"int8") ||126 mxIsClass(dataref,"uint8")){127 128 /*Check dataref is not pointing to NaN: */129 if ( mxIsNaN(*(mxGetPr(dataref))) && (mxGetM(dataref)==1) && (mxGetN(dataref)==1) ){130 outmatrix_rows=0;131 outmatrix_cols=0;132 outmatrix=NULL;133 }134 else{135 if(!mxIsClass(dataref,"double") && !mxIsClass(dataref,"single")){136 _printLine_("Warning: converting matlab data from '" << mxGetClassName(dataref) << "' to 'double'");137 }138 /*Convert matlab matrix to double* matrix: */139 MatlabMatrixToDoubleMatrix(&doublematrix,&outmatrix_rows,&outmatrix_cols,dataref);140 141 /*Convert double matrix into integer matrix: */142 outmatrix=xNew<int>(outmatrix_rows*outmatrix_cols);143 for(i=0;i<outmatrix_rows*outmatrix_cols;i++)outmatrix[i]=(int)doublematrix[i];144 }145 }146 else{147 /*This is an error: we don't have the correct input!: */148 _error_("Input parameter of class " << mxGetClassName(dataref) << " not supported yet");149 }150 151 /*Assign output pointers:*/152 *pmatrix=outmatrix;153 if (pM)*pM=outmatrix_rows;154 if (pN)*pN=outmatrix_cols;155 }156 /*}}}*/157 /*FUNCTION FetchData(bool** pmatrix,int* pM,int *pN,const mxArray* dataref){{{*/158 void FetchData(bool** pmatrix,int* pM,int *pN,const mxArray* dataref){159 160 int i,outmatrix_rows,outmatrix_cols;161 double *doublematrix=NULL;162 bool *outmatrix=NULL;163 164 if(mxIsEmpty(dataref) ){165 /*Nothing to pick up. Just initialize matrix pointer to NULL: */166 outmatrix_rows=0;167 outmatrix_cols=0;168 outmatrix=NULL;169 }170 else if (mxIsClass(dataref,"double") ){171 172 /*Check dataref is not pointing to NaN: */173 if ( mxIsNaN(*(mxGetPr(dataref))) && (mxGetM(dataref)==1) && (mxGetN(dataref)==1) ){174 outmatrix_rows=0;175 outmatrix_cols=0;176 outmatrix=NULL;177 }178 else{179 180 /*Convert matlab matrix to double* matrix: */181 MatlabMatrixToDoubleMatrix(&doublematrix,&outmatrix_rows,&outmatrix_cols,dataref);182 183 /*Convert double matrix into integer matrix: */184 outmatrix=xNew<bool>(outmatrix_rows*outmatrix_cols);185 for(i=0;i<outmatrix_rows;i++)outmatrix[i]=(bool)doublematrix[i];186 }187 }188 else{189 /*This is an error: we don't have the correct input!: */190 _error_("Input parameter of class " << mxGetClassName(dataref) << " not supported yet");191 }192 193 /*Assign output pointers:*/194 *pmatrix=outmatrix;195 if (pM)*pM=outmatrix_rows;196 if (pN)*pN=outmatrix_cols;197 }198 /*}}}*/199 /*FUNCTION FetchData(bool** pmatrix,int* pnumel,int* pndims,int** psize,const mxArray* dataref){{{*/200 void FetchData(bool** pmatrix,int* pnumel,int* pndims,int** psize,const mxArray* dataref){201 202 int i;203 int outmatrix_numel,outmatrix_ndims;204 int* outmatrix_size=NULL;205 double* doublematrix=NULL;206 bool* outmatrix=NULL;207 208 if(mxIsEmpty(dataref) ){209 /*Nothing to pick up. Just initialize matrix pointer to NULL: */210 outmatrix_numel=0;211 outmatrix_ndims=0;212 outmatrix_size =NULL;213 outmatrix=NULL;214 }215 else if (mxIsClass(dataref,"logical") ){216 217 /*Check dataref is not pointing to NaN: */218 if ( mxIsNaN(*((bool*)mxGetData(dataref))) && (mxGetNumberOfElements(dataref)==1) ){219 outmatrix_numel=0;220 outmatrix_ndims=0;221 outmatrix_size =NULL;222 outmatrix=NULL;223 }224 else{225 226 /*Convert matlab n-dim array to bool* matrix: */227 MatlabNArrayToNArray(&outmatrix,&outmatrix_numel,&outmatrix_ndims,&outmatrix_size,dataref);228 }229 }230 else if (mxIsClass(dataref,"double") ){231 232 /*Check dataref is not pointing to NaN: */233 if ( mxIsNaN(*(mxGetPr(dataref))) && (mxGetNumberOfElements(dataref)==1) ){234 outmatrix_numel=0;235 outmatrix_ndims=0;236 outmatrix_size =NULL;237 outmatrix=NULL;238 }239 else{240 241 /*Convert matlab n-dim array to double* matrix: */242 MatlabNArrayToNArray(&doublematrix,&outmatrix_numel,&outmatrix_ndims,&outmatrix_size,dataref);243 244 /*Convert double matrix into bool matrix: */245 outmatrix=xNew<bool>(outmatrix_numel);246 for(i=0;i<outmatrix_numel;i++)outmatrix[i]=(bool)doublematrix[i];247 xDelete<double>(doublematrix);248 }249 }250 else{251 /*This is an error: we don't have the correct input!: */252 _error_("Input parameter of class " << mxGetClassName(dataref) << " not supported yet");253 }254 255 /*Assign output pointers:*/256 *pmatrix=outmatrix;257 if (pnumel)*pnumel=outmatrix_numel;258 if (pndims)*pndims=outmatrix_ndims;259 if (psize )*psize =outmatrix_size;260 else xDelete<int>(outmatrix_size);261 262 }263 /*}}}*/264 /*FUNCTION FetchData(double** pvector,int* pM,const mxArray* dataref){{{*/265 void FetchData(double** pvector,int* pM,const mxArray* dataref){266 267 double* outvector=NULL;268 int outvector_rows;269 270 if(mxIsEmpty(dataref)){271 /*Nothing to pick up. Just initialize matrix pointer to NULL: */272 outvector_rows=0;273 outvector=NULL;274 }275 else if (mxIsClass(dataref,"double") ){276 277 /*Convert matlab vector to double* vector: */278 MatlabVectorToDoubleVector(&outvector,&outvector_rows,dataref);279 280 }281 else{282 /*This is an error: we don't have the correct input!: */283 _error_("Input parameter of class " << mxGetClassName(dataref) << " not supported yet");284 }285 286 /*Assign output pointers:*/287 *pvector=outvector;288 if (pM)*pM=outvector_rows;289 }290 /*}}}*/291 /*FUNCTION FetchData(int** pvector,int* pM,const mxArray* dataref){{{*/292 void FetchData(int** pvector,int* pM,const mxArray* dataref){293 294 int i;295 double *doublevector = NULL;296 int *outvector = NULL;297 int outvector_rows;298 299 if(mxIsEmpty(dataref)){300 /*Nothing to pick up. Just initialize matrix pointer to NULL: */301 outvector_rows=0;302 outvector=NULL;303 }304 else if (mxIsClass(dataref,"double") ){305 306 /*Convert matlab vector to double* vector: */307 MatlabVectorToDoubleVector(&doublevector,&outvector_rows,dataref);308 309 /*Convert double vector into integer vector: */310 outvector=xNew<int>(outvector_rows);311 for(i=0;i<outvector_rows;i++)outvector[i]=(int)doublevector[i];312 }313 else{314 /*This is an error: we don't have the correct input!: */315 _error_("Input parameter of class " << mxGetClassName(dataref) << " not supported yet");316 }317 318 /*Assign output pointers:*/319 *pvector=outvector;320 if (pM)*pM=outvector_rows;321 }322 /*}}}*/323 /*FUNCTION FetchData(bool** pvector,int* pM,const mxArray* dataref){{{*/324 void FetchData(bool** pvector,int* pM,const mxArray* dataref){325 326 int i;327 double *doublevector = NULL;328 bool *outvector = NULL;329 int outvector_rows;330 331 if(mxIsEmpty(dataref)){332 /*Nothing to pick up. Just initialize matrix pointer to NULL: */333 outvector_rows=0;334 outvector=NULL;335 }336 else if (mxIsClass(dataref,"double") ){337 338 /*Convert matlab vector to double* vector: */339 MatlabVectorToDoubleVector(&doublevector,&outvector_rows,dataref);340 341 /*Convert double vector into integer vector: */342 outvector=xNew<bool>(outvector_rows);343 for(i=0;i<outvector_rows;i++)outvector[i]=(bool)doublevector[i];344 }345 else{346 /*This is an error: we don't have the correct input!: */347 _error_("Input parameter of class " << mxGetClassName(dataref) << " not supported yet");348 }349 350 /*Assign output pointers:*/351 *pvector=outvector;352 if (pM)*pM=outvector_rows;353 }354 /*}}}*/355 /*FUNCTION FetchData(float** pvector,int* pM,const mxArray* dataref){{{*/356 void FetchData(float** pvector,int* pM,const mxArray* dataref){357 358 int i;359 double *doublevector = NULL;360 float *outvector = NULL;361 int outvector_rows;362 363 if(mxIsEmpty(dataref)){364 /*Nothing to pick up. Just initialize matrix pointer to NULL: */365 outvector_rows=0;366 outvector=NULL;367 }368 else if (mxIsClass(dataref,"double") ){369 370 /*Convert matlab vector to double* vector: */371 MatlabVectorToDoubleVector(&doublevector,&outvector_rows,dataref);372 373 /*Convert double vector into float vector: */374 outvector=xNew<float>(outvector_rows);375 for(i=0;i<outvector_rows;i++)outvector[i]=(float)doublevector[i];376 }377 else{378 /*This is an error: we don't have the correct input!: */379 _error_("Input parameter of class " << mxGetClassName(dataref) << " not supported yet");380 }381 382 /*Assign output pointers:*/383 *pvector=outvector;384 if (pM)*pM=outvector_rows;385 }386 /*}}}*/387 /*FUNCTION FetchData(char** pstring,const mxArray* dataref){{{*/388 void FetchData(char** pstring,const mxArray* dataref){389 390 char* outstring=NULL;391 392 /*Ok, the string should be coming directly from the matlab workspace: */393 if (!mxIsClass(dataref,"char")){394 _error_("input data_type is not a string!");395 }396 else{397 /*Recover the string:*/398 int stringlen;399 400 stringlen = mxGetM(dataref)*mxGetN(dataref)+1;401 outstring =xNew<char>(stringlen);402 mxGetString(dataref,outstring,stringlen);403 }404 405 /*Assign output pointers:*/406 *pstring=outstring;407 }/*}}}*/408 /*FUNCTION FetchData(char** pmatrix,int* pnumel,int* pndims,int** psize,const mxArray* dataref){{{*/409 void FetchData(char** pmatrix,int* pnumel,int* pndims,int** psize,const mxArray* dataref){410 411 int outmatrix_numel,outmatrix_ndims;412 int* outmatrix_size=NULL;413 char* outmatrix=NULL;414 415 if(mxIsEmpty(dataref) ){416 /*Nothing to pick up. Just initialize matrix pointer to NULL: */417 outmatrix_numel=0;418 outmatrix_ndims=0;419 outmatrix_size =NULL;420 outmatrix=NULL;421 }422 else if (mxIsClass(dataref,"char") ){423 424 /*Convert matlab n-dim array to char* matrix: */425 MatlabNArrayToNArray(&outmatrix,&outmatrix_numel,&outmatrix_ndims,&outmatrix_size,dataref);426 }427 else{428 /*This is an error: we don't have the correct input!: */429 _error_("Input parameter of class " << mxGetClassName(dataref) << " not supported yet");430 }431 432 /*Assign output pointers:*/433 *pmatrix=outmatrix;434 if (pnumel)*pnumel=outmatrix_numel;435 if (pndims)*pndims=outmatrix_ndims;436 if (psize )*psize =outmatrix_size;437 else xDelete<int>(outmatrix_size);438 439 }440 /*}}}*/441 /*FUNCTION FetchData(double* pscalar,const mxArray* dataref){{{*/442 void FetchData(double* pscalar,const mxArray* dataref){443 444 double scalar;445 446 if (!mxIsClass(dataref,"double")){447 _error_("input data_type is not a double!");448 }449 else{450 /*Recover the double: */451 scalar=mxGetScalar(dataref);452 }453 454 /*Assign output pointers:*/455 *pscalar=scalar;456 }457 /*}}}*/458 /*FUNCTION FetchData(int* pinteger,const mxArray* dataref){{{*/459 void FetchData(int* pinteger,const mxArray* dataref){460 461 int integer;462 463 if (!mxIsClass(dataref,"double")){464 _error_("input data_type is not a scalar!");465 }466 else{467 /*Recover the double: */468 integer=(int)mxGetScalar(dataref);469 }470 471 /*Assign output pointers:*/472 *pinteger=integer;473 }474 /*}}}*/475 /*FUNCTION FetchData(bool* pboolean,const mxArray* dataref){{{*/476 void FetchData(bool* pboolean,const mxArray* dataref){477 478 bool* mxbool_ptr=NULL;479 480 if (mxIsClass(dataref,"logical")){481 if(mxGetM(dataref)!=1) _error_("input data is not of size 1x1");482 if(mxGetN(dataref)!=1) _error_("input data is not of size 1x1");483 mxbool_ptr=mxGetLogicals(dataref);484 }485 else{486 _error_("input data_type is not a bool!");487 }488 489 *pboolean=*mxbool_ptr;490 }491 /*}}}*/492 493 /*ISSM objects*/494 /*FUNCTION FetchData(Matrix<double>** pmatrix,const mxArray* dataref){{{*/495 void FetchData(Matrix<double>** pmatrix,const mxArray* dataref){496 497 Matrix<double>* outmatrix=NULL;498 int dummy=0;499 500 if (mxIsClass(dataref,"double") ){501 502 /*Convert matlab matrix to matrix: */503 outmatrix=MatlabMatrixToMatrix(dataref);504 505 }506 else{507 /*This is an error: we don't have the correct input!: */508 _error_("Input parameter of class " << mxGetClassName(dataref) << " not supported yet");509 }510 511 /*Assign output pointers:*/512 *pmatrix=outmatrix;513 }514 /*}}}*/515 /*FUNCTION FetchData(Vector<double>** pvector,const mxArray* dataref){{{*/516 void FetchData(Vector<double>** pvector,const mxArray* dataref){517 518 Vector<double>* vector=NULL;519 int dummy;520 521 if(mxIsEmpty(dataref)){522 /*Nothing to pick up. Just initialize matrix pointer to NULL: */523 vector=new Vector<double>(0);524 }525 else if (mxIsClass(dataref,"double") ){526 527 /*Convert matlab vector to petsc vector: */528 vector=MatlabVectorToVector(dataref);529 }530 else{531 /*This is an error: we don't have the correct input!: */532 _error_("Input parameter of class " << mxGetClassName(dataref) << " not supported yet");533 }534 535 /*Assign output pointers:*/536 *pvector=vector;537 }538 /*}}}*/539 /*FUNCTION FetchData(BamgGeom** pbamggeom,const mxArray* dataref){{{*/540 void FetchData(BamgGeom** pbamggeom,const mxArray* dataref){541 542 /*Initialize output*/543 BamgGeom* bamggeom=new BamgGeom();544 545 /*Fetch all fields*/546 FetchData(&bamggeom->Vertices,&bamggeom->VerticesSize[0],&bamggeom->VerticesSize[1],mxGetAssignedField(dataref,0,"Vertices"));547 FetchData(&bamggeom->Edges, &bamggeom->EdgesSize[0], &bamggeom->EdgesSize[1], mxGetAssignedField(dataref,0,"Edges"));548 FetchData(&bamggeom->Corners, &bamggeom->CornersSize[0], &bamggeom->CornersSize[1], mxGetAssignedField(dataref,0,"Corners"));549 FetchData(&bamggeom->RequiredVertices,&bamggeom->RequiredVerticesSize[0],&bamggeom->RequiredVerticesSize[1],mxGetAssignedField(dataref,0,"RequiredVertices"));550 FetchData(&bamggeom->RequiredEdges, &bamggeom->RequiredEdgesSize[0], &bamggeom->RequiredEdgesSize[1], mxGetAssignedField(dataref,0,"RequiredEdges"));551 FetchData(&bamggeom->CrackedEdges,&bamggeom->CrackedEdgesSize[0],&bamggeom->CrackedEdgesSize[1],mxGetAssignedField(dataref,0,"CrackedEdges"));552 FetchData(&bamggeom->SubDomains,&bamggeom->SubDomainsSize[0],&bamggeom->SubDomainsSize[1],mxGetAssignedField(dataref,0,"SubDomains"));553 554 /*Assign output pointers:*/555 *pbamggeom=bamggeom;556 }557 /*}}}*/558 /*FUNCTION FetchData(BamgMesh** pbamgmesh,const mxArray* dataref){{{*/559 void FetchData(BamgMesh** pbamgmesh,const mxArray* dataref){560 561 /*Initialize output*/562 BamgMesh* bamgmesh=new BamgMesh();563 564 /*Fetch all fields*/565 FetchData(&bamgmesh->Vertices,&bamgmesh->VerticesSize[0],&bamgmesh->VerticesSize[1],mxGetAssignedField(dataref,0,"Vertices"));566 FetchData(&bamgmesh->Edges, &bamgmesh->EdgesSize[0], &bamgmesh->EdgesSize[1], mxGetAssignedField(dataref,0,"Edges"));567 FetchData(&bamgmesh->Triangles, &bamgmesh->TrianglesSize[0], &bamgmesh->TrianglesSize[1], mxGetAssignedField(dataref,0,"Triangles"));568 FetchData(&bamgmesh->CrackedEdges,&bamgmesh->CrackedEdgesSize[0],&bamgmesh->CrackedEdgesSize[1],mxGetAssignedField(dataref,0,"CrackedEdges"));569 FetchData(&bamgmesh->VerticesOnGeomEdge,&bamgmesh->VerticesOnGeomEdgeSize[0],&bamgmesh->VerticesOnGeomEdgeSize[1],mxGetAssignedField(dataref,0,"VerticesOnGeomEdge"));570 FetchData(&bamgmesh->VerticesOnGeomVertex,&bamgmesh->VerticesOnGeomVertexSize[0],&bamgmesh->VerticesOnGeomVertexSize[1],mxGetAssignedField(dataref,0,"VerticesOnGeomVertex"));571 FetchData(&bamgmesh->EdgesOnGeomEdge, &bamgmesh->EdgesOnGeomEdgeSize[0], &bamgmesh->EdgesOnGeomEdgeSize[1], mxGetAssignedField(dataref,0,"EdgesOnGeomEdge"));572 FetchData(&bamgmesh->IssmSegments,&bamgmesh->IssmSegmentsSize[0],&bamgmesh->IssmSegmentsSize[1],mxGetAssignedField(dataref,0,"IssmSegments"));573 574 /*Assign output pointers:*/575 *pbamgmesh=bamgmesh;576 }577 /*}}}*/578 /*FUNCTION FetchData(BamgOpts** pbamgopts,const mxArray* dataref){{{*/579 void FetchData(BamgOpts** pbamgopts,const mxArray* dataref){580 581 /*Initialize output*/582 BamgOpts* bamgopts=new BamgOpts();583 584 /*Fetch all fields*/585 FetchData(&bamgopts->anisomax,mxGetField(dataref,0,"anisomax"));586 FetchData(&bamgopts->cutoff,mxGetField(dataref,0,"cutoff"));587 FetchData(&bamgopts->coeff,mxGetField(dataref,0,"coeff"));588 FetchData(&bamgopts->errg,mxGetField(dataref,0,"errg"));589 FetchData(&bamgopts->gradation,mxGetField(dataref,0,"gradation"));590 FetchData(&bamgopts->Hessiantype,mxGetField(dataref,0,"Hessiantype"));591 FetchData(&bamgopts->MaxCornerAngle,mxGetField(dataref,0,"MaxCornerAngle"));592 FetchData(&bamgopts->maxnbv,mxGetField(dataref,0,"maxnbv"));593 FetchData(&bamgopts->maxsubdiv,mxGetField(dataref,0,"maxsubdiv"));594 FetchData(&bamgopts->Metrictype,mxGetField(dataref,0,"Metrictype"));595 FetchData(&bamgopts->nbjacobi,mxGetField(dataref,0,"nbjacobi"));596 FetchData(&bamgopts->nbsmooth,mxGetField(dataref,0,"nbsmooth"));597 FetchData(&bamgopts->omega,mxGetField(dataref,0,"omega"));598 FetchData(&bamgopts->power,mxGetField(dataref,0,"power"));599 FetchData(&bamgopts->verbose,mxGetField(dataref,0,"verbose"));600 601 FetchData(&bamgopts->Crack,mxGetField(dataref,0,"Crack"));602 FetchData(&bamgopts->geometricalmetric,mxGetField(dataref,0,"geometricalmetric"));603 FetchData(&bamgopts->KeepVertices,mxGetField(dataref,0,"KeepVertices"));604 FetchData(&bamgopts->splitcorners,mxGetField(dataref,0,"splitcorners"));605 606 FetchData(&bamgopts->hmin,mxGetField(dataref,0,"hmin"));607 FetchData(&bamgopts->hmax,mxGetField(dataref,0,"hmax"));608 FetchData(&bamgopts->hminVertices,&bamgopts->hminVerticesSize[0],&bamgopts->hminVerticesSize[1],mxGetField(dataref,0,"hminVertices"));609 FetchData(&bamgopts->hmaxVertices,&bamgopts->hmaxVerticesSize[0],&bamgopts->hmaxVerticesSize[1],mxGetField(dataref,0,"hmaxVertices"));610 FetchData(&bamgopts->hVertices,&bamgopts->hVerticesSize[0],&bamgopts->hVerticesSize[1],mxGetField(dataref,0,"hVertices"));611 FetchData(&bamgopts->metric,&bamgopts->metricSize[0],&bamgopts->metricSize[1],mxGetField(dataref,0,"metric"));612 FetchData(&bamgopts->field,&bamgopts->fieldSize[0],&bamgopts->fieldSize[1],mxGetField(dataref,0,"field"));613 FetchData(&bamgopts->err,&bamgopts->errSize[0],&bamgopts->errSize[1],mxGetField(dataref,0,"err"));614 615 /*Additional checks*/616 bamgopts->Check();617 618 /*Assign output pointers:*/619 *pbamgopts=bamgopts;620 }621 /*}}}*/622 /*FUNCTION FetchData(Options** poptions,const mxArray** pdataref){{{*/623 void FetchData(Options** poptions,int istart, int nrhs,const mxArray** pdataref){624 625 char *name = NULL;626 Option *option = NULL;627 628 /*Initialize output*/629 Options* options=new Options();630 631 /*Fetch all options*/632 for (int i=istart; i<nrhs; i=i+2){633 if (!mxIsClass(pdataref[i],"char")) _error_("Argument " << i+1 << " must be name of option");634 635 FetchData(&name,pdataref[i]);636 if(i+1 == nrhs) _error_("Argument " << i+2 << " must exist and be value of option \"" << name << "\".");637 638 option=(Option*)OptionParse(name,&pdataref[i+1]);639 options->AddOption(option);640 option=NULL;641 }642 643 /*Assign output pointers:*/644 *poptions=options;645 }646 /*}}}*/647 /*FUNCTION FetchData(DataSet** pcontours,const mxArray* dataref){{{*/648 void FetchData(DataSet** pcontours,const mxArray* dataref){649 650 int numcontours,index,test1,test2;651 char *contourname = NULL;652 DataSet *contours = NULL;653 Contour<double> *contouri = NULL;654 655 if (mxIsClass(dataref,"char")){656 FetchData(&contourname,dataref);657 contours=DomainOutlineRead<double>(contourname);658 }659 else if(mxIsClass(dataref,"struct")){660 661 contours=new DataSet(0);662 numcontours=mxGetNumberOfElements(dataref);663 664 for(int i=0;i<numcontours;i++){665 666 contouri=xNew<Contour<double> >(1);667 668 index = mxGetFieldNumber(dataref,"nods");669 if(index==-1) _error_("input structure does not have a 'nods' field");670 FetchData(&contouri->nods,mxGetFieldByNumber(dataref,i,index));671 672 index = mxGetFieldNumber(dataref,"x");673 if(index==-1) _error_("input structure does not have a 'x' field");674 FetchData(&contouri->x,&test1,&test2,mxGetFieldByNumber(dataref,i,index));675 if(test1!=contouri->nods || test2!=1) _error_("field x should be of size ["<<contouri->nods<<" 1]");676 677 index = mxGetFieldNumber(dataref,"y");678 if(index==-1) _error_("input structure does not have a 'y' field");679 FetchData(&contouri->y,&test1,&test2,mxGetFieldByNumber(dataref,i,index));680 if(test1!=contouri->nods || test2!=1) _error_("field y should be of size ["<<contouri->nods<<" 1]");681 682 contours->AddObject(contouri);683 }684 }685 else{686 _error_("Contour is neither a string nor a structure and cannot be loaded ("<<mxGetClassName(dataref)<<" not supported)");687 }688 689 /*clean-up and assign output pointer*/690 xDelete<char>(contourname);691 *pcontours=contours;692 }693 /*}}}*/ -
../trunk-jpl/src/c/matlab/io/CheckNumMatlabArguments.cpp
1 /*!\file CheckNumMatlabArguments.cpp:2 * \brief: check number of arguments and report an usage error message.3 */4 5 #ifdef HAVE_CONFIG_H6 #include <config.h>7 #else8 #error "Cannot compile with HAVE_CONFIG_H symbol! run configure first!"9 #endif10 11 #include "../../shared/Exceptions/exceptions.h"12 #include "../../include/include.h"13 #include "mex.h"14 15 int CheckNumMatlabArguments(int nlhs,int NLHS, int nrhs,int NRHS, const char* __FUNCT__, void (*function)( void )){16 17 /*checks on arguments on the matlab side: */18 if (nrhs==0 && nlhs==0) {19 /*unless NLHS=0 and NRHS=0, we are just asking for documentation: */20 if (NRHS==0 && NLHS==0)return 1;21 /* special case: */22 function();23 _error_("usage: see above");24 }25 else if (nlhs!=NLHS || nrhs!=NRHS ) {26 function();27 _error_("usage error.");28 }29 return 1;30 } -
../trunk-jpl/src/c/matlab/io/WriteMatlabData.cpp
1 /* \file WriteData.c:2 * \brief: general interface for writing data3 */4 5 #ifdef HAVE_CONFIG_H6 #include <config.h>7 #else8 #error "Cannot compile with HAVE_CONFIG_H symbol! run configure first!"9 #endif10 11 #include <mex.h>12 #include "../../include/include.h"13 #include "../../shared/shared.h"14 #include "./matlabio.h"15 16 /*Primitive data types*/17 /*FUNCTION WriteData(mxArray** pdataref,double* matrix, int M,int N){{{*/18 void WriteData(mxArray** pdataref,double* matrix, int M,int N){19 20 mxArray *dataref = NULL;21 double *tmatrix = NULL;22 23 if(matrix){24 /*create the matlab matrixwith Matlab's memory manager */25 tmatrix=(double*)mxMalloc(M*N*sizeof(double));26 for(int i=0;i<M;i++){27 for(int j=0;j<N;j++){28 tmatrix[j*M+i]=matrix[i*N+j];29 }30 }31 dataref = mxCreateDoubleMatrix(0,0,mxREAL);32 mxSetM(dataref,(mwSize)M);33 mxSetN(dataref,(mwSize)N);34 mxSetPr(dataref,(double*)tmatrix);35 }36 else{37 dataref = mxCreateDoubleMatrix(0,0,mxREAL);38 }39 *pdataref=dataref;40 }41 /*}}}*/42 /*FUNCTION WriteData(mxArray** pdataref,int* matrix, int M,int N){{{*/43 void WriteData(mxArray** pdataref,int* matrix, int M,int N){44 45 mxArray* dataref = NULL;46 double* tmatrix = NULL;47 48 if(matrix){49 /*convert to double matrix using Matlab's memory manager*/50 double* tmatrix=(double*)mxMalloc(M*N*sizeof(double));51 for(int i=0;i<M;i++){52 for(int j=0;j<N;j++){53 tmatrix[j*M+i]=(double)matrix[i*N+j];54 }55 }56 dataref = mxCreateDoubleMatrix(0,0,mxREAL);57 mxSetM(dataref,(mwSize)M);58 mxSetN(dataref,(mwSize)N);59 mxSetPr(dataref,(double*)tmatrix);60 }61 else{62 dataref = mxCreateDoubleMatrix(0,0,mxREAL);63 }64 *pdataref=dataref;65 }66 /*}}}*/67 /*FUNCTION WriteData(mxArray** pdataref,double* vector, int M){{{*/68 void WriteData(mxArray** pdataref,double* vector, int M){69 70 mxArray* dataref = NULL;71 double* vector_matlab = NULL;72 73 if(vector){74 75 /*create the matlab vector with Matlab's memory manager */76 vector_matlab=(double*)mxMalloc(M*sizeof(double));77 for(int i=0;i<M;i++) vector_matlab[i]=vector[i];78 dataref = mxCreateDoubleMatrix(0,0,mxREAL);79 mxSetM(dataref,(mwSize)M);80 mxSetN(dataref,(mwSize)1);81 mxSetPr(dataref,vector_matlab);82 }83 else{84 dataref = mxCreateDoubleMatrix(0,0,mxREAL);85 }86 87 *pdataref=dataref;88 }89 /*}}}*/90 /*FUNCTION WriteData(mxArray** pdataref,double scalar){{{*/91 void WriteData(mxArray** pdataref,double scalar){92 93 *pdataref=mxCreateDoubleScalar(scalar);94 }95 /*}}}*/96 /*FUNCTION WriteData(mxArray** pdataref,int integer){{{*/97 void WriteData(mxArray** pdataref,int integer){98 99 *pdataref=mxCreateDoubleScalar((double)integer);100 101 }102 /*}}}*/103 /*FUNCTION WriteData(mxArray** pdataref,int boolean){{{*/104 void WriteData(mxArray** pdataref,bool boolean){105 106 *pdataref=mxCreateDoubleScalar((double)boolean);107 108 }109 /*}}}*/110 /*FUNCTION WriteData(mxArray** pdataref,char* string){{{*/111 void WriteData(mxArray** pdataref,char* string){112 113 *pdataref=mxCreateString(string);114 }115 /*}}}*/116 /*FUNCTION WriteData(mxArray** pdataref){{{*/117 void WriteData(mxArray** pdataref){118 119 ;120 121 }122 /*}}}*/123 124 /*ISSM objects*/125 /*FUNCTION WriteData(mxArray** pdataref,BamgGeom* bamggeom){{{*/126 void WriteData(mxArray** pdataref,BamgGeom* bamggeom){127 128 /*Intermediary*/129 int i;130 mxArray *dataref = NULL;131 const int numfields = 8;132 const char *fnames[numfields];133 mwSize ndim = 2;134 mwSize dimensions[2] = {1,1};135 136 /*Initialize field names*/137 i=0;138 fnames[i++] = "Vertices";139 fnames[i++] = "Edges";140 fnames[i++] = "TangentAtEdges";141 fnames[i++] = "Corners";142 fnames[i++] = "RequiredVertices";143 fnames[i++] = "RequiredEdges";144 fnames[i++] = "CrackedEdges";145 fnames[i++] = "SubDomains";146 _assert_(i==numfields);147 148 /*Initialize Matlab structure*/149 dataref=mxCreateStructArray(ndim,dimensions,numfields,fnames);150 151 /*set each matlab each field*/152 i=0;153 i++; SetStructureField(dataref,"Vertices", bamggeom->VerticesSize[0], bamggeom->VerticesSize[1], bamggeom->Vertices);154 i++; SetStructureField(dataref,"Edges", bamggeom->EdgesSize[0], bamggeom->EdgesSize[1], bamggeom->Edges);155 i++; SetStructureField(dataref,"TangentAtEdges", bamggeom->TangentAtEdgesSize[0], bamggeom->TangentAtEdgesSize[1], bamggeom->TangentAtEdges);156 i++; SetStructureField(dataref,"Corners", bamggeom->CornersSize[0], bamggeom->CornersSize[1], bamggeom->Corners);157 i++; SetStructureField(dataref,"RequiredVertices",bamggeom->RequiredVerticesSize[0],bamggeom->RequiredVerticesSize[1],bamggeom->RequiredVertices);158 i++; SetStructureField(dataref,"RequiredEdges", bamggeom->RequiredEdgesSize[0], bamggeom->RequiredEdgesSize[1], bamggeom->RequiredEdges);159 i++; SetStructureField(dataref,"CrackedEdges", bamggeom->CrackedEdgesSize[0], bamggeom->CrackedEdgesSize[1], bamggeom->CrackedEdges);160 i++; SetStructureField(dataref,"SubDomains", bamggeom->SubDomainsSize[0], bamggeom->SubDomainsSize[1], bamggeom->SubDomains);161 _assert_(i==numfields);162 163 /*Assign output*/164 *pdataref=dataref;165 }166 /*}}}*/167 /*FUNCTION WriteData(mxArray** pdataref,BamgMesh* bamgmesh){{{*/168 void WriteData(mxArray** pdataref,BamgMesh* bamgmesh){169 170 /*Intermediary*/171 int i;172 mxArray *dataref = NULL;173 const int numfields = 16;174 const char *fnames[numfields];175 mwSize ndim = 2;176 mwSize dimensions[2] = {1,1};177 178 /*Initialize field names*/179 i=0;180 fnames[i++] = "Vertices";181 fnames[i++] = "Edges";182 fnames[i++] = "Triangles";183 fnames[i++] = "Quadrilaterals";184 fnames[i++] = "IssmEdges";185 fnames[i++] = "IssmSegments";186 fnames[i++] = "VerticesOnGeomVertex";187 fnames[i++] = "VerticesOnGeomEdge";188 fnames[i++] = "EdgesOnGeomEdge";189 fnames[i++] = "SubDomains";190 fnames[i++] = "SubDomainsFromGeom";191 fnames[i++] = "ElementConnectivity";192 fnames[i++] = "NodalConnectivity";193 fnames[i++] = "NodalElementConnectivity";194 fnames[i++] = "CrackedVertices";195 fnames[i++] = "CrackedEdges";196 _assert_(i==numfields);197 198 /*Initialize Matlab structure*/199 dataref=mxCreateStructArray(ndim,dimensions,numfields,fnames);200 201 /*set each matlab each field*/202 i=0;203 i++; SetStructureField(dataref,"Vertices",bamgmesh->VerticesSize[0], bamgmesh->VerticesSize[1],bamgmesh->Vertices);204 i++; SetStructureField(dataref,"Edges", bamgmesh->EdgesSize[0],bamgmesh->EdgesSize[1], bamgmesh->Edges);205 i++; SetStructureField(dataref,"Triangles", bamgmesh->TrianglesSize[0],bamgmesh->TrianglesSize[1], bamgmesh->Triangles);206 i++; SetStructureField(dataref,"Quadrilaterals",bamgmesh->QuadrilateralsSize[0], bamgmesh->QuadrilateralsSize[1],bamgmesh->Quadrilaterals);207 i++; SetStructureField(dataref,"IssmEdges", bamgmesh->IssmEdgesSize[0],bamgmesh->IssmEdgesSize[1], bamgmesh->IssmEdges);208 i++; SetStructureField(dataref,"IssmSegments",bamgmesh->IssmSegmentsSize[0], bamgmesh->IssmSegmentsSize[1],bamgmesh->IssmSegments);209 i++; SetStructureField(dataref,"VerticesOnGeomVertex",bamgmesh->VerticesOnGeomVertexSize[0],bamgmesh->VerticesOnGeomVertexSize[1], bamgmesh->VerticesOnGeomVertex);210 i++; SetStructureField(dataref,"VerticesOnGeomEdge",bamgmesh->VerticesOnGeomEdgeSize[0],bamgmesh->VerticesOnGeomEdgeSize[1], bamgmesh->VerticesOnGeomEdge);211 i++; SetStructureField(dataref,"EdgesOnGeomEdge", bamgmesh->EdgesOnGeomEdgeSize[0], bamgmesh->EdgesOnGeomEdgeSize[1],bamgmesh->EdgesOnGeomEdge);212 i++; SetStructureField(dataref,"SubDomains",bamgmesh->SubDomainsSize[0], bamgmesh->SubDomainsSize[1],bamgmesh->SubDomains);213 i++; SetStructureField(dataref,"SubDomainsFromGeom", bamgmesh->SubDomainsFromGeomSize[0], bamgmesh->SubDomainsFromGeomSize[1],bamgmesh->SubDomainsFromGeom);214 i++; SetStructureField(dataref,"ElementConnectivity",bamgmesh->ElementConnectivitySize[0],bamgmesh->ElementConnectivitySize[1], bamgmesh->ElementConnectivity);215 i++; SetStructureField(dataref,"NodalConnectivity",bamgmesh->NodalConnectivitySize[0],bamgmesh->NodalConnectivitySize[1], bamgmesh->NodalConnectivity);216 i++; SetStructureField(dataref,"NodalElementConnectivity", bamgmesh->NodalElementConnectivitySize[0], bamgmesh->NodalElementConnectivitySize[1],bamgmesh->NodalElementConnectivity);217 i++; SetStructureField(dataref,"CrackedVertices", bamgmesh->CrackedVerticesSize[0],bamgmesh->CrackedVerticesSize[1], bamgmesh->CrackedVertices);218 i++; SetStructureField(dataref,"CrackedEdges",bamgmesh->CrackedEdgesSize[0], bamgmesh->CrackedEdgesSize[1],bamgmesh->CrackedEdges);219 _assert_(i==numfields);220 221 /*Assign output*/222 *pdataref=dataref;223 }224 /*}}}*/225 /*FUNCTION WriteData(mxArray** pdataref,SeqMat<double>* matrix){{{*/226 void WriteData(mxArray** pdataref,SeqMat<double>* matrix){227 228 int i,j;229 int rows,cols;230 mxArray *dataref = NULL;231 double *matrix_ptr = NULL;232 double *tmatrix_ptr = NULL;233 234 if(matrix){235 236 matrix_ptr=matrix->ToSerial();237 matrix->GetSize(&rows,&cols);238 239 /*Now transpose the matrix and allocate with Matlab's memory manager: */240 tmatrix_ptr=(double*)mxMalloc(rows*cols*sizeof(double));241 for(i=0;i<rows;i++){242 for(j=0;j<cols;j++){243 tmatrix_ptr[j*rows+i]=matrix_ptr[i*cols+j];244 }245 }246 247 /*create matlab matrix: */248 dataref=mxCreateDoubleMatrix(0,0,mxREAL);249 mxSetM(dataref,rows);250 mxSetN(dataref,cols);251 mxSetPr(dataref,tmatrix_ptr);252 253 /*Free ressources:*/254 xDelete<double>(matrix_ptr);255 }256 else{257 dataref = mxCreateDoubleMatrix(0,0,mxREAL);258 }259 260 *pdataref=dataref;261 }262 /*}}}*/263 /*FUNCTION WriteData(mxArray** pdataref,SeqVec<double>* vector){{{*/264 void WriteData(mxArray** pdataref,SeqVec<double>* vector){265 266 mxArray* dataref=NULL;267 double* vector_ptr=NULL;268 double* vector_matlab=NULL;269 int rows;270 271 if(vector){272 /*call toolkit routine: */273 vector_ptr=vector->ToMPISerial();274 vector->GetSize(&rows);275 276 /*now create the matlab vector with Matlab's memory manager */277 vector_matlab=(double*)mxMalloc(rows*sizeof(double));278 for(int i=0;i<rows;i++) vector_matlab[i]=vector_ptr[i];279 280 dataref = mxCreateDoubleMatrix(0,0,mxREAL);281 mxSetM(dataref,rows);282 mxSetN(dataref,1);283 mxSetPr(dataref,vector_matlab);284 }285 else{286 dataref = mxCreateDoubleMatrix(0,0,mxREAL);287 }288 289 /*Clean-up and return*/290 xDelete<double>(vector_ptr);291 *pdataref=dataref;292 }293 /*}}}*/294 /*FUNCTION WriteData(mxArray** pdataref,RiftStruct* riftstruct){{{*/295 void WriteData(mxArray** pdataref,RiftStruct* riftstruct){296 297 /*Intermediary*/298 int i;299 mxArray *dataref = NULL;300 const int numfields = 10;301 const char *fnames[numfields];302 mwSize ndim = 2;303 mwSize dimensions[2] = {1,1};304 305 /*Initialize field names*/306 i=0;307 fnames[i++] = "numsegs";308 fnames[i++] = "segments";309 fnames[i++] = "pairs";310 fnames[i++] = "tips";311 fnames[i++] = "penaltypairs";312 fnames[i++] = "fill";313 fnames[i++] = "friction";314 fnames[i++] = "fraction";315 fnames[i++] = "fractionincrement";316 fnames[i++] = "state";317 _assert_(i==numfields);318 319 /*Initialize matlab structure of dimension numrifts*/320 dimensions[0]=riftstruct->numrifts;321 dataref=mxCreateStructArray(ndim,dimensions,numfields,fnames);322 323 /*set each matlab each field*/324 for(int i=0;i<riftstruct->numrifts;i++){325 SetStructureFieldi(dataref,i,"numsegs" ,riftstruct->riftsnumsegments[i]);326 SetStructureFieldi(dataref,i,"segments" ,riftstruct->riftsnumsegments[i] ,3,riftstruct->riftssegments[i]);327 SetStructureFieldi(dataref,i,"pairs" ,riftstruct->riftsnumpairs[i] ,2,riftstruct->riftspairs[i]);328 SetStructureFieldi(dataref,i,"tips" ,1 ,2,&riftstruct->riftstips[2*i]);329 SetStructureFieldi(dataref,i,"penaltypairs" ,riftstruct->riftsnumpenaltypairs[i],7,riftstruct->riftspenaltypairs[i]);330 SetStructureFieldi(dataref,i,"fill" ,IceEnum);331 SetStructureFieldi(dataref,i,"friction" ,0);332 SetStructureFieldi(dataref,i,"fraction" ,0.);333 SetStructureFieldi(dataref,i,"fractionincrement",0.1);334 SetStructureFieldi(dataref,i,"state" ,riftstruct->riftsnumpenaltypairs[i],1,riftstruct->state[i]);335 }336 337 /*Assign output*/338 *pdataref=dataref;339 }340 /*}}}*/341 342 /*Toolkit*/343 /*FUNCTION SetStructureField{{{*/344 void SetStructureField(mxArray* dataref,const char* fieldname,int M,int N,double* fieldpointer){345 346 mxArray* field = NULL;347 348 /*Convert field*/349 WriteData(&field,fieldpointer,M,N);350 351 /*Assign to structure*/352 mxSetField(dataref,0,fieldname,field);353 }354 /*}}}*/355 /*FUNCTION SetStructureFieldi(mxArray* dataref,int i,const char* fieldname,int M,int N,double* fieldpointer){{{*/356 void SetStructureFieldi(mxArray* dataref,int i,const char* fieldname,int M,int N,double* fieldpointer){357 358 mxArray* field = NULL;359 360 /*Convert field*/361 WriteData(&field,fieldpointer,M,N);362 363 /*Assign to structure*/364 mxSetField(dataref,i,fieldname,field);365 }366 /*}}}*/367 /*FUNCTION SetStructureFieldi(mxArray* dataref,int i,const char* fieldname,int field){{{*/368 void SetStructureFieldi(mxArray* dataref,int i,const char* fieldname,int fieldin){369 370 mxArray* field = NULL;371 372 /*Convert field*/373 WriteData(&field,fieldin);374 375 /*Assign to structure*/376 mxSetField(dataref,i,fieldname,field);377 }378 /*}}}*/379 /*FUNCTION SetStructureFieldi(mxArray* dataref,int i,const char* fieldname,double field){{{*/380 void SetStructureFieldi(mxArray* dataref,int i,const char* fieldname,double fieldin){381 382 mxArray* field = NULL;383 384 /*Convert field*/385 WriteData(&field,fieldin);386 387 /*Assign to structure*/388 mxSetField(dataref,i,fieldname,field);389 }390 /*}}}*/ -
../trunk-jpl/src/c/matlab/io/mxGetAssignedField.cpp
1 /*!\file: mxGetAssignedField.c:2 * \brief: abstract interface on parallel side for i/o, so it ressembles the serial i/o.3 *4 * In serial mode, this routine takes care of returning the field coming5 * from the model. If largesize is 1, we are running out of core models in6 * matlab, and we need to call the subsref private method from the model object7 * in order to correctly load the data from disk.8 */9 10 #ifdef HAVE_CONFIG_H11 #include <config.h>12 #else13 #error "Cannot compile without HAVE_CONFIG_H symbol! run configure first!"14 #endif15 16 #include "mex.h"17 18 mxArray* mxGetAssignedField(const mxArray* pmxa_array,int number,const char* field){19 20 //output21 mxArray* mxfield=NULL;22 23 //input24 mxArray *inputs[2];25 mxArray *pindex = NULL;26 const char *fnames[2];27 mwSize ndim = 2;28 mwSize onebyone[2] = {1,1};29 30 //We want to call the subsasgn method, and get the returned array.This ensures that if we are running31 //large sized problems, the data is truly loaded from disk by the model subsasgn class method.32 inputs[0]=(mxArray*)pmxa_array; //this is the model33 34 //create index structure used in the assignment (index.type='.' and index.subs='x' for field x for ex)35 fnames[0] = "type";36 fnames[1] = "subs";37 pindex=mxCreateStructArray( ndim,onebyone,2,fnames);38 mxSetField( pindex, 0, "type",mxCreateString("."));39 mxSetField( pindex, 0, "subs",mxCreateString(field));40 inputs[1]=pindex;41 42 mexCallMATLAB( 1, &mxfield, 2, (mxArray**)inputs, "subsref");43 44 return mxfield;45 } -
../trunk-jpl/src/c/matlab/io/MatlabMatrixToDoubleMatrix.cpp
1 /* \file MatlabMatrixToDoubleMatrix.cpp2 * \brief: convert a sparse or dense matlab matrix to a double* pointer3 */4 5 #ifdef HAVE_CONFIG_H6 #include <config.h>7 #else8 #error "Cannot compile with HAVE_CONFIG_H symbol! run configure first!"9 #endif10 11 /*Matlab includes: */12 #include "mex.h"13 #include "../../shared/shared.h"14 15 int MatlabMatrixToDoubleMatrix(double** pmatrix,int* pmatrix_rows,int* pmatrix_cols,const mxArray* mxmatrix){16 17 int i,j,count,rows,cols;18 19 /*output: */20 double* matrix=NULL;21 22 /*matlab indices: */23 mwIndex* ir=NULL;24 mwIndex* jc=NULL;25 26 /*Ok, first check if we are dealing with a sparse or full matrix: */27 if (mxIsSparse(mxmatrix)){28 29 /*Dealing with sparse matrix: recover size first: */30 double* pmxmatrix=(double*)mxGetPr(mxmatrix);31 rows=mxGetM(mxmatrix);32 cols=mxGetN(mxmatrix);33 34 if(rows*cols){35 matrix=xNewZeroInit<double>(rows*cols);36 37 /*Now, get ir,jc and pr: */38 ir=mxGetIr(mxmatrix);39 jc=mxGetJc(mxmatrix);40 41 /*Now, start inserting data into double* matrix: */42 count=0;43 for(i=0;i<cols;i++){44 for(j=0;j<(jc[i+1]-jc[i]);j++){45 matrix[rows*ir[count]+i]=pmxmatrix[count];46 count++;47 }48 }49 }50 51 }52 else if(mxIsClass(mxmatrix,"double")){53 /*Dealing with dense matrix: recover pointer and size: */54 double* pmxmatrix=(double*)mxGetPr(mxmatrix);55 rows=mxGetM(mxmatrix);56 cols=mxGetN(mxmatrix);57 58 /*Create serial matrix: */59 if(rows*cols){60 matrix=xNewZeroInit<double>(rows*cols);61 62 for(i=0;i<rows;i++){63 for(j=0;j<cols;j++){64 matrix[cols*i+j]=(double)pmxmatrix[rows*j+i];65 }66 }67 }68 }69 else if(mxIsClass(mxmatrix,"single")){70 /*Dealing with dense matrix: recover pointer and size: */71 float *pmxmatrix=(float*)mxGetPr(mxmatrix);72 rows=mxGetM(mxmatrix);73 cols=mxGetN(mxmatrix);74 75 /*Create serial matrix: */76 if(rows*cols){77 matrix=xNewZeroInit<double>(rows*cols);78 79 for(i=0;i<rows;i++){80 for(j=0;j<cols;j++){81 matrix[cols*i+j]=(double)pmxmatrix[rows*j+i];82 }83 }84 }85 }86 else if(mxIsClass(mxmatrix,"int16")){87 /*Dealing with dense matrix: recover pointer and size: */88 short int *pmxmatrix=(short*)mxGetPr(mxmatrix);89 rows=mxGetM(mxmatrix);90 cols=mxGetN(mxmatrix);91 92 /*Create serial matrix: */93 if(rows*cols){94 matrix=xNewZeroInit<double>(rows*cols);95 96 for(i=0;i<rows;i++){97 for(j=0;j<cols;j++){98 matrix[cols*i+j]=(double)pmxmatrix[rows*j+i];99 }100 }101 }102 }103 else if(mxIsClass(mxmatrix,"uint8")){104 /*Dealing with dense matrix: recover pointer and size: */105 char *pmxmatrix=(char*)mxGetPr(mxmatrix);106 rows=mxGetM(mxmatrix);107 cols=mxGetN(mxmatrix);108 109 /*Create serial matrix: */110 if(rows*cols){111 matrix=xNewZeroInit<double>(rows*cols);112 113 for(i=0;i<rows;i++){114 for(j=0;j<cols;j++){115 matrix[cols*i+j]=(double)pmxmatrix[rows*j+i];116 }117 }118 }119 }120 else{121 _error_("Matlab matrix type Not implemented yet");122 }123 124 /*Assign output pointer: */125 *pmatrix=matrix;126 *pmatrix_rows=rows;127 *pmatrix_cols=cols;128 129 return 1;130 } -
../trunk-jpl/src/c/matlab/io/MatlabVectorToVector.cpp
1 /*!\file MatlabVectorToVector.cpp2 */3 4 /*Headers:*/5 /*{{{*/6 #ifdef HAVE_CONFIG_H7 #include <config.h>8 #else9 #error "Cannot compile with HAVE_CONFIG_H symbol! run configure first!"10 #endif11 12 #include <mex.h>13 #include <stdio.h>14 #include <string.h>15 #include "./matlabio.h"16 #include "../../classes/classes.h"17 #include "../../shared/shared.h"18 #include "../../Container/Container.h"19 #include "../../include/include.h"20 #include "../../toolkits/toolkits.h"21 22 /*}}}*/23 24 Vector<double>* MatlabVectorToVector(const mxArray* mxvector){25 26 int dummy;27 Vector<double>* vector=NULL;28 29 /*allocate vector object: */30 vector=new Vector<double>();31 32 #ifdef _HAVE_PETSC_33 vector->pvector=MatlabVectorToPetscVec(mxvector);34 #else35 vector->svector=MatlabVectorToSeqVec(mxvector);36 #endif37 38 return vector;39 } -
../trunk-jpl/src/c/matlab/io/MatlabMatrixToPetscMat.cpp
1 /* \file MatlabMatrixToPetscMatrix.cpp2 * \brief: convert a sparse or dense matlab matrix to a serial Petsc matrix:3 */4 5 #ifdef HAVE_CONFIG_H6 #include <config.h>7 #else8 #error "Cannot compile with HAVE_CONFIG_H symbol! run configure first!"9 #endif10 #include "../../shared/shared.h"11 12 /*Petsc includes: */13 #include "petscmat.h"14 #include "petscvec.h"15 #include "petscksp.h"16 17 /*Matlab includes: */18 #include "mex.h"19 #include "matlabio.h"20 21 PetscMat* MatlabMatrixToPetscMat(const mxArray* mxmatrix){22 23 int dummy;24 PetscMat* matrix=new PetscMat();25 26 MatlabMatrixToPetscMat(&matrix->matrix, &dummy, &dummy, mxmatrix);27 28 return matrix;29 }30 int MatlabMatrixToPetscMat(Mat* pmatrix,int* pmatrix_rows,int* pmatrix_cols,const mxArray* mxmatrix){31 32 int rows, cols;33 double *mxmatrix_ptr = NULL;34 double *tmatrix = NULL;35 int ierr;36 int i,j;37 38 /*output: */39 Mat matrix = NULL;40 41 /*matlab indices: */42 mwIndex *ir = NULL;43 mwIndex *jc = NULL;44 double *pr = NULL;45 int count;46 int nnz;47 int nz;48 49 /*petsc indices: */50 int *idxm = NULL;51 int *idxn = NULL;52 53 /*Ok, first check if we are dealing with a sparse or full matrix: */54 if (mxIsSparse(mxmatrix)){55 56 /*Dealing with sparse matrix: recover size first: */57 mxmatrix_ptr=(double*)mxGetPr(mxmatrix);58 rows=mxGetM(mxmatrix);59 cols=mxGetN(mxmatrix);60 nnz=mxGetNzmax(mxmatrix);61 if(rows){62 nz=(int)((double)nnz/(double)rows);63 }64 else{65 nz=0;66 }67 68 ierr=MatCreateSeqAIJ(PETSC_COMM_SELF,rows,cols,nz,PETSC_NULL,&matrix);CHKERRQ(ierr);69 70 /*Now, get ir,jc and pr: */71 pr=mxGetPr(mxmatrix);72 ir=mxGetIr(mxmatrix);73 jc=mxGetJc(mxmatrix);74 75 /*Now, start inserting data into sparse matrix: */76 count=0;77 for(i=0;i<cols;i++){78 for(j=0;j<(jc[i+1]-jc[i]);j++){79 MatSetValue(matrix,ir[count],i,pr[count],INSERT_VALUES);80 count++;81 }82 }83 }84 else{85 /*Dealing with dense matrix: recover pointer and size: */86 mxmatrix_ptr=(double*)mxGetPr(mxmatrix);87 rows=mxGetM(mxmatrix);88 cols=mxGetN(mxmatrix);89 90 /*transpose, as Petsc now does not allows MAT_COLUMN_ORIENTED matrices in MatSetValues: */91 tmatrix=xNew<double>(rows*cols);92 for(i=0;i<cols;i++){93 for(j=0;j<rows;j++){94 *(tmatrix+rows*i+j)=*(mxmatrix_ptr+cols*j+i);95 }96 }97 98 /*Create serial matrix: */99 ierr=MatCreateSeqDense(PETSC_COMM_SELF,rows,cols,NULL,&matrix);CHKERRQ(ierr);100 101 /*Insert mxmatrix_ptr values into petsc matrix: */102 idxm=xNew<int>(rows);103 idxn=xNew<int>(cols);104 105 for(i=0;i<rows;i++)idxm[i]=i;106 for(i=0;i<cols;i++)idxn[i]=i;107 108 ierr=MatSetValues(matrix,rows,idxm,cols,idxn,tmatrix,INSERT_VALUES); CHKERRQ(ierr);109 110 xDelete<double>(tmatrix);111 }112 113 /*Assemble matrix: */114 MatAssemblyBegin(matrix,MAT_FINAL_ASSEMBLY);115 MatAssemblyEnd(matrix,MAT_FINAL_ASSEMBLY);116 117 /*Assign output pointer: */118 *pmatrix=matrix;119 if(pmatrix_rows) *pmatrix_rows=rows;120 if(pmatrix_cols) *pmatrix_cols=cols;121 122 return 1;123 } -
../trunk-jpl/src/c/matlab/io/matlabio.h
1 /*\file matlabio.h2 *\brief: I/O for ISSM in matlab mode3 */4 5 #ifndef _MATLAB_IO_H_6 #define _MATLAB_IO_H_7 8 #ifdef HAVE_CONFIG_H9 #include <config.h>10 #else11 #error "Cannot compile with HAVE_CONFIG_H symbol! run configure first!"12 #endif13 14 #include <mex.h>15 #include "../../classes/classes.h"16 #include "../../Container/Container.h"17 #include "../../include/include.h"18 19 void WriteData(mxArray** pdataref,SeqMat<double>* matrix);20 void WriteData(mxArray** pdataref,double* matrix, int M,int N);21 void WriteData(mxArray** pdataref,int* matrix, int M,int N);22 void WriteData(mxArray** pdataref,SeqVec<double>* vector);23 void WriteData(mxArray** pdataref,double* vector, int M);24 void WriteData(mxArray** pdataref,int integer);25 void WriteData(mxArray** pdataref,bool boolean);26 void WriteData(mxArray** pdataref,double scalar);27 void WriteData(mxArray** pdataref,char* string);28 void WriteData(mxArray** pdataref);29 void WriteData(mxArray** pdataref,BamgGeom* bamggeom);30 void WriteData(mxArray** pdataref,BamgMesh* bamgmesh);31 void WriteData(mxArray** pdataref,RiftStruct* riftstruct);32 33 void FetchData(double** pmatrix,int* pM,int *pN,const mxArray* dataref);34 void FetchData(double** pmatrix,int* pnumel,int* pndims,int** psize,const mxArray* dataref);35 void FetchData(int** pmatrix,int* pM,int *pN,const mxArray* dataref);36 void FetchData(bool** pmatrix,int* pM,int *pN,const mxArray* dataref);37 void FetchData(bool** pmatrix,int* pnumel,int* pndims,int** psize,const mxArray* dataref);38 void FetchData(Matrix<double>** pmatrix,const mxArray* dataref);39 void FetchData(int** pvector,int* pM,const mxArray* dataref);40 void FetchData(float** pvector,int* pM,const mxArray* dataref);41 void FetchData(double** pvector,int* pM,const mxArray* dataref);42 void FetchData(bool** pvector,int* pM,const mxArray* dataref);43 void FetchData(Vector<double>** pvector,const mxArray* dataref);44 void FetchData(char** pstring,const mxArray* dataref);45 void FetchData(char** pmatrix,int* pnumel,int* pndims,int** psize,const mxArray* dataref);46 void FetchData(double* pscalar,const mxArray* dataref);47 void FetchData(int* pinteger,const mxArray* dataref);48 void FetchData(bool* pbool,const mxArray* dataref);49 void FetchData(BamgGeom** bamggeom,const mxArray* dataref);50 void FetchData(BamgMesh** bamgmesh,const mxArray* dataref);51 void FetchData(BamgOpts** bamgopts,const mxArray* dataref);52 void FetchData(Options** poptions,int istart, int nrhs,const mxArray** pdataref);53 void FetchData(DataSet** pcontours,const mxArray* dataref);54 55 Option* OptionParse(char* name, const mxArray* prhs[]);56 GenericOption<double>* OptionDoubleParse( char* name, const mxArray* prhs[]);57 GenericOption<double*>* OptionDoubleArrayParse( char* name, const mxArray* prhs[]);58 GenericOption<bool*>* OptionLogicalParse( char* name, const mxArray* prhs[]);59 GenericOption<char*>* OptionCharParse( char* name, const mxArray* prhs[]);60 GenericOption<Options**>* OptionStructParse( char* name, const mxArray* prhs[]);61 GenericOption<Options*>* OptionCellParse( char* name, const mxArray* prhs[]);62 63 mxArray* mxGetAssignedField(const mxArray* pmxa_array,int number, const char* field);64 void SetStructureField(mxArray* dataref,const char* fieldname,int fieldrows,int fieldcols,double* fieldpointer);65 void SetStructureFieldi(mxArray* dataref,int i,const char* fieldname,int fieldrows,int fieldcols,double* fieldpointer);66 void SetStructureFieldi(mxArray* dataref,int i,const char* fieldname,int field);67 void SetStructureFieldi(mxArray* dataref,int i,const char* fieldname,double field);68 int CheckNumMatlabArguments(int nlhs,int NLHS, int nrhs,int NRHS, const char* THISFUNCTION, void (*function)( void ));69 70 /*Matlab to Matrix routines: */71 Matrix<double>* MatlabMatrixToMatrix(const mxArray* mxmatrix);72 Vector<double>* MatlabVectorToVector(const mxArray* mxvector);73 74 /*Matlab to double* routines: */75 int MatlabVectorToDoubleVector(double** pvector,int* pvector_rows,const mxArray* mxvector);76 int MatlabMatrixToDoubleMatrix(double** pmatrix,int* pmatrix_rows,int* pmatrix_cols,const mxArray* mxmatrix);77 int MatlabNArrayToNArray(double** pmatrix,int* pmatrix_numel,int* pmatrix_ndims,int** pmatrix_size,const mxArray* mxmatrix);78 int MatlabNArrayToNArray(bool** pmatrix,int* pmatrix_numel,int* pmatrix_ndims,int** pmatrix_size,const mxArray* mxmatrix);79 int MatlabNArrayToNArray(char** pmatrix,int* pmatrix_numel,int* pmatrix_ndims,int** pmatrix_size,const mxArray* mxmatrix);80 81 /*Matlab to SeqMat routines: */82 SeqMat<double>* MatlabMatrixToSeqMat(const mxArray* dataref);83 SeqVec<double>* MatlabVectorToSeqVec(const mxArray* dataref);84 85 /*Matlab to Petsc routines: */86 #ifdef _HAVE_PETSC_87 int MatlabMatrixToPetscMat(Mat* matrix,int* prows,int* pcols, const mxArray* mxmatrix);88 PetscMat* MatlabMatrixToPetscMat(const mxArray* mxmatrix);89 int MatlabVectorToPetscVec(Vec* pvector,int* pvector_rows,const mxArray* mxvector);90 PetscVec* MatlabVectorToPetscVec(const mxArray* mxvector);91 #endif92 93 #endif /* _IO_H_ */ -
../trunk-jpl/src/c/matlab/io/MatlabVectorToSeqVec.cpp
1 /*!\file MatlabVectorToSeqVec.cpp2 */3 4 /*Headers:*/5 /*{{{*/6 #ifdef HAVE_CONFIG_H7 #include <config.h>8 #else9 #error "Cannot compile with HAVE_CONFIG_H symbol! run configure first!"10 #endif11 12 #include <mex.h>13 #include <stdio.h>14 #include <string.h>15 #include "../../toolkits/toolkits.h"16 #include "../../shared/shared.h"17 #include "./matlabio.h"18 19 /*}}}*/20 21 SeqVec<double>* MatlabVectorToSeqVec(const mxArray* dataref){22 23 SeqVec<double>* output=NULL;24 25 output=new SeqVec<double>();26 MatlabVectorToDoubleVector(&output->vector,&output->M,dataref);27 return output;28 29 } -
../trunk-jpl/src/c/matlab/io/MatlabNArrayToNArray.cpp
1 /* \file MatlabNArrayToNArray.cpp2 * \brief: convert a sparse or dense matlab n-dimensional array to cpp n-dimensional array3 */4 5 #ifdef HAVE_CONFIG_H6 #include <config.h>7 #else8 #error "Cannot compile with HAVE_CONFIG_H symbol! run configure first!"9 #endif10 11 #include "../../shared/shared.h"12 #include "../../include/include.h"13 14 #include <mex.h>15 16 /*FUNCTION MatlabNArrayToNArray(double** pmatrix,int* pmatrix_numel,int* pmatrix_ndims,int** pmatrix_size,const mxArray* mxmatrix){{{*/17 int MatlabNArrayToNArray(double** pmatrix,int* pmatrix_numel,int* pmatrix_ndims,int** pmatrix_size,const mxArray* mxmatrix){18 19 int i,j,rows,cols;20 int numel,ndims;21 int *size,*dims;22 double* mxmatrix_ptr=NULL;23 const mwSize* ipt=NULL;24 25 /*output: */26 double* matrix=NULL;27 28 /*matlab indices: */29 mwIndex *ir = NULL;30 mwIndex *jc = NULL;31 double *pr = NULL;32 int count;33 34 /*get Matlab matrix information: */35 numel=mxGetNumberOfElements(mxmatrix);36 ndims=mxGetNumberOfDimensions(mxmatrix);37 ipt =mxGetDimensions(mxmatrix);38 size =xNew<int>(ndims);39 for (i=0;i<ndims;i++) size[i]=(int)ipt[i];40 41 /*Ok, first check if we are dealing with a sparse or full matrix: */42 if (mxIsSparse(mxmatrix)){43 44 /*Dealing with sparse matrix: recover size first: */45 rows = mxGetM(mxmatrix);46 cols = mxGetN(mxmatrix);47 48 matrix=xNewZeroInit<double>(rows*cols);49 50 /*Now, get ir,jc and pr: */51 ir = mxGetIr(mxmatrix);52 jc = mxGetJc(mxmatrix);53 pr = mxGetPr(mxmatrix);54 55 /*Now, start inserting data into double* matrix: */56 count=0;57 for(i=0;i<cols;i++){58 for(j=0;j<(jc[i+1]-jc[i]);j++){59 *(matrix+rows*ir[count]+i)=pr[count];60 count++;61 }62 }63 64 }65 else{66 67 /*Dealing with dense matrix: recover pointer and size: */68 mxmatrix_ptr=(double*)mxGetPr(mxmatrix);69 70 /*Create serial matrix: */71 matrix=xNewZeroInit<double>(numel);72 73 dims=xNew<int>(ndims);74 for(i=0;i<numel;i++){75 ColumnWiseDimsFromIndex(dims,i,size,ndims);76 j = IndexFromRowWiseDims(dims,size,ndims);77 matrix[j]=(double)mxmatrix_ptr[i];78 }79 xDelete<int>(dims);80 }81 82 /*Assign output pointer: */83 *pmatrix = matrix;84 *pmatrix_numel = numel;85 *pmatrix_ndims = ndims;86 *pmatrix_size = size;87 88 return 1;89 }90 /*}}}*/91 /*FUNCTION MatlabNArrayToNArray(bool** pmatrix,int* pmatrix_numel,int* pmatrix_ndims,int** pmatrix_size,const mxArray* mxmatrix){{{*/92 int MatlabNArrayToNArray(bool** pmatrix,int* pmatrix_numel,int* pmatrix_ndims,int** pmatrix_size,const mxArray* mxmatrix){93 94 int i,j,rows,cols;95 int numel,ndims;96 int *size,*dims;97 bool* mxmatrix_ptr=NULL;98 const mwSize* ipt=NULL;99 100 /*output: */101 bool* matrix=NULL;102 103 /*matlab indices: */104 mwIndex *ir = NULL;105 mwIndex *jc = NULL;106 bool *pm = NULL;107 int count;108 109 /*get Matlab matrix information: */110 numel = mxGetNumberOfElements(mxmatrix);111 ndims = mxGetNumberOfDimensions(mxmatrix);112 ipt = mxGetDimensions(mxmatrix);113 size = xNew<int>(ndims);114 for (i=0;i<ndims;i++) size[i]=(int)ipt[i];115 116 /*Ok, first check if we are dealing with a sparse or full matrix: */117 if (mxIsSparse(mxmatrix)){118 119 /*Dealing with sparse matrix: recover size first: */120 rows=mxGetM(mxmatrix);121 cols=mxGetN(mxmatrix);122 matrix=xNewZeroInit<bool>(rows*cols);123 124 /*Now, get ir,jc and pm: */125 ir=mxGetIr(mxmatrix);126 jc=mxGetJc(mxmatrix);127 pm=(bool*)mxGetData(mxmatrix);128 129 /*Now, start inserting data into bool* matrix: */130 count=0;131 for(i=0;i<cols;i++){132 for(j=0;j<(jc[i+1]-jc[i]);j++){133 matrix[rows*ir[count]+i]=pm[count];134 count++;135 }136 }137 }138 else{139 140 /*Dealing with dense matrix: recover pointer and size: */141 mxmatrix_ptr=(bool*)mxGetData(mxmatrix);142 143 /*Create serial matrix: */144 matrix=xNew<bool>(numel);145 dims=xNew<int>(ndims);146 for(i=0;i<numel;i++){147 ColumnWiseDimsFromIndex(dims,i,size,ndims);148 j=IndexFromRowWiseDims(dims,size,ndims);149 matrix[j]=(bool)mxmatrix_ptr[i];150 }151 xDelete<int>(dims);152 }153 154 /*Assign output pointer: */155 *pmatrix = matrix;156 *pmatrix_numel = numel;157 *pmatrix_ndims = ndims;158 *pmatrix_size = size;159 160 return 1;161 }162 /*}}}*/163 /*FUNCTION MatlabNArrayToNArray(char** pmatrix,int* pmatrix_numel,int* pmatrix_ndims,int** pmatrix_size,const mxArray* mxmatrix){{{*/164 int MatlabNArrayToNArray(char** pmatrix,int* pmatrix_numel,int* pmatrix_ndims,int** pmatrix_size,const mxArray* mxmatrix){165 166 int i,j,rows,cols;167 int numel,ndims;168 int *size , *dims;169 mxChar *mxmatrix_ptr = NULL;170 const mwSize *ipt = NULL;171 172 /*output: */173 char* matrix=NULL;174 175 /*matlab indices: */176 mwIndex *ir = NULL;177 mwIndex *jc = NULL;178 char *pm = NULL;179 int count;180 181 /*get Matlab matrix information: */182 numel = mxGetNumberOfElements(mxmatrix);183 ndims = mxGetNumberOfDimensions(mxmatrix);184 ipt = mxGetDimensions(mxmatrix);185 size = xNew<int>(ndims);186 for (i=0;i<ndims;i++) size[i]=(int)ipt[i];187 188 /*Ok, first check if we are dealing with a sparse or full matrix: */189 if (mxIsSparse(mxmatrix)){190 191 /*Dealing with sparse matrix: recover size first: */192 rows = mxGetM(mxmatrix);193 cols = mxGetN(mxmatrix);194 matrix=xNew<char>(rows*cols);195 196 /*Now, get ir,jc and pm: */197 ir = mxGetIr(mxmatrix);198 jc = mxGetJc(mxmatrix);199 pm = (char*)mxGetData(mxmatrix);200 201 /*Now, start inserting data into char* matrix: */202 count=0;203 for(i=0;i<cols;i++){204 for(j=0;j<(jc[i+1]-jc[i]);j++){205 matrix[rows*ir[count]+i]=(char)pm[count];206 count++;207 }208 }209 }210 else{211 /*Dealing with dense matrix: recover pointer and size: */212 mxmatrix_ptr=mxGetChars(mxmatrix);213 214 /*Create serial matrix: */215 matrix=xNew<char>(numel+1);216 matrix[numel]='\0';217 218 /*looping code adapted from Matlab example explore.c: */219 int elements_per_page = size[0] * size[1];220 /* total_number_of_pages = size[2] x size[3] x ... x size[N-1] */221 int total_number_of_pages = 1;222 for (i=2; i<ndims; i++) {223 total_number_of_pages *= size[i];224 }225 226 i=0;227 for (int page=0; page < total_number_of_pages; page++) {228 int row;229 /* On each page, walk through each row. */230 for (row=0; row<size[0]; row++) {231 int column;232 j = (page * elements_per_page) + row;233 234 /* Walk along each column in the current row. */235 for (column=0; column<size[1]; column++) {236 *(matrix+i++)=(char)*(mxmatrix_ptr+j);237 j += size[0];238 }239 }240 }241 }242 243 /*Assign output pointer: */244 *pmatrix = matrix;245 *pmatrix_numel = numel;246 *pmatrix_ndims = ndims;247 *pmatrix_size = size;248 249 return 1;250 }251 /*}}}*/ -
../trunk-jpl/src/c/matlab/io/MatlabMatrixToMatrix.cpp
1 /*!\file MatlabMatrixToMatrix.cpp2 */3 4 /*Headers:*/5 /*{{{*/6 #ifdef HAVE_CONFIG_H7 #include <config.h>8 #else9 #error "Cannot compile with HAVE_CONFIG_H symbol! run configure first!"10 #endif11 12 #include <mex.h>13 #include <stdio.h>14 #include <string.h>15 #include "./matlabio.h"16 #include "../../classes/classes.h"17 #include "../../shared/shared.h"18 #include "../../Container/Container.h"19 #include "../../include/include.h"20 #include "../../toolkits/toolkits.h"21 22 /*}}}*/23 24 Matrix<double>* MatlabMatrixToMatrix(const mxArray* mxmatrix){25 26 int dummy;27 Matrix<double>* matrix=NULL;28 29 /*allocate matrix object: */30 matrix=new Matrix<double>();31 32 #ifdef _HAVE_PETSC_33 matrix->pmatrix=MatlabMatrixToPetscMat(mxmatrix);34 #else35 matrix->smatrix=MatlabMatrixToSeqMat(mxmatrix);36 #endif37 38 return matrix;39 } -
../trunk-jpl/src/c/toolkits/python/pythonincludes.h
1 /* \file pythonincludes.h2 * \brief all includes for PYTHON layer3 */4 5 #ifndef _PYTHON_INCLUDES_H_6 #define _PYTHON_INCLUDES_H_7 8 #ifdef HAVE_CONFIG_H9 #include <config.h>10 #else11 #error "Cannot compile with HAVE_CONFIG_H symbol! run configure first!"12 #endif13 14 #if _PYTHON_MAJOR_ == 215 #undef NPY_NO_DEPRECATED_API16 #define NPY_NO_DEPRECATED_API NPY_1_7_API_VERSION17 #else18 #define NPY_NO_DEPRECATED_API19 #endif20 21 #include "Python.h"22 #include "arrayobject.h"23 24 #endif -
../trunk-jpl/src/c/toolkits/toolkits.h
11 11 #error "Cannot compile with HAVE_CONFIG_H symbol! run configure first!" 12 12 #endif 13 13 14 #ifdef _HAVE_PYTHON_15 #include "./python/pythonincludes.h"16 #endif17 18 14 #ifdef _HAVE_PETSC_ 19 15 #include "./petsc/petscincludes.h" 20 16 #endif … … 30 26 #include "./triangle/triangleincludes.h" 31 27 #include "./toolkitsenums.h" 32 28 #include "./issm/issmtoolkit.h" 33 34 29 #endif -
../trunk-jpl/src/c/Makefile.am
1 AM_CPPFLAGS = @DAKOTAINCL@ @SHAPELIBINCL@ @PETSCINCL@ @SLEPCINCL@ @MPIINCL@ @M ATLABINCL@ @METISINCL@ @CHACOINCL@ @SCOTCHINCL@ @PLAPACKINCL@ @BLASLAPACKINCL@ @MKLINCL@ @MUMPSINCL@ @TRIANGLEINCL@ @SPAIINCL@ @HYPREINCL@ @PROMETHEUSINCL@ @SUPERLUINCL@ @SPOOLESINCL@ @PASTIXINCL@ @MLINCL@ @TAOINCL@ @ADIC2INCL@ @ADOLCINCL@ @GSLINCL@ @BOOSTINCL@ @PYTHONINCL@ @PYTHON_NUMPYINCL@1 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@ 2 2 3 3 EXEEXT=$(ISSMEXT) 4 4 … … 8 8 if SHAREDLIBS 9 9 lib_LTLIBRARIES = libISSMCore.la libISSMOverload.la libISSM.la 10 10 endif 11 if PYTHON12 lib_LIBRARIES += libISSMPython.a13 endif14 if MATLAB15 if SHAREDLIBS16 lib_LTLIBRARIES += libISSMMatlab.la17 endif18 lib_LIBRARIES += libISSMMatlab.a19 endif20 11 if WRAPPERS 21 12 if SHAREDLIBS 22 13 lib_LTLIBRARIES += libISSMWrappers.la … … 763 754 metis_sources= ./toolkits/metis/patches/metispatches.h\ 764 755 ./toolkits/metis/patches/METIS_PartMeshNodalPatch.cpp 765 756 #}}} 766 #Python sources {{{767 python_sources= ./python/io/pythonio.h\768 ./python/python-binding.h\769 ./python/io/WritePythonData.cpp\770 ./python/io/CheckNumPythonArguments.cpp\771 ./python/io/FetchPythonData.cpp772 773 #}}}774 #Matlab sources {{{775 matlab_sources= ./toolkits/matlab/matlabincludes.h\776 ./matlab/matlab-binding.h\777 ./matlab/io/matlabio.h\778 ./matlab/io/MatlabNArrayToNArray.cpp\779 ./matlab/io/CheckNumMatlabArguments.cpp\780 ./matlab/io/mxGetAssignedField.cpp\781 ./matlab/io/WriteMatlabData.cpp\782 ./matlab/io/FetchMatlabData.cpp\783 ./matlab/io/OptionParse.cpp\784 ./matlab/io/MatlabMatrixToMatrix.cpp\785 ./matlab/io/MatlabVectorToVector.cpp\786 ./matlab/io/MatlabVectorToDoubleVector.cpp\787 ./matlab/io/MatlabMatrixToDoubleMatrix.cpp\788 ./matlab/io/MatlabMatrixToSeqMat.cpp\789 ./matlab/io/MatlabVectorToSeqVec.cpp790 #}}}791 #Matlab and Petsc sources {{{792 matlabpetsc_sources= ./matlab/io/MatlabMatrixToPetscMat.cpp\793 ./matlab/io/MatlabVectorToPetscVec.cpp794 795 #}}}796 757 #Wrappers sources{{{ 797 758 wrapper_sources= ./shared/Threads/issm_threads.h\ 798 759 ./shared/Threads/LaunchThread.cpp\ … … 944 905 issm_sources += $(metis_sources) 945 906 endif 946 907 947 if PETSC948 if MATLAB949 issm_sources += $(matlabpetsc_sources)950 endif951 endif952 953 908 if KRIGING 954 909 issm_sources += $(pkriging_sources) 955 910 endif … … 986 941 endif 987 942 endif 988 943 989 if PYTHON990 libISSMPython_a_SOURCES = $(python_sources)991 libISSMPython_a_CXXFLAGS= $(ALLCXXFLAGS)992 endif993 994 if MATLAB995 libISSMMatlab_a_SOURCES = $(matlab_sources)996 libISSMMatlab_a_CXXFLAGS= $(ALLCXXFLAGS)997 if SHAREDLIBS998 libISSMMatlab_la_SOURCES = $(libISSMMatlab_a_SOURCES)999 endif1000 endif1001 1002 944 if VERSION 1003 945 AM_LDFLAGS = 1004 946 else -
../trunk-jpl/src/wrappers/python/include/wrapper_macros.h
1 /* \file python_macros.h 2 * \brief: macros used for the python bindings 3 */ 4 5 #ifndef _PY_WRAPPER_MACROS_H_ 6 #define _PY_WRAPPER_MACROS_H_ 7 8 #ifdef HAVE_CONFIG_H 9 #include <config.h> 10 #else 11 #error "Cannot compile with HAVE_CONFIG_H symbol! run configure first!" 12 #endif 13 14 #ifdef _HAVE_PYTHON_ 15 /* MODULEBOOT/MODULEEND {{{*/ 16 17 /*The following macros hide the error exception handling in a matlab module. Just put 18 * MODULEBOOT(); and MODULEEND(); at the beginning and end of a module, and c++ exceptions 19 * will be trapped*/ 20 #define MODULEBOOT(); \ 21 PyObject *output = PyTuple_New(NLHS); \ 22 int nrhs = (int)PyTuple_Size(args); \ 23 if(!output) return NULL;\ 24 try{ \ 25 IssmComm::SetComm(-1); 26 27 #define MODULEEND(); }\ 28 catch(ErrorException &exception){\ 29 PyErr_SetString(PyExc_TypeError,exception.PythonReport()); \ 30 return NULL;\ 31 } \ 32 catch (exception &e){\ 33 PyErr_SetString(PyExc_TypeError,exprintf("Standard exception: %s\n",e.what()));\ 34 return NULL;\ 35 }\ 36 catch(...){\ 37 PyErr_SetString(PyExc_TypeError,"An unexpected error occurred");\ 38 return NULL;\ 39 }\ 40 return output; 41 //}}} 42 #if _PYTHON_MAJOR_ >=3 43 /* WRAPPER 3.2 {{{*/ 44 #define WRAPPER(modulename,...) \ 45 \ 46 static PyObject* modulename(PyObject* self,PyObject* args);\ 47 static PyMethodDef modulename##_funcs[] = {\ 48 {#modulename, (PyCFunction)modulename, METH_VARARGS, ""},\ 49 {NULL,NULL,0,NULL}\ 50 };\ 51 \ 52 static struct PyModuleDef modulename##module= {\ 53 PyModuleDef_HEAD_INIT,\ 54 #modulename, /* name of module */\ 55 NULL, /* module documentation, may be NULL */\ 56 -1, /* size of per-interpreter state of the module,\ 57 or -1 if the module keeps state in global variables. */\ 58 modulename##_funcs\ 59 };\ 60 \ 61 PyMODINIT_FUNC PyInit_##modulename(void){\ 62 \ 63 import_array();\ 64 return PyModule_Create(&modulename##module);\ 65 }\ 66 \ 67 static PyObject* modulename(PyObject* self,PyObject* args) 68 /*}}}*/ 69 #else 70 /* WRAPPER 2.7 {{{*/ 71 #define WRAPPER(modulename,...) \ 72 \ 73 static PyObject* modulename(PyObject* self,PyObject* args);\ 74 static PyMethodDef modulename##_funcs[] = {\ 75 {#modulename, (PyCFunction)modulename, METH_VARARGS, ""},\ 76 {NULL,NULL,0,NULL}\ 77 };\ 78 \ 79 PyMODINIT_FUNC init##modulename(void){\ 80 \ 81 import_array();\ 82 (void) Py_InitModule(#modulename, modulename##_funcs);\ 83 }\ 84 \ 85 static PyObject* modulename(PyObject* self,PyObject* args) 86 /*}}}*/ 87 #endif 88 /* CHECKARGUMENTS {{{*/ 89 #define CHECKARGUMENTS(NLHS,NRHS,functionpointer) CheckNumPythonArguments(args, NRHS,functionpointer) 90 /*}}}*/ 91 #endif 92 #endif -
../trunk-jpl/src/wrappers/python/io/pythonio.h
1 /*\file pythonio.h 2 *\brief: I/O for ISSM in python mode 3 */ 4 5 #ifndef _PYTHON_IO_H_ 6 #define _PYTHON_IO_H_ 7 8 #ifdef HAVE_CONFIG_H 9 #include <config.h> 10 #else 11 #error "Cannot compile with HAVE_CONFIG_H symbol! run configure first!" 12 #endif 13 14 #include "../include/pythonincludes.h" 15 #include "../../c/classes/classes.h" 16 #include "../../c/Container/Container.h" 17 #include "../../c/include/include.h" 18 19 void WriteData(PyObject* py_tuple,int index, double* matrix, int M,int N); 20 void WriteData(PyObject* py_tuple,int index, int integer); 21 void WriteData(PyObject* py_tuple,int index, char* string); 22 void WriteData(PyObject* py_tuple,int index); 23 void WriteData(PyObject* py_tuple,int index, SeqMat<double>* matrix); 24 void WriteData(PyObject* py_tuple,int index, SeqVec<double>* vector); 25 void WriteData(PyObject* py_tuple,int index, BamgGeom* bamggeom); 26 void WriteData(PyObject* py_tuple,int index, BamgMesh* bamgmesh); 27 void WriteData(PyObject* py_tuple,int index, RiftStruct* riftstruct); 28 29 void FetchData(double** pvector,int* pM,PyObject* py_ref); 30 void FetchData(double** pmatrix,int* pM,int *pN,PyObject* py_array); 31 void FetchData(int** pmatrix,int* pM,int *pN,PyObject* py_matrix); 32 void FetchData(char** pstring,PyObject* py_unicode); 33 void FetchData(double* pscalar,PyObject* py_float); 34 void FetchData(int* pinteger,PyObject* py_long); 35 void FetchData(bool* pbool,PyObject* py_boolean); 36 void FetchData(BamgGeom** bamggeom,PyObject* py_dict); 37 void FetchData(BamgMesh** bamgmesh,PyObject* py_dict); 38 void FetchData(BamgOpts** bamgopts,PyObject* py_dict); 39 void FetchData(Options** poptions,int istart, int nrhs,PyObject* py_tuple); 40 void FetchData(DataSet** pcontours,PyObject* py_list); 41 42 int CheckNumPythonArguments(PyObject* inputs,int NRHS, void (*function)( void )); 43 44 /*Utils*/ 45 PyObject* PyArrayFromCopiedData(int dims[2],double* data); 46 PyObject* PyArrayFromCopiedData(int dimi,int dimj,double* data); 47 48 #endif /* _IO_H_ */ -
../trunk-jpl/src/wrappers/python/io/CheckNumPythonArguments.cpp
1 /*!\file CheckNumPythonArguments.cpp: 2 * \brief: check number of arguments and report an usage error message. 3 */ 4 5 #define PY_ARRAY_UNIQUE_SYMBOL PythonIOSymbol 6 #define NO_IMPORT 7 8 #include "./pythonio.h" 9 #include "../../c/shared/Exceptions/exceptions.h" 10 #include "../../c/include/include.h" 11 12 int CheckNumPythonArguments(PyObject* inputs,int NRHS, void (*function)( void )){ 13 14 Py_ssize_t size=0; 15 16 /*figure out size of tuple in input: */ 17 size=PyTuple_Size(inputs); 18 19 /*check on requested size: */ 20 if (size==0){ 21 function(); 22 _error_("usage: see above"); 23 } 24 else if (size!=NRHS ) { 25 function(); 26 _error_("usage error."); 27 } 28 return 1; 29 } -
../trunk-jpl/src/wrappers/python/io/FetchPythonData.cpp
1 /*\file FetchData.cpp: 2 * \brief: general I/O interface to fetch data in python 3 */ 4 5 #ifdef HAVE_CONFIG_H 6 #include <config.h> 7 #else 8 #error "Cannot compile with HAVE_CONFIG_H symbol! run configure first!" 9 #endif 10 11 #define PY_ARRAY_UNIQUE_SYMBOL PythonIOSymbol 12 #define NO_IMPORT 13 14 #include "./pythonio.h" 15 #include "../../c/include/include.h" 16 #include "../../c/shared/shared.h" 17 18 /*Primitive data types*/ 19 /*FUNCTION FetchData(double* pscalar,PyObject* py_float){{{*/ 20 void FetchData(double* pscalar,PyObject* py_float){ 21 22 double scalar; 23 24 /*return internal value: */ 25 scalar=PyFloat_AsDouble(py_float); 26 27 /*output: */ 28 *pscalar=scalar; 29 } 30 /*}}}*/ 31 /*FUNCTION FetchData(int* pinteger,PyObject* py_long){{{*/ 32 void FetchData(int* pinteger, PyObject* py_long){ 33 34 int integer; 35 36 /*return internal value: */ 37 integer=(int)PyLong_AsLong(py_long); 38 39 /*output: */ 40 *pinteger=integer; 41 } 42 /*}}}*/ 43 /*FUNCTION FetchData(bool* pboolean,PyObject* py_boolean){{{*/ 44 void FetchData(bool* pboolean,PyObject* py_boolean){ 45 46 bool boolean; 47 48 /*check this is indeed a subtype of long type: */ 49 if(!PyBool_Check(py_boolean))_error_("expecting a boolean in input!"); 50 51 /*extract boolean: */ 52 boolean=(bool)PyLong_AsLong(py_boolean); 53 54 /*simple copy: */ 55 *pboolean=boolean; 56 57 } 58 /*}}}*/ 59 /*FUNCTION FetchData(double** pmatrix,int* pM, int* pN, PyObject* py_matrix){{{*/ 60 void FetchData(double** pmatrix,int* pM,int *pN,PyObject* py_matrix){ 61 62 /*output: */ 63 double* dmatrix=NULL; 64 double* matrix=NULL; 65 int M,N; 66 int ndim; 67 npy_intp* dims=NULL; 68 69 /*retrive dimensions: */ 70 ndim=PyArray_NDIM((const PyArrayObject*)py_matrix); 71 if(ndim!=2)_error_("expecting an MxN matrix in input!"); 72 dims=PyArray_DIMS((PyArrayObject*)py_matrix); 73 M=dims[0]; N=dims[1]; 74 75 if (M && N) { 76 /*retrieve internal value: */ 77 dmatrix=(double*)PyArray_DATA((PyArrayObject*)py_matrix); 78 79 /*copy matrix: */ 80 matrix=xNew<double>(M*N); 81 memcpy(matrix,dmatrix,(M*N)*sizeof(double)); 82 } 83 else 84 matrix=NULL; 85 86 /*output: */ 87 if(pM)*pM=M; 88 if(pN)*pN=N; 89 if(pmatrix)*pmatrix=matrix; 90 } 91 /*}}}*/ 92 /*FUNCTION FetchData(int** pmatrix,int* pM, int* pN, PyObject* py_matrix){{{*/ 93 void FetchData(int** pmatrix,int* pM,int *pN,PyObject* py_matrix){ 94 95 /*output: */ 96 double* dmatrix=NULL; 97 int* matrix=NULL; 98 int M,N; 99 100 /*intermediary:*/ 101 int i; 102 int ndim; 103 npy_intp* dims=NULL; 104 105 /*retrive dimensions: */ 106 ndim=PyArray_NDIM((const PyArrayObject*)py_matrix); 107 if(ndim!=2)_error_("expecting an MxN matrix in input!"); 108 dims=PyArray_DIMS((PyArrayObject*)py_matrix); 109 M=dims[0]; N=dims[1]; 110 111 if (M && N) { 112 /*retrieve internal value: */ 113 dmatrix=(double*)PyArray_DATA((PyArrayObject*)py_matrix); 114 115 /*transform into integer matrix: */ 116 matrix=xNew<int>(M*N); 117 for(i=0;i<M*N;i++)matrix[i]=(int)dmatrix[i]; 118 } 119 else 120 matrix=NULL; 121 122 /*output: */ 123 if(pM)*pM=M; 124 if(pN)*pN=N; 125 if(pmatrix)*pmatrix=matrix; 126 } 127 /*}}}*/ 128 /*FUNCTION FetchData(double** pvector,int* pM, PyObject* py_vector){{{*/ 129 void FetchData(double** pvector,int* pM,PyObject* py_vector){ 130 131 /*output: */ 132 double* dvector=NULL; 133 double* vector=NULL; 134 int M; 135 int ndim; 136 npy_intp* dims=NULL; 137 138 /*retrive dimensions: */ 139 ndim=PyArray_NDIM((const PyArrayObject*)py_vector); 140 if(ndim!=1)_error_("expecting an Mx1 vector in input!"); 141 dims=PyArray_DIMS((PyArrayObject*)py_vector); 142 M=dims[0]; 143 144 if (M) { 145 /*retrieve internal value: */ 146 dvector=(double*)PyArray_DATA((PyArrayObject*)py_vector); 147 148 /*copy vector: */ 149 vector=xNew<double>(M); 150 memcpy(vector,dvector,(M)*sizeof(double)); 151 } 152 else 153 vector=NULL; 154 155 /*output: */ 156 if(pM)*pM=M; 157 if(pvector)*pvector=vector; 158 } 159 /*}}}*/ 160 161 /*ISSM objects*/ 162 /*FUNCTION FetchData(BamgGeom** pbamggeom,PyObject* py_dict){{{*/ 163 void FetchData(BamgGeom** pbamggeom,PyObject* py_dict){ 164 165 /*Initialize output*/ 166 BamgGeom* bamggeom=new BamgGeom(); 167 168 /*Fetch all fields*/ 169 FetchData(&bamggeom->Vertices,&bamggeom->VerticesSize[0],&bamggeom->VerticesSize[1],PyDict_GetItemString(py_dict,"Vertices")); 170 FetchData(&bamggeom->Edges, &bamggeom->EdgesSize[0], &bamggeom->EdgesSize[1], PyDict_GetItemString(py_dict,"Edges")); 171 FetchData(&bamggeom->Corners, &bamggeom->CornersSize[0], &bamggeom->CornersSize[1], PyDict_GetItemString(py_dict,"Corners")); 172 FetchData(&bamggeom->RequiredVertices,&bamggeom->RequiredVerticesSize[0],&bamggeom->RequiredVerticesSize[1],PyDict_GetItemString(py_dict,"RequiredVertices")); 173 FetchData(&bamggeom->RequiredEdges, &bamggeom->RequiredEdgesSize[0], &bamggeom->RequiredEdgesSize[1], PyDict_GetItemString(py_dict,"RequiredEdges")); 174 FetchData(&bamggeom->CrackedEdges,&bamggeom->CrackedEdgesSize[0],&bamggeom->CrackedEdgesSize[1],PyDict_GetItemString(py_dict,"CrackedEdges")); 175 FetchData(&bamggeom->SubDomains,&bamggeom->SubDomainsSize[0],&bamggeom->SubDomainsSize[1],PyDict_GetItemString(py_dict,"SubDomains")); 176 177 /*Assign output pointers:*/ 178 *pbamggeom=bamggeom; 179 } 180 /*}}}*/ 181 /*FUNCTION FetchData(BamgMesh** pbamgmesh,PyObject* py_dict){{{*/ 182 void FetchData(BamgMesh** pbamgmesh,PyObject* py_dict){ 183 184 /*Initialize output*/ 185 BamgMesh* bamgmesh=new BamgMesh(); 186 187 /*Fetch all fields*/ 188 FetchData(&bamgmesh->Vertices,&bamgmesh->VerticesSize[0],&bamgmesh->VerticesSize[1],PyDict_GetItemString(py_dict,"Vertices")); 189 FetchData(&bamgmesh->Edges, &bamgmesh->EdgesSize[0], &bamgmesh->EdgesSize[1], PyDict_GetItemString(py_dict,"Edges")); 190 FetchData(&bamgmesh->Triangles, &bamgmesh->TrianglesSize[0], &bamgmesh->TrianglesSize[1], PyDict_GetItemString(py_dict,"Triangles")); 191 FetchData(&bamgmesh->CrackedEdges,&bamgmesh->CrackedEdgesSize[0],&bamgmesh->CrackedEdgesSize[1],PyDict_GetItemString(py_dict,"CrackedEdges")); 192 FetchData(&bamgmesh->VerticesOnGeomEdge,&bamgmesh->VerticesOnGeomEdgeSize[0],&bamgmesh->VerticesOnGeomEdgeSize[1],PyDict_GetItemString(py_dict,"VerticesOnGeomEdge")); 193 FetchData(&bamgmesh->VerticesOnGeomVertex,&bamgmesh->VerticesOnGeomVertexSize[0],&bamgmesh->VerticesOnGeomVertexSize[1],PyDict_GetItemString(py_dict,"VerticesOnGeomVertex")); 194 FetchData(&bamgmesh->EdgesOnGeomEdge, &bamgmesh->EdgesOnGeomEdgeSize[0], &bamgmesh->EdgesOnGeomEdgeSize[1], PyDict_GetItemString(py_dict,"EdgesOnGeomEdge")); 195 FetchData(&bamgmesh->IssmSegments,&bamgmesh->IssmSegmentsSize[0],&bamgmesh->IssmSegmentsSize[1],PyDict_GetItemString(py_dict,"IssmSegments")); 196 197 /*Assign output pointers:*/ 198 *pbamgmesh=bamgmesh; 199 } 200 /*}}}*/ 201 /*FUNCTION FetchData(BamgOpts** pbamgopts,PyObject* py_dict){{{*/ 202 void FetchData(BamgOpts** pbamgopts,PyObject* py_dict){ 203 204 /*Initialize output*/ 205 BamgOpts* bamgopts=new BamgOpts(); 206 207 /*Fetch all fields*/ 208 FetchData(&bamgopts->anisomax,PyDict_GetItemString(py_dict,"anisomax")); 209 FetchData(&bamgopts->cutoff,PyDict_GetItemString(py_dict,"cutoff")); 210 FetchData(&bamgopts->coeff,PyDict_GetItemString(py_dict,"coeff")); 211 FetchData(&bamgopts->errg,PyDict_GetItemString(py_dict,"errg")); 212 FetchData(&bamgopts->gradation,PyDict_GetItemString(py_dict,"gradation")); 213 FetchData(&bamgopts->Hessiantype,PyDict_GetItemString(py_dict,"Hessiantype")); 214 FetchData(&bamgopts->MaxCornerAngle,PyDict_GetItemString(py_dict,"MaxCornerAngle")); 215 FetchData(&bamgopts->maxnbv,PyDict_GetItemString(py_dict,"maxnbv")); 216 FetchData(&bamgopts->maxsubdiv,PyDict_GetItemString(py_dict,"maxsubdiv")); 217 FetchData(&bamgopts->Metrictype,PyDict_GetItemString(py_dict,"Metrictype")); 218 FetchData(&bamgopts->nbjacobi,PyDict_GetItemString(py_dict,"nbjacobi")); 219 FetchData(&bamgopts->nbsmooth,PyDict_GetItemString(py_dict,"nbsmooth")); 220 FetchData(&bamgopts->omega,PyDict_GetItemString(py_dict,"omega")); 221 FetchData(&bamgopts->power,PyDict_GetItemString(py_dict,"power")); 222 FetchData(&bamgopts->verbose,PyDict_GetItemString(py_dict,"verbose")); 223 224 FetchData(&bamgopts->Crack,PyDict_GetItemString(py_dict,"Crack")); 225 FetchData(&bamgopts->geometricalmetric,PyDict_GetItemString(py_dict,"geometricalmetric")); 226 FetchData(&bamgopts->KeepVertices,PyDict_GetItemString(py_dict,"KeepVertices")); 227 FetchData(&bamgopts->splitcorners,PyDict_GetItemString(py_dict,"splitcorners")); 228 229 FetchData(&bamgopts->hmin,PyDict_GetItemString(py_dict,"hmin")); 230 FetchData(&bamgopts->hmax,PyDict_GetItemString(py_dict,"hmax")); 231 FetchData(&bamgopts->hminVertices,&bamgopts->hminVerticesSize[0],&bamgopts->hminVerticesSize[1],PyDict_GetItemString(py_dict,"hminVertices")); 232 FetchData(&bamgopts->hmaxVertices,&bamgopts->hmaxVerticesSize[0],&bamgopts->hmaxVerticesSize[1],PyDict_GetItemString(py_dict,"hmaxVertices")); 233 FetchData(&bamgopts->hVertices,&bamgopts->hVerticesSize[0],&bamgopts->hVerticesSize[1],PyDict_GetItemString(py_dict,"hVertices")); 234 FetchData(&bamgopts->metric,&bamgopts->metricSize[0],&bamgopts->metricSize[1],PyDict_GetItemString(py_dict,"metric")); 235 FetchData(&bamgopts->field,&bamgopts->fieldSize[0],&bamgopts->fieldSize[1],PyDict_GetItemString(py_dict,"field")); 236 FetchData(&bamgopts->err,&bamgopts->errSize[0],&bamgopts->errSize[1],PyDict_GetItemString(py_dict,"err")); 237 238 /*Additional checks*/ 239 bamgopts->Check(); 240 241 /*Assign output pointers:*/ 242 *pbamgopts=bamgopts; 243 } 244 /*}}}*/ 245 /*FUNCTION FetchData(Options** poptions,int istart, int nrhs,PyObject* py_tuple){{{*/ 246 void FetchData(Options** poptions,int istart, int nrhs,PyObject* py_tuple){ 247 248 char *name = NULL; 249 Option *option = NULL; 250 251 /*Initialize output*/ 252 Options* options=new Options(); 253 254 /*Fetch all options*/ 255 for (int i=istart; i<nrhs; i=i+2){ 256 if (!PyString_Check(PyTuple_GetItem(py_tuple,(Py_ssize_t)i))) _error_("Argument " << i+1 << " must be name of option"); 257 258 FetchData(&name,PyTuple_GetItem(py_tuple,(Py_ssize_t)i)); 259 if(i+1 == nrhs) _error_("Argument " << i+2 << " must exist and be value of option \"" << name << "\"."); 260 261 _pprintLine_("FetchData for Options not implemented yet, ignoring option \"" << name << "\"!"); 262 263 // option=(Option*)OptionParse(name,&PyTuple_GetItem(py_tuple,(Py_ssize_t)(i+1))); 264 // options->AddOption(option); 265 // option=NULL; 266 } 267 268 /*Assign output pointers:*/ 269 *poptions=options; 270 } 271 /*}}}*/ 272 /*FUNCTION FetchData(DataSet** pcontours,PyObject* py_list){{{*/ 273 void FetchData(DataSet** pcontours,PyObject* py_list){ 274 275 int numcontours,test1,test2; 276 char *contourname = NULL; 277 DataSet *contours = NULL; 278 Contour<double> *contouri = NULL; 279 PyObject *py_dicti = NULL; 280 PyObject *py_item = NULL; 281 282 if (PyString_Check(py_list)){ 283 FetchData(&contourname,py_list); 284 contours=DomainOutlineRead<double>(contourname); 285 } 286 else if(PyList_Check(py_list)){ 287 288 contours=new DataSet(0); 289 numcontours=(int)PyList_Size(py_list); 290 291 for(int i=0;i<numcontours;i++){ 292 293 contouri=xNew<Contour<double> >(1); 294 py_dicti=PyList_GetItem(py_list,(Py_ssize_t)i); 295 296 py_item = PyDict_GetItemString(py_dicti,"nods"); 297 if(!py_item) _error_("input structure does not have a 'nods' field"); 298 FetchData(&contouri->nods,py_item); 299 300 py_item = PyDict_GetItemString(py_dicti,"x"); 301 if(!py_item) _error_("input structure does not have a 'x' field"); 302 FetchData(&contouri->x,&test1,&test2,py_item); 303 if(test1!=contouri->nods || test2!=1) _error_("field x should be of size ["<<contouri->nods<<" 1]"); 304 305 py_item = PyDict_GetItemString(py_dicti,"y"); 306 if(!py_item) _error_("input structure does not have a 'y' field"); 307 FetchData(&contouri->y,&test1,&test2,py_item); 308 if(test1!=contouri->nods || test2!=1) _error_("field y should be of size ["<<contouri->nods<<" 1]"); 309 310 contours->AddObject(contouri); 311 } 312 } 313 else{ 314 _error_("Contour is neither a string nor a structure and cannot be loaded"); 315 } 316 317 /*clean-up and assign output pointer*/ 318 xDelete<char>(contourname); 319 *pcontours=contours; 320 } 321 /*}}}*/ 322 323 /*Python version dependent: */ 324 #if _PYTHON_MAJOR_ >= 3 325 /*FUNCTION FetchData(char** pstring,PyObject* py_unicode){{{*/ 326 void FetchData(char** pstring,PyObject* py_unicode){ 327 328 PyObject* py_bytes; 329 char* string=NULL; 330 331 /*convert to bytes format: */ 332 PyUnicode_FSConverter(py_unicode,&py_bytes); 333 334 /*convert from bytes to string: */ 335 string=PyBytes_AS_STRING(py_bytes); 336 337 *pstring=string; 338 } 339 /*}}}*/ 340 #else 341 /*FUNCTION FetchData(char** pstring,PyObject* py_string){{{*/ 342 void FetchData(char** pstring,PyObject* py_string){ 343 344 char* string=NULL; 345 346 /*extract internal string: */ 347 string=PyString_AsString(py_string); 348 349 /*copy string (note strlen does not include trailing NULL): */ 350 *pstring=xNew<char>(strlen(string)+1); 351 memcpy(*pstring,string,(strlen(string)+1)*sizeof(char)); 352 } 353 /*}}}*/ 354 #endif -
../trunk-jpl/src/wrappers/python/io/WritePythonData.cpp
1 /* \file WriteData.c: 2 * \brief: general interface for writing data 3 */ 4 5 #ifdef HAVE_CONFIG_H 6 #include <config.h> 7 #else 8 #error "Cannot compile with HAVE_CONFIG_H symbol! run configure first!" 9 #endif 10 11 #define PY_ARRAY_UNIQUE_SYMBOL PythonIOSymbol 12 #define NO_IMPORT 13 14 #include "./pythonio.h" 15 #include "../../c/include/include.h" 16 #include "../../c/Container/Container.h" 17 #include "../../c/shared/shared.h" 18 #include "../../c/EnumDefinitions/EnumDefinitions.h" 19 20 /*Primitive data types*/ 21 /*FUNCTION WriteData(PyObject* py_tuple,int index,int integer){{{*/ 22 void WriteData(PyObject* py_tuple, int index, int integer){ 23 24 PyTuple_SetItem(py_tuple, index, PyInt_FromSsize_t((Py_ssize_t)integer)); 25 26 }/*}}}*/ 27 /*FUNCTION WriteData(PyObject* py_tuple,int index,char* string){{{*/ 28 void WriteData(PyObject* py_tuple, int index, char* string){ 29 30 PyTuple_SetItem(py_tuple, index, PyUnicode_FromString(string)); 31 32 }/*}}}*/ 33 /*FUNCTION WriteData(PyObject* py_tuple,int index, double* matrix, int M, int N){{{*/ 34 void WriteData(PyObject* tuple, int index, double* matrix, int M,int N){ 35 36 npy_intp dims[2]={0,0}; 37 PyObject* array=NULL; 38 39 dims[0]=(npy_intp)M; 40 dims[1]=(npy_intp)N; 41 array=PyArray_SimpleNewFromData(2,dims,NPY_DOUBLE,matrix); 42 43 PyTuple_SetItem(tuple, index, array); 44 }/*}}}*/ 45 /*FUNCTION WriteData(PyObject* py_tuple,int index){{{*/ 46 void WriteData(PyObject* py_tuple, int index){ 47 48 PyTuple_SetItem(py_tuple, index, Py_None); 49 50 }/*}}}*/ 51 52 /*ISSM objects*/ 53 /*FUNCTION WriteData(PyObject* py_tuple,int index,BamgGeom* bamggeom){{{*/ 54 void WriteData(PyObject* py_tuple,int index,BamgGeom* bamggeom){ 55 56 PyObject* dict=NULL; 57 58 dict=PyDict_New(); 59 60 PyDict_SetItemString(dict,"Vertices",PyArrayFromCopiedData(bamggeom->VerticesSize,bamggeom->Vertices)); 61 PyDict_SetItemString(dict,"Edges",PyArrayFromCopiedData(bamggeom->EdgesSize,bamggeom->Edges)); 62 PyDict_SetItemString(dict,"TangentAtEdges",PyArrayFromCopiedData(bamggeom->TangentAtEdgesSize,bamggeom->TangentAtEdges)); 63 PyDict_SetItemString(dict,"Corners",PyArrayFromCopiedData(bamggeom->CornersSize,bamggeom->Corners)); 64 PyDict_SetItemString(dict,"RequiredVertices",PyArrayFromCopiedData(bamggeom->RequiredVerticesSize,bamggeom->RequiredVertices)); 65 PyDict_SetItemString(dict,"RequiredEdges",PyArrayFromCopiedData(bamggeom->RequiredEdgesSize,bamggeom->RequiredEdges)); 66 PyDict_SetItemString(dict,"CrackedEdges",PyArrayFromCopiedData(bamggeom->CrackedEdgesSize,bamggeom->CrackedEdges)); 67 PyDict_SetItemString(dict,"SubDomains",PyArrayFromCopiedData(bamggeom->SubDomainsSize,bamggeom->SubDomains)); 68 69 PyTuple_SetItem(py_tuple, index, dict); 70 } 71 /*}}}*/ 72 /*FUNCTION WriteData(PyObject* py_tuple,int index,BamgMesh* bamgmesh){{{*/ 73 void WriteData(PyObject* py_tuple,int index,BamgMesh* bamgmesh){ 74 75 PyObject* dict=NULL; 76 77 dict=PyDict_New(); 78 79 PyDict_SetItemString(dict,"Vertices",PyArrayFromCopiedData(bamgmesh->VerticesSize,bamgmesh->Vertices)); 80 PyDict_SetItemString(dict,"Edges",PyArrayFromCopiedData(bamgmesh->EdgesSize,bamgmesh->Edges)); 81 PyDict_SetItemString(dict,"Triangles",PyArrayFromCopiedData(bamgmesh->TrianglesSize,bamgmesh->Triangles)); 82 PyDict_SetItemString(dict,"Quadrilaterals",PyArrayFromCopiedData(bamgmesh->QuadrilateralsSize,bamgmesh->Quadrilaterals)); 83 PyDict_SetItemString(dict,"IssmEdges",PyArrayFromCopiedData(bamgmesh->IssmEdgesSize,bamgmesh->IssmEdges)); 84 PyDict_SetItemString(dict,"IssmSegments",PyArrayFromCopiedData(bamgmesh->IssmSegmentsSize,bamgmesh->IssmSegments)); 85 PyDict_SetItemString(dict,"VerticesOnGeomVertex",PyArrayFromCopiedData(bamgmesh->VerticesOnGeomVertexSize,bamgmesh->VerticesOnGeomVertex)); 86 PyDict_SetItemString(dict,"VerticesOnGeomEdge",PyArrayFromCopiedData(bamgmesh->VerticesOnGeomEdgeSize,bamgmesh->VerticesOnGeomEdge)); 87 PyDict_SetItemString(dict,"EdgesOnGeomEdge",PyArrayFromCopiedData(bamgmesh->EdgesOnGeomEdgeSize,bamgmesh->EdgesOnGeomEdge)); 88 PyDict_SetItemString(dict,"SubDomains",PyArrayFromCopiedData(bamgmesh->SubDomainsSize,bamgmesh->SubDomains)); 89 PyDict_SetItemString(dict,"SubDomainsFromGeom",PyArrayFromCopiedData(bamgmesh->SubDomainsFromGeomSize,bamgmesh->SubDomainsFromGeom)); 90 PyDict_SetItemString(dict,"ElementConnectivity",PyArrayFromCopiedData(bamgmesh->ElementConnectivitySize,bamgmesh->ElementConnectivity)); 91 PyDict_SetItemString(dict,"NodalConnectivity",PyArrayFromCopiedData(bamgmesh->NodalConnectivitySize,bamgmesh->NodalConnectivity)); 92 PyDict_SetItemString(dict,"NodalElementConnectivity",PyArrayFromCopiedData(bamgmesh->NodalElementConnectivitySize,bamgmesh->NodalElementConnectivity)); 93 PyDict_SetItemString(dict,"CrackedVertices",PyArrayFromCopiedData(bamgmesh->CrackedVerticesSize,bamgmesh->CrackedVertices)); 94 PyDict_SetItemString(dict,"CrackedEdges",PyArrayFromCopiedData(bamgmesh->CrackedEdgesSize,bamgmesh->CrackedEdges)); 95 96 PyTuple_SetItem(py_tuple, index, dict); 97 } 98 /*}}}*/ 99 /*FUNCTION WriteData(PyObject* py_tuple,int index,SeqMat<double>* matrix){{{*/ 100 void WriteData(PyObject* py_tuple,int index,SeqMat<double>* matrix){ 101 102 int M,N; 103 double* buffer=NULL; 104 npy_intp dims[2]={0,0}; 105 PyObject* array=NULL; 106 107 buffer=matrix->ToSerial(); 108 matrix->GetSize(&M,&N); 109 dims[0]=(npy_intp)M; 110 dims[1]=(npy_intp)N; 111 array=PyArray_SimpleNewFromData(2,dims,NPY_DOUBLE,buffer); 112 113 PyTuple_SetItem(py_tuple, index, array); 114 115 }/*}}}*/ 116 /*FUNCTION WriteData(PyObject* py_tuple,int index,SeqVec<double>* vector){{{*/ 117 void WriteData(PyObject* py_tuple,int index,SeqVec<double>* vector){ 118 119 int M; 120 double* buffer=NULL; 121 npy_intp dim=10; 122 PyObject* array=NULL; 123 124 buffer=vector->ToMPISerial(); 125 vector->GetSize(&M); 126 dim=(npy_intp)M; 127 array=PyArray_SimpleNewFromData(1,&dim,NPY_DOUBLE,buffer); 128 129 PyTuple_SetItem(py_tuple, index, array); 130 } 131 /*}}}*/ 132 /*FUNCTION WriteData(PyObject* py_tuple,int index,RiftStruct* riftstruct){{{*/ 133 void WriteData(PyObject* py_tuple,int index,RiftStruct* riftstruct){ 134 135 int i; 136 PyObject* list=NULL; 137 PyObject* dict=NULL; 138 139 list=PyList_New((Py_ssize_t)0); 140 141 for (i=0; i<riftstruct->numrifts; i++) { 142 dict=PyDict_New(); 143 144 PyDict_SetItemString(dict,"numsegs" ,PyInt_FromSsize_t((Py_ssize_t)riftstruct->riftsnumsegments[i])); 145 PyDict_SetItemString(dict,"segments" ,PyArrayFromCopiedData(riftstruct->riftsnumsegments[i] ,3,riftstruct->riftssegments[i])); 146 PyDict_SetItemString(dict,"pairs" ,PyArrayFromCopiedData(riftstruct->riftsnumpairs[i] ,2,riftstruct->riftspairs[i])); 147 PyDict_SetItemString(dict,"tips" ,PyArrayFromCopiedData(1 ,2,&riftstruct->riftstips[2*i])); 148 PyDict_SetItemString(dict,"penaltypairs" ,PyArrayFromCopiedData(riftstruct->riftsnumpenaltypairs[i],7,riftstruct->riftspenaltypairs[i])); 149 PyDict_SetItemString(dict,"fill" ,PyInt_FromSsize_t((Py_ssize_t)IceEnum)); 150 PyDict_SetItemString(dict,"friction" ,PyInt_FromSsize_t((Py_ssize_t)0)); 151 PyDict_SetItemString(dict,"fraction" ,PyFloat_FromDouble(0.)); 152 PyDict_SetItemString(dict,"fractionincrement",PyFloat_FromDouble(0.1)); 153 PyDict_SetItemString(dict,"state" ,PyArrayFromCopiedData(riftstruct->riftsnumpenaltypairs[i],1,riftstruct->state[i])); 154 155 PyList_Append(list, dict); 156 } 157 158 PyTuple_SetItem(py_tuple, index, list); 159 } 160 /*}}}*/ 161 162 /*Utils*/ 163 /*FUNCTION PyArrayFromCopiedData(int dims[2],double* data){{{*/ 164 PyObject* PyArrayFromCopiedData(int dims[2],double* data){ 165 166 double* pydata; 167 npy_intp pydims[2]={0,0}; 168 169 /* note that PyArray_SimpleNewFromData does not copy the data, so that when the original 170 object (e.g. bamggeom,bamgmesh) is deleted, the data is gone. */ 171 172 pydims[0]=(npy_intp)dims[0]; 173 pydims[1]=(npy_intp)dims[1]; 174 pydata=xNew<IssmDouble>(dims[0]*dims[1]); 175 memcpy(pydata,data,dims[0]*dims[1]*sizeof(double)); 176 return PyArray_SimpleNewFromData(2,pydims,NPY_DOUBLE,pydata); 177 } 178 /*}}}*/ 179 /*FUNCTION PyArrayFromCopiedData(int dimi,int dimj,double* data){{{*/ 180 PyObject* PyArrayFromCopiedData(int dimi,int dimj,double* data){ 181 182 double* pydata; 183 npy_intp pydims[2]={0,0}; 184 185 /* note that PyArray_SimpleNewFromData does not copy the data, so that when the original 186 object (e.g. bamggeom,bamgmesh) is deleted, the data is gone. */ 187 188 pydims[0]=(npy_intp)dimi; 189 pydims[1]=(npy_intp)dimj; 190 pydata=xNew<IssmDouble>(dimi*dimj); 191 memcpy(pydata,data,dimi*dimj*sizeof(double)); 192 return PyArray_SimpleNewFromData(2,pydims,NPY_DOUBLE,pydata); 193 } 194 /*}}}*/ -
../trunk-jpl/src/wrappers/python/Makefile.am
1 AM_CPPFLAGS = @DAKOTAINCL@ @PETSCINCL@ @MPIINCL@ @SPOOLESINCL@ @METISINCL@ @TRIANGLEINCL@ @CHACOINCL@ @SCOTCHINCL@ @SHAPELIBINCL@ @ BOOSTINCL@ @PYTHONINCL@ @PYTHON_NUMPYINCL@1 AM_CPPFLAGS = @DAKOTAINCL@ @PETSCINCL@ @MPIINCL@ @SPOOLESINCL@ @METISINCL@ @TRIANGLEINCL@ @CHACOINCL@ @SCOTCHINCL@ @SHAPELIBINCL@ @PYTHONINCL@ @PYTHON_NUMPYINCL@ 2 2 3 3 EXEEXT=$(PYTHONWRAPPEREXT) 4 4 5 #python io{{{ 6 lib_LIBRARIES = libISSMPython.a 7 if SHAREDLIBS 8 lib_LTLIBRARIES = libISSMPython.la 9 else 10 lib_LTLIBRARIES = 11 endif 12 13 io_sources= ./include/pythonincludes.h\ 14 ./io/pythonio.h\ 15 ./io/WritePythonData.cpp\ 16 ./io/CheckNumPythonArguments.cpp\ 17 ./io/FetchPythonData.cpp 18 19 ALLCXXFLAGS= -fPIC -D_GNU_SOURCE -fno-omit-frame-pointer -pthread -D_CPP_ $(CXXFLAGS) $(CXXOPTFLAGS) 20 libISSMPython_a_SOURCES = $(io_sources) 21 libISSMPython_a_CXXFLAGS= $(ALLCXXFLAGS) 22 if SHAREDLIBS 23 libISSMPython_la_SOURCES = $(io_sources) 24 endif 25 #}}} 5 26 #Wrappers {{{ 6 27 if WRAPPERS 7 28 lib_LTLIBRARIES = BamgConvertMesh.la\ … … 37 58 AM_LDFLAGS += -avoid-version 38 59 endif 39 60 if SHAREDLIBS 40 deps += . ./../c/libISSMPython.la61 deps += ./libISSMPython.la 41 62 else 42 deps += . ./../c/libISSMPython.a63 deps += ./libISSMPython.a 43 64 AM_LDFLAGS += --no-warnings 44 65 endif 45 66 -
../trunk-jpl/src/wrappers/Scotch/Scotch.h
12 12 #include "../../c/modules/modules.h" 13 13 #include "../../c/Container/Container.h" 14 14 #include "../../c/shared/shared.h" 15 #include "../ ../c/issm-binding.h"15 #include "../bindings.h" 16 16 17 17 #undef __FUNCT__ 18 18 #define __FUNCT__ "Scotch" -
../trunk-jpl/src/wrappers/NodeConnectivity/NodeConnectivity.h
26 26 #include "../../c/modules/modules.h" 27 27 #include "../../c/Container/Container.h" 28 28 #include "../../c/shared/shared.h" 29 #include "../ ../c/issm-binding.h"29 #include "../bindings.h" 30 30 #include "../../c/io/io.h" 31 31 #include "../../c/EnumDefinitions/EnumDefinitions.h" 32 32 -
../trunk-jpl/src/wrappers/BamgConvertMesh/BamgConvertMesh.h
20 20 #include "../../c/modules/modules.h" 21 21 #include "../../c/Container/Container.h" 22 22 #include "../../c/shared/shared.h" 23 #include "../ ../c/issm-binding.h"23 #include "../bindings.h" 24 24 #include "../../c/io/io.h" 25 25 26 26 #undef __FUNCT__ -
../trunk-jpl/src/wrappers/KMLOverlay/KMLOverlay.h
20 20 #include "../../c/modules/modules.h" 21 21 #include "../../c/Container/Container.h" 22 22 #include "../../c/shared/shared.h" 23 #include "../ ../c/issm-binding.h"23 #include "../bindings.h" 24 24 25 25 #undef __FUNCT__ 26 26 #define __FUNCT__ "KMLOverlay" -
../trunk-jpl/src/wrappers/ContourToNodes/ContourToNodes.h
20 20 #include "../../c/modules/modules.h" 21 21 #include "../../c/Container/Container.h" 22 22 #include "../../c/shared/shared.h" 23 #include "../ ../c/issm-binding.h"23 #include "../bindings.h" 24 24 25 25 #undef __FUNCT__ 26 26 #define __FUNCT__ "ContourToNodes" -
../trunk-jpl/src/wrappers/HoleFiller/HoleFiller.h
20 20 #include "../../c/modules/modules.h" 21 21 #include "../../c/Container/Container.h" 22 22 #include "../../c/shared/shared.h" 23 #include "../ ../c/issm-binding.h"23 #include "../bindings.h" 24 24 25 25 #undef __FUNCT__ 26 26 #define __FUNCT__ "HoleFiller" -
../trunk-jpl/src/wrappers/MeshProfileIntersection/MeshProfileIntersection.h
20 20 #include "../../c/modules/modules.h" 21 21 #include "../../c/Container/Container.h" 22 22 #include "../../c/shared/shared.h" 23 #include "../ ../c/issm-binding.h"23 #include "../bindings.h" 24 24 25 25 #undef __FUNCT__ 26 26 #define __FUNCT__ "MeshProfileIntersection" -
../trunk-jpl/src/wrappers/InterpFromMeshToMesh3d/InterpFromMeshToMesh3d.h
20 20 #include "../../c/modules/modules.h" 21 21 #include "../../c/Container/Container.h" 22 22 #include "../../c/shared/shared.h" 23 #include "../ ../c/issm-binding.h"23 #include "../bindings.h" 24 24 25 25 #undef __FUNCT__ 26 26 #define __FUNCT__ "InterpFromMeshToMesh3d" -
../trunk-jpl/src/wrappers/Ll2xy/Ll2xy.h
20 20 #include "../../c/modules/modules.h" 21 21 #include "../../c/Container/Container.h" 22 22 #include "../../c/shared/shared.h" 23 #include "../ ../c/issm-binding.h"23 #include "../bindings.h" 24 24 25 25 #undef __FUNCT__ 26 26 #define __FUNCT__ "Ll2xy" -
../trunk-jpl/src/wrappers/BamgMesher/BamgMesher.h
20 20 #include "../../c/modules/modules.h" 21 21 #include "../../c/Container/Container.h" 22 22 #include "../../c/shared/shared.h" 23 #include "../ ../c/issm-binding.h"23 #include "../bindings.h" 24 24 25 25 #undef __FUNCT__ 26 26 #define __FUNCT__ "BamgMesher" -
../trunk-jpl/src/wrappers/InterpFromGridToMesh/InterpFromGridToMesh.h
20 20 #include "../../c/modules/modules.h" 21 21 #include "../../c/Container/Container.h" 22 22 #include "../../c/shared/shared.h" 23 #include "../ ../c/issm-binding.h"23 #include "../bindings.h" 24 24 25 25 #undef __FUNCT__ 26 26 #define __FUNCT__ "InterpFromGridToMesh" -
../trunk-jpl/src/wrappers/InterpFromMeshToGrid/InterpFromMeshToGrid.h
20 20 #include "../../c/modules/modules.h" 21 21 #include "../../c/Container/Container.h" 22 22 #include "../../c/shared/shared.h" 23 #include "../ ../c/issm-binding.h"23 #include "../bindings.h" 24 24 25 25 #undef __FUNCT__ 26 26 #define __FUNCT__ "InterpFromMeshToGrid" -
../trunk-jpl/src/wrappers/KMLFileRead/KMLFileRead.h
20 20 #include "../../c/modules/modules.h" 21 21 #include "../../c/Container/Container.h" 22 22 #include "../../c/shared/shared.h" 23 #include "../ ../c/issm-binding.h"23 #include "../bindings.h" 24 24 25 25 #undef __FUNCT__ 26 26 #define __FUNCT__ "KMLFileRead" -
../trunk-jpl/src/wrappers/Shp2Kml/Shp2Kml.h
20 20 #include "../../c/modules/modules.h" 21 21 #include "../../c/Container/Container.h" 22 22 #include "../../c/shared/shared.h" 23 #include "../ ../c/issm-binding.h"23 #include "../bindings.h" 24 24 25 25 #undef __FUNCT__ 26 26 #define __FUNCT__ "Shp2Kml" -
../trunk-jpl/src/wrappers/AverageFilter/AverageFilter.h
20 20 #include "../../c/modules/modules.h" 21 21 #include "../../c/Container/Container.h" 22 22 #include "../../c/shared/shared.h" 23 #include "../ ../c/issm-binding.h"23 #include "../bindings.h" 24 24 25 25 #undef __FUNCT__ 26 26 #define __FUNCT__ "AverageFilter" -
../trunk-jpl/src/wrappers/TriMeshProcessRifts/TriMeshProcessRifts.h
20 20 #include "../../c/modules/modules.h" 21 21 #include "../../c/Container/Container.h" 22 22 #include "../../c/shared/shared.h" 23 #include "../ ../c/issm-binding.h"23 #include "../bindings.h" 24 24 25 25 #undef __FUNCT__ 26 26 #define __FUNCT__ "TriMeshProcessRifts" -
../trunk-jpl/src/wrappers/Exp2Kml/Exp2Kml.h
20 20 #include "../../c/modules/modules.h" 21 21 #include "../../c/Container/Container.h" 22 22 #include "../../c/shared/shared.h" 23 #include "../ ../c/issm-binding.h"23 #include "../bindings.h" 24 24 25 25 #undef __FUNCT__ 26 26 #define __FUNCT__ "Exp2Kml" -
../trunk-jpl/src/wrappers/Kml2Exp/Kml2Exp.h
20 20 #include "../../c/modules/modules.h" 21 21 #include "../../c/Container/Container.h" 22 22 #include "../../c/shared/shared.h" 23 #include "../ ../c/issm-binding.h"23 #include "../bindings.h" 24 24 25 25 #undef __FUNCT__ 26 26 #define __FUNCT__ "Kml2Exp" -
../trunk-jpl/src/wrappers/PointCloudFindNeighbors/PointCloudFindNeighbors.h
20 20 #include "../../c/modules/modules.h" 21 21 #include "../../c/Container/Container.h" 22 22 #include "../../c/shared/shared.h" 23 #include "../ ../c/issm-binding.h"23 #include "../bindings.h" 24 24 25 25 #undef __FUNCT__ 26 26 #define __FUNCT__ "PointCloudFindNeighbors" -
../trunk-jpl/src/wrappers/PropagateFlagsFromConnectivity/PropagateFlagsFromConnectivity.h
20 20 #include "../../c/modules/modules.h" 21 21 #include "../../c/Container/Container.h" 22 22 #include "../../c/shared/shared.h" 23 #include "../ ../c/issm-binding.h"23 #include "../bindings.h" 24 24 25 25 #undef __FUNCT__ 26 26 #define __FUNCT__ "PropagateFlagsFromConnectivity" -
../trunk-jpl/src/wrappers/include/issm-binding.h
1 #ifndef _ISSM_BINDING_H_ 2 #define _ISSM_BINDING_H_ 3 4 #ifdef HAVE_CONFIG_H 5 #include <config.h> 6 #else 7 #error "Cannot compile with HAVE_CONFIG_H symbol! run configure first!" 8 #endif 9 10 #ifdef _HAVE_MATLAB_MODULES_ 11 #include "../matlab/include/matlab-macros.h" 12 #endif 13 14 #ifdef _HAVE_PYTHON_MODULES_ 15 #include "../python/include/python-macros.h" 16 #endif 17 18 #endif -
../trunk-jpl/src/wrappers/bindings.h
1 #ifndef _BINDINGS_H_ 2 #define _BINDINGS_H_ 3 4 #ifdef HAVE_CONFIG_H 5 #include <config.h> 6 #else 7 #error "Cannot compile with HAVE_CONFIG_H symbol! run configure first!" 8 #endif 9 10 #ifdef _HAVE_MATLAB_MODULES_ 11 #include "./matlab/include/matlabincludes.h" 12 #include "./matlab/include/wrapper_macros.h" 13 #include "./matlab/io/matlabio.h" 14 #endif 15 16 #ifdef _HAVE_PYTHON_MODULES_ 17 #include "./python/include/pythonincludes.h" 18 #include "./python/include/wrapper_macros.h" 19 #include "./python/io/pythonio.h" 20 #endif 21 22 #endif -
../trunk-jpl/src/wrappers/TriaSearch/TriaSearch.h
19 19 #include "../../c/modules/modules.h" 20 20 #include "../../c/Container/Container.h" 21 21 #include "../../c/shared/shared.h" 22 #include "../ ../c/issm-binding.h"22 #include "../bindings.h" 23 23 24 24 #undef __FUNCT__ 25 25 #define __FUNCT__ "TriaSearch" -
../trunk-jpl/src/wrappers/InternalFront/InternalFront.h
18 18 19 19 #include "../../c/include/globals.h" 20 20 #include "../../c/shared/shared.h" 21 #include "../ ../c/issm-binding.h"21 #include "../bindings.h" 22 22 #include "../../c/io/io.h" 23 23 24 24 #undef __FUNCT__ -
../trunk-jpl/src/wrappers/MeshPartition/MeshPartition.h
20 20 #include "../../c/modules/modules.h" 21 21 #include "../../c/Container/Container.h" 22 22 #include "../../c/shared/shared.h" 23 #include "../ ../c/issm-binding.h"23 #include "../bindings.h" 24 24 25 25 #undef __FUNCT__ 26 26 #define __FUNCT__ "MeshPartition" -
../trunk-jpl/src/wrappers/InterpFromMesh2d/InterpFromMesh2d.h
20 20 #include "../../c/modules/modules.h" 21 21 #include "../../c/Container/Container.h" 22 22 #include "../../c/shared/shared.h" 23 #include "../ ../c/issm-binding.h"23 #include "../bindings.h" 24 24 25 25 #undef __FUNCT__ 26 26 #define __FUNCT__ "InterpFromMesh2d" -
../trunk-jpl/src/wrappers/ElementConnectivity/ElementConnectivity.h
23 23 #include "../../c/modules/modules.h" 24 24 #include "../../c/Container/Container.h" 25 25 #include "../../c/shared/shared.h" 26 #include "../ ../c/issm-binding.h"26 #include "../bindings.h" 27 27 #include "../../c/io/io.h" 28 28 #include "../../c/EnumDefinitions/EnumDefinitions.h" 29 29 -
../trunk-jpl/src/wrappers/Kriging/Kriging.h
19 19 #include "../../c/include/globals.h" 20 20 #include "../../c/modules/modules.h" 21 21 #include "../../c/shared/shared.h" 22 #include "../ ../c/issm-binding.h"22 #include "../bindings.h" 23 23 24 24 #undef __FUNCT__ 25 25 #define __FUNCT__ "Kriging" -
../trunk-jpl/src/wrappers/EnumToString/EnumToString.h
21 21 #include "../../c/modules/modules.h" 22 22 #include "../../c/Container/Container.h" 23 23 #include "../../c/shared/shared.h" 24 #include "../ ../c/issm-binding.h"24 #include "../bindings.h" 25 25 26 26 #undef __FUNCT__ 27 27 #define __FUNCT__ "EnumToString" -
../trunk-jpl/src/wrappers/StringToEnum/StringToEnum.h
21 21 #include "../../c/modules/modules.h" 22 22 #include "../../c/Container/Container.h" 23 23 #include "../../c/shared/shared.h" 24 #include "../ ../c/issm-binding.h"24 #include "../bindings.h" 25 25 26 26 #undef __FUNCT__ 27 27 #define __FUNCT__ "StringToEnum" -
../trunk-jpl/src/wrappers/matlab/include/wrapper_macros.h
1 /* \file matlab macros.h 2 * \brief: macros used for the matlab bindings 3 */ 4 5 #ifndef _MATLAB_MACROS_H_ 6 #define _MATLAB_MACROS_H_ 7 8 #ifdef HAVE_CONFIG_H 9 #include <config.h> 10 #else 11 #error "Cannot compile with HAVE_CONFIG_H symbol! run configure first!" 12 #endif 13 14 #ifdef _HAVE_MATLAB_ 15 /* MODULEBOOT/MODULEEND {{{*/ 16 17 /*The following macros hide the error exception handling in a matlab module. Just put 18 * MODULEBOOT(); and MODULEEND(); at the beginning and end of a module, and c++ exceptions 19 * will be trapped*/ 20 #define MODULEBOOT(); try{ \ 21 IssmComm::SetComm(-1); 22 23 #define MODULEEND(); }\ 24 catch(ErrorException &exception){\ 25 mexErrMsgTxt(exception.MatlabReport()); \ 26 }\ 27 catch (exception &e){\ 28 mexErrMsgTxt(exprintf("Standard exception: %s\n",e.what()));\ 29 }\ 30 catch(...){\ 31 mexErrMsgTxt("An unexpected error occurred");\ 32 } 33 /*}}}*/ 34 /* WRAPPER {{{*/ 35 #define WRAPPER(modulename,...) void mexFunction(int nlhs, mxArray* plhs[], int nrhs, const mxArray* prhs[]) 36 /*}}}*/ 37 /* CHECKARGUMENTS {{{*/ 38 #define CHECKARGUMENTS(NLHS,NRHS,functionpointer) CheckNumMatlabArguments(nlhs,NLHS,nrhs,NRHS,__FUNCT__,functionpointer) 39 /*}}}*/ 40 #endif 41 42 #endif -
../trunk-jpl/src/wrappers/matlab/io/MatlabMatrixToSeqMat.cpp
1 /*!\file MatlabMatrixToSeqMat.cpp 2 */ 3 4 /*Headers:*/ 5 #ifdef HAVE_CONFIG_H 6 #include <config.h> 7 #else 8 #error "Cannot compile with HAVE_CONFIG_H symbol! run configure first!" 9 #endif 10 11 #include <stdio.h> 12 #include <string.h> 13 #include "./matlabio.h" 14 #include "../../c/toolkits/toolkits.h" 15 #include "../../c/shared/shared.h" 16 17 SeqMat<double>* MatlabMatrixToSeqMat(const mxArray* dataref){ 18 19 SeqMat<double>* output=NULL; 20 21 output=new SeqMat<double>(); 22 MatlabMatrixToDoubleMatrix(&output->matrix,&output->M,&output->N,dataref); 23 return output; 24 25 } -
../trunk-jpl/src/wrappers/matlab/io/MatlabVectorToPetscVec.cpp
1 /* \file MatlabVectorToPetscVector.cpp 2 * \brief: convert a sparse or dense matlab vector to a serial Petsc vector: 3 */ 4 5 #ifdef HAVE_CONFIG_H 6 #include <config.h> 7 #else 8 #error "Cannot compile with HAVE_CONFIG_H symbol! run configure first!" 9 #endif 10 11 /*Petsc includes: */ 12 #include <petscmat.h> 13 #include <petscvec.h> 14 #include <petscksp.h> 15 16 /*Matlab includes: */ 17 #include "./matlabio.h" 18 #include "../../c/shared/shared.h" 19 20 PetscVec* MatlabVectorToPetscVec(const mxArray* mxvector){ 21 22 int dummy; 23 PetscVec* vector=new PetscVec(); 24 25 MatlabVectorToPetscVec(&vector->vector,&dummy, mxvector); 26 27 return vector; 28 } 29 30 int MatlabVectorToPetscVec(Vec* pvector,int* pvector_rows,const mxArray* mxvector){ 31 32 int rows, cols; 33 double* mxvector_ptr=NULL; 34 int ierr; 35 int i,j; 36 37 /*output: */ 38 Vec vector=NULL; 39 40 /*matlab indices: */ 41 mwIndex* ir=NULL; 42 mwIndex* jc=NULL; 43 double* pr=NULL; 44 int count; 45 int nnz; 46 int nz; 47 48 /*petsc indices: */ 49 int* idxm=NULL; 50 51 /*Ok, first check if we are dealing with a sparse or full vector: */ 52 if (mxIsSparse(mxvector)){ 53 54 /*Dealing with sparse vector: recover size first: */ 55 mxvector_ptr=(double*)mxGetPr(mxvector); 56 rows=mxGetM(mxvector); 57 cols=mxGetN(mxvector); 58 nnz=mxGetNzmax(mxvector); 59 nz=(int)((double)nnz/(double)rows); 60 61 ierr=VecCreateSeq(PETSC_COMM_SELF,rows,&vector);CHKERRQ(ierr); 62 63 /*Now, get ir,jc and pr: */ 64 pr=mxGetPr(mxvector); 65 ir=mxGetIr(mxvector); 66 jc=mxGetJc(mxvector); 67 68 /*Now, start inserting data into sparse vector: */ 69 count=0; 70 for(i=0;i<cols;i++){ 71 for(j=0;j<(jc[i+1]-jc[i]);j++){ 72 VecSetValue(vector,ir[count],pr[count],INSERT_VALUES); 73 count++; 74 } 75 } 76 77 } 78 else{ 79 80 /*Dealing with dense vector: recover pointer and size: */ 81 mxvector_ptr=(double*)mxGetPr(mxvector); 82 rows=mxGetM(mxvector); 83 cols=mxGetN(mxvector); 84 85 /*Create serial vector: */ 86 ierr=VecCreateSeq(PETSC_COMM_SELF,rows,&vector);CHKERRQ(ierr); 87 88 /*Insert mxvector_ptr values into petsc vector: */ 89 idxm=xNew<int>(rows); 90 91 for(i=0;i<rows;i++)idxm[i]=i; 92 93 ierr=VecSetValues(vector,rows,idxm,mxvector_ptr,INSERT_VALUES);CHKERRQ(ierr); 94 95 } 96 97 /*Assemble vector: */ 98 VecAssemblyBegin(vector); 99 VecAssemblyEnd(vector); 100 101 /*Assign output pointer: */ 102 *pvector=vector; 103 *pvector_rows=rows; 104 105 return 1; 106 } -
../trunk-jpl/src/wrappers/matlab/io/OptionParse.cpp
1 /*\file OptionParse.c 2 *\brief: functions to parse the mex options. 3 */ 4 #ifdef HAVE_CONFIG_H 5 #include <config.h> 6 #else 7 #error "Cannot compile with HAVE_CONFIG_H symbol! run configure first!" 8 #endif 9 10 #include <cstring> 11 #include "./matlabio.h" 12 #include "../../c/shared/shared.h" 13 #include "../../c/io/io.h" 14 15 GenericOption<double>* OptionDoubleParse( char* name, const mxArray* prhs[]){ /*{{{*/ 16 17 GenericOption<double> *odouble = NULL; 18 19 /*check and parse the name */ 20 odouble=new GenericOption<double>(); 21 odouble->name =xNew<char>(strlen(name)+1); 22 memcpy(odouble->name,name,(strlen(name)+1)*sizeof(char)); 23 FetchData(&odouble->value,prhs[0]); 24 odouble->numel=1; 25 odouble->ndims=1; 26 odouble->size=NULL; 27 28 return(odouble); 29 }/*}}}*/ 30 GenericOption<double*>* OptionDoubleArrayParse( char* name, const mxArray* prhs[]){ /*{{{*/ 31 32 GenericOption<double*> *odouble = NULL; 33 34 /*check and parse the name */ 35 odouble=new GenericOption<double*>(); 36 odouble->name =xNew<char>(strlen(name)+1); 37 memcpy(odouble->name,name,(strlen(name)+1)*sizeof(char)); 38 39 /*check and parse the value */ 40 if (!mxIsClass(prhs[0],"double")){ 41 _error_("Value of option \"" << odouble->name << "\" must be class \"double\", not class \"" << mxGetClassName(prhs[0]) <<"\"."); 42 } 43 FetchData(&odouble->value,&odouble->numel,&odouble->ndims,&odouble->size,prhs[0]); 44 45 return(odouble); 46 }/*}}}*/ 47 GenericOption<bool*>* OptionLogicalParse( char* name, const mxArray* prhs[]){ /*{{{*/ 48 49 GenericOption<bool*> *ological = NULL; 50 51 /*check and parse the name */ 52 ological=new GenericOption<bool*>(); 53 ological->name =xNew<char>(strlen(name)+1); 54 memcpy(ological->name,name,(strlen(name)+1)*sizeof(char)); 55 56 /*check and parse the value */ 57 if (!mxIsClass(prhs[0],"logical")){ 58 _error_("Value of option \"" << ological->name << "\" must be class \"logical\", not class \"" << mxGetClassName(prhs[0]) <<"\"."); 59 } 60 FetchData(&ological->value,&ological->numel,&ological->ndims,&ological->size,prhs[0]); 61 62 return(ological); 63 }/*}}}*/ 64 GenericOption<char*>* OptionCharParse( char* name, const mxArray* prhs[]){ /*{{{*/ 65 66 GenericOption<char*> *ochar = NULL; 67 68 /*check and parse the name */ 69 ochar=new GenericOption<char*>(); 70 ochar->name =xNew<char>(strlen(name)+1); 71 memcpy(ochar->name,name,(strlen(name)+1)*sizeof(char)); 72 73 /*check and parse the value */ 74 if (!mxIsClass(prhs[0],"char")){ 75 _error_("Value of option \"" << ochar->name << "\" must be class \"char\", not class \"" << mxGetClassName(prhs[0]) <<"\"."); 76 } 77 FetchData(&ochar->value,&ochar->numel,&ochar->ndims,&ochar->size,prhs[0]); 78 79 return(ochar); 80 }/*}}}*/ 81 GenericOption<Options**>* OptionStructParse( char* name, const mxArray* prhs[]){ /*{{{*/ 82 83 int i; 84 char namei[161]; 85 Option* option = NULL; 86 GenericOption<Options**> *ostruct = NULL; 87 const mwSize *ipt = NULL; 88 const mxArray *structi; 89 mwIndex sindex; 90 91 /*check and parse the name */ 92 ostruct=new GenericOption<Options**>(); 93 ostruct->name =xNew<char>(strlen(name)+1); 94 memcpy(ostruct->name,name,(strlen(name)+1)*sizeof(char)); 95 96 /*check and parse the value */ 97 if (!mxIsClass(prhs[0],"struct")){ 98 _error_("Value of option \"" << ostruct->name << "\" must be class \"struct\", not class \"" << mxGetClassName(prhs[0]) <<"\"."); 99 } 100 ostruct->numel=mxGetNumberOfElements(prhs[0]); 101 ostruct->ndims=mxGetNumberOfDimensions(prhs[0]); 102 ipt =mxGetDimensions(prhs[0]); 103 ostruct->size =xNew<int>(ostruct->ndims); 104 for (i=0; i<ostruct->ndims; i++) ostruct->size[i]=(int)ipt[i]; 105 if (ostruct->numel) ostruct->value=xNew<Options*>(ostruct->numel); 106 107 /*loop through and process each element of the struct array */ 108 for (sindex=0; sindex<ostruct->numel; sindex++) { 109 ostruct->value[sindex]=new Options; 110 111 /*loop through and process each field for the element */ 112 for (i=0; i<mxGetNumberOfFields(prhs[0]); i++) { 113 sprintf(namei,"%s.%s",name,mxGetFieldNameByNumber(prhs[0],i)); 114 structi=mxGetFieldByNumber(prhs[0],sindex,i); 115 116 option=(Option*)OptionParse(namei,&structi); 117 ostruct->value[sindex]->AddObject((Object*)option); 118 option=NULL; 119 } 120 } 121 122 return(ostruct); 123 }/*}}}*/ 124 GenericOption<Options*>* OptionCellParse( char* name, const mxArray* prhs[]){ /*{{{*/ 125 126 int i; 127 int *dims; 128 char namei[161]; 129 char cstr[81]; 130 GenericOption<Options*> *ocell = NULL; 131 Option *option = NULL; 132 const mwSize *ipt = NULL; 133 const mxArray *celli; 134 mwIndex cindex; 135 136 /*check and parse the name */ 137 ocell=new GenericOption<Options*>(); 138 ocell->name =xNew<char>(strlen(name)+1); 139 memcpy(ocell->name,name,(strlen(name)+1)*sizeof(char)); 140 141 /*check and parse the value */ 142 if (!mxIsClass(prhs[0],"cell")){ 143 _error_("Value of option \"" << ocell->name << "\" must be class \"cell\", not class \"" << mxGetClassName(prhs[0]) <<"\"."); 144 } 145 146 ocell->numel=mxGetNumberOfElements(prhs[0]); 147 ocell->ndims=mxGetNumberOfDimensions(prhs[0]); 148 ipt =mxGetDimensions(prhs[0]); 149 ocell->size =xNew<int>(ocell->ndims); 150 for (i=0; i<ocell->ndims; i++) ocell->size[i]=(int)ipt[i]; 151 ocell->value=new Options; 152 153 /*loop through and process each element of the cell array */ 154 dims=xNew<int>(ocell->ndims); 155 for (cindex=0; cindex<ocell->numel; cindex++) { 156 ColumnWiseDimsFromIndex(dims,(int)cindex,ocell->size,ocell->ndims); 157 StringFromDims(cstr,dims,ocell->ndims); 158 #ifdef _INTEL_WIN_ 159 _snprintf(namei,161,"%s%s",name,cstr); 160 #else 161 snprintf(namei,161,"%s%s",name,cstr); 162 #endif 163 celli=mxGetCell(prhs[0],cindex); 164 165 option=(Option*)OptionParse(namei,&celli); 166 ocell->value->AddObject((Object*)option); 167 option=NULL; 168 } 169 xDelete<int>(dims); 170 171 return(ocell); 172 }/*}}}*/ 173 Option* OptionParse(char* name, const mxArray* prhs[]){ /*{{{*/ 174 175 Option *option = NULL; 176 mxArray *lhs[1]; 177 178 /*parse the value according to the matlab data type */ 179 if (mxIsClass(prhs[0],"double") && (mxGetNumberOfElements(prhs[0])==1)) 180 option=(Option*)OptionDoubleParse(name,prhs); 181 else if(mxIsClass(prhs[0],"double") && (mxGetNumberOfElements(prhs[0])!=1)) 182 option=(Option*)OptionDoubleArrayParse(name,prhs); 183 else if(mxIsClass(prhs[0],"logical")) 184 option=(Option*)OptionLogicalParse(name,prhs); 185 else if(mxIsClass(prhs[0],"char")) 186 option=(Option*)OptionCharParse(name,prhs); 187 else if(mxIsClass(prhs[0],"struct")) 188 option=(Option*)OptionStructParse(name,prhs); 189 else if(mxIsClass(prhs[0],"cell")) 190 option=(Option*)OptionCellParse(name,prhs); 191 else { 192 _pprintLine_(" Converting value of option \"" << name << "\" from unrecognized class \"" << mxGetClassName(prhs[0]) << "\" to class \"" << "struct" << "\"."); 193 if (!mexCallMATLAB(1,lhs,1,(mxArray**)prhs,"struct")) { 194 option=(Option*)OptionStructParse(name,(const mxArray**)lhs); 195 mxDestroyArray(lhs[0]); 196 } 197 else _error_("Second argument value of option \""<< name <<"\" is of unrecognized class \""<< mxGetClassName(prhs[0]) <<"\"."); 198 } 199 200 return(option); 201 }/*}}}*/ -
../trunk-jpl/src/wrappers/matlab/io/CheckNumMatlabArguments.cpp
1 /*!\file CheckNumMatlabArguments.cpp: 2 * \brief: check number of arguments and report an usage error message. 3 */ 4 5 #include "./matlabio.h" 6 #include "../../c/shared/Exceptions/exceptions.h" 7 8 int CheckNumMatlabArguments(int nlhs,int NLHS, int nrhs,int NRHS, const char* THISFUNCTION, void (*function)( void )){ 9 10 /*checks on arguments on the matlab side: */ 11 if (nrhs==0 && nlhs==0) { 12 /*unless NLHS=0 and NRHS=0, we are just asking for documentation: */ 13 if (NRHS==0 && NLHS==0)return 1; 14 /* special case: */ 15 function(); 16 _error_("usage: see above"); 17 } 18 else if (nlhs!=NLHS || nrhs!=NRHS ) { 19 function(); 20 _error_("usage error."); 21 } 22 return 1; 23 } -
../trunk-jpl/src/wrappers/matlab/io/FetchMatlabData.cpp
1 /*\file FetchData.cpp: 2 * \brief: general I/O interface to fetch data in matlab 3 */ 4 5 #ifdef HAVE_CONFIG_H 6 #include <config.h> 7 #else 8 #error "Cannot compile with HAVE_CONFIG_H symbol! run configure first!" 9 #endif 10 11 #include "./matlabio.h" 12 #include "../../c/shared/shared.h" 13 14 /*Primitive data types*/ 15 /*FUNCTION FetchData(double** pmatrix,int* pM,int *pN,const mxArray* dataref){{{*/ 16 void FetchData(double** pmatrix,int* pM,int *pN,const mxArray* dataref){ 17 18 double* outmatrix=NULL; 19 int outmatrix_rows,outmatrix_cols; 20 21 if(mxIsEmpty(dataref) ){ 22 /*Nothing to pick up. Just initialize matrix pointer to NULL: */ 23 outmatrix_rows=0; 24 outmatrix_cols=0; 25 outmatrix=NULL; 26 } 27 else if( mxIsClass(dataref,"double") || 28 mxIsClass(dataref,"single") || 29 mxIsClass(dataref,"int16") || 30 mxIsClass(dataref,"int8") || 31 mxIsClass(dataref,"uint8")){ 32 /*Check dataref is not pointing to NaN: */ 33 if ( mxIsNaN(*(mxGetPr(dataref))) && (mxGetM(dataref)==1) && (mxGetN(dataref)==1) ){ 34 outmatrix_rows=0; 35 outmatrix_cols=0; 36 outmatrix=NULL; 37 } 38 else{ 39 if(!mxIsClass(dataref,"double") && !mxIsClass(dataref,"single")){ 40 _printLine_("Warning: converting matlab data from '" << mxGetClassName(dataref) << "' to 'double'"); 41 } 42 /*Convert matlab matrix to double* matrix: */ 43 MatlabMatrixToDoubleMatrix(&outmatrix,&outmatrix_rows,&outmatrix_cols,dataref); 44 } 45 } 46 else{ 47 /*This is an error: we don't have the correct input!: */ 48 _error_("Input parameter of class " << mxGetClassName(dataref) << " not supported yet"); 49 } 50 51 /*Assign output pointers:*/ 52 *pmatrix=outmatrix; 53 if (pM)*pM=outmatrix_rows; 54 if (pN)*pN=outmatrix_cols; 55 56 } 57 /*}}}*/ 58 /*FUNCTION FetchData(double** pmatrix,int* pnumel,int* pndims,int** psize,const mxArray* dataref){{{*/ 59 void FetchData(double** pmatrix,int* pnumel,int* pndims,int** psize,const mxArray* dataref){ 60 61 int outmatrix_numel,outmatrix_ndims; 62 double *outmatrix = NULL; 63 int *outmatrix_size = NULL; 64 65 if(mxIsEmpty(dataref) ){ 66 /*Nothing to pick up. Just initialize matrix pointer to NULL: */ 67 outmatrix_numel = 0; 68 outmatrix_ndims = 0; 69 outmatrix_size = NULL; 70 outmatrix = NULL; 71 } 72 else if( mxIsClass(dataref,"double") || 73 mxIsClass(dataref,"single") || 74 mxIsClass(dataref,"int16") || 75 mxIsClass(dataref,"int8") || 76 mxIsClass(dataref,"uint8")){ 77 78 /*Check dataref is not pointing to NaN: */ 79 if (mxIsNaN(*(mxGetPr(dataref))) && (mxGetNumberOfElements(dataref)==1)){ 80 outmatrix_numel = 0; 81 outmatrix_ndims = 0; 82 outmatrix_size = NULL; 83 outmatrix = NULL; 84 } 85 else{ 86 if(!mxIsClass(dataref,"double") && !mxIsClass(dataref,"single")){ 87 _printLine_("Warning: converting matlab data from '" << mxGetClassName(dataref) << "' to 'double'"); 88 } 89 /*Convert matlab n-dim array to double* matrix: */ 90 MatlabNArrayToNArray(&outmatrix,&outmatrix_numel,&outmatrix_ndims,&outmatrix_size,dataref); 91 } 92 } 93 else{ 94 /*This is an error: we don't have the correct input!: */ 95 _error_("Input parameter of class " << mxGetClassName(dataref) << " not supported yet"); 96 } 97 98 /*Assign output pointers:*/ 99 *pmatrix=outmatrix; 100 if (pnumel)*pnumel=outmatrix_numel; 101 if (pndims)*pndims=outmatrix_ndims; 102 if (psize )*psize =outmatrix_size; 103 else xDelete<int>(outmatrix_size); 104 105 } 106 /*}}}*/ 107 /*FUNCTION FetchData(int** pmatrix,int* pM,int *pN,const mxArray* dataref){{{*/ 108 void FetchData(int** pmatrix,int* pM,int *pN,const mxArray* dataref){ 109 110 int i,outmatrix_rows,outmatrix_cols; 111 double *doublematrix=NULL; 112 int *outmatrix=NULL; 113 114 if(mxIsEmpty(dataref) ){ 115 /*Nothing to pick up. Just initialize matrix pointer to NULL: */ 116 outmatrix_rows=0; 117 outmatrix_cols=0; 118 outmatrix=NULL; 119 } 120 else if( mxIsClass(dataref,"double") || 121 mxIsClass(dataref,"single") || 122 mxIsClass(dataref,"int16") || 123 mxIsClass(dataref,"int8") || 124 mxIsClass(dataref,"uint8")){ 125 126 /*Check dataref is not pointing to NaN: */ 127 if ( mxIsNaN(*(mxGetPr(dataref))) && (mxGetM(dataref)==1) && (mxGetN(dataref)==1) ){ 128 outmatrix_rows=0; 129 outmatrix_cols=0; 130 outmatrix=NULL; 131 } 132 else{ 133 if(!mxIsClass(dataref,"double") && !mxIsClass(dataref,"single")){ 134 _printLine_("Warning: converting matlab data from '" << mxGetClassName(dataref) << "' to 'double'"); 135 } 136 /*Convert matlab matrix to double* matrix: */ 137 MatlabMatrixToDoubleMatrix(&doublematrix,&outmatrix_rows,&outmatrix_cols,dataref); 138 139 /*Convert double matrix into integer matrix: */ 140 outmatrix=xNew<int>(outmatrix_rows*outmatrix_cols); 141 for(i=0;i<outmatrix_rows*outmatrix_cols;i++)outmatrix[i]=(int)doublematrix[i]; 142 } 143 } 144 else{ 145 /*This is an error: we don't have the correct input!: */ 146 _error_("Input parameter of class " << mxGetClassName(dataref) << " not supported yet"); 147 } 148 149 /*Assign output pointers:*/ 150 *pmatrix=outmatrix; 151 if (pM)*pM=outmatrix_rows; 152 if (pN)*pN=outmatrix_cols; 153 } 154 /*}}}*/ 155 /*FUNCTION FetchData(bool** pmatrix,int* pM,int *pN,const mxArray* dataref){{{*/ 156 void FetchData(bool** pmatrix,int* pM,int *pN,const mxArray* dataref){ 157 158 int i,outmatrix_rows,outmatrix_cols; 159 double *doublematrix=NULL; 160 bool *outmatrix=NULL; 161 162 if(mxIsEmpty(dataref) ){ 163 /*Nothing to pick up. Just initialize matrix pointer to NULL: */ 164 outmatrix_rows=0; 165 outmatrix_cols=0; 166 outmatrix=NULL; 167 } 168 else if (mxIsClass(dataref,"double") ){ 169 170 /*Check dataref is not pointing to NaN: */ 171 if ( mxIsNaN(*(mxGetPr(dataref))) && (mxGetM(dataref)==1) && (mxGetN(dataref)==1) ){ 172 outmatrix_rows=0; 173 outmatrix_cols=0; 174 outmatrix=NULL; 175 } 176 else{ 177 178 /*Convert matlab matrix to double* matrix: */ 179 MatlabMatrixToDoubleMatrix(&doublematrix,&outmatrix_rows,&outmatrix_cols,dataref); 180 181 /*Convert double matrix into integer matrix: */ 182 outmatrix=xNew<bool>(outmatrix_rows*outmatrix_cols); 183 for(i=0;i<outmatrix_rows;i++)outmatrix[i]=(bool)doublematrix[i]; 184 } 185 } 186 else{ 187 /*This is an error: we don't have the correct input!: */ 188 _error_("Input parameter of class " << mxGetClassName(dataref) << " not supported yet"); 189 } 190 191 /*Assign output pointers:*/ 192 *pmatrix=outmatrix; 193 if (pM)*pM=outmatrix_rows; 194 if (pN)*pN=outmatrix_cols; 195 } 196 /*}}}*/ 197 /*FUNCTION FetchData(bool** pmatrix,int* pnumel,int* pndims,int** psize,const mxArray* dataref){{{*/ 198 void FetchData(bool** pmatrix,int* pnumel,int* pndims,int** psize,const mxArray* dataref){ 199 200 int i; 201 int outmatrix_numel,outmatrix_ndims; 202 int* outmatrix_size=NULL; 203 double* doublematrix=NULL; 204 bool* outmatrix=NULL; 205 206 if(mxIsEmpty(dataref) ){ 207 /*Nothing to pick up. Just initialize matrix pointer to NULL: */ 208 outmatrix_numel=0; 209 outmatrix_ndims=0; 210 outmatrix_size =NULL; 211 outmatrix=NULL; 212 } 213 else if (mxIsClass(dataref,"logical") ){ 214 215 /*Check dataref is not pointing to NaN: */ 216 if ( mxIsNaN(*((bool*)mxGetData(dataref))) && (mxGetNumberOfElements(dataref)==1) ){ 217 outmatrix_numel=0; 218 outmatrix_ndims=0; 219 outmatrix_size =NULL; 220 outmatrix=NULL; 221 } 222 else{ 223 224 /*Convert matlab n-dim array to bool* matrix: */ 225 MatlabNArrayToNArray(&outmatrix,&outmatrix_numel,&outmatrix_ndims,&outmatrix_size,dataref); 226 } 227 } 228 else if (mxIsClass(dataref,"double") ){ 229 230 /*Check dataref is not pointing to NaN: */ 231 if ( mxIsNaN(*(mxGetPr(dataref))) && (mxGetNumberOfElements(dataref)==1) ){ 232 outmatrix_numel=0; 233 outmatrix_ndims=0; 234 outmatrix_size =NULL; 235 outmatrix=NULL; 236 } 237 else{ 238 239 /*Convert matlab n-dim array to double* matrix: */ 240 MatlabNArrayToNArray(&doublematrix,&outmatrix_numel,&outmatrix_ndims,&outmatrix_size,dataref); 241 242 /*Convert double matrix into bool matrix: */ 243 outmatrix=xNew<bool>(outmatrix_numel); 244 for(i=0;i<outmatrix_numel;i++)outmatrix[i]=(bool)doublematrix[i]; 245 xDelete<double>(doublematrix); 246 } 247 } 248 else{ 249 /*This is an error: we don't have the correct input!: */ 250 _error_("Input parameter of class " << mxGetClassName(dataref) << " not supported yet"); 251 } 252 253 /*Assign output pointers:*/ 254 *pmatrix=outmatrix; 255 if (pnumel)*pnumel=outmatrix_numel; 256 if (pndims)*pndims=outmatrix_ndims; 257 if (psize )*psize =outmatrix_size; 258 else xDelete<int>(outmatrix_size); 259 260 } 261 /*}}}*/ 262 /*FUNCTION FetchData(double** pvector,int* pM,const mxArray* dataref){{{*/ 263 void FetchData(double** pvector,int* pM,const mxArray* dataref){ 264 265 double* outvector=NULL; 266 int outvector_rows; 267 268 if(mxIsEmpty(dataref)){ 269 /*Nothing to pick up. Just initialize matrix pointer to NULL: */ 270 outvector_rows=0; 271 outvector=NULL; 272 } 273 else if (mxIsClass(dataref,"double") ){ 274 275 /*Convert matlab vector to double* vector: */ 276 MatlabVectorToDoubleVector(&outvector,&outvector_rows,dataref); 277 278 } 279 else{ 280 /*This is an error: we don't have the correct input!: */ 281 _error_("Input parameter of class " << mxGetClassName(dataref) << " not supported yet"); 282 } 283 284 /*Assign output pointers:*/ 285 *pvector=outvector; 286 if (pM)*pM=outvector_rows; 287 } 288 /*}}}*/ 289 /*FUNCTION FetchData(int** pvector,int* pM,const mxArray* dataref){{{*/ 290 void FetchData(int** pvector,int* pM,const mxArray* dataref){ 291 292 int i; 293 double *doublevector = NULL; 294 int *outvector = NULL; 295 int outvector_rows; 296 297 if(mxIsEmpty(dataref)){ 298 /*Nothing to pick up. Just initialize matrix pointer to NULL: */ 299 outvector_rows=0; 300 outvector=NULL; 301 } 302 else if (mxIsClass(dataref,"double") ){ 303 304 /*Convert matlab vector to double* vector: */ 305 MatlabVectorToDoubleVector(&doublevector,&outvector_rows,dataref); 306 307 /*Convert double vector into integer vector: */ 308 outvector=xNew<int>(outvector_rows); 309 for(i=0;i<outvector_rows;i++)outvector[i]=(int)doublevector[i]; 310 } 311 else{ 312 /*This is an error: we don't have the correct input!: */ 313 _error_("Input parameter of class " << mxGetClassName(dataref) << " not supported yet"); 314 } 315 316 /*Assign output pointers:*/ 317 *pvector=outvector; 318 if (pM)*pM=outvector_rows; 319 } 320 /*}}}*/ 321 /*FUNCTION FetchData(bool** pvector,int* pM,const mxArray* dataref){{{*/ 322 void FetchData(bool** pvector,int* pM,const mxArray* dataref){ 323 324 int i; 325 double *doublevector = NULL; 326 bool *outvector = NULL; 327 int outvector_rows; 328 329 if(mxIsEmpty(dataref)){ 330 /*Nothing to pick up. Just initialize matrix pointer to NULL: */ 331 outvector_rows=0; 332 outvector=NULL; 333 } 334 else if (mxIsClass(dataref,"double") ){ 335 336 /*Convert matlab vector to double* vector: */ 337 MatlabVectorToDoubleVector(&doublevector,&outvector_rows,dataref); 338 339 /*Convert double vector into integer vector: */ 340 outvector=xNew<bool>(outvector_rows); 341 for(i=0;i<outvector_rows;i++)outvector[i]=(bool)doublevector[i]; 342 } 343 else{ 344 /*This is an error: we don't have the correct input!: */ 345 _error_("Input parameter of class " << mxGetClassName(dataref) << " not supported yet"); 346 } 347 348 /*Assign output pointers:*/ 349 *pvector=outvector; 350 if (pM)*pM=outvector_rows; 351 } 352 /*}}}*/ 353 /*FUNCTION FetchData(float** pvector,int* pM,const mxArray* dataref){{{*/ 354 void FetchData(float** pvector,int* pM,const mxArray* dataref){ 355 356 int i; 357 double *doublevector = NULL; 358 float *outvector = NULL; 359 int outvector_rows; 360 361 if(mxIsEmpty(dataref)){ 362 /*Nothing to pick up. Just initialize matrix pointer to NULL: */ 363 outvector_rows=0; 364 outvector=NULL; 365 } 366 else if (mxIsClass(dataref,"double") ){ 367 368 /*Convert matlab vector to double* vector: */ 369 MatlabVectorToDoubleVector(&doublevector,&outvector_rows,dataref); 370 371 /*Convert double vector into float vector: */ 372 outvector=xNew<float>(outvector_rows); 373 for(i=0;i<outvector_rows;i++)outvector[i]=(float)doublevector[i]; 374 } 375 else{ 376 /*This is an error: we don't have the correct input!: */ 377 _error_("Input parameter of class " << mxGetClassName(dataref) << " not supported yet"); 378 } 379 380 /*Assign output pointers:*/ 381 *pvector=outvector; 382 if (pM)*pM=outvector_rows; 383 } 384 /*}}}*/ 385 /*FUNCTION FetchData(char** pstring,const mxArray* dataref){{{*/ 386 void FetchData(char** pstring,const mxArray* dataref){ 387 388 char* outstring=NULL; 389 390 /*Ok, the string should be coming directly from the matlab workspace: */ 391 if (!mxIsClass(dataref,"char")){ 392 _error_("input data_type is not a string!"); 393 } 394 else{ 395 /*Recover the string:*/ 396 int stringlen; 397 398 stringlen = mxGetM(dataref)*mxGetN(dataref)+1; 399 outstring =xNew<char>(stringlen); 400 mxGetString(dataref,outstring,stringlen); 401 } 402 403 /*Assign output pointers:*/ 404 *pstring=outstring; 405 }/*}}}*/ 406 /*FUNCTION FetchData(char** pmatrix,int* pnumel,int* pndims,int** psize,const mxArray* dataref){{{*/ 407 void FetchData(char** pmatrix,int* pnumel,int* pndims,int** psize,const mxArray* dataref){ 408 409 int outmatrix_numel,outmatrix_ndims; 410 int* outmatrix_size=NULL; 411 char* outmatrix=NULL; 412 413 if(mxIsEmpty(dataref) ){ 414 /*Nothing to pick up. Just initialize matrix pointer to NULL: */ 415 outmatrix_numel=0; 416 outmatrix_ndims=0; 417 outmatrix_size =NULL; 418 outmatrix=NULL; 419 } 420 else if (mxIsClass(dataref,"char") ){ 421 422 /*Convert matlab n-dim array to char* matrix: */ 423 MatlabNArrayToNArray(&outmatrix,&outmatrix_numel,&outmatrix_ndims,&outmatrix_size,dataref); 424 } 425 else{ 426 /*This is an error: we don't have the correct input!: */ 427 _error_("Input parameter of class " << mxGetClassName(dataref) << " not supported yet"); 428 } 429 430 /*Assign output pointers:*/ 431 *pmatrix=outmatrix; 432 if (pnumel)*pnumel=outmatrix_numel; 433 if (pndims)*pndims=outmatrix_ndims; 434 if (psize )*psize =outmatrix_size; 435 else xDelete<int>(outmatrix_size); 436 437 } 438 /*}}}*/ 439 /*FUNCTION FetchData(double* pscalar,const mxArray* dataref){{{*/ 440 void FetchData(double* pscalar,const mxArray* dataref){ 441 442 double scalar; 443 444 if (!mxIsClass(dataref,"double")){ 445 _error_("input data_type is not a double!"); 446 } 447 else{ 448 /*Recover the double: */ 449 scalar=mxGetScalar(dataref); 450 } 451 452 /*Assign output pointers:*/ 453 *pscalar=scalar; 454 } 455 /*}}}*/ 456 /*FUNCTION FetchData(int* pinteger,const mxArray* dataref){{{*/ 457 void FetchData(int* pinteger,const mxArray* dataref){ 458 459 int integer; 460 461 if (!mxIsClass(dataref,"double")){ 462 _error_("input data_type is not a scalar!"); 463 } 464 else{ 465 /*Recover the double: */ 466 integer=(int)mxGetScalar(dataref); 467 } 468 469 /*Assign output pointers:*/ 470 *pinteger=integer; 471 } 472 /*}}}*/ 473 /*FUNCTION FetchData(bool* pboolean,const mxArray* dataref){{{*/ 474 void FetchData(bool* pboolean,const mxArray* dataref){ 475 476 bool* mxbool_ptr=NULL; 477 478 if (mxIsClass(dataref,"logical")){ 479 if(mxGetM(dataref)!=1) _error_("input data is not of size 1x1"); 480 if(mxGetN(dataref)!=1) _error_("input data is not of size 1x1"); 481 mxbool_ptr=mxGetLogicals(dataref); 482 } 483 else{ 484 _error_("input data_type is not a bool!"); 485 } 486 487 *pboolean=*mxbool_ptr; 488 } 489 /*}}}*/ 490 491 /*ISSM objects*/ 492 /*FUNCTION FetchData(Matrix<double>** pmatrix,const mxArray* dataref){{{*/ 493 void FetchData(Matrix<double>** pmatrix,const mxArray* dataref){ 494 495 Matrix<double>* outmatrix=NULL; 496 int dummy=0; 497 498 if (mxIsClass(dataref,"double") ){ 499 500 /*Convert matlab matrix to matrix: */ 501 outmatrix=MatlabMatrixToMatrix(dataref); 502 503 } 504 else{ 505 /*This is an error: we don't have the correct input!: */ 506 _error_("Input parameter of class " << mxGetClassName(dataref) << " not supported yet"); 507 } 508 509 /*Assign output pointers:*/ 510 *pmatrix=outmatrix; 511 } 512 /*}}}*/ 513 /*FUNCTION FetchData(Vector<double>** pvector,const mxArray* dataref){{{*/ 514 void FetchData(Vector<double>** pvector,const mxArray* dataref){ 515 516 Vector<double>* vector=NULL; 517 int dummy; 518 519 if(mxIsEmpty(dataref)){ 520 /*Nothing to pick up. Just initialize matrix pointer to NULL: */ 521 vector=new Vector<double>(0); 522 } 523 else if (mxIsClass(dataref,"double") ){ 524 525 /*Convert matlab vector to petsc vector: */ 526 vector=MatlabVectorToVector(dataref); 527 } 528 else{ 529 /*This is an error: we don't have the correct input!: */ 530 _error_("Input parameter of class " << mxGetClassName(dataref) << " not supported yet"); 531 } 532 533 /*Assign output pointers:*/ 534 *pvector=vector; 535 } 536 /*}}}*/ 537 /*FUNCTION FetchData(BamgGeom** pbamggeom,const mxArray* dataref){{{*/ 538 void FetchData(BamgGeom** pbamggeom,const mxArray* dataref){ 539 540 /*Initialize output*/ 541 BamgGeom* bamggeom=new BamgGeom(); 542 543 /*Fetch all fields*/ 544 FetchData(&bamggeom->Vertices,&bamggeom->VerticesSize[0],&bamggeom->VerticesSize[1],mxGetAssignedField(dataref,0,"Vertices")); 545 FetchData(&bamggeom->Edges, &bamggeom->EdgesSize[0], &bamggeom->EdgesSize[1], mxGetAssignedField(dataref,0,"Edges")); 546 FetchData(&bamggeom->Corners, &bamggeom->CornersSize[0], &bamggeom->CornersSize[1], mxGetAssignedField(dataref,0,"Corners")); 547 FetchData(&bamggeom->RequiredVertices,&bamggeom->RequiredVerticesSize[0],&bamggeom->RequiredVerticesSize[1],mxGetAssignedField(dataref,0,"RequiredVertices")); 548 FetchData(&bamggeom->RequiredEdges, &bamggeom->RequiredEdgesSize[0], &bamggeom->RequiredEdgesSize[1], mxGetAssignedField(dataref,0,"RequiredEdges")); 549 FetchData(&bamggeom->CrackedEdges,&bamggeom->CrackedEdgesSize[0],&bamggeom->CrackedEdgesSize[1],mxGetAssignedField(dataref,0,"CrackedEdges")); 550 FetchData(&bamggeom->SubDomains,&bamggeom->SubDomainsSize[0],&bamggeom->SubDomainsSize[1],mxGetAssignedField(dataref,0,"SubDomains")); 551 552 /*Assign output pointers:*/ 553 *pbamggeom=bamggeom; 554 } 555 /*}}}*/ 556 /*FUNCTION FetchData(BamgMesh** pbamgmesh,const mxArray* dataref){{{*/ 557 void FetchData(BamgMesh** pbamgmesh,const mxArray* dataref){ 558 559 /*Initialize output*/ 560 BamgMesh* bamgmesh=new BamgMesh(); 561 562 /*Fetch all fields*/ 563 FetchData(&bamgmesh->Vertices,&bamgmesh->VerticesSize[0],&bamgmesh->VerticesSize[1],mxGetAssignedField(dataref,0,"Vertices")); 564 FetchData(&bamgmesh->Edges, &bamgmesh->EdgesSize[0], &bamgmesh->EdgesSize[1], mxGetAssignedField(dataref,0,"Edges")); 565 FetchData(&bamgmesh->Triangles, &bamgmesh->TrianglesSize[0], &bamgmesh->TrianglesSize[1], mxGetAssignedField(dataref,0,"Triangles")); 566 FetchData(&bamgmesh->CrackedEdges,&bamgmesh->CrackedEdgesSize[0],&bamgmesh->CrackedEdgesSize[1],mxGetAssignedField(dataref,0,"CrackedEdges")); 567 FetchData(&bamgmesh->VerticesOnGeomEdge,&bamgmesh->VerticesOnGeomEdgeSize[0],&bamgmesh->VerticesOnGeomEdgeSize[1],mxGetAssignedField(dataref,0,"VerticesOnGeomEdge")); 568 FetchData(&bamgmesh->VerticesOnGeomVertex,&bamgmesh->VerticesOnGeomVertexSize[0],&bamgmesh->VerticesOnGeomVertexSize[1],mxGetAssignedField(dataref,0,"VerticesOnGeomVertex")); 569 FetchData(&bamgmesh->EdgesOnGeomEdge, &bamgmesh->EdgesOnGeomEdgeSize[0], &bamgmesh->EdgesOnGeomEdgeSize[1], mxGetAssignedField(dataref,0,"EdgesOnGeomEdge")); 570 FetchData(&bamgmesh->IssmSegments,&bamgmesh->IssmSegmentsSize[0],&bamgmesh->IssmSegmentsSize[1],mxGetAssignedField(dataref,0,"IssmSegments")); 571 572 /*Assign output pointers:*/ 573 *pbamgmesh=bamgmesh; 574 } 575 /*}}}*/ 576 /*FUNCTION FetchData(BamgOpts** pbamgopts,const mxArray* dataref){{{*/ 577 void FetchData(BamgOpts** pbamgopts,const mxArray* dataref){ 578 579 /*Initialize output*/ 580 BamgOpts* bamgopts=new BamgOpts(); 581 582 /*Fetch all fields*/ 583 FetchData(&bamgopts->anisomax,mxGetField(dataref,0,"anisomax")); 584 FetchData(&bamgopts->cutoff,mxGetField(dataref,0,"cutoff")); 585 FetchData(&bamgopts->coeff,mxGetField(dataref,0,"coeff")); 586 FetchData(&bamgopts->errg,mxGetField(dataref,0,"errg")); 587 FetchData(&bamgopts->gradation,mxGetField(dataref,0,"gradation")); 588 FetchData(&bamgopts->Hessiantype,mxGetField(dataref,0,"Hessiantype")); 589 FetchData(&bamgopts->MaxCornerAngle,mxGetField(dataref,0,"MaxCornerAngle")); 590 FetchData(&bamgopts->maxnbv,mxGetField(dataref,0,"maxnbv")); 591 FetchData(&bamgopts->maxsubdiv,mxGetField(dataref,0,"maxsubdiv")); 592 FetchData(&bamgopts->Metrictype,mxGetField(dataref,0,"Metrictype")); 593 FetchData(&bamgopts->nbjacobi,mxGetField(dataref,0,"nbjacobi")); 594 FetchData(&bamgopts->nbsmooth,mxGetField(dataref,0,"nbsmooth")); 595 FetchData(&bamgopts->omega,mxGetField(dataref,0,"omega")); 596 FetchData(&bamgopts->power,mxGetField(dataref,0,"power")); 597 FetchData(&bamgopts->verbose,mxGetField(dataref,0,"verbose")); 598 599 FetchData(&bamgopts->Crack,mxGetField(dataref,0,"Crack")); 600 FetchData(&bamgopts->geometricalmetric,mxGetField(dataref,0,"geometricalmetric")); 601 FetchData(&bamgopts->KeepVertices,mxGetField(dataref,0,"KeepVertices")); 602 FetchData(&bamgopts->splitcorners,mxGetField(dataref,0,"splitcorners")); 603 604 FetchData(&bamgopts->hmin,mxGetField(dataref,0,"hmin")); 605 FetchData(&bamgopts->hmax,mxGetField(dataref,0,"hmax")); 606 FetchData(&bamgopts->hminVertices,&bamgopts->hminVerticesSize[0],&bamgopts->hminVerticesSize[1],mxGetField(dataref,0,"hminVertices")); 607 FetchData(&bamgopts->hmaxVertices,&bamgopts->hmaxVerticesSize[0],&bamgopts->hmaxVerticesSize[1],mxGetField(dataref,0,"hmaxVertices")); 608 FetchData(&bamgopts->hVertices,&bamgopts->hVerticesSize[0],&bamgopts->hVerticesSize[1],mxGetField(dataref,0,"hVertices")); 609 FetchData(&bamgopts->metric,&bamgopts->metricSize[0],&bamgopts->metricSize[1],mxGetField(dataref,0,"metric")); 610 FetchData(&bamgopts->field,&bamgopts->fieldSize[0],&bamgopts->fieldSize[1],mxGetField(dataref,0,"field")); 611 FetchData(&bamgopts->err,&bamgopts->errSize[0],&bamgopts->errSize[1],mxGetField(dataref,0,"err")); 612 613 /*Additional checks*/ 614 bamgopts->Check(); 615 616 /*Assign output pointers:*/ 617 *pbamgopts=bamgopts; 618 } 619 /*}}}*/ 620 /*FUNCTION FetchData(Options** poptions,const mxArray** pdataref){{{*/ 621 void FetchData(Options** poptions,int istart, int nrhs,const mxArray** pdataref){ 622 623 char *name = NULL; 624 Option *option = NULL; 625 626 /*Initialize output*/ 627 Options* options=new Options(); 628 629 /*Fetch all options*/ 630 for (int i=istart; i<nrhs; i=i+2){ 631 if (!mxIsClass(pdataref[i],"char")) _error_("Argument " << i+1 << " must be name of option"); 632 633 FetchData(&name,pdataref[i]); 634 if(i+1 == nrhs) _error_("Argument " << i+2 << " must exist and be value of option \"" << name << "\"."); 635 636 option=(Option*)OptionParse(name,&pdataref[i+1]); 637 options->AddOption(option); 638 option=NULL; 639 } 640 641 /*Assign output pointers:*/ 642 *poptions=options; 643 } 644 /*}}}*/ 645 /*FUNCTION FetchData(DataSet** pcontours,const mxArray* dataref){{{*/ 646 void FetchData(DataSet** pcontours,const mxArray* dataref){ 647 648 int numcontours,index,test1,test2; 649 char *contourname = NULL; 650 DataSet *contours = NULL; 651 Contour<double> *contouri = NULL; 652 653 if (mxIsClass(dataref,"char")){ 654 FetchData(&contourname,dataref); 655 contours=DomainOutlineRead<double>(contourname); 656 } 657 else if(mxIsClass(dataref,"struct")){ 658 659 contours=new DataSet(0); 660 numcontours=mxGetNumberOfElements(dataref); 661 662 for(int i=0;i<numcontours;i++){ 663 664 contouri=xNew<Contour<double> >(1); 665 666 index = mxGetFieldNumber(dataref,"nods"); 667 if(index==-1) _error_("input structure does not have a 'nods' field"); 668 FetchData(&contouri->nods,mxGetFieldByNumber(dataref,i,index)); 669 670 index = mxGetFieldNumber(dataref,"x"); 671 if(index==-1) _error_("input structure does not have a 'x' field"); 672 FetchData(&contouri->x,&test1,&test2,mxGetFieldByNumber(dataref,i,index)); 673 if(test1!=contouri->nods || test2!=1) _error_("field x should be of size ["<<contouri->nods<<" 1]"); 674 675 index = mxGetFieldNumber(dataref,"y"); 676 if(index==-1) _error_("input structure does not have a 'y' field"); 677 FetchData(&contouri->y,&test1,&test2,mxGetFieldByNumber(dataref,i,index)); 678 if(test1!=contouri->nods || test2!=1) _error_("field y should be of size ["<<contouri->nods<<" 1]"); 679 680 contours->AddObject(contouri); 681 } 682 } 683 else{ 684 _error_("Contour is neither a string nor a structure and cannot be loaded ("<<mxGetClassName(dataref)<<" not supported)"); 685 } 686 687 /*clean-up and assign output pointer*/ 688 xDelete<char>(contourname); 689 *pcontours=contours; 690 } 691 /*}}}*/ -
../trunk-jpl/src/wrappers/matlab/io/MatlabVectorToDoubleVector.cpp
1 /* \file MatlabVectorToDoubleVector.cpp 2 * \brief: convert a sparse or dense matlab vector to a serial vector: 3 */ 4 5 #ifdef HAVE_CONFIG_H 6 #include <config.h> 7 #else 8 #error "Cannot compile with HAVE_CONFIG_H symbol! run configure first!" 9 #endif 10 11 #include <string.h> 12 13 /*Matlab includes: */ 14 #include "./matlabio.h" 15 #include "../../c/shared/shared.h" 16 17 int MatlabVectorToDoubleVector(double** pvector,int* pvector_rows,const mxArray* mxvector){ 18 19 int rows,cols; 20 double* mxvector_ptr=NULL; 21 int ierr; 22 int i,j; 23 24 /*output: */ 25 double* vector=NULL; 26 27 /*matlab indices: */ 28 mwIndex* ir=NULL; 29 mwIndex* jc=NULL; 30 double* pr=NULL; 31 int count; 32 int nnz; 33 int nz; 34 35 /*Ok, first check if we are dealing with a sparse or full vector: */ 36 if (mxIsSparse(mxvector)){ 37 38 /*Dealing with sparse vector: recover size first: */ 39 mxvector_ptr=(double*)mxGetPr(mxvector); 40 rows=mxGetM(mxvector); 41 cols=mxGetN(mxvector); 42 nnz=mxGetNzmax(mxvector); 43 44 /*Check that input is actualy a vector*/ 45 if (cols!=1) _error_("input vector of size " << rows << "x" << cols << " should have only one column"); 46 47 nz=(int)((double)nnz/(double)rows); 48 49 if(rows){ 50 vector=xNewZeroInit<double>(rows); 51 52 /*Now, get ir,jc and pr: */ 53 pr=mxGetPr(mxvector); 54 ir=mxGetIr(mxvector); 55 jc=mxGetJc(mxvector); 56 57 /*Now, start inserting data into sparse vector: */ 58 count=0; 59 for(i=0;i<cols;i++){ 60 for(j=0;j<(jc[i+1]-jc[i]);j++){ 61 vector[ir[count]]=pr[count]; 62 count++; 63 } 64 } 65 } 66 67 } 68 else{ 69 70 /*Dealing with dense vector: recover pointer and size: */ 71 mxvector_ptr=(double*)mxGetPr(mxvector); 72 rows=mxGetM(mxvector); 73 cols=mxGetN(mxvector); 74 75 /*Check that input is actualy a vector*/ 76 if (cols!=1) _error_("input vector of size " << rows << "x" << cols << " should have only one column"); 77 78 /*allocate and memcpy*/ 79 if(rows){ 80 vector=xNew<double>(rows); 81 memcpy(vector,mxvector_ptr,rows*sizeof(double)); 82 } 83 else{ 84 vector=NULL; 85 } 86 } 87 88 /*Assign output pointer: */ 89 *pvector=vector; 90 *pvector_rows=rows; 91 92 return 1; 93 } -
../trunk-jpl/src/wrappers/matlab/io/WriteMatlabData.cpp
1 /* \file WriteData.c: 2 * \brief: general interface for writing data 3 */ 4 5 #ifdef HAVE_CONFIG_H 6 #include <config.h> 7 #else 8 #error "Cannot compile with HAVE_CONFIG_H symbol! run configure first!" 9 #endif 10 11 #include "./matlabio.h" 12 #include "../../c/shared/shared.h" 13 14 /*Primitive data types*/ 15 /*FUNCTION WriteData(mxArray** pdataref,double* matrix, int M,int N){{{*/ 16 void WriteData(mxArray** pdataref,double* matrix, int M,int N){ 17 18 mxArray *dataref = NULL; 19 double *tmatrix = NULL; 20 21 if(matrix){ 22 /*create the matlab matrixwith Matlab's memory manager */ 23 tmatrix=(double*)mxMalloc(M*N*sizeof(double)); 24 for(int i=0;i<M;i++){ 25 for(int j=0;j<N;j++){ 26 tmatrix[j*M+i]=matrix[i*N+j]; 27 } 28 } 29 dataref = mxCreateDoubleMatrix(0,0,mxREAL); 30 mxSetM(dataref,(mwSize)M); 31 mxSetN(dataref,(mwSize)N); 32 mxSetPr(dataref,(double*)tmatrix); 33 } 34 else{ 35 dataref = mxCreateDoubleMatrix(0,0,mxREAL); 36 } 37 *pdataref=dataref; 38 } 39 /*}}}*/ 40 /*FUNCTION WriteData(mxArray** pdataref,int* matrix, int M,int N){{{*/ 41 void WriteData(mxArray** pdataref,int* matrix, int M,int N){ 42 43 mxArray* dataref = NULL; 44 double* tmatrix = NULL; 45 46 if(matrix){ 47 /*convert to double matrix using Matlab's memory manager*/ 48 double* tmatrix=(double*)mxMalloc(M*N*sizeof(double)); 49 for(int i=0;i<M;i++){ 50 for(int j=0;j<N;j++){ 51 tmatrix[j*M+i]=(double)matrix[i*N+j]; 52 } 53 } 54 dataref = mxCreateDoubleMatrix(0,0,mxREAL); 55 mxSetM(dataref,(mwSize)M); 56 mxSetN(dataref,(mwSize)N); 57 mxSetPr(dataref,(double*)tmatrix); 58 } 59 else{ 60 dataref = mxCreateDoubleMatrix(0,0,mxREAL); 61 } 62 *pdataref=dataref; 63 } 64 /*}}}*/ 65 /*FUNCTION WriteData(mxArray** pdataref,double* vector, int M){{{*/ 66 void WriteData(mxArray** pdataref,double* vector, int M){ 67 68 mxArray* dataref = NULL; 69 double* vector_matlab = NULL; 70 71 if(vector){ 72 73 /*create the matlab vector with Matlab's memory manager */ 74 vector_matlab=(double*)mxMalloc(M*sizeof(double)); 75 for(int i=0;i<M;i++) vector_matlab[i]=vector[i]; 76 dataref = mxCreateDoubleMatrix(0,0,mxREAL); 77 mxSetM(dataref,(mwSize)M); 78 mxSetN(dataref,(mwSize)1); 79 mxSetPr(dataref,vector_matlab); 80 } 81 else{ 82 dataref = mxCreateDoubleMatrix(0,0,mxREAL); 83 } 84 85 *pdataref=dataref; 86 } 87 /*}}}*/ 88 /*FUNCTION WriteData(mxArray** pdataref,double scalar){{{*/ 89 void WriteData(mxArray** pdataref,double scalar){ 90 91 *pdataref=mxCreateDoubleScalar(scalar); 92 } 93 /*}}}*/ 94 /*FUNCTION WriteData(mxArray** pdataref,int integer){{{*/ 95 void WriteData(mxArray** pdataref,int integer){ 96 97 *pdataref=mxCreateDoubleScalar((double)integer); 98 99 } 100 /*}}}*/ 101 /*FUNCTION WriteData(mxArray** pdataref,int boolean){{{*/ 102 void WriteData(mxArray** pdataref,bool boolean){ 103 104 *pdataref=mxCreateDoubleScalar((double)boolean); 105 106 } 107 /*}}}*/ 108 /*FUNCTION WriteData(mxArray** pdataref,char* string){{{*/ 109 void WriteData(mxArray** pdataref,char* string){ 110 111 *pdataref=mxCreateString(string); 112 } 113 /*}}}*/ 114 /*FUNCTION WriteData(mxArray** pdataref){{{*/ 115 void WriteData(mxArray** pdataref){ 116 117 ; 118 119 } 120 /*}}}*/ 121 122 /*ISSM objects*/ 123 /*FUNCTION WriteData(mxArray** pdataref,BamgGeom* bamggeom){{{*/ 124 void WriteData(mxArray** pdataref,BamgGeom* bamggeom){ 125 126 /*Intermediary*/ 127 int i; 128 mxArray *dataref = NULL; 129 const int numfields = 8; 130 const char *fnames[numfields]; 131 mwSize ndim = 2; 132 mwSize dimensions[2] = {1,1}; 133 134 /*Initialize field names*/ 135 i=0; 136 fnames[i++] = "Vertices"; 137 fnames[i++] = "Edges"; 138 fnames[i++] = "TangentAtEdges"; 139 fnames[i++] = "Corners"; 140 fnames[i++] = "RequiredVertices"; 141 fnames[i++] = "RequiredEdges"; 142 fnames[i++] = "CrackedEdges"; 143 fnames[i++] = "SubDomains"; 144 _assert_(i==numfields); 145 146 /*Initialize Matlab structure*/ 147 dataref=mxCreateStructArray(ndim,dimensions,numfields,fnames); 148 149 /*set each matlab each field*/ 150 i=0; 151 i++; SetStructureField(dataref,"Vertices", bamggeom->VerticesSize[0], bamggeom->VerticesSize[1], bamggeom->Vertices); 152 i++; SetStructureField(dataref,"Edges", bamggeom->EdgesSize[0], bamggeom->EdgesSize[1], bamggeom->Edges); 153 i++; SetStructureField(dataref,"TangentAtEdges", bamggeom->TangentAtEdgesSize[0], bamggeom->TangentAtEdgesSize[1], bamggeom->TangentAtEdges); 154 i++; SetStructureField(dataref,"Corners", bamggeom->CornersSize[0], bamggeom->CornersSize[1], bamggeom->Corners); 155 i++; SetStructureField(dataref,"RequiredVertices",bamggeom->RequiredVerticesSize[0],bamggeom->RequiredVerticesSize[1],bamggeom->RequiredVertices); 156 i++; SetStructureField(dataref,"RequiredEdges", bamggeom->RequiredEdgesSize[0], bamggeom->RequiredEdgesSize[1], bamggeom->RequiredEdges); 157 i++; SetStructureField(dataref,"CrackedEdges", bamggeom->CrackedEdgesSize[0], bamggeom->CrackedEdgesSize[1], bamggeom->CrackedEdges); 158 i++; SetStructureField(dataref,"SubDomains", bamggeom->SubDomainsSize[0], bamggeom->SubDomainsSize[1], bamggeom->SubDomains); 159 _assert_(i==numfields); 160 161 /*Assign output*/ 162 *pdataref=dataref; 163 } 164 /*}}}*/ 165 /*FUNCTION WriteData(mxArray** pdataref,BamgMesh* bamgmesh){{{*/ 166 void WriteData(mxArray** pdataref,BamgMesh* bamgmesh){ 167 168 /*Intermediary*/ 169 int i; 170 mxArray *dataref = NULL; 171 const int numfields = 16; 172 const char *fnames[numfields]; 173 mwSize ndim = 2; 174 mwSize dimensions[2] = {1,1}; 175 176 /*Initialize field names*/ 177 i=0; 178 fnames[i++] = "Vertices"; 179 fnames[i++] = "Edges"; 180 fnames[i++] = "Triangles"; 181 fnames[i++] = "Quadrilaterals"; 182 fnames[i++] = "IssmEdges"; 183 fnames[i++] = "IssmSegments"; 184 fnames[i++] = "VerticesOnGeomVertex"; 185 fnames[i++] = "VerticesOnGeomEdge"; 186 fnames[i++] = "EdgesOnGeomEdge"; 187 fnames[i++] = "SubDomains"; 188 fnames[i++] = "SubDomainsFromGeom"; 189 fnames[i++] = "ElementConnectivity"; 190 fnames[i++] = "NodalConnectivity"; 191 fnames[i++] = "NodalElementConnectivity"; 192 fnames[i++] = "CrackedVertices"; 193 fnames[i++] = "CrackedEdges"; 194 _assert_(i==numfields); 195 196 /*Initialize Matlab structure*/ 197 dataref=mxCreateStructArray(ndim,dimensions,numfields,fnames); 198 199 /*set each matlab each field*/ 200 i=0; 201 i++; SetStructureField(dataref,"Vertices",bamgmesh->VerticesSize[0], bamgmesh->VerticesSize[1],bamgmesh->Vertices); 202 i++; SetStructureField(dataref,"Edges", bamgmesh->EdgesSize[0],bamgmesh->EdgesSize[1], bamgmesh->Edges); 203 i++; SetStructureField(dataref,"Triangles", bamgmesh->TrianglesSize[0],bamgmesh->TrianglesSize[1], bamgmesh->Triangles); 204 i++; SetStructureField(dataref,"Quadrilaterals",bamgmesh->QuadrilateralsSize[0], bamgmesh->QuadrilateralsSize[1],bamgmesh->Quadrilaterals); 205 i++; SetStructureField(dataref,"IssmEdges", bamgmesh->IssmEdgesSize[0],bamgmesh->IssmEdgesSize[1], bamgmesh->IssmEdges); 206 i++; SetStructureField(dataref,"IssmSegments",bamgmesh->IssmSegmentsSize[0], bamgmesh->IssmSegmentsSize[1],bamgmesh->IssmSegments); 207 i++; SetStructureField(dataref,"VerticesOnGeomVertex",bamgmesh->VerticesOnGeomVertexSize[0],bamgmesh->VerticesOnGeomVertexSize[1], bamgmesh->VerticesOnGeomVertex); 208 i++; SetStructureField(dataref,"VerticesOnGeomEdge",bamgmesh->VerticesOnGeomEdgeSize[0],bamgmesh->VerticesOnGeomEdgeSize[1], bamgmesh->VerticesOnGeomEdge); 209 i++; SetStructureField(dataref,"EdgesOnGeomEdge", bamgmesh->EdgesOnGeomEdgeSize[0], bamgmesh->EdgesOnGeomEdgeSize[1],bamgmesh->EdgesOnGeomEdge); 210 i++; SetStructureField(dataref,"SubDomains",bamgmesh->SubDomainsSize[0], bamgmesh->SubDomainsSize[1],bamgmesh->SubDomains); 211 i++; SetStructureField(dataref,"SubDomainsFromGeom", bamgmesh->SubDomainsFromGeomSize[0], bamgmesh->SubDomainsFromGeomSize[1],bamgmesh->SubDomainsFromGeom); 212 i++; SetStructureField(dataref,"ElementConnectivity",bamgmesh->ElementConnectivitySize[0],bamgmesh->ElementConnectivitySize[1], bamgmesh->ElementConnectivity); 213 i++; SetStructureField(dataref,"NodalConnectivity",bamgmesh->NodalConnectivitySize[0],bamgmesh->NodalConnectivitySize[1], bamgmesh->NodalConnectivity); 214 i++; SetStructureField(dataref,"NodalElementConnectivity", bamgmesh->NodalElementConnectivitySize[0], bamgmesh->NodalElementConnectivitySize[1],bamgmesh->NodalElementConnectivity); 215 i++; SetStructureField(dataref,"CrackedVertices", bamgmesh->CrackedVerticesSize[0],bamgmesh->CrackedVerticesSize[1], bamgmesh->CrackedVertices); 216 i++; SetStructureField(dataref,"CrackedEdges",bamgmesh->CrackedEdgesSize[0], bamgmesh->CrackedEdgesSize[1],bamgmesh->CrackedEdges); 217 _assert_(i==numfields); 218 219 /*Assign output*/ 220 *pdataref=dataref; 221 } 222 /*}}}*/ 223 /*FUNCTION WriteData(mxArray** pdataref,SeqMat<double>* matrix){{{*/ 224 void WriteData(mxArray** pdataref,SeqMat<double>* matrix){ 225 226 int i,j; 227 int rows,cols; 228 mxArray *dataref = NULL; 229 double *matrix_ptr = NULL; 230 double *tmatrix_ptr = NULL; 231 232 if(matrix){ 233 234 matrix_ptr=matrix->ToSerial(); 235 matrix->GetSize(&rows,&cols); 236 237 /*Now transpose the matrix and allocate with Matlab's memory manager: */ 238 tmatrix_ptr=(double*)mxMalloc(rows*cols*sizeof(double)); 239 for(i=0;i<rows;i++){ 240 for(j=0;j<cols;j++){ 241 tmatrix_ptr[j*rows+i]=matrix_ptr[i*cols+j]; 242 } 243 } 244 245 /*create matlab matrix: */ 246 dataref=mxCreateDoubleMatrix(0,0,mxREAL); 247 mxSetM(dataref,rows); 248 mxSetN(dataref,cols); 249 mxSetPr(dataref,tmatrix_ptr); 250 251 /*Free ressources:*/ 252 xDelete<double>(matrix_ptr); 253 } 254 else{ 255 dataref = mxCreateDoubleMatrix(0,0,mxREAL); 256 } 257 258 *pdataref=dataref; 259 } 260 /*}}}*/ 261 /*FUNCTION WriteData(mxArray** pdataref,SeqVec<double>* vector){{{*/ 262 void WriteData(mxArray** pdataref,SeqVec<double>* vector){ 263 264 mxArray* dataref=NULL; 265 double* vector_ptr=NULL; 266 double* vector_matlab=NULL; 267 int rows; 268 269 if(vector){ 270 /*call toolkit routine: */ 271 vector_ptr=vector->ToMPISerial(); 272 vector->GetSize(&rows); 273 274 /*now create the matlab vector with Matlab's memory manager */ 275 vector_matlab=(double*)mxMalloc(rows*sizeof(double)); 276 for(int i=0;i<rows;i++) vector_matlab[i]=vector_ptr[i]; 277 278 dataref = mxCreateDoubleMatrix(0,0,mxREAL); 279 mxSetM(dataref,rows); 280 mxSetN(dataref,1); 281 mxSetPr(dataref,vector_matlab); 282 } 283 else{ 284 dataref = mxCreateDoubleMatrix(0,0,mxREAL); 285 } 286 287 /*Clean-up and return*/ 288 xDelete<double>(vector_ptr); 289 *pdataref=dataref; 290 } 291 /*}}}*/ 292 /*FUNCTION WriteData(mxArray** pdataref,RiftStruct* riftstruct){{{*/ 293 void WriteData(mxArray** pdataref,RiftStruct* riftstruct){ 294 295 /*Intermediary*/ 296 int i; 297 mxArray *dataref = NULL; 298 const int numfields = 10; 299 const char *fnames[numfields]; 300 mwSize ndim = 2; 301 mwSize dimensions[2] = {1,1}; 302 303 /*Initialize field names*/ 304 i=0; 305 fnames[i++] = "numsegs"; 306 fnames[i++] = "segments"; 307 fnames[i++] = "pairs"; 308 fnames[i++] = "tips"; 309 fnames[i++] = "penaltypairs"; 310 fnames[i++] = "fill"; 311 fnames[i++] = "friction"; 312 fnames[i++] = "fraction"; 313 fnames[i++] = "fractionincrement"; 314 fnames[i++] = "state"; 315 _assert_(i==numfields); 316 317 /*Initialize matlab structure of dimension numrifts*/ 318 dimensions[0]=riftstruct->numrifts; 319 dataref=mxCreateStructArray(ndim,dimensions,numfields,fnames); 320 321 /*set each matlab each field*/ 322 for(int i=0;i<riftstruct->numrifts;i++){ 323 SetStructureFieldi(dataref,i,"numsegs" ,riftstruct->riftsnumsegments[i]); 324 SetStructureFieldi(dataref,i,"segments" ,riftstruct->riftsnumsegments[i] ,3,riftstruct->riftssegments[i]); 325 SetStructureFieldi(dataref,i,"pairs" ,riftstruct->riftsnumpairs[i] ,2,riftstruct->riftspairs[i]); 326 SetStructureFieldi(dataref,i,"tips" ,1 ,2,&riftstruct->riftstips[2*i]); 327 SetStructureFieldi(dataref,i,"penaltypairs" ,riftstruct->riftsnumpenaltypairs[i],7,riftstruct->riftspenaltypairs[i]); 328 SetStructureFieldi(dataref,i,"fill" ,IceEnum); 329 SetStructureFieldi(dataref,i,"friction" ,0); 330 SetStructureFieldi(dataref,i,"fraction" ,0.); 331 SetStructureFieldi(dataref,i,"fractionincrement",0.1); 332 SetStructureFieldi(dataref,i,"state" ,riftstruct->riftsnumpenaltypairs[i],1,riftstruct->state[i]); 333 } 334 335 /*Assign output*/ 336 *pdataref=dataref; 337 } 338 /*}}}*/ 339 340 /*Toolkit*/ 341 /*FUNCTION SetStructureField{{{*/ 342 void SetStructureField(mxArray* dataref,const char* fieldname,int M,int N,double* fieldpointer){ 343 344 mxArray* field = NULL; 345 346 /*Convert field*/ 347 WriteData(&field,fieldpointer,M,N); 348 349 /*Assign to structure*/ 350 mxSetField(dataref,0,fieldname,field); 351 } 352 /*}}}*/ 353 /*FUNCTION SetStructureFieldi(mxArray* dataref,int i,const char* fieldname,int M,int N,double* fieldpointer){{{*/ 354 void SetStructureFieldi(mxArray* dataref,int i,const char* fieldname,int M,int N,double* fieldpointer){ 355 356 mxArray* field = NULL; 357 358 /*Convert field*/ 359 WriteData(&field,fieldpointer,M,N); 360 361 /*Assign to structure*/ 362 mxSetField(dataref,i,fieldname,field); 363 } 364 /*}}}*/ 365 /*FUNCTION SetStructureFieldi(mxArray* dataref,int i,const char* fieldname,int field){{{*/ 366 void SetStructureFieldi(mxArray* dataref,int i,const char* fieldname,int fieldin){ 367 368 mxArray* field = NULL; 369 370 /*Convert field*/ 371 WriteData(&field,fieldin); 372 373 /*Assign to structure*/ 374 mxSetField(dataref,i,fieldname,field); 375 } 376 /*}}}*/ 377 /*FUNCTION SetStructureFieldi(mxArray* dataref,int i,const char* fieldname,double field){{{*/ 378 void SetStructureFieldi(mxArray* dataref,int i,const char* fieldname,double fieldin){ 379 380 mxArray* field = NULL; 381 382 /*Convert field*/ 383 WriteData(&field,fieldin); 384 385 /*Assign to structure*/ 386 mxSetField(dataref,i,fieldname,field); 387 } 388 /*}}}*/ -
../trunk-jpl/src/wrappers/matlab/io/mxGetAssignedField.cpp
1 /*!\file: mxGetAssignedField.c: 2 * \brief: abstract interface on parallel side for i/o, so it ressembles the serial i/o. 3 * 4 * In serial mode, this routine takes care of returning the field coming 5 * from the model. If largesize is 1, we are running out of core models in 6 * matlab, and we need to call the subsref private method from the model object 7 * in order to correctly load the data from disk. 8 */ 9 10 #include "./matlabio.h" 11 12 mxArray* mxGetAssignedField(const mxArray* pmxa_array,int number,const char* field){ 13 14 //output 15 mxArray* mxfield=NULL; 16 17 //input 18 mxArray *inputs[2]; 19 mxArray *pindex = NULL; 20 const char *fnames[2]; 21 mwSize ndim = 2; 22 mwSize onebyone[2] = {1,1}; 23 24 //We want to call the subsasgn method, and get the returned array.This ensures that if we are running 25 //large sized problems, the data is truly loaded from disk by the model subsasgn class method. 26 inputs[0]=(mxArray*)pmxa_array; //this is the model 27 28 //create index structure used in the assignment (index.type='.' and index.subs='x' for field x for ex) 29 fnames[0] = "type"; 30 fnames[1] = "subs"; 31 pindex=mxCreateStructArray( ndim,onebyone,2,fnames); 32 mxSetField( pindex, 0, "type",mxCreateString(".")); 33 mxSetField( pindex, 0, "subs",mxCreateString(field)); 34 inputs[1]=pindex; 35 36 mexCallMATLAB( 1, &mxfield, 2, (mxArray**)inputs, "subsref"); 37 38 return mxfield; 39 } -
../trunk-jpl/src/wrappers/matlab/io/MatlabMatrixToDoubleMatrix.cpp
1 /* \file MatlabMatrixToDoubleMatrix.cpp 2 * \brief: convert a sparse or dense matlab matrix to a double* pointer 3 */ 4 5 #ifdef HAVE_CONFIG_H 6 #include <config.h> 7 #else 8 #error "Cannot compile with HAVE_CONFIG_H symbol! run configure first!" 9 #endif 10 11 /*Matlab includes: */ 12 #include "./matlabio.h" 13 #include "../../c/shared/shared.h" 14 15 int MatlabMatrixToDoubleMatrix(double** pmatrix,int* pmatrix_rows,int* pmatrix_cols,const mxArray* mxmatrix){ 16 17 int i,j,count,rows,cols; 18 19 /*output: */ 20 double* matrix=NULL; 21 22 /*matlab indices: */ 23 mwIndex* ir=NULL; 24 mwIndex* jc=NULL; 25 26 /*Ok, first check if we are dealing with a sparse or full matrix: */ 27 if (mxIsSparse(mxmatrix)){ 28 29 /*Dealing with sparse matrix: recover size first: */ 30 double* pmxmatrix=(double*)mxGetPr(mxmatrix); 31 rows=mxGetM(mxmatrix); 32 cols=mxGetN(mxmatrix); 33 34 if(rows*cols){ 35 matrix=xNewZeroInit<double>(rows*cols); 36 37 /*Now, get ir,jc and pr: */ 38 ir=mxGetIr(mxmatrix); 39 jc=mxGetJc(mxmatrix); 40 41 /*Now, start inserting data into double* matrix: */ 42 count=0; 43 for(i=0;i<cols;i++){ 44 for(j=0;j<(jc[i+1]-jc[i]);j++){ 45 matrix[rows*ir[count]+i]=pmxmatrix[count]; 46 count++; 47 } 48 } 49 } 50 51 } 52 else if(mxIsClass(mxmatrix,"double")){ 53 /*Dealing with dense matrix: recover pointer and size: */ 54 double* pmxmatrix=(double*)mxGetPr(mxmatrix); 55 rows=mxGetM(mxmatrix); 56 cols=mxGetN(mxmatrix); 57 58 /*Create serial matrix: */ 59 if(rows*cols){ 60 matrix=xNewZeroInit<double>(rows*cols); 61 62 for(i=0;i<rows;i++){ 63 for(j=0;j<cols;j++){ 64 matrix[cols*i+j]=(double)pmxmatrix[rows*j+i]; 65 } 66 } 67 } 68 } 69 else if(mxIsClass(mxmatrix,"single")){ 70 /*Dealing with dense matrix: recover pointer and size: */ 71 float *pmxmatrix=(float*)mxGetPr(mxmatrix); 72 rows=mxGetM(mxmatrix); 73 cols=mxGetN(mxmatrix); 74 75 /*Create serial matrix: */ 76 if(rows*cols){ 77 matrix=xNewZeroInit<double>(rows*cols); 78 79 for(i=0;i<rows;i++){ 80 for(j=0;j<cols;j++){ 81 matrix[cols*i+j]=(double)pmxmatrix[rows*j+i]; 82 } 83 } 84 } 85 } 86 else if(mxIsClass(mxmatrix,"int16")){ 87 /*Dealing with dense matrix: recover pointer and size: */ 88 short int *pmxmatrix=(short*)mxGetPr(mxmatrix); 89 rows=mxGetM(mxmatrix); 90 cols=mxGetN(mxmatrix); 91 92 /*Create serial matrix: */ 93 if(rows*cols){ 94 matrix=xNewZeroInit<double>(rows*cols); 95 96 for(i=0;i<rows;i++){ 97 for(j=0;j<cols;j++){ 98 matrix[cols*i+j]=(double)pmxmatrix[rows*j+i]; 99 } 100 } 101 } 102 } 103 else if(mxIsClass(mxmatrix,"uint8")){ 104 /*Dealing with dense matrix: recover pointer and size: */ 105 char *pmxmatrix=(char*)mxGetPr(mxmatrix); 106 rows=mxGetM(mxmatrix); 107 cols=mxGetN(mxmatrix); 108 109 /*Create serial matrix: */ 110 if(rows*cols){ 111 matrix=xNewZeroInit<double>(rows*cols); 112 113 for(i=0;i<rows;i++){ 114 for(j=0;j<cols;j++){ 115 matrix[cols*i+j]=(double)pmxmatrix[rows*j+i]; 116 } 117 } 118 } 119 } 120 else{ 121 _error_("Matlab matrix type Not implemented yet"); 122 } 123 124 /*Assign output pointer: */ 125 *pmatrix=matrix; 126 *pmatrix_rows=rows; 127 *pmatrix_cols=cols; 128 129 return 1; 130 } -
../trunk-jpl/src/wrappers/matlab/io/MatlabMatrixToPetscMat.cpp
1 /* \file MatlabMatrixToPetscMatrix.cpp 2 * \brief: convert a sparse or dense matlab matrix to a serial Petsc matrix: 3 */ 4 5 #ifdef HAVE_CONFIG_H 6 #include <config.h> 7 #else 8 #error "Cannot compile with HAVE_CONFIG_H symbol! run configure first!" 9 #endif 10 #include "../../c/shared/shared.h" 11 12 /*Petsc includes: */ 13 #include <petscmat.h> 14 #include <petscvec.h> 15 #include <petscksp.h> 16 17 /*Matlab includes: */ 18 #include "./matlabio.h" 19 20 PetscMat* MatlabMatrixToPetscMat(const mxArray* mxmatrix){ 21 22 int dummy; 23 PetscMat* matrix=new PetscMat(); 24 25 MatlabMatrixToPetscMat(&matrix->matrix, &dummy, &dummy, mxmatrix); 26 27 return matrix; 28 } 29 int MatlabMatrixToPetscMat(Mat* pmatrix,int* pmatrix_rows,int* pmatrix_cols,const mxArray* mxmatrix){ 30 31 int rows, cols; 32 double *mxmatrix_ptr = NULL; 33 double *tmatrix = NULL; 34 int ierr; 35 int i,j; 36 37 /*output: */ 38 Mat matrix = NULL; 39 40 /*matlab indices: */ 41 mwIndex *ir = NULL; 42 mwIndex *jc = NULL; 43 double *pr = NULL; 44 int count; 45 int nnz; 46 int nz; 47 48 /*petsc indices: */ 49 int *idxm = NULL; 50 int *idxn = NULL; 51 52 /*Ok, first check if we are dealing with a sparse or full matrix: */ 53 if (mxIsSparse(mxmatrix)){ 54 55 /*Dealing with sparse matrix: recover size first: */ 56 mxmatrix_ptr=(double*)mxGetPr(mxmatrix); 57 rows=mxGetM(mxmatrix); 58 cols=mxGetN(mxmatrix); 59 nnz=mxGetNzmax(mxmatrix); 60 if(rows){ 61 nz=(int)((double)nnz/(double)rows); 62 } 63 else{ 64 nz=0; 65 } 66 67 ierr=MatCreateSeqAIJ(PETSC_COMM_SELF,rows,cols,nz,PETSC_NULL,&matrix);CHKERRQ(ierr); 68 69 /*Now, get ir,jc and pr: */ 70 pr=mxGetPr(mxmatrix); 71 ir=mxGetIr(mxmatrix); 72 jc=mxGetJc(mxmatrix); 73 74 /*Now, start inserting data into sparse matrix: */ 75 count=0; 76 for(i=0;i<cols;i++){ 77 for(j=0;j<(jc[i+1]-jc[i]);j++){ 78 MatSetValue(matrix,ir[count],i,pr[count],INSERT_VALUES); 79 count++; 80 } 81 } 82 } 83 else{ 84 /*Dealing with dense matrix: recover pointer and size: */ 85 mxmatrix_ptr=(double*)mxGetPr(mxmatrix); 86 rows=mxGetM(mxmatrix); 87 cols=mxGetN(mxmatrix); 88 89 /*transpose, as Petsc now does not allows MAT_COLUMN_ORIENTED matrices in MatSetValues: */ 90 tmatrix=xNew<double>(rows*cols); 91 for(i=0;i<cols;i++){ 92 for(j=0;j<rows;j++){ 93 *(tmatrix+rows*i+j)=*(mxmatrix_ptr+cols*j+i); 94 } 95 } 96 97 /*Create serial matrix: */ 98 ierr=MatCreateSeqDense(PETSC_COMM_SELF,rows,cols,NULL,&matrix);CHKERRQ(ierr); 99 100 /*Insert mxmatrix_ptr values into petsc matrix: */ 101 idxm=xNew<int>(rows); 102 idxn=xNew<int>(cols); 103 104 for(i=0;i<rows;i++)idxm[i]=i; 105 for(i=0;i<cols;i++)idxn[i]=i; 106 107 ierr=MatSetValues(matrix,rows,idxm,cols,idxn,tmatrix,INSERT_VALUES); CHKERRQ(ierr); 108 109 xDelete<double>(tmatrix); 110 } 111 112 /*Assemble matrix: */ 113 MatAssemblyBegin(matrix,MAT_FINAL_ASSEMBLY); 114 MatAssemblyEnd(matrix,MAT_FINAL_ASSEMBLY); 115 116 /*Assign output pointer: */ 117 *pmatrix=matrix; 118 if(pmatrix_rows) *pmatrix_rows=rows; 119 if(pmatrix_cols) *pmatrix_cols=cols; 120 121 return 1; 122 } -
../trunk-jpl/src/wrappers/matlab/io/MatlabVectorToVector.cpp
1 /*!\file MatlabVectorToVector.cpp 2 */ 3 4 /*Headers:*/ 5 #ifdef HAVE_CONFIG_H 6 #include <config.h> 7 #else 8 #error "Cannot compile with HAVE_CONFIG_H symbol! run configure first!" 9 #endif 10 #include <stdio.h> 11 #include <string.h> 12 #include "./matlabio.h" 13 #include "../../c/shared/shared.h" 14 #include "../../c/toolkits/toolkits.h" 15 16 Vector<double>* MatlabVectorToVector(const mxArray* mxvector){ 17 18 int dummy; 19 Vector<double>* vector=NULL; 20 21 /*allocate vector object: */ 22 vector=new Vector<double>(); 23 24 #ifdef _HAVE_PETSC_ 25 vector->pvector=MatlabVectorToPetscVec(mxvector); 26 #else 27 vector->svector=MatlabVectorToSeqVec(mxvector); 28 #endif 29 30 return vector; 31 } -
../trunk-jpl/src/wrappers/matlab/io/MatlabMatrixToMatrix.cpp
1 /*!\file MatlabMatrixToMatrix.cpp 2 */ 3 4 #ifdef HAVE_CONFIG_H 5 #include <config.h> 6 #else 7 #error "Cannot compile with HAVE_CONFIG_H symbol! run configure first!" 8 #endif 9 10 #include <stdio.h> 11 #include <string.h> 12 #include "./matlabio.h" 13 #include "../../c/shared/shared.h" 14 #include "../../c/toolkits/toolkits.h" 15 16 Matrix<double>* MatlabMatrixToMatrix(const mxArray* mxmatrix){ 17 18 int dummy; 19 Matrix<double>* matrix=NULL; 20 21 /*allocate matrix object: */ 22 matrix=new Matrix<double>(); 23 24 #ifdef _HAVE_PETSC_ 25 matrix->pmatrix=MatlabMatrixToPetscMat(mxmatrix); 26 #else 27 matrix->smatrix=MatlabMatrixToSeqMat(mxmatrix); 28 #endif 29 30 return matrix; 31 } -
../trunk-jpl/src/wrappers/matlab/io/MatlabNArrayToNArray.cpp
1 /* \file MatlabNArrayToNArray.cpp 2 * \brief: convert a sparse or dense matlab n-dimensional array to cpp n-dimensional array 3 */ 4 5 #ifdef HAVE_CONFIG_H 6 #include <config.h> 7 #else 8 #error "Cannot compile with HAVE_CONFIG_H symbol! run configure first!" 9 #endif 10 11 #include "./matlabio.h" 12 #include "../../c/shared/shared.h" 13 #include "../../c/include/include.h" 14 15 /*FUNCTION MatlabNArrayToNArray(double** pmatrix,int* pmatrix_numel,int* pmatrix_ndims,int** pmatrix_size,const mxArray* mxmatrix){{{*/ 16 int MatlabNArrayToNArray(double** pmatrix,int* pmatrix_numel,int* pmatrix_ndims,int** pmatrix_size,const mxArray* mxmatrix){ 17 18 int i,j,rows,cols; 19 int numel,ndims; 20 int *size,*dims; 21 double* mxmatrix_ptr=NULL; 22 const mwSize* ipt=NULL; 23 24 /*output: */ 25 double* matrix=NULL; 26 27 /*matlab indices: */ 28 mwIndex *ir = NULL; 29 mwIndex *jc = NULL; 30 double *pr = NULL; 31 int count; 32 33 /*get Matlab matrix information: */ 34 numel=mxGetNumberOfElements(mxmatrix); 35 ndims=mxGetNumberOfDimensions(mxmatrix); 36 ipt =mxGetDimensions(mxmatrix); 37 size =xNew<int>(ndims); 38 for (i=0;i<ndims;i++) size[i]=(int)ipt[i]; 39 40 /*Ok, first check if we are dealing with a sparse or full matrix: */ 41 if (mxIsSparse(mxmatrix)){ 42 43 /*Dealing with sparse matrix: recover size first: */ 44 rows = mxGetM(mxmatrix); 45 cols = mxGetN(mxmatrix); 46 47 matrix=xNewZeroInit<double>(rows*cols); 48 49 /*Now, get ir,jc and pr: */ 50 ir = mxGetIr(mxmatrix); 51 jc = mxGetJc(mxmatrix); 52 pr = mxGetPr(mxmatrix); 53 54 /*Now, start inserting data into double* matrix: */ 55 count=0; 56 for(i=0;i<cols;i++){ 57 for(j=0;j<(jc[i+1]-jc[i]);j++){ 58 *(matrix+rows*ir[count]+i)=pr[count]; 59 count++; 60 } 61 } 62 63 } 64 else{ 65 66 /*Dealing with dense matrix: recover pointer and size: */ 67 mxmatrix_ptr=(double*)mxGetPr(mxmatrix); 68 69 /*Create serial matrix: */ 70 matrix=xNewZeroInit<double>(numel); 71 72 dims=xNew<int>(ndims); 73 for(i=0;i<numel;i++){ 74 ColumnWiseDimsFromIndex(dims,i,size,ndims); 75 j = IndexFromRowWiseDims(dims,size,ndims); 76 matrix[j]=(double)mxmatrix_ptr[i]; 77 } 78 xDelete<int>(dims); 79 } 80 81 /*Assign output pointer: */ 82 *pmatrix = matrix; 83 *pmatrix_numel = numel; 84 *pmatrix_ndims = ndims; 85 *pmatrix_size = size; 86 87 return 1; 88 } 89 /*}}}*/ 90 /*FUNCTION MatlabNArrayToNArray(bool** pmatrix,int* pmatrix_numel,int* pmatrix_ndims,int** pmatrix_size,const mxArray* mxmatrix){{{*/ 91 int MatlabNArrayToNArray(bool** pmatrix,int* pmatrix_numel,int* pmatrix_ndims,int** pmatrix_size,const mxArray* mxmatrix){ 92 93 int i,j,rows,cols; 94 int numel,ndims; 95 int *size,*dims; 96 bool* mxmatrix_ptr=NULL; 97 const mwSize* ipt=NULL; 98 99 /*output: */ 100 bool* matrix=NULL; 101 102 /*matlab indices: */ 103 mwIndex *ir = NULL; 104 mwIndex *jc = NULL; 105 bool *pm = NULL; 106 int count; 107 108 /*get Matlab matrix information: */ 109 numel = mxGetNumberOfElements(mxmatrix); 110 ndims = mxGetNumberOfDimensions(mxmatrix); 111 ipt = mxGetDimensions(mxmatrix); 112 size = xNew<int>(ndims); 113 for (i=0;i<ndims;i++) size[i]=(int)ipt[i]; 114 115 /*Ok, first check if we are dealing with a sparse or full matrix: */ 116 if (mxIsSparse(mxmatrix)){ 117 118 /*Dealing with sparse matrix: recover size first: */ 119 rows=mxGetM(mxmatrix); 120 cols=mxGetN(mxmatrix); 121 matrix=xNewZeroInit<bool>(rows*cols); 122 123 /*Now, get ir,jc and pm: */ 124 ir=mxGetIr(mxmatrix); 125 jc=mxGetJc(mxmatrix); 126 pm=(bool*)mxGetData(mxmatrix); 127 128 /*Now, start inserting data into bool* matrix: */ 129 count=0; 130 for(i=0;i<cols;i++){ 131 for(j=0;j<(jc[i+1]-jc[i]);j++){ 132 matrix[rows*ir[count]+i]=pm[count]; 133 count++; 134 } 135 } 136 } 137 else{ 138 139 /*Dealing with dense matrix: recover pointer and size: */ 140 mxmatrix_ptr=(bool*)mxGetData(mxmatrix); 141 142 /*Create serial matrix: */ 143 matrix=xNew<bool>(numel); 144 dims=xNew<int>(ndims); 145 for(i=0;i<numel;i++){ 146 ColumnWiseDimsFromIndex(dims,i,size,ndims); 147 j=IndexFromRowWiseDims(dims,size,ndims); 148 matrix[j]=(bool)mxmatrix_ptr[i]; 149 } 150 xDelete<int>(dims); 151 } 152 153 /*Assign output pointer: */ 154 *pmatrix = matrix; 155 *pmatrix_numel = numel; 156 *pmatrix_ndims = ndims; 157 *pmatrix_size = size; 158 159 return 1; 160 } 161 /*}}}*/ 162 /*FUNCTION MatlabNArrayToNArray(char** pmatrix,int* pmatrix_numel,int* pmatrix_ndims,int** pmatrix_size,const mxArray* mxmatrix){{{*/ 163 int MatlabNArrayToNArray(char** pmatrix,int* pmatrix_numel,int* pmatrix_ndims,int** pmatrix_size,const mxArray* mxmatrix){ 164 165 int i,j,rows,cols; 166 int numel,ndims; 167 int *size , *dims; 168 mxChar *mxmatrix_ptr = NULL; 169 const mwSize *ipt = NULL; 170 171 /*output: */ 172 char* matrix=NULL; 173 174 /*matlab indices: */ 175 mwIndex *ir = NULL; 176 mwIndex *jc = NULL; 177 char *pm = NULL; 178 int count; 179 180 /*get Matlab matrix information: */ 181 numel = mxGetNumberOfElements(mxmatrix); 182 ndims = mxGetNumberOfDimensions(mxmatrix); 183 ipt = mxGetDimensions(mxmatrix); 184 size = xNew<int>(ndims); 185 for (i=0;i<ndims;i++) size[i]=(int)ipt[i]; 186 187 /*Ok, first check if we are dealing with a sparse or full matrix: */ 188 if (mxIsSparse(mxmatrix)){ 189 190 /*Dealing with sparse matrix: recover size first: */ 191 rows = mxGetM(mxmatrix); 192 cols = mxGetN(mxmatrix); 193 matrix=xNew<char>(rows*cols); 194 195 /*Now, get ir,jc and pm: */ 196 ir = mxGetIr(mxmatrix); 197 jc = mxGetJc(mxmatrix); 198 pm = (char*)mxGetData(mxmatrix); 199 200 /*Now, start inserting data into char* matrix: */ 201 count=0; 202 for(i=0;i<cols;i++){ 203 for(j=0;j<(jc[i+1]-jc[i]);j++){ 204 matrix[rows*ir[count]+i]=(char)pm[count]; 205 count++; 206 } 207 } 208 } 209 else{ 210 /*Dealing with dense matrix: recover pointer and size: */ 211 mxmatrix_ptr=mxGetChars(mxmatrix); 212 213 /*Create serial matrix: */ 214 matrix=xNew<char>(numel+1); 215 matrix[numel]='\0'; 216 217 /*looping code adapted from Matlab example explore.c: */ 218 int elements_per_page = size[0] * size[1]; 219 /* total_number_of_pages = size[2] x size[3] x ... x size[N-1] */ 220 int total_number_of_pages = 1; 221 for (i=2; i<ndims; i++) { 222 total_number_of_pages *= size[i]; 223 } 224 225 i=0; 226 for (int page=0; page < total_number_of_pages; page++) { 227 int row; 228 /* On each page, walk through each row. */ 229 for (row=0; row<size[0]; row++) { 230 int column; 231 j = (page * elements_per_page) + row; 232 233 /* Walk along each column in the current row. */ 234 for (column=0; column<size[1]; column++) { 235 *(matrix+i++)=(char)*(mxmatrix_ptr+j); 236 j += size[0]; 237 } 238 } 239 } 240 } 241 242 /*Assign output pointer: */ 243 *pmatrix = matrix; 244 *pmatrix_numel = numel; 245 *pmatrix_ndims = ndims; 246 *pmatrix_size = size; 247 248 return 1; 249 } 250 /*}}}*/ -
../trunk-jpl/src/wrappers/matlab/io/MatlabVectorToSeqVec.cpp
1 /*!\file MatlabVectorToSeqVec.cpp 2 */ 3 4 /*Headers:*/ 5 #include <mex.h> 6 #include <stdio.h> 7 #include <string.h> 8 #include "./matlabio.h" 9 #include "../../c/toolkits/toolkits.h" 10 #include "../../c/shared/shared.h" 11 12 SeqVec<double>* MatlabVectorToSeqVec(const mxArray* dataref){ 13 14 SeqVec<double>* output=NULL; 15 16 output=new SeqVec<double>(); 17 MatlabVectorToDoubleVector(&output->vector,&output->M,dataref); 18 return output; 19 20 } -
../trunk-jpl/src/wrappers/matlab/io/matlabio.h
1 /*\file matlabio.h 2 *\brief: I/O for ISSM in matlab mode 3 */ 4 5 #ifndef _MATLAB_IO_H_ 6 #define _MATLAB_IO_H_ 7 8 #ifdef HAVE_CONFIG_H 9 #include <config.h> 10 #else 11 #error "Cannot compile with HAVE_CONFIG_H symbol! run configure first!" 12 #endif 13 14 #include "../include/matlabincludes.h" 15 #include "../../c/classes/classes.h" 16 #include "../../c/Container/Container.h" 17 #include "../../c/include/include.h" 18 19 void WriteData(mxArray** pdataref,SeqMat<double>* matrix); 20 void WriteData(mxArray** pdataref,double* matrix, int M,int N); 21 void WriteData(mxArray** pdataref,int* matrix, int M,int N); 22 void WriteData(mxArray** pdataref,SeqVec<double>* vector); 23 void WriteData(mxArray** pdataref,double* vector, int M); 24 void WriteData(mxArray** pdataref,int integer); 25 void WriteData(mxArray** pdataref,bool boolean); 26 void WriteData(mxArray** pdataref,double scalar); 27 void WriteData(mxArray** pdataref,char* string); 28 void WriteData(mxArray** pdataref); 29 void WriteData(mxArray** pdataref,BamgGeom* bamggeom); 30 void WriteData(mxArray** pdataref,BamgMesh* bamgmesh); 31 void WriteData(mxArray** pdataref,RiftStruct* riftstruct); 32 33 void FetchData(double** pmatrix,int* pM,int *pN,const mxArray* dataref); 34 void FetchData(double** pmatrix,int* pnumel,int* pndims,int** psize,const mxArray* dataref); 35 void FetchData(int** pmatrix,int* pM,int *pN,const mxArray* dataref); 36 void FetchData(bool** pmatrix,int* pM,int *pN,const mxArray* dataref); 37 void FetchData(bool** pmatrix,int* pnumel,int* pndims,int** psize,const mxArray* dataref); 38 void FetchData(Matrix<double>** pmatrix,const mxArray* dataref); 39 void FetchData(int** pvector,int* pM,const mxArray* dataref); 40 void FetchData(float** pvector,int* pM,const mxArray* dataref); 41 void FetchData(double** pvector,int* pM,const mxArray* dataref); 42 void FetchData(bool** pvector,int* pM,const mxArray* dataref); 43 void FetchData(Vector<double>** pvector,const mxArray* dataref); 44 void FetchData(char** pstring,const mxArray* dataref); 45 void FetchData(char** pmatrix,int* pnumel,int* pndims,int** psize,const mxArray* dataref); 46 void FetchData(double* pscalar,const mxArray* dataref); 47 void FetchData(int* pinteger,const mxArray* dataref); 48 void FetchData(bool* pbool,const mxArray* dataref); 49 void FetchData(BamgGeom** bamggeom,const mxArray* dataref); 50 void FetchData(BamgMesh** bamgmesh,const mxArray* dataref); 51 void FetchData(BamgOpts** bamgopts,const mxArray* dataref); 52 void FetchData(Options** poptions,int istart, int nrhs,const mxArray** pdataref); 53 void FetchData(DataSet** pcontours,const mxArray* dataref); 54 55 Option* OptionParse(char* name, const mxArray* prhs[]); 56 GenericOption<double>* OptionDoubleParse( char* name, const mxArray* prhs[]); 57 GenericOption<double*>* OptionDoubleArrayParse( char* name, const mxArray* prhs[]); 58 GenericOption<bool*>* OptionLogicalParse( char* name, const mxArray* prhs[]); 59 GenericOption<char*>* OptionCharParse( char* name, const mxArray* prhs[]); 60 GenericOption<Options**>* OptionStructParse( char* name, const mxArray* prhs[]); 61 GenericOption<Options*>* OptionCellParse( char* name, const mxArray* prhs[]); 62 63 mxArray* mxGetAssignedField(const mxArray* pmxa_array,int number, const char* field); 64 void SetStructureField(mxArray* dataref,const char* fieldname,int fieldrows,int fieldcols,double* fieldpointer); 65 void SetStructureFieldi(mxArray* dataref,int i,const char* fieldname,int fieldrows,int fieldcols,double* fieldpointer); 66 void SetStructureFieldi(mxArray* dataref,int i,const char* fieldname,int field); 67 void SetStructureFieldi(mxArray* dataref,int i,const char* fieldname,double field); 68 int CheckNumMatlabArguments(int nlhs,int NLHS, int nrhs,int NRHS, const char* THISFUNCTION, void (*function)( void )); 69 70 /*Matlab to Matrix routines: */ 71 Matrix<double>* MatlabMatrixToMatrix(const mxArray* mxmatrix); 72 Vector<double>* MatlabVectorToVector(const mxArray* mxvector); 73 74 /*Matlab to double* routines: */ 75 int MatlabVectorToDoubleVector(double** pvector,int* pvector_rows,const mxArray* mxvector); 76 int MatlabMatrixToDoubleMatrix(double** pmatrix,int* pmatrix_rows,int* pmatrix_cols,const mxArray* mxmatrix); 77 int MatlabNArrayToNArray(double** pmatrix,int* pmatrix_numel,int* pmatrix_ndims,int** pmatrix_size,const mxArray* mxmatrix); 78 int MatlabNArrayToNArray(bool** pmatrix,int* pmatrix_numel,int* pmatrix_ndims,int** pmatrix_size,const mxArray* mxmatrix); 79 int MatlabNArrayToNArray(char** pmatrix,int* pmatrix_numel,int* pmatrix_ndims,int** pmatrix_size,const mxArray* mxmatrix); 80 81 /*Matlab to SeqMat routines: */ 82 SeqMat<double>* MatlabMatrixToSeqMat(const mxArray* dataref); 83 SeqVec<double>* MatlabVectorToSeqVec(const mxArray* dataref); 84 85 /*Matlab to Petsc routines: */ 86 #ifdef _HAVE_PETSC_ 87 int MatlabMatrixToPetscMat(Mat* matrix,int* prows,int* pcols, const mxArray* mxmatrix); 88 PetscMat* MatlabMatrixToPetscMat(const mxArray* mxmatrix); 89 int MatlabVectorToPetscVec(Vec* pvector,int* pvector_rows,const mxArray* mxvector); 90 PetscVec* MatlabVectorToPetscVec(const mxArray* mxvector); 91 #endif 92 93 #endif /* _IO_H_ */ -
../trunk-jpl/src/wrappers/matlab/Makefile.am
1 AM_CPPFLAGS = @DAKOTAINCL@ @MATLABINCL@ @PETSCINCL@ @MPIINCL@ @SPOOLESINCL@ @METISINCL@ @TRIANGLEINCL@ @CHACOINCL@ @SCOTCHINCL@ @SHAPELIBINCL@ @BOOSTINCL@ @PYTHONINCL@ @PYTHON_NUMPYINCL@ @ADOLCINCL@1 AM_CPPFLAGS = @DAKOTAINCL@ @MATLABINCL@ @PETSCINCL@ @MPIINCL@ @SPOOLESINCL@ @METISINCL@ @TRIANGLEINCL@ @CHACOINCL@ @SCOTCHINCL@ @SHAPELIBINCL@ 2 2 3 3 EXEEXT=$(MATLABWRAPPEREXT) 4 4 5 #matlab io{{{ 6 lib_LIBRARIES = libISSMMatlab.a 7 if SHAREDLIBS 8 lib_LTLIBRARIES = libISSMMatlab.la 9 else 10 lib_LTLIBRARIES = 11 endif 12 13 io_sources= ./include/matlabincludes.h\ 14 ./io/matlabio.h\ 15 ./io/MatlabNArrayToNArray.cpp\ 16 ./io/CheckNumMatlabArguments.cpp\ 17 ./io/mxGetAssignedField.cpp\ 18 ./io/WriteMatlabData.cpp\ 19 ./io/FetchMatlabData.cpp\ 20 ./io/OptionParse.cpp\ 21 ./io/MatlabMatrixToMatrix.cpp\ 22 ./io/MatlabVectorToVector.cpp\ 23 ./io/MatlabVectorToDoubleVector.cpp\ 24 ./io/MatlabMatrixToDoubleMatrix.cpp\ 25 ./io/MatlabMatrixToSeqMat.cpp\ 26 ./io/MatlabVectorToSeqVec.cpp 27 28 ALLCXXFLAGS= -fPIC -D_GNU_SOURCE -fno-omit-frame-pointer -pthread -D_CPP_ $(CXXFLAGS) $(CXXOPTFLAGS) 29 libISSMMatlab_a_SOURCES = $(io_sources) 30 libISSMMatlab_a_CXXFLAGS= $(ALLCXXFLAGS) 31 if SHAREDLIBS 32 libISSMMatlab_la_SOURCES = $(io_sources) 33 endif 34 #}}} 5 35 #Wrappers {{{ 6 36 if WRAPPERS 7 lib_LTLIBRARIES = AverageFilter.la\37 lib_LTLIBRARIES += AverageFilter.la\ 8 38 BamgMesher.la\ 9 39 BamgConvertMesh.la\ 10 40 BamgTriangulate.la\ … … 45 75 Kml2Exp.la 46 76 endif 47 77 endif 48 49 78 #}}} 50 79 #Flags and libraries {{{ 51 80 #if SHAREDLIBS … … 67 96 AM_LDFLAGS += -avoid-version 68 97 endif 69 98 if SHAREDLIBS 70 deps += . ./../c/libISSMMatlab.la99 deps += ./libISSMMatlab.la 71 100 else 72 deps += . ./../c/libISSMMatlab.a101 deps += ./libISSMMatlab.a 73 102 AM_LDFLAGS += --no-warnings 74 103 endif 75 104 -
../trunk-jpl/src/wrappers/BamgTriangulate/BamgTriangulate.h
20 20 #include "../../c/modules/modules.h" 21 21 #include "../../c/Container/Container.h" 22 22 #include "../../c/shared/shared.h" 23 #include "../ ../c/issm-binding.h"23 #include "../bindings.h" 24 24 25 25 #undef __FUNCT__ 26 26 #define __FUNCT__ "BamgTriangulate" -
../trunk-jpl/src/wrappers/InterpFromMeshToMesh2d/InterpFromMeshToMesh2d.h
23 23 #include "../../c/modules/modules.h" 24 24 #include "../../c/Container/Container.h" 25 25 #include "../../c/shared/shared.h" 26 #include "../ ../c/issm-binding.h"26 #include "../bindings.h" 27 27 #include "../../c/io/io.h" 28 28 #include "../../c/EnumDefinitions/EnumDefinitions.h" 29 29 -
../trunk-jpl/src/wrappers/ContourToMesh/ContourToMesh.h
23 23 #include "../../c/modules/modules.h" 24 24 #include "../../c/Container/Container.h" 25 25 #include "../../c/shared/shared.h" 26 #include "../ ../c/issm-binding.h"26 #include "../bindings.h" 27 27 #include "../../c/io/io.h" 28 28 #include "../../c/EnumDefinitions/EnumDefinitions.h" 29 29 -
../trunk-jpl/src/wrappers/Xy2ll/Xy2ll.h
20 20 #include "../../c/modules/modules.h" 21 21 #include "../../c/Container/Container.h" 22 22 #include "../../c/shared/shared.h" 23 #include "../ ../c/issm-binding.h"23 #include "../bindings.h" 24 24 25 25 #undef __FUNCT__ 26 26 #define __FUNCT__ "Xy2ll" -
../trunk-jpl/src/wrappers/KMLMeshWrite/KMLMeshWrite.h
20 20 #include "../../c/modules/modules.h" 21 21 #include "../../c/Container/Container.h" 22 22 #include "../../c/shared/shared.h" 23 #include "../ ../c/issm-binding.h"23 #include "../bindings.h" 24 24 25 25 #undef __FUNCT__ 26 26 #define __FUNCT__ "KMLMeshWrite" -
../trunk-jpl/src/wrappers/TriMesh/TriMesh.h
23 23 #include "../../c/modules/modules.h" 24 24 #include "../../c/Container/Container.h" 25 25 #include "../../c/shared/shared.h" 26 #include "../ ../c/issm-binding.h"26 #include "../bindings.h" 27 27 #include "../../c/io/io.h" 28 28 #include "../../c/EnumDefinitions/EnumDefinitions.h" 29 29 -
../trunk-jpl/src/wrappers/Chaco/Chaco.h
24 24 #include "../../c/modules/modules.h" 25 25 #include "../../c/Container/Container.h" 26 26 #include "../../c/shared/shared.h" 27 #include "../ ../c/issm-binding.h"27 #include "../bindings.h" 28 28 29 29 #undef __FUNCT__ 30 30 #define __FUNCT__ "Chaco"
Note:
See TracBrowser
for help on using the repository browser.