#!/usr/bin/perl ############################################################################ # use: sref_model page [sref] [cycle] [s] # # cycle={03,09,15,21} # ############################################################################ # Turn on/off debug printing. # # 0 = No debugging # 1 = Some debugging # 2 = Verbose debugging $DEBUG=0; #$DEBUG=1; #$DEBUG=2; sub init_defs; sub get_cr; sub ch_col_name; sub do_main_hdr; sub pr_col_name; sub gen_body; sub createLoopHTML; sub createLoopHTMLIndex; $kk=1; init_defs; # initialize default variables, etc. get_cr; # determine rows and column names ch_col_name; # change column names to descriptive titles open (MFF, ">${ofile}"); do_main_hdr; # print main html header while ($kk < 4) { pr_col_name; # print column names in main page gen_body; # generate main page $kk++; } close MFF; exit 0; ############################################################################ ######################################################################### # Initial definitions and tests # Define some constants, make sure we have the right number and type of # arguments. sub init_defs { # turn off I/O buffering $| = 1; if ($DEBUG > 1) { print "Entering init_defs...\n"; } if ($#ARGV != 2) { die "Usage: build_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,eta, 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 ($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"; } $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 ($siz !~ /[sml]/) { die "Size must be [sml]\n"; } if ($cycle !~ /03|09|15|21/) { die "cycle must be [03|09|15|21]\n"; } $ofile="$htmltmp/model_${siz}.shtml"; $fpcf="$htmltmp/fpc.shtml"; if ($ENV{RELPATH}) {$hrf=$ENV{RELPATH}; } else { $hrf="/pmb/nw${envir}/analysis"; } # imagedir - relative location of the images directory # 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 # looplistdir - location of the image loop lists # ###MAS $htmdir="${region}/${model}/${cycle}"; $htmdir="/${model}/${cycle}"; $imagedir = "images"; $gifdir="${htmdir}/${imagedir}"; $modhtms=$htmltmp; $modgifs="${basep}${gifdir}"; $looplistdir = "loop_lists"; # Relative to the $htmdir. $full_looplistdir = "$basep$htmdir/$looplistdir"; if ( ! -e $full_looplistdir ) { mkdir("$full_looplistdir") || die "Error creating directory $full_looplistdir: $!.\n"; } if ($DEBUG > 0) { print "Base GIF directory(\$basep\$gifdir): $basep$gifdir \n"; print " basep: $basep\n"; print " gifdir: $gifdir\n"; print " htmdir: $htmdir\n"; print " modhtms: $modhtms\n"; print " looplistdir: $looplistdir (Relative to htmdir)\n"; print " imagedir: $imagedir (Relative to htmdir)\n"; } $cln=""; $clnv=0; # cln = column name; clnv = number of columns $tsn=""; $tsnv=0; # tsn = time slice name; tsnv = number of t.s. @cln=""; @tsn=""; # same as the variables, except these are arrays @cln1=""; # descriptive column names, corresponds to @cln $colnm=""; # number of columns in table #RRomero# Constants for the HTML code $HTML_website_title = "Model Analyses and Forecasts"; $HTML_table_border = "1"; $HTML_table_bgcolor = "#ffffff"; $HTML_table_cellpadding = "2"; $HTML_table_cellspacing = "0"; $HTML_table_width = "100%"; #RRomero# Set image looper variables. $HTML_loop_codebase = "/java/AniS"; $HTML_loop_archive = "aniscode.jar"; $HTML_loop_code = "AniS.class"; $HTML_loop_param_controls = "startstop, looprock, step, speed, firstlast, refresh, show, toggle"; $HTML_loop_param_active_zoom = "3"; $HTML_loop_param_backcolor = "xCCCCCC"; $HTML_loop_param_forecolor = "x000000"; $HTML_loop_param_pause = "2000"; $HTML_loop_param_pause_percent = "500"; $HTML_loop_param_toggle_size = "8,8,2"; #RRomero# Set the image size parameter for the image looper SWITCH: { $siz =~ /l/ && do { $HTML_loop_image_width = "1280"; $HTML_loop_image_height = "1124"; last SWITCH; }; $siz =~ /m/ && do { $HTML_loop_image_width = "1024"; $HTML_loop_image_height = "868"; last SWITCH; }; DEFAULT: do { $HTML_loop_image_width = "900"; $HTML_loop_image_height = "750"; }; } if ($DEBUG > 1) { print "HTML_loop_image_width: $HTML_loop_image_width, HTML_loop_image_height: $HTML_loop_image_height\n"; } if ($DEBUG > 1) { print "Leaving init_defs.\n"; } return; } ######################################################################### ############################################################################ ############################################################################ ######################################################################### # The next routine opens the directory given by $basep/$gifdir. It finds all # the images belonging to a particular image size and determines the column # headers as well as the number of rows and time slices based on the # file names. The nomenclature of the images is # "[model]_[type]_[time][size].gif". # Based on this information, all the different types and times can be # established. # # $cln and $tsn hold the (orderless) column names and times, respectively. # @cln and @tsn are lists that hold the ordered entries # $clnv and $tsnv contain the number of entries for each sub get_cr { if ($DEBUG > 1) { print "Entering get_cr...\n"; } if ($DEBUG > 0) { print " Opening GIF directory $modgifs...\n"; } opendir(MODR, $modgifs) || die "Error opening directory $modgifs: $!.\n"; if ($DEBUG > 0) { print " Reading GIF directory $modgifs...\n"; } @fnames = readdir MODR; if ($DEBUG > 1) { print " GIF filenames: @fnames\n"; } if ($DEBUG > 0) { print " Closing GIF directory $modgifs...\n"; } closedir MODR || die "Error closing directory $modgifs: $!.\n"; while ($curfl = (shift @fnames)) { if ($DEBUG > 1) { print " Checking $curfl...\n"; } if ($curfl =~ /.*_.*_\d{3,3}${siz}\.gif/o) { if ($DEBUG > 1) { print " Parsing $curfl...\n"; } ($mn, $clnn, $rest) = split /_/, $curfl, 3; ($tsnn, $rest) = split /${siz}\./, $rest, 2; if ($cln !~ /$clnn/i) { $cln = "$clnn:$cln"; $clnv++; } if ($tsn !~ /$tsnn/i) { $tsn = "$tsnn:$tsn"; $tsnv++; } } } @cln = sort reverse (split /:/, $cln); # sorted list of column names @tsn = sort (split /:/, $tsn); # sorted list of time slices $colnm=@cln + 1 ; # number of columns in table = # of column names + 1 if ($DEBUG > 1) { print <<"ENDOFTEXT"; cln = @cln tsn = @tsn colnm = $colnm ENDOFTEXT } if ($DEBUG > 1) { print "Leaving get_cr.\n"; } return; } ######################################################################### ############################################################################ ############################################################################ ######################################################################### # Change some of the column names we recognize to something more descriptive sub ch_col_name { if ($DEBUG > 1) { print "Entering ch_col_name...\n"; } open (MTR, "<$fixgem/webgif_mtrans") || die "Error opening $fixgem/webgif_mtrans: $!.\n"; while () { chomp; if ($_ =~ /^\w/) { ($coln, $desc) = split /:/, $_, 2; $table{$coln}="$desc"; } } for ($i=0;$i<$clnv;$i++) { $sub=$cln[$i]; if ($table{$sub} =~ /.{1,}/) { $cln1[$i] = $table{$sub}; } } close MTR || die "Error closing $fixgem/webgif_mtrans: $!.\n"; if ($DEBUG > 1) { print "Leaving ch_col_name.\n"; } return; } ######################################################################### ######################################################################### # Creating header for model html page sub do_main_hdr { if ($DEBUG > 1) { print "Entering do_main_hdr...\n"; } print MFF <<"ENDOFTEXT"; NCEP ${title} Model Forecasts

${HTML_website_title}
${regtitle} ${cycle} UTC ${title}

ENDOFTEXT print MFF << "ENDOFTEXT";
[850-700 Thk, 10m Winds, 2m Tmp, Mean SL Pres, CAPE, CIN, Lifted Index, 6-hr precip, 12-hr precip, and 24-hr precip.]
[6-hr Precip > .25, Prob. of CAPE, 2m Tmp < 0, and 10m Winds > 25 Knots ] ENDOFTEXT if ($DEBUG > 1) { print "Leaving do_main_hdr.\n"; } return; } ######################################################################### ############################################################################ # Print out column names for all existing files sub pr_col_name { if ($DEBUG > 1) { print "Entering pr_col_name...\n"; } $prc=int (192/$clnv); $iopen=0; $iclose=10; if ($kk == 2 ) { $iopen=10; $iclose=20; } if ($kk == 3 ) { $iopen=20; $iclose=$clnv; } for ($i=$iopen;$i<$iclose;$i++) { print MFF "\n"; } print MFF "\n"; if ($DEBUG > 1) { print "Leaving pr_col_name.\n"; } return; } ######################################################################### ######################################################################### # Generate the content of the main and 4-panel pages sub gen_body { if ($DEBUG > 1) { print "Entering gen_body...\n"; } $bgc=0; # set background to 0 # $bgc keeps alternating between 0 and 1 and determines # the background color for any particular row. $day=0; # $day keeps track of the day we're looking at, # starting with 0 at 0Z $j=0; # j goes through all time steps that are given in tsn #RRomero# Begin printing the HTML row containing the "loop" links. print MFF "\n"; print MFF "\n"; $iopen=0; $iclose=10; if ($kk == 2) { $iopen=10; $iclose=20; } if ($kk == 3) { $iopen=20; $iclose=$clnv; } for ( $i=$iopen;$i<$iclose;$i++ ) { $cln=$cln[$i]; $flnm2="${model}_"; $flnm2="${flnm2}${cln}_"; $looplistfilename = "${looplistdir}/${cln}_${siz}_loop.list"; $loophtml="${cln}_${siz}_loop.shtml"; $loophtmlindex="index_${cln}_${siz}_loop.shtml"; if ($DEBUG > 1) { print <"; print MFF "Loop"; print MFF "\n"; } print MFF "\n"; #RRomero# End printing the HTML row containing the "loop" links. while ($j < $tsnv) { $stepcnt=0; # stepcnt keeps track of how many steps we have in each day while (($tsn[$j] <= $day*24) && ($j < $tsnv) ) { unshift @hrofday, $tsn[$j]; $j++; $stepcnt++; } if ($DEBUG > 1) { print " hrofday=@hrofday\n"; } if ($DEBUG > 1) { print " j=$j, tsnv=$tsnv, stepcnt=$stepcnt\n"; } # @hrofday contains the number of hours within the day # given by $day, starting with day 0 (initial). for ($n = 0; $n < $stepcnt; $n++) { $tstp = pop @hrofday; if ($DEBUG > 1) { print " tstp=$tstp\n"; } if ($bgc == 0) { print MFF "\n"; $bgc=1; } else { print MFF "\n"; $bgc=0; } if ($tstp == 0) { print MFF "\n"; } if ($n == 0 && $tstp != 0) { print MFF "\n"; } $iopen=0; $iclose=10; if ($kk == 2) { $iopen=10; $iclose=20; } if ($kk == 3) { $iopen=20; $iclose=$clnv; } for ($i = $iopen; $i < $iclose; $i++) { print MFF "\n"; } print MFF ""; } $day++; } $i=0; @ctime=localtime(time); $ctime[4]++; if ($ctime[2] < 10) { $ctime[2]="0$ctime[2]"; } if ($ctime[1] < 10) { $ctime[1]="0$ctime[1]"; } print MFF "

 $cln1[$i]
 
Initial"; print MFF "Day ${day}"; $cln = $cln[$i]; $flnm2 = "${model}_"; $flnm2 = "${flnm2}${cln}_"; ## $looplist = "${DATA}/web/output/loop_lists/${cln}_${siz}_loop.list"; $looplist = "${modhtms}/${looplistdir}/${cln}_${siz}_loop.list"; $flnm2 = "${flnm2}${tstp}${siz}.gif"; if ($DEBUG > 1) { print <<"ENDOFTEXT"; cln2=$cln2 clnv=$clnv cln=$cln[$i] flnm2=${model}_ flnm2=${flnm2}${cln}_ flnm2=${flnm2}${tstp}${siz}.gif ### GIF File: $basep$gifdir/$flnm2 --Zhu GIF File: $modgifs/$flnm2 looplist: $looplist ENDOFTEXT } if ( $j == 1 && -e $looplist ) { if ($DEBUG > 0) { print " Deleting previous loop image listing file $looplist.\n"; } if ($DEBUG > 0) { print " Running \"rm -f $looplist\".\n"; } #system("rm -f $looplist"); unlink($looplist) || die "Error deleting $looplist: $!\n"; } if ( $DEBUG > 0 ) { print "Fully qualified GIF filename: $basep$gifdir/$flnm2\n"; } ###if (-e "$basep$gifdir/$flnm2") { --Zhu if (-e "$modgifs/$flnm2") { #RRomero# Begin open and write this image to the loop file list. open (LOOPLIST, ">> $looplist") || die "Error opening $looplist: $!\n"; print LOOPLIST "$imagedir/$flnm2\n"; #RR#TESTING PURPOSES#print LOOPLIST "/pmb/nw${envir}/analysis/namer/$gifdir/$flnm2\n"; close LOOPLIST || die "Error closing $looplist: $!\n"; #RRomero# End open and write this image to the loop file list. print MFF "$tstp"; } else { print MFF "$tstp"; } print MFF "
"; if ($kk < 3 ){ if ($kk == 1) { print MFF << "ENDOFSCR";
[250mb Hts, 250mb Wnds, 500mb Hts, 700mb RH, 700mb Tmp, 850mb RH, 850mb Tmp, 850mb Wnds, 1000-850 Thk, and 1000-500 Thk.]
[6-hr Precip > .25, Prob. of CAPE, 2m Tmp < 0, and 10m Winds > 25 Knots ] ENDOFSCR } if ($kk == 2) { print MFF << "ENDOFIPT";
250mb Hts, 250mb Wnds, 500mb Hts, 700mb RH, 700mb Tmp, 850mb RH, 850mb Tmp, 850mb Wnds, 1000-850 Thk, and 1000-500 Thk ]
[850-700 Thk, 10m Winds, 2m Tmp, Mean SL Pres, CAPE, CIN, Lifted Index, 6-hr precip, 12-hr precip, and 24-hr precip.] ENDOFIPT } print MFF << "EOF9";

EOF9 } else { print MFF ""; print MFF ""; print MFF ""; print MFF "Page last modified:"; print MFF "\n"; print MFF "\n"; } if ($DEBUG > 1) { print "Leaving gen_body.\n"; } return; } ######################################################################### ############################################################################ sub createLoopHTML { my $MYNAME = "createLoopHTML"; if ($DEBUG > 1) { print "Entering $MYNAME.\n"; } my($model_html_dir, $loophtml, $looplistfilename, $cycle, $model, $cln, $siz) = @_; if ($DEBUG > 1) { print <<"ENDOFTEXT"; Variables Passed: model_html_dir = $model_html_dir loophtml = $loophtml looplistfilename = $looplistfilename cycle = $cycle model = $model cln = $cln siz = $siz ENDOFTEXT } #RR#Override for testing purposes #RR#$model_html_dir = "${DATA}/web/output"; $loophtml_full_path = "$model_html_dir/$loophtml"; open(LOOPHTML, "> $loophtml_full_path") || die "Error opening $loophtml_full_path for writing: $!\n"; $model = uc $model; $caption = "$cycle $model $cln Image Loop"; print LOOPHTML <<"ENDOFTEXT";
 
$caption
ENDOFTEXT close(LOOPHTML) || die "Error closing $loophtml_full_path: $!\n"; if ($DEBUG > 1) { print "Leaving $MYNAME.\n"; } } ######################################################################### ############################################################################ sub createLoopHTMLIndex { my $MYNAME = "createLoopHTMLIndex"; if ($DEBUG > 1) { print "Entering $MYNAME.\n"; } my($model_html_dir, $loophtml, $loophtmlindex, $model) = @_; if ($DEBUG > 1) { print <<"ENDOFTEXT"; Variables Passed: model_html_dir = $model_html_dir loophtml = $loophtml loophtmlindex = $loophtmlindex model = $model ENDOFTEXT } #RR#Override for testing purposes #RR#$model_html_dir = "${DATA}/web/output"; $loophtmlindex_full_path = "$model_html_dir/$loophtmlindex"; open(LOOPHTMLINDEX, "> $loophtmlindex_full_path") || die "Error opening $loophtmlindex_full_path for writing: $!\n"; $model = uc $model; #NOTE: #NOTE: The below HTML implements the NWS corporate web image for the image loop web page. #NOTE: DO NOT MODIFY WITHOUT CONSULTING THE NCEP WEBMASTER. #NOTE: print LOOPHTMLINDEX <<"ENDOFTEXT"; NCEP Model Analyses and Forecasts
NCEP Home > NCEP Central Operations > Production Management Branch > Model Analyses and Forecasts > $model
Page last modified:
ENDOFTEXT close(LOOPHTMLINDEX) || die "Error closing $loophtml_full_path: $!\n"; if ($DEBUG > 1) { print "Leaving $MYNAME.\n"; } }