确定NetCDF中HDF5变量的签名状态 [英] Determining signed state for HDF5 variables in NetCDF

查看:141
本文介绍了确定NetCDF中HDF5变量的签名状态的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的团队已获得要读取的HDF5文件.它们包含带有无符号变量的结构化数据.我和我的团队很高兴找到NetCDF库,尽管使用NetCDF数据模型,该库仍允许纯Java读取HDF5文件.

My team has been given HDF5 files to read. They contain structured data with unsigned variables. I and my team were overjoyed to find the NetCDF library, which allows pure-Java reading of HDF5 files, albeit using the NetCDF data model.

没问题-我们认为我们只是将NetCDF数据模型转换为我们想要的任何模型.只要我们得到数据.然后,我们尝试从HDF5文件中读取一个无符号的32位整数.我们可以加载HDFView 2.9,然后看到该变量是一个无符号的32位整数.但是...事实证明, NetCDF-3不会'不支持无符号值

No problem---we thought we'd just translate from the NetCDF data model to whatever model we wanted. As long as we get the data out. Then we tried to read an unsigned 32-bit integer from the HDF5 file. We can load up HDFView 2.9 and see that the variable is an unsigned 32-bit integer. But... it turns out that NetCDF-3 doesn't support unsigned values!

为了增加侮辱性伤害,NetCDF-3建议您扩大数据类型"或使用_Unsigned = "true"属性(我没有做这个)来指示应将32位视为无符号值.

To add insult to injury, NetCDF-3 recommends that you "widen the data type" or use an _Unsigned = "true" attribute (I am not making this up) to indicate that the 32 bits should be treated as an unsigned value.

好吧,如果我是从头开始创建NetCDF数据的话,这些合并也许会有效,但是如何使用NetCDF检测到现有HDF5文件中的32位值应解释为未签名?

Well, maybe those kludges would be effective if I were creating NetCDF data from scratch, but how can I detect using NetCDF that a 32-bit value in an existing HDF5 file should be interpreted as unsigned?

更新:显然我在ucar.ma2.DataType中看不到任何未签名的类型.

Update: Apparently NetCDF-4 does support unsigned data types. So this begs the question: How can I determine whether a value is signed or unsigned from the NetCDF Java library?" I don't see any unsigned types in ucar.ma2.DataType.

推荐答案

是的,您可以查找_Unsigned ="true"属性,也可以调用Variable.isUnsigned().

Yes, you can look for _Unsigned = "true" attribute, or you can call Variable.isUnsigned().

由于Java不支持无符号类型,因此这是一个艰难的设计决策.最终,为了提高效率,我们决定不自动加宽类型.因此,应用程序必须检查并做正确的事情.查看ucar.nc2.DataType.unsignedXXX()帮助器方法.

Because Java doesnt support unsigned types, it was a difficult design decision. Ultimately we decided not to automatically widen the type, for efficiency. So the application must check and do the right thing. Look at ucar.nc2.DataType.unsignedXXX() helper methods.

读取数据时,将获得一个Array对象.您可以调用Array.isUnsigned().同样,像Array.getDouble()这样的提取器也可以正确转换.

When you read the data, you get an Array object. you can call Array.isUnsigned(). Also the extractors like Array.getDouble() will convert correctly.

netCDF-Java库支持称为通用数据模型"的扩展数据模型,以抽象出文件格式的差异.因此,我们不受netCDF-3文件格式或数据模型的限制.但是我们在Java中

The netCDF-Java library supports an extended data model called the "Common data Model" to abstract out differences in file formats. So we are not stuck with the limits of the netCDF-3 file format or data model. But we are in Java

约翰

这篇关于确定NetCDF中HDF5变量的签名状态的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆