| 1 |
"""This code takes the raw data from the Nortek AWAC and prepares it |
|---|
| 2 |
for matlab You input a raw binary *.WPR file from the AWAC and it outputs three Currents files with all of the currents |
|---|
| 3 |
data, as well as a waves orbital velocity, range, pressure and sysinfo file for each wave burst""" |
|---|
| 4 |
|
|---|
| 5 |
|
|---|
| 6 |
import sys, struct, math, shutil, os |
|---|
| 7 |
|
|---|
| 8 |
try: |
|---|
| 9 |
infileName = sys.argv[1] |
|---|
| 10 |
|
|---|
| 11 |
except: |
|---|
| 12 |
print 'error' |
|---|
| 13 |
sys.exit(1) |
|---|
| 14 |
|
|---|
| 15 |
ifile = open(infileName, 'rb') |
|---|
| 16 |
testOfile=open('test','w') |
|---|
| 17 |
currentsOfile = open('currents', 'w') |
|---|
| 18 |
currentsHeaderOfile = open('currentsHeader','w') |
|---|
| 19 |
currentsTiltOfile = open('currentsTilt','w') |
|---|
| 20 |
|
|---|
| 21 |
currentsOfile.write('%this is the Nortek AWAC Currents data \n') |
|---|
| 22 |
currentsHeaderOfile.write('%this is the Header data for the Nortek AWAC Currents data \n %it includes Header Info, Date info, Pressure and Temp \n') |
|---|
| 23 |
currentsTiltOfile.write('%this is the Tilt readings (heading pitch and roll) for the Nortek AWAC Currents data \n') |
|---|
| 24 |
|
|---|
| 25 |
|
|---|
| 26 |
|
|---|
| 27 |
|
|---|
| 28 |
HWconfID= 0x05a5 |
|---|
| 29 |
|
|---|
| 30 |
readHeaderID=ifile.read(2) |
|---|
| 31 |
headerID=struct.unpack('H',readHeaderID)[0] |
|---|
| 32 |
if headerID != HWconfID: |
|---|
| 33 |
print 'error with Hardware Config Header' |
|---|
| 34 |
sys.exit(1) |
|---|
| 35 |
|
|---|
| 36 |
|
|---|
| 37 |
readSize=ifile.read(2) |
|---|
| 38 |
size=struct.unpack('H',readSize)[0] |
|---|
| 39 |
|
|---|
| 40 |
length=(size*2)-2 |
|---|
| 41 |
|
|---|
| 42 |
|
|---|
| 43 |
readSerial=ifile.read(14) |
|---|
| 44 |
|
|---|
| 45 |
|
|---|
| 46 |
readBoardC=ifile.read(2) |
|---|
| 47 |
|
|---|
| 48 |
|
|---|
| 49 |
readBoardF=ifile.read(2) |
|---|
| 50 |
|
|---|
| 51 |
|
|---|
| 52 |
readPIC=ifile.read(2) |
|---|
| 53 |
|
|---|
| 54 |
|
|---|
| 55 |
readHardRev=ifile.read(2) |
|---|
| 56 |
|
|---|
| 57 |
|
|---|
| 58 |
readRecSize=ifile.read(2) |
|---|
| 59 |
|
|---|
| 60 |
|
|---|
| 61 |
readStatus=ifile.read(2) |
|---|
| 62 |
|
|---|
| 63 |
|
|---|
| 64 |
ifile.read(12) |
|---|
| 65 |
|
|---|
| 66 |
|
|---|
| 67 |
readFirmVersion=ifile.read(4) |
|---|
| 68 |
firmVersion=struct.unpack('I',readFirmVersion)[0] |
|---|
| 69 |
currentsHeaderOfile.write(str(firmVersion)) |
|---|
| 70 |
currentsHeaderOfile.write(' %Firmware Version \n') |
|---|
| 71 |
|
|---|
| 72 |
|
|---|
| 73 |
readCheckSum=ifile.read(2) |
|---|
| 74 |
|
|---|
| 75 |
|
|---|
| 76 |
|
|---|
| 77 |
|
|---|
| 78 |
|
|---|
| 79 |
|
|---|
| 80 |
HeadConfID= 0x04a5 |
|---|
| 81 |
|
|---|
| 82 |
readHeaderID=ifile.read(2) |
|---|
| 83 |
headerID=struct.unpack('H',readHeaderID)[0] |
|---|
| 84 |
if headerID != HeadConfID: |
|---|
| 85 |
print 'error with Head Config Header' |
|---|
| 86 |
sys.exit(1) |
|---|
| 87 |
|
|---|
| 88 |
|
|---|
| 89 |
readSize=ifile.read(2) |
|---|
| 90 |
size=struct.unpack('H',readSize)[0] |
|---|
| 91 |
|
|---|
| 92 |
length=(size*2)-2 |
|---|
| 93 |
|
|---|
| 94 |
|
|---|
| 95 |
readHeadConfig=ifile.read(2) |
|---|
| 96 |
|
|---|
| 97 |
|
|---|
| 98 |
readHeadFreq=ifile.read(2) |
|---|
| 99 |
headFreq=struct.unpack('H',readHeadFreq)[0] |
|---|
| 100 |
currentsHeaderOfile.write(str(headFreq)) |
|---|
| 101 |
currentsHeaderOfile.write(' %head frequency in khz \n') |
|---|
| 102 |
|
|---|
| 103 |
|
|---|
| 104 |
readHeadType=ifile.read(2) |
|---|
| 105 |
|
|---|
| 106 |
|
|---|
| 107 |
readHeadSerial=ifile.read(12) |
|---|
| 108 |
|
|---|
| 109 |
|
|---|
| 110 |
ifile.read(176) |
|---|
| 111 |
|
|---|
| 112 |
|
|---|
| 113 |
ifile.read(22) |
|---|
| 114 |
|
|---|
| 115 |
|
|---|
| 116 |
readNbeams=ifile.read(2) |
|---|
| 117 |
Nbeams=struct.unpack('H',readNbeams)[0] |
|---|
| 118 |
currentsHeaderOfile.write(str(Nbeams)) |
|---|
| 119 |
currentsHeaderOfile.write(' %number of beams \n') |
|---|
| 120 |
|
|---|
| 121 |
|
|---|
| 122 |
readChecksum=ifile.read(2) |
|---|
| 123 |
|
|---|
| 124 |
|
|---|
| 125 |
|
|---|
| 126 |
|
|---|
| 127 |
|
|---|
| 128 |
|
|---|
| 129 |
UserConfID= 0x00a5 |
|---|
| 130 |
|
|---|
| 131 |
readHeaderID=ifile.read(2) |
|---|
| 132 |
headerID=struct.unpack('H',readHeaderID)[0] |
|---|
| 133 |
if headerID != UserConfID: |
|---|
| 134 |
print 'error with User Config Header' |
|---|
| 135 |
sys.exit(1) |
|---|
| 136 |
|
|---|
| 137 |
|
|---|
| 138 |
readSize=ifile.read(2) |
|---|
| 139 |
size=struct.unpack('H',readSize)[0] |
|---|
| 140 |
|
|---|
| 141 |
length=(size*2)-2 |
|---|
| 142 |
|
|---|
| 143 |
|
|---|
| 144 |
readPulse=ifile.read(2) |
|---|
| 145 |
pulse=struct.unpack('H',readPulse)[0] |
|---|
| 146 |
currentsHeaderOfile.write(str(pulse)) |
|---|
| 147 |
currentsHeaderOfile.write(' %transmit pulse length (counts) \n') |
|---|
| 148 |
|
|---|
| 149 |
|
|---|
| 150 |
readBlanking=ifile.read(2) |
|---|
| 151 |
blanking=struct.unpack('H',readBlanking)[0] |
|---|
| 152 |
|
|---|
| 153 |
|
|---|
| 154 |
readReceive=ifile.read(2) |
|---|
| 155 |
receive=struct.unpack('H',readReceive)[0] |
|---|
| 156 |
currentsHeaderOfile.write(str(receive)) |
|---|
| 157 |
currentsHeaderOfile.write(' %recieve length (counts) \n') |
|---|
| 158 |
|
|---|
| 159 |
|
|---|
| 160 |
readTimePing=ifile.read(2) |
|---|
| 161 |
timePing=struct.unpack('H',readTimePing)[0] |
|---|
| 162 |
currentsHeaderOfile.write(str(timePing)) |
|---|
| 163 |
currentsHeaderOfile.write(' %time between pings (counts) \n') |
|---|
| 164 |
|
|---|
| 165 |
|
|---|
| 166 |
readTimeBurst=ifile.read(2) |
|---|
| 167 |
timeBurst=struct.unpack('H',readTimeBurst)[0] |
|---|
| 168 |
currentsHeaderOfile.write(str(timeBurst)) |
|---|
| 169 |
currentsHeaderOfile.write(' %time between burst sequence (counts) \n') |
|---|
| 170 |
|
|---|
| 171 |
|
|---|
| 172 |
readBeamSeq=ifile.read(2) |
|---|
| 173 |
beamSeq=struct.unpack('H',readBeamSeq)[0] |
|---|
| 174 |
currentsHeaderOfile.write(str(beamSeq)) |
|---|
| 175 |
currentsHeaderOfile.write(' %number of beam sequences per burst \n') |
|---|
| 176 |
|
|---|
| 177 |
|
|---|
| 178 |
readAvgInt=ifile.read(2) |
|---|
| 179 |
avgInt=struct.unpack('H',readAvgInt)[0] |
|---|
| 180 |
currentsHeaderOfile.write(str(avgInt)) |
|---|
| 181 |
currentsHeaderOfile.write(' %average interval (seconds) \n') |
|---|
| 182 |
|
|---|
| 183 |
|
|---|
| 184 |
|
|---|
| 185 |
readNbeams=ifile.read(2) |
|---|
| 186 |
|
|---|
| 187 |
|
|---|
| 188 |
readTimeCont=ifile.read(2) |
|---|
| 189 |
|
|---|
| 190 |
|
|---|
| 191 |
readPowerCont=ifile.read(2) |
|---|
| 192 |
|
|---|
| 193 |
|
|---|
| 194 |
ifile.read(6) |
|---|
| 195 |
|
|---|
| 196 |
|
|---|
| 197 |
readCompRate=ifile.read(2) |
|---|
| 198 |
|
|---|
| 199 |
|
|---|
| 200 |
readCoord=ifile.read(2) |
|---|
| 201 |
coord=struct.unpack('H',readCoord)[0] |
|---|
| 202 |
currentsHeaderOfile.write(str(coord)) |
|---|
| 203 |
currentsHeaderOfile.write(' %coord system, 0=ENU, 1=XYZ, 2=Beam \n') |
|---|
| 204 |
|
|---|
| 205 |
|
|---|
| 206 |
readNcells=ifile.read(2) |
|---|
| 207 |
Ncells=struct.unpack('H',readNcells)[0] |
|---|
| 208 |
currentsHeaderOfile.write(str(Ncells)) |
|---|
| 209 |
currentsHeaderOfile.write(' %number of bins or cells \n') |
|---|
| 210 |
|
|---|
| 211 |
|
|---|
| 212 |
|
|---|
| 213 |
readCellSize=ifile.read(2) |
|---|
| 214 |
cCellSize=struct.unpack('H',readCellSize)[0] |
|---|
| 215 |
|
|---|
| 216 |
|
|---|
| 217 |
cell=cCellSize*100.0*(750/((headFreq*1000.0*4)/255.0)) |
|---|
| 218 |
cellint = math.floor(cell) |
|---|
| 219 |
rawCellSize=0.01*cellint/256.0 |
|---|
| 220 |
cellSize=math.cos(25*(math.pi/180))*rawCellSize |
|---|
| 221 |
currentsHeaderOfile.write(str('%3.2f' %cellSize)) |
|---|
| 222 |
currentsHeaderOfile.write(' %bin cell size (m) \n') |
|---|
| 223 |
|
|---|
| 224 |
|
|---|
| 225 |
pLength=rawCellSize*100.0 |
|---|
| 226 |
cellBlanking=blanking*100.0*(750.0/32768.0)-pLength |
|---|
| 227 |
cellBlanking=0.01*math.floor(cellBlanking) |
|---|
| 228 |
cellBlanking=math.cos(25*(math.pi/180))*cellBlanking |
|---|
| 229 |
currentsHeaderOfile.write(str('%3.2f' %cellBlanking)) |
|---|
| 230 |
currentsHeaderOfile.write(' %blanking distance (m) \n') |
|---|
| 231 |
|
|---|
| 232 |
|
|---|
| 233 |
currentsHeaderOfile.write(' % cell heights from bottom (meters) \n') |
|---|
| 234 |
depths=[] |
|---|
| 235 |
for i in range(1,Ncells+1): |
|---|
| 236 |
depths.append(cellBlanking+cellSize*i) |
|---|
| 237 |
currentsHeaderOfile.write(str('%3.2f' %depths[i-1])) |
|---|
| 238 |
currentsHeaderOfile.write('\n') |
|---|
| 239 |
|
|---|
| 240 |
|
|---|
| 241 |
readMeasInt=ifile.read(2) |
|---|
| 242 |
measInt=struct.unpack('H',readMeasInt)[0] |
|---|
| 243 |
currentsHeaderOfile.write(str(measInt)) |
|---|
| 244 |
currentsHeaderOfile.write(' %measurement interval (seconds) \n') |
|---|
| 245 |
|
|---|
| 246 |
|
|---|
| 247 |
readDepName=ifile.read(6) |
|---|
| 248 |
|
|---|
| 249 |
|
|---|
| 250 |
readRecWrap=ifile.read(2) |
|---|
| 251 |
|
|---|
| 252 |
|
|---|
| 253 |
readStarTime=ifile.read(6) |
|---|
| 254 |
|
|---|
| 255 |
|
|---|
| 256 |
readDiagTime=ifile.read(4) |
|---|
| 257 |
diagTime=struct.unpack('I',readDiagTime)[0] |
|---|
| 258 |
|
|---|
| 259 |
|
|---|
| 260 |
readMode=ifile.read(2) |
|---|
| 261 |
|
|---|
| 262 |
|
|---|
| 263 |
readAdjSound=ifile.read(2) |
|---|
| 264 |
|
|---|
| 265 |
|
|---|
| 266 |
readNsamples=ifile.read(2) |
|---|
| 267 |
Nsamples=struct.unpack('H',readNsamples)[0] |
|---|
| 268 |
|
|---|
| 269 |
|
|---|
| 270 |
readNbeamCell=ifile.read(2) |
|---|
| 271 |
|
|---|
| 272 |
|
|---|
| 273 |
readNpingsDiag=ifile.read(2) |
|---|
| 274 |
|
|---|
| 275 |
|
|---|
| 276 |
readModeTest=ifile.read(2) |
|---|
| 277 |
|
|---|
| 278 |
|
|---|
| 279 |
readAnalAddr=ifile.read(2) |
|---|
| 280 |
|
|---|
| 281 |
|
|---|
| 282 |
readSoftVers=ifile.read(2) |
|---|
| 283 |
|
|---|
| 284 |
|
|---|
| 285 |
ifile.read(2) |
|---|
| 286 |
|
|---|
| 287 |
|
|---|
| 288 |
readVelAdjTable=ifile.read(180) |
|---|
| 289 |
|
|---|
| 290 |
|
|---|
| 291 |
readFileComments=ifile.read(180) |
|---|
| 292 |
|
|---|
| 293 |
|
|---|
| 294 |
readMode=ifile.read(2) |
|---|
| 295 |
byteList=struct.unpack('2B', readMode) |
|---|
| 296 |
|
|---|
| 297 |
def int2msbits(n, count=8): |
|---|
| 298 |
"""returns the most-significant binary of integer n, using count number of digits""" |
|---|
| 299 |
return "".join([str((n >> y) & 1) for y in range(0, count)]) |
|---|
| 300 |
|
|---|
| 301 |
bytemap = '' |
|---|
| 302 |
bitmap = '' |
|---|
| 303 |
for ind in range(len(byteList)): |
|---|
| 304 |
byte = struct.pack('B', byteList[ind]) |
|---|
| 305 |
bytemap += byte |
|---|
| 306 |
bits = int2msbits(byteList[ind]) |
|---|
| 307 |
bitmap += bits |
|---|
| 308 |
|
|---|
| 309 |
|
|---|
| 310 |
readPercWave=ifile.read(2) |
|---|
| 311 |
PercWave=struct.unpack('H',readPercWave)[0] |
|---|
| 312 |
PercWave=(PercWave/32767)*100 |
|---|
| 313 |
|
|---|
| 314 |
|
|---|
| 315 |
readWavePulse=ifile.read(2) |
|---|
| 316 |
wavePulse=struct.unpack('H',readWavePulse)[0] |
|---|
| 317 |
|
|---|
| 318 |
|
|---|
| 319 |
readFixedBlanking=ifile.read(2) |
|---|
| 320 |
fixedBlanking=struct.unpack('H',readFixedBlanking)[0] |
|---|
| 321 |
|
|---|
| 322 |
|
|---|
| 323 |
readWaveCellSize=ifile.read(2) |
|---|
| 324 |
waveCellSize=struct.unpack('H',readWaveCellSize)[0] |
|---|
| 325 |
|
|---|
| 326 |
|
|---|
| 327 |
readWaveSamples=ifile.read(2) |
|---|
| 328 |
waveSamples=struct.unpack('H',readWaveSamples)[0] |
|---|
| 329 |
|
|---|
| 330 |
|
|---|
| 331 |
ifile.read(8) |
|---|
| 332 |
|
|---|
| 333 |
|
|---|
| 334 |
readAnalogScale=ifile.read(2) |
|---|
| 335 |
|
|---|
| 336 |
|
|---|
| 337 |
readCorrThresh=ifile.read(2) |
|---|
| 338 |
|
|---|
| 339 |
|
|---|
| 340 |
ifile.read(2) |
|---|
| 341 |
|
|---|
| 342 |
|
|---|
| 343 |
readPulseLag=ifile.read(2) |
|---|
| 344 |
|
|---|
| 345 |
|
|---|
| 346 |
ifile.read(30) |
|---|
| 347 |
|
|---|
| 348 |
|
|---|
| 349 |
readStageMatch=ifile.read(16) |
|---|
| 350 |
|
|---|
| 351 |
|
|---|
| 352 |
readChecksum=ifile.read(2) |
|---|
| 353 |
|
|---|
| 354 |
|
|---|
| 355 |
|
|---|
| 356 |
|
|---|
| 357 |
|
|---|
| 358 |
|
|---|
| 359 |
currentsTime=[] |
|---|
| 360 |
currentsPress=[] |
|---|
| 361 |
currentsTemp=[] |
|---|
| 362 |
currentsHeading=[] |
|---|
| 363 |
currentsPitch=[] |
|---|
| 364 |
currentsRoll=[] |
|---|
| 365 |
allVel1=[] |
|---|
| 366 |
allVel2=[] |
|---|
| 367 |
allVel3=[] |
|---|
| 368 |
allAmp1=[] |
|---|
| 369 |
allAmp2=[] |
|---|
| 370 |
allAmp3=[] |
|---|
| 371 |
|
|---|
| 372 |
VelID= 0x20a5 |
|---|
| 373 |
|
|---|
| 374 |
readHeaderID=ifile.read(2) |
|---|
| 375 |
headerID=struct.unpack('H',readHeaderID)[0] |
|---|
| 376 |
if headerID != VelID: |
|---|
| 377 |
print 'error with Velocity Profile Header' |
|---|
| 378 |
sys.exit(1) |
|---|
| 379 |
|
|---|
| 380 |
while headerID == VelID: |
|---|
| 381 |
|
|---|
| 382 |
|
|---|
| 383 |
|
|---|
| 384 |
readSize=ifile.read(2) |
|---|
| 385 |
if len(readSize) == 0: |
|---|
| 386 |
break |
|---|
| 387 |
size=struct.unpack('H',readSize)[0] |
|---|
| 388 |
|
|---|
| 389 |
length=(size*2)-2 |
|---|
| 390 |
|
|---|
| 391 |
|
|---|
| 392 |
|
|---|
| 393 |
readMinute=ifile.read(1) |
|---|
| 394 |
minute=struct.unpack('B',readMinute)[0] |
|---|
| 395 |
minute=str(hex(minute))[2:4] |
|---|
| 396 |
|
|---|
| 397 |
readSecond=ifile.read(1) |
|---|
| 398 |
second=struct.unpack('B',readSecond)[0] |
|---|
| 399 |
second=str(hex(second))[2:4] |
|---|
| 400 |
|
|---|
| 401 |
readDay=ifile.read(1) |
|---|
| 402 |
day=struct.unpack('B',readDay)[0] |
|---|
| 403 |
day=str(hex(day))[2:4] |
|---|
| 404 |
|
|---|
| 405 |
readHour=ifile.read(1) |
|---|
| 406 |
hour=struct.unpack('B',readHour)[0] |
|---|
| 407 |
hour=str(hex(hour))[2:4] |
|---|
| 408 |
|
|---|
| 409 |
readYear=ifile.read(1) |
|---|
| 410 |
year=struct.unpack('B',readYear)[0] |
|---|
| 411 |
year=str(hex(year))[2:4] |
|---|
| 412 |
|
|---|
| 413 |
readMonth=ifile.read(1) |
|---|
| 414 |
month=struct.unpack('B',readMonth)[0] |
|---|
| 415 |
month=str(hex(month))[2:4] |
|---|
| 416 |
|
|---|
| 417 |
century = str(20) |
|---|
| 418 |
|
|---|
| 419 |
startTime=century+(year.zfill(2))+(month.zfill(2))+(day.zfill(2))+(hour.zfill(2))+(minute.zfill(2))+(second.zfill(2)) |
|---|
| 420 |
|
|---|
| 421 |
|
|---|
| 422 |
FileStamp=(year.zfill(2))+(month.zfill(2))+(day.zfill(2))+(hour.zfill(2))+(minute.zfill(2)) |
|---|
| 423 |
currentsTime.append(FileStamp) |
|---|
| 424 |
|
|---|
| 425 |
|
|---|
| 426 |
|
|---|
| 427 |
readError=ifile.read(2) |
|---|
| 428 |
error=struct.unpack('H',readError)[0] |
|---|
| 429 |
|
|---|
| 430 |
|
|---|
| 431 |
readAnalog1=ifile.read(2) |
|---|
| 432 |
analog1=struct.unpack('H',readAnalog1)[0] |
|---|
| 433 |
|
|---|
| 434 |
|
|---|
| 435 |
readBattery=ifile.read(2) |
|---|
| 436 |
battery=struct.unpack('H',readBattery)[0] |
|---|
| 437 |
|
|---|
| 438 |
|
|---|
| 439 |
readSound=ifile.read(2) |
|---|
| 440 |
sound=struct.unpack('H',readSound)[0] |
|---|
| 441 |
|
|---|
| 442 |
|
|---|
| 443 |
readHeading=ifile.read(2) |
|---|
| 444 |
heading=struct.unpack('H',readHeading)[0] |
|---|
| 445 |
currentsHeading.append(heading) |
|---|
| 446 |
|
|---|
| 447 |
|
|---|
| 448 |
readPitch=ifile.read(2) |
|---|
| 449 |
pitch=struct.unpack('h',readPitch)[0] |
|---|
| 450 |
currentsPitch.append(pitch) |
|---|
| 451 |
|
|---|
| 452 |
|
|---|
| 453 |
readRoll=ifile.read(2) |
|---|
| 454 |
roll=struct.unpack('h',readRoll)[0] |
|---|
| 455 |
currentsRoll.append(roll) |
|---|
| 456 |
|
|---|
| 457 |
|
|---|
| 458 |
readPressMSB=ifile.read(1) |
|---|
| 459 |
pressureMSB=struct.unpack('B',readPressMSB)[0] |
|---|
| 460 |
|
|---|
| 461 |
|
|---|
| 462 |
readStatus=ifile.read(1) |
|---|
| 463 |
|
|---|
| 464 |
|
|---|
| 465 |
readPressLSW=ifile.read(2) |
|---|
| 466 |
pressureLSW=struct.unpack('H',readPressLSW)[0] |
|---|
| 467 |
|
|---|
| 468 |
|
|---|
| 469 |
pressure= 65536*pressureMSB + pressureLSW |
|---|
| 470 |
currentsPress.append(pressure) |
|---|
| 471 |
|
|---|
| 472 |
|
|---|
| 473 |
readTemp=ifile.read(2) |
|---|
| 474 |
temp=struct.unpack('h',readTemp)[0] |
|---|
| 475 |
currentsTemp.append(temp) |
|---|
| 476 |
|
|---|
| 477 |
|
|---|
| 478 |
readSpare=ifile.read(88) |
|---|
| 479 |
|
|---|
| 480 |
|
|---|
| 481 |
|
|---|
| 482 |
numCells=3*Ncells |
|---|
| 483 |
vel1=[] |
|---|
| 484 |
vel2=[] |
|---|
| 485 |
vel3=[] |
|---|
| 486 |
while numCells > 0: |
|---|
| 487 |
readVel=ifile.read(2) |
|---|
| 488 |
vel=struct.unpack('h',readVel)[0] |
|---|
| 489 |
if numCells > 2*Ncells: |
|---|
| 490 |
vel1.append(vel) |
|---|
| 491 |
elif numCells > Ncells: |
|---|
| 492 |
vel2.append(vel) |
|---|
| 493 |
else: |
|---|
| 494 |
vel3.append(vel) |
|---|
| 495 |
numCells -=1 |
|---|
| 496 |
allVel1.append(vel1) |
|---|
| 497 |
allVel2.append(vel2) |
|---|
| 498 |
allVel3.append(vel3) |
|---|
| 499 |
|
|---|
| 500 |
|
|---|
| 501 |
|
|---|
| 502 |
numCells=3*Ncells |
|---|
| 503 |
amp1=[] |
|---|
| 504 |
amp2=[] |
|---|
| 505 |
amp3=[] |
|---|
| 506 |
while numCells > 0: |
|---|
| 507 |
readAmp=ifile.read(1) |
|---|
| 508 |
amp=struct.unpack('B',readAmp)[0] |
|---|
| 509 |
if numCells > 2*Ncells: |
|---|
| 510 |
amp1.append(amp) |
|---|
| 511 |
elif numCells > Ncells: |
|---|
| 512 |
amp2.append(amp) |
|---|
| 513 |
else: |
|---|
| 514 |
amp3.append(amp) |
|---|
| 515 |
numCells -=1 |
|---|
| 516 |
allAmp1.append(amp1) |
|---|
| 517 |
allAmp2.append(amp2) |
|---|
| 518 |
allAmp3.append(amp3) |
|---|
| 519 |
|
|---|
| 520 |
|
|---|
| 521 |
if Ncells/2 != 0: |
|---|
| 522 |
ifile.read(1) |
|---|
| 523 |
|
|---|
| 524 |
else: |
|---|
| 525 |
ifile.read(0) |
|---|
| 526 |
|
|---|
| 527 |
|
|---|
| 528 |
ifile.seek(-(length+1),1) |
|---|
| 529 |
dataStruct=ifile.read(length) |
|---|
| 530 |
|
|---|
| 531 |
total =0 |
|---|
| 532 |
for byte in dataStruct: |
|---|
| 533 |
value = struct.unpack('B', byte)[0] |
|---|
| 534 |
total += value |
|---|
| 535 |
|
|---|
| 536 |
cs=total |
|---|
| 537 |
|
|---|
| 538 |
|
|---|
| 539 |
readChecksum=ifile.read(2) |
|---|
| 540 |
checksum=struct.unpack('H',readChecksum)[0] |
|---|
| 541 |
|
|---|
| 542 |
|
|---|
| 543 |
|
|---|
| 544 |
|
|---|
| 545 |
|
|---|
| 546 |
|
|---|
| 547 |
WdataID=0x31a5 |
|---|
| 548 |
|
|---|
| 549 |
|
|---|
| 550 |
readHeaderID=ifile.read(2) |
|---|
| 551 |
if len(readHeaderID) == 0: |
|---|
| 552 |
break |
|---|
| 553 |
headerID=struct.unpack('H',readHeaderID)[0] |
|---|
| 554 |
|
|---|
| 555 |
|
|---|
| 556 |
|
|---|
| 557 |
while headerID == WdataID: |
|---|
| 558 |
|
|---|
| 559 |
if headerID != WdataID: |
|---|
| 560 |
break |
|---|
| 561 |
|
|---|
| 562 |
pressureOfile = open('pressure', 'w') |
|---|
| 563 |
rangeOfile = open('range', 'w') |
|---|
| 564 |
orbitOfile = open('orbit', 'w') |
|---|
| 565 |
sysinfoOfile = open('sysinfo', 'w') |
|---|
| 566 |
|
|---|
| 567 |
|
|---|
| 568 |
|
|---|
| 569 |
sysinfoOfile.write(str(coord)) |
|---|
| 570 |
sysinfoOfile.write(' %coord system, 0=ENU, 1=XYZ, 2=Beam \n') |
|---|
| 571 |
|
|---|
| 572 |
sysinfoOfile.write(str(bitmap)) |
|---|
| 573 |
sysinfoOfile.write(' % bit1:data rate 0=1Hz,1=2Hz bit2:wave cell position 0=fixed,1=dynamic bit3=type of pos 0=% of mean press, 1=% of min press \n') |
|---|
| 574 |
|
|---|
| 575 |
sysinfoOfile.write(str(PercWave)) |
|---|
| 576 |
sysinfoOfile.write(' %percentage for wave cell position \n') |
|---|
| 577 |
|
|---|
| 578 |
|
|---|
| 579 |
|
|---|
| 580 |
readSize=ifile.read(2) |
|---|
| 581 |
size=struct.unpack('H',readSize)[0] |
|---|
| 582 |
|
|---|
| 583 |
length=(size*2)-2 |
|---|
| 584 |
|
|---|
| 585 |
|
|---|
| 586 |
|
|---|
| 587 |
readMinute=ifile.read(1) |
|---|
| 588 |
minute=struct.unpack('B',readMinute)[0] |
|---|
| 589 |
minute=str(hex(minute))[2:4] |
|---|
| 590 |
|
|---|
| 591 |
readSecond=ifile.read(1) |
|---|
| 592 |
second=struct.unpack('B',readSecond)[0] |
|---|
| 593 |
second=str(hex(second))[2:4] |
|---|
| 594 |
|
|---|
| 595 |
readDay=ifile.read(1) |
|---|
| 596 |
day=struct.unpack('B',readDay)[0] |
|---|
| 597 |
day=str(hex(day))[2:4] |
|---|
| 598 |
|
|---|
| 599 |
readHour=ifile.read(1) |
|---|
| 600 |
hour=struct.unpack('B',readHour)[0] |
|---|
| 601 |
hour=str(hex(hour))[2:4] |
|---|
| 602 |
|
|---|
| 603 |
readYear=ifile.read(1) |
|---|
| 604 |
year=struct.unpack('B',readYear)[0] |
|---|
| 605 |
year=str(hex(year))[2:4] |
|---|
| 606 |
|
|---|
| 607 |
readMonth=ifile.read(1) |
|---|
| 608 |
month=struct.unpack('B',readMonth)[0] |
|---|
| 609 |
month=str(hex(month))[2:4] |
|---|
| 610 |
|
|---|
| 611 |
century = str(20) |
|---|
| 612 |
|
|---|
| 613 |
startTime=century+(year.zfill(2))+(month.zfill(2))+(day.zfill(2))+(hour.zfill(2))+(minute.zfill(2))+(second.zfill(2)) |
|---|
| 614 |
|
|---|
| 615 |
|
|---|
| 616 |
FileStamp=(year.zfill(2))+(month.zfill(2))+(day.zfill(2))+(hour.zfill(2))+(minute.zfill(2)) |
|---|
| 617 |
|
|---|
| 618 |
sysinfoOfile.write(startTime) |
|---|
| 619 |
sysinfoOfile.write(' % this is the start time \n') |
|---|
| 620 |
|
|---|
| 621 |
|
|---|
| 622 |
|
|---|
| 623 |
|
|---|
| 624 |
readWaveRecords=ifile.read(2) |
|---|
| 625 |
waveRecords=struct.unpack('H',readWaveRecords)[0] |
|---|
| 626 |
|
|---|
| 627 |
|
|---|
| 628 |
readBlanking=ifile.read(2) |
|---|
| 629 |
blanking=struct.unpack('H',readBlanking)[0] |
|---|
| 630 |
|
|---|
| 631 |
|
|---|
| 632 |
readBattery=ifile.read(2) |
|---|
| 633 |
|
|---|
| 634 |
|
|---|
| 635 |
readSound=ifile.read(2) |
|---|
| 636 |
sound=struct.unpack('H',readSound)[0] |
|---|
| 637 |
sysinfoOfile.write(str(sound)) |
|---|
| 638 |
sysinfoOfile.write(' %speed of sound (0.1m/s) \n') |
|---|
| 639 |
|
|---|
| 640 |
|
|---|
| 641 |
readHeading=ifile.read(2) |
|---|
| 642 |
heading=struct.unpack('H',readHeading)[0] |
|---|
| 643 |
sysinfoOfile.write(str(heading)) |
|---|
| 644 |
sysinfoOfile.write(' %heading \n') |
|---|
| 645 |
|
|---|
| 646 |
|
|---|
| 647 |
readPitch=ifile.read(2) |
|---|
| 648 |
pitch=struct.unpack('h',readPitch)[0] |
|---|
| 649 |
sysinfoOfile.write(str(pitch)) |
|---|
| 650 |
sysinfoOfile.write(' %pitch \n') |
|---|
| 651 |
|
|---|
| 652 |
|
|---|
| 653 |
readRoll=ifile.read(2) |
|---|
| 654 |
roll=struct.unpack('h',readRoll)[0] |
|---|
| 655 |
sysinfoOfile.write(str(roll)) |
|---|
| 656 |
sysinfoOfile.write(' %roll \n') |
|---|
| 657 |
|
|---|
| 658 |
|
|---|
| 659 |
readMinPress=ifile.read(2) |
|---|
| 660 |
minPress=struct.unpack('H',readMinPress)[0] |
|---|
| 661 |
sysinfoOfile.write(str(minPress)) |
|---|
| 662 |
sysinfoOfile.write(' %min press (mm) \n') |
|---|
| 663 |
|
|---|
| 664 |
|
|---|
| 665 |
readMaxPress=ifile.read(2) |
|---|
| 666 |
|
|---|
| 667 |
|
|---|
| 668 |
readTemp=ifile.read(2) |
|---|
| 669 |
|
|---|
| 670 |
|
|---|
| 671 |
readCellSize=ifile.read(2) |
|---|
| 672 |
hCellSize=struct.unpack('H',readCellSize)[0] |
|---|
| 673 |
|
|---|
| 674 |
|
|---|
| 675 |
|
|---|
| 676 |
cell=hCellSize*100.0*(750/((headFreq*1000.0*4)/255.0)) |
|---|
| 677 |
cellint = math.floor(cell) |
|---|
| 678 |
cellSize=0.01*cellint/256.0 |
|---|
| 679 |
sysinfoOfile.write(str('%3.2f' %cellSize)) |
|---|
| 680 |
sysinfoOfile.write(' %wave cell size (m) \n') |
|---|
| 681 |
|
|---|
| 682 |
|
|---|
| 683 |
pLength=cellSize*100.0 |
|---|
| 684 |
cellDist=blanking*100.0*(750.0/32768.0)-pLength |
|---|
| 685 |
cellDist=0.01*math.floor(cellDist) |
|---|
| 686 |
beamCellPos=cellDist+cellSize |
|---|
| 687 |
cellPos=math.cos(25*(math.pi/180))*beamCellPos |
|---|
| 688 |
sysinfoOfile.write(str('%3.2f' %cellPos)) |
|---|
| 689 |
sysinfoOfile.write(' %wave cell position (m) \n') |
|---|
| 690 |
testOfile.write(str('%3.2f' %cellPos)) |
|---|
| 691 |
testOfile.write(' \n') |
|---|
| 692 |
|
|---|
| 693 |
|
|---|
| 694 |
readAmpBeam1=ifile.read(1) |
|---|
| 695 |
|
|---|
| 696 |
|
|---|
| 697 |
readAmpBeam2=ifile.read(1) |
|---|
| 698 |
|
|---|
| 699 |
|
|---|
| 700 |
readAmpBeam3=ifile.read(1) |
|---|
| 701 |
|
|---|
| 702 |
|
|---|
| 703 |
readAmpBeam4=ifile.read(1) |
|---|
| 704 |
|
|---|
| 705 |
|
|---|
| 706 |
readMagBeam1=ifile.read(2) |
|---|
| 707 |
|
|---|
| 708 |
|
|---|
| 709 |
readMagBeam2=ifile.read(2) |
|---|
| 710 |
|
|---|
| 711 |
|
|---|
| 712 |
readMagBeam3=ifile.read(2) |
|---|
| 713 |
|
|---|
| 714 |
|
|---|
| 715 |
readMagBeam4=ifile.read(2) |
|---|
| 716 |
|
|---|
| 717 |
|
|---|
| 718 |
ifile.read(14) |
|---|
| 719 |
|
|---|
| 720 |
|
|---|
| 721 |
readChecksum=ifile.read(2) |
|---|
| 722 |
|
|---|
| 723 |
|
|---|
| 724 |
|
|---|
| 725 |
|
|---|
| 726 |
|
|---|
| 727 |
|
|---|
| 728 |
|
|---|
| 729 |
|
|---|
| 730 |
|
|---|
| 731 |
waveID= 0x30a5 |
|---|
| 732 |
extraID= 0x42a5 |
|---|
| 733 |
|
|---|
| 734 |
|
|---|
| 735 |
headerID=waveID |
|---|
| 736 |
|
|---|
| 737 |
while (headerID == waveID) or (headerID == extraID): |
|---|
| 738 |
|
|---|
| 739 |
|
|---|
| 740 |
readHeaderID=ifile.read(2) |
|---|
| 741 |
if len(readHeaderID) == 0: |
|---|
| 742 |
break |
|---|
| 743 |
headerID=struct.unpack('H',readHeaderID)[0] |
|---|
| 744 |
|
|---|
| 745 |
if (headerID != waveID) and (headerID != extraID): |
|---|
| 746 |
break |
|---|
| 747 |
|
|---|
| 748 |
|
|---|
| 749 |
|
|---|
| 750 |
if headerID == extraID: |
|---|
| 751 |
readSize=ifile.read(2) |
|---|
| 752 |
size=struct.unpack('H',readSize)[0] |
|---|
| 753 |
ifile.read(size*2-2) |
|---|
| 754 |
|
|---|
| 755 |
|
|---|
| 756 |
|
|---|
| 757 |
readSize=ifile.read(2) |
|---|
| 758 |
size=struct.unpack('H',readSize)[0] |
|---|
| 759 |
|
|---|
| 760 |
length=(size*2)-2 |
|---|
| 761 |
|
|---|
| 762 |
|
|---|
| 763 |
readPressure=ifile.read(2) |
|---|
| 764 |
pressure=struct.unpack('H',readPressure)[0] |
|---|
| 765 |
pressureOfile.write(str(pressure)) |
|---|
| 766 |
pressureOfile.write('\n') |
|---|
| 767 |
|
|---|
| 768 |
|
|---|
| 769 |
readAST1=ifile.read(2) |
|---|
| 770 |
AST1=struct.unpack('H',readAST1)[0] |
|---|
| 771 |
rangeOfile.write(str('%06d' % AST1)) |
|---|
| 772 |
rangeOfile.write(' \n') |
|---|
| 773 |
|
|---|
| 774 |
|
|---|
| 775 |
aInput=ifile.read(2) |
|---|
| 776 |
|
|---|
| 777 |
|
|---|
| 778 |
readVel1=ifile.read(2) |
|---|
| 779 |
vel1=struct.unpack('h',readVel1)[0] |
|---|
| 780 |
orbitOfile.write(str('%06d' % vel1)) |
|---|
| 781 |
orbitOfile.write(' ') |
|---|
| 782 |
|
|---|
| 783 |
|
|---|
| 784 |
readVel2=ifile.read(2) |
|---|
| 785 |
vel2=struct.unpack('h',readVel2)[0] |
|---|
| 786 |
orbitOfile.write(str('%06d' % vel2)) |
|---|
| 787 |
orbitOfile.write(' ') |
|---|
| 788 |
|
|---|
| 789 |
|
|---|
| 790 |
readVel3=ifile.read(2) |
|---|
| 791 |
vel3=struct.unpack('h',readVel3)[0] |
|---|
| 792 |
orbitOfile.write(str('%06d' % vel3)) |
|---|
| 793 |
orbitOfile.write('\n') |
|---|
| 794 |
|
|---|
| 795 |
|
|---|
| 796 |
readAST2=ifile.read(2) |
|---|
| 797 |
AST2=struct.unpack('H',readAST2)[0] |
|---|
| 798 |
rangeOfile.write(str('%06d' % AST2)) |
|---|
| 799 |
rangeOfile.write(' \n') |
|---|
| 800 |
|
|---|
| 801 |
|
|---|
| 802 |
readAmp1=ifile.read(1) |
|---|
| 803 |
amp1=struct.unpack('B',readAmp1)[0] |
|---|
| 804 |
|
|---|
| 805 |
|
|---|
| 806 |
readAmp2=ifile.read(1) |
|---|
| 807 |
amp2=struct.unpack('B',readAmp2)[0] |
|---|
| 808 |
|
|---|
| 809 |
|
|---|
| 810 |
readAmp3=ifile.read(1) |
|---|
| 811 |
amp3=struct.unpack('B',readAmp3)[0] |
|---|
| 812 |
|
|---|
| 813 |
|
|---|
| 814 |
readASTQuality=ifile.read(1) |
|---|
| 815 |
ASTQuality=struct.unpack('B',readASTQuality)[0] |
|---|
| 816 |
|
|---|
| 817 |
|
|---|
| 818 |
readChecksum=ifile.read(2) |
|---|
| 819 |
|
|---|
| 820 |
|
|---|
| 821 |
|
|---|
| 822 |
pressureOfile.close() |
|---|
| 823 |
rangeOfile.close() |
|---|
| 824 |
orbitOfile.close() |
|---|
| 825 |
sysinfoOfile.close() |
|---|
| 826 |
|
|---|
| 827 |
shutil.copy('pressure','pressure_'+FileStamp+'.txt') |
|---|
| 828 |
shutil.copy('orbit','orbit_'+FileStamp+'.txt') |
|---|
| 829 |
shutil.copy('range','range_'+FileStamp+'.txt') |
|---|
| 830 |
shutil.copy('sysinfo','sysinfo_'+FileStamp+'.txt') |
|---|
| 831 |
|
|---|
| 832 |
os.remove('pressure') |
|---|
| 833 |
os.remove('orbit') |
|---|
| 834 |
os.remove('range') |
|---|
| 835 |
os.remove('sysinfo') |
|---|
| 836 |
|
|---|
| 837 |
|
|---|
| 838 |
|
|---|
| 839 |
|
|---|
| 840 |
currentsHeaderOfile.write('%List of time records for this data set, YYMMDDHHMM \n') |
|---|
| 841 |
|
|---|
| 842 |
for date in currentsTime: |
|---|
| 843 |
currentsHeaderOfile.write(str(date)) |
|---|
| 844 |
currentsHeaderOfile.write('\n') |
|---|
| 845 |
|
|---|
| 846 |
currentsHeaderOfile.write('%List of pressure readings for each current burst \n') |
|---|
| 847 |
|
|---|
| 848 |
for press in currentsPress: |
|---|
| 849 |
currentsHeaderOfile.write(str(press/1000.000)) |
|---|
| 850 |
currentsHeaderOfile.write('\n') |
|---|
| 851 |
|
|---|
| 852 |
currentsHeaderOfile.write('%List of temp readings in degrees C for each current burst \n') |
|---|
| 853 |
|
|---|
| 854 |
for temp in currentsTemp: |
|---|
| 855 |
currentsHeaderOfile.write(str(temp/100.00)) |
|---|
| 856 |
currentsHeaderOfile.write('\n') |
|---|
| 857 |
|
|---|
| 858 |
currentsTiltOfile.write('%List heading,pitch and roll values in degrees for each current burst \n') |
|---|
| 859 |
|
|---|
| 860 |
for value in range(len(currentsHeading)): |
|---|
| 861 |
currentsTiltOfile.write(str('%- 8.1f' %(currentsHeading[value]/10.0))) |
|---|
| 862 |
currentsTiltOfile.write(str('%- 8.1f' %(currentsPitch[value]/10.0))) |
|---|
| 863 |
currentsTiltOfile.write(str('%- 8.1f' %(currentsRoll[value]/10.0))) |
|---|
| 864 |
currentsTiltOfile.write('\n') |
|---|
| 865 |
|
|---|
| 866 |
|
|---|
| 867 |
|
|---|
| 868 |
currentsOfile.write('% velocities and amplitudes with lines of Ncells for each burst \n') |
|---|
| 869 |
currentsOfile.write('% velocities from lowest cell up, in m/s ---- amplitudes in counts \n') |
|---|
| 870 |
currentsOfile.write('% vel1(beam1, x or u) vel2(beam2, y or v) vel3(beam3, z or w) ---- amp1(beam1) amp2(beam2) amp3(beam3) \n') |
|---|
| 871 |
|
|---|
| 872 |
|
|---|
| 873 |
for list in range(len(allVel1)): |
|---|
| 874 |
for i in range(0,Ncells): |
|---|
| 875 |
currentsOfile.write(str('%- 8.3f' % (allVel1[list][i]/1000.000))) |
|---|
| 876 |
currentsOfile.write(str('%- 8.3f' % (allVel2[list][i]/1000.000))) |
|---|
| 877 |
currentsOfile.write(str('%- 8.3f' % (allVel3[list][i]/1000.000))) |
|---|
| 878 |
currentsOfile.write(str('%-8d' % allAmp1[list][i])) |
|---|
| 879 |
currentsOfile.write(str('%-8d' % allAmp2[list][i])) |
|---|
| 880 |
currentsOfile.write(str('%-8d' % allAmp3[list][i])) |
|---|
| 881 |
currentsOfile.write( '\n') |
|---|
| 882 |
|
|---|
| 883 |
|
|---|
| 884 |
currentsOfile.close() |
|---|
| 885 |
currentsHeaderOfile.close() |
|---|
| 886 |
currentsTiltOfile.close() |
|---|
| 887 |
shutil.copy('currents','currents_'+currentsTime[0]+'.txt') |
|---|
| 888 |
shutil.copy('currentsHeader','currentsHeader_'+currentsTime[0]+'.txt') |
|---|
| 889 |
shutil.copy('currentsTilt','currentsTilt_'+currentsTime[0]+'.txt') |
|---|
| 890 |
|
|---|
| 891 |
print 'End Of File, Processing Complete' |
|---|
| 892 |
|
|---|
| 893 |
currentsOfile.close() |
|---|
| 894 |
currentsHeaderOfile.close() |
|---|
| 895 |
currentsTiltOfile.close() |
|---|
| 896 |
pressureOfile.close() |
|---|
| 897 |
rangeOfile.close() |
|---|
| 898 |
orbitOfile.close() |
|---|
| 899 |
sysinfoOfile.close() |
|---|
| 900 |
|
|---|
| 901 |
os.remove('currents') |
|---|
| 902 |
os.remove('currentsHeader') |
|---|
| 903 |
os.remove('currentsTilt') |
|---|
| 904 |
|
|---|
| 905 |
ifile.close() |
|---|
| 906 |
testOfile.close() |
|---|