Index: trunk/NEMO/OFF_SRC/IOM/in_out_manager.F90
===================================================================
--- trunk/NEMO/OFF_SRC/IOM/in_out_manager.F90	(revision 1641)
+++ trunk/NEMO/OFF_SRC/IOM/in_out_manager.F90	(revision 1642)
@@ -5,7 +5,8 @@
    !!                 turbulent closure parameterization
    !!=====================================================================
-   !! History :   1.0  !  2002-06  (G. Madec)  original code
+   !! History :   1.0  !  2002-06  (G. Madec)   original code
    !!             2.0  !  2006-07  (S. Masson)  iom, add ctl_stop, ctl_warn
-   !!             3.0  !  2008-06  (G. Madec)  add ctmp4 to ctmp10
+   !!             3.0  !  2008-06  (G. Madec)   add ctmp4 to ctmp10
+   !!             3.2  !  2009-08  (S. MAsson)  add new ctl_opn
    !!----------------------------------------------------------------------
 
@@ -18,4 +19,7 @@
    USE par_oce         ! ocean parameter
    USE lib_print       ! formated print library
+#if defined key_agrif
+   USE Agrif_Util
+#endif
 
    IMPLICIT NONE
@@ -25,44 +29,67 @@
    !!                   namrun namelist parameters
    !!----------------------------------------------------------------------
-   CHARACTER(len=16)  ::   cexper        = "exp0"      !: experiment name used for output filename
+   CHARACTER(len=16)  ::   cn_exp        = "exp0"      !: experiment name used for output filename
    CHARACTER(len=32)  ::   cn_ocerst_in  = "restart"   !: suffix of ocean restart name (input)
    CHARACTER(len=32)  ::   cn_ocerst_out = "restart"   !: suffix of ocean restart name (output)
    LOGICAL            ::   ln_rstart     = .FALSE.     !: start from (F) rest or (T) a restart file
-   INTEGER            ::   no            = 0           !: job number
-   INTEGER            ::   nrstdt        = 0           !: control of the time step (0, 1 or 2)
+   INTEGER            ::   nn_no         = 0           !: job number
+   INTEGER            ::   nn_rstctl     = 0           !: control of the time step (0, 1 or 2)
    INTEGER            ::   nn_rstssh     = 0           !: hand made initilization of ssh or not (1/0)
-   INTEGER            ::   nit000        = 1           !: index of the first time step
-   INTEGER            ::   nitend        = 10          !: index of the last time step
-   INTEGER            ::   ndate0        = 961115      !: initial calendar date aammjj
-   INTEGER            ::   nleapy        = 0           !: Leap year calendar flag (0/1 or 30)
-   INTEGER            ::   ninist        = 0           !: initial state output flag (0/1)
+   INTEGER            ::   nn_it000      = 1           !: index of the first time step
+   INTEGER            ::   nn_itend      = 10          !: index of the last time step
+   INTEGER            ::   nn_date0      = 961115      !: initial calendar date aammjj
+   INTEGER            ::   nn_leapy      = 0           !: Leap year calendar flag (0/1 or 30)
+   INTEGER            ::   nn_istate     = 0           !: initial state output flag (0/1)
+   INTEGER            ::   nn_write      =   10        !: model standard output frequency
+   INTEGER            ::   nn_stock      =   10        !: restart file frequency
    LOGICAL            ::   ln_dimgnnn    = .FALSE.     !: type of dimgout. (F): 1 file for all proc
                                                        !:                  (T): 1 file per proc
    LOGICAL            ::   ln_mskland    = .FALSE.     !: mask land points in NetCDF outputs (costly: + ~15%)
+   LOGICAL            ::   ln_clobber    = .FALSE.     !: clobber (overwrite) an existing file
+   INTEGER            ::   nn_chunksz    = 0           !: chunksize (bytes) for NetCDF file (working only with iom_nf90 routines)
+
+   !! conversion of DOCTOR norm namelist name into model name
+   !! (this should disappear in a near futur)
+
+   CHARACTER(len=16)  ::   cexper                      !: experiment name used for output filename
+   INTEGER            ::   no                          !: job number
+   INTEGER            ::   nrstdt                      !: control of the time step (0, 1 or 2)
+   INTEGER            ::   nit000                      !: index of the first time step
+   INTEGER            ::   nitend                      !: index of the last time step
+   INTEGER            ::   ndate0                      !: initial calendar date aammjj
+   INTEGER            ::   nleapy                      !: Leap year calendar flag (0/1 or 30)
+   INTEGER            ::   ninist                      !: initial state output flag (0/1)
+   INTEGER            ::   nwrite                      !: model standard output frequency
+   INTEGER            ::   nstock                      !: restart file frequency
+
    !!----------------------------------------------------------------------
    !! was in restart but moved here because of the OFF line... better solution should be found...
    !!----------------------------------------------------------------------
    INTEGER            ::   nitrst                 !: time step at which restart file should be written
+
    !!----------------------------------------------------------------------
    !!                    output monitoring
    !!----------------------------------------------------------------------
    LOGICAL            ::   ln_ctl     = .FALSE.   !: run control for debugging
-   INTEGER            ::   nstock     =   10      !: restart file frequency
-   INTEGER            ::   nprint     =    0      !: level of print (0 no print)
-   INTEGER            ::   nwrite     =   10      !: restart file frequency
-   INTEGER            ::   nictls     =    0      !: Start i indice for the SUM control
-   INTEGER            ::   nictle     =    0      !: End   i indice for the SUM control
-   INTEGER            ::   njctls     =    0      !: Start j indice for the SUM control
-   INTEGER            ::   njctle     =    0      !: End   j indice for the SUM control
-   INTEGER            ::   isplt      =    1      !: number of processors following i
-   INTEGER            ::   jsplt      =    1      !: number of processors following j
+   INTEGER            ::   nn_print     =    0    !: level of print (0 no print)
+   INTEGER            ::   nn_ictls     =    0    !: Start i indice for the SUM control
+   INTEGER            ::   nn_ictle     =    0    !: End   i indice for the SUM control
+   INTEGER            ::   nn_jctls     =    0    !: Start j indice for the SUM control
+   INTEGER            ::   nn_jctle     =    0    !: End   j indice for the SUM control
+   INTEGER            ::   nn_isplt      =    1   !: number of processors following i
+   INTEGER            ::   nn_jsplt      =    1   !: number of processors following j
+   INTEGER            ::   nn_bench     =    0    !: benchmark parameter (0/1)
+   INTEGER            ::   nn_bit_cmp   =    0    !: bit reproducibility  (0/1)
+
+   !                                              !: OLD namelist names
+   INTEGER ::   nprint, nictls, nictle, njctls, njctle, isplt, jsplt, nbench, nbit_cmp   
+
    INTEGER            ::   ijsplt     =    1      !: nb of local domain = nb of processors
-   INTEGER            ::   nbench     =    0      !: benchmark parameter (0/1)
-   INTEGER            ::   nbit_cmp   =    0      !: bit reproducibility  (0/1)
+
    !!----------------------------------------------------------------------
    !!                        logical units
    !!----------------------------------------------------------------------
    INTEGER            ::   numstp                 !: logical unit for time step
-   INTEGER            ::   numout                 !: logical unit for output print
+   INTEGER            ::   numout     =    6      !: logical unit for output print
    INTEGER            ::   numnam                 !: logical unit for namelist
    INTEGER            ::   numnam_ice             !: logical unit for ice namelist
@@ -70,5 +97,4 @@
    INTEGER            ::   numsol                 !: logical unit for solver statistics
    INTEGER            ::   numwri                 !: logical unit for output write
-   INTEGER            ::   numisp                 !: logical unit for island statistics
    INTEGER            ::   numgap                 !: logical unit for differences diagnostic
    INTEGER            ::   numbol                 !: logical unit for "bol" diagnostics
@@ -79,5 +105,4 @@
    !!                          Run control  
    !!----------------------------------------------------------------------
-
    INTEGER            ::   nstop = 0                !: error flag (=number of reason for a premature stop run)
    INTEGER            ::   nwarn = 0                !: warning flag (=number of warning found during the run)
@@ -88,5 +113,5 @@
    CHARACTER (len=64) ::   cform_err = "(/,' ===>>> : E R R O R',     /,'         ===========',/)"       !:
    CHARACTER (len=64) ::   cform_war = "(/,' ===>>> : W A R N I N G', /,'         ===============',/)"   !:
-   LOGICAL            ::   lwp                      !: boolean : true on the 1st processor only
+   LOGICAL            ::   lwp      = .FALSE.       !: boolean : true on the 1st processor only
    LOGICAL            ::   lsp_area = .TRUE.        !: to make a control print over a specific area
    !!----------------------------------------------------------------------
@@ -160,4 +185,79 @@
 
 
+   SUBROUTINE ctl_opn ( knum, cdfile, cdstat, cdform, cdacce, klengh, kout, ldwp, karea )
+      !!----------------------------------------------------------------------
+      !!                  ***  ROUTINE ctl_opn  ***
+      !!
+      !! ** Purpose :   Open file and check if required file is available.
+      !!
+      !! ** Method  :   Fortan open
+      !!
+      !! History :
+      !!        !  1995-12  (G. Madec)  Original code
+      !!   8.5  !  2002-06  (G. Madec)  F90: Free form and module
+      !!----------------------------------------------------------------------
+
+      INTEGER          , INTENT(  out) ::   knum      ! logical unit to open
+      CHARACTER(len=*) , INTENT(in   ) ::   cdfile    ! file name to open
+      CHARACTER(len=*) , INTENT(in   ) ::   cdstat    ! disposition specifier
+      CHARACTER(len=*) , INTENT(in   ) ::   cdform    ! formatting specifier
+      CHARACTER(len=*) , INTENT(in   ) ::   cdacce    ! access specifier
+      INTEGER          , INTENT(in   ) ::   klengh    ! record length
+      INTEGER          , INTENT(in   ) ::   kout      ! number of logical units for write
+      LOGICAL          , INTENT(in   ) ::   ldwp      ! boolean term for print
+      INTEGER, OPTIONAL, INTENT(in   ) ::   karea     ! proc number
+      !!
+      CHARACTER(len=80) ::   clfile
+      INTEGER           ::   iost
+
+      ! adapt filename
+      ! ----------------
+      clfile = TRIM(cdfile)
+      IF( PRESENT( karea ) ) THEN
+         IF( karea > 1 )   WRITE(clfile, "(a,'_',i4.4)") TRIM(clfile), karea-1
+      ENDIF
+#if defined key_agrif
+      IF( .NOT. Agrif_Root() )   clfile = TRIM(Agrif_CFixed())//'_'//TRIM(clfile)
+      knum=Agrif_Get_Unit()
+#else
+      knum=getunit()
+#endif
+
+      iost=0
+      IF( cdacce(1:6) == 'DIRECT' )  THEN
+         OPEN( UNIT=knum, FILE=clfile, FORM=cdform, ACCESS=cdacce, STATUS=cdstat, RECL=klengh, ERR=100, IOSTAT=iost )
+      ELSE
+         OPEN( UNIT=knum, FILE=clfile, FORM=cdform, ACCESS=cdacce, STATUS=cdstat             , ERR=100, IOSTAT=iost )
+      ENDIF
+      IF( iost == 0 ) THEN
+         IF(ldwp) THEN
+            WRITE(kout,*) '     file   : ', clfile,' open ok'
+            WRITE(kout,*) '     unit   = ', knum
+            WRITE(kout,*) '     status = ', cdstat
+            WRITE(kout,*) '     form   = ', cdform
+            WRITE(kout,*) '     access = ', cdacce
+            WRITE(kout,*)
+         ENDIF
+      ENDIF
+100   CONTINUE
+      IF( iost /= 0 ) THEN
+         IF(ldwp) THEN
+            WRITE(kout,*)
+            WRITE(kout,*) ' ===>>>> : bad opening file: ', clfile
+            WRITE(kout,*) ' =======   ===  '
+            WRITE(kout,*) '           unit   = ', knum
+            WRITE(kout,*) '           status = ', cdstat
+            WRITE(kout,*) '           form   = ', cdform
+            WRITE(kout,*) '           access = ', cdacce
+            WRITE(kout,*) '           iostat = ', iost
+            WRITE(kout,*) '           we stop. verify the file '
+            WRITE(kout,*)
+         ENDIF
+         STOP 'ctl_opn bad opening'
+      ENDIF
+      
+   END SUBROUTINE ctl_opn
+
+
    FUNCTION getunit()
       !!----------------------------------------------------------------------
