diff --git a/CMakeLists.txt b/CMakeLists.txt index 38689ad..9873162 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -62,3 +62,9 @@ add_subdirectory ("MEXlibCZI") add_subdirectory("lib") add_subdirectory("MatlabMex") + +##set(OCTAVE_CONFIGEXECUTABLE_PATHHINT "D:/SW/octave-9.2.0-w64/mingw64/bin") +set(OCTAVE_CONFIGEXECUTABLE_PATHHINT "/d/SW/octave-9.2.0-w64/mingw64/bin/") +find_package(Octave) + +add_subdirectory("OctaveOct") \ No newline at end of file diff --git a/MatlabMex/app_api_implementation.c b/MatlabMex/app_api_implementation.c index 9441950..77f8e98 100644 --- a/MatlabMex/app_api_implementation.c +++ b/MatlabMex/app_api_implementation.c @@ -12,12 +12,12 @@ bool matlabMexIsNanOrInfSingle(float value) return mxIsNaN(value) || mxIsInf(value); } -double matlabMaxGetInfinityDouble(void) +double matlabMexGetInfinityDouble(void) { return mxGetInf(); } -double matlabMaxGetNaNDouble(void) +double matlabMexGetNaNDouble(void) { return mxGetNaN(); } @@ -249,8 +249,8 @@ struct IAppExtensionFunctions g_appExtensionFunctions = { .pfn_IsNanOrInfDouble = matlabMexIsNanOrInfDouble, .pfn_IsNanOrInfSingle = matlabMexIsNanOrInfSingle, - .pfn_GetInfDouble = matlabMaxGetInfinityDouble, - .pfn_GetNaNDouble = matlabMaxGetNaNDouble, + .pfn_GetInfDouble = matlabMexGetInfinityDouble, + .pfn_GetNaNDouble = matlabMexGetNaNDouble, .pfn_GetData = matlabMexGetData, .pfn_GetUint8s = matlabMexGetUint8s, .pfn_GetInt8s = matlabMexGetInt8s, diff --git a/OctaveOct/CMakeLists.txt b/OctaveOct/CMakeLists.txt new file mode 100644 index 0000000..599bf5f --- /dev/null +++ b/OctaveOct/CMakeLists.txt @@ -0,0 +1,11 @@ +set(octaveOctSourceFiles + "octlibczi.cpp" +) + +add_library (OctaveOct SHARED + ${octaveOctSourceFiles}) + +target_compile_features(OctaveOct PRIVATE c_std_11) +set_target_properties(OctaveOct PROPERTIES CXX_STANDARD 17) +target_include_directories(OctaveOct PRIVATE ${OCTAVE_INCLUDE_DIR}/../) +target_link_libraries(OctaveOct PRIVATE lib) diff --git a/OctaveOct/helloworld.cc b/OctaveOct/helloworld.cc new file mode 100644 index 0000000..a6ebfb8 --- /dev/null +++ b/OctaveOct/helloworld.cc @@ -0,0 +1,16 @@ +#include + +DEFUN_DLD(helloworld, args, nargout, + "Hello World Help String") +{ + octave_stdout << "Hello World has " + << args.length() << " input arguments and " + << nargout << " output arguments.\n"; + + // Return empty matrices for any outputs + octave_value_list retval(nargout); + for (int i = 0; i < nargout; i++) + retval(i) = octave_value(Matrix()); + + return retval; +} \ No newline at end of file diff --git a/OctaveOct/octlibczi.cpp b/OctaveOct/octlibczi.cpp new file mode 100644 index 0000000..1b4a13c --- /dev/null +++ b/OctaveOct/octlibczi.cpp @@ -0,0 +1,167 @@ +#include +#include "../AppModel/include/app_api.h" +#include + +bool octaveOctIsNanOrInfDouble(double value) +{ + return octave::math::isnan(value) != 0 || octave::math::isinf(value) != 0; +} + +bool octaveOctIsNanOrInfSingle(float f) +{ + return octave::math::isnan(f) != 0 || octave::math::isinf(f) != 0; +} + +double octaveOctGetInfinityDouble(void) +{ + return lo_ieee_inf_value(); +} + +double octaveOctGetNaNDouble(void) +{ + return lo_ieee_nan_value(); +} + +void* octaveOctGetData(const Parameter* parameter) +{ + return const_cast(reinterpret_cast(const_cast(parameter))->mex_get_data()); +} + +uint8_t* octaveOctGetUint8s(const Parameter* parameter) +{ + return (uint8_t*)(reinterpret_cast(const_cast(parameter))->mex_get_data(mxUINT8_CLASS)); +} + +int8_t* octaveOctGetInt8s(const Parameter* parameter) +{ + return (int8_t*)(reinterpret_cast(const_cast(parameter))->mex_get_data(mxINT8_CLASS)); +} + +uint16_t* octaveOctGetUint16s(const Parameter* parameter) +{ + return (uint16_t*)(reinterpret_cast(const_cast(parameter))->mex_get_data(mxUINT16_CLASS)); +} + +int16_t* octaveOctGetInt16s(const Parameter* parameter) +{ + return (int16_t*)(reinterpret_cast(const_cast(parameter))->mex_get_data(mxINT16_CLASS)); +} + +uint32_t* octaveOctGetUint32s(const Parameter* parameter) +{ + return (uint32_t*)(reinterpret_cast(const_cast(parameter))->mex_get_data(mxUINT32_CLASS)); +} + +int32_t* octaveOctGetInt32s(const Parameter* parameter) +{ + return (int32_t*)(reinterpret_cast(const_cast(parameter))->mex_get_data(mxINT32_CLASS)); +} + +uint64_t* octaveOctGetUint64s(const Parameter* parameter) +{ + return (uint64_t*)(reinterpret_cast(const_cast(parameter))->mex_get_data(mxUINT64_CLASS)); +} + +int64_t* octaveOctGetInt64s(const Parameter* parameter) +{ + return (int64_t*)(reinterpret_cast(const_cast(parameter))->mex_get_data(mxINT64_CLASS)); +} + +double* octaveOctGetDoubles(const Parameter* parameter) +{ + return (double*)(reinterpret_cast(const_cast(parameter))->mex_get_data(mxDOUBLE_CLASS)); +} + +float* octaveOctGetSingles(const Parameter* parameter) +{ + return (float*)(reinterpret_cast(const_cast(parameter))->mex_get_data(mxSINGLE_CLASS)); +} + +bool* octaveOctGetLogicals(const Parameter* parameter) +{ + return (bool*)octaveOctGetData(parameter); +} + +bool octaveOctIsNumeric(const Parameter* parameter) +{ + return reinterpret_cast(parameter)->isnumeric(); +} + +bool octaveOctIsChar(const Parameter* parameter) +{ + return reinterpret_cast(parameter)->is_string(); +} + +bool octaveOctIsSparse(const Parameter* parameter) +{ + return reinterpret_cast(parameter)->issparse(); +} + +bool octaveOctIsStruct(const Parameter* parameter) +{ + return reinterpret_cast(parameter)->isstruct(); +} + +Parameter* octaveOctCreateString(const char* string) +{ + return (Parameter*)new octave_value(string); +} + +void matlabReportErrorAndRaiseSignal(const char* identifier, const char* message) +{ + mexErrMsgIdAndTxt(identifier, message); +} + +char* matlabStrDupHostAllocated(const char* string) +{ + size_t len = strlen(string); + char* msz = (char*)mxMalloc(len + 1); + memcpy(msz, string, len); + msz[len] = '\0'; + return msz; +} + + +static struct IAppExtensionFunctions g_appExtensionFunctions = +{ + octaveOctIsNanOrInfDouble, + octaveOctIsNanOrInfSingle, + octaveOctGetInfinityDouble, + octaveOctGetNaNDouble, + octaveOctGetData, + octaveOctGetUint8s, + octaveOctGetInt8s, + octaveOctGetUint16s, + octaveOctGetInt16s, + octaveOctGetUint32s, + octaveOctGetInt32s, + octaveOctGetUint64s, + octaveOctGetInt64s, + octaveOctGetDoubles, + octaveOctGetSingles, + octaveOctGetLogicals, + nullptr, + nullptr, + nullptr, + nullptr +}; + +constexpr int kMaxInputArguments = 20; + +DEFUN_DLD(octlibczi, args, nargout, + "Hello World Help String") +{ + int nargin = args.length(); + + std::array input_args; + for (int i = 0; i < nargin; ++i) + { + input_args[i] = (Parameter)&args(i); + } + + auto arg0 = args(0); + octave_stdout << "Hello World has " << nargin + << " input arguments and " + << nargout << " output arguments.\n"; + return octave_value_list(); +} \ No newline at end of file diff --git a/OctaveOct/octlibczi.oct b/OctaveOct/octlibczi.oct new file mode 100644 index 0000000..66e7feb Binary files /dev/null and b/OctaveOct/octlibczi.oct differ