#!/usr/local/bin/perl -w
use Env;
# created 00/7/26
# it creates a web page (4day_plot.html) that
# shows the latest ACE 4 day browse plot
# script: 4day_plot.pl
defined $ACEPROG or die "ACEPROG env. variable is not set. Call 4day_plot.pl from a shell that has sourced ~asc/procenv\n";
#chdir("$BRPLOTWEBDIR/");
$year_in = `tail -1 $ACEPROG/browse_proc/rbflist.all`;
#print "$year_in\n";
$year_in =~ s/.*BRW_(\d+)-(\d+)T.*\n/$1/;
$doy_in = $2;
#print "$year_in $doy_in\n";
($day, $month, $year) = &convert_yrdoy2dy_mon_yr($year_in, $doy_in);
$DATE = `date`;
chop($DATE);
#open(LAST_DAY2, "$BRPLOTWEBDIR/last_day_processed.txt") or die "can't open file last_day_processed.txt - $!";
open(HTML_PG, ">$BRPLOTWEBDIR/4day_plot.html") or die "can't open file 4day_plot.html - $!";
$month < 10 and $month = "0"."$month";
$day = $day + 0;
$day < 10 and $day = "0"."$day";
# move old 4 day plot to archive
`mv $BRPLOTWEBDIR/4day_plot*.gif $BRPLOTWEBDIR/4day_plot_archive/`;
# add date to end of plot filename
`cp $BRPLOTWEBDIR/mag_swe_epam_sis.gif $BRPLOTWEBDIR/4day_plot$year$month$day.gif`;
`cp $BRPLOTWEBDIR/4day_plot$year$month$day.gif $BRPLOTWEBDIR/4day_plot_archive/`;
`cd $BRPLOTWEBDIR/4day_plot_archive; ls -1 4day_plot*.gif > 4day_plot.lst`;
%months = ( "01" => "Jan", "02" => "Feb", "03" => "Mar", "04" => "Apr", "05" => "May", "06" => "Jun", "07" => "Jul", "08" => "Aug", "09" => "Sep", "10" => "Oct", "11" => "Nov", "12" => "Dec");
$day_display = $day + 0;
print HTML_PG "
ACE 4-day Browse Plot
ACE 4-day Browse Plot
plot updated through
$day_display $months{$month} $year
(DOY $doy_in)
Browse Data
MAG
Browse Data
SWEPAM
Browse Data
EPAM
Browse Data
SIS
Browse Data
";
#########################################################################
#########################################################################
#########################################################################
print HTML_PG "
\nClick for Printable Page\n";
print HTML_PG "
\n4 Day Plot Archive\n";
print HTML_PG "\n";
print HTML_PG "\nComplete ACE Browse Data\n";
print HTML_PG "
\nACE Level 2 Data
(Publication Quality)\n";
print HTML_PG "
\n";
print HTML_PG "
\n";
print HTML_PG "\nReturn to ASC Home Page
";
print HTML_PG "html updated: $DATE\n";
print HTML_PG "\n";
###########################################################
sub convert_yrdoy2dy_mon_yr {
### convert YEAR DOY ---> day month year
### input: year and DOY
### output: day month year
my ($year_in, $doy_in) = @_;
$doy_in > 366 and die "No year has more than 366 days - $!";
### initialize all 4 local variables to 0 -- Pg. 82 Perl 5 book
my ($num, $month, $leap_day, $day) = (0) x 4;
my $remainder = $year_in / 4;
my $remainder2 = int($year_in / 4);
### if remainders are equal then year is evenly divisible by 4
### and is a leap year. (caution will only work until year 2100 :)
$remainder == $remainder2 and $leap_day = 1;
### DOY's for a non leap year for each month
my @doys = ("31", "59", "90", "120", "151", "181", "212", "243", "273", "304", "334", "365");
### start with Mar since Jan & Feb are special cases (months=0-11)
for ($num=2; $num<=11; $num++) {
### january is a special case
$doy_in <= $doys[0] and ($day=$doy_in) and ($month=1) and last;
### february is a special case
$doy_in <= ($doys[1]+$leap_day) and ($day=$doy_in-$doys[0]) and ($month=2) and last;
### for all other months
($doy_in <= $doys[$num]+$leap_day) and ($day=$doy_in-$doys[$num-1]-$leap_day) and ($month=$num+1) and last;
}
return ($day, $month, $year_in);
}