Index: /trunk/UTIL/CFG_TOOLS/Makefile
===================================================================
--- /trunk/UTIL/CFG_TOOLS/Makefile	(revision 1799)
+++ /trunk/UTIL/CFG_TOOLS/Makefile	(revision 1799)
@@ -0,0 +1,57 @@
+#
+# Makefile 
+#
+#---------------------------------------------------------------------
+
+EXEC_BIN1 = create_coordinates.exe
+
+NCDF_PATH= /usr/local/include
+NETCDF_LIB = -L/usr/local/lib -lnetcdf
+
+F_C = gfortran
+F_P = 
+F_O = -ffixed-line-length-132 -fdefault-real-8 -c -I$(NCDF_PATH) $(F_P) $(NETCDF_LIB)
+
+OBJSET  = \
+	agrif_types.o \
+	io_netcdf.o \
+	agrif_readwrite.o \
+ 	tools_brice.o \
+
+### Target
+all: 		$(EXEC_BIN1) 
+		@echo compilation is OK		
+
+
+### dependancies
+$(EXEC_BIN1) :	$(OBJSET) create_coordinates.o
+		$(F_C) -o $(EXEC_BIN1) create_coordinates.o $(OBJSET) $(NETCDF_LIB)
+                    			
+
+
+agrif_readwrite.o : io_netcdf.o agrif_types.o agrif_readwrite.f90
+	$(F_C)  $(F_O) agrif_readwrite.f90 
+
+create_coordinates.o : agrif_readwrite.o create_coordinates.f90
+	$(F_C)  $(F_O) create_coordinates.f90
+
+agrif_types.o : agrif_types.f90
+	$(F_C)  $(F_O) agrif_types.f90 
+
+io_netcdf.o : agrif_types.o io_netcdf.f90
+	$(F_C)  $(F_O) io_netcdf.f90
+
+tools_brice.o : agrif_types.o tools_brice.f90
+	$(F_C)  $(F_O) tools_brice.f90
+
+
+### cleaning objects, libraries and executables
+clean:
+		rm -f *.o *.mod $(EXEC_BIN1)
+		@echo \(.o .mod and executables are removed\)
+
+### execution
+exe:
+		./$(EXEC_BIN1) namelist
+		make clean
+		@echo \(OK execution\)
Index: /trunk/UTIL/CFG_TOOLS/agrif_readwrite.f90
===================================================================
--- /trunk/UTIL/CFG_TOOLS/agrif_readwrite.f90	(revision 1799)
+++ /trunk/UTIL/CFG_TOOLS/agrif_readwrite.f90	(revision 1799)
@@ -0,0 +1,212 @@
+MODULE agrif_readwrite
+  !
+  USE agrif_types
+  !USE tools_brice
+  !
+  IMPLICIT NONE
+  !
+  !INTEGER :: nx_fine, ny_fine
+  !
+CONTAINS
+  !       
+  !*****************************************************
+  !   function Read_Coordinates(name,Grid)
+  !*****************************************************
+
+  INTEGER FUNCTION Read_Coordinates(name,Grid,Pacifique)
+    !
+    USE io_netcdf
+    !    
+    !  file name to open
+    ! 
+    CHARACTER(*) name
+    LOGICAL,OPTIONAL :: Pacifique
+    ! 
+    TYPE(Coordinates) :: Grid
+    !      
+    CALL Read_Ncdf_var('glamt',name,Grid%glamt)
+    CALL Read_Ncdf_var('glamu',name,Grid%glamu)
+    CALL Read_Ncdf_var('glamv',name,Grid%glamv)
+    CALL Read_Ncdf_var('glamf',name,Grid%glamf)
+    CALL Read_Ncdf_var('gphit',name,Grid%gphit)
+    CALL Read_Ncdf_var('gphiu',name,Grid%gphiu)
+    CALL Read_Ncdf_var('gphiv',name,Grid%gphiv)
+    CALL Read_Ncdf_var('gphif',name,Grid%gphif)
+    CALL Read_Ncdf_var('e1t',name,Grid%e1t)
+    CALL Read_Ncdf_var('e1u',name,Grid%e1u)
+    CALL Read_Ncdf_var('e1v',name,Grid%e1v)
+    CALL Read_Ncdf_var('e1f',name,Grid%e1f)
+    CALL Read_Ncdf_var('e2t',name,Grid%e2t)
+    CALL Read_Ncdf_var('e2u',name,Grid%e2u)
+    CALL Read_Ncdf_var('e2v',name,Grid%e2v)
+    CALL Read_Ncdf_var('e2f',name,Grid%e2f)
+    CALL Read_Ncdf_var('nav_lon',name,Grid%nav_lon)
+    CALL Read_Ncdf_var('nav_lat',name,Grid%nav_lat)       
+    ! 
+    IF( PRESENT(Pacifique) )THEN
+       IF ( Grid%glamt(1,1) > Grid%glamt(nxfin,nyfin) ) THEN           
+       Pacifique = .TRUE.
+       WHERE ( Grid%glamt < 0 )
+          Grid%glamt = Grid%glamt + 360.
+       END WHERE
+       WHERE ( Grid%glamf < 0 )
+          Grid%glamf = Grid%glamf + 360.
+       END WHERE
+       WHERE ( Grid%glamu < 0 )
+          Grid%glamu = Grid%glamu + 360.
+       END WHERE
+       WHERE ( Grid%glamv < 0 )
+          Grid%glamv = Grid%glamv + 360.
+       END WHERE
+       WHERE ( Grid%nav_lon < 0 )
+          Grid%nav_lon = Grid%nav_lon + 360.
+       END WHERE
+       ENDIF
+    ENDIF
+    !            
+    WRITE(*,*) ' '
+    WRITE(*,*) 'Reading coordinates file: ',name
+    WRITE(*,*) ' '
+    !      
+    Read_Coordinates = 1
+    !      
+  END FUNCTION Read_Coordinates
+
+  !*****************************************************
+  !   function Write_Coordinates(name,Grid)
+  !*****************************************************
+
+  INTEGER FUNCTION Write_Coordinates(name,Grid,nx_fine,ny_fine)
+    !
+    USE io_netcdf
+    CHARACTER(*) name
+    TYPE(Coordinates) :: Grid
+    INTEGER :: status,ncid,z
+    REAL*8,DIMENSION(:),POINTER :: tabtemp
+    INTEGER,DIMENSION(:),POINTER :: tabint
+    CHARACTER(len=20),DIMENSION(4) :: dimnames
+	INTEGER :: nx_fine, ny_fine
+    !
+    status = nf90_create(name,NF90_WRITE,ncid)
+    status = nf90_close(ncid)
+    !           
+    !CALL Write_Ncdf_dim('x',name,nxfin)
+    !CALL Write_Ncdf_dim('y',name,nyfin)
+	CALL Write_Ncdf_dim('x',name,nx_fine)
+    CALL Write_Ncdf_dim('y',name,ny_fine)
+    IF(.NOT. iom_activated) CALL Write_Ncdf_dim('z',name,1)
+    CALL Write_Ncdf_dim('time',name,0)
+    !      
+    dimnames(1)='x'
+    dimnames(2)='y'
+    CALL Write_Ncdf_var('nav_lon',dimnames(1:2),name,Grid%nav_lon,'float')      
+    CALL Write_Ncdf_var('nav_lat',dimnames(1:2),name,Grid%nav_lat,'float')
+    !
+    IF(.NOT. iom_activated) THEN
+       ! copy nav_lev variable -> IOIPSL
+       CALL Read_Ncdf_dim('z',parent_coordinate_file,z)
+       ALLOCATE(tabtemp(z))
+       CALL Read_Ncdf_var('nav_lev',TRIM(parent_coordinate_file),tabtemp)
+       CALL Write_Ncdf_var('nav_lev','z',name,tabtemp,'float')           
+       DEALLOCATE(tabtemp)
+    ENDIF
+    !
+    CALL Read_Ncdf_var('time',TRIM(parent_coordinate_file),tabtemp)
+    CALL Write_Ncdf_var('time','time',name,tabtemp,'float')           
+    DEALLOCATE(tabtemp)      
+    CALL Read_Ncdf_var('time_steps',TRIM(parent_coordinate_file),tabint)
+    CALL Write_Ncdf_var('time_steps','time',name,tabint) 
+    !      
+    dimnames(1)='x'
+    dimnames(2)='y'
+    IF(iom_activated) THEN
+       dimnames(3)='time'
+    ELSE
+       dimnames(3)='z'
+       dimnames(4)='time'
+    ENDIF
+
+    CALL Write_Ncdf_var('glamt',dimnames,name,Grid%glamt,3,'double')
+    CALL Write_Ncdf_var('glamu',dimnames,name,Grid%glamu,3,'double')
+    CALL Write_Ncdf_var('glamv',dimnames,name,Grid%glamv,3,'double')
+    CALL Write_Ncdf_var('glamf',dimnames,name,Grid%glamf,3,'double')
+    CALL Write_Ncdf_var('gphit',dimnames,name,Grid%gphit,3,'double')
+    CALL Write_Ncdf_var('gphiu',dimnames,name,Grid%gphiu,3,'double')
+    CALL Write_Ncdf_var('gphiv',dimnames,name,Grid%gphiv,3,'double')
+    CALL Write_Ncdf_var('gphif',dimnames,name,Grid%gphif,3,'double')      
+    CALL Write_Ncdf_var('e1t',dimnames,name,Grid%e1t,3,'double')      
+    CALL Write_Ncdf_var('e1u',dimnames,name,Grid%e1u,3,'double')     
+    CALL Write_Ncdf_var('e1v',dimnames,name,Grid%e1v,3,'double')      
+    CALL Write_Ncdf_var('e1f',dimnames,name,Grid%e1f,3,'double')
+    CALL Write_Ncdf_var('e2t',dimnames,name,Grid%e2t,3,'double')
+    CALL Write_Ncdf_var('e2u',dimnames,name,Grid%e2u,3,'double')
+    CALL Write_Ncdf_var('e2v',dimnames,name,Grid%e2v,3,'double')
+    CALL Write_Ncdf_var('e2f',dimnames,name,Grid%e2f,3,'double')
+    !      
+    CALL Copy_Ncdf_att('nav_lon',TRIM(parent_coordinate_file),name,&
+         MINVAL(Grid%nav_lon),MAXVAL(Grid%nav_lon))
+    CALL Copy_Ncdf_att('nav_lat',TRIM(parent_coordinate_file),name,&
+         MINVAL(Grid%nav_lat),MAXVAL(Grid%nav_lat))
+    CALL Copy_Ncdf_att('nav_lev',TRIM(parent_coordinate_file),name)
+    CALL Copy_Ncdf_att('time',TRIM(parent_coordinate_file),name)
+    CALL Copy_Ncdf_att('time_steps',TRIM(parent_coordinate_file),name)
+    CALL Copy_Ncdf_att('glamt',TRIM(parent_coordinate_file),name)
+    CALL Copy_Ncdf_att('glamu',TRIM(parent_coordinate_file),name)
+    CALL Copy_Ncdf_att('glamv',TRIM(parent_coordinate_file),name)
+    CALL Copy_Ncdf_att('glamf',TRIM(parent_coordinate_file),name)
+    CALL Copy_Ncdf_att('gphit',TRIM(parent_coordinate_file),name)
+    CALL Copy_Ncdf_att('gphiu',TRIM(parent_coordinate_file),name)
+    CALL Copy_Ncdf_att('gphiv',TRIM(parent_coordinate_file),name)
+    CALL Copy_Ncdf_att('gphif',TRIM(parent_coordinate_file),name)
+    CALL Copy_Ncdf_att('e1t',TRIM(parent_coordinate_file),name)
+    CALL Copy_Ncdf_att('e1u',TRIM(parent_coordinate_file),name)
+    CALL Copy_Ncdf_att('e1v',TRIM(parent_coordinate_file),name)
+    CALL Copy_Ncdf_att('e1f',TRIM(parent_coordinate_file),name)
+    CALL Copy_Ncdf_att('e2t',TRIM(parent_coordinate_file),name)
+    CALL Copy_Ncdf_att('e2u',TRIM(parent_coordinate_file),name)
+    CALL Copy_Ncdf_att('e2v',TRIM(parent_coordinate_file),name)
+    CALL Copy_Ncdf_att('e2f',TRIM(parent_coordinate_file),name)            
+    !
+    WRITE(*,*) ' '
+    WRITE(*,*) 'Writing coordinates file: ',name
+    IF(.NOT. iom_activated) WRITE(*,*) 'IOISPL format'
+    IF(iom_activated) WRITE(*,*) 'IOM format'      
+    WRITE(*,*) ' '
+    !
+    Write_Coordinates = 1
+    !      
+  END FUNCTION Write_Coordinates
+  !
+  !
+  !*****************************************************
+  !   function set_child_name(Parentname,Childname)
+  !*****************************************************
+  !
+  SUBROUTINE set_child_name(Parentname,Childname)
+    !
+    CHARACTER(*),INTENT(in) :: Parentname
+    CHARACTER(*),INTENT(out) :: Childname
+    CHARACTER(2) :: prefix
+    INTEGER :: pos
+    !   
+    pos  = INDEX(TRIM(Parentname),'/',back=.TRUE.)
+    !
+    prefix=Parentname(pos+1:pos+2)
+    IF (prefix == '1_') THEN
+       Childname = '2_'//Parentname(pos+3:LEN(Parentname)) 
+    ELSEIF (prefix == '2_') THEN
+       Childname = '3_'//Parentname(pos+3:LEN(Parentname)) 
+    ELSEIF (prefix == '3_') THEN
+       Childname = '4_'//Parentname(pos+3:LEN(Parentname)) 
+    ELSEIF (prefix == '4_') THEN
+       Childname = '5_'//Parentname(pos+3:LEN(Parentname)) 
+    ELSE
+       Childname = '1_'//Parentname(pos+1:LEN(Parentname)) 
+    ENDIF
+    !   
+  END SUBROUTINE set_child_name
+  !
+
+!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!             
+!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
+END MODULE agrif_readwrite
Index: /trunk/UTIL/CFG_TOOLS/agrif_types.f90
===================================================================
--- /trunk/UTIL/CFG_TOOLS/agrif_types.f90	(revision 1799)
+++ /trunk/UTIL/CFG_TOOLS/agrif_types.f90	(revision 1799)
@@ -0,0 +1,274 @@
+!      
+MODULE agrif_types
+  !
+  PUBLIC
+  !   
+  !*****************************
+  ! Coordinates type definition 
+  !*****************************
+  TYPE Coordinates
+     !
+     REAL*8, DIMENSION(:,:), POINTER :: nav_lon,nav_lat => NULL()
+     REAL*8, DIMENSION(:,:), POINTER :: glamv, glamu, glamt, glamf => NULL()
+     REAL*8, DIMENSION(:,:), POINTER :: gphit, gphiu, gphiv, gphif => NULL()
+     REAL*8, DIMENSION(:,:), POINTER :: e1t, e1u, e1v, e1f => NULL()
+     REAL*8, DIMENSION(:,:), POINTER :: e2t, e2u, e2v, e2f => NULL()
+     REAL*8, DIMENSION(:,:), POINTER :: bathy_level => NULL()
+     REAL*8, DIMENSION(:,:), POINTER :: bathy_meter => NULL()
+     REAL*8, DIMENSION(:,:,:),POINTER :: fmask,umask,vmask,tmask => NULL()
+     REAL*8, DIMENSION(:,:,:),POINTER :: e3t_ps,e3w_ps,gdept_ps,gdepwps => NULL()
+     REAL*8, DIMENSION(:,:),POINTER :: gdepw_ps => NULL()
+     REAL*8, DIMENSION(:), POINTER :: gdeptht => NULL()
+     INTEGER, DIMENSION(:) , POINTER :: time_steps => NULL()
+     !     
+  END TYPE Coordinates
+  !
+  !
+  !
+  TYPE mixed_coordinates
+   !
+     REAL*8, DIMENSION(:,:), POINTER :: nav_lon,nav_lat => NULL()
+     REAL*8, DIMENSION(:,:), POINTER :: glam => NULL()
+     REAL*8, DIMENSION(:,:), POINTER :: gphi => NULL()
+     REAL*8, DIMENSION(:,:), POINTER :: e1 => NULL()
+     REAL*8, DIMENSION(:,:), POINTER :: e2 => NULL()
+     REAL*8, DIMENSION(:,:), POINTER :: bathy_level => NULL()
+     REAL*8, DIMENSION(:,:), POINTER :: bathy_meter => NULL()
+     REAL*8, DIMENSION(:,:,:),POINTER :: fmask,umask,vmask,tmask => NULL()
+     REAL*8, DIMENSION(:,:,:),POINTER :: e3t_ps,e3w_ps,gdept_ps,gdepwps => NULL()
+     REAL*8, DIMENSION(:,:),POINTER :: gdepw_ps => NULL()
+     REAL*8, DIMENSION(:), POINTER :: gdeptht => NULL()
+     INTEGER, DIMENSION(:) , POINTER :: time_steps => NULL()
+     !     
+  END TYPE mixed_coordinates
+  !
+  !
+  !
+  CHARACTER*8,DIMENSION(10) :: flxtab = (/'socliot1','socliot2','socliopl',&
+       'socliocl','socliohu','socliowi','soshfldo','sohefldo','sowaflup','sofbt   '/)
+  !
+  !
+  !**************************************************************
+  ! Declaration of various input file variables (namelist.input) 
+  !**************************************************************
+  !
+  INTEGER irafx,irafy
+  INTEGER nxfin,nyfin
+  INTEGER, PARAMETER :: nbghostcellsfine = 2
+  INTEGER, PARAMETER :: nbghostcellscoarse = 1
+  !      
+  INTEGER imin,jmin,imax,jmax,rho,rhot
+  INTEGER shlat
+  INTEGER N,type_bathy_interp
+  ! 
+  INTEGER jpizoom,jpjzoom,nb_connection_pts
+  !      
+  REAL*8 ppacr,ppdzmin,pphmax,ppkth,smoothing_factor,e3zps_min,e3zps_rat
+  REAL*8 psur,pa0,pa1,adatrj
+  !       
+  LOGICAL partial_steps,smoothing,bathy_update
+  LOGICAL new_topo,removeclosedseas,dimg,iom_activated
+  !       
+  CHARACTER*100 parent_bathy_level,elevation_database,parent_bathy_meter
+  CHARACTER*100 parent_coordinate_file,restart_file,updated_parent_file,restart_trc_file
+  CHARACTER*100 dimg_output_file,interp_type
+  !      
+  CHARACTER(len=80),DIMENSION(20) :: flx_Files, u_files, v_files
+  CHARACTER(len=255),DIMENSION(20) :: VAR_INTERP
+  !
+  NAMELIST /input_output/iom_activated
+  !
+  NAMELIST /coarse_grid_files/parent_coordinate_file,parent_bathy_level
+  !      
+  NAMELIST /bathymetry/new_topo,elevation_database,smoothing,smoothing_factor, &
+       nb_connection_pts,removeclosedseas,type_bathy_interp      
+  !      
+  NAMELIST /nesting/imin,imax,jmin,jmax,rho,rhot,bathy_update,updated_parent_file      
+  !
+  NAMELIST /vertical_grid/ppkth,ppacr,ppdzmin,pphmax,psur,pa0,pa1,N
+  ! 
+  NAMELIST /partial_cells/partial_steps,parent_bathy_meter,e3zps_min,e3zps_rat      
+  !
+  NAMELIST /nemo_coarse_grid/ jpizoom,jpjzoom 
+  !          
+  NAMELIST /forcing_files/ flx_files, u_files, v_files 
+  !           
+  NAMELIST /interp/ VAR_INTERP
+  !      
+  NAMELIST /restart/ restart_file,shlat,dimg,dimg_output_file,adatrj,interp_type 
+
+  NAMELIST /restart_trc/ restart_trc_file,interp_type 
+
+  INTEGER :: connectionsize = 3
+  !
+CONTAINS
+  !
+  !********************************************************
+  !subroutine agrif_grid_allocate				*
+  !							*
+  !allocation of grid type elements 			*
+  !      according to nx and ny				*
+  !							*
+  !							*
+  !********************************************************
+  !       
+  SUBROUTINE agrif_grid_allocate(Grid,nx,ny)
+    !
+    TYPE(Coordinates) :: Grid
+    INTEGER :: nx,ny
+    !
+    ALLOCATE(Grid%nav_lon(nx,ny),Grid%nav_lat(nx,ny))
+    !
+    ALLOCATE(Grid%glamt(nx,ny),Grid%glamu(nx,ny),Grid%glamv(nx,ny),Grid%glamf(nx,ny))
+    ALLOCATE(Grid%gphit(nx,ny),Grid%gphiu(nx,ny),Grid%gphiv(nx,ny),Grid%gphif(nx,ny))
+    !
+    ALLOCATE(Grid%e1t(nx,ny),Grid%e1u(nx,ny),Grid%e1v(nx,ny),Grid%e1f(nx,ny))
+    ALLOCATE(Grid%e2t(nx,ny),Grid%e2u(nx,ny),Grid%e2v(nx,ny),Grid%e2f(nx,ny))
+    !
+    ALLOCATE(Grid%bathy_level(nx,ny))
+    !
+  END SUBROUTINE agrif_grid_allocate
+  !
+  !
+  !********************************************************
+  !subroutine mixed_grid_allocate				*
+  !							*
+  !allocation of grid type elements 			*
+  !      according to nx and ny				*
+  !							*
+  !							*
+  !********************************************************
+  !       
+  SUBROUTINE mixed_grid_allocate(Grid,nx,ny)
+    !
+    TYPE(mixed_Coordinates) :: Grid
+    INTEGER :: nx,ny
+    !
+    ALLOCATE(Grid%nav_lon(nx,ny),Grid%nav_lat(nx,ny))
+    !
+    ALLOCATE(Grid%glam(nx,ny))
+    ALLOCATE(Grid%gphi(nx,ny))
+    !
+    ALLOCATE(Grid%e1(nx,ny))
+    ALLOCATE(Grid%e2(nx,ny))
+    !
+    ALLOCATE(Grid%bathy_level(nx,ny))
+    !
+  END SUBROUTINE mixed_grid_allocate
+  !
+  !
+!************************************************************************
+  !									*
+  !   subroutine read_namelist						*
+  !									*
+  !   read variables contained in namelist.input file   			*
+  !   filled in by user 							*
+  !									*
+  !************************************************************************
+  !
+  SUBROUTINE read_namelist(namelistname)
+    !
+    IMPLICIT NONE
+    CHARACTER(len=80) :: namelistname
+    CHARACTER*255 :: output
+    LOGICAL :: is_it_there
+    INTEGER unit_nml
+    !      
+    FLX_FILES = '/NULL'
+    U_FILES = '/NULL'
+    V_FILES = '/NULL'
+    VAR_INTERP = 'NULL'
+    unit_nml = Agrif_Get_Unit()
+    !      
+    INQUIRE ( FILE = namelistname , EXIST = is_it_there )      
+    !
+    IF ( is_it_there ) THEN 
+       !
+       OPEN ( FILE   = namelistname , &
+            UNIT   =  unit_nml        , &
+            STATUS = 'OLD'            , &
+            FORM   = 'FORMATTED'      , &
+            ACTION = 'READ'           , &
+            ACCESS = 'SEQUENTIAL'     )	  
+       !
+       REWIND(unit_nml)
+       READ (unit_nml , NML = input_output)
+       READ (unit_nml , NML = coarse_grid_files)
+       READ (unit_nml , NML = bathymetry)	  
+       READ (unit_nml , NML = nesting) 
+       READ (unit_nml , NML = vertical_grid)
+       READ (unit_nml , NML = partial_cells)                    
+       READ (unit_nml , NML = nemo_coarse_grid ) 
+      ! READ (unit_nml , NML = forcing_files )  
+       READ (unit_nml , NML = interp )   
+       READ (unit_nml , NML = restart )
+       READ (unit_nml , NML = restart_trc )
+       CLOSE(unit_nml)
+       !	
+       irafx = rho
+       irafy = rho
+       imin = imin + jpizoom - 1
+       imax = imax + jpizoom - 1
+       jmin = jmin + jpjzoom - 1
+       jmax = jmax + jpjzoom - 1
+       !
+       !nxfin = (imax-imin)*irafx+nbghostcellsfine*2
+       !nyfin = (jmax-jmin)*irafy+nbghostcellsfine*2
+	   !IF(imin>imax) THEN
+	   !   nxfin = (722-imin+imax-1)*rho + NINT(1-(1./rho))
+	   !ELSE
+	   !   nxfin = (imax-imin+1)*rho + 1
+       !ENDIF
+	   !	  nyfin = (jmax-jmin+1)*rho + 1
+	   !
+    ELSE
+       !
+       PRINT *,'namelist file ''',TRIM(namelistname),''' not found'
+       STOP	 
+       !
+    END IF
+    !
+    !
+  END SUBROUTINE read_namelist
+
+  INTEGER FUNCTION agrif_int(x)
+
+    REAL :: x
+    INTEGER ::i
+
+    i = FLOOR(x) + 1
+
+    IF( ABS(x - i).LE.0.0001 )THEN
+       agrif_int = i
+    ELSE
+       agrif_int = i-1
+    ENDIF
+
+  END FUNCTION agrif_int
+  !
+  !*************************************************
+  !   function Agrif_Get_Unit                             
+  !*************************************************
+  !
+
+  INTEGER FUNCTION Agrif_Get_Unit()
+    !
+    INTEGER n
+    LOGICAL op
+    INTEGER :: nunit
+    INTEGER :: iii,out,iiimax 
+    ! 
+    DO n = 7,1000
+       ! 
+       INQUIRE(Unit=n,Opened=op)
+       !
+       IF (.NOT.op) EXIT
+       !      
+    ENDDO
+    !
+    Agrif_Get_Unit=n
+    !
+    !
+  END FUNCTION Agrif_Get_Unit
+  !
+END MODULE agrif_types
Index: /trunk/UTIL/CFG_TOOLS/cfg_tools.f90
===================================================================
--- /trunk/UTIL/CFG_TOOLS/cfg_tools.f90	(revision 1799)
+++ /trunk/UTIL/CFG_TOOLS/cfg_tools.f90	(revision 1799)
@@ -0,0 +1,1027 @@
+MODULE tools_brice
+!-----------------------------------------------------------
+!
+!   to make it we use a 4th order polynomial interpolation
+!
+!	        Created by Brice Lemaire on 12/2009.
+!
+!-----------------------------------------------------------
+USE agrif_types
+  !
+  IMPLICIT NONE
+     PUBLIC
+	 !
+     INTEGER :: nxGmix, nyGmix
+     INTEGER :: nxG1, nyG1, nxG2, nyG2, nxG3, nyG3, nxG4, nyG4
+	 INTEGER :: nxG1mix, nyG1mix
+	 INTEGER :: nxG2mix, nyG2mix
+	 INTEGER :: nxG3mix, nyG3mix
+	 INTEGER :: nxG4mix, nyG4mix
+	 INTEGER :: nx_fine, ny_fine, nx_coarse, ny_coarse
+	 INTEGER :: i, j, i_min, j_min
+	 INTEGER :: k, m
+	 !
+	 PUBLIC mixed_grid
+	 PRIVATE mixed_G1, mixed_G2, mixed_G4
+	 !
+	 INTERFACE mixed_grid
+		MODULE PROCEDURE mixed_G1, mixed_G2, mixed_G4
+	 END INTERFACE
+	 !
+   CONTAINS
+     !
+     !********************************************************
+     !              SUBROUTINE mixed grid 				    *
+     !									        			*
+     !	  mix from four grids (U,V,F,T) to one grid			*
+     !												        *
+     !		   CALLED from create_coordinates.f90	        *
+     !********************************************************
+     !    
+	 SUBROUTINE mixed_G1(G1,Gmix)
+	  !
+	 TYPE(Coordinates), INTENT(IN) :: G1
+	 TYPE(mixed_coordinates), INTENT(INOUT) :: Gmix
+     !
+	 WRITE(*,*) ''
+	 WRITE(*,*) '*** ROUTINE mixed_G1 ***'
+	 WRITE(*,*) ''
+	 !
+	 nxG1 = (imax+1) - (imin-1) + 1   !(+1) rajout de 2 bandes fantmes
+	 nyG1 = (jmax+1) - (jmin-1) + 1
+	 !
+     WRITE(*,*) ''
+     WRITE(*,*) '*** CHECKING SIZE OF INPUT GRID***'
+     WRITE(*,*) nxG1, 'x', nyG1
+     WRITE(*,*) ''
+	 !
+	 nx_coarse = nxG1
+	 ny_coarse = nyG1
+	 !
+	 !!!Calculate size of mixed grid (nx x ny)
+	 nxGmix = (nx_coarse) * 2                       !nbre de pts connus (T,U,V,F) suivant x
+	 nxGmix = nxGmix + (rho-1)*(nxGmix-1)             !nbre de points  interpoler
+     ! 
+	 nyGmix = (ny_coarse) * 2                       !nbre de pts connus (T,U,V,F) suivant y
+	 nyGmix = nyGmix + (rho-1)*(nyGmix-1)             !nbre de points  interpoler
+     ! 
+	 WRITE(*,*) ''
+	 WRITE(*,*) '*** SIZE OF MIXED GRID ***'
+	 WRITE(*,*) nxGmix, ' x ', nyGmix
+	 WRITE(*,*) ''
+	 !
+	 nx_fine = (nx_coarse-2)*rho + 1
+	 ny_fine = (ny_coarse-2)*rho + 1
+	 !
+	 WRITE(*,*) ''
+	 WRITE(*,*) '*** SIZE OF FINE GRID ***'
+	 WRITE(*,*) nx_fine, ' x ', ny_fine
+	 WRITE(*,*) ''
+	 !
+	 !!!Allocate mixed grid
+     CALL mixed_grid_allocate(Gmix,nxGmix,nyGmix)      !from agrif_types
+     !
+	 !!!Calculate part of each grid to make Gmix
+	 nxG1mix = nxGmix                        
+	 nyG1mix = nyGmix                          
+	 !
+	 !***On rcupre les pts depuis G1
+   j_min = jmin-1
+   DO j=1,nyG1mix,(2*rho)
+   	  i_min = imin-1
+      DO i=1,nxG1mix,(2*rho)
+	     Gmix%nav_lon(i,j)      =  G1%nav_lon(i_min,j_min)
+         Gmix%nav_lat(i+rho,j)  =  G1%nav_lat(i_min,j_min)	    
+		 !
+         Gmix%glam(i,j)         =  G1%glamt(i_min,j_min)
+         Gmix%glam(i+rho,j)     =  G1%glamu(i_min,j_min)
+		 Gmix%glam(i,j+rho)     =  G1%glamv(i_min,j_min)
+	     Gmix%glam(i+rho,j+rho) =  G1%glamf(i_min,j_min)		    
+		 !
+         Gmix%gphi(i,j)         =  G1%gphit(i_min,j_min)
+         Gmix%gphi(i+rho,j)     =  G1%gphiu(i_min,j_min)		 
+		 Gmix%gphi(i,j+rho)     =  G1%gphiv(i_min,j_min)
+	     Gmix%gphi(i+rho,j+rho) =  G1%gphif(i_min,j_min)
+		 !
+		 Gmix%e1(i,j)         =  G1%e1t(i_min,j_min)
+         Gmix%e1(i+rho,j)     =  G1%e1u(i_min,j_min)		 
+		 Gmix%e1(i,j+rho)     =  G1%e1v(i_min,j_min)
+	     Gmix%e1(i+rho,j+rho) =  G1%e1f(i_min,j_min)	
+		 !	
+		 Gmix%e2(i,j)         =  G1%e2t(i_min,j_min)
+         Gmix%e2(i+rho,j)     =  G1%e2u(i_min,j_min)		 
+		 Gmix%e2(i,j+rho)     =  G1%e2v(i_min,j_min)
+	     Gmix%e2(i+rho,j+rho) =  G1%e2f(i_min,j_min) 
+		 !
+		 i_min = i_min+1	
+	  ENDDO
+	  j_min = j_min+1	
+   ENDDO
+   !
+!print*, 'Gmix%nav_lat= '
+!DO j=1,nyG1mix
+!print*, Gmix%nav_lat(:,j)
+!END DO  
+   !
+print*, 'G1%glamt= '
+DO j=jmin-1,jmax+1
+print*, G1%glamt(imin-1:imax+1,j)
+ENDDO
+print*,''
+print*, 'G1%glamu= '
+DO j=jmin-1,jmax+1
+print*, G1%glamu(imin-1:imax+1,j)
+ENDDO
+print*,''
+print*, 'Gmix%glam= '
+DO j=1,nyGmix
+print*, Gmix%glam(:,j)
+ENDDO
+     !
+	 END SUBROUTINE
+	 !	  
+	 !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
+	 !
+	 SUBROUTINE mixed_G2(G1,G2,Gmix)
+	  !
+	 TYPE(Coordinates), INTENT(IN) :: G1,G2
+	 TYPE(mixed_coordinates), INTENT(INOUT) :: Gmix
+	 !
+	 WRITE(*,*) ''
+	 WRITE(*,*) '*** ROUTINE mixed_G2 ***'
+	 WRITE(*,*) ''
+	 !
+     !
+	 nxG1 = SIZE(G1%glamt,1) - (imin-1) + 1   !(+1) rajout d'une bande fantme
+	 nyG1 = (jmax+1) - (jmin-1) + 1
+	 print*, nxG1, nyG1
+	 !
+	 nxG2 = (imax+1) - 2      !(-2) on supprime les bandes de chevauchement
+     nyG2 = nyG1
+	 print*, nxG2, nyG2
+	 !
+	 nx_coarse = nxG1+nxG2 
+	 ny_coarse = nyG1 
+	 !
+	 !!!Calculate size of mixed grid (nx x ny)
+	 nxGmix = (nx_coarse) * 2       !nbre de pts connus (T,U,V,F) suivant x
+	 nxGmix = nxGmix + (rho-1)*(nxGmix-1)             !nbre de points  interpoler
+     ! 
+	 nyGmix = (ny_coarse) * 2       !nbre de pts connus (T,U,V,F) suivant y
+	 nyGmix = nyGmix + (rho-1)*(nyGmix-1)             !nbre de points  interpoler
+     ! 
+	 WRITE(*,*) '*** SIZE OF MIXED GRID ***'
+	 WRITE(*,*) nxGmix, ' x ', nyGmix
+	 WRITE(*,*) ''
+	 !
+	 !nx_fine = (nxG1-1 + nxG2-1)*rho + 1   !(-1) on supprime les 2 bandes fantmes
+	 !ny_fine = (nyG1-1)*rho + 1	
+	 
+	 nx_fine = (nx_coarse-2)*rho + 1
+	 ny_fine = (ny_coarse-2)*rho + 1
+	 !
+	 WRITE(*,*) '*** SIZE OF FINE GRID ***'
+	 WRITE(*,*) nx_fine, ' x ', ny_fine
+	 WRITE(*,*) ''
+	 !
+	 !!!Allocate mixed grid
+     CALL mixed_grid_allocate(Gmix,nxGmix,nyGmix)      !from agrif_types
+     !
+	 !!!Calculate part of each grid to make Gmix
+	 nxG1mix = nxG1  * 2                                !nbre de pts connus (T,U,V,F) suivant x
+	 nxG1mix = nxG1mix + (rho-1)*(nxG1mix-1)            !nbre de points  interpoler
+     !    
+	 nyG1mix = nyG1  * 2                                !nbre de pts connus (T,U,V,F) suivant x
+	 nyG1mix = nyG1mix + (rho-1)*(nyG1mix-1)            !nbre de points  interpoler
+     print*,'nxG1mix= ', nxG1mix, 'nyG1mix= ', nyG1mix
+	 !
+	 nxG2mix = nxG2  * 2                                !nbre de pts connus (T,U,V,F) suivant x
+	 nxG2mix = nxG2mix + (rho-1)*(nxG2mix-1) + 1        !nbre de points  interpoler
+    ! 
+	 nyG2mix = nyG2  * 2                                !nbre de pts connus (T,U,V,F) suivant x
+	 nyG2mix = nyG2mix + (rho-1)*(nyG2mix-1)            !nbre de points  interpoler
+	 print*,'nxG2mix= ', nxG2mix, 'nyG2mix= ', nyG2mix     
+	 !
+	 IF((nxG1mix+nxG2mix).NE.nxGmix) THEN
+        WRITE(*,*) ''
+		WRITE(*,*) '*** ERROR ***'
+		WRITE(*,*) 'nxG1mix + nxG2mix /= nxGmix'
+	    WRITE(*,*) nxG1mix + nxG2mix, ' /= ', nxGmix
+	    WRITE(*,*) ''
+	 ENDIF	
+	 !
+   !*** On rcupre les pts depuis G1
+   j_min = jmin-1
+   DO j=1,nyG1mix,(2*rho)
+   	  i_min = imin-1
+      DO i=1,nxG1mix,(2*rho)
+	     Gmix%nav_lon(i,j)      =  G1%nav_lon(i_min,j_min)
+         Gmix%nav_lat(i+rho,j)  =  G1%nav_lat(i_min,j_min)	    
+		 !
+         Gmix%glam(i,j)         =  G1%glamt(i_min,j_min)
+         Gmix%glam(i+rho,j)     =  G1%glamu(i_min,j_min)
+		 Gmix%glam(i,j+rho)     =  G1%glamv(i_min,j_min)
+	     Gmix%glam(i+rho,j+rho) =  G1%glamf(i_min,j_min)		    
+		 !
+         Gmix%gphi(i,j)         =  G1%gphit(i_min,j_min)
+         Gmix%gphi(i+rho,j)     =  G1%gphiu(i_min,j_min)		 
+		 Gmix%gphi(i,j+rho)     =  G1%gphiv(i_min,j_min)
+	     Gmix%gphi(i+rho,j+rho) =  G1%gphif(i_min,j_min)
+		 !
+		 Gmix%e1(i,j)         =  G1%e1t(i_min,j_min)
+         Gmix%e1(i+rho,j)     =  G1%e1u(i_min,j_min)		 
+		 Gmix%e1(i,j+rho)     =  G1%e1v(i_min,j_min)
+	     Gmix%e1(i+rho,j+rho) =  G1%e1f(i_min,j_min)	
+		 !	
+		 Gmix%e2(i,j)         =  G1%e2t(i_min,j_min)
+         Gmix%e2(i+rho,j)     =  G1%e2u(i_min,j_min)		 
+		 Gmix%e2(i,j+rho)     =  G1%e2v(i_min,j_min)
+	     Gmix%e2(i+rho,j+rho) =  G1%e2f(i_min,j_min) 
+		 !
+		 i_min = i_min+1	
+	  ENDDO
+	  j_min = j_min+1	
+   ENDDO
+   !
+   !***On rcupre les pts depuis G2
+   j_min = jmin - 1
+   DO j=1,nyG2mix,(2*rho)      
+	  i_min = 3
+      DO k=i,nxGmix,(2*rho)
+	  print*, k       
+	     Gmix%nav_lon(k,j)      =  G2%nav_lon(i_min,j_min)
+         Gmix%nav_lat(k+rho,j)  =  G2%nav_lat(i_min,j_min)	    
+		 !
+         Gmix%glam(k,j)         =  G2%glamt(i_min,j_min)
+         Gmix%glam(k+rho,j)     =  G2%glamu(i_min,j_min)
+		 Gmix%glam(k,j+rho)     =  G2%glamv(i_min,j_min)
+	     Gmix%glam(k+rho,j+rho) =  G2%glamf(i_min,j_min)		    
+		 !
+         Gmix%gphi(k,j)         =  G2%gphit(i_min,j_min)
+         Gmix%gphi(k+rho,j)     =  G2%gphiu(i_min,j_min)		 
+		 Gmix%gphi(k,j+rho)     =  G2%gphiv(i_min,j_min)
+	     Gmix%gphi(k+rho,j+rho) =  G2%gphif(i_min,j_min)
+		 !
+		 Gmix%e1(k,j)         =  G2%e1t(i_min,j_min)
+         Gmix%e1(k+rho,j)     =  G2%e1u(i_min,j_min)		 
+		 Gmix%e1(k,j+rho)     =  G2%e1v(i_min,j_min)
+	     Gmix%e1(k+rho,j+rho) =  G2%e1f(i_min,j_min)	
+		 !	
+		 Gmix%e2(k,j)         =  G2%e2t(i_min,j_min)
+         Gmix%e2(k+rho,j)     =  G2%e2u(i_min,j_min)		 
+		 Gmix%e2(k,j+rho)     =  G2%e2v(i_min,j_min)
+	     Gmix%e2(k+rho,j+rho) =  G2%e2f(i_min,j_min) 
+		 !
+		 i_min = i_min+1	
+	  ENDDO
+	  j_min = j_min+1	
+   ENDDO
+     !
+print*, 'G1%glamt= '
+DO j=jmin-1,jmax+1
+print*, G1%glamt(imin-1:SIZE(G1%glamt,1),j)
+ENDDO
+print*,''
+print*, 'G1%glamu= '
+DO j=jmin-1,jmax+1
+print*, G1%glamu(imin-1:SIZE(G1%glamu,1),j)
+ENDDO
+print*,''
+print*, 'Gmix%glam= '
+DO j=1,nyGmix
+print*, Gmix%glam(:,j)
+ENDDO
+
+	 END SUBROUTINE
+	 !
+	 !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
+	 !
+	 SUBROUTINE mixed_G3(G1,G3,Gmix)
+	  !
+	 TYPE(Coordinates), INTENT(IN) :: G1,G2,G3
+	 TYPE(mixed_coordinates), INTENT(INOUT) :: Gmix
+	 !
+	 WRITE(*,*) ''
+	 WRITE(*,*) '*** ROUTINE mixed_G3 ***'
+	 WRITE(*,*) ''
+	 !
+     !
+	 nxG1 = (imax+1) - (imin-1) + 1				  !(+1) rajout de 2 bandes fantmes
+	 nyG1 = SIZE(G1%glamt,2) - (jmin-1) + 1
+	 print*, nxG1, nyG1
+     !
+     nxG3 = nxG1  
+     nyG3 = SIZE(G3%glamt,2) - (jmax-1) + 1 - 2   !(-2) on supprime les bandes de chevauchement
+	 print*, nxG3, nyG3
+	 !
+	 nx_coarse = nxG1 
+	 ny_coarse = nyG1 + nyG3
+	 !
+	 !!!Calculate size of mixed grid (nx x ny)
+	 nxGmix = (nx_coarse) * 2       !nbre de pts connus (T,U,V,F) suivant x
+	 nxGmix = nxGmix + (rho-1)*(nxGmix-1)             !nbre de points  interpoler
+     ! 
+	 nyGmix = (ny_coarse) * 2       !nbre de pts connus (T,U,V,F) suivant y
+	 nyGmix = nyGmix + (rho-1)*(nyGmix-1)             !nbre de points  interpoler
+     ! 
+	 WRITE(*,*) '*** SIZE OF MIXED GRID ***'
+	 WRITE(*,*) nxGmix, ' x ', nyGmix
+	 WRITE(*,*) ''
+	 !
+	 !nx_fine = (nxGmix/2) - 1
+	 !ny_fine = (nyGmix/2) - 1
+	 nx_fine = (nx_coarse-2)*rho + 1
+	 ny_fine = (ny_coarse-2)*rho + 1
+	
+	 !
+	 WRITE(*,*) '*** SIZE OF FINE GRID ***'
+	 WRITE(*,*) nx_fine, ' x ', ny_fine
+	 WRITE(*,*) ''
+	 !
+	 !!!Allocate mixed grid
+     CALL mixed_grid_allocate(Gmix,nxGmix,nyGmix)      !from agrif_types
+     !
+	 !!!Calculate part of each grid to make Gmix
+	 nxG1mix = nxG1  * 2                           !nbre de pts connus (T,U,V,F) suivant x
+	 nxG1mix = nxG1mix + (rho-1)*(nxG1mix-1)        !nbre de points  interpoler
+     ! 
+	 nyG1mix = nyG1  * 2                           !nbre de pts connus (T,U,V,F) suivant x
+	 nyG1mix = nyG1mix + (rho-1)*(nyG1mix-1)        !nbre de points  interpoler
+     print*,'nxG1mix= ', nxG1mix, 'nyG1mix= ', nyG1mix
+	 !
+	 nxG2mix = nxG2  * 2                           !nbre de pts connus (T,U,V,F) suivant x
+	 nxG2mix = nxG2mix + (rho-1)*(nxG2mix-1)        !nbre de points  interpoler
+    ! 
+	 nyG2mix = nyG2  * 2                           !nbre de pts connus (T,U,V,F) suivant x
+	 nyG2mix = nyG2mix + (rho-1)*(nyG2mix-1)        !nbre de points  interpoler
+	 print*,'nxG2mix= ', nxG2mix, 'nyG2mix= ', nyG2mix     
+	 !
+	 nxG3mix = nxG3  * 2                           !nbre de pts connus (T,U,V,F) suivant x
+	 nxG3mix = nxG3mix + (rho-1)*(nxG3mix-1)        !nbre de points  interpoler
+     ! 
+	 nyG3mix = nyG3  * 2                           !nbre de pts connus (T,U,V,F) suivant x
+	 nyG3mix = nyG3mix + (rho-1)*(nyG3mix-1)        !nbre de points  interpoler
+	 print*,'nxG3mix= ', nxG3mix, 'nyG3mix= ', nyG3mix          
+	 !
+	 nxG4mix = nxG4  * 2                           !nbre de pts connus (T,U,V,F) suivant x
+	 nxG4mix = nxG4mix + (rho-1)*(nxG4mix-1)        !nbre de points  interpoler
+     ! 
+	 nyG4mix = nyG4  * 2                           !nbre de pts connus (T,U,V,F) suivant x
+	 nyG4mix = nyG4mix + (rho-1)*(nyG4mix-1)        !nbre de points  interpoler
+ 	 print*,'nxG4mix= ', nxG4mix, 'nyG4mix= ', nyG4mix         
+	 !
+
+   !***On rcupre les pts depuis G1
+   j_min = jmin-1
+   DO j=1,nyG1mix,(2*rho)
+   	  i_min = imin-1
+      DO i=1,nxG1mix,(2*rho)
+	     Gmix%nav_lon(i,j)      =  G1%nav_lon(i_min,j_min)
+         Gmix%nav_lat(i+rho,j)  =  G1%nav_lat(i_min,j_min)	    
+		 !
+         Gmix%glam(i,j)         =  G1%glamt(i_min,j_min)
+         Gmix%glam(i+rho,j)     =  G1%glamu(i_min,j_min)
+		 Gmix%glam(i,j+rho)     =  G1%glamv(i_min,j_min)
+	     Gmix%glam(i+rho,j+rho) =  G1%glamf(i_min,j_min)		    
+		 !
+         Gmix%gphi(i,j)         =  G1%gphit(i_min,j_min)
+         Gmix%gphi(i+rho,j)     =  G1%gphiu(i_min,j_min)		 
+		 Gmix%gphi(i,j+rho)     =  G1%gphiv(i_min,j_min)
+	     Gmix%gphi(i+rho,j+rho) =  G1%gphif(i_min,j_min)
+		 !
+		 Gmix%e1(i,j)         =  G1%e1t(i_min,j_min)
+         Gmix%e1(i+rho,j)     =  G1%e1u(i_min,j_min)		 
+		 Gmix%e1(i,j+rho)     =  G1%e1v(i_min,j_min)
+	     Gmix%e1(i+rho,j+rho) =  G1%e1f(i_min,j_min)	
+		 !	
+		 Gmix%e2(i,j)         =  G1%e2t(i_min,j_min)
+         Gmix%e2(i+rho,j)     =  G1%e2u(i_min,j_min)		 
+		 Gmix%e2(i,j+rho)     =  G1%e2v(i_min,j_min)
+	     Gmix%e2(i+rho,j+rho) =  G1%e2f(i_min,j_min) 
+		 !
+		 i_min = i_min+1	
+	  ENDDO
+	  j_min = j_min+1	
+   ENDDO
+   !
+   !***On rcupre les pts depuis G2
+   j_min = jmin - 1
+   DO j=1,nyG2mix,(2*rho)      
+	  i_min = 3
+      DO k=i,nxGmix,(2*rho)       
+	     Gmix%nav_lon(k,j)      =  G2%nav_lon(i_min,j_min)
+         Gmix%nav_lat(k+rho,j)  =  G2%nav_lat(i_min,j_min)	    
+		 !
+         Gmix%glam(k,j)         =  G2%glamt(i_min,j_min)
+         Gmix%glam(k+rho,j)     =  G2%glamu(i_min,j_min)
+		 Gmix%glam(k,j+rho)     =  G2%glamv(i_min,j_min)
+	     Gmix%glam(k+rho,j+rho) =  G2%glamf(i_min,j_min)		    
+		 !
+         Gmix%gphi(k,j)         =  G2%gphit(i_min,j_min)
+         Gmix%gphi(k+rho,j)     =  G2%gphiu(i_min,j_min)		 
+		 Gmix%gphi(k,j+rho)     =  G2%gphiv(i_min,j_min)
+	     Gmix%gphi(k+rho,j+rho) =  G2%gphif(i_min,j_min)
+		 !
+		 Gmix%e1(k,j)         =  G2%e1t(i_min,j_min)
+         Gmix%e1(k+rho,j)     =  G2%e1u(i_min,j_min)		 
+		 Gmix%e1(k,j+rho)     =  G2%e1v(i_min,j_min)
+	     Gmix%e1(k+rho,j+rho) =  G2%e1f(i_min,j_min)	
+		 !	
+		 Gmix%e2(k,j)         =  G2%e2t(i_min,j_min)
+         Gmix%e2(k+rho,j)     =  G2%e2u(i_min,j_min)		 
+		 Gmix%e2(k,j+rho)     =  G2%e2v(i_min,j_min)
+	     Gmix%e2(k+rho,j+rho) =  G2%e2f(i_min,j_min) 
+		 !
+		 i_min = i_min+1	
+	  ENDDO
+	  j_min = j_min+1	
+   ENDDO
+   !
+   !**On rcupre les pts depuis G3
+   j_min = SIZE(G3%glamt,2)-2      !on supprime les bandes de chevauchement
+   DO m=j,nyGmix,(2*rho)
+   	  i_min = imin + imax
+      DO i=1,nxG3mix,(2*rho)
+	     Gmix%nav_lon(i,m)      =  G3%nav_lon(i_min,j_min)
+         Gmix%nav_lat(i+rho,m)  =  G3%nav_lat(i_min,j_min)	    
+		 !
+         Gmix%glam(i,m)         =  G3%glamt(i_min,j_min)
+         Gmix%glam(i+rho,m)     =  G3%glamu(i_min,j_min)
+		 Gmix%glam(i,m+rho)     =  G3%glamv(i_min,j_min)
+	     Gmix%glam(i+rho,m+rho) =  G3%glamf(i_min,j_min)		    
+		 !
+         Gmix%gphi(i,m)         =  G3%gphit(i_min,j_min)
+         Gmix%gphi(i+rho,m)     =  G3%gphiu(i_min,j_min)		 
+		 Gmix%gphi(i,m+rho)     =  G3%gphiv(i_min,j_min)
+	     Gmix%gphi(i+rho,m+rho) =  G3%gphif(i_min,j_min)
+		 !
+		 Gmix%e1(i,m)         =  G3%e1t(i_min,j_min)
+         Gmix%e1(i+rho,m)     =  G3%e1u(i_min,j_min)		 
+		 Gmix%e1(i,m+rho)     =  G3%e1v(i_min,j_min)
+	     Gmix%e1(i+rho,m+rho) =  G3%e1f(i_min,j_min)	
+		 !	
+		 Gmix%e2(i,m)         =  G3%e2t(i_min,j_min)
+         Gmix%e2(i+rho,m)     =  G3%e2u(i_min,j_min)		 
+		 Gmix%e2(i,m+rho)     =  G3%e2v(i_min,j_min)
+	     Gmix%e2(i+rho,m+rho) =  G3%e2f(i_min,j_min) 
+		 !
+		 i_min = i_min - 1      !on se dplace le long de (-i)	
+	  ENDDO
+	  j_min = j_min - 1         !on se dplace le long de (-j)	
+   ENDDO
+   !   
+   !**On rcupre les pts depuis G4
+   j_min =  SIZE(G4%glamt,2)-2     !on supprime les bandes de chevauchement
+   DO m=j,nyGmix,(2*rho)
+   	  i_min = SIZE(G4%glamt,1)-2
+      DO k=i,nxGmix,(2*rho)
+	     Gmix%nav_lon(k,m)      =  G4%nav_lon(i_min,j_min)
+         Gmix%nav_lat(k+rho,m)  =  G4%nav_lat(i_min,j_min)	    
+		 !
+         Gmix%glam(k,m)         =  G4%glamt(i_min,j_min)
+         Gmix%glam(k+rho,m)     =  G4%glamu(i_min,j_min)
+		 Gmix%glam(k,m+rho)     =  G4%glamv(i_min,j_min)
+	     Gmix%glam(k+rho,m+rho) =  G4%glamf(i_min,j_min)		    
+		 !
+         Gmix%gphi(k,m)         =  G4%gphit(i_min,j_min)
+         Gmix%gphi(k+rho,m)     =  G4%gphiu(i_min,j_min)		 
+		 Gmix%gphi(k,m+rho)     =  G4%gphiv(i_min,j_min)
+	     Gmix%gphi(k+rho,m+rho) =  G4%gphif(i_min,j_min)
+		 !
+		 Gmix%e1(k,m)         =  G4%e1t(i_min,j_min)
+         Gmix%e1(k+rho,m)     =  G4%e1u(i_min,j_min)		 
+		 Gmix%e1(k,m+rho)     =  G4%e1v(i_min,j_min)
+	     Gmix%e1(k+rho,m+rho) =  G4%e1f(i_min,j_min)	
+		 !	
+		 Gmix%e2(k,m)         =  G4%e2t(i_min,j_min)
+         Gmix%e2(k+rho,m)     =  G4%e2u(i_min,j_min)		 
+		 Gmix%e2(k,m+rho)     =  G4%e2v(i_min,j_min)
+	     Gmix%e2(k+rho,m+rho) =  G4%e2f(i_min,j_min) 
+		 !
+		 i_min = i_min - 1      !on se dplace le long de (-i)	
+	  ENDDO
+	  j_min = j_min - 1         !on se dplace le long de (-j)	
+   ENDDO
+   !
+print*, 'G1%glamt= '
+DO j=jmin-1,SIZE(G1%glamt,2)
+print*, G1%glamt(imin-1:SIZE(G1%glamt,1),j)
+ENDDO
+print*,''
+print*, 'G1%glamu= '
+DO j=jmin-1,SIZE(G1%glamu,2)
+print*, G1%glamu(imin-1:SIZE(G1%glamu,1),j)
+ENDDO
+print*,''
+print*, 'Gmix%glam= '
+DO j=1,nyGmix
+print*, Gmix%glam(:,j)
+ENDDO
+
+	 END SUBROUTINE
+	 !
+	 !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
+	 ! 
+     SUBROUTINE mixed_G4(G1,G2,G3,G4,Gmix)
+	 !
+	 TYPE(Coordinates), INTENT(IN) :: G1,G2,G3,G4
+	 TYPE(mixed_coordinates), INTENT(INOUT) :: Gmix
+	 !
+	 WRITE(*,*) ''
+	 WRITE(*,*) '*** ROUTINE mixed_G4 ***'
+	 WRITE(*,*) ''
+	 !
+     !
+	 nxG1 = SIZE(G1%glamt,1) - (imin-1) + 1   !(+1) rajout d'une bande fantme
+	 nyG1 = SIZE(G1%glamt,2) - (jmin-1) + 1
+	 print*, nxG1, nyG1
+	 !
+	 nxG2 = imax + 1 - 2      !(-2) on supprime les bandes de chevauchement
+     nyG2 = SIZE(G2%glamt,2) - (jmin-1) + 1
+	 print*, nxG2, nyG2
+     !
+     nxG3 = SIZE(G3%glamt,1) - (imin-1) + 1  
+     nyG3 = SIZE(G3%glamt,2) - (jmax-1) + 1 - 2   !(-2) on supprime les bandes de chevauchement
+	 print*, nxG3, nyG3
+	 !
+     nxG4 = imax + 1 - 2      !(-2) on supprime les bandes de chevauchement
+     nyG4 = SIZE(G4%glamt,2) - (jmax-1) + 1 - 2   !(-2) on supprime les bandes de chevauchement
+     print*, nxG4, nyG4
+	 !
+     WRITE(*,*) ''
+     WRITE(*,*) '*** CHECKING SIZE OF THE MIXED GRID***'
+     WRITE(*,*) ' nxG1 + nxG2 = nxG3 + nxG4 = nx_coarse'
+     WRITE(*,*) nxG1 + nxG2, ' = ', nxG3 + nxG4 
+     WRITE(*,*) ''
+	 WRITE(*,*) ' nyG1 + nyG3 = nyG2 + nyG4 = ny_coarse'
+     WRITE(*,*) nyG1 + nyG3, ' = ', nyG2 + nyG4 
+     WRITE(*,*) ''
+	 !
+	 nx_coarse = nxG1 + nxG2
+	 ny_coarse = nyG1 + nyG3
+	 !
+	 !!!Calculate size of mixed grid (nx x ny)
+	 nxGmix = (nxG1  + nxG2) * 2       !nbre de pts connus (T,U,V,F) suivant x
+	 nxGmix = nxGmix + (rho-1)*(nxGmix-1)             !nbre de points  interpoler
+     ! 
+	 nyGmix = (nyG1 + nyG3) * 2       !nbre de pts connus (T,U,V,F) suivant y
+	 nyGmix = nyGmix + (rho-1)*(nyGmix-1)             !nbre de points  interpoler
+     ! 
+	 WRITE(*,*) '*** SIZE OF MIXED GRID ***'
+	 WRITE(*,*) nxGmix, ' x ', nyGmix
+	 WRITE(*,*) ''
+	 !
+	 !nx_fine = (nxGmix/2) - 1
+	 !ny_fine = (nyGmix/2) - 1
+	 nx_fine = (nx_coarse-2)*rho + 1
+	 ny_fine = (ny_coarse-2)*rho + 1
+	
+	 !
+	 WRITE(*,*) '*** SIZE OF FINE GRID ***'
+	 WRITE(*,*) nx_fine, ' x ', ny_fine
+	 WRITE(*,*) ''
+	 !
+	 !!!Allocate mixed grid
+     CALL mixed_grid_allocate(Gmix,nxGmix,nyGmix)      !from agrif_types
+     !
+	 !!!Calculate part of each grid to make Gmix
+	 nxG1mix = nxG1  * 2                           !nbre de pts connus (T,U,V,F) suivant x
+	 nxG1mix = nxG1mix + (rho-1)*(nxG1mix-1)        !nbre de points  interpoler
+     ! 
+	 nyG1mix = nyG1  * 2                           !nbre de pts connus (T,U,V,F) suivant x
+	 nyG1mix = nyG1mix + (rho-1)*(nyG1mix-1)        !nbre de points  interpoler
+     print*,'nxG1mix= ', nxG1mix, 'nyG1mix= ', nyG1mix
+	 !
+	 nxG2mix = nxG2  * 2                           !nbre de pts connus (T,U,V,F) suivant x
+	 nxG2mix = nxG2mix + (rho-1)*(nxG2mix-1)        !nbre de points  interpoler
+    ! 
+	 nyG2mix = nyG2  * 2                           !nbre de pts connus (T,U,V,F) suivant x
+	 nyG2mix = nyG2mix + (rho-1)*(nyG2mix-1)        !nbre de points  interpoler
+	 print*,'nxG2mix= ', nxG2mix, 'nyG2mix= ', nyG2mix     
+	 !
+	 nxG3mix = nxG3  * 2                           !nbre de pts connus (T,U,V,F) suivant x
+	 nxG3mix = nxG3mix + (rho-1)*(nxG3mix-1)        !nbre de points  interpoler
+     ! 
+	 nyG3mix = nyG3  * 2                           !nbre de pts connus (T,U,V,F) suivant x
+	 nyG3mix = nyG3mix + (rho-1)*(nyG3mix-1)        !nbre de points  interpoler
+	 print*,'nxG3mix= ', nxG3mix, 'nyG3mix= ', nyG3mix          
+	 !
+	 nxG4mix = nxG4  * 2                           !nbre de pts connus (T,U,V,F) suivant x
+	 nxG4mix = nxG4mix + (rho-1)*(nxG4mix-1)        !nbre de points  interpoler
+     ! 
+	 nyG4mix = nyG4  * 2                           !nbre de pts connus (T,U,V,F) suivant x
+	 nyG4mix = nyG4mix + (rho-1)*(nyG4mix-1)        !nbre de points  interpoler
+ 	 print*,'nxG4mix= ', nxG4mix, 'nyG4mix= ', nyG4mix         
+	 !
+
+   !***On rcupre les pts depuis G1
+   j_min = jmin-1
+   DO j=1,nyG1mix,(2*rho)
+   	  i_min = imin-1
+      DO i=1,nxG1mix,(2*rho)
+	     Gmix%nav_lon(i,j)      =  G1%nav_lon(i_min,j_min)
+         Gmix%nav_lat(i+rho,j)  =  G1%nav_lat(i_min,j_min)	    
+		 !
+         Gmix%glam(i,j)         =  G1%glamt(i_min,j_min)
+         Gmix%glam(i+rho,j)     =  G1%glamu(i_min,j_min)
+		 Gmix%glam(i,j+rho)     =  G1%glamv(i_min,j_min)
+	     Gmix%glam(i+rho,j+rho) =  G1%glamf(i_min,j_min)		    
+		 !
+         Gmix%gphi(i,j)         =  G1%gphit(i_min,j_min)
+         Gmix%gphi(i+rho,j)     =  G1%gphiu(i_min,j_min)		 
+		 Gmix%gphi(i,j+rho)     =  G1%gphiv(i_min,j_min)
+	     Gmix%gphi(i+rho,j+rho) =  G1%gphif(i_min,j_min)
+		 !
+		 Gmix%e1(i,j)         =  G1%e1t(i_min,j_min)
+         Gmix%e1(i+rho,j)     =  G1%e1u(i_min,j_min)		 
+		 Gmix%e1(i,j+rho)     =  G1%e1v(i_min,j_min)
+	     Gmix%e1(i+rho,j+rho) =  G1%e1f(i_min,j_min)	
+		 !	
+		 Gmix%e2(i,j)         =  G1%e2t(i_min,j_min)
+         Gmix%e2(i+rho,j)     =  G1%e2u(i_min,j_min)		 
+		 Gmix%e2(i,j+rho)     =  G1%e2v(i_min,j_min)
+	     Gmix%e2(i+rho,j+rho) =  G1%e2f(i_min,j_min) 
+		 !
+		 i_min = i_min+1	
+	  ENDDO
+	  j_min = j_min+1	
+   ENDDO
+   !
+   !***On rcupre les pts depuis G2
+   j_min = jmin - 1
+   DO j=1,nyG2mix,(2*rho)      
+	  i_min = 3
+      DO k=i,nxGmix,(2*rho)       
+	     Gmix%nav_lon(k,j)      =  G2%nav_lon(i_min,j_min)
+         Gmix%nav_lat(k+rho,j)  =  G2%nav_lat(i_min,j_min)	    
+		 !
+         Gmix%glam(k,j)         =  G2%glamt(i_min,j_min)
+         Gmix%glam(k+rho,j)     =  G2%glamu(i_min,j_min)
+		 Gmix%glam(k,j+rho)     =  G2%glamv(i_min,j_min)
+	     Gmix%glam(k+rho,j+rho) =  G2%glamf(i_min,j_min)		    
+		 !
+         Gmix%gphi(k,j)         =  G2%gphit(i_min,j_min)
+         Gmix%gphi(k+rho,j)     =  G2%gphiu(i_min,j_min)		 
+		 Gmix%gphi(k,j+rho)     =  G2%gphiv(i_min,j_min)
+	     Gmix%gphi(k+rho,j+rho) =  G2%gphif(i_min,j_min)
+		 !
+		 Gmix%e1(k,j)         =  G2%e1t(i_min,j_min)
+         Gmix%e1(k+rho,j)     =  G2%e1u(i_min,j_min)		 
+		 Gmix%e1(k,j+rho)     =  G2%e1v(i_min,j_min)
+	     Gmix%e1(k+rho,j+rho) =  G2%e1f(i_min,j_min)	
+		 !	
+		 Gmix%e2(k,j)         =  G2%e2t(i_min,j_min)
+         Gmix%e2(k+rho,j)     =  G2%e2u(i_min,j_min)		 
+		 Gmix%e2(k,j+rho)     =  G2%e2v(i_min,j_min)
+	     Gmix%e2(k+rho,j+rho) =  G2%e2f(i_min,j_min) 
+		 !
+		 i_min = i_min+1	
+	  ENDDO
+	  j_min = j_min+1	
+   ENDDO
+   !
+   !**On rcupre les pts depuis G3
+   j_min = SIZE(G3%glamt,2)-2      !on supprime les bandes de chevauchement
+   DO m=j,nyGmix,(2*rho)
+   	  i_min = imin + imax
+      DO i=1,nxG3mix,(2*rho)
+	     Gmix%nav_lon(i,m)      =  G3%nav_lon(i_min,j_min)
+         Gmix%nav_lat(i+rho,m)  =  G3%nav_lat(i_min,j_min)	    
+		 !
+         Gmix%glam(i,m)         =  G3%glamt(i_min,j_min)
+         Gmix%glam(i+rho,m)     =  G3%glamu(i_min,j_min)
+		 Gmix%glam(i,m+rho)     =  G3%glamv(i_min,j_min)
+	     Gmix%glam(i+rho,m+rho) =  G3%glamf(i_min,j_min)		    
+		 !
+         Gmix%gphi(i,m)         =  G3%gphit(i_min,j_min)
+         Gmix%gphi(i+rho,m)     =  G3%gphiu(i_min,j_min)		 
+		 Gmix%gphi(i,m+rho)     =  G3%gphiv(i_min,j_min)
+	     Gmix%gphi(i+rho,m+rho) =  G3%gphif(i_min,j_min)
+		 !
+		 Gmix%e1(i,m)         =  G3%e1t(i_min,j_min)
+         Gmix%e1(i+rho,m)     =  G3%e1u(i_min,j_min)		 
+		 Gmix%e1(i,m+rho)     =  G3%e1v(i_min,j_min)
+	     Gmix%e1(i+rho,m+rho) =  G3%e1f(i_min,j_min)	
+		 !	
+		 Gmix%e2(i,m)         =  G3%e2t(i_min,j_min)
+         Gmix%e2(i+rho,m)     =  G3%e2u(i_min,j_min)		 
+		 Gmix%e2(i,m+rho)     =  G3%e2v(i_min,j_min)
+	     Gmix%e2(i+rho,m+rho) =  G3%e2f(i_min,j_min) 
+		 !
+		 i_min = i_min - 1      !on se dplace le long de (-i)	
+	  ENDDO
+	  j_min = j_min - 1         !on se dplace le long de (-j)	
+   ENDDO
+   !   
+   !**On rcupre les pts depuis G4
+   j_min =  SIZE(G4%glamt,2)-2     !on supprime les bandes de chevauchement
+   DO m=j,nyGmix,(2*rho)
+   	  i_min = SIZE(G4%glamt,1)-2
+      DO k=i,nxGmix,(2*rho)
+	     Gmix%nav_lon(k,m)      =  G4%nav_lon(i_min,j_min)
+         Gmix%nav_lat(k+rho,m)  =  G4%nav_lat(i_min,j_min)	    
+		 !
+         Gmix%glam(k,m)         =  G4%glamt(i_min,j_min)
+         Gmix%glam(k+rho,m)     =  G4%glamu(i_min,j_min)
+		 Gmix%glam(k,m+rho)     =  G4%glamv(i_min,j_min)
+	     Gmix%glam(k+rho,m+rho) =  G4%glamf(i_min,j_min)		    
+		 !
+         Gmix%gphi(k,m)         =  G4%gphit(i_min,j_min)
+         Gmix%gphi(k+rho,m)     =  G4%gphiu(i_min,j_min)		 
+		 Gmix%gphi(k,m+rho)     =  G4%gphiv(i_min,j_min)
+	     Gmix%gphi(k+rho,m+rho) =  G4%gphif(i_min,j_min)
+		 !
+		 Gmix%e1(k,m)         =  G4%e1t(i_min,j_min)
+         Gmix%e1(k+rho,m)     =  G4%e1u(i_min,j_min)		 
+		 Gmix%e1(k,m+rho)     =  G4%e1v(i_min,j_min)
+	     Gmix%e1(k+rho,m+rho) =  G4%e1f(i_min,j_min)	
+		 !	
+		 Gmix%e2(k,m)         =  G4%e2t(i_min,j_min)
+         Gmix%e2(k+rho,m)     =  G4%e2u(i_min,j_min)		 
+		 Gmix%e2(k,m+rho)     =  G4%e2v(i_min,j_min)
+	     Gmix%e2(k+rho,m+rho) =  G4%e2f(i_min,j_min) 
+		 !
+		 i_min = i_min - 1      !on se dplace le long de (-i)	
+	  ENDDO
+	  j_min = j_min - 1         !on se dplace le long de (-j)	
+   ENDDO
+   !
+print*, 'G1%glamt= '
+DO j=jmin-1,SIZE(G1%glamt,2)
+print*, G1%glamt(imin-1:SIZE(G1%glamt,1),j)
+ENDDO
+print*,''
+print*, 'G1%glamu= '
+DO j=jmin-1,SIZE(G1%glamu,2)
+print*, G1%glamu(imin-1:SIZE(G1%glamu,1),j)
+ENDDO
+print*,''
+print*, 'Gmix%glam= '
+DO j=1,nyGmix
+print*, Gmix%glam(:,j)
+ENDDO
+	 END SUBROUTINE
+     !
+     !
+     !********************************************************
+     !                 SUBROUTINE interp   				    *
+     !									        			*
+     !	calculate polynomial interpolation at 4th order		*
+     !												        *
+     !		   CALLED from create_coordinates.f90	        *
+     !********************************************************
+     !       
+     SUBROUTINE interp_grid(Gmix)
+	 !
+	 TYPE(mixed_coordinates) :: Gmix
+	 !TYPE(Coordinates) :: Grid1
+	 REAL*8, DIMENSION(rho-1,4) :: S      !Array to store the coefficients of Lagrange 	 
+     INTEGER :: i, j, k, status
+	 !
+	 WRITE(*,*) ''
+	 WRITE(*,*) '*** ROUTINE interp ***'
+	 WRITE(*,*) ''
+	 !
+	 !!!Calculate coefficients 
+	 status = pol_coef(S)
+	 !
+	 !IF(rho>1) THEN
+	 !!!Interpolation along longitude
+	 do j=1,SIZE(Gmix%glam,2),rho
+	    do i=1,SIZE(Gmix%glam,1),rho
+		   do k=1,rho-1
+		      Gmix%glam(i+rho+k,j) =   S(k,1) * Gmix%glam(i,j)         &
+										   + S(k,2) * Gmix%glam(i+1*rho,j)   &
+									       + S(k,3) * Gmix%glam(i+2*rho,j)   &
+									       + S(k,4) * Gmix%glam(i+3*rho,j)
+			  !
+			  Gmix%gphi(i+rho+k,j) =   S(k,1) * Gmix%gphi(i,j)         &
+										   + S(k,2) * Gmix%gphi(i+1*rho,j)   &
+									       + S(k,3) * Gmix%gphi(i+2*rho,j)   &
+									       + S(k,4) * Gmix%gphi(i+3*rho,j)
+			  !
+			  Gmix%e1(i+rho+k,j) =     S(k,1) * Gmix%e1(i,j)         &
+										   + S(k,2) * Gmix%e1(i+1*rho,j)   &
+									       + S(k,3) * Gmix%e1(i+2*rho,j)   &
+									       + S(k,4) * Gmix%e1(i+3*rho,j)
+			  !
+			  Gmix%e2(i+rho+k,j) =     S(k,1) * Gmix%e2(i,j)         &
+										   + S(k,2) * Gmix%e2(i+1*rho,j)   &
+									       + S(k,3) * Gmix%e2(i+2*rho,j)   &
+									       + S(k,4) * Gmix%e2(i+3*rho,j)
+			  !
+			  Gmix%nav_lon(i+rho+k,j) = Gmix%glam(i+rho+k,j)
+			  Gmix%nav_lat(i+rho+k,j) = Gmix%gphi(i+rho+k,j)
+			  !
+		   end do
+		   !							   
+	       IF(i+3*rho == SIZE(Gmix%glam,1)) EXIT
+		end do
+	end do
+	 !
+	 !!!Interpolation along latitude
+	 do i=1,SIZE(Gmix%glam,1)
+	    do j=1,SIZE(Gmix%glam,2),rho
+		   do k=1,rho-1
+		      Gmix%glam(i,j+rho+k) =   S(k,1) * Gmix%glam(i,j)       &
+										   + S(k,2) * Gmix%glam(i,j+rho)   &
+									       + S(k,3) * Gmix%glam(i,j+2*rho) &
+									       + S(k,4) * Gmix%glam(i,j+3*rho)
+		      !
+			  Gmix%gphi(i,j+rho+k) =   S(k,1) * Gmix%gphi(i,j)       &
+										   + S(k,2) * Gmix%gphi(i,j+rho)   &
+									       + S(k,3) * Gmix%gphi(i,j+2*rho) &
+									       + S(k,4) * Gmix%gphi(i,j+3*rho)
+			  !
+			  Gmix%e1(i,j+rho+k) =     S(k,1) * Gmix%e1(i,j)       &
+										   + S(k,2) * Gmix%e1(i,j+rho)   &
+									       + S(k,3) * Gmix%e1(i,j+2*rho) &
+									       + S(k,4) * Gmix%e1(i,j+3*rho)
+			  !
+			  Gmix%e2(i,j+rho+k) =     S(k,1) * Gmix%e2(i,j)       &
+										   + S(k,2) * Gmix%e2(i,j+rho)   &
+									       + S(k,3) * Gmix%e2(i,j+2*rho) &
+									       + S(k,4) * Gmix%e2(i,j+3*rho)
+			  !
+			  Gmix%nav_lon(i,j+rho+k) = Gmix%glam(i,j+rho+k)
+			  Gmix%nav_lat(i,j+rho+k) = Gmix%gphi(i,j+rho+k)
+			  !
+			end do
+			  !							   
+			IF(j+3*rho == SIZE(Gmix%glam,2)) EXIT
+		end do
+	end do	
+
+     !
+    
+	 END SUBROUTINE
+     !
+	 !
+     !********************************************************
+     !                  FUNCTION pol_coef   			    *
+     !									        			*
+     !	      calculate the coefficients of Lagrange   		*
+     !			 for the polynomial interpolation	        *
+     !												        *
+	 !             CALLED from SUBROUTINE interp            *
+     !********************************************************
+     !     
+	 REAL FUNCTION pol_coef(vect)
+	    !
+		REAL*8, DIMENSION(rho-1,4) :: vect
+		REAL*8, DIMENSION(3) :: v		
+		INTEGER :: i, m, k
+		REAL*8 :: x0      !position relative du point  calculer 
+		INTEGER :: x_k, x_i      !position relative des points utiliss pour l'interpolation
+		REAL*8 :: eps 
+		!
+		!on parle de position relative puisque nous utilisons les positions
+		!indiciaires, lesquelles sont rptes dans toute la grille.
+		!Il n'est donc ncessaire de calculer qu'une fois les 4 coefficients 
+		!qui seront utiliss dans toute la grille en fonction de rho
+		!
+		     !
+	 WRITE(*,*) ''
+	 WRITE(*,*) '*** FUNCTION pol_coef ***'
+	 WRITE(*,*) ''
+	 !
+		m=1
+		eps = 1.-1e-8
+		!
+		do k=1,rho-1 
+		   x0=rho+1+k
+		   i=1
+		   do x_i=1,4+3*(rho-1),rho
+			m=1
+			   do x_k=1,4+3*(rho-1),rho
+			     IF(x_k == x_i) THEN
+				    CYCLE
+				 ELSE	
+		         v(m) = (x0-x_k) / (x_i-x_k)
+				 m=m+1
+		         END IF
+			   end do
+		       vect(k,i) = product(v)
+			   i=i+1
+		   end do
+		end do
+		!
+		IF((SUM(vect)<eps .OR. SUM(vect)>eps) .AND. rho>1) THEN
+		   print*,''
+		   print*, '*** CHECK LAGRANGE COEFFICIENTS: ***'
+		   print*,''
+		   do i=1,rho-1
+		      print*,'point #',i
+		      print*, 'S(i,:)= ', vect(i,:)
+		      print*, 'SUM(S(i,:)) =', SUM(vect(i,:))
+			  print*,''
+		   end do
+		   print*, ''
+		   pol_coef = 1
+		ELSE
+		   !print*,'Error with Lagrange coefficients'
+		   pol_coef = 0
+		END IF
+	    !
+	 END FUNCTION pol_coef
+	 !
+     !
+     !********************************************************
+     !             SUBROUTINE alloc_child_grid   		    *
+     !									        			*
+     !	      create the child grid from mixed grid		    *
+     !												        *
+     !		   CALLED from create_coordinates.f90	        *
+     !********************************************************
+     !       
+     SUBROUTINE alloc_child_grid(Gmix, Grid1)	 
+	 !
+	 TYPE(mixed_coordinates), INTENT(IN) :: Gmix
+	 TYPE(coordinates), INTENT(INOUT) :: Grid1
+	 INTEGER :: i, j, p, q
+	 !
+	 WRITE(*,*) ''
+	 WRITE(*,*) '*** ROUTINE alloc_child_grid ***'
+	 WRITE(*,*) ''
+	 !
+	 !
+	 IF(rho>1) THEN
+	    q=1
+	    DO j=rho+2,(SIZE(Gmix%glam,2)-(rho)),2
+	    p=1
+	    DO i=rho+2,(SIZE(Gmix%glam,1)-(rho)),2
+		   !
+		   Grid1%nav_lon(p,q) = Gmix%nav_lon(i,j)
+		   Grid1%nav_lat(p,q) = Gmix%nav_lat(i,j)
+		   !
+		   Grid1%glamt(p,q) = Gmix%glam(i,j)
+		   Grid1%glamu(p,q) = Gmix%glam(i+1,j)
+		   Grid1%glamv(p,q) = Gmix%glam(i,j+1)
+		   Grid1%glamf(p,q) = Gmix%glam(i+1,j+1)
+		   !
+		   Grid1%gphit(p,q) = Gmix%gphi(i,j)
+		   Grid1%gphiu(p,q) = Gmix%gphi(i+1,j)
+		   Grid1%gphiv(p,q) = Gmix%gphi(i,j+1)
+		   Grid1%gphif(p,q) = Gmix%gphi(i+1,j+1)
+		   !
+		   Grid1%e1t(p,q) = Gmix%e1(i,j)
+		   Grid1%e1u(p,q) = Gmix%e1(i+1,j)
+		   Grid1%e1v(p,q) = Gmix%e1(i,j+1)
+		   Grid1%e1f(p,q) = Gmix%e1(i+1,j+1)
+		   !
+		   Grid1%e2t(p,q) = Gmix%e2(i,j)
+		   Grid1%e2u(p,q) = Gmix%e2(i+1,j)
+		   Grid1%e2v(p,q) = Gmix%e2(i,j+1)
+		   Grid1%e2f(p,q) = Gmix%e2(i+1,j+1)
+		   !		
+		   p=p+1
+		END DO
+		q=q+1
+	END DO
+ELSE
+	     q=1
+	    DO j=1,SIZE(Gmix%glam,2),2
+	    p=1
+	    DO i=1,SIZE(Gmix%glam,1),2
+		   !
+		   Grid1%nav_lon(p,q) = Gmix%nav_lon(i,j)
+		   Grid1%nav_lat(p,q) = Gmix%nav_lat(i+1,j)
+		   !
+		   Grid1%glamt(p,q) = Gmix%glam(i,j)
+		   Grid1%glamu(p,q) = Gmix%glam(i+1,j)
+		   Grid1%glamv(p,q) = Gmix%glam(i,j+1)
+		   Grid1%glamf(p,q) = Gmix%glam(i+1,j+1)
+		   !
+		   Grid1%gphit(p,q) = Gmix%gphi(i,j)
+		   Grid1%gphiu(p,q) = Gmix%gphi(i+1,j)
+		   Grid1%gphiv(p,q) = Gmix%gphi(i,j+1)
+		   Grid1%gphif(p,q) = Gmix%gphi(i+1,j+1)
+		   !
+		   Grid1%e1t(p,q) = Gmix%e1(i,j)
+		   Grid1%e1u(p,q) = Gmix%e1(i+1,j)
+		   Grid1%e1v(p,q) = Gmix%e1(i,j+1)
+		   Grid1%e1f(p,q) = Gmix%e1(i+1,j+1)
+		   !
+		   Grid1%e2t(p,q) = Gmix%e2(i,j)
+		   Grid1%e2u(p,q) = Gmix%e2(i+1,j)
+		   Grid1%e2v(p,q) = Gmix%e2(i,j+1)
+		   Grid1%e2f(p,q) = Gmix%e2(i+1,j+1)
+		   !		
+		p=p+1
+		END DO
+		q=q+1
+		END DO
+	   ENDIF
+	
+   WRITE(*,*) ''
+   WRITE(*,*) 'Size of the Child grid: ', nx_fine, ' x ', ny_fine
+   WRITE(*,*) ''	
+print*, 'Grid1%nav_lat= '
+DO j=1,ny_fine
+print*, Grid1%nav_lat(:,j)
+END DO    
+	 !
+	 END SUBROUTINE alloc_child_grid
+!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!             
+!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
+END MODULE tools_brice
Index: /trunk/UTIL/CFG_TOOLS/create_coordinates.f90
===================================================================
--- /trunk/UTIL/CFG_TOOLS/create_coordinates.f90	(revision 1799)
+++ /trunk/UTIL/CFG_TOOLS/create_coordinates.f90	(revision 1799)
@@ -0,0 +1,93 @@
+program create_coordinates
+!-----------------------------------------------------------
+!
+!	  to create coordinates file (e.g. 1_coordinates.nc)
+!    for fine grid from coarse grid (e.g. coordinates.nc)
+!
+!   to make it we use a 4th order polynomial interpolation
+!
+!	        Created by Brice Lemaire on 12/2009.
+!
+!-----------------------------------------------------------
+USE netcdf
+USE agrif_readwrite
+USE tools_brice
+!------------
+IMPLICIT NONE
+   !
+   TYPE(coordinates) :: G1, G2, G3, G4     !from agrif_types from agrif_readwrite
+   TYPE(coordinates) :: fine_grid
+   TYPE(mixed_coordinates) :: Gmix      !from agrif_types from agrif_readwrite
+   !INTEGER :: nxG1, nyG1, nxG2, nyG2, nxG3, nyG3, nxG4, nyG4
+   INTEGER :: narg,iargc
+   INTEGER :: status
+   CHARACTER(len=80) :: namelistname, Child_filename
+   !
+   !!!Read input file (namelist file)
+   narg = iargc()
+   !
+   IF (narg == 0) THEN
+	   namelistname = 'namelist.input'
+   ELSE
+	   CALL getarg(1,namelistname)
+   ENDIF
+   !
+   CALL read_namelist(namelistname)      !imin,imax,jmin,jmax,parent_coordinate_file
+   !
+   !!!Read parent coordinate file
+   IF((imin.LT.imax).AND.(jmin.LT.jmax)) THEN
+      status = Read_Coordinates(TRIM(parent_coordinate_file),G1)      !from agrif_readwrite
+   ELSEIF((imin.GE.imax).AND.(jmin.LT.jmax)) THEN
+      status = Read_Coordinates(TRIM(parent_coordinate_file),G1)      !from agrif_readwrite
+      status = Read_Coordinates(TRIM(parent_coordinate_file),G2)      !from agrif_readwrite
+   ELSEIF((imin.GE.imax).AND.(jmin.GE.jmax)) THEN
+	  status = Read_Coordinates(TRIM(parent_coordinate_file),G1)      !from agrif_readwrite
+      status = Read_Coordinates(TRIM(parent_coordinate_file),G2)      !from agrif_readwrite
+      status = Read_Coordinates(TRIM(parent_coordinate_file),G3)      !from agrif_readwrite
+      status = Read_Coordinates(TRIM(parent_coordinate_file),G4)      !from agrif_readwrite
+   ENDIF
+   ! 
+   !
+   !!!Create the mixed grid with U,V,F & W values
+   IF((imin.LT.imax).AND.(jmin.LT.jmax)) THEN
+      CALL mixed_grid(G1,Gmix)
+   ELSEIF((imin.GE.imax).AND.(jmin.LT.jmax)) THEN
+      CALL mixed_grid(G1,G2,Gmix)
+   ELSEIF((imin.GE.imax).AND.(jmin.GE.jmax)) THEN
+      CALL mixed_grid(G1,G2,G3,G4,Gmix)      !from tools_brice
+   !ELSEIF()
+   ENDIF
+   
+   
+!print*, 'G1%nav_lat= '
+!DO j=jmin-1,jmax+1
+!print*, G1%nav_lat(imin-1:imax+1,j)
+!END DO  
+
+!print*, 'G1%nav_lon= '
+!DO j=jmin-1,jmax+1
+!print*, G1%nav_lon(imin-1:imax+1,j)
+!END DO 
+   !
+   !!!Interpolation inside the mixed grid
+   IF(rho>1) THEN
+      CALL interp_grid(Gmix)      !from tools_brice
+   ENDIF
+   !   
+   !!!Define name of child coordinate file
+   CALL set_child_name(parent_coordinate_file,Child_filename)      !coordinates.nc -> 1_coordinates.nc
+   !
+   !!!Allocation of child grid elements
+   CALL agrif_grid_allocate(fine_grid,nx_fine,ny_fine)      !from agrif_types
+   !
+   !!!Break the mixed grid Gmix into 4 grids (G1%u, G1%v, G1%t, GI%f)
+   CALL alloc_child_grid(Gmix,fine_grid)      !from tools_brice
+   !
+print*, 'fine_grid%glamf= '
+DO j=1,ny_fine
+print*, fine_grid%glamf(:,j)
+END DO 
+    !!!Read parent coordinate file
+   status = Write_Coordinates(Child_filename,fine_grid,nx_fine,ny_fine)      !from agrif_readwrite
+   !
+end program create_coordinates
Index: /trunk/UTIL/CFG_TOOLS/io_netcdf.f90
===================================================================
--- /trunk/UTIL/CFG_TOOLS/io_netcdf.f90	(revision 1799)
+++ /trunk/UTIL/CFG_TOOLS/io_netcdf.f90	(revision 1799)
@@ -0,0 +1,1815 @@
+!************************************************************************
+! Fortran 95 OPA Nesting tools						*
+!									*
+!     Copyright (C) 2005 Florian Lemari�(Florian.Lemarie@imag.fr)	*
+!									*
+!************************************************************************
+!
+!********************************************************************************
+!										*
+! module io_netcdf								*
+!										*
+! NetCDF Fortran 90 read/write interface					*
+! using input/output functions provided						*
+! by unidata									*
+!										*
+!http://my.unidata.ucar.edu/content/software/netcdf/docs/netcdf-f90/index.html	*
+!										*
+!********************************************************************************
+!
+!
+!
+MODULE io_netcdf
+  !      
+  USE netcdf
+  USE agrif_types
+  !      
+  INTERFACE Read_Ncdf_var
+     MODULE PROCEDURE Read_Ncdf_var1d_Real,   &
+          Read_Ncdf_var2d_Real,   &
+          Read_Ncdf_var2d_Real_bis,   &
+          Read_Ncdf_var3d_Real,   &
+          Read_Ncdf_var4d_Real,   &
+          Read_Ncdf_var3d_Real_t, &
+          Read_Ncdf_var4d_Real_t, &
+          Read_Ncdf_var4d_Real_nt, &
+          Read_Ncdf_var1d_Int,    &
+          Read_Ncdf_var2d_Int,    &
+          Read_Ncdf_var3d_Int,    &
+          Read_Ncdf_var4d_Int,    &
+          Read_Ncdf_var0d_Int,    &
+          Read_Ncdf_var0d_Real
+  END INTERFACE
+  !
+  INTERFACE Write_Ncdf_var
+     MODULE PROCEDURE Write_Ncdf_var1d_Real,   &
+          Write_Ncdf_var2d_Real,   &
+          Write_Ncdf_var3d_Real,   &
+          Write_Ncdf_var4d_Real,   &
+          Write_Ncdf_var3d_Real_t, &
+          Write_Ncdf_var4d_Real_t, &
+          Write_Ncdf_var4d_Real_nt, &                           
+          Write_Ncdf_var2d_Real_bis,&			   
+          Write_Ncdf_var1d_Int,    &
+          Write_Ncdf_var2d_Int,    &
+          Write_Ncdf_var3d_Int,    &
+          Write_Ncdf_var4d_Int,    &
+          Write_Ncdf_var0d_Real
+  END INTERFACE
+  ! 
+  INTERFACE Copy_Ncdf_att
+     MODULE PROCEDURE Copy_Ncdf_att_latlon,Copy_Ncdf_att_var
+  END INTERFACE
+  !
+CONTAINS
+  !
+  !****************************************************************
+  !   subroutine Read_Ncdf_dim					*
+  !								*
+  ! subroutine to retrieve value of a given dimension 		*
+  !								*
+  !     dimname : name of dimension to retrieve			*
+  !     file    : netcdf file name				*
+  !     dimval  : value of the required dimension			*
+  !								*
+  !****************************************************************
+  !
+  SUBROUTINE Read_Ncdf_dim(dimname,file,dimval)   
+    !      
+    IMPLICIT NONE
+    !           
+    CHARACTER(*),INTENT(in) :: dimname,file    
+    INTEGER    :: dimval
+    !            
+    ! local variables
+    !
+    INTEGER ncid,status,dimid
+    !     
+    status = nf90_open(file,NF90_NOWRITE,ncid)
+    IF (status/=nf90_noerr) THEN    
+       WRITE(*,*)"unable to open netcdf file : ",file
+       STOP
+    ENDIF
+    !     
+    status = nf90_inq_dimid(ncid,dimname,dimid)
+    status = nf90_inquire_dimension(ncid,dimid,len=dimval)						                
+    !      
+    status = nf90_close(ncid)
+    !      
+  END SUBROUTINE Read_Ncdf_dim
+  !
+  !**************************************************************
+  ! end subroutine Read_Ncdf_dim
+  !**************************************************************      
+  !
+  !****************************************************************
+  !   subroutine Write_Ncdf_dim					*
+  !								*
+  ! subroutine to write a dimension in a given file 		*
+  !								*
+  !     dimname : name of dimension to initialize			*
+  !     file    : netcdf file name				*
+  !     dimval  : value of the dimension to write			*
+  !								*
+  !****************************************************************
+  !
+  SUBROUTINE Write_Ncdf_dim(dimname,file,dimval)   
+    !      
+    IMPLICIT NONE
+    !           
+    CHARACTER(*),INTENT(in) :: dimname,file    
+    INTEGER    :: dimval
+    !      
+    ! local variables
+    !
+    INTEGER ncid,status,dimid
+    !     
+    status = nf90_open(file,NF90_WRITE,ncid)
+    IF (status/=nf90_noerr) THEN    
+       WRITE(*,*)"unable to open netcdf file : ",file
+       STOP
+    ENDIF
+    !     
+    status = nf90_redef(ncid)
+    IF(dimval.EQ.0) THEN
+       status = nf90_def_dim(ncid,dimname,nf90_unlimited,dimid)       
+    ELSE
+       status = nf90_def_dim(ncid,dimname,dimval,dimid)  
+    END IF
+
+    status = nf90_enddef(ncid)
+    !      
+
+    status = nf90_close(ncid)
+    !      
+  END SUBROUTINE Write_Ncdf_dim
+  !
+  !**************************************************************
+  ! end subroutine Write_Ncdf_dim
+  !**************************************************************            
+  ! 
+  !****************************************************************
+  !   subroutine Read_Ncdf_var					*
+  !								*
+  ! subroutine to retrieve values of a given variable 		*
+  !								*
+  !     varname : name of variable to retrieve			*
+  !     file    : netcdf file name				*
+  !     tabvar  : array containing values of the required variable*
+  !								*
+  !****************************************************************
+  !          
+  !**************************************************************
+  !   subroutine Read_Ncdf_var1d_real
+  !**************************************************************          
+  !      
+  SUBROUTINE Read_Ncdf_var1d_Real(varname,file,tabvar)
+    !      
+    IMPLICIT NONE
+    !       
+    CHARACTER(*),INTENT(in) :: varname,file
+    REAL*8, DIMENSION(:), POINTER :: tabvar
+    !
+    !local variables
+    !
+    INTEGER, DIMENSION(1) :: dimID
+    INTEGER :: dim1
+    INTEGER :: status,ncid
+    INTEGER :: varid             
+    !
+    status = nf90_open(file,NF90_NOWRITE,ncid)
+    !      
+    IF (status/=nf90_noerr) THEN    
+       WRITE(*,*)"unable to open netcdf file : ",file
+       STOP
+    ENDIF
+    !     
+    status = nf90_inq_varid(ncid,varname,varid)
+    status=nf90_inquire_variable(ncid,varid,dimids=dimID)
+    status=nf90_inquire_dimension(ncid,dimID(1),len=dim1)
+    !                
+    IF(.NOT. ASSOCIATED(tabvar)) THEN
+       ALLOCATE(tabvar(dim1))  
+    ELSE
+       IF( ANY(SHAPE(tabvar)/=(/dim1/)) ) THEN	   
+          DEALLOCATE(tabvar)   
+          ALLOCATE(tabvar(dim1))      
+       ENDIF
+    ENDIF
+    !        
+    status=nf90_get_var(ncid,varid,tabvar)     
+    !     
+    status = nf90_close(ncid)
+    ! 
+  END SUBROUTINE Read_Ncdf_var1d_Real
+  !           
+  !**************************************************************
+  ! end subroutine Read_Ncdf_var1d_real
+  !**************************************************************          
+  !            
+  !           
+  !**************************************************************
+  !   subroutine Read_Ncdf_var2d_real
+  !**************************************************************          
+  !      
+  SUBROUTINE Read_Ncdf_var2d_Real(varname,file,tabvar)
+    !      
+    IMPLICIT NONE
+    !       
+    CHARACTER(*),INTENT(in) :: varname,file
+    REAL*8, DIMENSION(:,:), POINTER :: tabvar
+    !local variables
+    INTEGER, DIMENSION(10) :: dimIDS
+    INTEGER :: dim1,dim2
+    INTEGER :: status,ncid
+    INTEGER :: varid             
+    !
+    status = nf90_open(file,NF90_NOWRITE,ncid)
+    !      
+    IF (status/=nf90_noerr) THEN    
+       WRITE(*,*)"unable to open netcdf file : ",file
+       STOP
+    ENDIF
+    !     
+    status = nf90_inq_varid(ncid,varname,varid)
+    status=nf90_inquire_variable(ncid,varid,dimids=dimIDS)
+    status=nf90_inquire_dimension(ncid,dimIDS(1),len=dim1)
+    status=nf90_inquire_dimension(ncid,dimIDS(2),len=dim2)
+    !                
+    IF(.NOT. ASSOCIATED(tabvar)) THEN
+       ALLOCATE(tabvar(dim1,dim2))  
+    ELSE
+       IF( ANY(SHAPE(tabvar)/=(/dim1,dim2/)) ) THEN	   
+          DEALLOCATE(tabvar)   
+          ALLOCATE(tabvar(dim1,dim2))      
+       ENDIF
+    ENDIF
+    !       
+    status=nf90_get_var(ncid,varid,tabvar)     
+    !     
+    status = nf90_close(ncid)
+    !     
+  END SUBROUTINE Read_Ncdf_var2d_Real
+  !           
+  !**************************************************************
+  ! end subroutine Read_Ncdf_var2d_real
+  !**************************************************************          
+  !    
+
+  !           
+  !**************************************************************
+  !   subroutine Read_Ncdf_var2d_real_bis
+  !**************************************************************          
+  !      
+  SUBROUTINE Read_Ncdf_var2d_Real_bis(varname,file,tabvar,strt,cnt)
+    !      
+    IMPLICIT NONE
+    !       
+    CHARACTER(*),INTENT(in) :: varname,file
+    REAL*8, DIMENSION(:,:), POINTER :: tabvar
+    !local variables
+    INTEGER, DIMENSION(10) :: dimIDS
+    INTEGER, DIMENSION(2) :: strt,cnt
+    INTEGER :: dim1,dim2
+    INTEGER :: status,ncid
+    INTEGER :: varid             
+    !
+    status = nf90_open(file,NF90_NOWRITE,ncid)
+    !      
+    IF (status/=nf90_noerr) THEN    
+       WRITE(*,*)"unable to open netcdf file : ",file
+       STOP
+    ENDIF
+    !     
+    dim1 = cnt(1) 
+    dim2 = cnt(2)
+    !      
+    status = nf90_inq_varid(ncid,varname,varid)
+    status=nf90_inquire_variable(ncid,varid,dimids=dimIDS)
+    !                
+    IF(.NOT. ASSOCIATED(tabvar)) THEN
+       ALLOCATE(tabvar(dim1,dim2))  
+    ELSE
+       IF( ANY(SHAPE(tabvar)/=(/dim1,dim2/)) ) THEN	   
+          DEALLOCATE(tabvar)   
+          ALLOCATE(tabvar(dim1,dim2))      
+       ENDIF
+    ENDIF
+    !       
+    status=nf90_get_var(ncid,varid,tabvar,start = strt,count = cnt)     
+    !     
+    status = nf90_close(ncid)
+    !     
+  END SUBROUTINE Read_Ncdf_var2d_Real_bis
+  !           
+  !**************************************************************
+  ! end subroutine Read_Ncdf_var2d_real_bis
+  !**************************************************************          
+  !  
+
+
+  !           
+  !**************************************************************
+  !   subroutine Read_Ncdf_var3d_real
+  !**************************************************************          
+  !      
+  SUBROUTINE Read_Ncdf_var3d_Real(varname,file,tabvar)
+    !      
+    IMPLICIT NONE
+    !       
+    CHARACTER(*),INTENT(in) :: varname,file
+    REAL*8, DIMENSION(:,:,:), POINTER :: tabvar
+    !
+    !local variables
+    !
+    INTEGER, DIMENSION(10) :: dimIDS
+    INTEGER :: dim1,dim2,dim3
+    INTEGER :: status,ncid
+    INTEGER :: varid             
+    !
+    status = nf90_open(file,NF90_NOWRITE,ncid)
+    !      
+    IF (status/=nf90_noerr) THEN    
+       WRITE(*,*)"unable to open netcdf file : ",file
+       STOP
+    ENDIF
+    !     
+    status = nf90_inq_varid(ncid,varname,varid)
+    status=nf90_inquire_variable(ncid,varid,dimids=dimIDS)
+    status=nf90_inquire_dimension(ncid,dimIDS(1),len=dim1)
+    status=nf90_inquire_dimension(ncid,dimIDS(2),len=dim2)  
+    status=nf90_inquire_dimension(ncid,dimIDS(3),len=dim3)
+    !                
+    IF(.NOT. ASSOCIATED(tabvar)) THEN
+       ALLOCATE(tabvar(dim1,dim2,dim3))  
+    ELSE
+       IF( ANY(SHAPE(tabvar) /= (/dim1,dim2,dim3/)) ) THEN	   
+          DEALLOCATE(tabvar)   
+          ALLOCATE(tabvar(dim1,dim2,dim3))      
+       ENDIF
+    ENDIF
+    !      
+    status=nf90_get_var(ncid,varid,tabvar) 
+    IF (status/=nf90_noerr) THEN    
+       WRITE(*,*)"unable to retrieve netcdf variable : ",TRIM(varname)
+       STOP
+    ENDIF
+    !     
+    status = nf90_close(ncid)
+    !     
+  END SUBROUTINE Read_Ncdf_var3d_Real
+  !           
+  !**************************************************************
+  ! end subroutine Read_Ncdf_var3d_real
+  !**************************************************************          
+  ! 
+  !           
+  !**************************************************************
+  !   subroutine Read_Ncdf_var4d_real
+  !**************************************************************          
+  !      
+  SUBROUTINE Read_Ncdf_var4d_Real(varname,file,tabvar)
+    !      
+    IMPLICIT NONE
+    !       
+    CHARACTER(*),INTENT(in) :: varname,file
+    REAL*8, DIMENSION(:,:,:,:), POINTER :: tabvar
+    !
+    !local variables
+    !
+    INTEGER, DIMENSION(10) :: dimIDS
+    INTEGER :: dim1,dim2,dim3,dim4
+    INTEGER :: status,ncid
+    INTEGER :: varid             
+    !
+    status = nf90_open(file,NF90_NOWRITE,ncid)
+    !      
+    IF (status/=nf90_noerr) THEN    
+       WRITE(*,*)"unable to open netcdf file : ",file
+       STOP
+    ENDIF
+    !     
+    status = nf90_inq_varid(ncid,varname,varid)
+    status=nf90_inquire_variable(ncid,varid,dimids=dimIDS)
+    status=nf90_inquire_dimension(ncid,dimIDS(1),len=dim1)
+    status=nf90_inquire_dimension(ncid,dimIDS(2),len=dim2)  
+    status=nf90_inquire_dimension(ncid,dimIDS(3),len=dim3)   
+    status=nf90_inquire_dimension(ncid,dimIDS(4),len=dim4)       
+    !                
+    IF(.NOT. ASSOCIATED(tabvar)) THEN
+       ALLOCATE(tabvar(dim1,dim2,dim3,dim4))  
+    ELSE
+       IF( ANY(SHAPE(tabvar) /= (/dim1,dim2,dim3,dim4/)) ) THEN	   
+          DEALLOCATE(tabvar)   
+          ALLOCATE(tabvar(dim1,dim2,dim3,dim4))      
+       ENDIF
+    ENDIF
+    !  
+    status=nf90_get_var(ncid,varid,tabvar)     
+    !     
+    status = nf90_close(ncid)
+    !     
+  END SUBROUTINE Read_Ncdf_var4d_Real
+
+  SUBROUTINE Read_Ncdf_var0d_Real(varname,file,tabvar)
+    !      
+    IMPLICIT NONE
+    !       
+    CHARACTER(*),INTENT(in) :: varname,file
+    REAL*8 :: tabvar
+    !
+    !local variables
+    !
+    INTEGER :: status,ncid
+    INTEGER :: varid             
+    !
+    status = nf90_open(file,NF90_NOWRITE,ncid)
+    !      
+    IF (status/=nf90_noerr) THEN    
+       WRITE(*,*)"unable to open netcdf file : ",file
+       STOP
+    ENDIF
+    !     
+    status = nf90_inq_varid(ncid,varname,varid)
+    !
+    !  
+    status=nf90_get_var(ncid,varid,tabvar)     
+    !     
+    status = nf90_close(ncid)
+    !     
+  END SUBROUTINE Read_Ncdf_var0d_Real
+
+  SUBROUTINE Read_Ncdf_var0d_Int(varname,file,tabvar)
+    !      
+    IMPLICIT NONE
+    !       
+    CHARACTER(*),INTENT(in) :: varname,file
+    INTEGER :: tabvar
+    !
+    !local variables
+    !
+    INTEGER :: status,ncid
+    INTEGER :: varid             
+    !
+    status = nf90_open(file,NF90_NOWRITE,ncid)
+    !      
+    IF (status/=nf90_noerr) THEN    
+       WRITE(*,*)"unable to open netcdf file : ",file
+       STOP
+    ENDIF
+    !     
+    status = nf90_inq_varid(ncid,varname,varid)
+    !
+    !  
+    status=nf90_get_var(ncid,varid,tabvar)     
+    !     
+    status = nf90_close(ncid)
+    !     
+  END SUBROUTINE Read_Ncdf_var0d_Int
+  !           
+  !**************************************************************
+  ! end subroutine Read_Ncdf_var4d_real
+  !**************************************************************          
+  !             
+  !           
+  !**************************************************************
+  !   subroutine Read_Ncdf_var1d_int
+  !**************************************************************          
+  !      
+  SUBROUTINE Read_Ncdf_var1d_Int(varname,file,tabvar)
+    !      
+    IMPLICIT NONE
+    !       
+    CHARACTER(*),INTENT(in) :: varname,file
+    INTEGER, DIMENSION(:), POINTER :: tabvar
+    !
+    !local variables
+    !
+    INTEGER,DIMENSION(10) :: dimID
+    INTEGER :: dim1
+    INTEGER :: status,ncid
+    INTEGER :: varid             
+    !
+    status = nf90_open(file,NF90_NOWRITE,ncid)
+    !      
+    IF (status/=nf90_noerr) THEN    
+       WRITE(*,*)"unable to open netcdf file : ",file
+       STOP
+    ENDIF
+    !     
+    status = nf90_inq_varid(ncid,varname,varid)
+    status=nf90_inquire_variable(ncid,varid,dimids=dimID)
+    status=nf90_inquire_dimension(ncid,dimID(1),len=dim1)          
+    !                
+    IF(.NOT. ASSOCIATED(tabvar)) THEN
+       ALLOCATE(tabvar(dim1))  
+    ELSE
+       IF( ANY(SHAPE(tabvar) /= (/dim1/)) ) THEN	   
+          DEALLOCATE(tabvar)   
+          ALLOCATE(tabvar(dim1))      
+       ENDIF
+    ENDIF
+    !  
+    status=nf90_get_var(ncid,varid,tabvar)     
+    !     
+    status = nf90_close(ncid)
+    !      
+  END SUBROUTINE Read_Ncdf_var1d_Int
+  !           
+  !**************************************************************
+  ! end subroutine Read_Ncdf_var1d_int
+  !**************************************************************          
+  !            
+  !           
+  !**************************************************************
+  !   subroutine Read_Ncdf_var2d_int
+  !**************************************************************          
+  !      
+  SUBROUTINE Read_Ncdf_var2d_Int(varname,file,tabvar)
+    !      
+    IMPLICIT NONE
+    !       
+    CHARACTER(*),INTENT(in) :: varname,file
+    INTEGER, DIMENSION(:,:), POINTER :: tabvar
+    !local variables
+    INTEGER, DIMENSION(10) :: dimIDS
+    INTEGER :: dim1,dim2
+    INTEGER :: status,ncid
+    INTEGER :: varid             
+    !
+    status = nf90_open(file,NF90_NOWRITE,ncid)
+    !      
+    IF (status/=nf90_noerr) THEN    
+       WRITE(*,*)"unable to open netcdf file : ",file
+       STOP
+    ENDIF
+    !     
+    status = nf90_inq_varid(ncid,varname,varid)
+    status=nf90_inquire_variable(ncid,varid,dimids=dimIDS)
+    status=nf90_inquire_dimension(ncid,dimIDS(1),len=dim1)
+    status=nf90_inquire_dimension(ncid,dimIDS(2),len=dim2)      
+    !                
+    IF(.NOT. ASSOCIATED(tabvar)) THEN
+       ALLOCATE(tabvar(dim1,dim2))  
+    ELSE
+       IF( ANY(SHAPE(tabvar) /= (/dim1,dim2/)) ) THEN	   
+          DEALLOCATE(tabvar)   
+          ALLOCATE(tabvar(dim1,dim2))      
+       ENDIF
+    ENDIF
+    !  
+    status=nf90_get_var(ncid,varid,tabvar)     
+    !     
+    status = nf90_close(ncid)
+    !      
+  END SUBROUTINE Read_Ncdf_var2d_Int
+  !           
+  !**************************************************************
+  ! end subroutine Read_Ncdf_var2d_Int
+  !**************************************************************          
+  !    
+
+  !           
+  !**************************************************************
+  !   subroutine Read_Ncdf_var3d_Int
+  !**************************************************************          
+  !      
+  SUBROUTINE Read_Ncdf_var3d_Int(varname,file,tabvar)
+    !      
+    IMPLICIT NONE
+    !       
+    CHARACTER(*),INTENT(in) :: varname,file
+    INTEGER, DIMENSION(:,:,:), POINTER :: tabvar
+    !
+    !local variables
+    !
+    INTEGER, DIMENSION(10) :: dimIDS
+    INTEGER :: dim1,dim2,dim3
+    INTEGER :: status,ncid
+    INTEGER :: varid             
+    !
+    status = nf90_open(file,NF90_NOWRITE,ncid)
+    !      
+    IF (status/=nf90_noerr) THEN    
+       WRITE(*,*)"unable to open netcdf file : ",file
+       STOP
+    ENDIF
+    !     
+    status = nf90_inq_varid(ncid,varname,varid)
+    status=nf90_inquire_variable(ncid,varid,dimids=dimIDS)
+    status=nf90_inquire_dimension(ncid,dimIDS(1),len=dim1)
+    status=nf90_inquire_dimension(ncid,dimIDS(2),len=dim2)  
+    status=nf90_inquire_dimension(ncid,dimIDS(3),len=dim3)          
+    !                
+    IF(.NOT. ASSOCIATED(tabvar)) THEN
+       ALLOCATE(tabvar(dim1,dim2,dim3))  
+    ELSE
+       IF( ANY(SHAPE(tabvar) /= (/dim1,dim2,dim3/)) ) THEN	   
+          DEALLOCATE(tabvar)   
+          ALLOCATE(tabvar(dim1,dim2,dim3))      
+       ENDIF
+    ENDIF
+    ! 
+    status=nf90_get_var(ncid,varid,tabvar)     
+    !     
+    status = nf90_close(ncid)
+    !      
+  END SUBROUTINE Read_Ncdf_var3d_Int
+  !           
+  !**************************************************************
+  ! end subroutine Read_Ncdf_var3d_int
+  !**************************************************************  
+  !
+  !
+  !
+  !**************************************************************
+  !   subroutine Read_Ncdf_var4d_int
+  !**************************************************************          
+  !      
+  SUBROUTINE Read_Ncdf_var4d_Int(varname,file,tabvar)
+    !      
+    IMPLICIT NONE
+    !       
+    CHARACTER(*),INTENT(in) :: varname,file
+    INTEGER, DIMENSION(:,:,:,:), POINTER :: tabvar
+    !
+    !local variables
+    !
+    INTEGER, DIMENSION(10) :: dimIDS
+    INTEGER :: dim1,dim2,dim3,dim4
+    INTEGER :: status,ncid
+    INTEGER :: varid             
+    !
+    status = nf90_open(file,NF90_NOWRITE,ncid)
+    !      
+    IF (status/=nf90_noerr) THEN    
+       WRITE(*,*)"unable to open netcdf file : ",file
+       STOP
+    ENDIF
+    !     
+    status = nf90_inq_varid(ncid,varname,varid)
+    status=nf90_inquire_variable(ncid,varid,dimids=dimIDS)
+    status=nf90_inquire_dimension(ncid,dimIDS(1),len=dim1)
+    status=nf90_inquire_dimension(ncid,dimIDS(2),len=dim2)  
+    status=nf90_inquire_dimension(ncid,dimIDS(3),len=dim3)   
+    status=nf90_inquire_dimension(ncid,dimIDS(4),len=dim4)       
+    !                
+    IF(.NOT. ASSOCIATED(tabvar)) THEN
+       ALLOCATE(tabvar(dim1,dim2,dim3,dim4))  
+    ELSE
+       IF( ANY(SHAPE(tabvar) /= (/dim1,dim2,dim3,dim4/)) ) THEN	   
+          DEALLOCATE(tabvar)   
+          ALLOCATE(tabvar(dim1,dim2,dim3,dim4))      
+       ENDIF
+    ENDIF
+    !  
+    status=nf90_get_var(ncid,varid,tabvar)     
+    !     
+    status = nf90_close(ncid)
+    !     
+  END SUBROUTINE Read_Ncdf_var4d_Int
+  !           
+  !**************************************************************
+  ! end subroutine Read_Ncdf_var4d_real
+  !**************************************************************         
+  !    
+  !
+  !****************************************************************
+  !   subroutine Write_Ncdf_var					*
+  !								*
+  ! subroutine to write a variable in a given file 		*
+  !								*
+  !     varname : name of variable to store			*     
+  !     dimname : name of dimensions of the given variable	*
+  !     file    : netcdf file name				*
+  !     tabvar  : values of the variable to write			*
+  !								*
+  !****************************************************************
+  !    
+  !      
+  !**************************************************************
+  !   subroutine Write_Ncdf_var1d_real
+  !**************************************************************    
+  !      
+  SUBROUTINE Write_Ncdf_var1d_Real(varname,dimname,file,tabvar,typevar)
+    !      
+    IMPLICIT NONE
+    !       
+    CHARACTER(*),INTENT(in) :: varname,file,dimname,typevar
+    REAL*8, DIMENSION(:), POINTER :: tabvar
+    !
+    ! local variables
+    !
+    INTEGER :: dimid
+    INTEGER :: status,ncid
+    INTEGER :: varid             
+    !
+    status = nf90_open(file,NF90_WRITE,ncid)       
+    IF (status/=nf90_noerr) THEN    
+       WRITE(*,*)"unable to open netcdf file : ",file
+       STOP
+    ENDIF
+    !     
+    status = nf90_inq_dimid(ncid,dimname, dimid)
+    status = nf90_inq_varid(ncid,varname,varid)
+    status = nf90_redef(ncid)
+    SELECT CASE(TRIM(typevar))
+    CASE('double')
+       status = nf90_def_var(ncid,varname,nf90_double,(/dimid/),varid)
+    CASE('float')
+       status = nf90_def_var(ncid,varname,nf90_float,(/dimid/),varid)      
+    END SELECT
+    status = nf90_enddef(ncid)
+    status = nf90_put_var(ncid,varid,tabvar)     
+    !     
+    status = nf90_close(ncid)
+    ! 
+  END SUBROUTINE Write_Ncdf_var1d_Real
+  !      
+  !**************************************************************
+  !   end subroutine Write_Ncdf_var1d_real
+  !**************************************************************
+  !      
+  !**************************************************************
+  !   subroutine Write_Ncdf_var2d_real
+  !**************************************************************    
+  !      
+  SUBROUTINE Write_Ncdf_var2d_Real_bis(varname,dimname,file,tabvar,nbdim,typevar)
+    !      
+    IMPLICIT NONE
+    !       
+    CHARACTER(*),INTENT(in) :: varname,file,typevar
+    INTEGER,INTENT(in) :: nbdim
+    CHARACTER(*), DIMENSION(4) :: dimname
+    REAL*8, DIMENSION(:,:) :: tabvar
+    REAL*8, DIMENSION(:,:,:),POINTER :: tabtemp3d
+    REAL*8, DIMENSION(:,:,:,:),POINTER :: tabtemp4d
+    !
+    ! local variables
+    !
+    INTEGER :: dimid1,dimid2,dimid3,dimid4
+    INTEGER :: status,ncid,ncid2
+    INTEGER :: varid,varid2             
+    ! 
+    IF(nbdim==4) THEN      
+       ALLOCATE(tabtemp4d(SIZE(tabvar,1),SIZE(tabvar,2),1,1))
+       tabtemp4d(:,:,1,1) = tabvar(:,:)
+    ELSE IF(nbdim==3) THEN
+       ALLOCATE(tabtemp3d(SIZE(tabvar,1),SIZE(tabvar,2),1))
+       tabtemp3d(:,:,1) = tabvar(:,:)
+    END IF
+    !      
+    status = nf90_open(file,NF90_WRITE,ncid)       
+    IF (status/=nf90_noerr) THEN    
+       WRITE(*,*)"unable to open netcdf file : ",file
+       STOP
+    ENDIF
+    !     
+    status = nf90_inq_dimid(ncid,dimname(1), dimid1)
+    status = nf90_inq_dimid(ncid,dimname(2), dimid2)
+    status = nf90_inq_dimid(ncid,dimname(3), dimid3)
+    !      
+    IF(nbdim==4) status = nf90_inq_dimid(ncid,dimname(4), dimid4)
+    !      
+    status = nf90_inq_varid(ncid,varname,varid)
+    status = nf90_redef(ncid)
+    IF(nbdim==4 .AND. typevar == 'double') THEN
+       status = nf90_def_var(ncid,varname,nf90_double,     &
+            (/dimid1,dimid2,dimid3,dimid4/),varid)
+       !                              
+    ELSE IF(nbdim==4 .AND. typevar == 'float') THEN
+       status = nf90_def_var(ncid,varname,nf90_float,     &
+            (/dimid1,dimid2,dimid3,dimid4/),varid)                        
+       !          
+    ELSE IF(nbdim==3 .AND. typevar == 'float') THEN
+       status = nf90_def_var(ncid,varname,nf90_float,     &
+            (/dimid1,dimid2,dimid3/),varid)
+       !
+    ELSE IF(nbdim==3 .AND. typevar == 'double') THEN
+       status = nf90_def_var(ncid,varname,nf90_double,     &
+            (/dimid1,dimid2,dimid3/),varid)
+       !     			      			      
+    ENDIF
+    !      			      
+    status = nf90_enddef(ncid)
+    IF(nbdim==4) status = nf90_put_var(ncid,varid,tabtemp4d)
+    IF(nbdim==3) status = nf90_put_var(ncid,varid,tabtemp3d)
+    !      
+    IF(ASSOCIATED( tabtemp3d ) ) DEALLOCATE( tabtemp3d )   
+    IF(ASSOCIATED( tabtemp4d ) ) DEALLOCATE( tabtemp4d )     
+    !
+    status = nf90_close(ncid)
+    ! 
+  END SUBROUTINE Write_Ncdf_var2d_Real_bis
+  !      
+  !**************************************************************
+  !   end subroutine Write_Ncdf_var2d_real
+  !**************************************************************  
+  !   
+  !      
+  !**************************************************************
+  !   subroutine Write_Ncdf_var2d_real
+  !**************************************************************    
+  !      
+  SUBROUTINE Write_Ncdf_var2d_Real(varname,dimname,file,tabvar,typevar)
+    !      
+    !      implicit none
+    !       
+    CHARACTER(*),INTENT(in) :: varname,file,typevar
+    CHARACTER(*), DIMENSION(2) :: dimname
+    REAL*8, DIMENSION(:,:), POINTER :: tabvar
+    !
+    ! local variables
+    !
+    INTEGER :: dimid1,dimid2
+    INTEGER :: status,ncid
+    INTEGER :: varid             
+    !
+    status = nf90_open(file,NF90_WRITE,ncid)       
+    IF (status/=nf90_noerr) THEN    
+       WRITE(*,*)"unable to open netcdf file : ",file
+       STOP
+    ENDIF
+    !     
+    status = nf90_inq_dimid(ncid,dimname(1), dimid1)
+    status = nf90_inq_dimid(ncid,dimname(2), dimid2)
+    status = nf90_inq_varid(ncid,varname,varid)
+    status = nf90_redef(ncid)
+
+    SELECT CASE(TRIM(typevar))
+    CASE('double')
+       status = nf90_def_var(ncid,varname,nf90_double,     &
+            (/dimid1,dimid2/),varid)
+    CASE('float')
+       status = nf90_def_var(ncid,varname,nf90_float,     &
+            (/dimid1,dimid2/),varid)     
+    END SELECT
+    !
+    status = nf90_enddef(ncid)
+    status = nf90_put_var(ncid,varid,tabvar)     
+    !     
+    status = nf90_close(ncid)
+    ! 
+  END SUBROUTINE Write_Ncdf_var2d_Real
+  !      
+  !**************************************************************
+  !   end subroutine Write_Ncdf_var2d_real
+  !**************************************************************  
+  !
+  !      
+  !**************************************************************
+  !   subroutine Write_Ncdf_var3d_real
+  !**************************************************************
+  !      
+  SUBROUTINE Write_Ncdf_var3d_Real(varname,dimname,file,tabvar,typevar)
+    !      
+    IMPLICIT NONE
+    !       
+    CHARACTER(*),INTENT(in) :: varname,file,typevar
+    CHARACTER(*),DIMENSION(3),INTENT(in) :: dimname
+    REAL*8, DIMENSION(:,:,:), POINTER :: tabvar
+    !
+    ! local variables
+    !
+    INTEGER :: dimid1,dimid2,dimid3
+    INTEGER :: status,ncid
+    INTEGER :: varid             
+    !
+    status = nf90_open(file,NF90_WRITE,ncid)       
+    IF (status/=nf90_noerr) THEN    
+       WRITE(*,*)"unable to open netcdf file : ",file
+       STOP
+    ENDIF
+    !     
+    status = nf90_inq_dimid(ncid,dimname(1), dimid1)
+    status = nf90_inq_dimid(ncid,dimname(2), dimid2)
+    status = nf90_inq_dimid(ncid,dimname(3), dimid3)
+    status = nf90_inq_varid(ncid,varname,varid)
+    status = nf90_redef(ncid)
+
+    SELECT CASE(TRIM(typevar))
+    CASE('double')
+       status = nf90_def_var(ncid,varname,nf90_double,     &
+            (/dimid1,dimid2,dimid3/),varid)
+    CASE('float')
+       status = nf90_def_var(ncid,varname,nf90_float,     &
+            (/dimid1,dimid2,dimid3/),varid)    
+    END SELECT
+    !
+    status = nf90_enddef(ncid)
+    status = nf90_put_var(ncid,varid,tabvar)     
+    !     
+    status = nf90_close(ncid)
+    ! 
+  END SUBROUTINE Write_Ncdf_var3d_Real
+  !      
+  !**************************************************************
+  !   end subroutine Write_Ncdf_var3d_real
+  !**************************************************************
+  ! 
+  !
+  !**************************************************************
+  !   subroutine Write_Ncdf_var4d_real
+  !**************************************************************
+  !      
+  SUBROUTINE Write_Ncdf_var4d_Real(varname,dimname,file,tabvar,typevar)
+    !      
+    IMPLICIT NONE
+    !       
+    CHARACTER(*),INTENT(in) :: varname,file,typevar
+    CHARACTER(*),DIMENSION(4),INTENT(in) :: dimname
+    REAL*8, DIMENSION(:,:,:,:), POINTER :: tabvar
+    !
+    ! local variables
+    !
+    INTEGER :: dimid1,dimid2,dimid3,dimid4
+    INTEGER :: status,ncid
+    INTEGER :: varid             
+    !
+    status = nf90_open(file,NF90_WRITE,ncid)       
+    IF (status/=nf90_noerr) THEN    
+       WRITE(*,*)"unable to open netcdf file : ",file
+       STOP
+    ENDIF
+    !
+    status = nf90_inq_varid(ncid,varname,varid)
+    !      
+    IF(status/=nf90_noerr) THEN
+       !     
+       status = nf90_inq_dimid(ncid,dimname(1), dimid1)
+       status = nf90_inq_dimid(ncid,dimname(2), dimid2)
+       status = nf90_inq_dimid(ncid,dimname(3), dimid3)
+       status = nf90_inq_dimid(ncid,dimname(4), dimid4)
+       status = nf90_redef(ncid)
+       !      
+       SELECT CASE(TRIM(typevar))
+       CASE('double')
+          status = nf90_def_var(ncid,varname,nf90_double,     &
+               (/dimid1,dimid2,dimid3,dimid4/),varid)
+       CASE('float')
+          status = nf90_def_var(ncid,varname,nf90_float,     &
+               (/dimid1,dimid2,dimid3,dimid4/),varid)   
+       END SELECT
+       !
+       status = nf90_enddef(ncid)
+    ENDIF
+    !         
+    status = nf90_put_var(ncid,varid,tabvar)     
+    !     
+    status = nf90_close(ncid)
+    ! 
+  END SUBROUTINE Write_Ncdf_var4d_Real
+  !      
+  !**************************************************************
+  !   end subroutine Write_Ncdf_var4d_real
+  !**************************************************************
+  !
+  !
+  !  
+  !**************************************************************
+  !   subroutine Write_Ncdf_var1d_Int
+  !**************************************************************    
+  !      
+  SUBROUTINE Write_Ncdf_var1d_Int(varname,dimname,file,tabvar)
+    !      
+    IMPLICIT NONE
+    !       
+    CHARACTER(*),INTENT(in) :: varname,file,dimname
+    INTEGER, DIMENSION(:), POINTER :: tabvar
+    !
+    ! local variables
+    !
+    INTEGER :: dimid
+    INTEGER :: status,ncid
+    INTEGER :: varid             
+    !
+    !           print *,'ici tabvar = ',tabvar,varname,dimname
+    status = nf90_open(file,NF90_WRITE,ncid)       
+    IF (status/=nf90_noerr) THEN    
+       WRITE(*,*)"unable to open netcdf file : ",file
+       STOP
+    ENDIF
+    !     
+    status = nf90_inq_dimid(ncid,dimname, dimid)
+    status = nf90_inq_varid(ncid,varname,varid)
+    status = nf90_redef(ncid)
+    status = nf90_def_var(ncid,varname,nf90_int,(/dimid/),varid)
+    status = nf90_enddef(ncid)
+    status = nf90_put_var(ncid,varid,tabvar)     
+    !     
+    status = nf90_close(ncid)
+    ! 
+  END SUBROUTINE Write_Ncdf_var1d_Int
+  !      
+  !**************************************************************
+  !   end subroutine Write_Ncdf_var1d_Int
+  !**************************************************************
+  !  
+  !      
+  !**************************************************************
+  !   subroutine Write_Ncdf_var2d_Int
+  !**************************************************************    
+  !      
+  SUBROUTINE Write_Ncdf_var2d_Int(varname,dimname,file,tabvar)
+    !      
+    IMPLICIT NONE
+    !       
+    CHARACTER(*),INTENT(in) :: varname,file
+    CHARACTER(*), DIMENSION(2) :: dimname
+    INTEGER, DIMENSION(:,:), POINTER :: tabvar
+    !
+    ! local variables
+    !
+    INTEGER :: dimid1,dimid2
+    INTEGER :: status,ncid
+    INTEGER :: varid             
+    !
+    status = nf90_open(file,NF90_WRITE,ncid)       
+    IF (status/=nf90_noerr) THEN    
+       WRITE(*,*)"unable to open netcdf file : ",file
+       STOP
+    ENDIF
+    !     
+    status = nf90_inq_dimid(ncid,dimname(1), dimid1)
+    status = nf90_inq_dimid(ncid,dimname(2), dimid2)
+    status = nf90_inq_varid(ncid,varname,varid)
+    status = nf90_redef(ncid)
+    status = nf90_def_var(ncid,varname,nf90_int,     &
+         (/dimid1,dimid2/),varid)
+    status = nf90_enddef(ncid)
+    status = nf90_put_var(ncid,varid,tabvar)     
+    !     
+    status = nf90_close(ncid)
+    ! 
+  END SUBROUTINE Write_Ncdf_var2d_Int
+  !      
+  !**************************************************************
+  !   end subroutine Write_Ncdf_var2d_Int
+  !**************************************************************  
+  ! 
+  !      
+  !**************************************************************
+  !   subroutine Write_Ncdf_var3d_Int
+  !**************************************************************
+  !      
+  SUBROUTINE Write_Ncdf_var3d_Int(varname,dimname,file,tabvar)
+    !      
+    IMPLICIT NONE
+    !       
+    CHARACTER(*),INTENT(in) :: varname,file
+    CHARACTER(*),DIMENSION(3),INTENT(in) :: dimname
+    INTEGER, DIMENSION(:,:,:), POINTER :: tabvar
+    !
+    ! local variables
+    !
+    INTEGER :: dimid1,dimid2,dimid3
+    INTEGER :: status,ncid
+    INTEGER :: varid             
+    !
+    status = nf90_open(file,NF90_WRITE,ncid)       
+    IF (status/=nf90_noerr) THEN    
+       WRITE(*,*)"unable to open netcdf file : ",file
+       STOP
+    ENDIF
+    !     
+    status = nf90_inq_dimid(ncid,dimname(1), dimid1)
+    status = nf90_inq_dimid(ncid,dimname(2), dimid2)
+    status = nf90_inq_dimid(ncid,dimname(3), dimid3)
+    status = nf90_inq_varid(ncid,varname,varid)
+    status = nf90_redef(ncid)
+    status = nf90_def_var(ncid,varname,nf90_int,     &
+         (/dimid1,dimid2,dimid3/),varid)
+    status = nf90_enddef(ncid)
+    status = nf90_put_var(ncid,varid,tabvar)     
+    !     
+    status = nf90_close(ncid)
+    ! 
+  END SUBROUTINE Write_Ncdf_var3d_Int
+  !      
+  !**************************************************************
+  !   end subroutine Write_Ncdf_var3d_Int
+  !**************************************************************
+  ! 
+  !
+  !**************************************************************
+  !   subroutine Write_Ncdf_var4d_Int
+  !**************************************************************
+  !      
+  SUBROUTINE Write_Ncdf_var4d_Int(varname,dimname,file,tabvar)
+    !      
+    IMPLICIT NONE
+    !       
+    CHARACTER(*),INTENT(in) :: varname,file
+    CHARACTER(*),DIMENSION(4),INTENT(in) :: dimname
+    INTEGER, DIMENSION(:,:,:,:), POINTER :: tabvar
+    !
+    ! local variables
+    !
+    INTEGER :: dimid1,dimid2,dimid3,dimid4
+    INTEGER :: status,ncid
+    INTEGER :: varid             
+    !
+    status = nf90_open(file,NF90_WRITE,ncid)       
+    IF (status/=nf90_noerr) THEN    
+       WRITE(*,*)"unable to open netcdf file : ",file
+       STOP
+    ENDIF
+    !     
+    status = nf90_inq_dimid(ncid,dimname(1), dimid1)
+    status = nf90_inq_dimid(ncid,dimname(2), dimid2)
+    status = nf90_inq_dimid(ncid,dimname(3), dimid3)
+    status = nf90_inq_dimid(ncid,dimname(4), dimid4)
+    status = nf90_inq_varid(ncid,varname,varid)
+    status = nf90_redef(ncid)
+    status = nf90_def_var(ncid,varname,nf90_int,     &
+         (/dimid1,dimid2,dimid3,dimid4/),varid)
+    status = nf90_enddef(ncid)
+    status = nf90_put_var(ncid,varid,tabvar)     
+    !     
+    status = nf90_close(ncid)
+    ! 
+  END SUBROUTINE Write_Ncdf_var4d_Int
+  !      
+  !**************************************************************
+  !   end subroutine Write_Ncdf_var4d_Int
+  !************************************************************** 
+  !
+  !
+  !****************************************************************
+  !   subroutine Read_Ncdf_var_t					*
+  !								*
+  ! subroutine to read a variable in a given file for time t	*
+  !								*
+  !     varname : name of variable to read			*     
+  !     file    : netcdf file name				*
+  !     tabvar  : values of the read variable			*
+  !     time    : time corresponding to the values to read	*	
+  !								*
+  !****************************************************************
+  !
+  !
+  !**************************************************************
+  !   subroutine Read_Ncdf_var3d_real_t
+  !**************************************************************          
+  !      
+  SUBROUTINE Read_Ncdf_var3d_Real_t(varname,file,tabvar,time)
+    !      
+    USE agrif_types     
+    !      
+    IMPLICIT NONE
+    !       
+    CHARACTER(*),INTENT(in) :: varname,file
+    INTEGER,INTENT(in) :: time
+    REAL*8, DIMENSION(:,:,:), POINTER :: tabvar
+    !
+    !local variables
+    !
+    INTEGER, DIMENSION(3) :: dimIDS
+    INTEGER :: dim1,dim2
+    INTEGER :: status,ncid
+    INTEGER :: varid             
+    !
+    status = nf90_open(file,NF90_NOWRITE,ncid)
+    !      
+    IF (status/=nf90_noerr) THEN    
+       WRITE(*,*)"unable to open netcdf file : ",file
+       STOP
+    ENDIF
+    !     
+    status = nf90_inq_varid(ncid,varname,varid)
+    !        
+    status=nf90_inquire_variable(ncid,varid,dimids=dimIDS)
+    status=nf90_inquire_dimension(ncid,dimIDS(1),len=dim1)
+    status=nf90_inquire_dimension(ncid,dimIDS(2),len=dim2)
+    !
+    IF(.NOT. ASSOCIATED(tabvar)) THEN
+       ALLOCATE(tabvar(dim1,dim2,1))  
+    ELSE
+       IF( ANY(SHAPE(tabvar) /= (/dim1,dim2,1/)) ) THEN	   
+          DEALLOCATE(tabvar)   
+          ALLOCATE(tabvar(dim1,dim2,1))      
+       ENDIF
+    ENDIF
+
+    status=nf90_get_var(ncid,varid,tabvar,start=(/1,1,time/))
+
+    IF (status/=nf90_noerr) THEN    
+       WRITE(*,*)"unable to retrieve netcdf variable : ",TRIM(varname)
+       STOP
+    ENDIF
+    !     
+    status = nf90_close(ncid)
+    !     
+  END SUBROUTINE Read_Ncdf_var3d_Real_t
+  !           
+  !**************************************************************
+  ! end subroutine Read_Ncdf_var3d_real_t
+  !**************************************************************          
+  !
+  !
+  !
+  !****************************************************************
+  !   subroutine Write_Ncdf_var_t					*
+  !								*
+  ! subroutine to write a variable in a given file for time t	*
+  !								*
+  !     varname : name of variable to store			*     
+  !     dimname : name of dimensions of the given variable	*
+  !     file    : netcdf file name				*
+  !     tabvar  : values of the variable to write			*
+  !     time    : time corresponding to the values to store	*	
+  !								*
+  !****************************************************************
+  !
+  !      
+  !**************************************************************
+  !   subroutine Write_Ncdf_var3d_real_t
+  !**************************************************************
+  !      
+  SUBROUTINE Write_Ncdf_var3d_Real_t(varname,dimname,file,tabvar,time,typevar)
+    !      
+    IMPLICIT NONE
+    !       
+    CHARACTER(*),INTENT(in) :: varname,file,typevar
+    CHARACTER(*),DIMENSION(3),INTENT(in) :: dimname
+    INTEGER :: time
+    REAL*8, DIMENSION(:,:,:), POINTER :: tabvar
+    !
+    ! local variables
+    !
+    INTEGER :: dimid1,dimid2,dimid3
+    INTEGER :: status,ncid
+    INTEGER :: varid             
+    !
+    status = nf90_open(file,NF90_WRITE,ncid)       
+    IF (status/=nf90_noerr) THEN    
+       WRITE(*,*)"unable to open netcdf file : ",file
+       STOP
+    ENDIF
+    !     
+    IF(time==1) THEN
+       !      
+       status = nf90_inq_dimid(ncid,dimname(1), dimid1)
+       status = nf90_inq_dimid(ncid,dimname(2), dimid2)
+       status = nf90_inq_dimid(ncid,dimname(3), dimid3)
+       status = nf90_redef(ncid)
+
+       !      
+       SELECT CASE(TRIM(typevar))
+       CASE('double')
+          status = nf90_def_var(ncid,varname,nf90_double,     &
+               (/dimid1,dimid2,dimid3/),varid) 
+       CASE('float')
+          status = nf90_def_var(ncid,varname,nf90_float,     &
+               (/dimid1,dimid2,dimid3/),varid)    
+       END SELECT
+       !
+       status = nf90_enddef(ncid)
+
+    ELSE
+       status = nf90_inq_varid(ncid, varname, varid)
+    ENDIF
+    !      
+    status = nf90_put_var(ncid,varid,tabvar,start=(/1,1,time/))
+    IF (status/=nf90_noerr) THEN    
+       WRITE(*,*)"unable to store variable ",varname, &
+	    " in file ",file
+       STOP
+    ENDIF
+    !     
+    status = nf90_close(ncid)
+    ! 
+  END SUBROUTINE Write_Ncdf_var3d_Real_t
+  !      
+  !**************************************************************
+  !   end subroutine Write_Ncdf_var3d_real_t
+  !**************************************************************
+  !
+  !
+  !****************************************************************
+  !   subroutine Read_Ncdf_var_t					*
+  !								*
+  ! subroutine to read a variable in a given file for time t	*
+  !						at level n	*
+  !     varname : name of variable to read			*     
+  !     file    : netcdf file name				*
+  !     tabvar  : values of the read variable			*
+  !     time    : time corresponding to the values to read	*	
+  !     level   : level corresponding to the values to read	*
+  !								*
+  !****************************************************************
+  !
+  !
+  !**************************************************************
+  !   subroutine Read_Ncdf_var4d_real_nt
+  !**************************************************************          
+  !      
+  SUBROUTINE Read_Ncdf_var4d_Real_nt(varname,file,tabvar,time,level)
+    !      
+    USE agrif_types     
+    !      
+    IMPLICIT NONE
+    !       
+    CHARACTER(*),INTENT(in) :: varname,file
+    INTEGER,INTENT(in) :: time,level
+    REAL*8, DIMENSION(:,:,:,:), POINTER :: tabvar
+    !
+    !local variables
+    !
+    INTEGER, DIMENSION(4) :: dimIDS
+    INTEGER :: dim1,dim2
+    INTEGER :: status,ncid
+    INTEGER :: varid             
+    !
+    status = nf90_open(file,NF90_NOWRITE,ncid)
+    !      
+    IF (status/=nf90_noerr) THEN    
+       WRITE(*,*)"unable to open netcdf file : ",file
+       STOP
+    ENDIF
+    !     
+    status = nf90_inq_varid(ncid,varname,varid)
+    !        
+    status=nf90_inquire_variable(ncid,varid,dimids=dimIDS)
+    status=nf90_inquire_dimension(ncid,dimIDS(1),len=dim1)
+    status=nf90_inquire_dimension(ncid,dimIDS(2),len=dim2)
+    !
+    IF(.NOT. ASSOCIATED(tabvar)) THEN
+       ALLOCATE(tabvar(dim1,dim2,1,1))  
+    ELSE
+       IF ((SIZE(tabvar,1) /= dim1) .OR. (SIZE(tabvar,2) /= dim2)) THEN
+          DEALLOCATE(tabvar)
+          ALLOCATE(tabvar(dim1,dim2,1,1))
+       ENDIF
+    ENDIF
+    !
+    status=nf90_get_var(ncid,varid,tabvar,start=(/1,1,level,time/),count=(/dim1,dim2,1,1/))
+    !                                             
+    IF (status/=nf90_noerr) THEN    
+       WRITE(*,*)"unable to retrieve netcdf variable : ",TRIM(varname)
+       STOP
+    ENDIF
+    !     
+    status = nf90_close(ncid)
+    !     
+  END SUBROUTINE Read_Ncdf_var4d_Real_nt
+  !           
+  !**************************************************************
+  ! end subroutine Read_Ncdf_var4d_real_nt
+  !**************************************************************          
+  !
+  !
+  !**************************************************************
+  !   subroutine Read_Ncdf_var4d_real_t
+  !**************************************************************          
+  !      
+  SUBROUTINE Read_Ncdf_var4d_Real_t(varname,file,tabvar,time)
+    !      
+    USE agrif_types     
+    !      
+    IMPLICIT NONE
+    !       
+    CHARACTER(*),INTENT(in) :: varname,file
+    INTEGER,INTENT(in) :: time
+    REAL*8, DIMENSION(:,:,:,:), POINTER :: tabvar
+    !
+    !local variables
+    !
+    INTEGER, DIMENSION(4) :: dimIDS
+    INTEGER :: dim1,dim2,dim3
+    INTEGER :: status,ncid
+    INTEGER :: varid             
+    !
+    status = nf90_open(file,NF90_NOWRITE,ncid)
+    !      
+    IF (status/=nf90_noerr) THEN    
+       WRITE(*,*)"unable to open netcdf file : ",file
+       STOP
+    ENDIF
+    !     
+    status = nf90_inq_varid(ncid,varname,varid)
+    !        
+    status=nf90_inquire_variable(ncid,varid,dimids=dimIDS)
+    status=nf90_inquire_dimension(ncid,dimIDS(1),len=dim1)
+    status=nf90_inquire_dimension(ncid,dimIDS(2),len=dim2)
+    status=nf90_inquire_dimension(ncid,dimIDS(3),len=dim3)
+    !
+    IF(.NOT. ASSOCIATED(tabvar)) ALLOCATE(tabvar(dim1,dim2,dim3,1))  
+    status=nf90_get_var(ncid,varid,tabvar,start=(/1,1,1,time/))
+
+    IF (status/=nf90_noerr) THEN    
+       WRITE(*,*)"unable to retrieve netcdf variable : ",TRIM(varname)
+       STOP
+    ENDIF
+    !     
+    status = nf90_close(ncid)
+    !     
+  END SUBROUTINE Read_Ncdf_var4d_Real_t
+  !           
+  !**************************************************************
+  ! end subroutine Read_Ncdf_var4d_real_t
+  !**************************************************************          
+  !
+  !
+  !****************************************************************
+  !   subroutine Write_Ncdf_var_t					*
+  !								*
+  ! subroutine to write a variable in a given file for time t	*
+  !						at level n	*
+  !     varname : name of variable to store			*     
+  !     dimname : name of dimensions of the given variable	*
+  !     file    : netcdf file name				*
+  !     tabvar  : values of the variable to write			*
+  !     time    : time corresponding to the values to store	*	
+  !     level   : level corresponding to the values to store	*
+  !								*
+  !****************************************************************
+  !
+  !      
+  !**************************************************************
+  !   subroutine Write_Ncdf_var4d_real_t
+  !**************************************************************
+  !      
+  SUBROUTINE Write_Ncdf_var4d_Real_t(varname,dimname,file,tabvar,time,typevar)
+    !      
+    IMPLICIT NONE
+    !       
+    CHARACTER(*),INTENT(in) :: varname,file,typevar
+    CHARACTER(*),DIMENSION(4),INTENT(in) :: dimname
+    INTEGER :: time,level
+    REAL*8, DIMENSION(:,:,:,:), POINTER :: tabvar
+    !
+    ! local variables
+    !
+    INTEGER :: dimid1,dimid2,dimid3,dimid4
+    INTEGER :: status,ncid
+    INTEGER :: varid             
+    !
+    status = nf90_open(file,NF90_WRITE,ncid)       
+    IF (status/=nf90_noerr) THEN    
+       WRITE(*,*)"unable to open netcdf file : ",file
+       STOP
+    ENDIF
+    !      
+    IF(time==1) THEN
+       !      
+       status = nf90_inq_dimid(ncid,dimname(1), dimid1)
+       status = nf90_inq_dimid(ncid,dimname(2), dimid2)
+       status = nf90_inq_dimid(ncid,dimname(3), dimid3)
+       status = nf90_inq_dimid(ncid,dimname(4), dimid4)
+       status = nf90_redef(ncid)
+       !      
+       SELECT CASE(TRIM(typevar))
+       CASE('double')
+          status = nf90_def_var(ncid,TRIM(varname),nf90_double,     &
+               (/dimid1,dimid2,dimid3,dimid4/),varid)  
+       CASE('float')
+          status = nf90_def_var(ncid,TRIM(varname),nf90_float,     &
+               (/dimid1,dimid2,dimid3,dimid4/),varid)    
+       END SELECT
+       !
+       status = nf90_enddef(ncid)
+
+    ELSE
+       status = nf90_inq_varid(ncid, varname, varid)
+    ENDIF
+    !    
+    status = nf90_put_var(ncid,varid,tabvar,start=(/1,1,1,time/))
+    IF (status/=nf90_noerr) THEN    
+       WRITE(*,*)"unable to store variable ",varname, &
+	    " in file ",file
+       STOP
+    ENDIF
+    !    
+    status = nf90_close(ncid)
+    ! 
+  END SUBROUTINE Write_Ncdf_var4d_Real_t
+  !      
+  !**************************************************************
+  !   end subroutine Write_Ncdf_var4d_real_t
+  !**************************************************************
+  !
+  !      
+  !**************************************************************
+  !   subroutine Write_Ncdf_var4d_real_nt
+  !**************************************************************
+  !      
+  SUBROUTINE Write_Ncdf_var4d_Real_nt(varname,dimname,file,tabvar,time,level,typevar)
+    !      
+    IMPLICIT NONE
+    !       
+    CHARACTER(*),INTENT(in) :: varname,file,typevar
+    CHARACTER(*),DIMENSION(4),INTENT(in) :: dimname
+    INTEGER :: time,level
+    REAL*8, DIMENSION(:,:,:,:), POINTER :: tabvar
+    !
+    ! local variables
+    !
+    INTEGER :: dimid1,dimid2,dimid3,dimid4
+    INTEGER :: status,ncid
+    INTEGER :: varid             
+    !
+    status = nf90_open(file,NF90_WRITE,ncid)       
+    IF (status/=nf90_noerr) THEN    
+       WRITE(*,*)"unable to open netcdf file : ",file
+       STOP
+    ENDIF
+    !      
+    IF(time==1.AND.level==1) THEN
+       !      
+       status = nf90_inq_dimid(ncid,dimname(1), dimid1)
+       status = nf90_inq_dimid(ncid,dimname(2), dimid2)
+       status = nf90_inq_dimid(ncid,dimname(3), dimid3)
+       status = nf90_inq_dimid(ncid,dimname(4), dimid4)
+       status = nf90_redef(ncid)
+       !      
+       SELECT CASE(TRIM(typevar))
+       CASE('double')
+          status = nf90_def_var(ncid,TRIM(varname),nf90_double,     &
+               (/dimid1,dimid2,dimid3,dimid4/),varid)  
+       CASE('float')
+          status = nf90_def_var(ncid,TRIM(varname),nf90_float,     &
+               (/dimid1,dimid2,dimid3,dimid4/),varid)    
+       END SELECT
+       !
+       status = nf90_enddef(ncid)
+
+    ELSE
+       status = nf90_inq_varid(ncid, varname, varid)
+    ENDIF
+    !    
+    status = nf90_put_var(ncid,varid,tabvar,start=(/1,1,level,time/))
+    IF (status/=nf90_noerr) THEN    
+       WRITE(*,*)"unable to store variable ",varname, &
+	    " in file ",file
+       STOP
+    ENDIF
+    !    
+    status = nf90_close(ncid)
+    ! 
+  END SUBROUTINE Write_Ncdf_var4d_Real_nt
+
+  SUBROUTINE Write_Ncdf_var0d_Real(varname,file,tabvar,typevar)
+    !      
+    IMPLICIT NONE
+    !       
+    CHARACTER(*),INTENT(in) :: varname,file,typevar
+    INTEGER :: time,level
+    REAL*8 :: tabvar
+    !
+    ! local variables
+    !
+    INTEGER :: status,ncid
+    INTEGER :: varid             
+    !
+    status = nf90_open(file,NF90_WRITE,ncid)       
+    IF (status/=nf90_noerr) THEN    
+       WRITE(*,*)"unable to open netcdf file : ",file
+       STOP
+    ENDIF
+    !      
+
+    status = nf90_redef(ncid)
+    !      
+    SELECT CASE(TRIM(typevar))
+    CASE('double')
+       status = nf90_def_var(ncid,TRIM(varname),nf90_double,     &
+            varid=varid)  
+    CASE('float')
+       status = nf90_def_var(ncid,TRIM(varname),nf90_float,     &
+            varid=varid)    
+    END SELECT
+    !
+    status = nf90_enddef(ncid)
+
+    !    
+    status = nf90_put_var(ncid,varid,tabvar)
+    IF (status/=nf90_noerr) THEN    
+       WRITE(*,*)"unable to store variable ",varname, &
+	    " in file ",file
+       STOP
+    ENDIF
+    !    
+    status = nf90_close(ncid)
+    ! 
+  END SUBROUTINE Write_Ncdf_var0d_Real
+  !      
+  !**************************************************************
+  !   end subroutine Write_Ncdf_var4d_real_nt
+  !**************************************************************
+  !
+  !****************************************************************
+  !   subroutine Read_Ncdf_VarName				*
+  !								*
+  ! subroutine to retrieve of all variables 			*
+  ! included in a given file					*
+  !								*
+  !     filename    : netcdf file name				*
+  !     tabvarname  : array containing various variables names	*
+  !								*
+  !****************************************************************
+  !
+  !**************************************************************
+  !   subroutine Read_Ncdf_VarName
+  !**************************************************************          
+  !
+  SUBROUTINE Read_Ncdf_VarName(filename,tabvarname)
+    !      
+    CHARACTER(*),INTENT(in) :: filename
+    CHARACTER*20,DIMENSION(:),POINTER :: tabvarname
+    INTEGER :: nDimensions,nVariables
+    INTEGER :: nAttributes,unlimitedDimId,i
+    INTEGER :: ncid,status,dimid
+    !     
+    status = nf90_open(filename,NF90_NOWRITE,ncid)
+    IF (status/=nf90_noerr) THEN    
+       WRITE(*,*)"unable to open netcdf file : ",filename
+       STOP
+    ENDIF
+    !      
+    status = nf90_inquire(ncid,nDimensions,nVariables,nAttributes, &                                                      
+         unlimitedDimId) 
+    !
+    ALLOCATE(tabvarname(nVariables))
+    !
+    DO i=1,nVariables
+       status = nf90_inquire_variable(ncid,i,tabvarname(i))
+    END DO
+
+  END SUBROUTINE Read_Ncdf_Varname
+  !
+  !**************************************************************
+  !   end subroutine Read_Ncdf_VarName
+  !**************************************************************          
+  !
+  !**************************************************************
+  !   subroutine Copy_Ncdf_att
+  !**************************************************************          
+  !
+  SUBROUTINE Copy_Ncdf_att_var(varname,filein,fileout)
+    !      
+    CHARACTER(*),INTENT(in) :: filein,fileout
+    CHARACTER(*),INTENT(in) :: varname
+    INTEGER :: ncid_in,ncid_out,status,varid_in,varid_out
+    !     
+    !      print *,'filein = ',filein,fileout
+    status = nf90_open(filein,NF90_NOWRITE,ncid_in)
+    IF (status/=nf90_noerr) THEN    
+       WRITE(*,*)"unable to open input netcdf file : ",filein
+       STOP
+    ENDIF
+    !     							     	   
+    status = nf90_open(fileout,NF90_WRITE,ncid_out)
+    IF (status/=nf90_noerr) THEN    
+       WRITE(*,*)"unable to open output netcdf file : ",fileout
+       STOP
+    ENDIF
+    !  
+    !      print *,'ici1'
+    status = nf90_inq_varid(ncid_in,varname,varid_in)
+    status = nf90_inq_varid(ncid_out,varname,varid_out)
+    !
+    status = nf90_redef(ncid_out)
+    !      
+    status = nf90_copy_att(ncid_in,varid_in,'units',ncid_out,varid_out)
+    status = nf90_copy_att(ncid_in,varid_in,'valid_min',ncid_out,varid_out)
+    status = nf90_copy_att(ncid_in,varid_in,'valid_max',ncid_out,varid_out) 
+    status = nf90_copy_att(ncid_in,varid_in,'long_name',ncid_out,varid_out)
+    status = nf90_copy_att(ncid_in,varid_in,'calendar',ncid_out,varid_out)
+    status = nf90_copy_att(ncid_in,varid_in,'title',ncid_out,varid_out)     
+    status = nf90_copy_att(ncid_in,varid_in,'time_origin',ncid_out,varid_out) 
+    status = nf90_copy_att(ncid_in,varid_in,'positive',ncid_out,varid_out)                 
+    status = nf90_copy_att(ncid_in,varid_in,'tstep_sec',ncid_out,varid_out)          
+    status = nf90_copy_att(ncid_in,varid_in,'nav_model',ncid_out,varid_out)   
+    status = nf90_copy_att(ncid_in,varid_in,'Minvalue=',ncid_out,varid_out)
+    status = nf90_copy_att(ncid_in,varid_in,'Maxvalue=',ncid_out,varid_out)  
+    status = nf90_copy_att(ncid_in,varid_in,'short_name',ncid_out,varid_out)
+    status = nf90_copy_att(ncid_in,varid_in,'online_operation',ncid_out,varid_out)
+    status = nf90_copy_att(ncid_in,varid_in,'axis',ncid_out,varid_out)            
+    status = nf90_copy_att(ncid_in,varid_in,'interval_operation',ncid_out,varid_out)
+    status = nf90_copy_att(ncid_in,varid_in,'interval_write',ncid_out,varid_out) 
+    status = nf90_copy_att(ncid_in,varid_in,'associate',ncid_out,varid_out)
+    status = nf90_copy_att(ncid_in,varid_in,'actual_range',ncid_out,varid_out) 
+    status = nf90_copy_att(ncid_in,varid_in,'longitude',ncid_out,varid_out)
+    status = nf90_copy_att(ncid_in,varid_in,'latitude',ncid_out,varid_out)
+    status = nf90_copy_att(ncid_in,varid_in,'scale_factor',ncid_out,varid_out)
+    status = nf90_copy_att(ncid_in,varid_in,'add_offset',ncid_out,varid_out)
+    status = nf90_copy_att(ncid_in,varid_in,'missing_value',ncid_out,varid_out) 
+    !      
+    status = nf90_enddef(ncid_out)  
+    !
+    status = nf90_close(ncid_in)
+    status = nf90_close(ncid_out)
+    !      print *,'ici2'
+    ! 
+  END SUBROUTINE Copy_Ncdf_att_var
+  !
+  !**************************************************************
+  !   end subroutine Copy_Ncdf_att
+  !**************************************************************         
+  !**************************************************************
+  !   subroutine Copy_Ncdf_att
+  !**************************************************************          
+  !
+  SUBROUTINE Copy_Ncdf_att_latlon(varname,filein,fileout,min,max)
+    !      
+    CHARACTER(*),INTENT(in) :: filein,fileout
+    CHARACTER(*),INTENT(in) :: varname
+    REAL*8 :: min,max
+    INTEGER :: ncid_in,ncid_out,status,varid_in,varid_out
+    !     
+    status = nf90_open(filein,NF90_NOWRITE,ncid_in)
+    IF (status/=nf90_noerr) THEN    
+       WRITE(*,*)"unable to open netcdf file : ",filein
+       STOP
+    ENDIF
+    !     							     	   
+    status = nf90_open(fileout,NF90_WRITE,ncid_out)
+    IF (status/=nf90_noerr) THEN    
+       WRITE(*,*)"unable to open netcdf file : ",fileout
+       STOP
+    ENDIF
+    !  
+    status = nf90_inq_varid(ncid_in,varname,varid_in)
+    status = nf90_inq_varid(ncid_out,varname,varid_out)
+    !
+    status = nf90_redef(ncid_out)
+    !      
+    SELECT CASE (varname)
+       !      
+    CASE('nav_lon')     
+       status = nf90_copy_att(ncid_in,varid_in,'units',ncid_out,varid_out) 
+       status = nf90_put_att(ncid_out,varid_out,'valid_min',REAL(min,4))
+       status = nf90_put_att(ncid_out,varid_out,'valid_max',REAL(max,4))
+       status = nf90_copy_att(ncid_in,varid_in,'long_name',ncid_out,varid_out)
+       status = nf90_copy_att(ncid_in,varid_in,'nav_model',ncid_out,varid_out)
+       status = nf90_copy_att(ncid_in,varid_in,'title',ncid_out,varid_out)
+       !
+    CASE('nav_lat')
+       status = nf90_copy_att(ncid_in,varid_in,'units',ncid_out,varid_out) 
+       status = nf90_put_att(ncid_out,varid_out,'valid_min',REAL(min,4))
+       status = nf90_put_att(ncid_out,varid_out,'valid_max',REAL(max,4))
+       status = nf90_copy_att(ncid_in,varid_in,'long_name',ncid_out,varid_out)
+       status = nf90_copy_att(ncid_in,varid_in,'nav_model',ncid_out,varid_out)
+       status = nf90_copy_att(ncid_in,varid_in,'title',ncid_out,varid_out) 
+       !
+    END SELECT
+    !      
+    status = nf90_enddef(ncid_out)  
+    !
+    status = nf90_close(ncid_in)
+    status = nf90_close(ncid_out)
+  END SUBROUTINE Copy_Ncdf_att_latlon
+  !*************************************************************
+  !**************************************************************
+  !**************************************************************
+  !   function Get_NbDims
+  !**************************************************************          
+  !
+  INTEGER FUNCTION Get_NbDims( varname , filename )
+    !
+    CHARACTER(*),INTENT(in) :: varname,filename
+    INTEGER :: status,ncid,varid    
+    !      
+    status = nf90_open(TRIM(filename),NF90_NOWRITE,ncid)
+    IF (status/=nf90_noerr) THEN    
+       WRITE(*,*)"unable to open netcdf file : ",TRIM(filename)
+       STOP
+    ENDIF
+    status = nf90_inq_varid(ncid,TRIM(varname),varid)     
+    status = nf90_inquire_variable(ncid, varid , ndims = Get_NbDims)
+    !
+    RETURN
+    !
+  END FUNCTION Get_NbDims
+  !
+  !*************************************************************
+  !**************************************************************
+  !   function Get_NbDims
+  !**************************************************************          
+  !
+  LOGICAL FUNCTION Dims_Existence( dimname , filename )
+    !
+    CHARACTER(*),INTENT(in) :: dimname,filename
+    INTEGER :: status,ncid,dimid    
+    !      
+    status = nf90_open(TRIM(filename),NF90_NOWRITE,ncid)
+    IF (status/=nf90_noerr) THEN    
+       WRITE(*,*)"unable to open netcdf file : ",TRIM(filename)
+       STOP
+    ENDIF
+    status = nf90_inq_dimid(ncid,dimname,dimid)
+    !      
+    IF (status/=nf90_noerr) THEN
+       Dims_Existence = .FALSE.
+    ELSE
+       Dims_Existence = .TRUE.
+    ENDIF
+    !
+    RETURN
+    !
+  END FUNCTION Dims_Existence
+  !
+  !*************************************************************
+  !**************************************************************
+END MODULE io_netcdf
Index: /trunk/UTIL/CFG_TOOLS/namelist
===================================================================
--- /trunk/UTIL/CFG_TOOLS/namelist	(revision 1799)
+++ /trunk/UTIL/CFG_TOOLS/namelist	(revision 1799)
@@ -0,0 +1,95 @@
+&input_output
+    iom_activated = true 
+/
+
+&coarse_grid_files    
+    parent_coordinate_file = 'coordinates_ORCA_R05.nc'
+    parent_bathy_level    = 'bathy_level.nc'  
+/    
+    
+&bathymetry    
+! new_topo = true
+    new_topo = false
+    elevation_database = 'bathymetry_meter_ORCA_R05.nc'
+    smoothing = true
+    smoothing_factor = 0.6
+    nb_connection_pts = 3    
+    removeclosedseas = true
+    type_bathy_interp = 0 
+/   
+
+&nesting    
+    imin = 722
+    imax = 3
+    jmin = 50
+    jmax = 52
+    rho  = 2
+								
+    rhot = 2
+    bathy_update = true
+    updated_parent_file = 'bathy_updated.nc'				
+/
+
+&vertical_grid    
+    ppkth = 21.4333619793800
+    ppacr = 3
+    ppdzmin = 0
+    pphmax  = 0
+    psur = -4762.96143546300
+    pa0  = 255.58049070440
+    pa1  = 245.58132232490
+    N  = 31
+/    
+    
+&partial_cells    	
+    partial_steps = true
+    parent_bathy_meter = 'bathy_meter.nc'
+    e3zps_min = 25.
+    e3zps_rat = 0.2
+/
+
+&nemo_coarse_grid    
+    jpizoom = 1			
+    jpjzoom = 1			
+/
+&forcing_files		   
+    U_FILES = taux_1m.nc
+!'dyna_grid_U.nc'                              ! needed for Offline
+    V_FILES =  tauy_1m.nc
+!'dyna_grid_V.nc'                              ! needed for Offline
+    FLX_FILES = 
+    'data_1m_salinity_nomask.nc',
+    'data_1m_potential_temperature_nomask.nc',
+    'flx.nc',
+    'geothermal_heating.nc'
+!    'river.orca.nc ',                         ! needed for Pisces
+!    'ndeposition.orca.nc',                    ! needed for Pisces 
+!    'dust.orca.nc',                           ! needed for Pisces 
+!    'bathy.orca.nc'                           ! needed for Pisces
+!'dyna_grid_T.nc',                             ! needed for Offline
+!'dyna_grid_W.nc'                              ! needed for Offline 
+/
+
+&interp
+    VAR_INTERP =
+    'votemper/bicubic',
+    'vosaline/bicubic'
+!    'dust/bilinear',
+!    'riverdic/bilinear',
+!    'riverpoc/bilinear',
+!    'riverdoc/bilinear',
+!    'nedep/bilinear',
+!    'bathy/bilinear'
+/
+
+&restart
+    restart_file = 'restart.nc'   
+    shlat = 0
+    dimg = false
+    dimg_output_file = 'test_dimg'
+    adatrj = 360.25 
+    interp_type = 'bilinear'
+/ 
+&restart_trc
+    restart_trc_file = 'restart_trc.nc'   
+/ 
