12 int strlength_in, idx;
14 strlength_in = strlen( cstring );
16 for( idx=strlength_in; idx<strlength; idx++ ) {
31 fieldnames = (
char**)mxMalloc(eq_struct->
numfields *
sizeof(
char**) );
34 mexPrintf(
"\nRetriving the fieldnames\n" );
38 for( idx=0; idx<eq_struct->
numfields; idx++ ) {
57 int idx_orig, idx_new;
62 mexWarnMsgTxt(
"siesta_EQuUs:EQuUs_MATLAB:regularizeEQstruct:EQuInvalid EQstructure: numfields was not set in EQstructure");
67 mexWarnMsgTxt(
"siesta_EQuUs:EQuUs_MATLAB:regularizeEQstruct:EQuInvalid EQstructure: fields was not set in EQstructure");
73 for ( idx_orig=0; idx_orig<eq_struct->
numfields; idx_orig++ ) {
74 eq_element = &eq_struct->
fields[idx_orig];
76 eq_struct->
fields[idx_new] = eq_struct->
fields[idx_orig];
82 if ( numfields == eq_struct->
numfields ) {
86 mexPrintf(
"%d fields were invalid in the scanned structure\n", eq_struct->
numfields - numfields );
90 for ( idx_orig=numfields; idx_orig<eq_struct->
numfields; idx_orig++ ) {
91 #ifdef __INTEL_COMPILER 92 equus_c_mp_deallocateelement_( &eq_struct->
fields[idx_orig] );
108 if (mxIsStruct( Mstruct ) == 0) {
109 mexErrMsgIdAndTxt (
"siesta_EQuUs:setField:NotStructure",
"The given mxArray is not a structure.");
116 dims = (mwSize*)malloc( (*eq_element->
dim)*
sizeof(mwSize));
118 for ( idx=1; idx<=*eq_element->
dim; idx++) {
119 dims[idx-1] = eq_element->
dims[idx-1];
120 numElements = numElements*eq_element->
dims[idx-1];
124 mexPrintf(
"elementname: %s\n", eq_element->
elementname );
125 mexPrintf(
"Number of elements: %d\n", numElements );
126 mexPrintf(
"Type of elements: %d\n", *eq_element->
classID );
127 mexPrintf(
"number of dimensions: %d\n", *eq_element->
dim );
128 if ( *eq_element->
dim == 2) {
129 mexPrintf(
"dimensions: %d x %d\n\n", dims[0], dims[1] );
131 mexPrintf(
"dimensions: %d x 1\n\n", dims[0] );
136 if ( *eq_element->
classID == mxLOGICAL_CLASS ) {
138 value = mxCreateLogicalArray( *eq_element->
dim, dims );
139 mxLogical *start_of_pr = mxGetLogicals(value);
140 int bytes_to_copy = numElements * mxGetElementSize(value);
141 memcpy(start_of_pr,eq_element->
value,bytes_to_copy);
143 else if (*eq_element->
classID == mxCHAR_CLASS ) {
145 value = mxCreateCharMatrixFromStrings(numElements, (
const char **)(eq_element->
value));
147 else if (*eq_element->
classID == mxSTRUCT_CLASS ) {
152 value = mxCreateStructMatrix(1, 1, eq_struct->
numfields, (
const char**)fieldnames);
153 for ( idx=0; idx<eq_struct->
numfields; idx++) {
157 else if ( *eq_element->
classID == mxDOUBLE_CLASS ||
158 *eq_element->
classID == mxSINGLE_CLASS ||
159 *eq_element->
classID == mxINT8_CLASS ||
160 *eq_element->
classID == mxUINT8_CLASS ||
161 *eq_element->
classID == mxINT16_CLASS ||
162 *eq_element->
classID == mxUINT16_CLASS ||
163 *eq_element->
classID == mxINT32_CLASS ||
164 *eq_element->
classID == mxUINT32_CLASS ||
165 *eq_element->
classID == mxINT64_CLASS ||
166 *eq_element->
classID == mxUINT64_CLASS ) {
168 value = mxCreateNumericArray( *eq_element->
dim, dims, *eq_element->
classID, mxREAL );
169 void *start_of_pr = mxGetData(value);
170 int bytes_to_copy = numElements * mxGetElementSize(value);
171 memcpy(start_of_pr,eq_element->
value,bytes_to_copy);
174 value = mxCreateDoubleMatrix( 0, 0, mxREAL );
177 if( ~mxIsEmpty( (
const mxArray *)value) ) {
181 #ifdef __INTEL_COMPILER 182 equus_c_mp_deallocateelement_( eq_element );
194 void setField( mxArray* field,
const char* fieldname, mxArray* Mstruct )
196 if (mxIsStruct( Mstruct ) == 0) {
197 mexErrMsgIdAndTxt (
"siesta_EQuUs:setField:NotStructure",
"The given mxArray is not a structure.");
202 field_idx = mxGetFieldNumber(Mstruct, fieldname);
205 if (field_idx == - 1) {
206 mxAddField(Mstruct, fieldname);
207 if( ~mxIsEmpty( (
const mxArray *)field) ) {
208 mxSetField(Mstruct, 0, fieldname, field);
215 field_tmp = mxGetFieldByNumber(Mstruct, 0, field_idx);
218 if( field_tmp == NULL ) {
219 mxSetFieldByNumber(Mstruct, 0, field_idx, field);
228 dims = (mwSize*)mxMalloc(ndim *
sizeof(mwSize) );
232 if (mxIsCell(field_tmp)) {
234 mexPrintf(
"Adding another element to the cell array\n");
236 const size_t * dims_tmp = (
const size_t *) mxGetDimensions( field_tmp );
237 dims[0] = dims_tmp[0]+1;
238 cellarray = mxCreateCellArray(ndim, dims);
241 for ( idx=0; idx<dims[0]-1; idx++) {
242 mxSetCell(cellarray, idx, mxGetCell(field_tmp, idx) );
245 mxSetCell(cellarray, dims[0]-1, field);
246 mxSetFieldByNumber(Mstruct, 0, field_idx, cellarray);
251 mexPrintf(
"Converting field to cell array\n");
255 cellarray = mxCreateCellArray(ndim, dims);
256 mxSetCell(cellarray, 0, field_tmp);
257 mxSetCell(cellarray, 1, field);
259 mxSetFieldByNumber(Mstruct, 0, field_idx, cellarray);
char ** getFieldnames(EQstruct *eq_struct)
Get all the element names stored in the eq_struct structure prototype.
void regularizeEQstruct(EQstruct *eq_struct)
Sort out invalid EQelements from an EQstruct structure prototype.
void __equus_c_MOD_deallocateelement(EQelement *eq_element)
void convert2FortranString(char *cstring, int strlength)
Converts a C string into fortran compatible character array.
void setField(EQelement *eq_element, mxArray *Mstruct)
Set a field in a MATLAB structure.