sbcssm.F90 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294
  1. MODULE sbcssm
  2. !!======================================================================
  3. !! *** MODULE sbcssm ***
  4. !! Off-line : interpolation of the physical fields
  5. !!======================================================================
  6. !! History :
  7. !! NEMO 3.4 ! 2012-03 First version by S. Alderson
  8. !! ! Heavily derived from Christian's dtadyn routine
  9. !! ! in OFF_SRC
  10. !!----------------------------------------------------------------------
  11. !!----------------------------------------------------------------------
  12. !! sbc_ssm_init : initialization, namelist read, and SAVEs control
  13. !! sbc_ssm : Interpolation of the fields
  14. !!----------------------------------------------------------------------
  15. USE oce ! ocean dynamics and tracers variables
  16. USE c1d ! 1D configuration: lk_c1d
  17. USE dom_oce ! ocean domain: variables
  18. USE zdf_oce ! ocean vertical physics: variables
  19. USE sbc_oce ! surface module: variables
  20. USE phycst ! physical constants
  21. USE eosbn2 ! equation of state - Brunt Vaisala frequency
  22. USE lbclnk ! ocean lateral boundary conditions (or mpp link)
  23. USE zpshde ! z-coord. with partial steps: horizontal derivatives
  24. USE in_out_manager ! I/O manager
  25. USE iom ! I/O library
  26. USE lib_mpp ! distributed memory computing library
  27. USE prtctl ! print control
  28. USE fldread ! read input fields
  29. USE timing ! Timing
  30. IMPLICIT NONE
  31. PRIVATE
  32. PUBLIC sbc_ssm_init ! called by sbc_init
  33. PUBLIC sbc_ssm ! called by sbc
  34. CHARACTER(len=100) :: cn_dir !: Root directory for location of ssm files
  35. LOGICAL :: ln_3d_uve !: specify whether input velocity data is 3D
  36. LOGICAL :: ln_read_frq !: specify whether we must read frq or not
  37. LOGICAL :: l_initdone = .false.
  38. INTEGER :: nfld_3d
  39. INTEGER :: nfld_2d
  40. INTEGER :: jf_tem ! index of temperature
  41. INTEGER :: jf_sal ! index of salinity
  42. INTEGER :: jf_usp ! index of u velocity component
  43. INTEGER :: jf_vsp ! index of v velocity component
  44. INTEGER :: jf_ssh ! index of sea surface height
  45. INTEGER :: jf_e3t ! index of first T level thickness
  46. INTEGER :: jf_frq ! index of fraction of qsr absorbed in the 1st T level
  47. TYPE(FLD), ALLOCATABLE, DIMENSION(:) :: sf_ssm_3d ! structure of input fields (file information, fields read)
  48. TYPE(FLD), ALLOCATABLE, DIMENSION(:) :: sf_ssm_2d ! structure of input fields (file information, fields read)
  49. !!----------------------------------------------------------------------
  50. !! NEMO/OFF 3.3 , NEMO Consortium (2010)
  51. !! $Id: sbcssm.F90 2442 2015-06-12 08:32:11Z ufla $
  52. !! Software governed by the CeCILL licence (NEMOGCM/NEMO_CeCILL.txt)
  53. !!----------------------------------------------------------------------
  54. CONTAINS
  55. SUBROUTINE sbc_ssm( kt )
  56. !!----------------------------------------------------------------------
  57. !! *** ROUTINE sbc_ssm ***
  58. !!
  59. !! ** Purpose : Prepares dynamics and physics fields from a NEMO run
  60. !! for an off-line simulation using surface processes only
  61. !!
  62. !! ** Method : calculates the position of data
  63. !! - interpolates data if needed
  64. !!----------------------------------------------------------------------
  65. !
  66. INTEGER, INTENT(in) :: kt ! ocean time-step index
  67. !
  68. INTEGER :: ji, jj ! dummy loop indices
  69. REAL(wp) :: ztinta ! ratio applied to after records when doing time interpolation
  70. REAL(wp) :: ztintb ! ratio applied to before records when doing time interpolation
  71. !!----------------------------------------------------------------------
  72. !
  73. IF( nn_timing == 1 ) CALL timing_start( 'sbc_ssm')
  74. IF( nfld_3d > 0 ) CALL fld_read( kt, 1, sf_ssm_3d ) !== read data at kt time step ==!
  75. IF( nfld_2d > 0 ) CALL fld_read( kt, 1, sf_ssm_2d ) !== read data at kt time step ==!
  76. !
  77. IF( ln_3d_uve ) THEN
  78. ssu_m(:,:) = sf_ssm_3d(jf_usp)%fnow(:,:,1) * umask(:,:,1) ! u-velocity
  79. ssv_m(:,:) = sf_ssm_3d(jf_vsp)%fnow(:,:,1) * vmask(:,:,1) ! v-velocity
  80. IF( lk_vvl ) e3t_m(:,:) = sf_ssm_3d(jf_e3t)%fnow(:,:,1) * tmask(:,:,1) ! v-velocity
  81. ELSE
  82. ssu_m(:,:) = sf_ssm_2d(jf_usp)%fnow(:,:,1) * umask(:,:,1) ! u-velocity
  83. ssv_m(:,:) = sf_ssm_2d(jf_vsp)%fnow(:,:,1) * vmask(:,:,1) ! v-velocity
  84. IF( lk_vvl ) e3t_m(:,:) = sf_ssm_2d(jf_e3t)%fnow(:,:,1) * tmask(:,:,1) ! v-velocity
  85. ENDIF
  86. !
  87. sst_m(:,:) = sf_ssm_2d(jf_tem)%fnow(:,:,1) * tmask(:,:,1) ! temperature
  88. sss_m(:,:) = sf_ssm_2d(jf_sal)%fnow(:,:,1) * tmask(:,:,1) ! salinity
  89. ssh_m(:,:) = sf_ssm_2d(jf_ssh)%fnow(:,:,1) * tmask(:,:,1) ! sea surface height
  90. IF( ln_read_frq ) frq_m(:,:) = sf_ssm_2d(jf_frq)%fnow(:,:,1) * tmask(:,:,1) ! sea surface height
  91. !
  92. IF ( nn_ice == 1 ) THEN
  93. tsn(:,:,1,jp_tem) = sst_m(:,:)
  94. tsn(:,:,1,jp_sal) = sss_m(:,:)
  95. tsb(:,:,1,jp_tem) = sst_m(:,:)
  96. tsb(:,:,1,jp_sal) = sss_m(:,:)
  97. ENDIF
  98. ub (:,:,1) = ssu_m(:,:)
  99. vb (:,:,1) = ssv_m(:,:)
  100. IF(ln_ctl) THEN ! print control
  101. CALL prt_ctl(tab2d_1=sst_m, clinfo1=' sst_m - : ', mask1=tmask, ovlap=1 )
  102. CALL prt_ctl(tab2d_1=sss_m, clinfo1=' sss_m - : ', mask1=tmask, ovlap=1 )
  103. CALL prt_ctl(tab2d_1=ssu_m, clinfo1=' ssu_m - : ', mask1=umask, ovlap=1 )
  104. CALL prt_ctl(tab2d_1=ssv_m, clinfo1=' ssv_m - : ', mask1=vmask, ovlap=1 )
  105. CALL prt_ctl(tab2d_1=ssh_m, clinfo1=' ssh_m - : ', mask1=tmask, ovlap=1 )
  106. IF( lk_vvl ) CALL prt_ctl(tab2d_1=ssh_m, clinfo1=' e3t_m - : ', mask1=tmask, ovlap=1 )
  107. IF( ln_read_frq ) CALL prt_ctl(tab2d_1=frq_m, clinfo1=' frq_m - : ', mask1=tmask, ovlap=1 )
  108. ENDIF
  109. !
  110. IF( l_initdone ) THEN ! Mean value at each nn_fsbc time-step !
  111. CALL iom_put( 'ssu_m', ssu_m )
  112. CALL iom_put( 'ssv_m', ssv_m )
  113. CALL iom_put( 'sst_m', sst_m )
  114. CALL iom_put( 'sss_m', sss_m )
  115. CALL iom_put( 'ssh_m', ssh_m )
  116. IF( lk_vvl ) CALL iom_put( 'e3t_m', e3t_m )
  117. IF( ln_read_frq ) CALL iom_put( 'frq_m', frq_m )
  118. ENDIF
  119. !
  120. IF( nn_timing == 1 ) CALL timing_stop( 'sbc_ssm')
  121. !
  122. END SUBROUTINE sbc_ssm
  123. SUBROUTINE sbc_ssm_init
  124. !!----------------------------------------------------------------------
  125. !! *** ROUTINE sbc_ssm_init ***
  126. !!
  127. !! ** Purpose : Initialisation of the dynamical data
  128. !! ** Method : - read the data namsbc_ssm namelist
  129. !!
  130. !! ** Action : - read parameters
  131. !!----------------------------------------------------------------------
  132. INTEGER :: ierr, ierr0, ierr1, ierr2, ierr3 ! return error code
  133. INTEGER :: ifpr ! dummy loop indice
  134. INTEGER :: inum, idv, idimv, jpm ! local integer
  135. INTEGER :: ios ! Local integer output status for namelist read
  136. !!
  137. CHARACTER(len=100) :: cn_dir ! Root directory for location of core files
  138. TYPE(FLD_N), ALLOCATABLE, DIMENSION(:) :: slf_3d ! array of namelist information on the fields to read
  139. TYPE(FLD_N), ALLOCATABLE, DIMENSION(:) :: slf_2d ! array of namelist information on the fields to read
  140. TYPE(FLD_N) :: sn_tem, sn_sal ! information about the fields to be read
  141. TYPE(FLD_N) :: sn_usp, sn_vsp
  142. TYPE(FLD_N) :: sn_ssh, sn_e3t, sn_frq
  143. !
  144. NAMELIST/namsbc_sas/cn_dir, ln_3d_uve, ln_read_frq, sn_tem, sn_sal, sn_usp, sn_vsp, sn_ssh, sn_e3t, sn_frq
  145. !!----------------------------------------------------------------------
  146. IF( ln_rstart .AND. nn_components == jp_iam_sas ) RETURN
  147. REWIND( numnam_ref ) ! Namelist namsbc_sas in reference namelist : Input fields
  148. READ ( numnam_ref, namsbc_sas, IOSTAT = ios, ERR = 901)
  149. 901 IF( ios /= 0 ) CALL ctl_nam ( ios , 'namsbc_sas in reference namelist', lwp )
  150. REWIND( numnam_cfg ) ! Namelist namsbc_sas in configuration namelist : Input fields
  151. READ ( numnam_cfg, namsbc_sas, IOSTAT = ios, ERR = 902 )
  152. 902 IF( ios /= 0 ) CALL ctl_nam ( ios , 'namsbc_sas in configuration namelist', lwp )
  153. IF(lwm) WRITE ( numond, namsbc_sas )
  154. ! ! store namelist information in an array
  155. ! ! Control print
  156. IF(lwp) THEN
  157. WRITE(numout,*)
  158. WRITE(numout,*) 'sbc_sas : standalone surface scheme '
  159. WRITE(numout,*) '~~~~~~~~~~~ '
  160. WRITE(numout,*) ' Namelist namsbc_sas'
  161. WRITE(numout,*) ' Are we supplying a 3D u,v and e3 field ln_3d_uve = ', ln_3d_uve
  162. WRITE(numout,*) ' Are we reading frq (fraction of qsr absorbed in the 1st T level) ln_read_frq = ', ln_read_frq
  163. WRITE(numout,*)
  164. ENDIF
  165. !
  166. !! switch off stuff that isn't sensible with a standalone module
  167. !! note that we need sbc_ssm called first in sbc
  168. !
  169. IF( ln_apr_dyn ) THEN
  170. IF( lwp ) WRITE(numout,*) 'No atmospheric gradient needed with StandAlone Surface scheme'
  171. ln_apr_dyn = .FALSE.
  172. ENDIF
  173. IF( ln_rnf ) THEN
  174. IF( lwp ) WRITE(numout,*) 'No runoff needed with StandAlone Surface scheme'
  175. ln_rnf = .FALSE.
  176. ENDIF
  177. IF( ln_ssr ) THEN
  178. IF( lwp ) WRITE(numout,*) 'No surface relaxation needed with StandAlone Surface scheme'
  179. ln_ssr = .FALSE.
  180. ENDIF
  181. IF( nn_fwb > 0 ) THEN
  182. IF( lwp ) WRITE(numout,*) 'No freshwater budget adjustment needed with StandAlone Surface scheme'
  183. nn_fwb = 0
  184. ENDIF
  185. IF( nn_closea > 0 ) THEN
  186. IF( lwp ) WRITE(numout,*) 'No closed seas adjustment needed with StandAlone Surface scheme'
  187. nn_closea = 0
  188. ENDIF
  189. !
  190. !! following code is a bit messy, but distinguishes between when u,v are 3d arrays and
  191. !! when we have other 3d arrays that we need to read in
  192. !! so if a new field is added i.e. jf_new, just give it the next integer in sequence
  193. !! for the corresponding dimension (currently if ln_3d_uve is true, 4 for 2d and 3 for 3d,
  194. !! alternatively if ln_3d_uve is false, 6 for 2d and 1 for 3d), reset nfld_3d, nfld_2d,
  195. !! and the rest of the logic should still work
  196. !
  197. jf_tem = 1 ; jf_sal = 2 ; jf_ssh = 3 ; jf_frq = 4 ! default 2D fields index
  198. !
  199. IF( ln_3d_uve ) THEN
  200. jf_usp = 1 ; jf_vsp = 2 ; jf_e3t = 3 ! define 3D fields index
  201. nfld_3d = 2 + COUNT( (/lk_vvl/) ) ! number of 3D fields to read
  202. nfld_2d = 3 + COUNT( (/ln_read_frq/) ) ! number of 2D fields to read
  203. ELSE
  204. jf_usp = 4 ; jf_vsp = 5 ; jf_e3t = 6 ; jf_frq = 6 + COUNT( (/lk_vvl/) ) ! update 2D fields index
  205. nfld_3d = 0 ! no 3D fields to read
  206. nfld_2d = 5 + COUNT( (/lk_vvl/) ) + COUNT( (/ln_read_frq/) ) ! number of 2D fields to read
  207. ENDIF
  208. IF( nfld_3d > 0 ) THEN
  209. ALLOCATE( slf_3d(nfld_3d), STAT=ierr ) ! set slf structure
  210. IF( ierr > 0 ) THEN
  211. CALL ctl_stop( 'sbc_ssm_init: unable to allocate slf 3d structure' ) ; RETURN
  212. ENDIF
  213. slf_3d(jf_usp) = sn_usp
  214. slf_3d(jf_vsp) = sn_vsp
  215. IF( lk_vvl ) slf_3d(jf_e3t) = sn_e3t
  216. ENDIF
  217. IF( nfld_2d > 0 ) THEN
  218. ALLOCATE( slf_2d(nfld_2d), STAT=ierr ) ! set slf structure
  219. IF( ierr > 0 ) THEN
  220. CALL ctl_stop( 'sbc_ssm_init: unable to allocate slf 2d structure' ) ; RETURN
  221. ENDIF
  222. slf_2d(jf_tem) = sn_tem ; slf_2d(jf_sal) = sn_sal ; slf_2d(jf_ssh) = sn_ssh
  223. IF( ln_read_frq ) slf_2d(jf_frq) = sn_frq
  224. IF( .NOT. ln_3d_uve ) THEN
  225. slf_2d(jf_usp) = sn_usp ; slf_2d(jf_vsp) = sn_vsp
  226. IF( lk_vvl ) slf_2d(jf_e3t) = sn_e3t
  227. ENDIF
  228. ENDIF
  229. !
  230. ierr1 = 0 ! default definition if slf_?d(ifpr)%ln_tint = .false.
  231. IF( nfld_3d > 0 ) THEN
  232. ALLOCATE( sf_ssm_3d(nfld_3d), STAT=ierr ) ! set sf structure
  233. IF( ierr > 0 ) THEN
  234. CALL ctl_stop( 'sbc_ssm_init: unable to allocate sf structure' ) ; RETURN
  235. ENDIF
  236. DO ifpr = 1, nfld_3d
  237. ALLOCATE( sf_ssm_3d(ifpr)%fnow(jpi,jpj,jpk) , STAT=ierr0 )
  238. IF( slf_3d(ifpr)%ln_tint ) ALLOCATE( sf_ssm_3d(ifpr)%fdta(jpi,jpj,jpk,2) , STAT=ierr1 )
  239. IF( ierr0 + ierr1 > 0 ) THEN
  240. CALL ctl_stop( 'sbc_ssm_init : unable to allocate sf_ssm_3d array structure' ) ; RETURN
  241. ENDIF
  242. END DO
  243. ! ! fill sf with slf_i and control print
  244. CALL fld_fill( sf_ssm_3d, slf_3d, cn_dir, 'sbc_ssm_init', '3D Data in file', 'namsbc_ssm' )
  245. ENDIF
  246. IF( nfld_2d > 0 ) THEN
  247. ALLOCATE( sf_ssm_2d(nfld_2d), STAT=ierr ) ! set sf structure
  248. IF( ierr > 0 ) THEN
  249. CALL ctl_stop( 'sbc_ssm_init: unable to allocate sf 2d structure' ) ; RETURN
  250. ENDIF
  251. DO ifpr = 1, nfld_2d
  252. ALLOCATE( sf_ssm_2d(ifpr)%fnow(jpi,jpj,1) , STAT=ierr0 )
  253. IF( slf_2d(ifpr)%ln_tint ) ALLOCATE( sf_ssm_2d(ifpr)%fdta(jpi,jpj,1,2) , STAT=ierr1 )
  254. IF( ierr0 + ierr1 > 0 ) THEN
  255. CALL ctl_stop( 'sbc_ssm_init : unable to allocate sf_ssm_2d array structure' ) ; RETURN
  256. ENDIF
  257. END DO
  258. !
  259. CALL fld_fill( sf_ssm_2d, slf_2d, cn_dir, 'sbc_ssm_init', '2D Data in file', 'namsbc_ssm' )
  260. ENDIF
  261. !
  262. ! finally tidy up
  263. IF( nfld_3d > 0 ) DEALLOCATE( slf_3d, STAT=ierr )
  264. IF( nfld_2d > 0 ) DEALLOCATE( slf_2d, STAT=ierr )
  265. CALL sbc_ssm( nit000 ) ! need to define ss?_m arrays used in limistate
  266. IF( .NOT. ln_read_frq ) frq_m(:,:) = 1.
  267. l_initdone = .TRUE.
  268. !
  269. END SUBROUTINE sbc_ssm_init
  270. !!======================================================================
  271. END MODULE sbcssm