-
Notifications
You must be signed in to change notification settings - Fork 69
/
trees_io_ls.f90
883 lines (651 loc) · 21.7 KB
/
trees_io_ls.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
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
!!
!! Copyright (C) 2009-2013 Johns Hopkins University
!!
!! This file is part of lesgo.
!!
!! lesgo 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.
!!
!! lesgo 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 lesgo. If not, see <http://www.gnu.org/licenses/>.
!!
module trees_io_ls
use trees_base_ls
implicit none
save
private
public :: draw_tree_array, write_ta_data, read_ta_data
character (*), parameter :: mod_name = 'trees_io_ls'
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
contains
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!--assumes file with unit no. lun is opened and positioned correctly
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
recursive subroutine draw_branches (branch, lun)
implicit none
type (branch_type), intent (in) :: branch
integer, intent (in) :: lun
character (*), parameter :: sub_name = mod_name // '.draw_branches'
integer, parameter :: n_face = 4
integer, parameter :: n_height = 2 !--must be > 1
integer :: i, j
integer :: n_tot, n_cap, n_base
logical :: add_base_this !--local, changeable version of add_base
real (rp) :: pi
real (rp) :: h, dh, theta, dtheta, theta0
real (rp) :: r, r0, r_top, l
real (rp) :: x_local, y_local, z_local
real (rp) :: x_abs, y_abs, z_abs
!----------------------------------------------------------------------
pi = acos (-1._rp)
if (add_cap) then
select case (cap_shape)
case ('hemispherical')
n_cap = 2
case ('rectangular')
n_cap = 2
case default
call error (sub_name, 'invalid cap_shape')
end select
else
n_cap = 1 !--draw lid
end if
if (add_base .and. (branch % gen > 0)) then
add_base_this = add_base
else !--do not draw base for trunks
add_base_this = .false.
end if
if (add_base_this) then
select case (base_shape)
case ('hemispherical')
n_base = 2
case ('rectangular')
n_base = 2
case default
call error (sub_name, 'invalid cap_shape')
end select
else
n_base = 1 !--draw bottom
end if
n_tot = n_height + n_cap + n_base
if (use_tecplot) call write_tecplot_zone_hdr ()
!--define n_face X n_height mesh to represent the branch
dtheta = 2._rp * pi / n_face
l = branch % l
dh = l / (n_height - 1)
select case (branch_cross_section)
case ('circular')
r0 = (branch % d) / 2._rp
theta0 = branch % twist
case ('square')
if (n_face /= 4) then
call error (sub_name, 'use n_face = 4 with square X-section')
end if
r0 = (branch % d) / sqrt (2._rp)
theta0 = pi / 4._rp + (branch % twist)
case ('square+plate')
call mesg (sub_name, 'cannot draw square+plate cross-section')
goto 001 !--do nothing, exit this nicely
case default
call error (sub_name, 'invalid branch_cross_section')
end select
r_top = r0 * (1._rp - (branch % taper))
do j = 1, n_tot
theta = theta0
call set_h ()
call set_radius () !--set the radius used for drawing
call draw_cross_section ()
end do
if (associated (branch % sub_branch)) then !--this is safer, perhaps
do i = 1, branch % n_sub_branch
call draw_branches (branch % sub_branch(i), lun) !--recursion
end do
end if
001 continue
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
contains
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
subroutine draw_cross_section ()
implicit none
do i = 1, n_face + 1 !--(+1) needed to complete circle
x_local = r * cos (theta)
y_local = r * sin (theta)
z_local = h
x_abs = (branch % x0(1)) + &
x_local * (branch % x_hat(1)) + &
y_local * (branch % y_hat(1)) + &
z_local * (branch % z_hat(1))
y_abs = (branch % x0(2)) + &
x_local * (branch % x_hat(2)) + &
y_local * (branch % y_hat(2)) + &
z_local * (branch % z_hat(2))
z_abs = (branch % x0(3)) + &
x_local * (branch % x_hat(3)) + &
y_local * (branch % y_hat(3)) + &
z_local * (branch % z_hat(3))
write (lun, '(3(f12.5,1x))') x_abs, y_abs, z_abs
theta = theta + dtheta
end do
end subroutine draw_cross_section
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
subroutine set_h ()
implicit none
if (j <= n_base) then
if (add_base_this) then
select case (base_shape)
case ('hemispherical') !--n_base = 2
if (j == 1) then
h = -(branch % d) / 2._rp
else !--j = 2
h = -((branch % d) / 2._rp) / sqrt (2._rp)
end if
case ('rectangular') !--n_base = 2
h = -(branch % d) / 2._rp
end select
else !--n_base = 1, so j = 1
h = 0._rp
end if
else if ( j > n_height + n_base) then
if (add_cap) then
select case (cap_shape)
case ('hemispherical') !--n_cap = 2
if (j == n_tot - 1) then
h = l + (1._rp - branch % taper) * ((branch % d) / 2._rp) &
/ sqrt (2._rp)
else !--j = n_tot
h = l + (1._rp - branch % taper) * (branch % d) / 2._rp
end if
case ('rectangular') !--c_cap = 2
h = l + (1._rp - branch % taper) * (branch % d) / 2._rp
end select
else !--n_cap = 1, so j = n_tot
h = l
end if
else
h = (j - n_base - 1) * dh
end if
end subroutine set_h
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!--not that taper is not included with caps
!--depends on h: call AFTER set_h
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
subroutine set_radius ()
implicit none
if (j <= n_base) then
if (add_base_this) then
select case (base_shape)
case ('hemispherical') !--n_base is 2
if (j == 1) then
r = 0._rp
else
r = r0 / sqrt (2._rp)
end if
case ('rectangular') !--n_base is 2
if (j == 1) then
r = 0._rp
else
r = r0
end if
end select
else !--n_base is 1
r = 0._rp
end if
else if (j > n_height + n_base) then
if (add_cap) then
select case (cap_shape)
case ('hemispherical') !--n_cap is 2
if (j == n_tot - 1) then
r = r_top / sqrt (2._rp)
else
r = 0._rp
end if
case ('rectangular') !--n_cap is 2
if (j == n_tot - 1) then
r = r_top
else
r = 0._rp
end if
end select
else !--n_cap is 1
r = 0._rp
end if
else
r = r0 * (1._rp - (h / l) * (branch % taper)) !--add the taper
end if
end subroutine set_radius
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
subroutine write_tecplot_zone_hdr ()
implicit none
write (lun, '(a,i0,a,i0,a)') 'zone, f=point, i = ', n_face + 1, &
', j = ', n_tot, ', k = 1'
end subroutine write_tecplot_zone_hdr
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
end subroutine draw_branches
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
subroutine draw_tree_array (name)
implicit none
character (*), intent (in) :: name
character(1024) :: msg
character (*), parameter :: sub_name = mod_name // &
'.draw_tree_array'
integer, parameter :: lun = 1
integer :: i
logical :: opn
!----------------------------------------------------------------------
inquire (unit = lun, opened = opn)
if (opn) then
write (msg, '(a,i0,a)') 'unit ', lun, ' is already open'
call error (sub_name, msg)
else
open (lun, file = name)
end if
if (use_tecplot) then ! write header
write (lun, *) 'variables = "x" "y" "z"'
end if
do i = 1, n_tree
call draw_branches (tree_array(i) % trunk, lun)
end do
close (lun)
end subroutine draw_tree_array
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!--read in branch data from file
!--assumes the tree data structure already exists, only some things
! need to be read from file, e.g. velscale
!--this must be kept in sync with write_br_data
!--does not care about order
!--we make allowance for some spaces here (not really needed)
!--some error checking in here to let us know in case of error
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
recursive subroutine read_br_data (br, lun)
implicit none
type (branch_type), intent (inout) :: br
integer, intent (in) :: lun
character (*), parameter :: sub = mod_name // '.read_br_data'
!--shortened name since used alot here
character (256) :: line
integer :: i
integer :: ieq
integer :: itmp
logical :: ltmp
!----------------------------------------------------------------------
read (lun, '(a)') line
if (index (line, 'begin branch') == 0) then
call error (sub, "no 'begin branch' statement")
end if
do
read (lun, '(a)') line
!--is this the end of this branch?
if (index (line, 'end branch') > 0) exit
ieq = index (line, '=')
!--is there an equals sign?
! if not, then this line does not contain useful data (except
! maybe for error checking), so skip to next line
if (ieq == 0) cycle !--read next line
!--the commented reads here indicate that the value should be known
! from trees_setup anyway, so that case is a do-nothing
select case ( trim (line(1:ieq-1)) )
case ('ident')
read (line(ieq+1:), *) itmp
if (itmp /= br % ident) call error (sub, 'ident mismatch')
case ('itree')
read (line(ieq+1:), *) itmp
if (itmp /= br % itree) call error (sub, 'itree mismatch')
case ('gen')
read (line(ieq+1:), *) itmp
if (itmp /= br % gen) call error (sub, 'gen mismatch')
case ('n_sub_branch')
read (line(ieq+1:), *) itmp
if (itmp /= br % n_sub_branch) call error (sub, 'n_sub_branch mismatch')
case ('zone')
read (line(ieq+1:), *) itmp
if (itmp /= br % zone) call warn (sub, 'zone mismatch')
!--difference zones allowed
case ('nbboxpt')
!read (line(ieq+1:), *) br % nbboxpt
case ('nrespt')
!read (line(ieq+1:), *) br % nrespt
case ('resolved')
read (line(ieq+1:), *) ltmp
if (ltmp .neqv. br % resolved) call error (sub, 'resolved mismatch')
case ('l')
!read (line(ieq+1:), *) br % l
case ('d')
!read (line(ieq+1:), *) br % d
case ('taper')
!read (line(ieq+1:), *) br % taper
case ('twist')
!read (line(ieq+1:), *) br % twist
case ('width_bbox')
!read (line(ieq+1:), *) br % width_bbox
case ('height_bbox')
!read (line(ieq+1:), *) br % height_bbox
case ('root_height')
!read (line(ieq+1:), *) br % root_height
case ('fcoeff')
!read (line(ieq+1:), *) br % fcoeff
case ('fdist_coeff')
!read (line(ieq+1:), *) br % fdist_coeff
case ('A')
read (line(ieq+1:), *) br % A
case ('fcoeff_dir')
!read (line(ieq+1:), *) br % fcoeff_dir
case ('fnorm')
!read (line(ieq+1:), *) br % fnorm
case ('Mdyn')
!read (line(ieq+1:), *) br % Mdyn
case ('x0')
!read (line(ieq+1:), *) br % x0
case ('abs_dir')
!read (line(ieq+1:), *) br % abs_dir
case ('rel_dir')
!read (line(ieq+1:), *) br % rel_dir
case ('resf')
read (line(ieq+1:), *) br % resf
case ('unresf')
read (line(ieq+1:), *) br % unresf
case ('resftot')
read (line(ieq+1:), *) br % resftot
case ('unresftot')
read (line(ieq+1:), *) br % unresftot
case ('ftot')
read (line(ieq+1:), *) br % ftot
case ('velscale')
read (line(ieq+1:), *) br % velscale
case ('x_hat')
!read (line(ieq+1:), *) br % x_hat
case ('y_hat')
!read (line(ieq+1:), *) br % y_hat
case ('z_hat')
!read (line(ieq+1:), *) br % z_hat
case default
call error ( sub, 'invalid data line' // n_l // trim (line) )
end select
end do
if (associated (br % sub_branch)) then
do i = 1, br % n_sub_branch
call read_br_data (br % sub_branch(i), lun)
end do
end if
end subroutine read_br_data
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
subroutine read_tree_data (tree, lun)
implicit none
type (tree_type), intent (inout) :: tree
character (*), parameter :: sub_name = mod_name // '.read_tree_data'
integer, intent (in) :: lun
character (256) :: line
!----------------------------------------------------------------------
read (lun, '(a)') line
if (index (line, 'begin tree') == 0) call error (sub_name, &
"missing 'begin tree'")
call read_br_data (tree % trunk, lun)
read (lun, '(a)') line
if (index (line, 'end tree') == 0) call error (sub_name, &
"missing 'end tree'")
end subroutine read_tree_data
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
subroutine read_ta_data (name)
implicit none
character (*), intent (in) :: name
character(1024) :: msg
character (*), parameter :: sub_name = mod_name // '.read_ta_data'
integer, parameter :: lun = 1
character (256) :: line
integer :: i
logical :: opn, exst
!----------------------------------------------------------------------
if (.not. tree_array_initialized) then
call error (sub_name, 'tree_array not initialized')
end if
inquire (unit=lun, opened=opn)
if (opn) then
write (msg, '(a,i0,a)') 'unit ', lun, ' is already open'
call error (sub_name, msg)
end if
inquire (file=name, exist=exst, opened=opn)
if (.not. exst) then
call error (sub_name, 'file ' // trim (name) // ' does not exist')
else if (opn) then
call error (sub_name, 'file ' // trim (name) // 'is already open')
end if
open (lun, file=name, action='read')
do i = 1, n_tree
read (lun, '(a)') line
!--this check is not precise
if ((index (line, 'begin tree') == 0) .or. &
(index (line, 'of') < index (line, 'begin tree'))) then
call error (sub_name, 'invalid begin tree i of n_tree line' // n_l // &
'line =' // line)
end if
call read_tree_data (tree_array(i), lun)
end do
close (lun)
end subroutine read_ta_data
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!--dumps all branch data to file
!--may want to make format nicer
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
recursive subroutine write_br_data (br, lun)
implicit none
type (branch_type), intent (in) :: br
integer, intent (in) :: lun
character (*), parameter:: ifmt = 'i0'
character (*), parameter :: rfmt = 'es13.6'
character (64) :: fmt
integer :: i
!----------------------------------------------------------------------
write (lun, '(a)') 'begin branch'
fmt = '(a,' // ifmt // ')'
write (lun, fmt) 'ident = ', br % ident
write (lun, fmt) 'itree = ', br % itree
write (lun, fmt) 'gen = ', br % gen
write (lun, fmt) 'n_sub_branch = ', br % n_sub_branch
write (lun, fmt) 'zone = ', br % zone
write (lun, fmt) 'nbboxpt = ', br % nbboxpt
write (lun, fmt) 'nrespt = ', br % nrespt
if (associated (br % bboxpt)) then
write (lun, '(a)') 'branch % bboxpt is associated'
!write (lun, '(a)') 'br % bboxpt:'
!fmt = '(4(' // ifmt // ',1x))'
!do i = 1, br % nbboxpt
! write (lun, fmt) i, br % bboxpt(:, i)
!end do
else
write (lun, '(a)') 'br % bboxpt is NOT associated'
end if
write (lun, '(a,l1)') 'resolved = ', br % resolved
fmt = '(a,' // rfmt // ')' !--for reals
write (lun, fmt) 'l = ', br % l
write (lun, fmt) 'd = ', br % d
write (lun, fmt) 'taper = ', br % taper
write (lun, fmt) 'twist = ', br % twist
write (lun, fmt) 'width_bbox = ', br % width_bbox
write (lun, fmt) 'height_bbox = ', br % height_bbox
write (lun, fmt) 'root_height = ', br % root_height
write (fmt, '(a,i0,a)') '(a,', nfcoeff, '(' // rfmt // ',1x))'
write (lun, fmt) 'fcoeff = ', br % fcoeff
write (lun, fmt) 'fdist_coeff = ', br % fdist_coeff
write (lun, fmt) 'A = ', br % A
write (fmt, '(a,i0,a)') '(a,', nd * nfcoeff, '(' // rfmt // ',1x))'
write (lun, fmt) 'fcoeff_dir = ', br % fcoeff_dir
write (lun, fmt) 'fnorm = ', br % fnorm
fmt = '(a,3(' // rfmt // ',1x))' !--could write nd instead of 3
write (lun, fmt) 'Mdyn = ', br % Mdyn
write (lun, fmt) 'x0 = ', br % x0
write (lun, fmt) 'abs_dir = ', br % abs_dir
write (lun, fmt) 'rel_dir = ', br % rel_dir
write (lun, fmt) 'resf = ', br % resf
write (lun, fmt) 'unresf = ', br % unresf
write (lun, fmt) 'resftot = ', br % resftot
write (lun, fmt) 'unresftot = ', br % unresftot
write (lun, fmt) 'ftot = ', br % ftot
write (lun, fmt) 'velscale = ', br % velscale
write (lun, fmt) 'x_hat = ', br % x_hat
write (lun, fmt) 'y_hat = ', br % y_hat
write (lun, fmt) 'z_hat = ', br % z_hat
if (associated (br % sub_branch)) then
write (lun, '(a)') 'sub_branch is associated'
else
write (lun, '(a)') 'sub_branch is NOT associated'
end if
if (associated (br % parent_branch)) then
write (lun, '(a)') 'parent_branch is associated'
else
write (lun, '(a)') 'parent_branch is NOT associated'
end if
write (lun, '(a)') 'end branch'
if (associated (br % sub_branch)) then
do i = 1, br % n_sub_branch
call write_br_data (br % sub_branch(i), lun)
end do
end if
end subroutine write_br_data
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
subroutine write_tree_data (tree, lun)
implicit none
type (tree_type), intent (in) :: tree
character (*), parameter :: sub_name = mod_name // '.write_tree_data'
integer, intent (in) :: lun
!----------------------------------------------------------------------
write (lun, '(a)') 'begin tree'
call write_br_data (tree % trunk, lun)
write (lun, '(a)') 'end tree'
end subroutine write_tree_data
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
subroutine write_ta_data (name)
implicit none
character (*), intent (in) :: name
character(1024) :: msg
character (*), parameter :: sub_name = mod_name // '.write_ta_data'
integer, parameter :: lun = 1
integer :: i
logical :: opn
!----------------------------------------------------------------------
if (.not. tree_array_initialized) then
call error (sub_name, 'tree_array not initialized')
end if
inquire (unit = lun, opened = opn)
if (opn) then
write (msg, '(a,i0,a)') 'unit ', lun, ' is already open'
call error (sub_name, msg)
else
open (lun, file = name)
end if
do i = 1, n_tree
write (lun, '(a,i0,a,i0)') 'begin tree ', i, ' of ', n_tree
call write_tree_data (tree_array(i), lun)
end do
close (lun)
end subroutine write_ta_data
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!--really only for debugging: lets us know when forcing is not working
!--commented out to remove sim_param dependence from this module
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!subroutine output_tree_array_grid_vel (name)
!implicit none
!
!character (*), intent (in) :: name
!
!character (*), parameter :: sub_name = mod_name // &
! '.output_tree_array_grid_vel'
!
!integer, parameter :: lun = 1
!
!integer :: i
!
!logical :: opn
!
!!----------------------------------------------------------------------
!
!inquire (unit = lun, opened = opn)
!if (opn) then
! write (msg, '(a,i0,a)') 'unit ', lun, ' is already open'
! call error (sub_name, msg)
!else
! open (lun, file = name)
!end if
!
!do i = 1, n_tree
!
! write (lun, *) 'begin tree ', i, ' of ', n_tree
!
! call output_tree_grid_vel (tree_array(i), lun)
!
!end do
!
!close (lun)
!
!end subroutine output_tree_array_grid_vel
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!subroutine output_tree_grid_vel (tree, lun)
!implicit none
!
!type (tree_type), intent (in) :: tree
!
!integer, intent (in) :: lun
!
!character (*), parameter :: sub_name = mod_name // &
! '.output_tree_grid_vel'
!
!!----------------------------------------------------------------------
!
!write (lun, *) 'begin tree'
!
!call warn (sub_name, 'output_branch_grid_vel has been disabled')
!!call output_branch_grid_vel (tree % trunk, lun)
!
!end subroutine output_tree_grid_vel
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
! outputs grid velocity at the nodes of the branches
! really only for debugging, lets us know if our forcing is messed up
!--careful: adding this will add sim_param dependence to this file,
! which is not good for trees_pre
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!recursive subroutine output_branch_grid_vel (branch, lun)
!use sim_param, only : u, v, w
!
!type (branch_type), intent (in) :: branch
!
!integer, intent (in) :: lun
!
!character (*), parameter :: sub_name = mod_name // &
! '.output_branch_grid_vel'
!
!integer :: i, j, k
!integer :: i_pt
!
!!----------------------------------------------------------------------
!
!if (branch % n_pt < 1) call error (sub_name, 'n_pt < 1')
!
!write (lun, *) 'begin branch'
!
!do i_pt = 1, branch % n_pt
!
! i = branch % jx(1, i_pt)
! j = branch % jx(2, i_pt)
! k = branch % jx(3, i_pt)
!
! write (lun, *) i, j, k, u(i, j, k), v(i, j, k), &
! 0.5_rp * (w(i, j, k) + w(i, j, k+1))
!
!end do
!
!if (associated (branch % sub_branch)) then
!
! do i = 1, branch % n_sub_branch
! call output_branch_grid_vel (branch % sub_branch(i), lun)
! end do
!
!end if
!
!end subroutine output_branch_grid_vel
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
end module trees_io_ls