comp_rhop.f90 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143
  1. program comp_rhop
  2. !
  3. ! =============================================================================
  4. !
  5. ! This program computes the potential density rhop based on the equation
  6. ! used in NEMO. Beware that the configuration is hard-coded. LX, LY
  7. ! LZ, LT need to be changed for each new configuration and the program
  8. ! needs to be recompiled with the makefile provided.
  9. !
  10. ! Usage ./comp_rhop with a namelist called namelist_rhop:
  11. ! &density
  12. ! input_file = ''
  13. ! input_Tvar = ''
  14. ! input_Svar = ''
  15. ! input_Dvar = ''
  16. ! outfile = ''
  17. ! /
  18. !
  19. ! History : Virginie Guemas - Initial version PhD tools - February 2008
  20. ! - Namelist and remove hard-coding - April 2014
  21. !
  22. ! =============================================================================
  23. !
  24. USE eosbn2 ! Routine from NEMO to compute rhop
  25. IMPLICIT NONE
  26. INCLUDE 'netcdf.inc'
  27. CHARACTER(80) :: &
  28. & input_file, & ! Input netcdf file name
  29. & input_Tvar, & ! Input netcdf potential temperature variable name
  30. & input_Svar, & ! Input netcdf salinity variable name
  31. & input_Dvar, & ! Input netcdf depth variable name
  32. & outfile ! Ouput netcdf file name
  33. NAMELIST/density/input_file,input_Tvar,input_Svar,input_Dvar,outfile
  34. INTEGER,PARAMETER :: inam=1
  35. INTEGER :: ncid, varid, istat
  36. INTEGER,DIMENSION(4) :: dimoutids
  37. INTEGER,PARAMETER :: LX=1442,LY=1021,LZ=46,LT=1
  38. ! These dimensions need to be changed also in eosbn2.f90 for each new
  39. ! configuration
  40. DOUBLE PRECISION,DIMENSION(LX,LY,LZ,LT) :: PT,PS
  41. DOUBLE PRECISION,DIMENSION(LZ) :: PD
  42. DOUBLE PRECISION,DIMENSION(LX,LY,LZ,LT) :: PRHO
  43. DOUBLE PRECISION,DIMENSION(LX,LY,LZ) :: MASK
  44. DOUBLE PRECISION,DIMENSION(LX,LY,LZ,LT) :: Zrho_smow,PO
  45. INTEGER :: JI,JJ,JK,JT
  46. !
  47. ! =============================================================================
  48. !
  49. ! Read the namelist
  50. ! ==================
  51. OPEN(UNIT=inam,FILE='namelist_rhop',FORM='FORMATTED',ACCESS=&
  52. &'SEQUENTIAL',STATUS='OLD',IOSTAT=istat)
  53. IF (istat /=0 ) THEN
  54. PRINT*,'IOSTAT = ',istat
  55. STOP"Problem opening namelist_rhop"
  56. END IF
  57. REWIND(inam)
  58. READ(UNIT=inam,NML=density)
  59. ! Read input thermodynamic fields
  60. ! =================================
  61. !
  62. istat = NF_OPEN (input_file,0,ncid )
  63. call check_stat(istat,'Opening input file')
  64. istat = NF_INQ_VARID(ncid,input_Tvar,varid)
  65. call check_stat(istat,'Finding input temperature variable')
  66. istat = NF_GET_VAR_DOUBLE(ncid,varid,PT)
  67. call check_stat(istat,'Reading input temperature')
  68. istat = NF_INQ_VARID(ncid,input_Svar,varid)
  69. call check_stat(istat,'Finding input salinity variable')
  70. istat = NF_GET_VAR_DOUBLE(ncid,varid,PS)
  71. call check_stat(istat,'Reading input temperature')
  72. istat = NF_INQ_VARID(ncid,input_Dvar,varid)
  73. call check_stat(istat,'Finding input depth variable')
  74. istat = NF_GET_VAR_DOUBLE(ncid,varid,PD)
  75. call check_stat(istat,'Reading input depth')
  76. istat = NF_CLOSE ( ncid )
  77. call check_stat(istat,'Closing input file')
  78. !
  79. ! compute potential density
  80. !
  81. MASK = 1.
  82. WHERE(PT(:,:,:,1) > 1e19 .or. PT(:,:,:,1)< -9e30)
  83. MASK = 0.
  84. END WHERE
  85. DO JT = 1,LT
  86. call eos_insitu_pot( PT(:,:,:,JT), PS(:,:,:,JT), PD, MASK, &
  87. &PRHO(:,:,:,JT) )
  88. WHERE (MASK < 0.5)
  89. PRHO(:,:,:,JT) = 1e20
  90. END WHERE
  91. END DO
  92. !
  93. ! Write outputs
  94. ! ==============
  95. !
  96. istat = NF_CREATE(outfile,NF_NOCLOBBER,ncid)
  97. call check_stat(istat,'Opening output file')
  98. istat = NF_DEF_DIM(ncid,'x',LX,dimoutids(1))
  99. call check_stat(istat,'Defining x dimension in output file')
  100. istat = NF_DEF_DIM(ncid,'y',LY,dimoutids(2))
  101. call check_stat(istat,'Defining y dimension in output file')
  102. istat = NF_DEF_DIM(ncid,'z',LZ,dimoutids(3))
  103. call check_stat(istat,'Defining z dimension in output file')
  104. istat = NF_DEF_DIM(ncid,'t',LT,dimoutids(4))
  105. call check_stat(istat,'Defining t dimension in output file')
  106. istat = NF_DEF_VAR(ncid,'rhop',NF_DOUBLE,4,dimoutids,varid)
  107. call check_stat(istat,'Defining rhop variable in output file')
  108. istat = NF_PUT_ATT_DOUBLE(ncid,varid,'missing_value',NF_DOUBLE,1,DBLE(1e20))
  109. call check_stat(istat,'Defining missing value for rhop')
  110. istat = NF_ENDDEF(ncid)
  111. call check_stat(istat,'Closing output file definition')
  112. istat = NF_PUT_VAR_DOUBLE(ncid,varid,PRHO)
  113. call check_stat(istat,'Writing rhop in output file')
  114. istat = NF_CLOSE ( ncid )
  115. call check_stat(istat,'Closing output file')
  116. end program comp_rhop