Index: IOIPSL/trunk/src/histcom.f90
===================================================================
--- IOIPSL/trunk/src/histcom.f90	(revision 879)
+++ IOIPSL/trunk/src/histcom.f90	(revision 881)
@@ -110,5 +110,5 @@
  &  last_opp,last_wrt,last_opp_chk,last_wrt_chk,nb_opp,nb_wrt
 !- For future optimization
-  REAL,ALLOCATABLE,DIMENSION(:) :: t_bf
+  REAL,POINTER,DIMENSION(:) :: t_bf
 !#  REAL,ALLOCATABLE,DIMENSION(:) :: V_1_D
 !#  REAL,ALLOCATABLE,DIMENSION(:,:) :: V_2_D
@@ -692,5 +692,5 @@
     dims(1:1) = (/ W_F(idf)%xid /)
   ENDIF
-  iret = NF90_DEF_VAR (nfid,lon_name,NF90_FLOAT,dims(1:ndim),nlonid)
+  iret = NF90_DEF_VAR (nfid,lon_name,NF90_REAL4,dims(1:ndim),nlonid)
   IF (rectilinear) THEN
     iret = NF90_PUT_ATT (nfid,nlonid,'axis',"X")
@@ -713,5 +713,5 @@
     dims(1:1) = (/ W_F(idf)%yid /)
   ENDIF
-  iret = NF90_DEF_VAR (nfid,lat_name,NF90_FLOAT,dims(1:ndim),nlatid)
+  iret = NF90_DEF_VAR (nfid,lat_name,NF90_REAL4,dims(1:ndim),nlatid)
   IF (rectilinear) THEN
     iret = NF90_PUT_ATT (nfid,nlatid,'axis',"Y")
@@ -867,5 +867,5 @@
   IF (l_dbg) WRITE(*,*) "histhori_irregular 2.0"
 !-
-  iret = NF90_DEF_VAR (nfid,lon_name,NF90_FLOAT,dims(1:ndim),nlonid)
+  iret = NF90_DEF_VAR (nfid,lon_name,NF90_REAL4,dims(1:ndim),nlonid)
   iret = NF90_PUT_ATT (nfid,nlonid,'standard_name',"longitude")
   iret = NF90_PUT_ATT (nfid,nlonid,'units',"degrees_east")
@@ -880,5 +880,5 @@
 !-
   iret = NF90_PUT_ATT (nfid,nlonid,'bounds',TRIM(lonbound_name))
-  iret = NF90_DEF_VAR (nfid,lonbound_name,NF90_FLOAT, &
+  iret = NF90_DEF_VAR (nfid,lonbound_name,NF90_REAL4, &
  &                     dimsb(1:ndimb),nlonidb)
   longname = 'Boundaries for coordinate variable '//TRIM(lon_name)
@@ -889,5 +889,5 @@
   IF (l_dbg) WRITE(*,*) "histhori_irregular 3.0"
 !-
-  iret = NF90_DEF_VAR (nfid,lat_name,NF90_FLOAT,dims(1:ndim),nlatid)
+  iret = NF90_DEF_VAR (nfid,lat_name,NF90_REAL4,dims(1:ndim),nlatid)
   iret = NF90_PUT_ATT (nfid,nlatid,'standard_name',"latitude")
   iret = NF90_PUT_ATT (nfid,nlatid,'units',"degrees_north")
@@ -902,5 +902,5 @@
 !-
   iret = NF90_PUT_ATT (nfid,nlatid,'bounds',TRIM(latbound_name))
-  iret = NF90_DEF_VAR (nfid,latbound_name,NF90_FLOAT, &
+  iret = NF90_DEF_VAR (nfid,latbound_name,NF90_REAL4, &
  &                     dimsb(1:ndimb),nlatidb)
   longname = 'Boundaries for coordinate variable '//TRIM(lat_name)
@@ -1051,5 +1051,5 @@
   leng = MIN(LEN_TRIM(pzaxname),20)
   iret = NF90_DEF_DIM (nfid,pzaxname(1:leng),pzsize,zaxid_tmp)
-  iret = NF90_DEF_VAR (nfid,pzaxname(1:leng),NF90_FLOAT, &
+  iret = NF90_DEF_VAR (nfid,pzaxname(1:leng),NF90_REAL4, &
  &                     zaxid_tmp,zdimid)
   iret = NF90_PUT_ATT (nfid,zdimid,'axis',"Z")
@@ -1551,5 +1551,5 @@
       str30 = "time_counter"
     ENDIF
-    iret = NF90_DEF_VAR (nfid,str30,NF90_DOUBLE, &
+    iret = NF90_DEF_VAR (nfid,str30,NF90_REAL8, &
  &           dims(1),W_F(idf)%W_V(itx)%tdimid)
     IF (W_F(idf)%n_tax <= 1) THEN
@@ -1664,8 +1664,15 @@
       ENDIF
       IF (W_F(idf)%W_V(iv)%hist_wrt_rng) THEN
-        iret = NF90_PUT_ATT (nfid,nvid,'valid_min', &
- &               REAL(W_F(idf)%W_V(iv)%hist_minmax(1),KIND=4))
-        iret = NF90_PUT_ATT (nfid,nvid,'valid_max', &
- &               REAL(W_F(idf)%W_V(iv)%hist_minmax(2),KIND=4))
+        IF (W_F(idf)%W_V(iv)%v_typ == hist_r8) THEN
+          iret = NF90_PUT_ATT (nfid,nvid,'valid_min', &
+ &                 REAL(W_F(idf)%W_V(iv)%hist_minmax(1),KIND=8))
+          iret = NF90_PUT_ATT (nfid,nvid,'valid_max', &
+ &                 REAL(W_F(idf)%W_V(iv)%hist_minmax(2),KIND=8))
+        ELSE
+          iret = NF90_PUT_ATT (nfid,nvid,'valid_min', &
+ &                 REAL(W_F(idf)%W_V(iv)%hist_minmax(1),KIND=4))
+          iret = NF90_PUT_ATT (nfid,nvid,'valid_max', &
+ &                 REAL(W_F(idf)%W_V(iv)%hist_minmax(2),KIND=4))
+        ENDIF
       ENDIF
       iret = NF90_PUT_ATT (nfid,nvid,'long_name', &
@@ -2482,12 +2489,19 @@
 !-------- Put the min and max values on the file
           nvid = W_F(ifile)%W_V(iv)%ncvid
-          iret = NF90_PUT_ATT (nfid,nvid,'valid_min', &
- &                 REAL(W_F(ifile)%W_V(iv)%hist_minmax(1),KIND=4))
-          iret = NF90_PUT_ATT (nfid,nvid,'valid_max', &
- &                 REAL(W_F(ifile)%W_V(iv)%hist_minmax(2),KIND=4))
+          IF (W_F(ifile)%W_V(iv)%v_typ == hist_r8) THEN
+            iret = NF90_PUT_ATT (nfid,nvid,'valid_min', &
+ &                   REAL(W_F(ifile)%W_V(iv)%hist_minmax(1),KIND=8))
+            iret = NF90_PUT_ATT (nfid,nvid,'valid_max', &
+ &                   REAL(W_F(ifile)%W_V(iv)%hist_minmax(2),KIND=8))
+          ELSE
+            iret = NF90_PUT_ATT (nfid,nvid,'valid_min', &
+ &                   REAL(W_F(ifile)%W_V(iv)%hist_minmax(1),KIND=4))
+            iret = NF90_PUT_ATT (nfid,nvid,'valid_max', &
+ &                   REAL(W_F(ifile)%W_V(iv)%hist_minmax(2),KIND=4))
+          ENDIF
         ENDIF
       ENDIF
 !---- Time-Buffers
-      IF (ALLOCATED(W_F(ifile)%W_V(iv)%t_bf)) THEN
+      IF (ASSOCIATED(W_F(ifile)%W_V(iv)%t_bf)) THEN
         DEALLOCATE(W_F(ifile)%W_V(iv)%t_bf)
       ENDIF
