m_get_mod_nrens.f90 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  1. # 0 "<stdin>"
  2. # 0 "<built-in>"
  3. # 0 "<command-line>"
  4. # 1 "/usr/include/stdc-predef.h" 1 3 4
  5. # 17 "/usr/include/stdc-predef.h" 3 4
  6. # 2 "<command-line>" 2
  7. # 1 "<stdin>"
  8. # 10 "<stdin>"
  9. module m_get_mod_nrens
  10. ! Finds how many ensemble members there are by counting ocean
  11. ! and ice restart files.
  12. !
  13. ! If an optional integer vector 'enslist' is submitted, the
  14. ! numbers of the 'still living' members is returned.
  15. !
  16. use qmpi, only : stop_mpi, master
  17. contains
  18. subroutine get_mod_nrens(nrens, enslist)
  19. implicit none
  20. ! In/out
  21. integer, intent(inout) :: nrens
  22. integer, dimension(:), intent(out), optional :: enslist
  23. ! Local variables
  24. logical ex
  25. integer iens ! loop var
  26. character(len=3) :: cens ! contains '1xx' of member
  27. character(len=99) :: path2mod='./' ! should model output be somewhere else
  28. integer :: maxnrens=899 ! max nr of members we're looking for
  29. integer nrice ! ice file counter
  30. ! restart files will have been moved to path2mod and be called
  31. ! 'forecast_ice_XXX.nc' where XXX is the enseble identifier (101-)
  32. ! Count members. Assumed nrens at most 1000.
  33. nrens = 0
  34. do iens=1,maxnrens
  35. write(cens,'(i3.3)') iens+100
  36. inquire(exist=ex,file=trim(path2mod)//'forecast_oce_'//cens//'.nc')
  37. if (ex) then
  38. nrens = nrens + 1
  39. if (present(enslist)) enslist(nrens) = iens
  40. end if
  41. end do
  42. ! Warn if arbitrary max. limit of nrens is reached.
  43. if ( ( nrens.eq.maxnrens ).and.(master) ) then
  44. print *,'WARNING:'
  45. print *,'WARNING: Ensemble sizes above ',maxnrens,' are not recognized.'
  46. print *,'WARNING: Adjust m_get_mod_nrens.F90 to go bigger.'
  47. ! Don't forget to adjust also length of cens.
  48. print *,'WARNING:'
  49. endif
  50. ! Count ice members. Assumed nrens at most maxnrens.
  51. nrice = 0
  52. do iens=1,maxnrens
  53. write(cens,'(i3.3)') iens+100
  54. inquire(exist=ex,file=trim(path2mod)//'forecast_ice_'//cens//'.nc')
  55. if (ex) nrice = nrice + 1
  56. end do
  57. if (nrice /= nrens) then
  58. if (master) then
  59. print *,'(get_mod_nrens) Error: Different number of ocean and ice restarts!!!'
  60. print *,'Ocean restarts : ',nrens
  61. print *,'Ice restarts : ',nrice
  62. end if
  63. call stop_mpi()
  64. end if
  65. end subroutine get_mod_nrens
  66. end module m_get_mod_nrens