Ejemplo n.º 1
0
 // harvest proj file
 public void harvestProj(File f) throws Exception {
   Project proj = new Project("proj", pappl);
   JSReadable r = new JSReadable(f);
   try {
     proj.importXML(r);
     for (int i = 0; i < proj.nChild(); i++) {
       if (!(proj.child(i) instanceof PModel)) continue;
       PModel pmodel = (PModel) proj.child(i);
       String mml = pmodel.modelSource.stringVal();
       processMML(f, pmodel.name(), mml);
     }
   } catch (Exception e) {
     System.out.println("Ignoring read error " + f);
   }
 }
Ejemplo n.º 2
0
  // mainline
  public static final void main(String[] args) throws Exception {

    // parse command line
    if (args.length != 5)
      throw new Xcept(
          "Example2 usage: project-file model input-variable input-value output-variable");
    JSReadable projFile = new JSReadable(args[0]);
    String modelName = args[1];
    String uname = args[2];
    String uvalue = args[3];
    String vname = args[4];

    // load application server and project
    PApplication appl = new PApplication();
    Project proj = new Project("proj", appl);
    proj.importXML(projFile);

    // find and compile model
    PModel pmodel = (PModel) proj.child(modelName);
    PJob pjob = new PModelBuildJob(pmodel);
    pjob.simpleRun();
    ASModel rt = pmodel.rt();

    // set input variable
    ASVar u = rt.getASVar(uname);
    u.setAssign(uvalue);

    // run model
    pjob = new PModelRunJob(pmodel);
    pjob.simpleRun();

    // query output variable
    ASVar v = rt.getASVar(vname);
    Data data = rt.getData(0, v);

    // print output in PrettyFormat
    DataFormat fmt = new PrettyDataFormat();
    DataWriter wrt = fmt.createWriter();
    Data.List list = new Data.List(1);
    list.add(data);
    wrt.writeData(System.out, list);
  }