#! /usr/bin/perl ############################################################################ # zsolt.szabo@noaa.gov # # use: drfice [model name] [cycle] [size] # # model name={drf} # # cycle={0} # # size={s} # ############################################################################ sub init_defs; sub get_cr; sub ch_col_name; sub do_main_hdr; sub pr_col_name; sub gen_body; sub pr_col_name2; init_defs; # initialize default variables, etc. get_cr; # determine rows and column names ch_col_name; # change column names to descriptive titles # Here we build the web page and write it out to $ofile (which is # defined above as $modhtml/model_[size].shtml) open (MFF, ">${ofile}"); do_main_hdr; # print main html header pr_col_name; # print column names in main page gen_body; # generate main page 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: buildpage [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 ($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 !~ /00|06|12|18/) { if ($model !~ "ruc" ) { die "cycle must be [00|06|12|18]\n"; } } $ofile="$htmltmp/model_${siz}.shtml"; $fpcf="$htmltmp/fpc.shtml"; 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 ###MAS $htmdir="${region}/${model}/${cycle}"; $htmdir="/${model}/${cycle}"; $gifdir="${htmdir}/images"; $modhtms=$htmltmp; $modgifs="${basep}/${gifdir}"; $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 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 { print " modgifs is $modgifs " ; opendir MODR, $modgifs or die "directory does not exist\n"; @fnames = readdir MODR; closedir MODR; while ($curfl = (shift @fnames)) { if ($curfl =~ /.*_.*_\d{3,3}${siz}\.gif/o) { ($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 return; } ######################################################################### ############################################################################ ############################################################################ ######################################################################### # Change some of the column names we recognize to something more descriptive sub ch_col_name { open (MTR, "<$fixgem/webgif_mtrans") or die "Cannot open $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; return; } ######################################################################### ############################################################################ ############################################################################ ######################################################################### # Creating header for model html page sub do_main_hdr { print MFF <<"EOS"; /MMAB/NCEP Polar Ice Drift Forecasts

National Centers for Environmental Prediction

Drift Ice Model Forecasts

EOS print MFF << "EOS2"; EOS2 return; } ######################################################################### ############################################################################ ############################################################################ ######################################################################### # Print out column names for all existing files sub pr_col_name { $prc=int (96/$clnv); for ($i=0;$i<$clnv;$i++) { print MFF "\n"; } print MFF "\n"; return; } ######################################################################### ############################################################################ # Print out embedded column names sub pr_col_name2 { $fpcn=@fpcols; # number of columns in 4 panel chart + 1 print MFF ""; print MFF "\n"; $prc=int (96/$clnv); for ($i=0;$i<$clnv;$i++) { print MFF "\n"; } print MFF "\n"; return; ############################################################################ ######################################################################### # Generate the content of the main/4-panel pages sub gen_body { $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 while ((int $j)<(int $tsnv)) { # stepcnt keeps track of how many steps we have in each # day $stepcnt=0; while (((int @tsn[$j])<=(int $day*24)) && ((int $j) < (int $tsnv))) { unshift @hrofday, @tsn[$j++]; $stepcnt++; } # @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 ($bgc==0) { print MFF "\n"; $bgc=1; } else { print MFF "\n"; $bgc=0; } if ((int $tstp)==0) { print MFF "\n"; } if ($n==0 && $tstp != 0) { print MFF "\n"; } # Print all appropriate columns on the main page for ($i=0;$i<$clnv;$i++) { print MFF "\n"; } # Print all appropriate columns on the 4-panel page for ($i=0;$i<$fpcn;$i++) { @cnms=split /:/,@fpcols[$i]; } print MFF ""; } $day++; } # Print out column names for all existing files $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 "
${cycle} UTC
 @cln1[$i]
@cln1[$i]
Initial"; print MFF "Day ${day}"; $cln=@cln[$i]; $flnm2="${model}_"; $flnm2="${flnm2}${cln}_"; $flnm2="${flnm2}${tstp}${siz}.gif"; if (-e "$basep/$gifdir/$flnm2") { print MFF "$tstp"; } else { print MFF "$tstp"; } print MFF "
"; print MFF ""; print MFF ""; print MFF ""; print MFF "Created: 17-Jul-01, Last updated: "; print MFF "\n"; print MFF "\n"; close MFF; return; } ######################################################################### }