SURFEX  V8_0
Surfex V8_0 release
 All Classes Files Functions Variables
modi_gltools_genlist.F90
Go to the documentation of this file.
1 !SFX_LIC Copyright 1994-2014 CNRS, Meteo-France and Universite Paul Sabatier
2 !SFX_LIC This is part of the SURFEX software governed by the CeCILL-C licence
3 !SFX_LIC version 1. See LICENSE, CeCILL-C_V1-en.txt and CeCILL-C_V1-fr.txt
4 !SFX_LIC for details. version 1.
5 !GLT_LIC The GELATO model is a seaice model used in stand-alone or embedded mode.
6 !GLT_LIC It has been developed by Meteo-France. The holder of GELATO is Meteo-France.
7 !GLT_LIC
8 !GLT_LIC This software is governed by the CeCILL-C license under French law and biding
9 !GLT_LIC by the rules of distribution of free software. See the CeCILL-C_V1-en.txt
10 !GLT_LIC (English) and CeCILL-C_V1-fr.txt (French) for details. The CeCILL is a free
11 !GLT_LIC software license, explicitly compatible with the GNU GPL
12 !GLT_LIC (see http://www.gnu.org/licenses/license-list.en.html#CeCILL)
13 !GLT_LIC
14 !GLT_LIC The CeCILL-C licence agreement grants users the right to modify and re-use the
15 !GLT_LIC software governed by this free software license. The exercising of this right
16 !GLT_LIC is conditional upon the obligation to make available to the community the
17 !GLT_LIC modifications made to the source code of the software so as to contribute to
18 !GLT_LIC its evolution.
19 !GLT_LIC
20 !GLT_LIC In consideration of access to the source code and the rights to copy, modify
21 !GLT_LIC and redistribute granted by the license, users are provided only with a limited
22 !GLT_LIC warranty and the software's author, the holder of the economic rights, and the
23 !GLT_LIC successive licensors only have limited liability. In this respect, the risks
24 !GLT_LIC associated with loading, using, modifying and/or developing or reproducing the
25 !GLT_LIC software by the user are brought to the user's attention, given its Free
26 !GLT_LIC Software status, which may make it complicated to use, with the result that its
27 !GLT_LIC use is reserved for developers and experienced professionals having in-depth
28 !GLT_LIC computer knowledge. Users are therefore encouraged to load and test the
29 !GLT_LIC suitability of the software as regards their requirements in conditions enabling
30 !GLT_LIC the security of their systems and/or data to be ensured and, more generally, to
31 !GLT_LIC use and operate it in the same conditions of security.
32 !GLT_LIC
33 !GLT_LIC The GELATO sofware is cureently distibuted with the SURFEX software, available at
34 !GLT_LIC http://www.cnrm.meteo.fr/surfex. The fact that you download the software deemed that
35 !GLT_LIC you had knowledge of the CeCILL-C license and that you accept its terms.
36 !GLT_LIC Attempts to use this software in a way not complying with CeCILL-C license
37 !GLT_LIC may lead to prosecution.
38 !GLT_LIC
39 ! A generic linked list object
41 !
42  implicit none
43 
44  private
45 
46  public :: list_t
47  public :: list_data
48  public :: list_init
49  public :: list_free
50  public :: list_insert
51  public :: list_put
52  public :: list_get
53  public :: list_next
54  public :: list_count
55 
56  ! A public variable to use as a MOLD for transfer()
57  integer, dimension(:), allocatable :: list_data
58 
59  ! Linked list node data type
60  type :: list_t
61  private
62  integer, dimension(:), pointer :: data => null()
63  type(list_t), pointer :: next => null()
64  end type list_t
65 
66 contains
67 
68  ! Initialize a head node SELF and optionally store the provided DATA.
69  subroutine list_init(self, data)
70  type(list_t), pointer :: self
71  integer, dimension(:), intent(in), optional :: data
72 
73  allocate(self)
74  nullify(self%next)
75 
76  if (present(data)) then
77  allocate(self%data(size(data)))
78  self%data = data
79  else
80  nullify(self%data)
81  end if
82  end subroutine list_init
83 
84  ! Free the entire list and all data, beginning at SELF
85  subroutine list_free(self)
86  type(list_t), pointer :: self
87  type(list_t), pointer :: current
88  type(list_t), pointer :: next
89 
90  current => self
91  do while (associated(current))
92  next => current%next
93  if (associated(current%data)) then
94  deallocate(current%data)
95  nullify(current%data)
96  end if
97  deallocate(current)
98  nullify(current)
99  current => next
100  end do
101  end subroutine list_free
102 
103  ! Return the next node after SELF
104  function list_next(self) result(next)
105  type(list_t), pointer :: self
106  type(list_t), pointer :: next
107  next => self%next
108  end function list_next
109 
110  ! Insert a list node after SELF containing DATA (optional)
111  subroutine list_insert(self, data)
112  type(list_t), pointer :: self
113  integer, dimension(:), intent(in), optional :: data
114  type(list_t), pointer :: next
115 
116  allocate(next)
117 
118  if (present(data)) then
119  allocate(next%data(size(data)))
120  next%data = data
121  else
122  nullify(next%data)
123  end if
124 
125  next%next => self%next
126  self%next => next
127  end subroutine list_insert
128 
129  ! Store the encoded DATA in list node SELF
130  subroutine list_put(self, data)
131  type(list_t), pointer :: self
132  integer, dimension(:), intent(in) :: data
133 
134  if (associated(self%data)) then
135  deallocate(self%data)
136  nullify(self%data)
137  end if
138  self%data = data
139  end subroutine list_put
140 
141  ! Return the DATA stored in the node SELF
142  function list_get(self) result(data)
143  type(list_t), pointer :: self
144  integer, dimension(:), pointer :: data
145  data => self%data
146  end function list_get
147 
148  INTEGER FUNCTION list_count( self )
149  TYPE(list_t), POINTER :: self
150 
151  TYPE(list_t), POINTER :: current,next
152 
153  IF ( ASSOCIATED(self) ) then
154  list_count = 1
155  current => self
156  DO WHILE ( ASSOCIATED(current%next) )
157  current => current%next
158  list_count = list_count + 1
159  END DO
160  ELSE
161  list_count = 0
162  END IF
163  END FUNCTION list_count
164 
165 end module modi_gltools_genlist
type(list_node_t) function, pointer, public list_next(self)
subroutine, public list_insert(self, data)
subroutine, public list_put(self, data)
INTEGER function, public list_count(self)
subroutine, public list_init(self, data)
subroutine, public list_free(self)
integer function, dimension(:), pointer, public list_get(self)