m_get_mod_fld.F90 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145
  1. module m_get_mod_fld
  2. ! KAL -- This routine reads one of the fields from the model, specified
  3. ! KAL -- by name, vertical level and time level
  4. ! KAL -- This routine is really only effective for the new restart files.
  5. contains
  6. !~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  7. subroutine get_mod_fld(fld,j,cfld,vlevel,tlevel,nx,ny)
  8. #if defined (QMPI)
  9. use qmpi
  10. #else
  11. use qmpi_fake
  12. #endif
  13. implicit none
  14. integer, intent(in) :: nx,ny ! Grid dimension
  15. integer, intent(in) :: j ! Ensemble member to read
  16. real, dimension(nx,ny), intent(out) :: fld ! output fld
  17. character(len=*), intent(in) :: cfld ! name of fld
  18. integer, intent(in) :: tlevel ! time level
  19. integer, intent(in) :: vlevel ! vertical level
  20. integer reclICE
  21. real*8, dimension(nx,ny) :: ficem,hicem,hsnwm,ticem,tsrfm
  22. logical ex
  23. character(len=*),parameter :: icefile='forecastICE.uf'
  24. ! KAL -- shortcut -- the analysis is for observation icec -- this little "if"
  25. ! means the analysis will only work for ice. Add a check though
  26. if ((trim(cfld)/='icec' .and. trim(cfld)/='hice') .or. vlevel/=0 .or. tlevel/=1)then
  27. if (master) print *,'get_mod_fld only works for icec for now'
  28. call stop_mpi()
  29. end if
  30. !###################################################################
  31. !####################### READ ICE MODEL #########################
  32. !###################################################################
  33. #if defined (ICE)
  34. #warning "COMPILING WITH ICE"
  35. inquire(exist=ex,file=icefile)
  36. if (.not.ex) then
  37. if (master) then
  38. print *,icefile//' does not exist!'
  39. print *,'(get_mod_fld)'
  40. end if
  41. call stop_mpi()
  42. end if
  43. inquire(iolength=reclICE)ficem,hicem,hsnwm,ticem,tsrfm !,iceU,iceV
  44. open(10,file=icefile,form='unformatted',access='direct',recl=reclICE,action='read')
  45. read(10,rec=j)ficem,hicem,hsnwm,ticem,tsrfm !,iceU,iceV
  46. if (trim(cfld)=='icec') fld = ficem
  47. if (trim(cfld)=='hice') fld = hicem
  48. close(10)
  49. #else
  50. #warning "COMPILING WITHOUT ICE"
  51. #endif
  52. return
  53. end subroutine get_mod_fld
  54. ! KAL - This is for the new file type
  55. subroutine get_mod_fld_new(memfile,fld,iens,cfld,vlevel,tlevel,nx,ny)
  56. use mod_raw_io
  57. #if defined (QMPI)
  58. use qmpi, only : qmpi_proc_num, master
  59. #else
  60. use qmpi_fake
  61. #endif
  62. implicit none
  63. integer, intent(in) :: nx,ny ! Grid dimension
  64. integer, intent(in) :: iens ! Ensemble member to read
  65. real, dimension(nx,ny), intent(out) :: fld ! output fld
  66. character(len=*), intent(in) :: memfile! base name of input files
  67. character(len=*), intent(in) :: cfld ! name of fld
  68. integer, intent(in) :: tlevel ! time level
  69. integer, intent(in) :: vlevel ! vertical level
  70. real*8, dimension(nx,ny) :: readfldr8
  71. real*4, dimension(nx,ny) :: readfldr4
  72. real*4:: amin, amax,spval
  73. real :: bmin, bmax
  74. integer :: indx
  75. ! Dette fordi is-variablane forelobig er paa gammalt format.
  76. if (trim(cfld) /= 'icec' .and. trim(cfld) /= 'hice') then
  77. ! KAL - 1) f kva index som skal lesast finn vi fraa .b fil (header)
  78. call rst_index_from_header(trim(memfile)//'.b', & ! filnavn utan extension
  79. cfld , & ! felt som skal lesast fex saln,temp
  80. vlevel, & ! vertikalnivaa
  81. tlevel, & ! time level - kan vere 1 eller 2 - vi bruker 1 foreloepig
  82. indx, & ! indexen som maa lesas fra data fila
  83. bmin,bmax, & ! min/max - kan sjekkast mot det som er i datafila
  84. .true. )
  85. if (indx < 0) then
  86. if (master) then
  87. print *, 'ERROR: get_mod_fld_new(): ', trim(memfile), '.b: "',&
  88. trim(cfld), '" not found'
  89. end if
  90. stop
  91. end if
  92. ! KAL -- les datafelt vi fann fraa header fila (indx)
  93. spval=0.
  94. call READRAW(readfldr4 ,& ! Midlertidig felt som skal lesast
  95. amin, amax ,& ! max/min fraa data (.a) fila
  96. nx,ny ,& ! dimensjonar
  97. .false.,spval ,& ! dette brukast for sette "no value" verdiar
  98. trim(memfile)//'.a',& ! fil som skal lesast fraa
  99. indx) ! index funne over
  100. ! Sjekk p at vi har lest rett - samanlign max/min fr filene
  101. if (abs(amin-bmin).gt.abs(bmin)*1.e-4 .or. &
  102. abs(bmax-amax).gt.abs(bmax)*1.e-4 ) then
  103. print *,'Inconsistency between .a and .b files'
  104. print *,'.a : ',amin,amax
  105. print *,'.b : ',bmin,bmax
  106. print *,cfld,vlevel,tlevel
  107. print *,indx
  108. print *,'node ',qmpi_proc_num
  109. call exit(1)
  110. end if
  111. fld=readfldr4
  112. else ! fld = fice, hice
  113. ! Gammal rutine ja
  114. call get_mod_fld(readfldr8,iens,cfld,0,1,nx,ny)
  115. fld=readfldr8
  116. end if
  117. end subroutine
  118. end module m_get_mod_fld