1 |
jmc |
1.7 |
C $Header: /u/gcmpack/MITgcm/pkg/zonal_filt/zonal_filter.F,v 1.6 2009/09/02 19:22:07 jmc Exp $ |
2 |
jmc |
1.5 |
C $Name: $ |
3 |
adcroft |
1.2 |
|
4 |
|
|
#include "ZONAL_FILT_OPTIONS.h" |
5 |
|
|
|
6 |
jmc |
1.7 |
CBOP 0 |
7 |
|
|
C !ROUTINE: ZONAL_FILTER |
8 |
|
|
|
9 |
|
|
C !INTERFACE: |
10 |
jmc |
1.6 |
SUBROUTINE ZONAL_FILTER( |
11 |
|
|
U field, |
12 |
|
|
I fieldMask, |
13 |
jmc |
1.7 |
I jMin, jMax, kSize, bi, bj, gridLoc, myThid ) |
14 |
jmc |
1.6 |
|
15 |
jmc |
1.7 |
C !DESCRIPTION: |
16 |
jmc |
1.6 |
C *==========================================================* |
17 |
|
|
C | S/R ZONAL_FILTER |
18 |
|
|
C | o Apply FFT filter to a latitude circle. |
19 |
|
|
C *==========================================================* |
20 |
|
|
|
21 |
jmc |
1.7 |
C !USES: |
22 |
adcroft |
1.2 |
IMPLICIT NONE |
23 |
|
|
C == Global data == |
24 |
|
|
#include "SIZE.h" |
25 |
jmc |
1.5 |
#include "EEPARAMS.h" |
26 |
|
|
#include "PARAMS.h" |
27 |
|
|
#include "GRID.h" |
28 |
adcroft |
1.2 |
#include "ZONAL_FILT.h" |
29 |
|
|
#include "FFTPACK.h" |
30 |
|
|
|
31 |
jmc |
1.7 |
C !INPUT/OUTPUT PARAMETERS: |
32 |
|
|
C jMin :: Range of points to filter |
33 |
adcroft |
1.2 |
C jMax |
34 |
jmc |
1.7 |
C kSize :: Number of levels to filter |
35 |
|
|
C bi, bj :: tile indices |
36 |
|
|
C field :: Field to filter |
37 |
|
|
C fieldMask :: mask corresponding to field to filter |
38 |
|
|
C gridLoc :: Position on the grid (U or V) of field. |
39 |
|
|
C myThid :: my Thread Id number |
40 |
|
|
INTEGER kSize |
41 |
|
|
_RL field (1-OLx:sNx+OLx,1-OLy:sNy+OLy,kSize) |
42 |
|
|
_RS fieldMask(1-Olx:sNx+Olx,1-Oly:sNy+Oly,kSize) |
43 |
|
|
INTEGER jMin, jMax, bi, bj |
44 |
jmc |
1.6 |
INTEGER gridLoc |
45 |
adcroft |
1.2 |
INTEGER myThid |
46 |
jmc |
1.7 |
CEOP |
47 |
adcroft |
1.2 |
|
48 |
|
|
#ifdef ALLOW_ZONAL_FILT |
49 |
|
|
|
50 |
jmc |
1.7 |
C !LOCAL VARIABLES: |
51 |
adcroft |
1.2 |
Real*8 phi(Nx) |
52 |
|
|
Real*8 phiMask(Nx) |
53 |
|
|
Real*8 avPhi |
54 |
jmc |
1.7 |
INTEGER i, j, k |
55 |
adcroft |
1.2 |
|
56 |
jmc |
1.7 |
DO k= 1, kSize |
57 |
adcroft |
1.2 |
DO j=jMin, jMax |
58 |
jmc |
1.5 |
IF ( (gridLoc.EQ.1 .AND.ABS(yC(1,j,bi,bj)).GE.zonal_filt_lat) |
59 |
|
|
& .OR.(gridLoc.EQ.2 .AND.ABS(yG(2,j,bi,bj)).GE.zonal_filt_lat) |
60 |
|
|
& .OR. zonal_filt_mode2dx.EQ.2 ) THEN |
61 |
adcroft |
1.2 |
|
62 |
|
|
C o Copy zonal line of field into local workspace |
63 |
|
|
DO i=1,sNx |
64 |
jmc |
1.7 |
phi(i) = field(i,j,k) |
65 |
|
|
phiMask(i) = fieldMask(i,j,k) |
66 |
adcroft |
1.2 |
ENDDO |
67 |
|
|
|
68 |
|
|
C Interpolate through land |
69 |
|
|
CALL ZONAL_FILT_PRESMOOTH( phiMask,phi,avPhi,sNx,myThid ) |
70 |
|
|
|
71 |
|
|
C o Forward transform (using specific FFT package) |
72 |
|
|
C CALL R8FFTF( Nx, phi, FFTPACKWS(1,bj) ) |
73 |
|
|
CALL R8FFTF1( Nx, phi, |
74 |
|
|
& FFTPACKWS1(1,bj), FFTPACKWS2(1,bj),FFTPACKWS3(1,bj) ) |
75 |
|
|
|
76 |
|
|
C o Apply amplitude filter and normalize |
77 |
|
|
IF (gridLoc .EQ. 1) THEN |
78 |
|
|
DO i=1, Nx |
79 |
|
|
phi(i)=phi(i)*ampFactor(i,j,bi,bj)/float(Nx) |
80 |
|
|
ENDDO |
81 |
|
|
ELSEIF (gridLoc .EQ. 2) THEN |
82 |
|
|
DO i=1, Nx |
83 |
|
|
phi(i)=phi(i)*ampFactorV(i,j,bi,bj)/float(Nx) |
84 |
|
|
ENDDO |
85 |
|
|
ELSE |
86 |
heimbach |
1.4 |
WRITE(*,*) 'Error: gridLoc = ',gridLoc |
87 |
adcroft |
1.2 |
STOP 'Error: gridLoc has illegal value' |
88 |
|
|
ENDIF |
89 |
|
|
|
90 |
|
|
C o Backward transform (using specific FFT package) |
91 |
|
|
C CALL R8FFTB( Nx, phi, FFTPACKWS(1,bj) ) |
92 |
|
|
CALL R8FFTB1( Nx, phi, |
93 |
|
|
& FFTPACKWS1(1,bj), FFTPACKWS2(1,bj),FFTPACKWS3(1,bj) ) |
94 |
|
|
|
95 |
|
|
C De-interpolate through land |
96 |
|
|
CALL ZONAL_FILT_POSTSMOOTH(phiMask,phi,avPhi,sNx,myThid) |
97 |
|
|
|
98 |
|
|
C o Do periodic wrap around by hand |
99 |
|
|
DO i=1-OLx,0 |
100 |
jmc |
1.7 |
field(i,j,k) = phi(sNx+i) |
101 |
adcroft |
1.2 |
ENDDO |
102 |
|
|
DO i=1,sNx |
103 |
jmc |
1.7 |
field(i,j,k) = phi(i) |
104 |
adcroft |
1.2 |
ENDDO |
105 |
|
|
DO i=sNx+1,sNx+OLx |
106 |
jmc |
1.7 |
field(i,j,k) = phi(i-sNx) |
107 |
adcroft |
1.2 |
ENDDO |
108 |
|
|
|
109 |
jmc |
1.5 |
ENDIF |
110 |
adcroft |
1.2 |
ENDDO |
111 |
|
|
ENDDO |
112 |
|
|
|
113 |
|
|
#endif /* ALLOW_ZONAL_FILT */ |
114 |
|
|
|
115 |
|
|
RETURN |
116 |
|
|
END |