RDI_PD0_IO.pl
author A.M. Thurnherr <athurnherr@yahoo.com>
Tue, 29 Jun 2021 12:21:32 -0400
changeset 59 4f4530fa35da
parent 58 78607e2e8add
permissions -rw-r--r--
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:
14
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
     1
#======================================================================
51
148c092b3a09 after somewhat suspicous RDI_PD0_IO.pl merge and just before adding
Andreas Thurnherr <ant@ldeo.columbia.edu>
parents: 50
diff changeset
     2
#                    R D I _ P D 0 _ I O . P L 
14
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
     3
#                    doc: Sat Jan 18 14:54:43 2003
58
78607e2e8add Nortek files
Andreas Thurnherr <ant@ldeo.columbia.edu>
parents: 57
diff changeset
     4
#                    dlm: Wed Mar 17 22:54:27 2021
14
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
     5
#                    (c) 2003 A.M. Thurnherr
58
78607e2e8add Nortek files
Andreas Thurnherr <ant@ldeo.columbia.edu>
parents: 57
diff changeset
     6
#					 uE-Info: 129 35 NIL 0 0 72 2 2 4 NIL ofnI
14
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
     7
#======================================================================
51
148c092b3a09 after somewhat suspicous RDI_PD0_IO.pl merge and just before adding
Andreas Thurnherr <ant@ldeo.columbia.edu>
parents: 50
diff changeset
     8
    
37
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 36
diff changeset
     9
# Read RDI PD0 binary data files (*.[0-9][0-9][0-9])
51
148c092b3a09 after somewhat suspicous RDI_PD0_IO.pl merge and just before adding
Andreas Thurnherr <ant@ldeo.columbia.edu>
parents: 50
diff changeset
    10
    
14
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
    11
# HISTORY:
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
    12
#	Jan 18, 2003: - incepted aboard the Aurora Australis (KAOS)
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
    13
#	Jan 19, 2003: - continued
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
    14
#	Jan 20, 2003: - replaced INTENSITY by AMPLITUDE
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
    15
#	Jan 21, 2003: - changed heading-correction field names
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
    16
#	Jan 27, 2003: - cosmetics
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
    17
#	Feb 14, 2003: - moved BT setup into header
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
    18
#	Mar 15, 2003: - moved 10th xmit voltage into header as BATTERY field
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
    19
#				  - removed again, because values are not meaningful
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
    20
#	Feb 24, 2004: - continued aboard Nathaniel B. Palmer (Anslope II)
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
    21
#				  - BUG: ensemble # was wrong on error messages
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
    22
#	Feb 26, 2004: - removed ESW_ERROR and bitmasking of ERROR_STATUS_WORD
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
    23
#	Feb 27, 2004: - removed some unused (commented-out) baggage
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
    24
#	Mar 11, 2004: - BUG: renamed ACD -> ADC
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
    25
#	Mar 18, 2004: - cosmetics
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
    26
#	Mar 30, 2004: - rewrote to speed up reading; new version takes
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
    27
#					~40% less time
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
    28
#	Sep 14, 2005: - made BT data optional (NUMBER_OF_DATA_TYPES)
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
    29
#				  - added DATA_FORMAT
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
    30
#	Sep 15, 2005: - debugged
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
    31
#				  - implement checksum to robustly find EOF
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
    32
#				  - renamed to RDI_BB_Read.pl
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
    33
#				  - BUG: had used POSIX::mktime with wrong month def!
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
    34
#	Oct 30, 2005: - added WH300 FW16.27 file format
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
    35
#				  - added DATA_FORMAT_VARIANT
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
    36
#				  - changed semantics so that first valid ensemble is
39
3bddaa514ef5 before Hamburg
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 37
diff changeset
    37
#					in E[0] (instead of E[$ensNo-1])
14
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
    38
#	Nov  8, 2005: - replaced UNIXTIME by UNIX_TIME
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
    39
#				  - added SECNO
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
    40
#	Aug 31: 2006: - added DAYNO
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
    41
#	Aug  1, 2007: - BUG: typo in monthLength()
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
    42
#	Sep 18, 2007: - modified readHeader() readDta() WBRhdr() WBRens() to
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
    43
#					conserve memory (no large arrays as retvals)
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
    44
#	Jun  4, 2008: - BUG: BB150 code was not considered on Sep 18, 2007
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
    45
#	Aug 15, 2010: - downgraded "unexpected number of data types" from error to warning
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
    46
#				  - BUG: WBRcfn had not been set correctly
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
    47
#				  - modified to allow processing files without time info
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
    48
#	May 12, 2011: - added code to report built-in-test errors
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
    49
#	Mar 19, 2013: - added support for WH600 data file (58 fixed leader bytes)
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
    50
#	Mar 20, 2013: - removed DATA_FORMAT stuff
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
    51
#				  - added support for BT data in subset of ensembles
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
    52
#	Apr 29, 2013: - changed semantics to assume EOF when unexpected number of data types
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
    53
#					are present in an ensemble
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
    54
#	Nov 25, 2013: - renamed from [RDI_BB_Read.pl]
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
    55
#				  - begin implementing WBWens()
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
    56
#				  - checkEnsemble() expunged
18
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 14
diff changeset
    57
#	Mar  3, 2014: - BUG: WBPens() did not handle incomple ensembles at EOF correctly
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 14
diff changeset
    58
#	Mar  4, 2014: - added support for DATA_SOURCE_ID
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 14
diff changeset
    59
#	Apr 24, 2014: - added debug statements to log %-GOOD values
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 14
diff changeset
    60
#	May  6, 2014: - loosened input format checks
48
cdc74ebada81 after partial adaptation to RTI files
Andreas Thurnherr <ant@ldeo.columbia.edu>
parents: 45
diff changeset
    61
#	May  7, 2014: - removed BT_PRESENT flag
21
0b5bbe60131c version sent to P16N
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 18
diff changeset
    62
#	Sep  6, 2014: - adapted WBRhdr to >7 data types
0b5bbe60131c version sent to P16N
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 18
diff changeset
    63
#	Oct 15, 2014: - implemented work-around for readData() not recognizing
0b5bbe60131c version sent to P16N
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 18
diff changeset
    64
#					incomplete ensemble at the end, which seems to imply that there is
39
3bddaa514ef5 before Hamburg
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 37
diff changeset
    65
#					a garbage final ensemble that passes the checksum test???
26
02776c168135 made RDI_BB_IO work with files containing leading garbage
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents: 24
diff changeset
    66
#	Oct  2, 2015: - added &skip_initial_trash()
28
7c7da52363c2 transport version
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 26
diff changeset
    67
#	Dec 18, 2015: - added most data types to WBPofs()
7c7da52363c2 transport version
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 26
diff changeset
    68
#				  - BUG: WBPens() requires round() for scaled values
31
b6ca27a1d19c pre Tampa
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 29
diff changeset
    69
#	Jan  9, 2016: - removed system() from writeData()
b6ca27a1d19c pre Tampa
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 29
diff changeset
    70
#				  - BUG: WBRhdr() did not set DATA_SOURCE_ID
29
aeb26e966b71 transport
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 28
diff changeset
    71
#				  - added PRODUCER
31
b6ca27a1d19c pre Tampa
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 29
diff changeset
    72
#				  - BUG: writeData() did not work correctly for ECOGIG OC26 moored data (spaces in filename?)
b6ca27a1d19c pre Tampa
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 29
diff changeset
    73
#				  - added support for patching coordinate system
32
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 31
diff changeset
    74
#	Feb 16, 2016: - added transducer orientation to WBPens()
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 31
diff changeset
    75
#				  - BUG: most WBPens() error messages used wrong file name
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 31
diff changeset
    76
#	Feb 23, 2016: - changed WBRhdr() to use 2nd ensemble (with correct data-source id)
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 31
diff changeset
    77
#	Feb 26, 2016: - added basic BT data to WBPens(); not BT_RL_* and BT_SIGNAL_STRENGTH
36
515b06dae59c version at end of ECOGIG EN586 cruise
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 32
diff changeset
    78
#	Feb 29, 2016: - LEAP DAY: actually got BT data patching to work
515b06dae59c version at end of ECOGIG EN586 cruise
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 32
diff changeset
    79
#	Jul 30, 2016: - BUG: incomplete last ensemble with garbage content was returned on reading
515b06dae59c version at end of ECOGIG EN586 cruise
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 32
diff changeset
    80
#						 WH300 data
37
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 36
diff changeset
    81
#	Aug  5, 2016: - cosmetics
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 36
diff changeset
    82
#	Aug 23, 2016: - added &clearEns()
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 36
diff changeset
    83
#	Nov  9, 2016: - made WBRhdr() return undef on "empty" files
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 36
diff changeset
    84
#	Nov 18, 2016: - BUG: ensNo was not reported correctly in format errors
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 36
diff changeset
    85
#	Nov 23, 2016: - no longer set pitch/roll/heading to undef in clearEns()
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 36
diff changeset
    86
#	Mar  7, 2016: - renamed round() to stop clashing with ANTSLIB
39
3bddaa514ef5 before Hamburg
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 37
diff changeset
    87
#	May 18, 2017: - maded readHeader() more permissive (checkFmt flag)
3bddaa514ef5 before Hamburg
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 37
diff changeset
    88
#				  - added partial support for Ocean Surveyor data
3bddaa514ef5 before Hamburg
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 37
diff changeset
    89
#	Aug  1, 2017: BUG: minor typo in ocean surveyor code (err check not done?)
3bddaa514ef5 before Hamburg
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 37
diff changeset
    90
#	Aug  7, 2017: - added LAG_LENGTH
3bddaa514ef5 before Hamburg
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 37
diff changeset
    91
#				  - added SPEED_OF_SOUND to header
3bddaa514ef5 before Hamburg
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 37
diff changeset
    92
#	Aug  8, 2017: - replaced croak() by die()
3bddaa514ef5 before Hamburg
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 37
diff changeset
    93
#				  - added actual transducer frequencies
40
6a46e9d31106 after Hamburg visit
Andreas Thurnherr <ant@ldeo.columbia.edu>
parents: 39
diff changeset
    94
#	Nov 22, 2017: - BUG: dayNo() and monthLength() clashed with [libconv.pl]
42
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 40
diff changeset
    95
#				  - added support for RDI_PD0_IO::IGNORE_Y2K_CLOCK
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 40
diff changeset
    96
#	Dec  7, 2017: - added suppress_error to readHeader()
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 40
diff changeset
    97
#	Dec 23, 2017: - BUG: could no longer read Anslope II raw files
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 40
diff changeset
    98
#				  - added support for patching ADCP time data
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 40
diff changeset
    99
#				  - added support for RDI_PD0_IO::OVERRIDE_Y2K_CLOCK
43
b63fa355644c commit to merge with changes from EN620
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 42
diff changeset
   100
#	Feb  6, 2018: - added supprort for first_ens, last_ens in readData()
b63fa355644c commit to merge with changes from EN620
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 42
diff changeset
   101
#	Feb  7, 2018: - BUG: new params were not optional
b63fa355644c commit to merge with changes from EN620
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 42
diff changeset
   102
#				  - made read routines more permissive by allowing
b63fa355644c commit to merge with changes from EN620
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 42
diff changeset
   103
#					garbage between ensembles
b63fa355644c commit to merge with changes from EN620
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 42
diff changeset
   104
#	Mar 15, 2018: - BUG: WBPens() did not work for files with garbage
b63fa355644c commit to merge with changes from EN620
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 42
diff changeset
   105
#	Mar 16, 2018: - added skipped garbage warning
b63fa355644c commit to merge with changes from EN620
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 42
diff changeset
   106
#				  - BUG: garbage skipping did not work correctly for files w/o BT
b63fa355644c commit to merge with changes from EN620
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 42
diff changeset
   107
#	Mar 20, 2018: - BUG: garbage skipping STILL did not work correctly for files w/o BT
b63fa355644c commit to merge with changes from EN620
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 42
diff changeset
   108
#	Apr  9, 2018: - added last_bin argument to readData()
b63fa355644c commit to merge with changes from EN620
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 42
diff changeset
   109
#	Apr 10, 2018: - slight improvement (parameter range check)
b63fa355644c commit to merge with changes from EN620
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 42
diff changeset
   110
#	Apr 23, 2018: - make WBRens() work (again?) with BB150 data froim 1996
b63fa355644c commit to merge with changes from EN620
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 42
diff changeset
   111
#	Apr 24, 2018: - BUG: undefined lat_bin argument to readData() did not work
b63fa355644c commit to merge with changes from EN620
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 42
diff changeset
   112
#	Apr 30, 2018: - added support for repeated ensembles
b63fa355644c commit to merge with changes from EN620
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 42
diff changeset
   113
#				  - added warning on wrong ensemble length
b63fa355644c commit to merge with changes from EN620
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 42
diff changeset
   114
#	Jun  9, 2018: - removed double \n from warnings
48
cdc74ebada81 after partial adaptation to RTI files
Andreas Thurnherr <ant@ldeo.columbia.edu>
parents: 45
diff changeset
   115
#	Jun 12, 2018: - BUG: IMPed files did not pass the garbage detection
cdc74ebada81 after partial adaptation to RTI files
Andreas Thurnherr <ant@ldeo.columbia.edu>
parents: 45
diff changeset
   116
#	Jun 13, 2019: - adapted reading routines to RTI files (free order of data types)
cdc74ebada81 after partial adaptation to RTI files
Andreas Thurnherr <ant@ldeo.columbia.edu>
parents: 45
diff changeset
   117
#				  - removed old BT_PRESENT code
50
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 49
diff changeset
   118
#	Jun 28, 2019: - renamed SECONDS to SECOND for consistency
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 49
diff changeset
   119
#	Jun 30, 2019: - added dirty flag to prevent bad PD0 patching
51
148c092b3a09 after somewhat suspicous RDI_PD0_IO.pl merge and just before adding
Andreas Thurnherr <ant@ldeo.columbia.edu>
parents: 50
diff changeset
   120
#				  - added $show_progress
148c092b3a09 after somewhat suspicous RDI_PD0_IO.pl merge and just before adding
Andreas Thurnherr <ant@ldeo.columbia.edu>
parents: 50
diff changeset
   121
#	Feb 13, 2020: - added support for $readDataProgress (to Jun 13 version)
148c092b3a09 after somewhat suspicous RDI_PD0_IO.pl merge and just before adding
Andreas Thurnherr <ant@ldeo.columbia.edu>
parents: 50
diff changeset
   122
#	Apr 12, 2020: - merged laptop and whoosher versions which both implemented
148c092b3a09 after somewhat suspicous RDI_PD0_IO.pl merge and just before adding
Andreas Thurnherr <ant@ldeo.columbia.edu>
parents: 50
diff changeset
   123
#					progreass; not sure whether this merge is successful
52
5b07a9b89aee - adapted to work with IMPed moored ADCP data
Andreas Thurnherr <ant@ldeo.columbia.edu>
parents: 51
diff changeset
   124
#				  - disabled duplicate ens detection, which turns reading into
5b07a9b89aee - adapted to work with IMPed moored ADCP data
Andreas Thurnherr <ant@ldeo.columbia.edu>
parents: 51
diff changeset
   125
#					O(N^2) process
55
540d6574caca adapted to Nortek
Andreas Thurnherr <ant@ldeo.columbia.edu>
parents: 52
diff changeset
   126
#	Apr 14, 2020: - BUG: WBPens did not work for ens# > 65535 (high byte)
540d6574caca adapted to Nortek
Andreas Thurnherr <ant@ldeo.columbia.edu>
parents: 52
diff changeset
   127
#	Mar  3, 2021: - adapted to Nortek PD0 files
58
78607e2e8add Nortek files
Andreas Thurnherr <ant@ldeo.columbia.edu>
parents: 57
diff changeset
   128
#	Mar 13, 2021: - finished adaptation to Nortek files
78607e2e8add Nortek files
Andreas Thurnherr <ant@ldeo.columbia.edu>
parents: 57
diff changeset
   129
#	Mar 17, 2021: - updated HISTORY
55
540d6574caca adapted to Nortek
Andreas Thurnherr <ant@ldeo.columbia.edu>
parents: 52
diff changeset
   130
# END OF HISTORY
51
148c092b3a09 after somewhat suspicous RDI_PD0_IO.pl merge and just before adding
Andreas Thurnherr <ant@ldeo.columbia.edu>
parents: 50
diff changeset
   131
    
14
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   132
# FIRMWARE VERSIONS:
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   133
#	It appears that different firmware versions generate different file
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   134
#	structures. Currently (Sep 2005) these routines have been tested
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   135
#	with the following firmware versions (as reported by [listHdr]):
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   136
#
39
3bddaa514ef5 before Hamburg
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 37
diff changeset
   137
#	Firmw.	DATA_FORMAT(_VARIANT)	Owner	Cruise	FIXED_LEADER_LENGTH
14
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   138
#------------------------------------------------------------
39
3bddaa514ef5 before Hamburg
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 37
diff changeset
   139
#	05.52	BB150 (1)				UH		CLIVAR/P16S 42
14
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   140
#	16.12	WH300 (1)				FSU 	A0304		53
39
3bddaa514ef5 before Hamburg
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 37
diff changeset
   141
#	16.21	WH300 (1)				LDEO	NBP0402 	53
3bddaa514ef5 before Hamburg
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 37
diff changeset
   142
#	16.27	WH300 (2)				Nash	?			59
51
148c092b3a09 after somewhat suspicous RDI_PD0_IO.pl merge and just before adding
Andreas Thurnherr <ant@ldeo.columbia.edu>
parents: 50
diff changeset
   143
    
29
aeb26e966b71 transport
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 28
diff changeset
   144
# PD0 FILE FORMAT EXTENSIONS:
aeb26e966b71 transport
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 28
diff changeset
   145
#
32
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 31
diff changeset
   146
#	- file creator encoded in DATA_SOURCE_ID
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 31
diff changeset
   147
#
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 31
diff changeset
   148
#	- first ensemble uses default RDI DATA_SOURCE_ID because the LDEO_IX
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 31
diff changeset
   149
#	  software assumes this
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 31
diff changeset
   150
#
39
3bddaa514ef5 before Hamburg
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 37
diff changeset
   151
#	- DATA_SOURCE_ID = 0x7F 					original TRDI PD0 file
29
aeb26e966b71 transport
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 28
diff changeset
   152
#
43
b63fa355644c commit to merge with changes from EN620
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 42
diff changeset
   153
#	- DATA_SOURCE_ID = 0xA0 | PATCHED_MASK		produced by IMP+LADCP, KVH+LADCP
29
aeb26e966b71 transport
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 28
diff changeset
   154
#		PATCHED_MASK & 0x04:						pitch value has been patched
aeb26e966b71 transport
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 28
diff changeset
   155
#		PATCHED_MASK & 0x02:						roll value has been patched
aeb26e966b71 transport
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 28
diff changeset
   156
#		PATCHED_MASK & 0x01:						heading value has been patched
aeb26e966b71 transport
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 28
diff changeset
   157
#			- PITCH & ROLL can be missing (0x8000 badval as in velocities)
aeb26e966b71 transport
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 28
diff changeset
   158
#			- HEADING can be missing (0xF000 badval, as 0x8000 is valid 327.68 heading)
aeb26e966b71 transport
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 28
diff changeset
   159
#
31
b6ca27a1d19c pre Tampa
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 29
diff changeset
   160
#	- DATA_SOURCE_ID = 0xE0 					produced by editPD0
51
148c092b3a09 after somewhat suspicous RDI_PD0_IO.pl merge and just before adding
Andreas Thurnherr <ant@ldeo.columbia.edu>
parents: 50
diff changeset
   161
    
14
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   162
# NOTES:
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   163
#	- RDI stores data in VAX/Intel byte order (little endian)
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   164
#	- the output data structure does not exactly mirror the file data
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   165
#	  structure; the header is not stored at all and the fixed leader
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   166
#	  data are not duplicated in every ensemble
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   167
#	- in the RDI files some fields that logically belong into the header
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   168
#	  or the fixed leader (e.g. BT_MIN_CORRELATION) appear in the 
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   169
#	  ensemble data --- these are not read on input
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   170
#	- the field names are generally unabbreviated except for
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   171
#	  BT (= Bottom Track), RL (= Reference Layer), MIN and MAX
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   172
#	- all arrays are 0-referenced, but the ensemble number is not!
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   173
#	- a list of filenames can be be passed to readData() so that
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   174
#	  files split onto several memory cards (typically .000 .001 &c)
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   175
#	  can be read --- not sure if this works, actually
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   176
#	- the RDI manuals are not entirely clear everywhere; I have made
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   177
#	  guesses in some cases, but they should not affect the main
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   178
#	  fields of interest
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   179
#	- some fields in the fixed leader are not really fixed in a LADCP
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   180
#	  setting (e.g. xducer orientation); I'v made an educated guess
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   181
#	  as to which fields to move to the ENS array
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   182
#	- all units except pressure are SI, i.e. in m and m/s
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   183
#	- I don't understand the ERROR_STATUS_WORD; here's what 3 different
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   184
#	  instruments returned:
39
3bddaa514ef5 before Hamburg
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 37
diff changeset
   185
#		0x88000100	FSU instrument during A0304 (Firmware 16.12)
14
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   186
#		0x88008180	LDEO uplooker (slave) during NBP0402 (Firmware 16.21)
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   187
#		0x00008180	LDEO downlooker (master) during NBP0402 (Firmware 16.21)
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   188
#	  According to the manual (January 2001 version) this would, for example,
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   189
#	  indicate power failures on both FSU and LDEO slave instruments...
40
6a46e9d31106 after Hamburg visit
Andreas Thurnherr <ant@ldeo.columbia.edu>
parents: 39
diff changeset
   190
#	- defining the variable "$RDI_PD0_IO::IGNORE_Y2K_CLOCK" before calling &readData()
6a46e9d31106 after Hamburg visit
Andreas Thurnherr <ant@ldeo.columbia.edu>
parents: 39
diff changeset
   191
#	  makes the code ignore the Y2K clock and use the old clock instead; this 
6a46e9d31106 after Hamburg visit
Andreas Thurnherr <ant@ldeo.columbia.edu>
parents: 39
diff changeset
   192
#	  is used for Dan Torres' KVH system
51
148c092b3a09 after somewhat suspicous RDI_PD0_IO.pl merge and just before adding
Andreas Thurnherr <ant@ldeo.columbia.edu>
parents: 50
diff changeset
   193
    
14
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   194
# &readData() returns perl obj (ref to anonymous hash) with the following
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   195
# structure:
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   196
#
18
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 14
diff changeset
   197
#	DATA_SOURCE_ID					scalar		0x7f (Workhorse, also DVL)
14
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   198
#	NUMBER_OF_DATA_TYPES			scalar		6 (no BT) or 7
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   199
#	ENSEMBLE_BYTES					scalar		?, number of bytes w/o checksum
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   200
#	HEADER_BYTES					scalar		?
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   201
#	FIXED_LEADER_BYTES				scalar		42 for BB150; 53 for WH300, 58 for WH600, 59 for WH300(Nash)
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   202
#	VARIABLE_LEADER_BYTES			scalar		?
39
3bddaa514ef5 before Hamburg
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 37
diff changeset
   203
#	VELOCITY_DATA_BYTES 			scalar		?
14
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   204
#	CORRELATION_DATA_BYTES			scalar		?
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   205
#	ECHO_INTENSITY_DATA_BYTES		scalar		?
39
3bddaa514ef5 before Hamburg
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 37
diff changeset
   206
#	PERCENT_GOOD_DATA_BYTES 		scalar		?
14
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   207
#	CPU_FW_VER						scalar		0--255
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   208
#	CPU_FW_REV						scalar		0--255
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   209
#	BEAM_FREQUENCY					scalar		75, 150, 300, 600, 1200, 2400 [kHz]
39
3bddaa514ef5 before Hamburg
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 37
diff changeset
   210
#	LAG_LENGTH						scalar		???
3bddaa514ef5 before Hamburg
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 37
diff changeset
   211
#	CONVEX_BEAM_PATTERN 			bool		undefined, 1
14
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   212
#	CONCAVE_BEAM_PATTERN			bool		undefined, 1
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   213
#	SENSOR_CONFIG					scalar		1--3
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   214
#	XDUCER_HEAD_ATTACHED			bool		undefined, 1
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   215
#	BEAM_ANGLE						scalar		15,20,30,undefined=other [deg]
39
3bddaa514ef5 before Hamburg
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 37
diff changeset
   216
#	N_BEAMS 						scalar		4--5
14
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   217
#	N_DEMODS						scalar		2--3(???),undefined=n/a
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   218
#	N_BINS							scalar		1--128
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   219
#	PINGS_PER_ENSEMBLE				scalar		0--16384
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   220
#	BIN_LENGTH						scalar		0.01--64 [m]
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   221
#	BLANKING_DISTANCE				scalar		0-99.99 [m]
39
3bddaa514ef5 before Hamburg
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 37
diff changeset
   222
#	MIN_CORRELATION 				scalar		0--255
14
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   223
#	N_CODE_REPETITIONS				scalar		0--255
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   224
#	MIN_PERCENT_GOOD				scalar		1--100 [%]
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   225
#	MAX_ERROR_VELOCITY				scalar		0--5 [m/s]
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   226
#	TIME_BETWEEN_PINGS				scalar		0--? [s]
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   227
#	BEAM_COORDINATES				bool		undefined,1
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   228
#	INSTRUMENT_COORDINATES			bool		undefined,1
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   229
#	SHIP_COORDINATES				bool		undefined,1
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   230
#	EARTH_COORDINATES				bool		undefined,1
39
3bddaa514ef5 before Hamburg
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 37
diff changeset
   231
#	PITCH_AND_ROLL_USED 			bool		undefined,1
14
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   232
#	USE_3_BEAM_ON_LOW_CORR			bool		undefined,1
39
3bddaa514ef5 before Hamburg
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 37
diff changeset
   233
#	BIN_MAPPING_ALLOWED 			bool		undefined,1
3bddaa514ef5 before Hamburg
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 37
diff changeset
   234
#	HEADING_ALIGNMENT				scalar		-179.99..180 [deg]
3bddaa514ef5 before Hamburg
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 37
diff changeset
   235
#	HEADING_BIAS					scalar		-179.99..180 [deg]
57
5a59411306ba updated for Nortek
Andreas Thurnherr <ant@ldeo.columbia.edu>
parents: 56
diff changeset
   236
#	SSPEED_CALCULATED		bool		undefined,1
5a59411306ba updated for Nortek
Andreas Thurnherr <ant@ldeo.columbia.edu>
parents: 56
diff changeset
   237
#	SSPEED_USING_PRESS 			bool		undefined,1
39
3bddaa514ef5 before Hamburg
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 37
diff changeset
   238
#	USE_COMPASS 					bool		undefined,1
14
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   239
#	USE_PITCH_SENSOR				bool		undefined,1
39
3bddaa514ef5 before Hamburg
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 37
diff changeset
   240
#	USE_ROLL_SENSOR 				bool		undefined,1
3bddaa514ef5 before Hamburg
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 37
diff changeset
   241
#	USE_CONDUCTIVITY_SENSOR 		bool		undefined,1
14
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   242
#	USE_TEMPERATURE_SENSOR			bool		undefined,1
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   243
#	SPEED_OF_SOUND_CALCULATED		bool		undefined,1
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   244
#	PRESSURE_SENSOR_AVAILABLE		bool		undefined,1
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   245
#	COMPASS_AVAILABLE				bool		undefined,1
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   246
#	PITCH_SENSOR_AVAILABLE			bool		undefined,1
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   247
#	ROLL_SENSOR_AVAILABLE			bool		undefined,1
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   248
#	CONDUCTIVITY_SENSOR_AVAILABLE	bool		undefined,1
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   249
#	TEMPERATURE_SENSOR_AVAILABLE	bool		undefined,1
39
3bddaa514ef5 before Hamburg
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 37
diff changeset
   250
#	DISTANCE_TO_BIN1_CENTER 		scalar		0--655.35 [m]
14
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   251
#	TRANSMITTED_PULSE_LENGTH		scalar		0--655.35 [m]
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   252
#	RL_FIRST_BIN					scalar		1--128
39
3bddaa514ef5 before Hamburg
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 37
diff changeset
   253
#	RL_LAST_BIN 					scalar		1--128
14
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   254
#	FALSE_TARGET_THRESHOLD			scalar		0--254, undefined=disabled
39
3bddaa514ef5 before Hamburg
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 37
diff changeset
   255
#	LOW_LATENCY_SETTING 			scalar		0--5(???)
14
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   256
#	TRANSMIT_LAG_DISTANCE			scalar		0--655.35 [m]
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   257
#	CPU_SERIAL_NUMBER				scalar		undefined, 0--65535 if WH300
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   258
#	NARROW_BANDWIDTH				bool		undefined,1 (only set if WH300)
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   259
#	WIDE_BANDWIDTH					bool		undefined,1 (only set if WH300)
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   260
#	TRANSMIT_POWER					scalar		undefined, 0--255(high) if WH300
39
3bddaa514ef5 before Hamburg
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 37
diff changeset
   261
#	TRANSMIT_POWER_HIGH 			bool		undefined,1 (only set if WH300)
14
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   262
#	BT_PINGS_PER_ENSEMBLE			scalar		0--999
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   263
#	BT_DELAY_BEFORE_REACQUIRE		scalar		0--999
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   264
#	BT_MIN_CORRELATION				scalar		0--255
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   265
#	BT_MIN_EVAL_AMPLITUDE			scalar		0--255
39
3bddaa514ef5 before Hamburg
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 37
diff changeset
   266
#	BT_MIN_PERCENT_GOOD 			scalar		0--100 [%]
3bddaa514ef5 before Hamburg
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 37
diff changeset
   267
#	BT_MODE 						scalar		4,5,6(?)
14
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   268
#	BT_MAX_ERROR_VELOCITY			scalar		0--5 [m/s], undef=not screened
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   269
#	BT_RL_MIN_SIZE					scalar		0--99.9 [m]
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   270
#	BT_RL_NEAR						scalar		0--999.9 [m]
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   271
#	BT_RL_FAR						scalar		0--999.9 [m]
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   272
#	BT_MAX_TRACKING_DEPTH			scalar		8--999.9 [m]
39
3bddaa514ef5 before Hamburg
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 37
diff changeset
   273
#	ENSEMBLE[ensemble_no-1] 		array		ensemble info
14
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   274
#		XDUCER_FACING_UP			bool		undefined, 1
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   275
#		XDUCER_FACING_DOWN			bool		undefined, 1
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   276
#		N_BEAMS_USED				scalar		3,4,5(?)
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   277
#		NUMBER						scalar		1--16777215
39
3bddaa514ef5 before Hamburg
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 37
diff changeset
   278
#		BUILT_IN_TEST_ERROR 		scalar		?,undefined=none
14
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   279
#		SPEED_OF_SOUND				scalar		1400--1600 [m/s]
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   280
#		XDUCER_DEPTH				scalar		0.1--999.9 [m]
39
3bddaa514ef5 before Hamburg
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 37
diff changeset
   281
#		HEADING 					scalar		0--359.99 [deg]    --- IMP EXTENSION: undef
18
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 14
diff changeset
   282
#		PITCH						scalar		-20.00-20.00 [deg] --- IMP EXTENSION: undef
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 14
diff changeset
   283
#		ROLL						scalar		-20.00-20.00 [deg] --- IMP EXTENSION: undef
14
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   284
#		SALINITY					scalar		0-40 [psu]
39
3bddaa514ef5 before Hamburg
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 37
diff changeset
   285
#		TEMPERATURE 				scalar		-5.00--40.00 [deg]
14
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   286
#		MIN_PRE_PING_WAIT_TIME		scalar		? [s]
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   287
#		HEADING_STDDEV				scalar		0-180 [deg]
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   288
#		PITCH_STDDEV				scalar		0.0-20.0 [deg]
39
3bddaa514ef5 before Hamburg
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 37
diff changeset
   289
#		ROLL_STDDEV 				scalar		0.0-20.0 [deg]
14
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   290
#		ADC_XMIT_CURRENT			scalar		0--255
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   291
#		ADC_XMIT_VOLTAGE			scalar		0--255
39
3bddaa514ef5 before Hamburg
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 37
diff changeset
   292
#		ADC_AMBIENT_TEMPERATURE 	scalar		0--255
14
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   293
#		ADC_PRESSURE_PLUS			scalar		0--255
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   294
#		ADC_PRESSURE_MINUS			scalar		0--255
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   295
#		ADC_ATTITUDE_TEMPERATURE	scalar		0--255
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   296
#		ADC_ATTITUDE				scalar		0--255
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   297
#		ADC_CONTAMINATION			scalar		0--255
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   298
#		ERROR_STATUS_WORD			scalar		undefined, ? (only set if WH300)
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   299
#		PRESSURE					scalar		undefined, ?-? [dbar] (only set if WH300)
39
3bddaa514ef5 before Hamburg
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 37
diff changeset
   300
#		PRESSURE_STDDEV 			scalar		undefined, ?-? [dbar] (only set if WH300)
14
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   301
#		DATE						string		MM/DD/YYYY
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   302
#		YEAR						scalar		?
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   303
#		MONTH						scalar		1--12
39
3bddaa514ef5 before Hamburg
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 37
diff changeset
   304
#		DAY 						scalar		1--31
14
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   305
#		TIME						string		HH:MM:SS.hh
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   306
#		HOUR						scalar		0--23
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   307
#		MINUTE						scalar		0--59
50
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 49
diff changeset
   308
#		SECOND	 					scalar		0--59.99
14
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   309
#		UNIX_TIME					scalar		0--?
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   310
#		SECNO						scalar		0--? (number of seconds since daystart)
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   311
#		DAYNO						double		fractional day number since start of current year (1.0 is midnight Jan 1st)
39
3bddaa514ef5 before Hamburg
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 37
diff changeset
   312
#		VELOCITY[bin][beam] 		scalars 	-32.767--32.768 [m/s], undef=bad
3bddaa514ef5 before Hamburg
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 37
diff changeset
   313
#		CORRELATION[bin][beam]		scalars 	1--255, undefined=bad
3bddaa514ef5 before Hamburg
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 37
diff changeset
   314
#		ECHO_AMPLITUDE[bin][beam]	scalars 	0--255
3bddaa514ef5 before Hamburg
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 37
diff changeset
   315
#		PERCENT_GOOD[bin][beam] 	scalars 	0--255
3bddaa514ef5 before Hamburg
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 37
diff changeset
   316
#		BT_RANGE[beam]				scalars 	tons [m]
3bddaa514ef5 before Hamburg
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 37
diff changeset
   317
#		BT_VELOCITY[beam]			scalars 	see VELOCITY
3bddaa514ef5 before Hamburg
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 37
diff changeset
   318
#		BT_CORRELATION[beam]		scalars 	see CORRELATION
3bddaa514ef5 before Hamburg
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 37
diff changeset
   319
#		BT_EVAL_AMPLITUDE[beam] 	scalars 	0--255
3bddaa514ef5 before Hamburg
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 37
diff changeset
   320
#		BT_PERCENT_GOOD[beam]		scalars 	see PERCENT_GOOD
3bddaa514ef5 before Hamburg
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 37
diff changeset
   321
#		BT_RL_VELOCITY[beam]		scalars 	see VELOCITY
3bddaa514ef5 before Hamburg
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 37
diff changeset
   322
#		BT_RL_CORRELATION[beam] 	scalars 	see CORRELATION
3bddaa514ef5 before Hamburg
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 37
diff changeset
   323
#		BT_RL_ECHO_AMPLITUDE[beam]	scalars 	see ECHO_AMPLITUDE
3bddaa514ef5 before Hamburg
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 37
diff changeset
   324
#		BT_RL_PERCENT_GOOD[beam]	scalars 	see PERCENT_GOOD
3bddaa514ef5 before Hamburg
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 37
diff changeset
   325
#		BT_SIGNAL_STRENGTH[beam]	scalars 	0--255
14
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   326
#		HIGH_GAIN					bool		1, undefined
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   327
#		LOW_GAIN					bool		1, undefined
51
148c092b3a09 after somewhat suspicous RDI_PD0_IO.pl merge and just before adding
Andreas Thurnherr <ant@ldeo.columbia.edu>
parents: 50
diff changeset
   328
    
148c092b3a09 after somewhat suspicous RDI_PD0_IO.pl merge and just before adding
Andreas Thurnherr <ant@ldeo.columbia.edu>
parents: 50
diff changeset
   329
use strict;
148c092b3a09 after somewhat suspicous RDI_PD0_IO.pl merge and just before adding
Andreas Thurnherr <ant@ldeo.columbia.edu>
parents: 50
diff changeset
   330
use Time::Local;										# timegm()
148c092b3a09 after somewhat suspicous RDI_PD0_IO.pl merge and just before adding
Andreas Thurnherr <ant@ldeo.columbia.edu>
parents: 50
diff changeset
   331
148c092b3a09 after somewhat suspicous RDI_PD0_IO.pl merge and just before adding
Andreas Thurnherr <ant@ldeo.columbia.edu>
parents: 50
diff changeset
   332
$RDI_PD0_IO::show_progress = 0;							# when set, print . every 1000 ens read
148c092b3a09 after somewhat suspicous RDI_PD0_IO.pl merge and just before adding
Andreas Thurnherr <ant@ldeo.columbia.edu>
parents: 50
diff changeset
   333
    
14
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   334
#----------------------------------------------------------------------
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   335
# Time Conversion Subroutines
40
6a46e9d31106 after Hamburg visit
Andreas Thurnherr <ant@ldeo.columbia.edu>
parents: 39
diff changeset
   336
#	- prepended with _ to avoid conflicts with [libconv.pl]
14
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   337
#----------------------------------------------------------------------
51
148c092b3a09 after somewhat suspicous RDI_PD0_IO.pl merge and just before adding
Andreas Thurnherr <ant@ldeo.columbia.edu>
parents: 50
diff changeset
   338
    
148c092b3a09 after somewhat suspicous RDI_PD0_IO.pl merge and just before adding
Andreas Thurnherr <ant@ldeo.columbia.edu>
parents: 50
diff changeset
   339
sub _monthLength($$)									# of days in month
148c092b3a09 after somewhat suspicous RDI_PD0_IO.pl merge and just before adding
Andreas Thurnherr <ant@ldeo.columbia.edu>
parents: 50
diff changeset
   340
{
148c092b3a09 after somewhat suspicous RDI_PD0_IO.pl merge and just before adding
Andreas Thurnherr <ant@ldeo.columbia.edu>
parents: 50
diff changeset
   341
	my($Y,$M) = @_;
148c092b3a09 after somewhat suspicous RDI_PD0_IO.pl merge and just before adding
Andreas Thurnherr <ant@ldeo.columbia.edu>
parents: 50
diff changeset
   342
148c092b3a09 after somewhat suspicous RDI_PD0_IO.pl merge and just before adding
Andreas Thurnherr <ant@ldeo.columbia.edu>
parents: 50
diff changeset
   343
	return 31 if ($M==1 || $M==3 || $M==5 || $M==7 ||
148c092b3a09 after somewhat suspicous RDI_PD0_IO.pl merge and just before adding
Andreas Thurnherr <ant@ldeo.columbia.edu>
parents: 50
diff changeset
   344
				  $M==8 || $M==10 || $M==12);
148c092b3a09 after somewhat suspicous RDI_PD0_IO.pl merge and just before adding
Andreas Thurnherr <ant@ldeo.columbia.edu>
parents: 50
diff changeset
   345
	return 30 if ($M==4 || $M==6 || $M==9 || $M==11);
148c092b3a09 after somewhat suspicous RDI_PD0_IO.pl merge and just before adding
Andreas Thurnherr <ant@ldeo.columbia.edu>
parents: 50
diff changeset
   346
	return 28 if ($Y%4 != 0);
148c092b3a09 after somewhat suspicous RDI_PD0_IO.pl merge and just before adding
Andreas Thurnherr <ant@ldeo.columbia.edu>
parents: 50
diff changeset
   347
	return 29 if ($Y%100 != 0);
148c092b3a09 after somewhat suspicous RDI_PD0_IO.pl merge and just before adding
Andreas Thurnherr <ant@ldeo.columbia.edu>
parents: 50
diff changeset
   348
	return 28 if ($Y%400 > 0);
148c092b3a09 after somewhat suspicous RDI_PD0_IO.pl merge and just before adding
Andreas Thurnherr <ant@ldeo.columbia.edu>
parents: 50
diff changeset
   349
	return 29;
148c092b3a09 after somewhat suspicous RDI_PD0_IO.pl merge and just before adding
Andreas Thurnherr <ant@ldeo.columbia.edu>
parents: 50
diff changeset
   350
}
148c092b3a09 after somewhat suspicous RDI_PD0_IO.pl merge and just before adding
Andreas Thurnherr <ant@ldeo.columbia.edu>
parents: 50
diff changeset
   351
148c092b3a09 after somewhat suspicous RDI_PD0_IO.pl merge and just before adding
Andreas Thurnherr <ant@ldeo.columbia.edu>
parents: 50
diff changeset
   352
{ my($epoch,$lM,$lD,$lY,$ldn);							# static scope
148c092b3a09 after somewhat suspicous RDI_PD0_IO.pl merge and just before adding
Andreas Thurnherr <ant@ldeo.columbia.edu>
parents: 50
diff changeset
   353
148c092b3a09 after somewhat suspicous RDI_PD0_IO.pl merge and just before adding
Andreas Thurnherr <ant@ldeo.columbia.edu>
parents: 50
diff changeset
   354
  sub _dayNo($$$$$$)
148c092b3a09 after somewhat suspicous RDI_PD0_IO.pl merge and just before adding
Andreas Thurnherr <ant@ldeo.columbia.edu>
parents: 50
diff changeset
   355
  {
148c092b3a09 after somewhat suspicous RDI_PD0_IO.pl merge and just before adding
Andreas Thurnherr <ant@ldeo.columbia.edu>
parents: 50
diff changeset
   356
	  my($Y,$M,$D,$h,$m,$s) = @_;
148c092b3a09 after somewhat suspicous RDI_PD0_IO.pl merge and just before adding
Andreas Thurnherr <ant@ldeo.columbia.edu>
parents: 50
diff changeset
   357
	  my($dn);
148c092b3a09 after somewhat suspicous RDI_PD0_IO.pl merge and just before adding
Andreas Thurnherr <ant@ldeo.columbia.edu>
parents: 50
diff changeset
   358
  
148c092b3a09 after somewhat suspicous RDI_PD0_IO.pl merge and just before adding
Andreas Thurnherr <ant@ldeo.columbia.edu>
parents: 50
diff changeset
   359
	  if ($Y==$lY && $M==$lM && $D==$lD) {				# same day as last samp
148c092b3a09 after somewhat suspicous RDI_PD0_IO.pl merge and just before adding
Andreas Thurnherr <ant@ldeo.columbia.edu>
parents: 50
diff changeset
   360
		  $dn = $ldn;
148c092b3a09 after somewhat suspicous RDI_PD0_IO.pl merge and just before adding
Andreas Thurnherr <ant@ldeo.columbia.edu>
parents: 50
diff changeset
   361
	  } else {											# new day
148c092b3a09 after somewhat suspicous RDI_PD0_IO.pl merge and just before adding
Andreas Thurnherr <ant@ldeo.columbia.edu>
parents: 50
diff changeset
   362
		  $epoch = $Y unless defined($epoch);			# 1st call
148c092b3a09 after somewhat suspicous RDI_PD0_IO.pl merge and just before adding
Andreas Thurnherr <ant@ldeo.columbia.edu>
parents: 50
diff changeset
   363
		  $lY = $Y; $lM = $M; $lD = $D; 				# store
148c092b3a09 after somewhat suspicous RDI_PD0_IO.pl merge and just before adding
Andreas Thurnherr <ant@ldeo.columbia.edu>
parents: 50
diff changeset
   364
  
148c092b3a09 after somewhat suspicous RDI_PD0_IO.pl merge and just before adding
Andreas Thurnherr <ant@ldeo.columbia.edu>
parents: 50
diff changeset
   365
		  for ($dn=0,my($cY)=$epoch; $cY<$Y; $cY++) {	# multiple years
148c092b3a09 after somewhat suspicous RDI_PD0_IO.pl merge and just before adding
Andreas Thurnherr <ant@ldeo.columbia.edu>
parents: 50
diff changeset
   366
			  $dn += 337 + &_monthLength($Y,$M);
14
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   367
		  }
51
148c092b3a09 after somewhat suspicous RDI_PD0_IO.pl merge and just before adding
Andreas Thurnherr <ant@ldeo.columbia.edu>
parents: 50
diff changeset
   368
  
148c092b3a09 after somewhat suspicous RDI_PD0_IO.pl merge and just before adding
Andreas Thurnherr <ant@ldeo.columbia.edu>
parents: 50
diff changeset
   369
		  $dn += $D;									# day in month
148c092b3a09 after somewhat suspicous RDI_PD0_IO.pl merge and just before adding
Andreas Thurnherr <ant@ldeo.columbia.edu>
parents: 50
diff changeset
   370
		  while (--$M > 0) {							# preceding months
148c092b3a09 after somewhat suspicous RDI_PD0_IO.pl merge and just before adding
Andreas Thurnherr <ant@ldeo.columbia.edu>
parents: 50
diff changeset
   371
			  $dn += &_monthLength($Y,$M);
148c092b3a09 after somewhat suspicous RDI_PD0_IO.pl merge and just before adding
Andreas Thurnherr <ant@ldeo.columbia.edu>
parents: 50
diff changeset
   372
		  }
148c092b3a09 after somewhat suspicous RDI_PD0_IO.pl merge and just before adding
Andreas Thurnherr <ant@ldeo.columbia.edu>
parents: 50
diff changeset
   373
148c092b3a09 after somewhat suspicous RDI_PD0_IO.pl merge and just before adding
Andreas Thurnherr <ant@ldeo.columbia.edu>
parents: 50
diff changeset
   374
		  $ldn = $dn;									# store
14
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   375
	  }
51
148c092b3a09 after somewhat suspicous RDI_PD0_IO.pl merge and just before adding
Andreas Thurnherr <ant@ldeo.columbia.edu>
parents: 50
diff changeset
   376
	  return $dn + $h/24 + $m/24/60 + $s/24/3600;
148c092b3a09 after somewhat suspicous RDI_PD0_IO.pl merge and just before adding
Andreas Thurnherr <ant@ldeo.columbia.edu>
parents: 50
diff changeset
   377
  }
148c092b3a09 after somewhat suspicous RDI_PD0_IO.pl merge and just before adding
Andreas Thurnherr <ant@ldeo.columbia.edu>
parents: 50
diff changeset
   378
148c092b3a09 after somewhat suspicous RDI_PD0_IO.pl merge and just before adding
Andreas Thurnherr <ant@ldeo.columbia.edu>
parents: 50
diff changeset
   379
} # static scope
148c092b3a09 after somewhat suspicous RDI_PD0_IO.pl merge and just before adding
Andreas Thurnherr <ant@ldeo.columbia.edu>
parents: 50
diff changeset
   380
14
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   381
#----------------------------------------------------------------------
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   382
# Read Data
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   383
#----------------------------------------------------------------------
51
148c092b3a09 after somewhat suspicous RDI_PD0_IO.pl merge and just before adding
Andreas Thurnherr <ant@ldeo.columbia.edu>
parents: 50
diff changeset
   384
148c092b3a09 after somewhat suspicous RDI_PD0_IO.pl merge and just before adding
Andreas Thurnherr <ant@ldeo.columbia.edu>
parents: 50
diff changeset
   385
my($WBRcfn,$WBPcfn);									# current file names for reading/patching
148c092b3a09 after somewhat suspicous RDI_PD0_IO.pl merge and just before adding
Andreas Thurnherr <ant@ldeo.columbia.edu>
parents: 50
diff changeset
   386
my($BIT_errors) = 0;									# built-in-test errors
148c092b3a09 after somewhat suspicous RDI_PD0_IO.pl merge and just before adding
Andreas Thurnherr <ant@ldeo.columbia.edu>
parents: 50
diff changeset
   387
148c092b3a09 after somewhat suspicous RDI_PD0_IO.pl merge and just before adding
Andreas Thurnherr <ant@ldeo.columbia.edu>
parents: 50
diff changeset
   388
my($FmtErr) = "%s: illegal %s Id 0x%04x at ensemble %d";
148c092b3a09 after somewhat suspicous RDI_PD0_IO.pl merge and just before adding
Andreas Thurnherr <ant@ldeo.columbia.edu>
parents: 50
diff changeset
   389
    
14
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   390
#----------------------------------------------------------------------
43
b63fa355644c commit to merge with changes from EN620
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 42
diff changeset
   391
# skip to next valid start of ensemble (skip over garbage)
26
02776c168135 made RDI_BB_IO work with files containing leading garbage
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents: 24
diff changeset
   392
#----------------------------------------------------------------------
51
148c092b3a09 after somewhat suspicous RDI_PD0_IO.pl merge and just before adding
Andreas Thurnherr <ant@ldeo.columbia.edu>
parents: 50
diff changeset
   393
    
43
b63fa355644c commit to merge with changes from EN620
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 42
diff changeset
   394
sub goto_next_ens(@)
b63fa355644c commit to merge with changes from EN620
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 42
diff changeset
   395
{
b63fa355644c commit to merge with changes from EN620
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 42
diff changeset
   396
	my($fh,$return_skipped) = @_;							# if return_skipped not set, return file pos
b63fa355644c commit to merge with changes from EN620
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 42
diff changeset
   397
	my($buf,$dta);
b63fa355644c commit to merge with changes from EN620
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 42
diff changeset
   398
b63fa355644c commit to merge with changes from EN620
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 42
diff changeset
   399
	my($found) = 0; 										# zero consecutive 0x7f found
b63fa355644c commit to merge with changes from EN620
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 42
diff changeset
   400
	my($skipped) = 0; my($garbage_start);
b63fa355644c commit to merge with changes from EN620
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 42
diff changeset
   401
	while ($found < 2) {
b63fa355644c commit to merge with changes from EN620
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 42
diff changeset
   402
		sysread($fh,$buf,1) == 1 || last; 
b63fa355644c commit to merge with changes from EN620
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 42
diff changeset
   403
		($dta) = unpack('C',$buf);
b63fa355644c commit to merge with changes from EN620
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 42
diff changeset
   404
		if ($dta == 0x7f) {
b63fa355644c commit to merge with changes from EN620
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 42
diff changeset
   405
			$found++;
b63fa355644c commit to merge with changes from EN620
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 42
diff changeset
   406
		} elsif ($found==1 &&
51
148c092b3a09 after somewhat suspicous RDI_PD0_IO.pl merge and just before adding
Andreas Thurnherr <ant@ldeo.columbia.edu>
parents: 50
diff changeset
   407
					($dta==0xE0 ||									# from editPD0
43
b63fa355644c commit to merge with changes from EN620
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 42
diff changeset
   408
					 (($dta&0xF0)==0xA0 && ($dta&0x0F)<8))) {		# from IMP+LADCP or KVH+LADCP
b63fa355644c commit to merge with changes from EN620
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 42
diff changeset
   409
			$found++;
b63fa355644c commit to merge with changes from EN620
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 42
diff changeset
   410
		} elsif ($found == 0) {
b63fa355644c commit to merge with changes from EN620
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 42
diff changeset
   411
			$garbage_start = sysseek($fh,0,1)-1 unless defined($garbage_start);
b63fa355644c commit to merge with changes from EN620
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 42
diff changeset
   412
			$skipped++;
b63fa355644c commit to merge with changes from EN620
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 42
diff changeset
   413
		} else {											# here, found == 1 but 2nd byte was not found
b63fa355644c commit to merge with changes from EN620
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 42
diff changeset
   414
			$garbage_start = sysseek($fh,0,1)-$found unless defined($garbage_start);
b63fa355644c commit to merge with changes from EN620
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 42
diff changeset
   415
			$skipped += $found;
b63fa355644c commit to merge with changes from EN620
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 42
diff changeset
   416
			$found = 0;
b63fa355644c commit to merge with changes from EN620
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 42
diff changeset
   417
		}
b63fa355644c commit to merge with changes from EN620
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 42
diff changeset
   418
	}
b63fa355644c commit to merge with changes from EN620
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 42
diff changeset
   419
	my($fpos) = ($found < 2) ? undef : sysseek($fh,-2,1);
b63fa355644c commit to merge with changes from EN620
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 42
diff changeset
   420
	return $skipped if ($return_skipped);
51
148c092b3a09 after somewhat suspicous RDI_PD0_IO.pl merge and just before adding
Andreas Thurnherr <ant@ldeo.columbia.edu>
parents: 50
diff changeset
   421
    
43
b63fa355644c commit to merge with changes from EN620
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 42
diff changeset
   422
	if ($skipped) {
b63fa355644c commit to merge with changes from EN620
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 42
diff changeset
   423
		if (eof($fh)) {
b63fa355644c commit to merge with changes from EN620
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 42
diff changeset
   424
#				04/18/18: disabled the following line of code because it is very common at
b63fa355644c commit to merge with changes from EN620
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 42
diff changeset
   425
#						  least with the older RDI instruments I am looking at in the context
b63fa355644c commit to merge with changes from EN620
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 42
diff changeset
   426
#						  of the SR1b repeat section analysis
b63fa355644c commit to merge with changes from EN620
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 42
diff changeset
   427
#			print(STDERR "WARNING (RDI_PD0_IO): PD0 file ends with $skipped garbage bytes\n");
b63fa355644c commit to merge with changes from EN620
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 42
diff changeset
   428
		} elsif ($garbage_start == 0) {
b63fa355644c commit to merge with changes from EN620
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 42
diff changeset
   429
			print(STDERR "WARNING (RDI_PD0_IO): PD0 file starts with $skipped garbage bytes\n");
b63fa355644c commit to merge with changes from EN620
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 42
diff changeset
   430
		} else {
b63fa355644c commit to merge with changes from EN620
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 42
diff changeset
   431
			print(STDERR "WARNING (RDI_PD0_IO): $skipped garbage bytes in PD0 file beginning at byte $garbage_start\n");
26
02776c168135 made RDI_BB_IO work with files containing leading garbage
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents: 24
diff changeset
   432
		}
02776c168135 made RDI_BB_IO work with files containing leading garbage
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents: 24
diff changeset
   433
	}
51
148c092b3a09 after somewhat suspicous RDI_PD0_IO.pl merge and just before adding
Andreas Thurnherr <ant@ldeo.columbia.edu>
parents: 50
diff changeset
   434
    
43
b63fa355644c commit to merge with changes from EN620
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 42
diff changeset
   435
	return $fpos;
b63fa355644c commit to merge with changes from EN620
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 42
diff changeset
   436
}
51
148c092b3a09 after somewhat suspicous RDI_PD0_IO.pl merge and just before adding
Andreas Thurnherr <ant@ldeo.columbia.edu>
parents: 50
diff changeset
   437
    
26
02776c168135 made RDI_BB_IO work with files containing leading garbage
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents: 24
diff changeset
   438
#----------------------------------------------------------------------
14
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   439
# readHeader(file_name,^dta) WBRhdr(^data)
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   440
#	- read header data
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   441
#	- also includes some data from 1st ens
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   442
#----------------------------------------------------------------------
51
148c092b3a09 after somewhat suspicous RDI_PD0_IO.pl merge and just before adding
Andreas Thurnherr <ant@ldeo.columbia.edu>
parents: 50
diff changeset
   443
    
14
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   444
sub readHeader(@)
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   445
{
42
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 40
diff changeset
   446
	my($fn,$dta,$suppress_error) = @_;
14
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   447
	$WBRcfn = $fn;
39
3bddaa514ef5 before Hamburg
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 37
diff changeset
   448
	open(WBRF,$WBRcfn) || die("$WBRcfn: $!");
42
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 40
diff changeset
   449
	if (WBRhdr($dta)) {
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 40
diff changeset
   450
		return 1;
51
148c092b3a09 after somewhat suspicous RDI_PD0_IO.pl merge and just before adding
Andreas Thurnherr <ant@ldeo.columbia.edu>
parents: 50
diff changeset
   451
	} elsif ($suppress_error) {
42
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 40
diff changeset
   452
		return undef;
51
148c092b3a09 after somewhat suspicous RDI_PD0_IO.pl merge and just before adding
Andreas Thurnherr <ant@ldeo.columbia.edu>
parents: 50
diff changeset
   453
	} else {
42
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 40
diff changeset
   454
		die("$WBRcfn: Insufficient data\n");
51
148c092b3a09 after somewhat suspicous RDI_PD0_IO.pl merge and just before adding
Andreas Thurnherr <ant@ldeo.columbia.edu>
parents: 50
diff changeset
   455
	}
14
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   456
}
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   457
48
cdc74ebada81 after partial adaptation to RTI files
Andreas Thurnherr <ant@ldeo.columbia.edu>
parents: 45
diff changeset
   458
sub WBRhdr($)
14
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   459
{
48
cdc74ebada81 after partial adaptation to RTI files
Andreas Thurnherr <ant@ldeo.columbia.edu>
parents: 45
diff changeset
   460
	my($dta) = @_;
56
82384f531dba improvements for Nortek
Andreas Thurnherr <ant@ldeo.columbia.edu>
parents: 55
diff changeset
   461
	my($hid,$did,$B,$W,$i,$dummy);
82384f531dba improvements for Nortek
Andreas Thurnherr <ant@ldeo.columbia.edu>
parents: 55
diff changeset
   462
	local our($ndt,$buf,$id,$start_ens,@WBRofs);
14
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   463
	my($B1,$B2,$B3,$B4,$B5,$B6,$B7,$W1,$W2,$W3,$W4,$W5);
39
3bddaa514ef5 before Hamburg
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 37
diff changeset
   464
    
14
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   465
	#--------------------
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   466
	# HEADER
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   467
	#--------------------
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   468
43
b63fa355644c commit to merge with changes from EN620
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 42
diff changeset
   469
	my($skipped) = goto_next_ens(\*WBRF,1);	
50
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 49
diff changeset
   470
	if ($skipped > 0) {
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 49
diff changeset
   471
		$RDI_PD0_IO::File_Dirty = 1;
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 49
diff changeset
   472
	   	printf(STDERR "WARNING: %d bytes of initial garbage\n",$skipped);
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 49
diff changeset
   473
	}
43
b63fa355644c commit to merge with changes from EN620
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 42
diff changeset
   474
	
37
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 36
diff changeset
   475
	sysread(WBRF,$buf,6) == 6 || return undef;
32
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 31
diff changeset
   476
	($hid,$did,$dta->{ENSEMBLE_BYTES},$dummy,$dta->{NUMBER_OF_DATA_TYPES})
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 31
diff changeset
   477
		= unpack('CCvCC',$buf);
36
515b06dae59c version at end of ECOGIG EN586 cruise
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 32
diff changeset
   478
	$hid == 0x7f || die(sprintf($FmtErr,$WBRcfn,"Header (hid)",$hid,0));
515b06dae59c version at end of ECOGIG EN586 cruise
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 32
diff changeset
   479
	$did == 0x7f || die(sprintf($FmtErr,$WBRcfn,"Header (did)",$did,0));
56
82384f531dba improvements for Nortek
Andreas Thurnherr <ant@ldeo.columbia.edu>
parents: 55
diff changeset
   480
	$ndt = $dta->{NUMBER_OF_DATA_TYPES};
32
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 31
diff changeset
   481
37
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 36
diff changeset
   482
	$start_ens = sysseek(WBRF,$dta->{ENSEMBLE_BYTES}-6+2,1) || return undef;
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 36
diff changeset
   483
	sysread(WBRF,$buf,6) == 6 || return undef;
14
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   484
	($hid,$did,$dta->{ENSEMBLE_BYTES},$dummy,$dta->{NUMBER_OF_DATA_TYPES})
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   485
		= unpack('CCvCC',$buf);
36
515b06dae59c version at end of ECOGIG EN586 cruise
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 32
diff changeset
   486
	$hid == 0x7f || die(sprintf($FmtErr,$WBRcfn,"Header (hid2)",$hid,0));
29
aeb26e966b71 transport
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 28
diff changeset
   487
	$dta->{DATA_SOURCE_ID} = $did;
aeb26e966b71 transport
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 28
diff changeset
   488
	if ($did == 0x7f) {
57
5a59411306ba updated for Nortek
Andreas Thurnherr <ant@ldeo.columbia.edu>
parents: 56
diff changeset
   489
		$dta->{PRODUCER} = 'TRDI or Nortek ADCP';
31
b6ca27a1d19c pre Tampa
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 29
diff changeset
   490
	} elsif (($did&0xF0) == 0xA0) {
b6ca27a1d19c pre Tampa
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 29
diff changeset
   491
		$dta->{PRODUCER} = 'IMP+LADCP (Thurnherr software)';
b6ca27a1d19c pre Tampa
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 29
diff changeset
   492
	} elsif (($did&0xF0) == 0xE0) {
b6ca27a1d19c pre Tampa
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 29
diff changeset
   493
		$dta->{PRODUCER} = 'editPD0 (Thurnherr software)';
29
aeb26e966b71 transport
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 28
diff changeset
   494
	} else {
31
b6ca27a1d19c pre Tampa
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 29
diff changeset
   495
		$dta->{PRODUCER} = sprintf('unknown (0x%02X)');
29
aeb26e966b71 transport
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 28
diff changeset
   496
	}
aeb26e966b71 transport
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 28
diff changeset
   497
14
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   498
	sysread(WBRF,$buf,2*$dta->{NUMBER_OF_DATA_TYPES})
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   499
		== 2*$dta->{NUMBER_OF_DATA_TYPES}
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   500
			|| die("$WBRcfn: $!");
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   501
	@WBRofs = unpack("v$dta->{NUMBER_OF_DATA_TYPES}",$buf);
56
82384f531dba improvements for Nortek
Andreas Thurnherr <ant@ldeo.columbia.edu>
parents: 55
diff changeset
   502
14
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   503
#	for ($i=0; $i<$dta->{NUMBER_OF_DATA_TYPES}; $i++) {
56
82384f531dba improvements for Nortek
Andreas Thurnherr <ant@ldeo.columbia.edu>
parents: 55
diff changeset
   504
#		printf(STDERR "WBRofs[$i] = %d\n",$WBRofs[$i]);
14
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   505
#	}
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   506
39
3bddaa514ef5 before Hamburg
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 37
diff changeset
   507
	$dta->{HEADER_BYTES}					= $WBRofs[0];
3bddaa514ef5 before Hamburg
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 37
diff changeset
   508
	$dta->{FIXED_LEADER_BYTES}				= $WBRofs[1] - $WBRofs[0];
3bddaa514ef5 before Hamburg
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 37
diff changeset
   509
	$dta->{VARIABLE_LEADER_BYTES}			= $WBRofs[2] - $WBRofs[1];
3bddaa514ef5 before Hamburg
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 37
diff changeset
   510
3bddaa514ef5 before Hamburg
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 37
diff changeset
   511
	if ($dta->{FIXED_LEADER_BYTES} == 42) { 			# Eric Firing's old instrument I used in 2004
3bddaa514ef5 before Hamburg
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 37
diff changeset
   512
		$dta->{INSTRUMENT_TYPE} = 'BB150';
3bddaa514ef5 before Hamburg
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 37
diff changeset
   513
	} elsif ($dta->{FIXED_LEADER_BYTES} == 53) {		# old firmware: no serial numbers
3bddaa514ef5 before Hamburg
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 37
diff changeset
   514
		$dta->{INSTRUMENT_TYPE} = 'Workhorse';  
3bddaa514ef5 before Hamburg
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 37
diff changeset
   515
	} elsif ($dta->{FIXED_LEADER_BYTES} == 59) {		# new firmware: with serial numbers
57
5a59411306ba updated for Nortek
Andreas Thurnherr <ant@ldeo.columbia.edu>
parents: 56
diff changeset
   516
		$dta->{INSTRUMENT_TYPE} = 'Workhorse or Signature';
39
3bddaa514ef5 before Hamburg
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 37
diff changeset
   517
	} elsif ($dta->{FIXED_LEADER_BYTES} == 58) {		# DVL
3bddaa514ef5 before Hamburg
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 37
diff changeset
   518
		$dta->{INSTRUMENT_TYPE} = 'Explorer';
3bddaa514ef5 before Hamburg
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 37
diff changeset
   519
	} elsif ($dta->{FIXED_LEADER_BYTES} == 60) {		# OS75
3bddaa514ef5 before Hamburg
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 37
diff changeset
   520
		$dta->{INSTRUMENT_TYPE} = 'Ocean Surveyor';
51
148c092b3a09 after somewhat suspicous RDI_PD0_IO.pl merge and just before adding
Andreas Thurnherr <ant@ldeo.columbia.edu>
parents: 50
diff changeset
   521
	} else {
39
3bddaa514ef5 before Hamburg
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 37
diff changeset
   522
		$dta->{INSTRUMENT_TYPE} = 'unknown';
51
148c092b3a09 after somewhat suspicous RDI_PD0_IO.pl merge and just before adding
Andreas Thurnherr <ant@ldeo.columbia.edu>
parents: 50
diff changeset
   523
	}
39
3bddaa514ef5 before Hamburg
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 37
diff changeset
   524
56
82384f531dba improvements for Nortek
Andreas Thurnherr <ant@ldeo.columbia.edu>
parents: 55
diff changeset
   525
	my($BT_dt) = WBRdtaIndex(0x0600); 
82384f531dba improvements for Nortek
Andreas Thurnherr <ant@ldeo.columbia.edu>
parents: 55
diff changeset
   526
	$dta->{BT_PRESENT} = defined($BT_dt);
82384f531dba improvements for Nortek
Andreas Thurnherr <ant@ldeo.columbia.edu>
parents: 55
diff changeset
   527
	@{$dta->{DATA_TYPES}} = WBRdtaTypes();
82384f531dba improvements for Nortek
Andreas Thurnherr <ant@ldeo.columbia.edu>
parents: 55
diff changeset
   528
39
3bddaa514ef5 before Hamburg
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 37
diff changeset
   529
	#--------------------------------
3bddaa514ef5 before Hamburg
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 37
diff changeset
   530
	# Variable Leader: SPEED_OF_SOUND
3bddaa514ef5 before Hamburg
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 37
diff changeset
   531
	#--------------------------------
14
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   532
26
02776c168135 made RDI_BB_IO work with files containing leading garbage
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents: 24
diff changeset
   533
	sysseek(WBRF,$start_ens+$WBRofs[1],0) || die("$WBRcfn: $!");
14
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   534
	sysread(WBRF,$buf,2) == 2 || die("$WBRcfn: $!");
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   535
	$id = unpack('v',$buf);
39
3bddaa514ef5 before Hamburg
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 37
diff changeset
   536
	if ($dta->{INSTRUMENT_TYPE} eq 'Ocean Surveyor') {
3bddaa514ef5 before Hamburg
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 37
diff changeset
   537
		$id == 0x0081 || printf(STDERR $FmtErr."\n",$WBRcfn,"Variable Leader",$id,1);
51
148c092b3a09 after somewhat suspicous RDI_PD0_IO.pl merge and just before adding
Andreas Thurnherr <ant@ldeo.columbia.edu>
parents: 50
diff changeset
   538
	} else {
39
3bddaa514ef5 before Hamburg
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 37
diff changeset
   539
		$id == 0x0080 || printf(STDERR $FmtErr."\n",$WBRcfn,"Variable Leader",$id,1);
51
148c092b3a09 after somewhat suspicous RDI_PD0_IO.pl merge and just before adding
Andreas Thurnherr <ant@ldeo.columbia.edu>
parents: 50
diff changeset
   540
	}
39
3bddaa514ef5 before Hamburg
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 37
diff changeset
   541
	sysseek(WBRF,12,1) || die("$WBRcfn: $!");							# skip up to speed of sound
14
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   542
	sysread(WBRF,$buf,2) == 2 || die("$WBRcfn: $!");
39
3bddaa514ef5 before Hamburg
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 37
diff changeset
   543
	$dta->{SPEED_OF_SOUND} = unpack('v',$buf);
51
148c092b3a09 after somewhat suspicous RDI_PD0_IO.pl merge and just before adding
Andreas Thurnherr <ant@ldeo.columbia.edu>
parents: 50
diff changeset
   544
    
14
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   545
	#--------------------
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   546
	# FIXED LEADER
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   547
	#--------------------
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   548
26
02776c168135 made RDI_BB_IO work with files containing leading garbage
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents: 24
diff changeset
   549
	sysseek(WBRF,$start_ens+$WBRofs[0],0) || die("$WBRcfn: $!");
14
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   550
	sysread(WBRF,$buf,42) == 42 || die("$WBRcfn: $!");
39
3bddaa514ef5 before Hamburg
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 37
diff changeset
   551
	($id,$dta->{CPU_FW_VER},$dta->{CPU_FW_REV},$B1,$B2,$dummy,
3bddaa514ef5 before Hamburg
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 37
diff changeset
   552
	 $dta->{LAG_LENGTH},$dummy,
14
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   553
	 $dta->{N_BINS},$dta->{PINGS_PER_ENSEMBLE},$dta->{BIN_LENGTH},
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   554
	 $dta->{BLANKING_DISTANCE},$dummy,$dta->{MIN_CORRELATION},
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   555
	 $dta->{N_CODE_REPETITIONS},$dta->{MIN_PERCENT_GOOD},
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   556
	 $dta->{MAX_ERROR_VELOCITY},$dta->{TIME_BETWEEN_PINGS},$B3,$B4,$B5,
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   557
	 $dta->{HEADING_ALIGNMENT},$dta->{HEADING_BIAS},$B6,$B7,
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   558
	 $dta->{DISTANCE_TO_BIN1_CENTER},$dta->{TRANSMITTED_PULSE_LENGTH},
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   559
	 $dta->{REF_LAYER_FIRST_BIN},$dta->{REF_LAYER_LAST_BIN},
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   560
	 $dta->{FALSE_TARGET_THRESHOLD},$dta->{LOW_LATENCY_SETTING},
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   561
	 $dta->{TRANSMIT_LAG_DISTANCE}) =
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   562
		unpack('vCCCCC3CvvvCCCCvCCCCvvCCvvCCCCv',$buf);
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   563
39
3bddaa514ef5 before Hamburg
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 37
diff changeset
   564
	if ($dta->{INSTRUMENT_TYPE} eq 'Ocean Surveyor') {
3bddaa514ef5 before Hamburg
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 37
diff changeset
   565
		$id == 0x0001 || printf(STDERR $FmtErr."\n",$WBRcfn,"Fixed Leader",$id,0);
51
148c092b3a09 after somewhat suspicous RDI_PD0_IO.pl merge and just before adding
Andreas Thurnherr <ant@ldeo.columbia.edu>
parents: 50
diff changeset
   566
	} else {
39
3bddaa514ef5 before Hamburg
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 37
diff changeset
   567
		$id == 0x0000 || printf(STDERR $FmtErr."\n",$WBRcfn,"Fixed Leader",$id,0);
51
148c092b3a09 after somewhat suspicous RDI_PD0_IO.pl merge and just before adding
Andreas Thurnherr <ant@ldeo.columbia.edu>
parents: 50
diff changeset
   568
	}
14
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   569
51
148c092b3a09 after somewhat suspicous RDI_PD0_IO.pl merge and just before adding
Andreas Thurnherr <ant@ldeo.columbia.edu>
parents: 50
diff changeset
   570
#	$dta->{BEAM_FREQUENCY} = 2**($B1 & 0x07) * 75;						# nominal
148c092b3a09 after somewhat suspicous RDI_PD0_IO.pl merge and just before adding
Andreas Thurnherr <ant@ldeo.columbia.edu>
parents: 50
diff changeset
   571
	if	  (($B1&0x07) == 0b000) { $dta->{BEAM_FREQUENCY} =	 76.8; }		# actual
148c092b3a09 after somewhat suspicous RDI_PD0_IO.pl merge and just before adding
Andreas Thurnherr <ant@ldeo.columbia.edu>
parents: 50
diff changeset
   572
	elsif (($B1&0x07) == 0b001) { $dta->{BEAM_FREQUENCY} =	153.6; }
148c092b3a09 after somewhat suspicous RDI_PD0_IO.pl merge and just before adding
Andreas Thurnherr <ant@ldeo.columbia.edu>
parents: 50
diff changeset
   573
	elsif (($B1&0x07) == 0b010) { $dta->{BEAM_FREQUENCY} =	307.2; }
148c092b3a09 after somewhat suspicous RDI_PD0_IO.pl merge and just before adding
Andreas Thurnherr <ant@ldeo.columbia.edu>
parents: 50
diff changeset
   574
	elsif (($B1&0x07) == 0b011) { $dta->{BEAM_FREQUENCY} =	614.4; }
39
3bddaa514ef5 before Hamburg
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 37
diff changeset
   575
	elsif (($B1&0x07) == 0b100) { $dta->{BEAM_FREQUENCY} = 1228.8; }
3bddaa514ef5 before Hamburg
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 37
diff changeset
   576
	elsif (($B1&0x07) == 0b101) { $dta->{BEAM_FREQUENCY} = 2457.6; }
3bddaa514ef5 before Hamburg
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 37
diff changeset
   577
	else { die(sprintf("$WBRcfn: cannot decode BEAM_FREQUENCY (%03b)\n",$B1&0x07)); }
3bddaa514ef5 before Hamburg
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 37
diff changeset
   578
51
148c092b3a09 after somewhat suspicous RDI_PD0_IO.pl merge and just before adding
Andreas Thurnherr <ant@ldeo.columbia.edu>
parents: 50
diff changeset
   579
	$dta->{CONVEX_BEAM_PATTERN} = 1 if ($B1 & 0x08);
148c092b3a09 after somewhat suspicous RDI_PD0_IO.pl merge and just before adding
Andreas Thurnherr <ant@ldeo.columbia.edu>
parents: 50
diff changeset
   580
	$dta->{CONCAVE_BEAM_PATTERN} = 1 if (!($B1 & 0x08));
148c092b3a09 after somewhat suspicous RDI_PD0_IO.pl merge and just before adding
Andreas Thurnherr <ant@ldeo.columbia.edu>
parents: 50
diff changeset
   581
	$dta->{SENSOR_CONFIG} = ($B1 & 0x30) >> 4;
148c092b3a09 after somewhat suspicous RDI_PD0_IO.pl merge and just before adding
Andreas Thurnherr <ant@ldeo.columbia.edu>
parents: 50
diff changeset
   582
	$dta->{XDUCER_HEAD_ATTACHED} = 1 if ($B1 & 0x40);
14
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   583
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   584
	if	  (($B2 & 0x03) == 0x00) { $dta->{BEAM_ANGLE} = 15; }
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   585
	elsif (($B2 & 0x03) == 0x01) { $dta->{BEAM_ANGLE} = 20; }
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   586
	elsif (($B2 & 0x03) == 0x02) { $dta->{BEAM_ANGLE} = 30; }
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   587
	if	  (($B2 & 0xF0) == 0x40) { $dta->{N_BEAMS} = 4; }
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   588
	elsif (($B2 & 0xF0) == 0x50) { $dta->{N_BEAMS} = 5; $dta->{N_DEMODS} = 3; }
51
148c092b3a09 after somewhat suspicous RDI_PD0_IO.pl merge and just before adding
Andreas Thurnherr <ant@ldeo.columbia.edu>
parents: 50
diff changeset
   589
	elsif (($B2 & 0xF0) == 0xF0) { $dta->{N_BEAMS} = 5; $dta->{N_DEMODS} = 2; }
14
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   590
    
51
148c092b3a09 after somewhat suspicous RDI_PD0_IO.pl merge and just before adding
Andreas Thurnherr <ant@ldeo.columbia.edu>
parents: 50
diff changeset
   591
	$dta->{BIN_LENGTH} /= 100;
148c092b3a09 after somewhat suspicous RDI_PD0_IO.pl merge and just before adding
Andreas Thurnherr <ant@ldeo.columbia.edu>
parents: 50
diff changeset
   592
	$dta->{BLANKING_DISTANCE} /= 100;
14
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   593
51
148c092b3a09 after somewhat suspicous RDI_PD0_IO.pl merge and just before adding
Andreas Thurnherr <ant@ldeo.columbia.edu>
parents: 50
diff changeset
   594
	$dta->{MAX_ERROR_VELOCITY} /= 1000;
148c092b3a09 after somewhat suspicous RDI_PD0_IO.pl merge and just before adding
Andreas Thurnherr <ant@ldeo.columbia.edu>
parents: 50
diff changeset
   595
	$dta->{TIME_BETWEEN_PINGS} *= 60;
14
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   596
	$dta->{TIME_BETWEEN_PINGS} += $B3 + $B4/100;
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   597
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   598
	$dta->{BEAM_COORDINATES}		  = 1 if (($B5 & 0x18) == 0x00);
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   599
	$dta->{INSTRUMENT_COORDINATES}	  = 1 if (($B5 & 0x18) == 0x08);
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   600
	$dta->{SHIP_COORDINATES}		  = 1 if (($B5 & 0x18) == 0x10);
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   601
	$dta->{EARTH_COORDINATES}		  = 1 if (($B5 & 0x18) == 0x18);
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   602
	$dta->{PITCH_AND_ROLL_USED} 	  = 1 if ($B5 & 0x04);
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   603
	$dta->{USE_3_BEAM_ON_LOW_CORR}	  = 1 if ($B5 & 0x02);
51
148c092b3a09 after somewhat suspicous RDI_PD0_IO.pl merge and just before adding
Andreas Thurnherr <ant@ldeo.columbia.edu>
parents: 50
diff changeset
   604
	$dta->{BIN_MAPPING_ALLOWED} 	  = 1 if ($B5 & 0x01);
148c092b3a09 after somewhat suspicous RDI_PD0_IO.pl merge and just before adding
Andreas Thurnherr <ant@ldeo.columbia.edu>
parents: 50
diff changeset
   605
	    
14
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   606
	$dta->{HEADING_ALIGNMENT} =
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   607
		($dta->{EARTH_COORDINATES} || $dta->{SHIP_COORDINATES}) ?
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   608
			$dta->{HEADING_ALIGNMENT} / 100 : undef;
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   609
	$dta->{HEADING_BIAS} =
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   610
		($dta->{EARTH_COORDINATES} || $dta->{SHIP_COORDINATES}) ?
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   611
			$dta->{HEADING_BIAS} / 100 : undef;
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   612
57
5a59411306ba updated for Nortek
Andreas Thurnherr <ant@ldeo.columbia.edu>
parents: 56
diff changeset
   613
	$dta->{SSPEED_FROM_EC_SETTING}		= 1 unless ($B6 & 0x40); 	# these are the aspirations
5a59411306ba updated for Nortek
Andreas Thurnherr <ant@ldeo.columbia.edu>
parents: 56
diff changeset
   614
	$dta->{DEPTH_FROM_ED_SETTING}	   	= 1 unless ($B6 & 0x20); 
5a59411306ba updated for Nortek
Andreas Thurnherr <ant@ldeo.columbia.edu>
parents: 56
diff changeset
   615
	$dta->{HEADING_FROM_EH_SETTING}		= 1 unless ($B6 & 0x10); 
5a59411306ba updated for Nortek
Andreas Thurnherr <ant@ldeo.columbia.edu>
parents: 56
diff changeset
   616
	$dta->{PITCH_FROM_EP_SETTING}	  	= 1 unless ($B6 & 0x08); 
5a59411306ba updated for Nortek
Andreas Thurnherr <ant@ldeo.columbia.edu>
parents: 56
diff changeset
   617
	$dta->{ROLL_FROM_ER_SETTING} 		= 1 unless ($B6 & 0x04); 
5a59411306ba updated for Nortek
Andreas Thurnherr <ant@ldeo.columbia.edu>
parents: 56
diff changeset
   618
	$dta->{SALIN_FROM_ES_SETTING}		= 1 unless ($B6 & 0x02); 
5a59411306ba updated for Nortek
Andreas Thurnherr <ant@ldeo.columbia.edu>
parents: 56
diff changeset
   619
	$dta->{TEMP_FROM_ET_SETTING}  		= 1 unless ($B6 & 0x01); 
14
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   620
57
5a59411306ba updated for Nortek
Andreas Thurnherr <ant@ldeo.columbia.edu>
parents: 56
diff changeset
   621
	$dta->{SSPEED_CALCULATED}			= 1 if ($B7 & 0x40); 		# and this is how it is in practice
5a59411306ba updated for Nortek
Andreas Thurnherr <ant@ldeo.columbia.edu>
parents: 56
diff changeset
   622
	$dta->{PRESSURE_SENSOR}				= 1 if ($B7 & 0x20); 
5a59411306ba updated for Nortek
Andreas Thurnherr <ant@ldeo.columbia.edu>
parents: 56
diff changeset
   623
	$dta->{COMPASS}			  			= 1 if ($B7 & 0x10); 
5a59411306ba updated for Nortek
Andreas Thurnherr <ant@ldeo.columbia.edu>
parents: 56
diff changeset
   624
	$dta->{PITCH_SENSOR}				= 1 if ($B7 & 0x08); 
5a59411306ba updated for Nortek
Andreas Thurnherr <ant@ldeo.columbia.edu>
parents: 56
diff changeset
   625
	$dta->{ROLL_SENSOR}		  			= 1 if ($B7 & 0x04); 
5a59411306ba updated for Nortek
Andreas Thurnherr <ant@ldeo.columbia.edu>
parents: 56
diff changeset
   626
	$dta->{CONDUCTIVITY_SENSOR} 		= 1 if ($B7 & 0x02); 
5a59411306ba updated for Nortek
Andreas Thurnherr <ant@ldeo.columbia.edu>
parents: 56
diff changeset
   627
	$dta->{TEMPERATURE_SENSOR}  		= 1 if ($B7 & 0x01); 
14
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   628
51
148c092b3a09 after somewhat suspicous RDI_PD0_IO.pl merge and just before adding
Andreas Thurnherr <ant@ldeo.columbia.edu>
parents: 50
diff changeset
   629
	$dta->{DISTANCE_TO_BIN1_CENTER}  /= 100;
148c092b3a09 after somewhat suspicous RDI_PD0_IO.pl merge and just before adding
Andreas Thurnherr <ant@ldeo.columbia.edu>
parents: 50
diff changeset
   630
	$dta->{TRANSMITTED_PULSE_LENGTH} /= 100;
14
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   631
51
148c092b3a09 after somewhat suspicous RDI_PD0_IO.pl merge and just before adding
Andreas Thurnherr <ant@ldeo.columbia.edu>
parents: 50
diff changeset
   632
	$dta->{FALSE_TARGET_THRESHOLD} = undef
14
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   633
		if ($dta->{FALSE_TARGET_THRESHOLD} == 255);
51
148c092b3a09 after somewhat suspicous RDI_PD0_IO.pl merge and just before adding
Andreas Thurnherr <ant@ldeo.columbia.edu>
parents: 50
diff changeset
   634
	$dta->{TRANSMIT_LAG_DISTANCE} /= 100;
14
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   635
57
5a59411306ba updated for Nortek
Andreas Thurnherr <ant@ldeo.columbia.edu>
parents: 56
diff changeset
   636
	if ($dta->{INSTRUMENT_TYPE} eq 'Workhorse or Signature') {
14
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   637
		sysread(WBRF,$buf,11) == 11 || die("$WBRcfn: $!");
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   638
		($W1,$W2,$W3,$W4,$W5,$dta->{TRANSMIT_POWER}) = 
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   639
			unpack('vvvvvC',$buf);
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   640
57
5a59411306ba updated for Nortek
Andreas Thurnherr <ant@ldeo.columbia.edu>
parents: 56
diff changeset
   641
		if ($W1 == 0x6953 && $W2 == 0x6E67 &&
5a59411306ba updated for Nortek
Andreas Thurnherr <ant@ldeo.columbia.edu>
parents: 56
diff changeset
   642
			$W3 == 0x7461 && $W4 == 0x0075) {
5a59411306ba updated for Nortek
Andreas Thurnherr <ant@ldeo.columbia.edu>
parents: 56
diff changeset
   643
				$dta->{INSTRUMENT_TYPE} = 'Signature';
5a59411306ba updated for Nortek
Andreas Thurnherr <ant@ldeo.columbia.edu>
parents: 56
diff changeset
   644
				$dta->{TRANSMIT_POWER_MAX} = ($dta->{TRANSMIT_POWER} == 122);
5a59411306ba updated for Nortek
Andreas Thurnherr <ant@ldeo.columbia.edu>
parents: 56
diff changeset
   645
				$dta->{PRODUCER} = 'Nortek ADCP' if ($dta->{PRODUCER} eq 'TRDI or Nortek ADCP');
5a59411306ba updated for Nortek
Andreas Thurnherr <ant@ldeo.columbia.edu>
parents: 56
diff changeset
   646
		} else {
5a59411306ba updated for Nortek
Andreas Thurnherr <ant@ldeo.columbia.edu>
parents: 56
diff changeset
   647
			$dta->{INSTRUMENT_TYPE} = 'Workhorse';
5a59411306ba updated for Nortek
Andreas Thurnherr <ant@ldeo.columbia.edu>
parents: 56
diff changeset
   648
			$dta->{CPU_SERIAL_NUMBER} = sprintf("%04X%04X%04X%04X",$W1,$W2,$W3,$W4);
5a59411306ba updated for Nortek
Andreas Thurnherr <ant@ldeo.columbia.edu>
parents: 56
diff changeset
   649
			$dta->{TRANSMIT_POWER_MAX} = ($dta->{TRANSMIT_POWER} == 255);
5a59411306ba updated for Nortek
Andreas Thurnherr <ant@ldeo.columbia.edu>
parents: 56
diff changeset
   650
			$dta->{PRODUCER} = 'TRDI ADCP' if ($dta->{PRODUCER} eq 'TRDI or Nortek ADCP');
5a59411306ba updated for Nortek
Andreas Thurnherr <ant@ldeo.columbia.edu>
parents: 56
diff changeset
   651
		}
51
148c092b3a09 after somewhat suspicous RDI_PD0_IO.pl merge and just before adding
Andreas Thurnherr <ant@ldeo.columbia.edu>
parents: 50
diff changeset
   652
    
14
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   653
		$dta->{NARROW_BANDWIDTH} = ($W5 == 1);
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   654
		$dta->{WIDE_BANDWIDTH}	 = ($W5 == 0);
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   655
51
148c092b3a09 after somewhat suspicous RDI_PD0_IO.pl merge and just before adding
Andreas Thurnherr <ant@ldeo.columbia.edu>
parents: 50
diff changeset
   656
		if ($dta->{FIXED_LEADER_BYTES} == 59) { 				# new style with serial number
14
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   657
			sysread(WBRF,$buf,6) == 6 || die("$WBRcfn: $!");
51
148c092b3a09 after somewhat suspicous RDI_PD0_IO.pl merge and just before adding
Andreas Thurnherr <ant@ldeo.columbia.edu>
parents: 50
diff changeset
   658
			($dummy,$dta->{SERIAL_NUMBER},$dummy) = 			# last bytes is beam angle, but that info has
148c092b3a09 after somewhat suspicous RDI_PD0_IO.pl merge and just before adding
Andreas Thurnherr <ant@ldeo.columbia.edu>
parents: 50
diff changeset
   659
				unpack('CVC',$buf); 							# already been provided above
14
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   660
		}
51
148c092b3a09 after somewhat suspicous RDI_PD0_IO.pl merge and just before adding
Andreas Thurnherr <ant@ldeo.columbia.edu>
parents: 50
diff changeset
   661
	}
14
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   662
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   663
	if ($dta->{INSTRUMENT_TYPE} eq 'Explorer') {
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   664
		sysread(WBRF,$buf,16) == 16 || die("$WBRcfn: $!");
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   665
		($dummy,$dummy,$W5,$dummy,$dta->{SERIAL_NUMBER}) = 
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   666
			unpack('VVvvV',$buf);
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   667
		$dta->{NARROW_BANDWIDTH} = ($W5 == 1);
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   668
		$dta->{WIDE_BANDWIDTH}	 = ($W5 == 0);
51
148c092b3a09 after somewhat suspicous RDI_PD0_IO.pl merge and just before adding
Andreas Thurnherr <ant@ldeo.columbia.edu>
parents: 50
diff changeset
   669
	}
14
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   670
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   671
	#-----------------------
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   672
	# 1st ENSEMBLE, BT Setup
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   673
	#-----------------------
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   674
56
82384f531dba improvements for Nortek
Andreas Thurnherr <ant@ldeo.columbia.edu>
parents: 55
diff changeset
   675
	if ($dta->{BT_PRESENT}) {
82384f531dba improvements for Nortek
Andreas Thurnherr <ant@ldeo.columbia.edu>
parents: 55
diff changeset
   676
		sysseek(WBRF,$start_ens+$WBRofs[$BT_dt],0) || die("$WBRcfn: $!");
82384f531dba improvements for Nortek
Andreas Thurnherr <ant@ldeo.columbia.edu>
parents: 55
diff changeset
   677
		sysread(WBRF,$buf,12) == 12 || die("$WBRcfn: $!");
82384f531dba improvements for Nortek
Andreas Thurnherr <ant@ldeo.columbia.edu>
parents: 55
diff changeset
   678
		($id,$dta->{BT_PINGS_PER_ENSEMBLE},$dta->{BT_DELAY_BEFORE_REACQUIRE},
82384f531dba improvements for Nortek
Andreas Thurnherr <ant@ldeo.columbia.edu>
parents: 55
diff changeset
   679
		 $dta->{BT_MIN_CORRELATION},$dta->{BT_MIN_EVAL_AMPLITUDE},
82384f531dba improvements for Nortek
Andreas Thurnherr <ant@ldeo.columbia.edu>
parents: 55
diff changeset
   680
		 $dta->{BT_MIN_PERCENT_GOOD},$dta->{BT_MODE},
82384f531dba improvements for Nortek
Andreas Thurnherr <ant@ldeo.columbia.edu>
parents: 55
diff changeset
   681
		 $dta->{BT_MAX_ERROR_VELOCITY}) = unpack('vvvCCCCv',$buf);
82384f531dba improvements for Nortek
Andreas Thurnherr <ant@ldeo.columbia.edu>
parents: 55
diff changeset
   682
		 
82384f531dba improvements for Nortek
Andreas Thurnherr <ant@ldeo.columbia.edu>
parents: 55
diff changeset
   683
		$id == 0x0600 ||
82384f531dba improvements for Nortek
Andreas Thurnherr <ant@ldeo.columbia.edu>
parents: 55
diff changeset
   684
			printf(STDERR $FmtErr."\n",$WBRcfn,"Bottom Track",$id,0,tell(WBRF));
82384f531dba improvements for Nortek
Andreas Thurnherr <ant@ldeo.columbia.edu>
parents: 55
diff changeset
   685
   
82384f531dba improvements for Nortek
Andreas Thurnherr <ant@ldeo.columbia.edu>
parents: 55
diff changeset
   686
		$dta->{BT_MAX_ERROR_VELOCITY} =
82384f531dba improvements for Nortek
Andreas Thurnherr <ant@ldeo.columbia.edu>
parents: 55
diff changeset
   687
			$dta->{BT_MAX_ERROR_VELOCITY} ? $dta->{BT_MAX_ERROR_VELOCITY} / 1000
82384f531dba improvements for Nortek
Andreas Thurnherr <ant@ldeo.columbia.edu>
parents: 55
diff changeset
   688
										  : undef;
82384f531dba improvements for Nortek
Andreas Thurnherr <ant@ldeo.columbia.edu>
parents: 55
diff changeset
   689
   
82384f531dba improvements for Nortek
Andreas Thurnherr <ant@ldeo.columbia.edu>
parents: 55
diff changeset
   690
		sysseek(WBRF,28,1) || die("$WBRcfn: $!");
82384f531dba improvements for Nortek
Andreas Thurnherr <ant@ldeo.columbia.edu>
parents: 55
diff changeset
   691
		sysread(WBRF,$buf,6) == 6 || die("$WBRcfn: $!");
82384f531dba improvements for Nortek
Andreas Thurnherr <ant@ldeo.columbia.edu>
parents: 55
diff changeset
   692
		($dta->{BT_RL_MIN_SIZE},$dta->{BT_RL_NEAR},$dta->{BT_RL_FAR})
82384f531dba improvements for Nortek
Andreas Thurnherr <ant@ldeo.columbia.edu>
parents: 55
diff changeset
   693
			= unpack('vvv',$buf);
82384f531dba improvements for Nortek
Andreas Thurnherr <ant@ldeo.columbia.edu>
parents: 55
diff changeset
   694
   
82384f531dba improvements for Nortek
Andreas Thurnherr <ant@ldeo.columbia.edu>
parents: 55
diff changeset
   695
		$dta->{BT_RL_MIN_SIZE} /= 10;
82384f531dba improvements for Nortek
Andreas Thurnherr <ant@ldeo.columbia.edu>
parents: 55
diff changeset
   696
		$dta->{BT_RL_NEAR} /= 10;
82384f531dba improvements for Nortek
Andreas Thurnherr <ant@ldeo.columbia.edu>
parents: 55
diff changeset
   697
		$dta->{BT_RL_FAR} /= 10;
82384f531dba improvements for Nortek
Andreas Thurnherr <ant@ldeo.columbia.edu>
parents: 55
diff changeset
   698
	    
82384f531dba improvements for Nortek
Andreas Thurnherr <ant@ldeo.columbia.edu>
parents: 55
diff changeset
   699
		sysseek(WBRF,20,1) || die("$WBRcfn: $!");		# skip data
82384f531dba improvements for Nortek
Andreas Thurnherr <ant@ldeo.columbia.edu>
parents: 55
diff changeset
   700
		sysread(WBRF,$buf,2) == 2 || die("$WBRcfn: $!");
82384f531dba improvements for Nortek
Andreas Thurnherr <ant@ldeo.columbia.edu>
parents: 55
diff changeset
   701
		$dta->{BT_MAX_TRACKING_DEPTH} = unpack('v',$buf) / 10;
82384f531dba improvements for Nortek
Andreas Thurnherr <ant@ldeo.columbia.edu>
parents: 55
diff changeset
   702
	 }
14
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   703
    
51
148c092b3a09 after somewhat suspicous RDI_PD0_IO.pl merge and just before adding
Andreas Thurnherr <ant@ldeo.columbia.edu>
parents: 50
diff changeset
   704
	return $dta;
14
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   705
}
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   706
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   707
#----------------------------------------------------------------------
43
b63fa355644c commit to merge with changes from EN620
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 42
diff changeset
   708
# readData(file_name,^data[,first_ens,last_ens[,last_bin]]) 
51
148c092b3a09 after somewhat suspicous RDI_PD0_IO.pl merge and just before adding
Andreas Thurnherr <ant@ldeo.columbia.edu>
parents: 50
diff changeset
   709
#	- read ensembles
43
b63fa355644c commit to merge with changes from EN620
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 42
diff changeset
   710
#	- read all ensembles unless first_ens and last_ens are given
b63fa355644c commit to merge with changes from EN620
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 42
diff changeset
   711
#	- read all bins unless last_bin is given
51
148c092b3a09 after somewhat suspicous RDI_PD0_IO.pl merge and just before adding
Andreas Thurnherr <ant@ldeo.columbia.edu>
parents: 50
diff changeset
   712
#	- NB: CODE GETS PROGRESSIVELY SLOWER => HUGE PAIN FOR LARGE FILES
14
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   713
#----------------------------------------------------------------------
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   714
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   715
sub readData(@)
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   716
{
43
b63fa355644c commit to merge with changes from EN620
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 42
diff changeset
   717
	my($fn,$dta,$fe,$le,$lb) = @_;
14
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   718
	$WBRcfn = $fn;
51
148c092b3a09 after somewhat suspicous RDI_PD0_IO.pl merge and just before adding
Andreas Thurnherr <ant@ldeo.columbia.edu>
parents: 50
diff changeset
   719
	open(WBRF,$WBRcfn) || die("$WBRcfn: $!\n");
148c092b3a09 after somewhat suspicous RDI_PD0_IO.pl merge and just before adding
Andreas Thurnherr <ant@ldeo.columbia.edu>
parents: 50
diff changeset
   720
	WBRhdr($dta) || die("$WBRcfn: Insufficient Data\n");
148c092b3a09 after somewhat suspicous RDI_PD0_IO.pl merge and just before adding
Andreas Thurnherr <ant@ldeo.columbia.edu>
parents: 50
diff changeset
   721
	$lb = $dta->{N_BINS}
43
b63fa355644c commit to merge with changes from EN620
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 42
diff changeset
   722
		unless (numberp($lb) && $lb>=1 && $lb<=$dta->{N_BINS});
b63fa355644c commit to merge with changes from EN620
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 42
diff changeset
   723
	WBRens($lb,$dta->{FIXED_LEADER_BYTES},\@{$dta->{ENSEMBLE}},$fe,$le);
14
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   724
	print(STDERR "$WBRcfn: $BIT_errors built-in-test errors\n")
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   725
		if ($BIT_errors);
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   726
}
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   727
43
b63fa355644c commit to merge with changes from EN620
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 42
diff changeset
   728
sub WBRens(@)
14
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   729
{
43
b63fa355644c commit to merge with changes from EN620
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 42
diff changeset
   730
	my($nbins,$fixed_leader_bytes,$E,$fe,$le) = @_;
48
cdc74ebada81 after partial adaptation to RTI files
Andreas Thurnherr <ant@ldeo.columbia.edu>
parents: 45
diff changeset
   731
	my($B1,$B2,$B3,$B4,$I,$bin,$beam,$dummy,@dta,$i,$cs);
cdc74ebada81 after partial adaptation to RTI files
Andreas Thurnherr <ant@ldeo.columbia.edu>
parents: 45
diff changeset
   732
	my($ens,$ensNo,$dayStart,$ens_length,$hid,$did,$el);
cdc74ebada81 after partial adaptation to RTI files
Andreas Thurnherr <ant@ldeo.columbia.edu>
parents: 45
diff changeset
   733
	local our($ndt,$buf,$id,$start_ens,@WBRofs);
14
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   734
51
148c092b3a09 after somewhat suspicous RDI_PD0_IO.pl merge and just before adding
Andreas Thurnherr <ant@ldeo.columbia.edu>
parents: 50
diff changeset
   735
	sysseek(WBRF,0,0) || die("$WBRcfn: $!");
43
b63fa355644c commit to merge with changes from EN620
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 42
diff changeset
   736
ENSEMBLE:
b63fa355644c commit to merge with changes from EN620
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 42
diff changeset
   737
	for ($ens=0; 1; $ens++) {
51
148c092b3a09 after somewhat suspicous RDI_PD0_IO.pl merge and just before adding
Andreas Thurnherr <ant@ldeo.columbia.edu>
parents: 50
diff changeset
   738
		print(STDERR '.') if ($RDI_PD0_IO::show_progress && $ens % 1000 == 0);
43
b63fa355644c commit to merge with changes from EN620
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 42
diff changeset
   739
		$start_ens = goto_next_ens(\*WBRF);
b63fa355644c commit to merge with changes from EN620
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 42
diff changeset
   740
		last unless defined($start_ens);
b63fa355644c commit to merge with changes from EN620
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 42
diff changeset
   741
b63fa355644c commit to merge with changes from EN620
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 42
diff changeset
   742
		#----------------------------------------
b63fa355644c commit to merge with changes from EN620
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 42
diff changeset
   743
		# Handle first_ens and last_ens
b63fa355644c commit to merge with changes from EN620
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 42
diff changeset
   744
		#----------------------------------------
b63fa355644c commit to merge with changes from EN620
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 42
diff changeset
   745
b63fa355644c commit to merge with changes from EN620
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 42
diff changeset
   746
		if (defined($fe) && $ens>0 && ${$E}[$ens-1]->{NUMBER}<$fe) {					# delete previous ensemble
b63fa355644c commit to merge with changes from EN620
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 42
diff changeset
   747
			pop(@{$E}); $ens--;
b63fa355644c commit to merge with changes from EN620
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 42
diff changeset
   748
		}
b63fa355644c commit to merge with changes from EN620
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 42
diff changeset
   749
b63fa355644c commit to merge with changes from EN620
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 42
diff changeset
   750
		if (defined($le) && $ens>0 && ${$E}[$ens-1]->{NUMBER}>$le) {					# delete previous ensemble and finish
b63fa355644c commit to merge with changes from EN620
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 42
diff changeset
   751
			pop(@{$E}); $ens--;
b63fa355644c commit to merge with changes from EN620
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 42
diff changeset
   752
			last;
b63fa355644c commit to merge with changes from EN620
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 42
diff changeset
   753
		}
14
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   754
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   755
		#----------------------------------------
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   756
		# Get ensemble length and # of data types 
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   757
		#----------------------------------------
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   758
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   759
		sysseek(WBRF,$start_ens,0) || die("$WBRcfn: $!");
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   760
		sysread(WBRF,$buf,6) == 6 || last;
43
b63fa355644c commit to merge with changes from EN620
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 42
diff changeset
   761
		($hid,$did,$el,$dummy,$ndt) = unpack('CCvCC',$buf);
37
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 36
diff changeset
   762
		$hid == 0x7f || die(sprintf($FmtErr,$WBRcfn,"Header",$hid,defined($ensNo)?$ensNo+1:0));
29
aeb26e966b71 transport
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 28
diff changeset
   763
		${$E}[$ens]->{DATA_SOURCE_ID} = $did;
aeb26e966b71 transport
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 28
diff changeset
   764
		if ($did == 0x7f) {
aeb26e966b71 transport
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 28
diff changeset
   765
			${$E}[$ens]->{PRODUCER} = 'TRDI ADCP';
aeb26e966b71 transport
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 28
diff changeset
   766
		} elsif ($did&0xF0 == 0xA0) {
aeb26e966b71 transport
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 28
diff changeset
   767
			${$E}[$ens]->{PRODUCER} = 'IMP+LADCP (Thurnherr software)';
31
b6ca27a1d19c pre Tampa
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 29
diff changeset
   768
		} elsif ($did&0xF0 == 0xE0) {
29
aeb26e966b71 transport
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 28
diff changeset
   769
			${$E}[$ens]->{PRODUCER} = 'editPD0 (Thurnherr software)';
aeb26e966b71 transport
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 28
diff changeset
   770
		} else {
aeb26e966b71 transport
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 28
diff changeset
   771
			${$E}[$ens]->{PRODUCER} = 'unknown';
51
148c092b3a09 after somewhat suspicous RDI_PD0_IO.pl merge and just before adding
Andreas Thurnherr <ant@ldeo.columbia.edu>
parents: 50
diff changeset
   772
		}
29
aeb26e966b71 transport
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 28
diff changeset
   773
43
b63fa355644c commit to merge with changes from EN620
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 42
diff changeset
   774
		if (defined($ens_length) && ($el != $ens_length)) {
50
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 49
diff changeset
   775
			$RDI_PD0_IO::File_Dirty = 1;
43
b63fa355644c commit to merge with changes from EN620
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 42
diff changeset
   776
			print(STDERR "WARNING (RDI_PD0_IO): ensemble ${$E}[$#{$E}]->{NUMBER} skipped (unexpected length)\n");
b63fa355644c commit to merge with changes from EN620
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 42
diff changeset
   777
			pop(@{$E});
b63fa355644c commit to merge with changes from EN620
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 42
diff changeset
   778
			$ens--;
b63fa355644c commit to merge with changes from EN620
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 42
diff changeset
   779
			next;
b63fa355644c commit to merge with changes from EN620
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 42
diff changeset
   780
		}
51
148c092b3a09 after somewhat suspicous RDI_PD0_IO.pl merge and just before adding
Andreas Thurnherr <ant@ldeo.columbia.edu>
parents: 50
diff changeset
   781
	    
43
b63fa355644c commit to merge with changes from EN620
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 42
diff changeset
   782
		$ens_length = $el;
b63fa355644c commit to merge with changes from EN620
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 42
diff changeset
   783
b63fa355644c commit to merge with changes from EN620
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 42
diff changeset
   784
##		printf(STDERR "$WBRcfn: WARNING: unexpected number of data types (%d, ens=$ens)\n",$ndt),last
18
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 14
diff changeset
   785
##				unless ($ndt == 6 || $ndt == 7);
50
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 49
diff changeset
   786
		my($nread) = sysread(WBRF,$buf,2*$ndt);						# 2019 EPR test
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 49
diff changeset
   787
		if ($nread != 2*$ndt) {
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 49
diff changeset
   788
			printf(STDERR "$WBRcfn: WARNING: expected to read %d bytes, got only %d in ensemble %d\n",
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 49
diff changeset
   789
							2*$ndt,$nread,${$E}[$ens]->{NUMBER});
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 49
diff changeset
   790
			last;							
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 49
diff changeset
   791
        }
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 49
diff changeset
   792
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 49
diff changeset
   793
14
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   794
		@WBRofs = unpack("v$ndt",$buf);
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   795
		$fixed_leader_bytes = $WBRofs[1] - $WBRofs[0];
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   796
#		print(STDERR "@WBRofs\n");
51
148c092b3a09 after somewhat suspicous RDI_PD0_IO.pl merge and just before adding
Andreas Thurnherr <ant@ldeo.columbia.edu>
parents: 50
diff changeset
   797
    
14
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   798
		#-------------------------------
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   799
		# Make Sure Ensemble is Complete
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   800
		#-------------------------------
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   801
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   802
		# UH BB150 writes incomplete ensembles (i.e. short read
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   803
		# indicates EOF). FSU WH300 has bogus data in incomplete
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   804
		# final ensemble.
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   805
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   806
		sysseek(WBRF,$start_ens,0) || die("$WBRcfn: $!");
37
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 36
diff changeset
   807
		unless ((sysread(WBRF,$buf,$ens_length) == $ens_length) &&				# incomplete ensemble
36
515b06dae59c version at end of ECOGIG EN586 cruise
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 32
diff changeset
   808
				(sysread(WBRF,$cs,2) == 2)) {
43
b63fa355644c commit to merge with changes from EN620
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 42
diff changeset
   809
#			print(STDERR "INCOMPLETE ENSEMBLE\n");
36
515b06dae59c version at end of ECOGIG EN586 cruise
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 32
diff changeset
   810
			pop(@{$E});
515b06dae59c version at end of ECOGIG EN586 cruise
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 32
diff changeset
   811
			last;
515b06dae59c version at end of ECOGIG EN586 cruise
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 32
diff changeset
   812
		}
14
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   813
37
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 36
diff changeset
   814
		unless (unpack('%16C*',$buf) == unpack('v',$cs)) {						# bad checksum
43
b63fa355644c commit to merge with changes from EN620
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 42
diff changeset
   815
#			print(STDERR "BAD CHECKSUM\n");
b63fa355644c commit to merge with changes from EN620
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 42
diff changeset
   816
			pop(@{$E}); $ens--;
b63fa355644c commit to merge with changes from EN620
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 42
diff changeset
   817
			next;
51
148c092b3a09 after somewhat suspicous RDI_PD0_IO.pl merge and just before adding
Andreas Thurnherr <ant@ldeo.columbia.edu>
parents: 50
diff changeset
   818
		}	    
14
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   819
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   820
		#------------------------------
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   821
		# Variable Leader
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   822
		#------------------------------
51
148c092b3a09 after somewhat suspicous RDI_PD0_IO.pl merge and just before adding
Andreas Thurnherr <ant@ldeo.columbia.edu>
parents: 50
diff changeset
   823
    
37
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 36
diff changeset
   824
		my($lastEns) = $ensNo;
14
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   825
		sysseek(WBRF,$start_ens+$WBRofs[1],0) || die("$WBRcfn: $!");
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   826
		sysread(WBRF,$buf,4) == 4 || die("$WBRcfn: $!");
37
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 36
diff changeset
   827
		($id,$ensNo) = unpack("vv",$buf);										# only lower two bytes!!!
14
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   828
39
3bddaa514ef5 before Hamburg
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 37
diff changeset
   829
		if (${$E}[$ens]->{INSTRUMENT_TYPE} eq 'Ocean Surveyor') {
3bddaa514ef5 before Hamburg
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 37
diff changeset
   830
			$id == 0x0081 ||
3bddaa514ef5 before Hamburg
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 37
diff changeset
   831
				die(sprintf($FmtErr,$WBRcfn,"Variable Leader",$id,$ensNo + ($lastEns - ($lastEns & 0xFFFF))));
51
148c092b3a09 after somewhat suspicous RDI_PD0_IO.pl merge and just before adding
Andreas Thurnherr <ant@ldeo.columbia.edu>
parents: 50
diff changeset
   832
		} else {
39
3bddaa514ef5 before Hamburg
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 37
diff changeset
   833
			$id == 0x0080 ||
3bddaa514ef5 before Hamburg
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 37
diff changeset
   834
				die(sprintf($FmtErr,$WBRcfn,"Variable Leader",$id,$ensNo + ($lastEns - ($lastEns & 0xFFFF))));
51
148c092b3a09 after somewhat suspicous RDI_PD0_IO.pl merge and just before adding
Andreas Thurnherr <ant@ldeo.columbia.edu>
parents: 50
diff changeset
   835
		}
14
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   836
42
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 40
diff changeset
   837
#		if ($fixed_leader_bytes==42 || $fixed_leader_bytes==58) {				# BB150 & Explorer DVL (if DISABLED!)
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 40
diff changeset
   838
			sysread(WBRF,$buf,7) == 7 || die("$WBRcfn: $!");					# always read pre-Y2K clock
14
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   839
			(${$E}[$ens]->{YEAR},${$E}[$ens]->{MONTH},
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   840
			 ${$E}[$ens]->{DAY},${$E}[$ens]->{HOUR},${$E}[$ens]->{MINUTE},
50
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 49
diff changeset
   841
			 ${$E}[$ens]->{SECOND},$B4) = unpack('CCCCCCC',$buf);
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 49
diff changeset
   842
			${$E}[$ens]->{SECOND} += $B4/100;
14
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   843
			${$E}[$ens]->{YEAR} += (${$E}[$ens]->{YEAR} > 80) ? 1900 : 2000;
40
6a46e9d31106 after Hamburg visit
Andreas Thurnherr <ant@ldeo.columbia.edu>
parents: 39
diff changeset
   844
#		} else {
6a46e9d31106 after Hamburg visit
Andreas Thurnherr <ant@ldeo.columbia.edu>
parents: 39
diff changeset
   845
#			sysseek(WBRF,7,1) || die("$WBRcfn: $!");							# use Y2K RTC instead
6a46e9d31106 after Hamburg visit
Andreas Thurnherr <ant@ldeo.columbia.edu>
parents: 39
diff changeset
   846
#		}
14
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   847
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   848
		sysread(WBRF,$buf,1) == 1 || die("$WBRcfn: $!");
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   849
		$ensNo += unpack('C',$buf) << 16;
43
b63fa355644c commit to merge with changes from EN620
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 42
diff changeset
   850
52
5b07a9b89aee - adapted to work with IMPed moored ADCP data
Andreas Thurnherr <ant@ldeo.columbia.edu>
parents: 51
diff changeset
   851
##		CODE DISABLED BECAUSE IT TAKES TOO MUCH TIME ON LARGE FILES.
5b07a9b89aee - adapted to work with IMPed moored ADCP data
Andreas Thurnherr <ant@ldeo.columbia.edu>
parents: 51
diff changeset
   852
##		NOT SURE HOW COMMON DUPLICATE ENSEMBLES ARE.		
5b07a9b89aee - adapted to work with IMPed moored ADCP data
Andreas Thurnherr <ant@ldeo.columbia.edu>
parents: 51
diff changeset
   853
##
5b07a9b89aee - adapted to work with IMPed moored ADCP data
Andreas Thurnherr <ant@ldeo.columbia.edu>
parents: 51
diff changeset
   854
##		for (my($i)=$ens; $i>0; $i--) {											# check for duplicate ens; e.g. 2018 S4P 24UL
5b07a9b89aee - adapted to work with IMPed moored ADCP data
Andreas Thurnherr <ant@ldeo.columbia.edu>
parents: 51
diff changeset
   855
##			if (${$E}[$i]->{NUMBER} == $ensNo) {									
5b07a9b89aee - adapted to work with IMPed moored ADCP data
Andreas Thurnherr <ant@ldeo.columbia.edu>
parents: 51
diff changeset
   856
##				$RDI_PD0_IO::File_Dirty = 1;
5b07a9b89aee - adapted to work with IMPed moored ADCP data
Andreas Thurnherr <ant@ldeo.columbia.edu>
parents: 51
diff changeset
   857
##				print(STDERR "WARNING (RDI_PD0_IO): duplicate ensemble $ensNo skipped\n");
5b07a9b89aee - adapted to work with IMPed moored ADCP data
Andreas Thurnherr <ant@ldeo.columbia.edu>
parents: 51
diff changeset
   858
##				pop(@{$E});
5b07a9b89aee - adapted to work with IMPed moored ADCP data
Andreas Thurnherr <ant@ldeo.columbia.edu>
parents: 51
diff changeset
   859
##				$ens--;
5b07a9b89aee - adapted to work with IMPed moored ADCP data
Andreas Thurnherr <ant@ldeo.columbia.edu>
parents: 51
diff changeset
   860
##				next ENSEMBLE;
5b07a9b89aee - adapted to work with IMPed moored ADCP data
Andreas Thurnherr <ant@ldeo.columbia.edu>
parents: 51
diff changeset
   861
##			}
5b07a9b89aee - adapted to work with IMPed moored ADCP data
Andreas Thurnherr <ant@ldeo.columbia.edu>
parents: 51
diff changeset
   862
##		}
51
148c092b3a09 after somewhat suspicous RDI_PD0_IO.pl merge and just before adding
Andreas Thurnherr <ant@ldeo.columbia.edu>
parents: 50
diff changeset
   863
		    
14
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   864
		${$E}[$ens]->{NUMBER} = $ensNo;
51
148c092b3a09 after somewhat suspicous RDI_PD0_IO.pl merge and just before adding
Andreas Thurnherr <ant@ldeo.columbia.edu>
parents: 50
diff changeset
   865
	    
14
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   866
		sysread(WBRF,$buf,30) == 30 || die("$WBRcfn: $!");
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   867
		(${$E}[$ens]->{BUILT_IN_TEST_ERROR},${$E}[$ens]->{SPEED_OF_SOUND},
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   868
		 ${$E}[$ens]->{XDUCER_DEPTH},${$E}[$ens]->{HEADING},
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   869
		 ${$E}[$ens]->{PITCH},${$E}[$ens]->{ROLL},
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   870
		 ${$E}[$ens]->{SALINITY},${$E}[$ens]->{TEMPERATURE},
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   871
		 ${$E}[$ens]->{MIN_PRE_PING_WAIT_TIME},$B1,$B2,
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   872
		 ${$E}[$ens]->{HEADING_STDDEV},${$E}[$ens]->{PITCH_STDDEV},
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   873
		 ${$E}[$ens]->{ROLL_STDDEV},${$E}[$ens]->{ADC_XMIT_CURRENT},
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   874
		 ${$E}[$ens]->{ADC_XMIT_VOLTAGE},${$E}[$ens]->{ADC_AMBIENT_TEMPERATURE},
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   875
		 ${$E}[$ens]->{ADC_PRESSURE_PLUS},${$E}[$ens]->{ADC_PRESSURE_MINUS},
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   876
		 ${$E}[$ens]->{ADC_ATTITUDE_TEMPERATURE},${$E}[$ens]->{ADC_ATTITUDE},
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   877
		 ${$E}[$ens]->{ADC_CONTAMINATION})
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   878
			= unpack('vvvvvvvvCCCCCCCCCCCCCC',$buf);
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   879
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   880
		${$E}[$ens]->{BUILT_IN_TEST_ERROR} = undef
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   881
			unless (${$E}[$ens]->{BUILT_IN_TEST_ERROR});
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   882
		$BIT_errors++ if (${$E}[$ens]->{BUILT_IN_TEST_ERROR});
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   883
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   884
		${$E}[$ens]->{XDUCER_DEPTH} /= 10;
18
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 14
diff changeset
   885
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 14
diff changeset
   886
		#-------------------------------------------------
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 14
diff changeset
   887
		# IMP EXTENSION: PITCH/ROLL/HEADING CAN BE MISSING
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 14
diff changeset
   888
		#-------------------------------------------------
51
148c092b3a09 after somewhat suspicous RDI_PD0_IO.pl merge and just before adding
Andreas Thurnherr <ant@ldeo.columbia.edu>
parents: 50
diff changeset
   889
	    
18
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 14
diff changeset
   890
		${$E}[$ens]->{HEADING} = (${$E}[$ens]->{HEADING} == 0xF000)
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 14
diff changeset
   891
							   ? undef
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 14
diff changeset
   892
							   : ${$E}[$ens]->{HEADING} / 100;
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 14
diff changeset
   893
		${$E}[$ens]->{PITCH} = (${$E}[$ens]->{PITCH} == 0x8000)
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 14
diff changeset
   894
							 ? undef
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 14
diff changeset
   895
							 : unpack('s',pack('S',${$E}[$ens]->{PITCH})) / 100;
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 14
diff changeset
   896
		${$E}[$ens]->{ROLL}  = (${$E}[$ens]->{ROLL} == 0x8000)
51
148c092b3a09 after somewhat suspicous RDI_PD0_IO.pl merge and just before adding
Andreas Thurnherr <ant@ldeo.columbia.edu>
parents: 50
diff changeset
   897
							 ? undef
148c092b3a09 after somewhat suspicous RDI_PD0_IO.pl merge and just before adding
Andreas Thurnherr <ant@ldeo.columbia.edu>
parents: 50
diff changeset
   898
							 : unpack('s',pack('S',${$E}[$ens]->{ROLL})) / 100;
148c092b3a09 after somewhat suspicous RDI_PD0_IO.pl merge and just before adding
Andreas Thurnherr <ant@ldeo.columbia.edu>
parents: 50
diff changeset
   899
							 
18
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 14
diff changeset
   900
		${$E}[$ens]->{TEMPERATURE} = unpack('s',pack('S',${$E}[$ens]->{TEMPERATURE})) / 100;
14
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   901
		${$E}[$ens]->{MIN_PRE_PING_WAIT_TIME} *= 60;
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   902
		${$E}[$ens]->{MIN_PRE_PING_WAIT_TIME} += $B1 + $B2/100;
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   903
		${$E}[$ens]->{PITCH_STDDEV} /= 10;
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   904
		${$E}[$ens]->{ROLL_STDDEV} /= 10;
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   905
40
6a46e9d31106 after Hamburg visit
Andreas Thurnherr <ant@ldeo.columbia.edu>
parents: 39
diff changeset
   906
		if (($fixed_leader_bytes==53 || $fixed_leader_bytes==59) && 		# Workhorse instruments
6a46e9d31106 after Hamburg visit
Andreas Thurnherr <ant@ldeo.columbia.edu>
parents: 39
diff changeset
   907
			!defined($RDI_PD0_IO::IGNORE_Y2K_CLOCK)) {
14
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   908
			sysread(WBRF,$buf,23) == 23 || die("$WBRcfn: $!");
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   909
			(${$E}[$ens]->{ERROR_STATUS_WORD},
51
148c092b3a09 after somewhat suspicous RDI_PD0_IO.pl merge and just before adding
Andreas Thurnherr <ant@ldeo.columbia.edu>
parents: 50
diff changeset
   910
			 $dummy,${$E}[$ens]->{PRESSURE},${$E}[$ens]->{PRESSURE_STDDEV},
14
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   911
			 $dummy,${$E}[$ens]->{YEAR},$B3,${$E}[$ens]->{MONTH},
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   912
			 ${$E}[$ens]->{DAY},${$E}[$ens]->{HOUR},${$E}[$ens]->{MINUTE},
50
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 49
diff changeset
   913
			 ${$E}[$ens]->{SECOND},$B4)
14
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   914
				= unpack('VvVVCCCCCCCCC',$buf);
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   915
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   916
			${$E}[$ens]->{PRESSURE} /= 1000;
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   917
			${$E}[$ens]->{PRESSURE_STDDEV} /= 1000;
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   918
			${$E}[$ens]->{YEAR} *= 100; ${$E}[$ens]->{YEAR} += $B3;
50
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 49
diff changeset
   919
			${$E}[$ens]->{SECOND} += $B4/100;
14
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   920
		}
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   921
51
148c092b3a09 after somewhat suspicous RDI_PD0_IO.pl merge and just before adding
Andreas Thurnherr <ant@ldeo.columbia.edu>
parents: 50
diff changeset
   922
#		THE FOLLOWING LINE OF CODE WAS REMOVED 7/30/2016 WHEN I ADDED A POP
36
515b06dae59c version at end of ECOGIG EN586 cruise
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 32
diff changeset
   923
#		TO THE last STATEMENT ABOVE (INCOMPLETE ENSEMBLE)
42
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 40
diff changeset
   924
#		THE LINE WAS RE-ENABLED ON 12/23/2017 BECAUSE OTHERWISE THE
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 40
diff changeset
   925
#		ANSLOPE II PROFILES IN THE HOWTO CANNOT BE READ.
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 40
diff changeset
   926
		pop(@{$E}),last if (${$E}[$ens]->{MONTH}>12);						# 10/15/2014; IWISE#145 UL ???
21
0b5bbe60131c version sent to P16N
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 18
diff changeset
   927
14
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   928
		if ($fixed_leader_bytes == 58) {									# Explorer DVL
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   929
			sysread(WBRF,$buf,14) == 14 || die("$WBRcfn: $!");
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   930
			(${$E}[$ens]->{ERROR_STATUS_WORD},
51
148c092b3a09 after somewhat suspicous RDI_PD0_IO.pl merge and just before adding
Andreas Thurnherr <ant@ldeo.columbia.edu>
parents: 50
diff changeset
   931
			 $dummy,${$E}[$ens]->{PRESSURE},${$E}[$ens]->{PRESSURE_STDDEV})
14
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   932
				= unpack('VvVV',$buf);
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   933
			${$E}[$ens]->{PRESSURE} /= 1000;
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   934
			${$E}[$ens]->{PRESSURE_STDDEV} /= 1000;
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   935
		}
51
148c092b3a09 after somewhat suspicous RDI_PD0_IO.pl merge and just before adding
Andreas Thurnherr <ant@ldeo.columbia.edu>
parents: 50
diff changeset
   936
	    
14
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   937
		${$E}[$ens]->{DATE}
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   938
			= sprintf("%02d/%02d/%d",${$E}[$ens]->{MONTH},
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   939
									 ${$E}[$ens]->{DAY},
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   940
									 ${$E}[$ens]->{YEAR});
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   941
		${$E}[$ens]->{TIME}
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   942
			= sprintf("%02d:%02d:%05.02f",${$E}[$ens]->{HOUR},
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   943
										  ${$E}[$ens]->{MINUTE},
50
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 49
diff changeset
   944
									 	  ${$E}[$ens]->{SECOND});
14
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   945
		${$E}[$ens]->{DAYNO}
40
6a46e9d31106 after Hamburg visit
Andreas Thurnherr <ant@ldeo.columbia.edu>
parents: 39
diff changeset
   946
			= &_dayNo(${$E}[$ens]->{YEAR},${$E}[$ens]->{MONTH},${$E}[$ens]->{DAY},
50
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 49
diff changeset
   947
					  ${$E}[$ens]->{HOUR},${$E}[$ens]->{MINUTE},${$E}[$ens]->{SECOND});
14
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   948
43
b63fa355644c commit to merge with changes from EN620
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 42
diff changeset
   949
		# when analyzing an STA file from an OS75 SADCP (Poseidon),
14
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   950
		# I noticed that there is no time information. This causes
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   951
		# timegm to bomb. 
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   952
		if (${$E}[$ens]->{MONTH} == 0) {					# no time info
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   953
			${$E}[$ens]->{UNIX_TIME} = 0;
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   954
			${$E}[$ens]->{SECNO} = 0;
51
148c092b3a09 after somewhat suspicous RDI_PD0_IO.pl merge and just before adding
Andreas Thurnherr <ant@ldeo.columbia.edu>
parents: 50
diff changeset
   955
		} else {
43
b63fa355644c commit to merge with changes from EN620
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 42
diff changeset
   956
#			print(STDERR "[$ens]->${$E}[$ens]->{MINUTE}:${$E}[$ens]->{HOUR},${$E}[$ens]->{DAY},${$E}[$ens]->{MONTH},${$E}[$ens]->{YEAR}-<\n");
14
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   957
			${$E}[$ens]->{UNIX_TIME}
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   958
				= timegm(0,${$E}[$ens]->{MINUTE},
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   959
						   ${$E}[$ens]->{HOUR},
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   960
						   ${$E}[$ens]->{DAY},
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   961
						   ${$E}[$ens]->{MONTH}-1,			# timegm jan==0!!!
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   962
						   ${$E}[$ens]->{YEAR})
50
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 49
diff changeset
   963
				  + ${$E}[$ens]->{SECOND};
14
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   964
	
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   965
			$dayStart = timegm(0,0,0,${$E}[$ens]->{DAY},
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   966
									 ${$E}[$ens]->{MONTH}-1,
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   967
									 ${$E}[$ens]->{YEAR})
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   968
				unless defined($dayStart);
51
148c092b3a09 after somewhat suspicous RDI_PD0_IO.pl merge and just before adding
Andreas Thurnherr <ant@ldeo.columbia.edu>
parents: 50
diff changeset
   969
			${$E}[$ens]->{SECNO} = ${$E}[$ens]->{UNIX_TIME} - $dayStart;
148c092b3a09 after somewhat suspicous RDI_PD0_IO.pl merge and just before adding
Andreas Thurnherr <ant@ldeo.columbia.edu>
parents: 50
diff changeset
   970
		}
14
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   971
51
148c092b3a09 after somewhat suspicous RDI_PD0_IO.pl merge and just before adding
Andreas Thurnherr <ant@ldeo.columbia.edu>
parents: 50
diff changeset
   972
		sysseek(WBRF,$start_ens+$WBRofs[0]+4,0) 	# System Config / Fixed Leader
14
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   973
			|| die("$WBRcfn: $!");
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   974
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   975
		sysread(WBRF,$buf,5) == 5 || die("$WBRcfn: $!");
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   976
		($B1,$dummy,$dummy,$dummy,${$E}[$ens]->{N_BEAMS_USED})
51
148c092b3a09 after somewhat suspicous RDI_PD0_IO.pl merge and just before adding
Andreas Thurnherr <ant@ldeo.columbia.edu>
parents: 50
diff changeset
   977
			= unpack('CCCCC',$buf);     
148c092b3a09 after somewhat suspicous RDI_PD0_IO.pl merge and just before adding
Andreas Thurnherr <ant@ldeo.columbia.edu>
parents: 50
diff changeset
   978
		${$E}[$ens]->{XDUCER_FACING_UP}   = 1 if	 ($B1 & 0x80);
14
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   979
		${$E}[$ens]->{XDUCER_FACING_DOWN} = 1 unless ($B1 & 0x80);
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   980
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   981
		#--------------------
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   982
		# Velocity Data
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   983
		#--------------------
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   984
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   985
		my($ndata) = $nbins * 4;
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   986
48
cdc74ebada81 after partial adaptation to RTI files
Andreas Thurnherr <ant@ldeo.columbia.edu>
parents: 45
diff changeset
   987
		my($vel_di) = WBRdtaIndex(0x0100);
58
78607e2e8add Nortek files
Andreas Thurnherr <ant@ldeo.columbia.edu>
parents: 57
diff changeset
   988
		if (defined($vel_di)) {
78607e2e8add Nortek files
Andreas Thurnherr <ant@ldeo.columbia.edu>
parents: 57
diff changeset
   989
			sysseek(WBRF,$start_ens+$WBRofs[$vel_di],0) || die("$WBRcfn: $!");
78607e2e8add Nortek files
Andreas Thurnherr <ant@ldeo.columbia.edu>
parents: 57
diff changeset
   990
			sysread(WBRF,$buf,2+$ndata*2) == 2+$ndata*2 || die("$WBRcfn: $!");
78607e2e8add Nortek files
Andreas Thurnherr <ant@ldeo.columbia.edu>
parents: 57
diff changeset
   991
			($id,@dta) = unpack("vv$ndata",$buf);
78607e2e8add Nortek files
Andreas Thurnherr <ant@ldeo.columbia.edu>
parents: 57
diff changeset
   992
	
78607e2e8add Nortek files
Andreas Thurnherr <ant@ldeo.columbia.edu>
parents: 57
diff changeset
   993
			for ($i=0,$bin=0; $bin<$nbins; $bin++) {
78607e2e8add Nortek files
Andreas Thurnherr <ant@ldeo.columbia.edu>
parents: 57
diff changeset
   994
				for ($beam=0; $beam<4; $beam++,$i++) {
78607e2e8add Nortek files
Andreas Thurnherr <ant@ldeo.columbia.edu>
parents: 57
diff changeset
   995
					${$E}[$ens]->{VELOCITY}[$bin][$beam] =
78607e2e8add Nortek files
Andreas Thurnherr <ant@ldeo.columbia.edu>
parents: 57
diff changeset
   996
						unpack('s',pack('S',$dta[$i])) / 1000
78607e2e8add Nortek files
Andreas Thurnherr <ant@ldeo.columbia.edu>
parents: 57
diff changeset
   997
							if ($dta[$i] != 0x8000);
78607e2e8add Nortek files
Andreas Thurnherr <ant@ldeo.columbia.edu>
parents: 57
diff changeset
   998
				}
78607e2e8add Nortek files
Andreas Thurnherr <ant@ldeo.columbia.edu>
parents: 57
diff changeset
   999
	        }
78607e2e8add Nortek files
Andreas Thurnherr <ant@ldeo.columbia.edu>
parents: 57
diff changeset
  1000
	    } else {
78607e2e8add Nortek files
Andreas Thurnherr <ant@ldeo.columbia.edu>
parents: 57
diff changeset
  1001
#   		die("no velocity data in ensemble #$ensNo\n");
78607e2e8add Nortek files
Andreas Thurnherr <ant@ldeo.columbia.edu>
parents: 57
diff changeset
  1002
			print(STDERR "WARNING: no velocity data in ensemble #$ensNo\n");
78607e2e8add Nortek files
Andreas Thurnherr <ant@ldeo.columbia.edu>
parents: 57
diff changeset
  1003
        }	    
14
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
  1004
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
  1005
		#--------------------
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
  1006
		# Correlation Data
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
  1007
		#--------------------
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
  1008
48
cdc74ebada81 after partial adaptation to RTI files
Andreas Thurnherr <ant@ldeo.columbia.edu>
parents: 45
diff changeset
  1009
		my($corr_di) = WBRdtaIndex(0x0200);
58
78607e2e8add Nortek files
Andreas Thurnherr <ant@ldeo.columbia.edu>
parents: 57
diff changeset
  1010
		if (defined($corr_di)) {
78607e2e8add Nortek files
Andreas Thurnherr <ant@ldeo.columbia.edu>
parents: 57
diff changeset
  1011
			sysseek(WBRF,$start_ens+$WBRofs[$corr_di],0) || die("$WBRcfn: $!");
78607e2e8add Nortek files
Andreas Thurnherr <ant@ldeo.columbia.edu>
parents: 57
diff changeset
  1012
			sysread(WBRF,$buf,2+$ndata) == 2+$ndata || die("$WBRcfn: $!");
78607e2e8add Nortek files
Andreas Thurnherr <ant@ldeo.columbia.edu>
parents: 57
diff changeset
  1013
			($id,@dta) = unpack("vC$ndata",$buf);
78607e2e8add Nortek files
Andreas Thurnherr <ant@ldeo.columbia.edu>
parents: 57
diff changeset
  1014
	
78607e2e8add Nortek files
Andreas Thurnherr <ant@ldeo.columbia.edu>
parents: 57
diff changeset
  1015
			for ($i=0,$bin=0; $bin<$nbins; $bin++) {
78607e2e8add Nortek files
Andreas Thurnherr <ant@ldeo.columbia.edu>
parents: 57
diff changeset
  1016
				for ($beam=0; $beam<4; $beam++,$i++) {
78607e2e8add Nortek files
Andreas Thurnherr <ant@ldeo.columbia.edu>
parents: 57
diff changeset
  1017
					${$E}[$ens]->{CORRELATION}[$bin][$beam] = $dta[$i]
78607e2e8add Nortek files
Andreas Thurnherr <ant@ldeo.columbia.edu>
parents: 57
diff changeset
  1018
						if ($dta[$i]);
78607e2e8add Nortek files
Andreas Thurnherr <ant@ldeo.columbia.edu>
parents: 57
diff changeset
  1019
				}
78607e2e8add Nortek files
Andreas Thurnherr <ant@ldeo.columbia.edu>
parents: 57
diff changeset
  1020
	        }
78607e2e8add Nortek files
Andreas Thurnherr <ant@ldeo.columbia.edu>
parents: 57
diff changeset
  1021
	    } else {
78607e2e8add Nortek files
Andreas Thurnherr <ant@ldeo.columbia.edu>
parents: 57
diff changeset
  1022
#  			die("no correlation data in ensemble #$ensNo\n")
78607e2e8add Nortek files
Andreas Thurnherr <ant@ldeo.columbia.edu>
parents: 57
diff changeset
  1023
  			print(STDERR "WARNING: no correlation data in ensemble #$ensNo\n")
78607e2e8add Nortek files
Andreas Thurnherr <ant@ldeo.columbia.edu>
parents: 57
diff changeset
  1024
  		}
14
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
  1025
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
  1026
		#--------------------
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
  1027
		# Echo Intensity Data
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
  1028
		#--------------------
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
  1029
48
cdc74ebada81 after partial adaptation to RTI files
Andreas Thurnherr <ant@ldeo.columbia.edu>
parents: 45
diff changeset
  1030
		my($echo_di) = WBRdtaIndex(0x0300);
58
78607e2e8add Nortek files
Andreas Thurnherr <ant@ldeo.columbia.edu>
parents: 57
diff changeset
  1031
		if (defined($echo_di)) {
78607e2e8add Nortek files
Andreas Thurnherr <ant@ldeo.columbia.edu>
parents: 57
diff changeset
  1032
			sysseek(WBRF,$start_ens+$WBRofs[$echo_di],0) || die("$WBRcfn: $!");
78607e2e8add Nortek files
Andreas Thurnherr <ant@ldeo.columbia.edu>
parents: 57
diff changeset
  1033
			sysread(WBRF,$buf,2+$ndata) == 2+$ndata || die("$WBRcfn: $!");
78607e2e8add Nortek files
Andreas Thurnherr <ant@ldeo.columbia.edu>
parents: 57
diff changeset
  1034
			($id,@dta) = unpack("vC$ndata",$buf);
78607e2e8add Nortek files
Andreas Thurnherr <ant@ldeo.columbia.edu>
parents: 57
diff changeset
  1035
	
78607e2e8add Nortek files
Andreas Thurnherr <ant@ldeo.columbia.edu>
parents: 57
diff changeset
  1036
			$id == 0x0300 ||
78607e2e8add Nortek files
Andreas Thurnherr <ant@ldeo.columbia.edu>
parents: 57
diff changeset
  1037
				die(sprintf($FmtErr,$WBRcfn,"Echo Intensity",$id,$ensNo));
78607e2e8add Nortek files
Andreas Thurnherr <ant@ldeo.columbia.edu>
parents: 57</