tmm_mf_grib.F90 60 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801
  1. !###############################################################################
  2. !
  3. ! Input/output of meteofiles : grib version.
  4. !
  5. !### macro's ###################################################################
  6. !
  7. #define TRACEBACK write (gol,'("in ",a," (",a,", line",i5,")")') rname, __FILE__, __LINE__; call goErr
  8. #define IF_NOTOK_RETURN(action) if (status/=0) then; TRACEBACK; action; return; end if
  9. #define IF_ERROR_RETURN(action) if (status> 0) then; TRACEBACK; action; return; end if
  10. !
  11. #include "tmm.inc"
  12. !
  13. !###############################################################################
  14. module tmm_mf_grib
  15. use GO , only : gol, goErr, goPr
  16. use GO , only : TDate
  17. use file_grib, only : TGribFile
  18. implicit none
  19. ! --- in/out ----------------------------
  20. private
  21. public :: TMeteoFile_grib
  22. public :: Init, Done
  23. public :: Get
  24. public :: ReadRecord
  25. ! --- const ------------------------------
  26. character(len=*), parameter :: mname = 'tmm_mf_grib'
  27. !--- type ---------------------------------
  28. type TMeteoFile_grib
  29. ! file name:
  30. character(len=256) :: fname
  31. ! time range covered by file:
  32. type(TDate) :: trange(2)
  33. logical :: constant
  34. ! other time keys for this file:
  35. character(len=16) :: treskey
  36. type(TDate) :: tday
  37. ! current time range covered by grib record:
  38. type(TDate) :: tref, t1, t2
  39. !
  40. ! file description
  41. !
  42. character(len=16) :: ec_class, ec_type
  43. character(len=256) :: paramkeys
  44. !
  45. ! 3d field
  46. !
  47. type(TGribFile) :: grib
  48. !
  49. ! surface pressure field
  50. !
  51. logical :: do_spm
  52. character(len=256) :: spm_fname
  53. type(TGribFile) :: spm_grib
  54. logical :: spm_lnsp2sp
  55. !
  56. end type TMeteoFile_grib
  57. ! --- interfaces -------------------------
  58. interface Init
  59. module procedure mf_Init
  60. end interface
  61. interface Done
  62. module procedure mf_Done
  63. end interface
  64. interface Get
  65. module procedure mf_Get
  66. end interface
  67. interface ReadRecord
  68. module procedure mf_ReadRecord
  69. end interface
  70. contains
  71. ! ==============================================================
  72. ! ====
  73. ! ==== original
  74. ! ====
  75. ! ==============================================================
  76. subroutine mf_Init( mf, dir, archivekeys, paramkey, &
  77. tday, t1, t2, status )
  78. use GO, only : TDate, Get, NewDate, operator(>)
  79. use GO, only : goVarValue, goWriteKeyNum
  80. ! --- in/out ----------------------------
  81. type(TMeteoFile_grib), intent(out) :: mf
  82. character(len=*), intent(in) :: dir
  83. character(len=*), intent(in) :: archivekeys
  84. character(len=*), intent(in) :: paramkey
  85. type(TDate), intent(in) :: tday, t1, t2
  86. integer, intent(out) :: status
  87. ! --- const --------------------------------------
  88. character(len=*), parameter :: rname = mname//'/mf_Init'
  89. ! --- local --------------------------------
  90. character(len=16) :: form
  91. character(len=16) :: ec_class, ec_type, ec_tres, ec_levs, mfile
  92. integer :: ec_sh, ec_gg
  93. character(len=16) :: grid, gridN, gridT
  94. character(len=16) :: levs
  95. character(len=16) :: spm_tres
  96. type(TDate) :: tfile
  97. integer :: ccyy, mm, dd
  98. type(TDate) :: tc
  99. logical :: exist
  100. ! --- begin --------------------------------
  101. !
  102. ! extract fields from archivekey :
  103. ! form=tmpp;class=od;type=fg;nlev=60;sh=159;gg=80;tres=_fg006up4tr3
  104. !
  105. form = 'tmpp'
  106. call goVarValue( archivekeys, ';', 'form', '=', form, status )
  107. IF_ERROR_RETURN(status=1)
  108. !
  109. ec_class = 'od'
  110. call goVarValue( archivekeys, ';', 'class', '=', ec_class, status )
  111. IF_ERROR_RETURN(status=1)
  112. !
  113. ec_type = 'fc'
  114. call goVarValue( archivekeys, ';', 'type', '=', ec_type, status )
  115. IF_ERROR_RETURN(status=1)
  116. !
  117. ec_levs = 'ml60'
  118. call goVarValue( archivekeys, ';', 'levs', '=', ec_levs, status )
  119. IF_ERROR_RETURN(status=1)
  120. !
  121. ec_sh = 159
  122. call goVarValue( archivekeys, ';', 'sh', '=', ec_sh, status )
  123. IF_ERROR_RETURN(status=1)
  124. !
  125. ec_gg = 80
  126. call goVarValue( archivekeys, ';', 'gg', '=', ec_gg, status )
  127. IF_ERROR_RETURN(status=1)
  128. !
  129. ec_tres = ''
  130. call goVarValue( archivekeys, ';', 'tres', '=', ec_tres, status )
  131. IF_ERROR_RETURN(status=1)
  132. ! >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
  133. ! fg data available up to 2000-09-12 00:00 ; after, use fc data:
  134. if ( ec_tres == '_fg006up4tr3' ) then
  135. tc = NewDate( 2000, 09, 12, 00, 00, 00 )
  136. if ( t1 > tc ) then
  137. write (gol,'(" WARNING - using fc data after 2000-09-12 00:00")'); call goPr
  138. ec_type = 'fc'
  139. ec_tres = '_fc012up2tr3'
  140. end if
  141. end if
  142. ! <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
  143. ! store some values ...
  144. mf%ec_class = ec_class
  145. mf%ec_type = ec_type
  146. ! Date of the first forecast with cycle 37r3
  147. tc = NewDate( 2011, 11, 15, 12, 00, 00 )
  148. !
  149. ! meteo file
  150. !
  151. ! grid : T159, N80, etc
  152. call goWriteKeyNum( gridT, 'T', ec_sh )
  153. call goWriteKeyNum( gridN, 'N', ec_gg )
  154. ! defaults
  155. levs = ec_levs
  156. grid = 'Xxx'
  157. mfile = trim(paramkey)
  158. mf%paramkeys = '-'//trim(paramkey)//'-'
  159. mf%constant = .false.
  160. mf%do_spm = .false.
  161. mf%spm_fname = 'none'
  162. mf%spm_lnsp2sp = .false.
  163. spm_tres = ec_tres
  164. ! specials
  165. select case ( paramkey )
  166. case ( 'LNSP' )
  167. levs = 'ml1'
  168. grid = gridT
  169. if ( form /= '3hr' ) ec_tres = '_03p03'
  170. case ( 'VO', 'D' )
  171. mfile = 'VOD'
  172. mf%paramkeys = '-VO-D-'
  173. grid = gridT
  174. mf%do_spm = .true.
  175. spm_tres = '_03p03'
  176. if ( form == '3hr' ) then
  177. mfile = paramkey
  178. mf%paramkeys = '-'//trim(paramkey)//'-'
  179. spm_tres = ec_tres
  180. end if
  181. case ( 'T', 'W' )
  182. grid = gridT
  183. mf%do_spm = .true.
  184. spm_tres = '_03p03'
  185. if ( form == '3hr' ) then
  186. spm_tres = ec_tres
  187. end if
  188. case ( 'Q' )
  189. grid = gridN
  190. mf%do_spm = .true.
  191. spm_tres = '_03p03'
  192. mf%spm_lnsp2sp = .true.
  193. if ( form == '3hr' ) then
  194. spm_tres = ec_tres
  195. end if
  196. case ( 'CLWC', 'CIWC', 'CC', 'CCO', 'CCU' )
  197. grid = gridN
  198. mfile = 'CLD'
  199. mf%paramkeys = '-CLWC-CIWC-CC-CCO-CCU-'
  200. mf%do_spm = .true.
  201. spm_tres = '_03p03'
  202. mf%spm_lnsp2sp = .true.
  203. if ( form == '3hr' ) then
  204. spm_tres = ec_tres
  205. end if
  206. case ( 'oro' )
  207. levs = 'sfc'
  208. grid = gridN
  209. mf%constant = .true.
  210. ec_tres = 'const'
  211. case ( 'lsm' )
  212. levs = 'sfc'
  213. grid = gridN
  214. mf%constant = .true.
  215. case ( 'cvl', 'cvh', 'tvl', 'tvh', 'sr', 'al', 'lsrh' )
  216. ec_type = 'an'
  217. levs = 'sfc'
  218. grid = gridN
  219. mfile = 'S0'
  220. mf%paramkeys = '-cvl-cvh-tvl-tvh-sr-al-lsrh-'
  221. ec_tres = '_06p06'
  222. ! Before cycle 37r3
  223. ! case ( 'ci', 'swvl1', 'swvl2', 'swvl3', 'swvl4', '10fg', 'sd', 'lsp', &
  224. ! 'cp', 'sf', 'sshf', 'slhf', 'blh', 'u10m', 'v10m', 't2m', 'd2m', &
  225. ! 'ssr', 'ewss', 'nsss', 'sstr' ,'src' )
  226. ! levs = 'sfc'
  227. ! grid = gridN
  228. ! mfile = 'S1'
  229. ! mf%paramkeys = '-'
  230. ! mf%paramkeys = trim(mf%paramkeys)//'ci-swvl1-swvl2-swvl3-swvl4-10fg-sd-lsp-'
  231. ! mf%paramkeys = trim(mf%paramkeys)//'cp-sf-sshf-slhf-blh-10u-10v-2t-2d-'
  232. ! mf%paramkeys = trim(mf%paramkeys)//'ssr-ewss-nsss-sstr-src-'
  233. ! ec_tres = '_03p03'
  234. ! After cycle 37r3
  235. case ( 'ci', 'swvl1', 'swvl2', 'swvl3', 'swvl4', '10fg','10fg3', 'sd', 'lsp', &
  236. 'cp', 'sf', 'sshf', 'slhf', 'blh', 'u10m', 'v10m', 't2m', 'd2m', &
  237. 'ssr', 'ewss', 'nsss', 'sstr' ,'src' )
  238. levs = 'sfc'
  239. grid = gridN
  240. mfile = 'S1'
  241. mf%paramkeys = '-'
  242. ! Before or after cycle 37r3
  243. if ( (t1 > tc).and.(trim(ec_class)=='od') ) then
  244. mf%paramkeys = trim(mf%paramkeys)//'ci-swvl1-swvl2-swvl3-swvl4-10fg3-sd-lsp-'
  245. else
  246. mf%paramkeys = trim(mf%paramkeys)//'ci-swvl1-swvl2-swvl3-swvl4-10fg-sd-lsp-'
  247. end if
  248. mf%paramkeys = trim(mf%paramkeys)//'cp-sf-sshf-slhf-blh-10u-10v-2t-2d-'
  249. mf%paramkeys = trim(mf%paramkeys)//'ssr-ewss-nsss-sstr-src-'
  250. ec_tres = '_03p03'
  251. end select
  252. ! convert input times to file name times:
  253. call GetGribTime( ec_tres, tday, t1, t2, status, tfile=tfile, trange=mf%trange )
  254. IF_NOTOK_RETURN(status=1)
  255. ! store some time params
  256. mf%treskey = ec_tres
  257. if ( ec_type == 'an' ) mf%treskey = 'an'//ec_tres
  258. mf%tday = tday
  259. ! create file name:
  260. ! dir/od-fc-2000-01-ml60-T159-T_20000101_fg006up4tr3.gb
  261. select case ( paramkey )
  262. case ( 'oro' )
  263. write (mf%fname,'(a,"/",a,"-",a,"-",i4.4,"-",i2.2,"-",a,"-",a,"-",a,a)') &
  264. trim(dir), &
  265. trim(ec_class), trim(ec_type), 0000, 00, trim(levs), trim(grid), &
  266. 'Z', '.gb'
  267. case ( 'lsm' )
  268. write (mf%fname,'(a,"/",a,"-",a,"-",i4.4,"-",i2.2,"-",a,"-",a,"-",a,a)') &
  269. trim(dir), &
  270. trim(ec_class), trim(ec_type), 0000, 00, trim(levs), trim(grid), &
  271. 'LSM', '.gb'
  272. case default
  273. ! extract time values:
  274. call Get( tfile, year=ccyy, month=mm, day=dd )
  275. ! path and file include date:
  276. write (mf%fname,'(a,"/",a,"-",a,"-",i4.4,"-",i2.2,"-",a,"-",a,"-",a,"_",i4.4,2i2.2,a,a)') &
  277. trim(dir), &
  278. trim(ec_class), trim(ec_type), ccyy, mm, trim(levs), trim(grid), &
  279. trim(mfile), ccyy, mm, dd, trim(ec_tres), '.gb'
  280. end select
  281. ! exist ?
  282. inquire( file=mf%fname, exist=exist )
  283. if ( .not. exist ) then
  284. write (gol,'("grib file does not exist:")'); call goErr
  285. write (gol,'(" ",a)') trim(mf%fname); call goErr
  286. write (gol,'("in ",a)') rname; call goErr; status=1; return
  287. end if
  288. !
  289. ! sp or lnsp ?
  290. !
  291. if ( mf%do_spm ) then
  292. ! grid : T159
  293. grid = gridT
  294. ! levels: ml1
  295. levs = 'ml1'
  296. ! create file name:
  297. ! dir/od-fc-2000-01-ml60-T159-T_20000101_fg006up4tr3.gb
  298. write (mf%spm_fname,'(a,"/",a,"-",a,"-",i4.4,"-",i2.2,"-",a,"-",a,"-",a,"_",i4.4,2i2.2,a,a)') &
  299. trim(dir), &
  300. trim(ec_class), trim(ec_type), ccyy, mm, trim(levs), trim(grid), &
  301. 'LNSP', ccyy, mm, dd, trim(spm_tres), '.gb'
  302. ! exist ?
  303. inquire( file=mf%spm_fname, exist=exist )
  304. if ( .not. exist ) then
  305. write (gol,'("grib file does not exist:")'); call goErr
  306. write (gol,'(" ",a)') trim(mf%spm_fname); call goErr
  307. write (gol,'("in ",a)') rname; call goErr; status=1; return
  308. end if
  309. end if
  310. ! ok
  311. status = 0
  312. end subroutine mf_Init
  313. ! ***
  314. subroutine mf_Done( mf, status )
  315. use file_grib, only : Done
  316. ! --- in/out ------------------------------------
  317. type(TMeteoFile_grib), intent(inout) :: mf
  318. integer, intent(out) :: status
  319. ! --- const --------------------------------------
  320. character(len=*), parameter :: rname = mname//'/mf_Done'
  321. ! --- begin -------------------------------------
  322. ! nothing to be done ...
  323. ! ok
  324. status = 0
  325. end subroutine mf_Done
  326. ! ***
  327. subroutine mf_Get( mf, status, trange1, trange2, paramkeys )
  328. use GO, only : TDate
  329. ! --- in/out ----------------------------
  330. type(TMeteoFile_grib), intent(in) :: mf
  331. integer, intent(out) :: status
  332. type(TDate), intent(out), optional :: trange1, trange2
  333. character(len=*), intent(out), optional :: paramkeys
  334. ! --- const --------------------------------------
  335. character(len=*), parameter :: rname = mname//'/mf_Get'
  336. ! --- local --------------------------------
  337. ! --- begin --------------------------------
  338. ! time range:
  339. if ( present(trange1) ) trange1 = mf%trange(1)
  340. if ( present(trange2) ) trange2 = mf%trange(2)
  341. ! contents:
  342. if ( present(paramkeys) ) paramkeys = trim(mf%paramkeys)
  343. ! ok
  344. status = 0
  345. end subroutine mf_Get
  346. ! ***
  347. subroutine mf_ReadRecord( mf, paramkey, t1, t2, nuv, nw, &
  348. gridtype, levi, &
  349. lli, ll, sp_ll, &
  350. ggi, gg, sp_gg, &
  351. shi, sh, lnsp_sh, &
  352. tmi, status )
  353. use parray , only : pa_Init, pa_Done
  354. use GO , only : TDate
  355. use Grid , only : TLevelInfo
  356. use Grid , only : TllGridInfo, TggGridInfo, TshGridInfo
  357. use tmm_info , only : TMeteoInfo
  358. ! --- in/out -------------------------------
  359. type(TMeteoFile_grib), intent(inout) :: mf
  360. character(len=*), intent(in) :: paramkey
  361. type(TDate), intent(in) :: t1, t2
  362. character(len=1), intent(in) :: nuv
  363. character(len=1), intent(in) :: nw
  364. character(len=2), intent(out) :: gridtype
  365. type(TLevelInfo), intent(out) :: levi
  366. type(TllGridInfo), intent(inout) :: lli
  367. real, pointer :: ll(:,:,:)
  368. real, pointer :: sp_ll(:,:)
  369. type(TggGridInfo), intent(inout) :: ggi
  370. real, pointer :: gg(:,:)
  371. real, pointer :: sp_gg(:)
  372. type(TshGridInfo), intent(inout) :: shi
  373. complex, pointer :: sh(:,:)
  374. complex, pointer :: lnsp_sh(:)
  375. type(TMeteoInfo), intent(out) :: tmi
  376. integer, intent(out) :: status
  377. ! --- const --------------------------------------
  378. character(len=*), parameter :: rname = mname//'/mf_ReadRecord'
  379. ! --- local -------------------------------
  380. real, pointer :: ll2(:,:,:)
  381. real, pointer :: gg2(:,:)
  382. complex, pointer :: sh2(:,:)
  383. ! --- begin ---------------------------------
  384. ! combined field ?
  385. select case ( paramkey )
  386. case ( 'sstr' )
  387. ! read first field:
  388. call mf_ReadRecord_1( mf, 'ewss', t1, t2, nuv, nw, &
  389. gridtype, levi, &
  390. lli, ll, sp_ll, &
  391. ggi, gg, sp_gg, &
  392. shi, sh, lnsp_sh, &
  393. tmi, status )
  394. IF_NOTOK_RETURN(status=1)
  395. ! init pointer:
  396. call pa_Init( ll2 )
  397. call pa_Init( gg2 )
  398. call pa_Init( sh2 )
  399. ! read second field:
  400. call mf_ReadRecord_1( mf, 'nsss', t1, t2, nuv, nw, &
  401. gridtype, levi, &
  402. lli, ll2, sp_ll, &
  403. ggi, gg2, sp_gg, &
  404. shi, sh2, lnsp_sh, &
  405. tmi, status )
  406. IF_NOTOK_RETURN(status=1)
  407. ! process:
  408. select case ( gridtype )
  409. case ( 'll' ) ; ll = sqrt( ll**2 + ll2**2 )
  410. case ( 'gg' ) ; gg = sqrt( gg**2 + gg2**2 )
  411. case ( 'sh' ) ; sh = sqrt( sh**2 + sh2**2 )
  412. case default
  413. write (gol,'("unsupported gridtype for substract :",a)') gridtype; call goErr
  414. write (gol,'("in ",a)') rname; call goErr; status=1; return
  415. end select
  416. ! clear pointers:
  417. call pa_Done( ll2 )
  418. call pa_Done( gg2 )
  419. call pa_Done( sh2 )
  420. case default
  421. call mf_ReadRecord_1( mf, paramkey, t1, t2, nuv, nw, &
  422. gridtype, levi, &
  423. lli, ll, sp_ll, &
  424. ggi, gg, sp_gg, &
  425. shi, sh, lnsp_sh, &
  426. tmi, status )
  427. IF_NOTOK_RETURN(status=1)
  428. end select
  429. ! ok
  430. status = 0
  431. end subroutine mf_ReadRecord
  432. ! ***
  433. subroutine mf_ReadRecord_1( mf, paramkey, t1, t2, nuv, nw, &
  434. gridtype, levi, &
  435. lli, ll, sp_ll, &
  436. ggi, gg, sp_gg, &
  437. shi, sh, lnsp_sh, &
  438. tmi, status )
  439. use parray , only : pa_Init, pa_Done
  440. use GO , only : TDate, operator(<), operator(-), rTotal, wrtgol
  441. use Grid , only : TLevelInfo
  442. use Grid , only : TllGridInfo, TggGridInfo, TshGridInfo
  443. use tmm_info , only : TMeteoInfo
  444. ! --- in/out -------------------------------
  445. type(TMeteoFile_grib), intent(inout) :: mf
  446. character(len=*), intent(in) :: paramkey
  447. type(TDate), intent(in) :: t1, t2
  448. character(len=1), intent(in) :: nuv
  449. character(len=1), intent(in) :: nw
  450. character(len=2), intent(out) :: gridtype
  451. type(TLevelInfo), intent(out) :: levi
  452. type(TllGridInfo), intent(inout) :: lli
  453. real, pointer :: ll(:,:,:)
  454. real, pointer :: sp_ll(:,:)
  455. type(TggGridInfo), intent(inout) :: ggi
  456. real, pointer :: gg(:,:)
  457. real, pointer :: sp_gg(:)
  458. type(TshGridInfo), intent(inout) :: shi
  459. complex, pointer :: sh(:,:)
  460. complex, pointer :: lnsp_sh(:)
  461. type(TMeteoInfo), intent(out) :: tmi
  462. integer, intent(out) :: status
  463. ! --- const --------------------------------------
  464. character(len=*), parameter :: rname = mname//'/mf_ReadRecord_1'
  465. ! --- local -------------------------------
  466. type(TDate) :: tref
  467. real, pointer :: ll1(:,:,:)
  468. real, pointer :: gg1(:,:)
  469. complex, pointer :: sh1(:,:)
  470. real :: dt_sec
  471. ! --- begin ---------------------------------
  472. ! accumulated field ?
  473. select case ( paramkey )
  474. ! ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  475. ! accumulated fields
  476. ! ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  477. case ( 'lsp', 'cp', 'sf', 'sshf', 'slhf', 'ssr', 'ewss', 'nsss' )
  478. ! get reference time for requested time interval:
  479. call GetGribTime( mf%treskey, mf%tday, t1, t2, status, tref=tref )
  480. IF_NOTOK_RETURN(status=1)
  481. ! should be a time interval ...
  482. if ( .not. (t1 < t2) ) then
  483. write (gol,'("accumulated fields requires time interval:")'); call goErr
  484. write (gol,'(" paramkey : ",a)') paramkey; call goErr
  485. call wrtgol( ' t1 : ', t1 ); call goErr
  486. call wrtgol( ' t2 : ', t2 ); call goErr
  487. write (gol,'("in ",a)') rname; call goErr; status=1; return
  488. end if
  489. ! read field accumulated over [tref,t2] :
  490. call mf_ReadRecord_2( mf, paramkey, tref, t2, t2, nuv, nw, &
  491. gridtype, levi, &
  492. lli, ll, sp_ll, &
  493. ggi, gg, sp_gg, &
  494. shi, sh, lnsp_sh, &
  495. tmi, status )
  496. IF_NOTOK_RETURN(status=1)
  497. ! substract [tref,t1] if necessary:
  498. if ( tref < t1 ) then
  499. ! init pointer:
  500. call pa_Init( ll1 )
  501. call pa_Init( gg1 )
  502. call pa_Init( sh1 )
  503. ! read field accumulated over [tref,t1] :
  504. call mf_ReadRecord_2( mf, paramkey, tref, t1, t1, nuv, nw, &
  505. gridtype, levi, &
  506. lli, ll1, sp_ll, &
  507. ggi, gg1, sp_gg, &
  508. shi, sh1, lnsp_sh, &
  509. tmi, status )
  510. IF_NOTOK_RETURN(status=1)
  511. ! substract:
  512. select case ( gridtype )
  513. case ( 'll' ) ; ll = ll - ll1
  514. case ( 'gg' ) ; gg = gg - gg1
  515. case ( 'sh' ) ; sh = sh - sh1
  516. case default
  517. write (gol,'("unsupported gridtype for substract :",a)') gridtype; call goErr
  518. write (gol,'("in ",a)') rname; call goErr; status=1; return
  519. end select
  520. ! clear pointers:
  521. call pa_Done( ll1 )
  522. call pa_Done( gg1 )
  523. call pa_Done( sh1 )
  524. end if
  525. ! return time averages only:
  526. dt_sec = rTotal( t2 - t1, 'sec' )
  527. select case ( gridtype )
  528. case ( 'll' ) ; ll = ll / dt_sec
  529. case ( 'gg' ) ; gg = gg / dt_sec
  530. case ( 'sh' ) ; sh = sh / dt_sec
  531. case default
  532. write (gol,'("unsupported gridtype for time average :",a)') gridtype; call goErr
  533. write (gol,'("in ",a)') rname; call goErr; status=1; return
  534. end select
  535. ! ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  536. ! instantaneous fields
  537. ! ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  538. case default
  539. ! get reference time for requested time interval:
  540. call GetGribTime( mf%treskey, mf%tday, t1, t2, status, tref=tref )
  541. IF_NOTOK_RETURN(status=1)
  542. ! just read ..
  543. call mf_ReadRecord_2( mf, paramkey, tref, t1, t2, nuv, nw, &
  544. gridtype, levi, &
  545. lli, ll, sp_ll, &
  546. ggi, gg, sp_gg, &
  547. shi, sh, lnsp_sh, &
  548. tmi, status )
  549. IF_NOTOK_RETURN(status=1)
  550. end select
  551. ! ok
  552. status = 0
  553. end subroutine mf_ReadRecord_1
  554. ! ***
  555. subroutine mf_ReadRecord_2( mf, paramkey, tref, t1, t2, nuv, nw, &
  556. gridtype, levi, &
  557. lli, ll, sp_ll, &
  558. ggi, gg, sp_gg, &
  559. shi, sh, lnsp_sh, &
  560. tmi, status )
  561. use GO , only : TDate, wrtgol
  562. use Grid , only : Init, Done
  563. use Grid , only : TLevelInfo
  564. use Grid , only : TllGridInfo, TggGridInfo, TshGridInfo
  565. use Grid , only : Interpol
  566. use file_grib , only : Init, Done, ReadRecord, Get, Check
  567. use file_grib , only : levtype_sfc, levtype_hyb
  568. use file_grib , only : gridtype_ll, gridtype_gg, gridtype_sh
  569. use grib_table, only : GetPid
  570. use PArray , only : pa_Init, pa_Done, pa_SetShape
  571. use tmm_info , only : TMeteoInfo, Init, AddHistory
  572. ! --- in/out -------------------------------
  573. type(TMeteoFile_grib), intent(inout) :: mf
  574. character(len=*), intent(in) :: paramkey
  575. type(TDate), intent(in) :: tref, t1, t2
  576. character(len=1), intent(in) :: nuv
  577. character(len=1), intent(in) :: nw
  578. character(len=2), intent(out) :: gridtype
  579. type(TLevelInfo), intent(out) :: levi
  580. type(TllGridInfo), intent(inout) :: lli
  581. real, pointer :: ll(:,:,:)
  582. real, pointer :: sp_ll(:,:)
  583. type(TggGridInfo), intent(inout) :: ggi
  584. real, pointer :: gg(:,:)
  585. real, pointer :: sp_gg(:)
  586. type(TshGridInfo), intent(inout) :: shi
  587. complex, pointer :: sh(:,:)
  588. complex, pointer :: lnsp_sh(:)
  589. type(TMeteoInfo), intent(out) :: tmi
  590. integer, intent(out) :: status
  591. ! --- const --------------------------------------
  592. character(len=*), parameter :: rname = mname//'/mf_ReadRecord_2'
  593. ! --- local -------------------------------
  594. logical :: isfirst
  595. logical :: reopened
  596. integer :: pid, tabid
  597. integer :: nlev, glevtype, glevel
  598. integer :: level
  599. integer :: ggridtype
  600. real :: lon_first, lon_inc
  601. integer :: lon_n
  602. real :: lat_first, lat_inc
  603. integer :: lat_n
  604. integer :: ggN
  605. integer :: shT
  606. integer :: greftime(5), gtimerange(4)
  607. character(len=64) :: key
  608. integer :: ilat
  609. real, pointer :: pat(:,:)
  610. type(TshGridInfo) :: tmp_shi
  611. complex, pointer :: tmp_sh(:)
  612. ! --- begin ---------------------------------
  613. ! no fluxes through boundaries ...
  614. if ( nuv /= 'n' ) then
  615. write (gol,'("unsupported nuv key : ",a)') nuv; call goErr
  616. write (gol,'("in ",a)') rname; call goErr; status=1; return
  617. end if
  618. ! init pointer arrays:
  619. call pa_Init( pat )
  620. !
  621. ! ~~~ 3d field or 2d stored in 3d array
  622. !
  623. ! open grib file
  624. call Init( mf%grib, mf%fname, 'r', status )
  625. IF_NOTOK_RETURN(status=1)
  626. ! arrays and grids not defined yet
  627. isfirst = .true.
  628. reopened = .false.
  629. ! loop over records
  630. level = 0
  631. do
  632. !
  633. ! read gribsection in file buffer
  634. !
  635. call ReadRecord( mf%grib, status )
  636. select case ( status )
  637. case ( 0 )
  638. ! no error
  639. case ( 1 )
  640. ! eof
  641. if ( .not. reopened ) then
  642. !write (*,'("grib read record: re-open ...")')
  643. ! close:
  644. call Done( mf%grib, status )
  645. IF_NOTOK_RETURN(status=1)
  646. ! reopen:
  647. call Init( mf%grib, mf%fname, 'r', status )
  648. IF_NOTOK_RETURN(status=1)
  649. reopened = .true.
  650. cycle
  651. else
  652. write (gol,'("reached eof before requested record was found")'); call goErr
  653. write (gol,'(" file : ",a)') trim(mf%fname); call goErr
  654. write (gol,'(" paramkey : ",a)') trim(paramkey); call goErr
  655. call wrtgol( ' tref : ', tref ); call goErr
  656. call wrtgol( ' t1 : ', t1 ); call goErr
  657. call wrtgol( ' t2 : ', t2 ); call goErr
  658. write (gol,'("in ",a)') rname; call goErr; status=1; return
  659. end if
  660. case default
  661. write (gol,'("error from grib ReadRecord; status=",i6)') status; call goErr
  662. write (gol,'("in ",a)') rname; call goErr; status=1; return
  663. end select
  664. !
  665. ! checks ...
  666. !
  667. ! get param id for the requested field from grib table:
  668. select case ( paramkey )
  669. case ( 'spm' ) ; call GetPid( 'ec', 'SP' , pid, tabid, status )
  670. case default ; call GetPid( 'ec', paramkey, pid, tabid, status )
  671. end select
  672. IF_NOTOK_RETURN(status=1)
  673. ! check parameter; continue if not ok:
  674. call Check( mf%grib, pid=pid, debug=0, status=status )
  675. if (status/=0) cycle
  676. ! fill times ?
  677. if ( .not. mf%constant ) then
  678. ! extract time fields from grib, store in mf%tref/mf%t1/mf%t2
  679. call SetTime( mf, status )
  680. IF_NOTOK_RETURN(status=1)
  681. ! check time:
  682. call CheckTime( mf, tref, t1, t2, status )
  683. if (status/=0) then
  684. !write (*,'("grib read record: wrong time; skip ...")')
  685. cycle
  686. !write (gol,'("found unexpected times in grib file:")'); call goErr
  687. !write (gol,'(" paramkey : ",a)') paramkey; call goErr
  688. !call wrtgol( ' req. t1 : ', t1 ); call goErr
  689. !call wrtgol( ' t2 : ', t2 ); call goErr
  690. !call wrtgol( ' grib t1 : ', mf%t1 ); call goErr
  691. !call wrtgol( ' t2 : ', mf%t2 ); call goErr
  692. !write (gol,'(" grib file : ",a)') trim(mf%fname); call goErr
  693. !write (gol,'("in ",a)') rname; call goErr; status=1; return
  694. end if
  695. end if ! time checking
  696. ! extract level stuff:
  697. call Get( mf%grib, nlev=nlev, levtype=glevtype, level=glevel, status=status )
  698. IF_NOTOK_RETURN(status=1)
  699. ! check level type:
  700. select case ( glevtype )
  701. case ( levtype_sfc )
  702. ! surface field
  703. nlev = 1
  704. glevel = 1
  705. case ( levtype_hyb )
  706. select case ( paramkey )
  707. case ( 'LNSP' )
  708. nlev = 1
  709. case default
  710. ! level in 3d field
  711. end select
  712. case default
  713. write (gol,'("found unexpected level type: ")'); call goErr
  714. write (gol,'(" leveltype : ",i3)') glevtype; call goErr
  715. write (gol,'(" paramkey : ",a)') paramkey; call goErr
  716. write (gol,'(" grib file : ",a)') trim(mf%fname); call goErr
  717. write (gol,'("in ",a)') rname; call goErr; status=1; return
  718. end select
  719. ! check level:
  720. level = level + 1
  721. if ( glevel /= level ) then
  722. write (gol,'("found unexpected level: ")'); call goErr
  723. write (gol,'(" paramkey : ",a)') paramkey; call goErr
  724. write (gol,'(" req. level : ",i6)') level; call goErr
  725. write (gol,'(" grib level : ",i6)') glevel; call goErr
  726. write (gol,'(" grib nlev : ",i6)') nlev; call goErr
  727. write (gol,'(" grib file : ",a)') trim(mf%fname); call goErr
  728. write (gol,'("in ",a)') rname; call goErr; status=1; return
  729. end if
  730. !
  731. ! define grids and arrays
  732. !
  733. if ( isfirst ) then
  734. !
  735. ! * info
  736. !
  737. ! example of history:
  738. ! model=ecmwf;class=od;type=fc;tref=2000,12,31,12,00; ...
  739. ! trange=001,234,240,001;sh=159;nlev=60
  740. !
  741. call Init( tmi, paramkey, 'unknown', status )
  742. call AddHistory( tmi, 'model==ecmwf', status )
  743. call AddHistory( tmi, 'class=='//trim(mf%ec_class), status )
  744. call AddHistory( tmi, 'type=='//trim(mf%ec_type) , status )
  745. !
  746. call Get( mf%grib, status, reftime=greftime, timerange=gtimerange )
  747. IF_NOTOK_RETURN(status=1)
  748. write (key,'("tref==",i4.4,4(",",i2.2))') greftime
  749. call AddHistory( tmi, trim(key), status )
  750. write (key,'("trange==",i3.3,3(",",i3.3))') gtimerange
  751. call AddHistory( tmi, trim(key), status )
  752. !
  753. write (key,'("nlev==",i3.3)') nlev
  754. call AddHistory( tmi, trim(key), status )
  755. !
  756. ! * define horizontal grid:
  757. !
  758. ! extract grid type:
  759. call Get( mf%grib, status, gridtype=ggridtype )
  760. IF_NOTOK_RETURN(status=1)
  761. ! setup:
  762. select case ( ggridtype )
  763. ! o lat/lon
  764. case ( gridtype_ll )
  765. ! routine returns lat/lon grid:
  766. gridtype = 'll'
  767. ! grib storage is north pole to south pole:
  768. call Get( mf%grib, status, &
  769. lon_first=lon_first, lon_inc=lon_inc, lon_n=lon_n, &
  770. lat_last =lat_first, lat_inc=lat_inc, lat_n=lat_n )
  771. IF_NOTOK_RETURN(status=1)
  772. ! define grid structure:
  773. call Init( lli, lon_first, lon_inc, lon_n, &
  774. lat_first, lat_inc, lat_n, status )
  775. IF_NOTOK_RETURN(status=1)
  776. ! init array to store 2d field from grib file (north-south order):
  777. call pa_SetShape( pat, lon_n, lat_n )
  778. ! allocate output:
  779. call pa_SetShape( ll, lon_n, lat_n, nlev )
  780. ! add to history:
  781. write (key,'("longrid==",f7.2,",",f6.2,",",i4)') lon_first, lon_inc, lon_n
  782. call AddHistory( tmi, trim(key), status )
  783. write (key,'("latgrid==",f7.2,",",f6.2,",",i4)') lat_first, lat_inc, lat_n
  784. call AddHistory( tmi, trim(key), status )
  785. ! o gaussian grid
  786. case ( gridtype_gg )
  787. ! routine returns gg grid:
  788. gridtype = 'gg'
  789. ! extract grid number:
  790. call Get( mf%grib, status, N=ggN )
  791. IF_NOTOK_RETURN(status=1)
  792. ! define grid structure:
  793. call Init( ggi, ggN, .true., status )
  794. IF_NOTOK_RETURN(status=1)
  795. ! allocate output:
  796. call pa_SetShape( gg, ggi%np, nlev )
  797. ! add to history:
  798. write (key,'("gg==",i4.4)') ggN
  799. call AddHistory( tmi, trim(key), status )
  800. ! o spectral field:
  801. case ( gridtype_sh )
  802. ! routine returns sh grid:
  803. gridtype = 'sh'
  804. ! extract spectral truncation:
  805. call Get( mf%grib, status, T=shT )
  806. IF_NOTOK_RETURN(status=1)
  807. ! intialize spherical harmonic field info:
  808. call Init( shi, shT, status )
  809. IF_NOTOK_RETURN(status=1)
  810. ! allocate output:
  811. call pa_SetShape( sh, shi%np, nlev )
  812. ! add to history:
  813. write (key,'("sh==",i4.4)') shT
  814. call AddHistory( tmi, trim(key), status )
  815. case default
  816. write (gol,'("unsupported gridtype for setup : ",i6)') ggridtype; call goErr
  817. write (gol,'("in ",a)') rname; call goErr; status=1; return
  818. end select
  819. !
  820. ! * levels
  821. !
  822. select case ( nlev )
  823. case ( 1 )
  824. call Init( levi, nlev, (/0.0,0.0/), (/0.0,0.0/), status )
  825. IF_NOTOK_RETURN(status=1)
  826. case ( 60 )
  827. call Init( levi, 'ec60', status )
  828. IF_NOTOK_RETURN(status=1)
  829. end select
  830. ! not again ...
  831. isfirst = .false.
  832. end if ! isfirst (grid definition and allocation)
  833. !
  834. ! store
  835. !
  836. select case ( ggridtype )
  837. case ( gridtype_ll )
  838. ! read 2d pat from grib; storred from north to south
  839. call Get( mf%grib, status, ll=pat )
  840. IF_NOTOK_RETURN(status=1)
  841. ! store from south to north:
  842. do ilat = 1, lat_n
  843. ll(:,ilat,level) = pat(:,lat_n+1-ilat)
  844. end do
  845. case ( gridtype_gg )
  846. ! read 2d pat from grib:
  847. call Get( mf%grib, status, gg=gg(:,level) )
  848. IF_NOTOK_RETURN(status=1)
  849. case ( gridtype_sh )
  850. ! read 2d pat from grib:
  851. call Get( mf%grib, status, sh=sh(:,level) )
  852. IF_NOTOK_RETURN(status=1)
  853. case default
  854. write (gol,'("unsupported gridtype for 2d pat : ",i6)') gridtype; call goErr
  855. write (gol,'("in ",a)') rname; call goErr; status=1; return
  856. end select
  857. ! last record for this field ?
  858. if ( glevel == nlev ) exit
  859. end do ! records
  860. ! close grib file
  861. call Done( mf%grib, status )
  862. IF_NOTOK_RETURN(status=1)
  863. !
  864. ! ~~~ surface pressure
  865. !
  866. if ( mf%do_spm ) then
  867. ! open grib file
  868. call Init( mf%spm_grib, mf%spm_fname, 'r', status )
  869. IF_NOTOK_RETURN(status=1)
  870. ! loop over time records
  871. do
  872. ! read gribsection in file buffer
  873. call ReadRecord( mf%spm_grib, status )
  874. IF_NOTOK_RETURN(status=1)
  875. ! fill times
  876. call SetTime( mf, status )
  877. IF_NOTOK_RETURN(status=1)
  878. ! check time:
  879. call CheckTime( mf, tref, t1, t2, status )
  880. if (status/=0) then
  881. !write (*,'("grib read record: spm wrong time; skip ...")')
  882. cycle
  883. !write (gol,'("found unexpected times in grib file:")'); call goErr
  884. !write (gol,'(" paramkey : ",a)') paramkey; call goErr
  885. !call wrtgol( ' req. t1 : ', t1 ); call goErr
  886. !call wrtgol( ' t2 : ', t2 ); call goErr
  887. !call wrtgol( ' grib t1 : ', mf%t1 ); call goErr
  888. !call wrtgol( ' t2 : ', mf%t2 ); call goErr
  889. !write (gol,'(" grib file : ",a)') trim(mf%spm_fname); call goErr
  890. !write (gol,'("in ",a)') rname; call goErr; status=1; return
  891. end if
  892. ! time ok
  893. exit
  894. end do ! time loop
  895. ! set param id:
  896. select case ( ggridtype )
  897. case ( gridtype_ll )
  898. call GetPid( 'ec', 'SP', pid, tabid, status )
  899. IF_NOTOK_RETURN(status=1)
  900. case ( gridtype_gg )
  901. if ( mf%spm_lnsp2sp ) then
  902. call GetPid( 'ec', 'LNSP', pid, tabid, status )
  903. IF_NOTOK_RETURN(status=1)
  904. else
  905. call GetPid( 'ec', 'SP', pid, tabid, status )
  906. IF_NOTOK_RETURN(status=1)
  907. end if
  908. case ( gridtype_sh )
  909. call GetPid( 'ec', 'LNSP', pid, tabid, status )
  910. IF_NOTOK_RETURN(status=1)
  911. case default
  912. write (gol,'("unsupported gridtype for setup sp/lnsp : ",i6)') ggridtype; call goErr
  913. write (gol,'("in ",a)') rname; call goErr; status=1; return
  914. end select
  915. ! check parameter:
  916. call Check( mf%spm_grib, pid=pid, debug=1, status=status )
  917. IF_NOTOK_RETURN(status=1)
  918. ! check level:
  919. call Get( mf%spm_grib, levtype=glevtype, level=glevel, status=status )
  920. IF_NOTOK_RETURN(status=1)
  921. select case ( ggridtype )
  922. case ( gridtype_ll )
  923. if ( glevtype /= levtype_sfc ) then
  924. write (gol,'("found unexpected level type ")'); call goErr
  925. write (gol,'(" paramkey : ",a)') paramkey; call goErr
  926. write (gol,'(" sfc level type : ",i6)') levtype_sfc; call goErr
  927. write (gol,'(" grib level type : ",i6)') glevtype; call goErr
  928. write (gol,'(" grib file : ",a)') trim(mf%spm_fname); call goErr
  929. write (gol,'("in ",a)') rname; call goErr; status=1; return
  930. end if
  931. case ( gridtype_gg )
  932. if ( mf%spm_lnsp2sp ) then
  933. if ( (glevtype /= levtype_hyb) .or. (glevel /= 1) ) then
  934. write (gol,'("found unexpected level type (lnsp for 3d gg)")'); call goErr
  935. write (gol,'(" paramkey : ",a)') paramkey; call goErr
  936. write (gol,'(" hyb level type : ",i6)') levtype_hyb; call goErr
  937. write (gol,'(" grib level type : ",i6)') glevtype; call goErr
  938. write (gol,'(" grib level : ",i6)') glevel; call goErr
  939. write (gol,'(" grib file : ",a)') trim(mf%spm_fname); call goErr
  940. write (gol,'("in ",a)') rname; call goErr; status=1; return
  941. end if
  942. else
  943. if ( glevtype /= levtype_sfc ) then
  944. write (gol,'("found unexpected level type ")'); call goErr
  945. write (gol,'(" paramkey : ",a)') paramkey; call goErr
  946. write (gol,'(" sfc level type : ",i6)') levtype_sfc; call goErr
  947. write (gol,'(" grib level type : ",i6)') glevtype; call goErr
  948. write (gol,'(" grib file : ",a)') trim(mf%spm_fname); call goErr
  949. write (gol,'("in ",a)') rname; call goErr; status=1; return
  950. end if
  951. end if
  952. case ( gridtype_sh )
  953. if ( (glevtype /= levtype_hyb) .or. (glevel /= 1) ) then
  954. write (gol,'("found unexpected level type ")'); call goErr
  955. write (gol,'(" paramkey : ",a)') paramkey; call goErr
  956. write (gol,'(" hyb level type : ",i6)') levtype_hyb; call goErr
  957. write (gol,'(" grib level type : ",i6)') glevtype; call goErr
  958. write (gol,'(" grib level : ",i6)') glevel; call goErr
  959. write (gol,'(" grib file : ",a)') trim(mf%spm_fname); call goErr
  960. write (gol,'("in ",a)') rname; call goErr; status=1; return
  961. end if
  962. case default
  963. write (gol,'("unsupported gridtype for sp/lnsp levs : ",i6)') ggridtype; call goErr
  964. write (gol,'("in ",a)') rname; call goErr; status=1; return
  965. end select
  966. ! read and store surface pressure field:
  967. select case ( ggridtype )
  968. case ( gridtype_ll )
  969. ! allocate storage
  970. call pa_SetShape( sp_ll, lon_n, lat_n )
  971. ! read 2d pat from grib; storred from north to south
  972. call Get( mf%spm_grib, status, ll=pat )
  973. IF_NOTOK_RETURN(status=1)
  974. ! store from south to north:
  975. do ilat = 1, lat_n
  976. sp_ll(:,ilat) = pat(:,lat_n+1-ilat)
  977. end do
  978. case ( gridtype_gg )
  979. ! allocate storage
  980. call pa_SetShape( sp_gg, ggi%np )
  981. ! convert from sh lnsp or read directly:
  982. if ( mf%spm_lnsp2sp ) then
  983. ! allocate output:
  984. call pa_SetShape( sh, shi%np, nlev )
  985. ! extract spectral truncation:
  986. call Get( mf%spm_grib, status, T=shT )
  987. IF_NOTOK_RETURN(status=1)
  988. ! intialize spherical harmonic field info:
  989. call Init( tmp_shi, shT, status )
  990. IF_NOTOK_RETURN(status=1)
  991. ! allocate storage for lnsp:
  992. call pa_Init( tmp_sh )
  993. call pa_SetShape( tmp_sh, tmp_shi%np )
  994. ! read lnsp on sh grid:
  995. call Get( mf%spm_grib, status, sh=tmp_sh )
  996. IF_NOTOK_RETURN(status=1)
  997. ! interpolate from sh to gg:
  998. call Interpol( tmp_shi, tmp_sh, ggi, sp_gg, status ) ! ln(Pa)
  999. IF_NOTOK_RETURN(status=1)
  1000. ! clear
  1001. call Done( tmp_shi )
  1002. call pa_Done( tmp_sh )
  1003. ! convert from lnsp to sp :
  1004. sp_gg = exp(sp_gg) ! Pa
  1005. else
  1006. ! read 2d pat from grib; storred from north to south
  1007. call Get( mf%spm_grib, status, gg=sp_gg )
  1008. IF_NOTOK_RETURN(status=1)
  1009. end if
  1010. case ( gridtype_sh )
  1011. ! allocate storage
  1012. call pa_SetShape( lnsp_sh, shi%np )
  1013. ! read spectral coeff:
  1014. call Get( mf%spm_grib, status, sh=lnsp_sh )
  1015. IF_NOTOK_RETURN(status=1)
  1016. case default
  1017. write (gol,'("unsupported gridtype for reading sp/lnsp : ",i6)') ggridtype; call goErr
  1018. write (gol,'("in ",a)') rname; call goErr; status=1; return
  1019. end select
  1020. ! close grib file
  1021. call Done( mf%spm_grib, status )
  1022. IF_NOTOK_RETURN(status=1)
  1023. end if
  1024. !
  1025. ! ~~~ end
  1026. !
  1027. ! deallocate arrays
  1028. call pa_Done( pat )
  1029. ! ok
  1030. status = 0
  1031. end subroutine mf_ReadRecord_2
  1032. ! ****************************************************************************
  1033. !
  1034. ! In gribfile:
  1035. ! reftime : for example time at which forecast is made
  1036. ! timerange: increment or interval
  1037. !
  1038. ! arguments: ok if:
  1039. !
  1040. ! time1 == time2 time1==time2 == reftime+timerange
  1041. !
  1042. ! time1 == 0 time2 == reftime+timerange
  1043. !
  1044. ! time2 == 0 time1 == reftime
  1045. !
  1046. ! time1 < time2 time1 == refitme, time2 == reftime+timerange
  1047. !
  1048. !
  1049. ! grib [t1-----------t2]
  1050. ! status
  1051. ! o time1/2 record too old 1
  1052. ! o time1/2 ok 0
  1053. ! o time1/2 record too new 2
  1054. !
  1055. !
  1056. ! SetTime( mf, status )
  1057. !
  1058. ! Extracts time values from current grib record,
  1059. ! store in mf%t1, mf%t2
  1060. !
  1061. ! return status:
  1062. ! 0 : ok
  1063. ! other : some error
  1064. !
  1065. ! CheckTime( mf, time1, time2, status )
  1066. !
  1067. ! return status:
  1068. ! 0 : times match
  1069. ! 1 : times do not match, try next record
  1070. ! 2 : current record is newer than requested (reopen ?)
  1071. ! 3 : some error
  1072. !
  1073. ! ***
  1074. !
  1075. ! Return time parameters for grib files:
  1076. ! o tfile : date in filename
  1077. ! o trange : time interval covered by fields in file
  1078. ! o tref : reference time (forecast start?) for tday,[t1,t2]
  1079. !
  1080. subroutine GetGribTime( ec_treskey, tday, t1, t2, status, tfile, trange, tref )
  1081. use GO, only : TDate, Get, Set, wrtgol, NewDate, IncrDate, operator(+), operator(-)
  1082. ! --- in/out --------------------------------
  1083. character(len=*), intent(in) :: ec_treskey
  1084. type(TDate), intent(in) :: tday, t1, t2
  1085. integer, intent(out) :: status
  1086. type(TDate), intent(out), optional :: tfile
  1087. type(TDate), intent(out), optional :: trange(2)
  1088. type(TDate), intent(out), optional :: tref
  1089. ! --- const --------------------------------------
  1090. character(len=*), parameter :: rname = mname//'/GetGribTime'
  1091. ! --- local --------------------------------
  1092. integer :: hour2, time6(6)
  1093. integer :: dd, hh, step
  1094. ! --- begin --------------------------------
  1095. ! set day shift, start hour, and step
  1096. select case ( ec_treskey )
  1097. ! ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  1098. ! constant field
  1099. ! ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  1100. case ( 'const' )
  1101. ! only tday is usefull ...
  1102. if ( present(tfile ) ) tfile = tday
  1103. if ( present(trange) ) trange = (/t1,t2/) ! any, any
  1104. if ( present(tref ) ) tref = tday ! dummy ...
  1105. ! ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  1106. ! fg, 3 hourly
  1107. ! ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  1108. case ( '_fg006up4tr3' )
  1109. ! extract end hour:
  1110. call Get( t2, hour=hour2 )
  1111. ! set forecast start time and step given hour:
  1112. select case ( hour2 )
  1113. case ( 00 ) ; dd = 0 ; hh = 00 ; step = 6
  1114. case ( 03 ) ; dd = 0 ; hh = 03 ; step = 3
  1115. case ( 06 ) ; dd = 0 ; hh = 06 ; step = 6
  1116. case ( 09 ) ; dd = 0 ; hh = 09 ; step = 3
  1117. case ( 12 ) ; dd = 0 ; hh = 12 ; step = 6
  1118. case ( 15 ) ; dd = 0 ; hh = 15 ; step = 3
  1119. case ( 18 ) ; dd = 0 ; hh = 18 ; step = 6
  1120. case ( 21 ) ; dd = 0 ; hh = 21 ; step = 3
  1121. case default
  1122. write (gol,'("unsupported hour :")'); call goErr
  1123. write (gol,'(" hour2 : ",i2)') hour2; call goErr
  1124. write (gol,'(" timesteps : ",a )') ec_treskey; call goErr
  1125. call wrtgol( ' time1 : ', t1 ); call goErr
  1126. write (gol,'("in ",a)') rname; call goErr; status=1; return
  1127. end select
  1128. ! file ccyymmdd contains fields for [00,24) :
  1129. if ( present(tfile) ) then
  1130. tfile = t1
  1131. call Set( tfile, hour=00 )
  1132. end if
  1133. ! fields valid for [00,24) :
  1134. if ( present(trange) ) then
  1135. trange(1) = t1
  1136. call Set( trange(1), hour=0, min=0, sec=0, mili=0 )
  1137. trange(2) = trange(1) + IncrDate(hour=23,min=59,sec=59,mili=999)
  1138. ! trap last fg time 2000-09-12 00:00 ; data valid forr 00:00 only:
  1139. call Get( tfile, time6=time6 )
  1140. if ( all(time6(1:3)==(/2000,09,12/)) ) trange(2) = trange(1)
  1141. end if
  1142. ! reference time = start of forecast
  1143. if ( present(tref) ) then
  1144. call Get( t1, time6=time6 )
  1145. time6(4:6) = 0
  1146. tref = NewDate( time6=time6 ) + IncrDate( day=dd, hour=hh )
  1147. end if
  1148. ! ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  1149. ! fc, 3 hourly
  1150. ! ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  1151. case ( '_fc012up2tr3', '_03p03' )
  1152. ! extract end hour:
  1153. call Get( t2, hour=hour2 )
  1154. ! set forecast start time and step given hour:
  1155. select case ( hour2 )
  1156. case ( 00 ) ; dd = -1 ; hh = 12 ; step = 12
  1157. case ( 03 ) ; dd = 0 ; hh = 00 ; step = 3
  1158. case ( 06 ) ; dd = 0 ; hh = 00 ; step = 6
  1159. case ( 09 ) ; dd = 0 ; hh = 00 ; step = 9
  1160. case ( 12 ) ; dd = 0 ; hh = 00 ; step = 12
  1161. case ( 15 ) ; dd = 0 ; hh = 12 ; step = 3
  1162. case ( 18 ) ; dd = 0 ; hh = 12 ; step = 6
  1163. case ( 21 ) ; dd = 0 ; hh = 12 ; step = 9
  1164. case default
  1165. write (gol,'("unsupported hour :")'); call goErr
  1166. write (gol,'(" hour2 : ",i2)') hour2; call goErr
  1167. write (gol,'(" timesteps : ",a )') ec_treskey; call goErr
  1168. call wrtgol( ' time1 : ', t1 ); call goErr
  1169. write (gol,'("in ",a)') rname; call goErr; status=1; return
  1170. end select
  1171. ! file ccyymmdd contains fields for (00,24] :
  1172. if ( present(tfile) ) then
  1173. ! current day by default:
  1174. tfile = t2
  1175. call Set( tfile, hour=0, min=0, sec=0, mili=0 ) ! 00:00
  1176. ! trap (..,00:00], this should be previous day:
  1177. call Get( t2, time6=time6 )
  1178. if ( all(time6(4:6)==0) ) tfile = tfile - IncrDate(day=1)
  1179. end if
  1180. ! fields valid for (00,24] :
  1181. if ( present(trange) ) then
  1182. trange(1) = t2
  1183. call Set( trange(1), hour=0, min=0, sec=0, mili=0 ) ! 00:00
  1184. ! trap 00:00, this should be previous day:
  1185. call Get( t2, time6=time6 )
  1186. if ( all(time6(4:6)==0) ) trange(1) = trange(1) - IncrDate(day=1)
  1187. ! complete (00,24]
  1188. trange(2) = trange(1) + IncrDate(day=1) ! 24:00
  1189. call Set( trange(1), mili=1 ) ! > 00:00
  1190. end if
  1191. ! reference time = start of forecast
  1192. if ( present(tref) ) then
  1193. call Get( t2, time6=time6 )
  1194. time6(4:6) = 0
  1195. tref = NewDate( time6=time6 ) + IncrDate( day=dd, hour=hh )
  1196. end if
  1197. ! ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  1198. ! fc, 6 hourly
  1199. ! ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  1200. case ( '_06p06' )
  1201. ! extract end hour:
  1202. call Get( t2, hour=hour2 )
  1203. ! set forecast start time and step given hour:
  1204. select case ( hour2 )
  1205. case ( 00 ) ; dd = -1 ; hh = 12 ; step = 12
  1206. case ( 06 ) ; dd = 0 ; hh = 00 ; step = 6
  1207. case ( 12 ) ; dd = 0 ; hh = 00 ; step = 12
  1208. case ( 18 ) ; dd = 0 ; hh = 12 ; step = 6
  1209. case default
  1210. write (gol,'("unsupported hour :")'); call goErr
  1211. write (gol,'(" hour2 : ",i2)') hour2; call goErr
  1212. write (gol,'(" timesteps : ",a )') ec_treskey; call goErr
  1213. call wrtgol( ' time1 : ', t1 ); call goErr
  1214. write (gol,'("in ",a)') rname; call goErr; status=1; return
  1215. end select
  1216. ! file ccyymmdd contains fields for (00,24] :
  1217. if ( present(tfile) ) then
  1218. ! current day by default:
  1219. tfile = t1
  1220. call Set( tfile, hour=00 )
  1221. ! trap 00:00, this should be previous day:
  1222. call Get( t1, time6=time6 )
  1223. if ( all(time6(4:6)==0) ) tfile = tfile - IncrDate(day=1)
  1224. end if
  1225. ! fields valid for (00,24] :
  1226. if ( present(trange) ) then
  1227. trange(1) = t1
  1228. call Set( trange(1), hour=0, min=0, sec=0, mili=0 ) ! 00:00
  1229. ! trap 00:00, this should be previous day:
  1230. call Get( t1, time6=time6 )
  1231. if ( all(time6(4:6)==0) ) trange(1) = trange(1) - IncrDate(day=1)
  1232. ! complete (00,24]
  1233. trange(2) = trange(1) + IncrDate(day=1) ! 24:00
  1234. call Set( trange(1), mili=1 ) ! > 00:00
  1235. end if
  1236. ! reference time = start of forecast
  1237. if ( present(tref) ) then
  1238. call Get( t1, time6=time6 )
  1239. time6(4:6) = 0
  1240. tref = NewDate( time6=time6 ) + IncrDate( day=dd, hour=hh )
  1241. end if
  1242. ! ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  1243. ! analysis, 6 hourly
  1244. ! ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  1245. case ( 'an_06p06' )
  1246. ! extract end hour:
  1247. call Get( t2, hour=hour2 )
  1248. ! set forecast start time and step given hour:
  1249. select case ( hour2 )
  1250. case ( 00 ) ; dd = 0 ; hh = 00 ; step = 00
  1251. case ( 06 ) ; dd = 0 ; hh = 06 ; step = 00
  1252. case ( 12 ) ; dd = 0 ; hh = 12 ; step = 00
  1253. case ( 18 ) ; dd = 0 ; hh = 18 ; step = 00
  1254. case default
  1255. write (gol,'("unsupported hour :")'); call goErr
  1256. write (gol,'(" hour2 : ",i2)') hour2; call goErr
  1257. write (gol,'(" timesteps : ",a )') ec_treskey; call goErr
  1258. call wrtgol( ' time1 : ', t1 ); call goErr
  1259. write (gol,'("in ",a)') rname; call goErr; status=1; return
  1260. end select
  1261. ! file ccyymmdd contains fields for (00,24] :
  1262. if ( present(tfile) ) then
  1263. ! current day by default:
  1264. tfile = t1
  1265. call Set( tfile, hour=00 )
  1266. ! trap 00:00, this should be previous day:
  1267. call Get( t1, time6=time6 )
  1268. if ( all(time6(4:6)==0) ) tfile = tfile - IncrDate(day=1)
  1269. end if
  1270. ! fields valid for (00,24] :
  1271. if ( present(trange) ) then
  1272. trange(1) = t1
  1273. call Set( trange(1), hour=0, min=0, sec=0, mili=0 ) ! 00:00
  1274. ! trap 00:00, this should be previous day:
  1275. call Get( t1, time6=time6 )
  1276. if ( all(time6(4:6)==0) ) trange(1) = trange(1) - IncrDate(day=1)
  1277. ! complete (00,24]
  1278. trange(2) = trange(1) + IncrDate(day=1) ! 24:00
  1279. call Set( trange(1), mili=1 ) ! > 00:00
  1280. end if
  1281. ! reference time = start of forecast
  1282. if ( present(tref) ) then
  1283. call Get( t1, time6=time6 )
  1284. time6(4:6) = 0
  1285. tref = NewDate( time6=time6 ) + IncrDate( day=dd, hour=hh )
  1286. end if
  1287. ! ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  1288. ! ???
  1289. ! ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  1290. case default
  1291. write (gol,'("unsupported time resolution key:")'); call goErr
  1292. write (gol,'(" ",a)') trim(ec_treskey); call goErr
  1293. write (gol,'("in ",a)') rname; call goErr; status=1; return
  1294. end select
  1295. ! ok
  1296. status = 0
  1297. end subroutine GetGribTime
  1298. ! ***
  1299. !
  1300. ! Extract time fields of current grib record,
  1301. ! store in mf%tref, mf%t1, mf%t2
  1302. !
  1303. subroutine SetTime( mf, status )
  1304. use GO, only : TDate, NewDate, IncrDate, operator(+), wrtgol
  1305. use file_grib, only : TGribFile, Check, Get
  1306. ! --- const -------------------------------------
  1307. character(len=*), parameter :: rname = mname//'/SetTime'
  1308. ! --- in/out -------------------------------
  1309. type(TMeteoFile_Grib), intent(inout) :: mf
  1310. integer, intent(out) :: status
  1311. ! --- local -------------------------------
  1312. integer :: reftime(5), timerange(4)
  1313. ! --- begin -------------------------------
  1314. ! extract time fields from grib record:
  1315. call Get( mf%grib, status, reftime=reftime, timerange=timerange )
  1316. IF_NOTOK_RETURN(status=1)
  1317. ! Fill t1 and t2 with the time information; might be equal.
  1318. ! Check time range indicator (WMO code table 5):
  1319. select case ( timerange(4) )
  1320. case ( 0, 1 )
  1321. !
  1322. ! 0 = Forecast product valid for reference time + P1 (P1>0),
  1323. ! or uninitialized analysis product for reference time (P1=0)
  1324. !
  1325. ! 1 = Initialized analysis product for reference time (P1=0).
  1326. !
  1327. ! fill reference time:
  1328. mf%tref = NewDate( time5=reftime )
  1329. ! fill t1 with reftime+timerange;
  1330. ! add P1 in hours; check time unit (WMO code table 4)
  1331. mf%t1 = NewDate( time5=reftime )
  1332. select case ( timerange(1) )
  1333. case ( 1 ) ! hours
  1334. mf%t1 = mf%t1 + IncrDate( hour=timerange(2) )
  1335. case default
  1336. write (gol,'("grib timerange units other than hours not supported yet")'); call goErr
  1337. write (gol,'(" reftime : ",i4,4i3)') reftime; call goErr
  1338. write (gol,'(" timerange : ",4i3)') timerange; call goErr
  1339. write (gol,'(" file : ",a)') trim(mf%grib%fname); call goErr
  1340. write (gol,'("in ",a)') rname; call goErr; status=1; return
  1341. end select
  1342. ! instant time:
  1343. mf%t2 = mf%t1
  1344. case ( 2 )
  1345. !
  1346. ! 2 = Product with a valid time ranging between
  1347. ! reference time + P1 and reference time + P2
  1348. !
  1349. ! fill t1 with reftime+P1;
  1350. ! add P1 in hours; check time unit (WMO code table 4)
  1351. mf%t1 = NewDate( time5=reftime )
  1352. select case ( timerange(1) )
  1353. case ( 1 ) ! hours
  1354. mf%t1 = mf%t1 + IncrDate( hour=timerange(2) )
  1355. case default
  1356. write (gol,'("grib timerange units other than hours not supported yet")'); call goErr
  1357. write (gol,'(" file : ",a)') trim(mf%grib%fname); call goErr
  1358. write (gol,'("in ",a)') rname; call goErr; status=1; return
  1359. end select
  1360. ! fill t2 with reftime+P1;
  1361. ! add P1 in hours; check time unit (WMO code table 4)
  1362. mf%t2 = NewDate( time5=reftime )
  1363. select case ( timerange(1) )
  1364. case ( 1 ) ! hours
  1365. mf%t2 = mf%t2 + IncrDate( hour=timerange(3) )
  1366. case default
  1367. write (gol,'("grib timerange units other than hours not supported yet")'); call goErr
  1368. write (gol,'(" file : ",a)') trim(mf%grib%fname); call goErr
  1369. write (gol,'("in ",a)') rname; call goErr; status=1; return
  1370. end select
  1371. case default
  1372. write (gol,'("unsupported time range indicator:")'); call goErr
  1373. write (gol,'(" indicator : ",i6)') timerange(4); call goErr
  1374. write (gol,'(" file : ",a)') trim(mf%grib%fname); call goErr
  1375. write (gol,'("in ",a)') rname; call goErr; status=1; return
  1376. end select
  1377. ! ok
  1378. status = 0
  1379. end subroutine SetTime
  1380. ! ***
  1381. subroutine CheckTime( mf, tref, t1, t2, status )
  1382. use GO
  1383. use file_grib, only : Check, Get
  1384. ! --- const -------------------------------------
  1385. character(len=*), parameter :: rname = mname//'/CheckTime'
  1386. ! --- in/out -------------------------------
  1387. type(TMeteoFile_Grib), intent(in) :: mf
  1388. type(TDate), intent(in) :: tref, t1, t2
  1389. integer, intent(out) :: status
  1390. ! --- local -------------------------------
  1391. integer :: year1, year2
  1392. ! --- begin -------------------------------
  1393. ! requested year zero ? always ok
  1394. call Get( t1, year=year1 )
  1395. call Get( t2, year=year2 )
  1396. if ( (year1 == 0) .and. (year2 == 0) ) then
  1397. ! requested constant field, always ok
  1398. status = 0; return ! ok
  1399. end if
  1400. if ( year1 == 0 ) then
  1401. ! do not test t1, only t2
  1402. if ( t2 == mf%t2 ) then
  1403. status = 0; return ! ok
  1404. else
  1405. status = 1; return ! not ok, try next
  1406. end if
  1407. else if ( year2 == 0 ) then
  1408. ! do not test t2, only t1
  1409. if ( t1 == mf%t1 ) then
  1410. status = 0; return ! ok
  1411. else
  1412. status = 1; return ! not ok, try next
  1413. end if
  1414. end if
  1415. ! ! interval or instant time
  1416. ! if ( t1 < t2 ) then
  1417. !
  1418. ! !! time interval: [t1,t2] should be inside [t1,t2]
  1419. ! !if ( (t1 >= mf%t1) .and. (t2 <= mf%t2) ) then
  1420. ! ! status = 0; return ! ok
  1421. ! !else
  1422. ! ! status = 1; return ! try next
  1423. ! !end if
  1424. !
  1425. ! ! time interval: [t1,t2] should be equal to [t1,t2]
  1426. ! if ( (t1 == mf%t1) .and. (t2 == mf%t2) ) then
  1427. ! status = 0; return ! ok
  1428. ! else
  1429. ! status = 1; return ! try next
  1430. ! end if
  1431. !
  1432. ! else if ( t1 == t2 ) then
  1433. !
  1434. ! ! instant time: t2 should match t2
  1435. ! if ( t2 == mf%t2 ) then
  1436. ! status = 0; return ! ok
  1437. ! else
  1438. ! status = 1; return ! try next
  1439. ! end if
  1440. !
  1441. ! else
  1442. !
  1443. ! write (gol,'("t1 should not exceed t2:")'); call goErr
  1444. ! call wrtgol( ' t1 : ', t1 ); call goErr
  1445. ! call wrtgol( ' t2 : ', t2 ); call goErr
  1446. ! write (*,'("ERROR in ",a)') rname; status=3; return
  1447. !
  1448. ! end if
  1449. ! compare all:
  1450. if ( (tref == mf%tref) .and. (t1 == mf%t1) .and. (t2 == mf%t2) ) then
  1451. status = 0; return ! ok
  1452. else
  1453. status = 1; return ! try next
  1454. end if
  1455. ! some error ...
  1456. status = 1
  1457. end subroutine CheckTime
  1458. end module tmm_mf_grib