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 231638

Area Forecast Discussion
National Weather Service San Francisco Bay Area
838 AM PST Sat Jan 23 2021

.SYNOPSIS...Expect dry and seasonably cool conditions today.
Widespread light to moderate rainfall is expected Sunday afternoon
and evening, along with colder temperatures and lowering snow
levels. Gusty northwest winds will follow Sunday night into
Monday. A much stronger and wetter system will then impact the
region with potentially heavy rain and strong winds from late
Tuesday through Thursday. Additional rainfall is possible by next

&& of 08:38 AM PST Saturday...The last few rain
chances from this morning have dissipated with skies beginning to
clear along the coastal regions. Freezing levels were also low
enough overnight to result in some minor snow accumulations over
the highest peaks of Monterey county. Webcams on Palo Escrito show
a dusting to possibly one inch of snow. Satellite imagery still
shows cloud cover over more interior areas and a few pockets of
fog are lingering in the North Bay. Santa Rosa is currently
showing fog limiting visibility to a mile and a quarter and Napa
is showing even thicker fog at just a quarter mile visibility.
This fog looks to clear into the late morning, with most areas set
for a sunny afternoon. Temperatures today are forecasted to be
seasonably cool with highs again peaking in the mid 50s for most.
Much of the forecast remains on track with the next rain chances
coming on Sunday and heavier rainfall expected in the middle of
next week.


.PREV DISCUSSION...As of 3:55 AM PST Saturday...KMUX radar currently
showing scattered showers over Monterey County as well as our
coastal waters south of the Golden Gate. These showers are
associated with one final shortwave trough dropping south along
the Central Coast. Based on recent radar trends, shower activity
is decreasing over land. Latest short-term model data indicate
only isolated showers will linger over Monterey and San Benito
Counties through mid morning. Otherwise, expect dry conditions
today along with seasonable temperatures.

Early morning satellite imagery shows an upstream system
currently over the Gulf of Alaska. This system is forecast to drop
to the southeast and bring widespread precipitation to our
forecast area, starting in the North Bay around midday on Sunday
and then spreading south across the rest of our region on Sunday
afternoon and evening. Rain intensity with this system is expected
to be light to moderate, although a brief period of locally heavy
rain rates is possible along the cold front Sunday afternoon and
evening. Rain totals through Sunday night are forecast to range
from a tenth to a half inch in most areas, with potentially up to
an inch in the Santa Cruz and Santa Lucia Mountains. Showers will
taper off Sunday night and mostly end by Monday, although isolated
showers may linger near the coast into Monday. This is a cold
system and light snow accumulation is likely above 3000 feet. Snow
levels will drop as low as 2000 feet by late Sunday evening, but
by then most precipitation will be through our area.

After the cold front passes late Sunday, northwest winds will
increase, especially over the coastal waters where gales are
likely from late Sunday into Monday. Gusty northwest winds are
also expected locally over land from Sunday night into Monday,
especially near the coast and in the coastal hills where local
gusts up to 40 mph are possible.

Once winds subside Monday night, the stage will be set for cold
temperatures, with overnight lows early Tuesday morning forecast
to drop to around freezing in the inland valleys. Areas of frost
are likely in our cooler inland valleys early on Tuesday.

Attention next turns to a much stronger and wetter system arriving
from the northwest by late Tuesday, bringing potentially heavy
rain and strong winds from Tuesday evening through Thursday. This
system is forecast to contain ample moisture and qualify as a
weak to moderate atmospheric river (AR) event. While models agree
this system will be capable of generating heavy rain rates,
especially on Tuesday night and Wednesday, there is disagreement
on how persistent the heavy rain might be and therefore how much
total precipitation might fall. The ECMWF moves the frontal
boundary and associated heavy rain band through our forecast area
steadily from late Tuesday through late Wednesday, waiting until
the band is south of our area before slowing its southward
progress. The GFS, on the other hand, forecasts the band of
intense precipitation to stall out over Monterey County on
Wednesday afternoon and then slowly lifts the boundary back north
to the Santa Cruz Mountains and East Bay by Thursday afternoon,
before shifting it back to the south on Thursday night. Either
model scenario would likely generate heavy rain rates and pose a
risk of debris flows and flash flooding over the various burn
scars, not to mention minor flooding in poorly drained and low-
lying areas. But the GFS solution is more concerning due to the
potential for a more prolonged period of heavy rainfall.
Preliminary forecast rain totals from late Tuesday through
Thursday range from 2 to 4 inches in most urban and low elevation
areas, except locally less in rain-shadowed valleys, and from 4 to
7 inches in the hills, with locally higher amounts a definite
possibility. Rainfall projections will be fine-tuned as we draw
closer to this event, but the primary message is to be prepared
for heavy rainfall and potential flash flooding and debris flows
in and near recent burn scars from Tuesday evening through
Wednesday and possibly through Thursday night. In addition, expect
strong and gusty winds at times through the event.

Our weather will become less intense late in the week. However,
models agree that the weather pattern will remain active with
additional rainfall likely by next weekend.

&& of 4:24 AM PST Saturday...For the 12Z TAFs. Rain
showers have mostly cleared out of the Bay Area, but are lingering
near the Central Coast, as seen on radar imagery. These showers
should end by 16z. Terminals are mainly VFR/MVFR with local areas
of IFR/LIFR where stratus and fog have formed. Can expect cigs
and patchy fog to linger through the mid-morning hours, with post-
frontal moisture providing support. Cigs will clear by late
morning bringing VFR conditions for the afternoon and evening with
gentle onshore winds. Patchy fog will be possible tonight, mainly
in sheltered valleys. The next storm system arrives Sunday
afternoon with steady rain and increasing winds.

Vicinity of KSFO...VFR/MVFR with some low clouds and cigs around
the Bay 2000-3000 ft AGL, as per obs and satellite night imagery.
Gradual clearing can be expected through the morning. Light
northerly winds 5 to 10 kt shifting to WNW this afternoon, up to
15 kt. Clouds will increase late tonight ahead of the next frontal
system Sunday afternoon and evening.

SFO Bridge Approach...Scattered low clouds may impact the approach
through the morning hours.

Monterey Bay Terminals...VFR-MVFR ceilings with scattered showers
ending by 16z. VFR conditions mid-morning through the day with
light to slightly breezy onshore winds. High clouds increase late
this evening but VFR should prevail.

&& of 08:10 AM PST Saturday...Scattered showers continue
over the southern waters and will cease by the morning. Breezy to
gusty northerly winds over the northern and outer waters will
persist throughout the day. Rain returns  Sunday into Monday,
accompanied by widespread gusty winds with  gale force conditions
possible Sunday night into Monday morning.  Heavy rain arrives by
the middle of next week. Large, long period  northwest swell
arrives Sunday into Monday.


     .Tday...SCA...Pt Arena to Pt Reyes 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 from 11 AM



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 Friday, January 22, 2021

High Temperature

91°F at Johnstown, NY

Low Temperature

-17°F at Aitkin Municipal Airport, MN

High Precipatation

1.43in at Alexandria Esler Field, LA

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