Location: Metabolic Component Library @ 38fe44af096f / CellML-source / CellMLTools / src / componentlibrary / CodeGeneratorTest.java

Author:
Randall Britten <r.britten@auckland.ac.nz>
Date:
2013-04-17 15:40:27+12:00
Desc:
Trivial whitespace changes, and moved import to be adjacent to peer import.
Permanent Source URI:
https://models.cellml.org/w/matthiaskoenig/MetabolicComponentLibrary/rawfile/38fe44af096fb53d9b250091fe0563b33b5f778f/CellML-source/CellMLTools/src/componentlibrary/CodeGeneratorTest.java

package componentlibrary;

import tools.CellMLReader;
import cellml_api.CellMLBootstrap;
import cellml_api.Model;
import cellml_services.CodeGenerator;
import cellml_services.CodeGeneratorBootstrap;
import cellml_services.CodeInformation;
import cellml_services.IDACodeGenerator;

/** Generate C & Python Code from a given model */
public class CodeGeneratorTest {

	/* Use CCGS to generate code analog to 
	* 		CellML2C.cpp
	* 		CellML2Python.cpp
	*/
	private static void generateCode(Model model, boolean useida){
		System.loadLibrary("java_ccgs");
		CodeGeneratorBootstrap cgBootstrap = cellml_bootstrap.CCGSBootstrap.createCodeGeneratorBootstrap();
		
		model.fullyInstantiateImports();
		CodeInformation codeInfo = null;
		if (useida){
			CodeGenerator cg = cgBootstrap.createCodeGenerator();
			codeInfo = cg.generateCode(model);
		} else {
			IDACodeGenerator cgida = cgBootstrap.createIDACodeGenerator();
			codeInfo = cgida.generateCode(model);
		}
		
		// print errors
		String error = codeInfo.getErrorMessage();
		if (error!=null && error.length()>0){
			System.err.println("Code generation error: " + error);
			return;
		}
		
		//the usenames stuff form CellML2C & VellML2Python
		// -> doNameAnnotations()
		
		// How to write the code ???
		System.out.println("*** Code Generated ***");
		System.out.println("NONE: " +  codeInfo.toString());
		
		// String code = ??	
		// uses the -> WriteCode() functions in CellML2C & CellML2Python
		// but not accessible via the API ?
	}
	
	
	public static void main (String[] args){
		System.loadLibrary("java_cellml");
	    CellMLBootstrap bootstrap =  cellml_bootstrap.CellMLBootstrap.createCellMLBootstrap();
		Model model = CellMLReader.loadFromURL(bootstrap, "MassActionBiBiRev.cellml");
		generateCode(model, true);
	}
}