NCEPLIBS-sp 2.4.0
sptranf.f
Go to the documentation of this file.
1C> @file
2C> @brief Perform a scalar 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
10C>
11C> @author Iredell @date 96-02-29
12
13C> This subprogram performs a spherical transform between spectral
14C> coefficients of scalar quantities and fields on a global
15C> cylindrical grid.
16C>
17C> The wave-space can be either triangular or
18C> rhomboidal. The grid-space can be either an equally-spaced grid
19C> (with or without pole points) or a Gaussian grid.
20C>
21C> The wave and grid fields may have general indexing,
22C> but each wave field is in sequential 'ibm order',
23C> i.e. with zonal wavenumber as the slower index.
24C>
25C> Transforms are done in latitude pairs for efficiency;
26C> thus grid arrays for each hemisphere must be passed.
27C>
28C> If so requested, just a subset of the latitude pairs
29C> may be transformed in each invocation of the subprogram.
30C> The transforms are all multiprocessed over latitude except
31C> the transform from fourier to spectral is multiprocessed
32C> over zonal wavenumber to ensure reproducibility.
33C>
34C> Transform several fields at a time to improve vectorization.
35C> Subprogram can be called from a multiprocessing environment.
36C>
37C> Minimum grid dimensions for unaliased transforms to spectral:
38C> DIMENSION |LINEAR |QUADRATIC
39C> ----------------------- |--------- |-------------
40C> IMAX | 2*MAXWV+2 | 3*MAXWV/2*2+2
41C> JMAX (IDRT=4,IROMB=0) | 1*MAXWV+1 | 3*MAXWV/2+1
42C> JMAX (IDRT=4,IROMB=1) | 2*MAXWV+1 | 5*MAXWV/2+1
43C> JMAX (IDRT=0,IROMB=0) | 2*MAXWV+3 | 3*MAXWV/2*2+3
44C> JMAX (IDRT=0,IROMB=1) | 4*MAXWV+3 | 5*MAXWV/2*2+3
45C> JMAX (IDRT=256,IROMB=0) | 2*MAXWV+1 | 3*MAXWV/2*2+1
46C> JMAX (IDRT=256,IROMB=1) | 4*MAXWV+1 | 5*MAXWV/2*2+1
47C>
48C> @param IROMB spectral domain shape
49c> (0 for triangular, 1 for rhomboidal)
50C> @param MAXWV spectral truncation
51C> @param IDRT grid identifier
52C> - IDRT=4 for Gaussian grid,
53C> - IDRT=0 for equally-spaced grid including poles
54C> - IDRT=256 for equally-spaced grid excluding poles
55C> @param IMAX even number of longitudes.
56C> @param JMAX number of latitudes.
57C> @param KMAX number of fields to transform.
58C> @param IP longitude index for the prime meridian
59C> @param IS skip number between longitudes
60C> @param JN skip number between n.h. latitudes from north
61C> @param JS skip number between s.h. latitudes from south
62C> @param KW skip number between wave fields
63C> @param KG skip number between grid fields
64C> @param JB latitude index (from pole) to begin transform
65C> @param JE latitude index (from pole) to end transform
66C> @param JC number of cpus over which to multiprocess
67C> @param[out] WAVE wave fields if IDIR>0
68C> @param[out] GRIDN n.h. grid fields (starting at JB) if IDIR<0
69C> @param[out] GRIDS s.h. grid fields (starting at JB) if IDIR<0
70C> @param IDIR transform flag
71C> (IDIR>0 for wave to grid, IDIR<0 for grid to wave)
72C>
73C> @author Iredell @date 96-02-29
74 SUBROUTINE sptranf(IROMB,MAXWV,IDRT,IMAX,JMAX,KMAX,
75 & IP,IS,JN,JS,KW,KG,JB,JE,JC,
76 & WAVE,GRIDN,GRIDS,IDIR)
77
78 REAL WAVE(*),GRIDN(*),GRIDS(*)
79 REAL EPS((MAXWV+1)*((IROMB+1)*MAXWV+2)/2),EPSTOP(MAXWV+1)
80 REAL ENN1((MAXWV+1)*((IROMB+1)*MAXWV+2)/2)
81 REAL ELONN1((MAXWV+1)*((IROMB+1)*MAXWV+2)/2)
82 REAL EON((MAXWV+1)*((IROMB+1)*MAXWV+2)/2),EONTOP(MAXWV+1)
83 REAL(8) AFFT(50000+4*IMAX), AFFT_TMP(50000+4*IMAX)
84 REAL CLAT(JB:JE),SLAT(JB:JE),WLAT(JB:JE)
85 REAL PLN((MAXWV+1)*((IROMB+1)*MAXWV+2)/2,JB:JE)
86 REAL PLNTOP(MAXWV+1,JB:JE)
87 REAL WTOP(2*(MAXWV+1))
88 REAL G(IMAX,2)
89! write(0,*) 'sptranf top'
90
91C SET PARAMETERS
92 mp=0
93 CALL sptranf0(iromb,maxwv,idrt,imax,jmax,jb,je,
94 & eps,epstop,enn1,elonn1,eon,eontop,
95 & afft,clat,slat,wlat,pln,plntop)
96C - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
97C TRANSFORM WAVE TO GRID
98 IF(idir.GT.0) THEN
99C$OMP PARALLEL DO PRIVATE(AFFT_TMP,KWS,WTOP,G,IJKN,IJKS)
100 DO k=1,kmax
101 afft_tmp=afft
102 kws=(k-1)*kw
103 wtop=0
104 DO j=jb,je
105 CALL sptranf1(iromb,maxwv,idrt,imax,jmax,j,j,
106 & eps,epstop,enn1,elonn1,eon,eontop,
107 & afft_tmp,clat(j),slat(j),wlat(j),
108 & pln(1,j),plntop(1,j),mp,
109 & wave(kws+1),wtop,g,idir)
110 IF(ip.EQ.1.AND.is.EQ.1) THEN
111 DO i=1,imax
112 ijkn=i+(j-jb)*jn+(k-1)*kg
113 ijks=i+(j-jb)*js+(k-1)*kg
114 gridn(ijkn)=g(i,1)
115 grids(ijks)=g(i,2)
116 ENDDO
117 ELSE
118 DO i=1,imax
119 ijkn=mod(i+ip-2,imax)*is+(j-jb)*jn+(k-1)*kg+1
120 ijks=mod(i+ip-2,imax)*is+(j-jb)*js+(k-1)*kg+1
121 gridn(ijkn)=g(i,1)
122 grids(ijks)=g(i,2)
123 ENDDO
124 ENDIF
125 ENDDO
126 ENDDO
127
128C TRANSFORM GRID TO WAVE
129 ELSE
130C$OMP PARALLEL DO PRIVATE(AFFT_TMP,KWS,WTOP,G,IJKN,IJKS)
131 DO k=1,kmax
132 afft_tmp=afft
133 kws=(k-1)*kw
134 wtop=0
135 DO j=jb,je
136 IF(wlat(j).GT.0.) THEN
137 IF(ip.EQ.1.AND.is.EQ.1) THEN
138 DO i=1,imax
139 ijkn=i+(j-jb)*jn+(k-1)*kg
140 ijks=i+(j-jb)*js+(k-1)*kg
141 g(i,1)=gridn(ijkn)
142 g(i,2)=grids(ijks)
143 ENDDO
144 ELSE
145 DO i=1,imax
146 ijkn=mod(i+ip-2,imax)*is+(j-jb)*jn+(k-1)*kg+1
147 ijks=mod(i+ip-2,imax)*is+(j-jb)*js+(k-1)*kg+1
148 g(i,1)=gridn(ijkn)
149 g(i,2)=grids(ijks)
150 ENDDO
151 ENDIF
152 CALL sptranf1(iromb,maxwv,idrt,imax,jmax,j,j,
153 & eps,epstop,enn1,elonn1,eon,eontop,
154 & afft_tmp,clat(j),slat(j),wlat(j),
155 & pln(1,j),plntop(1,j),mp,
156 & wave(kws+1),wtop,g,idir)
157 ENDIF
158 ENDDO
159 ENDDO
160 ENDIF
161 END
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 sptranf(IROMB, MAXWV, IDRT, IMAX, JMAX, KMAX, IP, IS, JN, JS, KW, KG, JB, JE, JC, WAVE, GRIDN, GRIDS, IDIR)
This subprogram performs a spherical transform between spectral coefficients of scalar quantities and...
Definition: sptranf.f:77