user_output_noaa.F90 30 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737
  1. ! ********************* DUMMY for TM5-MP **************************
  2. !#################################################################
  3. !WP!
  4. !WP! Routine samples specific events in space and time, as read from a list of
  5. !WP! events. These events are created from the NOAA ESRL Flask database, and can
  6. !WP! thus be matched to observations using the eventnumbers. Co-sampling is based on
  7. !WP! a 4-hour window around the observations time and date, and slopes sampling is
  8. !WP! currently used for the interpolation. Contact Wouter Peters
  9. !WP! (Wouter.Peters@noaa.gov) to get the lists of NOAA ESRL event numbers in the
  10. !WP! proper format. Or copy and paste the following lines to a file (remove comment, no header):
  11. !
  12. !ASK_01D0 23.18 5.42 2728.0 2000 1 1 13 30 0 9703
  13. !CHR_01D1 1.70 -157.17 3.0 2000 1 1 3 40 0 42746
  14. !SPO_01D0 -89.98 -24.80 2810.0 2000 1 1 5 55 0 129319
  15. !STM_01D0 66.00 2.00 7.0 2000 1 1 11 15 0 134065
  16. !KZD_01D0 44.45 75.57 412.0 2000 1 3 4 20 0 69908
  17. !RPB_01D0 13.17 -59.43 45.0 2000 1 3 19 30 0 108606
  18. !KEY_01D0 25.67 -80.20 3.0 2000 1 3 18 0 0 63211
  19. !MLO_01D0 19.53 -155.58 3397.0 2000 1 3 20 37 0 84745
  20. !
  21. !WP! To turn this routine on, add the following RC items to your tm5.rc file:
  22. !
  23. ! output.noaa : T
  24. ! input.noaa.filename : noaa.list # get from Wouter
  25. ! inputdir.noaa : /p73/co2/input/1x1/ # your noaa.list file location here
  26. ! output.noaa.filename: noaa.hdf
  27. !WP!
  28. !WP! Routine is off as default and will thus not bother other users
  29. !WP!
  30. !WP! Future improvements:
  31. !WP! - window size can be read from rc-file
  32. !WP! - tracer list can be specific
  33. !WP! - interpolation mode could be an rc-file item
  34. !WP! - or all 3 interpolations could be used
  35. !WP! - more extensive output on model sample (gph, grid, ...)
  36. !WP!
  37. !WP! Created June 9th, 2007 by Wouter Peters
  38. !WP!
  39. !### macro's #####################################################
  40. !
  41. #define TRACEBACK write (gol,'("in ",a," (",a,", line",i5,")")') rname, __FILE__, __LINE__; call goErr
  42. #define IF_NOTOK_RETURN(action) if (status/=0) then; TRACEBACK; action; return; end if
  43. #define IF_ERROR_RETURN(action) if (status> 0) then; TRACEBACK; action; return; end if
  44. !
  45. #include "tm5.inc"
  46. !
  47. !#################################################################
  48. module user_output_noaa
  49. use GO , only : gol, goErr, goPr, goLabel, goUpCase
  50. ! use dims, only : im, jm, lm, dx, xref, dy, yref, xbeg, xend, ybeg, yend
  51. ! use dims, only : nregions, region_name, itaui,itaue, xcyc
  52. ! use chem_param, only : fscale, ntracet
  53. ! use file_hdf, only : THdfFile, Init, Done, TSds, SetDim, WriteData, WriteAttribute
  54. ! use ParTools
  55. ! #ifdef MPI
  56. ! use mpi_const, only : my_real,mpi_comm_world,ierr,mpi_integer,mpi_character
  57. ! use mpi_comm, only : barrier
  58. ! #endif
  59. implicit none
  60. public :: init_noaa_events, get_noaa, write_noaa_events, noaa_data
  61. logical :: noaa_data=.false.
  62. ! private
  63. ! character(len=100) :: EventlistFilename = ''
  64. ! character(len=100) :: EventlistOutFilename = ''
  65. ! character(len=100) :: InputDir = './'
  66. ! integer :: n_event, n_temp
  67. ! integer,dimension(6) :: idate_event
  68. ! integer :: itau_event
  69. ! integer :: window = 4*3600 ! 2 hrs around obs hour
  70. ! type(THdfFile) :: io_hdf ! contains HDF output file
  71. ! character(len=*), parameter :: mname = 'user_output_noaa'
  72. ! type observation
  73. ! integer,dimension(6) :: idate ! date of observation
  74. ! character(len=24) :: ident ! station identifier
  75. ! real :: lat ! latitude of station
  76. ! real :: lon ! longitude of station
  77. ! real :: height ! height of station
  78. ! integer :: eventnumber ! unique reference to NOAA ESRL database
  79. ! real,dimension(ntracet) :: mmix=0.0
  80. ! integer :: itau=0
  81. ! integer :: n_accumulate=0 ! nr of times concentration was added in get_noaa
  82. ! real :: weight ! accumulated time weighting, replaces n_accumulate in evaluation
  83. ! integer :: region
  84. ! integer :: is
  85. ! integer :: js
  86. ! integer :: lsmin
  87. ! integer :: lsmax
  88. ! end type observation
  89. ! type(observation), dimension(:), allocatable :: concentration
  90. ! ! private
  91. ! integer,parameter :: nf_trace = 1
  92. ! real :: rmf
  93. ! ! number of locations to be calculated for 1 model time
  94. ! integer,dimension(nf_trace) :: if_trace = (/ 1 /)
  95. contains
  96. subroutine write_noaa_events(status)
  97. ! !=====================================
  98. ! ! HDF output for noaa events
  99. ! ! (averaged model results)
  100. ! !=====================================
  101. ! use ParTools
  102. ! use Dims, only : itaui, itaue, ndyn_max, idate, idatei, idatee
  103. ! use file_hdf, only : Init, WriteAttribute, WriteData, TSds, Done
  104. ! use GO, only : TrcFile, Init, Done, ReadRc
  105. ! use global_data, only : rcfile, outdir
  106. ! use chem_param, only : ntracet,names
  107. ! implicit none
  108. ! ! i/o
  109. integer :: status
  110. ! integer :: i_stat, tag,n
  111. ! type(TrcFile) :: rcF
  112. ! character(len=12) :: xname
  113. ! integer :: i, ii, j
  114. ! type(TSds), dimension(:), allocatable :: Sds
  115. ! type(TSds) :: ds
  116. ! real,dimension(:),allocatable :: data_array
  117. ! integer, dimension(:,:), allocatable :: iidate
  118. ! character(len=10) :: sidatei, sidatee
  119. ! ! --- const ------------------------------
  120. ! character(len=*), parameter :: rname = mname//'/write_noaa_events'
  121. STATUS=0
  122. ! call evaluate_noaa()
  123. ! if(myid==root) then !WP! Create output file and write header
  124. ! call Init( rcF, rcfile,status)
  125. ! call ReadRc( rcF, 'output.noaa.filename', EventlistOutFilename,status)
  126. ! call Done( rcF ,status)
  127. ! IF_NOTOK_RETURN(status=1)
  128. ! !WP! Add the date to the filename
  129. ! i = index(EventlistOutFilename,'.hdf')
  130. ! write(sidatei,'(i4.4,3i2.2)') idatei(1:4)
  131. ! write(sidatee,'(i4.4,3i2.2)') idatee(1:4)
  132. ! if(i /= 0) then
  133. ! EventlistOutFilename = EventlistOutFilename(1:i-1)//'_'//sidatei//'_'//sidatee//'.hdf'
  134. ! else
  135. ! EventlistOutFilename = trim(EventlistOutFilename)//'_'//sidatei//'_'//sidatee//'.hdf'
  136. ! endif
  137. ! call Init( io_hdf, trim(OutDir)//'/'// trim(EventlistOutFilename),'create' , status)
  138. ! IF_NOTOK_RETURN(status=1)
  139. ! call Init(ds, io_hdf, 'event_lat' ,(/n_event/),'real(4)',status)
  140. ! call SetDim( ds, 0, 'eventnumber', 'event number', (/ (concentration(j)%eventnumber, j=1,n_event) /) ,status)
  141. ! call WriteAttribute(ds, 'Unit', 'deg N',status)
  142. ! call WriteData( ds, concentration(1:n_event)%lat,status)
  143. ! call Done(ds,status)
  144. ! IF_NOTOK_RETURN(status=1)
  145. ! call Init(ds, io_hdf, 'event_lon' ,(/n_event/),'real(4)',status)
  146. ! call SetDim( ds, 0, 'eventnumber', 'event number', (/ (concentration(j)%eventnumber, j=1,n_event) /) ,status)
  147. ! call WriteAttribute(ds, 'Unit', 'deg E',status)
  148. ! call WriteData( ds, concentration(1:n_event)%lon,status)
  149. ! call Done(ds,status)
  150. ! IF_NOTOK_RETURN(status=1)
  151. ! call Init(ds, io_hdf, 'event_height' ,(/n_event/),'real(4)',status)
  152. ! call SetDim( ds, 0, 'eventnumber', 'event number', (/ (concentration(j)%eventnumber, j=1,n_event) /) ,status)
  153. ! call WriteData( ds, concentration(1:n_event)%height,status)
  154. ! call WriteAttribute(ds, 'Unit', 'meters a.s.l.',status)
  155. ! call Done(ds,status)
  156. ! IF_NOTOK_RETURN(status=1)
  157. ! call Init(ds, io_hdf, 'event_region' ,(/n_event/),'integer(2)',status)
  158. ! call SetDim( ds, 0, 'eventnumber', 'event number', (/ (concentration(j)%eventnumber, j=1,n_event) /) ,status)
  159. ! call WriteData( ds, concentration(1:n_event)%region,status)
  160. ! call Done(ds,status)
  161. ! IF_NOTOK_RETURN(status=1)
  162. ! call Init(ds, io_hdf, 'event_is' ,(/n_event/),'integer(2)',status)
  163. ! call SetDim( ds, 0, 'eventnumber', 'event number', (/ (concentration(j)%eventnumber, j=1,n_event) /) ,status)
  164. ! call WriteData( ds, concentration(1:n_event)%is,status)
  165. ! call Done(ds,status)
  166. ! IF_NOTOK_RETURN(status=1)
  167. ! call Init(ds, io_hdf, 'event_js' ,(/n_event/),'integer(2)',status)
  168. ! call SetDim( ds, 0, 'eventnumber', 'event number', (/ (concentration(j)%eventnumber, j=1,n_event) /) ,status)
  169. ! call WriteData( ds, concentration(1:n_event)%js,status)
  170. ! call Done(ds,status)
  171. ! IF_NOTOK_RETURN(status=1)
  172. ! call Init(ds, io_hdf, 'idate', (/6, n_event/), 'integer(2)',status)
  173. ! call SetDim( ds, 0, 'n_idate ', 'yymmddhhssmm', (/ (j, j=1,6) /) ,status)
  174. ! call SetDim( ds, 1, 'eventnumber', 'event number', (/ (concentration(j)%eventnumber, j=1,n_event) /) ,status)
  175. ! call WriteAttribute(ds, 'Unit', 'year month day hour minutes seconds',status)
  176. ! allocate(iidate(6,n_event))
  177. ! do j=1,n_event
  178. ! iidate(:,j) = concentration(j)%idate
  179. ! enddo
  180. ! call WriteData( ds, iidate,status)
  181. ! IF_NOTOK_RETURN(status=1)
  182. ! deallocate(iidate)
  183. ! call Done(ds,status)
  184. ! IF_NOTOK_RETURN(status=1)
  185. ! call WriteAttribute( io_hdf, 'ntracet', ntracet,status)
  186. ! call WriteAttribute( io_hdf, 'n_event', n_event,status)
  187. ! call WriteAttribute( io_hdf, 'event_ident' , concentration(1:n_event)%ident,status)
  188. ! call WriteAttribute( io_hdf, 'tracer_names' , names(1:ntracet),status)
  189. ! call WriteAttribute( io_hdf, 'event_nsample', concentration(1:n_event)%n_accumulate,status)
  190. ! IF_NOTOK_RETURN(status=1)
  191. ! allocate(Sds(ntracet))
  192. ! do i=1, ntracet
  193. ! xname = trim(names(i))
  194. ! call init(Sds(i), io_hdf, xname, (/n_event/), 'real(4)',status)
  195. ! call SetDim( Sds(i), 0, 'eventnumber', 'event number', (/ (concentration(j)%eventnumber, j=1,n_event) /) ,status)
  196. ! call WriteAttribute(Sds(i), 'Unit', 'Volume mixing ratio',status)
  197. ! enddo
  198. ! IF_NOTOK_RETURN(status=1)
  199. ! endif ! root
  200. ! !WP! Now write datasets from each PE to file
  201. ! allocate(data_array(n_event))
  202. ! do i=1,ntracet
  203. ! data_array=concentration(1:n_event)%mmix(i) ! copy tracer to data_array, proper PE will send to root for I/O
  204. ! #ifdef MPI
  205. ! call MPI_BCAST(data_array(1),n_event,MY_REAL,tracer_id(i),mpi_comm_world,ierr)
  206. ! #endif
  207. ! if(myid==root) then
  208. ! call WriteData(Sds(i),data_array,status)
  209. ! IF_NOTOK_RETURN(status=1)
  210. ! call Done(Sds(i),status)
  211. ! IF_NOTOK_RETURN(status=1)
  212. ! endif
  213. ! enddo
  214. ! deallocate(data_array)
  215. ! if(myid==root)deallocate(Sds)
  216. ! deallocate(concentration)
  217. ! if(myid==root) then
  218. ! call Done(io_hdf,status)
  219. ! IF_NOTOK_RETURN(status=1)
  220. ! endif
  221. end subroutine write_noaa_events
  222. subroutine init_noaa_events(status)
  223. ! use Meteo, only : Set
  224. ! use Meteo, only : temper_dat, humid_dat, gph_dat
  225. ! use binas, only : ae, twopi, grav
  226. ! use dims, only : im, jm, lm, dx, dy, xref, yref, xbeg, ybeg, xend, yend
  227. ! use dims, only : nregions, region_name, itaur, xcyc, idate
  228. ! use chem_param, only : ntrace, ntracet, names, fscale
  229. ! use toolbox, only : escape_tm
  230. ! use datetime, only : date2tau
  231. ! use go_string, only : goUpCase
  232. ! use go_string, only : goNum2Str
  233. ! use GO, only : TrcFile, Init, Done, ReadRc
  234. ! use global_data, only : rcfile
  235. ! implicit none
  236. ! ! i/o
  237. integer :: status
  238. ! ! local
  239. ! character(len=200) :: dummy
  240. ! integer :: fstatus
  241. ! integer :: i_stat, j_stat,n
  242. ! integer :: sunit0=123
  243. ! integer :: region
  244. ! integer,dimension(6) :: idate_sim
  245. ! integer :: itau_sim, isim, ispec
  246. ! ! x,y resolution (in degrees) for current region
  247. ! real :: dxr, dyr
  248. ! character(len=8) :: name_spec !CMK changed from 6-->8
  249. ! logical :: site_found
  250. ! type(TrcFile) :: rcF
  251. ! integer, dimension(6) :: temp_idate
  252. ! integer :: temp_itau,temp_eventnumber
  253. ! real :: temp_lon,temp_lat,temp_height
  254. ! character(len=30) :: temp_ident
  255. ! ! --- const ------------------------------
  256. ! character(len=*), parameter :: rname = mname//'/init_noaa_events'
  257. ! ! start
  258. STATUS=0
  259. ! do region=1,nregions
  260. ! call Set( gph_dat(region), status, used=.true. )
  261. ! IF_NOTOK_RETURN(status=1)
  262. ! call Set( temper_dat(region), status, used=.true. )
  263. ! IF_NOTOK_RETURN(status=1)
  264. ! call Set( humid_dat(region), status, used=.true. )
  265. ! IF_NOTOK_RETURN(status=1)
  266. ! enddo
  267. ! if(myid==root) then
  268. ! call Init( rcF, rcfile,status)
  269. ! call ReadRc( rcF, 'input.noaa.filename', EventlistFilename,status)
  270. ! call ReadRc( rcF, 'inputdir.noaa', InputDir,status)
  271. ! call Done( rcF,status)
  272. ! !=======================================================
  273. ! ! open StationFile (with list of stations)
  274. ! ! "station" means "observation" in this context (arj)
  275. ! !=======================================================
  276. ! open(UNIT=sunit0, FORM='FORMATTED', &
  277. ! FILE=trim(InputDir)//'/'//trim(EventlistFilename)//trim(goNum2Str(idate(1),'(i4.4)'))//trim(goNum2Str(idate(2),'(i2.2)'))//trim(goNum2Str(1,'(i2.2)')) , &
  278. ! ERR=1000)
  279. ! ! count number of stations
  280. ! n_temp=0
  281. ! stat_loop: DO
  282. ! read(sunit0, '(a)', END=100) dummy
  283. ! n_temp = n_temp+1
  284. ! end do stat_loop
  285. ! 100 continue
  286. ! print *, '_________________________________________________' &
  287. ! //'_____________________________'
  288. ! print *, ' preparing to read ', n_temp, ' NOAA events from file: ' //trim(InputDir)//'/'//trim(EventlistFilename)//trim(goNum2Str(idate(1),'(i4.4)'))//trim(goNum2Str(idate(2),'(i2.2)'))//trim(goNum2Str(idate(3),'(i2.2)'))
  289. ! print *, '_________________________________________________' &
  290. ! //'_____________________________'
  291. ! endif
  292. ! #ifdef MPI
  293. ! call MPI_BCAST(n_temp ,1, MPI_INTEGER, root ,MPI_COMM_WORLD,ierr)
  294. ! #endif
  295. ! if(n_temp.eq.0) call escape_tm( 'read_noaa_events: no obs in file ' // EventlistFilename)
  296. ! if(allocated(concentration)) deallocate(concentration) ! avoid double allocation
  297. ! allocate(concentration(n_temp)) ! very long array, only partly used
  298. ! dyr = dy/yref(1)
  299. ! dxr = dx/xref(1)
  300. ! !===============
  301. ! ! read stations
  302. ! !===============
  303. ! n_event=0
  304. ! if(myid==root) then
  305. ! rewind(sunit0)
  306. ! do i_stat=1, n_temp
  307. ! read(sunit0, '(a24,1x,f8.2,f8.2,f8.1,1x,6i4,1x,i30)') &
  308. ! temp_ident, &
  309. ! temp_lat, &
  310. ! temp_lon, &
  311. ! temp_height, &
  312. ! temp_idate, &
  313. ! temp_eventnumber
  314. ! call date2tau(temp_idate,temp_itau) ! fill itau
  315. ! if(abs(temp_itau-itaui).lt.1) temp_itau=temp_itau+3600
  316. ! if(abs(temp_itau-itaue).lt.1) temp_itau=temp_itau-3600
  317. ! if(temp_itau<itaui.or.temp_itau>itaue) then
  318. ! cycle ! exclude events not within this run
  319. ! endif
  320. ! if(temp_lat<-90.or.temp_lat>90) then
  321. ! cycle ! exclude events not within this run
  322. ! endif
  323. ! if(temp_lon<-180.or.temp_lon>180) then
  324. ! cycle ! exclude events not within this run
  325. ! endif
  326. ! !WP! Proceed to fill array concentration with obs within start and end of this run
  327. ! n_event=n_event+1
  328. ! ! goUpCase is *probably* unnecessary
  329. ! concentration(n_event)%ident=goUpCase(trim(adjustl(temp_ident)))
  330. ! concentration(n_event)%lat=temp_lat
  331. ! concentration(n_event)%lon=temp_lon
  332. ! concentration(n_event)%itau=temp_itau
  333. ! concentration(n_event)%height=temp_height
  334. ! concentration(n_event)%idate=temp_idate
  335. ! concentration(n_event)%eventnumber=temp_eventnumber
  336. ! ! Note that the is and js components for the observation locations are
  337. ! ! set *before* the site moves are applied. Is this a bug?
  338. ! ! -Andy, 7 Nov 2006
  339. ! concentration(n_event)%is = &
  340. ! int((concentration(n_event)%lon-float(xbeg(1)))/dxr + 0.99999)
  341. ! concentration(n_event)%js = &
  342. ! int((concentration(n_event)%lat-float(ybeg(1)))/dyr + 0.99999)
  343. ! concentration(n_event)%lsmin = 999
  344. ! concentration(n_event)%lsmax = 0
  345. ! print('(a24,1x,f8.2,f8.2,f8.1,1x,6i4,x,i30)'), &
  346. ! concentration(n_event)%ident, &
  347. ! concentration(n_event)%lat, &
  348. ! concentration(n_event)%lon, &
  349. ! concentration(n_event)%height, &
  350. ! concentration(n_event)%idate, &
  351. ! concentration(n_event)%eventnumber
  352. ! end do
  353. ! ! close stationfile
  354. ! close(sunit0)
  355. ! endif
  356. ! ! share the number of real events: n_event
  357. ! !
  358. ! #ifdef MPI
  359. ! call MPI_BCAST(n_event ,1, MPI_INTEGER, root ,MPI_COMM_WORLD,ierr)
  360. ! #endif
  361. ! if(n_event==0) then ! no data in range
  362. ! write(gol,*) 'WARNING: No NOAA ESRL events within this run, skipping output ' ; call goPr
  363. ! deallocate(concentration)
  364. ! noaa_data=.false.
  365. ! status=0
  366. ! return
  367. ! else
  368. ! write(gol,*) 'Found ',n_event,' NOAA ESRL events within this run' ; call goPr
  369. ! endif
  370. ! ! determine assignment of station to region
  371. ! ! (with highest refinement factor)
  372. ! #ifdef MPI
  373. ! do i_stat=1, n_event
  374. ! call MPI_BCAST(concentration(i_stat)%ident ,24, MPI_CHARACTER, &
  375. ! root ,MPI_COMM_WORLD,ierr)
  376. ! call MPI_BCAST(concentration(i_stat)%lat ,1, MY_REAL , &
  377. ! root ,MPI_COMM_WORLD,ierr)
  378. ! call MPI_BCAST(concentration(i_stat)%lon ,1, MY_REAL , &
  379. ! root ,MPI_COMM_WORLD,ierr)
  380. ! call MPI_BCAST(concentration(i_stat)%height,1, MY_REAL , &
  381. ! root ,MPI_COMM_WORLD,ierr)
  382. ! call MPI_BCAST(concentration(i_stat)%idate,6, MPI_INTEGER , &
  383. ! root ,MPI_COMM_WORLD,ierr)
  384. ! call MPI_BCAST(concentration(i_stat)%eventnumber,1, MPI_INTEGER , &
  385. ! root ,MPI_COMM_WORLD,ierr)
  386. ! call MPI_BCAST(concentration(i_stat)%itau,1, MPI_INTEGER , &
  387. ! root ,MPI_COMM_WORLD,ierr)
  388. ! call MPI_BCAST(concentration(i_stat)%is ,1, MPI_INTEGER, &
  389. ! root ,MPI_COMM_WORLD,ierr)
  390. ! call MPI_BCAST(concentration(i_stat)%js ,1, MPI_INTEGER, &
  391. ! root ,MPI_COMM_WORLD,ierr)
  392. ! call MPI_BCAST(concentration(i_stat)%lsmin ,1, MPI_INTEGER, &
  393. ! root ,MPI_COMM_WORLD,ierr)
  394. ! call MPI_BCAST(concentration(i_stat)%lsmax ,1, MPI_INTEGER, &
  395. ! root ,MPI_COMM_WORLD,ierr)
  396. ! end do
  397. ! #endif
  398. ! do i_stat=1, n_event
  399. ! ! assume global region as default for average mixing ratios
  400. ! concentration(i_stat)%region = 1
  401. ! concentration(i_stat)%is=1
  402. ! concentration(i_stat)%js=1
  403. ! concentration(i_stat)%n_accumulate = 0 ! no model values addded yet
  404. ! concentration(i_stat)%weight = 0.0 ! no model values addded yet
  405. ! concentration(i_stat)%mmix(:) = 0.0 ! no model values addded yet
  406. ! do region=1, nregions
  407. ! dyr = dy/yref(region)
  408. ! dxr = dx/xref(region)
  409. ! if ( (concentration(i_stat)%lon .gt. xbeg(region) .and. &
  410. ! concentration(i_stat)%lon .lt. xend(region)) .and. &
  411. ! (concentration(i_stat)%lat .gt. ybeg(region) .and. &
  412. ! concentration(i_stat)%lat.lt.yend(region) ) ) then
  413. ! !=====================
  414. ! ! station is in region
  415. ! !=====================
  416. ! ! determine region with hightes refinement factor
  417. ! ! if (xref(region) > xref(concentration(i_stat)%region)) then
  418. ! concentration(i_stat)%region = region
  419. ! concentration(i_stat)%is = &
  420. ! int((concentration(i_stat)%lon-float(xbeg(region)))/dxr + 0.99999)
  421. ! concentration(i_stat)%js = &
  422. ! int((concentration(i_stat)%lat-float(ybeg(region)))/dyr + 0.99999)
  423. ! ! end if
  424. ! end if
  425. ! end do
  426. ! end do
  427. ! call Par_Barrier
  428. ! return
  429. ! ! error handling
  430. ! 1000 call escape_tm( 'read_noaa_events: could not open ' // trim(InputDir)//'/'//EventlistFilename)
  431. end subroutine init_noaa_events
  432. subroutine get_noaa(region,itau_f,force)
  433. ! !
  434. ! ! This subroutine samples the model at given locations in array
  435. ! ! concentrations and puts the values in the tag: forecast
  436. ! ! This is done only in a certain time window, or when the keyword /force is
  437. ! ! used. Thus, a model field can be sampled at sites instantaneously (force),
  438. ! ! or at appropriate time ( omit force)
  439. ! !
  440. ! ! Note: the values accumulate so care should be taken to clear the forecast
  441. ! ! and n_accumulate tags between functions
  442. ! !
  443. ! !
  444. ! use global_data, only: mass_dat, region_dat
  445. ! use Meteo, only: gph_dat, m_dat
  446. ! use ParTools, only: myid,ntracet_ar
  447. ! use dims, only : ndyn,ndyn_max
  448. ! implicit none
  449. ! ! input/output
  450. integer,intent(in) :: region
  451. ! ! idate_f: date for which output required...
  452. integer(kind=8),intent(in) :: itau_f
  453. logical,optional :: force
  454. ! ! local
  455. ! real,dimension(:,:,:), pointer :: m,gph
  456. ! real,dimension(:,:,:,:), pointer :: rm, rxm, rym, rzm
  457. ! real,dimension(0:lm(region)) :: height
  458. ! integer :: i,is,js,l,n,isn,jsn,ls,j,offsetj, lst, lstn, lmr, lsn
  459. ! real :: flon,flat,falt,ris,rjs,dxr,dyr,wcx,wcy,rls, wcz
  460. ! real :: this_weight
  461. ! ! start
  462. ! m => m_dat(region)%data !pointers to global arrays...
  463. ! rm => mass_dat(region)%rm_t
  464. ! rxm => mass_dat(region)%rxm_t
  465. ! rym => mass_dat(region)%rym_t
  466. ! rzm => mass_dat(region)%rzm_t
  467. ! gph => gph_dat(region)%data
  468. ! lmr=lm(region)
  469. ! this_weight=real(ndyn)/real(ndyn_max)
  470. ! fcast_loop: do n=1,n_event
  471. ! ! 0. Is idate equal to idate_site
  472. ! ! 1. Is the site in the area?--->no, then put -1 in c
  473. ! ! 2. Determine gridbox
  474. ! ! 3. Use slopes to determine concentration at the site.
  475. ! if ( (concentration(n)%itau.ge.itau_f-window/2.and.&
  476. ! concentration(n)%itau.lt.itau_f+window/2).or.force ) then
  477. ! dyr = dy/yref(region)
  478. ! dxr = dx/xref(region)
  479. ! flon=concentration(n)%lon
  480. ! flat=concentration(n)%lat
  481. ! falt=concentration(n)%height
  482. ! if (concentration(n)%region == region) then
  483. ! ris = (flon-float(xbeg(region)))/dxr + 0.99999
  484. ! rjs = (flat-float(ybeg(region)))/dyr + 0.99999
  485. ! is = int(ris) ! i-index of grid cell in which station is located
  486. ! js = int(rjs) ! j-index of grid cell in which station is located
  487. ! !fraction from the center of the is-box (-0.5---+0.5)
  488. ! ris = ris-is-0.5
  489. ! !idem js
  490. ! rjs = rjs-js-0.5
  491. ! !the neighbour for pressure interpolation
  492. ! if(ris .gt. 0) then
  493. ! isn = is+1
  494. ! else
  495. ! isn = is-1
  496. ! endif
  497. ! !the neighbour for y interpolation
  498. ! if(rjs .gt. 0) then
  499. ! jsn = js+1
  500. ! else
  501. ! jsn = js-1
  502. ! endif
  503. ! ! x- / y-weighting of grid cell in which station is located
  504. ! wcx = (1.0-abs(ris)) ! 1.0 ... 0.5
  505. ! wcy = (1.0-abs(rjs)) ! 1.0 ... 0.5
  506. ! !=================================================================
  507. ! ! if index of neighbour is exceeding range of region set
  508. ! ! neighbour = current cell (i.e. no interpolation)
  509. ! ! in case of cyclic x-boundaries take corresponding cyclic i index
  510. ! !=================================================================
  511. ! if ( jsn < 1) jsn=1
  512. ! if ( jsn > jm(region) ) jsn=jm(region) ! isn-->jsn (wouter Peters)
  513. ! if ( xcyc(region) == 0 ) then
  514. ! ! non-cyclic boundaries
  515. ! if ( isn < 1) isn=1
  516. ! if ( isn > im(region) ) isn=im(region)
  517. ! else
  518. ! ! cyclic x-boundaries
  519. ! if ( isn < 1 ) isn=im(region)
  520. ! if ( isn > im(region) ) isn=1
  521. ! end if
  522. ! ! interpolate the altitude to site position...
  523. ! ls = 1 !layer
  524. ! do l=0,lm(region)
  525. ! height(l) = wcx * wcy* gph(is,js,l+1) + &
  526. ! (1.0-wcx)* wcy* gph(isn,js,l+1) + &
  527. ! wcx *(1.0-wcy)* gph(is,jsn,l+1) + &
  528. ! (1.0-wcx)*(1.0-wcy)* gph(isn,jsn,l+1)
  529. ! enddo
  530. ! do l=2,lm(region) ! selects layer , note that we start from second layer from surface
  531. ! if(height(l).gt.falt) exit
  532. ! enddo
  533. ! select case(l)
  534. ! case(0)
  535. ! if(myid==root) print*,'get_noaa: Warning..., forecast altitude ',&
  536. ! 'is below the surface height',height(0),' > ',falt,concentration(n)%ident
  537. ! ls = 1
  538. ! rls = -0.5 !surface...
  539. ! case default
  540. ! ls = l !the site layer
  541. ! ! the off-set from the center of the layer (-0.5--->+0.5)
  542. ! ! (interpolation is in (m))
  543. ! rls = (falt-height(l-1))/(height(l)-height(l-1)) - 0.5
  544. ! end select
  545. ! !=================================
  546. ! !the neighbour for z interpolation
  547. ! !=================================
  548. ! if ( rls .gt. 0 ) then
  549. ! lsn = ls+1
  550. ! else
  551. ! lsn = ls-1
  552. ! end if
  553. ! ! z-weighting of grid cell in which station is located
  554. ! wcz = (1.0-abs(rls)) !.0 ... 0.5
  555. ! !=========================================================
  556. ! ! if vertical neighbor is 0 (which does not exist)
  557. ! ! take vertical layer with l=2 for EXTRApolation to ground
  558. ! !=========================================================
  559. ! IF(lsn == 0) THEN
  560. ! lsn=2
  561. ! wcz=1.0-rls ! 1.0 ... 1.5
  562. ! ENDIF
  563. ! IF(lsn == lmr+1) THEN
  564. ! !=========================================================
  565. ! ! if vertical neighbor is lmr+1 (which does not exist)
  566. ! ! -> no interpolation
  567. ! !=========================================================
  568. ! lsn=lmr ! no interpolation
  569. ! wcz=1.0
  570. ! ENDIF
  571. ! !from is,js,ls, ris,rjs,rls, determine the mixing ratio of each tracer ...
  572. ! do j=1,ntracetloc
  573. ! ! rm-value is obtained from rm + slopes.
  574. ! ! slope = rxm = (rm*dX/dx *deltaX/2)
  575. ! ! For EnKF forward, not sure that sum over a zero
  576. ! ! length subarray works properly. Let's be specific
  577. ! ! anyway.
  578. ! offsetj = sum(ntracet_ar(0:myid-1))
  579. ! rmf = ( rm(is,js,ls,j) + &
  580. ! 2.0*(ris*rxm(is,js,ls,j) + &
  581. ! rjs*rym(is,js,ls,j) + &
  582. ! rls*rzm(is,js,ls,j) ) )/m(is,js,ls)*fscale(offsetj+j)
  583. ! concentration(n)%mmix(offsetj+j)=concentration(n)%mmix(offsetj+j)+rmf !*fscale(offsetj+j)
  584. ! enddo
  585. ! concentration(n)%n_accumulate=concentration(n)%n_accumulate+1
  586. ! concentration(n)%weight=concentration(n)%weight + this_weight
  587. ! !! if(myid==root) then
  588. ! ! print*,'DEBUG Check ',myid, concentration(n)%ident,concentration(n)%n_accumulate,concentration(n)%model(:)/concentration(n)%n_accumulate
  589. ! ! endif
  590. ! endif
  591. ! endif ! force/time
  592. ! enddo fcast_loop
  593. ! nullify(m)
  594. ! nullify(rm)
  595. ! nullify(rxm)
  596. ! nullify(rym)
  597. ! nullify(rzm)
  598. ! nullify(gph)
  599. end subroutine get_noaa
  600. ! subroutine evaluate_noaa
  601. ! ! convert concentrations to ppm and average over n_accumulate
  602. ! integer :: n
  603. ! do n=1,ntracet
  604. ! where(concentration%n_accumulate.ge.1) &
  605. ! concentration%mmix(n)=1.e6*concentration%mmix(n)/concentration%weight
  606. ! enddo
  607. ! end subroutine evaluate_noaa
  608. end module user_output_noaa