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.
Carl, i can't reproduce the problem. i have created an index for 2005-07-14-0900_us057g1010t04q060003000, read each data section, and display each parameter without any problems. i also converted the file to netcdf with Grib12Netcdf.java program that i've attached. robb... On Tue, 21 Mar 2006, Carl Drews wrote: > New Reply: Negative array size error > > Is this problem resolved yet? I still see the error on grib1 files, but > not on grib2 files. > > Carl Drews > x2802 > > > > Ticket Details > =================== > Ticket ID: MQN-848427 > Department: Support netCDF Decoders > Priority: High > Status: Closed > http://www.unidata.ucar.edu/esupport/staff/index.php?_m=tickets&_a=viewticket&ticketid=307 > =============================================================================== Robb Kambic Unidata Program Center Software Engineer III Univ. Corp for Atmospheric Research address@hidden WWW: http://www.unidata.ucar.edu/ ===============================================================================
package ucar.nc2.iosp.grib;
// import statements
import ucar.unidata.io.RandomAccessFile;
import ucar.nc2.*;
import ucar.nc2.util.CancelTask;
import java.lang.*; // Standard java functions
import java.util.*;
import java.io.IOException;
import java.io.FileNotFoundException; // Extra utilities from sun
/***************************************************************************
*
* @author Robb Kambic 3/22/06
*
* @version 1.0
*
****************************************************************************/
public class Grib12Netcdf {
/************************************************************************
*
* Grib12Netcdf usage of the class, if called without arguments
*
************************************************************************/
public void usage(String className) {
System.out.println();
System.out.println("Usage of " + className + ":");
System.out.println( "Parameters:");
System.out.println( "<Grib1FileToRead> reads/scans metadata");
System.out.println( "<NetCDF output file> file to store results");
System.out.println();
System.out.println("java -Xmx256m " + className +
" <GribFileToRead> <NetCDF output file>");
System.exit(0);
}
/***********************************************************************
* Grib12Netcdf<br>
*
* @param args input Filename of gribfile to read
* @param args output Netcdf file name
*
*************************************************************************/
public static void main(String args[]) throws IOException {
// Function References
Grib12Netcdf func = new Grib12Netcdf();
// Test usage
if (args.length != 2) {
// Get class name as String
Class cl = func.getClass();
func.usage(cl.getName());
}
// Get UTC TimeZone
// A list of available ID's show that UTC has ID = 127
TimeZone tz = TimeZone.getTimeZone("127");
TimeZone.setDefault(tz);
// Say hello
Date now = Calendar.getInstance().getTime();
//System.out.println(now.toString() + " ... Start of Grib12Netcdf");
System.out.println("read grib1 file="+args[0]+" write to netCDF
file="+args[1]);
// Reading of Grib files must be inside a try-catch block
try {
IOServiceProvider iosp = null;
iosp = (IOServiceProvider) new Grib1ServiceProvider();
RandomAccessFile raf = null;
raf = new RandomAccessFile( args[0], "r" );
NetcdfFile ncfile = (NetcdfFile) new MakeNetcdfFile( iosp, raf,
args[0], null );
NetcdfFile nc = FileWriter.writeToFile( ncfile, args[1] );
nc.close();
raf.close(); // done reading
// Catch thrown errors from GribFile
} catch (FileNotFoundException noFileError) {
System.err.println("FileNotFoundException : " + noFileError);
} catch (IOException ioError) {
System.err.println("IOException : " + ioError);
}
// Goodbye message
now = Calendar.getInstance().getTime();
//System.out.println(now.toString() + " ... End of Grib12Netcdf!");
} // end main
static class MakeNetcdfFile extends NetcdfFile {
MakeNetcdfFile( IOServiceProvider spi, RandomAccessFile raf,
String location, CancelTask cancelTask ) throws IOException {
super( spi, raf, location, cancelTask );
}
}
}