5 ! Test deferred-length character arguments to selected intrinsics
6 ! that may return a character result of same length as first argument:
7 ! CSHIFT, EOSHIFT, MAXVAL, MERGE, MINVAL, PACK, SPREAD, TRANSPOSE, UNPACK
18 character(len
=:), allocatable
:: m(:)
20 m
= [ character(len
=10) :: 'ape','bat','cat','dog','eel','fly','gnu']
21 m
= pack (m
, mask
=(m(:)(2:2) == 'a'))
23 ! print *, "m = '", m,"' ", "; expected is ['bat','cat']"
24 if (.not
. all (m
== ['bat','cat'])) stop 1
26 ! print *, "size(m) = ", size(m), "; expected is 2"
27 if (size (m
) /= 2) stop 2
29 ! print *, "len(m) = ", len(m), "; expected is 10"
30 if (len (m
) /= 10) stop 3
32 ! print *, "len_trim(m) = ", len_trim(m), "; expected is 3 3"
33 if (.not
. all (len_trim(m
) == [3,3])) stop 4
37 character(len
=:), allocatable
:: array(:), array2(:,:)
38 character(len
=:), allocatable
:: res
, res1(:), res2(:)
40 array
= ["bb", "aa", "cc"]
43 if (res
/= "aa") stop 11
45 res
= maxval (array
, mask
=[.true
.,.true
.,.false
.])
46 if (res
/= "bb") stop 12
48 res1
= cshift (array
, 1)
49 if (any (res1
/= ["aa","cc","bb"])) stop 13
51 res2
= eoshift (res1
, -1)
52 if (any (res2
/= [" ", "aa", "cc"])) stop 14
54 res2
= pack (array
, mask
=[.true
.,.false
.,.true
.])
55 if (any (res2
/= ["bb","cc"])) stop 15
57 res2
= unpack (res2
, mask
=[.true
.,.false
.,.true
.], field
="aa")
58 if (any (res2
/= array
)) stop 16
60 res2
= merge (res2
, array
, [.true
.,.false
.,.true
.])
61 if (any (res2
/= array
)) stop 17
63 array2
= spread (array
, dim
=2, ncopies
=2)
64 array2
= transpose (array2
)
65 if (any (shape (array2
) /= [2,3])) stop 18
66 if (any (array2(2,:) /= array
)) stop 19
70 character(:), allocatable
:: array1(:), array2(:)
71 array1
= ["aa","cc","bb"]
72 array2
= copy (array1
)
73 if (any (array1
/= array2
)) stop 20
76 function copy (arg
) result (res
)
77 character(:), allocatable
:: res(:)
78 character(*), intent(in
) :: arg(:)
82 allocate (character(k
) :: res(n
))