coarray_41.f90: Add "-latomic" option if libatomic_available.
[official-gcc.git] / gcc / testsuite / gfortran.dg / class_allocate_12.f90
blobd50943d5e447f39a766fb777c6736c2377112e42
1 ! { dg-do run }
3 ! PR fortran/51972
5 ! Contributed by Damian Rouson
7 module surrogate_module
8 type ,abstract :: surrogate
9 end type
10 end module
12 module strategy_module
13 use surrogate_module
15 type :: strategy
16 end type
17 end module
19 module integrand_module
20 use surrogate_module
21 use strategy_module
22 implicit none
24 type ,abstract, extends(surrogate) :: integrand
25 class(strategy), allocatable :: quadrature
26 end type
27 end module integrand_module
29 module lorenz_module
30 use strategy_module
31 use integrand_module
32 implicit none
34 type ,extends(integrand) :: lorenz
35 real, dimension(:), allocatable :: state
36 contains
37 procedure ,public :: assign => assign_lorenz
38 end type
39 contains
40 type(lorenz) function constructor(initial_state, this_strategy)
41 real ,dimension(:) ,intent(in) :: initial_state
42 class(strategy) ,intent(in) :: this_strategy
43 constructor%state=initial_state
44 allocate (constructor%quadrature, source=this_strategy)
45 end function
47 subroutine assign_lorenz(lhs,rhs)
48 class(lorenz) ,intent(inout) :: lhs
49 class(integrand) ,intent(in) :: rhs
50 select type(rhs)
51 class is (lorenz)
52 allocate (lhs%quadrature, source=rhs%quadrature)
53 lhs%state=rhs%state
54 end select
55 end subroutine
56 end module lorenz_module
58 module runge_kutta_2nd_module
59 use surrogate_module,only : surrogate
60 use strategy_module ,only : strategy
61 use integrand_module,only : integrand
62 implicit none
64 type, extends(strategy) ,public :: runge_kutta_2nd
65 contains
66 procedure, nopass :: integrate
67 end type
68 contains
69 subroutine integrate(this)
70 class(surrogate) ,intent(inout) :: this
71 class(integrand) ,allocatable :: this_half
73 select type (this)
74 class is (integrand)
75 allocate (this_half, source=this)
76 end select
77 end subroutine
78 end module
80 program main
81 use lorenz_module
82 use runge_kutta_2nd_module ,only : runge_kutta_2nd, integrate
83 implicit none
85 type(runge_kutta_2nd) :: timed_lorenz_integrator
86 type(lorenz) :: attractor
88 attractor = constructor( [1., 1., 1.] , timed_lorenz_integrator)
89 call integrate(attractor)
90 end program main