java读写netcdf文件_将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 dims = new ArrayList();

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

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

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值