49 character(len=:),
allocatable :: paramname
50 character(len=:),
dimension(:),
allocatable :: keys
51 character(len=:),
dimension(:),
allocatable :: values
60 character(len=:),
allocatable :: name
61 character(len=:),
dimension(:),
allocatable :: keys
62 character(len=:),
dimension(:),
allocatable :: values
71 character(len=:),
allocatable :: name
72 type (
fmvar_t),
allocatable :: variables(:)
80 character(len=:),
allocatable :: name
98 character(len=*),
intent(in),
optional :: filename
103 if (.not.
present(filename))
then
110 allocate(fmtable%types(ntypes))
122 type(
fmtype_t),
intent(inout) :: fmType
123 integer,
intent(in) :: yfid
124 integer,
dimension(1) :: key_ids
125 character(len=256) :: key_name
126 character(len=256) :: key_value
131 allocate(fmtype%models(nmodels))
134 call get_block_ids(yfid,
"modlist", fmtype%models(:)%id, fmtype%id)
136 if (
get_nkeys(yfid, fmtype%id).ne.1)
then
137 call mpp_error(fatal,
"fm_yaml_mod: A single `field_type` key is expected")
144 if (trim(key_name).ne.
"field_type")
then
145 call mpp_error(fatal,
"fm_yaml_mod: A single `field_type` key is expected")
148 fmtype%name = trim(key_value)
157 type(
fmmodel_t),
intent(inout) :: fmModel
158 integer,
intent(in) :: yfid
159 integer,
dimension(1) :: key_ids
160 character(len=256) :: key_name
161 character(len=256) :: key_value
166 allocate(fmmodel%variables(nvars))
169 call get_block_ids(yfid,
"varlist", fmmodel%variables(:)%id, fmmodel%id)
171 if (
get_nkeys(yfid, fmmodel%id).ne.1)
then
172 call mpp_error(fatal,
"fm_yaml_mod: A single `model_type` key is expected")
179 if (trim(key_name).ne.
"model_type")
then
180 call mpp_error(fatal,
"fm_yaml_mod: A single `model_type` key is expected")
183 fmmodel%name = trim(key_value)
192 type(
fmvar_t),
intent(inout) :: fmVar
193 integer,
intent(in) :: yfid
195 integer,
allocatable :: key_ids(:)
196 character(len=256) :: key_name
197 character(len=256) :: key_value
202 character(:),
allocatable :: attr_method_keys(:)
203 character(:),
allocatable :: attr_method_values(:)
209 nattrs =
size(attr_method_keys)
212 allocate(key_ids(nkeys))
215 maxln = len(attr_method_keys)
216 maxlv = len(attr_method_values)
223 if (trim(key_name) .eq.
"variable")
then
224 if (i_name .ne. -1)
then
225 call mpp_error(fatal,
"fm_yaml_mod: A variable can have only one `variable` key")
228 fmvar%name = trim(key_value)
231 maxln = max(maxln, len_trim(key_name))
232 maxlv = max(maxlv, len_trim(key_value))
236 if (i_name .eq. -1)
then
237 call mpp_error(fatal,
"fm_yaml_mod: Every variable must have a `variable` key")
241 nmethods = nkeys - 1 + nattrs
243 allocate(
character(len=maxln)::fmVar%keys(nmethods))
244 allocate(
character(len=maxlv)::fmVar%values(nmethods))
248 if (i.eq.i_name) cycle
252 fmvar%keys(j) = trim(key_name)
253 fmvar%values(j) = trim(key_value)
259 fmvar%keys(j:) = attr_method_keys
260 fmvar%values(j:) = attr_method_values
266 type(
fmvar_t),
intent(inout) :: fmVar
267 integer,
intent(in) :: yfid
268 character(:),
allocatable,
intent(out) :: method_keys(:)
269 character(:),
allocatable,
intent(out) :: method_values(:)
272 integer,
allocatable :: key_ids(:)
273 character(len=256) :: key_name
274 character(len=256) :: key_value
279 integer,
allocatable :: name_key_id(:)
283 allocate(fmvar%attributes(nattrs))
284 allocate(name_key_id(nattrs))
294 associate(fmattr => fmvar%attributes(i))
296 fmattr%paramname = trim(key_value)
299 allocate(key_ids(nkeys))
309 if (trim(key_name) .eq.
"value")
then
310 if (name_key_id(i) .ne. -1)
then
311 call mpp_error(fatal,
"fm_yaml_mod: A variable attribute block can only have one `value` key")
314 maxln_m = max(maxln_m, len(fmattr%paramname))
315 maxlv_m = max(maxlv_m, len_trim(key_value))
317 name_key_id(i) = key_ids(j)
319 maxln_a = max(maxln_a, len_trim(key_name))
320 maxlv_a = max(maxlv_a, len_trim(key_value))
324 if (name_key_id(i) .eq. -1)
then
325 call mpp_error(fatal,
"fm_yaml_mod: Every variable attribute must have a `value` key")
328 allocate(
character(len=maxln_a)::fmAttr%keys(nkeys - 1))
329 allocate(
character(len=maxlv_a)::fmAttr%values(nkeys - 1))
333 if (key_ids(j).eq.name_key_id(i)) cycle
337 fmattr%keys(k) = trim(key_name)
338 fmattr%values(k) = trim(key_value)
347 allocate(
character(len=maxln_m)::method_keys(nattrs))
348 allocate(
character(len=maxlv_m)::method_values(nattrs))
351 method_keys(i) = fmvar%attributes(i)%paramname
357 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 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.