Jump to content

Retrieving NOAA buoy data realtime text file for message board


amount

Recommended Posts

Hi,

 

I'm trying to set up a messageboard/blog where people can log surfing sessions.  As part of this I would like to have a generic form where people can enter their comments as well as give a specific time of their session.  With the given time, I would like to have a script that would automatically retrieve data from an NOAA buoy feed (particularly, this one: http://www.ndbc.noaa.gov/data/realtime2/41002.spec ) and have the relevant data pasted onto the text of their blog entry.  For example, if somebody went surfing at 1:00 PM on February 16, I would want the script to access the buoy feed, find the relevant line (for the time) and column (for the category, such as SwH for "Swell Height") and past text to the post (such as: "Swell Height = x").

 

This is also in the very early development stages, so I'm not sure what kind of bulletinboard/blog software I should use (preferably something free!).  I'm a bit of a newbie at this, so any information (and simple language) would be greatly appreciated.  Thanks a bunch!

 

--Andre

 

Link to comment
Share on other sites

This code should work...although since it takes a bit to process all of the text data you will want to cache the data from noaa and refresh it every hour or so to avoid excess traffic and processing on your server.

 

//get the data
$wave_data = file("http://www.ndbc.noaa.gov/data/realtime2/41002.spec");
$lines = count($wave_data);

//strip extra spaces from the first line
$columns = preg_replace('/\s\s+/', ' ', $wave_data[0]);

//get the column data
$columns = explode(" ", trim($columns));

for ($i = 1; $i < $lines; $i++) {
//strip extra spaces from the line
$line = preg_replace('/\s\s+/', ' ', $wave_data[$i]);

//explode into elements
$line = explode(" ", trim($line));

$cnt = count($line);

//build an array where we can reference the data
for ($j = 3; $j < $cnt; $j++) {
	$data[$line[0]][$line[1]][$line[2]][$line[3]][$columns[$j]] = $line[$j];
}


}

//with the above array, we can reference the data in the following way:

$year = '2007';
$month = '02';
$day = '16';
$hour = '20';

echo $data[$year][$month][$day][$hour]['SwH'];
echo $data[$year][$month][$day][$hour]['STEEPNESS'];

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.