Soil Water Balance (SWB2)
Loading...
Searching...
No Matches
data_catalog.F90
Go to the documentation of this file.
1!> @file
2!! Contains module @ref data_catalog, defining the @DATA_CATALOG_T data type, which contains type-bound
3!! procedures to add, delete, and find @ref DATA_CATALOG_ENTRY_T values
4!! created during the course of a SWB run.
5
6
7!> Defines the @ref DATA_CATALOG_T data type, which contains type-bound
8!! procedures to add, delete, and find @ref DATA_CATALOG_ENTRY_T values
9!! created during the course of a SWB run.
11
12 use iso_c_binding, only : c_int, c_float, c_bool, c_double
13 use logfiles, only : logs, log_all, log_debug
14 use fstring
16 implicit none
17
18 private
19
20 public :: data_catalog_t
21
22 !> @typedef DATA_CATALOG_T data type contains type-bound
23 !! procedures to add, delete, and find @ref DATA_CATALOG_ENTRY_T values
24 !! created during the course of a SWB run.
26 type (data_catalog_entry_t), pointer :: first => null()
27 type (data_catalog_entry_t), pointer :: last => null()
28 type (data_catalog_entry_t), pointer :: current => null()
29 integer (c_int) :: count = 0
30 contains
31
32 private
33
34 procedure :: catalog_add_entry_sub
35 procedure :: catalog_delete_entry_sub
36 procedure :: catalog_find_key_fn
37 procedure :: catalog_find_next_key_fn
38 procedure :: catalog_get_entry_at_index_fn
39 procedure :: catalog_print_sub
40 procedure :: catalog_set_all_proj4_string_sub
41 procedure :: catalog_set_all_start_year_sub
42 procedure :: catalog_set_all_end_year_sub
43
44 !> Add a data_catalog_entry object to the data_catalog.
45 generic, public :: add => catalog_add_entry_sub
46 !> Remove a data_catalog_entry object from the data_catalog.
47 generic, public :: delete => catalog_delete_entry_sub
48 !> Find a data_catalog_entry object by searching for its key value.
49 generic, public :: find => catalog_find_key_fn
50 !> Return next data_catalog_entry object in list.
51 generic, public :: next => catalog_find_next_key_fn
52 !> Return data_catalog_entry found at a specific index value within the list.
53 generic, public :: get => catalog_get_entry_at_index_fn
54 !> Print out a detailed summary of data_catalog_entry objects currently stored in data_catalog.
55 generic, public :: print => catalog_print_sub
56 generic, public :: set_proj4 => catalog_set_all_proj4_string_sub
57 generic, public :: set_endyear => catalog_set_all_end_year_sub
58 generic, public :: set_startyear => catalog_set_all_start_year_sub
59
60 end type data_catalog_t
61
62 public :: dat
63
64 !> DAT is a global to hold data catalog entries
66
67contains
68
69!--------------------------------------------------------------------------------------------------
70
71 !> @memberof DATA_CATALOG_T
72 subroutine catalog_set_all_start_year_sub( this, iStartYear )
73
74
75 class(data_catalog_t) :: this
76 integer (c_int), intent(in) :: istartyear
77
78 ! [ LOCALS ]
79 type (data_catalog_entry_t), pointer :: current
80
81 if (associated( this%first ) ) then
82
83 current => this%first
84
85 do while ( associated(current) )
86
87 current%iStartYear = istartyear
88
89 current => current%next
90
91 enddo
92
93 endif
94
95 end subroutine catalog_set_all_start_year_sub
96
97!--------------------------------------------------------------------------------------------------
98
99 !> @memberof DATA_CATALOG_T
100 subroutine catalog_set_all_end_year_sub( this, iEndYear )
101
102
103 class(data_catalog_t) :: this
104 integer (c_int), intent(in) :: iendyear
105
106 ! [ LOCALS ]
107 type (data_catalog_entry_t), pointer :: current
108
109 if (associated( this%first ) ) then
110
111 current => this%first
112
113 do while ( associated(current) )
114
115 current%iEndYear = iendyear
116
117 current => current%next
118
119 enddo
120
121 endif
122
123 end subroutine catalog_set_all_end_year_sub
124
125!--------------------------------------------------------------------------------------------------
126
127 !> @memberof DATA_CATALOG_T
128 subroutine catalog_set_all_proj4_string_sub( this, PROJ4_string )
129
130
131 class(data_catalog_t) :: this
132 character (len=*), intent(in) :: proj4_string
133
134 ! [ LOCALS ]
135 type (data_catalog_entry_t), pointer :: current
136
137 if (associated( this%first ) ) then
138
139 current => this%first
140
141 do while ( associated(current) )
142
143 call current%set_source_PROJ4( proj4_string )
144
145 current => current%next
146
147 enddo
148
149 endif
150
151
152
153 end subroutine catalog_set_all_proj4_string_sub
154
155!--------------------------------------------------------------------------------------------------
156
157 !> @memberof DATA_CATALOG_T
158 subroutine catalog_add_entry_sub( this, key, data )
159
160 class(data_catalog_t) :: this
161 character (len=*), intent(in) :: key
162 type (data_catalog_entry_t), pointer :: data
163
164 if (this%count == 0 ) then
165
166 if (associated (data) ) then
167
168 call data%setkey( key )
169 this%last => data
170 this%first => data
171 data%next => null()
172 data%previous => null()
173 this%count = 1
174
175 endif
176
177 else if( associated(data) ) then
178
179 call data%setkey( key )
180 this%last%next => data
181 data%previous => this%last
182 this%last => data
183 data%next => null()
184
185 this%count = this%count + 1
186
187 endif
188
189
190
191 end subroutine catalog_add_entry_sub
192
193!--------------------------------------------------------------------------------------------------
194
195 !> @memberof DATA_CATALOG_T
196 subroutine catalog_delete_entry_sub( this, key )
197
198 class(data_catalog_t) :: this
199 character (len=*), intent(in) :: key
200
201 ! [ LOCALS ]
202 type (data_catalog_entry_t), pointer :: current => null()
203 type (data_catalog_entry_t), pointer :: previous => null()
204 type (data_catalog_entry_t), pointer :: next => null()
205
206
207 current => catalog_find_key_fn(this, key)
208
209 if ( associated (current) ) then
210
211 previous => current%previous
212 next => current%next
213
214 previous%next => next
215 next%previous => previous
216
217 deallocate( current )
218 current => null()
219
220 this%count = this%count - 1
221
222 endif
223
224 end subroutine catalog_delete_entry_sub
225
226!--------------------------------------------------------------------------------------------------
227
228 !> @memberof DATA_CATALOG_T
229 function catalog_get_entry_at_index_fn(this, index) result(data)
230
231 class(data_catalog_t) :: this
232 integer (c_int), intent(in) :: index
233 type (data_catalog_entry_t), pointer :: data
234
235 ! [ LOCALS ]
236 integer (c_int) :: icount
237
238 data => null()
239 icount = 0
240
241 if ( associated( this%first ) ) then
242
243 data => this%first
244
245 do while ( associated(data) )
246
247 icount = icount + 1
248
249 this%current => data
250
251 if ( icount == index ) exit
252 data => data%next
253
254 enddo
255
256 endif
257
258 end function catalog_get_entry_at_index_fn
259
260!--------------------------------------------------------------------------------------------------
261
262 !> @memberof DATA_CATALOG_T
263 function catalog_find_key_fn( this, key) result( data )
264
265 class(data_catalog_t) :: this
266 character (len=*), intent(in) :: key
267 type (data_catalog_entry_t), pointer :: data
268
269 data => null()
270
271 if ( associated( this%first ) ) then
272
273 data => this%first
274
275 this%current => this%first
276
277 do while ( associated(data) )
278
279 if ( data%sKeyword .strequal. key ) exit
280 data => data%next
281 this%current => data
282
283 enddo
284
285 endif
286
287 end function catalog_find_key_fn
288
289!--------------------------------------------------------------------------------------------------
290 !> @memberof DATA_CATALOG_T
291 function catalog_find_next_key_fn( this, key) result( data )
292
293 class(data_catalog_t) :: this
294 character (len=*), intent(in) :: key
295 type (data_catalog_entry_t), pointer :: data
296
297 data => null()
298
299 if ( associated( this%current ) ) then
300
301 this%current => this%current%next
302 data => this%current
303
304 do while ( associated(data) )
305
306 if ( data%sKeyword .strequal. key ) exit
307
308 data => data%next
309 this%current => data
310
311 enddo
312
313 endif
314
315 end function catalog_find_next_key_fn
316
317!--------------------------------------------------------------------------------------------------
318
319 !> @memberof DATA_CATALOG_T
320 !! @private
321 subroutine catalog_print_sub(this)
322
323 class(data_catalog_t) :: this
324
325 type (data_catalog_entry_t), pointer :: current
326
327 if (associated( this%first ) ) then
328
329 current => this%first
330
331 do while ( associated(current) )
332
333 call logs%write("Catalog key: "//dquote(current%sKeyword), ilinesbefore=1, &
334 ilinesafter=1, iloglevel=log_debug)
335
336 call current%dump_data_structure()
337
338 current => current%next
339
340 enddo
341
342 endif
343
344 end subroutine catalog_print_sub
345
346!--------------------------------------------------------------------------------------------------
347
348end module data_catalog
Defines the DATA_CATALOG_T data type, which contains type-bound procedures to add,...
type(data_catalog_t), public dat
DAT is a global to hold data catalog entries.
type(logfile_t), public logs
Definition logfiles.F90:62