From weatherlink to meteohub

Discussion of the Meteohub software package

Moderator: Mattk

Post Reply
meteo-bures
Fresh Boarder
Fresh Boarder
Posts: 7
Joined: Fri Apr 03, 2015 11:04 am

From weatherlink to meteohub

Post by meteo-bures »

Hello,

I'm looking for a way to stop my 24/24 PC running Weatherlink.

Two functions are still missing for me : For the NOAA report, I'm just close to find a solution with the template script below. But some variables are still missing :
  • seqdays1_th0_temp_max_time
    seqdays1_th0_temp_min_time
    seqdays1_wind0_gustspeedmax_kn
    seqdays1_wind0_gustspeedmax_time
    rain max mm and time for the month
    and, but it's not useful for me, hett and cool degree days
You can see both Weatherlink report et Meteohub here :
Weatherlink : http://www.meteo-bures.fr/meteo/noaa/NOAAMO.TXT
Meteohub : http://www.meteo-bures.fr/uploadMH/NOAAMO.php

If anybody has some idea, i'll be interested :D

Below my script :

Code: Select all

<html>
<head>
</head>
<body>
<?php

// convertion lat and long from DEC to DMS
$lat   = DECtoDMS ( [actual_station_latitude_decimal], "LAT" ) ;
$long  = DECtoDMS ( [actual_station_longitude_decimal], "LONG" ) ;

// count days for the month
$nbday = cal_days_in_month ( CAL_GREGORIAN, [actual_date0_month_local], [actual_date0_year_local] ) ;

// array construct with seqday var
$seqday1_th0_temp_c_tab = explode ( " ", "[seqday1_th0_temp_c]" ) ;
$seqday1_th0_tempmin_c_tab = explode ( " ", "[seqday1_th0_tempmin_c]" ) ;
$seqday1_th0_tempmax_c_tab = explode ( " ", "[seqday1_th0_tempmax_c]" ) ;
$seqday1_rain0_total_mm_tab = explode ( " ", "[seqday1_rain0_total_mm]"  ) ;
$seqday1_wind0_speed_kn_tab = explode ( " ", "[seqday1_wind0_speed_kn]" ) ;
$seqday1_wind0_gustspeed_kn_tab = explode ( " ", "[seqday1_wind0_gustspeed_kn]" ) ;
$seqday1_wind0_maindir_deg_tab = explode ( " ", "[seqday1_wind0_maindir_deg]" ) ;
$seqday1_localdate_tab = explode ( " ", "[seqday1_localdate]" ) ;

// init counters
$Max32     = 0 ;
$Max0      = 0 ;
$Min0      = 0 ;
$Min18     = 0 ;
$MaxRain   = max ( $seqday1_rain0_total_mm_tab ) ; // *bad* not reliable, because there are days of month and month -1
$DayRain   = [month1_rain0_days] ;
$DayRain02 = 0 ;
$DayRain2  = 0 ;
$DayRain20 = 0 ;
?>
<pre>
                   MONTHLY CLIMATOLOGICAL SUMMARY for <?php echo strftime ( "%b. %Y", strtotime ( [actual_localdate] ) ) ; ?> 

NAME: Montjay   CITY: Bures-sur-Yvette   STATE: France 
ELEV: <?php echo sprintf("%5d", [actual_thb0_height_m]) ; ?> m  LAT:  <?php echo sprintf ( "%2d", $lat['deg'] ) . "&deg; " . sprintf ( "%02d", $lat['min'] ) . "' " . sprintf ( "%02d", $lat['sec'] ) . "\" " . $lat['dir'] ; ?>  LONG:  <?php echo sprintf ( "%2d", $long['deg'] ) . "&deg; " . sprintf ( "%02d", $long['min'] ) . "' " . sprintf ( "%02d", $long['sec'] ) . "\" " . $long['dir']; ?>


                   TEMPERATURE (&deg;C), RAIN  (mm), WIND SPEED (km/h)

                                      HEAT  COOL        AVG
    MEAN                              DEG   DEG         WIND                 DOM
DAY TEMP  HIGH   TIME   LOW    TIME   DAYS  DAYS  RAIN  SPEED HIGH   TIME    DIR
------------------------------------------------------------------------------------
<?php

// seqday1 array begin at current day -1 
// the 1st of current month begin at seqday array at current day - 2
	$j = [actual_date0_day_local] - 2 ;
	
	// loop for 1st of month and current day -1
	for ( $i = 1; $i <= $nbday; $i++ ) {
	
		// print day
		echo sprintf ( "%2d", $i ) ;
		
			// if exist weather value
		if ( $seqday1_th0_temp_c_tab[$j] ) {

			// print mean temp
			echo sprintf ( "%6.1f", $seqday1_th0_temp_c_tab[$j] ) ;
			
			// print temp max
			echo sprintf ( "%6.1f", $seqday1_th0_tempmax_c_tab[$j] ) ;
			
			// time temp max unknown
			echo sprintf ( "%8s", "00:00" ) ;
			
			// print temp min
			echo sprintf ( "%6.1f", $seqday1_th0_tempmin_c_tab[$j] ) ;
			
			// time temp min unknown
			echo sprintf ( "%8s", "00:00" ) ;
			
			// heat deg day unknown
			echo sprintf ( "%6.1f", 0 ) ;
			
			// cool deg day unknown
			echo sprintf ( "%6.1f", 0 ) ;
			
			// print total day rain
			echo sprintf ( "%6.1f", $seqday1_rain0_total_mm_tab[$j] ) ;
			
			// print avg wind speed in km/h
			echo sprintf ( "%6.1f", $seqday1_wind0_speed_kn_tab[$j] * 1.852 ) ;
			
			// *bad* max gustspeed unknown, only avg gustspeed 
			echo sprintf ( "%6.1f", $seqday1_wind0_gustspeed_kn_tab[$j] * 1.852 ) ;
			
			// time gustspeed unknown
			echo sprintf ( "%8s", "00:00" ) ;
			
			// print wind dir text (function below)
			echo sprintf ( "%6s", WinDIR( $seqday1_wind0_maindir_deg_tab[$j] ) ) ;
			
			// calc nb days with temp max >= 32
			if ( $seqday1_th0_tempmax_c_tab[$j] >= 32 ) {
				$Max32++ ;
			}
			// calc nb days with temp max <+ 0
			if ( $seqday1_th0_tempmax_c_tab[$j] <= 0 ) {
				$Max0++ ;
			}
			// calc nb days with temp min <= 0
			if ( $seqday1_th0_tempmin_c_tab[$j] <= 0 ) {
				$Min0++ ;
			}
			// calc nb days with temp min <= -18
			if ( $seqday1_th0_tempmin_c_tab[$j] <= -18 ) {
				$Min18++ ;
			}
			// calc nb days with rain, with rain > 20mm and > 2mm
			if ( $seqday1_rain0_total_mm_tab[$j] >  0) {
				if ( $seqday1_rain0_total_mm_tab[$j] > 20 ) {
					$DayRain20++ ;
				}
				elseif ( $seqday1_rain0_total_mm_tab[$j] > 2 ) {
					$DayRain2++ ;
				}
			}
		}
		echo "<br />" ;
		$j = $j - 1 ;
	}
echo "------------------------------------------------------------------------------------" ;
echo "<br />" ;

// print month values (from month1)
echo sprintf ( "%8.1f", [month1_th0_temp_c] ) . 
	sprintf ( "%6.1f", [month1_th0_tempmax_c] ) . 
	sprintf ( "%6d", strftime( '%d', strtotime( [month1_th0_tempmax_time] ) ) ) . 
	sprintf ( "%8.1f", [month1_th0_tempmin_c] ) . 
	sprintf ( "%6d", strftime( '%d', strtotime( [month1_th0_tempmin_time] ) ) ) . 
	sprintf ( "%8.1f", 0 ) . 
	sprintf ( "%6.1f", 0 ) . 
	sprintf ( "%6.1f", [month1_rain0_total_mm] ) .
	sprintf ( "%6.1f", [month1_wind0_speed_kmh] ) .
	sprintf ( "%6.1f", [month1_wind0_gustspeedmax_kmh] ) . 
	sprintf ( "%6d", strftime ( '%d', strtotime ( [month1_wind0_gustspeedmax_time] ) ) ) . 
	sprintf ( "%8s", [month1_wind0_maindir_en] ) ;
echo "<br />" ;
echo "<br />" ;

// print nb days with temp max >= 32 
echo "Max >=  32.0:" . sprintf ( "%3d", $Max32 ) . "<br />" ;

// print nb days with temp max >= 0
echo "Max <=   0.0:" . sprintf ( "%3d", $Max0 ) . "<br />" ;

// print nb days with temp min <= 0
echo "Min <=   0.0:" . sprintf ( "%3d", $Min0 ) . "<br />" ;

// print nb days with temp min <= -18
echo "Min <= -18.0:" . sprintf ( "%3d", $Min18 ) . "<br />" ;

// *bad* print max rain (not reliable) and date time max rain
echo "Max Rain:" . sprintf ( "%6.2f", $MaxRain ) . " ON " . strftime ( "%d/%m/%y", strtotime ( $DateMaxRain ) ) . "<br />" ;

// print nb days with rain, with rain > 2mm and with rain > 20 mm
echo "Days of Rain: " . $DayRain . " (> .2 mm) " . $DayRain2 . " (> 2 mm) " . $DayRain20 . " (> 20 mm) <br />" ;

// print base for cool and heat degree days
echo "Heat Base:  18.3  Cool Base:  18.3  Method: Integration" . "<br />" ;
?>
</pre>

<?php
function DECtoDMS ( $dec, $dir ) {

// Converts decimal longitude / latitude to DMS
// ( Degrees / minutes / seconds ) 

// This is the piece of code which may appear to 
// be inefficient, but to avoid issues with floating
// point math we extract the integer part and the float
// part by using a string function.

	if ( strtoupper ( $dir ) == "LAT" ) {
    	$Direction = $dec < 0 ? 'S': 'N' ;
    }  
    elseif ( strtoupper ( $dir ) == "LONG" ) {
    	$Direction = $dec < 0 ? 'W': 'E' ;
    }		

    $vars = explode ( ".",$dec ) ;
    $deg = $vars[0] ;
    $tempma = "0.".$vars[1] ;

    $tempma = $tempma * 3600 ;
    $min = floor ( $tempma / 60 ) ;
    $sec = $tempma - ( $min*60 ) ;

    return array ( "deg" => $deg, "min" => $min, "sec" => $sec, "dir" => $Direction );
}    

function WinDIR($dir) {

// convert wind decimal direction to text
	if ( $dir <= 11.25 ) {
		$txt = "N" ;
	}
	elseif ( $dir <= 33.75 ) {
		$txt = "NNE" ;
	}
	elseif ( $dir <= 56.25 ) {
		$txt = "NE" ;
	}
	elseif ( $dir <= 78.75 ) {
		$txt = "ENE" ;
	}
	elseif ( $dir <= 101.25 ) {
		$txt = "E" ;
	}
	elseif ( $dir <= 123.75 ) {
		$txt = "ESE" ;
	}
	elseif ( $dir <= 146.25 ) {
		$txt = "SE" ;
	}
	elseif ( $dir <= 168.75 ) {
		$txt = "SSE" ;
	}
	elseif ( $dir <= 191.25 ) {
		$txt = "S" ;
	}
	elseif ( $dir <= 213.75 ) {
		$txt = "SSW" ;
	}
	elseif ( $dir <= 236.25 ) {
		$txt = "SW" ;
	}
	elseif ( $dir <= 258.75 ) {
		$txt = "WSW" ;
	}
	elseif ( $dir <= 281.25 ) {
		$txt = "W" ;
	}
	elseif ( $dir <= 303.75 ) {
		$txt = "WNW" ;
	}
	elseif ( $dir <= 326.25 ) {
		$txt = "NW" ;
	}
	elseif ( $dir <= 348.75 ) {
		$txt = "NNW" ;
	}
	elseif ( $dir <= 360 ) {
		$txt = "N" ;
	}
	
	return $txt ;
}

?>	
</body>
</html>  
Best regards :-)
Post Reply