This archive contains answers to questions sent to Unidata support through mid-2025. Note that the archive is no longer being updated. We provide the archive for reference; many of the answers presented here remain technically correct, even if somewhat outdated. For the most up-to-date information on the use of NSF Unidata software and data services, please consult the Software Documentation first.
On Thu, 28 Aug 2008, Bali, Pelin wrote:
Robb, I've been registered to address@hidden and I was sending my questions to 'address@hidden' all the time. I don't know how it is being handled from there and how it falls into your spam. I started to think that you were ignoring my messages. <:) After sending this message, I made a little change in my code to read Grib1GridDefinitionSection.params field to get HashMap of the parameters. This helped me to get all the information I needed. However, in the grib1 index file, the Dx and Dy fields of the grid definition section was still displaying wrong numbers. My colleague and I started looking into the Grib1GridDefinitionSection.java. In the section where the information obtained from octets 24-25 (Dx) and octets 26-27(Dy or np), they were being read as "short". We changed them to read by using GribNumbers.int2 method (please see the following code snippet). It started spitting out the correct numbers. Sincerely, Pelin Bali.
Pelin,Here's my findings so far, the only time readSHort returns a wrong value is the missing value scenario. ie when byte 1 and 2 = 255. readShort returns -0.0010 and GribNumbers.int2 return -9999. Is this what you are seeing? If not could you make available a file that i can test.
thanks, robb...
case 202 : // octets 18-20 (La2 - latitude of last grid point) lat2 = GribNumbers.int3(raf) / 1000.0; // octets 21-23 (Lo2 - longitude of last grid point) lon2 = GribNumbers.int3(raf) / 1000.0; // octets 24-25 (Dx - Longitudinal Direction Increment ) //------------------------------------------------------ // This is where we made the change. //------------------------------------------------------- //dx = raf.readShort() / 1000.0; dx = GribNumbers.int2(raf) / 1000.0; // octets 26-27 (Dy - Latitudinal Direction Increment ) // Np - parallels between a pole and the equator if (type == 4) { // np = raf.readShort(); np = GribNumbers.int2(raf); } else { // dy = raf.readShort() / 1000.0; dy = GribNumbers.int2(raf) / 1000.0; } //----------------------------------------------------------- // End of our changes. // ---------------------------------------------------------- // octet 28 (Scanning mode) See Table 8 scan = raf.read(); // octet 29-32 reserved reserved = raf.readInt(); if (P_VorL != 255) { if( NV == 0 || NV == 255 ) { getPL(raf); } else { getPV(NV, raf); } } break; // end Latitude/Longitude grids -----Original Message----- From: Robb Kambic [mailto:address@hidden] Sent: Wednesday, August 27, 2008 3:20 PM To: Bali, Pelin Cc: decoders Subject: Re: Fw: decoders] Grib1 Indexer and GDS info (fwd) Bali, your support msg has been sitting in my spam folder for months now, i just clean it out so that;s the reason for delay. There is an online support on unidata's home page and it's more dependable. I going to address your msg in a general manner until we get to the same level. The Grib decoder package was meant to only be a low level API, the data resolution that you are looking for would be easier to use a ToolsUI program the uses the Grib package. Actually i think you should be able to do the refinement w/o doing any coding. The ToolsUI program is located at: https://www.unidata.ucar.edu/software/netcdf-java/ It will read in the file and it has options to select areas of data, the documentation is a little scarce but intuitive. The is also NCML that will let you manipulate the output files. On the other hand: The grib package provides a dump, indexer and getData program that can be used as templates to get the info you were looking for. There are javadocs on all these routines on the decoders page. There is also a display package IDV that could do the data processing. Hope this helps. RObb...---------- Forwarded message ---------- Date: Tue, 5 Aug 2008 10:59:21 -0400 From: "Bali, Pelin" <address@hidden> To: address@hidden Subject: decoders] Grib1 Indexer and GDS info I am using the Grib1Indexer to read the Grib file. I need to get the information lat, long, and nxny (145 X 73) as indicated below. I tried to use Index.GdsRecord, however I wasn't successful. Although I could get start points of lat and long, I wasn't able to get neither resolution nor the end points of lat & long by using gdsRecord. Could you please show me some that direction on how to get this information? Thanks in advance. ------------ rec 98:1554711:date 2008080400 TMP kpds5=11 kpds6=105 kpds7=2 levels=(0,2) grid=16 2 m above gnd 24hr fcst: TMP=Temp. [K] timerange 0 P1 24 P2 0 TimeU 1 nx 145 ny 73 GDS grid 0 num_in_ave 0 missing 0 center 1 subcenter 0 process 45 Table 1 scan: WE:SN winds(N/S) latlon: lat -90.000000 to 90.000000 by 2.500000 nxny 10585 long 0.000000 to 360.000000 by 2.500000, (145 x 73) scan 64 mode 128 bdsgrid 1-- The following is how I use the grib indexer to get the grib data. RandomAccessFile raf = new RandomAccessFile(filePath, "r"); Grib1Indexer indexer = new Grib1Indexer(); PrintStream ps = new PrintStream(indexPath); indexer.writeFileIndex(raf, ps, false ); Index index = new Index(); boolean rc = index.open(indexPath); ArrayList gribIndexRecords = index.getGribRecords(); ArrayList<GdsRecord> gdsRecords = index.getHorizCoordSys(); // // Build a hashmap for the GDS keys. // java.util.HashMap gdsMap = new java.util.HashMap(); for (int a = 0; a < gdsRecords.size(); a++) { GdsRecord gdsRecord = gdsRecords.get(a); gdsMap.put(gdsRecord.gdsKey, gdsRecord); } for (Iterator it = gribIndexRecords.iterator (); it.hasNext (); ) { zz++; GribRecord gribRecord = (GribRecord)it.next(); if (gribRecord != null) { // // Select only temperature. // if (gribRecord.paramNumber == 11 ) { if (gribRecord.levelType1 == 105) { if (gribRecord.levelValue1 == 2.0) { if (gribRecord.forecastTime == 24) { Grib1Data grib1data = new Grib1Data(raf); if (gdsMap.get(gribRecord.gdsKey) != null) { GdsRecord gds = (GdsRecord)gdsMap.get(gribRecord.gdsKey); System.out.println("Dx: " + gds.dx); System.out.println("Dy: " + gds.dy); System.out.println("Grid Shape Code: " + gds.grid_shape_code); System.out.println("Grid Type: " + gds.grid_type); System.out.println("La1: " + gds.La1); System.out.println("LaD: " + gds.LaD); System.out.println("Latin1: " + gds.latin1); System.out.println("Latin2: " + gds.latin2); System.out.println("Lo1: " + gds.Lo1); System.out.println("LoV: " + gds.LoV); System.out.println("Major Axis Earth " + gds.major_axis_earth); System.out.println("Minor Axis Earth " + gds.minor_axis_earth); System.out.println("Nx: " + gds.nx); System.out.println("Ny: " + gds.ny); System.out.println("Radius Spherical Earth: " + gds.radius_spherical_earth); System.out.println("Resolution: " + gds.resolution); System.out.println("Winds: " + gds.winds); } float[] arr = grib1data.getData(gribRecord.offset1, gribRecord.decimalScale, gribRecord.bmsExists); } // hour 24 } // 2m } //above ground } // end of temperature } // grib record is not null } // end for Sincerely, Pelin Bali WeatherPredict Consulting, Inc. 3200 Atlantic Avenue, Suite 114 Raleigh, NC 27604 Phone (Direct): 919-239-8833 Phone (Main) : 919-876-3633 Fax : 919-876-4469 "Imagination will often carry us to worlds that never were. But without it we go nowhere." - Carl Sagan (Cosmos - 1980)======================================================================== ======= Robb Kambic Unidata Program Center Software Engineer III Univ. Corp for Atmospheric Research address@hidden WWW: http://www.unidata.ucar.edu/ ======================================================================== =======
=============================================================================== Robb Kambic Unidata Program Center Software Engineer III Univ. Corp for Atmospheric Research address@hidden WWW: http://www.unidata.ucar.edu/ ===============================================================================