head 1.1;
access;
symbols;
locks
jmj:1.1; strict;
comment @# @;
1.1
date 98.08.25.20.19.50; author jmj; state Exp;
branches;
next ;
desc
@@
1.1
log
@Initial revision
@
text
@#!/packages/bin/perl
#-------------------------------------------------
#
# ep_summary_plots.cgi - LANL database web browser
#
# Joerg-Micha Jahn, NIS-2, LANL, January 1998
#
# This script allows browsing of the LANL database in the spirit
# of the CCR data browser. Main difference to the CCR browser is the use of
# the CGI.pm module to make forms processing easier, and of date5.pm for
# elegant date calculations.
#
# Modification History:
#
#
#-------------------------------------------------
### add location of modules to the path
BEGIN {push@@INC, "/n/toaster/u/jmj/public_html/cgi-bin/test/";}
use CGI;
use date5;
### default values we will use
@@day_name = ("Sunday","Monday","Tuesday","Wednesday","Thursday",
"Friday","Saturday");
@@month_name = ("January","February","March","April","May","June","July",
"August","September","October","November","December");
$plot_root_dir = '../../ep_summary_plots';
$a_one = 1;
### start of main script
$query = new CGI; # create a new CGI object
### first we need to scan the URL. The reason is that we need to identify
### optional input parameters. Furthermore we need to deal with calls from
### other browsers (namely CCR and MPA), since those will call with a date
### using a '/' rather than a '?'
$caller_url = $query->self_url; ### this gets the complete(!) URL
if ($caller_url =~ /[\?|\/]/) { ### here we have a query style case - good
@@keywords = $query->keywords; ### this gets the optional input
if (($#keywords > -1) && ($keywords[0] =~ /[0-9]/)) { # there was a input
@@components = ();
$i=0;
while (1) {
$temp = substr($keywords[0],$i,1);
if ($temp =~ /[0-9]/) {push(@@components,$temp)} else {last;}
$i++;
}
if ($i == 5) { ### yyDDD
$year = "$components[0]$components[1]";
if (int $year >= 76) {$year = "19$year";} else {$year = "20$year";}
$DOY = "$components[2]$components[3]$components[4]";
$jday = &Date5::jday($a_one,$a_one,$year);
($month,$day,$year,$weekday) = &Date5::jdate($jday+$DOY-1);
} elsif($i == 6) { ### yymmdd
$year = "$components[0]$components[1]";
$month = "$components[2]$components[3]";
$day = "$components[4]$components[5]";
if (int $year >= 76) {$year = "19$year";} else {$year = "20$year";}
} elsif($i == 7) { ### yyyyDDD
$year = "$components[0]$components[1]$components[2]$components[3]";
$DOY = "$components[4]$components[5]$components[6]";
$jday = &Date5::jday($a_one,$a_one,$year);
($month,$day,$year,$weekday) = &Date5::jdate($jday+$DOY-1);
} elsif($i == 8) { ### yyyymmdd
$year = "$components[0]$components[1]$components[2]$components[3]";
$month = "$components[4]$components[5]";
$day = "$components[6]$components[7]";
}
if ($month < 10) {$month = "0$month";}
if ($day < 10) {$day = "0$day";}
$query->param(-name=>'year', -values=>$year);
$query->param(-name=>'month', -values=>$month);
$query->param(-name=>'day', -values=>$day);
}
if (($#keywords > -1) && (($keywords[1] == 'Both') ||
($keywords[1] == 'Electrons') ||
($keywords[1] == 'Protons'))) {
$plot_type = $keywords[1];
$query->param(-name=>'plot_type', -values=>$plot_type);
}
}
### determine today's date - needed for some of the links (Dst, AE indices);
### this is reasonably fast, so we don't bother with passing those values via
### hidden fields (and save some code that way)
$today_julian_day = &Date5::today();
($today_month,$today_day,$today_year,$today_weekday) =
&Date5::jdate($today_julian_day);
if ($today_month < 10) {$today_month = "0$today_month";}
if ($today_day < 10) {$today_day = "0$today_day";}
$today_date = "${today_year}${today_month}${today_day}";
### for the Dst index we need the info for the previous month; the
### corresponding year is called "prevous_year", though a bit confusing...
$previous_month = $today_month - 1;
$previous_year = $today_year;
if ($previous_month == 0) {
$previous_month = 12;
$previous_year--;
}
if ($previous_month < 10) {$previous_month = "0$previous_month";}
$query->import_names('Q'); ### import name space to update form - we need
### this since the form is NOT updated when
### we use clickable image buttons or the "jump
### to latest" button.
if ($Q::year ne '') { ### this means there was user input ...
### calculate Julian day from input, and then date from this resulting
### julian day - this assures that senseless input (like Feb 31) will
### result in a sensible date - although not quite the one the user
### intended
$julian_day = &Date5::jday($Q::month,$Q::day,$Q::year);
($curr_month,$curr_day,$curr_year,$curr_weekday) =
&Date5::jdate($julian_day);
### get the day of year (DOY) - THIS IS NOT FINAL YET
$j_day_first = &Date5::jday($a_one,$a_one,$curr_year);
$DOY = $julian_day - $j_day_first + 1;
if ($DOY < 100) { $DOY = "0$DOY"; }
if ($DOY < 10) { $DOY = "0$DOY"; }
### save value of image buttons for further use
$next_day = $query->param('next_day.x');
$previous_day = $query->param('previous_day.x');
### 'jump to latest' or image button chosen. We need to pass parameters
### since all "SELECT" fields were not changed for such a request
if ($Q::latest) {
opendir(DIR, "$plot_root_dir/");
$check_jday = $today_julian_day;
while (1) {
($mm,$dd,$yy,$wd) =
&Date5::jdate($check_jday);
if ($mm < 10) {$mm = "0$mm";}
if ($dd < 10) {$dd = "0$dd";}
$check_date = "${yy}${mm}${dd}";
$e_filename = "$plot_root_dir/${check_date}_loe.gif";
if (-e $e_filename) {last;};
$check_jday--;
}
$e_last_date = $check_date;
opendir(DIR, "$plot_root_dir/");
$check_jday = $today_julian_day;
while (1) {
($mm,$dd,$yy,$wd) =
&Date5::jdate($check_jday);
if ($mm < 10) {$mm = "0$mm";}
if ($dd < 10) {$dd = "0$dd";}
$check_date = "${yy}${mm}${dd}";
$p_filename = "$plot_root_dir/${check_date}_lop.gif";
if (-e $p_filename) {last;};
$check_jday--;
}
$p_last_date = $check_date;
if ($Q::plot_type eq 'Electrons') {
$latest_date = $e_last_date;
} elsif ($Q::plot_type eq 'Protons') {
$latest_date = $p_last_date;
} else {
if ($e_last_date >= $p_last_date) {
$latest_date = $e_last_date;
} else {
$latest_date = $p_last_date;
}
}
$curr_year = substr($latest_date,0,4);
$curr_month = int substr($latest_date,4,2);
$curr_day = int substr($latest_date,6,2);
$keywords[0] = '';
}
### "next" and "previous" day buttons were pressed; calculate the new date
if ($next_day) {
$julian_day++;
($curr_month,$curr_day,$curr_year,$curr_weekday) =
&Date5::jdate($julian_day);
}
if ($previous_day) {
$julian_day--;
($curr_month,$curr_day,$curr_year,$curr_weekday) =
&Date5::jdate($julian_day);
}
### pass all parameters to object; needed to update form, since the form
### is NOT updated when non-select fields are pressed (i.e. the image
### buttons, and the "latest" field
### NOTE: ONLY object parameters will be saved by the script!
$query->param(-name=>'year', -values=>$curr_year);
$query->param(-name=>'month', -values=>$curr_month);
$query->param(-name=>'day', -values=>$curr_day);
### assure 2-digit month/day - needed to construct file name
if ($curr_month < 10) {$curr_month = "0$curr_month";}
if ($curr_day < 10) {$curr_day = "0$curr_day";}
$curr_date = "${curr_year}${curr_month}${curr_day}";
$curr_short_date = substr($curr_date,2,6);
($month,$day,$year,$weekday) = &Date5::jdate($jday+$DOY-1);
### determine the name of the image file; NOTE: 4-digit years!!
$e_image_filename =
"$plot_root_dir/$curr_year$curr_month${curr_day}_loe.gif";
if (! -e $e_image_filename) {
$e_image_filename = "/lanl_ep_data/images/no_electrons.gif";
}
$p_image_filename =
"$plot_root_dir/$curr_year$curr_month${curr_day}_lop.gif";
if (! -e $p_image_filename) {
$p_image_filename = "/lanl_ep_data/images/no_protons.gif";
}
} ### end of if (Q::year != '')
$query->import_names('Q'); ### reimport UPDATED (!!) name space; needed
### to update form
$query->param(-name=>'year', -values=>$$Q::_year);
$query->param(-name=>'month', -values=>$$Q::_month);
$query->param(-name=>'day', -values=>$$Q::_day);
$query->param(-name=>'plot_type', -values=>$plot_type);
$query->import_names('Q'); ### reimport UPDATED (!!) name space; needed
$julian_day = &Date5::jday($Q::month,$Q::day,$Q::year);
($curr_month,$curr_day,$curr_year,$curr_weekday) =
&Date5::jdate($julian_day);
if ($curr_month < 10) {$curr_month = "0$curr_month";}
if ($curr_day < 10) {$curr_day = "0$curr_day";}
$curr_date = "${curr_year}${curr_month}${curr_day}";
$curr_short_date = substr($curr_date,2,6);
### start building the HTML document/form; the little redirect thing is
### currently a clootch - but iot was the only way I could think o fright
### now which allows to incorporate an updated (!) current date in the web
### page address as it is shown by the browser
if (($keywords[0] eq '') && ($Q::year ne '')) {
print $query->redirect("http://leadbelly.lanl.gov/lanl_ep_data/cgi-bin/ep_plot_choose_2.cgi?$curr_date+$Q::plot_type");
} else {
print $query->header();
}
print $query->start_html(-title=>'CPA/SOPA Summary Plots');
####### begin of form #######
print $query->startform;
#print "$caller_url
";
### if script is called for the first time, print a special entry page
if ($Q::year eq '') {
print qq{
"; print $query->image_button(-name=>'previous_day', -src=>'../images/left_arrow.gif', -align=>'MIDDLE'), " "; print $query->image_button(-name=>'next_day', -src=>'../images/right_arrow.gif', -align=>'MIDDLE'), "
"; ### Input section, select date, plot type, etc. print qq{
"; print $query->endform; ####### end of form ####### NOT end of HTML !!!! ### links at the bottom of the page if ($Q::year eq '') { print qq{
"Low Energy" particle summary plots can be
viewed and browsed on line. Use this form to choose the date you
want to start on. After that each plot page has a
"forward" and "back" arrow and
a "choose date" button that will bring you back to
this page.
About the Plot Format
};
print qq{