Index: branches/2011/dev_NEMO_MERGE_2011/NEMOGCM/NEMO/OPA_SRC/DIA/diaharm.F90
===================================================================
--- branches/2011/dev_NEMO_MERGE_2011/NEMOGCM/NEMO/OPA_SRC/DIA/diaharm.F90	(revision 3186)
+++ branches/2011/dev_NEMO_MERGE_2011/NEMOGCM/NEMO/OPA_SRC/DIA/diaharm.F90	(revision 3247)
@@ -25,8 +25,7 @@
    PRIVATE
 
-   LOGICAL, PUBLIC, PARAMETER ::   lk_diaharm  = .TRUE.
+   LOGICAL, PUBLIC, PARAMETER :: lk_diaharm  = .TRUE.
    
-   INTEGER, PARAMETER :: nb_harmo_max =  9
-   INTEGER, PARAMETER :: jpincomax    = 18
+   INTEGER, PARAMETER :: jpincomax    = 2.*jpmax_harmo
    INTEGER, PARAMETER :: jpdimsparse  = jpincomax*300*24
 
@@ -34,5 +33,5 @@
                          nit000_han = 1, & ! First time step used for harmonic analysis
                          nitend_han = 1, & ! Last time step used for harmonic analysis
-                         nstep_han  = 1  & ! Time step frequency for harmonic analysis
+                         nstep_han  = 1, & ! Time step frequency for harmonic analysis
                          nb_ana            ! Number of harmonics to analyse
 
@@ -44,4 +43,5 @@
                                                 out_v
 
+   INTEGER :: ninco, nsparse
    INTEGER ,       DIMENSION(jpdimsparse)         :: njsparse, nisparse
    INTEGER , SAVE, DIMENSION(jpincomax)           :: ipos1
@@ -51,5 +51,5 @@
    REAL(wp), SAVE, DIMENSION(jpincomax)           :: zpivot
 
-   CHARACTER (LEN=4), DIMENSION(nb_harmo_max) ::   &
+   CHARACTER (LEN=4), DIMENSION(jpmax_harmo) ::   &
        tname         ! Names of tidal constituents ('M2', 'K1',...)
 
@@ -78,26 +78,26 @@
       !! * Local declarations 
       INTEGER :: jh, nhan, jk, ji
-      NAMELIST/nam_diaharm/ nit000_han, nitend_han, nstep_han, nb_ana, tname
-
-      !!----------------------------------------------------------------------
-
-      ! Read namelist parameters:
-      ! -------------------------
+
+      NAMELIST/nam_diaharm/ nit000_han, nitend_han, nstep_han, tname
+      !!----------------------------------------------------------------------
+
+      IF(lwp) THEN
+         WRITE(numout,*)
+         WRITE(numout,*) 'dia_harm_init: Tidal harmonic analysis initialization'
+         WRITE(numout,*) '~~~~~~~ '
+      ENDIF
+      !
+      CALL tide_init_Wave
+      !
+      tname(:)=''
+      !
+      ! Read Namelist nam_diaharm
       REWIND ( numnam )
       READ   ( numnam, nam_diaharm )
-
-      IF(lwp) WRITE(numout,*)
-      IF(lwp) WRITE(numout,*) 'dia_harm_init: Tidal harmonic analysis initialization'
-      IF(lwp) WRITE(numout,*) '~~~~~~~~~~~~~'
-
-      IF(lwp) WRITE(numout,*) 'First time step used for analysis:  nit000_han= ', nit000_han
-      IF(lwp) WRITE(numout,*) 'Last  time step used for analysis:  nitend_han= ', nitend_han
-      IF(lwp) WRITE(numout,*) 'Time step frequency for harmonic analysis:  nstep_han= ', nstep_han
-
-      IF (nb_ana > nb_harmo_max) THEN
-        IF(lwp) WRITE(numout,*) ' E R R O R : dia_harm_init. &
-                                & nb_ana must be lower than nb_harmo_max, stop'
-        IF(lwp) WRITE(numout,*) 'nb_harmo_max= ', nb_harmo_max
-        nstop = nstop + 1
+      !
+      IF(lwp) THEN
+         WRITE(numout,*) 'First time step used for analysis:  nit000_han= ', nit000_han
+         WRITE(numout,*) 'Last  time step used for analysis:  nitend_han= ', nitend_han
+         WRITE(numout,*) 'Time step frequency for harmonic analysis:  nstep_han= ', nstep_han
       ENDIF
 
@@ -105,23 +105,39 @@
       ! ----------------------------------------------
       IF (nit000 > nit000_han) THEN
-        IF(lwp) WRITE(numout,*) ' E R R O R : dia_harm_init. &
-                                & nit000_han must be greater than nit000, stop'
-        IF(lwp) WRITE(numout,*) 'restart capability not implemented'
+        IF(lwp) WRITE(numout,*) ' E R R O R dia_harm_init : nit000_han must be greater than nit000, stop'
+        IF(lwp) WRITE(numout,*) ' restart capability not implemented'
         nstop = nstop + 1
       ENDIF
       IF (nitend < nitend_han) THEN
-        IF(lwp) WRITE(numout,*) ' E R R O R : dia_harm_init. &
-                                & nitend_han must be lower than nitend, stop'
-        IF(lwp) WRITE(numout,*) 'restart capability not implemented'
+        IF(lwp) WRITE(numout,*) ' E R R O R dia_harm_init : nitend_han must be lower than nitend, stop'
+        IF(lwp) WRITE(numout,*) ' restart capability not implemented'
         nstop = nstop + 1
       ENDIF
 
       IF (MOD(nitend_han-nit000_han+1,nstep_han).NE.0) THEN
-        IF(lwp) WRITE(numout,*) ' E R R O R : dia_harm_init. &
-                                & analysis time span must be a multiple of nstep_han, stop'
+        IF(lwp) WRITE(numout,*) ' E R R O R dia_harm_init : analysis time span must be a multiple of nstep_han, stop'
         nstop = nstop + 1
       END IF
 
-      CALL tide_init_Wave
+      nb_ana=0
+      DO jk=1,jpmax_harmo
+         DO ji=1,jpmax_harmo
+            IF(TRIM(tname(jk)) == Wave(ji)%cname_tide) THEN
+               nb_ana=nb_ana+1
+            ENDIF
+         END DO
+      ENDDO
+      !
+      IF(lwp) THEN
+         WRITE(numout,*) '        Namelist nam_diaharm'
+         WRITE(numout,*) '        nb_ana    = ', nb_ana
+         CALL flush(numout)
+      ENDIF
+      !
+      IF (nb_ana > jpmax_harmo) THEN
+        IF(lwp) WRITE(numout,*) ' E R R O R dia_harm_init : nb_ana must be lower than jpmax_harmo, stop'
+        IF(lwp) WRITE(numout,*) ' jpmax_harmo= ', jpmax_harmo
+        nstop = nstop + 1
+      ENDIF
 
       ALLOCATE(name    (nb_ana))
@@ -183,5 +199,5 @@
            (MOD(kt,nstep_han).EQ.0) ) THEN
 
-        ztime = kt*rdt 
+        ztime = (kt-nit000+1)*rdt 
        
         nhc = 0
@@ -239,5 +255,5 @@
       REAL(wp), POINTER, DIMENSION(:,:,:,:) :: ana_amp
       !!--------------------------------------------------------------------
-      CALL wrk_alloc( jpi , jpj , nb_harmo_max , 2 , ana_amp )
+      CALL wrk_alloc( jpi , jpj , jpmax_harmo , 2 , ana_amp )
 
       IF(lwp) WRITE(numout,*)
@@ -280,5 +296,5 @@
                DO jc = 1,2
                   kun = kun + 1
-                  tmp4(kun)=ana_temp(ji,jj,kun,1)
+                  ztmp4(kun)=ana_temp(ji,jj,kun,1)
                ENDDO
             ENDDO
@@ -288,6 +304,6 @@
             ! Fill output array
             DO jh = 1, nb_ana
-               ana_amp(ji,jj,jh,1)=tmp7((jh-1)*2+1)
-               ana_amp(ji,jj,jh,2)=tmp7((jh-1)*2+2)
+               ana_amp(ji,jj,jh,1)=ztmp7((jh-1)*2+1)
+               ana_amp(ji,jj,jh,2)=ztmp7((jh-1)*2+2)
             END DO
          END DO
@@ -317,5 +333,5 @@
                DO jc = 1,2
                   kun = kun + 1
-                  tmp4(kun)=ana_temp(ji,jj,kun,2)
+                  ztmp4(kun)=ana_temp(ji,jj,kun,2)
                ENDDO
             ENDDO
@@ -325,6 +341,6 @@
             ! Fill output array
             DO jh = 1, nb_ana
-               ana_amp(ji,jj,jh,1)=tmp7((jh-1)*2+1)
-               ana_amp(ji,jj,jh,2)=tmp7((jh-1)*2+2)
+               ana_amp(ji,jj,jh,1)=ztmp7((jh-1)*2+1)
+               ana_amp(ji,jj,jh,2)=ztmp7((jh-1)*2+2)
             END DO
 
@@ -351,5 +367,5 @@
                DO jc = 1,2
                   kun = kun + 1
-                  tmp4(kun)=ana_temp(ji,jj,kun,3)
+                  ztmp4(kun)=ana_temp(ji,jj,kun,3)
                ENDDO
             ENDDO
@@ -359,6 +375,6 @@
             ! Fill output array
             DO jh = 1, nb_ana
-               ana_amp(ji,jj,jh,1)=tmp7((jh-1)*2+1)
-               ana_amp(ji,jj,jh,2)=tmp7((jh-1)*2+2)
+               ana_amp(ji,jj,jh,1)=ztmp7((jh-1)*2+1)
+               ana_amp(ji,jj,jh,2)=ztmp7((jh-1)*2+2)
             END DO
 
@@ -378,9 +394,9 @@
 
       CALL dia_wri_harm ! Write results in files
-
-      CALL wrk_dealloc( jpi , jpj , nb_harmo_max , 2 , ana_amp )
-  END SUBROUTINE dia_harm_end
-
-  SUBROUTINE dia_wri_harm
+      CALL wrk_dealloc( jpi , jpj , jpmax_harmo , 2 , ana_amp )
+      !
+   END SUBROUTINE dia_harm_end
+
+   SUBROUTINE dia_wri_harm
       !!--------------------------------------------------------------------
       !!                 ***  ROUTINE dia_wri_harm  ***
@@ -397,8 +413,8 @@
       CHARACTER(LEN=lc) :: cltext
       CHARACTER(LEN=lc) ::   &
-         cdfile_name_T    ,   & ! name of the file created (T-points)
-         cdfile_name_U    ,   & ! name of the file created (U-points)
-         cdfile_name_V          ! name of the file created (V-points)
-      INTEGER  ::   jh       
+         cdfile_name_T   ,   & ! name of the file created (T-points)
+         cdfile_name_U   ,   & ! name of the file created (U-points)
+         cdfile_name_V         ! name of the file created (V-points)
+      INTEGER  ::   jh
       !!----------------------------------------------------------------------
 
@@ -410,5 +426,5 @@
 
       IF(lwp) WRITE(numout,*) '  '
-      IF(lwp) WRITE(numout,*) 'dia_wri_harm : Write harmonic analysis results' 
+      IF(lwp) WRITE(numout,*) 'dia_wri_harm : Write harmonic analysis results'
 #if defined key_dimgout
       IF(lwp) WRITE(numout,*) '~~~~~~~~~~~~~  Output files: ', TRIM(cdfile_name_T)
@@ -457,5 +473,5 @@
 #endif
 
-  END SUBROUTINE dia_wri_harm
+   END SUBROUTINE dia_wri_harm
 
    SUBROUTINE SUR_DETERMINE(init)
