#!/usr/local/perl/bin/perl -w # FZ to FU Perl Script # # Script to read in a river forecast, globally # change the FZ codes to an FY code, and output # the results to a temporary file. Then, the # temporary file is copied to the appropriate # location in the AWIPS system. # # Modifications: # JB Bower # 02 March 2004: Original Script # 04 March 2004: Change script to change FZ to FU (instead of FY) # 08 March 2004: Change open file line to get file from texdb read instead of local file copy # 25 April 2006: Changed matching to decode crest forecast # use strict; # CONSTANTS # Definition of values that are to remain # constant while the script is run. my $IN = 0; # Command argument position for the input file name my $TEMPFILE = "/awips/dev/localapps/hydro/bin/RIVER.TMP"; # File name of the output temp file my $AWIPSDIR = "/data/fxa/ispan/hydro/"; # Directory in which to place final output # # Open the temp file. If unable to create the temp # file, kill the script and give an error message. # die "Could not open output file $TEMPFILE\n" unless (open(OUTPUT, ">$TEMPFILE")); # # Make sure that an input file was listed at the # command line. If not, output an error, write # the error to the temp file, and kill the script. # unless($ARGV[$IN]) { print OUTPUT "Input file argument not given to script!\n"; die "Input file argument not given to script!\n"; } # # Eliminate any carriage returns that may exist in the # input file's name. (Just a precaution.) # my $infile = $ARGV[$IN]; $infile =~ s/"\n"//; # # Now that the argument is verified to exist, open the # input file. If it cannot be opened, output an error, # write the error to the temp file, and kill the # script # unless(open(INPUT, "/awips/fxa/bin/textdb -r $infile|")) { print OUTPUT "Input file $infile could not be opened\n"; die "Input file $infile could not be opened\n"; } # # All files are opened...now start replacing all # instances of the code FZ with FU. Note that this # will search for the pattern "/???FZ", where # a '?' represents any character, except null, and # will replace it with "/???FU". This will _help_ # to eliminate the possibility of destroying a # wanted "FZ", such as one that is part of a # station ID. # The "..." is the PED, e.g. HGI; and gets put into $+ # my $match = "FZ"; # the string to find my $replace = "FU"; # what to replace it with # Run through file while () { s/\/(...)$match/\/$+$replace/g; print OUTPUT; } # # Copy the temp file to the appropriate directory # for AWIPS. The copied file will have the same # file name as the original. Directory is defined # as a constant at the beginning of the script. # system("cp $TEMPFILE $AWIPSDIR$ARGV[$IN]"); # END OF FILE