grib_table.F90 15 KB

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