Dr. Arne JachensDr. Arne Jachens

Heizungssteuerung Web-Interface

readNamedData

Script to read in structured data, where the first line is expected to contain the names of the data columns.

From dicrectory $path the file $fname is read in. The data should be in columns which are separated by $delimiter.

The result $data is an array with column names of raw data as array keys.

<?php 
/* published under GPL www.gnu.org/licenses/gpl.html */
function readNamedData($fname,$path,$delimiter){
  $fname=sprintf("%s%s", $path, $fname);
  if (file_exists($fname)) {
    $fid = fopen($fname, "r");
    $line = fgets( $fid, 2048 ); #headerline
    $line=str_replace(" #","",trim($line));
    $fieldNames=explode($delimiter,$line);
    $NoVars=count($fieldNames);
    $line = fgets( $fid, 2048 );
    $n=-1;
    while(!feof($fid)){
    if($line[0]!=" #"){
      $n++;
      /* change format of numbers */
      $line=str_replace(",",".",$line);
      $values=explode($delimiter,$line);
      #echo $fname. "<br>";
      #print_r($fieldNames);echo "<br>";
      #print_r($values);echo"<br>";
      #exit(1);
      $time[$n]=trim($values[0]);
      echo $line. "<br>";
      for($m=0;$m<$NoVars;$m++){
	$data[$fieldNames[$m]][$n]=trim($values[$m]);
      } #m
      } #fi
      $line = fgets( $fid, 2048 );
    } #n
    fclose($fid);
  }else{
    printf("FILE ".$fname." DOES NOT EXIST!\N");
  }
  return $data;
}
?>

Index of Library

1EM_editParameter.php
2EM_handleJSON.php
3EM_plot.php
4HV_Admin_Login.php
5HV_colorMap.php
6HV_composeH2Oplot.php
7HV_config.php
8HV_H2Olevel.php
9HV_readOperationState.php
10HV_restart.php
11HV_serviceLog.php
12HV_setParameters.php
13HV_showHouse.php
14HV_showLog.php
15HV_showWeatherForecast.php
16HV_TempCal.php
17index.php
18readFilenames.php
19readNamedData.php

Der gesamte Sourcecode darf gemäß GNU General Public License weiterverbreitet werden.