tmm_mf.F90 35 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207
  1. !###############################################################################
  2. !
  3. #define TRACEBACK write (gol,'("in ",a," (",a,", line",i5,")")') rname, __FILE__, __LINE__; call goErr
  4. !
  5. #define IF_NOTOK_RETURN(action) if (status/=0) then; TRACEBACK; action; return; end if
  6. #define IF_ERROR_RETURN(action) if (status >0) then; TRACEBACK; action; return; end if
  7. !
  8. #include "tmm.inc"
  9. !
  10. !###############################################################################
  11. module tmm_mf
  12. use GO , only : gol, goErr, goPr, goBug
  13. use GO , only : TDate
  14. use Grid, only : TllGridInfo, TggGridInfo, TshGridInfo, TshGrid, TLevelInfo
  15. #ifdef with_tmm_tmpp
  16. use tmm_mf_tmpp , only : TMeteoFile_tmpp
  17. #endif
  18. #ifdef with_tmm_tm5
  19. use tmm_mf_tm5_nc , only : TMeteoFile_tm5_nc
  20. #endif
  21. #ifdef with_tmm_ecmwf
  22. use tmm_mf_ecmwf_tmpp, only : TMeteoFile_ecmwf_tmpp
  23. use tmm_mf_ecmwf_tm5 , only : TMeteoFile_ecmwf_tm5
  24. #endif
  25. #ifdef with_tmm_ncep
  26. use tmm_mf_ncep_cdc , only : TMeteoFile_ncep_cdc
  27. use tmm_mf_ncep_gfs , only : TMeteoFile_ncep_gfs
  28. #endif
  29. #ifdef with_prism
  30. use tmm_mf_prism , only : TMeteoFile_prism
  31. #endif
  32. #ifdef with_tmm_msc
  33. use tmm_mf_msc , only : TMeteoFile_msc
  34. #endif
  35. implicit none
  36. ! --- in/out -------------------------------------
  37. private
  38. public :: TMeteoFile
  39. public :: Init, Done
  40. public :: Opened, CheckTime, CheckParam
  41. public :: SetupInput
  42. public :: ReadRecord
  43. public :: SetupOutput
  44. public :: WriteRecord
  45. ! --- const ---------------------------------------
  46. character(len=*), parameter :: mname = 'tmm_mf'
  47. ! --- types --------------------------------------
  48. type TMeteoFile
  49. ! opened yet ?
  50. logical :: opened
  51. character(len=1) :: io = ''
  52. ! meteo archive keys:
  53. character(len=256) :: dir = ''
  54. character(len=256) :: archivekey = ''
  55. ! parameter keys for fields in this file
  56. character(len=256) :: paramkeys = ''
  57. ! time range for which file is valid
  58. type(TDate) :: t1, t2
  59. !
  60. ! access to current meteo file
  61. !
  62. character(len=10) :: filetype = ''
  63. character(len=256) :: filename = ''
  64. character(len=256) :: spm_filename = ''
  65. #ifdef with_tmm_tmpp
  66. type(TMeteoFile_tmpp) :: mf_tmpp ! tmpp written hdf file
  67. #endif
  68. #ifdef with_tmm_tm5
  69. type(TMeteoFile_tm5_nc) :: mf_tm5_nc ! tm5 written netcdf file
  70. #endif
  71. #ifdef with_tmm_ecmwf
  72. type(TMeteoFile_ecmwf_tmpp) :: mf_ecmwf_tmpp ! grib file retrieved with tmpp
  73. type(TMeteoFile_ecmwf_tm5) :: mf_ecmwf_tm5 ! grib file retrieved with tm5
  74. #endif
  75. #ifdef with_tmm_ncep
  76. type(TMeteoFile_ncep_cdc) :: mf_ncep_cdc ! ncep file from cdc archive
  77. type(TMeteoFile_ncep_gfs) :: mf_ncep_gfs ! ncep gfs file
  78. #endif
  79. #ifdef with_prism
  80. type(TMeteoFile_prism) :: mf_prism ! prism file
  81. #endif
  82. #ifdef with_tmm_msc
  83. type(TMeteoFile_msc) :: mf_msc ! msc file
  84. #endif
  85. end type TMeteoFile
  86. ! --- interfaces -------------------------------
  87. interface Init
  88. module procedure mf_Init
  89. end interface
  90. interface Done
  91. module procedure mf_Done
  92. end interface
  93. interface Opened
  94. module procedure mf_Opened
  95. end interface
  96. interface CheckTime
  97. module procedure mf_CheckTime
  98. end interface
  99. interface CheckParam
  100. module procedure mf_CheckParam
  101. end interface
  102. interface SetupInput
  103. module procedure mf_SetupInput
  104. end interface
  105. interface ReadRecord
  106. module procedure mf_ReadRecord
  107. end interface
  108. ! interface ReadEqvLatStuff
  109. ! module procedure mf_ReadEqvLatStuff
  110. ! end interface
  111. interface SetupOutput
  112. module procedure mf_SetupOutput
  113. end interface
  114. interface WriteRecord
  115. module procedure mf_WriteRecord_2d
  116. module procedure mf_WriteRecord_3d
  117. end interface
  118. contains
  119. ! ===========================================================
  120. !
  121. ! init/done
  122. !
  123. ! ===========================================================
  124. subroutine mf_Init( mf, io, status )
  125. ! --- begin -------------------------------------------
  126. type(TMeteoFile), intent(out) :: mf
  127. character(len=1), intent(in) :: io
  128. integer, intent(out) :: status
  129. ! --- const -------------------------------------------
  130. character(len=*), parameter :: rname = mname//'/mf_Init'
  131. ! --- begin -------------------------------------------
  132. ! input or output ?
  133. mf%io = io
  134. ! file not opened yet
  135. mf%opened = .false.
  136. ! ok
  137. status = 0
  138. end subroutine mf_Init
  139. ! ***
  140. subroutine mf_Done( mf, status )
  141. use GO, only : goSystem
  142. use Grid, only : Done
  143. #ifdef with_tmm_tmpp
  144. use tmm_mf_tmpp , only : Done
  145. #endif
  146. #ifdef with_tmm_tm5
  147. use tmm_mf_tm5_nc , only : Done
  148. #endif
  149. #ifdef with_tmm_ecmwf
  150. use tmm_mf_ecmwf_tmpp, only : Done
  151. use tmm_mf_ecmwf_tm5 , only : Done
  152. #endif
  153. #ifdef with_tmm_ncep
  154. use tmm_mf_ncep_cdc , only : Done
  155. use tmm_mf_ncep_gfs , only : Done
  156. #endif
  157. #ifdef with_prism
  158. use tmm_mf_prism , only : Done
  159. #endif
  160. #ifdef with_tmm_msc
  161. use tmm_mf_msc , only : Done
  162. #endif
  163. ! --- begin -------------------------------------------
  164. type(TMeteoFile), intent(inout) :: mf
  165. integer, intent(out) :: status
  166. ! --- const -------------------------------------------
  167. character(len=*), parameter :: rname = mname//'/mf_Done'
  168. ! --- begin -------------------------------------------
  169. ! close file if necessary
  170. if ( mf%opened ) then
  171. select case ( mf%filetype )
  172. #ifdef with_tmm_tmpp
  173. case ( 'tmpp' )
  174. call Done( mf%mf_tmpp, status )
  175. IF_NOTOK_RETURN(status=1)
  176. #endif
  177. #ifdef with_tmm_tm5
  178. case ( 'tm5-nc' )
  179. call Done( mf%mf_tm5_nc, status )
  180. IF_NOTOK_RETURN(status=1)
  181. #endif
  182. #ifdef with_tmm_ecmwf
  183. case ( 'ecmwf-tmpp' )
  184. call Done( mf%mf_ecmwf_tmpp, status )
  185. IF_NOTOK_RETURN(status=1)
  186. case ( 'ecmwf-tm5' )
  187. call Done( mf%mf_ecmwf_tm5, status )
  188. IF_NOTOK_RETURN(status=1)
  189. #endif
  190. #ifdef with_tmm_ncep
  191. case ( 'ncep-cdc' )
  192. call Done( mf%mf_ncep_cdc, status )
  193. IF_NOTOK_RETURN(status=1)
  194. case ( 'ncep-gfs' )
  195. call Done( mf%mf_ncep_gfs, status )
  196. IF_NOTOK_RETURN(status=1)
  197. #endif
  198. #ifdef with_prism
  199. case ( 'prism' )
  200. call Done( mf%mf_prism, status )
  201. IF_NOTOK_RETURN(status=1)
  202. #endif
  203. #ifdef with_tmm_msc
  204. case ( 'msc-data' )
  205. call Done( mf%mf_msc, status )
  206. IF_NOTOK_RETURN(status=1)
  207. #endif
  208. case default
  209. write (gol,'("unsupported filetype `",a,"`")') trim(mf%filetype); call goErr
  210. TRACEBACK; status=1; return
  211. end select
  212. mf%opened = .false.
  213. end if
  214. ! ok
  215. status = 0
  216. end subroutine mf_Done
  217. ! ***
  218. logical function mf_Opened( mf )
  219. ! --- begin -------------------------------------------
  220. type(TMeteoFile), intent(in) :: mf
  221. ! --- begin -------------------------------------------
  222. mf_Opened = mf%opened
  223. end function mf_Opened
  224. ! ===========================================================
  225. !
  226. ! check contents of open meteo file
  227. !
  228. ! ===========================================================
  229. ! Check time in meteo file;
  230. ! status:
  231. ! <0 : mf does not include [t1,t2]
  232. ! 0 : mf includes [t,t2]
  233. ! >0 : error; mf not open ?
  234. !
  235. subroutine mf_CheckTime( mf, t1, t2, status )
  236. use GO, only : TDate, IncrDate, wrtgol, IsAnyDate
  237. use GO, only : operator(+), operator(-), operator(==), operator(<), operator(<=)
  238. ! --- begin -------------------------------------------
  239. type(TMeteoFile), intent(in) :: mf
  240. type(TDate), intent(in) :: t1, t2
  241. integer, intent(out) :: status
  242. ! --- const -------------------------------------------
  243. character(len=*), parameter :: rname = mname//'/mf_CheckTime'
  244. ! --- begin -------------------------------------------
  245. ! not open ?
  246. if ( .not. Opened(mf) ) then
  247. write (gol,'("meteo file not opened")'); call goErr
  248. TRACEBACK; status = 1; return
  249. end if
  250. ! trap any date:
  251. if ( IsAnyDate(t1) .and. IsAnyDate(t2) ) then
  252. status = 0; return
  253. end if
  254. ! [t1,t2] is either:
  255. ! covered by mf -> status = 0
  256. ! older than mf -> status = -2
  257. ! newer than mf -> status = -1
  258. ! error ... (half in, half outside mf)
  259. ! seperate tests for intervals and instant time:
  260. if ( t1 == t2 ) then
  261. ! instant time
  262. if ( ( (mf%t1 <= t1) .and. (t1 <= mf%t2) ) ) then
  263. status = 0; return
  264. else if ( t1 < mf%t1 ) then
  265. status = -2; return
  266. else if ( mf%t2 <= t1 ) then
  267. status = -1; return
  268. else
  269. write (gol,'("requested instant time t1 (=t2) overlaps part of mf time:")'); call goErr
  270. call wrtgol( ' t1 : ', t1 ); call goErr
  271. call wrtgol( ' t2 : ', t2 ); call goErr
  272. call wrtgol( ' mf%t1 : ', mf%t1 ); call goErr
  273. call wrtgol( ' mf%t2 : ', mf%t2 ); call goErr
  274. write (gol,'(" params : ",a)') trim(mf%paramkeys); call goErr
  275. TRACEBACK; status = 1; return
  276. end if
  277. else if ( t1 < t2 ) then
  278. ! interval
  279. ! extra: [t1,t2] is covered by mf%(t1,t2) ...
  280. if ( ( (mf%t1 <= t1) .and. (t2 <= mf%t2 ) ) .or. &
  281. ( (mf%t1-IncrDate(mili=1) <= t1) .and. (t2 <= mf%t2+IncrDate(mili=1)) ) ) then
  282. status = 0; return
  283. else if ( t2 <= mf%t1 ) then
  284. ! request for field older than those in file
  285. status = -2; return
  286. else if ( mf%t2 <= t1 ) then
  287. ! request for field newer than those in file
  288. status = -1; return
  289. else
  290. write (gol,'("requested interval [t1,t2] overlaps part of mf time:")'); call goErr
  291. call wrtgol( ' t1 : ', t1 ); call goErr
  292. call wrtgol( ' t2 : ', t2 ); call goErr
  293. call wrtgol( ' mf%t1 : ', mf%t1 ); call goErr
  294. call wrtgol( ' mf%t2 : ', mf%t2 ); call goErr
  295. write (gol,'(" params : ",a)') trim(mf%paramkeys); call goErr
  296. TRACEBACK; status = 1; return
  297. end if
  298. else
  299. write (gol,'("arguments should specify an instant time or valid interval :")'); call goErr
  300. call wrtgol( ' t1 : ', t1 ); call goErr
  301. call wrtgol( ' t2 : ', t2 ); call goErr
  302. TRACEBACK; status = 1; return
  303. end if
  304. ! something wrong if this point is reached ...
  305. status = 1
  306. end subroutine mf_CheckTime
  307. ! ***
  308. ! Check if param is included in meteo file;
  309. ! status:
  310. ! <0 : mf does not include param
  311. ! 0 : mf includes param
  312. ! >0 : error; mf not open ?
  313. !
  314. subroutine mf_CheckParam( mf, io, archivekey, paramkey, status )
  315. use GO, only : goLoCase
  316. ! --- begin -------------------------------------------
  317. type(TMeteoFile), intent(in) :: mf
  318. character(len=*), intent(in) :: io
  319. character(len=*), intent(in) :: archivekey
  320. character(len=*), intent(in) :: paramkey
  321. integer, intent(out) :: status
  322. ! --- const -------------------------------------------
  323. character(len=*), parameter :: rname = mname//'/mf_CheckParam'
  324. ! --- local --------------------------------------------
  325. integer :: pos
  326. ! --- begin -------------------------------------------
  327. ! not open ?
  328. if ( .not. Opened(mf) ) then
  329. write (gol,'("meteo file not opened")'); call goErr
  330. TRACEBACK; status = 1; return
  331. end if
  332. ! by default not found ..
  333. status = -1
  334. ! wrong input/output ? then leave:
  335. if ( io /= mf%io ) return
  336. ! wrong grid ? then leave
  337. if ( archivekey /= mf%archivekey ) return
  338. ! param list is for example: '-ps-pu-pv-',
  339. ! thus search for example for '-pu-' ...
  340. ! convert all to lowercase
  341. pos = index( goLoCase(trim(mf%paramkeys)), '-'//goLoCase(trim(paramkey))//'-' )
  342. if ( pos < 1 ) return
  343. ! ok
  344. status = 0
  345. end subroutine mf_CheckParam
  346. ! ===========================================================
  347. !
  348. ! open meteo file for input
  349. !
  350. ! ===========================================================
  351. !
  352. ! Open the meteo file that contains the field specified by
  353. ! archivekey, parameter key, time,
  354. ! or do nothing if the requested file has been opened already.
  355. !
  356. ! <archivekey> = <archivetype>:<archivename>
  357. !
  358. ! tmpp:od-fc-ml60-glb3x2
  359. ! tmppS:od-fc-ml60-glb3x2
  360. ! grib:od-fc-ml60-glb3x2
  361. ! prism:
  362. !
  363. subroutine mf_SetupInput( mf, archivekey, paramkey, tday, t1, t2, &
  364. rcfilename, dir, status )
  365. use GO, only : goSplitLine, goReadFromLine
  366. use GO, only : goSystem
  367. use GO, only : TrcFile, Init, Done, ReadRc
  368. use GO, only : TDate, IncrDate, Get, NewDate, wrtgol, &
  369. Operator(+), Operator(-), Operator(/)
  370. #ifdef with_tmm_tmpp
  371. use tmm_mf_tmpp , only : Init, Get
  372. #endif
  373. #ifdef with_tmm_tm5
  374. use tmm_mf_tm5_nc , only : Init, Get
  375. #endif
  376. #ifdef with_tmm_ecmwf
  377. use tmm_mf_ecmwf_tmpp, only : Init, Get
  378. use tmm_mf_ecmwf_tm5 , only : Init, Get
  379. #endif
  380. #ifdef with_tmm_ncep
  381. use tmm_mf_ncep_cdc , only : Init, Get
  382. use tmm_mf_ncep_gfs , only : Init, Get
  383. #endif
  384. #ifdef with_prism
  385. use tmm_mf_prism , only : Init
  386. #endif
  387. #ifdef with_tmm_msc
  388. use tmm_mf_msc , only : Init, Get
  389. #endif
  390. ! --- in/out -------------------------------------
  391. type(TMeteoFile), intent(inout) :: mf
  392. character(len=*), intent(in) :: archivekey
  393. character(len=*), intent(in) :: paramkey
  394. type(TDate), intent(in) :: tday, t1, t2
  395. character(len=*), intent(in) :: rcfilename
  396. character(len=*), intent(in) :: dir
  397. integer, intent(inout) :: status
  398. ! --- const -------------------------------------
  399. character(len=*), parameter :: rname = mname//'/mf_SetupInput'
  400. ! name of info file:
  401. character(len=*), parameter :: infofilename = 'tmm_info.rc'
  402. ! --- local -------------------------------------
  403. character(len=10) :: archivetype
  404. character(len=256) :: archivename
  405. character(len=256) :: command
  406. integer :: year1, month1, day1, hour1
  407. integer :: year2, month2, day2, hour2
  408. integer :: dth
  409. type(TrcFile) :: infofile
  410. character(len=256) :: archivename2
  411. character(len=10) :: mclass
  412. character(len=10) :: mtype
  413. character(len=10) :: mlevs
  414. character(len=10) :: mgrid
  415. character(len=10) :: filekey
  416. character(len=16) :: treskey
  417. logical :: with_spm
  418. logical :: constant
  419. ! --- begin -------------------------------------
  420. ! store archive key:
  421. mf%archivekey = trim(archivekey)
  422. mf%dir = trim(dir)
  423. ! split archive key in type and name:
  424. call goSplitLine( archivekey, archivetype, ':', archivename, status )
  425. IF_NOTOK_RETURN(status=1)
  426. ! usually, meteo is storred in file;
  427. ! for PRISM project, meteo is in the memory ...
  428. select case ( archivetype )
  429. #ifdef with_tmm_tmpp
  430. ! ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  431. ! hdf files written by tmpp
  432. ! ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  433. case ( 'tmpp' )
  434. ! wich of the 'mf%mf_???' is used ?
  435. mf%filetype = 'tmpp'
  436. ! setup file:
  437. call Init( mf%mf_tmpp, 'i', dir, archivename, paramkey, &
  438. tday, t1, t2, status )
  439. IF_NOTOK_RETURN(status=1)
  440. ! store filename:
  441. mf%filename = mf%mf_tmpp%fname
  442. ! extract time range:
  443. call Get( mf%mf_tmpp, status, trange1=mf%t1, trange2=mf%t2 )
  444. IF_NOTOK_RETURN(status=1)
  445. ! extract paramkeys for fields in file:
  446. call Get( mf%mf_tmpp, status, paramkeys=mf%paramkeys )
  447. IF_NOTOK_RETURN(status=1)
  448. #endif
  449. #ifdef with_tmm_tm5
  450. ! ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  451. ! netcdf files written by tm5
  452. ! ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  453. case ( 'tm5-nc' )
  454. ! wich of the 'mf%mf_???' is used ?
  455. mf%filetype = 'tm5-nc'
  456. ! setup file:
  457. call Init( mf%mf_tm5_nc, 'i', dir, archivename//';form='//trim(archivetype), paramkey, &
  458. tday, t1, t2, status )
  459. IF_NOTOK_RETURN(status=1)
  460. ! store filename:
  461. mf%filename = mf%mf_tm5_nc%fname
  462. ! extract time range:
  463. call Get( mf%mf_tm5_nc, status, trange1=mf%t1, trange2=mf%t2 )
  464. IF_NOTOK_RETURN(status=1)
  465. ! extract paramkeys for fields in file:
  466. call Get( mf%mf_tm5_nc, status, paramkeys=mf%paramkeys )
  467. IF_NOTOK_RETURN(status=1)
  468. #endif
  469. #ifdef with_tmm_ecmwf
  470. ! ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  471. ! ecmwf grib files
  472. ! ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  473. case ( 'ecmwf-tmpp' )
  474. ! wich of the 'mf%mf_???' is used ?
  475. mf%filetype = 'ecmwf-tmpp'
  476. ! setup file:
  477. call Init( mf%mf_ecmwf_tmpp, dir, archivename, paramkey, &
  478. tday, t1, t2, status )
  479. IF_NOTOK_RETURN(status=1)
  480. ! store filename:
  481. mf%filename = mf%mf_ecmwf_tmpp%fname
  482. ! extract time range:
  483. call Get( mf%mf_ecmwf_tmpp, status, trange1=mf%t1, trange2=mf%t2 )
  484. IF_NOTOK_RETURN(status=1)
  485. ! extract list of parameters in files:
  486. call Get( mf%mf_ecmwf_tmpp, status, paramkeys=mf%paramkeys )
  487. IF_NOTOK_RETURN(status=1)
  488. case ( 'ecmwf-tm5' )
  489. ! wich of the 'mf%mf_???' is used ?
  490. mf%filetype = 'ecmwf-tm5'
  491. ! setup file:
  492. call Init( mf%mf_ecmwf_tm5, dir, trim(archivename), paramkey, &
  493. tday, t1, t2, status )
  494. IF_NOTOK_RETURN(status=1)
  495. ! store filename:
  496. mf%filename = mf%mf_ecmwf_tm5%fname
  497. ! extract time range:
  498. call Get( mf%mf_ecmwf_tm5, status, trange1=mf%t1, trange2=mf%t2 )
  499. IF_NOTOK_RETURN(status=1)
  500. ! extract list of parameters in files:
  501. call Get( mf%mf_ecmwf_tm5, status, paramkeys=mf%paramkeys )
  502. IF_NOTOK_RETURN(status=1)
  503. #endif
  504. #ifdef with_tmm_ncep
  505. ! ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  506. ! ncep files
  507. ! ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  508. case ( 'ncep-cdc' )
  509. ! wich of the 'mf%mf_???' is used ?
  510. mf%filetype = 'ncep-cdc'
  511. ! setup file:
  512. call Init( mf%mf_ncep_cdc, dir, archivename, paramkey, &
  513. tday, t1, t2, status )
  514. IF_NOTOK_RETURN(status=1)
  515. ! store filename:
  516. mf%filename = mf%mf_ncep_cdc%fname
  517. ! extract time range:
  518. call Get( mf%mf_ncep_cdc, status, trange1=mf%t1, trange2=mf%t2 )
  519. IF_NOTOK_RETURN(status=1)
  520. ! extract list of parameters in files:
  521. call Get( mf%mf_ncep_cdc, status, paramkeys=mf%paramkeys )
  522. IF_NOTOK_RETURN(status=1)
  523. case ( 'ncep-gfs' )
  524. ! wich of the 'mf%mf_???' is used ?
  525. mf%filetype = 'ncep-gfs'
  526. ! setup file:
  527. call Init( mf%mf_ncep_gfs, dir, archivename, paramkey, &
  528. tday, t1, t2, status )
  529. IF_NOTOK_RETURN(status=1)
  530. ! store filename:
  531. mf%filename = mf%mf_ncep_gfs%fname
  532. ! extract time range:
  533. call Get( mf%mf_ncep_gfs, status, trange1=mf%t1, trange2=mf%t2 )
  534. IF_NOTOK_RETURN(status=1)
  535. ! extract list of parameters in files:
  536. call Get( mf%mf_ncep_gfs, status, paramkeys=mf%paramkeys )
  537. IF_NOTOK_RETURN(status=1)
  538. #endif
  539. #ifdef with_tmm_msc
  540. ! ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  541. ! msc-data text files
  542. ! ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  543. case ( 'msc-data' )
  544. ! wich of the 'mf%mf_???' is used ?
  545. mf%filetype = 'msc-data'
  546. ! setup file:
  547. call Init( mf%mf_msc, dir, archivename, paramkey, &
  548. tday, t1, t2, status )
  549. IF_NOTOK_RETURN(status=1)
  550. ! store filename:
  551. mf%filename = mf%mf_msc%fname
  552. ! extract time range:
  553. call Get( mf%mf_msc, status, trange1=mf%t1, trange2=mf%t2 )
  554. IF_NOTOK_RETURN(status=1)
  555. ! extract which fields are stored in the file:
  556. call Get( mf%mf_msc, status, paramkeys=mf%paramkeys )
  557. IF_NOTOK_RETURN(status=1)
  558. #endif
  559. #ifdef with_prism
  560. ! ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  561. ! prism meteo in memory
  562. ! ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  563. case ( 'prism' )
  564. ! only the requested parameter is provided by this prism 'file' ...
  565. mf%paramkeys = '-'//trim(paramkey)//'-'
  566. ! infinite time range ...
  567. mf%t1 = NewDate( year=1900, month=1, day=1, hour=1 )
  568. mf%t2 = NewDate( year=9999, month=9, day=9, hour=9 )
  569. !call wrtgol( ' fields valid from : ', mf%t1 )
  570. !call wrtgol( ' to : ', mf%t2 )
  571. ! set file type and file name:
  572. mf%filetype = 'prism'
  573. mf%filename = 'dummy'
  574. ! setup prism access;
  575. ! tday is used for orography date
  576. ! (adhoc solution; at the moment only [t1,t2] is provided to ReadRecord
  577. ! but this should become tday, [t1,t2] )
  578. call Init( mf%mf_prism, tday, status )
  579. IF_NOTOK_RETURN(status=1)
  580. #endif
  581. ! ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  582. ! error ...
  583. ! ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  584. case default
  585. write (gol,'("unsupported archivetype `",a,"`")') trim(archivetype); call goErr
  586. TRACEBACK; status=1; return
  587. end select
  588. ! file is opened (or, at least file name is known)
  589. mf%opened = .true.
  590. ! ok
  591. status = 0
  592. end subroutine mf_SetupInput
  593. ! ===========================================================
  594. !
  595. ! read fields, grid definition, etc
  596. !
  597. ! ===========================================================
  598. subroutine mf_ReadRecord( mf, paramkey, unit, tday, t1, t2, nuv, nw, &
  599. gridtype, levi, &
  600. lli, ll, sp_ll, &
  601. ggi, gg, sp_gg, &
  602. shi, sh, lnsp_sh, &
  603. tmi, status )
  604. use GO , only : TDate, operator(+), operator(-), operator(/)
  605. use Grid , only : TllGridInfo, TggGridInfo, TshGridInfo, TLevelInfo
  606. use tmm_info , only : TMeteoInfo, Init, AddHistory
  607. #ifdef with_tmm_tmpp
  608. use tmm_mf_tmpp , only : ReadRecord
  609. #endif
  610. #ifdef with_tmm_tm5
  611. use tmm_mf_tm5_nc , only : ReadRecord
  612. #endif
  613. #ifdef with_tmm_ecmwf
  614. use tmm_mf_ecmwf_tmpp, only : ReadRecord
  615. use tmm_mf_ecmwf_tm5 , only : ReadRecord
  616. #endif
  617. #ifdef with_tmm_ncep
  618. use tmm_mf_ncep_cdc , only : ReadRecord
  619. use tmm_mf_ncep_gfs , only : ReadRecord
  620. #endif
  621. #ifdef with_prism
  622. use tmm_mf_prism , only : ReadRecord
  623. #endif
  624. #ifdef with_tmm_msc
  625. use tmm_mf_msc , only : ReadRecord
  626. #endif
  627. ! --- in/out -------------------------------
  628. type(TMeteoFile), intent(inout) :: mf
  629. character(len=*), intent(in) :: paramkey
  630. character(len=*), intent(in) :: unit
  631. type(TDate), intent(in) :: tday, t1, t2
  632. character(len=1), intent(in) :: nuv
  633. character(len=1), intent(in) :: nw
  634. character(len=2), intent(out) :: gridtype
  635. type(TLevelInfo), intent(out) :: levi
  636. type(TllGridInfo), intent(inout) :: lli
  637. real, pointer :: ll(:,:,:)
  638. real, pointer :: sp_ll(:,:)
  639. type(TggGridInfo), intent(inout) :: ggi
  640. real, pointer :: gg(:,:)
  641. real, pointer :: sp_gg(:)
  642. type(TshGridInfo), intent(inout) :: shi
  643. complex, pointer :: sh(:,:)
  644. complex, pointer :: lnsp_sh(:)
  645. type(TMeteoInfo), intent(out) :: tmi
  646. integer, intent(out) :: status
  647. ! --- const --------------------------------------
  648. character(len=*), parameter :: rname = mname//'/mf_ReadRecord'
  649. ! --- local --------------------------------------
  650. type(TDate) :: tmid
  651. ! --- begin ---------------------------------
  652. !write (*,'(a,": begin")') name
  653. select case ( mf%filetype )
  654. #ifdef with_tmm_tmpp
  655. case ( 'tmpp' )
  656. ! read from hdf file:
  657. call ReadRecord( mf%mf_tmpp, paramkey, t1, t2, nuv, nw, &
  658. gridtype, levi, &
  659. lli, ll, sp_ll, &
  660. status )
  661. IF_NOTOK_RETURN(status=1)
  662. ! fill some info values:
  663. call Init( tmi, paramkey, 'unkown', status )
  664. call AddHistory( tmi, 'archivekey=='//trim(mf%archivekey), status )
  665. #endif
  666. #ifdef with_tmm_tm5
  667. case ( 'tm5-nc' ) ! read from netcdf file
  668. call ReadRecord( mf%mf_tm5_nc, paramkey, unit, t1, t2, nuv, nw, &
  669. gridtype, levi, lli, ll, sp_ll, status )
  670. IF_NOTOK_RETURN(status=1)
  671. ! fill some info values:
  672. call Init( tmi, paramkey, 'unkown', status )
  673. call AddHistory( tmi, 'archivekey=='//trim(mf%archivekey), status )
  674. #endif
  675. #ifdef with_tmm_ecmwf
  676. case ( 'ecmwf-tmpp' )
  677. ! read from grib file:
  678. call ReadRecord( mf%mf_ecmwf_tmpp, paramkey, t1, t2, nuv, nw, &
  679. gridtype, levi, &
  680. lli, ll, sp_ll, &
  681. ggi, gg, sp_gg, &
  682. shi, sh, lnsp_sh, &
  683. tmi, status )
  684. IF_NOTOK_RETURN(status=1)
  685. case ( 'ecmwf-tm5' )
  686. ! read from grib file:
  687. call ReadRecord( mf%mf_ecmwf_tm5, paramkey, tday, t1, t2, nuv, nw, &
  688. gridtype, levi, &
  689. lli, ll, sp_ll, &
  690. ggi, gg, sp_gg, &
  691. shi, sh, lnsp_sh, &
  692. tmi, status )
  693. IF_NOTOK_RETURN(status=1)
  694. #endif
  695. #ifdef with_tmm_ncep
  696. case ( 'ncep-cdc' )
  697. ! read from ncep file:
  698. call ReadRecord( mf%mf_ncep_cdc, paramkey, t1, t2, nuv, nw, &
  699. gridtype, levi, &
  700. lli, ll, sp_ll, &
  701. ggi, gg, sp_gg, &
  702. shi, sh, lnsp_sh, &
  703. tmi, status )
  704. IF_NOTOK_RETURN(status=1)
  705. #endif
  706. #ifdef with_tmm_ncep
  707. case ( 'ncep-gfs' )
  708. ! read from ncep file:
  709. call ReadRecord( mf%mf_ncep_gfs, paramkey, t1, t2, nuv, nw, &
  710. gridtype, levi, &
  711. lli, ll, sp_ll, &
  712. ggi, gg, sp_gg, &
  713. shi, sh, lnsp_sh, &
  714. tmi, status )
  715. IF_NOTOK_RETURN(status=1)
  716. #endif
  717. #ifdef with_prism
  718. case ( 'prism' )
  719. ! receive from oasis coupler:
  720. call ReadRecord( mf%mf_prism, paramkey, t1, t2, nuv, nw, &
  721. gridtype, levi, &
  722. lli, ll, sp_ll, &
  723. ggi, gg, sp_gg, &
  724. shi, sh, lnsp_sh, &
  725. tmi, status )
  726. IF_NOTOK_RETURN(status=1)
  727. #endif
  728. #ifdef with_tmm_msc
  729. case ( 'msc-data' )
  730. ! read from grib file:
  731. tmid = t1 + (t2-t1)/2
  732. call ReadRecord( mf%mf_msc, paramkey, tmid, tmid, nuv, nw, &
  733. gridtype, levi, &
  734. lli, ll, sp_ll, &
  735. ggi, gg, sp_gg, &
  736. shi, sh, lnsp_sh, &
  737. tmi, status )
  738. IF_NOTOK_RETURN(status=1)
  739. #endif
  740. case default
  741. write (gol,'("unsupported filetype `",a,"`")') trim(mf%filetype); call goErr
  742. TRACEBACK; status=1; return
  743. end select
  744. ! ok
  745. status = 0
  746. !write (*,'(a,": end")') name
  747. end subroutine mf_ReadRecord
  748. ! ***
  749. ! ===========================================================
  750. !
  751. ! open meteo file for output
  752. !
  753. ! ===========================================================
  754. !
  755. ! Open the meteo file that should contain the field specified by
  756. ! archivekey, parameter key, time,
  757. ! or do nothing if the requested file has been opened already.
  758. !
  759. ! <archivekey> = <archivetype>:<archivename>
  760. !
  761. ! tmpp:od-fc-ml60-glb3x2
  762. !
  763. subroutine mf_SetupOutput( mf, archivekey, paramkey, tday, t1, t2, &
  764. rcfilename, dir, status )
  765. use GO, only : goSplitLine
  766. use GO, only : TrcFile, Init, Done, ReadRc
  767. use GO, only : TDate
  768. #ifdef with_tmm_tm5
  769. use tmm_mf_tm5_nc , only : Init, Get
  770. #endif
  771. ! --- in/out -------------------------------------
  772. type(TMeteoFile), intent(inout) :: mf
  773. character(len=*), intent(in) :: archivekey
  774. character(len=*), intent(in) :: paramkey
  775. type(TDate), intent(in) :: tday, t1, t2
  776. character(len=*), intent(in) :: rcfilename
  777. character(len=*), intent(in) :: dir
  778. integer, intent(inout) :: status
  779. ! --- const -------------------------------------
  780. character(len=*), parameter :: rname = mname//'/mf_SetupOutput'
  781. ! --- local -------------------------------------
  782. character(len=10) :: archivetype
  783. character(len=256) :: archivename
  784. ! character(len=256) :: command
  785. ! integer :: year1, month1, day1, hour1
  786. ! integer :: year2, month2, day2, hour2
  787. ! integer :: dth
  788. type(TrcFile) :: infofile
  789. character(len=256) :: archivename2
  790. character(len=10) :: mclass
  791. character(len=10) :: mtype
  792. character(len=10) :: mlevs
  793. character(len=10) :: mgrid
  794. character(len=10) :: filekey
  795. character(len=16) :: treskey
  796. logical :: with_spm
  797. ! --- begin -------------------------------------
  798. ! store archive key:
  799. mf%archivekey = trim(archivekey)
  800. ! split archive key in type and name:
  801. call goSplitLine( archivekey, archivetype, ':', archivename, status )
  802. IF_NOTOK_RETURN(status=1)
  803. ! deceide on archive type:
  804. select case ( archivetype )
  805. #ifdef with_tmm_tm5
  806. ! ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  807. ! daily netcdf files
  808. ! ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  809. case ( 'tm5-nc' )
  810. ! always netcdf files:
  811. mf%filetype = 'tm5-nc'
  812. ! setup file:
  813. call Init( mf%mf_tm5_nc, 'o', dir, trim(archivename), paramkey, &
  814. tday, t1, t2, status )
  815. IF_NOTOK_RETURN(status=1)
  816. ! store filename:
  817. call Get( mf%mf_tm5_nc, status, filename=mf%filename )
  818. IF_NOTOK_RETURN(status=1)
  819. ! extract time range:
  820. call Get( mf%mf_tm5_nc, status, trange1=mf%t1, trange2=mf%t2 )
  821. IF_NOTOK_RETURN(status=1)
  822. ! extract paramkeys for fields in file:
  823. call Get( mf%mf_tm5_nc, status, paramkeys=mf%paramkeys )
  824. IF_NOTOK_RETURN(status=1)
  825. #endif
  826. ! ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  827. ! error ...
  828. ! ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  829. case default
  830. write (gol,'("unsupported archivetype `",a,"`")') trim(archivetype); call goErr
  831. write (gol,'(" for archivekey `",a,"`")') trim(archivekey); call goErr
  832. write (gol,'(" and for paramkey `",a,"`")') trim(paramkey); call goErr
  833. TRACEBACK; status=1; return
  834. end select
  835. ! file is opened (or, at least file name is known)
  836. mf%opened = .true.
  837. ! ok
  838. status = 0
  839. end subroutine mf_SetupOutput
  840. ! ***
  841. subroutine mf_WriteRecord_2d( mf, tmi, paramkey, unit, tday, t1, t2, &
  842. lli, nuv, ll, status )
  843. use GO , only : TDate
  844. use Grid , only : TllGridInfo
  845. use tmm_info , only : TMeteoInfo
  846. #ifdef with_tmm_tm5
  847. use tmm_mf_tm5_nc , only : WriteRecord
  848. #endif
  849. ! --- in/out -------------------------------
  850. type(TMeteoFile), intent(inout) :: mf
  851. type(TMeteoInfo), intent(in) :: tmi
  852. character(len=*), intent(in) :: paramkey, unit
  853. type(TDate), intent(in) :: tday, t1, t2
  854. type(TllGridInfo), intent(in) :: lli
  855. character(len=1), intent(in) :: nuv
  856. real, intent(in) :: ll(:,:)
  857. integer, intent(out) :: status
  858. ! --- const --------------------------------------
  859. character(len=*), parameter :: rname = mname//'/mf_WriteRecord_2d'
  860. ! --- begin ---------------------------------
  861. select case ( mf%filetype )
  862. #ifdef with_tmm_tm5
  863. case ( 'tm5-nc' )
  864. call WriteRecord( mf%mf_tm5_nc, tmi, paramkey, unit, tday, t1, t2, &
  865. lli, nuv, ll, status )
  866. IF_NOTOK_RETURN(status=1)
  867. #endif
  868. case default
  869. write (gol,'("unsupported filetype `",a,"`")') trim(mf%filetype); call goErr
  870. TRACEBACK; status=1; return
  871. end select
  872. ! ok
  873. status = 0
  874. end subroutine mf_WriteRecord_2d
  875. ! ***
  876. subroutine mf_WriteRecord_3d( mf, tmi, spname, paramkey, unit, tday, t1, t2, &
  877. lli, nuv, levi, nw, ps, ll, status )!, &
  878. !nlev )
  879. use GO , only : TDate
  880. use Grid , only : TllGridInfo, TLevelInfo
  881. use tmm_info , only : TMeteoInfo
  882. #ifdef with_tmm_tm5
  883. use tmm_mf_tm5_nc , only : WriteRecord
  884. #endif
  885. ! --- in/out -------------------------------
  886. type(TMeteoFile), intent(inout) :: mf
  887. type(TMeteoInfo), intent(in) :: tmi
  888. character(len=*), intent(in) :: spname, paramkey, unit
  889. type(TDate), intent(in) :: tday, t1, t2
  890. type(TllGridInfo), intent(in) :: lli
  891. character(len=1), intent(in) :: nuv
  892. type(TLevelInfo), intent(in) :: levi
  893. character(len=1), intent(in) :: nw
  894. real, intent(in) :: ps(:,:)
  895. real, intent(in) :: ll(:,:,:)
  896. integer, intent(out) :: status
  897. !integer, intent(in), optional :: nlev
  898. ! --- const --------------------------------------
  899. character(len=*), parameter :: rname = mname//'/mf_WriteRecord_3d'
  900. ! --- begin ---------------------------------
  901. select case ( mf%filetype )
  902. #ifdef with_tmm_tm5
  903. case ( 'tm5-nc' )
  904. call WriteRecord( mf%mf_tm5_nc, tmi, spname, paramkey, unit, tday, t1, t2, &
  905. lli, nuv, levi, nw, ps, ll, status )!, &
  906. !nlev=nlev )
  907. IF_NOTOK_RETURN(status=1)
  908. #endif
  909. case default
  910. write (gol,'("unsupported filetype `",a,"`")') trim(mf%filetype); call goErr
  911. TRACEBACK; status=1; return
  912. end select
  913. ! ok
  914. status = 0
  915. end subroutine mf_WriteRecord_3d
  916. end module tmm_mf