Repository: python-metar/python-metar

Issue:
Cannot parse multiple BECOMING groups
A `ParserError` is raised when trying to parse a report with multiple BECOMING (`BECMG`) groups:

> Unparsed groups in body 'BECMG FM1000 TL1020 6000 NSW' while processing 'METAR WSSS 280900Z 26009KT 180V350 0600 R20R/1900D R20C/1600D +TSRA FEW008 SCT013CB FEW015TCU 24/23 Q1010 BECMG FM0920 TL0930 3000 TSRA BECMG FM1000 TL1020 6000 NSW'

> Unparsed groups in body 'BECMG FM1920 TL1940 6000 NSW' while processing 'METAR WSSS 311900Z 28009KT 210V320 1800 +TSRA FEW010 FEW014CB BKN015TCU 25/24 Q1011 BECMG TL1920 4000 TSRA BECMG FM1920 TL1940 6000 NSW'

> Unparsed groups in body 'BECMG FM1955 TL2010 6000 NSW' while processing 'METAR WSSS 311930Z VRB05KT 1800 +TSRA FEW008 FEW014CB SCT015TCU 25/24 Q1011 BECMG FM1940 TL1955 4000 TSRA BECMG FM1955 TL2010 6000 NSW'

> Unparsed groups in body 'BECMG FM2020 TL2040 6000 NSW' while processing 'METAR WSSS 312000Z VRB04KT 2000 +TSRA FEW010 FEW014CB SCT040 BKN140 24/24 Q1011 BECMG TL2020 4000 -TSRA BECMG FM2020 TL2040 6000 NSW'

Comments:

Patch:
diff --git a/metar/Datatypes.py b/metar/Datatypes.py
index c1ba23f..201f624 100644
--- a/metar/Datatypes.py
+++ b/metar/Datatypes.py
@@ -480,8 +480,8 @@ class position(object):
         long1 = self.longitude
         lat2 = position2.latitude
         long2 = position2.longitude
-        a = sin(0.5(lat2 - lat1)) + cos(lat1) * cos(lat2) * sin(
-            0.5 * (long2 - long1) ** 2
+        a = (sin(0.5(lat2 - lat1))) ** 2 + cos(lat1) * cos(lat2) * (sin(
+            0.5 * (long2 - long1)) ** 2
         )
         c = 2.0 * atan(sqrt(a) * sqrt(1.0 - a))
         d = distance(earth_radius * c, "M")
diff --git a/metar/Metar.py b/metar/Metar.py
index 9ac23db..9dc08a7 100644
--- a/metar/Metar.py
+++ b/metar/Metar.py
@@ -43,7 +43,7 @@ TIME_RE = re.compile(
         (?P<min>\d\d)Z?\s+""",
     re.VERBOSE,
 )
-MODIFIER_RE = re.compile(r"^(?P<mod>AUTO|FINO|NIL|TEST|CORR?|RTD|CC[A-G])\s+")
+MODIFIER_RE = re.compile(r"^(?P<mod>AUTO|COR AUTO|FINO|NIL|TEST|CORR?|RTD|CC[A-G])\s+")
 WIND_RE = re.compile(
     r"""^(?P<dir>[\dO]{3}|[0O]|///|MMM|VRB)
         (?P<speed>P?[\dO]{2,3}|[/M]{2,3})
@@ -1045,7 +1045,7 @@ class Metar(object):
         (WINDSHEAR_RE, _handleWindShear, True),
         (COLOR_RE, _handleColor, True),
         (RUNWAYSTATE_RE, _handleRunwayState, True),
-        (TREND_RE, _handleTrend, False),
+        (TREND_RE, _handleTrend, True),
         (REMARK_RE, _startRemarks, False),
     ]
 


Test patch:
diff --git a/test/test_metar.py b/test/test_metar.py
index 3770baf..92e9534 100644
--- a/test/test_metar.py
+++ b/test/test_metar.py
@@ -39,6 +39,20 @@ def test_module():
     assert hasattr(metar, "__version__")
 
 
+def test_issue114_multiplebecominggroups():
+    """multiple BECMG (becoming) groups should be possible"""
+    code = (
+        "METAR WSSS 280900Z 26009KT 180V350 0600 R20R/1900D R20C/1600D +TSRA FEW008 SCT013CB FEW015TCU 24/23 Q1010 "
+        "BECMG FM0920 TL0930 3000 TSRA "
+        "BECMG FM1000 TL1020 6000 NSW"
+    )
+
+    metar = Metar.Metar(code)
+    assert metar.decode_completed
+    assert len(metar._trend_groups) == 10
+    assert metar.trend() == "BECMG FM0920 TL0930 3000 TSRA BECMG FM1000 TL1020 6000 NSW"
+
+
 @pytest.mark.parametrize("trailstr", ["", "=", "=  "])
 def test_issue84_trimequals(trailstr):
     """A trailing = in METAR should not trip up the ingest."""
@@ -602,3 +616,14 @@ def test_not_strict_mode():
     assert report.station_id == "K9L2"
     assert report.vis.value() == 10
     assert report.sky_conditions() == "clear"
+
+
+def test_cor_auto_mod():
+    """Test parsing of a COR AUTO Metar."""
+    code = (
+        "METAR KADW 252356Z COR AUTO 10008KT 10SM CLR 19/11 A2986 "
+        "RMK AO2 SLP117 T01880111 10230 20188 50004 $ COR 0007="
+    )
+    m = Metar.Metar(code, year=2019)
+
+    assert m.mod == 'COR AUTO'