NCEPLIBS-ip  5.1.0
spsynth.f
Go to the documentation of this file.
1 C> @file
2 C> @brief Synthesize Fourier coefficients from spectral coefficients.
3 C>
4 C> ### Program History Log
5 C> Date | Programmer | Comments
6 C> -----|------------|---------
7 C> 91-10-31 | Mark Iredell | Initial.
8 C> 1998-12-18 | Mark Iredell | Include scalar and gradient option.
9 C>
10 C> @author Iredell @date 92-10-31
11 
12 C> Synthesizes Fourier coefficients from spectral coefficients
13 C> for a latitude pair (Northern and Southern hemispheres).
14 C>
15 C> Vector components are divided by cosine of latitude.
16 C>
17 C> @param I spectral domain shape
18 C> (0 for triangular, 1 for rhomboidal)
19 C> @param M spectral truncation
20 C> @param IM even number of Fourier coefficients
21 C> @param IX dimension of Fourier coefficients (IX>=IM+2)
22 C> @param NC dimension of spectral coefficients
23 C> (NC>=(M+1)*((I+1)*M+2))
24 C> @param NCTOP dimension of spectral coefficients over top
25 C> (NCTOP>=2*(M+1))
26 C> @param KM number of fields
27 C> @param CLAT cosine of latitude
28 C> @param PLN ((M+1)*((I+1)*M+2)/2) Legendre polynomial
29 C> @param PLNTOP Legendre polynomial over top
30 C> @param SPC spectral coefficients
31 C> @param SPCTOP spectral coefficients over top
32 C> @param MP identifiers (0 for scalar, 1 for vector,
33 C> or 10 for scalar and gradient)
34 C> @param F Fourier coefficients for latitude pair
35 C>
36 C> @author Iredell @date 92-10-31
37  SUBROUTINE spsynth(I,M,IM,IX,NC,NCTOP,KM,CLAT,PLN,PLNTOP,MP,
38  & SPC,SPCTOP,F)
39 
40  REAL PLN((M+1)*((I+1)*M+2)/2),PLNTOP(M+1)
41  INTEGER MP(KM)
42  REAL SPC(NC,KM),SPCTOP(NCTOP,KM)
43  REAL F(IX,2,KM)
44  REAL :: TINYREAL=tiny(1.0)
45 
46 C ZERO OUT FOURIER COEFFICIENTS.
47  DO k=1,km
48  DO l=0,im/2
49  f(2*l+1,1,k)=0.
50  f(2*l+2,1,k)=0.
51  f(2*l+1,2,k)=0.
52  f(2*l+2,2,k)=0.
53  ENDDO
54  ENDDO
55 
56 C SYNTHESIS OVER POLE.
57 C INITIALIZE FOURIER COEFFICIENTS WITH TERMS OVER TOP OF THE SPECTRUM.
58 C INITIALIZE EVEN AND ODD POLYNOMIALS SEPARATELY.
59  IF(abs(clat).LT.tinyreal) THEN
60  ltope=mod(m+1+i,2)
61 !C$OMP PARALLEL DO PRIVATE(LB,LE,L,KS,KP,N,F1R,F1I)
62  DO k=1,km
63  lb=mp(k)
64  le=mp(k)
65  IF(mp(k).EQ.10) THEN
66  lb=0
67  le=1
68  ENDIF
69  l=lb
70  IF(l.EQ.1) THEN
71  IF(l.EQ.ltope) THEN
72  f(2*l+1,1,k)=plntop(l+1)*spctop(2*l+1,k)
73  f(2*l+2,1,k)=plntop(l+1)*spctop(2*l+2,k)
74  ELSE
75  f(2*l+1,2,k)=plntop(l+1)*spctop(2*l+1,k)
76  f(2*l+2,2,k)=plntop(l+1)*spctop(2*l+2,k)
77  ENDIF
78  ENDIF
79 C FOR EACH ZONAL WAVENUMBER, SYNTHESIZE TERMS OVER TOTAL WAVENUMBER.
80 C SYNTHESIZE EVEN AND ODD POLYNOMIALS SEPARATELY.
81  DO l=lb,le
82  ks=l*(2*m+(i-1)*(l-1))
83  kp=ks/2+1
84  DO n=l,i*l+m,2
85  f(2*l+1,1,k)=f(2*l+1,1,k)+pln(kp+n)*spc(ks+2*n+1,k)
86  f(2*l+2,1,k)=f(2*l+2,1,k)+pln(kp+n)*spc(ks+2*n+2,k)
87  ENDDO
88  DO n=l+1,i*l+m,2
89  f(2*l+1,2,k)=f(2*l+1,2,k)+pln(kp+n)*spc(ks+2*n+1,k)
90  f(2*l+2,2,k)=f(2*l+2,2,k)+pln(kp+n)*spc(ks+2*n+2,k)
91  ENDDO
92 C SEPARATE FOURIER COEFFICIENTS FROM EACH HEMISPHERE.
93 C ODD POLYNOMIALS CONTRIBUTE NEGATIVELY TO THE SOUTHERN HEMISPHERE.
94  f1r=f(2*l+1,1,k)
95  f1i=f(2*l+2,1,k)
96  f(2*l+1,1,k)=f1r+f(2*l+1,2,k)
97  f(2*l+2,1,k)=f1i+f(2*l+2,2,k)
98  f(2*l+1,2,k)=f1r-f(2*l+1,2,k)
99  f(2*l+2,2,k)=f1i-f(2*l+2,2,k)
100  ENDDO
101  ENDDO
102 
103 C SYNTHESIS OVER FINITE LATITUDE.
104 C INITIALIZE FOURIER COEFFICIENTS WITH TERMS OVER TOP OF THE SPECTRUM.
105 C INITIALIZE EVEN AND ODD POLYNOMIALS SEPARATELY.
106  ELSE
107  lx=min(m,im/2)
108  ltope=mod(m+1,2)
109  ltopo=1-ltope
110  le=1+i*ltope
111  lo=2-i*ltopo
112 !C$OMP PARALLEL DO PRIVATE(L,KS,KP,N,F1R,F1I)
113  DO k=1,km
114  IF(mp(k).EQ.1) THEN
115  DO l=ltope,lx,2
116  f(2*l+1,le,k)=plntop(l+1)*spctop(2*l+1,k)
117  f(2*l+2,le,k)=plntop(l+1)*spctop(2*l+2,k)
118  ENDDO
119  DO l=ltopo,lx,2
120  f(2*l+1,lo,k)=plntop(l+1)*spctop(2*l+1,k)
121  f(2*l+2,lo,k)=plntop(l+1)*spctop(2*l+2,k)
122  ENDDO
123  ENDIF
124 C FOR EACH ZONAL WAVENUMBER, SYNTHESIZE TERMS OVER TOTAL WAVENUMBER.
125 C SYNTHESIZE EVEN AND ODD POLYNOMIALS SEPARATELY.
126  DO l=0,lx
127  ks=l*(2*m+(i-1)*(l-1))
128  kp=ks/2+1
129  DO n=l,i*l+m,2
130  f(2*l+1,1,k)=f(2*l+1,1,k)+pln(kp+n)*spc(ks+2*n+1,k)
131  f(2*l+2,1,k)=f(2*l+2,1,k)+pln(kp+n)*spc(ks+2*n+2,k)
132  ENDDO
133  DO n=l+1,i*l+m,2
134  f(2*l+1,2,k)=f(2*l+1,2,k)+pln(kp+n)*spc(ks+2*n+1,k)
135  f(2*l+2,2,k)=f(2*l+2,2,k)+pln(kp+n)*spc(ks+2*n+2,k)
136  ENDDO
137  ENDDO
138 C SEPARATE FOURIER COEFFICIENTS FROM EACH HEMISPHERE.
139 C ODD POLYNOMIALS CONTRIBUTE NEGATIVELY TO THE SOUTHERN HEMISPHERE.
140 C DIVIDE VECTOR COMPONENTS BY COSINE LATITUDE.
141  DO l=0,lx
142  f1r=f(2*l+1,1,k)
143  f1i=f(2*l+2,1,k)
144  f(2*l+1,1,k)=f1r+f(2*l+1,2,k)
145  f(2*l+2,1,k)=f1i+f(2*l+2,2,k)
146  f(2*l+1,2,k)=f1r-f(2*l+1,2,k)
147  f(2*l+2,2,k)=f1i-f(2*l+2,2,k)
148  ENDDO
149  IF(mp(k).EQ.1) THEN
150  DO l=0,lx
151  f(2*l+1,1,k)=f(2*l+1,1,k)/clat
152  f(2*l+2,1,k)=f(2*l+2,1,k)/clat
153  f(2*l+1,2,k)=f(2*l+1,2,k)/clat
154  f(2*l+2,2,k)=f(2*l+2,2,k)/clat
155  ENDDO
156  ENDIF
157  ENDDO
158  ENDIF
159  END
subroutine spsynth(I, M, IM, IX, NC, NCTOP, KM, CLAT, PLN, PLNTOP, MP, SPC, SPCTOP, F)
Synthesizes Fourier coefficients from spectral coefficients for a latitude pair (Northern and Souther...
Definition: spsynth.f:39