sedwri.F90 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277
  1. MODULE sedwri
  2. #if defined key_sed
  3. !!======================================================================
  4. !! *** MODULE sedwri ***
  5. !! Sediment diagnostics : write sediment output files
  6. !!======================================================================
  7. USE sed
  8. USE sedarr
  9. USE ioipsl
  10. USE dianam ! build name of file (routine)
  11. IMPLICIT NONE
  12. PRIVATE
  13. !! * Accessibility
  14. PUBLIC sed_wri
  15. INTEGER :: nised
  16. INTEGER :: nhorised
  17. INTEGER :: ndimt52
  18. INTEGER :: ndimt51
  19. INTEGER :: ndepsed
  20. REAL(wp) :: zjulian
  21. INTEGER, ALLOCATABLE, SAVE, DIMENSION(:) :: ndext52
  22. INTEGER, ALLOCATABLE, SAVE, DIMENSION(:) :: ndext51
  23. !! $Id: sedwri.F90 2355 2015-05-20 07:11:50Z ufla $
  24. CONTAINS
  25. !!----------------------------------------------------------------------
  26. !! NetCDF output file
  27. !!----------------------------------------------------------------------
  28. SUBROUTINE sed_wri( kt )
  29. !!----------------------------------------------------------------------
  30. !! *** ROUTINE sed_wri ***
  31. !!
  32. !! ** Purpose : output of sediment passive tracer
  33. !!
  34. !! History :
  35. !! ! 06-07 (C. Ethe) original
  36. !!----------------------------------------------------------------------
  37. INTEGER, INTENT(in) :: kt
  38. CHARACTER(len = 60) :: clhstnam, clop
  39. INTEGER :: ji, jk, js, jw, jn
  40. REAL(wp) :: zsto,zout, zdt
  41. INTEGER :: iimi, iima, ijmi, ijma,ipk, it, itmod
  42. CHARACTER(len = 20) :: cltra , cltrau
  43. CHARACTER(len = 80) :: cltral
  44. REAL(wp) :: zrate
  45. REAL(wp), ALLOCATABLE, DIMENSION(:,:) :: zdta, zflx
  46. !!-------------------------------------------------------------------
  47. ! Initialisation
  48. ! -----------------
  49. IF( kt == nittrc000 ) ALLOCATE( ndext52(jpij*jpksed), ndext51(jpij) )
  50. ! Define frequency of output and means
  51. zdt = dtsed
  52. IF( ln_mskland ) THEN ; clop = "only(x)" ! put 1.e+20 on land (very expensive!!)
  53. ELSE ; clop = "x" ! no use of the mask value (require less cpu time)
  54. ENDIF
  55. #if defined key_diainstant
  56. zsto = nwrised * zdt
  57. clop = "inst("//TRIM(clop)//")"
  58. #else
  59. zsto = zdt
  60. clop = "ave("//TRIM(clop)//")"
  61. #endif
  62. zout = nwrised * zdt
  63. ! Define indices of the horizontal output zoom and vertical limit storage
  64. iimi = 1 ; iima = jpi
  65. ijmi = 1 ; ijma = jpj
  66. ipk = jpksed
  67. ! define time axis
  68. it = kt
  69. itmod = kt - nitsed000 + 1
  70. ! 1. Initilisations
  71. ! -----------------------------------------------------------------
  72. WRITE(numsed,*) ' '
  73. WRITE(numsed,*) 'sed_wri kt = ', kt
  74. WRITE(numsed,*) ' '
  75. ALLOCATE( zdta(jpoce,jpksed) ) ; ALLOCATE( zflx(jpoce,jpwatp1) )
  76. ! 2. Back to 2D geometry
  77. ! -----------------------------------------------------------------
  78. CALL unpack_arr( jpoce, trcsedi(1:jpi,1:jpj,1:jpksed,1) , iarroce(1:jpoce), &
  79. & solcp(1:jpoce,1:jpksed,jsopal ) )
  80. CALL unpack_arr( jpoce, trcsedi(1:jpi,1:jpj,1:jpksed,2) , iarroce(1:jpoce), &
  81. & solcp(1:jpoce,1:jpksed,jsclay ) )
  82. CALL unpack_arr( jpoce, trcsedi(1:jpi,1:jpj,1:jpksed,3) , iarroce(1:jpoce), &
  83. & solcp(1:jpoce,1:jpksed,jspoc ) )
  84. CALL unpack_arr( jpoce, trcsedi(1:jpi,1:jpj,1:jpksed,4) , iarroce(1:jpoce), &
  85. & solcp(1:jpoce,1:jpksed,jscal ) )
  86. CALL unpack_arr( jpoce, trcsedi(1:jpi,1:jpj,1:jpksed,5) , iarroce(1:jpoce), &
  87. & pwcp(1:jpoce,1:jpksed,jwsil ) )
  88. CALL unpack_arr( jpoce, trcsedi(1:jpi,1:jpj,1:jpksed,6) , iarroce(1:jpoce), &
  89. & pwcp(1:jpoce,1:jpksed,jwoxy ) )
  90. CALL unpack_arr( jpoce, trcsedi(1:jpi,1:jpj,1:jpksed,7) , iarroce(1:jpoce), &
  91. & pwcp(1:jpoce,1:jpksed,jwdic ) )
  92. CALL unpack_arr( jpoce, trcsedi(1:jpi,1:jpj,1:jpksed,8) , iarroce(1:jpoce), &
  93. & pwcp(1:jpoce,1:jpksed,jwno3 ) )
  94. CALL unpack_arr( jpoce, trcsedi(1:jpi,1:jpj,1:jpksed,9) , iarroce(1:jpoce), &
  95. & pwcp(1:jpoce,1:jpksed,jwpo4 ) )
  96. CALL unpack_arr( jpoce, trcsedi(1:jpi,1:jpj,1:jpksed,10) , iarroce(1:jpoce), &
  97. & pwcp(1:jpoce,1:jpksed,jwalk ) )
  98. CALL unpack_arr( jpoce, trcsedi(1:jpi,1:jpj,1:jpksed,11) , iarroce(1:jpoce), &
  99. & pwcp(1:jpoce,1:jpksed,jwc13 ) )
  100. ! porosity
  101. zdta(:,:) = 0.
  102. DO jk = 1, jpksed
  103. DO ji = 1, jpoce
  104. zdta(ji,jk) = -LOG10( hipor(ji,jk) / densSW(ji) )
  105. ENDDO
  106. ENDDO
  107. CALL unpack_arr( jpoce, flxsedi3d(1:jpi,1:jpj,1:jpksed,1) , iarroce(1:jpoce), &
  108. & zdta(1:jpoce,1:jpksed) )
  109. CALL unpack_arr( jpoce, flxsedi3d(1:jpi,1:jpj,1:jpksed,2) , iarroce(1:jpoce), &
  110. & co3por(1:jpoce,1:jpksed) )
  111. ! computation of delta 13C
  112. zdta(:,:) = 0.
  113. DO jk = 1, jpksed
  114. DO ji = 1, jpoce
  115. zdta(ji,jk) = ( ( pwcp(ji,jk,jwc13) / pwcp(ji,jk,jwdic) / pdb ) - 1. ) &
  116. & * 1000.
  117. ENDDO
  118. ENDDO
  119. CALL unpack_arr( jpoce, flxsedi3d(1:jpi,1:jpj,1:jpksed,3) , iarroce(1:jpoce), &
  120. & zdta(1:jpoce,1:jpksed) )
  121. zflx(:,:) = 0.
  122. ! Calculation of fluxes mol/cm2/s
  123. DO jw = 1, jpwat
  124. DO ji = 1, jpoce
  125. zflx(ji,jw) = ( pwcp(ji,1,jw) - pwcp_dta(ji,jw) ) &
  126. & * 1.e-3 * dzkbot(ji) / dtsed
  127. ENDDO
  128. ENDDO
  129. ! Calculation of accumulation rate per dt
  130. DO js = 1, jpsol
  131. zrate = mol_wgt(js) / ( dens * por1(jpksed) ) / dtsed
  132. DO ji = 1, jpoce
  133. zflx(ji,jpwatp1) = zflx(ji,jpwatp1) + ( tosed(ji,js) - fromsed(ji,js) ) * zrate
  134. ENDDO
  135. ENDDO
  136. CALL unpack_arr( jpoce, flxsedi2d(1:jpi,1:jpj,1), iarroce(1:jpoce), zflx(1:jpoce,1) )
  137. CALL unpack_arr( jpoce, flxsedi2d(1:jpi,1:jpj,2), iarroce(1:jpoce), zflx(1:jpoce,2) )
  138. CALL unpack_arr( jpoce, flxsedi2d(1:jpi,1:jpj,3), iarroce(1:jpoce), zflx(1:jpoce,3) )
  139. CALL unpack_arr( jpoce, flxsedi2d(1:jpi,1:jpj,4), iarroce(1:jpoce), zflx(1:jpoce,4) )
  140. CALL unpack_arr( jpoce, flxsedi2d(1:jpi,1:jpj,5), iarroce(1:jpoce), zflx(1:jpoce,5) )
  141. CALL unpack_arr( jpoce, flxsedi2d(1:jpi,1:jpj,6), iarroce(1:jpoce), zflx(1:jpoce,6) )
  142. CALL unpack_arr( jpoce, flxsedi2d(1:jpi,1:jpj,7), iarroce(1:jpoce), zflx(1:jpoce,8) )
  143. ! 3. Define NETCDF files and fields at beginning of first time step
  144. ! -----------------------------------------------------------------
  145. IF( kt == nitsed000 ) THEN
  146. ! Define the NETCDF files
  147. CALL ymds2ju ( nyear, nmonth, nday, rdt, zjulian )
  148. zjulian = zjulian - adatrj ! set calendar origin to the beginning of the experiment
  149. CALL dia_nam ( clhstnam, nwrised, 'sed_T' )
  150. CALL histbeg ( clhstnam, jpi, glamt, jpj, gphit, &
  151. & iimi, iima-iimi+1, ijmi, ijma-ijmi+1, &
  152. & nitsed000-1, zjulian, zdt, nhorised, nised , domain_id=nidom, snc4chunks=snc4set )
  153. CALL histvert( nised,'deptht','Vertic.sed.T levels','m',ipk, profsed, ndepsed, 'down' )
  154. CALL wheneq ( jpi*jpj*ipk, tmasksed, 1, 1., ndext52, ndimt52 )
  155. CALL wheneq ( jpi*jpj, tmasksed(:,:,1), 1, 1., ndext51, ndimt51 )
  156. ! Declare all the output fields as NETCDF variables
  157. DO jn = 1, jptrased
  158. cltra = sedtrcd(jn) ! short title for sediment variable
  159. cltral = sedtrcl(jn) ! long title for sediment variable
  160. cltrau = sedtrcu(jn) ! unit for sediment variable
  161. CALL histdef( nised, cltra,cltral,cltrau, jpi, jpj, nhorised, &
  162. & ipk, 1, ipk, ndepsed, 32, clop, zsto, zout )
  163. ENDDO
  164. ! 3D diagnostic
  165. DO jn = 1, jpdia3dsed
  166. cltra = seddia3d(jn) ! short title for 3D diagnostic
  167. cltral = seddia3l(jn) ! long title for 3D diagnostic
  168. cltrau = seddia3u(jn) ! UNIT for 3D diagnostic
  169. CALL histdef( nised, cltra,cltral,cltrau, jpi, jpj, nhorised, &
  170. & ipk, 1, ipk, ndepsed, 32, clop, zsto, zout )
  171. ENDDO
  172. ! Fluxes
  173. DO jn = 1, jpdia2dsed
  174. cltra = seddia2d(jn) ! short title for 2D diagnostic
  175. cltral = seddia2l(jn) ! long title for 2D diagnostic
  176. cltrau = seddia2u(jn) ! UNIT for 2D diagnostic
  177. CALL histdef( nised, cltra,cltral,cltrau, jpi, jpj, nhorised, &
  178. & 1, 1, 1, -99, 32, clop, zsto, zout )
  179. ENDDO
  180. CALL histend( nised, snc4set )
  181. WRITE(numsed,*)
  182. WRITE(numsed,*) 'End of NetCDF sediment output file Initialization'
  183. ENDIF
  184. ! Start writing data
  185. ! ---------------------
  186. DO jn = 1, jptrased
  187. cltra = sedtrcd(jn) ! short title for 3D diagnostic
  188. CALL histwrite( nised, cltra, it, trcsedi(:,:,:,jn), ndimt52, ndext52 )
  189. END DO
  190. DO jn = 1, jpdia3dsed
  191. cltra = seddia3d(jn) ! short title for 3D diagnostic
  192. CALL histwrite( nised, cltra, it, flxsedi3d(:,:,:,jn), ndimt52, ndext52 )
  193. END DO
  194. DO jn = 1, jpdia2dsed
  195. cltra = seddia2d(jn) ! short title for 2D diagnostic
  196. CALL histwrite( nised, cltra, it, flxsedi2d(:,:,jn ), ndimt51, ndext51 )
  197. END DO
  198. ! 3. Closing all files
  199. ! --------------------
  200. IF( kt == nitsedend ) THEN
  201. CALL histclo( nised )
  202. ENDIF
  203. DEALLOCATE( zdta ) ; DEALLOCATE( zflx )
  204. END SUBROUTINE sed_wri
  205. #else
  206. !!======================================================================
  207. !! MODULE sedwri : Dummy module
  208. !!======================================================================
  209. !! $Id: sedwri.F90 2355 2015-05-20 07:11:50Z ufla $
  210. CONTAINS
  211. SUBROUTINE sed_wri( kt ) ! Empty routine
  212. INTEGER, INTENT(in) :: kt
  213. WRITE(*,*) 'sed_adv: You should not have seen this print! error?', kt
  214. END SUBROUTINE sed_wri
  215. !!======================================================================
  216. #endif
  217. END MODULE sedwri