New URL for NEMO forge!   http://forge.nemo-ocean.eu

Since March 2022 along with NEMO 4.2 release, the code development moved to a self-hosted GitLab.
This present forge is now archived and remained online for history.
in_out_manager.F90 in trunk/NEMOGCM/NEMO/OPA_SRC/IOM – NEMO

source: trunk/NEMOGCM/NEMO/OPA_SRC/IOM/in_out_manager.F90 @ 2528

Last change on this file since 2528 was 2528, checked in by rblod, 13 years ago

Update NEMOGCM from branch nemo_v3_3_beta

  • Property svn:keywords set to Id
File size: 15.7 KB
Line 
1MODULE in_out_manager   
2   !!======================================================================
3   !!                       ***  MODULE  in_out_manager  ***
4   !! Ocean physics:  vertical mixing coefficient compute from the tke
5   !!                 turbulent closure parameterization
6   !!=====================================================================
7   !! History :   1.0  !  2002-06  (G. Madec)   original code
8   !!             2.0  !  2006-07  (S. Masson)  iom, add ctl_stop, ctl_warn
9   !!             3.0  !  2008-06  (G. Madec)   add ctmp4 to ctmp10
10   !!             3.2  !  2009-08  (S. MAsson)  add new ctl_opn
11   !!             3.3  !  2010-10  (A. Coward)  add NetCDF4 usage
12   !!----------------------------------------------------------------------
13
14   !!----------------------------------------------------------------------
15   !!   ctl_stop   : update momentum and tracer Kz from a tke scheme
16   !!   ctl_warn   : initialization, namelist read, and parameters control
17   !!   getunit    : give the index of an unused logical unit
18   !!----------------------------------------------------------------------
19   USE par_oce       ! ocean parameter
20   USE lib_print     ! formated print library
21   USE nc4interface  ! NetCDF4 interface
22
23   IMPLICIT NONE
24   PUBLIC
25
26   !!----------------------------------------------------------------------
27   !!                   namrun namelist parameters
28   !!----------------------------------------------------------------------
29   CHARACTER(lc) ::   cn_exp        = "exp0"      !: experiment name used for output filename
30   CHARACTER(lc) ::   cn_ocerst_in  = "restart"   !: suffix of ocean restart name (input)
31   CHARACTER(lc) ::   cn_ocerst_out = "restart"   !: suffix of ocean restart name (output)
32   LOGICAL       ::   ln_rstart     = .FALSE.     !: start from (F) rest or (T) a restart file
33   INTEGER       ::   nn_no         = 0           !: job number
34   INTEGER       ::   nn_rstctl     = 0           !: control of the time step (0, 1 or 2)
35   INTEGER       ::   nn_rstssh     = 0           !: hand made initilization of ssh or not (1/0)
36   INTEGER       ::   nn_it000      = 1           !: index of the first time step
37   INTEGER       ::   nn_itend      = 10          !: index of the last time step
38   INTEGER       ::   nn_date0      = 961115      !: initial calendar date aammjj
39   INTEGER       ::   nn_leapy      = 0           !: Leap year calendar flag (0/1 or 30)
40   INTEGER       ::   nn_istate     = 0           !: initial state output flag (0/1)
41   INTEGER       ::   nn_write      =   10        !: model standard output frequency
42   INTEGER       ::   nn_stock      =   10        !: restart file frequency
43   LOGICAL       ::   ln_dimgnnn    = .FALSE.     !: type of dimgout. (F): 1 file for all proc
44                                                       !:                  (T): 1 file per proc
45   LOGICAL       ::   ln_mskland    = .FALSE.     !: mask land points in NetCDF outputs (costly: + ~15%)
46   LOGICAL       ::   ln_clobber    = .FALSE.     !: clobber (overwrite) an existing file
47   INTEGER       ::   nn_chunksz    = 0           !: chunksize (bytes) for NetCDF file (works only with iom_nf90 routines)
48#if defined key_netcdf4
49   !!----------------------------------------------------------------------
50   !!                   namnc4 namelist parameters                         (key_netcdf4)
51   !!----------------------------------------------------------------------
52   ! The following four values determine the partitioning of the output fields
53   ! into netcdf4 chunks. They are unrelated to the nn_chunk_sz setting which is
54   ! for runtime optimisation. The individual netcdf4 chunks can be optionally
55   ! gzipped (recommended) leading to significant reductions in I/O volumes
56   !                                   !!!**  variables only used with iom_nf90 routines and key_netcdf4 **
57   INTEGER ::   nn_nchunks_i = 1        !: number of chunks required in the i-dimension
58   INTEGER ::   nn_nchunks_j = 1        !: number of chunks required in the j-dimension
59   INTEGER ::   nn_nchunks_k = 1        !: number of chunks required in the k-dimension
60   INTEGER ::   nn_nchunks_t = 1        !: number of chunks required in the t-dimension
61   LOGICAL ::   ln_nc4zip    = .TRUE.   !: netcdf4 usage: (T) chunk and compress output using the HDF5 sublayers of netcdf4
62   !                                    !                 (F) ignore chunking request and use the netcdf4 library
63   !                                    !                     to produce netcdf3-compatible files
64#endif
65!$AGRIF_DO_NOT_TREAT
66   TYPE(snc4_ctl)     :: snc4set        !: netcdf4 chunking control structure (always needed for decision making)
67!$AGRIF_END_DO_NOT_TREAT
68
69
70   !! conversion of DOCTOR norm namelist name into model name
71   !! (this should disappear in a near futur)
72
73   CHARACTER(lc) ::   cexper                      !: experiment name used for output filename
74   INTEGER       ::   no                          !: job number
75   INTEGER       ::   nrstdt                      !: control of the time step (0, 1 or 2)
76   INTEGER       ::   nit000                      !: index of the first time step
77   INTEGER       ::   nitend                      !: index of the last time step
78   INTEGER       ::   ndate0                      !: initial calendar date aammjj
79   INTEGER       ::   nleapy                      !: Leap year calendar flag (0/1 or 30)
80   INTEGER       ::   ninist                      !: initial state output flag (0/1)
81   INTEGER       ::   nwrite                      !: model standard output frequency
82   INTEGER       ::   nstock                      !: restart file frequency
83
84   !!----------------------------------------------------------------------
85   !! was in restart but moved here because of the OFF line... better solution should be found...
86   !!----------------------------------------------------------------------
87   INTEGER ::   nitrst   !: time step at which restart file should be written
88
89   !!----------------------------------------------------------------------
90   !!                    output monitoring
91   !!----------------------------------------------------------------------
92   LOGICAL ::   ln_ctl     = .FALSE.   !: run control for debugging
93   INTEGER ::   nn_print     =    0    !: level of print (0 no print)
94   INTEGER ::   nn_ictls     =    0    !: Start i indice for the SUM control
95   INTEGER ::   nn_ictle     =    0    !: End   i indice for the SUM control
96   INTEGER ::   nn_jctls     =    0    !: Start j indice for the SUM control
97   INTEGER ::   nn_jctle     =    0    !: End   j indice for the SUM control
98   INTEGER ::   nn_isplt     =    1    !: number of processors following i
99   INTEGER ::   nn_jsplt     =    1    !: number of processors following j
100   INTEGER ::   nn_bench     =    0    !: benchmark parameter (0/1)
101   INTEGER ::   nn_bit_cmp   =    0    !: bit reproducibility  (0/1)
102
103   !                                         
104   INTEGER ::   nprint, nictls, nictle, njctls, njctle, isplt, jsplt, nbench    !: OLD namelist names
105
106   INTEGER ::   ijsplt     =    1      !: nb of local domain = nb of processors
107
108   !!----------------------------------------------------------------------
109   !!                        logical units
110   !!----------------------------------------------------------------------
111   INTEGER ::   numstp     =   -1      !: logical unit for time step
112   INTEGER ::   numout     =    6      !: logical unit for output print
113   INTEGER ::   numnam     =   -1      !: logical unit for namelist
114   INTEGER ::   numnam_ice =   -1      !: logical unit for ice namelist
115   INTEGER ::   numevo_ice =   -1      !: logical unit for ice variables (temp. evolution)
116   INTEGER ::   numsol     =   -1      !: logical unit for solver statistics
117
118   !!----------------------------------------------------------------------
119   !!                          Run control 
120   !!----------------------------------------------------------------------
121   INTEGER       ::   nstop = 0             !: error flag (=number of reason for a premature stop run)
122   INTEGER       ::   nwarn = 0             !: warning flag (=number of warning found during the run)
123   CHARACTER(lc) ::   ctmp1, ctmp2, ctmp3   !: temporary characters 1 to 3
124   CHARACTER(lc) ::   ctmp4, ctmp5, ctmp6   !: temporary characters 4 to 6
125   CHARACTER(lc) ::   ctmp7, ctmp8, ctmp9   !: temporary characters 7 to 9
126   CHARACTER(lc) ::   ctmp10                !: temporary character 10
127   CHARACTER(lc) ::   cform_err = "(/,' ===>>> : E R R O R',     /,'         ===========',/)"       !:
128   CHARACTER(lc) ::   cform_war = "(/,' ===>>> : W A R N I N G', /,'         ===============',/)"   !:
129   LOGICAL       ::   lwp      = .FALSE.    !: boolean : true on the 1st processor only
130   LOGICAL       ::   lsp_area = .TRUE.     !: to make a control print over a specific area
131
132   !!----------------------------------------------------------------------
133   !! NEMO/OPA 3.3 , NEMO Consortium (2010)
134   !! $Id$
135   !! Software governed by the CeCILL licence     (NEMOGCM/NEMO_CeCILL.txt)
136   !!----------------------------------------------------------------------
137CONTAINS
138
139   SUBROUTINE ctl_stop( cd1, cd2, cd3, cd4, cd5,   &
140      &                 cd6, cd7, cd8, cd9, cd10 )
141      !!----------------------------------------------------------------------
142      !!                  ***  ROUTINE  stop_opa  ***
143      !!
144      !! ** Purpose :   print in ocean.outpput file a error message and
145      !!                increment the error number (nstop) by one.
146      !!----------------------------------------------------------------------
147      CHARACTER(len=*), INTENT(in), OPTIONAL ::  cd1, cd2, cd3, cd4, cd5
148      CHARACTER(len=*), INTENT(in), OPTIONAL ::  cd6, cd7, cd8, cd9, cd10
149      !!----------------------------------------------------------------------
150      !
151      nstop = nstop + 1 
152      IF(lwp) THEN
153         WRITE(numout,cform_err)
154         IF( PRESENT(cd1 ) ) WRITE(numout,*) cd1
155         IF( PRESENT(cd2 ) ) WRITE(numout,*) cd2
156         IF( PRESENT(cd3 ) ) WRITE(numout,*) cd3
157         IF( PRESENT(cd4 ) ) WRITE(numout,*) cd4
158         IF( PRESENT(cd5 ) ) WRITE(numout,*) cd5
159         IF( PRESENT(cd6 ) ) WRITE(numout,*) cd6
160         IF( PRESENT(cd7 ) ) WRITE(numout,*) cd7
161         IF( PRESENT(cd8 ) ) WRITE(numout,*) cd8
162         IF( PRESENT(cd9 ) ) WRITE(numout,*) cd9
163         IF( PRESENT(cd10) ) WRITE(numout,*) cd10
164      ENDIF
165                               CALL FLUSH(numout    )
166      IF( numstp     /= -1 )   CALL FLUSH(numstp    )
167      IF( numsol     /= -1 )   CALL FLUSH(numsol    )
168      IF( numevo_ice /= -1 )   CALL FLUSH(numevo_ice)
169      !
170   END SUBROUTINE ctl_stop
171
172
173   SUBROUTINE ctl_warn( cd1, cd2, cd3, cd4, cd5,   &
174      &                 cd6, cd7, cd8, cd9, cd10 )
175      !!----------------------------------------------------------------------
176      !!                  ***  ROUTINE  stop_warn  ***
177      !!
178      !! ** Purpose :   print in ocean.outpput file a error message and
179      !!                increment the warning number (nwarn) by one.
180      !!----------------------------------------------------------------------
181      CHARACTER(len=*), INTENT(in), OPTIONAL ::  cd1, cd2, cd3, cd4, cd5
182      CHARACTER(len=*), INTENT(in), OPTIONAL ::  cd6, cd7, cd8, cd9, cd10
183      !!----------------------------------------------------------------------
184      !
185      nwarn = nwarn + 1 
186      IF(lwp) THEN
187         WRITE(numout,cform_war)
188         IF( PRESENT(cd1 ) ) WRITE(numout,*) cd1
189         IF( PRESENT(cd2 ) ) WRITE(numout,*) cd2
190         IF( PRESENT(cd3 ) ) WRITE(numout,*) cd3
191         IF( PRESENT(cd4 ) ) WRITE(numout,*) cd4
192         IF( PRESENT(cd5 ) ) WRITE(numout,*) cd5
193         IF( PRESENT(cd6 ) ) WRITE(numout,*) cd6
194         IF( PRESENT(cd7 ) ) WRITE(numout,*) cd7
195         IF( PRESENT(cd8 ) ) WRITE(numout,*) cd8
196         IF( PRESENT(cd9 ) ) WRITE(numout,*) cd9
197         IF( PRESENT(cd10) ) WRITE(numout,*) cd10
198      ENDIF
199      CALL FLUSH(numout)
200      !
201   END SUBROUTINE ctl_warn
202
203
204   SUBROUTINE ctl_opn( knum, cdfile, cdstat, cdform, cdacce, klengh, kout, ldwp, karea )
205      !!----------------------------------------------------------------------
206      !!                  ***  ROUTINE ctl_opn  ***
207      !!
208      !! ** Purpose :   Open file and check if required file is available.
209      !!
210      !! ** Method  :   Fortan open
211      !!----------------------------------------------------------------------
212      INTEGER          , INTENT(  out) ::   knum      ! logical unit to open
213      CHARACTER(len=*) , INTENT(in   ) ::   cdfile    ! file name to open
214      CHARACTER(len=*) , INTENT(in   ) ::   cdstat    ! disposition specifier
215      CHARACTER(len=*) , INTENT(in   ) ::   cdform    ! formatting specifier
216      CHARACTER(len=*) , INTENT(in   ) ::   cdacce    ! access specifier
217      INTEGER          , INTENT(in   ) ::   klengh    ! record length
218      INTEGER          , INTENT(in   ) ::   kout      ! number of logical units for write
219      LOGICAL          , INTENT(in   ) ::   ldwp      ! boolean term for print
220      INTEGER, OPTIONAL, INTENT(in   ) ::   karea     ! proc number
221      !!
222      CHARACTER(len=80) ::   clfile
223      INTEGER           ::   iost
224      !!----------------------------------------------------------------------
225
226      ! adapt filename
227      ! ----------------
228      clfile = TRIM(cdfile)
229      IF( PRESENT( karea ) ) THEN
230         IF( karea > 1 )   WRITE(clfile, "(a,'_',i4.4)") TRIM(clfile), karea-1
231      ENDIF
232#if defined key_agrif
233      IF( .NOT. Agrif_Root() )   clfile = TRIM(Agrif_CFixed())//'_'//TRIM(clfile)
234      knum=Agrif_Get_Unit()
235#else
236      knum=getunit()
237#endif
238
239      iost=0
240      IF( cdacce(1:6) == 'DIRECT' )  THEN
241         OPEN( UNIT=knum, FILE=clfile, FORM=cdform, ACCESS=cdacce, STATUS=cdstat, RECL=klengh, ERR=100, IOSTAT=iost )
242      ELSE
243         OPEN( UNIT=knum, FILE=clfile, FORM=cdform, ACCESS=cdacce, STATUS=cdstat             , ERR=100, IOSTAT=iost )
244      ENDIF
245      IF( iost == 0 ) THEN
246         IF(ldwp) THEN
247            WRITE(kout,*) '     file   : ', clfile,' open ok'
248            WRITE(kout,*) '     unit   = ', knum
249            WRITE(kout,*) '     status = ', cdstat
250            WRITE(kout,*) '     form   = ', cdform
251            WRITE(kout,*) '     access = ', cdacce
252            WRITE(kout,*)
253         ENDIF
254      ENDIF
255100   CONTINUE
256      IF( iost /= 0 ) THEN
257         IF(ldwp) THEN
258            WRITE(kout,*)
259            WRITE(kout,*) ' ===>>>> : bad opening file: ', clfile
260            WRITE(kout,*) ' =======   ===  '
261            WRITE(kout,*) '           unit   = ', knum
262            WRITE(kout,*) '           status = ', cdstat
263            WRITE(kout,*) '           form   = ', cdform
264            WRITE(kout,*) '           access = ', cdacce
265            WRITE(kout,*) '           iostat = ', iost
266            WRITE(kout,*) '           we stop. verify the file '
267            WRITE(kout,*)
268         ENDIF
269         STOP 'ctl_opn bad opening'
270      ENDIF
271     
272   END SUBROUTINE ctl_opn
273
274
275   FUNCTION getunit()
276      !!----------------------------------------------------------------------
277      !!                  ***  FUNCTION  getunit  ***
278      !!
279      !! ** Purpose :   return the index of an unused logical unit
280      !!----------------------------------------------------------------------
281      INTEGER :: getunit
282      LOGICAL :: llopn 
283      !!----------------------------------------------------------------------
284      !
285      getunit = 15   ! choose a unit that is big enough then it is not already used in NEMO
286      llopn = .TRUE.
287      DO WHILE( (getunit < 998) .AND. llopn )
288         getunit = getunit + 1
289         INQUIRE( unit = getunit, opened = llopn )
290      END DO
291      IF( (getunit == 999) .AND. llopn ) THEN
292         CALL ctl_stop( 'getunit: All logical units until 999 are used...' )
293         getunit = -1
294      ENDIF
295      !
296   END FUNCTION getunit
297
298   !!=====================================================================
299END MODULE in_out_manager
Note: See TracBrowser for help on using the repository browser.