来自 Fortran 代码的 Rectilinear_grid 的二进制 vtk 不能由 paraview 工作

binary vtk for Rectilinear_grid from fortran code can not worked by paraview

我使用了从 Whosebug 发布的代码并将其修改为:

program VTKBinary

implicit none

real*4    :: x(2) = (0., 1.)
real*4    :: y(2) = (0., 1.)
real*4    :: z(2) = (0., 1.)

character :: buffer*80, lf*1, str1*8, str2*8, str3*8
integer   :: ivtk = 9, int,i

lf = char(10) ! line feed character

!open(unit=ivtk,file='test_bin.vtk',form='binary',convert='BIG_ENDIAN')
open(unit=ivtk,file='test_bin.vtk',access='stream',convert='BIG_ENDIAN')

buffer = '# vtk DataFile Version 3.0'//lf      ; write(ivtk) trim(buffer)
buffer = 'vtk output'//lf                      ; write(ivtk) trim(buffer)
buffer = 'BINARY'//lf                          ; write(ivtk) trim(buffer)
buffer = 'DATASET RECTILINEAR_GRID'//lf        ; write(ivtk) trim(buffer)

! WRITE GRID
write(str1(1:8),'(i8)') size(x)
write(str2(1:8),'(i8)') size(y)
write(str3(1:8),'(i8)') size(z)
buffer = 'DIMENSIONS '//str1//str2//str3//lf         ; write(ivtk) trim(buffer)
buffer = 'X_COORDINATES '//str1//'  float'//lf                 ; write(ivtk) trim(buffer)
!write(ivtk) x
write(ivtk) (x(i),i=1,size(x))
buffer = lf//'Y_COORDINATES '//str2//'  float'//lf             ; write(ivtk) trim(buffer)
!write(ivtk) y
write(ivtk) (y(i),i=1,size(y))
buffer = lf//'Z_COORDINATES '//str3//'  float'//lf             ; write(ivtk) trim(buffer)
!write(ivtk) z
write(ivtk) (z(i),i=1,size(z))

close(ivtk)

end program VTKBinary

这段代码是gfortran编译好的,生成vtk文件运行良好。

问题:paraview读取vtk报错如下:

Warning: In C:\DBD\pvs-x64\paraview\src\paraview\VTK\Rendering\Core\vtkRenderer.cxx, line 1029
vtkOpenGLRenderer (000000000BF00BF0): Resetting view-up since view plane normal is parallel

问题:你能帮我解决这个问题吗?

非常感谢。

@AlexanderVoigt 指出了主要问题。数组被指定为 [0., 1.],而不是 (0., 1.),那将是一个等于一个虚数单位的复数 i.

另外一个问题是最后少了lf。只需使用

buffer = 'X_COORDINATES '//str1//'  float'//lf             ; write(ivtk) trim(buffer)
write(ivtk) x, lf
buffer = 'Y_COORDINATES '//str2//'  float'//lf             ; write(ivtk) trim(buffer)
write(ivtk) y, lf
buffer = 'Z_COORDINATES '//str3//'  float'//lf             ; write(ivtk) trim(buffer)
write(ivtk) z, lf

最好总是把 lf 放在最后,以免忘记。

顺便说一句,您不必将字符串放入缓冲区然后 trim 它,您甚至可以直接写入它们:

write(ivtk) 'X_COORDINATES '//str1//'  float'//lf