iGoApp Posted January 13, 2013 Report Posted January 13, 2013 Hi, all. If anyone is experienced in Java, can you help please? I am finishing a project (which is my first project, so I am just a beginner) and I would like to parse Metar data into my main class (actually, I need just temperature, but parsing the whole Metar report would be nice-to-have). I have found a code by Matthew Feldt, but cannot make it work (e.g., the Temperature method is not seen). Is there an easy and/or working solution? Thank you! Quote
Andyrooc Posted January 13, 2013 Report Posted January 13, 2013 The Temperature class is there and has a number of methods in it. Which method are you trying to use? Quote
iGoApp Posted January 15, 2013 Author Report Posted January 15, 2013 (edited) Hi, Andyrooc. Are you talking about this?http://jfall-javafx.googlecode.com/svn-history/r6/WeatherFX/src/com/feldt/metar/Metar.java I see only one class here (Metar), where the Temperature method "is not seen" when the jar is exported to the project in Eclipse. Do you have it working? Thank you so much for your help! Edited January 15, 2013 by igorland Quote
Andyrooc Posted January 15, 2013 Report Posted January 15, 2013 Looks like you haven't got the whole thing. Try this: http://feldt.com/work/projects/metar/ Quote
iGoApp Posted January 17, 2013 Author Report Posted January 17, 2013 Hi, Andyrooc. When I try to create an object referring to a class, it gives an error "The type temperature is not visible."This is what I am trying to do: import com.feldt.metar.*; public class main { public static void main(String[] args) { Temperature temp = new Temperature(); String dep = temp.parseTemperature("KSEA"); } } Hm, what is wrong? Thanks. Quote
Andyrooc Posted January 17, 2013 Report Posted January 17, 2013 The MetarRun.java has all the code you need in it: This bit here will allow you to get temperature for example: MetarFtp metarFtp = MetarFtp.parse(station); metar = Metar.parse(station, metarFtp.getObservation(), metarFtp.getObservationDateAsString()); if (metar != null) { //here you can use the metar object to get temperature, ie: Temperature temp = metar.getTemperature(); if (detailValue.booleanValue()) { System.out.println(metar.getFormattedMetar()); } else { System.out.println(metar.toString()); } } Quote
iGoApp Posted January 17, 2013 Author Report Posted January 17, 2013 (edited) Thank you so much for your help. Tried it, keep getting "Exception in thread "main" com.feldt.metar.exceptions.MetarException: Connection timed out: connect." import com.feldt.metar.Metar;import com.feldt.metar.MetarFtp;import com.feldt.metar.exceptions.MetarException;import com.feldt.metar.exceptions.MetarParseException; public class GetMetar { public static void main(String[] args) throws MetarParseException, MetarException { String station = "KLAX";MetarFtp metarFtp = MetarFtp.parse(station); Metar metar = Metar.parse(station, metarFtp.getObservation(), metarFtp.getObservationDateAsString()); if (metar != null) { System.out.println(metar.toString());} } } Edited January 17, 2013 by igorland Quote
Andyrooc Posted January 17, 2013 Report Posted January 17, 2013 You'll need to change your ftp server to: ftp://tgftp.nws.noaa.gov/data/observations/metar/stations/ (in metar.properties) Quote
iGoApp Posted January 18, 2013 Author Report Posted January 18, 2013 Thanks! This code works and now I CAN get a Metar report. Much appreciated. I still cannot get just Temperature since it gives me the error: The type is not visible! Hm............ Quote
Andyrooc Posted January 18, 2013 Report Posted January 18, 2013 Temperature is mostly static methods, so you can't create an instance of the class. Quote
iGoApp Posted January 26, 2013 Author Report Posted January 26, 2013 Thanks, Andyrooc. Your help is much appreciated. I am getting the desired temperature now. The only problem is that the com.feldt.metar.exceptions.MetarParseException is thrown too often because tokens are not recognized: (e.g., M08/ instead of M08/M20). But thanks anyways for your help! Quote
iGoApp Posted January 27, 2013 Author Report Posted January 27, 2013 (edited) Andyrooc. Do you know how to deal with the following? UAAAcom.feldt.metar.exceptions.MetarParseException : Unknown token: "16002MPS" in "UAAA 271400Z 16002MPS 0700 R05L/1900N R05R/1900N BR FU FEW050 BKN100 01/M02 Q1016 88CLRD65 TEMPO 0600 FU"at com.feldt.metar.Metar.parse(Metar.java:213)at MetarData.temperature(MetarData.java:25)at Main.main(Main.java:26)Exception in thread "main" java.lang.NullPointerExceptionat MetarData.temperature(MetarData.java:29) at Main.main(Main.java:26) Thank you so much! Edited January 27, 2013 by igorland Quote
Andyrooc Posted January 28, 2013 Report Posted January 28, 2013 It looks like that library handles North American METAR info, but not the international standard. Odd. It'll need a bit of re-working to get it to handle WMO standards properly. BTW, this is a nice little tool for reading Metar data: http://www.metarreader.com/ Quote
iGoApp Posted January 28, 2013 Author Report Posted January 28, 2013 Thanks! Well, what I am doing now is creating my own Java class to read Metar and get the Temperature data. If you are interested, I can share with you the code when I am done. Cheers. Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.