author | Andreas Thurnherr <ant@ldeo.columbia.edu> |
Sun, 21 Oct 2018 20:01:48 -0400 | |
changeset 45 | 5767cbe470a0 |
parent 44 | b7654ea68af6 |
parent 43 | b63fa355644c |
child 47 | 494a76548e94 |
child 48 | cdc74ebada81 |
permissions | -rw-r--r-- |
14 | 1 |
#====================================================================== |
40
6a46e9d31106
after Hamburg visit
Andreas Thurnherr <ant@ldeo.columbia.edu>
parents:
39
diff
changeset
|
2 |
# R D I _ P D 0 _ I O . P L |
14 | 3 |
# doc: Sat Jan 18 14:54:43 2003 |
43
b63fa355644c
commit to merge with changes from EN620
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
42
diff
changeset
|
4 |
# dlm: Tue Jun 12 19:10:08 2018 |
14 | 5 |
# (c) 2003 A.M. Thurnherr |
43
b63fa355644c
commit to merge with changes from EN620
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
42
diff
changeset
|
6 |
# uE-Info: 115 72 NIL 0 0 72 2 2 4 NIL ofnI |
14 | 7 |
#====================================================================== |
39 | 8 |
|
37 | 9 |
# Read RDI PD0 binary data files (*.[0-9][0-9][0-9]) |
39 | 10 |
|
14 | 11 |
# HISTORY: |
12 |
# Jan 18, 2003: - incepted aboard the Aurora Australis (KAOS) |
|
13 |
# Jan 19, 2003: - continued |
|
14 |
# Jan 20, 2003: - replaced INTENSITY by AMPLITUDE |
|
15 |
# Jan 21, 2003: - changed heading-correction field names |
|
16 |
# Jan 27, 2003: - cosmetics |
|
17 |
# Feb 14, 2003: - moved BT setup into header |
|
18 |
# Mar 15, 2003: - moved 10th xmit voltage into header as BATTERY field |
|
19 |
# - removed again, because values are not meaningful |
|
20 |
# Feb 24, 2004: - continued aboard Nathaniel B. Palmer (Anslope II) |
|
21 |
# - BUG: ensemble # was wrong on error messages |
|
22 |
# Feb 26, 2004: - removed ESW_ERROR and bitmasking of ERROR_STATUS_WORD |
|
23 |
# Feb 27, 2004: - removed some unused (commented-out) baggage |
|
24 |
# Mar 11, 2004: - BUG: renamed ACD -> ADC |
|
25 |
# Mar 18, 2004: - cosmetics |
|
26 |
# Mar 30, 2004: - rewrote to speed up reading; new version takes |
|
27 |
# ~40% less time |
|
28 |
# Sep 14, 2005: - made BT data optional (NUMBER_OF_DATA_TYPES) |
|
29 |
# - added DATA_FORMAT |
|
30 |
# Sep 15, 2005: - debugged |
|
31 |
# - implement checksum to robustly find EOF |
|
32 |
# - renamed to RDI_BB_Read.pl |
|
33 |
# - BUG: had used POSIX::mktime with wrong month def! |
|
34 |
# Oct 30, 2005: - added WH300 FW16.27 file format |
|
35 |
# - added DATA_FORMAT_VARIANT |
|
36 |
# - changed semantics so that first valid ensemble is |
|
39 | 37 |
# in E[0] (instead of E[$ensNo-1]) |
14 | 38 |
# Nov 8, 2005: - replaced UNIXTIME by UNIX_TIME |
39 |
# - added SECNO |
|
40 |
# Aug 31: 2006: - added DAYNO |
|
41 |
# Aug 1, 2007: - BUG: typo in monthLength() |
|
42 |
# Sep 18, 2007: - modified readHeader() readDta() WBRhdr() WBRens() to |
|
43 |
# conserve memory (no large arrays as retvals) |
|
44 |
# Jun 4, 2008: - BUG: BB150 code was not considered on Sep 18, 2007 |
|
45 |
# Aug 15, 2010: - downgraded "unexpected number of data types" from error to warning |
|
46 |
# - BUG: WBRcfn had not been set correctly |
|
47 |
# - modified to allow processing files without time info |
|
48 |
# May 12, 2011: - added code to report built-in-test errors |
|
49 |
# Mar 19, 2013: - added support for WH600 data file (58 fixed leader bytes) |
|
50 |
# Mar 20, 2013: - removed DATA_FORMAT stuff |
|
51 |
# - added support for BT data in subset of ensembles |
|
52 |
# Apr 29, 2013: - changed semantics to assume EOF when unexpected number of data types |
|
53 |
# are present in an ensemble |
|
54 |
# Nov 25, 2013: - renamed from [RDI_BB_Read.pl] |
|
55 |
# - begin implementing WBWens() |
|
56 |
# - checkEnsemble() expunged |
|
18 | 57 |
# Mar 3, 2014: - BUG: WBPens() did not handle incomple ensembles at EOF correctly |
58 |
# Mar 4, 2014: - added support for DATA_SOURCE_ID |
|
59 |
# Apr 24, 2014: - added debug statements to log %-GOOD values |
|
60 |
# May 6, 2014: - loosened input format checks |
|
61 |
# May 7, 2014: - removed BT_present flag |
|
21 | 62 |
# Sep 6, 2014: - adapted WBRhdr to >7 data types |
63 |
# Oct 15, 2014: - implemented work-around for readData() not recognizing |
|
64 |
# incomplete ensemble at the end, which seems to imply that there is |
|
39 | 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 | 67 |
# Dec 18, 2015: - added most data types to WBPofs() |
68 |
# - BUG: WBPens() requires round() for scaled values |
|
31 | 69 |
# Jan 9, 2016: - removed system() from writeData() |
70 |
# - BUG: WBRhdr() did not set DATA_SOURCE_ID |
|
29 | 71 |
# - added PRODUCER |
31 | 72 |
# - BUG: writeData() did not work correctly for ECOGIG OC26 moored data (spaces in filename?) |
73 |
# - added support for patching coordinate system |
|
32 | 74 |
# Feb 16, 2016: - added transducer orientation to WBPens() |
75 |
# - BUG: most WBPens() error messages used wrong file name |
|
76 |
# Feb 23, 2016: - changed WBRhdr() to use 2nd ensemble (with correct data-source id) |
|
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 | 81 |
# Aug 5, 2016: - cosmetics |
82 |
# Aug 23, 2016: - added &clearEns() |
|
83 |
# Nov 9, 2016: - made WBRhdr() return undef on "empty" files |
|
84 |
# Nov 18, 2016: - BUG: ensNo was not reported correctly in format errors |
|
85 |
# Nov 23, 2016: - no longer set pitch/roll/heading to undef in clearEns() |
|
86 |
# Mar 7, 2016: - renamed round() to stop clashing with ANTSLIB |
|
39 | 87 |
# May 18, 2017: - maded readHeader() more permissive (checkFmt flag) |
88 |
# - added partial support for Ocean Surveyor data |
|
89 |
# Aug 1, 2017: BUG: minor typo in ocean surveyor code (err check not done?) |
|
90 |
# Aug 7, 2017: - added LAG_LENGTH |
|
91 |
# - added SPEED_OF_SOUND to header |
|
92 |
# Aug 8, 2017: - replaced croak() by die() |
|
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 | 95 |
# - added support for RDI_PD0_IO::IGNORE_Y2K_CLOCK |
96 |
# Dec 7, 2017: - added suppress_error to readHeader() |
|
97 |
# Dec 23, 2017: - BUG: could no longer read Anslope II raw files |
|
98 |
# - added support for patching ADCP time data |
|
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 |
b63fa355644c
commit to merge with changes from EN620
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
42
diff
changeset
|
115 |
# Jun 12, 2018: - BUG: IMPed files did not pass the garbage detection |
39 | 116 |
|
14 | 117 |
# FIRMWARE VERSIONS: |
118 |
# It appears that different firmware versions generate different file |
|
119 |
# structures. Currently (Sep 2005) these routines have been tested |
|
120 |
# with the following firmware versions (as reported by [listHdr]): |
|
121 |
# |
|
39 | 122 |
# Firmw. DATA_FORMAT(_VARIANT) Owner Cruise FIXED_LEADER_LENGTH |
14 | 123 |
#------------------------------------------------------------ |
39 | 124 |
# 05.52 BB150 (1) UH CLIVAR/P16S 42 |
14 | 125 |
# 16.12 WH300 (1) FSU A0304 53 |
39 | 126 |
# 16.21 WH300 (1) LDEO NBP0402 53 |
127 |
# 16.27 WH300 (2) Nash ? 59 |
|
128 |
||
29 | 129 |
# PD0 FILE FORMAT EXTENSIONS: |
130 |
# |
|
32 | 131 |
# - file creator encoded in DATA_SOURCE_ID |
132 |
# |
|
133 |
# - first ensemble uses default RDI DATA_SOURCE_ID because the LDEO_IX |
|
134 |
# software assumes this |
|
135 |
# |
|
39 | 136 |
# - DATA_SOURCE_ID = 0x7F original TRDI PD0 file |
29 | 137 |
# |
43
b63fa355644c
commit to merge with changes from EN620
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
42
diff
changeset
|
138 |
# - DATA_SOURCE_ID = 0xA0 | PATCHED_MASK produced by IMP+LADCP, KVH+LADCP |
29 | 139 |
# PATCHED_MASK & 0x04: pitch value has been patched |
140 |
# PATCHED_MASK & 0x02: roll value has been patched |
|
141 |
# PATCHED_MASK & 0x01: heading value has been patched |
|
142 |
# - PITCH & ROLL can be missing (0x8000 badval as in velocities) |
|
143 |
# - HEADING can be missing (0xF000 badval, as 0x8000 is valid 327.68 heading) |
|
144 |
# |
|
31 | 145 |
# - DATA_SOURCE_ID = 0xE0 produced by editPD0 |
39 | 146 |
|
14 | 147 |
# NOTES: |
148 |
# - RDI stores data in VAX/Intel byte order (little endian) |
|
149 |
# - the output data structure does not exactly mirror the file data |
|
150 |
# structure; the header is not stored at all and the fixed leader |
|
151 |
# data are not duplicated in every ensemble |
|
152 |
# - in the RDI files some fields that logically belong into the header |
|
153 |
# or the fixed leader (e.g. BT_MIN_CORRELATION) appear in the |
|
154 |
# ensemble data --- these are not read on input |
|
155 |
# - the field names are generally unabbreviated except for |
|
156 |
# BT (= Bottom Track), RL (= Reference Layer), MIN and MAX |
|
157 |
# - all arrays are 0-referenced, but the ensemble number is not! |
|
158 |
# - a list of filenames can be be passed to readData() so that |
|
159 |
# files split onto several memory cards (typically .000 .001 &c) |
|
160 |
# can be read --- not sure if this works, actually |
|
161 |
# - the RDI manuals are not entirely clear everywhere; I have made |
|
162 |
# guesses in some cases, but they should not affect the main |
|
163 |
# fields of interest |
|
164 |
# - some fields in the fixed leader are not really fixed in a LADCP |
|
165 |
# setting (e.g. xducer orientation); I'v made an educated guess |
|
166 |
# as to which fields to move to the ENS array |
|
167 |
# - all units except pressure are SI, i.e. in m and m/s |
|
168 |
# - I don't understand the ERROR_STATUS_WORD; here's what 3 different |
|
169 |
# instruments returned: |
|
39 | 170 |
# 0x88000100 FSU instrument during A0304 (Firmware 16.12) |
14 | 171 |
# 0x88008180 LDEO uplooker (slave) during NBP0402 (Firmware 16.21) |
172 |
# 0x00008180 LDEO downlooker (master) during NBP0402 (Firmware 16.21) |
|
173 |
# According to the manual (January 2001 version) this would, for example, |
|
174 |
# 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
|
175 |
# - 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
|
176 |
# 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
|
177 |
# is used for Dan Torres' KVH system |
39 | 178 |
|
14 | 179 |
# &readData() returns perl obj (ref to anonymous hash) with the following |
180 |
# structure: |
|
181 |
# |
|
18 | 182 |
# DATA_SOURCE_ID scalar 0x7f (Workhorse, also DVL) |
14 | 183 |
# NUMBER_OF_DATA_TYPES scalar 6 (no BT) or 7 |
184 |
# ENSEMBLE_BYTES scalar ?, number of bytes w/o checksum |
|
185 |
# HEADER_BYTES scalar ? |
|
186 |
# FIXED_LEADER_BYTES scalar 42 for BB150; 53 for WH300, 58 for WH600, 59 for WH300(Nash) |
|
187 |
# VARIABLE_LEADER_BYTES scalar ? |
|
39 | 188 |
# VELOCITY_DATA_BYTES scalar ? |
14 | 189 |
# CORRELATION_DATA_BYTES scalar ? |
190 |
# ECHO_INTENSITY_DATA_BYTES scalar ? |
|
39 | 191 |
# PERCENT_GOOD_DATA_BYTES scalar ? |
14 | 192 |
# BT_PRESENT bool NUMBER_OF_DATA_TYPES == 7 |
193 |
# BT_DATA_BYTES scalar undefined, ? if BT_PRESENT |
|
194 |
# CPU_FW_VER scalar 0--255 |
|
195 |
# CPU_FW_REV scalar 0--255 |
|
196 |
# BEAM_FREQUENCY scalar 75, 150, 300, 600, 1200, 2400 [kHz] |
|
39 | 197 |
# LAG_LENGTH scalar ??? |
198 |
# CONVEX_BEAM_PATTERN bool undefined, 1 |
|
14 | 199 |
# CONCAVE_BEAM_PATTERN bool undefined, 1 |
200 |
# SENSOR_CONFIG scalar 1--3 |
|
201 |
# XDUCER_HEAD_ATTACHED bool undefined, 1 |
|
202 |
# BEAM_ANGLE scalar 15,20,30,undefined=other [deg] |
|
39 | 203 |
# N_BEAMS scalar 4--5 |
14 | 204 |
# N_DEMODS scalar 2--3(???),undefined=n/a |
205 |
# N_BINS scalar 1--128 |
|
206 |
# PINGS_PER_ENSEMBLE scalar 0--16384 |
|
207 |
# BIN_LENGTH scalar 0.01--64 [m] |
|
208 |
# BLANKING_DISTANCE scalar 0-99.99 [m] |
|
39 | 209 |
# MIN_CORRELATION scalar 0--255 |
14 | 210 |
# N_CODE_REPETITIONS scalar 0--255 |
211 |
# MIN_PERCENT_GOOD scalar 1--100 [%] |
|
212 |
# MAX_ERROR_VELOCITY scalar 0--5 [m/s] |
|
213 |
# TIME_BETWEEN_PINGS scalar 0--? [s] |
|
214 |
# BEAM_COORDINATES bool undefined,1 |
|
215 |
# INSTRUMENT_COORDINATES bool undefined,1 |
|
216 |
# SHIP_COORDINATES bool undefined,1 |
|
217 |
# EARTH_COORDINATES bool undefined,1 |
|
39 | 218 |
# PITCH_AND_ROLL_USED bool undefined,1 |
14 | 219 |
# USE_3_BEAM_ON_LOW_CORR bool undefined,1 |
39 | 220 |
# BIN_MAPPING_ALLOWED bool undefined,1 |
221 |
# HEADING_ALIGNMENT scalar -179.99..180 [deg] |
|
222 |
# HEADING_BIAS scalar -179.99..180 [deg] |
|
14 | 223 |
# CALCULATE_SPEED_OF_SOUND bool undefined,1 |
39 | 224 |
# USE_PRESSURE_SENSOR bool undefined,1 |
225 |
# USE_COMPASS bool undefined,1 |
|
14 | 226 |
# USE_PITCH_SENSOR bool undefined,1 |
39 | 227 |
# USE_ROLL_SENSOR bool undefined,1 |
228 |
# USE_CONDUCTIVITY_SENSOR bool undefined,1 |
|
14 | 229 |
# USE_TEMPERATURE_SENSOR bool undefined,1 |
230 |
# SPEED_OF_SOUND_CALCULATED bool undefined,1 |
|
231 |
# PRESSURE_SENSOR_AVAILABLE bool undefined,1 |
|
232 |
# COMPASS_AVAILABLE bool undefined,1 |
|
233 |
# PITCH_SENSOR_AVAILABLE bool undefined,1 |
|
234 |
# ROLL_SENSOR_AVAILABLE bool undefined,1 |
|
235 |
# CONDUCTIVITY_SENSOR_AVAILABLE bool undefined,1 |
|
236 |
# TEMPERATURE_SENSOR_AVAILABLE bool undefined,1 |
|
39 | 237 |
# DISTANCE_TO_BIN1_CENTER scalar 0--655.35 [m] |
14 | 238 |
# TRANSMITTED_PULSE_LENGTH scalar 0--655.35 [m] |
239 |
# RL_FIRST_BIN scalar 1--128 |
|
39 | 240 |
# RL_LAST_BIN scalar 1--128 |
14 | 241 |
# FALSE_TARGET_THRESHOLD scalar 0--254, undefined=disabled |
39 | 242 |
# LOW_LATENCY_SETTING scalar 0--5(???) |
14 | 243 |
# TRANSMIT_LAG_DISTANCE scalar 0--655.35 [m] |
244 |
# CPU_SERIAL_NUMBER scalar undefined, 0--65535 if WH300 |
|
245 |
# NARROW_BANDWIDTH bool undefined,1 (only set if WH300) |
|
246 |
# WIDE_BANDWIDTH bool undefined,1 (only set if WH300) |
|
247 |
# TRANSMIT_POWER scalar undefined, 0--255(high) if WH300 |
|
39 | 248 |
# TRANSMIT_POWER_HIGH bool undefined,1 (only set if WH300) |
14 | 249 |
# BT_PINGS_PER_ENSEMBLE scalar 0--999 |
250 |
# BT_DELAY_BEFORE_REACQUIRE scalar 0--999 |
|
251 |
# BT_MIN_CORRELATION scalar 0--255 |
|
252 |
# BT_MIN_EVAL_AMPLITUDE scalar 0--255 |
|
39 | 253 |
# BT_MIN_PERCENT_GOOD scalar 0--100 [%] |
254 |
# BT_MODE scalar 4,5,6(?) |
|
14 | 255 |
# BT_MAX_ERROR_VELOCITY scalar 0--5 [m/s], undef=not screened |
256 |
# BT_RL_MIN_SIZE scalar 0--99.9 [m] |
|
257 |
# BT_RL_NEAR scalar 0--999.9 [m] |
|
258 |
# BT_RL_FAR scalar 0--999.9 [m] |
|
259 |
# BT_MAX_TRACKING_DEPTH scalar 8--999.9 [m] |
|
39 | 260 |
# ENSEMBLE[ensemble_no-1] array ensemble info |
14 | 261 |
# XDUCER_FACING_UP bool undefined, 1 |
262 |
# XDUCER_FACING_DOWN bool undefined, 1 |
|
263 |
# N_BEAMS_USED scalar 3,4,5(?) |
|
264 |
# NUMBER scalar 1--16777215 |
|
39 | 265 |
# BUILT_IN_TEST_ERROR scalar ?,undefined=none |
14 | 266 |
# SPEED_OF_SOUND scalar 1400--1600 [m/s] |
267 |
# XDUCER_DEPTH scalar 0.1--999.9 [m] |
|
39 | 268 |
# HEADING scalar 0--359.99 [deg] --- IMP EXTENSION: undef |
18 | 269 |
# PITCH scalar -20.00-20.00 [deg] --- IMP EXTENSION: undef |
270 |
# ROLL scalar -20.00-20.00 [deg] --- IMP EXTENSION: undef |
|
14 | 271 |
# SALINITY scalar 0-40 [psu] |
39 | 272 |
# TEMPERATURE scalar -5.00--40.00 [deg] |
14 | 273 |
# MIN_PRE_PING_WAIT_TIME scalar ? [s] |
274 |
# HEADING_STDDEV scalar 0-180 [deg] |
|
275 |
# PITCH_STDDEV scalar 0.0-20.0 [deg] |
|
39 | 276 |
# ROLL_STDDEV scalar 0.0-20.0 [deg] |
14 | 277 |
# ADC_XMIT_CURRENT scalar 0--255 |
278 |
# ADC_XMIT_VOLTAGE scalar 0--255 |
|
39 | 279 |
# ADC_AMBIENT_TEMPERATURE scalar 0--255 |
14 | 280 |
# ADC_PRESSURE_PLUS scalar 0--255 |
281 |
# ADC_PRESSURE_MINUS scalar 0--255 |
|
282 |
# ADC_ATTITUDE_TEMPERATURE scalar 0--255 |
|
283 |
# ADC_ATTITUDE scalar 0--255 |
|
284 |
# ADC_CONTAMINATION scalar 0--255 |
|
285 |
# ERROR_STATUS_WORD scalar undefined, ? (only set if WH300) |
|
286 |
# PRESSURE scalar undefined, ?-? [dbar] (only set if WH300) |
|
39 | 287 |
# PRESSURE_STDDEV scalar undefined, ?-? [dbar] (only set if WH300) |
14 | 288 |
# DATE string MM/DD/YYYY |
289 |
# YEAR scalar ? |
|
290 |
# MONTH scalar 1--12 |
|
39 | 291 |
# DAY scalar 1--31 |
14 | 292 |
# TIME string HH:MM:SS.hh |
293 |
# HOUR scalar 0--23 |
|
294 |
# MINUTE scalar 0--59 |
|
39 | 295 |
# SECONDS scalar 0--59.99 |
14 | 296 |
# UNIX_TIME scalar 0--? |
297 |
# SECNO scalar 0--? (number of seconds since daystart) |
|
298 |
# DAYNO double fractional day number since start of current year (1.0 is midnight Jan 1st) |
|
39 | 299 |
# VELOCITY[bin][beam] scalars -32.767--32.768 [m/s], undef=bad |
300 |
# CORRELATION[bin][beam] scalars 1--255, undefined=bad |
|
301 |
# ECHO_AMPLITUDE[bin][beam] scalars 0--255 |
|
302 |
# PERCENT_GOOD[bin][beam] scalars 0--255 |
|
303 |
# BT_RANGE[beam] scalars tons [m] |
|
304 |
# BT_VELOCITY[beam] scalars see VELOCITY |
|
305 |
# BT_CORRELATION[beam] scalars see CORRELATION |
|
306 |
# BT_EVAL_AMPLITUDE[beam] scalars 0--255 |
|
307 |
# BT_PERCENT_GOOD[beam] scalars see PERCENT_GOOD |
|
308 |
# BT_RL_VELOCITY[beam] scalars see VELOCITY |
|
309 |
# BT_RL_CORRELATION[beam] scalars see CORRELATION |
|
310 |
# BT_RL_ECHO_AMPLITUDE[beam] scalars see ECHO_AMPLITUDE |
|
311 |
# BT_RL_PERCENT_GOOD[beam] scalars see PERCENT_GOOD |
|
312 |
# BT_SIGNAL_STRENGTH[beam] scalars 0--255 |
|
14 | 313 |
# HIGH_GAIN bool 1, undefined |
314 |
# LOW_GAIN bool 1, undefined |
|
39 | 315 |
|
316 |
use strict; |
|
317 |
use Time::Local; # timegm() |
|
318 |
||
14 | 319 |
#---------------------------------------------------------------------- |
320 |
# Time Conversion Subroutines |
|
40
6a46e9d31106
after Hamburg visit
Andreas Thurnherr <ant@ldeo.columbia.edu>
parents:
39
diff
changeset
|
321 |
# - prepended with _ to avoid conflicts with [libconv.pl] |
14 | 322 |
#---------------------------------------------------------------------- |
39 | 323 |
|
40
6a46e9d31106
after Hamburg visit
Andreas Thurnherr <ant@ldeo.columbia.edu>
parents:
39
diff
changeset
|
324 |
sub _monthLength($$) # of days in month |
39 | 325 |
{ |
326 |
my($Y,$M) = @_; |
|
327 |
||
328 |
return 31 if ($M==1 || $M==3 || $M==5 || $M==7 || |
|
329 |
$M==8 || $M==10 || $M==12); |
|
330 |
return 30 if ($M==4 || $M==6 || $M==9 || $M==11); |
|
331 |
return 28 if ($Y%4 != 0); |
|
332 |
return 29 if ($Y%100 != 0); |
|
333 |
return 28 if ($Y%400 > 0); |
|
334 |
return 29; |
|
335 |
} |
|
336 |
||
337 |
{ my($epoch,$lM,$lD,$lY,$ldn); # static scope |
|
338 |
||
40
6a46e9d31106
after Hamburg visit
Andreas Thurnherr <ant@ldeo.columbia.edu>
parents:
39
diff
changeset
|
339 |
sub _dayNo($$$$$$) |
39 | 340 |
{ |
341 |
my($Y,$M,$D,$h,$m,$s) = @_; |
|
342 |
my($dn); |
|
343 |
||
344 |
if ($Y==$lY && $M==$lM && $D==$lD) { # same day as last samp |
|
345 |
$dn = $ldn; |
|
346 |
} else { # new day |
|
347 |
$epoch = $Y unless defined($epoch); # 1st call |
|
348 |
$lY = $Y; $lM = $M; $lD = $D; # store |
|
349 |
||
350 |
for ($dn=0,my($cY)=$epoch; $cY<$Y; $cY++) { # multiple years |
|
40
6a46e9d31106
after Hamburg visit
Andreas Thurnherr <ant@ldeo.columbia.edu>
parents:
39
diff
changeset
|
351 |
$dn += 337 + &_monthLength($Y,$M); |
39 | 352 |
} |
353 |
||
354 |
$dn += $D; # day in month |
|
355 |
while (--$M > 0) { # preceding months |
|
40
6a46e9d31106
after Hamburg visit
Andreas Thurnherr <ant@ldeo.columbia.edu>
parents:
39
diff
changeset
|
356 |
$dn += &_monthLength($Y,$M); |
39 | 357 |
} |
358 |
||
359 |
$ldn = $dn; # store |
|
14 | 360 |
} |
39 | 361 |
return $dn + $h/24 + $m/24/60 + $s/24/3600; |
14 | 362 |
} |
39 | 363 |
|
364 |
} # static scope |
|
365 |
||
14 | 366 |
#---------------------------------------------------------------------- |
367 |
# Read Data |
|
368 |
#---------------------------------------------------------------------- |
|
39 | 369 |
|
370 |
my($WBRcfn,$WBPcfn); # current file names for reading/patching |
|
371 |
my($BIT_errors) = 0; # built-in-test errors |
|
372 |
||
373 |
my($FmtErr) = "%s: illegal %s Id 0x%04x at ensemble %d"; |
|
374 |
||
14 | 375 |
#---------------------------------------------------------------------- |
43
b63fa355644c
commit to merge with changes from EN620
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
42
diff
changeset
|
376 |
# 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
|
377 |
#---------------------------------------------------------------------- |
39 | 378 |
|
43
b63fa355644c
commit to merge with changes from EN620
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
42
diff
changeset
|
379 |
sub goto_next_ens(@) |
b63fa355644c
commit to merge with changes from EN620
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
42
diff
changeset
|
380 |
{ |
b63fa355644c
commit to merge with changes from EN620
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
42
diff
changeset
|
381 |
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
|
382 |
my($buf,$dta); |
b63fa355644c
commit to merge with changes from EN620
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
42
diff
changeset
|
383 |
|
b63fa355644c
commit to merge with changes from EN620
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
42
diff
changeset
|
384 |
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
|
385 |
my($skipped) = 0; my($garbage_start); |
b63fa355644c
commit to merge with changes from EN620
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
42
diff
changeset
|
386 |
while ($found < 2) { |
b63fa355644c
commit to merge with changes from EN620
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
42
diff
changeset
|
387 |
sysread($fh,$buf,1) == 1 || last; |
b63fa355644c
commit to merge with changes from EN620
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
42
diff
changeset
|
388 |
($dta) = unpack('C',$buf); |
b63fa355644c
commit to merge with changes from EN620
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
42
diff
changeset
|
389 |
if ($dta == 0x7f) { |
b63fa355644c
commit to merge with changes from EN620
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
42
diff
changeset
|
390 |
$found++; |
b63fa355644c
commit to merge with changes from EN620
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
42
diff
changeset
|
391 |
} elsif ($found==1 && |
b63fa355644c
commit to merge with changes from EN620
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
42
diff
changeset
|
392 |
($dta==0xE0 || # from editPD0 |
b63fa355644c
commit to merge with changes from EN620
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
42
diff
changeset
|
393 |
(($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
|
394 |
$found++; |
b63fa355644c
commit to merge with changes from EN620
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
42
diff
changeset
|
395 |
} elsif ($found == 0) { |
b63fa355644c
commit to merge with changes from EN620
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
42
diff
changeset
|
396 |
$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
|
397 |
$skipped++; |
b63fa355644c
commit to merge with changes from EN620
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
42
diff
changeset
|
398 |
} 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
|
399 |
$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
|
400 |
$skipped += $found; |
b63fa355644c
commit to merge with changes from EN620
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
42
diff
changeset
|
401 |
$found = 0; |
b63fa355644c
commit to merge with changes from EN620
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
42
diff
changeset
|
402 |
} |
b63fa355644c
commit to merge with changes from EN620
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
42
diff
changeset
|
403 |
} |
b63fa355644c
commit to merge with changes from EN620
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
42
diff
changeset
|
404 |
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
|
405 |
return $skipped if ($return_skipped); |
39 | 406 |
|
43
b63fa355644c
commit to merge with changes from EN620
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
42
diff
changeset
|
407 |
if ($skipped) { |
b63fa355644c
commit to merge with changes from EN620
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
42
diff
changeset
|
408 |
if (eof($fh)) { |
b63fa355644c
commit to merge with changes from EN620
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
42
diff
changeset
|
409 |
# 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
|
410 |
# 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
|
411 |
# of the SR1b repeat section analysis |
b63fa355644c
commit to merge with changes from EN620
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
42
diff
changeset
|
412 |
# 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
|
413 |
} elsif ($garbage_start == 0) { |
b63fa355644c
commit to merge with changes from EN620
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
42
diff
changeset
|
414 |
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
|
415 |
} else { |
b63fa355644c
commit to merge with changes from EN620
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
42
diff
changeset
|
416 |
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
|
417 |
} |
02776c168135
made RDI_BB_IO work with files containing leading garbage
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
24
diff
changeset
|
418 |
} |
39 | 419 |
|
43
b63fa355644c
commit to merge with changes from EN620
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
42
diff
changeset
|
420 |
return $fpos; |
b63fa355644c
commit to merge with changes from EN620
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
42
diff
changeset
|
421 |
} |
b63fa355644c
commit to merge with changes from EN620
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
42
diff
changeset
|
422 |
|
26
02776c168135
made RDI_BB_IO work with files containing leading garbage
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
24
diff
changeset
|
423 |
#---------------------------------------------------------------------- |
14 | 424 |
# readHeader(file_name,^dta) WBRhdr(^data) |
425 |
# - read header data |
|
426 |
# - also includes some data from 1st ens |
|
427 |
#---------------------------------------------------------------------- |
|
39 | 428 |
|
14 | 429 |
sub readHeader(@) |
430 |
{ |
|
42 | 431 |
my($fn,$dta,$suppress_error) = @_; |
14 | 432 |
$WBRcfn = $fn; |
39 | 433 |
open(WBRF,$WBRcfn) || die("$WBRcfn: $!"); |
42 | 434 |
if (WBRhdr($dta)) { |
435 |
return 1; |
|
436 |
} elsif ($suppress_error) { |
|
437 |
return undef; |
|
438 |
} else { |
|
439 |
die("$WBRcfn: Insufficient data\n"); |
|
440 |
} |
|
14 | 441 |
} |
442 |
||
39 | 443 |
sub WBRhdr(@) |
14 | 444 |
{ |
39 | 445 |
my($dta,$checkFmt) = @_; |
26
02776c168135
made RDI_BB_IO work with files containing leading garbage
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
24
diff
changeset
|
446 |
my($start_ens,$buf,$hid,$did,$Ndt,$B,$W,$i,$dummy,$id,@WBRofs); |
14 | 447 |
my($B1,$B2,$B3,$B4,$B5,$B6,$B7,$W1,$W2,$W3,$W4,$W5); |
39 | 448 |
my($BT_dt); |
449 |
||
14 | 450 |
#-------------------- |
451 |
# HEADER |
|
452 |
#-------------------- |
|
453 |
||
43
b63fa355644c
commit to merge with changes from EN620
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
42
diff
changeset
|
454 |
my($skipped) = goto_next_ens(\*WBRF,1); |
b63fa355644c
commit to merge with changes from EN620
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
42
diff
changeset
|
455 |
printf(STDERR "WARNING: %d bytes of initial garbage\n",$skipped) |
b63fa355644c
commit to merge with changes from EN620
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
42
diff
changeset
|
456 |
if ($skipped > 0); |
b63fa355644c
commit to merge with changes from EN620
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
42
diff
changeset
|
457 |
|
37 | 458 |
sysread(WBRF,$buf,6) == 6 || return undef; |
32 | 459 |
($hid,$did,$dta->{ENSEMBLE_BYTES},$dummy,$dta->{NUMBER_OF_DATA_TYPES}) |
460 |
= unpack('CCvCC',$buf); |
|
36
515b06dae59c
version at end of ECOGIG EN586 cruise
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
32
diff
changeset
|
461 |
$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
|
462 |
$did == 0x7f || die(sprintf($FmtErr,$WBRcfn,"Header (did)",$did,0)); |
32 | 463 |
|
37 | 464 |
$start_ens = sysseek(WBRF,$dta->{ENSEMBLE_BYTES}-6+2,1) || return undef; |
465 |
sysread(WBRF,$buf,6) == 6 || return undef; |
|
14 | 466 |
($hid,$did,$dta->{ENSEMBLE_BYTES},$dummy,$dta->{NUMBER_OF_DATA_TYPES}) |
467 |
= unpack('CCvCC',$buf); |
|
36
515b06dae59c
version at end of ECOGIG EN586 cruise
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
32
diff
changeset
|
468 |
$hid == 0x7f || die(sprintf($FmtErr,$WBRcfn,"Header (hid2)",$hid,0)); |
29 | 469 |
$dta->{DATA_SOURCE_ID} = $did; |
470 |
if ($did == 0x7f) { |
|
471 |
$dta->{PRODUCER} = 'TRDI ADCP'; |
|
31 | 472 |
} elsif (($did&0xF0) == 0xA0) { |
473 |
$dta->{PRODUCER} = 'IMP+LADCP (Thurnherr software)'; |
|
474 |
} elsif (($did&0xF0) == 0xE0) { |
|
475 |
$dta->{PRODUCER} = 'editPD0 (Thurnherr software)'; |
|
29 | 476 |
} else { |
31 | 477 |
$dta->{PRODUCER} = sprintf('unknown (0x%02X)'); |
29 | 478 |
} |
479 |
||
39 | 480 |
if ($checkFmt) { |
481 |
printf(STDERR "WARNING: unexpected number of data types (%d)\n", |
|
482 |
$dta->{NUMBER_OF_DATA_TYPES}) |
|
483 |
unless ($dta->{NUMBER_OF_DATA_TYPES} == 6 || |
|
484 |
$dta->{NUMBER_OF_DATA_TYPES} == 7); |
|
485 |
$dta->{BT_PRESENT} = ($dta->{NUMBER_OF_DATA_TYPES} >= 7); |
|
486 |
} |
|
14 | 487 |
|
488 |
sysread(WBRF,$buf,2*$dta->{NUMBER_OF_DATA_TYPES}) |
|
489 |
== 2*$dta->{NUMBER_OF_DATA_TYPES} |
|
490 |
|| die("$WBRcfn: $!"); |
|
491 |
@WBRofs = unpack("v$dta->{NUMBER_OF_DATA_TYPES}",$buf); |
|
492 |
# for ($i=0; $i<$dta->{NUMBER_OF_DATA_TYPES}; $i++) { |
|
43
b63fa355644c
commit to merge with changes from EN620
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
42
diff
changeset
|
493 |
# printf(STDERR "WBRofs[$i] = %d",$WBRofs[$i]); |
14 | 494 |
# } |
495 |
||
39 | 496 |
|
497 |
$dta->{HEADER_BYTES} = $WBRofs[0]; |
|
498 |
$dta->{FIXED_LEADER_BYTES} = $WBRofs[1] - $WBRofs[0]; |
|
499 |
$dta->{VARIABLE_LEADER_BYTES} = $WBRofs[2] - $WBRofs[1]; |
|
500 |
if ($checkFmt) { |
|
501 |
$dta->{VELOCITY_DATA_BYTES} = $WBRofs[3] - $WBRofs[2]; |
|
502 |
$dta->{CORRELATION_DATA_BYTES} = $WBRofs[4] - $WBRofs[3]; |
|
503 |
$dta->{ECHO_INTENSITY_DATA_BYTES} = $WBRofs[5] - $WBRofs[4]; |
|
504 |
if ($dta->{BT_PRESENT}) { |
|
505 |
$dta->{PERCENT_GOOD_DATA_BYTES} = $WBRofs[6] - $WBRofs[5]; |
|
506 |
$dta->{BT_DATA_BYTES} = $dta->{ENSEMBLE_BYTES} - 4 - $WBRofs[6]; |
|
507 |
} else { |
|
508 |
$dta->{PERCENT_GOOD_DATA_BYTES} = $dta->{ENSEMBLE_BYTES} - 4 - $WBRofs[5]; |
|
509 |
} |
|
510 |
} |
|
511 |
||
512 |
if ($dta->{FIXED_LEADER_BYTES} == 42) { # Eric Firing's old instrument I used in 2004 |
|
513 |
$dta->{INSTRUMENT_TYPE} = 'BB150'; |
|
514 |
} elsif ($dta->{FIXED_LEADER_BYTES} == 53) { # old firmware: no serial numbers |
|
515 |
$dta->{INSTRUMENT_TYPE} = 'Workhorse'; |
|
516 |
} elsif ($dta->{FIXED_LEADER_BYTES} == 59) { # new firmware: with serial numbers |
|
517 |
$dta->{INSTRUMENT_TYPE} = 'Workhorse'; |
|
518 |
} elsif ($dta->{FIXED_LEADER_BYTES} == 58) { # DVL |
|
519 |
$dta->{INSTRUMENT_TYPE} = 'Explorer'; |
|
520 |
} elsif ($dta->{FIXED_LEADER_BYTES} == 60) { # OS75 |
|
521 |
$dta->{INSTRUMENT_TYPE} = 'Ocean Surveyor'; |
|
522 |
} else { |
|
523 |
$dta->{INSTRUMENT_TYPE} = 'unknown'; |
|
524 |
} |
|
525 |
||
526 |
#-------------------------------- |
|
527 |
# Variable Leader: SPEED_OF_SOUND |
|
528 |
#-------------------------------- |
|
14 | 529 |
|
26
02776c168135
made RDI_BB_IO work with files containing leading garbage
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
24
diff
changeset
|
530 |
sysseek(WBRF,$start_ens+$WBRofs[1],0) || die("$WBRcfn: $!"); |
14 | 531 |
sysread(WBRF,$buf,2) == 2 || die("$WBRcfn: $!"); |
532 |
$id = unpack('v',$buf); |
|
39 | 533 |
if ($dta->{INSTRUMENT_TYPE} eq 'Ocean Surveyor') { |
534 |
$id == 0x0081 || printf(STDERR $FmtErr."\n",$WBRcfn,"Variable Leader",$id,1); |
|
535 |
} else { |
|
536 |
$id == 0x0080 || printf(STDERR $FmtErr."\n",$WBRcfn,"Variable Leader",$id,1); |
|
537 |
} |
|
538 |
sysseek(WBRF,12,1) || die("$WBRcfn: $!"); # skip up to speed of sound |
|
14 | 539 |
sysread(WBRF,$buf,2) == 2 || die("$WBRcfn: $!"); |
39 | 540 |
$dta->{SPEED_OF_SOUND} = unpack('v',$buf); |
541 |
||
542 |
#---------------------------------- |
|
543 |
# Check Data Format of 1st Ensemble |
|
544 |
#---------------------------------- |
|
14 | 545 |
|
39 | 546 |
if ($checkFmt) { |
547 |
sysseek(WBRF,$start_ens+$WBRofs[2],0) || die("$WBRcfn: $!"); |
|
548 |
sysread(WBRF,$buf,2) == 2 || die("$WBRcfn: $!"); |
|
549 |
$id = unpack('v',$buf); |
|
550 |
$id == 0x0100 || printf(STDERR $FmtErr."\n",$WBRcfn,"Velocity Data",$id,1); |
|
551 |
||
552 |
sysseek(WBRF,$start_ens+$WBRofs[3],0) || die("$WBRcfn: $!"); |
|
553 |
sysread(WBRF,$buf,2) == 2 || die("$WBRcfn: $!"); |
|
554 |
$id = unpack('v',$buf); |
|
555 |
$id == 0x0200 || printf(STDERR $FmtErr."\n",$WBRcfn,"Correlation Data",$id,1); |
|
556 |
||
557 |
sysseek(WBRF,$start_ens+$WBRofs[4],0) || die("$WBRcfn: $!"); |
|
558 |
sysread(WBRF,$buf,2) == 2 || die("$WBRcfn: $!"); |
|
559 |
$id = unpack('v',$buf); |
|
560 |
$id == 0x0300 || printf(STDERR $FmtErr."\n",$WBRcfn,"Echo Intensity",$id,1); |
|
561 |
||
562 |
sysseek(WBRF,$start_ens+$WBRofs[5],0) || die("$WBRcfn: $!"); |
|
563 |
sysread(WBRF,$buf,2) == 2 || die("$WBRcfn: $!"); |
|
564 |
$id = unpack('v',$buf); |
|
565 |
$id == 0x0400 || printf(STDERR $FmtErr."\n",$WBRcfn,"Percent-Good Data",$id,1); |
|
566 |
||
567 |
if ($dta->{BT_PRESENT}) { |
|
568 |
for ($BT_dt=6; $BT_dt<$dta->{NUMBER_OF_DATA_TYPES}; $BT_dt++) { # scan until BT found |
|
569 |
sysseek(WBRF,$start_ens+$WBRofs[$BT_dt],0) || die("$WBRcfn: $!"); |
|
570 |
sysread(WBRF,$buf,2) == 2 || die("$WBRcfn: $!"); |
|
571 |
$id = unpack('v',$buf); |
|
572 |
last if ($id == 0x0600); |
|
573 |
} |
|
574 |
||
575 |
if ($BT_dt == $dta->{NUMBER_OF_DATA_TYPES}) { |
|
576 |
printf(STDERR "WARNING: no BT data found\n");die; |
|
577 |
undef($dta->{BT_PRESENT}); |
|
578 |
} |
|
579 |
} |
|
14 | 580 |
} |
581 |
||
582 |
#-------------------- |
|
583 |
# FIXED LEADER |
|
584 |
#-------------------- |
|
585 |
||
26
02776c168135
made RDI_BB_IO work with files containing leading garbage
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
24
diff
changeset
|
586 |
sysseek(WBRF,$start_ens+$WBRofs[0],0) || die("$WBRcfn: $!"); |
14 | 587 |
sysread(WBRF,$buf,42) == 42 || die("$WBRcfn: $!"); |
39 | 588 |
($id,$dta->{CPU_FW_VER},$dta->{CPU_FW_REV},$B1,$B2,$dummy, |
589 |
$dta->{LAG_LENGTH},$dummy, |
|
14 | 590 |
$dta->{N_BINS},$dta->{PINGS_PER_ENSEMBLE},$dta->{BIN_LENGTH}, |
591 |
$dta->{BLANKING_DISTANCE},$dummy,$dta->{MIN_CORRELATION}, |
|
592 |
$dta->{N_CODE_REPETITIONS},$dta->{MIN_PERCENT_GOOD}, |
|
593 |
$dta->{MAX_ERROR_VELOCITY},$dta->{TIME_BETWEEN_PINGS},$B3,$B4,$B5, |
|
594 |
$dta->{HEADING_ALIGNMENT},$dta->{HEADING_BIAS},$B6,$B7, |
|
595 |
$dta->{DISTANCE_TO_BIN1_CENTER},$dta->{TRANSMITTED_PULSE_LENGTH}, |
|
596 |
$dta->{REF_LAYER_FIRST_BIN},$dta->{REF_LAYER_LAST_BIN}, |
|
597 |
$dta->{FALSE_TARGET_THRESHOLD},$dta->{LOW_LATENCY_SETTING}, |
|
598 |
$dta->{TRANSMIT_LAG_DISTANCE}) = |
|
599 |
unpack('vCCCCC3CvvvCCCCvCCCCvvCCvvCCCCv',$buf); |
|
600 |
||
39 | 601 |
if ($dta->{INSTRUMENT_TYPE} eq 'Ocean Surveyor') { |
602 |
$id == 0x0001 || printf(STDERR $FmtErr."\n",$WBRcfn,"Fixed Leader",$id,0); |
|
603 |
} else { |
|
604 |
$id == 0x0000 || printf(STDERR $FmtErr."\n",$WBRcfn,"Fixed Leader",$id,0); |
|
605 |
} |
|
14 | 606 |
|
39 | 607 |
# $dta->{BEAM_FREQUENCY} = 2**($B1 & 0x07) * 75; # nominal |
608 |
if (($B1&0x07) == 0b000) { $dta->{BEAM_FREQUENCY} = 76.8; } # actual |
|
609 |
elsif (($B1&0x07) == 0b001) { $dta->{BEAM_FREQUENCY} = 153.6; } |
|
610 |
elsif (($B1&0x07) == 0b010) { $dta->{BEAM_FREQUENCY} = 307.2; } |
|
611 |
elsif (($B1&0x07) == 0b011) { $dta->{BEAM_FREQUENCY} = 614.4; } |
|
612 |
elsif (($B1&0x07) == 0b100) { $dta->{BEAM_FREQUENCY} = 1228.8; } |
|
613 |
elsif (($B1&0x07) == 0b101) { $dta->{BEAM_FREQUENCY} = 2457.6; } |
|
614 |
else { die(sprintf("$WBRcfn: cannot decode BEAM_FREQUENCY (%03b)\n",$B1&0x07)); } |
|
615 |
||
14 | 616 |
$dta->{CONVEX_BEAM_PATTERN} = 1 if ($B1 & 0x08); |
617 |
$dta->{CONCAVE_BEAM_PATTERN} = 1 if (!($B1 & 0x08)); |
|
618 |
$dta->{SENSOR_CONFIG} = ($B1 & 0x30) >> 4; |
|
619 |
$dta->{XDUCER_HEAD_ATTACHED} = 1 if ($B1 & 0x40); |
|
620 |
||
621 |
if (($B2 & 0x03) == 0x00) { $dta->{BEAM_ANGLE} = 15; } |
|
622 |
elsif (($B2 & 0x03) == 0x01) { $dta->{BEAM_ANGLE} = 20; } |
|
623 |
elsif (($B2 & 0x03) == 0x02) { $dta->{BEAM_ANGLE} = 30; } |
|
624 |
if (($B2 & 0xF0) == 0x40) { $dta->{N_BEAMS} = 4; } |
|
625 |
elsif (($B2 & 0xF0) == 0x50) { $dta->{N_BEAMS} = 5; $dta->{N_DEMODS} = 3; } |
|
626 |
elsif (($B2 & 0xF0) == 0xF0) { $dta->{N_BEAMS} = 5; $dta->{N_DEMODS} = 2; } |
|
627 |
||
628 |
$dta->{BIN_LENGTH} /= 100; |
|
629 |
$dta->{BLANKING_DISTANCE} /= 100; |
|
630 |
||
631 |
$dta->{MAX_ERROR_VELOCITY} /= 1000; |
|
632 |
$dta->{TIME_BETWEEN_PINGS} *= 60; |
|
633 |
$dta->{TIME_BETWEEN_PINGS} += $B3 + $B4/100; |
|
634 |
||
635 |
$dta->{BEAM_COORDINATES} = 1 if (($B5 & 0x18) == 0x00); |
|
636 |
$dta->{INSTRUMENT_COORDINATES} = 1 if (($B5 & 0x18) == 0x08); |
|
637 |
$dta->{SHIP_COORDINATES} = 1 if (($B5 & 0x18) == 0x10); |
|
638 |
$dta->{EARTH_COORDINATES} = 1 if (($B5 & 0x18) == 0x18); |
|
639 |
$dta->{PITCH_AND_ROLL_USED} = 1 if ($B5 & 0x04); |
|
640 |
$dta->{USE_3_BEAM_ON_LOW_CORR} = 1 if ($B5 & 0x02); |
|
641 |
$dta->{BIN_MAPPING_ALLOWED} = 1 if ($B5 & 0x01); |
|
642 |
||
643 |
$dta->{HEADING_ALIGNMENT} = |
|
644 |
($dta->{EARTH_COORDINATES} || $dta->{SHIP_COORDINATES}) ? |
|
645 |
$dta->{HEADING_ALIGNMENT} / 100 : undef; |
|
646 |
$dta->{HEADING_BIAS} = |
|
647 |
($dta->{EARTH_COORDINATES} || $dta->{SHIP_COORDINATES}) ? |
|
648 |
$dta->{HEADING_BIAS} / 100 : undef; |
|
649 |
||
650 |
$dta->{CALCULATE_SPEED_OF_SOUND} = 1 if ($B6 & 0x40); |
|
651 |
$dta->{USE_PRESSURE_SENSOR} = 1 if ($B6 & 0x20); |
|
652 |
$dta->{USE_COMPASS} = 1 if ($B6 & 0x10); |
|
653 |
$dta->{USE_PITCH_SENSOR} = 1 if ($B6 & 0x08); |
|
654 |
$dta->{USE_ROLL_SENSOR} = 1 if ($B6 & 0x04); |
|
655 |
$dta->{USE_CONDUCTIVITY_SENSOR} = 1 if ($B6 & 0x02); |
|
656 |
$dta->{USE_TEMPERATURE_SENSOR} = 1 if ($B6 & 0x01); |
|
657 |
||
658 |
$dta->{SPEED_OF_SOUND_CALCULATED} = 1 if ($B7 & 0x40); |
|
659 |
$dta->{PRESSURE_SENSOR_AVAILABLE} = 1 if ($B7 & 0x20); |
|
660 |
$dta->{COMPASS_AVAILABLE} = 1 if ($B7 & 0x10); |
|
661 |
$dta->{PITCH_SENSOR_AVAILABLE} = 1 if ($B7 & 0x08); |
|
662 |
$dta->{ROLL_SENSOR_AVAILABLE} = 1 if ($B7 & 0x04); |
|
663 |
$dta->{CONDUCTIVITY_SENSOR_AVAILABLE} = 1 if ($B7 & 0x02); |
|
664 |
$dta->{TEMPERATURE_SENSOR_AVAILABLE} = 1 if ($B7 & 0x01); |
|
665 |
||
666 |
$dta->{DISTANCE_TO_BIN1_CENTER} /= 100; |
|
667 |
$dta->{TRANSMITTED_PULSE_LENGTH} /= 100; |
|
668 |
||
669 |
$dta->{FALSE_TARGET_THRESHOLD} = undef |
|
670 |
if ($dta->{FALSE_TARGET_THRESHOLD} == 255); |
|
671 |
$dta->{TRANSMIT_LAG_DISTANCE} /= 100; |
|
672 |
||
673 |
if ($dta->{INSTRUMENT_TYPE} eq 'Workhorse') { |
|
674 |
sysread(WBRF,$buf,11) == 11 || die("$WBRcfn: $!"); |
|
675 |
($W1,$W2,$W3,$W4,$W5,$dta->{TRANSMIT_POWER}) = |
|
676 |
unpack('vvvvvC',$buf); |
|
677 |
||
678 |
$dta->{CPU_SERIAL_NUMBER} = sprintf("%04X%04X%04X%04X",$W1,$W2,$W3,$W4); |
|
679 |
||
680 |
$dta->{NARROW_BANDWIDTH} = ($W5 == 1); |
|
681 |
$dta->{WIDE_BANDWIDTH} = ($W5 == 0); |
|
682 |
$dta->{TRANSMIT_POWER_HIGH} = ($dta->{TRANSMIT_POWER} == 255); |
|
683 |
||
684 |
if ($dta->{FIXED_LEADER_BYTES} == 59) { # new style with serial number |
|
685 |
sysread(WBRF,$buf,6) == 6 || die("$WBRcfn: $!"); |
|
686 |
($dummy,$dta->{SERIAL_NUMBER},$dummy) = # last bytes is beam angle, but that info has |
|
687 |
unpack('CVC',$buf); # already been provided above |
|
688 |
} |
|
689 |
} |
|
690 |
||
691 |
if ($dta->{INSTRUMENT_TYPE} eq 'Explorer') { |
|
692 |
sysread(WBRF,$buf,16) == 16 || die("$WBRcfn: $!"); |
|
693 |
($dummy,$dummy,$W5,$dummy,$dta->{SERIAL_NUMBER}) = |
|
694 |
unpack('VVvvV',$buf); |
|
695 |
$dta->{NARROW_BANDWIDTH} = ($W5 == 1); |
|
696 |
$dta->{WIDE_BANDWIDTH} = ($W5 == 0); |
|
697 |
} |
|
698 |
||
699 |
#----------------------- |
|
700 |
# 1st ENSEMBLE, BT Setup |
|
701 |
#----------------------- |
|
702 |
||
703 |
if ($dta->{BT_PRESENT}) { |
|
26
02776c168135
made RDI_BB_IO work with files containing leading garbage
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
24
diff
changeset
|
704 |
sysseek(WBRF,$start_ens+$WBRofs[$BT_dt],0) || die("$WBRcfn: $!"); |
14 | 705 |
sysread(WBRF,$buf,12) == 12 || die("$WBRcfn: $!"); |
706 |
($id,$dta->{BT_PINGS_PER_ENSEMBLE},$dta->{BT_DELAY_BEFORE_REACQUIRE}, |
|
707 |
$dta->{BT_MIN_CORRELATION},$dta->{BT_MIN_EVAL_AMPLITUDE}, |
|
708 |
$dta->{BT_MIN_PERCENT_GOOD},$dta->{BT_MODE}, |
|
709 |
$dta->{BT_MAX_ERROR_VELOCITY}) = unpack('vvvCCCCv',$buf); |
|
710 |
||
711 |
$id == 0x0600 || |
|
26
02776c168135
made RDI_BB_IO work with files containing leading garbage
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
24
diff
changeset
|
712 |
printf(STDERR $FmtErr."\n",$WBRcfn,"Bottom Track",$id,0,tell(WBRF)); |
14 | 713 |
|
714 |
$dta->{BT_MAX_ERROR_VELOCITY} = |
|
715 |
$dta->{BT_MAX_ERROR_VELOCITY} ? $dta->{BT_MAX_ERROR_VELOCITY} / 1000 |
|
716 |
: undef; |
|
717 |
||
718 |
sysseek(WBRF,28,1) || die("$WBRcfn: $!"); |
|
719 |
sysread(WBRF,$buf,6) == 6 || die("$WBRcfn: $!"); |
|
720 |
($dta->{BT_RL_MIN_SIZE},$dta->{BT_RL_NEAR},$dta->{BT_RL_FAR}) |
|
721 |
= unpack('vvv',$buf); |
|
722 |
||
723 |
$dta->{BT_RL_MIN_SIZE} /= 10; |
|
724 |
$dta->{BT_RL_NEAR} /= 10; |
|
725 |
$dta->{BT_RL_FAR} /= 10; |
|
726 |
||
727 |
sysseek(WBRF,20,1) || die("$WBRcfn: $!"); # skip data |
|
728 |
sysread(WBRF,$buf,2) == 2 || die("$WBRcfn: $!"); |
|
729 |
$dta->{BT_MAX_TRACKING_DEPTH} = unpack('v',$buf) / 10; |
|
730 |
} |
|
731 |
||
732 |
return $dta; |
|
733 |
} |
|
734 |
||
735 |
#---------------------------------------------------------------------- |
|
43
b63fa355644c
commit to merge with changes from EN620
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
42
diff
changeset
|
736 |
# readData(file_name,^data[,first_ens,last_ens[,last_bin]]) |
b63fa355644c
commit to merge with changes from EN620
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
42
diff
changeset
|
737 |
# - read ensembles |
b63fa355644c
commit to merge with changes from EN620
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
42
diff
changeset
|
738 |
# - 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
|
739 |
# - read all bins unless last_bin is given |
14 | 740 |
#---------------------------------------------------------------------- |
741 |
||
742 |
sub readData(@) |
|
743 |
{ |
|
43
b63fa355644c
commit to merge with changes from EN620
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
42
diff
changeset
|
744 |
my($fn,$dta,$fe,$le,$lb) = @_; |
14 | 745 |
$WBRcfn = $fn; |
37 | 746 |
open(WBRF,$WBRcfn) || die("$WBRcfn: $!\n"); |
39 | 747 |
WBRhdr($dta,1) || die("$WBRcfn: Insufficient Data\n"); |
43
b63fa355644c
commit to merge with changes from EN620
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
42
diff
changeset
|
748 |
$lb = $dta->{N_BINS} |
b63fa355644c
commit to merge with changes from EN620
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
42
diff
changeset
|
749 |
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
|
750 |
WBRens($lb,$dta->{FIXED_LEADER_BYTES},\@{$dta->{ENSEMBLE}},$fe,$le); |
14 | 751 |
print(STDERR "$WBRcfn: $BIT_errors built-in-test errors\n") |
752 |
if ($BIT_errors); |
|
753 |
} |
|
754 |
||
43
b63fa355644c
commit to merge with changes from EN620
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
42
diff
changeset
|
755 |
sub WBRens(@) |
14 | 756 |
{ |
43
b63fa355644c
commit to merge with changes from EN620
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
42
diff
changeset
|
757 |
my($nbins,$fixed_leader_bytes,$E,$fe,$le) = @_; |
14 | 758 |
my($start_ens,$B1,$B2,$B3,$B4,$I,$id,$bin,$beam,$buf,$dummy,@dta,$i,$cs,@WBRofs); |
43
b63fa355644c
commit to merge with changes from EN620
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
42
diff
changeset
|
759 |
my($ens,$ensNo,$dayStart,$ens_length,$hid,$did,$ndt,$el); |
14 | 760 |
|
26
02776c168135
made RDI_BB_IO work with files containing leading garbage
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
24
diff
changeset
|
761 |
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
|
762 |
ENSEMBLE: |
b63fa355644c
commit to merge with changes from EN620
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
42
diff
changeset
|
763 |
for ($ens=0; 1; $ens++) { |
b63fa355644c
commit to merge with changes from EN620
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
42
diff
changeset
|
764 |
$start_ens = goto_next_ens(\*WBRF); |
b63fa355644c
commit to merge with changes from EN620
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
42
diff
changeset
|
765 |
last unless defined($start_ens); |
b63fa355644c
commit to merge with changes from EN620
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
42
diff
changeset
|
766 |
|
b63fa355644c
commit to merge with changes from EN620
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
42
diff
changeset
|
767 |
#---------------------------------------- |
b63fa355644c
commit to merge with changes from EN620
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
42
diff
changeset
|
768 |
# Handle first_ens and last_ens |
b63fa355644c
commit to merge with changes from EN620
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
42
diff
changeset
|
769 |
#---------------------------------------- |
b63fa355644c
commit to merge with changes from EN620
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
42
diff
changeset
|
770 |
|
b63fa355644c
commit to merge with changes from EN620
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
42
diff
changeset
|
771 |
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
|
772 |
pop(@{$E}); $ens--; |
b63fa355644c
commit to merge with changes from EN620
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
42
diff
changeset
|
773 |
} |
b63fa355644c
commit to merge with changes from EN620
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
42
diff
changeset
|
774 |
|
b63fa355644c
commit to merge with changes from EN620
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
42
diff
changeset
|
775 |
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
|
776 |
pop(@{$E}); $ens--; |
b63fa355644c
commit to merge with changes from EN620
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
42
diff
changeset
|
777 |
last; |
b63fa355644c
commit to merge with changes from EN620
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
42
diff
changeset
|
778 |
} |
14 | 779 |
|
780 |
#---------------------------------------- |
|
781 |
# Get ensemble length and # of data types |
|
782 |
#---------------------------------------- |
|
783 |
||
784 |
sysseek(WBRF,$start_ens,0) || die("$WBRcfn: $!"); |
|
785 |
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
|
786 |
($hid,$did,$el,$dummy,$ndt) = unpack('CCvCC',$buf); |
37 | 787 |
$hid == 0x7f || die(sprintf($FmtErr,$WBRcfn,"Header",$hid,defined($ensNo)?$ensNo+1:0)); |
29 | 788 |
${$E}[$ens]->{DATA_SOURCE_ID} = $did; |
789 |
if ($did == 0x7f) { |
|
790 |
${$E}[$ens]->{PRODUCER} = 'TRDI ADCP'; |
|
791 |
} elsif ($did&0xF0 == 0xA0) { |
|
792 |
${$E}[$ens]->{PRODUCER} = 'IMP+LADCP (Thurnherr software)'; |
|
31 | 793 |
} elsif ($did&0xF0 == 0xE0) { |
29 | 794 |
${$E}[$ens]->{PRODUCER} = 'editPD0 (Thurnherr software)'; |
795 |
} else { |
|
796 |
${$E}[$ens]->{PRODUCER} = 'unknown'; |
|
797 |
} |
|
798 |
||
43
b63fa355644c
commit to merge with changes from EN620
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
42
diff
changeset
|
799 |
if (defined($ens_length) && ($el != $ens_length)) { |
b63fa355644c
commit to merge with changes from EN620
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
42
diff
changeset
|
800 |
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
|
801 |
pop(@{$E}); |
b63fa355644c
commit to merge with changes from EN620
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
42
diff
changeset
|
802 |
$ens--; |
b63fa355644c
commit to merge with changes from EN620
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
42
diff
changeset
|
803 |
next; |
b63fa355644c
commit to merge with changes from EN620
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
42
diff
changeset
|
804 |
} |
b63fa355644c
commit to merge with changes from EN620
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
42
diff
changeset
|
805 |
|
b63fa355644c
commit to merge with changes from EN620
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
42
diff
changeset
|
806 |
$ens_length = $el; |
b63fa355644c
commit to merge with changes from EN620
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
42
diff
changeset
|
807 |
|
b63fa355644c
commit to merge with changes from EN620
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
42
diff
changeset
|
808 |
## printf(STDERR "$WBRcfn: WARNING: unexpected number of data types (%d, ens=$ens)\n",$ndt),last |
18 | 809 |
## unless ($ndt == 6 || $ndt == 7); |
14 | 810 |
sysread(WBRF,$buf,2*$ndt) == 2*$ndt || die("$WBRcfn: $!"); |
811 |
@WBRofs = unpack("v$ndt",$buf); |
|
812 |
$fixed_leader_bytes = $WBRofs[1] - $WBRofs[0]; |
|
813 |
# print(STDERR "@WBRofs\n"); |
|
814 |
||
815 |
#------------------------------- |
|
816 |
# Make Sure Ensemble is Complete |
|
817 |
#------------------------------- |
|
818 |
||
819 |
# UH BB150 writes incomplete ensembles (i.e. short read |
|
820 |
# indicates EOF). FSU WH300 has bogus data in incomplete |
|
821 |
# final ensemble. |
|
822 |
||
823 |
sysseek(WBRF,$start_ens,0) || die("$WBRcfn: $!"); |
|
37 | 824 |
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
|
825 |
(sysread(WBRF,$cs,2) == 2)) { |
43
b63fa355644c
commit to merge with changes from EN620
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
42
diff
changeset
|
826 |
# print(STDERR "INCOMPLETE ENSEMBLE\n"); |
36
515b06dae59c
version at end of ECOGIG EN586 cruise
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
32
diff
changeset
|
827 |
pop(@{$E}); |
515b06dae59c
version at end of ECOGIG EN586 cruise
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
32
diff
changeset
|
828 |
last; |
515b06dae59c
version at end of ECOGIG EN586 cruise
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
32
diff
changeset
|
829 |
} |
14 | 830 |
|
37 | 831 |
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
|
832 |
# print(STDERR "BAD CHECKSUM\n"); |
b63fa355644c
commit to merge with changes from EN620
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
42
diff
changeset
|
833 |
pop(@{$E}); $ens--; |
b63fa355644c
commit to merge with changes from EN620
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
42
diff
changeset
|
834 |
next; |
b63fa355644c
commit to merge with changes from EN620
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
42
diff
changeset
|
835 |
} |
14 | 836 |
|
837 |
#------------------------------ |
|
838 |
# Variable Leader |
|
839 |
#------------------------------ |
|
840 |
||
37 | 841 |
my($lastEns) = $ensNo; |
14 | 842 |
sysseek(WBRF,$start_ens+$WBRofs[1],0) || die("$WBRcfn: $!"); |
843 |
sysread(WBRF,$buf,4) == 4 || die("$WBRcfn: $!"); |
|
37 | 844 |
($id,$ensNo) = unpack("vv",$buf); # only lower two bytes!!! |
14 | 845 |
|
39 | 846 |
if (${$E}[$ens]->{INSTRUMENT_TYPE} eq 'Ocean Surveyor') { |
847 |
$id == 0x0081 || |
|
848 |
die(sprintf($FmtErr,$WBRcfn,"Variable Leader",$id,$ensNo + ($lastEns - ($lastEns & 0xFFFF)))); |
|
849 |
} else { |
|
850 |
$id == 0x0080 || |
|
851 |
die(sprintf($FmtErr,$WBRcfn,"Variable Leader",$id,$ensNo + ($lastEns - ($lastEns & 0xFFFF)))); |
|
852 |
} |
|
14 | 853 |
|
42 | 854 |
# if ($fixed_leader_bytes==42 || $fixed_leader_bytes==58) { # BB150 & Explorer DVL (if DISABLED!) |
855 |
sysread(WBRF,$buf,7) == 7 || die("$WBRcfn: $!"); # always read pre-Y2K clock |
|
14 | 856 |
(${$E}[$ens]->{YEAR},${$E}[$ens]->{MONTH}, |
857 |
${$E}[$ens]->{DAY},${$E}[$ens]->{HOUR},${$E}[$ens]->{MINUTE}, |
|
858 |
${$E}[$ens]->{SECONDS},$B4) = unpack('CCCCCCC',$buf); |
|
859 |
${$E}[$ens]->{SECONDS} += $B4/100; |
|
860 |
${$E}[$ens]->{YEAR} += (${$E}[$ens]->{YEAR} > 80) ? 1900 : 2000; |
|
40
6a46e9d31106
after Hamburg visit
Andreas Thurnherr <ant@ldeo.columbia.edu>
parents:
39
diff
changeset
|
861 |
# } else { |
6a46e9d31106
after Hamburg visit
Andreas Thurnherr <ant@ldeo.columbia.edu>
parents:
39
diff
changeset
|
862 |
# sysseek(WBRF,7,1) || die("$WBRcfn: $!"); # use Y2K RTC instead |
6a46e9d31106
after Hamburg visit
Andreas Thurnherr <ant@ldeo.columbia.edu>
parents:
39
diff
changeset
|
863 |
# } |
14 | 864 |
|
865 |
sysread(WBRF,$buf,1) == 1 || die("$WBRcfn: $!"); |
|
866 |
$ensNo += unpack('C',$buf) << 16; |
|
43
b63fa355644c
commit to merge with changes from EN620
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
42
diff
changeset
|
867 |
|
b63fa355644c
commit to merge with changes from EN620
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
42
diff
changeset
|
868 |
for (my($i)=$ens; $i>0; $i--) { # check for duplicate ens; e.g. 2018 S4P 24UL |
b63fa355644c
commit to merge with changes from EN620
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
42
diff
changeset
|
869 |
if (${$E}[$i]->{NUMBER} == $ensNo) { |
b63fa355644c
commit to merge with changes from EN620
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
42
diff
changeset
|
870 |
print(STDERR "WARNING (RDI_PD0_IO): duplicate ensemble $ensNo skipped\n"); |
b63fa355644c
commit to merge with changes from EN620
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
42
diff
changeset
|
871 |
pop(@{$E}); |
b63fa355644c
commit to merge with changes from EN620
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
42
diff
changeset
|
872 |
$ens--; |
b63fa355644c
commit to merge with changes from EN620
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
42
diff
changeset
|
873 |
next ENSEMBLE; |
b63fa355644c
commit to merge with changes from EN620
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
42
diff
changeset
|
874 |
} |
b63fa355644c
commit to merge with changes from EN620
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
42
diff
changeset
|
875 |
} |
b63fa355644c
commit to merge with changes from EN620
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
42
diff
changeset
|
876 |
|
14 | 877 |
${$E}[$ens]->{NUMBER} = $ensNo; |
878 |
||
879 |
sysread(WBRF,$buf,30) == 30 || die("$WBRcfn: $!"); |
|
880 |
(${$E}[$ens]->{BUILT_IN_TEST_ERROR},${$E}[$ens]->{SPEED_OF_SOUND}, |
|
881 |
${$E}[$ens]->{XDUCER_DEPTH},${$E}[$ens]->{HEADING}, |
|
882 |
${$E}[$ens]->{PITCH},${$E}[$ens]->{ROLL}, |
|
883 |
${$E}[$ens]->{SALINITY},${$E}[$ens]->{TEMPERATURE}, |
|
884 |
${$E}[$ens]->{MIN_PRE_PING_WAIT_TIME},$B1,$B2, |
|
885 |
${$E}[$ens]->{HEADING_STDDEV},${$E}[$ens]->{PITCH_STDDEV}, |
|
886 |
${$E}[$ens]->{ROLL_STDDEV},${$E}[$ens]->{ADC_XMIT_CURRENT}, |
|
887 |
${$E}[$ens]->{ADC_XMIT_VOLTAGE},${$E}[$ens]->{ADC_AMBIENT_TEMPERATURE}, |
|
888 |
${$E}[$ens]->{ADC_PRESSURE_PLUS},${$E}[$ens]->{ADC_PRESSURE_MINUS}, |
|
889 |
${$E}[$ens]->{ADC_ATTITUDE_TEMPERATURE},${$E}[$ens]->{ADC_ATTITUDE}, |
|
890 |
${$E}[$ens]->{ADC_CONTAMINATION}) |
|
891 |
= unpack('vvvvvvvvCCCCCCCCCCCCCC',$buf); |
|
892 |
||
893 |
${$E}[$ens]->{BUILT_IN_TEST_ERROR} = undef |
|
894 |
unless (${$E}[$ens]->{BUILT_IN_TEST_ERROR}); |
|
895 |
$BIT_errors++ if (${$E}[$ens]->{BUILT_IN_TEST_ERROR}); |
|
896 |
||
897 |
${$E}[$ens]->{XDUCER_DEPTH} /= 10; |
|
18 | 898 |
|
899 |
#------------------------------------------------- |
|
900 |
# IMP EXTENSION: PITCH/ROLL/HEADING CAN BE MISSING |
|
901 |
#------------------------------------------------- |
|
902 |
||
903 |
${$E}[$ens]->{HEADING} = (${$E}[$ens]->{HEADING} == 0xF000) |
|
904 |
? undef |
|
905 |
: ${$E}[$ens]->{HEADING} / 100; |
|
906 |
${$E}[$ens]->{PITCH} = (${$E}[$ens]->{PITCH} == 0x8000) |
|
907 |
? undef |
|
908 |
: unpack('s',pack('S',${$E}[$ens]->{PITCH})) / 100; |
|
909 |
${$E}[$ens]->{ROLL} = (${$E}[$ens]->{ROLL} == 0x8000) |
|
910 |
? undef |
|
911 |
: unpack('s',pack('S',${$E}[$ens]->{ROLL})) / 100; |
|
912 |
||
913 |
${$E}[$ens]->{TEMPERATURE} = unpack('s',pack('S',${$E}[$ens]->{TEMPERATURE})) / 100; |
|
14 | 914 |
${$E}[$ens]->{MIN_PRE_PING_WAIT_TIME} *= 60; |
915 |
${$E}[$ens]->{MIN_PRE_PING_WAIT_TIME} += $B1 + $B2/100; |
|
916 |
${$E}[$ens]->{PITCH_STDDEV} /= 10; |
|
917 |
${$E}[$ens]->{ROLL_STDDEV} /= 10; |
|
918 |
||
40
6a46e9d31106
after Hamburg visit
Andreas Thurnherr <ant@ldeo.columbia.edu>
parents:
39
diff
changeset
|
919 |
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
|
920 |
!defined($RDI_PD0_IO::IGNORE_Y2K_CLOCK)) { |
14 | 921 |
sysread(WBRF,$buf,23) == 23 || die("$WBRcfn: $!"); |
922 |
(${$E}[$ens]->{ERROR_STATUS_WORD}, |
|
923 |
$dummy,${$E}[$ens]->{PRESSURE},${$E}[$ens]->{PRESSURE_STDDEV}, |
|
924 |
$dummy,${$E}[$ens]->{YEAR},$B3,${$E}[$ens]->{MONTH}, |
|
925 |
${$E}[$ens]->{DAY},${$E}[$ens]->{HOUR},${$E}[$ens]->{MINUTE}, |
|
926 |
${$E}[$ens]->{SECONDS},$B4) |
|
927 |
= unpack('VvVVCCCCCCCCC',$buf); |
|
928 |
||
929 |
${$E}[$ens]->{PRESSURE} /= 1000; |
|
930 |
${$E}[$ens]->{PRESSURE_STDDEV} /= 1000; |
|
931 |
${$E}[$ens]->{YEAR} *= 100; ${$E}[$ens]->{YEAR} += $B3; |
|
932 |
${$E}[$ens]->{SECONDS} += $B4/100; |
|
933 |
} |
|
934 |
||
36
515b06dae59c
version at end of ECOGIG EN586 cruise
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
32
diff
changeset
|
935 |
# THE FOLLOWING LINE OF CODE WAS REMOVED 7/30/2016 WHEN I ADDED A POP |
515b06dae59c
version at end of ECOGIG EN586 cruise
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
32
diff
changeset
|
936 |
# TO THE last STATEMENT ABOVE (INCOMPLETE ENSEMBLE) |
42 | 937 |
# THE LINE WAS RE-ENABLED ON 12/23/2017 BECAUSE OTHERWISE THE |
938 |
# ANSLOPE II PROFILES IN THE HOWTO CANNOT BE READ. |
|
939 |
pop(@{$E}),last if (${$E}[$ens]->{MONTH}>12); # 10/15/2014; IWISE#145 UL ??? |
|
21 | 940 |
|
14 | 941 |
if ($fixed_leader_bytes == 58) { # Explorer DVL |
942 |
sysread(WBRF,$buf,14) == 14 || die("$WBRcfn: $!"); |
|
943 |
(${$E}[$ens]->{ERROR_STATUS_WORD}, |
|
944 |
$dummy,${$E}[$ens]->{PRESSURE},${$E}[$ens]->{PRESSURE_STDDEV}) |
|
945 |
= unpack('VvVV',$buf); |
|
946 |
${$E}[$ens]->{PRESSURE} /= 1000; |
|
947 |
${$E}[$ens]->{PRESSURE_STDDEV} /= 1000; |
|
948 |
} |
|
949 |
||
950 |
${$E}[$ens]->{DATE} |
|
951 |
= sprintf("%02d/%02d/%d",${$E}[$ens]->{MONTH}, |
|
952 |
${$E}[$ens]->{DAY}, |
|
953 |
${$E}[$ens]->{YEAR}); |
|
954 |
${$E}[$ens]->{TIME} |
|
955 |
= sprintf("%02d:%02d:%05.02f",${$E}[$ens]->{HOUR}, |
|
956 |
${$E}[$ens]->{MINUTE}, |
|
957 |
${$E}[$ens]->{SECONDS}); |
|
958 |
${$E}[$ens]->{DAYNO} |
|
40
6a46e9d31106
after Hamburg visit
Andreas Thurnherr <ant@ldeo.columbia.edu>
parents:
39
diff
changeset
|
959 |
= &_dayNo(${$E}[$ens]->{YEAR},${$E}[$ens]->{MONTH},${$E}[$ens]->{DAY}, |
6a46e9d31106
after Hamburg visit
Andreas Thurnherr <ant@ldeo.columbia.edu>
parents:
39
diff
changeset
|
960 |
${$E}[$ens]->{HOUR},${$E}[$ens]->{MINUTE},${$E}[$ens]->{SECONDS}); |
14 | 961 |
|
43
b63fa355644c
commit to merge with changes from EN620
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
42
diff
changeset
|
962 |
# when analyzing an STA file from an OS75 SADCP (Poseidon), |
14 | 963 |
# I noticed that there is no time information. This causes |
964 |
# timegm to bomb. |
|
965 |
if (${$E}[$ens]->{MONTH} == 0) { # no time info |
|
966 |
${$E}[$ens]->{UNIX_TIME} = 0; |
|
967 |
${$E}[$ens]->{SECNO} = 0; |
|
968 |
} else { |
|
43
b63fa355644c
commit to merge with changes from EN620
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
42
diff
changeset
|
969 |
# print(STDERR "[$ens]->${$E}[$ens]->{MINUTE}:${$E}[$ens]->{HOUR},${$E}[$ens]->{DAY},${$E}[$ens]->{MONTH},${$E}[$ens]->{YEAR}-<\n"); |
14 | 970 |
${$E}[$ens]->{UNIX_TIME} |
971 |
= timegm(0,${$E}[$ens]->{MINUTE}, |
|
972 |
${$E}[$ens]->{HOUR}, |
|
973 |
${$E}[$ens]->{DAY}, |
|
974 |
${$E}[$ens]->{MONTH}-1, # timegm jan==0!!! |
|
975 |
${$E}[$ens]->{YEAR}) |
|
976 |
+ ${$E}[$ens]->{SECONDS}; |
|
977 |
||
978 |
$dayStart = timegm(0,0,0,${$E}[$ens]->{DAY}, |
|
979 |
${$E}[$ens]->{MONTH}-1, |
|
980 |
${$E}[$ens]->{YEAR}) |
|
981 |
unless defined($dayStart); |
|
982 |
${$E}[$ens]->{SECNO} = ${$E}[$ens]->{UNIX_TIME} - $dayStart; |
|
983 |
} |
|
984 |
||
985 |
sysseek(WBRF,$start_ens+$WBRofs[0]+4,0) # System Config / Fixed Leader |
|
986 |
|| die("$WBRcfn: $!"); |
|
987 |
||
988 |
sysread(WBRF,$buf,5) == 5 || die("$WBRcfn: $!"); |
|
989 |
($B1,$dummy,$dummy,$dummy,${$E}[$ens]->{N_BEAMS_USED}) |
|
990 |
= unpack('CCCCC',$buf); |
|
991 |
${$E}[$ens]->{XDUCER_FACING_UP} = 1 if ($B1 & 0x80); |
|
992 |
${$E}[$ens]->{XDUCER_FACING_DOWN} = 1 unless ($B1 & 0x80); |
|
993 |
||
994 |
#-------------------- |
|
995 |
# Velocity Data |
|
996 |
#-------------------- |
|
997 |
||
998 |
my($ndata) = $nbins * 4; |
|
999 |
||
1000 |
sysseek(WBRF,$start_ens+$WBRofs[2],0) || die("$WBRcfn: $!"); |
|
1001 |
sysread(WBRF,$buf,2+$ndata*2) == 2+$ndata*2 || die("$WBRcfn: $!"); |
|
1002 |
($id,@dta) = unpack("vv$ndata",$buf); |
|
1003 |
||
1004 |
$id == 0x0100 || |
|
37 | 1005 |
die(sprintf($FmtErr,$WBRcfn,"Velocity Data",$id,$ensNo)); |
14 | 1006 |
|
1007 |
for ($i=0,$bin=0; $bin<$nbins; $bin++) { |
|
1008 |
for ($beam=0; $beam<4; $beam++,$i++) { |
|
1009 |
${$E}[$ens]->{VELOCITY}[$bin][$beam] = |
|
1010 |
unpack('s',pack('S',$dta[$i])) / 1000 |
|
1011 |
if ($dta[$i] != 0x8000); |
|
1012 |
} |
|
1013 |
} |
|
1014 |
||
1015 |
#-------------------- |
|
1016 |
# Correlation Data |
|
1017 |
#-------------------- |
|
1018 |
||
1019 |
sysseek(WBRF,$start_ens+$WBRofs[3],0) || die("$WBRcfn: $!"); |
|
1020 |
sysread(WBRF,$buf,2+$ndata) == 2+$ndata || die("$WBRcfn: $!"); |
|
1021 |
($id,@dta) = unpack("vC$ndata",$buf); |
|
1022 |
||
1023 |
$id == 0x0200 || |
|
37 | 1024 |
die(sprintf($FmtErr,$WBRcfn,"Correlation Data",$id,$ensNo)); |
14 | 1025 |
|
1026 |
for ($i=0,$bin=0; $bin<$nbins; $bin++) { |
|
1027 |
for ($beam=0; $beam<4; $beam++,$i++) { |
|
1028 |
${$E}[$ens]->{CORRELATION}[$bin][$beam] = $dta[$i] |
|
1029 |
if ($dta[$i]); |
|
1030 |
} |
|
1031 |
} |
|
1032 |
||
1033 |
#-------------------- |
|
1034 |
# Echo Intensity Data |
|
1035 |
#-------------------- |
|
1036 |
||
1037 |
sysseek(WBRF,$start_ens+$WBRofs[4],0) || die("$WBRcfn: $!"); |
|
1038 |
sysread(WBRF,$buf,2+$ndata) == 2+$ndata || die("$WBRcfn: $!"); |
|
1039 |
($id,@dta) = unpack("vC$ndata",$buf); |
|
1040 |
||
1041 |
$id == 0x0300 || |
|
37 | 1042 |
die(sprintf($FmtErr,$WBRcfn,"Echo Intensity",$id,$ensNo)); |
14 | 1043 |
|
1044 |
for ($i=0,$bin=0; $bin<$nbins; $bin++) { |
|
1045 |
for ($beam=0; $beam<4; $beam++,$i++) { |
|
1046 |
${$E}[$ens]->{ECHO_AMPLITUDE}[$bin][$beam] = $dta[$i]; |
|
1047 |
} |
|
1048 |
} |
|
1049 |
||
1050 |
#-------------------- |
|
1051 |
# Percent Good Data |
|
1052 |
#-------------------- |
|
1053 |
||
1054 |
sysseek(WBRF,$start_ens+$WBRofs[5],0) || die("$WBRcfn: $!"); |
|
1055 |
sysread(WBRF,$buf,2+$ndata) == 2+$ndata || die("$WBRcfn: $!"); |
|
1056 |
($id,@dta) = unpack("vC$ndata",$buf); |
|
1057 |
||
1058 |
$id == 0x0400 || |
|
37 | 1059 |
die(sprintf($FmtErr,$WBRcfn,"Percent-Good Data",$id,$ensNo)); |
14 | 1060 |
|
1061 |
for ($i=0,$bin=0; $bin<$nbins; $bin++) { |
|
1062 |
for ($beam=0; $beam<4; $beam++,$i++) { |
|
1063 |
${$E}[$ens]->{PERCENT_GOOD}[$bin][$beam] = $dta[$i]; |
|
1064 |
} |
|
1065 |
} |
|
1066 |
||
18 | 1067 |
#----------------------------------------- |
14 | 1068 |
# Bottom-Track Data |
18 | 1069 |
# - scan through remaining data types |
1070 |
#----------------------------------------- |
|
14 | 1071 |
|
18 | 1072 |
my($nxt); |
1073 |
for ($nxt=6; $nxt<$ndt; $nxt++) { # scan until BT found |
|
1074 |
sysseek(WBRF,$start_ens+$WBRofs[$nxt],0) || die("$WBRcfn: $!"); |
|
14 | 1075 |
sysread(WBRF,$buf,2) == 2 || die("$WBRcfn: $!"); |
1076 |
$id = unpack('v',$buf); |
|
18 | 1077 |
last if ($id == 0x0600); |
1078 |
} |
|
1079 |
||
43
b63fa355644c
commit to merge with changes from EN620
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
42
diff
changeset
|
1080 |
if ($nxt == $ndt) { # no BT found => next ens |
b63fa355644c
commit to merge with changes from EN620
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
42
diff
changeset
|
1081 |
# sysseek(WBRF,4,1) || die("$WBRcfn: $!"); # skip over remainder of ensemble |
b63fa355644c
commit to merge with changes from EN620
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
42
diff
changeset
|
1082 |
sysseek(WBRF,$start_ens+$ens_length+2,0) || die("$WBRcfn: $!"); |
b63fa355644c
commit to merge with changes from EN620
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
42
diff
changeset
|
1083 |
next; |
b63fa355644c
commit to merge with changes from EN620
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
42
diff
changeset
|
1084 |
} |
18 | 1085 |
|
32 | 1086 |
sysseek(WBRF,14,1) || die("$WBRcfn: $!"); # BT range, velocity, corr, %-good, ... |
18 | 1087 |
sysread(WBRF,$buf,28) == 28 || die("$WBRcfn: $!"); |
1088 |
@dta = unpack('v4v4C4C4C4',$buf); |
|
1089 |
for ($beam=0; $beam<4; $beam++) { |
|
32 | 1090 |
${$E}[$ens]->{BT_RANGE}[$beam] = $dta[$beam] / 100 # lower 2 bytes only! |
1091 |
if ($dta[$beam]); # (see below for high bytes) |
|
18 | 1092 |
} |
1093 |
for ($beam=0; $beam<4; $beam++) { |
|
1094 |
${$E}[$ens]->{BT_VELOCITY}[$beam] = |
|
1095 |
unpack('s',pack('S',$dta[4+$beam])) / 1000 |
|
1096 |
if ($dta[4+$beam] != 0x8000); |
|
1097 |
} |
|
1098 |
for ($beam=0; $beam<4; $beam++) { |
|
1099 |
${$E}[$ens]->{BT_CORRELATION}[$beam] = $dta[8+$beam] |
|
1100 |
if ($dta[8+$beam]); |
|
1101 |
} |
|
32 | 1102 |
for ($beam=0; $beam<4; $beam++) { # BT filter parameter |
18 | 1103 |
${$E}[$ens]->{BT_EVAL_AMPLITUDE}[$beam] = $dta[12+$beam]; |
1104 |
} |
|
1105 |
for ($beam=0; $beam<4; $beam++) { |
|
1106 |
${$E}[$ens]->{BT_PERCENT_GOOD}[$beam] = $dta[16+$beam]; |
|
1107 |
} |
|
1108 |
||
32 | 1109 |
sysseek(WBRF,6,1) || die("$WBRcfn: $!"); # BT ref level stuff |
18 | 1110 |
sysread(WBRF,$buf,20) == 20 || die("$WBRcfn: $!"); |
1111 |
@dta = unpack('v4C4C4C4',$buf); |
|
1112 |
for ($beam=0; $beam<4; $beam++) { |
|
1113 |
${$E}[$ens]->{BT_RL_VELOCITY}[$beam] = |
|
1114 |
unpack('s',pack('S',$dta[$beam])) / 1000 |
|
1115 |
if ($dta[$beam] != 0x8000); |
|
1116 |
} |
|
1117 |
for ($beam=0; $beam<4; $beam++) { |
|
1118 |
${$E}[$ens]->{BT_RL_CORRELATION}[$beam] = $dta[4+$beam] |
|
1119 |
if ($dta[4+$beam]); |
|
1120 |
} |
|
1121 |
for ($beam=0; $beam<4; $beam++) { |
|
1122 |
${$E}[$ens]->{BT_RL_ECHO_AMPLITUDE}[$beam] = $dta[8+$beam]; |
|
1123 |
} |
|
1124 |
for ($beam=0; $beam<4; $beam++) { |
|
1125 |
${$E}[$ens]->{BT_RL_PERCENT_GOOD}[$beam] = $dta[12+$beam]; |
|
1126 |
} |
|
1127 |
||
32 | 1128 |
sysseek(WBRF,2,1) || die("$WBRcfn: $!"); # BT signal strength & BT range high bytes |
43
b63fa355644c
commit to merge with changes from EN620
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
42
diff
changeset
|
1129 |
# sysread(WBRF,$buf,9) == 9 || die("$WBRcfn: $!"); |
b63fa355644c
commit to merge with changes from EN620
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
42
diff
changeset
|
1130 |
if (sysread(WBRF,$buf,9) == 9) { # SR1b JR16 BB150 data files require this |
b63fa355644c
commit to merge with changes from EN620
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
42
diff
changeset
|
1131 |
@dta = unpack('C4CC4',$buf); |
b63fa355644c
commit to merge with changes from EN620
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
42
diff
changeset
|
1132 |
for ($beam=0; $beam<4; $beam++) { |
b63fa355644c
commit to merge with changes from EN620
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
42
diff
changeset
|
1133 |
${$E}[$ens]->{BT_SIGNAL_STRENGTH}[$beam] = $dta[$beam]; |
b63fa355644c
commit to merge with changes from EN620
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
42
diff
changeset
|
1134 |
} |
b63fa355644c
commit to merge with changes from EN620
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
42
diff
changeset
|
1135 |
${$E}[$ens]->{HIGH_GAIN} if ($dta[4]); |
b63fa355644c
commit to merge with changes from EN620
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
42
diff
changeset
|
1136 |
${$E}[$ens]->{LOW_GAIN} unless ($dta[4]); |
b63fa355644c
commit to merge with changes from EN620
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
42
diff
changeset
|
1137 |
for ($beam=0; $beam<4; $beam++) { # high bytes (1 byte per beam) |
b63fa355644c
commit to merge with changes from EN620
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
42
diff
changeset
|
1138 |
${$E}[$ens]->{BT_RANGE}[$beam] += $dta[5+$beam] * 655.36 |
b63fa355644c
commit to merge with changes from EN620
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
42
diff
changeset
|
1139 |
if ($dta[5+$beam]); |
b63fa355644c
commit to merge with changes from EN620
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
42
diff
changeset
|
1140 |
} |
b63fa355644c
commit to merge with changes from EN620
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
42
diff
changeset
|
1141 |
# sysseek(WBRF,8,1) || die("$WBRcfn: $!"); # remainder of ensemble |
b63fa355644c
commit to merge with changes from EN620
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
42
diff
changeset
|
1142 |
} |
b63fa355644c
commit to merge with changes from EN620
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
42
diff
changeset
|
1143 |
sysseek(WBRF,$start_ens+$ens_length+2,0) || die("$WBRcfn: $!"); |
14 | 1144 |
} # ens loop |
1145 |
} |
|
1146 |
||
1147 |
#---------------------------------------------------------------------- |
|
28 | 1148 |
# writeData(output_file_name,^data) WBPens(nbins,fixed_leader_bytes,^data) |
1149 |
# - writeData() copies file previously read with readData() to output_file_name |
|
1150 |
# - WBPens() patches new PD0 file with ^data |
|
1151 |
# - ^data is modified!!!! |
|
1152 |
# - output file must already exist and have correct structure |
|
1153 |
# - only subset of data structure is patched: |
|
1154 |
# - Header: Data Source Id |
|
1155 |
# - Var Ldr: Soundspeed, Depth, Heading, Pitch, Roll, Temp, Salin |
|
1156 |
# - Data: Velocity, Correlation, Echo Amp, %-Good, |
|
14 | 1157 |
#---------------------------------------------------------------------- |
1158 |
||
1159 |
sub writeData(@) |
|
1160 |
{ |
|
1161 |
my($fn,$dta) = @_; |
|
1162 |
||
1163 |
die("writeData() needs \$WBRcfn from previous readData()") |
|
31 | 1164 |
unless (length($WBRcfn) > 0); |
1165 |
||
1166 |
sysseek(WBRF,0,0) || die("$WBRcfn: $!"); # rewind input file |
|
1167 |
$WBPcfn = $fn; # set patch file name for error messages |
|
1168 |
open(WBPF,"+>$WBPcfn") || die("$WBPcfn: $!"); # open patch file for r/w |
|
14 | 1169 |
|
31 | 1170 |
while (1) { # copy input file to patch file |
1171 |
my($buf); |
|
1172 |
my($nread) = sysread(WBRF,$buf,100*1024); |
|
1173 |
die("$WBRcfn: $!\n") if ($nread < 0); |
|
1174 |
last if ($nread == 0); |
|
1175 |
my($nwritten) = syswrite(WBPF,$buf,100*1024); |
|
1176 |
die("$WBPcfn: $! ($nwritten of $nread written)\n") |
|
1177 |
unless ($nwritten = $nread); |
|
1178 |
} |
|
1179 |
sysseek(WBPF,0,0) || die("$WBPcfn: $!"); # rewind patch file |
|
1180 |
||
1181 |
WBPens($dta->{N_BINS},$dta->{FIXED_LEADER_BYTES},$dta); |
|
14 | 1182 |
} |
1183 |
||
37 | 1184 |
sub _round(@) |
28 | 1185 |
{ |
1186 |
return $_[0] >= 0 ? int($_[0] + 0.5) |
|
1187 |
: int($_[0] - 0.5); |
|
1188 |
} |
|
1189 |
||
1190 |
||
14 | 1191 |
sub WBPens($$$) |
1192 |
{ |
|
31 | 1193 |
my($nbins,$fixed_leader_bytes,$dta) = @_; |
14 | 1194 |
my($start_ens,$B1,$B2,$B3,$B4,$I,$id,$bin,$beam,$buf,$dummy,@dta,$i,$cs,@WBPofs); |
43
b63fa355644c
commit to merge with changes from EN620
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
42
diff
changeset
|
1195 |
my($ens,$dayStart,$ens_length,$hid,$ndt,$el); |
14 | 1196 |
|
43
b63fa355644c
commit to merge with changes from EN620
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
42
diff
changeset
|
1197 |
# for ($ens=$start_ens=0; $ens<=$#{$dta->{ENSEMBLE}}; $ens++,$start_ens+=$ens_length+2) { |
b63fa355644c
commit to merge with changes from EN620
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
42
diff
changeset
|
1198 |
for ($ens=0; $ens<=$#{$dta->{ENSEMBLE}}; $ens++) { |
b63fa355644c
commit to merge with changes from EN620
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
42
diff
changeset
|
1199 |
$start_ens = goto_next_ens(\*WBPF); |
b63fa355644c
commit to merge with changes from EN620
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
42
diff
changeset
|
1200 |
die("ens = $ens\n") unless defined($start_ens); |
14 | 1201 |
|
18 | 1202 |
#------------------------------ |
1203 |
# Patch Header (Data Source Id) |
|
1204 |
#------------------------------ |
|
14 | 1205 |
|
1206 |
sysseek(WBPF,$start_ens,0) || die("$WBPcfn: $!"); |
|
18 | 1207 |
sysread(WBPF,$buf,1) || die("$WBPcfn: unexpected EOF"); |
1208 |
($hid) = unpack('C',$buf); |
|
1209 |
$hid == 0x7f || die(sprintf($FmtErr,$WBPcfn,"Header",$hid,$ens)); |
|
1210 |
||
31 | 1211 |
$buf = pack('C',$dta->{ENSEMBLE}[$ens]->{DATA_SOURCE_ID}); |
18 | 1212 |
my($nw) = syswrite(WBPF,$buf,1); |
1213 |
$nw == 1 || die("$WBPcfn: $nw bytes written ($!)"); |
|
1214 |
||
1215 |
sysread(WBPF,$buf,4) == 4 || die("$WBPcfn: unexpected EOF"); |
|
43
b63fa355644c
commit to merge with changes from EN620
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
42
diff
changeset
|
1216 |
($el,$dummy,$ndt) = unpack('vCC',$buf); |
b63fa355644c
commit to merge with changes from EN620
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
42
diff
changeset
|
1217 |
$ens--,next if (defined($ens_length) && ($el != $ens_length)); |
b63fa355644c
commit to merge with changes from EN620
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
42
diff
changeset
|
1218 |
$ens_length = $el; |
b63fa355644c
commit to merge with changes from EN620
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
42
diff
changeset
|
1219 |
|
b63fa355644c
commit to merge with changes from EN620
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
42
diff
changeset
|
1220 |
printf(STDERR "$WBPcfn: WARNING: unexpected number of data types (%d, ens=$ens)\n",$ndt),last |
14 | 1221 |
unless ($ndt == 6 || $ndt == 7); |
18 | 1222 |
|
14 | 1223 |
sysread(WBPF,$buf,2*$ndt) == 2*$ndt || die("$WBPcfn: $!"); |
1224 |
@WBPofs = unpack("v$ndt",$buf); |
|
1225 |
$fixed_leader_bytes = $WBPofs[1] - $WBPofs[0]; |
|
31 | 1226 |
|
1227 |
#-------------------- |
|
1228 |
# Fixed Leader |
|
1229 |
#-------------------- |
|
14 | 1230 |
|
32 | 1231 |
sysseek(WBPF,$start_ens+$WBPofs[0]+4,0) # system config (transducer orientation) |
1232 |
|| die("$WBPcfn: $!"); |
|
1233 |
sysread(WBPF,$buf,1) == 1 || die("$WBPcfn: $!"); |
|
1234 |
$B1 = unpack('C',$buf); |
|
1235 |
$B1 |= 0x80 if ($dta->{ENSEMBLE}[$ens]->{XDUCER_FACING_UP}); |
|
1236 |
$B1 &= 0x7F if ($dta->{ENSEMBLE}[$ens]->{XDUCER_FACING_DOWN}); |
|
1237 |
$buf = pack('C',$B1); |
|
1238 |
sysseek(WBPF,$start_ens+$WBPofs[0]+4,0) |
|
1239 |
|| die("$WBPcfn: $!"); |
|
1240 |
syswrite(WBPF,$buf,1) == 1 || die("$WBPcfn: $!"); |
|
1241 |
||
1242 |
sysseek(WBPF,$start_ens+$WBPofs[0]+25,0) || die("$WBPcfn: $!"); # EX / coord-transformation |
|
31 | 1243 |
sysread(WBPF,$buf,1) == 1 || die("$WBPcfn: $!"); |
1244 |
my($EX) = unpack('C',$buf); |
|
1245 |
if ($dta->{BEAM_COORDINATES}) { |
|
1246 |
$EX &= ~0x18; |
|
1247 |
} elsif ($dta->{EARTH_COORDINATES}) { |
|
1248 |
$EX |= 0x18; |
|
1249 |
} else { |
|
1250 |
die("$WBPcfn: only beam- and earth coordinates are supported (implementation restriction)\n"); |
|
1251 |
} |
|
1252 |
$buf = pack('C',$EX); |
|
1253 |
sysseek(WBPF,$start_ens+$WBPofs[0]+25,0) || die("$WBPcfn: $!"); |
|
1254 |
syswrite(WBPF,$buf,1) == 1 || die("$WBPcfn: $!"); |
|
1255 |
||
42 | 1256 |
#---------------------------------------------------------------------- |
43
b63fa355644c
commit to merge with changes from EN620
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
42
diff
changeset
|
1257 |
# Variable Leader #0 |
b63fa355644c
commit to merge with changes from EN620
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
42
diff
changeset
|
1258 |
# - read ensNo for debugging purposes |
b63fa355644c
commit to merge with changes from EN620
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
42
diff
changeset
|
1259 |
#---------------------------------------------------------------------- |
b63fa355644c
commit to merge with changes from EN620
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
42
diff
changeset
|
1260 |
|
b63fa355644c
commit to merge with changes from EN620
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
42
diff
changeset
|
1261 |
sysseek(WBPF,$start_ens+$WBPofs[1]+2,0) || die("$WBPcfn: $!"); |
b63fa355644c
commit to merge with changes from EN620
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
42
diff
changeset
|
1262 |
sysread(WBPF,$buf,2) == 2 || die("$WBPcfn: $!"); |
b63fa355644c
commit to merge with changes from EN620
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
42
diff
changeset
|
1263 |
my($ensNo) = unpack("v",$buf); # only lower two bytes!!! |
b63fa355644c
commit to merge with changes from EN620
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
42
diff
changeset
|
1264 |
sysseek(WBPF,$start_ens+$WBPofs[1]+13,0) || die("$WBPcfn: $!"); # jump to high byte |
b63fa355644c
commit to merge with changes from EN620
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
42
diff
changeset
|
1265 |
sysread(WBPF,$buf,1) == 1 || die("$WBPcfn: $!"); |
b63fa355644c
commit to merge with changes from EN620
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
42
diff
changeset
|
1266 |
$ensNo += unpack('C',$buf) << 16; |
b63fa355644c
commit to merge with changes from EN620
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
42
diff
changeset
|
1267 |
die("ensNo = $ensNo (should be $dta->{ENSEMBLE}[$ens]->{NUMBER})\n") |
b63fa355644c
commit to merge with changes from EN620
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
42
diff
changeset
|
1268 |
unless ($ensNo == $dta->{ENSEMBLE}[$ens]->{NUMBER}); |
b63fa355644c
commit to merge with changes from EN620
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
42
diff
changeset
|
1269 |
|
b63fa355644c
commit to merge with changes from EN620
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
42
diff
changeset
|
1270 |
#---------------------------------------------------------------------- |
42 | 1271 |
# Variable Leader #1 |
1272 |
# - if $RDI_PD0_IO::OVERRIDE_Y2K_CLOCK is set, the data from the pre-Y2K |
|
1273 |
# clock are used to override the ADCP clock values; this allows |
|
1274 |
# a better time to be recorded by the data acquisition system |
|
1275 |
# without overwriting the main instrument clock data |
|
1276 |
#---------------------------------------------------------------------- |
|
31 | 1277 |
|
42 | 1278 |
if ($RDI_PD0_IO::OVERRIDE_Y2K_CLOCK) { |
1279 |
sysseek(WBPF,$start_ens+$WBPofs[1]+4,0) || die("$WBPcfn: $!"); # jump to RTC_YEAR |
|
43
b63fa355644c
commit to merge with changes from EN620
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
42
diff
changeset
|
1280 |
sysread(WBPF,$buf,7) == 7 || die("$WBPcfn: $!"); # read pre-Y2K clock |
42 | 1281 |
($dta->{ENSEMBLE}[$ens]->{YEAR}, |
1282 |
$dta->{ENSEMBLE}[$ens]->{MONTH}, |
|
1283 |
$dta->{ENSEMBLE}[$ens]->{DAY}, |
|
1284 |
$dta->{ENSEMBLE}[$ens]->{HOUR}, |
|
1285 |
$dta->{ENSEMBLE}[$ens]->{MINUTE}, |
|
1286 |
$dta->{ENSEMBLE}[$ens]->{SECONDS},$B4) = |
|
1287 |
unpack('CCCCCCC',$buf); |
|
1288 |
$dta->{ENSEMBLE}[$ens]->{SECONDS} += $B4/100; |
|
1289 |
$dta->{ENSEMBLE}[$ens]->{YEAR} += ($dta->{ENSEMBLE}[$ens]->{YEAR} > 80) ? 1900 : 2000; |
|
1290 |
} |
|
1291 |
||
1292 |
#---------------------------------------------------------------------- |
|
1293 |
# Variable Leader #2 |
|
43
b63fa355644c
commit to merge with changes from EN620
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
42
diff
changeset
|
1294 |
# - read ensemble number for debugging purposes |
42 | 1295 |
# - patch everything from SPEED_OF_SOUND to TEMPERATURE |
1296 |
# - at one stage, IMP allowed for missing values in pitch/roll and heading; |
|
1297 |
# on 12/23/2017 the corresponding code was disabled (replaced by assertion) |
|
1298 |
#---------------------------------------------------------------------- |
|
1299 |
||
1300 |
sysseek(WBPF,$start_ens+$WBPofs[1]+14,0) || die("$WBPcfn: $!"); # jump to SPEED_OF_SOUND |
|
14 | 1301 |
|
37 | 1302 |
$dta->{ENSEMBLE}[$ens]->{XDUCER_DEPTH} = _round($dta->{ENSEMBLE}[$ens]->{XDUCER_DEPTH}*10); |
18 | 1303 |
|
42 | 1304 |
# $dta->{ENSEMBLE}[$ens]->{HEADING} = defined($dta->{ENSEMBLE}[$ens]->{HEADING}) |
1305 |
# ? _round($dta->{ENSEMBLE}[$ens]->{HEADING}*100) |
|
1306 |
# : 0xF000; |
|
1307 |
# $dta->{ENSEMBLE}[$ens]->{PITCH} = defined($dta->{ENSEMBLE}[$ens]->{PITCH}) |
|
1308 |
# ? unpack('S',pack('s',_round($dta->{ENSEMBLE}[$ens]->{PITCH}*100))) |
|
1309 |
# : 0x8000; |
|
1310 |
# $dta->{ENSEMBLE}[$ens]->{ROLL} = defined($dta->{ENSEMBLE}[$ens]->{ROLL}) |
|
1311 |
# ? unpack('S',pack('s',_round($dta->{ENSEMBLE}[$ens]->{ROLL}*100))) |
|
1312 |
# : 0x8000; |
|
28 | 1313 |
|
42 | 1314 |
croak("$0: assertion failed") unless defined($dta->{ENSEMBLE}[$ens]->{HEADING}) && |
1315 |
defined($dta->{ENSEMBLE}[$ens]->{PITCH}) && |
|
1316 |
defined($dta->{ENSEMBLE}[$ens]->{ROLL}); |
|
1317 |
$dta->{ENSEMBLE}[$ens]->{HEADING} = _round($dta->{ENSEMBLE}[$ens]->{HEADING}*100); |
|
1318 |
$dta->{ENSEMBLE}[$ens]->{PITCH} = unpack('S',pack('s',_round($dta->{ENSEMBLE}[$ens]->{PITCH}*100))); |
|
1319 |
$dta->{ENSEMBLE}[$ens]->{ROLL} = unpack('S',pack('s',_round($dta->{ENSEMBLE}[$ens]->{ROLL}*100))); |
|
1320 |
$dta->{ENSEMBLE}[$ens]->{TEMPERATURE} = unpack('S',pack('s',_round($dta->{ENSEMBLE}[$ens]->{TEMPERATURE}*100))); |
|
14 | 1321 |
|
1322 |
$buf = pack('vvvvvvv', |
|
31 | 1323 |
$dta->{ENSEMBLE}[$ens]->{SPEED_OF_SOUND}, |
1324 |
$dta->{ENSEMBLE}[$ens]->{XDUCER_DEPTH},$dta->{ENSEMBLE}[$ens]->{HEADING}, |
|
1325 |
$dta->{ENSEMBLE}[$ens]->{PITCH},$dta->{ENSEMBLE}[$ens]->{ROLL}, |
|
1326 |
$dta->{ENSEMBLE}[$ens]->{SALINITY},$dta->{ENSEMBLE}[$ens]->{TEMPERATURE}); |
|
14 | 1327 |
|
1328 |
my($nw) = syswrite(WBPF,$buf,14); |
|
1329 |
$nw == 14 || die("$WBPcfn: $nw bytes written ($!)"); |
|
1330 |
||
28 | 1331 |
|
42 | 1332 |
#---------------------------------------------------------------------- |
1333 |
# Variable Leader #3 |
|
1334 |
# - patch Y2K RTC |
|
1335 |
#---------------------------------------------------------------------- |
|
1336 |
||
1337 |
sysseek(WBPF,$start_ens+$WBPofs[1]+57,0) || die("$WBPcfn: $!"); # jump to RTC_CENTURY |
|
1338 |
||
1339 |
my($century) = int($dta->{ENSEMBLE}[$ens]->{YEAR} / 100); |
|
1340 |
my($year) = $dta->{ENSEMBLE}[$ens]->{YEAR} % 100; |
|
1341 |
my($seconds) = int($dta->{ENSEMBLE}[$ens]->{SECONDS}); |
|
1342 |
my($hundredths) = 100 * ($dta->{ENSEMBLE}[$ens]->{SECONDS} - $seconds); |
|
1343 |
$buf = pack('CCCCCCCC',$century,$year,$dta->{ENSEMBLE}[$ens]->{MONTH}, |
|
1344 |
$dta->{ENSEMBLE}[$ens]->{DAY},$dta->{ENSEMBLE}[$ens]->{HOUR}, |
|
1345 |
$dta->{ENSEMBLE}[$ens]->{MINUTE},$seconds,$hundredths); |
|
1346 |
my($nw) = syswrite(WBPF,$buf,8); |
|
1347 |
$nw == 8 || die("$WBPcfn: $nw bytes written ($!)"); |
|
1348 |
||
28 | 1349 |
#-------------------- |
1350 |
# Velocity Data |
|
1351 |
#-------------------- |
|
1352 |
||
32 | 1353 |
sysseek(WBPF,$start_ens+$WBPofs[2]+2,0) || die("$WBPcfn: $!"); # skip velocity data id (assume it is correct) |
28 | 1354 |
for ($bin=0; $bin<$nbins; $bin++) { |
1355 |
for ($beam=0; $beam<4; $beam++) { |
|
31 | 1356 |
$dta->{ENSEMBLE}[$ens]->{VELOCITY}[$bin][$beam] = defined($dta->{ENSEMBLE}[$ens]->{VELOCITY}[$bin][$beam]) |
37 | 1357 |
? _round($dta->{ENSEMBLE}[$ens]->{VELOCITY}[$bin][$beam]*1000) |
28 | 1358 |
: 0x8000; |
31 | 1359 |
$buf = pack('v',unpack('S',pack('s',$dta->{ENSEMBLE}[$ens]->{VELOCITY}[$bin][$beam]))); |
28 | 1360 |
my($nw) = syswrite(WBPF,$buf,2); |
1361 |
$nw == 2 || die("$WBPcfn: $nw bytes written ($!)"); |
|
1362 |
} |
|
1363 |
} |
|
1364 |
||
1365 |
#-------------------- |
|
1366 |
# Correlation Data |
|
1367 |
#-------------------- |
|
1368 |
||
32 | 1369 |
sysseek(WBPF,$start_ens+$WBPofs[3]+2,0) || die("$WBPcfn: $!"); |
28 | 1370 |
for ($bin=0; $bin<$nbins; $bin++) { |
1371 |
for ($beam=0; $beam<4; $beam++) { |
|
31 | 1372 |
$buf = pack('C',$dta->{ENSEMBLE}[$ens]->{CORRELATION}[$bin][$beam]); |
28 | 1373 |
my($nw) = syswrite(WBPF,$buf,1); |
1374 |
$nw == 1 || die("$WBPcfn: $nw bytes written ($!)"); |
|
1375 |
} |
|
1376 |
} |
|
1377 |
||
1378 |
#-------------------- |
|
1379 |
# Echo Intensity Data |
|
1380 |
#-------------------- |
|
1381 |
||
32 | 1382 |
sysseek(WBPF,$start_ens+$WBPofs[4]+2,0) || die("$WBPcfn: $!"); |
28 | 1383 |
|
1384 |
for ($bin=0; $bin<$nbins; $bin++) { |
|
1385 |
for ($beam=0; $beam<4; $beam++) { |
|
31 | 1386 |
$buf = pack('C',$dta->{ENSEMBLE}[$ens]->{ECHO_AMPLITUDE}[$bin][$beam]); |
28 | 1387 |
my($nw) = syswrite(WBPF,$buf,1); |
1388 |
$nw == 1 || die("$WBPcfn: $nw bytes written ($!)"); |
|
1389 |
} |
|
1390 |
} |
|
1391 |
||
1392 |
#-------------------- |
|
1393 |
# Percent Good Data |
|
1394 |
#-------------------- |
|
1395 |
||
32 | 1396 |
sysseek(WBPF,$start_ens+$WBPofs[5]+2,0) || die("$WBPcfn: $!"); |
28 | 1397 |
|
1398 |
for ($i=0,$bin=0; $bin<$nbins; $bin++) { |
|
1399 |
for ($beam=0; $beam<4; $beam++,$i++) { |
|
31 | 1400 |
$buf = pack('C',$dta->{ENSEMBLE}[$ens]->{PERCENT_GOOD}[$bin][$beam]); |
28 | 1401 |
my($nw) = syswrite(WBPF,$buf,1); |
1402 |
$nw == 1 || die("$WBPcfn: $nw bytes written ($!)"); |
|
1403 |
} |
|
1404 |
} |
|
1405 |
||
1406 |
#----------------------------------------- |
|
1407 |
# Bottom-Track Data |
|
1408 |
# - scan through remaining data types |
|
1409 |
#----------------------------------------- |
|
1410 |
||
1411 |
my($nxt); |
|
1412 |
for ($nxt=6; $nxt<$ndt; $nxt++) { # scan until BT found |
|
32 | 1413 |
sysseek(WBPF,$start_ens+$WBPofs[$nxt],0) || die("$WBPcfn: $!"); |
36
515b06dae59c
version at end of ECOGIG EN586 cruise
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
32
diff
changeset
|
1414 |
sysread(WBPF,$buf,2) == 2 || die("$WBPcfn: $! [ens=$ens]"); |
28 | 1415 |
$id = unpack('v',$buf); |
1416 |
last if ($id == 0x0600); |
|
1417 |
} |
|
1418 |
||
1419 |
unless ($nxt == $ndt) { # BT found |
|
32 | 1420 |
sysseek(WBPF,14,1) || die("$WBPcfn: $!"); # skip BT config |
1421 |
for ($beam=0; $beam<4; $beam++) { # BT range low bytes (2 per beam) |
|
37 | 1422 |
$buf = pack('v',_round($dta->{ENSEMBLE}[$ens]->{BT_RANGE}[$beam] * 100) & 0xFFFF); |
32 | 1423 |
my($nw) = syswrite(WBPF,$buf,2); |
1424 |
$nw == 2 || die("$WBPcfn: $nw bytes written ($!)"); |
|
1425 |
} |
|
1426 |
||
1427 |
for ($beam=0; $beam<4; $beam++) { # BT velocities |
|
1428 |
$buf = pack('v',unpack('S',pack('s', |
|
1429 |
defined($dta->{ENSEMBLE}[$ens]->{BT_VELOCITY}[$beam]) |
|
37 | 1430 |
? _round($dta->{ENSEMBLE}[$ens]->{BT_VELOCITY}[$beam]*1000) |
32 | 1431 |
: 0x8000))); |
1432 |
my($nw) = syswrite(WBPF,$buf,2); |
|
1433 |
$nw == 2 || die("$WBPcfn: $nw bytes written ($!)"); |
|
1434 |
} |
|
1435 |
||
1436 |
for ($beam=0; $beam<4; $beam++) { # BT correlation |
|
1437 |
$buf = pack('C',$dta->{ENSEMBLE}[$ens]->{BT_CORRELATION}[$beam]); |
|
1438 |
my($nw) = syswrite(WBPF,$buf,1); |
|
1439 |
$nw == 1 || die("$WBPcfn: $nw bytes written ($!)"); |
|
1440 |
} |
|
1441 |
||
1442 |
for ($beam=0; $beam<4; $beam++) { # BT evaluation amp of matching filter |
|
1443 |
$buf = pack('C',$dta->{ENSEMBLE}[$ens]->{BT_EVAL_AMPLITUDE}[$beam]); |
|
1444 |
my($nw) = syswrite(WBPF,$buf,1); |
|
1445 |
$nw == 1 || die("$WBPcfn: $nw bytes written ($!)"); |
|
1446 |
} |
|
1447 |
||
1448 |
for ($beam=0; $beam<4; $beam++) { # BT percent good |
|
1449 |
$buf = pack('C',$dta->{ENSEMBLE}[$ens]->{BT_PERCENT_GOOD}[$beam]); |
|
1450 |
my($nw) = syswrite(WBPF,$buf,1); |
|
1451 |
$nw == 1 || die("$WBPcfn: $nw bytes written ($!)"); |
|
1452 |
} |
|
28 | 1453 |
|
32 | 1454 |
sysseek(WBPF,33,1) || die("$WBPcfn: $!"); # BT range high bytes (1 per beam) |
1455 |
for ($beam=0; $beam<4; $beam++) { |
|
37 | 1456 |
$buf = pack('C',(_round($dta->{ENSEMBLE}[$ens]->{BT_RANGE}[$beam]*100) & 0xFF0000) >> 16); |
32 | 1457 |
my($nw) = syswrite(WBPF,$buf,1); |
1458 |
$nw == 1 || die("$WBPcfn: $nw bytes written ($!)"); |
|
1459 |
} |
|
1460 |
||
1461 |
} # if BT found |
|
28 | 1462 |
|
14 | 1463 |
#---------------- |
1464 |
# Update Checksum |
|
1465 |
#---------------- |
|
1466 |
||
1467 |
sysseek(WBPF,$start_ens,0) || die("$WBPcfn: $!"); |
|
1468 |
sysread(WBPF,$buf,$ens_length) == $ens_length || die("$WBPcfn: $!"); |
|
1469 |
$cs = unpack('%16C*',$buf); |
|
1470 |
$buf = pack('v',$cs); |
|
1471 |
$nw = syswrite(WBPF,$buf,2); |
|
1472 |
$nw == 2 || die("$WBPcfn: $nw bytes written, ens=$ens ($!)"); |
|
1473 |
||
1474 |
} # ens loop |
|
1475 |
} |
|
1476 |
||
37 | 1477 |
#---------------------------------------------------------------------- |
1478 |
# &clearEns(^data,ens-index) |
|
1479 |
# - undefine all velocities in ensemble, including BT |
|
1480 |
# - this is required for the LDEO_IX software, |
|
1481 |
# which does not recognize missing attitude values |
|
1482 |
# - set percent good to zero |
|
1483 |
# - this is done for consistency |
|
1484 |
# - DO NOT undef heading, pitch and roll |
|
1485 |
# - the LDEO software does not recognize missing attitude vals |
|
1486 |
# and, therefore, misinterprets those |
|
1487 |
# - while this should not matter because all the velocities are |
|
1488 |
# also deleted, it was found that setting only the heading to |
|
1489 |
# undef'd and leaving pitch and roll unchanged causes |
|
1490 |
# significant errors in GPS velocity referencing! This |
|
1491 |
# must be a bug |
|
1492 |
# - also, if attitudes are undef'd the LDEO software |
|
1493 |
# cannto determine the instrument offset from pitch/roll |
|
1494 |
# and the pitch/roll DL vs UL plots are bogus |
|
1495 |
#---------------------------------------------------------------------- |
|
1496 |
||
1497 |
sub clearEns($$) |
|
1498 |
{ |
|
1499 |
my($dta,$ens) = @_; |
|
39 | 1500 |
die("clearEns: ens-index $ens out of range\n") |
37 | 1501 |
unless ($ens>=0 && $ens<=$#{$dta->{ENSEMBLE}}); |
1502 |
for (my($bin)=0; $bin<$dta->{N_BINS}; $bin++) { |
|
1503 |
undef(@{$dta->{ENSEMBLE}[$ens]->{VELOCITY}[$bin]}); |
|
1504 |
@{$dta->{ENSEMBLE}[$ens]->{PERCENT_GOOD}[$bin]} = (0,0,0,0); |
|
1505 |
} |
|
1506 |
undef(@{$dta->{ENSEMBLE}[$ens]->{BT_VELOCITY}}); |
|
1507 |
@{$dta->{ENSEMBLE}[$ens]->{BT_PERCENT_GOOD}} = (0,0,0,0); |
|
1508 |
# undef($dta->{ENSEMBLE}[$ens]->{HEADING}); |
|
1509 |
# undef($dta->{ENSEMBLE}[$ens]->{PITCH}); |
|
1510 |
# undef($dta->{ENSEMBLE}[$ens]->{ROLL}); |
|
1511 |
} |
|
1512 |
||
14 | 1513 |
1; # return true for all the world to see |