#!/usr/local/bin/perl
#
# ep_plot_choose_3.cgi
# - perl script for LANL EP summary plot browser
# This version makes heavier use of Dynamic HTML.
#
# Michael G. Henderson -- Mar 15, 2000.
#
#
require "cgi-lib.pl";
require "ctime.pl";
$script = $ENV{'SCRIPT_NAME'};
$root_dir = $script;
$root_dir =~ s+(.*)/.*$+\1+;
$HTTP_REFERER = $ENV{'HTTP_REFERER'};
$PATH_INFO = $ENV{'PATH_INFO'};
$browser = $ENV{'HTTP_USER_AGENT'};
$server = $ENV{'SERVER_NAME'};
#
# Check to see if we have Java2 with LiveConnect Enabled.
# There really ought to be a better way than this!
# (For now, this assumes that IE doesnt support it. Fix later.)
#
if (($browser =~ 'Netscape6') || ($browser =~ 'Gecko')) { $HaveJava2 = 1; $HaveSanePngSupport = 1;}
elsif ($browser =~ 'MSIE 6') { $HaveJava2 = 1; $HaveSanePngSupport = 1;}
else { $HaveJava2 = 0; $HaveSanePngSupport = 0;}
# Check to see if this is running on avatar or not.
if ($server =~ 'avatar') { $Avatar = 1; }
else { $Avatar = 0; }
#
# Read in the plot description files to set all of the appropriate variables...
# Set flag to include external plots.
#
$IncludeThisPlot = 1;
require "ep_plot_descriptions.pl";
$remote = $ENV{"REMOTE_HOST"} || $ENV{"REMOTE_ADDR"};
if ($remote !~ /\./) {
$remote .= ".lanl.gov";
}
if (&ReadParse(*input)) {
#
# We are in here because there was cgi info to process
#
# print &PrintHeader, &PrintVariables(%input);
$year = $input{"Year"};
$month = $input{"Month"};
$day = $input{"Day"};
$size = $input{"PlotSize"};
$EphemType = $input{"EphemType"};
$PlotType = $input{"PlotType"};
$Action2 = $input{"Action2"};
$date = $year*10000 + $month*100 + $day;
#
# some of the plot types have + and - in the name. "escapify" all such occurences
# for doing the string comps
#
$p = $PlotType;
if ($p eq "loe+lop") { $p = "loe" };
$p =~ s/\+/\\+/;
$p =~ s/\-/\\-/;
if ($Action2 =~ /Latest/){ # then jump to latest date available
&FindLatest($p);
$date = $latest_file;
$date =~ s/^(\d{8})\S*/\1/;
$year = $date;
$month = $date;
$day = $date;
$year =~ s/(\d{4})(\d{2})(\d{2})/\1/;
$month =~ s/(\d{4})(\d{2})(\d{2})/\2/;
$day =~ s/(\d{4})(\d{2})(\d{2})/\3/;
}
#
# paste the page up to the browser
#
if (IsValidDate($date)){
&DoPage($year, $month, $day, $PlotType, $size, $EphemType);
}
else {
&WarnOfInvalidDate($date, $year, $month, $day);
}
} elsif ($PATH_INFO ne "") {
#
# The user has called the script with PATH_INFO extensions....
# interpret the path_info and process
#
$PATH_INFO =~ s/^\///;
($date, $PlotType, $size, $EphemType) = split("/", $PATH_INFO);
if ($size eq ""){
$size = 2;
}
#
# some of the plot types have + and - in the name. "escapify" all such occurences
# for doing the string comps
#
$p = $PlotType;
$p =~ s/\+/\\+/;
$p =~ s/\-/\\-/;
if ($date =~ /Latest/i){ # then jump to latest date available
&FindLatest($p);
printf qq| latest_file = $latest_file\n|;
$date = $latest_file;
$date =~ s/^(\d{8})\S*/\1/;
$year = $date;
$month = $date;
$day = $date;
$year =~ s/(\d{4})(\d{2})(\d{2})/\1/;
$month =~ s/(\d{4})(\d{2})(\d{2})/\2/;
$month += 0;
$day =~ s/(\d{4})(\d{2})(\d{2})/\3/;
$day += 0;
$year = $year;
}
else {
($dow, $monstr, $year, $month, $day, $DOY) = Doy($date);
# $year = int($date/10000);
# $tmp = $date - $year*10000;
# $month = int($tmp/100);
# $day = $tmp - $month*100;
}
if (IsValidDate($date)){
&DoPage($year, $month, $day, $PlotType, $size, $EphemType);
}
else {
&WarnOfInvalidDate($date, $year, $month, $day);
}
} else{
#
# The user has just typed in the name of the script.
# No info obtained either though stdin or via the PATH_INFO technique.
# post defaults.
#
print &PrintHeader;
printf qq|\n|;
printf qq|
Welcome to the LANL Geosynchronous Energetic Particle Summary Plot Browser\n|;
printf qq|(v3.0). This utility provides access to all of our pre-generated \"Low\n|;
printf qq|Energy\" proton and electron summary plots. These plots show spin-averaged\n|;
printf qq|fluxes from each satellite for each day since July 4, 1976. There is one plot\n|;
printf qq|for electrons and one plot for protons.
\n|;
# printf qq|Over this time period, 2 different instruments were used to acquire the data --\n|;
# printf qq|satellites launched prior to 1988 all carried \"CPA\" detectors,\n|;
# printf qq|while those launched after 1988 all carried \"SOPA\" detectors (post-1988\n|;
# printf qq|sats also carry the MPA plasma instrument). You can easily determine which is which\n|;
# printf qq|directly from the spacecraft name since the satellites are designated by their\n|;
# printf qq|international identifier numbers which automatically gives the launch year.\n|;
# printf qq|For example, \"1989-046\" means that this spacecraft was the 46th\n|;
# printf qq|launch in 1989 and therfore must carry a SOPA detector, while\n|;
# printf qq|\"1984-129\" was the 129th lauch in 1984 and must therefore carry a\n|;
# printf qq|CPA detector.
\n|;
#
# printf qq|It is important to note that the low energy channels span slightly different\n|;
# printf qq|energy ranges for CPA versus SOPA. The ranges are given approximately as follows;
\n|;
printf qq|Use the form below to choose the desired: plot type, size, and date.\n|;
printf qq|Hit the \"Go\" button to take you to that date. If you are only interested in\n|;
printf qq|the latest available plot, then hit the \"Latest\" button (the date is ignored in this case -- the\n|;
printf qq|latest date will be found for you).\n|;
printf qq|
\n|;
printf qq|\n|;
printf qq|Report problems to Mike Henderson\n|;
printf qq|who wrote and maintains the EP summary plot browser. \n|;
printf qq|http://nis-www.lanl.gov/~mgh\n|;
printf qq| \n|;
printf qq|\n|;
$tx =
printf qq|Or report problems to Geoff Reeves\n|;
printf qq|who maintains the EP Web Pages. \n|;
printf qq|http://leadbelly.lanl.gov/reeves.html\n|;
printf qq| \n|;
printf qq|
\n|;
printf qq|\n|;
printf qq|\n|;
}
sub numerically { $a <=> $b };
#
# This subroutine creates the pulldown menus for selecting Date, Plot type etc..
#
sub chooser {
local($date, $PlotType, $size, $flag, $EphemType) = @_;
local($i, @SELECTED1, @SELECTED2, @SELECTED3, @SELECTED4, @SELECTED5);
local($year, $month, $day);
($c_year, $_c_month) = year_month();
$ny = $c_year - 1976 + 2;
#
# Figure out which values to select
#
#
# First set all of the SELECTED variables to blanks
#
for ($i = 0; $i < $nPType; $i++) { $SELECTED1[$i] = " "; }
for ($i = 0; $i < 12; $i++) { $SELECTED2[$i] = " "; }
for ($i = 0; $i < 31; $i++) { $SELECTED3[$i] = " "; }
for ($i = 0; $i < 50; $i++) { $SELECTED4[$i] = " "; }
for ($i = 0; $i < 4; $i++) { $SELECTED5[$i] = " "; }
for ($i = 0; $i < 2; $i++) { $SELECTED6[$i] = " "; }
#
# Change selections to what we get from arg list
#
$year = $date ;
$month = $date ;
$day = $date ;
$year =~ s/^([0-9]{4})[0-9]{4}/\1/;
$month =~ s/^[0-9]{4}([0-9]{2})[0-9]{2}/\1/;
$day =~ s/^[0-9]{4}[0-9]{2}([0-9]{2})/\1/;
$SELECTED1[$PType{$PlotType}] = "SELECTED";
$SELECTED2[$month-1] = "SELECTED";
$SELECTED3[$day-1] = "SELECTED";
$SELECTED4[$year-1976] = "SELECTED";
$SELECTED5[$size-1] = "SELECTED";
$SELECTED6[$EphemType-1] = "SELECTED";
printf qq| \n|;
}
sub WarnOfInvalidDate{
local($date, $year, $month, $day) = @_;
local($dow, $monstr, $YYYY, $MM, $DD, $DOY);
($dow, $monstr, $YYYY, $MM, $DD, $DOY) = Doy($date);
printf("Content-type: text/html\n\n");
printf qq|\n\n|;
printf qq|LANL GEO EP Summary Plot for: $dow, $monstr $DD, $YYYY\n|;
printf qq|\n|;
printf qq|\n|;
if ($HaveSanePngSupport){
printf qq|\n\n\n|;
} else {
printf qq|\n\n\n|;
}
printf qq|
You Entered an Invalid Date \n|;
printf qq|( Cannot recognize $date as a date )
\n|;
printf qq|Try yyyymmdd or yyyyddd \n|;
printf qq|or if the date is in the 20th century try yyddd or yymmdd \n|;
printf qq|or make sure you dont have an impossible day-of-month value (e.g. 19990229)
\n|;
printf qq|These summary plots should not be used for publication. Higher\n|;
printf qq|quality plots which have been checked for errors are available on request.\n|;
printf qq|The data presented here do have known instrumental effects, "bugs"\n|;
printf qq|and "glitches" and are provided "as is" (see Proton caveats).\n|;
printf qq|Keeping the LANL EP\n|;
printf qq|team involved in your analysis will help all of us. If you would\n|;
printf qq|like to request publishable plots or data or if you have questions\n|;
printf qq|about the data please contact a member of the EP team:
\n|;
printf qq|\n|;
printf qq| \n|;
if ( $SpPageWidth < 200 ) {
printf qq| \n|;
printf qq|Report problems to Mike Henderson\n|;
} else {
printf qq|Report problems to Mike Henderson\n|;
}
printf qq|who wrote and maintains the EP summary plot browser. \n|;
printf qq|
\n|;
printf qq|
\n|;
printf qq|
\n|;
printf qq|
\n|;
if ( $NSP > 1 ) {
printf qq|
\n|;
}
printf qq|
\n|;
printf qq|
UT: 0.00 (00:00:00)
\n|;
printf qq|
\n|;
printf qq| $PName[$PType{$PlotType}] \n|;
printf qq| $dow, $monstr $DD, $YYYY ( $date / $yyyyddd ) \n|;
printf qq| \n|;
printf qq| \n|;
printf qq| \n|;
printf qq| \n|;
if ($HaveJava2){
#
# OK, a bug has been pestering me for ages. Looks Like Ive finally found a work-around!
# The bug was such that if you hit the "GO" button on the form to bring up a new page,
# the Java applet came up fine. But if you hit an arrow it didnt load (bad magic number error
# -- which means the ClassLoader didnt think the file was a Java class!) It seems to
# work OK if you add the CODEBASE tag as well as the other tags though....
#
#printf qq| \n|;
printf qq| \n|;
if ($EphemType == 2){ printf qq|\n|;}
}
printf qq|