listEns
author A.M. Thurnherr <athurnherr@yahoo.com>
Tue, 29 Jun 2021 12:21:32 -0400
changeset 59 4f4530fa35da
parent 55 540d6574caca
permissions -rwxr-xr-x
V2.4 - New Features: - support for Nortek PD0 files - patchPD0 support for moored ADCP data - bug fixes & minor improvements
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
0
229a0d72d2ab first hg version
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
     1
#!/usr/bin/perl
229a0d72d2ab first hg version
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
     2
#======================================================================
229a0d72d2ab first hg version
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
     3
#                    L I S T E N S 
229a0d72d2ab first hg version
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
     4
#                    doc: Sat Jan 18 18:41:49 2003
55
540d6574caca adapted to Nortek
Andreas Thurnherr <ant@ldeo.columbia.edu>
parents: 54
diff changeset
     5
#                    dlm: Wed Mar  3 15:35:40 2021
0
229a0d72d2ab first hg version
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
     6
#                    (c) 2003 A.M. Thurnherr
55
540d6574caca adapted to Nortek
Andreas Thurnherr <ant@ldeo.columbia.edu>
parents: 54
diff changeset
     7
#                    uE-Info: 239 14 NIL 0 0 72 2 2 4 NIL ofnI
0
229a0d72d2ab first hg version
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
     8
#======================================================================
229a0d72d2ab first hg version
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
     9
43
b63fa355644c commit to merge with changes from EN620
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 37
diff changeset
    10
$synopsis = 'list ensemble summaries (default), dump ensembles (-E), time-average ensembles (-T)';
0
229a0d72d2ab first hg version
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
    11
229a0d72d2ab first hg version
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
    12
# HISTORY:
229a0d72d2ab first hg version
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
    13
#	Jan 18, 2003: - created
229a0d72d2ab first hg version
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
    14
#	Mar 18, 2004: - updated
229a0d72d2ab first hg version
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
    15
#	Sep 15, 2005: - made ESW optional (BB150)
229a0d72d2ab first hg version
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
    16
#				  - change RDI binread library name
229a0d72d2ab first hg version
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
    17
#	Aug 25, 2006: - added -r)ange
229a0d72d2ab first hg version
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
    18
#				  - added write -E)nsembles
229a0d72d2ab first hg version
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
    19
#	Aug 26, 2006: - added -M)agdecl
229a0d72d2ab first hg version
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
    20
#	Sep 19, 2007: - adapted to new [RDI_BB_Read.pl] (not tested)
229a0d72d2ab first hg version
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
    21
#	Jan 26, 2008: - BUG: diagnostic output had been written to STDOUT
229a0d72d2ab first hg version
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
    22
#	Feb  1, 2008: - BUG: still more diagnostic output written to STDOUT
229a0d72d2ab first hg version
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
    23
#				  - BUG: -E/-A combo had ignored -E
229a0d72d2ab first hg version
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
    24
#				  - changed %-good fieldnames for earth coordinates
229a0d72d2ab first hg version
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
    25
#				  - allowed for 3-beam solutions
229a0d72d2ab first hg version
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
    26
#	Feb  7, 2008: - added -f)ields
229a0d72d2ab first hg version
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
    27
#	Apr  4, 2008: - made -f output nan on undefined values
229a0d72d2ab first hg version
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
    28
#				  - BUG: -f fields did not allow array indices
229a0d72d2ab first hg version
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
    29
#				  - added in-w)ater data only
229a0d72d2ab first hg version
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
    30
#				  - restructured for simplicity
229a0d72d2ab first hg version
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
    31
#	Mar  2, 2009: - added # of valid bin-1 vels to non-ANTS output
229a0d72d2ab first hg version
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
    32
#	Jul 30, 2009: - NaN => nan
1
a3b6a908dec5 after P302 cruise
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents: 0
diff changeset
    33
#	Aug 15, 2010: - BUG: usage typo
5
29faa9e6226c after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents: 1
diff changeset
    34
#	Dec 10, 2010: - changed ANTS output to time/date instead of UNIX time
29faa9e6226c after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents: 1
diff changeset
    35
#	Jan  5, 2011: - added -b
6
603221e51c6f pre IWISE
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 5
diff changeset
    36
#	May 12, 2011: - disabled error exit on built-in-test errors when ensembles are dumped to stdout
10
c835cd613f3e before EGU Vienna
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 6
diff changeset
    37
#	Mar 20, 2013: - removed DATA_FORMAT stuff
11
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents: 10
diff changeset
    38
#	Apr 12, 2013: - added bin number to -E output
13
b176da8559b3 before implementing WBWens (PD0 writing)
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 11
diff changeset
    39
#	Aug  7, 2013: - added -d, -4
b176da8559b3 before implementing WBWens (PD0 writing)
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 11
diff changeset
    40
#				  - added w12, w34 to -E output
b176da8559b3 before implementing WBWens (PD0 writing)
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 11
diff changeset
    41
#				  - added sounspeed correction warning
b176da8559b3 before implementing WBWens (PD0 writing)
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 11
diff changeset
    42
#				  - changed -E from prefix to suffix
b176da8559b3 before implementing WBWens (PD0 writing)
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 11
diff changeset
    43
#				  - added active header line to -E output
18
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 13
diff changeset
    44
#	Mar  4, 2014: - added partial support for DATA_SOURCE_ID
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 13
diff changeset
    45
#				  - added support for missing PITCH/ROLL/HEADING
21
0b5bbe60131c version sent to P16N
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 18
diff changeset
    46
#	Sep  8, 2014: - added -B)T  
33
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 21
diff changeset
    47
#   Mar 17, 2016: - adapted to new Getopt library
34
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 33
diff changeset
    48
#	Apr 19, 2016: - added %date, %time to -E output
37
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 34
diff changeset
    49
#	Nov  9, 2016: - BUG: no error on missing files
43
b63fa355644c commit to merge with changes from EN620
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 37
diff changeset
    50
#	Feb  7, 2018: - removed 3-beam error
b63fa355644c commit to merge with changes from EN620
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 37
diff changeset
    51
#	Apr  1, 2018: - improved usage message
b63fa355644c commit to merge with changes from EN620
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 37
diff changeset
    52
#				  - removed -Q option (errcheck only, which is not necessary; can use mkProfile to check for errors)
b63fa355644c commit to merge with changes from EN620
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 37
diff changeset
    53
#				  - added -T (time averaging)
b63fa355644c commit to merge with changes from EN620
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 37
diff changeset
    54
#	Apr  2, 2018: - made it work
b63fa355644c commit to merge with changes from EN620
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 37
diff changeset
    55
#				  - BUG: velBeamToInstrument() was using old usage
b63fa355644c commit to merge with changes from EN620
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 37
diff changeset
    56
#	Apr  3, 2018: - BUG: typo
b63fa355644c commit to merge with changes from EN620
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 37
diff changeset
    57
#				  - added -S from [listBins]
b63fa355644c commit to merge with changes from EN620
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 37
diff changeset
    58
#				  - removed -B and an BT data (current version did not treat beam-coord BT data correctly)
b63fa355644c commit to merge with changes from EN620
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 37
diff changeset
    59
#	Apr  4, 2018: - added support for first_ens and last_ens in [RDI_PD0_IO.pl]
b63fa355644c commit to merge with changes from EN620
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 37
diff changeset
    60
#				  - removed support for multiple input files
b63fa355644c commit to merge with changes from EN620
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 37
diff changeset
    61
#	Apr 10, 2018: - added -l)ast bin
b63fa355644c commit to merge with changes from EN620
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 37
diff changeset
    62
#	May 31, 2018: - BUG: -A was disabled by default
50
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 43
diff changeset
    63
#	Feb 13, 2020: - added support for $readDataProgress
54
21cf468fa8e0 prior to A20
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 50
diff changeset
    64
#	Feb 19, 2021: - BUG: -T did not handle new years correctly
55
540d6574caca adapted to Nortek
Andreas Thurnherr <ant@ldeo.columbia.edu>
parents: 54
diff changeset
    65
#	Mar  3, 2021: - BUG: debug statement left in place
540d6574caca adapted to Nortek
Andreas Thurnherr <ant@ldeo.columbia.edu>
parents: 54
diff changeset
    66
# END OF HISTORY
0
229a0d72d2ab first hg version
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
    67
229a0d72d2ab first hg version
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
    68
# Notes:
43
b63fa355644c commit to merge with changes from EN620
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 37
diff changeset
    69
#	- -E/-B outputs data in earth coordinates, unless -b is set also
b63fa355644c commit to merge with changes from EN620
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 37
diff changeset
    70
#	- -E/-T output is always in ANTS format
0
229a0d72d2ab first hg version
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
    71
33
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 21
diff changeset
    72
use Getopt::Std;
43
b63fa355644c commit to merge with changes from EN620
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 37
diff changeset
    73
b63fa355644c commit to merge with changes from EN620
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 37
diff changeset
    74
$ADCP_tools_minVersion = 2.2;
b63fa355644c commit to merge with changes from EN620
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 37
diff changeset
    75
($ADCP_TOOLS) = ($0 =~ m{(.*/)[^/]+});
b63fa355644c commit to merge with changes from EN620
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 37
diff changeset
    76
require "$ADCP_TOOLS/ADCP_tools_lib.pl";
b63fa355644c commit to merge with changes from EN620
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 37
diff changeset
    77
b63fa355644c commit to merge with changes from EN620
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 37
diff changeset
    78
$antsMinLibVersion = 7.0;
b63fa355644c commit to merge with changes from EN620
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 37
diff changeset
    79
($ANTS) = (`which ANTSlib` =~ m{^(.*)/[^/]*$});
b63fa355644c commit to merge with changes from EN620
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 37
diff changeset
    80
require "$ANTS/ants.pl";
b63fa355644c commit to merge with changes from EN620
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 37
diff changeset
    81
require "$ANTS/libconv.pl";
b63fa355644c commit to merge with changes from EN620
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 37
diff changeset
    82
b63fa355644c commit to merge with changes from EN620
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 37
diff changeset
    83
($self) = ($0 =~ m{.*/([^/]+)});
b63fa355644c commit to merge with changes from EN620
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 37
diff changeset
    84
$cmdline = "$self @ARGV";
0
229a0d72d2ab first hg version
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
    85
43
b63fa355644c commit to merge with changes from EN620
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 37
diff changeset
    86
die("\n$self [-4ABbdEfiMprSTw] <PD0 file> -- $synopsis\n\nCommand-Line Options:\n\t" .
b63fa355644c commit to merge with changes from EN620
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 37
diff changeset
    87
			  "Output Ensemble Summary (default mode):\n\t\t" .
b63fa355644c commit to merge with changes from EN620
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 37
diff changeset
    88
				  "[-A)NTS format]\n\t\t" .
b63fa355644c commit to merge with changes from EN620
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 37
diff changeset
    89
			  "Dump Ensembles (-E|-T; ANTS Format):\n\t\t" .
b63fa355644c commit to merge with changes from EN620
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 37
diff changeset
    90
				  "[dump individual -E)nsemples <.suff>]\n\t\t" .
b63fa355644c commit to merge with changes from EN620
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 37
diff changeset
    91
				  "[-T)ime-average ensembles [time-series start (decimal day),]<averaging interval (days)>[,time-series end (decimal day)]]\n\t\t\t" .
b63fa355644c commit to merge with changes from EN620
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 37
diff changeset
    92
				  	"[-i)gnore bins with <fraction> of max samples (-T only)]\n\t\t\t" .
b63fa355644c commit to merge with changes from EN620
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 37
diff changeset
    93
				  	"[output -B)asename <bn>]\n\t\t" .
b63fa355644c commit to merge with changes from EN620
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 37
diff changeset
    94
				  "[-M)agnetic <declination>]\n\t\t" .
b63fa355644c commit to merge with changes from EN620
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 37
diff changeset
    95
				  "[-S)oundspeed correction <salin|*,temp|*,depth|*>\n\t\t" .
b63fa355644c commit to merge with changes from EN620
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 37
diff changeset
    96
				  "[require min -p)ercent-good <#>]\n\t\t" .
b63fa355644c commit to merge with changes from EN620
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 37
diff changeset
    97
				  "[keep -b)eam coords (do not transform to earth coordinates)]\n\t" .
b63fa355644c commit to merge with changes from EN620
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 37
diff changeset
    98
			  "Common Options:\n\t\t" .
50
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 43
diff changeset
    99
			  	  "[-z print progress dots every 10000 ens\n\t\t" .
43
b63fa355644c commit to merge with changes from EN620
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 37
diff changeset
   100
				  "[add -f)ields <[name=]FIELD[,...]>]\n\t\t" .
b63fa355644c commit to merge with changes from EN620
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 37
diff changeset
   101
				  "[require -4)-beam solutions] [-d)iscard <beam#>]\n\t\t" .
b63fa355644c commit to merge with changes from EN620
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 37
diff changeset
   102
				  "[-r)ange <first_ens,last_ens>] [-l)ast <bin>]\n\t\t" .
b63fa355644c commit to merge with changes from EN620
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 37
diff changeset
   103
				  "[in-w)ater ensembles only]\n")
50
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 43
diff changeset
   104
	unless (&getopts('4AB:bd:E:f:i:l:M:p:r:S:T:wz') && @ARGV == 1);
13
b176da8559b3 before implementing WBWens (PD0 writing)
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 11
diff changeset
   105
43
b63fa355644c commit to merge with changes from EN620
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 37
diff changeset
   106
die("$ARGV[0]: no such file\n")
b63fa355644c commit to merge with changes from EN620
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 37
diff changeset
   107
	unless (-f $ARGV[0]);
b63fa355644c commit to merge with changes from EN620
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 37
diff changeset
   108
50
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 43
diff changeset
   109
$global::readDataProgress = 10000 if defined($opt_z);
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 43
diff changeset
   110
43
b63fa355644c commit to merge with changes from EN620
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 37
diff changeset
   111
$dump_ens = defined($opt_E) + defined($opt_T);
b63fa355644c commit to merge with changes from EN620
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 37
diff changeset
   112
die("$self: cannot combine -E with -T\n") if ($dump_ens > 1);
b63fa355644c commit to merge with changes from EN620
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 37
diff changeset
   113
b63fa355644c commit to merge with changes from EN620
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 37
diff changeset
   114
if (defined($opt_S)) {
b63fa355644c commit to merge with changes from EN620
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 37
diff changeset
   115
	($SS_salin,$SS_temp,$SS_depth) = split(',',$opt_S);
b63fa355644c commit to merge with changes from EN620
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 37
diff changeset
   116
} else {
b63fa355644c commit to merge with changes from EN620
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 37
diff changeset
   117
	print(STDERR "WARNING: no soundspeed correction applied!\n")
b63fa355644c commit to merge with changes from EN620
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 37
diff changeset
   118
		if ($dump_ens);
b63fa355644c commit to merge with changes from EN620
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 37
diff changeset
   119
}
0
229a0d72d2ab first hg version
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
   120
229a0d72d2ab first hg version
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
   121
print(STDERR "WARNING: magnetic declination not set!\n")
43
b63fa355644c commit to merge with changes from EN620
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 37
diff changeset
   122
	if ($dump_ens && !defined($opt_M));
0
229a0d72d2ab first hg version
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
   123
43
b63fa355644c commit to merge with changes from EN620
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 37
diff changeset
   124
die("$self: illegal option combination\n")
b63fa355644c commit to merge with changes from EN620
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 37
diff changeset
   125
	if ((defined($opt_M) || defined($opt_p) || defined($opt_b)) && !defined($dump_ens));
0
229a0d72d2ab first hg version
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
   126
43
b63fa355644c commit to merge with changes from EN620
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 37
diff changeset
   127
die("$self: -4 and -d are mutually exclusive\n")
13
b176da8559b3 before implementing WBWens (PD0 writing)
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 11
diff changeset
   128
	if ($opt_4 && defined($opt_d));
b176da8559b3 before implementing WBWens (PD0 writing)
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 11
diff changeset
   129
43
b63fa355644c commit to merge with changes from EN620
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 37
diff changeset
   130
#undef($opt_A) if defined($dump_ens);
0
229a0d72d2ab first hg version
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
   131
229a0d72d2ab first hg version
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
   132
$opt_p = 0 unless defined($opt_p);
229a0d72d2ab first hg version
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
   133
229a0d72d2ab first hg version
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
   134
if ($opt_f) {										# additional fields
229a0d72d2ab first hg version
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
   135
	@addFields = split(',',$opt_f);
229a0d72d2ab first hg version
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
   136
	foreach my $f (@addFields) {
229a0d72d2ab first hg version
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
   137
		$f =~ s/\s//g;								# remove spaces
229a0d72d2ab first hg version
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
   138
		@def = split('=',$f);
229a0d72d2ab first hg version
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
   139
		if (@def == 2) {							# name=field
229a0d72d2ab first hg version
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
   140
			$addLayout .= $opt_A ? " {$def[0]}" : " $def[0]";
229a0d72d2ab first hg version
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
   141
			$f = $def[1];
229a0d72d2ab first hg version
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
   142
		} else {									# field
229a0d72d2ab first hg version
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
   143
			$addLayout .= " {$f}";
229a0d72d2ab first hg version
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
   144
		}
229a0d72d2ab first hg version
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
   145
	}
229a0d72d2ab first hg version
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
   146
#	print(STDERR "addLayout = $addLayout\n");
229a0d72d2ab first hg version
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
   147
#	print(STDERR "\@addFields = @addFields\n");
229a0d72d2ab first hg version
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
   148
}
229a0d72d2ab first hg version
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
   149
13
b176da8559b3 before implementing WBWens (PD0 writing)
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 11
diff changeset
   150
$RDI_Coords::minValidVels = 4 if ($opt_4);			# no 3-beam solutions
b176da8559b3 before implementing WBWens (PD0 writing)
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 11
diff changeset
   151
0
229a0d72d2ab first hg version
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
   152
#----------------------------------------------------------------------
229a0d72d2ab first hg version
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
   153
# MAIN
229a0d72d2ab first hg version
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
   154
#----------------------------------------------------------------------
229a0d72d2ab first hg version
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
   155
43
b63fa355644c commit to merge with changes from EN620
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 37
diff changeset
   156
printf(STDERR "Reading $ARGV[0]...");
b63fa355644c commit to merge with changes from EN620
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 37
diff changeset
   157
if (defined($opt_r)) {								# read selected range
b63fa355644c commit to merge with changes from EN620
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 37
diff changeset
   158
	my($fe,$le) = split(',',$opt_r);
b63fa355644c commit to merge with changes from EN620
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 37
diff changeset
   159
	readData(@ARGV,\%dta,$fe,$le,$opt_l);
b63fa355644c commit to merge with changes from EN620
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 37
diff changeset
   160
} else {											# read entire file (possibly selected bins)
b63fa355644c commit to merge with changes from EN620
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 37
diff changeset
   161
	readData(@ARGV,\%dta,undef,undef,$opt_l);
b63fa355644c commit to merge with changes from EN620
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 37
diff changeset
   162
}
b63fa355644c commit to merge with changes from EN620
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 37
diff changeset
   163
printf(STDERR "\n\t%d complete ensembles\n",scalar(@{$dta{ENSEMBLE}}));
b63fa355644c commit to merge with changes from EN620
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 37
diff changeset
   164
b63fa355644c commit to merge with changes from EN620
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 37
diff changeset
   165
$dta{HEADING_BIAS} = -$opt_M;						# magnetic declination
b63fa355644c commit to merge with changes from EN620
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 37
diff changeset
   166
b63fa355644c commit to merge with changes from EN620
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 37
diff changeset
   167
if ($dta{BEAM_COORDINATES}) {						# coords used
b63fa355644c commit to merge with changes from EN620
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 37
diff changeset
   168
	$beamCoords = 1;
b63fa355644c commit to merge with changes from EN620
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 37
diff changeset
   169
} elsif (!$dta{EARTH_COORDINATES}) {
b63fa355644c commit to merge with changes from EN620
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 37
diff changeset
   170
	die("$ARGV[0]: beam or earth coordinates required (implementation restriction)\n");
b63fa355644c commit to merge with changes from EN620
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 37
diff changeset
   171
}
b63fa355644c commit to merge with changes from EN620
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 37
diff changeset
   172
die("$ARGV[0]: -b requires beam-coordinate data\n")
b63fa355644c commit to merge with changes from EN620
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 37
diff changeset
   173
	if ($opt_b && !$beamCoords);
b63fa355644c commit to merge with changes from EN620
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 37
diff changeset
   174
b63fa355644c commit to merge with changes from EN620
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 37
diff changeset
   175
($basename) = defined($opt_B)						# set basename of output files
b63fa355644c commit to merge with changes from EN620
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 37
diff changeset
   176
			? $opt_B
b63fa355644c commit to merge with changes from EN620
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 37
diff changeset
   177
			: ($ARGV[0] =~ m{([^\./]+)\.[^\.]+});
b63fa355644c commit to merge with changes from EN620
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 37
diff changeset
   178
b63fa355644c commit to merge with changes from EN620
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 37
diff changeset
   179
#----------------------------------------------------------------------
b63fa355644c commit to merge with changes from EN620
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 37
diff changeset
   180
# define &dumpEns() routine for different output formats:
b63fa355644c commit to merge with changes from EN620
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 37
diff changeset
   181
#	-A			ANTS format ensemble summary
b63fa355644c commit to merge with changes from EN620
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 37
diff changeset
   182
#	-E			create one file per ensemble
b63fa355644c commit to merge with changes from EN620
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 37
diff changeset
   183
#	-T			time-average multiple ensembles
b63fa355644c commit to merge with changes from EN620
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 37
diff changeset
   184
#	default:	ASCII ensemble summary (human readable)
b63fa355644c commit to merge with changes from EN620
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 37
diff changeset
   185
#----------------------------------------------------------------------
37
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 34
diff changeset
   186
43
b63fa355644c commit to merge with changes from EN620
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 37
diff changeset
   187
if ($opt_A) {										# select output fmt: ANTS
b63fa355644c commit to merge with changes from EN620
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 37
diff changeset
   188
	print("#ANTS#PARAMS# PD0_file{$ARGV[0]}\n");
b63fa355644c commit to merge with changes from EN620
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 37
diff changeset
   189
	printf("#ANTS#PARAMS# N_ensembles{%d}\n",scalar(@{$dta{ENSEMBLE}}));
b63fa355644c commit to merge with changes from EN620
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 37
diff changeset
   190
	print('#ANTS#FIELDS# {ens} {date} {time} {unix-time} {xducer_up} {temp} {hdg} {pitch} {roll} {XMIT_VOLTAGE} {XMIT_CURRENT}');
b63fa355644c commit to merge with changes from EN620
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 37
diff changeset
   191
	print(' {ESW}') if ($dta{FIXED_LEADER_BYTES} >= 53);
b63fa355644c commit to merge with changes from EN620
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 37
diff changeset
   192
	print("$addLayout\n");
0
229a0d72d2ab first hg version
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
   193
43
b63fa355644c commit to merge with changes from EN620
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 37
diff changeset
   194
	$dumpEns = sub ($)
b63fa355644c commit to merge with changes from EN620
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 37
diff changeset
   195
	{
b63fa355644c commit to merge with changes from EN620
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 37
diff changeset
   196
		my($e) = @_;
b63fa355644c commit to merge with changes from EN620
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 37
diff changeset
   197
	    
b63fa355644c commit to merge with changes from EN620
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 37
diff changeset
   198
		printf('%d %s %s %lf %d %g',
b63fa355644c commit to merge with changes from EN620
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 37
diff changeset
   199
			$dta{ENSEMBLE}[$e]->{NUMBER},
b63fa355644c commit to merge with changes from EN620
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 37
diff changeset
   200
			$dta{ENSEMBLE}[$e]->{DATE},
b63fa355644c commit to merge with changes from EN620
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 37
diff changeset
   201
			$dta{ENSEMBLE}[$e]->{TIME},
b63fa355644c commit to merge with changes from EN620
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 37
diff changeset
   202
			$dta{ENSEMBLE}[$e]->{UNIX_TIME},
b63fa355644c commit to merge with changes from EN620
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 37
diff changeset
   203
			$dta{ENSEMBLE}[$e]->{XDUCER_FACING_UP} ? 1 : 0,
b63fa355644c commit to merge with changes from EN620
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 37
diff changeset
   204
			$dta{ENSEMBLE}[$e]->{TEMPERATURE},
b63fa355644c commit to merge with changes from EN620
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 37
diff changeset
   205
		);
b63fa355644c commit to merge with changes from EN620
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 37
diff changeset
   206
		if (defined($dta{ENSEMBLE}[$e]->{HEADING})) { printf(' %g',$dta{ENSEMBLE}[$e]->{HEADING}); }
b63fa355644c commit to merge with changes from EN620
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 37
diff changeset
   207
		else { printf(' nan'); }
b63fa355644c commit to merge with changes from EN620
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 37
diff changeset
   208
		if (defined($dta{ENSEMBLE}[$e]->{PITCH})) { printf(' %g',$dta{ENSEMBLE}[$e]->{PITCH}); }
b63fa355644c commit to merge with changes from EN620
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 37
diff changeset
   209
		else { printf(' nan'); }
b63fa355644c commit to merge with changes from EN620
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 37
diff changeset
   210
		if (defined($dta{ENSEMBLE}[$e]->{ROLL})) { printf(' %g',$dta{ENSEMBLE}[$e]->{ROLL}); }
b63fa355644c commit to merge with changes from EN620
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 37
diff changeset
   211
		else { printf(' nan'); }
b63fa355644c commit to merge with changes from EN620
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 37
diff changeset
   212
		printf(' %g %g',
b63fa355644c commit to merge with changes from EN620
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 37
diff changeset
   213
			$dta{ENSEMBLE}[$e]->{ADC_XMIT_VOLTAGE},
b63fa355644c commit to merge with changes from EN620
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 37
diff changeset
   214
			$dta{ENSEMBLE}[$e]->{ADC_XMIT_CURRENT},
b63fa355644c commit to merge with changes from EN620
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 37
diff changeset
   215
		);
b63fa355644c commit to merge with changes from EN620
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 37
diff changeset
   216
		printf(' %08X',$dta{ENSEMBLE}[$e]->{ERROR_STATUS_WORD})
b63fa355644c commit to merge with changes from EN620
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 37
diff changeset
   217
			if ($dta{FIXED_LEADER_BYTES} >= 53);
b63fa355644c commit to merge with changes from EN620
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 37
diff changeset
   218
		foreach my $f (@addFields) {
b63fa355644c commit to merge with changes from EN620
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 37
diff changeset
   219
			my($fn,$fi) = ($f =~ m{([^[]*)(\[.*)});
b63fa355644c commit to merge with changes from EN620
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 37
diff changeset
   220
			$fn = $f unless defined($fn);
b63fa355644c commit to merge with changes from EN620
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 37
diff changeset
   221
			my($v) = eval("\$dta{ENSEMBLE}[$e]->{$fn}$fi");
b63fa355644c commit to merge with changes from EN620
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 37
diff changeset
   222
			print(defined($v) ? " $v" : " nan");
b63fa355644c commit to merge with changes from EN620
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 37
diff changeset
   223
		}
b63fa355644c commit to merge with changes from EN620
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 37
diff changeset
   224
		print("\n");
0
229a0d72d2ab first hg version
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
   225
	}
229a0d72d2ab first hg version
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
   226
43
b63fa355644c commit to merge with changes from EN620
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 37
diff changeset
   227
} elsif ($opt_E) {										# dump each ensemble in separate file 
5
29faa9e6226c after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents: 1
diff changeset
   228
43
b63fa355644c commit to merge with changes from EN620
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 37
diff changeset
   229
	$dumpEns = sub ($)
b63fa355644c commit to merge with changes from EN620
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 37
diff changeset
   230
	{
b63fa355644c commit to merge with changes from EN620
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 37
diff changeset
   231
		my($e) = @_;
b63fa355644c commit to merge with changes from EN620
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 37
diff changeset
   232
		my($b,$i);
b63fa355644c commit to merge with changes from EN620
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 37
diff changeset
   233
		my($file) = "$dta{ENSEMBLE}[$e]->{NUMBER}$opt_E";
b63fa355644c commit to merge with changes from EN620
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 37
diff changeset
   234
    
b63fa355644c commit to merge with changes from EN620
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 37
diff changeset
   235
		my($ssCorr) = defined($opt_S) ? ssCorr($dta{ENSEMBLE}[$e],$SS_salin,$SS_temp,$SS_depth) : 1;
0
229a0d72d2ab first hg version
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
   236
43
b63fa355644c commit to merge with changes from EN620
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 37
diff changeset
   237
		open(P,">$file") || die("$file: $!\n");
b63fa355644c commit to merge with changes from EN620
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 37
diff changeset
   238
		print(P "#!/usr/bin/perl -S list\n");
55
540d6574caca adapted to Nortek
Andreas Thurnherr <ant@ldeo.columbia.edu>
parents: 54
diff changeset
   239
		printf(P "#ANTS#PARAMS# " .
43
b63fa355644c commit to merge with changes from EN620
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 37
diff changeset
   240
				"date{$dta{ENSEMBLE}[$e]->{DATE}} " .
b63fa355644c commit to merge with changes from EN620
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 37
diff changeset
   241
				"time{$dta{ENSEMBLE}[$e]->{TIME}} " .
b63fa355644c commit to merge with changes from EN620
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 37
diff changeset
   242
				"soundspeed_correction{%s} " .
b63fa355644c commit to merge with changes from EN620
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 37
diff changeset
   243
				"magnetic_declination{%g} " .
b63fa355644c commit to merge with changes from EN620
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 37
diff changeset
   244
				"\n",
b63fa355644c commit to merge with changes from EN620
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 37
diff changeset
   245
					(defined($opt_S) ? $opt_S : "NONE!"),
b63fa355644c commit to merge with changes from EN620
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 37
diff changeset
   246
					$opt_M
b63fa355644c commit to merge with changes from EN620
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 37
diff changeset
   247
		);
b63fa355644c commit to merge with changes from EN620
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 37
diff changeset
   248
		print(P "#ANTS#FIELDS# " .
b63fa355644c commit to merge with changes from EN620
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 37
diff changeset
   249
				"{bin} {dz} {u} {v} {w} {e} {w12} {w34} {corr1} {corr2} {corr3} {corr4} " .
b63fa355644c commit to merge with changes from EN620
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 37
diff changeset
   250
				"{amp1} {amp2} {amp3} {amp4} "
b63fa355644c commit to merge with changes from EN620
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 37
diff changeset
   251
		);
b63fa355644c commit to merge with changes from EN620
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 37
diff changeset
   252
		if ($beamCoords) {
b63fa355644c commit to merge with changes from EN620
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 37
diff changeset
   253
			print(P "{pcg1} {pcg2} {pcg3} {pcg4}");
b63fa355644c commit to merge with changes from EN620
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 37
diff changeset
   254
		} else {
b63fa355644c commit to merge with changes from EN620
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 37
diff changeset
   255
			print(P "{pc3beam} {pcBadErrVel} {pc1or2beam} {pc4beam}");
b63fa355644c commit to merge with changes from EN620
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 37
diff changeset
   256
		}
b63fa355644c commit to merge with changes from EN620
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 37
diff changeset
   257
		print(P "$addLayout\n");
b63fa355644c commit to merge with changes from EN620
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 37
diff changeset
   258
		    
b63fa355644c commit to merge with changes from EN620
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 37
diff changeset
   259
		my($ssCorr) = defined($opt_S) ? ssCorr($dta{ENSEMBLE}[$e],$SS_salin,$SS_temp,$SS_depth) : 1;
b63fa355644c commit to merge with changes from EN620
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 37
diff changeset
   260
		for (my($b)=0; $b<$dta{N_BINS}; $b++) {
b63fa355644c commit to merge with changes from EN620
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 37
diff changeset
   261
			my(@v,$w12,$w34);
b63fa355644c commit to merge with changes from EN620
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 37
diff changeset
   262
			my($dz) = $ssCorr * ($dta{DISTANCE_TO_BIN1_CENTER} + $b*$dta{BIN_LENGTH});
b63fa355644c commit to merge with changes from EN620
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 37
diff changeset
   263
    
b63fa355644c commit to merge with changes from EN620
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 37
diff changeset
   264
			if ($beamCoords) {
b63fa355644c commit to merge with changes from EN620
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 37
diff changeset
   265
				undef($dta{ENSEMBLE}[$e]->{VELOCITY}[$b][0])
b63fa355644c commit to merge with changes from EN620
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 37
diff changeset
   266
					if (($dta{ENSEMBLE}[$e]->{PERCENT_GOOD}[$b][0] < $opt_p) || ($opt_d == 1));
b63fa355644c commit to merge with changes from EN620
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 37
diff changeset
   267
				undef($dta{ENSEMBLE}[$e]->{VELOCITY}[$b][1])
b63fa355644c commit to merge with changes from EN620
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 37
diff changeset
   268
					if (($dta{ENSEMBLE}[$e]->{PERCENT_GOOD}[$b][1] < $opt_p) || ($opt_d == 2));
b63fa355644c commit to merge with changes from EN620
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 37
diff changeset
   269
				undef($dta{ENSEMBLE}[$e]->{VELOCITY}[$b][2])
b63fa355644c commit to merge with changes from EN620
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 37
diff changeset
   270
					if (($dta{ENSEMBLE}[$e]->{PERCENT_GOOD}[$b][2] < $opt_p) || ($opt_d == 3));
b63fa355644c commit to merge with changes from EN620
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 37
diff changeset
   271
				undef($dta{ENSEMBLE}[$e]->{VELOCITY}[$b][3])
b63fa355644c commit to merge with changes from EN620
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 37
diff changeset
   272
					if (($dta{ENSEMBLE}[$e]->{PERCENT_GOOD}[$b][3] < $opt_p) || ($opt_d == 4));
b63fa355644c commit to merge with changes from EN620
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 37
diff changeset
   273
				($dummy,$w12,$dummy,$w34) =
b63fa355644c commit to merge with changes from EN620
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 37
diff changeset
   274
					velBeamToBPEarth(\%dta,$e,@{$dta{ENSEMBLE}[$e]->{VELOCITY}[$b]});
b63fa355644c commit to merge with changes from EN620
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 37
diff changeset
   275
				@v = $opt_b ? @{$dta{ENSEMBLE}[$e]->{VELOCITY}[$b]} :
b63fa355644c commit to merge with changes from EN620
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 37
diff changeset
   276
							  velBeamToEarth(\%dta,$e,@{$dta{ENSEMBLE}[$e]->{VELOCITY}[$b]});
b63fa355644c commit to merge with changes from EN620
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 37
diff changeset
   277
			} else {
b63fa355644c commit to merge with changes from EN620
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 37
diff changeset
   278
				@v = velApplyHdgBias(\%dta,$e,@{$dta{ENSEMBLE}[$e]->{VELOCITY}[$b]});
b63fa355644c commit to merge with changes from EN620
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 37
diff changeset
   279
			}
b63fa355644c commit to merge with changes from EN620
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 37
diff changeset
   280
			$v[0] *= $ssCorr if defined($v[0]);
b63fa355644c commit to merge with changes from EN620
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 37
diff changeset
   281
			$v[1] *= $ssCorr if defined($v[1]);
b63fa355644c commit to merge with changes from EN620
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 37
diff changeset
   282
			$v[2] *= $ssCorr if defined($v[2]);
b63fa355644c commit to merge with changes from EN620
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 37
diff changeset
   283
			$v[3] *= $ssCorr if defined($v[3]);
b63fa355644c commit to merge with changes from EN620
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 37
diff changeset
   284
			$w12 *= $ssCorr if defined($w12);
b63fa355644c commit to merge with changes from EN620
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 37
diff changeset
   285
			$w34 *= $ssCorr if defined($w34);
b63fa355644c commit to merge with changes from EN620
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 37
diff changeset
   286
    
b63fa355644c commit to merge with changes from EN620
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 37
diff changeset
   287
			$v[0] = nan unless defined($v[0]);		# u
b63fa355644c commit to merge with changes from EN620
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 37
diff changeset
   288
			$v[1] = nan unless defined($v[1]);		# v
b63fa355644c commit to merge with changes from EN620
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 37
diff changeset
   289
			$v[2] = nan unless defined($v[2]);		# w
b63fa355644c commit to merge with changes from EN620
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 37
diff changeset
   290
			$v[3] = nan unless defined($v[3]);		# err_vel
b63fa355644c commit to merge with changes from EN620
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 37
diff changeset
   291
			$w12 = nan unless defined($w12);		# w from beams 1&2
b63fa355644c commit to merge with changes from EN620
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 37
diff changeset
   292
			$w34 = nan unless defined($w34);		# w from beams 3&4
b63fa355644c commit to merge with changes from EN620
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 37
diff changeset
   293
b63fa355644c commit to merge with changes from EN620
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 37
diff changeset
   294
			my(@out) = (
b63fa355644c commit to merge with changes from EN620
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 37
diff changeset
   295
				$b+1,$dz,$v[0],$v[1],$v[2],$v[3],$w12,$w34,
b63fa355644c commit to merge with changes from EN620
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 37
diff changeset
   296
				@{$dta{ENSEMBLE}[$e]->{CORRELATION}[$b]},
b63fa355644c commit to merge with changes from EN620
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 37
diff changeset
   297
				@{$dta{ENSEMBLE}[$e]->{ECHO_AMPLITUDE}[$b]},
b63fa355644c commit to merge with changes from EN620
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 37
diff changeset
   298
				@{$dta{ENSEMBLE}[$e]->{PERCENT_GOOD}[$b]}
18
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 13
diff changeset
   299
			);
0
229a0d72d2ab first hg version
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
   300
			foreach my $f (@addFields) {
229a0d72d2ab first hg version
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
   301
				my($fn,$fi) = ($f =~ m{([^[]*)(\[.*)});
229a0d72d2ab first hg version
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
   302
				$fn = $f unless defined($fn);
43
b63fa355644c commit to merge with changes from EN620
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 37
diff changeset
   303
				push(@out,eval("\$dta{ENSEMBLE}[$e]->{$fn}$fi"));
b63fa355644c commit to merge with changes from EN620
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 37
diff changeset
   304
			}
b63fa355644c commit to merge with changes from EN620
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 37
diff changeset
   305
			for ($i=0; $i<19+@addFields; $i++) {
b63fa355644c commit to merge with changes from EN620
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 37
diff changeset
   306
				$out[$i] = nan unless defined($out[$i]);
0
229a0d72d2ab first hg version
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
   307
			}
43
b63fa355644c commit to merge with changes from EN620
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 37
diff changeset
   308
			print(P "@out\n");
0
229a0d72d2ab first hg version
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
   309
		}
43
b63fa355644c commit to merge with changes from EN620
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 37
diff changeset
   310
		chmod(0777&~umask,*P);
b63fa355644c commit to merge with changes from EN620
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 37
diff changeset
   311
		close(P);
b63fa355644c commit to merge with changes from EN620
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 37
diff changeset
   312
	}
0
229a0d72d2ab first hg version
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
   313
43
b63fa355644c commit to merge with changes from EN620
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 37
diff changeset
   314
} elsif (defined($opt_T)) { 									# time-average ensembles
b63fa355644c commit to merge with changes from EN620
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 37
diff changeset
   315
b63fa355644c commit to merge with changes from EN620
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 37
diff changeset
   316
	my(@tmp) = split(',',$opt_T);								# decode -T 
54
21cf468fa8e0 prior to A20
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 50
diff changeset
   317
	my($Tstart,$deltaT,$Tend,$month,$day);						# NB: $yearbase needs to be global!
43
b63fa355644c commit to merge with changes from EN620
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 37
diff changeset
   318
	if (@tmp == 3) {
b63fa355644c commit to merge with changes from EN620
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 37
diff changeset
   319
		($Tstart,$deltaT,$Tend) = @tmp;
b63fa355644c commit to merge with changes from EN620
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 37
diff changeset
   320
	} elsif (@tmp == 2) {
b63fa355644c commit to merge with changes from EN620
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 37
diff changeset
   321
		($Tstart,$deltaT) = @tmp;
54
21cf468fa8e0 prior to A20
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 50
diff changeset
   322
		($month,$day,$yearbase) = split('/',$dta{ENSEMBLE}[0]->{DATE});
21cf468fa8e0 prior to A20
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 50
diff changeset
   323
		$Tend = str2dec_time($dta{ENSEMBLE}[0]->{DATE},$dta{ENSEMBLE}[$#{$dta{ENSEMBLE}}]->{TIME},$yearbase);
43
b63fa355644c commit to merge with changes from EN620
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 37
diff changeset
   324
	} else {
54
21cf468fa8e0 prior to A20
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 50
diff changeset
   325
		($month,$day,$yearbase) = split('/',$dta{ENSEMBLE}[0]->{DATE});
21cf468fa8e0 prior to A20
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 50
diff changeset
   326
		$Tstart = str2dec_time($dta{ENSEMBLE}[0]->{DATE},$dta{ENSEMBLE}[0]->{TIME},$yearbase);
43
b63fa355644c commit to merge with changes from EN620
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 37
diff changeset
   327
		($deltaT) = @tmp;
54
21cf468fa8e0 prior to A20
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 50
diff changeset
   328
		$Tend = str2dec_time($dta{ENSEMBLE}[$#{$dta{ENSEMBLE}}]->{DATE},$dta{ENSEMBLE}[$#{$dta{ENSEMBLE}}]->{TIME},$yearbase);
43
b63fa355644c commit to merge with changes from EN620
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 37
diff changeset
   329
	}
b63fa355644c commit to merge with changes from EN620
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 37
diff changeset
   330
	$Tstart = &{&antsCompileConstExpr($')} if ($Tstart =~ m{^=});
b63fa355644c commit to merge with changes from EN620
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 37
diff changeset
   331
	$deltaT = &{&antsCompileConstExpr($')} if ($deltaT =~ m{^=});
b63fa355644c commit to merge with changes from EN620
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 37
diff changeset
   332
	$Tend	= &{&antsCompileConstExpr($')} if ($Tend   =~ m{^=});
b63fa355644c commit to merge with changes from EN620
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 37
diff changeset
   333
	$deltaT = 9e99 unless ($deltaT > 0);
b63fa355644c commit to merge with changes from EN620
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 37
diff changeset
   334
																# format string for zero-padded filenames
b63fa355644c commit to merge with changes from EN620
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 37
diff changeset
   335
	my($fnfmt) = sprintf('%%0%dd',length(sprintf('%d',($Tend-$Tstart)/$deltaT+1)));
b63fa355644c commit to merge with changes from EN620
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 37
diff changeset
   336
b63fa355644c commit to merge with changes from EN620
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 37
diff changeset
   337
	$cbin		= 1;											# current tim-bin number; used inside dumpEns
b63fa355644c commit to merge with changes from EN620
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 37
diff changeset
   338
	$max_nens	= 0;											# max number of samples
b63fa355644c commit to merge with changes from EN620
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 37
diff changeset
   339
b63fa355644c commit to merge with changes from EN620
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 37
diff changeset
   340
	sub dde($$) 												# divide allowing for zero; used inside dumpEns
b63fa355644c commit to merge with changes from EN620
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 37
diff changeset
   341
	{
b63fa355644c commit to merge with changes from EN620
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 37
diff changeset
   342
		my($sum,$n) = @_;
b63fa355644c commit to merge with changes from EN620
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 37
diff changeset
   343
		return $n ? $sum/$n : nan;
b63fa355644c commit to merge with changes from EN620
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 37
diff changeset
   344
	}
0
229a0d72d2ab first hg version
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
   345
43
b63fa355644c commit to merge with changes from EN620
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 37
diff changeset
   346
	$dumpEns = sub ($)											# time average and output when next bin is started
b63fa355644c commit to merge with changes from EN620
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 37
diff changeset
   347
	{
b63fa355644c commit to merge with changes from EN620
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 37
diff changeset
   348
		my($e) = @_;
b63fa355644c commit to merge with changes from EN620
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 37
diff changeset
   349
		my($b,$i);
b63fa355644c commit to merge with changes from EN620
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 37
diff changeset
   350
54
21cf468fa8e0 prior to A20
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 50
diff changeset
   351
		my($dn) = ($e >= 0) ? str2dec_time($dta{ENSEMBLE}[$e]->{DATE},$dta{ENSEMBLE}[$e]->{TIME},$yearbase) : undef;
43
b63fa355644c commit to merge with changes from EN620
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 37
diff changeset
   352
54
21cf468fa8e0 prior to A20
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 50
diff changeset
   353
#		print(STDERR "ens#$e at $dn (cbin = $cbin)\n");
43
b63fa355644c commit to merge with changes from EN620
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 37
diff changeset
   354
		if ($e<0 || $dn>=$Tstart+$cbin*$deltaT) {				# dump full bin
b63fa355644c commit to merge with changes from EN620
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 37
diff changeset
   355
			my($file) = sprintf("$basename.T$fnfmt",$cbin); 	# file name: <basename>.T0001
54
21cf468fa8e0 prior to A20
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 50
diff changeset
   356
#			print(STDERR "dumping average to $file...\n");
43
b63fa355644c commit to merge with changes from EN620
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 37
diff changeset
   357
b63fa355644c commit to merge with changes from EN620
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 37
diff changeset
   358
			do {												# skip empy bins
b63fa355644c commit to merge with changes from EN620
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 37
diff changeset
   359
				$cbin++;
b63fa355644c commit to merge with changes from EN620
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 37
diff changeset
   360
			} while ($dn>=$Tstart+$cbin*$deltaT);
b63fa355644c commit to merge with changes from EN620
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 37
diff changeset
   361
b63fa355644c commit to merge with changes from EN620
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 37
diff changeset
   362
			$max_nens = $a1_n[0] if ($a1_n[0] > $max_nens); 	# update max number of samples in time bin
b63fa355644c commit to merge with changes from EN620
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 37
diff changeset
   363
			if ($a1_n[0] >= $opt_i*$max_nens) { 				# write file only if sufficient samples (-i)
0
229a0d72d2ab first hg version
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
   364
			    
43
b63fa355644c commit to merge with changes from EN620
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 37
diff changeset
   365
				open(P,">$file") || die("$file: $!\n"); 		# open file and output metadata
b63fa355644c commit to merge with changes from EN620
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 37
diff changeset
   366
				print(P "#!/usr/bin/perl -S list\n");
b63fa355644c commit to merge with changes from EN620
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 37
diff changeset
   367
				print(P "#ANTS# $cmdline\n");
b63fa355644c commit to merge with changes from EN620
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 37
diff changeset
   368
				printf(P "#ANTS#PARAMS# " .
b63fa355644c commit to merge with changes from EN620
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 37
diff changeset
   369
						"PD0_file{$ARGV[0]} " .
b63fa355644c commit to merge with changes from EN620
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 37
diff changeset
   370
						"dn{%s} " .
b63fa355644c commit to merge with changes from EN620
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 37
diff changeset
   371
						"N_ensembles{%d} ensemble_range{%d,%d} " .
b63fa355644c commit to merge with changes from EN620
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 37
diff changeset
   372
						"delta-T{%g} " .
b63fa355644c commit to merge with changes from EN620
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 37
diff changeset
   373
						"soundspeed_correction{%s} " .
b63fa355644c commit to merge with changes from EN620
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 37
diff changeset
   374
						"magnetic_declination{%g} " .
b63fa355644c commit to merge with changes from EN620
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 37
diff changeset
   375
						"\n",
b63fa355644c commit to merge with changes from EN620
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 37
diff changeset
   376
							&dde($dn_s,$dn_n),
b63fa355644c commit to merge with changes from EN620
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 37
diff changeset
   377
							$a1_n[0],$feib,$leib,$deltaT,
b63fa355644c commit to merge with changes from EN620
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 37
diff changeset
   378
							(defined($opt_S) ? $opt_S : "NONE!"),
b63fa355644c commit to merge with changes from EN620
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 37
diff changeset
   379
							$opt_M
b63fa355644c commit to merge with changes from EN620
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 37
diff changeset
   380
b63fa355644c commit to merge with changes from EN620
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 37
diff changeset
   381
				);
b63fa355644c commit to merge with changes from EN620
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 37
diff changeset
   382
			    
b63fa355644c commit to merge with changes from EN620
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 37
diff changeset
   383
				print(P "#ANTS#FIELDS# " .													# Layout
b63fa355644c commit to merge with changes from EN620
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 37
diff changeset
   384
						"{bin} {dz} {u} {v} {w} {e} {w12} {w34} {corr1} {corr2} {corr3} {corr4} " .
b63fa355644c commit to merge with changes from EN620
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 37
diff changeset
   385
						"{amp1} {amp2} {amp3} {amp4} "
b63fa355644c commit to merge with changes from EN620
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 37
diff changeset
   386
				);
0
229a0d72d2ab first hg version
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
   387
				if ($beamCoords) {
43
b63fa355644c commit to merge with changes from EN620
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 37
diff changeset
   388
					print(P "{pcg1} {pcg2} {pcg3} {pcg4} ");
0
229a0d72d2ab first hg version
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
   389
				} else {
43
b63fa355644c commit to merge with changes from EN620
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 37
diff changeset
   390
					print(P "{pc3beam} {pcBadErrVel} {pc1or2beam} {pc4beam} ");
0
229a0d72d2ab first hg version
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
   391
				}
43
b63fa355644c commit to merge with changes from EN620
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 37
diff changeset
   392
				print(P "{uvw.nsamp} {e.nsamp} ");
b63fa355644c commit to merge with changes from EN620
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 37
diff changeset
   393
				print(P "$addLayout\n");
b63fa355644c commit to merge with changes from EN620
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 37
diff changeset
   394
																							# ssCorr for dz based on first ensemble in bin
b63fa355644c commit to merge with changes from EN620
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 37
diff changeset
   395
				my($ssCorr) = defined($opt_S)
b63fa355644c commit to merge with changes from EN620
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 37
diff changeset
   396
							? ssCorr($dta{ENSEMBLE}[$feib-$dta{ENSEMBLE}[0]->{NUMBER}],$SS_salin,$SS_temp,$SS_depth)
b63fa355644c commit to merge with changes from EN620
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 37
diff changeset
   397
							: 1;
b63fa355644c commit to merge with changes from EN620
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 37
diff changeset
   398
				for (my($b)=0; $b<$dta{N_BINS}; $b++) { 									# output data
b63fa355644c commit to merge with changes from EN620
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 37
diff changeset
   399
					my($dz) = $ssCorr * ($dta{DISTANCE_TO_BIN1_CENTER} + $b*$dta{BIN_LENGTH});
b63fa355644c commit to merge with changes from EN620
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 37
diff changeset
   400
					printf(P "%d %g  %g %g %g %g  %g %g  %d %d %d %d  %d %d %d %d  %d %d %d %d	%d %d",
b63fa355644c commit to merge with changes from EN620
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 37
diff changeset
   401
						$b+1,$dz,
b63fa355644c commit to merge with changes from EN620
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 37
diff changeset
   402
						&dde($v1[$b],$v1_n[$b]),&dde($v2[$b],$v2_n[$b]),&dde($v3[$b],$v3_n[$b]),&dde($v4[$b],$v4_n[$b]),
b63fa355644c commit to merge with changes from EN620
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 37
diff changeset
   403
						&dde($w12[$b],$w12_n[$b]),&dde($w34[$b],$w34_n[$b]),
b63fa355644c commit to merge with changes from EN620
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 37
diff changeset
   404
						&dde($c1[$b],$c1_n[$b]),&dde($c2[$b],$c2_n[$b]),&dde($c3[$b],$c3_n[$b]),&dde($c4[$b],$c4_n[$b]),
b63fa355644c commit to merge with changes from EN620
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 37
diff changeset
   405
						&dde($a1[$b],$a1_n[$b]),&dde($a2[$b],$a2_n[$b]),&dde($a3[$b],$a3_n[$b]),&dde($a4[$b],$a4_n[$b]),
b63fa355644c commit to merge with changes from EN620
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 37
diff changeset
   406
						&dde($p1[$b],$p1_n[$b]),&dde($p2[$b],$p2_n[$b]),&dde($p3[$b],$p3_n[$b]),&dde($p4[$b],$p4_n[$b]),
b63fa355644c commit to merge with changes from EN620
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 37
diff changeset
   407
						$v1_n[$b],$v4_n[$b]
b63fa355644c commit to merge with changes from EN620
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 37
diff changeset
   408
					);
21
0b5bbe60131c version sent to P16N
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 18
diff changeset
   409
43
b63fa355644c commit to merge with changes from EN620
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 37
diff changeset
   410
					for (my($i)=0; $i<@af; $i++) {
b63fa355644c commit to merge with changes from EN620
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 37
diff changeset
   411
						printf(P "%g ",&dde($af[$i][$b],$af_n[$i][$b]));
b63fa355644c commit to merge with changes from EN620
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 37
diff changeset
   412
					}
b63fa355644c commit to merge with changes from EN620
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 37
diff changeset
   413
					print(P "\n");
21
0b5bbe60131c version sent to P16N
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 18
diff changeset
   414
				}
43
b63fa355644c commit to merge with changes from EN620
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 37
diff changeset
   415
				chmod(0777&~umask,*P);														# activate output
b63fa355644c commit to merge with changes from EN620
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 37
diff changeset
   416
				close(P);
b63fa355644c commit to merge with changes from EN620
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 37
diff changeset
   417
			} # if -i check okay
b63fa355644c commit to merge with changes from EN620
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 37
diff changeset
   418
b63fa355644c commit to merge with changes from EN620
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 37
diff changeset
   419
			for (my($b)=0; $b<$dta{N_BINS}; $b++) { 										# reset stats	 
b63fa355644c commit to merge with changes from EN620
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 37
diff changeset
   420
				$v1[$b] = $v1_n[$b] = $v2[$b] = $v2_n[$b] = $v3[$b] = $v3_n[$b] = $v4[$b] = $v4_n[$b] = 0;
b63fa355644c commit to merge with changes from EN620
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 37
diff changeset
   421
				$w12[$b] = $w12_n[$b] = $w34[$b] = $w34_n[$b] = 0;
b63fa355644c commit to merge with changes from EN620
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 37
diff changeset
   422
				$c1[$b] = $c1_n[$b] = $c2[$b] = $c2_n[$b] = $c3[$b] = $c3_n[$b] = $c4[$b] = $c4_n[$b] = 0;							    
b63fa355644c commit to merge with changes from EN620
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 37
diff changeset
   423
				$a1[$b] = $a1_n[$b] = $a2[$b] = $a2_n[$b] = $a3[$b] = $a3_n[$b] = $a4[$b] = $a4_n[$b] = 0;
b63fa355644c commit to merge with changes from EN620
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 37
diff changeset
   424
				$p1[$b] = $p1_n[$b] = $p2[$b] = $p2_n[$b] = $p3[$b] = $p3_n[$b] = $p4[$b] = $p4_n[$b] = 0;
b63fa355644c commit to merge with changes from EN620
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 37
diff changeset
   425
				for (my($i)=0; $i<@af; $i++) {
b63fa355644c commit to merge with changes from EN620
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 37
diff changeset
   426
					$af[$i][$b] = $af_n[$i][$b] = 0;
0
229a0d72d2ab first hg version
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
   427
				}
43
b63fa355644c commit to merge with changes from EN620
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 37
diff changeset
   428
				$dn_s = $dn_n = 0;															# day number
0
229a0d72d2ab first hg version
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
   429
			}
43
b63fa355644c commit to merge with changes from EN620
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 37
diff changeset
   430
				    
b63fa355644c commit to merge with changes from EN620
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 37
diff changeset
   431
			undef($feib);																	# make sure first ensemble in bin will be updated below
b63fa355644c commit to merge with changes from EN620
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 37
diff changeset
   432
		} # if time bin is full
0
229a0d72d2ab first hg version
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
   433
43
b63fa355644c commit to merge with changes from EN620
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 37
diff changeset
   434
		$feib = $dta{ENSEMBLE}[$e]->{NUMBER} unless defined($feib); 						# update first and last ensembles in current bin
b63fa355644c commit to merge with changes from EN620
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 37
diff changeset
   435
		$leib = $dta{ENSEMBLE}[$e]->{NUMBER};
0
229a0d72d2ab first hg version
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
   436
43
b63fa355644c commit to merge with changes from EN620
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 37
diff changeset
   437
		$dn_s += $dn; $dn_n++;																# day number
b63fa355644c commit to merge with changes from EN620
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 37
diff changeset
   438
		    
b63fa355644c commit to merge with changes from EN620
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 37
diff changeset
   439
		my($ssCorr) = defined($opt_S) ? ssCorr($dta{ENSEMBLE}[$e],$SS_salin,$SS_temp,$SS_depth) : 1;
b63fa355644c commit to merge with changes from EN620
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 37
diff changeset
   440
		for (my($b)=0; $b<$dta{N_BINS}; $b++) {
b63fa355644c commit to merge with changes from EN620
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 37
diff changeset
   441
			my(@v,$this_w12,$this_w34);
b63fa355644c commit to merge with changes from EN620
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 37
diff changeset
   442
			if ($beamCoords) {																# convert to earth coordinates
b63fa355644c commit to merge with changes from EN620
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 37
diff changeset
   443
				undef($dta{ENSEMBLE}[$e]->{VELOCITY}[$b][0])
b63fa355644c commit to merge with changes from EN620
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 37
diff changeset
   444
					if (($dta{ENSEMBLE}[$e]->{PERCENT_GOOD}[$b][0] < $opt_p) || ($opt_d == 1));
b63fa355644c commit to merge with changes from EN620
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 37
diff changeset
   445
				undef($dta{ENSEMBLE}[$e]->{VELOCITY}[$b][1])
b63fa355644c commit to merge with changes from EN620
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 37
diff changeset
   446
					if (($dta{ENSEMBLE}[$e]->{PERCENT_GOOD}[$b][1] < $opt_p) || ($opt_d == 2));
b63fa355644c commit to merge with changes from EN620
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 37
diff changeset
   447
				undef($dta{ENSEMBLE}[$e]->{VELOCITY}[$b][2])
b63fa355644c commit to merge with changes from EN620
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 37
diff changeset
   448
					if (($dta{ENSEMBLE}[$e]->{PERCENT_GOOD}[$b][2] < $opt_p) || ($opt_d == 3));
b63fa355644c commit to merge with changes from EN620
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 37
diff changeset
   449
				undef($dta{ENSEMBLE}[$e]->{VELOCITY}[$b][3])
b63fa355644c commit to merge with changes from EN620
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 37
diff changeset
   450
					if (($dta{ENSEMBLE}[$e]->{PERCENT_GOOD}[$b][3] < $opt_p) || ($opt_d == 4));
b63fa355644c commit to merge with changes from EN620
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 37
diff changeset
   451
				($dummy,$this_w12,$dummy,$this_w34) =
b63fa355644c commit to merge with changes from EN620
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 37
diff changeset
   452
					velBeamToBPEarth(\%dta,$e,@{$dta{ENSEMBLE}[$e]->{VELOCITY}[$b]});
b63fa355644c commit to merge with changes from EN620
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 37
diff changeset
   453
				@v = $opt_b ? @{$dta{ENSEMBLE}[$e]->{VELOCITY}[$b]} :
b63fa355644c commit to merge with changes from EN620
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 37
diff changeset
   454
							  velBeamToEarth(\%dta,$e,@{$dta{ENSEMBLE}[$e]->{VELOCITY}[$b]});
b63fa355644c commit to merge with changes from EN620
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 37
diff changeset
   455
			} else {
b63fa355644c commit to merge with changes from EN620
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 37
diff changeset
   456
				@v = velApplyHdgBias(\%dta,$e,@{$dta{ENSEMBLE}[$e]->{VELOCITY}[$b]});
b63fa355644c commit to merge with changes from EN620
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 37
diff changeset
   457
			}
b63fa355644c commit to merge with changes from EN620
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 37
diff changeset
   458
			$v[0] *= $ssCorr if defined($v[0]); $v[1] *= $ssCorr if defined($v[1]); 		# apply sound-speed correction
b63fa355644c commit to merge with changes from EN620
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 37
diff changeset
   459
			$v[2] *= $ssCorr if defined($v[2]); $v[3] *= $ssCorr if defined($v[3]);
b63fa355644c commit to merge with changes from EN620
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 37
diff changeset
   460
			$w12  *= $ssCorr if defined($w12);	$w34  *= $ssCorr if defined($w34);
b63fa355644c commit to merge with changes from EN620
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 37
diff changeset
   461
    
b63fa355644c commit to merge with changes from EN620
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 37
diff changeset
   462
			$v1[$b]+=$v[0],$v1_n[$b]++ if defined($v[0]);									# update sums and nsamps
b63fa355644c commit to merge with changes from EN620
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 37
diff changeset
   463
			$v2[$b]+=$v[1],$v2_n[$b]++ if defined($v[1]);
b63fa355644c commit to merge with changes from EN620
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 37
diff changeset
   464
			$v3[$b]+=$v[2],$v3_n[$b]++ if defined($v[2]);
b63fa355644c commit to merge with changes from EN620
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 37
diff changeset
   465
			$v4[$b]+=$v[3],$v4_n[$b]++ if defined($v[3]);
b63fa355644c commit to merge with changes from EN620
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 37
diff changeset
   466
			$w12[$b]+=$this_w12,$w12_n[$b]++ if defined($this_w12);
b63fa355644c commit to merge with changes from EN620
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 37
diff changeset
   467
			$w34[$b]+=$this_w34,$w34_n[$b]++ if defined($this_w34);
b63fa355644c commit to merge with changes from EN620
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 37
diff changeset
   468
			$c1[$b]+=$dta{ENSEMBLE}[$e]->{CORRELATION}[$b][0],$c1_n[$b]++;
b63fa355644c commit to merge with changes from EN620
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 37
diff changeset
   469
			$c2[$b]+=$dta{ENSEMBLE}[$e]->{CORRELATION}[$b][1],$c2_n[$b]++;
b63fa355644c commit to merge with changes from EN620
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 37
diff changeset
   470
			$c3[$b]+=$dta{ENSEMBLE}[$e]->{CORRELATION}[$b][2],$c3_n[$b]++;
b63fa355644c commit to merge with changes from EN620
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 37
diff changeset
   471
			$c4[$b]+=$dta{ENSEMBLE}[$e]->{CORRELATION}[$b][3],$c4_n[$b]++;
b63fa355644c commit to merge with changes from EN620
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 37
diff changeset
   472
			$a1[$b]+=$dta{ENSEMBLE}[$e]->{ECHO_AMPLITUDE}[$b][0],$a1_n[$b]++;
b63fa355644c commit to merge with changes from EN620
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 37
diff changeset
   473
			$a2[$b]+=$dta{ENSEMBLE}[$e]->{ECHO_AMPLITUDE}[$b][1],$a2_n[$b]++;
b63fa355644c commit to merge with changes from EN620
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 37
diff changeset
   474
			$a3[$b]+=$dta{ENSEMBLE}[$e]->{ECHO_AMPLITUDE}[$b][2],$a3_n[$b]++;
b63fa355644c commit to merge with changes from EN620
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 37
diff changeset
   475
			$a4[$b]+=$dta{ENSEMBLE}[$e]->{ECHO_AMPLITUDE}[$b][3],$a4_n[$b]++;
b63fa355644c commit to merge with changes from EN620
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 37
diff changeset
   476
			$p1[$b]+=$dta{ENSEMBLE}[$e]->{PERCENT_GOOD}[$b][0],$p1_n[$b]++;
b63fa355644c commit to merge with changes from EN620
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 37
diff changeset
   477
			$p2[$b]+=$dta{ENSEMBLE}[$e]->{PERCENT_GOOD}[$b][1],$p2_n[$b]++;
b63fa355644c commit to merge with changes from EN620
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 37
diff changeset
   478
			$p3[$b]+=$dta{ENSEMBLE}[$e]->{PERCENT_GOOD}[$b][2],$p3_n[$b]++;
b63fa355644c commit to merge with changes from EN620
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 37
diff changeset
   479
			$p4[$b]+=$dta{ENSEMBLE}[$e]->{PERCENT_GOOD}[$b][3],$p4_n[$b]++;
b63fa355644c commit to merge with changes from EN620
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 37
diff changeset
   480
b63fa355644c commit to merge with changes from EN620
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 37
diff changeset
   481
			my($fi) = 0;
0
229a0d72d2ab first hg version
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
   482
			foreach my $f (@addFields) {
229a0d72d2ab first hg version
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
   483
				my($fn,$fi) = ($f =~ m{([^[]*)(\[.*)});
229a0d72d2ab first hg version
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
   484
				$fn = $f unless defined($fn);
43
b63fa355644c commit to merge with changes from EN620
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 37
diff changeset
   485
				my($val) = eval("\$dta{ENSEMBLE}[$e]->{$fn}$fi");
b63fa355644c commit to merge with changes from EN620
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 37
diff changeset
   486
				$af[$fi][$b]+=$val,$af_n[$fi][$b]++ if defined($val);
b63fa355644c commit to merge with changes from EN620
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 37
diff changeset
   487
				$fi++;
0
229a0d72d2ab first hg version
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
   488
			}
229a0d72d2ab first hg version
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
   489
		}
43
b63fa355644c commit to merge with changes from EN620
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 37
diff changeset
   490
	}
b63fa355644c commit to merge with changes from EN620
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 37
diff changeset
   491
b63fa355644c commit to merge with changes from EN620
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 37
diff changeset
   492
} else {											# neither ANTS nor ens files (DEFAULT OUTPUT)
b63fa355644c commit to merge with changes from EN620
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 37
diff changeset
   493
	if ($dta{FIXED_LEADER_BYTES} >= 53) {
b63fa355644c commit to merge with changes from EN620
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 37
diff changeset
   494
		printf("Ens # Date		 Time		 XD  Temp Headng Pitch	Roll #vv DSID ESW$addLayout\n");
b63fa355644c commit to merge with changes from EN620
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 37
diff changeset
   495
		printf("----------------------------------------------------------------------------\n");
b63fa355644c commit to merge with changes from EN620
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 37
diff changeset
   496
	} else {
b63fa355644c commit to merge with changes from EN620
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 37
diff changeset
   497
		printf("Ens # Date		 Time		 XD  Temp Headng Pitch	Roll #vv DSID$addLayout\n");
b63fa355644c commit to merge with changes from EN620
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 37
diff changeset
   498
		printf("------------------------------------------------------------------------\n");
0
229a0d72d2ab first hg version
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
   499
	}
229a0d72d2ab first hg version
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
   500
43
b63fa355644c commit to merge with changes from EN620
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 37
diff changeset
   501
	$dumpEns = sub ($)
b63fa355644c commit to merge with changes from EN620
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 37
diff changeset
   502
	{
b63fa355644c commit to merge with changes from EN620
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 37
diff changeset
   503
		my($e) = @_;
0
229a0d72d2ab first hg version
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
   504
43
b63fa355644c commit to merge with changes from EN620
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 37
diff changeset
   505
		printf('%5d %s %s %s %5.1f',
b63fa355644c commit to merge with changes from EN620
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 37
diff changeset
   506
			$dta{ENSEMBLE}[$e]->{NUMBER},
b63fa355644c commit to merge with changes from EN620
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 37
diff changeset
   507
			$dta{ENSEMBLE}[$e]->{DATE},
b63fa355644c commit to merge with changes from EN620
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 37
diff changeset
   508
			$dta{ENSEMBLE}[$e]->{TIME},
b63fa355644c commit to merge with changes from EN620
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 37
diff changeset
   509
			$dta{ENSEMBLE}[$e]->{XDUCER_FACING_UP} ? "UP" : "DN",
b63fa355644c commit to merge with changes from EN620
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 37
diff changeset
   510
			$dta{ENSEMBLE}[$e]->{TEMPERATURE},
b63fa355644c commit to merge with changes from EN620
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 37
diff changeset
   511
		);
b63fa355644c commit to merge with changes from EN620
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 37
diff changeset
   512
		if (defined($dta{ENSEMBLE}[$e]->{HEADING})) { printf(' %6.1f',$dta{ENSEMBLE}[$e]->{HEADING}); }
b63fa355644c commit to merge with changes from EN620
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 37
diff changeset
   513
		else { printf('    nan'); }
b63fa355644c commit to merge with changes from EN620
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 37
diff changeset
   514
		if (defined($dta{ENSEMBLE}[$e]->{PITCH})) { printf(' %5.1f',$dta{ENSEMBLE}[$e]->{PITCH}); }
b63fa355644c commit to merge with changes from EN620
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 37
diff changeset
   515
		else { printf('   nan'); }
b63fa355644c commit to merge with changes from EN620
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 37
diff changeset
   516
		if (defined($dta{ENSEMBLE}[$e]->{ROLL})) { printf(' %5.1f',$dta{ENSEMBLE}[$e]->{ROLL}); }
b63fa355644c commit to merge with changes from EN620
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 37
diff changeset
   517
		else { printf('   nan'); }
b63fa355644c commit to merge with changes from EN620
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 37
diff changeset
   518
		printf(' %3d 0x%02X',
b63fa355644c commit to merge with changes from EN620
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 37
diff changeset
   519
			$dta{ENSEMBLE}[$e]->{BIN1VELS},
b63fa355644c commit to merge with changes from EN620
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 37
diff changeset
   520
			$dta{ENSEMBLE}[$e]->{DATA_SOURCE_ID},
b63fa355644c commit to merge with changes from EN620
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 37
diff changeset
   521
		);
b63fa355644c commit to merge with changes from EN620
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 37
diff changeset
   522
		printf(' 0x%08X',$dta{ENSEMBLE}[$e]->{ERROR_STATUS_WORD})
b63fa355644c commit to merge with changes from EN620
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 37
diff changeset
   523
			if ($dta{FIXED_LEADER_BYTES} >= 53);
b63fa355644c commit to merge with changes from EN620
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 37
diff changeset
   524
		foreach my $f (@addFields) {
b63fa355644c commit to merge with changes from EN620
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 37
diff changeset
   525
			my($fn,$fi) = ($f =~ m{([^[]*)(\[.*)});
b63fa355644c commit to merge with changes from EN620
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 37
diff changeset
   526
			$fn = $f unless defined($fn);
b63fa355644c commit to merge with changes from EN620
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 37
diff changeset
   527
			my($v) = eval("\$dta{ENSEMBLE}[$e]->{$fn}$fi");
b63fa355644c commit to merge with changes from EN620
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 37
diff changeset
   528
			print(defined($v) ? " $v" : " nan");
b63fa355644c commit to merge with changes from EN620
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 37
diff changeset
   529
		}
b63fa355644c commit to merge with changes from EN620
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 37
diff changeset
   530
		print(" BUILT-IN-TEST ERROR")
b63fa355644c commit to merge with changes from EN620
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 37
diff changeset
   531
			if defined($dta{ENSEMBLE}[$e]->{BUILT_IN_TEST_ERROR});
b63fa355644c commit to merge with changes from EN620
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 37
diff changeset
   532
		print("\n");
b63fa355644c commit to merge with changes from EN620
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 37
diff changeset
   533
	}
b63fa355644c commit to merge with changes from EN620
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 37
diff changeset
   534
} # define output format
0
229a0d72d2ab first hg version
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
   535
43
b63fa355644c commit to merge with changes from EN620
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 37
diff changeset
   536
#----------------------------------------------------------------------
b63fa355644c commit to merge with changes from EN620
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 37
diff changeset
   537
# Loop Over Ensembles
b63fa355644c commit to merge with changes from EN620
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 37
diff changeset
   538
#----------------------------------------------------------------------
b63fa355644c commit to merge with changes from EN620
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 37
diff changeset
   539
b63fa355644c commit to merge with changes from EN620
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 37
diff changeset
   540
for ($e=0; $e<=$#{$dta{ENSEMBLE}}; $e++) {
b63fa355644c commit to merge with changes from EN620
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 37
diff changeset
   541
	 $dta{ENSEMBLE}[$e]->{BIN1VELS} =
b63fa355644c commit to merge with changes from EN620
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 37
diff changeset
   542
			defined($dta{ENSEMBLE}[$e]->{VELOCITY}[1][0]) +
b63fa355644c commit to merge with changes from EN620
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 37
diff changeset
   543
			defined($dta{ENSEMBLE}[$e]->{VELOCITY}[1][1]) +
b63fa355644c commit to merge with changes from EN620
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 37
diff changeset
   544
			defined($dta{ENSEMBLE}[$e]->{VELOCITY}[1][2]) +
b63fa355644c commit to merge with changes from EN620
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 37
diff changeset
   545
			defined($dta{ENSEMBLE}[$e]->{VELOCITY}[1][3]);
b63fa355644c commit to merge with changes from EN620
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 37
diff changeset
   546
	next if ($opt_w && $dta{ENSEMBLE}[$e]->{BIN1VELS}<3);
b63fa355644c commit to merge with changes from EN620
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 37
diff changeset
   547
b63fa355644c commit to merge with changes from EN620
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 37
diff changeset
   548
	die("BIT error in ensemble $dta{ENSEMBLE}[$e]->{NUMBER}\n")
b63fa355644c commit to merge with changes from EN620
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 37
diff changeset
   549
		if ($opt_A || $dump_ens) && defined($dta{ENSEMBLE}[$e]->{BUILT_IN_TEST_ERROR});
b63fa355644c commit to merge with changes from EN620
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 37
diff changeset
   550
	die("Low gain in ensemble #$dta{ENSEMBLE}[$e]->{NUMBER}\n")
b63fa355644c commit to merge with changes from EN620
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 37
diff changeset
   551
		if ($dta{ENSEMBLE}[$e]->{LOW_GAIN});
b63fa355644c commit to merge with changes from EN620
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 37
diff changeset
   552
b63fa355644c commit to merge with changes from EN620
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 37
diff changeset
   553
	&$dumpEns($e);
0
229a0d72d2ab first hg version
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
   554
}
229a0d72d2ab first hg version
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
   555
43
b63fa355644c commit to merge with changes from EN620
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 37
diff changeset
   556
&$dumpEns(-1) if defined($opt_T);										# dump final bin
b63fa355644c commit to merge with changes from EN620
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 37
diff changeset
   557
0
229a0d72d2ab first hg version
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
   558
exit(0);