p_check_ice_en.F90 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  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_en
  9. use mod_raw_io
  10. use m_parse_blkdat
  11. use m_get_mod_grid
  12. use m_get_mod_fld
  13. implicit none
  14. integer*4, external :: iargc
  15. integer iens
  16. real, dimension(:,:), allocatable :: modlon,modlat,depths
  17. logical, allocatable, dimension(:, :) :: iswater
  18. integer :: idm,jdm,kdm
  19. integer :: ios
  20. integer :: nens
  21. real, allocatable, dimension(:,:) :: ficem,hicem,hsnwm,ticem,tsrfm
  22. real, allocatable, dimension(:,:) :: fld
  23. integer :: reclICE
  24. real :: mindx,meandx,rdummy
  25. character(len=80) :: icerestart,filename
  26. character(len=3) :: ctmp
  27. integer :: nmissing
  28. real, allocatable, dimension(:) :: icevolume, icearea
  29. real :: meanicevolume, maxvalue_hicem, maxvalue_ticem, maxvalue_tsrfm
  30. logical :: ex
  31. if ( iargc()==2 ) then
  32. call getarg(1,icerestart)
  33. call getarg(2,ctmp)
  34. read(ctmp,*) nens
  35. else
  36. print *,'"check_ice_en" -- A routine to check that no ice records are missing'
  37. print *
  38. print *,'Usage: checkice_en <surname of ice_file> <ensemble_size>'
  39. call exit(1)
  40. endif
  41. !Get model dimensions
  42. call parse_blkdat('idm ','integer',rdummy,idm)
  43. call parse_blkdat('jdm ','integer',rdummy,jdm)
  44. open(11, file = 'icevolume.txt', status = 'replace')
  45. close(11)
  46. allocate(modlon (idm,jdm))
  47. allocate(modlat (idm,jdm))
  48. allocate(depths (idm,jdm))
  49. allocate(fld (idm,jdm))
  50. call get_mod_grid(modlon, modlat, depths, mindx, meandx, idm, jdm)
  51. allocate(iswater(idm, jdm))
  52. iswater = depths > 1.0d0 .and. depths < 1.0e25
  53. allocate(icevolume(nens))
  54. allocate(icearea(nens))
  55. icevolume = 0.0d0
  56. icearea = 0.0d0
  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. ! to check the existing for the mem-file
  70. do iens=1,nens
  71. write(ctmp,'(i3.3)') iens
  72. filename=trim(icerestart)//trim(ctmp)
  73. print *,iens
  74. inquire(exist=ex,file=trim(filename)//'.b')
  75. if (.not.ex) then
  76. write(*,*) 'Can not find '//trim(filename)//'.b'
  77. stop '(EnKF_postprocess)'
  78. end if
  79. call get_mod_fld_new(trim(filename),fld(:,:),1,'ficem ',0,1,idm,jdm); ficem=fld;
  80. call get_mod_fld_new(trim(filename),fld(:,:),1,'hicem ',0,1,idm,jdm); hicem=fld;
  81. icevolume(iens) = sum(ficem * hicem, mask = iswater)
  82. icearea(iens) = sum(ficem, mask = iswater)
  83. end do
  84. open(11, file = 'icevolume.txt', status = 'old', position = 'append')
  85. do iens=1,nens
  86. write(11, '(i4, f14.0, f14.0)') iens, icevolume(iens), icearea(iens)
  87. end do
  88. close(11)
  89. meanicevolume = sum(icevolume) / real(nens)
  90. nmissing = 0
  91. do iens=1,nens
  92. write(ctmp,'(i3.3)') iens
  93. filename=trim(icerestart)//trim(ctmp)
  94. call get_mod_fld_new(trim(filename),fld(:,:),1,'hicem ',0,1,idm,jdm); hicem=fld;
  95. call get_mod_fld_new(trim(filename),fld(:,:),1,'ticem ',0,1,idm,jdm); ticem=fld;
  96. call get_mod_fld_new(trim(filename),fld(:,:),1,'tsrfm ',0,1,idm,jdm); tsrfm=fld;
  97. maxvalue_hicem = maxval(hicem, mask = iswater) ! In meters
  98. maxvalue_ticem = maxval(ticem, mask = iswater) ! In Kelvin
  99. maxvalue_tsrfm = maxval(tsrfm, mask = iswater) ! In Kelvin
  100. if (maxvalue_hicem < 0.1 .or. maxvalue_hicem > 100.0 .or. &
  101. maxvalue_ticem < 10.0 .or. maxvalue_tsrfm < 10.0) then
  102. nmissing = nmissing + 1
  103. print '(A, $)', '-'
  104. open(10, file = 'missing_icerecords.txt', position = 'append')
  105. write(10, '(i4)') iens
  106. close(10)
  107. elseif (icevolume(iens) /= icevolume(iens) .or. (meanicevolume - icevolume(iens)) / meanicevolume > 0.35) then
  108. nmissing = nmissing + 1
  109. print '(A, $)', '*'
  110. print *, 'member ', iens, ': icevolume = ', icevolume(iens),&
  111. ', meanicevolume = ', meanicevolume
  112. open(10, file = 'missing_icerecords.txt', position = 'append')
  113. write(10, '(i4)') iens
  114. close(10)
  115. else
  116. print '(A, $)', '.'
  117. end if
  118. end do
  119. ! close(20)
  120. print *, ''
  121. if (nmissing > 0) then
  122. print *, 'ERROR: ice field is missing for', nmissing, ' member(s)',&
  123. ' check "missing_icerecords.txt" for member IDs'
  124. end if
  125. end program checkice_en