public function parse($remaining_metar, $cavok = false)
 {
     $result = $this->consume($remaining_metar);
     $found = $result['found'];
     $new_remaining_metar = $result['remaining'];
     // handle the case where nothing has been found and metar is not cavok
     if ($found == null && !$cavok) {
         throw new ChunkDecoderException($remaining_metar, $new_remaining_metar, 'Bad format for clouds information', $this);
     }
     // default case: CAVOK or clear sky, no cloud layer
     $result = array('clouds' => array());
     // there are clouds, handle cloud layers and visibility
     if ($found != null && $found[2] == null) {
         for ($i = 3; $i <= 15; $i += 4) {
             if ($found[$i] != null) {
                 $layer = new CloudLayer();
                 $layer_height = Value::toInt($found[$i + 2]);
                 if ($layer_height !== null) {
                     $layer_height_ft = $layer_height * 100;
                 } else {
                     $layer_height_ft = null;
                 }
                 $layer->setChunk(trim($found[$i]));
                 $layer->setAmount($found[$i + 1])->setBaseHeight(Value::newValue($layer_height_ft, Value::FEET))->setType($found[$i + 3]);
                 $result['clouds'][] = $layer;
             }
         }
     }
     // return result + remaining metar
     return array('result' => $result, 'remaining_metar' => $new_remaining_metar);
 }
 public function parse($remaining_metar, $cavok = false)
 {
     $result = $this->consume($remaining_metar);
     $found = $result['found'];
     $new_remaining_metar = $result['remaining'];
     // handle the case where nothing has been found
     if ($found == null) {
         throw new ChunkDecoderException($remaining_metar, $new_remaining_metar, 'Bad format for visibility information', $this);
     }
     if ($found[1] == 'CAVOK') {
         // cloud and visibility OK
         $cavok = true;
         $visibility = null;
     } elseif ($found[1] == '////') {
         // information not available
         $cavok = false;
         $visibility = null;
     } else {
         $cavok = false;
         $visibility = new Visibility();
         if ($found[2] != null) {
             // icao visibility
             $visibility->setChunk(trim($found[1]));
             $visibility->setVisibility(Value::newIntValue($found[2], Value::METER));
             if ($found[4] != null) {
                 $visibility->setMinimumVisibility(Value::newIntValue($found[5], Value::METER))->setMinimumVisibilityDirection($found[6]);
             }
             $visibility->setNDV($found[3] != null);
         } else {
             // us visibility
             $main = intval($found[7]);
             $frac_top = intval($found[9]);
             $frac_bot = intval($found[10]);
             if ($frac_bot != 0) {
                 $vis_value = $main + $frac_top / $frac_bot;
             } else {
                 $vis_value = $main;
             }
             $visibility->setChunk(trim($found[1]));
             $visibility->setVisibility(Value::newValue($vis_value, Value::STATUTE_MILE));
         }
     }
     // return result + remaining metar
     return array('result' => array('cavok' => $cavok, 'visibility' => $visibility), 'remaining_metar' => $new_remaining_metar);
 }
 public function parse($remaining_metar, $cavok = false)
 {
     $result = $this->consume($remaining_metar);
     $found = $result['found'];
     $new_remaining_metar = $result['remaining'];
     // throw error if nothing has been found
     if ($found == null) {
         throw new ChunkDecoderException($remaining_metar, $new_remaining_metar, 'Atmospheric pressure not found', $this);
     }
     $raw_value = Value::toInt($found[2]);
     $type = $found[1];
     // convert value if needed
     if ($type == 'A') {
         $raw_value = $raw_value / 100;
     }
     $value = Value::newValue($raw_value, $this->units[$type]);
     // retrieve found params
     $result = array('pressure' => $value);
     // return result + remaining metar
     return array('result' => $result, 'remaining_metar' => $new_remaining_metar);
 }