m_get_mod_nrens.F90 2.3 KB

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