domzgr.F90 131 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659
  1. MODULE domzgr
  2. !!==============================================================================
  3. !! *** MODULE domzgr ***
  4. !! Ocean initialization : domain initialization
  5. !!==============================================================================
  6. !! History : OPA ! 1995-12 (G. Madec) Original code : s vertical coordinate
  7. !! ! 1997-07 (G. Madec) lbc_lnk call
  8. !! ! 1997-04 (J.-O. Beismann)
  9. !! 8.5 ! 2002-09 (A. Bozec, G. Madec) F90: Free form and module
  10. !! - ! 2002-09 (A. de Miranda) rigid-lid + islands
  11. !! NEMO 1.0 ! 2003-08 (G. Madec) F90: Free form and module
  12. !! - ! 2005-10 (A. Beckmann) modifications for hybrid s-ccordinates & new stretching function
  13. !! 2.0 ! 2006-04 (R. Benshila, G. Madec) add zgr_zco
  14. !! 3.0 ! 2008-06 (G. Madec) insertion of domzgr_zps.h90 & conding style
  15. !! 3.2 ! 2009-07 (R. Benshila) Suppression of rigid-lid option
  16. !! 3.3 ! 2010-11 (G. Madec) add mbk. arrays associated to the deepest ocean level
  17. !! 3.4 ! 2012-08 (J. Siddorn) added Siddorn and Furner stretching function
  18. !! 3.4 ! 2012-12 (R. Bourdalle-Badie and G. Reffray) modify C1D case
  19. !! 3.6 ! 2014-11 (P. Mathiot and C. Harris) add ice shelf capabilitye
  20. !!----------------------------------------------------------------------
  21. !!----------------------------------------------------------------------
  22. !! dom_zgr : defined the ocean vertical coordinate system
  23. !! zgr_bat : bathymetry fields (levels and meters)
  24. !! zgr_bat_zoom : modify the bathymetry field if zoom domain
  25. !! zgr_bat_ctl : check the bathymetry files
  26. !! zgr_bot_level: deepest ocean level for t-, u, and v-points
  27. !! zgr_z : reference z-coordinate
  28. !! zgr_zco : z-coordinate
  29. !! zgr_zps : z-coordinate with partial steps
  30. !! zgr_sco : s-coordinate
  31. !! fssig : tanh stretch function
  32. !! fssig1 : Song and Haidvogel 1994 stretch function
  33. !! fgamma : Siddorn and Furner 2012 stretching function
  34. !!---------------------------------------------------------------------
  35. USE oce ! ocean variables
  36. USE dom_oce ! ocean domain
  37. USE closea ! closed seas
  38. USE c1d ! 1D vertical configuration
  39. USE in_out_manager ! I/O manager
  40. USE iom ! I/O library
  41. USE lbclnk ! ocean lateral boundary conditions (or mpp link)
  42. USE lib_mpp ! distributed memory computing library
  43. USE wrk_nemo ! Memory allocation
  44. USE timing ! Timing
  45. IMPLICIT NONE
  46. PRIVATE
  47. PUBLIC dom_zgr ! called by dom_init.F90
  48. ! !!* Namelist namzgr_sco *
  49. LOGICAL :: ln_s_sh94 ! use hybrid s-sig Song and Haidvogel 1994 stretching function fssig1 (ln_sco=T)
  50. LOGICAL :: ln_s_sf12 ! use hybrid s-z-sig Siddorn and Furner 2012 stretching function fgamma (ln_sco=T)
  51. !
  52. REAL(wp) :: rn_sbot_min ! minimum depth of s-bottom surface (>0) (m)
  53. REAL(wp) :: rn_sbot_max ! maximum depth of s-bottom surface (= ocean depth) (>0) (m)
  54. REAL(wp) :: rn_rmax ! maximum cut-off r-value allowed (0<rn_rmax<1)
  55. REAL(wp) :: rn_hc ! Critical depth for transition from sigma to stretched coordinates
  56. ! Song and Haidvogel 1994 stretching parameters
  57. REAL(wp) :: rn_theta ! surface control parameter (0<=rn_theta<=20)
  58. REAL(wp) :: rn_thetb ! bottom control parameter (0<=rn_thetb<= 1)
  59. REAL(wp) :: rn_bb ! stretching parameter
  60. ! ! ( rn_bb=0; top only, rn_bb =1; top and bottom)
  61. ! Siddorn and Furner stretching parameters
  62. LOGICAL :: ln_sigcrit ! use sigma coordinates below critical depth (T) or Z coordinates (F) for Siddorn & Furner stretch
  63. REAL(wp) :: rn_alpha ! control parameter ( > 1 stretch towards surface, < 1 towards seabed)
  64. REAL(wp) :: rn_efold ! efold length scale for transition to stretched coord
  65. REAL(wp) :: rn_zs ! depth of surface grid box
  66. ! bottom cell depth (Zb) is a linear function of water depth Zb = H*a + b
  67. REAL(wp) :: rn_zb_a ! bathymetry scaling factor for calculating Zb
  68. REAL(wp) :: rn_zb_b ! offset for calculating Zb
  69. !! * Substitutions
  70. # include "domzgr_substitute.h90"
  71. # include "vectopt_loop_substitute.h90"
  72. !!----------------------------------------------------------------------
  73. !! NEMO/OPA 3.3.1 , NEMO Consortium (2011)
  74. !! $Id: domzgr.F90 5506 2015-06-29 15:19:38Z clevy $
  75. !! Software governed by the CeCILL licence (NEMOGCM/NEMO_CeCILL.txt)
  76. !!----------------------------------------------------------------------
  77. CONTAINS
  78. SUBROUTINE dom_zgr
  79. !!----------------------------------------------------------------------
  80. !! *** ROUTINE dom_zgr ***
  81. !!
  82. !! ** Purpose : set the depth of model levels and the resulting
  83. !! vertical scale factors.
  84. !!
  85. !! ** Method : - reference 1D vertical coordinate (gdep._1d, e3._1d)
  86. !! - read/set ocean depth and ocean levels (bathy, mbathy)
  87. !! - vertical coordinate (gdep., e3.) depending on the
  88. !! coordinate chosen :
  89. !! ln_zco=T z-coordinate
  90. !! ln_zps=T z-coordinate with partial steps
  91. !! ln_zco=T s-coordinate
  92. !!
  93. !! ** Action : define gdep., e3., mbathy and bathy
  94. !!----------------------------------------------------------------------
  95. INTEGER :: ioptio, ibat ! local integer
  96. INTEGER :: ios
  97. !
  98. NAMELIST/namzgr/ ln_zco, ln_zps, ln_sco, ln_isfcav
  99. !!----------------------------------------------------------------------
  100. !
  101. IF( nn_timing == 1 ) CALL timing_start('dom_zgr')
  102. !
  103. REWIND( numnam_ref ) ! Namelist namzgr in reference namelist : Vertical coordinate
  104. READ ( numnam_ref, namzgr, IOSTAT = ios, ERR = 901 )
  105. 901 IF( ios /= 0 ) CALL ctl_nam ( ios , 'namzgr in reference namelist', lwp )
  106. REWIND( numnam_cfg ) ! Namelist namzgr in configuration namelist : Vertical coordinate
  107. READ ( numnam_cfg, namzgr, IOSTAT = ios, ERR = 902 )
  108. 902 IF( ios /= 0 ) CALL ctl_nam ( ios , 'namzgr in configuration namelist', lwp )
  109. IF(lwm) WRITE ( numond, namzgr )
  110. IF(lwp) THEN ! Control print
  111. WRITE(numout,*)
  112. WRITE(numout,*) 'dom_zgr : vertical coordinate'
  113. WRITE(numout,*) '~~~~~~~'
  114. WRITE(numout,*) ' Namelist namzgr : set vertical coordinate'
  115. WRITE(numout,*) ' z-coordinate - full steps ln_zco = ', ln_zco
  116. WRITE(numout,*) ' z-coordinate - partial steps ln_zps = ', ln_zps
  117. WRITE(numout,*) ' s- or hybrid z-s-coordinate ln_sco = ', ln_sco
  118. WRITE(numout,*) ' ice shelf cavities ln_isfcav = ', ln_isfcav
  119. ENDIF
  120. ioptio = 0 ! Check Vertical coordinate options
  121. IF( ln_zco ) ioptio = ioptio + 1
  122. IF( ln_zps ) ioptio = ioptio + 1
  123. IF( ln_sco ) ioptio = ioptio + 1
  124. IF( ioptio /= 1 ) CALL ctl_stop( ' none or several vertical coordinate options used' )
  125. !
  126. ! Build the vertical coordinate system
  127. ! ------------------------------------
  128. CALL zgr_z ! Reference z-coordinate system (always called)
  129. CALL zgr_bat ! Bathymetry fields (levels and meters)
  130. IF( lk_c1d ) CALL lbc_lnk( bathy , 'T', 1._wp ) ! 1D config.: same bathy value over the 3x3 domain
  131. IF( ln_zco ) CALL zgr_zco ! z-coordinate
  132. IF( ln_zps ) CALL zgr_zps ! Partial step z-coordinate
  133. IF( ln_sco ) CALL zgr_sco ! s-coordinate or hybrid z-s coordinate
  134. !
  135. ! final adjustment of mbathy & check
  136. ! -----------------------------------
  137. IF( lzoom ) CALL zgr_bat_zoom ! correct mbathy in case of zoom subdomain
  138. IF( .NOT.lk_c1d ) CALL zgr_bat_ctl ! check bathymetry (mbathy) and suppress isolated ocean points
  139. CALL zgr_bot_level ! deepest ocean level for t-, u- and v-points
  140. CALL zgr_top_level ! shallowest ocean level for T-, U-, V- points
  141. !
  142. IF( lk_c1d ) THEN ! 1D config.: same mbathy value over the 3x3 domain
  143. ibat = mbathy(2,2)
  144. mbathy(:,:) = ibat
  145. END IF
  146. !
  147. IF( nprint == 1 .AND. lwp ) THEN
  148. WRITE(numout,*) ' MIN val mbathy ', MINVAL( mbathy(:,:) ), ' MAX ', MAXVAL( mbathy(:,:) )
  149. WRITE(numout,*) ' MIN val depth t ', MINVAL( gdept_0(:,:,:) ), &
  150. & ' w ', MINVAL( gdepw_0(:,:,:) ), '3w ', MINVAL( gdep3w_0(:,:,:) )
  151. WRITE(numout,*) ' MIN val e3 t ', MINVAL( e3t_0(:,:,:) ), ' f ', MINVAL( e3f_0(:,:,:) ), &
  152. & ' u ', MINVAL( e3u_0(:,:,:) ), ' u ', MINVAL( e3v_0(:,:,:) ), &
  153. & ' uw', MINVAL( e3uw_0(:,:,:)), ' vw', MINVAL( e3vw_0(:,:,:)), &
  154. & ' w ', MINVAL( e3w_0(:,:,:) )
  155. WRITE(numout,*) ' MAX val depth t ', MAXVAL( gdept_0(:,:,:) ), &
  156. & ' w ', MAXVAL( gdepw_0(:,:,:) ), '3w ', MAXVAL( gdep3w_0(:,:,:) )
  157. WRITE(numout,*) ' MAX val e3 t ', MAXVAL( e3t_0(:,:,:) ), ' f ', MAXVAL( e3f_0(:,:,:) ), &
  158. & ' u ', MAXVAL( e3u_0(:,:,:) ), ' u ', MAXVAL( e3v_0(:,:,:) ), &
  159. & ' uw', MAXVAL( e3uw_0(:,:,:)), ' vw', MAXVAL( e3vw_0(:,:,:)), &
  160. & ' w ', MAXVAL( e3w_0(:,:,:) )
  161. ENDIF
  162. !
  163. IF( nn_timing == 1 ) CALL timing_stop('dom_zgr')
  164. !
  165. END SUBROUTINE dom_zgr
  166. SUBROUTINE zgr_z
  167. !!----------------------------------------------------------------------
  168. !! *** ROUTINE zgr_z ***
  169. !!
  170. !! ** Purpose : set the depth of model levels and the resulting
  171. !! vertical scale factors.
  172. !!
  173. !! ** Method : z-coordinate system (use in all type of coordinate)
  174. !! The depth of model levels is defined from an analytical
  175. !! function the derivative of which gives the scale factors.
  176. !! both depth and scale factors only depend on k (1d arrays).
  177. !! w-level: gdepw_1d = gdep(k)
  178. !! e3w_1d(k) = dk(gdep)(k) = e3(k)
  179. !! t-level: gdept_1d = gdep(k+0.5)
  180. !! e3t_1d(k) = dk(gdep)(k+0.5) = e3(k+0.5)
  181. !!
  182. !! ** Action : - gdept_1d, gdepw_1d : depth of T- and W-point (m)
  183. !! - e3t_1d , e3w_1d : scale factors at T- and W-levels (m)
  184. !!
  185. !! Reference : Marti, Madec & Delecluse, 1992, JGR, 97, No8, 12,763-12,766.
  186. !!----------------------------------------------------------------------
  187. INTEGER :: jk ! dummy loop indices
  188. REAL(wp) :: zt, zw ! temporary scalars
  189. REAL(wp) :: zsur, za0, za1, zkth ! Values set from parameters in
  190. REAL(wp) :: zacr, zdzmin, zhmax ! par_CONFIG_Rxx.h90
  191. REAL(wp) :: zrefdep ! depth of the reference level (~10m)
  192. REAL(wp) :: za2, zkth2, zacr2 ! Values for optional double tanh function set from parameters
  193. !!----------------------------------------------------------------------
  194. !
  195. IF( nn_timing == 1 ) CALL timing_start('zgr_z')
  196. !
  197. ! Set variables from parameters
  198. ! ------------------------------
  199. zkth = ppkth ; zacr = ppacr
  200. zdzmin = ppdzmin ; zhmax = pphmax
  201. zkth2 = ppkth2 ; zacr2 = ppacr2 ! optional (ldbletanh=T) double tanh parameters
  202. ! If ppa1 and ppa0 and ppsur are et to pp_to_be_computed
  203. ! za0, za1, zsur are computed from ppdzmin , pphmax, ppkth, ppacr
  204. IF( ppa1 == pp_to_be_computed .AND. &
  205. & ppa0 == pp_to_be_computed .AND. &
  206. & ppsur == pp_to_be_computed ) THEN
  207. !
  208. #if defined key_agrif
  209. za1 = ( ppdzmin - pphmax / FLOAT(jpkdta-1) ) &
  210. & / ( TANH((1-ppkth)/ppacr) - ppacr/FLOAT(jpkdta-1) * ( LOG( COSH( (jpkdta - ppkth) / ppacr) )&
  211. & - LOG( COSH( ( 1 - ppkth) / ppacr) ) ) )
  212. #else
  213. za1 = ( ppdzmin - pphmax / FLOAT(jpkm1) ) &
  214. & / ( TANH((1-ppkth)/ppacr) - ppacr/FLOAT(jpk-1) * ( LOG( COSH( (jpk - ppkth) / ppacr) ) &
  215. & - LOG( COSH( ( 1 - ppkth) / ppacr) ) ) )
  216. #endif
  217. za0 = ppdzmin - za1 * TANH( (1-ppkth) / ppacr )
  218. zsur = - za0 - za1 * ppacr * LOG( COSH( (1-ppkth) / ppacr ) )
  219. ELSE
  220. za1 = ppa1 ; za0 = ppa0 ; zsur = ppsur
  221. za2 = ppa2 ! optional (ldbletanh=T) double tanh parameter
  222. ENDIF
  223. IF(lwp) THEN ! Parameter print
  224. WRITE(numout,*)
  225. WRITE(numout,*) ' zgr_z : Reference vertical z-coordinates'
  226. WRITE(numout,*) ' ~~~~~~~'
  227. IF( ppkth == 0._wp ) THEN
  228. WRITE(numout,*) ' Uniform grid with ',jpk-1,' layers'
  229. WRITE(numout,*) ' Total depth :', zhmax
  230. #if defined key_agrif
  231. WRITE(numout,*) ' Layer thickness:', zhmax/(jpkdta-1)
  232. #else
  233. WRITE(numout,*) ' Layer thickness:', zhmax/(jpk-1)
  234. #endif
  235. ELSE
  236. IF( ppa1 == 0._wp .AND. ppa0 == 0._wp .AND. ppsur == 0._wp ) THEN
  237. WRITE(numout,*) ' zsur, za0, za1 computed from '
  238. WRITE(numout,*) ' zdzmin = ', zdzmin
  239. WRITE(numout,*) ' zhmax = ', zhmax
  240. ENDIF
  241. WRITE(numout,*) ' Value of coefficients for vertical mesh:'
  242. WRITE(numout,*) ' zsur = ', zsur
  243. WRITE(numout,*) ' za0 = ', za0
  244. WRITE(numout,*) ' za1 = ', za1
  245. WRITE(numout,*) ' zkth = ', zkth
  246. WRITE(numout,*) ' zacr = ', zacr
  247. IF( ldbletanh ) THEN
  248. WRITE(numout,*) ' (Double tanh za2 = ', za2
  249. WRITE(numout,*) ' parameters) zkth2= ', zkth2
  250. WRITE(numout,*) ' zacr2= ', zacr2
  251. ENDIF
  252. ENDIF
  253. ENDIF
  254. ! Reference z-coordinate (depth - scale factor at T- and W-points)
  255. ! ======================
  256. IF( ppkth == 0._wp ) THEN ! uniform vertical grid
  257. #if defined key_agrif
  258. za1 = zhmax / FLOAT(jpkdta-1)
  259. #else
  260. za1 = zhmax / FLOAT(jpk-1)
  261. #endif
  262. DO jk = 1, jpk
  263. zw = FLOAT( jk )
  264. zt = FLOAT( jk ) + 0.5_wp
  265. gdepw_1d(jk) = ( zw - 1 ) * za1
  266. gdept_1d(jk) = ( zt - 1 ) * za1
  267. e3w_1d (jk) = za1
  268. e3t_1d (jk) = za1
  269. END DO
  270. ELSE ! Madec & Imbard 1996 function
  271. IF( .NOT. ldbletanh ) THEN
  272. DO jk = 1, jpk
  273. zw = REAL( jk , wp )
  274. zt = REAL( jk , wp ) + 0.5_wp
  275. gdepw_1d(jk) = ( zsur + za0 * zw + za1 * zacr * LOG ( COSH( (zw-zkth) / zacr ) ) )
  276. gdept_1d(jk) = ( zsur + za0 * zt + za1 * zacr * LOG ( COSH( (zt-zkth) / zacr ) ) )
  277. e3w_1d (jk) = za0 + za1 * TANH( (zw-zkth) / zacr )
  278. e3t_1d (jk) = za0 + za1 * TANH( (zt-zkth) / zacr )
  279. END DO
  280. ELSE
  281. DO jk = 1, jpk
  282. zw = FLOAT( jk )
  283. zt = FLOAT( jk ) + 0.5_wp
  284. ! Double tanh function
  285. gdepw_1d(jk) = ( zsur + za0 * zw + za1 * zacr * LOG ( COSH( (zw-zkth ) / zacr ) ) &
  286. & + za2 * zacr2* LOG ( COSH( (zw-zkth2) / zacr2 ) ) )
  287. gdept_1d(jk) = ( zsur + za0 * zt + za1 * zacr * LOG ( COSH( (zt-zkth ) / zacr ) ) &
  288. & + za2 * zacr2* LOG ( COSH( (zt-zkth2) / zacr2 ) ) )
  289. e3w_1d (jk) = za0 + za1 * TANH( (zw-zkth ) / zacr ) &
  290. & + za2 * TANH( (zw-zkth2) / zacr2 )
  291. e3t_1d (jk) = za0 + za1 * TANH( (zt-zkth ) / zacr ) &
  292. & + za2 * TANH( (zt-zkth2) / zacr2 )
  293. END DO
  294. ENDIF
  295. gdepw_1d(1) = 0._wp ! force first w-level to be exactly at zero
  296. ENDIF
  297. IF ( ln_isfcav ) THEN
  298. ! need to be like this to compute the pressure gradient with ISF. If not, level beneath the ISF are not aligned (sum(e3t) /= depth)
  299. ! define e3t_0 and e3w_0 as the differences between gdept and gdepw respectively
  300. DO jk = 1, jpkm1
  301. e3t_1d(jk) = gdepw_1d(jk+1)-gdepw_1d(jk)
  302. END DO
  303. e3t_1d(jpk) = e3t_1d(jpk-1) ! we don't care because this level is masked in NEMO
  304. DO jk = 2, jpk
  305. e3w_1d(jk) = gdept_1d(jk) - gdept_1d(jk-1)
  306. END DO
  307. e3w_1d(1 ) = 2._wp * (gdept_1d(1) - gdepw_1d(1))
  308. END IF
  309. !!gm BUG in s-coordinate this does not work!
  310. ! deepest/shallowest W level Above/Below ~10m
  311. zrefdep = 10._wp - 0.1_wp * MINVAL( e3w_1d ) ! ref. depth with tolerance (10% of minimum layer thickness)
  312. nlb10 = MINLOC( gdepw_1d, mask = gdepw_1d > zrefdep, dim = 1 ) ! shallowest W level Below ~10m
  313. nla10 = nlb10 - 1 ! deepest W level Above ~10m
  314. !!gm end bug
  315. IF(lwp) THEN ! control print
  316. WRITE(numout,*)
  317. WRITE(numout,*) ' Reference z-coordinate depth and scale factors:'
  318. WRITE(numout, "(9x,' level gdept_1d gdepw_1d e3t_1d e3w_1d ')" )
  319. WRITE(numout, "(10x, i4, 4f9.2)" ) ( jk, gdept_1d(jk), gdepw_1d(jk), e3t_1d(jk), e3w_1d(jk), jk = 1, jpk )
  320. ENDIF
  321. DO jk = 1, jpk ! control positivity
  322. IF( e3w_1d (jk) <= 0._wp .OR. e3t_1d (jk) <= 0._wp ) CALL ctl_stop( 'dom:zgr_z: e3w_1d or e3t_1d =< 0 ' )
  323. IF( gdepw_1d(jk) < 0._wp .OR. gdept_1d(jk) < 0._wp ) CALL ctl_stop( 'dom:zgr_z: gdepw_1d or gdept_1d < 0 ' )
  324. END DO
  325. !
  326. IF( nn_timing == 1 ) CALL timing_stop('zgr_z')
  327. !
  328. END SUBROUTINE zgr_z
  329. SUBROUTINE zgr_bat
  330. !!----------------------------------------------------------------------
  331. !! *** ROUTINE zgr_bat ***
  332. !!
  333. !! ** Purpose : set bathymetry both in levels and meters
  334. !!
  335. !! ** Method : read or define mbathy and bathy arrays
  336. !! * level bathymetry:
  337. !! The ocean basin geometry is given by a two-dimensional array,
  338. !! mbathy, which is defined as follow :
  339. !! mbathy(ji,jj) = 1, ..., jpk-1, the number of ocean level
  340. !! at t-point (ji,jj).
  341. !! = 0 over the continental t-point.
  342. !! The array mbathy is checked to verified its consistency with
  343. !! model option. in particular:
  344. !! mbathy must have at least 1 land grid-points (mbathy<=0)
  345. !! along closed boundary.
  346. !! mbathy must be cyclic IF jperio=1.
  347. !! mbathy must be lower or equal to jpk-1.
  348. !! isolated ocean grid points are suppressed from mbathy
  349. !! since they are only connected to remaining
  350. !! ocean through vertical diffusion.
  351. !! ntopo=-1 : rectangular channel or bassin with a bump
  352. !! ntopo= 0 : flat rectangular channel or basin
  353. !! ntopo= 1 : mbathy is read in 'bathy_level.nc' NetCDF file
  354. !! bathy is read in 'bathy_meter.nc' NetCDF file
  355. !!
  356. !! ** Action : - mbathy: level bathymetry (in level index)
  357. !! - bathy : meter bathymetry (in meters)
  358. !!----------------------------------------------------------------------
  359. INTEGER :: ji, jj, jl, jk ! dummy loop indices
  360. INTEGER :: inum ! temporary logical unit
  361. INTEGER :: ierror ! error flag
  362. INTEGER :: ii_bump, ij_bump, ih ! bump center position
  363. INTEGER :: ii0, ii1, ij0, ij1, ik ! local indices
  364. REAL(wp) :: r_bump , h_bump , h_oce ! bump characteristics
  365. REAL(wp) :: zi, zj, zh, zhmin ! local scalars
  366. INTEGER , ALLOCATABLE, DIMENSION(:,:) :: idta ! global domain integer data
  367. REAL(wp), ALLOCATABLE, DIMENSION(:,:) :: zdta ! global domain scalar data
  368. !!----------------------------------------------------------------------
  369. !
  370. IF( nn_timing == 1 ) CALL timing_start('zgr_bat')
  371. !
  372. IF(lwp) WRITE(numout,*)
  373. IF(lwp) WRITE(numout,*) ' zgr_bat : defines level and meter bathymetry'
  374. IF(lwp) WRITE(numout,*) ' ~~~~~~~'
  375. !
  376. ! (ISF) initialisation ice shelf draft and top level
  377. risfdep(:,:)=0._wp
  378. misfdep(:,:)=1
  379. ! ! ================== !
  380. IF( ntopo == 0 .OR. ntopo == -1 ) THEN ! defined by hand !
  381. ! ! ================== !
  382. ! ! global domain level and meter bathymetry (idta,zdta)
  383. !
  384. ALLOCATE( idta(jpidta,jpjdta), STAT=ierror )
  385. IF( ierror > 0 ) CALL ctl_stop( 'STOP', 'zgr_bat: unable to allocate idta array' )
  386. ALLOCATE( zdta(jpidta,jpjdta), STAT=ierror )
  387. IF( ierror > 0 ) CALL ctl_stop( 'STOP', 'zgr_bat: unable to allocate zdta array' )
  388. !
  389. IF( ntopo == 0 ) THEN ! flat basin
  390. IF(lwp) WRITE(numout,*)
  391. IF(lwp) WRITE(numout,*) ' bathymetry field: flat basin'
  392. IF( rn_bathy > 0.01 ) THEN
  393. IF(lwp) WRITE(numout,*) ' Depth = rn_bathy read in namelist'
  394. zdta(:,:) = rn_bathy
  395. IF( ln_sco ) THEN ! s-coordinate (zsc ): idta()=jpk
  396. idta(:,:) = jpkm1
  397. ELSE ! z-coordinate (zco or zps): step-like topography
  398. idta(:,:) = jpkm1
  399. DO jk = 1, jpkm1
  400. WHERE( gdept_1d(jk) < zdta(:,:) .AND. zdta(:,:) <= gdept_1d(jk+1) ) idta(:,:) = jk
  401. END DO
  402. ENDIF
  403. ELSE
  404. IF(lwp) WRITE(numout,*) ' Depth = depthw(jpkm1)'
  405. idta(:,:) = jpkm1 ! before last level
  406. zdta(:,:) = gdepw_1d(jpk) ! last w-point depth
  407. h_oce = gdepw_1d(jpk)
  408. ENDIF
  409. ELSE ! bump centered in the basin
  410. IF(lwp) WRITE(numout,*)
  411. IF(lwp) WRITE(numout,*) ' bathymetry field: flat basin with a bump'
  412. ii_bump = jpidta / 2 ! i-index of the bump center
  413. ij_bump = jpjdta / 2 ! j-index of the bump center
  414. r_bump = 50000._wp ! bump radius (meters)
  415. h_bump = 2700._wp ! bump height (meters)
  416. h_oce = gdepw_1d(jpk) ! background ocean depth (meters)
  417. IF(lwp) WRITE(numout,*) ' bump characteristics: '
  418. IF(lwp) WRITE(numout,*) ' bump center (i,j) = ', ii_bump, ii_bump
  419. IF(lwp) WRITE(numout,*) ' bump height = ', h_bump , ' meters'
  420. IF(lwp) WRITE(numout,*) ' bump radius = ', r_bump , ' index'
  421. IF(lwp) WRITE(numout,*) ' background ocean depth = ', h_oce , ' meters'
  422. !
  423. DO jj = 1, jpjdta ! zdta :
  424. DO ji = 1, jpidta
  425. zi = FLOAT( ji - ii_bump ) * ppe1_m / r_bump
  426. zj = FLOAT( jj - ij_bump ) * ppe2_m / r_bump
  427. zdta(ji,jj) = h_oce - h_bump * EXP( -( zi*zi + zj*zj ) )
  428. END DO
  429. END DO
  430. ! ! idta :
  431. IF( ln_sco ) THEN ! s-coordinate (zsc ): idta()=jpk
  432. idta(:,:) = jpkm1
  433. ELSE ! z-coordinate (zco or zps): step-like topography
  434. idta(:,:) = jpkm1
  435. DO jk = 1, jpkm1
  436. WHERE( gdept_1d(jk) < zdta(:,:) .AND. zdta(:,:) <= gdept_1d(jk+1) ) idta(:,:) = jk
  437. END DO
  438. ENDIF
  439. ENDIF
  440. ! ! set GLOBAL boundary conditions
  441. ! ! Caution : idta on the global domain: use of jperio, not nperio
  442. IF( jperio == 1 .OR. jperio == 4 .OR. jperio == 6 ) THEN
  443. idta( : , 1 ) = -1 ; zdta( : , 1 ) = -1._wp
  444. idta( : ,jpjdta) = 0 ; zdta( : ,jpjdta) = 0._wp
  445. ELSEIF( jperio == 2 ) THEN
  446. idta( : , 1 ) = idta( : , 3 ) ; zdta( : , 1 ) = zdta( : , 3 )
  447. idta( : ,jpjdta) = 0 ; zdta( : ,jpjdta) = 0._wp
  448. idta( 1 , : ) = 0 ; zdta( 1 , : ) = 0._wp
  449. idta(jpidta, : ) = 0 ; zdta(jpidta, : ) = 0._wp
  450. ELSE
  451. ih = 0 ; zh = 0._wp
  452. IF( ln_sco ) ih = jpkm1 ; IF( ln_sco ) zh = h_oce
  453. idta( : , 1 ) = ih ; zdta( : , 1 ) = zh
  454. idta( : ,jpjdta) = ih ; zdta( : ,jpjdta) = zh
  455. idta( 1 , : ) = ih ; zdta( 1 , : ) = zh
  456. idta(jpidta, : ) = ih ; zdta(jpidta, : ) = zh
  457. ENDIF
  458. ! ! local domain level and meter bathymetries (mbathy,bathy)
  459. mbathy(:,:) = 0 ! set to zero extra halo points
  460. bathy (:,:) = 0._wp ! (require for mpp case)
  461. DO jj = 1, nlcj ! interior values
  462. DO ji = 1, nlci
  463. mbathy(ji,jj) = idta( mig(ji), mjg(jj) )
  464. bathy (ji,jj) = zdta( mig(ji), mjg(jj) )
  465. END DO
  466. END DO
  467. !
  468. DEALLOCATE( idta, zdta )
  469. !
  470. ! ! ================ !
  471. ELSEIF( ntopo == 1 ) THEN ! read in file ! (over the local domain)
  472. ! ! ================ !
  473. !
  474. IF( ln_zco ) THEN ! zco : read level bathymetry
  475. CALL iom_open ( 'bathy_level.nc', inum )
  476. CALL iom_get ( inum, jpdom_data, 'Bathy_level', bathy )
  477. CALL iom_close( inum )
  478. mbathy(:,:) = INT( bathy(:,:) )
  479. ! ! =====================
  480. IF( cp_cfg == "orca" .AND. jp_cfg == 2 ) THEN ! ORCA R2 configuration
  481. ! ! =====================
  482. IF( nn_cla == 0 ) THEN
  483. ii0 = 140 ; ii1 = 140 ! Gibraltar Strait open
  484. ij0 = 102 ; ij1 = 102 ! (Thomson, Ocean Modelling, 1995)
  485. DO ji = mi0(ii0), mi1(ii1)
  486. DO jj = mj0(ij0), mj1(ij1)
  487. mbathy(ji,jj) = 15
  488. END DO
  489. END DO
  490. IF(lwp) WRITE(numout,*)
  491. IF(lwp) WRITE(numout,*) ' orca_r2: Gibraltar strait open at i=',ii0,' j=',ij0
  492. !
  493. ii0 = 160 ; ii1 = 160 ! Bab el mandeb Strait open
  494. ij0 = 88 ; ij1 = 88 ! (Thomson, Ocean Modelling, 1995)
  495. DO ji = mi0(ii0), mi1(ii1)
  496. DO jj = mj0(ij0), mj1(ij1)
  497. mbathy(ji,jj) = 12
  498. END DO
  499. END DO
  500. IF(lwp) WRITE(numout,*)
  501. IF(lwp) WRITE(numout,*) ' orca_r2: Bab el Mandeb strait open at i=',ii0,' j=',ij0
  502. ENDIF
  503. !
  504. ENDIF
  505. !
  506. ENDIF
  507. IF( ln_zps .OR. ln_sco ) THEN ! zps or sco : read meter bathymetry
  508. CALL iom_open ( 'bathy_meter.nc', inum )
  509. IF ( ln_isfcav ) THEN
  510. CALL iom_get ( inum, jpdom_data, 'Bathymetry_isf', bathy, lrowattr=.false. )
  511. ELSE
  512. CALL iom_get ( inum, jpdom_data, 'Bathymetry' , bathy, lrowattr=ln_use_jattr )
  513. END IF
  514. CALL iom_close( inum )
  515. !
  516. IF ( ln_isfcav ) THEN
  517. CALL iom_open ( 'isf_draft_meter.nc', inum )
  518. CALL iom_get ( inum, jpdom_data, 'isf_draft', risfdep )
  519. CALL iom_close( inum )
  520. WHERE( bathy(:,:) <= 0._wp ) risfdep(:,:) = 0._wp
  521. END IF
  522. !
  523. IF( cp_cfg == "orca" .AND. jp_cfg == 2 ) THEN ! ORCA R2 configuration
  524. !
  525. IF( nn_cla == 0 ) THEN
  526. ii0 = 140 ; ii1 = 140 ! Gibraltar Strait open
  527. ij0 = 102 ; ij1 = 102 ! (Thomson, Ocean Modelling, 1995)
  528. DO ji = mi0(ii0), mi1(ii1)
  529. DO jj = mj0(ij0), mj1(ij1)
  530. bathy(ji,jj) = 284._wp
  531. END DO
  532. END DO
  533. IF(lwp) WRITE(numout,*)
  534. IF(lwp) WRITE(numout,*) ' orca_r2: Gibraltar strait open at i=',ii0,' j=',ij0
  535. !
  536. ii0 = 160 ; ii1 = 160 ! Bab el mandeb Strait open
  537. ij0 = 88 ; ij1 = 88 ! (Thomson, Ocean Modelling, 1995)
  538. DO ji = mi0(ii0), mi1(ii1)
  539. DO jj = mj0(ij0), mj1(ij1)
  540. bathy(ji,jj) = 137._wp
  541. END DO
  542. END DO
  543. IF(lwp) WRITE(numout,*)
  544. IF(lwp) WRITE(numout,*) ' orca_r2: Bab el Mandeb strait open at i=',ii0,' j=',ij0
  545. ENDIF
  546. !
  547. ENDIF
  548. !
  549. ENDIF
  550. ! ! =============== !
  551. ELSE ! error !
  552. ! ! =============== !
  553. WRITE(ctmp1,*) 'parameter , ntopo = ', ntopo
  554. CALL ctl_stop( ' zgr_bat : '//trim(ctmp1) )
  555. ENDIF
  556. !
  557. IF( nn_closea == 0 ) CALL clo_bat( bathy, mbathy ) !== NO closed seas or lakes ==!
  558. !
  559. IF ( .not. ln_sco ) THEN !== set a minimum depth ==!
  560. ! patch to avoid case bathy = ice shelf draft and bathy between 0 and zhmin
  561. IF ( ln_isfcav ) THEN
  562. WHERE (bathy == risfdep)
  563. bathy = 0.0_wp ; risfdep = 0.0_wp
  564. END WHERE
  565. END IF
  566. ! end patch
  567. IF( rn_hmin < 0._wp ) THEN ; ik = - INT( rn_hmin ) ! from a nb of level
  568. ELSE ; ik = MINLOC( gdepw_1d, mask = gdepw_1d > rn_hmin, dim = 1 ) ! from a depth
  569. ENDIF
  570. zhmin = gdepw_1d(ik+1) ! minimum depth = ik+1 w-levels
  571. WHERE( bathy(:,:) <= 0._wp ) ; bathy(:,:) = 0._wp ! min=0 over the lands
  572. ELSE WHERE ; bathy(:,:) = MAX( zhmin , bathy(:,:) ) ! min=zhmin over the oceans
  573. END WHERE
  574. IF(lwp) write(numout,*) 'Minimum ocean depth: ', zhmin, ' minimum number of ocean levels : ', ik
  575. ENDIF
  576. !
  577. IF( nn_timing == 1 ) CALL timing_stop('zgr_bat')
  578. !
  579. END SUBROUTINE zgr_bat
  580. SUBROUTINE zgr_bat_zoom
  581. !!----------------------------------------------------------------------
  582. !! *** ROUTINE zgr_bat_zoom ***
  583. !!
  584. !! ** Purpose : - Close zoom domain boundary if necessary
  585. !! - Suppress Med Sea from ORCA R2 and R05 arctic zoom
  586. !!
  587. !! ** Method :
  588. !!
  589. !! ** Action : - update mbathy: level bathymetry (in level index)
  590. !!----------------------------------------------------------------------
  591. INTEGER :: ii0, ii1, ij0, ij1 ! temporary integers
  592. !!----------------------------------------------------------------------
  593. !
  594. IF(lwp) WRITE(numout,*)
  595. IF(lwp) WRITE(numout,*) ' zgr_bat_zoom : modify the level bathymetry for zoom domain'
  596. IF(lwp) WRITE(numout,*) ' ~~~~~~~~~~~~'
  597. !
  598. ! Zoom domain
  599. ! ===========
  600. !
  601. ! Forced closed boundary if required
  602. IF( lzoom_s ) mbathy( : , mj0(jpjzoom):mj1(jpjzoom) ) = 0
  603. IF( lzoom_w ) mbathy( mi0(jpizoom):mi1(jpizoom) , : ) = 0
  604. IF( lzoom_e ) mbathy( mi0(jpiglo+jpizoom-1):mi1(jpiglo+jpizoom-1) , : ) = 0
  605. IF( lzoom_n ) mbathy( : , mj0(jpjglo+jpjzoom-1):mj1(jpjglo+jpjzoom-1) ) = 0
  606. !
  607. ! Configuration specific domain modifications
  608. ! (here, ORCA arctic configuration: suppress Med Sea)
  609. IF( cp_cfg == "orca" .AND. cp_cfz == "arctic" ) THEN
  610. SELECT CASE ( jp_cfg )
  611. ! ! =======================
  612. CASE ( 2 ) ! ORCA_R2 configuration
  613. ! ! =======================
  614. IF(lwp) WRITE(numout,*) ' ORCA R2 arctic zoom: suppress the Med Sea'
  615. ii0 = 141 ; ii1 = 162 ! Sea box i,j indices
  616. ij0 = 98 ; ij1 = 110
  617. ! ! =======================
  618. CASE ( 05 ) ! ORCA_R05 configuration
  619. ! ! =======================
  620. IF(lwp) WRITE(numout,*) ' ORCA R05 arctic zoom: suppress the Med Sea'
  621. ii0 = 563 ; ii1 = 642 ! zero over the Med Sea boxe
  622. ij0 = 314 ; ij1 = 370
  623. END SELECT
  624. !
  625. mbathy( mi0(ii0):mi1(ii1) , mj0(ij0):mj1(ij1) ) = 0 ! zero over the Med Sea boxe
  626. !
  627. ENDIF
  628. !
  629. END SUBROUTINE zgr_bat_zoom
  630. SUBROUTINE zgr_bat_ctl
  631. !!----------------------------------------------------------------------
  632. !! *** ROUTINE zgr_bat_ctl ***
  633. !!
  634. !! ** Purpose : check the bathymetry in levels
  635. !!
  636. !! ** Method : The array mbathy is checked to verified its consistency
  637. !! with the model options. in particular:
  638. !! mbathy must have at least 1 land grid-points (mbathy<=0)
  639. !! along closed boundary.
  640. !! mbathy must be cyclic IF jperio=1.
  641. !! mbathy must be lower or equal to jpk-1.
  642. !! isolated ocean grid points are suppressed from mbathy
  643. !! since they are only connected to remaining
  644. !! ocean through vertical diffusion.
  645. !! C A U T I O N : mbathy will be modified during the initializa-
  646. !! tion phase to become the number of non-zero w-levels of a water
  647. !! column, with a minimum value of 1.
  648. !!
  649. !! ** Action : - update mbathy: level bathymetry (in level index)
  650. !! - update bathy : meter bathymetry (in meters)
  651. !!----------------------------------------------------------------------
  652. !!
  653. INTEGER :: ji, jj, jl ! dummy loop indices
  654. INTEGER :: icompt, ibtest, ikmax ! temporary integers
  655. REAL(wp), POINTER, DIMENSION(:,:) :: zbathy
  656. !!----------------------------------------------------------------------
  657. !
  658. IF( nn_timing == 1 ) CALL timing_start('zgr_bat_ctl')
  659. !
  660. CALL wrk_alloc( jpi, jpj, zbathy )
  661. !
  662. IF(lwp) WRITE(numout,*)
  663. IF(lwp) WRITE(numout,*) ' zgr_bat_ctl : check the bathymetry'
  664. IF(lwp) WRITE(numout,*) ' ~~~~~~~~~~~'
  665. ! ! Suppress isolated ocean grid points
  666. IF(lwp) WRITE(numout,*)
  667. IF(lwp) WRITE(numout,*)' suppress isolated ocean grid points'
  668. IF(lwp) WRITE(numout,*)' -----------------------------------'
  669. icompt = 0
  670. DO jl = 1, 2
  671. IF( nperio == 1 .OR. nperio == 4 .OR. nperio == 6 ) THEN
  672. mbathy( 1 ,:) = mbathy(jpim1,:) ! local domain is cyclic east-west
  673. mbathy(jpi,:) = mbathy( 2 ,:)
  674. ENDIF
  675. DO jj = 2, jpjm1
  676. DO ji = 2, jpim1
  677. ibtest = MAX( mbathy(ji-1,jj), mbathy(ji+1,jj), &
  678. & mbathy(ji,jj-1), mbathy(ji,jj+1) )
  679. IF( ibtest < mbathy(ji,jj) ) THEN
  680. IF(lwp) WRITE(numout,*) ' the number of ocean level at ', &
  681. & 'grid-point (i,j) = ',ji,jj,' is changed from ', mbathy(ji,jj),' to ', ibtest
  682. mbathy(ji,jj) = ibtest
  683. icompt = icompt + 1
  684. ENDIF
  685. END DO
  686. END DO
  687. END DO
  688. IF( lk_mpp ) CALL mpp_sum( icompt )
  689. IF( icompt == 0 ) THEN
  690. IF(lwp) WRITE(numout,*)' no isolated ocean grid points'
  691. ELSE
  692. IF(lwp) WRITE(numout,*)' ',icompt,' ocean grid points suppressed'
  693. ENDIF
  694. IF( lk_mpp ) THEN
  695. zbathy(:,:) = FLOAT( mbathy(:,:) )
  696. CALL lbc_lnk( zbathy, 'T', 1._wp )
  697. mbathy(:,:) = INT( zbathy(:,:) )
  698. ENDIF
  699. ! ! East-west cyclic boundary conditions
  700. IF( nperio == 0 ) THEN
  701. IF(lwp) WRITE(numout,*) ' mbathy set to 0 along east and west boundary: nperio = ', nperio
  702. IF( lk_mpp ) THEN
  703. IF( nbondi == -1 .OR. nbondi == 2 ) THEN
  704. IF( jperio /= 1 ) mbathy(1,:) = 0
  705. ENDIF
  706. IF( nbondi == 1 .OR. nbondi == 2 ) THEN
  707. IF( jperio /= 1 ) mbathy(nlci,:) = 0
  708. ENDIF
  709. ELSE
  710. IF( ln_zco .OR. ln_zps ) THEN
  711. mbathy( 1 ,:) = 0
  712. mbathy(jpi,:) = 0
  713. ELSE
  714. mbathy( 1 ,:) = jpkm1
  715. mbathy(jpi,:) = jpkm1
  716. ENDIF
  717. ENDIF
  718. ELSEIF( nperio == 1 .OR. nperio == 4 .OR. nperio == 6 ) THEN
  719. IF(lwp) WRITE(numout,*)' east-west cyclic boundary conditions on mbathy: nperio = ', nperio
  720. mbathy( 1 ,:) = mbathy(jpim1,:)
  721. mbathy(jpi,:) = mbathy( 2 ,:)
  722. ELSEIF( nperio == 2 ) THEN
  723. IF(lwp) WRITE(numout,*) ' equatorial boundary conditions on mbathy: nperio = ', nperio
  724. ELSE
  725. IF(lwp) WRITE(numout,*) ' e r r o r'
  726. IF(lwp) WRITE(numout,*) ' parameter , nperio = ', nperio
  727. ! STOP 'dom_mba'
  728. ENDIF
  729. ! Boundary condition on mbathy
  730. IF( .NOT.lk_mpp ) THEN
  731. !!gm !!bug ??? think about it !
  732. ! ... mono- or macro-tasking: T-point, >0, 2D array, no slab
  733. zbathy(:,:) = FLOAT( mbathy(:,:) )
  734. CALL lbc_lnk( zbathy, 'T', 1._wp )
  735. mbathy(:,:) = INT( zbathy(:,:) )
  736. ENDIF
  737. ! Number of ocean level inferior or equal to jpkm1
  738. ikmax = 0
  739. DO jj = 1, jpj
  740. DO ji = 1, jpi
  741. ikmax = MAX( ikmax, mbathy(ji,jj) )
  742. END DO
  743. END DO
  744. !!gm !!! test to do: ikmax = MAX( mbathy(:,:) ) ???
  745. IF( ikmax > jpkm1 ) THEN
  746. IF(lwp) WRITE(numout,*) ' maximum number of ocean level = ', ikmax,' > jpk-1'
  747. IF(lwp) WRITE(numout,*) ' change jpk to ',ikmax+1,' to use the exact ead bathymetry'
  748. ELSE IF( ikmax < jpkm1 ) THEN
  749. IF(lwp) WRITE(numout,*) ' maximum number of ocean level = ', ikmax,' < jpk-1'
  750. IF(lwp) WRITE(numout,*) ' you can decrease jpk to ', ikmax+1
  751. ENDIF
  752. IF( lwp .AND. nprint == 1 ) THEN ! control print
  753. WRITE(numout,*)
  754. WRITE(numout,*) ' bathymetric field : number of non-zero T-levels '
  755. WRITE(numout,*) ' ------------------'
  756. CALL prihin( mbathy, jpi, jpj, 1, jpi, 1, 1, jpj, 1, 3, numout )
  757. WRITE(numout,*)
  758. ENDIF
  759. !
  760. CALL wrk_dealloc( jpi, jpj, zbathy )
  761. !
  762. IF( nn_timing == 1 ) CALL timing_stop('zgr_bat_ctl')
  763. !
  764. END SUBROUTINE zgr_bat_ctl
  765. SUBROUTINE zgr_bot_level
  766. !!----------------------------------------------------------------------
  767. !! *** ROUTINE zgr_bot_level ***
  768. !!
  769. !! ** Purpose : defines the vertical index of ocean bottom (mbk. arrays)
  770. !!
  771. !! ** Method : computes from mbathy with a minimum value of 1 over land
  772. !!
  773. !! ** Action : mbkt, mbku, mbkv : vertical indices of the deeptest
  774. !! ocean level at t-, u- & v-points
  775. !! (min value = 1 over land)
  776. !!----------------------------------------------------------------------
  777. !!
  778. INTEGER :: ji, jj ! dummy loop indices
  779. REAL(wp), POINTER, DIMENSION(:,:) :: zmbk
  780. !!----------------------------------------------------------------------
  781. !
  782. IF( nn_timing == 1 ) CALL timing_start('zgr_bot_level')
  783. !
  784. CALL wrk_alloc( jpi, jpj, zmbk )
  785. !
  786. IF(lwp) WRITE(numout,*)
  787. IF(lwp) WRITE(numout,*) ' zgr_bot_level : ocean bottom k-index of T-, U-, V- and W-levels '
  788. IF(lwp) WRITE(numout,*) ' ~~~~~~~~~~~~~'
  789. !
  790. mbkt(:,:) = MAX( mbathy(:,:) , 1 ) ! bottom k-index of T-level (=1 over land)
  791. ! ! bottom k-index of W-level = mbkt+1
  792. DO jj = 1, jpjm1 ! bottom k-index of u- (v-) level
  793. DO ji = 1, jpim1
  794. mbku(ji,jj) = MIN( mbkt(ji+1,jj ) , mbkt(ji,jj) )
  795. mbkv(ji,jj) = MIN( mbkt(ji ,jj+1) , mbkt(ji,jj) )
  796. END DO
  797. END DO
  798. ! converte into REAL to use lbc_lnk ; impose a min value of 1 as a zero can be set in lbclnk
  799. zmbk(:,:) = REAL( mbku(:,:), wp ) ; CALL lbc_lnk(zmbk,'U',1.) ; mbku (:,:) = MAX( INT( zmbk(:,:) ), 1 )
  800. zmbk(:,:) = REAL( mbkv(:,:), wp ) ; CALL lbc_lnk(zmbk,'V',1.) ; mbkv (:,:) = MAX( INT( zmbk(:,:) ), 1 )
  801. !
  802. CALL wrk_dealloc( jpi, jpj, zmbk )
  803. !
  804. IF( nn_timing == 1 ) CALL timing_stop('zgr_bot_level')
  805. !
  806. END SUBROUTINE zgr_bot_level
  807. SUBROUTINE zgr_top_level
  808. !!----------------------------------------------------------------------
  809. !! *** ROUTINE zgr_bot_level ***
  810. !!
  811. !! ** Purpose : defines the vertical index of ocean top (mik. arrays)
  812. !!
  813. !! ** Method : computes from misfdep with a minimum value of 1
  814. !!
  815. !! ** Action : mikt, miku, mikv : vertical indices of the shallowest
  816. !! ocean level at t-, u- & v-points
  817. !! (min value = 1)
  818. !!----------------------------------------------------------------------
  819. !!
  820. INTEGER :: ji, jj ! dummy loop indices
  821. REAL(wp), POINTER, DIMENSION(:,:) :: zmik
  822. !!----------------------------------------------------------------------
  823. !
  824. IF( nn_timing == 1 ) CALL timing_start('zgr_top_level')
  825. !
  826. CALL wrk_alloc( jpi, jpj, zmik )
  827. !
  828. IF(lwp) WRITE(numout,*)
  829. IF(lwp) WRITE(numout,*) ' zgr_top_level : ocean top k-index of T-, U-, V- and W-levels '
  830. IF(lwp) WRITE(numout,*) ' ~~~~~~~~~~~~~'
  831. !
  832. mikt(:,:) = MAX( misfdep(:,:) , 1 ) ! top k-index of T-level (=1)
  833. ! ! top k-index of W-level (=mikt)
  834. DO jj = 1, jpjm1 ! top k-index of U- (U-) level
  835. DO ji = 1, jpim1
  836. miku(ji,jj) = MAX( mikt(ji+1,jj ) , mikt(ji,jj) )
  837. mikv(ji,jj) = MAX( mikt(ji ,jj+1) , mikt(ji,jj) )
  838. mikf(ji,jj) = MAX( mikt(ji ,jj+1) , mikt(ji,jj), mikt(ji+1,jj ), mikt(ji+1,jj+1) )
  839. END DO
  840. END DO
  841. ! converte into REAL to use lbc_lnk ; impose a min value of 1 as a zero can be set in lbclnk
  842. zmik(:,:) = REAL( miku(:,:), wp ) ; CALL lbc_lnk(zmik,'U',1.) ; miku (:,:) = MAX( INT( zmik(:,:) ), 1 )
  843. zmik(:,:) = REAL( mikv(:,:), wp ) ; CALL lbc_lnk(zmik,'V',1.) ; mikv (:,:) = MAX( INT( zmik(:,:) ), 1 )
  844. zmik(:,:) = REAL( mikf(:,:), wp ) ; CALL lbc_lnk(zmik,'F',1.) ; mikf (:,:) = MAX( INT( zmik(:,:) ), 1 )
  845. !
  846. CALL wrk_dealloc( jpi, jpj, zmik )
  847. !
  848. IF( nn_timing == 1 ) CALL timing_stop('zgr_top_level')
  849. !
  850. END SUBROUTINE zgr_top_level
  851. SUBROUTINE zgr_zco
  852. !!----------------------------------------------------------------------
  853. !! *** ROUTINE zgr_zco ***
  854. !!
  855. !! ** Purpose : define the z-coordinate system
  856. !!
  857. !! ** Method : set 3D coord. arrays to reference 1D array
  858. !!----------------------------------------------------------------------
  859. INTEGER :: jk
  860. !!----------------------------------------------------------------------
  861. !
  862. IF( nn_timing == 1 ) CALL timing_start('zgr_zco')
  863. !
  864. DO jk = 1, jpk
  865. gdept_0 (:,:,jk) = gdept_1d(jk)
  866. gdepw_0 (:,:,jk) = gdepw_1d(jk)
  867. gdep3w_0(:,:,jk) = gdepw_1d(jk)
  868. e3t_0 (:,:,jk) = e3t_1d (jk)
  869. e3u_0 (:,:,jk) = e3t_1d (jk)
  870. e3v_0 (:,:,jk) = e3t_1d (jk)
  871. e3f_0 (:,:,jk) = e3t_1d (jk)
  872. e3w_0 (:,:,jk) = e3w_1d (jk)
  873. e3uw_0 (:,:,jk) = e3w_1d (jk)
  874. e3vw_0 (:,:,jk) = e3w_1d (jk)
  875. END DO
  876. !
  877. IF( nn_timing == 1 ) CALL timing_stop('zgr_zco')
  878. !
  879. END SUBROUTINE zgr_zco
  880. SUBROUTINE zgr_zps
  881. !!----------------------------------------------------------------------
  882. !! *** ROUTINE zgr_zps ***
  883. !!
  884. !! ** Purpose : the depth and vertical scale factor in partial step
  885. !! z-coordinate case
  886. !!
  887. !! ** Method : Partial steps : computes the 3D vertical scale factors
  888. !! of T-, U-, V-, W-, UW-, VW and F-points that are associated with
  889. !! a partial step representation of bottom topography.
  890. !!
  891. !! The reference depth of model levels is defined from an analytical
  892. !! function the derivative of which gives the reference vertical
  893. !! scale factors.
  894. !! From depth and scale factors reference, we compute there new value
  895. !! with partial steps on 3d arrays ( i, j, k ).
  896. !!
  897. !! w-level: gdepw_0(i,j,k) = gdep(k)
  898. !! e3w_0(i,j,k) = dk(gdep)(k) = e3(i,j,k)
  899. !! t-level: gdept_0(i,j,k) = gdep(k+0.5)
  900. !! e3t_0(i,j,k) = dk(gdep)(k+0.5) = e3(i,j,k+0.5)
  901. !!
  902. !! With the help of the bathymetric file ( bathymetry_depth_ORCA_R2.nc),
  903. !! we find the mbathy index of the depth at each grid point.
  904. !! This leads us to three cases:
  905. !!
  906. !! - bathy = 0 => mbathy = 0
  907. !! - 1 < mbathy < jpkm1
  908. !! - bathy > gdepw_0(jpk) => mbathy = jpkm1
  909. !!
  910. !! Then, for each case, we find the new depth at t- and w- levels
  911. !! and the new vertical scale factors at t-, u-, v-, w-, uw-, vw-
  912. !! and f-points.
  913. !!
  914. !! This routine is given as an example, it must be modified
  915. !! following the user s desiderata. nevertheless, the output as
  916. !! well as the way to compute the model levels and scale factors
  917. !! must be respected in order to insure second order accuracy
  918. !! schemes.
  919. !!
  920. !! c a u t i o n : gdept_1d, gdepw_1d and e3._1d are positives
  921. !! - - - - - - - gdept_0, gdepw_0 and e3. are positives
  922. !!
  923. !! Reference : Pacanowsky & Gnanadesikan 1997, Mon. Wea. Rev., 126, 3248-3270.
  924. !!----------------------------------------------------------------------
  925. !!
  926. INTEGER :: ji, jj, jk ! dummy loop indices
  927. INTEGER :: ik, it, ikb, ikt ! temporary integers
  928. LOGICAL :: ll_print ! Allow control print for debugging
  929. REAL(wp) :: ze3tp , ze3wp ! Last ocean level thickness at T- and W-points
  930. REAL(wp) :: zdepwp, zdepth ! Ajusted ocean depth to avoid too small e3t
  931. REAL(wp) :: zmax ! Maximum depth
  932. REAL(wp) :: zdiff ! temporary scalar
  933. REAL(wp) :: zrefdep ! temporary scalar
  934. REAL(wp), POINTER, DIMENSION(:,:,:) :: zprt
  935. !!---------------------------------------------------------------------
  936. !
  937. IF( nn_timing == 1 ) CALL timing_start('zgr_zps')
  938. !
  939. CALL wrk_alloc( jpi, jpj, jpk, zprt )
  940. !
  941. IF(lwp) WRITE(numout,*)
  942. IF(lwp) WRITE(numout,*) ' zgr_zps : z-coordinate with partial steps'
  943. IF(lwp) WRITE(numout,*) ' ~~~~~~~ '
  944. IF(lwp) WRITE(numout,*) ' mbathy is recomputed : bathy_level file is NOT used'
  945. ll_print = .FALSE. ! Local variable for debugging
  946. IF(lwp .AND. ll_print) THEN ! control print of the ocean depth
  947. WRITE(numout,*)
  948. WRITE(numout,*) 'dom_zgr_zps: bathy (in hundred of meters)'
  949. CALL prihre( bathy, jpi, jpj, 1,jpi, 1, 1, jpj, 1, 1.e-2, numout )
  950. ENDIF
  951. ! bathymetry in level (from bathy_meter)
  952. ! ===================
  953. zmax = gdepw_1d(jpk) + e3t_1d(jpk) ! maximum depth (i.e. the last ocean level thickness <= 2*e3t_1d(jpkm1) )
  954. bathy(:,:) = MIN( zmax , bathy(:,:) ) ! bounded value of bathy (min already set at the end of zgr_bat)
  955. WHERE( bathy(:,:) == 0._wp ) ; mbathy(:,:) = 0 ! land : set mbathy to 0
  956. ELSE WHERE ; mbathy(:,:) = jpkm1 ! ocean : initialize mbathy to the max ocean level
  957. END WHERE
  958. ! Compute mbathy for ocean points (i.e. the number of ocean levels)
  959. ! find the number of ocean levels such that the last level thickness
  960. ! is larger than the minimum of e3zps_min and e3zps_rat * e3t_1d (where
  961. ! e3t_1d is the reference level thickness
  962. DO jk = jpkm1, 1, -1
  963. zdepth = gdepw_1d(jk) + MIN( e3zps_min, e3t_1d(jk)*e3zps_rat )
  964. WHERE( 0._wp < bathy(:,:) .AND. bathy(:,:) <= zdepth ) mbathy(:,:) = jk-1
  965. END DO
  966. IF ( ln_isfcav ) CALL zgr_isf
  967. ! Scale factors and depth at T- and W-points
  968. DO jk = 1, jpk ! intitialization to the reference z-coordinate
  969. gdept_0(:,:,jk) = gdept_1d(jk)
  970. gdepw_0(:,:,jk) = gdepw_1d(jk)
  971. e3t_0 (:,:,jk) = e3t_1d (jk)
  972. e3w_0 (:,:,jk) = e3w_1d (jk)
  973. END DO
  974. !
  975. DO jj = 1, jpj
  976. DO ji = 1, jpi
  977. ik = mbathy(ji,jj)
  978. IF( ik > 0 ) THEN ! ocean point only
  979. ! max ocean level case
  980. IF( ik == jpkm1 ) THEN
  981. zdepwp = bathy(ji,jj)
  982. ze3tp = bathy(ji,jj) - gdepw_1d(ik)
  983. ze3wp = 0.5_wp * e3w_1d(ik) * ( 1._wp + ( ze3tp/e3t_1d(ik) ) )
  984. e3t_0(ji,jj,ik ) = ze3tp
  985. e3t_0(ji,jj,ik+1) = ze3tp
  986. e3w_0(ji,jj,ik ) = ze3wp
  987. e3w_0(ji,jj,ik+1) = ze3tp
  988. gdepw_0(ji,jj,ik+1) = zdepwp
  989. gdept_0(ji,jj,ik ) = gdept_1d(ik-1) + ze3wp
  990. gdept_0(ji,jj,ik+1) = gdept_0(ji,jj,ik) + ze3tp
  991. !
  992. ELSE ! standard case
  993. IF( bathy(ji,jj) <= gdepw_1d(ik+1) ) THEN ; gdepw_0(ji,jj,ik+1) = bathy(ji,jj)
  994. ELSE ; gdepw_0(ji,jj,ik+1) = gdepw_1d(ik+1)
  995. ENDIF
  996. !gm Bug? check the gdepw_1d
  997. ! ... on ik
  998. gdept_0(ji,jj,ik) = gdepw_1d(ik) + ( gdepw_0(ji,jj,ik+1) - gdepw_1d(ik) ) &
  999. & * ((gdept_1d( ik ) - gdepw_1d(ik) ) &
  1000. & / ( gdepw_1d( ik+1) - gdepw_1d(ik) ))
  1001. e3t_0 (ji,jj,ik) = e3t_1d (ik) * ( gdepw_0 (ji,jj,ik+1) - gdepw_1d(ik) ) &
  1002. & / ( gdepw_1d( ik+1) - gdepw_1d(ik) )
  1003. e3w_0(ji,jj,ik) = 0.5_wp * ( gdepw_0(ji,jj,ik+1) + gdepw_1d(ik+1) - 2._wp * gdepw_1d(ik) ) &
  1004. & * ( e3w_1d(ik) / ( gdepw_1d(ik+1) - gdepw_1d(ik) ) )
  1005. ! ... on ik+1
  1006. e3w_0 (ji,jj,ik+1) = e3t_0 (ji,jj,ik)
  1007. e3t_0 (ji,jj,ik+1) = e3t_0 (ji,jj,ik)
  1008. gdept_0(ji,jj,ik+1) = gdept_0(ji,jj,ik) + e3t_0(ji,jj,ik)
  1009. ENDIF
  1010. ENDIF
  1011. END DO
  1012. END DO
  1013. !
  1014. it = 0
  1015. DO jj = 1, jpj
  1016. DO ji = 1, jpi
  1017. ik = mbathy(ji,jj)
  1018. IF( ik > 0 ) THEN ! ocean point only
  1019. e3tp (ji,jj) = e3t_0(ji,jj,ik)
  1020. e3wp (ji,jj) = e3w_0(ji,jj,ik)
  1021. ! test
  1022. zdiff= gdepw_0(ji,jj,ik+1) - gdept_0(ji,jj,ik )
  1023. IF( zdiff <= 0._wp .AND. lwp ) THEN
  1024. it = it + 1
  1025. WRITE(numout,*) ' it = ', it, ' ik = ', ik, ' (i,j) = ', ji, jj
  1026. WRITE(numout,*) ' bathy = ', bathy(ji,jj)
  1027. WRITE(numout,*) ' gdept_0 = ', gdept_0(ji,jj,ik), ' gdepw_0 = ', gdepw_0(ji,jj,ik+1), ' zdiff = ', zdiff
  1028. WRITE(numout,*) ' e3tp = ', e3t_0 (ji,jj,ik), ' e3wp = ', e3w_0 (ji,jj,ik )
  1029. ENDIF
  1030. ENDIF
  1031. END DO
  1032. END DO
  1033. !
  1034. IF ( ln_isfcav ) THEN
  1035. ! (ISF) Definition of e3t, u, v, w for ISF case
  1036. DO jj = 1, jpj
  1037. DO ji = 1, jpi
  1038. ik = misfdep(ji,jj)
  1039. IF( ik > 1 ) THEN ! ice shelf point only
  1040. IF( risfdep(ji,jj) < gdepw_1d(ik) ) risfdep(ji,jj)= gdepw_1d(ik)
  1041. gdepw_0(ji,jj,ik) = risfdep(ji,jj)
  1042. !gm Bug? check the gdepw_0
  1043. ! ... on ik
  1044. gdept_0(ji,jj,ik) = gdepw_1d(ik+1) - ( gdepw_1d(ik+1) - gdepw_0(ji,jj,ik) ) &
  1045. & * ( gdepw_1d(ik+1) - gdept_1d(ik) ) &
  1046. & / ( gdepw_1d(ik+1) - gdepw_1d(ik) )
  1047. e3t_0 (ji,jj,ik ) = gdepw_1d(ik+1) - gdepw_0(ji,jj,ik)
  1048. e3w_0 (ji,jj,ik+1) = gdept_1d(ik+1) - gdept_0(ji,jj,ik)
  1049. IF( ik + 1 == mbathy(ji,jj) ) THEN ! ice shelf point only (2 cell water column)
  1050. e3w_0 (ji,jj,ik+1) = gdept_0(ji,jj,ik+1) - gdept_0(ji,jj,ik)
  1051. ENDIF
  1052. ! ... on ik / ik-1
  1053. e3w_0 (ji,jj,ik ) = 2._wp * (gdept_0(ji,jj,ik) - gdepw_0(ji,jj,ik))
  1054. e3t_0 (ji,jj,ik-1) = gdepw_0(ji,jj,ik) - gdepw_1d(ik-1)
  1055. ! The next line isn't required and doesn't affect results - included for consistency with bathymetry code
  1056. gdept_0(ji,jj,ik-1) = gdept_1d(ik-1)
  1057. ENDIF
  1058. END DO
  1059. END DO
  1060. !
  1061. it = 0
  1062. DO jj = 1, jpj
  1063. DO ji = 1, jpi
  1064. ik = misfdep(ji,jj)
  1065. IF( ik > 1 ) THEN ! ice shelf point only
  1066. e3tp (ji,jj) = e3t_0(ji,jj,ik )
  1067. e3wp (ji,jj) = e3w_0(ji,jj,ik+1 )
  1068. ! test
  1069. zdiff= gdept_0(ji,jj,ik) - gdepw_0(ji,jj,ik )
  1070. IF( zdiff <= 0. .AND. lwp ) THEN
  1071. it = it + 1
  1072. WRITE(numout,*) ' it = ', it, ' ik = ', ik, ' (i,j) = ', ji, jj
  1073. WRITE(numout,*) ' risfdep = ', risfdep(ji,jj)
  1074. WRITE(numout,*) ' gdept = ', gdept_0(ji,jj,ik), ' gdepw = ', gdepw_0(ji,jj,ik+1), ' zdiff = ', zdiff
  1075. WRITE(numout,*) ' e3tp = ', e3tp(ji,jj), ' e3wp = ', e3wp(ji,jj)
  1076. ENDIF
  1077. ENDIF
  1078. END DO
  1079. END DO
  1080. END IF
  1081. ! END (ISF)
  1082. ! Scale factors and depth at U-, V-, UW and VW-points
  1083. DO jk = 1, jpk ! initialisation to z-scale factors
  1084. e3u_0 (:,:,jk) = e3t_1d(jk)
  1085. e3v_0 (:,:,jk) = e3t_1d(jk)
  1086. e3uw_0(:,:,jk) = e3w_1d(jk)
  1087. e3vw_0(:,:,jk) = e3w_1d(jk)
  1088. END DO
  1089. DO jk = 1,jpk ! Computed as the minimum of neighbooring scale factors
  1090. DO jj = 1, jpjm1
  1091. DO ji = 1, fs_jpim1 ! vector opt.
  1092. e3u_0 (ji,jj,jk) = MIN( e3t_0(ji,jj,jk), e3t_0(ji+1,jj,jk) )
  1093. e3v_0 (ji,jj,jk) = MIN( e3t_0(ji,jj,jk), e3t_0(ji,jj+1,jk) )
  1094. e3uw_0(ji,jj,jk) = MIN( e3w_0(ji,jj,jk), e3w_0(ji+1,jj,jk) )
  1095. e3vw_0(ji,jj,jk) = MIN( e3w_0(ji,jj,jk), e3w_0(ji,jj+1,jk) )
  1096. END DO
  1097. END DO
  1098. END DO
  1099. IF ( ln_isfcav ) THEN
  1100. ! (ISF) define e3uw (adapted for 2 cells in the water column)
  1101. DO jj = 2, jpjm1
  1102. DO ji = 2, fs_jpim1 ! vector opt.
  1103. ikb = MAX(mbathy (ji,jj),mbathy (ji+1,jj))
  1104. ikt = MAX(misfdep(ji,jj),misfdep(ji+1,jj))
  1105. IF (ikb == ikt+1) e3uw_0(ji,jj,ikb) = MIN( gdept_0(ji,jj,ikb ), gdept_0(ji+1,jj ,ikb ) ) &
  1106. & - MAX( gdept_0(ji,jj,ikb-1), gdept_0(ji+1,jj ,ikb-1) )
  1107. ikb = MAX(mbathy (ji,jj),mbathy (ji,jj+1))
  1108. ikt = MAX(misfdep(ji,jj),misfdep(ji,jj+1))
  1109. IF (ikb == ikt+1) e3vw_0(ji,jj,ikb) = MIN( gdept_0(ji,jj,ikb ), gdept_0(ji ,jj+1,ikb ) ) &
  1110. & - MAX( gdept_0(ji,jj,ikb-1), gdept_0(ji ,jj+1,ikb-1) )
  1111. END DO
  1112. END DO
  1113. END IF
  1114. CALL lbc_lnk( e3u_0 , 'U', 1._wp ) ; CALL lbc_lnk( e3uw_0, 'U', 1._wp ) ! lateral boundary conditions
  1115. CALL lbc_lnk( e3v_0 , 'V', 1._wp ) ; CALL lbc_lnk( e3vw_0, 'V', 1._wp )
  1116. !
  1117. DO jk = 1, jpk ! set to z-scale factor if zero (i.e. along closed boundaries)
  1118. WHERE( e3u_0 (:,:,jk) == 0._wp ) e3u_0 (:,:,jk) = e3t_1d(jk)
  1119. WHERE( e3v_0 (:,:,jk) == 0._wp ) e3v_0 (:,:,jk) = e3t_1d(jk)
  1120. WHERE( e3uw_0(:,:,jk) == 0._wp ) e3uw_0(:,:,jk) = e3w_1d(jk)
  1121. WHERE( e3vw_0(:,:,jk) == 0._wp ) e3vw_0(:,:,jk) = e3w_1d(jk)
  1122. END DO
  1123. ! Scale factor at F-point
  1124. DO jk = 1, jpk ! initialisation to z-scale factors
  1125. e3f_0(:,:,jk) = e3t_1d(jk)
  1126. END DO
  1127. DO jk = 1, jpk ! Computed as the minimum of neighbooring V-scale factors
  1128. DO jj = 1, jpjm1
  1129. DO ji = 1, fs_jpim1 ! vector opt.
  1130. e3f_0(ji,jj,jk) = MIN( e3v_0(ji,jj,jk), e3v_0(ji+1,jj,jk) )
  1131. END DO
  1132. END DO
  1133. END DO
  1134. CALL lbc_lnk( e3f_0, 'F', 1._wp ) ! Lateral boundary conditions
  1135. !
  1136. DO jk = 1, jpk ! set to z-scale factor if zero (i.e. along closed boundaries)
  1137. WHERE( e3f_0(:,:,jk) == 0._wp ) e3f_0(:,:,jk) = e3t_1d(jk)
  1138. END DO
  1139. !!gm bug ? : must be a do loop with mj0,mj1
  1140. !
  1141. e3t_0(:,mj0(1),:) = e3t_0(:,mj0(2),:) ! we duplicate factor scales for jj = 1 and jj = 2
  1142. e3w_0(:,mj0(1),:) = e3w_0(:,mj0(2),:)
  1143. e3u_0(:,mj0(1),:) = e3u_0(:,mj0(2),:)
  1144. e3v_0(:,mj0(1),:) = e3v_0(:,mj0(2),:)
  1145. e3f_0(:,mj0(1),:) = e3f_0(:,mj0(2),:)
  1146. ! Control of the sign
  1147. IF( MINVAL( e3t_0 (:,:,:) ) <= 0._wp ) CALL ctl_stop( ' zgr_zps : e r r o r e3t_0 <= 0' )
  1148. IF( MINVAL( e3w_0 (:,:,:) ) <= 0._wp ) CALL ctl_stop( ' zgr_zps : e r r o r e3w_0 <= 0' )
  1149. IF( MINVAL( gdept_0(:,:,:) ) < 0._wp ) CALL ctl_stop( ' zgr_zps : e r r o r gdept_0 < 0' )
  1150. IF( MINVAL( gdepw_0(:,:,:) ) < 0._wp ) CALL ctl_stop( ' zgr_zps : e r r o r gdepw_0 < 0' )
  1151. ! Compute gdep3w_0 (vertical sum of e3w)
  1152. IF ( ln_isfcav ) THEN ! if cavity
  1153. WHERE (misfdep == 0) misfdep = 1
  1154. DO jj = 1,jpj
  1155. DO ji = 1,jpi
  1156. gdep3w_0(ji,jj,1) = 0.5_wp * e3w_0(ji,jj,1)
  1157. DO jk = 2, misfdep(ji,jj)
  1158. gdep3w_0(ji,jj,jk) = gdep3w_0(ji,jj,jk-1) + e3w_0(ji,jj,jk)
  1159. END DO
  1160. IF (misfdep(ji,jj) .GE. 2) gdep3w_0(ji,jj,misfdep(ji,jj)) = risfdep(ji,jj) + 0.5_wp * e3w_0(ji,jj,misfdep(ji,jj))
  1161. DO jk = misfdep(ji,jj) + 1, jpk
  1162. gdep3w_0(ji,jj,jk) = gdep3w_0(ji,jj,jk-1) + e3w_0(ji,jj,jk)
  1163. END DO
  1164. END DO
  1165. END DO
  1166. ELSE ! no cavity
  1167. gdep3w_0(:,:,1) = 0.5_wp * e3w_0(:,:,1)
  1168. DO jk = 2, jpk
  1169. gdep3w_0(:,:,jk) = gdep3w_0(:,:,jk-1) + e3w_0(:,:,jk)
  1170. END DO
  1171. END IF
  1172. ! ! ================= !
  1173. IF(lwp .AND. ll_print) THEN ! Control print !
  1174. ! ! ================= !
  1175. DO jj = 1,jpj
  1176. DO ji = 1, jpi
  1177. ik = MAX( mbathy(ji,jj), 1 )
  1178. zprt(ji,jj,1) = e3t_0 (ji,jj,ik)
  1179. zprt(ji,jj,2) = e3w_0 (ji,jj,ik)
  1180. zprt(ji,jj,3) = e3u_0 (ji,jj,ik)
  1181. zprt(ji,jj,4) = e3v_0 (ji,jj,ik)
  1182. zprt(ji,jj,5) = e3f_0 (ji,jj,ik)
  1183. zprt(ji,jj,6) = gdep3w_0(ji,jj,ik)
  1184. END DO
  1185. END DO
  1186. WRITE(numout,*)
  1187. WRITE(numout,*) 'domzgr e3t(mbathy)' ; CALL prihre(zprt(:,:,1),jpi,jpj,1,jpi,1,1,jpj,1,1.e-3,numout)
  1188. WRITE(numout,*)
  1189. WRITE(numout,*) 'domzgr e3w(mbathy)' ; CALL prihre(zprt(:,:,2),jpi,jpj,1,jpi,1,1,jpj,1,1.e-3,numout)
  1190. WRITE(numout,*)
  1191. WRITE(numout,*) 'domzgr e3u(mbathy)' ; CALL prihre(zprt(:,:,3),jpi,jpj,1,jpi,1,1,jpj,1,1.e-3,numout)
  1192. WRITE(numout,*)
  1193. WRITE(numout,*) 'domzgr e3v(mbathy)' ; CALL prihre(zprt(:,:,4),jpi,jpj,1,jpi,1,1,jpj,1,1.e-3,numout)
  1194. WRITE(numout,*)
  1195. WRITE(numout,*) 'domzgr e3f(mbathy)' ; CALL prihre(zprt(:,:,5),jpi,jpj,1,jpi,1,1,jpj,1,1.e-3,numout)
  1196. WRITE(numout,*)
  1197. WRITE(numout,*) 'domzgr gdep3w(mbathy)' ; CALL prihre(zprt(:,:,6),jpi,jpj,1,jpi,1,1,jpj,1,1.e-3,numout)
  1198. ENDIF
  1199. !
  1200. CALL wrk_dealloc( jpi, jpj, jpk, zprt )
  1201. !
  1202. IF( nn_timing == 1 ) CALL timing_stop('zgr_zps')
  1203. !
  1204. END SUBROUTINE zgr_zps
  1205. SUBROUTINE zgr_isf
  1206. !!----------------------------------------------------------------------
  1207. !! *** ROUTINE zgr_isf ***
  1208. !!
  1209. !! ** Purpose : check the bathymetry in levels
  1210. !!
  1211. !! ** Method : THe water column have to contained at least 2 cells
  1212. !! Bathymetry and isfdraft are modified (dig/close) to respect
  1213. !! this criterion.
  1214. !!
  1215. !!
  1216. !! ** Action : - test compatibility between isfdraft and bathy
  1217. !! - bathy and isfdraft are modified
  1218. !!----------------------------------------------------------------------
  1219. !!
  1220. INTEGER :: ji, jj, jk, jl ! dummy loop indices
  1221. INTEGER :: ik, it ! temporary integers
  1222. INTEGER :: id, jd, nprocd
  1223. INTEGER :: icompt, ibtest, ibtestim1, ibtestip1, ibtestjm1, ibtestjp1 ! (ISF)
  1224. LOGICAL :: ll_print ! Allow control print for debugging
  1225. REAL(wp) :: ze3tp , ze3wp ! Last ocean level thickness at T- and W-points
  1226. REAL(wp) :: zdepwp, zdepth ! Ajusted ocean depth to avoid too small e3t
  1227. REAL(wp) :: zmax, zmin ! Maximum and minimum depth
  1228. REAL(wp) :: zdiff ! temporary scalar
  1229. REAL(wp) :: zrefdep ! temporary scalar
  1230. REAL(wp) :: zbathydiff, zrisfdepdiff ! isf temporary scalar
  1231. REAL(wp), POINTER, DIMENSION(:,:) :: zrisfdep, zbathy, zmask ! 2D workspace (ISH)
  1232. INTEGER , POINTER, DIMENSION(:,:) :: zmbathy, zmisfdep ! 2D workspace (ISH)
  1233. !!---------------------------------------------------------------------
  1234. !
  1235. IF( nn_timing == 1 ) CALL timing_start('zgr_isf')
  1236. !
  1237. CALL wrk_alloc( jpi, jpj, zbathy, zmask, zrisfdep)
  1238. CALL wrk_alloc( jpi, jpj, zmisfdep, zmbathy )
  1239. ! (ISF) compute misfdep
  1240. WHERE( risfdep(:,:) == 0._wp .AND. bathy(:,:) .NE. 0) ; misfdep(:,:) = 1 ! open water : set misfdep to 1
  1241. ELSEWHERE ; misfdep(:,:) = 2 ! iceshelf : initialize misfdep to second level
  1242. END WHERE
  1243. ! Compute misfdep for ocean points (i.e. first wet level)
  1244. ! find the first ocean level such that the first level thickness
  1245. ! is larger than the bot_level of e3zps_min and e3zps_rat * e3t_0 (where
  1246. ! e3t_0 is the reference level thickness
  1247. DO jk = 2, jpkm1
  1248. zdepth = gdepw_1d(jk+1) - MIN( e3zps_min, e3t_1d(jk)*e3zps_rat )
  1249. WHERE( 0._wp < risfdep(:,:) .AND. risfdep(:,:) >= zdepth ) misfdep(:,:) = jk+1
  1250. END DO
  1251. WHERE (risfdep(:,:) <= e3t_1d(1) .AND. risfdep(:,:) .GT. 0._wp)
  1252. risfdep(:,:) = 0. ; misfdep(:,:) = 1
  1253. END WHERE
  1254. ! basic check for the compatibility of bathy and risfdep. I think it should be offline because it is not perfect and cannot solved all the situation
  1255. icompt = 0
  1256. ! run the bathy check 10 times to be sure all the modif in the bathy or iceshelf draft are compatible together
  1257. DO jl = 1, 10
  1258. WHERE (bathy(:,:) .EQ. risfdep(:,:) )
  1259. misfdep(:,:) = 0 ; risfdep(:,:) = 0._wp
  1260. mbathy (:,:) = 0 ; bathy (:,:) = 0._wp
  1261. END WHERE
  1262. WHERE (mbathy(:,:) <= 0)
  1263. misfdep(:,:) = 0; risfdep(:,:) = 0._wp
  1264. mbathy (:,:) = 0; bathy (:,:) = 0._wp
  1265. ENDWHERE
  1266. IF( lk_mpp ) THEN
  1267. zbathy(:,:) = FLOAT( misfdep(:,:) )
  1268. CALL lbc_lnk( zbathy, 'T', 1. )
  1269. misfdep(:,:) = INT( zbathy(:,:) )
  1270. CALL lbc_lnk( risfdep, 'T', 1. )
  1271. CALL lbc_lnk( bathy, 'T', 1. )
  1272. zbathy(:,:) = FLOAT( mbathy(:,:) )
  1273. CALL lbc_lnk( zbathy, 'T', 1. )
  1274. mbathy(:,:) = INT( zbathy(:,:) )
  1275. ENDIF
  1276. IF( nperio == 1 .OR. nperio == 4 .OR. nperio == 6 ) THEN
  1277. misfdep( 1 ,:) = misfdep(jpim1,:) ! local domain is cyclic east-west
  1278. misfdep(jpi,:) = misfdep( 2 ,:)
  1279. ENDIF
  1280. IF( nperio == 1 .OR. nperio == 4 .OR. nperio == 6 ) THEN
  1281. mbathy( 1 ,:) = mbathy(jpim1,:) ! local domain is cyclic east-west
  1282. mbathy(jpi,:) = mbathy( 2 ,:)
  1283. ENDIF
  1284. ! split last cell if possible (only where water column is 2 cell or less)
  1285. DO jk = jpkm1, 1, -1
  1286. zmax = gdepw_1d(jk) + MIN( e3zps_min, e3t_1d(jk)*e3zps_rat )
  1287. WHERE( gdepw_1d(jk) < bathy(:,:) .AND. bathy(:,:) <= zmax .AND. misfdep + 1 >= mbathy)
  1288. mbathy(:,:) = jk
  1289. bathy(:,:) = zmax
  1290. END WHERE
  1291. END DO
  1292. ! split top cell if possible (only where water column is 2 cell or less)
  1293. DO jk = 2, jpkm1
  1294. zmax = gdepw_1d(jk+1) - MIN( e3zps_min, e3t_1d(jk)*e3zps_rat )
  1295. WHERE( gdepw_1d(jk+1) > risfdep(:,:) .AND. risfdep(:,:) >= zmax .AND. misfdep + 1 >= mbathy)
  1296. misfdep(:,:) = jk
  1297. risfdep(:,:) = zmax
  1298. END WHERE
  1299. END DO
  1300. ! Case where bathy and risfdep compatible but not the level variable mbathy/misfdep because of partial cell condition
  1301. DO jj = 1, jpj
  1302. DO ji = 1, jpi
  1303. ! find the minimum change option:
  1304. ! test bathy
  1305. IF (risfdep(ji,jj) .GT. 1) THEN
  1306. zbathydiff =ABS(bathy(ji,jj) - (gdepw_1d(mbathy (ji,jj)+1) &
  1307. & + MIN( e3zps_min, e3t_1d(mbathy (ji,jj)+1)*e3zps_rat )))
  1308. zrisfdepdiff=ABS(risfdep(ji,jj) - (gdepw_1d(misfdep(ji,jj) ) &
  1309. & - MIN( e3zps_min, e3t_1d(misfdep(ji,jj)-1)*e3zps_rat )))
  1310. IF (bathy(ji,jj) .GT. risfdep(ji,jj) .AND. mbathy(ji,jj) .LT. misfdep(ji,jj)) THEN
  1311. IF (zbathydiff .LE. zrisfdepdiff) THEN
  1312. bathy(ji,jj) = gdepw_1d(mbathy(ji,jj)) + MIN( e3zps_min, e3t_1d(mbathy(ji,jj)+1)*e3zps_rat )
  1313. mbathy(ji,jj)= mbathy(ji,jj) + 1
  1314. ELSE
  1315. risfdep(ji,jj) = gdepw_1d(misfdep(ji,jj)) - MIN( e3zps_min, e3t_1d(misfdep(ji,jj)-1)*e3zps_rat )
  1316. misfdep(ji,jj) = misfdep(ji,jj) - 1
  1317. END IF
  1318. END IF
  1319. END IF
  1320. END DO
  1321. END DO
  1322. ! At least 2 levels for water thickness at T, U, and V point.
  1323. DO jj = 1, jpj
  1324. DO ji = 1, jpi
  1325. ! find the minimum change option:
  1326. ! test bathy
  1327. IF( misfdep(ji,jj) == mbathy(ji,jj) .AND. mbathy(ji,jj) .GT. 1) THEN
  1328. zbathydiff =ABS(bathy(ji,jj) - (gdepw_1d(mbathy (ji,jj)+1)&
  1329. & + MIN( e3zps_min,e3t_1d(mbathy (ji,jj)+1)*e3zps_rat )))
  1330. zrisfdepdiff=ABS(risfdep(ji,jj) - (gdepw_1d(misfdep(ji,jj) ) &
  1331. & - MIN( e3zps_min,e3t_1d(misfdep(ji,jj)-1)*e3zps_rat )))
  1332. IF (zbathydiff .LE. zrisfdepdiff) THEN
  1333. mbathy(ji,jj) = mbathy(ji,jj) + 1
  1334. bathy(ji,jj) = gdepw_1d(mbathy (ji,jj)) + MIN( e3zps_min, e3t_1d(mbathy(ji,jj) +1)*e3zps_rat )
  1335. ELSE
  1336. misfdep(ji,jj)= misfdep(ji,jj) - 1
  1337. risfdep(ji,jj) = gdepw_1d(misfdep(ji,jj)+1) - MIN( e3zps_min, e3t_1d(misfdep(ji,jj))*e3zps_rat )
  1338. END IF
  1339. ENDIF
  1340. END DO
  1341. END DO
  1342. ! point V mbathy(ji,jj) EQ misfdep(ji,jj+1)
  1343. DO jj = 1, jpjm1
  1344. DO ji = 1, jpim1
  1345. IF( misfdep(ji,jj+1) == mbathy(ji,jj) .AND. mbathy(ji,jj) .GT. 1) THEN
  1346. zbathydiff =ABS(bathy(ji,jj ) - (gdepw_1d(mbathy (ji,jj)+1) &
  1347. & + MIN( e3zps_min, e3t_1d(mbathy (ji,jj )+1)*e3zps_rat )))
  1348. zrisfdepdiff=ABS(risfdep(ji,jj+1) - (gdepw_1d(misfdep(ji,jj+1)) &
  1349. & - MIN( e3zps_min, e3t_1d(misfdep(ji,jj+1)-1)*e3zps_rat )))
  1350. IF (zbathydiff .LE. zrisfdepdiff) THEN
  1351. mbathy(ji,jj) = mbathy(ji,jj) + 1
  1352. bathy(ji,jj) = gdepw_1d(mbathy (ji,jj )) &
  1353. & + MIN( e3zps_min, e3t_1d(mbathy(ji,jj )+1)*e3zps_rat )
  1354. ELSE
  1355. misfdep(ji,jj+1) = misfdep(ji,jj+1) - 1
  1356. risfdep (ji,jj+1) = gdepw_1d(misfdep(ji,jj+1)+1) &
  1357. & - MIN( e3zps_min, e3t_1d(misfdep(ji,jj+1))*e3zps_rat )
  1358. END IF
  1359. ENDIF
  1360. END DO
  1361. END DO
  1362. IF( lk_mpp ) THEN
  1363. zbathy(:,:) = FLOAT( misfdep(:,:) )
  1364. CALL lbc_lnk( zbathy, 'T', 1. )
  1365. misfdep(:,:) = INT( zbathy(:,:) )
  1366. CALL lbc_lnk( risfdep, 'T', 1. )
  1367. CALL lbc_lnk( bathy, 'T', 1. )
  1368. zbathy(:,:) = FLOAT( mbathy(:,:) )
  1369. CALL lbc_lnk( zbathy, 'T', 1. )
  1370. mbathy(:,:) = INT( zbathy(:,:) )
  1371. ENDIF
  1372. ! point V misdep(ji,jj) EQ mbathy(ji,jj+1)
  1373. DO jj = 1, jpjm1
  1374. DO ji = 1, jpim1
  1375. IF( misfdep(ji,jj) == mbathy(ji,jj+1) .AND. mbathy(ji,jj) .GT. 1) THEN
  1376. zbathydiff =ABS( bathy(ji,jj+1) - (gdepw_1d(mbathy (ji,jj+1)+1) &
  1377. & + MIN( e3zps_min, e3t_1d(mbathy (ji,jj+1)+1)*e3zps_rat )))
  1378. zrisfdepdiff=ABS(risfdep(ji,jj ) - (gdepw_1d(misfdep(ji,jj ) ) &
  1379. & - MIN( e3zps_min, e3t_1d(misfdep(ji,jj )-1)*e3zps_rat )))
  1380. IF (zbathydiff .LE. zrisfdepdiff) THEN
  1381. mbathy (ji,jj+1) = mbathy(ji,jj+1) + 1
  1382. bathy (ji,jj+1) = gdepw_1d(mbathy (ji,jj+1) ) + MIN( e3zps_min, e3t_1d(mbathy (ji,jj+1)+1)*e3zps_rat )
  1383. ELSE
  1384. misfdep(ji,jj) = misfdep(ji,jj) - 1
  1385. risfdep(ji,jj) = gdepw_1d(misfdep(ji,jj )+1) - MIN( e3zps_min, e3t_1d(misfdep(ji,jj ) )*e3zps_rat )
  1386. END IF
  1387. ENDIF
  1388. END DO
  1389. END DO
  1390. IF( lk_mpp ) THEN
  1391. zbathy(:,:) = FLOAT( misfdep(:,:) )
  1392. CALL lbc_lnk( zbathy, 'T', 1. )
  1393. misfdep(:,:) = INT( zbathy(:,:) )
  1394. CALL lbc_lnk( risfdep, 'T', 1. )
  1395. CALL lbc_lnk( bathy, 'T', 1. )
  1396. zbathy(:,:) = FLOAT( mbathy(:,:) )
  1397. CALL lbc_lnk( zbathy, 'T', 1. )
  1398. mbathy(:,:) = INT( zbathy(:,:) )
  1399. ENDIF
  1400. ! point U mbathy(ji,jj) EQ misfdep(ji,jj+1)
  1401. DO jj = 1, jpjm1
  1402. DO ji = 1, jpim1
  1403. IF( misfdep(ji+1,jj) == mbathy(ji,jj) .AND. mbathy(ji,jj) .GT. 1) THEN
  1404. zbathydiff =ABS( bathy(ji ,jj) - (gdepw_1d(mbathy (ji,jj)+1) &
  1405. & + MIN( e3zps_min, e3t_1d(mbathy (ji ,jj)+1)*e3zps_rat )))
  1406. zrisfdepdiff=ABS(risfdep(ji+1,jj) - (gdepw_1d(misfdep(ji+1,jj)) &
  1407. & - MIN( e3zps_min, e3t_1d(misfdep(ji+1,jj)-1)*e3zps_rat )))
  1408. IF (zbathydiff .LE. zrisfdepdiff) THEN
  1409. mbathy(ji,jj) = mbathy(ji,jj) + 1
  1410. bathy(ji,jj) = gdepw_1d(mbathy (ji,jj)) + MIN( e3zps_min, e3t_1d(mbathy(ji,jj) +1)*e3zps_rat )
  1411. ELSE
  1412. misfdep(ji+1,jj)= misfdep(ji+1,jj) - 1
  1413. risfdep(ji+1,jj) = gdepw_1d(misfdep(ji+1,jj)+1) - MIN( e3zps_min, e3t_1d(misfdep(ji+1,jj))*e3zps_rat )
  1414. END IF
  1415. ENDIF
  1416. ENDDO
  1417. ENDDO
  1418. IF( lk_mpp ) THEN
  1419. zbathy(:,:) = FLOAT( misfdep(:,:) )
  1420. CALL lbc_lnk( zbathy, 'T', 1. )
  1421. misfdep(:,:) = INT( zbathy(:,:) )
  1422. CALL lbc_lnk( risfdep, 'T', 1. )
  1423. CALL lbc_lnk( bathy, 'T', 1. )
  1424. zbathy(:,:) = FLOAT( mbathy(:,:) )
  1425. CALL lbc_lnk( zbathy, 'T', 1. )
  1426. mbathy(:,:) = INT( zbathy(:,:) )
  1427. ENDIF
  1428. ! point U misfdep(ji,jj) EQ bathy(ji,jj+1)
  1429. DO jj = 1, jpjm1
  1430. DO ji = 1, jpim1
  1431. IF( misfdep(ji,jj) == mbathy(ji+1,jj) .AND. mbathy(ji,jj) .GT. 1) THEN
  1432. zbathydiff =ABS( bathy(ji+1,jj) - (gdepw_1d(mbathy (ji+1,jj)+1) &
  1433. & + MIN( e3zps_min, e3t_1d(mbathy (ji+1,jj)+1)*e3zps_rat )))
  1434. zrisfdepdiff=ABS(risfdep(ji ,jj) - (gdepw_1d(misfdep(ji ,jj) ) &
  1435. & - MIN( e3zps_min, e3t_1d(misfdep(ji ,jj)-1)*e3zps_rat )))
  1436. IF (zbathydiff .LE. zrisfdepdiff) THEN
  1437. mbathy(ji+1,jj) = mbathy (ji+1,jj) + 1
  1438. bathy (ji+1,jj) = gdepw_1d(mbathy (ji+1,jj) ) &
  1439. & + MIN( e3zps_min, e3t_1d(mbathy (ji+1,jj) +1)*e3zps_rat )
  1440. ELSE
  1441. misfdep(ji,jj) = misfdep(ji ,jj) - 1
  1442. risfdep(ji,jj) = gdepw_1d(misfdep(ji ,jj)+1) &
  1443. & - MIN( e3zps_min, e3t_1d(misfdep(ji ,jj) )*e3zps_rat )
  1444. END IF
  1445. ENDIF
  1446. ENDDO
  1447. ENDDO
  1448. IF( lk_mpp ) THEN
  1449. zbathy(:,:) = FLOAT( misfdep(:,:) )
  1450. CALL lbc_lnk( zbathy, 'T', 1. )
  1451. misfdep(:,:) = INT( zbathy(:,:) )
  1452. CALL lbc_lnk( risfdep, 'T', 1. )
  1453. CALL lbc_lnk( bathy, 'T', 1. )
  1454. zbathy(:,:) = FLOAT( mbathy(:,:) )
  1455. CALL lbc_lnk( zbathy, 'T', 1. )
  1456. mbathy(:,:) = INT( zbathy(:,:) )
  1457. ENDIF
  1458. END DO
  1459. ! end dig bathy/ice shelf to be compatible
  1460. ! now fill single point in "coastline" of ice shelf, bathy, hole, and test again one cell tickness
  1461. DO jl = 1,20
  1462. ! remove single point "bay" on isf coast line in the ice shelf draft'
  1463. DO jk = 2, jpk
  1464. WHERE (misfdep==0) misfdep=jpk
  1465. zmask=0
  1466. WHERE (misfdep .LE. jk) zmask=1
  1467. DO jj = 2, jpjm1
  1468. DO ji = 2, jpim1
  1469. IF (misfdep(ji,jj) .EQ. jk) THEN
  1470. ibtest = zmask(ji-1,jj) + zmask(ji+1,jj) + zmask(ji,jj-1) + zmask(ji,jj+1)
  1471. IF (ibtest .LE. 1) THEN
  1472. risfdep(ji,jj)=gdepw_1d(jk+1) ; misfdep(ji,jj)=jk+1
  1473. IF (misfdep(ji,jj) .GT. mbathy(ji,jj)) misfdep(ji,jj) = jpk
  1474. END IF
  1475. END IF
  1476. END DO
  1477. END DO
  1478. END DO
  1479. WHERE (misfdep==jpk)
  1480. misfdep=0 ; risfdep=0. ; mbathy=0 ; bathy=0.
  1481. END WHERE
  1482. IF( lk_mpp ) THEN
  1483. zbathy(:,:) = FLOAT( misfdep(:,:) )
  1484. CALL lbc_lnk( zbathy, 'T', 1. )
  1485. misfdep(:,:) = INT( zbathy(:,:) )
  1486. CALL lbc_lnk( risfdep, 'T', 1. )
  1487. CALL lbc_lnk( bathy, 'T', 1. )
  1488. zbathy(:,:) = FLOAT( mbathy(:,:) )
  1489. CALL lbc_lnk( zbathy, 'T', 1. )
  1490. mbathy(:,:) = INT( zbathy(:,:) )
  1491. ENDIF
  1492. ! remove single point "bay" on bathy coast line beneath an ice shelf'
  1493. DO jk = jpk,1,-1
  1494. zmask=0
  1495. WHERE (mbathy .GE. jk ) zmask=1
  1496. DO jj = 2, jpjm1
  1497. DO ji = 2, jpim1
  1498. IF (mbathy(ji,jj) .EQ. jk .AND. misfdep(ji,jj) .GE. 2) THEN
  1499. ibtest = zmask(ji-1,jj) + zmask(ji+1,jj) + zmask(ji,jj-1) + zmask(ji,jj+1)
  1500. IF (ibtest .LE. 1) THEN
  1501. bathy(ji,jj)=gdepw_1d(jk) ; mbathy(ji,jj)=jk-1
  1502. IF (misfdep(ji,jj) .GT. mbathy(ji,jj)) mbathy(ji,jj) = 0
  1503. END IF
  1504. END IF
  1505. END DO
  1506. END DO
  1507. END DO
  1508. WHERE (mbathy==0)
  1509. misfdep=0 ; risfdep=0. ; mbathy=0 ; bathy=0.
  1510. END WHERE
  1511. IF( lk_mpp ) THEN
  1512. zbathy(:,:) = FLOAT( misfdep(:,:) )
  1513. CALL lbc_lnk( zbathy, 'T', 1. )
  1514. misfdep(:,:) = INT( zbathy(:,:) )
  1515. CALL lbc_lnk( risfdep, 'T', 1. )
  1516. CALL lbc_lnk( bathy, 'T', 1. )
  1517. zbathy(:,:) = FLOAT( mbathy(:,:) )
  1518. CALL lbc_lnk( zbathy, 'T', 1. )
  1519. mbathy(:,:) = INT( zbathy(:,:) )
  1520. ENDIF
  1521. ! fill hole in ice shelf
  1522. zmisfdep = misfdep
  1523. zrisfdep = risfdep
  1524. WHERE (zmisfdep .LE. 1) zmisfdep=jpk
  1525. DO jj = 2, jpjm1
  1526. DO ji = 2, jpim1
  1527. ibtestim1 = zmisfdep(ji-1,jj ) ; ibtestip1 = zmisfdep(ji+1,jj )
  1528. ibtestjm1 = zmisfdep(ji ,jj-1) ; ibtestjp1 = zmisfdep(ji ,jj+1)
  1529. IF( zmisfdep(ji,jj) .GE. mbathy(ji-1,jj ) ) ibtestim1 = jpk!MAX(0, mbathy(ji-1,jj ) - 1)
  1530. IF( zmisfdep(ji,jj) .GE. mbathy(ji+1,jj ) ) ibtestip1 = jpk!MAX(0, mbathy(ji+1,jj ) - 1)
  1531. IF( zmisfdep(ji,jj) .GE. mbathy(ji ,jj-1) ) ibtestjm1 = jpk!MAX(0, mbathy(ji ,jj-1) - 1)
  1532. IF( zmisfdep(ji,jj) .GE. mbathy(ji ,jj+1) ) ibtestjp1 = jpk!MAX(0, mbathy(ji ,jj+1) - 1)
  1533. ibtest=MIN(ibtestim1, ibtestip1, ibtestjm1, ibtestjp1)
  1534. IF( ibtest == jpk .AND. misfdep(ji,jj) .GE. 2) THEN
  1535. mbathy(ji,jj) = 0 ; bathy(ji,jj) = 0.0_wp ; misfdep(ji,jj) = 0 ; risfdep(ji,jj) = 0.0_wp
  1536. END IF
  1537. IF( zmisfdep(ji,jj) < ibtest .AND. misfdep(ji,jj) .GE. 2) THEN
  1538. misfdep(ji,jj) = ibtest
  1539. risfdep(ji,jj) = gdepw_1d(ibtest)
  1540. ENDIF
  1541. ENDDO
  1542. ENDDO
  1543. IF( lk_mpp ) THEN
  1544. zbathy(:,:) = FLOAT( misfdep(:,:) )
  1545. CALL lbc_lnk( zbathy, 'T', 1. )
  1546. misfdep(:,:) = INT( zbathy(:,:) )
  1547. CALL lbc_lnk( risfdep, 'T', 1. )
  1548. CALL lbc_lnk( bathy, 'T', 1. )
  1549. zbathy(:,:) = FLOAT( mbathy(:,:) )
  1550. CALL lbc_lnk( zbathy, 'T', 1. )
  1551. mbathy(:,:) = INT( zbathy(:,:) )
  1552. ENDIF
  1553. !
  1554. !! fill hole in bathymetry
  1555. zmbathy (:,:)=mbathy (:,:)
  1556. DO jj = 2, jpjm1
  1557. DO ji = 2, jpim1
  1558. ibtestim1 = zmbathy(ji-1,jj ) ; ibtestip1 = zmbathy(ji+1,jj )
  1559. ibtestjm1 = zmbathy(ji ,jj-1) ; ibtestjp1 = zmbathy(ji ,jj+1)
  1560. IF( zmbathy(ji,jj) .LT. misfdep(ji-1,jj ) ) ibtestim1 = 0!MIN(jpk-1, misfdep(ji-1,jj ) + 1)
  1561. IF( zmbathy(ji,jj) .LT. misfdep(ji+1,jj ) ) ibtestip1 = 0
  1562. IF( zmbathy(ji,jj) .LT. misfdep(ji ,jj-1) ) ibtestjm1 = 0
  1563. IF( zmbathy(ji,jj) .LT. misfdep(ji ,jj+1) ) ibtestjp1 = 0
  1564. ibtest=MAX(ibtestim1, ibtestip1, ibtestjm1, ibtestjp1)
  1565. IF( ibtest == 0 .AND. misfdep(ji,jj) .GE. 2) THEN
  1566. mbathy(ji,jj) = 0 ; bathy(ji,jj) = 0.0_wp ; misfdep(ji,jj) = 0 ; risfdep(ji,jj) = 0.0_wp ;
  1567. END IF
  1568. IF( ibtest < zmbathy(ji,jj) .AND. misfdep(ji,jj) .GE. 2) THEN
  1569. mbathy(ji,jj) = ibtest
  1570. bathy(ji,jj) = gdepw_1d(ibtest+1)
  1571. ENDIF
  1572. END DO
  1573. END DO
  1574. IF( lk_mpp ) THEN
  1575. zbathy(:,:) = FLOAT( misfdep(:,:) )
  1576. CALL lbc_lnk( zbathy, 'T', 1. )
  1577. misfdep(:,:) = INT( zbathy(:,:) )
  1578. CALL lbc_lnk( risfdep, 'T', 1. )
  1579. CALL lbc_lnk( bathy, 'T', 1. )
  1580. zbathy(:,:) = FLOAT( mbathy(:,:) )
  1581. CALL lbc_lnk( zbathy, 'T', 1. )
  1582. mbathy(:,:) = INT( zbathy(:,:) )
  1583. ENDIF
  1584. ! if not compatible after all check (ie U point water column less than 2 cells), mask U
  1585. DO jj = 1, jpjm1
  1586. DO ji = 1, jpim1
  1587. IF (mbathy(ji,jj) == misfdep(ji+1,jj) .AND. mbathy(ji,jj) .GE. 1 .AND. mbathy(ji+1,jj) .GE. 1) THEN
  1588. mbathy(ji,jj) = mbathy(ji,jj) - 1 ; bathy(ji,jj) = gdepw_1d(mbathy(ji,jj)+1) ;
  1589. END IF
  1590. END DO
  1591. END DO
  1592. IF( lk_mpp ) THEN
  1593. zbathy(:,:) = FLOAT( misfdep(:,:) )
  1594. CALL lbc_lnk( zbathy, 'T', 1. )
  1595. misfdep(:,:) = INT( zbathy(:,:) )
  1596. CALL lbc_lnk( risfdep, 'T', 1. )
  1597. CALL lbc_lnk( bathy, 'T', 1. )
  1598. zbathy(:,:) = FLOAT( mbathy(:,:) )
  1599. CALL lbc_lnk( zbathy, 'T', 1. )
  1600. mbathy(:,:) = INT( zbathy(:,:) )
  1601. ENDIF
  1602. ! if not compatible after all check (ie U point water column less than 2 cells), mask U
  1603. DO jj = 1, jpjm1
  1604. DO ji = 1, jpim1
  1605. IF (misfdep(ji,jj) == mbathy(ji+1,jj) .AND. mbathy(ji,jj) .GE. 1 .AND. mbathy(ji+1,jj) .GE. 1) THEN
  1606. mbathy(ji+1,jj) = mbathy(ji+1,jj) - 1; bathy(ji+1,jj) = gdepw_1d(mbathy(ji+1,jj)+1) ;
  1607. END IF
  1608. END DO
  1609. END DO
  1610. IF( lk_mpp ) THEN
  1611. zbathy(:,:) = FLOAT( misfdep(:,:) )
  1612. CALL lbc_lnk( zbathy, 'T', 1. )
  1613. misfdep(:,:) = INT( zbathy(:,:) )
  1614. CALL lbc_lnk( risfdep, 'T', 1. )
  1615. CALL lbc_lnk( bathy, 'T', 1. )
  1616. zbathy(:,:) = FLOAT( mbathy(:,:) )
  1617. CALL lbc_lnk( zbathy, 'T', 1. )
  1618. mbathy(:,:) = INT( zbathy(:,:) )
  1619. ENDIF
  1620. ! if not compatible after all check (ie V point water column less than 2 cells), mask V
  1621. DO jj = 1, jpjm1
  1622. DO ji = 1, jpi
  1623. IF (mbathy(ji,jj) == misfdep(ji,jj+1) .AND. mbathy(ji,jj) .GE. 1 .AND. mbathy(ji,jj+1) .GE. 1) THEN
  1624. mbathy(ji,jj) = mbathy(ji,jj) - 1 ; bathy(ji,jj) = gdepw_1d(mbathy(ji,jj)+1) ;
  1625. END IF
  1626. END DO
  1627. END DO
  1628. IF( lk_mpp ) THEN
  1629. zbathy(:,:) = FLOAT( misfdep(:,:) )
  1630. CALL lbc_lnk( zbathy, 'T', 1. )
  1631. misfdep(:,:) = INT( zbathy(:,:) )
  1632. CALL lbc_lnk( risfdep, 'T', 1. )
  1633. CALL lbc_lnk( bathy, 'T', 1. )
  1634. zbathy(:,:) = FLOAT( mbathy(:,:) )
  1635. CALL lbc_lnk( zbathy, 'T', 1. )
  1636. mbathy(:,:) = INT( zbathy(:,:) )
  1637. ENDIF
  1638. ! if not compatible after all check (ie V point water column less than 2 cells), mask V
  1639. DO jj = 1, jpjm1
  1640. DO ji = 1, jpi
  1641. IF (misfdep(ji,jj) == mbathy(ji,jj+1) .AND. mbathy(ji,jj) .GE. 1 .AND. mbathy(ji,jj+1) .GE. 1) THEN
  1642. mbathy(ji,jj+1) = mbathy(ji,jj+1) - 1 ; bathy(ji,jj+1) = gdepw_1d(mbathy(ji,jj+1)+1) ;
  1643. END IF
  1644. END DO
  1645. END DO
  1646. IF( lk_mpp ) THEN
  1647. zbathy(:,:) = FLOAT( misfdep(:,:) )
  1648. CALL lbc_lnk( zbathy, 'T', 1. )
  1649. misfdep(:,:) = INT( zbathy(:,:) )
  1650. CALL lbc_lnk( risfdep, 'T', 1. )
  1651. CALL lbc_lnk( bathy, 'T', 1. )
  1652. zbathy(:,:) = FLOAT( mbathy(:,:) )
  1653. CALL lbc_lnk( zbathy, 'T', 1. )
  1654. mbathy(:,:) = INT( zbathy(:,:) )
  1655. ENDIF
  1656. ! if not compatible after all check, mask T
  1657. DO jj = 1, jpj
  1658. DO ji = 1, jpi
  1659. IF (mbathy(ji,jj) <= misfdep(ji,jj)) THEN
  1660. misfdep(ji,jj) = 0 ; risfdep(ji,jj) = 0._wp ; mbathy(ji,jj) = 0 ; bathy(ji,jj) = 0._wp ;
  1661. END IF
  1662. END DO
  1663. END DO
  1664. WHERE (mbathy(:,:) == 1)
  1665. mbathy = 0; bathy = 0.0_wp ; misfdep = 0 ; risfdep = 0.0_wp
  1666. END WHERE
  1667. END DO
  1668. ! end check compatibility ice shelf/bathy
  1669. ! remove very shallow ice shelf (less than ~ 10m if 75L)
  1670. WHERE (misfdep(:,:) <= 5)
  1671. misfdep = 1; risfdep = 0.0_wp;
  1672. END WHERE
  1673. IF( icompt == 0 ) THEN
  1674. IF(lwp) WRITE(numout,*)' no points with ice shelf too close to bathymetry'
  1675. ELSE
  1676. IF(lwp) WRITE(numout,*)' ',icompt,' ocean grid points with ice shelf thickness reduced to avoid bathymetry'
  1677. ENDIF
  1678. CALL wrk_dealloc( jpi, jpj, zmask, zbathy, zrisfdep )
  1679. CALL wrk_dealloc( jpi, jpj, zmisfdep, zmbathy )
  1680. IF( nn_timing == 1 ) CALL timing_stop('zgr_isf')
  1681. END SUBROUTINE
  1682. SUBROUTINE zgr_sco
  1683. !!----------------------------------------------------------------------
  1684. !! *** ROUTINE zgr_sco ***
  1685. !!
  1686. !! ** Purpose : define the s-coordinate system
  1687. !!
  1688. !! ** Method : s-coordinate
  1689. !! The depth of model levels is defined as the product of an
  1690. !! analytical function by the local bathymetry, while the vertical
  1691. !! scale factors are defined as the product of the first derivative
  1692. !! of the analytical function by the bathymetry.
  1693. !! (this solution save memory as depth and scale factors are not
  1694. !! 3d fields)
  1695. !! - Read bathymetry (in meters) at t-point and compute the
  1696. !! bathymetry at u-, v-, and f-points.
  1697. !! hbatu = mi( hbatt )
  1698. !! hbatv = mj( hbatt )
  1699. !! hbatf = mi( mj( hbatt ) )
  1700. !! - Compute z_gsigt, z_gsigw, z_esigt, z_esigw from an analytical
  1701. !! function and its derivative given as function.
  1702. !! z_gsigt(k) = fssig (k )
  1703. !! z_gsigw(k) = fssig (k-0.5)
  1704. !! z_esigt(k) = fsdsig(k )
  1705. !! z_esigw(k) = fsdsig(k-0.5)
  1706. !! Three options for stretching are give, and they can be modified
  1707. !! following the users requirements. Nevertheless, the output as
  1708. !! well as the way to compute the model levels and scale factors
  1709. !! must be respected in order to insure second order accuracy
  1710. !! schemes.
  1711. !!
  1712. !! The three methods for stretching available are:
  1713. !!
  1714. !! s_sh94 (Song and Haidvogel 1994)
  1715. !! a sinh/tanh function that allows sigma and stretched sigma
  1716. !!
  1717. !! s_sf12 (Siddorn and Furner 2012?)
  1718. !! allows the maintenance of fixed surface and or
  1719. !! bottom cell resolutions (cf. geopotential coordinates)
  1720. !! within an analytically derived stretched S-coordinate framework.
  1721. !!
  1722. !! s_tanh (Madec et al 1996)
  1723. !! a cosh/tanh function that gives stretched coordinates
  1724. !!
  1725. !!----------------------------------------------------------------------
  1726. !
  1727. INTEGER :: ji, jj, jk, jl ! dummy loop argument
  1728. INTEGER :: iip1, ijp1, iim1, ijm1 ! temporary integers
  1729. INTEGER :: ios ! Local integer output status for namelist read
  1730. REAL(wp) :: zrmax, ztaper ! temporary scalars
  1731. REAL(wp) :: zrfact
  1732. !
  1733. REAL(wp), POINTER, DIMENSION(:,: ) :: ztmpi1, ztmpi2, ztmpj1, ztmpj2
  1734. REAL(wp), POINTER, DIMENSION(:,: ) :: zenv, ztmp, zmsk, zri, zrj, zhbat
  1735. NAMELIST/namzgr_sco/ln_s_sh94, ln_s_sf12, ln_sigcrit, rn_sbot_min, rn_sbot_max, rn_hc, rn_rmax,rn_theta, &
  1736. rn_thetb, rn_bb, rn_alpha, rn_efold, rn_zs, rn_zb_a, rn_zb_b
  1737. !!----------------------------------------------------------------------
  1738. !
  1739. IF( nn_timing == 1 ) CALL timing_start('zgr_sco')
  1740. !
  1741. CALL wrk_alloc( jpi, jpj, zenv, ztmp, zmsk, zri, zrj, zhbat , ztmpi1, ztmpi2, ztmpj1, ztmpj2 )
  1742. !
  1743. REWIND( numnam_ref ) ! Namelist namzgr_sco in reference namelist : Sigma-stretching parameters
  1744. READ ( numnam_ref, namzgr_sco, IOSTAT = ios, ERR = 901)
  1745. 901 IF( ios /= 0 ) CALL ctl_nam ( ios , 'namzgr_sco in reference namelist', lwp )
  1746. REWIND( numnam_cfg ) ! Namelist namzgr_sco in configuration namelist : Sigma-stretching parameters
  1747. READ ( numnam_cfg, namzgr_sco, IOSTAT = ios, ERR = 902 )
  1748. 902 IF( ios /= 0 ) CALL ctl_nam ( ios , 'namzgr_sco in configuration namelist', lwp )
  1749. IF(lwm) WRITE ( numond, namzgr_sco )
  1750. IF(lwp) THEN ! control print
  1751. WRITE(numout,*)
  1752. WRITE(numout,*) 'domzgr_sco : s-coordinate or hybrid z-s-coordinate'
  1753. WRITE(numout,*) '~~~~~~~~~~~'
  1754. WRITE(numout,*) ' Namelist namzgr_sco'
  1755. WRITE(numout,*) ' stretching coeffs '
  1756. WRITE(numout,*) ' maximum depth of s-bottom surface (>0) rn_sbot_max = ',rn_sbot_max
  1757. WRITE(numout,*) ' minimum depth of s-bottom surface (>0) rn_sbot_min = ',rn_sbot_min
  1758. WRITE(numout,*) ' Critical depth rn_hc = ',rn_hc
  1759. WRITE(numout,*) ' maximum cut-off r-value allowed rn_rmax = ',rn_rmax
  1760. WRITE(numout,*) ' Song and Haidvogel 1994 stretching ln_s_sh94 = ',ln_s_sh94
  1761. WRITE(numout,*) ' Song and Haidvogel 1994 stretching coefficients'
  1762. WRITE(numout,*) ' surface control parameter (0<=rn_theta<=20) rn_theta = ',rn_theta
  1763. WRITE(numout,*) ' bottom control parameter (0<=rn_thetb<= 1) rn_thetb = ',rn_thetb
  1764. WRITE(numout,*) ' stretching parameter (song and haidvogel) rn_bb = ',rn_bb
  1765. WRITE(numout,*) ' Siddorn and Furner 2012 stretching ln_s_sf12 = ',ln_s_sf12
  1766. WRITE(numout,*) ' switching to sigma (T) or Z (F) at H<Hc ln_sigcrit = ',ln_sigcrit
  1767. WRITE(numout,*) ' Siddorn and Furner 2012 stretching coefficients'
  1768. WRITE(numout,*) ' stretchin parameter ( >1 surface; <1 bottom) rn_alpha = ',rn_alpha
  1769. WRITE(numout,*) ' e-fold length scale for transition region rn_efold = ',rn_efold
  1770. WRITE(numout,*) ' Surface cell depth (Zs) (m) rn_zs = ',rn_zs
  1771. WRITE(numout,*) ' Bathymetry multiplier for Zb rn_zb_a = ',rn_zb_a
  1772. WRITE(numout,*) ' Offset for Zb rn_zb_b = ',rn_zb_b
  1773. WRITE(numout,*) ' Bottom cell (Zb) (m) = H*rn_zb_a + rn_zb_b'
  1774. ENDIF
  1775. hift(:,:) = rn_sbot_min ! set the minimum depth for the s-coordinate
  1776. hifu(:,:) = rn_sbot_min
  1777. hifv(:,:) = rn_sbot_min
  1778. hiff(:,:) = rn_sbot_min
  1779. ! ! set maximum ocean depth
  1780. bathy(:,:) = MIN( rn_sbot_max, bathy(:,:) )
  1781. DO jj = 1, jpj
  1782. DO ji = 1, jpi
  1783. IF( bathy(ji,jj) > 0._wp ) bathy(ji,jj) = MAX( rn_sbot_min, bathy(ji,jj) )
  1784. END DO
  1785. END DO
  1786. ! ! =============================
  1787. ! ! Define the envelop bathymetry (hbatt)
  1788. ! ! =============================
  1789. ! use r-value to create hybrid coordinates
  1790. zenv(:,:) = bathy(:,:)
  1791. !
  1792. ! set first land point adjacent to a wet cell to sbot_min as this needs to be included in smoothing
  1793. DO jj = 1, jpj
  1794. DO ji = 1, jpi
  1795. IF( bathy(ji,jj) == 0._wp ) THEN
  1796. iip1 = MIN( ji+1, jpi )
  1797. ijp1 = MIN( jj+1, jpj )
  1798. iim1 = MAX( ji-1, 1 )
  1799. ijm1 = MAX( jj-1, 1 )
  1800. IF( ( + bathy(iim1,ijp1) + bathy(ji,ijp1) + bathy(iip1,ijp1) &
  1801. & + bathy(iim1,jj ) + bathy(iip1,jj ) &
  1802. & + bathy(iim1,ijm1) + bathy(ji,ijm1) + bathy(iip1,ijp1) ) > 0._wp ) THEN
  1803. zenv(ji,jj) = rn_sbot_min
  1804. ENDIF
  1805. ENDIF
  1806. END DO
  1807. END DO
  1808. ! apply lateral boundary condition CAUTION: keep the value when the lbc field is zero
  1809. CALL lbc_lnk( zenv, 'T', 1._wp, 'no0' )
  1810. !
  1811. ! smooth the bathymetry (if required)
  1812. scosrf(:,:) = 0._wp ! ocean surface depth (here zero: no under ice-shelf sea)
  1813. scobot(:,:) = bathy(:,:) ! ocean bottom depth
  1814. !
  1815. jl = 0
  1816. zrmax = 1._wp
  1817. !
  1818. !
  1819. ! set scaling factor used in reducing vertical gradients
  1820. zrfact = ( 1._wp - rn_rmax ) / ( 1._wp + rn_rmax )
  1821. !
  1822. ! initialise temporary evelope depth arrays
  1823. ztmpi1(:,:) = zenv(:,:)
  1824. ztmpi2(:,:) = zenv(:,:)
  1825. ztmpj1(:,:) = zenv(:,:)
  1826. ztmpj2(:,:) = zenv(:,:)
  1827. !
  1828. ! initialise temporary r-value arrays
  1829. zri(:,:) = 1._wp
  1830. zrj(:,:) = 1._wp
  1831. ! ! ================ !
  1832. DO WHILE( jl <= 10000 .AND. ( zrmax - rn_rmax ) > 1.e-8_wp ) ! Iterative loop !
  1833. ! ! ================ !
  1834. jl = jl + 1
  1835. zrmax = 0._wp
  1836. ! we set zrmax from previous r-values (zri and zrj) first
  1837. ! if set after current r-value calculation (as previously)
  1838. ! we could exit DO WHILE prematurely before checking r-value
  1839. ! of current zenv
  1840. DO jj = 1, nlcj
  1841. DO ji = 1, nlci
  1842. zrmax = MAX( zrmax, ABS(zri(ji,jj)), ABS(zrj(ji,jj)) )
  1843. END DO
  1844. END DO
  1845. zri(:,:) = 0._wp
  1846. zrj(:,:) = 0._wp
  1847. DO jj = 1, nlcj
  1848. DO ji = 1, nlci
  1849. iip1 = MIN( ji+1, nlci ) ! force zri = 0 on last line (ji=ncli+1 to jpi)
  1850. ijp1 = MIN( jj+1, nlcj ) ! force zrj = 0 on last raw (jj=nclj+1 to jpj)
  1851. IF( (zenv(ji,jj) > 0._wp) .AND. (zenv(iip1,jj) > 0._wp)) THEN
  1852. zri(ji,jj) = ( zenv(iip1,jj ) - zenv(ji,jj) ) / ( zenv(iip1,jj ) + zenv(ji,jj) )
  1853. END IF
  1854. IF( (zenv(ji,jj) > 0._wp) .AND. (zenv(ji,ijp1) > 0._wp)) THEN
  1855. zrj(ji,jj) = ( zenv(ji ,ijp1) - zenv(ji,jj) ) / ( zenv(ji ,ijp1) + zenv(ji,jj) )
  1856. END IF
  1857. IF( zri(ji,jj) > rn_rmax ) ztmpi1(ji ,jj ) = zenv(iip1,jj ) * zrfact
  1858. IF( zri(ji,jj) < -rn_rmax ) ztmpi2(iip1,jj ) = zenv(ji ,jj ) * zrfact
  1859. IF( zrj(ji,jj) > rn_rmax ) ztmpj1(ji ,jj ) = zenv(ji ,ijp1) * zrfact
  1860. IF( zrj(ji,jj) < -rn_rmax ) ztmpj2(ji ,ijp1) = zenv(ji ,jj ) * zrfact
  1861. END DO
  1862. END DO
  1863. IF( lk_mpp ) CALL mpp_max( zrmax ) ! max over the global domain
  1864. !
  1865. IF(lwp)WRITE(numout,*) 'zgr_sco : iter= ',jl, ' rmax= ', zrmax
  1866. !
  1867. DO jj = 1, nlcj
  1868. DO ji = 1, nlci
  1869. zenv(ji,jj) = MAX(zenv(ji,jj), ztmpi1(ji,jj), ztmpi2(ji,jj), ztmpj1(ji,jj), ztmpj2(ji,jj) )
  1870. END DO
  1871. END DO
  1872. ! apply lateral boundary condition CAUTION: keep the value when the lbc field is zero
  1873. CALL lbc_lnk( zenv, 'T', 1._wp, 'no0' )
  1874. ! ! ================ !
  1875. END DO ! End loop !
  1876. ! ! ================ !
  1877. DO jj = 1, jpj
  1878. DO ji = 1, jpi
  1879. zenv(ji,jj) = MAX( zenv(ji,jj), rn_sbot_min ) ! set all points to avoid undefined scale value warnings
  1880. END DO
  1881. END DO
  1882. !
  1883. ! Envelope bathymetry saved in hbatt
  1884. hbatt(:,:) = zenv(:,:)
  1885. IF( MINVAL( gphit(:,:) ) * MAXVAL( gphit(:,:) ) <= 0._wp ) THEN
  1886. IF ( jphgr_msh == 2 .OR. jphgr_msh == 3) CALL ctl_stop( 'dom:zgr_sco: if jphgr_msh = 2 or 3 and &
  1887. & s-coordinates stop, if not correction at Equator is applied, but it is wrong')
  1888. CALL ctl_warn( ' s-coordinates are tapered in vicinity of the Equator' )
  1889. DO jj = 1, jpj
  1890. DO ji = 1, jpi
  1891. ztaper = EXP( -(gphit(ji,jj)/8._wp)**2._wp )
  1892. hbatt(ji,jj) = rn_sbot_max * ztaper + hbatt(ji,jj) * ( 1._wp - ztaper )
  1893. END DO
  1894. END DO
  1895. ENDIF
  1896. !
  1897. IF(lwp) THEN ! Control print
  1898. WRITE(numout,*)
  1899. WRITE(numout,*) ' domzgr: hbatt field; ocean depth in meters'
  1900. WRITE(numout,*)
  1901. CALL prihre( hbatt(1,1), jpi, jpj, 1, jpi, 1, 1, jpj, 1, 0._wp, numout )
  1902. IF( nprint == 1 ) THEN
  1903. WRITE(numout,*) ' bathy MAX ', MAXVAL( bathy(:,:) ), ' MIN ', MINVAL( bathy(:,:) )
  1904. WRITE(numout,*) ' hbatt MAX ', MAXVAL( hbatt(:,:) ), ' MIN ', MINVAL( hbatt(:,:) )
  1905. ENDIF
  1906. ENDIF
  1907. ! ! ==============================
  1908. ! ! hbatu, hbatv, hbatf fields
  1909. ! ! ==============================
  1910. IF(lwp) THEN
  1911. WRITE(numout,*)
  1912. WRITE(numout,*) ' zgr_sco: minimum depth of the envelop topography set to : ', rn_sbot_min
  1913. ENDIF
  1914. hbatu(:,:) = rn_sbot_min
  1915. hbatv(:,:) = rn_sbot_min
  1916. hbatf(:,:) = rn_sbot_min
  1917. DO jj = 1, jpjm1
  1918. DO ji = 1, jpim1 ! NO vector opt.
  1919. hbatu(ji,jj) = 0.50_wp * ( hbatt(ji ,jj) + hbatt(ji+1,jj ) )
  1920. hbatv(ji,jj) = 0.50_wp * ( hbatt(ji ,jj) + hbatt(ji ,jj+1) )
  1921. hbatf(ji,jj) = 0.25_wp * ( hbatt(ji ,jj) + hbatt(ji ,jj+1) &
  1922. & + hbatt(ji+1,jj) + hbatt(ji+1,jj+1) )
  1923. END DO
  1924. END DO
  1925. !
  1926. ! Apply lateral boundary condition
  1927. !!gm ! CAUTION: retain non zero value in the initial file this should be OK for orca cfg, not for EEL
  1928. zhbat(:,:) = hbatu(:,:) ; CALL lbc_lnk( hbatu, 'U', 1._wp )
  1929. DO jj = 1, jpj
  1930. DO ji = 1, jpi
  1931. IF( hbatu(ji,jj) == 0._wp ) THEN
  1932. IF( zhbat(ji,jj) == 0._wp ) hbatu(ji,jj) = rn_sbot_min
  1933. IF( zhbat(ji,jj) /= 0._wp ) hbatu(ji,jj) = zhbat(ji,jj)
  1934. ENDIF
  1935. END DO
  1936. END DO
  1937. zhbat(:,:) = hbatv(:,:) ; CALL lbc_lnk( hbatv, 'V', 1._wp )
  1938. DO jj = 1, jpj
  1939. DO ji = 1, jpi
  1940. IF( hbatv(ji,jj) == 0._wp ) THEN
  1941. IF( zhbat(ji,jj) == 0._wp ) hbatv(ji,jj) = rn_sbot_min
  1942. IF( zhbat(ji,jj) /= 0._wp ) hbatv(ji,jj) = zhbat(ji,jj)
  1943. ENDIF
  1944. END DO
  1945. END DO
  1946. zhbat(:,:) = hbatf(:,:) ; CALL lbc_lnk( hbatf, 'F', 1._wp )
  1947. DO jj = 1, jpj
  1948. DO ji = 1, jpi
  1949. IF( hbatf(ji,jj) == 0._wp ) THEN
  1950. IF( zhbat(ji,jj) == 0._wp ) hbatf(ji,jj) = rn_sbot_min
  1951. IF( zhbat(ji,jj) /= 0._wp ) hbatf(ji,jj) = zhbat(ji,jj)
  1952. ENDIF
  1953. END DO
  1954. END DO
  1955. !!bug: key_helsinki a verifer
  1956. hift(:,:) = MIN( hift(:,:), hbatt(:,:) )
  1957. hifu(:,:) = MIN( hifu(:,:), hbatu(:,:) )
  1958. hifv(:,:) = MIN( hifv(:,:), hbatv(:,:) )
  1959. hiff(:,:) = MIN( hiff(:,:), hbatf(:,:) )
  1960. IF( nprint == 1 .AND. lwp ) THEN
  1961. WRITE(numout,*) ' MAX val hif t ', MAXVAL( hift (:,:) ), ' f ', MAXVAL( hiff (:,:) ), &
  1962. & ' u ', MAXVAL( hifu (:,:) ), ' v ', MAXVAL( hifv (:,:) )
  1963. WRITE(numout,*) ' MIN val hif t ', MINVAL( hift (:,:) ), ' f ', MINVAL( hiff (:,:) ), &
  1964. & ' u ', MINVAL( hifu (:,:) ), ' v ', MINVAL( hifv (:,:) )
  1965. WRITE(numout,*) ' MAX val hbat t ', MAXVAL( hbatt(:,:) ), ' f ', MAXVAL( hbatf(:,:) ), &
  1966. & ' u ', MAXVAL( hbatu(:,:) ), ' v ', MAXVAL( hbatv(:,:) )
  1967. WRITE(numout,*) ' MIN val hbat t ', MINVAL( hbatt(:,:) ), ' f ', MINVAL( hbatf(:,:) ), &
  1968. & ' u ', MINVAL( hbatu(:,:) ), ' v ', MINVAL( hbatv(:,:) )
  1969. ENDIF
  1970. !! helsinki
  1971. ! ! =======================
  1972. ! ! s-ccordinate fields (gdep., e3.)
  1973. ! ! =======================
  1974. !
  1975. ! non-dimensional "sigma" for model level depth at w- and t-levels
  1976. !========================================================================
  1977. ! Song and Haidvogel 1994 (ln_s_sh94=T)
  1978. ! Siddorn and Furner 2012 (ln_sf12=T)
  1979. ! or tanh function (both false)
  1980. !========================================================================
  1981. IF ( ln_s_sh94 ) THEN
  1982. CALL s_sh94()
  1983. ELSE IF ( ln_s_sf12 ) THEN
  1984. CALL s_sf12()
  1985. ELSE
  1986. CALL s_tanh()
  1987. ENDIF
  1988. CALL lbc_lnk( e3t_0 , 'T', 1._wp )
  1989. CALL lbc_lnk( e3u_0 , 'U', 1._wp )
  1990. CALL lbc_lnk( e3v_0 , 'V', 1._wp )
  1991. CALL lbc_lnk( e3f_0 , 'F', 1._wp )
  1992. CALL lbc_lnk( e3w_0 , 'W', 1._wp )
  1993. CALL lbc_lnk( e3uw_0, 'U', 1._wp )
  1994. CALL lbc_lnk( e3vw_0, 'V', 1._wp )
  1995. fsdepw(:,:,:) = gdepw_0 (:,:,:)
  1996. fsde3w(:,:,:) = gdep3w_0(:,:,:)
  1997. !
  1998. where (e3t_0 (:,:,:).eq.0.0) e3t_0(:,:,:) = 1.0
  1999. where (e3u_0 (:,:,:).eq.0.0) e3u_0(:,:,:) = 1.0
  2000. where (e3v_0 (:,:,:).eq.0.0) e3v_0(:,:,:) = 1.0
  2001. where (e3f_0 (:,:,:).eq.0.0) e3f_0(:,:,:) = 1.0
  2002. where (e3w_0 (:,:,:).eq.0.0) e3w_0(:,:,:) = 1.0
  2003. where (e3uw_0 (:,:,:).eq.0.0) e3uw_0(:,:,:) = 1.0
  2004. where (e3vw_0 (:,:,:).eq.0.0) e3vw_0(:,:,:) = 1.0
  2005. #if defined key_agrif
  2006. ! Ensure meaningful vertical scale factors in ghost lines/columns
  2007. IF( .NOT. Agrif_Root() ) THEN
  2008. !
  2009. IF((nbondi == -1).OR.(nbondi == 2)) THEN
  2010. e3u_0(1,:,:) = e3u_0(2,:,:)
  2011. ENDIF
  2012. !
  2013. IF((nbondi == 1).OR.(nbondi == 2)) THEN
  2014. e3u_0(nlci-1,:,:) = e3u_0(nlci-2,:,:)
  2015. ENDIF
  2016. !
  2017. IF((nbondj == -1).OR.(nbondj == 2)) THEN
  2018. e3v_0(:,1,:) = e3v_0(:,2,:)
  2019. ENDIF
  2020. !
  2021. IF((nbondj == 1).OR.(nbondj == 2)) THEN
  2022. e3v_0(:,nlcj-1,:) = e3v_0(:,nlcj-2,:)
  2023. ENDIF
  2024. !
  2025. ENDIF
  2026. #endif
  2027. fsdept(:,:,:) = gdept_0 (:,:,:)
  2028. fsdepw(:,:,:) = gdepw_0 (:,:,:)
  2029. fsde3w(:,:,:) = gdep3w_0(:,:,:)
  2030. fse3t (:,:,:) = e3t_0 (:,:,:)
  2031. fse3u (:,:,:) = e3u_0 (:,:,:)
  2032. fse3v (:,:,:) = e3v_0 (:,:,:)
  2033. fse3f (:,:,:) = e3f_0 (:,:,:)
  2034. fse3w (:,:,:) = e3w_0 (:,:,:)
  2035. fse3uw(:,:,:) = e3uw_0 (:,:,:)
  2036. fse3vw(:,:,:) = e3vw_0 (:,:,:)
  2037. !!
  2038. ! HYBRID :
  2039. DO jj = 1, jpj
  2040. DO ji = 1, jpi
  2041. DO jk = 1, jpkm1
  2042. IF( scobot(ji,jj) >= fsdept(ji,jj,jk) ) mbathy(ji,jj) = MAX( 2, jk )
  2043. END DO
  2044. IF( scobot(ji,jj) == 0._wp ) mbathy(ji,jj) = 0
  2045. END DO
  2046. END DO
  2047. IF( nprint == 1 .AND. lwp ) WRITE(numout,*) ' MIN val mbathy h90 ', MINVAL( mbathy(:,:) ), &
  2048. & ' MAX ', MAXVAL( mbathy(:,:) )
  2049. IF( nprint == 1 .AND. lwp ) THEN ! min max values over the local domain
  2050. WRITE(numout,*) ' MIN val mbathy ', MINVAL( mbathy(:,:) ), ' MAX ', MAXVAL( mbathy(:,:) )
  2051. WRITE(numout,*) ' MIN val depth t ', MINVAL( gdept_0(:,:,:) ), &
  2052. & ' w ', MINVAL( gdepw_0(:,:,:) ), '3w ' , MINVAL( gdep3w_0(:,:,:) )
  2053. WRITE(numout,*) ' MIN val e3 t ', MINVAL( e3t_0 (:,:,:) ), ' f ' , MINVAL( e3f_0 (:,:,:) ), &
  2054. & ' u ', MINVAL( e3u_0 (:,:,:) ), ' u ' , MINVAL( e3v_0 (:,:,:) ), &
  2055. & ' uw', MINVAL( e3uw_0 (:,:,:) ), ' vw' , MINVAL( e3vw_0 (:,:,:) ), &
  2056. & ' w ', MINVAL( e3w_0 (:,:,:) )
  2057. WRITE(numout,*) ' MAX val depth t ', MAXVAL( gdept_0(:,:,:) ), &
  2058. & ' w ', MAXVAL( gdepw_0(:,:,:) ), '3w ' , MAXVAL( gdep3w_0(:,:,:) )
  2059. WRITE(numout,*) ' MAX val e3 t ', MAXVAL( e3t_0 (:,:,:) ), ' f ' , MAXVAL( e3f_0 (:,:,:) ), &
  2060. & ' u ', MAXVAL( e3u_0 (:,:,:) ), ' u ' , MAXVAL( e3v_0 (:,:,:) ), &
  2061. & ' uw', MAXVAL( e3uw_0 (:,:,:) ), ' vw' , MAXVAL( e3vw_0 (:,:,:) ), &
  2062. & ' w ', MAXVAL( e3w_0 (:,:,:) )
  2063. ENDIF
  2064. ! END DO
  2065. IF(lwp) THEN ! selected vertical profiles
  2066. WRITE(numout,*)
  2067. WRITE(numout,*) ' domzgr: vertical coordinates : point (1,1,k) bathy = ', bathy(1,1), hbatt(1,1)
  2068. WRITE(numout,*) ' ~~~~~~ --------------------'
  2069. WRITE(numout,"(9x,' level gdept_0 gdepw_0 e3t_0 e3w_0')")
  2070. WRITE(numout,"(10x,i4,4f9.2)") ( jk, gdept_0(1,1,jk), gdepw_0(1,1,jk), &
  2071. & e3t_0 (1,1,jk) , e3w_0 (1,1,jk) , jk=1,jpk )
  2072. DO jj = mj0(20), mj1(20)
  2073. DO ji = mi0(20), mi1(20)
  2074. WRITE(numout,*)
  2075. WRITE(numout,*) ' domzgr: vertical coordinates : point (20,20,k) bathy = ', bathy(ji,jj), hbatt(ji,jj)
  2076. WRITE(numout,*) ' ~~~~~~ --------------------'
  2077. WRITE(numout,"(9x,' level gdept_0 gdepw_0 e3t_0 e3w_0')")
  2078. WRITE(numout,"(10x,i4,4f9.2)") ( jk, gdept_0(ji,jj,jk), gdepw_0(ji,jj,jk), &
  2079. & e3t_0 (ji,jj,jk) , e3w_0 (ji,jj,jk) , jk=1,jpk )
  2080. END DO
  2081. END DO
  2082. DO jj = mj0(74), mj1(74)
  2083. DO ji = mi0(100), mi1(100)
  2084. WRITE(numout,*)
  2085. WRITE(numout,*) ' domzgr: vertical coordinates : point (100,74,k) bathy = ', bathy(ji,jj), hbatt(ji,jj)
  2086. WRITE(numout,*) ' ~~~~~~ --------------------'
  2087. WRITE(numout,"(9x,' level gdept_0 gdepw_0 e3t_0 e3w_0')")
  2088. WRITE(numout,"(10x,i4,4f9.2)") ( jk, gdept_0(ji,jj,jk), gdepw_0(ji,jj,jk), &
  2089. & e3t_0 (ji,jj,jk) , e3w_0 (ji,jj,jk) , jk=1,jpk )
  2090. END DO
  2091. END DO
  2092. ENDIF
  2093. !================================================================================
  2094. ! check the coordinate makes sense
  2095. !================================================================================
  2096. DO ji = 1, jpi
  2097. DO jj = 1, jpj
  2098. IF( hbatt(ji,jj) > 0._wp) THEN
  2099. DO jk = 1, mbathy(ji,jj)
  2100. ! check coordinate is monotonically increasing
  2101. IF (fse3w(ji,jj,jk) <= 0._wp .OR. fse3t(ji,jj,jk) <= 0._wp ) THEN
  2102. WRITE(ctmp1,*) 'ERROR zgr_sco : e3w or e3t =< 0 at point (i,j,k)= ', ji, jj, jk
  2103. WRITE(numout,*) 'ERROR zgr_sco : e3w or e3t =< 0 at point (i,j,k)= ', ji, jj, jk
  2104. WRITE(numout,*) 'e3w',fse3w(ji,jj,:)
  2105. WRITE(numout,*) 'e3t',fse3t(ji,jj,:)
  2106. CALL ctl_stop( ctmp1 )
  2107. ENDIF
  2108. ! and check it has never gone negative
  2109. IF( fsdepw(ji,jj,jk) < 0._wp .OR. fsdept(ji,jj,jk) < 0._wp ) THEN
  2110. WRITE(ctmp1,*) 'ERROR zgr_sco : gdepw or gdept =< 0 at point (i,j,k)= ', ji, jj, jk
  2111. WRITE(numout,*) 'ERROR zgr_sco : gdepw or gdept =< 0 at point (i,j,k)= ', ji, jj, jk
  2112. WRITE(numout,*) 'gdepw',fsdepw(ji,jj,:)
  2113. WRITE(numout,*) 'gdept',fsdept(ji,jj,:)
  2114. CALL ctl_stop( ctmp1 )
  2115. ENDIF
  2116. ! and check it never exceeds the total depth
  2117. IF( fsdepw(ji,jj,jk) > hbatt(ji,jj) ) THEN
  2118. WRITE(ctmp1,*) 'ERROR zgr_sco : gdepw > hbatt at point (i,j,k)= ', ji, jj, jk
  2119. WRITE(numout,*) 'ERROR zgr_sco : gdepw > hbatt at point (i,j,k)= ', ji, jj, jk
  2120. WRITE(numout,*) 'gdepw',fsdepw(ji,jj,:)
  2121. CALL ctl_stop( ctmp1 )
  2122. ENDIF
  2123. END DO
  2124. DO jk = 1, mbathy(ji,jj)-1
  2125. ! and check it never exceeds the total depth
  2126. IF( fsdept(ji,jj,jk) > hbatt(ji,jj) ) THEN
  2127. WRITE(ctmp1,*) 'ERROR zgr_sco : gdept > hbatt at point (i,j,k)= ', ji, jj, jk
  2128. WRITE(numout,*) 'ERROR zgr_sco : gdept > hbatt at point (i,j,k)= ', ji, jj, jk
  2129. WRITE(numout,*) 'gdept',fsdept(ji,jj,:)
  2130. CALL ctl_stop( ctmp1 )
  2131. ENDIF
  2132. END DO
  2133. ENDIF
  2134. END DO
  2135. END DO
  2136. !
  2137. CALL wrk_dealloc( jpi, jpj, zenv, ztmp, zmsk, zri, zrj, zhbat , ztmpi1, ztmpi2, ztmpj1, ztmpj2 )
  2138. !
  2139. IF( nn_timing == 1 ) CALL timing_stop('zgr_sco')
  2140. !
  2141. END SUBROUTINE zgr_sco
  2142. !!======================================================================
  2143. SUBROUTINE s_sh94()
  2144. !!----------------------------------------------------------------------
  2145. !! *** ROUTINE s_sh94 ***
  2146. !!
  2147. !! ** Purpose : stretch the s-coordinate system
  2148. !!
  2149. !! ** Method : s-coordinate stretch using the Song and Haidvogel 1994
  2150. !! mixed S/sigma coordinate
  2151. !!
  2152. !! Reference : Song and Haidvogel 1994.
  2153. !!----------------------------------------------------------------------
  2154. !
  2155. INTEGER :: ji, jj, jk ! dummy loop argument
  2156. REAL(wp) :: zcoeft, zcoefw ! temporary scalars
  2157. !
  2158. REAL(wp), POINTER, DIMENSION(:,:,:) :: z_gsigw3, z_gsigt3, z_gsi3w3
  2159. REAL(wp), POINTER, DIMENSION(:,:,:) :: z_esigt3, z_esigw3, z_esigtu3, z_esigtv3, z_esigtf3, z_esigwu3, z_esigwv3
  2160. CALL wrk_alloc( jpi, jpj, jpk, z_gsigw3, z_gsigt3, z_gsi3w3 )
  2161. CALL wrk_alloc( jpi, jpj, jpk, z_esigt3, z_esigw3, z_esigtu3, z_esigtv3, z_esigtf3, z_esigwu3, z_esigwv3 )
  2162. z_gsigw3 = 0._wp ; z_gsigt3 = 0._wp ; z_gsi3w3 = 0._wp
  2163. z_esigt3 = 0._wp ; z_esigw3 = 0._wp
  2164. z_esigtu3 = 0._wp ; z_esigtv3 = 0._wp ; z_esigtf3 = 0._wp
  2165. z_esigwu3 = 0._wp ; z_esigwv3 = 0._wp
  2166. DO ji = 1, jpi
  2167. DO jj = 1, jpj
  2168. IF( hbatt(ji,jj) > rn_hc ) THEN !deep water, stretched sigma
  2169. DO jk = 1, jpk
  2170. z_gsigw3(ji,jj,jk) = -fssig1( REAL(jk,wp)-0.5_wp, rn_bb )
  2171. z_gsigt3(ji,jj,jk) = -fssig1( REAL(jk,wp) , rn_bb )
  2172. END DO
  2173. ELSE ! shallow water, uniform sigma
  2174. DO jk = 1, jpk
  2175. z_gsigw3(ji,jj,jk) = REAL(jk-1,wp) / REAL(jpk-1,wp)
  2176. z_gsigt3(ji,jj,jk) = ( REAL(jk-1,wp) + 0.5_wp ) / REAL(jpk-1,wp)
  2177. END DO
  2178. ENDIF
  2179. !
  2180. DO jk = 1, jpkm1
  2181. z_esigt3(ji,jj,jk ) = z_gsigw3(ji,jj,jk+1) - z_gsigw3(ji,jj,jk)
  2182. z_esigw3(ji,jj,jk+1) = z_gsigt3(ji,jj,jk+1) - z_gsigt3(ji,jj,jk)
  2183. END DO
  2184. z_esigw3(ji,jj,1 ) = 2._wp * ( z_gsigt3(ji,jj,1 ) - z_gsigw3(ji,jj,1 ) )
  2185. z_esigt3(ji,jj,jpk) = 2._wp * ( z_gsigt3(ji,jj,jpk) - z_gsigw3(ji,jj,jpk) )
  2186. !
  2187. ! Coefficients for vertical depth as the sum of e3w scale factors
  2188. z_gsi3w3(ji,jj,1) = 0.5_wp * z_esigw3(ji,jj,1)
  2189. DO jk = 2, jpk
  2190. z_gsi3w3(ji,jj,jk) = z_gsi3w3(ji,jj,jk-1) + z_esigw3(ji,jj,jk)
  2191. END DO
  2192. !
  2193. DO jk = 1, jpk
  2194. zcoeft = ( REAL(jk,wp) - 0.5_wp ) / REAL(jpkm1,wp)
  2195. zcoefw = ( REAL(jk,wp) - 1.0_wp ) / REAL(jpkm1,wp)
  2196. gdept_0 (ji,jj,jk) = ( scosrf(ji,jj) + (hbatt(ji,jj)-rn_hc)*z_gsigt3(ji,jj,jk)+rn_hc*zcoeft )
  2197. gdepw_0 (ji,jj,jk) = ( scosrf(ji,jj) + (hbatt(ji,jj)-rn_hc)*z_gsigw3(ji,jj,jk)+rn_hc*zcoefw )
  2198. gdep3w_0(ji,jj,jk) = ( scosrf(ji,jj) + (hbatt(ji,jj)-rn_hc)*z_gsi3w3(ji,jj,jk)+rn_hc*zcoeft )
  2199. END DO
  2200. !
  2201. END DO ! for all jj's
  2202. END DO ! for all ji's
  2203. DO ji = 1, jpim1
  2204. DO jj = 1, jpjm1
  2205. DO jk = 1, jpk
  2206. z_esigtu3(ji,jj,jk) = ( hbatt(ji,jj)*z_esigt3(ji,jj,jk)+hbatt(ji+1,jj)*z_esigt3(ji+1,jj,jk) ) &
  2207. & / ( hbatt(ji,jj)+hbatt(ji+1,jj) )
  2208. z_esigtv3(ji,jj,jk) = ( hbatt(ji,jj)*z_esigt3(ji,jj,jk)+hbatt(ji,jj+1)*z_esigt3(ji,jj+1,jk) ) &
  2209. & / ( hbatt(ji,jj)+hbatt(ji,jj+1) )
  2210. z_esigtf3(ji,jj,jk) = ( hbatt(ji,jj)*z_esigt3(ji,jj,jk)+hbatt(ji+1,jj)*z_esigt3(ji+1,jj,jk) &
  2211. & + hbatt(ji,jj+1)*z_esigt3(ji,jj+1,jk)+hbatt(ji+1,jj+1)*z_esigt3(ji+1,jj+1,jk) ) &
  2212. & / ( hbatt(ji,jj)+hbatt(ji+1,jj)+hbatt(ji,jj+1)+hbatt(ji+1,jj+1) )
  2213. z_esigwu3(ji,jj,jk) = ( hbatt(ji,jj)*z_esigw3(ji,jj,jk)+hbatt(ji+1,jj)*z_esigw3(ji+1,jj,jk) ) &
  2214. & / ( hbatt(ji,jj)+hbatt(ji+1,jj) )
  2215. z_esigwv3(ji,jj,jk) = ( hbatt(ji,jj)*z_esigw3(ji,jj,jk)+hbatt(ji,jj+1)*z_esigw3(ji,jj+1,jk) ) &
  2216. & / ( hbatt(ji,jj)+hbatt(ji,jj+1) )
  2217. !
  2218. e3t_0(ji,jj,jk) = ( (hbatt(ji,jj)-rn_hc)*z_esigt3 (ji,jj,jk) + rn_hc/REAL(jpkm1,wp) )
  2219. e3u_0(ji,jj,jk) = ( (hbatu(ji,jj)-rn_hc)*z_esigtu3(ji,jj,jk) + rn_hc/REAL(jpkm1,wp) )
  2220. e3v_0(ji,jj,jk) = ( (hbatv(ji,jj)-rn_hc)*z_esigtv3(ji,jj,jk) + rn_hc/REAL(jpkm1,wp) )
  2221. e3f_0(ji,jj,jk) = ( (hbatf(ji,jj)-rn_hc)*z_esigtf3(ji,jj,jk) + rn_hc/REAL(jpkm1,wp) )
  2222. !
  2223. e3w_0 (ji,jj,jk) = ( (hbatt(ji,jj)-rn_hc)*z_esigw3 (ji,jj,jk) + rn_hc/REAL(jpkm1,wp) )
  2224. e3uw_0(ji,jj,jk) = ( (hbatu(ji,jj)-rn_hc)*z_esigwu3(ji,jj,jk) + rn_hc/REAL(jpkm1,wp) )
  2225. e3vw_0(ji,jj,jk) = ( (hbatv(ji,jj)-rn_hc)*z_esigwv3(ji,jj,jk) + rn_hc/REAL(jpkm1,wp) )
  2226. END DO
  2227. END DO
  2228. END DO
  2229. CALL wrk_dealloc( jpi, jpj, jpk, z_gsigw3, z_gsigt3, z_gsi3w3 )
  2230. CALL wrk_dealloc( jpi, jpj, jpk, z_esigt3, z_esigw3, z_esigtu3, z_esigtv3, z_esigtf3, z_esigwu3, z_esigwv3 )
  2231. END SUBROUTINE s_sh94
  2232. SUBROUTINE s_sf12
  2233. !!----------------------------------------------------------------------
  2234. !! *** ROUTINE s_sf12 ***
  2235. !!
  2236. !! ** Purpose : stretch the s-coordinate system
  2237. !!
  2238. !! ** Method : s-coordinate stretch using the Siddorn and Furner 2012?
  2239. !! mixed S/sigma/Z coordinate
  2240. !!
  2241. !! This method allows the maintenance of fixed surface and or
  2242. !! bottom cell resolutions (cf. geopotential coordinates)
  2243. !! within an analytically derived stretched S-coordinate framework.
  2244. !!
  2245. !!
  2246. !! Reference : Siddorn and Furner 2012 (submitted Ocean modelling).
  2247. !!----------------------------------------------------------------------
  2248. !
  2249. INTEGER :: ji, jj, jk ! dummy loop argument
  2250. REAL(wp) :: zsmth ! smoothing around critical depth
  2251. REAL(wp) :: zzs, zzb ! Surface and bottom cell thickness in sigma space
  2252. !
  2253. REAL(wp), POINTER, DIMENSION(:,:,:) :: z_gsigw3, z_gsigt3, z_gsi3w3
  2254. REAL(wp), POINTER, DIMENSION(:,:,:) :: z_esigt3, z_esigw3, z_esigtu3, z_esigtv3, z_esigtf3, z_esigwu3, z_esigwv3
  2255. !
  2256. CALL wrk_alloc( jpi, jpj, jpk, z_gsigw3, z_gsigt3, z_gsi3w3 )
  2257. CALL wrk_alloc( jpi, jpj, jpk, z_esigt3, z_esigw3, z_esigtu3, z_esigtv3, z_esigtf3, z_esigwu3, z_esigwv3 )
  2258. z_gsigw3 = 0._wp ; z_gsigt3 = 0._wp ; z_gsi3w3 = 0._wp
  2259. z_esigt3 = 0._wp ; z_esigw3 = 0._wp
  2260. z_esigtu3 = 0._wp ; z_esigtv3 = 0._wp ; z_esigtf3 = 0._wp
  2261. z_esigwu3 = 0._wp ; z_esigwv3 = 0._wp
  2262. DO ji = 1, jpi
  2263. DO jj = 1, jpj
  2264. IF (hbatt(ji,jj)>rn_hc) THEN !deep water, stretched sigma
  2265. zzb = hbatt(ji,jj)*rn_zb_a + rn_zb_b ! this forces a linear bottom cell depth relationship with H,.
  2266. ! could be changed by users but care must be taken to do so carefully
  2267. zzb = 1.0_wp-(zzb/hbatt(ji,jj))
  2268. zzs = rn_zs / hbatt(ji,jj)
  2269. IF (rn_efold /= 0.0_wp) THEN
  2270. zsmth = tanh( (hbatt(ji,jj)- rn_hc ) / rn_efold )
  2271. ELSE
  2272. zsmth = 1.0_wp
  2273. ENDIF
  2274. DO jk = 1, jpk
  2275. z_gsigw3(ji,jj,jk) = REAL(jk-1,wp) /REAL(jpk-1,wp)
  2276. z_gsigt3(ji,jj,jk) = (REAL(jk-1,wp)+0.5_wp)/REAL(jpk-1,wp)
  2277. ENDDO
  2278. z_gsigw3(ji,jj,:) = fgamma( z_gsigw3(ji,jj,:), zzb, zzs, zsmth )
  2279. z_gsigt3(ji,jj,:) = fgamma( z_gsigt3(ji,jj,:), zzb, zzs, zsmth )
  2280. ELSE IF (ln_sigcrit) THEN ! shallow water, uniform sigma
  2281. DO jk = 1, jpk
  2282. z_gsigw3(ji,jj,jk) = REAL(jk-1,wp) /REAL(jpk-1,wp)
  2283. z_gsigt3(ji,jj,jk) = (REAL(jk-1,wp)+0.5)/REAL(jpk-1,wp)
  2284. END DO
  2285. ELSE ! shallow water, z coordinates
  2286. DO jk = 1, jpk
  2287. z_gsigw3(ji,jj,jk) = REAL(jk-1,wp) /REAL(jpk-1,wp)*(rn_hc/hbatt(ji,jj))
  2288. z_gsigt3(ji,jj,jk) = (REAL(jk-1,wp)+0.5_wp)/REAL(jpk-1,wp)*(rn_hc/hbatt(ji,jj))
  2289. END DO
  2290. ENDIF
  2291. DO jk = 1, jpkm1
  2292. z_esigt3(ji,jj,jk) = z_gsigw3(ji,jj,jk+1) - z_gsigw3(ji,jj,jk)
  2293. z_esigw3(ji,jj,jk+1) = z_gsigt3(ji,jj,jk+1) - z_gsigt3(ji,jj,jk)
  2294. END DO
  2295. z_esigw3(ji,jj,1 ) = 2.0_wp * (z_gsigt3(ji,jj,1 ) - z_gsigw3(ji,jj,1 ))
  2296. z_esigt3(ji,jj,jpk) = 2.0_wp * (z_gsigt3(ji,jj,jpk) - z_gsigw3(ji,jj,jpk))
  2297. ! Coefficients for vertical depth as the sum of e3w scale factors
  2298. z_gsi3w3(ji,jj,1) = 0.5 * z_esigw3(ji,jj,1)
  2299. DO jk = 2, jpk
  2300. z_gsi3w3(ji,jj,jk) = z_gsi3w3(ji,jj,jk-1) + z_esigw3(ji,jj,jk)
  2301. END DO
  2302. DO jk = 1, jpk
  2303. gdept_0 (ji,jj,jk) = (scosrf(ji,jj)+hbatt(ji,jj))*z_gsigt3(ji,jj,jk)
  2304. gdepw_0 (ji,jj,jk) = (scosrf(ji,jj)+hbatt(ji,jj))*z_gsigw3(ji,jj,jk)
  2305. gdep3w_0(ji,jj,jk) = (scosrf(ji,jj)+hbatt(ji,jj))*z_gsi3w3(ji,jj,jk)
  2306. END DO
  2307. ENDDO ! for all jj's
  2308. ENDDO ! for all ji's
  2309. DO ji=1,jpi-1
  2310. DO jj=1,jpj-1
  2311. DO jk = 1, jpk
  2312. z_esigtu3(ji,jj,jk) = ( hbatt(ji,jj)*z_esigt3(ji,jj,jk)+hbatt(ji+1,jj)*z_esigt3(ji+1,jj,jk) ) / &
  2313. ( hbatt(ji,jj)+hbatt(ji+1,jj) )
  2314. z_esigtv3(ji,jj,jk) = ( hbatt(ji,jj)*z_esigt3(ji,jj,jk)+hbatt(ji,jj+1)*z_esigt3(ji,jj+1,jk) ) / &
  2315. ( hbatt(ji,jj)+hbatt(ji,jj+1) )
  2316. z_esigtf3(ji,jj,jk) = ( hbatt(ji,jj)*z_esigt3(ji,jj,jk)+hbatt(ji+1,jj)*z_esigt3(ji+1,jj,jk) + &
  2317. hbatt(ji,jj+1)*z_esigt3(ji,jj+1,jk)+hbatt(ji+1,jj+1)*z_esigt3(ji+1,jj+1,jk) ) / &
  2318. ( hbatt(ji,jj)+hbatt(ji+1,jj)+hbatt(ji,jj+1)+hbatt(ji+1,jj+1) )
  2319. z_esigwu3(ji,jj,jk) = ( hbatt(ji,jj)*z_esigw3(ji,jj,jk)+hbatt(ji+1,jj)*z_esigw3(ji+1,jj,jk) ) / &
  2320. ( hbatt(ji,jj)+hbatt(ji+1,jj) )
  2321. z_esigwv3(ji,jj,jk) = ( hbatt(ji,jj)*z_esigw3(ji,jj,jk)+hbatt(ji,jj+1)*z_esigw3(ji,jj+1,jk) ) / &
  2322. ( hbatt(ji,jj)+hbatt(ji,jj+1) )
  2323. e3t_0(ji,jj,jk)=(scosrf(ji,jj)+hbatt(ji,jj))*z_esigt3(ji,jj,jk)
  2324. e3u_0(ji,jj,jk)=(scosrf(ji,jj)+hbatu(ji,jj))*z_esigtu3(ji,jj,jk)
  2325. e3v_0(ji,jj,jk)=(scosrf(ji,jj)+hbatv(ji,jj))*z_esigtv3(ji,jj,jk)
  2326. e3f_0(ji,jj,jk)=(scosrf(ji,jj)+hbatf(ji,jj))*z_esigtf3(ji,jj,jk)
  2327. !
  2328. e3w_0(ji,jj,jk)=hbatt(ji,jj)*z_esigw3(ji,jj,jk)
  2329. e3uw_0(ji,jj,jk)=hbatu(ji,jj)*z_esigwu3(ji,jj,jk)
  2330. e3vw_0(ji,jj,jk)=hbatv(ji,jj)*z_esigwv3(ji,jj,jk)
  2331. END DO
  2332. ENDDO
  2333. ENDDO
  2334. !
  2335. CALL lbc_lnk(e3t_0 ,'T',1.) ; CALL lbc_lnk(e3u_0 ,'T',1.)
  2336. CALL lbc_lnk(e3v_0 ,'T',1.) ; CALL lbc_lnk(e3f_0 ,'T',1.)
  2337. CALL lbc_lnk(e3w_0 ,'T',1.)
  2338. CALL lbc_lnk(e3uw_0,'T',1.) ; CALL lbc_lnk(e3vw_0,'T',1.)
  2339. !
  2340. ! ! =============
  2341. CALL wrk_dealloc( jpi, jpj, jpk, z_gsigw3, z_gsigt3, z_gsi3w3 )
  2342. CALL wrk_dealloc( jpi, jpj, jpk, z_esigt3, z_esigw3, z_esigtu3, z_esigtv3, z_esigtf3, z_esigwu3, z_esigwv3 )
  2343. END SUBROUTINE s_sf12
  2344. SUBROUTINE s_tanh()
  2345. !!----------------------------------------------------------------------
  2346. !! *** ROUTINE s_tanh***
  2347. !!
  2348. !! ** Purpose : stretch the s-coordinate system
  2349. !!
  2350. !! ** Method : s-coordinate stretch
  2351. !!
  2352. !! Reference : Madec, Lott, Delecluse and Crepon, 1996. JPO, 26, 1393-1408.
  2353. !!----------------------------------------------------------------------
  2354. INTEGER :: ji, jj, jk ! dummy loop argument
  2355. REAL(wp) :: zcoeft, zcoefw ! temporary scalars
  2356. REAL(wp), POINTER, DIMENSION(:) :: z_gsigw, z_gsigt, z_gsi3w
  2357. REAL(wp), POINTER, DIMENSION(:) :: z_esigt, z_esigw
  2358. CALL wrk_alloc( jpk, z_gsigw, z_gsigt, z_gsi3w )
  2359. CALL wrk_alloc( jpk, z_esigt, z_esigw )
  2360. z_gsigw = 0._wp ; z_gsigt = 0._wp ; z_gsi3w = 0._wp
  2361. z_esigt = 0._wp ; z_esigw = 0._wp
  2362. DO jk = 1, jpk
  2363. z_gsigw(jk) = -fssig( REAL(jk,wp)-0.5_wp )
  2364. z_gsigt(jk) = -fssig( REAL(jk,wp) )
  2365. END DO
  2366. IF( nprint == 1 .AND. lwp ) WRITE(numout,*) 'z_gsigw 1 jpk ', z_gsigw(1), z_gsigw(jpk)
  2367. !
  2368. ! Coefficients for vertical scale factors at w-, t- levels
  2369. !!gm bug : define it from analytical function, not like juste bellow....
  2370. !!gm or betteroffer the 2 possibilities....
  2371. DO jk = 1, jpkm1
  2372. z_esigt(jk ) = z_gsigw(jk+1) - z_gsigw(jk)
  2373. z_esigw(jk+1) = z_gsigt(jk+1) - z_gsigt(jk)
  2374. END DO
  2375. z_esigw( 1 ) = 2._wp * ( z_gsigt(1 ) - z_gsigw(1 ) )
  2376. z_esigt(jpk) = 2._wp * ( z_gsigt(jpk) - z_gsigw(jpk) )
  2377. !
  2378. ! Coefficients for vertical depth as the sum of e3w scale factors
  2379. z_gsi3w(1) = 0.5_wp * z_esigw(1)
  2380. DO jk = 2, jpk
  2381. z_gsi3w(jk) = z_gsi3w(jk-1) + z_esigw(jk)
  2382. END DO
  2383. !!gm: depuw, depvw can be suppressed (modif in ldfslp) and depw=dep3w can be set (save 3 3D arrays)
  2384. DO jk = 1, jpk
  2385. zcoeft = ( REAL(jk,wp) - 0.5_wp ) / REAL(jpkm1,wp)
  2386. zcoefw = ( REAL(jk,wp) - 1.0_wp ) / REAL(jpkm1,wp)
  2387. gdept_0 (:,:,jk) = ( scosrf(:,:) + (hbatt(:,:)-hift(:,:))*z_gsigt(jk) + hift(:,:)*zcoeft )
  2388. gdepw_0 (:,:,jk) = ( scosrf(:,:) + (hbatt(:,:)-hift(:,:))*z_gsigw(jk) + hift(:,:)*zcoefw )
  2389. gdep3w_0(:,:,jk) = ( scosrf(:,:) + (hbatt(:,:)-hift(:,:))*z_gsi3w(jk) + hift(:,:)*zcoeft )
  2390. END DO
  2391. !!gm: e3uw, e3vw can be suppressed (modif in dynzdf, dynzdf_iso, zdfbfr) (save 2 3D arrays)
  2392. DO jj = 1, jpj
  2393. DO ji = 1, jpi
  2394. DO jk = 1, jpk
  2395. e3t_0(ji,jj,jk) = ( (hbatt(ji,jj)-hift(ji,jj))*z_esigt(jk) + hift(ji,jj)/REAL(jpkm1,wp) )
  2396. e3u_0(ji,jj,jk) = ( (hbatu(ji,jj)-hifu(ji,jj))*z_esigt(jk) + hifu(ji,jj)/REAL(jpkm1,wp) )
  2397. e3v_0(ji,jj,jk) = ( (hbatv(ji,jj)-hifv(ji,jj))*z_esigt(jk) + hifv(ji,jj)/REAL(jpkm1,wp) )
  2398. e3f_0(ji,jj,jk) = ( (hbatf(ji,jj)-hiff(ji,jj))*z_esigt(jk) + hiff(ji,jj)/REAL(jpkm1,wp) )
  2399. !
  2400. e3w_0 (ji,jj,jk) = ( (hbatt(ji,jj)-hift(ji,jj))*z_esigw(jk) + hift(ji,jj)/REAL(jpkm1,wp) )
  2401. e3uw_0(ji,jj,jk) = ( (hbatu(ji,jj)-hifu(ji,jj))*z_esigw(jk) + hifu(ji,jj)/REAL(jpkm1,wp) )
  2402. e3vw_0(ji,jj,jk) = ( (hbatv(ji,jj)-hifv(ji,jj))*z_esigw(jk) + hifv(ji,jj)/REAL(jpkm1,wp) )
  2403. END DO
  2404. END DO
  2405. END DO
  2406. CALL wrk_dealloc( jpk, z_gsigw, z_gsigt, z_gsi3w )
  2407. CALL wrk_dealloc( jpk, z_esigt, z_esigw )
  2408. END SUBROUTINE s_tanh
  2409. FUNCTION fssig( pk ) RESULT( pf )
  2410. !!----------------------------------------------------------------------
  2411. !! *** ROUTINE fssig ***
  2412. !!
  2413. !! ** Purpose : provide the analytical function in s-coordinate
  2414. !!
  2415. !! ** Method : the function provide the non-dimensional position of
  2416. !! T and W (i.e. between 0 and 1)
  2417. !! T-points at integer values (between 1 and jpk)
  2418. !! W-points at integer values - 1/2 (between 0.5 and jpk-0.5)
  2419. !!----------------------------------------------------------------------
  2420. REAL(wp), INTENT(in) :: pk ! continuous "k" coordinate
  2421. REAL(wp) :: pf ! sigma value
  2422. !!----------------------------------------------------------------------
  2423. !
  2424. pf = ( TANH( rn_theta * ( -(pk-0.5_wp) / REAL(jpkm1) + rn_thetb ) ) &
  2425. & - TANH( rn_thetb * rn_theta ) ) &
  2426. & * ( COSH( rn_theta ) &
  2427. & + COSH( rn_theta * ( 2._wp * rn_thetb - 1._wp ) ) ) &
  2428. & / ( 2._wp * SINH( rn_theta ) )
  2429. !
  2430. END FUNCTION fssig
  2431. FUNCTION fssig1( pk1, pbb ) RESULT( pf1 )
  2432. !!----------------------------------------------------------------------
  2433. !! *** ROUTINE fssig1 ***
  2434. !!
  2435. !! ** Purpose : provide the Song and Haidvogel version of the analytical function in s-coordinate
  2436. !!
  2437. !! ** Method : the function provides the non-dimensional position of
  2438. !! T and W (i.e. between 0 and 1)
  2439. !! T-points at integer values (between 1 and jpk)
  2440. !! W-points at integer values - 1/2 (between 0.5 and jpk-0.5)
  2441. !!----------------------------------------------------------------------
  2442. REAL(wp), INTENT(in) :: pk1 ! continuous "k" coordinate
  2443. REAL(wp), INTENT(in) :: pbb ! Stretching coefficient
  2444. REAL(wp) :: pf1 ! sigma value
  2445. !!----------------------------------------------------------------------
  2446. !
  2447. IF ( rn_theta == 0 ) then ! uniform sigma
  2448. pf1 = - ( pk1 - 0.5_wp ) / REAL( jpkm1 )
  2449. ELSE ! stretched sigma
  2450. pf1 = ( 1._wp - pbb ) * ( SINH( rn_theta*(-(pk1-0.5_wp)/REAL(jpkm1)) ) ) / SINH( rn_theta ) &
  2451. & + pbb * ( (TANH( rn_theta*( (-(pk1-0.5_wp)/REAL(jpkm1)) + 0.5_wp) ) - TANH( 0.5_wp * rn_theta ) ) &
  2452. & / ( 2._wp * TANH( 0.5_wp * rn_theta ) ) )
  2453. ENDIF
  2454. !
  2455. END FUNCTION fssig1
  2456. FUNCTION fgamma( pk1, pzb, pzs, psmth) RESULT( p_gamma )
  2457. !!----------------------------------------------------------------------
  2458. !! *** ROUTINE fgamma ***
  2459. !!
  2460. !! ** Purpose : provide analytical function for the s-coordinate
  2461. !!
  2462. !! ** Method : the function provides the non-dimensional position of
  2463. !! T and W (i.e. between 0 and 1)
  2464. !! T-points at integer values (between 1 and jpk)
  2465. !! W-points at integer values - 1/2 (between 0.5 and jpk-0.5)
  2466. !!
  2467. !! This method allows the maintenance of fixed surface and or
  2468. !! bottom cell resolutions (cf. geopotential coordinates)
  2469. !! within an analytically derived stretched S-coordinate framework.
  2470. !!
  2471. !! Reference : Siddorn and Furner, in prep
  2472. !!----------------------------------------------------------------------
  2473. REAL(wp), INTENT(in ) :: pk1(jpk) ! continuous "k" coordinate
  2474. REAL(wp) :: p_gamma(jpk) ! stretched coordinate
  2475. REAL(wp), INTENT(in ) :: pzb ! Bottom box depth
  2476. REAL(wp), INTENT(in ) :: pzs ! surface box depth
  2477. REAL(wp), INTENT(in ) :: psmth ! Smoothing parameter
  2478. REAL(wp) :: za1,za2,za3 ! local variables
  2479. REAL(wp) :: zn1,zn2 ! local variables
  2480. REAL(wp) :: za,zb,zx ! local variables
  2481. integer :: jk
  2482. !!----------------------------------------------------------------------
  2483. !
  2484. zn1 = 1./(jpk-1.)
  2485. zn2 = 1. - zn1
  2486. za1 = (rn_alpha+2.0_wp)*zn1**(rn_alpha+1.0_wp)-(rn_alpha+1.0_wp)*zn1**(rn_alpha+2.0_wp)
  2487. za2 = (rn_alpha+2.0_wp)*zn2**(rn_alpha+1.0_wp)-(rn_alpha+1.0_wp)*zn2**(rn_alpha+2.0_wp)
  2488. za3 = (zn2**3.0_wp - za2)/( zn1**3.0_wp - za1)
  2489. za = pzb - za3*(pzs-za1)-za2
  2490. za = za/( zn2-0.5_wp*(za2+zn2**2.0_wp) - za3*(zn1-0.5_wp*(za1+zn1**2.0_wp) ) )
  2491. zb = (pzs - za1 - za*( zn1-0.5_wp*(za1+zn1**2.0_wp ) ) ) / (zn1**3.0_wp - za1)
  2492. zx = 1.0_wp-za/2.0_wp-zb
  2493. DO jk = 1, jpk
  2494. p_gamma(jk) = za*(pk1(jk)*(1.0_wp-pk1(jk)/2.0_wp))+zb*pk1(jk)**3.0_wp + &
  2495. & zx*( (rn_alpha+2.0_wp)*pk1(jk)**(rn_alpha+1.0_wp)- &
  2496. & (rn_alpha+1.0_wp)*pk1(jk)**(rn_alpha+2.0_wp) )
  2497. p_gamma(jk) = p_gamma(jk)*psmth+pk1(jk)*(1.0_wp-psmth)
  2498. ENDDO
  2499. !
  2500. END FUNCTION fgamma
  2501. !!======================================================================
  2502. END MODULE domzgr