1! @LICENSE@, see README.md
2! Generic purpose variable as in any scripting language
3! It has the power to transform into any variable at any time
4module variable
5  !! A type-free variable module to contain _any_ data in fortran.
6  !!
7  !! This module implements a generic variable-type (`type(variable_t)`)
8  !! which may contain _any_ data-type (even user-derived type constructs).
9  !!
10  !! Its basic usage is somewhat different than the regular assignment
11  !! in fortran.
12  !!
13  !! Example:
14  !!
15  !!```fortran
16  !! real :: r
17  !! real :: ra(10)
18  !! real, target :: rb(10)
19  !! type(variable_t) :: v
20  !! call assign(v, r) ! v now contains value of r
21  !! call assign(v, ra) ! v now contains array with values of ra
22  !! call delete(v) ! delete content
23  !! call associate(v, ra) ! v now contains a pointer to rb
24  !! call assign(ra, v) ! copies data from rb to ra
25  !!```
26  !!
27  !! The assignment routine behaves like `=` (delete old value)
28  !! whereas the associate routine behaves like `=>` (nullify old value).
29  !!
30  !! The data-types allowed in this type is *not* limited by this
31  !! module, but we currently allow integers, reals, complex and C-pointers.
32  ! Load the iso_c_binding for containing a C-pointer
33  use, intrinsic :: iso_c_binding
34  implicit none
35  private
36  integer, parameter :: ih = selected_int_kind(4)
37  integer, parameter :: is = selected_int_kind(9)
38  integer, parameter :: il = selected_int_kind(18)
39  integer, parameter :: sp = selected_real_kind(p=6)
40  integer, parameter :: dp = selected_real_kind(p=15)
41  ! To create a constant transfer data-type of the
42  ! pointer methods
43  character(len=1) :: local_enc_type(1)
44  ! Internal variable to hold the size of the "type" switch
45  !> Maximum character length of the type specifier in the variable, no
46  !! unique identifier may be longer than this.
47  integer, parameter, public :: VARIABLE_TYPE_LENGTH = 4
48  type :: variable_t
49     !! Container for _any_ fortran data-type, intrinsically handles all
50     !! from fortran and any external type may be added via external routines.
51     !!
52     !! The container is based on a type-transfer method by storing a pointer
53     !! to the data and transfer the type to a character array via encoding.
54     !! This enables one to retrieve the pointer position later and thus enables
55     !! pointer assignments and easy copying of data.
56     character(len=VARIABLE_TYPE_LENGTH) :: t = '    '
57     ! The encoding placement of all data
58     character(len=1), dimension(:), allocatable :: enc
59  end type variable_t
60  public :: variable_t
61  interface which
62     !! Type of content stored in the variable (`character(len=VARIABLE_TYPE_LENGTH)`)
63     module procedure which_
64  end interface
65  public :: which
66  interface delete
67     !! Delete the variable (equivalent to `deallocate(<>)`).
68     module procedure delete_
69  end interface
70  public :: delete
71  interface nullify
72     !! Nullify the variable (equivalent to `nullify(<>)`).
73     module procedure nullify_
74  end interface
75  public :: nullify
76  interface print
77     !! Print (to std-out) information regarding the variable, i.e. the type.
78     module procedure print_
79  end interface
80  public :: print
81  ! Specific routines for passing types to variables
82  interface associate_type
83     module procedure associate_type_
84  end interface
85  public :: associate_type
86  interface enc
87     !! The encoding of the stored pointer (`character, dimension(:)`)
88     !!
89     !! This is mainly intenteded for internal use to transfer between real
90     !! data and the data containers.
91     !!
92     !! It is however required to enable external type storage routines.
93     module procedure enc_
94  end interface
95  public :: enc
96  interface size_enc
97     !! The size of the encoding character array (`size(enc(<>))`)
98     !!
99     !! This is mainly intenteded for internal use to transfer between real
100     !! data and the data containers.
101     module procedure size_enc_
102  end interface
103  public :: size_enc
104  ! Specific routine for packing a character(len=*) to
105  ! character(len=1) (:)
106  interface cpack
107     !! Convert a `character(len=*)` to `character, dimension(:)`
108     !!
109     !! A routine requirement for creating pointers to character storages.
110     !! One can convert from `len=*` to an array of `len=1` and back using [[cunpack]].
111     !!
112     !! Because fortran requires dimensions of arrays assignments to be same size it
113     !! one has to specify ranges if the length of the character is not equivalent
114     !! to the size of the array.
115     !!
116     !! Example:
117     !!
118     !!```fortran
119     !! character(len=20) :: a
120     !! character :: b(10)
121     !! a = 'Hello'
122     !! b(1:5) = cpack('Hello')
123     !!```
124     !!
125     !! @note
126     !! This is a requirement because it is not possible to create a unified pointer
127     !! to arbitrary length characters. Hence we store all `len=*` variables as `len=1` character arrays.
128     module procedure cpack_
129  end interface cpack
130  public :: cpack
131  ! Specific routine for packing a character(len=*) to
132  ! character(len=1) (:)
133  interface cunpack
134     !! Convert a `character(len=1), dimensions(:)` to `character(len=*)`
135     !!
136     !! Pack an array into a character of arbitrary length.
137     !! This convenience function helps converting between arrays of characters
138     !! and fixed length characters.
139     !!
140     !! As character assignment is not restricted similarly as array assignments
141     !! it is not a requirement to specify ranges when using this function.
142     module procedure cunpack_
143  end interface cunpack
144  public :: cunpack
145interface assign
146module procedure assign_get_a0_0
147module procedure assign_set_a0_0
148module procedure assign_var
149module procedure assign_get_a1
150module procedure assign_set_a1
151module procedure assign_get_s0
152module procedure assign_set_s0
153module procedure assign_get_s1
154module procedure assign_set_s1
155module procedure assign_get_s2
156module procedure assign_set_s2
157module procedure assign_get_s3
158module procedure assign_set_s3
159module procedure assign_get_d0
160module procedure assign_set_d0
161module procedure assign_get_d1
162module procedure assign_set_d1
163module procedure assign_get_d2
164module procedure assign_set_d2
165module procedure assign_get_d3
166module procedure assign_set_d3
167module procedure assign_get_c0
168module procedure assign_set_c0
169module procedure assign_get_c1
170module procedure assign_set_c1
171module procedure assign_get_c2
172module procedure assign_set_c2
173module procedure assign_get_c3
174module procedure assign_set_c3
175module procedure assign_get_z0
176module procedure assign_set_z0
177module procedure assign_get_z1
178module procedure assign_set_z1
179module procedure assign_get_z2
180module procedure assign_set_z2
181module procedure assign_get_z3
182module procedure assign_set_z3
183module procedure assign_get_b0
184module procedure assign_set_b0
185module procedure assign_get_b1
186module procedure assign_set_b1
187module procedure assign_get_b2
188module procedure assign_set_b2
189module procedure assign_get_b3
190module procedure assign_set_b3
191module procedure assign_get_h0
192module procedure assign_set_h0
193module procedure assign_get_h1
194module procedure assign_set_h1
195module procedure assign_get_h2
196module procedure assign_set_h2
197module procedure assign_get_h3
198module procedure assign_set_h3
199module procedure assign_get_i0
200module procedure assign_set_i0
201module procedure assign_get_i1
202module procedure assign_set_i1
203module procedure assign_get_i2
204module procedure assign_set_i2
205module procedure assign_get_i3
206module procedure assign_set_i3
207module procedure assign_get_l0
208module procedure assign_set_l0
209module procedure assign_get_l1
210module procedure assign_set_l1
211module procedure assign_get_l2
212module procedure assign_set_l2
213module procedure assign_get_l3
214module procedure assign_set_l3
215module procedure assign_get_cp0
216module procedure assign_set_cp0
217module procedure assign_get_cp1
218module procedure assign_set_cp1
219module procedure assign_get_fp0
220module procedure assign_set_fp0
221module procedure assign_get_fp1
222module procedure assign_set_fp1
223end interface
224public :: assign
225interface associate
226module procedure associate_var
227module procedure associate_get_a1
228module procedure associate_set_a1
229module procedure associate_get_s0
230module procedure associate_set_s0
231module procedure associate_get_s1
232module procedure associate_set_s1
233module procedure associate_get_s2
234module procedure associate_set_s2
235module procedure associate_get_s3
236module procedure associate_set_s3
237module procedure associate_get_d0
238module procedure associate_set_d0
239module procedure associate_get_d1
240module procedure associate_set_d1
241module procedure associate_get_d2
242module procedure associate_set_d2
243module procedure associate_get_d3
244module procedure associate_set_d3
245module procedure associate_get_c0
246module procedure associate_set_c0
247module procedure associate_get_c1
248module procedure associate_set_c1
249module procedure associate_get_c2
250module procedure associate_set_c2
251module procedure associate_get_c3
252module procedure associate_set_c3
253module procedure associate_get_z0
254module procedure associate_set_z0
255module procedure associate_get_z1
256module procedure associate_set_z1
257module procedure associate_get_z2
258module procedure associate_set_z2
259module procedure associate_get_z3
260module procedure associate_set_z3
261module procedure associate_get_b0
262module procedure associate_set_b0
263module procedure associate_get_b1
264module procedure associate_set_b1
265module procedure associate_get_b2
266module procedure associate_set_b2
267module procedure associate_get_b3
268module procedure associate_set_b3
269module procedure associate_get_h0
270module procedure associate_set_h0
271module procedure associate_get_h1
272module procedure associate_set_h1
273module procedure associate_get_h2
274module procedure associate_set_h2
275module procedure associate_get_h3
276module procedure associate_set_h3
277module procedure associate_get_i0
278module procedure associate_set_i0
279module procedure associate_get_i1
280module procedure associate_set_i1
281module procedure associate_get_i2
282module procedure associate_set_i2
283module procedure associate_get_i3
284module procedure associate_set_i3
285module procedure associate_get_l0
286module procedure associate_set_l0
287module procedure associate_get_l1
288module procedure associate_set_l1
289module procedure associate_get_l2
290module procedure associate_set_l2
291module procedure associate_get_l3
292module procedure associate_set_l3
293module procedure associate_get_cp0
294module procedure associate_set_cp0
295module procedure associate_get_cp1
296module procedure associate_set_cp1
297module procedure associate_get_fp0
298module procedure associate_set_fp0
299module procedure associate_get_fp1
300module procedure associate_set_fp1
301end interface
302public :: associate
303interface associatd
304module procedure associatd_l_a1
305module procedure associatd_r_a1
306module procedure associatd_l_s0
307module procedure associatd_r_s0
308module procedure associatd_l_s1
309module procedure associatd_r_s1
310module procedure associatd_l_s2
311module procedure associatd_r_s2
312module procedure associatd_l_s3
313module procedure associatd_r_s3
314module procedure associatd_l_d0
315module procedure associatd_r_d0
316module procedure associatd_l_d1
317module procedure associatd_r_d1
318module procedure associatd_l_d2
319module procedure associatd_r_d2
320module procedure associatd_l_d3
321module procedure associatd_r_d3
322module procedure associatd_l_c0
323module procedure associatd_r_c0
324module procedure associatd_l_c1
325module procedure associatd_r_c1
326module procedure associatd_l_c2
327module procedure associatd_r_c2
328module procedure associatd_l_c3
329module procedure associatd_r_c3
330module procedure associatd_l_z0
331module procedure associatd_r_z0
332module procedure associatd_l_z1
333module procedure associatd_r_z1
334module procedure associatd_l_z2
335module procedure associatd_r_z2
336module procedure associatd_l_z3
337module procedure associatd_r_z3
338module procedure associatd_l_b0
339module procedure associatd_r_b0
340module procedure associatd_l_b1
341module procedure associatd_r_b1
342module procedure associatd_l_b2
343module procedure associatd_r_b2
344module procedure associatd_l_b3
345module procedure associatd_r_b3
346module procedure associatd_l_h0
347module procedure associatd_r_h0
348module procedure associatd_l_h1
349module procedure associatd_r_h1
350module procedure associatd_l_h2
351module procedure associatd_r_h2
352module procedure associatd_l_h3
353module procedure associatd_r_h3
354module procedure associatd_l_i0
355module procedure associatd_r_i0
356module procedure associatd_l_i1
357module procedure associatd_r_i1
358module procedure associatd_l_i2
359module procedure associatd_r_i2
360module procedure associatd_l_i3
361module procedure associatd_r_i3
362module procedure associatd_l_l0
363module procedure associatd_r_l0
364module procedure associatd_l_l1
365module procedure associatd_r_l1
366module procedure associatd_l_l2
367module procedure associatd_r_l2
368module procedure associatd_l_l3
369module procedure associatd_r_l3
370module procedure associatd_l_cp0
371module procedure associatd_r_cp0
372module procedure associatd_l_cp1
373module procedure associatd_r_cp1
374module procedure associatd_l_fp0
375module procedure associatd_r_fp0
376module procedure associatd_l_fp1
377module procedure associatd_r_fp1
378end interface
379public :: associatd
380contains
381  subroutine print_(this)
382    type(variable_t), intent(in) :: this
383    write(*,'(t2,a)') this%t
384  end subroutine print_
385  elemental function which_(this) result(t)
386    type(variable_t), intent(in) :: this
387    character(len=VARIABLE_TYPE_LENGTH) :: t
388    t = this%t
389  end function which_
390  subroutine delete_(this,dealloc)
391    type(variable_t), intent(inout) :: this
392    logical, intent(in), optional :: dealloc
393    logical :: ldealloc
394type :: pta1
395 character(len=1), pointer :: p(:) => null()
396end type pta1
397type(pta1) :: pa1
398type :: pts0
399 real(sp), pointer :: p => null()
400end type pts0
401type(pts0) :: ps0
402type :: pts1
403 real(sp), pointer :: p(:) => null()
404end type pts1
405type(pts1) :: ps1
406type :: pts2
407 real(sp), pointer :: p(:,:) => null()
408end type pts2
409type(pts2) :: ps2
410type :: pts3
411 real(sp), pointer :: p(:,:,:) => null()
412end type pts3
413type(pts3) :: ps3
414type :: ptd0
415 real(dp), pointer :: p => null()
416end type ptd0
417type(ptd0) :: pd0
418type :: ptd1
419 real(dp), pointer :: p(:) => null()
420end type ptd1
421type(ptd1) :: pd1
422type :: ptd2
423 real(dp), pointer :: p(:,:) => null()
424end type ptd2
425type(ptd2) :: pd2
426type :: ptd3
427 real(dp), pointer :: p(:,:,:) => null()
428end type ptd3
429type(ptd3) :: pd3
430type :: ptc0
431 complex(sp), pointer :: p => null()
432end type ptc0
433type(ptc0) :: pc0
434type :: ptc1
435 complex(sp), pointer :: p(:) => null()
436end type ptc1
437type(ptc1) :: pc1
438type :: ptc2
439 complex(sp), pointer :: p(:,:) => null()
440end type ptc2
441type(ptc2) :: pc2
442type :: ptc3
443 complex(sp), pointer :: p(:,:,:) => null()
444end type ptc3
445type(ptc3) :: pc3
446type :: ptz0
447 complex(dp), pointer :: p => null()
448end type ptz0
449type(ptz0) :: pz0
450type :: ptz1
451 complex(dp), pointer :: p(:) => null()
452end type ptz1
453type(ptz1) :: pz1
454type :: ptz2
455 complex(dp), pointer :: p(:,:) => null()
456end type ptz2
457type(ptz2) :: pz2
458type :: ptz3
459 complex(dp), pointer :: p(:,:,:) => null()
460end type ptz3
461type(ptz3) :: pz3
462type :: ptb0
463 logical, pointer :: p => null()
464end type ptb0
465type(ptb0) :: pb0
466type :: ptb1
467 logical, pointer :: p(:) => null()
468end type ptb1
469type(ptb1) :: pb1
470type :: ptb2
471 logical, pointer :: p(:,:) => null()
472end type ptb2
473type(ptb2) :: pb2
474type :: ptb3
475 logical, pointer :: p(:,:,:) => null()
476end type ptb3
477type(ptb3) :: pb3
478type :: pth0
479 integer(ih), pointer :: p => null()
480end type pth0
481type(pth0) :: ph0
482type :: pth1
483 integer(ih), pointer :: p(:) => null()
484end type pth1
485type(pth1) :: ph1
486type :: pth2
487 integer(ih), pointer :: p(:,:) => null()
488end type pth2
489type(pth2) :: ph2
490type :: pth3
491 integer(ih), pointer :: p(:,:,:) => null()
492end type pth3
493type(pth3) :: ph3
494type :: pti0
495 integer(is), pointer :: p => null()
496end type pti0
497type(pti0) :: pi0
498type :: pti1
499 integer(is), pointer :: p(:) => null()
500end type pti1
501type(pti1) :: pi1
502type :: pti2
503 integer(is), pointer :: p(:,:) => null()
504end type pti2
505type(pti2) :: pi2
506type :: pti3
507 integer(is), pointer :: p(:,:,:) => null()
508end type pti3
509type(pti3) :: pi3
510type :: ptl0
511 integer(il), pointer :: p => null()
512end type ptl0
513type(ptl0) :: pl0
514type :: ptl1
515 integer(il), pointer :: p(:) => null()
516end type ptl1
517type(ptl1) :: pl1
518type :: ptl2
519 integer(il), pointer :: p(:,:) => null()
520end type ptl2
521type(ptl2) :: pl2
522type :: ptl3
523 integer(il), pointer :: p(:,:,:) => null()
524end type ptl3
525type(ptl3) :: pl3
526type :: ptcp0
527 type(c_ptr), pointer :: p => null()
528end type ptcp0
529type(ptcp0) :: pcp0
530type :: ptcp1
531 type(c_ptr), pointer :: p(:) => null()
532end type ptcp1
533type(ptcp1) :: pcp1
534type :: ptfp0
535 type(c_funptr), pointer :: p => null()
536end type ptfp0
537type(ptfp0) :: pfp0
538type :: ptfp1
539 type(c_funptr), pointer :: p(:) => null()
540end type ptfp1
541type(ptfp1) :: pfp1
542type :: pta_
543 type(pta__), pointer :: p(:) => null()
544end type pta_
545type :: pta__
546 character(len=1), pointer :: p => null()
547end type pta__
548type(pta_) :: pa_
549    integer :: i
550    ldealloc = .true.
551    if ( present(dealloc) ) ldealloc = dealloc
552    if ( ldealloc ) then
553if (this%t == 'a1') then
554  pa1 = transfer(this%enc,pa1)
555  deallocate(pa1%p)
556end if
557if (this%t == 's0') then
558  ps0 = transfer(this%enc,ps0)
559  deallocate(ps0%p)
560end if
561if (this%t == 's1') then
562  ps1 = transfer(this%enc,ps1)
563  deallocate(ps1%p)
564end if
565if (this%t == 's2') then
566  ps2 = transfer(this%enc,ps2)
567  deallocate(ps2%p)
568end if
569if (this%t == 's3') then
570  ps3 = transfer(this%enc,ps3)
571  deallocate(ps3%p)
572end if
573if (this%t == 'd0') then
574  pd0 = transfer(this%enc,pd0)
575  deallocate(pd0%p)
576end if
577if (this%t == 'd1') then
578  pd1 = transfer(this%enc,pd1)
579  deallocate(pd1%p)
580end if
581if (this%t == 'd2') then
582  pd2 = transfer(this%enc,pd2)
583  deallocate(pd2%p)
584end if
585if (this%t == 'd3') then
586  pd3 = transfer(this%enc,pd3)
587  deallocate(pd3%p)
588end if
589if (this%t == 'c0') then
590  pc0 = transfer(this%enc,pc0)
591  deallocate(pc0%p)
592end if
593if (this%t == 'c1') then
594  pc1 = transfer(this%enc,pc1)
595  deallocate(pc1%p)
596end if
597if (this%t == 'c2') then
598  pc2 = transfer(this%enc,pc2)
599  deallocate(pc2%p)
600end if
601if (this%t == 'c3') then
602  pc3 = transfer(this%enc,pc3)
603  deallocate(pc3%p)
604end if
605if (this%t == 'z0') then
606  pz0 = transfer(this%enc,pz0)
607  deallocate(pz0%p)
608end if
609if (this%t == 'z1') then
610  pz1 = transfer(this%enc,pz1)
611  deallocate(pz1%p)
612end if
613if (this%t == 'z2') then
614  pz2 = transfer(this%enc,pz2)
615  deallocate(pz2%p)
616end if
617if (this%t == 'z3') then
618  pz3 = transfer(this%enc,pz3)
619  deallocate(pz3%p)
620end if
621if (this%t == 'b0') then
622  pb0 = transfer(this%enc,pb0)
623  deallocate(pb0%p)
624end if
625if (this%t == 'b1') then
626  pb1 = transfer(this%enc,pb1)
627  deallocate(pb1%p)
628end if
629if (this%t == 'b2') then
630  pb2 = transfer(this%enc,pb2)
631  deallocate(pb2%p)
632end if
633if (this%t == 'b3') then
634  pb3 = transfer(this%enc,pb3)
635  deallocate(pb3%p)
636end if
637if (this%t == 'h0') then
638  ph0 = transfer(this%enc,ph0)
639  deallocate(ph0%p)
640end if
641if (this%t == 'h1') then
642  ph1 = transfer(this%enc,ph1)
643  deallocate(ph1%p)
644end if
645if (this%t == 'h2') then
646  ph2 = transfer(this%enc,ph2)
647  deallocate(ph2%p)
648end if
649if (this%t == 'h3') then
650  ph3 = transfer(this%enc,ph3)
651  deallocate(ph3%p)
652end if
653if (this%t == 'i0') then
654  pi0 = transfer(this%enc,pi0)
655  deallocate(pi0%p)
656end if
657if (this%t == 'i1') then
658  pi1 = transfer(this%enc,pi1)
659  deallocate(pi1%p)
660end if
661if (this%t == 'i2') then
662  pi2 = transfer(this%enc,pi2)
663  deallocate(pi2%p)
664end if
665if (this%t == 'i3') then
666  pi3 = transfer(this%enc,pi3)
667  deallocate(pi3%p)
668end if
669if (this%t == 'l0') then
670  pl0 = transfer(this%enc,pl0)
671  deallocate(pl0%p)
672end if
673if (this%t == 'l1') then
674  pl1 = transfer(this%enc,pl1)
675  deallocate(pl1%p)
676end if
677if (this%t == 'l2') then
678  pl2 = transfer(this%enc,pl2)
679  deallocate(pl2%p)
680end if
681if (this%t == 'l3') then
682  pl3 = transfer(this%enc,pl3)
683  deallocate(pl3%p)
684end if
685if (this%t == 'cp0') then
686  pcp0 = transfer(this%enc,pcp0)
687  deallocate(pcp0%p)
688end if
689if (this%t == 'cp1') then
690  pcp1 = transfer(this%enc,pcp1)
691  deallocate(pcp1%p)
692end if
693if (this%t == 'fp0') then
694  pfp0 = transfer(this%enc,pfp0)
695  deallocate(pfp0%p)
696end if
697if (this%t == 'fp1') then
698  pfp1 = transfer(this%enc,pfp1)
699  deallocate(pfp1%p)
700end if
701       if ( this%t == 'a-' ) then
702          pa_ = transfer(this%enc,pa_)
703          do i = 1 , size(pa_%p)
704             deallocate(pa_%p(i)%p)
705          end do
706          deallocate(pa_%p)
707       end if
708    end if
709    call nullify(this)
710  end subroutine delete_
711  elemental subroutine nullify_(this)
712    type(variable_t), intent(inout) :: this
713    this%t = '  '
714    if ( allocated(this%enc) ) deallocate(this%enc)
715  end subroutine nullify_
716  ! Returns the bare encoding of this variable
717  ! This can ease the process of assigning
718  ! user-types to a variable.
719  ! An encoding might be 2, or 10000000 bytes big.
720  ! Therefore we use a subroutine to determine
721  ! the size of the returning encoding characters.
722  ! If the size of the returning enc is not
723  ! big enough it will be reset to ' '
724  subroutine enc_(this,enc)
725    type(variable_t), intent(in) :: this
726    character(len=1), intent(out) :: enc(:)
727    integer :: i
728    if ( this%t == '  ' ) then
729       enc = ' '
730    else
731       ! We do have an encoding
732       i = size(this%enc)
733       if ( i > size(enc) ) then
734          enc = ' '
735       else
736          enc(1:i) = this%enc
737       end if
738    end if
739  end subroutine enc_
740  function size_enc_(this) result(len)
741    type(variable_t), intent(in) :: this
742    integer :: len
743    if ( this%t == '  ' ) then
744       len = 0
745    else
746       len = size(this%enc)
747    end if
748  end function size_enc_
749  ! We allow the user to pass an encoding field.
750  ! As this is the same as passing a char
751  ! we MUST use a specific routine for this.
752  ! One _could_, in principle, add an optional
753  ! logical flag for the assign_set_a_, however
754  ! one cannot assign a type by passing a reference
755  ! and hence we ONLY allow associate_type
756  ! This also means that any de-allocation of variables
757  ! containing an external type will only de-reference it.
758  ! A bit counter-intuitive, yet the variable type needs
759  ! all information about the type to successfully de-allocate it.
760  ! It is ALSO very important that the user
761  ! passed the full-encoding WITHOUT padding of ' '.
762  ! We cannot know for sure whether the encoding actually terminates
763  ! in a bit corresponding to char(' ')!
764  subroutine associate_type_(this,enc,dealloc)
765    type(variable_t), intent(inout) :: this
766    character(len=1), intent(in) :: enc(:)
767    logical, intent(in), optional :: dealloc
768    logical :: ldealloc
769    ldealloc = .false.
770    if(present(dealloc))ldealloc = dealloc
771    if (.not. ldealloc) then
772       ! if we do not deallocate, nullify
773       call nullify(this)
774    else
775       call delete(this)
776    end if
777    this%t = 'USER'
778    allocate(this%enc(size(enc)))
779    this%enc(:) = enc(:)
780  end subroutine associate_type_
781  pure function cpack_(c) result(car)
782    character(len=*), intent(in) :: c
783    character(len=1) :: car(len(c))
784    integer :: i
785    do i = 1 , len(c)
786       car(i) = c(i:i)
787    end do
788  end function cpack_
789  pure function cunpack_(car) result(c)
790    character(len=1), intent(in) :: car(:)
791    character(len=size(car)) :: c
792    integer :: i
793    do i = 1 , size(car)
794       c(i:i) = car(i)
795    end do
796  end function cunpack_
797  subroutine assignment_(this,rhs)
798    type(variable_t), intent(inout) :: this
799    type(variable_t), intent(in) :: rhs
800    call assign(this,rhs)
801  end subroutine assignment_
802  subroutine assign_var(this,rhs,dealloc)
803    type(variable_t), intent(inout) :: this
804    type(variable_t), intent(in) :: rhs
805    logical, intent(in), optional :: dealloc
806    logical :: ldealloc
807    integer :: i
808type :: pta1
809 character(len=1), pointer :: p(:) => null()
810end type pta1
811type(pta1) :: pa1_1, pa1_2
812type :: pts0
813 real(sp), pointer :: p => null()
814end type pts0
815type(pts0) :: ps0_1, ps0_2
816type :: pts1
817 real(sp), pointer :: p(:) => null()
818end type pts1
819type(pts1) :: ps1_1, ps1_2
820type :: pts2
821 real(sp), pointer :: p(:,:) => null()
822end type pts2
823type(pts2) :: ps2_1, ps2_2
824type :: pts3
825 real(sp), pointer :: p(:,:,:) => null()
826end type pts3
827type(pts3) :: ps3_1, ps3_2
828type :: ptd0
829 real(dp), pointer :: p => null()
830end type ptd0
831type(ptd0) :: pd0_1, pd0_2
832type :: ptd1
833 real(dp), pointer :: p(:) => null()
834end type ptd1
835type(ptd1) :: pd1_1, pd1_2
836type :: ptd2
837 real(dp), pointer :: p(:,:) => null()
838end type ptd2
839type(ptd2) :: pd2_1, pd2_2
840type :: ptd3
841 real(dp), pointer :: p(:,:,:) => null()
842end type ptd3
843type(ptd3) :: pd3_1, pd3_2
844type :: ptc0
845 complex(sp), pointer :: p => null()
846end type ptc0
847type(ptc0) :: pc0_1, pc0_2
848type :: ptc1
849 complex(sp), pointer :: p(:) => null()
850end type ptc1
851type(ptc1) :: pc1_1, pc1_2
852type :: ptc2
853 complex(sp), pointer :: p(:,:) => null()
854end type ptc2
855type(ptc2) :: pc2_1, pc2_2
856type :: ptc3
857 complex(sp), pointer :: p(:,:,:) => null()
858end type ptc3
859type(ptc3) :: pc3_1, pc3_2
860type :: ptz0
861 complex(dp), pointer :: p => null()
862end type ptz0
863type(ptz0) :: pz0_1, pz0_2
864type :: ptz1
865 complex(dp), pointer :: p(:) => null()
866end type ptz1
867type(ptz1) :: pz1_1, pz1_2
868type :: ptz2
869 complex(dp), pointer :: p(:,:) => null()
870end type ptz2
871type(ptz2) :: pz2_1, pz2_2
872type :: ptz3
873 complex(dp), pointer :: p(:,:,:) => null()
874end type ptz3
875type(ptz3) :: pz3_1, pz3_2
876type :: ptb0
877 logical, pointer :: p => null()
878end type ptb0
879type(ptb0) :: pb0_1, pb0_2
880type :: ptb1
881 logical, pointer :: p(:) => null()
882end type ptb1
883type(ptb1) :: pb1_1, pb1_2
884type :: ptb2
885 logical, pointer :: p(:,:) => null()
886end type ptb2
887type(ptb2) :: pb2_1, pb2_2
888type :: ptb3
889 logical, pointer :: p(:,:,:) => null()
890end type ptb3
891type(ptb3) :: pb3_1, pb3_2
892type :: pth0
893 integer(ih), pointer :: p => null()
894end type pth0
895type(pth0) :: ph0_1, ph0_2
896type :: pth1
897 integer(ih), pointer :: p(:) => null()
898end type pth1
899type(pth1) :: ph1_1, ph1_2
900type :: pth2
901 integer(ih), pointer :: p(:,:) => null()
902end type pth2
903type(pth2) :: ph2_1, ph2_2
904type :: pth3
905 integer(ih), pointer :: p(:,:,:) => null()
906end type pth3
907type(pth3) :: ph3_1, ph3_2
908type :: pti0
909 integer(is), pointer :: p => null()
910end type pti0
911type(pti0) :: pi0_1, pi0_2
912type :: pti1
913 integer(is), pointer :: p(:) => null()
914end type pti1
915type(pti1) :: pi1_1, pi1_2
916type :: pti2
917 integer(is), pointer :: p(:,:) => null()
918end type pti2
919type(pti2) :: pi2_1, pi2_2
920type :: pti3
921 integer(is), pointer :: p(:,:,:) => null()
922end type pti3
923type(pti3) :: pi3_1, pi3_2
924type :: ptl0
925 integer(il), pointer :: p => null()
926end type ptl0
927type(ptl0) :: pl0_1, pl0_2
928type :: ptl1
929 integer(il), pointer :: p(:) => null()
930end type ptl1
931type(ptl1) :: pl1_1, pl1_2
932type :: ptl2
933 integer(il), pointer :: p(:,:) => null()
934end type ptl2
935type(ptl2) :: pl2_1, pl2_2
936type :: ptl3
937 integer(il), pointer :: p(:,:,:) => null()
938end type ptl3
939type(ptl3) :: pl3_1, pl3_2
940type :: ptcp0
941 type(c_ptr), pointer :: p => null()
942end type ptcp0
943type(ptcp0) :: pcp0_1, pcp0_2
944type :: ptcp1
945 type(c_ptr), pointer :: p(:) => null()
946end type ptcp1
947type(ptcp1) :: pcp1_1, pcp1_2
948type :: ptfp0
949 type(c_funptr), pointer :: p => null()
950end type ptfp0
951type(ptfp0) :: pfp0_1, pfp0_2
952type :: ptfp1
953 type(c_funptr), pointer :: p(:) => null()
954end type ptfp1
955type(ptfp1) :: pfp1_1, pfp1_2
956type :: pta_
957 type(pta__), pointer :: p(:) => null()
958end type pta_
959type :: pta__
960 character(len=1), pointer :: p => null()
961end type pta__
962type(pta_) :: pa__1, pa__2
963    ! collect deallocation option (default as =)
964    ! ASSIGNMENT in fortran is per default destructive
965    ldealloc = .true.
966    if(present(dealloc))ldealloc = dealloc
967    if (.not. ldealloc) then
968       ! if we do not deallocate, nullify
969       call nullify(this)
970    else
971       call delete(this)
972    end if
973    this%t = rhs%t
974    ! First allocate the LHS
975if ( this%t == 'a1' ) then
976pa1_2 = transfer(rhs%enc,pa1_2)
977allocate(pa1_1%p(size(pa1_2%p)))
978endif
979if ( this%t == 's0' ) then
980ps0_2 = transfer(rhs%enc,ps0_2)
981allocate(ps0_1%p)
982elseif ( this%t == 's1' ) then
983ps1_2 = transfer(rhs%enc,ps1_2)
984allocate(ps1_1%p(size(ps1_2%p)))
985elseif ( this%t == 's2' ) then
986ps2_2 = transfer(rhs%enc,ps2_2)
987allocate(ps2_1%p(size(ps2_2%p,1),size(ps2_2%p,2)))
988elseif ( this%t == 's3' ) then
989ps3_2 = transfer(rhs%enc,ps3_2)
990allocate(ps3_1%p(size(ps3_2%p,1),size(ps3_2%p,2),size(ps3_2%p,3)))
991endif
992if ( this%t == 'd0' ) then
993pd0_2 = transfer(rhs%enc,pd0_2)
994allocate(pd0_1%p)
995elseif ( this%t == 'd1' ) then
996pd1_2 = transfer(rhs%enc,pd1_2)
997allocate(pd1_1%p(size(pd1_2%p)))
998elseif ( this%t == 'd2' ) then
999pd2_2 = transfer(rhs%enc,pd2_2)
1000allocate(pd2_1%p(size(pd2_2%p,1),size(pd2_2%p,2)))
1001elseif ( this%t == 'd3' ) then
1002pd3_2 = transfer(rhs%enc,pd3_2)
1003allocate(pd3_1%p(size(pd3_2%p,1),size(pd3_2%p,2),size(pd3_2%p,3)))
1004endif
1005if ( this%t == 'c0' ) then
1006pc0_2 = transfer(rhs%enc,pc0_2)
1007allocate(pc0_1%p)
1008elseif ( this%t == 'c1' ) then
1009pc1_2 = transfer(rhs%enc,pc1_2)
1010allocate(pc1_1%p(size(pc1_2%p)))
1011elseif ( this%t == 'c2' ) then
1012pc2_2 = transfer(rhs%enc,pc2_2)
1013allocate(pc2_1%p(size(pc2_2%p,1),size(pc2_2%p,2)))
1014elseif ( this%t == 'c3' ) then
1015pc3_2 = transfer(rhs%enc,pc3_2)
1016allocate(pc3_1%p(size(pc3_2%p,1),size(pc3_2%p,2),size(pc3_2%p,3)))
1017endif
1018if ( this%t == 'z0' ) then
1019pz0_2 = transfer(rhs%enc,pz0_2)
1020allocate(pz0_1%p)
1021elseif ( this%t == 'z1' ) then
1022pz1_2 = transfer(rhs%enc,pz1_2)
1023allocate(pz1_1%p(size(pz1_2%p)))
1024elseif ( this%t == 'z2' ) then
1025pz2_2 = transfer(rhs%enc,pz2_2)
1026allocate(pz2_1%p(size(pz2_2%p,1),size(pz2_2%p,2)))
1027elseif ( this%t == 'z3' ) then
1028pz3_2 = transfer(rhs%enc,pz3_2)
1029allocate(pz3_1%p(size(pz3_2%p,1),size(pz3_2%p,2),size(pz3_2%p,3)))
1030endif
1031if ( this%t == 'b0' ) then
1032pb0_2 = transfer(rhs%enc,pb0_2)
1033allocate(pb0_1%p)
1034elseif ( this%t == 'b1' ) then
1035pb1_2 = transfer(rhs%enc,pb1_2)
1036allocate(pb1_1%p(size(pb1_2%p)))
1037elseif ( this%t == 'b2' ) then
1038pb2_2 = transfer(rhs%enc,pb2_2)
1039allocate(pb2_1%p(size(pb2_2%p,1),size(pb2_2%p,2)))
1040elseif ( this%t == 'b3' ) then
1041pb3_2 = transfer(rhs%enc,pb3_2)
1042allocate(pb3_1%p(size(pb3_2%p,1),size(pb3_2%p,2),size(pb3_2%p,3)))
1043endif
1044if ( this%t == 'h0' ) then
1045ph0_2 = transfer(rhs%enc,ph0_2)
1046allocate(ph0_1%p)
1047elseif ( this%t == 'h1' ) then
1048ph1_2 = transfer(rhs%enc,ph1_2)
1049allocate(ph1_1%p(size(ph1_2%p)))
1050elseif ( this%t == 'h2' ) then
1051ph2_2 = transfer(rhs%enc,ph2_2)
1052allocate(ph2_1%p(size(ph2_2%p,1),size(ph2_2%p,2)))
1053elseif ( this%t == 'h3' ) then
1054ph3_2 = transfer(rhs%enc,ph3_2)
1055allocate(ph3_1%p(size(ph3_2%p,1),size(ph3_2%p,2),size(ph3_2%p,3)))
1056endif
1057if ( this%t == 'i0' ) then
1058pi0_2 = transfer(rhs%enc,pi0_2)
1059allocate(pi0_1%p)
1060elseif ( this%t == 'i1' ) then
1061pi1_2 = transfer(rhs%enc,pi1_2)
1062allocate(pi1_1%p(size(pi1_2%p)))
1063elseif ( this%t == 'i2' ) then
1064pi2_2 = transfer(rhs%enc,pi2_2)
1065allocate(pi2_1%p(size(pi2_2%p,1),size(pi2_2%p,2)))
1066elseif ( this%t == 'i3' ) then
1067pi3_2 = transfer(rhs%enc,pi3_2)
1068allocate(pi3_1%p(size(pi3_2%p,1),size(pi3_2%p,2),size(pi3_2%p,3)))
1069endif
1070if ( this%t == 'l0' ) then
1071pl0_2 = transfer(rhs%enc,pl0_2)
1072allocate(pl0_1%p)
1073elseif ( this%t == 'l1' ) then
1074pl1_2 = transfer(rhs%enc,pl1_2)
1075allocate(pl1_1%p(size(pl1_2%p)))
1076elseif ( this%t == 'l2' ) then
1077pl2_2 = transfer(rhs%enc,pl2_2)
1078allocate(pl2_1%p(size(pl2_2%p,1),size(pl2_2%p,2)))
1079elseif ( this%t == 'l3' ) then
1080pl3_2 = transfer(rhs%enc,pl3_2)
1081allocate(pl3_1%p(size(pl3_2%p,1),size(pl3_2%p,2),size(pl3_2%p,3)))
1082endif
1083if ( this%t == 'cp0' ) then
1084pcp0_2 = transfer(rhs%enc,pcp0_2)
1085allocate(pcp0_1%p)
1086elseif ( this%t == 'cp1' ) then
1087pcp1_2 = transfer(rhs%enc,pcp1_2)
1088allocate(pcp1_1%p(size(pcp1_2%p)))
1089endif
1090if ( this%t == 'fp0' ) then
1091pfp0_2 = transfer(rhs%enc,pfp0_2)
1092allocate(pfp0_1%p)
1093elseif ( this%t == 'fp1' ) then
1094pfp1_2 = transfer(rhs%enc,pfp1_2)
1095allocate(pfp1_1%p(size(pfp1_2%p)))
1096endif
1097    if ( this%t == 'a-' ) then ! character(len=*)
1098       pa__2 = transfer(rhs%enc, pa__2)
1099       allocate(pa__1%p(size(pa__2%p)))
1100       do i = 1 , size(pa__2%p)
1101          allocate(pa__1%p(i)%p)
1102          pa__1%p(i)%p = pa__2%p(i)%p
1103       end do
1104       allocate(this%enc(size(transfer(pa__1, local_enc_type))))
1105       this%enc(:) = transfer(pa__1, local_enc_type)
1106       do i = 1 , size(pa__1%p)
1107         nullify(pa__1%p(i)%p)
1108       end do
1109       nullify(pa__1%p)
1110    end if
1111    ! copy over RHS and Save encoding
1112if ( this%t == 'a1' ) then
1113pa1_1%p = pa1_2%p
1114allocate(this%enc(size(transfer(pa1_1, local_enc_type))))
1115this%enc(:) = transfer(pa1_1, local_enc_type)
1116nullify(pa1_1%p)
1117endif
1118if ( this%t == 's0' ) then
1119ps0_1%p = ps0_2%p
1120allocate(this%enc(size(transfer(ps0_1, local_enc_type))))
1121this%enc(:) = transfer(ps0_1, local_enc_type)
1122nullify(ps0_1%p)
1123elseif ( this%t == 's1' ) then
1124ps1_1%p = ps1_2%p
1125allocate(this%enc(size(transfer(ps1_1, local_enc_type))))
1126this%enc(:) = transfer(ps1_1, local_enc_type)
1127nullify(ps1_1%p)
1128elseif ( this%t == 's2' ) then
1129ps2_1%p = ps2_2%p
1130allocate(this%enc(size(transfer(ps2_1, local_enc_type))))
1131this%enc(:) = transfer(ps2_1, local_enc_type)
1132nullify(ps2_1%p)
1133elseif ( this%t == 's3' ) then
1134ps3_1%p = ps3_2%p
1135allocate(this%enc(size(transfer(ps3_1, local_enc_type))))
1136this%enc(:) = transfer(ps3_1, local_enc_type)
1137nullify(ps3_1%p)
1138endif
1139if ( this%t == 'd0' ) then
1140pd0_1%p = pd0_2%p
1141allocate(this%enc(size(transfer(pd0_1, local_enc_type))))
1142this%enc(:) = transfer(pd0_1, local_enc_type)
1143nullify(pd0_1%p)
1144elseif ( this%t == 'd1' ) then
1145pd1_1%p = pd1_2%p
1146allocate(this%enc(size(transfer(pd1_1, local_enc_type))))
1147this%enc(:) = transfer(pd1_1, local_enc_type)
1148nullify(pd1_1%p)
1149elseif ( this%t == 'd2' ) then
1150pd2_1%p = pd2_2%p
1151allocate(this%enc(size(transfer(pd2_1, local_enc_type))))
1152this%enc(:) = transfer(pd2_1, local_enc_type)
1153nullify(pd2_1%p)
1154elseif ( this%t == 'd3' ) then
1155pd3_1%p = pd3_2%p
1156allocate(this%enc(size(transfer(pd3_1, local_enc_type))))
1157this%enc(:) = transfer(pd3_1, local_enc_type)
1158nullify(pd3_1%p)
1159endif
1160if ( this%t == 'c0' ) then
1161pc0_1%p = pc0_2%p
1162allocate(this%enc(size(transfer(pc0_1, local_enc_type))))
1163this%enc(:) = transfer(pc0_1, local_enc_type)
1164nullify(pc0_1%p)
1165elseif ( this%t == 'c1' ) then
1166pc1_1%p = pc1_2%p
1167allocate(this%enc(size(transfer(pc1_1, local_enc_type))))
1168this%enc(:) = transfer(pc1_1, local_enc_type)
1169nullify(pc1_1%p)
1170elseif ( this%t == 'c2' ) then
1171pc2_1%p = pc2_2%p
1172allocate(this%enc(size(transfer(pc2_1, local_enc_type))))
1173this%enc(:) = transfer(pc2_1, local_enc_type)
1174nullify(pc2_1%p)
1175elseif ( this%t == 'c3' ) then
1176pc3_1%p = pc3_2%p
1177allocate(this%enc(size(transfer(pc3_1, local_enc_type))))
1178this%enc(:) = transfer(pc3_1, local_enc_type)
1179nullify(pc3_1%p)
1180endif
1181if ( this%t == 'z0' ) then
1182pz0_1%p = pz0_2%p
1183allocate(this%enc(size(transfer(pz0_1, local_enc_type))))
1184this%enc(:) = transfer(pz0_1, local_enc_type)
1185nullify(pz0_1%p)
1186elseif ( this%t == 'z1' ) then
1187pz1_1%p = pz1_2%p
1188allocate(this%enc(size(transfer(pz1_1, local_enc_type))))
1189this%enc(:) = transfer(pz1_1, local_enc_type)
1190nullify(pz1_1%p)
1191elseif ( this%t == 'z2' ) then
1192pz2_1%p = pz2_2%p
1193allocate(this%enc(size(transfer(pz2_1, local_enc_type))))
1194this%enc(:) = transfer(pz2_1, local_enc_type)
1195nullify(pz2_1%p)
1196elseif ( this%t == 'z3' ) then
1197pz3_1%p = pz3_2%p
1198allocate(this%enc(size(transfer(pz3_1, local_enc_type))))
1199this%enc(:) = transfer(pz3_1, local_enc_type)
1200nullify(pz3_1%p)
1201endif
1202if ( this%t == 'b0' ) then
1203pb0_1%p = pb0_2%p
1204allocate(this%enc(size(transfer(pb0_1, local_enc_type))))
1205this%enc(:) = transfer(pb0_1, local_enc_type)
1206nullify(pb0_1%p)
1207elseif ( this%t == 'b1' ) then
1208pb1_1%p = pb1_2%p
1209allocate(this%enc(size(transfer(pb1_1, local_enc_type))))
1210this%enc(:) = transfer(pb1_1, local_enc_type)
1211nullify(pb1_1%p)
1212elseif ( this%t == 'b2' ) then
1213pb2_1%p = pb2_2%p
1214allocate(this%enc(size(transfer(pb2_1, local_enc_type))))
1215this%enc(:) = transfer(pb2_1, local_enc_type)
1216nullify(pb2_1%p)
1217elseif ( this%t == 'b3' ) then
1218pb3_1%p = pb3_2%p
1219allocate(this%enc(size(transfer(pb3_1, local_enc_type))))
1220this%enc(:) = transfer(pb3_1, local_enc_type)
1221nullify(pb3_1%p)
1222endif
1223if ( this%t == 'h0' ) then
1224ph0_1%p = ph0_2%p
1225allocate(this%enc(size(transfer(ph0_1, local_enc_type))))
1226this%enc(:) = transfer(ph0_1, local_enc_type)
1227nullify(ph0_1%p)
1228elseif ( this%t == 'h1' ) then
1229ph1_1%p = ph1_2%p
1230allocate(this%enc(size(transfer(ph1_1, local_enc_type))))
1231this%enc(:) = transfer(ph1_1, local_enc_type)
1232nullify(ph1_1%p)
1233elseif ( this%t == 'h2' ) then
1234ph2_1%p = ph2_2%p
1235allocate(this%enc(size(transfer(ph2_1, local_enc_type))))
1236this%enc(:) = transfer(ph2_1, local_enc_type)
1237nullify(ph2_1%p)
1238elseif ( this%t == 'h3' ) then
1239ph3_1%p = ph3_2%p
1240allocate(this%enc(size(transfer(ph3_1, local_enc_type))))
1241this%enc(:) = transfer(ph3_1, local_enc_type)
1242nullify(ph3_1%p)
1243endif
1244if ( this%t == 'i0' ) then
1245pi0_1%p = pi0_2%p
1246allocate(this%enc(size(transfer(pi0_1, local_enc_type))))
1247this%enc(:) = transfer(pi0_1, local_enc_type)
1248nullify(pi0_1%p)
1249elseif ( this%t == 'i1' ) then
1250pi1_1%p = pi1_2%p
1251allocate(this%enc(size(transfer(pi1_1, local_enc_type))))
1252this%enc(:) = transfer(pi1_1, local_enc_type)
1253nullify(pi1_1%p)
1254elseif ( this%t == 'i2' ) then
1255pi2_1%p = pi2_2%p
1256allocate(this%enc(size(transfer(pi2_1, local_enc_type))))
1257this%enc(:) = transfer(pi2_1, local_enc_type)
1258nullify(pi2_1%p)
1259elseif ( this%t == 'i3' ) then
1260pi3_1%p = pi3_2%p
1261allocate(this%enc(size(transfer(pi3_1, local_enc_type))))
1262this%enc(:) = transfer(pi3_1, local_enc_type)
1263nullify(pi3_1%p)
1264endif
1265if ( this%t == 'l0' ) then
1266pl0_1%p = pl0_2%p
1267allocate(this%enc(size(transfer(pl0_1, local_enc_type))))
1268this%enc(:) = transfer(pl0_1, local_enc_type)
1269nullify(pl0_1%p)
1270elseif ( this%t == 'l1' ) then
1271pl1_1%p = pl1_2%p
1272allocate(this%enc(size(transfer(pl1_1, local_enc_type))))
1273this%enc(:) = transfer(pl1_1, local_enc_type)
1274nullify(pl1_1%p)
1275elseif ( this%t == 'l2' ) then
1276pl2_1%p = pl2_2%p
1277allocate(this%enc(size(transfer(pl2_1, local_enc_type))))
1278this%enc(:) = transfer(pl2_1, local_enc_type)
1279nullify(pl2_1%p)
1280elseif ( this%t == 'l3' ) then
1281pl3_1%p = pl3_2%p
1282allocate(this%enc(size(transfer(pl3_1, local_enc_type))))
1283this%enc(:) = transfer(pl3_1, local_enc_type)
1284nullify(pl3_1%p)
1285endif
1286if ( this%t == 'cp0' ) then
1287pcp0_1%p = pcp0_2%p
1288allocate(this%enc(size(transfer(pcp0_1, local_enc_type))))
1289this%enc(:) = transfer(pcp0_1, local_enc_type)
1290nullify(pcp0_1%p)
1291elseif ( this%t == 'cp1' ) then
1292pcp1_1%p = pcp1_2%p
1293allocate(this%enc(size(transfer(pcp1_1, local_enc_type))))
1294this%enc(:) = transfer(pcp1_1, local_enc_type)
1295nullify(pcp1_1%p)
1296endif
1297if ( this%t == 'fp0' ) then
1298pfp0_1%p = pfp0_2%p
1299allocate(this%enc(size(transfer(pfp0_1, local_enc_type))))
1300this%enc(:) = transfer(pfp0_1, local_enc_type)
1301nullify(pfp0_1%p)
1302elseif ( this%t == 'fp1' ) then
1303pfp1_1%p = pfp1_2%p
1304allocate(this%enc(size(transfer(pfp1_1, local_enc_type))))
1305this%enc(:) = transfer(pfp1_1, local_enc_type)
1306nullify(pfp1_1%p)
1307endif
1308if ( this%t == 'USER' ) then
1309write(*,'(a)') 'var: Cannot assign a UT, USE call associate(..)'
1310end if
1311  end subroutine assign_var
1312  subroutine associate_var(this,rhs,dealloc,success)
1313    type(variable_t), intent(inout) :: this
1314    type(variable_t), intent(in) :: rhs
1315    logical, intent(in), optional :: dealloc
1316    logical, intent(out), optional :: success
1317    logical :: ldealloc
1318    ! collect deallocation option (default as =)
1319    ! ASSOCIATION in fortran is per default non-destructive
1320    ldealloc = .false.
1321    if ( present(success) ) success = .true.
1322    if ( present(dealloc) ) ldealloc = dealloc
1323    if (.not. ldealloc) then
1324       ! if we do not deallocate, nullify
1325       call nullify(this)
1326    else
1327       call delete(this)
1328    end if
1329    ! Association is done by copying the encoding
1330    this%t = rhs%t
1331    allocate(this%enc(size(rhs%enc)))
1332    this%enc(:) = rhs%enc(:)
1333  end subroutine associate_var
1334  pure function associatd_var(this,rhs) result(ret)
1335    type(variable_t), intent(in) :: this
1336    type(variable_t), intent(in) :: rhs
1337    logical :: ret
1338type :: pta1
1339 character(len=1), pointer :: p(:) => null()
1340end type pta1
1341type(pta1) :: pa1_1, pa1_2
1342type :: pts0
1343 real(sp), pointer :: p => null()
1344end type pts0
1345type(pts0) :: ps0_1, ps0_2
1346type :: pts1
1347 real(sp), pointer :: p(:) => null()
1348end type pts1
1349type(pts1) :: ps1_1, ps1_2
1350type :: pts2
1351 real(sp), pointer :: p(:,:) => null()
1352end type pts2
1353type(pts2) :: ps2_1, ps2_2
1354type :: pts3
1355 real(sp), pointer :: p(:,:,:) => null()
1356end type pts3
1357type(pts3) :: ps3_1, ps3_2
1358type :: ptd0
1359 real(dp), pointer :: p => null()
1360end type ptd0
1361type(ptd0) :: pd0_1, pd0_2
1362type :: ptd1
1363 real(dp), pointer :: p(:) => null()
1364end type ptd1
1365type(ptd1) :: pd1_1, pd1_2
1366type :: ptd2
1367 real(dp), pointer :: p(:,:) => null()
1368end type ptd2
1369type(ptd2) :: pd2_1, pd2_2
1370type :: ptd3
1371 real(dp), pointer :: p(:,:,:) => null()
1372end type ptd3
1373type(ptd3) :: pd3_1, pd3_2
1374type :: ptc0
1375 complex(sp), pointer :: p => null()
1376end type ptc0
1377type(ptc0) :: pc0_1, pc0_2
1378type :: ptc1
1379 complex(sp), pointer :: p(:) => null()
1380end type ptc1
1381type(ptc1) :: pc1_1, pc1_2
1382type :: ptc2
1383 complex(sp), pointer :: p(:,:) => null()
1384end type ptc2
1385type(ptc2) :: pc2_1, pc2_2
1386type :: ptc3
1387 complex(sp), pointer :: p(:,:,:) => null()
1388end type ptc3
1389type(ptc3) :: pc3_1, pc3_2
1390type :: ptz0
1391 complex(dp), pointer :: p => null()
1392end type ptz0
1393type(ptz0) :: pz0_1, pz0_2
1394type :: ptz1
1395 complex(dp), pointer :: p(:) => null()
1396end type ptz1
1397type(ptz1) :: pz1_1, pz1_2
1398type :: ptz2
1399 complex(dp), pointer :: p(:,:) => null()
1400end type ptz2
1401type(ptz2) :: pz2_1, pz2_2
1402type :: ptz3
1403 complex(dp), pointer :: p(:,:,:) => null()
1404end type ptz3
1405type(ptz3) :: pz3_1, pz3_2
1406type :: ptb0
1407 logical, pointer :: p => null()
1408end type ptb0
1409type(ptb0) :: pb0_1, pb0_2
1410type :: ptb1
1411 logical, pointer :: p(:) => null()
1412end type ptb1
1413type(ptb1) :: pb1_1, pb1_2
1414type :: ptb2
1415 logical, pointer :: p(:,:) => null()
1416end type ptb2
1417type(ptb2) :: pb2_1, pb2_2
1418type :: ptb3
1419 logical, pointer :: p(:,:,:) => null()
1420end type ptb3
1421type(ptb3) :: pb3_1, pb3_2
1422type :: pth0
1423 integer(ih), pointer :: p => null()
1424end type pth0
1425type(pth0) :: ph0_1, ph0_2
1426type :: pth1
1427 integer(ih), pointer :: p(:) => null()
1428end type pth1
1429type(pth1) :: ph1_1, ph1_2
1430type :: pth2
1431 integer(ih), pointer :: p(:,:) => null()
1432end type pth2
1433type(pth2) :: ph2_1, ph2_2
1434type :: pth3
1435 integer(ih), pointer :: p(:,:,:) => null()
1436end type pth3
1437type(pth3) :: ph3_1, ph3_2
1438type :: pti0
1439 integer(is), pointer :: p => null()
1440end type pti0
1441type(pti0) :: pi0_1, pi0_2
1442type :: pti1
1443 integer(is), pointer :: p(:) => null()
1444end type pti1
1445type(pti1) :: pi1_1, pi1_2
1446type :: pti2
1447 integer(is), pointer :: p(:,:) => null()
1448end type pti2
1449type(pti2) :: pi2_1, pi2_2
1450type :: pti3
1451 integer(is), pointer :: p(:,:,:) => null()
1452end type pti3
1453type(pti3) :: pi3_1, pi3_2
1454type :: ptl0
1455 integer(il), pointer :: p => null()
1456end type ptl0
1457type(ptl0) :: pl0_1, pl0_2
1458type :: ptl1
1459 integer(il), pointer :: p(:) => null()
1460end type ptl1
1461type(ptl1) :: pl1_1, pl1_2
1462type :: ptl2
1463 integer(il), pointer :: p(:,:) => null()
1464end type ptl2
1465type(ptl2) :: pl2_1, pl2_2
1466type :: ptl3
1467 integer(il), pointer :: p(:,:,:) => null()
1468end type ptl3
1469type(ptl3) :: pl3_1, pl3_2
1470type :: ptcp0
1471 type(c_ptr), pointer :: p => null()
1472end type ptcp0
1473type(ptcp0) :: pcp0_1, pcp0_2
1474type :: ptcp1
1475 type(c_ptr), pointer :: p(:) => null()
1476end type ptcp1
1477type(ptcp1) :: pcp1_1, pcp1_2
1478type :: ptfp0
1479 type(c_funptr), pointer :: p => null()
1480end type ptfp0
1481type(ptfp0) :: pfp0_1, pfp0_2
1482type :: ptfp1
1483 type(c_funptr), pointer :: p(:) => null()
1484end type ptfp1
1485type(ptfp1) :: pfp1_1, pfp1_2
1486type :: pta_
1487 type(pta__), pointer :: p(:) => null()
1488end type pta_
1489type :: pta__
1490 character(len=1), pointer :: p => null()
1491end type pta__
1492type(pta_) :: pa__1, pa__2
1493    ret = this%t==rhs%t
1494    if ( .not. ret ) return
1495if ( this%t == 'a1' ) then
1496pa1_1 = transfer(this%enc,pa1_1)
1497pa1_2 = transfer(rhs%enc,pa1_2)
1498ret = associated(pa1_1%p,pa1_2%p)
1499endif
1500if ( this%t == 's0' ) then
1501ps0_1 = transfer(this%enc,ps0_1)
1502ps0_2 = transfer(rhs%enc,ps0_2)
1503ret = associated(ps0_1%p,ps0_2%p)
1504elseif ( this%t == 's1' ) then
1505ps1_1 = transfer(this%enc,ps1_1)
1506ps1_2 = transfer(rhs%enc,ps1_2)
1507ret = associated(ps1_1%p,ps1_2%p)
1508elseif ( this%t == 's2' ) then
1509ps2_1 = transfer(this%enc,ps2_1)
1510ps2_2 = transfer(rhs%enc,ps2_2)
1511ret = associated(ps2_1%p,ps2_2%p)
1512elseif ( this%t == 's3' ) then
1513ps3_1 = transfer(this%enc,ps3_1)
1514ps3_2 = transfer(rhs%enc,ps3_2)
1515ret = associated(ps3_1%p,ps3_2%p)
1516endif
1517if ( this%t == 'd0' ) then
1518pd0_1 = transfer(this%enc,pd0_1)
1519pd0_2 = transfer(rhs%enc,pd0_2)
1520ret = associated(pd0_1%p,pd0_2%p)
1521elseif ( this%t == 'd1' ) then
1522pd1_1 = transfer(this%enc,pd1_1)
1523pd1_2 = transfer(rhs%enc,pd1_2)
1524ret = associated(pd1_1%p,pd1_2%p)
1525elseif ( this%t == 'd2' ) then
1526pd2_1 = transfer(this%enc,pd2_1)
1527pd2_2 = transfer(rhs%enc,pd2_2)
1528ret = associated(pd2_1%p,pd2_2%p)
1529elseif ( this%t == 'd3' ) then
1530pd3_1 = transfer(this%enc,pd3_1)
1531pd3_2 = transfer(rhs%enc,pd3_2)
1532ret = associated(pd3_1%p,pd3_2%p)
1533endif
1534if ( this%t == 'c0' ) then
1535pc0_1 = transfer(this%enc,pc0_1)
1536pc0_2 = transfer(rhs%enc,pc0_2)
1537ret = associated(pc0_1%p,pc0_2%p)
1538elseif ( this%t == 'c1' ) then
1539pc1_1 = transfer(this%enc,pc1_1)
1540pc1_2 = transfer(rhs%enc,pc1_2)
1541ret = associated(pc1_1%p,pc1_2%p)
1542elseif ( this%t == 'c2' ) then
1543pc2_1 = transfer(this%enc,pc2_1)
1544pc2_2 = transfer(rhs%enc,pc2_2)
1545ret = associated(pc2_1%p,pc2_2%p)
1546elseif ( this%t == 'c3' ) then
1547pc3_1 = transfer(this%enc,pc3_1)
1548pc3_2 = transfer(rhs%enc,pc3_2)
1549ret = associated(pc3_1%p,pc3_2%p)
1550endif
1551if ( this%t == 'z0' ) then
1552pz0_1 = transfer(this%enc,pz0_1)
1553pz0_2 = transfer(rhs%enc,pz0_2)
1554ret = associated(pz0_1%p,pz0_2%p)
1555elseif ( this%t == 'z1' ) then
1556pz1_1 = transfer(this%enc,pz1_1)
1557pz1_2 = transfer(rhs%enc,pz1_2)
1558ret = associated(pz1_1%p,pz1_2%p)
1559elseif ( this%t == 'z2' ) then
1560pz2_1 = transfer(this%enc,pz2_1)
1561pz2_2 = transfer(rhs%enc,pz2_2)
1562ret = associated(pz2_1%p,pz2_2%p)
1563elseif ( this%t == 'z3' ) then
1564pz3_1 = transfer(this%enc,pz3_1)
1565pz3_2 = transfer(rhs%enc,pz3_2)
1566ret = associated(pz3_1%p,pz3_2%p)
1567endif
1568if ( this%t == 'b0' ) then
1569pb0_1 = transfer(this%enc,pb0_1)
1570pb0_2 = transfer(rhs%enc,pb0_2)
1571ret = associated(pb0_1%p,pb0_2%p)
1572elseif ( this%t == 'b1' ) then
1573pb1_1 = transfer(this%enc,pb1_1)
1574pb1_2 = transfer(rhs%enc,pb1_2)
1575ret = associated(pb1_1%p,pb1_2%p)
1576elseif ( this%t == 'b2' ) then
1577pb2_1 = transfer(this%enc,pb2_1)
1578pb2_2 = transfer(rhs%enc,pb2_2)
1579ret = associated(pb2_1%p,pb2_2%p)
1580elseif ( this%t == 'b3' ) then
1581pb3_1 = transfer(this%enc,pb3_1)
1582pb3_2 = transfer(rhs%enc,pb3_2)
1583ret = associated(pb3_1%p,pb3_2%p)
1584endif
1585if ( this%t == 'h0' ) then
1586ph0_1 = transfer(this%enc,ph0_1)
1587ph0_2 = transfer(rhs%enc,ph0_2)
1588ret = associated(ph0_1%p,ph0_2%p)
1589elseif ( this%t == 'h1' ) then
1590ph1_1 = transfer(this%enc,ph1_1)
1591ph1_2 = transfer(rhs%enc,ph1_2)
1592ret = associated(ph1_1%p,ph1_2%p)
1593elseif ( this%t == 'h2' ) then
1594ph2_1 = transfer(this%enc,ph2_1)
1595ph2_2 = transfer(rhs%enc,ph2_2)
1596ret = associated(ph2_1%p,ph2_2%p)
1597elseif ( this%t == 'h3' ) then
1598ph3_1 = transfer(this%enc,ph3_1)
1599ph3_2 = transfer(rhs%enc,ph3_2)
1600ret = associated(ph3_1%p,ph3_2%p)
1601endif
1602if ( this%t == 'i0' ) then
1603pi0_1 = transfer(this%enc,pi0_1)
1604pi0_2 = transfer(rhs%enc,pi0_2)
1605ret = associated(pi0_1%p,pi0_2%p)
1606elseif ( this%t == 'i1' ) then
1607pi1_1 = transfer(this%enc,pi1_1)
1608pi1_2 = transfer(rhs%enc,pi1_2)
1609ret = associated(pi1_1%p,pi1_2%p)
1610elseif ( this%t == 'i2' ) then
1611pi2_1 = transfer(this%enc,pi2_1)
1612pi2_2 = transfer(rhs%enc,pi2_2)
1613ret = associated(pi2_1%p,pi2_2%p)
1614elseif ( this%t == 'i3' ) then
1615pi3_1 = transfer(this%enc,pi3_1)
1616pi3_2 = transfer(rhs%enc,pi3_2)
1617ret = associated(pi3_1%p,pi3_2%p)
1618endif
1619if ( this%t == 'l0' ) then
1620pl0_1 = transfer(this%enc,pl0_1)
1621pl0_2 = transfer(rhs%enc,pl0_2)
1622ret = associated(pl0_1%p,pl0_2%p)
1623elseif ( this%t == 'l1' ) then
1624pl1_1 = transfer(this%enc,pl1_1)
1625pl1_2 = transfer(rhs%enc,pl1_2)
1626ret = associated(pl1_1%p,pl1_2%p)
1627elseif ( this%t == 'l2' ) then
1628pl2_1 = transfer(this%enc,pl2_1)
1629pl2_2 = transfer(rhs%enc,pl2_2)
1630ret = associated(pl2_1%p,pl2_2%p)
1631elseif ( this%t == 'l3' ) then
1632pl3_1 = transfer(this%enc,pl3_1)
1633pl3_2 = transfer(rhs%enc,pl3_2)
1634ret = associated(pl3_1%p,pl3_2%p)
1635endif
1636if ( this%t == 'cp0' ) then
1637pcp0_1 = transfer(this%enc,pcp0_1)
1638pcp0_2 = transfer(rhs%enc,pcp0_2)
1639ret = associated(pcp0_1%p,pcp0_2%p)
1640elseif ( this%t == 'cp1' ) then
1641pcp1_1 = transfer(this%enc,pcp1_1)
1642pcp1_2 = transfer(rhs%enc,pcp1_2)
1643ret = associated(pcp1_1%p,pcp1_2%p)
1644endif
1645if ( this%t == 'fp0' ) then
1646pfp0_1 = transfer(this%enc,pfp0_1)
1647pfp0_2 = transfer(rhs%enc,pfp0_2)
1648ret = associated(pfp0_1%p,pfp0_2%p)
1649elseif ( this%t == 'fp1' ) then
1650pfp1_1 = transfer(this%enc,pfp1_1)
1651pfp1_2 = transfer(rhs%enc,pfp1_2)
1652ret = associated(pfp1_1%p,pfp1_2%p)
1653endif
1654if ( this%t == 'USER' ) then
1655ret = all(this%enc == rhs%enc)
1656end if
1657  end function associatd_var
1658  ! The character(len=*) is a bit difficult because
1659  ! there is no way to generate a specific type for _all_
1660  ! len=1,2,3,...
1661  ! variables.
1662  ! Instead we convert the character to char(len=1)
1663  ! and store a pointer to this.
1664  ! This ensures that it can be retrieved (via associate)
1665  ! and mangled through another variable type
1666  subroutine assign_set_a0_0(this,rhs,dealloc)
1667    type(variable_t), intent(inout) :: this
1668    character(len=*), intent(in) :: rhs
1669    logical, intent(in), optional :: dealloc
1670    character(len=1), pointer :: c(:) => null()
1671    integer :: i
1672    allocate(c(len(rhs)))
1673    do i = 1 , size(c)
1674       c(i) = rhs(i:i)
1675    end do
1676    ! This is still a "copy"
1677    call associate(this, c, dealloc)
1678    nullify(c)
1679  end subroutine assign_set_a0_0
1680  subroutine assign_get_a0_0(lhs,this,success)
1681    character(len=*), intent(out) :: lhs
1682    type(variable_t), intent(inout) :: this
1683    logical, intent(out), optional :: success
1684    character(len=1), pointer :: c(:) => null()
1685    logical :: lsuccess
1686    integer :: i
1687    call associate(c, this, success=lsuccess)
1688    if ( lsuccess ) lsuccess = len(lhs) >= size(c)
1689    if ( present(success) ) success = lsuccess
1690    lhs = ' '
1691    if ( .not. lsuccess ) return
1692    do i = 1 , size(c)
1693       lhs(i:i) = c(i)
1694    end do
1695  end subroutine assign_get_a0_0
1696subroutine assign_set_a1(this,rhs,dealloc)
1697  type(variable_t), intent(inout) :: this
1698  character(len=1), intent(in), dimension(:) :: rhs
1699  logical, intent(in), optional :: dealloc
1700  logical :: ldealloc
1701  type :: pt
1702    character(len=1), pointer , dimension(:) :: p => null()
1703  end type
1704  type(pt) :: p
1705  ! ASSIGNMENT in fortran is per default destructive
1706  ldealloc = .true.
1707  if(present(dealloc))ldealloc = dealloc
1708  if (ldealloc) then
1709     call delete(this)
1710  else
1711     call nullify(this)
1712  end if
1713  ! With pointer transfer we need to deallocate
1714  ! else bounds might change...
1715  this%t = "a1"
1716  allocate(p%p(size(rhs))) ! allocate space
1717  p%p = rhs ! copy data over
1718  allocate(this%enc(size(transfer(p, local_enc_type)))) ! allocate encoding
1719  this%enc(:) = transfer(p, local_enc_type) ! transfer pointer type to the encoding
1720  ! We already have shipped it
1721  nullify(p%p)
1722end subroutine assign_set_a1
1723subroutine assign_get_a1(lhs,this,success)
1724  character(len=1), intent(out), dimension(:) :: lhs
1725  type(variable_t), intent(in) :: this
1726  logical, intent(out), optional :: success
1727  logical :: lsuccess
1728  type :: pt
1729    character(len=1), pointer , dimension(:) :: p => null()
1730  end type
1731  type(pt) :: p
1732  lsuccess = this%t == "a1"
1733  if (lsuccess) then
1734    p = transfer(this%enc,p) ! retrieve pointer encoding
1735    lsuccess = all(shape(p%p)==shape(lhs)) !&
1736     ! .and. all((lbound(p%p) == lbound(lhs))) &
1737     ! .and. all((ubound(p%p) == ubound(lhs)))
1738  end if
1739  if (present(success)) success = lsuccess
1740  if (.not. lsuccess) return
1741  lhs = p%p
1742end subroutine assign_get_a1
1743subroutine associate_get_a1(lhs,this,dealloc,success)
1744  character(len=1), pointer , dimension(:) :: lhs
1745  type(variable_t), intent(in) :: this
1746  logical, intent(in), optional :: dealloc
1747  logical, intent(out), optional :: success
1748  logical :: ldealloc, lsuccess
1749  type :: pt
1750    character(len=1), pointer , dimension(:) :: p => null()
1751  end type
1752  type(pt) :: p
1753  lsuccess = this%t == "a1"
1754  if (present(success)) success = lsuccess
1755  ! ASSOCIATION in fortran is per default non-destructive
1756  ldealloc = .false.
1757  if(present(dealloc))ldealloc = dealloc
1758  ! there is one problem, say if lhs is not nullified...
1759  if (ldealloc.and.associated(lhs)) then
1760     deallocate(lhs)
1761     nullify(lhs)
1762  end if
1763  if (.not. lsuccess ) return
1764  p = transfer(this%enc,p) ! retrieve pointer encoding
1765  lhs => p%p
1766end subroutine associate_get_a1
1767subroutine associate_set_a1(this,rhs,dealloc)
1768  type(variable_t), intent(inout) :: this
1769  character(len=1), intent(in), dimension(:), target :: rhs
1770  logical, intent(in), optional :: dealloc
1771  logical :: ldealloc
1772  type :: pt
1773    character(len=1), pointer , dimension(:) :: p => null()
1774  end type
1775  type(pt) :: p
1776  ! ASSOCIATION in fortran is per default non-destructive
1777  ldealloc = .false.
1778  if(present(dealloc))ldealloc = dealloc
1779  if (ldealloc) then
1780     call delete(this)
1781  else
1782     call nullify(this)
1783  end if
1784  this%t = "a1"
1785  p%p => rhs
1786  allocate(this%enc(size(transfer(p, local_enc_type)))) ! allocate encoding
1787  this%enc(:) = transfer(p, local_enc_type) ! transfer pointer type to the encoding
1788end subroutine associate_set_a1
1789pure function associatd_l_a1(lhs,this) result(ret)
1790  character(len=1), pointer , dimension(:) :: lhs
1791  type(variable_t), intent(in) :: this
1792  logical :: ret
1793  type :: pt
1794    character(len=1), pointer , dimension(:) :: p
1795  end type
1796  type(pt) :: p
1797  ret = this%t == "a1"
1798  if (ret) then
1799     nullify(p%p)
1800     p = transfer(this%enc,p)
1801     ret = associated(lhs,p%p)
1802  endif
1803end function associatd_l_a1
1804pure function associatd_r_a1(this,rhs) result(ret)
1805  type(variable_t), intent(in) :: this
1806  character(len=1), pointer , dimension(:) :: rhs
1807  logical :: ret
1808  type :: pt
1809    character(len=1), pointer , dimension(:) :: p
1810  end type
1811  type(pt) :: p
1812  ret = this%t == "a1"
1813  if (ret) then
1814     nullify(p%p)
1815     p = transfer(this%enc,p)
1816     ret = associated(p%p,rhs)
1817  endif
1818end function associatd_r_a1
1819! All boolean functions
1820subroutine assign_set_s0(this,rhs,dealloc)
1821  type(variable_t), intent(inout) :: this
1822  real(sp), intent(in) :: rhs
1823  logical, intent(in), optional :: dealloc
1824  logical :: ldealloc
1825  type :: pt
1826    real(sp), pointer :: p => null()
1827  end type
1828  type(pt) :: p
1829  ! ASSIGNMENT in fortran is per default destructive
1830  ldealloc = .true.
1831  if(present(dealloc))ldealloc = dealloc
1832  if (ldealloc) then
1833     call delete(this)
1834  else
1835     call nullify(this)
1836  end if
1837  ! With pointer transfer we need to deallocate
1838  ! else bounds might change...
1839  this%t = "s0"
1840  allocate(p%p) ! allocate space
1841  p%p = rhs ! copy data over
1842  allocate(this%enc(size(transfer(p, local_enc_type)))) ! allocate encoding
1843  this%enc(:) = transfer(p, local_enc_type) ! transfer pointer type to the encoding
1844  ! We already have shipped it
1845  nullify(p%p)
1846end subroutine assign_set_s0
1847subroutine assign_get_s0(lhs,this,success)
1848  real(sp), intent(out) :: lhs
1849  type(variable_t), intent(in) :: this
1850  logical, intent(out), optional :: success
1851  logical :: lsuccess
1852  type :: pt
1853    real(sp), pointer :: p => null()
1854  end type
1855  type(pt) :: p
1856  lsuccess = this%t == "s0"
1857  if (present(success)) success = lsuccess
1858  if (.not. lsuccess) return
1859  p = transfer(this%enc,p) ! retrieve pointer encoding
1860  lhs = p%p
1861end subroutine assign_get_s0
1862subroutine associate_get_s0(lhs,this,dealloc,success)
1863  real(sp), pointer :: lhs
1864  type(variable_t), intent(in) :: this
1865  logical, intent(in), optional :: dealloc
1866  logical, intent(out), optional :: success
1867  logical :: ldealloc, lsuccess
1868  type :: pt
1869    real(sp), pointer :: p => null()
1870  end type
1871  type(pt) :: p
1872  lsuccess = this%t == "s0"
1873  if (present(success)) success = lsuccess
1874  ! ASSOCIATION in fortran is per default non-destructive
1875  ldealloc = .false.
1876  if(present(dealloc))ldealloc = dealloc
1877  ! there is one problem, say if lhs is not nullified...
1878  if (ldealloc.and.associated(lhs)) then
1879     deallocate(lhs)
1880     nullify(lhs)
1881  end if
1882  if (.not. lsuccess ) return
1883  p = transfer(this%enc,p) ! retrieve pointer encoding
1884  lhs => p%p
1885end subroutine associate_get_s0
1886subroutine associate_set_s0(this,rhs,dealloc)
1887  type(variable_t), intent(inout) :: this
1888  real(sp), intent(in), target :: rhs
1889  logical, intent(in), optional :: dealloc
1890  logical :: ldealloc
1891  type :: pt
1892    real(sp), pointer :: p => null()
1893  end type
1894  type(pt) :: p
1895  ! ASSOCIATION in fortran is per default non-destructive
1896  ldealloc = .false.
1897  if(present(dealloc))ldealloc = dealloc
1898  if (ldealloc) then
1899     call delete(this)
1900  else
1901     call nullify(this)
1902  end if
1903  this%t = "s0"
1904  p%p => rhs
1905  allocate(this%enc(size(transfer(p, local_enc_type)))) ! allocate encoding
1906  this%enc(:) = transfer(p, local_enc_type) ! transfer pointer type to the encoding
1907end subroutine associate_set_s0
1908pure function associatd_l_s0(lhs,this) result(ret)
1909  real(sp), pointer :: lhs
1910  type(variable_t), intent(in) :: this
1911  logical :: ret
1912  type :: pt
1913    real(sp), pointer :: p
1914  end type
1915  type(pt) :: p
1916  ret = this%t == "s0"
1917  if (ret) then
1918     nullify(p%p)
1919     p = transfer(this%enc,p)
1920     ret = associated(lhs,p%p)
1921  endif
1922end function associatd_l_s0
1923pure function associatd_r_s0(this,rhs) result(ret)
1924  type(variable_t), intent(in) :: this
1925  real(sp), pointer :: rhs
1926  logical :: ret
1927  type :: pt
1928    real(sp), pointer :: p
1929  end type
1930  type(pt) :: p
1931  ret = this%t == "s0"
1932  if (ret) then
1933     nullify(p%p)
1934     p = transfer(this%enc,p)
1935     ret = associated(p%p,rhs)
1936  endif
1937end function associatd_r_s0
1938! All boolean functions
1939subroutine assign_set_s1(this,rhs,dealloc)
1940  type(variable_t), intent(inout) :: this
1941  real(sp), intent(in), dimension(:) :: rhs
1942  logical, intent(in), optional :: dealloc
1943  logical :: ldealloc
1944  type :: pt
1945    real(sp), pointer , dimension(:) :: p => null()
1946  end type
1947  type(pt) :: p
1948  ! ASSIGNMENT in fortran is per default destructive
1949  ldealloc = .true.
1950  if(present(dealloc))ldealloc = dealloc
1951  if (ldealloc) then
1952     call delete(this)
1953  else
1954     call nullify(this)
1955  end if
1956  ! With pointer transfer we need to deallocate
1957  ! else bounds might change...
1958  this%t = "s1"
1959  allocate(p%p(size(rhs))) ! allocate space
1960  p%p = rhs ! copy data over
1961  allocate(this%enc(size(transfer(p, local_enc_type)))) ! allocate encoding
1962  this%enc(:) = transfer(p, local_enc_type) ! transfer pointer type to the encoding
1963  ! We already have shipped it
1964  nullify(p%p)
1965end subroutine assign_set_s1
1966subroutine assign_get_s1(lhs,this,success)
1967  real(sp), intent(out), dimension(:) :: lhs
1968  type(variable_t), intent(in) :: this
1969  logical, intent(out), optional :: success
1970  logical :: lsuccess
1971  type :: pt
1972    real(sp), pointer , dimension(:) :: p => null()
1973  end type
1974  type(pt) :: p
1975  lsuccess = this%t == "s1"
1976  if (lsuccess) then
1977    p = transfer(this%enc,p) ! retrieve pointer encoding
1978    lsuccess = all(shape(p%p)==shape(lhs)) !&
1979     ! .and. all((lbound(p%p) == lbound(lhs))) &
1980     ! .and. all((ubound(p%p) == ubound(lhs)))
1981  end if
1982  if (present(success)) success = lsuccess
1983  if (.not. lsuccess) return
1984  lhs = p%p
1985end subroutine assign_get_s1
1986subroutine associate_get_s1(lhs,this,dealloc,success)
1987  real(sp), pointer , dimension(:) :: lhs
1988  type(variable_t), intent(in) :: this
1989  logical, intent(in), optional :: dealloc
1990  logical, intent(out), optional :: success
1991  logical :: ldealloc, lsuccess
1992  type :: pt
1993    real(sp), pointer , dimension(:) :: p => null()
1994  end type
1995  type(pt) :: p
1996  lsuccess = this%t == "s1"
1997  if (present(success)) success = lsuccess
1998  ! ASSOCIATION in fortran is per default non-destructive
1999  ldealloc = .false.
2000  if(present(dealloc))ldealloc = dealloc
2001  ! there is one problem, say if lhs is not nullified...
2002  if (ldealloc.and.associated(lhs)) then
2003     deallocate(lhs)
2004     nullify(lhs)
2005  end if
2006  if (.not. lsuccess ) return
2007  p = transfer(this%enc,p) ! retrieve pointer encoding
2008  lhs => p%p
2009end subroutine associate_get_s1
2010subroutine associate_set_s1(this,rhs,dealloc)
2011  type(variable_t), intent(inout) :: this
2012  real(sp), intent(in), dimension(:), target :: rhs
2013  logical, intent(in), optional :: dealloc
2014  logical :: ldealloc
2015  type :: pt
2016    real(sp), pointer , dimension(:) :: p => null()
2017  end type
2018  type(pt) :: p
2019  ! ASSOCIATION in fortran is per default non-destructive
2020  ldealloc = .false.
2021  if(present(dealloc))ldealloc = dealloc
2022  if (ldealloc) then
2023     call delete(this)
2024  else
2025     call nullify(this)
2026  end if
2027  this%t = "s1"
2028  p%p => rhs
2029  allocate(this%enc(size(transfer(p, local_enc_type)))) ! allocate encoding
2030  this%enc(:) = transfer(p, local_enc_type) ! transfer pointer type to the encoding
2031end subroutine associate_set_s1
2032pure function associatd_l_s1(lhs,this) result(ret)
2033  real(sp), pointer , dimension(:) :: lhs
2034  type(variable_t), intent(in) :: this
2035  logical :: ret
2036  type :: pt
2037    real(sp), pointer , dimension(:) :: p
2038  end type
2039  type(pt) :: p
2040  ret = this%t == "s1"
2041  if (ret) then
2042     nullify(p%p)
2043     p = transfer(this%enc,p)
2044     ret = associated(lhs,p%p)
2045  endif
2046end function associatd_l_s1
2047pure function associatd_r_s1(this,rhs) result(ret)
2048  type(variable_t), intent(in) :: this
2049  real(sp), pointer , dimension(:) :: rhs
2050  logical :: ret
2051  type :: pt
2052    real(sp), pointer , dimension(:) :: p
2053  end type
2054  type(pt) :: p
2055  ret = this%t == "s1"
2056  if (ret) then
2057     nullify(p%p)
2058     p = transfer(this%enc,p)
2059     ret = associated(p%p,rhs)
2060  endif
2061end function associatd_r_s1
2062! All boolean functions
2063subroutine assign_set_s2(this,rhs,dealloc)
2064  type(variable_t), intent(inout) :: this
2065  real(sp), intent(in), dimension(:,:) :: rhs
2066  logical, intent(in), optional :: dealloc
2067  logical :: ldealloc
2068  type :: pt
2069    real(sp), pointer , dimension(:,:) :: p => null()
2070  end type
2071  type(pt) :: p
2072  ! ASSIGNMENT in fortran is per default destructive
2073  ldealloc = .true.
2074  if(present(dealloc))ldealloc = dealloc
2075  if (ldealloc) then
2076     call delete(this)
2077  else
2078     call nullify(this)
2079  end if
2080  ! With pointer transfer we need to deallocate
2081  ! else bounds might change...
2082  this%t = "s2"
2083  allocate(p%p(size(rhs,1),size(rhs,2))) ! allocate space
2084  p%p = rhs ! copy data over
2085  allocate(this%enc(size(transfer(p, local_enc_type)))) ! allocate encoding
2086  this%enc(:) = transfer(p, local_enc_type) ! transfer pointer type to the encoding
2087  ! We already have shipped it
2088  nullify(p%p)
2089end subroutine assign_set_s2
2090subroutine assign_get_s2(lhs,this,success)
2091  real(sp), intent(out), dimension(:,:) :: lhs
2092  type(variable_t), intent(in) :: this
2093  logical, intent(out), optional :: success
2094  logical :: lsuccess
2095  type :: pt
2096    real(sp), pointer , dimension(:,:) :: p => null()
2097  end type
2098  type(pt) :: p
2099  lsuccess = this%t == "s2"
2100  if (lsuccess) then
2101    p = transfer(this%enc,p) ! retrieve pointer encoding
2102    lsuccess = all(shape(p%p)==shape(lhs)) !&
2103     ! .and. all((lbound(p%p) == lbound(lhs))) &
2104     ! .and. all((ubound(p%p) == ubound(lhs)))
2105  end if
2106  if (present(success)) success = lsuccess
2107  if (.not. lsuccess) return
2108  lhs = p%p
2109end subroutine assign_get_s2
2110subroutine associate_get_s2(lhs,this,dealloc,success)
2111  real(sp), pointer , dimension(:,:) :: lhs
2112  type(variable_t), intent(in) :: this
2113  logical, intent(in), optional :: dealloc
2114  logical, intent(out), optional :: success
2115  logical :: ldealloc, lsuccess
2116  type :: pt
2117    real(sp), pointer , dimension(:,:) :: p => null()
2118  end type
2119  type(pt) :: p
2120  lsuccess = this%t == "s2"
2121  if (present(success)) success = lsuccess
2122  ! ASSOCIATION in fortran is per default non-destructive
2123  ldealloc = .false.
2124  if(present(dealloc))ldealloc = dealloc
2125  ! there is one problem, say if lhs is not nullified...
2126  if (ldealloc.and.associated(lhs)) then
2127     deallocate(lhs)
2128     nullify(lhs)
2129  end if
2130  if (.not. lsuccess ) return
2131  p = transfer(this%enc,p) ! retrieve pointer encoding
2132  lhs => p%p
2133end subroutine associate_get_s2
2134subroutine associate_set_s2(this,rhs,dealloc)
2135  type(variable_t), intent(inout) :: this
2136  real(sp), intent(in), dimension(:,:), target :: rhs
2137  logical, intent(in), optional :: dealloc
2138  logical :: ldealloc
2139  type :: pt
2140    real(sp), pointer , dimension(:,:) :: p => null()
2141  end type
2142  type(pt) :: p
2143  ! ASSOCIATION in fortran is per default non-destructive
2144  ldealloc = .false.
2145  if(present(dealloc))ldealloc = dealloc
2146  if (ldealloc) then
2147     call delete(this)
2148  else
2149     call nullify(this)
2150  end if
2151  this%t = "s2"
2152  p%p => rhs
2153  allocate(this%enc(size(transfer(p, local_enc_type)))) ! allocate encoding
2154  this%enc(:) = transfer(p, local_enc_type) ! transfer pointer type to the encoding
2155end subroutine associate_set_s2
2156pure function associatd_l_s2(lhs,this) result(ret)
2157  real(sp), pointer , dimension(:,:) :: lhs
2158  type(variable_t), intent(in) :: this
2159  logical :: ret
2160  type :: pt
2161    real(sp), pointer , dimension(:,:) :: p
2162  end type
2163  type(pt) :: p
2164  ret = this%t == "s2"
2165  if (ret) then
2166     nullify(p%p)
2167     p = transfer(this%enc,p)
2168     ret = associated(lhs,p%p)
2169  endif
2170end function associatd_l_s2
2171pure function associatd_r_s2(this,rhs) result(ret)
2172  type(variable_t), intent(in) :: this
2173  real(sp), pointer , dimension(:,:) :: rhs
2174  logical :: ret
2175  type :: pt
2176    real(sp), pointer , dimension(:,:) :: p
2177  end type
2178  type(pt) :: p
2179  ret = this%t == "s2"
2180  if (ret) then
2181     nullify(p%p)
2182     p = transfer(this%enc,p)
2183     ret = associated(p%p,rhs)
2184  endif
2185end function associatd_r_s2
2186! All boolean functions
2187subroutine assign_set_s3(this,rhs,dealloc)
2188  type(variable_t), intent(inout) :: this
2189  real(sp), intent(in), dimension(:,:,:) :: rhs
2190  logical, intent(in), optional :: dealloc
2191  logical :: ldealloc
2192  type :: pt
2193    real(sp), pointer , dimension(:,:,:) :: p => null()
2194  end type
2195  type(pt) :: p
2196  ! ASSIGNMENT in fortran is per default destructive
2197  ldealloc = .true.
2198  if(present(dealloc))ldealloc = dealloc
2199  if (ldealloc) then
2200     call delete(this)
2201  else
2202     call nullify(this)
2203  end if
2204  ! With pointer transfer we need to deallocate
2205  ! else bounds might change...
2206  this%t = "s3"
2207  allocate(p%p(size(rhs,1),size(rhs,2),size(rhs,3))) ! allocate space
2208  p%p = rhs ! copy data over
2209  allocate(this%enc(size(transfer(p, local_enc_type)))) ! allocate encoding
2210  this%enc(:) = transfer(p, local_enc_type) ! transfer pointer type to the encoding
2211  ! We already have shipped it
2212  nullify(p%p)
2213end subroutine assign_set_s3
2214subroutine assign_get_s3(lhs,this,success)
2215  real(sp), intent(out), dimension(:,:,:) :: lhs
2216  type(variable_t), intent(in) :: this
2217  logical, intent(out), optional :: success
2218  logical :: lsuccess
2219  type :: pt
2220    real(sp), pointer , dimension(:,:,:) :: p => null()
2221  end type
2222  type(pt) :: p
2223  lsuccess = this%t == "s3"
2224  if (lsuccess) then
2225    p = transfer(this%enc,p) ! retrieve pointer encoding
2226    lsuccess = all(shape(p%p)==shape(lhs)) !&
2227     ! .and. all((lbound(p%p) == lbound(lhs))) &
2228     ! .and. all((ubound(p%p) == ubound(lhs)))
2229  end if
2230  if (present(success)) success = lsuccess
2231  if (.not. lsuccess) return
2232  lhs = p%p
2233end subroutine assign_get_s3
2234subroutine associate_get_s3(lhs,this,dealloc,success)
2235  real(sp), pointer , dimension(:,:,:) :: lhs
2236  type(variable_t), intent(in) :: this
2237  logical, intent(in), optional :: dealloc
2238  logical, intent(out), optional :: success
2239  logical :: ldealloc, lsuccess
2240  type :: pt
2241    real(sp), pointer , dimension(:,:,:) :: p => null()
2242  end type
2243  type(pt) :: p
2244  lsuccess = this%t == "s3"
2245  if (present(success)) success = lsuccess
2246  ! ASSOCIATION in fortran is per default non-destructive
2247  ldealloc = .false.
2248  if(present(dealloc))ldealloc = dealloc
2249  ! there is one problem, say if lhs is not nullified...
2250  if (ldealloc.and.associated(lhs)) then
2251     deallocate(lhs)
2252     nullify(lhs)
2253  end if
2254  if (.not. lsuccess ) return
2255  p = transfer(this%enc,p) ! retrieve pointer encoding
2256  lhs => p%p
2257end subroutine associate_get_s3
2258subroutine associate_set_s3(this,rhs,dealloc)
2259  type(variable_t), intent(inout) :: this
2260  real(sp), intent(in), dimension(:,:,:), target :: rhs
2261  logical, intent(in), optional :: dealloc
2262  logical :: ldealloc
2263  type :: pt
2264    real(sp), pointer , dimension(:,:,:) :: p => null()
2265  end type
2266  type(pt) :: p
2267  ! ASSOCIATION in fortran is per default non-destructive
2268  ldealloc = .false.
2269  if(present(dealloc))ldealloc = dealloc
2270  if (ldealloc) then
2271     call delete(this)
2272  else
2273     call nullify(this)
2274  end if
2275  this%t = "s3"
2276  p%p => rhs
2277  allocate(this%enc(size(transfer(p, local_enc_type)))) ! allocate encoding
2278  this%enc(:) = transfer(p, local_enc_type) ! transfer pointer type to the encoding
2279end subroutine associate_set_s3
2280pure function associatd_l_s3(lhs,this) result(ret)
2281  real(sp), pointer , dimension(:,:,:) :: lhs
2282  type(variable_t), intent(in) :: this
2283  logical :: ret
2284  type :: pt
2285    real(sp), pointer , dimension(:,:,:) :: p
2286  end type
2287  type(pt) :: p
2288  ret = this%t == "s3"
2289  if (ret) then
2290     nullify(p%p)
2291     p = transfer(this%enc,p)
2292     ret = associated(lhs,p%p)
2293  endif
2294end function associatd_l_s3
2295pure function associatd_r_s3(this,rhs) result(ret)
2296  type(variable_t), intent(in) :: this
2297  real(sp), pointer , dimension(:,:,:) :: rhs
2298  logical :: ret
2299  type :: pt
2300    real(sp), pointer , dimension(:,:,:) :: p
2301  end type
2302  type(pt) :: p
2303  ret = this%t == "s3"
2304  if (ret) then
2305     nullify(p%p)
2306     p = transfer(this%enc,p)
2307     ret = associated(p%p,rhs)
2308  endif
2309end function associatd_r_s3
2310! All boolean functions
2311subroutine assign_set_d0(this,rhs,dealloc)
2312  type(variable_t), intent(inout) :: this
2313  real(dp), intent(in) :: rhs
2314  logical, intent(in), optional :: dealloc
2315  logical :: ldealloc
2316  type :: pt
2317    real(dp), pointer :: p => null()
2318  end type
2319  type(pt) :: p
2320  ! ASSIGNMENT in fortran is per default destructive
2321  ldealloc = .true.
2322  if(present(dealloc))ldealloc = dealloc
2323  if (ldealloc) then
2324     call delete(this)
2325  else
2326     call nullify(this)
2327  end if
2328  ! With pointer transfer we need to deallocate
2329  ! else bounds might change...
2330  this%t = "d0"
2331  allocate(p%p) ! allocate space
2332  p%p = rhs ! copy data over
2333  allocate(this%enc(size(transfer(p, local_enc_type)))) ! allocate encoding
2334  this%enc(:) = transfer(p, local_enc_type) ! transfer pointer type to the encoding
2335  ! We already have shipped it
2336  nullify(p%p)
2337end subroutine assign_set_d0
2338subroutine assign_get_d0(lhs,this,success)
2339  real(dp), intent(out) :: lhs
2340  type(variable_t), intent(in) :: this
2341  logical, intent(out), optional :: success
2342  logical :: lsuccess
2343  type :: pt
2344    real(dp), pointer :: p => null()
2345  end type
2346  type(pt) :: p
2347  lsuccess = this%t == "d0"
2348  if (present(success)) success = lsuccess
2349  if (.not. lsuccess) return
2350  p = transfer(this%enc,p) ! retrieve pointer encoding
2351  lhs = p%p
2352end subroutine assign_get_d0
2353subroutine associate_get_d0(lhs,this,dealloc,success)
2354  real(dp), pointer :: lhs
2355  type(variable_t), intent(in) :: this
2356  logical, intent(in), optional :: dealloc
2357  logical, intent(out), optional :: success
2358  logical :: ldealloc, lsuccess
2359  type :: pt
2360    real(dp), pointer :: p => null()
2361  end type
2362  type(pt) :: p
2363  lsuccess = this%t == "d0"
2364  if (present(success)) success = lsuccess
2365  ! ASSOCIATION in fortran is per default non-destructive
2366  ldealloc = .false.
2367  if(present(dealloc))ldealloc = dealloc
2368  ! there is one problem, say if lhs is not nullified...
2369  if (ldealloc.and.associated(lhs)) then
2370     deallocate(lhs)
2371     nullify(lhs)
2372  end if
2373  if (.not. lsuccess ) return
2374  p = transfer(this%enc,p) ! retrieve pointer encoding
2375  lhs => p%p
2376end subroutine associate_get_d0
2377subroutine associate_set_d0(this,rhs,dealloc)
2378  type(variable_t), intent(inout) :: this
2379  real(dp), intent(in), target :: rhs
2380  logical, intent(in), optional :: dealloc
2381  logical :: ldealloc
2382  type :: pt
2383    real(dp), pointer :: p => null()
2384  end type
2385  type(pt) :: p
2386  ! ASSOCIATION in fortran is per default non-destructive
2387  ldealloc = .false.
2388  if(present(dealloc))ldealloc = dealloc
2389  if (ldealloc) then
2390     call delete(this)
2391  else
2392     call nullify(this)
2393  end if
2394  this%t = "d0"
2395  p%p => rhs
2396  allocate(this%enc(size(transfer(p, local_enc_type)))) ! allocate encoding
2397  this%enc(:) = transfer(p, local_enc_type) ! transfer pointer type to the encoding
2398end subroutine associate_set_d0
2399pure function associatd_l_d0(lhs,this) result(ret)
2400  real(dp), pointer :: lhs
2401  type(variable_t), intent(in) :: this
2402  logical :: ret
2403  type :: pt
2404    real(dp), pointer :: p
2405  end type
2406  type(pt) :: p
2407  ret = this%t == "d0"
2408  if (ret) then
2409     nullify(p%p)
2410     p = transfer(this%enc,p)
2411     ret = associated(lhs,p%p)
2412  endif
2413end function associatd_l_d0
2414pure function associatd_r_d0(this,rhs) result(ret)
2415  type(variable_t), intent(in) :: this
2416  real(dp), pointer :: rhs
2417  logical :: ret
2418  type :: pt
2419    real(dp), pointer :: p
2420  end type
2421  type(pt) :: p
2422  ret = this%t == "d0"
2423  if (ret) then
2424     nullify(p%p)
2425     p = transfer(this%enc,p)
2426     ret = associated(p%p,rhs)
2427  endif
2428end function associatd_r_d0
2429! All boolean functions
2430subroutine assign_set_d1(this,rhs,dealloc)
2431  type(variable_t), intent(inout) :: this
2432  real(dp), intent(in), dimension(:) :: rhs
2433  logical, intent(in), optional :: dealloc
2434  logical :: ldealloc
2435  type :: pt
2436    real(dp), pointer , dimension(:) :: p => null()
2437  end type
2438  type(pt) :: p
2439  ! ASSIGNMENT in fortran is per default destructive
2440  ldealloc = .true.
2441  if(present(dealloc))ldealloc = dealloc
2442  if (ldealloc) then
2443     call delete(this)
2444  else
2445     call nullify(this)
2446  end if
2447  ! With pointer transfer we need to deallocate
2448  ! else bounds might change...
2449  this%t = "d1"
2450  allocate(p%p(size(rhs))) ! allocate space
2451  p%p = rhs ! copy data over
2452  allocate(this%enc(size(transfer(p, local_enc_type)))) ! allocate encoding
2453  this%enc(:) = transfer(p, local_enc_type) ! transfer pointer type to the encoding
2454  ! We already have shipped it
2455  nullify(p%p)
2456end subroutine assign_set_d1
2457subroutine assign_get_d1(lhs,this,success)
2458  real(dp), intent(out), dimension(:) :: lhs
2459  type(variable_t), intent(in) :: this
2460  logical, intent(out), optional :: success
2461  logical :: lsuccess
2462  type :: pt
2463    real(dp), pointer , dimension(:) :: p => null()
2464  end type
2465  type(pt) :: p
2466  lsuccess = this%t == "d1"
2467  if (lsuccess) then
2468    p = transfer(this%enc,p) ! retrieve pointer encoding
2469    lsuccess = all(shape(p%p)==shape(lhs)) !&
2470     ! .and. all((lbound(p%p) == lbound(lhs))) &
2471     ! .and. all((ubound(p%p) == ubound(lhs)))
2472  end if
2473  if (present(success)) success = lsuccess
2474  if (.not. lsuccess) return
2475  lhs = p%p
2476end subroutine assign_get_d1
2477subroutine associate_get_d1(lhs,this,dealloc,success)
2478  real(dp), pointer , dimension(:) :: lhs
2479  type(variable_t), intent(in) :: this
2480  logical, intent(in), optional :: dealloc
2481  logical, intent(out), optional :: success
2482  logical :: ldealloc, lsuccess
2483  type :: pt
2484    real(dp), pointer , dimension(:) :: p => null()
2485  end type
2486  type(pt) :: p
2487  lsuccess = this%t == "d1"
2488  if (present(success)) success = lsuccess
2489  ! ASSOCIATION in fortran is per default non-destructive
2490  ldealloc = .false.
2491  if(present(dealloc))ldealloc = dealloc
2492  ! there is one problem, say if lhs is not nullified...
2493  if (ldealloc.and.associated(lhs)) then
2494     deallocate(lhs)
2495     nullify(lhs)
2496  end if
2497  if (.not. lsuccess ) return
2498  p = transfer(this%enc,p) ! retrieve pointer encoding
2499  lhs => p%p
2500end subroutine associate_get_d1
2501subroutine associate_set_d1(this,rhs,dealloc)
2502  type(variable_t), intent(inout) :: this
2503  real(dp), intent(in), dimension(:), target :: rhs
2504  logical, intent(in), optional :: dealloc
2505  logical :: ldealloc
2506  type :: pt
2507    real(dp), pointer , dimension(:) :: p => null()
2508  end type
2509  type(pt) :: p
2510  ! ASSOCIATION in fortran is per default non-destructive
2511  ldealloc = .false.
2512  if(present(dealloc))ldealloc = dealloc
2513  if (ldealloc) then
2514     call delete(this)
2515  else
2516     call nullify(this)
2517  end if
2518  this%t = "d1"
2519  p%p => rhs
2520  allocate(this%enc(size(transfer(p, local_enc_type)))) ! allocate encoding
2521  this%enc(:) = transfer(p, local_enc_type) ! transfer pointer type to the encoding
2522end subroutine associate_set_d1
2523pure function associatd_l_d1(lhs,this) result(ret)
2524  real(dp), pointer , dimension(:) :: lhs
2525  type(variable_t), intent(in) :: this
2526  logical :: ret
2527  type :: pt
2528    real(dp), pointer , dimension(:) :: p
2529  end type
2530  type(pt) :: p
2531  ret = this%t == "d1"
2532  if (ret) then
2533     nullify(p%p)
2534     p = transfer(this%enc,p)
2535     ret = associated(lhs,p%p)
2536  endif
2537end function associatd_l_d1
2538pure function associatd_r_d1(this,rhs) result(ret)
2539  type(variable_t), intent(in) :: this
2540  real(dp), pointer , dimension(:) :: rhs
2541  logical :: ret
2542  type :: pt
2543    real(dp), pointer , dimension(:) :: p
2544  end type
2545  type(pt) :: p
2546  ret = this%t == "d1"
2547  if (ret) then
2548     nullify(p%p)
2549     p = transfer(this%enc,p)
2550     ret = associated(p%p,rhs)
2551  endif
2552end function associatd_r_d1
2553! All boolean functions
2554subroutine assign_set_d2(this,rhs,dealloc)
2555  type(variable_t), intent(inout) :: this
2556  real(dp), intent(in), dimension(:,:) :: rhs
2557  logical, intent(in), optional :: dealloc
2558  logical :: ldealloc
2559  type :: pt
2560    real(dp), pointer , dimension(:,:) :: p => null()
2561  end type
2562  type(pt) :: p
2563  ! ASSIGNMENT in fortran is per default destructive
2564  ldealloc = .true.
2565  if(present(dealloc))ldealloc = dealloc
2566  if (ldealloc) then
2567     call delete(this)
2568  else
2569     call nullify(this)
2570  end if
2571  ! With pointer transfer we need to deallocate
2572  ! else bounds might change...
2573  this%t = "d2"
2574  allocate(p%p(size(rhs,1),size(rhs,2))) ! allocate space
2575  p%p = rhs ! copy data over
2576  allocate(this%enc(size(transfer(p, local_enc_type)))) ! allocate encoding
2577  this%enc(:) = transfer(p, local_enc_type) ! transfer pointer type to the encoding
2578  ! We already have shipped it
2579  nullify(p%p)
2580end subroutine assign_set_d2
2581subroutine assign_get_d2(lhs,this,success)
2582  real(dp), intent(out), dimension(:,:) :: lhs
2583  type(variable_t), intent(in) :: this
2584  logical, intent(out), optional :: success
2585  logical :: lsuccess
2586  type :: pt
2587    real(dp), pointer , dimension(:,:) :: p => null()
2588  end type
2589  type(pt) :: p
2590  lsuccess = this%t == "d2"
2591  if (lsuccess) then
2592    p = transfer(this%enc,p) ! retrieve pointer encoding
2593    lsuccess = all(shape(p%p)==shape(lhs)) !&
2594     ! .and. all((lbound(p%p) == lbound(lhs))) &
2595     ! .and. all((ubound(p%p) == ubound(lhs)))
2596  end if
2597  if (present(success)) success = lsuccess
2598  if (.not. lsuccess) return
2599  lhs = p%p
2600end subroutine assign_get_d2
2601subroutine associate_get_d2(lhs,this,dealloc,success)
2602  real(dp), pointer , dimension(:,:) :: lhs
2603  type(variable_t), intent(in) :: this
2604  logical, intent(in), optional :: dealloc
2605  logical, intent(out), optional :: success
2606  logical :: ldealloc, lsuccess
2607  type :: pt
2608    real(dp), pointer , dimension(:,:) :: p => null()
2609  end type
2610  type(pt) :: p
2611  lsuccess = this%t == "d2"
2612  if (present(success)) success = lsuccess
2613  ! ASSOCIATION in fortran is per default non-destructive
2614  ldealloc = .false.
2615  if(present(dealloc))ldealloc = dealloc
2616  ! there is one problem, say if lhs is not nullified...
2617  if (ldealloc.and.associated(lhs)) then
2618     deallocate(lhs)
2619     nullify(lhs)
2620  end if
2621  if (.not. lsuccess ) return
2622  p = transfer(this%enc,p) ! retrieve pointer encoding
2623  lhs => p%p
2624end subroutine associate_get_d2
2625subroutine associate_set_d2(this,rhs,dealloc)
2626  type(variable_t), intent(inout) :: this
2627  real(dp), intent(in), dimension(:,:), target :: rhs
2628  logical, intent(in), optional :: dealloc
2629  logical :: ldealloc
2630  type :: pt
2631    real(dp), pointer , dimension(:,:) :: p => null()
2632  end type
2633  type(pt) :: p
2634  ! ASSOCIATION in fortran is per default non-destructive
2635  ldealloc = .false.
2636  if(present(dealloc))ldealloc = dealloc
2637  if (ldealloc) then
2638     call delete(this)
2639  else
2640     call nullify(this)
2641  end if
2642  this%t = "d2"
2643  p%p => rhs
2644  allocate(this%enc(size(transfer(p, local_enc_type)))) ! allocate encoding
2645  this%enc(:) = transfer(p, local_enc_type) ! transfer pointer type to the encoding
2646end subroutine associate_set_d2
2647pure function associatd_l_d2(lhs,this) result(ret)
2648  real(dp), pointer , dimension(:,:) :: lhs
2649  type(variable_t), intent(in) :: this
2650  logical :: ret
2651  type :: pt
2652    real(dp), pointer , dimension(:,:) :: p
2653  end type
2654  type(pt) :: p
2655  ret = this%t == "d2"
2656  if (ret) then
2657     nullify(p%p)
2658     p = transfer(this%enc,p)
2659     ret = associated(lhs,p%p)
2660  endif
2661end function associatd_l_d2
2662pure function associatd_r_d2(this,rhs) result(ret)
2663  type(variable_t), intent(in) :: this
2664  real(dp), pointer , dimension(:,:) :: rhs
2665  logical :: ret
2666  type :: pt
2667    real(dp), pointer , dimension(:,:) :: p
2668  end type
2669  type(pt) :: p
2670  ret = this%t == "d2"
2671  if (ret) then
2672     nullify(p%p)
2673     p = transfer(this%enc,p)
2674     ret = associated(p%p,rhs)
2675  endif
2676end function associatd_r_d2
2677! All boolean functions
2678subroutine assign_set_d3(this,rhs,dealloc)
2679  type(variable_t), intent(inout) :: this
2680  real(dp), intent(in), dimension(:,:,:) :: rhs
2681  logical, intent(in), optional :: dealloc
2682  logical :: ldealloc
2683  type :: pt
2684    real(dp), pointer , dimension(:,:,:) :: p => null()
2685  end type
2686  type(pt) :: p
2687  ! ASSIGNMENT in fortran is per default destructive
2688  ldealloc = .true.
2689  if(present(dealloc))ldealloc = dealloc
2690  if (ldealloc) then
2691     call delete(this)
2692  else
2693     call nullify(this)
2694  end if
2695  ! With pointer transfer we need to deallocate
2696  ! else bounds might change...
2697  this%t = "d3"
2698  allocate(p%p(size(rhs,1),size(rhs,2),size(rhs,3))) ! allocate space
2699  p%p = rhs ! copy data over
2700  allocate(this%enc(size(transfer(p, local_enc_type)))) ! allocate encoding
2701  this%enc(:) = transfer(p, local_enc_type) ! transfer pointer type to the encoding
2702  ! We already have shipped it
2703  nullify(p%p)
2704end subroutine assign_set_d3
2705subroutine assign_get_d3(lhs,this,success)
2706  real(dp), intent(out), dimension(:,:,:) :: lhs
2707  type(variable_t), intent(in) :: this
2708  logical, intent(out), optional :: success
2709  logical :: lsuccess
2710  type :: pt
2711    real(dp), pointer , dimension(:,:,:) :: p => null()
2712  end type
2713  type(pt) :: p
2714  lsuccess = this%t == "d3"
2715  if (lsuccess) then
2716    p = transfer(this%enc,p) ! retrieve pointer encoding
2717    lsuccess = all(shape(p%p)==shape(lhs)) !&
2718     ! .and. all((lbound(p%p) == lbound(lhs))) &
2719     ! .and. all((ubound(p%p) == ubound(lhs)))
2720  end if
2721  if (present(success)) success = lsuccess
2722  if (.not. lsuccess) return
2723  lhs = p%p
2724end subroutine assign_get_d3
2725subroutine associate_get_d3(lhs,this,dealloc,success)
2726  real(dp), pointer , dimension(:,:,:) :: lhs
2727  type(variable_t), intent(in) :: this
2728  logical, intent(in), optional :: dealloc
2729  logical, intent(out), optional :: success
2730  logical :: ldealloc, lsuccess
2731  type :: pt
2732    real(dp), pointer , dimension(:,:,:) :: p => null()
2733  end type
2734  type(pt) :: p
2735  lsuccess = this%t == "d3"
2736  if (present(success)) success = lsuccess
2737  ! ASSOCIATION in fortran is per default non-destructive
2738  ldealloc = .false.
2739  if(present(dealloc))ldealloc = dealloc
2740  ! there is one problem, say if lhs is not nullified...
2741  if (ldealloc.and.associated(lhs)) then
2742     deallocate(lhs)
2743     nullify(lhs)
2744  end if
2745  if (.not. lsuccess ) return
2746  p = transfer(this%enc,p) ! retrieve pointer encoding
2747  lhs => p%p
2748end subroutine associate_get_d3
2749subroutine associate_set_d3(this,rhs,dealloc)
2750  type(variable_t), intent(inout) :: this
2751  real(dp), intent(in), dimension(:,:,:), target :: rhs
2752  logical, intent(in), optional :: dealloc
2753  logical :: ldealloc
2754  type :: pt
2755    real(dp), pointer , dimension(:,:,:) :: p => null()
2756  end type
2757  type(pt) :: p
2758  ! ASSOCIATION in fortran is per default non-destructive
2759  ldealloc = .false.
2760  if(present(dealloc))ldealloc = dealloc
2761  if (ldealloc) then
2762     call delete(this)
2763  else
2764     call nullify(this)
2765  end if
2766  this%t = "d3"
2767  p%p => rhs
2768  allocate(this%enc(size(transfer(p, local_enc_type)))) ! allocate encoding
2769  this%enc(:) = transfer(p, local_enc_type) ! transfer pointer type to the encoding
2770end subroutine associate_set_d3
2771pure function associatd_l_d3(lhs,this) result(ret)
2772  real(dp), pointer , dimension(:,:,:) :: lhs
2773  type(variable_t), intent(in) :: this
2774  logical :: ret
2775  type :: pt
2776    real(dp), pointer , dimension(:,:,:) :: p
2777  end type
2778  type(pt) :: p
2779  ret = this%t == "d3"
2780  if (ret) then
2781     nullify(p%p)
2782     p = transfer(this%enc,p)
2783     ret = associated(lhs,p%p)
2784  endif
2785end function associatd_l_d3
2786pure function associatd_r_d3(this,rhs) result(ret)
2787  type(variable_t), intent(in) :: this
2788  real(dp), pointer , dimension(:,:,:) :: rhs
2789  logical :: ret
2790  type :: pt
2791    real(dp), pointer , dimension(:,:,:) :: p
2792  end type
2793  type(pt) :: p
2794  ret = this%t == "d3"
2795  if (ret) then
2796     nullify(p%p)
2797     p = transfer(this%enc,p)
2798     ret = associated(p%p,rhs)
2799  endif
2800end function associatd_r_d3
2801! All boolean functions
2802subroutine assign_set_c0(this,rhs,dealloc)
2803  type(variable_t), intent(inout) :: this
2804  complex(sp), intent(in) :: rhs
2805  logical, intent(in), optional :: dealloc
2806  logical :: ldealloc
2807  type :: pt
2808    complex(sp), pointer :: p => null()
2809  end type
2810  type(pt) :: p
2811  ! ASSIGNMENT in fortran is per default destructive
2812  ldealloc = .true.
2813  if(present(dealloc))ldealloc = dealloc
2814  if (ldealloc) then
2815     call delete(this)
2816  else
2817     call nullify(this)
2818  end if
2819  ! With pointer transfer we need to deallocate
2820  ! else bounds might change...
2821  this%t = "c0"
2822  allocate(p%p) ! allocate space
2823  p%p = rhs ! copy data over
2824  allocate(this%enc(size(transfer(p, local_enc_type)))) ! allocate encoding
2825  this%enc(:) = transfer(p, local_enc_type) ! transfer pointer type to the encoding
2826  ! We already have shipped it
2827  nullify(p%p)
2828end subroutine assign_set_c0
2829subroutine assign_get_c0(lhs,this,success)
2830  complex(sp), intent(out) :: lhs
2831  type(variable_t), intent(in) :: this
2832  logical, intent(out), optional :: success
2833  logical :: lsuccess
2834  type :: pt
2835    complex(sp), pointer :: p => null()
2836  end type
2837  type(pt) :: p
2838  lsuccess = this%t == "c0"
2839  if (present(success)) success = lsuccess
2840  if (.not. lsuccess) return
2841  p = transfer(this%enc,p) ! retrieve pointer encoding
2842  lhs = p%p
2843end subroutine assign_get_c0
2844subroutine associate_get_c0(lhs,this,dealloc,success)
2845  complex(sp), pointer :: lhs
2846  type(variable_t), intent(in) :: this
2847  logical, intent(in), optional :: dealloc
2848  logical, intent(out), optional :: success
2849  logical :: ldealloc, lsuccess
2850  type :: pt
2851    complex(sp), pointer :: p => null()
2852  end type
2853  type(pt) :: p
2854  lsuccess = this%t == "c0"
2855  if (present(success)) success = lsuccess
2856  ! ASSOCIATION in fortran is per default non-destructive
2857  ldealloc = .false.
2858  if(present(dealloc))ldealloc = dealloc
2859  ! there is one problem, say if lhs is not nullified...
2860  if (ldealloc.and.associated(lhs)) then
2861     deallocate(lhs)
2862     nullify(lhs)
2863  end if
2864  if (.not. lsuccess ) return
2865  p = transfer(this%enc,p) ! retrieve pointer encoding
2866  lhs => p%p
2867end subroutine associate_get_c0
2868subroutine associate_set_c0(this,rhs,dealloc)
2869  type(variable_t), intent(inout) :: this
2870  complex(sp), intent(in), target :: rhs
2871  logical, intent(in), optional :: dealloc
2872  logical :: ldealloc
2873  type :: pt
2874    complex(sp), pointer :: p => null()
2875  end type
2876  type(pt) :: p
2877  ! ASSOCIATION in fortran is per default non-destructive
2878  ldealloc = .false.
2879  if(present(dealloc))ldealloc = dealloc
2880  if (ldealloc) then
2881     call delete(this)
2882  else
2883     call nullify(this)
2884  end if
2885  this%t = "c0"
2886  p%p => rhs
2887  allocate(this%enc(size(transfer(p, local_enc_type)))) ! allocate encoding
2888  this%enc(:) = transfer(p, local_enc_type) ! transfer pointer type to the encoding
2889end subroutine associate_set_c0
2890pure function associatd_l_c0(lhs,this) result(ret)
2891  complex(sp), pointer :: lhs
2892  type(variable_t), intent(in) :: this
2893  logical :: ret
2894  type :: pt
2895    complex(sp), pointer :: p
2896  end type
2897  type(pt) :: p
2898  ret = this%t == "c0"
2899  if (ret) then
2900     nullify(p%p)
2901     p = transfer(this%enc,p)
2902     ret = associated(lhs,p%p)
2903  endif
2904end function associatd_l_c0
2905pure function associatd_r_c0(this,rhs) result(ret)
2906  type(variable_t), intent(in) :: this
2907  complex(sp), pointer :: rhs
2908  logical :: ret
2909  type :: pt
2910    complex(sp), pointer :: p
2911  end type
2912  type(pt) :: p
2913  ret = this%t == "c0"
2914  if (ret) then
2915     nullify(p%p)
2916     p = transfer(this%enc,p)
2917     ret = associated(p%p,rhs)
2918  endif
2919end function associatd_r_c0
2920! All boolean functions
2921subroutine assign_set_c1(this,rhs,dealloc)
2922  type(variable_t), intent(inout) :: this
2923  complex(sp), intent(in), dimension(:) :: rhs
2924  logical, intent(in), optional :: dealloc
2925  logical :: ldealloc
2926  type :: pt
2927    complex(sp), pointer , dimension(:) :: p => null()
2928  end type
2929  type(pt) :: p
2930  ! ASSIGNMENT in fortran is per default destructive
2931  ldealloc = .true.
2932  if(present(dealloc))ldealloc = dealloc
2933  if (ldealloc) then
2934     call delete(this)
2935  else
2936     call nullify(this)
2937  end if
2938  ! With pointer transfer we need to deallocate
2939  ! else bounds might change...
2940  this%t = "c1"
2941  allocate(p%p(size(rhs))) ! allocate space
2942  p%p = rhs ! copy data over
2943  allocate(this%enc(size(transfer(p, local_enc_type)))) ! allocate encoding
2944  this%enc(:) = transfer(p, local_enc_type) ! transfer pointer type to the encoding
2945  ! We already have shipped it
2946  nullify(p%p)
2947end subroutine assign_set_c1
2948subroutine assign_get_c1(lhs,this,success)
2949  complex(sp), intent(out), dimension(:) :: lhs
2950  type(variable_t), intent(in) :: this
2951  logical, intent(out), optional :: success
2952  logical :: lsuccess
2953  type :: pt
2954    complex(sp), pointer , dimension(:) :: p => null()
2955  end type
2956  type(pt) :: p
2957  lsuccess = this%t == "c1"
2958  if (lsuccess) then
2959    p = transfer(this%enc,p) ! retrieve pointer encoding
2960    lsuccess = all(shape(p%p)==shape(lhs)) !&
2961     ! .and. all((lbound(p%p) == lbound(lhs))) &
2962     ! .and. all((ubound(p%p) == ubound(lhs)))
2963  end if
2964  if (present(success)) success = lsuccess
2965  if (.not. lsuccess) return
2966  lhs = p%p
2967end subroutine assign_get_c1
2968subroutine associate_get_c1(lhs,this,dealloc,success)
2969  complex(sp), pointer , dimension(:) :: lhs
2970  type(variable_t), intent(in) :: this
2971  logical, intent(in), optional :: dealloc
2972  logical, intent(out), optional :: success
2973  logical :: ldealloc, lsuccess
2974  type :: pt
2975    complex(sp), pointer , dimension(:) :: p => null()
2976  end type
2977  type(pt) :: p
2978  lsuccess = this%t == "c1"
2979  if (present(success)) success = lsuccess
2980  ! ASSOCIATION in fortran is per default non-destructive
2981  ldealloc = .false.
2982  if(present(dealloc))ldealloc = dealloc
2983  ! there is one problem, say if lhs is not nullified...
2984  if (ldealloc.and.associated(lhs)) then
2985     deallocate(lhs)
2986     nullify(lhs)
2987  end if
2988  if (.not. lsuccess ) return
2989  p = transfer(this%enc,p) ! retrieve pointer encoding
2990  lhs => p%p
2991end subroutine associate_get_c1
2992subroutine associate_set_c1(this,rhs,dealloc)
2993  type(variable_t), intent(inout) :: this
2994  complex(sp), intent(in), dimension(:), target :: rhs
2995  logical, intent(in), optional :: dealloc
2996  logical :: ldealloc
2997  type :: pt
2998    complex(sp), pointer , dimension(:) :: p => null()
2999  end type
3000  type(pt) :: p
3001  ! ASSOCIATION in fortran is per default non-destructive
3002  ldealloc = .false.
3003  if(present(dealloc))ldealloc = dealloc
3004  if (ldealloc) then
3005     call delete(this)
3006  else
3007     call nullify(this)
3008  end if
3009  this%t = "c1"
3010  p%p => rhs
3011  allocate(this%enc(size(transfer(p, local_enc_type)))) ! allocate encoding
3012  this%enc(:) = transfer(p, local_enc_type) ! transfer pointer type to the encoding
3013end subroutine associate_set_c1
3014pure function associatd_l_c1(lhs,this) result(ret)
3015  complex(sp), pointer , dimension(:) :: lhs
3016  type(variable_t), intent(in) :: this
3017  logical :: ret
3018  type :: pt
3019    complex(sp), pointer , dimension(:) :: p
3020  end type
3021  type(pt) :: p
3022  ret = this%t == "c1"
3023  if (ret) then
3024     nullify(p%p)
3025     p = transfer(this%enc,p)
3026     ret = associated(lhs,p%p)
3027  endif
3028end function associatd_l_c1
3029pure function associatd_r_c1(this,rhs) result(ret)
3030  type(variable_t), intent(in) :: this
3031  complex(sp), pointer , dimension(:) :: rhs
3032  logical :: ret
3033  type :: pt
3034    complex(sp), pointer , dimension(:) :: p
3035  end type
3036  type(pt) :: p
3037  ret = this%t == "c1"
3038  if (ret) then
3039     nullify(p%p)
3040     p = transfer(this%enc,p)
3041     ret = associated(p%p,rhs)
3042  endif
3043end function associatd_r_c1
3044! All boolean functions
3045subroutine assign_set_c2(this,rhs,dealloc)
3046  type(variable_t), intent(inout) :: this
3047  complex(sp), intent(in), dimension(:,:) :: rhs
3048  logical, intent(in), optional :: dealloc
3049  logical :: ldealloc
3050  type :: pt
3051    complex(sp), pointer , dimension(:,:) :: p => null()
3052  end type
3053  type(pt) :: p
3054  ! ASSIGNMENT in fortran is per default destructive
3055  ldealloc = .true.
3056  if(present(dealloc))ldealloc = dealloc
3057  if (ldealloc) then
3058     call delete(this)
3059  else
3060     call nullify(this)
3061  end if
3062  ! With pointer transfer we need to deallocate
3063  ! else bounds might change...
3064  this%t = "c2"
3065  allocate(p%p(size(rhs,1),size(rhs,2))) ! allocate space
3066  p%p = rhs ! copy data over
3067  allocate(this%enc(size(transfer(p, local_enc_type)))) ! allocate encoding
3068  this%enc(:) = transfer(p, local_enc_type) ! transfer pointer type to the encoding
3069  ! We already have shipped it
3070  nullify(p%p)
3071end subroutine assign_set_c2
3072subroutine assign_get_c2(lhs,this,success)
3073  complex(sp), intent(out), dimension(:,:) :: lhs
3074  type(variable_t), intent(in) :: this
3075  logical, intent(out), optional :: success
3076  logical :: lsuccess
3077  type :: pt
3078    complex(sp), pointer , dimension(:,:) :: p => null()
3079  end type
3080  type(pt) :: p
3081  lsuccess = this%t == "c2"
3082  if (lsuccess) then
3083    p = transfer(this%enc,p) ! retrieve pointer encoding
3084    lsuccess = all(shape(p%p)==shape(lhs)) !&
3085     ! .and. all((lbound(p%p) == lbound(lhs))) &
3086     ! .and. all((ubound(p%p) == ubound(lhs)))
3087  end if
3088  if (present(success)) success = lsuccess
3089  if (.not. lsuccess) return
3090  lhs = p%p
3091end subroutine assign_get_c2
3092subroutine associate_get_c2(lhs,this,dealloc,success)
3093  complex(sp), pointer , dimension(:,:) :: lhs
3094  type(variable_t), intent(in) :: this
3095  logical, intent(in), optional :: dealloc
3096  logical, intent(out), optional :: success
3097  logical :: ldealloc, lsuccess
3098  type :: pt
3099    complex(sp), pointer , dimension(:,:) :: p => null()
3100  end type
3101  type(pt) :: p
3102  lsuccess = this%t == "c2"
3103  if (present(success)) success = lsuccess
3104  ! ASSOCIATION in fortran is per default non-destructive
3105  ldealloc = .false.
3106  if(present(dealloc))ldealloc = dealloc
3107  ! there is one problem, say if lhs is not nullified...
3108  if (ldealloc.and.associated(lhs)) then
3109     deallocate(lhs)
3110     nullify(lhs)
3111  end if
3112  if (.not. lsuccess ) return
3113  p = transfer(this%enc,p) ! retrieve pointer encoding
3114  lhs => p%p
3115end subroutine associate_get_c2
3116subroutine associate_set_c2(this,rhs,dealloc)
3117  type(variable_t), intent(inout) :: this
3118  complex(sp), intent(in), dimension(:,:), target :: rhs
3119  logical, intent(in), optional :: dealloc
3120  logical :: ldealloc
3121  type :: pt
3122    complex(sp), pointer , dimension(:,:) :: p => null()
3123  end type
3124  type(pt) :: p
3125  ! ASSOCIATION in fortran is per default non-destructive
3126  ldealloc = .false.
3127  if(present(dealloc))ldealloc = dealloc
3128  if (ldealloc) then
3129     call delete(this)
3130  else
3131     call nullify(this)
3132  end if
3133  this%t = "c2"
3134  p%p => rhs
3135  allocate(this%enc(size(transfer(p, local_enc_type)))) ! allocate encoding
3136  this%enc(:) = transfer(p, local_enc_type) ! transfer pointer type to the encoding
3137end subroutine associate_set_c2
3138pure function associatd_l_c2(lhs,this) result(ret)
3139  complex(sp), pointer , dimension(:,:) :: lhs
3140  type(variable_t), intent(in) :: this
3141  logical :: ret
3142  type :: pt
3143    complex(sp), pointer , dimension(:,:) :: p
3144  end type
3145  type(pt) :: p
3146  ret = this%t == "c2"
3147  if (ret) then
3148     nullify(p%p)
3149     p = transfer(this%enc,p)
3150     ret = associated(lhs,p%p)
3151  endif
3152end function associatd_l_c2
3153pure function associatd_r_c2(this,rhs) result(ret)
3154  type(variable_t), intent(in) :: this
3155  complex(sp), pointer , dimension(:,:) :: rhs
3156  logical :: ret
3157  type :: pt
3158    complex(sp), pointer , dimension(:,:) :: p
3159  end type
3160  type(pt) :: p
3161  ret = this%t == "c2"
3162  if (ret) then
3163     nullify(p%p)
3164     p = transfer(this%enc,p)
3165     ret = associated(p%p,rhs)
3166  endif
3167end function associatd_r_c2
3168! All boolean functions
3169subroutine assign_set_c3(this,rhs,dealloc)
3170  type(variable_t), intent(inout) :: this
3171  complex(sp), intent(in), dimension(:,:,:) :: rhs
3172  logical, intent(in), optional :: dealloc
3173  logical :: ldealloc
3174  type :: pt
3175    complex(sp), pointer , dimension(:,:,:) :: p => null()
3176  end type
3177  type(pt) :: p
3178  ! ASSIGNMENT in fortran is per default destructive
3179  ldealloc = .true.
3180  if(present(dealloc))ldealloc = dealloc
3181  if (ldealloc) then
3182     call delete(this)
3183  else
3184     call nullify(this)
3185  end if
3186  ! With pointer transfer we need to deallocate
3187  ! else bounds might change...
3188  this%t = "c3"
3189  allocate(p%p(size(rhs,1),size(rhs,2),size(rhs,3))) ! allocate space
3190  p%p = rhs ! copy data over
3191  allocate(this%enc(size(transfer(p, local_enc_type)))) ! allocate encoding
3192  this%enc(:) = transfer(p, local_enc_type) ! transfer pointer type to the encoding
3193  ! We already have shipped it
3194  nullify(p%p)
3195end subroutine assign_set_c3
3196subroutine assign_get_c3(lhs,this,success)
3197  complex(sp), intent(out), dimension(:,:,:) :: lhs
3198  type(variable_t), intent(in) :: this
3199  logical, intent(out), optional :: success
3200  logical :: lsuccess
3201  type :: pt
3202    complex(sp), pointer , dimension(:,:,:) :: p => null()
3203  end type
3204  type(pt) :: p
3205  lsuccess = this%t == "c3"
3206  if (lsuccess) then
3207    p = transfer(this%enc,p) ! retrieve pointer encoding
3208    lsuccess = all(shape(p%p)==shape(lhs)) !&
3209     ! .and. all((lbound(p%p) == lbound(lhs))) &
3210     ! .and. all((ubound(p%p) == ubound(lhs)))
3211  end if
3212  if (present(success)) success = lsuccess
3213  if (.not. lsuccess) return
3214  lhs = p%p
3215end subroutine assign_get_c3
3216subroutine associate_get_c3(lhs,this,dealloc,success)
3217  complex(sp), pointer , dimension(:,:,:) :: lhs
3218  type(variable_t), intent(in) :: this
3219  logical, intent(in), optional :: dealloc
3220  logical, intent(out), optional :: success
3221  logical :: ldealloc, lsuccess
3222  type :: pt
3223    complex(sp), pointer , dimension(:,:,:) :: p => null()
3224  end type
3225  type(pt) :: p
3226  lsuccess = this%t == "c3"
3227  if (present(success)) success = lsuccess
3228  ! ASSOCIATION in fortran is per default non-destructive
3229  ldealloc = .false.
3230  if(present(dealloc))ldealloc = dealloc
3231  ! there is one problem, say if lhs is not nullified...
3232  if (ldealloc.and.associated(lhs)) then
3233     deallocate(lhs)
3234     nullify(lhs)
3235  end if
3236  if (.not. lsuccess ) return
3237  p = transfer(this%enc,p) ! retrieve pointer encoding
3238  lhs => p%p
3239end subroutine associate_get_c3
3240subroutine associate_set_c3(this,rhs,dealloc)
3241  type(variable_t), intent(inout) :: this
3242  complex(sp), intent(in), dimension(:,:,:), target :: rhs
3243  logical, intent(in), optional :: dealloc
3244  logical :: ldealloc
3245  type :: pt
3246    complex(sp), pointer , dimension(:,:,:) :: p => null()
3247  end type
3248  type(pt) :: p
3249  ! ASSOCIATION in fortran is per default non-destructive
3250  ldealloc = .false.
3251  if(present(dealloc))ldealloc = dealloc
3252  if (ldealloc) then
3253     call delete(this)
3254  else
3255     call nullify(this)
3256  end if
3257  this%t = "c3"
3258  p%p => rhs
3259  allocate(this%enc(size(transfer(p, local_enc_type)))) ! allocate encoding
3260  this%enc(:) = transfer(p, local_enc_type) ! transfer pointer type to the encoding
3261end subroutine associate_set_c3
3262pure function associatd_l_c3(lhs,this) result(ret)
3263  complex(sp), pointer , dimension(:,:,:) :: lhs
3264  type(variable_t), intent(in) :: this
3265  logical :: ret
3266  type :: pt
3267    complex(sp), pointer , dimension(:,:,:) :: p
3268  end type
3269  type(pt) :: p
3270  ret = this%t == "c3"
3271  if (ret) then
3272     nullify(p%p)
3273     p = transfer(this%enc,p)
3274     ret = associated(lhs,p%p)
3275  endif
3276end function associatd_l_c3
3277pure function associatd_r_c3(this,rhs) result(ret)
3278  type(variable_t), intent(in) :: this
3279  complex(sp), pointer , dimension(:,:,:) :: rhs
3280  logical :: ret
3281  type :: pt
3282    complex(sp), pointer , dimension(:,:,:) :: p
3283  end type
3284  type(pt) :: p
3285  ret = this%t == "c3"
3286  if (ret) then
3287     nullify(p%p)
3288     p = transfer(this%enc,p)
3289     ret = associated(p%p,rhs)
3290  endif
3291end function associatd_r_c3
3292! All boolean functions
3293subroutine assign_set_z0(this,rhs,dealloc)
3294  type(variable_t), intent(inout) :: this
3295  complex(dp), intent(in) :: rhs
3296  logical, intent(in), optional :: dealloc
3297  logical :: ldealloc
3298  type :: pt
3299    complex(dp), pointer :: p => null()
3300  end type
3301  type(pt) :: p
3302  ! ASSIGNMENT in fortran is per default destructive
3303  ldealloc = .true.
3304  if(present(dealloc))ldealloc = dealloc
3305  if (ldealloc) then
3306     call delete(this)
3307  else
3308     call nullify(this)
3309  end if
3310  ! With pointer transfer we need to deallocate
3311  ! else bounds might change...
3312  this%t = "z0"
3313  allocate(p%p) ! allocate space
3314  p%p = rhs ! copy data over
3315  allocate(this%enc(size(transfer(p, local_enc_type)))) ! allocate encoding
3316  this%enc(:) = transfer(p, local_enc_type) ! transfer pointer type to the encoding
3317  ! We already have shipped it
3318  nullify(p%p)
3319end subroutine assign_set_z0
3320subroutine assign_get_z0(lhs,this,success)
3321  complex(dp), intent(out) :: lhs
3322  type(variable_t), intent(in) :: this
3323  logical, intent(out), optional :: success
3324  logical :: lsuccess
3325  type :: pt
3326    complex(dp), pointer :: p => null()
3327  end type
3328  type(pt) :: p
3329  lsuccess = this%t == "z0"
3330  if (present(success)) success = lsuccess
3331  if (.not. lsuccess) return
3332  p = transfer(this%enc,p) ! retrieve pointer encoding
3333  lhs = p%p
3334end subroutine assign_get_z0
3335subroutine associate_get_z0(lhs,this,dealloc,success)
3336  complex(dp), pointer :: lhs
3337  type(variable_t), intent(in) :: this
3338  logical, intent(in), optional :: dealloc
3339  logical, intent(out), optional :: success
3340  logical :: ldealloc, lsuccess
3341  type :: pt
3342    complex(dp), pointer :: p => null()
3343  end type
3344  type(pt) :: p
3345  lsuccess = this%t == "z0"
3346  if (present(success)) success = lsuccess
3347  ! ASSOCIATION in fortran is per default non-destructive
3348  ldealloc = .false.
3349  if(present(dealloc))ldealloc = dealloc
3350  ! there is one problem, say if lhs is not nullified...
3351  if (ldealloc.and.associated(lhs)) then
3352     deallocate(lhs)
3353     nullify(lhs)
3354  end if
3355  if (.not. lsuccess ) return
3356  p = transfer(this%enc,p) ! retrieve pointer encoding
3357  lhs => p%p
3358end subroutine associate_get_z0
3359subroutine associate_set_z0(this,rhs,dealloc)
3360  type(variable_t), intent(inout) :: this
3361  complex(dp), intent(in), target :: rhs
3362  logical, intent(in), optional :: dealloc
3363  logical :: ldealloc
3364  type :: pt
3365    complex(dp), pointer :: p => null()
3366  end type
3367  type(pt) :: p
3368  ! ASSOCIATION in fortran is per default non-destructive
3369  ldealloc = .false.
3370  if(present(dealloc))ldealloc = dealloc
3371  if (ldealloc) then
3372     call delete(this)
3373  else
3374     call nullify(this)
3375  end if
3376  this%t = "z0"
3377  p%p => rhs
3378  allocate(this%enc(size(transfer(p, local_enc_type)))) ! allocate encoding
3379  this%enc(:) = transfer(p, local_enc_type) ! transfer pointer type to the encoding
3380end subroutine associate_set_z0
3381pure function associatd_l_z0(lhs,this) result(ret)
3382  complex(dp), pointer :: lhs
3383  type(variable_t), intent(in) :: this
3384  logical :: ret
3385  type :: pt
3386    complex(dp), pointer :: p
3387  end type
3388  type(pt) :: p
3389  ret = this%t == "z0"
3390  if (ret) then
3391     nullify(p%p)
3392     p = transfer(this%enc,p)
3393     ret = associated(lhs,p%p)
3394  endif
3395end function associatd_l_z0
3396pure function associatd_r_z0(this,rhs) result(ret)
3397  type(variable_t), intent(in) :: this
3398  complex(dp), pointer :: rhs
3399  logical :: ret
3400  type :: pt
3401    complex(dp), pointer :: p
3402  end type
3403  type(pt) :: p
3404  ret = this%t == "z0"
3405  if (ret) then
3406     nullify(p%p)
3407     p = transfer(this%enc,p)
3408     ret = associated(p%p,rhs)
3409  endif
3410end function associatd_r_z0
3411! All boolean functions
3412subroutine assign_set_z1(this,rhs,dealloc)
3413  type(variable_t), intent(inout) :: this
3414  complex(dp), intent(in), dimension(:) :: rhs
3415  logical, intent(in), optional :: dealloc
3416  logical :: ldealloc
3417  type :: pt
3418    complex(dp), pointer , dimension(:) :: p => null()
3419  end type
3420  type(pt) :: p
3421  ! ASSIGNMENT in fortran is per default destructive
3422  ldealloc = .true.
3423  if(present(dealloc))ldealloc = dealloc
3424  if (ldealloc) then
3425     call delete(this)
3426  else
3427     call nullify(this)
3428  end if
3429  ! With pointer transfer we need to deallocate
3430  ! else bounds might change...
3431  this%t = "z1"
3432  allocate(p%p(size(rhs))) ! allocate space
3433  p%p = rhs ! copy data over
3434  allocate(this%enc(size(transfer(p, local_enc_type)))) ! allocate encoding
3435  this%enc(:) = transfer(p, local_enc_type) ! transfer pointer type to the encoding
3436  ! We already have shipped it
3437  nullify(p%p)
3438end subroutine assign_set_z1
3439subroutine assign_get_z1(lhs,this,success)
3440  complex(dp), intent(out), dimension(:) :: lhs
3441  type(variable_t), intent(in) :: this
3442  logical, intent(out), optional :: success
3443  logical :: lsuccess
3444  type :: pt
3445    complex(dp), pointer , dimension(:) :: p => null()
3446  end type
3447  type(pt) :: p
3448  lsuccess = this%t == "z1"
3449  if (lsuccess) then
3450    p = transfer(this%enc,p) ! retrieve pointer encoding
3451    lsuccess = all(shape(p%p)==shape(lhs)) !&
3452     ! .and. all((lbound(p%p) == lbound(lhs))) &
3453     ! .and. all((ubound(p%p) == ubound(lhs)))
3454  end if
3455  if (present(success)) success = lsuccess
3456  if (.not. lsuccess) return
3457  lhs = p%p
3458end subroutine assign_get_z1
3459subroutine associate_get_z1(lhs,this,dealloc,success)
3460  complex(dp), pointer , dimension(:) :: lhs
3461  type(variable_t), intent(in) :: this
3462  logical, intent(in), optional :: dealloc
3463  logical, intent(out), optional :: success
3464  logical :: ldealloc, lsuccess
3465  type :: pt
3466    complex(dp), pointer , dimension(:) :: p => null()
3467  end type
3468  type(pt) :: p
3469  lsuccess = this%t == "z1"
3470  if (present(success)) success = lsuccess
3471  ! ASSOCIATION in fortran is per default non-destructive
3472  ldealloc = .false.
3473  if(present(dealloc))ldealloc = dealloc
3474  ! there is one problem, say if lhs is not nullified...
3475  if (ldealloc.and.associated(lhs)) then
3476     deallocate(lhs)
3477     nullify(lhs)
3478  end if
3479  if (.not. lsuccess ) return
3480  p = transfer(this%enc,p) ! retrieve pointer encoding
3481  lhs => p%p
3482end subroutine associate_get_z1
3483subroutine associate_set_z1(this,rhs,dealloc)
3484  type(variable_t), intent(inout) :: this
3485  complex(dp), intent(in), dimension(:), target :: rhs
3486  logical, intent(in), optional :: dealloc
3487  logical :: ldealloc
3488  type :: pt
3489    complex(dp), pointer , dimension(:) :: p => null()
3490  end type
3491  type(pt) :: p
3492  ! ASSOCIATION in fortran is per default non-destructive
3493  ldealloc = .false.
3494  if(present(dealloc))ldealloc = dealloc
3495  if (ldealloc) then
3496     call delete(this)
3497  else
3498     call nullify(this)
3499  end if
3500  this%t = "z1"
3501  p%p => rhs
3502  allocate(this%enc(size(transfer(p, local_enc_type)))) ! allocate encoding
3503  this%enc(:) = transfer(p, local_enc_type) ! transfer pointer type to the encoding
3504end subroutine associate_set_z1
3505pure function associatd_l_z1(lhs,this) result(ret)
3506  complex(dp), pointer , dimension(:) :: lhs
3507  type(variable_t), intent(in) :: this
3508  logical :: ret
3509  type :: pt
3510    complex(dp), pointer , dimension(:) :: p
3511  end type
3512  type(pt) :: p
3513  ret = this%t == "z1"
3514  if (ret) then
3515     nullify(p%p)
3516     p = transfer(this%enc,p)
3517     ret = associated(lhs,p%p)
3518  endif
3519end function associatd_l_z1
3520pure function associatd_r_z1(this,rhs) result(ret)
3521  type(variable_t), intent(in) :: this
3522  complex(dp), pointer , dimension(:) :: rhs
3523  logical :: ret
3524  type :: pt
3525    complex(dp), pointer , dimension(:) :: p
3526  end type
3527  type(pt) :: p
3528  ret = this%t == "z1"
3529  if (ret) then
3530     nullify(p%p)
3531     p = transfer(this%enc,p)
3532     ret = associated(p%p,rhs)
3533  endif
3534end function associatd_r_z1
3535! All boolean functions
3536subroutine assign_set_z2(this,rhs,dealloc)
3537  type(variable_t), intent(inout) :: this
3538  complex(dp), intent(in), dimension(:,:) :: rhs
3539  logical, intent(in), optional :: dealloc
3540  logical :: ldealloc
3541  type :: pt
3542    complex(dp), pointer , dimension(:,:) :: p => null()
3543  end type
3544  type(pt) :: p
3545  ! ASSIGNMENT in fortran is per default destructive
3546  ldealloc = .true.
3547  if(present(dealloc))ldealloc = dealloc
3548  if (ldealloc) then
3549     call delete(this)
3550  else
3551     call nullify(this)
3552  end if
3553  ! With pointer transfer we need to deallocate
3554  ! else bounds might change...
3555  this%t = "z2"
3556  allocate(p%p(size(rhs,1),size(rhs,2))) ! allocate space
3557  p%p = rhs ! copy data over
3558  allocate(this%enc(size(transfer(p, local_enc_type)))) ! allocate encoding
3559  this%enc(:) = transfer(p, local_enc_type) ! transfer pointer type to the encoding
3560  ! We already have shipped it
3561  nullify(p%p)
3562end subroutine assign_set_z2
3563subroutine assign_get_z2(lhs,this,success)
3564  complex(dp), intent(out), dimension(:,:) :: lhs
3565  type(variable_t), intent(in) :: this
3566  logical, intent(out), optional :: success
3567  logical :: lsuccess
3568  type :: pt
3569    complex(dp), pointer , dimension(:,:) :: p => null()
3570  end type
3571  type(pt) :: p
3572  lsuccess = this%t == "z2"
3573  if (lsuccess) then
3574    p = transfer(this%enc,p) ! retrieve pointer encoding
3575    lsuccess = all(shape(p%p)==shape(lhs)) !&
3576     ! .and. all((lbound(p%p) == lbound(lhs))) &
3577     ! .and. all((ubound(p%p) == ubound(lhs)))
3578  end if
3579  if (present(success)) success = lsuccess
3580  if (.not. lsuccess) return
3581  lhs = p%p
3582end subroutine assign_get_z2
3583subroutine associate_get_z2(lhs,this,dealloc,success)
3584  complex(dp), pointer , dimension(:,:) :: lhs
3585  type(variable_t), intent(in) :: this
3586  logical, intent(in), optional :: dealloc
3587  logical, intent(out), optional :: success
3588  logical :: ldealloc, lsuccess
3589  type :: pt
3590    complex(dp), pointer , dimension(:,:) :: p => null()
3591  end type
3592  type(pt) :: p
3593  lsuccess = this%t == "z2"
3594  if (present(success)) success = lsuccess
3595  ! ASSOCIATION in fortran is per default non-destructive
3596  ldealloc = .false.
3597  if(present(dealloc))ldealloc = dealloc
3598  ! there is one problem, say if lhs is not nullified...
3599  if (ldealloc.and.associated(lhs)) then
3600     deallocate(lhs)
3601     nullify(lhs)
3602  end if
3603  if (.not. lsuccess ) return
3604  p = transfer(this%enc,p) ! retrieve pointer encoding
3605  lhs => p%p
3606end subroutine associate_get_z2
3607subroutine associate_set_z2(this,rhs,dealloc)
3608  type(variable_t), intent(inout) :: this
3609  complex(dp), intent(in), dimension(:,:), target :: rhs
3610  logical, intent(in), optional :: dealloc
3611  logical :: ldealloc
3612  type :: pt
3613    complex(dp), pointer , dimension(:,:) :: p => null()
3614  end type
3615  type(pt) :: p
3616  ! ASSOCIATION in fortran is per default non-destructive
3617  ldealloc = .false.
3618  if(present(dealloc))ldealloc = dealloc
3619  if (ldealloc) then
3620     call delete(this)
3621  else
3622     call nullify(this)
3623  end if
3624  this%t = "z2"
3625  p%p => rhs
3626  allocate(this%enc(size(transfer(p, local_enc_type)))) ! allocate encoding
3627  this%enc(:) = transfer(p, local_enc_type) ! transfer pointer type to the encoding
3628end subroutine associate_set_z2
3629pure function associatd_l_z2(lhs,this) result(ret)
3630  complex(dp), pointer , dimension(:,:) :: lhs
3631  type(variable_t), intent(in) :: this
3632  logical :: ret
3633  type :: pt
3634    complex(dp), pointer , dimension(:,:) :: p
3635  end type
3636  type(pt) :: p
3637  ret = this%t == "z2"
3638  if (ret) then
3639     nullify(p%p)
3640     p = transfer(this%enc,p)
3641     ret = associated(lhs,p%p)
3642  endif
3643end function associatd_l_z2
3644pure function associatd_r_z2(this,rhs) result(ret)
3645  type(variable_t), intent(in) :: this
3646  complex(dp), pointer , dimension(:,:) :: rhs
3647  logical :: ret
3648  type :: pt
3649    complex(dp), pointer , dimension(:,:) :: p
3650  end type
3651  type(pt) :: p
3652  ret = this%t == "z2"
3653  if (ret) then
3654     nullify(p%p)
3655     p = transfer(this%enc,p)
3656     ret = associated(p%p,rhs)
3657  endif
3658end function associatd_r_z2
3659! All boolean functions
3660subroutine assign_set_z3(this,rhs,dealloc)
3661  type(variable_t), intent(inout) :: this
3662  complex(dp), intent(in), dimension(:,:,:) :: rhs
3663  logical, intent(in), optional :: dealloc
3664  logical :: ldealloc
3665  type :: pt
3666    complex(dp), pointer , dimension(:,:,:) :: p => null()
3667  end type
3668  type(pt) :: p
3669  ! ASSIGNMENT in fortran is per default destructive
3670  ldealloc = .true.
3671  if(present(dealloc))ldealloc = dealloc
3672  if (ldealloc) then
3673     call delete(this)
3674  else
3675     call nullify(this)
3676  end if
3677  ! With pointer transfer we need to deallocate
3678  ! else bounds might change...
3679  this%t = "z3"
3680  allocate(p%p(size(rhs,1),size(rhs,2),size(rhs,3))) ! allocate space
3681  p%p = rhs ! copy data over
3682  allocate(this%enc(size(transfer(p, local_enc_type)))) ! allocate encoding
3683  this%enc(:) = transfer(p, local_enc_type) ! transfer pointer type to the encoding
3684  ! We already have shipped it
3685  nullify(p%p)
3686end subroutine assign_set_z3
3687subroutine assign_get_z3(lhs,this,success)
3688  complex(dp), intent(out), dimension(:,:,:) :: lhs
3689  type(variable_t), intent(in) :: this
3690  logical, intent(out), optional :: success
3691  logical :: lsuccess
3692  type :: pt
3693    complex(dp), pointer , dimension(:,:,:) :: p => null()
3694  end type
3695  type(pt) :: p
3696  lsuccess = this%t == "z3"
3697  if (lsuccess) then
3698    p = transfer(this%enc,p) ! retrieve pointer encoding
3699    lsuccess = all(shape(p%p)==shape(lhs)) !&
3700     ! .and. all((lbound(p%p) == lbound(lhs))) &
3701     ! .and. all((ubound(p%p) == ubound(lhs)))
3702  end if
3703  if (present(success)) success = lsuccess
3704  if (.not. lsuccess) return
3705  lhs = p%p
3706end subroutine assign_get_z3
3707subroutine associate_get_z3(lhs,this,dealloc,success)
3708  complex(dp), pointer , dimension(:,:,:) :: lhs
3709  type(variable_t), intent(in) :: this
3710  logical, intent(in), optional :: dealloc
3711  logical, intent(out), optional :: success
3712  logical :: ldealloc, lsuccess
3713  type :: pt
3714    complex(dp), pointer , dimension(:,:,:) :: p => null()
3715  end type
3716  type(pt) :: p
3717  lsuccess = this%t == "z3"
3718  if (present(success)) success = lsuccess
3719  ! ASSOCIATION in fortran is per default non-destructive
3720  ldealloc = .false.
3721  if(present(dealloc))ldealloc = dealloc
3722  ! there is one problem, say if lhs is not nullified...
3723  if (ldealloc.and.associated(lhs)) then
3724     deallocate(lhs)
3725     nullify(lhs)
3726  end if
3727  if (.not. lsuccess ) return
3728  p = transfer(this%enc,p) ! retrieve pointer encoding
3729  lhs => p%p
3730end subroutine associate_get_z3
3731subroutine associate_set_z3(this,rhs,dealloc)
3732  type(variable_t), intent(inout) :: this
3733  complex(dp), intent(in), dimension(:,:,:), target :: rhs
3734  logical, intent(in), optional :: dealloc
3735  logical :: ldealloc
3736  type :: pt
3737    complex(dp), pointer , dimension(:,:,:) :: p => null()
3738  end type
3739  type(pt) :: p
3740  ! ASSOCIATION in fortran is per default non-destructive
3741  ldealloc = .false.
3742  if(present(dealloc))ldealloc = dealloc
3743  if (ldealloc) then
3744     call delete(this)
3745  else
3746     call nullify(this)
3747  end if
3748  this%t = "z3"
3749  p%p => rhs
3750  allocate(this%enc(size(transfer(p, local_enc_type)))) ! allocate encoding
3751  this%enc(:) = transfer(p, local_enc_type) ! transfer pointer type to the encoding
3752end subroutine associate_set_z3
3753pure function associatd_l_z3(lhs,this) result(ret)
3754  complex(dp), pointer , dimension(:,:,:) :: lhs
3755  type(variable_t), intent(in) :: this
3756  logical :: ret
3757  type :: pt
3758    complex(dp), pointer , dimension(:,:,:) :: p
3759  end type
3760  type(pt) :: p
3761  ret = this%t == "z3"
3762  if (ret) then
3763     nullify(p%p)
3764     p = transfer(this%enc,p)
3765     ret = associated(lhs,p%p)
3766  endif
3767end function associatd_l_z3
3768pure function associatd_r_z3(this,rhs) result(ret)
3769  type(variable_t), intent(in) :: this
3770  complex(dp), pointer , dimension(:,:,:) :: rhs
3771  logical :: ret
3772  type :: pt
3773    complex(dp), pointer , dimension(:,:,:) :: p
3774  end type
3775  type(pt) :: p
3776  ret = this%t == "z3"
3777  if (ret) then
3778     nullify(p%p)
3779     p = transfer(this%enc,p)
3780     ret = associated(p%p,rhs)
3781  endif
3782end function associatd_r_z3
3783! All boolean functions
3784subroutine assign_set_b0(this,rhs,dealloc)
3785  type(variable_t), intent(inout) :: this
3786  logical, intent(in) :: rhs
3787  logical, intent(in), optional :: dealloc
3788  logical :: ldealloc
3789  type :: pt
3790    logical, pointer :: p => null()
3791  end type
3792  type(pt) :: p
3793  ! ASSIGNMENT in fortran is per default destructive
3794  ldealloc = .true.
3795  if(present(dealloc))ldealloc = dealloc
3796  if (ldealloc) then
3797     call delete(this)
3798  else
3799     call nullify(this)
3800  end if
3801  ! With pointer transfer we need to deallocate
3802  ! else bounds might change...
3803  this%t = "b0"
3804  allocate(p%p) ! allocate space
3805  p%p = rhs ! copy data over
3806  allocate(this%enc(size(transfer(p, local_enc_type)))) ! allocate encoding
3807  this%enc(:) = transfer(p, local_enc_type) ! transfer pointer type to the encoding
3808  ! We already have shipped it
3809  nullify(p%p)
3810end subroutine assign_set_b0
3811subroutine assign_get_b0(lhs,this,success)
3812  logical, intent(out) :: lhs
3813  type(variable_t), intent(in) :: this
3814  logical, intent(out), optional :: success
3815  logical :: lsuccess
3816  type :: pt
3817    logical, pointer :: p => null()
3818  end type
3819  type(pt) :: p
3820  lsuccess = this%t == "b0"
3821  if (present(success)) success = lsuccess
3822  if (.not. lsuccess) return
3823  p = transfer(this%enc,p) ! retrieve pointer encoding
3824  lhs = p%p
3825end subroutine assign_get_b0
3826subroutine associate_get_b0(lhs,this,dealloc,success)
3827  logical, pointer :: lhs
3828  type(variable_t), intent(in) :: this
3829  logical, intent(in), optional :: dealloc
3830  logical, intent(out), optional :: success
3831  logical :: ldealloc, lsuccess
3832  type :: pt
3833    logical, pointer :: p => null()
3834  end type
3835  type(pt) :: p
3836  lsuccess = this%t == "b0"
3837  if (present(success)) success = lsuccess
3838  ! ASSOCIATION in fortran is per default non-destructive
3839  ldealloc = .false.
3840  if(present(dealloc))ldealloc = dealloc
3841  ! there is one problem, say if lhs is not nullified...
3842  if (ldealloc.and.associated(lhs)) then
3843     deallocate(lhs)
3844     nullify(lhs)
3845  end if
3846  if (.not. lsuccess ) return
3847  p = transfer(this%enc,p) ! retrieve pointer encoding
3848  lhs => p%p
3849end subroutine associate_get_b0
3850subroutine associate_set_b0(this,rhs,dealloc)
3851  type(variable_t), intent(inout) :: this
3852  logical, intent(in), target :: rhs
3853  logical, intent(in), optional :: dealloc
3854  logical :: ldealloc
3855  type :: pt
3856    logical, pointer :: p => null()
3857  end type
3858  type(pt) :: p
3859  ! ASSOCIATION in fortran is per default non-destructive
3860  ldealloc = .false.
3861  if(present(dealloc))ldealloc = dealloc
3862  if (ldealloc) then
3863     call delete(this)
3864  else
3865     call nullify(this)
3866  end if
3867  this%t = "b0"
3868  p%p => rhs
3869  allocate(this%enc(size(transfer(p, local_enc_type)))) ! allocate encoding
3870  this%enc(:) = transfer(p, local_enc_type) ! transfer pointer type to the encoding
3871end subroutine associate_set_b0
3872pure function associatd_l_b0(lhs,this) result(ret)
3873  logical, pointer :: lhs
3874  type(variable_t), intent(in) :: this
3875  logical :: ret
3876  type :: pt
3877    logical, pointer :: p
3878  end type
3879  type(pt) :: p
3880  ret = this%t == "b0"
3881  if (ret) then
3882     nullify(p%p)
3883     p = transfer(this%enc,p)
3884     ret = associated(lhs,p%p)
3885  endif
3886end function associatd_l_b0
3887pure function associatd_r_b0(this,rhs) result(ret)
3888  type(variable_t), intent(in) :: this
3889  logical, pointer :: rhs
3890  logical :: ret
3891  type :: pt
3892    logical, pointer :: p
3893  end type
3894  type(pt) :: p
3895  ret = this%t == "b0"
3896  if (ret) then
3897     nullify(p%p)
3898     p = transfer(this%enc,p)
3899     ret = associated(p%p,rhs)
3900  endif
3901end function associatd_r_b0
3902! All boolean functions
3903subroutine assign_set_b1(this,rhs,dealloc)
3904  type(variable_t), intent(inout) :: this
3905  logical, intent(in), dimension(:) :: rhs
3906  logical, intent(in), optional :: dealloc
3907  logical :: ldealloc
3908  type :: pt
3909    logical, pointer , dimension(:) :: p => null()
3910  end type
3911  type(pt) :: p
3912  ! ASSIGNMENT in fortran is per default destructive
3913  ldealloc = .true.
3914  if(present(dealloc))ldealloc = dealloc
3915  if (ldealloc) then
3916     call delete(this)
3917  else
3918     call nullify(this)
3919  end if
3920  ! With pointer transfer we need to deallocate
3921  ! else bounds might change...
3922  this%t = "b1"
3923  allocate(p%p(size(rhs))) ! allocate space
3924  p%p = rhs ! copy data over
3925  allocate(this%enc(size(transfer(p, local_enc_type)))) ! allocate encoding
3926  this%enc(:) = transfer(p, local_enc_type) ! transfer pointer type to the encoding
3927  ! We already have shipped it
3928  nullify(p%p)
3929end subroutine assign_set_b1
3930subroutine assign_get_b1(lhs,this,success)
3931  logical, intent(out), dimension(:) :: lhs
3932  type(variable_t), intent(in) :: this
3933  logical, intent(out), optional :: success
3934  logical :: lsuccess
3935  type :: pt
3936    logical, pointer , dimension(:) :: p => null()
3937  end type
3938  type(pt) :: p
3939  lsuccess = this%t == "b1"
3940  if (lsuccess) then
3941    p = transfer(this%enc,p) ! retrieve pointer encoding
3942    lsuccess = all(shape(p%p)==shape(lhs)) !&
3943     ! .and. all((lbound(p%p) == lbound(lhs))) &
3944     ! .and. all((ubound(p%p) == ubound(lhs)))
3945  end if
3946  if (present(success)) success = lsuccess
3947  if (.not. lsuccess) return
3948  lhs = p%p
3949end subroutine assign_get_b1
3950subroutine associate_get_b1(lhs,this,dealloc,success)
3951  logical, pointer , dimension(:) :: lhs
3952  type(variable_t), intent(in) :: this
3953  logical, intent(in), optional :: dealloc
3954  logical, intent(out), optional :: success
3955  logical :: ldealloc, lsuccess
3956  type :: pt
3957    logical, pointer , dimension(:) :: p => null()
3958  end type
3959  type(pt) :: p
3960  lsuccess = this%t == "b1"
3961  if (present(success)) success = lsuccess
3962  ! ASSOCIATION in fortran is per default non-destructive
3963  ldealloc = .false.
3964  if(present(dealloc))ldealloc = dealloc
3965  ! there is one problem, say if lhs is not nullified...
3966  if (ldealloc.and.associated(lhs)) then
3967     deallocate(lhs)
3968     nullify(lhs)
3969  end if
3970  if (.not. lsuccess ) return
3971  p = transfer(this%enc,p) ! retrieve pointer encoding
3972  lhs => p%p
3973end subroutine associate_get_b1
3974subroutine associate_set_b1(this,rhs,dealloc)
3975  type(variable_t), intent(inout) :: this
3976  logical, intent(in), dimension(:), target :: rhs
3977  logical, intent(in), optional :: dealloc
3978  logical :: ldealloc
3979  type :: pt
3980    logical, pointer , dimension(:) :: p => null()
3981  end type
3982  type(pt) :: p
3983  ! ASSOCIATION in fortran is per default non-destructive
3984  ldealloc = .false.
3985  if(present(dealloc))ldealloc = dealloc
3986  if (ldealloc) then
3987     call delete(this)
3988  else
3989     call nullify(this)
3990  end if
3991  this%t = "b1"
3992  p%p => rhs
3993  allocate(this%enc(size(transfer(p, local_enc_type)))) ! allocate encoding
3994  this%enc(:) = transfer(p, local_enc_type) ! transfer pointer type to the encoding
3995end subroutine associate_set_b1
3996pure function associatd_l_b1(lhs,this) result(ret)
3997  logical, pointer , dimension(:) :: lhs
3998  type(variable_t), intent(in) :: this
3999  logical :: ret
4000  type :: pt
4001    logical, pointer , dimension(:) :: p
4002  end type
4003  type(pt) :: p
4004  ret = this%t == "b1"
4005  if (ret) then
4006     nullify(p%p)
4007     p = transfer(this%enc,p)
4008     ret = associated(lhs,p%p)
4009  endif
4010end function associatd_l_b1
4011pure function associatd_r_b1(this,rhs) result(ret)
4012  type(variable_t), intent(in) :: this
4013  logical, pointer , dimension(:) :: rhs
4014  logical :: ret
4015  type :: pt
4016    logical, pointer , dimension(:) :: p
4017  end type
4018  type(pt) :: p
4019  ret = this%t == "b1"
4020  if (ret) then
4021     nullify(p%p)
4022     p = transfer(this%enc,p)
4023     ret = associated(p%p,rhs)
4024  endif
4025end function associatd_r_b1
4026! All boolean functions
4027subroutine assign_set_b2(this,rhs,dealloc)
4028  type(variable_t), intent(inout) :: this
4029  logical, intent(in), dimension(:,:) :: rhs
4030  logical, intent(in), optional :: dealloc
4031  logical :: ldealloc
4032  type :: pt
4033    logical, pointer , dimension(:,:) :: p => null()
4034  end type
4035  type(pt) :: p
4036  ! ASSIGNMENT in fortran is per default destructive
4037  ldealloc = .true.
4038  if(present(dealloc))ldealloc = dealloc
4039  if (ldealloc) then
4040     call delete(this)
4041  else
4042     call nullify(this)
4043  end if
4044  ! With pointer transfer we need to deallocate
4045  ! else bounds might change...
4046  this%t = "b2"
4047  allocate(p%p(size(rhs,1),size(rhs,2))) ! allocate space
4048  p%p = rhs ! copy data over
4049  allocate(this%enc(size(transfer(p, local_enc_type)))) ! allocate encoding
4050  this%enc(:) = transfer(p, local_enc_type) ! transfer pointer type to the encoding
4051  ! We already have shipped it
4052  nullify(p%p)
4053end subroutine assign_set_b2
4054subroutine assign_get_b2(lhs,this,success)
4055  logical, intent(out), dimension(:,:) :: lhs
4056  type(variable_t), intent(in) :: this
4057  logical, intent(out), optional :: success
4058  logical :: lsuccess
4059  type :: pt
4060    logical, pointer , dimension(:,:) :: p => null()
4061  end type
4062  type(pt) :: p
4063  lsuccess = this%t == "b2"
4064  if (lsuccess) then
4065    p = transfer(this%enc,p) ! retrieve pointer encoding
4066    lsuccess = all(shape(p%p)==shape(lhs)) !&
4067     ! .and. all((lbound(p%p) == lbound(lhs))) &
4068     ! .and. all((ubound(p%p) == ubound(lhs)))
4069  end if
4070  if (present(success)) success = lsuccess
4071  if (.not. lsuccess) return
4072  lhs = p%p
4073end subroutine assign_get_b2
4074subroutine associate_get_b2(lhs,this,dealloc,success)
4075  logical, pointer , dimension(:,:) :: lhs
4076  type(variable_t), intent(in) :: this
4077  logical, intent(in), optional :: dealloc
4078  logical, intent(out), optional :: success
4079  logical :: ldealloc, lsuccess
4080  type :: pt
4081    logical, pointer , dimension(:,:) :: p => null()
4082  end type
4083  type(pt) :: p
4084  lsuccess = this%t == "b2"
4085  if (present(success)) success = lsuccess
4086  ! ASSOCIATION in fortran is per default non-destructive
4087  ldealloc = .false.
4088  if(present(dealloc))ldealloc = dealloc
4089  ! there is one problem, say if lhs is not nullified...
4090  if (ldealloc.and.associated(lhs)) then
4091     deallocate(lhs)
4092     nullify(lhs)
4093  end if
4094  if (.not. lsuccess ) return
4095  p = transfer(this%enc,p) ! retrieve pointer encoding
4096  lhs => p%p
4097end subroutine associate_get_b2
4098subroutine associate_set_b2(this,rhs,dealloc)
4099  type(variable_t), intent(inout) :: this
4100  logical, intent(in), dimension(:,:), target :: rhs
4101  logical, intent(in), optional :: dealloc
4102  logical :: ldealloc
4103  type :: pt
4104    logical, pointer , dimension(:,:) :: p => null()
4105  end type
4106  type(pt) :: p
4107  ! ASSOCIATION in fortran is per default non-destructive
4108  ldealloc = .false.
4109  if(present(dealloc))ldealloc = dealloc
4110  if (ldealloc) then
4111     call delete(this)
4112  else
4113     call nullify(this)
4114  end if
4115  this%t = "b2"
4116  p%p => rhs
4117  allocate(this%enc(size(transfer(p, local_enc_type)))) ! allocate encoding
4118  this%enc(:) = transfer(p, local_enc_type) ! transfer pointer type to the encoding
4119end subroutine associate_set_b2
4120pure function associatd_l_b2(lhs,this) result(ret)
4121  logical, pointer , dimension(:,:) :: lhs
4122  type(variable_t), intent(in) :: this
4123  logical :: ret
4124  type :: pt
4125    logical, pointer , dimension(:,:) :: p
4126  end type
4127  type(pt) :: p
4128  ret = this%t == "b2"
4129  if (ret) then
4130     nullify(p%p)
4131     p = transfer(this%enc,p)
4132     ret = associated(lhs,p%p)
4133  endif
4134end function associatd_l_b2
4135pure function associatd_r_b2(this,rhs) result(ret)
4136  type(variable_t), intent(in) :: this
4137  logical, pointer , dimension(:,:) :: rhs
4138  logical :: ret
4139  type :: pt
4140    logical, pointer , dimension(:,:) :: p
4141  end type
4142  type(pt) :: p
4143  ret = this%t == "b2"
4144  if (ret) then
4145     nullify(p%p)
4146     p = transfer(this%enc,p)
4147     ret = associated(p%p,rhs)
4148  endif
4149end function associatd_r_b2
4150! All boolean functions
4151subroutine assign_set_b3(this,rhs,dealloc)
4152  type(variable_t), intent(inout) :: this
4153  logical, intent(in), dimension(:,:,:) :: rhs
4154  logical, intent(in), optional :: dealloc
4155  logical :: ldealloc
4156  type :: pt
4157    logical, pointer , dimension(:,:,:) :: p => null()
4158  end type
4159  type(pt) :: p
4160  ! ASSIGNMENT in fortran is per default destructive
4161  ldealloc = .true.
4162  if(present(dealloc))ldealloc = dealloc
4163  if (ldealloc) then
4164     call delete(this)
4165  else
4166     call nullify(this)
4167  end if
4168  ! With pointer transfer we need to deallocate
4169  ! else bounds might change...
4170  this%t = "b3"
4171  allocate(p%p(size(rhs,1),size(rhs,2),size(rhs,3))) ! allocate space
4172  p%p = rhs ! copy data over
4173  allocate(this%enc(size(transfer(p, local_enc_type)))) ! allocate encoding
4174  this%enc(:) = transfer(p, local_enc_type) ! transfer pointer type to the encoding
4175  ! We already have shipped it
4176  nullify(p%p)
4177end subroutine assign_set_b3
4178subroutine assign_get_b3(lhs,this,success)
4179  logical, intent(out), dimension(:,:,:) :: lhs
4180  type(variable_t), intent(in) :: this
4181  logical, intent(out), optional :: success
4182  logical :: lsuccess
4183  type :: pt
4184    logical, pointer , dimension(:,:,:) :: p => null()
4185  end type
4186  type(pt) :: p
4187  lsuccess = this%t == "b3"
4188  if (lsuccess) then
4189    p = transfer(this%enc,p) ! retrieve pointer encoding
4190    lsuccess = all(shape(p%p)==shape(lhs)) !&
4191     ! .and. all((lbound(p%p) == lbound(lhs))) &
4192     ! .and. all((ubound(p%p) == ubound(lhs)))
4193  end if
4194  if (present(success)) success = lsuccess
4195  if (.not. lsuccess) return
4196  lhs = p%p
4197end subroutine assign_get_b3
4198subroutine associate_get_b3(lhs,this,dealloc,success)
4199  logical, pointer , dimension(:,:,:) :: lhs
4200  type(variable_t), intent(in) :: this
4201  logical, intent(in), optional :: dealloc
4202  logical, intent(out), optional :: success
4203  logical :: ldealloc, lsuccess
4204  type :: pt
4205    logical, pointer , dimension(:,:,:) :: p => null()
4206  end type
4207  type(pt) :: p
4208  lsuccess = this%t == "b3"
4209  if (present(success)) success = lsuccess
4210  ! ASSOCIATION in fortran is per default non-destructive
4211  ldealloc = .false.
4212  if(present(dealloc))ldealloc = dealloc
4213  ! there is one problem, say if lhs is not nullified...
4214  if (ldealloc.and.associated(lhs)) then
4215     deallocate(lhs)
4216     nullify(lhs)
4217  end if
4218  if (.not. lsuccess ) return
4219  p = transfer(this%enc,p) ! retrieve pointer encoding
4220  lhs => p%p
4221end subroutine associate_get_b3
4222subroutine associate_set_b3(this,rhs,dealloc)
4223  type(variable_t), intent(inout) :: this
4224  logical, intent(in), dimension(:,:,:), target :: rhs
4225  logical, intent(in), optional :: dealloc
4226  logical :: ldealloc
4227  type :: pt
4228    logical, pointer , dimension(:,:,:) :: p => null()
4229  end type
4230  type(pt) :: p
4231  ! ASSOCIATION in fortran is per default non-destructive
4232  ldealloc = .false.
4233  if(present(dealloc))ldealloc = dealloc
4234  if (ldealloc) then
4235     call delete(this)
4236  else
4237     call nullify(this)
4238  end if
4239  this%t = "b3"
4240  p%p => rhs
4241  allocate(this%enc(size(transfer(p, local_enc_type)))) ! allocate encoding
4242  this%enc(:) = transfer(p, local_enc_type) ! transfer pointer type to the encoding
4243end subroutine associate_set_b3
4244pure function associatd_l_b3(lhs,this) result(ret)
4245  logical, pointer , dimension(:,:,:) :: lhs
4246  type(variable_t), intent(in) :: this
4247  logical :: ret
4248  type :: pt
4249    logical, pointer , dimension(:,:,:) :: p
4250  end type
4251  type(pt) :: p
4252  ret = this%t == "b3"
4253  if (ret) then
4254     nullify(p%p)
4255     p = transfer(this%enc,p)
4256     ret = associated(lhs,p%p)
4257  endif
4258end function associatd_l_b3
4259pure function associatd_r_b3(this,rhs) result(ret)
4260  type(variable_t), intent(in) :: this
4261  logical, pointer , dimension(:,:,:) :: rhs
4262  logical :: ret
4263  type :: pt
4264    logical, pointer , dimension(:,:,:) :: p
4265  end type
4266  type(pt) :: p
4267  ret = this%t == "b3"
4268  if (ret) then
4269     nullify(p%p)
4270     p = transfer(this%enc,p)
4271     ret = associated(p%p,rhs)
4272  endif
4273end function associatd_r_b3
4274! All boolean functions
4275subroutine assign_set_h0(this,rhs,dealloc)
4276  type(variable_t), intent(inout) :: this
4277  integer(ih), intent(in) :: rhs
4278  logical, intent(in), optional :: dealloc
4279  logical :: ldealloc
4280  type :: pt
4281    integer(ih), pointer :: p => null()
4282  end type
4283  type(pt) :: p
4284  ! ASSIGNMENT in fortran is per default destructive
4285  ldealloc = .true.
4286  if(present(dealloc))ldealloc = dealloc
4287  if (ldealloc) then
4288     call delete(this)
4289  else
4290     call nullify(this)
4291  end if
4292  ! With pointer transfer we need to deallocate
4293  ! else bounds might change...
4294  this%t = "h0"
4295  allocate(p%p) ! allocate space
4296  p%p = rhs ! copy data over
4297  allocate(this%enc(size(transfer(p, local_enc_type)))) ! allocate encoding
4298  this%enc(:) = transfer(p, local_enc_type) ! transfer pointer type to the encoding
4299  ! We already have shipped it
4300  nullify(p%p)
4301end subroutine assign_set_h0
4302subroutine assign_get_h0(lhs,this,success)
4303  integer(ih), intent(out) :: lhs
4304  type(variable_t), intent(in) :: this
4305  logical, intent(out), optional :: success
4306  logical :: lsuccess
4307  type :: pt
4308    integer(ih), pointer :: p => null()
4309  end type
4310  type(pt) :: p
4311  lsuccess = this%t == "h0"
4312  if (present(success)) success = lsuccess
4313  if (.not. lsuccess) return
4314  p = transfer(this%enc,p) ! retrieve pointer encoding
4315  lhs = p%p
4316end subroutine assign_get_h0
4317subroutine associate_get_h0(lhs,this,dealloc,success)
4318  integer(ih), pointer :: lhs
4319  type(variable_t), intent(in) :: this
4320  logical, intent(in), optional :: dealloc
4321  logical, intent(out), optional :: success
4322  logical :: ldealloc, lsuccess
4323  type :: pt
4324    integer(ih), pointer :: p => null()
4325  end type
4326  type(pt) :: p
4327  lsuccess = this%t == "h0"
4328  if (present(success)) success = lsuccess
4329  ! ASSOCIATION in fortran is per default non-destructive
4330  ldealloc = .false.
4331  if(present(dealloc))ldealloc = dealloc
4332  ! there is one problem, say if lhs is not nullified...
4333  if (ldealloc.and.associated(lhs)) then
4334     deallocate(lhs)
4335     nullify(lhs)
4336  end if
4337  if (.not. lsuccess ) return
4338  p = transfer(this%enc,p) ! retrieve pointer encoding
4339  lhs => p%p
4340end subroutine associate_get_h0
4341subroutine associate_set_h0(this,rhs,dealloc)
4342  type(variable_t), intent(inout) :: this
4343  integer(ih), intent(in), target :: rhs
4344  logical, intent(in), optional :: dealloc
4345  logical :: ldealloc
4346  type :: pt
4347    integer(ih), pointer :: p => null()
4348  end type
4349  type(pt) :: p
4350  ! ASSOCIATION in fortran is per default non-destructive
4351  ldealloc = .false.
4352  if(present(dealloc))ldealloc = dealloc
4353  if (ldealloc) then
4354     call delete(this)
4355  else
4356     call nullify(this)
4357  end if
4358  this%t = "h0"
4359  p%p => rhs
4360  allocate(this%enc(size(transfer(p, local_enc_type)))) ! allocate encoding
4361  this%enc(:) = transfer(p, local_enc_type) ! transfer pointer type to the encoding
4362end subroutine associate_set_h0
4363pure function associatd_l_h0(lhs,this) result(ret)
4364  integer(ih), pointer :: lhs
4365  type(variable_t), intent(in) :: this
4366  logical :: ret
4367  type :: pt
4368    integer(ih), pointer :: p
4369  end type
4370  type(pt) :: p
4371  ret = this%t == "h0"
4372  if (ret) then
4373     nullify(p%p)
4374     p = transfer(this%enc,p)
4375     ret = associated(lhs,p%p)
4376  endif
4377end function associatd_l_h0
4378pure function associatd_r_h0(this,rhs) result(ret)
4379  type(variable_t), intent(in) :: this
4380  integer(ih), pointer :: rhs
4381  logical :: ret
4382  type :: pt
4383    integer(ih), pointer :: p
4384  end type
4385  type(pt) :: p
4386  ret = this%t == "h0"
4387  if (ret) then
4388     nullify(p%p)
4389     p = transfer(this%enc,p)
4390     ret = associated(p%p,rhs)
4391  endif
4392end function associatd_r_h0
4393! All boolean functions
4394subroutine assign_set_h1(this,rhs,dealloc)
4395  type(variable_t), intent(inout) :: this
4396  integer(ih), intent(in), dimension(:) :: rhs
4397  logical, intent(in), optional :: dealloc
4398  logical :: ldealloc
4399  type :: pt
4400    integer(ih), pointer , dimension(:) :: p => null()
4401  end type
4402  type(pt) :: p
4403  ! ASSIGNMENT in fortran is per default destructive
4404  ldealloc = .true.
4405  if(present(dealloc))ldealloc = dealloc
4406  if (ldealloc) then
4407     call delete(this)
4408  else
4409     call nullify(this)
4410  end if
4411  ! With pointer transfer we need to deallocate
4412  ! else bounds might change...
4413  this%t = "h1"
4414  allocate(p%p(size(rhs))) ! allocate space
4415  p%p = rhs ! copy data over
4416  allocate(this%enc(size(transfer(p, local_enc_type)))) ! allocate encoding
4417  this%enc(:) = transfer(p, local_enc_type) ! transfer pointer type to the encoding
4418  ! We already have shipped it
4419  nullify(p%p)
4420end subroutine assign_set_h1
4421subroutine assign_get_h1(lhs,this,success)
4422  integer(ih), intent(out), dimension(:) :: lhs
4423  type(variable_t), intent(in) :: this
4424  logical, intent(out), optional :: success
4425  logical :: lsuccess
4426  type :: pt
4427    integer(ih), pointer , dimension(:) :: p => null()
4428  end type
4429  type(pt) :: p
4430  lsuccess = this%t == "h1"
4431  if (lsuccess) then
4432    p = transfer(this%enc,p) ! retrieve pointer encoding
4433    lsuccess = all(shape(p%p)==shape(lhs)) !&
4434     ! .and. all((lbound(p%p) == lbound(lhs))) &
4435     ! .and. all((ubound(p%p) == ubound(lhs)))
4436  end if
4437  if (present(success)) success = lsuccess
4438  if (.not. lsuccess) return
4439  lhs = p%p
4440end subroutine assign_get_h1
4441subroutine associate_get_h1(lhs,this,dealloc,success)
4442  integer(ih), pointer , dimension(:) :: lhs
4443  type(variable_t), intent(in) :: this
4444  logical, intent(in), optional :: dealloc
4445  logical, intent(out), optional :: success
4446  logical :: ldealloc, lsuccess
4447  type :: pt
4448    integer(ih), pointer , dimension(:) :: p => null()
4449  end type
4450  type(pt) :: p
4451  lsuccess = this%t == "h1"
4452  if (present(success)) success = lsuccess
4453  ! ASSOCIATION in fortran is per default non-destructive
4454  ldealloc = .false.
4455  if(present(dealloc))ldealloc = dealloc
4456  ! there is one problem, say if lhs is not nullified...
4457  if (ldealloc.and.associated(lhs)) then
4458     deallocate(lhs)
4459     nullify(lhs)
4460  end if
4461  if (.not. lsuccess ) return
4462  p = transfer(this%enc,p) ! retrieve pointer encoding
4463  lhs => p%p
4464end subroutine associate_get_h1
4465subroutine associate_set_h1(this,rhs,dealloc)
4466  type(variable_t), intent(inout) :: this
4467  integer(ih), intent(in), dimension(:), target :: rhs
4468  logical, intent(in), optional :: dealloc
4469  logical :: ldealloc
4470  type :: pt
4471    integer(ih), pointer , dimension(:) :: p => null()
4472  end type
4473  type(pt) :: p
4474  ! ASSOCIATION in fortran is per default non-destructive
4475  ldealloc = .false.
4476  if(present(dealloc))ldealloc = dealloc
4477  if (ldealloc) then
4478     call delete(this)
4479  else
4480     call nullify(this)
4481  end if
4482  this%t = "h1"
4483  p%p => rhs
4484  allocate(this%enc(size(transfer(p, local_enc_type)))) ! allocate encoding
4485  this%enc(:) = transfer(p, local_enc_type) ! transfer pointer type to the encoding
4486end subroutine associate_set_h1
4487pure function associatd_l_h1(lhs,this) result(ret)
4488  integer(ih), pointer , dimension(:) :: lhs
4489  type(variable_t), intent(in) :: this
4490  logical :: ret
4491  type :: pt
4492    integer(ih), pointer , dimension(:) :: p
4493  end type
4494  type(pt) :: p
4495  ret = this%t == "h1"
4496  if (ret) then
4497     nullify(p%p)
4498     p = transfer(this%enc,p)
4499     ret = associated(lhs,p%p)
4500  endif
4501end function associatd_l_h1
4502pure function associatd_r_h1(this,rhs) result(ret)
4503  type(variable_t), intent(in) :: this
4504  integer(ih), pointer , dimension(:) :: rhs
4505  logical :: ret
4506  type :: pt
4507    integer(ih), pointer , dimension(:) :: p
4508  end type
4509  type(pt) :: p
4510  ret = this%t == "h1"
4511  if (ret) then
4512     nullify(p%p)
4513     p = transfer(this%enc,p)
4514     ret = associated(p%p,rhs)
4515  endif
4516end function associatd_r_h1
4517! All boolean functions
4518subroutine assign_set_h2(this,rhs,dealloc)
4519  type(variable_t), intent(inout) :: this
4520  integer(ih), intent(in), dimension(:,:) :: rhs
4521  logical, intent(in), optional :: dealloc
4522  logical :: ldealloc
4523  type :: pt
4524    integer(ih), pointer , dimension(:,:) :: p => null()
4525  end type
4526  type(pt) :: p
4527  ! ASSIGNMENT in fortran is per default destructive
4528  ldealloc = .true.
4529  if(present(dealloc))ldealloc = dealloc
4530  if (ldealloc) then
4531     call delete(this)
4532  else
4533     call nullify(this)
4534  end if
4535  ! With pointer transfer we need to deallocate
4536  ! else bounds might change...
4537  this%t = "h2"
4538  allocate(p%p(size(rhs,1),size(rhs,2))) ! allocate space
4539  p%p = rhs ! copy data over
4540  allocate(this%enc(size(transfer(p, local_enc_type)))) ! allocate encoding
4541  this%enc(:) = transfer(p, local_enc_type) ! transfer pointer type to the encoding
4542  ! We already have shipped it
4543  nullify(p%p)
4544end subroutine assign_set_h2
4545subroutine assign_get_h2(lhs,this,success)
4546  integer(ih), intent(out), dimension(:,:) :: lhs
4547  type(variable_t), intent(in) :: this
4548  logical, intent(out), optional :: success
4549  logical :: lsuccess
4550  type :: pt
4551    integer(ih), pointer , dimension(:,:) :: p => null()
4552  end type
4553  type(pt) :: p
4554  lsuccess = this%t == "h2"
4555  if (lsuccess) then
4556    p = transfer(this%enc,p) ! retrieve pointer encoding
4557    lsuccess = all(shape(p%p)==shape(lhs)) !&
4558     ! .and. all((lbound(p%p) == lbound(lhs))) &
4559     ! .and. all((ubound(p%p) == ubound(lhs)))
4560  end if
4561  if (present(success)) success = lsuccess
4562  if (.not. lsuccess) return
4563  lhs = p%p
4564end subroutine assign_get_h2
4565subroutine associate_get_h2(lhs,this,dealloc,success)
4566  integer(ih), pointer , dimension(:,:) :: lhs
4567  type(variable_t), intent(in) :: this
4568  logical, intent(in), optional :: dealloc
4569  logical, intent(out), optional :: success
4570  logical :: ldealloc, lsuccess
4571  type :: pt
4572    integer(ih), pointer , dimension(:,:) :: p => null()
4573  end type
4574  type(pt) :: p
4575  lsuccess = this%t == "h2"
4576  if (present(success)) success = lsuccess
4577  ! ASSOCIATION in fortran is per default non-destructive
4578  ldealloc = .false.
4579  if(present(dealloc))ldealloc = dealloc
4580  ! there is one problem, say if lhs is not nullified...
4581  if (ldealloc.and.associated(lhs)) then
4582     deallocate(lhs)
4583     nullify(lhs)
4584  end if
4585  if (.not. lsuccess ) return
4586  p = transfer(this%enc,p) ! retrieve pointer encoding
4587  lhs => p%p
4588end subroutine associate_get_h2
4589subroutine associate_set_h2(this,rhs,dealloc)
4590  type(variable_t), intent(inout) :: this
4591  integer(ih), intent(in), dimension(:,:), target :: rhs
4592  logical, intent(in), optional :: dealloc
4593  logical :: ldealloc
4594  type :: pt
4595    integer(ih), pointer , dimension(:,:) :: p => null()
4596  end type
4597  type(pt) :: p
4598  ! ASSOCIATION in fortran is per default non-destructive
4599  ldealloc = .false.
4600  if(present(dealloc))ldealloc = dealloc
4601  if (ldealloc) then
4602     call delete(this)
4603  else
4604     call nullify(this)
4605  end if
4606  this%t = "h2"
4607  p%p => rhs
4608  allocate(this%enc(size(transfer(p, local_enc_type)))) ! allocate encoding
4609  this%enc(:) = transfer(p, local_enc_type) ! transfer pointer type to the encoding
4610end subroutine associate_set_h2
4611pure function associatd_l_h2(lhs,this) result(ret)
4612  integer(ih), pointer , dimension(:,:) :: lhs
4613  type(variable_t), intent(in) :: this
4614  logical :: ret
4615  type :: pt
4616    integer(ih), pointer , dimension(:,:) :: p
4617  end type
4618  type(pt) :: p
4619  ret = this%t == "h2"
4620  if (ret) then
4621     nullify(p%p)
4622     p = transfer(this%enc,p)
4623     ret = associated(lhs,p%p)
4624  endif
4625end function associatd_l_h2
4626pure function associatd_r_h2(this,rhs) result(ret)
4627  type(variable_t), intent(in) :: this
4628  integer(ih), pointer , dimension(:,:) :: rhs
4629  logical :: ret
4630  type :: pt
4631    integer(ih), pointer , dimension(:,:) :: p
4632  end type
4633  type(pt) :: p
4634  ret = this%t == "h2"
4635  if (ret) then
4636     nullify(p%p)
4637     p = transfer(this%enc,p)
4638     ret = associated(p%p,rhs)
4639  endif
4640end function associatd_r_h2
4641! All boolean functions
4642subroutine assign_set_h3(this,rhs,dealloc)
4643  type(variable_t), intent(inout) :: this
4644  integer(ih), intent(in), dimension(:,:,:) :: rhs
4645  logical, intent(in), optional :: dealloc
4646  logical :: ldealloc
4647  type :: pt
4648    integer(ih), pointer , dimension(:,:,:) :: p => null()
4649  end type
4650  type(pt) :: p
4651  ! ASSIGNMENT in fortran is per default destructive
4652  ldealloc = .true.
4653  if(present(dealloc))ldealloc = dealloc
4654  if (ldealloc) then
4655     call delete(this)
4656  else
4657     call nullify(this)
4658  end if
4659  ! With pointer transfer we need to deallocate
4660  ! else bounds might change...
4661  this%t = "h3"
4662  allocate(p%p(size(rhs,1),size(rhs,2),size(rhs,3))) ! allocate space
4663  p%p = rhs ! copy data over
4664  allocate(this%enc(size(transfer(p, local_enc_type)))) ! allocate encoding
4665  this%enc(:) = transfer(p, local_enc_type) ! transfer pointer type to the encoding
4666  ! We already have shipped it
4667  nullify(p%p)
4668end subroutine assign_set_h3
4669subroutine assign_get_h3(lhs,this,success)
4670  integer(ih), intent(out), dimension(:,:,:) :: lhs
4671  type(variable_t), intent(in) :: this
4672  logical, intent(out), optional :: success
4673  logical :: lsuccess
4674  type :: pt
4675    integer(ih), pointer , dimension(:,:,:) :: p => null()
4676  end type
4677  type(pt) :: p
4678  lsuccess = this%t == "h3"
4679  if (lsuccess) then
4680    p = transfer(this%enc,p) ! retrieve pointer encoding
4681    lsuccess = all(shape(p%p)==shape(lhs)) !&
4682     ! .and. all((lbound(p%p) == lbound(lhs))) &
4683     ! .and. all((ubound(p%p) == ubound(lhs)))
4684  end if
4685  if (present(success)) success = lsuccess
4686  if (.not. lsuccess) return
4687  lhs = p%p
4688end subroutine assign_get_h3
4689subroutine associate_get_h3(lhs,this,dealloc,success)
4690  integer(ih), pointer , dimension(:,:,:) :: lhs
4691  type(variable_t), intent(in) :: this
4692  logical, intent(in), optional :: dealloc
4693  logical, intent(out), optional :: success
4694  logical :: ldealloc, lsuccess
4695  type :: pt
4696    integer(ih), pointer , dimension(:,:,:) :: p => null()
4697  end type
4698  type(pt) :: p
4699  lsuccess = this%t == "h3"
4700  if (present(success)) success = lsuccess
4701  ! ASSOCIATION in fortran is per default non-destructive
4702  ldealloc = .false.
4703  if(present(dealloc))ldealloc = dealloc
4704  ! there is one problem, say if lhs is not nullified...
4705  if (ldealloc.and.associated(lhs)) then
4706     deallocate(lhs)
4707     nullify(lhs)
4708  end if
4709  if (.not. lsuccess ) return
4710  p = transfer(this%enc,p) ! retrieve pointer encoding
4711  lhs => p%p
4712end subroutine associate_get_h3
4713subroutine associate_set_h3(this,rhs,dealloc)
4714  type(variable_t), intent(inout) :: this
4715  integer(ih), intent(in), dimension(:,:,:), target :: rhs
4716  logical, intent(in), optional :: dealloc
4717  logical :: ldealloc
4718  type :: pt
4719    integer(ih), pointer , dimension(:,:,:) :: p => null()
4720  end type
4721  type(pt) :: p
4722  ! ASSOCIATION in fortran is per default non-destructive
4723  ldealloc = .false.
4724  if(present(dealloc))ldealloc = dealloc
4725  if (ldealloc) then
4726     call delete(this)
4727  else
4728     call nullify(this)
4729  end if
4730  this%t = "h3"
4731  p%p => rhs
4732  allocate(this%enc(size(transfer(p, local_enc_type)))) ! allocate encoding
4733  this%enc(:) = transfer(p, local_enc_type) ! transfer pointer type to the encoding
4734end subroutine associate_set_h3
4735pure function associatd_l_h3(lhs,this) result(ret)
4736  integer(ih), pointer , dimension(:,:,:) :: lhs
4737  type(variable_t), intent(in) :: this
4738  logical :: ret
4739  type :: pt
4740    integer(ih), pointer , dimension(:,:,:) :: p
4741  end type
4742  type(pt) :: p
4743  ret = this%t == "h3"
4744  if (ret) then
4745     nullify(p%p)
4746     p = transfer(this%enc,p)
4747     ret = associated(lhs,p%p)
4748  endif
4749end function associatd_l_h3
4750pure function associatd_r_h3(this,rhs) result(ret)
4751  type(variable_t), intent(in) :: this
4752  integer(ih), pointer , dimension(:,:,:) :: rhs
4753  logical :: ret
4754  type :: pt
4755    integer(ih), pointer , dimension(:,:,:) :: p
4756  end type
4757  type(pt) :: p
4758  ret = this%t == "h3"
4759  if (ret) then
4760     nullify(p%p)
4761     p = transfer(this%enc,p)
4762     ret = associated(p%p,rhs)
4763  endif
4764end function associatd_r_h3
4765! All boolean functions
4766subroutine assign_set_i0(this,rhs,dealloc)
4767  type(variable_t), intent(inout) :: this
4768  integer(is), intent(in) :: rhs
4769  logical, intent(in), optional :: dealloc
4770  logical :: ldealloc
4771  type :: pt
4772    integer(is), pointer :: p => null()
4773  end type
4774  type(pt) :: p
4775  ! ASSIGNMENT in fortran is per default destructive
4776  ldealloc = .true.
4777  if(present(dealloc))ldealloc = dealloc
4778  if (ldealloc) then
4779     call delete(this)
4780  else
4781     call nullify(this)
4782  end if
4783  ! With pointer transfer we need to deallocate
4784  ! else bounds might change...
4785  this%t = "i0"
4786  allocate(p%p) ! allocate space
4787  p%p = rhs ! copy data over
4788  allocate(this%enc(size(transfer(p, local_enc_type)))) ! allocate encoding
4789  this%enc(:) = transfer(p, local_enc_type) ! transfer pointer type to the encoding
4790  ! We already have shipped it
4791  nullify(p%p)
4792end subroutine assign_set_i0
4793subroutine assign_get_i0(lhs,this,success)
4794  integer(is), intent(out) :: lhs
4795  type(variable_t), intent(in) :: this
4796  logical, intent(out), optional :: success
4797  logical :: lsuccess
4798  type :: pt
4799    integer(is), pointer :: p => null()
4800  end type
4801  type(pt) :: p
4802  lsuccess = this%t == "i0"
4803  if (present(success)) success = lsuccess
4804  if (.not. lsuccess) return
4805  p = transfer(this%enc,p) ! retrieve pointer encoding
4806  lhs = p%p
4807end subroutine assign_get_i0
4808subroutine associate_get_i0(lhs,this,dealloc,success)
4809  integer(is), pointer :: lhs
4810  type(variable_t), intent(in) :: this
4811  logical, intent(in), optional :: dealloc
4812  logical, intent(out), optional :: success
4813  logical :: ldealloc, lsuccess
4814  type :: pt
4815    integer(is), pointer :: p => null()
4816  end type
4817  type(pt) :: p
4818  lsuccess = this%t == "i0"
4819  if (present(success)) success = lsuccess
4820  ! ASSOCIATION in fortran is per default non-destructive
4821  ldealloc = .false.
4822  if(present(dealloc))ldealloc = dealloc
4823  ! there is one problem, say if lhs is not nullified...
4824  if (ldealloc.and.associated(lhs)) then
4825     deallocate(lhs)
4826     nullify(lhs)
4827  end if
4828  if (.not. lsuccess ) return
4829  p = transfer(this%enc,p) ! retrieve pointer encoding
4830  lhs => p%p
4831end subroutine associate_get_i0
4832subroutine associate_set_i0(this,rhs,dealloc)
4833  type(variable_t), intent(inout) :: this
4834  integer(is), intent(in), target :: rhs
4835  logical, intent(in), optional :: dealloc
4836  logical :: ldealloc
4837  type :: pt
4838    integer(is), pointer :: p => null()
4839  end type
4840  type(pt) :: p
4841  ! ASSOCIATION in fortran is per default non-destructive
4842  ldealloc = .false.
4843  if(present(dealloc))ldealloc = dealloc
4844  if (ldealloc) then
4845     call delete(this)
4846  else
4847     call nullify(this)
4848  end if
4849  this%t = "i0"
4850  p%p => rhs
4851  allocate(this%enc(size(transfer(p, local_enc_type)))) ! allocate encoding
4852  this%enc(:) = transfer(p, local_enc_type) ! transfer pointer type to the encoding
4853end subroutine associate_set_i0
4854pure function associatd_l_i0(lhs,this) result(ret)
4855  integer(is), pointer :: lhs
4856  type(variable_t), intent(in) :: this
4857  logical :: ret
4858  type :: pt
4859    integer(is), pointer :: p
4860  end type
4861  type(pt) :: p
4862  ret = this%t == "i0"
4863  if (ret) then
4864     nullify(p%p)
4865     p = transfer(this%enc,p)
4866     ret = associated(lhs,p%p)
4867  endif
4868end function associatd_l_i0
4869pure function associatd_r_i0(this,rhs) result(ret)
4870  type(variable_t), intent(in) :: this
4871  integer(is), pointer :: rhs
4872  logical :: ret
4873  type :: pt
4874    integer(is), pointer :: p
4875  end type
4876  type(pt) :: p
4877  ret = this%t == "i0"
4878  if (ret) then
4879     nullify(p%p)
4880     p = transfer(this%enc,p)
4881     ret = associated(p%p,rhs)
4882  endif
4883end function associatd_r_i0
4884! All boolean functions
4885subroutine assign_set_i1(this,rhs,dealloc)
4886  type(variable_t), intent(inout) :: this
4887  integer(is), intent(in), dimension(:) :: rhs
4888  logical, intent(in), optional :: dealloc
4889  logical :: ldealloc
4890  type :: pt
4891    integer(is), pointer , dimension(:) :: p => null()
4892  end type
4893  type(pt) :: p
4894  ! ASSIGNMENT in fortran is per default destructive
4895  ldealloc = .true.
4896  if(present(dealloc))ldealloc = dealloc
4897  if (ldealloc) then
4898     call delete(this)
4899  else
4900     call nullify(this)
4901  end if
4902  ! With pointer transfer we need to deallocate
4903  ! else bounds might change...
4904  this%t = "i1"
4905  allocate(p%p(size(rhs))) ! allocate space
4906  p%p = rhs ! copy data over
4907  allocate(this%enc(size(transfer(p, local_enc_type)))) ! allocate encoding
4908  this%enc(:) = transfer(p, local_enc_type) ! transfer pointer type to the encoding
4909  ! We already have shipped it
4910  nullify(p%p)
4911end subroutine assign_set_i1
4912subroutine assign_get_i1(lhs,this,success)
4913  integer(is), intent(out), dimension(:) :: lhs
4914  type(variable_t), intent(in) :: this
4915  logical, intent(out), optional :: success
4916  logical :: lsuccess
4917  type :: pt
4918    integer(is), pointer , dimension(:) :: p => null()
4919  end type
4920  type(pt) :: p
4921  lsuccess = this%t == "i1"
4922  if (lsuccess) then
4923    p = transfer(this%enc,p) ! retrieve pointer encoding
4924    lsuccess = all(shape(p%p)==shape(lhs)) !&
4925     ! .and. all((lbound(p%p) == lbound(lhs))) &
4926     ! .and. all((ubound(p%p) == ubound(lhs)))
4927  end if
4928  if (present(success)) success = lsuccess
4929  if (.not. lsuccess) return
4930  lhs = p%p
4931end subroutine assign_get_i1
4932subroutine associate_get_i1(lhs,this,dealloc,success)
4933  integer(is), pointer , dimension(:) :: lhs
4934  type(variable_t), intent(in) :: this
4935  logical, intent(in), optional :: dealloc
4936  logical, intent(out), optional :: success
4937  logical :: ldealloc, lsuccess
4938  type :: pt
4939    integer(is), pointer , dimension(:) :: p => null()
4940  end type
4941  type(pt) :: p
4942  lsuccess = this%t == "i1"
4943  if (present(success)) success = lsuccess
4944  ! ASSOCIATION in fortran is per default non-destructive
4945  ldealloc = .false.
4946  if(present(dealloc))ldealloc = dealloc
4947  ! there is one problem, say if lhs is not nullified...
4948  if (ldealloc.and.associated(lhs)) then
4949     deallocate(lhs)
4950     nullify(lhs)
4951  end if
4952  if (.not. lsuccess ) return
4953  p = transfer(this%enc,p) ! retrieve pointer encoding
4954  lhs => p%p
4955end subroutine associate_get_i1
4956subroutine associate_set_i1(this,rhs,dealloc)
4957  type(variable_t), intent(inout) :: this
4958  integer(is), intent(in), dimension(:), target :: rhs
4959  logical, intent(in), optional :: dealloc
4960  logical :: ldealloc
4961  type :: pt
4962    integer(is), pointer , dimension(:) :: p => null()
4963  end type
4964  type(pt) :: p
4965  ! ASSOCIATION in fortran is per default non-destructive
4966  ldealloc = .false.
4967  if(present(dealloc))ldealloc = dealloc
4968  if (ldealloc) then
4969     call delete(this)
4970  else
4971     call nullify(this)
4972  end if
4973  this%t = "i1"
4974  p%p => rhs
4975  allocate(this%enc(size(transfer(p, local_enc_type)))) ! allocate encoding
4976  this%enc(:) = transfer(p, local_enc_type) ! transfer pointer type to the encoding
4977end subroutine associate_set_i1
4978pure function associatd_l_i1(lhs,this) result(ret)
4979  integer(is), pointer , dimension(:) :: lhs
4980  type(variable_t), intent(in) :: this
4981  logical :: ret
4982  type :: pt
4983    integer(is), pointer , dimension(:) :: p
4984  end type
4985  type(pt) :: p
4986  ret = this%t == "i1"
4987  if (ret) then
4988     nullify(p%p)
4989     p = transfer(this%enc,p)
4990     ret = associated(lhs,p%p)
4991  endif
4992end function associatd_l_i1
4993pure function associatd_r_i1(this,rhs) result(ret)
4994  type(variable_t), intent(in) :: this
4995  integer(is), pointer , dimension(:) :: rhs
4996  logical :: ret
4997  type :: pt
4998    integer(is), pointer , dimension(:) :: p
4999  end type
5000  type(pt) :: p
5001  ret = this%t == "i1"
5002  if (ret) then
5003     nullify(p%p)
5004     p = transfer(this%enc,p)
5005     ret = associated(p%p,rhs)
5006  endif
5007end function associatd_r_i1
5008! All boolean functions
5009subroutine assign_set_i2(this,rhs,dealloc)
5010  type(variable_t), intent(inout) :: this
5011  integer(is), intent(in), dimension(:,:) :: rhs
5012  logical, intent(in), optional :: dealloc
5013  logical :: ldealloc
5014  type :: pt
5015    integer(is), pointer , dimension(:,:) :: p => null()
5016  end type
5017  type(pt) :: p
5018  ! ASSIGNMENT in fortran is per default destructive
5019  ldealloc = .true.
5020  if(present(dealloc))ldealloc = dealloc
5021  if (ldealloc) then
5022     call delete(this)
5023  else
5024     call nullify(this)
5025  end if
5026  ! With pointer transfer we need to deallocate
5027  ! else bounds might change...
5028  this%t = "i2"
5029  allocate(p%p(size(rhs,1),size(rhs,2))) ! allocate space
5030  p%p = rhs ! copy data over
5031  allocate(this%enc(size(transfer(p, local_enc_type)))) ! allocate encoding
5032  this%enc(:) = transfer(p, local_enc_type) ! transfer pointer type to the encoding
5033  ! We already have shipped it
5034  nullify(p%p)
5035end subroutine assign_set_i2
5036subroutine assign_get_i2(lhs,this,success)
5037  integer(is), intent(out), dimension(:,:) :: lhs
5038  type(variable_t), intent(in) :: this
5039  logical, intent(out), optional :: success
5040  logical :: lsuccess
5041  type :: pt
5042    integer(is), pointer , dimension(:,:) :: p => null()
5043  end type
5044  type(pt) :: p
5045  lsuccess = this%t == "i2"
5046  if (lsuccess) then
5047    p = transfer(this%enc,p) ! retrieve pointer encoding
5048    lsuccess = all(shape(p%p)==shape(lhs)) !&
5049     ! .and. all((lbound(p%p) == lbound(lhs))) &
5050     ! .and. all((ubound(p%p) == ubound(lhs)))
5051  end if
5052  if (present(success)) success = lsuccess
5053  if (.not. lsuccess) return
5054  lhs = p%p
5055end subroutine assign_get_i2
5056subroutine associate_get_i2(lhs,this,dealloc,success)
5057  integer(is), pointer , dimension(:,:) :: lhs
5058  type(variable_t), intent(in) :: this
5059  logical, intent(in), optional :: dealloc
5060  logical, intent(out), optional :: success
5061  logical :: ldealloc, lsuccess
5062  type :: pt
5063    integer(is), pointer , dimension(:,:) :: p => null()
5064  end type
5065  type(pt) :: p
5066  lsuccess = this%t == "i2"
5067  if (present(success)) success = lsuccess
5068  ! ASSOCIATION in fortran is per default non-destructive
5069  ldealloc = .false.
5070  if(present(dealloc))ldealloc = dealloc
5071  ! there is one problem, say if lhs is not nullified...
5072  if (ldealloc.and.associated(lhs)) then
5073     deallocate(lhs)
5074     nullify(lhs)
5075  end if
5076  if (.not. lsuccess ) return
5077  p = transfer(this%enc,p) ! retrieve pointer encoding
5078  lhs => p%p
5079end subroutine associate_get_i2
5080subroutine associate_set_i2(this,rhs,dealloc)
5081  type(variable_t), intent(inout) :: this
5082  integer(is), intent(in), dimension(:,:), target :: rhs
5083  logical, intent(in), optional :: dealloc
5084  logical :: ldealloc
5085  type :: pt
5086    integer(is), pointer , dimension(:,:) :: p => null()
5087  end type
5088  type(pt) :: p
5089  ! ASSOCIATION in fortran is per default non-destructive
5090  ldealloc = .false.
5091  if(present(dealloc))ldealloc = dealloc
5092  if (ldealloc) then
5093     call delete(this)
5094  else
5095     call nullify(this)
5096  end if
5097  this%t = "i2"
5098  p%p => rhs
5099  allocate(this%enc(size(transfer(p, local_enc_type)))) ! allocate encoding
5100  this%enc(:) = transfer(p, local_enc_type) ! transfer pointer type to the encoding
5101end subroutine associate_set_i2
5102pure function associatd_l_i2(lhs,this) result(ret)
5103  integer(is), pointer , dimension(:,:) :: lhs
5104  type(variable_t), intent(in) :: this
5105  logical :: ret
5106  type :: pt
5107    integer(is), pointer , dimension(:,:) :: p
5108  end type
5109  type(pt) :: p
5110  ret = this%t == "i2"
5111  if (ret) then
5112     nullify(p%p)
5113     p = transfer(this%enc,p)
5114     ret = associated(lhs,p%p)
5115  endif
5116end function associatd_l_i2
5117pure function associatd_r_i2(this,rhs) result(ret)
5118  type(variable_t), intent(in) :: this
5119  integer(is), pointer , dimension(:,:) :: rhs
5120  logical :: ret
5121  type :: pt
5122    integer(is), pointer , dimension(:,:) :: p
5123  end type
5124  type(pt) :: p
5125  ret = this%t == "i2"
5126  if (ret) then
5127     nullify(p%p)
5128     p = transfer(this%enc,p)
5129     ret = associated(p%p,rhs)
5130  endif
5131end function associatd_r_i2
5132! All boolean functions
5133subroutine assign_set_i3(this,rhs,dealloc)
5134  type(variable_t), intent(inout) :: this
5135  integer(is), intent(in), dimension(:,:,:) :: rhs
5136  logical, intent(in), optional :: dealloc
5137  logical :: ldealloc
5138  type :: pt
5139    integer(is), pointer , dimension(:,:,:) :: p => null()
5140  end type
5141  type(pt) :: p
5142  ! ASSIGNMENT in fortran is per default destructive
5143  ldealloc = .true.
5144  if(present(dealloc))ldealloc = dealloc
5145  if (ldealloc) then
5146     call delete(this)
5147  else
5148     call nullify(this)
5149  end if
5150  ! With pointer transfer we need to deallocate
5151  ! else bounds might change...
5152  this%t = "i3"
5153  allocate(p%p(size(rhs,1),size(rhs,2),size(rhs,3))) ! allocate space
5154  p%p = rhs ! copy data over
5155  allocate(this%enc(size(transfer(p, local_enc_type)))) ! allocate encoding
5156  this%enc(:) = transfer(p, local_enc_type) ! transfer pointer type to the encoding
5157  ! We already have shipped it
5158  nullify(p%p)
5159end subroutine assign_set_i3
5160subroutine assign_get_i3(lhs,this,success)
5161  integer(is), intent(out), dimension(:,:,:) :: lhs
5162  type(variable_t), intent(in) :: this
5163  logical, intent(out), optional :: success
5164  logical :: lsuccess
5165  type :: pt
5166    integer(is), pointer , dimension(:,:,:) :: p => null()
5167  end type
5168  type(pt) :: p
5169  lsuccess = this%t == "i3"
5170  if (lsuccess) then
5171    p = transfer(this%enc,p) ! retrieve pointer encoding
5172    lsuccess = all(shape(p%p)==shape(lhs)) !&
5173     ! .and. all((lbound(p%p) == lbound(lhs))) &
5174     ! .and. all((ubound(p%p) == ubound(lhs)))
5175  end if
5176  if (present(success)) success = lsuccess
5177  if (.not. lsuccess) return
5178  lhs = p%p
5179end subroutine assign_get_i3
5180subroutine associate_get_i3(lhs,this,dealloc,success)
5181  integer(is), pointer , dimension(:,:,:) :: lhs
5182  type(variable_t), intent(in) :: this
5183  logical, intent(in), optional :: dealloc
5184  logical, intent(out), optional :: success
5185  logical :: ldealloc, lsuccess
5186  type :: pt
5187    integer(is), pointer , dimension(:,:,:) :: p => null()
5188  end type
5189  type(pt) :: p
5190  lsuccess = this%t == "i3"
5191  if (present(success)) success = lsuccess
5192  ! ASSOCIATION in fortran is per default non-destructive
5193  ldealloc = .false.
5194  if(present(dealloc))ldealloc = dealloc
5195  ! there is one problem, say if lhs is not nullified...
5196  if (ldealloc.and.associated(lhs)) then
5197     deallocate(lhs)
5198     nullify(lhs)
5199  end if
5200  if (.not. lsuccess ) return
5201  p = transfer(this%enc,p) ! retrieve pointer encoding
5202  lhs => p%p
5203end subroutine associate_get_i3
5204subroutine associate_set_i3(this,rhs,dealloc)
5205  type(variable_t), intent(inout) :: this
5206  integer(is), intent(in), dimension(:,:,:), target :: rhs
5207  logical, intent(in), optional :: dealloc
5208  logical :: ldealloc
5209  type :: pt
5210    integer(is), pointer , dimension(:,:,:) :: p => null()
5211  end type
5212  type(pt) :: p
5213  ! ASSOCIATION in fortran is per default non-destructive
5214  ldealloc = .false.
5215  if(present(dealloc))ldealloc = dealloc
5216  if (ldealloc) then
5217     call delete(this)
5218  else
5219     call nullify(this)
5220  end if
5221  this%t = "i3"
5222  p%p => rhs
5223  allocate(this%enc(size(transfer(p, local_enc_type)))) ! allocate encoding
5224  this%enc(:) = transfer(p, local_enc_type) ! transfer pointer type to the encoding
5225end subroutine associate_set_i3
5226pure function associatd_l_i3(lhs,this) result(ret)
5227  integer(is), pointer , dimension(:,:,:) :: lhs
5228  type(variable_t), intent(in) :: this
5229  logical :: ret
5230  type :: pt
5231    integer(is), pointer , dimension(:,:,:) :: p
5232  end type
5233  type(pt) :: p
5234  ret = this%t == "i3"
5235  if (ret) then
5236     nullify(p%p)
5237     p = transfer(this%enc,p)
5238     ret = associated(lhs,p%p)
5239  endif
5240end function associatd_l_i3
5241pure function associatd_r_i3(this,rhs) result(ret)
5242  type(variable_t), intent(in) :: this
5243  integer(is), pointer , dimension(:,:,:) :: rhs
5244  logical :: ret
5245  type :: pt
5246    integer(is), pointer , dimension(:,:,:) :: p
5247  end type
5248  type(pt) :: p
5249  ret = this%t == "i3"
5250  if (ret) then
5251     nullify(p%p)
5252     p = transfer(this%enc,p)
5253     ret = associated(p%p,rhs)
5254  endif
5255end function associatd_r_i3
5256! All boolean functions
5257subroutine assign_set_l0(this,rhs,dealloc)
5258  type(variable_t), intent(inout) :: this
5259  integer(il), intent(in) :: rhs
5260  logical, intent(in), optional :: dealloc
5261  logical :: ldealloc
5262  type :: pt
5263    integer(il), pointer :: p => null()
5264  end type
5265  type(pt) :: p
5266  ! ASSIGNMENT in fortran is per default destructive
5267  ldealloc = .true.
5268  if(present(dealloc))ldealloc = dealloc
5269  if (ldealloc) then
5270     call delete(this)
5271  else
5272     call nullify(this)
5273  end if
5274  ! With pointer transfer we need to deallocate
5275  ! else bounds might change...
5276  this%t = "l0"
5277  allocate(p%p) ! allocate space
5278  p%p = rhs ! copy data over
5279  allocate(this%enc(size(transfer(p, local_enc_type)))) ! allocate encoding
5280  this%enc(:) = transfer(p, local_enc_type) ! transfer pointer type to the encoding
5281  ! We already have shipped it
5282  nullify(p%p)
5283end subroutine assign_set_l0
5284subroutine assign_get_l0(lhs,this,success)
5285  integer(il), intent(out) :: lhs
5286  type(variable_t), intent(in) :: this
5287  logical, intent(out), optional :: success
5288  logical :: lsuccess
5289  type :: pt
5290    integer(il), pointer :: p => null()
5291  end type
5292  type(pt) :: p
5293  lsuccess = this%t == "l0"
5294  if (present(success)) success = lsuccess
5295  if (.not. lsuccess) return
5296  p = transfer(this%enc,p) ! retrieve pointer encoding
5297  lhs = p%p
5298end subroutine assign_get_l0
5299subroutine associate_get_l0(lhs,this,dealloc,success)
5300  integer(il), pointer :: lhs
5301  type(variable_t), intent(in) :: this
5302  logical, intent(in), optional :: dealloc
5303  logical, intent(out), optional :: success
5304  logical :: ldealloc, lsuccess
5305  type :: pt
5306    integer(il), pointer :: p => null()
5307  end type
5308  type(pt) :: p
5309  lsuccess = this%t == "l0"
5310  if (present(success)) success = lsuccess
5311  ! ASSOCIATION in fortran is per default non-destructive
5312  ldealloc = .false.
5313  if(present(dealloc))ldealloc = dealloc
5314  ! there is one problem, say if lhs is not nullified...
5315  if (ldealloc.and.associated(lhs)) then
5316     deallocate(lhs)
5317     nullify(lhs)
5318  end if
5319  if (.not. lsuccess ) return
5320  p = transfer(this%enc,p) ! retrieve pointer encoding
5321  lhs => p%p
5322end subroutine associate_get_l0
5323subroutine associate_set_l0(this,rhs,dealloc)
5324  type(variable_t), intent(inout) :: this
5325  integer(il), intent(in), target :: rhs
5326  logical, intent(in), optional :: dealloc
5327  logical :: ldealloc
5328  type :: pt
5329    integer(il), pointer :: p => null()
5330  end type
5331  type(pt) :: p
5332  ! ASSOCIATION in fortran is per default non-destructive
5333  ldealloc = .false.
5334  if(present(dealloc))ldealloc = dealloc
5335  if (ldealloc) then
5336     call delete(this)
5337  else
5338     call nullify(this)
5339  end if
5340  this%t = "l0"
5341  p%p => rhs
5342  allocate(this%enc(size(transfer(p, local_enc_type)))) ! allocate encoding
5343  this%enc(:) = transfer(p, local_enc_type) ! transfer pointer type to the encoding
5344end subroutine associate_set_l0
5345pure function associatd_l_l0(lhs,this) result(ret)
5346  integer(il), pointer :: lhs
5347  type(variable_t), intent(in) :: this
5348  logical :: ret
5349  type :: pt
5350    integer(il), pointer :: p
5351  end type
5352  type(pt) :: p
5353  ret = this%t == "l0"
5354  if (ret) then
5355     nullify(p%p)
5356     p = transfer(this%enc,p)
5357     ret = associated(lhs,p%p)
5358  endif
5359end function associatd_l_l0
5360pure function associatd_r_l0(this,rhs) result(ret)
5361  type(variable_t), intent(in) :: this
5362  integer(il), pointer :: rhs
5363  logical :: ret
5364  type :: pt
5365    integer(il), pointer :: p
5366  end type
5367  type(pt) :: p
5368  ret = this%t == "l0"
5369  if (ret) then
5370     nullify(p%p)
5371     p = transfer(this%enc,p)
5372     ret = associated(p%p,rhs)
5373  endif
5374end function associatd_r_l0
5375! All boolean functions
5376subroutine assign_set_l1(this,rhs,dealloc)
5377  type(variable_t), intent(inout) :: this
5378  integer(il), intent(in), dimension(:) :: rhs
5379  logical, intent(in), optional :: dealloc
5380  logical :: ldealloc
5381  type :: pt
5382    integer(il), pointer , dimension(:) :: p => null()
5383  end type
5384  type(pt) :: p
5385  ! ASSIGNMENT in fortran is per default destructive
5386  ldealloc = .true.
5387  if(present(dealloc))ldealloc = dealloc
5388  if (ldealloc) then
5389     call delete(this)
5390  else
5391     call nullify(this)
5392  end if
5393  ! With pointer transfer we need to deallocate
5394  ! else bounds might change...
5395  this%t = "l1"
5396  allocate(p%p(size(rhs))) ! allocate space
5397  p%p = rhs ! copy data over
5398  allocate(this%enc(size(transfer(p, local_enc_type)))) ! allocate encoding
5399  this%enc(:) = transfer(p, local_enc_type) ! transfer pointer type to the encoding
5400  ! We already have shipped it
5401  nullify(p%p)
5402end subroutine assign_set_l1
5403subroutine assign_get_l1(lhs,this,success)
5404  integer(il), intent(out), dimension(:) :: lhs
5405  type(variable_t), intent(in) :: this
5406  logical, intent(out), optional :: success
5407  logical :: lsuccess
5408  type :: pt
5409    integer(il), pointer , dimension(:) :: p => null()
5410  end type
5411  type(pt) :: p
5412  lsuccess = this%t == "l1"
5413  if (lsuccess) then
5414    p = transfer(this%enc,p) ! retrieve pointer encoding
5415    lsuccess = all(shape(p%p)==shape(lhs)) !&
5416     ! .and. all((lbound(p%p) == lbound(lhs))) &
5417     ! .and. all((ubound(p%p) == ubound(lhs)))
5418  end if
5419  if (present(success)) success = lsuccess
5420  if (.not. lsuccess) return
5421  lhs = p%p
5422end subroutine assign_get_l1
5423subroutine associate_get_l1(lhs,this,dealloc,success)
5424  integer(il), pointer , dimension(:) :: lhs
5425  type(variable_t), intent(in) :: this
5426  logical, intent(in), optional :: dealloc
5427  logical, intent(out), optional :: success
5428  logical :: ldealloc, lsuccess
5429  type :: pt
5430    integer(il), pointer , dimension(:) :: p => null()
5431  end type
5432  type(pt) :: p
5433  lsuccess = this%t == "l1"
5434  if (present(success)) success = lsuccess
5435  ! ASSOCIATION in fortran is per default non-destructive
5436  ldealloc = .false.
5437  if(present(dealloc))ldealloc = dealloc
5438  ! there is one problem, say if lhs is not nullified...
5439  if (ldealloc.and.associated(lhs)) then
5440     deallocate(lhs)
5441     nullify(lhs)
5442  end if
5443  if (.not. lsuccess ) return
5444  p = transfer(this%enc,p) ! retrieve pointer encoding
5445  lhs => p%p
5446end subroutine associate_get_l1
5447subroutine associate_set_l1(this,rhs,dealloc)
5448  type(variable_t), intent(inout) :: this
5449  integer(il), intent(in), dimension(:), target :: rhs
5450  logical, intent(in), optional :: dealloc
5451  logical :: ldealloc
5452  type :: pt
5453    integer(il), pointer , dimension(:) :: p => null()
5454  end type
5455  type(pt) :: p
5456  ! ASSOCIATION in fortran is per default non-destructive
5457  ldealloc = .false.
5458  if(present(dealloc))ldealloc = dealloc
5459  if (ldealloc) then
5460     call delete(this)
5461  else
5462     call nullify(this)
5463  end if
5464  this%t = "l1"
5465  p%p => rhs
5466  allocate(this%enc(size(transfer(p, local_enc_type)))) ! allocate encoding
5467  this%enc(:) = transfer(p, local_enc_type) ! transfer pointer type to the encoding
5468end subroutine associate_set_l1
5469pure function associatd_l_l1(lhs,this) result(ret)
5470  integer(il), pointer , dimension(:) :: lhs
5471  type(variable_t), intent(in) :: this
5472  logical :: ret
5473  type :: pt
5474    integer(il), pointer , dimension(:) :: p
5475  end type
5476  type(pt) :: p
5477  ret = this%t == "l1"
5478  if (ret) then
5479     nullify(p%p)
5480     p = transfer(this%enc,p)
5481     ret = associated(lhs,p%p)
5482  endif
5483end function associatd_l_l1
5484pure function associatd_r_l1(this,rhs) result(ret)
5485  type(variable_t), intent(in) :: this
5486  integer(il), pointer , dimension(:) :: rhs
5487  logical :: ret
5488  type :: pt
5489    integer(il), pointer , dimension(:) :: p
5490  end type
5491  type(pt) :: p
5492  ret = this%t == "l1"
5493  if (ret) then
5494     nullify(p%p)
5495     p = transfer(this%enc,p)
5496     ret = associated(p%p,rhs)
5497  endif
5498end function associatd_r_l1
5499! All boolean functions
5500subroutine assign_set_l2(this,rhs,dealloc)
5501  type(variable_t), intent(inout) :: this
5502  integer(il), intent(in), dimension(:,:) :: rhs
5503  logical, intent(in), optional :: dealloc
5504  logical :: ldealloc
5505  type :: pt
5506    integer(il), pointer , dimension(:,:) :: p => null()
5507  end type
5508  type(pt) :: p
5509  ! ASSIGNMENT in fortran is per default destructive
5510  ldealloc = .true.
5511  if(present(dealloc))ldealloc = dealloc
5512  if (ldealloc) then
5513     call delete(this)
5514  else
5515     call nullify(this)
5516  end if
5517  ! With pointer transfer we need to deallocate
5518  ! else bounds might change...
5519  this%t = "l2"
5520  allocate(p%p(size(rhs,1),size(rhs,2))) ! allocate space
5521  p%p = rhs ! copy data over
5522  allocate(this%enc(size(transfer(p, local_enc_type)))) ! allocate encoding
5523  this%enc(:) = transfer(p, local_enc_type) ! transfer pointer type to the encoding
5524  ! We already have shipped it
5525  nullify(p%p)
5526end subroutine assign_set_l2
5527subroutine assign_get_l2(lhs,this,success)
5528  integer(il), intent(out), dimension(:,:) :: lhs
5529  type(variable_t), intent(in) :: this
5530  logical, intent(out), optional :: success
5531  logical :: lsuccess
5532  type :: pt
5533    integer(il), pointer , dimension(:,:) :: p => null()
5534  end type
5535  type(pt) :: p
5536  lsuccess = this%t == "l2"
5537  if (lsuccess) then
5538    p = transfer(this%enc,p) ! retrieve pointer encoding
5539    lsuccess = all(shape(p%p)==shape(lhs)) !&
5540     ! .and. all((lbound(p%p) == lbound(lhs))) &
5541     ! .and. all((ubound(p%p) == ubound(lhs)))
5542  end if
5543  if (present(success)) success = lsuccess
5544  if (.not. lsuccess) return
5545  lhs = p%p
5546end subroutine assign_get_l2
5547subroutine associate_get_l2(lhs,this,dealloc,success)
5548  integer(il), pointer , dimension(:,:) :: lhs
5549  type(variable_t), intent(in) :: this
5550  logical, intent(in), optional :: dealloc
5551  logical, intent(out), optional :: success
5552  logical :: ldealloc, lsuccess
5553  type :: pt
5554    integer(il), pointer , dimension(:,:) :: p => null()
5555  end type
5556  type(pt) :: p
5557  lsuccess = this%t == "l2"
5558  if (present(success)) success = lsuccess
5559  ! ASSOCIATION in fortran is per default non-destructive
5560  ldealloc = .false.
5561  if(present(dealloc))ldealloc = dealloc
5562  ! there is one problem, say if lhs is not nullified...
5563  if (ldealloc.and.associated(lhs)) then
5564     deallocate(lhs)
5565     nullify(lhs)
5566  end if
5567  if (.not. lsuccess ) return
5568  p = transfer(this%enc,p) ! retrieve pointer encoding
5569  lhs => p%p
5570end subroutine associate_get_l2
5571subroutine associate_set_l2(this,rhs,dealloc)
5572  type(variable_t), intent(inout) :: this
5573  integer(il), intent(in), dimension(:,:), target :: rhs
5574  logical, intent(in), optional :: dealloc
5575  logical :: ldealloc
5576  type :: pt
5577    integer(il), pointer , dimension(:,:) :: p => null()
5578  end type
5579  type(pt) :: p
5580  ! ASSOCIATION in fortran is per default non-destructive
5581  ldealloc = .false.
5582  if(present(dealloc))ldealloc = dealloc
5583  if (ldealloc) then
5584     call delete(this)
5585  else
5586     call nullify(this)
5587  end if
5588  this%t = "l2"
5589  p%p => rhs
5590  allocate(this%enc(size(transfer(p, local_enc_type)))) ! allocate encoding
5591  this%enc(:) = transfer(p, local_enc_type) ! transfer pointer type to the encoding
5592end subroutine associate_set_l2
5593pure function associatd_l_l2(lhs,this) result(ret)
5594  integer(il), pointer , dimension(:,:) :: lhs
5595  type(variable_t), intent(in) :: this
5596  logical :: ret
5597  type :: pt
5598    integer(il), pointer , dimension(:,:) :: p
5599  end type
5600  type(pt) :: p
5601  ret = this%t == "l2"
5602  if (ret) then
5603     nullify(p%p)
5604     p = transfer(this%enc,p)
5605     ret = associated(lhs,p%p)
5606  endif
5607end function associatd_l_l2
5608pure function associatd_r_l2(this,rhs) result(ret)
5609  type(variable_t), intent(in) :: this
5610  integer(il), pointer , dimension(:,:) :: rhs
5611  logical :: ret
5612  type :: pt
5613    integer(il), pointer , dimension(:,:) :: p
5614  end type
5615  type(pt) :: p
5616  ret = this%t == "l2"
5617  if (ret) then
5618     nullify(p%p)
5619     p = transfer(this%enc,p)
5620     ret = associated(p%p,rhs)
5621  endif
5622end function associatd_r_l2
5623! All boolean functions
5624subroutine assign_set_l3(this,rhs,dealloc)
5625  type(variable_t), intent(inout) :: this
5626  integer(il), intent(in), dimension(:,:,:) :: rhs
5627  logical, intent(in), optional :: dealloc
5628  logical :: ldealloc
5629  type :: pt
5630    integer(il), pointer , dimension(:,:,:) :: p => null()
5631  end type
5632  type(pt) :: p
5633  ! ASSIGNMENT in fortran is per default destructive
5634  ldealloc = .true.
5635  if(present(dealloc))ldealloc = dealloc
5636  if (ldealloc) then
5637     call delete(this)
5638  else
5639     call nullify(this)
5640  end if
5641  ! With pointer transfer we need to deallocate
5642  ! else bounds might change...
5643  this%t = "l3"
5644  allocate(p%p(size(rhs,1),size(rhs,2),size(rhs,3))) ! allocate space
5645  p%p = rhs ! copy data over
5646  allocate(this%enc(size(transfer(p, local_enc_type)))) ! allocate encoding
5647  this%enc(:) = transfer(p, local_enc_type) ! transfer pointer type to the encoding
5648  ! We already have shipped it
5649  nullify(p%p)
5650end subroutine assign_set_l3
5651subroutine assign_get_l3(lhs,this,success)
5652  integer(il), intent(out), dimension(:,:,:) :: lhs
5653  type(variable_t), intent(in) :: this
5654  logical, intent(out), optional :: success
5655  logical :: lsuccess
5656  type :: pt
5657    integer(il), pointer , dimension(:,:,:) :: p => null()
5658  end type
5659  type(pt) :: p
5660  lsuccess = this%t == "l3"
5661  if (lsuccess) then
5662    p = transfer(this%enc,p) ! retrieve pointer encoding
5663    lsuccess = all(shape(p%p)==shape(lhs)) !&
5664     ! .and. all((lbound(p%p) == lbound(lhs))) &
5665     ! .and. all((ubound(p%p) == ubound(lhs)))
5666  end if
5667  if (present(success)) success = lsuccess
5668  if (.not. lsuccess) return
5669  lhs = p%p
5670end subroutine assign_get_l3
5671subroutine associate_get_l3(lhs,this,dealloc,success)
5672  integer(il), pointer , dimension(:,:,:) :: lhs
5673  type(variable_t), intent(in) :: this
5674  logical, intent(in), optional :: dealloc
5675  logical, intent(out), optional :: success
5676  logical :: ldealloc, lsuccess
5677  type :: pt
5678    integer(il), pointer , dimension(:,:,:) :: p => null()
5679  end type
5680  type(pt) :: p
5681  lsuccess = this%t == "l3"
5682  if (present(success)) success = lsuccess
5683  ! ASSOCIATION in fortran is per default non-destructive
5684  ldealloc = .false.
5685  if(present(dealloc))ldealloc = dealloc
5686  ! there is one problem, say if lhs is not nullified...
5687  if (ldealloc.and.associated(lhs)) then
5688     deallocate(lhs)
5689     nullify(lhs)
5690  end if
5691  if (.not. lsuccess ) return
5692  p = transfer(this%enc,p) ! retrieve pointer encoding
5693  lhs => p%p
5694end subroutine associate_get_l3
5695subroutine associate_set_l3(this,rhs,dealloc)
5696  type(variable_t), intent(inout) :: this
5697  integer(il), intent(in), dimension(:,:,:), target :: rhs
5698  logical, intent(in), optional :: dealloc
5699  logical :: ldealloc
5700  type :: pt
5701    integer(il), pointer , dimension(:,:,:) :: p => null()
5702  end type
5703  type(pt) :: p
5704  ! ASSOCIATION in fortran is per default non-destructive
5705  ldealloc = .false.
5706  if(present(dealloc))ldealloc = dealloc
5707  if (ldealloc) then
5708     call delete(this)
5709  else
5710     call nullify(this)
5711  end if
5712  this%t = "l3"
5713  p%p => rhs
5714  allocate(this%enc(size(transfer(p, local_enc_type)))) ! allocate encoding
5715  this%enc(:) = transfer(p, local_enc_type) ! transfer pointer type to the encoding
5716end subroutine associate_set_l3
5717pure function associatd_l_l3(lhs,this) result(ret)
5718  integer(il), pointer , dimension(:,:,:) :: lhs
5719  type(variable_t), intent(in) :: this
5720  logical :: ret
5721  type :: pt
5722    integer(il), pointer , dimension(:,:,:) :: p
5723  end type
5724  type(pt) :: p
5725  ret = this%t == "l3"
5726  if (ret) then
5727     nullify(p%p)
5728     p = transfer(this%enc,p)
5729     ret = associated(lhs,p%p)
5730  endif
5731end function associatd_l_l3
5732pure function associatd_r_l3(this,rhs) result(ret)
5733  type(variable_t), intent(in) :: this
5734  integer(il), pointer , dimension(:,:,:) :: rhs
5735  logical :: ret
5736  type :: pt
5737    integer(il), pointer , dimension(:,:,:) :: p
5738  end type
5739  type(pt) :: p
5740  ret = this%t == "l3"
5741  if (ret) then
5742     nullify(p%p)
5743     p = transfer(this%enc,p)
5744     ret = associated(p%p,rhs)
5745  endif
5746end function associatd_r_l3
5747! All boolean functions
5748subroutine assign_set_cp0(this,rhs,dealloc)
5749  type(variable_t), intent(inout) :: this
5750  type(c_ptr), intent(in) :: rhs
5751  logical, intent(in), optional :: dealloc
5752  logical :: ldealloc
5753  type :: pt
5754    type(c_ptr), pointer :: p => null()
5755  end type
5756  type(pt) :: p
5757  ! ASSIGNMENT in fortran is per default destructive
5758  ldealloc = .true.
5759  if(present(dealloc))ldealloc = dealloc
5760  if (ldealloc) then
5761     call delete(this)
5762  else
5763     call nullify(this)
5764  end if
5765  ! With pointer transfer we need to deallocate
5766  ! else bounds might change...
5767  this%t = "cp0"
5768  allocate(p%p) ! allocate space
5769  p%p = rhs ! copy data over
5770  allocate(this%enc(size(transfer(p, local_enc_type)))) ! allocate encoding
5771  this%enc(:) = transfer(p, local_enc_type) ! transfer pointer type to the encoding
5772  ! We already have shipped it
5773  nullify(p%p)
5774end subroutine assign_set_cp0
5775subroutine assign_get_cp0(lhs,this,success)
5776  type(c_ptr), intent(out) :: lhs
5777  type(variable_t), intent(in) :: this
5778  logical, intent(out), optional :: success
5779  logical :: lsuccess
5780  type :: pt
5781    type(c_ptr), pointer :: p => null()
5782  end type
5783  type(pt) :: p
5784  lsuccess = this%t == "cp0"
5785  if (present(success)) success = lsuccess
5786  if (.not. lsuccess) return
5787  p = transfer(this%enc,p) ! retrieve pointer encoding
5788  lhs = p%p
5789end subroutine assign_get_cp0
5790subroutine associate_get_cp0(lhs,this,dealloc,success)
5791  type(c_ptr), pointer :: lhs
5792  type(variable_t), intent(in) :: this
5793  logical, intent(in), optional :: dealloc
5794  logical, intent(out), optional :: success
5795  logical :: ldealloc, lsuccess
5796  type :: pt
5797    type(c_ptr), pointer :: p => null()
5798  end type
5799  type(pt) :: p
5800  lsuccess = this%t == "cp0"
5801  if (present(success)) success = lsuccess
5802  ! ASSOCIATION in fortran is per default non-destructive
5803  ldealloc = .false.
5804  if(present(dealloc))ldealloc = dealloc
5805  ! there is one problem, say if lhs is not nullified...
5806  if (ldealloc.and.associated(lhs)) then
5807     deallocate(lhs)
5808     nullify(lhs)
5809  end if
5810  if (.not. lsuccess ) return
5811  p = transfer(this%enc,p) ! retrieve pointer encoding
5812  lhs => p%p
5813end subroutine associate_get_cp0
5814subroutine associate_set_cp0(this,rhs,dealloc)
5815  type(variable_t), intent(inout) :: this
5816  type(c_ptr), intent(in), target :: rhs
5817  logical, intent(in), optional :: dealloc
5818  logical :: ldealloc
5819  type :: pt
5820    type(c_ptr), pointer :: p => null()
5821  end type
5822  type(pt) :: p
5823  ! ASSOCIATION in fortran is per default non-destructive
5824  ldealloc = .false.
5825  if(present(dealloc))ldealloc = dealloc
5826  if (ldealloc) then
5827     call delete(this)
5828  else
5829     call nullify(this)
5830  end if
5831  this%t = "cp0"
5832  p%p => rhs
5833  allocate(this%enc(size(transfer(p, local_enc_type)))) ! allocate encoding
5834  this%enc(:) = transfer(p, local_enc_type) ! transfer pointer type to the encoding
5835end subroutine associate_set_cp0
5836pure function associatd_l_cp0(lhs,this) result(ret)
5837  type(c_ptr), pointer :: lhs
5838  type(variable_t), intent(in) :: this
5839  logical :: ret
5840  type :: pt
5841    type(c_ptr), pointer :: p
5842  end type
5843  type(pt) :: p
5844  ret = this%t == "cp0"
5845  if (ret) then
5846     nullify(p%p)
5847     p = transfer(this%enc,p)
5848     ret = associated(lhs,p%p)
5849  endif
5850end function associatd_l_cp0
5851pure function associatd_r_cp0(this,rhs) result(ret)
5852  type(variable_t), intent(in) :: this
5853  type(c_ptr), pointer :: rhs
5854  logical :: ret
5855  type :: pt
5856    type(c_ptr), pointer :: p
5857  end type
5858  type(pt) :: p
5859  ret = this%t == "cp0"
5860  if (ret) then
5861     nullify(p%p)
5862     p = transfer(this%enc,p)
5863     ret = associated(p%p,rhs)
5864  endif
5865end function associatd_r_cp0
5866! All boolean functions
5867subroutine assign_set_cp1(this,rhs,dealloc)
5868  type(variable_t), intent(inout) :: this
5869  type(c_ptr), intent(in), dimension(:) :: rhs
5870  logical, intent(in), optional :: dealloc
5871  logical :: ldealloc
5872  type :: pt
5873    type(c_ptr), pointer , dimension(:) :: p => null()
5874  end type
5875  type(pt) :: p
5876  ! ASSIGNMENT in fortran is per default destructive
5877  ldealloc = .true.
5878  if(present(dealloc))ldealloc = dealloc
5879  if (ldealloc) then
5880     call delete(this)
5881  else
5882     call nullify(this)
5883  end if
5884  ! With pointer transfer we need to deallocate
5885  ! else bounds might change...
5886  this%t = "cp1"
5887  allocate(p%p(size(rhs))) ! allocate space
5888  p%p = rhs ! copy data over
5889  allocate(this%enc(size(transfer(p, local_enc_type)))) ! allocate encoding
5890  this%enc(:) = transfer(p, local_enc_type) ! transfer pointer type to the encoding
5891  ! We already have shipped it
5892  nullify(p%p)
5893end subroutine assign_set_cp1
5894subroutine assign_get_cp1(lhs,this,success)
5895  type(c_ptr), intent(out), dimension(:) :: lhs
5896  type(variable_t), intent(in) :: this
5897  logical, intent(out), optional :: success
5898  logical :: lsuccess
5899  type :: pt
5900    type(c_ptr), pointer , dimension(:) :: p => null()
5901  end type
5902  type(pt) :: p
5903  lsuccess = this%t == "cp1"
5904  if (lsuccess) then
5905    p = transfer(this%enc,p) ! retrieve pointer encoding
5906    lsuccess = all(shape(p%p)==shape(lhs)) !&
5907     ! .and. all((lbound(p%p) == lbound(lhs))) &
5908     ! .and. all((ubound(p%p) == ubound(lhs)))
5909  end if
5910  if (present(success)) success = lsuccess
5911  if (.not. lsuccess) return
5912  lhs = p%p
5913end subroutine assign_get_cp1
5914subroutine associate_get_cp1(lhs,this,dealloc,success)
5915  type(c_ptr), pointer , dimension(:) :: lhs
5916  type(variable_t), intent(in) :: this
5917  logical, intent(in), optional :: dealloc
5918  logical, intent(out), optional :: success
5919  logical :: ldealloc, lsuccess
5920  type :: pt
5921    type(c_ptr), pointer , dimension(:) :: p => null()
5922  end type
5923  type(pt) :: p
5924  lsuccess = this%t == "cp1"
5925  if (present(success)) success = lsuccess
5926  ! ASSOCIATION in fortran is per default non-destructive
5927  ldealloc = .false.
5928  if(present(dealloc))ldealloc = dealloc
5929  ! there is one problem, say if lhs is not nullified...
5930  if (ldealloc.and.associated(lhs)) then
5931     deallocate(lhs)
5932     nullify(lhs)
5933  end if
5934  if (.not. lsuccess ) return
5935  p = transfer(this%enc,p) ! retrieve pointer encoding
5936  lhs => p%p
5937end subroutine associate_get_cp1
5938subroutine associate_set_cp1(this,rhs,dealloc)
5939  type(variable_t), intent(inout) :: this
5940  type(c_ptr), intent(in), dimension(:), target :: rhs
5941  logical, intent(in), optional :: dealloc
5942  logical :: ldealloc
5943  type :: pt
5944    type(c_ptr), pointer , dimension(:) :: p => null()
5945  end type
5946  type(pt) :: p
5947  ! ASSOCIATION in fortran is per default non-destructive
5948  ldealloc = .false.
5949  if(present(dealloc))ldealloc = dealloc
5950  if (ldealloc) then
5951     call delete(this)
5952  else
5953     call nullify(this)
5954  end if
5955  this%t = "cp1"
5956  p%p => rhs
5957  allocate(this%enc(size(transfer(p, local_enc_type)))) ! allocate encoding
5958  this%enc(:) = transfer(p, local_enc_type) ! transfer pointer type to the encoding
5959end subroutine associate_set_cp1
5960pure function associatd_l_cp1(lhs,this) result(ret)
5961  type(c_ptr), pointer , dimension(:) :: lhs
5962  type(variable_t), intent(in) :: this
5963  logical :: ret
5964  type :: pt
5965    type(c_ptr), pointer , dimension(:) :: p
5966  end type
5967  type(pt) :: p
5968  ret = this%t == "cp1"
5969  if (ret) then
5970     nullify(p%p)
5971     p = transfer(this%enc,p)
5972     ret = associated(lhs,p%p)
5973  endif
5974end function associatd_l_cp1
5975pure function associatd_r_cp1(this,rhs) result(ret)
5976  type(variable_t), intent(in) :: this
5977  type(c_ptr), pointer , dimension(:) :: rhs
5978  logical :: ret
5979  type :: pt
5980    type(c_ptr), pointer , dimension(:) :: p
5981  end type
5982  type(pt) :: p
5983  ret = this%t == "cp1"
5984  if (ret) then
5985     nullify(p%p)
5986     p = transfer(this%enc,p)
5987     ret = associated(p%p,rhs)
5988  endif
5989end function associatd_r_cp1
5990! All boolean functions
5991subroutine assign_set_fp0(this,rhs,dealloc)
5992  type(variable_t), intent(inout) :: this
5993  type(c_funptr), intent(in) :: rhs
5994  logical, intent(in), optional :: dealloc
5995  logical :: ldealloc
5996  type :: pt
5997    type(c_funptr), pointer :: p => null()
5998  end type
5999  type(pt) :: p
6000  ! ASSIGNMENT in fortran is per default destructive
6001  ldealloc = .true.
6002  if(present(dealloc))ldealloc = dealloc
6003  if (ldealloc) then
6004     call delete(this)
6005  else
6006     call nullify(this)
6007  end if
6008  ! With pointer transfer we need to deallocate
6009  ! else bounds might change...
6010  this%t = "fp0"
6011  allocate(p%p) ! allocate space
6012  p%p = rhs ! copy data over
6013  allocate(this%enc(size(transfer(p, local_enc_type)))) ! allocate encoding
6014  this%enc(:) = transfer(p, local_enc_type) ! transfer pointer type to the encoding
6015  ! We already have shipped it
6016  nullify(p%p)
6017end subroutine assign_set_fp0
6018subroutine assign_get_fp0(lhs,this,success)
6019  type(c_funptr), intent(out) :: lhs
6020  type(variable_t), intent(in) :: this
6021  logical, intent(out), optional :: success
6022  logical :: lsuccess
6023  type :: pt
6024    type(c_funptr), pointer :: p => null()
6025  end type
6026  type(pt) :: p
6027  lsuccess = this%t == "fp0"
6028  if (present(success)) success = lsuccess
6029  if (.not. lsuccess) return
6030  p = transfer(this%enc,p) ! retrieve pointer encoding
6031  lhs = p%p
6032end subroutine assign_get_fp0
6033subroutine associate_get_fp0(lhs,this,dealloc,success)
6034  type(c_funptr), pointer :: lhs
6035  type(variable_t), intent(in) :: this
6036  logical, intent(in), optional :: dealloc
6037  logical, intent(out), optional :: success
6038  logical :: ldealloc, lsuccess
6039  type :: pt
6040    type(c_funptr), pointer :: p => null()
6041  end type
6042  type(pt) :: p
6043  lsuccess = this%t == "fp0"
6044  if (present(success)) success = lsuccess
6045  ! ASSOCIATION in fortran is per default non-destructive
6046  ldealloc = .false.
6047  if(present(dealloc))ldealloc = dealloc
6048  ! there is one problem, say if lhs is not nullified...
6049  if (ldealloc.and.associated(lhs)) then
6050     deallocate(lhs)
6051     nullify(lhs)
6052  end if
6053  if (.not. lsuccess ) return
6054  p = transfer(this%enc,p) ! retrieve pointer encoding
6055  lhs => p%p
6056end subroutine associate_get_fp0
6057subroutine associate_set_fp0(this,rhs,dealloc)
6058  type(variable_t), intent(inout) :: this
6059  type(c_funptr), intent(in), target :: rhs
6060  logical, intent(in), optional :: dealloc
6061  logical :: ldealloc
6062  type :: pt
6063    type(c_funptr), pointer :: p => null()
6064  end type
6065  type(pt) :: p
6066  ! ASSOCIATION in fortran is per default non-destructive
6067  ldealloc = .false.
6068  if(present(dealloc))ldealloc = dealloc
6069  if (ldealloc) then
6070     call delete(this)
6071  else
6072     call nullify(this)
6073  end if
6074  this%t = "fp0"
6075  p%p => rhs
6076  allocate(this%enc(size(transfer(p, local_enc_type)))) ! allocate encoding
6077  this%enc(:) = transfer(p, local_enc_type) ! transfer pointer type to the encoding
6078end subroutine associate_set_fp0
6079pure function associatd_l_fp0(lhs,this) result(ret)
6080  type(c_funptr), pointer :: lhs
6081  type(variable_t), intent(in) :: this
6082  logical :: ret
6083  type :: pt
6084    type(c_funptr), pointer :: p
6085  end type
6086  type(pt) :: p
6087  ret = this%t == "fp0"
6088  if (ret) then
6089     nullify(p%p)
6090     p = transfer(this%enc,p)
6091     ret = associated(lhs,p%p)
6092  endif
6093end function associatd_l_fp0
6094pure function associatd_r_fp0(this,rhs) result(ret)
6095  type(variable_t), intent(in) :: this
6096  type(c_funptr), pointer :: rhs
6097  logical :: ret
6098  type :: pt
6099    type(c_funptr), pointer :: p
6100  end type
6101  type(pt) :: p
6102  ret = this%t == "fp0"
6103  if (ret) then
6104     nullify(p%p)
6105     p = transfer(this%enc,p)
6106     ret = associated(p%p,rhs)
6107  endif
6108end function associatd_r_fp0
6109! All boolean functions
6110subroutine assign_set_fp1(this,rhs,dealloc)
6111  type(variable_t), intent(inout) :: this
6112  type(c_funptr), intent(in), dimension(:) :: rhs
6113  logical, intent(in), optional :: dealloc
6114  logical :: ldealloc
6115  type :: pt
6116    type(c_funptr), pointer , dimension(:) :: p => null()
6117  end type
6118  type(pt) :: p
6119  ! ASSIGNMENT in fortran is per default destructive
6120  ldealloc = .true.
6121  if(present(dealloc))ldealloc = dealloc
6122  if (ldealloc) then
6123     call delete(this)
6124  else
6125     call nullify(this)
6126  end if
6127  ! With pointer transfer we need to deallocate
6128  ! else bounds might change...
6129  this%t = "fp1"
6130  allocate(p%p(size(rhs))) ! allocate space
6131  p%p = rhs ! copy data over
6132  allocate(this%enc(size(transfer(p, local_enc_type)))) ! allocate encoding
6133  this%enc(:) = transfer(p, local_enc_type) ! transfer pointer type to the encoding
6134  ! We already have shipped it
6135  nullify(p%p)
6136end subroutine assign_set_fp1
6137subroutine assign_get_fp1(lhs,this,success)
6138  type(c_funptr), intent(out), dimension(:) :: lhs
6139  type(variable_t), intent(in) :: this
6140  logical, intent(out), optional :: success
6141  logical :: lsuccess
6142  type :: pt
6143    type(c_funptr), pointer , dimension(:) :: p => null()
6144  end type
6145  type(pt) :: p
6146  lsuccess = this%t == "fp1"
6147  if (lsuccess) then
6148    p = transfer(this%enc,p) ! retrieve pointer encoding
6149    lsuccess = all(shape(p%p)==shape(lhs)) !&
6150     ! .and. all((lbound(p%p) == lbound(lhs))) &
6151     ! .and. all((ubound(p%p) == ubound(lhs)))
6152  end if
6153  if (present(success)) success = lsuccess
6154  if (.not. lsuccess) return
6155  lhs = p%p
6156end subroutine assign_get_fp1
6157subroutine associate_get_fp1(lhs,this,dealloc,success)
6158  type(c_funptr), pointer , dimension(:) :: lhs
6159  type(variable_t), intent(in) :: this
6160  logical, intent(in), optional :: dealloc
6161  logical, intent(out), optional :: success
6162  logical :: ldealloc, lsuccess
6163  type :: pt
6164    type(c_funptr), pointer , dimension(:) :: p => null()
6165  end type
6166  type(pt) :: p
6167  lsuccess = this%t == "fp1"
6168  if (present(success)) success = lsuccess
6169  ! ASSOCIATION in fortran is per default non-destructive
6170  ldealloc = .false.
6171  if(present(dealloc))ldealloc = dealloc
6172  ! there is one problem, say if lhs is not nullified...
6173  if (ldealloc.and.associated(lhs)) then
6174     deallocate(lhs)
6175     nullify(lhs)
6176  end if
6177  if (.not. lsuccess ) return
6178  p = transfer(this%enc,p) ! retrieve pointer encoding
6179  lhs => p%p
6180end subroutine associate_get_fp1
6181subroutine associate_set_fp1(this,rhs,dealloc)
6182  type(variable_t), intent(inout) :: this
6183  type(c_funptr), intent(in), dimension(:), target :: rhs
6184  logical, intent(in), optional :: dealloc
6185  logical :: ldealloc
6186  type :: pt
6187    type(c_funptr), pointer , dimension(:) :: p => null()
6188  end type
6189  type(pt) :: p
6190  ! ASSOCIATION in fortran is per default non-destructive
6191  ldealloc = .false.
6192  if(present(dealloc))ldealloc = dealloc
6193  if (ldealloc) then
6194     call delete(this)
6195  else
6196     call nullify(this)
6197  end if
6198  this%t = "fp1"
6199  p%p => rhs
6200  allocate(this%enc(size(transfer(p, local_enc_type)))) ! allocate encoding
6201  this%enc(:) = transfer(p, local_enc_type) ! transfer pointer type to the encoding
6202end subroutine associate_set_fp1
6203pure function associatd_l_fp1(lhs,this) result(ret)
6204  type(c_funptr), pointer , dimension(:) :: lhs
6205  type(variable_t), intent(in) :: this
6206  logical :: ret
6207  type :: pt
6208    type(c_funptr), pointer , dimension(:) :: p
6209  end type
6210  type(pt) :: p
6211  ret = this%t == "fp1"
6212  if (ret) then
6213     nullify(p%p)
6214     p = transfer(this%enc,p)
6215     ret = associated(lhs,p%p)
6216  endif
6217end function associatd_l_fp1
6218pure function associatd_r_fp1(this,rhs) result(ret)
6219  type(variable_t), intent(in) :: this
6220  type(c_funptr), pointer , dimension(:) :: rhs
6221  logical :: ret
6222  type :: pt
6223    type(c_funptr), pointer , dimension(:) :: p
6224  end type
6225  type(pt) :: p
6226  ret = this%t == "fp1"
6227  if (ret) then
6228     nullify(p%p)
6229     p = transfer(this%enc,p)
6230     ret = associated(p%p,rhs)
6231  endif
6232end function associatd_r_fp1
6233! All boolean functions
6234end module variable
6235