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 Tuesday, 28-Jul-2020 2:45 PM

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 050602

Area Forecast Discussion
National Weather Service San Francisco Bay Area
1002 PM PST Fri Dec 4 2020

.SYNOPSIS...Daytime temperatures cool slightly headed into the
weekend as a weak cold front pushes into northern California.
Offshore winds are then set to develop late Sunday into Monday with
gusty conditions in the region`s higher elevations. Otherwise, mild
afternoons and cool nights are expected through next week with
ongoing dry weather conditions.

&& of 09:02 PM PST Friday...Another pleasant day
around the Bay Area and Central for the second day in a row with
highs above normal. Generally speaking high temps this afternoon
topped out in the mid 60s to low 70s - or about 5 to 10 degrees
above normal for early December. Mostly clear skies earlier this
evening yielded another nice sunset. Clear skies and relatively
light winds overnight will also translate to another chilly night
across the interior valleys and away from urban centers. Did
update the official forecast to lower interior temperatures by a
few degrees - closer to what was observed Friday morning. Coldest
interior spots will hit the lower 30s to possibly some upper 20s.

The main weather concerns the next few days continues to be the
same - precip chances over the weekend and an offshore flow event
later in the weekend into early next week. A few of the 00Z models
are in and still show a decaying frontal boundary moving over the
Bay Area Saturday night and early Sunday. The hi-res models show a
better chance for light precip over the North Bay and coastal
drizzle/coastal mountain drizzle elsewhere. No beneficial
rainfall nonetheless. One upside of the decaying boundary will be
solid uptick in RH. The higher humidity will temper fire weather
concerns a tad with the offshore flow event. In other words,
gusty offshore flow will kick in Sunday night (see below for
details), but humidity will be on the higher side and not lower
until Monday. That is likely the reason a Fire Weather Watch will
not be needed. Winds remain offshore on Monday across the entire
forecast area. That being said, high temperatures on Monday may
not be high enough. Digging into some ensemble data and the
Extreme Forecast Index (ECMWF) shows the low level temperatures
being forecast on Monday are on the anomalous side. If the models
keep trending this way, temperatures on Monday may need a boost.

Still no major rain expected through the middle of the month. Not
looking good with percent of normals for OAK and SJC sitting at


.PREV of 01:25 PM PST Friday...

A mid/upper level trough will then push into the Pacific Northwest
late Saturday driving a frontal boundary into northern California.
Cloud cover will increase ahead of this frontal boundary and result
in slightly cooler afternoon temperatures, especially for the
northern portion of the region. The latest short-range guidance
indicates the potential for light rain to reach coastal Sonoma
County Saturday afternoon and evening along the tail end of the
frontal boundary. While coastal drizzle may also be possible with
this passing system, region-wide measurable precipitation is
unlikely. At best, a few hundredths of an inch of rainfall will be
possible, especially along coastal Sonoma County.

Cloud cover will begin to clear out during the afternoon on Sunday
as a cut-off low develops from the aforementioned mid/upper level
trough and tracks southward into Nevada. This will result in a
tightening pressure gradient allowing for offshore flow to develop
over the region late Sunday night into Monday. North to northeast
winds will be strongest in the region`s hills, ridges and peaks
early Monday morning before weakening slightly Monday afternoon.
Wind gusts of 35 to 45 mph will be likely with the gusts in excess
of 50 mph possible in the highest peaks (Mt. Saint Helena & Mt.
Diablo). At this time, the lowest humidity doesn`t look to advect
into the region until during the day Monday as winds begin to relax.
That said, elevated to near critical fire weather conditions are
still possible from late Sunday into Monday in the region`s higher
elevations as fuels across the region are nearing record dryness.
Thus, these conditions will be closely monitored in the coming days.

As the ridge builds inland to our north, winds will diminish and
temperatures will be on a warming trend Monday into Tuesday with
widespread 60s to low/mid 70s possible through midweek. The warmest
areas look to be across the interior portions of the Central Coast
on Tuesday where a few spots may even reach into the upper 70s. This
too will likely result in cooler overnight temperatures as well late
next week. Temperatures do trend slightly cooler late in the week as
troughing returns to the West Coast, yet dry weather conditions look
likely to persist.

&& of 10:01 PM PST Friday...For the 06z TAFs. VFR
across all terminals with mostly clear skies and light winds.
Satellite night imagery shows some low clouds developing offshore,
which are not expected to impact terminals. High clouds are a
couple of hundred miles off shore. Mostly clear conditions
expected overnight with a dry airmass in place, though patchy fog
and low clouds will be possible in coastal valleys, and along the
immediate coast. A frontal boundary approaches Saturday afternoon
bringing high clouds, but little to no precip, so VFR conditions
will prevail throughout the day.

Vicinity of KSFO...VFR with clear skies and light winds through
the overnight hours. High clouds move in Saturday afternoon, but
remaining VFR with light winds

SFO Bridge Approach...Similar to KSFO.

Monterey Bay Terminals...VFR with clear skies. Light to calm
winds with light to moderate SE wind developing in the Salinas
Valley overnight. VFR continues tomorrow with high clouds for the

&& of 9:00 PM Friday...Occasional large breaking waves
may still persist over the next several hours, but the NW swell
continues to subside. A moderate NW swell will prevail through the
weekend. Models are indicating the next NW swell to arrive on
Monday. This swell is currently forecast to be slightly smaller
than this previous swell train, however it will arrive with a
period between 20-22 seconds on Monday, with growing wave heights
into Tuesday. Use caution if visiting the coast and remember to
never turn your back to the ocean!

&& of 08:43 PM PST Friday...Light to locally moderate
northwest winds will continue tonight through early Saturday while
long period NW swell slowly subsides. As a front approaches
Saturday afternoon, winds will become southwesterly to westerly
before turning northerly and increasing on Sunday. Some light rain
or drizzle is possible in the northern waters Saturday afternoon
and evening. As winds ease and turn out of the NE Monday night
into Tuesday, another long period large amplitude swell will move
into the waters. This will cause large breaking waves across
nearshore shoals.


     .Tngt...SCA...Pigeon Pt to Pt Piedras Blancas 10-60 nm until 3 AM



MARINE: Lorber

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 Thursday, December 3, 2020

High Temperature

86°F at Christiansted Hamilton Field Ap, VI

Low Temperature

-10°F at Big Piney Marbleton Ap, WY
-10°F at Dixon Airport, WY

High Precipatation

0.92in at Jackson Hawkins Field, MS

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.04 - 28-Jul-2020 see history).