8 #error "Cannot compile with HAVE_CONFIG_H symbol! run configure first!"
15 void FetchData(
double** pmatrix,
int* pM,
int *pN,
const mxArray* dataref){
17 double* outmatrix=NULL;
18 int outmatrix_rows,outmatrix_cols;
20 if(mxIsEmpty(dataref) ){
26 else if( mxIsClass(dataref,
"double") ||
27 mxIsClass(dataref,
"single") ||
28 mxIsClass(dataref,
"int16") ||
29 mxIsClass(dataref,
"int8") ||
30 mxIsClass(dataref,
"uint8")){
32 if ( mxIsNaN(*(mxGetPr(dataref))) && (mxGetM(dataref)==1) && (mxGetN(dataref)==1) ){
38 if(!mxIsClass(dataref,
"double") && !mxIsClass(dataref,
"single")){
39 _printf_(
"Warning: converting matlab data from '" << mxGetClassName(dataref) <<
"' to 'double'\n");
47 _error_(
"Input parameter of class " << mxGetClassName(dataref) <<
" not supported yet");
52 if (pM)*pM=outmatrix_rows;
53 if (pN)*pN=outmatrix_cols;
57 void FetchData(
int** pmatrix,
int* pM,
int *pN,
const mxArray* dataref){
59 int i,outmatrix_rows,outmatrix_cols;
60 double *doublematrix=NULL;
63 if(mxIsEmpty(dataref) ){
69 else if( mxIsClass(dataref,
"double") ||
70 mxIsClass(dataref,
"single") ||
71 mxIsClass(dataref,
"int16") ||
72 mxIsClass(dataref,
"int8") ||
73 mxIsClass(dataref,
"uint8")){
76 if ( mxIsNaN(*(mxGetPr(dataref))) && (mxGetM(dataref)==1) && (mxGetN(dataref)==1) ){
82 if(!mxIsClass(dataref,
"double") && !mxIsClass(dataref,
"single")){
83 _printf_(
"Warning: converting matlab data from '" << mxGetClassName(dataref) <<
"' to 'double'\n");
89 outmatrix=xNew<int>(outmatrix_rows*outmatrix_cols);
90 for(i=0;i<outmatrix_rows*outmatrix_cols;i++)outmatrix[i]=(
int)doublematrix[i];
95 _error_(
"Input parameter of class " << mxGetClassName(dataref) <<
" not supported yet");
100 if (pM)*pM=outmatrix_rows;
101 if (pN)*pN=outmatrix_cols;
104 void FetchData(
bool** pmatrix,
int* pM,
int *pN,
const mxArray* dataref){
106 int i,outmatrix_rows,outmatrix_cols;
107 double *doublematrix=NULL;
108 bool *outmatrix=NULL;
110 if(mxIsEmpty(dataref) ){
116 else if (mxIsClass(dataref,
"double") ){
119 if ( mxIsNaN(*(mxGetPr(dataref))) && (mxGetM(dataref)==1) && (mxGetN(dataref)==1) ){
130 outmatrix=xNew<bool>(outmatrix_rows*outmatrix_cols);
131 for(i=0;i<outmatrix_rows;i++)outmatrix[i]=(
bool)doublematrix[i];
136 _error_(
"Input parameter of class " << mxGetClassName(dataref) <<
" not supported yet");
141 if (pM)*pM=outmatrix_rows;
142 if (pN)*pN=outmatrix_cols;
145 void FetchData(
double** pvector,
int* pM,
const mxArray* dataref){
147 double* outvector=NULL;
154 if(M*N>0 && (M!=1 && N!=1)){
155 _error_(
"input vector of size " << M <<
"x" << N <<
" should have only one column");
166 void FetchData(
int** pvector,
int* pM,
const mxArray* dataref){
169 double *doublevector = NULL;
170 int *outvector = NULL;
173 if(mxIsEmpty(dataref)){
178 else if (mxIsClass(dataref,
"double") ){
181 FetchData(&doublevector,&outvector_rows,dataref);
184 outvector=xNew<int>(outvector_rows);
185 for(i=0;i<outvector_rows;i++)outvector[i]=(
int)doublevector[i];
189 _error_(
"Input parameter of class " << mxGetClassName(dataref) <<
" not supported yet");
194 if (pM)*pM=outvector_rows;
197 void FetchData(
bool** pvector,
int* pM,
const mxArray* dataref){
200 double *doublevector = NULL;
201 bool *outvector = NULL;
204 if(mxIsEmpty(dataref)){
209 else if (mxIsClass(dataref,
"double") ){
212 FetchData(&doublevector,&outvector_rows,dataref);
215 outvector=xNew<bool>(outvector_rows);
216 for(i=0;i<outvector_rows;i++)outvector[i]=(
bool)doublevector[i];
220 _error_(
"Input parameter of class " << mxGetClassName(dataref) <<
" not supported yet");
225 if (pM)*pM=outvector_rows;
228 void FetchData(
float** pvector,
int* pM,
const mxArray* dataref){
231 double *doublevector = NULL;
232 float *outvector = NULL;
235 if(mxIsEmpty(dataref)){
240 else if (mxIsClass(dataref,
"double") ){
243 FetchData(&doublevector,&outvector_rows,dataref);
246 outvector=xNew<float>(outvector_rows);
247 for(i=0;i<outvector_rows;i++)outvector[i]=(
float)doublevector[i];
251 _error_(
"Input parameter of class " << mxGetClassName(dataref) <<
" not supported yet");
256 if (pM)*pM=outvector_rows;
261 char* outstring=NULL;
264 if (!mxIsClass(dataref,
"char")){
265 _error_(
"input data_type is not a string!");
271 stringlen = mxGetM(dataref)*mxGetN(dataref)+1;
272 outstring =xNew<char>(stringlen);
273 mxGetString(dataref,outstring,stringlen);
283 if (!mxIsClass(dataref,
"double")){
284 _error_(
"input data_type is not a double!");
288 scalar=mxGetScalar(dataref);
299 if (!mxIsClass(dataref,
"double")){
300 _error_(
"input data_type is not a scalar!");
304 integer=(int)mxGetScalar(dataref);
313 bool* mxbool_ptr=NULL;
315 if (mxIsClass(dataref,
"logical")){
316 if(mxGetM(dataref)!=1)
_error_(
"input data is not of size 1x1");
317 if(mxGetN(dataref)!=1)
_error_(
"input data is not of size 1x1");
318 mxbool_ptr=mxGetLogicals(dataref);
321 _error_(
"input data_type is not a bool!");
324 *pboolean=*mxbool_ptr;
416 for (
int i=istart; i<nrhs; i=i+2){
417 if (!mxIsClass(pdataref[i],
"char"))
_error_(
"Argument " << i+1 <<
" must be name of option");
420 if(i+1 == nrhs)
_error_(
"Argument " << i+2 <<
" must exist and be value of option \"" << name <<
"\".");
433 int numcontours,index,test1,test2;
434 char *contourname = NULL;
438 if(mxIsClass(dataref,
"char")){
440 contours=ExpRead<double>(contourname);
442 else if(mxIsClass(dataref,
"struct")){
445 numcontours=mxGetNumberOfElements(dataref);
447 for(
int i=0;i<numcontours;i++){
451 index = mxGetFieldNumber(dataref,
"nods");
452 if(index==-1)
_error_(
"input structure does not have a 'nods' field");
453 FetchData(&contouri->
nods,mxGetFieldByNumber(dataref,i,index));
455 index = mxGetFieldNumber(dataref,
"x");
456 if(index==-1)
_error_(
"input structure does not have a 'x' field");
457 FetchData(&contouri->
x,&test1,&test2,mxGetFieldByNumber(dataref,i,index));
458 if(test1!=contouri->
nods || test2!=1)
_error_(
"field x should be of size ["<<contouri->
nods<<
" 1]");
460 index = mxGetFieldNumber(dataref,
"y");
461 if(index==-1)
_error_(
"input structure does not have a 'y' field");
462 FetchData(&contouri->
y,&test1,&test2,mxGetFieldByNumber(dataref,i,index));
463 if(test1!=contouri->
nods || test2!=1)
_error_(
"field y should be of size ["<<contouri->
nods<<
" 1]");
469 _error_(
"Contour is neither a string nor a structure and cannot be loaded ("<<mxGetClassName(dataref)<<
" not supported)");
473 xDelete<char>(contourname);
477 void FetchChacoData(
int* pnvtxs,
int** padjacency,
int** pstart,
float** pewgts,
const mxArray* A_IN,
const mxArray* EWGTS_IN){
480 int nvtxs = mxGetN(A_IN);
481 mwIndex* mwstart = mxGetJc(A_IN);
482 mwIndex* mwadjacency = mxGetIr(A_IN);
483 int nzmax = mxGetNzmax(A_IN);
485 int* start = xNew<int>(nvtxs+1);
486 for(
int i=0;i<nvtxs+1;i++) start[i]=(
int)mwstart[i];
488 int* adjacency = xNew<int>(nzmax);
489 for(
int i=0; i<nzmax; i++) adjacency[i]= (
int)mwadjacency[i];
492 int nedges = start[nvtxs];
494 if(!mxIsEmpty(EWGTS_IN)){
495 ewgts = xNewZeroInit<float>(nedges);
496 double* doublepointer = mxGetPr(A_IN);
497 for(
int i = 0; i<nedges;i++) ewgts[i] = (
float)doublepointer[i];
502 *padjacency = adjacency;
512 int rows=mxGetM(mxmatrix);
513 int cols=mxGetN(mxmatrix);
518 *pmatrix_rows = rows;
519 *pmatrix_cols = cols;
524 double* matrix=xNewZeroInit<double>(rows*cols);
527 if(mxIsSparse(mxmatrix)){
530 double* pmxmatrix=(
double*)mxGetPr(mxmatrix);
533 mwIndex* ir=mxGetIr(mxmatrix);
534 mwIndex* jc=mxGetJc(mxmatrix);
538 for(
int i=0;i<cols;i++){
539 for(
int j=0;j<(jc[i+1]-jc[i]);j++){
540 matrix[rows*ir[count]+i]=pmxmatrix[count];
545 else if(mxIsClass(mxmatrix,
"double")){
546 double* pmxmatrix=(
double*)mxGetPr(mxmatrix);
547 for(
int i=0;i<rows;i++)
for(
int j=0;j<cols;j++) matrix[cols*i+j]=(
double)pmxmatrix[rows*j+i];
549 else if(mxIsClass(mxmatrix,
"single")){
550 float *pmxmatrix=(
float*)mxGetPr(mxmatrix);
551 for(
int i=0;i<rows;i++)
for(
int j=0;j<cols;j++) matrix[cols*i+j]=(
double)pmxmatrix[rows*j+i];
553 else if(mxIsClass(mxmatrix,
"int16")){
554 short int *pmxmatrix=(
short*)mxGetPr(mxmatrix);
555 for(
int i=0;i<rows;i++)
for(
int j=0;j<cols;j++) matrix[cols*i+j]=(
double)pmxmatrix[rows*j+i];
557 else if(mxIsClass(mxmatrix,
"uint8")){
558 char *pmxmatrix=(
char*)mxGetPr(mxmatrix);
559 for(
int i=0;i<rows;i++)
for(
int j=0;j<cols;j++) matrix[cols*i+j]=(
double)pmxmatrix[rows*j+i];
562 _error_(
"Matlab matrix type "<<mxGetClassName(mxmatrix)<<
" Not implemented yet");
575 mxArray *mxfield = NULL;
577 if(mxIsStruct(pmxa_array)){
578 mxfield = mxGetField(pmxa_array,number,field);
586 mwSize onebyone[2] = {1,1};
589 const char *fnames[2];
590 fnames[0] =
"type"; fnames[1] =
"subs";
591 mxArray* pindex=mxCreateStructArray( ndim,onebyone,2,fnames);
592 mxSetField( pindex, 0,
"type",mxCreateString(
"."));
593 mxSetField( pindex, 0,
"subs",mxCreateString(field));
594 inputs[0]=(mxArray*)pmxa_array;
597 mexCallMATLAB( 1, &mxfield, 2, (mxArray**)inputs,
"subsref");
600 if(mxfield == NULL)
_error_(
"Could not find field "<< field <<
" in structure");
612 if (mxIsClass(prhs[0],
"double") && (mxGetNumberOfElements(prhs[0])==1)){
615 else if(mxIsClass(prhs[0],
"double") && (mxGetNumberOfElements(prhs[0])>1)){
618 else if(mxIsClass(prhs[0],
"char")){
622 _error_(
"Second argument value of option \""<< name <<
"\" is of unrecognized class \""<< mxGetClassName(prhs[0]) <<
"\".");
633 option->
name =xNew<char>(strlen(name)+1);
634 memcpy(option->
name,name,(strlen(name)+1)*
sizeof(
char));
649 option->
name =xNew<char>(strlen(name)+1);
650 memcpy(option->
name,name,(strlen(name)+1)*
sizeof(
char));
653 if (!mxIsClass(prhs[0],
"double")){
654 _error_(
"Value of option \"" << option->
name <<
"\" must be class \"double\", not class \"" << mxGetClassName(prhs[0]) <<
"\".");
668 option->
name =xNew<char>(strlen(name)+1);
669 memcpy(option->
name,name,(strlen(name)+1)*
sizeof(
char));
672 if(!mxIsClass(prhs[0],
"char")){
673 _error_(
"Value of option \"" << option->
name <<
"\" must be class \"char\", not class \"" << mxGetClassName(prhs[0]) <<
"\".");
678 option->
size[0] = strlen(name);