Index: /branches/2015/dev_r5003_MERCATOR6_CRS/NEMOGCM/NEMO/OPA_SRC/CRS/crsini.F90
===================================================================
--- /branches/2015/dev_r5003_MERCATOR6_CRS/NEMOGCM/NEMO/OPA_SRC/CRS/crsini.F90	(revision 6796)
+++ /branches/2015/dev_r5003_MERCATOR6_CRS/NEMOGCM/NEMO/OPA_SRC/CRS/crsini.F90	(revision 6797)
@@ -106,4 +106,13 @@
         WRITE(numout,*) '   type of Kz coarsening (0,1,2)         nn_crs_kz  = ', nn_crs_kz
         WRITE(numout,*) '   wn coarsened or computed using hdivn  ln_crs_wn  = ', ln_crs_wn
+
+        SELECT CASE ( nn_crs_kz )
+           CASE ( 0 ) ; WRITE(numout,*) '   coarsene KZ with MEAN(KZ)'
+           CASE ( 1 ) ; WRITE(numout,*) '   coarsene KZ with MIN(KZ)'
+           CASE ( 2 ) ; WRITE(numout,*) '   coarsene KZ with MAX(KZ)'
+           CASE ( 3 ) ; WRITE(numout,*) '   coarsene KZ with MEANLOG(KZ)'
+           CASE ( 4 ) ; WRITE(numout,*) '   coarsene KZ with MEDIANE(KZ)'
+           CASE ( 5 ) ; WRITE(numout,*) '   coarsene KZ with TKE coarsening'
+       END SELECT
      ENDIF
               
@@ -111,5 +120,4 @@
      rfacty_r = 1. / nn_facty
 
-write(narea+200,*)"crsini0",nstop; call flush(narea+200)
 
      !---------------------------------------------------------
@@ -117,5 +125,4 @@
      !---------------------------------------------------------
      CALL crs_dom_def      
-write(narea+200,*)"crsini1",nstop; call flush(narea+200)
 
      !---------------------------------------------------------
@@ -128,13 +135,4 @@
  
      CALL crs_dom_msk
-write(narea+200,*)"crsini2",nstop; call flush(narea+200)
-      CALL mppsync()
-
-     !IF( narea==279 )THEN
-     !WRITE(narea+200,*)"tutu1 ",jpi,jpj,nldi,nlei,nldj,nlej
-     !DO jj=1,jpj
-     !   WRITE(narea+200,*)"tutu2 ",jj,MINVAL(tmask(:,jj,:)),MAXVAL(tmask(:,jj,:))
-     !ENDDO
-     !ENDIF
 
      !  3.b. Get the coordinates
@@ -142,28 +140,8 @@
      !      Even-numbered reduction factor, center coordinate on U-,V- faces or f-corner.
      !      
-     !IF ( nresty /= 0 .AND. nrestx /= 0 ) THEN
         CALL crs_dom_coordinates( gphit, glamt, 'T', gphit_crs, glamt_crs ) 
         CALL crs_dom_coordinates( gphiu, glamu, 'U', gphiu_crs, glamu_crs )       
         CALL crs_dom_coordinates( gphiv, glamv, 'V', gphiv_crs, glamv_crs ) 
         CALL crs_dom_coordinates( gphif, glamf, 'F', gphif_crs, glamf_crs ) 
-     !ELSEIF ( nresty /= 0 .AND. nrestx == 0 ) THEN
-     !   CALL crs_dom_coordinates( gphiu, glamu, 'T', gphit_crs, glamt_crs )
-     !   CALL crs_dom_coordinates( gphiu, glamu, 'U', gphiu_crs, glamu_crs )
-     !   CALL crs_dom_coordinates( gphif, glamf, 'V', gphiv_crs, glamv_crs )
-     !   CALL crs_dom_coordinates( gphif, glamf, 'F', gphif_crs, glamf_crs )
-     !ELSEIF ( nresty == 0 .AND. nrestx /= 0 ) THEN
-     !   CALL crs_dom_coordinates( gphiv, glamv, 'T', gphit_crs, glamt_crs )
-     !   CALL crs_dom_coordinates( gphif, glamf, 'U', gphiu_crs, glamu_crs )
-     !   CALL crs_dom_coordinates( gphiv, glamv, 'V', gphiv_crs, glamv_crs )
-     !   CALL crs_dom_coordinates( gphif, glamf, 'F', gphif_crs, glamf_crs )
-     !ELSE 
-     !   CALL crs_dom_coordinates( gphif, glamf, 'T', gphit_crs, glamt_crs )
-     !   CALL crs_dom_coordinates( gphif, glamf, 'U', gphiu_crs, glamu_crs )
-     !   CALL crs_dom_coordinates( gphif, glamf, 'V', gphiv_crs, glamv_crs )
-     !   CALL crs_dom_coordinates( gphif, glamf, 'F', gphif_crs, glamf_crs )
-     !ENDIF
-      CALL mppsync()
-
-write(narea+200,*)"crsini3",nstop; call flush(narea+200)
 
      !  3.c. Get the horizontal mesh
@@ -175,18 +153,4 @@
      CALL crs_dom_hgr( e1v, e2v, 'V', e1v_crs, e2v_crs )
      CALL crs_dom_hgr( e1f, e2f, 'F', e1f_crs, e2f_crs )
-
-     DO ji=nldi_crs,nlei_crs
-     DO jj=nldj_crs,nlej_crs
-        IF( e1t_crs(ji,jj)==0._wp .AND. tmask_crs(ji,jj,1) .NE. 0._wp )WRITE(narea+8000-1,*)"e1t_crs=0",ji,jj;CALL FLUSH(narea+8000-1) 
-        IF( e1u_crs(ji,jj)==0._wp .AND. umask_crs(ji,jj,1) .NE. 0._wp )WRITE(narea+8000-1,*)"e1u_crs=0",ji,jj;CALL FLUSH(narea+8000-1) 
-        IF( e1v_crs(ji,jj)==0._wp .AND. vmask_crs(ji,jj,1) .NE. 0._wp )WRITE(narea+8000-1,*)"e1v_crs=0",ji,jj;CALL FLUSH(narea+8000-1) 
-        IF( e1f_crs(ji,jj)==0._wp .AND. fmask_crs(ji,jj,1) .NE. 0._wp )WRITE(narea+8000-1,*)"e1f_crs=0",ji,jj;CALL FLUSH(narea+8000-1) 
-        IF( e2t_crs(ji,jj)==0._wp .AND. tmask_crs(ji,jj,1) .NE. 0._wp )WRITE(narea+8000-1,*)"e2t_crs=0",ji,jj;CALL FLUSH(narea+8000-1) 
-        IF( e2u_crs(ji,jj)==0._wp .AND. umask_crs(ji,jj,1) .NE. 0._wp )WRITE(narea+8000-1,*)"e2u_crs=0",ji,jj;CALL FLUSH(narea+8000-1) 
-        IF( e2v_crs(ji,jj)==0._wp .AND. vmask_crs(ji,jj,1) .NE. 0._wp )WRITE(narea+8000-1,*)"e2v_crs=0",ji,jj;CALL FLUSH(narea+8000-1) 
-        IF( e2f_crs(ji,jj)==0._wp .AND. fmask_crs(ji,jj,1) .NE. 0._wp )WRITE(narea+8000-1,*)"e2f_crs=0",ji,jj;CALL FLUSH(narea+8000-1) 
-     ENDDO
-     ENDDO
-
 
      WHERE(e1t_crs == 0._wp) e1t_crs=r_inf
@@ -199,17 +163,6 @@
      WHERE(e2f_crs == 0._wp) e2f_crs=r_inf
 
-     zmin=MINVAL(e1t_crs,mask=(tmask_crs(:,:,1)==1));CALL mpp_min(zmin);zmax=MAXVAL(e1t_crs,mask=(tmask_crs(:,:,1)==1));CALL mpp_max(zmax);IF(lwp)WRITE(numout,*)"crs e1t_crs ",zmin,zmax
-     zmin=MINVAL(e1u_crs,mask=(umask_crs(:,:,1)==1));CALL mpp_min(zmin);zmax=MAXVAL(e1u_crs,mask=(umask_crs(:,:,1)==1));CALL mpp_max(zmax);IF(lwp)WRITE(numout,*)"crs e1u_crs ",zmin,zmax
-     zmin=MINVAL(e1v_crs,mask=(vmask_crs(:,:,1)==1));CALL mpp_min(zmin);zmax=MAXVAL(e1v_crs,mask=(vmask_crs(:,:,1)==1));CALL mpp_max(zmax);IF(lwp)WRITE(numout,*)"crs e1v_crs ",zmin,zmax
-     zmin=MINVAL(e1f_crs,mask=(fmask_crs(:,:,1)==1));CALL mpp_min(zmin);zmax=MAXVAL(e1f_crs,mask=(fmask_crs(:,:,1)==1));CALL mpp_max(zmax);IF(lwp)WRITE(numout,*)"crs e1f_crs ",zmin,zmax
-     zmin=MINVAL(e2t_crs,mask=(tmask_crs(:,:,1)==1));CALL mpp_min(zmin);zmax=MAXVAL(e2t_crs,mask=(tmask_crs(:,:,1)==1));CALL mpp_max(zmax);IF(lwp)WRITE(numout,*)"crs e2t_crs ",zmin,zmax
-     zmin=MINVAL(e2u_crs,mask=(umask_crs(:,:,1)==1));CALL mpp_min(zmin);zmax=MAXVAL(e2u_crs,mask=(umask_crs(:,:,1)==1));CALL mpp_max(zmax);IF(lwp)WRITE(numout,*)"crs e2u_crs ",zmin,zmax
-     zmin=MINVAL(e2v_crs,mask=(vmask_crs(:,:,1)==1));CALL mpp_min(zmin);zmax=MAXVAL(e2v_crs,mask=(vmask_crs(:,:,1)==1));CALL mpp_max(zmax);IF(lwp)WRITE(numout,*)"crs e2v_crs ",zmin,zmax
-     zmin=MINVAL(e2f_crs,mask=(fmask_crs(:,:,1)==1));CALL mpp_min(zmin);zmax=MAXVAL(e2f_crs,mask=(fmask_crs(:,:,1)==1));CALL mpp_max(zmax);IF(lwp)WRITE(numout,*)"crs e2f_crs ",zmin,zmax
-
-
      e1e2t_crs(:,:) = e1t_crs(:,:) * e2t_crs(:,:)
      
-write(narea+200,*)"crsini4",nstop; call flush(narea+200)
      
      !      3.c.2 Coriolis factor  
@@ -248,33 +201,4 @@
      CALL crs_dom_sfc( vmask, 'V', e1e3v_crs, e1e3v_msk, p_e1=e1v, p_e3=zfse3v )
 
-     DO ji=nldi_crs,nlei_crs
-     DO jj=nldj_crs,nlej_crs
-     DO jk=1,jpk   
-        IF( e1e2w_crs(ji,jj,jk)==0._wp .AND. tmask_crs(ji,jj,jk)==1._wp )WRITE(narea+8000-1,*)"e1e2w_crs=0",ji,jj,jk;CALL FLUSH(narea+8000-1)
-        IF( e1e2w_msk(ji,jj,jk)==0._wp .AND. tmask_crs(ji,jj,jk)==1._wp )WRITE(narea+8000-1,*)"e1e2w_msk=0",ji,jj,jk;CALL FLUSH(narea+8000-1)
-        IF( e2e3u_crs(ji,jj,jk)==0._wp .AND. umask_crs(ji,jj,jk)==1._wp )WRITE(narea+8000-1,*)"e2e3u_crs=0",ji,jj,jk;CALL FLUSH(narea+8000-1)
-        IF( e2e3u_msk(ji,jj,jk)==0._wp .AND. umask_crs(ji,jj,jk)==1._wp )WRITE(narea+8000-1,*)"e2e3u_msk=0",ji,jj,jk;CALL FLUSH(narea+8000-1)
-        IF( e1e3v_crs(ji,jj,jk)==0._wp .AND. vmask_crs(ji,jj,jk)==1._wp )WRITE(narea+8000-1,*)"e1e3v_crs=0",ji,jj,jk;CALL FLUSH(narea+8000-1)
-        IF( e1e3v_msk(ji,jj,jk)==0._wp .AND. vmask_crs(ji,jj,jk)==1._wp )WRITE(narea+8000-1,*)"e1e3v_msk=0",ji,jj,jk;CALL FLUSH(narea+8000-1)
-     ENDDO
-     ENDDO
-     ENDDO
-write(narea+200,*)"crsini5",nstop; call flush(narea+200)
-
-!     WHERE(e1e2w_crs == 0._wp) e1e2w_crs=r_inf
-!     WHERE(e2e3u_crs == 0._wp) e2e3u_crs=r_inf
-!     WHERE(e1e3v_crs == 0._wp) e1e3v_crs=r_inf
-!     WHERE(e1e2w_msk == 0._wp) e1e2w_msk=r_inf
-!     WHERE(e2e3u_msk == 0._wp) e2e3u_msk=r_inf
-!     WHERE(e1e3v_msk == 0._wp) e1e3v_msk=r_inf
-     zmin=MINVAL(e1e2w_crs,mask=(tmask_crs(:,:,:)==1));CALL mpp_min(zmin);zmax=MAXVAL(e1e2w_crs,mask=(tmask_crs(:,:,:)==1));CALL mpp_max(zmax);IF(lwp)WRITE(numout,*)"crs e1e2w_crs ",zmin,zmax
-     zmin=MINVAL(e2e3u_crs,mask=(umask_crs(:,:,:)==1));CALL mpp_min(zmin);zmax=MAXVAL(e2e3u_crs,mask=(umask_crs(:,:,:)==1));CALL mpp_max(zmax);IF(lwp)WRITE(numout,*)"crs e2e3u_crs ",zmin,zmax
-     zmin=MINVAL(e1e3v_crs,mask=(vmask_crs(:,:,:)==1));CALL mpp_min(zmin);zmax=MAXVAL(e1e3v_crs,mask=(vmask_crs(:,:,:)==1));CALL mpp_max(zmax);IF(lwp)WRITE(numout,*)"crs e1e3v_crs ",zmin,zmax
-     zmin=MINVAL(e1e2w_msk,mask=(tmask_crs(:,:,:)==1));CALL mpp_min(zmin);zmax=MAXVAL(e1e2w_msk,mask=(tmask_crs(:,:,:)==1));CALL mpp_max(zmax);IF(lwp)WRITE(numout,*)"crs e1e2w_msk ",zmin,zmax
-     zmin=MINVAL(e2e3u_msk,mask=(umask_crs(:,:,:)==1));CALL mpp_min(zmin);zmax=MAXVAL(e2e3u_msk,mask=(umask_crs(:,:,:)==1));CALL mpp_max(zmax);IF(lwp)WRITE(numout,*)"crs e2e3u_msk ",zmin,zmax
-     zmin=MINVAL(e1e3v_msk,mask=(vmask_crs(:,:,:)==1));CALL mpp_min(zmin);zmax=MAXVAL(e1e3v_msk,mask=(vmask_crs(:,:,:)==1));CALL mpp_max(zmax);IF(lwp)WRITE(numout,*)"crs e1e3v_msk ",zmin,zmax
-   
-     !cbr facsurfu(:,:,:) = umask_crs(:,:,:) * e2e3u_msk(:,:,:) / e2e3u_crs(:,:,:)
-     !cbr facsurfv(:,:,:) = vmask_crs(:,:,:) * e1e3v_msk(:,:,:) / e1e3v_crs(:,:,:)
      DO jk=1,jpk
         DO ji=1,jpi_crs
@@ -291,20 +215,6 @@
      ENDDO
 
-        DO ji=nldi_crs,nlei_crs
-           DO jj=nldj_crs,nlej_crs
-        IF( ABS(e2u_crs(ji,jj)) .LE. 1.e-5 )WRITE(narea+8000-1,*)"UNDERFLOW e2u_crs",ji,jj,e2u_crs(ji,jj),umask_crs(ji,jj,1) ; CALL FLUSH(narea+8000-1)
-        IF( ABS(e1v_crs(ji,jj)) .LE. 1.e-5 )WRITE(narea+8000-1,*)"UNDERFLOW e1v_crs",ji,jj,e1v_crs(ji,jj),vmask_crs(ji,jj,1) ; CALL FLUSH(narea+8000-1)
-           ENDDO
-        ENDDO
-
-
      !    3.d.3   Vertical scale factors
      !
-     zmin=MINVAL(e2u_crs(nldi_crs:nlei_crs,nldj_crs:nlej_crs));zmax=MAXVAL(e2u_crs(nldi_crs:nlei_crs,nldj_crs:nlej_crs));CALL mpp_min(zmin);CALL mpp_max(zmax);IF(lwp)WRITE(numout,*)"e2u_crs",zmin,zmax;CALL FLUSH(numout)  
-     zmin=MINVAL(e1v_crs(nldi_crs:nlei_crs,nldj_crs:nlej_crs));zmax=MAXVAL(e1v_crs(nldi_crs:nlei_crs,nldj_crs:nlej_crs));CALL mpp_min(zmin);CALL mpp_max(zmax);IF(lwp)WRITE(numout,*)"e1v_crs",zmin,zmax;CALL FLUSH(numout)  
-     zmin=MINVAL(e1e2w_crs(nldi_crs:nlei_crs,nldj_crs:nlej_crs,:));zmax=MAXVAL(e1e2w_crs(nldi_crs:nlei_crs,nldj_crs:nlej_crs,:));CALL mpp_min(zmin);CALL mpp_max(zmax);IF(lwp)WRITE(numout,*)"e1e2w_crs",zmin,zmax;CALL FLUSH(numout)  
-     zmin=MINVAL(zfse3u);zmax=MAXVAL(zfse3u);CALL mpp_min(zmin);CALL mpp_max(zmax);IF(lwp)WRITE(numout,*)"zfse3u",zmin,zmax;CALL FLUSH(numout)  
-     zmin=MINVAL(zfse3v);zmax=MAXVAL(zfse3v);CALL mpp_min(zmin);CALL mpp_max(zmax);IF(lwp)WRITE(numout,*)"zfse3v",zmin,zmax;CALL FLUSH(numout)  
-
      CALL crs_dom_e3( e1t, e2t, zfse3t, p_sfc_3d_crs=e1e2w_crs, cd_type='T', p_mask=tmask, p_e3_crs=e3t_0_crs, p_e3_max_crs=e3t_max_0_crs)
      CALL crs_dom_e3( e1t, e2t, zfse3w, p_sfc_3d_crs=e1e2w_crs, cd_type='W', p_mask=tmask, p_e3_crs=e3w_0_crs, p_e3_max_crs=e3w_max_0_crs)
@@ -316,5 +226,4 @@
      WHERE(e3w_max_0_crs == 0._wp) e3w_max_0_crs=r_inf
 
-write(narea+200,*)"crsini6",nstop; call flush(narea+200)
 #if defined key_vvl
      e3t_max_n_crs=e3t_max_0_crs
@@ -336,5 +245,4 @@
 #endif
 
-write(narea+200,*)"crsini7",nstop; call flush(narea+200)
      ! Reset 0 to e3t_0 or e3w_0
      DO jk = 1, jpk
@@ -375,5 +283,4 @@
 #endif
 
-write(narea+200,*)"crsini8",nstop; call flush(narea+200)
 
      !---------------------------------------------------------
@@ -397,5 +304,4 @@
      !CALL dom_grid_glo   ! Return to parent grid domain
 
-write(narea+200,*)"crsini9",nstop; call flush(narea+200)
 
      !
@@ -413,5 +319,4 @@
       rhop_crs(:,:,:)=0._wp ; rhd_crs(:,:,:)=0._wp ; rb2_crs(:,:,:)=0._wp
 
-write(narea+200,*)"crsini10",nstop; call flush(narea+200)
  
      !---------------------------------------------------------
