File: string_87.f90

package info (click to toggle)
lfortran 0.59.0-3
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 56,736 kB
  • sloc: cpp: 168,052; f90: 74,272; python: 17,537; ansic: 7,705; yacc: 2,345; sh: 1,334; fortran: 895; makefile: 37; javascript: 15
file content (83 lines) | stat: -rw-r--r-- 1,896 bytes parent folder | download | duplicates (3)
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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
! Test StringToArray casting
program string_87
    character(10) :: str
    character(10) :: str2
    
    str = "HelloWorld"
    call ff1(str)
    print *, str
    if(str /= "HelloWTrld") error stop 3
    
    str = "HelloWorld"
    call ff2(str)
    print *, str
    if(str /= "HelloWTrld") error stop 6
    
    str = "HelloWorld"
    call ff3(str)
    print *, str
    if(str /= "HelloWTrld") error stop 9
    
    str = "HelloWorld"
    call ff4(str)
    print *, str
    if(str /= "HelloWTrld") error stop 12
    
    ! TODO :: SUPPORT CASE BELOW

    ! str = "HelloWorld"
    ! call ff5(str, 2)
    ! print *, str
    ! if(str /= "HelloWTrld") error stop 15
    
    str = "Hello"
    call ff1_1(trim(str)//"World")

    contains
    
    subroutine ff1(s)
      character(5) :: s(2)
      if(s(1) /= "Hello") error stop 1
      if(s(2) /= "World") error stop 2
      s(2)(2:2) = "T"
    end subroutine

    subroutine ff2(s)
      character(5) :: s(*)
      if(s(1) /= "Hello") error stop 4
      if(s(2) /= "World") error stop 5
      s(2)(2:2) = "T"
    end subroutine

    subroutine ff3(s)
      character(*) :: s(1)
      if(len(s(1)) /= 10) error stop 7
      if(s(1) /= "HelloWorld") error stop 8
      s(1)(7:7) = "T"
    end subroutine

    subroutine ff4(s)
      character(*) :: s(*)
      if(len(s(1)) /= 10) error stop 10
      if(s(1) /= "HelloWorld") error stop 11
      s(1)(7:7) = "T"
    end subroutine

    subroutine ff5(s, n)
      integer :: n
      character(*) :: s(n)
      if(len(s(1)) /= 10) error stop 13
      if(s(1) /= "HelloWorld") error stop 14
      s(1)(7:7) = "T"
    end subroutine

    subroutine ff1_1(s)
      character(2) :: s(5)
      if(s(1) /= "He") error stop 16
      if(s(2) /= "ll") error stop 17
      if(s(3) /= "oW") error stop 18
      if(s(4) /= "or") error stop 19
      if(s(5) /= "ld") error stop 20
    end subroutine

end program