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 221322

Area Forecast Discussion
National Weather Service San Francisco Bay Area
522 AM PST Fri Nov 22 2019

.SYNOPSIS...Seasonable temperatures along with dry weather
conditions will persist through the upcoming weekend. Colder
conditions and unsettled weather will develop over the region as
early as Tuesday of next week and continue through Thanksgiving,
likely impacting holiday travel.


.DISCUSSION...As of 9:00 PM PST Thursday...Temperatures were very
isothermal across our region today, with nearly all locations
reporting high temperatures in the 60s. Light southerly flow
brought increased low level moisture into our area and patchy low
clouds persist this evening, mainly near Monterey Bay.

No significant changes are anticipated through Friday. Light
southerly flow will continue through the morning hours, with the
flow forecast to turn to the east and northeast by late
afternoon, resulting in low level drying. This drying probably
won`t occur early enough in the day to have much impact on
temperatures, and tomorrow`s highs will likely be similar to
today, or perhaps a few degrees warmer.

Light offshore flow will persist into the weekend while the
airmass warms over our area in response to an upper ridge building
across northern California. These developments will result in a
modest daytime warming trend through the weekend, with lower 70s
becoming more common. Drier air and mostly clear skies will also
mean cooler nighttime temperatures, particularly in the valleys
where overnight lows will drop into the 30s. Patchy early morning
valley frost is likely through the weekend.

A pattern change is expected to get underway early next week. On
Monday the upper ridge is forecast to shift offshore while a
shortwave trough skirts by our area to the northeast. Passage of
this shortwave trough will trigger increasing northwest winds
across our area on Monday afternoon. Winds are then expected to
veer to the north in the hills on Monday night and become locally
gusty. The brief period of offshore winds in the hills on Monday
night is not expected to be as strong as the most recent offshore
wind event. However, humidity will be low and fuels will still be
very dry. Thus, fire weather concerns will be somewhat elevated
from late Monday through early Tuesday.

Models continue to indicate widespread rainfall across our area by
late Tuesday. A system dropping southeast from the Gulf of Alaska
is forecast to tap into moisture from another system north of
Hawaii. Models agree in spreading precipitation from northwest to
southeast across our area on Tuesday afternoon and evening. Rain
rates are expected to be moderate, and perhaps even briefly heavy
late on Tuesday, as a robust cold front sweeps across our area. A
cold upper trough is then forecast to settle over California
through at least Thanksgiving, and possibly into Friday as well,
maintaining a cool and unsettled weather pattern. Preliminary
precipitation totals from Tuesday through Friday range from
0.25-0.75" and locally up to an inch. Across the northern part of
our area, the bulk of the precipitation is expected to fall with
the cold front on Tuesday, with not much more thereafter. In
southern areas, precipitation looks to be most widespread late on
Tuesday, but with scattered showers then adding to precipitation
totals through through Thanksgiving. Next week`s system will be
cold with 850 mb temperatures forecast to drop as low as minus 3
deg C by Wednesday night. The coldest air will arrive after most
precipitation falls, but we could see snowfall accumulation on our
higher mountains next week, particularly on the Santa Lucias in
Monterey County. Highs next next Wednesday and Thursday are
forecast to be held in the 50s in most areas, with colder
temperatures expected in the hills.

&& of 5:20 AM PST Friday...Light easterly wind over
the Bay Area from the low pressure system over the southwest.
Winds will switch to a light onshore this afternoon as the
influence of the low diminishes. Low clouds along the coast
skirting the Peninsula and the MRY Bay Area and the Salinas Valley
this morning. Models indicate less low level moisture tonight and
Saturday morning even though the flow is onshore so VFR expected

Vicinity of KSFO...SCT-BKN clouds through 17Z with bases around
2000 ft. Light easterly wind this morning becoming onshore to 10
kt late in the day.

SFO Bridge Approach...Similar to KSFO.

Monterey Bay Terminals...Clouds in the Salinas Valley are lower
than the coastal clouds. MVFR at MRY but IFR at SNS with vsbys
down to 3-5 miles. Clearing after 16Z.

&& of 05:20 AM PST Friday...Low pressure over the
southwest will move east. Easterly winds will switch to north to
northwest tonight. A long-period northwest swell will arrive today
and continue through the weekend. Winds will increase late Sunday
or Monday as a strong storm approaches.


     .Tday...SCA...Pt Arena to Pigeon Pt 10-60 nm from 9 AM
             SCA...Pt Arena to Pt Reyes 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 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 Thursday, November 21, 2019

High Temperature

88°F at Roosevelt Roads Nas, PU
88°F at Alice/Intl, TX

Low Temperature

-2°F at Hallock, MN
-2°F at Yellowstone (ramos), WY

High Precipatation

1.33in at Walnut Ridge (awos), AR

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