Index: trunk/LMDZ.GENERIC/README
===================================================================
--- trunk/LMDZ.GENERIC/README	(revision 1529)
+++ trunk/LMDZ.GENERIC/README	(revision 1531)
@@ -1163,2 +1163,5 @@
   on the global dynamics grid.
   As before, the slab ocean only works in serial.
+
+== 07/04/2016 == EM+MT
+- Fix buggy ouputs in 1D introduced by previous code modifications.
Index: trunk/LMDZ.GENERIC/libf/phystd/dyn1d/rcm1d.F
===================================================================
--- trunk/LMDZ.GENERIC/libf/phystd/dyn1d/rcm1d.F	(revision 1529)
+++ trunk/LMDZ.GENERIC/libf/phystd/dyn1d/rcm1d.F	(revision 1531)
@@ -21,9 +21,11 @@
      &                        mugaz, rcp, omeg
       use time_phylmdz_mod, only: daysec, dtphys, day_step, ecritphy,
-     &                            nday
+     &                            nday, iphysiq
       use callkeys_mod, only: tracer,check_cpp_match,rings_shadow,
      &	                      specOLR,water,pceil,ok_slab_ocean
       USE comvert_mod, ONLY: ap,bp,aps,bps,pa,preff
       USE logic_mod, ONLY: hybrid,autozlevs
+      use regular_lonlat_mod, only: init_regular_lonlat
+      use planete_mod, only: ini_planete_mod
       use inifis_mod, only: inifis
       implicit none
@@ -478,5 +480,5 @@
       write(*,*) " day_step = ",day_step
 
-       
+      iphysiq=1 ! in 1D model physics are called evry time step
       ecritphy=day_step ! default value for ecritphy
       PRINT *,'Nunber of steps between writediagfi ?'
@@ -497,4 +499,10 @@
       write(*,*)"-------------------------------------"
       write(*,*)"-------------------------------------"
+
+      ! initializations, as with iniphysiq.F90 for the 3D GCM
+      CALL init_regular_lonlat(1,1,longitude,latitude,
+     &                   (/0.,0./),(/0.,0./))
+      
+      call ini_planete_mod(nlayer,preff,ap,bp)
 
 !!! CALL INIFIS
Index: trunk/LMDZ.GENERIC/libf/phystd/inistats.F
===================================================================
--- trunk/LMDZ.GENERIC/libf/phystd/inistats.F	(revision 1529)
+++ trunk/LMDZ.GENERIC/libf/phystd/inistats.F	(revision 1531)
@@ -16,9 +16,18 @@
       integer :: l,nsteppd
       real, dimension(nbp_lev) ::  sig_s
-      real :: lon_reg_ext(nbp_lon+1) ! extended longitudes
+      real,allocatable :: lon_reg_ext(:) ! extended longitudes
       integer :: idim_lat,idim_lon,idim_llm,idim_llmp1,idim_time
       real, dimension(istime) :: lt
       integer :: nvarid
 
+
+      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
+      
       write (*,*) 
       write (*,*) '                        || STATS ||'
@@ -46,6 +55,9 @@
       
       lon_reg_ext(1:nbp_lon)=lon_reg(1:nbp_lon)
-      !add extra redundant point (180 degrees, since lon_reg starts at -180
-      lon_reg_ext(nbp_lon+1)=-lon_reg_ext(1)
+      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
 
       if (is_master) then
@@ -59,5 +71,9 @@
 
       ierr = NF_DEF_DIM (nid, "latitude", nbp_lat, idim_lat)
-      ierr = NF_DEF_DIM (nid, "longitude", nbp_lon+1, idim_lon)
+      IF (nbp_lon*nbp_lat==1) THEN
+        ierr = NF_DEF_DIM (nid, "longitude", 1, idim_lon)
+      ELSE
+        ierr = NF_DEF_DIM (nid, "longitude", nbp_lon+1, idim_lon)
+      ENDIF
       ierr = NF_DEF_DIM (nid, "altitude", nbp_lev, idim_llm)
       ierr = NF_DEF_DIM (nid, "llmp1", nbp_lev+1, idim_llmp1)
Index: trunk/LMDZ.GENERIC/libf/phystd/iniwrite.F
===================================================================
--- trunk/LMDZ.GENERIC/libf/phystd/iniwrite.F	(revision 1529)
+++ trunk/LMDZ.GENERIC/libf/phystd/iniwrite.F	(revision 1531)
@@ -1,3 +1,3 @@
-      SUBROUTINE iniwrite(nid,idayref,phis,area)
+      SUBROUTINE iniwrite(nid,idayref,phis,area,nbplon,nbplat)
 
       use comsoil_h, only: mlayer, nsoilmx
@@ -35,6 +35,7 @@
       integer,intent(in) :: nid        ! NetCDF file ID
       INTEGER*4,intent(in) :: idayref  ! date (initial date for this run)
-      real,intent(in) :: phis(nbp_lon+1,nbp_lat) ! surface geopotential
-      real,intent(in) :: area(nbp_lon+1,nbp_lat) ! mesh area (m2)
+      real,intent(in) :: phis(nbplon,nbp_lat) ! surface geopotential
+      real,intent(in) :: area(nbplon,nbp_lat) ! mesh area (m2)
+      integer,intent(in) :: nbplon,nbplat ! sizes of area and phis arrays
 
 c   Local:
@@ -44,5 +45,5 @@
       REAL tab_cntrl(length) ! run parameters are stored in this array
       INTEGER ierr
-      REAl :: lon_reg_ext(nbp_lon+1) ! extended longitudes
+      REAl,ALLOCATABLE :: lon_reg_ext(:) ! extended longitudes
 
       integer :: nvarid,idim_index,idim_rlonv
@@ -51,4 +52,12 @@
       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
@@ -102,5 +111,9 @@
 !      ierr = NF_DEF_DIM (nid, "rlonu", iip1, idim_rlonu)
       ierr = NF_DEF_DIM (nid, "latitude", nbp_lat, idim_rlatu)
-      ierr = NF_DEF_DIM (nid, "longitude", nbp_lon+1, idim_rlonv)
+      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, "rlatv", jjm, idim_rlatv)
       ierr = NF_DEF_DIM (nid, "interlayer", (nbp_lev+1), idim_llmp1)
@@ -164,7 +177,11 @@
 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
-      lon_reg_ext(nbp_lon+1)=-lon_reg_ext(1)
+      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)
Index: trunk/LMDZ.GENERIC/libf/phystd/iniwrite_specIR.F
===================================================================
--- trunk/LMDZ.GENERIC/libf/phystd/iniwrite_specIR.F	(revision 1529)
+++ trunk/LMDZ.GENERIC/libf/phystd/iniwrite_specIR.F	(revision 1531)
@@ -1,3 +1,3 @@
-      SUBROUTINE iniwrite_specIR(nid,idayref,area)
+      SUBROUTINE iniwrite_specIR(nid,idayref,area,nbplon,nbplat)
 
       use radinc_h, only: L_NSPECTI
@@ -36,5 +36,6 @@
       integer,intent(in) :: nid        ! NetCDF file ID
       INTEGER*4,intent(in) :: idayref  ! date (initial date for this run)
-      real,intent(in) :: area(nbp_lon+1,nbp_lat) ! mesh area (m2)
+      real,intent(in) :: area(nbplon,nbplat) ! mesh area (m2)
+      integer,intent(in) :: nbplon,nbplat ! sizes of area
 
 c   Local:
@@ -44,5 +45,5 @@
       REAL tab_cntrl(length) ! run parameters are stored in this array
       INTEGER ierr
-      REAl :: lon_reg_ext(nbp_lon+1) ! extended longitudes
+      REAl,ALLOCATABLE :: lon_reg_ext(:) ! extended longitudes
 
       integer :: nvarid,idim_index,idim_rlonu,idim_rlonv
@@ -53,4 +54,12 @@
 
 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
@@ -103,6 +112,10 @@
       ierr = NF_DEF_DIM (nid, "index", length, idim_index)
       ierr = NF_DEF_DIM (nid, "latitude", nbp_lat, idim_rlatu)
-      ierr = NF_DEF_DIM (nid, "longitude", nbp_lon+1, idim_rlonv)
-      ierr = NF_DEF_DIM (nid, "IR Wavenumber",L_NSPECTI,idim_bandsIR)
+      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, "IR_Wavenumber",L_NSPECTI,idim_bandsIR)
 
       ierr = NF_ENDDEF(nid)
@@ -149,5 +162,9 @@
       lon_reg_ext(1:nbp_lon)=lon_reg(1:nbp_lon)
       !add extra redundant point (180 degrees, since lon_reg starts at -180
-      lon_reg_ext(nbp_lon+1)=-lon_reg_ext(1)
+      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)
@@ -175,8 +192,8 @@
       ! define variable
 #ifdef NC_DOUBLE
-      ierr=NF_DEF_VAR(nid,"IR Wavenumber",NF_DOUBLE,1,
-     .                                idim_bandsIR,nvarid)
-#else
-      ierr=NF_DEF_VAR(nid,"IR Wavenumber",NF_FLOAT,1,
+      ierr=NF_DEF_VAR(nid,"IR_Wavenumber",NF_DOUBLE,1,
+     .                                idim_bandsIR,nvarid)
+#else
+      ierr=NF_DEF_VAR(nid,"IR_Wavenumber",NF_FLOAT,1,
      .                                idim_bandsIR,nvarid)
 #endif
@@ -199,8 +216,8 @@
       ! define variable
 #ifdef NC_DOUBLE
-      ierr=NF_DEF_VAR(nid,"IR Bandwidth",NF_DOUBLE,1,
-     .                                idim_bandsIR,nvarid)
-#else
-      ierr=NF_DEF_VAR(nid,"IR Bandwidth",NF_FLOAT,1,
+      ierr=NF_DEF_VAR(nid,"IR_Bandwidth",NF_DOUBLE,1,
+     .                                idim_bandsIR,nvarid)
+#else
+      ierr=NF_DEF_VAR(nid,"IR_Bandwidth",NF_FLOAT,1,
      .                                idim_bandsIR,nvarid)
 #endif
Index: trunk/LMDZ.GENERIC/libf/phystd/iniwrite_specVI.F
===================================================================
--- trunk/LMDZ.GENERIC/libf/phystd/iniwrite_specVI.F	(revision 1529)
+++ trunk/LMDZ.GENERIC/libf/phystd/iniwrite_specVI.F	(revision 1531)
@@ -1,3 +1,3 @@
-      SUBROUTINE iniwrite_specVI(nid,idayref,area)
+      SUBROUTINE iniwrite_specVI(nid,idayref,area,nbplon,nbplat)
 
       use radinc_h, only: L_NSPECTV
@@ -36,5 +36,6 @@
       integer,intent(in) :: nid        ! NetCDF file ID
       INTEGER*4,INTENT(IN) :: idayref  ! date (initial date for this run)
-      real,intent(in) :: area(nbp_lon+1,nbp_lat) ! mesh area (m2)
+      real,intent(in) :: area(nbplon,nbplat) ! mesh area (m2)
+      integer,intent(in) :: nbplon,nbplat ! sizes of area
 
 c   Local:
@@ -44,5 +45,5 @@
       REAL tab_cntrl(length) ! run parameters are stored in this array
       INTEGER ierr
-      REAl :: lon_reg_ext(nbp_lon+1) ! extended longitudes
+      REAl,ALLOCATABLE :: lon_reg_ext(:) ! extended longitudes
 
       integer :: nvarid,idim_index,idim_rlonu,idim_rlonv
@@ -53,4 +54,12 @@
 
 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
@@ -103,6 +112,10 @@
       ierr = NF_DEF_DIM (nid, "index", length, idim_index)
       ierr = NF_DEF_DIM (nid, "latitude", nbp_lat, idim_rlatu)
-      ierr = NF_DEF_DIM (nid, "longitude", nbp_lon+1, idim_rlonv)
-      ierr = NF_DEF_DIM (nid, "VI Wavenumber",L_NSPECTV,idim_bandsVI)
+      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, "VI_Wavenumber",L_NSPECTV,idim_bandsVI)
 
       ierr = NF_ENDDEF(nid)
@@ -148,5 +161,9 @@
       lon_reg_ext(1:nbp_lon)=lon_reg(1:nbp_lon)
       !add extra redundant point (180 degrees, since lon_reg starts at -180
-      lon_reg_ext(nbp_lon+1)=-lon_reg_ext(1)
+      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)
@@ -174,8 +191,8 @@
       ! define variable
 #ifdef NC_DOUBLE
-      ierr=NF_DEF_VAR(nid,"VI Wavenumber",NF_DOUBLE,1,
-     .                                idim_bandsVI,nvarid)
-#else
-      ierr=NF_DEF_VAR(nid,"VI Wavenumber",NF_FLOAT,1,
+      ierr=NF_DEF_VAR(nid,"VI_Wavenumber",NF_DOUBLE,1,
+     .                                idim_bandsVI,nvarid)
+#else
+      ierr=NF_DEF_VAR(nid,"VI_Wavenumber",NF_FLOAT,1,
      .                                idim_bandsVI,nvarid)
 #endif
@@ -199,8 +216,8 @@
       ! define variable
 #ifdef NC_DOUBLE
-      ierr=NF_DEF_VAR(nid,"VI Bandwidth",NF_DOUBLE,1,
-     .                                idim_bandsVI,nvarid)
-#else
-      ierr=NF_DEF_VAR(nid,"VI Bandwidth",NF_FLOAT,1,
+      ierr=NF_DEF_VAR(nid,"VI_Bandwidth",NF_DOUBLE,1,
+     .                                idim_bandsVI,nvarid)
+#else
+      ierr=NF_DEF_VAR(nid,"VI_Bandwidth",NF_FLOAT,1,
      .                                idim_bandsVI,nvarid)
 #endif
Index: trunk/LMDZ.GENERIC/libf/phystd/iniwritesoil.F90
===================================================================
--- trunk/LMDZ.GENERIC/libf/phystd/iniwritesoil.F90	(revision 1529)
+++ trunk/LMDZ.GENERIC/libf/phystd/iniwritesoil.F90	(revision 1531)
@@ -1,3 +1,3 @@
-subroutine iniwritesoil(nid,ngrid,inertia,area)
+subroutine iniwritesoil(nid,ngrid,inertia,area,nbplon,nbplat)
 
 ! initialization routine for 'writediagoil'. Here we create/define
@@ -17,6 +17,7 @@
 integer,intent(in) :: ngrid
 integer,intent(in) :: nid ! NetCDF output file ID
-real,intent(in) :: inertia(nbp_lon+1,nbp_lat,nsoilmx)
-real,intent(in) :: area(nbp_lon+1,nbp_lat) ! mesh area (m2)
+real,intent(in) :: inertia(nbplon,nbplat,nsoilmx)
+real,intent(in) :: area(nbplon,nbp_lat) ! mesh area (m2)
+integer,intent(in) :: nbplon,nbplat ! sizes of area
 
 ! Local variables:
@@ -33,5 +34,14 @@
 real,dimension(nbp_lon+1,nbp_lat,nsoilmx) :: data3 ! to store 3D data
 integer :: i,j,l,ig0
-real :: lon_reg_ext(nbp_lon+1) ! extended longitudes
+real,allocatable :: lon_reg_ext(:) ! extended longitudes
+
+
+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
 
 ! 1. Define the dimensions
@@ -40,5 +50,9 @@
 
 ! Define the dimensions
-ierr=NF_DEF_DIM(nid,"longitude",nbp_lon+1,idim_rlonv)
+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
 if (ierr.ne.NF_NOERR) then
   write(*,*)"iniwritesoil: Error, could not define longitude dimension"
@@ -82,6 +96,8 @@
 
 lon_reg_ext(1:nbp_lon)=lon_reg(1:nbp_lon)
-!add extra redundant point (180 degrees, since lon_reg starts at -180
-lon_reg_ext(nbp_lon+1)=-lon_reg_ext(1)
+if (nbp_lon*nbp_lat/=1) then ! in 3D only:
+  ! add extra redundant point (180 degrees, since lon_reg starts at -180
+  lon_reg_ext(nbp_lon+1)=-lon_reg_ext(1)
+endif
 
 ! Write longitude to file
Index: trunk/LMDZ.GENERIC/libf/phystd/mkstat.F90
===================================================================
--- trunk/LMDZ.GENERIC/libf/phystd/mkstat.F90	(revision 1529)
+++ trunk/LMDZ.GENERIC/libf/phystd/mkstat.F90	(revision 1531)
@@ -12,5 +12,5 @@
 use statto_mod, only: istime,count
 use mod_phys_lmdz_para, only : is_master
-use mod_grid_phy_lmdz, only : nbp_lon, nbp_lat, nbp_lev
+use mod_grid_phy_lmdz, only : nbp_lon, nbp_lat, nbp_lev, klon_glo
 
 implicit none
@@ -22,9 +22,9 @@
 integer, dimension(5) :: dimids
 character (len=50) :: name,nameout,units,title
-real, dimension(nbp_lon+1,nbp_lat,nbp_lev) :: sum3d,square3d,mean3d,sd3d
-real, dimension(nbp_lon+1,nbp_lat) :: sum2d,square2d,mean2d,sd2d
+real,allocatable :: sum3d(:,:,:),square3d(:,:,:),mean3d(:,:,:),sd3d(:,:,:)
+real,allocatable :: sum2d(:,:),square2d(:,:),mean2d(:,:),sd2d(:,:)
 real, dimension(istime) :: time
 real, dimension(nbp_lat) :: lat
-real, dimension(nbp_lon+1) :: lon
+real,allocatable :: lon(:)
 real, dimension(nbp_lev) :: alt
 logical :: lcopy=.true.
@@ -38,4 +38,25 @@
 if (is_master) then
 ! only the master needs do this
+if (klon_glo>1) then
+  allocate(lon(nbp_lon+1))
+  allocate(sum3d(nbp_lon+1,nbp_lat,nbp_lev))
+  allocate(square3d(nbp_lon+1,nbp_lat,nbp_lev))
+  allocate(mean3d(nbp_lon+1,nbp_lat,nbp_lev))
+  allocate(sd3d(nbp_lon+1,nbp_lat,nbp_lev))
+  allocate(sum2d(nbp_lon+1,nbp_lat))
+  allocate(square2d(nbp_lon+1,nbp_lat))
+  allocate(mean2d(nbp_lon+1,nbp_lat))
+  allocate(sd2d(nbp_lon+1,nbp_lat))
+else ! 1D model case
+  allocate(lon(1))
+  allocate(sum3d(1,1,nbp_lev))
+  allocate(square3d(1,1,nbp_lev))
+  allocate(mean3d(1,1,nbp_lev))
+  allocate(sd3d(1,1,nbp_lev))
+  allocate(sum2d(1,1))
+  allocate(square2d(1,1))
+  allocate(mean2d(1,1))
+  allocate(sd2d(1,1))
+endif
 
 ierr = NF_OPEN("stats.nc",NF_WRITE,nid)
@@ -105,5 +126,9 @@
 !      dimout(4)=timeid
 
-      size=(/nbp_lon+1,nbp_lat,nbp_lev,1/)
+      if (klon_glo>1) then ! general case
+        size=(/nbp_lon+1,nbp_lat,nbp_lev,1/)
+      else ! 1D model
+        size=(/1,1,nbp_lev,1/)
+      endif
       do lt=1,istime
          start=(/1,1,1,lt/)
@@ -135,5 +160,9 @@
 !      dimout(3)=timeid
 
-      size=(/nbp_lon+1,nbp_lat,1,0/)
+      if (klon_glo>1) then ! general case
+        size=(/nbp_lon+1,nbp_lat,1,0/)
+      else
+        size=(/1,1,1,0/)
+      endif
       do lt=1,istime
          start=(/1,1,lt,0/)
Index: trunk/LMDZ.GENERIC/libf/phystd/writediagfi.F
===================================================================
--- trunk/LMDZ.GENERIC/libf/phystd/writediagfi.F	(revision 1529)
+++ trunk/LMDZ.GENERIC/libf/phystd/writediagfi.F	(revision 1531)
@@ -63,4 +63,6 @@
       real*4 dx1(nbp_lev)           ! to store a 1D (column) data set
       real*4 dx0
+      real*4 dx3_1d(1,nbp_lev) ! to store a profile with 1D model
+      real*4 dx2_1d ! to store a surface value with 1D model
 
       real*4,save :: date
@@ -221,5 +223,6 @@
 
          ! Build phis() and area()
-         do i=1,nbp_lon+1 ! poles
+         IF (klon_glo>1) THEN
+          do i=1,nbp_lon+1 ! poles
            phis(i,1)=phisfi_glo(1)
            phis(i,nbp_lat)=phisfi_glo(klon_glo)
@@ -227,6 +230,6 @@
            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
+          enddo
+          do j=2,nbp_lat-1
            ig0= 1+(j-2)*nbp_lon
            do i=1,nbp_lon
@@ -237,8 +240,13 @@
            phis(nbp_lon+1,j)=phis(1,j)
            area(nbp_lon+1,j)=area(1,j)
-         enddo
+          enddo
+         ENDIF
          
          ! write "header" of file (longitudes, latitudes, geopotential, ...)
-         call iniwrite(nid,day_ini,phis,area)
+         IF (klon_glo>1) THEN ! general 3D case
+           call iniwrite(nid,day_ini,phis,area,nbp_lon+1,nbp_lat)
+         ELSE ! 1D model
+           call iniwrite(nid,day_ini,phisfi_glo(1),areafi_glo(1),1,1)
+         ENDIF
 
          endif ! of if (is_master)
@@ -255,10 +263,9 @@
       endif ! if (firstnom.eq.'1234567890')
 
-      if (ngrid.eq.1) then
+      if (klon_glo.eq.1) then
         ! in testphys1d, for the 1d version of the GCM, iphysiq and irythme
         ! are undefined; so set them to 1
         iphysiq=1 
         irythme=1
-        ! NB: 
       endif
 
@@ -327,4 +334,5 @@
 !         Passage variable physique -->  variable dynamique
 !         recast (copy) variable from physics grid to dynamics grid
+          IF (klon_glo>1) THEN ! General case
            DO l=1,nbp_lev
              DO i=1,nbp_lon+1
@@ -340,4 +348,7 @@
              ENDDO
            ENDDO
+          ELSE ! 1D model case
+           dx3_1d(1,1:nbp_lev)=px(1,1:nbp_lev)
+          ENDIF
 #endif
 !         Ecriture du champs
@@ -367,5 +378,9 @@
            corner(4)=ntime
 
-           edges(1)=nbp_lon+1
+           IF (klon_glo==1) THEN
+             edges(1)=1
+           ELSE
+             edges(1)=nbp_lon+1
+           ENDIF
            edges(2)=nbp_lat
            edges(3)=nbp_lev
@@ -378,12 +393,16 @@
 !           write(*,*)"       edges()=",edges
 !           write(*,*)"       dx3()=",dx3
-           ierr= NF_PUT_VARA_REAL(nid,varid,corner,edges,dx3)
+           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 writediagfi"
-              write(*,*) "***** with ",nom
+              write(*,*) "***** with dx3: ",nom
               write(*,*) 'ierr=', ierr,": ",NF_STRERROR(ierr)
-c             call abort
+              stop
            endif 
 
@@ -412,5 +431,5 @@
 !         Passage variable physique -->  physique dynamique
 !         recast (copy) variable from physics grid to dynamics grid
-
+          IF (klon_glo>1) THEN ! General case
              DO i=1,nbp_lon+1
                 dx2(i,1)=px(1,1)
@@ -424,4 +443,7 @@
                 dx2(nbp_lon+1,j)=dx2(1,j)
              ENDDO
+          ELSE ! 1D model case
+            dx2_1d=px(1,1)
+          ENDIF
 #endif
 
@@ -449,5 +471,9 @@
            corner(2)=1
            corner(3)=ntime
-           edges(1)=nbp_lon+1
+           IF (klon_glo==1) THEN
+             edges(1)=1
+           ELSE
+             edges(1)=nbp_lon+1
+           ENDIF
            edges(2)=nbp_lat
            edges(3)=1
@@ -457,12 +483,16 @@
 !           ierr = NF_PUT_VARA_DOUBLE (nid,varid,corner,edges,dx2) 
 !#else         
-           ierr= NF_PUT_VARA_REAL(nid,varid,corner,edges,dx2)
+           IF (klon_glo>1) THEN ! General case
+             ierr= NF_PUT_VARA_REAL(nid,varid,corner,edges,dx2)
+           ELSE
+             ierr= NF_PUT_VARA_REAL(nid,varid,corner,edges,dx2_1d)
+           ENDIF
 !#endif     
 
            if (ierr.ne.NF_NOERR) then
               write(*,*) "***** PUT_VAR matter in writediagfi"
-              write(*,*) "***** with ",nom
+              write(*,*) "***** with dx2: ",nom
               write(*,*) 'ierr=', ierr,": ",NF_STRERROR(ierr)
-c             call abort
+              stop
            endif 
 
@@ -512,7 +542,7 @@
            if (ierr.ne.NF_NOERR) then
               write(*,*) "***** PUT_VAR problem in writediagfi"
-              write(*,*) "***** with ",nom
+              write(*,*) "***** with dx1: ",nom
               write(*,*) 'ierr=', ierr,": ",NF_STRERROR(ierr)
-c             call abort
+              stop
            endif 
 
@@ -550,7 +580,7 @@
            if (ierr.ne.NF_NOERR) then
               write(*,*) "***** PUT_VAR matter in writediagfi"
-              write(*,*) "***** with ",nom
+              write(*,*) "***** with dx0: ",nom
               write(*,*) 'ierr=', ierr,": ",NF_STRERROR(ierr)
-c             call abort
+              stop
            endif 
 
Index: trunk/LMDZ.GENERIC/libf/phystd/writediagsoil.F90
===================================================================
--- trunk/LMDZ.GENERIC/libf/phystd/writediagsoil.F90	(revision 1529)
+++ trunk/LMDZ.GENERIC/libf/phystd/writediagsoil.F90	(revision 1531)
@@ -36,4 +36,6 @@
 real*4,dimension(nbp_lon+1,nbp_lat) :: data2 ! to store 2D data
 real*4 :: data0 ! to store 0D data
+real*4 :: data3_1d(1,nsoilmx) ! to store a profile in 1D model
+real*4 :: data2_1d ! to store surface value with 1D model
 integer :: i,j,l ! for loops
 integer :: ig0
@@ -108,5 +110,6 @@
 
    ! build inertia() and area()
-   do i=1,nbp_lon+1 ! poles
+   if (klon_glo>1) then
+    do i=1,nbp_lon+1 ! poles
      inertia(i,1,1:nsoilmx)=inertiafi_glo(1,1:nsoilmx)
      inertia(i,nbp_lat,1:nsoilmx)=inertiafi_glo(klon_glo,1:nsoilmx)
@@ -114,6 +117,6 @@
      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
+    enddo
+    do j=2,nbp_lat-1
      ig0= 1+(j-2)*nbp_lon
      do i=1,nbp_lon
@@ -124,8 +127,13 @@
      inertia(nbp_lon+1,j,1:nsoilmx)=inertia(1,j,1:nsoilmx)
      area(nbp_lon+1,j)=area(1,j)
-   enddo
+    enddo
+   endif
    
    ! write "header" of file (longitudes, latitudes, geopotential, ...)
-   call iniwritesoil(nid,ngrid,inertia,area)
+   if (klon_glo>1) then ! general 3D case
+     call iniwritesoil(nid,ngrid,inertia,area,nbp_lon+1,nbp_lat)
+   else ! 1D model
+     call iniwritesoil(nid,ngrid,inertiafi_glo(1,:),areafi_glo(1),1,1)
+   endif
 
   endif ! of if (is_master)
@@ -189,5 +197,6 @@
 !$OMP BARRIER
 #else
-  do l=1,nsoilmx
+  if (klon_glo>1) then ! General case
+   do l=1,nsoilmx
     ! handle the poles
     do i=1,nbp_lon+1
@@ -203,5 +212,8 @@
       data3(nbp_lon+1,j,l)=data3(1,j,l) ! extra (modulo) longitude
     enddo
-  enddo
+   enddo
+  else ! 1D model case
+   data3_1d(1,1:nsoilmx)=px(1,1:nsoilmx)
+  endif
 #endif
   
@@ -230,5 +242,9 @@
   corners(4)=ntime
   
-  edges(1)=nbp_lon+1
+  if (klon_glo==1) then
+    edges(1)=1
+  else
+    edges(1)=nbp_lon+1
+  endif
   edges(2)=nbp_lat
   edges(3)=nsoilmx
@@ -239,5 +255,9 @@
 !  ierr=NF_PUT_VARA_DOUBLE(nid,varid,corners,edges,data3)
 !#else
-  ierr=NF_PUT_VARA_REAL(nid,varid,corners,edges,data3)
+  if (klon_glo>1) then
+    ierr=NF_PUT_VARA_REAL(nid,varid,corners,edges,data3)
+  else
+    ierr=NF_PUT_VARA_REAL(nid,varid,corners,edges,data3_1d)
+  endif
 !#endif
   if (ierr.ne.NF_NOERR) then
@@ -264,17 +284,21 @@
 !$OMP BARRIER
 #else
-  ! handle the poles
-  do i=1,nbp_lon+1
-    data2(i,1)=px(1,1)
-    data2(i,nbp_lat)=px(ngrid,1)
-  enddo
-  ! rest of the grid
-  do j=2,nbp_lat-1
-    ig0=1+(j-2)*nbp_lon
-    do i=1,nbp_lon
-      data2(i,j)=px(ig0+i,1)
-    enddo
-    data2(nbp_lon+1,j)=data2(1,j) ! extra (modulo) longitude
-  enddo
+  if (klon_glo>1) then ! general case
+    ! handle the poles
+    do i=1,nbp_lon+1
+      data2(i,1)=px(1,1)
+      data2(i,nbp_lat)=px(ngrid,1)
+    enddo
+    ! rest of the grid
+    do j=2,nbp_lat-1
+      ig0=1+(j-2)*nbp_lon
+      do i=1,nbp_lon
+        data2(i,j)=px(ig0+i,1)
+      enddo
+      data2(nbp_lon+1,j)=data2(1,j) ! extra (modulo) longitude
+    enddo
+  else ! 1D model case
+    data2_1d=px(1,1)
+  endif
 #endif
 
@@ -301,5 +325,9 @@
   corners(3)=ntime
   
-  edges(1)=nbp_lon+1
+  if (klon_glo==1) then
+    edges(1)=1
+  else
+    edges(1)=nbp_lon+1
+  endif
   edges(2)=nbp_lat
   edges(3)=1
@@ -309,5 +337,9 @@
 !  ierr=NF_PUT_VARA_DOUBLE(nid,varid,corners,edges,data2)
 !#else
-  ierr=NF_PUT_VARA_REAL(nid,varid,corners,edges,data2)
+  if (klon_glo>1) then ! General case
+    ierr=NF_PUT_VARA_REAL(nid,varid,corners,edges,data2)
+  else
+    ierr=NF_PUT_VARA_REAL(nid,varid,corners,edges,data2_1d)
+  endif
 !#endif
   if (ierr.ne.NF_NOERR) then
Index: trunk/LMDZ.GENERIC/libf/phystd/writediagspecIR.F
===================================================================
--- trunk/LMDZ.GENERIC/libf/phystd/writediagspecIR.F	(revision 1529)
+++ trunk/LMDZ.GENERIC/libf/phystd/writediagspecIR.F	(revision 1531)
@@ -87,5 +87,6 @@
       real area((nbp_lon+1),nbp_lat)
 ! added by RDW for OLR output
-       real dx3(nbp_lon+1,nbp_lat,L_NSPECTI) ! to store the data set
+      real dx3(nbp_lon+1,nbp_lat,L_NSPECTI) ! to store the data set
+      real dx3_1d(1,L_NSPECTI) ! to store the data with 1D model
 
 #ifdef CPP_PARA
@@ -152,10 +153,11 @@
 
          ! Build area()
-         do i=1,nbp_lon+1 ! poles
+         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
+          enddo
+          do j=2,nbp_lat-1
            ig0= 1+(j-2)*nbp_lon
            do i=1,nbp_lon
@@ -164,8 +166,13 @@
            ! handle redundant point in longitude
            area(nbp_lon+1,j)=area(1,j)
-         enddo
+          enddo
+         ENDIF
 
          ! write "header" of file (longitudes, latitudes, area, ...)
-         call iniwrite_specIR(nid,day_ini,area)
+         IF (klon_glo>1) THEN ! general 3D case
+           call iniwrite_specIR(nid,day_ini,area,nbp_lon+1,nbp_lat)
+         ELSE
+           call iniwrite_specIR(nid,day_ini,areafi_glo(1),1,1)
+         ENDIF
          endif ! of if (is_master)
 
@@ -245,4 +252,5 @@
 !$OMP BARRIER
 #else
+          IF (klon_glo>1) THEN ! General case
            DO l=1,L_NSPECTI
              DO i=1,nbp_lon+1
@@ -258,4 +266,7 @@
              ENDDO
            ENDDO
+          ELSE ! 1D model case
+            dx3_1d(1,1:L_NSPECTI)=px(1,1:L_NSPECTI)
+          ENDIF
 #endif
 
@@ -269,5 +280,5 @@
               ierr= NF_INQ_DIMID(nid,"longitude",id(1))
               ierr= NF_INQ_DIMID(nid,"latitude",id(2))
-              ierr= NF_INQ_DIMID(nid,"IR Wavenumber",id(3))
+              ierr= NF_INQ_DIMID(nid,"IR_Wavenumber",id(3))
               ierr= NF_INQ_DIMID(nid,"Time",id(4))
 
@@ -285,12 +296,24 @@
            corner(4)=ntime
 
-           edges(1)=nbp_lon+1
+           IF (klon_glo==1) THEN
+             edges(1)=1
+           ELSE
+             edges(1)=nbp_lon+1
+           ENDIF
            edges(2)=nbp_lat
            edges(3)=L_NSPECTI
            edges(4)=1
 #ifdef NC_DOUBLE
-           ierr= NF_PUT_VARA_DOUBLE(nid,varid,corner,edges,dx3)
-#else
-           ierr= NF_PUT_VARA_REAL(nid,varid,corner,edges,dx3)
+           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
 
Index: trunk/LMDZ.GENERIC/libf/phystd/writediagspecVI.F
===================================================================
--- trunk/LMDZ.GENERIC/libf/phystd/writediagspecVI.F	(revision 1529)
+++ trunk/LMDZ.GENERIC/libf/phystd/writediagspecVI.F	(revision 1531)
@@ -87,5 +87,6 @@
       real area((nbp_lon+1),nbp_lat)
 ! added by RDW for OSR output
-       real dx3(nbp_lon+1,nbp_lat,L_NSPECTV) ! to store the data set
+      real dx3(nbp_lon+1,nbp_lat,L_NSPECTV) ! to store the data set
+      real dx3_1d(1,L_NSPECTV) ! to store the data with 1D model
 
 #ifdef CPP_PARA
@@ -151,10 +152,11 @@
 
          ! Build area()
-         do i=1,nbp_lon+1 ! poles
+         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
+          enddo
+          do j=2,nbp_lat-1
            ig0= 1+(j-2)*nbp_lon
            do i=1,nbp_lon
@@ -163,8 +165,13 @@
            ! handle redundant point in longitude
            area(nbp_lon+1,j)=area(1,j)
-         enddo
+          enddo
+         ENDIF
 
          ! write "header" of file (longitudes, latitudes, geopotential, ...)
-         call iniwrite_specVI(nid,day_ini,area)
+         IF (klon_glo>1) THEN ! general 3D case
+           call iniwrite_specVI(nid,day_ini,area,nbp_lon+1,nbp_lat)
+         ELSE
+           call iniwrite_specVI(nid,day_ini,areafi_glo(1),1,1)
+         ENDIF
          endif ! of if (is_master)
 
@@ -244,4 +251,5 @@
 !$OMP BARRIER
 #else
+          IF (klon_glo>1) THEN ! General case
            DO l=1,L_NSPECTV
              DO i=1,nbp_lon+1
@@ -257,4 +265,7 @@
              ENDDO
            ENDDO
+          ELSE ! 1D model case
+           dx3_1d(1,1:L_NSPECTV)=px(1,1:L_NSPECTV)
+          ENDIF
 #endif
 
@@ -268,5 +279,5 @@
               ierr= NF_INQ_DIMID(nid,"longitude",id(1))
               ierr= NF_INQ_DIMID(nid,"latitude",id(2))
-              ierr= NF_INQ_DIMID(nid,"VI Wavenumber",id(3))
+              ierr= NF_INQ_DIMID(nid,"VI_Wavenumber",id(3))
               ierr= NF_INQ_DIMID(nid,"Time",id(4))
 
@@ -284,12 +295,24 @@
            corner(4)=ntime
 
-           edges(1)=nbp_lon+1
+           IF (klon_glo==1) THEN
+             edges(1)=1
+           ELSE
+             edges(1)=nbp_lon+1
+           ENDIF
            edges(2)=nbp_lat
            edges(3)=L_NSPECTV
            edges(4)=1
 #ifdef NC_DOUBLE
-           ierr= NF_PUT_VARA_DOUBLE(nid,varid,corner,edges,dx3)
-#else
-           ierr= NF_PUT_VARA_REAL(nid,varid,corner,edges,dx3)
+           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
 
Index: trunk/LMDZ.GENERIC/libf/phystd/wstats.F90
===================================================================
--- trunk/LMDZ.GENERIC/libf/phystd/wstats.F90	(revision 1529)
+++ trunk/LMDZ.GENERIC/libf/phystd/wstats.F90	(revision 1531)
@@ -13,6 +13,6 @@
 integer,intent(in) :: dim
 real,intent(in) :: px(ngrid,nbp_lev)
-real, dimension(nbp_lon+1,nbp_lat,nbp_lev) :: mean3d,sd3d,dx3
-real, dimension(nbp_lon+1,nbp_lat) :: mean2d,sd2d,dx2
+real,allocatable,save :: mean3d(:,:,:),sd3d(:,:,:),dx3(:,:,:)
+real,allocatable,save :: mean2d(:,:),sd2d(:,:),dx2(:,:)
 character (len=50) :: namebis
 character (len=50), save :: firstvar
@@ -49,4 +49,19 @@
    firstvar=trim((nom))
    call inistats(ierr)
+   if (klon_glo>1) then ! general case, 3D GCM
+     allocate(mean3d(nbp_lon+1,nbp_lat,nbp_lev))
+     allocate(sd3d(nbp_lon+1,nbp_lat,nbp_lev))
+     allocate(dx3(nbp_lon+1,nbp_lat,nbp_lev))
+     allocate(mean2d(nbp_lon+1,nbp_lat))
+     allocate(sd2d(nbp_lon+1,nbp_lat))
+     allocate(dx2(nbp_lon+1,nbp_lat))
+   else ! 1D model
+     allocate(mean3d(1,1,nbp_lev))
+     allocate(sd3d(1,1,nbp_lev))
+     allocate(dx3(1,1,nbp_lev))
+     allocate(mean2d(1,1))
+     allocate(sd2d(1,1))
+     allocate(dx2(1,1))
+   endif
 endif
 
@@ -194,10 +209,18 @@
    if (dim.eq.3) then
       start=(/1,1,1,indx/)
-      sizes=(/nbp_lon+1,nbp_lat,nbp_lev,1/)
+      if (klon_glo>1) then !general case
+        sizes=(/nbp_lon+1,nbp_lat,nbp_lev,1/)
+      else
+        sizes=(/1,1,nbp_lev,1/)
+      endif
       mean3d(:,:,:)=0
       sd3d(:,:,:)=0
    else if (dim.eq.2) then
       start=(/1,1,indx,0/)
-      sizes=(/nbp_lon+1,nbp_lev,1,0/)
+      if (klon_glo>1) then !general case
+        sizes=(/nbp_lon+1,nbp_lev,1,0/)
+      else
+        sizes=(/1,1,1,0/)
+      endif
       mean2d(:,:)=0
       sd2d(:,:)=0
@@ -207,5 +230,9 @@
    if (dim.eq.3) then
       start=(/1,1,1,indx/)
-      sizes=(/nbp_lon+1,nbp_lat,nbp_lev,1/)
+      if (klon_glo>1) then !general case
+        sizes=(/nbp_lon+1,nbp_lat,nbp_lev,1/)
+      else ! 1D model case
+        sizes=(/1,1,nbp_lev,1/)
+      endif
 #ifdef NC_DOUBLE
       ierr = NF_GET_VARA_DOUBLE(nid,meanid,start,sizes,mean3d)
@@ -216,4 +243,5 @@
 #endif
       if (ierr.ne.NF_NOERR) then
+         write (*,*) "wstats error reading :",trim(nom)
          write (*,*) NF_STRERROR(ierr)
          stop ""
@@ -222,5 +250,9 @@
    else if (dim.eq.2) then
       start=(/1,1,indx,0/)
-      sizes=(/nbp_lon+1,nbp_lat,1,0/)
+      if (klon_glo>1) then ! general case
+        sizes=(/nbp_lon+1,nbp_lat,1,0/)
+      else
+        sizes=(/1,1,1,0/)
+      endif
 #ifdef NC_DOUBLE
       ierr = NF_GET_VARA_DOUBLE(nid,meanid,start,sizes,mean2d)
@@ -231,4 +263,5 @@
 #endif
       if (ierr.ne.NF_NOERR) then
+         write (*,*) "wstats error reading :",trim(nom)
          write (*,*) NF_STRERROR(ierr)
          stop ""
@@ -242,8 +275,12 @@
 if (dim.eq.3) then
   dx3(1:nbp_lon,:,:)=px3_glo(:,:,:)
-  dx3(nbp_lon+1,:,:)=dx3(1,:,:)
+  IF (klon_glo>1) THEN ! in 3D, add redundant longitude point
+    dx3(nbp_lon+1,:,:)=dx3(1,:,:)
+  ENDIF
 else ! dim.eq.2
   dx2(1:nbp_lon,:)=px2_glo(:,:)
-  dx2(nbp_lon+1,:)=dx2(1,:)
+  IF (klon_glo>1) THEN ! in 3D, add redundant longitude point
+    dx2(nbp_lon+1,:)=dx2(1,:)
+  ENDIF
 endif
 
@@ -263,4 +300,9 @@
    ierr = NF_PUT_VARA_REAL(nid,sdid,start,sizes,sd3d)
 #endif
+  if (ierr.ne.NF_NOERR) then
+     write (*,*) "wstats error writing :",trim(nom)
+     write (*,*) NF_STRERROR(ierr)
+     stop ""
+  endif
 
 else if (dim.eq.2) then
@@ -276,4 +318,13 @@
    ierr = NF_PUT_VARA_REAL(nid,sdid,start,sizes,sd2d)
 #endif
+  if (ierr.ne.NF_NOERR) then
+     write (*,*) "wstats error writing :",trim(nom)
+     write(*,*) "start:",start
+     write(*,*) "sizes:",sizes
+     write(*,*) "mean2d:",mean2d
+     write(*,*) "sd2d:",sd2d
+     write (*,*) NF_STRERROR(ierr)
+     stop ""
+  endif
 
 endif ! of if (dim.eq.3) elseif (dim.eq.2)
@@ -286,5 +337,5 @@
 !======================================================
 subroutine inivar(nid,varid,ngrid,dim,indx,px,ierr)
-use mod_grid_phy_lmdz, only : nbp_lon, nbp_lat, nbp_lev
+use mod_grid_phy_lmdz, only : nbp_lon, nbp_lat, nbp_lev, klon_glo
 
 implicit none
@@ -300,13 +351,20 @@
 real, dimension(nbp_lon+1,nbp_lat,nbp_lev) :: dx3
 real, dimension(nbp_lon+1,nbp_lat) :: dx2
+real :: dx3_1d(nbp_lev) ! for 1D outputs
+real :: dx2_1d ! for 1D outputs
 
 if (dim.eq.3) then
 
    start=(/1,1,1,indx/)
-   sizes=(/nbp_lon+1,nbp_lat,nbp_lev,1/)
+   if (klon_glo>1) then ! general 3D case
+     sizes=(/nbp_lon+1,nbp_lat,nbp_lev,1/)
+   else
+     sizes=(/1,1,nbp_lev,1/)
+   endif
 
 !  Passage variable physique -->  variable dynamique
 
-   DO l=1,nbp_lev
+   if (klon_glo>1) then ! general case
+    DO l=1,nbp_lev
       DO i=1,nbp_lon+1
          dx3(i,1,l)=px(1,l)
@@ -320,19 +378,40 @@
          dx3(nbp_lon+1,j,l)=dx3(1,j,l)
       ENDDO
-   ENDDO
-
-#ifdef NC_DOUBLE
-   ierr = NF_PUT_VARA_DOUBLE(nid,varid,start,sizes,dx3)
-#else
-   ierr = NF_PUT_VARA_REAL(nid,varid,start,sizes,dx3)
-#endif
+    ENDDO
+   else ! 1D model case
+     dx3_1d(1:nbp_lev)=px(1,1:nbp_lev)
+   endif
+
+#ifdef NC_DOUBLE
+   if (klon_glo>1) then
+     ierr = NF_PUT_VARA_DOUBLE(nid,varid,start,sizes,dx3)
+   else
+     ierr = NF_PUT_VARA_DOUBLE(nid,varid,start,sizes,dx3_1d)
+   endif
+#else
+   if (klon_glo>1) then
+     ierr = NF_PUT_VARA_REAL(nid,varid,start,sizes,dx3)
+   else
+     ierr = NF_PUT_VARA_REAL(nid,varid,start,sizes,dx3_1d)
+   endif
+#endif
+  if (ierr.ne.NF_NOERR) then
+     write (*,*) "inivar error writing variable"
+     write (*,*) NF_STRERROR(ierr)
+     stop ""
+  endif
 
 else if (dim.eq.2) then
 
       start=(/1,1,indx,0/)
-      sizes=(/nbp_lon+1,nbp_lat,1,0/)
+      if (klon_glo>1) then ! general 3D case
+        sizes=(/nbp_lon+1,nbp_lat,1,0/)
+      else
+        sizes=(/1,1,1,0/)
+      endif
 
 !    Passage variable physique -->  physique dynamique
 
+  if (klon_glo>1) then ! general case
   DO i=1,nbp_lon+1
      dx2(i,1)=px(1,1)
@@ -346,10 +425,26 @@
      dx2(nbp_lon+1,j)=dx2(1,j)
   ENDDO
-
-#ifdef NC_DOUBLE
-   ierr = NF_PUT_VARA_DOUBLE(nid,varid,start,sizes,dx2)
-#else
-   ierr = NF_PUT_VARA_REAL(nid,varid,start,sizes,dx2)
-#endif
+  else ! 1D model case
+    dx2_1d=px(1,1)
+  endif
+  
+#ifdef NC_DOUBLE
+   if (klon_glo>1) then
+     ierr = NF_PUT_VARA_DOUBLE(nid,varid,start,sizes,dx2)
+   else
+     ierr = NF_PUT_VARA_DOUBLE(nid,varid,start,sizes,dx2_1d)
+   endif
+#else
+   if (klon_glo>1) then
+     ierr = NF_PUT_VARA_REAL(nid,varid,start,sizes,dx2)
+   else
+     ierr = NF_PUT_VARA_REAL(nid,varid,start,sizes,dx2_1d)
+   endif
+#endif
+  if (ierr.ne.NF_NOERR) then
+     write (*,*) "inivar error writing variable"
+     write (*,*) NF_STRERROR(ierr)
+     stop ""
+  endif
 
 endif
