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 261211

Area Forecast Discussion
National Weather Service San Francisco Bay Area
511 AM PDT Mon Sep 26 2022

.SYNOPSIS...A deep marine layer this morning with widespread low
clouds slowly clearing back to the coast by midday. Further
cooling on Tuesday as a weak weather system passes to our north
keeping temperatures a few degrees below normal into Wednesday.
High pressure rebuilds Thursday and Friday with a warming trend
before temperatures return to near normal next weekend with
continued dry weather.

&& of 3:25 AM PDT Monday...Marine layer has
deepened in excess of 1500 feet with a widespread stratus
intrusion this morning out into the Delta, much of the North Bay
and poking out into the interior East Bay valleys. Westerly winds
were gusting to around 20 mph at Travis AFB just after midnight
which is a sure sign of cool marine air spreading inland as SFO-
Sac gradient remains just under 3 mb. The airmass aloft is still
warm with the higher hills still seeing temps in the 70s. However
the presence of the deep marine layer, onshore gradients and
approaching upper trough by Tuesday suggest temps will be a few
degrees below model guidance. Expect low clouds to erode back to
the coast a little slower this morning. This afternoon the onshore
breezes may be stronger as the next upstream shortwave approaches
well offshore.

As this feature arrives on Tuesday expect further deepening of
the marine layer overnight into Tuesday with breezy west winds
Tuesday afternoon along the coast and through the coastal gaps
along with local drizzle as the marine layer deepens. Inland highs
mainly 70 and lower 80s for Tuesday afternoon with no big changes
into Weds.

As that system moves east high pressure rebuilds Thursday and
Friday with a noted warming and drying trend as weak northerly
flow develops in the boundary layer. That being said not seeing
signs of any significant northerly or offshore wind events that
are favored by climatology this time of year. After temps rebound
to finish out the work week another trough arrives by next weekend
keeping temps near to slightly below normal.

Fire danger decreased after last weeks wetting rains. Energy
release components are still below normal (wet/moist) but quickly
climbing back towards normal values. For the time being there are
prescribed burns that the office is supporting but we will need
to keep monitoring fuel/soil moisture levels as we finish out Sept
and head into October.

In the uber long range there are some hints of the PNA trending
negative by around Columbus Day which is when climatology
supports the first wetter troughs into the Pacific Northwest. Euro
and GFS ensembles show a few members with precip for far NorCal
which has shown up in some of the fantasy range runs of the gfs
out beyond 300 hours. Just something to watch over the coming
weeks as we transition deeper into fall.


.AVIATION...As of 5:10 AM Monday... For the 12Z TAFs. Marine
stratus intrusion has brought a mix of MVFR/IFR/LIFR conditions to
most area terminals. Coastal profilers depict a fairly steady
marine layer depth 1600-1800 ft. Satellite imagery shows stratus
covering the bays and near coastal valleys, and is now expanding
into interior East Bay. With similar conditions to yesterday,
projecting clearing at terminals 17z-19z, interior to coastal.
Clouds may linger around Monterey Bay somewhat later. Winds on
Monday afternoon expected to be moderate to breezy in a generally
northwesterly onshore pattern. Stratus returns by evening to
Monterey Bay, and at night to SF Bay area with likely MVFR/IFR
cigs as the marine layer deepens.

Vicinity of SFO... Combination of MVFR/IFR cigs as stratus now
covers the bay and area terminals. Extensive coverage over land
and ocean with onshore gradient should keep clearing until late
morning (18z-19z), with moderate confidence. Light winds becoming
breezy onshore out of the NW this afternoon, 15-20 kt with some
higher gusts. High confidence in return of stratus tonight with
low confidence in timing.

KSFO Bridge Approach... Similar to SFO.

Monterey Bay... Mainly LIFR conditions, with IFR at KSNS. Late
clearing to VFR, 18z-21z, from the interior to the coast.
Northwest winds light to moderate this afternoon, with moderate
confidence in an early return of stratus around 01z-03z.

&& of 02:42 AM PDT Monday...The northern waters will
see light to moderate northwest winds today through Tuesday.
Stronger winds will be experienced south of Pigeon Point,
especially near coastal jet areas. Winds will ramp up Wednesday
and Thursday across the waters, combined with stronger northwest
swell, resulting in steep, hazardous seas. A series of moderate
period northwest swells continues through the week along with a
longer period southerly swell.


     .Tday...SCA...SF Bay from 3 PM
             SCA...Pigeon Pt to Pt Pinos 0-10 nm from 3 PM
             SCA...Pt Pinos to Pt Piedras Blancas 0-10 nm from 3 PM



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 Sunday, September 25, 2022

High Temperature

111°F at El Centro Naf, CA

Low Temperature

26°F at Leadville, CO

High Precipatation

1.33in at Somerset Airport, NJ

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).