Jump to content

Recommended Posts

Posted

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!

Posted

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.

Posted

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

Posted (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 by igorland
Posted

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

Posted

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!

Posted (edited)

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
Posted

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.

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now
  • Recently Browsing   0 members

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