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.

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 Thursday, 13-Oct-2016 12:40 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 141735

Area Forecast Discussion
National Weather Service San Francisco Bay Area
935 AM PST Thu Dec 14 2017

...Breezy conditions likely late Friday through Sunday morning...
...Elevated fire danger particularly for higher elevation
locations for the same time...

.SYNOPSIS...Dry weather continues this week as high pressure resides
over California. A mainly dry cold front will sweep south over
the area late Friday night and early Saturday morning which then
increases N-NE winds along the ridges and peaks Saturday.

&& of 9:05 AM PST Thursday...Main concern for the
forecast centers over the weekend with locally gusty winds and
low humidity readings likely. After several calls will likely go
with a fire weather watch for all higher elevation spots from late
Friday through Sunday morning. Winds could locally gust over 50
mph while maximum humidity values Saturday night will struggle to
get above 20% in some spots.

Worth noting that the 12Z operational GFS has backed off on
precipitation chances for the middle of next week.

.PREVIOUS DISCUSSION...After an extended period of stagnant
weather with a Rex Block, a pattern change is likely this weekend
and possibly rain returning next week.

Currently a stout offshore flow set up prevails with high pressure
over the Great Basin and low pressure along the coast. Latest
offshore gradients are actually stronger than 24 hours ago at 14
mb (SFO-WMC). Needless to say, this pressure gradient is leading
to mild temperatures, dry conditions and very gusty winds over
higher elevations. Mt Diablo is once again the winner for
strongest winds with gusts up to 53 mph. Santa Rita Peak in San
Benito County is the driest with relative humidity values sitting
about 10%. For what it`s worth, that is up about 5% from earlier
in the night. Heightened fire weather concerns exist over the
peaks tonight. Similar to last night, different story in the
valleys with much weaker winds and colder temperatures. Several
interior valleys locations are currently sitting in the upper 20s
to lower 30s. Patchy frost will be possible in these locations. A
few stations across the North Bay Valleys are also reporting dense

If you liked yesterday`s weather you`ll like today`s. Mostly sunny
skies and above normal temperatures. High pressure finally breaks
down on Friday as a weak frontal boundary and associated upper
level trough sweep through the region. Models continue to show a
dry frontal passage Friday night for the Bay Area, but some light
precip is poss for far N CA. This change in the pattern will bring
slightly cooler temperatures this weekend. More importantly, it`s
the weather conditions that develop behind the front impacting the
Bay Area. Offshore flow gradients ramp up pretty quick Friday
night into Saturday morning. The local WRF model continues to
show NE winds of 20-30 mph with gusts exceeding 50 mph over the
higher terrain of the North/East Bay and Santa Cruz Mountains.
Given that it is still several forecast periods out will hold off
on a wind advisory, but issue a hazardous weather outlook to
highlight winds. In addition to the wind impact, fire weather
concerns will also develop. Humidity values will recovery early
Friday night, but plummet below 30% as NE wind kick in. Breezy to
gusty NE winds persist through Sunday morning. A fire weather
watch may be needed for Saturday night as humidity recoveries will
be poor all night with NE winds over higher terrain.

High pressure rebuilds over the region Sunday through Tuesday. The
much talked about precipitation chances for the middle of next
week still exist. In fact, the 00Z models are much different than
24 hours ago. The big three models all show a large scale trough
sweeping through the West Coast on Wednesday. All three models
also show some QPF around the Bay Area as well. It`s still too far
out for exact amounts, but at this point we`ll take anything we
can get. Hope the models stay locked on this solution and don`t
flip flop back to drier solutions.


.AVIATION...As of 9:35 AM PST Thursday...For 18z TAFs. Mainly
clear skies will prevail through the rest of the day with the
exception of a thin veil of high clouds spilling in over the
region. Patchy fog will return over KSTS late tonight...otherwise
clear elsewhere. Mainly light winds with a slight seabreeze
expected this afternoon.

High confidence.

Vicinity of KSFO...VFR. Light and variable winds turning west-
northwest by late afternoon, around 10 kt.

SFO Bridge Approach...Similar to KSFO.

Monterey Bay Terminals...VFR. Easterly winds around 10 kt down
the Salinas Valley this morning. Winds should switch more onshore
and decrease some by late afternoon, before turning back east
late tonight.



Record high temperatures for Thursday, December 14, 2017.

SF BAY AREA                     December 14
 HEALDSBURG..............       77/1942
 SANTA ROSA..............       72/1956
 KENTFIELD...............       70/1942
 SAN RAFAEL..............       70/1959
 NAPA....................       73/1959
 SAN FRANCISCO...........       69/1988
 SFO AIRPORT.............       69/1958
 OAKLAND AIRPORT.........       65/1958
 RICHMOND................       67/1983
 LIVERMORE...............       75/1958
 MOFFETT FIELD...........       72/1958
 SAN JOSE................       73/1958
 GILROY..................       72/1988

 MONTEREY................       78/1953
 SANTA CRUZ..............       82/1953
 SALINAS.................       80/1988
 SALINAS AIRPORT.........       81/1953
 KING CITY...............       83/1958

&& of 8:51 AM PST Thursday...Generally light to
moderate northerly winds will persist today and Friday over the
coastal waters. A cold front will push through the area late
Friday and will bring with it increasing northwest winds. Seas
will gradually increase through the rest of the week.






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.05 - 31-Mar-2015 see history).

PHP for NWS CPC USA Extremes

This script was originated by Michael of and has been rewritten to use the NWS Climate Prediction Center's One Day Old Daily Data Summary text file for the USA. 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 four variables:

$usahigh - contains the text of the high temperature station(s) (value and station name from the NWS)
$usalow - contains the text of the low temperature station(s) (value and station name from the NWS)
$usaprecip - contains the text of the high precipitation station(s) (value and station name from the NWS)
$reportDate - contains the text of the date for the report (default format is 'Dayname, Month day, Year')

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 courtsey of <a href=\"";
print "";
print "\">NWS-CPC</a></small></p>\n";


which produces this result (with live data):

USA Extremes for Wednesday, December 13, 2017

High Temperature

87°F at Camarillo (awos), CA

Low Temperature

-15°F at Mount Washington, NH

High Precipatation

0.56in at Green Bay/A.straubel, WI

Data courtsey 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.

// Site to Parse
$url2 = "";
// Name of cache file  --  This file must be set to CHMOD-666
$cacheFileDir = './'; // directory to store cache file in.
$cacheFile2 = "usaextremesCache4.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
$rUOM = 'in';     // or ='' for no rain unit display
$ignoreStations = array('99NRB'); // Station numbers to ignore, Array of station numbers

NWS CPC One Day Extremes PHP script Download (4.03 - 13-Oct-2016 see history).