editPD0
changeset 37 40d85448debf
parent 36 515b06dae59c
child 40 6a46e9d31106
equal deleted inserted replaced
36:515b06dae59c 37:40d85448debf
     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 Jul 12 18:56:55 2016
     5 #                    dlm: Tue Nov 15 11:05:46 2016
     6 #                    (c) 2013 A.M. Thurnherr
     6 #                    (c) 2013 A.M. Thurnherr
     7 #                    uE-Info: 118 0 NIL 0 0 72 2 2 4 NIL ofnI
     7 #                    uE-Info: 73 76 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:
    68 #				  - BUG: instrument2earth() set wrong flag
    68 #				  - BUG: instrument2earth() set wrong flag
    69 #	Jun  8, 2016: - adapted to new interface of velInstrumentToBeam()
    69 #	Jun  8, 2016: - adapted to new interface of velInstrumentToBeam()
    70 #				  - added %-good to beam2earth and earth2beam
    70 #				  - added %-good to beam2earth and earth2beam
    71 #				  - made single-ping ensemble requirement for most routines
    71 #				  - made single-ping ensemble requirement for most routines
    72 #	Jul 12, 2016: - updated ensure_{DL,UL} routines
    72 #	Jul 12, 2016: - updated ensure_{DL,UL} routines
       
    73 #	Nov 15, 2016: - BUG: ensure_{DL,UL} routines did not negate heading data
    73 
    74 
    74 use Getopt::Std;
    75 use Getopt::Std;
    75 
    76 
    76 ($ADCP_TOOLS) = ($0 =~ m{(.*/)[^/]+});
    77 ($ADCP_TOOLS) = ($0 =~ m{(.*/)[^/]+});
    77 $ADCP_tools_minVersion = 1.4; 
    78 $ADCP_tools_minVersion = 1.4; 
    87 die("$0: -e <edit-file> or -x <expr> required\n")
    88 die("$0: -e <edit-file> or -x <expr> required\n")
    88     unless (defined($opt_x) || -r $opt_e);
    89     unless (defined($opt_x) || -r $opt_e);
    89 
    90 
    90 print(STDERR "Reading $ARGV[0]...");                # read data
    91 print(STDERR "Reading $ARGV[0]...");                # read data
    91 readData($ARGV[0],\%dta);
    92 readData($ARGV[0],\%dta);
    92 print(STDERR "done\n");
    93 printf(STDERR "done (%d complete ensembles)\n",
       
    94 	scalar(@{$dta{ENSEMBLE}}));
    93 
    95 
    94 #----------------------------------------------------------------------
    96 #----------------------------------------------------------------------
    95 
    97 
    96 print(STDERR "Editing Data...");                
    98 print(STDERR "Editing Data...");                
    97 
    99 
   109 #
   111 #
   110 # override transducer orientation
   112 # override transducer orientation
   111 #
   113 #
   112 #	These routines are intended to correct ADCP data for
   114 #	These routines are intended to correct ADCP data for
   113 #	erroneous orientation switch readings, primarily because
   115 #	erroneous orientation switch readings, primarily because
   114 #	of a stuck switch. While not fully debugged, negating
   116 #	of a stuck switch.
   115 #	the roll value greatly improves the vertical velocity
   117 #		Roll: Based on text from the coord trans manual,
   116 #	solutions of 2007 CLIVAR I08S profile #1. (#2-#7 could
   118 #			  it seems likely that the roll data need to
   117 #	also be used for testing)
   119 #			  be negated. In case of 2007(?) CLIVAR I08S
   118 #
   120 #			  profile #1 w gets much better with negated
       
   121 #			  roll. Also, in 2016 CLIVAR P18 profile 003
       
   122 #			  the instrument-offset calculation from
       
   123 #			  compass and pitch/roll only agree with the
       
   124 #			  roll negated.
       
   125 #		Hdg: Based on the time-series of headings recorded
       
   126 #		     during P18 profile 003 the heading needs
       
   127 #			 to be negated. Doing so yields a good profile.
   119 
   128 
   120 sub ensure_DL()
   129 sub ensure_DL()
   121 {
   130 {
   122 	if ($dta{ENSEMBLE}[$e]->{XDUCER_FACING_UP}) {
   131 	if ($dta{ENSEMBLE}[$e]->{XDUCER_FACING_UP}) {
   123 		$dta{ENSEMBLE}[$e]->{ROLL} *= -1;
   132 		$dta{ENSEMBLE}[$e]->{ROLL} *= -1;
       
   133 		$dta{ENSEMBLE}[$e]->{HEADING} *= -1; 
       
   134 		$dta{ENSEMBLE}[$e]->{HEADING} += 360
       
   135 			if ($dta{ENSEMBLE}[$e]->{HEADING} < 0);
   124 		$dta{ENSEMBLE}[$e]->{XDUCER_FACING_DOWN} = 1;
   136 		$dta{ENSEMBLE}[$e]->{XDUCER_FACING_DOWN} = 1;
   125 		$dta{ENSEMBLE}[$e]->{XDUCER_FACING_UP} = undef;
   137 		$dta{ENSEMBLE}[$e]->{XDUCER_FACING_UP} = undef;
   126 	}
   138 	}
   127 	return 1;
   139 	return 1;
   128 }
   140 }
   129 
   141 
   130 sub ensure_UL()
   142 sub ensure_UL()
   131 {
   143 {
   132 	if ($dta{ENSEMBLE}[$e]->{XDUCER_FACING_DOWN}) {
   144 	if ($dta{ENSEMBLE}[$e]->{XDUCER_FACING_DOWN}) {
   133 		$dta{ENSEMBLE}[$e]->{ROLL} *= -1;
   145 		$dta{ENSEMBLE}[$e]->{ROLL} *= -1;
       
   146 		$dta{ENSEMBLE}[$e]->{HEADING} *= -1; 
       
   147 		$dta{ENSEMBLE}[$e]->{HEADING} += 360
       
   148 			if ($dta{ENSEMBLE}[$e]->{HEADING} < 0);
   134 		$dta{ENSEMBLE}[$e]->{XDUCER_FACING_UP} = 1;
   149 		$dta{ENSEMBLE}[$e]->{XDUCER_FACING_UP} = 1;
   135 		$dta{ENSEMBLE}[$e]->{XDUCER_FACING_DOWN} = undef;
   150 		$dta{ENSEMBLE}[$e]->{XDUCER_FACING_DOWN} = undef;
   136 	}
   151 	}
   137 	return 1;
   152 	return 1;
   138 }
   153 }