diff --git a/metar.html b/metar.html index 3bbc3b5..c95074c 100644 --- a/metar.html +++ b/metar.html @@ -492,31 +492,72 @@ }, // VIS { - match: p => p[0] === 'VIS' && p.length > 2 && (isDirection(p[1]) || (p[1] === 'LW' && p.length > 3 && isDirection(p[3]))), + match: p => p[0] === 'VIS' && p.length > 2 && (isDirection(p[1]) || (p[1] === 'LW' && p.length > 3 && (isDirection(p[2]) || isDirection(p[3])))), decode: p => { - // VIS LW + // VIS LW ... if (p[1] === 'LW') { - const visibility = p[2].replace('SM', ''); - const direction = p[3]; - return { - consumed: 4, - text: ` - VIS LW ${p[2]} ${direction}: Visibility locally worse, ${visibility} statute miles to the ${decodeDirection(direction).replace(/ to /g, '-')}` - }; + // VIS LW ... (new format) + if (isDirection(p[2])) { + const direction = p[2]; + let vis_parts = [p[3]]; + let vis_consumed = 1; + + if (p.length > 4) { + if (p[4] === 'SM') { // "3 SM" + vis_parts.push(p[4]); + vis_consumed++; + } else if (p[3].match(/^\d+$/) && p[4].match(/^\d+\/\d+SM$/)) { // "1 1/2SM" + vis_parts.push(p[4]); + vis_consumed++; + } + } + const raw_vis = vis_parts.join(' '); + const raw_remark = ['VIS', 'LW', direction, raw_vis].join(' '); + const visibility = raw_vis.replace('SM', ''); + + return { + consumed: 3 + vis_consumed, + text: ` - ${raw_remark}: Visibility locally worse, ${visibility} statute miles to the ${decodeDirection(direction).replace(/ to /g, '-')}` + }; + } + + // VIS LW (old format) + if (isDirection(p[3])) { + const visibility = p[2].replace('SM', ''); + const direction = p[3]; + return { + consumed: 4, + text: ` - VIS LW ${p[2]} ${direction}: Visibility locally worse, ${visibility} statute miles to the ${decodeDirection(direction).replace(/ to /g, '-')}` + }; + } } // VIS if (isDirection(p[1])) { - const visibility = p[2].replace('SM', ''); const direction = p[1]; - const raw_vis = p[2]; - let consumed = 3; + let vis_parts = [p[2]]; + let vis_consumed = 1; + + if (p.length > 3) { + if (p[3] === 'SM') { // "3 SM" + vis_parts.push(p[3]); + vis_consumed++; + } else if (p[2].match(/^\d+$/) && p[3].match(/^\d+\/\d+SM$/)) { // "1 1/2SM" + vis_parts.push(p[3]); + vis_consumed++; + } + } + const raw_vis = vis_parts.join(' '); + const visibility = raw_vis.replace('SM', ''); + + let consumed = 2 + vis_consumed; let raw_parts = ['VIS', direction, raw_vis]; let text_parts = []; text_parts.push(`Visibility ${decodeDirection(direction)} ${visibility} miles`); - if (p.length > 3 && p[3] === 'INTMT') { - consumed = 4; + if (p.length > (2 + vis_consumed) && p[2 + vis_consumed] === 'INTMT') { + consumed++; raw_parts.push('INTMT'); text_parts.push('intermittent'); }