Skip to content

Commit 02fd41b

Browse files
committed
add character allocatable example
1 parent 9a86a37 commit 02fd41b

File tree

3 files changed

+26
-0
lines changed

3 files changed

+26
-0
lines changed

character/CMakeLists.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,10 @@ add_test(NAME char:AsciiSpecial COMMAND ascii)
44
add_executable(character_array character_array.f90)
55
add_test(NAME char:array COMMAND character_array)
66

7+
add_executable(character_allocatable character_allocatable.f90)
8+
add_test(NAME char:allocatable COMMAND character_allocatable)
9+
10+
711
add_executable(split split_string.f90)
812
add_test(NAME char:SplitString COMMAND split)
913

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
program character_alloctable
2+
!! shows Fortran 2003 allocatable character and auto-allocated array
3+
implicit none
4+
5+
character(:), allocatable :: flex(:)
6+
7+
flex = [character(9) :: 'hi', 'hello', 'greetings']
8+
9+
if (size(flex) /= 3) error stop
10+
if (len(flex(1)) /= 9) error stop
11+
if (len_trim(flex(1)) /= 2) error stop
12+
13+
flex = [character(8) :: 'bye', 'goodbye', 'farewell', 'sayanora']
14+
15+
if (size(flex) /= 4) error stop
16+
if (len(flex(1)) /= 8) error stop
17+
if (len_trim(flex(1)) /= 3) error stop
18+
19+
end program

character/meson.build

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@ test('Ascii Special', ascii, suite: 'char', timeout: 10)
44
char_array = executable('character_array', 'character_array.f90')
55
test('CharacterArray', char_array, suite: 'char', timeout: 10)
66

7+
char_alloc = executable('character_allocatable', 'character_allocatable.f90')
8+
test('CharacterAllocatable', char_alloc, suite: 'char', timeout: 10)
9+
710
split = executable('split', 'split_string.f90')
811
test('Split Character', split, suite: 'char', timeout: 10)
912

0 commit comments

Comments
 (0)