Example #1
1
  // ## operation writeChemkinSpecies(ReactionModel,SystemSnapshot)
  public static String writeChemkinSpecies(
      ReactionModel p_reactionModel, SystemSnapshot p_beginStatus) {
    // #[ operation writeChemkinSpecies(ReactionModel,SystemSnapshot)

    StringBuilder result = new StringBuilder();
    result.append("SPECIES\n");

    CoreEdgeReactionModel cerm = (CoreEdgeReactionModel) p_reactionModel;

    // write inert gas
    for (Iterator iter = p_beginStatus.getInertGas(); iter.hasNext(); ) {
      String name = (String) iter.next();
      result.append('\t' + name + '\n');
    }

    // write species
    for (Iterator iter = cerm.getSpecies(); iter.hasNext(); ) {
      Species spe = (Species) iter.next();
      result.append('\t' + spe.getChemkinName() + '\n');
    }

    result.append("END\n");

    return result.toString();

    // #]
  }
Example #2
0
 public void display(Graphics2D g, AffineTransform a_trans) {
   Iterator i = createIterator();
   while (i.hasNext()) {
     GlyphObject object = (GlyphObject) i.next();
     object.display(g, a_trans);
   } // while
 }
Example #3
0
  // ## operation writeChemkinReactions(ReactionModel)
  // 10/26/07 gmagoon: changed to take temperature as parameter (it doesn't seem like this method is
  // currently used anywhere)
  public static String writeChemkinReactions(
      ReactionModel p_reactionModel, Temperature p_temperature) {
    // #[ operation writeChemkinReactions(ReactionModel)
    StringBuilder result = new StringBuilder();
    result.append("REACTIONS	KCAL/MOLE\n");
    CoreEdgeReactionModel cerm = (CoreEdgeReactionModel) p_reactionModel;

    LinkedHashSet all = cerm.getReactedReactionSet();

    HashSet hs = new HashSet();
    int numfor = 0;
    int numrev = 0;
    int numdup = 0;
    int numnorev = 0;
    for (Iterator iter = all.iterator(); iter.hasNext(); ) {
      Reaction rxn = (Reaction) iter.next();
      if (rxn.isForward()) {
        result.append(
            " "
                + rxn.toChemkinString(p_temperature)
                + "\n"); // 10/26/07 gmagoon: changed to avoid use of Global.temperature
        //	result.append(" " + rxn.toChemkinString(Global.temperature) + "\n");

      }
    }

    result.append("END\n");

    return result.toString();

    // #]
  }
Example #4
0
  /**
   * Reload the composite nodes of the circuit, this is recursive
   *
   * @param g the graphics that will paint the node
   * @throws CircuitLoadingException if the internal circuit can not be loaded
   */
  public void reloadCompositeNodes(Graphics g) throws CircuitLoadingException {
    for (iterNodes = this.nodes.iterator(); iterNodes.hasNext(); ) {
      Node n = iterNodes.next();

      if (n.getCategoryID() == Node.COMPOSITE) ((CompositeNode) n).reload(g);
    }
  }
Example #5
0
  public void selectNext() {
    Iterator i = new SelectionIterator(this);

    if (m_actives.size() == 1) {
      boolean isFound = false;

      // loop the iterator in reverse order of drawing
      while (i.hasNext()) {
        GlyphObject object = (GlyphObject) i.next();

        if (m_actives.isSelected(object)) {
          isFound = true;
          continue;
        } // if

        if (!isFound) {
          continue;
        } // if

        m_actives.unselectAll();
        m_actives.addActive(object);
        return;
      } // while i
    } // if

    i = new SelectionIterator(this);
    if (i.hasNext()) {
      GlyphObject object = (GlyphObject) i.next();
      m_actives.unselectAll();
      m_actives.addActive(object);
      return;
    } // if
  }
Example #6
0
 public EdgeLayout getEdgeLayouts(String spid, String sid, String tpid, String tid) {
   Iterator<EdgeLayout> ee = edges.iterator();
   EdgeLayout el;
   while (ee.hasNext()) {
     el = ee.next();
     if (el.sourceNode.equals(sid) && el.targetNode.equals(tid)) {
       return el;
     }
   }
   return null;
 } // */
Example #7
0
  /**
   * Get the inputable nodes of the circuit
   *
   * @return an hashset of the inputable nodes of the circuit
   */
  public HashSet<Inputable> getInputables() {
    HashSet<Inputable> inputs = new HashSet<Inputable>();

    for (iterNodes = getNodesIterator(); iterNodes.hasNext(); ) {
      Node n = iterNodes.next();

      if (n.getCategoryID() == Node.INPUT) inputs.add((Inputable) n);
    }

    return inputs;
  }
Example #8
0
  /**
   * Get the outputable nodes of the circuit
   *
   * @return an hashset of the outputable nodes of the circuit
   */
  public HashSet<Outputable> getOutputables() {
    HashSet<Outputable> outputs = new HashSet<Outputable>();

    for (iterNodes = getNodesIterator(); iterNodes.hasNext(); ) {
      Node n = iterNodes.next();

      if (n.getCategoryID() == Node.OUTPUT) outputs.add((Outputable) n);
    }

    return outputs;
  }
Example #9
0
  protected void doGet(HttpServletRequest req, HttpServletResponse res)
      throws ServletException, IOException {
    try {
      DateFormat df = DateFormat.getDateTimeInstance();
      String titleStr = "C3P0 Status - " + df.format(new Date());

      DocumentBuilderFactory fact = DocumentBuilderFactory.newInstance();
      DocumentBuilder db = fact.newDocumentBuilder();
      Document doc = db.newDocument();

      Element htmlElem = doc.createElement("html");
      Element headElem = doc.createElement("head");

      Element titleElem = doc.createElement("title");
      titleElem.appendChild(doc.createTextNode(titleStr));

      Element bodyElem = doc.createElement("body");

      Element h1Elem = doc.createElement("h1");
      h1Elem.appendChild(doc.createTextNode(titleStr));

      Element h3Elem = doc.createElement("h3");
      h3Elem.appendChild(doc.createTextNode("PooledDataSources"));

      Element pdsDlElem = doc.createElement("dl");
      pdsDlElem.setAttribute("class", "PooledDataSources");
      for (Iterator ii = C3P0Registry.getPooledDataSources().iterator(); ii.hasNext(); ) {
        PooledDataSource pds = (PooledDataSource) ii.next();
        StatusReporter sr = findStatusReporter(pds, doc);
        pdsDlElem.appendChild(sr.reportDtElem());
        pdsDlElem.appendChild(sr.reportDdElem());
      }

      headElem.appendChild(titleElem);
      htmlElem.appendChild(headElem);

      bodyElem.appendChild(h1Elem);
      bodyElem.appendChild(h3Elem);
      bodyElem.appendChild(pdsDlElem);
      htmlElem.appendChild(bodyElem);

      res.setContentType("application/xhtml+xml");

      TransformerFactory tf = TransformerFactory.newInstance();
      Transformer transformer = tf.newTransformer();
      Source src = new DOMSource(doc);
      Result result = new StreamResult(res.getOutputStream());
      transformer.transform(src, result);
    } catch (IOException e) {
      throw e;
    } catch (Exception e) {
      throw new ServletException(e);
    }
  }
Example #10
0
 public String toString() {
   StringBuffer sb = new StringBuffer();
   sb.append(sourcepid + "," + sourceNode + "," + targetpid + "," + targetNode + ",");
   Iterator<LayoutPoint> e = bends.iterator();
   LayoutPoint b;
   while (e.hasNext()) {
     b = (LayoutPoint) e.next();
     sb.append(b.x + "," + b.y + ",");
   }
   sb.append("\n");
   return sb.toString();
 }
Example #11
0
 public String toBeautifiedString() {
   StringBuffer sb = new StringBuffer();
   sb.append("sourcePID: " + sourcepid);
   sb.append("  sourceNodeId: " + sourceNode + "\n");
   sb.append("  targetPID: " + targetpid);
   sb.append("  targetNodeId: " + targetNode + "\n");
   Iterator<LayoutPoint> e = bends.iterator();
   LayoutPoint b;
   while (e.hasNext()) {
     b = (LayoutPoint) e.next();
     sb.append(" Bend Points: " + b.x + "," + b.y + "  ");
   }
   sb.append("\n\n");
   return sb.toString();
 }
Example #12
0
  /**
   * converts this glyph into Shape. It could be called for root's preview mode or by include
   * invoke. Pushing either this GlyphFile or DIncludeInvoke should be handled before this.
   */
  public Shape toShape(AffineTransform a_trans) {

    int ppem = k_defaultPixelSize;

    GeneralPath retval = new GeneralPath();
    Iterator i = createIterator();
    while (i.hasNext()) {
      GlyphObject object = (GlyphObject) i.next();

      if (object instanceof EContourPoint || object instanceof EHint) {
        continue;
      } // if

      retval.append(object.toShape(a_trans, ppem), false);
    } // if

    return retval;
  }
Example #13
0
  /**
   * Save the XML description of the circuit
   *
   * @param output an output stream to write in
   * @return true if the dump was successful, false either
   */
  public boolean dumpToXml(OutputStream output) {
    Document doc;
    Element root;

    DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
    DocumentBuilder builder;

    try {
      builder = factory.newDocumentBuilder();
      doc = builder.newDocument();
    } catch (ParserConfigurationException pce) {
      System.err.println("dumpToXmlFile: unable to write XML save file.");
      return false;
    }

    root = doc.createElement("Circuit");
    root.setAttribute("name", this.getName());

    for (iterNodes = this.nodes.iterator(); iterNodes.hasNext(); )
      iterNodes.next().dumpToXml(doc, root);

    root.normalize();
    doc.appendChild(root);

    try {
      TransformerFactory tffactory = TransformerFactory.newInstance();
      Transformer transformer = tffactory.newTransformer();
      transformer.setOutputProperty(OutputKeys.INDENT, "yes");
      DOMSource source = new DOMSource(doc);
      StreamResult result = new StreamResult(output);
      transformer.transform(source, result);
    } catch (TransformerConfigurationException tce) {
      System.err.println("dumpToXmlFile:  Configuration Transformer exception.");
      return false;
    } catch (TransformerException te) {
      System.err.println("dumpToXmlFile: Transformer exception.");
      return false;
    }

    return true;
  }
Example #14
0
  public void flipLayoutLeftRight() {
    LayoutBox box = getExactLayoutBox();
    Iterator<NodeLayout> ne = nodes.iterator();
    while (ne.hasNext()) {
      NodeLayout nl = ne.next();
      if (nl.processID.equals("null")) {
        nl.x =
            box.topleft.x
                + (box.width - (nl.x - box.topleft.x))
                - 60; // minus 60 which is the width of process node's box, since using upperleft
                      // coor
      } else if (isSecondary(nl)) {
        nl.x = box.topleft.x + (box.width - (nl.x - box.topleft.x)) - 60;
      } else {
        nl.x = box.topleft.x + (box.width - (nl.x - box.topleft.x)) - 20;
      }
    }

    Iterator<EdgeLayout> e2 = edges.iterator();
    EdgeLayout el;
    while (e2.hasNext()) {
      el = e2.next();
      for (LayoutPoint lp : el.bends) {
        lp.x = box.topleft.x + (box.width - (lp.x - box.topleft.x));
      }
    }
  }
Example #15
0
  // convert coordinates to relative coordinates with the top-left one as (0,0)
  public void convertToRelativePositions() {
    LayoutBox box = getExactLayoutBox();
    // System.out.println("Box
    // ("+box.topleft.x+","+box.topleft.y+");("+(box.topleft.x+box.width)+","+(box.topleft.y+box.height));
    Iterator<NodeLayout> e = nodes.iterator();
    NodeLayout nl;
    while (e.hasNext()) {
      nl = e.next();
      /* Debug code
      if(nl.x<box.topleft.x || nl.y<box.topleft.y || nl.x>(box.topleft.x+box.width) || nl.y>(box.topleft.y+box.height)){

          System.out.println("Invalid node     "+nl.x+","+nl.y);
      }
      //*/
      nl.x = nl.x - box.topleft.x;
      nl.y = nl.y - box.topleft.y;
    }

    Iterator<EdgeLayout> e2 = edges.iterator();
    EdgeLayout el;
    while (e2.hasNext()) {
      el = e2.next();
      for (LayoutPoint lp : el.bends) {
        lp.x = lp.x - box.topleft.x;
        lp.y = lp.y - box.topleft.y;
      }
    }
  }
Example #16
0
  private boolean hitObjects(Rectangle2D a_rect, boolean a_isSelectOnlyOne) {
    boolean retval = false;

    Iterator i = new SelectionIterator(this);

    // loop the iterator in reverse order of drawing
    while (i.hasNext()) {
      GlyphObject object = (GlyphObject) i.next();

      if (!object.hit(a_rect, new AffineTransform())) {
        continue;
      } // if

      retval = true;

      if (a_isSelectOnlyOne) {
        return true;
      } // if
    } // while i

    return retval;
  }
Example #17
0
  /**
   * Make the circuit for simulation
   *
   * @return the equivalent circuit
   */
  public Circuit makeSimulationCircuit() {
    this.circuit = new Circuit();
    this.wirestable = new Hashtable<Link, Wire>();
    this.inputstable = new Hashtable<Node, Input>();
    this.outputstable = new Hashtable<Node, Output>();

    for (iterLinks = this.links.iterator(); iterLinks.hasNext(); )
      this.wirestable.put(iterLinks.next(), new Wire(this.circuit));

    for (iterNodes = this.nodes.iterator(); iterNodes.hasNext(); ) {
      Node n = iterNodes.next();
      Actor a = n.makeSimulationNode(this);

      if (a instanceof Input) {
        this.inputstable.put(n, (Input) a);
        this.circuit.addInput((Input) a);
      } else if (n instanceof OutputUI) {
        this.outputstable.put(n, (Output) a);
        this.circuit.addOutput((Output) a);
      }
    }

    return this.circuit;
  }
Example #18
0
  public static String writeGridOfRateCoeffs(ReactionModel p_reactionModel) {

    StringBuilder result = new StringBuilder();

    LinkedList pDepList = new LinkedList();
    CoreEdgeReactionModel cerm = (CoreEdgeReactionModel) p_reactionModel;

    for (Iterator iter = PDepNetwork.getNetworks().iterator(); iter.hasNext(); ) {
      PDepNetwork pdn = (PDepNetwork) iter.next();
      for (ListIterator pdniter = pdn.getNetReactions().listIterator(); pdniter.hasNext(); ) {
        PDepReaction rxn = (PDepReaction) pdniter.next();
        if (cerm.categorizeReaction(rxn) != 1) continue;
        // check if this reaction is not already in the list and also check if this reaction has a
        // reverse reaction
        // which is already present in the list.
        if (rxn.getReverseReaction() == null) rxn.generateReverseReaction();
        if (!rxn.reactantEqualsProduct()
            && !pDepList.contains(rxn)
            && !pDepList.contains(rxn.getReverseReaction())) {
          pDepList.add(rxn);
        }
      }
    }

    Temperature[] tempsUsedInFame = PDepRateConstant.getTemperatures();
    int numTemps = tempsUsedInFame.length;
    Pressure[] pressUsedInFame = PDepRateConstant.getPressures();
    int numPress = pressUsedInFame.length;

    for (int i = 0; i < numTemps; i++) {
      for (int j = 0; j < numPress; j++) {
        result.append(
            "T=" + tempsUsedInFame[i].getK() + "K,P=" + pressUsedInFame[j].getBar() + "bar\t");
      }
      result.append("\n");
    }
    result.append("\n");

    for (Iterator iter = pDepList.iterator(); iter.hasNext(); ) {
      PDepReaction r = (PDepReaction) iter.next();
      result.append(r.toString() + "\n");
      double[][] rates = new double[numTemps][numPress];
      rates = r.getPDepRate().getRateConstants();
      for (int i = 0; i < numTemps; i++) {
        for (int j = 0; j < numPress; j++) {
          result.append(rates[i][j] + "\t");
        }
        result.append("\n");
      }
      result.append("\n");
    }
    return result.toString();
  }
Example #19
0
 public String toString() {
   if (isEmpty()) {
     return "";
   }
   StringBuffer sb = new StringBuffer();
   Iterator<NodeLayout> e = nodes.iterator();
   while (e.hasNext()) sb.append((e.next()).toString());
   sb.append("\n");
   Iterator<EdgeLayout> ee = edges.iterator();
   while (ee.hasNext()) sb.append((ee.next()).toString());
   return sb.toString();
 }
Example #20
0
  public String toBeautifiedString() {
    StringBuffer sb = new StringBuffer();

    Iterator<NodeLayout> e = nodes.iterator();
    while (e.hasNext()) sb.append((e.next()).toBeautifiedString());
    sb.append("\n");
    Iterator<EdgeLayout> ee = edges.iterator();
    while (ee.hasNext()) {
      sb.append((ee.next()).toBeautifiedString());
    }

    sb.append("\n\nNumber of Nodes: ");
    sb.append(nodes.size());
    sb.append("\nNumber of Edges: ");
    sb.append(edges.size() + "\n");

    return sb.toString();
  }
Example #21
0
  // convert coordinates to shifted coordinates with the top-left one as (xs,ys)
  public void convertToShiftedPositions(double xs, double ys) {
    convertToRelativePositions();
    Iterator<NodeLayout> e = nodes.iterator();
    NodeLayout nl;
    while (e.hasNext()) {
      nl = e.next();
      nl.x += xs;
      nl.y += ys;
    }

    Iterator<EdgeLayout> e2 = edges.iterator();
    EdgeLayout el;
    while (e2.hasNext()) {
      el = e2.next();
      for (LayoutPoint lp : el.bends) {
        lp.x += xs;
        lp.y += ys;
      }
    }
  }
Example #22
0
  public void flipLayoutUpDown() {
    LayoutBox box = getExactLayoutBox();
    Iterator<NodeLayout> ne = nodes.iterator();
    while (ne.hasNext()) {
      NodeLayout nl = ne.next();
      if (isSecondary(nl)) {
        nl.y = box.topleft.y + (box.height - (nl.y - box.topleft.y)) - 12;
      } else {
        nl.y = box.topleft.y + (box.height - (nl.y - box.topleft.y)) - 20;
      }
    }

    Iterator<EdgeLayout> e2 = edges.iterator();
    EdgeLayout el;
    while (e2.hasNext()) {
      el = e2.next();
      for (LayoutPoint lp : el.bends) {
        lp.y = box.topleft.y + (box.height - (lp.y - box.topleft.y));
      }
    }
  }
Example #23
0
  public void filpLayoutUpDown() {
    LayoutBox box = getExactLayoutBox();
    Iterator<NodeLayout> ne = nodes.iterator();
    while (ne.hasNext()) {
      NodeLayout nl = ne.next();
      if (nl.cofactor.equalsIgnoreCase("true")) {
        nl.y = box.topleft.y + (box.height - (nl.y - box.topleft.y)) - 12;
      } else {
        nl.y = box.topleft.y + (box.height - (nl.y - box.topleft.y)) - 20;
      }
    }

    Iterator<EdgeLayout> e2 = edges.iterator();
    EdgeLayout el;
    while (e2.hasNext()) {
      el = e2.next();
      for (LayoutPoint lp : el.bends) {
        lp.y = box.topleft.y + (box.height - (lp.y - box.topleft.y));
      }
    }
  }
Example #24
0
 // Return the shared nodes(with the same node id) with the other LayoutInfo
 public LinkedHashMap<NodeLayout, NodeLayout> sharedNodes(LayoutInfo info2) {
   LinkedHashMap<NodeLayout, NodeLayout> shared = new LinkedHashMap<NodeLayout, NodeLayout>();
   Iterator<NodeLayout> e = nodes.iterator();
   while (e.hasNext()) {
     NodeLayout nl = e.next();
     if (nl.cofactor.equalsIgnoreCase("true")) {
       continue;
     }
     NodeLayout nl2;
     Iterator<NodeLayout> e2 = info2.nodes.iterator();
     while (e2.hasNext()) {
       nl2 = e2.next();
       if (nl2.cofactor.equalsIgnoreCase("true")) {
         continue;
       }
       if (nl.nodeID.equals(nl2.nodeID)) {
         shared.put(nl, nl2);
       }
     }
   }
   return shared;
 }
Example #25
0
  // ## operation writeChemkinReactions(ReactionModel)
  public static String writeChemkinPdepReactions(
      ReactionModel p_reactionModel, SystemSnapshot p_beginStatus) {
    // #[ operation writeChemkinReactions(ReactionModel)

    StringBuilder result = new StringBuilder();
    //      result.append("REACTIONS	KCAL/MOLE\n");

    String reactionHeader = "";

    String units4Ea = ArrheniusKinetics.getEaUnits();
    if (units4Ea.equals("cal/mol")) reactionHeader = "CAL/MOL\t";
    else if (units4Ea.equals("kcal/mol")) reactionHeader = "KCAL/MOL\t";
    else if (units4Ea.equals("J/mol")) reactionHeader = "JOULES/MOL\t";
    else if (units4Ea.equals("kJ/mol")) reactionHeader = "KJOULES/MOL\t";
    else if (units4Ea.equals("Kelvins")) reactionHeader = "KELVINS\t";

    String units4A = ArrheniusKinetics.getAUnits();
    if (units4A.equals("moles")) reactionHeader += "MOLES\n";
    else if (units4A.equals("molecules")) reactionHeader += "MOLECULES\n";

    result.append("REACTIONS\t" + reactionHeader);

    LinkedList pDepList = new LinkedList();
    LinkedList nonPDepList = new LinkedList();
    LinkedList duplicates = new LinkedList();

    CoreEdgeReactionModel cerm = (CoreEdgeReactionModel) p_reactionModel;
    // first get troe and thirdbodyreactions
    for (Iterator iter = cerm.getReactionSet().iterator(); iter.hasNext(); ) {
      Reaction r = (Reaction) iter.next();
      /*
       * 1Jul2009-MRH:
       * 	Added extra set of parenthesis.  Before, if the rxn was reverse but an instance of
       * 		TROEReaction, it would also be added to the pDepList, resulting in RMG reporting
       * 		both rxns (forward and reverse) in the chem.inp file, w/o a DUP tag.  Furthermore,
       * 		both rxns were given the same set of Arrhenius parameters.  Running this in
       * 		Chemkin-v4.1.1 resulted in an error.
       */
      if (r.isForward()
          && (r instanceof ThirdBodyReaction
              || r instanceof TROEReaction
              || r instanceof LindemannReaction)) {
        pDepList.add(r);
      }
    }

    for (Iterator iter = PDepNetwork.getNetworks().iterator(); iter.hasNext(); ) {
      PDepNetwork pdn = (PDepNetwork) iter.next();
      for (ListIterator pdniter = pdn.getNetReactions().listIterator(); pdniter.hasNext(); ) {
        PDepReaction rxn = (PDepReaction) pdniter.next();
        if (cerm.categorizeReaction(rxn) != 1) continue;

        // check if this reaction is not already in the list and also check if this reaction has a
        // reverse reaction
        // which is already present in the list.
        if (rxn.getReverseReaction() == null) rxn.generateReverseReaction();

        if (!rxn.reactantEqualsProduct()
            && !pDepList.contains(rxn)
            && !pDepList.contains(rxn.getReverseReaction())) {
          pDepList.add(rxn);
        }
      }
    }
    LinkedList removeReactions = new LinkedList();
    for (Iterator iter = p_reactionModel.getReactionSet().iterator(); iter.hasNext(); ) {
      Reaction r = (Reaction) iter.next();

      boolean presentInPDep = false;
      if (r.isForward()
          && !(r instanceof ThirdBodyReaction)
          && !(r instanceof TROEReaction)
          && !(r instanceof LindemannReaction)) {
        Iterator r_iter = pDepList.iterator();
        while (r_iter.hasNext()) {
          Reaction pDepr = (Reaction) r_iter.next();
          if (pDepr.equals(r)) {
            //      				removeReactions.add(pDepr);
            //      				duplicates.add(pDepr);
            //      				if (!r.hasAdditionalKinetics()){
            //      					duplicates.add(r);
            //      					presentInPDep = true;
            //      				}
            presentInPDep = true;
            nonPDepList.add(r);
          }
        }
        if (!presentInPDep) nonPDepList.add(r);
      }
    }

    for (Iterator iter = removeReactions.iterator(); iter.hasNext(); ) {
      Reaction r = (Reaction) iter.next();
      pDepList.remove(r);
    }

    for (Iterator iter = pDepList.iterator(); iter.hasNext(); ) {
      Reaction r = (Reaction) iter.next();
      // 6Jul2009-MRH:
      //	Pass both system temperature and pressure to function toChemkinString.
      //		The only PDepKineticsModel that uses the passed pressure is RATE
      result.append(
          r.toChemkinString(p_beginStatus.getTemperature(), p_beginStatus.getPressure())
              + "\n"); // 10/26/07 gmagoon: eliminating use of Global.temperature; **** I use
                       // beginStatus here, which may or may not be appropriate
      // result.append(r.toChemkinString(Global.temperature)+"\n");
    }
    for (Iterator iter = nonPDepList.iterator(); iter.hasNext(); ) {
      Reaction r = (Reaction) iter.next();
      result.append(
          r.toChemkinString(p_beginStatus.getTemperature(), p_beginStatus.getPressure()) + "\n");
      // result.append(r.toChemkinString(Global.temperature)+"\n");
    }
    for (Iterator iter = duplicates.iterator(); iter.hasNext(); ) {
      Reaction r = (Reaction) iter.next();
      result.append(
          r.toChemkinString(p_beginStatus.getTemperature(), p_beginStatus.getPressure())
              + "\n\tDUP\n");
      // result.append(r.toChemkinString(Global.temperature)+"\n\tDUP\n");
    }

    result.append("END\n");

    return result.toString();

    // #]
  }
Example #26
0
  public void CrawlRT(String RTPage) throws IOException {
    ArrayList<String> t = new ArrayList<String>();
    String crawlData;
    String crawlData2;
    String crawlData3;

    FileReader freader = new FileReader("Crawl.txt");
    BufferedReader br = new BufferedReader(freader);
    FileReader freader2 = new FileReader("Tocrawl.txt");
    BufferedReader br2 = new BufferedReader(freader2);
    FileWriter fwriter2 = new FileWriter("Tocrawl.txt", true);
    BufferedWriter bw2 = new BufferedWriter(fwriter2);
    FileWriter fwriter = new FileWriter("Crawl.txt", true);
    BufferedWriter bw = new BufferedWriter(fwriter);

    /*while(null != (crawlData2 = br.readLine()))
    {
    	if(crawlData2 !=null)
    		Crawl.add(crawlData2);
    }
    t = collectLinks(RTPage);
    Iterator<String> e3= t.iterator();
    while(e3.hasNext())
    {
    	String ee = e3.next();

    		if(!Crawl.contains(ee))
    		{
    			bw2.write(ee+"\r\n");
    		}



    }
    br.close();
    br2.close();
    bw.close();
    bw2.close();*/

    if (null == (crawlData = br.readLine()))
    // if(true)
    {
      // initial iteration
      bw.write(RTPage + "\r\n");
      Crawl.add(RTPage);
      t = collectLinks(RTPage);
      ToCrawl.addAll(t);
    } else {
      // collect data from files and load to array lists
      while (null != (crawlData2 = br.readLine())) {
        if (crawlData2 != null) Crawl.add(crawlData2);
      }

      while (null != (crawlData3 = br2.readLine())) {
        if (crawlData3 != null) ToCrawl.add(crawlData3);
      }
    }
    System.out.println("Crawlled");

    // Number of movies to be crawled
    for (int i = 0; i < 1000; i++) {
      if (ToCrawl.size() > 0) {
        Crawl.removeAll(Collections.singleton(null));
        ToCrawl.removeAll(Collections.singleton(null));
        String c = ToCrawl.get(0);
        if (Crawl.contains(c)) ToCrawl.remove(c);
        else {
          // collect links and collect data from a particular link
          Crawl.add(c);
          t = collectLinks(c);
          CollectData(c);
          ToCrawl.remove(c);
          Iterator<String> e3 = t.iterator();
          while (e3.hasNext()) {
            String ee = e3.next();
            if (!ToCrawl.contains(ee)) {
              if (!Crawl.contains(ee)) {
                ToCrawl.add(ee);
              }
            }
          }
          bw.write(c + "\r\n");
        }
      }
    }

    System.out.println("To Be Crawlled");
    Iterator<String> e2 = ToCrawl.iterator();
    while (e2.hasNext()) {
      // write to file the movies still to be crawled.
      bw2.write(e2.next() + "\r\n");
    }

    prop.setProperty("Id", Integer.toString(n));
    prop.store(new FileOutputStream("config.properties"), null);
    br.close();
    br2.close();
    bw.close();
    bw2.close();
  }
Example #27
0
  // ## operation writeReactorInputFile(ReactionModel,ReactionTime,ReactionTime,SystemSnapshot)
  public boolean writeReactorInputFile(
      ReactionModel p_reactionModel,
      ReactionTime p_beginTime,
      ReactionTime p_endTime,
      SystemSnapshot p_beginStatus) {
    // #[ operation writeReactorInputFile(ReactionModel,ReactionTime,ReactionTime,SystemSnapshot)
    // construct "input" string
    String input = "<?xml version=\"1.0\" standalone=\"no\"?>" + "\n";

    String dir = System.getProperty("RMG.workingDirectory");
    if (!dir.endsWith("/")) dir += "/";
    String dtd = dir + "software/reactorModel/documentTypeDefinitions/reactorInput.dtd";
    input += "<!DOCTYPE reactorinput SYSTEM \"" + dtd + "\">" + "\n";

    input += "<reactorinput>" + "\n";
    input += "<header>" + "\n";
    input += "<title>Reactor Input File</title>" + "\n";
    input +=
        "<description>RMG-generated file used to call an external reactor model</description>"
            + "\n";
    input += "</header>" + "\n";
    input += "<inputvalues>" + "\n";
    input += "<integrationparameters>" + "\n";
    input += "<reactortype>" + reactorType + "</reactortype>" + "\n";
    input +=
        "<starttime units=\""
            + p_beginTime.getUnit()
            + "\">"
            + MathTool.formatDouble(p_beginTime.getTime(), 15, 6)
            + "</starttime>"
            + "\n";
    input +=
        "<endtime units=\""
            + p_endTime.getUnit()
            + "\">"
            + MathTool.formatDouble(p_endTime.getTime(), 15, 6)
            + "</endtime>"
            + "\n";
    //      input += "<starttime units=\"" + p_beginTime.unit + "\">" +
    // MathTool.formatDouble(p_beginTime.time,15,6) +  "</starttime>" + "\n";
    //      input += "<endtime units=\"" + p_endTime.unit + "\">" +
    // MathTool.formatDouble(p_endTime.time,15,6) +  "</endtime>" + "\n";
    input += "<rtol>" + rtol + "</rtol>" + "\n";
    input += "<atol>" + atol + "</atol>" + "\n";
    input += "</integrationparameters>" + "\n";
    input += "<chemistry>" + "\n";
    input += "</chemistry>" + "\n";
    input += "<systemstate>" + "\n";
    input +=
        "<temperature units=\"K\">"
            + MathTool.formatDouble(p_beginStatus.getTemperature().getK(), 15, 6)
            + "</temperature>"
            + "\n";
    input +=
        "<pressure units=\"Pa\">"
            + MathTool.formatDouble(p_beginStatus.getPressure().getPa(), 15, 6)
            + "</pressure>"
            + "\n";
    for (Iterator iter = p_beginStatus.getSpeciesStatus(); iter.hasNext(); ) {
      SpeciesStatus spcStatus = (SpeciesStatus) iter.next();
      Species thisSpecies = spcStatus.getSpecies();
      CoreEdgeReactionModel cerm = (CoreEdgeReactionModel) p_reactionModel;
      if (cerm.containsAsReactedSpecies(thisSpecies)) {
        String spcChemkinName = thisSpecies.getChemkinName();
        double concentration = spcStatus.getConcentration();
        input +=
            "<amount units=\"molPerCm3\" speciesid=\""
                + spcChemkinName
                + "\">"
                + concentration
                + "</amount>"
                + "\n";
      }
    }
    for (Iterator iter = p_beginStatus.getInertGas(); iter.hasNext(); ) {
      String name = (String) iter.next();
      double conc = p_beginStatus.getInertGas(name);
      if (conc != 0.0)
        input +=
            "<amount units=\"molPerCm3\" speciesid=\"" + name + "\">" + conc + "</amount>" + "\n";
    }
    input += "</systemstate>" + "\n";
    input += "</inputvalues>" + "\n";
    input += "</reactorinput>" + "\n";

    // write "input" string to file
    try {
      String file = "chemkin/reactorInput.xml";
      FileWriter fw = new FileWriter(file);
      fw.write(input);
      fw.close();
      return true;
    } catch (Exception e) {
      System.out.println("Error in writing reactorInput.xml!");
      System.out.println(e.getMessage());
      return false;
    }

    // #]
  }
  public void build_bricks() {

    ImagePlus imp;
    ImagePlus orgimp;
    ImageStack stack;
    FileInfo finfo;

    if (lvImgTitle.isEmpty()) return;
    orgimp = WindowManager.getImage(lvImgTitle.get(0));
    imp = orgimp;

    finfo = imp.getFileInfo();
    if (finfo == null) return;

    int[] dims = imp.getDimensions();
    int imageW = dims[0];
    int imageH = dims[1];
    int nCh = dims[2];
    int imageD = dims[3];
    int nFrame = dims[4];
    int bdepth = imp.getBitDepth();
    double xspc = finfo.pixelWidth;
    double yspc = finfo.pixelHeight;
    double zspc = finfo.pixelDepth;
    double z_aspect = Math.max(xspc, yspc) / zspc;

    int orgW = imageW;
    int orgH = imageH;
    int orgD = imageD;
    double orgxspc = xspc;
    double orgyspc = yspc;
    double orgzspc = zspc;

    lv = lvImgTitle.size();
    if (filetype == "JPEG") {
      for (int l = 0; l < lv; l++) {
        if (WindowManager.getImage(lvImgTitle.get(l)).getBitDepth() != 8) {
          IJ.error("A SOURCE IMAGE MUST BE 8BIT GLAYSCALE");
          return;
        }
      }
    }

    // calculate levels
    /*		int baseXY = 256;
    		int baseZ = 256;

    		if (z_aspect < 0.5) baseZ = 128;
    		if (z_aspect > 2.0) baseXY = 128;
    		if (z_aspect >= 0.5 && z_aspect < 1.0) baseZ = (int)(baseZ*z_aspect);
    		if (z_aspect > 1.0 && z_aspect <= 2.0) baseXY = (int)(baseXY/z_aspect);

    		IJ.log("Z_aspect: " + z_aspect);
    		IJ.log("BaseXY: " + baseXY);
    		IJ.log("BaseZ: " + baseZ);
    */

    int baseXY = 256;
    int baseZ = 128;
    int dbXY = Math.max(orgW, orgH) / baseXY;
    if (Math.max(orgW, orgH) % baseXY > 0) dbXY *= 2;
    int dbZ = orgD / baseZ;
    if (orgD % baseZ > 0) dbZ *= 2;
    lv = Math.max(log2(dbXY), log2(dbZ)) + 1;

    int ww = orgW;
    int hh = orgH;
    int dd = orgD;
    for (int l = 0; l < lv; l++) {
      int bwnum = ww / baseXY;
      if (ww % baseXY > 0) bwnum++;
      int bhnum = hh / baseXY;
      if (hh % baseXY > 0) bhnum++;
      int bdnum = dd / baseZ;
      if (dd % baseZ > 0) bdnum++;

      if (bwnum % 2 == 0) bwnum++;
      if (bhnum % 2 == 0) bhnum++;
      if (bdnum % 2 == 0) bdnum++;

      int bw = (bwnum <= 1) ? ww : ww / bwnum + 1 + (ww % bwnum > 0 ? 1 : 0);
      int bh = (bhnum <= 1) ? hh : hh / bhnum + 1 + (hh % bhnum > 0 ? 1 : 0);
      int bd = (bdnum <= 1) ? dd : dd / bdnum + 1 + (dd % bdnum > 0 ? 1 : 0);

      bwlist.add(bw);
      bhlist.add(bh);
      bdlist.add(bd);

      IJ.log("LEVEL: " + l);
      IJ.log("  width: " + ww);
      IJ.log("  hight: " + hh);
      IJ.log("  depth: " + dd);
      IJ.log("  bw: " + bw);
      IJ.log("  bh: " + bh);
      IJ.log("  bd: " + bd);

      int xyl2 = Math.max(ww, hh) / baseXY;
      if (Math.max(ww, hh) % baseXY > 0) xyl2 *= 2;
      if (lv - 1 - log2(xyl2) <= l) {
        ww /= 2;
        hh /= 2;
      }
      IJ.log("  xyl2: " + (lv - 1 - log2(xyl2)));

      int zl2 = dd / baseZ;
      if (dd % baseZ > 0) zl2 *= 2;
      if (lv - 1 - log2(zl2) <= l) dd /= 2;
      IJ.log("  zl2: " + (lv - 1 - log2(zl2)));

      if (l < lv - 1) {
        lvImgTitle.add(lvImgTitle.get(0) + "_level" + (l + 1));
        IJ.selectWindow(lvImgTitle.get(0));
        IJ.run(
            "Scale...",
            "x=- y=- z=- width="
                + ww
                + " height="
                + hh
                + " depth="
                + dd
                + " interpolation=Bicubic average process create title="
                + lvImgTitle.get(l + 1));
      }
    }

    for (int l = 0; l < lv; l++) {
      IJ.log(lvImgTitle.get(l));
    }

    Document doc = newXMLDocument();
    Element root = doc.createElement("BRK");
    root.setAttribute("version", "1.0");
    root.setAttribute("nLevel", String.valueOf(lv));
    root.setAttribute("nChannel", String.valueOf(nCh));
    root.setAttribute("nFrame", String.valueOf(nFrame));
    doc.appendChild(root);

    for (int l = 0; l < lv; l++) {
      IJ.showProgress(0.0);

      int[] dims2 = imp.getDimensions();
      IJ.log(
          "W: "
              + String.valueOf(dims2[0])
              + " H: "
              + String.valueOf(dims2[1])
              + " C: "
              + String.valueOf(dims2[2])
              + " D: "
              + String.valueOf(dims2[3])
              + " T: "
              + String.valueOf(dims2[4])
              + " b: "
              + String.valueOf(bdepth));

      bw = bwlist.get(l).intValue();
      bh = bhlist.get(l).intValue();
      bd = bdlist.get(l).intValue();

      boolean force_pow2 = false;
      /*			if(IsPowerOf2(bw) && IsPowerOf2(bh) && IsPowerOf2(bd)) force_pow2 = true;

      			if(force_pow2){
      				//force pow2
      				if(Pow2(bw) > bw) bw = Pow2(bw)/2;
      				if(Pow2(bh) > bh) bh = Pow2(bh)/2;
      				if(Pow2(bd) > bd) bd = Pow2(bd)/2;
      			}

      			if(bw > imageW) bw = (Pow2(imageW) == imageW) ? imageW : Pow2(imageW)/2;
      			if(bh > imageH) bh = (Pow2(imageH) == imageH) ? imageH : Pow2(imageH)/2;
      			if(bd > imageD) bd = (Pow2(imageD) == imageD) ? imageD : Pow2(imageD)/2;

      */
      if (bw > imageW) bw = imageW;
      if (bh > imageH) bh = imageH;
      if (bd > imageD) bd = imageD;

      if (bw <= 1 || bh <= 1 || bd <= 1) break;

      if (filetype == "JPEG" && (bw < 8 || bh < 8)) break;

      Element lvnode = doc.createElement("Level");
      lvnode.setAttribute("lv", String.valueOf(l));
      lvnode.setAttribute("imageW", String.valueOf(imageW));
      lvnode.setAttribute("imageH", String.valueOf(imageH));
      lvnode.setAttribute("imageD", String.valueOf(imageD));
      lvnode.setAttribute("xspc", String.valueOf(xspc));
      lvnode.setAttribute("yspc", String.valueOf(yspc));
      lvnode.setAttribute("zspc", String.valueOf(zspc));
      lvnode.setAttribute("bitDepth", String.valueOf(bdepth));
      root.appendChild(lvnode);

      Element brksnode = doc.createElement("Bricks");
      brksnode.setAttribute("brick_baseW", String.valueOf(bw));
      brksnode.setAttribute("brick_baseH", String.valueOf(bh));
      brksnode.setAttribute("brick_baseD", String.valueOf(bd));
      lvnode.appendChild(brksnode);

      ArrayList<Brick> bricks = new ArrayList<Brick>();
      int mw, mh, md, mw2, mh2, md2;
      double tx0, ty0, tz0, tx1, ty1, tz1;
      double bx0, by0, bz0, bx1, by1, bz1;
      for (int k = 0; k < imageD; k += bd) {
        if (k > 0) k--;
        for (int j = 0; j < imageH; j += bh) {
          if (j > 0) j--;
          for (int i = 0; i < imageW; i += bw) {
            if (i > 0) i--;
            mw = Math.min(bw, imageW - i);
            mh = Math.min(bh, imageH - j);
            md = Math.min(bd, imageD - k);

            if (force_pow2) {
              mw2 = Pow2(mw);
              mh2 = Pow2(mh);
              md2 = Pow2(md);
            } else {
              mw2 = mw;
              mh2 = mh;
              md2 = md;
            }

            if (filetype == "JPEG") {
              if (mw2 < 8) mw2 = 8;
              if (mh2 < 8) mh2 = 8;
            }

            tx0 = i == 0 ? 0.0d : ((mw2 - mw + 0.5d) / mw2);
            ty0 = j == 0 ? 0.0d : ((mh2 - mh + 0.5d) / mh2);
            tz0 = k == 0 ? 0.0d : ((md2 - md + 0.5d) / md2);

            tx1 = 1.0d - 0.5d / mw2;
            if (mw < bw) tx1 = 1.0d;
            if (imageW - i == bw) tx1 = 1.0d;

            ty1 = 1.0d - 0.5d / mh2;
            if (mh < bh) ty1 = 1.0d;
            if (imageH - j == bh) ty1 = 1.0d;

            tz1 = 1.0d - 0.5d / md2;
            if (md < bd) tz1 = 1.0d;
            if (imageD - k == bd) tz1 = 1.0d;

            bx0 = i == 0 ? 0.0d : (i + 0.5d) / (double) imageW;
            by0 = j == 0 ? 0.0d : (j + 0.5d) / (double) imageH;
            bz0 = k == 0 ? 0.0d : (k + 0.5d) / (double) imageD;

            bx1 = Math.min((i + bw - 0.5d) / (double) imageW, 1.0d);
            if (imageW - i == bw) bx1 = 1.0d;

            by1 = Math.min((j + bh - 0.5d) / (double) imageH, 1.0d);
            if (imageH - j == bh) by1 = 1.0d;

            bz1 = Math.min((k + bd - 0.5d) / (double) imageD, 1.0d);
            if (imageD - k == bd) bz1 = 1.0d;

            int x, y, z;
            x = i - (mw2 - mw);
            y = j - (mh2 - mh);
            z = k - (md2 - md);
            bricks.add(
                new Brick(
                    x, y, z, mw2, mh2, md2, 0, 0, tx0, ty0, tz0, tx1, ty1, tz1, bx0, by0, bz0, bx1,
                    by1, bz1));
          }
        }
      }

      Element fsnode = doc.createElement("Files");
      lvnode.appendChild(fsnode);

      stack = imp.getStack();

      int totalbricknum = nFrame * nCh * bricks.size();
      int curbricknum = 0;
      for (int f = 0; f < nFrame; f++) {
        for (int ch = 0; ch < nCh; ch++) {
          int sizelimit = bdsizelimit * 1024 * 1024;
          int bytecount = 0;
          int filecount = 0;
          int pd_bufsize = Math.max(sizelimit, bw * bh * bd * bdepth / 8);
          byte[] packed_data = new byte[pd_bufsize];
          String base_dataname =
              basename
                  + "_Lv"
                  + String.valueOf(l)
                  + "_Ch"
                  + String.valueOf(ch)
                  + "_Fr"
                  + String.valueOf(f);
          String current_dataname = base_dataname + "_data" + filecount;

          Brick b_first = bricks.get(0);
          if (b_first.z_ != 0) IJ.log("warning");
          int st_z = b_first.z_;
          int ed_z = b_first.z_ + b_first.d_;
          LinkedList<ImageProcessor> iplist = new LinkedList<ImageProcessor>();
          for (int s = st_z; s < ed_z; s++)
            iplist.add(stack.getProcessor(imp.getStackIndex(ch + 1, s + 1, f + 1)));

          //					ImagePlus test;
          //					ImageStack tsst;
          //					test = NewImage.createByteImage("test", imageW, imageH, imageD,
          // NewImage.FILL_BLACK);
          //					tsst = test.getStack();
          for (int i = 0; i < bricks.size(); i++) {
            Brick b = bricks.get(i);

            if (ed_z > b.z_ || st_z < b.z_ + b.d_) {
              if (b.z_ > st_z) {
                for (int s = 0; s < b.z_ - st_z; s++) iplist.pollFirst();
                st_z = b.z_;
              } else if (b.z_ < st_z) {
                IJ.log("warning");
                for (int s = st_z - 1; s > b.z_; s--)
                  iplist.addFirst(stack.getProcessor(imp.getStackIndex(ch + 1, s + 1, f + 1)));
                st_z = b.z_;
              }

              if (b.z_ + b.d_ > ed_z) {
                for (int s = ed_z; s < b.z_ + b.d_; s++)
                  iplist.add(stack.getProcessor(imp.getStackIndex(ch + 1, s + 1, f + 1)));
                ed_z = b.z_ + b.d_;
              } else if (b.z_ + b.d_ < ed_z) {
                IJ.log("warning");
                for (int s = 0; s < ed_z - (b.z_ + b.d_); s++) iplist.pollLast();
                ed_z = b.z_ + b.d_;
              }
            } else {
              IJ.log("warning");
              iplist.clear();
              st_z = b.z_;
              ed_z = b.z_ + b.d_;
              for (int s = st_z; s < ed_z; s++)
                iplist.add(stack.getProcessor(imp.getStackIndex(ch + 1, s + 1, f + 1)));
            }

            if (iplist.size() != b.d_) {
              IJ.log("Stack Error");
              return;
            }

            //						int zz = st_z;

            int bsize = 0;
            byte[] bdata = new byte[b.w_ * b.h_ * b.d_ * bdepth / 8];
            Iterator<ImageProcessor> ipite = iplist.iterator();
            while (ipite.hasNext()) {

              //							ImageProcessor tsip = tsst.getProcessor(zz+1);

              ImageProcessor ip = ipite.next();
              ip.setRoi(b.x_, b.y_, b.w_, b.h_);
              if (bdepth == 8) {
                byte[] data = (byte[]) ip.crop().getPixels();
                System.arraycopy(data, 0, bdata, bsize, data.length);
                bsize += data.length;
              } else if (bdepth == 16) {
                ByteBuffer buffer = ByteBuffer.allocate(b.w_ * b.h_ * bdepth / 8);
                buffer.order(ByteOrder.LITTLE_ENDIAN);
                short[] data = (short[]) ip.crop().getPixels();
                for (short e : data) buffer.putShort(e);
                System.arraycopy(buffer.array(), 0, bdata, bsize, buffer.array().length);
                bsize += buffer.array().length;
              } else if (bdepth == 32) {
                ByteBuffer buffer = ByteBuffer.allocate(b.w_ * b.h_ * bdepth / 8);
                buffer.order(ByteOrder.LITTLE_ENDIAN);
                float[] data = (float[]) ip.crop().getPixels();
                for (float e : data) buffer.putFloat(e);
                System.arraycopy(buffer.array(), 0, bdata, bsize, buffer.array().length);
                bsize += buffer.array().length;
              }
            }

            String filename =
                basename
                    + "_Lv"
                    + String.valueOf(l)
                    + "_Ch"
                    + String.valueOf(ch)
                    + "_Fr"
                    + String.valueOf(f)
                    + "_ID"
                    + String.valueOf(i);

            int offset = bytecount;
            int datasize = bdata.length;

            if (filetype == "RAW") {
              int dummy = -1;
              // do nothing
            }
            if (filetype == "JPEG" && bdepth == 8) {
              try {
                DataBufferByte db = new DataBufferByte(bdata, datasize);
                Raster raster = Raster.createPackedRaster(db, b.w_, b.h_ * b.d_, 8, null);
                BufferedImage img =
                    new BufferedImage(b.w_, b.h_ * b.d_, BufferedImage.TYPE_BYTE_GRAY);
                img.setData(raster);
                ByteArrayOutputStream baos = new ByteArrayOutputStream();
                ImageOutputStream ios = ImageIO.createImageOutputStream(baos);
                String format = "jpg";
                Iterator<javax.imageio.ImageWriter> iter =
                    ImageIO.getImageWritersByFormatName("jpeg");
                javax.imageio.ImageWriter writer = iter.next();
                ImageWriteParam iwp = writer.getDefaultWriteParam();
                iwp.setCompressionMode(ImageWriteParam.MODE_EXPLICIT);
                iwp.setCompressionQuality((float) jpeg_quality * 0.01f);
                writer.setOutput(ios);
                writer.write(null, new IIOImage(img, null, null), iwp);
                // ImageIO.write(img, format, baos);
                bdata = baos.toByteArray();
                datasize = bdata.length;
              } catch (IOException e) {
                e.printStackTrace();
                return;
              }
            }
            if (filetype == "ZLIB") {
              byte[] tmpdata = new byte[b.w_ * b.h_ * b.d_ * bdepth / 8];
              Deflater compresser = new Deflater();
              compresser.setInput(bdata);
              compresser.setLevel(Deflater.DEFAULT_COMPRESSION);
              compresser.setStrategy(Deflater.DEFAULT_STRATEGY);
              compresser.finish();
              datasize = compresser.deflate(tmpdata);
              bdata = tmpdata;
              compresser.end();
            }

            if (bytecount + datasize > sizelimit && bytecount > 0) {
              BufferedOutputStream fis = null;
              try {
                File file = new File(directory + current_dataname);
                fis = new BufferedOutputStream(new FileOutputStream(file));
                fis.write(packed_data, 0, bytecount);
              } catch (IOException e) {
                e.printStackTrace();
                return;
              } finally {
                try {
                  if (fis != null) fis.close();
                } catch (IOException e) {
                  e.printStackTrace();
                  return;
                }
              }
              filecount++;
              current_dataname = base_dataname + "_data" + filecount;
              bytecount = 0;
              offset = 0;
              System.arraycopy(bdata, 0, packed_data, bytecount, datasize);
              bytecount += datasize;
            } else {
              System.arraycopy(bdata, 0, packed_data, bytecount, datasize);
              bytecount += datasize;
            }

            Element filenode = doc.createElement("File");
            filenode.setAttribute("filename", current_dataname);
            filenode.setAttribute("channel", String.valueOf(ch));
            filenode.setAttribute("frame", String.valueOf(f));
            filenode.setAttribute("brickID", String.valueOf(i));
            filenode.setAttribute("offset", String.valueOf(offset));
            filenode.setAttribute("datasize", String.valueOf(datasize));
            filenode.setAttribute("filetype", String.valueOf(filetype));

            fsnode.appendChild(filenode);

            curbricknum++;
            IJ.showProgress((double) (curbricknum) / (double) (totalbricknum));
          }
          if (bytecount > 0) {
            BufferedOutputStream fis = null;
            try {
              File file = new File(directory + current_dataname);
              fis = new BufferedOutputStream(new FileOutputStream(file));
              fis.write(packed_data, 0, bytecount);
            } catch (IOException e) {
              e.printStackTrace();
              return;
            } finally {
              try {
                if (fis != null) fis.close();
              } catch (IOException e) {
                e.printStackTrace();
                return;
              }
            }
          }
        }
      }

      for (int i = 0; i < bricks.size(); i++) {
        Brick b = bricks.get(i);
        Element bricknode = doc.createElement("Brick");
        bricknode.setAttribute("id", String.valueOf(i));
        bricknode.setAttribute("st_x", String.valueOf(b.x_));
        bricknode.setAttribute("st_y", String.valueOf(b.y_));
        bricknode.setAttribute("st_z", String.valueOf(b.z_));
        bricknode.setAttribute("width", String.valueOf(b.w_));
        bricknode.setAttribute("height", String.valueOf(b.h_));
        bricknode.setAttribute("depth", String.valueOf(b.d_));
        brksnode.appendChild(bricknode);

        Element tboxnode = doc.createElement("tbox");
        tboxnode.setAttribute("x0", String.valueOf(b.tx0_));
        tboxnode.setAttribute("y0", String.valueOf(b.ty0_));
        tboxnode.setAttribute("z0", String.valueOf(b.tz0_));
        tboxnode.setAttribute("x1", String.valueOf(b.tx1_));
        tboxnode.setAttribute("y1", String.valueOf(b.ty1_));
        tboxnode.setAttribute("z1", String.valueOf(b.tz1_));
        bricknode.appendChild(tboxnode);

        Element bboxnode = doc.createElement("bbox");
        bboxnode.setAttribute("x0", String.valueOf(b.bx0_));
        bboxnode.setAttribute("y0", String.valueOf(b.by0_));
        bboxnode.setAttribute("z0", String.valueOf(b.bz0_));
        bboxnode.setAttribute("x1", String.valueOf(b.bx1_));
        bboxnode.setAttribute("y1", String.valueOf(b.by1_));
        bboxnode.setAttribute("z1", String.valueOf(b.bz1_));
        bricknode.appendChild(bboxnode);
      }

      if (l < lv - 1) {
        imp = WindowManager.getImage(lvImgTitle.get(l + 1));
        int[] newdims = imp.getDimensions();
        imageW = newdims[0];
        imageH = newdims[1];
        imageD = newdims[3];
        xspc = orgxspc * ((double) orgW / (double) imageW);
        yspc = orgyspc * ((double) orgH / (double) imageH);
        zspc = orgzspc * ((double) orgD / (double) imageD);
        bdepth = imp.getBitDepth();
      }
    }

    File newXMLfile = new File(directory + basename + ".vvd");
    writeXML(newXMLfile, doc);

    for (int l = 1; l < lv; l++) {
      imp = WindowManager.getImage(lvImgTitle.get(l));
      imp.changes = false;
      imp.close();
    }
  }
Example #29
0
  // ## operation writeChemkinThermo(ReactionModel)
  public static String writeChemkinThermo(ReactionModel p_reactionModel) {
    // #[ operation writeChemkinThermo(ReactionModel)
    /*
     String thermoHeader = "! neon added by pey (20/6/04) - used thermo for Ar\n";
    thermoHeader += "Ne                120186Ne  1               G  0300.00   5000.00  1000.00      1\n";
    thermoHeader += " 0.02500000E+02 0.00000000E+00 0.00000000E+00 0.00000000E+00 0.00000000E+00    2\n";
    thermoHeader += "-0.07453750E+04 0.04366001E+02 0.02500000E+02 0.00000000E+00 0.00000000E+00    3\n";
    thermoHeader += " 0.00000000E+00 0.00000000E+00-0.07453750E+04 0.04366001E+02                   4\n";
    thermoHeader += "N2                121286N   2               G  0300.00   5000.00  1000.00      1\n";
    thermoHeader += " 0.02926640e+02 0.01487977e-01-0.05684761e-05 0.01009704e-08-0.06753351e-13    2\n";
    thermoHeader += "-0.09227977e+04 0.05980528e+02 0.03298677e+02 0.01408240e-01-0.03963222e-04    3\n";
    thermoHeader += " 0.05641515e-07-0.02444855e-10-0.01020900e+05 0.03950372e+02                   4\n";
    thermoHeader += "Ar                120186Ar  1               G  0300.00   5000.00  1000.00      1\n";
    thermoHeader += " 0.02500000e+02 0.00000000e+00 0.00000000e+00 0.00000000e+00 0.00000000e+00    2\n";
    thermoHeader += "-0.07453750e+04 0.04366001e+02 0.02500000e+02 0.00000000e+00 0.00000000e+00    3\n";
    thermoHeader += " 0.00000000e+00 0.00000000e+00-0.07453750e+04 0.04366001e+02                   4\n";
         */
    // #]
    String thermoHeader =
        "! The first four sets of polynomial coefficients (Ar, N2, Ne, He) are from         \n";
    thermoHeader +=
        "! THIRD MILLENIUM IDEAL GAS AND CONDENSED PHASE THERMOCHEMICAL DATABASE FOR     \n";
    thermoHeader +=
        "! COMBUSTION WITH UPDATES FROM ACTIVE THERMOCHENICAL TABLES                     \n";
    thermoHeader +=
        "! Authors: Alexander Burcat and Branko Ruscic                                   \n";
    thermoHeader +=
        "!                                                                               \n";
    thermoHeader +=
        "! The rest of the species are estimated by RMG (http://rmg.mit.edu/)            \n";
    // thermoHeader += "! Ar HF298=0.  REF=C.E. Moore 'Atomic Energy Levels' NSRDS-NBS 35 (1971)
    // p.211  \n";
    // thermoHeader += "! NASA Glen (former Lewis) Research Center   (1988)
    //    \n";
    thermoHeader +=
        "Ar                L 6/88Ar  1               G   200.000  6000.000 1000.        1\n";
    thermoHeader +=
        " 0.25000000E+01 0.00000000E+00 0.00000000E+00 0.00000000E+00 0.00000000E+00    2\n";
    thermoHeader +=
        "-0.74537500E+03 0.43796749E+01 0.25000000E+01 0.00000000E+00 0.00000000E+00    3\n";
    thermoHeader +=
        " 0.00000000E+00 0.00000000E+00-0.74537500E+03 0.43796749E+01                   4\n";
    // thermoHeader += "! N2  HF298= 0.0 KJ  REF=TSIV  Max Lst Sq Error Cp @ 6000 K 0.29%
    //    \n";
    thermoHeader +=
        "N2                G 8/02N   2               G   200.000  6000.000 1000.        1\n";
    thermoHeader +=
        " 2.95257637E+00 1.39690040E-03-4.92631603E-07 7.86010195E-11-4.60755204E-15    2\n";
    thermoHeader +=
        "-9.23948688E+02 5.87188762E+00 3.53100528E+00-1.23660988E-04-5.02999433E-07    3\n";
    thermoHeader +=
        " 2.43530612E-09-1.40881235E-12-1.04697628E+03 2.96747038E+00                   4\n";
    // thermoHeader += "!Ne    HF298= 0.0 KJ REF=McBride, Heimel, Ehlers & Gordon
    //    \n";
    // thermoHeader += "!                'Thermodynamic Properties to 6000 K...' NASA SP-3001
    // (1963)   \n";
    thermoHeader +=
        "Ne                L10/90Ne  1               G    200.0   6000.00  1000.0       1\n";
    thermoHeader +=
        " 0.25000000E 01 0.00000000E 00 0.00000000E 00 0.00000000E 00 0.00000000E 00    2\n";
    thermoHeader +=
        "-0.74537500E 03 0.33553227E 01 0.25000000E 01 0.00000000E 00 0.00000000E 00    3\n";
    thermoHeader +=
        " 0.00000000E 00 0.00000000E 00-0.74537498E 03 0.33553227E 01                   4\n";
    // thermoHeader += "7440-59-7
    //    \n";
    // thermoHeader += "He  HF298=0.0 KJ  REF=McBride, Heimel, Ehlers & Gordon "Thermodynamic
    // Properties\n";
    // thermoHeader += "to 6000K ..." NASA SP-3001 1963.
    //    \n";
    thermoHeader +=
        "He REF ELEMENT    L10/90HE 1.   0.   0.   0.G   200.000  6000.000  B   4.00260 1\n";
    thermoHeader +=
        " 2.50000000E+00 0.00000000E+00 0.00000000E+00 0.00000000E+00 0.00000000E+00    2\n";
    thermoHeader +=
        "-7.45375000E+02 9.28723974E-01 2.50000000E+00 0.00000000E+00 0.00000000E+00    3\n";
    thermoHeader +=
        " 0.00000000E+00 0.00000000E+00-7.45375000E+02 9.28723974E-01 0.00000000E+00    4\n\n";

    StringBuilder result = new StringBuilder();
    result.append("THERMO ALL\n");
    result.append("   300.000  1000.000  5000.000\n");
    result.append(thermoHeader);

    CoreEdgeReactionModel cerm = (CoreEdgeReactionModel) p_reactionModel;
    for (Iterator iter = cerm.getSpecies(); iter.hasNext(); ) {
      Species spe = (Species) iter.next();

      if (spe.getNasaThermoSource() != null) {
        result.append("!" + spe.getNasaThermoSource() + "\n");
      }
      result.append(spe.getNasaThermoData() + "\n");
    }
    result.append("END\n");

    // Added by Amrit for Richard's liquid phase chemkin code 05/21/2009
    result.append("\n");

    return result.toString();

    // #]
  }
Example #30
0
  public static String writeChemkinPdepReactions(ReactionSystem rs) {
    // #[ operation writeChemkinReactions(ReactionModel)

    StringBuilder result = new StringBuilder();
    result.append("REACTIONS	KCAL/MOLE\n");

    LinkedList rList = new LinkedList();
    LinkedList troeList = new LinkedList();
    LinkedList tbrList = new LinkedList();
    LinkedList duplicates = new LinkedList();
    LinkedList lindeList = new LinkedList();

    if (rs.dynamicSimulator instanceof JDASPK) {
      rList = ((JDASPK) rs.dynamicSimulator).rList;
      troeList = ((JDASPK) rs.dynamicSimulator).troeList;
      tbrList = ((JDASPK) rs.dynamicSimulator).thirdBodyList;
      duplicates = ((JDASPK) rs.dynamicSimulator).duplicates;
      lindeList = ((JDASPK) rs.dynamicSimulator).lindemannList;
    } else if (rs.dynamicSimulator instanceof JDASSL) {
      rList = ((JDASSL) rs.dynamicSimulator).rList;
      troeList = ((JDASSL) rs.dynamicSimulator).troeList;
      tbrList = ((JDASSL) rs.dynamicSimulator).thirdBodyList;
      duplicates = ((JDASSL) rs.dynamicSimulator).duplicates;
      lindeList = ((JDASSL) rs.dynamicSimulator).lindemannList;
    }

    for (Iterator iter = rList.iterator(); iter.hasNext(); ) {
      Reaction r = (Reaction) iter.next();
      // 10/26/07 gmagoon: changed to avoid use of Global.temperature; I am using
      // getPresentTemperature for the time being; it is possible that
      // getInitialStatus.getTemperature or something similar may be more appropriate
      result.append(r.toChemkinString(rs.getPresentTemperature()) + "\n");
      // result.append(r.toChemkinString(Global.temperature)+"\n");
    }
    for (Iterator iter = troeList.iterator(); iter.hasNext(); ) {
      Reaction r = (Reaction) iter.next();
      result.append(r.toChemkinString(rs.getPresentTemperature()) + "\n");
      // result.append(r.toChemkinString(Global.temperature)+"\n");
    }
    for (Iterator iter = tbrList.iterator(); iter.hasNext(); ) {
      Reaction r = (Reaction) iter.next();
      result.append(r.toChemkinString(rs.getPresentTemperature()) + "\n");
      // result.append(r.toChemkinString(Global.temperature)+"\n");
    }
    for (Iterator iter = duplicates.iterator(); iter.hasNext(); ) {
      Reaction r = (Reaction) iter.next();
      result.append(r.toChemkinString(rs.getPresentTemperature()) + "\n\tDUP\n");
      // result.append(r.toChemkinString(Global.temperature)+"\n\tDUP\n");
    }
    for (Iterator iter = lindeList.iterator(); iter.hasNext(); ) {
      Reaction r = (Reaction) iter.next();
      result.append(r.toChemkinString(rs.getPresentTemperature()) + "\n");
    }

    result.append("END\n");

    return result.toString();

    // #]
  }