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 Sunday, 05-Apr-2020 7:47 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 071732

Area Forecast Discussion
National Weather Service San Francisco Bay Area
1032 AM PDT Tue Apr 7 2020

.SYNOPSIS...An upper low moving slowly south just off the
California coast will maintain shower chances today, although many
areas will likely remain dry. Shower chances will persist
primarily across areas south of San Jose into Wednesday and
Thursday as the upper low will be slow to exit the region. A
warming and drying trend is forecast late in the week and into the


.DISCUSSION...As of 3:30 AM PDT Tuesday...Early morning satellite
imagery shows that the upper low responsible for yesterday`s
showers and thunderstorms remains centered just off the Central
Coast, and is moving slowly to the south. Radar indicates that
most shower activity is currently located offshore, although a few
light showers are being detected over the North Bay. Models agree
that shower potential will persist across much of our forecast
area today as vorticity centers rotate around the upper low, but
shower activity is expected to be more widely scattered today
compared to yesterday, and thunderstorms are far less likely. The
greatest chance of precipitation today is across Monterey and San
Benito Counties during this afternoon and evening. The other
short-term item of note is morning fog. Fog has formed in the
North and East Bay Valleys early this morning, and expect patchy
fog to persist in these areas through about mid morning.

Shower chances will continue through at least Wednesday, primarily
across areas south of San Jose, as the upper low moves inland
across southern California. Models often struggle with the track
of cutoff lows, and this case is no exception. There has been a
lot of model disagreement concerning the exact track of the low
around midweek. Latest models now forecast to the low to move to
near Las Vegas by Wednesday night and then retrograde back into
California on Thursday. Thus, we may very well see an increase in
shower activity on Thursday, especially across the south. And, if
the 00Z ECMWF verifies with its more northerly forecast track of
the retrograding low, then showers could develop as far north as
San Francisco on Thursday. Given the model inconsistencies
regarding the track of the upper low beyond 36 hours, forecast
confidence decreases greatly by Thursday.

Additional rainfall this week is expected to be less than a half
inch, with many locations, especially across the north, expected
to see very little accumulation, or none at all.

Yesterday`s temperatures were as much as 15 degrees below normal,
but we should see temperatures rebound today as the cold core of
the upper low moves away from our area, and also because most
areas will see more sun today. Temperatures should continue to
gradually warm through the week, except perhaps on Thursday if
the upper low retrogrades as forecast. Warming and drying are
expected in all areas from Friday through the weekend, and also
into early next week, as the upper low finally moves well off to
our east and an upper ridge builds just off the West Coast.

&& of 10:32 AM PDT Tuesday...for 18Z TAFs. This
morning`s low clouds have cleared out leaving some higher level
clouds across the North Bay at about 10,000 ft AGL. Current obs
show VFR conditions at all sites. Expecting VFR to prevail through
this evening before models show a region wide increase in low
level moisture overnight. MVFR/IFR cigs then forecast to prevail
for most if not all sites through the rest of the taf period.
Guidance suggests these low clouds may linger around the Bay Area
into the early afternoon. Additionally, patchy fog may also return
to the North Bay and portions of the East Bay. Generally light
winds this morning turning onshore in the afternoon around 10-15

Radar shows some lingering showers over portions of Sonoma County
this morning, though most areas should remain dry most of today.
High res models show some possible showers returning tonight in
the Monterey Bay Region south of San Jose.

Vicinity of KSFO...VFR through the evening before low clouds are
expected to develop across the Bay Area and then persist through
tomorrow morning. Low confidence on exact timing of cloud
development. May be a few stray showers in the vicinity but
otherwise dry conditions forecast. Variable winds again this
morning to turn onshore this afternoon around 10-15 kt.

SFO Bridge Approach...Similar to KSFO.

Monterey Bay Terminals...VFR into this evening before low clouds
are forecast to develop over the Monterey Region. MVFR/IFR
conditions then expected through the rest of the taf period.
Additionally, high res models are showing showers developing late
tonight and into early tomorrow morning. Light winds this morning
with locally breezy SE winds down the Salinas Valley. Onshore
winds this afternoon 10-15 kt.

&& of 08:29 AM PDT Tuesday...Northwest winds will
increase across the coastal waters this afternoon and into
tomorrow as an upper low slowly exits the region. Locally breezy
winds are expected this afternoon and evening over the Monterey
Bay and along the inner coastal waters from Pigeon Point to Point
Pinos as well as overnight north of Point Reyes. A long period
southwest and a long period west to northwest swell will arrive
this morning and continue into tomorrow before decreasing.


     .Tday...SCA...Mry Bay from 3 PM
             SCA...Pigeon Pt to Pt Pinos 0-10 nm from 3 PM




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 Monday, April 6, 2020

High Temperature

89°F at Miami/Kendall-tamiami, FL

Low Temperature

14°F at Eielson Afb, AK
14°F at Port Heiden (amos), AK
14°F at Meridian/Key Field, MS

High Precipatation

1.67in at Van Nuys Airport, CA

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)
$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.01 - 05-Apr-2020 see history).