editPD0
changeset 36 515b06dae59c
parent 34 3b4bcd55e1ea
child 37 40d85448debf
equal deleted inserted replaced
35:7c394a2d1fc9 36:515b06dae59c
     1 #!/usr/bin/perl
     1 #!/usr/bin/perl
     2 #======================================================================
     2 #======================================================================
     3 #                    E D I T P D 0 
     3 #                    E D I T P D 0 
     4 #                    doc: Mon Nov 25 20:24:31 2013
     4 #                    doc: Mon Nov 25 20:24:31 2013
     5 #                    dlm: Tue Apr 12 21:45:31 2016
     5 #                    dlm: Tue Jul 12 18:56:55 2016
     6 #                    (c) 2013 A.M. Thurnherr
     6 #                    (c) 2013 A.M. Thurnherr
     7 #                    uE-Info: 235 46 NIL 0 0 72 2 2 4 NIL ofnI
     7 #                    uE-Info: 118 0 NIL 0 0 72 2 2 4 NIL ofnI
     8 #======================================================================
     8 #======================================================================
     9 
     9 
    10 # edit RDI PD0 file, e.g. to replace pitch/roll/heading with external values
    10 # edit RDI PD0 file, e.g. to replace pitch/roll/heading with external values
    11 
    11 
    12 # NOTES:
    12 # NOTES:
    19 #		p(<pitch>)				set pitch value (RDI not gimbal pitch) of current ensemble
    19 #		p(<pitch>)				set pitch value (RDI not gimbal pitch) of current ensemble
    20 #		r(<roll>)				set roll alue value of current ensemble
    20 #		r(<roll>)				set roll alue value of current ensemble
    21 #		h(<heading>)			set heading alue value of current ensemble
    21 #		h(<heading>)			set heading alue value of current ensemble
    22 #
    22 #
    23 #		swap_beams(<b1>,<b2>)	swap data from beams b1 and b2
    23 #		swap_beams(<b1>,<b2>)	swap data from beams b1 and b2
    24 #								input in beam coords required
    24 #									- input in beam coords required
    25 #								beam rotation is equivalent to 3 consecutive beam swaps
    25 #									- beam rotation is equivalent to 3 consecutive beam swaps
    26 #								basic BT data are swapped as well (not RL and not SIGNAL_STRENGTH)
    26 #									- basic BT data are swapped as well (not RL and not SIGNAL_STRENGTH)
    27 #
    27 #
    28 #		earth2beam()			transform beam to earth coordinates
    28 #		earth2beam()			transform beam to earth coordinates
    29 #								does not handle bin-remapping
    29 #									- does not handle bin-remapping
    30 #								input in beam coords required
    30 #									- input in earth coords required
       
    31 #
       
    32 #		beam2earth()			transform earth to beam coordinates
       
    33 #									- does not handle bin-remapping
       
    34 #									- input in beam coords required
    31 #
    35 #
    32 #		instrument2beam()		transform instrument to earth coordinates
    36 #		instrument2beam()		transform instrument to earth coordinates
    33 #								does not handle bin-remapping
    37 #									- does not handle bin-remapping
    34 #								input in instrument coords required
    38 #									- input in instrument coords required
    35 #
    39 #
    36 #		ensure_UL()				overwrite transducer-orientation flag in data file
    40 #		ensure_UL()				correct data for wrong transducer orientation
    37 #		ensure_DL()
    41 #		ensure_DL()					- sets correct flag & negates roll value
    38 #
    42 #
    39 #	- -x notes:
    43 #	- -x notes:
    40 #		- multiple perl expressions can be combined with ,
    44 #		- multiple perl expressions can be combined with ,
    41 #
    45 #
    42 #	- Edit File Syntax:
    46 #	- Edit File Syntax:
    58 #	Feb 15, 2016: - added ensure_UL() ensure_DL()
    62 #	Feb 15, 2016: - added ensure_UL() ensure_DL()
    59 #	Feb 23, 2016: - added -k
    63 #	Feb 23, 2016: - added -k
    60 #	Feb 26, 2016: - added basic BT data to swap_beams()
    64 #	Feb 26, 2016: - added basic BT data to swap_beams()
    61 #				  - added earth2beam()
    65 #				  - added earth2beam()
    62 #	Apr 12, 2016: - added instrument2beam()
    66 #	Apr 12, 2016: - added instrument2beam()
       
    67 #	Jun  3, 2016: - added beam2earth()
       
    68 #				  - BUG: instrument2earth() set wrong flag
       
    69 #	Jun  8, 2016: - adapted to new interface of velInstrumentToBeam()
       
    70 #				  - added %-good to beam2earth and earth2beam
       
    71 #				  - made single-ping ensemble requirement for most routines
       
    72 #	Jul 12, 2016: - updated ensure_{DL,UL} routines
    63 
    73 
    64 use Getopt::Std;
    74 use Getopt::Std;
    65 
    75 
    66 ($ADCP_TOOLS) = ($0 =~ m{(.*/)[^/]+});
    76 ($ADCP_TOOLS) = ($0 =~ m{(.*/)[^/]+});
    67 $ADCP_tools_minVersion = 1.4; 
    77 $ADCP_tools_minVersion = 1.4; 
    97 sub h($) { $dta{ENSEMBLE}[$e]->{HEADING} = $_[0]; return 1;}
   107 sub h($) { $dta{ENSEMBLE}[$e]->{HEADING} = $_[0]; return 1;}
    98 
   108 
    99 #
   109 #
   100 # override transducer orientation
   110 # override transducer orientation
   101 #
   111 #
       
   112 #	These routines are intended to correct ADCP data for
       
   113 #	erroneous orientation switch readings, primarily because
       
   114 #	of a stuck switch. While not fully debugged, negating
       
   115 #	the roll value greatly improves the vertical velocity
       
   116 #	solutions of 2007 CLIVAR I08S profile #1. (#2-#7 could
       
   117 #	also be used for testing)
       
   118 #
       
   119 
   102 sub ensure_DL()
   120 sub ensure_DL()
   103 {
   121 {
   104 	$dta{ENSEMBLE}[$e]->{XDUCER_FACING_DOWN} = 1;
   122 	if ($dta{ENSEMBLE}[$e]->{XDUCER_FACING_UP}) {
   105 	$dta{ENSEMBLE}[$e]->{XDUCER_FACING_UP} = undef;
   123 		$dta{ENSEMBLE}[$e]->{ROLL} *= -1;
       
   124 		$dta{ENSEMBLE}[$e]->{XDUCER_FACING_DOWN} = 1;
       
   125 		$dta{ENSEMBLE}[$e]->{XDUCER_FACING_UP} = undef;
       
   126 	}
   106 	return 1;
   127 	return 1;
   107 }
   128 }
       
   129 
   108 sub ensure_UL()
   130 sub ensure_UL()
   109 {
   131 {
   110 	$dta{ENSEMBLE}[$e]->{XDUCER_FACING_DOWN} = undef;
   132 	if ($dta{ENSEMBLE}[$e]->{XDUCER_FACING_DOWN}) {
   111 	$dta{ENSEMBLE}[$e]->{XDUCER_FACING_UP} = 1;
   133 		$dta{ENSEMBLE}[$e]->{ROLL} *= -1;
       
   134 		$dta{ENSEMBLE}[$e]->{XDUCER_FACING_UP} = 1;
       
   135 		$dta{ENSEMBLE}[$e]->{XDUCER_FACING_DOWN} = undef;
       
   136 	}
   112 	return 1;
   137 	return 1;
   113 }
   138 }
   114 
   139 
   115 #
   140 #
   116 # swap data from two mis-connected beams
   141 # swap data from two mis-connected beams
   122 
   147 
   123 #	print(STDERR "\n entering swap_beams($b1,$b2) for ens = $e...");
   148 #	print(STDERR "\n entering swap_beams($b1,$b2) for ens = $e...");
   124 
   149 
   125 	die("$ARGV[0]: beam-coordinate data required\n")
   150 	die("$ARGV[0]: beam-coordinate data required\n")
   126 		unless ($dta{BEAM_COORDINATES});
   151 		unless ($dta{BEAM_COORDINATES});
       
   152 	die("$ARGV[0]: single-ping ensembles required\n")
       
   153 		unless ($dta{PINGS_PER_ENSEMBLE} == 1);
   127 
   154 
   128 	if ($dta{BT_PRESENT}) {
   155 	if ($dta{BT_PRESENT}) {
   129 		$tmp = $dta{ENSEMBLE}[$e]->{BT_RANGE}[$b1-1];
   156 		$tmp = $dta{ENSEMBLE}[$e]->{BT_RANGE}[$b1-1];
   130 		$dta{ENSEMBLE}[$e]->{BT_RANGE}[$b1-1] = $dta{ENSEMBLE}[$e]->{BT_RANGE}[$b2-1];
   157 		$dta{ENSEMBLE}[$e]->{BT_RANGE}[$b1-1] = $dta{ENSEMBLE}[$e]->{BT_RANGE}[$b2-1];
   131 		$dta{ENSEMBLE}[$e]->{BT_RANGE}[$b2-1] = $tmp;
   158 		$dta{ENSEMBLE}[$e]->{BT_RANGE}[$b2-1] = $tmp;
   176 	sub earth2beam()
   203 	sub earth2beam()
   177 	{
   204 	{
   178 		unless ($checked) {
   205 		unless ($checked) {
   179 			die("$ARGV[0]: earth-coordinate data required\n")
   206 			die("$ARGV[0]: earth-coordinate data required\n")
   180 				unless ($dta{EARTH_COORDINATES});
   207 				unless ($dta{EARTH_COORDINATES});
       
   208 			die("$ARGV[0]: single-ping ensembles required\n")
       
   209 				unless ($dta{PINGS_PER_ENSEMBLE} == 1);
   181 			$dta{BEAM_COORDINATES} = 1; undef($dta{EARTH_COORDINATES});
   210 			$dta{BEAM_COORDINATES} = 1; undef($dta{EARTH_COORDINATES});
   182 			$checked = 1;
   211 			$checked = 1;
   183 		}
   212 		}
   184 	    
   213 	    
   185 		for (my($bin)=0; $bin<$dta{N_BINS}; $bin++) {
   214 		for (my($bin)=0; $bin<$dta{N_BINS}; $bin++) {
   186 			@{$dta{ENSEMBLE}[$e]->{VELOCITY}[$bin]} =
   215 			if ($dta{ENSEMBLE}[$e]->{PERCENT_GOOD}[$bin][3] == 100) {			# 4-beam solution
   187 				velEarthToBeam(\%dta,$e,@{$dta{ENSEMBLE}[$e]->{VELOCITY}[$bin]});
   216                	@{$dta{ENSEMBLE}[$e]->{VELOCITY}[$bin]} =
       
   217 					velEarthToBeam(\%dta,$e,@{$dta{ENSEMBLE}[$e]->{VELOCITY}[$bin]});
       
   218 				@{$dta{ENSEMBLE}[$e]->{PERCENT_GOOD}[$bin]} = (100,100,100,100);
       
   219 			} else {															# 3-beam solution or no solution
       
   220 				undef(@{$dta{ENSEMBLE}[$e]->{VELOCITY}[$bin]});
       
   221 				@{$dta{ENSEMBLE}[$e]->{PERCENT_GOOD}[$bin]} = (0,0,0,0);
       
   222 			}
   188 		}
   223 		}
   189 	
   224 	
   190 		return 1;
   225 		return 1;
   191 	}
   226 	}
   192 
   227 
   200 	sub instrument2beam()
   235 	sub instrument2beam()
   201 	{
   236 	{
   202 		unless ($checked) {
   237 		unless ($checked) {
   203 			die("$ARGV[0]: instrument-coordinate data required\n")
   238 			die("$ARGV[0]: instrument-coordinate data required\n")
   204 				unless ($dta{INSTRUMENT_COORDINATES});
   239 				unless ($dta{INSTRUMENT_COORDINATES});
       
   240 			die("$ARGV[0]: single-ping ensembles required\n")
       
   241 				unless ($dta{PINGS_PER_ENSEMBLE} == 1);
   205 			$dta{BEAM_COORDINATES} = 1; undef($dta{INSTRUMENT_COORDINATES});
   242 			$dta{BEAM_COORDINATES} = 1; undef($dta{INSTRUMENT_COORDINATES});
   206 			$checked = 1;
   243 			$checked = 1;
   207 		}
   244 		}
   208 	    
   245 	    
   209 		for (my($bin)=0; $bin<$dta{N_BINS}; $bin++) {
   246 		for (my($bin)=0; $bin<$dta{N_BINS}; $bin++) {
   210 			@{$dta{ENSEMBLE}[$e]->{VELOCITY}[$bin]} =
   247 			@{$dta{ENSEMBLE}[$e]->{VELOCITY}[$bin]} =
   211 				velInstrumentToBeam(\%dta,@{$dta{ENSEMBLE}[$e]->{VELOCITY}[$bin]});
   248 				velInstrumentToBeam(\%dta,$e,@{$dta{ENSEMBLE}[$e]->{VELOCITY}[$bin]});
   212 		}
   249 		}
   213 	
   250 	
   214 		return 1;
   251 		return 1;
   215 	}
   252 	}
   216 
   253 
   224 	sub instrument2earth()
   261 	sub instrument2earth()
   225 	{
   262 	{
   226 		unless ($checked) {
   263 		unless ($checked) {
   227 			die("$ARGV[0]: instrument-coordinate data required\n")
   264 			die("$ARGV[0]: instrument-coordinate data required\n")
   228 				unless ($dta{INSTRUMENT_COORDINATES});
   265 				unless ($dta{INSTRUMENT_COORDINATES});
   229 			$dta{BEAM_COORDINATES} = 1; undef($dta{INSTRUMENT_COORDINATES});
   266 			die("$ARGV[0]: single-ping ensembles required\n")
       
   267 				unless ($dta{PINGS_PER_ENSEMBLE} == 1);
       
   268 			$dta{EARTH_COORDINATES} = 1; undef($dta{INSTRUMENT_COORDINATES});
   230 			$checked = 1;
   269 			$checked = 1;
   231 		}
   270 		}
   232 	    
   271 	    
   233 		for (my($bin)=0; $bin<$dta{N_BINS}; $bin++) {
   272 		for (my($bin)=0; $bin<$dta{N_BINS}; $bin++) {
   234 			@{$dta{ENSEMBLE}[$e]->{VELOCITY}[$bin]} =
   273 			@{$dta{ENSEMBLE}[$e]->{VELOCITY}[$bin]} =
   235 				velInstrumentToEarth(\%dta,$e,@{$dta{ENSEMBLE}[$e]->{VELOCITY}[$bin]});
   274 				velInstrumentToEarth(\%dta,$e,@{$dta{ENSEMBLE}[$e]->{VELOCITY}[$bin]});
       
   275 		}
       
   276 	
       
   277 		return 1;
       
   278 	}
       
   279 
       
   280 }
       
   281 
       
   282 #
       
   283 # transform beam to earth coordinates
       
   284 #
       
   285 { my($checked);
       
   286 
       
   287 	sub beam2earth()
       
   288 	{
       
   289 		unless ($checked) {
       
   290 			die("$ARGV[0]: beam-coordinate data required\n")
       
   291 				unless ($dta{BEAM_COORDINATES});
       
   292 			die("$ARGV[0]: single-ping ensembles required\n")
       
   293 				unless ($dta{PINGS_PER_ENSEMBLE} == 1);
       
   294 			$dta{EARTH_COORDINATES} = 1; undef($dta{BEAM_COORDINATES});
       
   295 			$checked = 1;
       
   296 		}
       
   297 	    
       
   298 		for (my($bin)=0; $bin<$dta{N_BINS}; $bin++) {
       
   299 			@{$dta{ENSEMBLE}[$e]->{VELOCITY}[$bin]} =
       
   300 				velBeamToEarth(\%dta,$e,@{$dta{ENSEMBLE}[$e]->{VELOCITY}[$bin]});
       
   301 			$dta{ENSEMBLE}[$e]->{PERCENT_GOOD}[$bin][0] = 100*$RDI_Coords::threeBeamFlag;	# 3-beam solution
       
   302 			$dta{ENSEMBLE}[$e]->{PERCENT_GOOD}[$bin][1] = 0;								# error velocity not checked
       
   303 			$dta{ENSEMBLE}[$e]->{PERCENT_GOOD}[$bin][2] =									# no solution -> more than 1 bad beam
       
   304 								@{$dta{ENSEMBLE}[$e]->{VELOCITY}[$bin]} ? 0 : 100;
       
   305 			$dta{ENSEMBLE}[$e]->{PERCENT_GOOD}[$bin][2] =									# 4-beam solution
       
   306 								100 -  $dta{ENSEMBLE}[$e]->{PERCENT_GOOD}[$bin][0];
   236 		}
   307 		}
   237 	
   308 	
   238 		return 1;
   309 		return 1;
   239 	}
   310 	}
   240 
   311