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

Re: How to work with this example?



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 = "simple_xy.nc";
    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
        dataFile.create();


        // 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) {
           e.printStackTrace();
    } catch (InvalidRangeException e) {
           e.printStackTrace();
    } finally {
         if (dataFile != null)
         try {
             dataFile.close();
         } catch (IOException ioe) {
             ioe.printStackTrace();
         }
    }

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

}

// I have been to change several lines to try to compile the example I see in: // http://www.unidata.ucar.edu/software/netcdf/examples/programs/Simple_xy_wr.java <http://www.unidata.ucar.edu/software/netcdf/examples/programs/Simple_xy_wr.java>

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

Thanks!