Skip to content

Reading BTL file with blank lines in header #196

@upsonp

Description

@upsonp

I've run into an issue reading a BTL file using the read.from_btl() function. The error occurred because there are blank lines in the header of the BTL file:

22102006.txt

...
30: * 7 external voltages sampled
31: * stored voltage # 0 = external voltage 0
32: * stored voltage # 1 = external voltage 1
33: * stored voltage # 2 = external voltage 2
34: * stored voltage # 3 = external voltage 3
35: * stored voltage # 4 = external voltage 4
36: * stored voltage # 5 = external voltage 5
37: * stored voltage # 6 = external voltage 6
38: *
39: 
40: * S>
41: * dh
42: * cast 0  03/31 06:45:17  smpls 0 to 10459  nv = 7  avg = 1  stp = switch of
43: 
44: * S>
45: # interval = seconds: 0.125
46: # start_time = Mar 31 2022 06:45:17 [Instrument's time stamp, header]
...

On line 39 a blank line is encountered, which activates this section of the read._parser_sea_save() function (line 169)

        else:  # btl.
            # There is no *END* like in a .cnv file, skip two after header info.
            if not (line.startswith("*") | line.startswith("#")):
                # Fix commonly occurring problem when Sbeox.* exists in the file
                # the name is concatenated to previous parameter
                # example:
                #   CStarAt0Sbeox0Mm/Kg to CStarAt0 Sbeox0Mm/Kg (really two different params)
                line = re.sub(r"(\S)Sbeox", "\\1 Sbeox", line)

                names = line.split()
                skiprows = k + 2
                break

Of course it hits the break and the rest of the file isn't read.

Any advice?

I have several thoughts on how we could solve this, but I don't want to modify something that will break the code for others.

Just spit balling, but a simple solution is to just make sure the line isn't a blank line

current code

        else:  # btl.
            # There is no *END* like in a .cnv file, skip two after header info.
            if not (line.startswith("*") | line.startswith("#")):
                # Fix commonly occurring problem when Sbeox.* exists in the file
                # the name is concatenated to previous parameter
                # example:
                #   CStarAt0Sbeox0Mm/Kg to CStarAt0 Sbeox0Mm/Kg (really two different params)
                line = re.sub(r"(\S)Sbeox", "\\1 Sbeox", line)

                names = line.split()
                skiprows = k + 2

modified code

        else:  # btl.
            # There is no *END* like in a .cnv file, skip two after header info.
            if line != '' and not (line.startswith("*") | line.startswith("#")):
                # Fix commonly occurring problem when Sbeox.* exists in the file
                # the name is concatenated to previous parameter
                # example:
                #   CStarAt0Sbeox0Mm/Kg to CStarAt0 Sbeox0Mm/Kg (really two different params)
                line = re.sub(r"(\S)Sbeox", "\\1 Sbeox", line)

                names = line.split()
                skiprows = k + 2

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions