emission_read__co2.F90 30 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886
  1. !
  2. #define TRACEBACK write (gol,'("in ",a," (",a,i6,")")') rname, __FILE__, __LINE__ ; call goErr
  3. #define IF_NOTOK_RETURN(action) if (status/=0) then; TRACEBACK; action; return; end if
  4. #define IF_ERROR_RETURN(action) if (status> 0) then; TRACEBACK; action; return; end if
  5. !
  6. #include "tm5.inc"
  7. !
  8. !-----------------------------------------------------------------------------
  9. ! TM5 !
  10. !-----------------------------------------------------------------------------
  11. !BOP
  12. !
  13. ! !MODULE: EMISSION_READ
  14. !
  15. ! !DESCRIPTION: This module provides objects and methods related to
  16. ! IPCC-AR5 emissions.
  17. !
  18. ! AR5 netCDF files are provided by CMIP5:
  19. !
  20. ! There are a few keys in the rc-file which control the behaviour of
  21. ! this module and the data used:
  22. ! # specify the (main) provider of emission sets
  23. ! input.emis.provider : AR5
  24. ! # where to find the emissions (this will be used by install-emis-ar5)
  25. ! input.emis.dir : ${TEMP}/EMIS/AR5
  26. ! # year of emissions (AR5 emissions will be linearly interpolated)
  27. ! input.emis.year : 2000
  28. ! # choose RCP out of RCP26, RCP45, RCP60, RCP85
  29. ! input.emis.AR5.RCP : RCP45
  30. !
  31. !\\
  32. !\\
  33. ! !INTERFACE:
  34. !
  35. MODULE EMISSION_READ
  36. !
  37. ! !USES:
  38. !
  39. use GO, only : gol, goErr, goPr, goLabel
  40. use emission_data, only : emis_input_dir_ar5
  41. use emission_data, only : vd_class_name_len
  42. use dims, only : nlon360, nlat180, iglbsfc
  43. use chem_param, only : xmc, xmco2
  44. use Dims, only : okdebug
  45. USE MDF, ONLY : MDF_Open, MDF_NETCDF, MDF_HDF4, MDF_READ
  46. USE MDF, ONLY : MDF_Inq_VarID, MDF_Get_Var, MDF_Close
  47. implicit none
  48. private
  49. !
  50. ! !PUBLIC MEMBER FUNCTIONS:
  51. !
  52. public :: emission_read_init, emission_read_done
  53. public :: numb_sectors, sectors_def
  54. public :: numb_providers, providers_def
  55. public :: sector_name_len
  56. public :: emission_ar5_readCO2
  57. public :: ar5_dim_3ddata
  58. public :: sector_type, provider_type
  59. !
  60. ! !PRIVATE DATA MEMBERS:
  61. !
  62. character(len=*), parameter :: mname = 'emission_read'
  63. ! ------------------------------
  64. ! global characteristics
  65. ! ------------------------------
  66. ! CO2 emissions from land use are provided at 0.5x0.5, from fossil fuel use at 1x1
  67. integer, parameter :: nlat360 = 360 ! number of latitudes for AR5 (0.5deg)
  68. integer, parameter :: nlon720 = 720 ! number of longitudes for AR5 data (0.5deg)
  69. integer, parameter :: sector_name_len = 18 ! length of sector descriptor
  70. integer, parameter :: categ_name_len = 14 ! length of category descriptor
  71. integer, parameter :: numb_sectors = 2 ! number of sectors (All providers!)
  72. integer, parameter :: numb_providers = 1 ! AR5
  73. integer, parameter :: ar5_dim_3ddata = 25 ! number of layers for aircraft data
  74. ! full list of providers
  75. character(8), dimension(numb_providers), parameter :: all_providers = &
  76. & (/ 'AR5 '/)
  77. ! Once CO2 will be combined with chemical tracers in one model,
  78. ! a separate category for AR5 CO2 could be introduced, because the file format is different
  79. ! List of providers effectively used
  80. character(8), PUBLIC, allocatable :: used_providers(:) ! CO2
  81. ! flag for degenerated cases
  82. logical, PUBLIC :: has_emis = .true.
  83. ! ------------------------------
  84. character(len=15), parameter :: filestr_common_pre = 'IPCC_emissions'
  85. character(len=25), parameter :: filestr_common_post = '0.5x0.5.nc'
  86. ! ------------------------------
  87. ! identifier of RCPs (RCP26, RCP45,...)
  88. ! ------------------------------
  89. character(len=5) :: filestr_rcpiden
  90. !---------------------------------------------
  91. ! CMIP5 CO2 emission data
  92. !---------------------------------------------
  93. ! historical data
  94. !---------------------------------------------
  95. ! emissions from fossil-fuel use are provided as monthly gridded fields for 1751-2007 (1x1 degree)
  96. ! (http://dods.ipsl.jussieu.fr/cpipsl/ANDRES/)
  97. ! emissions from land use are provided as yearly gridded fields for 1850-2005 (0.5x0.5 degree)
  98. ! (http://www.mpimet.mpg.de/en/wissenschaft/land-im-erdsystem/...
  99. ! .../wechselwirkung-klima-biogeosphaere/landcover-change-emission-data.html)
  100. ! we only use the data for the years 1850-2005:
  101. integer, dimension(2), parameter :: ar5_avail = (/1850, 2005/)
  102. ! global totals (Pg C/yr) are provided as well:
  103. ! the numbers for the reference year 2005 are:
  104. !real, parameter :: co2_ff_ref = 7.6137 ! Pg C/yr as provided
  105. real, parameter :: co2_ff_ref = 7.617692 ! Pg C/yr as calculated from the gridded fields
  106. !real, parameter :: co2_lu_ref = 1.196 ! Pg C/yr as provided
  107. real, parameter :: co2_lu_ref = 1.4673 ! Pg C/yr as calculated from the gridded field
  108. ! for the land-use emissions up to 2001 the totals calculated from the gridded fields agree well
  109. ! with the totals given by the data provider
  110. ! however, for the last four years 2002-2005 the gridded fields give substantially higher totals
  111. ! this suggests that the emission totals provided for land use have been harmonized with the RCPs
  112. ! while the gridded fields have not
  113. real :: co2_ref
  114. ! future CO2 emissions for the RCPs (2006-2100) are provided as yearly totals (Pg C/yr)
  115. ! we currently use the global totals, but regional totals are available as well
  116. ! values obtained from the IIASA RCP website (http://tntcat.iiasa.ac.at/RcpDb/)
  117. ! for 2006-2100 we combined these totals with the spatial distribution for 2005
  118. integer, parameter :: ar5_nr_avail_yrs = 11
  119. integer, dimension(ar5_nr_avail_yrs), parameter :: &
  120. ar5_avail_yrs = (/ 2005, 2010, 2020, 2030, 2040, &
  121. 2050, 2060, 2070, 2080, 2090, 2100 /)
  122. real, dimension(ar5_nr_avail_yrs), parameter :: &
  123. co2ff_rcp26 = (/ 7.971, 8.821, 9.288, 7.157, 4.535, 3.186, 1.419, 0.116, -0.433, -0.870, -0.931/), &
  124. co2ff_rcp60 = (/ 7.971, 8.512, 8.950, 9.995, 11.554, 13.044, 14.824, 16.506, 17.281, 14.313, 13.753/), &
  125. co2ff_rcp45 = (/ 7.971, 8.607, 9.872, 10.953, 11.338, 11.031, 9.401, 7.118, 4.182, 4.193, 4.203/), &
  126. co2ff_rcp85 = (/ 7.971, 8.926, 11.538, 13.839, 16.787, 20.205, 23.596, 25.962, 27.406, 28.337, 28.740/), &
  127. ! for 2000 and 2005 the global total fossil-fuel emissions for the RCPs
  128. ! are 2.7% resp. 5% higher than the totals given by the provider of the historical dataset
  129. ! this suggests that this dataset has not been harmonized with the RCPs
  130. co2lu_rcp26 = (/ 1.196, 1.056, 0.973, 0.789, 0.489, 0.201, 0.615, 0.538, 0.550, 0.602, 0.511/), &
  131. co2lu_rcp60 = (/ 1.196, 0.877, 0.406, -0.557, -0.714, -0.464, -0.258, -0.029, 0.244, 0.242, 0.181/), &
  132. co2lu_rcp45 = (/ 1.196, 0.911, 0.341, 0.216, 0.199, 0.249, 0.184, 0.104, 0.008, 0.027, 0.046/), &
  133. co2lu_rcp85 = (/ 1.196, 1.044, 0.906, 0.715, 0.645, 0.576, 0.501, 0.412, 0.309, 0.194, 0.077/)
  134. real, dimension(ar5_nr_avail_yrs) :: co2_rcp
  135. logical, dimension(:), allocatable :: ltimeind
  136. character(len=7) :: ar5ff_coverage = 'monthly'
  137. character(len=7) :: ar5lu_coverage = 'yearly '
  138. ! ------------------------------
  139. ! gridbox area (to be read only once per proc)
  140. ! ------------------------------
  141. character(len=25),parameter :: ar5_filestr_gridboxarea = 'gridbox_area.nc'
  142. logical, save :: area_found_05
  143. real, dimension(:,:), allocatable :: gridbox_area_05 ! gridbox area on 0.5x0.5 deg - used for AR5
  144. ! -----------------------
  145. ! data type for sectors
  146. ! -----------------------
  147. type sector_type
  148. sequence
  149. character(len=sector_name_len) :: name ! name of sector
  150. character(len=categ_name_len) :: catname ! name of category to be found in
  151. logical :: f3d ! 3d-data y/n
  152. character(len=vd_class_name_len) :: vdisttype ! vertical distribution type (equal to "classes" still to be defined)
  153. character(len=8) :: prov ! provider of information (AR5)
  154. end type sector_type
  155. type provider_type
  156. character(len=8) :: name
  157. integer :: nsect2d, nsect3d
  158. end type provider_type
  159. type(sector_type), dimension(numb_sectors) :: sectors_def
  160. type(provider_type), dimension(numb_providers) :: providers_def
  161. !
  162. ! !REVISION HISTORY:
  163. ! 1 Oct 2010 - Achim Strunk - v0 for AR5
  164. ! 19 Jun 2012 - P. Le Sager - cosmetic for lon-lat MPI domain decomposition
  165. ! (all reading/regridding on root for now)
  166. ! 20 Nov 2012 - Ph. Le Sager - defined and build lists of used providers
  167. ! - deal with inventories years availability
  168. ! - switch to MDF interface to read data
  169. !
  170. ! !TODO:
  171. ! - should be renamed something like "emission_inventories" or "emiss_providers"
  172. ! - and need to get a **SEPARATE** module for each inventories, before it
  173. ! becomes unmanageable again
  174. !
  175. !EOP
  176. !------------------------------------------------------------------------
  177. CONTAINS
  178. !--------------------------------------------------------------------------
  179. ! TM5 !
  180. !--------------------------------------------------------------------------
  181. !BOP
  182. !
  183. ! !IROUTINE: EMISSION_READ_INIT
  184. !
  185. ! !DESCRIPTION: Initialise reading related parameters and
  186. ! allocate needed arrays
  187. !
  188. !\\
  189. ! !INTERFACE:
  190. !
  191. SUBROUTINE EMISSION_READ_INIT( rcF, status )
  192. !
  193. ! !USES:
  194. !
  195. use GO, only : TrcFile, ReadRc
  196. use partools, only : isRoot
  197. use emission_data, only : LAR5
  198. use meteodata, only : set, gph_dat
  199. use dims, only : im, jm, lm, nregions
  200. !
  201. ! !INPUT PARAMETERS:
  202. !
  203. type(TrcFile) :: rcF
  204. !
  205. ! !OUTPUT PARAMETERS:
  206. !
  207. integer, intent(out) :: status
  208. !
  209. ! !REVISION HISTORY:
  210. ! 1 Oct 2010 - Achim Strunk - v0 for AR5
  211. ! 20 Nov 2012 - Ph. Le Sager - build lists of used providers
  212. !
  213. ! !REMARKS:
  214. !
  215. !EOP
  216. !------------------------------------------------------------------------
  217. !BOC
  218. character(len=*), parameter :: rname=mname//'/emission_read_init'
  219. integer :: isect, iprov, nused, region
  220. logical :: mask(numb_providers)
  221. ! --- begin --------------------------------------
  222. call ReadRc( rcF, 'input.emis.AR5.RCP', filestr_rcpiden, status, default='RCP26' )
  223. IF_ERROR_RETURN(status=1)
  224. ! ------------------
  225. ! build list of used providers
  226. ! ------------------
  227. ! Others gases
  228. mask = (/ LAR5 /)
  229. nused = count(mask)
  230. if (nused /= 0) then
  231. allocate( used_providers(nused) )
  232. used_providers = pack( all_providers, mask)
  233. else
  234. has_emis = .false.
  235. end if
  236. ! info
  237. if ( has_emis ) then
  238. write(gol,*) 'EMISS-INFO - Emissions providers used for CO2: ', used_providers ; call goPr
  239. else
  240. write(gol,*) 'EMISS-INFO - Emissions providers used for CO2: NONE' ; call goPr
  241. end if
  242. ! ------------------
  243. ! initialise sectors
  244. ! ------------------
  245. ! Type sequence is (name, category, is_3D_data, vdisttype, providers)
  246. sectors_def( 1) = sector_type('emiss_ff ', 'anthropogenic ', .false., 'combenergy ', 'AR5 ') ! Fossil Fuel
  247. sectors_def( 2) = sector_type('emiss_lu ', 'anthropogenic ', .false., 'nearsurface ', 'AR5 ') ! Land Use (assumed near surface for the moment, but that is open for discussion)
  248. ! -------------------------
  249. ! initialise providers info
  250. ! ------------------------
  251. do iprov = 1, numb_providers
  252. providers_def(iprov)%name = all_providers(iprov)
  253. providers_def(iprov)%nsect2d = count( (sectors_def%prov == all_providers(iprov)) .and. (sectors_def%f3d .eqv. .false.))
  254. providers_def(iprov)%nsect3d = count( (sectors_def%prov == all_providers(iprov)) .and. (sectors_def%f3d .eqv. .true.))
  255. write(gol,'("EMISS-INFO - Inventory ",a," has ",i3, " 2d-sectors, and ",i3," 3d-sectors")')&
  256. & all_providers(iprov), providers_def(iprov)%nsect2d, providers_def(iprov)%nsect3d ; call goPr
  257. end do
  258. ! -------------------------
  259. ! initialise GeopPotential Height on 1x1
  260. ! ------------------------
  261. do region=1, nregions
  262. call Set( gph_dat(region), status, used=.true. )
  263. end do
  264. ! ----------------------------------------
  265. ! allocate gridbox_area arrays
  266. ! ----------------------------------------
  267. allocate( gridbox_area_05( nlon720, nlat360 ) )
  268. ! OK
  269. status = 0
  270. END SUBROUTINE EMISSION_READ_INIT
  271. !EOC
  272. !--------------------------------------------------------------------------
  273. ! TM5 !
  274. !--------------------------------------------------------------------------
  275. !BOP
  276. !
  277. ! !IROUTINE: EMISSION_READ_DONE
  278. !
  279. ! !DESCRIPTION: Free allocated arrays.
  280. !\\
  281. !\\
  282. ! !INTERFACE:
  283. !
  284. subroutine emission_read_done( status )
  285. !
  286. ! !OUTPUT PARAMETERS:
  287. !
  288. integer, intent(out) :: status
  289. !
  290. ! !REVISION HISTORY:
  291. ! 1 Oct 2010 - Achim Strunk - v0
  292. !
  293. !EOP
  294. !------------------------------------------------------------------------
  295. !BOC
  296. character(len=*), parameter :: rname=mname//'/emission_read_done'
  297. deallocate( gridbox_area_05 )
  298. deallocate( used_providers )
  299. ! OK
  300. status = 0
  301. END SUBROUTINE EMISSION_READ_DONE
  302. !EOC
  303. !--------------------------------------------------------------------------
  304. ! TM5 !
  305. !--------------------------------------------------------------------------
  306. !BOP
  307. !
  308. ! !FUNCTION: EMISSION_COARSEN_TO_1X1
  309. !
  310. ! !DESCRIPTION: Coarsen the gridded information to 1x1 deg.
  311. !\\
  312. !\\
  313. ! !INTERFACE:
  314. !
  315. function emission_coarsen_to_1x1( emis_in, dim_nlon, dim_nlat, shift_lon, status )
  316. !
  317. ! !RETURN VALUE:
  318. !
  319. real, dimension(360,180) :: emission_coarsen_to_1x1
  320. !
  321. ! !INPUT PARAMETERS:
  322. !
  323. integer, intent(in) :: dim_nlon
  324. integer, intent(in) :: dim_nlat
  325. real, intent(in) :: emis_in(dim_nlon, dim_nlat)
  326. logical, intent(in) :: shift_lon
  327. !
  328. ! OUTPUT PARAMETERS:
  329. !
  330. integer , intent(out) :: status
  331. !
  332. ! !REVISION HISTORY:
  333. ! 1 Oct 2010 - Achim Strunk - v0 for AR5
  334. ! 1 Dec 2011 - Narcisa Banda - works for any input resolution lower than 1x1
  335. ! if 1x1 can be divided into exact number of gridcells (no interpolation)
  336. ! 1 Jul 2012 - Narcisa Banda - added the shift_lon logical flag:
  337. ! true if the data is read on longitudes [0,360] (then they need to be shifted on [-180,180])
  338. ! false if the data is read already on [-180,180]
  339. !
  340. !EOP
  341. !------------------------------------------------------------------------
  342. !BOC
  343. integer :: i, j
  344. integer :: nri, nrj
  345. ! --- begin -----------------------------------
  346. ! combine grid cells :
  347. ! from [ 0,360]x[-90,90] 001:360,361:720 001:360
  348. ! to [-180,180]x[-90,90] 001:180,181:360 001:180
  349. if ((mod(dim_nlon, 360) /= 0 ) .or. (mod(dim_nlat, 180) /= 0)) then
  350. print*,'coarsening of emissions to 1x1 does not work for this resolution'
  351. status = 1
  352. return
  353. endif
  354. nri = dim_nlon/360
  355. nrj = dim_nlat/180
  356. if (shift_lon) then
  357. ! combine grid cells :
  358. ! from [ 0,360]x[-90,90] 001:360,361:720 001:360
  359. ! to [-180,180]x[-90,90] 001:180,181:360 001:180
  360. do j = 1, 180
  361. ! west half
  362. do i = 1, 180
  363. emission_coarsen_to_1x1(i,j) = sum(emis_in(nri*180+nri*i-nri+1:nri*180+nri*i,nrj*j-nrj+1:nrj*j))
  364. end do
  365. ! east half
  366. do i = 1, 180
  367. emission_coarsen_to_1x1(180+i,j) = sum(emis_in(nri*i-nri+1:nri*i,nrj*j-nrj+1:nrj*j))
  368. end do
  369. end do
  370. else
  371. do j=1, 180
  372. do i=1, 360
  373. emission_coarsen_to_1x1(i,j) = sum(emis_in(nri*i-nri+1:nri*i,nrj*j-nrj+1:nrj*j))
  374. end do
  375. end do
  376. endif
  377. ! ok
  378. status = 0
  379. end function emission_coarsen_to_1x1
  380. !EOC
  381. !--------------------------------------------------------------------------
  382. ! TM5 !
  383. !--------------------------------------------------------------------------
  384. !BOP
  385. !
  386. ! !FUNCTION: VALID_YEAR
  387. !
  388. ! !DESCRIPTION: return a valid year for an emission inventory, based on
  389. ! requested year.
  390. !\\
  391. !\\
  392. ! !INTERFACE:
  393. !
  394. FUNCTION VALID_YEAR( iyear, iminmax, provider_name, verbose)
  395. !
  396. ! !RETURN VALUE:
  397. !
  398. integer :: valid_year
  399. !
  400. ! !INPUT PARAMETERS:
  401. !
  402. integer, intent(in) :: iyear, iminmax(2)
  403. character(len=*), intent(in) :: provider_name
  404. logical, intent(in) :: verbose
  405. !
  406. ! !REVISION HISTORY:
  407. ! 26 Nov 2012 - Ph. Le Sager - v0
  408. !
  409. !EOP
  410. !------------------------------------------------------------------------
  411. !BOC
  412. valid_year = MIN(iminmax(2),MAX(iyear,iminmax(1)))
  413. ! info only once a year, and per inventory
  414. if (verbose) then
  415. write(gol,'(a,i4," (avail: ",i4,"-",i4,")")') ' EMISS-INFO - EMISS YEAR for '//trim(provider_name)//' : ', &
  416. valid_year, iminmax ; call goPr
  417. end if
  418. END FUNCTION VALID_YEAR
  419. !EOC
  420. !--------------------------------------------------------------------------
  421. ! TM5 !
  422. !--------------------------------------------------------------------------
  423. !BOP
  424. !
  425. ! !IROUTINE: EMISSION_AR5_READCO2
  426. !
  427. ! !DESCRIPTION: Reading one sector of the files to be interpolated and
  428. ! returning an interpolated 3d emission field (d3data)
  429. !\\
  430. !\\
  431. ! !INTERFACE:
  432. !
  433. subroutine emission_ar5_ReadCO2( comp, iyear, imonth, sector, d3data, status )
  434. !
  435. ! !INPUT PARAMETERS:
  436. !
  437. character(len=*) , intent(in) :: comp
  438. integer , intent(in) :: iyear
  439. integer , intent(in) :: imonth
  440. integer , intent(in) :: sector
  441. !
  442. ! !OUTPUT PARAMETERS:
  443. !
  444. integer , intent(out) :: status
  445. real, dimension(nlon360,nlat180,ar5_dim_3ddata), intent(out) :: d3data
  446. !
  447. ! !REVISION HISTORY:
  448. ! 1 Oct 2010 - Achim Strunk - v0
  449. !
  450. !EOP
  451. !------------------------------------------------------------------------
  452. !BOC
  453. character(len=*), parameter :: rname = mname//'/emission_ar5_readCO2'
  454. character(len=256) :: fname
  455. character(len=256) :: fname_gridboxarea
  456. character(32) :: secname
  457. integer :: lt, year
  458. logical :: existfile
  459. integer, dimension(2) :: ltimes
  460. character(len=4), dimension(2) :: ar5_cyears
  461. real, dimension(2) :: ar5_ipcoef_years
  462. logical :: first=.true.
  463. real :: co2_rcp_target, co2_scale
  464. ! --- begin -----------------------------------
  465. ! initialise target array
  466. d3data = 0.0
  467. ! read in gridbox-area; once per CPU
  468. ! For CO2 the area field is read from the CO2 LU file
  469. !if( .not. area_found_05 ) then
  470. ! fname_gridboxarea = trim(emis_input_dir_ar5)//'/'//trim(ar5_filestr_gridboxarea)
  471. ! call emission_ReadGridboxArea(fname_gridboxarea, 'gridbox_area', gridbox_area_05, &
  472. ! & nlon720, nlat360, status )
  473. ! IF_NOTOK_RETURN(status=1)
  474. ! area_found_05=.true.
  475. !endif
  476. ! deal with out-of-bounds requested years
  477. year = valid_year( iyear, ar5_avail, 'AR5', first)
  478. first=.false.
  479. secname = sectors_def(sector)%name
  480. if ( iyear > year ) then
  481. ! ------------------------
  482. ! data for the year ar5_avail(2)=2005 will be read from file
  483. ! and need to be scaled (index=1: earlier year; index=2: later year)
  484. ! ------------------------
  485. ! ----------------------------------------
  486. ! get the right times to interpolate and related coefficients
  487. ! (ar5_avail_yrs(ltimes))
  488. !
  489. ! --> resulting scale factor will be a linear interpolation between neighbouring values
  490. !
  491. ! ----------------------------------------
  492. allocate( ltimeind( ar5_nr_avail_yrs ) )
  493. ltimeind = .false.
  494. where( ar5_avail_yrs < iyear ) ltimeind = .true.
  495. ! times(1): index representing time instance earlier than current year
  496. ! times(2): -"- -"- later than current year
  497. ltimes(2) = count( ltimeind ) + 1
  498. ltimes(1) = ltimes(2) - 1
  499. ! check a match with available years
  500. ! (in order to use only value instead of two)
  501. if( ar5_avail_yrs(ltimes(2)) == iyear ) &
  502. ltimes(1) = ltimes(2)
  503. deallocate( ltimeind )
  504. ! ar5_cyears will contain strings with the years
  505. write(ar5_cyears(1),'(I4.4)') ar5_avail_yrs(ltimes(1))
  506. write(ar5_cyears(2),'(I4.4)') ar5_avail_yrs(ltimes(2))
  507. ! ar5_ipcoef_years will contain interpolation coefficients
  508. ! default: factors 1.0/0.0
  509. ar5_ipcoef_years(1) = 1.0
  510. ar5_ipcoef_years(2) = 0.0
  511. if( ltimes(2) /= ltimes(1) ) then
  512. ar5_ipcoef_years(1) = (ar5_avail_yrs(ltimes(2)) - iyear) / &
  513. real( ar5_avail_yrs(ltimes(2)) - ar5_avail_yrs(ltimes(1)) )
  514. ar5_ipcoef_years(2) = 1.0 - ar5_ipcoef_years(1)
  515. end if
  516. select case (trim (secname) )
  517. case ( 'emiss_ff' )
  518. co2_ref=co2_ff_ref
  519. select case (trim(filestr_rcpiden) )
  520. case ('RCP26')
  521. co2_rcp(:)=co2ff_rcp26(:)
  522. case ('RCP45')
  523. co2_rcp(:)=co2ff_rcp45(:)
  524. case ('RCP60')
  525. co2_rcp(:)=co2ff_rcp60(:)
  526. case ('RCP85')
  527. co2_rcp(:)=co2ff_rcp85(:)
  528. case default
  529. write(gol, '("ERROR: no RCP scenario specified for CO2 emissions")') ; call goErr
  530. end select
  531. case ( 'emiss_lu')
  532. co2_ref=co2_lu_ref
  533. select case (trim(filestr_rcpiden) )
  534. case ('RCP26')
  535. co2_rcp(:)=co2lu_rcp26(:)
  536. case ('RCP45')
  537. co2_rcp(:)=co2lu_rcp45(:)
  538. case ('RCP60')
  539. co2_rcp(:)=co2lu_rcp60(:)
  540. case ('RCP85')
  541. co2_rcp(:)=co2lu_rcp85(:)
  542. end select
  543. end select
  544. co2_rcp_target=co2_rcp(ltimes(1))*ar5_ipcoef_years(1)+co2_rcp(ltimes(2))*ar5_ipcoef_years(2)
  545. co2_scale=co2_rcp_target/co2_ref
  546. else
  547. ! no scaling for years <= 2005
  548. co2_scale=1.
  549. endif
  550. ! ------------------------
  551. ! read CO2 emission file
  552. ! ------------------------
  553. select case ( trim (secname) )
  554. case ( 'emiss_ff' )
  555. fname = trim(emis_input_dir_ar5) //'/'// &
  556. 'CMIP5_gridcar_CO2_emissions_fossil_fuel_Andres_1751-2007_monthly_SC_mask11.nc'
  557. case ( 'emiss_lu' )
  558. fname = trim(emis_input_dir_ar5) //'/'// &
  559. 'carbon_emissions_landuse_20person.nc'
  560. case default
  561. write(gol, '("ERROR: emission sector ",a,"not available for CO2")') &
  562. trim(secname); call goErr
  563. status=1; return
  564. end select
  565. ! test existence of file
  566. inquire( file=trim(fname), exist=existfile)
  567. if( .not. existfile ) then
  568. write (gol,'("ERROR: file `",a,"` not found ")') trim(fname); call goErr
  569. status=1; return
  570. end if
  571. select case ( trim (secname) )
  572. case ( 'emiss_ff' )
  573. d3data(:,:,1) = d3data(:,:,1) + co2_scale * &
  574. emission_ar5_ReadCO2FF( fname, year, imonth, status )
  575. case ( 'emiss_lu' )
  576. d3data(:,:,1) = d3data(:,:,1) + co2_scale * &
  577. emission_ar5_ReadCO2LU( fname, year, status )
  578. case default
  579. write(gol, '("ERROR: emission sector ",a,"not available for CO2")') &
  580. trim(secname); call goErr
  581. status=1; return
  582. end select
  583. IF_NOTOK_RETURN(status=1)
  584. end subroutine emission_ar5_ReadCO2
  585. !EOC
  586. !--------------------------------------------------------------------------
  587. ! TM5 !
  588. !--------------------------------------------------------------------------
  589. !BOP
  590. !
  591. ! !FUNCTION: EMISSION_AR5_READCO2FF
  592. !
  593. ! !DESCRIPTION: Read monthly AR5 fossil-fuel CO2 emissions on a 1x1 grid
  594. !\\
  595. !\\
  596. ! !INTERFACE:
  597. !
  598. function emission_ar5_ReadCO2FF( fname, year, imonth, status )
  599. !
  600. ! !RETURN VALUE:
  601. !
  602. real :: emission_ar5_ReadCO2FF(360,180)
  603. !
  604. ! !INPUT PARAMETERS:
  605. !
  606. character(len=*), intent(in) :: fname
  607. integer, intent(in) :: year, imonth
  608. !
  609. ! !OUTPUT PARAMETERS:
  610. !
  611. integer, intent(out) :: status
  612. !
  613. ! !REVISION HISTORY:
  614. ! 20 May 2014 - T. van Noije
  615. !
  616. !EOP
  617. !------------------------------------------------------------------------
  618. !BOC
  619. character(len=*), parameter :: rname = mname//'/emission_ar5_ReadCO2FF'
  620. integer :: fid, varid
  621. real :: emis_in(360, 180), area(360,180)
  622. ! --- begin -----------------------------------
  623. ! initialise
  624. emission_ar5_ReadCO2FF = 0.0
  625. CALL MDF_Open( TRIM(fname), MDF_NETCDF, MDF_READ, fid, status )
  626. IF_NOTOK_RETURN(status=1)
  627. CALL MDF_Inq_VarID( fid, 'FF', varid, status )
  628. IF_ERROR_RETURN(status=1)
  629. CALL MDF_Get_Var( fid, varid, emis_in, status, start=(/1,1,12*(year-1751)+imonth/) )
  630. IF_NOTOK_RETURN(status=1)
  631. CALL MDF_Inq_VarID( fid, 'AREA', varid, status )
  632. IF_ERROR_RETURN(status=1)
  633. CALL MDF_Get_Var( fid, varid, area, status, start=(/1,1/) )
  634. IF_NOTOK_RETURN(status=1)
  635. ! to speed up reading of area could be done only once
  636. ! convert from g(C)/m^2/s to kg(CO2)/gridbox/s
  637. emission_ar5_ReadCO2FF(:,:) = emis_in(:,:) * area(:,:) * 1.e-3 * xmco2/xmc
  638. IF_NOTOK_RETURN(status=1)
  639. CALL MDF_Close( fid, status )
  640. IF_NOTOK_RETURN(status=1)
  641. status = 0
  642. return
  643. end function emission_ar5_ReadCO2FF
  644. !EOC
  645. !--------------------------------------------------------------------------
  646. ! TM5 !
  647. !--------------------------------------------------------------------------
  648. !BOP
  649. !
  650. ! !FUNCTION: EMISSION_AR5_READCO2LU
  651. !
  652. ! !DESCRIPTION: Read yearly AR5 land-use CO2 emissions on a 0.5x0.5 grid
  653. ! and convert to a 1x1 grid
  654. !\\
  655. !\\
  656. ! !INTERFACE:
  657. !
  658. function emission_ar5_ReadCO2LU( fname, year, status )
  659. !
  660. ! !RETURN VALUE:
  661. !
  662. real :: emission_ar5_ReadCO2LU(nlon360,nlat180)
  663. !
  664. ! !INPUT PARAMETERS:
  665. !
  666. character(len=*), intent(in) :: fname
  667. integer, intent(in) :: year
  668. !
  669. ! !OUTPUT PARAMETERS:
  670. !
  671. integer, intent(out) :: status
  672. !
  673. ! !REVISION HISTORY:
  674. ! 20 May 2014 - T. van Noije
  675. !
  676. !EOP
  677. !------------------------------------------------------------------------
  678. !BOC
  679. character(len=*), parameter :: rname = mname//'/emission_ar5_ReadCO2LU'
  680. integer :: fid, varid
  681. real :: emis_in(nlon720, nlat360), area(nlon720, nlat360)
  682. ! --- begin -----------------------------------
  683. ! initialise
  684. emission_ar5_ReadCO2LU = 0.0
  685. CALL MDF_Open( TRIM(fname), MDF_NETCDF, MDF_READ, fid, status )
  686. IF_NOTOK_RETURN(status=1)
  687. CALL MDF_Inq_VarID( fid, 'carbon_emission', varid, status )
  688. IF_ERROR_RETURN(status=1)
  689. CALL MDF_Get_Var( fid, varid, emis_in, status, start=(/1,1,year-1850+1/) )
  690. IF_NOTOK_RETURN(status=1)
  691. CALL MDF_Inq_VarID( fid, 'area', varid, status )
  692. IF_ERROR_RETURN(status=1)
  693. CALL MDF_Get_Var( fid, varid, area, status, start=(/1,1/) )
  694. IF_NOTOK_RETURN(status=1)
  695. ! to speed up reading of area could be done only once
  696. ! convert from g(C)/m^2/s to kg(CO2)/gridbox/s
  697. !emis_in(:,:) = emis_in(:,:) * gridbox_area_05(:,:) * 1.e-3 * xmco2/xmc
  698. emis_in(:,:) = emis_in(:,:) * area(:,:) * 1.e-3 * xmco2/xmc
  699. ! now coarsen to nlon360,nlat180
  700. emission_ar5_ReadCO2LU = emission_coarsen_to_1x1( emis_in(:,:), nlon720, nlat360,.true., status )
  701. IF_NOTOK_RETURN(status=1)
  702. CALL MDF_Close( fid, status )
  703. IF_NOTOK_RETURN(status=1)
  704. status = 0
  705. return
  706. end function emission_ar5_ReadCO2LU
  707. !EOC
  708. !--------------------------------------------------------------------------
  709. ! TM5 !
  710. !--------------------------------------------------------------------------
  711. !BOP
  712. !
  713. ! !IROUTINE: EMISSION_READGRIDBOXAREA
  714. !
  715. ! !DESCRIPTION:
  716. ! reading gridbox surface areas for 0.5 x 0.5 Edgar 4
  717. ! needed to scale the emissions from mass/m^2 to mass/grid
  718. !\\
  719. !\\
  720. ! !INTERFACE:
  721. !
  722. subroutine emission_ReadGridboxArea(fname, recname, gridbox_area, dim_nlon, dim_nlat, status )
  723. !
  724. ! !INPUT PARAMETERS:
  725. !
  726. character(len=*), intent(in) :: fname
  727. character(len=*), intent(in) :: recname
  728. integer, intent(in) :: dim_nlon
  729. integer, intent(in) :: dim_nlat
  730. !
  731. ! !OUTPUT PARAMETERS:
  732. !
  733. integer, intent(out) :: status
  734. real, dimension(dim_nlon, dim_nlat), intent(out) :: gridbox_area
  735. !
  736. ! !REVISION HISTORY:
  737. !
  738. ! 1 Oct 2010 - Achim Strunk - v0
  739. ! 1 Dec 2011 - Narcisa Banda - generalized it for any gridbox area size
  740. !
  741. ! !REMARKS:
  742. !
  743. !EOP
  744. !------------------------------------------------------------------------
  745. !BOC
  746. character(len=*), parameter :: rname = mname//'/emission_ReadGridboxArea'
  747. integer :: fid, varid
  748. ! --- begin -----------------------------------
  749. CALL MDF_Open( TRIM(fname), MDF_NETCDF, MDF_READ, fid, status )
  750. IF_NOTOK_RETURN(status=1)
  751. CALL MDF_Inq_VarID( fid, TRIM(recname), varid, status )
  752. IF_ERROR_RETURN(status=1)
  753. CALL MDF_Get_Var( fid, varid, gridbox_area, status )
  754. IF_NOTOK_RETURN(status=1)
  755. CALL MDF_Close( fid, status )
  756. IF_NOTOK_RETURN(status=1)
  757. status = 0
  758. end subroutine emission_ReadGridboxArea
  759. !EOC
  760. END MODULE EMISSION_READ