m_read_metno_icec.F90 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215
  1. module m_read_metno_icec
  2. contains
  3. subroutine read_metno_icec_repro(fname, data, gr)
  4. use nfw_mod
  5. use mod_measurement
  6. use mod_grid
  7. implicit none
  8. character(*), intent(in) :: fname
  9. type (measurement), allocatable, intent(out) :: data(:)
  10. type(grid), intent(out) :: gr
  11. logical :: ex
  12. integer :: ncid
  13. integer :: xc_id, yc_id
  14. integer :: nx, ny
  15. integer :: lon_id, lat_id, icec_id, std_id, flag_id
  16. real, allocatable :: lon(:,:), lat(:,:), icec(:,:), std(:, :)
  17. integer, allocatable :: flag(:,:)
  18. integer :: i, j, nobs
  19. print *, 'reading "', trim(fname), '"...'
  20. inquire(file = trim(fname), exist = ex)
  21. if (.not. ex) then
  22. print *, 'ERROR: file "', trim(fname), '" not found'
  23. stop
  24. end if
  25. call nfw_open(fname, nf_nowrite, ncid)
  26. call nfw_inq_dimid(fname, ncid, 'xc', xc_id)
  27. call nfw_inq_dimid(fname, ncid, 'yc', yc_id)
  28. call nfw_inq_dimlen(fname, ncid, xc_id, nx)
  29. call nfw_inq_dimlen(fname, ncid, yc_id, ny)
  30. print *, ' nx = ', nx
  31. print *, ' ny = ', ny
  32. allocate(lon(nx, ny))
  33. allocate(lat(nx, ny))
  34. allocate(icec(nx, ny))
  35. allocate(std(nx, ny))
  36. allocate(flag(nx, ny))
  37. call nfw_inq_varid(fname, ncid, 'lon', lon_id)
  38. call nfw_inq_varid(fname, ncid, 'lat', lat_id)
  39. call nfw_inq_varid(fname, ncid, 'ice_conc', icec_id)
  40. call nfw_inq_varid(fname, ncid, 'standard_error', std_id)
  41. call nfw_inq_varid(fname, ncid, 'status_flag', flag_id)
  42. call nfw_get_var_double(fname, ncid, lon_id, lon)
  43. call nfw_get_var_double(fname, ncid, lat_id, lat)
  44. call nfw_get_var_double(fname, ncid, icec_id, icec)
  45. call nfw_get_var_double(fname, ncid, std_id, std)
  46. call nfw_get_var_int(fname, ncid, flag_id, flag)
  47. call nfw_close(fname, ncid)
  48. print *, 'filling the measurements array...'
  49. allocate(data(nx * ny))
  50. ! 0.995 is the max allowed by the model
  51. where (9950.0d0 <= icec .and. icec <= 10000.d0)
  52. icec = 9950.0d0
  53. end where
  54. nobs = 0
  55. do j = 1, ny
  56. do i = 1, nx
  57. nobs = nobs + 1
  58. if (flag(i, j) /= 0) then
  59. data(nobs) % status = .false.
  60. cycle
  61. end if
  62. data(nobs) % id = 'ICEC'
  63. data(nobs) % d = icec(i, j) * 1d-4
  64. data(nobs) % var = max(1d-8 * std(i, j) ** 2, 0.01d0 + (0.5d0 - abs(0.5d0 - data(nobs) % d)) ** 2)
  65. data(nobs) % ipiv = i
  66. data(nobs) % jpiv = j
  67. data(nobs) % lon = lon(i, j)
  68. data(nobs) % lat = lat(i, j)
  69. data(nobs) % a1 = 1e10
  70. data(nobs) % a2 = 1e10
  71. data(nobs) % a3 = 1e10
  72. data(nobs) % a4 = 1e10
  73. data(nobs) % ns = 1
  74. data(nobs) % date = 0
  75. data(nobs) % depth = 0.0
  76. data(nobs) % status = .true.
  77. end do
  78. end do
  79. print *, ' ', nobs, 'primary ICEC observations'
  80. print *, ' ', minval(data % d), ' <= icec <= ', maxval(data % d)
  81. gr = default_grid
  82. gr % nx = nx
  83. gr % ny = ny
  84. gr%reg = .true.
  85. gr % order = 2
  86. gr%ux = '10 km'
  87. gr%uy = '10 km'
  88. gr%set = .true.
  89. deallocate(lat, lon, icec, std, flag)
  90. end subroutine read_metno_icec_repro
  91. subroutine read_metno_icec_norepro(fname, data, gr)
  92. use nfw_mod
  93. use mod_measurement
  94. use mod_grid
  95. implicit none
  96. character(*), intent(in) :: fname
  97. type (measurement), allocatable, intent(out) :: data(:)
  98. type(grid), intent(out) :: gr
  99. logical :: ex
  100. integer :: ncid
  101. integer :: xc_id, yc_id
  102. integer :: nx, ny
  103. integer :: lon_id, lat_id, icec_id, cfl_id, flag_id
  104. real, allocatable :: lon(:,:), lat(:,:), icec(:,:), cfl(:, :)
  105. integer, allocatable :: flag(:,:)
  106. integer :: i, j, nobs
  107. print *, 'reading "', trim(fname), '"...'
  108. inquire(file = trim(fname), exist = ex)
  109. if (.not. ex) then
  110. print *, 'ERROR: file "', trim(fname), '" not found'
  111. stop
  112. end if
  113. call nfw_open(fname, nf_nowrite, ncid)
  114. call nfw_inq_dimid(fname, ncid, 'xc', xc_id)
  115. call nfw_inq_dimid(fname, ncid, 'yc', yc_id)
  116. call nfw_inq_dimlen(fname, ncid, xc_id, nx)
  117. call nfw_inq_dimlen(fname, ncid, yc_id, ny)
  118. print *, ' nx = ', nx
  119. print *, ' ny = ', ny
  120. allocate(lon(nx, ny))
  121. allocate(lat(nx, ny))
  122. allocate(icec(nx, ny))
  123. allocate(cfl(nx, ny))
  124. allocate(flag(nx, ny))
  125. call nfw_inq_varid(fname, ncid, 'lon', lon_id)
  126. call nfw_inq_varid(fname, ncid, 'lat', lat_id)
  127. call nfw_inq_varid(fname, ncid, 'ice_conc', icec_id)
  128. call nfw_inq_varid(fname, ncid, 'confidence_level', cfl_id)
  129. call nfw_inq_varid(fname, ncid, 'status_flag', flag_id)
  130. call nfw_get_var_double(fname, ncid, lon_id, lon)
  131. call nfw_get_var_double(fname, ncid, lat_id, lat)
  132. call nfw_get_var_double(fname, ncid, icec_id, icec)
  133. call nfw_get_var_double(fname, ncid, cfl_id, cfl)
  134. call nfw_get_var_int(fname, ncid, flag_id, flag)
  135. call nfw_close(fname, ncid)
  136. print *, 'filling the measurements array...'
  137. allocate(data(nx * ny))
  138. ! 0.995 is the max allowed by the model
  139. where (9950.0d0 <= icec .and. icec <= 10000.d0)
  140. icec = 9950.0d0
  141. end where
  142. nobs = 0
  143. do j = 1, ny
  144. do i = 1, nx
  145. nobs = nobs + 1
  146. if (flag(i, j) /= 0 .OR. cfl(i,j) < 4) then
  147. data(nobs) % status = .false.
  148. cycle
  149. end if
  150. data(nobs) % id = 'ICEC'
  151. data(nobs) % d = icec(i, j) * 1d-4
  152. if (cfl(i,j)==4) then
  153. data(nobs) % var = 0.25d0
  154. else if (cfl(i,j) == 5 ) then
  155. data(nobs) % var = 0.01d0
  156. end if
  157. ! data(nobs) % var = 0.01d0 + (0.5d0 - abs(0.5d0 - data(nobs) % d)) ** 2
  158. data(nobs) % ipiv = i
  159. data(nobs) % jpiv = j
  160. data(nobs) % lon = lon(i, j)
  161. data(nobs) % lat = lat(i, j)
  162. data(nobs) % a1 = 1e10
  163. data(nobs) % a2 = 1e10
  164. data(nobs) % a3 = 1e10
  165. data(nobs) % a4 = 1e10
  166. data(nobs) % ns = 1
  167. data(nobs) % date = 0
  168. data(nobs) % depth = 0.0
  169. data(nobs) % status = .true.
  170. end do
  171. end do
  172. print *, ' ', nobs, 'primary ICEC observations'
  173. print *, ' ', minval(data % d), ' <= icec <= ', maxval(data % d)
  174. gr = default_grid
  175. gr % nx = nx
  176. gr % ny = ny
  177. gr%reg = .true.
  178. gr % order = 2
  179. gr%ux = '10 km'
  180. gr%uy = '10 km'
  181. gr%set = .true.
  182. deallocate(lat, lon, icec, cfl, flag)
  183. end subroutine read_metno_icec_norepro
  184. end module m_read_metno_icec