mkProfile
changeset 18 bb7bb9f83db9
parent 14 8c79b38a7086
child 21 0b5bbe60131c
equal deleted inserted replaced
17:591779f6df30 18:bb7bb9f83db9
     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: Thu Feb 13 15:45:20 2014
     5 #                    dlm: Sat May 24 22:50:02 2014
     6 #                    (c) 2003 A.M. Thurnherr
     6 #                    (c) 2003 A.M. Thurnherr
     7 #                    uE-Info: 283 0 NIL 0 0 72 2 2 4 NIL ofnI
     7 #                    uE-Info: 797 76 NIL 0 0 72 10 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:
    83 #	May 14, 2013: - added heading to output
    83 #	May 14, 2013: - added heading to output
    84 #				  - added err_vel to output
    84 #				  - added err_vel to output
    85 #				  - finally removed -d/-g
    85 #				  - finally removed -d/-g
    86 #	Nov 25, 2013: - expunged checkEnsemble
    86 #	Nov 25, 2013: - expunged checkEnsemble
    87 #	Feb 13, 2014: - added support set_range_lim()
    87 #	Feb 13, 2014: - added support set_range_lim()
       
    88 #	Mar  4, 2014: - added support to allow missing PITCH/ROLL/HEADING values
       
    89 #	May 24, 2014: - finally added (gimbal-)pitch & roll to default output
       
    90 #				  - renamed heading to hdg and pitchroll to tilt
    88 
    91 
    89 # NOTES:
    92 # NOTES:
    90 #	- the battery values are based on transmission voltages (different
    93 #	- the battery values are based on transmission voltages (different
    91 #	  from battery voltages) and reported without units (raw 8-bit a2d
    94 #	  from battery voltages) and reported without units (raw 8-bit a2d
    92 #	  values)
    95 #	  values)
   562 
   565 
   563 #======================================================================
   566 #======================================================================
   564 # Step 6: Pitch, Roll, Rotation
   567 # Step 6: Pitch, Roll, Rotation
   565 #======================================================================
   568 #======================================================================
   566 
   569 
       
   570 # in case of PITCH/ROLL/HEADING data gaps (IMP data), the calculations
       
   571 # are not entirely correct, as
       
   572 # 	i)  the rotation implied by the pre-/post-gap headings is not counted
       
   573 #	ii) the gappy ensembles are counted for calculating the rms vals
       
   574 
   567 my($prrms,$dnprrms,$upprrms) = (0,0,0);
   575 my($prrms,$dnprrms,$upprrms) = (0,0,0);
   568 my($rotrms,$prerot,$dnrot,$uprot,$postrot) = (0,0,0,0,0);
   576 my($rotrms,$prerot,$dnrot,$uprot,$postrot) = (0,0,0,0,0);
   569 
   577 
   570 sub rot($)
   578 sub rot($)
   571 {
   579 {
   572 	my($e) = @_;
   580 	my($e) = @_;
       
   581 	return 0
       
   582 		unless defined($dta{ENSEMBLE}[$e]->{HEADING}) && defined($dta{ENSEMBLE}[$e-1]->{HEADING});
   573 	my($rot) = $dta{ENSEMBLE}[$e]->{HEADING} -
   583 	my($rot) = $dta{ENSEMBLE}[$e]->{HEADING} -
   574 			   $dta{ENSEMBLE}[$e-1]->{HEADING};
   584 			   $dta{ENSEMBLE}[$e-1]->{HEADING};
   575 	$rot -= 360 if ($rot >  180);
   585 	$rot -= 360 if ($rot >  180);
   576 	$rot += 360 if ($rot < -180);
   586 	$rot += 360 if ($rot < -180);
   577 	return $rot;
   587 	return $rot;
   580 for ($e=1; $e<$firstgood; $e++) {				# pre-deployment
   590 for ($e=1; $e<$firstgood; $e++) {				# pre-deployment
   581 	$prerot += rot($e);
   591 	$prerot += rot($e);
   582 }
   592 }
   583 
   593 
   584 for (; $e<= $atbottom; $e++) {					# downcast
   594 for (; $e<= $atbottom; $e++) {					# downcast
   585 	$dta{ENSEMBLE}[$e]->{PITCHROLL} =
   595 	$dta{ENSEMBLE}[$e]->{TILT} =
   586 		&angle_from_vertical($dta{ENSEMBLE}[$e]->{PITCH},
   596 		&angle_from_vertical($dta{ENSEMBLE}[$e]->{PITCH},
   587 						  	 $dta{ENSEMBLE}[$e]->{ROLL});
   597 						  	 $dta{ENSEMBLE}[$e]->{ROLL});
   588 	$prrms += $dta{ENSEMBLE}[$e]->{PITCHROLL}**2;
   598 	$prrms += $dta{ENSEMBLE}[$e]->{TILT}**2
       
   599 		if numberp($dta{ENSEMBLE}[$e]->{TILT});
   589 				 
   600 				 
   590 	$dta{ENSEMBLE}[$e]->{ROTATION} = rot($e);
   601 	$dta{ENSEMBLE}[$e]->{ROTATION} = rot($e);
   591 	$dnrot += $dta{ENSEMBLE}[$e]->{ROTATION};
   602 	$dnrot += $dta{ENSEMBLE}[$e]->{ROTATION};
   592 	$rotrms += $dta{ENSEMBLE}[$e]->{ROTATION}**2;
   603 	$rotrms += $dta{ENSEMBLE}[$e]->{ROTATION}**2;
   593 }
   604 }
   594 $dnprrms = $prrms;
   605 $dnprrms = $prrms;
   595 
   606 
   596 for (; $e<=$lastgood; $e++) {					# upcast
   607 for (; $e<=$lastgood; $e++) {					# upcast
   597 	$dta{ENSEMBLE}[$e]->{PITCHROLL} =
   608 	$dta{ENSEMBLE}[$e]->{TILT} =
   598 		&angle_from_vertical($dta{ENSEMBLE}[$e]->{PITCH},
   609 		&angle_from_vertical($dta{ENSEMBLE}[$e]->{PITCH},
   599 						  	 $dta{ENSEMBLE}[$e]->{ROLL});
   610 						  	 $dta{ENSEMBLE}[$e]->{ROLL});
   600 	$prrms += $dta{ENSEMBLE}[$e]->{PITCHROLL}**2;
   611 	$prrms += $dta{ENSEMBLE}[$e]->{TILT}**2
       
   612 		if numberp($dta{ENSEMBLE}[$e]->{TILT});
   601 				 
   613 				 
   602 	$dta{ENSEMBLE}[$e]->{ROTATION} = rot($e);
   614 	$dta{ENSEMBLE}[$e]->{ROTATION} = rot($e);
   603 	$uprot += $dta{ENSEMBLE}[$e]->{ROTATION};
   615 	$uprot += $dta{ENSEMBLE}[$e]->{ROTATION};
   604 	$rotrms += $dta{ENSEMBLE}[$e]->{ROTATION}**2;
   616 	$rotrms += $dta{ENSEMBLE}[$e]->{ROTATION}**2;
   605 }
   617 }
   687 print("#ANTS# [] $USAGE\n");
   699 print("#ANTS# [] $USAGE\n");
   688 $uFields = "{u} {u_err} {v} {v_err} {x} {x_err} {y} {y_err}"
   700 $uFields = "{u} {u_err} {v} {v_err} {x} {x_err} {y} {y_err}"
   689 	if defined($opt_M);
   701 	if defined($opt_M);
   690 print("#ANTS#FIELDS# {ens} {time} {elapsed} {secno} {downcast} " .
   702 print("#ANTS#FIELDS# {ens} {time} {elapsed} {secno} {downcast} " .
   691 					"{w} {w_err} {err_vel} {depth} {depth_err} {seabed} " .
   703 					"{w} {w_err} {err_vel} {depth} {depth_err} {seabed} " .
   692 					"{pitchroll} {heading} {rotation} " .
   704 					"{pitch} {roll} {tilt} {hdg} {rotation} " .
   693 					"$uFields $addFields\n");
   705 					"$uFields $addFields\n");
   694 
   706 
   695 printf("#ANTS#PARAMS# date{$dta{ENSEMBLE}[$firstgood]->{DATE}} " .
   707 printf("#ANTS#PARAMS# date{$dta{ENSEMBLE}[$firstgood]->{DATE}} " .
   696 			   "start_time{$dta{ENSEMBLE}[$firstgood]->{TIME}} " .
   708 			   "start_time{$dta{ENSEMBLE}[$firstgood]->{TIME}} " .
   697 			  "bottom_time{$dta{ENSEMBLE}[$atbottom]->{TIME}} " .
   709 			  "bottom_time{$dta{ENSEMBLE}[$atbottom]->{TIME}} " .
   702 			"cast_duration{%.1f} " .
   714 			"cast_duration{%.1f} " .
   703 		   "0.8_valid_bins{%.1f} " .
   715 		   "0.8_valid_bins{%.1f} " .
   704 		  "0.8_valid_range{%.1f} " .
   716 		  "0.8_valid_range{%.1f} " .
   705 				"max_depth{%.1f} " .
   717 				"max_depth{%.1f} " .
   706 			  "depth_error{%.1f} " .
   718 			  "depth_error{%.1f} " .
   707 				"min_range{%d} " .
   719 				  "min_range{%d} " .
   708 			  "n_ensembles{%d} " .
   720 				"n_ensembles{%d} " .
   709 			   "w_gap_time{%d} " .
   721                  "w_gap_time{%d} " .
   710 				 "stderr_w{%.4f} " .
   722 				 "stderr_w{%.4f} " .
   711 			"rms_pitchroll{%.1f} " .
   723 				 "rms_tilt{%.1f} " .
   712    "downcast_rms_pitchroll{%.1f} " .
   724 		"downcast_rms_tilt{%.1f} " .
   713 	 "upcast_rms_pitchroll{%.1f} " .
   725           "upcast_rms_tilt{%.1f} " .
   714 			 "rms_rotation{%.2f} " .
   726 			 "rms_rotation{%.2f} " .
   715 	 "deployment_rotations{%d} " .
   727 	   "deployment_rotations{%d} " .
   716 	   "downcast_rotations{%d} " .
   728 		 "downcast_rotations{%d} " .
   717 		 "upcast_rotations{%d} " .
   729 		   "upcast_rotations{%d} " .
   718 	   "recovery_rotations{%d} " .
   730          "recovery_rotations{%d} " .
   719    "rms_heave_acceleration{%.2f} " .
   731    "rms_heave_acceleration{%.2f} " .
   720 				"bin1_dist{%.1f} " .
   732 				"bin1_dist{%.1f} " .
   721 			   "bin_length{%.1f} " .
   733 			   "bin_length{%.1f} " .
   722 					 "\n",
   734 					 "\n",
   723 			($dta{ENSEMBLE}[$#{$dta{ENSEMBLE}}]->{UNIX_TIME} -
   735 			($dta{ENSEMBLE}[$#{$dta{ENSEMBLE}}]->{UNIX_TIME} -
   780 	p($dta{ENSEMBLE}[$e]->{W_ERR});
   792 	p($dta{ENSEMBLE}[$e]->{W_ERR});
   781 	p($dta{ENSEMBLE}[$e]->{ERR_VEL});
   793 	p($dta{ENSEMBLE}[$e]->{ERR_VEL});
   782 	p($dta{ENSEMBLE}[$e]->{DEPTH});
   794 	p($dta{ENSEMBLE}[$e]->{DEPTH});
   783 	p($dta{ENSEMBLE}[$e]->{DEPTH_ERR});
   795 	p($dta{ENSEMBLE}[$e]->{DEPTH_ERR});
   784 	p($dta{ENSEMBLE}[$e]->{seabed});
   796 	p($dta{ENSEMBLE}[$e]->{seabed});
   785 	p($dta{ENSEMBLE}[$e]->{PITCHROLL});
   797 	p(&gimbal_pitch($dta{ENSEMBLE}[$e]->{PITCH},$dta{ENSEMBLE}[$e]->{ROLL}));
       
   798 	p($dta{ENSEMBLE}[$e]->{ROLL});
       
   799 	p($dta{ENSEMBLE}[$e]->{TILT});
   786 	p($dta{ENSEMBLE}[$e]->{HEADING});
   800 	p($dta{ENSEMBLE}[$e]->{HEADING});
   787 	p($dta{ENSEMBLE}[$e]->{ROTATION});
   801 	p($dta{ENSEMBLE}[$e]->{ROTATION});
   788 	if (defined($opt_M)) {
   802 	if (defined($opt_M)) {
   789 		p($dta{ENSEMBLE}[$e]->{U}); p($dta{ENSEMBLE}[$e]->{U_ERR});
   803 		p($dta{ENSEMBLE}[$e]->{U}); p($dta{ENSEMBLE}[$e]->{U_ERR});
   790 		p($dta{ENSEMBLE}[$e]->{V}); p($dta{ENSEMBLE}[$e]->{V_ERR});
   804 		p($dta{ENSEMBLE}[$e]->{V}); p($dta{ENSEMBLE}[$e]->{V_ERR});