#!/usr/bin/perl -w # RWB June 5, 2001 # This is a Perl script to read in data files with one day's data each # from the Richmond ADCP and concatenate a month's data into a single # file. This script (fixstage) is for the stage data. @mday=(0,31,59,90,120,151,181,212,243,273,304,334); $infn1='/d4/Darmat/data/naut/tides/2000/11/20001101.rmw.cgi'; # first file $d1=1; # first day $d2=30; # last day $outfilename='>/d4/Darmat/data/naut/tides/2000/11/asd01100.rmw'; # one month $outfilename='>'.substr($infn1,0,length($infn1)-16).'asd'. substr($infn1,-21,1).substr($infn1,-19,2).'00.rmw'; # print "$outfilename\n"; open(OUTFILE, $outfilename) or die "can't open file: $outfilename $!\n"; $infn=$infn1; for ($i=$d1; $i <= $d2; $i++) { substr($infn,-10,2)=sprintf("%02d",$i); print "\$infn after substitution = $infn\n"; open(INFILE, $infn) or die "can't open file: $infn $!\n"; while () { chomp; # no good for stage if (/(2000|2001)/) { # best way to select data lines. # if (/(Richmond|SeaLevel|0.00;0.00;0.00;)/) { # best way to select data lines. if (!/;....\s..\/..\s..:../) { # best way to select data lines. # print 'nonstandard line: '.$_."\n"; } else { s/\*{6}/999.99/; # replace a first bad value by a number. s/\*{6}/999.99/; # replace a second bad value. s/\*{6}/999.99/; # replace a third bad value. # print "\$_ = $_\n"; @fields=split(/;/); # parse as semi-colon delimited # Take apart the third field to get year, month, day, hour, minute. # Then calculate the time. Units are days since beginning of Jan. 1, # 1970. if(!$fields[3]) { print "\$_ = $_\n"; print "length(\$_) = ".length($_)."\n"; print "fields[0] = $fields[0]aa\n"; print "fields[1] = $fields[0].\n"; print "fields[2] = $fields[0].\n"; print "fields[3] = $fields[0].\n"; print "fields[4] = $fields[0].\n"; } $yr=substr($fields[3],0,4); # year $yr=substr($infn,-24,4); # year from input file name. $mo=substr($fields[3],5,2); # month $dy=substr($fields[3],8,2); # day ################################################################## # Correct a formatting error for current data from SFPORTS # $dy-=1; ################################################################## $hr=substr($fields[3],11,2); # hour $mn=substr($fields[3],14,2); # minute $mdays=$mday[$mo-1]; if(($yr%4)==0 && $mo>2) {$mdays+=1;} # leap-year correction. $time = int(($yr-1970)*365.25)+$mdays+$dy-1+($hr+$mn/60)/24; # printf("Time since start of Jan 1 1970 = %6.10f\n",$time); # Convert from feet to meters. if ($fields[0] !~ '999.99') {$h=$fields[0]*12*.0254;} else {$h='999.99';} print OUTFILE sprintf("%3.3f,%6.5f\n",$h,$time); # output as # comma-delimited string } } close(INFILE) or die "can't close INFILE\n"; } close(OUTFILE) or die "can't close OUTFILE\n"; open( TEMP,'>perltemp.tmp' ); print TEMP "rmw2wdsk,'".substr($outfilename,1)."'\nexit"; close( TEMP ); system("idl perltemp.tmp"); # Call IDL to reformat data. unlink( "perltemp.tmp" );