#!/usr/bin/perl
#
# Calculate a blackbody spectrum and print out intensity at a given wavelength.
#   Include log(lambda) and log(Intensity),
#   too.
#
# usage:  bb.pl  temp  lambda
#
# where "temp" is temperature in Kelvin, and "lambda" is wavelength in meters
# 
# MWR 8/19/2003

use POSIX;

$temp = $ARGV[0];
$lambda = $ARGV[1];

$start_lambda = 1e10;
$end_lambda = 1e-18;
$dlog_lambda = -0.1;

# this should be 2*h*c^2
$const = 1.0;
$h = 6.626e-34;
$c = 3.0e8;
$k = 1.38e-23;
$exponent_const = ($h*$c)/($k*$temp);

  $logl = log10($lambda);

  $top = $const/(pow($lambda, 5.0));
  $exponent = $exponent_const/$lambda;
  if ($exponent < 100) {
    $bot = exp($exponent);
    $blam = $top/$bot;
  }
  else {
    $blam = 1e-90;
  }
  # printf "exponent %9.4e  bot %9.4e \n", $exponent, $bot;


  $logblam = log10($blam);

  $nu = $h*$c/$lambda;
  $lognu = log10($nu);

  printf "%9.4e %9.4e %9.4e %9.4e %9.4e\n", $logl, $lambda, $blam, $logblam, $lognu; 

exit 0;

