New URL for NEMO forge!   http://forge.nemo-ocean.eu

Since March 2022 along with NEMO 4.2 release, the code development moved to a self-hosted GitLab.
This present forge is now archived and remained online for history.
t1.f90 in vendors/t/fcm-make/02-build-ext-iface/src – NEMO

source: vendors/t/fcm-make/02-build-ext-iface/src/t1.f90 @ 10669

Last change on this file since 10669 was 10669, checked in by nicolasmartin, 5 years ago

Import latest FCM release from Github into the repository for testing

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