/*
 * @(#)mex.h    generated by: makeheader    Mon Aug 22 12:51:20 1994
 *
 *		built from:	/rel/test42/bld/u2/extern/../matlab/platforms/sun4.ansi/src/cmex/cmex1.c
 *				/rel/test42/bld/u2/extern/../matlab/platforms/sun4.ansi/src/fmex/fmex.c
 */

#ifndef mex_h
#define mex_h

#ifdef __cplusplus
    extern "C" {
#endif


/*
 * Decide when to use function prototypes.
 */
#ifdef __STDC__
#define USE_FUNCTION_PROTOTYPES
#endif
#ifdef __cplusplus
#define USE_FUNCTION_PROTOTYPES
#endif


/*
 * These are needed because the symbols for these functions clash with the
 * FORTRAN ones with the same names.  The VMS linker makes all symbols
 * uppercase in the end.
 */
#ifdef VMS
#define mexFunction		CmexFunction
#define mexGetMatrixPtr		CmexGetMatrixPtr
#define mexCallMATLAB		CmexCallMATLAB
#define mexSetTrapFlag		CmexSetTrapFlag
#define mexErrMsgTxt		CmexErrMsgTxt
#define mexPrintf		CmexPrintf
#define mexAtExit		CmexAtExit
#define mexGetMatrix		CmexGetMatrix
#define mexPutMatrix		CmexPutMatrix
#define mexGetFull		CmexGetFull
#define mexPutFull		CmexPutFull
#define mexEvalString		CmexEvalString
#define mexEvaluateBlock 	CmexEvaluateBlock 
#endif /* VMS */


#include "matrix.h"


#ifdef applec
#include "mex_mac.h"
#endif

#ifdef THINK_C
#include "mex_mac.h"
#endif


/*
 * return pointer to named global matrix or NULL if it doesn't exist
 */
#ifdef USE_FUNCTION_PROTOTYPES
extern Matrix *mexGetGlobal(
    char	*name		/* name of variable in question */
    );
#else
extern Matrix *mexGetGlobal();
#endif /* USE_FUNCTION_PROTOTYPES */


/*
 * Get MATLAB's notion of EPS
 */
#ifdef USE_FUNCTION_PROTOTYPES
extern double mexGetEps(void);
#else
extern double mexGetEps();
#endif /* USE_FUNCTION_PROTOTYPES */


/*
 * Get MATLAB's notion of INF
 */
#ifdef USE_FUNCTION_PROTOTYPES
extern double mexGetInf(void);
#else
extern double mexGetInf();
#endif /* USE_FUNCTION_PROTOTYPES */


/*
 * Get MATLAB's notion of NAN
 */
#ifdef USE_FUNCTION_PROTOTYPES
extern double mexGetNaN(void);
#else
extern double mexGetNaN();
#endif /* USE_FUNCTION_PROTOTYPES */


/*
 * test for finiteness in a machine-independent manner
 */
#ifdef USE_FUNCTION_PROTOTYPES
extern int mexIsFinite(
    double x			/* value to test */
    );
#else
extern int mexIsFinite();
#endif /* USE_FUNCTION_PROTOTYPES */


/*
 * test for infinity in a machine-independent manner
 */
#ifdef USE_FUNCTION_PROTOTYPES
extern int mexIsInf(
    double x			/* value to test */
    );
#else
extern int mexIsInf();
#endif /* USE_FUNCTION_PROTOTYPES */


/*
 * test for NaN in a machine-independent manner
 */
#ifdef USE_FUNCTION_PROTOTYPES
extern int mexIsNaN(
    double x			/* value to test */
    );
#else
extern int mexIsNaN();
#endif /* USE_FUNCTION_PROTOTYPES */


/*
 * return pointer to named matrix 
 */
#ifdef USE_FUNCTION_PROTOTYPES
extern Matrix *mexGetMatrixPtr(
    char	*name		/* name of variable in question */
    );
#else
extern Matrix *mexGetMatrixPtr();
#endif /* USE_FUNCTION_PROTOTYPES */


/*
 * call MATLAB function
 */
#ifdef USE_FUNCTION_PROTOTYPES
extern int mexCallMATLAB(
    int		nlhs,		/* number of expected outputs */
    Matrix	*plhs[],	/* matrix pointer array returning outputs */
    int		nrhs,		/* number of inputs */
    Matrix	*prhs[],	/* matrix pointer array for inputs */
    char	*name		/* name of function */
    );
#else
extern int mexCallMATLAB();
#endif /* USE_FUNCTION_PROTOTYPES */


/*
 * set or clear mexCallMATLAB trap flag (if set then an error in  
 * mexCallMATLAB is caught and mexCallMATLAB will return a status value, 
 * if not set an error will cause control to revert to MATLAB)
 */
#ifdef USE_FUNCTION_PROTOTYPES
extern void mexSetTrapFlag(
    int		trap_flag	/* trap flag 0 - off, 1 - on) */
    );
#else
extern mexSetTrapFlag();
#endif /* USE_FUNCTION_PROTOTYPES */


/*
 * error return function
 */
#ifdef USE_FUNCTION_PROTOTYPES
extern void mexErrMsgTxt(
    const char	*error_msg	/* string with error message */
    );
#else
extern mexErrMsgTxt();
#endif /* USE_FUNCTION_PROTOTYPES */


/*
 * MATLAB pprintf (print to stdout and possibly to diary file)
 */
#ifdef USE_FUNCTION_PROTOTYPES
extern int mexPrintf(
    const char	*format,	/* printf style format */
    ...				/* any additional arguments */
    );
#else
extern int mexPrintf();
#endif /* USE_FUNCTION_PROTOTYPES */


/*
 * Register a function to be called by MATLAB in the event the Mex-file is to
 * be cleared or MATLAB is about to exit.  A non-zero value is returned if 
 * registeration fails.  Only one function may be registered per Mex-file.
 */
#ifdef USE_FUNCTION_PROTOTYPES
extern int mexAtExit(
    void	(*fcn)(void)
    );
#else
extern int mexAtExit();
#endif /* USE_FUNCTION_PROTOTYPES */


/*
 * Get a copy of the matrix from the local workspace 
 */
#ifdef USE_FUNCTION_PROTOTYPES
extern Matrix *mexGetMatrix(
    char	*name		/* name of variable in question */
    );
#else
extern Matrix *mexGetMatrix();
#endif /* USE_FUNCTION_PROTOTYPES */


/*
 * Put a copy of the matrix in the local workspace 
 */
#ifdef USE_FUNCTION_PROTOTYPES
extern int mexPutMatrix(
    Matrix	*pm		/* pointer to matrix */
    );
#else
extern int mexPutMatrix();
#endif /* USE_FUNCTION_PROTOTYPES */


/*
 * Easy get copy of the matrix from the local workspace
 */
#ifdef USE_FUNCTION_PROTOTYPES
extern int mexGetFull(
    char	*name,		/* name of variable in question */
    int		*m,		/* number of rows */
    int		*n,		/* number of columns */
    Real	**pr,		/* real part */
    Real	**pi		/* imaginary part */
    );
#else
extern int mexGetFull();
#endif /* USE_FUNCTION_PROTOTYPES */


/*
 * Easy put copy of the matrix in the local workspace
 */
#ifdef USE_FUNCTION_PROTOTYPES
extern int mexPutFull(
    char	*name,		/* name of variable in question */
    int		m,		/* number of rows */
    int		n,		/* number of columns */
    Real	*pr,		/* real part */
    Real	*pi		/* imaginary part */
    );
#else
extern int mexPutFull();
#endif /* USE_FUNCTION_PROTOTYPES */


/*
 * Execute a matlab command string in the local workspace
 */
#ifdef USE_FUNCTION_PROTOTYPES
extern int mexEvalString(
   char		*str		/* matlab command string */
    );
#else
extern int mexEvalString();
#endif /* USE_FUNCTION_PROTOTYPES */


/*
 * Evaluate a simulink block
 */
#ifdef USE_FUNCTION_PROTOTYPES
extern int mexEvaluateBlock( const char *graph_name, int block_no, int flag);
#else
extern int mexEvaluateBlock();
#endif /* USE_FUNCTION_PROTOTYPES */


/*
 * Set stdin I/O to cannonical mode.  This is a no-op on non unix machines.
 */
#ifdef USE_FUNCTION_PROTOTYPES
extern void mexSetCanonicalMode( void );
#else
extern mexSetCanonicalMode();
#endif /* USE_FUNCTION_PROTOTYPES */


/*
 * definitions which may be helpful
 */
#define printf          	mexPrintf

#define create_real_array(N)    (double *) mxCalloc((N),sizeof(double))
#define create_int_array(N)     (int *) mxCalloc((N),sizeof(int))
#define user_fcn                mexFunction
#define free_matrix             mxFreeMatrix
#define mex_calloc              mxCalloc
#define mex_free                mxFree
#define get_global              mexGetGlobal
#define matlab_fcn              mexCallMATLAB
#define matlab_trap             mexSetTrapFlag
#define mex_error               mexErrMsgTxt
#define mex_printf              mexPrintf
#define create_matrix   	mxCreateFull


#ifndef OLDSTYLE


/*
 * prototype of user-defined function
 */
#ifdef USE_FUNCTION_PROTOTYPES
extern void mexFunction(
    int		nlhs,		/* number of expected outputs */
    Matrix	*plhs[],	/* matrix pointer array returning outputs */
    int		nrhs,		/* number of inputs */
    Matrix	*prhs[]		/* matrix pointer array for inputs */
    );
#else
extern mexFunction();
#endif /* USE_FUNCTION_PROTOTYPES */


#endif /* OLDSTYLE */

#ifdef __cplusplus
    }	/* extern "C" */
#endif

#endif /* mex_h */
