diff --git a/metar.html b/metar.html
index c8fa455..e6791d9 100644
--- a/metar.html
+++ b/metar.html
@@ -279,6 +279,18 @@
'S': 'South', 'SW': 'Southwest', 'W': 'West', 'NW': 'Northwest'
};
+ function isDirection(dirStr) {
+ if (!dirStr) return false;
+ const dirParts = dirStr.split('-');
+ return dirParts.every(part => directions[part]);
+ }
+
+ function decodeDirection(dirStr) {
+ const dirParts = dirStr.split('-');
+ const decodedParts = dirParts.map(part => directions[part]);
+ return decodedParts.join(' to ').toLowerCase();
+ }
+
const decoders = [
// SLP
{
@@ -312,8 +324,8 @@
if (p.length > 1 && p[1] === 'ALQDS') {
return { consumed: 2, text: ` - VIRGA ALQDS: Virga in all quadrants` };
}
- if (p.length > 1 && directions[p[1]]) {
- return { consumed: 2, text: ` - VIRGA ${p[1]}: Virga to the ${directions[p[1]].toLowerCase()}` };
+ if (p.length > 1 && isDirection(p[1])) {
+ return { consumed: 2, text: ` - VIRGA ${p[1]}: Virga to the ${decodeDirection(p[1])}` };
}
return { consumed: 1, text: ` - ${p[0]}: ${specialRemarks[p[0]]}` };
}
@@ -346,8 +358,8 @@
if (mod === 'LENT') {
text = ` - ${cloudCode} LENT: ${cloudName} lenticularis`;
consumed = 2;
- if (p.length > 2 && directions[p[2]]) {
- text += ` to the ${directions[p[2]].toLowerCase()}`;
+ if (p.length > 2 && isDirection(p[2])) {
+ text += ` to the ${decodeDirection(p[2])}`;
consumed = 3;
}
} else if (mod === 'ASOCTD') {
@@ -356,8 +368,8 @@
if (p.length > 3 && p[2] === '/' && p[3] === 'HALO') {
text = ` - ${cloudCode} ASOCTD / HALO: ${cloudName} associated with Halo phenomenon`;
consumed = 4;
- } else if (p.length > 2 && directions[p[2]]) {
- text += ` to the ${directions[p[2]].toLowerCase()}`;
+ } else if (p.length > 2 && isDirection(p[2])) {
+ text += ` to the ${decodeDirection(p[2])}`;
consumed = 3;
}
} else if (mod === 'ALQDS') {
@@ -366,14 +378,14 @@
} else if (mod === 'TR') {
text = ` - ${cloudCode} TR: ${cloudName} clouds are translucent (thin)`;
consumed = 2;
- } else if (mod === 'DSNT' && p.length > 2 && directions[p[2]]) {
- text = ` - ${cloudCode} DSNT ${p[2]}: ${cloudName} distant ${directions[p[2]].toLowerCase()}`;
+ } else if (mod === 'DSNT' && p.length > 2 && isDirection(p[2])) {
+ text = ` - ${cloudCode} DSNT ${p[2]}: ${cloudName} distant ${decodeDirection(p[2])}`;
consumed = 3;
- } else if (directions[mod]) {
- text = ` - ${cloudCode} ${mod}: ${cloudName} to the ${directions[mod].toLowerCase()}`;
+ } else if (isDirection(mod)) {
+ text = ` - ${cloudCode} ${mod}: ${cloudName} to the ${decodeDirection(mod)}`;
consumed = 2;
- if (p.length > 3 && p[2] === 'MOV' && directions[p[3]]) {
- text += `, moving ${directions[p[3]].toLowerCase()}`;
+ if (p.length > 3 && p[2] === 'MOV' && isDirection(p[3])) {
+ text += `, moving ${decodeDirection(p[3])}`;
consumed = 4;
}
}