~nickpapior/siesta/trunk-buds-format0.92

« back to all changes in this revision

Viewing changes to Src/buds/include/bud_finitestack.inc

  • Committer: Nick Papior
  • Date: 2017-04-07 12:42:28 UTC
  • Revision ID: nickpapior@gmail.com-20170407124228-u5t08yr2p4fhzfeo
Initial commit of buds merged into siesta

Currently I have only enabled buds compilation.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
  ! @@LICENSE@@ see Copyright notice in the top-directory
 
2
 
 
3
  ! The following pre-processor variables are currently used when
 
4
  ! included:
 
5
  !  - BUD_TYPE_NAME of the type
 
6
  !  - BUD_TYPE_NAME_, internal data pointer of the type
 
7
  !  - BUD_TYPE_NAME_STR, the routine name in "string" format (for IO)
 
8
  !  - BUD_TYPE_NEW, the routine name for creating a new type
 
9
  !  - BUD_STACK_TYPE, the variable type contained in the stack
 
10
 
 
11
  ! Include the common utilities
 
12
#include "bud_utils.inc"
 
13
 
 
14
#include "bud_common_declarations.inc"
 
15
 
 
16
  !> @cond BUD_DOC_INC
 
17
 
 
18
  !> @defgroup bud-fstack Finite stack of arbitrary @bud
 
19
  !!
 
20
  !! The finite stack implementation is an extension of the regular
 
21
  !! reference counted objects.
 
22
  !!
 
23
  !! A stack is a "push-pop" sequence of @buds.
 
24
  !! A `push` of a new @bud is inserted at the top, if the stack is
 
25
  !! full the oldest entry is deleted and removed from the stack.
 
26
  !!
 
27
  !! A `pop` of a @bud removes the top entry of the stack and possibly
 
28
  !! returns the @bud.
 
29
  !!
 
30
  !! @note
 
31
  !! A type need not have _all_ these routines available if so desired.
 
32
  !! This is internally controlled and is mentioned for the relevant types.
 
33
 
 
34
  !> @endcond BUD_DOC_INC
 
35
 
 
36
  !> Finite stack with cyclic ability
 
37
  !!
 
38
  !! Container for a finite stack of a single @bud (BUD_STACK_TYPE).
 
39
  !!
 
40
  !! This data container holds 3 variables,
 
41
  !!  1. track maximum number of elements allowed in the finite stack
 
42
  !!  2. track how many elements are currently stored
 
43
  !!  3. An array of the stack of variables stored.
 
44
  type BUD_TYPE_NAME
 
45
 
 
46
    !> @cond BUD_DEVELOPER
 
47
 
 
48
    !> Stored pointer which contains the reference counting etc.
 
49
    type(BUD_TYPE_NAME_), pointer :: D => null()
 
50
 
 
51
    !> @endcond BUD_DEVELOPER
 
52
 
 
53
#   include "bud_common_type.inc"
 
54
#if BUD_FORTRAN >= 2003
 
55
 
 
56
    !> @iSee #new
 
57
    procedure, public :: new => new_
 
58
 
 
59
    !> @iSee #push
 
60
    procedure, public :: push => push_
 
61
    !> @iSee #pop
 
62
    procedure, public :: pop => pop_
 
63
    !> @iSee #retain
 
64
    procedure, public :: retain => retain_
 
65
 
 
66
    !> @iSee #element
 
67
    procedure, public :: element => get_elem_
 
68
    !> @iSee #element
 
69
    procedure, public :: get => get_elem_
 
70
 
 
71
    !> @iSee #element_p
 
72
    procedure, public :: element_p => get_elem_p_
 
73
    !> @iSee #element_p
 
74
    procedure, public :: get_p => get_elem_p_
 
75
 
 
76
    !> @iSee #size
 
77
    procedure, public :: size => size_elem_
 
78
    !> @iSee #size_max
 
79
    procedure, public :: size_max => size_max_elem_
 
80
 
 
81
#endif
 
82
  end type BUD_TYPE_NAME
 
83
 
 
84
 
 
85
  !> @cond BUD_DEVELOPER
 
86
 
 
87
  !> @bud container for BUD_TYPE_NAME
 
88
  type BUD_TYPE_NAME_
 
89
 
 
90
    !> Maximum number of elements that can be stored in this stack.
 
91
    !!
 
92
    !! @note
 
93
    !! There is little to no memory overhead of having an excessively
 
94
    !! large `max` as all elements which have not been assigned are
 
95
    !! allocations of data-pointers.
 
96
    !!
 
97
    !! Hence creating extreme stacks may still be memory efficient.
 
98
    integer :: nel_max
 
99
 
 
100
    !> Current number of elements in the stack.
 
101
    integer :: nel
 
102
 
 
103
    !> Array of elements (stack).
 
104
    type(BUD_STACK_TYPE), pointer :: T(:) => null()
 
105
 
 
106
    ! Consistent data in the reference counted object
 
107
#   include "bud_common_type_.inc"
 
108
 
 
109
  end type BUD_TYPE_NAME_
 
110
 
 
111
  !> @endcond BUD_DEVELOPER
 
112
 
 
113
 
 
114
  ! special counter for deleting all elements
 
115
  ! of a stack using:
 
116
  !   call pop(<this>, 0)
 
117
  !> Special parameter for popping all elements.
 
118
  !!
 
119
  !! Allows one to pop/delete all elements in the stack.
 
120
  !! This basically performs a
 
121
  !! \code{.f90}
 
122
  !!  n = size_max(this)
 
123
  !!  call delete(this)
 
124
  !!  call new(this, n)
 
125
  !! \endcode
 
126
  !!integer, public, parameter :: BUD_FSTACK_ALL = 0
 
127
 
 
128
 
 
129
  !> Internal initialization of finite stack holding BUD_STACK_TYPE
 
130
  !!
 
131
  !! If called on a previously allocated data scope this
 
132
  !! will clear the reference (@isee delete).
 
133
  !! Subsequently the type container will be allocated
 
134
  !! and the reference counted data will be 1.
 
135
  interface new
 
136
    module procedure new_
 
137
  end interface
 
138
  public :: new
 
139
 
 
140
  !> Adds/Pushes new element to the stack
 
141
  !!
 
142
  !! If the stack is full the oldest element will be deleted
 
143
  !! and the second oldest becomes the first element of the stack.
 
144
  !!
 
145
  !! @note
 
146
  !! One cannot push elements in the middle of the stack.
 
147
  interface push
 
148
    module procedure push_
 
149
  end interface
 
150
  public :: push
 
151
 
 
152
  !> Pop and (possibly) return the latest item in the stack
 
153
  !!
 
154
  !! The top item is returned in `item` and the stack
 
155
  !! is decremented thus removing the returned item from the stack.
 
156
  !!
 
157
  !! An optional index may be given, see #pop_delete_.
 
158
  !!
 
159
  !! If the top element has not been initialized the returned item will
 
160
  !! be un-initialized.
 
161
  !!
 
162
  !! @note
 
163
  !! The returned item will thus not have its counted references changed.
 
164
  interface pop
 
165
    module procedure pop_
 
166
    module procedure pop_delete_
 
167
  end interface
 
168
  public :: pop
 
169
 
 
170
 
 
171
  !> Retains a fixed number of elements in the stack
 
172
  !!
 
173
  !! Retains a number of elements from either the top or the
 
174
  !! bottom of the stack.
 
175
  !!
 
176
  !! If any of the counts are larger than the currently
 
177
  !! number of stored elements, nothing will happen.
 
178
  !!
 
179
  !! @note
 
180
  !! Defaults to `top=fnelem(this)-1`
 
181
  interface retain
 
182
    module procedure retain_
 
183
  end interface
 
184
  public :: retain
 
185
 
 
186
  !> Retrieve specific element from the stack
 
187
  !!
 
188
  !! If the requested element is beyond the number of
 
189
  !! stored elements `elem` will be un-initialized upon return.
 
190
  interface element
 
191
    module procedure get_elem_
 
192
  end interface
 
193
  public :: element
 
194
 
 
195
  !> Retrieve pointer to specific element in the stack
 
196
  !!
 
197
  !! Retrieving a pointer does not change the reference status
 
198
  !! of the @bud.
 
199
  !!
 
200
  !! If the requested element is beyond the number of
 
201
  !! stored elements `elem` will be null.
 
202
  !!
 
203
  interface element_p
 
204
    module procedure get_elem_p_
 
205
  end interface
 
206
  public :: element_p
 
207
 
 
208
  !> Query number of currently stored elements in this stack
 
209
  interface size
 
210
    module procedure size_elem_
 
211
  end interface
 
212
  public :: size
 
213
 
 
214
  !> Query maximum number of allowed elements in this stack
 
215
  interface size_max
 
216
    module procedure size_max_elem_
 
217
  end interface
 
218
  public :: size_max
 
219
 
 
220
 
 
221
  ! all default reference counted stuff
 
222
# include "bud_common.inc"
 
223
 
 
224
  !> @cond BUD_DEVELOPER
 
225
 
 
226
  subroutine delete_(this)
 
227
    type(BUD_TYPE_NAME), intent(inout) :: this
 
228
    integer :: i, stat
 
229
 
 
230
    stat = 0
 
231
    if ( associated(this%D%T) ) then
 
232
 
 
233
      ! Deallocate array
 
234
      do i = 1 , size(this%D%T)
 
235
        call delete(this%D%T(i))
 
236
        if ( 0 /= error(this%D%T(i)) ) then
 
237
          stat = error(this%D%T(i))
 
238
        end if
 
239
      end do
 
240
      deallocate(this%D%T, stat=i)
 
241
      if ( 0 /= i ) stat = i
 
242
      nullify(this%D%T)
 
243
 
 
244
    end if
 
245
 
 
246
    this%D%nel_max = 0
 
247
    this%D%nel = 0
 
248
    call set_error(this, stat)
 
249
 
 
250
  end subroutine delete_
 
251
 
 
252
  !> @endcond BUD_DEVELOPER
 
253
 
 
254
 
 
255
  !> @param[in] from the original `bud` which is copied to `to`
 
256
  !! @param[inout] to the output `bud` with the full copied data
 
257
  subroutine copy_(from, to)
 
258
    BUD_CLASS(BUD_TYPE_NAME), intent(in) :: from
 
259
    BUD_CLASS(BUD_TYPE_NAME), intent(inout) :: to
 
260
    integer :: i
 
261
    type(BUD_STACK_TYPE), pointer :: p
 
262
    type(BUD_STACK_TYPE) :: cp
 
263
 
 
264
    call delete(to)
 
265
    if ( .not. is_initd(from) ) return
 
266
 
 
267
    call new(to, from%D%nel_max)
 
268
 
 
269
    do i = 1 , size(from)
 
270
      p => element_p(from, i)
 
271
      call copy(p, cp)
 
272
      call push(to, cp)
 
273
      call delete(cp)
 
274
    end do
 
275
 
 
276
    ! Copy the common data-content
 
277
    call common_copy_(from, to)
 
278
 
 
279
  end subroutine copy_
 
280
 
 
281
  !> @param[inout] this initialize the finite stack
 
282
  !! @param[in] nel maximum number of elements that may be contained in the stack
 
283
  subroutine new_(this, nel)
 
284
    BUD_CLASS(BUD_TYPE_NAME), intent(inout) :: this
 
285
    integer, intent(in) :: nel
 
286
 
 
287
    if ( nel < 1 ) then
 
288
      call set_error(this, -1)
 
289
      return
 
290
    end if
 
291
 
 
292
    call initialize(this)
 
293
 
 
294
    this%D%nel_max = nel
 
295
    this%D%nel = 0
 
296
 
 
297
    ! prepare data locations
 
298
    allocate(this%D%T(nel))
 
299
 
 
300
  end subroutine new_
 
301
 
 
302
 
 
303
  !> @param[inout] this stack that gets added an element
 
304
  !! @param[in] item element added to the stack
 
305
  subroutine push_(this,item)
 
306
    BUD_CLASS(BUD_TYPE_NAME), intent(inout) :: this
 
307
    type(BUD_STACK_TYPE), intent(in) :: item
 
308
 
 
309
    integer :: el, i
 
310
 
 
311
    ! if this has not been initialised we immediately return
 
312
    ! We _could_ initialize it, but we do not know how
 
313
    ! many maximum elements that is allowed?
 
314
    ! So we return
 
315
    if ( .not. is_initd(this) ) return
 
316
 
 
317
    el = size(this)
 
318
 
 
319
    if ( el == size_max(this) ) then
 
320
 
 
321
      ! cycle stack and push
 
322
      do i = 2 , el
 
323
        this%D%T(i-1) = this%D%T(i)
 
324
      end do
 
325
      ! Assignment will also delete.
 
326
      this%D%T(el) = item
 
327
 
 
328
    else
 
329
 
 
330
      el = el + 1
 
331
      ! simply add it to the stack
 
332
      this%D%nel = el
 
333
      this%D%T(el) = item
 
334
 
 
335
    end if
 
336
 
 
337
  end subroutine push_
 
338
 
 
339
 
 
340
  !> @param[inout] this stack that gets removed an item
 
341
  !! @param[inout] item returned element from the top of the stack
 
342
  subroutine pop_(this, item)
 
343
    BUD_CLASS(BUD_TYPE_NAME), intent(inout) :: this
 
344
    type(BUD_STACK_TYPE), intent(inout) :: item
 
345
 
 
346
    integer :: el
 
347
 
 
348
    if ( .not. is_initd(this) ) then
 
349
      call delete(item)
 
350
      return
 
351
    end if
 
352
 
 
353
    el = size(this)
 
354
 
 
355
    ! easy case if it is empty
 
356
    if ( 0 == el ) then
 
357
 
 
358
      call delete(item)
 
359
      return
 
360
 
 
361
    end if
 
362
 
 
363
    ! retrieve the latest value
 
364
    item = this%D%T(el)
 
365
 
 
366
    call pop(this)
 
367
 
 
368
  end subroutine pop_
 
369
 
 
370
 
 
371
  !> @param[inout] this stack that gets removed an item
 
372
  !! @param[in] top @opt=1 number of popped elements from top.
 
373
  !!                If 0 is supplied it will
 
374
  !!                clear all elements.
 
375
  !! @param[in] bot @opt=@null has precedence if `top` not supplied.
 
376
  !!                Pops `bot` elements from the bottom of the stack.
 
377
  subroutine pop_delete_(this, top, bot)
 
378
    BUD_CLASS(BUD_TYPE_NAME), intent(inout) :: this
 
379
    integer, intent(in), optional :: top, bot
 
380
 
 
381
    integer :: lnpop
 
382
    integer :: el, i
 
383
 
 
384
    ! it is already empty...
 
385
    if ( .not. is_initd(this) ) return
 
386
 
 
387
    if ( .not. present(top) &
 
388
      .and. .not. present(bot) ) then
 
389
      call set_error(this, 1)
 
390
      return
 
391
    end if
 
392
 
 
393
    ! number of elements
 
394
    el = size(this)
 
395
 
 
396
    if ( present(top) .or. .not. present(bot) ) then
 
397
 
 
398
      ! regular top-popping
 
399
      lnpop = 1
 
400
 
 
401
      if ( present(top) ) lnpop = top
 
402
 
 
403
      ! If 0 is passed, we delete all
 
404
      if ( lnpop == 0 ) lnpop = el
 
405
 
 
406
      ! we should not pop anything
 
407
      if ( lnpop < 0 ) return
 
408
 
 
409
      do while ( lnpop > 0 )
 
410
 
 
411
        ! easy case if it is empty
 
412
        if ( 0 == el ) return
 
413
 
 
414
        ! Delete the local item and decrease counter
 
415
        call delete(this%D%T(el))
 
416
        this%D%nel = this%D%nel - 1
 
417
 
 
418
        el = el - 1
 
419
        lnpop = lnpop - 1
 
420
      end do
 
421
 
 
422
    else ! bot has been supplied
 
423
 
 
424
      ! bottom popping
 
425
      lnpop = bot
 
426
 
 
427
      ! in case of a negative number we cannot pop anything
 
428
      if ( lnpop < 0 ) return
 
429
 
 
430
      do while ( lnpop > 0 )
 
431
 
 
432
        ! easy case if it is empty
 
433
        if ( 0 == el ) return
 
434
 
 
435
        ! Delete the local item and decrease counter
 
436
        call delete(this%D%T(1))
 
437
        this%D%nel = this%D%nel - 1
 
438
        ! shift to attain the correct order
 
439
        do i = 1 , this%D%nel
 
440
          this%D%T(i) = this%D%T(i+1)
 
441
        end do
 
442
 
 
443
        el = el - 1
 
444
        lnpop = lnpop - 1
 
445
      end do
 
446
 
 
447
    end if
 
448
 
 
449
  end subroutine pop_delete_
 
450
 
 
451
 
 
452
  !> @param[inout] this stack to operate on
 
453
  !! @param[in] top @opt=1 number of elements kept from the top
 
454
  !! @param[in] bot @opt=@null number of elements kept from the bottom,
 
455
  !!                only used if `top` is not supplied.
 
456
  subroutine retain_(this, top, bot)
 
457
    BUD_CLASS(BUD_TYPE_NAME), intent(inout) :: this
 
458
    integer, intent(in), optional :: top, bot
 
459
 
 
460
    integer :: lnpop
 
461
    integer :: el
 
462
 
 
463
    if ( .not. is_initd(this) ) return
 
464
 
 
465
    if ( .not. present(top) &
 
466
      .and. .not. present(bot) ) then
 
467
      call set_error(this, 1)
 
468
      return
 
469
    end if
 
470
 
 
471
    ! number of elements
 
472
    el = size(this)
 
473
 
 
474
    if ( present(top) .or. .not. present(bot) ) then
 
475
 
 
476
      ! regular bot-popping
 
477
      lnpop = 1
 
478
      if ( present(top) ) lnpop = el - top
 
479
 
 
480
      ! we should not pop anything
 
481
      if ( lnpop < 0 ) return
 
482
 
 
483
      call pop(this, bot=lnpop)
 
484
 
 
485
    else
 
486
 
 
487
      ! retain 'n' items from the bottom
 
488
      lnpop = el - bot
 
489
 
 
490
      ! we should not pop anything
 
491
      if ( lnpop < 0 ) return
 
492
 
 
493
      call pop(this, top=lnpop)
 
494
 
 
495
    end if
 
496
 
 
497
  end subroutine retain_
 
498
 
 
499
 
 
500
  !> @param[in] this stack to retrieve element from
 
501
  !! @param[inout] elem returned item stored in element `iel`
 
502
  !! @param[in] iel @opt=`size(this)` index of element to return. May be negative to offset from the top
 
503
  subroutine get_elem_(this, elem, iel)
 
504
    BUD_CLASS(BUD_TYPE_NAME), intent(in) :: this
 
505
    type(BUD_STACK_TYPE), intent(inout) :: elem
 
506
    integer, intent(in), optional :: iel
 
507
    integer :: el
 
508
 
 
509
    call delete(elem)
 
510
    if ( .not. is_initd(this) ) return
 
511
 
 
512
    ! Default element
 
513
    el = size(this)
 
514
 
 
515
    if ( present(iel) ) then
 
516
      if ( iel < 0 ) then
 
517
        el = el + iel
 
518
      else
 
519
        el = iel
 
520
      end if
 
521
    end if
 
522
 
 
523
    if ( el <= size(this) ) then
 
524
      elem = this%D%T(el)
 
525
    end if
 
526
 
 
527
  end subroutine get_elem_
 
528
 
 
529
  !> @param[in] this stack to retrieve pointer element from
 
530
  !! @param[in] iel @opt=`size(this)` index of element to return. May be negative to offset from top.
 
531
  !! @result pointer to the element `iel`
 
532
  function get_elem_p_(this, iel) result(p)
 
533
    BUD_CLASS(BUD_TYPE_NAME), intent(in) :: this
 
534
    integer, intent(in), optional :: iel
 
535
    type(BUD_STACK_TYPE), pointer :: p
 
536
    integer :: el
 
537
 
 
538
    nullify(p)
 
539
    if ( .not. is_initd(this) ) return
 
540
 
 
541
    ! Default element
 
542
    el = size(this)
 
543
 
 
544
    if ( present(iel) ) then
 
545
      if ( iel < 0 ) then
 
546
        el = el + iel
 
547
      else
 
548
        el = iel
 
549
      end if
 
550
    end if
 
551
 
 
552
    if ( el <= size(this) ) then
 
553
      p => this%D%T(el)
 
554
    end if
 
555
 
 
556
  end function get_elem_p_
 
557
 
 
558
 
 
559
  !> @param[inout] this stack to count element from
 
560
  !! @return number of currently stored elements
 
561
  elemental function size_elem_(this) result (nel)
 
562
    BUD_CLASS(BUD_TYPE_NAME), intent(in) :: this
 
563
    integer :: nel
 
564
    if ( .not. is_initd(this) ) then
 
565
      nel = 0
 
566
    else
 
567
      nel = this%D%nel
 
568
    end if
 
569
  end function size_elem_
 
570
 
 
571
 
 
572
  !> @param[inout] this stack that is queried maximum size of
 
573
  !! @return maximum number of allowed elements
 
574
  elemental function size_max_elem_(this) result (nel_max)
 
575
    BUD_CLASS(BUD_TYPE_NAME), intent(in) :: this
 
576
    integer :: nel_max
 
577
    if ( .not. is_initd(this) ) then
 
578
      nel_max = 0
 
579
    else
 
580
      nel_max = this%D%nel_max
 
581
    end if
 
582
  end function size_max_elem_
 
583
 
 
584
 
 
585
#ifndef BUD_NO_IO
 
586
# ifndef BUD_IO_OVERLOAD
 
587
 
 
588
  !> @param[in] f a file (bud_File)
 
589
  !! @param[in] this collection @bud to be written
 
590
  subroutine write_(f, this)
 
591
    use BUD_CC2(BUD_MOD,_File)
 
592
    BUD_CLASS( BUD_CC2(BUD_TYPE,File) ), intent(inout) :: f
 
593
    BUD_CLASS(BUD_TYPE_NAME), intent(in) :: this
 
594
 
 
595
    logical :: formatted
 
596
    integer :: iu
 
597
    integer :: nel, nel_max, i
 
598
 
 
599
    ! If file is not opened, return immediately
 
600
    if ( .not. is_open(f) ) return
 
601
    if ( .not. is_initd(this) ) return
 
602
 
 
603
    formatted = is_formatted(f)
 
604
    iu = unit(f)
 
605
 
 
606
    ! Get information about this stack
 
607
    nel_max = size_max(this)
 
608
    nel = size(this)
 
609
 
 
610
    if ( formatted ) then
 
611
      write(iu, '(i16)') nel_max, nel
 
612
    else
 
613
      write(iu) nel_max, nel
 
614
    end if
 
615
 
 
616
    ! Now write each of them...
 
617
    do i = 1 , nel
 
618
      call write(f, this%D%T(i))
 
619
    end do
 
620
 
 
621
  end subroutine write_
 
622
 
 
623
  !> @param[in] f a file (bud_File)
 
624
  !! @param[in] this collection @bud to be readed
 
625
  subroutine read_(f, this)
 
626
    use BUD_CC2(BUD_MOD,_File)
 
627
    BUD_CLASS( BUD_CC2(BUD_TYPE,File) ), intent(inout) :: f
 
628
    BUD_CLASS(BUD_TYPE_NAME), intent(inout) :: this
 
629
 
 
630
    ! To read each of them individually
 
631
    type(BUD_STACK_TYPE) :: cp
 
632
 
 
633
    logical :: formatted
 
634
    integer :: iu
 
635
    integer :: nel, nel_max, i
 
636
 
 
637
    ! If file is not opened, return immediately
 
638
    if ( .not. is_open(f) ) return
 
639
 
 
640
    formatted = is_formatted(f)
 
641
    iu = unit(f)
 
642
 
 
643
    ! Get information about this stack
 
644
    if ( formatted ) then
 
645
      read(iu, '(i16)') nel_max, nel
 
646
    else
 
647
      read(iu) nel_max, nel
 
648
    end if
 
649
 
 
650
    ! Initialize this object
 
651
    call new(this, nel_max)
 
652
 
 
653
    ! Now read each of them...
 
654
    do i = 1 , nel
 
655
      call read(f, cp)
 
656
      call push(this, cp)
 
657
      call delete(cp)
 
658
    end do
 
659
 
 
660
  end subroutine read_
 
661
 
 
662
# endif
 
663
#endif
 
664
 
 
665
  !> @param[in] this data type
 
666
  !! @param[in] info @opt=BUD_TYPE_NAME_STR additional information printed
 
667
  !! @param[in] indent @opt=1 possible indentation of printed statement
 
668
  subroutine print_(this, info, indent)
 
669
    BUD_CLASS(BUD_TYPE_NAME), intent(in) :: this
 
670
    character(len=*), intent(in), optional :: info
 
671
    integer, intent(in), optional :: indent
 
672
 
 
673
    integer :: lindent
 
674
    integer :: i
 
675
 
 
676
    ! 4-byte variable
 
677
    character(len=32) :: fmt
 
678
    character(len=256) :: name
 
679
 
 
680
    name = BUD_TYPE_NAME_STR
 
681
    if ( present(info) ) name = info
 
682
    lindent = 1
 
683
    if ( present(indent) ) lindent = indent
 
684
 
 
685
    write(fmt, '(a,i0,a)') '(t',lindent,',3a)'
 
686
 
 
687
    if ( .not. is_initd(this) ) then
 
688
      write(*,fmt) "<", trim(name), " not initialized>"
 
689
      return
 
690
    end if
 
691
 
 
692
    write(fmt, '(a,i0,a)') '(t',lindent,',3a)'
 
693
    lindent = lindent + 2 ! step indentation
 
694
    write(*,fmt) "<<", trim(name), " stack>"
 
695
    do i = 1 , size(this)
 
696
      call print(this%D%T(i), indent = lindent)
 
697
    end do
 
698
    lindent = lindent - 2 ! go back to requested indentation
 
699
    write(fmt, '(a,i0,a)') '(t',lindent,',a,i0,a)'
 
700
    write(*,fmt) " <stack-refs: ", references(this), ">>"
 
701
 
 
702
  end subroutine print_
 
703
 
 
704
 
 
705
#undef BUD_MOD_NAME
 
706
#undef BUD_TYPE_NAME
 
707
#undef BUD_TYPE_NAME_
 
708
#undef BUD_TYPE_NAME_STR
 
709
#undef BUD_TYPE_NEW
 
710
#undef BUD_STACK_TYPE
 
711
 
 
712
 
 
713
  ! project-buds -- local file settings
 
714
  !     Anything below this line may be overwritten by scripts
 
715
  !     Below are non-editable settings
 
716
 
 
717
  ! Local Variables:
 
718
  !  mode: f90
 
719
  !  f90-if-indent: 2
 
720
  !  f90-type-indent: 2
 
721
  !  f90-associate-indent: 2
 
722
  !  f90-continuation-indent: 2
 
723
  !  f90-structure-indent: 2
 
724
  !  f90-critical-indent: 2
 
725
  !  f90-program-indent: 2
 
726
  !  f90-do-indent: 2
 
727
  ! End: