#!/usr/bin/perl
#
# Generate the profile of an optically thin absorption line,
#   intensity versus wavelength.  Follow the work of Tatum.
#
# Usage: thin_thermal.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: thin_thermal.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;

# the velocity of particles in the photosphere (m/s)
$modal_v = 9900;

# 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;
$sqrt_ln_2 = sqrt(log(2.0));
for ($lambda = $start_lambda; $lambda < $end_lambda; $lambda += $dlambda) {

  $x = $lambda - $cent_lambda;
  $g = ($modal_v/$c)*$cent_lambda*$sqrt_ln_2;
  $zz = 0.0 - (($x*$x*log(2))/($g*$g));
  $tau = $tau0*exp($zz);

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

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

}


exit 0;
