-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcal_vertical.f90
65 lines (48 loc) · 1.34 KB
/
cal_vertical.f90
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
subroutine cal_vertical(nx,ny,nz,Z,missing_val,f,g)
implicit none
integer, intent(in) :: nx, ny, nz
real,intent(in) :: f(nx,ny,nz), Z(nz), missing_val
real, intent(out) :: g(nx,ny,nz)
real :: f0(nx,ny,nz-1)
integer :: i, j, k, l, msk2d(nx,ny), outmsk(nx,ny,nz-1), msk(nx,ny,nz)
msk = 0
where(f.ne.missing_val)
msk = 1
end where
outmsk = 0.5*(msk(:,:,1:nz-1)+msk(:,:,2:nz))
where (outmsk.eq.0.5)
outmsk = 0
end where
msk2d = sum(outmsk,3)
f0 = 0
!OMP PARALLEL DO
do k = 1,nz-1
do j = 1,ny
do i = 1,nx
if ((f(i,j,k).ne.missing_val).and.(f(i,j,k+1).ne.missing_val)) then
f0(i,j,k-1) = 0.5*(f(i,j,k)+f(i,j,k+1))*(Z(k+1)-Z(k))
end if
end do
end do
end do
!OMP END PARALLEL DO
where((f0.gt.1).or.(f0.lt.-1))
f0 = 0
end where
g(:,:,nz) = 0
!OMP PARALLEL DO
do k = nz-1,1,-1
g(:,:,k) = g(:,:,k+1)+f0(:,:,k)
end do
!OMP END PARALLEL DO
where(msk2d.eq.0)
msk2d = 1
end where
!OMP PARALLEL DO
do j = 1,ny
do i = 1,nx
g(i,j,msk2d(i,j):nz) = missing_val
end do
end do
!OMP END PARALLEL DO
end subroutine