#!/usr/bin/perl

use lib 'd:/Programs/Perl/lib';

use strict;

use CSV;
use Sci::Science;
use Sci::Optics;
use Sci::OpticalMaterial;
use Sci::MultiLayer;

#=========================================================
# ‘åˆæ•Ï”
#=========================================================

#=========================================================
# Objectì»
# ‰ðÍðŒÝ’è
#=========================================================
my $optics = new Optics;

my $OutputCSV = "Spectrum.csv";

my $WLMin  =  100000; # nm
my $WLMax  = 3000000; # nm
my $WLStep =  10000.0; # nm

#=========================================================
# Ï‘wƒ‚ƒfƒ‹‚Ìì»
#=========================================================
my $FilmThickness      = 387.997e-9; # m, Film thickness

# For Tauc-Lorentz
my $e1inf =   1.08794;
my $e2inf =   0.0;
my $A     =  90.1;
my $Eg    =   2.786; # eV, Tauc gap
my $En0   =   6.290; # eV, Lorentz oscillation energy
my $C     =   6.786; # eV, Damping factor

# For Urbach
my @Em      = (3.1,      3.1);
my @E0      = (1.905,     0.5); # eV, Urbach energy
my @AUrbach = (0.0, 0.0000);
#my @AUrbach = (0.1034, 0.0000);

# For Lorentz
my $LorentzNe    = 0.4e20 * 1e6; # m-3
my $LorentzE0    = 2.805; # eV
my $Lorentzgamma = 0.3091; # eV

# For Drude
my $DrudeEp      = 0.627; # eV
my $Drudetau     = 5.5e-15; # s

open(OUT, ">$OutputCSV") or die "$!\n";
print OUT "E(eV),WL(nm),e1(Drude),e2(Drude),alpha(Drude),e1(Lorentz),e2(Lorentz),e1(TL),e2(TL)\n";
for(my $WL = $WLMin ; $WL < $WLMax ; $WL += $WLStep) {
	my $E = Optics::nmToeV($WL);
	my ($de1, $de2)   = $optics->Drude($E, 1.0, 0.0, $DrudeEp, $Drudetau);
	my ($dn1, $dk1)   = Optics::EpsToNK($de1, $de2);
	my $dalpha = Optics::KToAlpha($WL, $dk1);
	my ($le1, $le2)   = $optics->Lorentz($E, 1.0, 0.0, 1.0, $LorentzNe, $LorentzE0, $Lorentzgamma);
	my ($tle1, $tle2) = $optics->TaucLorentz($E, $e1inf, $e2inf, $A, $Eg, $En0, $C);
	print OUT "$E,$WL,$de1,$de2,$dalpha,$le1,$le2,$tle1,$tle2\n";
}
close(OUT);
exit;
