Index: /trunk/LMDZ.GENERIC/changelog.txt
===================================================================
--- /trunk/LMDZ.GENERIC/changelog.txt	(revision 3308)
+++ /trunk/LMDZ.GENERIC/changelog.txt	(revision 3309)
@@ -1906,2 +1906,7 @@
  need be provided in a "volcano.def" ASCII file read at runtime.
  (see routine "read_volcano" in volcano.F90)
+
+== 20/11/2023 == YJ
+- Cosmetic + clarifying some variables and comments in chemistry
+- add controle variable for actinique UV flux in photochemistry
+  and output surface UV flux in diagspecUV.nc
Index: /trunk/LMDZ.GENERIC/libf/aeronostd/calchim_asis.F90
===================================================================
--- /trunk/LMDZ.GENERIC/libf/aeronostd/calchim_asis.F90	(revision 3308)
+++ /trunk/LMDZ.GENERIC/libf/aeronostd/calchim_asis.F90	(revision 3309)
@@ -5,7 +5,7 @@
                          pu,pdu,pv,pdv,surfdust,surfice,icount,zdtchim)
 
-      use tracer_h, only: mmol, noms, nesp, is_chim
-
-      use conc_mod, only: mmean ! mean molecular mass of the atmosphere
+      use tracer_h,         only: mmol, noms, nesp, is_chim
+
+      use conc_mod,         only: mmean ! mean molecular mass of the atmosphere
       USE comcstfi_mod
       use callkeys_mod
@@ -14,5 +14,5 @@
       use chimiedata_h
       use radcommon_h,      only: glat
-      use wstats_mod, only: wstats
+      use wstats_mod,       only: wstats
 
       implicit none
@@ -256,6 +256,4 @@
 !        chemistry in lower atmosphere
 
-!         if (photochem) then
-
             call photochemistry_asis(nlayer,ngrid,                         &
                                 ig,lswitch,zycol,szacol,fractcol,ptimestep,&
@@ -338,5 +336,5 @@
 ! value of parameter 'output' to trigger writting of outputs
 ! is set above at the declaration of the variable.
-      if (photochem .and. output) then
+      if (output) then
 
             ! photoloysis
@@ -417,4 +415,11 @@
             endif
          endif ! end depos
+
+         if (jonline .and. output_writediagspecUV) then
+
+            !flux at the surface
+            call writediagspecUV(ngrid,"flux","flux(lon,lat,band)","photon.s-1.nm-1.cm-2",3,fluxUV(:,:,1))
+
+         endif ! end jonline
 
       end if ! of if (output)
Index: /trunk/LMDZ.GENERIC/libf/aeronostd/chimiedata_h.F90
===================================================================
--- /trunk/LMDZ.GENERIC/libf/aeronostd/chimiedata_h.F90	(revision 3308)
+++ /trunk/LMDZ.GENERIC/libf/aeronostd/chimiedata_h.F90	(revision 3309)
@@ -56,4 +56,5 @@
       real, save, allocatable :: albedo_snow_chim(:)    ! albedo snow on chemistry wavelenght grid
       real, save, allocatable :: albedo_co2_ice_chim(:) ! albedo co2 ice on chemistry wavelenght grid
+      real, save, allocatable :: fluxUV(:,:,:)          ! total actinic flux at each ngrid, wavelength and altitude (photon.s-1.nm-1.cm-2)
 
 !--------------------------------------------
Index: /trunk/LMDZ.GENERIC/libf/aeronostd/iniwrite_spec.F
===================================================================
--- /trunk/LMDZ.GENERIC/libf/aeronostd/iniwrite_spec.F	(revision 3309)
+++ /trunk/LMDZ.GENERIC/libf/aeronostd/iniwrite_spec.F	(revision 3309)
@@ -0,0 +1,259 @@
+      SUBROUTINE iniwrite_spec(nid,idayref,area,nbplon,nbplat)
+
+      use photolysis_mod, only : nw, wl, wc, wu
+      use comcstfi_mod, only: rad, omeg, g, mugaz, rcp, pi
+      use time_phylmdz_mod, only: daysec, dtphys
+!      USE logic_mod, ONLY: fxyhypb,ysinus
+!      USE serre_mod, ONLY: clon,clat,grossismx,grossismy,dzoomx,dzoomy
+!      USE ener_mod, ONLY: etot0,ptot0,ztot0,stot0,ang0
+      USE regular_lonlat_mod, ONLY: lon_reg, lat_reg
+      USE mod_grid_phy_lmdz, ONLY: nbp_lon, nbp_lat, nbp_lev
+
+      implicit none
+
+c=======================================================================
+c
+c   Auteur:  L. Fairhead  ,  P. Le Van, Y. Wanherdrick, F. Forget
+c   -------
+c
+c   Objet:
+c   ------
+c
+c   'Initialize' the diagfi_spec.nc file: write down dimensions as well
+c   as time-independent fields (e.g: geopotential, mesh area, ...)
+c
+c=======================================================================
+c-----------------------------------------------------------------------
+c   Declarations:
+c   -------------
+
+      include "netcdf.inc"
+
+c   Arguments:
+c   ----------
+
+      integer,intent(in) :: nid        ! NetCDF file ID
+      INTEGER*4,INTENT(IN) :: idayref  ! date (initial date for this run)
+      real,intent(in) :: area(nbplon,nbplat) ! mesh area (m2)
+      integer,intent(in) :: nbplon,nbplat ! sizes of area
+
+c   Local:
+c   ------
+      INTEGER length,l
+      parameter (length = 100)
+      REAL tab_cntrl(length) ! run parameters are stored in this array
+      INTEGER ierr
+      REAl,ALLOCATABLE :: lon_reg_ext(:) ! extended longitudes
+
+      integer :: nvarid,idim_index,idim_rlonu,idim_rlonv
+      integer :: idim_rlatu,idim_rlatv,idim_llmp1,idim_llm
+ !     integer :: idim_nsoilmx ! "subsurface_layers" dimension ID #
+      integer :: idim_wl ! "Wavelength" dimension ID #
+      integer, dimension(2) :: id  
+
+c-----------------------------------------------------------------------
+
+      IF (nbp_lon*nbp_lat==1) THEN
+        ! 1D model
+        ALLOCATE(lon_reg_ext(1))
+      ELSE
+        ! 3D model
+        ALLOCATE(lon_reg_ext(nbp_lon+1))
+      ENDIF
+
+      DO l=1,length
+         tab_cntrl(l)=0.
+      ENDDO
+      tab_cntrl(1)  = FLOAT(nbp_lon)
+      tab_cntrl(2)  = FLOAT(nbp_lat-1)
+      tab_cntrl(3)  = FLOAT(nbp_lev)
+      tab_cntrl(4)  = FLOAT(idayref)
+      tab_cntrl(5)  = rad
+      tab_cntrl(6)  = omeg
+      tab_cntrl(7)  = g
+      tab_cntrl(8)  = mugaz
+      tab_cntrl(9)  = rcp
+      tab_cntrl(10) = daysec
+      tab_cntrl(11) = dtphys
+!      tab_cntrl(12) = etot0
+!      tab_cntrl(13) = ptot0
+!      tab_cntrl(14) = ztot0
+!      tab_cntrl(15) = stot0
+!      tab_cntrl(16) = ang0
+c
+c    ..........    P.Le Van  ( ajout le 8/04/96 )    .........
+c         .....        parametres  pour le zoom          ......   
+!      tab_cntrl(17)  = clon
+!      tab_cntrl(18)  = clat
+!      tab_cntrl(19)  = grossismx
+!      tab_cntrl(20)  = grossismy
+c
+c     .....   ajout  le 6/05/97 et le 15/10/97  .......
+c
+!      IF ( fxyhypb )   THEN
+!        tab_cntrl(21) = 1.
+!        tab_cntrl(22) = dzoomx
+!        tab_cntrl(23) = dzoomy
+!      ELSE
+!        tab_cntrl(21) = 0.
+!        tab_cntrl(22) = dzoomx
+!        tab_cntrl(23) = dzoomy
+!        tab_cntrl(24) = 0.
+!        IF( ysinus )  tab_cntrl(24) = 1.
+!      ENDIF
+
+c    .........................................................
+
+! Define dimensions
+    
+      ierr = NF_REDEF (nid)
+
+      ierr = NF_DEF_DIM (nid, "index", length, idim_index)
+      ierr = NF_DEF_DIM (nid, "latitude", nbp_lat, idim_rlatu)
+      IF (nbp_lon*nbp_lat==1) THEN
+        ierr = NF_DEF_DIM (nid, "longitude", 1, idim_rlonv)
+      ELSE
+        ierr = NF_DEF_DIM (nid, "longitude", nbp_lon+1, idim_rlonv)
+      ENDIF
+      ierr = NF_DEF_DIM (nid, "Wavelength",nw,idim_wl)
+
+      ierr = NF_ENDDEF(nid)
+
+c  Contol parameters for this run
+      ierr = NF_REDEF (nid)
+#ifdef NC_DOUBLE
+      ierr = NF_DEF_VAR (nid, "controle", NF_DOUBLE, 1, 
+     .       idim_index,nvarid)
+#else
+      ierr = NF_DEF_VAR (nid, "controle", NF_FLOAT, 1, 
+     .       idim_index,nvarid)
+#endif
+      ierr = NF_PUT_ATT_TEXT (nid,nvarid,"title", 18,
+     .                       "Control parameters")
+      ierr = NF_ENDDEF(nid)
+#ifdef NC_DOUBLE
+      ierr = NF_PUT_VAR_DOUBLE (nid,nvarid,tab_cntrl)
+#else
+      ierr = NF_PUT_VAR_REAL (nid,nvarid,tab_cntrl)
+#endif
+
+c --------------------------
+c  longitudes and latitudes
+
+      ierr = NF_REDEF (nid)
+#ifdef NC_DOUBLE
+      ierr =NF_DEF_VAR(nid, "latitude", NF_DOUBLE, 1, idim_rlatu,nvarid)
+#else
+      ierr =NF_DEF_VAR (nid, "latitude", NF_FLOAT, 1, idim_rlatu,nvarid)
+#endif
+      ierr =NF_PUT_ATT_TEXT(nid,nvarid,'units',13,"degrees_north")
+      ierr = NF_PUT_ATT_TEXT (nid,nvarid,"long_name", 14,
+     .      "North latitude")
+      ierr = NF_ENDDEF(nid)
+#ifdef NC_DOUBLE
+      ierr = NF_PUT_VAR_DOUBLE (nid,nvarid,lat_reg/pi*180)
+#else
+      ierr = NF_PUT_VAR_REAL (nid,nvarid,lat_reg/pi*180)
+#endif
+c
+c --------------------------
+      lon_reg_ext(1:nbp_lon)=lon_reg(1:nbp_lon)
+      !add extra redundant point (180 degrees, since lon_reg starts at -180
+      IF (nbp_lon*nbp_lat/=1) THEN
+        ! In 3D, add extra redundant point (180 degrees,
+        ! since lon_reg starts at -180)
+        lon_reg_ext(nbp_lon+1)=-lon_reg_ext(1)
+      ENDIF
+
+      ierr = NF_REDEF (nid)
+#ifdef NC_DOUBLE
+      ierr =NF_DEF_VAR(nid,"longitude", NF_DOUBLE, 1, idim_rlonv,nvarid)
+#else
+      ierr = NF_DEF_VAR(nid,"longitude", NF_FLOAT, 1, idim_rlonv,nvarid)
+#endif
+      ierr = NF_PUT_ATT_TEXT (nid,nvarid,"long_name", 14,
+     .      "East longitude")
+      ierr = NF_PUT_ATT_TEXT(nid,nvarid,'units',12,"degrees_east")
+      ierr = NF_ENDDEF(nid)
+#ifdef NC_DOUBLE
+      ierr = NF_PUT_VAR_DOUBLE (nid,nvarid,lon_reg_ext/pi*180)
+#else
+      ierr = NF_PUT_VAR_REAL (nid,nvarid,lon_reg_ext/pi*180)
+#endif
+c
+
+!-------------------------------
+! Number of bands in the IR
+!-------------------------------
+
+      ierr=NF_REDEF (nid) ! Enter NetCDF (re-)define mode
+      ! define variable
+#ifdef NC_DOUBLE
+      ierr=NF_DEF_VAR(nid,"Wavelength",NF_DOUBLE,1,
+     .                                idim_wl,nvarid)
+#else
+      ierr=NF_DEF_VAR(nid,"Wavelength",NF_FLOAT,1,
+     .                                idim_wl,nvarid)
+#endif
+      ierr=NF_PUT_ATT_TEXT (nid,nvarid,"long_name", 37,
+     .                        "Band mid Wavelength in the UV-visible")
+      ierr=NF_PUT_ATT_TEXT (nid,nvarid,"units",2,"nm")
+      ierr=NF_ENDDEF(nid) ! Leave NetCDF define mode
+      ! write variable
+#ifdef NC_DOUBLE
+      ierr=NF_PUT_VAR_DOUBLE (nid,nvarid,dble(wc))
+#else
+      ierr=NF_PUT_VAR_REAL (nid,nvarid,real(wc))
+#endif
+
+c
+!-------------------------------
+! Width of bands in the Visible
+!-------------------------------
+
+      ierr=NF_REDEF (nid) ! Enter NetCDF (re-)define mode
+      ! define variable
+#ifdef NC_DOUBLE
+      ierr=NF_DEF_VAR(nid,"Wavelength_width",NF_DOUBLE,1,
+     .                                idim_wl,nvarid)
+#else
+      ierr=NF_DEF_VAR(nid,"Wavelength_width",NF_FLOAT,1,
+     .                                idim_wl,nvarid)
+#endif
+      ierr=NF_PUT_ATT_TEXT (nid,nvarid,"long_name", 27,
+     .                        "Bandwidth in the UV-visible")
+      ierr=NF_PUT_ATT_TEXT (nid,nvarid,"units",2,"nm")
+      ierr=NF_ENDDEF(nid) ! Leave NetCDF define mode
+      ! write variable
+#ifdef NC_DOUBLE
+      ierr=NF_PUT_VAR_DOUBLE (nid,nvarid,dble(wu-wl))
+#else
+      ierr=NF_PUT_VAR_REAL (nid,nvarid,real(wu-wl))
+#endif
+c
+c --------------------------
+c   Mesh area
+c --------------------------
+
+      id(1)=idim_rlonv
+      id(2)=idim_rlatu
+
+
+      ierr = NF_REDEF (nid)
+#ifdef NC_DOUBLE
+      ierr = NF_DEF_VAR (nid, "aire", NF_DOUBLE, 2, id,nvarid)
+#else
+      ierr = NF_DEF_VAR (nid, "aire", NF_FLOAT, 2, id,nvarid)
+#endif
+      ierr = NF_PUT_ATT_TEXT (nid, nvarid, "title", 9,
+     .                       "Mesh area")
+      ierr = NF_ENDDEF(nid)
+#ifdef NC_DOUBLE
+      ierr = NF_PUT_VAR_DOUBLE (nid,nvarid,area)
+#else
+      ierr = NF_PUT_VAR_REAL (nid,nvarid,area)
+#endif
+
+
+
+      END
Index: /trunk/LMDZ.GENERIC/libf/aeronostd/photochemistry_asis.F90
===================================================================
--- /trunk/LMDZ.GENERIC/libf/aeronostd/photochemistry_asis.F90	(revision 3308)
+++ /trunk/LMDZ.GENERIC/libf/aeronostd/photochemistry_asis.F90	(revision 3309)
@@ -137,4 +137,6 @@
      allocate(albedo_snow_chim(nw))
      allocate(albedo_co2_ice_chim(nw))
+     allocate(fluxUV(ngrid,nw,nlayer))
+     fluxUV(:,:,:) = 0.
     ! Step 1 : Initialisation of the Spectral Albedos.
      DO iw=1,nw
Index: /trunk/LMDZ.GENERIC/libf/aeronostd/photolysis_mod.F90
===================================================================
--- /trunk/LMDZ.GENERIC/libf/aeronostd/photolysis_mod.F90	(revision 3308)
+++ /trunk/LMDZ.GENERIC/libf/aeronostd/photolysis_mod.F90	(revision 3309)
@@ -32,5 +32,5 @@
     ! solar flux
   
-    real, allocatable, save :: f(:)            !  solar flux (photon.s-1.nm-1.cm-2) at 1 au
+    real, allocatable, save :: fstar1AU(:)     ! stellar flux (photon.s-1.nm-1.cm-2) at 1 au
   
     ! cross-sections and quantum yields
@@ -69,9 +69,9 @@
     call gridw(nw,wl,wc,wu,mopt)
   
-    allocate(f(nw))
+    allocate(fstar1AU(nw))
   
     ! read and grid solar flux data
    
-    call rdsolarflux(nw,wl,wc,f)
+    call rdsolarflux(nw,wl,wc,fstar1AU)
   
     ! read maximum wavelength until photochemical heating is calculated
@@ -474,5 +474,5 @@
     !==============================================================================
    
-    subroutine rdsolarflux(nw,wl,wc,f)
+    subroutine rdsolarflux(nw,wl,wc,fstar1AU)
   
         !     Read and re-grid solar flux data.            
@@ -490,5 +490,5 @@
         !     output
   
-        real, dimension(nw) :: f  ! solar flux (photon.s-1.nm-1.cm-2)
+        real, dimension(nw) :: fstar1AU  ! stellar flux (photon.s-1.nm-1.cm-2)
   
         !     local 
@@ -568,8 +568,8 @@
         ! 5.039e11 = 1.e-4*1e-9/(hc = 6.62e-34*2.998e8)
   
-        ! f need to be in photon.s-1.nm-1.cm-2
+        ! fstar1AU need to be in photon.s-1.nm-1.cm-2
         DO iw = 1, nw-1
            !f(iw) = yg1(iw)*wc(iw)*5.039e11  ! If yg1 in w.m-2.nm-1
-           f(iw) = yg1(iw)
+           fstar1AU(iw) = yg1(iw)
         ENDDO
   
Index: /trunk/LMDZ.GENERIC/libf/aeronostd/photolysis_online.F
===================================================================
--- /trunk/LMDZ.GENERIC/libf/aeronostd/photolysis_online.F	(revision 3308)
+++ /trunk/LMDZ.GENERIC/libf/aeronostd/photolysis_online.F	(revision 3309)
@@ -20,5 +20,5 @@
       use photolysis_mod
       use tracer_h
-      use chimiedata_h, only: indexchim
+      use chimiedata_h, only: indexchim, fluxUV
       use types_asis,   only: nb_phot_hv_max, nb_phot_max, jlabel,
      $                        reactions
@@ -45,7 +45,7 @@
       real (kind = 8), dimension(nlayer,nb_phot_max) :: e_phot      ! photolysis rates by energie (J.mol-1.s-1)
  
-!     solar flux at mars
-
-      real, dimension(nw) :: fmars                                  ! solar flux (w.m-2.nm-1)
+!     stellar flux at planet
+
+      real, dimension(nw) :: fplanet                                ! stellar flux (photon.s-1.nm-1.cm-2) at planet
       real :: factor
 
@@ -198,9 +198,9 @@
       call sphers(nlev,zalt,sza,dsdh,nid)
 
-!==== solar flux at mars
+!==== stellar flux at planet
 
       factor = (1./dist_sol)**2.
       do iw = 1,nw-1
-         fmars(iw) = f(iw)*factor
+         fplanet(iw) = fstar1AU(iw)*factor
       end do
 
@@ -229,5 +229,7 @@
 
          do ilay = 1,nlayer
-           saflux(ilay) = fmars(iw)*(fdir(ilay) + fdn(ilay) + fup(ilay))
+           saflux(ilay) = fplanet(iw)*
+     $                     (fdir(ilay) + fdn(ilay) + fup(ilay))
+           fluxUV(ig,iw,ilay) = saflux(ilay)
          end do
 
Index: /trunk/LMDZ.GENERIC/libf/aeronostd/writediagspecUV.F
===================================================================
--- /trunk/LMDZ.GENERIC/libf/aeronostd/writediagspecUV.F	(revision 3309)
+++ /trunk/LMDZ.GENERIC/libf/aeronostd/writediagspecUV.F	(revision 3309)
@@ -0,0 +1,322 @@
+      subroutine writediagspecUV(ngrid,nom,titre,unite,dimpx,px)
+
+!  parameter (input) :
+!  ----------
+!      ngrid : number of grid point where to calculate the physics
+!                (ngrid = 2+(jjm-1)*iim - 1/jjm)
+!                 (= nlon or klon in Earth physics)
+!      
+!      nom  : output variable name (string)
+!      titre: title variable name (string)
+!      unite : variable unit (string)
+!      px : output variable (real 0, 2, or 3d)
+!      dimpx : dimension of px : 0, 2, or 3 dimensions
+!
+!=================================================================
+!
+!      This is a modified version that accepts spectrally varying input
+!      RW (2010)
+!      UPDATE: copy of writediagspecVI for photochemstry wavelength
+!      range YJ (2024)
+!
+!=================================================================
+ 
+! Addition by RW (2010) to allow OSR to be saved in .nc format
+! Copy by YJ (2024) for surface UV flux
+      use photolysis_mod, only : nw
+      use geometry_mod, only: cell_area
+      use mod_phys_lmdz_para, only : is_mpi_root, is_master, gather
+      use mod_grid_phy_lmdz, only : klon_glo, Grid1Dto2D_glo,
+     &                              nbp_lon, nbp_lat, grid_type,
+     &                              unstructured
+      use time_phylmdz_mod, only: ecritphy, iphysiq, day_step, day_ini
+
+      implicit none
+
+      include "netcdf.inc"
+
+! Arguments on input:
+      integer ngrid
+      character (len=*) :: nom,titre,unite
+      integer dimpx
+      real px(ngrid,nw)
+
+! Local variables:
+
+!      real dx3(iip1,jjp1,llm) ! to store a 3D data set
+!      real dx2(iip1,jjp1)     ! to store a 2D (surface) data set
+!      real dx0
+
+      integer irythme
+      integer ierr
+      integer iq
+      integer i,j,l,zmax , ig0
+
+      integer,save :: zitau=0
+      character(len=20),save :: firstnom='1234567890'
+      real,save :: date
+!$OMP THREADPRIVATE(firstnom,zitau,date)
+
+! Ajouts
+      integer, save :: ntime=0
+!$OMP THREADPRIVATE(ntime)
+      integer :: idim,varid
+      integer :: nid
+      character (len =50):: fichnom
+      integer, dimension(4) :: id
+      integer, dimension(4) :: edges,corner
+
+      real area((nbp_lon+1),nbp_lat)
+! added by RDW for OSR output
+      real dx3(nbp_lon+1,nbp_lat,nw) ! to store the data set
+      real dx3_1d(1,nw) ! to store the data with 1D model
+
+#ifdef CPP_PARA
+! Added to work in parallel mode
+      real dx3_glop(klon_glo,nw)
+      real dx3_glo(nbp_lon,nbp_lat,nw) ! to store a global 3D data set
+      real areafi_glo(klon_glo) ! mesh area on global physics grid
+#else
+      real areafi_glo(ngrid) ! mesh area on global physics grid
+#endif
+      if (grid_type == unstructured) then 
+        return
+      endif
+
+!***************************************************************
+!output frequency
+
+      irythme = ecritphy ! output with ecritphy frequency
+!EM+JL if the spetra need to be output more frequently, need to define a ecritSpec...
+!     irythme = iphysiq  ! sortie a tous les pas physique
+
+!***************************************************************
+
+! Initialisation of 'firstnom' and create/open the "diagfi.nc" NetCDF file
+! ------------------------------------------------------------------------
+! (At first call of the subroutine)
+
+      fichnom="diagspecUV.nc"
+
+      if (firstnom.eq.'1234567890') then ! .true. for the very first call
+      !  to this subroutine; now set 'firstnom'
+         firstnom = nom
+         ! just to be sure, check that firstnom is large enough to hold nom
+         if (len_trim(firstnom).lt.len_trim(nom)) then
+           write(*,*) "writediagfi: Error !!!"
+           write(*,*) "   firstnom string not long enough!!"
+           write(*,*) "   increase its size to at least ",len_trim(nom)
+           stop
+         endif
+
+#ifdef CPP_PARA
+          ! Gather cell_area() mesh area on physics grid
+          call Gather(cell_area,areafi_glo)
+#else
+         areafi_glo(:)=cell_area(:)
+#endif
+         ! Create the NetCDF file
+         if (is_master) then
+         ierr = NF_CREATE(fichnom, NF_CLOBBER, nid)
+         ! Define the 'Time' dimension
+         ierr = nf_def_dim(nid,"Time",NF_UNLIMITED,idim)
+         ! Define the 'Time' variable
+#ifdef NC_DOUBLE
+         ierr = NF_DEF_VAR (nid, "Time", NF_DOUBLE, 1, idim,varid)
+#else
+         ierr = NF_DEF_VAR (nid, "Time", NF_FLOAT, 1, idim,varid)
+#endif
+         ! Add a long_name attribute
+         ierr = NF_PUT_ATT_TEXT (nid, varid, "long_name",
+     .          4,"Time")
+         ! Add a units attribute
+         ierr = NF_PUT_ATT_TEXT(nid, varid,'units',29,
+     .          "days since 0000-00-0 00:00:00")
+         ! Switch out of NetCDF Define mode
+         ierr = NF_ENDDEF(nid)
+
+         ! Build area()
+         IF (klon_glo>1) THEN
+          do i=1,nbp_lon+1 ! poles
+           ! divide at the poles by nbp_lon
+           area(i,1)=areafi_glo(1)/nbp_lon
+           area(i,nbp_lat)=areafi_glo(klon_glo)/nbp_lon
+          enddo
+          do j=2,nbp_lat-1
+           ig0= 1+(j-2)*nbp_lon
+           do i=1,nbp_lon
+              area(i,j)=areafi_glo(ig0+i)
+           enddo
+           ! handle redundant point in longitude
+           area(nbp_lon+1,j)=area(1,j)
+          enddo
+         ENDIF
+
+         ! write "header" of file (longitudes, latitudes, geopotential, ...)
+         IF (klon_glo>1) THEN ! general 3D case
+           call iniwrite_spec(nid,day_ini,area,nbp_lon+1,nbp_lat)
+         ELSE
+           call iniwrite_spec(nid,day_ini,areafi_glo(1),1,1)
+         ENDIF
+         endif ! of if (is_master)
+
+         zitau = -1 ! initialize zitau
+      else
+         if (is_master) then
+           ! Open the NetCDF file
+           ierr = NF_OPEN(fichnom,NF_WRITE,nid)
+         endif
+      endif ! if (firstnom.eq.'1234567890')
+
+! Increment time index 'zitau' if it is the "firstcall" (at given time level)
+! to writediagfi
+!------------------------------------------------------------------------
+      if (nom.eq.firstnom) then
+          zitau = zitau + iphysiq
+      end if
+
+!--------------------------------------------------------
+! Write the variables to output file if it's time to do so
+!--------------------------------------------------------
+
+      if ( MOD(zitau+1,irythme) .eq.0.) then
+
+! Compute/write/extend 'Time' coordinate (date given in days)
+! (done every "first call" (at given time level) to writediagfi)
+! Note: date is incremented as 1 step ahead of physics time
+!       (like the 'histoire' outputs)
+!--------------------------------------------------------
+
+        if (nom.eq.firstnom) then
+
+        ! We have identified a "first call" (at given date)
+           ntime=ntime+1 ! increment # of stored time steps
+           ! compute corresponding date (in days and fractions thereof)
+           date= float (zitau +1)/float (day_step)
+
+           if (is_master) then
+             ! Get NetCDF ID of 'Time' variable
+             ierr= NF_INQ_VARID(nid,"Time",varid)
+
+             ! Write (append) the new date to the 'Time' array
+#ifdef NC_DOUBLE
+             ierr= NF_PUT_VARA_DOUBLE(nid,varid,ntime,1,date)
+#else
+             ierr= NF_PUT_VARA_REAL(nid,varid,ntime,1,date)
+#endif
+             if (ierr.ne.NF_NOERR) then
+              write(*,*) "***** PUT_VAR matter in writediagspec_nc"
+              write(*,*) "***** with time"
+              write(*,*) 'ierr=', ierr   
+c             call abort
+             endif
+
+             write(6,*)'WRITEDIAGSPEC: date= ', date
+           endif ! of if (is_master)
+        end if ! of if (nom.eq.firstnom)
+
+
+ 
+!Case of a 3D variable
+!---------------------
+        if (dimpx.eq.3) then
+
+!         A. Recast (copy) variable from physics grid to dynamics grid
+#ifdef CPP_PARA
+  ! gather field on a "global" (without redundant longitude) array
+          call Gather(px,dx3_glop)
+!$OMP MASTER
+          if (is_mpi_root) then
+            call Grid1Dto2D_glo(dx3_glop,dx3_glo)
+            ! copy dx3_glo() to dx3(:) and add redundant longitude
+            dx3(1:nbp_lon,:,:)=dx3_glo(1:nbp_lon,:,:)
+            dx3(nbp_lon+1,:,:)=dx3(1,:,:)
+          endif
+!$OMP END MASTER
+!$OMP BARRIER
+#else
+          IF (klon_glo>1) THEN ! General case
+           DO l=1,nw
+             DO i=1,nbp_lon+1
+                dx3(i,1,l)=px(1,l)
+                dx3(i,nbp_lat,l)=px(ngrid,l)
+             ENDDO
+             DO j=2,nbp_lat-1
+                ig0= 1+(j-2)*nbp_lon
+                DO i=1,nbp_lon
+                   dx3(i,j,l)=px(ig0+i,l)
+                ENDDO
+                dx3(nbp_lon+1,j,l)=dx3(1,j,l)
+             ENDDO
+           ENDDO
+          ELSE ! 1D model case
+           dx3_1d(1,1:nw)=px(1,1:nw)
+          ENDIF
+#endif
+
+!         B. Write (append) the variable to the NetCDF file
+          if (is_master) then
+
+! name of the variable
+           ierr= NF_INQ_VARID(nid,nom,varid)
+           if (ierr /= NF_NOERR) then
+! corresponding dimensions
+              ierr= NF_INQ_DIMID(nid,"longitude",id(1))
+              ierr= NF_INQ_DIMID(nid,"latitude",id(2))
+              ierr= NF_INQ_DIMID(nid,"Wavelength",id(3))
+              ierr= NF_INQ_DIMID(nid,"Time",id(4))
+
+! Create the variable if it doesn't exist yet
+
+              write (*,*) "=========================="
+              write (*,*) "DIAGSPEC: creating variable ",nom
+              call def_var(nid,nom,titre,unite,4,id,varid,ierr)
+
+           endif
+
+           corner(1)=1
+           corner(2)=1
+           corner(3)=1
+           corner(4)=ntime
+
+           IF (klon_glo==1) THEN
+             edges(1)=1
+           ELSE
+             edges(1)=nbp_lon+1
+           ENDIF
+           edges(2)=nbp_lat
+           edges(3)=nw
+           edges(4)=1
+#ifdef NC_DOUBLE
+           IF (klon_glo>1) THEN ! General case
+             ierr= NF_PUT_VARA_DOUBLE(nid,varid,corner,edges,dx3)
+           ELSE
+             ierr= NF_PUT_VARA_DOUBLE(nid,varid,corner,edges,dx3_1d)
+           ENDIF
+#else
+           IF (klon_glo>1) THEN ! General case
+             ierr= NF_PUT_VARA_REAL(nid,varid,corner,edges,dx3)
+           ELSE
+             ierr= NF_PUT_VARA_REAL(nid,varid,corner,edges,dx3_1d)
+           ENDIF
+#endif
+
+           if (ierr.ne.NF_NOERR) then
+              write(*,*) "***** PUT_VAR problem in writediagspec"
+              write(*,*) "***** with ",nom
+              write(*,*) 'ierr=', ierr
+             call abort
+           endif 
+
+          endif ! of if (is_master)
+
+        endif ! of if (dimpx.eq.3)
+
+      endif ! of if ( MOD(zitau+1,irythme) .eq.0.)
+
+      ! Close the NetCDF file
+      if (is_master) then
+        ierr= NF_CLOSE(nid)
+      endif
+
+      end
Index: /trunk/LMDZ.GENERIC/libf/phystd/callkeys_mod.F90
===================================================================
--- /trunk/LMDZ.GENERIC/libf/phystd/callkeys_mod.F90	(revision 3308)
+++ /trunk/LMDZ.GENERIC/libf/phystd/callkeys_mod.F90	(revision 3309)
@@ -87,5 +87,6 @@
       logical,save :: depos
       logical,save :: haze
-!$OMP THREADPRIVATE(photochem,photoheat,jonline,depos)
+      logical,save :: output_writediagspecUV
+!$OMP THREADPRIVATE(photochem,photoheat,jonline,depos,output_writediagspecUV)
       logical,save :: calllott_nonoro
 !$OMP THREADPRIVATE(calllott_nonoro)
Index: /trunk/LMDZ.GENERIC/libf/phystd/inifis_mod.F90
===================================================================
--- /trunk/LMDZ.GENERIC/libf/phystd/inifis_mod.F90	(revision 3308)
+++ /trunk/LMDZ.GENERIC/libf/phystd/inifis_mod.F90	(revision 3309)
@@ -543,4 +543,9 @@
      if (is_master) write(*,*)trim(rname)//": haze = ",haze
 
+     if (is_master) write(*,*)trim(rname)//": Output photochemical surface UV flux ?"
+     output_writediagspecUV=.false. ! default value
+     call getin_p("output_writediagspecUV",output_writediagspecUV)
+     if (is_master) write(*,*)trim(rname)//": output_writediagspecUV = ",output_writediagspecUV
+
 ! Global1D mean and solar zenith angle
 
