1 | Simple style rules for namelists |
---|
2 | -------------------------------- |
---|
3 | |
---|
4 | NEMO reference namelists should adhere to the following simple style rules: |
---|
5 | |
---|
6 | 1. Comments outside a namelist block start with !! in column 1 |
---|
7 | 2. Each namelist block starts with 3 lines of the form: |
---|
8 | |
---|
9 | !----------------------------------------------------------------------- |
---|
10 | &namblockname ! short description of block |
---|
11 | !----------------------------------------------------------------------- |
---|
12 | |
---|
13 | with all ! and & 's starting in column 1 |
---|
14 | 3. The closing / for each namelist block is in column 1 |
---|
15 | 4. Comments within namelist blocks never start with !- . Use ! followed |
---|
16 | by space or != etc. |
---|
17 | |
---|
18 | These conventions make it possible to construct empty configuration namelists. |
---|
19 | For example, a namelist_cfg template can be produced from namelist_ref with |
---|
20 | the following grep command; e.g.: |
---|
21 | |
---|
22 | grep -E '^!-|^&|^/' namelist_ref > namelist_cfg.template |
---|
23 | |
---|
24 | head namelist_cfg.template |
---|
25 | |
---|
26 | !----------------------------------------------------------------------- |
---|
27 | &namrun ! parameters of the run |
---|
28 | !----------------------------------------------------------------------- |
---|
29 | / |
---|
30 | !----------------------------------------------------------------------- |
---|
31 | &namcfg ! parameters of the configuration |
---|
32 | !----------------------------------------------------------------------- |
---|
33 | / |
---|
34 | !----------------------------------------------------------------------- |
---|
35 | &namdom ! time and space domain |
---|
36 | !----------------------------------------------------------------------- |
---|
37 | / |
---|
38 | . |
---|
39 | . |
---|
40 | |
---|
41 | If all configuration namelists are produced and maintained using this |
---|
42 | strategy then standard, side-by-side comaparators, such as vimdiff or xxdiff, |
---|
43 | can be used to compare and transfer lines from the reference namelist to a |
---|
44 | configuration namelist when setting up a new configuration. |
---|
45 | |
---|
46 | Tips and tricks |
---|
47 | --------------- |
---|
48 | |
---|
49 | 1. The following bash function is useful when checking which namelist blocks |
---|
50 | are in active use in a configuration namelist: |
---|
51 | |
---|
52 | function list_used_nl(){ grep -n -E '^&|^/' "$1" | sed -e 's/:/ /' \ |
---|
53 | | awk ' BEGIN { x = 0 } \ |
---|
54 | {if ( NR % 2 == 0 && $1 - x > 2 ) printf("%3d %s\n", $1 - x , n) ; \ |
---|
55 | else x = $1; n = $2}' \ |
---|
56 | | sort -k 2;} |
---|
57 | |
---|
58 | which (assuming the namelist adheres to the conventions) will list the number |
---|
59 | of entries in each non-empty namelist block. The list is sorted on the block |
---|
60 | name to ease comparisons. For example: |
---|
61 | |
---|
62 | list_used_nl ORCA2_LIM3_PISCES/EXP00/namelist_cfg |
---|
63 | |
---|
64 | 1 &nambbc |
---|
65 | 5 &nambbl |
---|
66 | 30 &namberg |
---|
67 | 10 &namcfg |
---|
68 | 4 &namctl |
---|
69 | 3 &namdom |
---|
70 | 1 &namdrg |
---|
71 | 5 &namdyn_adv |
---|
72 | 1 &namdyn_hpg |
---|
73 | 22 &namdyn_ldf |
---|
74 | 1 &namdyn_spg |
---|
75 | 5 &namdyn_vor |
---|
76 | 3 &nameos |
---|
77 | 1 &namhsb |
---|
78 | 4 &namrun |
---|
79 | 1 &namsbc |
---|
80 | 1 &namsbc_blk |
---|
81 | 3 &namtra_adv |
---|
82 | 28 &namtra_ldf |
---|
83 | 10 &namtra_ldfeiv |
---|
84 | 25 &namzdf |
---|
85 | 3 &namzdf_iwm |
---|
86 | |
---|
87 | 2. vimdiff can give garish colours in some terminals. Usually this is because |
---|
88 | vim assumes, incorrectly, that the terminal only supports 8 colours. Try forcing |
---|
89 | 256 colours with: |
---|
90 | |
---|
91 | :set t_Co=256 |
---|
92 | |
---|
93 | to produce more pastel shades (add this to ~/.vimrc if successful). |
---|
94 | |
---|
95 | 3. Switching between vsplit panes in vim is a multi-key sequence. The tool is |
---|
96 | much easier to use if the sequence is mapped to a spare key. Here I use the |
---|
97 | § and ± key on my Mac keyboard (add to ~/.vimrc): |
---|
98 | |
---|
99 | map § ^Wl |
---|
100 | map ± ^Wh |
---|
101 | |
---|
102 | 4. With easy switching between panes, constructing namelists in vimdiff just |
---|
103 | requires the following commands in addition to normal editing: |
---|
104 | |
---|
105 | ]c - Go to next block of the diff |
---|
106 | dp - Push version of the block under cursor into the other pane |
---|
107 | do - Pull version of the block under cursor from the other pane |
---|
108 | |
---|
109 | |
---|