NCCOOS Trac Projects: Top | Web | Platforms | Processing | Viz | Sprints | Sandbox | (Wind)

Changeset 315

Show
Ignore:
Timestamp:
01/08/10 11:43:28
Author:
gdusek
Message:

changes to mulitple files due to recent merge

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • DPWP/trunk/DPWP/ADCP_splitter/adcpwaves.py

    r225 r315  
    11"""This code takes the raw waves portion of the adcp data from the splitter 
    22and outputs pressure, range, orbital velocity and system info text files that 
    3 can be read into matlab.""" 
     3can be read into matlab. 
     4 
     5NOTE:  Transducer height above bottom is hardwired into this code at .4m. 
     6Need to update code in the future to be a user selected option""" 
    47 
    58 
     
    1720 
    1821ifile = open(infileName, 'rb') 
     22 
     23# set the transducer height above bottom 
     24thab = 0.4 
    1925 
    2026 
     
    3541    Header =struct.unpack('H',readFirstHeader)[0] 
    3642    #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 
    3746 
    3847    firstLeaderHeader=259 
    3948    wavePingHeader=515 
    4049    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] 
    4555 
    4656    #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     
    4872     
    4973    readLeaderHeader=ifile.read(2) 
    5074    leaderHeader =struct.unpack('H',readLeaderHeader)[0] 
     75    #print hex(leaderHeader) 
    5176     
    5277    if leaderHeader != firstLeaderHeader: 
     
    141166 
    142167    # transducer height above the bottom 
    143     th = 0.4 
     168    th = thab 
    144169 
    145170    # heights above transducer 
     
    149174    hab = [th+elem for elem in hat] 
    150175 
     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         
    151187    for value in hab: 
    152188        sysinfoOfile.write(str(value)) 
     
    198234     
    199235    #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); 
    201244 
    202245 
     
    211254 
    212255     
    213         #read the length 
    214         length=ifile.read(2) 
    215         if len(length) == 0: 
     256        #read the checksum offset 
     257        csOffset=ifile.read(2) 
     258        if len(csOffset) == 0: 
    216259            print('\n End of file') 
    217260            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 
    222278     
    223279        readLeaderHeader=ifile.read(2) 
     
    226282        # if the leader header isnt the wave ping header move on to the next leader 
    227283        if leaderHeader != wavePingHeader: 
    228            break 
     284            break 
    229285 
    230286        #read through sample number and time since burst (don't need this) 
     
    263319        #read and write the orbital velocity data 
    264320 
    265         bytes=40 
     321        bytes=binsOut*8 
    266322 
    267323        while bytes > 0: 
     
    274330        orbitOfile.write('\n') 
    275331 
    276         #reserved space (?) 
    277         ifile.read(6) 
    278332 
    279333    # Done with the Wave Ping Type>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> 
    280334 
     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         
    281360 
    282361     
     
    332411    stdRoll=ifile.read(2) 
    333412 
    334     test1=ifile.read(2) 
    335      
    336     test2=ifile.read(2) 
     413    cs=ifile.read(2) 
     414 
     415    spare=ifile.read(2) 
    337416     
    338417