Eötvös Quantum Utilities  v5.0.144
Providing the Horsepowers in the Quantum Realm
read_hsx.cpp
Go to the documentation of this file.
1 
19 #include "mex.h"
20 #include <unistd.h>
21 #include <string.h>
22 #include "EQuUs_MATLAB.h"
23 
24 #ifdef __cplusplus
25 extern "C" {
26 #endif
27 
28 #ifdef __INTEL_COMPILER
29 void hsx_equus_mp_read_hsx_( char* fname, long *fname_len, EQstruct* eq_struct);
30 #else
31 void __hsx_equus_MOD_read_hsx( char* fname, long *fname_len, EQstruct* eq_struct);
32 #endif
33 
34 
35 #ifdef __cplusplus
36  }
37 #endif
38 
39 
40 
41 
48 void mexFunction(int nlhs, mxArray *plhs[],
49  int nrhs, const mxArray *prhs[])
50 {
51  /* input filename */
52  char *filename;
53  /* length of the filename */
54  long buflen;
55  /* field names of the output structure */
56  char **fieldnames;
57 
58 
59 
60 /*-----------------------------------------------------------------------*/
61 /* Check for proper number of arguments. */
62  if(nrhs != 1) {
63  mexErrMsgIdAndTxt ("siesta_EQuUs:hsx_m:nInput", "One input required.");
64  }
65  else if (nlhs > 1) {
66  mexErrMsgIdAndTxt ("siesta_EQuUs:hsx_m:nOutput", "Too many output arguments.");
67  }
68 
69 /* Validate inputs */
70 
71 /* Check that the input is a double.*/
72  if ((mxIsChar(prhs[0]) != 1)) {
73  mexErrMsgIdAndTxt ("siesta_EQuUs:hsx_m:NonString", "Input must be a string.");
74  }
75 
76  /* get the length of the input string */
77  buflen = (mxGetM(prhs[0]) * mxGetN(prhs[0])) + 1;
78 
79 
80  /* copy the string data from prhs[0] into a C string. */
81  filename = mxArrayToString(prhs[0]);
82 #ifdef DEBUG
83  mexPrintf( "%s\n", filename );
84 #endif
85 
86  if (access(filename, F_OK) == -1) {
87  mexErrMsgIdAndTxt ("siesta_EQuUs:hsx_m:FileNotExist", "The given file %s does not exist.", filename);
88  }
89 
90  EQelement eq_field, *eq_fields;
91  EQstruct eq_hsx;
92 
93 
94  /* Retriving the HSX structure */
95 #ifdef __INTEL_COMPILER
96  hsx_equus_mp_read_hsx_( filename, &buflen, &eq_hsx);
97 #else
98  __hsx_equus_MOD_read_hsx( filename, &buflen, &eq_hsx);
99 #endif
100 
101  /* obtaining the fieldnames */
102  fieldnames = getFieldnames( &eq_hsx );
103 
104  /* creating the MATLAB version of the output structure */
105  plhs[0] = mxCreateStructMatrix(1, 1, eq_hsx.numfields, (const char**)fieldnames);
106 
107 #ifdef DEBUG
108  mexPrintf( "\nSetting the fields\n*********************************\n" );
109 #endif
110  int idx;
111  for( idx=0; idx<eq_hsx.numfields; idx++ ) {
112 #ifdef DEBUG
113  mexPrintf( "setting field: %s:\n", fieldnames[idx] );
114 #endif
115  setField( &eq_hsx.fields[idx], plhs[0] );
116  }
117 
118 }
119 
120 
121 
int numfields
Definition: EQuUs_MATLAB.h:17
void mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[])
Gateway routine to read in the hsx structure generated by the SIESTA package (see http://www....
Definition: read_hsx.cpp:48
char ** getFieldnames(EQstruct *eq_struct)
Get all the element names stored in the eq_struct structure prototype.
void setField(EQelement *eq_field, mxArray *Mstruct)
Set a field in a MATLAB structure.
void __hsx_equus_MOD_read_hsx(char *fname, long *fname_len, EQstruct *eq_struct)
====================================================================== Gateway routine to read in the...
EQelement * fields
Definition: EQuUs_MATLAB.h:16