initexit.F90 25 KB

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