-
Notifications
You must be signed in to change notification settings - Fork 128
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Parser: Add ability to read in generic blocks #1519
Open
uramirez8707
wants to merge
2
commits into
NOAA-GFDL:main
Choose a base branch
from
uramirez8707:generic_parser
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,111 @@ | ||
program generic_blocks | ||
#ifdef use_yaml | ||
use fms_mod, only: fms_init, fms_end | ||
use mpp_mod, only: mpp_error, FATAL | ||
use yaml_parser_mod | ||
|
||
implicit none | ||
|
||
integer :: yaml_id !< Id of the yaml file | ||
integer, allocatable :: field_table_ids(:) !< The Ids of the field table entries | ||
integer, allocatable :: modlist_ids(:) !< The ids of the mods entries | ||
integer, allocatable :: varlist_ids(:) !< The ids of the variable entries | ||
integer, allocatable :: block_ids(:) !< The ids of the block entries | ||
integer, allocatable :: misc_block_ids(:) !< The ids of the misc block entries | ||
integer, allocatable :: key_ids(:) !< The ids of the keys | ||
character(len=50) :: variable_name !< The variable name | ||
character(len=50) :: model_type_name !< The model type | ||
character(len=50) :: block_name !< The name of the block | ||
character(len=50) :: key_name !< The name of the key | ||
character(len=50) :: key_value !< The value of the key | ||
character(len=50) :: varnames(2) !< The expected names of the variables | ||
character(len=50) :: blocknames1(1) !< The expected names of the blocks for the first variable | ||
character(len=50) :: blocknames2(2) !< The expected names of the blocks for the second variable | ||
character(len=50) :: keys(5) !< The expected names of the keys | ||
character(len=50) :: values(5) !< The expected names values of they keys | ||
integer :: key_count !< To keep track of the expected answers | ||
|
||
logical :: correct_answer !< True if the answer is correct | ||
integer :: i, j, k, l, m, n !< For do loops | ||
|
||
call fms_init() | ||
varnames(1) = "sphum" | ||
varnames(2) = "soa" | ||
|
||
blocknames1(1) = "profile_type" | ||
blocknames2(1) = "chem_param" | ||
blocknames2(2) = "profile_type" | ||
|
||
key_count = 0 | ||
keys(1) = "value"; values(1) = "fixed" | ||
keys(2) = "surface_value"; values(2) = "3.0e-06" | ||
keys(3) = "value"; values(3) = "aerosol" | ||
keys(4) = "value"; values(4) = "fixed" | ||
keys(5) = "surface_value"; values(5) = "1.0e-32" | ||
|
||
yaml_id = open_and_parse_file("sample.yaml") | ||
allocate(field_table_ids(get_num_blocks(yaml_id, "field_table"))) | ||
call get_block_ids(yaml_id, "field_table", field_table_ids) | ||
do i = 1, size(field_table_ids) | ||
allocate(modlist_ids(get_num_blocks(yaml_id, "modlist", parent_block_id=field_table_ids(i)))) | ||
call get_block_ids(yaml_id, "modlist", modlist_ids, field_table_ids(i)) | ||
|
||
do j = 1, size(modlist_ids) | ||
call get_value_from_key(yaml_id, modlist_ids(j), "model_type", model_type_name) | ||
print *, "Modlist::", trim(model_type_name) | ||
if (trim(model_type_name) .ne. "atmos_mod") & | ||
call mpp_error(FATAL, "Modlist is not the expected result") | ||
|
||
allocate(varlist_ids(get_num_blocks(yaml_id, "varlist", parent_block_id=modlist_ids(j)))) | ||
call get_block_ids(yaml_id, "varlist", varlist_ids, modlist_ids(j)) | ||
|
||
do k = 1, size(varlist_ids) | ||
call get_value_from_key(yaml_id, varlist_ids(k), "variable", variable_name) | ||
print *, "Variable::", trim(variable_name) | ||
if (trim(variable_name) .ne. varnames(k)) & | ||
call mpp_error(FATAL, "Variable is not the expected result") | ||
|
||
allocate(block_ids(get_num_unique_blocks(yaml_id, parent_block_id=varlist_ids(k)))) | ||
call get_unique_block_ids(yaml_id, block_ids, parent_block_id=varlist_ids(k)) | ||
do l = 1, size(block_ids) | ||
call get_block_name(yaml_id, block_ids(l), block_name) | ||
print *, "Block_name::", trim(block_name) | ||
|
||
if (k == 1) then | ||
correct_answer = trim(blocknames1(l)) .eq. trim(block_name) | ||
else | ||
correct_answer = trim(blocknames2(l)) .eq. trim(block_name) | ||
endif | ||
|
||
if (.not. correct_answer) call mpp_error(FATAL, "blockname is not the expected result") | ||
allocate(misc_block_ids(get_num_blocks(yaml_id, block_name, parent_block_id=varlist_ids(k)))) | ||
call get_block_ids(yaml_id, block_name, misc_block_ids, parent_block_id=varlist_ids(k)) | ||
do m = 1, size(misc_block_ids) | ||
allocate(key_ids(get_nkeys(yaml_id, misc_block_ids(m)))) | ||
call get_key_ids(yaml_id, misc_block_ids(m), key_ids) | ||
do n = 1, size(key_ids) | ||
key_count = key_count + 1 | ||
call get_key_name(yaml_id, key_ids(n), key_name) | ||
call get_key_value(yaml_id, key_ids(n), key_value) | ||
print *, "KEY:", trim(key_name), " VALUE:", trim(key_value) | ||
|
||
if (trim(key_name) .ne. trim(keys(key_count))) & | ||
call mpp_error(FATAL, "The key is not correct") | ||
|
||
if (trim(key_value) .ne. trim(values(key_count))) & | ||
call mpp_error(FATAL, "The value is not correct") | ||
enddo | ||
deallocate(key_ids) | ||
enddo | ||
deallocate(misc_block_ids) | ||
enddo | ||
deallocate(block_ids) | ||
print *, "---------" | ||
enddo | ||
deallocate(varlist_ids) | ||
enddo | ||
deallocate(modlist_ids) | ||
enddo | ||
call fms_end() | ||
#endif | ||
end program generic_blocks |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@J-Lentz @GFDL-Eric
This is relevant code that will be used to read the new field_table yaml format.
get_num_unique_blocks
is going to be used to get the number of unique blocks for each variable. For the example below, it will get 1 forsphum
and 2 forsoa
.get_unique_block_ids
will be used to get an id for each of the blocks and that can be used to get the block name (i.eprofile_type
forsphum
, andchem_param
andprofile_type
forsoa
) and from there, it can be read as normal ...