\r
import java.io.File;\r
import java.io.FileNotFoundException;\r
+import java.io.FilenameFilter;\r
import java.io.IOException;\r
import java.io.InputStream;\r
import java.io.PrintStream;\r
-import java.io.RandomAccessFile;\r
import java.net.URL;\r
import java.net.URLDecoder;\r
import java.util.ArrayList;\r
Process p = runOMC(simulationLocation.fullModelDir, null, parameters);\r
p.waitFor();\r
\r
- // Find the last line of the full description. This will be the name of the created simulation files\r
- String lastLine = readLastLine(simulationLocation.fullModel.getAbsolutePath());\r
- \r
- if(lastLine != null && lastLine.startsWith("end ")) {\r
- String lastClass = lastLine.substring(4, lastLine.length() -1); // e.g. "end xidz;" -> "xidz"\r
- lastClass = lastClass + "_init.xml";\r
- File initFile = new File(simulationLocation.fullModelDir, lastClass);\r
- if(initFile != null && initFile.isFile()) {\r
- // Replace original init contents with the new contents\r
- replaceInitFileContents(simulationLocation.initFile.getAbsolutePath(), initFile.getAbsolutePath(), experimentParameters);\r
+ // Find the new init file\r
+ FilenameFilter initFilter = new FilenameFilter() {\r
+\r
+ @Override\r
+ public boolean accept(File dir, String name) {\r
+ if(name.endsWith("_init.xml"))\r
+ return true;\r
+ else\r
+ return false;\r
}\r
+ };\r
+\r
+ File initFile = null;\r
+ for(File f : simulationLocation.fullModelDir.listFiles(initFilter)) {\r
+ initFile = f;\r
+ break;\r
}\r
- \r
+\r
+ if(initFile != null && initFile.isFile()) {\r
+ // Replace original init contents with the new contents\r
+ replaceInitFileContents(simulationLocation.initFile.getAbsolutePath(), initFile.getAbsolutePath(), experimentParameters);\r
+ }\r
+\r
} catch (ModelicaException e) {\r
e.printStackTrace();\r
} catch (InterruptedException e) {\r
}\r
}\r
\r
- /**\r
- * utility for reading the list line of a file\r
- * @param fileName\r
- * @return\r
- */\r
- private static String readLastLine( String fileName ) {\r
- try {\r
- File file = new File( fileName );\r
- RandomAccessFile fileHandler = new RandomAccessFile( file, "r" );\r
- long fileLength = file.length() - 1;\r
- StringBuilder sb = new StringBuilder();\r
- \r
- for( long filePointer = fileLength; filePointer != -1; filePointer-- ) {\r
- fileHandler.seek( filePointer );\r
- int readByte = fileHandler.readByte(); \r
- \r
- if( readByte == 0xA ) {\r
- if( filePointer == fileLength ) {\r
- continue;\r
- } else {\r
- break;\r
- }\r
- } else if( readByte == 0xD ) {\r
- if( filePointer == fileLength - 1 ) {\r
- continue;\r
- } else {\r
- break;\r
- } \r
- }\r
- \r
- sb.append( ( char ) readByte );\r
- }\r
- \r
- String lastLine = sb.reverse().toString();\r
- \r
- fileHandler.close();\r
- return lastLine;\r
- } catch( java.io.FileNotFoundException e ) {\r
- e.printStackTrace();\r
- } catch( java.io.IOException e ) {\r
- e.printStackTrace();\r
- }\r
- return null;\r
- }\r
}\r
b.append(" parameter Integer elements[:];\n");\r
b.append("end Enumeration_class;\n\n");\r
\r
+ // Spreadsheets are built when variables use values from them, so we cannot insert them yet\r
+ int spreadsheetlocation = b.length();\r
+ \r
HashSet<String> sheetNames = new HashSet<String>();\r
for(Sheet sheet : getSpreadSheets(configurations))\r
sheetNames.add(sheet.getName());\r
\r
b.append("end " + modelName + ";\n\n");\r
\r
- b.append(getGlobalSpreadSheets(configurations));\r
- \r
+ // Insert spreadsheets at this point. \r
+ b.insert(spreadsheetlocation, getGlobalSpreadSheets(configurations));\r
\r
+ \r
return b.toString();\r
}\r
\r
\r
@UpdateMethod\r
public boolean updateCells(ReadGraph g, Resource r) throws DatabaseException {\r
- this.resource = r;\r
- \r
- g.getObjects(r, Layer0.getInstance(g).ConsistsOf);\r
- \r
- Variable v = g.adapt(r, Variable.class);\r
cells.clear();\r
usedRanges.clear();\r
- for(Variable child : v.getChildren(g)) {\r
- String name = child.getName(g);\r
- try {\r
- SpreadsheetUtils.decodeCellAbsolute(name);\r
- Variant value = child.getPropertyValue(g, SheetVariables.CONTENT, Bindings.VARIANT);\r
- cells.put(name, value.getValue());\r
- } catch (CellParseException e) {\r
- } catch (MissingVariableException e) {\r
- System.out.println("missing content for: " + name);\r
+ this.resource = null;\r
+\r
+ if(g.hasStatement(r)) {\r
+ this.resource = r;\r
+ g.getObjects(r, Layer0.getInstance(g).ConsistsOf);\r
+ Variable v = g.adapt(r, Variable.class);\r
+ for(Variable child : v.getChildren(g)) {\r
+ String name = child.getName(g);\r
+ try {\r
+ SpreadsheetUtils.decodeCellAbsolute(name);\r
+ Variant value = child.getPropertyValue(g, SheetVariables.CONTENT, Bindings.VARIANT);\r
+ cells.put(name, value.getValue());\r
+ } catch (CellParseException e) {\r
+ } catch (MissingVariableException e) {\r
+ System.out.println("missing content for: " + name);\r
+ }\r
}\r
}\r
return true;\r