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