New URL for NEMO forge!   http://forge.nemo-ocean.eu

Since March 2022 along with NEMO 4.2 release, the code development moved to a self-hosted GitLab.
This present forge is now archived and remained online for history.
2019WP/KERNEL-02_Storkey_Coward_IMMERSE_first_steps (diff) – NEMO

Changes between Version 4 and Version 5 of 2019WP/KERNEL-02_Storkey_Coward_IMMERSE_first_steps


Ignore:
Timestamp:
2019-02-08T16:35:51+01:00 (5 years ago)
Author:
acc
Comment:

--

Legend:

Unmodified
Added
Removed
Modified
  • 2019WP/KERNEL-02_Storkey_Coward_IMMERSE_first_steps

    v4 v5  
    8282[=#preview] 
    8383 
    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 several to illustrate the successes and caveats for the method.  
     84Part 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.  
    8585 
    8686'''Step 1''' 
     
    109109 echo "Index: "$f >> patch.list 
    110110 echo "==============================" >> patch.list 
    111  n=0 
    112111 for n in `seq 0 1 $(( ${#INVARS[*]} - 1 ))` 
    113112 do 
     
    117116 echo "}}}" >> patch.list 
    118117done 
     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 
    119170}}} 
    120171 
     
    193244}}} 
    194245 
    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: 
     246So 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: 
    196247 
    197248'''The results on the sample set of files (patch.list):'''