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.

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, 27-Feb-2018 1:47 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 200547

Area Forecast Discussion
National Weather Service San Francisco Bay Area
1047 PM PDT Mon Mar 19 2018

.SYNOPSIS...A storm system will produce widespread rainfall
across our region from Tuesday through Thursday. Periods of heavy
rain are possible, mainly along the Big Sur Coast, as well as locally
strong southerly winds and thunderstorms. Showers will linger
into Friday and Saturday before dry conditions return on Sunday.


.DISCUSSION...As of 8:55 PM PDT Monday...More sun today, along
with a warming airmass under a shortwave ridge, allowed high
temperatures to climb into the 60s, which are close seasonal
averages. Some locations in the Salinas Valley reached into the
lower 70s.

Evening satellite shows that an upper low continues to spin well
offshore, about 1100 miles west of San Francisco. A plume of
subtropical moisture flowing south of this low contains
precipitable water values of between 1.5 and 2.0 inches. This
moisture plume is taking aim at central California just as models
have been forecasting. KMUX radar is already picking up some weak
returns offshore, but this is mostly mid level moisture. The deep
moisture plume is due to arrive along the Big Sur coast by sunrise
Tuesday and then spread north and east across most of the rest of
our area by Tuesday afternoon. Rain may become heavy along the
Big Sur Coast and in the Santa Lucia Mountains by Tuesday
afternoon as warm advection cranks up. Elsewhere, rain rates
tomorrow are expected to be mostly light to moderate. Southerly
winds will increase by Tuesday afternoon and evening, particularly
along the Big Sur Coast and across the higher hills of Monterey
and San Benito Counties. Gusts up to 35 mph are possible in these

The models generally agree that there will be a decrease in
precipitation from late Tuesday evening through much of Wednesday.
Periods of rain will continue during this time, but rainfall
won`t be as widespread or intense. Then, by late Wednesday the
upper low will begin to approach the coast, ramping up dynamic
forcing as well as orographic lift as southerly winds increase.
Precipitation rates could again be heavy at times from late
Wednesday through early Thursday. Again, the heaviest rain is
expected to be in the Santa Lucias and Big Sur region, but
localized heavy rain could occur elsewhere too. Strongest
southerly winds this week are expected from late Wednesday
afternoon through mid morning on Thursday when local gusts of up
to 50 mph are possible along the coast and in the hills.

Thunderstorms are possible starting late Wednesday afternoon and
early evening, mainly across the eastern portion of our forecast
area where the NAM forecasts surface CAPE values as high as 400
J/kg. Thunderstorm potential will also exist on Thursday as the
cold front sweeps through, but it looks like the most unstable
airmass will be located over the Central Valley on Thursday.

Rainfall totals from Tuesday through Thursday are forecast to
range from 0.75-1.50" for most urban areas...1-3 inches for Bay
Area mountains (except locally up to 4 inches or more in the Santa
Cruz Mountains if the moisture plume shifts slightly farther
north)...and 3 to 5 inches in the Santa Lucia Mountains with
locally up to 8 or even 10 inches on some of the higher southwest-
facing slopes or the Santa Lucias. Thus, the highest potential for
small stream flooding and mudslides/debris flows will be along
the Big Sur coast.

Showers are expected to taper off by late Thursday and mostly end
by Thursday night. But then a system approaching from the north
will bring renewed shower chances from late Friday through early
Saturday. Dry weather is expected to return to all areas by
Sunday. Longer range models indicate most of next week will remain


.AVIATION...As of 10:30 PM PDT Monday...Conditions will remain
VFR through tonight with high clouds. Models continue to trend
slower with the arrival of deeper moisture so timing of rain and
lower cigs has been pushed back to 21Z for the MRY Bay Area and
01-02Z for the SFO Bay Area. A break in the action is expected
later Tuesday evening. Winds over land remain light during the
day then increase in the evening as an upper level shortwave

Vicinity of KSFO...VFR. Cigs lower after 18Z but bases still
above 5-6 thousand feet. Cigs lowering to around 4000 ft with
light rain after 01Z. Southeast winds around 10 kt.

SFO Bridge Approach...Similar to KSFO.

Monterey Bay Terminals...VFR. Light rain after 20Z with cigs
lowering to 4000 ft. Winds becoming se and increasing to 15-18 kt
with gusts to 22-24 kt in the Salinas Valley.

&& of 10:40 PM PDT Monday...A 998 mb low centered 1100
miles west of Monterey will move east  tonight and Tuesday then
turn northeast on Wednesday. This will  bring increasing southeast
winds to the central waters tonight and the northern waters
Tuesday. As the upper level trough passes thrugh on Thursday there
will be a slight chance of afternoon thunderstorms. Large mixed
swells will develop Tuesday through Thursday resulting in rough
and erratic seas.






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, March 18, 2018

High Temperature

96°F at Laredo/Intl, TX

Low Temperature

-22°F at Saranac Lake/Adirondac, NY

High Precipatation

2.53in at Henderson City, KY

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.03 - 13-Oct-2016 see history).