Search in sources :

Example 1 with MatlabOdeFileCoder

use of cbit.vcell.matlab.MatlabOdeFileCoder in project vcell by virtualcell.

the class MatlabExtensionFilter method writeBioModel.

@Override
public void writeBioModel(DocumentManager documentManager, BioModel model, File exportFile, SimulationContext simulationContext) throws Exception {
    VCAssert.assertValid(simulationContext);
    // matlab from application; get application
    // regenerate a fresh MathDescription
    MathMapping mathMapping = simulationContext.createNewMathMapping();
    MathDescription mathDesc = mathMapping.getMathDescription();
    VCAssert.assertValid(mathDesc);
    VCAssert.assertFalse(mathDesc.isSpatial(), "spatial");
    VCAssert.assertFalse(mathDesc.isNonSpatialStoch(), "stochastic");
    Simulation sim = new Simulation(mathDesc);
    MatlabOdeFileCoder coder = new MatlabOdeFileCoder(sim);
    java.io.StringWriter sw = new java.io.StringWriter();
    java.io.PrintWriter pw = new java.io.PrintWriter(sw);
    String functionName = exportFile.getName();
    if (functionName.endsWith(".m")) {
        functionName = functionName.substring(0, functionName.length() - 2);
    }
    coder.write_V6_MFile(pw, functionName);
    pw.flush();
    pw.close();
    String resultString = sw.getBuffer().toString();
    FileUtils.writeStringToFile(exportFile, resultString);
}
Also used : Simulation(cbit.vcell.solver.Simulation) MathDescription(cbit.vcell.math.MathDescription) MathMapping(cbit.vcell.mapping.MathMapping) MatlabOdeFileCoder(cbit.vcell.matlab.MatlabOdeFileCoder)

Example 2 with MatlabOdeFileCoder

use of cbit.vcell.matlab.MatlabOdeFileCoder in project vcell by virtualcell.

the class ExportDocument method exportMatlab.

/**
 * Insert the method's description here.
 * Creation date: (7/26/2004 12:29:53 PM)
 */
private String exportMatlab(File exportFile, javax.swing.filechooser.FileFilter fileFilter, MathDescription mathDesc) throws ExpressionException, MathException {
    Simulation sim = new Simulation(mathDesc);
    MatlabOdeFileCoder coder = new MatlabOdeFileCoder(sim);
    java.io.StringWriter sw = new java.io.StringWriter();
    java.io.PrintWriter pw = new java.io.PrintWriter(sw);
    String functionName = exportFile.getName();
    if (functionName.endsWith(".m")) {
        functionName = functionName.substring(0, functionName.length() - 2);
    }
    if (fileFilter.getDescription().equals(FileFilters.FILE_FILTER_MATLABV6.getDescription())) {
        coder.write_V6_MFile(pw, functionName);
    }
    pw.flush();
    pw.close();
    return sw.getBuffer().toString();
}
Also used : PrintWriter(java.io.PrintWriter) Simulation(cbit.vcell.solver.Simulation) MatlabOdeFileCoder(cbit.vcell.matlab.MatlabOdeFileCoder) PrintWriter(java.io.PrintWriter)

Aggregations

MatlabOdeFileCoder (cbit.vcell.matlab.MatlabOdeFileCoder)2 Simulation (cbit.vcell.solver.Simulation)2 MathMapping (cbit.vcell.mapping.MathMapping)1 MathDescription (cbit.vcell.math.MathDescription)1 PrintWriter (java.io.PrintWriter)1