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


Ignore:
Timestamp:
2019-02-12T18:38:47+01:00 (18 months ago)
Author:
acc
Comment:

Legend:

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

    v5 v6  
    8484Part 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 
     86'''Version 2 -Tweaked refactoring script to handle indirect addressing (i.e. brackets within array indices)''' 
     87 
    8688'''Step 1''' 
    8789Perl is used in a 'edit in place' mode so the original files will be overwritten. Step 1 is therefore to create copies of the test files: 
     
    101103 INVARS=( ub  vb  wb  un  vn  wn ) 
    102104OUTVARS=( uu  vv  ww  uu  vv  ww ) 
    103   TLEVS=( jtb jtb jtb jtn jtn jtn ) 
     105  TLEVS=( Nnn Nnn Nnn Nii Nii Nii ) 
    104106# 
    105107rm patch.list 
     
    109111 echo "Index: "$f >> patch.list 
    110112 echo "==============================" >> patch.list 
     113 n=0 
    111114 for n in `seq 0 1 $(( ${#INVARS[*]} - 1 ))` 
    112115 do 
    113   perl -0777 -pi -e 's:([+.(,\s\-\/\*\%])'${INVARS[$n]}'\s*\(([^)]*)\):\1'${OUTVARS[$n]}'\(\2,'${TLEVS[$n]}'\):g'  $f 
     116  perl -0777 -pi -e 's@([+.(,\s\-\/\*\%])'${INVARS[$n]}'(\s*)(\(((?:[^()]++|(?3))*)\))@\1'${OUTVARS[$n]}'\2\(\4,'${TLEVS[$n]}'\)@g'  $f 
    114117 done 
    115118 diff -u TEST_FILES_ORG/`basename $f` $f >> patch.list 
     
    151154 
    152155# 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 
     156# opening bracket. This whitespace is preserved in pattern space 2 
     157 
     158# Everything following the opening bracket to matching closing bracket  
     159# is stored in pattern space 3. This requires a recursion and pattern space 4 ends up with 
     160# the interior of the outer brackets 
     161 
     162# The RHS of the substitute command rebuilds the line replacing INVARS with OUTVARS and 
     163# adding a ,TLEVS before the closing bracket 
     164 
     165   perl -0777 -pi -e 's@([+.(,\s\-\/\*\%])'${INVARS[$n]}'(\s*)(\(((?:[^()]++|(?3))*)\))@\1'${OUTVARS[$n]}'\2\(\4,'${TLEVS[$n]}'\)@g'  $f 
    162166 
    163167# End of variable loop 
     
    174178{{{ 
    175179cat TEST_FILES_ORG/contrived_tests.F90 
    176    un(:,:,:)                    ! The simplest test. Should ==> uu(:,:,:,jtn) 
    177   pun(:,:,:)                    ! target preceded by non-whitespace or operator. Should be unchanged 
    178   sbc_fwb(:,:,:)                ! target preceded by non-whitespace or operator. Should be unchanged 
     180  un(:,:,:)                    ! The simplest test. Should ==> uu(:,:,:,jtn) 
    179181   un ( ji   , jj,   : )        ! Check alternative simple case ==> uu ( ji   , jj,   :,jtn) 
    180182   a+ub(:,:,jk)                 ! Check preceeding operators are correctly recognised 
     
    185187 .OR.wn(:,:,jk)                 ! Check preceeding operators are correctly recognised 
    186188    (wn(:,:,jk) + wn(:,:,jk-1)) ! Check preceeding brackets are correctly recognised 
    187    un ( ji+1 ,     &            ! Check entries over multiple lines ae handled 
    188   &     jj, jk - 1 )            ! Check entries over multiple lines ae handled 
    189    un( mi0(ii) , mj0(jj ))      ! Brackets within arguments will break [ does this occur?] 
    190 }}} 
    191  
    192 '''Result of the script on the contrived tests:''' 
    193  
    194 {{{ 
    195 cat TEST_FILES/contrived_tests.F90 
    196    uu(:,:,:,jtn)                    ! The simplest test. Should ==> uu(:,:,:,jtn) 
     189   un ( ji+1 ,     &            ! Check that entries over 
     190  &     jj, jk - 1 )            !                    multiple lines are handled 
     191   wn( mi0(ii) , mj0(jj ))      ! Brackets within arguments may break [ does this occur?] 
    197192  pun(:,:,:)                    ! target preceded by non-whitespace or operator. Should be unchanged 
    198193  sbc_fwb(:,:,:)                ! target preceded by non-whitespace or operator. Should be unchanged 
    199    uu( ji   , jj,   : ,jtn)        ! Check alternative simple case ==> uu ( ji   , jj,   :,jtn) 
    200    a+uu(:,:,jk,jtb)                 ! Check preceeding operators are correctly recognised 
    201    a-vv(:,:,jk,jtb)                 ! Check preceeding operators are correctly recognised 
    202    a*vv(:,:,jk,jtn)                 ! Check preceeding operators are correctly recognised 
    203    a/ww(:,:,jk,jtb)                 ! Check preceeding operators are correctly recognised 
    204    a%ww(:,:,jk,jtn)                 ! Check preceeding operators are correctly recognised 
    205  .OR.ww(:,:,jk,jtn)                 ! Check preceeding operators are correctly recognised 
    206     (ww(:,:,jk,jtn) + ww(:,:,jk-1,jtn)) ! Check preceeding brackets are correctly recognised 
    207    uu( ji+1 ,     &            ! Check entries over multiple lines ae handled 
    208   &     jj, jk - 1 ,jtn)            ! Check entries over multiple lines ae handled 
    209    uu( mi0(ii,jtn) , mj0(jj ))      ! Brackets within arguments will break [ does this occur?] 
     194}}} 
     195 
     196'''Result of the script on the contrived tests:''' 
     197 
     198{{{ 
     199   uu(:,:,:,Nii)                    ! The simplest test. Should ==> uu(:,:,:,jtn) 
     200   uu ( ji   , jj,   : ,Nii)        ! Check alternative simple case ==> uu ( ji   , jj,   :,jtn) 
     201   a+uu(:,:,jk,Nnn)                 ! Check preceeding operators are correctly recognised 
     202   a-vv(:,:,jk,Nnn)                 ! Check preceeding operators are correctly recognised 
     203   a*vv(:,:,jk,Nii)                 ! Check preceeding operators are correctly recognised 
     204   a/ww(:,:,jk,Nnn)                 ! Check preceeding operators are correctly recognised 
     205   a%ww(:,:,jk,Nii)                 ! Check preceeding operators are correctly recognised 
     206 .OR.ww(:,:,jk,Nii)                 ! Check preceeding operators are correctly recognised 
     207    (ww(:,:,jk,Nii) + ww(:,:,jk-1,Nii)) ! Check preceeding brackets are correctly recognised 
     208   uu ( ji+1 ,     &            ! Check that entries over 
     209  &     jj, jk - 1 ,Nii)            !                    multiple lines are handled 
     210   ww( mi0(ii) , mj0(jj ),Nii)      ! Brackets within arguments may break [ does this occur?] 
     211  pun(:,:,:)                    ! target preceded by non-whitespace or operator. Should be unchanged 
     212  sbc_fwb(:,:,:)                ! target preceded by non-whitespace or operator. Should be unchanged 
    210213}}} 
    211214 
     
    213216Index: TEST_FILES/contrived_tests.F90 
    214217============================== 
    215 --- TEST_FILES_ORG/contrived_tests.F90  2019-02-08 14:21:07.000000000 +0000 
    216 +++ TEST_FILES/contrived_tests.F90      2019-02-08 14:39:25.000000000 +0000 
     218--- TEST_FILES_ORG/contrived_tests.F90  2019-02-12 17:16:52.000000000 +0000 
     219+++ TEST_FILES/contrived_tests.F90      2019-02-12 17:17:06.000000000 +0000 
    217220@@ -1,14 +1,14 @@ 
    218221-   un(:,:,:)                    ! The simplest test. Should ==> uu(:,:,:,jtn) 
    219 +   uu(:,:,:,jtn)                    ! The simplest test. Should ==> uu(:,:,:,jtn) 
    220    pun(:,:,:)                    ! target preceded by non-whitespace or operator. Should be unchanged 
    221    sbc_fwb(:,:,:)                ! target preceded by non-whitespace or operator. Should be unchanged 
    222222-   un ( ji   , jj,   : )        ! Check alternative simple case ==> uu ( ji   , jj,   :,jtn) 
    223223-   a+ub(:,:,jk)                 ! Check preceeding operators are correctly recognised 
     
    228228- .OR.wn(:,:,jk)                 ! Check preceeding operators are correctly recognised 
    229229-    (wn(:,:,jk) + wn(:,:,jk-1)) ! Check preceeding brackets are correctly recognised 
    230 -   un ( ji+1 ,     &            ! Check entries over multiple lines ae handled 
    231 -  &     jj, jk - 1 )            ! Check entries over multiple lines ae handled 
    232 -   un( mi0(ii) , mj0(jj ))      ! Brackets within arguments will break [ does this occur?] 
    233 +   uu( ji   , jj,   : ,jtn)        ! Check alternative simple case ==> uu ( ji   , jj,   :,jtn) 
    234 +   a+uu(:,:,jk,jtb)                 ! Check preceeding operators are correctly recognised 
    235 +   a-vv(:,:,jk,jtb)                 ! Check preceeding operators are correctly recognised 
    236 +   a*vv(:,:,jk,jtn)                 ! Check preceeding operators are correctly recognised 
    237 +   a/ww(:,:,jk,jtb)                 ! Check preceeding operators are correctly recognised 
    238 +   a%ww(:,:,jk,jtn)                 ! Check preceeding operators are correctly recognised 
    239 + .OR.ww(:,:,jk,jtn)                 ! Check preceeding operators are correctly recognised 
    240 +    (ww(:,:,jk,jtn) + ww(:,:,jk-1,jtn)) ! Check preceeding brackets are correctly recognised 
    241 +   uu( ji+1 ,     &            ! Check entries over multiple lines ae handled 
    242 +  &     jj, jk - 1 ,jtn)            ! Check entries over multiple lines ae handled 
    243 +   uu( mi0(ii,jtn) , mj0(jj ))      ! Brackets within arguments will break [ does this occur?] 
    244 }}} 
    245  
    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: 
     230-   un ( ji+1 ,     &            ! Check that entries over 
     231-  &     jj, jk - 1 )            !                    multiple lines are handled 
     232-   wn( mi0(ii) , mj0(jj ))      ! Brackets within arguments may break [ does this occur?] 
     233+   uu(:,:,:,Nii)                    ! The simplest test. Should ==> uu(:,:,:,jtn) 
     234+   uu ( ji   , jj,   : ,Nii)        ! Check alternative simple case ==> uu ( ji   , jj,   :,jtn) 
     235+   a+uu(:,:,jk,Nnn)                 ! Check preceeding operators are correctly recognised 
     236+   a-vv(:,:,jk,Nnn)                 ! Check preceeding operators are correctly recognised 
     237+   a*vv(:,:,jk,Nii)                 ! Check preceeding operators are correctly recognised 
     238+   a/ww(:,:,jk,Nnn)                 ! Check preceeding operators are correctly recognised 
     239+   a%ww(:,:,jk,Nii)                 ! Check preceeding operators are correctly recognised 
     240+ .OR.ww(:,:,jk,Nii)                 ! Check preceeding operators are correctly recognised 
     241+    (ww(:,:,jk,Nii) + ww(:,:,jk-1,Nii)) ! Check preceeding brackets are correctly recognised 
     242+   uu ( ji+1 ,     &            ! Check that entries over 
     243+  &     jj, jk - 1 ,Nii)            !                    multiple lines are handled 
     244+   ww( mi0(ii) , mj0(jj ),Nii)      ! Brackets within arguments may break [ does this occur?] 
     245   pun(:,:,:)                    ! target preceded by non-whitespace or operator. Should be unchanged 
     246   sbc_fwb(:,:,:)                ! target preceded by non-whitespace or operator. Should be unchanged 
     247}}} 
     248 
     249So all changes were made correctly and even those entries which were potential pitfalls (pun and sbc_fwb) were correctly ignored. Time to try a real set: 
    247250 
    248251'''The results on the sample set of files (patch.list):''' 
     
    250253{{{#!diff 
    251254Index: TEST_FILES/dynadv_cen2.F90 
    252 ================================================== 
     255============================== 
    253256--- TEST_FILES_ORG/dynadv_cen2.F90      2019-02-08 10:51:12.000000000 +0000 
    254 +++ TEST_FILES/dynadv_cen2.F90  2019-02-08 12:53:14.000000000 +0000 
     257+++ TEST_FILES/dynadv_cen2.F90  2019-02-12 17:17:06.000000000 +0000 
    255258@@ -66,14 +66,14 @@ 
    256259       !                             !==  Horizontal advection  ==! 
     
    259262-         zfu(:,:,jk) = 0.25_wp * e2u(:,:) * e3u_n(:,:,jk) * un(:,:,jk) 
    260263-         zfv(:,:,jk) = 0.25_wp * e1v(:,:) * e3v_n(:,:,jk) * vn(:,:,jk) 
    261 +         zfu(:,:,jk) = 0.25_wp * e2u(:,:) * e3u_n(:,:,jk) * uu(:,:,jk,jtn) 
    262 +         zfv(:,:,jk) = 0.25_wp * e1v(:,:) * e3v_n(:,:,jk) * vv(:,:,jk,jtn) 
     264+         zfu(:,:,jk) = 0.25_wp * e2u(:,:) * e3u_n(:,:,jk) * uu(:,:,jk,Nii) 
     265+         zfv(:,:,jk) = 0.25_wp * e1v(:,:) * e3v_n(:,:,jk) * vv(:,:,jk,Nii) 
    263266          DO jj = 1, jpjm1                 ! horizontal momentum fluxes (at T- and F-point) 
    264267             DO ji = 1, fs_jpim1   ! vector opt. 
     
    267270-               zfu_f(ji  ,jj  ,jk) = ( zfu(ji,jj,jk) + zfu(ji,jj+1,jk) ) * ( vn(ji,jj,jk) + vn(ji+1,jj  ,jk) ) 
    268271-               zfv_t(ji  ,jj+1,jk) = ( zfv(ji,jj,jk) + zfv(ji,jj+1,jk) ) * ( vn(ji,jj,jk) + vn(ji  ,jj+1,jk) ) 
    269 +               zfu_t(ji+1,jj  ,jk) = ( zfu(ji,jj,jk) + zfu(ji+1,jj,jk) ) * ( uu(ji,jj,jk,jtn) + uu(ji+1,jj  ,jk,jtn) ) 
    270 +               zfv_f(ji  ,jj  ,jk) = ( zfv(ji,jj,jk) + zfv(ji+1,jj,jk) ) * ( uu(ji,jj,jk,jtn) + uu(ji  ,jj+1,jk,jtn) ) 
    271 +               zfu_f(ji  ,jj  ,jk) = ( zfu(ji,jj,jk) + zfu(ji,jj+1,jk) ) * ( vv(ji,jj,jk,jtn) + vv(ji+1,jj  ,jk,jtn) ) 
    272 +               zfv_t(ji  ,jj+1,jk) = ( zfv(ji,jj,jk) + zfv(ji,jj+1,jk) ) * ( vv(ji,jj,jk,jtn) + vv(ji  ,jj+1,jk,jtn) ) 
     272+               zfu_t(ji+1,jj  ,jk) = ( zfu(ji,jj,jk) + zfu(ji+1,jj,jk) ) * ( uu(ji,jj,jk,Nii) + uu(ji+1,jj  ,jk,Nii) ) 
     273+               zfv_f(ji  ,jj  ,jk) = ( zfv(ji,jj,jk) + zfv(ji+1,jj,jk) ) * ( uu(ji,jj,jk,Nii) + uu(ji  ,jj+1,jk,Nii) ) 
     274+               zfu_f(ji  ,jj  ,jk) = ( zfu(ji,jj,jk) + zfu(ji,jj+1,jk) ) * ( vv(ji,jj,jk,Nii) + vv(ji+1,jj  ,jk,Nii) ) 
     275+               zfv_t(ji  ,jj+1,jk) = ( zfv(ji,jj,jk) + zfv(ji,jj+1,jk) ) * ( vv(ji,jj,jk,Nii) + vv(ji  ,jj+1,jk,Nii) ) 
    273276             END DO 
    274277          END DO 
     
    280283-               zfu_uw(ji,jj,1) = 0.5_wp * ( e1e2t(ji,jj) * wn(ji,jj,1) + e1e2t(ji+1,jj) * wn(ji+1,jj,1) ) * un(ji,jj,1) 
    281284-               zfv_vw(ji,jj,1) = 0.5_wp * ( e1e2t(ji,jj) * wn(ji,jj,1) + e1e2t(ji,jj+1) * wn(ji,jj+1,1) ) * vn(ji,jj,1) 
    282 +               zfu_uw(ji,jj,1) = 0.5_wp * ( e1e2t(ji,jj) * ww(ji,jj,1,jtn) + e1e2t(ji+1,jj) * ww(ji+1,jj,1,jtn) ) * uu(ji,jj,1,jtn) 
    283 +               zfv_vw(ji,jj,1) = 0.5_wp * ( e1e2t(ji,jj) * ww(ji,jj,1,jtn) + e1e2t(ji,jj+1) * ww(ji,jj+1,1,jtn) ) * vv(ji,jj,1,jtn) 
     285+               zfu_uw(ji,jj,1) = 0.5_wp * ( e1e2t(ji,jj) * ww(ji,jj,1,Nii) + e1e2t(ji+1,jj) * ww(ji+1,jj,1,Nii) ) * uu(ji,jj,1,Nii) 
     286+               zfv_vw(ji,jj,1) = 0.5_wp * ( e1e2t(ji,jj) * ww(ji,jj,1,Nii) + e1e2t(ji,jj+1) * ww(ji,jj+1,1,Nii) ) * vv(ji,jj,1,Nii) 
    284287             END DO 
    285288          END DO 
     
    289292             DO ji = 2, jpi 
    290293-               zfw(ji,jj,jk) = 0.25_wp * e1e2t(ji,jj) * wn(ji,jj,jk) 
    291 +               zfw(ji,jj,jk) = 0.25_wp * e1e2t(ji,jj) * ww(ji,jj,jk,jtn) 
     294+               zfw(ji,jj,jk) = 0.25_wp * e1e2t(ji,jj) * ww(ji,jj,jk,Nii) 
    292295             END DO 
    293296          END DO 
     
    296299-               zfu_uw(ji,jj,jk) = ( zfw(ji,jj,jk) + zfw(ji+1,jj  ,jk) ) * ( un(ji,jj,jk) + un(ji,jj,jk-1) ) 
    297300-               zfv_vw(ji,jj,jk) = ( zfw(ji,jj,jk) + zfw(ji  ,jj+1,jk) ) * ( vn(ji,jj,jk) + vn(ji,jj,jk-1) ) 
    298 +               zfu_uw(ji,jj,jk) = ( zfw(ji,jj,jk) + zfw(ji+1,jj  ,jk) ) * ( uu(ji,jj,jk,jtn) + uu(ji,jj,jk-1,jtn) ) 
    299 +               zfv_vw(ji,jj,jk) = ( zfw(ji,jj,jk) + zfw(ji  ,jj+1,jk) ) * ( vv(ji,jj,jk,jtn) + vv(ji,jj,jk-1,jtn) ) 
     301+               zfu_uw(ji,jj,jk) = ( zfw(ji,jj,jk) + zfw(ji+1,jj  ,jk) ) * ( uu(ji,jj,jk,Nii) + uu(ji,jj,jk-1,Nii) ) 
     302+               zfv_vw(ji,jj,jk) = ( zfw(ji,jj,jk) + zfw(ji  ,jj+1,jk) ) * ( vv(ji,jj,jk,Nii) + vv(ji,jj,jk-1,Nii) ) 
    300303             END DO 
    301304          END DO 
    302305       END DO 
    303306}}} 
    304  
    305307{{{#!diff 
    306308Index: TEST_FILES/dynadv_ubs.F90 
    307309============================== 
    308310--- TEST_FILES_ORG/dynadv_ubs.F90       2019-02-08 10:51:12.000000000 +0000 
    309 +++ TEST_FILES/dynadv_ubs.F90   2019-02-08 12:53:14.000000000 +0000 
     311+++ TEST_FILES/dynadv_ubs.F90   2019-02-12 17:17:06.000000000 +0000 
    310312@@ -101,17 +101,17 @@ 
    311313       DO jk = 1, jpkm1                       !  Laplacian of the velocity  ! 
     
    314316-         zfu(:,:,jk) = e2u(:,:) * e3u_n(:,:,jk) * un(:,:,jk) 
    315317-         zfv(:,:,jk) = e1v(:,:) * e3v_n(:,:,jk) * vn(:,:,jk) 
    316 +         zfu(:,:,jk) = e2u(:,:) * e3u_n(:,:,jk) * uu(:,:,jk,jtn) 
    317 +         zfv(:,:,jk) = e1v(:,:) * e3v_n(:,:,jk) * vv(:,:,jk,jtn) 
     318+         zfu(:,:,jk) = e2u(:,:) * e3u_n(:,:,jk) * uu(:,:,jk,Nii) 
     319+         zfv(:,:,jk) = e1v(:,:) * e3v_n(:,:,jk) * vv(:,:,jk,Nii) 
    318320          ! 
    319321          DO jj = 2, jpjm1                          ! laplacian 
     
    325327-               zlv_vu(ji,jj,jk,1) = ( vb (ji+1,jj  ,jk) - vb (ji  ,jj  ,jk) ) * fmask(ji  ,jj  ,jk)   & 
    326328-                  &               - ( vb (ji  ,jj  ,jk) - vb (ji-1,jj  ,jk) ) * fmask(ji-1,jj  ,jk) 
    327 +               zlu_uu(ji,jj,jk,1) = ( uu(ji+1,jj  ,jk,jtb) - 2.*uu(ji,jj,jk,jtb) + uu(ji-1,jj  ,jk,jtb) ) * umask(ji,jj,jk) 
    328 +               zlv_vv(ji,jj,jk,1) = ( vv(ji  ,jj+1,jk,jtb) - 2.*vv(ji,jj,jk,jtb) + vv(ji  ,jj-1,jk,jtb) ) * vmask(ji,jj,jk) 
    329 +               zlu_uv(ji,jj,jk,1) = ( uu(ji  ,jj+1,jk,jtb) - uu(ji  ,jj  ,jk,jtb) ) * fmask(ji  ,jj  ,jk)   & 
    330 +                  &               - ( uu(ji  ,jj  ,jk,jtb) - uu(ji  ,jj-1,jk,jtb) ) * fmask(ji  ,jj-1,jk) 
    331 +               zlv_vu(ji,jj,jk,1) = ( vv(ji+1,jj  ,jk,jtb) - vv(ji  ,jj  ,jk,jtb) ) * fmask(ji  ,jj  ,jk)   & 
    332 +                  &               - ( vv(ji  ,jj  ,jk,jtb) - vv(ji-1,jj  ,jk,jtb) ) * fmask(ji-1,jj  ,jk) 
     329+               zlu_uu(ji,jj,jk,1) = ( uu (ji+1,jj  ,jk,Nnn) - 2.*uu (ji,jj,jk,Nnn) + uu (ji-1,jj  ,jk,Nnn) ) * umask(ji,jj,jk) 
     330+               zlv_vv(ji,jj,jk,1) = ( vv (ji  ,jj+1,jk,Nnn) - 2.*vv (ji,jj,jk,Nnn) + vv (ji  ,jj-1,jk,Nnn) ) * vmask(ji,jj,jk) 
     331+               zlu_uv(ji,jj,jk,1) = ( uu (ji  ,jj+1,jk,Nnn) - uu (ji  ,jj  ,jk,Nnn) ) * fmask(ji  ,jj  ,jk)   & 
     332+                  &               - ( uu (ji  ,jj  ,jk,Nnn) - uu (ji  ,jj-1,jk,Nnn) ) * fmask(ji  ,jj-1,jk) 
     333+               zlv_vu(ji,jj,jk,1) = ( vv (ji+1,jj  ,jk,Nnn) - vv (ji  ,jj  ,jk,Nnn) ) * fmask(ji  ,jj  ,jk)   & 
     334+                  &               - ( vv (ji  ,jj  ,jk,Nnn) - vv (ji-1,jj  ,jk,Nnn) ) * fmask(ji-1,jj  ,jk) 
    333335                ! 
    334336                zlu_uu(ji,jj,jk,2) = ( zfu(ji+1,jj  ,jk) - 2.*zfu(ji,jj,jk) + zfu(ji-1,jj  ,jk) ) * umask(ji,jj,jk) 
     
    340342-         zfu(:,:,jk) = 0.25_wp * e2u(:,:) * e3u_n(:,:,jk) * un(:,:,jk) 
    341343-         zfv(:,:,jk) = 0.25_wp * e1v(:,:) * e3v_n(:,:,jk) * vn(:,:,jk) 
    342 +         zfu(:,:,jk) = 0.25_wp * e2u(:,:) * e3u_n(:,:,jk) * uu(:,:,jk,jtn) 
    343 +         zfv(:,:,jk) = 0.25_wp * e1v(:,:) * e3v_n(:,:,jk) * vv(:,:,jk,jtn) 
     344+         zfu(:,:,jk) = 0.25_wp * e2u(:,:) * e3u_n(:,:,jk) * uu(:,:,jk,Nii) 
     345+         zfv(:,:,jk) = 0.25_wp * e1v(:,:) * e3v_n(:,:,jk) * vv(:,:,jk,Nii) 
    344346          ! 
    345347          DO jj = 1, jpjm1                          ! horizontal momentum fluxes at T- and F-point 
     
    347349-               zui = ( un(ji,jj,jk) + un(ji+1,jj  ,jk) ) 
    348350-               zvj = ( vn(ji,jj,jk) + vn(ji  ,jj+1,jk) ) 
    349 +               zui = ( uu(ji,jj,jk,jtn) + uu(ji+1,jj  ,jk,jtn) ) 
    350 +               zvj = ( vv(ji,jj,jk,jtn) + vv(ji  ,jj+1,jk,jtn) ) 
     351+               zui = ( uu(ji,jj,jk,Nii) + uu(ji+1,jj  ,jk,Nii) ) 
     352+               zvj = ( vv(ji,jj,jk,Nii) + vv(ji  ,jj+1,jk,Nii) ) 
    351353                ! 
    352354                IF( zui > 0 ) THEN   ;   zl_u = zlu_uu(ji  ,jj,jk,1) 
     
    357359                zfv_f(ji  ,jj  ,jk) = ( zfvi - gamma2 * ( zlv_vu(ji,jj,jk,2) + zlv_vu(ji+1,jj  ,jk,2) )  )   & 
    358360-                  &                * ( un(ji,jj,jk) + un(ji  ,jj+1,jk) - gamma1 * zl_u ) 
    359 +                  &                * ( uu(ji,jj,jk,jtn) + uu(ji  ,jj+1,jk,jtn) - gamma1 * zl_u ) 
     361+                  &                * ( uu(ji,jj,jk,Nii) + uu(ji  ,jj+1,jk,Nii) - gamma1 * zl_u ) 
    360362                zfu_f(ji  ,jj  ,jk) = ( zfuj - gamma2 * ( zlu_uv(ji,jj,jk,2) + zlu_uv(ji  ,jj+1,jk,2) )  )   & 
    361363-                  &                * ( vn(ji,jj,jk) + vn(ji+1,jj  ,jk) - gamma1 * zl_v ) 
    362 +                  &                * ( vv(ji,jj,jk,jtn) + vv(ji+1,jj  ,jk,jtn) - gamma1 * zl_v ) 
     364+                  &                * ( vv(ji,jj,jk,Nii) + vv(ji+1,jj  ,jk,Nii) - gamma1 * zl_v ) 
    363365             END DO 
    364366          END DO 
     
    370372-               zfu_uw(ji,jj,1) = 0.5_wp * ( e1e2t(ji,jj) * wn(ji,jj,1) + e1e2t(ji+1,jj) * wn(ji+1,jj,1) ) * un(ji,jj,1) 
    371373-               zfv_vw(ji,jj,1) = 0.5_wp * ( e1e2t(ji,jj) * wn(ji,jj,1) + e1e2t(ji,jj+1) * wn(ji,jj+1,1) ) * vn(ji,jj,1) 
    372 +               zfu_uw(ji,jj,1) = 0.5_wp * ( e1e2t(ji,jj) * ww(ji,jj,1,jtn) + e1e2t(ji+1,jj) * ww(ji+1,jj,1,jtn) ) * uu(ji,jj,1,jtn) 
    373 +               zfv_vw(ji,jj,1) = 0.5_wp * ( e1e2t(ji,jj) * ww(ji,jj,1,jtn) + e1e2t(ji,jj+1) * ww(ji,jj+1,1,jtn) ) * vv(ji,jj,1,jtn) 
     374+               zfu_uw(ji,jj,1) = 0.5_wp * ( e1e2t(ji,jj) * ww(ji,jj,1,Nii) + e1e2t(ji+1,jj) * ww(ji+1,jj,1,Nii) ) * uu(ji,jj,1,Nii) 
     375+               zfv_vw(ji,jj,1) = 0.5_wp * ( e1e2t(ji,jj) * ww(ji,jj,1,Nii) + e1e2t(ji,jj+1) * ww(ji,jj+1,1,Nii) ) * vv(ji,jj,1,Nii) 
    374376             END DO 
    375377          END DO 
     
    379381             DO ji = 2, jpi 
    380382-               zfw(ji,jj,jk) = 0.25_wp * e1e2t(ji,jj) * wn(ji,jj,jk) 
    381 +               zfw(ji,jj,jk) = 0.25_wp * e1e2t(ji,jj) * ww(ji,jj,jk,jtn) 
     383+               zfw(ji,jj,jk) = 0.25_wp * e1e2t(ji,jj) * ww(ji,jj,jk,Nii) 
    382384             END DO 
    383385          END DO 
     
    386388-               zfu_uw(ji,jj,jk) = ( zfw(ji,jj,jk)+ zfw(ji+1,jj,jk) ) * ( un(ji,jj,jk) + un(ji,jj,jk-1) ) 
    387389-               zfv_vw(ji,jj,jk) = ( zfw(ji,jj,jk)+ zfw(ji,jj+1,jk) ) * ( vn(ji,jj,jk) + vn(ji,jj,jk-1) ) 
    388 +               zfu_uw(ji,jj,jk) = ( zfw(ji,jj,jk)+ zfw(ji+1,jj,jk) ) * ( uu(ji,jj,jk,jtn) + uu(ji,jj,jk-1,jtn) ) 
    389 +               zfv_vw(ji,jj,jk) = ( zfw(ji,jj,jk)+ zfw(ji,jj+1,jk) ) * ( vv(ji,jj,jk,jtn) + vv(ji,jj,jk-1,jtn) ) 
     390+               zfu_uw(ji,jj,jk) = ( zfw(ji,jj,jk)+ zfw(ji+1,jj,jk) ) * ( uu(ji,jj,jk,Nii) + uu(ji,jj,jk-1,Nii) ) 
     391+               zfv_vw(ji,jj,jk) = ( zfw(ji,jj,jk)+ zfw(ji,jj+1,jk) ) * ( vv(ji,jj,jk,Nii) + vv(ji,jj,jk-1,Nii) ) 
    390392             END DO 
    391393          END DO 
    392394       END DO 
    393395}}} 
    394  
    395396{{{#!diff 
    396397Index: TEST_FILES/dynkeg.F90 
    397398============================== 
    398399--- TEST_FILES_ORG/dynkeg.F90   2019-02-08 10:51:12.000000000 +0000 
    399 +++ TEST_FILES/dynkeg.F90       2019-02-08 12:53:14.000000000 +0000 
     400+++ TEST_FILES/dynkeg.F90       2019-02-12 17:17:06.000000000 +0000 
    400401@@ -56,8 +56,8 @@ 
    401402       !!         zhke = 1/2 [ mi-1( un^2 ) + mj-1( vn^2 ) ] 
     
    404405-      !!         zhke = 1/6 [ mi-1(  2 * un^2 + ((un(j+1)+un(j-1))/2)^2  ) 
    405406-      !!                    + mj-1(  2 * vn^2 + ((vn(i+1)+vn(i-1))/2)^2  ) ] 
    406 +      !!         zhke = 1/6 [ mi-1(  2 * un^2 + ((uu(j+1,jtn)+uu(j-1,jtn))/2)^2  ) 
    407 +      !!                    + mj-1(  2 * vn^2 + ((vv(I+1,jtn)+vv(i-1,jtn))/2)^2  ) ] 
     407+      !!         zhke = 1/6 [ mi-1(  2 * un^2 + ((uu(j+1,Nii)+uu(j-1,Nii))/2)^2  ) 
     408+      !!                    + mj-1(  2 * vn^2 + ((vv(i+1,Nii)+vv(i-1,Nii))/2)^2  ) ] 
    408409       !! 
    409410       !!      Take its horizontal gradient and add it to the general momentum 
     
    414415                      ifu   = NINT( idx_bdy(ib_bdy)%flagu(jb,igrd) ) 
    415416-                     un(ii-ifu,ij,jk) = un(ii,ij,jk) * umask(ii,ij,jk) 
    416 +                     uu(ii-ifu,ij,jk,jtn) = uu(ii,ij,jk,jtn) * umask(ii,ij,jk) 
     417+                     uu(ii-ifu,ij,jk,Nii) = uu(ii,ij,jk,Nii) * umask(ii,ij,jk) 
    417418                   END DO 
    418419                END DO 
     
    423424                      ifv   = NINT( idx_bdy(ib_bdy)%flagv(jb,igrd) ) 
    424425-                     vn(ii,ij-ifv,jk) = vn(ii,ij,jk) * vmask(ii,ij,jk) 
    425 +                     vv(ii,ij-ifv,jk,jtn) = vv(ii,ij,jk,jtn) * vmask(ii,ij,jk) 
     426+                     vv(ii,ij-ifv,jk,Nii) = vv(ii,ij,jk,Nii) * vmask(ii,ij,jk) 
    426427                   END DO 
    427428                END DO 
     
    435436-                  zv =    vn(ji  ,jj-1,jk) * vn(ji  ,jj-1,jk)   & 
    436437-                     &  + vn(ji  ,jj  ,jk) * vn(ji  ,jj  ,jk) 
    437 +                  zu =    uu(ji-1,jj  ,jk,jtn) * uu(ji-1,jj  ,jk,jtn)   & 
    438 +                     &  + uu(ji  ,jj  ,jk,jtn) * uu(ji  ,jj  ,jk,jtn) 
    439 +                  zv =    vv(ji  ,jj-1,jk,jtn) * vv(ji  ,jj-1,jk,jtn)   & 
    440 +                     &  + vv(ji  ,jj  ,jk,jtn) * vv(ji  ,jj  ,jk,jtn) 
     438+                  zu =    uu(ji-1,jj  ,jk,Nii) * uu(ji-1,jj  ,jk,Nii)   & 
     439+                     &  + uu(ji  ,jj  ,jk,Nii) * uu(ji  ,jj  ,jk,Nii) 
     440+                  zv =    vv(ji  ,jj-1,jk,Nii) * vv(ji  ,jj-1,jk,Nii)   & 
     441+                     &  + vv(ji  ,jj  ,jk,Nii) * vv(ji  ,jj  ,jk,Nii) 
    441442                   zhke(ji,jj,jk) = 0.25_wp * ( zv + zu ) 
    442443                END DO 
     
    450451-                     &   +     ( un(ji-1,jj-1,jk) + un(ji-1,jj+1,jk) ) * ( un(ji-1,jj-1,jk) + un(ji-1,jj+1,jk) )   & 
    451452-                     &   +     ( un(ji  ,jj-1,jk) + un(ji  ,jj+1,jk) ) * ( un(ji  ,jj-1,jk) + un(ji  ,jj+1,jk) ) 
    452 +                  zu = 8._wp * ( uu(ji-1,jj  ,jk,jtn) * uu(ji-1,jj  ,jk,jtn)    & 
    453 +                     &         + uu(ji  ,jj  ,jk,jtn) * uu(ji  ,jj  ,jk,jtn) )  & 
    454 +                     &   +     ( uu(ji-1,jj-1,jk,jtn) + uu(ji-1,jj+1,jk,jtn) ) * ( uu(ji-1,jj-1,jk,jtn) + uu(ji-1,jj+1,jk,jtn) )   & 
    455 +                     &   +     ( uu(ji  ,jj-1,jk,jtn) + uu(ji  ,jj+1,jk,jtn) ) * ( uu(ji  ,jj-1,jk,jtn) + uu(ji  ,jj+1,jk,jtn) ) 
     453+                  zu = 8._wp * ( uu(ji-1,jj  ,jk,Nii) * uu(ji-1,jj  ,jk,Nii)    & 
     454+                     &         + uu(ji  ,jj  ,jk,Nii) * uu(ji  ,jj  ,jk,Nii) )  & 
     455+                     &   +     ( uu(ji-1,jj-1,jk,Nii) + uu(ji-1,jj+1,jk,Nii) ) * ( uu(ji-1,jj-1,jk,Nii) + uu(ji-1,jj+1,jk,Nii) )   & 
     456+                     &   +     ( uu(ji  ,jj-1,jk,Nii) + uu(ji  ,jj+1,jk,Nii) ) * ( uu(ji  ,jj-1,jk,Nii) + uu(ji  ,jj+1,jk,Nii) ) 
    456457                      ! 
    457458-                  zv = 8._wp * ( vn(ji  ,jj-1,jk) * vn(ji  ,jj-1,jk)    & 
     
    459460-                     &  +      ( vn(ji-1,jj-1,jk) + vn(ji+1,jj-1,jk) ) * ( vn(ji-1,jj-1,jk) + vn(ji+1,jj-1,jk) )   & 
    460461-                     &  +      ( vn(ji-1,jj  ,jk) + vn(ji+1,jj  ,jk) ) * ( vn(ji-1,jj  ,jk) + vn(ji+1,jj  ,jk) ) 
    461 +                  zv = 8._wp * ( vv(ji  ,jj-1,jk,jtn) * vv(ji  ,jj-1,jk,jtn)    & 
    462 +                     &         + vv(ji  ,jj  ,jk,jtn) * vv(ji  ,jj  ,jk,jtn) )  & 
    463 +                     &  +      ( vv(ji-1,jj-1,jk,jtn) + vv(ji+1,jj-1,jk,jtn) ) * ( vv(ji-1,jj-1,jk,jtn) + vv(ji+1,jj-1,jk,jtn) )   & 
    464 +                     &  +      ( vv(ji-1,jj  ,jk,jtn) + vv(ji+1,jj  ,jk,jtn) ) * ( vv(ji-1,jj  ,jk,jtn) + vv(ji+1,jj  ,jk,jtn) ) 
     462+                  zv = 8._wp * ( vv(ji  ,jj-1,jk,Nii) * vv(ji  ,jj-1,jk,Nii)    & 
     463+                     &         + vv(ji  ,jj  ,jk,Nii) * vv(ji  ,jj  ,jk,Nii) )  & 
     464+                     &  +      ( vv(ji-1,jj-1,jk,Nii) + vv(ji+1,jj-1,jk,Nii) ) * ( vv(ji-1,jj-1,jk,Nii) + vv(ji+1,jj-1,jk,Nii) )   & 
     465+                     &  +      ( vv(ji-1,jj  ,jk,Nii) + vv(ji+1,jj  ,jk,Nii) ) * ( vv(ji-1,jj  ,jk,Nii) + vv(ji+1,jj  ,jk,Nii) ) 
    465466                   zhke(ji,jj,jk) = r1_48 * ( zv + zu ) 
    466467                END DO 
     
    472473-         un(:,:,:) = un(:,:,:) * umask(:,:,:) 
    473474-         vn(:,:,:) = vn(:,:,:) * vmask(:,:,:) 
    474 +         uu(:,:,:,jtn) = uu(:,:,:,jtn) * umask(:,:,:) 
    475 +         vv(:,:,:,jtn) = vv(:,:,:,jtn) * vmask(:,:,:) 
     475+         uu(:,:,:,Nii) = uu(:,:,:,Nii) * umask(:,:,:) 
     476+         vv(:,:,:,Nii) = vv(:,:,:,Nii) * vmask(:,:,:) 
    476477       ENDIF 
    477478 
    478479       ! 
    479480}}} 
    480  
    481481{{{#!diff 
    482482Index: TEST_FILES/dynvor.F90 
    483483============================== 
    484484}}} 
    485  
    486485{{{#!diff 
    487486Index: TEST_FILES/flo_oce.F90 
    488487============================== 
    489488--- TEST_FILES_ORG/flo_oce.F90  2019-02-08 10:51:12.000000000 +0000 
    490 +++ TEST_FILES/flo_oce.F90      2019-02-08 12:53:14.000000000 +0000 
     489+++ TEST_FILES/flo_oce.F90      2019-02-12 17:17:06.000000000 +0000 
    491490@@ -59,7 +59,7 @@ 
    492491       !!---------------------------------------------------------------------- 
     
    494493       !!---------------------------------------------------------------------- 
    495494-      ALLOCATE( wb(jpi,jpj,jpk) , nfloat(jpnfl) , nisobfl(jpnfl) , ngrpfl(jpnfl) , & 
    496 +      ALLOCATE( ww(jpi,jpj,jpk,jtb) , nfloat(jpnfl) , nisobfl(jpnfl) , ngrpfl(jpnfl) , & 
     495+      ALLOCATE( ww(jpi,jpj,jpk,Nnn) , nfloat(jpnfl) , nisobfl(jpnfl) , ngrpfl(jpnfl) , & 
    497496          &      flxx(jpnfl)     , flyy(jpnfl)   , flzz(jpnfl)    ,                 & 
    498497          &      tpifl(jpnfl)    , tpjfl(jpnfl)  , tpkfl(jpnfl)   , STAT=flo_oce_alloc ) 
     
    500499}}} 
    501500 
    502 ''' Ok This was wrong. jtb is not what should go into the ALLOCATE statement''' 
     501''' Ok This was wrong.Nnn is not what should go into the ALLOCATE statement''' 
    503502 
    504503{{{#!diff 
     
    506505============================== 
    507506--- TEST_FILES_ORG/floats.F90   2019-02-08 10:51:12.000000000 +0000 
    508 +++ TEST_FILES/floats.F90       2019-02-08 12:53:14.000000000 +0000 
     507+++ TEST_FILES/floats.F90       2019-02-12 17:17:06.000000000 +0000 
    509508@@ -64,7 +64,7 @@ 
    510509       ! 
     
    512511       ! 
    513512-      wb(:,:,:) = wn(:,:,:)         ! Save the old vertical velocity field 
    514 +      ww(:,:,:,jtb) = ww(:,:,:,jtn)         ! Save the old vertical velocity field 
     513+      ww(:,:,:,Nnn) = ww(:,:,:,Nii)         ! Save the old vertical velocity field 
    515514       ! 
    516515       IF( ln_timing )   CALL timing_stop('flo_stp') 
     
    521520       ! 
    522521-      wb(:,:,:) = wn(:,:,:)         ! set wb for computation of floats trajectories at the first time step 
    523 +      ww(:,:,:,jtb) = ww(:,:,:,jtn)         ! set wb for computation of floats trajectories at the first time step 
     522+      ww(:,:,:,Nnn) = ww(:,:,:,Nii)         ! set wb for computation of floats trajectories at the first time step 
    524523       ! 
    525524    END SUBROUTINE flo_init 
    526525 
    527526}}} 
    528  
    529527{{{#!diff 
    530528Index: TEST_FILES/sbcfwb.F90 
    531529============================== 
    532530}}} 
     531 
     532 
     533 
     534 
     535 
     536 
    533537 
    534538So far so good....