Index: /NEMO/branches/2019/dev_r11879_ENHANCE-05_SimonM-Harmonic_Analysis/src/OCE/DIA/diamlr.F90
===================================================================
--- /NEMO/branches/2019/dev_r11879_ENHANCE-05_SimonM-Harmonic_Analysis/src/OCE/DIA/diamlr.F90	(revision 11960)
+++ /NEMO/branches/2019/dev_r11879_ENHANCE-05_SimonM-Harmonic_Analysis/src/OCE/DIA/diamlr.F90	(revision 11961)
@@ -63,8 +63,8 @@
       TYPE(xios_field)                            ::   slxhdl_fld
       TYPE(xios_file)                             ::   slxhdl_fil
-      LOGICAL                                     ::   slxatt_enabled
-      CHARACTER(LEN=256)                          ::   slxatt_expr
-      CHARACTER(LEN=32)                           ::   slxatt_name1,   slxatt_name2
-      CHARACTER(LEN=32)                           ::   slxatt_gridref, slxatt_fieldref
+      LOGICAL                                     ::   llxatt_enabled
+      CHARACTER(LEN=256)                          ::   clxatt_expr
+      CHARACTER(LEN=32)                           ::   clxatt_name1,   clxatt_name2
+      CHARACTER(LEN=32)                           ::   clxatt_gridref, clxatt_fieldref
       INTEGER, PARAMETER                          ::   jpscanmax = 999
       INTEGER                                     ::   ireg, ifld
@@ -155,9 +155,9 @@
                ! Retrieve pre-configured value of "enabled" attribute and
                ! regressor expression
-               CALL xios_get_attr  ( slxhdl_regs(ireg+1), enabled=slxatt_enabled, expr=slxatt_expr )
+               CALL xios_get_attr  ( slxhdl_regs(ireg+1), enabled=llxatt_enabled, expr=clxatt_expr )
                ! If enabled, keep handle in list of active regressors; also
                ! substitute placeholders for tidal frequencies, phases, and
                ! nodal corrections in regressor expressions
-               IF ( slxatt_enabled ) THEN
+               IF ( llxatt_enabled ) THEN
 
                   ! Substitution of placeholders for tidal-constituent
@@ -171,20 +171,23 @@
                      ztide_phase = MOD( ztide_u(jn) +  ztide_v(jn) - adatrj * 86400.0_wp * ztide_omega(jn), 2.0_wp * rpi )
                      clrepl = "__TDE_"//TRIM( Wave(jn)%cname_tide )//"_omega__"
-                     DO WHILE ( INDEX( slxatt_expr, TRIM( clrepl ) ) > 0 )
+                     DO WHILE ( INDEX( clxatt_expr, TRIM( clrepl ) ) > 0 )
                         WRITE (clfloat, '(e25.18)') ztide_omega(jn)
-                        jl = INDEX( slxatt_expr, TRIM( clrepl ) )
-                        slxatt_expr = slxatt_expr(1:jl - 1)//clfloat//slxatt_expr(jl + LEN( TRIM( clrepl ) ):LEN( TRIM( slxatt_expr ) ))
+                        jl = INDEX( clxatt_expr, TRIM( clrepl ) )
+                        clxatt_expr = clxatt_expr(1:jl - 1)//clfloat//   &
+                           &          clxatt_expr(jl + LEN( TRIM( clrepl ) ):LEN( TRIM( clxatt_expr ) ))
                      END DO
                      clrepl = "__TDE_"//TRIM( Wave(jn)%cname_tide )//"_phase__"
-                     DO WHILE ( INDEX( slxatt_expr, TRIM( clrepl ) ) > 0 )
+                     DO WHILE ( INDEX( clxatt_expr, TRIM( clrepl ) ) > 0 )
                         WRITE (clfloat, '(e25.18)') ztide_phase
-                        jl = INDEX( slxatt_expr, TRIM( clrepl ) )
-                        slxatt_expr = slxatt_expr(1:jl - 1)//clfloat//slxatt_expr(jl + LEN( TRIM( clrepl ) ):LEN( TRIM( slxatt_expr ) ))
+                        jl = INDEX( clxatt_expr, TRIM( clrepl ) )
+                        clxatt_expr = clxatt_expr(1:jl - 1)//clfloat//   &
+                           &          clxatt_expr(jl + LEN( TRIM( clrepl ) ):LEN( TRIM( clxatt_expr ) ))
                      END DO
                      clrepl = "__TDE_"//TRIM( Wave(jn)%cname_tide )//"_amplitude__"
-                     DO WHILE (INDEX( slxatt_expr, TRIM( clrepl ) ) > 0 )
+                     DO WHILE (INDEX( clxatt_expr, TRIM( clrepl ) ) > 0 )
                         WRITE (clfloat, '(e25.18)') ztide_f(jn)
-                        jl = INDEX( slxatt_expr, TRIM( clrepl ) )
-                        slxatt_expr = slxatt_expr(1:jl - 1)//clfloat//slxatt_expr(jl + LEN( TRIM( clrepl ) ):LEN( TRIM( slxatt_expr ) ))
+                        jl = INDEX( clxatt_expr, TRIM( clrepl ) )
+                        clxatt_expr = clxatt_expr(1:jl - 1)//clfloat//   &
+                           &          clxatt_expr(jl + LEN( TRIM( clrepl ) ):LEN( TRIM( clxatt_expr ) ))
                      END DO
                   END DO
@@ -193,5 +196,5 @@
                   ! with field id to enable id string retrieval from stored handle
                   ! below; also re-set expression with possible substitutions
-                  CALL xios_set_attr  ( slxhdl_regs(ireg+1), name="diamlr_r"//cl3i, expr=TRIM( slxatt_expr ) )
+                  CALL xios_set_attr  ( slxhdl_regs(ireg+1), name="diamlr_r"//cl3i, expr=TRIM( clxatt_expr ) )
 
                   ireg = ireg + 1   ! Accept regressor in list of active regressors
@@ -205,7 +208,7 @@
                CALL xios_get_handle( "diamlr_f"//cl3i, slxhdl_flds(ifld+1) )
                ! Retrieve pre-configured value of "enabled" attribute
-               CALL xios_get_attr  ( slxhdl_flds(ifld+1), enabled=slxatt_enabled )
+               CALL xios_get_attr  ( slxhdl_flds(ifld+1), enabled=llxatt_enabled )
                ! If enabled, keep handle in list of fields selected for analysis
-               IF ( slxatt_enabled ) THEN
+               IF ( llxatt_enabled ) THEN
                   
                   ! Set name attribute (and overwrite possible pre-configured name)
@@ -238,30 +241,30 @@
             !      3-dimensional versions are simply obtained via grid
             !      transformations from the 2-dimensional version.
-            CALL xios_get_attr  ( slxhdl_regs( jm ), name=slxatt_name1, expr=slxatt_expr, enabled=slxatt_enabled )
-            CALL xios_add_child ( slxhdl_fldgrp, slxhdl_fld, TRIM( slxatt_name1 )//"_2D" )
-            CALL xios_set_attr  ( slxhdl_fld, expr=TRIM( slxatt_expr ), grid_ref="diamlr_grid_2D",     &
-               &                  field_ref="diamlr_time", enabled=slxatt_enabled )
-            CALL xios_add_child ( slxhdl_fldgrp, slxhdl_fld, TRIM( slxatt_name1 )//"_3D")
+            CALL xios_get_attr  ( slxhdl_regs( jm ), name=clxatt_name1, expr=clxatt_expr, enabled=llxatt_enabled )
+            CALL xios_add_child ( slxhdl_fldgrp, slxhdl_fld, TRIM( clxatt_name1 )//"_2D" )
+            CALL xios_set_attr  ( slxhdl_fld, expr=TRIM( clxatt_expr ), grid_ref="diamlr_grid_2D",     &
+               &                  field_ref="diamlr_time", enabled=llxatt_enabled )
+            CALL xios_add_child ( slxhdl_fldgrp, slxhdl_fld, TRIM( clxatt_name1 )//"_3D")
             CALL xios_set_attr  ( slxhdl_fld, expr="this", grid_ref="diamlr_grid_2D_to_3D",            &
-               &                  field_ref=TRIM( slxatt_name1 )//"_2D", enabled=slxatt_enabled)
+               &                  field_ref=TRIM( clxatt_name1 )//"_2D", enabled=llxatt_enabled)
             CALL xios_set_attr  ( slxhdl_regs(jm), expr="this", grid_ref="diamlr_grid_2D_to_scalar",   &
-               &                  field_ref=TRIM( slxatt_name1 )//"_2D", enabled=slxatt_enabled)
+               &                  field_ref=TRIM( clxatt_name1 )//"_2D", enabled=llxatt_enabled)
 
             !  ii) set up definitions for the output of scalar products with
             !      itself and with other active regressors
-            CALL xios_get_attr  ( slxhdl_regs(jm), name=slxatt_name1 )
+            CALL xios_get_attr  ( slxhdl_regs(jm), name=clxatt_name1 )
             CALL xios_get_handle( "diamlr_file_scalar", slxhdl_fil)
             DO jn = 1, jm
                ! Field for product between regressors
-               CALL xios_get_attr  ( slxhdl_regs(jn), name=slxatt_name2, enabled=slxatt_enabled )
-               CALL xios_add_child ( slxhdl_fldgrp, slxhdl_fld, TRIM( slxatt_name1 )//"."//TRIM( slxatt_name2 ) )
+               CALL xios_get_attr  ( slxhdl_regs(jn), name=clxatt_name2, enabled=llxatt_enabled )
+               CALL xios_add_child ( slxhdl_fldgrp, slxhdl_fld, TRIM( clxatt_name1 )//"."//TRIM( clxatt_name2 ) )
                ! Set appropriate name attribute to avoid the possibility of
                ! using an inappropriate inherited name attribute as the variable
                ! name in the output file
-               CALL xios_set_attr  ( slxhdl_fld, name=TRIM( slxatt_name1 )//"."//TRIM( slxatt_name2 ),      &
-                  &                  grid_ref="diamlr_grid_scalar", expr="this * "//TRIM( slxatt_name2 ),   &
-                  &                  field_ref=TRIM( slxatt_name1 ), enabled=slxatt_enabled, operation="accumulate")
+               CALL xios_set_attr  ( slxhdl_fld, name=TRIM( clxatt_name1 )//"."//TRIM( clxatt_name2 ),      &
+                  &                  grid_ref="diamlr_grid_scalar", expr="this * "//TRIM( clxatt_name2 ),   &
+                  &                  field_ref=TRIM( clxatt_name1 ), enabled=llxatt_enabled, operation="accumulate")
                ! Add regressor-product field to output file
-               CALL xios_add_child ( slxhdl_fil, slxhdl_fld, TRIM( slxatt_name1 )//"."//TRIM( slxatt_name2 ) )
+               CALL xios_add_child ( slxhdl_fil, slxhdl_fld, TRIM( clxatt_name1 )//"."//TRIM( clxatt_name2 ) )
             END DO
 
@@ -269,20 +272,20 @@
             !      fields selected for analysis
             DO jn = 1, ifld
-               CALL xios_get_attr( slxhdl_flds(jn), name=slxatt_name2, grid_ref=slxatt_gridref, field_ref=slxatt_fieldref )
+               CALL xios_get_attr( slxhdl_flds(jn), name=clxatt_name2, grid_ref=clxatt_gridref, field_ref=clxatt_fieldref )
                clgt="T"
-               IF ( INDEX( slxatt_gridref, "_U_" ) > 0 ) clgt="U"
-               IF ( INDEX( slxatt_gridref, "_V_" ) > 0 ) clgt="V"
-               IF ( INDEX( slxatt_gridref, "_W_" ) > 0 ) clgt="W"
+               IF ( INDEX( clxatt_gridref, "_U_" ) > 0 ) clgt="U"
+               IF ( INDEX( clxatt_gridref, "_V_" ) > 0 ) clgt="V"
+               IF ( INDEX( clxatt_gridref, "_W_" ) > 0 ) clgt="W"
                clgd="2D"
-               IF ( INDEX( slxatt_gridref, "_3D" ) > 0 ) clgd="3D"
-               CALL xios_add_child ( slxhdl_fldgrp, slxhdl_fld, TRIM( slxatt_name2 )//"."//TRIM( slxatt_name1 ) )
+               IF ( INDEX( clxatt_gridref, "_3D" ) > 0 ) clgd="3D"
+               CALL xios_add_child ( slxhdl_fldgrp, slxhdl_fld, TRIM( clxatt_name2 )//"."//TRIM( clxatt_name1 ) )
                ! Set appropriate name attribute to avoid the possibility of
                ! using an inappropriate inherited name attribute as the variable
                ! name in the output file
-               CALL xios_set_attr  ( slxhdl_fld, name=TRIM( slxatt_name2 )//"."//TRIM( slxatt_name1 ),         &
-                  &                  expr="this * "//TRIM( slxatt_fieldref ), grid_ref="diamlr_grid_"//clgd,   &
-                  &                  field_ref=TRIM( slxatt_name1 )//"_"//clgd, enabled=slxatt_enabled, operation="accumulate" )
+               CALL xios_set_attr  ( slxhdl_fld, name=TRIM( clxatt_name2 )//"."//TRIM( clxatt_name1 ),         &
+                  &                  expr="this * "//TRIM( clxatt_fieldref ), grid_ref="diamlr_grid_"//clgd,   &
+                  &                  field_ref=TRIM( clxatt_name1 )//"_"//clgd, enabled=llxatt_enabled, operation="accumulate" )
                CALL xios_get_handle( "diamlr_file_grid_"//clgt, slxhdl_fil )
-               CALL xios_add_child ( slxhdl_fil, slxhdl_fld, TRIM( slxatt_name2 )//"."//TRIM( slxatt_name1 ) )
+               CALL xios_add_child ( slxhdl_fil, slxhdl_fld, TRIM( clxatt_name2 )//"."//TRIM( clxatt_name1 ) )
             END DO
 
