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 061157

Area Forecast Discussion
National Weather Service San Francisco Bay Area
457 AM PDT Wed Jul 6 2022

.SYNOPSIS...Without a well defined marine layer, a mix of low and
mid level clouds continue today. Morning coastal drizzle may be
possible in areas with lower clouds. A gradual warming and drying
trend begins by midweek, however, below normal temperatures
persist today through Friday for the afternoon highs. By Saturday,
the region warms more becoming near to slightly above normal
conditions through Monday.

&& of 04:07 AM PDT Wednesday...We`ve got another
morning of mixed clouds. Looking at the Fort Ord and Bodega Bay
profilers, we don`t see a well defined marine layer which is
allowing low and mid level clouds to move farther inland as
opposed to a defined and compressed marine layer that limits the
inland intrusion of coastal stratus. If you`re closer to the
coast and under low marine stratus, you could see a bit of drizzle
again this morning.

Once again, not expecting any major temperature swings for this
afternoon`s highs. For the past two days, max temps have generally been
within 1-3 degrees of each other, if not the same, for several of
our observation sites. The upper level low offshore from the
Pacific NW continues to linger and with not much change in the
atmospheric environment, expect similar conditions today as we`ve
been seeing: below normal highs with mid 60s to mid 70s closer to
the coast and mid 70s to mid 80s inland. We`ll see breezy
conditions this afternoon into evening, also similar to

Warming, especially across the interior, will become more
noticeable as we get towards the end of the week and into the
weekend. The airmass aloft will gradually warm as high pressure
strengthens over the desert SW. 850 mb temps will increase towards
18 to 21 degrees C Friday and Saturday along with 500 mb heights
increasing to 588 to 594 dm. The warmest days in the near term are
forecast to occur on Sunday and Monday: coastal and bay shore
highs will be in the upper 60s to low 80s while inland areas range
mid 80s to mid 90s...a few upper 90s in the far interior.

What should be noted with this warming trend is that we`re not
expecting afternoon highs to be WELL above normal. In fact, 5-8
degrees above normal is probably the most we`ll see which is not
as significant as the 15 to 20 degrees above normal we saw in the
June heat events. Heat Risk continues to be at Low Risk for much
of our CWA with some Moderate Risk mixed in for Sunday and Monday
across the interior. Even the ECMWF EFI (extreme forecast index)
is only showing about 50 to 60 percent for max temp on Monday
indicating it`s not an extreme event.

For the extended, it looks as though our region will be in between
the center of the high pressure over the desert SW and the
lingering trough over Canada & the PacNW. The trough seems to dig
a little southward on Tuesday which would bring slight cooling,
but then the high pressure begins to dominate again. Looking
ahead at the ECMWF and GFS ensembles...they both show the peak
warm up for Sunday and Monday followed by that slight cooling on
Tuesday with warming again for the rest of next week. However,
once again, we`re not yet seeing a strong heat signal as peak
temps will likely stay in the 90s across the interior and not
reach triple digits.

&& of 4:44 AM PDT Wednesday...For the 12Z TAFs.
Expect varying cloud heights to continue with mostly under the
MVFR and IFR criteria lasting into the mid to late morning with
light to moderate winds. Widespread VFR returns with mid clouds in
the late morning and early afternoon with winds becoming moderate
to breezy. Low clouds will be slower to fill the bays and move
inland tonight, offering another batch of MVFR CIGs and patchy

Vicinity of KSFO...MVFR with light winds through the late morning
with some intermittent times of IFR. Expect VFR for the afternoon
with moderate to breezy westerly winds peaking around 15 kts with 22
kt gusts. These winds will ease into the night. Lower clouds look to
begin fill around the SF Bay in the late evening, leading to another
night of MVFR.

KSFO Bridge Approach...Similar to SFO.

Monterey Bay...MVFR with moments of IFR and mist through the late
morning. Winds will be light but become more moderate and breezy for
the afternoon. MVFR CIGs are expected to return for Wednesday
evening as winds begin to reduce and stratus moves inland.

&& of 04:07 AM PDT Wednesday...Generally light winds
will prevail over the coastal waters tonight and Wednesday, aside
from increases off the Santa Cruz County and Big Sur coasts during
the afternoon. Somewhat breezier conditions will then develop
generally, while winds increase more substantially in jets off the
aforementioned coastal stretches, and subsequently off the coast
of Sonoma County as well. These will be accompanied by
increasingly steep, short period wind-waves with seas becoming
hazardous for smaller craft.


     .Tday...SCA...Mry Bay from 3 PM



MARINE: Murdock

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 Monday, July 4, 2022

High Temperature

106°F at Cotulla La Salle County Ap, TX
106°F at Hill City Municipal Ap, KS
106°F at Cheyenne County Municipal Airport, KS

Low Temperature

7°F at Dixon Airport, WY

High Precipatation

3.20in at Marianna Municipal Ap, FL

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