Index: codes/icosagcm/trunk/src/write_field.f90
===================================================================
--- codes/icosagcm/trunk/src/write_field.f90	(revision 92)
+++ codes/icosagcm/trunk/src/write_field.f90	(revision 93)
@@ -61,5 +61,5 @@
     end function GetFieldIndex
     
-    SUBROUTINE Writefield(name_in,field,nind)
+    SUBROUTINE Writefield(name_in,field,nind,once)
     USE domain_mod
     USE field_mod
@@ -71,4 +71,6 @@
       TYPE(t_field),POINTER :: field(:)
       INTEGER,OPTIONAL,INTENT(IN) :: nind
+      LOGICAL,OPTIONAL,INTENT(IN) :: once
+      
       TYPE(t_field),POINTER :: field_glo(:)
       
@@ -85,7 +87,7 @@
       IF (mpi_rank==0) THEN
         IF (PRESENT(nind)) THEN
-         CALL writefield_gen(name_in,field_glo,domain_glo,nind)
+         CALL writefield_gen(name_in,field_glo,domain_glo,nind,once=once)
         ELSE
-         CALL writefield_gen(name_in,field_glo,domain_glo,1,ndomain_glo)
+         CALL writefield_gen(name_in,field_glo,domain_glo,1,ndomain_glo,once=once)
         ENDIF
       ENDIF
@@ -320,5 +322,5 @@
 
 
-    SUBROUTINE Writefield_gen(name_in, field, domain_type, ind_b_in, ind_e_in )
+    SUBROUTINE Writefield_gen(name_in, field, domain_type, ind_b_in, ind_e_in,once )
     USE netcdf_mod
     USE domain_mod
@@ -335,4 +337,5 @@
       REAL(r8),ALLOCATABLE :: field_val3d(:,:)
       REAL(r8),ALLOCATABLE :: field_val4d(:,:,:)
+      LOGICAL,OPTIONAL, INTENT(IN) :: once
       TYPE(t_domain),POINTER :: d
       INTEGER :: Index
@@ -375,5 +378,5 @@
       Index=GetFieldIndex(name)
       if (Index==-1) then
-        call create_header_gen(name_in,field,domain_type,ind_b_in,ind_e_in)
+        call create_header_gen(name_in,field,domain_type,ind_b_in,ind_e_in,once)
 	Index=GetFieldIndex(name)
       else
@@ -408,6 +411,13 @@
             ENDDO
           ENDDO
-          status=NF90_PUT_VAR(FieldId(Index),FieldVarId(index)%nc_id(1),Field_val2d,  &
-                              start=(/ 1,FieldIndex(Index) /),count=(/ncell,1 /))
+
+          IF (PRESENT(once) .AND. once) THEN 
+            status=NF90_PUT_VAR(FieldId(Index),FieldVarId(index)%nc_id(1),Field_val2d,  &
+                               start=(/ 1 /),count=(/ncell /))
+          ELSE
+            status=NF90_PUT_VAR(FieldId(Index),FieldVarId(index)%nc_id(1),Field_val2d,  &
+                               start=(/ 1,FieldIndex(Index) /),count=(/ncell,1 /))
+          ENDIF
+          
           DEALLOCATE(field_val2d)
         ELSE IF (field(1)%ndim==3) THEN
@@ -427,6 +437,12 @@
           ENDDO
            
-          status=NF90_PUT_VAR(FieldId(Index),FieldVarId(index)%nc_id(1),Field_val3d,start=(/ 1,1,FieldIndex(Index) /),   &
-                               count=(/ncell,size(field(1)%rval3d,2),1 /))
+          IF (PRESENT(once) .AND. once) THEN 
+            status=NF90_PUT_VAR(FieldId(Index),FieldVarId(index)%nc_id(1),Field_val3d,start=(/ 1,1 /),   &
+                                 count=(/ncell,size(field(1)%rval3d,2) /))
+          ELSE
+             status=NF90_PUT_VAR(FieldId(Index),FieldVarId(index)%nc_id(1),Field_val3d,start=(/ 1,1,FieldIndex(Index) /),   &
+                                 count=(/ncell,size(field(1)%rval3d,2),1 /))
+          ENDIF
+                                
           DEALLOCATE(field_val3d)
         ELSE IF (field(1)%ndim==4) THEN
@@ -449,6 +465,11 @@
             ENDDO
             
-            status=NF90_PUT_VAR(FieldId(Index),FieldVarId(index)%nc_id(q),Field_val3d,start=(/ 1,1,FieldIndex(Index) /),   &
-                               count=(/ncell,size(field(1)%rval4d,2),1 /))
+            IF (PRESENT(once) .AND. once) THEN 
+              status=NF90_PUT_VAR(FieldId(Index),FieldVarId(index)%nc_id(q),Field_val3d,start=(/ 1,1 /),   &
+                                 count=(/ncell,size(field(1)%rval4d,2),1 /))
+            ELSE
+              status=NF90_PUT_VAR(FieldId(Index),FieldVarId(index)%nc_id(q),Field_val3d,start=(/ 1,1,FieldIndex(Index) /),   &
+                                 count=(/ncell,size(field(1)%rval4d,2),1 /))
+            ENDIF
             DEALLOCATE(field_val3d)
           ENDDO         
@@ -503,6 +524,11 @@
           ENDDO
           
-          status=NF90_PUT_VAR(FieldId(Index),FieldVarId(index)%nc_id(1),                       &
-                              Field_val2d,start=(/ 1,FieldIndex(Index) /),count=(/ncell,1 /))
+          IF (PRESENT(once) .AND. once) THEN 
+            status=NF90_PUT_VAR(FieldId(Index),FieldVarId(index)%nc_id(1),                       &
+                                Field_val2d,start=(/ 1 /),count=(/ncell /))
+           ELSE
+            status=NF90_PUT_VAR(FieldId(Index),FieldVarId(index)%nc_id(1),                       &
+                                Field_val2d,start=(/ 1,FieldIndex(Index) /),count=(/ncell,1 /))
+          ENDIF
           DEALLOCATE(field_val2d)
 
@@ -529,6 +555,11 @@
           ENDDO
           
-          status=NF90_PUT_VAR(FieldId(Index),FieldVarId(index)%nc_id(1),Field_val3d,start=(/ 1,1,FieldIndex(Index) /),   &
-                              count=(/ncell,size(field(1)%rval3d,2),1 /))
+          IF (PRESENT(once) .AND. once) THEN 
+            status=NF90_PUT_VAR(FieldId(Index),FieldVarId(index)%nc_id(1),Field_val3d,start=(/ 1,1 /),   &
+                                count=(/ncell,size(field(1)%rval3d,2) /))
+          ELSE
+            status=NF90_PUT_VAR(FieldId(Index),FieldVarId(index)%nc_id(1),Field_val3d,start=(/ 1,1,FieldIndex(Index) /),   &
+                                count=(/ncell,size(field(1)%rval3d,2),1 /))
+          ENDIF
           DEALLOCATE(field_val3d)
         
@@ -557,6 +588,11 @@
             ENDDO
 
-            status=NF90_PUT_VAR(FieldId(Index),FieldVarId(index)%nc_id(q),Field_val3d,start=(/ 1,1,1,FieldIndex(Index) /),   &
-                                count=(/ncell,size(field(1)%rval4d,2),1 /))
+            IF (PRESENT(once) .AND. once) THEN 
+              status=NF90_PUT_VAR(FieldId(Index),FieldVarId(index)%nc_id(q),Field_val3d,start=(/ 1,1,1 /),   &
+                                  count=(/ncell,size(field(1)%rval4d,2) /))
+            ELSE
+              status=NF90_PUT_VAR(FieldId(Index),FieldVarId(index)%nc_id(q),Field_val3d,start=(/ 1,1,1,FieldIndex(Index) /),   &
+                                  count=(/ncell,size(field(1)%rval4d,2),1 /))
+            ENDIF
             DEALLOCATE(field_val3d)
           ENDDO
@@ -1111,5 +1147,5 @@
 
    
-    SUBROUTINE Create_header_gen(name_in,field,domain_type,ind_b_in,ind_e_in)
+    SUBROUTINE Create_header_gen(name_in,field,domain_type,ind_b_in,ind_e_in,once)
     USE netcdf_mod
     USE field_mod
@@ -1125,4 +1161,6 @@
       INTEGER,OPTIONAL,INTENT(IN) :: ind_b_in
       INTEGER,OPTIONAL,INTENT(IN) :: ind_e_in
+      LOGICAL,OPTIONAL,INTENT(IN) :: once
+      
       INTEGER :: ncell
       INTEGER :: nvert
@@ -1220,13 +1258,26 @@
 
         IF (Field(ind_b)%ndim==2) THEN
-          status = NF90_DEF_VAR(ncid,TRIM(ADJUSTL(name)),ncprec,(/ ncellId,timeId /),FieldVarId(NbField)%nc_id(1))
+          IF (PRESENT(once) .AND. once) THEN 
+            status = NF90_DEF_VAR(ncid,TRIM(ADJUSTL(name)),ncprec,(/ ncellId /),FieldVarId(NbField)%nc_id(1))
+          ELSE
+             status = NF90_DEF_VAR(ncid,TRIM(ADJUSTL(name)),ncprec,(/ ncellId,timeId /),FieldVarId(NbField)%nc_id(1))
+          ENDIF
           status = NF90_PUT_ATT(ncid,FieldVarId(NbField)%nc_id(1),"coordinates","lon_i lat_i")
         ELSE IF (Field(ind_b)%ndim==3) THEN
-          status = NF90_DEF_VAR(ncid,TRIM(ADJUSTL(name)),ncprec,(/ ncellId,dim3id,timeId /),FieldVarId(NbField)%nc_id(1))
+          IF (PRESENT(once) .AND. once) THEN 
+            status = NF90_DEF_VAR(ncid,TRIM(ADJUSTL(name)),ncprec,(/ ncellId,dim3id /),FieldVarId(NbField)%nc_id(1))
+          ELSE
+            status = NF90_DEF_VAR(ncid,TRIM(ADJUSTL(name)),ncprec,(/ ncellId,dim3id,timeId /),FieldVarId(NbField)%nc_id(1))
+          ENDIF
           status = NF90_PUT_ATT(ncid,FieldVarId(NbField)%nc_id(1),"coordinates","lon_i lat_i")
         ELSE IF (Field(ind_b)%ndim==4) THEN
           DO i=1,FieldVarId(NbField)%size
-            status = NF90_DEF_VAR(ncid,TRIM(ADJUSTL(name))//int2str(i),ncprec,(/ ncellId,dim3id,timeId /),  &
-                                  FieldVarId(NbField)%nc_id(i))
+            IF (PRESENT(once) .AND. once) THEN 
+              status = NF90_DEF_VAR(ncid,TRIM(ADJUSTL(name))//int2str(i),ncprec,(/ ncellId,dim3id /),  &
+                                    FieldVarId(NbField)%nc_id(i))
+            ELSE
+              status = NF90_DEF_VAR(ncid,TRIM(ADJUSTL(name))//int2str(i),ncprec,(/ ncellId,dim3id,timeId /),  &
+                                   FieldVarId(NbField)%nc_id(i))
+            ENDIF
             status = NF90_PUT_ATT(ncid,FieldVarId(NbField)%nc_id(i),"coordinates","lon_i lat_i")
           ENDDO        
@@ -1331,13 +1382,26 @@
 
         IF (Field(ind_b)%ndim==2) THEN
-          status = NF90_DEF_VAR(ncid,TRIM(ADJUSTL(name)),ncprec,(/ ncellId,timeId /),FieldVarId(NbField)%nc_id(1))
+          IF (PRESENT(once) .AND. once) THEN 
+            status = NF90_DEF_VAR(ncid,TRIM(ADJUSTL(name)),ncprec,(/ ncellId /),FieldVarId(NbField)%nc_id(1))
+          ELSE
+            status = NF90_DEF_VAR(ncid,TRIM(ADJUSTL(name)),ncprec,(/ ncellId,timeId /),FieldVarId(NbField)%nc_id(1))
+          ENDIF
           status = NF90_PUT_ATT(ncid,FieldVarId(NbField)%nc_id(1),"coordinates","lon_v lat_v")
         ELSE IF (Field(ind_b)%ndim==3) THEN
-          status = NF90_DEF_VAR(ncid,TRIM(ADJUSTL(name)),ncprec,(/ ncellId,dim3id,timeId /),FieldVarId(NbField)%nc_id(1))
+          IF (PRESENT(once) .AND. once) THEN 
+            status = NF90_DEF_VAR(ncid,TRIM(ADJUSTL(name)),ncprec,(/ ncellId,dim3id /),FieldVarId(NbField)%nc_id(1))
+          ELSE
+            status = NF90_DEF_VAR(ncid,TRIM(ADJUSTL(name)),ncprec,(/ ncellId,dim3id,timeId /),FieldVarId(NbField)%nc_id(1))
+          ENDIF
           status = NF90_PUT_ATT(ncid,FieldVarId(NbField)%nc_id(1),"coordinates","lon_v lat_v")
         ELSE IF (Field(ind_b)%ndim==4) THEN
           DO q=1,FieldVarId(NbField)%size
-            status = NF90_DEF_VAR(ncid,TRIM(ADJUSTL(name)//int2str(q)),ncprec,             &
-                                  (/ ncellId,dim3id,timeId /),FieldVarId(NbField)%nc_id(q))
+            IF (PRESENT(once) .AND. once) THEN 
+              status = NF90_DEF_VAR(ncid,TRIM(ADJUSTL(name)//int2str(q)),ncprec,             &
+                                    (/ ncellId,dim3id /),FieldVarId(NbField)%nc_id(q))
+            ELSE
+              status = NF90_DEF_VAR(ncid,TRIM(ADJUSTL(name)//int2str(q)),ncprec,             &
+                                    (/ ncellId,dim3id,timeId /),FieldVarId(NbField)%nc_id(q))
+            ENDIF
             status = NF90_PUT_ATT(ncid,FieldVarId(NbField)%nc_id(q),"coordinates","lon_v lat_v")
           ENDDO        
