My Project
rho_pmean.f90
Go to the documentation of this file.
1 
2 
3 
4 
5 
6 
7 
8 
9 
10 
11 
12 !/===========================================================================/
13 ! Copyright (c) 2007, The University of Massachusetts Dartmouth
14 ! Produced at the School of Marine Science & Technology
15 ! Marine Ecosystem Dynamics Modeling group
16 ! All rights reserved.
17 !
18 ! FVCOM has been developed by the joint UMASSD-WHOI research team. For
19 ! details of authorship and attribution of credit please see the FVCOM
20 ! technical manual or contact the MEDM group.
21 !
22 !
23 ! This file is part of FVCOM. For details, see http://fvcom.smast.umassd.edu
24 ! The full copyright notice is contained in the file COPYRIGHT located in the
25 ! root directory of the FVCOM code. This original header must be maintained
26 ! in all distributed versions.
27 !
28 ! THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
29 ! AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
30 ! THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
31 ! PURPOSE ARE DISCLAIMED.
32 !
33 !/---------------------------------------------------------------------------/
34 ! CVS VERSION INFORMATION
35 ! $Id$
36 ! $Name$
37 ! $Revision$
38 !/===========================================================================/
39 
40 !==============================================================================|
41 SUBROUTINE rho_pmean
42  !==============================================================================|
43  USE all_vars
44  USE mod_utils
45  USE mod_par
46  USE sinter
47  USE mod_wd
48  IMPLICIT NONE
49 
50  INTEGER, PARAMETER :: KBB=601
51  INTEGER, PARAMETER :: KBBM1=kbb-1
52 
53  REAL(SP) DELTZ
54  REAL(SP), DIMENSION(KBB) :: PHY_Z !Depth(m) in every standary Z levels
55  REAL(SP), DIMENSION(KBB) :: RHOZ !density in standary Z levels
56 
57  REAL(SP), DIMENSION(KBB) :: RHOA !density mean in standary Z levals
58 
59  REAL(SP), DIMENSION(KBM1) :: ZM !Depth (m) in every sigma levels for giving node
60  REAL(SP), DIMENSION(KBM1) :: RHOS !DENS AT SIGMA LEVELS
61 
62  REAL(SP), DIMENSION(KBB) :: FCOUNT
63 
64  INTEGER :: I,K,status,IERR,IB
65  REAL(SP) :: Z_TOP, Z_BOTTOM,SBUF
66 
67  !========================================
68  ! ONLY USED FOR PAR
69  REAL(SP), DIMENSION(KBB,NPROCS) :: RHOA_RCV, FCOUNT_RCV
70  !========================================
71 
72  !--CALCULATE Z-LEVELS TO MAX DEPTH---------------------------------------------|
73 
74  IF(dbg_set(dbg_sbr)) WRITE(ipt,*) "START: RHO_PMEAN"
75 
76  IF(dbg_set(dbg_log)) WRITE(ipt,*) "! Recalculating mean density in pressure coordinates"
77 
78 
79  IF(serial) THEN
80  IF(wetting_drying_on)THEN
81  z_top = maxval(el(1:m)*iswetn(1:m))
82  ELSE
83  z_top = maxval(el(1:m))
84  END IF
85  z_bottom = hmax+spacing(hmax)
86  ELSE
87  END IF
88 
89 
90 ! DELTZ=HMAX/FLOAT(KBBM1)
91  deltz=(z_bottom + z_top)/float(kbbm1)
92 
93  DO k=1,kbb
94  phy_z(k)= z_top - float(k-1)*deltz
95  END DO
96 
97 ! PHY_Z(1)=PHY_Z(1)-spacing(PHY_Z(1))
98 ! PHY_Z(KBB)=PHY_Z(KBB)+spacing(PHY_Z(KBB))
99 
100  phy_z(1)=nearest(z_top,-1.0_sp) ! Nearest number smaller than Z_TOP
101 
102  phy_z(kbb)=nearest(-z_bottom,1.0_sp) ! Nearest number larger than Z_BOTTOM
103 
104 
105  !--DO THE AVERAGE OVER Z_levels
106 
107 
108  IF(serial) THEN
109  rhoa=0.0_sp
110  fcount=0.0_sp
111  DO i=1,m
112 
113  !--LINEARLY INTERPOLATE TO OBTAIN DENSITY VALUES AT Z LEVELS-------------------|
114  zm(1:kbm1)=zz(i,1:kbm1)*d(i)+el(i)
115  rhos = rho1(i,1:kbm1)
116  CALL sinter_extrp_none(zm,rhos,phy_z,rhoz,kbm1,kbb)
117 
118  !--SUM THE DENSITY ACROSS ALL THE NODES AT ZLEVELS ----------!
119  DO k=1,kbb
120  IF(-h(i).LE.phy_z(k) .AND. el(i) .GE. phy_z(k)) THEN
121  fcount(k) = fcount(k) + 1.0_sp
122  rhoa(k)=rhoa(k)+rhoz(k)
123  END IF
124 
125  END DO
126 
127  END DO
128 
129  ! TAKE THE AVERAGE
130  IF(minval(fcount) .LT. 1.0_sp)THEN
131  IF(dbg_set(dbg_log)) WRITE(ipt,*) "FOUND NO DATA AT DEPTH:",phy_z(minloc(fcount,1))
132  CALL fatal_error("RHO_PMEAN: In Serial case, found fcount LT 0.0!")
133  END IF
134  rhoa = rhoa / fcount
135 
136  ELSE
137 
138  END IF
139 
140 
141  !--LINEARLY INTERPOLATE TO OBTAIN DENSITY VALUES AT SIGMA LEVELS-------------------|
142 
143 
144  DO i=1,m
145  IF(wetting_drying_on.and.iswetn(i)==0)cycle
146  DO k=1,kbm1
147  zm(k)=zz(i,k)*d(i)+el(i)
148  END DO
149  CALL sinter_extrp_none(phy_z,rhoa,zm,rhos,kbb,kbm1)
150  rmean1(i,1:kbm1) = rhos
151  END DO
152 
153  rmean1(:,kb)=0.0_sp
154 
155 
156  CALL n2e3d(rmean1,rmean)
157 
158 
159  IF(dbg_set(dbg_sbr)) WRITE(ipt,*) "END: RHO_PMEAN"
160 
161  RETURN
162 END SUBROUTINE rho_pmean
real(sp), dimension(:), allocatable, target d
Definition: mod_main.f90:1132
real(sp), dimension(:), allocatable, target h
Definition: mod_main.f90:1131
real(sp), dimension(:), allocatable, target el
Definition: mod_main.f90:1134
logical function dbg_set(vrb)
Definition: mod_utils.f90:182
real(sp), dimension(:,:), allocatable, target rho1
Definition: mod_main.f90:1309
subroutine sinter_extrp_none(X, A, Y, B, M1, N1)
Definition: sinter.f90:140
subroutine rho_pmean
Definition: rho_pmean.f90:42
subroutine fatal_error(ER1, ER2, ER3, ER4)
Definition: mod_utils.f90:230
subroutine n2e3d(NVAR, EVAR)
Definition: mod_main.f90:1370
integer, parameter dbg_sbr
Definition: mod_utils.f90:69
real(sp), dimension(:,:), allocatable, target zz
Definition: mod_main.f90:1091
real(sp), dimension(:,:), allocatable, target rmean
Definition: mod_main.f90:1285
real(sp), dimension(:,:), allocatable, target rmean1
Definition: mod_main.f90:1320
integer, parameter dbg_log
Definition: mod_utils.f90:65
integer, dimension(:), allocatable iswetn
Definition: mod_wd.f90:51