Index: /trunk/LMDZ.MARS/util/concatnc.F90
===================================================================
--- /trunk/LMDZ.MARS/util/concatnc.F90	(revision 1072)
+++ /trunk/LMDZ.MARS/util/concatnc.F90	(revision 1073)
@@ -18,4 +18,5 @@
 ! + handle absence of ap() and bp() if aps and bps are available 
 !    (case of stats file) FF, November 2011
+! + read and write controle field, if available. TN, October 2013
 ! ********************************************************
 
@@ -54,8 +55,9 @@
 ! memolonlen: # of elements of lon(), read from the first input file
 ! memoaltlen: # of elements of alt(), read from the first input file
-real, dimension(:), allocatable:: lat,lon,alt,time
+real, dimension(:), allocatable:: lat,lon,alt,ctl,time
 ! lat(): array, stores latitude coordinates
 ! lon(): array, stores longitude coordinates
 ! alt(): array, stores altitude coordinates
+! ctl(): array, stores controle coordinates
 ! time(): array, stores time coordinates
 integer :: nbvar,nbfile,nbvarfile,ndim
@@ -64,19 +66,22 @@
 ! nbvarfile: total # of variables in an input file
 ! ndim: [netcdf] # (3 or 4) of dimensions (for variables)
-integer :: latdim,londim,altdim,timedim
+integer :: latdim,londim,altdim,ctldim,timedim
 ! latdim: [netcdf] "latitude" dim ID
 ! londim: [netcdf] "longitude" dim ID
 ! altdim: [netcdf] "altdim" dim ID
+! ctldim: [netcdf] "ctldim" dim ID
 ! timedim: [netcdf] "timedim" dim ID
 integer :: gcmlayerdim ! NetCDF dimension ID for # of layers in GCM
-integer :: latvar,lonvar,altvar,timevar
+integer :: latvar,lonvar,altvar,ctlvar,timevar
 ! latvar: [netcdf] ID of "latitude" variable
 ! lonvar: [netcdf] ID of "longitude" variable
 ! altvar: [netcdf] ID of "altitude" variable
+! ctlvar: [netcdf] ID of "controle" variable
 ! timevar: [netcdf] ID of "Time" variable
-integer :: latlen,lonlen,altlen,timelen
+integer :: latlen,lonlen,altlen,ctllen,timelen
 ! latlen: # of elements of lat() array
 ! lonlen: # of elements of lon() array
-! altvar: # of elements of alt() array
+! altlen: # of elements of alt() array
+! ctllen: # of elements of ctl() array
 ! timelen: # of elemnets of time() array
 integer :: GCM_layers ! number of GCM atmospheric layers (may not be
@@ -141,4 +146,5 @@
 !write(*,*) "Beginning day of the first specified file?"
 write(*,*) "Starting day of the run stored in the first input file?"
+write(*,*) " (Obsolete if the controle field is present, answer any number)"
 write(*,*) "(e.g.: 100 if that run started at time=100 sols)"
 read(*,*) memotime
@@ -320,4 +326,15 @@
 !  write(*,*) "altlen: ",altlen
 
+   ierr=NF_INQ_DIMID(nid,"index",ctldim)
+   ierr=NF_INQ_VARID(nid,"controle",ctlvar)
+   if (ierr.NE.NF_NOERR) then
+      write(*,*) 'Field <controle> is missing in file'//file
+      ctllen=0
+      !stop ""
+   else
+      ierr=NF_INQ_DIMLEN(nid,ctldim,ctllen)
+   endif
+!  write(*,*) "controle: ",controle
+
 ! load size of aps() or sigma() (in case it is not altlen)
    ! default is that GCM_layers=altlen
@@ -345,15 +362,26 @@
       allocate(lon(lonlen))
       allocate(alt(altlen))
+      allocate(ctl(ctllen))
 #ifdef NC_DOUBLE
       ierr = NF_GET_VAR_DOUBLE(nid,latvar,lat)
       ierr = NF_GET_VAR_DOUBLE(nid,lonvar,lon)
       ierr = NF_GET_VAR_DOUBLE(nid,altvar,alt)
+      if (ctllen .ne. -1) ierr = NF_GET_VAR_DOUBLE(nid,ctlvar,ctl)
 #else
       ierr = NF_GET_VAR_REAL(nid,latvar,lat)
       ierr = NF_GET_VAR_REAL(nid,lonvar,lon)
       ierr = NF_GET_VAR_REAL(nid,altvar,alt)
-#endif
+      if (ctllen .ne. -1) ierr = NF_GET_VAR_REAL(nid,ctlvar,ctl)
+#endif
+      if (ctllen .ne. -1) then
+         if (modulo(int(memotime),669)/=modulo(int(ctl(4)),669)) then
+           write(*,'(2(A,I4),A)') "WARNING: Starting day of the run is not ",&
+                                modulo(int(memotime),669)," but ",modulo(int(ctl(4)),669),"!!"
+           write(*,*) "Starting day of the run has been corrected."
+           memotime=float(modulo(int(ctl(4)),669))
+         endif
+      endif
    ! Initialize output file's lat,lon,alt and time dimensions
-      call initiate (filename,lat,lon,alt,GCM_layers,nout,&
+      call initiate (filename,lat,lon,alt,ctl,GCM_layers,nout,&
        latdimout,londimout,altdimout,timedimout,&
        layerdimout,interlayerdimout,timevarout)
@@ -570,5 +598,5 @@
 
 !******************************************************************************
-subroutine initiate (filename,lat,lon,alt,GCM_layers,nout,&
+subroutine initiate (filename,lat,lon,alt,ctl,GCM_layers,nout,&
          latdimout,londimout,altdimout,timedimout,&
          layerdimout,interlayerdimout,timevarout)
@@ -596,4 +624,6 @@
 real, dimension(:), intent(in):: alt
 ! alt(): altitude
+real, dimension(:), intent(in):: ctl
+! ctl(): controle
 integer,intent(in) :: GCM_layers ! number of GCM layers
 integer, intent(out):: nout
@@ -619,4 +649,5 @@
 !integer :: latdim,londim,altdim,timedim
 integer :: nvarid,ierr
+integer :: ctldimout
 ! nvarid: [netcdf] ID of a variable
 ! ierr: [netcdf]  return error code (from called subroutines)
@@ -640,4 +671,5 @@
 ierr = NF_DEF_DIM(nout, "longitude", size(lon), londimout)
 ierr = NF_DEF_DIM(nout, "altitude", size(alt), altdimout)
+if (size(ctl).ne.0) ierr = NF_DEF_DIM(nout, "index", size(ctl), ctldimout)
 ierr = NF_DEF_DIM(nout, "Time", NF_UNLIMITED, timedimout)
 ierr = NF_DEF_DIM(nout, "GCM_layers", GCM_layers, layerdimout)
@@ -681,5 +713,5 @@
 
 !==============================================================================
-! 4. Write "altitude" (data and attributes)
+! 5. Write "altitude" (data and attributes)
 !==============================================================================
 
@@ -704,5 +736,31 @@
 #else
 ierr = NF_PUT_VAR_REAL (nout,nvarid,alt)
-#endif 
+#endif
+
+!==============================================================================
+! 6. Write "controle" (data and attributes)
+!==============================================================================
+
+if (size(ctl).ne.0) then
+   ! Switch to netcdf define mode
+   ierr = NF_REDEF (nout)
+
+   #ifdef NC_DOUBLE
+   ierr = NF_DEF_VAR (nout,"controle",NF_DOUBLE,1,ctldimout,nvarid)
+   #else
+   ierr = NF_DEF_VAR (nout,"controle",NF_FLOAT,1,ctldimout,nvarid)
+   #endif
+
+   ierr = NF_PUT_ATT_TEXT (nout,nvarid,"title",18,"Control parameters")
+
+   ! End netcdf define mode
+   ierr = NF_ENDDEF(nout)
+
+   #ifdef NC_DOUBLE
+   ierr = NF_PUT_VAR_DOUBLE (nout,nvarid,ctl)
+   #else
+   ierr = NF_PUT_VAR_REAL (nout,nvarid,ctl)
+   #endif
+endif
 
 end Subroutine initiate
@@ -1162,9 +1220,9 @@
 do i=1,timelen-1
    if ((ls(i+1)-ls(i)) > 350) then
-       write(*,*) "+ 360° Ls jump solved:", ls(i), ls(i+1), "at timestep", i
+       write(*,*) "+ 360 deg Ls jump solved:", ls(i), ls(i+1), "at timestep", i
       ls(i+1) = ls(i+1) - 360
        write(*,*) " corrected to now be:", ls(i), ls(i+1)
    else if ((ls(i)-ls(i+1)) > 350) then
-       write(*,*) "- 360° Ls jump solved:", ls(i), ls(i+1), "at timestep", i
+       write(*,*) "- 360 deg Ls jump solved:", ls(i), ls(i+1), "at timestep", i
       ls(i+1) = ls(i+1) + 360
        write(*,*) " corrected to now be:", ls(i), ls(i+1)
Index: /trunk/LMDZ.MARS/util/localtime.F90
===================================================================
--- /trunk/LMDZ.MARS/util/localtime.F90	(revision 1072)
+++ /trunk/LMDZ.MARS/util/localtime.F90	(revision 1073)
@@ -35,8 +35,9 @@
 integer :: varid
 ! varid: [netcdf] variable ID #
-real, dimension(:), allocatable:: lat,lon,alt,time
+real, dimension(:), allocatable:: lat,lon,alt,ctl,time
 ! lat(): array, stores latitude coordinates
 ! lon(): array, stores longitude coordinates
 ! alt(): array, stores altitude coordinates
+! ctl(): array, stores controle array
 ! time(): array, stores time coordinates
 integer :: nbvar,nbvarfile,ndim
@@ -45,19 +46,22 @@
 ! nbvarfile: total # of variables in an input file
 ! ndim: [netcdf] # (3 or 4) of dimensions (for variables)
-integer :: latdim,londim,altdim,timedim
+integer :: latdim,londim,altdim,ctldim,timedim
 ! latdim: [netcdf] "latitude" dim ID
 ! londim: [netcdf] "longitude" dim ID
 ! altdim: [netcdf] "altdim" dim ID
+! ctldim: [netcdf] "controle" dim ID
 ! timedim: [netcdf] "timedim" dim ID
-integer :: latvar,lonvar,altvar,timevar
+integer :: latvar,lonvar,altvar,ctlvar,timevar
 ! latvar: [netcdf] ID of "latitude" variable
 ! lonvar: [netcdf] ID of "longitude" variable
 ! altvar: [netcdf] ID of "altitude" variable
+! ctlvar: [netcdf] ID of "controle" variable
 ! timevar: [netcdf] ID of "Time" variable
-integer :: latlen,lonlen,altlen,timelen,timelen_lt,timelen_tot
+integer :: latlen,lonlen,altlen,ctllen,timelen,timelen_lt,timelen_tot
 integer :: ilat,ilon,ialt,it
 ! latlen: # of elements of lat() array
 ! lonlen: # of elements of lon() array
 ! altvar: # of elements of alt() array
+! ctlvar: # of elements of ctl() array
 ! timelen: # of elemnets of time() array
 ! timelen_tot:# =timelen or timelen+1 (if 1 more time to interpolate needed)
@@ -246,4 +250,15 @@
 !  write(*,*) "altlen: ",altlen
 
+   ierr=NF_INQ_DIMID(nid,"index",ctldim)
+   ierr=NF_INQ_VARID(nid,"controle",ctlvar)
+   if (ierr.NE.NF_NOERR) then
+      write(*,*) 'Field <controle> is missing in file'//file
+      ctllen=0
+      !stop ""
+   else
+      ierr=NF_INQ_DIMLEN(nid,ctldim,ctllen)
+   endif
+!  write(*,*) "controle: ",controle
+
 !==============================================================================
 ! 2.3. Read (and check compatibility of) dimensions of
@@ -255,12 +270,15 @@
       allocate(lon(lonlen))
       allocate(alt(altlen))
+      allocate(ctl(ctllen))
 #ifdef NC_DOUBLE
       ierr = NF_GET_VAR_DOUBLE(nid,latvar,lat)
       ierr = NF_GET_VAR_DOUBLE(nid,lonvar,lon)
       ierr = NF_GET_VAR_DOUBLE(nid,altvar,alt)
+      if (ctllen .ne. -1) ierr = NF_GET_VAR_DOUBLE(nid,ctlvar,ctl)
 #else
       ierr = NF_GET_VAR_REAL(nid,latvar,lat)
       ierr = NF_GET_VAR_REAL(nid,lonvar,lon)
       ierr = NF_GET_VAR_REAL(nid,altvar,alt)
+      if (ctllen .ne. -1) ierr = NF_GET_VAR_REAL(nid,ctlvar,ctl)
 #endif
 !==============================================================================
@@ -351,5 +369,5 @@
 
    ! Initialize output file's lat,lon,alt and time dimensions
-      call initiate (filename,lat,lon,alt,nout,&
+      call initiate (filename,lat,lon,alt,ctl,nout,&
            latdimout,londimout,altdimout,timedimout,timevarout)
    ! Initialize output file's aps,bps and phisinit variables
@@ -561,5 +579,5 @@
 
 !******************************************************************************
-Subroutine initiate (filename,lat,lon,alt,&
+Subroutine initiate (filename,lat,lon,alt,ctl,&
                      nout,latdimout,londimout,altdimout,timedimout,timevarout)
 !==============================================================================
@@ -586,4 +604,6 @@
 real, dimension(:), intent(in):: alt
 ! alt(): altitude
+real, dimension(:), intent(in):: ctl
+! ctl(): controle
 integer, intent(out):: nout
 ! nout: [netcdf] file ID
@@ -604,4 +624,5 @@
 !integer :: latdim,londim,altdim,timedim
 integer :: nvarid,ierr
+integer :: ctldimout
 ! nvarid: [netcdf] ID of a variable
 ! ierr: [netcdf]  return error code (from called subroutines)
@@ -625,4 +646,5 @@
 ierr = NF_DEF_DIM(nout, "longitude", size(lon), londimout)
 ierr = NF_DEF_DIM(nout, "altitude", size(alt), altdimout)
+if (size(ctl).ne.0) ierr = NF_DEF_DIM(nout, "index", size(ctl), ctldimout)
 ierr = NF_DEF_DIM(nout, "Time", NF_UNLIMITED, timedimout)
 
@@ -664,5 +686,5 @@
 
 !==============================================================================
-! 4. Write "altitude" (data and attributes)
+! 5. Write "altitude" (data and attributes)
 !==============================================================================
 
@@ -688,4 +710,30 @@
 ierr = NF_PUT_VAR_REAL (nout,nvarid,alt)
 #endif 
+
+!==============================================================================
+! 6. Write "controle" (data and attributes)
+!==============================================================================
+
+if (size(ctl).ne.0) then
+   ! Switch to netcdf define mode
+   ierr = NF_REDEF (nout)
+
+   #ifdef NC_DOUBLE
+   ierr = NF_DEF_VAR (nout,"controle",NF_DOUBLE,1,ctldimout,nvarid)
+   #else
+   ierr = NF_DEF_VAR (nout,"controle",NF_FLOAT,1,ctldimout,nvarid)
+   #endif
+
+   ierr = NF_PUT_ATT_TEXT (nout,nvarid,"title",18,"Control parameters")
+
+   ! End netcdf define mode
+   ierr = NF_ENDDEF(nout)
+
+   #ifdef NC_DOUBLE
+   ierr = NF_PUT_VAR_DOUBLE (nout,nvarid,ctl)
+   #else
+   ierr = NF_PUT_VAR_REAL (nout,nvarid,ctl)
+   #endif
+endif
 
 end Subroutine initiate
Index: /trunk/LMDZ.MARS/util/lslin.F90
===================================================================
--- /trunk/LMDZ.MARS/util/lslin.F90	(revision 1072)
+++ /trunk/LMDZ.MARS/util/lslin.F90	(revision 1073)
@@ -10,4 +10,6 @@
 ! Modified by Ehouarn Millour 10/2007 (changed evaluation of 'start_var'
 ! from hard-coded values to a computed value) 
+! Read controle field, if available TN, October 2013
+
 
 implicit none
@@ -109,8 +111,10 @@
 read(*,'(a50)') infile 
 
-write(*,*) "Is it a concatnc file? (y/n)?"
+!write(*,*) "Is it a concatnc file? (y/n)?"
+write(*,*) "Do you want to specify the beginning day of the file"
+write(*,*) "in case the controle field is not present ? (y/n)?"
 read(*,*) answer
 if ((answer=="y").or.(answer=="Y")) then
-   write(*,*) "Beginning day of the concatnc file?"
+   write(*,*) "Beginning day of the file?"
    read(*,*) reptime 
 !   start_var=8 ! 'concatnc' type of file
@@ -311,5 +315,6 @@
    endif
 
-   day_ini = tab_cntrl(4)                                                     
+   day_ini = tab_cntrl(4)                                               
+   day_ini = modulo(day_ini,669)                                                    
    write(*,*) 'day_ini', day_ini
 else
Index: /trunk/LMDZ.MARS/util/zrecast.F90
===================================================================
--- /trunk/LMDZ.MARS/util/zrecast.F90	(revision 1072)
+++ /trunk/LMDZ.MARS/util/zrecast.F90	(revision 1073)
@@ -60,4 +60,5 @@
 !              constants (radius, R, etc.) are now read from file
 ! TN 01/2013 : Adapted for large output files with at least 2 variables > 2 GiB
+! TN 10/2013 : Read and write controle field, if available
 !
 implicit none
@@ -80,6 +81,6 @@
 integer nbvar4dinfile ! # of 4D (lon,lat,alt,time) variables in input file
 integer outfid ! NetCDF output file ID
-integer lon_dimid,lat_dimid,alt_dimid,time_dimid ! NetCDF dimension IDs
-integer lon_varid,lat_varid,alt_varid,time_varid
+integer lon_dimid,lat_dimid,alt_dimid,time_dimid,ctl_dimid ! NetCDF dimension IDs
+integer lon_varid,lat_varid,alt_varid,time_varid,ctl_varid
 integer gcm_layers_dimid ! NetCDF dimension ID for # of layers in GCM
 integer sigma_varid,aps_varid,bps_varid
@@ -103,4 +104,6 @@
 integer latlength ! # of grid points along latitude
 integer altlength ! # of grid point along altitude (of input datasets)
+real,dimension(:),allocatable :: ctl ! controle
+integer ctllength ! # of grid points along controle
 real,dimension(:),allocatable :: time ! time
 integer timelength ! # of points along time
@@ -439,4 +442,32 @@
   if (ierr.ne.NF_NOERR) then
       stop "Error: Failed to get altitude length"
+  endif
+endif
+
+! controle
+ierr=NF_INQ_DIMID(infid,"index",tmpdimid)
+if (ierr.ne.NF_NOERR) then
+  write(*,*) "Could not get controle dimension ID"
+  ctllength = 0
+else
+  ierr=NF_INQ_VARID(infid,"controle",tmpvarid)
+  if (ierr.ne.NF_NOERR) then
+    stop "Error: Failed to get controle ID"
+  else
+    ierr=NF_INQ_DIMLEN(infid,tmpdimid,ctllength)
+    if (ierr.ne.NF_NOERR) then
+      stop "Error: Failed to get controle length"
+    else
+      allocate(ctl(ctllength),stat=ierr)
+      if (ierr.ne.0) then
+        write(*,*) "Error: Failed to allocate ctl(ctllength)"
+        write(*,*) "     ctllength=",ctllength
+        stop
+      endif
+      ierr=NF_GET_VAR_REAL(infid,tmpvarid,ctl)
+      if (ierr.ne.NF_NOERR) then
+        stop "Error: Failed reading controle"
+      endif
+    endif
   endif
 endif
@@ -1030,4 +1061,14 @@
 endif
 
+! controle
+if (ctllength .ne. 0) then
+  ierr=NF_DEF_DIM(outfid,"index",ctllength,ctl_dimid)
+  if (ierr.ne.NF_NOERR) then
+    write(*,*) "Error: Could not define controle dimension"
+    write(*,*) NF_STRERROR(ierr)
+    stop
+  endif
+endif
+
 ! GCM layers (for sigma or aps and bps)
 ierr=NF_DEF_DIM(outfid,"GCM_layers",altlength,gcm_layers_dimid)
@@ -1162,4 +1203,21 @@
   endif
 endif ! of if (have_sigma)
+
+! controle
+if (ctllength .ne. 0) then
+  ierr=NF_DEF_VAR(outfid,"controle",NF_REAL,1,ctl_dimid,ctl_varid)
+  if (ierr.ne.NF_NOERR) then
+    write(*,*) "Error: Could not define controle variable"
+    write(*,*) NF_STRERROR(ierr)
+    stop
+  endif
+
+  ! controle attributes
+  text='Control parameters'
+  ierr=NF_PUT_ATT_TEXT(outfid,ctl_varid,'title',len_trim(text),text)
+  if (ierr.ne.NF_NOERR) then
+    stop "Error: Problem writing title for controle"
+  endif
+endif
 
 ! GCM_layers
@@ -1509,4 +1567,14 @@
 endif
 
+! Write controle
+if (ctllength .ne. 0) then
+  ierr=NF_PUT_VAR_REAL(outfid,ctl_varid,ctl)
+  if (ierr.ne.NF_NOERR) then
+    write(*,*) "Error: Could not write controle data to output file"
+    write(*,*) NF_STRERROR(ierr)
+    stop
+  endif
+endif
+
 ! Write time
 ierr=NF_PUT_VARA_REAL(outfid,time_varid,1,timelength,time)
@@ -1771,5 +1839,5 @@
 subroutine init_planet_const(infid)
 ! initialize planetary constants using the "controle" array in the file
-! if "cointrole" array not found in file, look for it in "diagfi.nc"
+! if "controle" array not found in file, look for it in "diagfi.nc"
 use planet_const
 use netcdf
