[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Modifying headers



modHdrs is a script to change the headers of a strange feedtype to look
like a standard NOAAport header.

Robb...

#!/usr/local/bin/perl
#
#  Program to modify headers and trailers of feedtype to look like the 
#  old FOS format.  
#
#  usage: 
#
#  IDS|DDPLUS   
#  written by Robb Kambic 12/3/99
#
# process command line switches, no valid switches at this time
while ($_ = $ARGV[0], /^-/) {
         shift;
       last if /^--$/;
             /^(-v)/ && $verbose++;
             /^(-d)/ && ($dir = shift) ;
}
$dir = "." if( ! $dir ) ;

# process input parameters
if( $#ARGV == 0 ) {
        open( STDOUT, ">$dir/$ARGV[ 0 ]" ) || die "could not open $ARGV[ 0 ] 
$!\n" ;
}
select( STDOUT ) ; $| = 1 ;

# set interrupt handler
$SIG{ 'INT' }  = 'atexit' ;
$SIG{ 'KILL' }  = 'atexit' ;
$SIG{ 'TERM' }  = 'atexit' ;
$SIG{ 'QUIT' }  = 'atexit' ;

# Now begin parsing stream and breaking on \cC
$/ = "\cC" ;
# main loop   set select processing here from STDIN
START:
while( 1 ) {
        open( STDIN, '-' ) ;
        vec($rin,fileno(STDIN),1) = 1;
        $timeout = 1800 ; # 30 minutes
        $nfound = select( $rout = $rin, undef, undef, $timeout );
        # timed out
        if( ! $nfound ) {
                print STDERR "Shut down, time out 30 minutes\n" ;
                atexit() ;
        }
        atexit( "eof" ) if( eof( STDIN ) ) ;

        $_ = <STDIN> ; # get product
        #
        # Check and modify NOAAport headers 
        #
        s#^.*\cA.*\cA....#\cA\cM\r\n999 \cM\r\n# ; 
        #
        print $_ ; # write product
        #
        atexit( "eof" ) if( eof( STDIN ) ) ;
} # end while( 1 )
atexit( "eof" );
exit( 0 ) ; #should never get here

# execute at exit
sub atexit
{
local( $sig ) = @_ ;

if( $sig eq "eof" ) {
        print STDERR "eof on STDIN -- shutting down\n" ;
} elsif( defined( $sig )) {
        print STDERR "Caught SIG$sig -- shutting down\n" ;
}
close( STDOUT ) ;
close( STDERR ) ;
exit( 0 ) ;

}

===============================================================================
Robb Kambic                                Unidata Program Center
Software Engineer III                      Univ. Corp for Atmospheric Research
address@hidden             WWW: http://www.unidata.ucar.edu/
===============================================================================