#!/usr/bin/env perl

## Cotangent Transformer Calculator. 
## For matching 75 <-> 50 ohms.

## This file Copyright 2000 <contact@gbppr.org> under the GPL
## NO WARRANTY. Please send bug reports / patches / reports.

print "\n\n\t\tCotangent Transformer Calculator\n\n";

sub Print {
print "\n\n\n ** = Barrel connectors                                \n\n\n".
      " 50 ohm O-------|**|-------|**|-------|**|-------O 75 ohm   \n".
      " side                                              side     \n".
      "                   ^-------^  ^------^              \n".
      "                    Length A  Length B              \n\n\n".
      "        Frequency : $frq MHz\n".
      " Velocity Factors : $vf75 (75)\n".
      "                  : $vf50 (50)\n\n";
printf "        Length A : %.3f cm of 75 ohm coax\n".
       "                 : %.3f mm\n".
       "                 : %.3f inches\n\n", $wl75*10, $wl75*100, $wl75/2.54; 
printf "        Length B : %.3f cm of 50 ohm coax\n".
       "                 : %.3f mm\n".
       "                 : %.3f inches\n\n", $wl50*10, $wl50*100, $wl50/2.54;
} 
      
while (!$frq || $frq =~ m/[a-z]/i) {
        print "Enter frequency (in MHz): ";
        chomp($frq = <STDIN>);
        $frq =~ tr/0-9.//csd;
}

print "\n";

while (!$vf75 || $vf75 =~ m/[a-z]/i) {
        print "Enter velocity factor of 75 ohm coax (0.??): ";
        chomp($vf75 = <STDIN>);
        $vf75 =~ tr/0-9.//csd;
}

print "\n";

while (!$vf50 || $vf50 =~ m/[a-z]/i) {
        print "Enter velocity factor of 50 ohm coax (0.??): ";
        chomp($vf50 = <STDIN>);
        $vf50 =~ tr/0-9.//csd;
}

$wl75 = ((300 / $frq) * 0.81) * $vf75;
$wl50 = ((300 / $frq) * 0.81) * $vf50;

&Print;
