Index: /trunk/LMDZ.MARS/changelog.txt
===================================================================
--- /trunk/LMDZ.MARS/changelog.txt	(revision 4160)
+++ /trunk/LMDZ.MARS/changelog.txt	(revision 4161)
@@ -5141,2 +5141,8 @@
 == 31/03/2026 == JBC
 Giving standard explicit names to variables related to "paleoclimate" module + adding yearly average of flux exchanged with subsurface ice in XIOS output file intended for the PEM.
+
+== 01/04/2026 == JM
+- Fix improvedclouds_mod by adding a missing "else" condition on zdq.
+- Add the possibility to output watercaptag in physiq_mod.
+- Fix write_output to handle logical arrays with an unstructured grid.
+- Update some of the utils (localtime/zrecast) to handle phisfi.
Index: /trunk/LMDZ.MARS/libf/phymars/improvedclouds_mod.F90
===================================================================
--- /trunk/LMDZ.MARS/libf/phymars/improvedclouds_mod.F90	(revision 4160)
+++ /trunk/LMDZ.MARS/libf/phymars/improvedclouds_mod.F90	(revision 4161)
@@ -443,4 +443,7 @@
         IF (spenttime.ne.0) then
           zdq=(dMicetot/spenttime)!*(ptimestep-spenttime)
+        ELSE
+          ! Initialization for spenttime=0
+          zdq=zpotcond(ig,l)*((ptimestep-spenttime)/ptimestep)
         ENDIF
         zdq=abs(zdq)
Index: /trunk/LMDZ.MARS/libf/phymars/physiq_mod.F
===================================================================
--- /trunk/LMDZ.MARS/libf/phymars/physiq_mod.F	(revision 4160)
+++ /trunk/LMDZ.MARS/libf/phymars/physiq_mod.F	(revision 4161)
@@ -3337,4 +3337,6 @@
          call write_output("phisfi","Surface geopotential",
      &                    "m2s-2",phisfi(:))
+         call write_output("watercaptag","Watercap tag"
+     &         ,"Boolean",watercaptag(:))
          if (grid_type == regular_lonlat) then
            call write_output("area","Mesh area","m2",
Index: /trunk/LMDZ.MARS/libf/phymars/write_output_mod.F90
===================================================================
--- /trunk/LMDZ.MARS/libf/phymars/write_output_mod.F90	(revision 4160)
+++ /trunk/LMDZ.MARS/libf/phymars/write_output_mod.F90	(revision 4161)
@@ -285,7 +285,8 @@
 logical, dimension(:), intent(in) :: field
 ! Local argument used to convert logical to real
-real, dimension(ngrid) :: field_real
-logical :: is_active ! For XIOS, should this field be sent or not
-
+real, allocatable, dimension(:) :: field_real
+logical :: is_active ! For XIOS, should this field be sent or not
+
+allocate(field_real(size(field,1)))
 field_real = 0.
 where (field) field_real = 1.
Index: /trunk/LMDZ.MARS/util/localtime.F90
===================================================================
--- /trunk/LMDZ.MARS/util/localtime.F90	(revision 4160)
+++ /trunk/LMDZ.MARS/util/localtime.F90	(revision 4161)
@@ -1046,7 +1046,19 @@
 ierr=NF_INQ_VARID(infid,"phisinit",tmpvarid)
 if (ierr.ne.NF_NOERR) then
-  write(*,*) "Failed to get phisinit ID. OK"
-  phisinit = 0.
-  phis = .false.
+  write(*,*) "Failed to get phisinit ID..."
+  write(*,*) "Try name phisfi (xios name)..."
+  ierr=NF_INQ_VARID(infid,"phisfi",tmpvarid)
+  if (ierr.ne.NF_NOERR) then
+    write(*,*) "Failed again. Ok, I skip phisinit."
+    phisinit = 0.
+    phis = .false.
+  else
+    ierr=NF_GET_VAR_REAL(infid,tmpvarid,phisinit)
+    if (ierr.ne.NF_NOERR) then
+      write(*,*) "init2 ERRO: Failed reading phisinit"
+      stop
+    endif
+    phis = .true.
+  endif
 else
   ierr=NF_GET_VAR_REAL(infid,tmpvarid,phisinit)
Index: /trunk/LMDZ.MARS/util/zrecast.F90
===================================================================
--- /trunk/LMDZ.MARS/util/zrecast.F90	(revision 4160)
+++ /trunk/LMDZ.MARS/util/zrecast.F90	(revision 4161)
@@ -654,40 +654,52 @@
 if (ierr.ne.NF_NOERR) then
   write(*,*) "Warning: Failed to get phisinit ID from file ",trim(infile)
-  infile2="diagfi.nc"
-  write(*,*) "         Trying file ",trim(infile2)
-  ierr=NF_OPEN(infile2,NF_NOWRITE,infid2)
+  write(*,*) "Trying name phisfi (xios name)..."
+  ierr=NF_INQ_VARID(infid,"phisfi",tmpvarid)
   if (ierr.ne.NF_NOERR) then
-    write(*,*) "Problem: Could not find/open that file"
-    infile2="diagfi1.nc"
+    write(*,*) "Failed to find phisfi..."
+    infile2="diagfi.nc"
     write(*,*) "         Trying file ",trim(infile2)
     ierr=NF_OPEN(infile2,NF_NOWRITE,infid2)
     if (ierr.ne.NF_NOERR) then
       write(*,*) "Problem: Could not find/open that file"
-      infile2="phisinit.nc"
+      infile2="diagfi1.nc"
       write(*,*) "         Trying file ",trim(infile2)
       ierr=NF_OPEN(infile2,NF_NOWRITE,infid2)
       if (ierr.ne.NF_NOERR) then
-        write(*,*) "Error: Could not open that file either"
-        write(*,*) "Might as well stop here"
-        stop
+        write(*,*) "Problem: Could not find/open that file"
+        infile2="phisinit.nc"
+        write(*,*) "         Trying file ",trim(infile2)
+        ierr=NF_OPEN(infile2,NF_NOWRITE,infid2)
+        if (ierr.ne.NF_NOERR) then
+          write(*,*) "Error: Could not open that file either"
+          write(*,*) "Might as well stop here"
+          stop
+        endif
       endif
     endif
-  endif
-
-  ! Get ID for phisinit
-  ierr=NF_INQ_VARID(infid2,"phisinit",tmpvarid)
-  if (ierr.ne.NF_NOERR) then
-    write(*,*) "Error: Failed to get phisinit ID"
-    stop
-  endif
-  ! Get physinit
-  ierr=NF_GET_VAR_REAL(infid2,tmpvarid,phisinit)
-  if (ierr.ne.NF_NOERR) then
-    write(*,*) "Error: Failed reading phisinit"
-    stop
-  endif
-  ! Close file
-  write(*,*) 'OK, got phisinit'
-  ierr=NF_CLOSE(infid2)
+
+    ! Get ID for phisinit
+    ierr=NF_INQ_VARID(infid2,"phisinit",tmpvarid)
+    if (ierr.ne.NF_NOERR) then
+      write(*,*) "Error: Failed to get phisinit ID"
+      stop
+    endif
+  
+    ! Get physinit
+    ierr=NF_GET_VAR_REAL(infid2,tmpvarid,phisinit)
+    if (ierr.ne.NF_NOERR) then
+      write(*,*) "Error: Failed reading phisinit"
+      stop
+    endif
+    ! Close file
+    write(*,*) 'OK, got phisinit'
+    ierr=NF_CLOSE(infid2)
+  else
+    ierr=NF_GET_VAR_REAL(infid,tmpvarid,phisinit)
+    if (ierr.ne.NF_NOERR) then
+      write(*,*) "Error: Failed reading phisinit"
+      stop
+    endif
+  endif
 else
   ierr=NF_GET_VAR_REAL(infid,tmpvarid,phisinit)
@@ -697,5 +709,4 @@
   endif
 endif
-
 !===============================================================================
 ! 1.4 Choose and build the new vertical coordinate
