Forums > MaxMSP

weather report as information source

February 16, 2006 | 9:56 am


February 16, 2006 | 11:07 am

Sure.

It might be fairly simple to reverse-engineer the weather report
Dashboard item under OS X… (failing that, to just google for a
weather report API).

– N.

nick rothwell — composition, systems, performance — http://
http://www.cassiel.com


February 16, 2006 | 4:46 pm

There is a Flight Simulator called X-Plane which periodically downloads current weather conditions for the region your are flying.

It uses files called ‘METAR.rwx’

Thats as much as i can tell you….

john.


February 16, 2006 | 5:31 pm

> There is a Flight Simulator called X-Plane which periodically downloads current weather conditions for the region your are flying.

It probably uses the data from this service:

http://adds.aviationweather.gov/java/

Ben


February 16, 2006 | 5:32 pm


February 17, 2006 | 12:55 am

Hi friends,
Strangely enough, I’m working on a project right now where we take in clouds and visibility. The easiest would be to use NOAA’s "experimental" XML feeds, but because they don’t include visibility data for that, I’m just using their good old METAR files available via FTP. Find your URL for the one you want. The one in my code is for Fairbanks.
So, like I said, I’m using the METAR files. You can google for the specs. I made some regular expressions to find the cloud and visibility data.
Hope this helps. Perhaps Wally the bartender can move this thingy over to the Java thread?
In case you don’t want to scroll through my ugly code, here are the regex’s (note that they’re double-escaped for use in java string literals):

Visibility: \s((9{4})|(M?(\d{1,2})?\s?(\d/\d)?SM))\s
Clouds: \s((((VV|OVC|BKN|SCT|FEW)\d{3}(TCU|CB)?)|(SKC|CLR))\s)+

with love,
jim

private char[] URLReader() throws Exception // reads the metar file from the noa ftp server, and returns it as an array of chars
{
URL PAFAurl = new URL(" ftp://weather.noaa.gov/data/observations/metar/stations/PAFA .TXT ");
BufferedReader instream = new BufferedReader(
new InputStreamReader(
PAFAurl.openStream()));

char inbuffer[] = new char[2000];

instream.read(inbuffer, 0, 2000);
instream.close();

post(String.valueOf(inbuffer));

return inbuffer;
}

private void metarParser(char[] inbuffer)
{

float visfloat = 0;
int cloudint = 0; // this will range from 0 at no clouds, to 4 at OVC/VV

String inbufstring = String.valueOf(inbuffer);

CharSequence inbufcharseq = inbufstring.subSequence(0, (inbufstring.length() – 1));

Pattern p = Pattern.compile("\s((9{4})|(M?(\d{1,2})?\s?(\d/\d)?SM))\s ");
Matcher m = p.matcher(inbufcharseq);

if (m.find())
{
String visstring = m.group().trim();
//post("the visibility string is: "+ visstring);
if (visstring == "9999")
{
visfloat = 9999;
} else if (visstring == "M1/4SM") // automated stations with less than 1/4 mile vis should report this
{
visfloat = (float)0.125;
} else
{
String dummyarray[] = visstring.split("SM"); //trim off the "SM" at the end;
String visnumberstring = dummyarray[0];
//post("the visnumberstring is: "+visnumberstring);
String visarray[] = visnumberstring.split("/");
if (visarray.length > 1) //if there’s a fraction
{
Float denom = Float.valueOf(visarray[1]);
String fracarray[] = visarray[0].split("\s");
if (fracarray.length > 1) // if it’s a mixed number
{
Float numerator = Float.valueOf(fracarray[1]);
Float wholepart = Float.valueOf(fracarray[0]);
visfloat = wholepart.floatValue() + (numerator.floatValue() / denom.floatValue());
} else
{
Float numerator = Float.valueOf(fracarray[0]);
visfloat = numerator.floatValue() / denom.floatValue();
}

} else
{
visfloat = Float.valueOf(visarray[0]).floatValue();
}
}
} else
{
post("couldn’t find the visibility in: " + inbufcharseq.toString());
}

p = Pattern.compile("\s((((VV|OVC|BKN|SCT|FEW)\d{3}(TCU|CB)?)|(SKC|CLR))\s)+ ");
m = p.matcher(inbufcharseq);
if (m.find())
{
String cloudstring = m.group().trim();
//post("the cloud cover string is: "+ cloudstring);

String cloudstrings[] = cloudstring.split("\s");

for (int i = 0; i < cloudstrings.length; i++)
{
char c = cloudstrings[i].charAt(0);
if ((c == ‘V’)||(c == ‘O’))
{
cloudint = 4;
} else if (c == ‘B’)
{
if (cloudint < 3)
{
cloudint = 3;
}
} else if ((c == ‘S’)&&(cloudstrings[i].charAt(1) == ‘C’)) //to make sure it’s SCT and not SKC
{
if (cloudint < 2)
{
cloudint = 2;
}
} else if (c == ‘F’)
{
if (cloudint == 0)
{
cloudint = 1;
}
} else
{
post("malformed cloud string:" + cloudstrings[i]);
}
}
//post("the cloud cover int is: "+ String.valueOf(cloudint));
} else
{
post("couldn’t find the cloud cover in: " + inbufcharseq.toString());
}

outlet(1, cloudint);
outlet(0, visfloat);

}

public void update()
{
if (busyflag == 0)
{
busyflag = 1;
//create a new thread to do the weather stuff. ftp takes a long time
Thread t = new Thread()
{
public void run()
{
boolean successfulread = true;

try
{
post("starting the read/parse");
metarParser(URLReader());
}
catch (Exception e)
{
post(e.toString());
}

busyflag = 0;
}
};
t.start(); //start the thread executing

} else
{
post("busy. call back later.");
}
}


February 17, 2006 | 10:34 am

On 16 Feb 2006, at 17:32, mzed wrote:

> And I’d think it wouldn’t be too hard to parse this out with Java.

Pretty easy; it’s not too onerous to link up MXJ, HTTP fetches and
dom4j to interpret incoming XML via XPath.

I’d do it, but why do I care about the weather in America? :-)

nick rothwell — composition, systems, performance — http://
http://www.cassiel.com


February 17, 2006 | 10:55 am

On around Feb 17, 2006, at 11:34, Nick Rothwell said something like:
> I’d do it, but why do I care about the weather in America? :-)

Because when Bush sneezes, Blair says "I’m with you"?

(Sorry, it was such an easy shot)

– P.

————– http://www.bek.no/~pcastine/Litter/ ————–
Peter Castine | ^
| Litter Power & Litter Bundle for Jitter
pcastine@gmx.net |
pcastine@bek.no | iCE: Sequencing, Recording, and Interface Building
4-15@kagi.com | for Max/MSP
| Extremely cool
| http://www.dspaudio.com
| http://www.dspaudio.com/software/software.html


February 17, 2006 | 11:13 am


February 17, 2006 | 10:42 pm

I’m hip to that. Try this site, then:

http://www.rssweather.com/dir/

mzed


February 18, 2006 | 1:55 am


February 18, 2006 | 2:43 am

Ok.

With jit.uldl, my max patches now know the weather. My solutions are here:

http://homepage.mac.com/mikezed/weather.zip

And I’m still cleaing it up.

Still hoping for a non-Jitter method.

best,

mzed


February 18, 2006 | 9:27 am

Thanks everybody for the great hints.

Michael, my machine reports an error in finding your zip, could you
paste it as text

thanks, Falk


February 20, 2006 | 7:17 pm

> >
> > http://homepage.mac.com/mikezed/weather.zip
> >

Sorry, I messed up. It should work now.

mz


February 21, 2006 | 7:48 pm

michael,
sorry, but are you looking for something more than the java code that
i posted before (repeated below)? replace the URL with the one
appropriate for your weather station. this gives you the noaa METAR
report for any weather station. turn this array of chars into a
CharSequence, and use regexp to find the stuff you’re looking for. the
METAR specification is pretty rigorous and well documented on the web.
-jim

private char[] URLReader() throws Exception // reads the metar file from the noaa ftp server, and returns it as an array of chars
{
URL PAFAurl = new URL(" ftp://weather.noaa.gov/data/observations/metar/stations/PAFA .TXT ");
BufferedReader instream = new BufferedReader(
new InputStreamReader(
PAFAurl.openStream()));

char inbuffer[] = new char[2000];

instream.read(inbuffer, 0, 2000);
instream.close();

post(String.valueOf(inbuffer));

return inbuffer;
}


Viewing 15 posts - 1 through 15 (of 15 total)