m_read_amsr_norsex.F90 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175
  1. ! File: m_read_amsr_norsex.F90
  2. !
  3. ! Created: ???
  4. !
  5. ! Last modified: 29/06/2010
  6. !
  7. ! Purpose: Reads ICEC data
  8. !
  9. ! Description:
  10. !
  11. ! Modifications:
  12. ! 29/06/2010 PS:
  13. ! - set the maximum ICEC to 0.995 to match the model
  14. ! Prior history:
  15. ! Not documented.
  16. module m_read_amsr_norsex
  17. ! Reads amsr icec from NERSC (norsex)
  18. ! This will only work for northern hemisphere data - some minor corrections
  19. ! are needed for SH data
  20. integer, parameter, private :: STRLEN = 512
  21. contains
  22. subroutine read_amsr_norsex(fname,gr,data,obstype)
  23. use mod_grid
  24. use mod_measurement
  25. implicit none
  26. type (grid), intent(out) :: gr
  27. character(len=*) ,intent(in) :: fname
  28. type(measurement), allocatable, intent(out) :: data(:)
  29. character(len=5) ,intent(in) :: obstype
  30. integer :: i, j,k, rlen
  31. integer*1, allocatable :: iofldi1(:,:)
  32. integer*4, allocatable :: iofldi4(:,:)
  33. real *4, allocatable, dimension(:,:) :: lon,lat,icec
  34. logical :: ex(3)
  35. ! The grid stuff should be made more consistent - KAL
  36. gr = default_grid
  37. gr%undef=120.
  38. gr%nx=608
  39. gr%ny=896
  40. gr%order=2
  41. gr%ux='12.5 km' !Roughly
  42. gr%uy='12.5 km' !Roughly
  43. gr%set=.true.
  44. print '(a,3e14.3)','undef : ', gr%undef
  45. print *,' No of gridpoints: ', gridpoints(gr)
  46. ! Test for input files:
  47. inquire(exist=ex(1),file='psn12lons_v2.dat')
  48. inquire(exist=ex(2),file='psn12lats_v2.dat')
  49. inquire(exist=ex(3),file=trim(fname))
  50. if (any(.not.ex)) then
  51. print *,'A file is missing:'
  52. print *,'File flag: ',ex(1),' - name: psn12lons_v2.dat'
  53. print *,'File flag: ',ex(2),' - name: psn12lats_v2.dat'
  54. print *,'File flag: ',ex(3),' - name: '//trim(fname)
  55. print *,'(read_amsr_norsex)'
  56. call exit(1)
  57. end if
  58. ! Allocate fields and read input data
  59. allocate(icec (gr%nx,gr%ny))
  60. allocate(lon (gr%nx,gr%ny))
  61. allocate(lat (gr%nx,gr%ny))
  62. allocate(iofldi1(gr%nx,gr%ny))
  63. allocate(iofldi4(gr%nx,gr%ny))
  64. allocate(data (gr%nx*gr%ny))
  65. inquire(iolength=rlen) iofldi4
  66. open(10,file='psn12lons_v2.dat',status='old',form='unformatted',access='direct',recl=rlen)
  67. read(10,rec=1) iofldi4
  68. close(10)
  69. #if defined (LITTLE_ENDIAN) /* Lon/lat input files are big endian */
  70. do j=1,gr%ny
  71. do i=1,gr%nx
  72. call swapendian2(iofldi4(i,j),4)
  73. end do
  74. end do
  75. #endif
  76. lon = real(iofldi4,4) / 100000.0_4
  77. inquire(iolength=rlen) iofldi4
  78. open(10,file='psn12lats_v2.dat',status='old',form='unformatted',access='direct',recl=rlen)
  79. read(10,rec=1) iofldi4
  80. close(10)
  81. #if defined (LITTLE_ENDIAN) /* Lon/lat input files are big endian */
  82. do j=1,gr%ny
  83. do i=1,gr%nx
  84. call swapendian2(iofldi4(i,j),4)
  85. end do
  86. end do
  87. #endif
  88. lat = real(iofldi4, 4) / 100000.0_4
  89. inquire(iolength=rlen) iofldi1
  90. open(10,file=trim(fname),status='old',form='unformatted',access='direct',recl=rlen)
  91. read(10,rec=1) iofldi1
  92. close(10)
  93. icec=iofldi1
  94. where(icec>100)
  95. icec = real(gr % undef, 4)
  96. elsewhere
  97. icec = icec / 100.0_4
  98. !LB tighten observed pack ice
  99. !where (icec>0.9) icec = 1.0
  100. end where
  101. ! PS 25/06/2010 0.995 is the max allowed by the model
  102. where (0.995 <= icec .and. icec <= 1.0)
  103. icec = 0.995
  104. end where
  105. do j=1,gr%ny
  106. do i=1,gr%nx
  107. k=(j-1)*gr%nx +i
  108. data(k)%id = obstype
  109. data(k)%d = icec(i,j)
  110. data(k)%jpiv = j
  111. data(k)%ipiv = i
  112. data(k)%lon=lon(i,j)
  113. data(k)%lat=lat(i,j)
  114. !LB: Data support is assumed = a square grid cell
  115. !support diameter stored in %a1 (tricky, isn't it ?)
  116. data(k)%a1 = 12500. *sqrt(2.) ! AMSR-E grid diagonal
  117. data(k)%ns = 1 ! 1 for obs with a spatial extent
  118. data(k)%status = .not. undefined(data(k)%d,gr) ! active data
  119. ! PS 17.06.2010 - increased obs error at the ice edge
  120. ! data(k)%var = 0.01 ! KAL 10%
  121. data(k) % var = 0.01d0 + (0.5d0 - abs(0.5d0 - icec(i,j))) ** 2
  122. data(k) % depth = 0.0
  123. end do
  124. end do
  125. call icec2nc(gr % nx, gr % ny, icec, lon, lat)
  126. end subroutine read_amsr_norsex
  127. subroutine icec2nc(ni, nj, icec, lon, lat)
  128. use nfw_mod
  129. integer, intent(in) :: ni
  130. integer, intent(in) :: nj
  131. real*4, intent(in) :: icec(ni, nj), lon (ni, nj), lat(ni, nj)
  132. character(STRLEN) :: fname
  133. integer :: ncid
  134. integer :: nij_id(2), icec_id, lon_id, lat_id
  135. fname = 'icec.nc';
  136. call nfw_create(fname, nf_clobber, ncid)
  137. call nfw_def_dim(fname, ncid, 'ni', ni, nij_id(1));
  138. call nfw_def_dim(fname, ncid, 'nj', nj, nij_id(2));
  139. call nfw_def_var(fname, ncid, 'icec', nf_float, 2, nij_id, icec_id)
  140. call nfw_def_var(fname, ncid, 'lon', nf_float, 2, nij_id, lon_id)
  141. call nfw_def_var(fname, ncid, 'lat', nf_float, 2, nij_id, lat_id)
  142. call nfw_enddef(fname, ncid)
  143. call nfw_put_var_real(fname, ncid, icec_id, icec)
  144. call nfw_put_var_real(fname, ncid, lon_id, lon)
  145. call nfw_put_var_real(fname, ncid, lat_id, lat)
  146. call nfw_close(fname, ncid)
  147. end subroutine icec2nc
  148. end module m_read_amsr_norsex