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