initexit.F90 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820
  1. !### macro's #####################################################
  2. !
  3. #define TRACEBACK write (gol,'("in ",a," (",a,", line",i5,")")') rname, __FILE__, __LINE__; call goErr
  4. #define IF_NOTOK_RETURN(action) if (rcode/=0) then; TRACEBACK; action; return; end if
  5. #define IF_ERROR_RETURN(action) if (rcode> 0) then; TRACEBACK; action; return; end if
  6. #define IF_NOTOK_MPI(action) if (ierr/=MPI_SUCCESS) then; TRACEBACK; action; return; end if
  7. !
  8. #include "tm5.inc"
  9. !
  10. !-----------------------------------------------------------------------------
  11. ! TM5 !
  12. !-----------------------------------------------------------------------------
  13. !BOP
  14. !
  15. ! !MODULE: INITEXIT
  16. !
  17. ! !DESCRIPTION: contains routines to initialize/finalize the model
  18. !\\
  19. !\\
  20. ! !INTERFACE:
  21. !
  22. MODULE INITEXIT
  23. !
  24. ! !USES:
  25. !
  26. use GO, only : gol, goPr, goErr, goLabel
  27. use dims ! WARNING: has var 'status'
  28. implicit none
  29. private
  30. !
  31. ! !PUBLIC MEMBER FUNCTIONS:
  32. !
  33. public :: exitus
  34. public :: start
  35. public :: control_init
  36. !
  37. ! !PRIVATE DATA MEMBERS:
  38. !
  39. character(len=*), parameter :: mname = 'initexit'
  40. !
  41. ! !REVISION HISTORY:
  42. ! 6 Nov 2012 - Ph. Le Sager - new read_control subroutine
  43. !
  44. ! !REMARKS:
  45. !
  46. !EOP
  47. !------------------------------------------------------------------------
  48. CONTAINS
  49. !--------------------------------------------------------------------------
  50. ! TM5 !
  51. !--------------------------------------------------------------------------
  52. !BOP
  53. !
  54. ! !IROUTINE: DEFAULT_CNTL
  55. !
  56. ! !DESCRIPTION: provide default values of control variables
  57. !\\
  58. !\\
  59. ! !INTERFACE:
  60. !
  61. SUBROUTINE DEFAULT_CNTL ( rcode )
  62. !
  63. ! !USES:
  64. !
  65. use datetime, only : tau2date
  66. !
  67. ! !OUTPUT PARAMETERS:
  68. !
  69. integer, intent(out) :: rcode
  70. !
  71. ! !REVISION HISTORY:
  72. ! mh, 27-jun-1989 - 26-sep-1992
  73. ! mk, 21-dec-2002
  74. ! 6 Nov 2012 - Ph Le Sager -
  75. !
  76. ! !REMARKS:
  77. !
  78. !EOP
  79. !------------------------------------------------------------------------
  80. !BOC
  81. character(len=*), parameter :: rname = mname//'/default_cntl'
  82. integer :: i,k,n
  83. ! set calendar type
  84. icalendo=2
  85. ! default time steps of basic tasks
  86. nstep = 0
  87. ndyn = 3600*3
  88. nconv = 3600*3
  89. ndiff = 24*3600*1000 !never happes in one month
  90. ntrans = 0
  91. ndiag = 4*3600
  92. nchem = 0
  93. nsrce = 24*3600
  94. !nread = 3*3600 ! <--- set in main program by Meteo_Init
  95. nwrite = -1
  96. ninst = 0
  97. !c ! default is restart
  98. istart=10
  99. itaui=0
  100. newsrun=.true.
  101. call tau2date(itaui,idatei)
  102. if ( mod(idatei(4),3) /= 0 ) then
  103. rcode=1
  104. write(gol,*)' GMT start time should be multiple of 3'; call goErr
  105. TRACEBACK; return
  106. end if
  107. itaue=itaui
  108. call tau2date(itaue,idatee)
  109. itaut=0
  110. call tau2date(itaut,idatet)
  111. !c ! output for conservation diagnostics
  112. !c ! -1: daily, -2: monthly, -3: yearly,
  113. !c ! >=0 interval in sec
  114. ndiagp1=-2
  115. !c ! output for mean field diagnostics
  116. !c ! -1: daily, -2: monthly, -3: yearly,
  117. !c ! >=0 interval in sec
  118. ndiagp2=-2
  119. !c ! full convection
  120. czeta=1.
  121. !c ! full vertical diffusion
  122. czetak=1.
  123. !c ! scaling factor for horizontal diffusion
  124. limits=.true.
  125. !c ! checking interval
  126. ncheck=6
  127. !c ! control for debug output
  128. okdebug=.false.
  129. revert = 1
  130. END SUBROUTINE DEFAULT_CNTL
  131. !EOC
  132. !--------------------------------------------------------------------------
  133. ! TM5 !
  134. !--------------------------------------------------------------------------
  135. !BOP
  136. !
  137. ! !IROUTINE: EXITUS
  138. !
  139. ! !DESCRIPTION: terminate a model run
  140. !\\
  141. !\\
  142. ! !INTERFACE:
  143. !
  144. SUBROUTINE EXITUS( rcode )
  145. !
  146. ! !USES:
  147. !
  148. use global_data , only : free_fields, outdir
  149. use io_save, only : write_save_file
  150. use restart, only : rs_write
  151. use datetime, only : tstamp
  152. use advectm_cfl, only : done_cfl
  153. #ifdef with_budgets
  154. use budget_global, only : done_budget_global
  155. #endif
  156. #ifdef with_ecearth_optics
  157. use ecearth_optics, only : ECEarth_Optics_Done
  158. #endif
  159. use Partools, only : isRoot
  160. !
  161. ! !OUTPUT PARAMETERS:
  162. !
  163. integer, intent(out) :: rcode
  164. !
  165. ! !REVISION HISTORY:
  166. ! 6 Nov 2012 - Ph Le Sager -
  167. !
  168. ! !REMARKS:
  169. !
  170. !EOP
  171. !------------------------------------------------------------------------
  172. !BOC
  173. character(len=*), parameter :: rname = mname//'/exitus'
  174. integer :: region
  175. real :: cpu3
  176. ! --- begin ---------------------------------------
  177. #ifdef with_hdf4
  178. ! Save the model state. This routine is quite memory-consuming, and should
  179. ! not be called if not used.
  180. if(.not.rs_write) then
  181. call Write_save_file( 'successful completion of run',trim(outdir)//'/save', rcode )
  182. IF_NOTOK_RETURN(rcode=1)
  183. endif
  184. #endif
  185. #ifdef with_budgets
  186. ! save budgets, print summary
  187. call done_budget_global ( rcode )
  188. IF_NOTOK_RETURN(rcode=1)
  189. #endif
  190. #ifdef with_ecearth_optics
  191. call ECEarth_Optics_Done( rcode )
  192. IF_NOTOK_RETURN(rcode=1)
  193. #endif
  194. ! free memory
  195. call free_fields
  196. if ( isRoot ) then
  197. write (gol,'(" ")'); call goPr
  198. write (gol,'("CFL info from advection:")'); call goPr
  199. write (gol,'(a,i4,f10.4)') ' x: nloop_max, xi', nloop_max(1,1), xi(1,1); call goPr
  200. write (gol,'(a,i4,f10.4)') ' y: nloop_max, xi', nloop_max(1,2), xi(1,2); call goPr
  201. write (gol,'(a,i4,f10.4)') ' z: nloop_max, xi', nloop_max(1,3), xi(1,3); call goPr
  202. end if
  203. ! cfl finished
  204. call Done_CFL
  205. IF ( isRoot ) THEN
  206. write (gol,'(1x)'); call goPr
  207. write (gol,'("program has terminated normally.")'); call goPr
  208. call cputim(cpu3)
  209. cpu3 = cpu3-cpu0
  210. write (gol,'(a," > number of timesteps :",i8)') rname, nstep ; call goPr
  211. write (gol,'(a," > time-loop runtime [s] :",f16.2)') rname, cpu3 ; call goPr
  212. write (gol,'(a," > runtime/timesteps [s] :",f16.8)') rname, cpu3/nstep ; call goPr
  213. write (gol,'(1x)'); call goPr
  214. END IF
  215. ! ok
  216. rcode = 0
  217. END SUBROUTINE EXITUS
  218. !EOC
  219. !--------------------------------------------------------------------------
  220. ! TM5 !
  221. !--------------------------------------------------------------------------
  222. !BOP
  223. !
  224. ! !IROUTINE: CONTROL_INIT
  225. !
  226. ! !DESCRIPTION: set control variables, either to default or read from rc file.
  227. !\\
  228. !\\
  229. ! !INTERFACE:
  230. !
  231. SUBROUTINE CONTROL_INIT( rcode )
  232. !
  233. ! !USES:
  234. !
  235. use GO, only : TrcFile, Init, Done, ReadRc
  236. use GO, only : TDate, NewDate, AnyDate
  237. use GO, only : operator(+), operator(-)
  238. use GO, only : goTranslate
  239. use datetime, only : date2tau, tau2date, julday
  240. use global_data, only : rcfile, inputdir, outdir
  241. use global_data, only : fcmode, tfcday0
  242. use partools
  243. #ifdef oasis3
  244. use tm5_prism, only : PRISM_start_date
  245. #endif
  246. !
  247. ! !OUTPUT PARAMETERS:
  248. !
  249. integer, intent(out) :: rcode
  250. !
  251. ! !REVISION HISTORY:
  252. ! 6 Nov 2012 - Ph Le Sager - v0
  253. !
  254. ! !REMARKS:
  255. ! - this is code taken off 'start' in order to read control parameters
  256. ! before 'start' is called, so they are available for processes inits.
  257. !
  258. !EOP
  259. !------------------------------------------------------------------------
  260. !BOC
  261. character(len=*), parameter :: rname = mname//'/control_init'
  262. character(len=32) :: stime
  263. type(TrcFile) :: rcF
  264. integer :: ccyy, mm, dd
  265. ! -------------------- begin --------------------
  266. call default_cntl( rcode )
  267. IF_NOTOK_RETURN(rcode=1)
  268. onROOT : if ( isRoot ) then
  269. call Init( rcF, rcfile, rcode )
  270. IF_NOTOK_RETURN(rcode=1)
  271. ! forecast series ?
  272. call ReadRc( rcF, 'time.fc', fcmode, rcode, default=.false. )
  273. IF_ERROR_RETURN(rcode=1)
  274. ! read forecast day 0 ?
  275. if ( fcmode ) then
  276. ! read day: yyyy-mm-dd
  277. call ReadRc( rcF, 'time.fc.day0' , stime, rcode )
  278. IF_NOTOK_RETURN(rcode=1)
  279. call goTranslate( stime, '/-', ' ', rcode )
  280. IF_NOTOK_RETURN(rcode=1)
  281. read (stime,*,iostat=rcode) ccyy, mm, dd
  282. if ( rcode /= 0 ) then
  283. write (gol,'("reading ccyy mm dd from : ",a)') trim(stime); call goErr
  284. TRACEBACK; call goErr; rcode=1; return
  285. end if
  286. ! store day:
  287. tfcday0 = NewDate(year=ccyy,month=mm,day=dd)
  288. else
  289. ! dummy:
  290. tfcday0 = AnyDate()
  291. end if
  292. call ReadRc(rcF, 'time.ndyn_max', ndyn, rcode )
  293. IF_NOTOK_RETURN(rcode=1)
  294. nconv = ndyn
  295. nchem = ndyn
  296. nsrce = ndyn
  297. ndyn_max = ndyn
  298. ! ensure that every 'nread' seconds is at the end of a dynamic time step:
  299. call ReadRc( rcF, 'time.ntimestep', nread, rcode )
  300. IF_NOTOK_RETURN(rcode=1)
  301. ! how to initialize the tracer fields ?
  302. call ReadRc( rcF, 'istart', istart, rcode )
  303. IF_NOTOK_RETURN(rcode=1)
  304. ! input files:
  305. call ReadRc( rcF, 'inputdir', inputdir, rcode )
  306. IF_NOTOK_RETURN(rcode=1)
  307. ! print debug info ?
  308. call ReadRc( rcF, 'okdebug', okdebug, rcode )
  309. IF_NOTOK_RETURN(rcode=1)
  310. ! name of output directory:
  311. call ReadRc( rcF, 'output.dir', outdir, rcode )
  312. IF_NOTOK_RETURN(rcode=1)
  313. ! start time:
  314. call ReadRc( rcF, 'jobstep.timerange.start' , stime, rcode )
  315. IF_NOTOK_RETURN(rcode=1)
  316. call goTranslate( stime, '/-:', ' ', rcode )
  317. IF_NOTOK_RETURN(rcode=1)
  318. read (stime,*,iostat=rcode) idatei
  319. if ( rcode /= 0 ) then
  320. write (gol,'("could not read start time from : ",a)') trim(stime); call goErr
  321. TRACEBACK; rcode=1; return
  322. end if
  323. ! end time:
  324. call ReadRc( rcF, 'jobstep.timerange.end' , stime, rcode )
  325. IF_NOTOK_RETURN(rcode=1)
  326. call goTranslate( stime, '/-:', ' ', rcode )
  327. IF_NOTOK_RETURN(rcode=1)
  328. read (stime,*,iostat=rcode) idatee
  329. if ( rcode /= 0 ) then
  330. write (gol,'("could not read end time from : ",a)') trim(stime); call goErr
  331. TRACEBACK; rcode=1; return
  332. end if
  333. ! 'target' time?
  334. idatet = idatee
  335. ! close:
  336. call Done( rcF, rcode )
  337. IF_NOTOK_RETURN(rcode=1)
  338. end if onROOT
  339. #ifdef MPI
  340. ! broadcast namelist
  341. call MPI_BCAST(istart ,1, MPI_INTEGER, root ,localComm,ierr)
  342. IF_NOTOK_MPI(rcode=1)
  343. CALL MPI_BCAST(ndyn ,1, MPI_INTEGER, root ,localComm,ierr)
  344. IF_NOTOK_MPI(rcode=1)
  345. call MPI_BCAST(ndyn_max ,1, MPI_INTEGER, root ,localComm,ierr)
  346. IF_NOTOK_MPI(rcode=1)
  347. call MPI_BCAST(nconv ,1, MPI_INTEGER, root ,localComm,ierr)
  348. IF_NOTOK_MPI(rcode=1)
  349. call MPI_BCAST(ndiag ,1, MPI_INTEGER, root ,localComm,ierr)
  350. IF_NOTOK_MPI(rcode=1)
  351. call MPI_BCAST(nchem ,1, MPI_INTEGER, root ,localComm,ierr)
  352. IF_NOTOK_MPI(rcode=1)
  353. call MPI_BCAST(nsrce ,1, MPI_INTEGER, root ,localComm,ierr)
  354. IF_NOTOK_MPI(rcode=1)
  355. call MPI_BCAST(nread ,1, MPI_INTEGER, root ,localComm,ierr)
  356. IF_NOTOK_MPI(rcode=1)
  357. call MPI_BCAST(nwrite ,1, MPI_INTEGER, root ,localComm,ierr)
  358. IF_NOTOK_MPI(rcode=1)
  359. call MPI_BCAST(ninst ,1, MPI_INTEGER, root ,localComm,ierr)
  360. IF_NOTOK_MPI(rcode=1)
  361. call MPI_BCAST(ndiff ,1, MPI_INTEGER, root ,localComm,ierr)
  362. IF_NOTOK_MPI(rcode=1)
  363. call MPI_BCAST(icalendo ,1, MPI_INTEGER, root ,localComm,ierr)
  364. IF_NOTOK_MPI(rcode=1)
  365. call MPI_BCAST(iyear0 ,1, MPI_INTEGER, root ,localComm,ierr)
  366. IF_NOTOK_MPI(rcode=1)
  367. call MPI_BCAST(idatei ,6, MPI_INTEGER, root ,localComm,ierr)
  368. IF_NOTOK_MPI(rcode=1)
  369. call MPI_BCAST(idatee ,6, MPI_INTEGER, root ,localComm,ierr)
  370. IF_NOTOK_MPI(rcode=1)
  371. call MPI_BCAST(idatet ,6, MPI_INTEGER, root ,localComm,ierr)
  372. IF_NOTOK_MPI(rcode=1)
  373. call MPI_BCAST(ndiagp1 ,1, MPI_INTEGER, root ,localComm,ierr)
  374. IF_NOTOK_MPI(rcode=1)
  375. call MPI_BCAST(ndiagp2 ,1, MPI_INTEGER, root ,localComm,ierr)
  376. IF_NOTOK_MPI(rcode=1)
  377. call MPI_BCAST(czeta ,1, MY_REAL, root ,localComm,ierr)
  378. IF_NOTOK_MPI(rcode=1)
  379. call MPI_BCAST(czetak ,1, MY_REAL, root ,localComm,ierr)
  380. IF_NOTOK_MPI(rcode=1)
  381. call MPI_BCAST(limits ,1, MPI_LOGICAL, root ,localComm,ierr)
  382. IF_NOTOK_MPI(rcode=1)
  383. call MPI_BCAST(okdebug ,1, MPI_LOGICAL, root ,localComm,ierr)
  384. IF_NOTOK_MPI(rcode=1)
  385. call MPI_BCAST( inputdir, len(inputdir), MPI_CHARACTER, root, localComm, ierr )
  386. IF_NOTOK_MPI(rcode=1)
  387. call MPI_BCAST( outdir, len( outdir), MPI_CHARACTER, root, localComm, ierr )
  388. IF_NOTOK_MPI(rcode=1)
  389. #endif
  390. ! Init time/calendar
  391. !
  392. ! itau runs from beginning of year -1 allows running from 1-1-yyyy (cmk aug/2003)
  393. iyear0 = idatei(1)-1
  394. julday0=julday(1,1,iyear0)
  395. if (icalendo.eq.2) then
  396. julday0=julday(1,1,iyear0)
  397. end if
  398. call date2tau(idatei,itaui)
  399. itau=itaui
  400. call tau2date(itau,idate)
  401. call date2tau(idatee,itaue)
  402. call date2tau(idatet,itaut)
  403. ! set time flags
  404. newyr=.true.
  405. newhour(:)=.true.
  406. newday=.true.
  407. newmonth=.true.
  408. newsrun=.true.
  409. ! step counter
  410. nstep0=0
  411. nstep=0
  412. #ifdef oasis3
  413. ! store initial time for prism coupling via oasis3
  414. ! (time is defined as seconds from begin)
  415. PRISM_start_date = idatei
  416. #endif
  417. ! remains from zooming capabilities - set for region 1 if still needed
  418. children = 0
  419. isr(1) = 1
  420. ier(1) = im(1)
  421. jsr(1) = 1
  422. jer(1) = jm(1)
  423. splitorderzoom = ' '
  424. splitorderzoom(1,1:nsplitsteps) = splitorder
  425. rcode=0
  426. END SUBROUTINE CONTROL_INIT
  427. !EOC
  428. !--------------------------------------------------------------------------
  429. ! TM5 !
  430. !--------------------------------------------------------------------------
  431. !BOP
  432. !
  433. ! !IROUTINE: START
  434. !
  435. ! !DESCRIPTION: initialization of a model run or its continuation
  436. !\\
  437. !\\
  438. ! !INTERFACE:
  439. !
  440. subroutine start( tread1, tread2, rcode )
  441. !
  442. ! !USES:
  443. !
  444. use GO, only : TrcFile, Init, Done, ReadRc
  445. use GO, only : TDate, NewDate, IncrDate
  446. use GO, only : operator(+), operator(-), rTotal
  447. use global_data, only : rcfile
  448. use tracer_data, only : tracer_print, init_short
  449. use Meteo, only : Meteo_Setup_Mass, Meteo_Setup_Other
  450. #ifndef __GFORTRAN__
  451. use tracer_data, only : init_non_zero
  452. #endif
  453. #ifdef with_budgets
  454. use budget_global, only : Init_budget_global
  455. #endif
  456. use advectm_cfl, only : Init_CFL
  457. #ifndef without_advection
  458. use advectm_cfl, only : Check_CFL
  459. #endif
  460. #ifdef with_ecearth_optics
  461. use ecearth_optics, only : ECEarth_Optics_Init
  462. #endif
  463. ! to fill tracers:
  464. use user_input, only : user_input_start
  465. use restart, only : Restart_Read, Restart_Write
  466. use io_save, only : read_save_file_30, read_save_file
  467. use io_save, only : readhdfmmr, read_mmix
  468. !
  469. ! !OUTPUT PARAMETERS:
  470. !
  471. type(TDate), intent(out) :: tread1, tread2
  472. integer, intent(out) :: rcode
  473. !
  474. ! !REVISION HISTORY:
  475. ! 6 Nov 2012 - Ph Le Sager - took off reading of control parameters
  476. !
  477. ! !REMARKS:
  478. !
  479. !EOP
  480. !------------------------------------------------------------------------
  481. !BOC
  482. character(len=*), parameter :: rname = mname//'/start'
  483. integer :: n, region
  484. character(len=256) :: fname, fdir
  485. character(len=32 ) :: key
  486. type(TrcFile) :: rcF
  487. type(TDate) :: tdyn, tr(2)
  488. real :: t1, t2
  489. ! --- begin -----------------------------------------------
  490. call goLabel()
  491. write (gol,'(" ",a,": init cfl ...")') rname; call goPr
  492. ! initialise data for CFL routines
  493. CALL init_cfl
  494. write (gol,'(" ",a,": initial meteo (pressure, air mass), optionally from restart file ...")') rname; call goPr
  495. ! setup from start time to end of interval [k*nread,(k+1)*nread]
  496. tread1 = NewDate(time6=idate)
  497. tread2 = NewDate(time6=(/idate(1:3),0,0,0/)) + IncrDate(sec=floor(idate(4)*3600.0/nread)*nread+nread)
  498. ! n is the number of dynamic intervals within the time interval for which
  499. ! the meteo has been setup:
  500. n = ceiling( rTotal(tread2-tread1,'sec') / real(ndyn) )
  501. ndyn = nint( rTotal(tread2-tread1,'sec') / n )
  502. ! setup pressure and mass fields
  503. ! o do not check pressure implied by advection
  504. call Meteo_Setup_Mass( tread1, tread2, rcode, isfirst=.true. )
  505. IF_NOTOK_RETURN(rcode=1)
  506. #ifndef without_advection
  507. ! determine dynamic timestep ndyn for this interval [tread1,tread2] ; the
  508. ! initial number of time steps n is increased until no cfl violations
  509. ! occurs
  510. call Check_CFL( tread1, tread2, n, rcode )
  511. IF_NOTOK_RETURN(rcode=1)
  512. #endif
  513. ! * setup meteo for dynamic step tdyn+[0,ndyn]
  514. ! current time (begin of dynamics step)
  515. tdyn = NewDate( time6=idate )
  516. ! time range of dynamic step:
  517. tr(1) = tdyn
  518. tr(2) = tdyn + IncrDate( sec=ndyn )
  519. !! convert pu/pv to am/bm/cm, eventually time interpolated
  520. !call Setup_MassFlow( tr, rcode )
  521. !if (rcode/=0) call escape_tm('ERROR in tracer')
  522. ! setup (interpolate?) other meteo:
  523. call Meteo_Setup_Other( tr(1), tr(2), rcode, isfirst=.true. )
  524. IF_NOTOK_RETURN(rcode=1)
  525. !
  526. ! ** INIT TRACERS ****************************
  527. !
  528. write (gol,'(" ",a,": init tracer fields (istart=",i2,")...")') rname, istart; call goPr
  529. IF (revert == 1) THEN
  530. select case (istart)
  531. case(1)
  532. !
  533. ! initial tracer fields are set to zero
  534. ! nothing to do, since TRACER_INIT already set them to 0.
  535. #ifndef __GFORTRAN__
  536. case ( 2 )
  537. !
  538. ! initial tracer fields with a very small non-zero values
  539. !
  540. call INIT_NON_ZERO
  541. #endif
  542. case ( 30 )
  543. !
  544. ! Read "save" files with MIXING RATIO and (option) SLOPES, SECOND
  545. ! MOMENTS, of TRANSPORTED TRACERS.
  546. !
  547. ! File are defined with fully qualified name in the rc-file with
  548. ! the following format:
  549. !
  550. ! start.30.<region-name> : <fully-qualified-filename>
  551. !
  552. ! Example:
  553. !
  554. ! start.30.glb600x400 : /data/save_files/mystuff_glb6x4.hdf
  555. !
  556. call Init( rcF, rcfile, rcode )
  557. IF_NOTOK_RETURN(rcode=1)
  558. ! loop over regions:
  559. do region = 1, nregions
  560. write (key,'("start.30.",a)') trim(region_name(1))
  561. call ReadRc( rcF, key, fname, rcode, default='file_name_empty' )
  562. IF_NOTOK_RETURN (rcode = 1)
  563. write (gol,*) 'Using save file names from rc-file start.30.* values'; call goPr
  564. CALL Read_save_file_30( region, fname, rcode )
  565. IF_NOTOK_RETURN (rcode = 1)
  566. end do
  567. call Done( rcF, rcode )
  568. IF_NOTOK_RETURN(rcode=1)
  569. case ( 31 )
  570. !
  571. ! Read mass of both transpoted *AND* short lived species from so
  572. ! -called "save file". No slopes, but regridding to model resolution
  573. ! is available, since grid information is also read.
  574. !
  575. call Init( rcF, rcfile, rcode )
  576. IF_NOTOK_RETURN(rcode=1)
  577. do region=1,nregions
  578. ! name of save file
  579. call ReadRc( rcF, 'start.31.'//trim(region_name(region)), fname, rcode )
  580. IF_NOTOK_RETURN(rcode=1)
  581. ! read all tracers
  582. call Read_save_file( region, fname, rcode )
  583. IF_NOTOK_RETURN(rcode=1)
  584. ! overwrite with TM4 fields ?
  585. call ReadRc( rcF, 'start.31.'//trim(region_name(region))//'.TM4', fname, rcode, 'none' )
  586. IF_ERROR_RETURN(rcode=1)
  587. ! key found ? then read:
  588. if ( fname /= 'none' ) then
  589. call Read_save_file( region, fname, rcode, tm4=.true. )
  590. IF_NOTOK_RETURN(rcode=1)
  591. end if
  592. end do
  593. call Done( rcF, rcode )
  594. IF_NOTOK_RETURN(rcode=1)
  595. case ( 32, 33 )
  596. !
  597. ! 32 = read from restart file: tracers mass only (in fact mixing ratios)
  598. ! 33 = read from restart file: tracers mass (and air mass in standalone case)
  599. !
  600. ! Note that for 33, surface pressure and air mass (both available in
  601. ! the restart file) are also read in Meteo_Setup_Mass above. But not
  602. ! with 32.
  603. !
  604. call cpu_time(t1)
  605. #ifdef oasis3
  606. call Restart_Read( rcode, tracer_mass=.true., air_mass=.true.)
  607. IF_NOTOK_RETURN(rcode=1)
  608. #else
  609. call Restart_Read( rcode, tracer_mass=.true.)
  610. IF_NOTOK_RETURN(rcode=1)
  611. #endif
  612. call cpu_time(t2)
  613. write (gol,*) " time to read restart [s]: ", t2-t1 ; call goPr
  614. case ( 4 )
  615. !
  616. ! Initial tracer fields are obtained from a "saveoldfile" : see
  617. ! io_save for details.
  618. !
  619. call Init( rcF, rcfile, rcode )
  620. IF_NOTOK_RETURN(rcode=1)
  621. call ReadRc( rcF, 'start.4.'//trim(region_name(1)), fname, rcode )
  622. IF_NOTOK_RETURN(rcode=1)
  623. call readhdfmmr( 1, fname, rcode )
  624. IF_NOTOK_RETURN(rcode=1)
  625. call Done( rcF, rcode )
  626. IF_NOTOK_RETURN(rcode=1)
  627. case ( 5 )
  628. !
  629. ! Transported tracer fields are obtained from a mmix file.
  630. ! Slopes, if used, are set to 0.
  631. !
  632. ! This is typically the choice for combining different versions
  633. ! or extending the number of tracers.
  634. ! The compounds are searched by name. If not in the mmix file
  635. ! the field is initialized as zero (tiny(1.))
  636. !
  637. call Init( rcF, rcfile, rcode )
  638. IF_NOTOK_RETURN(rcode=1)
  639. call ReadRc( rcF, 'start.5.'//trim(region_name(1)), fname, rcode )
  640. IF_NOTOK_RETURN(rcode=1)
  641. call READ_MMIX(1,fname, rcode)
  642. IF_NOTOK_RETURN(rcode=1)
  643. call Done( rcF, rcode )
  644. IF_NOTOK_RETURN(rcode=1)
  645. case ( 9 )
  646. !
  647. ! USER DEFINED
  648. !
  649. call user_input_start( rcode )
  650. IF_NOTOK_RETURN(rcode=1)
  651. case default
  652. write (gol,'("unsupported istart : ",i2)') istart; call goErr
  653. TRACEBACK; rcode=1; return
  654. end select
  655. ! Ensure that non-tranported tracers are initialized
  656. if((istart==4.or.istart==5) .and.newsrun) then
  657. do n=1,nregions
  658. call init_short(n)
  659. enddo
  660. endif
  661. end if ! forward run
  662. if ( okdebug ) then
  663. do region=1,nregions
  664. call tracer_print(region, "read init", rcode)
  665. IF_NOTOK_RETURN(rcode=1)
  666. end do
  667. end if
  668. #ifdef with_budgets
  669. write (gol,'(" ",a,": init budgets ...")') rname; call goPr
  670. call init_budget_global ( rcode )
  671. IF_NOTOK_RETURN(rcode=1)
  672. #endif
  673. #ifdef with_ecearth_optics
  674. write (gol,'(" ",a,": init ecearth optics ...")') rname; call goPr
  675. Call ECEarth_Optics_Init( rcode )
  676. IF_NOTOK_RETURN(rcode=1)
  677. #endif
  678. call cputim(cpu0) ; call goLabel() ; rcode=0
  679. END SUBROUTINE START
  680. !EOC
  681. !--------------------------------------------------------------------------
  682. ! TM5 !
  683. !--------------------------------------------------------------------------
  684. !BOP
  685. !
  686. ! !IROUTINE: CPUTIM
  687. !
  688. ! !DESCRIPTION: returns current value of the processor clock in seconds.
  689. !\\
  690. !\\
  691. ! !INTERFACE:
  692. !
  693. subroutine cputim(time )
  694. !
  695. ! !OUTPUT PARAMETERS:
  696. !
  697. real,intent(out) :: time
  698. !
  699. !EOP
  700. !------------------------------------------------------------------------
  701. !BOC
  702. integer :: clock, clockrate
  703. call system_clock(clock, clockrate)
  704. time = clock*(1.0/clockrate)
  705. end subroutine cputim
  706. !EOC
  707. END MODULE INITEXIT