#!/usr/bin/perl
#
# create datafiles of the form
#
#   x    cos(x)  cos(x+off)   cos(x)+cos(x+off)
#
# over a set of ranges, to show wave addition
#
# MWR 5/15/2007

$debug = 1;

$twopi = (3.14159*2.0);

# create simple cosine wave, no offset, unit amplitude
$start_x = -10;
$end_x = 10;
$dx = 0.01;

$amp = 1.0;

$num_offsets = 12;

 for ($offset = 0; $offset <= $num_offsets; $offset++) {

  $offset_radians = $offset*($twopi/10);
  if ($debug > 0) {
    printf " offset %5d offset_radians %9.3f \n", $offset, $offset_radians;
  }

  $outfile = sprintf "cosine_addition_%02d.dat", $offset;
  open(OUTFILE, ">$outfile") || die("can't open file $outfile");

  for ($x = $start_x; $x <= $end_x; $x += $dx) {


       # first, add without any offset
       $xx = $x;
       $y = cos($xx);
       $y2 = cos($xx + $offset_radians);
       $sum = $y + $y2;

    printf OUTFILE " %9.4f  %9.4f  %9.4f  %9.4f  \n", $x, $y, $y2, $sum;

  }

  close(OUTFILE);

 }


exit 0;
