= 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 ==