cdfvT.f90 7.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250
  1. PROGRAM cdfvT
  2. !!-------------------------------------------------------------------
  3. !! *** PROGRAM cdfvT ***
  4. !!
  5. !! ** Purpose:
  6. !!
  7. !! ** Method: Try to avoid 3 d arrays
  8. !! Assume that all input files have the same number of time frames
  9. !!
  10. !! history :
  11. !! L. Brodeau , 2014 for BaraKuda !!
  12. !!
  13. !! Original : J.M. Molines (Nov 2004 ) for ORCA025
  14. !! J.M. Molines (apr 2005 ) : use of modules
  15. !! J.M. Molines (Feb. 2010 ): handle multiframes input files.
  16. !!-------------------------------------------------------------------
  17. !! $Rev: 317 $
  18. !! $Date: 2010-05-17 14:47:12 +0200 (Mon, 17 May 2010) $
  19. !! $Id: cdfvT.f90 317 2010-05-17 12:47:12Z molines $
  20. !!--------------------------------------------------------------
  21. USE cdfio
  22. USE io_ezcdf
  23. !! * Local variables
  24. IMPLICIT NONE
  25. INTEGER :: ji,jj,jk,jt,jkk !: dummy loop index
  26. INTEGER :: ierr !: working integer
  27. INTEGER :: narg, iargc
  28. INTEGER :: npiglo,npjglo, npk, nt !: size of the domain
  29. INTEGER, DIMENSION(4) :: ipk, id_varout
  30. REAL(KIND=4) , DIMENSION (:), ALLOCATABLE :: vtime ! lolo
  31. REAL(KIND=4) , DIMENSION (:), ALLOCATABLE :: vdepth ! lolo
  32. REAL(KIND=4) , DIMENSION (:,:), ALLOCATABLE :: xlon, xlat ! lolo
  33. REAL(KIND=4) , DIMENSION (:,:,:), ALLOCATABLE :: T_3D, S_3D, U_3D, V_3D, UEIV_3D, VEIV_3D, X_3D_u, X_3D_v !: lolo
  34. INTEGER(2) , DIMENSION (:,:,:), ALLOCATABLE :: mask_3d
  35. REAL(KIND=8) , DIMENSION (:,:,:), ALLOCATABLE :: zcumulut, zcumulus !: Arrays for cumulated values
  36. REAL(KIND=8) , DIMENSION (:,:,:), ALLOCATABLE :: zcumulvt, zcumulvs !: Arrays for cumulated values
  37. CHARACTER(LEN=256) :: cf_mm='mesh_mask.nc'
  38. CHARACTER(LEN=256) :: cf_t,cf_u,cf_v , cf_out, conf_tag , ctim !:
  39. TYPE (variable), DIMENSION(4) :: typvar !: structure for attributes
  40. LOGICAL :: lexist !: to inquire existence of files
  41. INTEGER :: istatus
  42. CHARACTER(LEN=64) :: cv_t, cv_s, cv_u, cv_v, cv_ueiv, cv_veiv
  43. INTEGER :: idf_t=0, idv_t=0, idf_s=0, idv_s=0, &
  44. & idf_u=0, idv_u=0, idf_v=0, idv_v=0, &
  45. & idf_ueiv=0, idv_ueiv=0, idf_veiv=0, idv_veiv=0
  46. INTEGER :: idf_vt=0, idv_vt=0, idv_vs=0, idv_ut=0, idv_us=0, idf_0=0, idv_0=0
  47. CHARACTER(LEN=100) :: cv_depth = 'deptht'
  48. LOGICAL :: leiv = .FALSE.
  49. !! Read command line
  50. narg= iargc()
  51. IF ( (narg < 5).OR.(narg > 7).OR.(narg == 6) ) THEN
  52. PRINT *,' Usage : cdfvT <CONF_TAG> <name T> <name S> <name U> <name V> (<name Ueiv> <name Veiv>)'
  53. PRINT *,' => files are: <CONF_TAG>_grid_T.nc <CONF_TAG>_grid_U.nc <CONF_TAG>_grid_V.nc'
  54. PRINT *,' Files mesh_mask.nc must be in te current directory'
  55. STOP
  56. ENDIF
  57. CALL getarg (1, conf_tag)
  58. CALL getarg (2, cv_t)
  59. CALL getarg (3, cv_s)
  60. CALL getarg (4, cv_u)
  61. CALL getarg (5, cv_v)
  62. PRINT *, ' Will compute VT using '//trim(cv_u)//' and '//trim(cv_v)
  63. IF (narg == 7) THEN
  64. leiv = .TRUE.
  65. CALL getarg (6, cv_ueiv)
  66. CALL getarg (7, cv_veiv)
  67. IF ( (trim(cv_ueiv) == '0').AND.(trim(cv_veiv) == '0') ) leiv = .FALSE.
  68. END IF
  69. IF ( leiv) &
  70. & PRINT *, ' and taking eddy-induced velocity into account using '//trim(cv_ueiv)//' and '//trim(cv_veiv)
  71. !! Initialisation from 1st file (all file are assume to have the same geometry)
  72. WRITE(cf_out,'(a,"_VT.nc")') trim(conf_tag)
  73. WRITE(cf_t,'(a,"_grid_T.nc")') trim(conf_tag)
  74. INQUIRE(FILE=cf_t,EXIST=lexist)
  75. IF ( .NOT. lexist ) THEN
  76. WRITE(cf_t,'(a,"_grid_T.nc4")') trim(conf_tag)
  77. INQUIRE(FILE=cf_t,EXIST=lexist)
  78. IF ( .NOT. lexist ) THEN
  79. PRINT *,' ERROR : missing grid_T or even gridT file '
  80. STOP
  81. ENDIF
  82. ENDIF
  83. PRINT *,TRIM(cf_t)
  84. npiglo= getdim (cf_t,'x')
  85. npjglo= getdim (cf_t,'y')
  86. npk = getdim (cf_t,'depth')
  87. ctim = 'none'
  88. nt = getdim (cf_t,'time',cdtrue=ctim,kstatus=istatus) !LB
  89. !LB:
  90. IF (nt == 0) THEN
  91. PRINT *, 'nt=0, assume 1' ; nt = 1
  92. END IF
  93. !LB.
  94. PRINT *, 'npiglo=', npiglo
  95. PRINT *, 'npjglo=', npjglo
  96. PRINT *, 'npk =', npk
  97. ALLOCATE( vtime(nt), vdepth(npk), xlon(npiglo,npjglo), xlat(npiglo,npjglo) )
  98. ALLOCATE( T_3D(npiglo,npjglo,npk), S_3D(npiglo,npjglo,npk), U_3D(npiglo,npjglo,npk), V_3D(npiglo,npjglo,npk) )
  99. ALLOCATE( X_3D_u(npiglo,npjglo,npk), X_3D_v(npiglo,npjglo,npk) )
  100. ALLOCATE( mask_3d(npiglo,npjglo,npk) )
  101. IF ( leiv ) ALLOCATE( UEIV_3D(npiglo,npjglo,npk), VEIV_3D(npiglo,npjglo,npk) )
  102. ALLOCATE( zcumulut(npiglo,npjglo,npk), zcumulus(npiglo,npjglo,npk) )
  103. ALLOCATE( zcumulvt(npiglo,npjglo,npk), zcumulvs(npiglo,npjglo,npk) )
  104. vtime = getvar1d(cf_t, trim(ctim), nt) !LB
  105. vdepth = getvar1d(cf_t, trim(cv_depth), npk) !LB
  106. !LB: Read lon and lat in mesh_mask to avoid problem with files with missing values on "removed land processors":
  107. xlon(:,:) = getvar(cf_mm, 'nav_lon', 1,npiglo,npjglo)
  108. xlat(:,:) = getvar(cf_mm, 'nav_lat', 1,npiglo,npjglo)
  109. CALL GETMASK_3D(cf_mm, 'tmask', mask_3d)
  110. WRITE(cf_t,'(a,"_grid_T.nc")') trim(conf_tag)
  111. INQUIRE(FILE=cf_t,EXIST=lexist)
  112. IF ( .NOT. lexist ) THEN
  113. WRITE(cf_t,'(a,"_grid_T.nc4")') trim(conf_tag)
  114. INQUIRE(FILE=cf_t,EXIST=lexist)
  115. IF ( .NOT. lexist ) THEN
  116. PRINT *,' ERROR : missing gridT or even grid_T file '
  117. STOP
  118. ENDIF
  119. ENDIF
  120. ! assume U and V file have same time span ...
  121. WRITE(cf_u,'(a,"_grid_U.nc")') trim(conf_tag)
  122. INQUIRE(FILE=cf_u,EXIST=lexist)
  123. IF ( .NOT. lexist ) THEN
  124. WRITE(cf_u,'(a,"_grid_U.nc4")') trim(conf_tag)
  125. INQUIRE(FILE=cf_u,EXIST=lexist)
  126. IF ( .NOT. lexist ) THEN
  127. PRINT *,' ERROR : missing grid_U or even gridU file '
  128. STOP
  129. ENDIF
  130. ENDIF
  131. WRITE(cf_v,'(a,"_grid_V.nc")') trim(conf_tag)
  132. INQUIRE(FILE=cf_v,EXIST=lexist)
  133. IF ( .NOT. lexist ) THEN
  134. WRITE(cf_v,'(a,"_grid_V.nc4")') trim(conf_tag)
  135. INQUIRE(FILE=cf_v,EXIST=lexist)
  136. IF ( .NOT. lexist ) THEN
  137. PRINT *,' ERROR : missing grid_V or even gridV file '
  138. STOP
  139. ENDIF
  140. ENDIF
  141. DO jt=1,nt
  142. PRINT *, ' * [cdfvT] jt = ', jt
  143. CALL GETVAR_3D(idf_t, idv_t, cf_t, cv_t, nt, jt, T_3D)
  144. CALL GETVAR_3D(idf_s, idv_s, cf_t, cv_s, nt, jt, S_3D)
  145. CALL GETVAR_3D(idf_u, idv_u, cf_u, cv_u, nt, jt, U_3D)
  146. CALL GETVAR_3D(idf_v, idv_v, cf_v, cv_v, nt, jt, V_3D)
  147. IF ( leiv ) THEN
  148. CALL GETVAR_3D(idf_ueiv, idv_ueiv, cf_u, cv_ueiv, nt, jt, UEIV_3D)
  149. CALL GETVAR_3D(idf_veiv, idv_veiv, cf_v, cv_veiv, nt, jt, VEIV_3D)
  150. U_3D = U_3D + UEIV_3D
  151. V_3D = V_3D + VEIV_3D
  152. END IF
  153. !LB: to avoid problem with files with missing values on "removed land processors":
  154. T_3D = T_3D*mask_3d
  155. S_3D = S_3D*mask_3d
  156. U_3D = U_3D*mask_3d
  157. V_3D = V_3D*mask_3d
  158. zcumulut(:,:,:) = 0.d0 ; zcumulvt(:,:,:) = 0.d0 !; total_time = 0.
  159. zcumulus(:,:,:) = 0.d0 ; zcumulvs(:,:,:) = 0.d0
  160. ! temperature
  161. X_3D_u(1:npiglo-1,:, :) = 0.5 * ( T_3D(1:npiglo-1,:, :) + T_3D(2:npiglo,:, :) ) ! temper at Upoint
  162. X_3D_v(:,1:npjglo-1, :) = 0.5 * ( T_3D(:,1:npjglo-1, :) + T_3D(:,2:npjglo, :) ) ! temper at Vpoint
  163. zcumulut(:,:,:) = X_3D_u(:,:,:) * U_3D(:,:,:)
  164. zcumulvt(:,:,:) = X_3D_v(:,:,:) * V_3D(:,:,:)
  165. ! salinity
  166. X_3D_u(1:npiglo-1,:, :) = 0.5 * ( S_3D(1:npiglo-1,:, :) + S_3D(2:npiglo,:, :) ) ! salinity at Upoint
  167. X_3D_v(:,1:npjglo-1, :) = 0.5 * ( S_3D(:,1:npjglo-1, :) + S_3D(:,2:npjglo, :) ) ! salinity at Vpoint
  168. zcumulus(:,:,:) = X_3D_u(:,:,:) * U_3D(:,:,:)
  169. zcumulvs(:,:,:) = X_3D_v(:,:,:) * V_3D(:,:,:)
  170. !! Printing record jt:
  171. CALL P3D_T_4v(idf_vt, idv_vt, idv_vs, idv_ut, idv_us, nt, jt, xlon, xlat, vdepth, REAL(vtime,8), &
  172. & REAL(zcumulvt,4), REAL(zcumulvs,4), REAL(zcumulut,4), REAL(zcumulus,4), &
  173. & cf_out, 'nav_lon', 'nav_lat', trim(cv_depth), 'time_counter', &
  174. & 'vomevt', 'vomevs', 'vozout', 'vozous', &
  175. & 0., 'seconds', 'm')
  176. END DO ! jt
  177. PRINT *, ' *** cdfvT => '//trim(cf_out)//' written!'; PRINT *, ''
  178. END PROGRAM cdfvT