File: string_83.f90

package info (click to toggle)
lfortran 0.58.0-6
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 54,512 kB
  • sloc: cpp: 162,179; f90: 68,251; python: 17,476; ansic: 6,278; yacc: 2,334; sh: 1,317; fortran: 892; makefile: 37; javascript: 15
file content (48 lines) | stat: -rw-r--r-- 1,447 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
module string_83_mod
    implicit none
    public
    character(len=*), parameter :: char_arr_global(4, 1) = reshape([ character(len=30) :: &
        "YES",&
        "\d                    ",&
        "5                             ",&
        "1 "], [4,1])

    contains

    subroutine sub(str)
        character(*), intent(out) :: str

        character(len(char_arr_global)) :: buffer
        if(len(buffer) /= 30) error stop

        if(len(char_arr_global(1, 1)) /= 30) error stop
        if(trim(char_arr_global(1, 1)) /= "YES") error stop
        if(trim(char_arr_global(2, 1)) /= "\d") error stop
        if(trim(char_arr_global(3, 1)) /= "5") error stop
        if(trim(char_arr_global(4, 1)) /= "1") error stop

        if(len(str) /= 30) error stop
        str = char_arr_global(3, 1)
    end subroutine

end module


program string_83
    use string_83_mod
    implicit none
    character(len=30) :: str
    character(:), allocatable :: write_buffer
    call sub(str)
    
    if(str /= char_arr_global(3, 1)) error stop

    allocate(character(len=len(char_arr_global)* size(char_arr_global)) :: write_buffer)
    write(write_buffer, "(4A)") char_arr_global
    print *, write_buffer
    if(write_buffer /= "YES                           &
                        \d                            &
                        5                             &
                        1                             ") error stop

end program