trdmxl_rst.F90 9.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202
  1. MODULE 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. !! trd_mxl_rst_write : write mixed layer trend restart
  10. !! trd_mxl_rst_read : read mixed layer trend restart
  11. !!---------------------------------------------------------------------------------
  12. USE dom_oce ! ocean space and time domain
  13. USE trd_oce ! trends: ocean variables
  14. USE in_out_manager ! I/O manager
  15. USE iom ! I/O module
  16. USE restart ! only for lrst_oce
  17. IMPLICIT NONE
  18. PRIVATE
  19. PUBLIC trd_mxl_rst_read ! routine called by trd_mxl_init
  20. PUBLIC trd_mxl_rst_write ! routine called by step.F90
  21. INTEGER :: nummxlw ! logical unit for mxl restart
  22. !!---------------------------------------------------------------------------------
  23. !! NEMO/OPA 3.3 , NEMO Consortium (2010)
  24. !! $Id: trdmxl_rst.F90 2422 2015-06-05 12:04:13Z ufla $
  25. !! Software governed by the CeCILL licence (NEMOGCM/NEMO_CeCILL.txt)
  26. !!---------------------------------------------------------------------------------
  27. CONTAINS
  28. SUBROUTINE trd_mxl_rst_write( kt )
  29. !!--------------------------------------------------------------------------------
  30. !! *** SUBROUTINE trd_mxl_rst_wri ***
  31. !!
  32. !! ** Purpose : Write mixed-layer diagnostics restart fields.
  33. !!--------------------------------------------------------------------------------
  34. INTEGER, INTENT( in ) :: kt ! ocean time-step index
  35. !
  36. CHARACTER (len=35) :: charout
  37. INTEGER :: jk ! loop indice
  38. CHARACTER(LEN=20) :: clkt ! ocean time-step deine as a character
  39. CHARACTER(LEN=50) :: clname ! output restart file name
  40. CHARACTER(LEN=256) :: clpath ! full path to restart file
  41. !!--------------------------------------------------------------------------------
  42. ! to get better performances with NetCDF format:
  43. ! we open and define the ocean restart_mxl file one time step before writing the data (-> at nitrst - 1)
  44. ! except if we write ocean restart_mxl files every time step or if an ocean restart_mxl file was writen at nitend - 1
  45. IF( kt == nitrst - 1 .OR. nstock == 1 .OR. ( kt == nitend .AND. MOD( nitend - 1, nstock ) == 0 ) ) THEN
  46. ! beware of the format used to write kt (default is i8.8, that should be large enough...)
  47. IF( nitrst > 999999999 ) THEN ; WRITE(clkt, * ) nitrst
  48. ELSE ; WRITE(clkt, '(i8.8)') nitrst
  49. ENDIF
  50. ! create the file
  51. clname = TRIM(cexper)//"_"//TRIM(ADJUSTL(clkt))//"_"//TRIM(cn_trdrst_out)
  52. clpath = TRIM(cn_ocerst_outdir)
  53. IF( clpath(LEN_TRIM(clpath):) /= '/' ) clpath = TRIM(clpath) // '/'
  54. IF(lwp) THEN
  55. WRITE(numout,*)
  56. SELECT CASE ( jprstlib )
  57. CASE ( jprstdimg ) ; WRITE(numout,*) ' open ocean restart_mxl binary file: '//clname
  58. CASE DEFAULT ; WRITE(numout,*) ' open ocean restart_mxl NetCDF file: '//clname
  59. END SELECT
  60. IF( kt == nitrst - 1 ) THEN ; WRITE(numout,*) ' kt = nitrst - 1 = ', kt,' date= ', ndastp
  61. ELSE ; WRITE(numout,*) ' kt = ' , kt,' date= ', ndastp
  62. ENDIF
  63. ENDIF
  64. CALL iom_open( TRIM(clpath)//TRIM(clname), nummxlw, ldwrt = .TRUE., kiolib = jprstlib )
  65. ENDIF
  66. IF( kt == nitrst .AND. lwp ) THEN
  67. WRITE(numout,*)
  68. WRITE(numout,*) 'trdmxl_rst: output for ML diags. restart, with trd_mxl_rst_write routine kt =', kt
  69. WRITE(numout,*) '~~~~~~~~~~'
  70. WRITE(numout,*)
  71. ENDIF
  72. IF( ln_trdmxl_instant ) THEN
  73. !-- Temperature
  74. CALL iom_rstput( kt, nitrst, nummxlw, 'tmlbb' , tmlbb )
  75. CALL iom_rstput( kt, nitrst, nummxlw, 'tmlbn' , tmlbn )
  76. CALL iom_rstput( kt, nitrst, nummxlw, 'tmlatfb' , tmlatfb )
  77. !-- Salinity
  78. CALL iom_rstput( kt, nitrst, nummxlw, 'smlbb' , smlbb )
  79. CALL iom_rstput( kt, nitrst, nummxlw, 'smlbn' , smlbn )
  80. CALL iom_rstput( kt, nitrst, nummxlw, 'smlatfb' , smlatfb )
  81. ELSE
  82. CALL iom_rstput( kt, nitrst, nummxlw, 'hmxlbn' , hmxlbn )
  83. !-- Temperature
  84. CALL iom_rstput( kt, nitrst, nummxlw, 'tmlbn' , tmlbn )
  85. CALL iom_rstput( kt, nitrst, nummxlw, 'tml_sumb' , tml_sumb )
  86. DO jk = 1, jpltrd
  87. IF( jk < 10 ) THEN ; WRITE(charout,FMT="('tmltrd_csum_ub_', I1)") jk
  88. ELSE ; WRITE(charout,FMT="('tmltrd_csum_ub_', I2)") jk
  89. ENDIF
  90. CALL iom_rstput( kt, nitrst, nummxlw, charout, tmltrd_csum_ub(:,:,jk) )
  91. ENDDO
  92. CALL iom_rstput( kt, nitrst, nummxlw, 'tmltrd_atf_sumb' , tmltrd_atf_sumb )
  93. !-- Salinity
  94. CALL iom_rstput( kt, nitrst, nummxlw, 'smlbn' , smlbn )
  95. CALL iom_rstput( kt, nitrst, nummxlw, 'sml_sumb' , sml_sumb )
  96. DO jk = 1, jpltrd
  97. IF( jk < 10 ) THEN ; WRITE(charout,FMT="('smltrd_csum_ub_', I1)") jk
  98. ELSE ; WRITE(charout,FMT="('smltrd_csum_ub_', I2)") jk
  99. ENDIF
  100. CALL iom_rstput( kt, nitrst, nummxlw, charout , smltrd_csum_ub(:,:,jk) )
  101. ENDDO
  102. CALL iom_rstput( kt, nitrst, nummxlw, 'smltrd_atf_sumb' , smltrd_atf_sumb )
  103. ENDIF
  104. !
  105. IF( kt == nitrst ) THEN
  106. CALL iom_close( nummxlw ) ! close the restart file (only at last time step)
  107. lrst_oce = .FALSE.
  108. ENDIF
  109. !
  110. END SUBROUTINE trd_mxl_rst_write
  111. SUBROUTINE trd_mxl_rst_read
  112. !!----------------------------------------------------------------------------
  113. !! *** SUBROUTINE trd_mxl_rst_lec ***
  114. !!
  115. !! ** Purpose : Read file for mixed-layer diagnostics restart.
  116. !!----------------------------------------------------------------------------
  117. INTEGER :: inum ! temporary logical unit
  118. !
  119. CHARACTER (len=35) :: charout
  120. INTEGER :: jk ! loop indice
  121. INTEGER :: jlibalt = jprstlib
  122. LOGICAL :: llok
  123. CHARACTER(LEN=256) :: clpath ! full path to restart file
  124. !!-----------------------------------------------------------------------------
  125. IF(lwp) THEN
  126. WRITE(numout,*)
  127. WRITE(numout,*) ' trd_mxl_rst_read : read the NetCDF mixed layer trend restart file'
  128. WRITE(numout,*) ' ~~~~~~~~~~~~~~~~'
  129. ENDIF
  130. clpath = TRIM(cn_ocerst_indir)
  131. IF( clpath(LEN_TRIM(clpath):) /= '/' ) clpath = TRIM(clpath) // '/'
  132. IF ( jprstlib == jprstdimg ) THEN
  133. ! eventually read netcdf file (monobloc) for restarting on different number of processors
  134. ! if {cn_trdrst_in}.nc exists, then set jlibalt to jpnf90
  135. INQUIRE( FILE = TRIM(clpath)//TRIM(cn_trdrst_in)//'.nc', EXIST = llok )
  136. IF ( llok ) THEN ; jlibalt = jpnf90
  137. ELSE ; jlibalt = jprstlib
  138. ENDIF
  139. ENDIF
  140. CALL iom_open( TRIM(clpath)//TRIM(cn_trdrst_in), inum, kiolib = jlibalt )
  141. IF( ln_trdmxl_instant ) THEN
  142. !-- Temperature
  143. CALL iom_get( inum, jpdom_autoglo, 'tmlbb' , tmlbb )
  144. CALL iom_get( inum, jpdom_autoglo, 'tmlbn' , tmlbn )
  145. CALL iom_get( inum, jpdom_autoglo, 'tmlatfb' , tmlatfb )
  146. !
  147. !-- Salinity
  148. CALL iom_get( inum, jpdom_autoglo, 'smlbb' , smlbb )
  149. CALL iom_get( inum, jpdom_autoglo, 'smlbn' , smlbn )
  150. CALL iom_get( inum, jpdom_autoglo, 'smlatfb' , smlatfb )
  151. ELSE
  152. CALL iom_get( inum, jpdom_autoglo, 'hmxlbn' , hmxlbn ) ! needed for hmxl_sum
  153. !
  154. !-- Temperature
  155. CALL iom_get( inum, jpdom_autoglo, 'tmlbn' , tmlbn ) ! needed for tml_sum
  156. CALL iom_get( inum, jpdom_autoglo, 'tml_sumb' , tml_sumb )
  157. DO jk = 1, jpltrd
  158. IF( jk < 10 ) THEN ; WRITE(charout,FMT="('tmltrd_csum_ub_', I1)") jk
  159. ELSE ; WRITE(charout,FMT="('tmltrd_csum_ub_', I2)") jk
  160. ENDIF
  161. CALL iom_get( inum, jpdom_autoglo, charout, tmltrd_csum_ub(:,:,jk) )
  162. END DO
  163. CALL iom_get( inum, jpdom_autoglo, 'tmltrd_atf_sumb' , tmltrd_atf_sumb)
  164. !
  165. !-- Salinity
  166. CALL iom_get( inum, jpdom_autoglo, 'smlbn' , smlbn ) ! needed for sml_sum
  167. CALL iom_get( inum, jpdom_autoglo, 'sml_sumb' , sml_sumb )
  168. DO jk = 1, jpltrd
  169. IF( jk < 10 ) THEN ; WRITE(charout,FMT="('smltrd_csum_ub_', I1)") jk
  170. ELSE ; WRITE(charout,FMT="('smltrd_csum_ub_', I2)") jk
  171. ENDIF
  172. CALL iom_get( inum, jpdom_autoglo, charout, smltrd_csum_ub(:,:,jk) )
  173. END DO
  174. CALL iom_get( inum, jpdom_autoglo, 'smltrd_atf_sumb' , smltrd_atf_sumb)
  175. !
  176. CALL iom_close( inum )
  177. ENDIF
  178. !
  179. END SUBROUTINE trd_mxl_rst_read
  180. !!=================================================================================
  181. END MODULE trdmxl_rst