#!/iag/bin/perl initialize(); ($begSecs, $endSecs) = createTimeAxis(); #----------------------------------------------------------------------- # This is a HORRIBLE KLUDGE but I just don't have time to make it right. # The issue is that mooring turnaround times have gone from weeks to # hours, which means the oasis directory structure has the daily info # for those particular turnaround days in two separate files. I don't # want to deal with that...so I do this kludge as a workaround :>{ #----------------------------------------------------------------------- #if( $Mooring eq "M1" ) # { $begSecs += 86400; } #if( $Mooring eq "M2" ) # { $begSecs += 2*86400; } createNc( $begSecs, $endSecs ); openNc(); processAtlas(); processCtd(); NetCDF::close( $ncID ); exit; #\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\ # # #////////////////////////////////////////////////////////////////////////////// sub initialize { $Mooring = shift(@ARGV); $monYY = shift(@ARGV); #----------------------------------------------------------------------- # deployed moorings #----------------------------------------------------------------------- @Mooring = ("M1","M2"); #----------------------------------------------------------------------- # deployment monYY #----------------------------------------------------------------------- @monYY = ("jan92", "aug92", "oct93", "mar95", "jun96", "may97"); die "Usage: ncCreate.pl monYY\n" unless(grep( /$Mooring/, @Mooring) and grep( /$monYY/, @monYY ) ); #----------------------------------------------------------------------- # find the indexes into the @Mooring and @monYY arrays for the input # parameters #----------------------------------------------------------------------- $moorNum = 0; for( @Mooring ) { last if( $Mooring[$moorNum] eq $Mooring ); $moorNum++; } $deployNum = 0; for( @monYY ) { last if( $monYY[$deployNum] eq $monYY ); $deployNum++; } #----------------------------------------------------------------------- # deployment YYDDD (per mooring) #----------------------------------------------------------------------- @yyddd = ([ "92016", "92244", "93308", "95075", "96177", "97213" ], [ "", "92267", "93287", "95059", "96205", "97126" ]); #----------------------------------------------------------------------- # deployment dates (per mooring) #----------------------------------------------------------------------- @deploy = (["Jan 16, 1992", "Aug 31, 1992", "Nov 04, 1993", "Mar 16, 1995", "Jun 25, 1996", "Aug 01, 1997"], ["", "Sep 23, 1992", "Oct 14, 1993", "Feb 28, 1995", "Jul 23, 1996", "May 06, 1997"]); #----------------------------------------------------------------------- # output netcdf file #----------------------------------------------------------------------- $ncFile = $Mooring . "-" . $yyddd[$moorNum][$deployNum] . ".nc"; #----------------------------------------------------------------------- # input file names #----------------------------------------------------------------------- ($mooring = $Mooring) =~ s/M/m/; $root = "/hosts/tsunami/oasis"; $atlasFile = join('/', $root, $monYY, $mooring, "data/atlas"); ($ctdFile = $atlasFile ) =~ s/atlas$/ctd/; #----------------------------------------------------------------------- # kludge for current deployment (which is under a slightly different # directory structure #----------------------------------------------------------------------- if( $monYY eq "may97" ) { $atlasFile = join('/', $root, $mooring, "data/atlas"); ($ctdFile = $atlasFile ) =~ s/atlas$/ctd/; } #----------------------------------------------------------------------- # verify input files exist #----------------------------------------------------------------------- unless( -e $atlasFile ) { print "Can't open $atlasFile for ATLAS input\n"; print "Usage: ncCreate.pl monYY\n"; } unless( -e $ctdFile ) { print "Can't open $ctdFile for CTD input\n"; print "Usage: ncCreate.pl monYY\n"; } #----------------------------------------------------------------------- # Don't buffer print statements #----------------------------------------------------------------------- $| = 1; #----------------------------------------------------------------------- # #----------------------------------------------------------------------- unshift( @INC, "../bin" ); require 'timelocal.pl'; require 'processAtlas.pl'; require 'processCtd.pl'; require 'ncUtils.pl'; #----------------------------------------------------------------------- # #----------------------------------------------------------------------- use NetCDF; } #---initialize---# #\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\ # # #////////////////////////////////////////////////////////////////////////////// sub createTimeAxis { my( $firstTime, $lastTime ); my(@atlasTime ) = getFirstLastTimes( $atlasFile ); my(@ctdTime ) = getFirstLastTimes( $ctdFile ); $firstTime = ($atlasTime[0] < $ctdTime[0]) ? $atlasTime[0] : $ctdTime[0]; $lastTime = ($atlasTime[1] > $ctdTime[1]) ? $atlasTime[1] : $ctdTime[1]; ( $firstTime, $lastTime ); } #---createTimeAxis---# #\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\ # # #////////////////////////////////////////////////////////////////////////////// sub createNc { ( $begSecs, $endSecs ) = @_; #----------------------------------------------------------------------- # Create shell #----------------------------------------------------------------------- ($replace{"NAME"} = $ncFile) =~ s/\.nc$//; $replace{"DEPLOY"} = "Deployed $deploy[$moorNum][$deployNum]"; $replace{"MOORING"} = $Mooring; open( TEMPL, "Mooring.cdl-template" ) or die "Didn't find Mooring.cdl-template"; open( OUT, "| ncgen -b" ); while( $line = ) { foreach $key ( keys %replace ) { if( $line =~ /$key/ ) { $line =~ s/$key/$replace{$key}/; } } print OUT $line; } close( TEMPL ); close( OUT ); openNc(); $nextSecs = $begSecs; while( $nextSecs < $endSecs+$secsPerTimeStep ) { push( @epochSecs, $nextSecs ); $nextSecs += $secsPerTimeStep; } @start = 0; @count = $#epochSecs+1; NetCDF::varput( $ncID, $varID{"oasisTime"}, \@start, \@count, \@epochSecs ); NetCDF::close( $ncID ); } #---createNc---# #\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\ # # #////////////////////////////////////////////////////////////////////////////// sub getFirstLastTimes { my( $file ) = $_[0]; open( FILE, $file ) or die("Failed to open $file\n"); my( $firstSecs, $lastSecs, $line, $year ); #-------------------------------------------------------------------- # get first epoch time value #-------------------------------------------------------------------- while( ) { next if/^#/; s/^\s+//; @field = split('\s+',$_); $year = pop( @field ); $firstSecs = timegm(0,0,0,1,0,substr($year,2,2)) + int(($field[0]-1) * $secsPerDay); last; } #-------------------------------------------------------------------- # get last epoch time value #-------------------------------------------------------------------- while( ) { s/^\s+//; @field = split('\s+',$_); $year = pop( @field ); $lastSecs = timegm(0,0,0,1,0,substr($year,2,2)) + int(($field[0]-1) * $secsPerDay); } ( $firstSecs, $lastSecs ); } #---getFirstLastTimes---#