package run.readers;
import run.Constraint;

import run.Controlset;

import run.Element;

import run.Load;

import run.Material;

import run.ModifiedStreamTokenizer;

import run.Node;

import run.Reader;

import run.RplVector;

import run.Token;

import run.TrackWriter;

import run.Tracker;

import run.Writer;

import run.materials.*;

import uka.karmi.rmi.RemoteException;

import java.io.*;

import java.lang.reflect.Array;

import java.text.ParseException;

import java.util.*;

import jp.lang.RemoteObject;

public class GmshReader extends Reader implements uka.patch.Patchable, uka.transport.Transportable {
   public void createPatch(Object _copy, uka.patch.PatchOutput po) throws java.io.IOException {
      GmshReader copy = (GmshReader)_copy;
      super.createPatch(copy, po);
      if (po.writeDiff(this.regpos, copy.regpos)) copy.regpos = this.regpos;
      if (po.writeDiff(this.constraint_in_block, copy.constraint_in_block)) copy.constraint_in_block = this.constraint_in_block;
      if (po.writeDiff(this.control_in_block, copy.control_in_block)) copy.control_in_block = this.control_in_block;
      if (po.writeDiff(this.material_in_block, copy.material_in_block)) copy.material_in_block = this.material_in_block;
      if (po.writeDiff(this.tracker_in_block, copy.tracker_in_block)) copy.tracker_in_block = this.tracker_in_block;
      if (po.writeDiff(this.element_in_block, copy.element_in_block)) copy.element_in_block = this.element_in_block;
      if (po.writeDiff(this.in_block2, copy.in_block2)) copy.in_block2 = this.in_block2;
      if (po.writeDiff(this.in_block, copy.in_block)) copy.in_block = this.in_block;
      copy.register = this.register = (int[])po.writeDiff(this.register, copy.register);
      copy.lastline = this.lastline = (run.Token[])po.writeDiff(this.lastline, copy.lastline);
      copy.temporary_controlset = this.temporary_controlset = (run.Controlset)po.writeDiff(this.temporary_controlset, copy.temporary_controlset);
      copy.current_constraint_type = this.current_constraint_type = (java.lang.String)po.writeDiff(this.current_constraint_type, copy.current_constraint_type);
      copy.current_tracker_type = this.current_tracker_type = (java.lang.String)po.writeDiff(this.current_tracker_type, copy.current_tracker_type);
      copy.current_element_type = this.current_element_type = (java.lang.String)po.writeDiff(this.current_element_type, copy.current_element_type);
      copy.temporary_load = this.temporary_load = (run.Load)po.writeDiff(this.temporary_load, copy.temporary_load);
      copy.temporary_constraint = this.temporary_constraint = (run.Constraint)po.writeDiff(this.temporary_constraint, copy.temporary_constraint);
      copy.temporary_node = this.temporary_node = (run.Node)po.writeDiff(this.temporary_node, copy.temporary_node);
      copy.str2 = this.str2 = (java.io.StreamTokenizer)po.writeDiff(this.str2, copy.str2);
      copy.str = this.str = (java.io.StreamTokenizer)po.writeDiff(this.str, copy.str);
      copy.keywords = this.keywords = (java.lang.String[])po.writeDiff(this.keywords, copy.keywords);
      copy.filename = this.filename = (java.lang.String)po.writeDiff(this.filename, copy.filename);
      copy.br2 = this.br2 = (java.io.BufferedReader)po.writeDiff(this.br2, copy.br2);
      copy.br = this.br = (java.io.BufferedReader)po.writeDiff(this.br, copy.br);
   }
   public void applyPatch(Object _copy, uka.patch.PatchInput pi) throws java.io.IOException, ClassNotFoundException {
      GmshReader copy = (GmshReader)_copy;
      super.applyPatch(copy, pi);
      if (pi.hasDiff()) copy.regpos = this.regpos = pi.getDiffAsInt();
      if (pi.hasDiff()) copy.constraint_in_block = this.constraint_in_block = pi.getDiffAsBoolean();
      if (pi.hasDiff()) copy.control_in_block = this.control_in_block = pi.getDiffAsBoolean();
      if (pi.hasDiff()) copy.material_in_block = this.material_in_block = pi.getDiffAsBoolean();
      if (pi.hasDiff()) copy.tracker_in_block = this.tracker_in_block = pi.getDiffAsBoolean();
      if (pi.hasDiff()) copy.element_in_block = this.element_in_block = pi.getDiffAsBoolean();
      if (pi.hasDiff()) copy.in_block2 = this.in_block2 = pi.getDiffAsBoolean();
      if (pi.hasDiff()) copy.in_block = this.in_block = pi.getDiffAsBoolean();
      if (pi.hasDiff()) copy.register = this.register = (int[])pi.getDiffAsObject();
      if (pi.hasDiff()) copy.lastline = this.lastline = (run.Token[])pi.getDiffAsObject();
      if (pi.hasDiff()) copy.temporary_controlset = this.temporary_controlset = (run.Controlset)pi.getDiffAsObject();
      if (pi.hasDiff()) copy.current_constraint_type = this.current_constraint_type = (java.lang.String)pi.getDiffAsObject();
      if (pi.hasDiff()) copy.current_tracker_type = this.current_tracker_type = (java.lang.String)pi.getDiffAsObject();
      if (pi.hasDiff()) copy.current_element_type = this.current_element_type = (java.lang.String)pi.getDiffAsObject();
      if (pi.hasDiff()) copy.temporary_load = this.temporary_load = (run.Load)pi.getDiffAsObject();
      if (pi.hasDiff()) copy.temporary_constraint = this.temporary_constraint = (run.Constraint)pi.getDiffAsObject();
      if (pi.hasDiff()) copy.temporary_node = this.temporary_node = (run.Node)pi.getDiffAsObject();
      if (pi.hasDiff()) copy.str2 = this.str2 = (java.io.StreamTokenizer)pi.getDiffAsObject();
      if (pi.hasDiff()) copy.str = this.str = (java.io.StreamTokenizer)pi.getDiffAsObject();
      if (pi.hasDiff()) copy.keywords = this.keywords = (java.lang.String[])pi.getDiffAsObject();
      if (pi.hasDiff()) copy.filename = this.filename = (java.lang.String)pi.getDiffAsObject();
      if (pi.hasDiff()) copy.br2 = this.br2 = (java.io.BufferedReader)pi.getDiffAsObject();
      if (pi.hasDiff()) copy.br = this.br = (java.io.BufferedReader)pi.getDiffAsObject();
   }
   public void descendReferences(uka.patch.ReferenceConsumer c) throws java.io.IOException {
      super.descendReferences(c);
      c.descend(this.register);
      c.descend(this.lastline);
      c.descend(this.temporary_controlset);
      c.descend(this.current_constraint_type);
      c.descend(this.current_tracker_type);
      c.descend(this.current_element_type);
      c.descend(this.temporary_load);
      c.descend(this.temporary_constraint);
      c.descend(this.temporary_node);
      c.descend(this.str2);
      c.descend(this.str);
      c.descend(this.keywords);
      c.descend(this.filename);
      c.descend(this.br2);
      c.descend(this.br);
   }
   public void filterReferences(uka.patch.ReferenceFilter f) {
      super.filterReferences(f);
      this.register = (int[])f.filter(this.register);
      this.lastline = (run.Token[])f.filter(this.lastline);
      this.temporary_controlset = (run.Controlset)f.filter(this.temporary_controlset);
      this.current_constraint_type = (java.lang.String)f.filter(this.current_constraint_type);
      this.current_tracker_type = (java.lang.String)f.filter(this.current_tracker_type);
      this.current_element_type = (java.lang.String)f.filter(this.current_element_type);
      this.temporary_load = (run.Load)f.filter(this.temporary_load);
      this.temporary_constraint = (run.Constraint)f.filter(this.temporary_constraint);
      this.temporary_node = (run.Node)f.filter(this.temporary_node);
      this.str2 = (java.io.StreamTokenizer)f.filter(this.str2);
      this.str = (java.io.StreamTokenizer)f.filter(this.str);
      this.keywords = (java.lang.String[])f.filter(this.keywords);
      this.filename = (java.lang.String)f.filter(this.filename);
      this.br2 = (java.io.BufferedReader)f.filter(this.br2);
      this.br = (java.io.BufferedReader)f.filter(this.br);
   }
   public static final uka.transport.TransportDescriptor TRANSPORT_DESCRIPTOR = new uka.transport.TransportDescriptor(){
      public Object unmarshalReference(uka.transport.UnmarshalStream s, int id) throws java.io.IOException, ClassNotFoundException {
         return new GmshReader(s, id);
      }
      public boolean unmarshal(Object obj, uka.transport.UnmarshalStream s) throws ClassNotFoundException, java.io.IOException {
         ((GmshReader)obj).unmarshal(s);
         return false;
      }
      public void marshalReference(Object obj, uka.transport.MarshalStream s) throws java.io.IOException {
         ((GmshReader)obj).marshalReference(s);
      }
      public void marshal(Object obj, uka.transport.MarshalStream s) throws java.io.IOException {
         ((GmshReader)obj).marshal(s);
      }
      public Object deepClone(Object orig, int id, uka.transport.DeepClone _helper) throws CloneNotSupportedException {
         try {
            return new GmshReader((GmshReader)orig, id, _helper);
         }  catch (java.io.IOException ex) {
            throw (CloneNotSupportedException)new CloneNotSupportedException().initCause(ex);
         }
      }
      public boolean deepCloneReferences(Object orig, Object copy, uka.transport.DeepClone _helper) throws CloneNotSupportedException {
         ((GmshReader)copy).deepCloneReferences((GmshReader)orig, _helper);
         return false;
      }
      public Class getType() {
         return GmshReader.class;
      }
   };
   public uka.transport.TransportDescriptor getTransportDescriptor() {
      return TRANSPORT_DESCRIPTOR;
   }
   private static final int _SIZE = uka.transport.BasicIO.SIZEOF_int + uka.transport.BasicIO.SIZEOF_boolean + uka.transport.BasicIO.SIZEOF_boolean + uka.transport.BasicIO.SIZEOF_boolean + uka.transport.BasicIO.SIZEOF_boolean + uka.transport.BasicIO.SIZEOF_boolean + uka.transport.BasicIO.SIZEOF_boolean + uka.transport.BasicIO.SIZEOF_boolean;
   public GmshReader(uka.transport.UnmarshalStream _stream, int _id) throws java.io.IOException, ClassNotFoundException {
      super(_stream, _id);
   }
   public void unmarshal(uka.transport.UnmarshalStream _stream) throws java.io.IOException, ClassNotFoundException {
      super.unmarshal(_stream);
      _stream.request(GmshReader._SIZE);
      byte[] _buffer = _stream.getBuffer();
      int _pos = _stream.getPosition();
      this.regpos = uka.transport.BasicIO.extractInt(_buffer, _pos);
      _pos += uka.transport.BasicIO.SIZEOF_int;
      this.constraint_in_block = uka.transport.BasicIO.extractBoolean(_buffer, _pos);
      _pos += uka.transport.BasicIO.SIZEOF_boolean;
      this.control_in_block = uka.transport.BasicIO.extractBoolean(_buffer, _pos);
      _pos += uka.transport.BasicIO.SIZEOF_boolean;
      this.material_in_block = uka.transport.BasicIO.extractBoolean(_buffer, _pos);
      _pos += uka.transport.BasicIO.SIZEOF_boolean;
      this.tracker_in_block = uka.transport.BasicIO.extractBoolean(_buffer, _pos);
      _pos += uka.transport.BasicIO.SIZEOF_boolean;
      this.element_in_block = uka.transport.BasicIO.extractBoolean(_buffer, _pos);
      _pos += uka.transport.BasicIO.SIZEOF_boolean;
      this.in_block2 = uka.transport.BasicIO.extractBoolean(_buffer, _pos);
      _pos += uka.transport.BasicIO.SIZEOF_boolean;
      this.in_block = uka.transport.BasicIO.extractBoolean(_buffer, _pos);
      _pos += uka.transport.BasicIO.SIZEOF_boolean;
      _stream.accept(GmshReader._SIZE);
      this.register = (int[])_stream.readReference();
      this.lastline = (run.Token[])_stream.readReference();
      this.temporary_controlset = (run.Controlset)_stream.readReference();
      this.current_constraint_type = (java.lang.String)_stream.readReference();
      this.current_tracker_type = (java.lang.String)_stream.readReference();
      this.current_element_type = (java.lang.String)_stream.readReference();
      this.temporary_load = (run.Load)_stream.readReference();
      this.temporary_constraint = (run.Constraint)_stream.readReference();
      this.temporary_node = (run.Node)_stream.readReference();
      this.str2 = (java.io.StreamTokenizer)_stream.readReference();
      this.str = (java.io.StreamTokenizer)_stream.readReference();
      this.keywords = (java.lang.String[])_stream.readReference();
      this.filename = (java.lang.String)_stream.readReference();
      this.br2 = (java.io.BufferedReader)_stream.readReference();
      this.br = (java.io.BufferedReader)_stream.readReference();
   }
   public void marshal(uka.transport.MarshalStream _stream) throws java.io.IOException {
      super.marshal(_stream);
      _stream.reserve(GmshReader._SIZE);
      byte[] _buffer = _stream.getBuffer();
      int _pos = _stream.getPosition();
      _pos = uka.transport.BasicIO.insert(_buffer, _pos, this.regpos);
      _pos = uka.transport.BasicIO.insert(_buffer, _pos, this.constraint_in_block);
      _pos = uka.transport.BasicIO.insert(_buffer, _pos, this.control_in_block);
      _pos = uka.transport.BasicIO.insert(_buffer, _pos, this.material_in_block);
      _pos = uka.transport.BasicIO.insert(_buffer, _pos, this.tracker_in_block);
      _pos = uka.transport.BasicIO.insert(_buffer, _pos, this.element_in_block);
      _pos = uka.transport.BasicIO.insert(_buffer, _pos, this.in_block2);
      _pos = uka.transport.BasicIO.insert(_buffer, _pos, this.in_block);
      _stream.deliver(_SIZE);
      _stream.writeReference(this.register);
      _stream.writeReference(this.lastline);
      _stream.writeReference(this.temporary_controlset);
      _stream.writeReference(this.current_constraint_type);
      _stream.writeReference(this.current_tracker_type);
      _stream.writeReference(this.current_element_type);
      _stream.writeReference(this.temporary_load);
      _stream.writeReference(this.temporary_constraint);
      _stream.writeReference(this.temporary_node);
      _stream.writeReference(this.str2);
      _stream.writeReference(this.str);
      _stream.writeReference(this.keywords);
      _stream.writeReference(this.filename);
      _stream.writeReference(this.br2);
      _stream.writeReference(this.br);
   }
   public GmshReader(GmshReader _orig, int _id, uka.transport.DeepClone _helper) throws CloneNotSupportedException, java.io.IOException {
      super(_orig, _id, _helper);
      this.regpos = _orig.regpos;
      this.constraint_in_block = _orig.constraint_in_block;
      this.control_in_block = _orig.control_in_block;
      this.material_in_block = _orig.material_in_block;
      this.tracker_in_block = _orig.tracker_in_block;
      this.element_in_block = _orig.element_in_block;
      this.in_block2 = _orig.in_block2;
      this.in_block = _orig.in_block;
   }
   public void deepCloneReferences(GmshReader _orig, uka.transport.DeepClone _helper) throws CloneNotSupportedException {
      super.deepCloneReferences(_orig, _helper);
      this.register = (int[])_helper.internalDeepClone(_orig.register);
      this.lastline = (run.Token[])_helper.internalDeepClone(_orig.lastline);
      this.temporary_controlset = (run.Controlset)_helper.internalDeepClone(_orig.temporary_controlset);
      this.current_constraint_type = (java.lang.String)_helper.internalDeepClone(_orig.current_constraint_type);
      this.current_tracker_type = (java.lang.String)_helper.internalDeepClone(_orig.current_tracker_type);
      this.current_element_type = (java.lang.String)_helper.internalDeepClone(_orig.current_element_type);
      this.temporary_load = (run.Load)_helper.internalDeepClone(_orig.temporary_load);
      this.temporary_constraint = (run.Constraint)_helper.internalDeepClone(_orig.temporary_constraint);
      this.temporary_node = (run.Node)_helper.internalDeepClone(_orig.temporary_node);
      this.str2 = (java.io.StreamTokenizer)_helper.internalDeepClone(_orig.str2);
      this.str = (java.io.StreamTokenizer)_helper.internalDeepClone(_orig.str);
      this.keywords = (java.lang.String[])_helper.internalDeepClone(_orig.keywords);
      this.filename = (java.lang.String)_helper.internalDeepClone(_orig.filename);
      this.br2 = (java.io.BufferedReader)_helper.internalDeepClone(_orig.br2);
      this.br = (java.io.BufferedReader)_helper.internalDeepClone(_orig.br);
   }
   private java.io.BufferedReader br;
   private java.io.BufferedReader br2;
   private java.lang.String filename;
   private java.lang.String[] keywords = {"$NOD", "$ENDNOD", "$ELM", "$ENDELM"};
   private boolean in_block = false;
   private boolean in_block2 = false;
   private java.io.StreamTokenizer str;
   private java.io.StreamTokenizer str2;
   private Node temporary_node;
   private Constraint temporary_constraint;
   private Load temporary_load;
   private boolean element_in_block = false;
   private boolean tracker_in_block = false;
   private boolean material_in_block = false;
   private java.lang.String current_element_type;
   private java.lang.String current_tracker_type;
   private java.lang.String current_constraint_type;
   private Controlset temporary_controlset;
   private boolean control_in_block;
   private boolean constraint_in_block;
   private Token[] lastline;
   private int[] register;
   private int regpos;
   public GmshReader(String fn) {
      super();
      int i;
      run.readers.GmshReader.this.filename = new String(fn);
      run.readers.GmshReader.this.register = new int[99];
   }
   public void close() {
      try {
         run.readers.GmshReader.this.br.close();
         run.readers.GmshReader.this.regpos = 0;
         Arrays.fill(run.readers.GmshReader.this.register, 0);
      }  catch (IOException ioe) {
         System.out.println("An IOException has occurred when closing the indata file");
         return;
      }
   }
   public void close2() {
      try {
         run.readers.GmshReader.this.br2.close();
      }  catch (IOException ioe) {
         System.out.println("An IOException has occurred when closing the indata file");
         return;
      }
   }
   public void getControlSet(Controlset temporary_controlset) throws Error {
      Token[] t;
      try {
         t = new Token[5];
         t[0] = new Token("RUN");
         t[1] = new Token("FROM");
         t[2] = new Token("0");
         t[3] = new Token("TO");
         t[4] = new Token("1");
         temporary_controlset.parse_Fembic(t, run.readers.GmshReader.this.str.lineno());
         t = new Token[4];
         t[0] = new Token("PRINT");
         t[1] = new Token("EVERY");
         t[2] = new Token("0.1");
         t[3] = new Token("STEP");
         temporary_controlset.parse_Fembic(t, run.readers.GmshReader.this.str.lineno());
         temporary_controlset.checkIndata();
      }  catch (Error e) {
         throw e;
      } catch (ParseException e) {
         throw new Error(e.getMessage() + " in line: " + (e.getErrorOffset() - 1));
      } catch (IllegalArgumentException e) {
         throw new Error(e.getMessage());
      }
   }
   public Element getNextElement(RplVector materiallist, RplVector nodelist, RplVector loadlist) throws java.text.ParseException, Error {
      int index;
      int val;
      Element temporary_element;
      Token[] t;
      try {
         do {
            t = this.tokenize(run.readers.GmshReader.this.str);
            if (t.length > 6) index = (int)t[1].getn(); else index = 100;
         }          while (index >= 15);
         val = (int)(t[2].getn() / 1.0E9);
         val %= 10;
         temporary_element = Element.getElementOfType_Gmsh(index, val);
         temporary_element.parse_Gmsh(t, run.readers.GmshReader.this.str.lineno(), nodelist, materiallist, loadlist);
         temporary_element.checkIndata();
         return (Element)temporary_element;
      }  catch (java.io.IOException e) {
         throw new Error(e.getMessage());
      } catch (Error e) {
         throw e;
      } catch (ParseException e) {
         throw new Error(e.getMessage() + " in line: " + (e.getErrorOffset() - 1));
      } catch (IllegalArgumentException e) {
         throw new Error(e.getMessage());
      }
   }
   public Tracker getNextTracker(RplVector nodelist, RplVector elementlist) throws java.text.ParseException, Error {
      int index;
      int val;
      int tpos;
      Tracker temporary_tracker;
      Token[] t;
      Token[] t2;
      Vector tmp;
      Node temp_node;
      try {
         val = 0;
         do {
            t = this.tokenize(run.readers.GmshReader.this.str);
            if (t.length >= 6) {
               val = (int)(t[2].getn() / 1.0E8);
               val %= 10;
            }
         }          while (val == 0 || this.compare(run.readers.GmshReader.this.register, val) != -1);
         val = (int)(t[2].getn() / 1.0E8);
         val %= 10;
         temporary_tracker = Tracker.getTrackerOfType_Gmsh(val);
         tpos = 6;
         this.open2();
         tmp = new Vector();
         for (index = 0; index < t.length; index++) tmp.add(t[index]);
         while (run.readers.GmshReader.this.str2.nextToken() != java.io.StreamTokenizer.TT_EOF) {
            run.readers.GmshReader.this.str2.pushBack();
            t2 = this.tokenize(run.readers.GmshReader.this.str2);
            if (t2.length >= 6) {
               index = (int)(t2[2].getn() / 1.0E8);
               index %= 10;
               if (val == index) {
                  tmp.add(t2[5]);
               }
            }
         }
         this.close2();
         t = new Token[tmp.size()];
         for (index = 0; index < tmp.size(); index++) t[index] = (Token)tmp.elementAt(index);
         temporary_tracker.parse_Gmsh(t, val, nodelist, elementlist);
         temporary_tracker.checkIndata();
         run.readers.GmshReader.this.register[run.readers.GmshReader.this.regpos++] = val;
         return (Tracker)temporary_tracker;
      }  catch (java.io.IOException e) {
         throw new Error(e.getMessage());
      } catch (Error e) {
         throw e;
      } catch (ParseException e) {
         throw new Error(e.getMessage() + " in line: " + (e.getErrorOffset() - 1));
      } catch (IllegalArgumentException e) {
         throw new Error(e.getMessage());
      }
   }
   public Constraint getNextConstraint(RplVector nodelist) throws java.text.ParseException, Error {
      int index;
      int val;
      int i;
      Constraint temporary_constraint;
      Token[] t;
      Node temp_node;
      try {
         val = 0;
         do {
            t = this.tokenize(run.readers.GmshReader.this.str);
            if (t.length >= 6) {
               val = (int)(t[2].getn() / 100000.0);
               val %= 100;
            }
         }          while (val == 0 || this.compare(run.readers.GmshReader.this.register, val) != -1);
         temporary_constraint = Constraint.getConstraintOfType_Gmsh(val);
         temporary_constraint.parse_Gmsh(t, val, nodelist);
         temporary_constraint.checkIndata();
         this.open2();
         while (run.readers.GmshReader.this.str2.nextToken() != java.io.StreamTokenizer.TT_EOF) {
            run.readers.GmshReader.this.str2.pushBack();
            t = this.tokenize(run.readers.GmshReader.this.str2);
            if (t.length >= 6) {
               index = (int)(t[2].getn() / 100000.0);
               index %= 100;
               if (val == index) {
                  for (i = 5; i < 5 + (int)t[4].getn(); i++) for (index = 0; index < nodelist.size(); index++) {
                     temp_node = (Node)nodelist.elementAt(index);
                     if (temp_node.getNumber() == t[i].getn()) temp_node.setConstraint(temporary_constraint);
                  }
               }
            }
         }
         this.close2();
         run.readers.GmshReader.this.register[run.readers.GmshReader.this.regpos++] = val;
         return (Constraint)temporary_constraint;
      }  catch (java.io.IOException e) {
         throw new Error(e.getMessage());
      } catch (Error e) {
         throw e;
      } catch (ParseException e) {
         throw new Error(e.getMessage() + " in line: " + (e.getErrorOffset() - 1));
      } catch (IllegalArgumentException e) {
         throw new Error(e.getMessage());
      }
   }
   public Material getNextMaterial() throws java.text.ParseException, Error {
      int val;
      Material temporary_material;
      Token[] t;
      try {
         val = 0;
         do {
            t = this.tokenize(run.readers.GmshReader.this.str);
            if (t.length >= 6) {
               val = (int)(t[2].getn() / 1000.0);
               val %= 100;
            }
         }          while (val == 0 || this.compare(run.readers.GmshReader.this.register, val) != -1);
         temporary_material = Material.getMaterialOfType_Gmsh(0);
         temporary_material.parse_Gmsh(t, run.readers.GmshReader.this.str.lineno());
         temporary_material.checkIndata();
         run.readers.GmshReader.this.register[run.readers.GmshReader.this.regpos++] = val;
         return (Material)temporary_material;
      }  catch (java.io.IOException e) {
         throw new Error(e.getMessage());
      } catch (Error e) {
         throw e;
      } catch (ParseException e) {
         throw new Error(e.getMessage() + " in line: " + (e.getErrorOffset() - 1));
      } catch (IllegalArgumentException e) {
         throw new Error(e.getMessage());
      }
   }
   public Load getNextLoad(RplVector nodelist) throws java.text.ParseException, Error {
      int index;
      int val;
      Load temporary_load;
      Token[] t;
      Node temp_node;
      try {
         if (run.readers.GmshReader.this.lastline == null) do {
            t = this.tokenize(run.readers.GmshReader.this.str);
            if (t.length == 6) index = (int)t[1].getn(); else index = 0;
            run.readers.GmshReader.this.regpos = 0;
         }          while (index != 15); else t = run.readers.GmshReader.this.lastline;
         val = (int)(t[2].getn() / 1.0E7);
         val %= 10;
         temporary_load = new Load();
         temporary_load.parse_Gmsh(t, val, nodelist);
         run.readers.GmshReader.this.temporary_constraint.checkIndata();
         this.open2();
         while (run.readers.GmshReader.this.str2.nextToken() != java.io.StreamTokenizer.TT_EOF) {
            run.readers.GmshReader.this.str2.pushBack();
            t = this.tokenize(run.readers.GmshReader.this.str2);
            if (t.length >= 6) {
               index = (int)(t[2].getn() / 1.0E7);
               index %= 10;
               if (val == index) {
                  for (index = 0; index < nodelist.size(); index++) {
                     temp_node = (Node)nodelist.elementAt(index);
                     if (temp_node.getNumber() == t[5].getn()) temp_node.setLoad(temporary_load);
                  }
               }
            }
         }
         this.close2();
         run.readers.GmshReader.this.register[run.readers.GmshReader.this.regpos++] = val;
         while (run.readers.GmshReader.this.str.nextToken() != java.io.StreamTokenizer.TT_EOF) {
            run.readers.GmshReader.this.str.pushBack();
            t = this.tokenize(run.readers.GmshReader.this.str);
            if (t.length > 2) {
               index = (int)(t[2].getn() / 1.0E7);
               index %= 10;
               if (this.compare(run.readers.GmshReader.this.register, index) < 0) {
                  run.readers.GmshReader.this.lastline = t;
                  break;
               }
            }
         }
         return temporary_load;
      }  catch (java.io.IOException e) {
         throw new Error(e.getMessage());
      } catch (Error e) {
         throw e;
      } catch (ParseException e) {
         throw new Error(e.getMessage() + " in line: " + (e.getErrorOffset() - 1));
      } catch (IllegalArgumentException e) {
         throw new Error(e.getMessage());
      }
   }
   public Node getNextNode(RplVector constraintlist, RplVector loadlist) throws java.text.ParseException, Error {
      int index;
      Constraint temp_constraint;
      Load temp_load;
      try {
         while (run.readers.GmshReader.this.str.nextToken() == java.io.StreamTokenizer.TT_EOL) {
            {
            }
         }
         run.readers.GmshReader.this.str.pushBack();
         while (run.readers.GmshReader.this.str.nextToken() != java.io.StreamTokenizer.TT_NUMBER && run.readers.GmshReader.this.str.ttype != java.io.StreamTokenizer.TT_EOF) {
            run.readers.GmshReader.this.in_block = false;
            run.readers.GmshReader.this.str.pushBack();
            while (run.readers.GmshReader.this.str.nextToken() != java.io.StreamTokenizer.TT_EOF) {
               if (run.readers.GmshReader.this.str.ttype == java.io.StreamTokenizer.TT_WORD) {
                  if (run.readers.GmshReader.this.str.sval.toUpperCase().equals("$NOD") && run.readers.GmshReader.this.str.nextToken() == run.readers.GmshReader.this.str.TT_EOL) {
                     run.readers.GmshReader.this.in_block = true;
                     while (run.readers.GmshReader.this.str.nextToken() != run.readers.GmshReader.this.str.TT_EOL) {
                        {
                        }
                     }
                     break;
                  }
               }
            }
         }
         if (!run.readers.GmshReader.this.in_block) {
            throw new java.text.ParseException("No nodes block found or missing nodes", run.readers.GmshReader.this.str.lineno());
         }
         run.readers.GmshReader.this.temporary_node = new Node();
         run.readers.GmshReader.this.temporary_node.setNumber((int)run.readers.GmshReader.this.str.nval);
         run.readers.GmshReader.this.temporary_node.parse_Gmsh(tokenize(run.readers.GmshReader.this.str), run.readers.GmshReader.this.str.lineno(), constraintlist, loadlist);
         run.readers.GmshReader.this.temporary_node.checkIndata();
         return run.readers.GmshReader.this.temporary_node;
      }  catch (java.io.IOException e) {
         throw new Error(e.getMessage());
      } catch (Error e) {
         throw e;
      } catch (ParseException e) {
         throw new Error(e.getMessage() + " in line: " + (e.getErrorOffset() - 1));
      } catch (IllegalArgumentException e) {
         throw new Error(e.getMessage());
      }
   }
   private boolean isAKeyword(String param) {
      int i;
      for (i = 0; i < run.readers.GmshReader.this.keywords.length; i++) {
         if (run.readers.GmshReader.this.keywords[i].equals(param.toUpperCase())) {
            return true;
         }
      }
      return false;
   }
   public int numberOfConstraints() throws java.text.ParseException {
      int noc = 0;
      int i = 0;
      int val = 0;
      Token[] temp;
      int[] constraints = new int[99];
      boolean found;
      this.open();
      try {
         while (run.readers.GmshReader.this.str.nextToken() != run.readers.GmshReader.this.str.TT_EOF) {
            if (run.readers.GmshReader.this.str.ttype == run.readers.GmshReader.this.str.TT_WORD) {
               if (run.readers.GmshReader.this.str.sval.toUpperCase().equals("$ELM")) {
                  while (run.readers.GmshReader.this.str.nextToken() != run.readers.GmshReader.this.str.TT_EOL) {
                     {
                     }
                  }
                  run.readers.GmshReader.this.str.pushBack();
                  while (run.readers.GmshReader.this.str.nextToken() != run.readers.GmshReader.this.str.TT_EOF) {
                     if (run.readers.GmshReader.this.str.ttype == run.readers.GmshReader.this.str.TT_WORD) {
                        if (this.isAKeyword(run.readers.GmshReader.this.str.sval)) {
                           run.readers.GmshReader.this.str.pushBack();
                           break;
                        }
                     }
                     temp = this.tokenize(run.readers.GmshReader.this.str);
                     found = false;
                     if (temp.length > 1) {
                        val = (int)(temp[1].getn() / 100000.0);
                        val %= 100;
                        for (i = 0; i < 99; i++) if (constraints[i] == val) found = true;
                     }
                     if (found == false && val != 0) {
                        constraints[noc] = val;
                        noc++;
                     }
                  }
               }
            }
         }
         System.out.println("Found" + noc + "constraints");
      }  catch (IOException ioe) {
         System.out.println("IOException when reading a constraintline from indata file");
         this.close();
         return -1;
      }
      this.close();
      return noc;
   }
   public int numberOfControls() throws java.text.ParseException {
      int noc;
      noc = 1;
      System.out.println("Found" + noc + "controls");
      return noc;
   }
   public int numberOfElements() throws java.text.ParseException {
      int noe = 0;
      this.open();
      try {
         while (run.readers.GmshReader.this.str.nextToken() != run.readers.GmshReader.this.str.TT_EOF) {
            if (run.readers.GmshReader.this.str.ttype == run.readers.GmshReader.this.str.TT_WORD) {
               if (run.readers.GmshReader.this.str.sval.toUpperCase().equals("$ELM")) {
                  while (run.readers.GmshReader.this.str.nextToken() != run.readers.GmshReader.this.str.TT_EOL) {
                     {
                     }
                  }
                  run.readers.GmshReader.this.str.pushBack();
                  while (run.readers.GmshReader.this.str.nextToken() != run.readers.GmshReader.this.str.TT_EOL && run.readers.GmshReader.this.str.ttype != run.readers.GmshReader.this.str.TT_EOF) {
                  }
                  run.readers.GmshReader.this.str.pushBack();
                  while (run.readers.GmshReader.this.str.nextToken() != run.readers.GmshReader.this.str.TT_EOF) {
                     if (run.readers.GmshReader.this.str.ttype == run.readers.GmshReader.this.str.TT_WORD) {
                        if (this.isAKeyword(run.readers.GmshReader.this.str.sval)) {
                           run.readers.GmshReader.this.str.pushBack();
                           break;
                        }
                     }
                     if (run.readers.GmshReader.this.str.ttype == run.readers.GmshReader.this.str.TT_NUMBER) {
                        run.readers.GmshReader.this.str.nextToken();
                        if (run.readers.GmshReader.this.str.nval != 15 && run.readers.GmshReader.this.str.ttype == run.readers.GmshReader.this.str.TT_NUMBER) noe++;
                        while (run.readers.GmshReader.this.str.nextToken() != run.readers.GmshReader.this.str.TT_EOL && run.readers.GmshReader.this.str.ttype != run.readers.GmshReader.this.str.TT_EOF) {
                           {
                           }
                        }
                     }
                  }
               }
            }
         }
         System.out.println("Found" + noe + "elements");
      }  catch (IOException ioe) {
         System.out.println("IOException when reading a line from indata file");
         this.close();
         return -1;
      }
      if (noe == 0) {
         this.close();
         throw new java.text.ParseException("No elements found", 0);
      }
      this.close();
      return noe;
   }
   public int numberOfTrackers() throws java.text.ParseException {
      int not = 0;
      int i = 0;
      int val = 0;
      int[] trackers = new int[9];
      Token[] temp;
      boolean found;
      this.open();
      try {
         while (run.readers.GmshReader.this.str.nextToken() != run.readers.GmshReader.this.str.TT_EOF) {
            if (run.readers.GmshReader.this.str.ttype == run.readers.GmshReader.this.str.TT_WORD) {
               if (run.readers.GmshReader.this.str.sval.toUpperCase().equals("$ELM")) {
                  while (run.readers.GmshReader.this.str.nextToken() != run.readers.GmshReader.this.str.TT_EOL) {
                     {
                     }
                  }
                  run.readers.GmshReader.this.str.pushBack();
                  while (run.readers.GmshReader.this.str.nextToken() != run.readers.GmshReader.this.str.TT_EOF) {
                     if (run.readers.GmshReader.this.str.ttype == run.readers.GmshReader.this.str.TT_WORD) {
                        if (this.isAKeyword(run.readers.GmshReader.this.str.sval)) {
                           run.readers.GmshReader.this.str.pushBack();
                           break;
                        }
                     }
                     temp = this.tokenize(run.readers.GmshReader.this.str);
                     found = false;
                     if (temp.length > 1) {
                        val = (int)(temp[1].getn() / 1.0E8);
                        val %= 10;
                        for (i = 0; i < 9; i++) if (trackers[i] == val) found = true;
                     }
                     if (found == false && val != 0) {
                        trackers[not] = val;
                        not++;
                     }
                  }
               }
            }
         }
         System.out.println("Found" + not + "trackers");
      }  catch (IOException ioe) {
         System.out.println("IOException when reading a trackerline from indata file");
         this.close();
         return -1;
      }
      this.close();
      return not;
   }
   public int numberOfLoads() throws java.text.ParseException {
      int nol = 0;
      int i = 0;
      int val = 0;
      Token[] temp;
      int[] constraints = new int[9];
      boolean found;
      this.open();
      try {
         while (run.readers.GmshReader.this.str.nextToken() != run.readers.GmshReader.this.str.TT_EOF) {
            if (run.readers.GmshReader.this.str.ttype == run.readers.GmshReader.this.str.TT_WORD) {
               if (run.readers.GmshReader.this.str.sval.toUpperCase().equals("$ELM")) {
                  while (run.readers.GmshReader.this.str.nextToken() != run.readers.GmshReader.this.str.TT_EOL) {
                     {
                     }
                  }
                  run.readers.GmshReader.this.str.pushBack();
                  while (run.readers.GmshReader.this.str.nextToken() != run.readers.GmshReader.this.str.TT_EOF) {
                     if (run.readers.GmshReader.this.str.ttype == run.readers.GmshReader.this.str.TT_WORD) {
                        if (this.isAKeyword(run.readers.GmshReader.this.str.sval)) {
                           run.readers.GmshReader.this.str.pushBack();
                           break;
                        }
                     }
                     temp = this.tokenize(run.readers.GmshReader.this.str);
                     found = false;
                     if (temp.length > 1) {
                        val = (int)(temp[1].getn() / 1.0E7);
                        val %= 10;
                        for (i = 0; i < 9; i++) if (constraints[i] == val) found = true;
                     }
                     if (found == false && val != 0) {
                        constraints[nol] = val;
                        nol++;
                     }
                  }
               }
            }
         }
         System.out.println("Found" + nol + "loads");
      }  catch (IOException ioe) {
         System.out.println("IOException when reading a line from indata file");
         this.close();
         return -1;
      }
      this.close();
      return nol;
   }
   public int numberOfMaterials() throws java.text.ParseException {
      int nom = 0;
      int val = 0;
      int i;
      boolean found;
      Token[] temp;
      int[] constraints = new int[99];
      this.open();
      try {
         while (run.readers.GmshReader.this.str.nextToken() != run.readers.GmshReader.this.str.TT_EOF) {
            if (run.readers.GmshReader.this.str.ttype == run.readers.GmshReader.this.str.TT_WORD) {
               if (run.readers.GmshReader.this.str.sval.toUpperCase().equals("$ELM")) {
                  while (run.readers.GmshReader.this.str.nextToken() != run.readers.GmshReader.this.str.TT_EOL) {
                     {
                     }
                  }
                  run.readers.GmshReader.this.str.pushBack();
                  while (run.readers.GmshReader.this.str.nextToken() != run.readers.GmshReader.this.str.TT_EOF) {
                     if (run.readers.GmshReader.this.str.ttype == run.readers.GmshReader.this.str.TT_WORD) {
                        if (this.isAKeyword(run.readers.GmshReader.this.str.sval)) {
                           run.readers.GmshReader.this.str.pushBack();
                           break;
                        }
                     }
                     temp = this.tokenize(run.readers.GmshReader.this.str);
                     found = false;
                     if (temp.length > 1) {
                        val = (int)(temp[1].getn() / 1000.0);
                        val %= 100;
                        for (i = 0; i < 99; i++) if (constraints[i] == val) found = true;
                     }
                     if (found == false && val != 0) {
                        constraints[nom] = val;
                        nom++;
                     }
                  }
               }
            }
         }
         System.out.println("Found" + nom + "materials");
      }  catch (IOException ioe) {
         System.out.println("IOException when reading a line from indata file");
         this.close();
         return -1;
      }
      if (nom == 0) {
         this.close();
         throw new java.text.ParseException("No materials found", 0);
      }
      this.close();
      return nom;
   }
   public int numberOfNodes() throws java.text.ParseException {
      int non = 0;
      this.open();
      try {
         while (run.readers.GmshReader.this.str.nextToken() != run.readers.GmshReader.this.str.TT_EOF) {
            if (run.readers.GmshReader.this.str.ttype == run.readers.GmshReader.this.str.TT_WORD) {
               if (run.readers.GmshReader.this.str.sval.toUpperCase().equals("$NOD") && run.readers.GmshReader.this.str.nextToken() == run.readers.GmshReader.this.str.TT_EOL) {
                  while (run.readers.GmshReader.this.str.nextToken() != run.readers.GmshReader.this.str.TT_EOF) {
                     if (run.readers.GmshReader.this.str.ttype == run.readers.GmshReader.this.str.TT_WORD) {
                        if (this.isAKeyword(run.readers.GmshReader.this.str.sval)) {
                           break;
                        }
                     }
                     if (run.readers.GmshReader.this.str.ttype == run.readers.GmshReader.this.str.TT_NUMBER) {
                        non++;
                        while (run.readers.GmshReader.this.str.nextToken() != run.readers.GmshReader.this.str.TT_EOL && run.readers.GmshReader.this.str.ttype != run.readers.GmshReader.this.str.TT_EOF) {
                           {
                           }
                        }
                     }
                  }
               }
            }
         }
         if (non > 0) non--;
         System.out.println("Found" + non + "nodes");
      }  catch (IOException ioe) {
         System.out.println("IOException when reading a line from indata file");
         this.close();
         return -1;
      }
      if (non == 0) {
         this.close();
         throw new java.text.ParseException("No nodes found", 0);
      }
      this.close();
      return non;
   }
   public void open() {
      FileReader fr;
      run.readers.GmshReader.this.in_block = false;
      run.readers.GmshReader.this.control_in_block = false;
      run.readers.GmshReader.this.constraint_in_block = false;
      run.readers.GmshReader.this.element_in_block = false;
      try {
         fr = new FileReader(run.readers.GmshReader.this.filename);
      }  catch (FileNotFoundException fnfe) {
         System.out.println("Fembic file does not exist");
         return;
      }
      try {
         run.readers.GmshReader.this.br = new BufferedReader(fr);
      }  catch (IllegalArgumentException ioe) {
         System.out.println("An IllegalArgumentException has occurred when opening the indata file");
         return;
      }
      run.readers.GmshReader.this.str = new ModifiedStreamTokenizer(run.readers.GmshReader.this.br);
   }
   public void open2() {
      FileReader fr;
      run.readers.GmshReader.this.in_block2 = false;
      try {
         fr = new FileReader(run.readers.GmshReader.this.filename);
      }  catch (FileNotFoundException fnfe) {
         System.out.println("Fembic file does not exist");
         return;
      }
      try {
         run.readers.GmshReader.this.br2 = new BufferedReader(fr);
      }  catch (IllegalArgumentException ioe) {
         System.out.println("An IllegalArgumentException has occurred when opening the indata file");
         return;
      }
      run.readers.GmshReader.this.str2 = new ModifiedStreamTokenizer(run.readers.GmshReader.this.br2);
   }
   public Writer getWriter(RplVector nodelist, RplVector elementlist, Controlset control, RemoteObject[] cluster_nodes) throws Error, RemoteException {
      Writer a;
      a = Writer.getWriterOfType_Fembic(control.getWriter(), nodelist, elementlist, cluster_nodes);
      try {
         a.checkIndata();
      }  catch (Error e) {
         throw e;
      }
      return a;
   }
   public TrackWriter getTrackWriter(RplVector trackerlist, Controlset control, RemoteObject[] cluster_nodes) throws Error, RemoteException {
      TrackWriter a;
      a = TrackWriter.getTrackWriterOfType_Fembic(control.getTrackWriter(), trackerlist, cluster_nodes);
      try {
         a.checkIndata();
      }  catch (Error e) {
         throw e;
      }
      return a;
   }
   public Token[] tokenize(java.io.StreamTokenizer str) throws IOException {
      int i;
      double num;
      String temp;
      String temp1;
      String temp2;
      Vector v = new Vector();
      Token t;
      Token[] arr;
      while (str.nextToken() != java.io.StreamTokenizer.TT_EOL && str.ttype != java.io.StreamTokenizer.TT_EOF) {
         if (str.ttype == java.io.StreamTokenizer.TT_WORD) {
            v.add(new Token(str.sval.trim()));
         } else {
            v.add(new Token(str.nval));
         }
      }
      for (i = 0; i < v.size(); i++) {
         t = (Token)v.elementAt(i);
         if (t.is_a_word()) {
            temp = new String(t.getw());
            if (temp.startsWith("[") && !temp.endsWith("]")) {
               v.remove(i);
               while (!temp.endsWith("]")) {
                  if (i >= v.size()) {
                     throw new IOException("IO Exception trying to find end ] of a parameter set in string\n");
                  }
                  t = (Token)v.elementAt(i);
                  v.remove(i);
                  if (t.is_a_number()) {
                     temp += new Double(t.getn()).toString();
                  } else {
                     temp += t.getw().trim();
                  }
               }
               v.insertElementAt(new Token(temp), i);
            } else if (temp.indexOf("=") != -1 && temp.length() > 1) {
               v.remove(i);
               if (temp.indexOf("=") != 0) {
                  v.insertElementAt(new Token(temp.substring(0, temp.indexOf("="))), i);
               } else {
                  i--;
               }
               v.insertElementAt(new Token(new String("=")), i + 1);
               if (temp.indexOf("=") != temp.length() - 1) {
                  v.insertElementAt(new Token(temp.substring(temp.indexOf("=") + 1, temp.length())), i + 2);
               }
               i--;
            }
         } else {
         }
      }
      arr = new Token[v.size()];
      for (i = 0; i < v.size(); i++) {
         arr[i] = (Token)v.elementAt(i);
      }
      return arr;
   }
   public void preProcess() throws java.text.ParseException {
   }
   private int compare(int[] a, int b) {
      int i;
      int res;
      res = -1;
      for (i = 0; i < a.length; i++) if (a[i] == b) {
         res = i;
         break;
      }
      return res;
   }
}
