5
integer, parameter :: rr_ = selected_real_kind(p=6) ! single (real*4)
6
integer, parameter :: rd_ = selected_real_kind(p=15) ! double (real*8)
7
integer, parameter :: is_ = selected_int_kind(4) ! short (integer*2)
8
integer, parameter :: ii_ = selected_int_kind(9) ! int (integer*4)
9
integer, parameter :: il_ = selected_int_kind(18) ! long (integer*8)
10
integer, parameter, private :: BUD_ID_LEn = 36
11
character(len=*), parameter, private :: &
12
BUD_MOd = 'BUD_CC2(BUD_MOD,_)BUD_MOD_NAME'
13
character(len=*), parameter, private :: &
14
BUD_TYPe = "LL_sArray1D"
16
type(LL_sArray1D_), pointer :: D => null()
20
type(LL_sArray1D_LList), pointer :: ll => null()
21
type(LL_sArray1D_LList), pointer :: head => null()
23
character(len=BUD_ID_LEN) :: id_ = "null_id"
25
type LL_sArray1D_LList
26
type(LL_sArray1D_LList), pointer :: prev => null()
27
type(LL_sArray1D_LList), pointer :: next => null()
30
private :: LL_sArray1D_LList
33
module procedure new_data_
36
interface assignment(=)
37
module procedure set_data_
40
module procedure size_llist_
44
module procedure size_llist_
48
module procedure set_data_
49
module procedure set_data_idx_
53
module procedure add_node_
54
module procedure add_node_data_
58
module procedure get_node_data_idx_
62
module procedure get_node_data_idx_
66
module procedure set_head_idx_
70
module procedure itt_step_
71
module procedure itt_step_i_
75
module procedure remove_node_
78
interface remove_node_data
79
module procedure remove_node_data_
81
public :: remove_node_data
83
module procedure copy_
87
private :: LL_sArray1D_
88
interface assignment(=)
89
module procedure common_assign_
91
public :: assignment(=)
92
private :: common_assign_
94
module procedure common_initialize_
97
private :: common_initialize_
98
interface is_initialized
99
module procedure common_is_initialized_
101
public :: is_initialized
102
private :: common_is_initialized_
103
interface initialized
104
module procedure common_is_initialized_
106
public :: initialized
108
module procedure common_is_initialized_
112
module procedure common_is_same_
115
private :: common_is_same_
117
module procedure common_is_same_
121
module procedure common_delete_
124
private :: common_delete_
126
module procedure common_nullify_
129
private :: common_nullify_
131
module procedure copy_
134
private :: common_copy_
136
module procedure print_
140
module procedure common_references_
143
private :: common_references_
145
module procedure common_references_
149
module procedure common_set_error_is_
150
module procedure common_set_error_ii_
151
module procedure common_set_error_il_
154
private :: common_set_error_is_
155
private :: common_set_error_ii_
156
private :: common_set_error_il_
158
module procedure common_error_
161
private :: common_error_
163
subroutine common_copy_(from, to)
164
type(LL_sArray1D), intent(in) :: from
165
type(LL_sArray1D), intent(inout) :: to
166
call set_error(to, error(from))
167
end subroutine common_copy_
168
subroutine common_initialize_(this)
169
type(LL_sArray1D), intent(inout) :: this
172
allocate(this%D, stat=error)
173
call set_error(this, error)
174
if ( error /= 0 ) return
176
call common_tag_object_(this)
177
end subroutine common_initialize_
178
pure function common_is_initialized_(this) result(init)
179
type(LL_sArray1D), intent(in) :: this
181
init = associated(this%D)
182
end function common_is_initialized_
183
elemental function common_is_same_(lhs, rhs) result(same)
184
type(LL_sArray1D), intent(in) :: lhs, rhs
186
same = is_initd(lhs) .and. is_initd(rhs)
187
if ( .not. same ) return
188
same = associated(lhs%D, target=rhs%D)
189
end function common_is_same_
190
subroutine common_delete_(this)
191
type(LL_sArray1D), intent(inout) :: this
193
call set_error(this, 0)
194
if (.not. is_initd(this) ) return
195
this%D%refs_ = this%D%refs_ - 1
196
if ( 0 == this%D%refs_ ) then
198
deallocate(this%D, stat=error)
199
call set_error(this, error)
202
end subroutine common_delete_
203
elemental subroutine common_nullify_(this)
204
type(LL_sArray1D), intent(inout) :: this
205
if (.not. is_initd(this) ) return
207
end subroutine common_nullify_
208
subroutine common_assign_(lhs, rhs)
209
type(LL_sArray1D), intent(inout) :: lhs
210
type(LL_sArray1D), intent(in) :: rhs
212
if ( .not. is_initd(rhs) ) return
214
lhs%D%refs_ = rhs%D%refs_ + 1
215
end subroutine common_assign_
216
elemental function common_references_(this) result(refs)
217
type(LL_sArray1D), intent(in) :: this
219
if ( is_initd(this) ) then
224
end function common_references_
225
elemental function common_error_(this) result(error)
226
type(LL_sArray1D), intent(in) :: this
228
if ( is_initd(this) ) then
233
end function common_error_
234
elemental subroutine common_set_error_is_(this, error)
235
type(LL_sArray1D), intent(inout) :: this
236
integer(is_), intent(in) :: error
238
end subroutine common_set_error_is_
239
elemental subroutine common_set_error_ii_(this, error)
240
type(LL_sArray1D), intent(inout) :: this
241
integer(ii_), intent(in) :: error
243
end subroutine common_set_error_ii_
244
elemental subroutine common_set_error_il_(this, error)
245
type(LL_sArray1D), intent(inout) :: this
246
integer(il_), intent(in) :: error
248
end subroutine common_set_error_il_
249
elemental function common_id_(this) result(str)
250
type(LL_sArray1D), intent(in) :: this
251
character(len=BUD_ID_LEn) :: str
253
end function common_id_
254
subroutine common_tag_object_(this)
255
type(LL_sArray1D), intent(inout) :: this
256
end subroutine common_tag_object_
257
subroutine delete_(this)
258
type(LL_sArray1D), intent(inout) :: this
259
type(LL_sArray1D_LList), pointer :: head, tmp
260
if ( associated(this%D%head) .and. .not. &
261
associated(this%D%ll) ) then
267
if ( associated(head) ) then
268
do while ( associated(head%prev) )
269
if ( associated(head%prev, this%D%ll) ) exit
272
if ( associated(head%prev, this%D%ll) ) then
277
do while ( associated(head) )
278
if ( associated(head%next, this%D%ll) ) exit
285
if ( associated(this%D%ll) ) then
286
call delete(this%D%ll%D)
287
deallocate(this%D%ll)
291
end subroutine delete_
292
subroutine new_(this)
293
type(LL_sArray1D), intent(inout) :: this
294
call initialize(this)
296
subroutine new_data_(this, D)
297
type(LL_sArray1D), intent(inout) :: this
298
type(sArray1D), intent(in) :: D
301
this%D%head => this%D%ll
303
end subroutine new_data_
304
subroutine get_ll_headp(this, head)
305
type(LL_sArray1D), intent(in) :: this
306
type(LL_sArray1D_LList), pointer :: head
307
if ( .not. is_initd(this) ) then
312
do while ( associated(head%prev) )
314
if ( associated(head, this%D%head) ) exit
316
end subroutine get_ll_headp
317
subroutine get_ll_tailp(this, tail)
318
type(LL_sArray1D), intent(in) :: this
319
type(LL_sArray1D_LList), pointer :: tail
320
if ( .not. is_initd(this) ) then
325
do while ( associated(tail%next) )
327
if ( associated(tail, this%D%head) ) exit
329
end subroutine get_ll_tailp
330
subroutine get_ll_idxp(this, node, index)
331
type(LL_sArray1D), intent(in), target :: this
332
type(LL_sArray1D_LList), pointer :: node
333
integer, intent(in), optional :: index
336
if ( .not. is_initd(this) ) return
338
if ( present(index) ) lindex = index
340
do while ( lindex < 0 .and. associated(node%prev) )
344
do while ( lindex > 0 .and. associated(node%next) )
348
if ( lindex /= 0 ) then
352
end subroutine get_ll_idxp
353
subroutine append_node(ll)
354
type(LL_sArray1D_LList), pointer :: ll
355
type(LL_sArray1D_LList), pointer :: tmp => null()
356
if ( .not. associated(ll) ) return
360
if ( associated(ll%next) ) then
365
end subroutine append_node
366
function size_llist_(this) result (nnodes)
367
type(LL_sArray1D), intent(in), target :: this
369
type(LL_sArray1D_LList), pointer :: head, tmp
371
if ( .not. is_initd(this) ) return
372
call get_ll_headp(this, head)
374
do while ( associated(tmp) )
377
if ( associated(tmp, head) ) exit
379
end function size_llist_
380
subroutine add_node_(this)
381
type(LL_sArray1D), intent(inout) :: this
382
type(LL_sArray1D_LList), pointer :: tail
383
if ( .not. is_initd(this) ) then
386
this%D%head => this%D%ll
389
call get_ll_tailp(this, tail)
390
call append_node(tail)
391
end subroutine add_node_
392
subroutine add_node_data_(this, D)
393
type(LL_sArray1D), intent(inout) :: this
394
type(sArray1D), intent(in) :: D
395
type(LL_sArray1D_LList), pointer :: tail
396
call get_ll_tailp(this, tail)
397
if ( .not. associated(tail) ) then
401
call append_node(tail)
403
end subroutine add_node_data_
404
subroutine set_data_(this, D)
405
type(LL_sArray1D), intent(inout) :: this
406
type(sArray1D), intent(in) :: D
407
if ( is_initd(this) ) then
410
end subroutine set_data_
411
subroutine set_data_idx_(this, D, index)
412
type(LL_sArray1D), intent(inout) :: this
413
type(sArray1D), intent(in) :: D
414
integer, intent(in) :: index
415
type(LL_sArray1D_LList), pointer :: node
416
call get_ll_idxp(this, node, index)
417
if ( .not. associated(node) ) return
419
end subroutine set_data_idx_
420
subroutine set_head_idx_(this, index)
421
type(LL_sArray1D), intent(inout) :: this
422
integer, intent(in) :: index
423
type(LL_sArray1D_LList), pointer :: node
424
call get_ll_idxp(this, node, index)
425
if ( .not. associated(node) ) return
427
end subroutine set_head_idx_
428
subroutine get_node_data_idx_(this, D, index)
429
type(LL_sArray1D), intent(in), target :: this
430
type(sArray1D), intent(inout) :: D
431
integer, intent(in), optional :: index
432
type(LL_sArray1D_LList), pointer :: node
434
if ( .not. is_initd(this) ) return
435
call get_ll_idxp(this, node, index)
436
if ( associated(node) ) D = node%D
437
end subroutine get_node_data_idx_
438
function itt_step_(this, itt) result(itterated)
439
type(LL_sArray1D), intent(in) :: this
440
type(LL_sArray1D), intent(inout) :: itt
443
if ( .not. is_initd(this) ) then
447
if ( .not. is_initd(itt) ) then
449
itt%D%head => this%D%head
450
itterated = associated(itt%D%head)
452
itt%D%head => itt%D%head%next
453
itterated = associated(itt%D%head)
454
if ( itterated ) then
455
itterated = .not. associated(itt%D%head, this%D%head)
458
if ( .not. itterated ) then
461
end function itt_step_
462
function itt_step_i_(this, itt, i) result(itterated)
463
type(LL_sArray1D), intent(in) :: this
464
type(LL_sArray1D), intent(inout) :: itt
465
integer, intent(in) :: i
469
if ( .not. is_initd(this) ) then
474
if ( .not. is_initd(itt) ) then
476
itt%D%head => this%D%head
477
itterated = associated(itt%D%head)
478
else if ( i > 0 ) then
481
itt%D%head => itt%D%head%next
482
itterated = associated(itt%D%head)
483
if ( itterated ) then
484
itterated = .not. associated(itt%D%head, this%D%head)
486
if ( .not. itterated ) exit
488
else if ( i < 0 ) then
491
itt%D%head => itt%D%head%prev
492
itterated = associated(itt%D%head)
493
if ( itterated ) then
494
itterated = .not. associated(itt%D%head, this%D%head)
496
if ( .not. itterated ) exit
499
if ( .not. itterated ) then
503
end function itt_step_i_
504
subroutine remove_node_(this, index)
505
type(LL_sArray1D), intent(inout), target :: this
506
integer, intent(in) :: index
507
type(LL_sArray1D_LList), pointer :: node, pnode, nnode
508
if ( .not. is_initd(this) ) return
509
call get_ll_idxp(this, node, index)
510
if ( .not. associated(node) ) return
515
if ( associated(pnode) ) then
518
if ( associated(nnode) ) then
523
end subroutine remove_node_
524
subroutine remove_node_data_(this, index)
525
type(LL_sArray1D), intent(inout), target :: this
526
integer, intent(in), optional :: index
527
type(LL_sArray1D_LList), pointer :: node
528
if ( .not. is_initd(this) ) return
529
call get_ll_idxp(this, node, index)
530
if ( .not. associated(node) ) return
532
end subroutine remove_node_data_
533
subroutine copy_(from, to)
534
type(LL_sArray1D), intent(inout) :: from, to
535
type(LL_sArray1D_LList), pointer :: t, f
537
if ( .not. is_initd(from) ) return
542
do while ( associated(f%next) )
548
if ( associated(t, to%D%head) ) return
552
do while ( associated(f%prev) )
560
subroutine print_(this, info, indent)
561
type(LL_sArray1D), intent(in), target :: this
562
character(len=*), intent(in), optional :: info
563
integer, intent(in), optional :: indent
565
type(LL_sArray1D_LList), pointer :: node
566
character(len=32) :: fmt
567
character(len=256) :: name
569
if ( present(info) ) name = info
571
if ( present(indent) ) lindent = indent
572
write(fmt, '(a,i0,a)') '(t',lindent,',3a)'
573
if ( .not. is_initd(this) ) then
574
write(*,fmt) "<", trim(name), " not initialized>"
577
write(fmt, '(a,i0,a)') '(t',lindent,',3a,i0,a)'
578
write(*,fmt) "<<", trim(name), " llist, nodes=",nodes(this),">"
579
lindent = lindent + 2 ! step indentation
580
call get_ll_headp(this, node)
581
do while ( associated(node) )
582
if ( associated(node, this%D%head) ) then
583
write(fmt, '(a,i0,a)') '(t',lindent,',a)'
584
call print(node%D, indent = lindent+2)
586
call print(node%D, indent = lindent)
590
lindent = lindent - 2 ! go back to requested indentation
591
write(fmt, '(a,i0,a)') '(t',lindent,',a,i0,a)'
592
write(*,fmt) " <llist-refs: ", references(this), ">>"
593
end subroutine print_
595
module bud_LL_iArray1D
599
integer, parameter :: rr_ = selected_real_kind(p=6) ! single (real*4)
600
integer, parameter :: rd_ = selected_real_kind(p=15) ! double (real*8)
601
integer, parameter :: is_ = selected_int_kind(4) ! short (integer*2)
602
integer, parameter :: ii_ = selected_int_kind(9) ! int (integer*4)
603
integer, parameter :: il_ = selected_int_kind(18) ! long (integer*8)
604
integer, parameter, private :: BUD_ID_LEn = 36
605
character(len=*), parameter, private :: &
606
BUD_MOd = 'BUD_CC2(BUD_MOD,_)BUD_MOD_NAME'
607
character(len=*), parameter, private :: &
608
BUD_TYPe = "LL_iArray1D"
610
type(LL_iArray1D_), pointer :: D => null()
611
integer :: error_ = 0
614
type(LL_iArray1D_LList), pointer :: ll => null()
615
type(LL_iArray1D_LList), pointer :: head => null()
617
character(len=BUD_ID_LEN) :: id_ = "null_id"
618
end type LL_iArray1D_
619
type LL_iArray1D_LList
620
type(LL_iArray1D_LList), pointer :: prev => null()
621
type(LL_iArray1D_LList), pointer :: next => null()
624
private :: LL_iArray1D_LList
626
module procedure new_
627
module procedure new_data_
630
interface assignment(=)
631
module procedure set_data_
634
module procedure size_llist_
638
module procedure size_llist_
642
module procedure set_data_
643
module procedure set_data_idx_
647
module procedure add_node_
648
module procedure add_node_data_
652
module procedure get_node_data_idx_
656
module procedure get_node_data_idx_
660
module procedure set_head_idx_
664
module procedure itt_step_
665
module procedure itt_step_i_
668
interface remove_node
669
module procedure remove_node_
671
public :: remove_node
672
interface remove_node_data
673
module procedure remove_node_data_
675
public :: remove_node_data
677
module procedure copy_
680
public :: LL_iArray1D
681
private :: LL_iArray1D_
682
interface assignment(=)
683
module procedure common_assign_
685
public :: assignment(=)
686
private :: common_assign_
688
module procedure common_initialize_
691
private :: common_initialize_
692
interface is_initialized
693
module procedure common_is_initialized_
695
public :: is_initialized
696
private :: common_is_initialized_
697
interface initialized
698
module procedure common_is_initialized_
700
public :: initialized
702
module procedure common_is_initialized_
706
module procedure common_is_same_
709
private :: common_is_same_
711
module procedure common_is_same_
715
module procedure common_delete_
718
private :: common_delete_
720
module procedure common_nullify_
723
private :: common_nullify_
725
module procedure copy_
728
private :: common_copy_
730
module procedure print_
734
module procedure common_references_
737
private :: common_references_
739
module procedure common_references_
743
module procedure common_set_error_is_
744
module procedure common_set_error_ii_
745
module procedure common_set_error_il_
748
private :: common_set_error_is_
749
private :: common_set_error_ii_
750
private :: common_set_error_il_
752
module procedure common_error_
755
private :: common_error_
757
subroutine common_copy_(from, to)
758
type(LL_iArray1D), intent(in) :: from
759
type(LL_iArray1D), intent(inout) :: to
760
call set_error(to, error(from))
761
end subroutine common_copy_
762
subroutine common_initialize_(this)
763
type(LL_iArray1D), intent(inout) :: this
766
allocate(this%D, stat=error)
767
call set_error(this, error)
768
if ( error /= 0 ) return
770
call common_tag_object_(this)
771
end subroutine common_initialize_
772
pure function common_is_initialized_(this) result(init)
773
type(LL_iArray1D), intent(in) :: this
775
init = associated(this%D)
776
end function common_is_initialized_
777
elemental function common_is_same_(lhs, rhs) result(same)
778
type(LL_iArray1D), intent(in) :: lhs, rhs
780
same = is_initd(lhs) .and. is_initd(rhs)
781
if ( .not. same ) return
782
same = associated(lhs%D, target=rhs%D)
783
end function common_is_same_
784
subroutine common_delete_(this)
785
type(LL_iArray1D), intent(inout) :: this
787
call set_error(this, 0)
788
if (.not. is_initd(this) ) return
789
this%D%refs_ = this%D%refs_ - 1
790
if ( 0 == this%D%refs_ ) then
792
deallocate(this%D, stat=error)
793
call set_error(this, error)
796
end subroutine common_delete_
797
elemental subroutine common_nullify_(this)
798
type(LL_iArray1D), intent(inout) :: this
799
if (.not. is_initd(this) ) return
801
end subroutine common_nullify_
802
subroutine common_assign_(lhs, rhs)
803
type(LL_iArray1D), intent(inout) :: lhs
804
type(LL_iArray1D), intent(in) :: rhs
806
if ( .not. is_initd(rhs) ) return
808
lhs%D%refs_ = rhs%D%refs_ + 1
809
end subroutine common_assign_
810
elemental function common_references_(this) result(refs)
811
type(LL_iArray1D), intent(in) :: this
813
if ( is_initd(this) ) then
818
end function common_references_
819
elemental function common_error_(this) result(error)
820
type(LL_iArray1D), intent(in) :: this
822
if ( is_initd(this) ) then
827
end function common_error_
828
elemental subroutine common_set_error_is_(this, error)
829
type(LL_iArray1D), intent(inout) :: this
830
integer(is_), intent(in) :: error
832
end subroutine common_set_error_is_
833
elemental subroutine common_set_error_ii_(this, error)
834
type(LL_iArray1D), intent(inout) :: this
835
integer(ii_), intent(in) :: error
837
end subroutine common_set_error_ii_
838
elemental subroutine common_set_error_il_(this, error)
839
type(LL_iArray1D), intent(inout) :: this
840
integer(il_), intent(in) :: error
842
end subroutine common_set_error_il_
843
elemental function common_id_(this) result(str)
844
type(LL_iArray1D), intent(in) :: this
845
character(len=BUD_ID_LEn) :: str
847
end function common_id_
848
subroutine common_tag_object_(this)
849
type(LL_iArray1D), intent(inout) :: this
850
end subroutine common_tag_object_
851
subroutine delete_(this)
852
type(LL_iArray1D), intent(inout) :: this
853
type(LL_iArray1D_LList), pointer :: head, tmp
854
if ( associated(this%D%head) .and. .not. &
855
associated(this%D%ll) ) then
861
if ( associated(head) ) then
862
do while ( associated(head%prev) )
863
if ( associated(head%prev, this%D%ll) ) exit
866
if ( associated(head%prev, this%D%ll) ) then
871
do while ( associated(head) )
872
if ( associated(head%next, this%D%ll) ) exit
879
if ( associated(this%D%ll) ) then
880
call delete(this%D%ll%D)
881
deallocate(this%D%ll)
885
end subroutine delete_
886
subroutine new_(this)
887
type(LL_iArray1D), intent(inout) :: this
888
call initialize(this)
890
subroutine new_data_(this, D)
891
type(LL_iArray1D), intent(inout) :: this
892
type(iArray1D), intent(in) :: D
895
this%D%head => this%D%ll
897
end subroutine new_data_
898
subroutine get_ll_headp(this, head)
899
type(LL_iArray1D), intent(in) :: this
900
type(LL_iArray1D_LList), pointer :: head
901
if ( .not. is_initd(this) ) then
906
do while ( associated(head%prev) )
908
if ( associated(head, this%D%head) ) exit
910
end subroutine get_ll_headp
911
subroutine get_ll_tailp(this, tail)
912
type(LL_iArray1D), intent(in) :: this
913
type(LL_iArray1D_LList), pointer :: tail
914
if ( .not. is_initd(this) ) then
919
do while ( associated(tail%next) )
921
if ( associated(tail, this%D%head) ) exit
923
end subroutine get_ll_tailp
924
subroutine get_ll_idxp(this, node, index)
925
type(LL_iArray1D), intent(in), target :: this
926
type(LL_iArray1D_LList), pointer :: node
927
integer, intent(in), optional :: index
930
if ( .not. is_initd(this) ) return
932
if ( present(index) ) lindex = index
934
do while ( lindex < 0 .and. associated(node%prev) )
938
do while ( lindex > 0 .and. associated(node%next) )
942
if ( lindex /= 0 ) then
946
end subroutine get_ll_idxp
947
subroutine append_node(ll)
948
type(LL_iArray1D_LList), pointer :: ll
949
type(LL_iArray1D_LList), pointer :: tmp => null()
950
if ( .not. associated(ll) ) return
954
if ( associated(ll%next) ) then
959
end subroutine append_node
960
function size_llist_(this) result (nnodes)
961
type(LL_iArray1D), intent(in), target :: this
963
type(LL_iArray1D_LList), pointer :: head, tmp
965
if ( .not. is_initd(this) ) return
966
call get_ll_headp(this, head)
968
do while ( associated(tmp) )
971
if ( associated(tmp, head) ) exit
973
end function size_llist_
974
subroutine add_node_(this)
975
type(LL_iArray1D), intent(inout) :: this
976
type(LL_iArray1D_LList), pointer :: tail
977
if ( .not. is_initd(this) ) then
980
this%D%head => this%D%ll
983
call get_ll_tailp(this, tail)
984
call append_node(tail)
985
end subroutine add_node_
986
subroutine add_node_data_(this, D)
987
type(LL_iArray1D), intent(inout) :: this
988
type(iArray1D), intent(in) :: D
989
type(LL_iArray1D_LList), pointer :: tail
990
call get_ll_tailp(this, tail)
991
if ( .not. associated(tail) ) then
995
call append_node(tail)
997
end subroutine add_node_data_
998
subroutine set_data_(this, D)
999
type(LL_iArray1D), intent(inout) :: this
1000
type(iArray1D), intent(in) :: D
1001
if ( is_initd(this) ) then
1004
end subroutine set_data_
1005
subroutine set_data_idx_(this, D, index)
1006
type(LL_iArray1D), intent(inout) :: this
1007
type(iArray1D), intent(in) :: D
1008
integer, intent(in) :: index
1009
type(LL_iArray1D_LList), pointer :: node
1010
call get_ll_idxp(this, node, index)
1011
if ( .not. associated(node) ) return
1013
end subroutine set_data_idx_
1014
subroutine set_head_idx_(this, index)
1015
type(LL_iArray1D), intent(inout) :: this
1016
integer, intent(in) :: index
1017
type(LL_iArray1D_LList), pointer :: node
1018
call get_ll_idxp(this, node, index)
1019
if ( .not. associated(node) ) return
1021
end subroutine set_head_idx_
1022
subroutine get_node_data_idx_(this, D, index)
1023
type(LL_iArray1D), intent(in), target :: this
1024
type(iArray1D), intent(inout) :: D
1025
integer, intent(in), optional :: index
1026
type(LL_iArray1D_LList), pointer :: node
1028
if ( .not. is_initd(this) ) return
1029
call get_ll_idxp(this, node, index)
1030
if ( associated(node) ) D = node%D
1031
end subroutine get_node_data_idx_
1032
function itt_step_(this, itt) result(itterated)
1033
type(LL_iArray1D), intent(in) :: this
1034
type(LL_iArray1D), intent(inout) :: itt
1035
logical :: itterated
1037
if ( .not. is_initd(this) ) then
1041
if ( .not. is_initd(itt) ) then
1043
itt%D%head => this%D%head
1044
itterated = associated(itt%D%head)
1046
itt%D%head => itt%D%head%next
1047
itterated = associated(itt%D%head)
1048
if ( itterated ) then
1049
itterated = .not. associated(itt%D%head, this%D%head)
1052
if ( .not. itterated ) then
1055
end function itt_step_
1056
function itt_step_i_(this, itt, i) result(itterated)
1057
type(LL_iArray1D), intent(in) :: this
1058
type(LL_iArray1D), intent(inout) :: itt
1059
integer, intent(in) :: i
1060
logical :: itterated
1063
if ( .not. is_initd(this) ) then
1068
if ( .not. is_initd(itt) ) then
1070
itt%D%head => this%D%head
1071
itterated = associated(itt%D%head)
1072
else if ( i > 0 ) then
1073
do while ( is /= i )
1075
itt%D%head => itt%D%head%next
1076
itterated = associated(itt%D%head)
1077
if ( itterated ) then
1078
itterated = .not. associated(itt%D%head, this%D%head)
1080
if ( .not. itterated ) exit
1082
else if ( i < 0 ) then
1083
do while ( is /= i )
1085
itt%D%head => itt%D%head%prev
1086
itterated = associated(itt%D%head)
1087
if ( itterated ) then
1088
itterated = .not. associated(itt%D%head, this%D%head)
1090
if ( .not. itterated ) exit
1093
if ( .not. itterated ) then
1097
end function itt_step_i_
1098
subroutine remove_node_(this, index)
1099
type(LL_iArray1D), intent(inout), target :: this
1100
integer, intent(in) :: index
1101
type(LL_iArray1D_LList), pointer :: node, pnode, nnode
1102
if ( .not. is_initd(this) ) return
1103
call get_ll_idxp(this, node, index)
1104
if ( .not. associated(node) ) return
1109
if ( associated(pnode) ) then
1112
if ( associated(nnode) ) then
1117
end subroutine remove_node_
1118
subroutine remove_node_data_(this, index)
1119
type(LL_iArray1D), intent(inout), target :: this
1120
integer, intent(in), optional :: index
1121
type(LL_iArray1D_LList), pointer :: node
1122
if ( .not. is_initd(this) ) return
1123
call get_ll_idxp(this, node, index)
1124
if ( .not. associated(node) ) return
1126
end subroutine remove_node_data_
1127
subroutine copy_(from, to)
1128
type(LL_iArray1D), intent(inout) :: from, to
1129
type(LL_iArray1D_LList), pointer :: t, f
1131
if ( .not. is_initd(from) ) return
1136
do while ( associated(f%next) )
1142
if ( associated(t, to%D%head) ) return
1146
do while ( associated(f%prev) )
1153
end subroutine copy_
1154
subroutine print_(this, info, indent)
1155
type(LL_iArray1D), intent(in), target :: this
1156
character(len=*), intent(in), optional :: info
1157
integer, intent(in), optional :: indent
1159
type(LL_iArray1D_LList), pointer :: node
1160
character(len=32) :: fmt
1161
character(len=256) :: name
1162
name = "LL_iArray1D"
1163
if ( present(info) ) name = info
1165
if ( present(indent) ) lindent = indent
1166
write(fmt, '(a,i0,a)') '(t',lindent,',3a)'
1167
if ( .not. is_initd(this) ) then
1168
write(*,fmt) "<", trim(name), " not initialized>"
1171
write(fmt, '(a,i0,a)') '(t',lindent,',3a,i0,a)'
1172
write(*,fmt) "<<", trim(name), " llist, nodes=",nodes(this),">"
1173
lindent = lindent + 2 ! step indentation
1174
call get_ll_headp(this, node)
1175
do while ( associated(node) )
1176
if ( associated(node, this%D%head) ) then
1177
write(fmt, '(a,i0,a)') '(t',lindent,',a)'
1178
call print(node%D, indent = lindent+2)
1180
call print(node%D, indent = lindent)
1184
lindent = lindent - 2 ! go back to requested indentation
1185
write(fmt, '(a,i0,a)') '(t',lindent,',a,i0,a)'
1186
write(*,fmt) " <llist-refs: ", references(this), ">>"
1187
end subroutine print_
1189
module bud_LL_lArray1D
1193
integer, parameter :: rr_ = selected_real_kind(p=6) ! single (real*4)
1194
integer, parameter :: rd_ = selected_real_kind(p=15) ! double (real*8)
1195
integer, parameter :: is_ = selected_int_kind(4) ! short (integer*2)
1196
integer, parameter :: ii_ = selected_int_kind(9) ! int (integer*4)
1197
integer, parameter :: il_ = selected_int_kind(18) ! long (integer*8)
1198
integer, parameter, private :: BUD_ID_LEn = 36
1199
character(len=*), parameter, private :: &
1200
BUD_MOd = 'BUD_CC2(BUD_MOD,_)BUD_MOD_NAME'
1201
character(len=*), parameter, private :: &
1202
BUD_TYPe = "LL_lArray1D"
1204
type(LL_lArray1D_), pointer :: D => null()
1205
integer :: error_ = 0
1206
end type LL_lArray1D
1208
type(LL_lArray1D_LList), pointer :: ll => null()
1209
type(LL_lArray1D_LList), pointer :: head => null()
1210
integer :: refs_ = 0
1211
character(len=BUD_ID_LEN) :: id_ = "null_id"
1212
end type LL_lArray1D_
1213
type LL_lArray1D_LList
1214
type(LL_lArray1D_LList), pointer :: prev => null()
1215
type(LL_lArray1D_LList), pointer :: next => null()
1218
private :: LL_lArray1D_LList
1220
module procedure new_
1221
module procedure new_data_
1224
interface assignment(=)
1225
module procedure set_data_
1228
module procedure size_llist_
1232
module procedure size_llist_
1236
module procedure set_data_
1237
module procedure set_data_idx_
1241
module procedure add_node_
1242
module procedure add_node_data_
1246
module procedure get_node_data_idx_
1250
module procedure get_node_data_idx_
1254
module procedure set_head_idx_
1258
module procedure itt_step_
1259
module procedure itt_step_i_
1262
interface remove_node
1263
module procedure remove_node_
1265
public :: remove_node
1266
interface remove_node_data
1267
module procedure remove_node_data_
1269
public :: remove_node_data
1271
module procedure copy_
1274
public :: LL_lArray1D
1275
private :: LL_lArray1D_
1276
interface assignment(=)
1277
module procedure common_assign_
1279
public :: assignment(=)
1280
private :: common_assign_
1281
interface initialize
1282
module procedure common_initialize_
1284
public :: initialize
1285
private :: common_initialize_
1286
interface is_initialized
1287
module procedure common_is_initialized_
1289
public :: is_initialized
1290
private :: common_is_initialized_
1291
interface initialized
1292
module procedure common_is_initialized_
1294
public :: initialized
1296
module procedure common_is_initialized_
1300
module procedure common_is_same_
1303
private :: common_is_same_
1305
module procedure common_is_same_
1309
module procedure common_delete_
1312
private :: common_delete_
1314
module procedure common_nullify_
1317
private :: common_nullify_
1319
module procedure copy_
1322
private :: common_copy_
1324
module procedure print_
1327
interface references
1328
module procedure common_references_
1330
public :: references
1331
private :: common_references_
1333
module procedure common_references_
1337
module procedure common_set_error_is_
1338
module procedure common_set_error_ii_
1339
module procedure common_set_error_il_
1342
private :: common_set_error_is_
1343
private :: common_set_error_ii_
1344
private :: common_set_error_il_
1346
module procedure common_error_
1349
private :: common_error_
1351
subroutine common_copy_(from, to)
1352
type(LL_lArray1D), intent(in) :: from
1353
type(LL_lArray1D), intent(inout) :: to
1354
call set_error(to, error(from))
1355
end subroutine common_copy_
1356
subroutine common_initialize_(this)
1357
type(LL_lArray1D), intent(inout) :: this
1360
allocate(this%D, stat=error)
1361
call set_error(this, error)
1362
if ( error /= 0 ) return
1364
call common_tag_object_(this)
1365
end subroutine common_initialize_
1366
pure function common_is_initialized_(this) result(init)
1367
type(LL_lArray1D), intent(in) :: this
1369
init = associated(this%D)
1370
end function common_is_initialized_
1371
elemental function common_is_same_(lhs, rhs) result(same)
1372
type(LL_lArray1D), intent(in) :: lhs, rhs
1374
same = is_initd(lhs) .and. is_initd(rhs)
1375
if ( .not. same ) return
1376
same = associated(lhs%D, target=rhs%D)
1377
end function common_is_same_
1378
subroutine common_delete_(this)
1379
type(LL_lArray1D), intent(inout) :: this
1381
call set_error(this, 0)
1382
if (.not. is_initd(this) ) return
1383
this%D%refs_ = this%D%refs_ - 1
1384
if ( 0 == this%D%refs_ ) then
1386
deallocate(this%D, stat=error)
1387
call set_error(this, error)
1390
end subroutine common_delete_
1391
elemental subroutine common_nullify_(this)
1392
type(LL_lArray1D), intent(inout) :: this
1393
if (.not. is_initd(this) ) return
1395
end subroutine common_nullify_
1396
subroutine common_assign_(lhs, rhs)
1397
type(LL_lArray1D), intent(inout) :: lhs
1398
type(LL_lArray1D), intent(in) :: rhs
1400
if ( .not. is_initd(rhs) ) return
1402
lhs%D%refs_ = rhs%D%refs_ + 1
1403
end subroutine common_assign_
1404
elemental function common_references_(this) result(refs)
1405
type(LL_lArray1D), intent(in) :: this
1407
if ( is_initd(this) ) then
1412
end function common_references_
1413
elemental function common_error_(this) result(error)
1414
type(LL_lArray1D), intent(in) :: this
1416
if ( is_initd(this) ) then
1421
end function common_error_
1422
elemental subroutine common_set_error_is_(this, error)
1423
type(LL_lArray1D), intent(inout) :: this
1424
integer(is_), intent(in) :: error
1426
end subroutine common_set_error_is_
1427
elemental subroutine common_set_error_ii_(this, error)
1428
type(LL_lArray1D), intent(inout) :: this
1429
integer(ii_), intent(in) :: error
1431
end subroutine common_set_error_ii_
1432
elemental subroutine common_set_error_il_(this, error)
1433
type(LL_lArray1D), intent(inout) :: this
1434
integer(il_), intent(in) :: error
1436
end subroutine common_set_error_il_
1437
elemental function common_id_(this) result(str)
1438
type(LL_lArray1D), intent(in) :: this
1439
character(len=BUD_ID_LEn) :: str
1441
end function common_id_
1442
subroutine common_tag_object_(this)
1443
type(LL_lArray1D), intent(inout) :: this
1444
end subroutine common_tag_object_
1445
subroutine delete_(this)
1446
type(LL_lArray1D), intent(inout) :: this
1447
type(LL_lArray1D_LList), pointer :: head, tmp
1448
if ( associated(this%D%head) .and. .not. &
1449
associated(this%D%ll) ) then
1450
nullify(this%D%head)
1455
if ( associated(head) ) then
1456
do while ( associated(head%prev) )
1457
if ( associated(head%prev, this%D%ll) ) exit
1460
if ( associated(head%prev, this%D%ll) ) then
1465
do while ( associated(head) )
1466
if ( associated(head%next, this%D%ll) ) exit
1473
if ( associated(this%D%ll) ) then
1474
call delete(this%D%ll%D)
1475
deallocate(this%D%ll)
1478
nullify(this%D%head)
1479
end subroutine delete_
1480
subroutine new_(this)
1481
type(LL_lArray1D), intent(inout) :: this
1482
call initialize(this)
1484
subroutine new_data_(this, D)
1485
type(LL_lArray1D), intent(inout) :: this
1486
type(lArray1D), intent(in) :: D
1489
this%D%head => this%D%ll
1491
end subroutine new_data_
1492
subroutine get_ll_headp(this, head)
1493
type(LL_lArray1D), intent(in) :: this
1494
type(LL_lArray1D_LList), pointer :: head
1495
if ( .not. is_initd(this) ) then
1500
do while ( associated(head%prev) )
1502
if ( associated(head, this%D%head) ) exit
1504
end subroutine get_ll_headp
1505
subroutine get_ll_tailp(this, tail)
1506
type(LL_lArray1D), intent(in) :: this
1507
type(LL_lArray1D_LList), pointer :: tail
1508
if ( .not. is_initd(this) ) then
1513
do while ( associated(tail%next) )
1515
if ( associated(tail, this%D%head) ) exit
1517
end subroutine get_ll_tailp
1518
subroutine get_ll_idxp(this, node, index)
1519
type(LL_lArray1D), intent(in), target :: this
1520
type(LL_lArray1D_LList), pointer :: node
1521
integer, intent(in), optional :: index
1524
if ( .not. is_initd(this) ) return
1526
if ( present(index) ) lindex = index
1528
do while ( lindex < 0 .and. associated(node%prev) )
1532
do while ( lindex > 0 .and. associated(node%next) )
1536
if ( lindex /= 0 ) then
1540
end subroutine get_ll_idxp
1541
subroutine append_node(ll)
1542
type(LL_lArray1D_LList), pointer :: ll
1543
type(LL_lArray1D_LList), pointer :: tmp => null()
1544
if ( .not. associated(ll) ) return
1548
if ( associated(ll%next) ) then
1553
end subroutine append_node
1554
function size_llist_(this) result (nnodes)
1555
type(LL_lArray1D), intent(in), target :: this
1557
type(LL_lArray1D_LList), pointer :: head, tmp
1559
if ( .not. is_initd(this) ) return
1560
call get_ll_headp(this, head)
1562
do while ( associated(tmp) )
1565
if ( associated(tmp, head) ) exit
1567
end function size_llist_
1568
subroutine add_node_(this)
1569
type(LL_lArray1D), intent(inout) :: this
1570
type(LL_lArray1D_LList), pointer :: tail
1571
if ( .not. is_initd(this) ) then
1574
this%D%head => this%D%ll
1577
call get_ll_tailp(this, tail)
1578
call append_node(tail)
1579
end subroutine add_node_
1580
subroutine add_node_data_(this, D)
1581
type(LL_lArray1D), intent(inout) :: this
1582
type(lArray1D), intent(in) :: D
1583
type(LL_lArray1D_LList), pointer :: tail
1584
call get_ll_tailp(this, tail)
1585
if ( .not. associated(tail) ) then
1589
call append_node(tail)
1591
end subroutine add_node_data_
1592
subroutine set_data_(this, D)
1593
type(LL_lArray1D), intent(inout) :: this
1594
type(lArray1D), intent(in) :: D
1595
if ( is_initd(this) ) then
1598
end subroutine set_data_
1599
subroutine set_data_idx_(this, D, index)
1600
type(LL_lArray1D), intent(inout) :: this
1601
type(lArray1D), intent(in) :: D
1602
integer, intent(in) :: index
1603
type(LL_lArray1D_LList), pointer :: node
1604
call get_ll_idxp(this, node, index)
1605
if ( .not. associated(node) ) return
1607
end subroutine set_data_idx_
1608
subroutine set_head_idx_(this, index)
1609
type(LL_lArray1D), intent(inout) :: this
1610
integer, intent(in) :: index
1611
type(LL_lArray1D_LList), pointer :: node
1612
call get_ll_idxp(this, node, index)
1613
if ( .not. associated(node) ) return
1615
end subroutine set_head_idx_
1616
subroutine get_node_data_idx_(this, D, index)
1617
type(LL_lArray1D), intent(in), target :: this
1618
type(lArray1D), intent(inout) :: D
1619
integer, intent(in), optional :: index
1620
type(LL_lArray1D_LList), pointer :: node
1622
if ( .not. is_initd(this) ) return
1623
call get_ll_idxp(this, node, index)
1624
if ( associated(node) ) D = node%D
1625
end subroutine get_node_data_idx_
1626
function itt_step_(this, itt) result(itterated)
1627
type(LL_lArray1D), intent(in) :: this
1628
type(LL_lArray1D), intent(inout) :: itt
1629
logical :: itterated
1631
if ( .not. is_initd(this) ) then
1635
if ( .not. is_initd(itt) ) then
1637
itt%D%head => this%D%head
1638
itterated = associated(itt%D%head)
1640
itt%D%head => itt%D%head%next
1641
itterated = associated(itt%D%head)
1642
if ( itterated ) then
1643
itterated = .not. associated(itt%D%head, this%D%head)
1646
if ( .not. itterated ) then
1649
end function itt_step_
1650
function itt_step_i_(this, itt, i) result(itterated)
1651
type(LL_lArray1D), intent(in) :: this
1652
type(LL_lArray1D), intent(inout) :: itt
1653
integer, intent(in) :: i
1654
logical :: itterated
1657
if ( .not. is_initd(this) ) then
1662
if ( .not. is_initd(itt) ) then
1664
itt%D%head => this%D%head
1665
itterated = associated(itt%D%head)
1666
else if ( i > 0 ) then
1667
do while ( is /= i )
1669
itt%D%head => itt%D%head%next
1670
itterated = associated(itt%D%head)
1671
if ( itterated ) then
1672
itterated = .not. associated(itt%D%head, this%D%head)
1674
if ( .not. itterated ) exit
1676
else if ( i < 0 ) then
1677
do while ( is /= i )
1679
itt%D%head => itt%D%head%prev
1680
itterated = associated(itt%D%head)
1681
if ( itterated ) then
1682
itterated = .not. associated(itt%D%head, this%D%head)
1684
if ( .not. itterated ) exit
1687
if ( .not. itterated ) then
1691
end function itt_step_i_
1692
subroutine remove_node_(this, index)
1693
type(LL_lArray1D), intent(inout), target :: this
1694
integer, intent(in) :: index
1695
type(LL_lArray1D_LList), pointer :: node, pnode, nnode
1696
if ( .not. is_initd(this) ) return
1697
call get_ll_idxp(this, node, index)
1698
if ( .not. associated(node) ) return
1703
if ( associated(pnode) ) then
1706
if ( associated(nnode) ) then
1711
end subroutine remove_node_
1712
subroutine remove_node_data_(this, index)
1713
type(LL_lArray1D), intent(inout), target :: this
1714
integer, intent(in), optional :: index
1715
type(LL_lArray1D_LList), pointer :: node
1716
if ( .not. is_initd(this) ) return
1717
call get_ll_idxp(this, node, index)
1718
if ( .not. associated(node) ) return
1720
end subroutine remove_node_data_
1721
subroutine copy_(from, to)
1722
type(LL_lArray1D), intent(inout) :: from, to
1723
type(LL_lArray1D_LList), pointer :: t, f
1725
if ( .not. is_initd(from) ) return
1730
do while ( associated(f%next) )
1736
if ( associated(t, to%D%head) ) return
1740
do while ( associated(f%prev) )
1747
end subroutine copy_
1748
subroutine print_(this, info, indent)
1749
type(LL_lArray1D), intent(in), target :: this
1750
character(len=*), intent(in), optional :: info
1751
integer, intent(in), optional :: indent
1753
type(LL_lArray1D_LList), pointer :: node
1754
character(len=32) :: fmt
1755
character(len=256) :: name
1756
name = "LL_lArray1D"
1757
if ( present(info) ) name = info
1759
if ( present(indent) ) lindent = indent
1760
write(fmt, '(a,i0,a)') '(t',lindent,',3a)'
1761
if ( .not. is_initd(this) ) then
1762
write(*,fmt) "<", trim(name), " not initialized>"
1765
write(fmt, '(a,i0,a)') '(t',lindent,',3a,i0,a)'
1766
write(*,fmt) "<<", trim(name), " llist, nodes=",nodes(this),">"
1767
lindent = lindent + 2 ! step indentation
1768
call get_ll_headp(this, node)
1769
do while ( associated(node) )
1770
if ( associated(node, this%D%head) ) then
1771
write(fmt, '(a,i0,a)') '(t',lindent,',a)'
1772
call print(node%D, indent = lindent+2)
1774
call print(node%D, indent = lindent)
1778
lindent = lindent - 2 ! go back to requested indentation
1779
write(fmt, '(a,i0,a)') '(t',lindent,',a,i0,a)'
1780
write(*,fmt) " <llist-refs: ", references(this), ">>"
1781
end subroutine print_
1783
module bud_LL_rArray1D
1787
integer, parameter :: rr_ = selected_real_kind(p=6) ! single (real*4)
1788
integer, parameter :: rd_ = selected_real_kind(p=15) ! double (real*8)
1789
integer, parameter :: is_ = selected_int_kind(4) ! short (integer*2)
1790
integer, parameter :: ii_ = selected_int_kind(9) ! int (integer*4)
1791
integer, parameter :: il_ = selected_int_kind(18) ! long (integer*8)
1792
integer, parameter, private :: BUD_ID_LEn = 36
1793
character(len=*), parameter, private :: &
1794
BUD_MOd = 'BUD_CC2(BUD_MOD,_)BUD_MOD_NAME'
1795
character(len=*), parameter, private :: &
1796
BUD_TYPe = "LL_rArray1D"
1798
type(LL_rArray1D_), pointer :: D => null()
1799
integer :: error_ = 0
1800
end type LL_rArray1D
1802
type(LL_rArray1D_LList), pointer :: ll => null()
1803
type(LL_rArray1D_LList), pointer :: head => null()
1804
integer :: refs_ = 0
1805
character(len=BUD_ID_LEN) :: id_ = "null_id"
1806
end type LL_rArray1D_
1807
type LL_rArray1D_LList
1808
type(LL_rArray1D_LList), pointer :: prev => null()
1809
type(LL_rArray1D_LList), pointer :: next => null()
1812
private :: LL_rArray1D_LList
1814
module procedure new_
1815
module procedure new_data_
1818
interface assignment(=)
1819
module procedure set_data_
1822
module procedure size_llist_
1826
module procedure size_llist_
1830
module procedure set_data_
1831
module procedure set_data_idx_
1835
module procedure add_node_
1836
module procedure add_node_data_
1840
module procedure get_node_data_idx_
1844
module procedure get_node_data_idx_
1848
module procedure set_head_idx_
1852
module procedure itt_step_
1853
module procedure itt_step_i_
1856
interface remove_node
1857
module procedure remove_node_
1859
public :: remove_node
1860
interface remove_node_data
1861
module procedure remove_node_data_
1863
public :: remove_node_data
1865
module procedure copy_
1868
public :: LL_rArray1D
1869
private :: LL_rArray1D_
1870
interface assignment(=)
1871
module procedure common_assign_
1873
public :: assignment(=)
1874
private :: common_assign_
1875
interface initialize
1876
module procedure common_initialize_
1878
public :: initialize
1879
private :: common_initialize_
1880
interface is_initialized
1881
module procedure common_is_initialized_
1883
public :: is_initialized
1884
private :: common_is_initialized_
1885
interface initialized
1886
module procedure common_is_initialized_
1888
public :: initialized
1890
module procedure common_is_initialized_
1894
module procedure common_is_same_
1897
private :: common_is_same_
1899
module procedure common_is_same_
1903
module procedure common_delete_
1906
private :: common_delete_
1908
module procedure common_nullify_
1911
private :: common_nullify_
1913
module procedure copy_
1916
private :: common_copy_
1918
module procedure print_
1921
interface references
1922
module procedure common_references_
1924
public :: references
1925
private :: common_references_
1927
module procedure common_references_
1931
module procedure common_set_error_is_
1932
module procedure common_set_error_ii_
1933
module procedure common_set_error_il_
1936
private :: common_set_error_is_
1937
private :: common_set_error_ii_
1938
private :: common_set_error_il_
1940
module procedure common_error_
1943
private :: common_error_
1945
subroutine common_copy_(from, to)
1946
type(LL_rArray1D), intent(in) :: from
1947
type(LL_rArray1D), intent(inout) :: to
1948
call set_error(to, error(from))
1949
end subroutine common_copy_
1950
subroutine common_initialize_(this)
1951
type(LL_rArray1D), intent(inout) :: this
1954
allocate(this%D, stat=error)
1955
call set_error(this, error)
1956
if ( error /= 0 ) return
1958
call common_tag_object_(this)
1959
end subroutine common_initialize_
1960
pure function common_is_initialized_(this) result(init)
1961
type(LL_rArray1D), intent(in) :: this
1963
init = associated(this%D)
1964
end function common_is_initialized_
1965
elemental function common_is_same_(lhs, rhs) result(same)
1966
type(LL_rArray1D), intent(in) :: lhs, rhs
1968
same = is_initd(lhs) .and. is_initd(rhs)
1969
if ( .not. same ) return
1970
same = associated(lhs%D, target=rhs%D)
1971
end function common_is_same_
1972
subroutine common_delete_(this)
1973
type(LL_rArray1D), intent(inout) :: this
1975
call set_error(this, 0)
1976
if (.not. is_initd(this) ) return
1977
this%D%refs_ = this%D%refs_ - 1
1978
if ( 0 == this%D%refs_ ) then
1980
deallocate(this%D, stat=error)
1981
call set_error(this, error)
1984
end subroutine common_delete_
1985
elemental subroutine common_nullify_(this)
1986
type(LL_rArray1D), intent(inout) :: this
1987
if (.not. is_initd(this) ) return
1989
end subroutine common_nullify_
1990
subroutine common_assign_(lhs, rhs)
1991
type(LL_rArray1D), intent(inout) :: lhs
1992
type(LL_rArray1D), intent(in) :: rhs
1994
if ( .not. is_initd(rhs) ) return
1996
lhs%D%refs_ = rhs%D%refs_ + 1
1997
end subroutine common_assign_
1998
elemental function common_references_(this) result(refs)
1999
type(LL_rArray1D), intent(in) :: this
2001
if ( is_initd(this) ) then
2006
end function common_references_
2007
elemental function common_error_(this) result(error)
2008
type(LL_rArray1D), intent(in) :: this
2010
if ( is_initd(this) ) then
2015
end function common_error_
2016
elemental subroutine common_set_error_is_(this, error)
2017
type(LL_rArray1D), intent(inout) :: this
2018
integer(is_), intent(in) :: error
2020
end subroutine common_set_error_is_
2021
elemental subroutine common_set_error_ii_(this, error)
2022
type(LL_rArray1D), intent(inout) :: this
2023
integer(ii_), intent(in) :: error
2025
end subroutine common_set_error_ii_
2026
elemental subroutine common_set_error_il_(this, error)
2027
type(LL_rArray1D), intent(inout) :: this
2028
integer(il_), intent(in) :: error
2030
end subroutine common_set_error_il_
2031
elemental function common_id_(this) result(str)
2032
type(LL_rArray1D), intent(in) :: this
2033
character(len=BUD_ID_LEn) :: str
2035
end function common_id_
2036
subroutine common_tag_object_(this)
2037
type(LL_rArray1D), intent(inout) :: this
2038
end subroutine common_tag_object_
2039
subroutine delete_(this)
2040
type(LL_rArray1D), intent(inout) :: this
2041
type(LL_rArray1D_LList), pointer :: head, tmp
2042
if ( associated(this%D%head) .and. .not. &
2043
associated(this%D%ll) ) then
2044
nullify(this%D%head)
2049
if ( associated(head) ) then
2050
do while ( associated(head%prev) )
2051
if ( associated(head%prev, this%D%ll) ) exit
2054
if ( associated(head%prev, this%D%ll) ) then
2059
do while ( associated(head) )
2060
if ( associated(head%next, this%D%ll) ) exit
2067
if ( associated(this%D%ll) ) then
2068
call delete(this%D%ll%D)
2069
deallocate(this%D%ll)
2072
nullify(this%D%head)
2073
end subroutine delete_
2074
subroutine new_(this)
2075
type(LL_rArray1D), intent(inout) :: this
2076
call initialize(this)
2078
subroutine new_data_(this, D)
2079
type(LL_rArray1D), intent(inout) :: this
2080
type(rArray1D), intent(in) :: D
2083
this%D%head => this%D%ll
2085
end subroutine new_data_
2086
subroutine get_ll_headp(this, head)
2087
type(LL_rArray1D), intent(in) :: this
2088
type(LL_rArray1D_LList), pointer :: head
2089
if ( .not. is_initd(this) ) then
2094
do while ( associated(head%prev) )
2096
if ( associated(head, this%D%head) ) exit
2098
end subroutine get_ll_headp
2099
subroutine get_ll_tailp(this, tail)
2100
type(LL_rArray1D), intent(in) :: this
2101
type(LL_rArray1D_LList), pointer :: tail
2102
if ( .not. is_initd(this) ) then
2107
do while ( associated(tail%next) )
2109
if ( associated(tail, this%D%head) ) exit
2111
end subroutine get_ll_tailp
2112
subroutine get_ll_idxp(this, node, index)
2113
type(LL_rArray1D), intent(in), target :: this
2114
type(LL_rArray1D_LList), pointer :: node
2115
integer, intent(in), optional :: index
2118
if ( .not. is_initd(this) ) return
2120
if ( present(index) ) lindex = index
2122
do while ( lindex < 0 .and. associated(node%prev) )
2126
do while ( lindex > 0 .and. associated(node%next) )
2130
if ( lindex /= 0 ) then
2134
end subroutine get_ll_idxp
2135
subroutine append_node(ll)
2136
type(LL_rArray1D_LList), pointer :: ll
2137
type(LL_rArray1D_LList), pointer :: tmp => null()
2138
if ( .not. associated(ll) ) return
2142
if ( associated(ll%next) ) then
2147
end subroutine append_node
2148
function size_llist_(this) result (nnodes)
2149
type(LL_rArray1D), intent(in), target :: this
2151
type(LL_rArray1D_LList), pointer :: head, tmp
2153
if ( .not. is_initd(this) ) return
2154
call get_ll_headp(this, head)
2156
do while ( associated(tmp) )
2159
if ( associated(tmp, head) ) exit
2161
end function size_llist_
2162
subroutine add_node_(this)
2163
type(LL_rArray1D), intent(inout) :: this
2164
type(LL_rArray1D_LList), pointer :: tail
2165
if ( .not. is_initd(this) ) then
2168
this%D%head => this%D%ll
2171
call get_ll_tailp(this, tail)
2172
call append_node(tail)
2173
end subroutine add_node_
2174
subroutine add_node_data_(this, D)
2175
type(LL_rArray1D), intent(inout) :: this
2176
type(rArray1D), intent(in) :: D
2177
type(LL_rArray1D_LList), pointer :: tail
2178
call get_ll_tailp(this, tail)
2179
if ( .not. associated(tail) ) then
2183
call append_node(tail)
2185
end subroutine add_node_data_
2186
subroutine set_data_(this, D)
2187
type(LL_rArray1D), intent(inout) :: this
2188
type(rArray1D), intent(in) :: D
2189
if ( is_initd(this) ) then
2192
end subroutine set_data_
2193
subroutine set_data_idx_(this, D, index)
2194
type(LL_rArray1D), intent(inout) :: this
2195
type(rArray1D), intent(in) :: D
2196
integer, intent(in) :: index
2197
type(LL_rArray1D_LList), pointer :: node
2198
call get_ll_idxp(this, node, index)
2199
if ( .not. associated(node) ) return
2201
end subroutine set_data_idx_
2202
subroutine set_head_idx_(this, index)
2203
type(LL_rArray1D), intent(inout) :: this
2204
integer, intent(in) :: index
2205
type(LL_rArray1D_LList), pointer :: node
2206
call get_ll_idxp(this, node, index)
2207
if ( .not. associated(node) ) return
2209
end subroutine set_head_idx_
2210
subroutine get_node_data_idx_(this, D, index)
2211
type(LL_rArray1D), intent(in), target :: this
2212
type(rArray1D), intent(inout) :: D
2213
integer, intent(in), optional :: index
2214
type(LL_rArray1D_LList), pointer :: node
2216
if ( .not. is_initd(this) ) return
2217
call get_ll_idxp(this, node, index)
2218
if ( associated(node) ) D = node%D
2219
end subroutine get_node_data_idx_
2220
function itt_step_(this, itt) result(itterated)
2221
type(LL_rArray1D), intent(in) :: this
2222
type(LL_rArray1D), intent(inout) :: itt
2223
logical :: itterated
2225
if ( .not. is_initd(this) ) then
2229
if ( .not. is_initd(itt) ) then
2231
itt%D%head => this%D%head
2232
itterated = associated(itt%D%head)
2234
itt%D%head => itt%D%head%next
2235
itterated = associated(itt%D%head)
2236
if ( itterated ) then
2237
itterated = .not. associated(itt%D%head, this%D%head)
2240
if ( .not. itterated ) then
2243
end function itt_step_
2244
function itt_step_i_(this, itt, i) result(itterated)
2245
type(LL_rArray1D), intent(in) :: this
2246
type(LL_rArray1D), intent(inout) :: itt
2247
integer, intent(in) :: i
2248
logical :: itterated
2251
if ( .not. is_initd(this) ) then
2256
if ( .not. is_initd(itt) ) then
2258
itt%D%head => this%D%head
2259
itterated = associated(itt%D%head)
2260
else if ( i > 0 ) then
2261
do while ( is /= i )
2263
itt%D%head => itt%D%head%next
2264
itterated = associated(itt%D%head)
2265
if ( itterated ) then
2266
itterated = .not. associated(itt%D%head, this%D%head)
2268
if ( .not. itterated ) exit
2270
else if ( i < 0 ) then
2271
do while ( is /= i )
2273
itt%D%head => itt%D%head%prev
2274
itterated = associated(itt%D%head)
2275
if ( itterated ) then
2276
itterated = .not. associated(itt%D%head, this%D%head)
2278
if ( .not. itterated ) exit
2281
if ( .not. itterated ) then
2285
end function itt_step_i_
2286
subroutine remove_node_(this, index)
2287
type(LL_rArray1D), intent(inout), target :: this
2288
integer, intent(in) :: index
2289
type(LL_rArray1D_LList), pointer :: node, pnode, nnode
2290
if ( .not. is_initd(this) ) return
2291
call get_ll_idxp(this, node, index)
2292
if ( .not. associated(node) ) return
2297
if ( associated(pnode) ) then
2300
if ( associated(nnode) ) then
2305
end subroutine remove_node_
2306
subroutine remove_node_data_(this, index)
2307
type(LL_rArray1D), intent(inout), target :: this
2308
integer, intent(in), optional :: index
2309
type(LL_rArray1D_LList), pointer :: node
2310
if ( .not. is_initd(this) ) return
2311
call get_ll_idxp(this, node, index)
2312
if ( .not. associated(node) ) return
2314
end subroutine remove_node_data_
2315
subroutine copy_(from, to)
2316
type(LL_rArray1D), intent(inout) :: from, to
2317
type(LL_rArray1D_LList), pointer :: t, f
2319
if ( .not. is_initd(from) ) return
2324
do while ( associated(f%next) )
2330
if ( associated(t, to%D%head) ) return
2334
do while ( associated(f%prev) )
2341
end subroutine copy_
2342
subroutine print_(this, info, indent)
2343
type(LL_rArray1D), intent(in), target :: this
2344
character(len=*), intent(in), optional :: info
2345
integer, intent(in), optional :: indent
2347
type(LL_rArray1D_LList), pointer :: node
2348
character(len=32) :: fmt
2349
character(len=256) :: name
2350
name = "LL_rArray1D"
2351
if ( present(info) ) name = info
2353
if ( present(indent) ) lindent = indent
2354
write(fmt, '(a,i0,a)') '(t',lindent,',3a)'
2355
if ( .not. is_initd(this) ) then
2356
write(*,fmt) "<", trim(name), " not initialized>"
2359
write(fmt, '(a,i0,a)') '(t',lindent,',3a,i0,a)'
2360
write(*,fmt) "<<", trim(name), " llist, nodes=",nodes(this),">"
2361
lindent = lindent + 2 ! step indentation
2362
call get_ll_headp(this, node)
2363
do while ( associated(node) )
2364
if ( associated(node, this%D%head) ) then
2365
write(fmt, '(a,i0,a)') '(t',lindent,',a)'
2366
call print(node%D, indent = lindent+2)
2368
call print(node%D, indent = lindent)
2372
lindent = lindent - 2 ! go back to requested indentation
2373
write(fmt, '(a,i0,a)') '(t',lindent,',a,i0,a)'
2374
write(*,fmt) " <llist-refs: ", references(this), ">>"
2375
end subroutine print_
2377
module bud_LL_dArray1D
2381
integer, parameter :: rr_ = selected_real_kind(p=6) ! single (real*4)
2382
integer, parameter :: rd_ = selected_real_kind(p=15) ! double (real*8)
2383
integer, parameter :: is_ = selected_int_kind(4) ! short (integer*2)
2384
integer, parameter :: ii_ = selected_int_kind(9) ! int (integer*4)
2385
integer, parameter :: il_ = selected_int_kind(18) ! long (integer*8)
2386
integer, parameter, private :: BUD_ID_LEn = 36
2387
character(len=*), parameter, private :: &
2388
BUD_MOd = 'BUD_CC2(BUD_MOD,_)BUD_MOD_NAME'
2389
character(len=*), parameter, private :: &
2390
BUD_TYPe = "LL_dArray1D"
2392
type(LL_dArray1D_), pointer :: D => null()
2393
integer :: error_ = 0
2394
end type LL_dArray1D
2396
type(LL_dArray1D_LList), pointer :: ll => null()
2397
type(LL_dArray1D_LList), pointer :: head => null()
2398
integer :: refs_ = 0
2399
character(len=BUD_ID_LEN) :: id_ = "null_id"
2400
end type LL_dArray1D_
2401
type LL_dArray1D_LList
2402
type(LL_dArray1D_LList), pointer :: prev => null()
2403
type(LL_dArray1D_LList), pointer :: next => null()
2406
private :: LL_dArray1D_LList
2408
module procedure new_
2409
module procedure new_data_
2412
interface assignment(=)
2413
module procedure set_data_
2416
module procedure size_llist_
2420
module procedure size_llist_
2424
module procedure set_data_
2425
module procedure set_data_idx_
2429
module procedure add_node_
2430
module procedure add_node_data_
2434
module procedure get_node_data_idx_
2438
module procedure get_node_data_idx_
2442
module procedure set_head_idx_
2446
module procedure itt_step_
2447
module procedure itt_step_i_
2450
interface remove_node
2451
module procedure remove_node_
2453
public :: remove_node
2454
interface remove_node_data
2455
module procedure remove_node_data_
2457
public :: remove_node_data
2459
module procedure copy_
2462
public :: LL_dArray1D
2463
private :: LL_dArray1D_
2464
interface assignment(=)
2465
module procedure common_assign_
2467
public :: assignment(=)
2468
private :: common_assign_
2469
interface initialize
2470
module procedure common_initialize_
2472
public :: initialize
2473
private :: common_initialize_
2474
interface is_initialized
2475
module procedure common_is_initialized_
2477
public :: is_initialized
2478
private :: common_is_initialized_
2479
interface initialized
2480
module procedure common_is_initialized_
2482
public :: initialized
2484
module procedure common_is_initialized_
2488
module procedure common_is_same_
2491
private :: common_is_same_
2493
module procedure common_is_same_
2497
module procedure common_delete_
2500
private :: common_delete_
2502
module procedure common_nullify_
2505
private :: common_nullify_
2507
module procedure copy_
2510
private :: common_copy_
2512
module procedure print_
2515
interface references
2516
module procedure common_references_
2518
public :: references
2519
private :: common_references_
2521
module procedure common_references_
2525
module procedure common_set_error_is_
2526
module procedure common_set_error_ii_
2527
module procedure common_set_error_il_
2530
private :: common_set_error_is_
2531
private :: common_set_error_ii_
2532
private :: common_set_error_il_
2534
module procedure common_error_
2537
private :: common_error_
2539
subroutine common_copy_(from, to)
2540
type(LL_dArray1D), intent(in) :: from
2541
type(LL_dArray1D), intent(inout) :: to
2542
call set_error(to, error(from))
2543
end subroutine common_copy_
2544
subroutine common_initialize_(this)
2545
type(LL_dArray1D), intent(inout) :: this
2548
allocate(this%D, stat=error)
2549
call set_error(this, error)
2550
if ( error /= 0 ) return
2552
call common_tag_object_(this)
2553
end subroutine common_initialize_
2554
pure function common_is_initialized_(this) result(init)
2555
type(LL_dArray1D), intent(in) :: this
2557
init = associated(this%D)
2558
end function common_is_initialized_
2559
elemental function common_is_same_(lhs, rhs) result(same)
2560
type(LL_dArray1D), intent(in) :: lhs, rhs
2562
same = is_initd(lhs) .and. is_initd(rhs)
2563
if ( .not. same ) return
2564
same = associated(lhs%D, target=rhs%D)
2565
end function common_is_same_
2566
subroutine common_delete_(this)
2567
type(LL_dArray1D), intent(inout) :: this
2569
call set_error(this, 0)
2570
if (.not. is_initd(this) ) return
2571
this%D%refs_ = this%D%refs_ - 1
2572
if ( 0 == this%D%refs_ ) then
2574
deallocate(this%D, stat=error)
2575
call set_error(this, error)
2578
end subroutine common_delete_
2579
elemental subroutine common_nullify_(this)
2580
type(LL_dArray1D), intent(inout) :: this
2581
if (.not. is_initd(this) ) return
2583
end subroutine common_nullify_
2584
subroutine common_assign_(lhs, rhs)
2585
type(LL_dArray1D), intent(inout) :: lhs
2586
type(LL_dArray1D), intent(in) :: rhs
2588
if ( .not. is_initd(rhs) ) return
2590
lhs%D%refs_ = rhs%D%refs_ + 1
2591
end subroutine common_assign_
2592
elemental function common_references_(this) result(refs)
2593
type(LL_dArray1D), intent(in) :: this
2595
if ( is_initd(this) ) then
2600
end function common_references_
2601
elemental function common_error_(this) result(error)
2602
type(LL_dArray1D), intent(in) :: this
2604
if ( is_initd(this) ) then
2609
end function common_error_
2610
elemental subroutine common_set_error_is_(this, error)
2611
type(LL_dArray1D), intent(inout) :: this
2612
integer(is_), intent(in) :: error
2614
end subroutine common_set_error_is_
2615
elemental subroutine common_set_error_ii_(this, error)
2616
type(LL_dArray1D), intent(inout) :: this
2617
integer(ii_), intent(in) :: error
2619
end subroutine common_set_error_ii_
2620
elemental subroutine common_set_error_il_(this, error)
2621
type(LL_dArray1D), intent(inout) :: this
2622
integer(il_), intent(in) :: error
2624
end subroutine common_set_error_il_
2625
elemental function common_id_(this) result(str)
2626
type(LL_dArray1D), intent(in) :: this
2627
character(len=BUD_ID_LEn) :: str
2629
end function common_id_
2630
subroutine common_tag_object_(this)
2631
type(LL_dArray1D), intent(inout) :: this
2632
end subroutine common_tag_object_
2633
subroutine delete_(this)
2634
type(LL_dArray1D), intent(inout) :: this
2635
type(LL_dArray1D_LList), pointer :: head, tmp
2636
if ( associated(this%D%head) .and. .not. &
2637
associated(this%D%ll) ) then
2638
nullify(this%D%head)
2643
if ( associated(head) ) then
2644
do while ( associated(head%prev) )
2645
if ( associated(head%prev, this%D%ll) ) exit
2648
if ( associated(head%prev, this%D%ll) ) then
2653
do while ( associated(head) )
2654
if ( associated(head%next, this%D%ll) ) exit
2661
if ( associated(this%D%ll) ) then
2662
call delete(this%D%ll%D)
2663
deallocate(this%D%ll)
2666
nullify(this%D%head)
2667
end subroutine delete_
2668
subroutine new_(this)
2669
type(LL_dArray1D), intent(inout) :: this
2670
call initialize(this)
2672
subroutine new_data_(this, D)
2673
type(LL_dArray1D), intent(inout) :: this
2674
type(dArray1D), intent(in) :: D
2677
this%D%head => this%D%ll
2679
end subroutine new_data_
2680
subroutine get_ll_headp(this, head)
2681
type(LL_dArray1D), intent(in) :: this
2682
type(LL_dArray1D_LList), pointer :: head
2683
if ( .not. is_initd(this) ) then
2688
do while ( associated(head%prev) )
2690
if ( associated(head, this%D%head) ) exit
2692
end subroutine get_ll_headp
2693
subroutine get_ll_tailp(this, tail)
2694
type(LL_dArray1D), intent(in) :: this
2695
type(LL_dArray1D_LList), pointer :: tail
2696
if ( .not. is_initd(this) ) then
2701
do while ( associated(tail%next) )
2703
if ( associated(tail, this%D%head) ) exit
2705
end subroutine get_ll_tailp
2706
subroutine get_ll_idxp(this, node, index)
2707
type(LL_dArray1D), intent(in), target :: this
2708
type(LL_dArray1D_LList), pointer :: node
2709
integer, intent(in), optional :: index
2712
if ( .not. is_initd(this) ) return
2714
if ( present(index) ) lindex = index
2716
do while ( lindex < 0 .and. associated(node%prev) )
2720
do while ( lindex > 0 .and. associated(node%next) )
2724
if ( lindex /= 0 ) then
2728
end subroutine get_ll_idxp
2729
subroutine append_node(ll)
2730
type(LL_dArray1D_LList), pointer :: ll
2731
type(LL_dArray1D_LList), pointer :: tmp => null()
2732
if ( .not. associated(ll) ) return
2736
if ( associated(ll%next) ) then
2741
end subroutine append_node
2742
function size_llist_(this) result (nnodes)
2743
type(LL_dArray1D), intent(in), target :: this
2745
type(LL_dArray1D_LList), pointer :: head, tmp
2747
if ( .not. is_initd(this) ) return
2748
call get_ll_headp(this, head)
2750
do while ( associated(tmp) )
2753
if ( associated(tmp, head) ) exit
2755
end function size_llist_
2756
subroutine add_node_(this)
2757
type(LL_dArray1D), intent(inout) :: this
2758
type(LL_dArray1D_LList), pointer :: tail
2759
if ( .not. is_initd(this) ) then
2762
this%D%head => this%D%ll
2765
call get_ll_tailp(this, tail)
2766
call append_node(tail)
2767
end subroutine add_node_
2768
subroutine add_node_data_(this, D)
2769
type(LL_dArray1D), intent(inout) :: this
2770
type(dArray1D), intent(in) :: D
2771
type(LL_dArray1D_LList), pointer :: tail
2772
call get_ll_tailp(this, tail)
2773
if ( .not. associated(tail) ) then
2777
call append_node(tail)
2779
end subroutine add_node_data_
2780
subroutine set_data_(this, D)
2781
type(LL_dArray1D), intent(inout) :: this
2782
type(dArray1D), intent(in) :: D
2783
if ( is_initd(this) ) then
2786
end subroutine set_data_
2787
subroutine set_data_idx_(this, D, index)
2788
type(LL_dArray1D), intent(inout) :: this
2789
type(dArray1D), intent(in) :: D
2790
integer, intent(in) :: index
2791
type(LL_dArray1D_LList), pointer :: node
2792
call get_ll_idxp(this, node, index)
2793
if ( .not. associated(node) ) return
2795
end subroutine set_data_idx_
2796
subroutine set_head_idx_(this, index)
2797
type(LL_dArray1D), intent(inout) :: this
2798
integer, intent(in) :: index
2799
type(LL_dArray1D_LList), pointer :: node
2800
call get_ll_idxp(this, node, index)
2801
if ( .not. associated(node) ) return
2803
end subroutine set_head_idx_
2804
subroutine get_node_data_idx_(this, D, index)
2805
type(LL_dArray1D), intent(in), target :: this
2806
type(dArray1D), intent(inout) :: D
2807
integer, intent(in), optional :: index
2808
type(LL_dArray1D_LList), pointer :: node
2810
if ( .not. is_initd(this) ) return
2811
call get_ll_idxp(this, node, index)
2812
if ( associated(node) ) D = node%D
2813
end subroutine get_node_data_idx_
2814
function itt_step_(this, itt) result(itterated)
2815
type(LL_dArray1D), intent(in) :: this
2816
type(LL_dArray1D), intent(inout) :: itt
2817
logical :: itterated
2819
if ( .not. is_initd(this) ) then
2823
if ( .not. is_initd(itt) ) then
2825
itt%D%head => this%D%head
2826
itterated = associated(itt%D%head)
2828
itt%D%head => itt%D%head%next
2829
itterated = associated(itt%D%head)
2830
if ( itterated ) then
2831
itterated = .not. associated(itt%D%head, this%D%head)
2834
if ( .not. itterated ) then
2837
end function itt_step_
2838
function itt_step_i_(this, itt, i) result(itterated)
2839
type(LL_dArray1D), intent(in) :: this
2840
type(LL_dArray1D), intent(inout) :: itt
2841
integer, intent(in) :: i
2842
logical :: itterated
2845
if ( .not. is_initd(this) ) then
2850
if ( .not. is_initd(itt) ) then
2852
itt%D%head => this%D%head
2853
itterated = associated(itt%D%head)
2854
else if ( i > 0 ) then
2855
do while ( is /= i )
2857
itt%D%head => itt%D%head%next
2858
itterated = associated(itt%D%head)
2859
if ( itterated ) then
2860
itterated = .not. associated(itt%D%head, this%D%head)
2862
if ( .not. itterated ) exit
2864
else if ( i < 0 ) then
2865
do while ( is /= i )
2867
itt%D%head => itt%D%head%prev
2868
itterated = associated(itt%D%head)
2869
if ( itterated ) then
2870
itterated = .not. associated(itt%D%head, this%D%head)
2872
if ( .not. itterated ) exit
2875
if ( .not. itterated ) then
2879
end function itt_step_i_
2880
subroutine remove_node_(this, index)
2881
type(LL_dArray1D), intent(inout), target :: this
2882
integer, intent(in) :: index
2883
type(LL_dArray1D_LList), pointer :: node, pnode, nnode
2884
if ( .not. is_initd(this) ) return
2885
call get_ll_idxp(this, node, index)
2886
if ( .not. associated(node) ) return
2891
if ( associated(pnode) ) then
2894
if ( associated(nnode) ) then
2899
end subroutine remove_node_
2900
subroutine remove_node_data_(this, index)
2901
type(LL_dArray1D), intent(inout), target :: this
2902
integer, intent(in), optional :: index
2903
type(LL_dArray1D_LList), pointer :: node
2904
if ( .not. is_initd(this) ) return
2905
call get_ll_idxp(this, node, index)
2906
if ( .not. associated(node) ) return
2908
end subroutine remove_node_data_
2909
subroutine copy_(from, to)
2910
type(LL_dArray1D), intent(inout) :: from, to
2911
type(LL_dArray1D_LList), pointer :: t, f
2913
if ( .not. is_initd(from) ) return
2918
do while ( associated(f%next) )
2924
if ( associated(t, to%D%head) ) return
2928
do while ( associated(f%prev) )
2935
end subroutine copy_
2936
subroutine print_(this, info, indent)
2937
type(LL_dArray1D), intent(in), target :: this
2938
character(len=*), intent(in), optional :: info
2939
integer, intent(in), optional :: indent
2941
type(LL_dArray1D_LList), pointer :: node
2942
character(len=32) :: fmt
2943
character(len=256) :: name
2944
name = "LL_dArray1D"
2945
if ( present(info) ) name = info
2947
if ( present(indent) ) lindent = indent
2948
write(fmt, '(a,i0,a)') '(t',lindent,',3a)'
2949
if ( .not. is_initd(this) ) then
2950
write(*,fmt) "<", trim(name), " not initialized>"
2953
write(fmt, '(a,i0,a)') '(t',lindent,',3a,i0,a)'
2954
write(*,fmt) "<<", trim(name), " llist, nodes=",nodes(this),">"
2955
lindent = lindent + 2 ! step indentation
2956
call get_ll_headp(this, node)
2957
do while ( associated(node) )
2958
if ( associated(node, this%D%head) ) then
2959
write(fmt, '(a,i0,a)') '(t',lindent,',a)'
2960
call print(node%D, indent = lindent+2)
2962
call print(node%D, indent = lindent)
2966
lindent = lindent - 2 ! go back to requested indentation
2967
write(fmt, '(a,i0,a)') '(t',lindent,',a,i0,a)'
2968
write(*,fmt) " <llist-refs: ", references(this), ">>"
2969
end subroutine print_
2971
module bud_LL_cArray1D
2975
integer, parameter :: rr_ = selected_real_kind(p=6) ! single (real*4)
2976
integer, parameter :: rd_ = selected_real_kind(p=15) ! double (real*8)
2977
integer, parameter :: is_ = selected_int_kind(4) ! short (integer*2)
2978
integer, parameter :: ii_ = selected_int_kind(9) ! int (integer*4)
2979
integer, parameter :: il_ = selected_int_kind(18) ! long (integer*8)
2980
integer, parameter, private :: BUD_ID_LEn = 36
2981
character(len=*), parameter, private :: &
2982
BUD_MOd = 'BUD_CC2(BUD_MOD,_)BUD_MOD_NAME'
2983
character(len=*), parameter, private :: &
2984
BUD_TYPe = "LL_cArray1D"
2986
type(LL_cArray1D_), pointer :: D => null()
2987
integer :: error_ = 0
2988
end type LL_cArray1D
2990
type(LL_cArray1D_LList), pointer :: ll => null()
2991
type(LL_cArray1D_LList), pointer :: head => null()
2992
integer :: refs_ = 0
2993
character(len=BUD_ID_LEN) :: id_ = "null_id"
2994
end type LL_cArray1D_
2995
type LL_cArray1D_LList
2996
type(LL_cArray1D_LList), pointer :: prev => null()
2997
type(LL_cArray1D_LList), pointer :: next => null()
3000
private :: LL_cArray1D_LList
3002
module procedure new_
3003
module procedure new_data_
3006
interface assignment(=)
3007
module procedure set_data_
3010
module procedure size_llist_
3014
module procedure size_llist_
3018
module procedure set_data_
3019
module procedure set_data_idx_
3023
module procedure add_node_
3024
module procedure add_node_data_
3028
module procedure get_node_data_idx_
3032
module procedure get_node_data_idx_
3036
module procedure set_head_idx_
3040
module procedure itt_step_
3041
module procedure itt_step_i_
3044
interface remove_node
3045
module procedure remove_node_
3047
public :: remove_node
3048
interface remove_node_data
3049
module procedure remove_node_data_
3051
public :: remove_node_data
3053
module procedure copy_
3056
public :: LL_cArray1D
3057
private :: LL_cArray1D_
3058
interface assignment(=)
3059
module procedure common_assign_
3061
public :: assignment(=)
3062
private :: common_assign_
3063
interface initialize
3064
module procedure common_initialize_
3066
public :: initialize
3067
private :: common_initialize_
3068
interface is_initialized
3069
module procedure common_is_initialized_
3071
public :: is_initialized
3072
private :: common_is_initialized_
3073
interface initialized
3074
module procedure common_is_initialized_
3076
public :: initialized
3078
module procedure common_is_initialized_
3082
module procedure common_is_same_
3085
private :: common_is_same_
3087
module procedure common_is_same_
3091
module procedure common_delete_
3094
private :: common_delete_
3096
module procedure common_nullify_
3099
private :: common_nullify_
3101
module procedure copy_
3104
private :: common_copy_
3106
module procedure print_
3109
interface references
3110
module procedure common_references_
3112
public :: references
3113
private :: common_references_
3115
module procedure common_references_
3119
module procedure common_set_error_is_
3120
module procedure common_set_error_ii_
3121
module procedure common_set_error_il_
3124
private :: common_set_error_is_
3125
private :: common_set_error_ii_
3126
private :: common_set_error_il_
3128
module procedure common_error_
3131
private :: common_error_
3133
subroutine common_copy_(from, to)
3134
type(LL_cArray1D), intent(in) :: from
3135
type(LL_cArray1D), intent(inout) :: to
3136
call set_error(to, error(from))
3137
end subroutine common_copy_
3138
subroutine common_initialize_(this)
3139
type(LL_cArray1D), intent(inout) :: this
3142
allocate(this%D, stat=error)
3143
call set_error(this, error)
3144
if ( error /= 0 ) return
3146
call common_tag_object_(this)
3147
end subroutine common_initialize_
3148
pure function common_is_initialized_(this) result(init)
3149
type(LL_cArray1D), intent(in) :: this
3151
init = associated(this%D)
3152
end function common_is_initialized_
3153
elemental function common_is_same_(lhs, rhs) result(same)
3154
type(LL_cArray1D), intent(in) :: lhs, rhs
3156
same = is_initd(lhs) .and. is_initd(rhs)
3157
if ( .not. same ) return
3158
same = associated(lhs%D, target=rhs%D)
3159
end function common_is_same_
3160
subroutine common_delete_(this)
3161
type(LL_cArray1D), intent(inout) :: this
3163
call set_error(this, 0)
3164
if (.not. is_initd(this) ) return
3165
this%D%refs_ = this%D%refs_ - 1
3166
if ( 0 == this%D%refs_ ) then
3168
deallocate(this%D, stat=error)
3169
call set_error(this, error)
3172
end subroutine common_delete_
3173
elemental subroutine common_nullify_(this)
3174
type(LL_cArray1D), intent(inout) :: this
3175
if (.not. is_initd(this) ) return
3177
end subroutine common_nullify_
3178
subroutine common_assign_(lhs, rhs)
3179
type(LL_cArray1D), intent(inout) :: lhs
3180
type(LL_cArray1D), intent(in) :: rhs
3182
if ( .not. is_initd(rhs) ) return
3184
lhs%D%refs_ = rhs%D%refs_ + 1
3185
end subroutine common_assign_
3186
elemental function common_references_(this) result(refs)
3187
type(LL_cArray1D), intent(in) :: this
3189
if ( is_initd(this) ) then
3194
end function common_references_
3195
elemental function common_error_(this) result(error)
3196
type(LL_cArray1D), intent(in) :: this
3198
if ( is_initd(this) ) then
3203
end function common_error_
3204
elemental subroutine common_set_error_is_(this, error)
3205
type(LL_cArray1D), intent(inout) :: this
3206
integer(is_), intent(in) :: error
3208
end subroutine common_set_error_is_
3209
elemental subroutine common_set_error_ii_(this, error)
3210
type(LL_cArray1D), intent(inout) :: this
3211
integer(ii_), intent(in) :: error
3213
end subroutine common_set_error_ii_
3214
elemental subroutine common_set_error_il_(this, error)
3215
type(LL_cArray1D), intent(inout) :: this
3216
integer(il_), intent(in) :: error
3218
end subroutine common_set_error_il_
3219
elemental function common_id_(this) result(str)
3220
type(LL_cArray1D), intent(in) :: this
3221
character(len=BUD_ID_LEn) :: str
3223
end function common_id_
3224
subroutine common_tag_object_(this)
3225
type(LL_cArray1D), intent(inout) :: this
3226
end subroutine common_tag_object_
3227
subroutine delete_(this)
3228
type(LL_cArray1D), intent(inout) :: this
3229
type(LL_cArray1D_LList), pointer :: head, tmp
3230
if ( associated(this%D%head) .and. .not. &
3231
associated(this%D%ll) ) then
3232
nullify(this%D%head)
3237
if ( associated(head) ) then
3238
do while ( associated(head%prev) )
3239
if ( associated(head%prev, this%D%ll) ) exit
3242
if ( associated(head%prev, this%D%ll) ) then
3247
do while ( associated(head) )
3248
if ( associated(head%next, this%D%ll) ) exit
3255
if ( associated(this%D%ll) ) then
3256
call delete(this%D%ll%D)
3257
deallocate(this%D%ll)
3260
nullify(this%D%head)
3261
end subroutine delete_
3262
subroutine new_(this)
3263
type(LL_cArray1D), intent(inout) :: this
3264
call initialize(this)
3266
subroutine new_data_(this, D)
3267
type(LL_cArray1D), intent(inout) :: this
3268
type(cArray1D), intent(in) :: D
3271
this%D%head => this%D%ll
3273
end subroutine new_data_
3274
subroutine get_ll_headp(this, head)
3275
type(LL_cArray1D), intent(in) :: this
3276
type(LL_cArray1D_LList), pointer :: head
3277
if ( .not. is_initd(this) ) then
3282
do while ( associated(head%prev) )
3284
if ( associated(head, this%D%head) ) exit
3286
end subroutine get_ll_headp
3287
subroutine get_ll_tailp(this, tail)
3288
type(LL_cArray1D), intent(in) :: this
3289
type(LL_cArray1D_LList), pointer :: tail
3290
if ( .not. is_initd(this) ) then
3295
do while ( associated(tail%next) )
3297
if ( associated(tail, this%D%head) ) exit
3299
end subroutine get_ll_tailp
3300
subroutine get_ll_idxp(this, node, index)
3301
type(LL_cArray1D), intent(in), target :: this
3302
type(LL_cArray1D_LList), pointer :: node
3303
integer, intent(in), optional :: index
3306
if ( .not. is_initd(this) ) return
3308
if ( present(index) ) lindex = index
3310
do while ( lindex < 0 .and. associated(node%prev) )
3314
do while ( lindex > 0 .and. associated(node%next) )
3318
if ( lindex /= 0 ) then
3322
end subroutine get_ll_idxp
3323
subroutine append_node(ll)
3324
type(LL_cArray1D_LList), pointer :: ll
3325
type(LL_cArray1D_LList), pointer :: tmp => null()
3326
if ( .not. associated(ll) ) return
3330
if ( associated(ll%next) ) then
3335
end subroutine append_node
3336
function size_llist_(this) result (nnodes)
3337
type(LL_cArray1D), intent(in), target :: this
3339
type(LL_cArray1D_LList), pointer :: head, tmp
3341
if ( .not. is_initd(this) ) return
3342
call get_ll_headp(this, head)
3344
do while ( associated(tmp) )
3347
if ( associated(tmp, head) ) exit
3349
end function size_llist_
3350
subroutine add_node_(this)
3351
type(LL_cArray1D), intent(inout) :: this
3352
type(LL_cArray1D_LList), pointer :: tail
3353
if ( .not. is_initd(this) ) then
3356
this%D%head => this%D%ll
3359
call get_ll_tailp(this, tail)
3360
call append_node(tail)
3361
end subroutine add_node_
3362
subroutine add_node_data_(this, D)
3363
type(LL_cArray1D), intent(inout) :: this
3364
type(cArray1D), intent(in) :: D
3365
type(LL_cArray1D_LList), pointer :: tail
3366
call get_ll_tailp(this, tail)
3367
if ( .not. associated(tail) ) then
3371
call append_node(tail)
3373
end subroutine add_node_data_
3374
subroutine set_data_(this, D)
3375
type(LL_cArray1D), intent(inout) :: this
3376
type(cArray1D), intent(in) :: D
3377
if ( is_initd(this) ) then
3380
end subroutine set_data_
3381
subroutine set_data_idx_(this, D, index)
3382
type(LL_cArray1D), intent(inout) :: this
3383
type(cArray1D), intent(in) :: D
3384
integer, intent(in) :: index
3385
type(LL_cArray1D_LList), pointer :: node
3386
call get_ll_idxp(this, node, index)
3387
if ( .not. associated(node) ) return
3389
end subroutine set_data_idx_
3390
subroutine set_head_idx_(this, index)
3391
type(LL_cArray1D), intent(inout) :: this
3392
integer, intent(in) :: index
3393
type(LL_cArray1D_LList), pointer :: node
3394
call get_ll_idxp(this, node, index)
3395
if ( .not. associated(node) ) return
3397
end subroutine set_head_idx_
3398
subroutine get_node_data_idx_(this, D, index)
3399
type(LL_cArray1D), intent(in), target :: this
3400
type(cArray1D), intent(inout) :: D
3401
integer, intent(in), optional :: index
3402
type(LL_cArray1D_LList), pointer :: node
3404
if ( .not. is_initd(this) ) return
3405
call get_ll_idxp(this, node, index)
3406
if ( associated(node) ) D = node%D
3407
end subroutine get_node_data_idx_
3408
function itt_step_(this, itt) result(itterated)
3409
type(LL_cArray1D), intent(in) :: this
3410
type(LL_cArray1D), intent(inout) :: itt
3411
logical :: itterated
3413
if ( .not. is_initd(this) ) then
3417
if ( .not. is_initd(itt) ) then
3419
itt%D%head => this%D%head
3420
itterated = associated(itt%D%head)
3422
itt%D%head => itt%D%head%next
3423
itterated = associated(itt%D%head)
3424
if ( itterated ) then
3425
itterated = .not. associated(itt%D%head, this%D%head)
3428
if ( .not. itterated ) then
3431
end function itt_step_
3432
function itt_step_i_(this, itt, i) result(itterated)
3433
type(LL_cArray1D), intent(in) :: this
3434
type(LL_cArray1D), intent(inout) :: itt
3435
integer, intent(in) :: i
3436
logical :: itterated
3439
if ( .not. is_initd(this) ) then
3444
if ( .not. is_initd(itt) ) then
3446
itt%D%head => this%D%head
3447
itterated = associated(itt%D%head)
3448
else if ( i > 0 ) then
3449
do while ( is /= i )
3451
itt%D%head => itt%D%head%next
3452
itterated = associated(itt%D%head)
3453
if ( itterated ) then
3454
itterated = .not. associated(itt%D%head, this%D%head)
3456
if ( .not. itterated ) exit
3458
else if ( i < 0 ) then
3459
do while ( is /= i )
3461
itt%D%head => itt%D%head%prev
3462
itterated = associated(itt%D%head)
3463
if ( itterated ) then
3464
itterated = .not. associated(itt%D%head, this%D%head)
3466
if ( .not. itterated ) exit
3469
if ( .not. itterated ) then
3473
end function itt_step_i_
3474
subroutine remove_node_(this, index)
3475
type(LL_cArray1D), intent(inout), target :: this
3476
integer, intent(in) :: index
3477
type(LL_cArray1D_LList), pointer :: node, pnode, nnode
3478
if ( .not. is_initd(this) ) return
3479
call get_ll_idxp(this, node, index)
3480
if ( .not. associated(node) ) return
3485
if ( associated(pnode) ) then
3488
if ( associated(nnode) ) then
3493
end subroutine remove_node_
3494
subroutine remove_node_data_(this, index)
3495
type(LL_cArray1D), intent(inout), target :: this
3496
integer, intent(in), optional :: index
3497
type(LL_cArray1D_LList), pointer :: node
3498
if ( .not. is_initd(this) ) return
3499
call get_ll_idxp(this, node, index)
3500
if ( .not. associated(node) ) return
3502
end subroutine remove_node_data_
3503
subroutine copy_(from, to)
3504
type(LL_cArray1D), intent(inout) :: from, to
3505
type(LL_cArray1D_LList), pointer :: t, f
3507
if ( .not. is_initd(from) ) return
3512
do while ( associated(f%next) )
3518
if ( associated(t, to%D%head) ) return
3522
do while ( associated(f%prev) )
3529
end subroutine copy_
3530
subroutine print_(this, info, indent)
3531
type(LL_cArray1D), intent(in), target :: this
3532
character(len=*), intent(in), optional :: info
3533
integer, intent(in), optional :: indent
3535
type(LL_cArray1D_LList), pointer :: node
3536
character(len=32) :: fmt
3537
character(len=256) :: name
3538
name = "LL_cArray1D"
3539
if ( present(info) ) name = info
3541
if ( present(indent) ) lindent = indent
3542
write(fmt, '(a,i0,a)') '(t',lindent,',3a)'
3543
if ( .not. is_initd(this) ) then
3544
write(*,fmt) "<", trim(name), " not initialized>"
3547
write(fmt, '(a,i0,a)') '(t',lindent,',3a,i0,a)'
3548
write(*,fmt) "<<", trim(name), " llist, nodes=",nodes(this),">"
3549
lindent = lindent + 2 ! step indentation
3550
call get_ll_headp(this, node)
3551
do while ( associated(node) )
3552
if ( associated(node, this%D%head) ) then
3553
write(fmt, '(a,i0,a)') '(t',lindent,',a)'
3554
call print(node%D, indent = lindent+2)
3556
call print(node%D, indent = lindent)
3560
lindent = lindent - 2 ! go back to requested indentation
3561
write(fmt, '(a,i0,a)') '(t',lindent,',a,i0,a)'
3562
write(*,fmt) " <llist-refs: ", references(this), ">>"
3563
end subroutine print_
3565
module bud_LL_zArray1D
3569
integer, parameter :: rr_ = selected_real_kind(p=6) ! single (real*4)
3570
integer, parameter :: rd_ = selected_real_kind(p=15) ! double (real*8)
3571
integer, parameter :: is_ = selected_int_kind(4) ! short (integer*2)
3572
integer, parameter :: ii_ = selected_int_kind(9) ! int (integer*4)
3573
integer, parameter :: il_ = selected_int_kind(18) ! long (integer*8)
3574
integer, parameter, private :: BUD_ID_LEn = 36
3575
character(len=*), parameter, private :: &
3576
BUD_MOd = 'BUD_CC2(BUD_MOD,_)BUD_MOD_NAME'
3577
character(len=*), parameter, private :: &
3578
BUD_TYPe = "LL_zArray1D"
3580
type(LL_zArray1D_), pointer :: D => null()
3581
integer :: error_ = 0
3582
end type LL_zArray1D
3584
type(LL_zArray1D_LList), pointer :: ll => null()
3585
type(LL_zArray1D_LList), pointer :: head => null()
3586
integer :: refs_ = 0
3587
character(len=BUD_ID_LEN) :: id_ = "null_id"
3588
end type LL_zArray1D_
3589
type LL_zArray1D_LList
3590
type(LL_zArray1D_LList), pointer :: prev => null()
3591
type(LL_zArray1D_LList), pointer :: next => null()
3594
private :: LL_zArray1D_LList
3596
module procedure new_
3597
module procedure new_data_
3600
interface assignment(=)
3601
module procedure set_data_
3604
module procedure size_llist_
3608
module procedure size_llist_
3612
module procedure set_data_
3613
module procedure set_data_idx_
3617
module procedure add_node_
3618
module procedure add_node_data_
3622
module procedure get_node_data_idx_
3626
module procedure get_node_data_idx_
3630
module procedure set_head_idx_
3634
module procedure itt_step_
3635
module procedure itt_step_i_
3638
interface remove_node
3639
module procedure remove_node_
3641
public :: remove_node
3642
interface remove_node_data
3643
module procedure remove_node_data_
3645
public :: remove_node_data
3647
module procedure copy_
3650
public :: LL_zArray1D
3651
private :: LL_zArray1D_
3652
interface assignment(=)
3653
module procedure common_assign_
3655
public :: assignment(=)
3656
private :: common_assign_
3657
interface initialize
3658
module procedure common_initialize_
3660
public :: initialize
3661
private :: common_initialize_
3662
interface is_initialized
3663
module procedure common_is_initialized_
3665
public :: is_initialized
3666
private :: common_is_initialized_
3667
interface initialized
3668
module procedure common_is_initialized_
3670
public :: initialized
3672
module procedure common_is_initialized_
3676
module procedure common_is_same_
3679
private :: common_is_same_
3681
module procedure common_is_same_
3685
module procedure common_delete_
3688
private :: common_delete_
3690
module procedure common_nullify_
3693
private :: common_nullify_
3695
module procedure copy_
3698
private :: common_copy_
3700
module procedure print_
3703
interface references
3704
module procedure common_references_
3706
public :: references
3707
private :: common_references_
3709
module procedure common_references_
3713
module procedure common_set_error_is_
3714
module procedure common_set_error_ii_
3715
module procedure common_set_error_il_
3718
private :: common_set_error_is_
3719
private :: common_set_error_ii_
3720
private :: common_set_error_il_
3722
module procedure common_error_
3725
private :: common_error_
3727
subroutine common_copy_(from, to)
3728
type(LL_zArray1D), intent(in) :: from
3729
type(LL_zArray1D), intent(inout) :: to
3730
call set_error(to, error(from))
3731
end subroutine common_copy_
3732
subroutine common_initialize_(this)
3733
type(LL_zArray1D), intent(inout) :: this
3736
allocate(this%D, stat=error)
3737
call set_error(this, error)
3738
if ( error /= 0 ) return
3740
call common_tag_object_(this)
3741
end subroutine common_initialize_
3742
pure function common_is_initialized_(this) result(init)
3743
type(LL_zArray1D), intent(in) :: this
3745
init = associated(this%D)
3746
end function common_is_initialized_
3747
elemental function common_is_same_(lhs, rhs) result(same)
3748
type(LL_zArray1D), intent(in) :: lhs, rhs
3750
same = is_initd(lhs) .and. is_initd(rhs)
3751
if ( .not. same ) return
3752
same = associated(lhs%D, target=rhs%D)
3753
end function common_is_same_
3754
subroutine common_delete_(this)
3755
type(LL_zArray1D), intent(inout) :: this
3757
call set_error(this, 0)
3758
if (.not. is_initd(this) ) return
3759
this%D%refs_ = this%D%refs_ - 1
3760
if ( 0 == this%D%refs_ ) then
3762
deallocate(this%D, stat=error)
3763
call set_error(this, error)
3766
end subroutine common_delete_
3767
elemental subroutine common_nullify_(this)
3768
type(LL_zArray1D), intent(inout) :: this
3769
if (.not. is_initd(this) ) return
3771
end subroutine common_nullify_
3772
subroutine common_assign_(lhs, rhs)
3773
type(LL_zArray1D), intent(inout) :: lhs
3774
type(LL_zArray1D), intent(in) :: rhs
3776
if ( .not. is_initd(rhs) ) return
3778
lhs%D%refs_ = rhs%D%refs_ + 1
3779
end subroutine common_assign_
3780
elemental function common_references_(this) result(refs)
3781
type(LL_zArray1D), intent(in) :: this
3783
if ( is_initd(this) ) then
3788
end function common_references_
3789
elemental function common_error_(this) result(error)
3790
type(LL_zArray1D), intent(in) :: this
3792
if ( is_initd(this) ) then
3797
end function common_error_
3798
elemental subroutine common_set_error_is_(this, error)
3799
type(LL_zArray1D), intent(inout) :: this
3800
integer(is_), intent(in) :: error
3802
end subroutine common_set_error_is_
3803
elemental subroutine common_set_error_ii_(this, error)
3804
type(LL_zArray1D), intent(inout) :: this
3805
integer(ii_), intent(in) :: error
3807
end subroutine common_set_error_ii_
3808
elemental subroutine common_set_error_il_(this, error)
3809
type(LL_zArray1D), intent(inout) :: this
3810
integer(il_), intent(in) :: error
3812
end subroutine common_set_error_il_
3813
elemental function common_id_(this) result(str)
3814
type(LL_zArray1D), intent(in) :: this
3815
character(len=BUD_ID_LEn) :: str
3817
end function common_id_
3818
subroutine common_tag_object_(this)
3819
type(LL_zArray1D), intent(inout) :: this
3820
end subroutine common_tag_object_
3821
subroutine delete_(this)
3822
type(LL_zArray1D), intent(inout) :: this
3823
type(LL_zArray1D_LList), pointer :: head, tmp
3824
if ( associated(this%D%head) .and. .not. &
3825
associated(this%D%ll) ) then
3826
nullify(this%D%head)
3831
if ( associated(head) ) then
3832
do while ( associated(head%prev) )
3833
if ( associated(head%prev, this%D%ll) ) exit
3836
if ( associated(head%prev, this%D%ll) ) then
3841
do while ( associated(head) )
3842
if ( associated(head%next, this%D%ll) ) exit
3849
if ( associated(this%D%ll) ) then
3850
call delete(this%D%ll%D)
3851
deallocate(this%D%ll)
3854
nullify(this%D%head)
3855
end subroutine delete_
3856
subroutine new_(this)
3857
type(LL_zArray1D), intent(inout) :: this
3858
call initialize(this)
3860
subroutine new_data_(this, D)
3861
type(LL_zArray1D), intent(inout) :: this
3862
type(zArray1D), intent(in) :: D
3865
this%D%head => this%D%ll
3867
end subroutine new_data_
3868
subroutine get_ll_headp(this, head)
3869
type(LL_zArray1D), intent(in) :: this
3870
type(LL_zArray1D_LList), pointer :: head
3871
if ( .not. is_initd(this) ) then
3876
do while ( associated(head%prev) )
3878
if ( associated(head, this%D%head) ) exit
3880
end subroutine get_ll_headp
3881
subroutine get_ll_tailp(this, tail)
3882
type(LL_zArray1D), intent(in) :: this
3883
type(LL_zArray1D_LList), pointer :: tail
3884
if ( .not. is_initd(this) ) then
3889
do while ( associated(tail%next) )
3891
if ( associated(tail, this%D%head) ) exit
3893
end subroutine get_ll_tailp
3894
subroutine get_ll_idxp(this, node, index)
3895
type(LL_zArray1D), intent(in), target :: this
3896
type(LL_zArray1D_LList), pointer :: node
3897
integer, intent(in), optional :: index
3900
if ( .not. is_initd(this) ) return
3902
if ( present(index) ) lindex = index
3904
do while ( lindex < 0 .and. associated(node%prev) )
3908
do while ( lindex > 0 .and. associated(node%next) )
3912
if ( lindex /= 0 ) then
3916
end subroutine get_ll_idxp
3917
subroutine append_node(ll)
3918
type(LL_zArray1D_LList), pointer :: ll
3919
type(LL_zArray1D_LList), pointer :: tmp => null()
3920
if ( .not. associated(ll) ) return
3924
if ( associated(ll%next) ) then
3929
end subroutine append_node
3930
function size_llist_(this) result (nnodes)
3931
type(LL_zArray1D), intent(in), target :: this
3933
type(LL_zArray1D_LList), pointer :: head, tmp
3935
if ( .not. is_initd(this) ) return
3936
call get_ll_headp(this, head)
3938
do while ( associated(tmp) )
3941
if ( associated(tmp, head) ) exit
3943
end function size_llist_
3944
subroutine add_node_(this)
3945
type(LL_zArray1D), intent(inout) :: this
3946
type(LL_zArray1D_LList), pointer :: tail
3947
if ( .not. is_initd(this) ) then
3950
this%D%head => this%D%ll
3953
call get_ll_tailp(this, tail)
3954
call append_node(tail)
3955
end subroutine add_node_
3956
subroutine add_node_data_(this, D)
3957
type(LL_zArray1D), intent(inout) :: this
3958
type(zArray1D), intent(in) :: D
3959
type(LL_zArray1D_LList), pointer :: tail
3960
call get_ll_tailp(this, tail)
3961
if ( .not. associated(tail) ) then
3965
call append_node(tail)
3967
end subroutine add_node_data_
3968
subroutine set_data_(this, D)
3969
type(LL_zArray1D), intent(inout) :: this
3970
type(zArray1D), intent(in) :: D
3971
if ( is_initd(this) ) then
3974
end subroutine set_data_
3975
subroutine set_data_idx_(this, D, index)
3976
type(LL_zArray1D), intent(inout) :: this
3977
type(zArray1D), intent(in) :: D
3978
integer, intent(in) :: index
3979
type(LL_zArray1D_LList), pointer :: node
3980
call get_ll_idxp(this, node, index)
3981
if ( .not. associated(node) ) return
3983
end subroutine set_data_idx_
3984
subroutine set_head_idx_(this, index)
3985
type(LL_zArray1D), intent(inout) :: this
3986
integer, intent(in) :: index
3987
type(LL_zArray1D_LList), pointer :: node
3988
call get_ll_idxp(this, node, index)
3989
if ( .not. associated(node) ) return
3991
end subroutine set_head_idx_
3992
subroutine get_node_data_idx_(this, D, index)
3993
type(LL_zArray1D), intent(in), target :: this
3994
type(zArray1D), intent(inout) :: D
3995
integer, intent(in), optional :: index
3996
type(LL_zArray1D_LList), pointer :: node
3998
if ( .not. is_initd(this) ) return
3999
call get_ll_idxp(this, node, index)
4000
if ( associated(node) ) D = node%D
4001
end subroutine get_node_data_idx_
4002
function itt_step_(this, itt) result(itterated)
4003
type(LL_zArray1D), intent(in) :: this
4004
type(LL_zArray1D), intent(inout) :: itt
4005
logical :: itterated
4007
if ( .not. is_initd(this) ) then
4011
if ( .not. is_initd(itt) ) then
4013
itt%D%head => this%D%head
4014
itterated = associated(itt%D%head)
4016
itt%D%head => itt%D%head%next
4017
itterated = associated(itt%D%head)
4018
if ( itterated ) then
4019
itterated = .not. associated(itt%D%head, this%D%head)
4022
if ( .not. itterated ) then
4025
end function itt_step_
4026
function itt_step_i_(this, itt, i) result(itterated)
4027
type(LL_zArray1D), intent(in) :: this
4028
type(LL_zArray1D), intent(inout) :: itt
4029
integer, intent(in) :: i
4030
logical :: itterated
4033
if ( .not. is_initd(this) ) then
4038
if ( .not. is_initd(itt) ) then
4040
itt%D%head => this%D%head
4041
itterated = associated(itt%D%head)
4042
else if ( i > 0 ) then
4043
do while ( is /= i )
4045
itt%D%head => itt%D%head%next
4046
itterated = associated(itt%D%head)
4047
if ( itterated ) then
4048
itterated = .not. associated(itt%D%head, this%D%head)
4050
if ( .not. itterated ) exit
4052
else if ( i < 0 ) then
4053
do while ( is /= i )
4055
itt%D%head => itt%D%head%prev
4056
itterated = associated(itt%D%head)
4057
if ( itterated ) then
4058
itterated = .not. associated(itt%D%head, this%D%head)
4060
if ( .not. itterated ) exit
4063
if ( .not. itterated ) then
4067
end function itt_step_i_
4068
subroutine remove_node_(this, index)
4069
type(LL_zArray1D), intent(inout), target :: this
4070
integer, intent(in) :: index
4071
type(LL_zArray1D_LList), pointer :: node, pnode, nnode
4072
if ( .not. is_initd(this) ) return
4073
call get_ll_idxp(this, node, index)
4074
if ( .not. associated(node) ) return
4079
if ( associated(pnode) ) then
4082
if ( associated(nnode) ) then
4087
end subroutine remove_node_
4088
subroutine remove_node_data_(this, index)
4089
type(LL_zArray1D), intent(inout), target :: this
4090
integer, intent(in), optional :: index
4091
type(LL_zArray1D_LList), pointer :: node
4092
if ( .not. is_initd(this) ) return
4093
call get_ll_idxp(this, node, index)
4094
if ( .not. associated(node) ) return
4096
end subroutine remove_node_data_
4097
subroutine copy_(from, to)
4098
type(LL_zArray1D), intent(inout) :: from, to
4099
type(LL_zArray1D_LList), pointer :: t, f
4101
if ( .not. is_initd(from) ) return
4106
do while ( associated(f%next) )
4112
if ( associated(t, to%D%head) ) return
4116
do while ( associated(f%prev) )
4123
end subroutine copy_
4124
subroutine print_(this, info, indent)
4125
type(LL_zArray1D), intent(in), target :: this
4126
character(len=*), intent(in), optional :: info
4127
integer, intent(in), optional :: indent
4129
type(LL_zArray1D_LList), pointer :: node
4130
character(len=32) :: fmt
4131
character(len=256) :: name
4132
name = "LL_zArray1D"
4133
if ( present(info) ) name = info
4135
if ( present(indent) ) lindent = indent
4136
write(fmt, '(a,i0,a)') '(t',lindent,',3a)'
4137
if ( .not. is_initd(this) ) then
4138
write(*,fmt) "<", trim(name), " not initialized>"
4141
write(fmt, '(a,i0,a)') '(t',lindent,',3a,i0,a)'
4142
write(*,fmt) "<<", trim(name), " llist, nodes=",nodes(this),">"
4143
lindent = lindent + 2 ! step indentation
4144
call get_ll_headp(this, node)
4145
do while ( associated(node) )
4146
if ( associated(node, this%D%head) ) then
4147
write(fmt, '(a,i0,a)') '(t',lindent,',a)'
4148
call print(node%D, indent = lindent+2)
4150
call print(node%D, indent = lindent)
4154
lindent = lindent - 2 ! go back to requested indentation
4155
write(fmt, '(a,i0,a)') '(t',lindent,',a,i0,a)'
4156
write(*,fmt) " <llist-refs: ", references(this), ">>"
4157
end subroutine print_