#!/usr/bin/perl
# 
# Compute some numbers needed to discuss the interference
#    of two particular travelling waves.
#
# MWR 4/10/2020

$debug = 1;

$mypi = 3.141592654;
$twopi = 2.0*$mypi;

# speed of light in vacuum (m/s)
$c = 2.99792458E8;

# wavelengths of the two waves, in vacuum (m)
$lam1 = 500.0E-9;
$lam2 = 505.0E-9;

# angular frequencies of the waves, in vacuum (rad/s)
$omega1 = $twopi*($c / $lam1);
$omega2 = $twopi*($c / $lam2);

# wavenumbers of the two waves, in vacuum (rad/m)
$k1 = $twopi*(1.0 / $lam1);
$k2 = $twopi*(1.0 / $lam2);

# combine the two waves in a vacuum
#   average wavelength (m)
$lam_avg_vac = ($lam1 + $lam2) / 2.0;
#   half-difference in wave number (rad/m)
$k_diff_vac = ($k1 - $k2);
$half_k_diff_vac = $k_diff_vac / 2.0;
#   wavelength of envelope (m)
$lam_env_vac = $twopi / $half_k_diff_vac;

printf "k_diff_vac %20.9e    half_k_diff_vac %20.9e \n",
      $k_diff_vac, $half_k_diff_vac;


# compute properties in crown glass, with diff index of refraction 
#   at 500 nm, n = 1.5214
$n1 = 1.5214;
$lam1_glass = $lam1 / $n1;
$k1_glass = $twopi / $lam1_glass;
$v1_glass = $omega1 / $k1_glass;

$n2 = 1.5211;
$lam2_glass = $lam2 / $n2;
$k2_glass = $twopi / $lam2_glass;
$v2_glass = $omega2 / $k2_glass;

# now properties of the combined wave, in crown glass
$omega_avg_glass = ($omega1 + $omega2) / 2.0;
$k_avg_glass = ($k1_glass + $k2_glass) / 2.0;
$lam_avg_glass = $twopi / $k_avg_glass;
$vp_glass = $omega_avg_glass / $k_avg_glass;

$delta_omega_glass = ($omega1 - $omega2);
$half_delta_omega_glass = $delta_omega_glass / 2.0;
$delta_k_glass = $k1_glass - $k2_glass;
$half_delta_k_glass = $delta_k_glass / 2.0;
$lam_env_glass = $twopi / $half_delta_k_glass;
$vg_glass = $half_delta_omega_glass / $half_delta_k_glass;



printf "\n\n\n";


# print a nice table
printf "# %25s %20s %20s \n", " ", "wave1", "wave2";
printf "#-------------------------------------------------------------\n";
printf "  %25s %20.9e %20.9e \n", "lam in vac (m)", $lam1, $lam2;
printf "  %25s %20.9e %20.9e \n", "omega in vac (rad/s)", $omega1, $omega2;
printf "  %25s %20.9e %20.9e \n", "k in vac (rad/m)", $k1, $k2;
printf "  \n";
printf "  %25s %20.9e %20.9e \n", "lam avg vac (m)", $lam_avg_vac, " ";
printf "  %25s %20.9e %20.9e \n", "lam env vac (m)", $lam_env_vac, " ";
printf "  \n";
printf "# in crown glass \n";
printf "  %25s %20.9e %20.9e \n", "lam glass (m)", $lam1_glass, $lam2_glass;
printf "  %25s %20.9e %20.9e \n", "k glass (m)", $k1_glass, $k2_glass;
printf "  %25s %20.9e %20.9e \n", "vel glass (m/s)", $v1_glass, $v2_glass;
printf "  \n";
printf "# in crown glass, combined wave \n";
printf "  %25s %20.9e %20.9e \n", "omega avg glass (rad/s)", $omega_avg_glass, " ";;
printf "  %25s %20.9e %20.9e \n", "lam  avg glass (m)", $lam_avg_glass, " ";;
printf "  %25s %20.9e %20.9e \n", "k  avg glass (rad/m)", $k_avg_glass, " ";;
printf "  %25s %20.9e %20.9e \n", "vp glass (m/s)", $vp_glass, " ";;
printf "  \n";
printf "  %25s %20.9e %20.9e \n", "0.5 delt om glass (rad/s)", $half_delta_omega_glass, " ";;
printf "  %25s %20.9e %20.9e \n", "lam env glass (m)", $lam_env_glass, " ";;
printf "  %25s %20.9e %20.9e \n", "0.5 delta k glass (rad/m)", $half_delta_k_glass, " ";;
printf "  %25s %20.9e %20.9e \n", "vg glass (m/s)", $vg_glass, " ";;

printf "#-------------------------------------------------------------\n";



exit 0;


