Index: trunk/LMDZ.MARS/libf/dynphy_lonlat/phymars/xvik.F
===================================================================
--- trunk/LMDZ.MARS/libf/dynphy_lonlat/phymars/xvik.F	(revision 2823)
+++ trunk/LMDZ.MARS/libf/dynphy_lonlat/phymars/xvik.F	(revision 2824)
@@ -3,5 +3,5 @@
       USE filtreg_mod, ONLY: inifilr
       USE comconst_mod, ONLY: dtvr,g,r,pi
-     
+      USE comvert_mod, ONLY: pa,preff
       
       IMPLICIT NONE
@@ -38,5 +38,4 @@
       CHARACTER*100  varname
       INTEGER ierr,nid,nvarid,dimid
-      LOGICAL nc
       INTEGER start_ps(3),start_temp(4),start_co2ice(3)
       INTEGER count_ps(3),count_temp(4),count_co2ice(3)
@@ -103,27 +102,43 @@
 c   initialisations:
 c-----------------------------------------------------------------------
+      pi=4.*atan(1.)
+      pa=20
+      preff=610.
 
       chr2="0"
+      iyear=0
       unanj=669.
-      print*,'WARNING!!!',unanj,'Jours/an'
-      nc=.true.
+      print*,'WARNING!!! Assuming',unanj,'sols/year'
+      
+c-----------------------------------------------------------------------
+c   Viking Lander coordinates:
+c   --------------------------------------------------------------------
+
+      lonvik(1) = lonvik1
+      latvik(1) = latvik1
+      lonvik(2) = lonvik2
+      latvik(2) = latvik2
       
       phivik(1) = phivik1
       phivik(2) = phivik2
       
-      print *, 'COORDVIKIIIN', latvik, lonvik
-      print*, 'LES PHIVIK', phivik
-      
-      
-
-
-
-      WRITE(*,*) 'Chemin des fichiers histoires'
+      WRITE(*,*) 'Viking coordinates:'
+      WRITE(*,*) 'latvik:',latvik,' lonvik:',lonvik
+      WRITE(*,*) 'Phivik:', phivik
+      
+      ! convert coordinates to radians
+      lonvik(1) = lonvik1 * pi/180.
+      latvik(1) = latvik1 * pi/180.
+      lonvik(2) = lonvik2 * pi/180.
+      latvik(2) = latvik2 * pi/180.
+      
+
+      WRITE(*,*) 'Path to the diagfi files directory'
       READ (*,'(a)')  pathchmp
-      WRITE(*,*) 'Chemin des fichiers sorties'
+      WRITE(*,*) 'Path to the dir for outputs'
       READ (*,'(a)')  pathsor
       
-      WRITE(*,*) 'Fichiers de sortie en sol (1) 
-     &,en ls (2) ,les deux (3)'
+      WRITE(*,*) 'Output file time axis in sol (1) '//
+     &'in ls (2) ,or both (3)'
       READ (*,*)  Time_unit
       
@@ -135,5 +150,5 @@
 
 c-----------------------------------------------------------------------
-c   ouverture des fichiers xgraph:
+c   output files:
 c-----------------------------------------------------------------------
       ifile(1)=12
@@ -143,10 +158,10 @@
       
       
-      print*,'Entrer un fichier NC (sans le .nc)'
+      print*,'diagfi file name (without trailing .nc)'
       READ(5,'(a)',err=9999) nomfich
       
 
 c%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
-c   grande boucle sur les fichiers histoire:
+c   loop on the diagfi files:
 c%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
 
@@ -164,14 +179,8 @@
       PRINT*,'timestep ',dtvr
 
-      IF(nc) THEN
       ierr= NF_OPEN(file(1:len_trim(file))//'.nc',NF_NOWRITE,nid)        
-      ELSE
-         PRINT*,'Ouverture binaire ',file
-         OPEN(unitlec,file=file,status='old',form='unformatted',
-     .   iostat=ierr)
-      ENDIF
-
-c----------------------------------------------------------------------
-c   initialisation de la physique:
+
+c----------------------------------------------------------------------
+c   initialise physics:
 c----------------------------------------------------------------------
 
@@ -211,13 +220,4 @@
         
         
-c-----------------------------------------------------------------------
-c   coordonnees des point Viking:
-c   --------------------------------------------------------------------
-
-      lonvik(1) = lonvik1 * pi/180.
-      latvik(1) = latvik1 * pi/180.
-      lonvik(2) = lonvik2 * pi/180.
-      latvik(2) = latvik2 * pi/180.
-      
                     
 c----------------------------------------------------------------------   
@@ -255,5 +255,5 @@
 
 c----------------------------------------------------------------------
-c   altitude reelle et modele aux points Viking
+c   true and model altitude at Viking locations
 c----------------------------------------------------------------------
 
@@ -269,9 +269,9 @@
          ENDDO
       ENDDO
-      PRINT*,'relief aux points Viking pour les sorties:',phivik
+      PRINT*,'phivik at Viking locations for outputs:',phivik
            
 
 c----------------------------------------------------------------------
-c   lectures des etats:
+c   read variables:
 c   -------------------------------------------------------------------
 
@@ -294,9 +294,9 @@
        
 c----------------------------------------------------------------------       
-c   lecture drs des champs:
-c----------------------------------------------------------------------
-
-
-ccccccccc  LECTURE Ps ccccccccccccccccccccccccccc
+c   read fields:
+c----------------------------------------------------------------------
+
+
+ccccccccc  Load Ps ccccccccccccccccccccccccccc
 
 
@@ -314,5 +314,5 @@
           PRINT*,'ps',ps(iip1/2,jjp1/2)
 
-ccccccccc  LECTURE Temperature ccccccccccccccccccccccccccc
+ccccccccc  Load Temperature ccccccccccccccccccccccccccc
 
 
@@ -353,5 +353,5 @@
 
 
-ccccccccc  LECTURE co2ice ccccccccccccccccccccccccccc
+ccccccccc  Load co2ice ccccccccccccccccccccccccccc
 
 
@@ -370,5 +370,5 @@
 
 c----------------------------------------------------------------------
-c Gestion du temps
+c Handle calendar
 c ---------------------------------------------------------------------
 
@@ -376,17 +376,17 @@
           PRINT*,'day ',day
           sol=day+day0
-          iyear=sol/unanj
-          WRITE (*,*) 'iyear',iyear
-          sol=sol-iyear*unanj
-
-c----------------------------------------------------------------------
-c Ouverture / fermeture des fichiers
+          do while (sol.gt.unanj)
+            sol=sol-unanj
+          enddo
+          WRITE (*,*) 'sol: ',sol,' iyear:',iyear
+
+c----------------------------------------------------------------------
+c Open /close files
 c ---------------------------------------------------------------------
 
           IF (iyear.NE.kyear) THEN
              WRITE(chr2(1:1),'(i1)') iyear+1
-             WRITE (*,*) 'iyear bis',iyear
-             WRITE (*,*) 'chr2'
-             WRITE (*,*)  chr2
+             WRITE (*,*) 'iyear bis:',iyear
+             WRITE (*,*) 'chr2:',trim(chr2)
              IF(iyear.GE.9) WRITE(chr2,'(i2)') iyear+1
              kyear=iyear
@@ -417,5 +417,5 @@
           
 c----------------------------------------------------------------------
-c Calcul de la moyenne de pression planetaire
+c Compute average planetary pressure
 c ---------------------------------------------------------------------
 
@@ -442,5 +442,5 @@
 
 
-c --------------Ecriture fichier sortie xprestot----------------------- 
+c --------------Write output file xprestot----------------------- 
 c  Sol ou ls ou les deux 
 c  Ps_moy_planetaire (Pa)
@@ -465,10 +465,9 @@
 
 c----------------------------------------------------------------------
-c boucle sur les sites vikings:
-c----------------------------------------------------------------------
-
-c----------------------------------------------------------------------
-c interpolation de la temperature dans la 7eme couche, de la pression
-c de surface et des vents aux points viking.
+c Loop on Viking sites:
+c----------------------------------------------------------------------
+
+c----------------------------------------------------------------------
+c interapolate using temperature in the 7th layer, of surface pressure
 c----------------------------------------------------------------------
 
@@ -491,5 +490,5 @@
                    zt=zt+zw(ii,jj,iv)*t7(i,j)
                    zp1=zp1+zw(ii,jj,iv)*log(ps(i,j)) ! interpolate in log(P)
-                   WRITE (*,*) 'ps autour iv',ps(i,j),iv
+                   WRITE (*,*) 'ps around iv',ps(i,j),iv
 
                 ENDDO
@@ -502,5 +501,5 @@
              
 c---------------------------------------------------------------------- 
-c  pression au sol extrapolee a partir de la temp. 7eme couche
+c  surface pressure extrapolated using temp. from 7th atmospheric layer
 c----------------------------------------------------------------------
            
@@ -514,10 +513,11 @@
           WRITE (*,*) 'iv,pstot,zp2, zp1, phivik(iv),phisim(iv),gh'
           WRITE (*,*) iv,pstot*airtot1,zp2,zp1,phivik(iv),phisim(iv),gh
+          WRITE(*,*) "------"
              
 
-c ------Ecriture 2 fichiers (1 pour Vl1, 1 pour VL2) sortie xpsol ------
-c  Sol ou ls ou les deux
-c  Ps site VLi (i=1,2) a  l'altitude GCM (Pa)
-c  Ps site VLi (i=1,2) a  l'altitude exacte  (interpolee) (Pa)
+c ------Write 2 files (1 for Vl1, 1 for VL2) xpsol ------
+c  Sol or ls or both
+c  Ps site VLi (i=1,2) at GCM altitude (Pa)
+c  Ps site VLi (i=1,2) at true (interpolated) altitude (Pa)
               
              IF(Time_unit == 1) THEN
@@ -537,25 +537,31 @@
 
 c======================================================================
-c   Fin de la boucle sur les etats du fichier histoire:
+c   End of loop of variables in the diagfi file
 c======================================================================
 
+       if (sol.ge.unanj-1.e-5) then 
+         ! end of year reached (with some roundoff margin)
+         ! increment iyear
+         iyear=iyear+1
+       endif
+
       ENDDO
 
       ierr= NF_CLOSE(nid)
 
-      PRINT*,'Fin du fichier',nomfich
-      print*,'Entrer un nouveau fichier NC 
-     &(sans le .nc) ou return pour finir'
+      PRINT*,'End of file',nomfich
+      print*,'Entrer new file name (without trailing .nc)', 
+     &" or return to end"
       READ(5,'(a)',err=9999) nomfich
 
 
 c%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
-c   Fin de la boucle sur les fichiers histoire:
+c   End of loop on the diagfi files
 c%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
 
       ENDDO
 
-      PRINT*,'relief du point V1',.001*phis(ivik(1),jvik(1))/g
-      PRINT*,'relief du point V2',.001*phis(ivik(2),jvik(2))/g
+      PRINT*,'altitude of VL1',.001*phis(ivik(1),jvik(1))/g
+      PRINT*,'altitude of VL2',.001*phis(ivik(2),jvik(2))/g
       DO iv=1,2
          PRINT*,'Viking',iv,'   i=',ivik(iv),'j  =',jvik(iv)
@@ -570,8 +576,8 @@
          print*,'zw'
          write(6,'(2(2f10.4/))') ((zw(ii,jj,iv),ii=0,1),jj=0,1)
-         print*,'altitude interpolee (km) ',phisim(iv)/1000./g
+         print*,'interpolated altitude (km) ',phisim(iv)/1000./g
       ENDDO
       PRINT*,'R=',r
- 9999  PRINT*,'Fin '
+ 9999  PRINT*,'End '
 
 7777  FORMAT ('latitude/longitude',4f7.1)
@@ -659,5 +665,5 @@
 !==============================================================================
 
-count_years=0 ! initialize
+      count_years=0 ! initialize
       zz=sol  ! use "zz" to store (and work on) the value of sol
       do while (zz.ge.year_day)
