ngmf.ui.mms.MmsParamsReader Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of oms Show documentation
Show all versions of oms Show documentation
Object Modeling System (OMS) is a pure Java object-oriented framework.
OMS v3.+ is a highly interoperable and lightweight modeling framework for component-based model and simulation development on multiple platforms.
/*
* $Id: MmsParamsReader.java 50798ee5e25c 2013-01-09 [email protected] $
*
* This file is part of the Object Modeling System (OMS),
* 2007-2012, Olaf David and others, Colorado State University.
*
* OMS is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, version 2.1.
*
* OMS is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with OMS. If not, see .
*/
package ngmf.ui.mms;
import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;
import java.util.StringTokenizer;
import java.util.logging.Logger;
public class MmsParamsReader {
private FileReader file;
private Logger log;
private String fileName;
private ParameterSet mps;
public MmsParamsReader(String fileName) throws IOException {
this(new FileReader(fileName), Logger.getLogger(MmsParamsReader.class.getName()));
this.fileName = fileName;
}
public MmsParamsReader(FileReader file) throws IOException {
this (file, Logger.getLogger(MmsParamsReader.class.getName()));
}
public MmsParamsReader(FileReader file, Logger log) throws IOException {
this.file = file;
this.log = log;
}
public ParameterSet read() throws IOException {
mps = new MmsParameterSet();
mps.setFileName(fileName);
/*
* Read dimensions
*/
String line;
BufferedReader in = null;
try {
in = new BufferedReader(file);
mps.setDescription(in.readLine());
mps.setVersion(in.readLine());
line = in.readLine();
/*
* Read Dimensions
*/
while (line != null) {
if (line.equals("** Parameters **")) {
break;
} else if (line.startsWith(" 1) {
dims[1] = (MmsDimension)(mps.getDimension(dim2));
}
mps.addParameter(new MmsParameter(name, width, dims, type_class, vals));
line = in.readLine();
line = in.readLine();
}
} catch (IOException ex) {
log.severe("Problem reading parameters");
ex.printStackTrace();
throw ex;
} catch (NumberFormatException ex) {
log.severe("NumberFormatException while reading parameters");
} finally {
try {
if (in!= null) {
in.close();
in = null;
}
} catch (IOException E) {}
}
if (mps.getDims().isEmpty() && mps.getParams().isEmpty()) {
mps = null;
throw (new IOException ("Invalid MMS parameter file."));
}
return mps;
}
public static void main(String arg[]) {
try {
MmsParamsReader mp = new MmsParamsReader(new FileReader(arg[0]));
ParameterSet ps = mp.read();
System.out.println ("Dimensions = " + ps.getDims());
System.out.println ("Parameters = " + ps.getParams());
} catch (java.io.FileNotFoundException e) {
System.out.println(arg[0] + " not found");
} catch (IOException e) {
System.out.println(arg[0] + " io exception");
}
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy