-
Notifications
You must be signed in to change notification settings - Fork 0
/
Read_Vtk_Mesh.f90
61 lines (50 loc) · 2.23 KB
/
Read_Vtk_Mesh.f90
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
!==============================================================================!
subroutine Read_Vtk_Mesh(msh, full_name)
!------------------------------------------------------------------------------!
! Reads vtk files created and allocates memory for the mesh along the way !
! !
! It was designed to read meshes obtained from "Neu_2_Vtu" utility !
! (in folder Meshes) and closely follows its formats (a7,i6,a6) etc. !
!------------------------------------------------------------------------------!
!----------------------------------[Modules]-----------------------------------!
use Mesh_Mod, only: Mesh_Type
!------------------------------------------------------------------------------!
implicit none
!---------------------------------[Arguments]----------------------------------!
type(Mesh_Type) :: msh
character(len=*) :: full_name
!-----------------------------------[Locals]-----------------------------------!
integer :: k, c, n
real :: tmp
character(len=80) :: line
!------------------------------[Local parameters]------------------------------!
integer, parameter :: VTK = 9
!==============================================================================!
open(VTK, file=trim(full_name), form='formatted')
!-----------------!
! Skip header !
!-----------------!
read(VTK,*) line; read(VTK,*) line; read(VTK,*) line; read(VTK,*) line;
!-------------------!
! Nodes section !
!-------------------!
read(VTK, '(a7,i6,a6)') line(1:7), msh % n_nodes, line(41:47)
allocate(msh % yn(msh % n_nodes))
allocate(msh % zn(msh % n_nodes))
do n = 1, msh % n_nodes
read(VTK, *) tmp, msh % yn(n), msh % zn(n)
end do
!-------------------!
! Cells section !
!-------------------!
read(VTK, '(a6,i6,a6)') line(1:6), msh % n_cells, line(41:47)
allocate(msh % yc(msh % n_cells))
allocate(msh % zc(msh % n_cells))
allocate(msh % cells_nodes(4, msh % n_cells))
allocate(msh % area(msh % n_cells))
do c = 1, msh % n_cells
read(VTK, *) k, msh % cells_nodes(1:4, c)
end do
msh % cells_nodes(:,:) = msh % cells_nodes(:,:) + 1
close(VTK)
end subroutine