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 Friday, 26-Jun-2020 8:09 AM

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 060044

Area Forecast Discussion
National Weather Service San Francisco Bay Area
544 PM PDT Sun Jul 5 2020

.SYNOPSIS...Temperatures are warm and conditions are dry with breezy
onshore winds. Monday afternoon high temperatures will be slightly
cooler as onshore flow increases with a likely return of the
marine layer for the immediate coastline. Temperatures are
expected to be similar day- to- day midweek before warming likely
late in the week and into next weekend.

&& of 01:42 PM PDT Sunday...Temperatures Sunday are
running similar to yesterday given the high pressure still located
over the Bay Area region. A few observations in the North Bay are
slightly warmer, but generally speaking the pattern and conditions
are consistent to yesterday. Winds remain on onshore and have
started to increase this afternoon. Despite the onshore direction,
coupled with the dry conditions over inland areas, the winds could
make fire containment challenging. However, as an update to the
previous discussion, it appears that the Park Fire is now improved
to 50% contained and crews and stopped its forward progress. Sky
conditions remain clear as the nearest bit of cloud cover is over
100 miles off the California coast.

The pattern changes slightly beginning overnight tonight, being
driven by an upper level trough currently northwest of the state of
Washington. As it moves down the Pacific coast tonight, expect a
deeper marine layer and a return of low clouds around the Monterey
Peninsula. Winds will remain onshore but increase overnight as well,
reaching farther inland. These cooler northwesterly winds will drive
5-7 degrees cooler temperatures on Monday, with isolated locations
seeing a 10 degree cool down.

As the trough moves through, these cooler temperatures in the 70s
and 80s will remain through the midweek. Winds will remain onshore
and be breezy. In a return to the weather pattern from last week,
high pressure to the southeast will once again build by the end of
the week. The return of higher pressure puts a warming trend in the
forecast for the weekend. Drier conditions prevail with no
precipitation forecast.

&& of 5:44 PM PDT Sunday...for 00Z TAFS. It`s VFR, a
few patches of coastal stratus and fog may redevelop tonight and
Monday morning. At this time similar to yesterday a dry mid-latitude
flow continues to prevent fog and stratus development. 24 hr trends
in temperatures and dew point temperatures support high confidence
VFR forecast for the evening and VFR continuing for the Bay Area
tonight and Monday morning due to sufficient northerly pressure
gradient and winds. Lower level cooling and weakening of the flat
500 mb height ridge is forecast tonight, Monday and Monday night
which will likely weaken the marine layer temperature inversion
at least a little bit and increase the marine layer depth.

The marine layer depth varies from 1,200 to 1,600 feet. A surface
high pressure ridge over northern California is producing a 7.4
mb ACV-SFO pressure gradient and 2.2 mb UKI-STS gradient. The 18z
NAM is under-forecasting the ACV-SFO pressure gradient by almost 2
mb which is quite likely resulting in stronger northwest winds
over the coast than modeled. Also, visible imagery shows clear
conditions over the coastal waters thus turbulent mixing and
diffusion of much drier air at or above the marine temperature
inversion continues to enter the boundary layer preventing marine
fog and stratus from developing. On the flip side both UKI-STS and
SFO-SMX gradients are over-forecast by the 18z NAM, although as
mentioned the UKI-STS gradient is 2.2 mb, the gradient now
strengthening closer to 18z NAM forecasts; the northerly gradient
and winds is causing downsloping warming and drying over the North
Bay, e.g. STS has sustained NW wind near 15 knots.

Not much let up in the strength of the aforementioned pressure
gradients is forecast tonight and Monday morning.

Vicinity of KSFO...VFR. 5 minute obs showing a stronger west wind
with gusts up over 30 knots likely into the evening close to airport
weather warning criteria for winds, criteria is 35 knots or higher
sustained or gusts. Looks good for VFR through the taf period given
overall conditions mainly due to a strengthening northerly ACV-SFO
pressure gradient, currently 7.4 mb. Similarly, a gusty west wind is
forecast Monday and Tuesday afternoons and evenings per statistical

SFO Bridge Approach...Similar to KSFO.

Monterey Bay Terminals...VFR. Not a clear cut VFR forecast for
tonight with strengthening northerly gradients, though at least at
the onset for the evening with plenty of mixing of drier air into
the boundary layer should keep VFR going. Later tonight and Monday
morning there`s the possibility of patchy IFR in fog and stratus
briefly forming until diurnal mixing mixes out any fog and/or stratus
by late Monday morning.

&& of 01:42 PM PDT Sunday...A 1030 mb high centered 1000
miles west of Cape Mendocino will move closer to the coast through
Monday. As a result, gusty  northwest winds will continue over the
coastal waters into  midweek. Gale force gusts are possible along
the Big Sur coast  Monday afternoon and evening. Strong northwest
winds will generate steep fresh swell resulting in hazardous seas
conditions. A long- period southerly swell will continue through
Monday before swell  periods begin to subside.


     .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 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
             SCA...Mry 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 Saturday, July 4, 2020

High Temperature

112°F at Palm Springs Asos, CA

Low Temperature

35°F at Bridgeport Sonora Junction, CA
35°F at Stanley Ranger Station, ID

High Precipatation

19.20in at Clovis Cannon Afb, NM

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.03 - 26-Jun-2020 see history).