FreeData_NWS CFML Custom Tag

Download | Revision History | Usage | Other Resources

This ColdFusion 4.1+ CFML custom tag uses CFHTTP to retrieve weather reports (posted hourly) from the National Weather Service's Interactive Weather Information Network.

Download back to top

This tag requires Macromedia's Cold Fusion development enviroment, version 4.1x or later. All downloads and code are covered by our Source Code Policy.

FreeData_NWS.zip, 3.10kb Zip-Format Archive

Revision History back to top

July 25, 2004 Version 1.0

  • Removed documentation from the downloadable archive to ease maintenance.

December 31, 1999 Version 1.0

  • The tag's name was changed from "CFMWS" to "FreeData_NWS".

September 3, 1999 Version 1.0

  • Initial Release.

Usage back to top

You must first go to the National Weather Service site and find the closest weather station to your area:

The NWS is a free data source and there is no licensing or usage agreements needed. Unlike other, commercial, datasources the NWS service rarely changes format (in fact hasn't changed enough to affect this tag's operation for well over five years and counting). This means that you can expect this tag to work reliably without need for frequent updates.

Tag Usage

The tag takes six parameters:

StateThe two letter state code of the state you're retrieving a report for.
CityThe city whose report you'd like. This must be copied exactly from the Interactive Weather Information Network.
VarPrefixThis value will be prepended to all variables returned from the tag. Defaults to "NWS_". Useful for running multiple queries on the same template.
NoDataValThe value that will be used in place of any null returns. Defaults to "XXX". Commonly used for values like "Gust Speed" that aren't standard for every report. If the value of "WeatherFailed" equals "N" every value, excepting report time will be set to the NoDataVal
DumpResultsIf "Y" displays the results of the tag in table, defaults to "N". Good for quick checks and checking variable names.

Tag Output

This tag outputs 12 data items describing the current weather conditions. This chart describes the variables returned. Note that the prefix "NWS_" will be replaced with the value from the VarPrefix attribute if present.

NWS_ReportTime:The time that the weather report was generated. Note that if the "state" attribute is correct, but the "city" attribute doesn't exist this variable will still have a valid return.
NWS_SkyCondShrt:This is the short or "raw" version of the sky condition. Some examples: "DRIZZLE" or "LGHT RAIN"
NWS_SkyCond:This is an attempt to create a "friendly" version of the sky condition. Some examples: "Drizzle" or "Light Rain". If a the tag can't create a friendly version the SkyCondShrt value is used.
NWS_Temp:The Temperature (in Fahrenheit).
NWS_DewPT:The Dew Point (in Fahrenheit).
NWS_Humidity:The Humidity (Percent).
NWS_WindDir:The "full" wind direction: "North", "South-East", etc.
NWS_WindDirShrt:The abbreviated wind direction: "NE", "S", etc.
NWS_WindSpeed:The Wind Speed (either "Calm" or number indicating miles-per-hour).
NWS_GustSpeed:The wind's gust speed. Not always available.
NWS_Pressure:The pressure (barometric inches).
NWS_PressureActivity:The pressure activity: "Rising","Falling", or "Steady"

In addition the tag also outputs the following:

NWS_VarNames:A comma-delimited string containing the variable names of the weather report. Can be used to programatically output the report results.
NWS_WeatherFailed:"N" if the return is a valid report, "Y" if the return is not valid.

Tag Example

The following example retrieves the weather report for Boston, MA, shows help, and displays the results.

<cfmodule template="FreeData_NWS.cfm"
	State="MA"
	City="BOSTON"
	VarPrefix="NWS_"
	NoDataVal="000"
	DumpResults="Y"
	Help="Y">

Displaying Tag Output Example

This example loops over the "VarName" list and displays the values (Note that the prefix "NWS_" may be changed at runtime).

<cfloop List="#NWS_VarNames#" index="Item">
	<cfoutput>
		#Item#:	#Evaluate("Caller.#Item#")#
	</cfoutput>
	<br>
</cfloop>

Example Tag Output back to top

This is a sample of the tag's output when retrieving a weather report for Boston, MA:

	Weather for BOSTON, MA:
	NWS_WeatherFailed     N
	NWS_ReportTime        JAN 9, 1999 12:00AM
	NWS_SkyCondShrt       DRIZZLE
	NWS_SkyCond           Drizzle
	NWS_Temp              34
	NWS_DewPT             34
	NWS_Humidity          100
	NWS_WindDir           West
	NWS_WindDirShrt       W
	NWS_WindSpeed         6
	NWS_GustSpeed         000
	NWS_Pressure          30.01
	NWS_PressureActivity  Falling
	

Other Resources back to top

Other resources to help you make the most of this component including code walkthroughs and supporting systems and external web links.

  • FreeData_NWS Database: This is a simple system that lets authors easily archive weather reports into an Access database.
  • FreeData_NWS: Your Weather: Get the current weather from your region from us in three different, easily parsable formats!
  • NWS IWIN Web Site: The home page of the National Weather Service system where FreeData_NWS gets its information.

20 Current Sessions; Time: 03:48:04 06-01-2009; Tick: 375