= Namelist Integrity checks = Misplaced or mis-spelt variables in configuration namelist files can be a source of frustration when porting configurations used with older releases of NEMO to more modern versions. The code will report these occurrences and stop during start-up; but only one instance is reported each time. Finding them all this way can be a time-consuming business. Part 1 of this page details a simple Python script which can be used to find mis-matches between a configuration namelist and its reference counterpart before attempting to run the model. For most users, this should be sufficient but developers of new features have the added uncertainty of not knowing if the reference namelist correctly contains all the namlist options available in the code. Part 2 of this page suggests further tools which can can construct a 'pseudo reference namelist' by parsing the fortran code base. The actual reference namelist and the 'pseudo' version can then be used with the integrity checker from part 1. By using the integrity checker twice, with the roles of the two namelists swapped, it is possible to confirm that: * The actual reference namelist is compatible with the code base * The actual reference namelist contains examples of all the namelist variables defined in the code base. All the scripts mentioned are attached to this page. == Part 1 Integrity checker == If we assume the following conventions for NEMO namelists: * namelists are started with ''&name_of_namelist'' appearing as the first non-whitespace on a line (and not followed by anything other than an optional comment) * Only one variable is set on each line * namelists are closed with / appearing as the first non-whitespace on a line then the attached [[attachment:nemo_nml_check.py]] script will: * read supplied namelist files * construct lists of namelist blocks and their contents (the latter being a list of lists) * compare the contents lists for matching named blocks to confirm membership * report any mis-matches together with the line number in the configuration namelist By default, the script will compare ''namelist_cfg'' and ''namelist_ref'' from the current directory. Alternative pairs can be named using the ''-c'' and ''-r'' command-line options: {{{ python nemo_nml_check.py --help usage: nemo_nml_check.py [-h] [--cfg [CFGFILE]] [--ref [REFFILE]] Check for consistency between cfg namelists and ref versions e.g. python nemo_nml_check.py --cfg --ref optional arguments: -h, --help show this help message and exit --cfg [CFGFILE], -c [CFGFILE] configuration namelist --ref [REFFILE], -r [REFFILE] reference namelist }}} A typical example of an error found between the default pairing is: {{{ python nemo_nml_check.py No match for: rn_rdt in namdom (at line no. 39 ) }}} and a quick check in the ''namelist_ref'' file will confirm that this is because ''rn_rdt'' has been renamed as ''rn_Dt''. == Part 2 Constructing a pseudo-reference namelist == Parsing the source code to extract information to build a pseudo reference namelist is simpler if we assume adherence to some coding conventions: * The namelist opening declaration: ''namelist / name_of_namelist /'' occurs on one line * The ''name_of_namelist'' string contains only alphanumeric characters and underscores * subsequent continuation lines have a leading ampersand and a trailing ampersand is placed on the preceding line (comments are allowed after the trailing ampersand) With these (seemingly safe) assumptions the attached Perl script: [[attachment:nemo_list_nmls.pl]] can be used to extract namelist templates from the source. For example: {{{ perl nemo_list_nmls.pl OCE/nemogcm.F90 &namctl ln_ctl = sn_cfctl = nn_print = nn_ictls = nn_ictle = nn_isplt = nn_jsplt = nn_jctls = nn_jctle = ln_timing = ln_diacfl = / &namcfg ln_read_cfg = cn_domcfg = ln_closea = ln_write_cfg = cn_domcfg_out = ln_use_jattr = / }}} Combined with a few lines of bash, this can be used to construct a pseudo-namelist_ref: {{{#!bash for f in `find ./OCE -name '*.[Fh]90'` do echo "! "$f >> pseudo_nml_ref perl nemolist_nmls.pl $f >> pseudo_nml_ref done }}} ''(this does assume scanning OCE is sufficient; how about OFF, SAS etc.?)'' == Part 3 Checking reference namelist and source compatibility == The ''pseudo-namelist_ref'' produced this way should contain all the variables that can be set via namelists (at least for the 'blue ocean'). Treating the actual ''namelist_ref'' as a configuration namelist and checking its integrity against the pseudo version should confirm the validity of everything in the reference namelist, Surprisingly quite a few variables are flagged (admittedly, this version may not have been entirely up-to-date [to be redone]): {{{ python nemo_nml_check.py -c namelist_ref -r pseudo_nml_ref No match for: sn_wnum in namsbc_wave (at line no. 567 ) No match for: sn_tauwoc in namsbc_wave (at line no. 568 ) No match for: sn_tauwx in namsbc_wave (at line no. 569 ) No match for: sn_tauwy in namsbc_wave (at line no. 570 ) No match for: sn_tide_cnames(1) in nam_tide (at line no. 664 ) No match for: ln_zinterp in nambdy_dta (at line no. 701 ) No match for: ln_full_vel in nambdy_dta (at line no. 703 ) No match for: bn_a_i in nambdy_dta (at line no. 718 ) No match for: bn_h_i in nambdy_dta (at line no. 719 ) No match for: bn_h_s in nambdy_dta (at line no. 720 ) No match for: bn_t_i in nambdy_dta (at line no. 721 ) No match for: bn_t_s in nambdy_dta (at line no. 722 ) No match for: bn_tsu in nambdy_dta (at line no. 723 ) No match for: bn_s_i in nambdy_dta (at line no. 724 ) No match for: bn_aip in nambdy_dta (at line no. 726 ) No match for: bn_hip in nambdy_dta (at line no. 727 ) No match for: rn_ice_tem in nambdy_dta (at line no. 729 ) No match for: rn_ice_sal in nambdy_dta (at line no. 730 ) No match for: rn_ice_age in nambdy_dta (at line no. 731 ) No match for: rn_ice_apnd in nambdy_dta (at line no. 732 ) No match for: rn_ice_hpnd in nambdy_dta (at line no. 733 ) No match for: ln_zinterp in nambdy_dta (at line no. 701 ) No match for: ln_full_vel in nambdy_dta (at line no. 703 ) No match for: cn_dir in nambdy_dta (at line no. 706 ) No match for: bn_ssh in nambdy_dta (at line no. 710 ) No match for: bn_u2d in nambdy_dta (at line no. 711 ) No match for: bn_v2d in nambdy_dta (at line no. 712 ) No match for: bn_u3d in nambdy_dta (at line no. 713 ) No match for: bn_v3d in nambdy_dta (at line no. 714 ) No match for: bn_tem in nambdy_dta (at line no. 715 ) No match for: bn_sal in nambdy_dta (at line no. 716 ) No match for: bn_a_i in nambdy_dta (at line no. 718 ) No match for: bn_h_i in nambdy_dta (at line no. 719 ) No match for: bn_h_s in nambdy_dta (at line no. 720 ) No match for: bn_t_i in nambdy_dta (at line no. 721 ) No match for: bn_t_s in nambdy_dta (at line no. 722 ) No match for: bn_tsu in nambdy_dta (at line no. 723 ) No match for: bn_s_i in nambdy_dta (at line no. 724 ) No match for: bn_aip in nambdy_dta (at line no. 726 ) No match for: bn_hip in nambdy_dta (at line no. 727 ) No match for: sn_cfctl%l_glochk in namctl (at line no. 1396 ) No match for: sn_cfctl%l_allon in namctl (at line no. 1397 ) No match for: sn_cfctl%l_config in namctl (at line no. 1398 ) No match for: sn_cfctl%l_runstat in namctl (at line no. 1399 ) No match for: sn_cfctl%l_trcstat in namctl (at line no. 1400 ) No match for: sn_cfctl%l_oceout in namctl (at line no. 1401 ) No match for: sn_cfctl%l_layout in namctl (at line no. 1402 ) No match for: sn_cfctl%l_prtctl in namctl (at line no. 1403 ) No match for: sn_cfctl%l_prttrc in namctl (at line no. 1404 ) No match for: sn_cfctl%l_oasout in namctl (at line no. 1405 ) No match for: sn_cfctl%procmin in namctl (at line no. 1406 ) No match for: sn_cfctl%procmax in namctl (at line no. 1407 ) No match for: sn_cfctl%procincr in namctl (at line no. 1408 ) No match for: sn_cfctl%ptimincr in namctl (at line no. 1409 ) }}} It is probably the case that the structure variables flagged (sn_*) are false positives. This is because only the structure name is declared in the namelist but individual members of the structure may be (and are) set the ''namelist_ref''. Nonetheless, there are quite a few normal variables to investigate. Even if these issues are resolved in more up-to-date revisions, this does illustrate the potential usefulness of this tool. Secondly, reversing the roles of the input namelists allows a check on whether or not all the available namelist variables have a default setting in ''namelist_ref'': {{{ python nemo_nml_check.py -r namelist_ref -c pseudo_nml_ref No match for: ln_time_average_weight in namberg (at line no. 26 ) No match for: ln_sto_ldf in namsto (at line no. 67 ) No match for: rn_ldf_std in namsto (at line no. 68 ) No match for: rn_ldf_tcor in namsto (at line no. 69 ) No match for: ln_sto_hpg in namsto (at line no. 70 ) No match for: rn_hpg_std in namsto (at line no. 71 ) No match for: rn_hpg_tcor in namsto (at line no. 72 ) No match for: ln_sto_pstar in namsto (at line no. 73 ) No match for: rn_pstar_std in namsto (at line no. 74 ) No match for: rn_pstar_tcor in namsto (at line no. 75 ) No match for: nn_pstar_flt in namsto (at line no. 76 ) No match for: nn_pstar_ord in namsto (at line no. 77 ) No match for: ln_sto_trd in namsto (at line no. 78 ) No match for: rn_trd_std in namsto (at line no. 79 ) No match for: rn_trd_tcor in namsto (at line no. 80 ) No match for: ln_sto_trc in namsto (at line no. 89 ) No match for: nn_sto_trc in namsto (at line no. 90 ) No match for: rn_trc_stdxy in namsto (at line no. 91 ) No match for: rn_trc_stdz in namsto (at line no. 92 ) No match for: rn_trc_tcor in namsto (at line no. 93 ) No match for: nn_trc_ord in namsto (at line no. 94 ) No match for: nn_trc_flt in namsto (at line no. 95 ) No match for: rn_trc_lim in namsto (at line no. 96 ) No match for: sn_cfctl in namctl (at line no. 223 ) No match for: ln_rnf_icb in namsbc_rnf (at line no. 575 ) No match for: sn_i_rnf in namsbc_rnf (at line no. 578 ) No match for: sn_tide_cnames in nam_tide (at line no. 1125 ) }}} The same caveats apply but there are a few issues warranting further investigation. [TBD: repeat process for SI3, TOP, PISCES etc.]