Netcdf 和 Fortran 结构
我有这个 Fortran 结构。
type custom
real :: a,b
real,dimension(20) ::c,d
real,dimension(20,50) :: e
end type custom
然后我有另一个像这样的结构
type custom2
type(custom):: data
end type custom2
,现在我创建一个对象类型(custom2)::pntr
是否可以将自定义结构中的所有数据直接写入 netcdf 格式,并使用所有组件的名称(即 a、b、c ,d,e) 相同。当然这是使用pntr(object)。 HDF5 中的任何解决方案也受到欢迎。提前致谢
I have this fortran structure.
type custom
real :: a,b
real,dimension(20) ::c,d
real,dimension(20,50) :: e
end type custom
Then I have another structure like this
type custom2
type(custom):: data
end type custom2
now i make an object type(custom2)::pntr
is it possible to write all the data in the structure custom in to netcdf format directly with all the names of the components (i.e. a,b,c,d,e) to be the same. Of course this is using pntr(object). Any solution of this in HDF5 is also welcome. Thanks in advance
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
原则上,是的,这对于 NetCDF4 是可能的;您正在寻找 用户手册的定义数据类型部分。
然而,对它的支持很差,可能会导致问题(即使在 F90 中,您最终也可能不得不使用 f77 接口)。这是我真正的第一次尝试,我无法编译它,因为 F90 绑定不允许 nf90_put_var 调用。还要注意,神奇之处在于计算偏移量,这在 Fortran 中并不简单(但如果您也使用 MPI,则可以使用 MPI_Get_Address 进行操作...)。 loc() 是一个常见但非标准的函数,它允许您执行此操作,如果您信任指针数学,您也可以使用 iso_c_bindings 和 c_loc() 。
In principle, yes, this is possible with NetCDF4; you're looking for the User Defined Data Types section of the manual.
However, the support for it is poor enough that it may cause problems (and you may end up having to use the f77 interface even in F90). Here's my really hacky first attempt, which I can't get to compile because the F90 bindings don't allow the nf90_put_var call. Note too that the magic is all in calculating the offsets, which is non-trivial in Fortran (but is doaable using MPI_Get_Address if you're also using MPI...). loc() is a common but non-standard function which would allow you to do this, and you could also use iso_c_bindings and c_loc() if you trust the pointer math.