Передать массив Java в файл netcdf - PullRequest
1 голос
/ 01 сентября 2011

Моя программа читает файлы 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

PS Вот файл шаблона .nc, созданный этим кодом: http://dl.dropbox.com/u/8058705/USTEC_netcdf/netcdf/2011_08_31.nc Также ... Я попытался использовать ncfile.write ("var_name", array), но я не думаю, чтоnetcdf 4 даже больше не использует функцию записи.Функция writeCDL использует OutputStreams, поэтому я попробую.

...