core/matlab/include/mex.h

00001 /*
00002  * @(#)mex.h    generated by: makeheader 5.1.3  Thu Jan 11 15:15:54 2007
00003  *
00004  *      built from: ../../src/include/copyright.h
00005  *              ../../src/include/pragma_interface.h
00006  *              mex_typedefs.h
00007  *              ./fmexapi.cpp
00008  *              ./fmexapi_stdcall.cpp
00009  *              ./fmexapiv5.cpp
00010  *              ./globals.cpp
00011  *              ./mexapi.cpp
00012  *              ./mexapiv4.cpp
00013  *              ./mexapiv5.cpp
00014  *              ./mexcbk.cpp
00015  *              ./mexdispatch.cpp
00016  *              ./mexintrf.cpp
00017  *              mexdbg.h
00018  */
00019 
00020 #if defined(_MSC_VER) || __GNUC__ > 3 || (__GNUC__ == 3 && __GNUC_MINOR__ > 3)
00021 #pragma once
00022 #endif
00023 
00024 #ifndef mex_h
00025 #define mex_h
00026 
00027 
00028 /*
00029  * Copyright 1984-2003 The MathWorks, Inc.
00030  * All Rights Reserved.
00031  */
00032 
00033 
00034 
00035 /* Copyright 2003-2004 The MathWorks, Inc. */
00036 
00037 /* Only define EXTERN_C if it hasn't been defined already. This allows
00038  * individual modules to have more control over managing their exports.
00039  */
00040 #ifndef EXTERN_C
00041 
00042 #ifdef __cplusplus
00043   #define EXTERN_C extern "C"
00044 #else
00045   #define EXTERN_C extern
00046 #endif
00047 
00048 #endif
00049 
00050 
00051 /* Copyright 1999-2001 The MathWorks, Inc. */
00052 
00053 /* $Revision: 1.1 $ */
00054 #ifndef mex_typedefs_h
00055 #define mex_typedefs_h
00056 typedef struct impl_info_tag *MEX_impl_info;
00057 
00058 #include "matrix.h"
00059 
00060 typedef struct mexGlobalTableEntry_Tag
00061 {
00062     const char *name;             /* The name of the global */
00063     mxArray    **variable;        /* A pointer to the variable */ 
00064 } mexGlobalTableEntry, *mexGlobalTable;
00065 
00066 #if defined(MSWIND)
00067 #define cicompare(s1,s2) utStrcmpi((s1),(s2))
00068 #else
00069 #define cicompare(s1,s2) strcmp((s1),(s2))
00070 #endif
00071 #define cscompare(s1,s2) strcmp((s1),(s2))
00072 
00073 typedef struct mexFunctionTableEntry_tag {
00074   const char *  name;
00075   mxFunctionPtr f;
00076   int           nargin;
00077   int           nargout;
00078   struct _mexLocalFunctionTable *local_function_table;
00079 } mexFunctionTableEntry, *mexFunctionTable;
00080 
00081 typedef struct _mexLocalFunctionTable {
00082   size_t           length;
00083   mexFunctionTable entries;
00084 } _mexLocalFunctionTable, *mexLocalFunctionTable;
00085 
00086 typedef struct {
00087   void (*initialize)(void);
00088   void (*terminate)(void);
00089 } _mexInitTermTableEntry, *mexInitTermTableEntry;
00090 
00091 #define MEX_INFORMATION_VERSION 1
00092 
00093 typedef struct {
00094   int                   version;
00095   int                   file_function_table_length;
00096   mexFunctionTable      file_function_table;
00097   int                   global_variable_table_length;
00098   mexGlobalTable        global_variable_table;
00099   int                   npaths;
00100   const char **         paths;
00101   int                   init_term_table_length;
00102   mexInitTermTableEntry init_term_table;
00103 } _mex_information, *mex_information;
00104 
00105 typedef mex_information(*fn_mex_file)(void);
00106 
00107 typedef void (*fn_clean_up_after_error)(void);
00108 typedef const char *(*fn_simple_function_to_string)(mxFunctionPtr f);
00109 
00110 typedef void (*fn_mex_enter_mex_library)(mex_information x);
00111 typedef fn_mex_enter_mex_library fn_mex_exit_mex_library;
00112 
00113 typedef mexLocalFunctionTable (*fn_mex_get_local_function_table)(void);
00114 typedef mexLocalFunctionTable (*fn_mex_set_local_function_table)(mexLocalFunctionTable);
00115 
00116 #endif
00117 
00118 
00119 /*
00120  * This header file "mex.h" declares all the types, macros and
00121  * functions necessary to interface mex files with the current
00122  * version of MATLAB.  See the release notes for information on 
00123  * supporting syntax from earlier versions.
00124  */  
00125 #include "matrix.h"
00126 
00127 #include <stdio.h>
00128 
00129 
00130 
00131 /*
00132  * mexFunction is the user-defined C routine that is called upon invocation
00133  * of a MEX-function.
00134  */
00135 EXTERN_C void mexFunction(
00136     int           nlhs,           /* number of expected outputs */
00137     mxArray       *plhs[],        /* array of pointers to output arguments */
00138     int           nrhs,           /* number of inputs */
00139     const mxArray *prhs[]         /* array of pointers to input arguments */
00140 );
00141 
00142 
00143 /*
00144  * Issue error message and return to MATLAB prompt
00145  */
00146 EXTERN_C void mexErrMsgTxt(
00147     const char  *error_msg  /* string with error message */
00148     );
00149 
00150 
00151 /*
00152  * Issue formatted error message with corresponding error identifier and return to MATLAB
00153  * prompt.
00154  */
00155 EXTERN_C void mexErrMsgIdAndTxt(
00156     const char * identifier, /* string with error message identifier */
00157     const char * err_msg,    /* string with error message printf-style format */
00158     ...                      /* any additional arguments */
00159     );
00160 
00161 
00162 /*
00163  * Invoke an unidentified warning. Such warnings can only be affected by the M-code
00164  * 'warning * all', since they have no specific identifier. See also mexWarnMsgIdAndTxt.
00165  */
00166 EXTERN_C void mexWarnMsgTxt(
00167     const char  *warn_msg   /* string with warning message */
00168     );
00169 
00170 
00171 /*
00172  * Invoke a warning with message identifier 'identifier' and message derived from 'fmt' and
00173  * subsequent arguments. The warning may either get printed as is (if it is set to 'on'), or
00174  * not actually get printed (if set to 'off'). See 'help warning' in MATLAB for more
00175  * details.
00176  */
00177 EXTERN_C void mexWarnMsgIdAndTxt(
00178     const char * identifier,    /* string with warning message identifer */
00179     const char * warn_msg,  /* string with warning message printf-style format */
00180     ...                         /* any additional arguments */
00181     );
00182 
00183 
00184 /*
00185  * mex equivalent to MATLAB's "disp" function
00186  */
00187 EXTERN_C int mexPrintf(
00188     const char  *fmt,   /* printf style format */
00189     ...             /* any additional arguments */
00190     );
00191 
00192 
00193 #define printf mexPrintf
00194 
00195 
00196 /*
00197  * Remove all components of an array plus the array header itself
00198  * from MATLAB's memory allocation list.  The array will now
00199  * persist between calls to the mex function.  To destroy this
00200  * array, you will need to explicitly call mxDestroyArray().
00201  */
00202 EXTERN_C void mexMakeArrayPersistent(
00203     mxArray *pa              /* pointer to array */
00204     );
00205 
00206 
00207 /*
00208  * Remove memory previously allocated via mxCalloc from MATLAB's
00209  * memory allocation list.  To free this memory, you will need to
00210  * explicitly call mxFree().
00211  */
00212 EXTERN_C void mexMakeMemoryPersistent(void *ptr);
00213 
00214 
00215 /*
00216  * mex equivalent to MATLAB's "set" function
00217  */
00218 EXTERN_C int mexSet(double handle, const char *property, mxArray *value);
00219 
00220 
00221 /* API interface which mimics the "get" function */
00222 EXTERN_C const mxArray *mexGet(double handle, const char *property);
00223 
00224 
00225 /*
00226  * call MATLAB function
00227  */
00228 EXTERN_C int mexCallMATLAB(
00229     int     nlhs,           /* number of expected outputs */
00230     mxArray *plhs[],        /* pointer array to outputs */
00231     int     nrhs,           /* number of inputs */
00232     mxArray *prhs[],        /* pointer array to inputs */
00233     const char  *fcn_name       /* name of function to execute */
00234     );
00235 
00236 
00237 /*
00238  * set or clear mexCallMATLAB trap flag (if set then an error in  
00239  * mexCallMATLAB is caught and mexCallMATLAB will return a status value, 
00240  * if not set an error will cause control to revert to MATLAB)
00241  */
00242 EXTERN_C void mexSetTrapFlag(int flag);
00243 
00244 
00245 /*
00246  * Print an assertion-style error message and return control to the
00247  * MATLAB command line.
00248  */ 
00249 EXTERN_C void mexPrintAssertion(
00250         const char *test, 
00251         const char *fname, 
00252         int linenum, 
00253         const char *message);
00254 
00255 
00256 /*
00257  * Tell whether or not a mxArray is in MATLAB's global workspace.
00258  */
00259 EXTERN_C bool mexIsGlobal(const mxArray *pA);
00260 
00261 
00262 #define mexGetGlobal()    mexGetGlobal_is_obsolete
00263 #define mxSetString()     mxSetString_is_obsolete
00264 #define mxSetDispMode()   mxSetDispMode_is_obsolete
00265 #define mexGetMatrixPtr() mexGetMatrixPtr_is_obsolete
00266 #define mexGetMatrix()    mexGetMatrix_is_obsolete
00267 #define mexPutMatrix()    mexPutMatrix_is_obsolete
00268 #define mexPutFull()      mexPutFull_is_obsolete
00269 #define mexGetFull()      mexGetFull_is_obsolete
00270 #define mexGetEps()       mexGetEps_is_obsolete
00271 #define mexGetInf()       mexGetInf_is_obsolete
00272 #define mexGetNaN()       mexGetNaN_is_obsolete
00273 #define mexIsFinite()     mexIsFinite_is_obsolete
00274 #define mexIsInf()        mexIsInf_is_obsolete
00275 #define mexIsNaN()        mexIsNaN_is_obsolete
00276 
00277 
00278 /*
00279  * mexAddFlops is no longer allowed.  
00280  */
00281 #define mexAddFlops(x) mexAddFlops_is_obsolete
00282 
00283 #if defined(V5_COMPAT)
00284 #define mexPutArray(parray, workspace) mexPutVariable(workspace, mxGetName(parray), parray)
00285 #define mexGetArray(name, workspace) mexGetVariable(workspace, name)
00286 #define mexGetArrayPtr(name, workspace) mexGetVariablePtr(workspace, name)
00287 #else
00288 #define mexPutArray() mexPutArray_is_obsolete
00289 #define mexGetArray() mexGetArray_is_obsolete
00290 #define mexGetArrayPtr() mexGetArrayPtr_is_obsolete
00291 #endif /* defined(V5_COMPAT) */
00292 
00293 
00294 /*
00295  * Place a copy of the array value into the specified workspace with the
00296  * specified name
00297  */
00298 EXTERN_C int mexPutVariable(
00299     const char *workspace,
00300     const char *name,
00301     const mxArray *parray       /* matrix to copy */
00302     );
00303 
00304 
00305 /*
00306  * return a pointer to the array value with the specified variable
00307  * name in the specified workspace
00308  */
00309 EXTERN_C const mxArray *mexGetVariablePtr(
00310     const char *workspace,
00311     const char *name        /* name of symbol */
00312     );
00313 
00314 
00315 /*
00316  * return a copy of the array value with the specified variable
00317  * name in the specified workspace
00318  */
00319 EXTERN_C mxArray *mexGetVariable(
00320     const char  *workspace,     
00321     const char  *name                /* name of variable in question */
00322     );
00323 
00324 
00325 /*
00326  * Lock a MEX-function so that it cannot be cleared from memory.
00327  */
00328 EXTERN_C void mexLock(void);
00329 
00330 
00331 /*
00332  * Unlock a locked MEX-function so that it can be cleared from memory.
00333  */
00334 EXTERN_C void mexUnlock(void);
00335 
00336 
00337 /*
00338  * Return true if the MEX-function is currently locked, false otherwise.
00339  */
00340 EXTERN_C bool mexIsLocked(void);
00341 
00342 
00343 /*
00344  * Return the name of a the MEXfunction currently executing.
00345  */
00346 EXTERN_C const char *mexFunctionName(void);
00347 
00348 
00349 /*
00350  * Parse and execute MATLAB syntax in string.  Returns zero if successful,
00351  * and a non zero value if an error occurs.
00352  */
00353 EXTERN_C int mexEvalString(
00354    const char *str     /* matlab command string */
00355 );
00356 
00357 
00358 /*
00359  * Register Mex-file's At-Exit function (accessed via MEX callback)
00360  */
00361 EXTERN_C int mexAtExit(
00362     void    (*exit_fcn)(void)
00363     );
00364 
00365 
00366 /* Copyright 1996-2006 The MathWorks, Inc. */
00367 
00368 /* $Revision: 1.1 $ */
00369 
00370 /*
00371  * Revisit.  Conflicts with 32-bit compatibility API.  XXX
00372  */
00373 #if 0
00374 
00375 #ifdef ARGCHECK
00376 
00377 #include "mwdebug.h" /* Prototype _d versions of API functions */
00378 
00379 #define mexAtExit(exitfcn)              mexAtExit_d(exitfcn, __FILE__, __LINE__)
00380 #define mexCallMATLAB(nlhs, plhs, nrhs, prhs, fcn) mexCallMATLAB_d(nlhs, plhs, nrhs, prhs, fcn, __FILE__, __LINE__)
00381 #define mexErrMsgTxt(errmsg)            mexErrMsgTxt_d(errmsg, __FILE__, __LINE__)
00382 #define mexEvalString(str)              mexEvalString_d(str, __FILE__, __LINE__)
00383 #define mexGet(handle, property)        mexGet_d(handle, property, __FILE__, __LINE__)
00384 #define mexGetVariable(workspace, name)     mexGetVariable_d(workspace, name, __FILE__, __LINE__)
00385 #define mexGetVariablePtr(workspace, name)      mexGetVariablePtr_d(workspace, name, __FILE__, __LINE__)
00386 #define mexIsGlobal(pa)                 mexIsGlobal_d(pa, __FILE__, __LINE__)
00387 #define mexMakeArrayPersistent(pa)      mexMakeArrayPersistent_d(pa, __FILE__, __LINE__)              
00388 #define mexMakeMemoryPersistent(ptr)    mexMakeMemoryPersistent_d(ptr, __FILE__, __LINE__)
00389 #define mexPutVariable(workspace, name, pa)     mexPutVariable_d(workspace, name, pa, __FILE__, __LINE__)
00390 #define mexSet(handle, property, value) mexSet_d(handle, property, value, __FILE__, __LINE__)
00391 #define mexSetTrapFlag(value)           mexSetTrapFlag_d(value, __FILE__, __LINE__)
00392 #define mexSubsAssign(plhs, sub, nsubs, rhs)    mexSubsAssign_d(plhs, sub, nsubs, rhs, __FILE__, __LINE__)
00393 #define mexSubsReference(prhs, sub, nsubs)    mexSubsReference_d(prhs, sub, nsubs, __FILE__, __LINE__)
00394 #define mexWarnMsgTxt(str)              mexWarnMsgTxt_d(str, __FILE__, __LINE__)
00395 #endif
00396 
00397 #endif
00398 
00399 #endif /* mex_h */

GridLAB-DTM Version 1.0
An open-source project initiated by the US Department of Energy