有 Java 编程相关的问题?

你可以在下面搜索框中键入要查询的问题!

数据库将java数组传递到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教程,似乎找不到一个例子。如果有人能给我指出正确的方向,那就太棒了。谢谢-多姆

这里是一个模板。由以下代码创建的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) 个答案