15 int strlength_in, idx;
17 strlength_in = strlen( cstring );
19 for( idx=strlength_in; idx<strlength; idx++ ) {
34 fieldnames = (
char**)mxMalloc(eq_struct->
numfields *
sizeof(
char**) );
37 mexPrintf(
"\nRetriving the fieldnames\n" );
41 for( idx=0; idx<eq_struct->
numfields; idx++ ) {
60 int idx_orig, idx_new;
65 mexWarnMsgTxt(
"siesta_EQuUs:EQuUs_MATLAB:regularizeEQstruct:EQuInvalid EQstructure: numfields was not set in EQstructure");
70 mexWarnMsgTxt(
"siesta_EQuUs:EQuUs_MATLAB:regularizeEQstruct:EQuInvalid EQstructure: fields was not set in EQstructure");
76 for ( idx_orig=0; idx_orig<eq_struct->
numfields; idx_orig++ ) {
77 eq_element = &eq_struct->
fields[idx_orig];
79 eq_struct->
fields[idx_new] = eq_struct->
fields[idx_orig];
85 if ( numfields == eq_struct->
numfields ) {
89 mexPrintf(
"%d fields were invalid in the scanned structure\n", eq_struct->
numfields - numfields );
93 for ( idx_orig=numfields; idx_orig<eq_struct->
numfields; idx_orig++ ) {
94 #ifdef __INTEL_COMPILER 95 equus_c_mp_deallocateelement_( &eq_struct->
fields[idx_orig] );
111 if (mxIsStruct( Mstruct ) == 0) {
112 mexErrMsgIdAndTxt (
"siesta_EQuUs:setField:NotStructure",
"The given mxArray is not a structure.");
119 dims = (mwSize*)malloc( (*eq_element->
dim)*
sizeof(mwSize));
121 for ( idx=1; idx<=*eq_element->
dim; idx++) {
122 dims[idx-1] = eq_element->
dims[idx-1];
123 numElements = numElements*eq_element->
dims[idx-1];
127 mexPrintf(
"elementname: %s\n", eq_element->
elementname );
128 mexPrintf(
"Number of elements: %d\n", numElements );
129 mexPrintf(
"Type of elements: %d\n", *eq_element->
classID );
130 mexPrintf(
"number of dimensions: %d\n", *eq_element->
dim );
131 if ( *eq_element->
dim == 2) {
132 mexPrintf(
"dimensions: %d x %d\n\n", dims[0], dims[1] );
134 mexPrintf(
"dimensions: %d x 1\n\n", dims[0] );
139 if ( *eq_element->
classID == mxLOGICAL_CLASS ) {
141 value = mxCreateLogicalArray( *eq_element->
dim, dims );
142 mxLogical *start_of_pr = mxGetLogicals(value);
143 int bytes_to_copy = numElements * mxGetElementSize(value);
144 memcpy(start_of_pr,eq_element->
value,bytes_to_copy);
146 else if (*eq_element->
classID == mxCHAR_CLASS ) {
148 value = mxCreateCharMatrixFromStrings(numElements, (
const char **)(eq_element->
value));
150 else if (*eq_element->
classID == mxSTRUCT_CLASS ) {
155 value = mxCreateStructMatrix(1, 1, eq_struct->
numfields, (
const char**)fieldnames);
156 for ( idx=0; idx<eq_struct->
numfields; idx++) {
160 else if ( *eq_element->
classID == mxDOUBLE_CLASS ||
161 *eq_element->
classID == mxSINGLE_CLASS ||
162 *eq_element->
classID == mxINT8_CLASS ||
163 *eq_element->
classID == mxUINT8_CLASS ||
164 *eq_element->
classID == mxINT16_CLASS ||
165 *eq_element->
classID == mxUINT16_CLASS ||
166 *eq_element->
classID == mxINT32_CLASS ||
167 *eq_element->
classID == mxUINT32_CLASS ||
168 *eq_element->
classID == mxINT64_CLASS ||
169 *eq_element->
classID == mxUINT64_CLASS ) {
171 value = mxCreateNumericArray( *eq_element->
dim, dims, *eq_element->
classID, mxREAL );
172 void *start_of_pr = mxGetData(value);
173 int bytes_to_copy = numElements * mxGetElementSize(value);
174 memcpy(start_of_pr,eq_element->
value,bytes_to_copy);
177 value = mxCreateDoubleMatrix( 0, 0, mxREAL );
180 if( ~mxIsEmpty( (
const mxArray *)value) ) {
184 #ifdef __INTEL_COMPILER 185 equus_c_mp_deallocateelement_( eq_element );
197 void setField( mxArray* field,
const char* fieldname, mxArray* Mstruct )
199 if (mxIsStruct( Mstruct ) == 0) {
200 mexErrMsgIdAndTxt (
"siesta_EQuUs:setField:NotStructure",
"The given mxArray is not a structure.");
205 field_idx = mxGetFieldNumber(Mstruct, fieldname);
208 if (field_idx == - 1) {
209 mxAddField(Mstruct, fieldname);
210 if( ~mxIsEmpty( (
const mxArray *)field) ) {
211 mxSetField(Mstruct, 0, fieldname, field);
218 field_tmp = mxGetFieldByNumber(Mstruct, 0, field_idx);
221 if( field_tmp == NULL ) {
222 mxSetFieldByNumber(Mstruct, 0, field_idx, field);
231 dims = (mwSize*)mxMalloc(ndim *
sizeof(mwSize) );
235 if (mxIsCell(field_tmp)) {
237 mexPrintf(
"Adding another element to the cell array\n");
239 const size_t * dims_tmp = (
const size_t *) mxGetDimensions( field_tmp );
240 dims[0] = dims_tmp[0]+1;
241 cellarray = mxCreateCellArray(ndim, dims);
244 for ( idx=0; idx<dims[0]-1; idx++) {
245 mxSetCell(cellarray, idx, mxGetCell(field_tmp, idx) );
248 mxSetCell(cellarray, dims[0]-1, field);
249 mxSetFieldByNumber(Mstruct, 0, field_idx, cellarray);
254 mexPrintf(
"Converting field to cell array\n");
258 cellarray = mxCreateCellArray(ndim, dims);
259 mxSetCell(cellarray, 0, field_tmp);
260 mxSetCell(cellarray, 1, field);
262 mxSetFieldByNumber(Mstruct, 0, field_idx, cellarray);
Header file for felper functions for interlanguage conversions.
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.