Index: trunk/NEMO/OPA_SRC/IOM/iom_rstdimg.F90
===================================================================
--- trunk/NEMO/OPA_SRC/IOM/iom_rstdimg.F90	(revision 1152)
+++ trunk/NEMO/OPA_SRC/IOM/iom_rstdimg.F90	(revision 1488)
@@ -48,12 +48,13 @@
       !! ** Purpose :  open an input file read only (return 0 if not found)
       !!---------------------------------------------------------------------
-      CHARACTER(len=*)       , INTENT(inout)           ::   cdname   ! File name
-      INTEGER                , INTENT(  out)           ::   kiomid   ! iom identifier of the opened file
-      LOGICAL                , INTENT(in   )           ::   ldwrt    ! read or write the file?
-      LOGICAL                , INTENT(in   )           ::   ldok     ! check the existence 
-      INTEGER, DIMENSION(2,5), INTENT(in   ), OPTIONAL ::   kdompar  ! domain parameters: 
+      CHARACTER(len=*)       , INTENT(inout)           ::   cdname      ! File name
+      INTEGER                , INTENT(  out)           ::   kiomid      ! iom identifier of the opened file
+      LOGICAL                , INTENT(in   )           ::   ldwrt       ! read or write the file?
+      LOGICAL                , INTENT(in   )           ::   ldok        ! check the existence 
+      INTEGER, DIMENSION(2,5), INTENT(in   ), OPTIONAL ::   kdompar     ! domain parameters: 
 
       CHARACTER(LEN=100)                      ::   clinfo                     ! info character
       CHARACTER(LEN=100)                      ::   cltmp                      ! temporary character
+      CHARACTER(LEN=10 )                      ::   clstatus                   ! status of opened file (REPLACE or NEW)
       INTEGER                                 ::   jv                         ! loop counter
       INTEGER                                 ::   istop                      ! temporary storage of nstop
@@ -70,7 +71,8 @@
       INTEGER                                 ::   iiglo, ijglo               ! domain global size 
       INTEGER                                 ::   jl                         ! loop variable
+      LOGICAL                                 ::   llclobber                  ! local definition of ln_clobber
       CHARACTER(LEN=jpvnl), DIMENSION(jpmax_vars) ::   clna0d, clna1d, clna2d, clna3d     ! name of 0/1/2/3D variables
-      REAL(wp),         DIMENSION(jpmax_vars) ::   zval0d, zval1d, zval2d, zval3d     ! value of 0d variables or record
-      !                                                                               ! position for 1/2/3D variables
+      REAL(wp),             DIMENSION(jpmax_vars) ::   zval0d, zval1d, zval2d, zval3d     ! value of 0d variables or record
+      !                                                                                   ! position for 1/2/3D variables
       !---------------------------------------------------------------------
       clinfo = '                    iom_rstdimg_open ~~~  '
@@ -78,4 +80,5 @@
       ios = 0            ! default definition
       kiomid = 0         ! default definition
+      llclobber = ldwrt .AND. ln_clobber
       ! get a free unit
       idrst = getunit()  ! get a free logical unit for the restart file
@@ -85,5 +88,5 @@
       ! Open the file...
       ! =============
-      IF( ldok ) THEN      ! Open existing file...
+      IF( ldok .AND. .NOT. llclobber ) THEN      ! Open existing file...
          ! find the record length
          OPEN( idrst, FILE = TRIM(cdname), FORM = 'unformatted', ACCESS = 'direct'   &
@@ -101,5 +104,5 @@
                &       , RECL = irecl8, STATUS = 'old', ACTION = 'read'     , IOSTAT = ios, ERR = 987 )
          ENDIF
-      ELSE                 ! the file does not exist
+      ELSE                                       ! the file does not exist (or we overwrite it)
          iln = INDEX( cdname, '.dimg' )
          IF( ldwrt ) THEN  ! the file should be open in readwrite mode so we create it...
@@ -110,6 +113,10 @@
             ENDIF
             IF(lwp) WRITE(numout,*) TRIM(clinfo)//' create new file: '//TRIM(cdname)//' in READWRITE mode'
+            
+            IF( llclobber ) THEN   ;   clstatus = 'REPLACE' 
+            ELSE                   ;   clstatus = 'NEW'
+            ENDIF
             OPEN( idrst, FILE = TRIM(cdname), FORM = 'UNFORMATTED', ACCESS = 'DIRECT'   &
-               &       , RECL = irecl8, STATUS = 'new', ACTION = 'readwrite', IOSTAT = ios, ERR = 987 )
+               &       , RECL = irecl8, STATUS = TRIM(clstatus), ACTION = 'readwrite', IOSTAT = ios, ERR = 987 )
          ELSE              ! the file should be open for read mode so it must exist...
             CALL ctl_stop( TRIM(clinfo), ' should be impossible case...' )
@@ -118,5 +125,5 @@
       ! Performs checks on the file
       ! =============
-      IF( ldok ) THEN      ! old file
+      IF( ldok .AND. .NOT. llclobber ) THEN      ! old file
          READ( idrst, REC = 1   , IOSTAT = ios, ERR = 987 )              &
               &   irecl8, inx, iny, inz, in0d, in1d, in2d, in3d, irhd,   &
