Index: NEMO/branches/2019/dev_r11879_ENHANCE-05_SimonM-Harmonic_Analysis/src/OCE/DIA/diadetide.F90
===================================================================
--- NEMO/branches/2019/dev_r11879_ENHANCE-05_SimonM-Harmonic_Analysis/src/OCE/DIA/diadetide.F90	(revision 12121)
+++ NEMO/branches/2019/dev_r11879_ENHANCE-05_SimonM-Harmonic_Analysis/src/OCE/DIA/diadetide.F90	(revision 12122)
@@ -11,5 +11,5 @@
    USE dom_oce        , ONLY :   rdt, nsec_day
    USE phycst         , ONLY :   rpi
-   USE tide_mod       , ONLY :   tide_harmo, jpmax_harmo, Wave
+   USE tide_mod
    USE xios
 
@@ -39,18 +39,16 @@
       !!----------------------------------------------------------------------
 
-      LOGICAL                             ::   llxatt_enabled
-      INTEGER, ALLOCATABLE, DIMENSION(:)  ::   itide                                    ! Tidal-constituent index
-      REAL(wp), ALLOCATABLE, DIMENSION(:) ::   ztide_omega, ztide_u, ztide_v, ztide_f   ! Tidal-constituent parameters
-      REAL(wp)                            ::   zdt
-      INTEGER                             ::   jn
+      REAL(wp)                                   ::   zdt
+      INTEGER                                    ::   jn
+      CHARACTER (LEN=4), DIMENSION(jpmax_harmo)  ::   ctide_selected = ' n/a '
+      TYPE(tide_harmonic), DIMENSION(:), POINTER ::   stideconst
 
       ! Enquire detiding activation state (test for presence of detiding-related
       ! weights field and output file group)
-      IF ( xios_is_valid_field( "diadetide_weight" ).AND.xios_is_valid_filegroup( "diadetide_files" ) ) THEN
-         llxatt_enabled = .TRUE.
+      IF ( xios_is_valid_field( "diadetide_weight" ).AND.xios_is_valid_filegroup( "diadetide_files" ).AND.ln_tide ) THEN
+         lk_diadetide = .TRUE.
       ELSE
-         llxatt_enabled = .FALSE.
+         lk_diadetide = .FALSE.
       END IF
-      lk_diadetide = llxatt_enabled
 
       IF (lwp) THEN
@@ -63,16 +61,13 @@
       IF (lk_diadetide) THEN
          ! Retrieve information about M2 tidal constituent
-         ALLOCATE( ztide_omega(1), ztide_v(1), ztide_u(1), ztide_f(1), itide(1) )
-         DO jn = 1, jpmax_harmo
-            IF (TRIM( Wave(jn)%cname_tide ) == 'M2') itide(1) = jn
-         END DO
-         CALL tide_harmo( ztide_omega, ztide_v, ztide_u, ztide_f, itide, 1 )
+         ctide_selected(1) = 'M2'
+         CALL tide_init_harmonics(ctide_selected, stideconst) 
+
          ! For M2, twice the tidal period spans slightly more than one full
          ! day. Compute the maximum number of equal intervals that span exactly
          ! twice the tidal period *and* whose mid-points fall within a 24-hour
          ! period from midnight to midnight.
-         zdt = Wave(itide(1))%nt * 2.0_wp * rpi / ztide_omega(1)
+         zdt = 2.0_wp * 2.0_wp * rpi / stideconst(1)%omega
          ndiadetide = FLOOR( zdt / ( zdt - 86400.0_wp ) )
-         DEALLOCATE( ztide_omega, ztide_v, ztide_u, ztide_f, itide )
          ! Compute mid-points of the intervals to be included in the detided
          ! average
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 12121)
+++ NEMO/branches/2019/dev_r11879_ENHANCE-05_SimonM-Harmonic_Analysis/src/OCE/DIA/diamlr.F90	(revision 12122)
@@ -14,5 +14,5 @@
    USE timing         , ONLY :   timing_start, timing_stop
    USE xios
-   USE tide_mod       , ONLY :   tide_harmo, jpmax_harmo, Wave
+   USE tide_mod
 
    IMPLICIT NONE
@@ -78,8 +78,7 @@
       INTEGER                                     ::   jl, jm, jn
       INTEGER                                     ::   itide                       ! Number of available tidal components
-      INTEGER,  ALLOCATABLE, DIMENSION(:)         ::   itide_const                 ! Index list of selected tidal constituents
-      REAL(wp), ALLOCATABLE, DIMENSION(:)         ::   ztide_omega, ztide_u,   &   ! Tidal frequency, phase, nodal correction
-         &                                             ztide_v, ztide_f
       REAL(wp)                                    ::   ztide_phase                 ! Tidal-constituent phase at adatrj=0
+      CHARACTER (LEN=4), DIMENSION(jpmax_harmo)   ::   ctide_selected = ' n/a '
+      TYPE(tide_harmonic), DIMENSION(:), POINTER  ::   stideconst
 
       IF(lwp) THEN
@@ -138,12 +137,19 @@
          ifld = 0
          !
-         ! Retrieve information (frequency, phase, nodal correction) about all
-         ! available tidal constituents for placeholder substitution below
-         itide = jpmax_harmo
-         ALLOCATE(itide_const(itide), ztide_omega(itide), ztide_u(itide), ztide_v(itide), ztide_f(itide))
-         DO jn = 1, itide
-            itide_const(jn) = jn   ! Select all available tidal constituents
-         END DO
-         CALL tide_harmo( ztide_omega, ztide_v, ztide_u, ztide_f, itide_const, itide )
+         IF ( ln_tide ) THEN
+            ! Retrieve information (frequency, phase, nodal correction) about all
+            ! available tidal constituents for placeholder substitution below
+            ctide_selected(1:34) = (/ 'Mf', 'Mm', 'Ssa', 'Mtm', 'Msf',    &
+               &                      'Msqm', 'Sa', 'K1', 'O1', 'P1',     &
+               &                      'Q1', 'J1', 'S1', 'M2', 'S2', 'N2', &
+               &                      'K2', 'nu2', 'mu2', '2N2', 'L2',    &
+               &                      'T2', 'eps2', 'lam2', 'R2', 'M3',   &
+               &                      'MKS2', 'MN4', 'MS4', 'M4', 'N4',   &
+               &                      'S4', 'M6', 'M8' /)
+            CALL tide_init_harmonics(ctide_selected, stideconst)
+            itide = size(stideconst)
+         ELSE
+            itide = 0
+         ENDIF
          
          DO jm = 1, jpscanmax
@@ -165,18 +171,19 @@
                   ! parameters (amplitudes, angular veloccities, nodal phase
                   ! correction) with values that have been obtained from the
-                  ! tidal-forcing implementation
+                  ! tidal-forcing implementation (if enabled)
                   DO jn = 1, itide
                      ! Compute phase of tidal constituent (incl. current nodal
                      ! correction) at the start of the model run (i.e. for
                      ! adatrj=0)
-                     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__"
+                     ztide_phase = MOD( stideconst(jn)%u +  stideconst(jn)%v0 - adatrj * 86400.0_wp * stideconst(jn)%omega, &
+                        & 2.0_wp * rpi )
+                     clrepl = "__TDE_"//TRIM( stideconst(jn)%cname_tide )//"_omega__"
                      DO WHILE ( INDEX( clxatt_expr, TRIM( clrepl ) ) > 0 )
-                        WRITE (clfloat, '(e25.18)') ztide_omega(jn)
+                        WRITE (clfloat, '(e25.18)') stideconst(jn)%omega
                         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__"
+                     clrepl = "__TDE_"//TRIM( stideconst(jn)%cname_tide )//"_phase__"
                      DO WHILE ( INDEX( clxatt_expr, TRIM( clrepl ) ) > 0 )
                         WRITE (clfloat, '(e25.18)') ztide_phase
@@ -185,7 +192,7 @@
                            &          clxatt_expr(jl + LEN( TRIM( clrepl ) ):LEN( TRIM( clxatt_expr ) ))
                      END DO
-                     clrepl = "__TDE_"//TRIM( Wave(jn)%cname_tide )//"_amplitude__"
+                     clrepl = "__TDE_"//TRIM( stideconst(jn)%cname_tide )//"_amplitude__"
                      DO WHILE (INDEX( clxatt_expr, TRIM( clrepl ) ) > 0 )
-                        WRITE (clfloat, '(e25.18)') ztide_f(jn)
+                        WRITE (clfloat, '(e25.18)') stideconst(jn)%f
                         jl = INDEX( clxatt_expr, TRIM( clrepl ) )
                         clxatt_expr = clxatt_expr(1:jl - 1)//clfloat//   &
@@ -236,7 +243,4 @@
 
          END DO
-
-         ! Release tidal data
-         DEALLOCATE( itide_const, ztide_omega, ztide_u, ztide_v, ztide_f )
 
          ! Output number of active regressors and fields selected for analysis
