dims.F90 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318
  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 :: itau,itaui,itaue,itaut,itau0,nwrite, nsrce
  90. integer,dimension(nregions) :: itaur ! itau count for the different regions
  91. integer :: nread = 6*3600
  92. ! read of 6-hourly fields is staggered with three hours.
  93. integer,parameter :: staggered = 3*3600
  94. integer :: ndyn, ndiff, nchem, nconv
  95. integer :: ndyn_max
  96. integer,dimension(6) :: idate,idatei,idatee,idatet,idate0,sdate_simulation
  97. logical :: newyr,newmonth,newday,newsrun,newhour(nregions)
  98. integer :: julday0,iyear0
  99. integer :: icalendo
  100. integer :: ndiagp1,ndiagp2
  101. integer :: nstep,nstep0
  102. real :: cpu0,cpu1
  103. real,dimension(nregions) :: areag
  104. ! main control variables, accessible through namelist 'inputz'
  105. ! all times (unless noted) are given in seconds.
  106. ! internally model time is kept in seconds (variables itau...) since
  107. ! 1st-jan-iyear0, 00:00:00
  108. ! (iyear0 now defined as the actual year at start)
  109. !---------------------------------------------------------------------------
  110. ! name type default purpose
  111. ! ---- ---- ------- -------
  112. !
  113. ! ndyn integer 1*3600 length of full advection step
  114. ! nconv integer 1*3600 interval for convection calculation
  115. ! ndiff integer 0 interval for horizontal diffusion calc
  116. ! nchem integer 0 interval for chemistry calculations
  117. ! nsrce integer 24*3600 interval for source calculation
  118. ! limits logical .true. if set to .true. then
  119. ! the slopes are limited
  120. ! such that no negative tracer
  121. ! masses should occur
  122. ! istart integer 10 start/restart options:
  123. ! 1 coldstart with initial fields set to 0
  124. ! 2 coldstart with initial fields computed
  125. ! in sr trace1 in sources_sinks...
  126. ! 3 coldstart with initial
  127. ! fields read from model output (save file)
  128. ! 4 coldstart with initial
  129. ! fields read from model output stored
  130. ! in mixing ratio (no slopes).
  131. ! nread integer 12*3600 interval for input of massfluxes and convection info
  132. ! nwrite integer 0 interval for alternate output of restart
  133. ! status on files save1.b and save2.b
  134. ! ninst integer 0 interval for output of instantaneous
  135. ! tracer mix ratio fields
  136. ! ncheck integer 0 interval for output of tracer mix ratio
  137. ! at checkpoints
  138. ! ndiag integer 12*3600 interval for computing mean quantities
  139. !CMK ndiagp1 and ndiagp2 not implemented yet...
  140. ! ndiagp1 integer -2 interval for output of
  141. ! -1 daily
  142. ! -2 monthly
  143. ! -3 yearly
  144. ! >=0 interval in seconds
  145. ! ndiagp2 integer -2 interval for output of time averaged fields
  146. ! -1 daily
  147. ! -2 monthly
  148. ! -3 yearly
  149. ! >=0 interval in seconds
  150. !
  151. ! name type default purpose
  152. ! ---- ---- ------- -------
  153. !
  154. ! icalendo integer 2 calendar type
  155. ! 1 permanent 360 day year calendar
  156. ! 2 real calendar
  157. ! 3 permanent 365 day year calendar
  158. ! 4 permanent 366 day year calendar
  159. ! iyear0 integer 1980 base year for calendar calculations
  160. ! (because of overflow problems this should
  161. ! deviate on a 32 bit machine
  162. ! not more than +-65 years from
  163. ! any year actually used in the
  164. ! model runs----> iyear0 now just the run year
  165. !
  166. ! date/times are expressed as yr,month,day,hour,min,sec
  167. !
  168. ! idatei(6) integer (1980 1 1 0 0 0) date/time for start of model run
  169. ! idatee(6) integer (1980 1 1 0 0 0) date/time for end of model run
  170. ! idatet(6) integer (1980 1 1 0 0 0) date/time after which instan-
  171. ! taneous output is written (controlled
  172. ! by 'ninst')
  173. !
  174. ! okdebug logical true TM5 debugging
  175. ! itau integer current model time
  176. ! idate(6) integer date corresponding to itau
  177. ! itaui integer start time (corresponds to idatei)
  178. ! itaue integer end time (corresponds to idatee)
  179. ! itaut integer time after which instantaneous output is
  180. ! written (corresponds to idatet)
  181. ! itau0 time/date when diagnostic arrays
  182. ! idate0(6) integer were last reset
  183. ! julday0 integer julian day of base time 1st-jan-iyear0, 0h
  184. ! Needed only when icalendo == 2
  185. ! idacc(8) integer counters:
  186. ! idacc(1) no of times averaged tracer
  187. ! mix ratio is calculated
  188. ! others are not used at present
  189. ! newyr logical .true. if at beginning of a new year
  190. ! newmonth logical .true. if at beginning of a new month
  191. ! newday logical .true. if at beginning of a new day (i.e. at 00Z)
  192. ! newsrun logical .true. if at beginning of a new run or
  193. ! at beginning of a continuation run
  194. ! nstep integer advection step counter for current run
  195. ! or continuation run
  196. ! nstep0 integer not needed
  197. ! cpu0 real process time at beginning of run (in sec)
  198. ! cpu1 real process time at last reset time instant
  199. ! areag real(nregions) surface of globe and regions
  200. ! itaur integer(nregions) time counter per region
  201. !
  202. !---------------------------------------------------------------------------
  203. character(len=160) xlabel
  204. !
  205. ! variable type purpose
  206. ! -------- ---- -------
  207. !
  208. ! xlabel char*160 run text label.
  209. ! last 8 characters contain model version info
  210. !
  211. !----------------------------------------------------------------------------
  212. integer,dimension(nregions) :: unit_mix
  213. !
  214. integer,parameter :: kinput0=5
  215. ! main control output
  216. integer,parameter :: kmain=6
  217. ! secondary control input
  218. integer,parameter :: kdebug=9
  219. ! temporary scratch files
  220. integer,parameter :: ktemp1=1
  221. ! czeta real 1. scaling factor for convection
  222. ! czetak real 1. scaling factor for vertical diffusion
  223. real :: czeta,czetak
  224. ! levels not zoomed yet ...
  225. integer, parameter :: zbeg(nregions_max) = 0
  226. integer, parameter :: zend(nregions_max) = lm(1)
  227. CONTAINS
  228. !--------------------------------------------------------------------------
  229. ! TM5 !
  230. !--------------------------------------------------------------------------
  231. !BOP
  232. !
  233. ! !IROUTINE: CHECKSHAPE
  234. !
  235. ! !DESCRIPTION: compare two vectors (typically shape of arrays)
  236. !\\
  237. !\\
  238. ! !INTERFACE:
  239. !
  240. SUBROUTINE CHECKSHAPE( shp1, shp2, rc )
  241. !
  242. ! !INPUT PARAMETERS:
  243. !
  244. integer, intent(in) :: shp1(:)
  245. integer, intent(in) :: shp2(:)
  246. !
  247. ! !OUTPUT PARAMETERS:
  248. !
  249. integer, intent(out) :: rc ! return code
  250. !
  251. ! !REVISION HISTORY:
  252. ! 1 Mar 2012 - P. Le Sager - added rc output for traceback to work
  253. !
  254. ! !REMARKS:
  255. !
  256. !EOP
  257. !------------------------------------------------------------------------
  258. !BOC
  259. character(len=*), parameter :: rname = mname//', CheckShape'
  260. if ( size(shp1) /= size(shp2) ) then
  261. write(gol,'("array shapes should have same length:")'); call goErr
  262. write(gol,'(" shp1 : ",i4)') shp1 ; call goErr
  263. write(gol,'(" shp2 : ",i4)') shp2 ; call goErr
  264. rc=1
  265. IF_NOTOK_RETURN(rc=1)
  266. end if
  267. if ( any( shp1 /= shp2 ) ) then
  268. write (gol,'(" array shapes are not equal:")') ; call goErr
  269. write (gol,'(" shp1 : ",i4)') shp1 ; call goErr
  270. write (gol,'(" shp2 : ",i4)') shp2 ; call goErr
  271. rc=1
  272. IF_NOTOK_RETURN(rc=1)
  273. end if
  274. rc=0
  275. END SUBROUTINE CHECKSHAPE
  276. !EOC
  277. END MODULE DIMS