|
1 | | -module MATLAB |
| 1 | +__precompile__() |
2 | 2 |
|
3 | | -using Base.Libdl: dlopen, dlsym, RTLD_LAZY, RTLD_GLOBAL |
| 3 | +module MATLAB |
4 | 4 |
|
5 | 5 | import Base: eltype, close, size, copy, ndims, unsafe_convert |
6 | 6 |
|
|
41 | 41 | include("mxbase.jl") |
42 | 42 | include("mxarray.jl") |
43 | 43 | include("matfile.jl") |
44 | | - |
45 | 44 | include("mstatements.jl") |
46 | 45 | include("engine.jl") |
47 | 46 | include("matstr.jl") |
48 | 47 |
|
49 | 48 | function __init__() |
| 49 | + |
| 50 | + # load libraries |
| 51 | + |
| 52 | + libmx[] = Libdl.dlopen(joinpath(matlab_lib_path, "libmx"), Libdl.RTLD_GLOBAL) |
| 53 | + libmat[] = Libdl.dlopen(joinpath(matlab_lib_path, "libmat"), Libdl.RTLD_GLOBAL) |
| 54 | + libeng[] = Libdl.dlopen(joinpath(matlab_lib_path, "libeng"), Libdl.RTLD_GLOBAL) |
| 55 | + |
| 56 | + |
| 57 | + # load functions to access mxArray |
| 58 | + |
| 59 | + _mx_free[] = mxfunc(:mxFree) |
| 60 | + |
| 61 | + _mx_get_classid[] = mxfunc(:mxGetClassID) |
| 62 | + _mx_get_m[] = mxfunc(:mxGetM) |
| 63 | + _mx_get_n[] = mxfunc(:mxGetN) |
| 64 | + _mx_get_nelems[] = mxfunc(:mxGetNumberOfElements) |
| 65 | + _mx_get_ndims[] = mxfunc(:mxGetNumberOfDimensions_730) |
| 66 | + _mx_get_elemsize[] = mxfunc(:mxGetElementSize) |
| 67 | + _mx_get_data[] = mxfunc(:mxGetData) |
| 68 | + _mx_get_dims[] = mxfunc(:mxGetDimensions_730) |
| 69 | + _mx_get_nfields[] = mxfunc(:mxGetNumberOfFields) |
| 70 | + _mx_get_pr[] = mxfunc(:mxGetPr) |
| 71 | + _mx_get_pi[] = mxfunc(:mxGetPi) |
| 72 | + _mx_get_ir[] = mxfunc(:mxGetIr_730) |
| 73 | + _mx_get_jc[] = mxfunc(:mxGetJc_730) |
| 74 | + |
| 75 | + _mx_is_double[] = mxfunc(:mxIsDouble) |
| 76 | + _mx_is_single[] = mxfunc(:mxIsSingle) |
| 77 | + _mx_is_int64[] = mxfunc(:mxIsInt64) |
| 78 | + _mx_is_uint64[] = mxfunc(:mxIsUint64) |
| 79 | + _mx_is_int32[] = mxfunc(:mxIsInt32) |
| 80 | + _mx_is_uint32[] = mxfunc(:mxIsUint32) |
| 81 | + _mx_is_int16[] = mxfunc(:mxIsInt16) |
| 82 | + _mx_is_uint16[] = mxfunc(:mxIsUint16) |
| 83 | + _mx_is_int8[] = mxfunc(:mxIsInt8) |
| 84 | + _mx_is_uint8[] = mxfunc(:mxIsUint8) |
| 85 | + _mx_is_char[] = mxfunc(:mxIsChar) |
| 86 | + |
| 87 | + _mx_is_numeric[] = mxfunc(:mxIsNumeric) |
| 88 | + _mx_is_logical[] = mxfunc(:mxIsLogical) |
| 89 | + _mx_is_complex[] = mxfunc(:mxIsComplex) |
| 90 | + _mx_is_sparse[] = mxfunc(:mxIsSparse) |
| 91 | + _mx_is_empty[] = mxfunc(:mxIsEmpty) |
| 92 | + _mx_is_struct[] = mxfunc(:mxIsStruct) |
| 93 | + _mx_is_cell[] = mxfunc(:mxIsCell) |
| 94 | + |
| 95 | + |
| 96 | + # load functions to create & delete MATLAB array |
| 97 | + |
| 98 | + _mx_create_numeric_mat[] = mxfunc(:mxCreateNumericMatrix_730) |
| 99 | + _mx_create_numeric_arr[] = mxfunc(:mxCreateNumericArray_730) |
| 100 | + |
| 101 | + _mx_create_double_scalar[] = mxfunc(:mxCreateDoubleScalar) |
| 102 | + _mx_create_logical_scalar[] = mxfunc(:mxCreateLogicalScalar) |
| 103 | + |
| 104 | + _mx_create_sparse[] = mxfunc(:mxCreateSparse_730) |
| 105 | + _mx_create_sparse_logical[] = mxfunc(:mxCreateSparseLogicalMatrix_730) |
| 106 | + |
| 107 | + _mx_create_string[] = mxfunc(:mxCreateString) |
| 108 | + _mx_create_char_array[] = mxfunc(:mxCreateCharArray_730) |
| 109 | + |
| 110 | + _mx_create_cell_array[] = mxfunc(:mxCreateCellArray_730) |
| 111 | + |
| 112 | + _mx_create_struct_matrix[] = mxfunc(:mxCreateStructMatrix_730) |
| 113 | + _mx_create_struct_array[] = mxfunc(:mxCreateStructArray_730) |
| 114 | + |
| 115 | + _mx_get_cell[] = mxfunc(:mxGetCell_730) |
| 116 | + _mx_set_cell[] = mxfunc(:mxSetCell_730) |
| 117 | + |
| 118 | + _mx_get_field[] = mxfunc(:mxGetField_730) |
| 119 | + _mx_set_field[] = mxfunc(:mxSetField_730) |
| 120 | + _mx_get_field_bynum[] = mxfunc(:mxGetFieldByNumber_730) |
| 121 | + _mx_get_fieldname[] = mxfunc(:mxGetFieldNameByNumber) |
| 122 | + |
| 123 | + _mx_get_string[] = mxfunc(:mxGetString_730) |
| 124 | + |
| 125 | + |
| 126 | + # load I/O mat functions |
| 127 | + |
| 128 | + _mat_open[] = matfunc(:matOpen) |
| 129 | + _mat_close[] = matfunc(:matClose) |
| 130 | + _mat_get_variable[] = matfunc(:matGetVariable) |
| 131 | + _mat_put_variable[] = matfunc(:matPutVariable) |
| 132 | + _mat_get_dir[] = matfunc(:matGetDir) |
| 133 | + |
| 134 | + |
50 | 135 | if is_windows() |
51 | | - global persistent_msession |
52 | 136 | # workaround "primary message table for module 77" error |
53 | 137 | # creates a dummy Engine session and keeps it open so the libraries used by all other |
54 | 138 | # Engine clients are not loaded and unloaded repeatedly |
55 | 139 | # see: https://www.mathworks.com/matlabcentral/answers/305877-what-is-the-primary-message-table-for-module-77 |
56 | | - persistent_msession = MSession(0) |
| 140 | + global persistent_msession = MSession(0) |
57 | 141 | end |
58 | 142 | end |
59 | 143 |
|
60 | | -# deprecations |
| 144 | + |
| 145 | +########################################################### |
| 146 | +# |
| 147 | +# deprecations |
| 148 | +# |
| 149 | +########################################################### |
| 150 | + |
61 | 151 | function nfields(mx::MxArray) |
62 | 152 | Base.depwarn("MATLAB.nfields is deprecated, use mxnfields instead.", :nfields) |
63 | 153 | return mxfields(mx) |
|
76 | 166 |
|
77 | 167 | @deprecate mxempty() mxarray(Float64,0,0) |
78 | 168 |
|
79 | | - |
80 | 169 | end |
0 commit comments