我正在尝试编写一个带有可变长度变量的 netCDF-4 文件。
理想情况下,我会使用 ncgen 实用程序,但它不支持ncml输入。因此,我使用的是 netCDF-java lib 4.6.6。以下没有可变长度变量的 ncml 生成一个可用的 netCDF-4 文件:
java -Xmx1g -classpath ~/dump/netcdfAll-4.6.6.jar ucar.nc2.dataset.NetcdfDataset -in test.ncml -out test.nc4 -netcdf4
这是对应的ncml/xml:
<?xml version="1.0" encoding="UTF-8"?>
<netcdf xmlns="http://www.unidata.ucar.edu/namespaces/netcdf/ncml-2.2" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://what.no">
<group name="data">
<dimension name="number_packets" length="6"/>
<variable name="packet_time_utc" shape="number_packets" type="double">
</variable>
</group>
</netcdf>
如果我向 ncml 添加另一个无限维度,则会发生故障
<?xml version="1.0" encoding="UTF-8"?>
<netcdf xmlns="http://www.unidata.ucar.edu/namespaces/netcdf/ncml-2.2" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://what.no">
<group name="data">
<dimension name="number_packets" length="6" isVariableLength="true" isShared="false"/>
<variable name="packet_time_utc" shape="number_packets" type="double">
</variable>
</group>
</netcdf>
根据 ncml schema,维度的定义是正确的。错误消息NetCDF:找不到变量:
NetcdfDatataset read from test-vlen.ncml write to test-Vlen.nc4 java.io.IOException: -49: NetCDF: Variable not found
at ucar.nc2.jni.netcdf.Nc4Iosp.writeData(Nc4Iosp.java:2835)
at ucar.nc2.jni.netcdf.Nc4Iosp.writeData(Nc4Iosp.java:2789)
at ucar.nc2.NetcdfFileWriter.write(NetcdfFileWriter.java:954)
at ucar.nc2.NetcdfFileWriter.write(NetcdfFileWriter.java:938)
at ucar.nc2.FileWriter2.copyAll(FileWriter2.java:431)
at ucar.nc2.FileWriter2.copyVarData(FileWriter2.java:384)
at ucar.nc2.FileWriter2.write(FileWriter2.java:199)
at ucar.nc2.dataset.NetcdfDataset.main(NetcdfDataset.java:1888)
Exception in thread "main" java.io.IOException: -101: NetCDF: HDF error
at ucar.nc2.jni.netcdf.Nc4Iosp.close(Nc4Iosp.java:289)
at ucar.nc2.NetcdfFileWriter.abort(NetcdfFileWriter.java:1032)
at ucar.nc2.FileWriter2.write(FileWriter2.java:207)
at ucar.nc2.dataset.NetcdfDataset.main(NetcdfDataset.java:1888)
按照此处length="*"
的建议指定,会导致不同的 NumberFormatException 错误。
我正在使用可用的最新版本:
- HDF 1.8.17
- netcdf C 4.4.0
- netCDF-java 库 4.6.6
错误是关于找不到变量(FileWrite 想要复制所有变量)。但是,我一直试图找到错误的根源。