Index: branches/2014/dev_r4650_UKMO10_Tidally_Meaned_Diagnostics/NEMOGCM/TOOLS/SIREN/src/iom_cdf.f90
===================================================================
--- branches/2014/dev_r4650_UKMO10_Tidally_Meaned_Diagnostics/NEMOGCM/TOOLS/SIREN/src/iom_cdf.f90	(revision 4744)
+++ branches/2014/dev_r4650_UKMO10_Tidally_Meaned_Diagnostics/NEMOGCM/TOOLS/SIREN/src/iom_cdf.f90	(revision 5260)
@@ -6,30 +6,42 @@
 !
 ! DESCRIPTION:
-!> @brief
-!> This module is a library to read/write Netcdf file.
+!> @brief NETCDF Input/Output manager :  Library to read Netcdf input files
 !>
 !> @details
-!>
 !>    to open netcdf file:<br/>
+!> @code
 !>    CALL iom_cdf_open(td_file)
-!>       - td_file is file structure (see file.f90)
+!> @endcode
+!>       - td_file is file structure (see @ref file)
 !>
 !>    to write in netcdf file:<br/>
+!> @code
 !>    CALL  iom_cdf_write_file(td_file)
+!> @endcode
 !>
 !>    to close netcdf file:<br/>
+!> @code
 !>    CALL iom_cdf_close(tl_file)
+!> @endcode
 !>
 !>    to read one dimension in netcdf file:<br/>
-!>    tl_dim = iom_cdf_read_dim(tl_file, id_dimid)<br/>
-!>    or<br/>
+!> @code
+!>    tl_dim = iom_cdf_read_dim(tl_file, id_dimid)
+!> @endcode
+!>    or
+!> @code
 !>    tl_dim = iom_cdf_read_dim(tl_file, cd_name)
+!> @endcode
 !>       - id_dimid is dimension id<br/>
 !>       - cd_name is dimension name
 !>
-!>    to read one global attribute in netcdf file:<br/>
-!>    tl_att = iom_cdf_read_att(tl_file, id_varid, id_attid)<br/>
-!>    or<br/>
+!>    to read one attribute in netcdf file:<br/>
+!> @code
+!>    tl_att = iom_cdf_read_att(tl_file, id_varid, id_attid)
+!> @endcode
+!>    or
+!> @code
 !>    tl_att = iom_cdf_read_att(tl_file, id_varid, cd_name)
+!> @endcode
 !>       - id_varid is variable id
 !>       - id_attid is attribute id<br/>
@@ -37,33 +49,24 @@
 !>    
 !>    to read one variable in netcdf file:<br/>
-!>    tl_var = iom_cdf_read_var(td_file, id_varid, [id_start, id_count])<br/>
-!>    or<br/>
-!>    tl_var = iom_cdf_read_var(td_file, cd_name, [id_start, [id_count,]] [cd_stdname])
+!> @code
+!>    tl_var = iom_cdf_read_var(td_file, id_varid, [id_start, id_count])
+!> @endcode
+!>    or
+!> @code
+!>    tl_var = iom_cdf_read_var(td_file, cd_name, [id_start, [id_count,]])
+!> @endcode
 !>       - id_varid is variabale id
 !>       - cd_name is variabale name
-!>       - id_start is a integer(4) 1D table of index from which the data 
-!>          values will be read (optional)
-!>       - id_count is a integer(4) 1D table of the number of indices selected
-!>          along each dimension (optional)
-!>       - cd_stdname is variable standard name (optional)
+!>       - id_start is a integer(4) 1D array of index from which the data 
+!>          values will be read [optional]
+!>       - id_count is a integer(4) 1D array of the number of indices selected
+!>          along each dimension [optional]
 !>
 !> @author
 !> J.Paul
 ! REVISION HISTORY:
-!> @date Nov, 2013 - Initial Version
-!
-!> @param MyModule_type : brief_description
+!> @date November, 2013 - Initial Version
 !
 !> @note Software governed by the CeCILL licence     (NEMOGCM/NEMO_CeCILL.txt)
-!
-!> @todo 
-!> - inform variable pni, pnj, pnij, area, iglo, jglo 
-!> - use var_init when read new variable
-!> - use dim_init when read new dimension
-!> - use att_init when read new attribute
-!> - add read td_dom
-!> @todo
-!> - voir si il ne faut pas redefinir (__copy) variable si elle vient de mpp
-!> exemple CALL  mpp_move_var( td_mpp, td_mpp%t_var )
 !----------------------------------------------------------------------
 MODULE iom_cdf
@@ -72,13 +75,10 @@
    USE kind                            ! F90 kind parameter
    USE fct                             ! basic useful function
-   USE logger                             ! log file manager
+   USE logger                          ! log file manager
    USE att                             ! attribute manage
    USE dim                             ! dimension manager
    USE var                             ! variable manager
    USE file                            ! file manager
-   USE dom                             ! domain manager
-!   USE proc                            ! processor manager
    IMPLICIT NONE
-   PRIVATE
    ! NOTE_avoid_public_variables_if_possible
 
@@ -91,30 +91,29 @@
    PUBLIC :: iom_cdf_fill_var    !< fill variable value in an opened netcdf file
    PUBLIC :: iom_cdf_write_file  !< write file structure contents in an opened netcdf file
-   ! PUBLIC :: iom_cdf_get_mpp     ! get sub domain decomposition in a netcdf file
-
-   PRIVATE :: iom_cdf__check           !< provides a simple interface to netcdf error message
-   PRIVATE :: iom_cdf__get_info        !< get global information in an opened netcdf file
-   PRIVATE :: iom_cdf__get_file_dim    !< read dimension on an opened netcdf file, and reorder it
-   PRIVATE :: iom_cdf__get_file_att    !< read global attribute on an opened netcdf file
-   PRIVATE :: iom_cdf__get_file_var    !< read information about variable on an opened netcdf file
-   PRIVATE :: iom_cdf__read_dim_id     !< read one dimension in an opened netcdf file, given dimension id.
-   PRIVATE :: iom_cdf__read_dim_name   !< read one dimension in an opened netcdf file, given dimension name.
-   PRIVATE :: iom_cdf__read_att_name   !< read variable or global attribute in an opened netcdf file, given attribute name. 
-   PRIVATE :: iom_cdf__read_att_id     !< read variable or global attribute in an opened netcdf file, given attribute id.
-   PRIVATE :: iom_cdf__read_var_id     !< read variable value in an opened netcdf file, given variable id.
-   PRIVATE :: iom_cdf__read_var_name   !< read variable value in an opened netcdf file, given variable name or standard name.
-   PRIVATE :: iom_cdf__read_var_meta   !< read metadata of a variable in an opened netcdf file.
-   PRIVATE :: iom_cdf__read_var_dim    !< read variable dimension in an opened netcdf file.
-   PRIVATE :: iom_cdf__read_var_att    !< read variable attributes in an opened netcdf file.
-   PRIVATE :: iom_cdf__read_var_value  !< read variable value in an opened netcdf file.
-   PRIVATE :: iom_cdf__write_dim       !< write one dimension in an opened netcdf file in write mode.
-   PRIVATE :: iom_cdf__write_att       !< write a variable attribute in an opened netcdf file.
-   PRIVATE :: iom_cdf__write_var       !< write a variable in an opened netcdf file.
-   PRIVATE :: iom_cdf__write_var_def   !< define variable in an opened netcdf file.
-   PRIVATE :: iom_cdf__write_var_value !< put variable value in an opened netcdf file.
-   PRIVATE :: iom_cdf__fill_var_id     !< fill variable value in an opened netcdf file, given variable id
-   PRIVATE :: iom_cdf__fill_var_name   !< fill variable value in an opened netcdf file, given variable name
-   PRIVATE :: iom_cdf__fill_var_all    !< fill all variable value in an opened netcdf file
-   PRIVATE :: iom_cdf__del_var_dim     !< remove variable dimension from an opened netcdf file
+
+   PRIVATE :: iom_cdf__check           ! provides a simple interface to netcdf error message
+   PRIVATE :: iom_cdf__get_info        ! get global information in an opened netcdf file
+   PRIVATE :: iom_cdf__get_file_dim    ! read dimension on an opened netcdf file, and reorder it
+   PRIVATE :: iom_cdf__get_file_att    ! read global attribute on an opened netcdf file
+   PRIVATE :: iom_cdf__get_file_var    ! read information about variable on an opened netcdf file
+   PRIVATE :: iom_cdf__read_dim_id     ! read one dimension in an opened netcdf file, given dimension id.
+   PRIVATE :: iom_cdf__read_dim_name   ! read one dimension in an opened netcdf file, given dimension name.
+   PRIVATE :: iom_cdf__read_att_name   ! read variable or global attribute in an opened netcdf file, given attribute name. 
+   PRIVATE :: iom_cdf__read_att_id     ! read variable or global attribute in an opened netcdf file, given attribute id.
+   PRIVATE :: iom_cdf__read_var_id     ! read variable value in an opened netcdf file, given variable id.
+   PRIVATE :: iom_cdf__read_var_name   ! read variable value in an opened netcdf file, given variable name or standard name.
+   PRIVATE :: iom_cdf__read_var_meta   ! read metadata of a variable in an opened netcdf file.
+   PRIVATE :: iom_cdf__read_var_dim    ! read variable dimension in an opened netcdf file.
+   PRIVATE :: iom_cdf__read_var_att    ! read variable attributes in an opened netcdf file.
+   PRIVATE :: iom_cdf__read_var_value  ! read variable value in an opened netcdf file.
+   PRIVATE :: iom_cdf__write_dim       ! write one dimension in an opened netcdf file in write mode.
+   PRIVATE :: iom_cdf__write_att       ! write a variable attribute in an opened netcdf file.
+   PRIVATE :: iom_cdf__write_var       ! write a variable in an opened netcdf file.
+   PRIVATE :: iom_cdf__write_var_def   ! define variable in an opened netcdf file.
+   PRIVATE :: iom_cdf__write_var_value ! put variable value in an opened netcdf file.
+   PRIVATE :: iom_cdf__fill_var_id     ! fill variable value in an opened netcdf file, given variable id
+   PRIVATE :: iom_cdf__fill_var_name   ! fill variable value in an opened netcdf file, given variable name
+   PRIVATE :: iom_cdf__fill_var_all    ! fill all variable value in an opened netcdf file
+   PRIVATE :: iom_cdf__del_coord_var   ! remove coordinate variable from an opened netcdf file
 
    INTERFACE iom_cdf_read_var
@@ -145,9 +144,8 @@
    !>
    !> @author J.Paul
-   !> - Nov, 2013- Initial Version
-   !
-   !> @param[in] id_status : error status
-   !-------------------------------------------------------------------
-   !> @code
+   !> - November, 2013- Initial Version
+   !
+   !> @param[in] id_status error status
+   !-------------------------------------------------------------------
    SUBROUTINE iom_cdf__check(id_status)
       IMPLICIT NONE
@@ -161,9 +159,9 @@
 
    END SUBROUTINE iom_cdf__check
-   !> @endcode
-   !-------------------------------------------------------------------
-   !> @brief This subroutine open a netcdf file in read or write mode<br/>
+   !-------------------------------------------------------------------
+   !> @brief This subroutine open a netcdf file in read or write mode.
+   !> @details
    !> if try to open a file in write mode that did not exist, create it.<br/>
-   !> if file already exist, get information about:
+   !> if file already exist, get information about0:<br/>
    !> - the number of variables
    !> - the number of dimensions
@@ -171,12 +169,12 @@
    !> - the ID of the unlimited dimension
    !> - the file format
-   !> and finally read dimensions.
+   !> Finally it read dimensions, and 'longitude' variable to compute East-West
+   !> overlap.
    !>
    !> @author J.Paul
-   !> - Nov, 2013- Initial Version
-   !
-   !> @param[inout] td_file : file structure
-   !-------------------------------------------------------------------
-   !> @code
+   !> - November, 2013- Initial Version
+   !
+   !> @param[inout] td_file   file structure
+   !-------------------------------------------------------------------
    SUBROUTINE iom_cdf_open(td_file)
       IMPLICIT NONE
@@ -189,8 +187,4 @@
 
       INTEGER(i4) :: il_status
-
-      TYPE(TVAR)  :: tl_lon
-      ! loop indices
-      INTEGER(i4) :: ji
       !----------------------------------------------------------------
 
@@ -202,11 +196,10 @@
          IF( .NOT. td_file%l_wrt )THEN
 
-            CALL logger_fatal( " OPEN: can not open file "//&
+            CALL logger_fatal( " IOM CDF OPEN: can not open file "//&
             &               TRIM(td_file%c_name) )
-            td_file%i_id=-1
-         
+ 
          ELSE
 
-            CALL logger_info( " CREATE: file "//TRIM(td_file%c_name) )
+            CALL logger_info( " IOM CDF CREATE: file "//TRIM(td_file%c_name) )
 
             il_status = NF90_CREATE( TRIM(td_file%c_name),&
@@ -220,26 +213,25 @@
 
       ELSE
-
          IF( td_file%i_id /= 0 )THEN
 
-            CALL logger_error( " OPEN: file "//&
+            CALL logger_error( " IOM CDF OPEN: file "//&
             &               TRIM(td_file%c_name)//" already opened")
 
          ELSE
-
+ 
             IF( .NOT. td_file%l_wrt )THEN
 
-               CALL logger_info( " OPEN: file "//&
+               CALL logger_info( " IOM CDF OPEN: file "//&
                &              TRIM(td_file%c_name)//" in read only mode" )
 
                il_status = NF90_OPEN( TRIM(td_file%c_name), &
-               &                      NF90_NOWRITE,              &
+               &                      NF90_NOWRITE,         &
                &                      td_file%i_id)
                CALL iom_cdf__check(il_status)
 
-               CALL logger_debug("OPEN "//TRIM(td_file%c_name)//" "//TRIM(fct_str(td_file%i_id)))
+               CALL logger_trace("IOM CDF OPEN "//TRIM(td_file%c_name)//" "//TRIM(fct_str(td_file%i_id)))
             ELSE
 
-               CALL logger_info( " OPEN: file "//&
+               CALL logger_info( "IOM CDF OPEN: file "//&
                &              TRIM(td_file%c_name)//" in write mode" )
 
@@ -263,19 +255,6 @@
             CALL iom_cdf__get_file_var(td_file)
 
-            ! get ew overlap
-            tl_lon=iom_cdf_read_var(td_file,'longitude')
-            td_file%i_ew=dom_get_ew_overlap(tl_lon)
-            CALL logger_debug(" IOM OPEN EW "//TRIM(fct_str(td_file%i_ew)) )
-            WHERE( td_file%t_var(:)%t_dim(1)%l_use )
-               td_file%t_var(:)%i_ew=td_file%i_ew
-            END WHERE
-            CALL var_clean(tl_lon)
-
-            DO ji=1,td_file%i_nvar
-               CALL logger_debug(TRIM(td_file%t_var(ji)%c_name)//": "//TRIM(fct_str(td_file%t_var(ji)%i_ew)) )
-            ENDDO
- 
             ! remove dimension variable from list of variable
-            CALL iom_cdf__del_var_dim(td_file)
+            CALL iom_cdf__del_coord_var(td_file)
 
          ENDIF
@@ -284,14 +263,12 @@
 
    END SUBROUTINE iom_cdf_open
-   !> @endcode
-   !-------------------------------------------------------------------
-   !> @brief This subroutine close netcdf file
+   !-------------------------------------------------------------------
+   !> @brief This subroutine close netcdf file.
    !>
    !> @author J.Paul
-   !> - Nov, 2013- Initial Version
-   !
-   !> @param[inout] td_file : file structure
-   !-------------------------------------------------------------------
-   !> @code
+   !> - November, 2013- Initial Version
+   !
+   !> @param[inout] td_file   file structure
+   !-------------------------------------------------------------------
    SUBROUTINE iom_cdf_close(td_file)
       IMPLICIT NONE
@@ -307,9 +284,9 @@
 
          CALL logger_error( &
-         &  " CLOSE: no id associated to file "//TRIM(td_file%c_name))
+         &  " IOM CDF CLOSE: no id associated to file "//TRIM(td_file%c_name))
 
       ELSE
          CALL logger_info( &
-         &  " CLOSE: file "//TRIM(td_file%c_name))
+         &  " IOM CDF CLOSE: file "//TRIM(td_file%c_name))
 
          il_status = NF90_CLOSE(td_file%i_id)
@@ -321,8 +298,7 @@
 
    END SUBROUTINE iom_cdf_close
-   !> @endcode
    !-------------------------------------------------------------------
    !> @brief This subroutine get global information in an opened netcdf 
-   !> file.<br/>
+   !> file.
    !> @details
    !> It gets the number of variables, the number of dimensions, 
@@ -331,10 +307,8 @@
    !>
    !> @author J.Paul
-   !> - Nov, 2013- Initial Version
-   !
-   !> @param[inout] td_file : file structure
-   !> @return file structure completed 
-   !-------------------------------------------------------------------
-   !> @code
+   !> - November, 2013- Initial Version
+   !
+   !> @param[inout] td_file   file structure
+   !-------------------------------------------------------------------
    SUBROUTINE iom_cdf__get_info(td_file)
       IMPLICIT NONE
@@ -348,5 +322,5 @@
 
       CALL logger_trace( &
-      &  " GET INFO: about netcdf file "//TRIM(td_file%c_name))
+      &  " IOM CDF GET INFO: about netcdf file "//TRIM(td_file%c_name))
 
       il_status=NF90_INQUIRE(td_file%i_id, td_file%i_ndim, &
@@ -365,17 +339,14 @@
 
    END SUBROUTINE iom_cdf__get_info
-   !> @endcode
    !-------------------------------------------------------------------
    !> @brief This subroutine read dimension on an opened netcdf file, and
-   !> reorder dimension to ('x', 'y', 'z', 't').<br/>
+   !> reorder dimension to ('x', 'y', 'z', 't').
    !> The dimension structure inside file structure is then completed.
    !
    !> @author J.Paul
-   !> - Nov, 2013- Initial Version
-   !
-   !> @param[inout] td_file : file structure
-   !> @return file structure completed 
-   !-------------------------------------------------------------------
-   !> @code
+   !> - November, 2013- Initial Version
+   !
+   !> @param[inout] td_file   file structure
+   !-------------------------------------------------------------------
    SUBROUTINE iom_cdf__get_file_dim(td_file)
       IMPLICIT NONE
@@ -401,5 +372,5 @@
          IF( td_file%i_uldid == -1 )THEN
             CALL logger_warn( &
-            &  " GET FILE DIM: there is no unlimited dimension in file "//&
+            &  " IOM CDF GET FILE DIM: there is no unlimited dimension in file "//&
             &  TRIM(td_file%c_name))
          ELSE
@@ -410,5 +381,5 @@
 
          CALL logger_warn( &
-         &  " GET FILE DIM: there is no dimension in file "//&
+         &  " IOM CDF GET FILE DIM: there is no dimension in file "//&
          &  TRIM(td_file%c_name))
 
@@ -419,17 +390,16 @@
 
    END SUBROUTINE iom_cdf__get_file_dim
-   !> @endcode
    !-------------------------------------------------------------------
    !> @brief This subroutine read global attribute on an opened netcdf 
-   !> file.<br/>
+   !> file.
    !> The attribute structure inside file structure is then completed.
    !
    !> @author J.Paul
-   !> - Nov, 2013- Initial Version
-   !
-   !> @param[inout] td_file : file structure
-   !> @return file structure completed 
-   !-------------------------------------------------------------------
-   !> @code
+   !> - November, 2013- Initial Version
+   !> @date September, 2014
+   !> - use attribute periodicity read from the file if present.
+   !
+   !> @param[inout] td_file   file structure
+   !-------------------------------------------------------------------
    SUBROUTINE iom_cdf__get_file_att(td_file)
       IMPLICIT NONE
@@ -437,4 +407,5 @@
       TYPE(TFILE), INTENT(INOUT) :: td_file
 
+      ! local variable
       ! loop indices
       INTEGER(i4) :: ji
@@ -443,4 +414,5 @@
       IF( td_file%i_natt > 0 )THEN
          IF(ASSOCIATED(td_file%t_att))THEN
+            CALL att_clean(td_file%t_att(:))
             DEALLOCATE(td_file%t_att)
          ENDIF
@@ -451,36 +423,24 @@
             td_file%t_att(ji)=iom_cdf_read_att( td_file, NF90_GLOBAL, ji)
             
-            SELECT CASE(TRIM(td_file%t_att(ji)%c_name))
-               CASE('periodicity')
-                  td_file%i_perio=INT(td_file%t_att(ji)%d_value(1),i4)
-               CASE('pivot_point')
-                  td_file%i_pivot=INT(td_file%t_att(ji)%d_value(1),i4)
-               CASE('ew_overlap')
-                  td_file%i_ew=INT(td_file%t_att(ji)%d_value(1),i4)
-            END SELECT
-
          ENDDO
 
       ELSE
          CALL logger_debug( &
-         &  " GET FILE ATT: there is no global attribute in file "//&
+         &  " IOM CDF GET FILE ATT: there is no global attribute in file "//&
          &  TRIM(td_file%c_name))
       ENDIF
 
    END SUBROUTINE iom_cdf__get_file_att
-   !> @endcode   
    !-------------------------------------------------------------------
    !> @brief This subroutine read information about variable of an 
-   !> opened netcdf file.<br/>
+   !> opened netcdf file.
    !> The variable structure inside file structure is then completed.
    !> @note variable value are not read !
    !
    !> @author J.Paul
-   !> - Nov, 2013- Initial Version
-   !
-   !> @param[inout] td_file : file structure
-   !> @return file structure completed 
-   !-------------------------------------------------------------------
-   !> @code
+   !> - November, 2013- Initial Version
+   !
+   !> @param[inout] td_file   file structure
+   !-------------------------------------------------------------------
    SUBROUTINE iom_cdf__get_file_var(td_file)
       IMPLICIT NONE
@@ -497,4 +457,5 @@
       IF( td_file%i_nvar > 0 )THEN
          IF(ASSOCIATED(td_file%t_var))THEN
+            CALL var_clean(td_file%t_var(:))
             DEALLOCATE(td_file%t_var)
          ENDIF
@@ -504,5 +465,4 @@
             ! read dimension information
             td_file%t_var(ji)=iom_cdf__read_var_meta( td_file, ji)
-
             SELECT CASE(td_file%t_var(ji)%i_ndim)
                CASE(0)
@@ -524,7 +484,9 @@
                   td_file%i_depthid=ji
                ELSE
-                  CALL logger_error("IOM OPEN: find more than one "//&
-                  &                 "depth variable in file "//&
-                  &                 TRIM(td_file%c_name) )
+                  IF( td_file%i_depthid /= ji )THEN
+                     CALL logger_error("IOM CDF GET FILE VAR: find more than one "//&
+                     &                 "depth variable in file "//&
+                     &                 TRIM(td_file%c_name) )
+                  ENDIF
                ENDIF
             ENDIF
@@ -554,21 +516,19 @@
       ELSE
          CALL logger_debug( &
-         &  " GET FILE VAR: there is no variable in file "//&
+         &  " IOM CDF GET FILE VAR: there is no variable in file "//&
          &  TRIM(td_file%c_name))
       ENDIF
 
    END SUBROUTINE iom_cdf__get_file_var
-   !> @endcode
-   !-------------------------------------------------------------------
-   !> @brief This subroutine delete variable dimension from an 
-   !> opened netcdf file.<br/>
-   !
-   !> @author J.Paul
-   !> - 2013- Initial Version
-   !
-   !> @param[inout] td_file : file structure
-   !-------------------------------------------------------------------
-   !> @code
-   SUBROUTINE iom_cdf__del_var_dim(td_file)
+   !-------------------------------------------------------------------
+   !> @brief This subroutine delete coordinate variable from an 
+   !> opened netcdf file if present.
+   !
+   !> @author J.Paul
+   !> - November, 2013- Initial Version
+   !
+   !> @param[inout] td_file   file structure
+   !-------------------------------------------------------------------
+   SUBROUTINE iom_cdf__del_coord_var(td_file)
       IMPLICIT NONE
       ! Argument      
@@ -598,87 +558,8 @@
       ELSE
          CALL logger_debug( &
-         &  " DEL VAR DIM: there is no variable in file "//&
+         &  " IOM CDF DEL VAR DIM: there is no variable in file "//&
          &  TRIM(td_file%c_name))
       ENDIF
-   END SUBROUTINE iom_cdf__del_var_dim
-   !> @endcode
-!   !-------------------------------------------------------------------
-!   !> @brief This subroutine get variable time from an 
-!   !> opened netcdf file.<br/>
-!   !
-!   !> @author J.Paul
-!   !> - 2013- Initial Version
-!   !
-!   !> @param[inout] td_file : file structure
-!   !-------------------------------------------------------------------
-!   !> @code
-!   SUBROUTINE iom_cdf__get_var_time(td_file)
-!      IMPLICIT NONE
-!      ! Argument      
-!      TYPE(TFILE), INTENT(INOUT) :: td_file
-!
-!      ! local variable
-!      CHARACTER(LEN=lc) :: cl_name
-!
-!      ! loop indices
-!      INTEGER(i4) :: ji
-!      !----------------------------------------------------------------
-!      IF( td_file%i_nvar > 0 )THEN
-!         DO ji=1,td_file%i_nvar
-!            cl_name=TRIM(td_file%t_var(ji)%c_name)
-!            IF( INDEX(cl_name,'time') /= 0 )THEN
-!               ! read time variable
-!               td_file%t_time=iom_cdf_read_var(td_file,ji)
-!               ! remove time variable from variable list
-!               CALL file_del_ver(td_file,TRIM(cl_name))
-!               EXIT
-!            ENDIF
-!         ENDDO
-!      ELSE
-!         CALL logger_debug( &
-!         &  " GET VAR TIME: there is no variable in file "//&
-!         &  TRIM(td_file%c_name))
-!      ENDIF
-!   END SUBROUTINE iom_cdf__get_var_time
-!   !> @endcode
-!   !-------------------------------------------------------------------
-!   !> @brief This subroutine get variable depth from an 
-!   !> opened netcdf file.<br/>
-!   !
-!   !> @author J.Paul
-!   !> - 2013- Initial Version
-!   !
-!   !> @param[inout] td_file : file structure
-!   !-------------------------------------------------------------------
-!   !> @code
-!   SUBROUTINE iom_cdf__get_var_depth(td_file)
-!      IMPLICIT NONE
-!      ! Argument      
-!      TYPE(TFILE), INTENT(INOUT) :: td_file
-!
-!      ! local variable
-!      CHARACTER(LEN=lc) :: cl_name
-!
-!      ! loop indices
-!      INTEGER(i4) :: ji
-!      !----------------------------------------------------------------
-!      IF( td_file%i_nvar > 0 )THEN
-!         DO ji=1,td_file%i_nvar
-!            cl_name=TRIM(td_file%t_var(ji)%c_name)
-!            IF( INDEX(cl_name,'depth') /= 0 )THEN
-!               ! read depth variable
-!               td_file%t_depth=iom_cdf_read_var(td_file,ji)
-!               ! remove depth variable from variable list
-!               CALL file_del_ver(td_file,TRIM(cl_name))
-!               EXIT
-!            ENDIF
-!         ENDDO
-!      ELSE
-!         CALL logger_debug( &
-!         &  " GET VAR TIME: there is no variable in file "//&
-!         &  TRIM(td_file%c_name))
-!      ENDIF
-!   END SUBROUTINE iom_cdf__get_var_depth
-!   !> @endcode
+   END SUBROUTINE iom_cdf__del_coord_var
    !-------------------------------------------------------------------
    !> @brief This function read one dimension in an opened netcdf file, 
@@ -686,11 +567,10 @@
    !
    !> @author J.Paul
-   !> - Nov, 2013- Initial Version
-   !
-   !> @param[in] td_file : file structure
-   !> @param[in] id_dimid : dimension id
+   !> - November, 2013- Initial Version
+   !
+   !> @param[in] td_file   file structure
+   !> @param[in] id_dimid  dimension id
    !> @return  dimension structure 
    !-------------------------------------------------------------------
-   !> @code
    TYPE(TDIM) FUNCTION iom_cdf__read_dim_id(td_file, id_dimid)
       IMPLICIT NONE
@@ -709,5 +589,5 @@
 
          CALL logger_error( &
-         &  " READ DIM: no id associated to file "//TRIM(td_file%c_name))
+         &  " IOM CDF READ DIM: no id associated to file "//TRIM(td_file%c_name))
 
       ELSE      
@@ -715,6 +595,6 @@
          iom_cdf__read_dim_id%i_id=id_dimid
 
-         CALL logger_debug( &
-         &  " READ DIM: dimension "//TRIM(fct_str(id_dimid))//&
+         CALL logger_trace( &
+         &  " IOM CDF READ DIM: dimension "//TRIM(fct_str(id_dimid))//&
          &  " in file "//TRIM(td_file%c_name))
 
@@ -728,5 +608,4 @@
 
    END FUNCTION iom_cdf__read_dim_id
-   !> @endcode
    !-------------------------------------------------------------------
    !> @brief This function read one dimension in an opened netcdf file, 
@@ -734,11 +613,10 @@
    !
    !> @author J.Paul
-   !> - Nov, 2013- Initial Version
-   !
-   !> @param[in] td_file : file structure
-   !> @param[in] cd_name : dimension name
+   !> - November, 2013- Initial Version
+   !
+   !> @param[in] td_file   file structure
+   !> @param[in] cd_name   dimension name
    !> @return  dimension structure 
    !-------------------------------------------------------------------
-   !> @code
    TYPE(TDIM) FUNCTION iom_cdf__read_dim_name(td_file, cd_name)
       IMPLICIT NONE
@@ -756,5 +634,5 @@
 
          CALL logger_error( &
-         &  " READ DIM: no id associated to file "//TRIM(td_file%c_name))
+         &  " IOM CDF READ DIM: no id associated to file "//TRIM(td_file%c_name))
 
       ELSE      
@@ -769,5 +647,4 @@
 
    END FUNCTION iom_cdf__read_dim_name
-   !> @endcode   
    !-------------------------------------------------------------------
    !> @brief This function read variable or global attribute in an opened 
@@ -775,13 +652,12 @@
    !
    !> @author J.Paul
-   !> - Nov, 2013- Initial Version
-   !
-   !> @param[in] td_file : file structure
-   !> @param[in] id_varid : variable id. use NF90_GLOBAL to read global
+   !> - November, 2013- Initial Version
+   !
+   !> @param[in] td_file   file structure
+   !> @param[in] id_varid  variable id. use NF90_GLOBAL to read global
    !> attribute in a file
-   !> @param[in] cd_name : attribute name
+   !> @param[in] cd_name   attribute name
    !> @return  attribute structure 
    !-------------------------------------------------------------------
-   !> @code
    TYPE(TATT) FUNCTION iom_cdf__read_att_name(td_file, id_varid, cd_name)
       IMPLICIT NONE
@@ -800,4 +676,5 @@
 
       CHARACTER(LEN=lc) :: cl_value
+      
       INTEGER(i1), DIMENSION(:), ALLOCATABLE :: bl_value
       INTEGER(i2), DIMENSION(:), ALLOCATABLE :: sl_value
@@ -810,5 +687,5 @@
 
          CALL logger_error( &
-         &  " READ ATT: no id associated to file "//TRIM(td_file%c_name))
+         &  " IOM CDF READ ATT: no id associated to file "//TRIM(td_file%c_name))
 
       ELSE      
@@ -819,12 +696,12 @@
          IF( id_varid == NF90_GLOBAL )THEN
 
-            CALL logger_debug( &
-            &  " READ ATT: inquire global attribute "//&
+            CALL logger_trace( &
+            &  " IOM CDF READ ATT: inquire global attribute "//&
             &  " in file "//TRIM(td_file%c_name))
 
          ELSE
 
-            CALL logger_debug( &
-            &  " READ ATT: inquire attribute "//&
+            CALL logger_trace( &
+            &  " IOM CDF READ ATT: inquire attribute "//&
             &  " of variable "//TRIM(fct_str(id_varid))//&
             &  " in file "//TRIM(td_file%c_name))
@@ -840,5 +717,5 @@
 
          !! get attribute value
-         CALL logger_debug( " READ ATT: get attribute "//TRIM(cl_name)//&
+         CALL logger_debug( " IOM CDF READ ATT: get attribute "//TRIM(cl_name)//&
          &               " in file "//TRIM(td_file%c_name))
 
@@ -851,5 +728,5 @@
 
                   CALL logger_error( &
-                  &  " READ ATT: not enough space to put attribute "//&
+                  &  " IOM CDF READ ATT: not enough space to put attribute "//&
                   &  TRIM(cl_name) )
 
@@ -872,7 +749,6 @@
                IF(il_status /= 0 )THEN
 
-                  CALL logger_error( &
-                  &  " READ ATT: not enough space to put attribute "//&
-                  &  TRIM(cl_name) )
+                  CALL logger_error( "IOM CDF READ ATT: "//&
+                  &  "not enough space to put attribute "//TRIM(cl_name) )
 
                ELSE
@@ -897,5 +773,5 @@
 
                   CALL logger_error( &
-                  &  " READ ATT: not enough space to put attribute "//&
+                  &  " IOM CDF READ ATT: not enough space to put attribute "//&
                   &  TRIM(cl_name) )
 
@@ -921,5 +797,5 @@
 
                   CALL logger_error( &
-                  &  " READ ATT: not enough space to put attribute "//&
+                  &  " IOM CDF READ ATT: not enough space to put attribute "//&
                   &  TRIM(cl_name) )
 
@@ -944,5 +820,5 @@
 
                   CALL logger_error( &
-                  &  " READ ATT: not enough space to put attribute "//&
+                  &  " IOM CDF READ ATT: not enough space to put attribute "//&
                   &  TRIM(cl_name) )
 
@@ -968,5 +844,5 @@
 
                   CALL logger_error( &
-                  &  " READ ATT: not enough space to put attribute "//&
+                  &  " IOM CDF READ ATT: not enough space to put attribute "//&
                   &  TRIM(cl_name) )
 
@@ -992,5 +868,4 @@
 
    END FUNCTION iom_cdf__read_att_name
-   !> @endcode   
    !-------------------------------------------------------------------
    !> @brief This function read variable or global attribute in an opened 
@@ -998,13 +873,12 @@
    !
    !> @author J.Paul
-   !> - Nov, 2013- Initial Version
-   !
-   !> @param[in] td_file : file structure
-   !> @param[in] id_varid : variable id. use NF90_GLOBAL to read global 
+   !> - November, 2013- Initial Version
+   !
+   !> @param[in] td_file   file structure
+   !> @param[in] id_varid  variable id. use NF90_GLOBAL to read global 
    !> attribute in a file
-   !> @param[in] id_attid : attribute id
+   !> @param[in] id_attid  attribute id
    !> @return  attribute structure 
    !-------------------------------------------------------------------
-   !> @code
    TYPE(TATT) FUNCTION iom_cdf__read_att_id(td_file, id_varid, id_attid)
       IMPLICIT NONE
@@ -1022,7 +896,7 @@
 
          CALL logger_error( &
-         &  " READ ATT: no id associated to file "//TRIM(td_file%c_name))
-
-      ELSE      
+         &  "IOM CDF READ ATT: no id associated to file "//TRIM(td_file%c_name))
+
+      ELSE
 
          ! get attribute name
@@ -1036,22 +910,21 @@
 
    END FUNCTION iom_cdf__read_att_id
-   !> @endcode   
    !-------------------------------------------------------------------
    !> @brief This function read variable value in an opened 
-   !> netcdf file, given variable id.</br/>
-   !> start indices and number of indices selected along each dimension 
-   !> could be specify in a 4 dimension table (/'x','y','z','t'/)
-   !
-   !> @author J.Paul
-   !> - Nov, 2013- Initial Version
-   !
-   !> @param[in] td_file : file structure
-   !> @param[in] id_varid : variable id
-   !> @param[in] id_start : index in the variable from which the data values 
+   !> netcdf file, given variable id.
+   !> @details
+   !> Optionaly, start indices and number of indices selected along each dimension 
+   !> could be specify in a 4 dimension array (/'x','y','z','t'/)
+   !
+   !> @author J.Paul
+   !> - November, 2013- Initial Version
+   !
+   !> @param[in] td_file   file structure
+   !> @param[in] id_varid  variable id
+   !> @param[in] id_start  index in the variable from which the data values 
    !> will be read
-   !> @param[in] id_count : number of indices selected along each dimension
+   !> @param[in] id_count  number of indices selected along each dimension
    !> @return  variable structure 
    !-------------------------------------------------------------------
-   !> @code
    TYPE(TVAR) FUNCTION iom_cdf__read_var_id(td_file, id_varid,&
    &                                        id_start, id_count)
@@ -1070,15 +943,14 @@
 
          CALL logger_error( &
-         &  " IOM READ VAR: no id associated to file "//TRIM(td_file%c_name))
+         &  " IOM CDF READ VAR: no id associated to file "//TRIM(td_file%c_name))
 
       ELSE
 
-         ! look for variable id
+         ! look for variable index
          il_ind(:)=MINLOC(td_file%t_var(:)%i_id,mask=(td_file%t_var(:)%i_id==id_varid))
          IF( il_ind(1) /= 0 )THEN
 
-            iom_cdf__read_var_id=td_file%t_var(il_ind(1))
-
-            print *,"iom_cdf__read_var_id ",trim(iom_cdf__read_var_id%c_name)," ",iom_cdf__read_var_id%i_ew
+            iom_cdf__read_var_id=var_copy(td_file%t_var(il_ind(1)))
+
             !!! read variable value
             CALL iom_cdf__read_var_value(td_file, iom_cdf__read_var_id, &
@@ -1086,7 +958,6 @@
 
          ELSE
-            print *,"iom_cdf__read_var_id "
             CALL logger_error( &
-            &  " IOM READ VAR: there is no variable with id "//&
+            &  " IOM CDF READ VAR: there is no variable with id "//&
             &  TRIM(fct_str(id_varid))//" in file "//TRIM(td_file%c_name))
          ENDIF
@@ -1094,27 +965,23 @@
       ENDIF
    END FUNCTION iom_cdf__read_var_id
-   !> @endcode   
    !-------------------------------------------------------------------
    !> @brief This function read variable value in an opened 
-   !> netcdf file, given variable name or standard name.</br/>
-   !> start indices and number of indices selected along each dimension 
-   !> could be specify in a 4 dimension table (/'x','y','z','t'/)
-   !
+   !> netcdf file, given variable name or standard name.
    !> @details
+   !> Optionaly, start indices and number of indices selected along each dimension 
+   !> could be specify in a 4 dimension array (/'x','y','z','t'/)
+   !>
    !> look first for variable name. If it doesn't
    !> exist in file, look for variable standard name.<br/>
-   !> If variable name is not present, check variable standard name.<br/>
-   !
-   !> @author J.Paul
-   !> - Nov, 2013- Initial Version
-   !
-   !> @param[in] td_file : file structure
-   !> @param[in] cd_name  : variable name
-   !> @param[in] id_start : index in the variable from which the data values will be read
-   !> @param[in] id_count : number of indices selected along each dimension
-   !> @param[in] cd_stdname : variable standard name
+   !
+   !> @author J.Paul
+   !> - November, 2013- Initial Version
+   !
+   !> @param[in] td_file   file structure
+   !> @param[in] cd_name   variable name or standard name.
+   !> @param[in] id_start  index in the variable from which the data values will be read
+   !> @param[in] id_count  number of indices selected along each dimension
    !> @return  variable structure 
    !-------------------------------------------------------------------
-   !> @code
    TYPE(TVAR) FUNCTION iom_cdf__read_var_name(td_file, cd_name,  &
    &                                          id_start, id_count )
@@ -1127,5 +994,5 @@
 
       ! local variable
-      INTEGER(i4)       :: il_ind
+      INTEGER(i4)       :: il_varid
       !----------------------------------------------------------------
       ! check if file opened
@@ -1133,5 +1000,5 @@
 
          CALL logger_error( &
-         &  " IOM READ VAR: no id associated to file "//TRIM(td_file%c_name))
+         &  " IOM CDF READ VAR: no id associated to file "//TRIM(td_file%c_name))
 
       ELSE
@@ -1140,13 +1007,13 @@
 
             CALL logger_error( &
-            &  " IOM READ VAR: you must specify a variable to read "//&
+            &  " IOM CDF READ VAR: you must specify a variable to read "//&
             &  " in file "//TRIM(td_file%c_name))
 
          ELSE
 
-            il_ind=var_get_id(td_file%t_var(:), cd_name)
-            IF( il_ind /= 0 )THEN
-
-               iom_cdf__read_var_name=td_file%t_var(il_ind)
+            il_varid=var_get_index(td_file%t_var(:), cd_name)
+            IF( il_varid /= 0 )THEN
+
+               iom_cdf__read_var_name=var_copy(td_file%t_var(il_varid))
 
                !!! read variable value
@@ -1158,5 +1025,5 @@
 
                CALL logger_error( &
-               &  " IOM READ VAR: there is no variable with "//&
+               &  " IOM CDF READ VAR: there is no variable with "//&
                &  " name or standard name "//TRIM(cd_name)//&
                &  " in file "//TRIM(td_file%c_name) )
@@ -1168,23 +1035,19 @@
       
    END FUNCTION iom_cdf__read_var_name
-   !> @endcode
-   !-------------------------------------------------------------------
-   !> @brief This subroutine fill variable value in an opened 
-   !> netcdf file, given variable id.</br/>
-   !> start indices and number of indices selected along each dimension 
-   !> could be specify in a 4 dimension table (/'x','y','z','t'/)
-   !
-   !> @note ne peut pas marcher qd on fait boucle sur les variable d'un
-   !> fichier. puisque change id.
-
-   !> @author J.Paul
-   !> - Nov, 2013- Initial Version
-   !
-   !> @param[inout] td_file : file structure
-   !> @param[in] id_start : index in the variable from which the data values 
+   !-------------------------------------------------------------------
+   !> @brief This subroutine fill all variable value from an opened 
+   !> netcdf file.
+   !> @details
+   !> Optionaly, start indices and number of indices selected along each dimension 
+   !> could be specify in a 4 dimension array (/'x','y','z','t'/)
+   !
+   !> @author J.Paul
+   !> - November, 2013- Initial Version
+   !
+   !> @param[inout] td_file   file structure
+   !> @param[in] id_start     index in the variable from which the data values 
    !> will be read
-   !> @param[in] id_count : number of indices selected along each dimension
-   !-------------------------------------------------------------------
-   !> @code
+   !> @param[in] id_count     number of indices selected along each dimension
+   !-------------------------------------------------------------------
    SUBROUTINE iom_cdf__fill_var_all(td_file, id_start, id_count)
       IMPLICIT NONE
@@ -1203,34 +1066,31 @@
 
          CALL logger_error( &
-         &  " FILL VAR: no id associated to file "//TRIM(td_file%c_name))
+         &  " IOM CDF FILL VAR: no id associated to file "//TRIM(td_file%c_name))
 
       ELSE
 
          DO ji=1,td_file%i_nvar
-            CALL iom_cdf_fill_var(td_file, ji, id_start, id_count)
+            CALL iom_cdf_fill_var(td_file, td_file%t_var(ji)%i_id, &
+            &                     id_start, id_count)
          ENDDO
 
       ENDIF
    END SUBROUTINE iom_cdf__fill_var_all
-   !> @endcode
    !-------------------------------------------------------------------
    !> @brief This subroutine fill variable value in an opened 
-   !> netcdf file, given variable id.</br/>
-   !> start indices and number of indices selected along each dimension 
-   !> could be specify in a 4 dimension table (/'x','y','z','t'/)
-   !
-   !> @note ne peut pas marcher qd on fait boucle sur les variable d'un
-   !> fichier. puisque change id.
-
-   !> @author J.Paul
-   !> - Nov, 2013- Initial Version
-   !
-   !> @param[inout] td_file : file structure
-   !> @param[in] id_varid : variable id
-   !> @param[in] id_start : index in the variable from which the data values 
+   !> netcdf file, given variable id.
+   !> @details
+   !> Optionaly, start indices and number of indices selected along each dimension 
+   !> could be specify in a 4 dimension array (/'x','y','z','t'/)
+   !
+   !> @author J.Paul
+   !> - November, 2013- Initial Version
+   !
+   !> @param[inout] td_file   file structure
+   !> @param[in] id_varid     variable id
+   !> @param[in] id_start     index in the variable from which the data values 
    !> will be read
-   !> @param[in] id_count : number of indices selected along each dimension
-   !-------------------------------------------------------------------
-   !> @code
+   !> @param[in] id_count     number of indices selected along each dimension
+   !-------------------------------------------------------------------
    SUBROUTINE iom_cdf__fill_var_id(td_file, id_varid, id_start, id_count)
       IMPLICIT NONE
@@ -1242,5 +1102,5 @@
 
       ! local variable
-      INTEGER(i4), DIMENSION(1) :: il_ind
+      INTEGER(i4), DIMENSION(1) :: il_varid
 
       ! loop indices
@@ -1251,23 +1111,25 @@
 
          CALL logger_error( &
-         &  " FILL VAR: no id associated to file "//TRIM(td_file%c_name))
+         &  "IOM CDF FILL VAR: no id associated to file "//TRIM(td_file%c_name))
 
       ELSE
 
          ! look for variable id
-         il_ind(:)=MINLOC( td_file%t_var(:)%i_id, &
+         il_varid(:)=MINLOC( td_file%t_var(:)%i_id, &
          &                 mask=(td_file%t_var(:)%i_id==id_varid))
-         IF( il_ind(1) /= 0 )THEN
+         IF( il_varid(1) /= 0 )THEN
 
             !!! read variable value
-            CALL iom_cdf__read_var_value(td_file, td_file%t_var(il_ind(1)), &
+            CALL iom_cdf__read_var_value(td_file, td_file%t_var(il_varid(1)), &
             &                            id_start, id_count)
 
             DO ji=1,td_file%i_nvar
-               CALL logger_debug(" var id "//TRIM(td_file%t_var(ji)%c_name)//" "//TRIM(fct_str(td_file%t_var(ji)%i_id)) )
+               CALL logger_debug(" IOM CDF FILL VAR: var id "//&
+               &     TRIM(td_file%t_var(ji)%c_name)//" "//&
+               &     TRIM(fct_str(td_file%t_var(ji)%i_id)) )
             ENDDO
          ELSE
             CALL logger_error( &
-            &  " FILL VAR: there is no variable with id "//&
+            &  " IOM CDF FILL VAR: there is no variable with id "//&
             &  TRIM(fct_str(id_varid))//" in file "//TRIM(td_file%c_name))
          ENDIF
@@ -1275,25 +1137,22 @@
       ENDIF
    END SUBROUTINE iom_cdf__fill_var_id
-   !> @endcode
    !-------------------------------------------------------------------
    !> @brief This subroutine fill variable value in an opened 
-   !> netcdf file, given variable name or standard name.</br/>
-   !> start indices and number of indices selected along each dimension 
-   !> could be specify in a 4 dimension table (/'x','y','z','t'/)
-   !
+   !> netcdf file, given variable name or standard name.
    !> @details
+   !> Optionaly, start indices and number of indices selected along each dimension 
+   !> could be specify in a 4 dimension array (/'x','y','z','t'/)
+   !>
    !> look first for variable name. If it doesn't
    !> exist in file, look for variable standard name.<br/>
-   !> If variable name is not present, check variable standard name.<br/>
-   !
-   !> @author J.Paul
-   !> - Nov, 2013- Initial Version
-   !
-   !> @param[inout] td_file : file structure
-   !> @param[in] cd_name  : variable name or standard name
-   !> @param[in] id_start : index in the variable from which the data values will be read
-   !> @param[in] id_count : number of indices selected along each dimension
-   !-------------------------------------------------------------------
-   !> @code
+   !
+   !> @author J.Paul
+   !> - November, 2013- Initial Version
+   !
+   !> @param[inout] td_file   file structure
+   !> @param[in] cd_name      variable name or standard name
+   !> @param[in] id_start     index in the variable from which the data values will be read
+   !> @param[in] id_count     number of indices selected along each dimension
+   !-------------------------------------------------------------------
    SUBROUTINE iom_cdf__fill_var_name(td_file, cd_name, id_start, id_count )
       IMPLICIT NONE
@@ -1305,5 +1164,5 @@
 
       ! local variable
-      INTEGER(i4)       :: il_ind
+      INTEGER(i4)       :: il_varid
       !----------------------------------------------------------------
       ! check if file opened
@@ -1311,13 +1170,13 @@
 
          CALL logger_error( &
-         &  " FILL VAR: no id associated to file "//TRIM(td_file%c_name))
+         &  "IOM CDF FILL VAR: no id associated to file "//TRIM(td_file%c_name))
 
       ELSE
 
-            il_ind=var_get_id(td_file%t_var(:), cd_name)
-            IF( il_ind /= 0 )THEN
+            il_varid=var_get_index(td_file%t_var(:), cd_name)
+            IF( il_varid /= 0 )THEN
 
                !!! read variable value
-               CALL iom_cdf__read_var_value(td_file, td_file%t_var(il_ind), &
+               CALL iom_cdf__read_var_value(td_file, td_file%t_var(il_varid), &
                &                            id_start, id_count)
 
@@ -1325,5 +1184,5 @@
 
                CALL logger_error( &
-               &  " FILL VAR: there is no variable with "//&
+               &  "IOM CDF FILL VAR: there is no variable with "//&
                &  "name or standard name"//TRIM(cd_name)//&
                &  " in file "//TRIM(td_file%c_name))
@@ -1333,19 +1192,19 @@
       
    END SUBROUTINE iom_cdf__fill_var_name
-   !> @endcode
    !-------------------------------------------------------------------
    !> @brief This function read metadata of a variable in an opened 
-   !> netcdf file.</br/>
+   !> netcdf file.
    !
    !> @note variable value are not read
    !
    !> @author J.Paul
-   !> - Nov, 2013- Initial Version
-   !
-   !> @param[in] id_fileid : file id
-   !> @param[in] id_varid : variable id
+   !> - November, 2013- Initial Version
+   !> @date September, 2014
+   !> - force to use FillValue=1.e20 if no FillValue for coordinate variable.
+   !
+   !> @param[in] td_file   file structure
+   !> @param[in] id_varid  variable id
    !> @return  variable structure 
    !-------------------------------------------------------------------
-   !> @code
    TYPE(TVAR) FUNCTION iom_cdf__read_var_meta(td_file, id_varid)
       IMPLICIT NONE
@@ -1375,5 +1234,6 @@
 
          CALL logger_error( &
-         &  " READ ATT: no id associated to file "//TRIM(td_file%c_name))
+         &  " IOM CDF READ VAR META: no id associated to file "//&
+         &   TRIM(td_file%c_name))
 
       ELSE
@@ -1381,5 +1241,6 @@
          ! inquire variable
          CALL logger_trace( &
-         &  " READ VAR: inquire variable "//TRIM(fct_str(id_varid))//&
+         &  " IOM CDF READ VAR META: inquire variable "//&
+         &  TRIM(fct_str(id_varid))//&
          &  " in file "//TRIM(td_file%c_name))
          
@@ -1393,8 +1254,6 @@
          &                                il_natt )
          CALL iom_cdf__check(il_status)
-
          !!! fill variable dimension structure
          tl_dim(:)=iom_cdf__read_var_dim( td_file, il_ndim, il_dimid(:) )
-
          IF( il_natt /= 0 )THEN
             ALLOCATE( tl_att(il_natt) )
@@ -1405,5 +1264,5 @@
             il_attid=att_get_id(tl_att(:),'_FillValue')
             IF( il_attid == 0 )THEN
-               CALL logger_warn("IOM READ VAR: no _FillValue for variable "//&
+               CALL logger_info("IOM CDF READ VAR META: no _FillValue for variable "//&
                &  TRIM(cl_name)//" in file "//TRIM(td_file%c_name) )
 
@@ -1411,27 +1270,39 @@
                IF( il_attid /= 0 )THEN
                   ! create attribute _FillValue
-                  CALL logger_warn("IOM READ VAR: assume _FillValue is equal to "//&
+                  CALL logger_info("IOM CDF READ VAR META: assume _FillValue is equal to "//&
                   &                "missing_value for variable "//TRIM(cl_name) )
-                  tl_fill=att_init('_FillValue',tl_att(il_attid)%d_value(:))
+                  tl_fill=att_init('_FillValue',tl_att(il_attid)%d_value(:), &
+                  &                 id_type=tl_att(il_attid)%i_type)
                ELSE
                   ! create attribute _FillValue
-                  CALL logger_warn("IOM READ VAR: assume _FillValue is equal to "//&
-                  &                "zero for variable "//TRIM(cl_name) )
-                  tl_fill=att_init('_FillValue',0.)
-                  !tl_fill=att_init('_FillValue',1.e20)
+                  SELECT CASE(TRIM(cl_name))
+                     CASE DEFAULT
+                        CALL logger_info("IOM CDF READ VAR META: assume _FillValue is equal to "//&
+                        &                "zero for variable "//TRIM(cl_name) )
+                        tl_fill=att_init('_FillValue',0.)
+                     CASE('nav_lon','nav_lat', &
+                        &  'glamt','glamu','glamv','glamf', &
+                        &  'gphit','gphiu','gphiv','gphif')
+                        CALL logger_info("IOM CDF READ VAR META: assume _FillValue is equal to "//&
+                        &                "dummy fillValue (1.e20) for variable "//TRIM(cl_name) )
+                        tl_fill=att_init('_FillValue',1.e20)
+                  END SELECT
                ENDIF
 
                ALLOCATE( tl_tmp(il_natt) )
                ! save read attribut
-               tl_tmp(:)=tl_att(:)
-               ! change number of attribute in table
+               tl_tmp(:)=att_copy(tl_att(:))
+               ! change number of attribute in array
+               CALL att_clean(tl_att(:))
                DEALLOCATE( tl_att )
                ALLOCATE( tl_att(il_natt+1) )
                ! copy read attribut
-               tl_att(1:il_natt)=tl_tmp(:)
+               tl_att(1:il_natt)=att_copy(tl_tmp(:))
+               ! clean
+               CALL att_clean(tl_tmp(:))
                DEALLOCATE( tl_tmp )
 
                ! create attribute _FillValue
-               tl_att(il_natt+1)=tl_fill
+               tl_att(il_natt+1)=att_copy(tl_fill)
 
             ENDIF
@@ -1440,9 +1311,18 @@
             ALLOCATE(tl_att(il_natt+1) )
             ! create attribute _FillValue
-            CALL logger_warn("IOM READ VAR: assume _FillValue is equal to "//&
-            &                "zero for variable "//TRIM(cl_name) )
-            tl_fill=att_init('_FillValue',0.)
+            SELECT CASE(TRIM(cl_name))
+               CASE DEFAULT
+                  CALL logger_info("IOM CDF READ VAR META: assume _FillValue is equal to "//&
+                  &                "zero for variable "//TRIM(cl_name) )
+                  tl_fill=att_init('_FillValue',0.)
+               CASE('nav_lon','nav_lat', &
+                  &  'glamt','glamu','glamv','glamf', &
+                  &  'gphit','gphiu','gphiv','gphif')
+                  CALL logger_info("IOM CDF READ VAR META: assume _FillValue is equal to "//&
+                  &                "dummy fillValue (1.e20) for variable "//TRIM(cl_name) )
+                  tl_fill=att_init('_FillValue',1.e20)
+            END SELECT            
             ! create attribute _FillValue
-            tl_att(il_natt+1)=tl_fill
+            tl_att(il_natt+1)=att_copy(tl_fill)
          ENDIF
 
@@ -1451,4 +1331,8 @@
          &                                tl_att(:), id_id=id_varid )
 
+         ! clean
+         CALL dim_clean(tl_dim(:))
+         CALL att_clean(tl_fill)
+         CALL att_clean(tl_att(:))
          DEALLOCATE( tl_att )
 
@@ -1456,24 +1340,24 @@
 
    END FUNCTION iom_cdf__read_var_meta
-   !> @endcode
    !-------------------------------------------------------------------
    !> @brief This subroutine read variable dimension
    !> in an opened netcdf file.
-   !
+   !>
    !> @details
    !> the number of dimension can't exceed 4, 
    !> and should be 'x', 'y', 'z', 't' (whatever their order).<br/>
-   !> If the number of dimension read is less than 4, the table of dimension
+   !> If the number of dimension read is less than 4, the array of dimension
    !> strucure is filled with unused dimension.<br/>
-   !> So the table of dimension structure of a variable is always compose of 4
+   !> So the array of dimension structure of a variable is always compose of 4
    !> dimension (use or not). 
    !
    !> @author J.Paul
-   !> - Nov, 2013- Initial Version
-   !
-   !> @param[inout] td_file : file structure
-   !> @return file structure completed 
-   !-------------------------------------------------------------------
-   !> @code
+   !> - November, 2013- Initial Version
+   !
+   !> @param[in] td_file   file structure
+   !> @param[in] id_ndim   number of dimension
+   !> @param[in] id_dimid  array of dimension id
+   !> @return array dimension structure 
+   !-------------------------------------------------------------------
    FUNCTION iom_cdf__read_var_dim(td_file, id_ndim, id_dimid)
       IMPLICIT NONE
@@ -1502,5 +1386,8 @@
          CALL dim_reorder(tl_dim(:))
 
-         iom_cdf__read_var_dim(:)=tl_dim(:)
+         iom_cdf__read_var_dim(:)=dim_copy(tl_dim(:))
+
+         ! clean
+         CALL dim_clean(tl_dim(:))
 
       ELSE IF( id_ndim > 0 .AND. id_ndim <= 4 )THEN
@@ -1508,5 +1395,5 @@
 
          DO ji = 1, id_ndim
-            CALL logger_debug( " READ VAR DIM: get variable dimension "//&
+            CALL logger_trace( " IOM CDF READ VAR DIM: get variable dimension "//&
             &               TRIM(fct_str(ji)) )
 
@@ -1521,9 +1408,12 @@
          CALL dim_reorder(tl_dim(:))
       
-         iom_cdf__read_var_dim(:)=tl_dim(:)
+         iom_cdf__read_var_dim(:)=dim_copy(tl_dim(:))
+
+         ! clean
+         CALL dim_clean(tl_dim(:))
 
       ELSE
 
-         CALL logger_error(" READ VAR DIM: can't manage "//&
+         CALL logger_error(" IOM CDF READ VAR DIM: can't manage "//&
          &              TRIM(fct_str(id_ndim))//" dimension(s)" )
 
@@ -1531,5 +1421,4 @@
 
    END FUNCTION iom_cdf__read_var_dim
-   !> @endcode   
    !-------------------------------------------------------------------
    !> @brief This subroutine read variable attributes
@@ -1537,11 +1426,11 @@
    !
    !> @author J.Paul
-   !> - Nov, 2013- Initial Version
-   !
-   !> @param[in] td_file : file structure
-   !> @param[inout] td_var : variable structure
-   !> @return filled variable attribute structure 
-   !-------------------------------------------------------------------
-   !> @code
+   !> - November, 2013- Initial Version
+   !
+   !> @param[in] td_file   file structure
+   !> @param[in] id_varid  variable id
+   !> @param[in] id_natt   number of attributes
+   !> @return array of attribute structure
+   !-------------------------------------------------------------------
    FUNCTION iom_cdf__read_var_att(td_file, id_varid, id_natt)
       IMPLICIT NONE
@@ -1555,5 +1444,4 @@
 
       ! local variable
-      TYPE(TATT), DIMENSION(id_natt) :: tl_att
 
       ! loop indices
@@ -1562,35 +1450,35 @@
 
       IF( id_natt > 0 )THEN
-
+      
          ! read attributes
          DO ji = 1, id_natt
-            CALL logger_debug( " READ VAR ATT: get attribute "//&
+            CALL logger_trace( " IOM CDF READ VAR ATT: get attribute "//&
             &               TRIM(fct_str(ji)) )
 
-            tl_att(ji)=iom_cdf_read_att(td_file, id_varid, ji)
+            iom_cdf__read_var_att(ji)=iom_cdf_read_att(td_file, id_varid, ji)
 
          ENDDO
 
-         iom_cdf__read_var_att(:)=tl_att(:)
-
       ELSE
 
-         CALL logger_debug( " READ VAR ATT: no attribute for variable " )
+         CALL logger_debug( " IOM CDF READ VAR ATT: no attribute for variable " )
 
       ENDIF
 
    END FUNCTION iom_cdf__read_var_att
-   !> @endcode   
    !-------------------------------------------------------------------
    !> @brief This subroutine read variable value
    !> in an opened netcdf file.
-   !
-   !> @author J.Paul
-   !> - Nov, 2013- Initial Version
-   !
-   !> @param[in] td_file : file structure
-   !> @param[inout] td_var : variable structure
-   !> @param[in] id_start : index in the variable from which the data values will be read
-   !> @param[in] id_count : number of indices selected along each dimension
+   !> @details
+   !> Optionaly, start indices and number of indices selected along each dimension 
+   !> could be specify in a 4 dimension array (/'x','y','z','t'/)
+   !
+   !> @author J.Paul
+   !> - November, 2013- Initial Version
+   !
+   !> @param[in] td_file   file structure
+   !> @param[inout] td_var variable structure
+   !> @param[in] id_start  index in the variable from which the data values will be read
+   !> @param[in] id_count  number of indices selected along each dimension
    !> @return variable structure completed 
    !
@@ -1598,5 +1486,4 @@
    !> - warning do not change fill value when use scale factor..
    !-------------------------------------------------------------------
-   !> @code
    SUBROUTINE iom_cdf__read_var_value(td_file, td_var, &
    &                                  id_start, id_count )
@@ -1610,173 +1497,186 @@
       ! local variable
       INTEGER(i4)                       :: il_status
-      INTEGER(i4)                       :: il_tmp1, il_tmp2, il_varid
+      INTEGER(i4)                       :: il_tmp1
+      INTEGER(i4)                       :: il_tmp2
+      INTEGER(i4)                       :: il_varid
       INTEGER(i4), DIMENSION(ip_maxdim) :: il_start
       INTEGER(i4), DIMENSION(ip_maxdim) :: il_count
       INTEGER(i4), DIMENSION(ip_maxdim) :: il_start_ord
       INTEGER(i4), DIMENSION(ip_maxdim) :: il_count_ord
-      REAL(dp)   , DIMENSION(:,:,:,:), ALLOCATABLE :: dl_value
-
-      TYPE(TDIM),  DIMENSION(ip_maxdim) :: tl_dim
+      REAL(dp)   , DIMENSION(:,:,:,:)  , ALLOCATABLE :: dl_value
+      REAL(dp)   , DIMENSION(:,:,:,:)  , ALLOCATABLE :: dl_tmp
+
       ! loop indices
       INTEGER(i4) :: ji
       !----------------------------------------------------------------
 
-      ! check id_count and id_start optionals parameters...
-      IF( (       PRESENT(id_start)  .AND. (.NOT. PRESENT(id_count))) .OR. &
-          ((.NOT. PRESENT(id_start)) .AND.        PRESENT(id_count) ) )THEN
-         CALL logger_warn( &
-         &  " READ VAR VALUE: id_start and id_count should be both specify")
-      ENDIF
-
-      IF( PRESENT(id_start).AND.PRESENT(id_count) )THEN
-
-         IF( SIZE(id_start(:)) /= ip_maxdim .OR. &
-         &   SIZE(id_count(:)) /= ip_maxdim )THEN
-            CALL logger_error("READ VAR: dimension of table start or count "//&
-            &      " are invalid to read variable "//TRIM(td_var%c_name)//&
-            &      " in file "//TRIM(td_file%c_name) )
-         ENDIF
-
-         ! change dimension order from ('x','y','z','t')
-         il_start(:)=dim_reorder_xyzt2(td_var%t_dim, id_start(:))
-         il_count(:)=dim_reorder_xyzt2(td_var%t_dim, id_count(:))
-
-         ! keep ordered table ('x','y','z','t')
-         il_start_ord(:)=il_start(:)
-         il_count_ord(:)=il_count(:)
-
+      ! check if variable in file structure
+      il_varid=var_get_id(td_file%t_var(:),TRIM(td_var%c_name))
+      IF( il_varid /= 0 )THEN
+
+         ! check id_count and id_start optionals parameters...
+         IF( (       PRESENT(id_start)  .AND. (.NOT. PRESENT(id_count))) .OR. &
+             ((.NOT. PRESENT(id_start)) .AND.        PRESENT(id_count) ) )THEN
+            CALL logger_warn( &
+            &  "IOM CDF READ VAR VALUE: id_start and id_count should be both specify")
+         ENDIF
+         IF( PRESENT(id_start).AND.PRESENT(id_count) )THEN
+
+            IF( SIZE(id_start(:)) /= ip_maxdim .OR. &
+            &   SIZE(id_count(:)) /= ip_maxdim )THEN
+               CALL logger_error("IOM CDF READ VAR: dimension of array start or count "//&
+               &      " are invalid to read variable "//TRIM(td_var%c_name)//&
+               &      " in file "//TRIM(td_file%c_name) )
+            ENDIF
+
+            ! change dimension order from ('x','y','z','t')
+            il_start(:)=dim_reorder_xyzt2(td_var%t_dim, id_start(:))
+            il_count(:)=dim_reorder_xyzt2(td_var%t_dim, id_count(:))
+
+            ! keep ordered array ('x','y','z','t')
+            il_start_ord(:)=id_start(:)
+            il_count_ord(:)=id_count(:)
+
+         ELSE
+
+            ! change dimension order from ('x','y','z','t')
+            il_start(:)=(/1,1,1,1/)
+            il_count(:)=dim_reorder_xyzt2(td_var%t_dim(:),td_var%t_dim(:)%i_len)
+
+            ! keep ordered array ('x','y','z','t')
+            il_start_ord(:)=(/1,1,1,1/)
+            il_count_ord(:)=td_var%t_dim(:)%i_len
+
+         ENDIF
+
+         ! check dimension
+         IF( .NOT. ALL(il_start_ord(:)>=(/1,1,1,1/)) )THEN
+
+            CALL logger_error( "IOM CDF READ VAR VALUE: start indices should"//&
+            &  " be greater than or equal to 1")
+
+         ENDIF
+
+         IF(.NOT.ALL(il_start_ord(:)+il_count_ord(:)-1 <= &
+            &  (/td_var%t_dim( 1 )%i_len,&
+            &    td_var%t_dim( 2 )%i_len,&
+            &    td_var%t_dim( 3 )%i_len,&
+            &    td_var%t_dim( 4 )%i_len &
+            &                                            /)) )THEN
+
+            CALL logger_error( "IOM CDF READ VAR VALUE: start + count exceed "//&
+            &  "variable dimension for "//TRIM(td_var%c_name) )
+
+            DO ji = 1, ip_maxdim
+               il_tmp1=il_start_ord(ji)+il_count_ord(ji)-1
+               il_tmp2=td_var%t_dim(ji)%i_len
+               CALL logger_debug( "IOM CDF READ VAR VALUE: start + count -1:"//&
+               &  TRIM(fct_str(il_tmp1))//" variable dimension"//&
+               &  TRIM(fct_str(il_tmp2)))
+            ENDDO
+
+         ELSE
+
+            ! Allocate space to hold variable value (unorder)
+            ALLOCATE(dl_value( il_count(1), &
+               &               il_count(2), &
+               &               il_count(3), &
+               &               il_count(4)),&
+               &               stat=il_status)
+            IF( il_status /= 0 )THEN
+
+              CALL logger_error( &
+               &  "IOM CDF READ VAR VALUE: not enough space to put variable "//&
+               &  TRIM(td_var%c_name))
+
+            ENDIF
+
+            ! read values
+            CALL logger_debug( &
+            &  "IOM CDF READ VAR VALUE: get variable "//TRIM(td_var%c_name)//&
+            &  " in file "//TRIM(td_file%c_name))
+
+            il_status = NF90_GET_VAR( td_file%i_id, il_varid,           &
+            &                                       dl_value(:,:,:,:),  &
+            &                                       start = il_start(:),&
+            &                                       count = il_count(:) )
+            CALL iom_cdf__check(il_status)
+
+            ! Allocate space to hold variable value in structure
+            IF( ASSOCIATED(td_var%d_value) )THEN
+               DEALLOCATE(td_var%d_value)   
+            ENDIF
+  
+            ! new dimension length
+            td_var%t_dim(:)%i_len=il_count_ord(:)
+
+!>   dummy patch for pgf95
+            ALLOCATE( dl_tmp( td_var%t_dim(1)%i_len, &
+            &                 td_var%t_dim(2)%i_len, &
+            &                 td_var%t_dim(3)%i_len, &
+            &                 td_var%t_dim(4)%i_len),&
+            &        stat=il_status)
+            IF(il_status /= 0 )THEN
+
+               CALL logger_error( &
+               &  "IOM CDF READ VAR VALUE: not enough space to put variable "//&
+               &  TRIM(td_var%c_name)//&
+               &  " in variable structure")
+            ENDIF
+            dl_tmp(:,:,:,:)=td_var%d_fill
+
+            ! reshape values to be ordered as ('x','y','z','t')
+            dl_tmp(:,:,:,:)=dim_reshape_2xyzt(td_var%t_dim(:), &
+            &                                 dl_value(:,:,:,:))
+
+            DEALLOCATE(dl_value)
+
+            ALLOCATE(td_var%d_value( td_var%t_dim(1)%i_len, &
+            &                        td_var%t_dim(2)%i_len, &
+            &                        td_var%t_dim(3)%i_len, &
+            &                        td_var%t_dim(4)%i_len),&
+            &        stat=il_status)
+            IF(il_status /= 0 )THEN
+
+               CALL logger_error( &
+               &  "IOM CDF READ VAR VALUE: not enough space to put variable "//&
+               &  TRIM(td_var%c_name)//&
+               &  " in variable structure")
+
+            ENDIF
+!            ! FillValue by default
+!            td_var%d_value(:,:,:,:)=td_var%d_fill
+!
+!            ! reshape values to be ordered as ('x','y','z','t')
+!            td_var%d_value(:,:,:,:)=dim_reshape_2xyzt(td_var%t_dim(:), &
+!            &                                         dl_value(:,:,:,:))
+!
+!            DEALLOCATE(dl_value)
+
+            td_var%d_value(:,:,:,:)=dl_tmp(:,:,:,:)
+            DEALLOCATE(dl_tmp)
+!<   dummy patch for pgf95
+
+            ! force to change _FillValue to avoid mistake 
+            ! with dummy zero _FillValue
+            IF( td_var%d_fill == 0._dp )THEN
+               CALL var_chg_FillValue(td_var)
+            ENDIF
+         ENDIF
       ELSE
-
-         ! change dimension order from ('x','y','z','t')
-         il_start(:)=(/1,1,1,1/)
-         il_count(:)=dim_reorder_xyzt2(td_var%t_dim(:),td_var%t_dim(:)%i_len)
-
-         ! keep ordered table ('x','y','z','t')
-         il_start_ord(:)=(/1,1,1,1/)
-         il_count_ord(:)=td_var%t_dim(:)%i_len
-
-      ENDIF
-
-      ! check dimension
-      IF( .NOT. ALL(il_start_ord(:)>=(/1,1,1,1/)) )THEN
-
          CALL logger_error( &
-         &" READ VAR VALUE: start indices should be greater than or equal to 1")
-
-      ENDIF
-
-      IF(.NOT.ALL(il_start_ord(:)+il_count_ord(:)-1<=(/td_var%t_dim(1)%i_len,&
-         &                                             td_var%t_dim(2)%i_len,&
-         &                                             td_var%t_dim(3)%i_len,&
-         &                                             td_var%t_dim(4)%i_len &
-         &                                            /)) )THEN
-
-         CALL logger_error( &
-         &  " READ VAR VALUE: start + count exceed variable dimension" )
-
-         DO ji = 1, ip_maxdim
-            il_tmp1=il_start_ord(ji)+il_count_ord(ji)
-            il_tmp2=td_var%t_dim(ji)%i_len
-            CALL logger_debug( &
-            &  " READ VAR VALUE: start + count -1 "//TRIM(fct_str(il_tmp1))//&
-            &  " variable dimension"//TRIM(fct_str(il_tmp2)))
-         ENDDO
-
-      ELSE
-
-         ! Allocate space to hold variable value (unorder)
-         ALLOCATE(dl_value( il_count(1), &
-            &               il_count(2), &
-            &               il_count(3), &
-            &               il_count(4)),&
-            &               stat=il_status)
-         IF( il_status /= 0 )THEN
-
-           CALL logger_error( &
-            &  " READ VAR VALUE: not enough space to put variable "//&
-            &  TRIM(td_var%c_name))
-
-         ENDIF
-
-         ! read values
-         CALL logger_debug( &
-         &  " READ VAR VALUE: get variable "//TRIM(td_var%c_name)//&
-         &  " in file "//TRIM(td_file%c_name))
-         CALL logger_debug("start "//TRIM(fct_str(il_start(1)))//','//&
-         &                           TRIM(fct_str(il_start(2)))//','//&
-         &                           TRIM(fct_str(il_start(3)))//','//&
-         &                           TRIM(fct_str(il_start(4)))//')'  )
-         CALL logger_debug("count "//TRIM(fct_str(il_count(1)))//','//&
-         &                           TRIM(fct_str(il_count(2)))//','//&
-         &                           TRIM(fct_str(il_count(3)))//','//&
-         &                           TRIM(fct_str(il_count(4)))//')'  )
-         CALL logger_debug("dim "//TRIM(fct_str(td_file%t_dim(1)%i_len))//','//&
-         &                         TRIM(fct_str(td_file%t_dim(2)%i_len))//','//&
-         &                         TRIM(fct_str(td_file%t_dim(3)%i_len))//','//&
-         &                         TRIM(fct_str(td_file%t_dim(4)%i_len))//')'  )
-         CALL logger_debug("shape "//TRIM(fct_str(SIZE(dl_value,DIM=1)))//","//&
-         &                           TRIM(fct_str(SIZE(dl_value,DIM=2)))//","//&
-         &                           TRIM(fct_str(SIZE(dl_value,DIM=3)))//","//&
-         &                           TRIM(fct_str(SIZE(dl_value,DIM=4)))//")" )
-         CALL logger_debug("var "//TRIM(td_var%c_name))
-         il_varid=var_get_id(td_file%t_var(:),TRIM(td_var%c_name))
-         CALL logger_debug("var id "//TRIM(fct_str(il_varid))//' '//TRIM(fct_str(td_var%i_id)))
-         CALL logger_debug("file id "//TRIM(fct_str(td_file%i_id)))
-         il_status = NF90_GET_VAR( td_file%i_id, td_var%i_id,        &
-         &                                       dl_value(:,:,:,:),  &
-         &                                       start = il_start(:),&
-         &                                       count = il_count(:) )
-         CALL iom_cdf__check(il_status)
-
-         ! Allocate space to hold variable value in structure
-         IF( ASSOCIATED(td_var%d_value) )THEN
-            DEALLOCATE(td_var%d_value)   
-         ENDIF
-  
-         ! new dimension length
-         td_var%t_dim(:)%i_len=il_count_ord(:)
-
-         ALLOCATE(td_var%d_value( il_count_ord(1), &
-         &                        il_count_ord(2), &
-         &                        il_count_ord(3), &
-         &                        il_count_ord(4)),&
-         &        stat=il_status)
-         IF(il_status /= 0 )THEN
-
-            CALL logger_error( &
-            &  " READ VAR VALUE: not enough space to put variable "//&
-            &  TRIM(td_var%c_name)//&
-            &  " in variable structure")
-
-         ENDIF
-         ! FillValue by default
-         td_var%d_value(:,:,:,:)=td_var%d_fill
-
-         ! reshape values to be ordered as ('x','y','z','t')
-         tl_dim(:)=td_var%t_dim(:)
-         td_var%d_value(:,:,:,:)=dim_reshape_2xyzt(tl_dim,dl_value(:,:,:,:))
-
-         DEALLOCATE(dl_value)
-
-         ! force to change _FillValue to avoid mistake 
-         ! with dummy zero _FillValue
-         IF( td_var%d_fill == 0._dp )THEN
-            CALL var_chg_FillValue(td_var)
-         ENDIF
+         &  "IOM CDF READ VAR VALUE: no variable "//TRIM(td_var%c_name)//&
+         &  " in file structure "//TRIM(td_file%c_name))
       ENDIF
 
    END SUBROUTINE iom_cdf__read_var_value
-   !> @endcode   
    !-------------------------------------------------------------------
    !> @brief This subroutine write file structure in an opened netcdf file.
    !
-   !> @details
-   !
-   !> @author J.Paul
-   !> - Nov, 2013- Initial Version
-   !
-   !> @param[in] td_file : file structure
-   !-------------------------------------------------------------------
-   !> @code
+   !> @author J.Paul
+   !> - November, 2013- Initial Version
+   !
+   !> @param[inout] td_file   file structure
+   !-------------------------------------------------------------------
    SUBROUTINE iom_cdf_write_file(td_file)
       IMPLICIT NONE
@@ -1800,14 +1700,14 @@
 
          CALL logger_error( &
-         &  " WRITE FILE: no id associated to file "//TRIM(td_file%c_name))
+         &  " IOM CDF WRITE FILE: no id associated to file "//TRIM(td_file%c_name))
 
       ELSE
          IF( td_file%l_wrt )THEN
 
-            ! delete dummy variable
-            CALL file_del_var( td_file, 'no0d' )
-            CALL file_del_var( td_file, 'no1d' )
-            CALL file_del_var( td_file, 'no2d' )
-            CALL file_del_var( td_file, 'no3d' )
+            ! remove dummy variable
+            CALL file_del_var(td_file,'no0d')
+            CALL file_del_var(td_file,'no1d')
+            CALL file_del_var(td_file,'no2d')
+            CALL file_del_var(td_file,'no3d')
 
             DO ji = 1, td_file%i_nvar
@@ -1816,9 +1716,13 @@
 
             ! save usefull dimension
-            tl_dim(:)=var_max_dim(td_file%t_var(:))
-
-            DO ji=1,ip_maxdim
-               IF( tl_dim(ji)%l_use ) CALL file_move_dim(td_file, tl_dim(ji))
-            ENDDO
+            IF( ASSOCIATED(td_file%t_var) )THEN
+               tl_dim(:)=var_max_dim(td_file%t_var(:))
+
+               DO ji=1,ip_maxdim
+                  IF( tl_dim(ji)%l_use ) CALL file_move_dim(td_file, tl_dim(ji))
+               ENDDO
+               ! clean
+               CALL dim_clean(tl_dim(:))
+            ENDIF
 
             ! write dimension in file
@@ -1836,6 +1740,10 @@
 
                   DEALLOCATE(il_value)
+
+                  ! do not use FillValue for dimension variable
+                  CALL var_del_att(tl_var, "_FillValue")
                    
                   CALL iom_cdf__write_var(td_file,tl_var)
+                  ! clean
                   CALL var_clean(tl_var)
 
@@ -1856,5 +1764,5 @@
 
             CALL logger_error( &
-            &  " WRITE FILE: try to write in file "//TRIM(td_file%c_name)//&
+            &  "IOM CDF WRITE FILE: try to write in file "//TRIM(td_file%c_name)//&
             &  ", not opened in write mode")
 
@@ -1863,5 +1771,4 @@
 
    END SUBROUTINE iom_cdf_write_file
-   !> @endcode
    !-------------------------------------------------------------------
    !> @brief This subroutine write one dimension in an opened netcdf 
@@ -1869,10 +1776,9 @@
    !
    !> @author J.Paul
-   !> - Nov, 2013- Initial Version
-   !
-   !> @param[inout] td_file : file structure
-   !> @param[inout] td_dim : dimension structure
-   !-------------------------------------------------------------------
-   !> @code
+   !> - November, 2013- Initial Version
+   !
+   !> @param[inout] td_file   file structure
+   !> @param[inout] td_dim    dimension structure
+   !-------------------------------------------------------------------
    SUBROUTINE iom_cdf__write_dim(td_file, td_dim)
       IMPLICIT NONE
@@ -1887,6 +1793,6 @@
       IF( .NOT. td_file%l_def )THEN
 
-         CALL logger_debug( &
-         &  " WRITE FILE DIM: Enter define mode, file "//TRIM(td_file%c_name))
+         CALL logger_trace( &
+         &  " IOM CDF WRITE FILE DIM: Enter define mode, file "//TRIM(td_file%c_name))
 
          ! Enter define mode
@@ -1901,6 +1807,6 @@
          IF( td_dim%l_uld )THEN
             ! write unlimited dimension
-            CALL logger_debug( &
-            &  " WRITE FILE DIM: write unlimited dimension "//&
+            CALL logger_trace( &
+            &  "IOM CDF WRITE FILE DIM: write unlimited dimension "//&
             &  TRIM(td_dim%c_name)//" in file "//TRIM(td_file%c_name))
 
@@ -1911,6 +1817,6 @@
          ELSE
             ! write not unlimited dimension
-            CALL logger_debug( &
-            &  " WRITE FILE DIM: write dimension "//TRIM(td_dim%c_name)//&
+            CALL logger_trace( &
+            &  "IOM CDF WRITE FILE DIM: write dimension "//TRIM(td_dim%c_name)//&
             &  " in file "//TRIM(td_file%c_name))
             
@@ -1923,5 +1829,4 @@
 
    END SUBROUTINE iom_cdf__write_dim
-   !> @endcode   
    !-------------------------------------------------------------------
    !> @brief This subroutine write a variable attribute in
@@ -1929,12 +1834,11 @@
    !
    !> @author J.Paul
-   !> - Nov, 2013- Initial Version
-   !
-   !> @param[inout] td_file : file structure
-   !> @param[in] id_varid : variable id. use NF90_GLOBAL to write global attribute
-   !> in a file
-   !> @param[in] td_att : attribute structure
-   !-------------------------------------------------------------------
-   !> @code
+   !> - November, 2013- Initial Version
+   !
+   !> @param[inout] td_file   file structure
+   !> @param[in] id_varid     variable id. use NF90_GLOBAL to write 
+   !> global attribute in a file
+   !> @param[in] td_att       attribute structure
+   !-------------------------------------------------------------------
    SUBROUTINE iom_cdf__write_att(td_file, id_varid, td_att)
       IMPLICIT NONE
@@ -1950,6 +1854,6 @@
       IF( .NOT. td_file%l_def )THEN
 
-         CALL logger_debug( &
-         &  " WRITE FILE ATT: Enter define mode, file "//TRIM(td_file%c_name))
+         CALL logger_trace( &
+         &  "IOM CDF WRITE FILE ATT: Enter define mode, file "//TRIM(td_file%c_name))
 
          ! Enter define mode
@@ -1962,6 +1866,6 @@
 
       !! put attribute value
-      CALL logger_debug( &
-      &  " WRITE FILE ATT: write attribute "//TRIM(td_att%c_name)//&
+      CALL logger_trace( &
+      &  "IOM CDF WRITE FILE ATT: write attribute "//TRIM(td_att%c_name)//&
       &  " of variable "//TRIM(fct_str(id_varid))//&
       &  " in file "//TRIM(td_file%c_name))
@@ -1983,15 +1887,13 @@
 
    END SUBROUTINE iom_cdf__write_att
-   !> @endcode   
-   !-------------------------------------------------------------------
-   !> @brief This subroutine write a variable in an opened netcdf file.</br/>
-   !
-   !> @author J.Paul
-   !> - Nov, 2013- Initial Version
-   !
-   !> @param[inout] td_file : file structure
-   !> @param[inout] td_var : variable structure
-   !-------------------------------------------------------------------
-   !> @code
+   !-------------------------------------------------------------------
+   !> @brief This subroutine write a variable in an opened netcdf file.
+   !
+   !> @author J.Paul
+   !> - November, 2013- Initial Version
+   !
+   !> @param[inout] td_file   file structure
+   !> @param[inout] td_var    variable structure
+   !-------------------------------------------------------------------
    SUBROUTINE iom_cdf__write_var(td_file, td_var)
       IMPLICIT NONE
@@ -2002,10 +1904,14 @@
       ! local variable
       INTEGER(i4) :: il_status
+      LOGICAL     :: ll_chg
+      ! loop indices
+      INTEGER(i4) :: ji
       !----------------------------------------------------------------
 
       IF( .NOT. td_file%l_def )THEN
 
-         CALL logger_debug( &
-         &  " WRITE FILE VAR: Enter define mode, file "//TRIM(td_file%c_name))
+         CALL logger_trace( &
+         &  " IOM CDF WRITE VAR: Enter define mode, file "//&
+         &  TRIM(td_file%c_name))
 
          ! Enter define mode
@@ -2023,6 +1929,20 @@
          CALL var_check_dim(td_var)
 
-         ! change fill value to NETCDF standard
-         CALL var_chg_FillValue(td_var)
+         ll_chg=.TRUE.
+         DO ji=1,ip_maxdim
+            IF( TRIM(fct_lower(cp_dimorder(ji:ji))) == &
+            &   TRIM(fct_lower(td_var%c_name)) )THEN
+               ll_chg=.FALSE.
+               CALL logger_trace(TRIM(fct_lower(td_var%c_name))//' is var dimension')
+               EXIT
+            ENDIF
+         ENDDO
+         IF( ll_chg )THEN
+            ! not a dimension variable
+            ! change FillValue
+
+            ! ugly patch until NEMO do not force to use 0. as FillValue 
+            CALL var_chg_FillValue(td_var,0._dp)
+         ENDIF
 
          ! define variable in file
@@ -2031,6 +1951,7 @@
          IF( td_file%l_def )THEN
 
-            CALL logger_debug( &
-            &  " WRITE FILE VAR: Leave define mode, file "//TRIM(td_file%c_name))
+            CALL logger_trace( &
+            &  " IOM CDF WRITE VAR: Leave define mode, file "//&
+            &  TRIM(td_file%c_name))
 
             ! Leave define mode
@@ -2050,16 +1971,14 @@
 
    END SUBROUTINE iom_cdf__write_var
-   !> @endcode   
    !-------------------------------------------------------------------
    !> @brief This function define variable in an opened netcdf file.
    !
    !> @author J.Paul
-   !> - Nov, 2013- Initial Version
-   !
-   !> @param[in] td_file : file structure
-   !> @param[in] td_var : variable structure
+   !> - November, 2013- Initial Version
+   !
+   !> @param[in] td_file   file structure
+   !> @param[in] td_var    variable structure
    !> @return  variable id
    !-------------------------------------------------------------------
-   !> @code
    INTEGER(i4) FUNCTION iom_cdf__write_var_def(td_file, td_var)
       IMPLICIT NONE
@@ -2070,5 +1989,8 @@
       ! local variable
       INTEGER(i4)                       :: il_status
+      INTEGER(i4)                       :: il_ind
       INTEGER(i4), DIMENSION(ip_maxdim) :: il_dimid
+
+      TYPE(TVAR)                        :: tl_var
 
       ! loop indices
@@ -2077,12 +1999,11 @@
       !----------------------------------------------------------------
 
-      CALL logger_debug( &
-      &  " WRITE FILE VAR DEF: get dimension to be used for variable "//&
-      &  TRIM(td_var%c_name)//" in file "//TRIM(td_file%c_name))
-
-      IF( ALL( .NOT. td_var%t_dim(:)%l_use ) )THEN
+      ! copy structure
+      tl_var=var_copy(td_var)
+
+      IF( ALL( .NOT. tl_var%t_dim(:)%l_use ) )THEN
          ! scalar value
-         il_status = NF90_DEF_VAR(td_file%i_id, TRIM(td_var%c_name), &
-         &                        td_var%i_type, varid=iom_cdf__write_var_def) 
+         il_status = NF90_DEF_VAR(td_file%i_id, TRIM(tl_var%c_name), &
+         &                        tl_var%i_type, varid=iom_cdf__write_var_def) 
          CALL iom_cdf__check(il_status)
       ELSE
@@ -2093,20 +2014,19 @@
          ! reorder dimension, so unused dimension won't be written
          DO ji = 1,  ip_maxdim
-            IF( td_var%t_dim(ji)%l_use )THEN
+            IF( tl_var%t_dim(ji)%l_use )THEN
                jj=jj+1
-               CALL logger_debug(" get dim id for dimension "//TRIM(td_var%t_dim(ji)%c_name))
-               il_dimid(jj)=dim_get_id(td_file%t_dim(:),td_var%t_dim(ji)%c_name)
+               il_dimid(jj)=dim_get_id(td_file%t_dim(:),tl_var%t_dim(ji)%c_name)
             ENDIF
          ENDDO
 
-         CALL logger_debug( &
-         &  " WRITE FILE VAR DEF: define dimension to be used for variable "//&
-         &  TRIM(td_var%c_name)//" in file "//TRIM(td_file%c_name))
+         CALL logger_trace( &
+         &  "IOM CDF WRITE VAR DEF: define dimension to be used for variable "//&
+         &  TRIM(tl_var%c_name)//" in file "//TRIM(td_file%c_name))
 
          DO ji=1,jj
-            CALL logger_debug(" WRITE FILE VAR DEF: dimid "//TRIM(fct_str(il_dimid(ji))) )
+            CALL logger_trace("IOM CDF WRITE VAR DEF: dimid "//TRIM(fct_str(il_dimid(ji))) )
          ENDDO
-         il_status = NF90_DEF_VAR(td_file%i_id, TRIM(td_var%c_name),     &
-         &                        td_var%i_type,                         &
+         il_status = NF90_DEF_VAR(td_file%i_id, TRIM(tl_var%c_name),     &
+         &                        tl_var%i_type,                         &
          &                        il_dimid(1:jj),                        &
          &                        varid=iom_cdf__write_var_def           )
@@ -2114,45 +2034,52 @@
       ENDIF
 
-      DO ji = 1, td_var%i_natt
-         CALL logger_debug( &
-         &  " WRITE FILE VAR DEF: put attribute "//TRIM(td_var%t_att(ji)%c_name)//&
-         &  " for variable "//TRIM(td_var%c_name)//&
+      ! remove unuseful attribute
+      il_ind=att_get_index( tl_var%t_att(:), "ew_overlap" )
+      IF( il_ind /= 0 )THEN
+         IF( tl_var%t_att(il_ind)%d_value(1) == -1 )THEN
+            CALL var_del_att(tl_var, tl_var%t_att(il_ind))
+         ENDIF
+      ENDIF
+
+      DO ji = 1, tl_var%i_natt
+         CALL logger_trace( &
+         &  " IOM CDF WRITE VAR DEF: put attribute "//TRIM(tl_var%t_att(ji)%c_name)//&
+         &  " for variable "//TRIM(tl_var%c_name)//&
          &  " in file "//TRIM(td_file%c_name) )
 
-         IF( td_var%t_att(ji)%i_type == NF90_CHAR )THEN
-            !IF( TRIM(td_var%t_att(ji)%c_value) /= 'unknown' )THEN
-            IF( TRIM(td_var%t_att(ji)%c_value) /= '' )THEN
+         IF( tl_var%t_att(ji)%i_type == NF90_CHAR )THEN
+            IF( TRIM(tl_var%t_att(ji)%c_value) /= '' )THEN
                il_status = NF90_PUT_ATT(td_file%i_id, iom_cdf__write_var_def, &
-               &                        TRIM(td_var%t_att(ji)%c_name),        &
-               &                        TRIM(td_var%t_att(ji)%c_value)        )
+               &                        TRIM(tl_var%t_att(ji)%c_name),        &
+               &                        TRIM(tl_var%t_att(ji)%c_value)        )
                CALL iom_cdf__check(il_status)
             ENDIF
          ELSE
-            SELECT CASE(td_var%t_att(ji)%i_type)
+            SELECT CASE(tl_var%t_att(ji)%i_type)
                CASE(NF90_BYTE)
                   il_status = NF90_PUT_ATT(td_file%i_id,                   &
                   &                        iom_cdf__write_var_def,         &
-                  &                        TRIM(td_var%t_att(ji)%c_name),  &
-                  &                        INT(td_var%t_att(ji)%d_value(:),i1))
+                  &                        TRIM(tl_var%t_att(ji)%c_name),  &
+                  &                        INT(tl_var%t_att(ji)%d_value(:),i1))
                CASE(NF90_SHORT)
                   il_status = NF90_PUT_ATT(td_file%i_id,                   &
                   &                        iom_cdf__write_var_def,         &
-                  &                        TRIM(td_var%t_att(ji)%c_name),  &
-                  &                        INT(td_var%t_att(ji)%d_value(:),i2))
+                  &                        TRIM(tl_var%t_att(ji)%c_name),  &
+                  &                        INT(tl_var%t_att(ji)%d_value(:),i2))
                CASE(NF90_INT)
                   il_status = NF90_PUT_ATT(td_file%i_id,                   &
                   &                        iom_cdf__write_var_def,         &
-                  &                        TRIM(td_var%t_att(ji)%c_name),  &
-                  &                        INT(td_var%t_att(ji)%d_value(:),i4))
+                  &                        TRIM(tl_var%t_att(ji)%c_name),  &
+                  &                        INT(tl_var%t_att(ji)%d_value(:),i4))
                CASE(NF90_FLOAT)
                   il_status = NF90_PUT_ATT(td_file%i_id,                   &
                   &                        iom_cdf__write_var_def,         &
-                  &                        TRIM(td_var%t_att(ji)%c_name),  &
-                  &                        REAL(td_var%t_att(ji)%d_value(:),sp))
+                  &                        TRIM(tl_var%t_att(ji)%c_name),  &
+                  &                        REAL(tl_var%t_att(ji)%d_value(:),sp))
                CASE(NF90_DOUBLE)
                   il_status = NF90_PUT_ATT(td_file%i_id,                   &
                   &                        iom_cdf__write_var_def,         &
-                  &                        TRIM(td_var%t_att(ji)%c_name),  &
-                  &                        REAL(td_var%t_att(ji)%d_value(:),dp))
+                  &                        TRIM(tl_var%t_att(ji)%c_name),  &
+                  &                        REAL(tl_var%t_att(ji)%d_value(:),dp))
                END SELECT
             CALL iom_cdf__check(il_status)
@@ -2161,5 +2088,4 @@
 
    END FUNCTION iom_cdf__write_var_def
-   !> @endcode
    !-------------------------------------------------------------------
    !> @brief This subroutine put variable value in an opened netcdf file.
@@ -2167,14 +2093,13 @@
    !> @details
    !> The variable is written in the type define in variable structure.
-   !> Only dimension used are printed, and fillValue in table are
+   !> Only dimension used are printed, and fillValue in array are
    !> replaced by default fill values defined in module netcdf for each type. 
    !
    !> @author J.Paul
-   !> - Nov, 2013- Initial Version
-   !
-   !> @param[in] td_file : file structure
-   !> @param[in] td_var : variable structure
-   !-------------------------------------------------------------------
-   !> @code
+   !> - November, 2013- Initial Version
+   !
+   !> @param[in] td_file   file structure
+   !> @param[in] td_var    variable structure
+   !-------------------------------------------------------------------
    SUBROUTINE iom_cdf__write_var_value(td_file, td_var)
       IMPLICIT NONE
@@ -2194,6 +2119,6 @@
 
       ! check which dimension use
-      CALL logger_debug( &
-      &  " WRITE FILE VAR VALUE: get dimension to be used for variable "//&
+      CALL logger_trace( &
+      &  "IOM CDF WRITE VAR VALUE: get dimension to be used for variable "//&
       &  TRIM(td_var%c_name)//" in file "//TRIM(td_file%c_name))
 
@@ -2202,6 +2127,4 @@
          IF( td_var%t_dim(ji)%l_use )THEN
             jj=jj+1
-            !il_order(ji)=jj
-            !il_shape(ji)=td_var%t_dim(jj)%i_len
             il_order(jj)=ji
             il_shape(jj)=td_var%t_dim(ji)%i_len
@@ -2212,6 +2135,4 @@
          IF( .NOT. td_var%t_dim(ji)%l_use )THEN
             jj=jj+1
-            !il_order(ji)=jj
-            !il_shape(ji)=td_var%t_dim(jj)%i_len
             il_order(jj)=ji
             il_shape(jj)=td_var%t_dim(ji)%i_len
@@ -2221,5 +2142,5 @@
       ALLOCATE( dl_value( il_shape(1),il_shape(2),il_shape(3),il_shape(4) ) )
 
-      ! reshape table, so unused dimension won't be written
+      ! reshape array, so unused dimension won't be written
       dl_value(:,:,:,:)=RESHAPE(source=td_var%d_value(:,:,:,:),&
       &                         SHAPE = il_shape(:), &
@@ -2227,6 +2148,6 @@
 
       ! put value
-      CALL logger_debug( &
-      &  " WRITE FILE VAR VALUE: put "//TRIM(td_var%c_name)//" value "//&
+      CALL logger_trace( &
+      &  "IOM CDF WRITE VAR VALUE: put "//TRIM(td_var%c_name)//" value "//&
       &  "in file "//TRIM(td_file%c_name))
 
@@ -2237,4 +2158,3 @@
 
    END SUBROUTINE iom_cdf__write_var_value
-   !> @endcode
 END MODULE iom_cdf
