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 152208

Area Forecast Discussion
National Weather Service San Francisco Bay Area
208 PM PST Sat Dec 15 2018

.SYNOPSIS...A weak frontal system will remain over the North Bay
today, producing scattered light showers. A stronger and wetter
system is forecast to impact the entire region Sunday and Sunday
night, with widespread moderate rain. Brief heavy rain is
possible Sunday afternoon and evening. In addition, gusty south
winds are likely Sunday and Sunday evening, mainly near the coast
and in the hills. Showers will taper off by late Sunday night and
end by midday Monday. A very large wave train arrives Late Sunday
into Monday. Dry and mild weather is forecast from Monday
afternoon through much of next week.

&& of 02:08 PM PST Saturday...Satellite imagery
reveals the synoptic pattern, with a large, deep trough centered
at about 50N 145W, providing us with high clouds streaming
overhead. This trough has plenty of cold air at its core with a
large area of convective clouds behind a cold front. Warm
advection continues in our region with winds veering with height.
A front which stalled over the Bay Area last night has lifted into
the North Bay, where scattered showers continue to produce light
rainfall amounts. These showers have slowly drifted to the
northwest and measurable rainfall in the past hour was confined to
the northwestern portion of Sonoma County. Showers will continue
to decrease this afternoon but will increase late this evening
across the North Bay as the deep upper level trough approaches.
Temperatures today have generally warmed into the upper 50s to mid
60s, with the warmest locations in the South Bay.

The upper trough off the coast will be our main weather maker for
the region Saturday night through Monday. As the trough
approaches, prefrontal warm advection precipitation, aided by
orographic lifting, will increase across the North Bay late
tonight through Sunday morning. A potent cold front will approach
the North Bay by late afternoon Sunday, pushing southeast and
reaching the SF Bay by mid evening and the Monterey Bay by early
Monday morning. A region of high PWAT (1.1-1.3") will push
through ahead of the cold front. Combined with strong
southwesterly flow, integrated vapor transport will rise into the
500-700 kg/m/s range, categorizing this event as a moderate
strength atmospheric river. Rain will intensify along and just
ahead of the cold front, with a brief period of heavy rain likely
along the front. Winds at the surface will become breezy to gusty
out of the south ahead of the front, especially along the coast
and in the higher terrain, but are not expected to reach advisory
criteria. As the front moves through, winds will quickly decrease
in strength and precipitation will taper off. The front and
precipitation are expected to be exiting Monterey and San Benito
Counties early Monday morning, with drying behind the front. Rainfall
totals will range from 1-3 inches across the North Bay and
coastal mountains and 0.5 to 1.25 inches in the populated areas
from the Golden Gate south. Some of the higher terrain of the
North Bay could see locally greater than 3 inches as moderate rain
falls most of the day Sunday. Finally, isolated thunderstorms are
possible along and behind the cold front as cooler air aloft
moves in with the trough creating instability.

Additionally, this system will be accompanied by a powerful swell
and large breaking waves Sunday through late Monday. This could
lead to minor coastal flooding in susceptible areas. See the
beaches section below for more details on the large impacts
expected along our coastline.

Following the trough, precipitation will end across all areas by
Monday afternoon. A ridge will then try to build into the region
starting Monday night. A plume of high PWAT will push to our
north into far northern CA and OR, but may sag just far enough
south for some light showers across our northern areas Tuesday and
Wednesday. 850 mb temps will warm to 12-14C on Wednesday and
Thursday under the ridge, and highs will respond by warming into
the low 60s to near 70 areawide. Lows will cool slightly as
conditions dry out, but should remain in the 40s to low 50s. A
system approaches the area on Thursday night and Friday, but looks
to fall apart as it does and precipitation chances remain low.
Temperatures will cool slightly but will remain mild through the

&& of 09:45 AM PST Saturday...Mainly VFR conditions
persist over the terminals today excepted for KSTS where low
clouds, rain and reduced visibility will persist in response to a
stalled frontal boundary. Southerly winds will generally be light
yet may increase a bit this afternoon through early evening.
Conditions will worsen region-wide during the day Sunday first
over the San Francisco Bay Area as a more potent frontal system
approaches the region.

Vicinity of KSFO...VFR conditions likely through the day. South-
southeasterly winds will increase to around 10 knots after 21Z.
Winds diminish slightly overnight but increase again and become
gusty Sunday morning ahead of the approaching cold front. More
widespread rain expected by midday Sunday.

SFO Bridge Approach...Similar to KSFO.

Monterey Bay Terminals...VFR. Southeasterly winds, increasing a
bit late this morning and into the afternoon in the northern
Salinas Valley. Winds briefly turn onshore this afternoon before
becoming southeasterly again tonight and into Sunday morning.

&& of 09:45 AM PST Saturday...A potent storm system
has resulted in a very large, long period west to northwest swell
train aimed at the California coast. Very long period forerunners
will arrive Sunday morning bringing a significantly increased risk
of rip currents and sneakers waves to the coast. The largest
waves are then forecast to arrive Sunday night through Monday
morning, with peak swells of 17 to 21 ft at 19 to 21 seconds.
Large breaking waves of 25 to 40 ft will be possible at west and
northwest facing locations, with breakers up to or exceeding 50 ft
at favored break points along the coast. A High Surf Warning
remains in effect from 9 AM Sunday through 9 PM Monday along the
entire coastline.

&& of 09:45 AM PST Saturday...A moderate west to
northwest swell will build and result in hazardous sea conditions
through the day. South to southeasterly winds will increase
tonight into Sunday morning ahead of a Pacific storm system that
will bring widespread rain and the potential for thunderstorms. An
even larger, more powerful long period west to northwest swell,
the largest seen this season so far, will move in Sunday afternoon
through Monday.


     .Tngt...SCA...Pt Arena to Pt Reyes 0-10 nm
             SCA...Pt Reyes to Pigeon Pt 0-10 nm
             SCA...Pigeon Pt to Pt Pinos 0-10 nm
             SCA...Pt Pinos to Pt Piedras Blancas 0-10 nm
             SCA...Pt Arena to Pigeon Pt 10-60 nm
             SCA...Pigeon Pt to Pt Piedras Blancas 10-60 nm
             SCA...Rough Bar Advisory for SF Bar




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 Friday, December 14, 2018

High Temperature

87°F at Marathon Airport, FL

Low Temperature

-14°F at Gunnison Co (awos), CO

High Precipatation

5.29in at Ocala Muni (awos), FL

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