#! /usr/bin/perl # read daily ascii simrad data on NBP0104 #use Date::Calc qw(Day_of_Week Week_Number Day_of_Week_to_Text); use Time::Local; $knot=-999; ## is the default value for stuff you don't want in your file. ######### ENTER DAYS TO PROCESS in simnowplotter.m or day.dat file ############# open (SIMDAY, "/home/karen/NBP/day.dat") or die "can't in simday\n"; while ($linen=){ @dayyouwant=$linen; } foreach $dayyouwant (@dayyouwant) { # set up for 3 frequencies; #$2freq should equal 4; $freq=4; chomp($day); $day=$dayyouwant; $daytoprocess=$day; $datacount1=0;$datacount2=0;$datacount3=0;$datacount=0; system("date"); unlink("/home/karen/NBP/NBP0104sim.prc"); unlink("/home/karen/NBP/NBP0104sim.prc.gz"); #system("cp /mnt/rvdas/current_cruise/rvdas/uw/NBP0104sim1.d$day.gz /home/karen/NBP/NBP0104sim.prc.gz"); system("cp /rawdata/rtuw/NBP0104sim1.d$day /home/karen/NBP/NBP0104sim.prc"); #system("gunzip /home/karen/NBP/NBP0104sim.prc.gz"); open (SIMREAD, "/home/karen/NBP/NBP0104sim.prc") or die "can't in\n"; open (SIMOUT1, ">SIMf".$day."out1.dat") or die "can't out1\n"; open (SIMOUT2, ">SIMf".$day."out2.dat") or die "can't out2\n"; open (SIMOUT3, ">SIMf".$day."out3.dat") or die "can't out3\n"; open (SIMTIME1, ">SIMf".$day."time1.dat") or die "can't out11\n"; open (SIMTIME2, ">SIMf".$day."time2.dat") or die "can't out22\n"; open (SIMTIME3, ">SIMf".$day."time3.dat") or die "can't out33\n"; #} # Set up start markers to avoid leading returns $startmark1=0; $startmark2=0; $startmark3=0; $timesthrough=0; $recordcount1=0; $recordcount2=0; $recordcount3=0; # Main loop through the entire rvdas generated file while($line = ){ $timesthrough++; chomp($line); $a=0; $b=0; $c=0; $d=0; $e=0; $f=0; $g=0; $h=0; $i=0; $j=0; $k=0; # Determine the frequency, which determines which file to put data into if ($line =~ /Q1/){ $freq=1; if ($startmark1>0){ $stopthis=25-$recordcount1; for ($m=1;$m<=$stopthis;$m++){ print SIMOUT1 "0 0 0 0 0 0 0 0 0 0 "; } print SIMOUT1 "\n"; } $startmark1=1; ( $time, $o)=split /\s+/, $line; ($year, $rtime)=split /\+/, $time; ($day, $hour, $min, $sec)=split /:/, $rtime; $min ||= $knot; # If $b false, replace with $knot; $day ||= $knot; # If $b false, replace with $knot; $hour ||= $knot; # If $b false, replace with $knot; $daytime= $day+($hour/24+($min/(24*60))+($sec/(24*60*60))); print SIMTIME1 $daytime, " ", $hour," ", $min, "\n"; $recordcount1=0; $datacount=0; } elsif ($line =~ /Q2/){ $freq=2; if ($startmark2>0){ $stopthis=25-$recordcount2; for ($m=1;$m<=$stopthis;$m++){ print SIMOUT2 "0 0 0 0 0 0 0 0 0 0 "; } print SIMOUT2 "\n"; } $startmark2=1; ( $time, $o)=split /\s+/, $line; ($year, $rtime)=split /\+/, $time; ($day, $hour, $min, $sec)=split /:/, $rtime; $min ||= $knot; # If $b false, replace with $knot; $day ||= $knot; # If $b false, replace with $knot; $hour ||= $knot; # If $b false, replace with $knot; $daytime= $day+($hour/24+($min/(24*60))+($sec/(24*60*60))); print SIMTIME2 $daytime," ", $hour," ", $min, "\n"; $recordcount2=0; $datacount=0; } elsif ($line =~ /Q3/){ $freq=3; if ($startmark3>0){ $stopthis=25-$recordcount3; for ($m=1;$m<=$stopthis;$m++){ print SIMOUT3 "0 0 0 0 0 0 0 0 0 0 "; } print SIMOUT3 "\n"; } $startmark3=1; ( $time, $o)=split /\s+/, $line; ($year, $rtime)=split /\+/, $time; ($day, $hour, $min, $sec)=split /:/, $rtime; $min ||= $knot; # If $b false, replace with $knot; $day ||= $knot; # If $b false, replace with $knot; $hour ||= $knot; # If $b false, replace with $knot; $daytime= $day+($hour/24+($min/(24*60))+($sec/(24*60*60))); print SIMTIME3 $daytime, " ", $hour," ", $min, "\n"; $recordcount3=0; $datacount=0; } else { if ($datacount <=240){ unless ($line =~ /[D%*]/) { ## WARNING EXCLUDES LONELY -'s and changes undef, "", 0 vals to -999 ...## # try to find dashes ####### $line =~ s/[\d \b \,]\-[\b \, \- \s \e]/$knot/; $line =~ s/\-\D|\-\Z/$knot/; # \a alarm \n newline \r carriage ret. \t tab \f form feed \e escape \d digit # \D nondigit \w word boundary \W non-word bound. \s white space (\t\n\r\f) # \S not white space * either 0 or 1 times... \Z at end of string ;) ##############SPLIT AND TEST AREA ####################### ##### unless defined($k) $k=$knot; ####### $b =~ s/undef/2/g; ####### unless defined($b=$knot); ####### unless($b) $b=0; ##########@SIMLINE= split /,/, $line; ##########$simrec=$#SIMLINE; # get last index in the line ( $b, $c, $d, $e, $f, $g, $h, $i, $j, $k)=split /,/, $line; $b ||= $knot; # If $b false, replace with $knot; $c ||= $knot; $d ||= $knot; $e ||= $knot; $f ||= $knot; $g ||= $knot; $h ||= $knot; $i ||= $knot; $j ||= $knot; $k ||= $knot; #############################START PRINTING FREQ DATA HERE ############### ########### Q1 RECORD STUFF #################### if ($freq<2) { $recordcount1++; print SIMOUT1 $b,' ', $c,' ', $d,' ', $e,' ', $f,' ', $g,' ', $h,' ', $i,' ', $j,' ', $k,' '; $datacount+=10; } ########### Q2 RECORD STUFF #################### elsif($freq<3 && $freq >1) { $recordcount2++; print SIMOUT2 $b,' ', $c,' ', $d,' ', $e,' ', $f,' ', $g,' ', $h,' ', $i,' ', $j,' ', $k,' '; $datacount+=10; } ########### Q3 RECORD STUFF #################### elsif($freq<4 && $freq >2) { $recordcount3++; print SIMOUT3 $b,' ', $c,' ', $d,' ', $e,' ', $f,' ', $g,' ', $h,' ', $i,' ', $j,' ', $k,' '; $datacount+=10; } } } } } ###################### WRITE LAST RECORD ######################## # Determine the frequency, which determines which file to put data into if($freq==1){ if ($startmark1>0){ $stopthis=25-$recordcount1; for ($m=1;$m<=$stopthis;$m++){ print SIMOUT1 "0 0 0 0 0 0 0 0 0 0 "; } print SIMOUT1 "\n"; } $startmark1=1; ( $time, $o)=split /\s+/, $line; ($year, $rtime)=split /\+/, $time; ($day, $hour, $min, $sec)=split /:/, $rtime; $min ||= $knot; # If $b false, replace with $knot; $day ||= $knot; # If $b false, replace with $knot; $hour ||= $knot; # If $b false, replace with $knot; #print $wkday, $month, $day, $time, $year, '\n'; $daytime= $day+($hour/24+($min/(24*60))+($sec/(24*60*60))); print SIMTIME1 $daytime," ", $hour," ", $min, "\n"; $recordcount1=0; } elsif ( $freq==2){ if ($startmark2>0){ $stopthis=25-$recordcount2; for ($m=1;$m<=$stopthis;$m++){ print SIMOUT2 "0 0 0 0 0 0 0 0 0 0 "; } print SIMOUT2 "\n"; } $startmark2=1; ( $time, $o)=split /\s+/, $line; ($year, $rtime)=split /\+/, $time; ($day, $hour, $min, $sec)=split /:/, $rtime; $min ||= $knot; # If $b false, replace with $knot; $day ||= $knot; # If $b false, replace with $knot; $hour ||= $knot; # If $b false, replace with $knot; #print $wkday, $month, $day, $time, $year, '\n'; $daytime= $day+($hour/24+($min/(24*60))+($sec/(24*60*60))); print SIMTIME2 $daytime, " ",$hour," ", $min, "\n"; $recordcount2=0; } elsif ($freq==3){ if ($startmark3>0){ $stopthis=25-$recordcount3; for ($m=1;$m<=$stopthis;$m++){ print SIMOUT3 "0 0 0 0 0 0 0 0 0 0 "; } print SIMOUT3 "\n"; } $startmark3=1; ( $time, $o)=split /\s+/, $line; ($year, $rtime)=split /\+/, $time; ($day, $hour, $min, $sec)=split /:/, $rtime; $min ||= $knot; # If $b false, replace with $knot; $day ||= $knot; # If $b false, replace with $knot; $hour ||= $knot; # If $b false, replace with $knot; #print $wkday, $month, $day, $time, $year, '\n'; $daytime= $day+($hour/24+($min/(24*60))+($sec/(24*60*60))); print SIMTIME3 $daytime, " ",$hour," ", $min, "\n"; $recordcount3=0; } system("date"); } #system("gzip /home/karen/NBP/SIMf21*"); #system("mv /home/karen/NBP/SIMf21* /home/karen/NBP/SIMfteens");