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 231855

Area Forecast Discussion
National Weather Service San Francisco Bay Area
1155 AM PDT Fri Jul 23 2021

.SYNOPSIS...The weather pattern remains consistent and seasonable
into Saturday with hot weather inland and mild temperatures near the
coast and bays. The marine layer is expected to remain fairly
shallow. Monsoonal moisture rotating out of Arizona will spread some
clouds across the Central Coast Sunday reaching the Bay Area by
Monday. Long range trends remain seasonably warm and dry through the
end of the month.

&& of 02:30 AM PDT Friday...The majority of the
lower 48 states are under the influence of a 594dm 500mb ridge
expanding coast to coast while the more progressive jet stream
remains roughly aligned with the Canadian border. Overnight GOES16
satellite imagery (due to GOES17 outage) depicts a concentration
of monsoonal moisture primarily focused over the Desert Southwest,
Great Basin, and portions of southeastern California. The marine
layer has compressed to below 1200 feet and is struggling to expand
beyond the Monterey Bay area, with little to no marine layer being
detected at the Bodega Bay profiler.

Models are in general agreement that this high pressure system
will expand to encompass our forecast beginning today and ensemble
clusters analysis shows good probability that the high pressure
system will remain in place through at least the next week. Of the
5 clusters, only 1 that is more heavily weighted towards the
Canadian model suggests troughing along our immediate coast by day
7 (Saturday Jul 31). Thus, there is a favorable chance that high
pressure influences could remain in place through the end of the

Consequently, the marine layer is anticipated to remain compressed
at or below 1000 feet, onshore flow will be subdued except through
coastal gaps late day due to differential temperature gradients,
and the interior will warm to become a few to several degrees
above seasonable normals through the next several days. Our
hottest interior locations will rise to the mid 90s to low 100s,
while inland valley communities will be in the mid 80s to low 90s,
and nearshore communities will hover closer to the mid 60s to low

One feature to watch will be an localized low pressure system
currently developing along the TX/NM border on the SE periphery of
the broad monsoonal ridge. This smaller low pressure disturbance
is anticipated to remain in a clockwise orbit around the stronger
high pressure system and will eventually rotate into Southern
California early next week where it will merge with another
offshore low pressure system. Next, both ensembles and consecutive
deterministic runs of the GFS/EURO suggest this inverted trough
will lift northward from Southern California into our area in the
late Monday to Tuesday timeframe. This corresponds with another
push of deeper elevated monsoonal and instability and a timeframe
to watch in terms of potential elevated convection. It will be
interesting to see how this plays out as it is not typical for us
to see an accompanying mid to upper level low supporting
monsoonal moisture this time of year. For now, the main threat
will be farther to the east over the Sierra Nevada, but we will
continue to watch how forecast data trends in the coming days as
the convective models have a chance to analyze the threat. That
said, we are currently carrying a roughly 10% chance of seeing
some weak elevated convection capable of producing high based
showers or perhaps a thunderstorms early next week. Prior to that,
however, we will see an increase in mid to high level clouds as
this monsoonal moisture begins to arrive from the south. This has
already begun to occur with overnight satellite imagery showing a
few to scattered high clouds at around 15000-20000 feet. This high
based moisture may become thick enough at times to drop
temperatures by a degree or two between the next several days, so
interior temperatures may ebb and flow depending on the
humidity/cloud cover aloft.

&& of 11:55 AM PDT Friday...For the 18z TAFs. Latest
coastal profilers are picking up on a 1200-1900ft marine layer
with a shallower layer along the Bay Area terminals and a deeper
layer over the Monterey Bay interface. As a result, VFR is being
observed all across SF Bay area terminals with clearing across the
Monterey Bay terminals late this morning. Will also observe some
high-based clouds (>20K ft) this afternoon as faint monsoonal
moisture rolls in to the region. Hi-res models and HREF ensemble
members are trending towards some patchy stratus resurgence
starting around 3Z over the Central Coast and 9Z in the Bay Area.
Given the trends, have adjusted the timing of MVFR/IFR cigs for
the coastal terminals, SFO/OAK, and the North Bay all accordingly.
Should also note that given the current synoptic setup, will
observe calm to light winds regionwide with only occasional breezy
spots along the gaps and passes. MVFR/IFR cigs will then lift by
16-17Z as the rinse and repeat pattern continues through the end
of this latest TAF package.

Vicinity of KSFO... Stratus has rapidly burned off this morning as
dry air mixes down to the surface. Do still have some high-based
clouds on the TAF for this afternoon given the monsoonal signature
but will remain VFR through the evening. Winds will also remain
light through the TAF period with the exception of this afternoon
where the Gap influence will allow for breezy conditions
(15-20kts) through sunset.Bulk of the MVFR/IFR cigs are trending
to remain locked over the East Bay due to the trajectory of the
moisture return along the Golden Gate but have added a TEMPO group
to SFO for MVFR/IFR cigs given the slight chance for some of the
stratus deck to track south should winds become more NNW
overnight. Any low cigs that do develop overnight will rapidly
burn off by 16-17Z.

KSFO Bridge Approach...Approach remains clear through the period.

Monterey Bay...Prevailing IFR and local LIFR with areas of mist
are exiting the Monterey Peninsula this morning as the stratus
retreats across the Bay. Marine profile is still running close to
2000 ft today so have adjusted MRY/SNS TAFs to account for breezy
conditions this afternoon (10-15kts) along with an early return of
the marine stratus (3-5Z). Will then observe calm to light winds
overnight along with MVFR/IFR cigs that will sit over the
terminals until 16-17Z.

&& of 11:13 AM PDT Friday...Northwesterly wind waves at
about 8 to 9 seconds continue to  drive the sea state. Winds will
slowly diminish throughout the  day; however, strong wind gusts
can still be expected over the  northern outer waters and along
the coast north of Point Reyes. Some strong gusts will also funnel
through the Golden Gate into San Francisco Bay this afternoon and
early evening. These strong  gusts will generate steep waves
resulting in hazardous seas  conditions, particularly for smaller
vessels. Lighter winds are expected this weekend, along with weak
southerly swell.


     .Tday...SCA...Pt Arena to Pigeon Pt 10-60 nm
             SCA...Pt Arena to Pt Reyes 0-10 nm
             SCA...SF Bay from 3 PM



MARINE: Lorber

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 Thursday, July 22, 2021

High Temperature

110°F at Needles, CA
110°F at Blythe Asos, CA
110°F at Imperial County Ap, CA

Low Temperature

34°F at Meacham, OR

High Precipatation

2.19in at Jacksonville Nas, 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).