Ignore:
Timestamp:
04/12/11 15:37:07 (14 years ago)
Author:
jschierm
Message:

Added Option processing for Matlab n-dimensional doubles, logicals, and characters.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • issm/trunk/src/c/io/OptionParse.cpp

    r7761 r7860  
    4242
    4343        OptionDouble *odouble = NULL;
    44         const mwSize  *ipt     = NULL;
    4544
    4645        /*check and parse the name  */
     
    5453        }
    5554
    56         odouble->numel=mxGetNumberOfElements(prhs[0]);
    57         odouble->ndims=mxGetNumberOfDimensions(prhs[0]);
    58         ipt           =mxGetDimensions(prhs[0]);
    59         odouble->size =(int *) xmalloc(odouble->ndims*sizeof(int));
    60         for (int i=0; i<odouble->ndims; i++) odouble->size[i]=(int)ipt[i];
    61 
    62         //  note that FetchData does not correctly handle ndims >= 3
    63         if (odouble->ndims > 2) {
    64                 _printf_(true,"WARNING -- option \"%s\" of class \"%s\" has ndims=%d and will be skipped.\n",odouble->name,mxGetClassName(prhs[0]),odouble->ndims);
    65                 odouble->numel=0;
    66         }
    67         else FetchData(&odouble->values,NULL,NULL,prhs[0]);
     55        FetchData(&odouble->values,&odouble->numel,&odouble->ndims,&odouble->size,prhs[0]);
    6856
    6957        return(odouble);
     
    7361
    7462        OptionLogical *ological = NULL;
    75         const mwSize   *ipt      = NULL;
    76         bool            btemp;
    7763
    7864        /*check and parse the name  */
     
    8672        }
    8773
    88         ological->numel=mxGetNumberOfElements(prhs[0]);
    89         ological->ndims=mxGetNumberOfDimensions(prhs[0]);
    90         ipt            =mxGetDimensions(prhs[0]);
    91         ological->size =(int *) xmalloc(ological->ndims*sizeof(int));
    92         for (int i=0; i<ological->ndims; i++) ological->size[i]=(int)ipt[i];
    93 
    94         //  note that FetchData does not correctly handle non-scalar logicals
    95         if (ological->ndims > 2 || ological->size[0] > 1 || ological->size[1] > 1) {
    96                 _printf_(true,"WARNING -- option \"%s\" of class \"%s\" is more than [1x1] and will be skipped.\n",ological->name,mxGetClassName(prhs[0]));
    97                 ological->numel=0;
    98         }
    99         else {
    100                 //FetchData(&ological->values,prhs[0]);
    101                 //could be memory leak until FetchData handles logical arrays
    102                 ological->values=(bool *) xmalloc(sizeof(bool));
    103                 FetchData(ological->values,prhs[0]);
    104         }
     74        FetchData(&ological->values,&ological->numel,&ological->ndims,&ological->size,prhs[0]);
    10575
    10676        return(ological);
     
    11080
    11181        OptionChar  *ochar = NULL;
    112         const mwSize *ipt   = NULL;
    11382
    11483        /*check and parse the name  */
     
    12291        }
    12392
    124         ochar->numel=mxGetNumberOfElements(prhs[0]);
    125         ochar->ndims=mxGetNumberOfDimensions(prhs[0]);
    126         ipt         =mxGetDimensions(prhs[0]);
    127         ochar->size =(int *) xmalloc(ochar->ndims*sizeof(int));
    128         for(int i=0; i<ochar->ndims; i++) ochar->size[i]=(int)ipt[i];
    129 
    130         //note that FetchData does not correctly handle ndims >= 2 or multiple rows
    131         if (ochar->ndims > 2 || ochar->size[0] > 1) {
    132                 _printf_(true,"WARNING -- option \"%s\" of class \"%s\" is more than [1xn] and will be skipped.\n",ochar->name,mxGetClassName(prhs[0]));
    133                 ochar->numel=0;
    134         }
    135         else FetchData(&ochar->values,prhs[0]);
     93        FetchData(&ochar->values,&ochar->numel,&ochar->ndims,&ochar->size,prhs[0]);
    13694
    13795        return(ochar);
Note: See TracChangeset for help on using the changeset viewer.