Skip to content

Commit

Permalink
AAXX YYGGiw typo verification
Browse files Browse the repository at this point in the history
  • Loading branch information
RoryPTB committed Oct 16, 2023
1 parent 342fb66 commit ee2c01d
Showing 1 changed file with 13 additions and 5 deletions.
18 changes: 13 additions & 5 deletions synop2bufr/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -1206,10 +1206,7 @@ def extract_individual_synop(data: str) -> list:
:returns: `list` of messages
"""

# Check for abbreviated header line TTAAii etc.

# Now split based as section 0 of synop, beginning AAXX YYGGi_w
# Split string based on section 0 of FM-12, beginning with AAXX
start_position = data.find("AAXX")

# Start position is -1 if AAXX is not present in the message
Expand All @@ -1218,7 +1215,18 @@ def extract_individual_synop(data: str) -> list:
"Invalid SYNOP message: AAXX could not be found."
)

data = re.split('(AAXX [0-9]{5})', data[start_position:])
# Split the string by AAXX YYGGiw
data = re.split('(AAXX\s+[0-9]{5})', data[start_position:])

# Check if the beginning of the message, that we're about to throw
# away (data[0]), also contains AAXX and thus there must be a
# typo present at the AAXX YYGGiw part of the report
if data[0].__contains__("AAXX"):
raise ValueError((
f"The following SYNOP message is invalid: {data[0]}"
" Please check again for typos."
))

data = data[1:] # Drop first null element
# Iterate over messages processing
messages = []
Expand Down

0 comments on commit ee2c01d

Please sign in to comment.