m_read_icemod.F90 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. MODULE m_read_icemod
  2. ! Francois Massonnet, UCL, 2013
  3. ! Reads data from icemod file (instead of classically restart files).
  4. ! This is required when doing data assimilation of OSISAF sea ice drift
  5. ! computed over several hours/days. Indeed, the restart only gives a
  6. ! snapshot of the state of the system while the icemod records the time
  7. ! average. The icemod file should have one time slice.
  8. USE NETCDF
  9. #if defined (QMPI)
  10. use qmpi
  11. #else
  12. use qmpi_fake
  13. #endif
  14. CONTAINS
  15. SUBROUTINE read_icemod(fld,k,enslist,cfld,nx,ny)
  16. IMPLICIT NONE
  17. real,dimension(nx,ny),intent(inout):: fld ! output fl
  18. character(len=*), intent(in) :: cfld ! name of fld
  19. integer, intent(in) :: k ! Index to enslist
  20. integer,dimension(:), intent(in) :: enslist! List of existing ensemble members
  21. integer, intent(in) :: nx,ny ! Grid dimension
  22. integer :: iens
  23. integer :: error, ncid,varID
  24. character(len=3) :: cmem
  25. character(len=99) :: cfile
  26. logical :: exf
  27. iens = enslist(k)
  28. write(cmem,'(i3.3)') 100+iens ! iens=1 gives cmem = 101
  29. cfile='icemod_'//cmem//'.nc'
  30. inquire(file=cfile, exist=exf)
  31. if (.not.exf) then
  32. if (master) print *, '(read_icemod): Icemod file '//cfile//' missing!'
  33. call stop_mpi()
  34. end if
  35. error = nf90_open(trim(cfile),nf90_Write,ncid); if (error.ne.nf90_noerr) call handle_err(error, "opening")
  36. error = nf90_inq_varid(ncid, trim(cfld), varID); if (error.ne.nf90_noerr) call handle_err(error, "inquiring varID")
  37. error = nf90_get_var(ncid, varID, fld); if (error.ne.nf90_noerr) call handle_err(error, "getting 2D variable")
  38. END SUBROUTINE read_icemod
  39. subroutine handle_err(status, infomsg)
  40. integer, intent ( in) :: status
  41. character(len = *), intent ( in), optional :: infomsg
  42. if(status /= nf90_noerr) then
  43. if (master) then
  44. if (present(infomsg)) then
  45. print *, 'Error while '//infomsg//' - '//trim(nf90_strerror(status))
  46. else
  47. print *, trim(nf90_strerror(status))
  48. endif ! opt arg
  49. print *,'(io_mod_fld)'
  50. endif ! only master outputs
  51. call stop_mpi()
  52. end if ! check error status
  53. end subroutine handle_err
  54. END MODULE m_read_icemod