user_output_cf.F90 78 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284
  1. !#################################################################
  2. !
  3. ! CF-conform HDF Output
  4. !
  5. ! NetCDF files following CF conventions.
  6. !
  7. ! Based on CF conform output see:
  8. ! website
  9. ! http://cf-pcmdi.llnl.gov/
  10. !
  11. ! NetCDF Climate and Forecast (CF) Metadata Convention
  12. !
  13. !
  14. ! Files should now follow the CF conventions, which:
  15. !
  16. ! - longitudes from [0,360] ?
  17. ! - levels from surface to top
  18. ! - time from 2001-01-01 00:00
  19. !
  20. ! SAMPLE RCFILE
  21. !
  22. ! output.cf : T
  23. ! output.cf.dataset.author : A. Slave (KNMI)
  24. ! output.cf.dataset.institution : KNMI, De Bilt, The Netherlands
  25. ! output.cf.dataset.version : GEMS run
  26. ! output.cf.fname.model : TM5
  27. ! output.cf.fname.expid : V1
  28. !
  29. ! output.cf.griddef.apply : F
  30. !
  31. ! output.cf.tp.apply : T
  32. !
  33. ! output.cf.vmr.n : 3
  34. ! output.cf.vmr.001.apply : T
  35. ! output.cf.vmr.001.fname : vmr3
  36. ! output.cf.vmr.001.dhour : 3
  37. ! output.cf.vmr.001.tracers : SO2 NOy CH4 OH HNO3 PAN H2O2 Radon Lead
  38. ! output.cf.vmr.002.apply : T
  39. !
  40. ! output.cf.vmr.002.fname : vmr1
  41. ! output.cf.vmr.002.dhour : 1
  42. ! output.cf.vmr.002.tracers : O3 O3s CO NO2 NO CH2O
  43. ! output.cf.vmr.003.apply : F
  44. !
  45. ! output.cf.vmr.003.fname : vmra
  46. ! output.cf.vmr.003.dhour : 3
  47. ! output.cf.vmr.003.tracers : SO4 NO3_A BC BCS POM SS1_N SS1_M SS2_N SS2_M SS3_N SS3_M DUST2_N DUST2_M DUST3_N DUST3_M
  48. !
  49. ! output.cf.depositions.apply : F
  50. ! output.cf.depositions.dhour : 3
  51. ! output.cf.depositions.tracers : O3 HNO3 NO NO2 H2O2 CH2O PAN CO NH3 NH4 SO2 NOy
  52. !
  53. ! output.cf.depvels.apply : F
  54. ! output.cf.depvels.dhour : 3
  55. ! output.cf.depvels.tracers : O3 HNO3 NO NO2 H2O2 CH2O PAN CO NH3 NH4 SO2
  56. !
  57. !
  58. !### macro's #####################################################
  59. !
  60. #define TRACEBACK write (gol,'("in ",a," (",a,", line",i5,")")') rname, __FILE__, __LINE__; call goErr
  61. #define IF_NOTOK_RETURN(action) if (status/=0) then; TRACEBACK; action; return; end if
  62. #define IF_ERROR_RETURN(action) if (status> 0) then; TRACEBACK; action; return; end if
  63. !
  64. #include "tm5.inc"
  65. !
  66. !#################################################################
  67. module user_output_cf
  68. use GO , only : gol, goPr, goErr, goLabel
  69. use GO , only : TDate
  70. use dims , only : nregions
  71. use chem_param , only : ntrace
  72. use chem_param , only : iNOx, iHNO3, iNO3_a, iPAN, iOrgNtr
  73. #ifdef with_tendencies
  74. use tm5_tendency, only : plc_ntr, plc_npr
  75. #endif
  76. use file_hdf, only : THdfFile, TSds,setdim
  77. implicit none
  78. ! --- in/out --------------------------
  79. private
  80. public :: Output_CF_Init, Output_CF_Done, Output_CF_Step
  81. ! --- const ---------------------------
  82. character(len=*), parameter :: mname = 'user_output.cf'
  83. ! reference time:
  84. integer, parameter :: time_reftime6(6) = (/2000,01,01,00,00,00/)
  85. character(len=*), parameter :: time_units = 'days since 2000-01-01 00:00:00'
  86. !
  87. ! NOy is not a standard tracer field, but sum of some transported tracers:
  88. ! NOx HNO3 PAN orgntr NO3_a
  89. ! where NOx is the sum of short lived tracers:
  90. ! NOx = NO + NO2 + NO3 + HNO4 + 2*N2O5
  91. !
  92. integer, parameter :: iNOy = ntrace + 1
  93. integer, parameter :: nNOyt = 5
  94. integer, parameter :: iNOyt(nNOyt) = (/ iNOx, iHNO3, iNO3_a, iPAN, iOrgNtr /)
  95. ! --- types ---------------------------
  96. type TCF_File_GridDef
  97. integer :: trec
  98. integer :: ncid
  99. integer :: dimid_scalar, dimid_lon, dimid_lat, dimid_lev, dimid_levi
  100. integer :: varid_lon, varid_lat, varid_time, varid_date
  101. integer :: varid_gridbox_area
  102. integer :: varid_a, varid_b
  103. integer :: varid_a_bnds, varid_b_bnds
  104. integer :: varid_p0
  105. !integer :: varid_ps
  106. !integer :: varid_geo_height
  107. end type TCF_File_GridDef
  108. type TCF_File_TP
  109. integer :: trec
  110. integer :: ncid
  111. integer :: dimid_lon, dimid_lat, dimid_lev, dimid_time, dimid_datelen
  112. integer :: varid_lon, varid_lat, varid_lev, varid_time, varid_date
  113. integer :: varid_ps
  114. integer :: varid_surface_temp
  115. integer :: varid_orog
  116. integer :: varid_geop
  117. integer :: varid_pressure
  118. integer :: varid_temp
  119. integer :: varid_humid
  120. integer :: varid_u, varid_v, varid_w
  121. end type TCF_File_TP
  122. type TCF_File_VMR
  123. integer :: trec
  124. integer :: dhour
  125. character(len=256) :: tracer_names
  126. integer :: ncid
  127. integer :: dimid_lon, dimid_lat, dimid_lev, dimid_time, dimid_datelen
  128. integer :: varid_lon, varid_lat, varid_lev, varid_time, varid_date
  129. integer :: ntr
  130. integer :: itr(ntrace)
  131. character(len=8) :: name_tr(ntrace)
  132. integer :: varid_tr(ntrace)
  133. end type TCF_File_VMR
  134. type TCF_File_DEPS
  135. integer :: trec
  136. integer :: dhour
  137. character(len=256) :: tracer_names
  138. integer :: ncid
  139. integer :: dimid_lon, dimid_lat, dimid_time, dimid_datelen
  140. integer :: varid_lon, varid_lat, varid_time, varid_date, varid_accum
  141. integer :: ntr
  142. integer :: itr(ntrace)
  143. character(len=8) :: name_tr(ntrace)
  144. integer :: varid_ddep(ntrace)
  145. real, pointer :: ddep_budget(:,:,:)
  146. logical :: with_wdep(ntrace)
  147. integer :: varid_wdep(ntrace)
  148. real, pointer :: wdep_budget(:,:,:)
  149. type(TDate) :: t0_budget
  150. end type TCF_File_DEPS
  151. type TCF_File_DEPV
  152. integer :: trec
  153. integer :: dhour
  154. character(len=256) :: tracer_names
  155. integer :: ncid
  156. integer :: dimid_lon, dimid_lat, dimid_time, dimid_datelen
  157. integer :: varid_lon, varid_lat, varid_time, varid_date
  158. integer :: ntr
  159. integer :: itr(ntrace)
  160. character(len=8) :: name_tr(ntrace)
  161. integer :: varid_tr(ntrace)
  162. end type TCF_File_DEPV
  163. #ifdef with_tendencies
  164. type TCF_File_TEND
  165. integer :: trec
  166. integer :: dhour
  167. character(len=256) :: tracer_names
  168. character(len=256) :: proces_names
  169. integer :: ncid
  170. integer :: dimid_lon, dimid_lat, dimid_lev, dimid_time, dimid_datelen
  171. integer :: varid_lon, varid_lat, varid_lev, varid_time, varid_date
  172. integer :: ntr
  173. integer :: itr(plc_ntr)
  174. character(len=8) :: name_tr(plc_ntr)
  175. integer :: npr
  176. integer :: ipr(plc_npr)
  177. character(len=8) :: name_pr(plc_npr)
  178. integer :: varid_tend(plc_ntr,plc_npr)
  179. end type TCF_File_TEND
  180. #endif
  181. type(THdfFile) :: GridDef_hdf(nregions)
  182. type TCF_output_var
  183. integer :: ivar
  184. character(len=128) :: var_name
  185. character(len=32) :: param_name
  186. character(len=32) :: param_name_default
  187. character(len=256) :: stand_name
  188. character(len=256) :: stand_name_default
  189. character(len=512) :: long_name
  190. character(len=512) :: long_name_default
  191. character(len=256) :: units
  192. character(len=256) :: units_default
  193. end type TCF_output_var
  194. ! --- var -----------------------------
  195. integer :: curr_day(nregions,3)
  196. character(len=32) :: fname_model
  197. character(len=6) :: fname_expid
  198. character(len=32) :: fname_grid(nregions)
  199. character(len=256) :: dataset_author, dataset_institution, dataset_version
  200. logical :: griddef_apply
  201. type(TCF_File_GridDef), save :: CFGridDef(nregions)
  202. integer :: nvar_dims
  203. integer,parameter :: CF_grid_nvar=10
  204. type(TCF_output_var), save :: CF_grid_var(CF_grid_nvar)
  205. type(TSds), save :: sds_grid(CF_grid_nvar)
  206. logical, allocatable :: vmr_apply(:)
  207. type(TCF_output_var), save :: CF_vmr_var(ntrace)
  208. type(TSds), allocatable, save :: sds_vmr_inst(:,:,:)
  209. logical :: tp_apply
  210. ! currently only surface pressure; to be extended
  211. type(TCF_output_var), save :: CF_TP_var(1)
  212. integer, save :: nvmr
  213. logical, allocatable :: vmr_apply_average(:)
  214. character(len=16), allocatable :: vmr_fname(:)
  215. integer, allocatable :: vmr_nvars(:)
  216. integer, allocatable :: vmr_dhour(:)
  217. character(len=256), allocatable :: vmr_tracer_names(:)
  218. type(TCF_File_VMR), allocatable, save :: CFVMR(:,:)
  219. type(THdfFile), allocatable, save :: CFVMR_hdf_inst(:,:)
  220. type(THdfFile), allocatable, save :: CFVMR_hdf_average(:,:)
  221. type(TCF_File_TP), save :: CFTP(nregions)
  222. type(TSds), allocatable, save :: sds_vmr_average(:,:,:)
  223. logical :: deps_apply
  224. character(len=16) :: deps_fname
  225. integer :: deps_dhour
  226. character(len=256) :: deps_tracer_names
  227. type(TCF_File_DEPS), save :: CFDEPS(nregions)
  228. logical :: depv_apply
  229. character(len=16) :: depv_fname
  230. integer :: depv_dhour
  231. character(len=256) :: depv_tracer_names
  232. type(TCF_File_DEPV), save :: CFDEPV(nregions)
  233. contains
  234. ! ********************************************************************
  235. ! ***
  236. ! *** init/step/done cf output
  237. ! *** and the naming
  238. ! ***
  239. ! ********************************************************************
  240. ! ***
  241. ! ********************************************************************
  242. ! ***
  243. ! *** subroutine Output_CF_naming reads in the rc-file that
  244. ! *** provides the user-defined naming conventions for the variables that
  245. ! *** are requested to be written out.
  246. ! *** The attributes currently contain the parameter name, default name, long name,
  247. ! *** and units.
  248. ! ***
  249. ! *** All default settings can be overwritten by the data from the rc-file.
  250. ! ********************************************************************
  251. subroutine Output_CF_naming(rcF,status)
  252. use GO , only : TrcFile, ReadRc
  253. use chem_param, only : ntrace, names, ra
  254. ! --- in/out ---------------------------------
  255. type(TrcFile), intent(inout) :: rcF
  256. integer, intent(out) :: status
  257. ! --- const ------------------------------
  258. character(len=*), parameter :: rname = mname//'/Output_CF_naming'
  259. ! --- local ------------------------------
  260. character(len=128) :: test_param_name
  261. integer :: ivar
  262. character(len=32) :: varname, varname_conc, varname_spec
  263. character(len=64) :: cf_medium_stnd, cf_medium_long
  264. character(len=64) :: cf_enti_stnd, cf_enti_long, cf_enti_unit
  265. character(len=64) :: cf_spec_stnd, cf_spec_long
  266. character(len=256) :: cf_name_stnd, cf_name_long, cf_name_unit
  267. character(len=512) :: comment
  268. ! --- begin -------------------------------
  269. !initialize standard names of keys...
  270. ivar=1
  271. CF_grid_var(ivar)%var_name='lon'
  272. CF_grid_var(ivar)%param_name_default='lon'
  273. CF_grid_var(ivar)%stand_name_default='longitude'
  274. CF_grid_var(ivar)%long_name_default='longitude'
  275. CF_grid_var(ivar)%units_default='degrees_east'
  276. ivar=2
  277. CF_grid_var(ivar)%var_name='lat'
  278. CF_grid_var(ivar)%param_name_default='lat'
  279. CF_grid_var(ivar)%stand_name_default='latitude'
  280. CF_grid_var(ivar)%long_name_default='latitude'
  281. CF_grid_var(ivar)%units_default='degrees_north'
  282. ivar=3
  283. CF_grid_var(ivar)%var_name='lev'
  284. CF_grid_var(ivar)%param_name_default='lev'
  285. CF_grid_var(ivar)%stand_name_default='level'
  286. CF_grid_var(ivar)%long_name_default='level'
  287. CF_grid_var(ivar)%units_default='level'
  288. ivar=4
  289. CF_grid_var(ivar)%var_name='time'
  290. CF_grid_var(ivar)%param_name_default='time'
  291. CF_grid_var(ivar)%stand_name_default='time'
  292. CF_grid_var(ivar)%long_name_default='time'
  293. CF_grid_var(ivar)%units_default='time'
  294. ivar=5
  295. CF_grid_var(ivar)%var_name='date'
  296. CF_grid_var(ivar)%param_name_default='date'
  297. CF_grid_var(ivar)%stand_name_default='date'
  298. CF_grid_var(ivar)%long_name_default='date'
  299. CF_grid_var(ivar)%units_default='date'
  300. ivar=6
  301. CF_grid_var(ivar)%var_name='area'
  302. CF_grid_var(ivar)%param_name_default='area'
  303. CF_grid_var(ivar)%stand_name_default='grid_cell_area'
  304. CF_grid_var(ivar)%long_name_default='grid-cell area'
  305. CF_grid_var(ivar)%units_default='m2'
  306. ivar=7
  307. CF_grid_var(ivar)%var_name='a'
  308. CF_grid_var(ivar)%param_name_default='a'
  309. CF_grid_var(ivar)%stand_name_default='atmosphere_hybrid_sigma_coordinate'
  310. CF_grid_var(ivar)%long_name_default='hybrid sigma coordinate a coefficient'
  311. CF_grid_var(ivar)%units_default='1'
  312. ivar=8
  313. CF_grid_var(ivar)%var_name='b'
  314. CF_grid_var(ivar)%param_name_default='b'
  315. CF_grid_var(ivar)%stand_name_default='atmosphere_hybrid_sigma_coordinate'
  316. CF_grid_var(ivar)%long_name_default='hybrid sigma coordinate b coefficient'
  317. CF_grid_var(ivar)%units_default='1'
  318. ivar=9
  319. CF_grid_var(ivar)%var_name='a_bnds'
  320. CF_grid_var(ivar)%param_name_default='a_bnds'
  321. CF_grid_var(ivar)%stand_name_default='atmosphere_hybrid_sigma_coordinate'
  322. CF_grid_var(ivar)%long_name_default='hybrid sigma coordinate a coefficient for layer bounds'
  323. CF_grid_var(ivar)%units_default='1'
  324. ivar=10
  325. CF_grid_var(ivar)%var_name='b_bnds'
  326. CF_grid_var(ivar)%param_name_default='b_bnds'
  327. CF_grid_var(ivar)%stand_name_default='atmosphere_hybrid_sigma_coordinate'
  328. CF_grid_var(ivar)%long_name_default='hybrid sigma coordinate b coefficient for layer bounds'
  329. CF_grid_var(ivar)%units_default='1'
  330. !read names of keys from rc-file
  331. do ivar =1,CF_grid_nvar
  332. call ReadRc( rcF, 'output.cf.griddef.'//trim( CF_grid_var(ivar)%var_name)//'.param.name', CF_grid_var(ivar)%param_name, status,default=trim(CF_grid_var(ivar)%param_name_default) )
  333. IF_ERROR_RETURN(status=1)
  334. call ReadRc( rcF, 'output.cf.griddef.'//trim( CF_grid_var(ivar)%var_name)//'.stand.name', CF_grid_var(ivar)%stand_name, status,default=trim(CF_grid_var(ivar)%stand_name_default) )
  335. IF_ERROR_RETURN(status=1)
  336. call ReadRc( rcF, 'output.cf.griddef.'//trim( CF_grid_var(ivar)%var_name)//'.long.name', CF_grid_var(ivar)%long_name , status,default=trim(CF_grid_var(ivar)%long_name_default) )
  337. IF_ERROR_RETURN(status=1)
  338. call ReadRc( rcF, 'output.cf.griddef.'//trim( CF_grid_var(ivar)%var_name)//'.units' , CF_grid_var(ivar)%units , status,default=trim(CF_grid_var(ivar)%units_default) )
  339. IF_ERROR_RETURN(status=1)
  340. enddo
  341. ! loop over all available tracers to define
  342. ! CF standard name for species:
  343. cf_enti_stnd = 'mole_fraction' ; cf_enti_unit = 'mole mole-1' ; cf_enti_long = 'volume mixing ratio'
  344. ! CF standard name for medium:
  345. cf_medium_stnd = 'in_air' ; cf_medium_long = 'in humid air'
  346. ! begin of variable name:
  347. varname_conc = 'vmr'
  348. ! no comment yet
  349. comment = ''
  350. ! standard names from CF conventions:
  351. do ivar = 1,ntrace
  352. select case ( trim(names(ivar)) )
  353. case ( 'CO', 'co' )
  354. varname_spec = 'co'
  355. cf_spec_stnd = 'carbon_monoxide'
  356. cf_spec_long = 'CO'
  357. case ( 'O3', 'o3' )
  358. varname_spec = 'o3'
  359. cf_spec_stnd = 'ozone'
  360. cf_spec_long = 'O3'
  361. case ( 'O3s', 'o3s' )
  362. varname_spec = 'o3s'
  363. cf_spec_stnd = 'ozone_from_stratosphere'
  364. cf_spec_long = 'O3s'
  365. case ( 'NO', 'no' )
  366. varname_spec = 'no'
  367. cf_spec_stnd = 'nitrogen_monoxide'
  368. cf_spec_long = 'NO'
  369. case ( 'NO2', 'no2' )
  370. varname_spec = 'no2'
  371. cf_spec_stnd = 'nitrogen_dioxide'
  372. cf_spec_long = 'NO2'
  373. case ( 'NOy', 'noy' )
  374. varname_spec = 'noy'
  375. cf_spec_stnd = 'nitrogen_oxides'
  376. cf_spec_long = 'NOy'
  377. comment = 'NOy = NOx + HNO3 + PAN + org.ntr., '// &
  378. 'with NOx = NO + NO2 + NO3 + HNO4 + N2O5'
  379. case ( 'NOx', 'nox' )
  380. varname_spec = 'nox'
  381. cf_spec_stnd = 'nitrogen_oxides'
  382. cf_spec_long = 'NOx'
  383. comment = 'NOx = NO + NO2 + NO3 + HNO4 + N2O5'
  384. case ( 'CH2O', 'ch2o', 'CHOH', 'choh' )
  385. varname_spec = 'ch2o'
  386. cf_spec_stnd = 'formaldehyde'
  387. cf_spec_long = 'CH2O'
  388. case ( 'SO2', 'so2' )
  389. varname_spec = 'so2'
  390. cf_spec_stnd = 'sulfur_dioxide'
  391. cf_spec_long = 'SO2'
  392. case ( 'SO4', 'so4' )
  393. varname_spec = 'so4'
  394. cf_spec_stnd = 'sulfate_as_sulfate_dry_aerosol'
  395. cf_spec_long = 'SO4'
  396. case ( 'CH4', 'ch4' )
  397. varname_spec = 'ch4'
  398. cf_spec_stnd = 'methane'
  399. cf_spec_long = 'CH4'
  400. case ( 'OH', 'oh' )
  401. varname_spec = 'oh'
  402. cf_spec_stnd = 'hydroxyl_radical'
  403. cf_spec_long = 'OH'
  404. case ( 'H2O2', 'h2o2' )
  405. varname_spec = 'h2o2'
  406. cf_spec_stnd = 'hydrogen_peroxide'
  407. cf_spec_long = 'H2O2'
  408. case ( 'HNO3', 'hno3' )
  409. varname_spec = 'hno3'
  410. cf_spec_stnd = 'nitric_acid'
  411. cf_spec_long = 'HNO3'
  412. case ( 'PAN', 'pan' )
  413. varname_spec = 'pan'
  414. cf_spec_stnd = 'peroxyacetyl_nitrate'
  415. cf_spec_long = 'PAN'
  416. case ( 'Rn', 'rn', 'Radon', 'radon' )
  417. varname_spec = 'rn'
  418. cf_spec_stnd = 'radon'
  419. cf_spec_long = 'Rn'
  420. case ( 'Pb', 'pb', 'Lead', 'lead' )
  421. varname_spec = 'pb'
  422. cf_spec_stnd = 'lead'
  423. cf_spec_long = 'Pb'
  424. case ( 'NO3_A', 'no3_a' )
  425. varname_spec = 'no3'
  426. cf_spec_stnd = 'nitrate_as_nitrate_dry_aerosol'
  427. cf_spec_long = 'NO3'
  428. case ( 'BC', 'bc' )
  429. varname_spec = 'bc'
  430. cf_spec_stnd = 'black_carbon_dry_aerosol'
  431. cf_spec_long = 'BC'
  432. case ( 'BCS', 'bcs' )
  433. varname_spec = 'bcs'
  434. cf_spec_stnd = 'hydrophilic_black_carbon_dry_aerosol'
  435. cf_spec_long = 'BC(aq)'
  436. case ( 'POM', 'pom' )
  437. varname_spec = 'om'
  438. cf_spec_stnd = 'organic_carbon_as_particulate_organic_matter_dry_aerosol'
  439. cf_spec_long = 'OM'
  440. case ( 'SS1_N', 'ss1_n' )
  441. varname_spec = 'ss1_n'
  442. cf_spec_stnd = 'seasalt_dry_aerosol_mode1_number'
  443. cf_spec_long = 'SS1_n'
  444. case ( 'SS1_M', 'ss1_m' )
  445. varname_spec = 'ss1_m'
  446. cf_spec_stnd = 'seasalt_dry_aerosol_mode1_mass'
  447. cf_spec_long = 'SS1_m'
  448. case ( 'SS2_N', 'ss2_n' )
  449. varname_spec = 'ss2_n'
  450. cf_spec_stnd = 'seasalt_dry_aerosol_mode2_number'
  451. cf_spec_long = 'SS2_n'
  452. case ( 'SS2_M', 'ss2_m' )
  453. varname_spec = 'ss2_m'
  454. cf_spec_stnd = 'seasalt_dry_aerosol_mode2_mass'
  455. cf_spec_long = 'SS2_m'
  456. case ( 'SS3_N', 'ss3_n' )
  457. varname_spec = 'ss3_n'
  458. cf_spec_stnd = 'seasalt_dry_aerosol_mode3_number'
  459. cf_spec_long = 'SS3_n'
  460. case ( 'SS3_M', 'ss3_m' )
  461. varname_spec = 'ss3_m'
  462. cf_spec_stnd = 'seasalt_dry_aerosol_mode3_mass'
  463. cf_spec_long = 'SS3_m'
  464. case ( 'DUST2_N', 'dust2_n' )
  465. varname_spec = 'dust2_n'
  466. cf_spec_stnd = 'dust_dry_aerosol_mode2_number'
  467. cf_spec_long = 'DUST2_n'
  468. case ( 'DUST2_M', 'dust2_m' )
  469. varname_spec = 'dust2_m'
  470. cf_spec_stnd = 'dust_dry_aerosol_mode2_madust'
  471. cf_spec_long = 'DUST2_m'
  472. case ( 'DUST3_N', 'dust3_n' )
  473. varname_spec = 'dust3_n'
  474. cf_spec_stnd = 'dust_dry_aerosol_mode3_number'
  475. cf_spec_long = 'DUST3_n'
  476. case ( 'DUST3_M', 'dust3_m' )
  477. varname_spec = 'dust3_m'
  478. cf_spec_stnd = 'dust_dry_aerosol_mode3_madust'
  479. cf_spec_long = 'DUST3_m'
  480. case default
  481. varname_spec = trim(names(ivar))
  482. cf_spec_stnd = trim(names(ivar))
  483. cf_spec_long = trim(names(ivar))
  484. write (gol,'("Use dummy naming for tracer: ",a)') names(ivar); call goPr
  485. write (gol,'("Use standard name")'); call goPr
  486. ! TRACEBACK; status=1; return
  487. end select
  488. write (varname,'(a,"_",a)') trim(varname_conc), trim(varname_spec)
  489. ! construct total names:
  490. CF_vmr_var(ivar)%var_name = trim(names(ivar)) ! e.g. O3, NO2
  491. CF_vmr_var(ivar)%param_name_default = trim(names(ivar)) ! the name of the output-variable. Currently the same, but may be different, e.g. vmr_o3, vmr_no2
  492. CF_vmr_var(ivar)%stand_name_default = trim(cf_enti_stnd)//'_of_'//trim(cf_spec_stnd)//'_'//trim(cf_medium_stnd)
  493. CF_vmr_var(ivar)%long_name_default = trim(cf_enti_long)//' of '//trim(cf_spec_long)//' '//trim(cf_medium_long)
  494. CF_vmr_var(ivar)%units_default = trim(cf_enti_unit)
  495. !overwrite these names of keys from rc-file, if necessary
  496. call ReadRc( rcF, 'output.cf.vmr.'//trim( CF_vmr_var(ivar)%var_name)//'.param.name', CF_vmr_var(ivar)%param_name, status,default=trim(CF_vmr_var(ivar)%param_name_default) )
  497. IF_ERROR_RETURN(status=1)
  498. call ReadRc( rcF, 'output.cf.vmr.'//trim( CF_vmr_var(ivar)%var_name)//'.stand.name', CF_vmr_var(ivar)%stand_name, status,default=trim(CF_vmr_var(ivar)%stand_name_default) )
  499. IF_ERROR_RETURN(status=1)
  500. call ReadRc( rcF, 'output.cf.vmr.'//trim( CF_vmr_var(ivar)%var_name)//'.long.name', CF_vmr_var(ivar)%long_name , status,default=trim(CF_vmr_var(ivar)%long_name_default) )
  501. IF_ERROR_RETURN(status=1)
  502. call ReadRc( rcF, 'output.cf.vmr.'//trim( CF_vmr_var(ivar)%var_name)//'.units' , CF_vmr_var(ivar)%units , status,default=trim(CF_vmr_var(ivar)%units_default) )
  503. IF_ERROR_RETURN(status=1)
  504. enddo
  505. !
  506. !Define naming of selected meteo-variables:
  507. !
  508. ivar = 1 ! surface pressure
  509. CF_TP_var(ivar)%var_name = 'ps'
  510. CF_TP_var(ivar)%param_name_default = 'ps'
  511. CF_TP_var(ivar)%stand_name_default = 'surface_air_pressure'
  512. CF_TP_var(ivar)%long_name_default = 'surface pressure'
  513. CF_TP_var(ivar)%units_default = 'Pa'
  514. !overwrite these names of keys from rc-file, if necessary
  515. call ReadRc( rcF, 'output.cf.TP.'//trim( CF_TP_var(ivar)%var_name)//'.param.name', CF_TP_var(ivar)%param_name, status,default=trim(CF_TP_var(ivar)%param_name_default) )
  516. IF_ERROR_RETURN(status=1)
  517. call ReadRc( rcF, 'output.cf.TP.'//trim( CF_TP_var(ivar)%var_name)//'.stand.name', CF_TP_var(ivar)%stand_name, status,default=trim(CF_TP_var(ivar)%stand_name_default) )
  518. IF_ERROR_RETURN(status=1)
  519. call ReadRc( rcF, 'output.cf.TP.'//trim( CF_TP_var(ivar)%var_name)//'.long.name', CF_TP_var(ivar)%long_name , status,default=trim(CF_TP_var(ivar)%long_name_default) )
  520. IF_ERROR_RETURN(status=1)
  521. call ReadRc( rcF, 'output.cf.TP.'//trim( CF_TP_var(ivar)%var_name)//'.units' , CF_TP_var(ivar)%units , status,default=trim(CF_TP_var(ivar)%units_default) )
  522. IF_ERROR_RETURN(status=1)
  523. end subroutine Output_CF_naming
  524. ! ***
  525. subroutine Output_CF_Init( rcF, dhour_min, status )
  526. use GO , only : TrcFile, ReadRc
  527. use meteo, only : lli
  528. use partools , only : Par_Barrier
  529. ! --- in/out ---------------------------------
  530. type(TrcFile), intent(inout) :: rcF
  531. integer, intent(out) :: dhour_min
  532. integer, intent(out) :: status
  533. ! --- const ------------------------------
  534. character(len=*), parameter :: rname = mname//'/Output_CF_Init'
  535. ! --- local ------------------------------
  536. integer :: region
  537. integer :: itf
  538. character(len=64) :: key
  539. character(len=3) :: nr
  540. integer :: ivmr,ivar,vmr_nvars_max
  541. character(len=256) :: test_param_name
  542. ! --- begin -------------------------------
  543. call goLabel(rname)
  544. ! Read in the dataset keys:
  545. call ReadRc( rcF, 'output.cf.dataset.author' , dataset_author , status )
  546. IF_NOTOK_RETURN(status=1)
  547. call ReadRc( rcF, 'output.cf.dataset.institution', dataset_institution, status )
  548. IF_NOTOK_RETURN(status=1)
  549. call ReadRc( rcF, 'output.cf.dataset.version' , dataset_version , status )
  550. IF_NOTOK_RETURN(status=1)
  551. ! Read in the filename keys:
  552. call ReadRc( rcF, 'output.cf.fname.model', fname_model, status )
  553. IF_NOTOK_RETURN(status=1)
  554. call ReadRc( rcF, 'output.cf.fname.expid', fname_expid, status )
  555. IF_NOTOK_RETURN(status=1)
  556. ! Read in the prefix grid name in case of zooming regions:
  557. if ( nregions > 1 ) then
  558. ! loop over regions:
  559. do region = 1, nregions
  560. ! short grid name from rcfile:
  561. call ReadRc( rcF, 'output.cf.fname.grid.'//trim(lli(region)%name), key, status )
  562. IF_NOTOK_RETURN(status=1)
  563. ! fill grid extenstion to file names:
  564. fname_grid(region) = '-'//trim(key)
  565. end do
  566. else
  567. ! empty
  568. fname_grid = ''
  569. end if
  570. !
  571. ! Initialize CF-compliant naming conventions: Read in the naming from an rc-file
  572. !
  573. call Output_CF_naming(rcF,status)
  574. IF_ERROR_RETURN(status=1)
  575. !
  576. !
  577. !
  578. ! Write-out a griddef file ?
  579. call ReadRc( rcF, 'output.cf.griddef.apply', griddef_apply, status )
  580. IF_NOTOK_RETURN(status=1)
  581. ! Write out a temperature, pressure, etc file ? (not yet implemented!)
  582. call ReadRc( rcF, 'output.cf.tp.apply', tp_apply, status )
  583. IF_NOTOK_RETURN(status=1)
  584. ! VMR files:
  585. ! read number of vmr files to be written:
  586. call ReadRc( rcF, 'output.cf.vmr.n', nvmr, status )
  587. IF_NOTOK_RETURN(status=1)
  588. if ( nvmr < 0 ) then
  589. write (gol,'("strange specification of number of vmr files : ",i6)') nvmr; call goErr
  590. TRACEBACK; status=1; return
  591. end if
  592. ! write any vmr files (data-files containing instantaneous info on species vol.mix.ratios)
  593. if ( nvmr > 0 ) then
  594. ! storage:
  595. allocate( vmr_apply(nvmr) )
  596. allocate( vmr_apply_average(nvmr) )
  597. allocate( vmr_fname(nvmr) )
  598. allocate( vmr_nvars(nvmr) )
  599. allocate( vmr_dhour(nvmr) )
  600. allocate( vmr_tracer_names(nvmr) )
  601. allocate( CFVMR(nregions,nvmr) )
  602. ! loop over vmr files:
  603. do ivmr = 1, nvmr
  604. ! number in rc keys:
  605. write (nr,'(i3.3)') ivmr
  606. ! apply ?
  607. call ReadRc( rcF, 'output.cf.vmr.'//nr//'.apply', vmr_apply(ivmr), status )
  608. IF_NOTOK_RETURN(status=1)
  609. ! proceed ?
  610. if ( vmr_apply(ivmr) ) then
  611. ! first part of filename:
  612. call ReadRc( rcF, 'output.cf.vmr.'//nr//'.fname', vmr_fname(ivmr), status )
  613. IF_NOTOK_RETURN(status=1)
  614. ! How many parameters are defined that need to be written out?
  615. call ReadRc( rcF, 'output.cf.vmr.'//nr//'.nvars', vmr_nvars(ivmr), status )
  616. IF_NOTOK_RETURN(status=1)
  617. ! time resolution:
  618. call ReadRc( rcF, 'output.cf.vmr.'//nr//'.dhour', vmr_dhour(ivmr), status )
  619. IF_NOTOK_RETURN(status=1)
  620. ! the names of tracers to be written:
  621. call ReadRc( rcF, 'output.cf.vmr.'//nr//'.tracers', vmr_tracer_names(ivmr), status )
  622. IF_NOTOK_RETURN(status=1)
  623. end if ! apply ?
  624. end do ! vmr numbers
  625. ! Find maximum number of variables to be saved:
  626. vmr_nvars_max = 0
  627. do ivmr=1,nvmr
  628. vmr_nvars_max=max(vmr_nvars_max,vmr_nvars(ivmr))
  629. enddo
  630. ! allocate sds_vmr_inst to be used later.
  631. ! for sufficient number of variables, make at least 7 more spaces available for
  632. ! grid definition.
  633. allocate(sds_vmr_inst(nregions,nvmr,vmr_nvars_max+7))
  634. allocate(CFVMR_hdf_inst(nregions,nvmr))
  635. allocate(CFVMR_hdf_average(nregions,nvmr))
  636. allocate(sds_vmr_average(nregions,nvmr,vmr_nvars_max+7))
  637. do ivmr = 1, nvmr
  638. ! number in rc keys:
  639. write (nr,'(i3.3)') ivmr
  640. ! apply ?
  641. call ReadRc( rcF, 'output.cf.vmr.average.'//nr//'.apply', vmr_apply_average(ivmr), status )
  642. IF_NOTOK_RETURN(status=1)
  643. ! proceed ? for now use the data read in for instantaneous output...
  644. ! This has not been coded yet... see vmr
  645. if ( vmr_apply_average(ivmr) ) then
  646. ! first part of filename:
  647. ! call ReadRc( rcF, 'output.cf.vmr.average.'//nr//'.fname', vmr_fname_average(ivmr), status )
  648. ! IF_NOTOK_RETURN(status=1)
  649. ! time resolution:
  650. ! call ReadRc( rcF, 'output.cf.vmr.average.'//nr//'.dhour', vmr_dhour_average(ivmr), status )
  651. ! IF_NOTOK_RETURN(status=1)
  652. ! tracers to be written:
  653. ! call ReadRc( rcF, 'output.cf.vmr.average.'//nr//'.tracers', vmr_tracer_names_average(ivmr), status )
  654. ! IF_NOTOK_RETURN(status=1)
  655. end if ! apply ?
  656. end do ! vmr average numbers
  657. end if ! nvmr > 0
  658. ! deposition fluxes: (not yet applicable... Please see 'vmr'-type of output)
  659. deps_fname = 'depositions'
  660. call ReadRc( rcF, 'output.cf.depositions.apply', deps_apply, status )
  661. IF_NOTOK_RETURN(status=1)
  662. if ( deps_apply ) then
  663. call ReadRc( rcF, 'output.cf.depositions.dhour', deps_dhour, status )
  664. IF_NOTOK_RETURN(status=1)
  665. call ReadRc( rcF, 'output.cf.depositions.tracers', deps_tracer_names, status )
  666. IF_NOTOK_RETURN(status=1)
  667. end if
  668. ! deposition velocities: (not yet applicable... Please see 'vmr'-type of output)
  669. depv_fname = 'depvels'
  670. call ReadRc( rcF, 'output.cf.depvels.apply', depv_apply, status )
  671. IF_NOTOK_RETURN(status=1)
  672. if ( depv_apply ) then
  673. call ReadRc( rcF, 'output.cf.depvels.dhour', depv_dhour, status )
  674. IF_NOTOK_RETURN(status=1)
  675. call ReadRc( rcF, 'output.cf.depvels.tracers', depv_tracer_names, status )
  676. IF_NOTOK_RETURN(status=1)
  677. end if
  678. ! no files open yet
  679. curr_day = -1
  680. ! lowest time frequency is 1 hour
  681. dhour_min = 1
  682. call goLabel()
  683. ! ok
  684. status = 0
  685. end subroutine Output_CF_Init
  686. subroutine Output_CF_Step( region, idate_f, status )
  687. ! --- in/out ---------------------------------
  688. integer, intent(in) :: region
  689. integer, intent(in) :: idate_f(6)
  690. integer, intent(out) :: status
  691. ! --- const ------------------------------
  692. character(len=*), parameter :: rname = mname//'/Output_CF_Step'
  693. ! --- begin -------------------------------
  694. call goLabel(rname)
  695. !
  696. ! close files if necessary
  697. !
  698. if ( all(curr_day(region,:) > 0) .and. any(idate_f(1:3) /= curr_day(region,:)) ) then
  699. ! write for 24:00
  700. call CF_Files_Write2( region, idate_f, status )
  701. IF_NOTOK_RETURN(status=1)
  702. ! close all:
  703. call CF_Files_Close( region, status )
  704. IF_NOTOK_RETURN(status=1)
  705. ! no files open ...
  706. curr_day(region,:) = -1
  707. end if
  708. !
  709. ! open files if necessary
  710. !
  711. if ( any(curr_day(region,:) < 0) ) then
  712. ! open files:
  713. call CF_Files_Open( region, idate_f, status )
  714. IF_NOTOK_RETURN(status=1)
  715. ! store date:
  716. curr_day(region,:) = idate_f(1:3)
  717. end if
  718. !
  719. ! write files
  720. !
  721. call CF_Files_Write( region, idate_f, status )
  722. IF_NOTOK_RETURN(status=1)
  723. ! special files-write:
  724. ! if ( any(idate_f(4:6) > 0) ) then
  725. ! call CF_Files_Write2( region, idate_f, status )
  726. ! IF_NOTOK_RETURN(status=1)
  727. ! end if
  728. !
  729. ! done
  730. !
  731. call goLabel()
  732. ! ok
  733. status = 0
  734. end subroutine Output_CF_Step
  735. ! ***
  736. subroutine Output_CF_Done( status )
  737. ! --- in/out ---------------------------------
  738. integer, intent(out) :: status
  739. ! --- const ------------------------------
  740. character(len=*), parameter :: rname = mname//'/Output_CF_Done'
  741. ! --- local -------------------------------
  742. integer :: region
  743. ! --- begin -------------------------------
  744. ! close files:
  745. do region = 1, nregions
  746. call CF_Files_Close( region, status )
  747. IF_NOTOK_RETURN(status=1)
  748. end do
  749. ! clear:
  750. if ( nvmr > 0 ) then
  751. deallocate( vmr_apply )
  752. deallocate( vmr_apply_average)
  753. deallocate( vmr_fname )
  754. deallocate( vmr_nvars )
  755. deallocate( vmr_dhour )
  756. deallocate( vmr_tracer_names )
  757. deallocate( CFVMR )
  758. deallocate( CFVMR_hdf_inst)
  759. deallocate( CFVMR_hdf_average )
  760. deallocate(sds_vmr_inst)
  761. deallocate(sds_vmr_average)
  762. end if
  763. ! ok
  764. status = 0
  765. end subroutine Output_CF_Done
  766. ! ********************************************************************
  767. ! ***
  768. ! *** open/write/close retro files
  769. ! ***
  770. ! ********************************************************************
  771. subroutine CF_Files_Open( region, idate_f, status )
  772. use global_data, only : outdir
  773. ! --- in/out ---------------------------------
  774. integer, intent(in) :: region
  775. integer, intent(in) :: idate_f(6)
  776. integer, intent(out) :: status
  777. ! --- const ------------------------------
  778. character(len=*), parameter :: rname = mname//'/CF_Files_Open'
  779. ! --- local -------------------------------
  780. integer :: ivmr
  781. ! --- begin -------------------------------
  782. ! grid definition:
  783. if ( griddef_apply ) then
  784. call CFGridDef_Init( CFGridDef(region), GridDef_hdf(region), outdir, fname_model, fname_expid, region, status )
  785. IF_NOTOK_RETURN(status=1)
  786. end if
  787. ! dynamics:
  788. ! if ( tp_apply ) then
  789. ! call CFTP_Init ( CFTP(region) , outdir, fname_model, fname_expid, region, idate_f, status )
  790. ! IF_NOTOK_RETURN(status=1)
  791. ! end if
  792. ! tracer concentrations: inst/ mean
  793. do ivmr = 1, nvmr
  794. if ( vmr_apply(ivmr) ) then
  795. call CFVMR_Init(CFVMR_hdf_inst(region,ivmr), CFVMR(region,ivmr), outdir, fname_model, fname_expid, &
  796. vmr_fname(ivmr), region, idate_f, &
  797. vmr_dhour(ivmr), vmr_tracer_names(ivmr), &
  798. ivmr, status )
  799. IF_NOTOK_RETURN(status=1)
  800. endif
  801. end do
  802. ! deposition fluxes:
  803. ! if ( deps_apply ) then
  804. ! call CFDEPS_Init( CFDEPS(region), outdir, fname_model, fname_expid, &
  805. ! deps_fname, region, idate_f, &
  806. ! deps_dhour, deps_tracer_names, status )
  807. ! IF_NOTOK_RETURN(status=1)
  808. ! end if
  809. ! ! deposition velocities:
  810. ! if ( depv_apply ) then
  811. ! call CFDEPV_Init( CFDEPV(region), outdir, fname_model, fname_expid, &
  812. ! depv_fname, region, idate_f, &
  813. ! depv_dhour, depv_tracer_names, status )
  814. ! IF_NOTOK_RETURN(status=1)
  815. ! end if
  816. ! ok
  817. status = 0
  818. end subroutine CF_Files_Open
  819. ! ***
  820. subroutine CF_Files_Write( region, idate_f, status )
  821. ! --- in/out ---------------------------------
  822. integer, intent(in) :: region
  823. integer, intent(in) :: idate_f(6)
  824. integer, intent(out) :: status
  825. ! --- const ------------------------------
  826. character(len=*), parameter :: rname = mname//'/CF_Files_Write'
  827. ! --- local -------------------------------
  828. integer :: ivmr
  829. ! --- begin -------------------------------
  830. ! grid definition:
  831. if ( griddef_apply ) then
  832. call CFGridDef_Write( CFGridDef(region), GridDef_hdf(region), region, status )
  833. IF_NOTOK_RETURN(status=1)
  834. end if
  835. ! dynamics:
  836. ! if ( tp_apply ) then
  837. ! call CFTP_Write( CFTP(region), region, idate_f, status )
  838. ! IF_NOTOK_RETURN(status=1)
  839. ! end if
  840. ! instantaneous tracer fields:
  841. do ivmr = 1, nvmr
  842. if ( .not. vmr_apply(ivmr) ) cycle
  843. call CFVMR_Write( CFVMR(region,ivmr), region, ivmr,idate_f, status )
  844. IF_NOTOK_RETURN(status=1)
  845. end do
  846. ! average tracer fields:
  847. ! do ivmr = 1, nvmr
  848. ! if ( .not. vmr_apply_average(ivmr) ) cycle
  849. ! call CFVMR_average( CFVMR(region,ivmr), region, idate_f, status )
  850. ! IF_NOTOK_RETURN(status=1)
  851. ! end do
  852. ! deposition velocities:
  853. ! if ( depv_apply ) then
  854. ! call CFDEPV_Write( CFDEPV(region), region, idate_f, status )
  855. ! IF_NOTOK_RETURN(status=1)
  856. ! end if
  857. ! ok
  858. status = 0
  859. end subroutine CF_Files_Write
  860. ! ***
  861. ! write at end of time interval
  862. subroutine CF_Files_Write2( region, idate_f, status )
  863. ! --- in/out ---------------------------------
  864. integer, intent(in) :: region
  865. integer, intent(in) :: idate_f(6)
  866. integer, intent(out) :: status
  867. ! --- const ------------------------------
  868. character(len=*), parameter :: rname = mname//'/CF_Files_Write2'
  869. ! --- begin -------------------------------
  870. ! deposition fluxes:
  871. ! if ( deps_apply ) then
  872. ! call CFDEPS_Write( CFDEPS(region), region, idate_f, status )
  873. ! IF_NOTOK_RETURN(status=1)
  874. ! end if
  875. ! ok
  876. status = 0
  877. end subroutine CF_Files_Write2
  878. ! ***
  879. subroutine CF_Files_Close( region, status )
  880. ! --- in/out ---------------------------------
  881. integer, intent(in) :: region
  882. integer, intent(out) :: status
  883. ! --- const ------------------------------
  884. character(len=*), parameter :: rname = mname//'/CF_Files_Close'
  885. ! --- local -------------------------------
  886. integer :: ivmr
  887. ! --- begin -------------------------------
  888. if ( griddef_apply ) then
  889. call CFGridDef_Done( CFGridDef(region),GridDef_hdf(region), status )
  890. IF_NOTOK_RETURN(status=1)
  891. end if
  892. ! if ( tp_apply ) then
  893. ! call CFTP_Done ( CFTP(region) , status )
  894. ! IF_NOTOK_RETURN(status=1)
  895. ! end if
  896. do ivmr = 1, nvmr
  897. if ( .not. vmr_apply(ivmr) ) cycle
  898. call CFVMR_Done( CFVMR(region,ivmr),CFVMR_hdf_inst(region,ivmr),region,ivmr, status )
  899. IF_NOTOK_RETURN(status=1)
  900. end do
  901. ! if ( deps_apply ) then
  902. ! call CFDEPS_Done( CFDEPS(region), status )
  903. ! IF_NOTOK_RETURN(status=1)
  904. ! end if
  905. ! if ( depv_apply ) then
  906. ! call CFDEPV_Done( CFDEPV(region), status )
  907. ! IF_NOTOK_RETURN(status=1)
  908. ! end if
  909. ! ok
  910. status = 0
  911. end subroutine CF_Files_Close
  912. ! ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  913. ! FILE 1: Model horizontal grid definition
  914. ! (longitude, latitude, size of gridbox [m2] ).
  915. ! native vertical grid definition (hybrid level coefficients) and the
  916. ! formula used to calculate pressure.
  917. ! ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  918. subroutine CFGridDef_Init( CF, CF_hdf, fdir, model, expid, region, status )
  919. use partools, only : myid, root, MPI_INFO_NULL
  920. use partools, only : localComm
  921. use Meteo , only : lli, levi
  922. use file_hdf, only : THdfFile, Init, setdim,WriteAttribute, WriteData, TSds, Done
  923. ! --- in/out -------------------------------------
  924. type(TCF_File_GridDef), intent(out) :: CF
  925. type(THdfFile),intent(out) :: CF_hdf
  926. character(len=*), intent(in) :: fdir
  927. character(len=*), intent(in) :: model
  928. character(len=*), intent(in) :: expid
  929. integer, intent(in) :: region
  930. integer, intent(out) :: status
  931. ! --- const --------------------------------------
  932. character(len=*), parameter :: rname = mname//'/CFGridDef_Init'
  933. ! --- local ------------------------------------
  934. ! type(THdfFile) :: CF_hdf
  935. character(len=256) :: fname
  936. integer :: j,varid,ivar
  937. character(len=256) :: xname
  938. ! --- begin -------------------------------------
  939. if (myid /= root) return
  940. call goLabel(rname)
  941. ! o open file
  942. ! write filename
  943. write (fname,'(a,"/",a,a,"_",a,"_",a,".hdf")') &
  944. trim(fdir), trim(model), trim(fname_grid(region)), trim(expid), 'griddef'
  945. call Init(CF_hdf,fname,'create', status)
  946. IF_NOTOK_RETURN(status=1)
  947. ! o global attributes
  948. call WriteAttribute(CF_hdf,'title','GridDef',status)
  949. IF_NOTOK_RETURN(status=1)
  950. call WriteAttribute(CF_hdf,'dataset_author', trim(dataset_author),status)
  951. IF_NOTOK_RETURN(status=1)
  952. call WriteAttribute(CF_hdf,'dataset_institution', trim(dataset_institution),status)
  953. IF_NOTOK_RETURN(status=1)
  954. call WriteAttribute(CF_hdf,'dataset_version', trim(dataset_version),status)
  955. IF_NOTOK_RETURN(status=1)
  956. ! o define dimensions
  957. CF%dimid_lon = lli(region)%nlon
  958. CF%dimid_lat = lli(region)%nlat
  959. CF%dimid_lev = levi%nlev
  960. CF%dimid_levi= levi%nlev+1
  961. ! o define variables
  962. ivar=1 ! longitude
  963. call init(sds_grid(ivar), CF_hdf, trim(CF_grid_var(ivar)%param_name), (/ CF%dimid_lon /), 'real(8)',status)
  964. IF_NOTOK_RETURN(status=1)
  965. call SetDim( sds_grid(ivar), 0, trim(CF_grid_var(ivar)%param_name), trim(CF_grid_var(ivar)%units),(/(lli(region)%lon_deg)/) ,status)
  966. IF_NOTOK_RETURN(status=1)
  967. call WriteAttribute(sds_grid(ivar), 'standard_name' , trim(CF_grid_var(ivar)%stand_name),status)
  968. IF_NOTOK_RETURN(status=1)
  969. call WriteAttribute(sds_grid(ivar), 'long_name' ,trim(CF_grid_var(ivar)%long_name),status )
  970. IF_NOTOK_RETURN(status=1)
  971. call WriteAttribute(sds_grid(ivar), 'units' , trim(CF_grid_var(ivar)%units),status )
  972. IF_NOTOK_RETURN(status=1)
  973. ivar = 2 ! latitude
  974. call init(sds_grid(ivar), CF_hdf, trim(CF_grid_var(ivar)%param_name), (/ CF%dimid_lat /), 'real(8)',status)
  975. IF_NOTOK_RETURN(status=1)
  976. call SetDim( sds_grid(ivar), 0, trim(CF_grid_var(ivar)%param_name), trim(CF_grid_var(ivar)%units),(/(lli(region)%lat_deg)/) ,status)
  977. IF_NOTOK_RETURN(status=1)
  978. call WriteAttribute(sds_grid(ivar), 'standard_name' , trim(CF_grid_var(ivar)%stand_name),status)
  979. IF_NOTOK_RETURN(status=1)
  980. call WriteAttribute(sds_grid(ivar), 'long_name' ,trim(CF_grid_var(ivar)%long_name),status )
  981. IF_NOTOK_RETURN(status=1)
  982. call WriteAttribute(sds_grid(ivar), 'units' , trim(CF_grid_var(ivar)%units),status )
  983. ivar = 6 ! gridbox area
  984. call init(sds_grid(ivar), CF_hdf, trim(CF_grid_var(ivar)%param_name), (/ CF%dimid_lon ,CF%dimid_lat /), 'real(8)',status)
  985. IF_NOTOK_RETURN(status=1)
  986. call SetDim( sds_grid(ivar), 0, trim(CF_grid_var(1)%param_name), trim(CF_grid_var(1)%units),(/(lli(region)%lon_deg)/) ,status)
  987. IF_NOTOK_RETURN(status=1)
  988. call SetDim( sds_grid(ivar), 1, trim(CF_grid_var(2)%param_name), trim(CF_grid_var(2)%units),(/(lli(region)%lat_deg)/) ,status)
  989. IF_NOTOK_RETURN(status=1)
  990. call WriteAttribute(sds_grid(ivar), 'standard_name' , trim(CF_grid_var(ivar)%stand_name),status)
  991. IF_NOTOK_RETURN(status=1)
  992. call WriteAttribute(sds_grid(ivar), 'long_name' ,trim(CF_grid_var(ivar)%long_name),status )
  993. IF_NOTOK_RETURN(status=1)
  994. call WriteAttribute(sds_grid(ivar), 'units' , trim(CF_grid_var(ivar)%units),status )
  995. do ivar = 7,8 ! a,b mid-level
  996. call init(sds_grid(ivar), CF_hdf, trim(CF_grid_var(ivar)%param_name), (/ CF%dimid_lev /), 'real(8)',status)
  997. IF_NOTOK_RETURN(status=1)
  998. call SetDim( sds_grid(ivar), 0, trim(CF_grid_var(3)%param_name), trim(CF_grid_var(3)%units),(/(j,j=1,levi%nlev)/) ,status)
  999. IF_NOTOK_RETURN(status=1)
  1000. call WriteAttribute(sds_grid(ivar), 'standard_name' , trim(CF_grid_var(ivar)%stand_name),status)
  1001. IF_NOTOK_RETURN(status=1)
  1002. call WriteAttribute(sds_grid(ivar), 'long_name' ,trim(CF_grid_var(ivar)%long_name),status )
  1003. IF_NOTOK_RETURN(status=1)
  1004. call WriteAttribute(sds_grid(ivar), 'units' , trim(CF_grid_var(ivar)%units),status )
  1005. enddo
  1006. do ivar = 9,10 ! a,b boundary values (at cell interfaces)
  1007. call init(sds_grid(ivar), CF_hdf, trim(CF_grid_var(ivar)%param_name), (/ CF%dimid_levi /), 'real(8)',status)
  1008. IF_NOTOK_RETURN(status=1)
  1009. call SetDim( sds_grid(ivar), 0, 'levi', trim(CF_grid_var(3)%units),(/(j,j=1,levi%nlev+1)/) ,status)
  1010. IF_NOTOK_RETURN(status=1)
  1011. call WriteAttribute(sds_grid(ivar), 'standard_name' , trim(CF_grid_var(ivar)%stand_name),status)
  1012. IF_NOTOK_RETURN(status=1)
  1013. call WriteAttribute(sds_grid(ivar), 'long_name' ,trim(CF_grid_var(ivar)%long_name),status )
  1014. IF_NOTOK_RETURN(status=1)
  1015. call WriteAttribute(sds_grid(ivar), 'units' , trim(CF_grid_var(ivar)%units),status )
  1016. enddo
  1017. ! o end defintion mode
  1018. ! o
  1019. ! no records written yet
  1020. CF%trec = 0
  1021. call goLabel()
  1022. ! ok
  1023. status = 0
  1024. end subroutine CFGridDef_Init
  1025. ! ***
  1026. subroutine CFGridDef_Write( CF, CF_hdf, region, status )
  1027. use GO , only : TDate, NewDate, rTotal, operator(-)
  1028. use Grid , only : AreaOper
  1029. use partools, only : myid, root
  1030. use Meteo , only : lli, levi
  1031. use Meteo , only : sp_dat
  1032. use file_hdf, only : THdfFile, WriteData
  1033. ! --- in/out -------------------------------------
  1034. type(TCF_File_GridDef), intent(inout) :: CF
  1035. type(THdfFile), intent(inout) :: CF_hdf
  1036. integer, intent(in) :: region
  1037. integer, intent(out) :: status
  1038. ! --- const --------------------------------------
  1039. character(len=*), parameter :: rname = mname//'/CFGridDef_Write'
  1040. ! --- local ------------------------------------
  1041. integer :: imr, jmr, lmr,ivar
  1042. real, allocatable :: ll(:,:)
  1043. !type(TDate) :: t, t0
  1044. real :: time
  1045. ! --- begin -------------------------------------
  1046. call goLabel(rname)
  1047. ! grid size
  1048. imr = lli(region)%nlon
  1049. jmr = lli(region)%nlat
  1050. lmr = levi%nlev
  1051. ! next time record:
  1052. CF%trec = CF%trec + 1
  1053. !! time since 2000-1-1 00:00
  1054. !t0 = NewDate( time6=time_reftime6 )
  1055. !t = NewDate( time6=idate_f )
  1056. !time = rTotal( t - t0, 'day' )
  1057. ! root only:
  1058. if ( myid == root ) then
  1059. ! lat/lon field:
  1060. allocate( ll(imr,jmr) )
  1061. ! o write data
  1062. if ( CF%trec == 1 ) then
  1063. ivar=1
  1064. call writedata(sds_grid(ivar),lli(region)%lon_deg,status)
  1065. IF_NOTOK_RETURN(status=1)
  1066. ivar=2
  1067. call writedata(sds_grid(ivar),lli(region)%lat_deg,status)
  1068. IF_NOTOK_RETURN(status=1)
  1069. ll = 1.0
  1070. call AreaOper( lli(region), ll, '*', 'm2', status )
  1071. IF_NOTOK_RETURN(status=1)
  1072. ivar=6
  1073. call writedata(sds_grid(ivar),ll,status)
  1074. IF_NOTOK_RETURN(status=1)
  1075. ivar=7
  1076. call writedata(sds_grid(ivar), levi%fa ,status)
  1077. IF_NOTOK_RETURN(status=1)
  1078. ivar=8
  1079. call writedata(sds_grid(ivar),levi%fb ,status)
  1080. IF_NOTOK_RETURN(status=1)
  1081. ivar=9
  1082. call writedata(sds_grid(ivar),levi%a(0:levi%nlev),status)
  1083. IF_NOTOK_RETURN(status=1)
  1084. ivar=10
  1085. call writedata(sds_grid(ivar),levi%b(0:levi%nlev),status)
  1086. IF_NOTOK_RETURN(status=1)
  1087. end if
  1088. ! clear
  1089. deallocate( ll )
  1090. end if ! root
  1091. ! end independend data mode:
  1092. !status = pnf90_end_indep_data( CF%ncid )
  1093. !IF_PNF90_NOTOK_RETURN(status=1)
  1094. call goLabel()
  1095. ! ok
  1096. status = 0
  1097. end subroutine CFGridDef_Write
  1098. ! ***
  1099. subroutine CFGridDef_Done( CF, CF_hdf, status )
  1100. use partools, only : myid, root
  1101. use Meteo , only : lli, levi
  1102. use file_hdf, only : THdfFile,Done
  1103. ! --- in/out -------------------------------------
  1104. type(TCF_File_GridDef), intent(inout) :: CF
  1105. type(THdfFile), intent(inout) :: CF_hdf
  1106. integer, intent(out) :: status
  1107. ! --- const --------------------------------------
  1108. character(len=*), parameter :: rname = mname//'/CFGridDef_Done'
  1109. ! --- local ------------------------------------
  1110. integer :: ivar
  1111. ! --- begin -------------------------------------
  1112. call goLabel(rname)
  1113. if (myid == root) then
  1114. ! close file
  1115. call Done(sds_grid(1),status)
  1116. call Done(sds_grid(2),status)
  1117. call Done(sds_grid(6),status)
  1118. call Done(sds_grid(7),status)
  1119. call Done(sds_grid(8),status)
  1120. call Done(sds_grid(9),status)
  1121. call Done(sds_grid(10),status)
  1122. call Done(CF_hdf, status)
  1123. IF_NOTOK_RETURN(status=1)
  1124. end if ! myid == root
  1125. call goLabel()
  1126. ! ok
  1127. status = 0
  1128. end subroutine CFGridDef_Done
  1129. ! ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  1130. ! FILE2: 3D field of monthly Model pressure [Pa] and temperature [K].
  1131. ! ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  1132. subroutine CFTP_Init( CF, fdir, model, expid, region, idate_f, status )
  1133. use partools, only : myid, root, MPI_INFO_NULL
  1134. use partools, only : localComm
  1135. use Meteo , only : lli, levi
  1136. use Meteo , only : Set
  1137. use Meteo , only : sp_dat, oro_dat, temper_dat, humid_dat, pu_dat, pv_dat, mfw_dat, gph_dat, t2m_dat
  1138. ! --- in/out -------------------------------------
  1139. type(TCF_File_TP), intent(out) :: CF
  1140. character(len=*), intent(in) :: fdir
  1141. character(len=*), intent(in) :: model
  1142. character(len=*), intent(in) :: expid
  1143. integer, intent(in) :: region
  1144. integer, intent(in) :: idate_f(6)
  1145. integer, intent(out) :: status
  1146. ! --- const --------------------------------------
  1147. character(len=*), parameter :: rname = mname//'/CFTP_Init'
  1148. ! --- local ------------------------------------
  1149. character(len=256) :: fname
  1150. integer :: varid
  1151. ! --- begin -------------------------------------
  1152. call goLabel(rname)
  1153. ! ensure that required meteo is loaded:
  1154. call Set( sp_dat(region), status, used=.true. )
  1155. call Set( oro_dat(region), status, used=.true. )
  1156. call Set( temper_dat(region), status, used=.true. )
  1157. call Set( t2m_dat(region), status, used=.true. )
  1158. call Set( humid_dat(region), status, used=.true. )
  1159. call Set( pu_dat(region), status, used=.true. )
  1160. call Set( pv_dat(region), status, used=.true. )
  1161. call Set( mfw_dat(region), status, used=.true. )
  1162. call Set( gph_dat(region), status, used=.true. ) ! used to compute vertical wind
  1163. ! o open file
  1164. ! write filename
  1165. ! write (fname,'(a,"/",a,a,"_",a,"_",a,"_",i4.4,"_",i2.2,"_",i2.2,".hdf")') &
  1166. ! trim(fdir), trim(model), trim(fname_grid(region)), trim(expid), 'TP', idate_f(1:3)
  1167. ! open:
  1168. ! status = pnf90_create( localComm, fname, PNF90_CLOBBER, MPI_INFO_NULL, CF%ncid )
  1169. ! IF_PNF90_NOTOK_RETURN(status=1)
  1170. ! o global attributes
  1171. ! o define dimensions
  1172. ! o define variables
  1173. ! o end defintion mode
  1174. ! o
  1175. ! no records written yet
  1176. CF%trec = 0
  1177. call goLabel()
  1178. ! ok
  1179. status = 0
  1180. end subroutine CFTP_Init
  1181. ! ***
  1182. subroutine CFTP_Write( CF, region, idate_f, status )
  1183. use Binas , only : grav
  1184. use Phys , only : GeoPotentialHeight
  1185. use Grid , only : FPressure, HPressure
  1186. use GO , only : TDate, NewDate, rTotal, operator(-)
  1187. use partools , only : myid, root
  1188. use Meteo , only : lli, levi
  1189. use Meteo , only : sp_dat, temper_dat, humid_dat, pu_dat, pv_dat, mfw_dat, gph_dat, oro_dat, t2m_dat
  1190. use Meteo , only : m_dat
  1191. use global_data, only : mass_dat
  1192. ! --- in/out -------------------------------------
  1193. type(TCF_File_TP), intent(inout) :: CF
  1194. integer, intent(in) :: region
  1195. integer, intent(in) :: idate_f(6)
  1196. integer, intent(out) :: status
  1197. ! --- const --------------------------------------
  1198. character(len=*), parameter :: rname = mname//'/CFTP_Write'
  1199. ! --- local ------------------------------------
  1200. integer :: i, j, l
  1201. integer :: imr, jmr, lmr
  1202. real, allocatable :: lev(:)
  1203. type(TDate) :: t, t0
  1204. real :: time
  1205. real, allocatable :: field3d(:,:,:)
  1206. real, allocatable :: p_hlev(:)
  1207. ! --- begin -------------------------------------
  1208. call goLabel(rname)
  1209. ! grid size
  1210. imr = lli(region)%nlon
  1211. jmr = lli(region)%nlat
  1212. lmr = levi%nlev
  1213. ! next time record:
  1214. CF%trec = CF%trec + 1
  1215. ! time since reftime:
  1216. t0 = NewDate( time6=time_reftime6 )
  1217. t = NewDate( time6=idate_f )
  1218. time = rTotal( t - t0, 'day' )
  1219. ! start independend data mode:
  1220. ! o write data
  1221. ! end independend data mode:
  1222. call goLabel()
  1223. ! ok
  1224. status = 0
  1225. end subroutine CFTP_Write
  1226. ! ***
  1227. subroutine CFTP_Done( CF, status )
  1228. use partools, only : myid, root
  1229. use Meteo , only : lli, levi
  1230. ! --- in/out -------------------------------------
  1231. type(TCF_File_TP), intent(inout) :: CF
  1232. integer, intent(out) :: status
  1233. ! --- const --------------------------------------
  1234. character(len=*), parameter :: rname = mname//'/CFTP_Done'
  1235. ! --- local ------------------------------------
  1236. ! --- begin -------------------------------------
  1237. call goLabel(rname)
  1238. ! close file
  1239. call goLabel()
  1240. ! ok
  1241. status = 0
  1242. end subroutine CFTP_Done
  1243. ! ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  1244. ! FILE3: 3D fields for O3, CO, CH4, ... volume mixing ratios
  1245. ! ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  1246. subroutine CFVMR_Init(CF_hdf, CF, fdir, model, expid, filetype, region, &
  1247. idate_f, dhour, tracer_names, ivmr, status )
  1248. use Binas , only : xmair
  1249. use GO , only : goReadFromLine, goUpCase
  1250. use chem_param , only : ntrace, names, ra
  1251. use partools , only : myid, root, MPI_INFO_NULL
  1252. use partools , only : localComm
  1253. use Meteo , only : lli, levi, sp_dat, cp_dat
  1254. use file_hdf, only : THdfFile, Init, setdim,WriteAttribute, WriteData, TSds, Done,SD_UNLIMITED
  1255. ! --- in/out -------------------------------------
  1256. type(THdfFile),intent(out) :: CF_hdf
  1257. type(TCF_File_VMR), intent(out) :: CF
  1258. character(len=*), intent(in) :: fdir
  1259. character(len=*), intent(in) :: model
  1260. character(len=*), intent(in) :: expid
  1261. character(len=*), intent(in) :: filetype
  1262. integer, intent(in) :: region
  1263. integer, intent(in) :: ivmr
  1264. integer, intent(in) :: idate_f(6)
  1265. integer, intent(in) :: dhour
  1266. character(len=*), intent(in) :: tracer_names
  1267. integer, intent(out) :: status
  1268. ! --- const --------------------------------------
  1269. character(len=*), parameter :: rname = mname//'/CFVMR_Init'
  1270. ! --- local ------------------------------------
  1271. character(len=256) :: fname
  1272. integer :: varid
  1273. character(len=256) :: trnames
  1274. character(len=8) :: trname, tmname
  1275. integer :: k, j,itr,ivar,ivar_tracer,ivar_vmr
  1276. character(len=32) :: varname, varname_conc, varname_spec
  1277. character(len=64) :: cf_medium_stnd, cf_medium_long
  1278. character(len=64) :: cf_enti_stnd, cf_enti_long, cf_enti_unit
  1279. character(len=64) :: cf_spec_stnd, cf_spec_long
  1280. character(len=256) :: cf_name_stnd, cf_name_long, cf_name_unit
  1281. character(len=512) :: comment
  1282. ! --- begin -------------------------------------
  1283. call goLabel(rname)
  1284. ! store arguments
  1285. CF%dhour = dhour
  1286. CF%tracer_names = tracer_names
  1287. !
  1288. ! Find trace index for requested tracers.
  1289. !
  1290. write (gol,'("selected tracers for VMR output:")'); call goPr
  1291. CF%ntr = 0
  1292. trnames = tracer_names
  1293. do
  1294. ! empty ?
  1295. if ( len_trim(trnames) == 0 ) exit
  1296. ! next number:
  1297. if ( CF%ntr == ntrace ) then
  1298. write (gol,'("number of elements in tracer names list exceeds ntrace=",i6)') ntrace; call goErr
  1299. TRACEBACK; status=1; return
  1300. end if
  1301. CF%ntr = CF%ntr + 1
  1302. ! extract leading name:
  1303. call goReadFromLine( trnames, trname, status, sep=' ' )
  1304. IF_NOTOK_RETURN(status=1)
  1305. ! store cf name:
  1306. CF%name_tr(CF%ntr) = trname
  1307. ! convert to tm5 name:
  1308. select case ( trname )
  1309. case ( 'HCHO' ) ; tmname = 'CH2O'
  1310. case ( 'Rn', 'Radon' ) ; tmname = 'Rn222'
  1311. case ( 'Pb', 'Lead' ) ; tmname = 'Pb210'
  1312. case default ; tmname = trname
  1313. end select
  1314. ! NOy is a special ...
  1315. select case ( tmname )
  1316. case ( 'NOy' )
  1317. ! defined as ntrace+1
  1318. CF%itr(CF%ntr) = iNOy
  1319. write (gol,'(" * ",a10)') trim(trname); call goPr
  1320. case default
  1321. ! loop over all names:
  1322. CF%itr(CF%ntr) = -1
  1323. do itr = 1, ntrace
  1324. ! case indendent match ?
  1325. if ( goUpCase(trim(tmname)) == goUpCase(trim(names(itr))) ) then
  1326. write (gol,'(" ",i3," ",a10," (",a10,") ",f12.4)') itr, trim(trname), trim(names(itr)), ra(itr); call goPr
  1327. CF%itr(CF%ntr) = itr
  1328. exit
  1329. end if
  1330. end do
  1331. end select
  1332. ! not found ?
  1333. if ( CF%itr(CF%ntr) < 0 ) then
  1334. write (gol,'("tracer name not supported:")'); call goPr
  1335. write (gol,'(" list all : ",a)') trim(tracer_names); call goPr
  1336. write (gol,'(" list element : ",i3)') CF%ntr; call goPr
  1337. write (gol,'(" cf name : ",a)') trim(trname); call goPr
  1338. write (gol,'(" tm5 name : ",a)') trim(tmname); call goPr
  1339. write (gol,'(" tm5 tracers : ")'); call goPr
  1340. do itr = 1, ntrace
  1341. write (gol,'(" ",i3," ",a)') itr, trim(names(itr)); call goPr
  1342. end do
  1343. TRACEBACK; status=1; return
  1344. end if
  1345. end do
  1346. ! empty file ?
  1347. if ( CF%ntr < 1 ) then
  1348. write (gol,'("no tracers extracted from list :",a)') tracer_names; call goErr
  1349. TRACEBACK; status=1; return
  1350. end if
  1351. !
  1352. ! Only root should initialize files
  1353. !
  1354. if (myid /= root) return
  1355. ! o open file for writing instantaneous data:
  1356. ! write filename
  1357. write (fname,'(a,"/",a,a,"_",a,"_",a,"_",i4.4,"_",i2.2,"_",i2.2,".hdf")') &
  1358. trim(fdir), trim(model), trim(fname_grid(region)), trim(expid), trim(filetype), idate_f(1:3)
  1359. ! open:
  1360. call Init(CF_hdf,trim(fname),'create', status)
  1361. IF_NOTOK_RETURN(status=1)
  1362. ! o write global attributes
  1363. call WriteAttribute(CF_hdf,'title','instantaneous volume mixing ratios',status)
  1364. IF_NOTOK_RETURN(status=1)
  1365. call WriteAttribute(CF_hdf,'dataset_author', trim(dataset_author),status)
  1366. IF_NOTOK_RETURN(status=1)
  1367. call WriteAttribute(CF_hdf,'dataset_institution', trim(dataset_institution),status)
  1368. IF_NOTOK_RETURN(status=1)
  1369. call WriteAttribute(CF_hdf,'dataset_version', trim(dataset_version),status)
  1370. IF_NOTOK_RETURN(status=1)
  1371. ! o define dimensions
  1372. CF%dimid_lon = lli(region)%nlon
  1373. CF%dimid_lat = lli(region)%nlat
  1374. CF%dimid_lev = levi%nlev
  1375. !This doesn't work. I don't know what should be set here...: CF%dimid_time='UNLIMITED'
  1376. CF%dimid_time=2
  1377. CF%dimid_datelen=6
  1378. ! o define variables, using the CF_grid_var and CF_vmr_var -stuff defined earlier
  1379. ivar=1 ! longitude
  1380. call init(sds_vmr_inst(region,ivmr,ivar), CF_hdf, trim(CF_grid_var(ivar)%param_name), (/ CF%dimid_lon /), 'real(8)',status)
  1381. IF_NOTOK_RETURN(status=1)
  1382. call SetDim( sds_vmr_inst(region,ivmr,ivar), 0, trim(CF_grid_var(ivar)%param_name), trim(CF_grid_var(ivar)%units),(/(lli(region)%lon_deg)/) ,status)
  1383. IF_NOTOK_RETURN(status=1)
  1384. call WriteAttribute(sds_vmr_inst(region,ivmr,ivar), 'standard_name' , trim(CF_grid_var(ivar)%stand_name),status)
  1385. IF_NOTOK_RETURN(status=1)
  1386. call WriteAttribute(sds_vmr_inst(region,ivmr,ivar), 'long_name' ,trim(CF_grid_var(ivar)%long_name),status )
  1387. IF_NOTOK_RETURN(status=1)
  1388. call WriteAttribute(sds_vmr_inst(region,ivmr,ivar), 'units' , trim(CF_grid_var(ivar)%units),status )
  1389. IF_NOTOK_RETURN(status=1)
  1390. ivar = 2 ! latitude
  1391. call init(sds_vmr_inst(region,ivmr,ivar), CF_hdf, trim(CF_grid_var(ivar)%param_name), (/ CF%dimid_lat /), 'real(8)',status)
  1392. IF_NOTOK_RETURN(status=1)
  1393. call SetDim( sds_vmr_inst(region,ivmr,ivar), 0, trim(CF_grid_var(ivar)%param_name), trim(CF_grid_var(ivar)%units),(/(lli(region)%lat_deg)/) ,status)
  1394. IF_NOTOK_RETURN(status=1)
  1395. call WriteAttribute(sds_vmr_inst(region,ivmr,ivar), 'standard_name' , trim(CF_grid_var(ivar)%stand_name),status)
  1396. IF_NOTOK_RETURN(status=1)
  1397. call WriteAttribute(sds_vmr_inst(region,ivmr,ivar), 'long_name' ,trim(CF_grid_var(ivar)%long_name),status )
  1398. IF_NOTOK_RETURN(status=1)
  1399. call WriteAttribute(sds_vmr_inst(region,ivmr,ivar), 'units' , trim(CF_grid_var(ivar)%units),status )
  1400. ivar = 3 ! level
  1401. call init(sds_vmr_inst(region,ivmr,ivar), CF_hdf, trim(CF_grid_var(ivar)%param_name), (/ CF%dimid_lev /), 'real(8)',status)
  1402. IF_NOTOK_RETURN(status=1)
  1403. call SetDim( sds_vmr_inst(region,ivmr,ivar), 0, trim(CF_grid_var(ivar)%param_name), trim(CF_grid_var(ivar)%units),(/(j,j=1,levi%nlev)/) ,status)
  1404. IF_NOTOK_RETURN(status=1)
  1405. call WriteAttribute(sds_vmr_inst(region,ivmr,ivar), 'standard_name' , trim(CF_grid_var(ivar)%stand_name),status)
  1406. IF_NOTOK_RETURN(status=1)
  1407. call WriteAttribute(sds_vmr_inst(region,ivmr,ivar), 'long_name' ,trim(CF_grid_var(ivar)%long_name),status )
  1408. IF_NOTOK_RETURN(status=1)
  1409. call WriteAttribute(sds_vmr_inst(region,ivmr,ivar), 'units' , trim(CF_grid_var(ivar)%units),status )
  1410. ivar = 4 ! time
  1411. call init(sds_vmr_inst(region,ivmr,ivar), CF_hdf, trim(CF_grid_var(ivar)%param_name), (/ SD_UNLIMITED /), 'real(8)',status)
  1412. IF_NOTOK_RETURN(status=1)
  1413. ! call SetDim( sds_vmr_inst(region,ivmr,ivar), 0, trim(CF_grid_var(ivar)%param_name), trim(CF_grid_var(ivar)%units), (/ /) ,status)
  1414. ! IF_NOTOK_RETURN(status=1)
  1415. call WriteAttribute(sds_vmr_inst(region,ivmr,ivar), 'standard_name' , trim(CF_grid_var(ivar)%stand_name),status)
  1416. IF_NOTOK_RETURN(status=1)
  1417. call WriteAttribute(sds_vmr_inst(region,ivmr,ivar), 'long_name' ,trim(CF_grid_var(ivar)%long_name),status )
  1418. IF_NOTOK_RETURN(status=1)
  1419. call WriteAttribute(sds_vmr_inst(region,ivmr,ivar), 'units' , trim(CF_grid_var(ivar)%units),status )
  1420. IF_NOTOK_RETURN(status=1)
  1421. ivar = 5 ! date
  1422. call init(sds_vmr_inst(region,ivmr,ivar), CF_hdf, trim(CF_grid_var(ivar)%param_name), (/ CF%dimid_datelen, SD_UNLIMITED /), 'integer(4)',status)
  1423. IF_NOTOK_RETURN(status=1)
  1424. call SetDim( sds_vmr_inst(region,ivmr,ivar), 0, trim(CF_grid_var(ivar)%param_name), trim(CF_grid_var(ivar)%units),(/1,2,3,4,5,6/) ,status)
  1425. IF_NOTOK_RETURN(status=1)
  1426. ! call SetDim( sds_vmr_inst(region,ivmr,ivar), 1, trim(CF_grid_var(4)%param_name), trim(CF_grid_var(4)%units),(/0/) ,status)
  1427. ! IF_NOTOK_RETURN(status=1)
  1428. call WriteAttribute(sds_vmr_inst(region,ivmr,ivar), 'standard_name' , trim(CF_grid_var(ivar)%stand_name),status)
  1429. IF_NOTOK_RETURN(status=1)
  1430. call WriteAttribute(sds_vmr_inst(region,ivmr,ivar), 'long_name' ,trim(CF_grid_var(ivar)%long_name),status )
  1431. IF_NOTOK_RETURN(status=1)
  1432. call WriteAttribute(sds_vmr_inst(region,ivmr,ivar), 'units' , trim(CF_grid_var(ivar)%units),status )
  1433. IF_NOTOK_RETURN(status=1)
  1434. ivar_vmr = 6 ! surface pressure
  1435. call init(sds_vmr_inst(region,ivmr,ivar_vmr), CF_hdf, trim(CF_TP_var(1)%param_name), (/CF%dimid_lon,CF%dimid_lat, SD_UNLIMITED /), 'real(8)',status)
  1436. IF_NOTOK_RETURN(status=1)
  1437. call SetDim( sds_vmr_inst(region,ivmr,ivar_vmr), 0, trim(CF_grid_var(1)%param_name), trim(CF_grid_var(1)%units),(/(lli(region)%lon_deg)/) ,status)
  1438. IF_NOTOK_RETURN(status=1)
  1439. call SetDim( sds_vmr_inst(region,ivmr,ivar_vmr), 1, trim(CF_grid_var(2)%param_name), trim(CF_grid_var(2)%units),(/(lli(region)%lat_deg)/) ,status)
  1440. IF_NOTOK_RETURN(status=1)
  1441. call WriteAttribute(sds_vmr_inst(region,ivmr,ivar_vmr), 'standard_name' , trim(CF_TP_var(1)%stand_name) ,status)
  1442. IF_NOTOK_RETURN(status=1)
  1443. call WriteAttribute(sds_vmr_inst(region,ivmr,ivar_vmr), 'long_name' , trim(CF_TP_var(1)%long_name) ,status )
  1444. IF_NOTOK_RETURN(status=1)
  1445. call WriteAttribute(sds_vmr_inst(region,ivmr,ivar_vmr), 'units' , trim(CF_TP_var(1)%param_name),status )
  1446. IF_NOTOK_RETURN(status=1)
  1447. nvar_dims=6
  1448. ! loop over tracer to be written:
  1449. do k = 1, CF%ntr
  1450. ivar_tracer=CF%itr(k)
  1451. ivar = nvar_dims+k
  1452. call init(sds_vmr_inst(region,ivmr,ivar), CF_hdf, trim(CF_vmr_var(ivar_tracer)%param_name), (/CF%dimid_lon,CF%dimid_lat, CF%dimid_lev, SD_UNLIMITED /), 'real(8)',status)
  1453. IF_NOTOK_RETURN(status=1)
  1454. call SetDim( sds_vmr_inst(region,ivmr,ivar), 0, trim(CF_grid_var(1)%param_name), trim(CF_grid_var(1)%units),(/(lli(region)%lon_deg)/) ,status)
  1455. IF_NOTOK_RETURN(status=1)
  1456. call SetDim( sds_vmr_inst(region,ivmr,ivar), 1, trim(CF_grid_var(2)%param_name), trim(CF_grid_var(2)%units),(/(lli(region)%lat_deg)/) ,status)
  1457. IF_NOTOK_RETURN(status=1)
  1458. call SetDim( sds_vmr_inst(region,ivmr,ivar), 2, trim(CF_grid_var(3)%param_name), trim(CF_grid_var(3)%units),(/(j,j=1,levi%nlev)/) ,status)
  1459. IF_NOTOK_RETURN(status=1)
  1460. ! call SetDim( sds_vmr_inst(region,ivmr,ivar), 3, trim(CF_grid_var(4)%param_name), trim(CF_grid_var(4)%units),(/0/) ,status)
  1461. ! IF_NOTOK_RETURN(status=1)
  1462. call WriteAttribute(sds_vmr_inst(region,ivmr,ivar), 'standard_name' , trim(CF_vmr_var(ivar_tracer)%stand_name),status)
  1463. IF_NOTOK_RETURN(status=1)
  1464. call WriteAttribute(sds_vmr_inst(region,ivmr,ivar), 'long_name' ,trim(CF_vmr_var(ivar_tracer)%long_name),status )
  1465. IF_NOTOK_RETURN(status=1)
  1466. call WriteAttribute(sds_vmr_inst(region,ivmr,ivar), 'units' , trim(CF_vmr_var(ivar_tracer)%units),status )
  1467. IF_NOTOK_RETURN(status=1)
  1468. ! store varid (?)
  1469. CF%varid_tr(k) = varid
  1470. end do
  1471. ! o end defintion mode
  1472. ! status = pnf90_enddef( CF%ncid )
  1473. ! IF_PNF90_NOTOK_RETURN(status=1)
  1474. ! o
  1475. ! no records written yet
  1476. CF%trec = 0
  1477. call goLabel()
  1478. ! ok
  1479. status = 0
  1480. end subroutine CFVMR_Init
  1481. ! ***
  1482. subroutine CFVMR_Write( CF, region, ivmr, idate_f, status )
  1483. use GO , only : TDate, NewDate, rTotal, operator(-)
  1484. use chem_param , only : ntrace, ntracet, fscale,names,ntrace_chem
  1485. use partools , only : myid, root
  1486. use partools , only : previous_par
  1487. use partools , only : tracer_active, tracer_loc, tracer_id
  1488. use partools , only : lmloc, offsetl
  1489. use partools , only : Par_Barrier, Par_Scatter_Over_Levels, Par_Gather_Tracer_t
  1490. use partools , only : which_par, previous_par,par_gather_from_levels,par_gather_tracer_k
  1491. use tracer_data, only : mass_dat, chem_dat
  1492. use Meteo , only : lli, levi
  1493. use Meteo , only : m_dat, sp_dat, cp_dat, iwc_dat, temper_dat
  1494. use file_hdf , only : THdfFile, WriteData, TSds, Done
  1495. use dims , only : jsr,jer,isr,ier
  1496. !vh use emission_nox, only: flashrate
  1497. #ifdef MPI
  1498. use mpi_comm, only : gather_tracer_t,gather_tracer_k
  1499. use mpi_const, only : my_real, mpi_sum, com_trac,com_lev, ierr
  1500. #endif
  1501. ! --- in/out -------------------------------------
  1502. type(TCF_File_VMR), intent(inout) :: CF
  1503. integer, intent(in) :: region
  1504. integer, intent(in) :: ivmr
  1505. integer, intent(in) :: idate_f(6)
  1506. integer, intent(out) :: status
  1507. ! --- const --------------------------------------
  1508. character(len=*), parameter :: rname = mname//'/CFVMR_Write'
  1509. ! --- local ------------------------------------
  1510. integer :: imr, jmr, lmr
  1511. real, allocatable :: lev(:)
  1512. integer :: i,j,l, ls, le,nsend,lmm,n
  1513. type(TDate) :: t, t0
  1514. real(8),dimension(1):: time
  1515. integer :: k, itr, itr_loc,ivar
  1516. integer :: k_comp, itr_comp, itr_comp_loc,lglob
  1517. integer,dimension(20):: my_nontr
  1518. integer :: my_nnontr
  1519. real, dimension(:,:,:,:), pointer :: rm
  1520. real, dimension(:,:,:,:), pointer :: rm_c
  1521. real, dimension(:,:,:), pointer :: m
  1522. real, dimension(:,:,:,:), allocatable :: rmk
  1523. real, dimension(:,:,:,:), allocatable :: x_t ,rm_cg,rm_tg,x_chem
  1524. real, allocatable :: NOy_k(:,:,:)
  1525. real, allocatable :: field_t(:,:,:)
  1526. real, allocatable :: field_k(:,:,:)
  1527. real, allocatable :: flsum(:,:)
  1528. real, allocatable :: flavg(:,:)
  1529. ! --- begin -------------------------------------
  1530. ! for multiple of dhour only ...
  1531. if ( (modulo(idate_f(4),CF%dhour)/=0) .or. any(idate_f(5:6)/=0) ) then
  1532. status=0; return
  1533. end if
  1534. call goLabel(rname)
  1535. ! grid size
  1536. imr = lli(region)%nlon
  1537. jmr = lli(region)%nlat
  1538. lmr = levi%nlev
  1539. ! next time record:
  1540. CF%trec = CF%trec + 1
  1541. ! time since 2000-1-1 00:00
  1542. t0 = NewDate( time6=time_reftime6 )
  1543. t = NewDate( time6=idate_f )
  1544. time = rTotal( t - t0, 'day' )
  1545. ! start independend data mode:
  1546. ! root only:
  1547. if ( myid == root ) then
  1548. ! only once ...
  1549. if ( CF%trec == 1 ) then
  1550. ivar=1
  1551. call writedata(sds_vmr_inst(region,ivmr,ivar),lli(region)%lon_deg,status)
  1552. IF_NOTOK_RETURN(status=1)
  1553. ivar=2
  1554. call writedata(sds_vmr_inst(region,ivmr,ivar),lli(region)%lat_deg,status)
  1555. IF_NOTOK_RETURN(status=1)
  1556. ! write level indices:
  1557. allocate( lev(lmr) )
  1558. do l = 1, lmr
  1559. lev(l) = real(l)
  1560. end do
  1561. ivar=3
  1562. call writedata(sds_vmr_inst(region,ivmr,ivar),lev,status)
  1563. IF_NOTOK_RETURN(status=1)
  1564. deallocate(lev)
  1565. end if ! first record
  1566. ! time:
  1567. ivar=4
  1568. call WriteData( sds_vmr_inst(region,ivmr,ivar), real(time), status, start=(/CF%trec-1/) )
  1569. ! call writedata( sds_vmr_inst(region,ivmr,ivar), time, status )
  1570. IF_NOTOK_RETURN(status=1)
  1571. ! date:
  1572. ivar=5
  1573. call WriteData( sds_vmr_inst(region,ivmr,ivar), reshape((idate_f),(/6,1/)), status, start=(/0,CF%trec-1/) )
  1574. IF_NOTOK_RETURN(status=1)
  1575. ! surface pressure
  1576. ivar=6 ! Now ivar corresponds to sds_vmr_inst
  1577. call WriteData(sds_vmr_inst(region,ivmr,ivar), sp_dat(region)%data(1:imr,1:jmr,1), status, start=(/0,0,CF%trec-1/))
  1578. IF_NOTOK_RETURN(status=1)
  1579. end if !Root dir
  1580. which_par=previous_par(region)
  1581. if ( which_par /= 'tracer' ) then
  1582. write (gol,'("Wrong type of parallelization : ",a)') which_par; call goErr
  1583. TRACEBACK; status=1; return
  1584. endif
  1585. rm_c => chem_dat(region)%rm_k
  1586. m => m_dat(region)%data
  1587. ! gather transported species
  1588. allocate(x_t(-1:imr+2,-1:jmr+2,lmr, ntracet))
  1589. if ( which_par == 'tracer' ) then
  1590. rm => mass_dat(region)%rm_t
  1591. call gather_tracer_t(x_t,imr,jmr,lmr,2,2,0,ntracet,rm,.false.)
  1592. nullify(rm)
  1593. else
  1594. rm => mass_dat(region)%rm_k
  1595. call gather_tracer_k(x_t,imr,jmr,lmr,2,2,0,ntracet,rm,.false.)
  1596. nullify(rm)
  1597. end if
  1598. !
  1599. ! gather non-transported species
  1600. ! These are always parallelized over layers.
  1601. ! First set tracers at correct location
  1602. !
  1603. ! are there any non-transported tracers in the requested output list?
  1604. ! put these tracers in 'my_nontr'
  1605. ! and evaluate the total number in 'my_nnontr'
  1606. my_nnontr=0
  1607. do k = 1,CF%ntr
  1608. if (CF%itr(k) >= ntracet+1) then
  1609. my_nnontr=my_nnontr+1
  1610. my_nontr(my_nnontr)=CF%itr(k)
  1611. endif
  1612. enddo
  1613. if (my_nnontr>0) then
  1614. allocate(x_chem(1:imr,1:jmr,lmr,my_nnontr))
  1615. #ifdef MPI
  1616. allocate(rm_cg (1:imr,1:jmr,lmr,my_nnontr))
  1617. if (lmloc > 0) then
  1618. lmm = offsetl
  1619. do n=1,my_nnontr
  1620. do l=1,lmloc
  1621. lglob=l+offsetl !offset is zero on tracer domain
  1622. do j = 1,jmr
  1623. do i = 1,imr
  1624. rm_cg(i,j,lglob,n) = rm_c(i,j,l,my_nontr(n))
  1625. end do
  1626. end do
  1627. end do
  1628. end do
  1629. endif
  1630. nsend=imr*jmr*lmr*my_nnontr
  1631. call mpi_allreduce( rm_cg, x_chem, nsend, &
  1632. my_real, mpi_sum, com_trac, ierr )
  1633. deallocate(rm_cg)
  1634. #else
  1635. do n=1,my_nnontr
  1636. do l=1,lmr
  1637. do j = 1,jmr
  1638. do i = 1,imr
  1639. x_chem(i,j,l,n) = rm_c(i,j,l,my_nontr(n))
  1640. end do
  1641. end do
  1642. end do
  1643. end do
  1644. #endif
  1645. endif ! (my_nnontr >0)
  1646. my_nnontr=0
  1647. ! loop over all tracer to be written:
  1648. do k = 1, CF%ntr
  1649. ! global tracer index:
  1650. itr = CF%itr(k)
  1651. ! sds-index:
  1652. ivar= nvar_dims+k
  1653. ! transported or chemistry only ?
  1654. if ( (itr >= 1) .and. (itr <= ntracet) ) then
  1655. if ( myid==root) then
  1656. call WriteData( sds_vmr_inst(region,ivmr,ivar), &
  1657. reshape( x_t(1:imr,1:jmr,1:lmr,itr)/m(1:imr,1:jmr,1:lmr)*fscale(itr), (/imr,jmr,lmr/) ), &
  1658. status, start=(/0,0,0,CF%trec-1/) )
  1659. IF_NOTOK_RETURN(status=1)
  1660. endif
  1661. else if ( (itr >= ntracet+1) .and. (itr <= ntrace) ) then
  1662. my_nnontr=my_nnontr+1
  1663. if ( myid==root) then
  1664. call WriteData( sds_vmr_inst(region,ivmr,ivar), &
  1665. reshape( x_chem(1:imr,1:jmr,1:lmr,my_nnontr)/m(1:imr,1:jmr,1:lmr)*fscale(itr), (/imr,jmr,lmr/) ), &
  1666. status, start=(/0,0,0,CF%trec-1/) )
  1667. IF_NOTOK_RETURN(status=1)
  1668. endif
  1669. ! some exceptions...
  1670. else if ( itr == iNOy ) then
  1671. write(*,*)'ERROR: CHECK IMPLEMENTATION!!! for NOy'
  1672. stop
  1673. ! mole fraction of NOy = sum of mole fractions of NOy components
  1674. ! storage for sum of NOy components (distributed over levels):
  1675. ! allocate( NOy_k(imr,jmr,lmloc) )
  1676. ! 3d fields with all levels or local levels only:
  1677. ! allocate( field_t(imr,jmr,lmr ) )
  1678. ! allocate( field_k(imr,jmr,lmloc) )
  1679. ! loop over transported NOy components:
  1680. NOy_k = 0.0
  1681. do k_comp = 1, nNOyt
  1682. ! global tracer index:
  1683. itr_comp = iNOyt(k_comp)
  1684. ! check ...
  1685. if ( itr_comp > ntracet ) then
  1686. write (gol,'("index of NOy component does not represent a transported tracer : ",i3)') itr_comp; call goErr
  1687. TRACEBACK; status=1; return
  1688. end if
  1689. ! how distributed ?
  1690. select case ( previous_par(region) )
  1691. ! distributed over tracers:
  1692. case ( 'tracer' )
  1693. ! fill 3D field with tracer or zeros:
  1694. if ( tracer_active(itr_comp) ) then
  1695. ! local tracer index:
  1696. itr_comp_loc = tracer_loc(itr_comp)
  1697. ! fill volume mixing ratio:
  1698. field_t = mass_dat(region)%rm_t(1:imr,1:jmr,1:lmr,itr_comp_loc) &
  1699. / m_dat(region)%data(1:imr,1:jmr,1:lmr) * fscale(itr_comp)
  1700. else
  1701. field_t = 0.0
  1702. end if
  1703. ! scatter from process with requested tracer over slabs of layers on all processors:
  1704. call Par_Scatter_Over_Levels( field_t, tracer_id(itr_comp), field_k, status )
  1705. IF_NOTOK_RETURN(status=1)
  1706. ! distributed over layers:
  1707. case ( 'levels' )
  1708. ! copy into target array:
  1709. field_k = mass_dat(region)%rm_k(1:imr,1:jmr,1:lmloc,itr_comp) &
  1710. / m_dat(region)%data(1:imr,1:jmr,ls:le) * fscale(itr_comp)
  1711. ! error ...
  1712. case default
  1713. write (gol,'("unsupported par for distributing NOy fields : ",a)') previous_par(region); call goErr
  1714. TRACEBACK; status=1; return
  1715. end select
  1716. ! add contribution of this NOy component:
  1717. NOy_k = NOy_k + field_k
  1718. end do
  1719. write (gol,'("Please implement treatment of variable : ",a)') 'NOy'; call goErr
  1720. TRACEBACK; status=1; return
  1721. else
  1722. write (gol,'("strange tracer index requested for output : ",i6)') itr; call goErr
  1723. TRACEBACK; status=1; return
  1724. end if
  1725. end do ! tracer
  1726. deallocate(x_t)
  1727. if (my_nnontr>0) then
  1728. deallocate(x_chem)
  1729. endif
  1730. ! end
  1731. call goLabel()
  1732. ! ok
  1733. status = 0
  1734. end subroutine CFVMR_Write
  1735. ! ***
  1736. subroutine CFVMR_Done( CF, CF_hdf, region,ivmr,status )
  1737. use partools, only : myid, root
  1738. use Meteo , only : lli, levi
  1739. use file_hdf, only : THdfFile,Done
  1740. ! --- in/out -------------------------------------
  1741. type(TCF_File_VMR), intent(inout) :: CF
  1742. type(THdfFile), intent(inout) :: CF_hdf
  1743. integer, intent(in) :: region
  1744. integer, intent(in) :: ivmr
  1745. integer, intent(out) :: status
  1746. ! --- const --------------------------------------
  1747. character(len=*), parameter :: rname = mname//'/CFVMR_Done'
  1748. ! --- local ------------------------------------
  1749. integer :: ivar,k
  1750. ! --- begin -------------------------------------
  1751. call goLabel(rname)
  1752. if (myid == root) then
  1753. ! close file
  1754. do k = 1, nvar_dims
  1755. call Done(sds_vmr_inst(region,ivmr,k),status)
  1756. IF_NOTOK_RETURN(status=1)
  1757. enddo
  1758. do k = 1, CF%ntr
  1759. call Done(sds_vmr_inst(region,ivmr,nvar_dims+k),status)
  1760. IF_NOTOK_RETURN(status=1)
  1761. enddo
  1762. call Done(CF_hdf, status)
  1763. IF_NOTOK_RETURN(status=1)
  1764. end if ! myid == root
  1765. call goLabel()
  1766. ! ok
  1767. status = 0
  1768. end subroutine CFVMR_Done
  1769. end module user_output_cf