Changes between Version 4 and Version 5 of 2019WP/KERNEL-02_Storkey_Coward_IMMERSE_first_steps
- Timestamp:
- 2019-02-08T16:35:51+01:00 (5 years ago)
Legend:
- Unmodified
- Added
- Removed
- Modified
-
2019WP/KERNEL-02_Storkey_Coward_IMMERSE_first_steps
v4 v5 82 82 [=#preview] 83 83 84 Part of the reorganisation for RK3 requires the refactoring of arrays such as un, ub into a single, 4 dimensional array with a time-level dimension. It is expected that much of the work required here can be automated to the extent that it is feasible to re-apply these changes after the annual merge. Below is a working example of how this might be achieved. Perl is used to carry out the pattern matching and substitution because of its ability to match patterns extending over several lines. A random subset of source files are used in this example and se veralto illustrate the successes and caveats for the method.84 Part of the reorganisation for RK3 requires the refactoring of arrays such as un, ub into a single, 4 dimensional array with a time-level dimension. It is expected that much of the work required here can be automated to the extent that it is feasible to re-apply these changes after the annual merge. Below is a working example of how this might be achieved. Perl is used to carry out the pattern matching and substitution because of its ability to match patterns extending over several lines. A random subset of source files are used in this example and serve to illustrate the successes and caveats for the method. 85 85 86 86 '''Step 1''' … … 109 109 echo "Index: "$f >> patch.list 110 110 echo "==============================" >> patch.list 111 n=0112 111 for n in `seq 0 1 $(( ${#INVARS[*]} - 1 ))` 113 112 do … … 117 116 echo "}}}" >> patch.list 118 117 done 118 }}} 119 120 '''The refactoring script explained''' 121 122 {{{ 123 # Some bash arrays to list the old names, new names and associated time-level index. 124 # The choice of names here is not meant to reflect a desired choice. Note all three arrays 125 # must have the same number of entries 126 127 INVARS=( ub vb wb un vn wn ) 128 OUTVARS=( uu vv ww uu vv ww ) 129 TLEVS=( jtb jtb jtb jtn jtn jtn ) 130 # 131 # Lines referring to patch.list are just generating some output for this Wiki page. 132 # They can be ignored for the purposes of explaining the script 133 134 # Loop over all files in test directory 135 136 for f in TEST_FILES/*.F90 137 do 138 139 # Loop over each input variable name 140 141 for n in `seq 0 1 $(( ${#INVARS[*]} - 1 ))` 142 do 143 144 # The perl command: 145 146 # -0777 -pi are the options that force replace in place operation. 147 # Could elect to redirect to new files 148 149 # The substitute command matches the INVAR string preceded by any of: +.(,whitespace-/*% 150 # Any match here goes into the first pattern space (\1) 151 152 # The INVAR string can have any amount of whitespace (including none) between it and an 153 # opening bracket. This whitespace is not preserved (but it could be, TBD) 154 155 # Everything following the opening bracket to (but not including) the next closing bracket 156 # is stored in pattern space 2 157 158 # The RHS of the substitute command rebuilds the line replacing INVAR with OUTVAR and 159 # adding a ,TLEV before the closing bracket 160 161 perl -0777 -pi -e 's:([+.(,\s\-\/\*\%])'${INVARS[$n]}'\s*\(([^)]*)\):\1'${OUTVARS[$n]}'\(\2,'${TLEVS[$n]}'\):g' $f 162 163 # End of variable loop 164 165 done 166 167 # End of file loop 168 169 done 119 170 }}} 120 171 … … 193 244 }}} 194 245 195 So all changes were made correctly (apart from the last which was expected). Also those entries which were potential pitfalls (pun and abc_fwb) were correctly ignored. Time to try a real set:246 So all changes were made correctly (apart from the last which was expected). Also those entries which were potential pitfalls (pun and sbc_fwb) were correctly ignored. Time to try a real set: 196 247 197 248 '''The results on the sample set of files (patch.list):'''