m_get_mod_fld.f90 5.1 KB

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