/* * ReadBatchInput.java * * Created on 04 January 2005, 18:17 */ import java.io.*; import java.util.regex.*; import java.util.*; import java.util.Iterator.*; /** * * @author mnaylor */ public class ReadBatchInput2 { /** * HashMap containing all the default and values input from batch file */ public static HashMap parameterMap; /** * FileReader for the batch input file */ public static FileReader fr; private static File file; private static String path; private static BufferedReader in; private static String [] header; private static Object beta, minStrength, maxStrength, usePeriodicBC, runtimeDuration; private static Object Nx, maxStressRelaxationFactor, loadingMechanism, percentageNoise; private static Object neighbourNumber, asymmetricFactor; private static String boundaryCondition; private static String fileNameRoot; // public static GarathsAutonome world; /** * Open batch file, read header and process */ public static void openAndInitiateBatchFile(){ openBatchInputFile(); readHeader(); } private static void init(){ Nx = "100"; neighbourNumber = "4"; fileNameRoot = "a"; beta = "0.2"; minStrength = "1.0"; maxStrength = "1.0"; usePeriodicBC = "false" ; loadingMechanism = "constantLoading"; runtimeDuration = "20000"; maxStressRelaxationFactor = "0"; percentageNoise = "0"; asymmetricFactor = "1"; parameterMap.put("Nx", Nx); parameterMap.put("neighbourNumber", neighbourNumber); parameterMap.put("fileNameRoot", fileNameRoot); parameterMap.put("beta", beta); parameterMap.put("maxStrength", maxStrength); parameterMap.put("minStrength", minStrength); parameterMap.put("loadingMechanism", loadingMechanism); parameterMap.put("usePeriodicBC", usePeriodicBC); parameterMap.put("runtimeDuration", runtimeDuration); parameterMap.put("maxStressRelaxationFactor", maxStressRelaxationFactor); parameterMap.put("percentageNoise", percentageNoise); parameterMap.put("asymmetricFactor", asymmetricFactor); } /** Creates a new instance of ReadBatchInput */ public ReadBatchInput2(String batchFileName) { parameterMap = new HashMap (); init(); // path = "/home/mnaylor/Java/AutomatonViewer/Batch/"; path = System.getProperty("user.dir"); System.out.println(path); file = new File (path + "/" + batchFileName); if (!file.exists()){ System.out.println("File " + file + " does not exist"); } else { openBatchInputFile(); readHeader(); } } private static void printRunDetails (){ try{ fileNameRoot = parameterMap.get("fileNameRoot").toString(); File detailsFile = new File (fileNameRoot + "-details.out"); FileWriter fwDetails = new FileWriter ( detailsFile ); Collection parameterMapValues = parameterMap.values(); Set parameterMapKeys = parameterMap.keySet(); Iterator iterator = parameterMapKeys.iterator(); Iterator collectionIterator = parameterMapValues.iterator(); while (iterator.hasNext()){ fwDetails.write(iterator.next() + " = " + collectionIterator.next() + "\n"); } fwDetails.close(); } catch ( IOException e ) { System.out.println("Cannot output run details to file"); } } /** * Reads next batch file entry and runs autonome accordingly */ public static void readNextBatchEntry (){ try { String nextLine; if ( (nextLine = in.readLine()) != null) { String [] fields = nextLine.split ( "," ); trimStringEntries (fields); setParameterMap(fields); printRunDetails(); } else{ System.out.println("End of file."); System.exit(0); } } catch ( IOException e ) { System.out.println("Cannot read and print batchInputFile"); } } private static void setParameterMap(String [] fields){ for (int n = 0; n