From: Reino Ruusu Date: Fri, 3 Mar 2017 16:13:16 +0000 (+0200) Subject: Fixed errors in feature.xml and SCL module. X-Git-Tag: v1.31.0~1 X-Git-Url: https://gerrit.simantics.org/r/gitweb?a=commitdiff_plain;h=1d69b788e922e5f6333dc93188c7da3a55d08723;p=simantics%2Fmatlab.git Fixed errors in feature.xml and SCL module. The wrong fi.vtt-prefixed names were corrected feature.xml. Added .feature to the id of the feature. Deleted erroneous references to jnipython.dll. Deleted requirement of JUnit from feature. Finished SCL module definition that was under development. Change-Id: Ib75106c7d153511654c1277d4c0edd72fe223565 --- diff --git a/org.simantics.matlablink.feature/feature.xml b/org.simantics.matlablink.feature/feature.xml index 292ec4a..4bd7d31 100644 --- a/org.simantics.matlablink.feature/feature.xml +++ b/org.simantics.matlablink.feature/feature.xml @@ -1,6 +1,6 @@ @@ -17,26 +17,23 @@ - - + fragment="true"/> diff --git a/org.simantics.matlablink.win32.x86_64/build.properties b/org.simantics.matlablink.win32.x86_64/build.properties index 2d0d26e..6cb28ac 100644 --- a/org.simantics.matlablink.win32.x86_64/build.properties +++ b/org.simantics.matlablink.win32.x86_64/build.properties @@ -2,7 +2,5 @@ source.. = src/ output.. = bin/ bin.includes = META-INF/,\ .,\ - jnimatlab.dll,\ - jnipython.dll -src.includes = jnimatlab.dll,\ - jnipython.dll + jnimatlab.dll +src.includes = jnimatlab.dll diff --git a/org.simantics.matlablink/scl/Simantics/Matlab.scl b/org.simantics.matlablink/scl/Simantics/Matlab.scl index 811e0aa..33d6cfb 100644 --- a/org.simantics.matlablink/scl/Simantics/Matlab.scl +++ b/org.simantics.matlablink/scl/Simantics/Matlab.scl @@ -1,21 +1,64 @@ import "Map" as Map import "Vector" import "File" +import "JavaBuiltin" as Java effect Matlab "Simantics/Matlab/Matlab" "org.simantics.matlablink.Engine" -importJava "org.simantics.matlablink.MatlabArray" +importJava "org.simantics.matlablink.MatlabArray" where data MatlabArray -importJava "org.simantics.matlablink.DoubleArray" - data DoubleArray -importJava "org.simantics.matlablink.CharacterArray" - data CharacterArray -importJava "org.simantics.matlablink.CellArray" - data CellArray -importJava "org.simantics.matlablink.StructArray" - data StructArray + getDoubleValue :: MatlabArray -> Vector Double + + @JavaName getDoubleValue + getDoubleItem :: MatlabArray -> Integer -> Double + + getStringValue :: MatlabArray -> String + getCellValue :: MatlabArray -> Vector MatlabArray + getCellItem :: MatlabArray -> Integer -> MatlabArray + getField :: MatlabArray -> Integer -> String -> MatlabArray + getStructItem :: MatlabArray -> Integer -> Map.T String MatlabArray + + isDouble :: MatlabArray -> Boolean + isCharacter :: MatlabArray -> Boolean + isCell :: MatlabArray -> Boolean + isStruct :: MatlabArray -> Boolean + + size :: MatlabArray -> Integer + dims :: MatlabArray -> Vector Integer + + @private + @JavaName toString + matlabArrayToString :: MatlabArray -> String + +importJava "org.simantics.matlablink.DoubleArray" where + data MatlabDoubleArray + @JavaName "" + doubleArray :: Vector Double -> MatlabArray + +importJava "org.simantics.matlablink.CharacterArray" where + data MatlabCharacterArray + @JavaName "" + characterArray :: String -> MatlabArray + +importJava "org.simantics.matlablink.CellArray" where + data MatlabCellArray + @JavaName "" + cellArray :: Integer -> MatlabCellArray + @JavaName "" + ndimCellArray :: Vector Integer -> MatlabCellArray + + setCellItem :: MatlabCellArray -> Integer -> MatlabArray -> () + +importJava "org.simantics.matlablink.StructArray" where + data MatlabStructArray + @JavaName "" + structArray :: Integer -> [String] -> MatlabStructArray + @JavaName "" + ndimStructArray :: Vector Integer -> [String] -> MatlabStructArray + + setField :: MatlabStructArray -> Integer -> String -> MatlabArray -> () importJava "org.simantics.matlablink.Engine" where data Engine @@ -24,19 +67,58 @@ importJava "org.simantics.matlablink.Engine" where closeEngine :: Engine -> () @JavaName evaluateMatlabExpression - executeMatlabExpression :: String -> () + executeMatlabStatement :: String -> () getMatlabArray :: String -> MatlabArray - getMatlabDoubleArray :: String -> DoubleArray - getMatlabCharacterArray :: String -> ChracterArray - getMatlabCellArray :: String -> CellArray - getMatlabStructArray :: String -> StructArray + getMatlabDoubleArray :: String -> MatlabArray + getMatlabCharacterArray :: String -> MatlabArray + getMatlabCellArray :: String -> MatlabArray + getMatlabStructArray :: String -> MatlabArray + + @private + @JavaName setMatlabDoubleArray + setMatlabDoubleArray' :: String -> MatlabDoubleArray -> () + @private + @JavaName setMatlabCharacterArray + setMatlabCharacterArray' :: String -> MatlabCharacterArray -> () + @private + @JavaName setMatlabCellArray + setMatlabCellArray' :: String -> MatlabCellArray -> () + @private + @JavaName setMatlabStructArray + setMatlabStructArray' :: String -> MatlabStructArray -> () + +@private +setMatlabDoubleArray :: String -> MatlabArray -> () +setMatlabDoubleArray name value = setMatlabDoubleArray' name (Java.unsafeCoerce value) + +@private +setMatlabCharacterArray :: String -> MatlabArray -> () +setMatlabCharacterArray name value = setMatlabCharacterArray' name (Java.unsafeCoerce value) + +@private +setMatlabCellArray :: String -> MatlabArray -> () +setMatlabCellArray name value = setMatlabCellArray' name (Java.unsafeCoerce value) + +@private +setMatlabStructArray :: String -> MatlabArray -> () +setMatlabStructArray name value = setMatlabStructArray' name (Java.unsafeCoerce value) + +class MatlabArrayType a where + asArray :: a -> MatlabArray + asArray = Java.unsafeCoerce - setMatlabArray :: String -> MatlabArray -> () - setMatlabDoubleArray :: String -> DoubleArray -> () - setMatlabCharacterArray :: String -> CharacterArray -> () - setMatlabCellArray :: String -> CellArray -> () - setMatlabStructArray :: String -> StructArray -> () +instance MatlabArrayType MatlabArray +instance MatlabArrayType MatlabDoubleArray +instance MatlabArrayType MatlabCharacterArray +instance MatlabArrayType MatlabCellArray +instance MatlabArrayType MatlabStructArray + +instance (MatlabArrayType a) => Show a where + show = matlabArrayToString . asArray + +setMatlabArray :: MatlabArrayType a => String -> a -> () +setMatlabArray name value = matchMatlabArray (asArray value) (setMatlabDoubleArray name) (setMatlabCharacterArray name) (setMatlabCellArray name) (setMatlabStructArray name) importJava "org.simantics.matlablink.Matlab" where @JavaName runWithEngine @@ -44,8 +126,9 @@ importJava "org.simantics.matlablink.Matlab" where @JavaName runMatlab runMatlabF :: File -> (() -> a) -> a - - matchMatlabArray :: a -> (Vector Double -> b) -> (String -> b) -> (Vector Dynamic -> b) -> (Map.T String (Vector Dynamic) -> b) -> b + + "Apply type-specific processing to a Matlab array: `matchMatlabArray array doubleFun charFun cellFun structFun`" + matchMatlabArray :: MatlabArray -> (MatlabArray -> b) -> (MatlabArray -> b) -> (MatlabArray -> b) -> (MatlabArray -> b) -> b openEngine :: File -> Engine @@ -57,7 +140,7 @@ runMatlab wd v = runMatlabF wd (\_ -> v) evaluateMatlabExpression :: MatlabCompatible a => String -> a evaluateMatlabExpression expression = do - executeMatlabExpression expression + executeMatlabStatement expression getMatlabVariable "ans" class (Typeable a) => MatlabCompatible a where @@ -65,33 +148,33 @@ class (Typeable a) => MatlabCompatible a where setMatlabVariable :: String -> a -> () instance MatlabCompatible (Vector Double) where - getMatlabVariable = getMatlabDoubleArray - setMatlabVariable name value = setMatlabDoubleArray name False value + getMatlabVariable = getDoubleValue . getMatlabDoubleArray + setMatlabVariable name value = setMatlabDoubleArray name (doubleArray value) instance MatlabCompatible [Double] where - getMatlabVariable = vectorToList . getMatlabDoubleArray - setMatlabVariable name value = setMatlabDoubleArray name False (vector value) + getMatlabVariable = vectorToList . getDoubleValue . getMatlabDoubleArray + setMatlabVariable name value = setMatlabDoubleArray name (doubleArray (vector value)) instance MatlabCompatible Double where - getMatlabVariable name = (getMatlabDoubleArray name)!0 - setMatlabVariable name value = setMatlabDoubleArray name False (vector [value]) + getMatlabVariable name = getDoubleItem (getMatlabDoubleArray name) 0 + setMatlabVariable name value = setMatlabDoubleArray name (doubleArray (vector [value])) instance MatlabCompatible String where - getMatlabVariable = getMatlabCharacterArray - setMatlabVariable = setMatlabCharacterArray + getMatlabVariable = getStringValue . getMatlabCharacterArray + setMatlabVariable name value = setMatlabCharacterArray name (characterArray value) -instance MatlabCompatible (Vector Dynamic) where - getMatlabVariable = getMatlabCellArray - setMatlabVariable name value = setMatlabCellArray name False value +instance MatlabCompatible (Vector MatlabArray) where + getMatlabVariable = getCellValue . getMatlabCellArray + setMatlabVariable name value = do + n = length value + array = cellArray n + forN n \i -> setCellItem array i (value!i) + setMatlabCellArray' name array -instance MatlabCompatible Dynamic where +instance MatlabCompatible [MatlabArray] where + getMatlabVariable = vectorToList . getCellValue . getMatlabCellArray + setMatlabVariable name value = setMatlabVariable name (vector value) + +instance MatlabCompatible MatlabArray where getMatlabVariable = getMatlabArray setMatlabVariable = setMatlabArray - -instance MatlabCompatible (Dynamic, Dynamic) where - getMatlabVariable name = let - v = getMatlabCellArray name - in - (v!0, v!1) - - setMatlabVariable name (a, b) = setMatlabCellArray name False (vector [toDynamic a, toDynamic b]) diff --git a/org.simantics.matlablink/src/org/simantics/matlablink/Matlab.java b/org.simantics.matlablink/src/org/simantics/matlablink/Matlab.java index 9d4adcf..b08f6b0 100644 --- a/org.simantics.matlablink/src/org/simantics/matlablink/Matlab.java +++ b/org.simantics.matlablink/src/org/simantics/matlablink/Matlab.java @@ -52,16 +52,16 @@ public class Matlab { } @SuppressWarnings( { "unchecked", "rawtypes" } ) - public static Object matchMatlabArray(Object array, Function doubleFun, Function stringFun, Function cellFun, Function structFun) { - if (array instanceof double[]) + public static Object matchMatlabArray(MatlabArray array, Function doubleFun, Function stringFun, Function cellFun, Function structFun) { + if (array instanceof DoubleArray) return doubleFun.apply(array); - else if (array instanceof String) + else if (array instanceof CharacterArray) return stringFun.apply(array); - else if (array instanceof Object[]) + else if (array instanceof CellArray) return cellFun.apply(array); - else if (array instanceof Map) + else if (array instanceof StructArray) return structFun.apply(array); else - return null; + throw new IllegalArgumentException("Unknown Matlab array type: " + array.getClass().getName()); } } diff --git a/org.simantics.matlablink/test/org/simantics/matlablink/test/TestMatlabEngine.java b/org.simantics.matlablink/test/org/simantics/matlablink/test/TestMatlabEngine.java index cae75fc..8fad938 100644 --- a/org.simantics.matlablink/test/org/simantics/matlablink/test/TestMatlabEngine.java +++ b/org.simantics.matlablink/test/org/simantics/matlablink/test/TestMatlabEngine.java @@ -21,17 +21,17 @@ import org.simantics.matlablink.StructArray; public class TestMatlabEngine { - Engine engine; - Path tempDir; + static Engine engine; + static Path tempDir; @BeforeClass - public void setUp() throws Exception { + public static void setUp() throws Exception { tempDir = Files.createTempDirectory( "testMatlabEngine" ); engine = Matlab.openEngine(tempDir.toFile()); } @AfterClass - public void tearDown() throws Exception { + public static void tearDown() throws Exception { engine.close(); tempDir.toFile().delete(); }