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 261232

Area Forecast Discussion
National Weather Service San Francisco Bay Area
532 AM PDT Sat Sep 26 2020

.SYNOPSIS...Some patchy clouds along the coast this morning but
developing north winds will bring sunny skies and a warming trend
this afternoon. Red Flag Warnings start at 9 pm tonight for the
North and East Bay with northeast winds developing in the hills.
The offshore winds will mix down on Sunday leading to hot and dry
weather across the entire Bay Area with warm temperatures all the
way to the coast. A second burst of offshore winds Sunday night
into Monday as Red Flag Warnings remain in effect through 11 am
Monday. Continued sunny and hot Monday with near record high temps
in the 90s and lower 100s. Only gradual cooling inland next week
as dry high pressure keeps temperatures above normal through the
beginning of October.

&& of 3:58 AM PDT Saturday...Fog bank is along the
coast but only Pt Reyes and Half Moon Bay reporting any clouds
with the marine layer now only around 800 feet deep. Synoptic
pattern is still zonal pushing into Oregon but northerly gradients
from SFO to Arcata are now up to 4 mb, a sign of the developing
offshore wind pattern. Today will be the transition day with sunny
skies and a noted inland warming trend this afternoon as
northerly downslope flow impacts the North Bay by later this
afternoon with highs into the lower 90s.

For tonight the main shortwave drops into the Northern Rockies as
a 594 dm high builds offshore. A developing tight surface pressure
gradient over the Sierra will translate into offshore winds. The
first shot of winds will come down the Sac Valley this evening,
then as the night time inversions set-up the first burst of winds
will reach the Napa hills sometime around 9-10 pm and then
overspread the higher terrain of Sonoma county. The Red Flag
warning goes into effect at 9 pm. The main change overnight has
been to add the lower elevations of the North Bay valleys
including the coast. For clarity of message the start times were
all left the same at 9 pm tonight. Also the end time for all the
Red Flags as been extended through 11 am Monday.

Overnight into early Sunday the WRF and NAM model show some winds
mixing down into the lower elevations of the North Bay by 2-4 am.
Event still looks to be of moderate strength with local gusts to
50 mph but widespread in the 30-40 mph range for the hills. The
initial burst of winds will help to drive humidity values much
lower by sunrise Sunday. Everyone will wake up to sunny skies with
no marine layer Sunday. Expect rapid warming and drying on Sunday
with local WRF model showing a bullseye of wind around 16-17z
Sunday with gusts 35-50 mph for the North Bay mtns as well as some
strong winds pushing out into the Delta region and interior East
Bay valleys. Highs on Sunday should be 90s to lower 100s most
inland areas with upper 80s pushing close to the coast and 70s
right at the beaches. Local WRF model shows extreme drying of the
boundary layer across the North Bay by Sunday evening as
persistent offshore winds continue.

If anything the models have trended slightly windier Sunday night
and very dry. There will be no humidity recovery across the
entire region with values staying well under 30% with many areas
in the teens for 24-36 hours. This will really dry out the fine
fuels that have been protected by the marine layer the last few

Surface gradient is tightest over the Sierra Sunday night
allowing east flow to push towards the Bay Area all night long.
Boundary layer winds look stronger Sunday night with dry winds
mixing down to lower elevations through Monday morning. Critical
conditions to last at least through Monday morning so went ahead
and extended the Red Flag Warning thru 11 am Monday.

Temperatures on Monday will be similar if not warmer than Sunday
so another day of temps in the 90s to lower 100s. During east
winds events the differences between the coast and inland become
negligible so expect uncomfortably hot weather within a few miles
of the ocean. Some daytime heat advisories may be needed but still
expect enough cooling at night to preclude significant heat
impacts. Though the afternoon hours will be uncomfortably hot for
those sensitive to the heat the very low dewpoints will keep heat
indices low.

Latest model solutions keep the ridge in place next week in highly
amplified pattern. Will need to watch for return southerly flow
along the coast with latest NAM showing some hints along the
Central Coast as early as Tuesday. Inland areas to remain above
normal temp wise next week. No sign of rain through early Oct.


.AVIATION...As of 5:32 AM PDT Saturday...For the 12z TAFs. VFR
prevails. Stratus along the coast but not expecting much inland
penetration with strong northerly gradient. Some fog reported at
KHAF but otherwise mostly clear conditions. The marine layer is
around 800 feet deep and and should not change much through the
morning. Keeping LLWS in TAF for KSTS through 18z due to gusty
winds around 30 kt being reported at 2000 ft elevation at Hawkeye
RAWS station near the airport. More LLWS expected tonight into
Sunday with strong NNE winds aloft lasting through Monday and
impacting Bay Area terminals. Northerly flow should prevent
redevelopment of the marine layer.

Vicinity of KSFO...VFR with light and variable winds. Stratus
over the ocean is moving southward down the coast. Not expecting
cigs to develop over terminals but few/sct possible through mid-
morning. VFR conditions expected through the TAF period with
strong onshore winds over 20 kts with gusts 25 to 30 kts this
afternoon into early evening.

SFO Bridge Approach...Similar to KSFO.

Monterey Bay Terminals...VFR over the terminals. Stratus just
offshore but northerly flow is not conducive to inland
penetration. Possible sct clouds for tempo periods around KMRY,
otherwise mostly clear. Light and variable winds will pick up and
be breezy this afternoon with VFR clear skies. Not expecting cigs
through the TAF period with drier airmass moving in for Sunday.


.CLIMATE...Here are the record high temperatures for Saturday
through Monday...

SANTA ROSA...........103 in 2009....103 in 2010.....104 in 2010
KENTFIELD............ 99 in 2016....103 in 1921.....102 in 1921
NAPA.................105 in 1963....101 in 1958.....102 in 1966
RICHMOND..............97 in 2019.....97 in 2010......97 in 2010
LIVERMORE............103 in 1952....105 in 1963.....105 in 2010
SAN FRANCISCO.........94 in 1992.....93 in 2010......95 in 1966
SF AIRPORT............95 in 1958.....96 in 2010......95 in 2010
REDWOOD CITY..........99 in 1963.....97 in 2010......98 in 2010
HALF MOON BAY.........90 in 1970.....89 in 1966......91 in 1958
OAKLAND DOWNTOWN......93 in 2016.....95 in 1973......92 in 2010
SAN JOSE..............98 in 2016.....98 in 1921......99 in 2010
GILROY...............104 in 1963....108 in 1963.....101 in 1963
SANTA CRUZ...........101 in 1970....103 in 2010.....100 in 1917
SALINAS..............101 in 2016....102 in 2010..... 99 in 1970
KING CITY............105 in 1963....107 in 2010.....102 in 1973

&& of 02:37 AM PDT Saturday...High pressure off the
California coast will keep gusty northwest winds through tonight.
The high will move into the Pacific Northwest Sunday and into the
Great Basin Monday. This will cause northwest winds to turn more
northerly on Sunday and east to southeast on Monday. Northwest
swell will slowly decrease while a light southerly swell will


     .Tday...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 Pinos to Pt Piedras Blancas 0-10 nm
             SCA...Pigeon Pt to Pt Piedras Blancas 10-60 nm
             SCA...Pt Arena to Pigeon Pt 10-60 nm
             SCA...Mry Bay




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, September 25, 2020

High Temperature

106°F at Needles, CA
106°F at Blythe Asos, CA
106°F at Laughlin Bullhead Intl Ap, AZ

Low Temperature

25°F at Angel Fire Airport, NM

High Precipatation

3.61in at Fort Bragg Mackall Aaf, NC

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