Skip to content

Commit 03e5b23

Browse files
committed
Finish discussion and example of explicitly quoted strings (and Norway problem) now that some of the internal details needed for this are fixed.
1 parent 57c0d4d commit 03e5b23

File tree

1 file changed

+22
-31
lines changed

1 file changed

+22
-31
lines changed

src/Infrastructure/HConfig/examples/ESMF_HConfigEx.F90

Lines changed: 22 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -969,6 +969,8 @@ program ESMF_HConfigEx
969969
call ESMF_HConfigFileLoad(hconfig, filename="exampleWithTags.yaml", rc=rc)
970970
!EOC
971971
if (rc /= ESMF_SUCCESS) call ESMF_Finalize(endflag=ESMF_END_ABORT)
972+
call ESMF_HConfigLog(hconfig, prefix="WithTagsStart: ", rc=rc)
973+
if (rc /= ESMF_SUCCESS) call ESMF_Finalize(endflag=ESMF_END_ABORT)
972974
!BOE
973975
! The file contains the following YAML:
974976
! \begin{verbatim}
@@ -1132,9 +1134,11 @@ program ESMF_HConfigEx
11321134
! TRUE | FALSE
11331135
! \end{verbatim}
11341136
!
1135-
! \paragraph{More Boolean values and the "Norway problem"}
1136-
! The YAMLCPP backend used by {\tt ESMF\_HConfig} interprets several
1137-
! additional values as boolean for convenience:
1137+
! \paragraph{Additional Boolean values and the "Norway problem"}
1138+
! The YAMLCPP backend used by {\tt ESMF\_HConfig} interprets all of the values
1139+
! recognized as such under \htmladdnormallink{YAML 1.1}
1140+
! {https://yaml.org/type/bool.html} as boolean. This extends the above list with
1141+
! additional options:
11381142
! \begin{verbatim}
11391143
! yes | no
11401144
! Yes | No
@@ -1145,43 +1149,39 @@ program ESMF_HConfigEx
11451149
! On | Off
11461150
! ON | OFF
11471151
! \end{verbatim}
1148-
! The interpretation of value {\tt ON} as a boolean, instead of a literal
1149-
! string, leads to the so-called {\em "Norway problem"}, where the same string
1150-
! is often used as country code instead. The more general problem referred to
1151-
! here is the misinterpretation of a value by YAML.
1152+
! The interpretation of value {\tt NO} as a boolean, instead of a literal
1153+
! string, can be problematic. It leads to the so-called {\em "Norway problem"},
1154+
! because the same string is often used as country code instead. The underlying
1155+
! problem is the misinterpretation of values by YAML.
11521156
!EOE
1153-
#if 1
11541157
tag = ESMF_HConfigGetTag(hconfig, keyString="value_thirteen", rc=rc)
11551158
if (rc /= ESMF_SUCCESS) call ESMF_Finalize(endflag=ESMF_END_ABORT)
11561159
write (msgString, '("value_thirteen HConfig tag: ", A30)') tag
11571160
call ESMF_LogWrite(trim(msgString), ESMF_LOGMSG_INFO, rc=rc)
11581161
if (rc /= ESMF_SUCCESS) call ESMF_Finalize(endflag=ESMF_END_ABORT)
1159-
#endif
11601162
!BOE
11611163
! Strictly speaking this is not a YAML problem, but instead a schema specific
11621164
! issue. Fortunately there are two simple solutions to ensure the correct and
1163-
! intended interpretation of values by the YAML schema used by
1164-
! {\tt ESMF\_HConfig}:
1165+
! intended interpretation of values by {\tt ESMF\_HConfig}:
11651166
!
11661167
! \begin{enumerate}
1167-
! \item Explicit quotation of strings. See for instance the {\em map value}
1168-
! for {\tt value\_fourteen}, which is {\tt "NO"}, and is consequently
1169-
! interpreted as a literal string, identified as {\tt tag:yaml.org,2002:str}.
1170-
!
1171-
! \item Explicit standard tags. This option allows explicit specificaitonof any
1172-
! tag and is discussed below.
1168+
! \item Explicit quotation of strings: See for instance the {\em map value}
1169+
! for {\tt value\_fourteen} in the current example. Using explicit quotes for
1170+
! {\tt "NO"}, the entry is safely interpreted as a literal string, and if
1171+
! queried for its tag, will return {\tt tag:yaml.org,2002:str}.
1172+
!
1173+
! \item Explicit standard tags: This option allows explicit specificaiton of any
1174+
! tag, e.g. the standard short-hand tag {\tt !str} for literal strings. This
1175+
! approach is discussed in more detal below.
11731176
! \end{enumerate}
11741177
!EOE
1175-
#if 0
11761178
tag = ESMF_HConfigGetTag(hconfig, keyString="value_fourteen", rc=rc)
11771179
if (rc /= ESMF_SUCCESS) call ESMF_Finalize(endflag=ESMF_END_ABORT)
11781180
write (msgString, '("value_fourteen HConfig tag: ", A30)') tag
11791181
call ESMF_LogWrite(trim(msgString), ESMF_LOGMSG_INFO, rc=rc)
11801182
if (rc /= ESMF_SUCCESS) call ESMF_Finalize(endflag=ESMF_END_ABORT)
1181-
#endif
11821183

1183-
call ESMF_HConfigAdd(hconfig, addKeyString="value_added", content="'NO'", &
1184-
rc=rc)
1184+
call ESMF_HConfigAdd(hconfig, addKeyString="value_added",content="'NO'",rc=rc)
11851185
if (rc /= ESMF_SUCCESS) call ESMF_Finalize(endflag=ESMF_END_ABORT)
11861186

11871187
tag = ESMF_HConfigGetTag(hconfig, keyString="value_added", rc=rc)
@@ -1190,17 +1190,8 @@ program ESMF_HConfigEx
11901190
call ESMF_LogWrite(trim(msgString), ESMF_LOGMSG_INFO, rc=rc)
11911191
if (rc /= ESMF_SUCCESS) call ESMF_Finalize(endflag=ESMF_END_ABORT)
11921192

1193-
call ESMF_HConfigLog(hconfig, prefix="WithTags: ", rc=rc)
1194-
if (rc /= ESMF_SUCCESS) call ESMF_Finalize(endflag=ESMF_END_ABORT)
1195-
1196-
#if 1
1197-
tag = ESMF_HConfigGetTag(hconfig, keyString="value_fourteen", rc=rc)
1193+
call ESMF_HConfigLog(hconfig, prefix="WithTagsFinish: ", rc=rc)
11981194
if (rc /= ESMF_SUCCESS) call ESMF_Finalize(endflag=ESMF_END_ABORT)
1199-
write (msgString, '("value_fourteen HConfig tag: ", A30)') tag
1200-
call ESMF_LogWrite(trim(msgString), ESMF_LOGMSG_INFO, rc=rc)
1201-
if (rc /= ESMF_SUCCESS) call ESMF_Finalize(endflag=ESMF_END_ABORT)
1202-
#endif
1203-
12041195
!BOE
12051196
! \paragraph{Explicit standard tags}
12061197
! Standard short-hand tags can be specified to change the default resolution.

0 commit comments

Comments
 (0)