source:
issm/oecreview/Archive/11961-11984/ISSM-11971-11972.diff@
11991
Last change on this file since 11991 was 11991, checked in by , 13 years ago | |
---|---|
File size: 13.7 KB |
-
proj/ice/larour/issm-uci-clean/trunk-jpl/src/c/io/Matlab/CheckNumMatlabArguments.cpp
1 /*!\file CheckNumMatlabArguments.cpp: 2 * \brief: check number of arguments and report an usage error message. 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 12 #if defined(_HAVE_MATLAB_) && defined(_SERIAL_) 13 14 #include "../../shared/Exceptions/exceptions.h" 15 #include "../../include/include.h" 16 #include "mex.h" 17 18 int CheckNumMatlabArguments(int nlhs,int NLHS, int nrhs,int NRHS, const char* __FUNCT__, void (*function)( void )){ 19 20 /*checks on arguments on the matlab side: */ 21 if (nrhs==0 && nlhs==0) { 22 /*unless NLHS=0 and NRHS=0, we are just asking for documentation: */ 23 if (NRHS==0 && NLHS==0)return 1; 24 /* special case: */ 25 function(); 26 _error_("usage: see above"); 27 } 28 else if (nlhs!=NLHS || nrhs!=NRHS ) { 29 function(); 30 _error_("usage error."); 31 } 32 return 1; 33 } 34 35 #endif -
proj/ice/larour/issm-uci-clean/trunk-jpl/src/c/io/Matlab/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 #ifdef HAVE_CONFIG_H 11 #include <config.h> 12 #else 13 #error "Cannot compile without HAVE_CONFIG_H symbol! run configure first!" 14 #endif 15 16 #if defined(_HAVE_MATLAB_) && defined(_SERIAL_) 17 #include "mex.h" 18 19 mxArray* mxGetAssignedField(const mxArray* pmxa_array,int number,const char* field){ 20 21 //output 22 mxArray* mxfield=NULL; 23 24 //input 25 mxArray *inputs[2]; 26 mxArray *pindex = NULL; 27 const char *fnames[2]; 28 mwSize ndim = 2; 29 mwSize onebyone[2] = {1,1}; 30 31 //We want to call the subsasgn method, and get the returned array.This ensures that if we are running 32 //large sized problems, the data is truly loaded from disk by the model subsasgn class method. 33 inputs[0]=(mxArray*)pmxa_array; //this is the model 34 35 //create index structure used in the assignment (index.type='.' and index.subs='x' for field x for ex) 36 fnames[0] = "type"; 37 fnames[1] = "subs"; 38 pindex=mxCreateStructArray( ndim,onebyone,2,fnames); 39 mxSetField( pindex, 0, "type",mxCreateString(".")); 40 mxSetField( pindex, 0, "subs",mxCreateString(field)); 41 inputs[1]=pindex; 42 43 mexCallMATLAB( 1, &mxfield, 2, (mxArray**)inputs, "subsref"); 44 45 return mxfield; 46 } 47 #endif -
proj/ice/larour/issm-uci-clean/trunk-jpl/src/c/io/Matlab/PrintfFunction.cpp
1 /*\file PrintfFunction.c 2 *\brief: this function is used by the _printf_ macro, to take into account the 3 *fact we may be running on a cluster. 4 */ 5 6 #include <stdarg.h> 7 #include <stdio.h> 8 #include "../../shared/shared.h" 9 #include "../../include/include.h" 10 11 #if defined(_HAVE_MATLAB_) && defined(_SERIAL_) 12 #include "mex.h" 13 #endif 14 15 int PrintfFunction(char* format,...){ 16 /*http://linux.die.net/man/3/vsnprintf*/ 17 18 /*string to be printed: */ 19 char *buffer = NULL; 20 int n,size = 100; 21 int string_size; 22 extern int my_rank; 23 extern int num_procs; 24 25 //variable list of arguments 26 va_list args; 27 28 while(true){ 29 30 /*allocate buffer for given string size*/ 31 buffer=(char*)xmalloc(size*sizeof(char)); 32 33 /* Try to print in the allocated space. */ 34 va_start(args, format); 35 #ifndef WIN32 36 n=vsnprintf(buffer,size,format,args); 37 #else 38 n=vsnprintf(buffer,size,format,args); 39 #endif 40 va_end(args); 41 42 /* If that worked, return the string. */ 43 if(n>-1 && n<size) break; 44 45 /* Else try again with more space. */ 46 if(n>-1) /* glibc 2.1 */ 47 size=n+1; /* precisely what is needed */ 48 else /* glibc 2.0 */ 49 size*=2; /* twice the old size */ 50 51 xfree((void**)&buffer); 52 } 53 54 /*Ok, if we are running in parallel, get node 0 to print*/ 55 #if defined(_PARALLEL_) 56 if(my_rank==0)printf(buffer); 57 #else 58 mexPrintf(buffer); 59 #endif 60 61 /*Clean up and return*/ 62 xfree((void**)&buffer); 63 return 1; 64 } -
proj/ice/larour/issm-uci-clean/trunk-jpl/src/c/io/Matlab/matlabio.h
57 57 OptionChar* OptionCharParse( char* name, const mxArray* prhs[]); 58 58 OptionStruct* OptionStructParse( char* name, const mxArray* prhs[]); 59 59 OptionCell* OptionCellParse( char* name, const mxArray* prhs[]); 60 61 mxArray* mxGetAssignedField(const mxArray* pmxa_array,int number, const char* field); 62 int CheckNumMatlabArguments(int nlhs,int NLHS, int nrhs,int NRHS, const char* THISFUNCTION, void (*function)( void )); 63 60 64 #endif 61 65 #endif /* _IO_H_ */ -
proj/ice/larour/issm-uci-clean/trunk-jpl/src/c/io/Python/pythonio.h
22 22 #if defined(_HAVE_PYTHON_) && defined(_SERIAL_) 23 23 24 24 //void WriteData(mxArray** pdataref,DataSet* dataset); 25 //void WriteData(mxArray** pdataref,Matrix* matrix);26 25 //void WriteData(mxArray** pdataref,double* matrix, int M,int N); 27 26 //void WriteData(mxArray** pdataref,int* matrix, int M,int N); 28 //void WriteData(mxArray** pdataref,Vector* vector);29 27 //void WriteData(mxArray** pdataref,double* vector, int M); 30 28 //void WriteData(mxArray** pdataref,int integer); 31 29 //void WriteData(mxArray** pdataref,bool boolean); 32 30 //void WriteData(mxArray** pdataref,double scalar); 33 //void WriteData(mxArray** pdataref,char* string);34 31 //void WriteData(DataHandle* pdataref,Parameters* parameters); 32 void WriteData(PyObject* py_tuple, int index, char* string); 33 void WriteData(PyObject* py_tuple, int index, Matrix* matrix); 34 void WriteData(PyObject* py_tuple, int index, Vector* vector); 35 35 36 36 37 //void FetchData(DataSet** pdataset,const mxArray* dataref); 37 38 //void FetchData(double** pmatrix,int* pM,int *pN,const mxArray* dataref); 38 39 //void FetchData(double** pmatrix,int* pnumel,int* pndims,int** psize,const mxArray* dataref); … … 47 48 //void FetchData(Vector** pvector,const mxArray* dataref); 48 49 //void FetchData(char** pmatrix,int* pnumel,int* pndims,int** psize,const mxArray* dataref); 49 50 //void FetchData(Parameters** pparameters, DataHandle dataref); 50 void FetchData(char** pstring,char* string); 51 void FetchData(double* pscalar,double scalar); 52 void FetchData(int* pinteger,int integer); 53 void FetchData(bool* pbool,bool boolean); 51 void FetchData(char** pstring,PyObject* py_unicode); 52 void FetchData(double* pscalar,PyObject* py_float); 53 void FetchData(int* pinteger,PyObject* py_long); 54 void FetchData(bool* pbool,PyObject* py_boolean); 55 56 int CheckNumPythonArguments(PyObject* inputs,int NRHS, void (*function)( void )); 57 54 58 #endif 55 59 56 60 #endif /* _IO_H_ */ -
proj/ice/larour/issm-uci-clean/trunk-jpl/src/c/io/Python/CheckNumPythonArguments.cpp
1 /*!\file CheckNumPythonArguments.cpp: 2 * \brief: check number of arguments and report an usage error message. 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 12 #if defined(_HAVE_PYTHON_) && defined(_SERIAL_) 13 14 #define PY_ARRAY_UNIQUE_SYMBOL PythonIOSymbol 15 #define NO_IMPORT 16 17 #include "../../toolkits/toolkits.h" 18 #include "../../shared/Exceptions/exceptions.h" 19 #include "../../include/include.h" 20 21 int CheckNumPythonArguments(PyObject* inputs,int NRHS, void (*function)( void )){ 22 23 Py_ssize_t size=0; 24 25 /*figure out size of tuple in input: */ 26 size=PyTuple_Size(inputs); 27 28 /*check on requested size: */ 29 if (size==0){ 30 function(); 31 _error_("usage: see above"); 32 } 33 else if (size!=NRHS ) { 34 function(); 35 _error_("usage error."); 36 } 37 return 1; 38 } 39 40 #endif -
proj/ice/larour/issm-uci-clean/trunk-jpl/src/c/io/Python/FetchPythonData.cpp
8 8 #error "Cannot compile with HAVE_CONFIG_H symbol! run configure first!" 9 9 #endif 10 10 11 #define PY_ARRAY_UNIQUE_SYMBOL PythonIOSymbol 12 #define NO_IMPORT 13 14 #include "../../toolkits/toolkits.h" 15 #include "../../include/include.h" 11 16 #include "../../shared/shared.h" 12 #include "../../include/include.h"13 17 14 18 #if defined(_HAVE_PYTHON_) && defined(_SERIAL_) 15 /*FUNCTION FetchData(char** pstring, char* string){{{1*/16 void FetchData(char** pstring, char* string){19 /*FUNCTION FetchData(char** pstring,PyObject* py_unicode){{{1*/ 20 void FetchData(char** pstring,PyObject* py_unicode){ 17 21 18 /*Copy string into string: */19 char* outstring=NULL;22 PyObject* py_bytes; 23 char* string=NULL; 20 24 21 outstring=(char*)xmalloc((strlen(string)+1)*sizeof(char)); 22 strcpy(outstring,string); 25 26 /*convert to bytes format: */ 27 PyUnicode_FSConverter(py_unicode,&py_bytes); 23 28 24 *pstring=outstring; 29 /*convert from bytes to string: */ 30 string=PyBytes_AS_STRING(py_bytes); 31 32 *pstring=string; 25 33 } 26 /*FUNCTION FetchData(double* pscalar, double scale){{{1*/27 void FetchData(double* pscalar, double scalar){34 /*FUNCTION FetchData(double* pscalar,PyObject* py_float){{{1*/ 35 void FetchData(double* pscalar,PyObject* py_float){ 28 36 29 /*simple copy: */ 37 double scalar; 38 39 /*return internal value: */ 40 scalar=PyFloat_AsDouble(py_float); 41 42 /*output: */ 30 43 *pscalar=scalar; 31 44 } 32 45 /*}}}*/ 33 /*FUNCTION FetchData(int* pinteger, int integer){{{1*/34 void FetchData(int* pinteger, int integer){46 /*FUNCTION FetchData(int* pinteger,PyObject* py_long){{{1*/ 47 void FetchData(int* pinteger, PyObject* py_long){ 35 48 36 /*simple copy: */ 49 int integer; 50 51 /*return internal value: */ 52 integer=(int)PyLong_AsLong(py_long); 53 54 /*output: */ 37 55 *pinteger=integer; 38 56 } 39 57 /*}}}*/ 40 /*FUNCTION FetchData(bool* pboolean, boolboolean){{{1*/41 void FetchData(bool* pboolean, boolboolean){58 /*FUNCTION FetchData(bool* pboolean,PyObject* py_boolean){{{1*/ 59 void FetchData(bool* pboolean,PyObject* py_boolean){ 42 60 61 bool boolean; 62 63 /*check this is indeed a subtype of long type: */ 64 if(!PyBool_Check(py_boolean))_error_("expecting a boolean in input!"); 65 66 /*extract boolean: */ 67 boolean=(bool)PyLong_AsLong(py_boolean); 68 43 69 /*simple copy: */ 44 70 *pboolean=boolean; 45 71 -
proj/ice/larour/issm-uci-clean/trunk-jpl/src/c/io/Python/WritePythonData.cpp
8 8 #error "Cannot compile with HAVE_CONFIG_H symbol! run configure first!" 9 9 #endif 10 10 11 #if defined(_HAVE_PYTHON_) && defined(_SERIAL_) 12 13 #define PY_ARRAY_UNIQUE_SYMBOL PythonIOSymbol 14 #define NO_IMPORT 15 16 #include "../../toolkits/toolkits.h" 11 17 #include "../../include/include.h" 18 #include "../../modules/modules.h" 19 #include "../../Container/Container.h" 12 20 #include "../../shared/shared.h" 21 #include "../../io/io.h" 22 #include "../../EnumDefinitions/EnumDefinitions.h" 13 23 14 #if defined(_HAVE_MATLAB_) && defined(_SERIAL_)15 #include <mex.h>16 24 25 /*FUNCTION WriteData(PyObject* py_tuple,int index,char* string){{{1*/ 26 void WriteData(PyObject* py_tuple, int index, char* string){ 27 28 PyTuple_SetItem(py_tuple, index, PyUnicode_FromString(string)); 29 30 } 31 /*}}}*/ 32 /*FUNCTION WriteData(PyObject* tuple,int index,Matrix* matrix){{{1*/ 33 void WriteData(PyObject* tuple,int index,Matrix* matrix){ 34 35 int M,N; 36 double* buffer=NULL; 37 npy_intp dims[2]={0,0}; 38 PyObject* array=NULL; 39 40 buffer=matrix->ToSerial(); 41 matrix->GetSize(&M,&N); 42 dims[0]=(npy_intp)M; 43 dims[1]=(npy_intp)N; 44 array=PyArray_SimpleNewFromData(2,dims,NPY_DOUBLE,buffer); 45 46 PyTuple_SetItem(tuple, index, array); 47 48 49 } 50 /*FUNCTION WriteData(PyObject* py_tuple,int index,Vector* vector){{{1*/ 51 void WriteData(PyObject* tuple,int index,Vector* vector){ 52 53 int M; 54 double* buffer=NULL; 55 npy_intp dim=10; 56 PyObject* array=NULL; 57 58 buffer=vector->ToMPISerial(); 59 vector->GetSize(&M); 60 dim=(npy_intp)M; 61 array=PyArray_SimpleNewFromData(1,&dim,NPY_DOUBLE,buffer); 62 63 PyTuple_SetItem(tuple, index, array); 64 65 66 } 67 /*}}}*/ 68 17 69 #endif
Note:
See TracBrowser
for help on using the repository browser.