Changeset 315
- Timestamp:
- 01/08/10 11:43:28
- Files:
-
- DPWP/trunk/DPWP/ADCP_splitter/adcpwaves.py (modified) (11 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
DPWP/trunk/DPWP/ADCP_splitter/adcpwaves.py
r225 r315 1 1 """This code takes the raw waves portion of the adcp data from the splitter 2 2 and outputs pressure, range, orbital velocity and system info text files that 3 can be read into matlab.""" 3 can be read into matlab. 4 5 NOTE: Transducer height above bottom is hardwired into this code at .4m. 6 Need to update code in the future to be a user selected option""" 4 7 5 8 … … 17 20 18 21 ifile = open(infileName, 'rb') 22 23 # set the transducer height above bottom 24 thab = 0.4 19 25 20 26 … … 35 41 Header =struct.unpack('H',readFirstHeader)[0] 36 42 #print 'headerID=', hex(Header) 43 if Header != 31103: 44 print(' \n error with file, check to see that file is a waves file') 45 break 37 46 38 47 firstLeaderHeader=259 39 48 wavePingHeader=515 40 49 lastLeaderHeader=771 41 42 #read the length 43 length=ifile.read(2) 44 length=struct.unpack('H',length)[0] 50 HPRheader=1027 51 52 #read the checksum offset 53 csOffset=ifile.read(2) 54 csOffset=struct.unpack('H',csOffset)[0] 45 55 46 56 #read 4 bytes before the leader ID 47 ifile.read(4) 57 spare=ifile.read(1) 58 59 readDatatypes=ifile.read(1) 60 datatypes=struct.unpack('B',readDatatypes)[0] 61 62 readOffset=ifile.read(2) 63 offset=struct.unpack('H',readOffset)[0] 64 65 #this is added in to account for extra bytes in the header 66 dataOffsetDif=offset-8 67 ifile.read(dataOffsetDif) 68 69 70 #THIS SECTION IS FOR THE FIRST DATA TYPE 71 48 72 49 73 readLeaderHeader=ifile.read(2) 50 74 leaderHeader =struct.unpack('H',readLeaderHeader)[0] 75 #print hex(leaderHeader) 51 76 52 77 if leaderHeader != firstLeaderHeader: … … 141 166 142 167 # transducer height above the bottom 143 th = 0.4168 th = thab 144 169 145 170 # heights above transducer … … 149 174 hab = [th+elem for elem in hat] 150 175 176 #if the bins output = 3 or 4 need to include NaNs 177 178 if binsOut == 4: 179 sysinfoOfile.write('NaN') 180 sysinfoOfile.write('\n') 181 elif binsOut == 3: 182 sysinfoOfile.write('NaN') 183 sysinfoOfile.write('\n') 184 sysinfoOfile.write('NaN') 185 sysinfoOfile.write('\n') 186 151 187 for value in hab: 152 188 sysinfoOfile.write(str(value)) … … 198 234 199 235 #Reserved space (?) 200 ifile.read(8) 236 ifile.read(4) 237 238 cs=ifile.read(2) 239 240 #should be the packets ID header again 241 test=ifile.read(2) 242 test=struct.unpack('H',test)[0] 243 #print hex(test); 201 244 202 245 … … 211 254 212 255 213 #read the length214 length=ifile.read(2)215 if len( length) == 0:256 #read the checksum offset 257 csOffset=ifile.read(2) 258 if len(csOffset) == 0: 216 259 print('\n End of file') 217 260 break 218 length=struct.unpack('H',length)[0] 219 220 #read 4 bytes before the leader ID 221 ifile.read(4) 261 csOffset=struct.unpack('H',csOffset)[0] 262 #print csOffset 263 264 265 #read the spare and datatype 266 spare=ifile.read(1) 267 268 datatypes=ifile.read(1) 269 270 #read the offset until the next datatype 271 offset=ifile.read(2) 272 offset=struct.unpack('H',offset)[0] 273 274 #this is added in to account for extra bytes in the header 275 dataOffsetDif=offset-8 276 ifile.read(dataOffsetDif) 277 222 278 223 279 readLeaderHeader=ifile.read(2) … … 226 282 # if the leader header isnt the wave ping header move on to the next leader 227 283 if leaderHeader != wavePingHeader: 228 break284 break 229 285 230 286 #read through sample number and time since burst (don't need this) … … 263 319 #read and write the orbital velocity data 264 320 265 bytes= 40321 bytes=binsOut*8 266 322 267 323 while bytes > 0: … … 274 330 orbitOfile.write('\n') 275 331 276 #reserved space (?)277 ifile.read(6)278 332 279 333 # Done with the Wave Ping Type>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> 280 334 335 # if the ADCP was set up to take heading, pitch and roll measurements 336 # for every ensemble needs to include this 337 338 ID=ifile.read(2) 339 ID=struct.unpack('H',ID)[0] 340 #print hex(ID) 341 342 if ID==HPRheader: 343 heading=ifile.read(2) 344 pitch=ifile.read(2) 345 roll=ifile.read(2) 346 spare=ifile.read(2) #not sure what this is 347 cs=ifile.read(2) 348 else: 349 ifile.seek(-2, 1) 350 spare=ifile.read(2) 351 cs=ifile.read(2) 352 353 354 ID=ifile.read(2) 355 if len(ID) == 0: 356 break 357 ID=struct.unpack('H',ID)[0] 358 359 281 360 282 361 … … 332 411 stdRoll=ifile.read(2) 333 412 334 test1=ifile.read(2)335 336 test2=ifile.read(2)413 cs=ifile.read(2) 414 415 spare=ifile.read(2) 337 416 338 417