@@ -18,11 +18,15 @@ module state_structure_mod
18
18
! > The add_domain() call adds a 'domain' to the state. This may be a component in
19
19
! > the case of XCESM or another coupled model.
20
20
! >
21
- ! > There are three ways to add a domain (these are overloaded as add_domain):
21
+ ! > There are four ways to add a domain (these are overloaded as add_domain):
22
22
! > * add_domain_blank. This takes model size as an argument.
23
23
! >
24
24
! > * add_domain_from_file. This takes a netcdf file and a list of variables
25
25
! >
26
+ ! > * add_domain_from_state_type. This takes a netcdf file and a state_var_type,
27
+ ! > which includes nvars, netcdf variable names, qtys (kinds),
28
+ ! > clamp_values (optional), and updates
29
+ ! >
26
30
! > * add_domain_from_spec. This makes a skeleton structure for a domain. Dimensions
27
31
! > for each variable must be added using add_dimension_to_variable(). This is intended
28
32
! > to be used to create netcdf output for models like bgrid_solo that are spun up.
@@ -68,6 +72,8 @@ module state_structure_mod
68
72
69
73
use sort_mod, only : index_sort
70
74
75
+ use default_model_mod, only : state_var_type
76
+
71
77
use netcdf
72
78
73
79
implicit none
@@ -240,8 +246,8 @@ module state_structure_mod
240
246
character (len= 256 ) :: info_file = ' NULL'
241
247
242
248
! string identifying the manner in which the domain was created
243
- ! 'blank', 'file', or 'spec'
244
- character (len= 6 ) :: method = ' none'
249
+ ! 'blank', 'file', 'state_type', or 'spec'
250
+ character (len= 11 ) :: method = ' none'
245
251
246
252
end type domain_type
247
253
@@ -281,6 +287,7 @@ module state_structure_mod
281
287
module procedure add_domain_blank
282
288
module procedure add_domain_from_file
283
289
module procedure add_domain_from_spec
290
+ module procedure add_domain_from_state_type
284
291
end interface
285
292
286
293
interface get_index_start
@@ -313,8 +320,6 @@ module state_structure_mod
313
320
! > into the state_strucutre.
314
321
! >
315
322
! > Returns a dom_id that can be used to harvest information of a particular domain
316
- ! >
317
- ! > Does this need to be a function or a subroutine?
318
323
319
324
320
325
function add_domain_from_file (info_file , num_vars , var_names , kind_list , clamp_vals , update_list ) result(dom_id)
@@ -365,6 +370,58 @@ function add_domain_from_file(info_file, num_vars, var_names, kind_list, clamp_v
365
370
end function add_domain_from_file
366
371
367
372
373
+ !- ------------------------------------------------------------------------------
374
+ ! > Given an info_file, reads in a state_var_type including nvars, netcdf
375
+ ! > variable names, qtys (kinds), clamp values (optional), and updates into the
376
+ ! > state_structure
377
+ ! >
378
+ ! > Returns a dom_id that can be used to harvest information of a particular domain
379
+
380
+
381
+ function add_domain_from_state_type (info_file , vars ) result(dom_id)
382
+
383
+ character (len=* ), intent (in ) :: info_file
384
+ type (state_var_type), intent (in ) :: vars
385
+ integer :: dom_id
386
+
387
+ integer :: ivar
388
+
389
+ ! add to domains
390
+ call assert_below_max_num_domains(' add_domain_from_state_type' )
391
+ state% num_domains = state% num_domains + 1
392
+ ! >@todo dom_id should be a handle.
393
+ dom_id = state% num_domains
394
+
395
+ ! save information about the information file
396
+ state% domain(dom_id)% info_file = info_file
397
+ state% domain(dom_id)% method = ' state_type'
398
+
399
+ ! set number of variables in this domain
400
+ state% domain(dom_id)% num_variables = vars% nvars
401
+
402
+ ! load up the variable names
403
+ allocate (state% domain(dom_id)% variable(vars% nvars))
404
+
405
+ do ivar = 1 , vars% nvars
406
+ state% domain(dom_id)% variable(ivar)% varname = vars% netcdf_var_names(ivar)
407
+ enddo
408
+
409
+ ! load up variable id's and sizes
410
+ call load_state_variable_info(state% domain(dom_id),dom_id)
411
+
412
+ ! load up the domain unique dimension info
413
+ call load_unique_dim_info(dom_id)
414
+
415
+ ! load up any cf-conventions if they exist
416
+ call load_common_cf_conventions(state% domain(dom_id))
417
+
418
+ call set_dart_kinds(dom_id, vars% nvars, vars% qtys)
419
+ if (allocated (vars% clamp_values)) call set_clamping(dom_id, vars% nvars, vars% clamp_values)
420
+ call set_update_list(dom_id, vars% nvars, vars% updates)
421
+
422
+ end function add_domain_from_state_type
423
+
424
+
368
425
!- ------------------------------------------------------------------------------
369
426
! > Defines a skeleton structure for the state structure. Dimension can be
370
427
! > added to variables with add_dimension_to_variable.
0 commit comments