MObsRead.F90 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145
  1. ! First include the set of model-wide compiler flags
  2. #include "tm5.inc"
  3. module MObsRead
  4. ! --------------------------------------------------------------------
  5. !
  6. ! This module reads TROPOMI NO2 data,
  7. !
  8. ! Mark ter Linden, KNMI, sep 2015
  9. !---------------------------------------------------------------------
  10. use MTObsTrack
  11. use datetime, only : date2tau, tau2date
  12. use TM5IF_module, only : TM5IF_select, TM5IF_obstrack_read
  13. use TM5IF_module, only : TM5IF_log_error, FILENAME_LEN
  14. use TM5IF_module, only : TM5IF_date, TM5IF_time_init
  15. implicit none
  16. !
  17. private
  18. !
  19. public :: ObsFileGet
  20. ! Store list of orbit file names here
  21. character(FILENAME_LEN), dimension(:), allocatable :: filenamelist
  22. integer :: filenameindex
  23. integer :: nfiles
  24. ! Only read list of filenames at start
  25. logical :: firstcall_mobsread = .true.
  26. contains
  27. subroutine ObsFileGet( listfilename, itau1, itau2, obsTrack, dataFound)
  28. !--------------------------------------------------------------
  29. ! Returns the retrieved level-2 TROPOMI data with mean orbit time between
  30. ! "itau1" and "itau2" and stores the result in "obsTrack".
  31. !
  32. ! input:
  33. ! listfilename = the file which contains a list of TROPOMI L2 NO2 files
  34. ! itau1 = time in TM5 seconds, start of model time interval
  35. ! itau2 = time in TM5 seconds, end of model time interval
  36. ! output:
  37. ! obsTrack = structure containing the TROPOMI L2 file read by this routine
  38. ! If no tracks are found, then "dataFound" will be set to .false.
  39. !
  40. ! NOTE: the tracks in the HDF file are assumed to be stored in
  41. ! chronological order. This allows to start checking the vdata's
  42. ! from the last one that has been read.
  43. ! --------------------------------------------------------------
  44. implicit none
  45. character(*), intent(in) :: listfilename
  46. integer, intent(in) :: itau1, itau2
  47. type(TObsTrack),intent(inout) :: obsTrack
  48. logical,intent(out) :: dataFound
  49. integer :: idt1(6),idt2(6)
  50. character(FILENAME_LEN) :: line
  51. integer :: fileunit, ifl
  52. integer :: status, IOstatus
  53. integer :: before_or_after
  54. type(TM5IF_date) :: time_start, time_stop
  55. datafound = .false.
  56. call tau2date(itau1,idt1) ; call tau2date(itau2,idt2)
  57. write(*,'(2(a,i4,"/",i2.2,"/",i2.2,x,i2.2,":",i2.2,":",i2.2))') ' ObsFileGet: itau1 ',idt1,' itau2 ',idt2
  58. call TM5IF_time_init(time_start, idt1(1), idt1(2), idt1(3), idt1(4), idt1(5), idt1(6))
  59. call TM5IF_time_init(time_stop, idt2(1), idt2(2), idt2(3), idt2(4), idt2(5), idt2(6))
  60. obstrack%count = 0
  61. obstrack%norbitparts = 0
  62. ! Read the list with orbit file names at start
  63. if ( firstcall_mobsread ) then
  64. fileunit = 13867
  65. open(unit=fileunit, file=trim(listfilename), iostat=status)
  66. if ( status /= 0 ) then
  67. call TM5IF_log_error("Failed to open '" // trim(listfilename) // "'")
  68. stop
  69. end if
  70. nfiles = 0
  71. do
  72. read(fileunit, '(A)', iostat=IOstatus) line
  73. if ( IOstatus /= 0 ) exit
  74. nfiles = nfiles + 1
  75. end do
  76. close(fileunit);
  77. print '(a,i5,a)', ' List file contains ',nfiles,' file names'
  78. ! create storage
  79. allocate ( filenamelist(nfiles) )
  80. ! Open once more ..
  81. open(unit=fileunit, file=trim(listfilename), iostat=status)
  82. ! .. and read file names
  83. ifl = 0
  84. do
  85. read(fileunit, '(A)', iostat=IOstatus) line
  86. if ( IOstatus /= 0 ) exit
  87. ifl = ifl + 1
  88. filenamelist(ifl) = line
  89. end do
  90. close(fileunit);
  91. ! This is done only at start of the run
  92. firstcall_mobsread = .false.
  93. ! start with inquiry of first file
  94. filenameindex = 1
  95. end if
  96. ! code below is done every time step
  97. do
  98. ! when last file has been checked: leave
  99. if ( filenameindex > nfiles ) exit
  100. ! check if file is within the time interval
  101. print *,' checking ',trim(filenamelist(filenameindex))
  102. call TM5IF_select ( trim(filenamelist(filenameindex)), time_start, time_stop, obstrack, before_or_after )
  103. if ( before_or_after >= 0 ) exit
  104. ! -1 : orbit time before time interval, try next file
  105. filenameindex = filenameindex + 1
  106. end do
  107. ! read only when data is found for this time interval
  108. if ( obstrack%norbitparts > 0 ) then
  109. call TM5IF_obstrack_read(obstrack)
  110. ! this file is done, move to next
  111. filenameindex = filenameindex + 1
  112. end if
  113. dataFound = obstrack%count /= 0
  114. if ( .not. dataFound ) print *,' ObsFileGet: no data found for this time interval'
  115. end subroutine ObsFileGet
  116. end module MObsRead