package material;

# Everything related to material properties

#require 5.000;
#require Exporter;

use strict;
use warnings;
use vars qw(@ISA);
#use Carp;

#@ISA = qw(Exporter);
#@EXPORT = qw(read_Kext);
#@ISA=qw(Wx::Frame);

sub new {
  my( $this ) = shift;
  my $class = ref($this) || $this;
  my $newInst={};
  $newInst->{C_T} = undef;
  $newInst->{C_L} = undef;
  $newInst->{RHO}= undef;
  $newInst->{K}= undef;
  bless($newInst, $class);
  return $newInst;
}

sub c_T {
  my $this = shift;
  if (@_) { $this->{C_T} = shift }
  return $this->{C_T};
}

sub c_L {
  my $this = shift;
  if (@_) { $this->{C_L} = shift }
  return $this->{C_L};
}

sub rho {
  my $this = shift;
  if (@_) { $this->{RHO} = shift }
  return $this->{RHO};
}


# This function can be used to read values from a file

sub read_property_file {
  # material properties input
  my $ret_val=0;
  my ($this,$property_file)= @_;
  open(FILE,$property_file) or return(0);
  my $linebuf;
  my @data_line;
  # Extract data
  # Signals if a particular entry is found by
  # adjusting a bit in the return value
  while ( $linebuf=<FILE> ) {
    chomp($linebuf);
    my @data_line=split(' ',$linebuf);
    if ($data_line[0] eq 'c') {
      $this->{C_L}=$data_line[1];
      $ret_val = ($ret_val | 1);
    }
    if ($data_line[0] eq 'c_T') {
      $this->{C_T}=$data_line[1];
      $ret_val = ($ret_val | 2);
    }
    if ($data_line[0] eq 'rho') {
      $this->{RHO}=$data_line[1];
      $ret_val = ($ret_val | 4);
    }
  }
  close(FILE);
  return $ret_val;
}

sub write_property_file {
  # material properties input
  my ($this,$property_file)= @_;
  open(FILE,">$property_file") or return(0);
  print FILE ("c $this->{C_L}\n");
  if ($this->{C_T}) {print FILE ("c_T $this->{C_T}\n"); }
  print FILE ("rho $this->{RHO}\n");
  close(FILE);
  return 1;
}

sub output_property_data {
  # material properties input
  my ($this,$process, $string)= @_;
  #open(STDOUT,$process->GetOutputStream) or return(0);
  my $a =$process->GetOutputStream;
  print $a "Begin of $string properties data\n";
  print $a "c $this->{C_L}\n";
  if ($this->{C_T}) {print $a "c_T $this->{C_T}\n"; }
  print $a "rho $this->{RHO}\n";
  print $a "End of $string properties data\n";
  #close(STDOUT);
  return 1;
}



1;
