src/MetadataParser.php
/**
     * Parse metadata from text file
     * 
     * Legacy: Both parameter and location metadata were stored in VQHA80/98 files.
     * 
     * As of 2021 only parameter metadata is stored in text files. Location metadata is stored
     * in CSV files.
     * 
     * @param string $raw SwissMetNet metadata string from text file
     * @return stdClass $metadata[array locations, array parameters]
     */
Parse metadata from text file

Both parameter and location metadata were stored in VQHA80/98 files.

As of 2021 only parameter metadata is stored in text files. Location metadata is stored
in CSV files.

@param string $raw SwissMetNet metadata string from text file
@return stdClass $metadata[array locations, array parameters]
Parse metadata from text file Both parameter and location metadata were stored in VQHA80 / 98 files . As of 2021 only parameter metadata is stored in text files . Location metadata is stored in CSV files . @param string $raw SwissMetNet metadata string from text file @return stdClass $metadata [ array locations array parameters ]
public static function parseFromTextFile(string $raw)
    {
        $metadata = new \stdClass();
        $metadata->locations = [];
        $metadata->parameters = [];
        $lines = explode("\n", $raw);
        foreach ($lines as $line) {
            $parts = [];
            if (!preg_match("/^([A-Z]{3,5})[ ]+(.+)[ ]+([0-9]{1,2})°([0-9]{2})'\/([0-9]{1,2})°([0-9]{2})'[ ]+([0-9]+)\/([0-9]+)[ ]+([0-9]+)/", utf8_encode($line), $parts)) continue;
            $location = [
                'id' => $parts[1],
                'name' => trim($parts[2]),
                'lat' => round($parts[5] + ($parts[6] / 60), 2),
                'lon' => round($parts[3] + ($parts[4] / 60), 2),
                'chx' => intval($parts[7]),
                'chy' => intval($parts[8]),
                'alt' => intval($parts[9]),
            ];
            $metadata->locations[] = (object) $location;
        }
        foreach ($lines as $line) {
            $parts = [];
            if (!preg_match("/^([a-z0-9]{8})[ ]{5,}(.*)[ ]{5,}(.*)/", utf8_encode($line), $parts)) continue;
            $parameter = [
                'id' => $parts[1],
                'unit' => trim($parts[2]),
                'description' => trim($parts[3]),
            ];
            $metadata->parameters[] = (object) $parameter;
        }
        return $metadata;
    }
public static function parseFromTextFile ( string $ raw ) { $ metadata = new \ stdClass ( ) ; $ metadata -> locations = [ ] ; $ metadata -> parameters = [ ] ; $ lines = explode ( " \n " , $ raw ) ; foreach ( $ lines as $ line ) { $ parts = [ ] ; if ( ! preg_match ( " /^([A-Z]{3,5})[ ]+(.+)[ ]+([0-9]{1,2})°([0-9]{2})'\/([0-9]{1,2})°([0-9]{2})'[ ]+([0-9]+)\/([0-9]+)[ ]+([0-9]+)/", u f8_encode($ l i ne), $ a rts)) c ntinue; $ location = [ 'id' => $ parts [ 1 ] , 'name' => trim ( $ parts [ 2 ] ) , 'lat' => round ( $ parts [ 5 ] + ( $ parts [ 6 ] / 60 ) , 2 ) , 'lon' => round ( $ parts [ 3 ] + ( $ parts [ 4 ] / 60 ) , 2 ) , 'chx' => intval ( $ parts [ 7 ] ) , 'chy' => intval ( $ parts [ 8 ] ) , 'alt' => intval ( $ parts [ 9 ] ) , ] ; $ metadata -> locations [ ] = ( object ) $ location ; } foreach ( $ lines as $ line ) { $ parts = [ ] ; if ( ! preg_match ( " /^([a-z0-9]{8})[ ]{5,}(.*)[ ]{5,}(.*)/ " , utf8_encode ( $ line ) , $ parts ) ) continue ; $ parameter = [ 'id' => $ parts [ 1 ] , 'unit' => trim ( $ parts [ 2 ] ) , 'description' => trim ( $ parts [ 3 ] ) , ] ; $ metadata -> parameters [ ] = ( object ) $ parameter ; } return $ metadata ; }
Parse metadata from text file
Parse metadata from text file
// Find locations // Query for station line // Find parameters // Query for parameter line