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, 10-Feb-2019 7:10 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 230535

Area Forecast Discussion
National Weather Service San Francisco Bay Area
1035 PM PDT Mon Jul 22 2019

.SYNOPSIS...A gradual warming trend will continue through midweek,
especially across the interior. This will lead to seasonably warm
temperatures inland while coastal areas remain mild under the
influence of a shallow marine layer and persistent onshore flow.
No significant changes are expected through the end of the week or
into next weekend, except the possibility of even warmer inland
temperatures during the weekend.


.DISCUSSION...As of 9:00 PM PDT Monday...The warming trend that
got underway yesterday became more widespread today, with nearly
all locations having warmer temps today than yesterday. Areas very
close to the ocean saw temperatures near persistence. There was a
44 degree difference between the coolest and warmest high
temperature in our forecast area today: from 58 at Ocean Beach in
San Francisco to 102 at Pinnacles National Park.

A shallow marine layer is resulting in patchy dense fog in coastal
areas this evening. A weather spotter recently reported visibility
of less than a quarter mile just to the east of Santa Cruz.
Patchy dense fog will likely continue to be an issue during the
night and morning hours through the rest of the week.

The upper level ridge centered near the Four Corners will continue
to be the dominant weather feature across the southwestern third
of the nation for the remainder of the week and into the upcoming
weekend. However, the ridge is expected to weaken slightly (and
briefly) over northern California tomorrow as as an upper trough,
currently centered offshore along 135W, lifts to the northeast
and into the Pacific Northwest. Thus, the warming trend will
likely stall tomorrow, and we may even see a few degrees of
cooling in some locations.

The warming trend will recommence on Wednesday as the ridge
strengthens once again over northern California. Most warming will
continue to be across inland areas where Wednesday`s highs could
be as much as 10 degrees warmer than normal. A shallow marine
layer will persist, as will onshore flow, and so areas close to
the ocean will likely experience only a few degrees of warming.

Most model guidance indicate that Wednesday will be the warmest
day of the work week and that temperatures will fall back slightly
for Thursday and Friday, but still remain very warm inland. We may
also see some mid and upper level cloud cover from late Wednesday
through early Friday as monsoon moisture rotating around the Four
Corners High tracks across California. Models forecast a very weak
shortwave trough rotating around the ridge, coincident with the
mid and upper level moisture, and this will be something to keep
an eye on for potential high-based showers and/or thunderstorms,
mainly for Thursday night.

The longer range models, including the ensemble mean from both the
ECMWF and GFS, agree that the center of the upper ridge will
shift westward and over southern California during the upcoming
weekend. This would likely result in renewed warming on Saturday
and Sunday. The ECMWF forecasts more robust weekend warming
compared to the GFS. Our current forecast more closely follows the
GFS. Projected Heat Impacts through the remainder of the week and
into the weekend, based on the current forecast, are mostly in
the low to moderate categories. However, heat impacts could
ratchet up into the high category for some inland areas next
weekend if the ECMWF forecast is correct.

&& of 10:35 PM PDT Monday...The marine layer remains
steady at 1200 ft this evening with status only covering the coast
from Santa Cruz south. Anticipate a return of stratus overnight
to KMRY and KSNS with all other terminals remaining clear.
Moderate onshore flow will continue to ease becoming light and
locally variable overnight.

Vicinity of KSFO...VFR conditions will prevail through the
forecast period. Onshore flow will continue to ease becoming
light around 5 to 10 kt overnight.

SFO Bridge Approach...Similar to KSFO.

Monterey Bay Terminals...LIFR cigs will prevail through tonight.
Clearing is anticipated around 17z Tuesday morning. Light and
locally variable winds expected overnight.

&& of 8:58 PM PDT Monday...Breezy northwest winds will
persist through Tuesday across the coastal waters. Winds will
increase becoming gusty Tuesday night and Wednesday as high
pressure builds into the Pacific Northwest and northern
California. Light southerly swell coupled with short period wind
waves will continue through the week.


     .Tngt...SCA...Pt Arena to Pt Reyes 0-10 nm
             SCA...Pt Reyes to Pigeon Pt 0-10 nm
             SCA...Pt Arena to Pigeon Pt 10-60 nm
             SCA...Pigeon Pt to Pt Piedras Blancas 10-60 nm
             SCA...Pt Pinos to Pt Piedras Blancas 0-10 nm from 3 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 USA Extremes

This script was originated by Michael of and has been rewritten to use the NWS Climate Prediction Center's One Day Old Daily Data Summary text file for the USA. 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 four variables:

$usahigh - contains the text of the high temperature station(s) (value and station name from the NWS)
$usalow - contains the text of the low temperature station(s) (value and station name from the NWS)
$usaprecip - contains the text of the high precipitation station(s) (value and station name from the NWS)
$reportDate - contains the text of the date for the report (default format is 'Dayname, Month day, Year')

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 courtsey of <a href=\"";
print "";
print "\">NWS-CPC</a></small></p>\n";


which produces this result (with live data):

USA Extremes for Sunday, July 21, 2019

High Temperature

113°F at Needles Airport, CA

Low Temperature

31°F at Stanley Ranger Stn, ID

High Precipatation

3.25in at Lincoln/Muni, NE

Data courtsey 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.

// Site to Parse
$url2 = "";
// Name of cache file  --  This file must be set to CHMOD-666
$cacheFileDir = './'; // directory to store cache file in.
$cacheFile2 = "usaextremesCache4.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
$rUOM = 'in';     // or ='' for no rain unit display
$ignoreStations = array('99NRB'); // Station numbers to ignore, Array of station numbers

NWS CPC One Day Extremes PHP script Download (4.03e - 09-Feb-2019 see history).