limrst_2.F90 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285
  1. MODULE limrst_2
  2. !!======================================================================
  3. !! *** MODULE limrst_2 ***
  4. !! Ice restart : write the ice restart file
  5. !!======================================================================
  6. !! History : 2.0 ! 01-04 (C. Ethe, G. Madec) Original code
  7. !! ! 06-07 (S. Masson) use IOM for restart read/write
  8. !! 3.3 ! 09-05 (G.Garric) addition of the lim2_evp case
  9. !!----------------------------------------------------------------------
  10. #if defined key_lim2
  11. !!----------------------------------------------------------------------
  12. !! 'key_lim2' : LIM 2.0 sea-ice model
  13. !!----------------------------------------------------------------------
  14. !! lim_rst_opn_2 : open ice restart file
  15. !! lim_rst_write_2 : write of the ice restart file
  16. !! lim_rst_read_2 : read the ice restart file
  17. !!----------------------------------------------------------------------
  18. USE dom_oce ! ocean domain
  19. USE ice_2 ! LIM-2: sea-ice variables
  20. USE sbc_oce ! Surface Boundary Condition: ocean
  21. USE sbc_ice ! Surface Boundary Condition: sea-ice
  22. USE in_out_manager ! I/O manager
  23. USE iom ! I/O library
  24. IMPLICIT NONE
  25. PRIVATE
  26. PUBLIC lim_rst_opn_2 ! routine called by sbcice_lim_2.F90
  27. PUBLIC lim_rst_write_2 ! routine called by sbcice_lim_2.F90
  28. PUBLIC lim_rst_read_2 ! routine called by iceini_2.F90
  29. LOGICAL, PUBLIC :: lrst_ice !: logical to control the ice restart write
  30. INTEGER, PUBLIC :: numrir, numriw !: logical unit for ice restart (read and write)
  31. !!----------------------------------------------------------------------
  32. !! NEMO/LIM2 3.3 , UCL - NEMO Consortium (2010)
  33. !! $Id: limrst_2.F90 2528 2010-12-27 17:33:53Z rblod $
  34. !! Software governed by the CeCILL licence (NEMOGCM/NEMO_CeCILL.txt)
  35. !!----------------------------------------------------------------------
  36. CONTAINS
  37. SUBROUTINE lim_rst_opn_2( kt )
  38. !!----------------------------------------------------------------------
  39. !! *** lim_rst_opn_2 ***
  40. !!
  41. !! ** purpose : output of sea-ice variable in a netcdf file
  42. !!----------------------------------------------------------------------
  43. INTEGER, INTENT(in) :: kt ! number of iteration
  44. !
  45. CHARACTER(LEN=20) :: clkt ! ocean time-step deine as a character
  46. CHARACTER(LEN=50) :: clname ! ice output restart file name
  47. CHARACTER(len=150) :: clpath ! full path to ice output restart file
  48. !!----------------------------------------------------------------------
  49. !
  50. IF( kt == nit000 ) lrst_ice = .FALSE. ! default definition
  51. ! to get better performances with NetCDF format:
  52. ! we open and define the ice restart file one ice time step before writing the data (-> at nitrst - 2*nn_fsbc + 1)
  53. ! except if we write ice restart files every ice time step or if an ice restart file was writen at nitend - 2*nn_fsbc + 1
  54. IF( kt == nitrst - 2*nn_fsbc + 1 .OR. nstock == nn_fsbc .OR. ( kt == nitend - nn_fsbc + 1 .AND. .NOT. lrst_ice ) ) THEN
  55. IF( nitrst <= nitend .AND. nitrst > 0 ) THEN
  56. ! beware of the format used to write kt (default is i8.8, that should be large enough...)
  57. IF( nitrst > 99999999 ) THEN ; WRITE(clkt, * ) nitrst
  58. ELSE ; WRITE(clkt, '(i8.8)') nitrst
  59. ENDIF
  60. ! create the file
  61. clname = TRIM(cexper)//"_"//TRIM(ADJUSTL(clkt))//"_"//TRIM(cn_icerst_out)
  62. clpath = TRIM(cn_icerst_outdir)
  63. IF( clpath(LEN_TRIM(clpath):) /= '/' ) clpath = TRIM(clpath)//'/'
  64. IF(lwp) THEN
  65. WRITE(numout,*)
  66. SELECT CASE ( jprstlib )
  67. CASE ( jprstdimg )
  68. WRITE(numout,*) ' open ice restart binary file: ',TRIM(clpath)//clname
  69. CASE DEFAULT
  70. WRITE(numout,*) ' open ice restart NetCDF file: ',TRIM(clpath)//clname
  71. END SELECT
  72. IF( kt == nitrst - 2*nn_fsbc + 1 ) THEN
  73. WRITE(numout,*) ' kt = nitrst - 2*nn_fsbc + 1 = ', kt,' date= ', ndastp
  74. ELSE ; WRITE(numout,*) ' kt = ' , kt,' date= ', ndastp
  75. ENDIF
  76. ENDIF
  77. CALL iom_open( TRIM(clpath)//TRIM(clname), numriw, ldwrt = .TRUE., kiolib = jprstlib )
  78. lrst_ice = .TRUE.
  79. ENDIF
  80. ENDIF
  81. !
  82. END SUBROUTINE lim_rst_opn_2
  83. SUBROUTINE lim_rst_write_2( kt )
  84. !!----------------------------------------------------------------------
  85. !! *** lim_rst_write_2 ***
  86. !!
  87. !! ** purpose : output of sea-ice variable in a netcdf file
  88. !!----------------------------------------------------------------------
  89. INTEGER, INTENT(in) :: kt ! number of iteration
  90. !
  91. INTEGER :: iter ! kt + nn_fsbc -1
  92. !!----------------------------------------------------------------------
  93. iter = kt + nn_fsbc - 1 ! ice restarts are written at kt == nitrst - nn_fsbc + 1
  94. IF( iter == nitrst ) THEN
  95. IF(lwp) WRITE(numout,*)
  96. IF(lwp) WRITE(numout,*) 'lim_rst_write_2 : write ice restart file kt =', kt
  97. IF(lwp) WRITE(numout,*) '~~~~~~~~~~~~~~~'
  98. ENDIF
  99. ! Write in numriw (if iter == nitrst)
  100. ! ------------------
  101. ! ! calendar control
  102. CALL iom_rstput( iter, nitrst, numriw, 'kt_ice', REAL( iter, wp) )
  103. CALL iom_rstput( iter, nitrst, numriw, 'hicif' , hicif (:,:) ) ! prognostic variables
  104. CALL iom_rstput( iter, nitrst, numriw, 'hsnif' , hsnif (:,:) )
  105. CALL iom_rstput( iter, nitrst, numriw, 'frld' , frld (:,:) )
  106. CALL iom_rstput( iter, nitrst, numriw, 'sist' , sist (:,:) )
  107. CALL iom_rstput( iter, nitrst, numriw, 'tbif1' , tbif (:,:,1) )
  108. CALL iom_rstput( iter, nitrst, numriw, 'tbif2' , tbif (:,:,2) )
  109. CALL iom_rstput( iter, nitrst, numriw, 'tbif3' , tbif (:,:,3) )
  110. CALL iom_rstput( iter, nitrst, numriw, 'u_ice' , u_ice (:,:) )
  111. CALL iom_rstput( iter, nitrst, numriw, 'v_ice' , v_ice (:,:) )
  112. CALL iom_rstput( iter, nitrst, numriw, 'qstoif' , qstoif(:,:) )
  113. CALL iom_rstput( iter, nitrst, numriw, 'fsbbq' , fsbbq (:,:) )
  114. #if ! defined key_lim2_vp
  115. CALL iom_rstput( iter, nitrst, numriw, 'stress1_i' , stress1_i (:,:) ) ! EVP rheology
  116. CALL iom_rstput( iter, nitrst, numriw, 'stress2_i' , stress2_i (:,:) )
  117. CALL iom_rstput( iter, nitrst, numriw, 'stress12_i' , stress12_i(:,:) )
  118. #endif
  119. CALL iom_rstput( iter, nitrst, numriw, 'sxice' , sxice (:,:) )
  120. CALL iom_rstput( iter, nitrst, numriw, 'syice' , syice (:,:) )
  121. CALL iom_rstput( iter, nitrst, numriw, 'sxxice' , sxxice(:,:) )
  122. CALL iom_rstput( iter, nitrst, numriw, 'syyice' , syyice(:,:) )
  123. CALL iom_rstput( iter, nitrst, numriw, 'sxyice' , sxyice(:,:) )
  124. CALL iom_rstput( iter, nitrst, numriw, 'sxsn' , sxsn (:,:) )
  125. CALL iom_rstput( iter, nitrst, numriw, 'sysn' , sysn (:,:) )
  126. CALL iom_rstput( iter, nitrst, numriw, 'sxxsn' , sxxsn (:,:) )
  127. CALL iom_rstput( iter, nitrst, numriw, 'syysn' , syysn (:,:) )
  128. CALL iom_rstput( iter, nitrst, numriw, 'sxysn' , sxysn (:,:) )
  129. CALL iom_rstput( iter, nitrst, numriw, 'sxa' , sxa (:,:) )
  130. CALL iom_rstput( iter, nitrst, numriw, 'sya' , sya (:,:) )
  131. CALL iom_rstput( iter, nitrst, numriw, 'sxxa' , sxxa (:,:) )
  132. CALL iom_rstput( iter, nitrst, numriw, 'syya' , syya (:,:) )
  133. CALL iom_rstput( iter, nitrst, numriw, 'sxya' , sxya (:,:) )
  134. CALL iom_rstput( iter, nitrst, numriw, 'sxc0' , sxc0 (:,:) )
  135. CALL iom_rstput( iter, nitrst, numriw, 'syc0' , syc0 (:,:) )
  136. CALL iom_rstput( iter, nitrst, numriw, 'sxxc0' , sxxc0 (:,:) )
  137. CALL iom_rstput( iter, nitrst, numriw, 'syyc0' , syyc0 (:,:) )
  138. CALL iom_rstput( iter, nitrst, numriw, 'sxyc0' , sxyc0 (:,:) )
  139. CALL iom_rstput( iter, nitrst, numriw, 'sxc1' , sxc1 (:,:) )
  140. CALL iom_rstput( iter, nitrst, numriw, 'syc1' , syc1 (:,:) )
  141. CALL iom_rstput( iter, nitrst, numriw, 'sxxc1' , sxxc1 (:,:) )
  142. CALL iom_rstput( iter, nitrst, numriw, 'syyc1' , syyc1 (:,:) )
  143. CALL iom_rstput( iter, nitrst, numriw, 'sxyc1' , sxyc1 (:,:) )
  144. CALL iom_rstput( iter, nitrst, numriw, 'sxc2' , sxc2 (:,:) )
  145. CALL iom_rstput( iter, nitrst, numriw, 'syc2' , syc2 (:,:) )
  146. CALL iom_rstput( iter, nitrst, numriw, 'sxxc2' , sxxc2 (:,:) )
  147. CALL iom_rstput( iter, nitrst, numriw, 'syyc2' , syyc2 (:,:) )
  148. CALL iom_rstput( iter, nitrst, numriw, 'sxyc2' , sxyc2 (:,:) )
  149. CALL iom_rstput( iter, nitrst, numriw, 'sxst' , sxst (:,:) )
  150. CALL iom_rstput( iter, nitrst, numriw, 'syst' , syst (:,:) )
  151. CALL iom_rstput( iter, nitrst, numriw, 'sxxst' , sxxst (:,:) )
  152. CALL iom_rstput( iter, nitrst, numriw, 'syyst' , syyst (:,:) )
  153. CALL iom_rstput( iter, nitrst, numriw, 'sxyst' , sxyst (:,:) )
  154. IF( iter == nitrst ) THEN
  155. CALL iom_close( numriw ) ! close the restart file
  156. lrst_ice = .FALSE.
  157. ENDIF
  158. !
  159. END SUBROUTINE lim_rst_write_2
  160. SUBROUTINE lim_rst_read_2
  161. !!----------------------------------------------------------------------
  162. !! *** lim_rst_read_2 ***
  163. !!
  164. !! ** purpose : read of sea-ice variable restart in a netcdf file
  165. !!----------------------------------------------------------------------
  166. REAL(wp) :: ziter
  167. INTEGER :: jlibalt = jprstlib
  168. LOGICAL :: llok
  169. INTEGER :: itest
  170. !!----------------------------------------------------------------------
  171. IF(lwp) THEN
  172. WRITE(numout,*)
  173. WRITE(numout,*) 'lim_rst_read_2 : read ice NetCDF restart file'
  174. WRITE(numout,*) '~~~~~~~~~~~~~~'
  175. ENDIF
  176. IF ( jprstlib == jprstdimg ) THEN
  177. ! eventually read netcdf file (monobloc) for restarting on different number of processors
  178. ! if {cn_icerst_in}.nc exists, then set jlibalt to jpnf90
  179. INQUIRE( FILE = TRIM(cn_icerst_indir)//'/'//TRIM(cn_icerst_in)//'.nc', EXIST = llok )
  180. IF ( llok ) THEN ; jlibalt = jpnf90 ; ELSE ; jlibalt = jprstlib ; ENDIF
  181. ENDIF
  182. CALL iom_open ( TRIM(cn_icerst_indir)//'/'//TRIM(cn_icerst_in), numrir, kiolib = jlibalt )
  183. CALL iom_get( numrir, 'kt_ice' , ziter )
  184. IF(lwp) WRITE(numout,*) ' read ice restart file at time step : ', INT( ziter )
  185. IF(lwp) WRITE(numout,*) ' in any case we force it to nit000 - 1 : ', nit000 - 1
  186. !Control of date
  187. IF( ( nit000 - INT(ziter) ) /= 1 .AND. ABS( nrstdt ) == 1 ) &
  188. & CALL ctl_stop( 'lim_rst_read ===>>>> : problem with nit000 in ice restart', &
  189. & ' verify the file or rerun with the value 0 for the', &
  190. & ' control of time parameter nrstdt' )
  191. CALL iom_get( numrir, jpdom_autoglo, 'hicif' , hicif )
  192. CALL iom_get( numrir, jpdom_autoglo, 'hsnif' , hsnif )
  193. CALL iom_get( numrir, jpdom_autoglo, 'frld' , frld )
  194. CALL iom_get( numrir, jpdom_autoglo, 'sist' , sist )
  195. CALL iom_get( numrir, jpdom_autoglo, 'tbif1' , tbif(:,:,1) )
  196. CALL iom_get( numrir, jpdom_autoglo, 'tbif2' , tbif(:,:,2) )
  197. CALL iom_get( numrir, jpdom_autoglo, 'tbif3' , tbif(:,:,3) )
  198. itest = iom_varid( numrir, 'u_ice', ldstop = .FALSE. ) ! test if the variable u_ice is included in the file
  199. IF( itest > 0 ) THEN ! yes -> new restart files (from NEMO 3.2)
  200. CALL iom_get( numrir, jpdom_autoglo, 'u_ice', u_ice )
  201. CALL iom_get( numrir, jpdom_autoglo, 'v_ice', v_ice )
  202. ELSE ! no -> old restart file with variable called [uv]i_ice (inroduced in NEMO 3.0)
  203. CALL iom_get( numrir, jpdom_autoglo, 'ui_ice', u_ice )
  204. CALL iom_get( numrir, jpdom_autoglo, 'vi_ice', v_ice )
  205. ENDIF
  206. CALL iom_get( numrir, jpdom_autoglo, 'qstoif' , qstoif )
  207. CALL iom_get( numrir, jpdom_autoglo, 'fsbbq' , fsbbq )
  208. #if ! defined key_lim2_vp
  209. CALL iom_get( numrir, jpdom_autoglo, 'stress1_i' , stress1_i )
  210. CALL iom_get( numrir, jpdom_autoglo, 'stress2_i' , stress2_i )
  211. CALL iom_get( numrir, jpdom_autoglo, 'stress12_i' , stress12_i )
  212. #endif
  213. CALL iom_get( numrir, jpdom_autoglo, 'sxice' , sxice )
  214. CALL iom_get( numrir, jpdom_autoglo, 'syice' , syice )
  215. CALL iom_get( numrir, jpdom_autoglo, 'sxxice' , sxxice )
  216. CALL iom_get( numrir, jpdom_autoglo, 'syyice' , syyice )
  217. CALL iom_get( numrir, jpdom_autoglo, 'sxyice' , sxyice )
  218. CALL iom_get( numrir, jpdom_autoglo, 'sxsn' , sxsn )
  219. CALL iom_get( numrir, jpdom_autoglo, 'sysn' , sysn )
  220. CALL iom_get( numrir, jpdom_autoglo, 'sxxsn' , sxxsn )
  221. CALL iom_get( numrir, jpdom_autoglo, 'syysn' , syysn )
  222. CALL iom_get( numrir, jpdom_autoglo, 'sxysn' , sxysn )
  223. CALL iom_get( numrir, jpdom_autoglo, 'sxa' , sxa )
  224. CALL iom_get( numrir, jpdom_autoglo, 'sya' , sya )
  225. CALL iom_get( numrir, jpdom_autoglo, 'sxxa' , sxxa )
  226. CALL iom_get( numrir, jpdom_autoglo, 'syya' , syya )
  227. CALL iom_get( numrir, jpdom_autoglo, 'sxya' , sxya )
  228. CALL iom_get( numrir, jpdom_autoglo, 'sxc0' , sxc0 )
  229. CALL iom_get( numrir, jpdom_autoglo, 'syc0' , syc0 )
  230. CALL iom_get( numrir, jpdom_autoglo, 'sxxc0' , sxxc0 )
  231. CALL iom_get( numrir, jpdom_autoglo, 'syyc0' , syyc0 )
  232. CALL iom_get( numrir, jpdom_autoglo, 'sxyc0' , sxyc0 )
  233. CALL iom_get( numrir, jpdom_autoglo, 'sxc1' , sxc1 )
  234. CALL iom_get( numrir, jpdom_autoglo, 'syc1' , syc1 )
  235. CALL iom_get( numrir, jpdom_autoglo, 'sxxc1' , sxxc1 )
  236. CALL iom_get( numrir, jpdom_autoglo, 'syyc1' , syyc1 )
  237. CALL iom_get( numrir, jpdom_autoglo, 'sxyc1' , sxyc1 )
  238. CALL iom_get( numrir, jpdom_autoglo, 'sxc2' , sxc2 )
  239. CALL iom_get( numrir, jpdom_autoglo, 'syc2' , syc2 )
  240. CALL iom_get( numrir, jpdom_autoglo, 'sxxc2' , sxxc2 )
  241. CALL iom_get( numrir, jpdom_autoglo, 'syyc2' , syyc2 )
  242. CALL iom_get( numrir, jpdom_autoglo, 'sxyc2' , sxyc2 )
  243. CALL iom_get( numrir, jpdom_autoglo, 'sxst' , sxst )
  244. CALL iom_get( numrir, jpdom_autoglo, 'syst' , syst )
  245. CALL iom_get( numrir, jpdom_autoglo, 'sxxst' , sxxst )
  246. CALL iom_get( numrir, jpdom_autoglo, 'syyst' , syyst )
  247. CALL iom_get( numrir, jpdom_autoglo, 'sxyst' , sxyst )
  248. CALL iom_close( numrir )
  249. !
  250. END SUBROUTINE lim_rst_read_2
  251. #else
  252. !!----------------------------------------------------------------------
  253. !! Default option : Empty module NO LIM 2.0 sea-ice model
  254. !!----------------------------------------------------------------------
  255. #endif
  256. !!======================================================================
  257. END MODULE limrst_2