Index: LMDZ6/trunk/libf/dyn3dmem/qminimum_loc.F
===================================================================
--- LMDZ6/trunk/libf/dyn3dmem/qminimum_loc.F	(revision 4469)
+++ LMDZ6/trunk/libf/dyn3dmem/qminimum_loc.F	(revision 5001)
@@ -31,4 +31,7 @@
 c     .................................................................
 c
+cDC iq_val and iq_liq are usable for q only, NOT for q_follow
+c   and zx_defau_diag (crash if iq_val/liq==3) => vapor/liquid
+c   water at hardcoded indices 1/2 in these variables
       INTEGER i, k, iq
       REAL zx_defau, zx_abc, zx_pump(ijb_u:ije_u), pompe
@@ -49,9 +52,4 @@
       INTEGER ixt
       INTEGER iso_verif_noNaN_nostop
-c
-c Quand l'eau liquide est trop petite (ou negative), on prend
-c l'eau vapeur de la meme couche et la convertit en eau liquide
-c (sans changer la temperature !)
-c
 
 c$OMP BARRIER
@@ -63,4 +61,10 @@
          first = .FALSE.
       END IF
+c
+c Quand l'eau liquide est trop petite (ou negative), on prend
+c l'eau vapeur de la meme couche et la convertit en eau liquide
+c (sans changer la temperature !)
+c
+
       call check_isotopes(q,ij_begin,ij_end,'qminimum 52')   
 
@@ -73,6 +77,6 @@
           zx_defau_diag(i,k,1)=0.0
           zx_defau_diag(i,k,2)=0.0
-          q_follow(i,k,1)=q(i,k,1)
-          q_follow(i,k,2)=q(i,k,2)
+          q_follow(i,k,1)=q(i,k,iq_vap)
+          q_follow(i,k,2)=q(i,k,iq_liq)
         ENDDO
 c$OMP END DO NOWAIT
@@ -80,18 +84,18 @@
 
       !write(lunout,*) 'qminimum 57'
-      DO 1000 k = 1, llm
+      DO k = 1, llm
 c$OMP DO SCHEDULE(STATIC)       
-      DO 1040 i = ijb, ije
-            if (seuil_liq - q(i,k,iq_liq) .gt. 0.d0 ) then
-
-              if (niso > 0) zx_defau_diag(i,k,iq_liq)=AMAX1
+        DO i = ijb, ije
+          if (seuil_liq - q(i,k,iq_liq) .gt. 0.d0 ) then
+
+            if (niso > 0) zx_defau_diag(i,k,2)=AMAX1
      :               ( seuil_liq - q(i,k,iq_liq), 0.0 )
 
-               q(i,k,iq_vap) = q(i,k,iq_vap) + q(i,k,iq_liq) - seuil_liq
-               q(i,k,iq_liq) = seuil_liq
-            endif
- 1040 CONTINUE
-c$OMP END DO NOWAIT
- 1000 CONTINUE
+            q(i,k,iq_vap) = q(i,k,iq_vap) + q(i,k,iq_liq) - seuil_liq
+            q(i,k,iq_liq) = seuil_liq
+          endif
+        END DO
+c$OMP END DO NOWAIT
+      END DO
 
 c
@@ -100,22 +104,20 @@
 c
       !write(lunout,*) 'qminimum 81'
-      iq = iq_vap
-c
       DO k = llm, 2, -1
 ccc      zx_abc = dpres(k) / dpres(k-1)
 c$OMP DO SCHEDULE(STATIC)
-      DO i = ijb, ije
-
-         if ( seuil_vap - q(i,k,iq) .gt. 0.d0 ) then
-
-            if (niso > 0)
-     &        zx_defau_diag(i,k,iq)=AMAX1( seuil_vap - q(i,k,iq), 0.0 )
-
-            q(i,k-1,iq) =  q(i,k-1,iq) - ( seuil_vap - q(i,k,iq) ) *
-     &           deltap(i,k) / deltap(i,k-1)
-            q(i,k,iq)   =  seuil_vap  
-
-         endif
-      ENDDO
+        DO i = ijb, ije
+
+          if ( seuil_vap - q(i,k,iq_vap) .gt. 0.d0 ) then
+
+            if (niso > 0) zx_defau_diag(i,k,1)
+     &           = AMAX1( seuil_vap - q(i,k,iq_vap), 0.0 )
+
+            q(i,k-1,iq_vap) = q(i,k-1,iq_vap) - (seuil_vap
+     &           -q(i,k,iq_vap)) * deltap(i,k)/deltap(i,k-1)
+            q(i,k,iq_vap)   =  seuil_vap  
+
+          endif
+        ENDDO
 c$OMP END DO NOWAIT
       ENDDO
@@ -129,6 +131,6 @@
 c$OMP DO SCHEDULE(STATIC)
       DO i = ijb, ije
-         zx_pump(i) = AMAX1( 0.0, seuil_vap - q(i,1,iq) )
-         q(i,1,iq)  = AMAX1( q(i,1,iq), seuil_vap )
+         zx_pump(i) = AMAX1( 0.0, seuil_vap - q(i,1,iq_vap) )
+         q(i,1,iq_vap)  = AMAX1( q(i,1,iq_vap), seuil_vap )
          IF (zx_pump(i) > 0.0) THEN
             nb_pump = nb_pump+1
@@ -165,5 +167,5 @@
       DO i = ijb, ije
         if (zx_pump(i).gt.0.0) then
-          q_follow(i,1,iq_vap)=q_follow(i,1,iq_vap)+zx_pump(i)
+          q_follow(i,1,1)=q_follow(i,1,1)+zx_pump(i)
         endif !if (zx_pump(i).gt.0.0) then
       enddo !DO i = ijb, ije  
@@ -175,13 +177,13 @@
 c$OMP DO SCHEDULE(STATIC)      
         DO i = ijb, ije
-          if (zx_defau_diag(i,k,iq_vap).gt.0.0) then             
+          if (zx_defau_diag(i,k,1).gt.0.0) then             
               ! on ajoute la vapeur en k     
-!              write(lunout,*) 'i,k,q_follow(i,k-1,iq_vap)=',
-!     :                 i,k,q_follow(i,k-1,iq_vap)          
-              if (q_follow(i,k-1,iq_vap).lt.min_qParent) then
+!              write(lunout,*) 'i,k,q_follow(i,k-1,ivap)=',
+!     :                 i,k,q_follow(i,k-1,1)          
+              if (q_follow(i,k-1,1).lt.min_qParent) then
                 write(lunout,*) 'tmp qmin: on stoppe'
                 write(lunout,*) 'zx_pump(i)=',zx_pump(i)
-                write(lunout,*) 'q_follow(i,:,iq_vap)=',
-     :                   q_follow(i,:,iq_vap)
+                write(lunout,*) 'q_follow(i,:,ivap)=',
+     :                   q_follow(i,:,1)
                 write(lunout,*) 'k=',k
                 call abort_gcm("qminimum","not enough vapor",1)
@@ -189,14 +191,14 @@
             do ixt=1,ntiso
 !                write(lunout,*) 'qmin 168: ixt=',ixt
-!                write(lunout,*) 'q(i,k,iqIsoPha(ixt,iq_vap)=',
+!                write(lunout,*) 'q(i,k,iqIsoPha(ixt,iq_vap))=',
 !     :             q(i,k,iqIsoPha(ixt,iq_vap))
-!                write(lunout,*) 'zx_defau_diag(i,k,iq_vap)=',
-!     :                  zx_defau_diag(i,k,iq_vap)
-!                write(lunout,*) 'q(i,k-1,iqIsoPha(ixt,iq_vap)=',
+!                write(lunout,*) 'zx_defau_diag(i,k,ivap)=',
+!     :                  zx_defau_diag(i,k,1)
+!                write(lunout,*) 'q(i,k-1,iqIsoPha(ixt,iq_vap))=',
 !     :                   q(i,k-1,iqIsoPha(ixt,iq_vap))     
 
                q(i,k,iqIsoPha(ixt,iq_vap))=q(i,k,iqIsoPha(ixt,iq_vap))
-     :           +zx_defau_diag(i,k,iq_vap)
-     :           *q(i,k-1,iqIsoPha(ixt,iq_vap))/q_follow(i,k-1,iq_vap)
+     :           +zx_defau_diag(i,k,1)
+     :           *q(i,k-1,iqIsoPha(ixt,iq_vap))/q_follow(i,k-1,1)
                 
               if (isoCheck) then
@@ -204,10 +206,10 @@
      :                   'qminimum 155').eq.1) then
                    write(*,*) 'i,k,ixt=',i,k,ixt
-                   write(*,*) 'q_follow(i,k-1,iq_vap)=',
-     :                   q_follow(i,k-1,iq_vap)
+                   write(*,*) 'q_follow(i,k-1,ivap)=',
+     :                   q_follow(i,k-1,1)
                    write(*,*) 'q(i,k,iqIsoPha(ixt,iq_vap))=',
      :                   q(i,k,iqIsoPha(ixt,iq_vap))
-                   write(*,*) 'zx_defau_diag(i,k,iq_vap)=',
-     :                   zx_defau_diag(i,k,iq_vap)
+                   write(*,*) 'zx_defau_diag(i,k,ivap)=',
+     :                   zx_defau_diag(i,k,1)
                    write(*,*) 'q(i,k-1,iqIsoPha(ixt,iq_vap))=',
      :                   q(i,k-1,iqIsoPha(ixt,iq_vap))
@@ -219,8 +221,8 @@
                q(i,k-1,iqIsoPha(ixt,iq_vap)) =
      :            q(i,k-1,iqIsoPha(ixt,iq_vap))
-     :              -zx_defau_diag(i,k,iq_vap)
+     :              -zx_defau_diag(i,k,1)
      :              *deltap(i,k)/deltap(i,k-1)
      :              *q(i,k-1,iqIsoPha(ixt,iq_vap))
-     :              /q_follow(i,k-1,iq_vap)
+     :              /q_follow(i,k-1,1)
 
                if (isoCheck) then
@@ -229,10 +231,10 @@
      :                   'qminimum 175').eq.1) then
                    write(*,*) 'k,i,ixt=',k,i,ixt
-                   write(*,*) 'q_follow(i,k-1,iq_vap)=',
-     :                   q_follow(i,k-1,iq_vap)
+                   write(*,*) 'q_follow(i,k-1,ivap)=',
+     :                   q_follow(i,k-1,1)
                    write(*,*) 'q(i,k,iqIsoPha(ixt,iq_vap))=',
      :                   q(i,k,iqIsoPha(ixt,iq_vap))
-                   write(*,*) 'zx_defau_diag(i,k,iq_vap)=',
-     :                   zx_defau_diag(i,k,iq_vap)
+                   write(*,*) 'zx_defau_diag(i,k,ivap)=',
+     :                   zx_defau_diag(i,k,1)
                    write(*,*) 'q(i,k-1,iqIsoPha(ixt,iq_vap))=',
      :                   q(i,k-1,iqIsoPha(ixt,iq_vap))
@@ -242,10 +244,10 @@
 
               enddo !do ixt=1,niso
-              q_follow(i,k,iq_vap)=   q_follow(i,k,iq_vap)
-     :               +zx_defau_diag(i,k,iq_vap)
-              q_follow(i,k-1,iq_vap)=   q_follow(i,k-1,iq_vap)
-     :               -zx_defau_diag(i,k,iq_vap)
+              q_follow(i,k,1)=   q_follow(i,k,1)
+     :               +zx_defau_diag(i,k,1)
+              q_follow(i,k-1,1)=   q_follow(i,k-1,1)
+     :               -zx_defau_diag(i,k,1)
      :              *deltap(i,k)/deltap(i,k-1)
-          endif !if (zx_defau_diag(i,k,iq_vap).gt.0.0) then
+          endif !if (zx_defau_diag(i,k,1).gt.0.0) then
         enddo !DO i = 1, ip1jmp1        
 c$OMP END DO NOWAIT
@@ -260,21 +262,21 @@
 c$OMP DO SCHEDULE(STATIC)
         DO i = ijb, ije
-          if (zx_defau_diag(i,k,iq_liq).gt.0.0) then
+          if (zx_defau_diag(i,k,2).gt.0.0) then
 
               ! on ajoute eau liquide en k en k              
               do ixt=1,ntiso
                q(i,k,iqIsoPha(ixt,iq_liq))=q(i,k,iqIsoPha(ixt,iq_liq))
-     :              +zx_defau_diag(i,k,iq_liq)
-     :              *q(i,k,iqIsoPha(ixt,iq_vap))/q_follow(i,k,iq_vap)
+     :              +zx_defau_diag(i,k,2)
+     :              *q(i,k,iqIsoPha(ixt,iq_vap))/q_follow(i,k,1)
               ! et on la retranche à la vapeur en k
                q(i,k,iqIsoPha(ixt,iq_vap))=q(i,k,iqIsoPha(ixt,iq_vap))
-     :              -zx_defau_diag(i,k,iq_liq)
-     :              *q(i,k,iqIsoPha(ixt,iq_vap))/q_follow(i,k,iq_vap)   
+     :              -zx_defau_diag(i,k,2)
+     :              *q(i,k,iqIsoPha(ixt,iq_vap))/q_follow(i,k,1)   
               enddo !do ixt=1,niso
-              q_follow(i,k,iq_liq)=   q_follow(i,k,iq_liq)
-     :               +zx_defau_diag(i,k,iq_liq)
-              q_follow(i,k,iq_vap)=   q_follow(i,k,iq_vap)
-     :               -zx_defau_diag(i,k,iq_liq)
-          endif !if (zx_defau_diag(i,k,iq_vap).gt.0.0) then
+              q_follow(i,k,2)=   q_follow(i,k,2)
+     :               +zx_defau_diag(i,k,2)
+              q_follow(i,k,1)=   q_follow(i,k,1)
+     :               -zx_defau_diag(i,k,2)
+          endif !if (zx_defau_diag(i,k,1).gt.0.0) then
         enddo !DO i = ijb, ije
 c$OMP END DO NOWAIT       
