#! /bin/perl # zsolt.szabo@noaa.gov #This code is modified to call the UpperAir html creation page $mailsub="web problem related to update script"; $user="zsolt.szabo\@noaa.gov"; if ($#ARGV != 2) { $mstrg="Incorrect arguments/argument count for update.\nuse: update [model] [cycle] [date]\nAborted.\n"; goto mail_send; } $bmodpg="build_model_page"; $dmodpg="drfice_model_page"; $fmodpg="sref_model_page"; $umodpg="upa_model_page"; if ($ENV{USHgempak}) { $scriptdir=$ENV{USHgempak}; } else { die "Please define ENV USHgempak.\n"; } $moddate="moddate"; $model=@ARGV[0]; $cycle=@ARGV[1]; $cdate=@ARGV[2]; print "model = $model\n"; if ($model !~ /nam|gfs|wrf|ngm|ruc|storm_1|storm_2|storm_3|storm_4|wave|drf|sref|hiresw|gefs|rtma|gens/) { $mstrg="Incorrect model: $model given.\nAborted.\n"; goto mail_send; } print "cycle = $cycle\n"; if ($cycle !~ /00|06|12|18/) { if ( $model !~ /ruc|sref|rtma/ ) { $mstrg="Incorrect cycle: $cycle.\nAborted.\n"; goto mail_send; } } if (!($ENV{BASEDIR})) { die "Please define env var BASEDIR first.\n"; } if (!($ENV{REGION})) { die "Please define env var REGION first.\n"; } $basedir="$ENV{BASEDIR}/$ENV{REGION}"; $basefile="$ENV{BASEDIR}"; if ($ENV{DEVELOP}) { $basedir="$basedir/temp"; } $htmdir="$basedir/$model/$cycle"; $gifdir="$htmdir/images"; if (-e "$gifdir/.update_lock") { sleep 30; if (-e "$gifdir/.update_lock") { $mstrg="You may have a stale lock file.\nAborted.\n"; goto mail_send; } } # we create a lock file and only release it once we're done. # that way we can ascertain that only one instance of update is # running open LFILE, ">$basedir/.update_lock"; close LFILE; # $ENV{MODELDATES} points to the file that contains the update times if ($ENV{MODELDATES}) { $datefile=$ENV{MODELDATES}; } else { $mstrg="need to set MODELDATES environment variable.\n"; goto mail_send; } $sufx=rand 1000; open ODATE, "<$datefile" or die "Couldn't read $datefile.\n"; open NDATE, ">$datefile_$cdate.$sufx" or die "couldn't write to $datefile_$cdate.$sufx.\n"; while ($dline=) { chomp($dline); ($mdl,$cycls)=split /:/,$dline,2; if ($mdl !~ /$model/) { print NDATE "$dline\n"; } else { print NDATE "$model:"; @cupd=split /:/,$cycls; $numcycls=@cupd; for ($i=0;$i<$numcycls;$i++) { if (@cupd[$i] =~ /$cycle-/) { ($cycle,$odate)=split /-/,@cupd[$i]; @cupd[$i]="$cycle-$cdate"; } print NDATE "@cupd[$i]"; if (($i+1)<$numcycls) { print NDATE ":"; } else { print NDATE "\n"; } } } } close ODATE; close NDATE; unlink "$datefile" or die "Couldn't update $datefile.\n"; rename "$datefile_$cdate.$sufx", "$datefile" or die "Couldn't move $datefile_$cdate.$sufx to $datefile.\n"; print "odate = $odate\n"; if (!($odate)) { print "$odate bad cycle time given.\n"; exit 1; } if ($odate !~ /$cdate/) { print "date has changed. Old date: $odate. New date: $cdate.\n"; #open NODATE, ">$htmdir/.date" or die "Couldn't write to $htmdir/.date.\n"; #print NODATE "$cdate"; #close NODATE; if (!(opendir INFILES2, $gifdir)) { $mstrg="Couldn't open $gifdir.\nAborted.\n"; goto mail_send; } @fnames2 = readdir INFILES2; closedir INFILES2; foreach $file (@fnames2) { if ($file =~ /.*.gif/) { if (!(unlink "$gifdir/$file")) { $mstrg="Couldn't delete $gifdir/$file.\nAborted.\n"; goto mail_send; } else { print "Removed $gifdir/$file\n"; } } } } @fnames1 = readdir INFILES1; closedir INFILES1; foreach $file (@fnames1) { if ($file =~ /.*.gif/) { if (!(rename "$incoming/$file", "$gifdir/$file")) { $mstrg="Couldn't move $incoming/$file to $gifdir/$file.\nAborted.\n"; goto mail_send; } } } @args_s=("$scriptdir/$bmodpg", "$model", "$cycle", "s"); @args_m=("$scriptdir/$bmodpg", "$model", "$cycle", "m"); @args_l=("$scriptdir/$bmodpg", "$model", "$cycle", "l"); @args_d=("$scriptdir/$dmodpg", "$model", "$cycle", "s"); @args_f=("$scriptdir/$fmodpg", "$model", "$cycle", "s"); @args_u=("$scriptdir/$umodpg", "$model", "$cycle", "l"); if ($model !~ "sref"){ if ($model !~ "drf" ) { print "@args_s[0] - @args_s[1] - @args_s[2] - @args_s[3]\n"; print "$basedir\n"; print "model = $model\n"; if ( $basedir !~ /united|canada|mexico|alaska/) { if ( ($model !~ /hiresw|gefs|rtma|gens/) && ($basedir !~ /samer|epac|africa/) ) { print "try to build small model page\n"; if (system(@args_s) != 0) { $mstrg="Couldn't build small model page.\nAborted.\n"; goto mail_send; } } if ( $model !~ "rtma") { print "try to build medium model page\n"; if (system(@args_m) != 0) { $mstrg="Couldn't build medium model page.\nAborted.\n"; print "Couldn't build medium model page.\nAborted.\n"; goto mail_send; } } if ( ($model !~ /gefs|gens/) && ($basedir !~ /samer|epac|africa/) ) { print "try to build large model page\n"; if (system(@args_l) != 0) { print "system(@args_l)\n"; $mstrg="Couldn't build large model page.\nAborted.\n"; goto mail_send; } } } else { if ( ($model =~ "gfs" ) || ($model =~ "nam") ) { print "@args_u[0] - @args_u[1] - @args_u[2] - @args_u[3]\n"; if(system(@args_u) != 0) { $mstrg="Couldn't build upperair modelpage.\nAborted.\n"; goto mail_send; } } } } else { if (system(@args_d) != 0) { $mstrg="Couldn't build drfice modelpage.\nAborted.\n"; goto mail_send; } } } else { if (system(@args_f) != 0) { $mstrg="Couldn't build sref modelpage.\nAborted.\n"; goto mail_send; } } unlink "$gifdir/.update_lock"; @args=("$scriptdir/$moddate $model $cycle $cdate"); print "system(@args)"; if (system(@args) != 0) { $mstrg="Couldn't update main models.html page.\nAborted.\n"; goto mail_send; } exit 0; mail_send: unlink "$gifdir/.update_lock"; print "$mstrg\n"; exit 1;