#!/usr/local/bin/perl # $Id: hyper.cgi,v 1.3 2003/04/08 20:04:01 jfrancis Exp $ # Clean up stupid percent stuff in http data. sub http_unquote { $_ = $_[0]; s/\+/ /g; s/\\(.)/$1/g; s/%(..)/sprintf ("%c", hex $1)/ge; s/\r//g; $_; } # Grab the POST data and stuff it into %passed if ($ENV{'REQUEST_METHOD'} eq 'POST') { sysread(STDIN, $ENV{'QUERY_STRING'}, $ENV{'CONTENT_LENGTH'}); } @pairs = split(/&/, $ENV{'QUERY_STRING'}); foreach (@pairs) { $_ = &http_unquote ($_); ($name, $val) = split(/=/,$_, 2); $passed{$name} = $val; } $query = $passed{'query'}; if($passed{'d'} eq "") { $passed{'d'}="0.03"; } # Don't internally buffer STDOUT since we're a CGI script. $|=1; # Spew the top part of the web page. printf("Content-type: text/html\n\n"); printf(""); if(($passed{'L'} eq "") || ($passed{'L'} eq "")) { # Form definition... printf("
\n"); # Fields... printf("Focal Length (mm):\n"); # Make a drop-down menu film sizes. printf("Film:\n"); # Submit button... printf("\n"); printf("
\n"); } else { printf("\n"); printf("\n"); printf("\n", $passed{'L'},$passed{'d'}); printf("
Lens Focal Length (mm)Diameter of Circle of Least Confusion (mm)
%d
%.2f
\n"); printf("


\n"); printf("\n"); printf("\n"); for $f (1,1.2,1.4,1.8,2,2.8,3.5,4,5.6,8,11,16,22,45,64) { printf("\n", $f,((($passed{'L'}*$passed{'L'})/($f*$passed{'d'}))/25.4)/12,(((($passed{'L'}*$passed{'L'})/($f*$passed{'d'}))/25.4)/12)/2); } printf("
Lens Aperture (f-stop)Hyperfocal Distance (ft)Closest Point in Focus (ft)
%.1f
%.2f
%.2f
\n"); } # Spew the bottom part of the web page. printf("\n");