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.
trdmxl_rst.F90 in branches/UKMO/dev_r5518_GO6_under_ice_relax_dr_hook/NEMOGCM/NEMO/OPA_SRC/TRD – NEMO

source: branches/UKMO/dev_r5518_GO6_under_ice_relax_dr_hook/NEMOGCM/NEMO/OPA_SRC/TRD/trdmxl_rst.F90 @ 11738

Last change on this file since 11738 was 11738, checked in by marc, 4 years ago

The Dr Hook changes from my perl code.

File size: 10.8 KB
Line 
1MODULE trdmxl_rst
2   !!=================================================================================
3   !!                       ***  MODULE  trdmxl_rst  ***
4   !! Ocean dynamic :  Input/Output files for restart on mixed-layer diagnostics
5   !!=================================================================================
6   !! History :  1.0  ! 2005-05 (C. Deltel)  Original code
7   !!---------------------------------------------------------------------------------
8
9   !!---------------------------------------------------------------------------------
10   !!  trd_mxl_rst_write : write mixed layer trend restart
11   !!  trd_mxl_rst_read  : read  mixed layer trend restart
12   !!---------------------------------------------------------------------------------
13   USE dom_oce         ! ocean space and time domain
14   USE trd_oce         ! trends: ocean variables
15   USE in_out_manager  ! I/O manager
16   USE iom             ! I/O module
17   USE restart         ! only for lrst_oce
18   USE timing
19
20   USE yomhook, ONLY: lhook, dr_hook
21   USE parkind1, ONLY: jprb, jpim
22
23   IMPLICIT NONE
24   PRIVATE
25 
26   PUBLIC   trd_mxl_rst_read    ! routine called by trd_mxl_init
27   PUBLIC   trd_mxl_rst_write   ! routine called by step.F90
28 
29   INTEGER ::   nummxlw         ! logical unit for mxl restart
30
31   !!---------------------------------------------------------------------------------
32   !! NEMO/OPA 3.3 , NEMO Consortium (2010)
33   !! $Id$
34   !! Software governed by the CeCILL licence (NEMOGCM/NEMO_CeCILL.txt)
35   !!---------------------------------------------------------------------------------
36CONTAINS
37 
38   SUBROUTINE trd_mxl_rst_write( kt )
39      !!--------------------------------------------------------------------------------
40      !!                  ***  SUBROUTINE trd_mxl_rst_wri  ***
41      !!               
42      !! ** Purpose :   Write mixed-layer diagnostics restart fields.
43      !!--------------------------------------------------------------------------------
44      INTEGER, INTENT( in ) ::   kt   ! ocean time-step index
45      !
46      CHARACTER (len=35) :: charout
47      INTEGER ::   jk                 ! loop indice
48      CHARACTER(LEN=20)   ::   clkt     ! ocean time-step deine as a character
49      CHARACTER(LEN=50)   ::   clname   ! output restart file name
50      CHARACTER(LEN=256)  ::   clpath   ! full path to restart file
51      INTEGER(KIND=jpim), PARAMETER :: zhook_in = 0
52      INTEGER(KIND=jpim), PARAMETER :: zhook_out = 1
53      REAL(KIND=jprb)               :: zhook_handle
54
55      CHARACTER(LEN=*), PARAMETER :: RoutineName='TRD_MXL_RST_WRITE'
56
57      IF (lhook) CALL dr_hook(RoutineName,zhook_in,zhook_handle)
58
59      !!--------------------------------------------------------------------------------
60
61      ! to get better performances with NetCDF format:
62      ! we open and define the ocean restart_mxl file one time step before writing the data (-> at nitrst - 1)
63      ! except if we write ocean restart_mxl files every time step or if an ocean restart_mxl file was writen at nitend - 1
64      IF( kt == nitrst - 1 .OR. nstock == 1 .OR. ( kt == nitend .AND. MOD( nitend - 1, nstock ) == 0 ) ) THEN
65         ! beware of the format used to write kt (default is i8.8, that should be large enough...)
66         IF( nitrst > 999999999 ) THEN   ;   WRITE(clkt, *       ) nitrst
67         ELSE                            ;   WRITE(clkt, '(i8.8)') nitrst
68         ENDIF
69         ! create the file
70         clname = TRIM(cexper)//"_"//TRIM(ADJUSTL(clkt))//"_"//TRIM(cn_trdrst_out)
71         clpath = TRIM(cn_ocerst_outdir)
72         IF( clpath(LEN_TRIM(clpath):) /= '/' ) clpath = TRIM(clpath) // '/'
73         IF(lwp) THEN
74            WRITE(numout,*)
75            SELECT CASE ( jprstlib )
76            CASE ( jprstdimg )   ;   WRITE(numout,*) '             open ocean restart_mxl binary file: '//clname
77            CASE DEFAULT         ;   WRITE(numout,*) '             open ocean restart_mxl NetCDF file: '//clname
78            END SELECT
79            IF( kt == nitrst - 1 ) THEN   ;   WRITE(numout,*) '             kt = nitrst - 1 = ', kt,' date= ', ndastp
80            ELSE                          ;   WRITE(numout,*) '             kt = '             , kt,' date= ', ndastp
81            ENDIF
82         ENDIF
83
84         CALL iom_open( TRIM(clpath)//TRIM(clname), nummxlw, ldwrt = .TRUE., kiolib = jprstlib )
85      ENDIF
86
87      IF( kt == nitrst .AND. lwp ) THEN
88         WRITE(numout,*)
89         WRITE(numout,*) 'trdmxl_rst: output for ML diags. restart, with trd_mxl_rst_write routine kt =', kt
90         WRITE(numout,*) '~~~~~~~~~~'
91         WRITE(numout,*)
92      ENDIF
93      IF(nn_timing == 2)  CALL timing_start('iom_rstput')
94      IF( ln_trdmxl_instant ) THEN 
95         !-- Temperature
96         CALL iom_rstput( kt, nitrst, nummxlw, 'tmlbb'           , tmlbb           )
97         CALL iom_rstput( kt, nitrst, nummxlw, 'tmlbn'           , tmlbn           )
98         CALL iom_rstput( kt, nitrst, nummxlw, 'tmlatfb'         , tmlatfb         )
99
100         !-- Salinity
101         CALL iom_rstput( kt, nitrst, nummxlw, 'smlbb'           , smlbb           )
102         CALL iom_rstput( kt, nitrst, nummxlw, 'smlbn'           , smlbn           )
103         CALL iom_rstput( kt, nitrst, nummxlw, 'smlatfb'         , smlatfb         )
104      ELSE
105         CALL iom_rstput( kt, nitrst, nummxlw, 'hmxlbn'          , hmxlbn          )
106
107         !-- Temperature
108         CALL iom_rstput( kt, nitrst, nummxlw, 'tmlbn'           , tmlbn           )
109         CALL iom_rstput( kt, nitrst, nummxlw, 'tml_sumb'        , tml_sumb        )
110         DO jk = 1, jpltrd
111            IF( jk < 10 ) THEN   ;   WRITE(charout,FMT="('tmltrd_csum_ub_', I1)")   jk
112            ELSE                 ;   WRITE(charout,FMT="('tmltrd_csum_ub_', I2)")   jk
113            ENDIF
114            CALL iom_rstput( kt, nitrst, nummxlw, charout,  tmltrd_csum_ub(:,:,jk) )
115         ENDDO
116         CALL iom_rstput( kt, nitrst, nummxlw, 'tmltrd_atf_sumb' , tmltrd_atf_sumb )
117
118         !-- Salinity
119         CALL iom_rstput( kt, nitrst, nummxlw, 'smlbn'           , smlbn           )
120         CALL iom_rstput( kt, nitrst, nummxlw, 'sml_sumb'        , sml_sumb        )
121         DO jk = 1, jpltrd
122            IF( jk < 10 ) THEN   ;   WRITE(charout,FMT="('smltrd_csum_ub_', I1)")   jk
123            ELSE                 ;   WRITE(charout,FMT="('smltrd_csum_ub_', I2)")   jk
124            ENDIF
125            CALL iom_rstput( kt, nitrst, nummxlw, charout , smltrd_csum_ub(:,:,jk) )
126         ENDDO
127         CALL iom_rstput( kt, nitrst, nummxlw, 'smltrd_atf_sumb' , smltrd_atf_sumb )
128      ENDIF
129      IF(nn_timing == 2)  CALL timing_stop('iom_rstput')
130      !
131      IF( kt == nitrst ) THEN
132         CALL iom_close( nummxlw )     ! close the restart file (only at last time step)
133         lrst_oce = .FALSE.
134      ENDIF
135      !
136      IF (lhook) CALL dr_hook(RoutineName,zhook_out,zhook_handle)
137   END SUBROUTINE trd_mxl_rst_write
138
139
140   SUBROUTINE trd_mxl_rst_read
141      !!----------------------------------------------------------------------------
142      !!                   ***  SUBROUTINE trd_mxl_rst_lec  ***
143      !!                   
144      !! ** Purpose :   Read file for mixed-layer diagnostics restart.
145      !!----------------------------------------------------------------------------
146      INTEGER  ::  inum       ! temporary logical unit
147      !
148      CHARACTER (len=35) :: charout
149      INTEGER ::   jk         ! loop indice
150      INTEGER ::   jlibalt = jprstlib
151      LOGICAL ::   llok
152      CHARACTER(LEN=256)  ::   clpath   ! full path to restart file
153      INTEGER(KIND=jpim), PARAMETER :: zhook_in = 0
154      INTEGER(KIND=jpim), PARAMETER :: zhook_out = 1
155      REAL(KIND=jprb)               :: zhook_handle
156
157      CHARACTER(LEN=*), PARAMETER :: RoutineName='TRD_MXL_RST_READ'
158
159      IF (lhook) CALL dr_hook(RoutineName,zhook_in,zhook_handle)
160
161      !!-----------------------------------------------------------------------------
162
163      IF(lwp)  THEN
164         WRITE(numout,*)
165         WRITE(numout,*) ' trd_mxl_rst_read : read the NetCDF mixed layer trend restart file'
166         WRITE(numout,*) ' ~~~~~~~~~~~~~~~~'
167      ENDIF
168
169      clpath = TRIM(cn_ocerst_indir)
170      IF( clpath(LEN_TRIM(clpath):) /= '/' ) clpath = TRIM(clpath) // '/'
171
172      IF ( jprstlib == jprstdimg ) THEN
173         ! eventually read netcdf file (monobloc)  for restarting on different number of processors
174         ! if {cn_trdrst_in}.nc exists, then set jlibalt to jpnf90
175         INQUIRE( FILE = TRIM(clpath)//TRIM(cn_trdrst_in)//'.nc', EXIST = llok )
176         IF ( llok ) THEN   ;   jlibalt = jpnf90   
177         ELSE               ;   jlibalt = jprstlib   
178         ENDIF
179      ENDIF
180
181      CALL iom_open( TRIM(clpath)//TRIM(cn_trdrst_in), inum, kiolib = jlibalt ) 
182      IF(nn_timing == 2)  CALL timing_start('iom_rstget')
183      IF( ln_trdmxl_instant ) THEN 
184         !-- Temperature
185         CALL iom_get( inum, jpdom_autoglo, 'tmlbb'           , tmlbb          )
186         CALL iom_get( inum, jpdom_autoglo, 'tmlbn'           , tmlbn          )
187         CALL iom_get( inum, jpdom_autoglo, 'tmlatfb'         , tmlatfb        )
188         !
189         !-- Salinity
190         CALL iom_get( inum, jpdom_autoglo, 'smlbb'           , smlbb          )
191         CALL iom_get( inum, jpdom_autoglo, 'smlbn'           , smlbn          )
192         CALL iom_get( inum, jpdom_autoglo, 'smlatfb'         , smlatfb        )
193      ELSE
194         CALL iom_get( inum, jpdom_autoglo, 'hmxlbn'          , hmxlbn         ) ! needed for hmxl_sum
195         !
196         !-- Temperature
197         CALL iom_get( inum, jpdom_autoglo, 'tmlbn'           , tmlbn          ) ! needed for tml_sum
198         CALL iom_get( inum, jpdom_autoglo, 'tml_sumb'        , tml_sumb       )
199         DO jk = 1, jpltrd
200            IF( jk < 10 ) THEN   ;   WRITE(charout,FMT="('tmltrd_csum_ub_', I1)")   jk
201            ELSE                 ;   WRITE(charout,FMT="('tmltrd_csum_ub_', I2)")   jk
202            ENDIF
203            CALL iom_get( inum, jpdom_autoglo, charout, tmltrd_csum_ub(:,:,jk) )
204         END DO
205         CALL iom_get( inum, jpdom_autoglo, 'tmltrd_atf_sumb' , tmltrd_atf_sumb)
206         !
207         !-- Salinity
208         CALL iom_get( inum, jpdom_autoglo, 'smlbn'           , smlbn          ) ! needed for sml_sum
209         CALL iom_get( inum, jpdom_autoglo, 'sml_sumb'        , sml_sumb       )
210         DO jk = 1, jpltrd
211            IF( jk < 10 ) THEN   ;   WRITE(charout,FMT="('smltrd_csum_ub_', I1)")   jk
212            ELSE                 ;   WRITE(charout,FMT="('smltrd_csum_ub_', I2)")   jk
213            ENDIF
214            CALL iom_get( inum, jpdom_autoglo, charout, smltrd_csum_ub(:,:,jk) )
215         END DO
216         CALL iom_get( inum, jpdom_autoglo, 'smltrd_atf_sumb' , smltrd_atf_sumb)
217         !
218      ENDIF
219      IF(nn_timing == 2)  CALL timing_stop('iom_rstget')
220      CALL iom_close( inum )
221      !
222      IF (lhook) CALL dr_hook(RoutineName,zhook_out,zhook_handle)
223   END SUBROUTINE trd_mxl_rst_read
224 
225  !!=================================================================================
226END MODULE trdmxl_rst
Note: See TracBrowser for help on using the repository browser.