p_check_ice.F90 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  1. !Fanf A short program to ensure that all member have the ice present.
  2. !
  3. ! PS: if there are corrupted ic fields - then
  4. ! (i) the member IDs of these fields will be wrtten to the file
  5. ! "missing_icerecords.txt"
  6. ! (ii) this also will be reported to stdout
  7. ! (iii) and also will be reflected in icevolume.txt
  8. program checkice
  9. use mod_raw_io
  10. use m_parse_blkdat
  11. use m_get_mod_grid
  12. implicit none
  13. integer*4, external :: iargc
  14. integer iens
  15. real, dimension(:,:), allocatable :: modlon,modlat,depths
  16. logical, allocatable, dimension(:, :) :: iswater
  17. integer :: idm,jdm,kdm
  18. integer :: ios
  19. integer :: nens
  20. real*8, allocatable, dimension(:,:) :: ficem,hicem,hsnwm,ticem,tsrfm
  21. integer :: reclICE
  22. real :: mindx,meandx,rdummy
  23. character(len=80) :: icerestart
  24. character(len=3) :: ctmp
  25. integer :: nmissing
  26. real, allocatable, dimension(:) :: icevolume, icearea
  27. real :: meanicevolume, maxvalue_hicem, maxvalue_ticem, maxvalue_tsrfm
  28. if ( iargc()==2 ) then
  29. call getarg(1,icerestart)
  30. call getarg(2,ctmp)
  31. read(ctmp,*) nens
  32. else
  33. print *,'"check_ice" -- A routine to check that no ice records are missing'
  34. print *
  35. print *,'Usage: checkice <ice_file> <ensemble_size>'
  36. call exit(1)
  37. endif
  38. open(20, file = trim(icerestart), iostat = ios)
  39. if (ios /= 0) then
  40. print *, 'ERROR: "', trim(icerestart), '" not found'
  41. call exit(1)
  42. end if
  43. close(20)
  44. allocate(icevolume(nens))
  45. allocate(icearea(nens))
  46. icevolume = 0.0d0
  47. icearea = 0.0d0
  48. !Get model dimensions
  49. call parse_blkdat('idm ','integer',rdummy,idm)
  50. call parse_blkdat('jdm ','integer',rdummy,jdm)
  51. allocate(modlon (idm,jdm))
  52. allocate(modlat (idm,jdm))
  53. allocate(depths (idm,jdm))
  54. call get_mod_grid(modlon, modlat, depths, mindx, meandx, idm, jdm)
  55. allocate(iswater(idm, jdm))
  56. iswater = depths > 1.0d0 .and. depths < 1.0e25
  57. allocate(ficem(idm,jdm))
  58. allocate(hicem(idm,jdm))
  59. allocate(hsnwm(idm,jdm))
  60. allocate(ticem(idm,jdm))
  61. allocate(tsrfm(idm,jdm))
  62. inquire(iolength = reclICE) ficem, hicem, hsnwm, ticem, tsrfm
  63. open(20, file = trim(icerestart), form = 'unformatted', access = 'direct',&
  64. recl = reclICE, status = 'old', iostat = ios)
  65. if (ios /= 0) then
  66. print *, 'ERROR: problem reading "', trim(icerestart), '"'
  67. call exit(1)
  68. end if
  69. open(11, file = 'icevolume.txt', status = 'replace')
  70. close(11)
  71. do iens=1,nens
  72. read(20, rec = iens, iostat = ios) ficem, hicem, hsnwm, ticem, tsrfm
  73. icevolume(iens) = sum(ficem * hicem, mask = iswater)
  74. icearea(iens) = sum(ficem, mask = iswater)
  75. end do
  76. meanicevolume = sum(icevolume) / real(nens)
  77. nmissing = 0
  78. do iens=1,nens
  79. read(20, rec = iens, iostat = ios) ficem, hicem, hsnwm, ticem, tsrfm
  80. maxvalue_hicem = maxval(hicem, mask = iswater) ! In meters
  81. maxvalue_ticem = maxval(ticem, mask = iswater) ! In Kelvin
  82. maxvalue_tsrfm = maxval(tsrfm, mask = iswater) ! In Kelvin
  83. if (maxvalue_hicem < 0.1 .or. maxvalue_hicem > 100.0 .or. &
  84. maxvalue_ticem < 10.0 .or. maxvalue_tsrfm < 10.0) then
  85. nmissing = nmissing + 1
  86. print '(A, $)', '-'
  87. open(10, file = 'missing_icerecords.txt', position = 'append')
  88. write(10, '(i4)') iens
  89. close(10)
  90. elseif (icevolume(iens) /= icevolume(iens) .or. (meanicevolume - icevolume(iens)) / meanicevolume > 0.35) then
  91. nmissing = nmissing + 1
  92. print '(A, $)', '*'
  93. print *, 'member ', iens, ': icevolume = ', icevolume(iens),&
  94. ', meanicevolume = ', meanicevolume
  95. open(10, file = 'missing_icerecords.txt', position = 'append')
  96. write(10, '(i4)') iens
  97. close(10)
  98. else
  99. print '(A, $)', '.'
  100. end if
  101. open(11, file = 'icevolume.txt', status = 'old', position = 'append')
  102. write(11, '(i4, f14.0, f14.0)') iens, icevolume(iens), icearea(iens)
  103. close(11)
  104. end do
  105. close(20)
  106. print *, ''
  107. if (nmissing > 0) then
  108. print *, 'ERROR: ice field is missing for', nmissing, ' member(s)',&
  109. ' check "missing_icerecords.txt" for member IDs'
  110. end if
  111. end program checkice