Jump to content

Metar in Java


iGoApp
 Share

Recommended Posts

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!

Link to comment
Share on other sites

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 by igorland
Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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());
                    }
                }

Link to comment
Share on other sites

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 by igorland
Link to comment
Share on other sites

Andyrooc. Do you know how to deal with the following?

 

 

UAAA

com.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.NullPointerException

at MetarData.temperature(MetarData.java:29) at Main.main(Main.java:26)

 

 

Thank you so much!

Edited by igorland
Link to comment
Share on other sites

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.   Paste as plain text instead

  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.

Loading...
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...