core/matlab/include/mat.h

00001 /*
00002  * @(#)mat.h    generated by: makeheader 5.1.3  Thu Jan 11 15:00:52 2007
00003  *
00004  *      built from: ../../src/include/copyright.h
00005  *              ../../src/include/pragma_interface.h
00006  *              ./fmatapi.cpp
00007  *              ./fmatapi_stdcall.cpp
00008  *              ./fmatapiv5.cpp
00009  *              ./matapi.cpp
00010  *              ./matapiv5.cpp
00011  *              ./matlvl4.cpp
00012  *              ./matlvl5.cpp
00013  *              ./matlvl7.cpp
00014  *              matdbg.h
00015  */
00016 
00017 #if defined(_MSC_VER) || __GNUC__ > 3 || (__GNUC__ == 3 && __GNUC_MINOR__ > 3)
00018 #pragma once
00019 #endif
00020 
00021 #ifndef mat_h
00022 #define mat_h
00023 
00024 
00025 /*
00026  * Copyright 1984-2003 The MathWorks, Inc.
00027  * All Rights Reserved.
00028  */
00029 
00030 
00031 
00032 /* Copyright 2003-2004 The MathWorks, Inc. */
00033 
00034 /* Only define EXTERN_C if it hasn't been defined already. This allows
00035  * individual modules to have more control over managing their exports.
00036  */
00037 #ifndef EXTERN_C
00038 
00039 #ifdef __cplusplus
00040   #define EXTERN_C extern "C"
00041 #else
00042   #define EXTERN_C extern
00043 #endif
00044 
00045 #endif
00046 
00047 
00048 #include <stdio.h>
00049 
00050 
00051 #include "matrix.h"
00052 
00053 
00054 typedef struct MATFile_tag MATFile;
00055 
00056 
00057 /* #ifdef MAT_ALLOW_OBSOLETE_API_CALLS */
00058 
00059 
00060 /*
00061  * Allocate and initialize a MATFile structure for a file "filename".
00062  * file "filename" must already have been fopened with a mode corresponding
00063  * to "mode" ("r" == "rb", "w" == "w+b", "u" == "r+b"), and the result
00064  * of that fopen must be passed in as "fp".
00065  *
00066  * WARNING:
00067  * THIS FILE IS FOR INTERNAL MATHWORKS USE ONLY.  IT IS AN UNDOCUMENTED
00068  * FUNCTION, AND MAY AT ANY TIME BE REMOVED FROM THE MAT API.
00069  */
00070 EXTERN_C MATFile * matCreateMATFile(const char * filename, FILE *fp, const char * mode);
00071 
00072 
00073 /* 
00074  * Open a MAT-file "filename" using mode "mode".  Return
00075  * a pointer to a MATFile for use with other MAT API functions.
00076  *
00077  * Current valid entries for "mode" are
00078  * "r"    == read only.
00079  * "w"    == write only (deletes any existing file with name <filename>).
00080  * "w4"   == as "w", but create a MATLAB 4.0 MAT-file.
00081  * "w7.3" == as "w", but create a MATLAB 7.3 MAT-file.
00082  * "u"    == update.  Read and write allowed, existing file is not deleted.
00083  * 
00084  * Return NULL if an error occurs.
00085  */
00086 EXTERN_C MATFile * matOpen(const char *filename, const char * mode);
00087 
00088 
00089 /*
00090  * Close a MAT-file opened with matOpen.
00091  *
00092  * Return zero for success, EOF on error.
00093  */
00094 EXTERN_C int matClose(MATFile *pMF);
00095 
00096 
00097 /*
00098  * Return the ANSI C FILE pointer obtained when the MAT-file was opened.
00099  * Warning: the FILE pointer may be NULL in the case of a MAT file format
00100  * that does not allow access to the raw file pointer.
00101  */
00102 EXTERN_C FILE * matGetFp(MATFile *pMF);
00103 
00104 
00105 /*
00106  * Write array value with the specified name to the MAT-file, deleting any 
00107  * previously existing variable with that name in the MAT-file.
00108  *
00109  * Return zero for success, nonzero for error.
00110  */
00111 EXTERN_C int matPutVariable(
00112            MATFile * pMF, 
00113            const char * name,
00114            const mxArray * pA
00115            );
00116 
00117 
00118 /*
00119  * Write array value with the specified name to the MAT-file pMF, deleting any 
00120  * previously existing variable in the MAT-file with the same name.
00121  *
00122  * The variable will be written such that when the MATLAB LOAD command 
00123  * loads the variable, it will automatically place it in the 
00124  * global workspace and establish a link to it in the local
00125  * workspace (as if the command "global <varname>" had been
00126  * issued after the variable was loaded.)
00127  *
00128  * Return zero for success, nonzero for error.
00129  */
00130 EXTERN_C int matPutVariableAsGlobal(
00131                MATFile * pMF, 
00132                const char * name,
00133                const mxArray * pA
00134                );
00135 
00136 
00137 /*
00138  * Read the array value for the specified variable name from a MAT-file.
00139  *
00140  * Return NULL if an error occurs.
00141  */
00142 EXTERN_C mxArray * matGetVariable(
00143              MATFile * pMF, 
00144              const char * name
00145              );
00146 
00147 
00148 /* 
00149  * Read the next array value from the current file location of the MAT-file
00150  * pMF.  This function should only be used in conjunction with 
00151  * matOpen and matClose.  Passing pMF to any other API functions
00152  * will cause matGetNextVariable() to work incorrectly.
00153  *
00154  * Return NULL if an error occurs.
00155  */
00156 EXTERN_C mxArray * matGetNextVariable(MATFile *pMF, const char **nameptr);
00157 
00158 
00159 /*
00160  * Read the array header of the next array value in a MAT-file.  
00161  * This function should only be used in conjunction with 
00162  * matOpen and matClose.  Passing pMF to any other API functions
00163  * will cause matGetNextVariableInfo to work incorrectly.
00164  * 
00165  * See the description of matGetVariableInfo() for the definition
00166  * and valid uses of an array header.
00167  *
00168  * Return NULL if an error occurs.
00169  */ 
00170 EXTERN_C mxArray * matGetNextVariableInfo(MATFile *pMF, const char **nameptr);
00171 
00172 
00173 /*
00174  * Read the array header for the variable with the specified name from 
00175  * the MAT-file.
00176  * 
00177  * An array header contains all the same information as an
00178  * array, except that the pr, pi, ir, and jc data structures are 
00179  * not allocated for non-recursive data types.  That is,
00180  * Cells, structures, and objects contain pointers to other
00181  * array headers, but numeric, string, and sparse arrays do not 
00182  * contain valid data in their pr, pi, ir, or jc fields.
00183  *
00184  * The purpose of an array header is to gain fast access to 
00185  * information about an array without reading all the array's
00186  * actual data.  Thus, functions such as mxGetM, mxGetN, and mxGetClassID
00187  * can be used with array headers, but mxGetPr, mxGetPi, mxGetIr, mxGetJc,
00188  * mxSetPr, mxSetPi, mxSetIr, and mxSetJc cannot.
00189  *
00190  * An array header should NEVER be returned to MATLAB (for example via the
00191  * MEX API), or any other non-matrix access API function that expects a
00192  * full mxArray (examples include engPutVariable(), matPutVariable(), and 
00193  * mexPutVariable()).
00194  *
00195  * Return NULL if an error occurs.
00196  */
00197 EXTERN_C mxArray * matGetVariableInfo(MATFile *pMF, const char * name);
00198 
00199 
00200 /*
00201  * Remove a variable with with the specified name from the MAT-file pMF.
00202  *
00203  * Return zero on success, non-zero on error.
00204  */
00205 EXTERN_C int matDeleteVariable(MATFile *pMF, const char *name);
00206 
00207 
00208 /* 
00209  * Get a list of the names of the arrays in a MAT-file.
00210  * The array of strings returned by this function contains "num"
00211  * entries.  It is allocated with one call to mxCalloc, and so 
00212  * can (must) be freed with one call to mxFree.
00213  *
00214  * If there are no arrays in the MAT-file, return value 
00215  * is NULL and num is set to zero.  If an error occurs,
00216  * return value is NULL and num is set to a negative number.
00217  */
00218 EXTERN_C char ** matGetDir(MATFile * pMF, int *num);
00219 
00220 
00221 #if defined(V5_COMPAT)
00222 #define matPutArray(pMF, pA)         matPutVariable(pMF, mxGetName(pA), pA)
00223 #define matPutNextArray(pMF, pA)     matPutNextVariable(pMF, mxGetName(pA), pA)
00224 #define matPutArrayAsGlobal(pMF, pA) matPutVariableAsGlobal(pMF, mxGetName(pA), pA)
00225 #define matGetArray(pMF, name)       matGetVariable(pMF, name)
00226 #define matGetArrayHeader(pMF, name) matGetVariableInfo(pMF, name)
00227 #define matGetNextArray(pMF)         matGetNextVariable(pMF, NULL)
00228 #define matGetNextArrayHeader(pMF)   matGetNextVariableInfo(pMF, NULL)
00229 #define matDeleteArray(pMF, name)    matDeleteVariable(pMF, name)
00230 #else
00231 #define matPutArray()                matPutArray_is_obsolete
00232 #define matPutNextArray()            matPutNextArray_is_obsolete
00233 #define matPutArrayAsGlobal()        matPutArrayAsGlobal_is_obsolete
00234 #define matGetArray()                matGetArray_is_obsolete
00235 #define matGetArrayHeader()          matGetArrayHeader_is_obsolete
00236 #define matGetNextArray()            matGetNextArray_is_obsolete
00237 #define matGetNextArrayHeader()      matGetNextArrayHeader_is_obsolete
00238 #define matDeleteArray()             matDeleteArray_is_obsolete
00239 #endif  /* defined(V5_COMPAT) */
00240 
00241 
00242 /* $Revision: 1.1 $ */
00243 #ifdef ARGCHECK
00244 
00245 #include "mwdebug.h" /* Prototype _d versions of API functions */
00246 
00247 #define matClose(pMAT)              matClose_d(pMAT, __FILE__, __LINE__)
00248 #define matDeleteVariable(pMAT, name)       matDeleteVariable_d(pMAT, name, __FILE__, __LINE__) 
00249 #define matGetVariable(pMAT, name)  matGetVariable_d(pMAT, name, __FILE__, __LINE__) 
00250 #define matGetVariableInfo(pMAT, name) matGetVariableInfo_d(pMAT, name, __FILE__, __LINE__) 
00251 #define matGetDir(pMAT, num)            matGetDir_d(pMAT, num, __FILE__, __LINE__)
00252 #define matGetFp(pMAT)              matGetFp_d(pMAT, __FILE__, __LINE__) 
00253 #define matGetNextVariable(pMAT, pname) matGetNextVariable_d(pMAT, pname, __FILE__, __LINE__)
00254 #define matGetNextVariableInfo(pMAT, pname)     matGetNextVariableInfo_d(pMAT, pname, __FILE__, __LINE__)
00255 #define matOpen(fname, permissions)             matOpen_d(fname, permissions, __FILE__, __LINE__) 
00256 #define matPutVariable(pMAT, name, pa)  matPutVariable_d(pMAT, name, pa, __FILE__, __LINE__)
00257 #define matPutVariableAsGlobal(pMAT, name, pa) matPutVariableAsGlobal_d(pMAT, name, pa, __FILE__, __LINE__)
00258 #endif
00259 
00260 #endif /* mat_h */

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