schwehr / generic-sensor-format

Sonar Generic Sensor Format (gsf) codec
Other
13 stars 8 forks source link

Dump GSV Hex Records #89

Closed murphyf001 closed 5 years ago

murphyf001 commented 5 years ago

Open gsf files, read through record by record and write the record on a CSV line. Each line has record length and record type as human readable values.

murphyf001 commented 5 years ago

By dumping by record, you can easily visualize the structure of the GSF file. Records are separated by lines of hex values. Each value is a four byte word.

schwehr commented 5 years ago

Can you explain why you closed the pull request?

murphyf001 commented 5 years ago

Basically, while I may know programming, I am a novice at GitHub. I'm also a novice at Python and swath bathymetry.

I'm trying to use the process of translating GSF from C to Python to enhance both my GSF knowledge and Python programming skills.

I tried to pass you the following code. The code will dump each GSF record as: int RecordLength, Int RecordType, 4 word hex of the rest of the record.

! Python 3.6.2

#

Licensed under the Apache License, Version 2.0 (the "License");

you may not use this file except in compliance with the License.

You may obtain a copy of the License at

#

http://www.apache.org/licenses/LICENSE-2.0

#

Unless required by applicable law or agreed to in writing, software

distributed under the License is distributed on an "AS IS" BASIS,

WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.

See the License for the specific language governing permissions and

limitations under the License.

Program dumps gsf files into records

record length, record type, and hex representation of the record

import os from struct import unpack import argparse def DumpGSF(filename):

Open dump file as Comma Separated Values file

for easy import into the spreadsheet of your choice

dumpfileName = filename + ".csv" infile = open(filename,"rb") dumpfile = open(dumpfileName,"w")

step through a record at a time

while True:

read the first two INT values

read_Length_Type = infile.read(8) if len(read_Length_Type)==0: break # End of file reached. recordLength,recordType = unpack(">II",read_Length_Type)

Human readable

dumpfile.write("{},{}".format(recordLength,recordType))

Read through each four byte word of the record

Understand that some values are two byte words and characters

for index in range(int(recordLength/4)): hexVal = infile.read(4).hex() dumpfile.write(",0x"+ hexVal)

New line at the end of the record

dumpfile.write("\n") dumpfile.close() def main(): parser = argparse.ArgumentParser() parser.add_argument('filenames', metavar='N', type=str, nargs='+', help='Files to get info about.') args = parser.parse_args() print(args) print(args.filenames) for filename in args.filenames: DumpGSF(filename) main()

I tried to open a new issue/pull request, but had difficulty.

I hope this is useful, Frank Murphy

On Mon, Sep 3, 2018 at 10:11 AM Kurt Schwehr notifications@github.com wrote:

Can you explain why you closed the pull request?

— You are receiving this because you modified the open/close state. Reply to this email directly, view it on GitHub https://github.com/schwehr/generic-sensor-format/pull/89#issuecomment-418141779, or mute the thread https://github.com/notifications/unsubscribe-auth/AMjLtNQASPsJNR2ERaXHH8guqE56Jrntks5uXUaLgaJpZM4WOsN3 .