Skip to content

Commit

Permalink
Merge pull request #175 from sbmlteam/matlab-octave-fun
Browse files Browse the repository at this point in the history
Ensure Translate/OutputSBML work on Octave and Matlab
  • Loading branch information
skeating committed Jun 22, 2022
2 parents 14d00cd + 0c7155a commit 3fb6298
Show file tree
Hide file tree
Showing 29 changed files with 3,881 additions and 6,544 deletions.
71 changes: 71 additions & 0 deletions .github/workflows/octave.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
name: Octave

on: [push]

env:
# Customize the CMake build type here (Release, Debug, RelWithDebInfo, etc.)
BUILD_TYPE: Release

jobs:
build:
strategy:
fail-fast: false
matrix:
os: [ubuntu-latest]
runs-on: ${{ matrix.os }}

steps:
- uses: actions/checkout@v2

- name: Checkout submodules
run: git submodule update --init --recursive

- name: update
if: matrix.os == 'ubuntu-latest'
shell: bash
run: |
sudo apt-get update
- name: add linux dependencies
if: matrix.os == 'ubuntu-latest'
shell: bash
run: |
sudo apt-get install swig liboctave-dev
- name: Create Build Environment
# Some projects don't allow in-source building, so create a separate build directory
# We'll use this as our working directory for all subsequent commands
run: cmake -E make_directory ${{runner.workspace}}/build

- name: Configure
# build dependencies
working-directory: ${{runner.workspace}}/build
shell: bash
run: |
cmake -DCMAKE_INSTALL_PREFIX=${{runner.workspace}}/install -DCMAKE_BUILD_TYPE=$BUILD_TYPE -DWITH_BZIP2=ON -DWITH_CHECK=OFF -DWITH_EXPAT=ON -DWITH_LIBXML=OFF -DWITH_OCTAVE=ON $GITHUB_WORKSPACE
- name: Build
working-directory: ${{runner.workspace}}/build
shell: bash
# Execute the build. You can specify a specific target with "--target <NAME>"
run: cmake --build . --config $BUILD_TYPE


- name: Install Strip
working-directory: ${{runner.workspace}}/build
run: cmake --install . --prefix instdir --strip

- name: Pack
working-directory: ${{runner.workspace}}/build/instdir
run: cmake -E tar cvzf ../octave_${{ matrix.os }}.tar.gz .

- name: Test
working-directory: ${{runner.workspace}}/build/instdir/lib/octave/site/oct/x86_64-pc-linux-gnu/test
shell: bash
run: LD_LIBRARY_PATH=../../../../.. octave --eval "runTests()"

- name: Upload
uses: actions/upload-artifact@v1
with:
path: ${{runner.workspace}}/build/octave_${{ matrix.os }}.tar.gz
name: octave_${{ matrix.os }}.tar.gz
5 changes: 5 additions & 0 deletions src/bindings/matlab/.gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,7 @@
runTests.log
*.mex*
testout.xml
mytest.m
*.asv
test/Out-test1/*

9 changes: 8 additions & 1 deletion src/bindings/matlab/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -92,10 +92,17 @@ endif()
if (EXTRA_INCLUDE_DIRS)
include_directories(${EXTRA_INCLUDE_DIRS})
endif(EXTRA_INCLUDE_DIRS)

SET(COMMON_FILES
"${CMAKE_CURRENT_SOURCE_DIR}/ModelDetails.cpp"
"${CMAKE_CURRENT_SOURCE_DIR}/StructureFields.cpp"
"${CMAKE_CURRENT_SOURCE_DIR}/CommonFunctions.cpp"
"${CMAKE_CURRENT_SOURCE_DIR}/Filenames.cpp"
"${CMAKE_CURRENT_SOURCE_DIR}/InputOutput.cpp" )

foreach(matlab_source_file "TranslateSBML" "OutputSBML")

add_library(matlab_binding_${matlab_source_file} SHARED "${CMAKE_CURRENT_SOURCE_DIR}/${matlab_source_file}.cpp")
add_library(matlab_binding_${matlab_source_file} SHARED "${CMAKE_CURRENT_SOURCE_DIR}/${matlab_source_file}.cpp" ${COMMON_FILES})
set_target_properties(matlab_binding_${matlab_source_file} PROPERTIES OUTPUT_NAME "${matlab_source_file}")
set_target_properties(matlab_binding_${matlab_source_file} PROPERTIES SUFFIX ".${MATLAB_MEX_EXT}")
set_target_properties(matlab_binding_${matlab_source_file} PROPERTIES PREFIX "")
Expand Down
114 changes: 114 additions & 0 deletions src/bindings/matlab/CommonFunctions.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,114 @@
#include "CommonFunctions.h"


//
// report error/free memory and exit when error encountered

void
FreeMem(GV& gv)
{
/* destroy arrays created */
mxDestroyArray(gv.modelArray);
gv.modelArray = NULL;
}

void
reportError(const std::string&id, const std::string& message, GV& gv)
{
if (gv.freeMemory)
{
FreeMem(gv);
}

mexErrMsgIdAndTxt(id.c_str(), message.c_str());
}


void
displayLine(const std::string& line)
{
mxArray* mxErrors[1];
mxErrors[0] = mxCreateString(line.c_str());
mexCallMATLAB(0, NULL, 1, mxErrors, "disp");
mxDestroyArray(mxErrors[0]);
}


mxArray *
CreateIntScalar (int nValue)
{
mxArray * pArray;
int * panData;

pArray = mxCreateNumericMatrix(1,1,mxINT32_CLASS, mxREAL);
panData = (int *)mxGetData(pArray);
panData[0] = nValue;

return pArray;
}

const char* FIELDTYPE_STRINGS[] =
{
"bool"
, "char"
, "double"
, "int"
, "structure"
, "uint"
};


FieldType_t
getFieldType(const char* type)
{
if (type != NULL)
{
const FieldType_t lo = TYPE_BOOL;
const FieldType_t hi = (const FieldType_t)(TYPE_UNKNOWN - 1);

return (FieldType_t)util_bsearchStringsI(FIELDTYPE_STRINGS, type, lo, hi);
}
else
return TYPE_UNKNOWN;
}

// only used by OutputSBML
bool getRequiredStatus(const std::string& prefix, GV& gv)
{
bool required = false;

if (gv.reqdPkgPrefixes.contains(prefix))
{
required = true;
}

return required;
}

void populatePackageLists(GV& gv)
{
//reqdPkgPrefixes.append("comp");
//reqdPkgPrefixes.append("spatial");

gv.unreqdPkgPrefixes.append("fbc");
gv.unreqdPkgPrefixes.append("qual");
gv.unreqdPkgPrefixes.append("groups");
}

// only used by OutputSBML
bool
isUnknownType(std::string tc)
{
// TO DO
if (tc == "(Unknown SBML Type)")
return true;
else if (tc == "(Unknown SBML Fbc Type)")
return true;
else if (tc == "(Unknown SBML Groups Type)")
return true;
else if (tc == "(Unknown SBML Qual Type)")
return true;
else
return false;
}

24 changes: 24 additions & 0 deletions src/bindings/matlab/CommonFunctions.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
#ifndef COMMON_FUNTICONS_INCLUDED
#define COMMON_FUNTICONS_INCLUDED

#include <string>

#include "Variables.h"

void FreeMem(GV& gv);

void reportError(const std::string&id, const std::string& message, GV& gv);

void displayLine(const std::string& line);

mxArray * CreateIntScalar (int nValue);

FieldType_t getFieldType(const char* type);

bool getRequiredStatus(const std::string& prefix, GV& gv);

void populatePackageLists(GV& gv);

bool isUnknownType(std::string tc);

#endif // COMMON_FUNTICONS_INCLUDED
2 changes: 1 addition & 1 deletion src/bindings/matlab/ConvertFormulaToMathML.m
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@
j = j+1;
x = SubFormula(j:length(SubFormula)-1);

if (exist('OCTAVE_VERSION', 'var'))
if (exist('OCTAVE_VERSION'))
ReplaceFormula = myRegexprep(SubFormula, n, x, 'once');
ReplaceFormula = myRegexprep(ReplaceFormula,regexptranslate('escape',x),n,2);
ReplaceFormula = myRegexprep(ReplaceFormula, 'nthroot', 'root', 'once');
Expand Down
Loading

0 comments on commit 3fb6298

Please sign in to comment.