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 230353

Area Forecast Discussion
National Weather Service San Francisco Bay Area
853 PM PDT Thu Apr 22 2021

.SYNOPSIS...Mainly dry and seasonable weather conditions will
persist through Friday night with periods of night and morning low
clouds. Cooling will occur on Saturday as both onshore flow and
cloud cover increase region-wide ahead of an approaching weather
system. Widespread rainfall is likely late Saturday night and
Sunday as a cold front sweeps across the region. Showers will
taper off Sunday night, but a few showers may linger into Monday.
A warming and drying trend is then expected beyond Monday.


.DISCUSSION...As of 8:50 PM PDT Thursday...Persistent marine
layer clouds and moderate onshore flow resulted in a cool day
across our region. Highs remained in the 50s in most coastal
areas, while 60s and lower 70s were observed elsewhere. Highs
today were well below normal. For example, today`s high
temperatures of 52 in Downtown San Francisco and 60 at the Sonoma
County Airport were 11 and 10 degrees below normal respectively.

The marine layer remains deep this evening and evening satellite
imagery and surface observations indicate that low clouds have
already advanced well inland, all the way to Pacheco Pass in
southeast Santa Clara County and closing in on Livermore in the
Interior East Bay. Ensemble low cloud probability forecasts have
captured the localized clearing on the Sonoma County Coast and
indicate that area may remain clear overnight, while low clouds
will persist or expand elsewhere. A shortwave ridge, currently
centered a short distance offshore, is forecast to shift eastward
overnight and the likely result will be a compression of the
marine layer by Friday morning. Thus, the expectation is that
clearing on Friday will occur more quickly across inland areas
compared to today, and afternoon clearing will be more
widespread. Consequently, high temperatures should trend at least
modestly warmer for inland areas tomorrow. Coastal locations
likely won`t see much change.

Inland temperatures are then expected to reverse course on
Saturday and cool once again as both onshore flow and clouds
increase ahead of an approaching weather system.

From Previous Discussion...A cold front will then drop into the
North Bay predawn hours on Sunday before progressing
southward/inland through the day. This will provide generally
light to occasionally moderate rainfall along the frontal boundary
with the potential for lingering rain showers in wake of the
frontal passage. Additionally, cannot rule out an isolated
thunderstorm or two over the North Bay as instability increases as
the main mid/upper level low drops into northern California.
Latest ensembles continue to indicate rainfall totals from this
system to range from 0.50"-1.00" for the North Bay hills /Santa
Cruz Mountains, 0.25"-0.50" around SF Bay/Peninsula/North Bay
valleys and 0.10"-0.25" for the interior East/South Bay valleys.
Cooler temperatures are also likely region-wide on Sunday with
daytime highs only reaching into the 50s and colder air advects

Conditions will begin to dry out late Sunday night into Monday
morning along with cooler temperatures, generally in the 40s region-
wide. While a lingering shower or two may be possible through midday
Monday, most precipitation will have exited our region to the east.
A very gradual warming trend is expected through the remainder of
next week as high pressure develops over the region.


.AVIATION...As of 05:10 PM PDT Thursday.....For the 00Z TAFs.
Weather pattern features low pressure exiting the region and being
replaced by a highly amplified ridge. The marine layer deepened
significantly under the exiting trough and has brought MVFR to
coastally influenced TAF sites through the day. Latest satellite
imagery shows a healthy upstream feed with continued deep onshore
advection of the stratus through SSW to NNE coastal gaps. Coastal
surface eddies have also complicated the forecasting of the onshore
advection of the stratus and model data is no longer aligned with
observations thus generally low to medium confidence on marine
layer coverage and timings. That said, building high pressure will
compressed the marine layer tonight into tomorrow morning and
limit the coverage of the stratus deck while lowering ceilings
closer to the IFR level, especially near the coast. Rather breezy
onshore winds of 14 to 22kt are possible through the remainder of
the evening and will gradually taper off overnight. For tomorrow
morning, a compressed yet stubborn marine layer will be present
once again along the coast and through coastal gaps. Continued
onshore flow through the day with advancing high clouds ahead of
the next storm system arriving late Saturday night.

Vicinity of KSFO...MVFR with rather breezy onshore winds this
evening. Satellite trends have been to shift the thick SF
peninsula feed southward over the terminal, thus expecting BKN-OVC
MVFR cigs to persist through the remainder of the day before
lowering down to borderline MVFR/IFR level overnight due to the
influence of the ridge. Patchy cigs will linger through midday
tomorrow as HREF ensemble suggests KSFO will once again be on the
edge of a stratus feed tomorrow.

SFO Bridge Approach...Similar to KSFO.

Monterey Bay Terminals...MVFR OVC cigs with a very robust onshore
feed through the remainder of the day. Satellite imagery does show
some thinning out of the lower levels of the marine stratus deck
early this evening but the mid/top level stratus deck continues
to push onshore unimpeded. For tonight, the influence of the ridge
will compress the marine layer and force ceilings down to the IFR
range through the middle of the night. Steady onshore flow and
upstream stratus feed will bring MVFR cigs throughout the day
tomorrow, though could see some brief midday clearing.

&& of 8:28 PM PDT Thursday...Breezy to locally gusty
northwest winds will prevail in the waters north of Point Reyes
through this evening. Northwest winds will finally subside to
become light to locally breezy across the waters tonight into
Friday as high pressure moves ashore. By Saturday morning winds
are forecast to turn southerly ahead of an approaching storm
system and weaken further. Southerly winds will then become breezy
to briefly gusty as a cold front is expected to move across the
waters during Sunday morning. Northwest winds will return in the
wake of this cold front later Sunday into next week.


     .Tngt...SCA...Pt Arena to Pigeon Pt 10-60 nm
             SCA...Pt Arena to Pt Reyes 0-10 nm
             SCA...SF Bay until 9 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 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 Wednesday, April 21, 2021

High Temperature

93°F at Phoenix Airport, AZ

Low Temperature

3°F at Mount Washington, NH
3°F at Custer County Ap, SD

High Precipatation

1.18in at Greenville Amos, ME

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