NCEPLIBS-sp 2.4.0
sptranfv.f
Go to the documentation of this file.
1C> @file
2C> @brief Perform a vector spherical transform
3C>
4C> ### Program History Log
5C> Date | Programmer | Comments
6C> -----|------------|---------
7C> 96-02-29 | Iredell | Initial.
8C> 1998-12-15 | Iredell | Generic fft used, openmp directives inserted
9C> 2013-01-16 | Iredell & MIRVIS | Fixing afft negative sharing effect during omp loops
10C>
11C> @author Iredell @date 96-02-29
12
13C> This subprogram performs a spherical transform
14C> between spectral coefficients of divergences and curls
15C> and vector fields on a global cylindrical grid.
16C>
17C> The wave-space can be either triangular or rhomboidal.
18C>
19C> The grid-space can be either an equally-spaced grid
20C> (with or without pole points) or a Gaussian grid.
21C>
22C> The wave and grid fields may have general indexing,
23C> but each wave field is in sequential 'ibm order',
24C> i.e. with zonal wavenumber as the slower index.
25C>
26C> Transforms are done in latitude pairs for efficiency;
27C> thus grid arrays for each hemisphere must be passed.
28C> if so requested, just a subset of the latitude pairs
29C> may be transformed in each invocation of the subprogram.
30C>
31C> The transforms are all multiprocessed over latitude except
32C> the transform from fourier to spectral is multiprocessed
33C> over zonal wavenumber to ensure reproducibility.
34C>
35C> Transform several fields at a time to improve vectorization.
36C> subprogram can be called from a multiprocessing environment.
37C>
38C> Minimum grid dimensions for unaliased transforms to spectral:
39C> DIMENSION |LINEAR |QUADRATIC
40C> ----------------------- |--------- |-------------
41C> IMAX |2*MAXWV+2 |3*MAXWV/2*2+2
42C> JMAX (IDRT=4,IROMB=0) |1*MAXWV+1 |3*MAXWV/2+1
43C> JMAX (IDRT=4,IROMB=1) |2*MAXWV+1 |5*MAXWV/2+1
44C> JMAX (IDRT=0,IROMB=0) |2*MAXWV+3 |3*MAXWV/2*2+3
45C> JMAX (IDRT=0,IROMB=1) |4*MAXWV+3 |5*MAXWV/2*2+3
46C> JMAX (IDRT=256,IROMB=0) |2*MAXWV+1 |3*MAXWV/2*2+1
47C> JMAX (IDRT=256,IROMB=1) |4*MAXWV+1 |5*MAXWV/2*2+1
48C>
49C> @param IROMB spectral domain shape
50C> (0 for triangular, 1 for rhomboidal)
51C> @param MAXWV spectral truncation
52C> @param IDRT grid identifier
53C> - IDRT=4 for Gaussian grid
54C> - IDRT=0 for equally-spaced grid including poles
55C> - IDRT=256 for equally-spaced grid excluding poles
56C> @param IMAX even number of longitudes.
57C> @param JMAX number of latitudes.
58C> @param KMAX number of fields to transform.
59C> @param IP longitude index for the prime meridian
60C> @param IS skip number between longitudes
61C> @param JN skip number between n.h. latitudes from north
62C> @param JS skip number between s.h. latitudes from south
63C> @param KW skip number between wave fields
64C> @param KG skip number between grid fields
65C> @param JB latitude index (from pole) to begin transform
66C> @param JE latitude index (from pole) to end transform
67C> @param JC number of cpus over which to multiprocess
68C> @param[out] WAVED wave divergence fields if IDIR>0
69C> [WAVED=(D(GRIDU)/DLAM+D(CLAT*GRIDV)/DPHI)/(CLAT*RERTH)]
70C> @param[out] WAVEZ wave vorticity fields if IDIR>0
71C> [WAVEZ=(D(GRIDV)/DLAM-D(CLAT*GRIDU)/DPHI)/(CLAT*RERTH)]
72C> @param[out] GRIDUN N.H. grid u-winds (starting at jb) if IDIR<0
73C> @param[out] GRIDUS S.H. grid u-winds (starting at jb) if IDIR<0
74C> @param[out] GRIDVN N.H. grid v-winds (starting at jb) if IDIR<0
75C> @param[out] GRIDVS S.H. grid v-winds (starting at jb) if IDIR<0
76C> @param IDIR transform flag
77C> (IDIR>0 for wave to grid, IDIR<0 for grid to wave).
78C>
79C> @author Iredell @date 96-02-29
80 SUBROUTINE sptranfv(IROMB,MAXWV,IDRT,IMAX,JMAX,KMAX,
81 & IP,IS,JN,JS,KW,KG,JB,JE,JC,
82 & WAVED,WAVEZ,GRIDUN,GRIDUS,GRIDVN,GRIDVS,IDIR)
83
84 REAL WAVED(*),WAVEZ(*),GRIDUN(*),GRIDUS(*),GRIDVN(*),GRIDVS(*)
85 REAL EPS((MAXWV+1)*((IROMB+1)*MAXWV+2)/2),EPSTOP(MAXWV+1)
86 REAL ENN1((MAXWV+1)*((IROMB+1)*MAXWV+2)/2)
87 REAL ELONN1((MAXWV+1)*((IROMB+1)*MAXWV+2)/2)
88 REAL EON((MAXWV+1)*((IROMB+1)*MAXWV+2)/2),EONTOP(MAXWV+1)
89 REAL(8) AFFT(50000+4*IMAX), AFFT_TMP(50000+4*IMAX)
90 REAL CLAT(JB:JE),SLAT(JB:JE),WLAT(JB:JE)
91 REAL PLN((MAXWV+1)*((IROMB+1)*MAXWV+2)/2,JB:JE)
92 REAL PLNTOP(MAXWV+1,JB:JE)
93 INTEGER MP(2)
94 REAL W((MAXWV+1)*((IROMB+1)*MAXWV+2)/2*2,2)
95 REAL WTOP(2*(MAXWV+1),2)
96 REAL G(IMAX,2,2)
97 REAL WINC((MAXWV+1)*((IROMB+1)*MAXWV+2)/2*2,2)
98
99C SET PARAMETERS
100 mx=(maxwv+1)*((iromb+1)*maxwv+2)/2
101 mp=1
102 CALL sptranf0(iromb,maxwv,idrt,imax,jmax,jb,je,
103 & eps,epstop,enn1,elonn1,eon,eontop,
104 & afft,clat,slat,wlat,pln,plntop)
105
106C TRANSFORM WAVE TO GRID
107 IF(idir.GT.0) THEN
108C$OMP PARALLEL DO PRIVATE(AFFT_TMP,KWS,W,WTOP,G,IJKN,IJKS)
109 DO k=1,kmax
110 afft_tmp=afft
111 kws=(k-1)*kw
112 CALL spdz2uv(iromb,maxwv,enn1,elonn1,eon,eontop,
113 & waved(kws+1),wavez(kws+1),
114 & w(1,1),w(1,2),wtop(1,1),wtop(1,2))
115 DO j=jb,je
116 CALL sptranf1(iromb,maxwv,idrt,imax,jmax,j,j,
117 & eps,epstop,enn1,elonn1,eon,eontop,
118 & afft_tmp,clat(j),slat(j),wlat(j),
119 & pln(1,j),plntop(1,j),mp,
120 & w(1,1),wtop(1,1),g(1,1,1),idir)
121 CALL sptranf1(iromb,maxwv,idrt,imax,jmax,j,j,
122 & eps,epstop,enn1,elonn1,eon,eontop,
123 & afft_tmp,clat(j),slat(j),wlat(j),
124 & pln(1,j),plntop(1,j),mp,
125 & w(1,2),wtop(1,2),g(1,1,2),idir)
126 IF(ip.EQ.1.AND.is.EQ.1) THEN
127 DO i=1,imax
128 ijkn=i+(j-jb)*jn+(k-1)*kg
129 ijks=i+(j-jb)*js+(k-1)*kg
130 gridun(ijkn)=g(i,1,1)
131 gridus(ijks)=g(i,2,1)
132 gridvn(ijkn)=g(i,1,2)
133 gridvs(ijks)=g(i,2,2)
134 ENDDO
135 ELSE
136 DO i=1,imax
137 ijkn=mod(i+ip-2,imax)*is+(j-jb)*jn+(k-1)*kg+1
138 ijks=mod(i+ip-2,imax)*is+(j-jb)*js+(k-1)*kg+1
139 gridun(ijkn)=g(i,1,1)
140 gridus(ijks)=g(i,2,1)
141 gridvn(ijkn)=g(i,1,2)
142 gridvs(ijks)=g(i,2,2)
143 ENDDO
144 ENDIF
145 ENDDO
146 ENDDO
147
148C TRANSFORM GRID TO WAVE
149 ELSE
150C$OMP PARALLEL DO PRIVATE(AFFT_TMP,KWS,W,WTOP,G,IJKN,IJKS,WINC)
151 DO k=1,kmax
152 afft_tmp=afft
153 kws=(k-1)*kw
154 w=0
155 wtop=0
156 DO j=jb,je
157 IF(wlat(j).GT.0.) THEN
158 IF(ip.EQ.1.AND.is.EQ.1) THEN
159 DO i=1,imax
160 ijkn=i+(j-jb)*jn+(k-1)*kg
161 ijks=i+(j-jb)*js+(k-1)*kg
162 g(i,1,1)=gridun(ijkn)/clat(j)**2
163 g(i,2,1)=gridus(ijks)/clat(j)**2
164 g(i,1,2)=gridvn(ijkn)/clat(j)**2
165 g(i,2,2)=gridvs(ijks)/clat(j)**2
166 ENDDO
167 ELSE
168 DO i=1,imax
169 ijkn=mod(i+ip-2,imax)*is+(j-jb)*jn+(k-1)*kg+1
170 ijks=mod(i+ip-2,imax)*is+(j-jb)*js+(k-1)*kg+1
171 g(i,1,1)=gridun(ijkn)/clat(j)**2
172 g(i,2,1)=gridus(ijks)/clat(j)**2
173 g(i,1,2)=gridvn(ijkn)/clat(j)**2
174 g(i,2,2)=gridvs(ijks)/clat(j)**2
175 ENDDO
176 ENDIF
177 CALL sptranf1(iromb,maxwv,idrt,imax,jmax,j,j,
178 & eps,epstop,enn1,elonn1,eon,eontop,
179 & afft_tmp,clat(j),slat(j),wlat(j),
180 & pln(1,j),plntop(1,j),mp,
181 & w(1,1),wtop(1,1),g(1,1,1),idir)
182 CALL sptranf1(iromb,maxwv,idrt,imax,jmax,j,j,
183 & eps,epstop,enn1,elonn1,eon,eontop,
184 & afft_tmp,clat(j),slat(j),wlat(j),
185 & pln(1,j),plntop(1,j),mp,
186 & w(1,2),wtop(1,2),g(1,1,2),idir)
187 ENDIF
188 ENDDO
189 CALL spuv2dz(iromb,maxwv,enn1,elonn1,eon,eontop,
190 & w(1,1),w(1,2),wtop(1,1),wtop(1,2),
191 & winc(1,1),winc(1,2))
192 waved(kws+1:kws+2*mx)=waved(kws+1:kws+2*mx)+winc(1:2*mx,1)
193 wavez(kws+1:kws+2*mx)=wavez(kws+1:kws+2*mx)+winc(1:2*mx,2)
194 ENDDO
195 ENDIF
196 END
subroutine spdz2uv(I, M, ENN1, ELONN1, EON, EONTOP, D, Z, U, V, UTOP, VTOP)
Computes the wind components from divergence and vorticity in spectral space.
Definition: spdz2uv.f:49
subroutine sptranf0(IROMB, MAXWV, IDRT, IMAX, JMAX, JB, JE, EPS, EPSTOP, ENN1, ELONN1, EON, EONTOP, AFFT, CLAT, SLAT, WLAT, PLN, PLNTOP)
This subprogram performs an initialization for subprogram sptranf().
Definition: sptranf0.f:37
subroutine sptranf1(IROMB, MAXWV, IDRT, IMAX, JMAX, JB, JE, EPS, EPSTOP, ENN1, ELONN1, EON, EONTOP, AFFT, CLAT, SLAT, WLAT, PLN, PLNTOP, MP, W, WTOP, G, IDIR)
This subprogram performs an single latitude transform for subprogram sptranf().
Definition: sptranf1.f:44
subroutine sptranfv(IROMB, MAXWV, IDRT, IMAX, JMAX, KMAX, IP, IS, JN, JS, KW, KG, JB, JE, JC, WAVED, WAVEZ, GRIDUN, GRIDUS, GRIDVN, GRIDVS, IDIR)
This subprogram performs a spherical transform between spectral coefficients of divergences and curls...
Definition: sptranfv.f:83
subroutine spuv2dz(I, M, ENN1, ELONN1, EON, EONTOP, U, V, UTOP, VTOP, D, Z)
Computes the divergence and vorticity from wind components in spectral space.
Definition: spuv2dz.f:49