-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Bug fix: Now fix parsing of categories more than 2 indent levels prior
It was discovered that this YAML markup was not being parsed properly in qfyaml 0.3.2: operations: transport: passive_species: CH3ITracer: long_name: Methyl_iodide mol_wt_in_g: 142.0 lifetime_in_s: 4.32e5 default_bkg_conc_in_vv: 1.0e-20 wet_deposition: activate: true The wet_deposition category was given the wrong indentation depth, and as such, operations:wet_deposition:activate was parsed as FALSE but should have been TRUE. This issue is now fixed and we will release this as qfyaml 0.3.0. NOTE: QFYAML works best if a constant indentation (e.g. always 2 spaces for each level) is used. You can use an editor such as Emacs to format your YAML input files accordingly. Also updated the test programs to test this behavior. Signed-off-by: Bob Yantosca <[email protected]>
- Loading branch information
Showing
5 changed files
with
129 additions
and
31 deletions.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -40,6 +40,7 @@ MODULE QFYAML_Mod | |
PUBLIC :: QFYAML_CleanUp | ||
PUBLIC :: QFYAML_Get | ||
PUBLIC :: QFYAML_Check | ||
PUBLIC :: QFYAML_FindDepth | ||
PUBLIC :: QFYAML_FindNextHigher | ||
PUBLIC :: QFYAML_Init | ||
PUBLIC :: QFYAML_Merge | ||
|
@@ -741,7 +742,8 @@ SUBROUTINE Parse_Line( yml, yml_anchored, set_by, & | |
! SAVEd variables | ||
LOGICAL, SAVE :: is_list_var = .FALSE. | ||
INTEGER, SAVE :: last_pos = 0 | ||
INTEGER, SAVE :: cat_pos(20) = 0 | ||
INTEGER, SAVE :: indent = 0 | ||
INTEGER, SAVE :: cat_pos(QFYAML_MaxStack) = 0 | ||
INTEGER, SAVE :: cat_index = 0 | ||
CHARACTER(LEN=QFYAML_NamLen), SAVE :: cat_stack(QFYAML_MaxStack) = "" | ||
|
||
|
@@ -805,23 +807,27 @@ SUBROUTINE Parse_Line( yml, yml_anchored, set_by, & | |
! If this category starts further along the line than the last | ||
! category, then increment index and add its position to the stack. | ||
IF ( pos > last_pos ) THEN | ||
indent = last_pos - pos | ||
cat_index = cat_index + 1 | ||
cat_pos(cat_index) = pos | ||
ENDIF | ||
|
||
! If this category starts earlier along the line than the last | ||
! category, then decrement index and add its position to the stack. | ||
! last category, then this | ||
! NOTE: This algorithm will work best if we assume a constant | ||
! indentation level. Best to use an editor such as emacs | ||
! to enforce a consistent indentation throughout the file. | ||
IF ( pos < last_pos ) THEN | ||
cat_index = cat_index - 1 | ||
indent = last_pos - pos | ||
cat_index = cat_index - ( indent / 2 ) | ||
cat_pos(cat_index) = pos | ||
ENDIF | ||
|
||
! If the index is negative or the category begins at the first | ||
! character of the line, then set index to 1 and store its | ||
! starting position in the first element of the stack. | ||
IF ( cat_index <= 0 .or. pos == 1 ) THEN | ||
cat_index = 1 | ||
cat_index = 1 | ||
cat_pos(cat_index) = pos | ||
ENDIF | ||
|
||
|
@@ -927,9 +933,9 @@ SUBROUTINE Parse_Line( yml, yml_anchored, set_by, & | |
category = cat_stack(C) | ||
IF ( C > 1 ) THEN | ||
DO CC = C-1, 1, -1 | ||
category = TRIM( cat_stack(CC) ) // & | ||
QFYAML_Category_Separator // & | ||
TRIM( category ) | ||
category = TRIM( cat_stack(CC) ) // & | ||
QFYAML_Category_Separator // & | ||
TRIM( category ) | ||
ENDDO | ||
ENDIF | ||
EXIT | ||
|
@@ -941,16 +947,15 @@ SUBROUTINE Parse_Line( yml, yml_anchored, set_by, & | |
category = cat_stack( MAX( C-1, 1 ) ) | ||
IF ( C-1 > 1 ) THEN | ||
DO CC = C-2, 1, -1 | ||
category = TRIM( cat_stack(CC) ) // & | ||
QFYAML_Category_Separator // & | ||
TRIM( category ) | ||
category = TRIM( cat_stack(CC) ) // & | ||
QFYAML_Category_Separator // & | ||
TRIM( category ) | ||
ENDDO | ||
ENDIF | ||
EXIT | ||
ENDIF | ||
ENDDO | ||
|
||
|
||
! Test if the variable is a YAML anchor | ||
IF ( var_name == "<<" ) THEN | ||
|
||
|
@@ -1498,6 +1503,51 @@ END SUBROUTINE QFYAML_check | |
! | ||
! !IROUTINE: QFYAML_FindNextHigher | ||
! | ||
! !DESCRIPTION: For a given category or variable name, returns its depth | ||
! (i.e. indentation level). This is equal to the number of separator | ||
! strings. | ||
!\\ | ||
!\\ | ||
! !INTERFACE: | ||
! | ||
FUNCTION QFYAML_FindDepth( name ) RESULT( depth ) | ||
! | ||
! !INPUT PARAMETERS: | ||
! | ||
CHARACTER(LEN=*), INTENT(IN) :: name | ||
! | ||
! RETURN VALUE: | ||
! | ||
INTEGER :: depth | ||
!EOP | ||
!------------------------------------------------------------------------------ | ||
!BOC | ||
! | ||
! !LOCAL VARIABLES: | ||
! | ||
INTEGER :: ix, c | ||
|
||
! Keep searching for all category separators | ||
! until there aren't any more. | ||
depth = 1 | ||
c = LEN_TRIM( name ) | ||
DO | ||
ix = INDEX( name(1:c), QFYAML_Category_Separator, back=.TRUE. ) | ||
IF ( ix <= 1 ) EXIT | ||
depth = depth + 1 | ||
c = ix - 1 | ||
ENDDO | ||
|
||
END FUNCTION QFYAML_FindDepth | ||
!EOC | ||
!------------------------------------------------------------------------------ | ||
! QFYAML: Bob Yantosca | [email protected] | Apr 2020 | ||
! Based on existing package https://github.com/jannisteunissen/config_fortran | ||
!------------------------------------------------------------------------------ | ||
!BOP | ||
! | ||
! !IROUTINE: QFYAML_FindNextHigher | ||
! | ||
! !DESCRIPTION: Finds variables that are one category depth higher than | ||
! a given target string (trg_str). Returns the number of variables that | ||
! match this criteria (n_matches), as well as the variables themselves | ||
|
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