Changeset 21881
- Timestamp:
- 07/27/17 09:39:50 (8 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
issm/trunk-jpl/src/wrappers/matlab/io/FetchMatlabData.cpp
r21864 r21881 996 996 mxArray* mxGetAssignedField(const mxArray* pmxa_array,int number,const char* field){ 997 997 998 //output 999 mxArray* mxfield=NULL; 1000 1001 //input 1002 mxArray *inputs[2]; 1003 mxArray *pindex = NULL; 1004 const char *fnames[2]; 1005 mwSize ndim = 2; 1006 mwSize onebyone[2] = {1,1}; 1007 1008 //We want to call the subsasgn method, and get the returned array.This ensures that if we are running 1009 //large sized problems, the data is truly loaded from disk by the model subsasgn class method. 1010 inputs[0]=(mxArray*)pmxa_array; //this is the model 1011 1012 //create index structure used in the assignment (index.type='.' and index.subs='x' for field x for ex) 1013 fnames[0] = "type"; 1014 fnames[1] = "subs"; 1015 pindex=mxCreateStructArray( ndim,onebyone,2,fnames); 1016 mxSetField( pindex, 0, "type",mxCreateString(".")); 1017 mxSetField( pindex, 0, "subs",mxCreateString(field)); 1018 inputs[1]=pindex; 1019 1020 mexCallMATLAB( 1, &mxfield, 2, (mxArray**)inputs, "subsref"); 998 /*Output*/ 999 mxArray *mxfield = NULL; 1000 1001 if(mxIsStruct(pmxa_array)){ 1002 mxfield = mxGetField(pmxa_array,number,field); 1003 } 1004 else{ 1005 /*This is an object, mxGetField returns NULL in old version of matlab (we do not have access to them)*/ 1006 1007 /*Intermediaries*/ 1008 mxArray *inputs[2]; 1009 mwSize ndim = 2; 1010 mwSize onebyone[2] = {1,1}; 1011 1012 /*create index structure used in the assignment (index.type='.' and index.subs='x' for field x*/ 1013 const char *fnames[2]; 1014 fnames[0] = "type"; fnames[1] = "subs"; 1015 mxArray* pindex=mxCreateStructArray( ndim,onebyone,2,fnames); 1016 mxSetField( pindex, 0, "type",mxCreateString(".")); 1017 mxSetField( pindex, 0, "subs",mxCreateString(field)); 1018 inputs[0]=(mxArray*)pmxa_array; //this is the model 1019 inputs[1]=pindex; 1020 1021 mexCallMATLAB( 1, &mxfield, 2, (mxArray**)inputs, "subsref"); 1022 } 1023 1024 if(mxfield == NULL) _error_("Could not find field "<< field <<" in structure"); 1021 1025 1022 1026 return mxfield;
Note:
See TracChangeset
for help on using the changeset viewer.