Eötvös Quantum Utilities  v4.9.146
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 
51 void mexFunction(int nlhs, mxArray *plhs[],
52  int nrhs, const mxArray *prhs[])
53 {
54  /* input filename */
55  char *filename;
56  /* length of the filename */
57  long buflen;
58  /* field names of the output structure */
59  char **fieldnames;
60 
61 
62 
63 /*-----------------------------------------------------------------------*/
64 /* Check for proper number of arguments. */
65  if(nrhs != 1) {
66  mexErrMsgIdAndTxt ("siesta_EQuUs:hsx_m:nInput", "One input required.");
67  }
68  else if (nlhs > 1) {
69  mexErrMsgIdAndTxt ("siesta_EQuUs:hsx_m:nOutput", "Too many output arguments.");
70  }
71 
72 /* Validate inputs */
73 
74 /* Check that the input is a double.*/
75  if ((mxIsChar(prhs[0]) != 1)) {
76  mexErrMsgIdAndTxt ("siesta_EQuUs:hsx_m:NonString", "Input must be a string.");
77  }
78 
79  /* get the length of the input string */
80  buflen = (mxGetM(prhs[0]) * mxGetN(prhs[0])) + 1;
81 
82 
83  /* copy the string data from prhs[0] into a C string. */
84  filename = mxArrayToString(prhs[0]);
85 #ifdef DEBUG
86  mexPrintf( "%s\n", filename );
87 #endif
88 
89  if (access(filename, F_OK) == -1) {
90  mexErrMsgIdAndTxt ("siesta_EQuUs:hsx_m:FileNotExist", "The given file %s does not exist.", filename);
91  }
92 
93  EQelement eq_field, *eq_fields;
94  EQstruct eq_hsx;
95 
96 
97  /* Retriving the HSX structure */
98 #ifdef __INTEL_COMPILER
99  hsx_equus_mp_read_hsx_( filename, &buflen, &eq_hsx);
100 #else
101  __hsx_equus_MOD_read_hsx( filename, &buflen, &eq_hsx);
102 #endif
103 
104  /* obtaining the fieldnames */
105  fieldnames = getFieldnames( &eq_hsx );
106 
107  /* creating the MATLAB version of the output structure */
108  plhs[0] = mxCreateStructMatrix(1, 1, eq_hsx.numfields, (const char**)fieldnames);
109 
110 #ifdef DEBUG
111  mexPrintf( "\nSetting the fields\n*********************************\n" );
112 #endif
113  int idx;
114  for( idx=0; idx<eq_hsx.numfields; idx++ ) {
115 #ifdef DEBUG
116  mexPrintf( "setting field: %s:\n", fieldnames[idx] );
117 #endif
118  setField( &eq_hsx.fields[idx], plhs[0] );
119  }
120 
121 }
122 
123 
124 
Header file for felper functions for interlanguage conversions.
int numfields
Definition: EQuUs_MATLAB.h:19
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:51
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:18