mod_analysisfields.F90 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156
  1. !KAL -- this module allows us to fine-tune the fields
  2. !KAL -- we wish to include in the analysis. The new
  3. !KAL -- layout of the EnKF makes it possible to specify fields
  4. !KAL -- to analyze at run-time rather than at compile-time
  5. !KAL -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
  6. !KAL --
  7. !KAL -- Module variables:
  8. !KAL -- numfields - total number of fields to process
  9. !KAL -- fieldnames - the names of the fields we wish to analyze
  10. !KAL -- fieldlevel - the levels of the associated fields
  11. !KAL -- fieldtype - in which file the field can be found:
  12. !ckb -- 1: ice, 2: ocean, 3: ice parameter,
  13. !ckb -- 4: ocean parameter
  14. !KAL --
  15. !KAL -- Ex: If we only want to assimilate temperatures in layer
  16. !KAL -- one and two, numfields, fieldnames and fieldlevel
  17. !KAL -- would look like:
  18. !KAL --
  19. !KAL -- numfields=2
  20. !KAL -- fieldnames (1)='temp', fieldnames (2)='temp'
  21. !KAL -- fieldlevel (1)= 1, fieldlevel (2)=2 (???)
  22. !ckb -- fieldtype (1)= 2, fieldtype (2)=2
  23. !KAL -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
  24. !KAL -- The file "analysisfields.in" specifies the fields to
  25. !KAL -- inlude in the analysis. Format of one line is fieldname
  26. !ckb -- first layer, last layer and fieldtype. For example:
  27. !KAL --
  28. !KAL -- fieldname 1 31 1
  29. !KAL -- 12345678901234567890123456789012345678901234567890
  30. !KAL --
  31. !KAL -- Fortran format for one line is '(a14,3i3)'
  32. !KAL --
  33. !KAL -- Example: to specify that we want temperature and salinity
  34. !ckb -- in layers 1-31 (ocean variables, type 2) to be
  35. !ckb -- updated, as well as ice concentration (layer 0,
  36. !ckb -- type 1), and the atmosphere-ice-drag coefficient,
  37. !ckb -- specify:
  38. !ckb --
  39. !ckb -- a_i_htc1 0 0 1
  40. !ckb -- v_i_htc1 0 0 1
  41. !ckb -- tempt_il3_htc5 0 0 1
  42. !ckb -- ub 1 31 2
  43. !ckb -- vb 1 31 2
  44. !ckb -- cai 0 0 3
  45. !KAL -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
  46. ! [FM,CKB] Changed to allow for column "parameter"
  47. module mod_analysisfields
  48. character(len=*), parameter :: infile='analysisfields.in'
  49. integer,save :: numfields
  50. character(len=14), dimension(:), save, allocatable:: fieldnames
  51. integer , dimension(:), save, allocatable:: fieldlevel
  52. integer , dimension(:), save, allocatable:: fieldtype
  53. contains
  54. integer function get_nrfields()
  55. #if defined (QMPI)
  56. use qmpi
  57. #else
  58. use qmpi_fake
  59. #endif
  60. implicit none
  61. integer :: ios,first,last,type
  62. logical :: ex
  63. character(len=14) :: char14
  64. inquire(exist=ex,file=infile)
  65. if (.not. ex) then
  66. if (master) print *,'Could not find '//infile
  67. call stop_mpi()
  68. end if
  69. open(10,status='old',form='formatted',file=infile)
  70. ios=0
  71. get_nrfields=0
  72. do while (ios==0)
  73. read(10,100,iostat=ios) char14,first,last,type
  74. if (ios==0) get_nrfields=get_nrfields+last-first+1
  75. end do
  76. close(10)
  77. 100 format (a14,3i3)
  78. end function
  79. subroutine get_analysisfields()
  80. #if defined (QMPI)
  81. use qmpi
  82. #else
  83. use qmpi_fake
  84. #endif
  85. implicit none
  86. integer :: first,last,type,k,nfld,ios
  87. logical :: ex
  88. character(len=14) :: char14
  89. numfields=get_nrfields()
  90. if (master) print *,'numfields is ',numfields
  91. if (numfields<=0 .or.numfields > 18000) then ! FM I Changed 600 to 18000
  92. if (master) print *,'(get_analysisfields) numfields is higher than max allowed setting or = 0'
  93. call stop_mpi()
  94. end if
  95. allocate(fieldnames(numfields))
  96. allocate(fieldlevel(numfields))
  97. allocate(fieldtype(numfields))
  98. inquire(exist=ex,file=infile)
  99. if (.not. ex) then
  100. if (master) print *,'Could not find '//infile
  101. call stop_mpi()
  102. end if
  103. open(10,status='old',form='formatted',file=infile)
  104. ios=0
  105. nfld=0
  106. do while (ios==0)
  107. read(10,100,iostat=ios) char14,first,last,type
  108. if (ios==0) then
  109. do k=first,last
  110. fieldnames (nfld+k-first+1)=char14
  111. fieldlevel (nfld+k-first+1)=k
  112. fieldtype (nfld+k-first+1)=type
  113. end do
  114. nfld=nfld+last-first+1
  115. end if
  116. end do
  117. close(10)
  118. 100 format (a14,3i3)
  119. if (nfld/=numfields) then
  120. if (master) print *,'An error occured when reading '//infile
  121. call stop_mpi()
  122. end if
  123. ! List fields used in analysis
  124. print *, "(mod_analysisfields) Fields used in analysis:"
  125. print *, "(mod_analysisfields) --- removed to reduce output ---"
  126. !do k=1,numfields
  127. ! if (master) print *,fieldnames(k),fieldlevel(k),fieldtype(k)
  128. !end do
  129. end subroutine
  130. end module mod_analysisfields