\r
File mbin = new File(mingw, "bin");\r
File mlib = new File(mingw, "lib");\r
- env.put("PATH", env.get("PATH") + File.pathSeparator + bin.getAbsolutePath()\r
- + File.pathSeparator + mbin.getAbsolutePath()\r
- + File.pathSeparator + mlib.getAbsolutePath());\r
- \r
+ String path_allcaps = env.get("PATH") == null ? "" : env.get("PATH") + File.pathSeparator;\r
+ env.put("PATH", path_allcaps + bin.getAbsolutePath()\r
+ + File.pathSeparator + mbin.getAbsolutePath()\r
+ + File.pathSeparator + mlib.getAbsolutePath());\r
+ String path = env.get("Path") == null ? "" : env.get("Path") + File.pathSeparator;\r
+ env.put("Path", path + bin.getAbsolutePath()\r
+ + File.pathSeparator + mbin.getAbsolutePath()\r
+ + File.pathSeparator + mlib.getAbsolutePath());\r
+\r
env.put("MODELICAUSERCFLAGS", "-O0");\r
\r
// run the process\r
import java.io.FileNotFoundException;\r
import java.io.FileOutputStream;\r
import java.io.IOException;\r
+import java.lang.reflect.Field;\r
import java.util.ArrayList;\r
import java.util.HashMap;\r
\r
private double startTime = DEFAULT_START_TIME;\r
private double stepDuration = DEFAULT_STEP_DURATION;\r
private int savePer = 1;\r
+ private static boolean fortranLibrariesLoaded = false;\r
\r
public static double DEFAULT_STEP_DURATION = 1.0;\r
public static double DEFAULT_STEP_LENGTH = 0.1;\r
if(simulationLocation != null && !canceled) {\r
// Load fmu and initialize it for simulation\r
try {\r
+ if (!fortranLibrariesLoaded) {\r
+ File omDir = ModelicaManager.getOMHome();\r
+ File mingw = new File(omDir, "MinGW");\r
+ File mbin = new File(mingw, "bin");\r
+ \r
+ // Add MinGW path to java.library.path. This is a bit of a hack because \r
+ // java.library.path isn't intended to be set programmatically.\r
+ String newLibPath = System.getProperty("java.library.path") + File.pathSeparator + mbin.getAbsolutePath();\r
+ System.setProperty("java.library.path", newLibPath);\r
+ Field fieldSysPath = ClassLoader.class.getDeclaredField("sys_paths");\r
+ fieldSysPath.setAccessible(true);\r
+ if (fieldSysPath != null) {\r
+ fieldSysPath.set(System.class.getClassLoader(), null);\r
+ }\r
+ \r
+ System.loadLibrary("libgfortran-3");\r
+ System.out.println("Loaded libgfortran-3.dll");\r
+ System.loadLibrary("pthreadGC2");\r
+ System.out.println("Loaded pthreadGC2.dll");\r
+ fortranLibrariesLoaded = true;\r
+ }\r
+ \r
control.loadFMUFile(simulationLocation.executableFile.getAbsolutePath()); // unzip and load fmu\r
instantiate();\r
\r
} catch (FMUJNIException e) {\r
System.err.println("SysdynGameExperiment initialization failed:\n\t" + e.getMessage());\r
+ } catch (SecurityException e) {\r
+ // TODO Auto-generated catch block\r
+ e.printStackTrace();\r
+ } catch (NoSuchFieldException e) {\r
+ // TODO Auto-generated catch block\r
+ e.printStackTrace();\r
+ } catch (IllegalArgumentException e) {\r
+ // TODO Auto-generated catch block\r
+ e.printStackTrace();\r
+ } catch (IllegalAccessException e) {\r
+ // TODO Auto-generated catch block\r
+ e.printStackTrace();\r
}\r
\r
}\r