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 221140

Area Forecast Discussion
National Weather Service San Francisco Bay Area
440 AM PDT Tue Sep 22 2020

.SYNOPSIS..Temperatures remain at or just below normal despite
gradually cooling through Thursday. Winds will remain onshore,
driven by the weak cold front passing through. Friday will begin to
warm before higher pressure along the coast sets up over the weekend
ushering in a return to hot temperatures for the Bay Area. These hot
temperatures will be coupled with dry offshore winds and lower
humidities. Warmer temperatures remain next week as the higher
pressure only shifts slightly to the east.

&& of 03:00 AM PDT Tuesday...High clouds pass over
the Bay Area this evening as a short wave upper level trough moves
eastward over the region. Patchy fog is being reported around
coastal areas, but the short wave has driven a compression of the
marine layer to below 800 feet; however, satellite is showing
stratus redeveloping along the coastline. Clouds should rebuild
and move over the Bay Area over the course of the morning. Patchy,
dense fog is also possible for low lying coastal areas.

A long wave trough over the Gulf of Alaska extends southward to the
Oregon/California border and will move toward British Columbia
through the course of the week. Meanwhile, higher pressure will
develop over the southeastern Pacific Ocean, stretching a ridge
northeastward over the Southern California and most of the Bay Area
and Central Coast. This set-up will drive consistent onshore flow
over the region. Temperatures will moderate and remain at seasonal
levels in the 70s and 80s, if not slightly cooler, through Thursday.
A weak cold front ahead of the long wave trough will pass over the
California coastline on Thursday. Most of the front will be north of
Sonoma county, so very little impacts are expected with the front;
but there is a chance of some light drizzle possible in the coastal
North Bay Thursday.

500 mb heights will begin lowering on Thursday as the long wave
trough moves eastward toward the Rockies. By Friday, the trough axis
will be east of Nevada with high pressure developing over the
Pacific Ocean. As the trough digs toward the Great plains and high
pressure strengthens, the forecast becomes focused on a stark warm
up of temperatures with winds turning to offshore.

Confidence is increasing as models have consistently showed
increasing high pressure over the weekend reaching a max height of
597 dm just of the coast. 850 mb temperatures on both the GFS and
Euro are between 24-26 degrees Celsius. It`s a far cry from the 600
dm high that was over the Four Corners over the Labor Day weekend
heat wave with 850 mb temps up to 30, but it will be strong enough
to raise temperatures into the 90s and lower-100s for inland areas.
Temperatures in the 80s are expected closer to the coast, but since
this pattern will also set-up offshore winds the chance still exists
to update the forecast to warmer coastal temperatures. Given that
the event is still several days away, there is lower confidence that
the offshore winds will mix down to the surface, driving the warmer
temperatures. For now, the strongest winds will be at elevated
terrain in North Bay Mountains and East Bay Hills. The Santa Cruz
Mountains are possible, but there is lower confidence at this time.
At this time, strongest wind gusts will likely be at the highest
peaks and ridges around 30 to 35 mph. Winds are expected to begin
gradually rotating to the north late on Friday evening, but the
main timeline for the stronger offshore winds will be Saturday
morning through early Monday morning, with peak winds on Sunday
morning. The offshore winds will also eliminate any impacts of the
marine layer and bring drier air over the Bay Area, reducing
humidities and raising fire concerns which will be monitored
as new information comes in and confidence increases.

By Monday, models start to disagree, but the high pressure looks to
only shift slightly eastward with the next trough building and
approaching the west coast by midweek next week. While hottest
temperatures are expected on Sunday and Monday, it is expected to
remain warm in the middle of next week, though temperatures will
begin to decrease. However, the dry conditions will remain, with no
substantial precipitation in the forecast.


.AVIATION...As of 4:35 AM PDT Tuesday...Marine layer compressed
this morning and is near 1000 feet. Satellite imagery shows
stratus limited to the northern part of the Bay Area impacting
mainly SFO and OAK. Areas of fog in the MRY Bay Area. Clouds
expected to scatter out by 17z. Drier air aloft mixes down to the
surface tonight resulting in less low stratus.

Vicinity of KSFO...IFR with bases around 800 ft. Clearing after
17Z. Breezy this afternoon with winds sustained to 20 kt gusting
to near 30 kt.

SFO Bridge Approach...Possible lowered slant-range vis from haze,
otherwise similar to KSFO.

Monterey Bay Terminals...IFR...areas of LIFR for fog reducing
vsbys to 1/2 mile through 14Z. Clearing expected after 17Z with
northwest winds to 10 kt in the afternoon.

&& of 04:38 AM PDT Tuesday...A deep low in the Gulf of
Alaska will produce a large long-period swell train that will
arrive late Thursday evening and into Friday morning. Swells by
then could be up to 9 to 11 ft with a 16 to 18 second period. The
main impacts will be increased wave heights breaking near the
shoreline and an increased risk of rip currents developing along
coastal beaches. With the increase in temperatures inland expected
this weekend, beachgoers should be mindful of the increased wave
activity and rip currents. The wave activity is forecast to
gradually decrease through the weekend, but caution is advised
through at least Sunday morning.

&& of 04:15 AM PDT Tuesday...A 1020 mb high is centered
900 miles west of Pt Pinos. A 979 mb low is in the Gulf of
Alaska. This low will generate a large northwest swell that will
arrive Thursday and Friday. Northwest winds will be light to
moderate with the strongest winds along the inner coastal waters.


     .Tday...SCA...Pigeon Pt to Pt Pinos 0-10 nm from 3 PM
             SCA...Pt Arena to Pigeon Pt 10-60 nm until 9 AM
             SCA...Pt Arena to Pt Reyes 0-10 nm
             SCA...Pt Pinos to Pt Piedras Blancas 0-10 nm from 3 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 Monday, September 21, 2020

High Temperature

106°F at El Centro Naf, CA
106°F at Imperial County Ap, CA
106°F at Palm Springs Asos, CA

Low Temperature

21°F at Presque Isle Awos, ME
21°F at Whitefield Mt Washington Regional Ap, NH
21°F at Saranac Lake Adirondack Regional Ap, NY

High Precipatation

5.70in at Houston Clover Field, TX

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