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

穿精又带淫゛_ 提交于 2020-01-11 11:57:45

问题


I used the code posted from stackoverflow and modified it as:

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

This code is compiled well by gfortran and it runs well to generate vtk file.

Problem: there is an error when the vtk is read by paraview as following:

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

Question: can you help me to solve this problem?

Many thanks.


回答1:


The main issue was pointed out by @AlexanderVoigt. Arrays are specified as [0., 1.], not as (0., 1.), that would be a complex number equal to one imaginary unit i.

The other problem is missing lf at the end. Just use

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

It is better to always put the lf at the end so you do not forget it.

BTW you do not have to put the strings in a buffer and then trim it, you can even write them directly:

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


来源:https://stackoverflow.com/questions/35299579/binary-vtk-for-rectilinear-grid-from-fortran-code-can-not-worked-by-paraview

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!