#!/usr/bin/perl
#
# Create transmission curves for the "B8" set of filters
#    based on description in 
#
# http://control.snap.nersc.gov:2440/twiki/pub/SNAPfilters/ExisitingDocuments/filters.pdf
#
# Note that "filter 0" _should_ have blue edge set by detector, but in
#    this document, it has same sloping blue edge as all others.
#
# MWR 3/17/2008

use POSIX;


$debug = 1;

$dlam = 1.0;

for ($ifilt = 1; $ifilt <= 8; $ifilt++) {

  $filename = sprintf "b8_%d.filter", $ifilt;
  open(FILENAME, ">$filename") || die("can't open file %s\n", $filename);

  # factor by which we stretch all wavelengths
  $stretch = pow( (1.0 + 0.201), ($ifilt - 1.0) );
  if ($debug > 0) {
    printf " ifilt %3d  stretch is %8.3f \n", $ifilt, $stretch;
  }

  # first the sloping blue side
  $start_lam = 3400.0;
  $end_lam = 4000.0;
  $bot = 0.0;
  $top = 1.0;
  for ($lam = $start_lam; $lam <= $end_lam; $lam += $dlam) {
    $frac = ($lam - $start_lam) / ($end_lam - $start_lam);
    $trans = $bot + $frac*($top - $bot);
    printf FILENAME "%8.3f %8.3f \n", $lam*$stretch, $trans;
  }

  # now the flat top
  $start_lam = 4000.0;
  $end_lam = 4700.0;
  for ($lam = $start_lam; $lam <= $end_lam; $lam += $dlam) {
    $trans = 1.0;
    printf FILENAME "%8.3f %8.3f \n", $lam*$stretch, $trans;
  }


  # now the vertical red side
  printf FILENAME "%8.3f %8.3f \n", $lam*$stretch, 1.0;
  printf FILENAME "%8.3f %8.3f \n", $lam*$stretch + $dlam, 0.0;


  close(FILENAME);



}

  


exit 0;



##############################################################################
# PROCEDURE: exec_cmd
#
# DESCRIPTION: Execute the given shell command line.  If the $debug flag
#              is set, we print to stdout the command line, and
#              also print out the result string.
#
# RETURNS:
#              the result of the command
#
#
sub exec_cmd {

  my($cmd, $ret);

  $cmd = $_[0];

  if ($debug > 0) {
    printf "cmd is ..$cmd.. \n";
  }
  $ret = `$cmd`;
  if ($debug > 0) {
    printf "ret is ..$ret.. \n";
  }

  return($ret);
}


