-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSwanVTKWriteData.ftn90
207 lines (207 loc) · 7.43 KB
/
SwanVTKWriteData.ftn90
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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
subroutine SwanVTKWriteData ( uvtk, pstype, nvar, ivtyp, voqr, data, lenp, mxk, myk, ionod )
!
! --|-----------------------------------------------------------|--
! | Delft University of Technology |
! | Faculty of Civil Engineering and Geosciences |
! | Environmental Fluid Mechanics Section |
! | P.O. Box 5048, 2600 GA Delft, The Netherlands |
! | |
! | Programmer: Marcel Zijlema |
! --|-----------------------------------------------------------|--
!
!
! SWAN (Simulating WAves Nearshore); a third generation wave model
! Copyright (C) 1993-2024 Delft University of Technology
!
! This program is free software: you can redistribute it and/or modify
! it under the terms of the GNU General Public License as published by
! the Free Software Foundation, either version 3 of the License, or
! (at your option) any later version.
!
! This program is distributed in the hope that it will be useful,
! but WITHOUT ANY WARRANTY; without even the implied warranty of
! MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
! GNU General Public License for more details.
!
! You should have received a copy of the GNU General Public License
! along with this program. If not, see <http://www.gnu.org/licenses/>.
!
!
! Authors
!
! 41.95: Marcel Zijlema
!
! Updates
!
! 41.95, July 2022: New subroutine
!
! Purpose
!
! Writes appended data to a VTK file
!
! Method
!
! See https://vtk.org/wp-content/uploads/2015/04/file-formats.pdf
!
! Modules used
!
use ocpcomm4
use swcomm1
use m_parall
use outp_data
use SwanGriddata
use SwanGridobjects
!
implicit none
!
! Argument variables
!
integer, intent(in) :: lenp ! length of piece data
integer, intent(in) :: mxk ! number of points in x-direction of frame
integer, intent(in) :: myk ! number of points in y-direction of frame
integer, intent(in) :: nvar ! number of output variables
integer, intent(in) :: uvtk ! unit number of VTK file
!
integer, dimension(nvar) , intent(in) :: ivtyp ! types of output variable
integer, dimension(nmovar), intent(in) :: voqr ! pointer in list of variables
!
integer, dimension(*), intent(in) :: ionod ! indicates in which subdomain nodes are located
!
real*4 , dimension(mxk*myk,*), intent(in) :: data ! output data
!
character(1), intent(in) :: pstype ! type of output point set
!
! Parameter variables
!
integer , parameter :: datasize = 4 ! number of bytes of integers and reals
integer , parameter :: ndim = 3 ! space dimension
! (set to 3 as required by Paraview)
integer , parameter :: nov = 3 ! number of vertices in cell (triangles only)
integer*1 , parameter :: ptype = 5 ! polygon type (5 = triangle)
character(1), parameter :: lf = char(10) ! line feed character
!
! Local variables
!
integer :: i ! loop counter
integer, save :: ient = 0 ! number of entries in this subroutine
integer :: ip ! local pointer
integer :: iproc ! processor number
integer :: ios ! I/O status
integer :: ivtype ! type of output quantity
integer :: j ! loop counter
integer :: jvar ! loop counter over output variables
integer*4 :: nbytes ! number of bytes in the block of data
integer :: v1 ! first vertex of cell
integer :: v2 ! second vertex of cell
integer :: v3 ! third vertex of cell
!
character(80) :: msgstr ! string to pass message
!
type(celltype), dimension(:), pointer :: cell ! datastructure for cells with their attributes
!
! Structure
!
! Description of the pseudo code
!
! Source text
!
if (ltrace) call strace (ient,'SwanVTKWriteData')
!
! point to cell object
!
cell => gridobject%cell_grid
!
ios = 0
!
iproc = INODE
!
! write the output data
!
do jvar = 1, nvar
!
ivtype = ivtyp(jvar)
!
if ( ovsvty(ivtype) < 3 ) then ! scalars
!
nbytes = lenp * datasize
!
if ( ios == 0 ) write(uvtk,iostat=ios) nbytes
do j = 1, myk
ip = (j-1)*mxk
do i = 1, mxk
if ( ios == 0 .and. ionod(ip+i) == iproc ) write(uvtk,iostat=ios) data(ip+i,voqr(ivtype))
enddo
enddo
!
else ! vectors (three components per node!)
!
nbytes = ndim * lenp * datasize
!
if ( ios == 0 ) write(uvtk,iostat=ios) nbytes
do j = 1, myk
ip = (j-1)*mxk
do i = 1, mxk
if ( ios == 0 .and. ionod(ip+i) == iproc ) write(uvtk,iostat=ios) data(ip+i,voqr(ivtype)), data(ip+i,voqr(ivtype)+1), 0.
enddo
enddo
!
endif
!
enddo
!
! write coordinates
! note: three components per node are required by Paraview, therefore add z = 0
!
nbytes = ndim * lenp * datasize
if ( ios == 0 ) write(uvtk,iostat=ios) nbytes
do j = 1, myk
ip = (j-1)*mxk
do i = 1, mxk
if ( ios == 0 .and. ionod(ip+i) == iproc ) write(uvtk,iostat=ios) data(ip+i,voqr(1)), data(ip+i,voqr(2)), 0.
enddo
enddo
!
if ( pstype == 'U' ) then
!
! connectivity
! note: Triangle connectivity list start with 1, here 0
!
nbytes = nov * ncells * datasize
if ( ios == 0 ) write(uvtk,iostat=ios) nbytes
do j = 1, ncells
v1 = cell(j)%face(1)%atti(FACEV1) -1
v2 = cell(j)%face(2)%atti(FACEV1) -1
v3 = cell(j)%face(3)%atti(FACEV1) -1
if ( ios == 0 ) write(uvtk,iostat=ios) v1, v2, v3
enddo
!
! write offset into the connectivity array for the end of each cell
!
nbytes = ncells * datasize
if ( ios == 0 ) write(uvtk,iostat=ios) nbytes
if ( ios == 0 ) write(uvtk,iostat=ios) (j, j=nov, nov*ncells, nov)
!
! write cell type
!
nbytes = ncells * datasize
if ( ios == 0 ) write(uvtk,iostat=ios) nbytes
if ( ios == 0 ) write(uvtk,iostat=ios) (ptype, j=1, ncells)
!
endif
!
vtkline = lf//' </AppendedData>'//lf
if ( ios == 0 ) write(uvtk,iostat=ios) trim(vtkline)
!
! end of the file
!
vtkline = '</VTKFile>'//lf
if ( ios == 0 ) write(uvtk,iostat=ios) trim(vtkline)
!
! if necessary, give message that error occurred while writing file
!
if ( ios /= 0 ) then
write (msgstr, '(a,i5)') 'Error while writing VTK file - iostat number =',ios
call msgerr( 2, trim(msgstr) )
endif
!
end subroutine SwanVTKWriteData