Unidata - To provide the data services, tools, and cyberinfrastructure leadership that advance Earth system science, enhance educational opportunities, and broaden participation. Unidata
         
  advanced  
 

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: decoders] First post - GRIB2 decoders




On Tue, 26 Feb 2008, Jelle Ferwerda wrote:

Dear Rob,

Finally.. I cracked it. I took one of the files in the indexer, and deleted all that was unneeded for my implementation.

Good job, if you want to read the data for that product you could add the code:


            Grib2Data g2d    = new Grib2Data(raf);
            float     data[] = g2d.getData(GdsOffset, PdsOffset);

            if (data != null) {
                int row = 0;
                for (int j = 0; j < data.length; j++) {
                    //if( j % 800 == 0 ) // used to test quasi data
                    //ps.println( "row ="+ row++ );
                    ps.println("data[ " + j + " ]=" + data[j]);
                }
            }
            raf.close();


This code was extracted from Grib2GetData.java.


robb...


I realize.. It is not the cleanest code in the world, but I managed to get the gdsoffset; I am sure I can get the rest to work too. Also, I found out that IDL can be called through a java interface, so all the data processing I will just handle in a familiar environment.


Thanks so much for your assistence!

Cheers,

Jelle.

PS: The code I use now for finding the offset (Still need to integrate & type juggle a bit) is:


String InFile = "C:\\java\\data\\MPE_20080222_0915_M9_00.grb"; int ProdInt = 0; // Index nr of product we want

// Yes we want output to memory
Boolean ToMem = true;
// Create a unidata specified RandomAccesFile for reading
ucar.unidata.io.RandomAccessFile InRA = new ucar.unidata.io.RandomAccessFile(InFile, "r"); try {
InRA.seek(0);


// Create an index of the file
Grib2Input g2i = new Grib2Input(InRA);
g2i.scan(true, false);
ArrayList products = g2i.getProducts();
for (int i = 0; i < products.size(); i++) {
if(i==ProdInt) // This I could clean up and just all the ProdInt in once go
{
Grib2Product product = (Grib2Product) products.get(i);
Grib2ProductDefinitionSection pds = product.getPDS();
Grib2IdentificationSection id = product.getID();
long GDSOFF = product.getGdsOffset();
long PDSOFF = product.getPdsOffset();
System.out.println(GDSOFF);
System.out.println(PDSOFF);
}
}
} catch (NotSupportedException noSupport) {
System.err.println("NotSupportedException : " + noSupport);
}
System.out.println(
"-----------------end------------------------");






-----------------------------------------------
Jelle Ferwerda
Postdoctoral Research Fellow

Animal Behavior Research Group
Department of Zoology / University of Oxford
South Parks Road / Oxford / OX13PS
United Kingdom

email: 		Jelle@xxxxxxxxxxxxx
Office Phone: 	+44 18652 71214
WWW:		http://www.bio-vision.nl
		http://www.cookseasonal.com
-----------------------------------------------


=============================================================================== Robb Kambic Unidata Program Center Software Engineer III Univ. Corp for Atmospheric Research rkambic@xxxxxxxxxxxxxxxx WWW: http://www.unidata.ucar.edu/ ===============================================================================


 
 
  Contact Us     Site Map     Search     Terms and Conditions     Privacy Policy     Participation Policy
 
National Science Foundation (NSF) UCAR Office of Programs University Corporation for Atmospheric Research (UCAR)   Unidata is a member of the UCAR Office of Programs, is managed by the University Corporation for Atmospheric Research, and is sponsored by the National Science Foundation.
P.O. Box 3000     Boulder, CO 80307-3000 USA     Tel: 303-497-8643     Fax: 303-497-8690