#1
  1. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Mar 2001
    Location
    New York
    Posts
    89
    Rep Power
    14

    Parsing METAR Data?


    Anyone written a script/regular expression to parse out METAR data?
  2. #2
  3. Happy Monkey
    Devshed Intermediate (1500 - 1999 posts)

    Join Date
    Nov 2001
    Location
    UK (University of Kentucky)
    Posts
    1,809
    Rep Power
    47
    I don't know if I speak for the rest of the board, but could you please be more descriptive as to what "METAR data" is?
  4. #3
  5. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Mar 2001
    Location
    New York
    Posts
    89
    Rep Power
    14
    sorry. Its weather data.

    Here is one of the strings I am trying to parse:
    http://weather.noaa.gov/pub/data/obs...tions/KJFK.TXT

    Here is the description of what it all means:
    http://tgsv5.nws.noaa.gov/oso/oso1/o...1/fmh1ch12.htm

    I have used regular expressions a few times but I have yet to find a good tutorial.
  6. #4
  7. Happy Monkey
    Devshed Intermediate (1500 - 1999 posts)

    Join Date
    Nov 2001
    Location
    UK (University of Kentucky)
    Posts
    1,809
    Rep Power
    47
    That's cool, I didn't know there was a code for that sort of thing... Anyway, how are you getting the code? Is it being passed to you as a string, or is it stored in a text file or database? It really doesn't matter, but I didn't know if part of your question was [for example] pulling the info from a text file. If you can get the data into a string, you can to one of two things:

    1) Use str_replace() to replace all line breaks with a pipe or some other character that your weather code doesn't use. Then explode() the data separated by a pipe (or whatever character you used) and then explode() those spaces.

    2) Use REGEX to pull all the lines into an array (broken apart with a line break) and then explode() the spaces.

    I hope this helps.
  8. #5
  9. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Mar 2001
    Location
    New York
    Posts
    89
    Rep Power
    14
    Thanks. I think I have a good idea as to how to try to parse it now... explode on all the " ", Loop through the array, and do a lot of if statements to find the data I need.. store data in a strings.
    Not pretty but should work none the less.

    I will try tonight. post it here if I succeed.
  10. #6
  11. php-oriented object
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2001
    Location
    0x9832053
    Posts
    173
    Rep Power
    14
    maybe you can improve performance and usability of the code using a class and instead of writing loads of "if"s, you can use the switch operator.
    i don't know what kind of data is that, but i can give you a hand if you want.
    Just my 2 cents
  12. #7
  13. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jun 2003
    Posts
    1
    Rep Power
    0

    An answer to your question


    Yes, someone has already written this so you don't have to duplicate the effort. I haven't tried it out yet but I'm going to.

    Check out PHP Weather here

    http://heime.net/weather/doc/phpweather.html

    Enjoy.
    -Gene

IMN logo majestic logo threadwatch logo seochat tools logo