[138] | 1 | /* |
---|
| 2 | * MATLAB Compiler: 4.11 (R2009b) |
---|
| 3 | * Date: Wed Jan 13 16:03:50 2010 |
---|
| 4 | * Arguments: "-B" "macro_default" "-B" "csharedlib:libmatrix" "-W" |
---|
| 5 | * "lib:libmatrix" "-T" "link:lib" "addmatrix.m" "multiplymatrix.m" |
---|
| 6 | * "eigmatrix.m" "-v" |
---|
| 7 | */ |
---|
| 8 | |
---|
| 9 | #include <stdio.h> |
---|
| 10 | #define EXPORTING_libmatrix 1 |
---|
| 11 | #include "libmatrix.h" |
---|
| 12 | #ifdef __cplusplus |
---|
| 13 | extern "C" { |
---|
| 14 | #endif |
---|
| 15 | |
---|
| 16 | extern mclComponentData __MCC_libmatrix_component_data; |
---|
| 17 | |
---|
| 18 | #ifdef __cplusplus |
---|
| 19 | } |
---|
| 20 | #endif |
---|
| 21 | |
---|
| 22 | |
---|
| 23 | static HMCRINSTANCE _mcr_inst = NULL; |
---|
| 24 | |
---|
| 25 | |
---|
| 26 | #ifdef __cplusplus |
---|
| 27 | extern "C" { |
---|
| 28 | #endif |
---|
| 29 | |
---|
| 30 | static int mclDefaultPrintHandler(const char *s) |
---|
| 31 | { |
---|
| 32 | return mclWrite(1 /* stdout */, s, sizeof(char)*strlen(s)); |
---|
| 33 | } |
---|
| 34 | |
---|
| 35 | #ifdef __cplusplus |
---|
| 36 | } /* End extern "C" block */ |
---|
| 37 | #endif |
---|
| 38 | |
---|
| 39 | #ifdef __cplusplus |
---|
| 40 | extern "C" { |
---|
| 41 | #endif |
---|
| 42 | |
---|
| 43 | static int mclDefaultErrorHandler(const char *s) |
---|
| 44 | { |
---|
| 45 | int written = 0; |
---|
| 46 | size_t len = 0; |
---|
| 47 | len = strlen(s); |
---|
| 48 | written = mclWrite(2 /* stderr */, s, sizeof(char)*len); |
---|
| 49 | if (len > 0 && s[ len-1 ] != '\n') |
---|
| 50 | written += mclWrite(2 /* stderr */, "\n", sizeof(char)); |
---|
| 51 | return written; |
---|
| 52 | } |
---|
| 53 | |
---|
| 54 | #ifdef __cplusplus |
---|
| 55 | } /* End extern "C" block */ |
---|
| 56 | #endif |
---|
| 57 | |
---|
| 58 | /* This symbol is defined in shared libraries. Define it here |
---|
| 59 | * (to nothing) in case this isn't a shared library. |
---|
| 60 | */ |
---|
| 61 | #ifndef LIB_libmatrix_C_API |
---|
| 62 | #define LIB_libmatrix_C_API /* No special import/export declaration */ |
---|
| 63 | #endif |
---|
| 64 | |
---|
| 65 | LIB_libmatrix_C_API |
---|
| 66 | bool MW_CALL_CONV libmatrixInitializeWithHandlers( |
---|
| 67 | mclOutputHandlerFcn error_handler, |
---|
| 68 | mclOutputHandlerFcn print_handler) |
---|
| 69 | { |
---|
| 70 | if (_mcr_inst != NULL) |
---|
| 71 | return true; |
---|
| 72 | if (!mclmcrInitialize()) |
---|
| 73 | return false; |
---|
| 74 | if (!mclInitializeComponentInstanceWithEmbeddedCTF(&_mcr_inst, |
---|
| 75 | &__MCC_libmatrix_component_data, |
---|
| 76 | true, NoObjectType, LibTarget, |
---|
| 77 | error_handler, print_handler, 62361, |
---|
| 78 | (void |
---|
| 79 | *)(libmatrixInitializeWithHandlers))) |
---|
| 80 | return false; |
---|
| 81 | return true; |
---|
| 82 | } |
---|
| 83 | |
---|
| 84 | LIB_libmatrix_C_API |
---|
| 85 | bool MW_CALL_CONV libmatrixInitialize(void) |
---|
| 86 | { |
---|
| 87 | return libmatrixInitializeWithHandlers(mclDefaultErrorHandler, mclDefaultPrintHandler); |
---|
| 88 | } |
---|
| 89 | |
---|
| 90 | LIB_libmatrix_C_API |
---|
| 91 | void MW_CALL_CONV libmatrixTerminate(void) |
---|
| 92 | { |
---|
| 93 | if (_mcr_inst != NULL) |
---|
| 94 | mclTerminateInstance(&_mcr_inst); |
---|
| 95 | } |
---|
| 96 | |
---|
| 97 | LIB_libmatrix_C_API |
---|
| 98 | long MW_CALL_CONV libmatrixGetMcrID() |
---|
| 99 | { |
---|
| 100 | return mclGetID(_mcr_inst); |
---|
| 101 | } |
---|
| 102 | |
---|
| 103 | LIB_libmatrix_C_API |
---|
| 104 | void MW_CALL_CONV libmatrixPrintStackTrace(void) |
---|
| 105 | { |
---|
| 106 | char** stackTrace; |
---|
| 107 | int stackDepth = mclGetStackTrace(_mcr_inst, &stackTrace); |
---|
| 108 | int i; |
---|
| 109 | for(i=0; i<stackDepth; i++) |
---|
| 110 | { |
---|
| 111 | mclWrite(2 /* stderr */, stackTrace[i], sizeof(char)*strlen(stackTrace[i])); |
---|
| 112 | mclWrite(2 /* stderr */, "\n", sizeof(char)*strlen("\n")); |
---|
| 113 | } |
---|
| 114 | mclFreeStackTrace(&stackTrace, stackDepth); |
---|
| 115 | } |
---|
| 116 | |
---|
| 117 | |
---|
| 118 | LIB_libmatrix_C_API |
---|
| 119 | bool MW_CALL_CONV mlxAddmatrix(int nlhs, mxArray *plhs[], int nrhs, mxArray *prhs[]) |
---|
| 120 | { |
---|
| 121 | return mclFeval(_mcr_inst, "addmatrix", nlhs, plhs, nrhs, prhs); |
---|
| 122 | } |
---|
| 123 | |
---|
| 124 | LIB_libmatrix_C_API |
---|
| 125 | bool MW_CALL_CONV mlxMultiplymatrix(int nlhs, mxArray *plhs[], int nrhs, mxArray *prhs[]) |
---|
| 126 | { |
---|
| 127 | return mclFeval(_mcr_inst, "multiplymatrix", nlhs, plhs, nrhs, prhs); |
---|
| 128 | } |
---|
| 129 | |
---|
| 130 | LIB_libmatrix_C_API |
---|
| 131 | bool MW_CALL_CONV mlxEigmatrix(int nlhs, mxArray *plhs[], int nrhs, mxArray *prhs[]) |
---|
| 132 | { |
---|
| 133 | return mclFeval(_mcr_inst, "eigmatrix", nlhs, plhs, nrhs, prhs); |
---|
| 134 | } |
---|
| 135 | |
---|
| 136 | LIB_libmatrix_C_API |
---|
| 137 | bool MW_CALL_CONV mlfAddmatrix(int nargout, mxArray** a, mxArray* a1, mxArray* a2) |
---|
| 138 | { |
---|
| 139 | return mclMlfFeval(_mcr_inst, "addmatrix", nargout, 1, 2, a, a1, a2); |
---|
| 140 | } |
---|
| 141 | |
---|
| 142 | LIB_libmatrix_C_API |
---|
| 143 | bool MW_CALL_CONV mlfMultiplymatrix(int nargout, mxArray** m, mxArray* a1, mxArray* a2) |
---|
| 144 | { |
---|
| 145 | return mclMlfFeval(_mcr_inst, "multiplymatrix", nargout, 1, 2, m, a1, a2); |
---|
| 146 | } |
---|
| 147 | |
---|
| 148 | LIB_libmatrix_C_API |
---|
| 149 | bool MW_CALL_CONV mlfEigmatrix(int nargout, mxArray** e, mxArray* a1) |
---|
| 150 | { |
---|
| 151 | return mclMlfFeval(_mcr_inst, "eigmatrix", nargout, 1, 1, e, a1); |
---|
| 152 | } |
---|