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 191131

Area Forecast Discussion
National Weather Service San Francisco Bay Area
431 AM PDT Thu May 19 2022

.SYNOPSIS...Gusty northerly winds increase tonight into Friday
with elevated fire weather concerns developing. Seasonably warm
and dry weather continues for this weekend into next week.
Forecast remains dry over the next 7 to 10 days.

&& of 02:20 AM PDT Thursday...

Thursday through Wednesday

Today through Friday:

Subtropical ridging will remain prominent across the eastern Pacific
while downstream troughing drops through the Pacific Northwest and
Great Basin. An accompanying cold front will sweep through the Bay
Area early today before dissipating along the Central Coast this
afternoon. A focused push of dry northerly winds will accompany this
system down the Sacramento Valley before affecting eastern portions
of the Bay Area from this evening into Friday morning. This will
lead to an uptick in both fire weather and wind related concerns
during this time. Taking a look at each potential hazard:

* Fire Weather: the combination of gusty winds and low relative
  humidity values will lead to elevated fire weather concerns
  later this afternoon through the first half of Friday. While
  live fuels remain somewhat moist dead fuels are drying. And
  while neither the expected fuels or weather conditions are
  considered "extreme" for our area they are still favorable for
  the rapid spread of new fires. The best overlap for near-
  critical conditions is over portions of the North and East Bay
  bordering the Sacramento Valley including the Napa Hills,
  eastern Contra Costa County, and the East Bay Hills. This area
  is outlooked in an Elevated fire weather risk by the Storm
  Prediction Center which appears prudent given expected
  conditions. Remember to do your part to be one less spark.
  Remember One less spark, one less wildfire.

* Wind: dry north to northeast winds are expected to push down the
  Sacramento valley late today and tonight, likely peaking from late
  tonight into Friday morning. Gusts of 40-50 mph are likely in the
  higher terrain of the Napa Hills, eastern Contra Costa County, and
  the East Bay hills. A Wind Advisory is now in effect for these
  areas from later tonight through late Friday morning. These winds
  may lead to downed limbs and power lines; particularly in the
  higher terrain.

High temperatures on Thursday will range from the 80s to near 90 for
inland areas with cooler 60s and lower 70s along the coast and bays.
Expect a few degrees of cooling by Friday as the upper trough passes
to our east. Lows will be mostly in the upper 40s and 50s.

Saturday through Wednesday:

Our area should remain along the northeast periphery of the mid-
upper ridge as surface high pressure centers to our west. Look for
seasonally warm and dry conditions with generally light winds.
Interior areas will remain on the warm side (80s-90s) while coastal
areas will remain in the 60s and 70s given daily seabreezes and
persistently cool sea-surface temperatures.

&& of 04:31 AM PDT Thursday...For the 12Z TAFs. Most
of the regional winds have tapered off, but the San Bruno Gap
continues to escalates winds around 20 knots at KSFO. The chance
for LLWS over the North Bay continues early Thursday morning, but
should be over by 15Z. VFR skies for Thursday. Winds increase once
again after 18Z and and feature strong wind gusts Thursday
afternoon. These winds will likely remain for much of Thursday
evening. However, if they do dissipate early, LLWS will once again
be a risk, and has already been added to the TAFs for the
terminals with the highest confidence. Some high clouds may pass
over the terminals overnight, but otherwise the skies remain VFR
as winds increase again Friday morning.

Vicinity of KSFO...Winds are still onshore and breezy, just below
20 knots. Expect these winds to increase once again Thursday with
stronger gusts after 21Z, not subsiding until well into Thursday
night. Other than some high clouds passing through, VFR is
expected through the TAF period.

KSFO Bridge Approach...Similar to KSFO.

Monterey Bay...KSNS has flirted with lower cigs this morning, but
there is nothing showing up on satellite. Most of the region
should remain VFR Thursday morning. Winds will increase after 18Z
with stronger gusts possible. Winds will likely diminish after
06Z. There is a slight chance of FEW lower clouds to build up
overnight into Friday morning along the immediate coast, but
there is low confidence in it having impacts to terminals.

&& of 02:48 AM PDT Thursday...Strong northwesterly
winds with gale force gusts are forecast across the coastal waters
into the weekend. Strong and gusty winds will also prevail across
San Francisco and Monterey Bays each afternoon and evening.
Strong winds will generate steep fresh swells through the weekend
as the sea state remains wind driven.


     .Tday...GLW...Pt Arena to Pt Reyes 0-10 nm
             GLW...Pt Reyes to Pigeon Pt 0-10 nm
             GLW...Pigeon Pt to Pt Pinos 0-10 nm
             GLW...Pt Pinos to Pt Piedras Blancas 0-10 nm
             GLW...Pt Arena to Pigeon Pt 10-60 nm
             GLW...Pigeon Pt to Pt Piedras Blancas 10-60 nm
             SCA...SF Bay
             SCA...Mry Bay




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, May 17, 2022

High Temperature

107°F at Cotulla La Salle County Ap, TX

Low Temperature

25°F at Mount Washington, NH
25°F at Angel Fire Airport, NM

High Precipatation

1.75in at Wayne Municipal Ap, NE

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