#!/usr/bin/perl -w # RWB May 30, 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. @mday=(0,31,59,90,120,151,181,212,243,273,304,334); $infn1='/d4/Darmat/data/naut/tides/2000/11/20001101.rmc'; # first file $d1=1; # first day $d2=30; # last day $outfilename='>/d4/Darmat/data/naut/tides/2000/11/asd01100.rmc'; # one month $outfilename='>'.substr($infn1,0,length($infn1)-12).'asd'. substr($infn1,-17,1).substr($infn1,-15,2).'00.rmc'; # print "$outfilename\n"; open(OUTFILE, $outfilename) or die "can't open file: $outfilename $!\n"; $infn=$infn1; for ($i=$d1; $i <= $d2; $i++) { substr($infn,-6,2)=sprintf("%02d",$i); print "\$infn after substitution = $infn\n"; open(INFILE, $infn) or die "can't open file: $infn $!\n"; while () { chomp; if (/(2000|2001)/) { # best way to select data lines. s/\*{6}/999.99/; # replace a first bad value by a number. s/\*{6}/999.99/; # replace a second bad value. @fields=split(/;/); # parse as semi-colon delimited # Use the current speed and direction to calculate the projectiojn # of the current velocity on a direction $angref (measured clockwise # from the north). $angref=340; # 20 degrees west of north $angle=$fields[0]; $speed=$fields[1]; if ($fields[0] !~ '999.99') {$v=$speed*cos(($angle-$angref)* 3.14159/180)*12*0.0254;} else {$v='999.99';} # printf("\$angle, \$speed, \$v = $angle, $speed, $v"); # 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. # print $fields[2]; $yr=substr($fields[2],0,4); # year $mo=substr($fields[2],5,2); # month $dy=substr($fields[2],8,2); # day $hr=substr($fields[2],11,2); # hour $mn=substr($fields[2],14,2); # minute # printf("\$mo, \$mday[\$mo-1] = $mo, $mday[$mo-1]"); # printf("\$yr, \$mo, \$dy, \$hr, and \$mn = %d %d %d %d %d\n", # $yr, $mo, $dy, $hr, $mn); $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); print OUTFILE sprintf("%3.3f,%6.5f\n",$v,$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 "rmc2wdsk,'".substr($outfilename,1)."'\nexit"; close( TEMP ); system("idl perltemp.tmp"); # Call IDL to reformat data. unlink( "perltemp.tmp" );