1 | ! A simple function |
---|
2 | logical function func_simple() |
---|
3 | func_simple = .true. |
---|
4 | end function func_simple |
---|
5 | |
---|
6 | ! A simple function, but with less friendly end |
---|
7 | logical function func_simple_1() |
---|
8 | func_simple_1 = .true. |
---|
9 | end function |
---|
10 | |
---|
11 | ! A simple function, but with even less friendly end |
---|
12 | logical function func_simple_2() |
---|
13 | func_simple_2 = .true. |
---|
14 | end |
---|
15 | |
---|
16 | ! A pure simple function |
---|
17 | pure logical function func_simple_pure() |
---|
18 | func_simple_pure = .true. |
---|
19 | end function func_simple_pure |
---|
20 | |
---|
21 | ! A pure recursive function |
---|
22 | recursive pure integer function func_simple_recursive_pure(i) |
---|
23 | integer, intent(in) :: i |
---|
24 | if (i <= 0) then |
---|
25 | func_simple_recursive_pure = i |
---|
26 | else |
---|
27 | func_simple_recursive_pure = i + func_simple_recursive_pure(i - 1) |
---|
28 | end if |
---|
29 | end function func_simple_recursive_pure |
---|
30 | |
---|
31 | ! An elemental simple function |
---|
32 | elemental logical function func_simple_elemental() |
---|
33 | func_simple_elemental = .true. |
---|
34 | end function func_simple_elemental |
---|
35 | |
---|
36 | ! An function with arguments and module imports |
---|
37 | integer(selected_int_kind(0)) function func_with_use_and_args(egg, ham) |
---|
38 | use foo |
---|
39 | ! Deliberate trailing spaces in next line |
---|
40 | use bar, only : organic, i_am_dim |
---|
41 | implicit none |
---|
42 | integer, intent(in) :: egg(i_am_dim) |
---|
43 | integer, intent(in) :: ham(i_am_dim, 2) |
---|
44 | real bacon |
---|
45 | ! Deliberate trailing spaces in next line |
---|
46 | type( organic ) :: tomato |
---|
47 | func_with_use_and_args = egg(1) + ham(1, 1) |
---|
48 | end function func_with_use_and_args |
---|
49 | |
---|
50 | ! A function with some parameters |
---|
51 | character(20) function func_with_parameters(egg, ham) |
---|
52 | implicit none |
---|
53 | character*(*), parameter :: x_param = '01234567890' |
---|
54 | character(*), parameter :: & ! throw in some comments |
---|
55 | y_param & |
---|
56 | = '!&!&!&!&!&!' ! how to make life interesting |
---|
57 | integer, parameter :: z = 20 |
---|
58 | character(len(x_param)), intent(in) :: egg |
---|
59 | character(len(y_param)), intent(in) :: ham |
---|
60 | func_with_parameters = egg // ham |
---|
61 | end function func_with_parameters |
---|
62 | |
---|
63 | ! A function with some parameters, with a result |
---|
64 | function func_with_parameters_1(egg, ham) result(r) |
---|
65 | implicit none |
---|
66 | integer, parameter :: x_param = 10 |
---|
67 | integer z_param |
---|
68 | parameter(z_param = 2) |
---|
69 | real, intent(in), dimension(x_param) :: egg |
---|
70 | integer, intent(in) :: ham |
---|
71 | logical :: r(z_param) |
---|
72 | r(1) = int(egg(1)) + ham > 0 |
---|
73 | r(2) = .false. |
---|
74 | end function func_with_parameters_1 |
---|
75 | |
---|
76 | ! A function with a contains |
---|
77 | character(10) function func_with_contains(mushroom, tomoato) |
---|
78 | character(5) mushroom |
---|
79 | character(5) tomoato |
---|
80 | func_with_contains = func_with_contains_1() |
---|
81 | contains |
---|
82 | character(10) function func_with_contains_1() |
---|
83 | func_with_contains_1 = mushroom // tomoato |
---|
84 | end function func_with_contains_1 |
---|
85 | end function func_with_contains |
---|
86 | |
---|
87 | ! A function with its result declared after a local in the same statement |
---|
88 | Function func_mix_local_and_result(egg, ham, bacon) Result(Breakfast) |
---|
89 | Integer, Intent(in) :: egg, ham |
---|
90 | Real, Intent(in) :: bacon |
---|
91 | Real :: tomato, breakfast |
---|
92 | Breakfast = real(egg) + real(ham) + bacon |
---|
93 | End Function func_mix_local_and_result |
---|
94 | |
---|
95 | ! A simple subroutine |
---|
96 | subroutine sub_simple() |
---|
97 | end subroutine sub_simple |
---|
98 | |
---|
99 | ! A simple subroutine, with not so friendly end |
---|
100 | subroutine sub_simple_1() |
---|
101 | end subroutine |
---|
102 | |
---|
103 | ! A simple subroutine, with even less friendly end |
---|
104 | subroutine sub_simple_2() |
---|
105 | end |
---|
106 | |
---|
107 | ! A simple subroutine, with funny continuation |
---|
108 | subroutine sub_simple_3() |
---|
109 | end sub& |
---|
110 | &routine& |
---|
111 | & sub_simple_3 |
---|
112 | |
---|
113 | ! A subroutine with a few contains |
---|
114 | subroutine sub_with_contains(foo) ! " & |
---|
115 | ! Deliberate trailing spaces in next line |
---|
116 | use Bar, only: i_am_dim |
---|
117 | character*(len('!"&''&"!')) & ! what a mess! |
---|
118 | foo |
---|
119 | call sub_with_contains_first() |
---|
120 | call sub_with_contains_second() |
---|
121 | call sub_with_contains_third() |
---|
122 | print*, foo |
---|
123 | contains |
---|
124 | subroutine sub_with_contains_first() |
---|
125 | interface |
---|
126 | integer function x() |
---|
127 | end function x |
---|
128 | end interface |
---|
129 | end subroutine sub_with_contains_first |
---|
130 | subroutine sub_with_contains_second() |
---|
131 | end subroutine |
---|
132 | subroutine sub_with_contains_third() |
---|
133 | end subroutine |
---|
134 | end subroutine sub_with_contains |
---|
135 | |
---|
136 | ! A subroutine with a renamed module import |
---|
137 | subroutine sub_with_renamed_import(i_am_dim) |
---|
138 | use bar, only: i_am_not_dim => i_am_dim |
---|
139 | integer, parameter :: d = 2 |
---|
140 | complex :: i_am_dim(d) |
---|
141 | print*, i_am_dim |
---|
142 | end subroutine sub_with_renamed_import |
---|
143 | |
---|
144 | ! A subroutine with an external argument |
---|
145 | subroutine sub_with_external(proc) |
---|
146 | external proc |
---|
147 | call proc() |
---|
148 | end subroutine sub_with_external |
---|
149 | |
---|
150 | ! A subroutine with an external argument, 2 |
---|
151 | ! https://github.com/metomi/fcm/issues/175 |
---|
152 | subroutine sub_with_external2(PROC) |
---|
153 | external proc |
---|
154 | call proc() |
---|
155 | end subroutine sub_with_external2 |
---|
156 | |
---|
157 | ! A subroutine with an external argument, 3 |
---|
158 | ! https://github.com/metomi/fcm/issues/175 |
---|
159 | subroutine sub_with_external3(proc) |
---|
160 | external PROC |
---|
161 | call proc() |
---|
162 | end subroutine sub_with_external3 |
---|
163 | |
---|
164 | ! A subroutine with a variable named "end" |
---|
165 | subroutine sub_with_end() |
---|
166 | integer :: end |
---|
167 | end = 0 |
---|
168 | end subroutine sub_with_end |
---|
169 | |
---|
170 | ! A module with nonsense |
---|
171 | module stuff |
---|
172 | character(*), parameter :: stuffing = 'yummy' |
---|
173 | contains |
---|
174 | subroutine matter() |
---|
175 | print*, 'Matter is not dark' |
---|
176 | end subroutine matter |
---|
177 | end module stuff |
---|