diaar5.F90 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401
  1. MODULE diaar5
  2. !!======================================================================
  3. !! *** MODULE diaar5 ***
  4. !! AR5 diagnostics
  5. !!======================================================================
  6. !! History : 3.2 ! 2009-11 (S. Masson) Original code
  7. !! 3.3 ! 2010-10 (C. Ethe, G. Madec) reorganisation of initialisation phase + merge TRC-TRA
  8. !!----------------------------------------------------------------------
  9. #if defined key_diaar5 || defined key_esopa
  10. !!----------------------------------------------------------------------
  11. !! 'key_diaar5' : activate ar5 diagnotics
  12. !!----------------------------------------------------------------------
  13. !! dia_ar5 : AR5 diagnostics
  14. !! dia_ar5_init : initialisation of AR5 diagnostics
  15. !!----------------------------------------------------------------------
  16. USE oce ! ocean dynamics and active tracers
  17. USE dom_oce ! ocean space and time domain
  18. USE eosbn2 ! equation of state (eos_bn2 routine)
  19. USE lib_mpp ! distribued memory computing library
  20. USE lib_fortran ! Fortran routines library
  21. USE iom ! I/O manager library
  22. USE timing ! preformance summary
  23. USE wrk_nemo ! working arrays
  24. USE fldread ! type FLD_N
  25. USE phycst ! physical constant
  26. USE in_out_manager ! I/O manager
  27. USE zdfddm
  28. USE zdf_oce
  29. IMPLICIT NONE
  30. PRIVATE
  31. PUBLIC dia_ar5 ! routine called in step.F90 module
  32. PUBLIC dia_ar5_init ! routine called in opa.F90 module
  33. PUBLIC dia_ar5_alloc ! routine called in nemogcm.F90 module
  34. LOGICAL, PUBLIC, PARAMETER :: lk_diaar5 = .TRUE. ! coupled flag
  35. REAL(wp) :: vol0 ! ocean volume (interior domain)
  36. REAL(wp) :: area_tot ! total ocean surface (interior domain)
  37. REAL(wp), ALLOCATABLE, SAVE, DIMENSION(:,: ) :: area ! cell surface (interior domain)
  38. REAL(wp), ALLOCATABLE, SAVE, DIMENSION(:,: ) :: thick0 ! ocean thickness (interior domain)
  39. REAL(wp), ALLOCATABLE, SAVE, DIMENSION(:,:,:) :: sn0 ! initial salinity
  40. !! * Substitutions
  41. # include "domzgr_substitute.h90"
  42. # include "zdfddm_substitute.h90"
  43. !!----------------------------------------------------------------------
  44. !! NEMO/OPA 3.3 , NEMO Consortium (2010)
  45. !! $Id$
  46. !! Software governed by the CeCILL licence (NEMOGCM/NEMO_CeCILL.txt)
  47. !!----------------------------------------------------------------------
  48. CONTAINS
  49. FUNCTION dia_ar5_alloc()
  50. !!----------------------------------------------------------------------
  51. !! *** ROUTINE dia_ar5_alloc ***
  52. !!----------------------------------------------------------------------
  53. INTEGER :: dia_ar5_alloc
  54. !!----------------------------------------------------------------------
  55. !
  56. ALLOCATE( area(jpi,jpj), thick0(jpi,jpj), sn0(jpi,jpj,jpk) , STAT=dia_ar5_alloc )
  57. !
  58. IF( lk_mpp ) CALL mpp_sum ( dia_ar5_alloc )
  59. IF( dia_ar5_alloc /= 0 ) CALL ctl_warn('dia_ar5_alloc: failed to allocate arrays')
  60. !
  61. END FUNCTION dia_ar5_alloc
  62. SUBROUTINE dia_ar5( kt )
  63. !!----------------------------------------------------------------------
  64. !! *** ROUTINE dia_ar5 ***
  65. !!
  66. !! ** Purpose : compute and output some AR5 diagnostics
  67. !!----------------------------------------------------------------------
  68. !
  69. INTEGER, INTENT( in ) :: kt ! ocean time-step index
  70. !
  71. INTEGER :: ji, jj, jk, iks, ikb ! dummy loop arguments
  72. REAL(wp) :: zvolssh, zvol, zssh_steric, zztmp, zarho, ztemp, zsal, zmass
  73. REAL(wp) :: zaw, zbw, zrw, zsst, zsss
  74. !
  75. REAL(wp), POINTER, DIMENSION(:,:) :: zarea_ssh, zbotpres, zpe, z2d ! 2D workspace
  76. REAL(wp), POINTER, DIMENSION(:,:,:) :: zrhd , zrhop, z3d, ztpot ! 3D workspace
  77. REAL(wp), POINTER, DIMENSION(:,:,:,:) :: ztsn ! 4D workspace
  78. !!--------------------------------------------------------------------
  79. IF( nn_timing == 1 ) CALL timing_start('dia_ar5')
  80. CALL wrk_alloc( jpi, jpj , zarea_ssh, zbotpres, zpe, z2d )
  81. CALL wrk_alloc( jpi, jpj, jpk , zrhd , zrhop, z3d, ztpot )
  82. CALL wrk_alloc( jpi, jpj, jpk, jpts, ztsn )
  83. !Call to init moved to here so that we can call iom_use in the
  84. !initialisation
  85. IF( kt == nit000 ) CALL dia_ar5_init
  86. zarea_ssh(:,:) = area(:,:) * sshn(:,:)
  87. ! ! total volume of liquid seawater
  88. zvolssh = glob_sum( zarea_ssh(:,:) )
  89. zvol = vol0 + zvolssh
  90. !
  91. z3d(:,:,jpk) = 0._wp ! ocean volume
  92. DO jk = 1, jpkm1
  93. z3d (:,:,jk) = area(:,:) * fse3t(:,:,jk) * tmask(:,:,jk)
  94. END DO
  95. CALL iom_put( "bathy" , bathy(:,:) )
  96. CALL iom_put( "e2u", e2u(:,:) )
  97. CALL iom_put( "e1v", e1v(:,:) )
  98. CALL iom_put( "areacello" , area(:,:) )
  99. !
  100. CALL iom_put( "volcello" , z3d(:,:,:) ) ! WARNING not consistent with CMIP DR where volcello is at ca. 2000
  101. CALL iom_put( "masscello" , rau0 * fse3t(:,:,:) * tmask(:,:,:) ) ! ocean mass
  102. !
  103. CALL iom_put( 'voltot', zvol )
  104. CALL iom_put( 'sshtot', zvolssh / area_tot )
  105. CALL iom_put( 'sshdyn', sshn(:,:) - (zvolssh / area_tot) )
  106. !
  107. IF( iom_use('sshthster')) THEN
  108. ztsn(:,:,:,jp_tem) = tsn(:,:,:,jp_tem) ! thermosteric ssh
  109. ztsn(:,:,:,jp_sal) = sn0(:,:,:)
  110. CALL eos( ztsn, zrhd, fsdept_n(:,:,:) ) ! now in situ density using initial salinity
  111. !
  112. zbotpres(:,:) = 0._wp ! no atmospheric surface pressure, levitating sea-ice
  113. DO jk = 1, jpkm1
  114. zbotpres(:,:) = zbotpres(:,:) + fse3t(:,:,jk) * zrhd(:,:,jk)
  115. END DO
  116. IF( .NOT.lk_vvl ) THEN
  117. IF ( ln_isfcav ) THEN
  118. DO jj = 1, jpj
  119. DO ji = 1, jpi
  120. iks = mikt(ji,jj)
  121. zbotpres(ji,jj) = zbotpres(ji,jj) + sshn(ji,jj) * zrhd(ji,jj,iks) + riceload(ji,jj)
  122. END DO
  123. END DO
  124. ELSE
  125. zbotpres(:,:) = zbotpres(:,:) + sshn(:,:) * zrhd(:,:,1)
  126. END IF
  127. END IF
  128. !
  129. zarho = glob_sum( area(:,:) * zbotpres(:,:) )
  130. zssh_steric = - zarho / area_tot
  131. CALL iom_put( 'sshthster', zssh_steric )
  132. !
  133. ENDIF
  134. ! ! steric sea surface height
  135. CALL eos( tsn, zrhd, zrhop, fsdept_n(:,:,:) ) ! now in situ and potential density
  136. zbotpres(:,:) = 0._wp ! no atmospheric surface pressure, levitating sea-ice
  137. DO jk = 1, jpkm1
  138. zbotpres(:,:) = zbotpres(:,:) + fse3t(:,:,jk) * zrhd(:,:,jk)
  139. END DO
  140. IF( .NOT.lk_vvl ) THEN
  141. IF ( ln_isfcav ) THEN
  142. DO jj = 1, jpj
  143. DO ji = 1, jpi
  144. iks = mikt(ji,jj)
  145. zbotpres(ji,jj) = zbotpres(ji,jj) + sshn(ji,jj) * zrhd(ji,jj,iks) + riceload(ji,jj)
  146. END DO
  147. END DO
  148. ELSE
  149. zbotpres(:,:) = zbotpres(:,:) + sshn(:,:) * zrhd(:,:,1)
  150. END IF
  151. END IF
  152. !
  153. zrhop(:,:,jpk) = 0._wp
  154. CALL iom_put( 'rhop', zrhop )
  155. !
  156. zarho = glob_sum( area(:,:) * zbotpres(:,:) )
  157. zssh_steric = - zarho / area_tot
  158. CALL iom_put( 'sshsteric', zssh_steric )
  159. ! ! ocean bottom pressure
  160. zztmp = rau0 * grav * 1.e-4_wp ! recover pressure from pressure anomaly and cover to dbar = 1.e4 Pa
  161. zbotpres(:,:) = zztmp * ( zbotpres(:,:) + sshn(:,:) + thick0(:,:) )
  162. CALL iom_put( 'botpres', zbotpres )
  163. ! ! Mean density anomalie, temperature and salinity
  164. !
  165. ztsn(:,:,:,:) = 0._wp ! ztsn(:,:,1,jp_tem/sal) is used here as 2D Workspace for temperature & salinity
  166. DO jk = 1, jpkm1
  167. ztsn(:,:,1,jp_tem) = ztsn(:,:,1,jp_tem) + area(:,:) * fse3t(:,:,jk) * tsn(:,:,jk,jp_tem)
  168. ztsn(:,:,1,jp_sal) = ztsn(:,:,1,jp_sal) + area(:,:) * fse3t(:,:,jk) * tsn(:,:,jk,jp_sal)
  169. ENDDO
  170. IF( .NOT.lk_vvl ) THEN
  171. IF( ln_isfcav ) THEN
  172. DO jj = 1, jpj
  173. DO ji = 1, jpi
  174. iks = mikt(ji,jj)
  175. ztsn(ji,jj,1,jp_tem) = ztsn(ji,jj,1,jp_tem) + zarea_ssh(ji,jj) * tsn(ji,jj,iks,jp_tem)
  176. ztsn(ji,jj,1,jp_sal) = ztsn(ji,jj,1,jp_sal) + zarea_ssh(ji,jj) * tsn(ji,jj,iks,jp_sal)
  177. END DO
  178. END DO
  179. ELSE
  180. ztsn(:,:,1,jp_tem) = ztsn(:,:,1,jp_tem) + zarea_ssh(:,:) * tsn(:,:,1,jp_tem)
  181. ztsn(:,:,1,jp_sal) = ztsn(:,:,1,jp_sal) + zarea_ssh(:,:) * tsn(:,:,1,jp_sal)
  182. END IF
  183. ENDIF
  184. !
  185. zsss = glob_sum( area(:,:) * tsn(:,:,1,jp_sal) )
  186. ztemp = glob_sum( ztsn(:,:,1,jp_tem) )
  187. zsal = glob_sum( ztsn(:,:,1,jp_sal) )
  188. zmass = rau0 * ( zarho + zvol )
  189. !
  190. CALL iom_put( 'masstot', zmass ) ! total mass of liquid seawater
  191. CALL iom_put( 'temptot', ztemp / zvol ) ! potential temperature in liquid seawater
  192. CALL iom_put( 'saltot' , zsal / zvol ) ! Salinity of liquid seawater
  193. CALL iom_put( 'ssstot' , zsss / area_tot ) ! Salinity of liquid seawater at surface
  194. IF( iom_use( "e3tb" ) ) THEN
  195. DO jj = 1, jpj
  196. DO ji = 1, jpi
  197. ikb = mbkt(ji,jj)
  198. z2d(ji,jj) = fse3t(ji,jj,ikb)
  199. END DO
  200. END DO
  201. CALL iom_put( "e3tb", z2d )
  202. ENDIF
  203. IF( nn_eos == -1 ) THEN ! ! potential temperature (TEOS-10 case)
  204. ztpot(:,:,:) = eos_pt_from_ct( tsn(:,:,:,jp_tem), tsn(:,:,:,jp_sal) )
  205. ztpot(:,:,jpk) = 0._wp
  206. !
  207. CALL iom_put( "toce_pot", ztpot(:,:,:) ) ! potential temperature (TEOS-10 case)
  208. CALL iom_put( "sst_pot" , ztpot(:,:,1) ) ! surface temperature
  209. !
  210. IF( iom_use('temptot_pot') ) THEN ! Output potential temperature in case we use TEOS-10
  211. z2d(:,:) = 0._wp
  212. DO jk = 1, jpkm1
  213. z2d(:,:) = z2d(:,:) + area(:,:) * fse3t(:,:,jk) * ztpot(:,:,jk)
  214. END DO
  215. zsst = glob_sum( area(:,:) * ztpot(:,:,1) )
  216. ztemp = glob_sum( z2d(:,:) )
  217. CALL iom_put( 'temptot_pot', ztemp / zvol )
  218. CALL iom_put( 'ssttot' , zsst / area_tot )
  219. ENDIF
  220. ! Vertical integral of temperature
  221. IF( iom_use("tosmint_pot") ) THEN
  222. z2d(:,:) = 0._wp
  223. DO jk = 1, jpkm1
  224. DO jj = 1, jpj
  225. DO ji = 1, jpi ! vector opt.
  226. z2d(ji,jj) = z2d(ji,jj) + rau0 * fse3t(ji,jj,jk) * ztpot(ji,jj,jk)
  227. END DO
  228. END DO
  229. END DO
  230. CALL iom_put( "tosmint_pot", z2d )
  231. ENDIF
  232. ELSE
  233. zsst = glob_sum( area(:,:) * tsn(:,:,1,jp_tem) ) ! Case EOS-80 : compute sst anyway
  234. CALL iom_put('ssttot', zsst / area_tot )
  235. ENDIF
  236. IF( iom_use( 'tnpeo' )) THEN
  237. ! Work done against stratification by vertical mixing
  238. ! Exclude points where rn2 is negative as convection kicks in here and
  239. ! work is not being done against stratification
  240. zpe(:,:) = 0._wp
  241. IF( lk_zdfddm ) THEN
  242. DO jk = 2, jpk
  243. DO jj = 1, jpj
  244. DO ji = 1, jpi
  245. IF( rn2(ji,jj,jk) > 0._wp ) THEN
  246. zrw = ( fsdepw(ji,jj,jk ) - fsdept(ji,jj,jk) ) &
  247. & / ( fsdept(ji,jj,jk-1) - fsdept(ji,jj,jk) )
  248. !
  249. zaw = rab_n(ji,jj,jk,jp_tem) * (1. - zrw) + rab_n(ji,jj,jk-1,jp_tem)* zrw
  250. zbw = rab_n(ji,jj,jk,jp_sal) * (1. - zrw) + rab_n(ji,jj,jk-1,jp_sal)* zrw
  251. !
  252. zpe(ji, jj) = zpe(ji, jj) &
  253. & - grav * ( avt(ji,jj,jk) * zaw * (tsn(ji,jj,jk-1,jp_tem) - tsn(ji,jj,jk,jp_tem) ) &
  254. & - fsavs(ji,jj,jk) * zbw * (tsn(ji,jj,jk-1,jp_sal) - tsn(ji,jj,jk,jp_sal) ) )
  255. ENDIF
  256. END DO
  257. END DO
  258. END DO
  259. ELSE
  260. DO jk = 1, jpk
  261. DO ji = 1, jpi
  262. DO jj = 1, jpj
  263. zpe(ji,jj) = zpe(ji,jj) + avt(ji, jj, jk) * MIN(0._wp,rn2(ji, jj, jk)) * rau0 * fse3w(ji, jj, jk)
  264. END DO
  265. END DO
  266. END DO
  267. ENDIF
  268. CALL lbc_lnk(zpe, 'T', 1._wp)
  269. CALL iom_put( 'tnpeo', zpe )
  270. ENDIF
  271. !
  272. CALL wrk_dealloc( jpi, jpj , zarea_ssh, zbotpres, zpe, z2d )
  273. CALL wrk_dealloc( jpi, jpj, jpk , zrhd , zrhop, z3d, ztpot )
  274. CALL wrk_dealloc( jpi, jpj, jpk, jpts, ztsn )
  275. !
  276. IF( nn_timing == 1 ) CALL timing_stop('dia_ar5')
  277. !
  278. END SUBROUTINE dia_ar5
  279. SUBROUTINE dia_ar5_init
  280. !!----------------------------------------------------------------------
  281. !! *** ROUTINE dia_ar5_init ***
  282. !!
  283. !! ** Purpose : initialization for AR5 diagnostic computation
  284. !!----------------------------------------------------------------------
  285. INTEGER :: inum
  286. INTEGER :: ik, idep
  287. INTEGER :: ji, jj, jk ! dummy loop indices
  288. REAL(wp) :: zztmp
  289. REAL(wp), POINTER, DIMENSION(:,:,:,:) :: zsaldta ! Jan/Dec levitus salinity
  290. REAL(wp), POINTER, DIMENSION(:,:) :: zvol0
  291. ! reading initial file
  292. LOGICAL :: ln_tsd_init !: T & S data flag
  293. LOGICAL :: ln_tsd_tradmp !: internal damping toward input data flag
  294. CHARACTER(len=100) :: cn_dir
  295. TYPE(FLD_N) :: sn_tem,sn_sal
  296. INTEGER :: ios=0
  297. NAMELIST/namtsd/ ln_tsd_init,ln_tsd_tradmp,cn_dir,sn_tem,sn_sal
  298. !
  299. REWIND( numnam_ref ) ! Namelist namtsd in reference namelist :
  300. READ ( numnam_ref, namtsd, IOSTAT = ios, ERR = 901)
  301. 901 IF( ios /= 0 ) CALL ctl_nam ( ios , ' namtsd in reference namelist for dia_ar5', lwp )
  302. REWIND( numnam_cfg ) ! Namelist namtsd in configuration namelist : Parameters of the run
  303. READ ( numnam_cfg, namtsd, IOSTAT = ios, ERR = 902 )
  304. 902 IF( ios /= 0 ) CALL ctl_nam ( ios , ' namtsd in configuration namelist for dia_ar5', lwp )
  305. IF(lwm) WRITE ( numond, namtsd )
  306. !
  307. !!----------------------------------------------------------------------
  308. !
  309. IF( nn_timing == 1 ) CALL timing_start('dia_ar5_init')
  310. !
  311. CALL wrk_alloc( jpi, jpj, jpk, 2, zsaldta )
  312. CALL wrk_alloc( jpi, jpj, zvol0 )
  313. ! ! allocate dia_ar5 arrays
  314. IF( dia_ar5_alloc() /= 0 ) CALL ctl_stop( 'STOP', 'dia_ar5_init : unable to allocate arrays' )
  315. area(:,:) = e1t(:,:) * e2t(:,:)
  316. area_tot = glob_sum( area(:,:) )
  317. zvol0 (:,:) = 0._wp
  318. thick0(:,:) = 0._wp
  319. DO jk = 1, jpkm1
  320. DO jj = 1, jpj ! interpolation of salinity at the last ocean level (i.e. the partial step)
  321. DO ji = 1, jpi
  322. idep = tmask(ji,jj,jk) * e3t_0(ji,jj,jk)
  323. zvol0 (ji,jj) = zvol0 (ji,jj) + idep * area(ji,jj)
  324. thick0(ji,jj) = thick0(ji,jj) + idep
  325. END DO
  326. END DO
  327. END DO
  328. vol0 = glob_sum( zvol0 )
  329. IF( iom_use('sshthster')) THEN
  330. CALL iom_open ( 'sali_ref_clim_monthly', inum )
  331. CALL iom_get ( inum, jpdom_data, 'vosaline' , zsaldta(:,:,:,1), 1 )
  332. CALL iom_get ( inum, jpdom_data, 'vosaline' , zsaldta(:,:,:,2), 12 )
  333. CALL iom_close( inum )
  334. sn0(:,:,:) = 0.5_wp * ( zsaldta(:,:,:,1) + zsaldta(:,:,:,2) )
  335. sn0(:,:,:) = sn0(:,:,:) * tmask(:,:,:)
  336. IF( ln_zps ) THEN ! z-coord. partial steps
  337. DO jj = 1, jpj ! interpolation of salinity at the last ocean level (i.e. the partial step)
  338. DO ji = 1, jpi
  339. ik = mbkt(ji,jj)
  340. IF( ik > 1 ) THEN
  341. zztmp = ( gdept_1d(ik) - gdept_0(ji,jj,ik) ) / ( gdept_1d(ik) - gdept_1d(ik-1) )
  342. sn0(ji,jj,ik) = ( 1._wp - zztmp ) * sn0(ji,jj,ik) + zztmp * sn0(ji,jj,ik-1)
  343. ENDIF
  344. END DO
  345. END DO
  346. ENDIF
  347. ENDIF
  348. !
  349. CALL wrk_dealloc( jpi, jpj, jpk, jpts, zsaldta )
  350. CALL wrk_dealloc( jpi, jpj, zvol0 )
  351. !
  352. IF( nn_timing == 1 ) CALL timing_stop('dia_ar5_init')
  353. !
  354. END SUBROUTINE dia_ar5_init
  355. #else
  356. !!----------------------------------------------------------------------
  357. !! Default option : NO diaar5
  358. !!----------------------------------------------------------------------
  359. LOGICAL, PUBLIC, PARAMETER :: lk_diaar5 = .FALSE. ! coupled flag
  360. CONTAINS
  361. SUBROUTINE dia_ar5_init ! Dummy routine
  362. END SUBROUTINE dia_ar5_init
  363. SUBROUTINE dia_ar5( kt ) ! Empty routine
  364. INTEGER :: kt
  365. WRITE(*,*) 'dia_ar5: You should not have seen this print! error?', kt
  366. END SUBROUTINE dia_ar5
  367. #endif
  368. !!======================================================================
  369. END MODULE diaar5