Re: How to work with this example?

  • Subject: Re: How to work with this example?
  • From: John Caron <caron@xxxxxxxxxxxxxxxx>
  • Date: Tue, 30 Jan 2007 16:05:11 -0700
Hi Ruben:

Perhaps you are using an old version of the library?

2.2.18 has this method:

NetcdfFileWriteable.addVariable(String varName, DataType dataType, List dims);

Ruben Arroyo wrote:
 public static void main(String args[])
     // We are writing 2D data, a 6 x 12 grid.
    final int NX = 6;
    final int NY = 12;

    // Create the file.
    String filename = "";
    NetcdfFileWriteable dataFile = null;

    try {
         dataFile = new NetcdfFileWriteable(filename);
// Create netCDF dimensions,
         Dimension xDim = dataFile.addDimension ("x", NX );
         Dimension yDim = dataFile.addDimension("y", NY );

         ArrayList<Dimension> dims =  new ArrayList<Dimension>();

         // define dimensions
         dims.add( xDim);
         dims.add( yDim);

        // Define a netCDF variable. The type of the variable in this case
        // is ncInt (32-bit integer).
         dataFile.addVariable("data", DataType.INT.getClass(), dims);
//dataFile.addVariable("data", DataType.INT.getClass(), dims);

         // This is the data array we will write. It will just be filled
         // with a progression of numbers for this example.
ArrayInt.D2 dataOut = new ArrayInt.D2 ( xDim.getLength(), yDim.getLength());

        // Create some pretend data. If this wasn't an example program, we
        // would have some real data to write, for example, model output.
        int i,j;

        for (i=0; i<xDim.getLength(); i++) {
             for (j=0; j<yDim.getLength(); j++) {
                 dataOut.set(i,j, i * NY + j);

        // create the file

        // Write the pretend data to the file. Although netCDF supports
        // reading and writing subsets of data, in this case we write all
        // the data in one operation.
       dataFile.write("data", dataOut);

    } catch (IOException e) {
    } catch (InvalidRangeException e) {
    } finally {
         if (dataFile != null)
         try {
         } catch (IOException ioe) {

     System.out.println( "*** SUCCESS writing example file!");


// I have been to change several lines to try to compile the example I see in: // <>

dataFile.addVariable("data", DataType.INT.getClass(), dims);
The method addVariable(String, Class, Dimension[]) in the type NetcdfFileWriteable is not applicable for the arguments (String, Class<capture-of ? extends DataType>, ArrayList)

And my question: Is possible that canot we pass an ArrayList to dataFile.addVariable ??


  • 2007 messages navigation, sorted by:
    1. Thread
    2. Subject
    3. Author
    4. Date
    5. ↑ Table Of Contents
  • Search the netcdf-java archives: