将java数组传递给netcdf文件

时间:2011-08-31 20:52:58

标签: java database multidimensional-array netcdf

我的程序读取ascii文件并将数据保存到四维NetCDF文件中。这是使用气候数据中心规范创建netcdf维度,变量和变量属性的代码:

    String filename = filename(date);
    NetcdfFileWriteable ncfile = NetcdfFileWriteable.createNew((filename + ".nc"), true);
    //Define Dimensions
    Dimension latDim = ncfile.addDimension("lat", 51);
    Dimension longDim = ncfile.addDimension("long", 101);
    Dimension satDim = ncfile.addDimension("sat", 33);
    Dimension timeDim = ncfile.addDimension("time", 96);
    //Define latitude variable and attributes
    ncfile.addVariable("lat", DataType.INT, "lat");
    ncfile.addVariableAttribute("lat", new Attribute("units", "degrees_north"));
    ncfile.addVariableAttribute("lat", new Attribute("long_name", "Latitude"));
    Array data = Array.factory( int.class, new int [] {2}, new int[] {10,60});
    ncfile.addVariableAttribute("lat", new Attribute("actual_range", data));
    //Define longitude variable and attributes
    ncfile.addVariable("long", DataType.INT, "long");
    ncfile.addVariableAttribute("long", new Attribute("units", "degrees_west"));
    ncfile.addVariableAttribute("long", new Attribute("long_name", "Longitude"));
    data = Array.factory( int.class, new int [] {2}, new int[] {50,150});
    ncfile.addVariableAttribute("long", new Attribute("actual_range", data));
    //Define time variable and attributes
    ncfile.addVariable("time", DataType.INT, "time");
    ncfile.addVariableAttribute("time", new Attribute("units", ("minuets since " + dateTool.string(date) + " 00:00UT")));
    ncfile.addVariableAttribute("time", new Attribute("long_name", "Time"));
    ncfile.addVariableAttribute("time", new Attribute("delta_t", "00:15:00"));
    //Define satellite variable and attributes
    ncfile.addVariable("sat", DataType.INT, "sat");
    ncfile.addVariableAttribute("sat", new Attribute("units", "NAVSTAR GPS Satellite #"));
    ncfile.addVariableAttribute("sat", new Attribute("long_name", "Satellite"));
    ncfile.addVariableAttribute("sat", new Attribute("vertical_TEC", "Satellite #0"));
    //Define TEC variable and attributes
    ArrayList<Dimension> dims = new ArrayList<Dimension>();
    dims.add(timeDim);
    dims.add(latDim);
    dims.add(longDim);
    dims.add(satDim);
    ncfile.addVariable("TEC", DataType.FLOAT, dims);
    ncfile.addVariableAttribute("TEC", new Attribute("precision", 1));
    ncfile.addVariableAttribute("TEC", new Attribute("least_significant_digit", 10));
    ncfile.addVariableAttribute("TEC", new Attribute("units", "TECU (10^16 electrons/m^2)"));
    //Define global attributes
    ncfile.addGlobalAttribute("creation_date", dateTool.string(date));
    ncfile.setFill(true);
    try {
        ncfile.create();
    } catch (IOException e) {
        System.out.println("ERROR creating file "+ncfile.getLocation()+"\n"+e);
    }
    ncfile.close();

现在我的问题是......如何在名为“TEC”的四维变量中的特定点插入三维数组?它应该是前进的,但我已经浏览了java netcdf教程,我似乎无法找到一个例子。如果有人能指出我正确的方向,那就太棒了。谢谢! -dom

P.S。这是由此代码创建的模板.nc文件:http://dl.dropbox.com/u/8058705/USTEC_netcdf/netcdf/2011_08_31.nc另外......我尝试使用ncfile.write(“var_name”,array),但我认为netcdf 4甚至不再使用write函数。 writeCDL函数使用OutputStreams,所以我试试看。

0 个答案:

没有答案