laminat.java

laminat.java — Java source code, 87 kB (89.123 bytes)

Dateiinhalt

/***********************************************************************
 * laminat.java
 *
 * Programm zur Berechnung der elastischen Eigenschaften von Laminaten
 * nach der klassischen Laminattheorie.
 *
 * 21.07.2000
 * Helmut Rapp
 * Institut fuer Aerospace Technologie
 * Hochschule Bremen
 * Neustadtswall 30
 * D-28201 Bremen
 *
 * e-mail: rapp@fbm.hs-bremen.de
 * URL:    http://mlbf01.fbm.hs-bremen.de
 *
 ************************************************************************/

import java.awt.*;
import java.awt.event.*;
import java.text.*;
import java.io.*;
import java.applet.*;

public class laminat extends java.applet.Applet{
  /** Main Class */
  static Frame f          = new Frame("Classical Laminate Theory with JAVA");
  static Frame file_load  = new Frame("Save/Load laminate definiton");
  Label lab_no        = new Label("Layer No.");
  Label lab_ftyp      = new Label("Fiber");
  Label lab_mtyp      = new Label("Matrix");
  Label lab_ang       = new Label("Angle");
  Label lab_thick     = new Label("Thickness");
  Label lab_cont      = new Label("Vol.Cont.");
  Label lab_tref      = new Label("z reference:");
  Label load_no       = new Label("Load Case:");
  Label load_l1       = new Label("nx");
  Label load_l2       = new Label("ny");
  Label load_l3       = new Label("nxy");
  Label load_l4       = new Label("mx");
  Label load_l5       = new Label("my");
  Label load_l6       = new Label("mxy");
  Label load_l7       = new Label("DeltaT");
  static Label lab_tges      = new Label("Laminate Thickness: 0.0");

         Button lay_ok       = new Button("Layer OK");
         Button load_ok      = new Button("Load OK");
         Button mb           = new Button("Analyse Laminate");
  static TextField lay_no    = new TextField(4);
  static TextField lay_ang   = new TextField(10);
  static TextField lay_thick = new TextField(10);
  static TextField lay_cont  = new TextField(10);
  static TextField lam_tref  = new TextField(10);
  static TextField load_v0   = new TextField(4);
  static TextField load_v1   = new TextField(6);
  static TextField load_v2   = new TextField(6);
  static TextField load_v3   = new TextField(6);
  static TextField load_v4   = new TextField(6);
  static TextField load_v5   = new TextField(6);
  static TextField load_v6   = new TextField(6);
  static TextField load_v7   = new TextField(6);
         String     str      = new String();
  static List  lam_def       = new List(11, false);
  static List load_list      = new List(6, false);
  static Choice lay_fiber    = new Choice();
  static Choice lay_matrix   = new Choice();
  static TextArea ud_list    = new TextArea("UD-List Area",10,40,
                                          TextArea.SCROLLBARS_VERTICAL_ONLY);
  static TextArea lam_list   = new TextArea("Laminate listing area",23,80,
                                          TextArea.SCROLLBARS_VERTICAL_ONLY);
  //static TextArea image      = new TextArea("  ",3,10,3);
  static Label image      = new Label("JavaLam");
  //static Panel image      = new Panel();

  static DecimalFormatSymbols locsym  = new DecimalFormatSymbols();
  static DecimalFormat f82   = new DecimalFormat("#######0.00",locsym);
  static DecimalFormat f84   = new DecimalFormat("#####0.0000",locsym);
  static String blanks       = new String("                         ");

  static Verbund verbund     = new Verbund();

  static int n_lage      = 0;
  static int n_lag_max   = 0;
  static double tges     = 0.0;
  static int n_loads     = 0;
  static int n_load_max  = 0;
  static int fail_crit   = 0;

/**
 * Building the program window and user interface.
 */
  public void init(){

     HandleButton he;
     
     GridBagLayout gbl      = new GridBagLayout();
     GridBagConstraints gbc = new GridBagConstraints();

     MenuBar meba = new MenuBar();
     f.setMenuBar(meba);
     Menu help = new Menu("Help");
     meba.add(help);
     meba.setHelpMenu(help);

     Menu files = new Menu("File");
     meba.add(files);
     MenuItem new_lam = new MenuItem("New Laminate");
     he               = new HandleButton(this, "New");
     new_lam.addActionListener(he);
     files.add(new_lam);
     MenuItem load_lam= new MenuItem("Load");
     he               = new HandleButton(this, "Load");
     load_lam.addActionListener(he);
     files.add(load_lam);
     MenuItem save_lam= new MenuItem("Save");
     he               = new HandleButton(this, "Save");
     save_lam.addActionListener(he);
     files.add(save_lam);
     MenuItem print_lam= new MenuItem("Print");
     he                = new HandleButton(this, "Print");
     print_lam.addActionListener(he);
     files.add(print_lam);
     MenuItem quit = new MenuItem("Quit");
     he            = new HandleButton(this, "Quit");
     quit.addActionListener(he);
     files.add(quit);

     Menu edit = new Menu("Edit Layer");
     meba.add(edit);
     MenuItem del_lay = new MenuItem("Delete Layer", new MenuShortcut('d'));
     he               = new HandleButton(this, "LayDelete");
     del_lay.addActionListener(he);
     edit.add(del_lay);
     MenuItem ins_lay = new MenuItem("Insert Layer", new MenuShortcut('i'));
     he               = new HandleButton(this, "LayInsert");
     ins_lay.addActionListener(he);
     edit.add(ins_lay);

     Menu loads = new Menu("Loads");
     meba.add(loads);
     MenuItem del_load = new MenuItem("Delete Loadcase",new MenuShortcut('r'));
     he                = new HandleButton(this, "LoadDelete");
     del_load.addActionListener(he);
     loads.add(del_load);
     MenuItem ins_load = new MenuItem("Insert Loadcase",new MenuShortcut('a'));
     he                = new HandleButton(this, "LoadInsert");
     ins_load.addActionListener(he);
     loads.add(ins_load);

     Menu fail = new Menu("Failure Criteria");
     meba.add(fail);
     MenuItem none = new MenuItem("None",new MenuShortcut('z'));
     he              = new HandleButton(this, "None");
     none.addActionListener(he);
     fail.add(none);
     MenuItem tsaiwu = new MenuItem("Tsai Wu mod",new MenuShortcut('t'));
     he              = new HandleButton(this, "TsaiWu");
     tsaiwu.addActionListener(he);
     fail.add(tsaiwu);
     MenuItem halpin = new MenuItem("Halpin",new MenuShortcut('h'));
     he              = new HandleButton(this, "Halpin");
     halpin.addActionListener(he);
     fail.add(halpin);
     MenuItem puckneu = new MenuItem("Puck (new)",new MenuShortcut('p'));
     he               = new HandleButton(this, "Puck");
     puckneu.addActionListener(he);
     fail.add(puckneu);
     MenuItem maxstr = new MenuItem("Max. Stress",new MenuShortcut('s'));
     he              = new HandleButton(this, "MaxStress");
     maxstr.addActionListener(he);
     fail.add(maxstr);

     he              = new HandleButton(this, "LamDef");
     lam_def.addActionListener(he);

     he              = new HandleButton(this, "LoadDef");
     load_list.addActionListener(he);

     lay_fiber.addItem("E-Glas");
     lay_fiber.addItem("T300");
     lay_fiber.addItem("T800");
     lay_fiber.addItem("Kevlar");
     lay_fiber.addItem("M40");
     //lay_fiber.addItem("Aluminium");
     //lay_fiber.addItem("Foam C60");
     lay_matrix.addItem("Epoxy");
     lay_matrix.addItem("Polyester");
     lay_matrix.addItem("Polyimid");
     

     f.setLayout(gbl);
     gbc.fill = GridBagConstraints.BOTH;
     gbc.gridy = 0;
     gbc.weightx = 10;
     gbc.weighty = 100;
     gbc.anchor = GridBagConstraints.CENTER;
     gbc.gridwidth = 1;
     gbl.setConstraints(lab_no, gbc);
     gbc.weightx = 100;
     gbc.gridwidth = 2;
     gbl.setConstraints(lab_ftyp, gbc);
     gbc.gridwidth = 2;
     gbl.setConstraints(lab_mtyp, gbc);
     gbc.gridwidth = 2;
     gbl.setConstraints(lab_ang, gbc);
     gbc.gridwidth = 2;
     gbl.setConstraints(lab_thick, gbc);
     gbc.gridwidth = 6;
     gbl.setConstraints(lab_cont, gbc);

     gbc.gridy = 1;
     gbc.gridwidth = 1;
     gbc.weighty = 100;
     gbl.setConstraints(lay_fiber, gbc);
     gbc.gridwidth = 2;
     gbl.setConstraints(lay_matrix, gbc);
     gbc.gridwidth = 2;
     gbl.setConstraints(lay_no, gbc);
     gbc.gridwidth = 2;
     gbl.setConstraints(lay_ang, gbc);
     gbc.gridwidth = 2;
     gbl.setConstraints(lay_thick, gbc);
     gbc.gridwidth = 2;
     gbl.setConstraints(lay_cont, gbc);
     gbc.gridwidth = 4;
     gbl.setConstraints(lay_ok, gbc);

     gbc.gridy = 2;
     gbc.gridwidth = 1;
     gbc.weighty = 10;
     gbl.setConstraints(load_no, gbc);
     gbc.gridwidth = 2;
     gbl.setConstraints(load_l1, gbc);
     gbc.gridwidth = 2;
     gbl.setConstraints(load_l2, gbc);
     gbc.gridwidth = 2;
     gbl.setConstraints(load_l3, gbc);
     gbc.gridwidth = 2;
     gbl.setConstraints(load_l4, gbc);
     gbc.gridwidth = 2;
     gbl.setConstraints(load_l5, gbc);
     gbc.gridwidth = 2;
     gbl.setConstraints(load_l6, gbc);
     gbc.gridwidth = 2;
     gbl.setConstraints(load_l7, gbc);

     gbc.gridy = 3;
     gbc.gridwidth = 1;
     gbc.weighty = 100;
     gbl.setConstraints(load_v0, gbc);
     gbc.gridwidth = 2;
     gbl.setConstraints(load_v1, gbc);
     gbc.gridwidth = 2;
     gbl.setConstraints(load_v2, gbc);
     gbc.gridwidth = 2;
     gbl.setConstraints(load_v3, gbc);
     gbc.gridwidth = 2;
     gbl.setConstraints(load_v4, gbc);
     gbc.gridwidth = 2;
     gbl.setConstraints(load_v5, gbc);
     gbc.gridwidth = 2;
     gbl.setConstraints(load_v6, gbc);
     gbc.gridwidth = 1;
     gbl.setConstraints(load_v7, gbc);
     gbc.gridwidth = 1;
     gbl.setConstraints(load_ok, gbc);

     gbc.gridy = 4;
     gbc.gridwidth = 3;
     gbl.setConstraints(lab_tges, gbc);
     gbc.gridwidth = 2;
     gbl.setConstraints(lab_tref, gbc);
     gbl.setConstraints(lam_tref, gbc);
     gbc.gridwidth = 10;
     gbl.setConstraints(mb, gbc);

     gbc.gridy = 5;
     gbc.gridx = 0;
     gbc.weighty = 0;
     gbc.gridwidth = 7;
     gbl.setConstraints(lam_def, gbc);
     gbc.gridx = 7;
     gbc.gridwidth = 8;
     gbl.setConstraints(ud_list, gbc);

     gbc.gridy = 6;
     gbc.gridx = 0;
     gbc.gridwidth = 9;
     gbl.setConstraints(load_list, gbc);
     gbc.gridx = 9;
     gbc.gridwidth = 6;
     gbl.setConstraints(image, gbc);

     gbc.gridy = 7;
     gbc.gridx = 0;
     gbc.gridwidth = 15;
     gbl.setConstraints(lam_list, gbc);


     he     = new HandleButton(this, "Layer OK");
     lay_ok.addActionListener(he); 
     he     = new HandleButton(this, "Load OK");
     load_ok.addActionListener(he); 
     he     = new HandleButton(this, "Analyse");
     mb.addActionListener(he); 

     f.add(load_v0);
     f.add(load_v1);
     f.add(load_v2);
     f.add(load_v3);
     f.add(load_v4);
     f.add(load_v5);
     f.add(load_v6);
     f.add(load_v7);
     f.add(load_ok);
     f.add(lab_no);
     f.add(lab_ftyp);
     f.add(lab_mtyp);
     f.add(lab_ang);
     f.add(lab_thick);
     f.add(lab_cont);
     f.add(lay_no);
     f.add(lay_fiber);
     f.add(lay_matrix);
     f.add(lay_ang);
     f.add(lay_thick);
     f.add(lay_cont);
     f.add(load_no);
     f.add(load_l1);
     f.add(load_l2);
     f.add(load_l3);
     f.add(load_l4);
     f.add(load_l5);
     f.add(load_l6);
     f.add(load_l7);
     f.add(image);
     f.add(lab_tges);
     f.add(lab_tref);
     f.add(lam_tref);
     f.add(lam_def);
     f.add(ud_list);
     f.add(load_list);
     f.add(lay_ok);
     f.add(mb);
     f.add(lam_list);

     lay_no.setText("1");
     lay_ang.setText("0.0");
     lay_thick.setText("1.0");
     lay_cont.setText("60.0");
     lam_tref.setText("0.0");
     load_v0.setText("1");
     load_v1.setText("0.0");
     load_v2.setText("0.0");
     load_v3.setText("0.0");
     load_v4.setText("0.0");
     load_v5.setText("0.0");
     load_v6.setText("0.0");
     load_v7.setText("0.0");

     //lam_list.setBackground(Color.blue);
     //lam_list.setForeground(Color.yellow);
     lay_ok.setBackground(Color.red);
     lay_ok.setForeground(Color.yellow);
     load_ok.setBackground(Color.red);
     load_ok.setForeground(Color.yellow);
     mb.setBackground(Color.red);
     mb.setForeground(Color.yellow);

     f.setFont(new Font("Serif", Font.BOLD, 12));
     lam_def.setFont(new Font("Monospaced", Font.PLAIN, 12));
     load_list.setFont(new Font("Monospaced", Font.PLAIN, 12));
     ud_list.setFont(new Font("Monospaced", Font.PLAIN, 12));
     lam_list.setFont(new Font("Monospaced", Font.PLAIN, 12));
     ud_list.setEditable(false);
     lam_list.setEditable(false);

     image.setBackground(Color.lightGray);
     image.setForeground(Color.white);
     image.setFont(new Font("Serif", Font.BOLD + Font.ITALIC, 24));
     image.setText("   JavaLam, Version 0.3, 21 Jul 2000");
     //image.setFont(new Font("TimesRoman", Font.BOLD, 12));
     //image.append("  iat - Hochschule Bremen" + '\n');
     //image.setFont(new Font("Times Roman", Font.BOLD + Font.ITALIC, 18));
     //image.append("  Structural Analysis & Design" + '\n');

     f.setResizable(true);
     f.setSize(900,850);
     //f.pack();
     f.toFront();
     f.show();

     Fiber.init();
     Matrix.init();
     verbund.init();

  }

/**
 * Adding a layer to the current end of the laminate defintion.
 */
  public static void addLayer() {
      n_lage = Integer.valueOf(lay_no.getText()).intValue();
      if (n_lag_max < 20 | n_lage < n_lag_max){
        if (n_lage <= n_lag_max) {
	  lam_def.replaceItem(new StringBuffer
              ("                                                           ").
                    insert(0,String.valueOf(n_lage)).
                    insert(5,lay_fiber.getSelectedItem()).
                    insert(17,lay_matrix.getSelectedItem()).
                    insert(29,lay_ang.getText()).
                    insert(39,lay_thick.getText()).
                    insert(49,lay_cont.getText()).toString().trim(),n_lage-1);
	  Verbund.replaceLayer(n_lage,
			 lay_fiber.getSelectedItem(),
			 lay_matrix.getSelectedItem(),
			 Double.valueOf(lay_ang.getText()).doubleValue(),
			 Double.valueOf(lay_thick.getText()).doubleValue(),
			 Double.valueOf(lay_cont.getText()).doubleValue());
	}
        else {
	  if (n_lage > n_lag_max+1) n_lage = n_lag_max + 1;
        lam_def.addItem(new StringBuffer
              ("                                                            ").
                     insert(0,String.valueOf(n_lage)).
                     insert(5,lay_fiber.getSelectedItem()).
                     insert(17,lay_matrix.getSelectedItem()).
                     insert(29,lay_ang.getText()).
                     insert(39,lay_thick.getText()).
                     insert(49,lay_cont.getText()).toString().trim(),n_lage-1);
	n_lag_max += 1;
	Verbund.addLayer(n_lage,
			 lay_fiber.getSelectedItem(),
			 lay_matrix.getSelectedItem(),
			 Double.valueOf(lay_ang.getText()).doubleValue(),
			 Double.valueOf(lay_thick.getText()).doubleValue(),
			 Double.valueOf(lay_cont.getText()).doubleValue());
	}
        lay_no.setText(String.valueOf(n_lage+1));

        tges   = verbund.getThick();
        lam_tref.setText(String.valueOf(tges/2.));
        lab_tges.setText("Laminate Thickness: " + tges);
        UdLayer.init(verbund.getFiber(n_lage),
		     verbund.getMatrix(n_lage),
		     verbund.getVolcont(n_lage));
        double strength[] = new double [5];
        Fiber.getStrength(verbund.getFiber(n_lage), strength);
        ud_list.setText(" ");
        ud_list.append("Properties of layer " + n_lage + 
                           " in fiber coordinate system:" + '\n');
        ud_list.append("  E_par       = " +
          blanks.substring(0, 12 - f82.format(UdLayer.getEpar()).length())
                                  +f82.format(UdLayer.getEpar())+
                      "    Strength at 60% fiber volume content: " + '\n');
        ud_list.append("  E_perp      = " +
          blanks.substring(0, 12 - f82.format(UdLayer.getEperp()).length())
                                  +f82.format(UdLayer.getEperp())+
                   "        sig_par_tension  = " + strength[0] + '\n');
        ud_list.append("  G_pp        = " +
          blanks.substring(0, 12 - f82.format(UdLayer.getGpp()).length())
                               +f82.format(UdLayer.getGpp())+
                   "        sig_par_compres  = " + strength[1] + '\n');
        ud_list.append("  Nue_ps      = " +
          blanks.substring(0, 12 - f84.format(UdLayer.getNueps()).length())
                               +f84.format(UdLayer.getNueps())+
                   "        sig_perp_tension = " + strength[2] + '\n');
        ud_list.append("  Alpha_par   = " +
                   blanks.substring(0, 8 - 
                   f84.format(UdLayer.getAlphapar()*1.e6).length()) +
                   f84.format(UdLayer.getAlphapar()*1.e6)+"E-06" +
                   "        sig_perp_compres = " + strength[3] + '\n');
        ud_list.append("  Alpha_perp  = " +
                   blanks.substring(0, 8 - 
                   f84.format(UdLayer.getAlphasenk()*1.e6).length()) +
                   f84.format(UdLayer.getAlphasenk()*1.e6)+"E-06" +
                   "        tau_pp           = " + strength[4] + '\n');
        double stmat [][] = new double [3][3];
        UdLayer.getSteif(stmat);
        ud_list.append('\n'+" Stiffness Matrix:"+'\n');
        for (int i=0; i<3; i++){
        ud_list.append(
             blanks.substring(0, 11 - f82.format(stmat[0][i]).length())
                                     +f82.format(stmat[0][i])+
             blanks.substring(0, 11 - f82.format(stmat[1][i]).length())
                                     +f82.format(stmat[1][i])+
             blanks.substring(0, 11 - f82.format(stmat[2][i]).length())
                                     +f82.format(stmat[2][i])+'\n');
	}
      }
  }

/**
 * Adding a loadcase to the current laminate loading.
 */
  public static void addLoad() {
      n_loads = Integer.valueOf(load_v0.getText()).intValue();
      if (n_load_max < 10 | n_loads < n_load_max){
        if (n_loads <= n_load_max) {
	  load_list.replaceItem(new StringBuffer
              ("                                                           ").
                    insert(0,String.valueOf(n_loads)).
                    insert( 5,load_v1.getText()).
                    insert(15,load_v2.getText()).
                    insert(25,load_v3.getText()).
                    insert(35,load_v4.getText()).
                    insert(45,load_v5.getText()).
                    insert(55,load_v6.getText()).
                    insert(65,load_v7.getText()).toString().trim(),n_loads-1);
	  Verbund.replaceLoads(n_loads,
			 Double.valueOf(load_v1.getText()).doubleValue(),
			 Double.valueOf(load_v2.getText()).doubleValue(),
			 Double.valueOf(load_v3.getText()).doubleValue(),
			 Double.valueOf(load_v4.getText()).doubleValue(),
			 Double.valueOf(load_v5.getText()).doubleValue(),
			 Double.valueOf(load_v6.getText()).doubleValue(),
			 Double.valueOf(load_v7.getText()).doubleValue());
	}
        else {
	  if (n_loads > n_load_max+1) n_loads = n_load_max + 1;
        load_list.addItem(new StringBuffer
              ("                                                            ").
                    insert(0,String.valueOf(n_loads)).
                    insert( 5,load_v1.getText()).
                    insert(15,load_v2.getText()).
                    insert(25,load_v3.getText()).
                    insert(35,load_v4.getText()).
                    insert(45,load_v5.getText()).
                    insert(55,load_v6.getText()).
                    insert(65,load_v7.getText()).toString().trim(),n_loads-1);
	n_load_max += 1;
	Verbund.addLoads(n_loads,
			 Double.valueOf(load_v1.getText()).doubleValue(),
			 Double.valueOf(load_v2.getText()).doubleValue(),
			 Double.valueOf(load_v3.getText()).doubleValue(),
			 Double.valueOf(load_v4.getText()).doubleValue(),
			 Double.valueOf(load_v5.getText()).doubleValue(),
			 Double.valueOf(load_v6.getText()).doubleValue(),
			 Double.valueOf(load_v7.getText()).doubleValue());
	}
      load_v0.setText(String.valueOf(n_loads+1));
      }
  }

/**
 * Analsis of the laminate considering the classical laminate theory.
 */
  public static void analyse() {
      verbund.analyse(Double.valueOf(lam_tref.getText()).doubleValue());
      double vsteif [][] = new double [6][6];
      verbund.getSteif(vsteif);
      lam_list.setText("Properties of the laminate: "+'\n');
      lam_list.append('\n'+"  Number of layers       : "+
                                                verbund.getNLayers()+'\n');
      lam_list.append("  Thickness of laminate  : "+
                                                verbund.getThick()+'\n');
      lam_list.append("  Coordinate of ref.plane: "+
                                                lam_tref.getText()+'\n');
      lam_list.append('\n'+"  Ex       : "+
             blanks.substring(0, 11 - f82.format(verbund.getEx()).length())
                                     +f82.format(verbund.getEx())+
                               "       Alpha x  : " +
                   blanks.substring(0, 9 - 
                   f84.format(Verbund.alpha[0]*1.e6).length()) +
                   f84.format(Verbund.alpha[0]*1.e6)+"E-06" +'\n');
      lam_list.append("  Ey       : "+
             blanks.substring(0, 11 - f82.format(verbund.getEy()).length())
                                     +f82.format(verbund.getEy())+
                               "       Alpha y  : " +
                   blanks.substring(0, 9 - 
                   f84.format(Verbund.alpha[1]*1.e6).length()) +
                   f84.format(Verbund.alpha[1]*1.e6)+"E-06" +'\n');
      lam_list.append("  Gxy      : "+
             blanks.substring(0, 11 - f82.format(verbund.getGxy()).length())
                                     +f82.format(verbund.getGxy())+
                               "       Alpha xy : " +
                   blanks.substring(0, 9 - 
                   f84.format(Verbund.alpha[2]*1.e6).length()) +
                   f84.format(Verbund.alpha[2]*1.e6)+"E-06" +'\n');
      lam_list.append("  Nuexy    : "+
             blanks.substring(0, 11 - f84.format(verbund.getNuexy()).length())
                                     +f84.format(verbund.getNuexy())+
                               "       Kappa x  : " +
                   blanks.substring(0, 9 - 
                   f84.format(Verbund.alpha[3]*1.e6).length()) +
                   f84.format(Verbund.alpha[3]*1.e6)+"E-06" +'\n');
      lam_list.append("  Nueyx    : "+
             blanks.substring(0, 11 - f84.format(verbund.getNueyx()).length())
                                     +f84.format(verbund.getNueyx())+
                               "       Kappa y  : " +
                   blanks.substring(0, 9 - 
                   f84.format(Verbund.alpha[4]*1.e6).length()) +
                   f84.format(Verbund.alpha[4]*1.e6)+"E-06" +'\n');
      lam_list.append("  Density  : "+
             blanks.substring(0, 11 - f84.format(verbund.getDens()).length())
                                     +f84.format(verbund.getDens())+
                               "       Kappa xy : " +
                   blanks.substring(0, 9 - 
                   f84.format(Verbund.alpha[5]*1.e6).length()) +
                   f84.format(Verbund.alpha[5]*1.e6)+"E-06" +'\n');
      lam_list.append('\n'+"Stiffness Matrix:"+'\n');
      for (int i=0; i<6; i++){
         lam_list.append(
             blanks.substring(0, 14 - f82.format(vsteif[0][i]).length())
                                     +f82.format(vsteif[0][i])+
             blanks.substring(0, 14 - f82.format(vsteif[1][i]).length())
                                     +f82.format(vsteif[1][i])+
             blanks.substring(0, 14 - f82.format(vsteif[2][i]).length())
                                     +f82.format(vsteif[2][i])+
             blanks.substring(0, 14 - f82.format(vsteif[3][i]).length())
                                     +f82.format(vsteif[3][i])+
             blanks.substring(0, 14 - f82.format(vsteif[4][i]).length())
                                     +f82.format(vsteif[4][i])+
             blanks.substring(0, 14 - f82.format(vsteif[5][i]).length())
                                     +f82.format(vsteif[5][i])+'\n');
	}
      if (Verbund.n_load > 0) {
          lam_list.append('\n'+
                  "Stresses in the individual layers of the laminate:"+'\n');
          if (laminat.fail_crit == 1)
                  lam_list.append(
                  "Failure criteria: Tsai Wu modified"+'\n');
          else if (laminat.fail_crit == 2)
                  lam_list.append(
                  "Failure criteria: Maximum Stress"+'\n');
	  for (int i=0; i<Verbund.n_load; i++) {
	    lam_list.append('\n' + "Load case " + (i+1) + '\n');
	    lam_list.append("Loads:  DeltaT    " +
                          "     nx          ny         nxy" +
                          "          mx          my         mxy" + '\n');
	    lam_list.append("  " + 
                   blanks.substring(0, 12 - 
                   f82.format(Verbund.loads[i][6]).length()) +
                   f82.format(Verbund.loads[i][6])+
                   blanks.substring(0, 11 - 
                   f82.format(Verbund.loads[i][0]).length()) +
                   f82.format(Verbund.loads[i][0])+
                   blanks.substring(0, 12 - 
                   f82.format(Verbund.loads[i][1]).length()) +
                   f82.format(Verbund.loads[i][1])+
                   blanks.substring(0, 12 - 
                   f82.format(Verbund.loads[i][2]).length()) +
                   f82.format(Verbund.loads[i][2])+
                   blanks.substring(0, 12 - 
                   f82.format(Verbund.loads[i][3]).length()) +
                   f82.format(Verbund.loads[i][3])+
                   blanks.substring(0, 12 - 
                   f82.format(Verbund.loads[i][4]).length()) +
                   f82.format(Verbund.loads[i][4])+
                   blanks.substring(0, 12 - 
                   f82.format(Verbund.loads[i][5]).length()) +
                   f82.format(Verbund.loads[i][5]) + '\n');
	    lam_list.append("Laminate strains: " +
                          "  eps_x       eps_y      eps_xy" +
                          "     kappy_x     kappa_y    kappa_xy" + '\n');
	    lam_list.append("             " + 
                   blanks.substring(0, 9 - 
                   f84.format(Verbund.epsilon[i][0]*1.e3).length()) +
                   f84.format(Verbund.epsilon[i][0]*1.e3)+"E-3" +
                   blanks.substring(0, 9 - 
                   f84.format(Verbund.epsilon[i][1]*1.e3).length()) +
                   f84.format(Verbund.epsilon[i][1]*1.e3)+"E-3" +
                   blanks.substring(0, 9 - 
                   f84.format(Verbund.epsilon[i][2]*1.e3).length()) +
                   f84.format(Verbund.epsilon[i][2]*1.e3)+"E-3" +
                   blanks.substring(0, 9 - 
                   f84.format(Verbund.epsilon[i][3]*1.e3).length()) +
                   f84.format(Verbund.epsilon[i][3]*1.e3)+"E-3" +
                   blanks.substring(0, 9 - 
                   f84.format(Verbund.epsilon[i][4]*1.e3).length()) +
                   f84.format(Verbund.epsilon[i][4]*1.e3)+"E-3" +
                   blanks.substring(0, 9 - 
                   f84.format(Verbund.epsilon[i][5]*1.e3).length()) +
                   f84.format(Verbund.epsilon[i][5]*1.e3)+"E-3" + '\n');
	    lam_list.append("Layer stresses:   " +
                          "  sig_x       sig_y      tau_xy" +
                          "     sig_par    sig_perp      tau_pp" + '\n');
	    for (int j=0; j<Verbund.n_layer; j++) {
	    lam_list.append("Layer " + 
                   blanks.substring(0, 2 -
                   String.valueOf(j+1).length()) + (j+1) + " bottom: " + 
                   blanks.substring(0, 8 - 
                   f82.format(Verbund.stress[i][j][0]).length()) +
                   f82.format(Verbund.stress[i][j][0])+
                   blanks.substring(0, 12 - 
                   f82.format(Verbund.stress[i][j][1]).length()) +
                   f82.format(Verbund.stress[i][j][1])+
                   blanks.substring(0, 12 - 
                   f82.format(Verbund.stress[i][j][2]).length()) +
                   f82.format(Verbund.stress[i][j][2])+
                   blanks.substring(0, 12 - 
                   f82.format(Verbund.stress[i][j][6]).length()) +
                   f82.format(Verbund.stress[i][j][6])+
                   blanks.substring(0, 12 - 
                   f82.format(Verbund.stress[i][j][7]).length()) +
                   f82.format(Verbund.stress[i][j][7])+
                   blanks.substring(0, 12 - 
                   f82.format(Verbund.stress[i][j][8]).length()) +
                   f82.format(Verbund.stress[i][j][8])+ '\n');
	    lam_list.append("Layer " +
                   blanks.substring(0, 2 -
                   String.valueOf(j+1).length()) + (j+1) + "    top: " + 
                   blanks.substring(0, 8 - 
                   f82.format(Verbund.stress[i][j][3]).length()) +
                   f82.format(Verbund.stress[i][j][3])+
                   blanks.substring(0, 12 - 
                   f82.format(Verbund.stress[i][j][4]).length()) +
                   f82.format(Verbund.stress[i][j][4])+
                   blanks.substring(0, 12 - 
                   f82.format(Verbund.stress[i][j][5]).length()) +
                   f82.format(Verbund.stress[i][j][5])+
                   blanks.substring(0, 12 - 
                   f82.format(Verbund.stress[i][j][9]).length()) +
                   f82.format(Verbund.stress[i][j][9])+
                   blanks.substring(0, 12 - 
                   f82.format(Verbund.stress[i][j][10]).length()) +
                   f82.format(Verbund.stress[i][j][10])+
                   blanks.substring(0, 12 - 
                   f82.format(Verbund.stress[i][j][11]).length()) +
                   f82.format(Verbund.stress[i][j][11])+ '\n');
            if (laminat.fail_crit > 0){
                   lam_list.append("       Minimum factors of safety: ");
                if (laminat.fail_crit == 1)
                   lam_list.append(
                     "Fiber failure: "+
                     blanks.substring(0, 7 - 
                     f82.format(Verbund.safety[i][j][0]).length()) +
                     f82.format(Verbund.safety[i][j][0]) + '\n' +
                     "        (Tsai Wu modified)   Interfiber failure: " +
                     blanks.substring(0, 7 - 
                     f82.format(Verbund.safety[i][j][1]).length()) +
                     f82.format(Verbund.safety[i][j][1])+ '\n');
                else if (laminat.fail_crit == 2)
                   lam_list.append(
                                                       "Fiber parall.: "+
                     blanks.substring(0, 7 - 
                     f82.format(Verbund.safety[i][j][0]).length()) +
                     f82.format(Verbund.safety[i][j][0]) + '\n' +
                     "        (Maximum Stress)          Fiber perp.  : " +
                     blanks.substring(0, 7 - 
                     f82.format(Verbund.safety[i][j][1]).length()) +
                     f82.format(Verbund.safety[i][j][1])  + '\n' +
                     "                                  Shear failure: " +
                     blanks.substring(0, 7 - 
                     f82.format(Verbund.safety[i][j][2]).length()) +
                     f82.format(Verbund.safety[i][j][2])  + '\n');
	        }
	    }
	  }
      }
  }

/**
 * Inserting a layer to the laminate after the marked layer.
 */
  public static void insertLayer() {
    int n_sel = lam_def.getSelectedIndex();
    if(n_sel >-1 && n_lag_max < 19){
        lam_def.addItem(lam_def.getItem(n_sel), n_sel+1);
	n_lag_max += 1;
	verbund.insertLayer(n_sel+1);
        for (int i = n_sel+1; i < lam_def.getItemCount(); i++){
          char num [] = new char [3];
          num[1] = ' ';
          int lang = String.valueOf(i+1).length();
	  String.valueOf(i+1).getChars(0,lang,num,0);
	  StringBuffer layer = new StringBuffer(lam_def.getItem(i));
	  layer.setCharAt(0,num[0]);
	  layer.setCharAt(1,num[1]);
	  lam_def.replaceItem(layer.toString(),i);
	}
        tges   = verbund.getThick();
        lam_tref.setText(String.valueOf(tges/2.));
        lab_tges.setText("Laminate Thickness: " + tges);
        lay_no.setText(String.valueOf(n_sel+2));
    }
  }

/**
 * Inserting a loadcase to the laminate loading.
 */
  public static void insertLoad() {
    int n_sel = load_list.getSelectedIndex();
    if(n_sel >-1 && n_load_max < 9){
        load_list.addItem(load_list.getItem(n_sel), n_sel+1);
	n_load_max += 1;
	verbund.insertLoads(n_sel+1);
        for (int i = n_sel+1; i < load_list.getItemCount(); i++){
          char num [] = new char [3];
          num[1] = ' ';
          int lang = String.valueOf(i+1).length();
	  String.valueOf(i+1).getChars(0,lang,num,0);
	  StringBuffer load = new StringBuffer(load_list.getItem(i));
	  load.setCharAt(0,num[0]);
	  load.setCharAt(1,num[1]);
	  load_list.replaceItem(load.toString(),i);
	}
        load_v0.setText(String.valueOf(n_sel+2));
    }
  }

/**
 * Deleting the marked layer from the laminate.
 */
  public static void deleteLayer() {
        int n_sel = lam_def.getSelectedIndex();
        if (n_sel > -1){
          lam_def.delItem(n_sel);
	  n_lag_max -= 1;
	  verbund.removeLayer(n_sel+1);
          for (int i = n_sel; i < lam_def.getItemCount(); i++){
            char num [] = new char [3];
            num[1] = ' ';
            int lang = String.valueOf(i+1).length();
	    String.valueOf(i+1).getChars(0,lang,num,0);
	    StringBuffer layer = new StringBuffer(lam_def.getItem(i));
	    layer.setCharAt(0,num[0]);
	    layer.setCharAt(1,num[1]);
	    lam_def.replaceItem(layer.toString(),i);
	  }
        tges   = verbund.getThick();
        lam_tref.setText(String.valueOf(tges/2.));
        lab_tges.setText("Laminate Thickness: " + tges);
	if (n_sel < n_lag_max) 
	  lam_def.select(n_sel);
	else
	  lam_def.select(n_lag_max-1);
	}
  }

/**
 * Deleting the marked loadcase from the laminate loading.
 */
  public static void deleteLoad() {
        int n_sel = load_list.getSelectedIndex();
        if (n_sel > -1){
          load_list.delItem(n_sel);
	  n_load_max -= 1;
	  verbund.removeLoads(n_sel+1);
          for (int i = n_sel; i < load_list.getItemCount(); i++){
            char num [] = new char [3];
            num[1] = ' ';
            int lang = String.valueOf(i+1).length();
	    String.valueOf(i+1).getChars(0,lang,num,0);
	    StringBuffer load = new StringBuffer(load_list.getItem(i));
	    load.setCharAt(0,num[0]);
	    load.setCharAt(1,num[1]);
	    load_list.replaceItem(load.toString(),i);
	  }
	if (n_sel < n_load_max) 
	  load_list.select(n_sel);
	else
	  load_list.select(n_load_max-1);
	}
  }

/**
 * Selecting a layer by double clicking it in the laminate definition list.
 */
  public static void selectLayer() {
    int n_sel = lam_def.getSelectedIndex();
    lay_no.setText(String.valueOf(n_sel+1));
    lay_ang.setText(String.valueOf(verbund.getAngle(n_sel+1)));
    lay_thick.setText(String.valueOf(verbund.getThick(n_sel+1)));
    lay_cont.setText(String.valueOf(verbund.getVolcont(n_sel+1)));
    lay_fiber.select(verbund.getFiber(n_sel+1));
    lay_matrix.select(verbund.getMatrix(n_sel+1));
  }

/**
 * Selecting a loadcase by double clicking it in the load definition list.
 */
  public static void selectLoad() {
    int n_sel = load_list.getSelectedIndex();
    load_v0.setText(String.valueOf(n_sel+1));
    load_v1.setText(String.valueOf(Verbund.loads[n_sel][0]));
    load_v2.setText(String.valueOf(Verbund.loads[n_sel][1]));
    load_v3.setText(String.valueOf(Verbund.loads[n_sel][2]));
    load_v4.setText(String.valueOf(Verbund.loads[n_sel][3]));
    load_v5.setText(String.valueOf(Verbund.loads[n_sel][4]));
    load_v6.setText(String.valueOf(Verbund.loads[n_sel][5]));
    load_v7.setText(String.valueOf(Verbund.loads[n_sel][6]));
  }

/**
 * Clearing the current laminate definition.
 */
  public static void newLaminate() {
	Fiber.init();
	Matrix.init();
        verbund.init();
        ud_list.setText("");
        lam_list.setText("");
        lay_no.setText("1");
        load_v0.setText("1");
        lam_def.removeAll();
        load_list.removeAll();
        n_lage      = 0;
        n_lag_max   = 0;
        tges        = 0.0;
        n_loads     = 0;
        n_load_max  = 0;
        load_v1.setText("0.0");
        load_v2.setText("0.0");
        load_v3.setText("0.0");
        load_v4.setText("0.0");
        load_v5.setText("0.0");
        load_v6.setText("0.0");
        load_v7.setText("0.0");
     Graphics g1 = image.getGraphics();
     g1.setColor(Color.red);
     g1.drawRect(5,5,420,90);
     g1.setColor(Color.blue);
     g1.drawRect(8,8,414,84);
     g1.setColor(Color.yellow);
     g1.drawString("iat - Hochschule Bremen",20,32);
     g1.drawString("Structural Analysis & Design",20,82);
  }

/**
 * Load a file defintion from file.
 */
  public static void loadLaminate() {
     FileDialog fd = new FileDialog(file_load, "Load Laminate Definition");
     fd.show();
     newLaminate();
     int i;
     try{
     BufferedReader datread = new BufferedReader(
                     new FileReader(fd.getDirectory()+fd.getFile()));
     System.out.println("Load file: " + fd.getFile() + ": ");
     String line = datread.readLine().trim();
     lam_tref.setText(line);
     System.out.println("Input line: " + line);
     for (i=0; i<1000; i++){
       line = datread.readLine().trim();
       System.out.println("Input line: " + line);
       if (line.startsWith("ENDE") | line.startsWith("LAST") ) {
	 break;
       }

       int index1    = line.indexOf(' ');
       String fiber  = line.substring(0, index1);
       line          = line.substring(index1).trim();

       index1        = line.indexOf(' ');
       String matrix = line.substring(0, index1);
       line          = line.substring(index1).trim();

       index1        = line.indexOf(' ');
       double angle  = Double.valueOf(line.substring(0, index1)).doubleValue();
       line          = line.substring(index1).trim();

       index1        = line.indexOf(' ');
       double thick  = Double.valueOf(line.substring(0, index1)).doubleValue();
       line          = line.substring(index1).trim();

       double cont   = Double.valueOf(line).doubleValue();
       Verbund.addLayer(i+1, fiber, matrix, angle, thick, cont);
       // System.out.println("line: "+(i+1)+' '+fiber+' '+matrix+' '+angle+
       //                   ' '+thick+' '+cont);
       lam_def.addItem(new StringBuffer
              ("                                                            ").
                         insert(0,String.valueOf(i+1)).
                         insert(5,fiber).
                         insert(17,matrix).
                         insert(29,""+angle).
                         insert(39,""+thick).
                         insert(49,""+cont).toString().trim(), i);
     }
     n_lag_max   = i;
     n_lage      = i;
     lay_no.setText(""+n_lage);
     if (line.startsWith("LAST")) {
       for (i=0; i<100; i++){
         line = datread.readLine().trim();
	 System.out.println("Input line: " + line);
	 if (line.startsWith("ENDE")) {
	   break;
	 }

       int index1    = line.indexOf(' ');
       double v1     = Double.valueOf(line.substring(0, index1)).doubleValue();
       line          = line.substring(index1).trim();

       index1        = line.indexOf(' ');
       double v2     = Double.valueOf(line.substring(0, index1)).doubleValue();
       line          = line.substring(index1).trim();

       index1        = line.indexOf(' ');
       double v3     = Double.valueOf(line.substring(0, index1)).doubleValue();
       line          = line.substring(index1).trim();

       index1        = line.indexOf(' ');
       double v4     = Double.valueOf(line.substring(0, index1)).doubleValue();
       line          = line.substring(index1).trim();

       index1        = line.indexOf(' ');
       double v5     = Double.valueOf(line.substring(0, index1)).doubleValue();
       line          = line.substring(index1).trim();

       index1        = line.indexOf(' ');
       double v6     = Double.valueOf(line.substring(0, index1)).doubleValue();
       line          = line.substring(index1).trim();

       double v7   = Double.valueOf(line).doubleValue();
       Verbund.addLoads(i+1, v1, v2, v3, v4, v5, v6, v7);
       load_list.addItem(new StringBuffer
              ("                                                            ").
                         insert(0,String.valueOf(i+1)).
                         insert(5,""+v1).
                         insert(15,""+v2).
                         insert(25,""+v3).
                         insert(35,""+v4).
                         insert(45,""+v5).
                         insert(55,""+v6).
                         insert(65,""+v7).toString().trim(), i);
       }
     n_load_max = i;
     }
     System.out.println("End of file!");
     datread.close();
     } catch (IOException e){ 
       System.out.println("I/O Error: " + e);
     }
     laminat.analyse();
     // System.out.println("Load: Directory: " + fd.getDirectory());
  }

/**
 * Save a laminate defintion to a file.
 */
  public static void saveLaminate() {
     FileDialog fd = new FileDialog(file_load, "Save Laminate Definition");

     //File dir = new File(".");
     //FilenameFilter filter = new MyFilter();
     //fd.setFilenameFilter(filter);
     //fd.setDirectory("./*.lam");
     
     fd.setFile("test.lam");
     fd.show();

     try {
     DataOutputStream datsave = new DataOutputStream(
                     new FileOutputStream(fd.getDirectory()+fd.getFile()));

     datsave.writeBytes("        " + lam_tref.getText() + "\r\n");
     for (int i=1; i<=n_lag_max; i++)
	datsave.writeBytes("" 
		                  + verbund.getFiber(i)
        +blanks.substring(0, 10 - verbund.getFiber(i).length())
		                  + verbund.getMatrix(i)
        +blanks.substring(0, 10 - verbund.getMatrix(i).length())
        +blanks.substring(0, 11 - f82.format(verbund.getAngle(i)).length())
                                   +f82.format(verbund.getAngle(i))
        +blanks.substring(0, 11 - f84.format(verbund.getThick(i)).length())
                                   +f84.format(verbund.getThick(i))
        +blanks.substring(0, 11 - f82.format(verbund.getVolcont(i)).length())
                                   +f82.format(verbund.getVolcont(i))+"\r\n");
     if (Verbund.n_load > 0) {
            datsave.writeBytes("LAST" + "\r\n");
	    for (int j=0; j<Verbund.n_load; j++)
	datsave.writeBytes("" 
        +blanks.substring(0, 10 - f82.format(verbund.loads[j][0]).length())
                                 +f82.format(verbund.loads[j][0])
        +blanks.substring(0, 10 - f82.format(verbund.loads[j][1]).length())
                                 +f82.format(verbund.loads[j][1])
        +blanks.substring(0, 10 - f82.format(verbund.loads[j][2]).length())
                                 +f82.format(verbund.loads[j][2])
        +blanks.substring(0, 10 - f82.format(verbund.loads[j][3]).length())
                                 +f82.format(verbund.loads[j][3])
        +blanks.substring(0, 10 - f82.format(verbund.loads[j][4]).length())
                                 +f82.format(verbund.loads[j][4])
        +blanks.substring(0, 10 - f82.format(verbund.loads[j][5]).length())
                                 +f82.format(verbund.loads[j][5])
        +blanks.substring(0, 10 - f82.format(verbund.loads[j][6]).length())
                                 +f82.format(verbund.loads[j][6])+"\r\n");
     }
     datsave.writeBytes("ENDE" + "\r\n");
     datsave.close();

     System.out.println("Save: " + n_lag_max + " Layers are written to file: "
                                + fd.getDirectory()+fd.getFile());
     } catch (IOException e){ 
       System.out.println("I/O Error: " + e);
     };
  }

/**
 * Print the file laminate results to a file.
 */
  public static void printLaminate() {
     FileDialog fd = new FileDialog(file_load, "Print Laminate Results");
     IOException f_err = new IOException();
     //fd.setFilenameFilter(filter);
     fd.show();
     double vsteif [][] = new double [6][6];
     verbund.getSteif(vsteif);
     try {
     DataOutputStream datsave = new DataOutputStream(
                     new FileOutputStream(fd.getDirectory()+fd.getFile()));

     datsave.writeBytes("                       Classical Laminate Theory"
                                                           + '\n');
     datsave.writeBytes("                       ========================="
                                                           + '\n');
     datsave.writeBytes("                                                "
                                                           + '\n');
     datsave.writeBytes("                                                " +
                                 "     JAVLAM V0.2, 01-10-98" + '\n');
     datsave.writeBytes("                                                " +
                                 "     Hochschule Bremen" + '\n');
     datsave.writeBytes("                                                " +
                                 "     Helmut Rapp" + '\n' + '\n');
     datsave.writeBytes("The laminate consists of " + n_lag_max + 
                                 " layers" + '\n');
     datsave.writeBytes("Thickness of Laminate:         " + tges + '\n');
     datsave.writeBytes("Coordinate of reference Plane: " + lam_tref.getText()
                                                         + '\n' + '\n');
     datsave.writeBytes("Laminate definition:" + '\n');
     datsave.writeBytes("                               Fibre   " + 
                        "  Layer    Fibre Volume" + '\n');
     datsave.writeBytes("Layer  Fibre     Matrix        Angle   " + 
                        "Thickness    Fraction  " + '\n'+'\n');
     for (int i=1; i<=n_lag_max; i++)
	datsave.writeBytes(
         blanks.substring(0, 4 - String.valueOf(i).length()) + i + "   "
		                  + verbund.getFiber(i)
        +blanks.substring(0, 10 - verbund.getFiber(i).length())
		                  + verbund.getMatrix(i)
        +blanks.substring(0, 10 - verbund.getMatrix(i).length())
        +blanks.substring(0, 9 - f82.format(verbund.getAngle(i)).length())
                                   +f82.format(verbund.getAngle(i))
        +blanks.substring(0, 11 - f84.format(verbund.getThick(i)).length())
                                   +f84.format(verbund.getThick(i))
        +blanks.substring(0, 11 - f82.format(verbund.getVolcont(i)).length())
                                   +f82.format(verbund.getVolcont(i))+'\n');
     datsave.writeBytes("" + '\n' + '\n' + "Laminate Stiffness Matrix" + '\n');
     datsave.writeBytes(              "=========================" + '\n'+'\n');
      for (int i=0; i<6; i++){
         datsave.writeBytes(
             blanks.substring(0, 14 - f82.format(vsteif[0][i]).length())
                                     +f82.format(vsteif[0][i])+
             blanks.substring(0, 14 - f82.format(vsteif[1][i]).length())
                                     +f82.format(vsteif[1][i])+
             blanks.substring(0, 14 - f82.format(vsteif[2][i]).length())
                                     +f82.format(vsteif[2][i])+
             blanks.substring(0, 14 - f82.format(vsteif[3][i]).length())
                                     +f82.format(vsteif[3][i])+
             blanks.substring(0, 14 - f82.format(vsteif[4][i]).length())
                                     +f82.format(vsteif[4][i])+
             blanks.substring(0, 14 - f82.format(vsteif[5][i]).length())
                                     +f82.format(vsteif[5][i])+'\n');
	}
     datsave.writeBytes("" + '\n' + '\n'+"Properties of the laminate" + '\n');
     datsave.writeBytes(            "==========================" + '\n'+'\n');
     datsave.writeBytes("" + '\n' + "  Ex       : " +
             blanks.substring(0, 11 - f82.format(verbund.getEx()).length())
                                     +f82.format(verbund.getEx())+
                               "       Alpha x  : " +
                   blanks.substring(0, 9 - 
                   f84.format(Verbund.alpha[0]*1.e6).length()) +
                   f84.format(Verbund.alpha[0]*1.e6)+"E-06" +'\n');
     datsave.writeBytes("  Ey       : "+
             blanks.substring(0, 11 - f82.format(verbund.getEy()).length())
                                     +f82.format(verbund.getEy())+
                               "       Alpha y  : " +
                   blanks.substring(0, 9 - 
                   f84.format(Verbund.alpha[1]*1.e6).length()) +
                   f84.format(Verbund.alpha[1]*1.e6)+"E-06" +'\n');
     datsave.writeBytes("  Gxy      : "+
             blanks.substring(0, 11 - f82.format(verbund.getGxy()).length())
                                     +f82.format(verbund.getGxy())+
                               "       Alpha xy : " +
                   blanks.substring(0, 9 - 
                   f84.format(Verbund.alpha[2]*1.e6).length()) +
                   f84.format(Verbund.alpha[2]*1.e6)+"E-06" +'\n');
     datsave.writeBytes("  Nuexy    : "+
             blanks.substring(0, 11 - f84.format(verbund.getNuexy()).length())
                                     +f84.format(verbund.getNuexy())+
                               "       Kappa x  : " +
                   blanks.substring(0, 9 - 
                   f84.format(Verbund.alpha[3]*1.e6).length()) +
                   f84.format(Verbund.alpha[3]*1.e6)+"E-06" +'\n');
     datsave.writeBytes("  Nueyx    : "+
             blanks.substring(0, 11 - f84.format(verbund.getNueyx()).length())
                                     +f84.format(verbund.getNueyx())+
                               "       Kappa y  : " +
                   blanks.substring(0, 9 - 
                   f84.format(Verbund.alpha[4]*1.e6).length()) +
                   f84.format(Verbund.alpha[4]*1.e6)+"E-06" +'\n');
     datsave.writeBytes("  Density  : "+
             blanks.substring(0, 11 - f84.format(verbund.getDens()).length())
                                     +f84.format(verbund.getDens())+
                               "       Kappa xy : " +
                   blanks.substring(0, 9 - 
                   f84.format(Verbund.alpha[5]*1.e6).length()) +
                   f84.format(Verbund.alpha[5]*1.e6)+"E-06" +'\n');
     if (Verbund.n_load > 0) {
          datsave.writeBytes('\n'+
                  "Stresses in the individual layers of the laminate:"+'\n');
          if (laminat.fail_crit == 1)
                 datsave.writeBytes("Failure criteria: Tsai Wu modified"+'\n');
          else if (laminat.fail_crit == 2)
                 datsave.writeBytes("Failure criteria: Maximum Stress"+'\n');
	  for (int i=0; i<Verbund.n_load; i++) {
	    datsave.writeBytes('\n' + "Load case " + (i+1) + '\n');
	    datsave.writeBytes("Loads:  DeltaT    " +
                          "     nx          ny         nxy" +
                          "          mx          my         mxy" + '\n');
	    datsave.writeBytes("  " + 
                   blanks.substring(0, 12 - 
                   f82.format(Verbund.loads[i][6]).length()) +
                   f82.format(Verbund.loads[i][6])+
                   blanks.substring(0, 11 - 
                   f82.format(Verbund.loads[i][0]).length()) +
                   f82.format(Verbund.loads[i][0])+
                   blanks.substring(0, 12 - 
                   f82.format(Verbund.loads[i][1]).length()) +
                   f82.format(Verbund.loads[i][1])+
                   blanks.substring(0, 12 - 
                   f82.format(Verbund.loads[i][2]).length()) +
                   f82.format(Verbund.loads[i][2])+
                   blanks.substring(0, 12 - 
                   f82.format(Verbund.loads[i][3]).length()) +
                   f82.format(Verbund.loads[i][3])+
                   blanks.substring(0, 12 - 
                   f82.format(Verbund.loads[i][4]).length()) +
                   f82.format(Verbund.loads[i][4])+
                   blanks.substring(0, 12 - 
                   f82.format(Verbund.loads[i][5]).length()) +
                   f82.format(Verbund.loads[i][5]) + '\n');
	    datsave.writeBytes("Laminate strains: " +
                          "  eps_x       eps_y      eps_xy" +
                          "     kappy_x     kappa_y    kappa_xy" + '\n');
	    datsave.writeBytes("             " + 
                   blanks.substring(0, 9 - 
                   f84.format(Verbund.epsilon[i][0]*1.e3).length()) +
                   f84.format(Verbund.epsilon[i][0]*1.e3)+"E-3" +
                   blanks.substring(0, 9 - 
                   f84.format(Verbund.epsilon[i][1]*1.e3).length()) +
                   f84.format(Verbund.epsilon[i][1]*1.e3)+"E-3" +
                   blanks.substring(0, 9 - 
                   f84.format(Verbund.epsilon[i][2]*1.e3).length()) +
                   f84.format(Verbund.epsilon[i][2]*1.e3)+"E-3" +
                   blanks.substring(0, 9 - 
                   f84.format(Verbund.epsilon[i][3]*1.e3).length()) +
                   f84.format(Verbund.epsilon[i][3]*1.e3)+"E-3" +
                   blanks.substring(0, 9 - 
                   f84.format(Verbund.epsilon[i][4]*1.e3).length()) +
                   f84.format(Verbund.epsilon[i][4]*1.e3)+"E-3" +
                   blanks.substring(0, 9 - 
                   f84.format(Verbund.epsilon[i][5]*1.e3).length()) +
                   f84.format(Verbund.epsilon[i][5]*1.e3)+"E-3" + '\n');
	    datsave.writeBytes("Layer stresses:   " +
                          "  sig_x       sig_y      tau_xy" +
                          "     sig_par    sig_perp      tau_pp" + '\n');
	    for (int j=0; j<Verbund.n_layer; j++) {
	    datsave.writeBytes("Layer " + 
                   blanks.substring(0, 2 -
                   String.valueOf(j+1).length()) + (j+1) + " bottom: " + 
                   blanks.substring(0, 8 - 
                   f82.format(Verbund.stress[i][j][0]).length()) +
                   f82.format(Verbund.stress[i][j][0])+
                   blanks.substring(0, 12 - 
                   f82.format(Verbund.stress[i][j][1]).length()) +
                   f82.format(Verbund.stress[i][j][1])+
                   blanks.substring(0, 12 - 
                   f82.format(Verbund.stress[i][j][2]).length()) +
                   f82.format(Verbund.stress[i][j][2])+
                   blanks.substring(0, 12 - 
                   f82.format(Verbund.stress[i][j][6]).length()) +
                   f82.format(Verbund.stress[i][j][6])+
                   blanks.substring(0, 12 - 
                   f82.format(Verbund.stress[i][j][7]).length()) +
                   f82.format(Verbund.stress[i][j][7])+
                   blanks.substring(0, 12 - 
                   f82.format(Verbund.stress[i][j][8]).length()) +
                   f82.format(Verbund.stress[i][j][8])+ '\n');
	    datsave.writeBytes("Layer " +
                   blanks.substring(0, 2 -
                   String.valueOf(j+1).length()) + (j+1) + "    top: " + 
                   blanks.substring(0, 8 - 
                   f82.format(Verbund.stress[i][j][3]).length()) +
                   f82.format(Verbund.stress[i][j][3])+
                   blanks.substring(0, 12 - 
                   f82.format(Verbund.stress[i][j][4]).length()) +
                   f82.format(Verbund.stress[i][j][4])+
                   blanks.substring(0, 12 - 
                   f82.format(Verbund.stress[i][j][5]).length()) +
                   f82.format(Verbund.stress[i][j][5])+
                   blanks.substring(0, 12 - 
                   f82.format(Verbund.stress[i][j][9]).length()) +
                   f82.format(Verbund.stress[i][j][9])+
                   blanks.substring(0, 12 - 
                   f82.format(Verbund.stress[i][j][10]).length()) +
                   f82.format(Verbund.stress[i][j][10])+
                   blanks.substring(0, 12 - 
                   f82.format(Verbund.stress[i][j][11]).length()) +
                   f82.format(Verbund.stress[i][j][11])+ '\n');	      
            if (laminat.fail_crit > 0){
                   datsave.writeBytes("       Minimum factors of safety: ");
                if (laminat.fail_crit == 1)
                   datsave.writeBytes(
                     "Fiber failure: "+
                     blanks.substring(0, 7 - 
                     f82.format(Verbund.safety[i][j][0]).length()) +
                     f82.format(Verbund.safety[i][j][0]) + '\n' +
                     "        (Tsai Wu modified)   Interfiber failure: " +
                     blanks.substring(0, 7 - 
                     f82.format(Verbund.safety[i][j][1]).length()) +
                     f82.format(Verbund.safety[i][j][1])+ '\n');
                else if (laminat.fail_crit == 2)
                   datsave.writeBytes(
                                                       "Fiber parall.: "+
                     blanks.substring(0, 7 - 
                     f82.format(Verbund.safety[i][j][0]).length()) +
                     f82.format(Verbund.safety[i][j][0]) + '\n' +
                     "        (Maximum Stress)          Fiber perp.  : " +
                     blanks.substring(0, 7 - 
                     f82.format(Verbund.safety[i][j][1]).length()) +
                     f82.format(Verbund.safety[i][j][1])  + '\n' +
                     "                                  Shear failure: " +
                     blanks.substring(0, 7 - 
                     f82.format(Verbund.safety[i][j][2]).length()) +
                     f82.format(Verbund.safety[i][j][2])  + '\n');
	       }
	    }
	  }
      }

     datsave.close();

     System.out.println("Print: Results for " + n_lag_max + 
                              " Layers are printed to file: " + fd.getFile());
     } catch (IOException e){ 
       System.out.println("I/O Error: " + e);
     };
  }

/**
 * Exiting the <b>laminate</b> program.
 */
  public static void exit() {
        System.exit(0);
       
  }

/**
 * Main method.
 */
  public static void main(String args[]){

      laminat Lam = new laminat();
      Lam.init();
  }

}

class HandleButton implements ActionListener {

  laminat theApp;
  String  theString;

  HandleButton(laminat a, String str) {
    theApp    = a;
    theString = str;
  
  }

  public void actionPerformed(ActionEvent e) {
    if (theString == "Layer OK")
        laminat.addLayer();
    else if (theString == "Load OK")
        laminat.addLoad();
    else if (theString == "Analyse")
        laminat.analyse();
    else if (theString == "LayInsert")
        laminat.insertLayer();
    else if (theString == "LayDelete")
        laminat.deleteLayer();
    else if (theString == "LoadInsert")
        laminat.insertLoad();
    else if (theString == "LoadDelete")
        laminat.deleteLoad();
    else if (theString == "New")
        laminat.newLaminate();
    else if (theString == "Load")
        laminat.loadLaminate();
    else if (theString == "Save")
        laminat.saveLaminate();
    else if (theString == "Print")
        laminat.printLaminate();
    else if (theString == "Quit")
        laminat.exit();
    else if (theString == "TsaiWu")
        laminat.fail_crit = 1;
    else if (theString == "MaxStress")
        laminat.fail_crit = 2;
    else if (theString == "None")
        laminat.fail_crit = 0;
    else if (theString == "LamDef")
        laminat.selectLayer();
    else if (theString == "LoadDef")
        laminat.selectLoad();
  }
}

class MyFilter implements FilenameFilter {

  public boolean accept(File dir, String name) {

    System.out.println("MyFilter: #" + name + "#   #" + dir + "# ");
    if (name.endsWith(".lam"))
         return true;
    else
         return false;
  }
}

class Verbund {

static private double ex, ey, gxy, nuexy, nueyx, z1, z2;
static private double tges, beta, density;
static private double steif [][]   = new double [6][6];
static private double nachg [][]   = new double [6][6];
static private double trans [][]   = new double [3][3];
static private double udsteif [][] = new double [3][3];
static private double hilf [][]    = new double [3][3];
static private double tempv []     = new double [6];
static double alpha []     = new double [6];
static private double udtemp []    = new double [3];
static private String lay_fib []   = new String [20];
static private String lay_mat []   = new String [20];
static private double lay_ang []   = new double [20];
static private double lay_thi []   = new double [20];
static private double lay_con []   = new double [20];
static int n_layer;
static int n_load;
static double loads [][]   = new double [10][7];
static double epsilon [][] = new double [10][6];
static private double epslag []    = new double [6];
static double stress [][][]= new double [10][20][12];
static double safety [][][]= new double [10][20][3];

  public static void init() {
    n_layer = 0;
    tges    = 0;
    n_load  = 0;
  }

  public static String getFiber(int layer){
    return lay_fib[layer-1];
  }

  public static String getMatrix(int layer){
    return lay_mat[layer-1];
  }

  public static double getAngle(int layer){
    return lay_ang[layer-1];
  }

  public static double getThick(int layer){
    return lay_thi[layer-1];
  }

  public static double getVolcont(int layer){
    return lay_con[layer-1];
  }

  public static int getNLayers(){
    return n_layer;
  }

  public static void addLayer(int layer, 
                              String fiber, String matrix, double angle,
                              double thick, double vol_cont) {
    n_layer += 1;
    lay_fib[layer-1] = fiber;
    lay_mat[layer-1] = matrix;
    lay_ang[layer-1] = angle;
    lay_thi[layer-1] = thick;
    lay_con[layer-1] = vol_cont;
    tges += thick;

    // System.out.println("Verbund.addLayer: line: "+(n_layer-1)+' '
    //                           +lay_fib[layer-1]+' '
    //                           +lay_mat[layer-1]+' '
    //                           +lay_ang[layer-1]+' '
    //                           +lay_thi[layer-1]+' '
    //                           +lay_con[layer-1]);
  }

  public static void replaceLayer(int layer, 
                              String fiber, String matrix, double angle,
                              double thick, double vol_cont) {
    tges = tges - lay_thi[layer-1] + thick;
    lay_fib[layer-1] = fiber;
    lay_mat[layer-1] = matrix;
    lay_ang[layer-1] = angle;
    lay_thi[layer-1] = thick;
    lay_con[layer-1] = vol_cont;    
  }

  public static void removeLayer(int layer) {
    tges = tges - lay_thi[layer-1];
    n_layer -= 1;
    for (int i=layer; i<n_layer+1; i++){
      lay_fib[i-1] = lay_fib[i];
      lay_mat[i-1] = lay_mat[i];
      lay_ang[i-1] = lay_ang[i];
      lay_thi[i-1] = lay_thi[i];
      lay_con[i-1] = lay_con[i];
    }
  }

  public static void insertLayer(int layer) {
    n_layer += 1;
    for (int i=n_layer; i>=layer; i--){
      lay_fib[i] = lay_fib[i-1];
      lay_mat[i] = lay_mat[i-1];
      lay_ang[i] = lay_ang[i-1];
      lay_thi[i] = lay_thi[i-1];
      lay_con[i] = lay_con[i-1];    
    }
    tges += lay_thi[layer-1];
  }

  public static void addLoads(int loadcase, 
           double v1, double v2, double v3, double v4, double v5, double v6, double v7) {
    n_load += 1;
    loads[n_load-1][0] = v1;
    loads[n_load-1][1] = v2;
    loads[n_load-1][2] = v3;
    loads[n_load-1][3] = v4;
    loads[n_load-1][4] = v5;
    loads[n_load-1][5] = v6;
    loads[n_load-1][6] = v7;
  }

  public static void replaceLoads(int loadcase, 
           double v1, double v2, double v3, double v4, double v5, double v6, double v7) {
    loads[loadcase-1][0] = v1;
    loads[loadcase-1][1] = v2;
    loads[loadcase-1][2] = v3;
    loads[loadcase-1][3] = v4;
    loads[loadcase-1][4] = v5;
    loads[loadcase-1][5] = v6;
    loads[loadcase-1][6] = v7;
  }

  public static void removeLoads(int loadcase) {
    n_load -= 1;
    for (int i=loadcase; i<n_load+1; i++){
      for ( int j=0; j<7; j++) loads[i-1][j] = loads[i][j];
    }
  }

  public static void insertLoads(int loadcase) {
    n_load += 1;
    for (int i=n_load; i>=loadcase; i--){
      for ( int j=0; j<7; j++) loads[i][j] = loads[i-1][j];
    }
  }

  public static void analyse(double tref) {

    double a11, a12, a22, b12, b1, b2, r1, r2, resfact;
    double strength[] = new double[5];

    System.out.println("Analysing laminate with "+ n_layer + " layers and " +
                        n_load +" loads. \n" +
                       "Failure criteria = " + laminat.fail_crit);

    for (int i=0; i<6; i++){
      tempv[i] = 0;
      for (int j=0; j<6; j++) steif[i][j] = 0.0;
    }
    density = 0.0;
    z1 = -tref;
    for (int i=0; i<n_layer; i++){
      z2 = z1 + lay_thi[i];
      UdLayer.init(lay_fib[i],lay_mat[i],lay_con[i]);
      UdLayer.getSteif(udsteif);
      UdLayer.getTempv(udtemp);
      beta = lay_ang[i]/180.*Math.PI;
      double sinb = Math.sin(beta);
      double cosb = Math.cos(beta);
      trans[0][0] = cosb*cosb;
      trans[0][1] = sinb*sinb;
      trans[0][2] = -2.*sinb*cosb;
      trans[1][0] = trans[0][1];
      trans[1][1] = trans[0][0];
      trans[1][2] = -trans[0][2];
      trans[2][0] = sinb*cosb;
      trans[2][1] = -trans[2][0];
      trans[2][2] = trans[0][0]-trans[0][1];
      Mathmat.matmul(trans, udsteif, hilf);
      Mathmat.transp(trans);
      Mathmat.matmul(hilf, trans, udsteif);
      for (int j=0; j<3; j++) {
          hilf[j][0] = trans[0][j]*udtemp[0]+
                       trans[1][j]*udtemp[1]+
                       trans[2][j]*udtemp[2];
      }
      for (int j=0; j<3; j++){
        tempv[j]   += hilf[j][0]*(z2-z1);
        tempv[j+3] += hilf[j][0]*0.5*(z2*z2-z1*z1);
	for (int k=0; k<3; k++){
	  steif[j][k]     += udsteif[j][k]*(z2-z1);
	  steif[j+3][k]   += udsteif[j][k]*(z2*z2-z1*z1)/2.;
	  steif[j][k+3]    = steif[j+3][k];
	  steif[j+3][k+3] += udsteif[j][k]*(z2*z2*z2-z1*z1*z1)/3.;
	}
      }
      density += UdLayer.getDensity() * (z2-z1);
      z1 = z2;
    }
    density /= tges;
    Mathmat.equal(steif, nachg);
    Mathmat.invert(nachg);

    ex    = 1./nachg[0][0]/tges;
    ey    = 1./nachg[1][1]/tges;
    gxy   = 1./nachg[2][2]/tges;
    nuexy = -nachg[0][1]/nachg[0][0];
    nueyx = -nachg[0][1]/nachg[1][1];

    for (int i=0; i<6; i++)
      {
        alpha[i] = 0.;
        for (int j=0; j<6; j++)
            alpha[i] += nachg[i][j]*tempv[j];
      }
    if (n_load > 0) {
        for (int i=0; i<n_load; i++)
	  {
            for (int j=0; j<6; j++)
	      {
                epsilon[i][j] = 0.0;
                for (int k=0; k<6; k++)
                       epsilon[i][j] += nachg[j][k]*loads[i][k];
                epsilon[i][j]        += alpha[j]*loads[i][6];
	      }
            z1   = -tref;
            for (int j=0; j<n_layer; j++)
	      {
                UdLayer.init(lay_fib[j],lay_mat[j],lay_con[j]);
		UdLayer.getSteif(udsteif);
		UdLayer.getTempv(udtemp);
                Fiber.getStrength(lay_fib[j], strength);
		beta = lay_ang[j]/180.*Math.PI;
		double sinb = Math.sin(beta);
		double cosb = Math.cos(beta);
		trans[0][0] = cosb*cosb;
		trans[0][1] = sinb*sinb;
		trans[0][2] = -2.*sinb*cosb;
		trans[1][0] = trans[0][1];
		trans[1][1] = trans[0][0];
		trans[1][2] = -trans[0][2];
		trans[2][0] = sinb*cosb;
		trans[2][1] = -trans[2][0];
		trans[2][2] = trans[0][0]-trans[0][1];
		Mathmat.matmul(trans, udsteif, hilf);
		Mathmat.transp(trans);
		Mathmat.matmul(hilf, trans, udsteif);
		for (int k=0; k<3; k++) {
		  hilf[k][0] = trans[0][k]*udtemp[0]+
		               trans[1][k]*udtemp[1]+
		               trans[2][k]*udtemp[2];
		}
		z2 = z1 + lay_thi[j];
                epslag[0] = epsilon[i][0] + epsilon[i][3]*z1;
                epslag[1] = epsilon[i][1] + epsilon[i][4]*z1;
                epslag[2] = epsilon[i][2] + epsilon[i][5]*z1;
                epslag[3] = epsilon[i][0] + epsilon[i][3]*z2;
                epslag[4] = epsilon[i][1] + epsilon[i][4]*z2;
                epslag[5] = epsilon[i][2] + epsilon[i][5]*z2;
                //System.out.println("layer strains bottom: "+ 
                //                   epslag[0]+"  "+epslag[1]+"  "+epslag[2]);
                //System.out.println("layer strains top   : "+ 
                //                   epslag[3]+"  "+epslag[4]+"  "+epslag[5]);
                //System.out.println("epslag: "+ 
                //                   tempvec[0]+"  "+tempvec[1]+"  "+tempvec[2]);
                for (int k=0; k<3; k++)
		  {
                    stress[i][j][k]    = 0.0;                 
                    stress[i][j][k+3]  = 0.0;                 
                    stress[i][j][k+6]  = 0.0;                 
                    stress[i][j][k+9]  = 0.0;                 
                    for (int l=0; l<3; l++)
		      {
                        stress[i][j][k]   += udsteif[k][l]*epslag[l]; 
                        stress[i][j][k+3] += udsteif[k][l]*epslag[l+3]; 
		      }
                    stress[i][j][k]       -= hilf[k][0]*loads[i][6];
                    stress[i][j][k+3]     -= hilf[k][0]*loads[i][6];
		  }
                trans[0][2] = -trans[0][2];
                trans[1][2] = -trans[1][2];
                trans[2][0] = -trans[2][0];
                trans[2][1] = -trans[2][1];
                for (int k=0; k<3; k++)
		  {
                    stress[i][j][k+6] = 
                                   trans[0][k] * stress[i][j][0] + 
                                   trans[1][k] * stress[i][j][1] + 
                                   trans[2][k] * stress[i][j][2]; 
                    stress[i][j][k+9] =  
                                   trans[0][k] * stress[i][j][3] + 
                                   trans[1][k] * stress[i][j][4] + 
                                   trans[2][k] * stress[i][j][5]; 
		  }
                z1 = z2;
		if (laminat.fail_crit > 0)
		  {
                    /*if (lagen[j].type == 1)
		      {
                         lagen[j].safety[i][0] = 
                             sqrt(lagen[j].stress[i][0]*lagen[j].stress[i][0]
                             +lagen[j].stress[i][1]*lagen[j].stress[i][1]
                             -lagen[j].stress[i][0]*lagen[j].stress[i][1]
                             +3.0*lagen[j].stress[i][2]*lagen[j].stress[i][2]);
                         if (lagen[j].safety[i][0] > 1.e-6)
                               lagen[j].safety[i][0] = lagen[j].strength[0]/
                                                  lagen[j].safety[i][0];
                         else  lagen[j].safety[i][0] = 1000.0;
                         resfact = 
                             sqrt(lagen[j].stress[i][3]*lagen[j].stress[i][3]
                             +lagen[j].stress[i][4]*lagen[j].stress[i][4]
                             -lagen[j].stress[i][3]*lagen[j].stress[i][4]
                             +3.0*lagen[j].stress[i][5]*lagen[j].stress[i][5]);
                         if (resfact > 1.e-6)
                               resfact  = lagen[j].strength[0]/resfact;
                         else  resfact  = 1000.0;
                         if (resfact < lagen[j].safety[i][0])
                                       lagen[j].safety[i][0] = resfact;
		      }
                    else if (lagen[j].type == 0)*/
                      if (laminat.fail_crit == 1)
		       {
                         a11 = 1./strength[0]/strength[1];
                         a22 = 1./strength[2]/strength[3];
                         a12 = -0.5*Math.sqrt(a11*a22);
                         b12 = 1./strength[4]/strength[4];
                         b1  = 1./strength[0]-1./strength[1];
                         b2  = 1./strength[2]-1./strength[3];
                         if (Math.abs(stress[i][j][6]) > 1.e-2)
                             if (stress[i][j][6] > 0.0)
                               safety[i][j][0] = strength[0]/stress[i][j][6];
                             else
                               safety[i][j][0] =-strength[1]/stress[i][j][6];
                         else  safety[i][j][0] = 1000.0;
                         if (Math.abs(stress[i][j][9]) > 1.e-2)
                             if (stress[i][j][9] > 0.0)
                               resfact         = strength[0]/stress[i][j][9];
                             else
                               resfact         =-strength[1]/stress[i][j][9];
                         else  resfact         = 1000.0;
                         if (resfact < safety[i][j][0])
                                       safety[i][j][0] = resfact;
                         r1 =   b1*stress[i][j][6]+b2*stress[i][j][7];
                         r2 =  a11*stress[i][j][6]*stress[i][j][6]
                             + a22*stress[i][j][7]*stress[i][j][7]
                           +2.*a12*stress[i][j][6]*stress[i][j][7]
                             + b12*stress[i][j][8]*stress[i][j][8];
                         safety[i][j][1] = r1 + Math.sqrt(r1*r1+4.*r2);
                         if (Math.abs(safety[i][j][1]) > 1.e-6)
                             safety[i][j][1] = 2./safety[i][j][1];
                         else safety[i][j][1] = 1000.0;
                         r1 =   b1*stress[i][j][9]+b2*stress[i][j][10];
                         r2 =  a11*stress[i][j][9]*stress[i][j][9]
                             + a22*stress[i][j][10]*stress[i][j][10]
                           +2.*a12*stress[i][j][9]*stress[i][j][10]
                           +   b12*stress[i][j][11]*stress[i][j][11];
                         resfact = r1 + Math.sqrt(r1*r1+4.*r2);
                         if (Math.abs(resfact) > 1.e-6)
                              resfact  = 2./resfact;
                         else resfact = 1000.0;
                         if (resfact < safety[i][j][1])
                                       safety[i][j][1] = resfact;
		       }
                      else if (laminat.fail_crit == 2)
		       {
                         if (Math.abs(stress[i][j][6]) > 1.e-2)
                             if (stress[i][j][6] > 0.0)
                               safety[i][j][0] = strength[0]/stress[i][j][6];
                             else
                               safety[i][j][0] =-strength[1]/stress[i][j][6];
                         else  safety[i][j][0] = 1000.0;
                         if (Math.abs(stress[i][j][9]) > 1.e-2)
                             if (stress[i][j][9] > 0.0)
                               resfact         = strength[0]/stress[i][j][9];
                             else
                               resfact         =-strength[1]/stress[i][j][9];
                         else  resfact         = 1000.0;
                         if (resfact < safety[i][j][0])
                                       safety[i][j][0] = resfact;
                         if (Math.abs(stress[i][j][7]) > 1.e-2)
                             if (stress[i][j][7] > 0.0)
                               safety[i][j][1] = strength[2]/stress[i][j][7];
                             else
                               safety[i][j][1] =-strength[3]/stress[i][j][7];
                         else  safety[i][j][1] = 1000.0;
                         if (Math.abs(stress[i][j][10]) > 1.e-2)
                             if (stress[i][j][10] > 0.0)
                               resfact         = strength[2]/stress[i][j][10];
                             else
                               resfact         =-strength[3]/stress[i][j][10];
                         else  resfact         = 1000.0;
                         if (resfact < safety[i][j][1])
                                       safety[i][j][1] = resfact;
                         if (Math.abs(stress[i][j][8]) > 1.e-2)
                             safety[i][j][2] = strength[4]/Math.abs(stress[i][j][8]);
                         else  safety[i][j][2] = 1000.0;
                         if (Math.abs(stress[i][j][11]) > 1.e-2)
                              resfact        = strength[4]/Math.abs(stress[i][j][11]);
                         else  resfact         = 1000.0;
                         if (resfact < safety[i][j][2])
                                       safety[i][j][2] = resfact;
		       }
		  }
	      }
	  }
    }
  }

  public static double getEx() {
    return ex;
  }

  public static double getEy() {
    return ey;
  }

  public static double getGxy() {
    return gxy;
  }

  public static double getNuexy() {
    return nuexy;
  }

  public static double getNueyx() {
    return nueyx;
  }

  public static double getThick() {
    return tges;
  }

  public static double getDens() {
    return density;
  }

  public static void getSteif(double stmat[][]) {
    for (int i=0; i<6; i++)
      for (int j=0; j<6; j++)
	stmat[i][j] = steif[i][j];
  }

  public static double getAlpha(int i) {
    return alpha[i];
  }
}

class UdLayer {

static private double epar, esenk, gkreuz, nueps, nuesp;
static private double alphapar, alphasenk, density;
static private double fprop []   = new double [7];
static private double mprop []   = new double [4];
static private double tempv []   = new double [3];
static private double steif [][] = new double [3][3];
static private double ret_val;

  public static void init(String fibre, String matrix, double volcont) {
    double aldiff, hilf, verh, ob, dz, z, zz, q3, q4, em;
    double q1 []   = new double [9];
    double q2 []   = new double [9];
    int      i;

    // System.out.println("UdLayer.init:     line: "+"  "
    //                           +fibre+' '
    //                           +matrix+' '
    //                           +volcont);

    ret_val  = Fiber.getProps(fibre, fprop);
    if (ret_val < 0.0)    
        System.out.println("UdLayer.init: Fiber material "
             +fibre+" not found");
    ret_val  = Matrix.getProps(matrix, mprop);
    if (ret_val < 0.0)    
        System.out.println("UdLayer.init: Matrix material "
             +matrix+" not found");
    volcont /= 100.0;
    density  = fprop[6] * volcont + mprop[3] * (1.-volcont);
    epar     = fprop[0] * volcont + mprop[0] * (1.-volcont);
    alphapar = (fprop[0] * fprop[4] * volcont + 
                 mprop[0] *mprop[2] * (1.-volcont)) / epar;
    double wurzel = 2.*Math.sqrt(volcont/Math.PI);
    double everh  = (1.-mprop[0]/fprop[1]);
    double schubm = mprop[0]/2./(1.+mprop[1]);
    double gverh  = (1.-schubm/fprop[2]);
    esenk   = mprop[0]*((1.-wurzel) - Math.PI/2./everh + 
                 2./everh/Math.sqrt(1.-4.*volcont/Math.PI*everh*everh)* 
                 Math.atan(Math.sqrt((1.+wurzel*everh)/(1.-wurzel*everh))));  
    nueps = fprop[3] * volcont + mprop[1] * (1.-volcont);
    gkreuz = schubm*((1.-wurzel) - Math.PI/2./gverh + 
                 2./gverh/Math.sqrt(1.-4.*volcont/Math.PI*gverh*gverh)* 
                 Math.atan(Math.sqrt((1.+wurzel*gverh)/(1.-wurzel*gverh))));
    double nuesp = nueps*esenk/epar;

    aldiff = fprop[5] - mprop[2];
    hilf   = (fprop[4] - mprop[2])*(mprop[1]*fprop[0] - fprop[3]*mprop[0]);
    verh   = 1.-mprop[0]/fprop[1];
    ob     = volcont/Math.PI;
    dz     = Math.sqrt(ob)/7.;
    z      = -dz;
    for (i=1; i<9; i++)
     {
       z +=  dz;
       if (i == 8) z = z - 0.01*dz;
       zz = 2.*Math.sqrt(ob-z*z);
       q2[i] = mprop[0]/(1.-verh*zz);
       q1[i] = (mprop[2]+aldiff*zz-hilf*(1.-zz)/
               (fprop[0]+mprop[0]*(1./zz-1.)))*q2[i];
     }
    q3 = 0.;
    q4 = 0.;
    for (i=2; i<9; i++)
     {
       q3 += (q1[i-1]+q1[i])/2.*dz;
       q4 += (q2[i-1]+q2[i])/2.*dz;
     }
    em = mprop[0]*(0.5-Math.sqrt(ob));
    alphasenk = (q3+em*mprop[2])/(q4+em);

    steif[0][0] = epar/(1.-nuesp*nueps);
    steif[1][0] = epar/(1.-nuesp*nueps)*nuesp;
    steif[2][0] = 0;
    steif[0][1] = steif[1][0];
    steif[1][1] = esenk/(1.-nuesp*nueps);
    steif[2][1] = 0;
    steif[0][2] = 0;
    steif[1][2] = 0;
    steif[2][2] = gkreuz;

    tempv[0]    = steif[0][0] * alphapar + steif[0][1] * alphasenk;
    tempv[1]    = steif[1][0] * alphapar + steif[1][1] * alphasenk;
    tempv[2]    = 0;

    // System.out.println("UdLayer.init:     line: "+"  "
    //                           +epar+' '
    //                           +esenk+' '
    //                           +gkreuz);
  }

  public static double getEpar() {
    return epar;
  }

  public static double getEperp() {
    return esenk;
  }

  public static double getGpp() {
    return gkreuz;
  }

  public static double getNueps() {
    return nueps;
  }

  public static double getAlphapar() {
    return alphapar;
  }

  public static double getAlphasenk() {
    return alphasenk;
  }

  public static double getDensity() {
    return density;
  }

  public static void getSteif(double stmat[][]) {
    for (int i=0; i<3; i++)
      for (int j=0; j<3; j++)
	stmat[i][j] = steif[i][j];
  }

  public static void getTempv(double tvect[]) {
    for (int i=0; i<3; i++)
	tvect[i] = tempv[i];
  }

}

class Fiber{

static double prop[][]  = new double [12][10];
static String name[]    = new String [10];
static int    mattype[] = new int [10];

  public static void init() {
    name[0]    = "T300";
    prop[0][0] = 218800.0;
    prop[1][0] = 28000.0;
    prop[2][0] = 50000.0;
    prop[3][0] = 0.23;
    prop[4][0] = -0.35e-6;
    prop[5][0] = 12.50e-6;
    prop[6][0] = 1.76;
    prop[7][0] = 1600.;
    prop[8][0] = 1600.;
    prop[9][0] = 50.;
    prop[10][0] = 200.;
    prop[11][0] = 100.;
    mattype[0]  = 1;

    name[1]    = "E-Glas";
    prop[0][1] = 73000.0;
    prop[1][1] = 73000.0;
    prop[2][1] = 29992.0;
    prop[3][1] = 0.217;
    prop[4][1] =  4.88e-6;
    prop[5][1] =  4.88e-6;
    prop[6][1] = 2.59;
    prop[7][1] = 1400.;
    prop[8][1] = 1600.;
    prop[9][1] = 70.;
    prop[10][1] = 180.;
    prop[11][1] = 80.;
    mattype[1]  = 1;

    name[2]    = "Kevlar";
    prop[0][2] = 124500.0;
    prop[1][2] = 9000.0;
    prop[2][2] = 14500.0;
    prop[3][2] = 0.43;
    prop[4][2] = -4.60e-6;
    prop[5][2] = 57.50e-6;
    prop[6][2] = 1.44;
    prop[7][2] = 1200.;
    prop[8][2] = 250.;
    prop[9][2] = 25.;
    prop[10][2] = 120.;
    prop[11][2] = 70.;
    mattype[2]  = 1;

    name[3]    = "T800";
    prop[0][3] = 294333.0;
    prop[1][3] = 28000.0;
    prop[2][3] = 50000.0;
    prop[3][3] = 0.23;
    prop[4][3] = -1.57e-6;
    prop[5][3] = 15.90e-6;
    prop[6][3] = 1.76;
    prop[7][3] = 3000.;
    prop[8][3] = 1500.;
    prop[9][3] = 50.;
    prop[10][3] = 200.;
    prop[11][3] = 110.;
    mattype[3]  = 1;

    name[4]    = "M40";
    prop[0][4] = 373500.0;
    prop[1][4] = 15200.0;
    prop[2][4] = 28600.0;
    prop[3][4] = 0.20;
    prop[4][4] = -0.29e-6;
    prop[5][4] = 59.0e-6;
    prop[6][4] = 1.81;
    prop[7][4] = 1400.;
    prop[8][4] = 800.;
    prop[9][4] = 30.;
    prop[10][4] = 100.;
    prop[11][4] = 50.;
    mattype[4]  = 1;

    name[5]    = "test";
    name[6]    = "test";
    name[7]    = "test";
    name[8]    = "test";
    name[9]    = "test";
  }

  public static double getProps(String fibre, double fprop[]) {
    for (int i=0; i<10; i++){
      if (name[i].equals(fibre)){
        for (int j=0; j<7; j++) fprop[j] = prop[j][i]; 
	return 1.0;
      }
    }
    return -1.0;
  }

  public static double getStrength(String fibre, double strength[]) {
    for (int i=0; i<10; i++){
      if (name[i].equals(fibre)){
        for (int j=0; j<5; j++) strength[j] = prop[7+j][i]; 
	return 1.0;
      }
    }
    return -1.0;
  }

  public static double getEpar(String fibre) {
    for (int i=0; i<10; i++){
      if (name[i].equals(fibre)){
	return prop[0][i];
      }
    }
    return -1.0;
  }

  public static double getEperp(String fibre) {
    for (int i=0; i<10; i++){
      if (name[i].equals(fibre)){
	return prop[1][i];
      }
    }
    return -1.0;
  }

  public static double getNueps(String fibre) {
    for (int i=0; i<10; i++){
      if (name[i].equals(fibre)){
	return prop[3][i];
      }
    }
    return -1.0;
  }
}

class Matrix{

static double prop[][] = new double [4][5];
static String name[]   = new String [5];

  public static void init() {
    name[0]    = "Epoxy";
    prop[0][0] = 3500.0;
    prop[1][0] = 0.35;
    prop[2][0] = 55.0e-6;
    prop[3][0] = 1.2;

    name[1]    = "Polyester";
    prop[0][1] = 3000.0;
    prop[1][1] = 0.35;
    prop[2][1] = 70.0e-6;
    prop[3][1] = 1.2;

    name[2]    = "Polyimid";
    prop[0][2] = 2900.0;
    prop[1][2] = 0.35;
    prop[2][2] = 56.4e-6;
    prop[3][2] = 1.2;

    name[3]    = "test";
    name[4]    = "test";
  }

  static double getProps(String matrix, double mprop[]) {
    for (int i=0; i<5; i++){
      if (name[i].equals(matrix)){
        for (int j=0; j<4; j++) mprop[j] = prop[j][i]; 
	return 1.0;
      }
    }
    return -1.0;
  }

  public static double getEmod(String matrix) {
    for (int i=0; i<5; i++){
      if (name[i].equals(matrix)){
	return prop[0][i];
      }
    }
    return -1.0;
  }

  public static double getNue(String matrix) {
    for (int i=0; i<5; i++){
      if (name[i].equals(matrix)){
	return prop[1][i];
      }
    }
    return -1.0;
  }

  public static double getAlpha(String matrix) {
    for (int i=0; i<10; i++){
      if (name[i].equals(matrix)){
	return prop[2][i];
      }
    }
    return -1.0;
  }

}

class Mathmat {

  public static void matmul(double mat1[][], double mat2[][], double mat3[][]){
    int n11 = mat1[0].length;
    int n12 = mat1.length;
    int n21 = mat2[0].length;
    int n22 = mat2.length;

    for (int i=0; i<n11; i++)
      for (int j=0; j<n11; j++){
	mat3[i][j] = 0;
	for (int k=0; k<n11; k++)
	  mat3[i][j] += mat1[i][k]*mat2[k][j];
	}
  }

  public static void transp(double mat1[][]){

    int n11 = mat1[0].length;

    for (int i=0; i<n11; i++)
      for (int j=i+1; j<n11; j++){
            double koeff = mat1[i][j];
	    mat1[i][j] = mat1[j][i];
            mat1[j][i] = koeff;
      }
         
  }

  public static void equal(double mat1[][], double mat2[][]){

    int n11 = mat1[0].length;

    for (int i=0; i<n11; i++)
      for (int j=0; j<n11; j++) mat2[i][j] = mat1[i][j];
  }

  public static void invert(double a[][]){

   int dim = a[0].length;
   double b[][] = new double [dim][dim];

   for (int i=0; i<dim; i++)
     {
       b[i][i] = 1./a[i][i];
       for (int j=0; j<dim; j++)
	 {
            if (j != i)
	      {
                b[j][i] =  a[j][i]/a[i][i];
                b[i][j] = -a[i][j]/a[i][i];
	      }
	 }
       for (int j=0; j<dim; j++)
	 {
           if (j != i)
	     {
           for (int k=0; k<dim; k++)
	       {
                if (k != i)
		  {
                    b[j][k] = a[j][k]-a[j][i]*a[i][k]/a[i][i];
		  }
	       }
	     }
	  }
        for (int j=0;j<dim; j++)
	  {
            for (int k=0; k<dim; k++)
	      {
                 a[j][k] = b[j][k];
	      }
	  }
      }
  }

}