nemogcm.F90 32 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702
  1. MODULE nemogcm
  2. !!======================================================================
  3. !! *** MODULE nemogcm ***
  4. !! Off-line Ocean : passive tracer evolution, dynamics read in files
  5. !!======================================================================
  6. !! History : 3.3 ! 2010-05 (C. Ethe) Full reorganization of the off-line: phasing with the on-line
  7. !! 4.0 ! 2011-01 (C. Ethe, A. R. Porter, STFC Daresbury) dynamical allocation
  8. !!----------------------------------------------------------------------
  9. !!----------------------------------------------------------------------
  10. !! nemo_gcm : off-line: solve ocean tracer only
  11. !! nemo_init : initialization of the nemo model
  12. !! nemo_ctl : initialisation of algorithm flag
  13. !! nemo_closefile : close remaining files
  14. !!----------------------------------------------------------------------
  15. USE dom_oce ! ocean space domain variables
  16. USE oce ! dynamics and tracers variables
  17. USE c1d ! 1D configuration
  18. USE domcfg ! domain configuration (dom_cfg routine)
  19. USE domain ! domain initialization from coordinate & bathymetry (dom_init routine)
  20. USE domrea ! domain initialization from mesh_mask (dom_init routine)
  21. USE eosbn2 ! equation of state (eos bn2 routine)
  22. ! ! ocean physics
  23. USE ldftra ! lateral diffusivity setting (ldf_tra_init routine)
  24. USE ldfslp ! slopes of neutral surfaces (ldf_slp_init routine)
  25. USE traqsr ! solar radiation penetration (tra_qsr_init routine)
  26. USE trabbl ! bottom boundary layer (tra_bbl_init routine)
  27. USE zdfini ! vertical physics: initialization
  28. USE sbcmod ! surface boundary condition (sbc_init routine)
  29. USE phycst ! physical constant (par_cst routine)
  30. USE dtadyn ! Lecture and Interpolation of the dynamical fields
  31. USE trcini ! Initilization of the passive tracers
  32. USE daymod ! calendar (day routine)
  33. USE trcstp ! passive tracer time-stepping (trc_stp routine)
  34. USE dtadyn ! Lecture and interpolation of the dynamical fields
  35. ! ! I/O & MPP
  36. USE iom ! I/O library
  37. USE in_out_manager ! I/O manager
  38. USE mppini ! shared/distributed memory setting (mpp_init routine)
  39. USE lib_mpp ! distributed memory computing
  40. #if defined key_iomput
  41. USE xios
  42. #endif
  43. USE prtctl ! Print control (prt_ctl_init routine)
  44. USE timing ! Timing
  45. USE lib_fortran ! Fortran utilities (allows no signed zero when 'key_nosignedzero' defined)
  46. USE lbcnfd, ONLY: isendto, nsndto, nfsloop, nfeloop ! Setup of north fold exchanges
  47. USE trc
  48. USE trcnam
  49. USE trcrst
  50. IMPLICIT NONE
  51. PRIVATE
  52. PUBLIC nemo_gcm ! called by nemo.F90
  53. CHARACTER (len=64) :: cform_aaa="( /, 'AAAAAAAA', / ) " ! flag for output listing
  54. !!----------------------------------------------------------------------
  55. !! NEMO/OFF 3.3 , NEMO Consortium (2010)
  56. !! $Id: nemogcm.F90 3977 2017-02-20 14:03:23Z ufla $
  57. !! Software governed by the CeCILL licence (NEMOGCM/NEMO_CeCILL.txt)
  58. !!----------------------------------------------------------------------
  59. CONTAINS
  60. SUBROUTINE nemo_gcm
  61. !!----------------------------------------------------------------------
  62. !! *** ROUTINE nemo_gcm ***
  63. !!
  64. !! ** Purpose : nemo solves the primitive equations on an orthogonal
  65. !! curvilinear mesh on the sphere.
  66. !!
  67. !! ** Method : - model general initialization
  68. !! - launch the time-stepping (dta_dyn and trc_stp)
  69. !! - finalize the run by closing files and communications
  70. !!
  71. !! References : Madec, Delecluse,Imbard, and Levy, 1997: internal report, IPSL.
  72. !! Madec, 2008, internal report, IPSL.
  73. !!----------------------------------------------------------------------
  74. INTEGER :: istp, indic ! time step index
  75. !!----------------------------------------------------------------------
  76. CALL nemo_init ! Initializations
  77. ! check that all process are still there... If some process have an error,
  78. ! they will never enter in step and other processes will wait until the end of the cpu time!
  79. IF( lk_mpp ) CALL mpp_max( nstop )
  80. ! !-----------------------!
  81. ! !== time stepping ==!
  82. ! !-----------------------!
  83. istp = nit000
  84. !
  85. DO WHILE ( istp <= nitend .AND. nstop == 0 ) ! time stepping
  86. !
  87. IF( istp == nit000 ) CALL iom_init( cxios_context ) ! iom_put initialization
  88. IF( istp /= nit000 ) CALL day ( istp ) ! Calendar (day was already called at nit000 in day_init)
  89. CALL iom_setkt ( istp - nit000 + 1, cxios_context ) ! say to iom that we are at time step kstp
  90. CALL trc_rst_opn( istp ) ! Open tracer ! restart file
  91. CALL dta_dyn ( istp ) ! Interpolation of the dynamical fields
  92. CALL trc_stp ( istp ) ! time-stepping
  93. IF( lk_vvl ) CALL dta_dyn_swp( istp ) ! swap of sea surface height and vertical scale factors
  94. CALL stp_ctl ( istp, indic ) ! Time loop: control and print
  95. istp = istp + 1
  96. IF( lk_mpp ) CALL mpp_max( nstop )
  97. END DO
  98. #if defined key_iomput
  99. CALL iom_context_finalize( cxios_context ) ! needed for XIOS+AGRIF
  100. #endif
  101. ! !------------------------!
  102. ! !== finalize the run ==!
  103. ! !------------------------!
  104. IF(lwp) WRITE(numout,cform_aaa) ! Flag AAAAAAA
  105. IF( nstop /= 0 .AND. lwp ) THEN ! error print
  106. WRITE(numout,cform_err)
  107. WRITE(numout,*) nstop, ' error have been found'
  108. ENDIF
  109. !
  110. IF( nn_timing == 1 ) CALL timing_finalize
  111. !
  112. CALL nemo_closefile
  113. !
  114. # if defined key_iomput
  115. CALL xios_finalize ! end mpp communications
  116. # else
  117. IF( lk_mpp ) CALL mppstop ! end mpp communications
  118. # endif
  119. !
  120. END SUBROUTINE nemo_gcm
  121. SUBROUTINE nemo_init
  122. !!----------------------------------------------------------------------
  123. !! *** ROUTINE nemo_init ***
  124. !!
  125. !! ** Purpose : initialization of the nemo model in off-line mode
  126. !!----------------------------------------------------------------------
  127. INTEGER :: ji ! dummy loop indices
  128. INTEGER :: ilocal_comm ! local integer
  129. INTEGER :: ios
  130. LOGICAL :: llexist
  131. CHARACTER(len=80), DIMENSION(16) :: cltxt
  132. !!
  133. NAMELIST/namctl/ ln_ctl , nn_print, nn_ictls, nn_ictle, &
  134. & nn_isplt, nn_jsplt, nn_jctls, nn_jctle, &
  135. & nn_bench, nn_timing
  136. NAMELIST/namcfg/ cp_cfg, cp_cfz, jp_cfg, jpidta, jpjdta, jpkdta, jpiglo, jpjglo, &
  137. & jpizoom, jpjzoom, jperio, ln_use_jattr
  138. !!----------------------------------------------------------------------
  139. cltxt = ''
  140. cxios_context = 'nemo'
  141. !
  142. ! ! Open reference namelist and configuration namelist files
  143. CALL ctl_opn( numnam_ref, 'namelist_ref', 'OLD', 'FORMATTED', 'SEQUENTIAL', -1, 6, .FALSE. )
  144. CALL ctl_opn( numnam_cfg, 'namelist_cfg', 'OLD', 'FORMATTED', 'SEQUENTIAL', -1, 6, .FALSE. )
  145. !
  146. REWIND( numnam_ref ) ! Namelist namctl in reference namelist : Control prints & Benchmark
  147. READ ( numnam_ref, namctl, IOSTAT = ios, ERR = 901 )
  148. 901 IF( ios /= 0 ) CALL ctl_nam ( ios , 'namctl in reference namelist', .TRUE. )
  149. REWIND( numnam_cfg ) ! Namelist namctl in confguration namelist : Control prints & Benchmark
  150. READ ( numnam_cfg, namctl, IOSTAT = ios, ERR = 902 )
  151. 902 IF( ios /= 0 ) CALL ctl_nam ( ios , 'namctl in configuration namelist', .TRUE. )
  152. !
  153. REWIND( numnam_ref ) ! Namelist namcfg in reference namelist : Control prints & Benchmark
  154. READ ( numnam_ref, namcfg, IOSTAT = ios, ERR = 903 )
  155. 903 IF( ios /= 0 ) CALL ctl_nam ( ios , 'namcfg in reference namelist', .TRUE. )
  156. REWIND( numnam_cfg ) ! Namelist namcfg in confguration namelist : Control prints & Benchmark
  157. READ ( numnam_cfg, namcfg, IOSTAT = ios, ERR = 904 )
  158. 904 IF( ios /= 0 ) CALL ctl_nam ( ios , 'namcfg in configuration namelist', .TRUE. )
  159. !
  160. ! !--------------------------------------------!
  161. ! ! set communicator & select the local node !
  162. ! ! NB: mynode also opens output.namelist.dyn !
  163. ! ! on unit number numond on first proc !
  164. ! !--------------------------------------------!
  165. #if defined key_iomput
  166. CALL xios_initialize( "for_xios_mpi_id",return_comm=ilocal_comm )
  167. narea = mynode( cltxt, 'output.namelist.dyn', numnam_ref, numnam_cfg, numond , nstop, ilocal_comm ) ! Nodes selection
  168. #else
  169. ilocal_comm = 0
  170. narea = mynode( cltxt, 'output.namelist.dyn', numnam_ref, numnam_cfg, numond , nstop ) ! Nodes selection (control print return in cltxt)
  171. #endif
  172. narea = narea + 1 ! mynode return the rank of proc (0 --> jpnij -1 )
  173. lwm = (narea == 1) ! control of output namelists
  174. lwp = (narea == 1) .OR. ln_ctl ! control of all listing output print
  175. IF(lwm) THEN
  176. ! write merged namelists from earlier to output namelist now that the
  177. ! file has been opened in call to mynode. nammpp has already been
  178. ! written in mynode (if lk_mpp_mpi)
  179. WRITE( numond, namctl )
  180. WRITE( numond, namcfg )
  181. ENDIF
  182. ! If dimensions of processor grid weren't specified in the namelist file
  183. ! then we calculate them here now that we have our communicator size
  184. IF( (jpni < 1) .OR. (jpnj < 1) )THEN
  185. #if defined key_mpp_mpi
  186. CALL nemo_partition(mppsize)
  187. #else
  188. jpni = 1
  189. jpnj = 1
  190. jpnij = jpni*jpnj
  191. #endif
  192. END IF
  193. ! Calculate domain dimensions given calculated jpni and jpnj
  194. ! This used to be done in par_oce.F90 when they were parameters rather
  195. ! than variables
  196. jpi = ( jpiglo-2*jpreci + (jpni-1) ) / jpni + 2*jpreci ! first dim.
  197. jpj = ( jpjglo-2*jprecj + (jpnj-1) ) / jpnj + 2*jprecj ! second dim.
  198. jpk = jpkdta ! third dim
  199. jpim1 = jpi-1 ! inner domain indices
  200. jpjm1 = jpj-1 ! " "
  201. jpkm1 = jpk-1 ! " "
  202. jpij = jpi*jpj ! jpi x j
  203. IF(lwp) THEN ! open listing units
  204. !
  205. CALL ctl_opn( numout, 'ocean.output', 'REPLACE', 'FORMATTED', 'SEQUENTIAL', -1, 6, .FALSE., narea )
  206. !
  207. WRITE(numout,*)
  208. WRITE(numout,*) ' CNRS - NERC - Met OFFICE - MERCATOR-ocean - INGV - CMCC'
  209. WRITE(numout,*) ' NEMO team'
  210. WRITE(numout,*) ' Ocean General Circulation Model'
  211. WRITE(numout,*) ' version 3.6 (2015) '
  212. WRITE(numout,*)
  213. WRITE(numout,*)
  214. DO ji = 1, SIZE(cltxt)
  215. IF( TRIM(cltxt(ji)) /= '' ) WRITE(numout,*) cltxt(ji) ! control print of mynode
  216. END DO
  217. WRITE(numout,cform_aaa) ! Flag AAAAAAA
  218. !
  219. ENDIF
  220. ! Now we know the dimensions of the grid and numout has been set we can
  221. ! allocate arrays
  222. CALL nemo_alloc()
  223. ! !--------------------------------!
  224. ! ! Model general initialization !
  225. ! !--------------------------------!
  226. CALL nemo_ctl ! Control prints & Benchmark
  227. ! ! Domain decomposition
  228. IF( jpni*jpnj == jpnij ) THEN ; CALL mpp_init ! standard cutting out
  229. ELSE ; CALL mpp_init2 ! eliminate land processors
  230. ENDIF
  231. !
  232. IF( nn_timing == 1 ) CALL timing_init
  233. !
  234. ! ! General initialization
  235. IF( nn_timing == 1 ) CALL timing_start( 'nemo_init')
  236. !
  237. CALL phy_cst ! Physical constants
  238. CALL eos_init ! Equation of state
  239. IF( lk_c1d ) CALL c1d_init ! 1D column configuration
  240. CALL dom_cfg ! Domain configuration
  241. !
  242. !
  243. INQUIRE( FILE='coordinates.nc', EXIST = llexist ) ! Check if coordinate file exist
  244. !
  245. IF( llexist ) THEN ; CALL dom_init ! compute the grid from coordinates and bathymetry
  246. ELSE ; CALL dom_rea ! read grid from the meskmask
  247. ENDIF
  248. CALL istate_init ! ocean initial state (Dynamics and tracers)
  249. IF( ln_nnogather ) CALL nemo_northcomms ! Initialise the northfold neighbour lists (must be done after the masks are defined)
  250. IF( ln_ctl ) CALL prt_ctl_init ! Print control
  251. CALL sbc_init ! Forcings : surface module
  252. #if ! defined key_degrad
  253. CALL ldf_tra_init ! Lateral ocean tracer physics
  254. #endif
  255. IF( lk_ldfslp ) CALL ldf_slp_init ! slope of lateral mixing
  256. CALL tra_qsr_init ! penetrative solar radiation qsr
  257. IF( lk_trabbl ) CALL tra_bbl_init ! advective (and/or diffusive) bottom boundary layer scheme
  258. CALL trc_nam_run ! Needed to get restart parameters for passive tracers
  259. CALL trc_rst_cal( nit000, 'READ' ) ! calendar
  260. CALL dta_dyn_init ! Initialization for the dynamics
  261. CALL trc_init ! Passive tracers initialization
  262. ! ! in various advection and diffusion routines
  263. IF(lwp) WRITE(numout,cform_aaa) ! Flag AAAAAAA
  264. !
  265. IF( nn_timing == 1 ) CALL timing_stop( 'nemo_init')
  266. !
  267. END SUBROUTINE nemo_init
  268. SUBROUTINE nemo_ctl
  269. !!----------------------------------------------------------------------
  270. !! *** ROUTINE nemo_ctl ***
  271. !!
  272. !! ** Purpose : control print setting
  273. !!
  274. !! ** Method : - print namctl information and check some consistencies
  275. !!----------------------------------------------------------------------
  276. !
  277. IF(lwp) THEN ! Parameter print
  278. WRITE(numout,*)
  279. WRITE(numout,*) 'nemo_flg: Control prints & Benchmark'
  280. WRITE(numout,*) '~~~~~~~ '
  281. WRITE(numout,*) ' Namelist namctl'
  282. WRITE(numout,*) ' run control (for debugging) ln_ctl = ', ln_ctl
  283. WRITE(numout,*) ' level of print nn_print = ', nn_print
  284. WRITE(numout,*) ' Start i indice for SUM control nn_ictls = ', nn_ictls
  285. WRITE(numout,*) ' End i indice for SUM control nn_ictle = ', nn_ictle
  286. WRITE(numout,*) ' Start j indice for SUM control nn_jctls = ', nn_jctls
  287. WRITE(numout,*) ' End j indice for SUM control nn_jctle = ', nn_jctle
  288. WRITE(numout,*) ' number of proc. following i nn_isplt = ', nn_isplt
  289. WRITE(numout,*) ' number of proc. following j nn_jsplt = ', nn_jsplt
  290. WRITE(numout,*) ' benchmark parameter (0/1) nn_bench = ', nn_bench
  291. ENDIF
  292. !
  293. nprint = nn_print ! convert DOCTOR namelist names into OLD names
  294. nictls = nn_ictls
  295. nictle = nn_ictle
  296. njctls = nn_jctls
  297. njctle = nn_jctle
  298. isplt = nn_isplt
  299. jsplt = nn_jsplt
  300. nbench = nn_bench
  301. IF(lwp) THEN ! control print
  302. WRITE(numout,*)
  303. WRITE(numout,*) 'namcfg : configuration initialization through namelist read'
  304. WRITE(numout,*) '~~~~~~~ '
  305. WRITE(numout,*) ' Namelist namcfg'
  306. WRITE(numout,*) ' configuration name cp_cfg = ', TRIM(cp_cfg)
  307. WRITE(numout,*) ' configuration resolution jp_cfg = ', jp_cfg
  308. WRITE(numout,*) ' 1st lateral dimension ( >= jpi ) jpidta = ', jpidta
  309. WRITE(numout,*) ' 2nd " " ( >= jpj ) jpjdta = ', jpjdta
  310. WRITE(numout,*) ' 3nd " " jpkdta = ', jpkdta
  311. WRITE(numout,*) ' 1st dimension of global domain in i jpiglo = ', jpiglo
  312. WRITE(numout,*) ' 2nd - - in j jpjglo = ', jpjglo
  313. WRITE(numout,*) ' left bottom i index of the zoom (in data domain) jpizoom = ', jpizoom
  314. WRITE(numout,*) ' left bottom j index of the zoom (in data domain) jpizoom = ', jpjzoom
  315. WRITE(numout,*) ' lateral cond. type (between 0 and 6) jperio = ', jperio
  316. WRITE(numout,*) ' use file attribute if exists as i/p j-start ln_use_jattr = ', ln_use_jattr
  317. ENDIF
  318. ! ! Parameter control
  319. !
  320. IF( ln_ctl ) THEN ! sub-domain area indices for the control prints
  321. IF( lk_mpp ) THEN
  322. isplt = jpni ; jsplt = jpnj ; ijsplt = jpni*jpnj ! the domain is forced to the real splitted domain
  323. ELSE
  324. IF( isplt == 1 .AND. jsplt == 1 ) THEN
  325. CALL ctl_warn( ' - isplt & jsplt are equal to 1', &
  326. & ' - the print control will be done over the whole domain' )
  327. ENDIF
  328. ijsplt = isplt * jsplt ! total number of processors ijsplt
  329. ENDIF
  330. IF(lwp) WRITE(numout,*)' - The total number of processors over which the'
  331. IF(lwp) WRITE(numout,*)' print control will be done is ijsplt : ', ijsplt
  332. !
  333. ! ! indices used for the SUM control
  334. IF( nictls+nictle+njctls+njctle == 0 ) THEN ! print control done over the default area
  335. lsp_area = .FALSE.
  336. ELSE ! print control done over a specific area
  337. lsp_area = .TRUE.
  338. IF( nictls < 1 .OR. nictls > jpiglo ) THEN
  339. CALL ctl_warn( ' - nictls must be 1<=nictls>=jpiglo, it is forced to 1' )
  340. nictls = 1
  341. ENDIF
  342. IF( nictle < 1 .OR. nictle > jpiglo ) THEN
  343. CALL ctl_warn( ' - nictle must be 1<=nictle>=jpiglo, it is forced to jpiglo' )
  344. nictle = jpiglo
  345. ENDIF
  346. IF( njctls < 1 .OR. njctls > jpjglo ) THEN
  347. CALL ctl_warn( ' - njctls must be 1<=njctls>=jpjglo, it is forced to 1' )
  348. njctls = 1
  349. ENDIF
  350. IF( njctle < 1 .OR. njctle > jpjglo ) THEN
  351. CALL ctl_warn( ' - njctle must be 1<=njctle>=jpjglo, it is forced to jpjglo' )
  352. njctle = jpjglo
  353. ENDIF
  354. ENDIF
  355. ENDIF
  356. !
  357. IF( nbench == 1 ) THEN ! Benchmark
  358. SELECT CASE ( cp_cfg )
  359. CASE ( 'gyre' ) ; CALL ctl_warn( ' The Benchmark is activated ' )
  360. CASE DEFAULT ; CALL ctl_stop( ' The Benchmark is based on the GYRE configuration:', &
  361. & ' cp_cfg="gyre" in namelsit &namcfg or set nbench = 0' )
  362. END SELECT
  363. ENDIF
  364. !
  365. IF( lk_c1d .AND. .NOT.lk_iomput ) CALL ctl_stop( 'nemo_ctl: The 1D configuration must be used ', &
  366. & 'with the IOM Input/Output manager. ' , &
  367. & 'Compile with key_iomput enabled' )
  368. !
  369. IF( 1_wp /= SIGN(1._wp,-0._wp) ) CALL ctl_stop( 'nemo_ctl: The intrinsec SIGN function follows ', &
  370. & 'f2003 standard. ' , &
  371. & 'Compile with key_nosignedzero enabled' )
  372. !
  373. END SUBROUTINE nemo_ctl
  374. SUBROUTINE nemo_closefile
  375. !!----------------------------------------------------------------------
  376. !! *** ROUTINE nemo_closefile ***
  377. !!
  378. !! ** Purpose : Close the files
  379. !!----------------------------------------------------------------------
  380. !
  381. IF ( lk_mpp ) CALL mppsync
  382. !
  383. CALL iom_close ! close all input/output files managed by iom_*
  384. !
  385. IF( numstp /= -1 ) CLOSE( numstp ) ! time-step file
  386. IF( numnam_ref /= -1 ) CLOSE( numnam_ref ) ! oce reference namelist
  387. IF( numnam_cfg /= -1 ) CLOSE( numnam_cfg ) ! oce configuration namelist
  388. IF( numout /= 6 ) CLOSE( numout ) ! standard model output file
  389. numout = 6 ! redefine numout in case it is used after this point...
  390. !
  391. END SUBROUTINE nemo_closefile
  392. SUBROUTINE nemo_alloc
  393. !!----------------------------------------------------------------------
  394. !! *** ROUTINE nemo_alloc ***
  395. !!
  396. !! ** Purpose : Allocate all the dynamic arrays of the OPA modules
  397. !!
  398. !! ** Method :
  399. !!----------------------------------------------------------------------
  400. USE diawri, ONLY: dia_wri_alloc
  401. USE dom_oce, ONLY: dom_oce_alloc
  402. USE zdf_oce, ONLY: zdf_oce_alloc
  403. USE ldftra_oce, ONLY: ldftra_oce_alloc
  404. USE trc_oce, ONLY: trc_oce_alloc
  405. !
  406. INTEGER :: ierr
  407. !!----------------------------------------------------------------------
  408. !
  409. ierr = oce_alloc () ! ocean
  410. ierr = ierr + dia_wri_alloc ()
  411. ierr = ierr + dom_oce_alloc () ! ocean domain
  412. ierr = ierr + ldftra_oce_alloc() ! ocean lateral physics : tracers
  413. ierr = ierr + zdf_oce_alloc () ! ocean vertical physics
  414. !
  415. ierr = ierr + trc_oce_alloc () ! shared TRC / TRA arrays
  416. !
  417. IF( lk_mpp ) CALL mpp_sum( ierr )
  418. IF( ierr /= 0 ) CALL ctl_stop( 'STOP', 'nemo_alloc: unable to allocate standard ocean arrays' )
  419. !
  420. END SUBROUTINE nemo_alloc
  421. SUBROUTINE nemo_partition( num_pes )
  422. !!----------------------------------------------------------------------
  423. !! *** ROUTINE nemo_partition ***
  424. !!
  425. !! ** Purpose :
  426. !!
  427. !! ** Method :
  428. !!----------------------------------------------------------------------
  429. INTEGER, INTENT(in) :: num_pes ! The number of MPI processes we have
  430. !
  431. INTEGER, PARAMETER :: nfactmax = 20
  432. INTEGER :: nfact ! The no. of factors returned
  433. INTEGER :: ierr ! Error flag
  434. INTEGER :: ji
  435. INTEGER :: idiff, mindiff, imin ! For choosing pair of factors that are closest in value
  436. INTEGER, DIMENSION(nfactmax) :: ifact ! Array of factors
  437. !!----------------------------------------------------------------------
  438. ierr = 0
  439. CALL factorise( ifact, nfactmax, nfact, num_pes, ierr )
  440. IF( nfact <= 1 ) THEN
  441. WRITE (numout, *) 'WARNING: factorisation of number of PEs failed'
  442. WRITE (numout, *) ' : using grid of ',num_pes,' x 1'
  443. jpnj = 1
  444. jpni = num_pes
  445. ELSE
  446. ! Search through factors for the pair that are closest in value
  447. mindiff = 1000000
  448. imin = 1
  449. DO ji = 1, nfact-1, 2
  450. idiff = ABS( ifact(ji) - ifact(ji+1) )
  451. IF( idiff < mindiff ) THEN
  452. mindiff = idiff
  453. imin = ji
  454. ENDIF
  455. END DO
  456. jpnj = ifact(imin)
  457. jpni = ifact(imin + 1)
  458. ENDIF
  459. !
  460. jpnij = jpni*jpnj
  461. !
  462. END SUBROUTINE nemo_partition
  463. SUBROUTINE factorise( kfax, kmaxfax, knfax, kn, kerr )
  464. !!----------------------------------------------------------------------
  465. !! *** ROUTINE factorise ***
  466. !!
  467. !! ** Purpose : return the prime factors of n.
  468. !! knfax factors are returned in array kfax which is of
  469. !! maximum dimension kmaxfax.
  470. !! ** Method :
  471. !!----------------------------------------------------------------------
  472. INTEGER , INTENT(in ) :: kn, kmaxfax
  473. INTEGER , INTENT( out) :: kerr, knfax
  474. INTEGER, DIMENSION(kmaxfax), INTENT( out) :: kfax
  475. !
  476. INTEGER :: ifac, jl, inu
  477. INTEGER, PARAMETER :: ntest = 14
  478. INTEGER :: ilfax(ntest)
  479. !
  480. ! lfax contains the set of allowed factors.
  481. data (ilfax(jl),jl=1,ntest) / 16384, 8192, 4096, 2048, 1024, 512, 256, &
  482. & 128, 64, 32, 16, 8, 4, 2 /
  483. !!----------------------------------------------------------------------
  484. ! Clear the error flag and initialise output vars
  485. kerr = 0
  486. kfax = 1
  487. knfax = 0
  488. ! Find the factors of n.
  489. IF( kn == 1 ) GOTO 20
  490. ! nu holds the unfactorised part of the number.
  491. ! knfax holds the number of factors found.
  492. ! l points to the allowed factor list.
  493. ! ifac holds the current factor.
  494. inu = kn
  495. knfax = 0
  496. DO jl = ntest, 1, -1
  497. !
  498. ifac = ilfax(jl)
  499. IF( ifac > inu ) CYCLE
  500. ! Test whether the factor will divide.
  501. IF( MOD(inu,ifac) == 0 ) THEN
  502. !
  503. knfax = knfax + 1 ! Add the factor to the list
  504. IF( knfax > kmaxfax ) THEN
  505. kerr = 6
  506. write (*,*) 'FACTOR: insufficient space in factor array ', knfax
  507. return
  508. ENDIF
  509. kfax(knfax) = ifac
  510. ! Store the other factor that goes with this one
  511. knfax = knfax + 1
  512. kfax(knfax) = inu / ifac
  513. !WRITE (*,*) 'ARPDBG, factors ',knfax-1,' & ',knfax,' are ', kfax(knfax-1),' and ',kfax(knfax)
  514. ENDIF
  515. !
  516. END DO
  517. 20 CONTINUE ! Label 20 is the exit point from the factor search loop.
  518. !
  519. END SUBROUTINE factorise
  520. #if defined key_mpp_mpi
  521. SUBROUTINE nemo_northcomms
  522. !!======================================================================
  523. !! *** ROUTINE nemo_northcomms ***
  524. !! nemo_northcomms : Setup for north fold exchanges with explicit
  525. !! point-to-point messaging
  526. !!=====================================================================
  527. !!----------------------------------------------------------------------
  528. !!
  529. !! ** Purpose : Initialization of the northern neighbours lists.
  530. !!----------------------------------------------------------------------
  531. !! 1.0 ! 2011-10 (A. C. Coward, NOCS & J. Donners, PRACE)
  532. !! 2.0 ! 2013-06 Setup avoiding MPI communication (I. Epicoco, S.
  533. !Mocavero, CMCC)
  534. !!----------------------------------------------------------------------
  535. INTEGER :: sxM, dxM, sxT, dxT, jn
  536. INTEGER :: njmppmax
  537. njmppmax = MAXVAL( njmppt )
  538. !initializes the north-fold communication variables
  539. isendto(:) = 0
  540. nsndto = 0
  541. !if I am a process in the north
  542. IF ( njmpp == njmppmax ) THEN
  543. !sxM is the first point (in the global domain) needed to compute the
  544. !north-fold for the current process
  545. sxM = jpiglo - nimppt(narea) - nlcit(narea) + 1
  546. !dxM is the last point (in the global domain) needed to compute the
  547. !north-fold for the current process
  548. dxM = jpiglo - nimppt(narea) + 2
  549. !loop over the other north-fold processes to find the processes
  550. !managing the points belonging to the sxT-dxT range
  551. DO jn = 1, jpni
  552. !sxT is the first point (in the global domain) of the jn
  553. !process
  554. sxT = nfiimpp(jn, jpnj)
  555. !dxT is the last point (in the global domain) of the jn
  556. !process
  557. dxT = nfiimpp(jn, jpnj) + nfilcit(jn, jpnj) - 1
  558. IF ((sxM .gt. sxT) .AND. (sxM .lt. dxT)) THEN
  559. nsndto = nsndto + 1
  560. isendto(nsndto) = jn
  561. ELSEIF ((sxM .le. sxT) .AND. (dxM .ge. dxT)) THEN
  562. nsndto = nsndto + 1
  563. isendto(nsndto) = jn
  564. ELSEIF ((dxM .lt. dxT) .AND. (sxT .lt. dxM)) THEN
  565. nsndto = nsndto + 1
  566. isendto(nsndto) = jn
  567. END IF
  568. END DO
  569. nfsloop = 1
  570. nfeloop = nlci
  571. DO jn = 2,jpni-1
  572. IF(nfipproc(jn,jpnj) .eq. (narea - 1)) THEN
  573. IF (nfipproc(jn - 1 ,jpnj) .eq. -1) THEN
  574. nfsloop = nldi
  575. ENDIF
  576. IF (nfipproc(jn + 1,jpnj) .eq. -1) THEN
  577. nfeloop = nlei
  578. ENDIF
  579. ENDIF
  580. END DO
  581. ENDIF
  582. l_north_nogather = .TRUE.
  583. END SUBROUTINE nemo_northcomms
  584. #else
  585. SUBROUTINE nemo_northcomms ! Dummy routine
  586. WRITE(*,*) 'nemo_northcomms: You should not have seen this print! error?'
  587. END SUBROUTINE nemo_northcomms
  588. #endif
  589. SUBROUTINE istate_init
  590. !!----------------------------------------------------------------------
  591. !! *** ROUTINE istate_init ***
  592. !!
  593. !! ** Purpose : Initialization to zero of the dynamics and tracers.
  594. !!----------------------------------------------------------------------
  595. !
  596. ! now fields ! after fields !
  597. un (:,:,:) = 0._wp ; ua(:,:,:) = 0._wp !
  598. vn (:,:,:) = 0._wp ; va(:,:,:) = 0._wp !
  599. wn (:,:,:) = 0._wp ! !
  600. hdivn(:,:,:) = 0._wp ! !
  601. tsn (:,:,:,:) = 0._wp ! !
  602. !
  603. rhd (:,:,:) = 0.e0
  604. rhop (:,:,:) = 0.e0
  605. rn2 (:,:,:) = 0.e0
  606. !
  607. END SUBROUTINE istate_init
  608. SUBROUTINE stp_ctl( kt, kindic )
  609. !!----------------------------------------------------------------------
  610. !! *** ROUTINE stp_ctl ***
  611. !!
  612. !! ** Purpose : Control the run
  613. !!
  614. !! ** Method : - Save the time step in numstp
  615. !!
  616. !! ** Actions : 'time.step' file containing the last ocean time-step
  617. !!----------------------------------------------------------------------
  618. INTEGER, INTENT(in ) :: kt ! ocean time-step index
  619. INTEGER, INTENT(inout) :: kindic ! indicator of solver convergence
  620. !!----------------------------------------------------------------------
  621. !
  622. IF( kt == nit000 .AND. lwp ) THEN
  623. WRITE(numout,*)
  624. WRITE(numout,*) 'stp_ctl : time-stepping control'
  625. WRITE(numout,*) '~~~~~~~'
  626. ! open time.step file
  627. CALL ctl_opn( numstp, 'time.step', 'REPLACE', 'FORMATTED', 'SEQUENTIAL', -1, numout, lwp, narea )
  628. ENDIF
  629. !
  630. IF(lwp) WRITE ( numstp, '(1x, i8)' ) kt !* save the current time step in numstp
  631. IF(lwp) REWIND( numstp ) ! --------------------------
  632. !
  633. END SUBROUTINE stp_ctl
  634. !!======================================================================
  635. END MODULE nemogcm