Index: trunk/LMDZ.MARS/util/concatnc.F90
===================================================================
--- trunk/LMDZ.MARS/util/concatnc.F90	(revision 2590)
+++ trunk/LMDZ.MARS/util/concatnc.F90	(revision 3077)
@@ -30,6 +30,6 @@
 character (len=100), dimension(1000) :: file
 ! file(): input file(s) names(s)
-character (len=30), dimension(16) :: notconcat
-! notconcat(): names of the (16) variables that won't be concatenated
+character (len=30), dimension(24) :: notconcat
+! notconcat(): names of the (24) variables that won't be concatenated
 character (len=100), dimension(:), allocatable :: var
 ! var(): name(s) of variable(s) that will be concatenated
@@ -131,5 +131,4 @@
 ! valid_range(2): [netcdf] interval in which a value is considered valid
 real :: year_day = 669.
-integer :: XIOS =0
 
 !==============================================================================
@@ -220,5 +219,13 @@
 notconcat(15)='phisinit'
 notconcat(16)='soildepth'
-
+! for XIOS files:
+notconcat(17)='lat'
+notconcat(18)='lon'
+notconcat(19)='time_instant'
+notconcat(20)='time_instant_bounds'
+notconcat(21)='time_counter'
+notconcat(22)='time_counter_bounds'
+notconcat(23)='area'
+notconcat(24)='phisfi'
 
 !==============================================================================
@@ -314,5 +321,5 @@
       ierr = NF_OPEN(file(i),NF_NOWRITE,nid)
       if (ierr.NE.NF_NOERR) then
-         write(*,*) 'ERROR: Pb opening file '//file(i)
+         write(*,*) 'ERROR: Pb opening file '//trim(file(i))
          write(*,*) NF_STRERROR(ierr)
          stop
@@ -329,42 +336,33 @@
    ierr=NF_INQ_VARID(nid,"latitude",latvar)
    if (ierr.NE.NF_NOERR) then
+     !failed to find "latitude"; look for "lat" instead
      ierr=NF_INQ_DIMID(nid,"lat",latdim)
      ierr=NF_INQ_VARID(nid,"lat",latvar)
-     if (ierr.EQ.NF_NOERR) then
-        write(*,*) 'XIOS concat spotted'
-        XIOS=1
-     endif
    endif  
    if (ierr.NE.NF_NOERR) then
-      write(*,*) 'ERROR: Field <latitude> or <lat> is missing in file '//file(i)
-      stop  
+     write(*,*) 'ERROR: Neither <latitude> nor <lat> in file '//trim(file(i))
+     stop  
    endif
    ierr=NF_INQ_DIMLEN(nid,latdim,latlen)
 !  write(*,*) "latlen: ",latlen
 
-   if (XIOS.EQ.0) then
-       ierr=NF_INQ_DIMID(nid,"longitude",londim)
-       ierr=NF_INQ_VARID(nid,"longitude",lonvar)
-       if (ierr.NE.NF_NOERR) then
-          write(*,*) 'ERROR: Field <longitude> is missing in file '//file(i)
-          stop 
-       endif
-       ierr=NF_INQ_DIMLEN(nid,londim,lonlen)
-       !  write(*,*) "lonlen: ",lonlen
-   else
-       ierr=NF_INQ_DIMID(nid,"lon",londim)
-       ierr=NF_INQ_VARID(nid,"lon",lonvar)
-       if (ierr.NE.NF_NOERR) then
-          write(*,*) 'ERROR: Field <lon> is missing in file '//file(i)
-          stop 
-       endif
-       ierr=NF_INQ_DIMLEN(nid,londim,lonlen)
-       !  write(*,*) "lonlen: ",lonlen
+   ierr=NF_INQ_DIMID(nid,"longitude",londim)
+   ierr=NF_INQ_VARID(nid,"longitude",lonvar)
+   if (ierr.NE.NF_NOERR) then
+     ! failed to find "longitude"; look for "lon" instead
+     ierr=NF_INQ_DIMID(nid,"lon",londim)
+     ierr=NF_INQ_VARID(nid,"lon",lonvar)
    endif
+   if (ierr.NE.NF_NOERR) then
+     write(*,*) 'ERROR: Neither <longitude> nor <lon> in file '//trim(file(i))
+     stop 
+   endif
+   ierr=NF_INQ_DIMLEN(nid,londim,lonlen)
+   !  write(*,*) "lonlen: ",lonlen
 
    ierr=NF_INQ_DIMID(nid,"altitude",altdim)
    ierr=NF_INQ_VARID(nid,"altitude",altvar)
    if (ierr.NE.NF_NOERR) then
-      write(*,*) 'ERROR: Field <altitude> is missing in file '//file(i)
+      write(*,*) 'ERROR: Field <altitude> is missing in file '//trim(file(i))
       stop
    endif
@@ -388,77 +386,63 @@
 ! 2.2.1 Check presence and read "controle" dimension & variable from input file
 !==============================================================================
-   if (XIOS.EQ.0) then
-        ierr=NF_INQ_DIMID(nid,"index",ctldim)
-        if (ierr.NE.NF_NOERR) then
-          write(*,*) 'Dimension <index> is missing in file '//file(i)
-          write(*,*) "The program continues..."
-          ctllen=0
-          !stop
-       else
-          ierr=NF_INQ_VARID(nid,"controle",ctlvar)
-          if (ierr.NE.NF_NOERR) then
-            write(*,*) 'Field <controle> is missing in file '//file(i)
-            write(*,*) "The program continues..."
-            ctllen=0
-            !stop
-          else
-            ierr=NF_INQ_DIMLEN(nid,ctldim,ctllen)
-          endif
-       endif
-   else
+
+   ctllen=-666 ! dummy initialization
+   ierr=NF_INQ_DIMID(nid,"index",ctldim)
+   if (ierr.NE.NF_NOERR) then
+     ctllen=0
+     ! no "index", look for "controle_axe" instead
      ierr=NF_INQ_DIMID(nid,"controle_axe",ctldim)
      if (ierr.NE.NF_NOERR) then
-       write(*,*) 'Dimension <controle_axe> is missing in file '//file(i)
-       write(*,*) "The program continues..."
+       write(*,*) 'Neither <index> nor <controle_axe> in file '//trim(file(i))
+       write(*,*) "The program continues without <controle>..."
        ctllen=0
-       !stop
      else
-       ierr=NF_INQ_VARID(nid,"controle",ctlvar)
-       if (ierr.NE.NF_NOERR) then
-          write(*,*) 'Field <controle> is missing in file '//file(i)
-           write(*,*) "The program continues..."
-          ctllen=0
-          !stop
-        else
-          ierr=NF_INQ_DIMLEN(nid,ctldim,ctllen)
-       endif
+       ierr=NF_INQ_DIMLEN(nid,ctldim,ctllen)
+     endif
+   else
+     ierr=NF_INQ_DIMLEN(nid,ctldim,ctllen)
+   endif
+
+   ! allocate ctl (even if ctllen==0; required to not trigger errors in debug
+   !  mode when ctl is passed as an argument to routines)
+   allocate(ctl(ctllen))
+
+   if (ctllen .ne. 0) then ! variable controle available
+     ierr=NF_INQ_VARID(nid,"controle",ctlvar)
+     if (ierr.NE.NF_NOERR) then
+       write(*,*) 'Field <controle> is missing in file '//trim(file(i))
+       write(*,*) "The program continues without <controle>..."
+       ctllen=0 ! seting that implies there is no "controle" later on
+     else
+      ierr = NF_GET_VAR_REAL(nid,ctlvar,ctl)
+      ctlsol = ctl(4)
      endif
    endif
 
-   if (ctllen .ne. 0) then ! variable controle
-      allocate(ctl(ctllen))
-      ierr = NF_GET_VAR_REAL(nid,ctlvar,ctl)
-      ctlsol = ctl(4)
-   endif
-
 !==============================================================================
 ! 2.3 Read "Time" dimension & variable from input file
 !==============================================================================
-   if (XIOS.EQ.0) then
+
    ierr=NF_INQ_DIMID(nid,"Time",timedim)
    if (ierr.NE.NF_NOERR) then
-      write(*,*) 'ERROR: Dimension <Time> is missing in file '//file(i)
-      stop
+     ! Time not found, look for "time_counter" instead
+     ierr=NF_INQ_DIMID(nid,"time_counter",timedim)
+     if (ierr.NE.NF_NOERR) then
+       write(*,*) 'ERROR: Neither <Time> nor <time_counter> dim in file '//trim(file(i))
+       stop
+     endif
    endif
+
+   ierr=NF_INQ_DIMLEN(nid,timedim,timelen)
+!  write(*,*) "timelen: ",timelen
+
    ierr=NF_INQ_VARID(nid,"Time",timevar)
    if (ierr.NE.NF_NOERR) then
-      write(*,*) 'ERROR: Field <Time> is missing in file '//file(i)
-      stop
-   endif
-   ierr=NF_INQ_DIMLEN(nid,timedim,timelen)
-!  write(*,*) "timelen: ",timelen
-   else
-   ierr=NF_INQ_DIMID(nid,"time_counter",timedim)
-   if (ierr.NE.NF_NOERR) then
-      write(*,*) 'ERROR: Dimension <time_counter> is missing in file '//file(i)
-      stop
-   endif
-   ierr=NF_INQ_VARID(nid,"time_counter",timevar)
-   if (ierr.NE.NF_NOERR) then
-      write(*,*) 'ERROR: Field <time_counter> is missing in file '//file(i)
-      stop
-   endif
-   ierr=NF_INQ_DIMLEN(nid,timedim,timelen)
-!  write(*,*) "timelen: ",timelen
+     ! "Time" not found, look for "time_counter" instead
+     ierr=NF_INQ_VARID(nid,"time_counter",timevar)
+     if (ierr.NE.NF_NOERR) then
+       write(*,*) 'ERROR: Neither <Time> nor <time_counter> in file '//trim(file(i))
+       stop
+     endif
    endif
 
@@ -568,9 +552,12 @@
 !         correction if the file to concatenate seems "before" previous file
 !         (for instance to concatenate diagfi from the previous year at the enf of a year)
-          print *, "time(rep)", time(rep), rep
-          print *, "ctlsol", ctlsol
-          print *, "starttimeoffset", starttimeoffset
-          print *, "output_time", output_time
-          print *, "previous_last_output_time", previous_last_output_time
+          if (rep.eq.1) then ! only print these checks once
+            print *, "time(rep=1)", time(rep)
+            print *, "ctlsol", ctlsol
+            print *, "starttimeoffset", starttimeoffset
+            print *, "output_time", output_time
+            print *, "previous_last_output_time", previous_last_output_time
+            write(*,*)
+          endif
           do while (output_time.lt.previous_last_output_time)  
                    output_time = output_time + year_day
@@ -717,6 +704,6 @@
    reptime=reptime+timelen
 
-   ! Deallocate controle if needed
-   if (ctllen.ne.0) deallocate(ctl)
+   ! Deallocate controle (is allocated and possibly read for each input file)
+   deallocate(ctl)
 
    ! Close input file
@@ -1054,5 +1041,17 @@
 if (ierr.ne.NF_NOERR) then
   write(*,*)"init2 warning: Failed to get aire ID."
-  area = .false.
+  ! try "area" instead of "aire"
+  ierr=NF_INQ_VARID(infid,"area",tmpvarid)
+  if (ierr.ne.NF_NOERR) then
+    write(*,*)"init2 warning: Failed to get area ID."
+    area = .false.
+  else
+    ierr=NF_GET_VAR_REAL(infid,tmpvarid,aire)
+    if (ierr.ne.NF_NOERR) then
+      write(*,*) "init2 Error: Failed reading area"
+      stop
+    endif
+    area = .true.    
+  endif
 else
   ierr=NF_GET_VAR_REAL(infid,tmpvarid,aire)
@@ -1073,5 +1072,17 @@
 if (ierr.ne.NF_NOERR) then
   write(*,*)"init2 warning: Failed to get phisinit ID."
-  phis = .false.
+  ! try "phisfi" instead of "phisinit"
+  ierr=NF_INQ_VARID(infid,"phisfi",tmpvarid)
+  if (ierr.ne.NF_NOERR) then
+    write(*,*)"init2 warning: Failed to get phisfi ID."
+    phis = .false.
+  else
+    ierr=NF_GET_VAR_REAL(infid,tmpvarid,phisinit)
+    if (ierr.ne.NF_NOERR) then
+      write(*,*) "init2 Error: Failed reading phisfi"
+      stop
+    endif
+  endif
+  phis = .true.  
 else
   ierr=NF_GET_VAR_REAL(infid,tmpvarid,phisinit)
