Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Reading BTL file with blank lines in header #196

Closed
upsonp opened this issue Nov 29, 2023 · 1 comment
Closed

Reading BTL file with blank lines in header #196

upsonp opened this issue Nov 29, 2023 · 1 comment

Comments

@upsonp
Copy link
Contributor

upsonp commented Nov 29, 2023

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
upsonp added a commit to upsonp/python-ctd that referenced this issue Nov 29, 2023
upsonp added a commit to upsonp/python-ctd that referenced this issue Dec 6, 2023
ocefpaf added a commit that referenced this issue Jan 8, 2024
@upsonp
Copy link
Contributor Author

upsonp commented Feb 22, 2024

This issue was resolved.

@upsonp upsonp closed this as completed Feb 22, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant