#!/usr/local/bin/perl
# This was copied from pages 342 and 343 of the book
# Build a Web Site.
# File Name: codetosched.pl
local($request_method,$content_length,$query_string);
#
# This assignment ensures that there are not problems in
# mixing fortran output with perl output.
#
$| = 1;
#Grab REQUEST_METHOD, CONTENT_LENGTH, and QUERY_STRING
$request_method = $ENV{'REQUEST_METHOD'};
$content_length = $ENV{'CONTENT_LENGTH'};
$query_string = $ENV{'QUERY_STRING'};
#Check whether this was a PUT or a POST
if (($request_method eq 'POST') || ($request_method eq 'PUT')) {
#If so, read the appropriate number of bytes from STDIN
read(STDIN, $query, $content_length);
#echo these bytes
print("Content-Type: text/html\n\n");
# print("The data received was:
\n\n");
# print("
\n");
# print("$query
");
#
# The material below was written by Steve Verrill, 4/01
#
#Try to parse $query. & separates fields. + separates multiple items in a field.
# @fields = split(/&/, $query);
# foreach $temp (@fields) {
# print ("$temp
");
# }
#
# Common name
#
# $comname = $fields[0];
$code0 = $query;
#
# get rid of code=
#
$code0 =~ s/code=//;
#
# blanks in the original lead to +'s
#
#
# get rid of pluses
#
$code0 =~ s/[\+]+//;
#
# translate lower case to upper case
#
$code0 =~ tr/a-z/A-Z/;
# print ("$code0
");
#
# remove the leading T
#
$code = $code0;
$code =~ s/^T//;
@codes = split(/-/,$code);
$temper = $codes[0];
$mc = ord(substr($codes[1],0,1)) - 64;
$depr = substr($codes[1],1,1);
$errflag = 0;
if ($temper < 1 || $temper > 14) {
$errflag = 1;
print("
Error: The temperature code did not lie in the");
print(" range 1 -- 14. If you have questions about this error");
print(" please contact Steve Verrill at
steve\@www1.fpl.fs.fed.us or 608-231-9375.
");
}
if ($mc < 1 || $mc > 6) {
$errflag = 1;
print("
Error: The moisture content code did not lie in the");
print(" range A -- F. If you have questions about this error");
print(" please contact Steve Verrill at
steve\@www1.fpl.fs.fed.us or 608-231-9375.
");
}
if ($depr < 1 || $depr > 8) {
$errflag = 1;
print("
Error: The wet bulb depression code did not lie in the");
print(" range 1 -- 8. If you have questions about this error");
print(" please contact Steve Verrill at
steve\@www1.fpl.fs.fed.us or 608-231-9375.
");
}
if ($errflag == 0) {
print("
For code $code0, the schedule is:
");
@proglist = ("sched.pr","$temper","$mc","$depr");
system(@proglist);
}
print("
For further information, please contact Steve Verrill at
steve\@www1.fpl.fs.fed.us or 608-231-9375.
");
print("Last modified on 4\/21\/01.");
}
elsif ($request_method eq 'GET') {
#If so, the data is in QUERY_STRING
$query = $query_string;
}
else {
#Otherwise, print an error
print("Content-Type: text/html\n\n");
print("Error: Unacceptable Method
\n\n");
print("
\n");
print("This script does not support the $ENV{'REQUEST_METHOD'}\n");
print("method for submitting forms. Please use the POST method.\n");
exit;
}