mkProfile
changeset 61 69192495f0db
parent 58 78607e2e8add
equal deleted inserted replaced
60:890e267a2d98 61:69192495f0db
     1 #!/usr/bin/perl
     1 #!/usr/bin/perl
     2 #======================================================================
     2 #======================================================================
     3 #                    M K P R O F I L E 
     3 #                    M K P R O F I L E 
     4 #                    doc: Sun Jan 19 18:55:26 2003
     4 #                    doc: Sun Jan 19 18:55:26 2003
     5 #                    dlm: Sat Apr 10 05:51:48 2021
     5 #                    dlm: Mon Oct 18 11:02:31 2021
     6 #                    (c) 2003 A.M. Thurnherr
     6 #                    (c) 2003 A.M. Thurnherr
     7 #                    uE-Info: 99 35 NIL 0 0 72 0 2 4 NIL ofnI
     7 #                    uE-Info: 101 76 NIL 0 0 72 0 2 4 NIL ofnI
     8 #======================================================================
     8 #======================================================================
     9 
     9 
    10 # Make an LADCP Profile by Integrating W (similar to Firing's scan*).
    10 # Make an LADCP Profile by Integrating W (similar to Firing's scan*).
    11 
    11 
    12 # HISTORY:
    12 # HISTORY:
    95 #	Oct 13, 2017: - added instrument orientation
    95 #	Oct 13, 2017: - added instrument orientation
    96 #	Apr  2, 2018: - BUG: velBeamToInstrument() used old usage
    96 #	Apr  2, 2018: - BUG: velBeamToInstrument() used old usage
    97 #	Apr 24, 2018: - BUG: bin1 was used even with zero blanking
    97 #	Apr 24, 2018: - BUG: bin1 was used even with zero blanking
    98 #	Apr 18, 2019: - added coord-transformation %PARAMs
    98 #	Apr 18, 2019: - added coord-transformation %PARAMs
    99 #	Apr 10, 2021: - adapted to V2.4
    99 #	Apr 10, 2021: - adapted to V2.4
       
   100 #	Oct 12, 2021: - added speed to output on -M
       
   101 #	Oct 18, 2021: - BUG: speed bombed with zero valid velocities in ensemble
   100 # HISTORY END
   102 # HISTORY END
   101 
   103 
   102 # NOTES:
   104 # NOTES:
   103 #	- the battery values are based on transmission voltages (different
   105 #	- the battery values are based on transmission voltages (different
   104 #	  from battery voltages) and reported without units (raw 8-bit a2d
   106 #	  from battery voltages) and reported without units (raw 8-bit a2d
   367 
   369 
   368 	if ($n >= 2) {
   370 	if ($n >= 2) {
   369 		my(@sumsq) = (0,0);
   371 		my(@sumsq) = (0,0);
   370 		$dta{ENSEMBLE}[$ens]->{U} /= $n;
   372 		$dta{ENSEMBLE}[$ens]->{U} /= $n;
   371 		$dta{ENSEMBLE}[$ens]->{V} /= $n;
   373 		$dta{ENSEMBLE}[$ens]->{V} /= $n;
       
   374 		$dta{ENSEMBLE}[$ens]->{SPEED} = sqrt($dta{ENSEMBLE}[$ens]->{U}**2 +
       
   375 											 $dta{ENSEMBLE}[$ens]->{V}**2);
   372 		for ($i=0; $i<$n; $i++) {
   376 		for ($i=0; $i<$n; $i++) {
   373 			$sumsq[0] += ($dta{ENSEMBLE}[$ens]->{U}-$goodU[$i])**2;
   377 			$sumsq[0] += ($dta{ENSEMBLE}[$ens]->{U}-$goodU[$i])**2;
   374 			$sumsq[1] += ($dta{ENSEMBLE}[$ens]->{V}-$goodV[$i])**2;
   378 			$sumsq[1] += ($dta{ENSEMBLE}[$ens]->{V}-$goodV[$i])**2;
   375 		}
   379 		}
   376 		$dta{ENSEMBLE}[$ens]->{U_ERR} = sqrt($sumsq[0])/($n-1);
   380 		$dta{ENSEMBLE}[$ens]->{U_ERR} = sqrt($sumsq[0])/($n-1);
   380 		$dta{ENSEMBLE}[$ens]->{V} = undef;
   384 		$dta{ENSEMBLE}[$ens]->{V} = undef;
   381     }    	
   385     }    	
   382 }
   386 }
   383 
   387 
   384 #----------------------------------------------------------------------
   388 #----------------------------------------------------------------------
   385 
   389 # Create Progressive Vector Diagram
   386 ($x,$y) = (0,0);											# init
   390 #----------------------------------------------------------------------
       
   391 
       
   392 ($x,$y,$cAvg,$ngood) = (0,0,0,0);										# init
   387 
   393 
   388 $dta{ENSEMBLE}[$firstgood]->{X} = $dta{ENSEMBLE}[$firstgood]->{X_ERR} = 0;
   394 $dta{ENSEMBLE}[$firstgood]->{X} = $dta{ENSEMBLE}[$firstgood]->{X_ERR} = 0;
   389 $dta{ENSEMBLE}[$firstgood]->{Y} = $dta{ENSEMBLE}[$firstgood]->{Y_ERR} = 0;
   395 $dta{ENSEMBLE}[$firstgood]->{Y} = $dta{ENSEMBLE}[$firstgood]->{Y_ERR} = 0;
   390 $prevgood = $firstgood;
   396 $prevgood = $firstgood;
   391 
   397 
   409 
   415 
   410 	#-----------------------------------
   416 	#-----------------------------------
   411 	# The current ensemble has valid u/v
   417 	# The current ensemble has valid u/v
   412 	#-----------------------------------
   418 	#-----------------------------------
   413 
   419 
       
   420 	$cAvg += $dta{ENSEMBLE}[$e]->{SPEED}; $ngood++;
       
   421 
   414 	$x -= $dta{ENSEMBLE}[$prevgood]->{U} * $dt;			# integrate
   422 	$x -= $dta{ENSEMBLE}[$prevgood]->{U} * $dt;			# integrate
   415 	$xErr += ($dta{ENSEMBLE}[$prevgood]->{U_ERR} * $dt)**2;
   423 	$xErr += ($dta{ENSEMBLE}[$prevgood]->{U_ERR} * $dt)**2;
   416 	$dta{ENSEMBLE}[$e]->{X} = $x;
   424 	$dta{ENSEMBLE}[$e]->{X} = $x;
   417 	$dta{ENSEMBLE}[$e]->{X_ERR} = sqrt($xErr);
   425 	$dta{ENSEMBLE}[$e]->{X_ERR} = sqrt($xErr);
   418 
   426 
   439 	$dta{ENSEMBLE}[$lastgood]->{Y_ERR} = sqrt($yErr);
   447 	$dta{ENSEMBLE}[$lastgood]->{Y_ERR} = sqrt($yErr);
   440 }
   448 }
   441 
   449 
   442 $firstgood++ if ($firstgood == 0);							# centered diff
   450 $firstgood++ if ($firstgood == 0);							# centered diff
   443 $lastgood-- if ($lastgood == $#{$dta{ENSEMBLE}});			# in step 6
   451 $lastgood-- if ($lastgood == $#{$dta{ENSEMBLE}});			# in step 6
       
   452 
       
   453 $cAvg = $ngood ? ($cAvg / $ngood) : nan;
   444 
   454 
   445 #======================================================================
   455 #======================================================================
   446 # Step 3: Calculate Uncertainties
   456 # Step 3: Calculate Uncertainties
   447 #======================================================================
   457 #======================================================================
   448 
   458 
   716 
   726 
   717 print("#!/usr/bin/perl -S list\n");		
   727 print("#!/usr/bin/perl -S list\n");		
   718 chmod(0777&~umask,*STDOUT);
   728 chmod(0777&~umask,*STDOUT);
   719 
   729 
   720 print("#ANTS# [] $USAGE\n");
   730 print("#ANTS# [] $USAGE\n");
   721 $uFields = "{u} {u_err} {v} {v_err} {x} {x_err} {y} {y_err}"
   731 $uFields = "{u} {u_err} {v} {v_err} {x} {x_err} {y} {y_err} {speed}"
   722 	if defined($opt_M);
   732 	if defined($opt_M);
   723 print("#ANTS#FIELDS# {ens} {time} {elapsed} {secno} {downcast} " .
   733 print("#ANTS#FIELDS# {ens} {time} {elapsed} {secno} {downcast} " .
   724 					"{w} {w_err} {err_vel} {depth} {depth_err} {seabed} " .
   734 					"{w} {w_err} {err_vel} {depth} {depth_err} {seabed} " .
   725 					"{pitch} {roll} {tilt} {hdg} {rotation} " .
   735 					"{pitch} {roll} {tilt} {hdg} {rotation} " .
   726 					"$uFields $addFields\n");
   736 					"$uFields $addFields\n");
   773 			$dta{DISTANCE_TO_BIN1_CENTER},
   783 			$dta{DISTANCE_TO_BIN1_CENTER},
   774 			$dta{BIN_LENGTH},
   784 			$dta{BIN_LENGTH},
   775 	  );
   785 	  );
   776 printf("#ANTS#PARAMS# magnetic_declination{$opt_M} " .
   786 printf("#ANTS#PARAMS# magnetic_declination{$opt_M} " .
   777 							  "uv_gap_time{%d} " .
   787 							  "uv_gap_time{%d} " .
   778 								   "mean_u{%.4f} " .
   788 								   "u.mean{%.4f} " .
   779 								 "stderr_u{%.4f} " .
   789 								 "u.sterrr{%.4f} " .
   780 									   "dx{%d} " .
   790 									   "dx{%d} " .
   781 								   "dx_err{%d} " .
   791 								   "dx.err{%d} " .
   782 								   "mean_v{%.4f} " .
   792 								   "v.mean{%.4f} " .
   783 								 "stderr_v{%.4f} " .
   793 								 "v.stderr{%.4f} " .
   784 									   "dy{%d} " .
   794 									   "dy{%d} " .
   785 								   "dy_err{%d}\n",
   795 								   "dy.err{%d} " .
       
   796 							   "speed.mean{%.2f}\n",
   786 	$uv_gap_time,
   797 	$uv_gap_time,
   787 	$dta{ENSEMBLE}[$lastgood]->{X} /
   798 	$dta{ENSEMBLE}[$lastgood]->{X} /
   788 		$dta{ENSEMBLE}[$lastgood]->{ELAPSED_TIME},
   799 		$dta{ENSEMBLE}[$lastgood]->{ELAPSED_TIME},
   789 	$uErr, $dta{ENSEMBLE}[$lastgood]->{X}, $x_err,
   800 	$uErr, $dta{ENSEMBLE}[$lastgood]->{X}, $x_err,
   790 	$dta{ENSEMBLE}[$lastgood]->{Y} /
   801 	$dta{ENSEMBLE}[$lastgood]->{Y} /
   791 		$dta{ENSEMBLE}[$lastgood]->{ELAPSED_TIME},
   802 		$dta{ENSEMBLE}[$lastgood]->{ELAPSED_TIME},
   792 	$vErr, $dta{ENSEMBLE}[$lastgood]->{Y}, $y_err,
   803 	$vErr, $dta{ENSEMBLE}[$lastgood]->{Y}, $y_err,
       
   804 	$cAvg
   793 ) if defined ($opt_M);
   805 ) if defined ($opt_M);
   794 if ($dta{TIME_BETWEEN_PINGS} == 0) {
   806 if ($dta{TIME_BETWEEN_PINGS} == 0) {
   795 	 print("#ANTS#PARAMS# pinging_rate{staggered}\n");
   807 	 print("#ANTS#PARAMS# pinging_rate{staggered}\n");
   796 } else {
   808 } else {
   797 	 printf("#ANTS#PARAMS# pinging_rate{%.2f}\n",
   809 	 printf("#ANTS#PARAMS# pinging_rate{%.2f}\n",
   827 	if (defined($opt_M)) {
   839 	if (defined($opt_M)) {
   828 		p($dta{ENSEMBLE}[$e]->{U}); p($dta{ENSEMBLE}[$e]->{U_ERR});
   840 		p($dta{ENSEMBLE}[$e]->{U}); p($dta{ENSEMBLE}[$e]->{U_ERR});
   829 		p($dta{ENSEMBLE}[$e]->{V}); p($dta{ENSEMBLE}[$e]->{V_ERR});
   841 		p($dta{ENSEMBLE}[$e]->{V}); p($dta{ENSEMBLE}[$e]->{V_ERR});
   830 		p($dta{ENSEMBLE}[$e]->{X}); p($dta{ENSEMBLE}[$e]->{X_ERR});
   842 		p($dta{ENSEMBLE}[$e]->{X}); p($dta{ENSEMBLE}[$e]->{X_ERR});
   831 		p($dta{ENSEMBLE}[$e]->{Y}); p($dta{ENSEMBLE}[$e]->{Y_ERR});
   843 		p($dta{ENSEMBLE}[$e]->{Y}); p($dta{ENSEMBLE}[$e]->{Y_ERR});
       
   844 		p($dta{ENSEMBLE}[$e]->{SPEED});
   832 	}
   845 	}
   833 	if (@f) {
   846 	if (@f) {
   834 		foreach $f (@f) {
   847 		foreach $f (@f) {
   835 			my($fn,$fi) = ($f =~ m{([^[]*)(\[.*)});
   848 			my($fn,$fi) = ($f =~ m{([^[]*)(\[.*)});
   836 			$fn = $f unless defined($fn);
   849 			$fn = $f unless defined($fn);