use of cbit.vcell.solvers.FunctionFileGenerator in project vcell by virtualcell.
the class FunctionFileCrawler method scan.
/**
* Insert the method's description here.
* Creation date: (2/2/01 3:40:29 PM)
*/
private void scan(File userDir, File outputDir) throws Exception {
File outputFile = null;
java.io.PrintWriter pw = null;
try {
outputFile = new File(outputDir, "FunctionFileCrawler_" + userDir.getName() + ".txt");
pw = new java.io.PrintWriter(new java.io.FileOutputStream(outputFile));
//
// file filter for *.functions files
//
java.io.FilenameFilter functionFileFilter = new java.io.FilenameFilter() {
public boolean accept(File dir, String name) {
return name.endsWith(".functions");
}
};
// find all the log files
File[] functionFiles = userDir.listFiles(functionFileFilter);
// loop through all the functions files
int filesWithSpaceInNames = 0;
for (int i = 0; i < functionFiles.length; i++) {
File fnFile = functionFiles[i];
if (fnFile.exists()) {
// read the functions from the function files and and check if they have spaces
Vector<AnnotatedFunction> annotatedFnsVector = FunctionFileGenerator.readFunctionsFile(fnFile, null);
boolean bNameHasSpaces = false;
for (int j = 0; j < annotatedFnsVector.size(); j++) {
AnnotatedFunction afn = annotatedFnsVector.elementAt(j);
if (afn.getName().indexOf(" ") > 0) {
// if function name has space, mangle the name and store the function in a different list.
bNameHasSpaces = true;
String newName = TokenMangler.fixTokenStrict(afn.getName());
annotatedFnsVector.set(j, new AnnotatedFunction(newName, afn.getExpression(), afn.getDomain(), afn.getErrorString(), afn.getFunctionType(), afn.getFunctionCatogery()));
} else {
annotatedFnsVector.set(j, afn);
}
}
// If function file had function(s) with space(s), need to rewrite function file
if (bNameHasSpaces) {
FunctionFileGenerator ffg = new FunctionFileGenerator(fnFile.getPath(), annotatedFnsVector);
ffg.generateFunctionFile();
filesWithSpaceInNames++;
totalNumOfFilesModified++;
}
} else {
System.err.println("Function file : " + fnFile.getName() + " does not exist.");
}
}
System.out.println("NUM Files with spaces in names : " + filesWithSpaceInNames + "; NUM Files with No spaces in names : " + (functionFiles.length - filesWithSpaceInNames));
} finally {
if (pw != null) {
pw.close();
}
if (lg.isTraceEnabled())
lg.trace("User " + userDir.getName() + ", See " + outputFile.getAbsolutePath() + " for details");
}
}
Aggregations