Skip to content

Instantly share code, notes, and snippets.

@UnixSage
Last active March 17, 2018 14:35
Show Gist options
  • Save UnixSage/1cb198c40afd2c1d0a1889d76253762b to your computer and use it in GitHub Desktop.
Save UnixSage/1cb198c40afd2c1d0a1889d76253762b to your computer and use it in GitHub Desktop.
Generate EAD (Equivalent Air Depth) tables For SCUBA Diving
#!/bin/perl
# mod-ead-calc
# By: John C. Place
# http://www.unixsage.com
print "<title>Maximim Operating Depth and Eqivlant Air Depth Table</title>\n";
print "<table border cellpadding=\"3\">\n";
print "<caption>Maximim Operating Depth and Eqivlant Air Depth Table (fsw)</caption>";
for($x=20; $x <= 100; $x+=2) {
if($x==20) { $x=21 }
if($x>41) { $x+=3 }
$o2[$node]=$x;
$mod14[$node]=calcmod("1.4",$x);
$mod16[$node]=calcmod("1.6",$x);
if($x==21) { $x=20 }
$node++;
}
print "<tr><th rowspan=\"2\">MOD</th><th>1.6</th>" ; foreach(@mod16) { print "<td width=\"1900\" align=\"right\">$_</td>"; } ; print "</tr>\n";
print "<tr><th>1.4</th>" ; foreach(@mod14) { print "<td align=\"right\">$_</td>"; } ; print "</tr>\n";
print "<tr><th colspan=\"2\">\%O<sub>2</sub></th>" ; foreach(@o2) { print "<th>$_</th>"; } ; print "</tr>\n";
print "<tr><th colspan=\"2\" rowspan=\"21\">EAD</th>";
for($depth=10; $depth < 210; $depth+=10) {
print "<tr><th>$depth</th>";
for($node=1; $node <= $#o2; $node++) {
if($depth <= $mod16[$node]) {
$ead=calcead($o2[$node],$depth);
if($ead > 0 ) { print "<td align=\"right\">$ead</td>"; }
}
}
print "</tr>\n";
}
print "</table>\n";
print "<p STYLE=\"page-break-after: always\"></p>\n";
reset 'a-z';
for($x=8; $x <= 100; $x+=2) {
if($x==20) { $x=21 }
if($x>41) { $x+=3 }
$o2[$node]=$x;
$mod12[$node]=calcmod("1.2",$x);
$mod13[$node]=calcmod("1.3",$x);
$mod14[$node]=calcmod("1.4",$x);
$mod15[$node]=calcmod("1.5",$x);
$mod16[$node]=calcmod("1.6",$x);
if($x==21) { $x=20 }
$node++;
}
print "<br><br>\n";
print "<table border cellpadding=\"3\">\n";
print "<caption>Maximim Operating Depth (fsw)</caption>";
print "<tr><th colspan=\"2\">\%O<sub>2</sub></th>" ; foreach(@o2) { print "<th>$_</th>"; } ; print "</tr>\n";
print "<tr><th rowspan=\"5\">MOD</th><th>1.6</th>" ; foreach(@mod16) { print "<td align=\"right\">$_</td>"; } ; print "</tr>\n";
print "<tr><th>1.5</th>" ; foreach(@mod15) { print "<td align=\"right\">$_</td>"; } ; print "</tr>\n";
print "<tr><th>1.4</th>" ; foreach(@mod14) { print "<td align=\"right\">$_</td>"; } ; print "</tr>\n";
print "<tr><th>1.3</th>" ; foreach(@mod13) { print "<td align=\"right\">$_</td>"; } ; print "</tr>\n";
print "<tr><th>1.2</th>" ; foreach(@mod12) { print "<td align=\"right\">$_</td>"; } ; print "</tr>\n";
print "</table>\n";
print "<br><br>\n";
reset 'a-z';
for($x=21; $x <= 40; $x+=1) {
$o2[$node]=$x;
$mod14[$node]=calcmod("1.4",$x);
$mod15[$node]=calcmod("1.5",$x);
$mod16[$node]=calcmod("1.6",$x);
$node++;
}
print "<table border cellpadding=\"3\">\n";
print "<caption>Maximim Operating Depth (fsw)</caption>";
print "<tr><th colspan=\"2\">\%O<sub>2</sub></th>" ; foreach(@o2) { print "<th>$_</th>"; } ; print "</tr>\n";
print "<tr><th rowspan=\"5\">MOD</th><th>1.6</th>" ; foreach(@mod16) { print "<td align=\"right\">$_</td>"; } ; print "</tr>\n";
print "<tr><th>1.5</th>" ; foreach(@mod15) { print "<td align=\"right\">$_</td>"; } ; print "</tr>\n";
print "<tr><th>1.4</th>" ; foreach(@mod14) { print "<td align=\"right\">$_</td>"; } ; print "</tr>\n";
print "</table>\n";
sub calcmod {
$ppo=shift;
$fo2=shift;
$mod=(($ppo / ($fo2 * .01))-1)*32.8;
$mod=sprintf("%.0f",$mod);
return($mod);
}
sub calcead {
$fo2=shift;
$depth=shift;
$ead=(((1-$fo2 * .01)/.79)*($depth+33))-33;
$ead=sprintf("%.0f",$ead);
if ($ead < 1) {$ead=0;}
return($ead);
}
print "<tiny>Generared by <a href=\"https://gist.github.com/UnixSage/1cb198c40afd2c1d0a1889d76253762b\">MOD EAD Calc</a></tiny>\n";
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment