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 040021

Area Forecast Discussion
National Weather Service San Francisco Bay Area
421 PM PST Wed Mar 3 2021

.SYNOPSIS...Dry weather conditions will prevail with temperatures
near seasonal averages into early Friday. A frontal boundary will
bring widespread, yet generally light rainfall to the Bay Area and
Central Coast Friday night into Saturday. Cool, mostly dry and
breezy conditions are likely for the upcoming weekend. Continued
cool and unsettled weather returns through the first half of next

&& of 01:40 PM PST Wednesday...A mix of sun and
clouds around the Bay Area and Central Coast this afternoon as a
low pressure system swings into Southern California. The counter-
clockwise rotation around the low is directing ample clouds
northward. Weather radars across Southern California are showing
decent rainfall activity moving inland. Bay Area radars on the
other hand are quiet. There are a few echoes showing up near the
Monterey/SLO county line, but this is likely just high

The low pressure system to the south is on track to move eastward
over the next 24 hours into the the Desert Southwest. Simply put,
dry weather will continue through at least Thursday night.
Temperatures will remain near seasonal averages as well.

By Friday a shift in the pattern as an upper low trough swings
into NorCal. The trough will also have a cold front associated
with it. This front will slowly move into the North Bay late
Friday morning and then slowly progress through the Bay Area
through early Saturday. The front will bring a return of some
rainfall to the region. Onset of rain will begin in the North Bay
late morning and making to SF Bay by afternoon and finally the
Central Coast Friday evening. The front initially has a decent
moisture tap as it moves into the North Bay, but the continuous
moisture tap fades as the front moves southward. Rainfall amounts
are generally 0.5"-0.75" for the coastal ranges/hills,
0.25"-0.50" for immediate Bay Area and North Bay and 0.25" or less
elsewhere. Interior portions of Monterey/San Benito will generally
be less than 0.10". Enough colder air will fill in behind the
fropa that any lingering showers through early Saturday may be
snow over the higher peaks. Drier weather returns Saturday
afternoon with some sunshine, but temperatures will be cool. Dry
conditions again on Sunday, but only a warm up of a few degrees on

Does the storm door finally open back up next week or at least
open a crack? Longer range models, both deterministic and
ensembles, show a colder and unsettled pattern for next week. The
first in a series of disturbances passes through the region on
Monday. Guidance suggests rain returns on Monday. Precip will
likely continue Tuesday and Wednesday as a another upper low
drifts into NorCal. Atmospheric River guidance also shows that
moisture taps will be limited Monday through Wednesday. One
difference is that much colder air will accompany these systems so
snow falling over the higher peaks will be possible.

CPC keeps much of the region with higher chances for precip
through the middle of the month.

&& of 4:22 PM PST Wednesday...For the 00Z TAFs.
Predominantly VFR across terminals, with MVFR cigs at KHAF and
KWVI. Satellite imagery reveals mid- and high-level clouds
associated with the outflow of a low pressure system centered off
the SoCal coast near San Diego. Low clouds are also visible along
the coast of Santa Cruz County, northward to Marin County.
Expecting a push of low clouds over terminals later this evening,
with an increasing onshore gradient. This will result in IFR/MVFR
conditions and possible LIFR for coastal terminals, beginning
around 06z, and lasting through early to mid-morning. Winds are
currently breezy and sometimes gusty out of the west to southwest,
and will diminish after sunset.

Vicinity of KSFO...VFR with few014 and bkn200 reported. Winds have
been shifting between westerly and southerly in the last hour,
with breezier winds having diminished. Lighter wind tonight into
early Thursday morning becoming enhanced southwesterly by late
morning. Expecting low clouds around the bay this evening with
possible IFR cigs after 06z. Clearing expected by mid-morning.

SFO Bridge Approach...Similar to KSFO.

Monterey Bay Terminals...VFR. Few mid- and high-clouds, with low
clouds expected to move over terminals tonight for IFR/MVFR,
possible LIFR after 06z. Breezy onshore winds, diminishing
overnight. Clearing to VFR by mid-morning.

&& of 03:00 PM PST Wednesday...A Beach Hazards
Statement has been issued for 3 am Thursday to 3 am Friday. A long
period northwest swell will create dangerous beach conditions with
increased risk of sneaker waves, rip currents, and long shore
currents. Do not turn your back to the ocean. Stay off rocks and

&& of 02:26 PM PST Wednesday...Northwest swell
diminishing today. On Thursday, gusty south winds will develop
over the northern coastal waters. Moderate period northwest swell
increases to long period swell during the day Thursday into early
Friday. A slow moving low pressure system arrives from the
northwest with rain Friday evening through Saturday.





MARINE: Bingaman

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, March 2, 2021

High Temperature

97°F at Kyle Oakley Field Airport, KY

Low Temperature

-28°F at Mount Washington, NH

High Precipatation

2.67in at Bainbridge Decatur Co Industrial Air Park 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.04 - 28-Jul-2020 see history).