-
Notifications
You must be signed in to change notification settings - Fork 5
/
vtk_io.f90
510 lines (452 loc) · 11.8 KB
/
vtk_io.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
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
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
module vtk_io
!use connectivity, only: element_data,node_data
!use initialization, only:U_dt
!use extract, only:sig,eps
use connectivity
use initialization, only:disp_type
use extract,only:stress_type
implicit none
integer,parameter::element_order=4
character(len=80) ::title
contains
subroutine digit_to_ch ( digit, ch )
!*****************************************************************************80
!
!
!! DIGIT_TO_CH returns the character representation of a decimal digit.
!
! Discussion:
!
! Instead of CHAR, we now use the ACHAR function, which
! guarantees the ASCII collating sequence.
!
! Example:
!
! DIGIT CH
! ----- ---
! 0 '0'
! 1 '1'
! ... ...
! 9 '9'
! 17 '*'
!
! Licensing:
!
! This code is distributed under the GNU LGPL license.
!
! Modified:
!
! 04 August 1999
!
! Author:
!
! John Burkardt
!
! Parameters:
!
! Input, integer ( kind = 4 ) DIGIT, the digit value between 0 and 9.
!
! Output, character CH, the corresponding character.
!
character ch
integer ( kind = 4 ) digit
if ( 0 <= digit .and. digit <= 9 ) then
ch = achar ( digit + 48 )
else
ch = '*'
end if
return
end subroutine digit_to_ch
subroutine get_unit ( iunit )
!*****************************************************************************80
!
!! GET_UNIT returns a free FORTRAN unit number.
!
! Discussion:
!
! A "free" FORTRAN unit number is an integer between 1 and 99 which
! is not currently associated with an I/O device. A free FORTRAN unit
! number is needed in order to open a file with the OPEN command.
!
! If IUNIT = 0, then no free FORTRAN unit could be found, although
! all 99 units were checked (except for units 5, 6 and 9, which
! are commonly reserved for console I/O).
!
! Otherwise, IUNIT is an integer between 1 and 99, representing a
! free FORTRAN unit. Note that GET_UNIT assumes that units 5 and 6
! are special, and will never return those values.
!
! Licensing:
!
! This code is distributed under the GNU LGPL license.
!
! Modified:
!
! 26 October 2008
!
! Author:
!
! John Burkardt
!
! Parameters:
!
! Output, integer ( kind = 4 ) IUNIT, the free unit number.
!
integer ( kind = 4 ) ios
integer ( kind = 4 ) i
integer ( kind = 4 ) iunit
logical lopen
iunit = 0
do i = 1, 99
if ( i /= 5 .and. i /= 6 .and. i /= 9 ) then
inquire ( unit = i, opened = lopen, iostat = ios )
if ( ios == 0 ) then
if ( .not. lopen ) then
iunit = i
return
end if
end if
end if
end do
return
end subroutine
subroutine i4_to_s_left ( i4, s )
!*****************************************************************************80
!
!! I4_TO_S_LEFT converts an I4 to a left-justified string.
!
! Discussion:
!
! An I4 is an integer ( kind = 4 ).
!
! Example:
!
! Assume that S is 6 characters long:
!
! I4 S
!
! 1 1
! -1 -1
! 0 0
! 1952 1952
! 123456 123456
! 1234567 ****** <-- Not enough room!
!
! Licensing:
!
! This code is distributed under the GNU LGPL license.
!
! Modified:
!
! 28 July 2000
!
! Author:
!
! John Burkardt
!
! Parameters:
!
! Input, integer ( kind = 4 ) I4, an integer to be converted.
!
! Output, character ( len = * ) S, the representation of the integer.
! The integer will be left-justified. If there is not enough space,
! the string will be filled with stars.
!
character c
integer ( kind = 4 ) i
integer ( kind = 4 ),intent(in):: i4
integer ( kind = 4 ) idig
integer ( kind = 4 ) ihi
integer ( kind = 4 ) ilo
integer ( kind = 4 ) ipos
integer ( kind = 4 ) ival
character ( len = * ),intent(out):: s
s = ' '
ilo = 1
ihi = len ( s )
if ( ihi <= 0 ) then
return
end if
!
! Make a copy of the integer.
!
ival = i4
!
! Handle the negative sign.
!
if ( ival < 0 ) then
if ( ihi <= 1 ) then
s(1:1) = '*'
return
end if
ival = -ival
s(1:1) = '-'
ilo = 2
end if
!
! The absolute value of the integer goes into S(ILO:IHI).
!
ipos = ihi
!
! Find the last digit of IVAL, strip it off, and stick it into the string.
!
do
idig = mod ( ival, 10 )
ival = ival / 10
if ( ipos < ilo ) then
do i = 1, ihi
s(i:i) = '*'
end do
return
end if
call digit_to_ch ( idig, c )
s(ipos:ipos) = c
ipos = ipos - 1
if ( ival == 0 ) then
exit
end if
end do
!
! Shift the string to the left.
!
s(ilo:ilo+ihi-ipos-1) = s(ipos+1:ihi)
s(ilo+ihi-ipos:ihi) = ' '
return
end subroutine
subroutine timestamp ( )
!*****************************************************************************80
!
!! TIMESTAMP prints the current YMDHMS date as a time stamp.
!
! Example:
!
! 31 May 2001 9:45:54.872 AM
!
! Licensing:
!
! This code is distributed under the GNU LGPL license.
!
! Modified:
!
! 18 May 2013
!
! Author:
!
! John Burkardt
!
! Parameters:
!
! None
!
character ( len = 8 ) ampm
integer ( kind = 4 ) d
integer ( kind = 4 ) h
integer ( kind = 4 ) m
integer ( kind = 4 ) mm
character ( len = 9 ), parameter, dimension(12) :: month = (/ &
'January ', 'February ', 'March ', 'April ', &
'May ', 'June ', 'July ', 'August ', &
'September', 'October ', 'November ', 'December ' /)
integer ( kind = 4 ) n
integer ( kind = 4 ) s
integer ( kind = 4 ) values(8)
integer ( kind = 4 ) y
call date_and_time ( values = values )
y = values(1)
m = values(2)
d = values(3)
h = values(5)
n = values(6)
s = values(7)
mm = values(8)
if ( h < 12 ) then
ampm = 'AM'
else if ( h == 12 ) then
if ( n == 0 .and. s == 0 ) then
ampm = 'Noon'
else
ampm = 'PM'
end if
else
h = h - 12
if ( h < 12 ) then
ampm = 'PM'
else if ( h == 12 ) then
if ( n == 0 .and. s == 0 ) then
ampm = 'Midnight'
else
ampm = 'AM'
end if
end if
end if
write ( *, '(i2,1x,a,1x,i4,2x,i2,a1,i2.2,a1,i2.2,a1,i3.3,1x,a)' ) &
d, trim ( month(m) ), y, h, ':', n, ':', s, '.', mm, trim ( ampm )
return
end subroutine
subroutine vtk_essential_write ( output_unit, title, node_nums, element_nums, &
element_order, node, element)
!*****************************************************************************80
!
!! VTK_PUVW_WRITE writes stress (sigxx,sigyy,sigxy) data to a VTK file.
!
! Licensing:
!
! This code is distributed under the GNU LGPL license.
!
! Modified:
!
! 26 March 2009
!
! Author:
!
! John Burkardt
!
! Parameters:
!
! Input, integer ( kind = 4 ) OUTPUT_UNIT, the unit number of the file.
!
! Input, character ( len = * ) TITLE, a title for the data.
!
! Input, integer ( kind = 4 ) NODE_NUM, the number of nodes.
!
! Input, integer ( kind = 4 ) ELEMENT_NUM, the number of elements.
!
! Input, integer ( kind = 4 ) ELEMENT_ORDER, the order of the elements
! (number of nodes in an element)
!
! Input, real ( kind = 8 ) XYZ(3,NODE_NUM), the node coordinates.
!
! Input, integer ( kind = 4 ) ELEMENT_NODE(ELEMENT_ORDER,ELEMENT_NUM), the
! nodes that make up each element.
!
! Input, real ( kind = 8 ) P(NODE_NUM), the pressure at each node.
!
! Input, real ( kind = 8 ) UVW(3,NODE_NUM), the velocity at each node.
!
character(len=*),intent(in):: title
integer ( kind = 4 ),intent(in) :: output_unit
integer ( kind = 4 ),intent(in) :: element_nums
integer ( kind = 4 ),intent(in) :: element_order
integer ( kind = 4 ),intent(in) :: node_nums
type(element_type), intent(in) :: element
type(node_type), intent(in) :: node
character ( len = 20 ) cell_size_string
character ( len = 20 ) element_num_string
character ( len = 20 ) node_num_string
integer ( kind = 4 ) :: node_id,el_id
call i4_to_s_left ( node_nums, node_num_string )
call i4_to_s_left ( element_nums, element_num_string )
call i4_to_s_left ( element_nums * ( element_order + 1 ), cell_size_string )
write ( output_unit, '(a)' ) '# vtk DataFile Version 2.0'
write ( output_unit, '(a)' ) title
write ( output_unit, '(a)' ) 'ASCII'
write ( output_unit, '(a)' ) 'DATASET UNSTRUCTURED_GRID'
write ( output_unit, '(a)' ) 'POINTS ' // trim (node_num_string ) // ' double'
do node_id = 1, node_nums
write ( output_unit, '(2x,g14.6,2x,g14.6,2x,g14.6)' ) &
node%coord(node_id,1:2),0.d0
end do
!
! Note that the element node indices must be converted from 1-based to 0-based
! before being written out.
!
write ( output_unit, '(a)' ) ' '
write ( output_unit, '(a)' ) 'CELLS ' // trim ( element_num_string ) &
// ' ' // trim ( cell_size_string )
do el_id = 1, element_nums
write ( output_unit, '(2x,i4,10(2x,i7))' ) &
element_order, element%vertex(el_id,1:element_order) - 1
end do
write ( output_unit, '(a)' ) ' '
write ( output_unit, '(a)' ) 'CELL_TYPES ' // trim ( element_num_string )
if ( element_order == 4 ) then
do el_id = 1, element_nums
write ( output_unit, '(a)' ) '9'
end do
else if ( element_order == 10 ) then
do el_id = 1, element_nums
write ( output_unit, '(a)' ) '24'
end do
end if
write ( output_unit, '(a)' ) ' '
write ( output_unit, '(a)' ) 'POINT_DATA ' // trim ( node_num_string )
return
end subroutine vtk_essential_write
subroutine vtk_vector_write ( output_unit, row,col,vector, name)
!*****************************************************************************80
!
!! VTK_PUVW_WRITE writes stress (sigxx,sigyy,sigxy) data to a VTK file.
!
! Licensing:
!
! This code is distributed under the GNU LGPL license.
!
! Modified:
!
! 26 March 2009
!
! Author:
!
! John Burkardt
!
! Parameters:
!
! Input, integer ( kind = 4 ) OUTPUT_UNIT, the unit number of the file.
!
! Input, character ( len = * ) TITLE, a title for the data.
!
! Input, integer ( kind = 4 ) NODE_NUM, the number of nodes.
!
! Input, integer ( kind = 4 ) ELEMENT_NUM, the number of elements.
!
! Input, integer ( kind = 4 ) ELEMENT_ORDER, the order of the elements
! (number of nodes in an element)
!
! Input, real ( kind = 8 ) XYZ(3,NODE_NUM), the node coordinates.
!
! Input, integer ( kind = 4 ) ELEMENT_NODE(ELEMENT_ORDER,ELEMENT_NUM), the
! nodes that make up each element.
!
! Input, real ( kind = 8 ) P(NODE_NUM), the pressure at each node.
!
! Input, real ( kind = 8 ) UVW(3,NODE_NUM), the velocity at each node.
!
integer ( kind = 4 ),intent(in) :: output_unit
integer ( kind = 4 ),intent(in) :: row,col
character(len=*), intent(in):: name
real(kind=8),intent(in):: vector(row,col)
integer::node_id
!
write ( output_unit, * ) 'VECTORS', name,' double'
do node_id = 1, row
write ( output_unit, '(2(2x,f14.6))' ) vector(node_id,1:col)
end do
return
end subroutine vtk_vector_write
subroutine vtk_scalar_write ( output_unit,node_nums, scalar, scalar_name)
integer,intent(in) ::output_unit
integer ( kind = 4 ),intent(in) :: node_nums
character(len=*), intent(in):: scalar_name
integer,intent(in):: scalar(node_nums)
integer::node_id
write ( output_unit, * ) 'SCALARS ', scalar_name, ' double'
write ( output_unit, '(a)' ) 'LOOKUP_TABLE default'
do node_id = 1, node_nums
write ( output_unit, '(I4)') scalar(node_id)
end do
return
end subroutine vtk_scalar_write
subroutine vtk_scalar_write_double ( output_unit,node_nums, scalar, scalar_name)
integer,intent(in)::output_unit
integer ( kind = 4 ),intent(in) :: node_nums
character(len=*), intent(in):: scalar_name
real(kind=8),intent(in):: scalar(node_nums)
integer::node_id
write ( output_unit, * ) 'SCALARS ', scalar_name, ' double'
write ( output_unit, '(a)' ) 'LOOKUP_TABLE default'
do node_id = 1, node_nums
write ( output_unit, '(f14.6)') scalar(node_id)
end do
return
end subroutine vtk_scalar_write_double
end module vtk_io