grib_table.F90 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414
  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 (status/=0) then; TRACEBACK; action; return; end if
  5. #define IF_ERROR_RETURN(action) if (status> 0) then; TRACEBACK; action; return; end if
  6. !
  7. #include "tmm.inc"
  8. !
  9. !#################################################################
  10. module grib_table
  11. implicit none
  12. ! --- in/out -----------------------------------
  13. private
  14. public :: GetPid
  15. public :: GetPidName
  16. ! --- const ------------------------------
  17. character(len=*), parameter :: mname = 'grib_table'
  18. contains
  19. ! =============================================================
  20. subroutine GetPid( table, key, pid, tabid, status )
  21. use GO, only : gol, goErr
  22. ! --- in/out --------------------------------
  23. character(len=*), intent(in) :: table
  24. character(len=*), intent(in) :: key
  25. integer, intent(out) :: pid
  26. integer, intent(out) :: tabid
  27. integer, intent(out) :: status
  28. ! --- const --------------------------------------
  29. character(len=*), parameter :: rname = mname//'/GetPid'
  30. ! --- local ----------------------------------
  31. integer :: tabv
  32. ! --- begin ----------------------------------
  33. ! default table version:
  34. tabid = 128
  35. select case ( table )
  36. ! ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  37. ! ECMWF codes
  38. ! ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  39. case ( 'ec' )
  40. select case ( key )
  41. case ( 'CVL' , 'cvl' ); pid = 027 ! low vegetation cover
  42. case ( 'CVH' , 'cvh' ); pid = 028 ! high vegetation cover
  43. case ( 'TVL' , 'tvl' ); pid = 029 ! type of low vegetation
  44. case ( 'TVH' , 'tvh' ); pid = 030 ! type of high vegetation
  45. case ( 'CI' , 'ci' ); pid = 031 ! sea-ice cover
  46. case ( 'SSTK', 'sstk', 'sst' ); pid = 034 ! sea surface temperature
  47. case ( 'SWV1', 'swv1', 'swvl1' ); pid = 039 ! volumetric soil water layer 1
  48. case ( 'SWV2', 'swv2', 'swvl2' ); pid = 040 ! volumetric soil water layer 2
  49. case ( 'SWV3', 'swv3', 'swvl3' ); pid = 041 ! volumetric soil water layer 3
  50. case ( 'SWV4', 'swv4', 'swvl4' ); pid = 042 ! volumetric soil water layer 4
  51. case ( 'STL1', 'stl1' ); pid = 139 ! soil temperature layer 1
  52. case ( 'G10M', 'g10m' ); pid = 049 ! wind gust at 10m (Need to account for the following two lines)
  53. case ( '10FG', '10fg' ); pid = 049 ! wind gust at 10m 3-HOURLY (before cycle 37r3) and HOURLY accumulation (after cycle 37r3)
  54. case ( '10FG3', '10fg3' ); pid = 028; tabid=228 ! wind gust at 10m 3-HOURLY accumulation (from cycle 37r3)
  55. case ( 'PV' ); pid = 60 ! potential vorticity (K m2/kg/s)
  56. ! era40, local table 162
  57. ! NOTE: for era2004 set, local table in grib files is actually 128 (error!)
  58. case ( 'UDMF' ); pid = 104; tabid = 162 ! updraught mass flux [kg/m2]
  59. case ( 'DDMF' ); pid = 105; tabid = 162 ! downdraught mass flux [kg/m2]
  60. case ( 'UDDR' ); pid = 106; tabid = 162 ! updraught detrainment rate [kg/m3]
  61. case ( 'DDDR' ); pid = 107; tabid = 162 ! downdraught detrainment rate [kg/m3]
  62. case ( 'K', 'TDCHA' ); pid = 109; tabid = 162 ! turbulent diff. coeff. for heat [m2]
  63. ! era5:
  64. case ( 'MUMF' ); pid = 009; tabid = 235 ! mean updraught mass flux [kg/m2/s] aver prev hour
  65. case ( 'MDMF' ); pid = 010; tabid = 235 ! mean downdraught mass flux [kg/m2/s] aver prev hour
  66. case ( 'MUDR' ); pid = 011; tabid = 235 ! mean updraught detrainment rate [kg/m3/s] aver prev hour
  67. case ( 'MDDR' ); pid = 012; tabid = 235 ! mean downdraught detrainment rate [kg/m3/s] aver prev hour
  68. case ( 'MTDCH'); pid = 014; tabid = 235 ! mean turbulent diff. coeff. for heat [m2/s ] aver prev hour
  69. case ( 'U' ); pid = 131 ! u wind
  70. case ( 'V' ); pid = 132 ! v wind
  71. case ( 'Z' ); pid = 129 ! geopotential, orography at surface
  72. case ( 'oro' ); pid = 129 ! orography (geopotential at surface)
  73. case ( 'T' ); pid = 130 ! temperature
  74. case ( 'Q' ); pid = 133 ! specific humidity
  75. case ( 'SP' , 'sp' ); pid = 134
  76. case ( 'W' ); pid = 135
  77. case ( 'VO' ); pid = 138
  78. case ( 'SLW' , 'slw' ); pid = 140
  79. case ( 'SD' , 'sd' ); pid = 141
  80. #ifdef with_ec_aver
  81. case ( 'MLSPR' , 'mlspr' ); pid = 029; tabid = 235 ! Mean large-scale precipitation rate kg m-2 s-1
  82. case ( 'MCPR' , 'mcpr' ); pid = 030; tabid = 235 ! Mean convective precipitation rate kg m-2 s-1
  83. case ( 'MSR' , 'msr' ); pid = 031; tabid = 235 ! Mean snowfall rate kg m-2 s-1
  84. case ( 'MSSHF' , 'msshf' ); pid = 033; tabid = 235 ! Mean surface sensible heat flux W m-2
  85. case ( 'MSLHF' , 'mslhf' ); pid = 034; tabid = 235 ! Mean surface latent heat flux W m-2
  86. case ( 'MSDWSWRF', 'msdwswrf' ); pid = 035; tabid = 235 ! Mean surface downward short-wave radiation flux W m-2
  87. case ( 'MSDWLWRF', 'msdwlwrf' ); pid = 036; tabid = 235 ! Mean surface downward long-wave radiation flux W m-2
  88. case ( 'MSNSWRF' , 'msnswrf' ); pid = 037; tabid = 235 ! Mean surface net short-wave radiation flux W m-2
  89. case ( 'MSNLWRF' , 'msnlwrf' ); pid = 038; tabid = 235 ! Mean surface net long-wave radiation flux W m-2
  90. case ( 'METSS' , 'metss' ); pid = 041; tabid = 235 ! Mean eastward turbulent surface stress N m-2
  91. case ( 'MNTSS' , 'mntss' ); pid = 042; tabid = 235 ! Mean northward turbulent surface stress N m-2
  92. #else
  93. case ( 'LSP' , 'lsp' ); pid = 142
  94. case ( 'CP' , 'cp' ); pid = 143
  95. case ( 'SF' , 'sf' ); pid = 144
  96. case ( 'SSHF', 'sshf' ); pid = 146
  97. case ( 'SLHF', 'slhf' ); pid = 147 ! surface latent heat flux (W m**-2 s)
  98. case ( 'SSRD', 'ssrd' ); pid = 169 ! surface solar radiation downwards
  99. case ( 'STRD', 'strd' ); pid = 175 ! surface thermal radiation downwards
  100. case ( 'SSR' , 'ssr' ); pid = 176 ! surface solar radiation
  101. case ( 'STR' , 'str' ); pid = 177 ! surface thermal radiation
  102. case ( 'EWSS', 'ewss' ); pid = 180
  103. case ( 'NSSS', 'nsss' ); pid = 181
  104. #endif
  105. case ( 'LNSP', 'lnsp' ); pid = 152
  106. case ( 'D' , 'd' ); pid = 155
  107. case ( 'GH' , 'gh' ); pid = 156 ! geopotential height
  108. case ( 'BLH' , 'blh' ); pid = 159 ! boundary layer height
  109. case ( 'U10M', 'u10m' ); pid = 165
  110. case ( 'V10M', 'v10m' ); pid = 166
  111. case ( 'T2M' , 't2m' ); pid = 167
  112. case ( 'D2M' , 'd2m' ); pid = 168
  113. case ( 'LSM' , 'lsm' ); pid = 172 ! land/sea mask
  114. #ifdef with_ec_aver
  115. case ( 'z0m' , 'SR', 'sr' ); pid = 244 ! Forecast Surface Roughness (m)
  116. case ( 'AL' , 'al', 'albedo' ); pid = 243 ! Forecst Albedo (0-1)
  117. #else
  118. case ( 'z0m' , 'SR', 'sr' ); pid = 173 ! Surface Roughness (m)
  119. case ( 'AL' , 'al', 'albedo' ); pid = 174 ! Albedo (0-1)
  120. #endif
  121. case ( 'LSRH', 'lsrh' ); pid = 234 ! Log. Surf.Roughn. length for Heat
  122. case ( 'ustar' ); pid = 250
  123. case ( 'Raero' ); pid = 251
  124. case ( 'CLWC' , 'clwc' ); pid = 246 ! cloud liquid water content
  125. case ( 'CIWC' , 'ciwc' ); pid = 247 ! cloud ice water content
  126. case ( 'CC' , 'cc' ); pid = 248 ! cloud cover
  127. case ( 'SRC' , 'src' ); pid = 198 ! skin reservoir content
  128. case ( 'SKT' , 'skt' ); pid = 235 ! skin temperature
  129. case default
  130. write (gol,'("unknown key `",a,"`")') trim(key); call goErr
  131. write (gol,'(" table : ",a)') trim(table); call goErr
  132. TRACEBACK; status=1; return
  133. end select
  134. ! ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  135. ! TM codes
  136. ! ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  137. case ( 'tm' )
  138. select case ( key )
  139. case ( 'PV' ); pid = 60 ! potential vorticity (K m2/kg/s)
  140. case ( 'K' ); pid = 109 ! diffusion (m2/s)
  141. case ( 'u' ); pid = 131 ! u wind
  142. case ( 'v' ); pid = 132 ! v wind
  143. case ( 'ps' ); pid = 160 ! average surface pressure
  144. case ( 'pu' ); pid = 158 ! u flux
  145. case ( 'pv' ); pid = 159 ! v flux
  146. case ( 'pw' ); pid = 157 ! w flux
  147. case ( 'Z' ); pid = 129 ! geopotential, orography at surface
  148. case ( 'T' ); pid = 130 ! temperature
  149. case ( 'Q' ); pid = 133 ! specific humidity
  150. case ( 'GH' ); pid = 156 ! geopotential height
  151. case ( 'eu' ); pid = 161 ! entrainment updraft
  152. case ( 'du' ); pid = 162 ! detrainment updraft
  153. case ( 'ed' ); pid = 164 ! entrainment downdraft
  154. case ( 'dd' ); pid = 165 ! detrainment downdraft
  155. case ( 'dk' ); pid = 163 ! vertical diffusion coef.
  156. case ( 'clbas' ); pid = 190 ! cloud base
  157. case ( 'cltop' ); pid = 191 ! cloud top
  158. case ( 'cllfs' ); pid = 192
  159. case ( 'Kz' ); pid = 163
  160. case ( 'pblh' ); pid = 159
  161. case ( 'pblh?' ); pid = 203
  162. case ( 'lsp' ); pid = 142
  163. case ( 'cp' ); pid = 143
  164. case ( 'sf' ); pid = 144
  165. case ( 'sshf' ); pid = 146
  166. case ( 'slhf' ); pid = 147 ! surface latent heat flux (W m**-2 s)
  167. case ( 'slw' ); pid = 140
  168. case ( 'sd' ); pid = 141
  169. case ( 'T2M', 'T2m', 't2m' ); pid = 167
  170. case ( 'D2M', 'D2m', 'd2m' ); pid = 168
  171. case ( 'z0m', 'SR' ); pid = 173
  172. case ( 'al' ); pid = 174 ! Albedo (0-1)
  173. case ( 'ewss' ); pid = 180
  174. case ( 'nsss' ); pid = 181
  175. case ( 'ustar' ); pid = 250
  176. case ( 'Raero' ); pid = 251
  177. case ( 'CLWC', 'clwc' ); pid = 246 ! cloud liquid water content
  178. case ( 'CIWC', 'ciwc' ); pid = 247 ! cloud ice water content
  179. case ( 'CC' , 'cc' ); pid = 248 ! cloud cover
  180. case ( 'CCO' , 'cco' ); pid = 249 ! overhead cloud cover
  181. case ( 'CCU' , 'ccu' ); pid = 250 ! underfeet cloud cover
  182. case ( 'ssr' ); pid = 176 ! surface solar radiation
  183. case ( 'src' ); pid = 198 ! skin reservoir content
  184. case default
  185. write (gol,'("unknown key `",a,"`")') trim(key); call goErr
  186. write (gol,'(" table : ",a)') trim(table); call goErr
  187. TRACEBACK; status=1; return
  188. end select
  189. case default
  190. write (gol,'("unknown table `",a,"`")') trim(table); call goErr
  191. TRACEBACK; status=1; return
  192. end select
  193. ! ok
  194. status = 0
  195. end subroutine GetPid
  196. ! =============================================================
  197. subroutine GetPidName( table, pid, name, status )
  198. use GO, only : gol, goErr
  199. ! --- in/out ------------------------------
  200. character(len=*), intent(in) :: table
  201. integer, intent(in) :: pid
  202. character(len=*), intent(out) :: name
  203. integer, intent(out) :: status
  204. ! --- const --------------------------------------
  205. character(len=*), parameter :: rname = mname//'/GetPidName'
  206. ! --- begin -------------------------------
  207. select case ( table )
  208. ! ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  209. ! ECMWF codes
  210. ! ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  211. case ( 'ec' )
  212. select case ( pid )
  213. case ( 109 ) ; name = 'K ' ! diffusion (m2/s); experimental
  214. case ( 129 ) ; name = 'Z '
  215. case ( 130 ) ; name = 'T '
  216. case ( 131 ) ; name = 'U '
  217. case ( 132 ) ; name = 'V '
  218. case ( 133 ) ; name = 'Q '
  219. case ( 134 ) ; name = 'SP '
  220. case ( 135 ) ; name = 'W '
  221. case ( 138 ) ; name = 'VO '
  222. case ( 141 ) ; name = 'SD '
  223. case ( 142 ) ; name = 'LSP '
  224. case ( 143 ) ; name = 'CP '
  225. case ( 144 ) ; name = 'SF '
  226. case ( 146 ) ; name = 'SSHF'
  227. case ( 147 ) ; name = 'SLHF'
  228. case ( 152 ) ; name = 'LNSP'
  229. case ( 155 ) ; name = 'D '
  230. case ( 156 ) ; name = 'GH '
  231. case ( 159 ) ; name = 'BLH '
  232. case ( 165 ) ; name = 'U10M'
  233. case ( 166 ) ; name = 'V10M'
  234. case ( 167 ) ; name = 'T2M '
  235. case ( 168 ) ; name = 'D2M '
  236. case ( 172 ) ; name = 'LSM '
  237. case ( 173 ) ; name = 'SR '
  238. case ( 174 ) ; name = 'AL '
  239. case ( 176 ) ; name = 'SSR '
  240. case ( 180 ) ; name = 'EWSS'
  241. case ( 181 ) ; name = 'NSSS'
  242. case ( 198 ) ; name = 'SRC '
  243. case ( 234 ) ; name = 'LSRH'
  244. case ( 246 ) ; name = 'CLWC'
  245. case ( 247 ) ; name = 'CIWC'
  246. case ( 248 ) ; name = 'CC '
  247. case default
  248. write (name,'("p",i3.3)') pid
  249. end select
  250. ! ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  251. ! TM codes
  252. ! ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  253. case ( 'tm' )
  254. select case ( pid )
  255. case ( 104 ) ; name = 'MU ' ! updraught mass flux kg m-2
  256. case ( 105 ) ; name = 'MD ' ! downdraught mass flux kg m-2
  257. case ( 106 ) ; name = 'DU ' ! updraught detrainment rate s m-1
  258. case ( 107 ) ; name = 'DD ' ! downdraught detrainment rate s m-1
  259. case ( 109 ) ; name = 'K ' ! diffusion (m2/s); experimental
  260. case ( 129 ) ; name = 'Z '
  261. case ( 130 ) ; name = 'T '
  262. case ( 131 ) ; name = 'U '
  263. case ( 132 ) ; name = 'V '
  264. case ( 133 ) ; name = 'Q '
  265. case ( 134 ) ; name = 'SP '
  266. case ( 135 ) ; name = 'W '
  267. case ( 138 ) ; name = 'VO '
  268. case ( 141 ) ; name = 'SD '
  269. case ( 142 ) ; name = 'LSP '
  270. case ( 143 ) ; name = 'CP '
  271. case ( 144 ) ; name = 'SF '
  272. case ( 146 ) ; name = 'SSHF'
  273. case ( 147 ) ; name = 'SLHF'
  274. case ( 152 ) ; name = 'LNSP'
  275. case ( 155 ) ; name = 'D '
  276. case ( 156 ) ; name = 'zg ' ! ECMWF : GH
  277. case ( 157 ) ; name = 'pw '
  278. case ( 158 ) ; name = 'pu '
  279. case ( 159 ) ; name = 'pv '
  280. case ( 160 ) ; name = 'sp '
  281. case ( 161 ) ; name = 'eu '
  282. case ( 162 ) ; name = 'du '
  283. case ( 163 ) ; name = 'dk '
  284. case ( 164 ) ; name = 'ed '
  285. case ( 165 ) ; name = 'dd '
  286. case ( 167 ) ; name = 'T2M '
  287. case ( 168 ) ; name = 'D2M '
  288. case ( 172 ) ; name = 'LSM '
  289. case ( 173 ) ; name = 'SR '
  290. case ( 174 ) ; name = 'AL '
  291. case ( 176 ) ; name = 'SSR '
  292. case ( 180 ) ; name = 'EWSS'
  293. case ( 181 ) ; name = 'NSSS'
  294. case ( 190 ) ; name = 'clb '
  295. case ( 191 ) ; name = 'clt '
  296. case ( 192 ) ; name = 'clfs'
  297. case ( 198 ) ; name = 'SRC '
  298. case ( 203 ) ; name = 'blh ' ! ECMWF's BLH has code 159, but this is pv in TM ...
  299. case ( 234 ) ; name = 'LSRH'
  300. case ( 246 ) ; name = 'CLWC'
  301. case ( 247 ) ; name = 'CIWC'
  302. case ( 248 ) ; name = 'CC '
  303. case ( 249 ) ; name = 'cco '
  304. case ( 250 ) ; name = 'ccu '
  305. case default
  306. write (name,'("p",i3.3)') pid
  307. end select
  308. case default
  309. write (gol,'("unknown table `",a,"`")') trim(table); call goErr
  310. TRACEBACK; status=1; return
  311. end select
  312. ! ok
  313. status = 0
  314. end subroutine GetPidName
  315. end module grib_table