]> gerrit.simantics Code Review - simantics/fmil.git/commitdiff
Default values for FMI values is NaN in FMIL.java 41/1941/1
authorMiro Richard Eklund <miro.eklund@semantum.fi>
Fri, 20 Jul 2018 14:46:29 +0000 (17:46 +0300)
committerMiro Richard Eklund <miro.eklund@semantum.fi>
Fri, 20 Jul 2018 14:46:29 +0000 (17:46 +0300)
Previously the default values were 0.0. Now, we can clearly see if the
values are fetched internally correctly by starting out with NaN. If an
actual value is found, it replaces it. If it fails, then NaN is still
present.

Change-Id: I019950cdf1559598d216cddbac28b8f2c1da95d5

org.simantics.fmil.core/src/org/simantics/fmil/core/FMIL.java

index fa09a71c4e2536af375ba8b4b0c65cf6a6839b89..7301caf4c8209883e9d77aaaa3fc3e5bc6a5aa17 100644 (file)
@@ -8,6 +8,7 @@ import java.nio.channels.FileChannel;
 import java.nio.channels.FileLock;
 import java.nio.file.Paths;
 import java.util.ArrayList;
+import java.util.Arrays;
 import java.util.HashSet;
 import java.util.List;
 import java.util.Set;
@@ -129,15 +130,16 @@ public class FMIL {
        }
        
        public boolean subscribe(String name) throws FMILException {
-               // Safety check
-               int vr = variableMap.get(name);
-               if(vr == 0) return false;
-               if(!subscriptionSet.add(name)) return false;
-               subscribedNames.add(name);
-               System.err.println("subscribed : " + name + " => " + subscribedNames.size());
-               subscription.add(vr);
-               subscribe(new int[] { vr });
-               return true;
+               synchronized(syncObject) {
+                       // Safety check
+                       int vr = variableMap.get(name);
+                       if(vr == 0) return false;
+                       if(!subscriptionSet.add(name)) return false;
+                       subscribedNames.add(name);
+                       subscription.add(vr);
+                       subscribe(new int[] { vr });
+                       return true;
+               }
        }
 
     public FMIL() {
@@ -495,10 +497,11 @@ public class FMIL {
         synchronized(syncObject) {
 
             try {
-
+               
                double[] results = new double[subscription.size()];
-                return getSubscribedResults_(getModelIDNew(), results);
-
+               Arrays.fill(results, Double.NaN);
+               
+               return getSubscribedResults_(getModelIDNew(), results);
             } catch (UnsatisfiedLinkError err) {
                 throw new FMILException(UNSATISFIED_LINK);
             } catch (Exception e) {