#! /usr/bin/perl
############################################################################
# jeff.ator@noaa.gov #
# use: p03_model_page [model name] [cycle] [size] #
# model name={gfs} #
# cycle={00,06,12,18} #
# size={m} #
############################################################################
$DEBUG=1;
sub init_defs;
sub do_main_hdr;
sub gen_body;
sub no_data_found;
sub create_index_m_p03_loop;
sub create_m_p03_loop;
sub create_p03_applet;
sub create_loop_list;
init_defs; # initialize default variables, etc.
# Here we build the web page and write it out to $ofile (which is
# defined within init_defs)
open (MFF, ">${ofile}");
do_main_hdr; # print main html header
#Check if image_dir is empty. If it is empty, build a no_data_found page
#else build the default p03 model page
$image_dir ="$htmltmp/images/";
if($DEBUG>0){
print("IMAGE DIRECTORY = $image_dir\n");
}
my @files = <$image_dir/*>;
my $count = @files;
if($count>0)
{
gen_body; # generate main page
create_index_m_p03_loop; #create the html page for looping
create_m_p03_loop;
create_p03_applet;
create_loop_list;
}
else
{
no_data_found;
}
exit 0;
############################################################################
# Initial definitions and tests
# Define some constants, make sure we have the right number and type of
# arguments.
############################################################################
sub init_defs {
if ($#ARGV != 2) {
die "use: p03_model_page [model name] [cycle] [size]\n";
}
# basep - the root directory, up to the location where the model dirs live
# model - the name of the model (gfs,nam, etc.)
# title - the title given for the table; it is derived from the model name
# cycle - (00,06, etc.)
# siz - three web pages are built, one for each size (s,m,l)
if ($DEBUG > 0) {
print"DATA = $ENV{DATA}\n";
print"BASEDIR = $ENV{BASEDIR}\n";
print"FIXgempak = $ENV{FIXgempak}\n";
print"REGION = $ENV{REGION}\n";
}
if ($ENV{DATA}) { $data=$ENV{DATA}; }
else { die "You must define environment variable DATA.\n"; }
if ($ENV{BASEDIR}) { $basep=$ENV{BASEDIR}; }
else { die "You must define environment variable BASEDIR.\n"; }
if ($ENV{FIXgempak}) { $fixgem=$ENV{FIXgempak}; }
else { die "You must define environment variable FIXgempak.\n"; }
if ($ENV{REGION}) {$region=$ENV{REGION}; }
else { die "You must define environment variable REGION.\n"; }
if ($region =~ /namer/) { $regtitle="North America"; }
elsif ($region =~ /npac/ ) { $regtitle="North Pacific"; }
elsif ($region =~ /carib/ ) { $regtitle="Western North Atlantic"; }
elsif ($region =~ /canada/ ) { $regtitle="Canada"; }
elsif ($region =~ /alaska/ ) { $regtitle="Alaska"; }
elsif ($region =~ /united/ ) { $regtitle="United States of America"; }
elsif ($region =~ /mexico/ ) { $regtitle="Mexico"; }
elsif ($region =~ /samer/ ) { $regtitle="South America"; }
elsif ($region =~ /africa/ ) { $regtitle="Africa"; }
#convert the region title to upper case to look up the graphics file for the html
#$uc_regtitle = uc($regtitle);
$basep="$basep/$region";
#if ($ENV{DEVELOP}) { $basep="$basep/temp"; }
$model=@ARGV[0];
$title=uc $model; # title for table
$cycle=@ARGV[1];
$htmltmp="$basep/$model/$cycle";
$siz=@ARGV[2]; # siz=image size (different pages created for each
# image size: small, medium, large)
if($model =~ "gfsp03")
{
$img_str = "gfs";
}
if($model =~ "namp03")
{
$img_str = "nam";
}
if(DEBUG>0) {
print"model = $model\n";
print"cycle = $cycle\n";
print"siz = $siz\n";
print"region = $region\n";
}
if ($siz !~ /[sml]/) {
die "Size must be [sml]\n";
}
if ($cycle !~ /00|06|12|18/) {
if ($model !~ "ruc" ) {
die "cycle must be [00|06|12|18]\n";
}
}
$ofile="$htmltmp/p03_m.shtml";
#get the path for image directory
$image_dir ="$htmltmp/images/";
if($DEBUG>0) {
print"image directory = $image_dir\n";
}
if ($ENV{RELPATH}) {$hrf=$ENV{RELPATH}; }
else { $hrf="/pmb/nw${envir}/analysis"; }
# gifdir - location of the GIF files, based on model and cycle
# htmdir - location of the html files
# basep and gifdir together make up a complete path to the images of a
# particular model/cycle
$htmdir="/${model}/${cycle}";
#$gifdir="${htmdir}/3hr";
$gifdir="${htmdir}/images";
$modgifs="${basep}/${gifdir}";
return;
}
############################################################################
#########################################################################
# Creating header for model html page
sub do_main_hdr {
print MFF <<"EOS";
NCEP 3-Hour Total Precipitation Forecasts
EOS
return;
}
#########################################################################
# Generate the content of the UPA model page
#########################################################################
sub gen_body {
print MFF << "EOS2";
3-Hour Total Precipitation Forecasts
${regtitle} ${cycle} UTC ${title}
EOS3
return;
}
##################################################################
# Generate the content of the p03_m_loop.shtml page
####################################################################
sub create_m_p03_loop
{
open (MFF2, ">${htmltmp}/p03_m_loop.shtml");
print MFF2 << "EOS4";
00 NAM p03 Image Loop
EOS4
return;
}
##################################################################
# Generate the content of the p03_applet.shtml page
####################################################################
sub create_p03_applet
{
open (MFF3, ">${htmltmp}/p03_applet.shtml");
print MFF3 << "EOS5";
2m Dew Point Image Loop(24hrs ago to current)
EOS5
return;
}
##################################################################
# Generate the content of the loop_list page
####################################################################
sub create_loop_list
{
use File::Path;
mkpath "${htmltmp}/loop_lists/";
open (MFF4, ">${htmltmp}/loop_lists/loop.list");
print MFF4 << "EOS6";
images/${img_str}_p03_003m.gif
images/${img_str}_p03_006m.gif
images/${img_str}_p03_009m.gif
images/${img_str}_p03_012m.gif
images/${img_str}_p03_015m.gif
images/${img_str}_p03_018m.gif
images/${img_str}_p03_021m.gif
images/${img_str}_p03_024m.gif
images/${img_str}_p03_027m.gif
images/${img_str}_p03_030m.gif
images/${img_str}_p03_033m.gif
images/${img_str}_p03_036m.gif
images/${img_str}_p03_039m.gif
images/${img_str}_p03_042m.gif
images/${img_str}_p03_045m.gif
images/${img_str}_p03_048m.gif
images/${img_str}_p03_051m.gif
images/${img_str}_p03_054m.gif
images/${img_str}_p03_057m.gif
images/${img_str}_p03_060m.gif
images/${img_str}_p03_063m.gif
images/${img_str}_p03_066m.gif
images/${img_str}_p03_069m.gif
images/${img_str}_p03_072m.gif
images/${img_str}_p03_075m.gif
images/${img_str}_p03_078m.gif
images/${img_str}_p03_081m.gif
images/${img_str}_p03_084m.gif
EOS6
return;
}
##################################################################
# Generate the content of the no_data_found page
####################################################################
sub no_data_found
{
print MFF << "EOS3";
No 3-Hour Total Precipitation Forecasts Available For
${regtitle} ${cycle} UTC ${title}