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 081148

Area Forecast Discussion
National Weather Service San Francisco Bay Area
448 AM PDT Wed Apr 8 2020

.SYNOPSIS...Isolated to scattered rain showers will be possible over
the Central Coast through midweek while mainly dry conditions
prevail to the north. Temperatures will begin a gradual warming
trend late in the week and into the upcoming weekend as conditions
dry out region-wide.

&& of 2:55 AM PDT Wednesday...The pesky low
pressure system that brought a variety of weather to the Bay Area
and Central Coast the last few days remains off the coast.
Overnight satellite imagery shows a broad circulation, with
embedded smaller circulations, spinning near the Channel Islands.
The cyclonic flow continues to advect moisture around the slow
moving low pressure. The advecting moisture has resulted in bands
of scattered showers moving over the San Joaquin Valley and
southern Monterey/San Benito. Over the last six hours a few gauges
have tipped in southern Monterey/San Benito with a few hundredths
up to a few tenths. It should be noted shower activity is
struggling to have any additional northern movement. Latest hi-res
models, like the HRRR and local WRF, keep showers chances through
day, but mainly south of San Jose. In fact, most likely locations
for showers will still be confined to Monterey/San Benito, but a
stray shower could drift north. The cold low pressure will make
for an interesting split with temperatures around the Bay
Area/Central Coast. Southern areas will remain seasonably cool
with filtered sunshine/showers (Monterey Bay region southward) and
northern areas will be mild an in a few spots above normal (San
Jose northward).

For tonight, the low finally moves eastward and begins its slow
exit of California. Before it finally exits a few additional
bands of showers may drift across the forecast area Wednesday
night and Thursday. Once again, best chance for precip will be
south of San Jose. Additional rainfall will generally be light.
Given the recent rain and lingering low level moisture patchy fog
will be possible Wednesday night and early Thursday.

Showers will end by Thursday night with a warming and drying trend
developing. Warmer and drier conditions are expect over the
weekend and into early next week.

&& of 4:46 AM PDT Wednesday...for 12Z TAFs. A thick
layer of stratus sits just off the coastline over the ocean, while
higher clouds spill over head associated to the weather system
over Southern California, tracking southeast. MVFR to VFR at this
hour. Locally varying winds will transition back to onshore and
strengthen in the afternoon as cloud cover lingers providing MVFR
conditions possible through the TAF period.

Vicinity of KSFO...MVFR at KSFO and KOAK due to stratus clouds
spilling into the Bay, with VFR elsewhere. Cigs are forecast to
lift to around 3,000 feet in the afternoon. Lower clouds for MVFR
conditions return in the evening for the remainder of the TAF
period. Winds are breezy and will re-strengthen and be onshore in
the afternoon.

SFO Bridge Approach...Similar to KSFO.

Monterey Bay Terminals...Closer to the coast, winds are breezy
with cigs around 1,500 feet and MVFR conditions. Farther inland
and winds are calmer with VFR. Winds will become onshore and
strengthen in the afternoon with cigs only lifting to around
2,500 feet. Isolated showers are possible in the evening.

&& of 02:37 AM PDT Wednesday...The low pressure system
continues to slowly move over southern California and farther
inland. Northwest winds will remain breezy through the morning and
then decrease. Lightly scattered showers over the southern waters
are possible. Northwest swell through the week, with a long
period southerly swell that gradually decreases.


     .Tday...SCA...Pt Arena to Pigeon Pt 10-60 nm until 3 PM
             SCA...Pt Arena to Pt Reyes 0-10 nm until 9 AM
             SCA...Pigeon Pt to Pt Piedras Blancas 10-60 nm until 9 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, April 7, 2020

High Temperature

93°F at Brownsville Intl, TX
93°F at Brooks Cnty Airport, TX
93°F at Fort Myers/Page Fld, FL
93°F at Gage/Shattuck, OK

Low Temperature

14°F at Iliamna Arpt (amos), AK
14°F at Mount Washington, NH

High Precipatation

1.85in at Winona, 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)
$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).