package inversionsrechnung;

# Everything related to the inversion of the kernel matrix

#require 5.000;
#require Exporter;

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

use PDL;
use PDL::Core;
use PDL::Math;
use PDL::Primitive;
use PDL::Complex;
#use Proc::Background; # for running background processes (in this case: inversion)
use File::Spec; # for OS-agnostic file and path names
use Wx;

use attenuation;
use material;

use size_distribution;

use lib qw( Module );
use Helos;
use Faran_lsg_pdl;

#@ISA = qw(Exporter);
#@EXPORT = qw(read_Kext);
@ISA=qw(size_distribution);


my $xm = pdl [0];

my $c_L;

my $h_L;
my $h_T;
my $g;

# Umrechnung Np/m/MHz -> dB/cm/MHz
my $dB = 20/log(10) / 100;

sub new {
  my( $this ) = shift;
  my $class = ref($this) || $this;
  my $newInst={};
  bless($newInst, $class);

  #printf "new inversionsrechnung\n";
  $newInst->Initialize;
  return $newInst;
}

sub Initialize {
  my ($this) = @_;
  #printf "Initialize $this\n";
  $this->{particle_properties} = material->new($this);
  $this->{fluid_properties} = material->new($this);
  $this->{C_L}= undef;
  $this->{H_L}= undef;
  $this->{H_T}= undef;
  $this->{G}= undef;
  $this->{X_50_INI}= 125;
  $this->{PHI_INI}= 1;
  $this->{attn} = attenuation->new($this);
  #$this->{logging} = Wx::LogTextCtrl();
  $this->size_distribution::Initialize; # call parent
}

sub calculate_parameters {
  my ($this) = @_;
  $this->{C_L}=$this->{fluid_properties}->c_L;
  #printf "C_L " . $this->c_l . "\n";
  #$c_L = $this->{fluid_properties}->c_L;
  $this->{H_L}=$this->{particle_properties}->c_L/$this->{fluid_properties}->c_L;
  #printf "H_L " . $this->h_l . "\n";
  $this->{H_T}=$this->{particle_properties}->c_T/$this->{fluid_properties}->c_L;
  #printf "H_T " . $this->h_t . "\n";
  $this->{G}=$this->{particle_properties}->rho/$this->{fluid_properties}->rho;
  #printf "G " . $this->g . "\n";
}

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


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

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

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

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

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

1;
