editPD0
changeset 40 6a46e9d31106
parent 37 40d85448debf
child 41 d7ab920c1de6
equal deleted inserted replaced
39:3bddaa514ef5 40:6a46e9d31106
     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 Nov 15 11:05:46 2016
     5 #                    dlm: Thu Jul 27 18:30:16 2017
     6 #                    (c) 2013 A.M. Thurnherr
     6 #                    (c) 2013 A.M. Thurnherr
     7 #                    uE-Info: 73 76 NIL 0 0 72 2 2 4 NIL ofnI
     7 #                    uE-Info: 122 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:
    37 #									- does not handle bin-remapping
    37 #									- does not handle bin-remapping
    38 #									- input in instrument coords required
    38 #									- input in instrument coords required
    39 #
    39 #
    40 #		ensure_UL()				correct data for wrong transducer orientation
    40 #		ensure_UL()				correct data for wrong transducer orientation
    41 #		ensure_DL()					- sets correct flag & negates roll value
    41 #		ensure_DL()					- sets correct flag & negates roll value
       
    42 #
       
    43 #		dealias(<WV lim[m/s]>) 	correct data for erroneously low WV setting
       
    44 #									- HEURISTIC, i.e. may not work
    42 #
    45 #
    43 #	- -x notes:
    46 #	- -x notes:
    44 #		- multiple perl expressions can be combined with ,
    47 #		- multiple perl expressions can be combined with ,
    45 #
    48 #
    46 #	- Edit File Syntax:
    49 #	- Edit File Syntax:
    69 #	Jun  8, 2016: - adapted to new interface of velInstrumentToBeam()
    72 #	Jun  8, 2016: - adapted to new interface of velInstrumentToBeam()
    70 #				  - added %-good to beam2earth and earth2beam
    73 #				  - added %-good to beam2earth and earth2beam
    71 #				  - made single-ping ensemble requirement for most routines
    74 #				  - made single-ping ensemble requirement for most routines
    72 #	Jul 12, 2016: - updated ensure_{DL,UL} routines
    75 #	Jul 12, 2016: - updated ensure_{DL,UL} routines
    73 #	Nov 15, 2016: - BUG: ensure_{DL,UL} routines did not negate heading data
    76 #	Nov 15, 2016: - BUG: ensure_{DL,UL} routines did not negate heading data
       
    77 #	Jul 27, 2017: - began working on dealias()
    74 
    78 
    75 use Getopt::Std;
    79 use Getopt::Std;
    76 
    80 
    77 ($ADCP_TOOLS) = ($0 =~ m{(.*/)[^/]+});
    81 ($ADCP_TOOLS) = ($0 =~ m{(.*/)[^/]+});
    78 $ADCP_tools_minVersion = 1.4; 
    82 $ADCP_tools_minVersion = 1.4; 
    99 
   103 
   100 #--------------------------------------------------
   104 #--------------------------------------------------
   101 # Data Editing Library
   105 # Data Editing Library
   102 #--------------------------------------------------
   106 #--------------------------------------------------
   103 
   107 
   104 #
   108 #--------------------------------------------------
   105 # override pitch/roll/heading
   109 # override pitch/roll/heading
   106 #
   110 #--------------------------------------------------
       
   111 
   107 sub p($) { $dta{ENSEMBLE}[$e]->{PITCH} = $_[0]; return 1; }
   112 sub p($) { $dta{ENSEMBLE}[$e]->{PITCH} = $_[0]; return 1; }
   108 sub r($) { $dta{ENSEMBLE}[$e]->{ROLL} = $_[0]; return 1; }
   113 sub r($) { $dta{ENSEMBLE}[$e]->{ROLL} = $_[0]; return 1; }
   109 sub h($) { $dta{ENSEMBLE}[$e]->{HEADING} = $_[0]; return 1;}
   114 sub h($) { $dta{ENSEMBLE}[$e]->{HEADING} = $_[0]; return 1;}
   110 
   115 
   111 #
   116 #--------------------------------------------------
       
   117 # correct data for erroneously low WV limit
       
   118 #--------------------------------------------------
       
   119 
       
   120 { my(@target);												# static scope, undef initially
       
   121 
       
   122 sub dealias_V0($)
       
   123 {
       
   124 	my($WV) = @_;
       
   125 
       
   126 	if (@target) {											# dealias everything but first ensemble
       
   127 		for (my($bin)=0; $bin<$dta{N_BINS}; $bin++) {
       
   128 			for (my($beam)=0; $beam<4; $beam++) {
       
   129 				next unless defined($dta{ENSEMBLE}[$e]->{VELOCITY}[$bin][$beam]);
       
   130 				my($dealiased) = 0;
       
   131 				$dealiased = ($dta{ENSEMBLE}[$e]->{VELOCITY}[$bin][$beam] - 2*$WV)
       
   132 					if ($dta{ENSEMBLE}[$e]->{VELOCITY}[$bin][$beam] > 0);
       
   133 				$dealiased = ($dta{ENSEMBLE}[$e]->{VELOCITY}[$bin][$beam] + 2*$WV)
       
   134 					if ($dta{ENSEMBLE}[$e]->{VELOCITY}[$bin][$beam] < 0);
       
   135 				if (abs($target[$beam]-$dta{ENSEMBLE}[$e]->{VELOCITY}[$bin][$beam]) >
       
   136 					abs($target[$beam]-$dealiased)) {
       
   137 						$dta{ENSEMBLE}[$e]->{VELOCITY}[$bin][$beam] = undef; #$dealiased;
       
   138 						$dealiased++;
       
   139 				}
       
   140 			}
       
   141     	}
       
   142     } else { # @target is undef
       
   143     	$dealiased = 0;
       
   144     }
       
   145 
       
   146 	@target = (0,0,0,0);									# calc ref-lr average target for next ens
       
   147 	for (my($bin)=1; $bin<=5; $bin++) {						# should work even if N_BINS < 5
       
   148 		for (my($beam)=0; $beam<4; $beam++) {
       
   149 			$target[$beam] += $dta{ENSEMBLE}[$e]->{VELOCITY}[$bin][$beam]/4
       
   150 				if defined($dta{ENSEMBLE}[$e]->{VELOCITY}[$bin][$beam]);
       
   151 		}
       
   152     }
       
   153 
       
   154     return 1;
       
   155 }
       
   156 
       
   157 } # static scope
       
   158 
       
   159 #--------------------------------------------------
   112 # override transducer orientation
   160 # override transducer orientation
   113 #
   161 #
   114 #	These routines are intended to correct ADCP data for
   162 #	These routines are intended to correct ADCP data for
   115 #	erroneous orientation switch readings, primarily because
   163 #	erroneous orientation switch readings, primarily because
   116 #	of a stuck switch.
   164 #	of a stuck switch.
   123 #			  compass and pitch/roll only agree with the
   171 #			  compass and pitch/roll only agree with the
   124 #			  roll negated.
   172 #			  roll negated.
   125 #		Hdg: Based on the time-series of headings recorded
   173 #		Hdg: Based on the time-series of headings recorded
   126 #		     during P18 profile 003 the heading needs
   174 #		     during P18 profile 003 the heading needs
   127 #			 to be negated. Doing so yields a good profile.
   175 #			 to be negated. Doing so yields a good profile.
       
   176 #--------------------------------------------------
   128 
   177 
   129 sub ensure_DL()
   178 sub ensure_DL()
   130 {
   179 {
   131 	if ($dta{ENSEMBLE}[$e]->{XDUCER_FACING_UP}) {
   180 	if ($dta{ENSEMBLE}[$e]->{XDUCER_FACING_UP}) {
   132 		$dta{ENSEMBLE}[$e]->{ROLL} *= -1;
   181 		$dta{ENSEMBLE}[$e]->{ROLL} *= -1;
   150 		$dta{ENSEMBLE}[$e]->{XDUCER_FACING_DOWN} = undef;
   199 		$dta{ENSEMBLE}[$e]->{XDUCER_FACING_DOWN} = undef;
   151 	}
   200 	}
   152 	return 1;
   201 	return 1;
   153 }
   202 }
   154 
   203 
   155 #
   204 #--------------------------------------------------
   156 # swap data from two mis-connected beams
   205 # swap data from two mis-connected beams
   157 #
   206 #--------------------------------------------------
       
   207 
   158 sub swap_beams($$)
   208 sub swap_beams($$)
   159 {
   209 {
   160 	my($b1,$b2) = @_;
   210 	my($b1,$b2) = @_;
   161 	my($tmp);
   211 	my($tmp);
   162 
   212 
   208 	}
   258 	}
   209 	return 1;
   259 	return 1;
   210 }
   260 }
   211 
   261 
   212 
   262 
   213 #
   263 #--------------------------------------------------
   214 # transform earth to beam coordinates
   264 # transform earth to beam coordinates
   215 #
   265 #--------------------------------------------------
       
   266 
   216 { my($checked);
   267 { my($checked);
   217 
   268 
   218 	sub earth2beam()
   269 	sub earth2beam()
   219 	{
   270 	{
   220 		unless ($checked) {
   271 		unless ($checked) {
   240 		return 1;
   291 		return 1;
   241 	}
   292 	}
   242 
   293 
   243 }
   294 }
   244 
   295 
   245 #
   296 #--------------------------------------------------
   246 # transform instrument to beam coordinates
   297 # transform instrument to beam coordinates
   247 #
   298 #--------------------------------------------------
       
   299 
   248 { my($checked);
   300 { my($checked);
   249 
   301 
   250 	sub instrument2beam()
   302 	sub instrument2beam()
   251 	{
   303 	{
   252 		unless ($checked) {
   304 		unless ($checked) {
   266 		return 1;
   318 		return 1;
   267 	}
   319 	}
   268 
   320 
   269 }
   321 }
   270 
   322 
   271 #
   323 #--------------------------------------------------
   272 # transform instrument to earth coordinates
   324 # transform instrument to earth coordinates
   273 #
   325 #--------------------------------------------------
       
   326 
   274 { my($checked);
   327 { my($checked);
   275 
   328 
   276 	sub instrument2earth()
   329 	sub instrument2earth()
   277 	{
   330 	{
   278 		unless ($checked) {
   331 		unless ($checked) {
   292 		return 1;
   345 		return 1;
   293 	}
   346 	}
   294 
   347 
   295 }
   348 }
   296 
   349 
   297 #
   350 #--------------------------------------------------
   298 # transform beam to earth coordinates
   351 # transform beam to earth coordinates
   299 #
   352 #--------------------------------------------------
       
   353 
   300 { my($checked);
   354 { my($checked);
   301 
   355 
   302 	sub beam2earth()
   356 	sub beam2earth()
   303 	{
   357 	{
   304 		unless ($checked) {
   358 		unless ($checked) {
   343 	while (<EF>) {
   397 	while (<EF>) {
   344 		s/\#.*//;
   398 		s/\#.*//;
   345 		next if m/^\s+$/;
   399 		next if m/^\s+$/;
   346 		my($ens,$expr) = m/^\s*(\*|\d+)\s+(.*)$/;
   400 		my($ens,$expr) = m/^\s*(\*|\d+)\s+(.*)$/;
   347 	
   401 	
   348 		my($id) = ($expr =~ m/^([A-Z]+)\s/);										# e.g. PITCH, ROLL, HEADING
   402 		my($id) = ($expr =~ m/^([A-Z]+)\s/);									# e.g. PITCH, ROLL, HEADING
   349 		$expr = sprintf('$dta{ENSEMBLE}[$e]->{%s}',$id)
   403 		$expr = sprintf('$dta{ENSEMBLE}[$e]->{%s}',$id)
   350 			if defined($id);
   404 			if defined($id);
   351 		    
   405 		    
   352 		push(@EE,$ens);
   406 		push(@EE,$ens);
   353 		push(@EX,$expr);
   407 		push(@EX,$expr);