50 character(len=:),
allocatable :: paramname
51 character(len=:),
dimension(:),
allocatable :: keys
52 character(len=:),
dimension(:),
allocatable :: values
61 character(len=:),
allocatable :: name
62 character(len=:),
dimension(:),
allocatable :: keys
63 character(len=:),
dimension(:),
allocatable :: values
72 character(len=:),
allocatable :: name
73 type (
fmvar_t),
allocatable :: variables(:)
81 character(len=:),
allocatable :: name
99 character(len=*),
intent(in),
optional :: filename
104 if (.not.
present(filename))
then
111 allocate(fmtable%types(ntypes))
123 type(
fmtype_t),
intent(inout) :: fmType
124 integer,
intent(in) :: yfid
125 integer,
dimension(1) :: key_ids
126 character(len=256) :: key_name
127 character(len=256) :: key_value
132 allocate(fmtype%models(nmodels))
135 call get_block_ids(yfid,
"modlist", fmtype%models(:)%id, fmtype%id)
137 if (
get_nkeys(yfid, fmtype%id).ne.1)
then
138 call mpp_error(fatal,
"fm_yaml_mod: A single `field_type` key is expected")
145 if (trim(key_name).ne.
"field_type")
then
146 call mpp_error(fatal,
"fm_yaml_mod: A single `field_type` key is expected")
149 fmtype%name = trim(key_value)
158 type(
fmmodel_t),
intent(inout) :: fmModel
159 integer,
intent(in) :: yfid
160 integer,
dimension(1) :: key_ids
161 character(len=256) :: key_name
162 character(len=256) :: key_value
167 allocate(fmmodel%variables(nvars))
170 call get_block_ids(yfid,
"varlist", fmmodel%variables(:)%id, fmmodel%id)
172 if (
get_nkeys(yfid, fmmodel%id).ne.1)
then
173 call mpp_error(fatal,
"fm_yaml_mod: A single `model_type` key is expected")
180 if (trim(key_name).ne.
"model_type")
then
181 call mpp_error(fatal,
"fm_yaml_mod: A single `model_type` key is expected")
184 fmmodel%name = trim(key_value)
193 type(
fmvar_t),
intent(inout) :: fmVar
194 integer,
intent(in) :: yfid
196 integer,
allocatable :: key_ids(:)
197 character(len=256) :: key_name
198 character(len=256) :: key_value
203 character(:),
allocatable :: attr_method_keys(:)
204 character(:),
allocatable :: attr_method_values(:)
210 nattrs =
size(attr_method_keys)
213 allocate(key_ids(nkeys))
216 maxln = len(attr_method_keys)
217 maxlv = len(attr_method_values)
224 if (trim(key_name) .eq.
"variable")
then
225 if (i_name .ne. -1)
then
226 call mpp_error(fatal,
"fm_yaml_mod: A variable can have only one `variable` key")
229 fmvar%name = trim(key_value)
232 maxln = max(maxln, len_trim(key_name))
233 maxlv = max(maxlv, len_trim(key_value))
237 if (i_name .eq. -1)
then
238 call mpp_error(fatal,
"fm_yaml_mod: Every variable must have a `variable` key")
242 nmethods = nkeys - 1 + nattrs
244 allocate(
character(len=maxln)::fmVar%keys(nmethods))
245 allocate(
character(len=maxlv)::fmVar%values(nmethods))
249 if (i.eq.i_name) cycle
253 fmvar%keys(j) = trim(key_name)
254 fmvar%values(j) = trim(key_value)
260 fmvar%keys(j:) = attr_method_keys
261 fmvar%values(j:) = attr_method_values
267 type(
fmvar_t),
intent(inout) :: fmVar
268 integer,
intent(in) :: yfid
269 character(:),
allocatable,
intent(out) :: method_keys(:)
270 character(:),
allocatable,
intent(out) :: method_values(:)
273 integer,
allocatable :: key_ids(:)
274 character(len=256) :: key_name
275 character(len=256) :: key_value
280 integer,
allocatable :: name_key_id(:)
284 allocate(fmvar%attributes(nattrs))
285 allocate(name_key_id(nattrs))
295 associate(fmattr => fmvar%attributes(i))
297 fmattr%paramname = trim(key_value)
300 allocate(key_ids(nkeys))
310 if (trim(key_name) .eq.
"value")
then
311 if (name_key_id(i) .ne. -1)
then
312 call mpp_error(fatal,
"fm_yaml_mod: A variable attribute block can only have one `value` key")
315 maxln_m = max(maxln_m, len(fmattr%paramname))
316 maxlv_m = max(maxlv_m, len_trim(key_value))
318 name_key_id(i) = key_ids(j)
320 maxln_a = max(maxln_a, len_trim(key_name))
321 maxlv_a = max(maxlv_a, len_trim(key_value))
325 if (name_key_id(i) .eq. -1)
then
326 call mpp_error(fatal,
"fm_yaml_mod: Every variable attribute must have a `value` key")
329 allocate(
character(len=maxln_a)::fmAttr%keys(nkeys - 1))
330 allocate(
character(len=maxlv_a)::fmAttr%values(nkeys - 1))
334 if (key_ids(j).eq.name_key_id(i)) cycle
338 fmattr%keys(k) = trim(key_name)
339 fmattr%values(k) = trim(key_value)
348 allocate(
character(len=maxln_m)::method_keys(nattrs))
349 allocate(
character(len=maxlv_m)::method_values(nattrs))
352 method_keys(i) = fmvar%attributes(i)%paramname
358 end module fm_yaml_mod
subroutine build_fmtype(fmType, yfid)
Populates an fmType, which is assumed to already have its id parameter set.
subroutine fmvar_read_attrs(fmVar, yfid, method_keys, method_values)
Reads the attribute blocks attached to a variable and populates the associated fmAttr structures....
subroutine build_fmmodel(fmModel, yfid)
Populates an fmModel, which is assumed to already have its id parameter set.
subroutine, public build_fmtable(fmTable, filename)
Subroutine to populate an fmTable by reading a yaml file, given an optional filename.
subroutine build_fmvar(fmVar, yfid)
Populates an fmVar and creates any associated fmAttrs.
This type represents a subparameter block for a given variable parameter. This type contains the name...
This type represents the entries for a given model, e.g. land, ocean, atmosphere. This type contains ...
This type contains the field types within a field table.
This type represents the entries for a specific field type, e.g. a tracer. This type contains the nam...
This type represents the entries for a given variable, e.g. dust. This type contains the name of the ...
integer function, public get_nkeys(file_id, block_id)
Gets the number of key-value pairs in a block.
subroutine, public get_key_name(file_id, key_id, key_name)
Gets the key from a file id.
integer function, public open_and_parse_file(filename)
Opens and parses a yaml file.
subroutine, public get_key_ids(file_id, block_id, key_ids)
Gets the ids of the key-value pairs in a block.
subroutine, public get_block_ids(file_id, block_name, block_ids, parent_block_id)
Gets the the ids of the blocks with block_name in the yaml file If parent_block_id is present,...
integer function, public get_num_unique_blocks(file_id, parent_block_id)
Gets the number of unique blocks.
integer function, public get_num_blocks(file_id, block_name, parent_block_id)
Determines the number of blocks with block_name in the yaml file If parent_block_id is present,...
subroutine, public get_unique_block_ids(file_id, block_ids, parent_block_id)
Gets the ids of the unique block ids.
subroutine, public get_block_name(file_id, block_id, block_name)
Gets the block name form the block id.
subroutine, public get_key_value(file_id, key_id, key_value)
Gets the value from a file id.