我是fortran的新手。我正在尝试使用 fortran 95 以 CGNS 格式编写 Flow 解决方案。我编写了 fortran 代码并为 python 创建了这个 fortran 代码的库。我想使用这个库来编写*.npy
格式*.cgns
格式的网格和流数据。我的fortran代码片段如下
subroutine un_2d_tr(filename, zoneName)
implicit none
include 'cgnslib_f.h'
character(*) fileName, zoneName
integer :: ier, cellDim, physDim, nelem_start, nelem_end, nbdyelem
integer :: iFile, iB, iCoordX, iCoordY, iSection, iFlow, iu, iv
integer, dimension(1,3) :: isize
character(len=32) :: basename, solname
! --------------------------------------------------------------------
! open CGNS file to write OR edit and create/read base
basename = 'Base'
! In 2D unstr.
cellDim=2
physDim=2
call cg_open_f(fileName,cg_mode_write,iFile,ier)
call check_cg_error_f(ier)
! write base
call cg_base_write_f(iFile,basename,cellDim,physDim, iB,ier)
call check_cg_error_f(ier)
...
我继续脚本将网格和流速写入 cgns 文件。使用 to write 打开新文件没有错误cg_open_f()
(错误状态 ier 为 0)。但是,当我尝试在打开的文件中使用cg_write_f()
或(用于编写基本流程)编写内容时,出现以下错误cg_base_write_f()
CGNS file 0 is not open
如果需要,我可以发布完整的 fortran 子例程。有没有人对如何纠正这个错误有任何建议?这可能是我的 linux 发行版的问题吗?如果有帮助,我使用的是 Ubuntu 17.10。我已包括check_cg_error_f()
以下内容。
subroutine check_cg_error_f(ier)
implicit none
include 'cgnslib_f.h'
integer ier
if (ier .ne. CG_OK) then
call cg_error_exit_f
endif
end
我用来搭建cgns库的cmake文件如下
BUILD_CGNSTOOLS OFF
CGNS_BUILD_SHARED ON
CGNS_USE_SHARED ON
CMAKE_BUILD_TYPE Release
CMAKE_INSTALL_PREFIX /home/adhitya/.local/cgns/3.1.4
ENABLE_64BIT ON
ENABLE_FORTRAN ON
ENABLE_HDF5 ON
ENABLE_SCOPING OFF
ENABLE_TESTS OFF
FORTRAN_NAMING LOWERCASE_
HDF5_INCLUDE_PATH /home/adhitya/.local/hdf5/1.8.16/include
HDF5_LIBRARY /home/adhitya/.local/hdf5/1.8.16/lib/libhdf5.so
HDF5_NEED_MPI OFF
HDF5_NEED_SZIP ON
HDF5_NEED_ZLIB ON
SZIP_LIBRARY /home/adhitya/.local/szip/lib/libsz.so
ZLIB_LIBRARY /home/adhitya/.local/zlib/lib/libz.so
cmake 构建版本 3.3.1
CGNS_BUILD_CGNSTOOLS OFF
CGNS_BUILD_SHARED ON
CGNS_BUILD_TESTING OFF
CGNS_ENABLE_64BIT ON
CGNS_ENABLE_BASE_SCOPE OFF
CGNS_ENABLE_FORTRAN ON
CGNS_ENABLE_HDF5 ON
CGNS_ENABLE_MEM_DEBUG OFF
CGNS_ENABLE_SCOPING OFF
CGNS_ENABLE_TESTS OFF
CGNS_USE_SHARED ON
CMAKE_BUILD_TYPE Release
CMAKE_INSTALL_PREFIX /home/adhitya/.local/cgns/3.3.1
HDF5_C_LIBRARY_dl /usr/lib/x86_64-linux-gnu/libdl.so
HDF5_C_LIBRARY_hdf5 /home/adhitya/.local/hdf5/lib/libhdf5.so
HDF5_C_LIBRARY_m /usr/lib/x86_64-linux-gnu/libm.so
HDF5_C_LIBRARY_sz /usr/lib/x86_64-linux-gnu/libsz.so
HDF5_C_LIBRARY_z /usr/lib/x86_64-linux-gnu/libz.so
HDF5_DIR HDF5_DIR-NOTFOUND
HDF5_NEED_MPI OFF
HDF5_NEED_SZIP ON
HDF5_NEED_ZLIB ON
SZIP_LIBRARY /home/adhitya/.local/szip/lib/libsz.so
ZLIB_LIBRARY /usr/lib/x86_64-linux-gnu/libz.so