nemogcm.F90 34 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751
  1. MODULE nemogcm
  2. !!======================================================================
  3. !! *** MODULE nemogcm ***
  4. !! Ocean system : NEMO GCM (ocean dynamics, on-line tracers, biochemistry and sea-ice)
  5. !!======================================================================
  6. !! History : OPA ! 1990-10 (C. Levy, G. Madec) Original code
  7. !! 7.0 ! 1991-11 (M. Imbard, C. Levy, G. Madec)
  8. !! 7.1 ! 1993-03 (M. Imbard, C. Levy, G. Madec, O. Marti, M. Guyon, A. Lazar,
  9. !! P. Delecluse, C. Perigaud, G. Caniaux, B. Colot, C. Maes) release 7.1
  10. !! - ! 1992-06 (L.Terray) coupling implementation
  11. !! - ! 1993-11 (M.A. Filiberti) IGLOO sea-ice
  12. !! 8.0 ! 1996-03 (M. Imbard, C. Levy, G. Madec, O. Marti, M. Guyon, A. Lazar,
  13. !! P. Delecluse, L.Terray, M.A. Filiberti, J. Vialar, A.M. Treguier, M. Levy) release 8.0
  14. !! 8.1 ! 1997-06 (M. Imbard, G. Madec)
  15. !! 8.2 ! 1999-11 (M. Imbard, H. Goosse) LIM sea-ice model
  16. !! ! 1999-12 (V. Thierry, A-M. Treguier, M. Imbard, M-A. Foujols) OPEN-MP
  17. !! ! 2000-07 (J-M Molines, M. Imbard) Open Boundary Conditions (CLIPPER)
  18. !! NEMO 1.0 ! 2002-08 (G. Madec) F90: Free form and modules
  19. !! - ! 2004-06 (R. Redler, NEC CCRLE, Germany) add OASIS[3/4] coupled interfaces
  20. !! - ! 2004-08 (C. Talandier) New trends organization
  21. !! - ! 2005-06 (C. Ethe) Add the 1D configuration possibility
  22. !! - ! 2005-11 (V. Garnier) Surface pressure gradient organization
  23. !! - ! 2006-03 (L. Debreu, C. Mazauric) Agrif implementation
  24. !! - ! 2006-04 (G. Madec, R. Benshila) Step reorganization
  25. !! - ! 2007-07 (J. Chanut, A. Sellar) Unstructured open boundaries (BDY)
  26. !! 3.2 ! 2009-08 (S. Masson) open/write in the listing file in mpp
  27. !! 3.3 ! 2010-05 (K. Mogensen, A. Weaver, M. Martin, D. Lea) Assimilation interface
  28. !! - ! 2010-10 (C. Ethe, G. Madec) reorganisation of initialisation phase
  29. !! 3.3.1! 2011-01 (A. R. Porter, STFC Daresbury) dynamical allocation
  30. !! 3.4 ! 2011-11 (C. Harris) decomposition changes for running with CICE
  31. !!----------------------------------------------------------------------
  32. !!----------------------------------------------------------------------
  33. !! nemo_gcm : solve ocean dynamics, tracer, biogeochemistry and/or sea-ice
  34. !! nemo_init : initialization of the NEMO system
  35. !! nemo_ctl : initialisation of the contol print
  36. !! nemo_closefile : close remaining open files
  37. !! nemo_alloc : dynamical allocation
  38. !! nemo_partition : calculate MPP domain decomposition
  39. !! factorise : calculate the factors of the no. of MPI processes
  40. !!----------------------------------------------------------------------
  41. USE step_oce ! module used in the ocean time stepping module
  42. USE sbc_oce ! surface boundary condition: ocean
  43. USE domcfg ! domain configuration (dom_cfg routine)
  44. USE daymod ! calendar
  45. USE mppini ! shared/distributed memory setting (mpp_init routine)
  46. USE domain ! domain initialization (dom_init routine)
  47. USE phycst ! physical constant (par_cst routine)
  48. USE step ! NEMO time-stepping (stp routine)
  49. USE lib_mpp ! distributed memory computing
  50. #if defined key_nosignedzero
  51. USE lib_fortran ! Fortran utilities (allows no signed zero when 'key_nosignedzero' defined)
  52. #endif
  53. #if defined key_iomput
  54. USE xios
  55. #endif
  56. USE cpl_oasis3
  57. USE sbcssm
  58. USE lbcnfd, ONLY: isendto, nsndto, nfsloop, nfeloop ! Setup of north fold exchanges
  59. USE icbstp ! handle bergs, calving, themodynamics and transport
  60. #if defined key_bdy
  61. USE bdyini ! open boundary cond. setting (bdy_init routine). clem: mandatory for LIM3
  62. USE bdydta ! open boundary cond. setting (bdy_dta_init routine). clem: mandatory for LIM3
  63. #endif
  64. USE bdy_par
  65. USE restart
  66. IMPLICIT NONE
  67. PRIVATE
  68. PUBLIC nemo_gcm ! called by model.F90
  69. PUBLIC nemo_init ! needed by AGRIF
  70. CHARACTER(lc) :: cform_aaa="( /, 'AAAAAAAA', / ) " ! flag for output listing
  71. !!----------------------------------------------------------------------
  72. !! NEMO/OPA 4.0 , NEMO Consortium (2011)
  73. !! $Id: nemogcm.F90 5424 2018-04-27 07:03:10Z ufla $
  74. !! Software governed by the CeCILL licence (NEMOGCM/NEMO_CeCILL.txt)
  75. !!----------------------------------------------------------------------
  76. CONTAINS
  77. SUBROUTINE nemo_gcm
  78. !!----------------------------------------------------------------------
  79. !! *** ROUTINE nemo_gcm ***
  80. !!
  81. !! ** Purpose : NEMO solves the primitive equations on an orthogonal
  82. !! curvilinear mesh on the sphere.
  83. !!
  84. !! ** Method : - model general initialization
  85. !! - launch the time-stepping (stp routine)
  86. !! - finalize the run by closing files and communications
  87. !!
  88. !! References : Madec, Delecluse, Imbard, and Levy, 1997: internal report, IPSL.
  89. !! Madec, 2008, internal report, IPSL.
  90. !!----------------------------------------------------------------------
  91. INTEGER :: istp ! time step index
  92. !!----------------------------------------------------------------------
  93. !
  94. #if defined key_agrif
  95. CALL Agrif_Init_Grids() ! AGRIF: set the meshes
  96. #endif
  97. ! !-----------------------!
  98. CALL nemo_init !== Initialisations ==!
  99. ! !-----------------------!
  100. #if defined key_agrif
  101. CALL Agrif_Declare_Var_dom ! AGRIF: set the meshes for DOM
  102. CALL Agrif_Declare_Var ! " " " " " DYN/TRA
  103. # if defined key_top
  104. CALL Agrif_Declare_Var_top ! " " " " " TOP
  105. # endif
  106. # if defined key_lim2
  107. CALL Agrif_Declare_Var_lim2 ! " " " " " LIM
  108. # endif
  109. #endif
  110. ! check that all process are still there... If some process have an error,
  111. ! they will never enter in step and other processes will wait until the end of the cpu time!
  112. IF( lk_mpp ) CALL mpp_max( nstop )
  113. IF(lwp) WRITE(numout,cform_aaa) ! Flag AAAAAAA
  114. ! !-----------------------!
  115. ! !== time stepping ==!
  116. ! !-----------------------!
  117. istp = nit000
  118. DO WHILE ( istp <= nitend .AND. nstop == 0 )
  119. #if defined key_agrif
  120. CALL Agrif_Step( stp ) ! AGRIF: time stepping
  121. #else
  122. CALL stp( istp ) ! standard time stepping
  123. #endif
  124. istp = istp + 1
  125. IF( lk_mpp ) CALL mpp_max( nstop )
  126. END DO
  127. !
  128. IF( ln_icebergs ) CALL icb_end( nitend )
  129. ! !------------------------!
  130. ! !== finalize the run ==!
  131. ! !------------------------!
  132. IF(lwp) WRITE(numout,cform_aaa) ! Flag AAAAAAA
  133. !
  134. IF( nstop /= 0 .AND. lwp ) THEN ! error print
  135. WRITE(numout,cform_err)
  136. WRITE(numout,*) nstop, ' error have been found'
  137. ENDIF
  138. !
  139. #if defined key_agrif
  140. CALL Agrif_ParentGrid_To_ChildGrid()
  141. IF( nn_timing == 1 ) CALL timing_finalize
  142. CALL Agrif_ChildGrid_To_ParentGrid()
  143. #endif
  144. IF( nn_timing == 1 ) CALL timing_finalize
  145. !
  146. CALL nemo_closefile
  147. !
  148. #if defined key_iomput
  149. CALL xios_finalize ! end mpp communications with xios
  150. IF( lk_oasis ) CALL cpl_finalize ! end coupling and mpp communications with OASIS
  151. #else
  152. IF( lk_oasis ) THEN
  153. CALL cpl_finalize ! end coupling and mpp communications with OASIS
  154. ELSE
  155. IF( lk_mpp ) CALL mppstop ! end mpp communications
  156. ENDIF
  157. #endif
  158. !
  159. END SUBROUTINE nemo_gcm
  160. SUBROUTINE nemo_init
  161. !!----------------------------------------------------------------------
  162. !! *** ROUTINE nemo_init ***
  163. !!
  164. !! ** Purpose : initialization of the NEMO GCM
  165. !!----------------------------------------------------------------------
  166. INTEGER :: ji ! dummy loop indices
  167. INTEGER :: ilocal_comm ! local integer
  168. INTEGER :: ios
  169. CHARACTER(len=80), DIMENSION(16) :: cltxt
  170. CHARACTER(len=80) :: clname
  171. !
  172. NAMELIST/namctl/ ln_ctl , nn_print, nn_ictls, nn_ictle, &
  173. & nn_isplt, nn_jsplt, nn_jctls, nn_jctle, &
  174. & nn_bench, nn_timing
  175. NAMELIST/namcfg/ cp_cfg, cp_cfz, jp_cfg, jpidta, jpjdta, jpkdta, jpiglo, jpjglo, &
  176. & jpizoom, jpjzoom, jperio, ln_use_jattr
  177. !!----------------------------------------------------------------------
  178. !
  179. cltxt = ''
  180. !
  181. ! ! Open reference namelist and configuration namelist files
  182. IF( lk_oasis ) THEN
  183. CALL ctl_opn( numnam_ref, 'namelist_sas_ref', 'OLD', 'FORMATTED', 'SEQUENTIAL', -1, 6, .FALSE. )
  184. CALL ctl_opn( numnam_cfg, 'namelist_sas_cfg', 'OLD', 'FORMATTED', 'SEQUENTIAL', -1, 6, .FALSE. )
  185. cxios_context = 'sas'
  186. clname = 'output.namelist_sas.dyn'
  187. ELSE
  188. CALL ctl_opn( numnam_ref, 'namelist_ref', 'OLD', 'FORMATTED', 'SEQUENTIAL', -1, 6, .FALSE. )
  189. CALL ctl_opn( numnam_cfg, 'namelist_cfg', 'OLD', 'FORMATTED', 'SEQUENTIAL', -1, 6, .FALSE. )
  190. cxios_context = 'nemo'
  191. clname = 'output.namelist.dyn'
  192. ENDIF
  193. !
  194. REWIND( numnam_ref ) ! Namelist namctl in reference namelist : Control prints & Benchmark
  195. READ ( numnam_ref, namctl, IOSTAT = ios, ERR = 901 )
  196. 901 IF( ios /= 0 ) CALL ctl_nam ( ios , 'namctl in reference namelist', .TRUE. )
  197. REWIND( numnam_cfg ) ! Namelist namctl in confguration namelist : Control prints & Benchmark
  198. READ ( numnam_cfg, namctl, IOSTAT = ios, ERR = 902 )
  199. 902 IF( ios /= 0 ) CALL ctl_nam ( ios , 'namctl in configuration namelist', .TRUE. )
  200. !
  201. REWIND( numnam_ref ) ! Namelist namcfg in reference namelist : Control prints & Benchmark
  202. READ ( numnam_ref, namcfg, IOSTAT = ios, ERR = 903 )
  203. 903 IF( ios /= 0 ) CALL ctl_nam ( ios , 'namcfg in reference namelist', .TRUE. )
  204. REWIND( numnam_cfg ) ! Namelist namcfg in confguration namelist : Control prints & Benchmark
  205. READ ( numnam_cfg, namcfg, IOSTAT = ios, ERR = 904 )
  206. 904 IF( ios /= 0 ) CALL ctl_nam ( ios , 'namcfg in configuration namelist', .TRUE. )
  207. ! Force values for AGRIF zoom (cf. agrif_user.F90)
  208. #if defined key_agrif
  209. IF( .NOT. Agrif_Root() ) THEN
  210. jpiglo = nbcellsx + 2 + 2*nbghostcells
  211. jpjglo = nbcellsy + 2 + 2*nbghostcells
  212. jpi = ( jpiglo-2*jpreci + (jpni-1+0) ) / jpni + 2*jpreci
  213. jpj = ( jpjglo-2*jprecj + (jpnj-1+0) ) / jpnj + 2*jprecj
  214. jpidta = jpiglo
  215. jpjdta = jpjglo
  216. jpizoom = 1
  217. jpjzoom = 1
  218. nperio = 0
  219. jperio = 0
  220. ln_use_jattr = .false.
  221. ENDIF
  222. #endif
  223. !
  224. ! !--------------------------------------------!
  225. ! ! set communicator & select the local node !
  226. ! ! NB: mynode also opens output.namelist.dyn !
  227. ! ! on unit number numond on first proc !
  228. ! !--------------------------------------------!
  229. #if defined key_iomput
  230. IF( Agrif_Root() ) THEN
  231. IF( lk_oasis ) THEN
  232. CALL cpl_init( "sas", ilocal_comm ) ! nemo local communicator given by oasis
  233. CALL xios_initialize( "not used",local_comm=ilocal_comm ) ! send nemo communicator to xios
  234. ELSE
  235. CALL xios_initialize( "for_xios_mpi_id",return_comm=ilocal_comm ) ! nemo local communicator given by xios
  236. ENDIF
  237. ENDIF
  238. narea = mynode ( cltxt, clname, numnam_ref, numnam_cfg, numond , nstop, ilocal_comm ) ! Nodes selection
  239. #else
  240. IF( lk_oasis ) THEN
  241. IF( Agrif_Root() ) THEN
  242. CALL cpl_init( "sas", ilocal_comm ) ! nemo local communicator given by oasis
  243. ENDIF
  244. narea = mynode( cltxt, clname, numnam_ref, numnam_cfg, numond , nstop, ilocal_comm ) ! Nodes selection (control print return in cltxt)
  245. ELSE
  246. ilocal_comm = 0
  247. narea = mynode( cltxt, clname, numnam_ref, numnam_cfg, numond , nstop ) ! Nodes selection (control print return in cltxt)
  248. ENDIF
  249. #endif
  250. narea = narea + 1 ! mynode return the rank of proc (0 --> jpnij -1 )
  251. lwm = (narea == 1) ! control of output namelists
  252. lwp = (narea == 1) .OR. ln_ctl ! control of all listing output print
  253. IF(lwm) THEN
  254. ! write merged namelists from earlier to output namelist now that the
  255. ! file has been opened in call to mynode. nammpp has already been
  256. ! written in mynode (if lk_mpp_mpi)
  257. WRITE( numond, namctl )
  258. WRITE( numond, namcfg )
  259. ENDIF
  260. ! If dimensions of processor grid weren't specified in the namelist file
  261. ! then we calculate them here now that we have our communicator size
  262. IF( (jpni < 1) .OR. (jpnj < 1) )THEN
  263. #if defined key_mpp_mpi
  264. IF( Agrif_Root() ) CALL nemo_partition(mppsize)
  265. #else
  266. jpni = 1
  267. jpnj = 1
  268. jpnij = jpni*jpnj
  269. #endif
  270. END IF
  271. ! Calculate domain dimensions given calculated jpni and jpnj
  272. ! This used to be done in par_oce.F90 when they were parameters rather
  273. ! than variables
  274. IF( Agrif_Root() ) THEN
  275. #if defined key_nemocice_decomp
  276. jpi = ( nx_global+2-2*jpreci + (jpni-1) ) / jpni + 2*jpreci ! first dim.
  277. jpj = ( ny_global+2-2*jprecj + (jpnj-1) ) / jpnj + 2*jprecj ! second dim.
  278. #else
  279. jpi = ( jpiglo-2*jpreci + (jpni-1) ) / jpni + 2*jpreci ! first dim.
  280. jpj = ( jpjglo-2*jprecj + (jpnj-1) ) / jpnj + 2*jprecj ! second dim.
  281. #endif
  282. ENDIF
  283. jpk = jpkdta ! third dim
  284. jpim1 = jpi-1 ! inner domain indices
  285. jpjm1 = jpj-1 ! " "
  286. jpkm1 = jpk-1 ! " "
  287. jpij = jpi*jpj ! jpi x j
  288. IF(lwp) THEN ! open listing units
  289. !
  290. IF( lk_oasis ) THEN
  291. CALL ctl_opn( numout, 'sas.output', 'REPLACE', 'FORMATTED', 'SEQUENTIAL', -1, 6, .FALSE., narea )
  292. ELSE
  293. CALL ctl_opn( numout, 'ocean.output', 'REPLACE', 'FORMATTED', 'SEQUENTIAL', -1, 6, .FALSE., narea )
  294. ENDIF
  295. !
  296. WRITE(numout,*)
  297. WRITE(numout,*) ' CNRS - NERC - Met OFFICE - MERCATOR-ocean - INGV - CMCC'
  298. WRITE(numout,*) ' NEMO team'
  299. WRITE(numout,*) ' Ocean General Circulation Model'
  300. WRITE(numout,*) ' version 3.6 (2015) '
  301. WRITE(numout,*) ' StandAlone Surface version (SAS) '
  302. WRITE(numout,*)
  303. WRITE(numout,*)
  304. DO ji = 1, SIZE(cltxt)
  305. IF( TRIM(cltxt(ji)) /= '' ) WRITE(numout,*) cltxt(ji) ! control print of mynode
  306. END DO
  307. WRITE(numout,cform_aaa) ! Flag AAAAAAA
  308. !
  309. ENDIF
  310. ! Now we know the dimensions of the grid and numout has been set we can
  311. ! allocate arrays
  312. CALL nemo_alloc()
  313. ! !-------------------------------!
  314. ! ! NEMO general initialization !
  315. ! !-------------------------------!
  316. CALL nemo_ctl ! Control prints & Benchmark
  317. ! ! Domain decomposition
  318. IF( jpni*jpnj == jpnij ) THEN ; CALL mpp_init ! standard cutting out
  319. ELSE ; CALL mpp_init2 ! eliminate land processors
  320. ENDIF
  321. !
  322. IF( nn_timing == 1 ) CALL timing_init
  323. !
  324. ! ! General initialization
  325. CALL phy_cst ! Physical constants
  326. CALL eos_init ! Equation of state
  327. CALL dom_cfg ! Domain configuration
  328. CALL dom_init ! Domain
  329. IF( ln_nnogather ) CALL nemo_northcomms ! Initialise the northfold neighbour lists (must be done after the masks are defined)
  330. IF( ln_ctl ) CALL prt_ctl_init ! Print control
  331. CALL day_init ! model calendar (using both namelist and restart infos)
  332. IF( ln_rstart ) CALL rst_read_open
  333. CALL sbc_init ! Forcings : surface module
  334. ! ==> clem: open boundaries init. is mandatory for LIM3 because ice BDY is not decoupled from
  335. ! the environment of ocean BDY. Therefore bdy is called in both OPA and SAS modules.
  336. ! This is not clean and should be changed in the future.
  337. #if defined key_bdy
  338. IF( lk_bdy ) CALL bdy_init
  339. IF( lk_bdy ) CALL bdy_dta_init
  340. ! ==>
  341. #endif
  342. IF(lwp) WRITE(numout,*) 'Euler time step switch is ', neuler
  343. !
  344. END SUBROUTINE nemo_init
  345. SUBROUTINE nemo_ctl
  346. !!----------------------------------------------------------------------
  347. !! *** ROUTINE nemo_ctl ***
  348. !!
  349. !! ** Purpose : control print setting
  350. !!
  351. !! ** Method : - print namctl information and check some consistencies
  352. !!----------------------------------------------------------------------
  353. !
  354. IF(lwp) THEN ! control print
  355. WRITE(numout,*)
  356. WRITE(numout,*) 'nemo_ctl: Control prints & Benchmark'
  357. WRITE(numout,*) '~~~~~~~ '
  358. WRITE(numout,*) ' Namelist namctl'
  359. WRITE(numout,*) ' run control (for debugging) ln_ctl = ', ln_ctl
  360. WRITE(numout,*) ' level of print nn_print = ', nn_print
  361. WRITE(numout,*) ' Start i indice for SUM control nn_ictls = ', nn_ictls
  362. WRITE(numout,*) ' End i indice for SUM control nn_ictle = ', nn_ictle
  363. WRITE(numout,*) ' Start j indice for SUM control nn_jctls = ', nn_jctls
  364. WRITE(numout,*) ' End j indice for SUM control nn_jctle = ', nn_jctle
  365. WRITE(numout,*) ' number of proc. following i nn_isplt = ', nn_isplt
  366. WRITE(numout,*) ' number of proc. following j nn_jsplt = ', nn_jsplt
  367. WRITE(numout,*) ' benchmark parameter (0/1) nn_bench = ', nn_bench
  368. ENDIF
  369. !
  370. nprint = nn_print ! convert DOCTOR namelist names into OLD names
  371. nictls = nn_ictls
  372. nictle = nn_ictle
  373. njctls = nn_jctls
  374. njctle = nn_jctle
  375. isplt = nn_isplt
  376. jsplt = nn_jsplt
  377. nbench = nn_bench
  378. IF(lwp) THEN ! control print
  379. WRITE(numout,*)
  380. WRITE(numout,*) 'namcfg : configuration initialization through namelist read'
  381. WRITE(numout,*) '~~~~~~~ '
  382. WRITE(numout,*) ' Namelist namcfg'
  383. WRITE(numout,*) ' configuration name cp_cfg = ', TRIM(cp_cfg)
  384. WRITE(numout,*) ' configuration zoom name cp_cfz = ', TRIM(cp_cfz)
  385. WRITE(numout,*) ' configuration resolution jp_cfg = ', jp_cfg
  386. WRITE(numout,*) ' 1st lateral dimension ( >= jpi ) jpidta = ', jpidta
  387. WRITE(numout,*) ' 2nd " " ( >= jpj ) jpjdta = ', jpjdta
  388. WRITE(numout,*) ' 3nd " " jpkdta = ', jpkdta
  389. WRITE(numout,*) ' 1st dimension of global domain in i jpiglo = ', jpiglo
  390. WRITE(numout,*) ' 2nd - - in j jpjglo = ', jpjglo
  391. WRITE(numout,*) ' left bottom i index of the zoom (in data domain) jpizoom = ', jpizoom
  392. WRITE(numout,*) ' left bottom j index of the zoom (in data domain) jpizoom = ', jpjzoom
  393. WRITE(numout,*) ' lateral cond. type (between 0 and 6) jperio = ', jperio
  394. WRITE(numout,*) ' use file attribute if exists as i/p j-start ln_use_jattr = ', ln_use_jattr
  395. ENDIF
  396. ! ! Parameter control
  397. !
  398. IF( ln_ctl ) THEN ! sub-domain area indices for the control prints
  399. IF( lk_mpp .AND. jpnij > 1 ) THEN
  400. isplt = jpni ; jsplt = jpnj ; ijsplt = jpni*jpnj ! the domain is forced to the real split domain
  401. ELSE
  402. IF( isplt == 1 .AND. jsplt == 1 ) THEN
  403. CALL ctl_warn( ' - isplt & jsplt are equal to 1', &
  404. & ' - the print control will be done over the whole domain' )
  405. ENDIF
  406. ijsplt = isplt * jsplt ! total number of processors ijsplt
  407. ENDIF
  408. IF(lwp) WRITE(numout,*)' - The total number of processors over which the'
  409. IF(lwp) WRITE(numout,*)' print control will be done is ijsplt : ', ijsplt
  410. !
  411. ! ! indices used for the SUM control
  412. IF( nictls+nictle+njctls+njctle == 0 ) THEN ! print control done over the default area
  413. lsp_area = .FALSE.
  414. ELSE ! print control done over a specific area
  415. lsp_area = .TRUE.
  416. IF( nictls < 1 .OR. nictls > jpiglo ) THEN
  417. CALL ctl_warn( ' - nictls must be 1<=nictls>=jpiglo, it is forced to 1' )
  418. nictls = 1
  419. ENDIF
  420. IF( nictle < 1 .OR. nictle > jpiglo ) THEN
  421. CALL ctl_warn( ' - nictle must be 1<=nictle>=jpiglo, it is forced to jpiglo' )
  422. nictle = jpiglo
  423. ENDIF
  424. IF( njctls < 1 .OR. njctls > jpjglo ) THEN
  425. CALL ctl_warn( ' - njctls must be 1<=njctls>=jpjglo, it is forced to 1' )
  426. njctls = 1
  427. ENDIF
  428. IF( njctle < 1 .OR. njctle > jpjglo ) THEN
  429. CALL ctl_warn( ' - njctle must be 1<=njctle>=jpjglo, it is forced to jpjglo' )
  430. njctle = jpjglo
  431. ENDIF
  432. ENDIF
  433. ENDIF
  434. !
  435. IF( nbench == 1 ) THEN ! Benchmark
  436. SELECT CASE ( cp_cfg )
  437. CASE ( 'gyre' ) ; CALL ctl_warn( ' The Benchmark is activated ' )
  438. CASE DEFAULT ; CALL ctl_stop( ' The Benchmark is based on the GYRE configuration:', &
  439. & ' cp_cfg="gyre" in namelist &namcfg or set nbench = 0' )
  440. END SELECT
  441. ENDIF
  442. !
  443. IF( 1_wp /= SIGN(1._wp,-0._wp) ) CALL ctl_stop( 'nemo_ctl: The intrinsec SIGN function follows ', &
  444. & 'f2003 standard. ' , &
  445. & 'Compile with key_nosignedzero enabled' )
  446. !
  447. END SUBROUTINE nemo_ctl
  448. SUBROUTINE nemo_closefile
  449. !!----------------------------------------------------------------------
  450. !! *** ROUTINE nemo_closefile ***
  451. !!
  452. !! ** Purpose : Close the files
  453. !!----------------------------------------------------------------------
  454. !
  455. IF( lk_mpp ) CALL mppsync
  456. !
  457. CALL iom_close ! close all input/output files managed by iom_*
  458. !
  459. IF( numstp /= -1 ) CLOSE( numstp ) ! time-step file
  460. IF( numnam_ref /= -1 ) CLOSE( numnam_ref ) ! oce reference namelist
  461. IF( numnam_cfg /= -1 ) CLOSE( numnam_cfg ) ! oce configuration namelist
  462. IF( lwm.AND.numond /= -1 ) CLOSE( numond ) ! oce output namelist
  463. IF( numnam_ice_ref /= -1 ) CLOSE( numnam_ice_ref ) ! ice reference namelist
  464. IF( numnam_ice_cfg /= -1 ) CLOSE( numnam_ice_cfg ) ! ice configuration namelist
  465. IF( lwm.AND.numoni /= -1 ) CLOSE( numoni ) ! ice output namelist
  466. IF( numevo_ice /= -1 ) CLOSE( numevo_ice ) ! ice variables (temp. evolution)
  467. IF( numout /= 6 ) CLOSE( numout ) ! standard model output file
  468. !
  469. numout = 6 ! redefine numout in case it is used after this point...
  470. !
  471. END SUBROUTINE nemo_closefile
  472. SUBROUTINE nemo_alloc
  473. !!----------------------------------------------------------------------
  474. !! *** ROUTINE nemo_alloc ***
  475. !!
  476. !! ** Purpose : Allocate all the dynamic arrays of the OPA modules
  477. !!
  478. !! ** Method :
  479. !!----------------------------------------------------------------------
  480. USE diawri , ONLY: dia_wri_alloc
  481. USE dom_oce , ONLY: dom_oce_alloc
  482. #if defined key_bdy
  483. USE bdy_oce , ONLY: bdy_oce_alloc
  484. USE oce ! clem: mandatory for LIM3 because needed for bdy arrays
  485. #else
  486. USE oce , ONLY : sshn, sshb, snwice_mass, snwice_mass_b, snwice_fmass
  487. #endif
  488. !
  489. INTEGER :: ierr,ierr1,ierr2,ierr3,ierr4,ierr5,ierr6,ierr7,ierr8
  490. INTEGER :: jpm
  491. !!----------------------------------------------------------------------
  492. !
  493. ierr = dia_wri_alloc ()
  494. ierr = ierr + dom_oce_alloc () ! ocean domain
  495. #if defined key_bdy
  496. ierr = ierr + bdy_oce_alloc () ! bdy masks (incl. initialization)
  497. ierr = ierr + oce_alloc () ! (tsn...)
  498. #endif
  499. #if ! defined key_bdy
  500. ALLOCATE( snwice_mass(jpi,jpj) , snwice_mass_b(jpi,jpj), &
  501. & snwice_fmass(jpi,jpj) , STAT= ierr1 )
  502. !
  503. ! lim code currently uses surface temperature and salinity in tsn array for initialisation
  504. ! and ub, vb arrays in ice dynamics, so allocate enough of arrays to use
  505. ! clem: should not be needed. To be checked out
  506. jpm = MAX(jp_tem, jp_sal)
  507. ALLOCATE( tsn(jpi,jpj,1,jpm) , STAT=ierr2 )
  508. ALLOCATE( ub(jpi,jpj,1) , STAT=ierr3 )
  509. ALLOCATE( vb(jpi,jpj,1) , STAT=ierr4 )
  510. ALLOCATE( tsb(jpi,jpj,1,jpm) , STAT=ierr5 )
  511. ALLOCATE( sshn(jpi,jpj) , STAT=ierr6 )
  512. ALLOCATE( un(jpi,jpj,1) , STAT=ierr7 )
  513. ALLOCATE( vn(jpi,jpj,1) , STAT=ierr8 )
  514. ierr = ierr + ierr1 + ierr2 + ierr3 + ierr4 + ierr5 + ierr6 + ierr7 + ierr8
  515. #endif
  516. !
  517. IF( lk_mpp ) CALL mpp_sum( ierr )
  518. IF( ierr /= 0 ) CALL ctl_stop( 'STOP', 'nemo_alloc : unable to allocate standard ocean arrays' )
  519. !
  520. END SUBROUTINE nemo_alloc
  521. SUBROUTINE nemo_partition( num_pes )
  522. !!----------------------------------------------------------------------
  523. !! *** ROUTINE nemo_partition ***
  524. !!
  525. !! ** Purpose :
  526. !!
  527. !! ** Method :
  528. !!----------------------------------------------------------------------
  529. INTEGER, INTENT(in) :: num_pes ! The number of MPI processes we have
  530. !
  531. INTEGER, PARAMETER :: nfactmax = 20
  532. INTEGER :: nfact ! The no. of factors returned
  533. INTEGER :: ierr ! Error flag
  534. INTEGER :: ji
  535. INTEGER :: idiff, mindiff, imin ! For choosing pair of factors that are closest in value
  536. INTEGER, DIMENSION(nfactmax) :: ifact ! Array of factors
  537. !!----------------------------------------------------------------------
  538. !
  539. ierr = 0
  540. !
  541. CALL factorise( ifact, nfactmax, nfact, num_pes, ierr )
  542. !
  543. IF( nfact <= 1 ) THEN
  544. WRITE (numout, *) 'WARNING: factorisation of number of PEs failed'
  545. WRITE (numout, *) ' : using grid of ',num_pes,' x 1'
  546. jpnj = 1
  547. jpni = num_pes
  548. ELSE
  549. ! Search through factors for the pair that are closest in value
  550. mindiff = 1000000
  551. imin = 1
  552. DO ji = 1, nfact-1, 2
  553. idiff = ABS( ifact(ji) - ifact(ji+1) )
  554. IF( idiff < mindiff ) THEN
  555. mindiff = idiff
  556. imin = ji
  557. ENDIF
  558. END DO
  559. jpnj = ifact(imin)
  560. jpni = ifact(imin + 1)
  561. ENDIF
  562. !
  563. jpnij = jpni*jpnj
  564. !
  565. END SUBROUTINE nemo_partition
  566. SUBROUTINE factorise( kfax, kmaxfax, knfax, kn, kerr )
  567. !!----------------------------------------------------------------------
  568. !! *** ROUTINE factorise ***
  569. !!
  570. !! ** Purpose : return the prime factors of n.
  571. !! knfax factors are returned in array kfax which is of
  572. !! maximum dimension kmaxfax.
  573. !! ** Method :
  574. !!----------------------------------------------------------------------
  575. INTEGER , INTENT(in ) :: kn, kmaxfax
  576. INTEGER , INTENT( out) :: kerr, knfax
  577. INTEGER, DIMENSION(kmaxfax), INTENT( out) :: kfax
  578. !
  579. INTEGER :: ifac, jl, inu
  580. INTEGER, PARAMETER :: ntest = 14
  581. INTEGER :: ilfax(ntest)
  582. !
  583. ! lfax contains the set of allowed factors.
  584. ilfax(:) = (/(2**jl,jl=ntest,1,-1)/)
  585. ! Clear the error flag and initialise output vars
  586. kerr = 0
  587. kfax = 1
  588. knfax = 0
  589. ! Find the factors of n.
  590. IF( kn == 1 ) GOTO 20
  591. ! nu holds the unfactorised part of the number.
  592. ! knfax holds the number of factors found.
  593. ! l points to the allowed factor list.
  594. ! ifac holds the current factor.
  595. inu = kn
  596. knfax = 0
  597. DO jl = ntest, 1, -1
  598. !
  599. ifac = ilfax(jl)
  600. IF( ifac > inu ) CYCLE
  601. ! Test whether the factor will divide.
  602. IF( MOD(inu,ifac) == 0 ) THEN
  603. !
  604. knfax = knfax + 1 ! Add the factor to the list
  605. IF( knfax > kmaxfax ) THEN
  606. kerr = 6
  607. write (*,*) 'FACTOR: insufficient space in factor array ', knfax
  608. return
  609. ENDIF
  610. kfax(knfax) = ifac
  611. ! Store the other factor that goes with this one
  612. knfax = knfax + 1
  613. kfax(knfax) = inu / ifac
  614. !WRITE (*,*) 'ARPDBG, factors ',knfax-1,' & ',knfax,' are ', kfax(knfax-1),' and ',kfax(knfax)
  615. ENDIF
  616. !
  617. END DO
  618. 20 CONTINUE ! Label 20 is the exit point from the factor search loop.
  619. !
  620. END SUBROUTINE factorise
  621. #if defined key_mpp_mpi
  622. SUBROUTINE nemo_northcomms
  623. !!======================================================================
  624. !! *** ROUTINE nemo_northcomms ***
  625. !! nemo_northcomms : Setup for north fold exchanges with explicit
  626. !! point-to-point messaging
  627. !!=====================================================================
  628. !!----------------------------------------------------------------------
  629. !!
  630. !! ** Purpose : Initialization of the northern neighbours lists.
  631. !!----------------------------------------------------------------------
  632. !! 1.0 ! 2011-10 (A. C. Coward, NOCS & J. Donners, PRACE)
  633. !! 2.0 ! 2013-06 Setup avoiding MPI communication (I. Epicoco, S. Mocavero, CMCC)
  634. !!----------------------------------------------------------------------
  635. INTEGER :: sxM, dxM, sxT, dxT, jn
  636. INTEGER :: njmppmax
  637. njmppmax = MAXVAL( njmppt )
  638. !initializes the north-fold communication variables
  639. isendto(:) = 0
  640. nsndto = 0
  641. !if I am a process in the north
  642. IF ( njmpp == njmppmax ) THEN
  643. !sxM is the first point (in the global domain) needed to compute the
  644. !north-fold for the current process
  645. sxM = jpiglo - nimppt(narea) - nlcit(narea) + 1
  646. !dxM is the last point (in the global domain) needed to compute the
  647. !north-fold for the current process
  648. dxM = jpiglo - nimppt(narea) + 2
  649. !loop over the other north-fold processes to find the processes
  650. !managing the points belonging to the sxT-dxT range
  651. DO jn = 1, jpni
  652. !sxT is the first point (in the global domain) of the jn
  653. !process
  654. sxT = nfiimpp(jn, jpnj)
  655. !dxT is the last point (in the global domain) of the jn
  656. !process
  657. dxT = nfiimpp(jn, jpnj) + nfilcit(jn, jpnj) - 1
  658. IF ((sxM .gt. sxT) .AND. (sxM .lt. dxT)) THEN
  659. nsndto = nsndto + 1
  660. isendto(nsndto) = jn
  661. ELSEIF ((sxM .le. sxT) .AND. (dxM .ge. dxT)) THEN
  662. nsndto = nsndto + 1
  663. isendto(nsndto) = jn
  664. ELSEIF ((dxM .lt. dxT) .AND. (sxT .lt. dxM)) THEN
  665. nsndto = nsndto + 1
  666. isendto(nsndto) = jn
  667. END IF
  668. END DO
  669. nfsloop = 1
  670. nfeloop = nlci
  671. DO jn = 2,jpni-1
  672. IF(nfipproc(jn,jpnj) .eq. (narea - 1)) THEN
  673. IF (nfipproc(jn - 1 ,jpnj) .eq. -1) THEN
  674. nfsloop = nldi
  675. ENDIF
  676. IF (nfipproc(jn + 1,jpnj) .eq. -1) THEN
  677. nfeloop = nlei
  678. ENDIF
  679. ENDIF
  680. END DO
  681. ENDIF
  682. l_north_nogather = .TRUE.
  683. END SUBROUTINE nemo_northcomms
  684. #else
  685. SUBROUTINE nemo_northcomms ! Dummy routine
  686. WRITE(*,*) 'nemo_northcomms: You should not have seen this print! error?'
  687. END SUBROUTINE nemo_northcomms
  688. #endif
  689. !!======================================================================
  690. END MODULE nemogcm