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 11970)
+++ NEMO/branches/2019/dev_r11879_ENHANCE-05_SimonM-Harmonic_Analysis/src/OCE/DIA/diamlr.F90	(revision 11971)
@@ -60,9 +60,9 @@
       TYPE(xios_fieldgroup)                       ::   slxhdl_fldgrp
       TYPE(xios_filegroup)                        ::   slxhdl_filgrp
-      TYPE(xios_field), ALLOCATABLE, DIMENSION(:) ::   slxhdl_regs, slxhdl_flds
+      TYPE(xios_field), ALLOCATABLE, DIMENSION(:) ::   slxhdl_regs,    slxhdl_flds
       TYPE(xios_field)                            ::   slxhdl_fld
       TYPE(xios_file)                             ::   slxhdl_fil
-      LOGICAL                                     ::   llxatt_enabled
-      CHARACTER(LEN=256)                          ::   clxatt_expr
+      LOGICAL                                     ::   llxatt_enabled, llxatt_comment
+      CHARACTER(LEN=256)                          ::   clxatt_expr,    clxatt_comment
       CHARACTER(LEN=32)                           ::   clxatt_name1,   clxatt_name2
       CHARACTER(LEN=32)                           ::   clxatt_gridref, clxatt_fieldref
@@ -124,5 +124,5 @@
             CALL xios_add_child      ( slxhdl_filgrp, slxhdl_fil, "diamlr_file_"//cl6a )
             CALL xios_set_attr       ( slxhdl_fil, name_suffix="_diamlr_"//cl6a,   &
-               &                       description="Intermediary output for multiple-linear-regression analysis - "//cl6a )
+               &                       description="Intermediate output for multiple-linear-regression analysis - "//cl6a )
             CALL iom_update_file_name( "diamlr_file_"//cl6a )
          END DO
@@ -193,8 +193,20 @@
                   END DO
 
-                  ! Set name attribute (and overwrite possible pre-configured name)
-                  ! 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( clxatt_expr ) )
+                  ! Set standard value for comment attribute, including possible
+                  ! existing comment added in parantheses
+                  CALL xios_is_defined_attr( slxhdl_regs(ireg+1), comment=llxatt_comment )
+                  IF ( llxatt_comment ) THEN
+                     CALL xios_get_attr( slxhdl_regs(ireg+1), comment=clxatt_comment )
+                     clxatt_comment = "Regressor "//cl3i//" ("//TRIM( clxatt_comment )//") "
+                  ELSE
+                     clxatt_comment = "Regressor "//cl3i
+                  END IF
+
+                  ! Set name attribute (and overwrite possible pre-configured
+                  ! name) with field id to enable id string retrieval from
+                  ! stored handle below, re-set expression with possible
+                  ! substitutions, and set or re-set comment attribute
+                  CALL xios_set_attr  ( slxhdl_regs(ireg+1), name="diamlr_r"//cl3i, expr=TRIM( clxatt_expr ),   &
+                     &                  comment=TRIM( clxatt_comment ) )
 
                   ireg = ireg + 1   ! Accept regressor in list of active regressors
@@ -241,5 +253,6 @@
             !      3-dimensional versions are simply obtained via grid
             !      transformations from the 2-dimensional version.
-            CALL xios_get_attr  ( slxhdl_regs( jm ), name=clxatt_name1, expr=clxatt_expr, enabled=llxatt_enabled )
+            CALL xios_get_attr  ( slxhdl_regs( jm ), name=clxatt_name1, expr=clxatt_expr,              &
+               &                  enabled=llxatt_enabled, comment=clxatt_comment )
             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",     &
@@ -251,18 +264,31 @@
                &                  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
+            !  ii) set up output of active regressors, including metadata
+            CALL xios_get_handle( "diamlr_file_scalar", slxhdl_fil )
+            ! Add regressor to output file
+            CALL xios_add_child ( slxhdl_fil, slxhdl_fld, TRIM( clxatt_name1 ) )
+            CALL xios_set_attr  ( slxhdl_fld, standard_name=TRIM( clxatt_comment ), long_name=TRIM( clxatt_expr ),   &
+               &                  operation="average" )
+               
+            ! iii) set up the output of scalar products with itself and with
+            !      other active regressors
             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=clxatt_name2, enabled=llxatt_enabled )
+               CALL xios_get_attr  ( slxhdl_regs(jn), name=clxatt_name2 )
                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( 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")
+               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,                                            &
+                  &                  long_name="Scalar product of regressor "//TRIM( clxatt_name1 )//   &
+                  &                     " and regressor "//TRIM( clxatt_name2 ),                        &
+                  &                  standard_name=TRIM( clxatt_name1 )//"."//TRIM( clxatt_name2 ),     &
+                  &                  operation="accumulate")
                ! Add regressor-product field to output file
                CALL xios_add_child ( slxhdl_fil, slxhdl_fld, TRIM( clxatt_name1 )//"."//TRIM( clxatt_name2 ) )
@@ -282,8 +308,16 @@
                ! 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( 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" )
+               ! name in the output file; use metadata (standard_name and
+               ! long_name) to refer to the id of the analysed field
+               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,                                             &
+                  &                  long_name="Scalar product of "//TRIM( clxatt_fieldref )//           &
+                  &                     " and regressor "//TRIM( clxatt_name1 ),                         &
+                  &                  standard_name=TRIM( clxatt_fieldref )//"."//TRIM( clxatt_name1 ),   &
+                  &                  operation="accumulate" )
                CALL xios_get_handle( "diamlr_file_grid_"//clgt, slxhdl_fil )
                CALL xios_add_child ( slxhdl_fil, slxhdl_fld, TRIM( clxatt_name2 )//"."//TRIM( clxatt_name1 ) )
