package run.readers;
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 run.Constraint;

import uka.karmi.rmi.RemoteException;

import java.io.*;

import java.text.ParseException;

import java.util.*;

import jp.lang.RemoteObject;

public class NastranReader extends Reader implements uka.patch.Patchable, uka.transport.Transportable {
   public void createPatch(Object _copy, uka.patch.PatchOutput po) throws java.io.IOException {
      NastranReader copy = (NastranReader)_copy;
      super.createPatch(copy, po);
      if (po.writeDiff(this.cnum, copy.cnum)) copy.cnum = this.cnum;
      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.nextline = this.nextline = (java.lang.String)po.writeDiff(this.nextline, copy.nextline);
      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 {
      NastranReader copy = (NastranReader)_copy;
      super.applyPatch(copy, pi);
      if (pi.hasDiff()) copy.cnum = this.cnum = 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.nextline = this.nextline = (java.lang.String)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.nextline);
      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.nextline = (java.lang.String)f.filter(this.nextline);
      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 NastranReader(s, id);
      }
      public boolean unmarshal(Object obj, uka.transport.UnmarshalStream s) throws ClassNotFoundException, java.io.IOException {
         ((NastranReader)obj).unmarshal(s);
         return false;
      }
      public void marshalReference(Object obj, uka.transport.MarshalStream s) throws java.io.IOException {
         ((NastranReader)obj).marshalReference(s);
      }
      public void marshal(Object obj, uka.transport.MarshalStream s) throws java.io.IOException {
         ((NastranReader)obj).marshal(s);
      }
      public Object deepClone(Object orig, int id, uka.transport.DeepClone _helper) throws CloneNotSupportedException {
         try {
            return new NastranReader((NastranReader)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 {
         ((NastranReader)copy).deepCloneReferences((NastranReader)orig, _helper);
         return false;
      }
      public Class getType() {
         return NastranReader.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 NastranReader(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(NastranReader._SIZE);
      byte[] _buffer = _stream.getBuffer();
      int _pos = _stream.getPosition();
      this.cnum = 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(NastranReader._SIZE);
      this.nextline = (java.lang.String)_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(NastranReader._SIZE);
      byte[] _buffer = _stream.getBuffer();
      int _pos = _stream.getPosition();
      _pos = uka.transport.BasicIO.insert(_buffer, _pos, this.cnum);
      _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.nextline);
      _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 NastranReader(NastranReader _orig, int _id, uka.transport.DeepClone _helper) throws CloneNotSupportedException, java.io.IOException {
      super(_orig, _id, _helper);
      this.cnum = _orig.cnum;
      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(NastranReader _orig, uka.transport.DeepClone _helper) throws CloneNotSupportedException {
      super.deepCloneReferences(_orig, _helper);
      this.nextline = (java.lang.String)_helper.internalDeepClone(_orig.nextline);
      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 = {"BEGIN", "ENDDATA"};
   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 String nextline;
   private int cnum;
   public NastranReader(String fn) {
      super();
      int i;
      this.filename = new String(fn);
      this.cnum = 0;
   }
   public void close() {
      try {
         this.br.close();
      }  catch (IOException ioe) {
         System.out.println("An IOException has occurred when closing the indata file");
         return;
      }
   }
   public void close2() {
      try {
         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, 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, 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;
      Element temporary_element;
      String element_type;
      String property_type;
      Token[] t;
      Token[] t2;
      element_type = "";
      property_type = "";
      t2 = null;
      try {
         while (this.str.nextToken() != java.io.StreamTokenizer.TT_EOF) {
            if (this.str.ttype == java.io.StreamTokenizer.TT_WORD) {
               if (this.str.sval.toUpperCase().replaceAll(",", " ").trim().equals("CBAR")) {
                  element_type = "ROD_2";
                  property_type = "PBAR";
                  this.in_block = true;
                  break;
               }
               if (this.str.sval.toUpperCase().replaceAll(",", " ").trim().equals("CQUAD4")) {
                  element_type = "SHELL_BT_4";
                  property_type = "PSHELL";
                  this.in_block = true;
                  break;
               }
               if (this.str.sval.toUpperCase().replaceAll(",", " ").trim().equals("CTRIA3")) {
                  element_type = "SHELL_C0_3";
                  property_type = "PSHELL";
                  this.in_block = true;
                  break;
               }
               if (this.str.sval.toUpperCase().replaceAll(",", " ").trim().equals("CHEXA")) {
                  element_type = "SOLID_ISO_6";
                  property_type = "PSOLID";
                  this.in_block = true;
                  break;
               }
               if (this.str.sval.toUpperCase().replaceAll(",", " ").trim().equals("CTETRA")) {
                  element_type = "SOLID_ISO_4";
                  property_type = "PSOLID";
                  this.in_block = true;
                  break;
               }
            }
         }
         if (!this.in_block) {
            throw new java.text.ParseException("No known element type found", this.str.lineno());
         }
         temporary_element = Element.getElementOfType_Fembic(element_type);
         t = tokenize(this.br, 8, this.str.sval.toUpperCase().replaceAll(",", " ").trim());
         this.open2();
         while (this.str2.nextToken() != java.io.StreamTokenizer.TT_EOF) {
            if (this.str2.ttype == java.io.StreamTokenizer.TT_WORD) {
               if (this.str2.sval.toUpperCase().replaceAll(",", " ").trim().equals(property_type)) {
                  t2 = tokenize(this.br2, 8, property_type);
                  if (t2[1].getn() == t[2].getn()) {
                     this.in_block2 = true;
                     break;
                  }
               }
            }
         }
         if (!this.in_block2) {
            close2();
            throw new java.text.ParseException("No known element property type found", this.str.lineno());
         }
         close2();
         temporary_element.parse_Nastran(t, t2, this.str.lineno(), nodelist, materiallist, loadlist);
         temporary_element.checkIndata();
         return 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 {
      boolean tracker_type_exists;
      int index;
      Tracker temporary_tracker;
      String arg1;
      String arg2;
      String arg3;
      try {
         while (this.str.nextToken() == java.io.StreamTokenizer.TT_EOL) {
            {
            }
         }
         this.str.pushBack();
         while (this.str.nextToken() != java.io.StreamTokenizer.TT_NUMBER) {
            this.str.pushBack();
            this.tracker_in_block = false;
            while (this.str.nextToken() != java.io.StreamTokenizer.TT_EOF) {
               if (this.str.ttype == java.io.StreamTokenizer.TT_WORD) {
                  if (this.str.sval.toUpperCase().equals("TRACKERS")) {
                     if (this.str.nextToken() == java.io.StreamTokenizer.TT_WORD) {
                        if (this.str.sval.toUpperCase().equals("OF")) {
                           {
                           }
                        } else {
                           throw new java.text.ParseException("No \'OF\' defined in tracker block header", this.str.lineno());
                        }
                     }
                     if (this.str.nextToken() == java.io.StreamTokenizer.TT_WORD) {
                        if (this.str.sval.toUpperCase().equals("TYPE")) {
                           {
                           }
                        } else {
                           throw new java.text.ParseException("No \'TYPE\' defined in tracker block header", this.str.lineno());
                        }
                     }
                     if (this.str.nextToken() == java.io.StreamTokenizer.TT_WORD) {
                        this.current_tracker_type = new String(this.str.sval.toUpperCase());
                     } else {
                        throw new java.text.ParseException("Unknown type defined in tracker block header", this.str.lineno());
                     }
                     System.out.println("Tracker block found!");
                     this.tracker_in_block = true;
                     this.str.nextToken();
                     break;
                  }
               }
            }
         }
         if (!this.tracker_in_block) {
            throw new java.text.ParseException("No trackers block found or missing trackers", this.str.lineno());
         }
         temporary_tracker = Tracker.getTrackerOfType_Fembic(this.current_tracker_type);
         temporary_tracker.setNumber((int)this.str.nval);
         tracker_type_exists = true;
         temporary_tracker.parse_Fembic(tokenize(this.str), this.str.lineno(), nodelist, elementlist);
         temporary_tracker.checkIndata();
         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;
      Constraint temporary_constraint;
      Token[] t;
      try {
         while (this.str.nextToken() != this.str.TT_EOF) {
            if (this.str.ttype == this.str.TT_WORD && this.str.sval.toUpperCase().replaceAll(",", " ").trim().equals("SPC1")) {
               this.cnum++;
               temporary_constraint = Constraint.getConstraintOfType_Nastran(this.str.sval.toUpperCase().replaceAll(",", " ").trim());
               t = tokenize(this.br, 8, this.str.sval.toUpperCase().replaceAll(",", " ").trim());
               temporary_constraint.parse_Nastran(t, this.cnum, nodelist);
               temporary_constraint.checkIndata();
               return (Constraint)temporary_constraint;
            }
         }
         return null;
      }  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 {
      return null;
   }
   public Material getNextMaterial() throws java.text.ParseException, Error {
      int index;
      Material temporary_material;
      try {
         while (this.str.nextToken() != java.io.StreamTokenizer.TT_EOF) {
            if (this.str.ttype == java.io.StreamTokenizer.TT_WORD) {
               if (this.str.sval.toUpperCase().replaceAll(",", " ").trim().equals("MAT1")) {
                  this.in_block = true;
                  break;
               }
            }
         }
         if (!this.in_block) {
            throw new java.text.ParseException("No MAT1 found or missing materials", this.str.lineno());
         }
         temporary_material = Material.getMaterialOfType_Nastran(this.str.sval.toUpperCase().replaceAll(",", " ").trim());
         temporary_material.parse_Nastran(tokenize(this.br, 8, "MAT1"), this.str.lineno());
         temporary_material.checkIndata();
         return 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 Node getNextNode(RplVector constraintlist, RplVector loadlist) throws java.text.ParseException, Error {
      int index;
      Constraint temp_constraint;
      Load temp_load;
      try {
         while (this.str.nextToken() != java.io.StreamTokenizer.TT_EOF) {
            if (this.str.ttype == java.io.StreamTokenizer.TT_WORD) {
               if (this.str.sval.toUpperCase().replaceAll(",", " ").trim().equals("GRID")) {
                  this.in_block = true;
                  break;
               }
            }
         }
         if (!this.in_block) {
            throw new java.text.ParseException("No nodes block found or missing nodes", this.str.lineno());
         }
         this.temporary_node = new Node();
         this.temporary_node.parse_Nastran(tokenize(this.br, 8, "GRID"), this.str.lineno(), constraintlist, loadlist);
         this.temporary_node.checkIndata();
         return 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 < this.keywords.length; i++) {
         if (this.keywords[i].equals(param.toUpperCase())) {
            return true;
         }
      }
      return false;
   }
   public int numberOfConstraints() throws java.text.ParseException {
      int noc = 0;
      this.open();
      try {
         while (this.str.nextToken() != this.str.TT_EOF) {
            if (this.str.ttype == this.str.TT_WORD && this.str.sval.replace(',', ' ').trim().equals("SPC1")) 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 (this.str.nextToken() != this.str.TT_EOF) {
            if (this.str.ttype == this.str.TT_WORD && this.str.sval.replace(',', ' ').trim().equals("CQUAD4")) noe++;
            if (this.str.ttype == this.str.TT_WORD && this.str.sval.replace(',', ' ').trim().equals("CTRIA3")) noe++;
            if (this.str.ttype == this.str.TT_WORD && this.str.sval.replace(',', ' ').trim().equals("CBAR")) noe++;
            if (this.str.ttype == this.str.TT_WORD && this.str.sval.replace(',', ' ').trim().equals("CHEXA")) noe++;
            if (this.str.ttype == this.str.TT_WORD && this.str.sval.replace(',', ' ').trim().equals("CTETRA")) noe++;
         }
         System.out.println("Found " + noe + " elements");
      }  catch (IOException ioe) {
         System.out.println("IOException when reading an element 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;
      not = 0;
      System.out.println("Found " + not + " trackers");
      return not;
   }
   public int numberOfLoads() throws java.text.ParseException {
      int noc = 0;
      this.close();
      return noc;
   }
   public int numberOfMaterials() throws java.text.ParseException {
      int nom = 0;
      this.open();
      try {
         while (this.str.nextToken() != this.str.TT_EOF) {
            if (this.str.ttype == this.str.TT_WORD && this.str.sval.replace(',', ' ').trim().equals("MAT1")) nom++;
         }
         System.out.println("Found " + nom + " materials");
      }  catch (IOException ioe) {
         System.out.println("IOException when reading a material 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 (this.str.nextToken() != this.str.TT_EOF) {
            if (this.str.ttype == this.str.TT_WORD && this.str.sval.replace(',', ' ').trim().equals("GRID")) non++;
         }
         System.out.println("Found " + non + " nodes");
      }  catch (IOException ioe) {
         System.out.println("IOException when reading a node 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 open2() {
      FileReader fr;
      this.in_block2 = false;
      try {
         fr = new FileReader(this.filename);
      }  catch (FileNotFoundException fnfe) {
         System.out.println("Fembic file does not exist");
         return;
      }
      try {
         this.br2 = new BufferedReader(fr);
      }  catch (IllegalArgumentException ioe) {
         System.out.println("An IllegalArgumentException has occurred when opening the indata file");
         return;
      }
      this.str2 = new ModifiedStreamTokenizer(this.br2);
   }
   public void open() {
      FileReader fr;
      this.in_block = false;
      this.control_in_block = false;
      this.constraint_in_block = false;
      this.element_in_block = false;
      try {
         fr = new FileReader(this.filename);
      }  catch (FileNotFoundException fnfe) {
         System.out.println("Fembic file does not exist");
         return;
      }
      try {
         this.br = new BufferedReader(fr);
      }  catch (IllegalArgumentException ioe) {
         System.out.println("An IllegalArgumentException has occurred when opening the indata file");
         return;
      }
      this.str = new ModifiedStreamTokenizer(this.br);
   }
   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);
      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 Token[] tokenize(BufferedReader str, int number_of_chars, String intro) throws IOException {
      int i;
      int j;
      String temp;
      Vector v = new Vector();
      Token[] arr;
      Token temptok;
      boolean looping = false;
      do {
         try {
            temp = str.readLine().replaceAll(",", " , ");
            if (looping == false) if (temp.indexOf(",") > -1 && temp.indexOf(",") != 1) temp = intro + "," + temp; else temp = intro + " " + temp;
         }  catch (IOException ioe) {
            System.out.println("IOException when trying to generate tokens from indata file");
            this.close();
            return null;
         }
         if (number_of_chars == 0 || temp.indexOf(",") > -1) {
            j = 0;
            i = temp.indexOf(",", j);
            while (i > -1) {
               temptok = new Token(temp.substring(j, i));
               v.add(temptok);
               j = i + 1;
               i = temp.indexOf(",", j);
            }
            v.add(new Token(temp.substring(j, temp.length())));
         } else {
            for (i = 0; i < temp.length(); i += number_of_chars) v.add(new Token(temp.substring(i, i + number_of_chars <= temp.length() ? i + number_of_chars : temp.length())));
         }
         looping = true;
      }       while (((Token)v.lastElement()).is_a_word() && ((Token)v.lastElement()).getw().startsWith("+"));
      for (i = v.size() - 1; i > -1; i--) {
         temptok = (Token)v.elementAt(i);
         if (temptok.is_a_word() && temptok.getw().startsWith("+")) v.removeElementAt(i);
      }
      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 {
      this.open2();
   }
}
