dims.F90 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319
  1. !
  2. #define TRACEBACK write (gol,'("in ",a," (",a,", line",i5,")")') rname, __FILE__, __LINE__; call goErr
  3. #define IF_NOTOK_RETURN(action) if (rc/=0) then; TRACEBACK; action; return; end if
  4. #define IF_ERROR_RETURN(action) if (rc> 0) then; TRACEBACK; action; return; end if
  5. !
  6. #include "tm5.inc"
  7. !
  8. !#################################################################
  9. MODULE DIMS
  10. use GO, only : gol, goPr, goErr
  11. use binas, only : pi
  12. use dims_grid
  13. use dims_levels
  14. use global_types
  15. IMPLICIT NONE
  16. PUBLIC
  17. private :: pi
  18. ! --- const -------------------------------------
  19. character(len=*), parameter, private :: mname = 'module Dims'
  20. ! --- const --------------------------------------
  21. character(len=100) :: datadir = ''
  22. real,parameter :: gtor = pi/180.0
  23. real,parameter :: one = 1.0
  24. real,parameter :: zero = 0.0
  25. integer,parameter :: nlat180 = 180
  26. integer,parameter :: nlon360 = 360
  27. real,dimension(nlat180) :: dxy11 ! surface area in 1x1
  28. real,parameter :: dlat = dy*gtor
  29. real,parameter :: dlon = dx*gtor
  30. ! define the parent child structure:
  31. integer,dimension(nregions,0:nregions) :: children
  32. ! children(r,0) = total number of children for region r (zero if childless)
  33. ! children(r,1) = number of first child of region r,
  34. ! children(r,2) = number of second child of region r, etc.
  35. ! grid-coordinates of each region with respect its parent
  36. ! (will be calculated at start program)
  37. integer,dimension(1:nregions) :: ibeg,iend,jbeg,jend,lbeg,lend
  38. integer,dimension(nregions) :: isr,ier,jsr,jer ! scope of the region
  39. ! depends on NPtouch/SPtouch, Xcyc
  40. ! calculated in determine_children_etc
  41. ! _________________________________________________________________________
  42. !
  43. ! sequence of steps that is used to process the algorithm.
  44. ! nsplitsteps contans total steps
  45. ! n_operators the number of different operators
  46. ! The routine process_region calls the corresponding routines,
  47. ! depending on splitorder.
  48. ! x = x-advection
  49. ! y = y-advection
  50. ! z = z-advection
  51. ! v = vertical mixing SGS
  52. ! s = sources
  53. ! c = chemistry....
  54. integer,parameter :: nsplitsteps = 12
  55. integer,parameter :: n_operators = nsplitsteps/2
  56. character,dimension(nsplitsteps),parameter :: splitorder = &
  57. (/'x','y','z','v','s','c','c','s','v','z','y','x'/)
  58. ! splitorderzoom contains the fully expanded list of operations
  59. ! for the children
  60. character,dimension(nregions,maxref*nsplitsteps) :: splitorderzoom
  61. ! status keeps track of the operations per region
  62. integer,dimension(nregions) :: status
  63. integer,parameter :: zoom_mode = 1
  64. ! _________________________________________________________________________
  65. ! advection scheme:
  66. #ifdef secmom
  67. character(5),parameter :: adv_scheme = '2nd_m'
  68. #else
  69. character(5),parameter :: adv_scheme = 'slope'
  70. #endif
  71. ! limits the slopes to physical values
  72. logical :: limits = .true.
  73. logical :: limits_extra = .true. ! used in secmom advection
  74. ! numbers of CFL violations and CFL numbers
  75. integer,dimension(nregions,3) :: nxi
  76. integer,dimension(nregions,3) :: nloop_max = 0
  77. real,dimension(nregions,3) :: xi
  78. ! small number with respect to the altitude unit (used in the advectz part)
  79. real,parameter:: epsz=0.0001
  80. ! _________________________________________________________________________
  81. ! some timing variables to be used in chemistry applications
  82. ! calculated by calc_sm, called in ss_monthly_update
  83. real :: sec_day,sec_month,sec_year !
  84. integer,dimension(12) :: mlen !length of the 12 month in days
  85. logical :: okdebug=.true.
  86. integer :: revert=1 ! if -1 reverses time and winds...
  87. integer :: istart
  88. integer :: ndiag,ninst,ncheck,ntrans
  89. integer(kind=8) :: itau,itaui,itaue,itaut,itau0
  90. integer :: nwrite, nsrce
  91. integer(kind=8),dimension(nregions) :: itaur ! itau count for the different regions
  92. integer :: nread = 6*3600
  93. ! read of 6-hourly fields is staggered with three hours.
  94. integer,parameter :: staggered = 3*3600
  95. integer :: ndyn, ndiff, nchem, nconv
  96. integer :: ndyn_max
  97. integer,dimension(6) :: idate,idatei,idatee,idatet,idate0
  98. logical :: newyr,newmonth,newday,newsrun,newhour(nregions)
  99. integer :: julday0,iyear0
  100. integer :: icalendo
  101. integer :: ndiagp1,ndiagp2
  102. integer :: nstep,nstep0
  103. real :: cpu0,cpu1
  104. real,dimension(nregions) :: areag
  105. ! main control variables, accessible through namelist 'inputz'
  106. ! all times (unless noted) are given in seconds.
  107. ! internally model time is kept in seconds (variables itau...) since
  108. ! 1st-jan-iyear0, 00:00:00
  109. ! (iyear0 now defined as the actual year at start)
  110. !---------------------------------------------------------------------------
  111. ! name type default purpose
  112. ! ---- ---- ------- -------
  113. !
  114. ! ndyn integer 1*3600 length of full advection step
  115. ! nconv integer 1*3600 interval for convection calculation
  116. ! ndiff integer 0 interval for horizontal diffusion calc
  117. ! nchem integer 0 interval for chemistry calculations
  118. ! nsrce integer 24*3600 interval for source calculation
  119. ! limits logical .true. if set to .true. then
  120. ! the slopes are limited
  121. ! such that no negative tracer
  122. ! masses should occur
  123. ! istart integer 10 start/restart options:
  124. ! 1 coldstart with initial fields set to 0
  125. ! 2 coldstart with initial fields computed
  126. ! in sr trace1 in sources_sinks...
  127. ! 3 coldstart with initial
  128. ! fields read from model output (save file)
  129. ! 4 coldstart with initial
  130. ! fields read from model output stored
  131. ! in mixing ratio (no slopes).
  132. ! nread integer 12*3600 interval for input of massfluxes and convection info
  133. ! nwrite integer 0 interval for alternate output of restart
  134. ! status on files save1.b and save2.b
  135. ! ninst integer 0 interval for output of instantaneous
  136. ! tracer mix ratio fields
  137. ! ncheck integer 0 interval for output of tracer mix ratio
  138. ! at checkpoints
  139. ! ndiag integer 12*3600 interval for computing mean quantities
  140. !CMK ndiagp1 and ndiagp2 not implemented yet...
  141. ! ndiagp1 integer -2 interval for output of
  142. ! -1 daily
  143. ! -2 monthly
  144. ! -3 yearly
  145. ! >=0 interval in seconds
  146. ! ndiagp2 integer -2 interval for output of time averaged fields
  147. ! -1 daily
  148. ! -2 monthly
  149. ! -3 yearly
  150. ! >=0 interval in seconds
  151. !
  152. ! name type default purpose
  153. ! ---- ---- ------- -------
  154. !
  155. ! icalendo integer 2 calendar type
  156. ! 1 permanent 360 day year calendar
  157. ! 2 real calendar
  158. ! 3 permanent 365 day year calendar
  159. ! 4 permanent 366 day year calendar
  160. ! iyear0 integer 1980 base year for calendar calculations
  161. ! (because of overflow problems this should
  162. ! deviate on a 32 bit machine
  163. ! not more than +-65 years from
  164. ! any year actually used in the
  165. ! model runs----> iyear0 now just the run year
  166. !
  167. ! date/times are expressed as yr,month,day,hour,min,sec
  168. !
  169. ! idatei(6) integer (1980 1 1 0 0 0) date/time for start of model run
  170. ! idatee(6) integer (1980 1 1 0 0 0) date/time for end of model run
  171. ! idatet(6) integer (1980 1 1 0 0 0) date/time after which instan-
  172. ! taneous output is written (controlled
  173. ! by 'ninst')
  174. !
  175. ! okdebug logical true TM5 debugging
  176. ! itau integer current model time
  177. ! idate(6) integer date corresponding to itau
  178. ! itaui integer start time (corresponds to idatei)
  179. ! itaue integer end time (corresponds to idatee)
  180. ! itaut integer time after which instantaneous output is
  181. ! written (corresponds to idatet)
  182. ! itau0 time/date when diagnostic arrays
  183. ! idate0(6) integer were last reset
  184. ! julday0 integer julian day of base time 1st-jan-iyear0, 0h
  185. ! Needed only when icalendo == 2
  186. ! idacc(8) integer counters:
  187. ! idacc(1) no of times averaged tracer
  188. ! mix ratio is calculated
  189. ! others are not used at present
  190. ! newyr logical .true. if at beginning of a new year
  191. ! newmonth logical .true. if at beginning of a new month
  192. ! newday logical .true. if at beginning of a new day (i.e. at 00Z)
  193. ! newsrun logical .true. if at beginning of a new run or
  194. ! at beginning of a continuation run
  195. ! nstep integer advection step counter for current run
  196. ! or continuation run
  197. ! nstep0 integer not needed
  198. ! cpu0 real process time at beginning of run (in sec)
  199. ! cpu1 real process time at last reset time instant
  200. ! areag real(nregions) surface of globe and regions
  201. ! itaur integer(nregions) time counter per region
  202. !
  203. !---------------------------------------------------------------------------
  204. character(len=160) xlabel
  205. !
  206. ! variable type purpose
  207. ! -------- ---- -------
  208. !
  209. ! xlabel char*160 run text label.
  210. ! last 8 characters contain model version info
  211. !
  212. !----------------------------------------------------------------------------
  213. integer,dimension(nregions) :: unit_mix
  214. !
  215. integer,parameter :: kinput0=5
  216. ! main control output
  217. integer,parameter :: kmain=6
  218. ! secondary control input
  219. integer,parameter :: kdebug=9
  220. ! temporary scratch files
  221. integer,parameter :: ktemp1=1
  222. ! czeta real 1. scaling factor for convection
  223. ! czetak real 1. scaling factor for vertical diffusion
  224. real :: czeta,czetak
  225. ! levels not zoomed yet ...
  226. integer, parameter :: zbeg(nregions_max) = 0
  227. integer, parameter :: zend(nregions_max) = lm(1)
  228. CONTAINS
  229. !--------------------------------------------------------------------------
  230. ! TM5 !
  231. !--------------------------------------------------------------------------
  232. !BOP
  233. !
  234. ! !IROUTINE: CHECKSHAPE
  235. !
  236. ! !DESCRIPTION: compare two vectors (typically shape of arrays)
  237. !\\
  238. !\\
  239. ! !INTERFACE:
  240. !
  241. SUBROUTINE CHECKSHAPE( shp1, shp2, rc )
  242. !
  243. ! !INPUT PARAMETERS:
  244. !
  245. integer, intent(in) :: shp1(:)
  246. integer, intent(in) :: shp2(:)
  247. !
  248. ! !OUTPUT PARAMETERS:
  249. !
  250. integer, intent(out) :: rc ! return code
  251. !
  252. ! !REVISION HISTORY:
  253. ! 1 Mar 2012 - P. Le Sager - added rc output for traceback to work
  254. !
  255. ! !REMARKS:
  256. !
  257. !EOP
  258. !------------------------------------------------------------------------
  259. !BOC
  260. character(len=*), parameter :: rname = mname//', CheckShape'
  261. if ( size(shp1) /= size(shp2) ) then
  262. write(gol,'("array shapes should have same length:")'); call goErr
  263. write(gol,'(" shp1 : ",i4)') shp1 ; call goErr
  264. write(gol,'(" shp2 : ",i4)') shp2 ; call goErr
  265. rc=1
  266. IF_NOTOK_RETURN(rc=1)
  267. end if
  268. if ( any( shp1 /= shp2 ) ) then
  269. write (gol,'(" array shapes are not equal:")') ; call goErr
  270. write (gol,'(" shp1 : ",i4)') shp1 ; call goErr
  271. write (gol,'(" shp2 : ",i4)') shp2 ; call goErr
  272. rc=1
  273. IF_NOTOK_RETURN(rc=1)
  274. end if
  275. rc=0
  276. END SUBROUTINE CHECKSHAPE
  277. !EOC
  278. END MODULE DIMS