Weather station scripts

They're free, but use at your own risk

The scripts referenced here are used in the operation of this weather station, and may be freely copied and used to support your station. Please note that you use these scripts at your own risk. No warranty is expressed or implied. I accept no liability for any damages that may ensue from their use.
You will need to configure them for your own particular weather station website.
RSS feed for Scripts Updates A RSS Feed is available to help keep you informed on updates to the scripts.

Many of these scripts are now available on GitHub at

If you find one or more of the scripts useful to you, please consider making a donation to help offset the routine expenses of operation of this website.
Thanks for your kind support!

A Version History is available -- check back from time to time to see if there are updates to scripts you have downloaded earlier. Announcements of version updates and new scripts are made on and Weather-Watch forums and saratogaWXPHP Twitter account as they become available.

This page was updated Friday, 26-Jun-2020 8:09 AM

PHP for NWS Area Forecast Discussion

This PHP script will fetch and cache the Forecast Area Discussion issued by your local NWS office.
Thanks to Mike Challis of Long Beach, WA for the inspiration for and enhancement of this script.

FXUS66 KMTR 090531

Area Forecast Discussion
National Weather Service San Francisco Bay Area
1031 PM PDT Wed Jul 8 2020

.SYNOPSIS...A warming and drying trend will occur through the
remainder of the work week and into the upcoming weekend,
especially across the interior. Meanwhile, seasonable conditions
are likely near the coast with periods of night and morning low
clouds giving way to mostly sunny afternoon conditions.


.DISCUSSION...As of 8:55 PM PDT Wednesday...Skies remain mostly
clear this evening except for increasing areas of low clouds near
Monterey Bay and a patch of stratus in western San Mateo County.
Low clouds are expected to gradually increase along the coast from
San Francisco southward overnight, and also develop inland from
Monterey Bay. However, a relatively robust 5.0 mb surface pressure
gradient from ACV to SFO will likely be sufficient to keep most of
the North Bay clear overnight, and limit inland intrusion of low
clouds in the SF Bay Area to only a few patches around SF Bay
late tonight and early on Thursday. Another limiting factor on
inland development of low clouds/fog overnight is the relatively
shallow depth of the marine layer - currently just over 1000 feet
at Fort Ord.

Models agree that an upper ridge will build over the Desert
Southwest through the remainder of the work week, and also expand
to the northwest across California, particularly over the upcoming
weekend. This will result in a continuation of a gradual warming
trend through Sunday. The warming trend will primarily impact
inland areas, as persistent onshore surface flow maintains
seasonably mild temperatures near the ocean. The gradual warming
trend may stall on Friday, or even reverse a few degrees in the
North Bay Valleys, when the north-to-south surface pressure
gradient weakens. But overall, the trend will be for gradual
inland warming, with temperatures expected to peak on Sunday.
Lower to mid 90s will become more common across the interior
tomorrow, while a few of the warmer spots such as Lake Berryessa
and Pinnacles National Park may reach 100. By Sunday, widespread
mid to upper 90s are likely in the interior valleys, with the
warmest inland valley spots expected to see highs in the 100-107
degree range.

In addition to a warming trend, the airmass over the interior is
forecast to become even drier through Sunday. Daytime minimum
relative humidity will be as low as the single digits, especially
over the weekend, while nighttime humidity recovery in the hills
above 1500 feet will be poor. These warm and dry conditions will
be a concern from a fire weather perspective. Fortunately, winds
are expected to be relatively light through the weekend, except
for local moderate and gusty afternoon and evening seabreeze

From Previous Discussion...Medium range forecast guidance and
ensembles indicates the ridge of high pressure over the Four
Corners will weaken in response to troughing over the Pacific
Northwest during the first half of next week. This will result in
a cooling trend (most notably across the interior) along with
breezy onshore winds.


.AVIATION...As of 10:31 PM PDT Wednesday...For 06z TAFs. Patchy
cloud cover have moved over coastal terminals, though VFR
conditions are still present and forecast through the TAF period;
the exception still being near the Monterey Peninsula dropping to
IFR later tonight. Onshore winds will prevail through the TAF
period with lighter winds overnight and stronger winds Thursday
afternoon, with stronger gusts possible, with widespread VFR.

Vicinity of KSFO...FEW cigs at 1200 ft AGL as KHAF is at MVFR.
While a few clouds could spill over the Bay, there is low
confidence in lower cigs at KSFO for tonight. Winds are still
breezy and onshore, though lighter than earlier tonight. VFR is
forecast on Thursday with stronger onshore winds with occasional

SFO Bridge Approach...Similar to KSFO.

Monterey Bay Terminals...MVFR already at KMRY with VFR elsewhere.
IFR and even LIFR is possible for terminals closer to the coast.
MVFR is expected farther inland with IFR possible. Winds remain
onshore and breezy, but will ease overnight. Clouds should mix out
by 18z for VFR, with stronger onshore winds Thursday afternoon.

&& of 8:29 PM PDT Wednesday...Winds out of the
northwest will prevail and remain gusty through tonight as high
pressure remains over the eastern Pacific. These winds will
generate steep fresh swell resulting in hazardous seas conditions,
particularly for smaller vessels. Winds will begin to ease
Thursday night into Friday over much of the waters, but remain
locally breezy over the northern outer waters. Mixed seas will
persist with a shorter period wind driven northwest wave and a
more moderate period southerly swell.


     .Tngt...SCA...Pt Arena to Pt Reyes 0-10 nm
             SCA...Pt Reyes to Pigeon Pt 0-10 nm
             SCA...Pt Arena to Pigeon Pt 10-60 nm
             SCA...Pigeon Pt to Pt Piedras Blancas 10-60 nm
             SCA...Pt Pinos to Pt Piedras Blancas 0-10 nm until 3 AM




Visit us at

Follow us on Facebook, Twitter, and YouTube at:

NWS MTR Office Area Forecast Discussion

To use, include the output of the script on your webpage by using

$doIncludeFD = true;
include("forecast-discussion.php"); ?>

to perform the include. Settings inside the script are:

// settings:
//  change myNWS to abbreviation for your local NWS office
//    other settings are optional
    $myNWS = 'MTR';   // San Francisco, NWS office
//  $myNWS = 'PQR';   // Portland, OR
//  $myNWS = 'OAX';   // Omaha, NE (Carter Lake, IA)
$cacheName = "forecast-discussion.txt"; // used to store the file so we don't have to // fetch it each time $refetchSeconds = 1800; // refetch every nnnn seconds
$cacheFileDir = './'; // default cache file directory // end of settings

The only required setting is for $myNWS which designates the local NWS office.
To find the 3-character abbreviation for your local NWS office for the $myNWS variable, follow these steps:

  1. Browse to
  2. Use the search box on the left to search for your city, state
  3. Look at the URL in the 'Forecast Discussion' link near the bottom of the page
  4. Use the 3-character abbreviation is in the &issuedby=XXX parameter on the Forecast Discussion link (XXX will be your local office)
  5. put the XXX in the $myNWS = 'XXX'; statement

The script has two optional parameters when you call it by URL from your website::

Will return the contents without the surrounding <html><head></head><body> and </body></html> tags
Will override the default $refetchSeconds=1800 so that the cache is refreshed immediately

NWS Area Forecast Discussion PHP script Demo and Download (1.06 - 27-Feb-2018 see history).

PHP for NWS CPC World Extremes

This script was originated by Michael of and has been rewritten to use the NWS Climate Prediction Center's CSV file for world observations. The script does not produce output (other than HTML comments for status), so you are free to include it in a page, and format the text output as you desire. The script returns data in variables:

$omittedCountry (text list of countries excluded from $world high/low/precip scans)
Note: the setting $ignoreCountrys is the array of country names to to exclude

$selectedCountry (setting: country name for selected country high/low/precip)
Note: run to see the list of country names to use

$usahigh (Note: for lower-48 USA states)
$usalow (Note: for lower-48 USA states)
$usaprecip (Note: for lower-48 USA states)

$selectedState (setting: USA state 2-character name abbreviation in settings area)
$selectState (a copy of $selectedState for compatibility with old stateextremes.php)

$reportDate (nicely formatted date of the report)
$stateReportDate (a copy of $reportDate for compatibility with old stateextremes.php)

You can run the script by using:


print "<p>USA Extremes for $reportDate</p>\n";
print "<p>High Temperature<br/><br/>$usahigh</p>\n";
print "<p>Low Temperature<br/><br/>$usalow</p>\n";
print "<p>High Precipatation<br/><br/>$usaprecip</p>\n";
print "<p><small>Data courtesy of <a href=\"";
print "";
print "\">NWS-CPC</a></small></p>\n";


which produces this result (with live data):

USA Extremes for Tuesday, July 7, 2020

High Temperature

114°F at Blythe Asos, CA

Low Temperature

33°F at Bryce Canyon Ap, UT
33°F at Lakeview Lake County Ap, OR

High Precipatation

5.12in at Augusta Daniel Field Airport, GA

Data courtesy of NWS-CPC

The script has internal settings which you can adjust. If run in a Saratoga template, the cache file will be stored in the ./cache/ directory based on $SITE['cacheFileDir'] in Settings.php.

$cacheFileDir = './'; // directory to store cache file in.
$cacheFile2 = "worldextremesCache.txt";  
// Age of cache file before re-fetch caching time, in seconds (3600 = 1 hour)
$cache_life = '3600';
$reportDateFormat = "l, F j, Y"; // Day, Month d, yyyy 
$tUOM = '&deg;F'; // or ='' for no temperature unit display (display in C is default)
$rUOM = 'in';     // or ='' for no rain unit display (display in mm is default)
$ignoreCountrys = array('Antarctica','Greenland');     // for world extremes - exclude these country(s)
$ignoreStations = array('99KLRJ');     // list of stn_id (field 0) to ignore for bogus data
$tempDiffAllowed = 40; // max difference Tmax-Tmin (C) for valid data
$selectedCountry = 'Canada'; // for country max/min/precip in $country* variables
// note: the $usa* variables will have the min/max/precip for the lower-48 states
$selectedState   = 'CA';  // for USA state max/min/precip in $state* variables

Note that $cacheFileDir, $tUOM, $rUOM will use the Saratoga template Settings.php values if used in a Saratoga template.

NWS CPC One Day Extremes PHP script Download (5.03 - 26-Jun-2020 see history).