#!/usr/bin/perl
#
# Generate the Lorentzian profile of an absorption line,
#   intensity versus wavelength.  Follow the work of Tatum.
#
# Usage: lorentz.pl  tau0   
#
#   where "tau0" is the optical depth of the line center.
#   

# MWR 2/19/2004

$debug = 1;

$tau0 = $ARGV[0];
if ($tau0 <= 0) {
  printf "usage: lorentz.pl tau0 \n";
  exit 1;
}

# some physical constants (MKS)
$pi = 3.14159;
$c = 2.9979e8;
$kb = 1.38E-23;
$mh = 1.66E-27;
$gasr = 8.31;

# central wavelength  (Angstroms)
$cent_lambda = 6563;
$start_lambda = 6520;
$end_lambda = 6590;
$dlambda = 0.01;

# damping constant 
$gamma = 5.0;


# central optical depth
#$tau0 = 0.1;

# Given temperature $temp and mass $mass, calculate the distribution function.
#    as we go, we'll determine the cumulative distribution function.
$sum = 0.0;
$index = 0;
$l_const = ($gamma*$cent_lambda*$cent_lambda)/(4.0*$pi*$c);
for ($lambda = $start_lambda; $lambda < $end_lambda; $lambda += $dlambda) {

  $x = $lambda - $cent_lambda;
  $zz = ($l_const*$l_const)/($x*$x + $l_const*$l_const);
  $tau = $tau0*$zz;

  $inten = 1.0*exp(-$tau);

  printf "%12.7e  %12.7e  %12.7e \n", $lambda, $tau, $inten;

}


exit 0;
