src/fwidm/dwdHourlyCrawler/hourly/DWDStationsController.php
public static function parseStations($filePath)
    {
        if (DIRECTORY_SEPARATOR == '\\')
            $filePath = str_replace('/', '\\', $filePath);
        ini_set('display_errors', 1);
        error_reporting(E_ALL);
        $stationConf = DWDConfiguration::getStationConfiguration();
        $stations = array();

        if (file_exists($filePath)) {
            $handle = fopen($filePath, "r");
            if ($handle) {
                //skips the first N lines of input, requires the file handle.
                self::skipDescriptionLines($stationConf->skipLines, $handle);
                while (($line = fgets($handle)) !== false) {
                    $line = mb_convert_encoding($line, "UTF-8", "iso-8859-1");

                    // eliminate multiple spaces, replace by single space
                    $output = preg_replace('!\s+!', ' ', $line);
                    //remove trailing and leading spaces.
                    $output = trim($output, ' ');

                    // process the line read - split by spaces
                    // stationId, from, until, stationHeight, lat, long, station name, state
                    // Station name can contain spaces and needs further processing, thus we limit to keep station name + state
                    // in one field
                    $split = explode(" ", $output, 7);
                    $name = explode(" ", $split[count($split) - 1]);
                    //last cell contains the county name.
                    $county = $name[count($name) - 1];
                    // merge all other contents of the name, glue them together with spaces.
                    $nameSlice = array_slice($name, 0, count($name) - 1);
                    $name = implode(" ", $nameSlice);

                    //evtl. array_filter
                    $from = Carbon::createFromFormat($stationConf->dateFormat, $split[1], 'UTC');
                    $until = Carbon::createFromFormat($stationConf->dateFormat, $split[2], 'UTC');

                    $station = new DWDStation($split[0], $from, $until,
                        $split[3], $split[4], $split[5], $name, $county,
                        $stationConf->activeRequirementDays);
                    $stations[] = $station;

                }

                fclose($handle);
            } else {
                throw new DWDLibException("Error opening the file: " . $filePath);
            }
        } else
            throw new DWDLibException("File does not exist - path: " . $filePath);

        return $stations;
    }
public static function parseStations($filePath)
    {
        if (DIRECTORY_SEPARATOR == '\\')
            $filePath = str_replace('/', '\\', $filePath);
        ini_set('display_errors', 1);
        error_reporting(E_ALL);
        $stationConf = DWDConfiguration::getStationConfiguration();
        $stations = array();

        if (file_exists($filePath)) {
            $handle = fopen($filePath, "r");
            if ($handle) {
                //skips the first N lines of input, requires the file handle.
                self::skipDescriptionLines($stationConf->skipLines, $handle);
                while (($line = fgets($handle)) !== false) {
                    $line = mb_convert_encoding($line, "UTF-8", "iso-8859-1");

                    // eliminate multiple spaces, replace by single space
                    $output = preg_replace('!\s+!', ' ', $line);
                    //remove trailing and leading spaces.
                    $output = trim($output, ' ');

                    // process the line read - split by spaces
                    // stationId, from, until, stationHeight, lat, long, station name, state
                    // Station name can contain spaces and needs further processing, thus we limit to keep station name + state
                    // in one field
                    $split = explode(" ", $output, 7);
                    $name = explode(" ", $split[count($split) - 1]);
                    //last cell contains the county name.
                    $county = $name[count($name) - 1];
                    // merge all other contents of the name, glue them together with spaces.
                    $nameSlice = array_slice($name, 0, count($name) - 1);
                    $name = implode(" ", $nameSlice);

                    //evtl. array_filter
                    $from = Carbon::createFromFormat($stationConf->dateFormat, $split[1], 'UTC');
                    $until = Carbon::createFromFormat($stationConf->dateFormat, $split[2], 'UTC');

                    $station = new DWDStation($split[0], $from, $until,
                        $split[3], $split[4], $split[5], $name, $county,
                        $stationConf->activeRequirementDays);
                    $stations[] = $station;

                }

                fclose($handle);
            } else {
                throw new DWDLibException("Error opening the file: " . $filePath);
            }
        } else
            throw new DWDLibException("File does not exist - path: " . $filePath);

        return $stations;
    }
public static function parseStations ( $ filePath ) { if ( DIRECTORY_SEPARATOR == '\\' ) $ filePath = str_replace ( '/' , '\\' , $ filePath ) ; ini_set ( 'display_errors' , 1 ) ; error_reporting ( E_ALL ) ; $ stationConf = DWDConfiguration :: getStationConfiguration ( ) ; $ stations = array ( ) ; if ( file_exists ( $ filePath ) ) { $ handle = fopen ( $ filePath , "r" ) ; if ( $ handle ) { //skips the first N lines of input, requires the file handle. self :: skipDescriptionLines ( $ stationConf -> skipLines , $ handle ) ; while ( ( $ line = fgets ( $ handle ) ) !== false ) { $ line = mb_convert_encoding ( $ line , "UTF-8" , "iso-8859-1" ) ; // eliminate multiple spaces, replace by single space $ output = preg_replace ( '!\s+!' , ' ' , $ line ) ; //remove trailing and leading spaces. $ output = trim ( $ output , ' ' ) ; // process the line read - split by spaces // stationId, from, until, stationHeight, lat, long, station name, state // Station name can contain spaces and needs further processing, thus we limit to keep station name + state // in one field $ split = explode ( " " , $ output , 7 ) ; $ name = explode ( " " , $ split [ count ( $ split ) - 1 ] ) ; //last cell contains the county name. $ county = $ name [ count ( $ name ) - 1 ] ; // merge all other contents of the name, glue them together with spaces. $ nameSlice = array_slice ( $ name , 0 , count ( $ name ) - 1 ) ; $ name = implode ( " " , $ nameSlice ) ; //evtl. array_filter $ from = Carbon :: createFromFormat ( $ stationConf -> dateFormat , $ split [ 1 ] , 'UTC' ) ; $ until = Carbon :: createFromFormat ( $ stationConf -> dateFormat , $ split [ 2 ] , 'UTC' ) ; $ station = new DWDStation ( $ split [ 0 ] , $ from , $ until , $ split [ 3 ] , $ split [ 4 ] , $ split [ 5 ] , $ name , $ county , $ stationConf -> activeRequirementDays ) ; $ stations [ ] = $ station ; } fclose ( $ handle ) ; } else { throw new DWDLibException ( "Error opening the file: " . $ filePath ) ; } } else throw new DWDLibException ( "File does not exist - path: " . $ filePath ) ; return $ stations ; }
Parse the station files into station objects.
@param $filePath - path to the station file
@return array - of stations
@throws DWDLibException - if zip opening fails or  zip does not exist
Parse the station files into station objects .