sedrst.F90 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283
  1. MODULE sedrst
  2. #if defined key_sed
  3. !!======================================================================
  4. !! *** MODULE sedrst ***
  5. !! Read and write the restart files for sediment
  6. !!======================================================================
  7. !!----------------------------------------------------------------------
  8. !! * Modules used
  9. !! ==============
  10. USE sed
  11. USE sedarr
  12. !! * Accessibility
  13. IMPLICIT NONE
  14. PRIVATE
  15. !! * Accessibility
  16. PUBLIC sed_rst_read
  17. PUBLIC sed_rst_wri
  18. !! * Module variables
  19. INTEGER, PUBLIC :: numrsr, numrsw !: logical unit for sed restart (read and write)
  20. !! $Id: sedrst.F90 2355 2015-05-20 07:11:50Z ufla $
  21. CONTAINS
  22. SUBROUTINE sed_rst_read
  23. !!----------------------------------------------------------------------
  24. !! *** ROUTINE sed_rst_read ***
  25. !!
  26. !! ** Purpose : Initialization of sediment module
  27. !! - sets initial sediment composition
  28. !! ( only clay or reading restart file )
  29. !!
  30. !! History :
  31. !! ! 06-07 (C. Ethe) original
  32. !!----------------------------------------------------------------------
  33. !! * Modules used
  34. USE iom
  35. !! * local declarations
  36. INTEGER :: ji, jk, jn
  37. REAL(wp), ALLOCATABLE, DIMENSION(:,:,:,:) :: zdta
  38. REAL(wp), ALLOCATABLE, DIMENSION(:,:,: ) :: zdta1
  39. REAL(wp), ALLOCATABLE, DIMENSION(:,: ) :: zhipor
  40. REAL(wp) :: zkt
  41. CHARACTER(len = 20) :: cltra
  42. INTEGER :: jlibalt = jprstlib
  43. LOGICAL :: llok
  44. !--------------------------------------------------------------------
  45. WRITE(numsed,*) ' '
  46. WRITE(numsed,*) ' Initilization of Sediment components from restart'
  47. WRITE(numsed,*) ' '
  48. ALLOCATE( zdta(jpi,jpj,jpksed,jptrased), zdta1(jpi,jpj,jpksed,2), zhipor(jpoce,jpksed) )
  49. IF ( jprstlib == jprstdimg ) THEN
  50. ! eventually read netcdf file (monobloc) for restarting on different number of processors
  51. ! if restart_sed.nc exists, then set jlibalt to jpnf90
  52. INQUIRE( FILE = 'restart_sed.nc', EXIST = llok )
  53. IF ( llok ) THEN ; jlibalt = jpnf90 ; ELSE ; jlibalt = jprstlib ; ENDIF
  54. ENDIF
  55. CALL iom_open( 'restart_sed', numrsr, kiolib = jlibalt )
  56. CALL iom_get( numrsr, 'kt' , zkt ) ! time-step
  57. DO jn = 1, jptrased
  58. cltra = sedtrcd(jn)
  59. CALL iom_get( numrsr, jpdom_unknown, cltra, zdta(:,:,:,jn), &
  60. & kstart=(/1,1,1/), kcount=(/jpi,jpj,jpksed/) )
  61. ENDDO
  62. CALL pack_arr( jpoce, solcp(1:jpoce,1:jpksed,jsopal), &
  63. & zdta(1:jpi,1:jpj,1:jpksed,1), iarroce(1:jpoce) )
  64. CALL pack_arr( jpoce, solcp(1:jpoce,1:jpksed,jsclay), &
  65. & zdta(1:jpi,1:jpj,1:jpksed,2), iarroce(1:jpoce) )
  66. CALL pack_arr( jpoce, solcp(1:jpoce,1:jpksed,jspoc), &
  67. & zdta(1:jpi,1:jpj,1:jpksed,3), iarroce(1:jpoce) )
  68. CALL pack_arr( jpoce, solcp(1:jpoce,1:jpksed,jscal), &
  69. & zdta(1:jpi,1:jpj,1:jpksed,4), iarroce(1:jpoce) )
  70. CALL pack_arr( jpoce, pwcp(1:jpoce,1:jpksed,jwsil), &
  71. & zdta(1:jpi,1:jpj,1:jpksed,5), iarroce(1:jpoce) )
  72. CALL pack_arr( jpoce, pwcp(1:jpoce,1:jpksed,jwoxy), &
  73. & zdta(1:jpi,1:jpj,1:jpksed,6), iarroce(1:jpoce) )
  74. CALL pack_arr( jpoce, pwcp(1:jpoce,1:jpksed,jwdic), &
  75. & zdta(1:jpi,1:jpj,1:jpksed,7), iarroce(1:jpoce) )
  76. CALL pack_arr( jpoce, pwcp(1:jpoce,1:jpksed,jwno3), &
  77. & zdta(1:jpi,1:jpj,1:jpksed,8), iarroce(1:jpoce) )
  78. CALL pack_arr( jpoce, pwcp(1:jpoce,1:jpksed,jwpo4), &
  79. & zdta(1:jpi,1:jpj,1:jpksed,9), iarroce(1:jpoce) )
  80. CALL pack_arr( jpoce, pwcp(1:jpoce,1:jpksed,jwalk), &
  81. & zdta(1:jpi,1:jpj,1:jpksed,10), iarroce(1:jpoce) )
  82. CALL pack_arr( jpoce, pwcp(1:jpoce,1:jpksed,jwc13), &
  83. & zdta(1:jpi,1:jpj,1:jpksed,11), iarroce(1:jpoce) )
  84. DO jn = 1, 2
  85. cltra = seddia3d(jn)
  86. CALL iom_get( numrsr, jpdom_unknown, cltra, zdta1(:,:,:,jn), &
  87. & kstart=(/1,1,1/), kcount=(/jpi,jpj,jpksed/) )
  88. ENDDO
  89. zhipor(:,:) = 0.
  90. CALL pack_arr( jpoce, zhipor(1:jpoce,1:jpksed), &
  91. & zdta1(1:jpi,1:jpj,1:jpksed,1), iarroce(1:jpoce) )
  92. ! Initialization of [h+] in mol/kg
  93. DO jk = 1, jpksed
  94. DO ji = 1, jpoce
  95. hipor (ji,jk) = 10.**( -1. * zhipor(ji,jk) )
  96. ENDDO
  97. ENDDO
  98. CALL pack_arr( jpoce, co3por(1:jpoce,1:jpksed), &
  99. & zdta1(1:jpi,1:jpj,1:jpksed,2), iarroce(1:jpoce) )
  100. ! Initialization of sediment composant only ie jk=2 to jk=jpksed
  101. ! ( nothing in jk=1)
  102. solcp(1:jpoce,1,:) = 0.
  103. pwcp (1:jpoce,1,:) = 0.
  104. DEALLOCATE( zdta )
  105. DEALLOCATE( zdta1 )
  106. DEALLOCATE( zhipor )
  107. END SUBROUTINE sed_rst_read
  108. SUBROUTINE sed_rst_wri( kt )
  109. !!----------------------------------------------------------------------
  110. !! *** ROUTINE sed_rst_wri ***
  111. !!
  112. !! ** Purpose : save field which are necessary for sediment restart
  113. !!
  114. !! History :
  115. !! ! 06-07 (C. Ethe) original
  116. !!----------------------------------------------------------------------
  117. !!* Modules used
  118. USE ioipsl
  119. !! *Arguments
  120. INTEGER, INTENT(in) :: kt ! number of iteration
  121. !! * local declarations
  122. INTEGER :: ji, jk
  123. INTEGER :: ic, jc, jn, itime
  124. REAL(wp) :: zdate0
  125. REAL(wp), DIMENSION(1) :: zinfo
  126. CHARACTER(len=50) :: clname,cln
  127. CHARACTER(len=20) :: cltra
  128. REAL(wp), DIMENSION(:,:) , ALLOCATABLE :: zdta
  129. !! -----------------------------------------------------------------------
  130. ALLOCATE( zdta(jpoce,jpksed) )
  131. IF( MOD(kt,nstock) == 0 .OR. kt == nitsedend ) THEN
  132. !! 0. initialisations
  133. !! ------------------
  134. IF(lwp) WRITE(numsed,*) ' '
  135. IF(lwp) WRITE(numsed,*) 'sed_rst_write : write the sediment restart file in NetCDF format ', &
  136. 'at it= ',kt
  137. IF(lwp) WRITE(numsed,*) '~~~~~~~~~'
  138. !! 1. WRITE in nutwrs
  139. !! ------------------
  140. ic = 1
  141. DO jc = 1,16
  142. IF( cexper(jc:jc) /= ' ') ic = jc
  143. END DO
  144. WRITE( cln,'("_",i5.5,i2.2,i2.2,"_restart.sed")') nyear, nmonth, nday
  145. clname = cexper(1:ic)//cln
  146. itime = 0
  147. CALL ymds2ju( nyear, nmonth, nday, rdt, zdate0 )
  148. zdate0 = zdate0 - adatrj ! set calendar origin to the beginning of the experiment
  149. CALL restini( 'NONE', jpi, jpj, glamt, gphit, jpksed, dz, &
  150. & clname, itime, zdate0, dtsed*nstock, numrsw, domain_id=nidom )
  151. zinfo(1) = REAL( kt)
  152. CALL restput( numrsw, 'kt', 1,1, 1,0, zinfo )
  153. ! Back to 2D geometry
  154. CALL unpack_arr( jpoce, trcsedi(1:jpi,1:jpj,1:jpksed,1) , iarroce(1:jpoce), &
  155. & solcp(1:jpoce,1:jpksed,jsopal ) )
  156. CALL unpack_arr( jpoce, trcsedi(1:jpi,1:jpj,1:jpksed,2) , iarroce(1:jpoce), &
  157. & solcp(1:jpoce,1:jpksed,jsclay ) )
  158. CALL unpack_arr( jpoce, trcsedi(1:jpi,1:jpj,1:jpksed,3) , iarroce(1:jpoce), &
  159. & solcp(1:jpoce,1:jpksed,jspoc ) )
  160. CALL unpack_arr( jpoce, trcsedi(1:jpi,1:jpj,1:jpksed,4) , iarroce(1:jpoce), &
  161. & solcp(1:jpoce,1:jpksed,jscal ) )
  162. CALL unpack_arr( jpoce, trcsedi(1:jpi,1:jpj,1:jpksed,5) , iarroce(1:jpoce), &
  163. & pwcp(1:jpoce,1:jpksed,jwsil ) )
  164. CALL unpack_arr( jpoce, trcsedi(1:jpi,1:jpj,1:jpksed,6) , iarroce(1:jpoce), &
  165. & pwcp(1:jpoce,1:jpksed,jwoxy ) )
  166. CALL unpack_arr( jpoce, trcsedi(1:jpi,1:jpj,1:jpksed,7) , iarroce(1:jpoce), &
  167. & pwcp(1:jpoce,1:jpksed,jwdic ) )
  168. CALL unpack_arr( jpoce, trcsedi(1:jpi,1:jpj,1:jpksed,8) , iarroce(1:jpoce), &
  169. & pwcp(1:jpoce,1:jpksed,jwno3 ) )
  170. CALL unpack_arr( jpoce, trcsedi(1:jpi,1:jpj,1:jpksed,9) , iarroce(1:jpoce), &
  171. & pwcp(1:jpoce,1:jpksed,jwpo4 ) )
  172. CALL unpack_arr( jpoce, trcsedi(1:jpi,1:jpj,1:jpksed,10) , iarroce(1:jpoce), &
  173. & pwcp(1:jpoce,1:jpksed,jwalk ) )
  174. CALL unpack_arr( jpoce, trcsedi(1:jpi,1:jpj,1:jpksed,11) , iarroce(1:jpoce), &
  175. & pwcp(1:jpoce,1:jpksed,jwc13 ) )
  176. ! porosity
  177. zdta(:,:) = 0.
  178. DO jk = 1, jpksed
  179. DO ji = 1, jpoce
  180. zdta(ji,jk) = -LOG10( hipor(ji,jk) / densSW(ji) )
  181. ENDDO
  182. ENDDO
  183. CALL unpack_arr( jpoce, flxsedi3d(1:jpi,1:jpj,1:jpksed,1) , iarroce(1:jpoce), &
  184. & zdta(1:jpoce,1:jpksed) )
  185. CALL unpack_arr( jpoce, flxsedi3d(1:jpi,1:jpj,1:jpksed,2) , iarroce(1:jpoce), &
  186. & co3por(1:jpoce,1:jpksed) )
  187. ! prognostic variables
  188. ! --------------------
  189. DO jn = 1, jptrased
  190. cltra = sedtrcd(jn)
  191. CALL restput( numrsw, cltra, jpi, jpj, jpksed, 0, trcsedi(:,:,:,jn) )
  192. ENDDO
  193. DO jn = 1, 2
  194. cltra = seddia3d(jn)
  195. CALL restput( numrsw, cltra, jpi, jpj, jpksed, 0, flxsedi3d(:,:,:,jn) )
  196. ENDDO
  197. CALL restclo( numrsw )
  198. ENDIF
  199. DEALLOCATE( zdta )
  200. END SUBROUTINE sed_rst_wri
  201. #else
  202. !!======================================================================
  203. !! MODULE sedrst : Dummy module
  204. !!======================================================================
  205. !! $Id: sedrst.F90 2355 2015-05-20 07:11:50Z ufla $
  206. CONTAINS
  207. SUBROUTINE sed_rst_read ! Empty routines
  208. END SUBROUTINE sed_rst_read
  209. SUBROUTINE sed_rst_wri( kt )
  210. INTEGER, INTENT ( in ) :: kt
  211. WRITE(*,*) 'sed_rst_wri: You should not have seen this print! error?', kt
  212. END SUBROUTINE sed_rst_wri
  213. #endif
  214. END MODULE sedrst