NCEPLIBS-sp  2.5.0
sptranf.f
Go to the documentation of this file.
1 C> @file
2 C> @brief Perform a scalar spherical transform
3 C>
4 C> ### Program History Log
5 C> Date | Programmer | Comments
6 C> -----|------------|---------
7 C> 96-02-29 | Iredell | Initial.
8 C> 1998-12-15 | Iredell | Generic fft used, openmp directives inserted
9 C> 2013-01-16 | Iredell, Mirvis | Fixing afft negative sharing effect
10 C>
11 C> @author Iredell @date 96-02-29
12 
13 C> This subprogram performs a spherical transform between spectral
14 C> coefficients of scalar quantities and fields on a global
15 C> cylindrical grid.
16 C>
17 C> The wave-space can be either triangular or
18 C> rhomboidal. The grid-space can be either an equally-spaced grid
19 C> (with or without pole points) or a Gaussian grid.
20 C>
21 C> The wave and grid fields may have general indexing,
22 C> but each wave field is in sequential 'ibm order',
23 C> i.e. with zonal wavenumber as the slower index.
24 C>
25 C> Transforms are done in latitude pairs for efficiency;
26 C> thus grid arrays for each hemisphere must be passed.
27 C>
28 C> If so requested, just a subset of the latitude pairs
29 C> may be transformed in each invocation of the subprogram.
30 C> The transforms are all multiprocessed over latitude except
31 C> the transform from fourier to spectral is multiprocessed
32 C> over zonal wavenumber to ensure reproducibility.
33 C>
34 C> Transform several fields at a time to improve vectorization.
35 C> Subprogram can be called from a multiprocessing environment.
36 C>
37 C> Minimum grid dimensions for unaliased transforms to spectral:
38 C> DIMENSION |LINEAR |QUADRATIC
39 C> ----------------------- |--------- |-------------
40 C> IMAX | 2*MAXWV+2 | 3*MAXWV/2*2+2
41 C> JMAX (IDRT=4,IROMB=0) | 1*MAXWV+1 | 3*MAXWV/2+1
42 C> JMAX (IDRT=4,IROMB=1) | 2*MAXWV+1 | 5*MAXWV/2+1
43 C> JMAX (IDRT=0,IROMB=0) | 2*MAXWV+3 | 3*MAXWV/2*2+3
44 C> JMAX (IDRT=0,IROMB=1) | 4*MAXWV+3 | 5*MAXWV/2*2+3
45 C> JMAX (IDRT=256,IROMB=0) | 2*MAXWV+1 | 3*MAXWV/2*2+1
46 C> JMAX (IDRT=256,IROMB=1) | 4*MAXWV+1 | 5*MAXWV/2*2+1
47 C>
48 C> @param IROMB spectral domain shape
49 c> (0 for triangular, 1 for rhomboidal)
50 C> @param MAXWV spectral truncation
51 C> @param IDRT grid identifier
52 C> - IDRT=4 for Gaussian grid,
53 C> - IDRT=0 for equally-spaced grid including poles
54 C> - IDRT=256 for equally-spaced grid excluding poles
55 C> @param IMAX even number of longitudes.
56 C> @param JMAX number of latitudes.
57 C> @param KMAX number of fields to transform.
58 C> @param IP longitude index for the prime meridian
59 C> @param IS skip number between longitudes
60 C> @param JN skip number between n.h. latitudes from north
61 C> @param JS skip number between s.h. latitudes from south
62 C> @param KW skip number between wave fields
63 C> @param KG skip number between grid fields
64 C> @param JB latitude index (from pole) to begin transform
65 C> @param JE latitude index (from pole) to end transform
66 C> @param JC number of cpus over which to multiprocess
67 C> @param[out] WAVE wave fields if IDIR>0
68 C> @param[out] GRIDN n.h. grid fields (starting at JB) if IDIR<0
69 C> @param[out] GRIDS s.h. grid fields (starting at JB) if IDIR<0
70 C> @param IDIR transform flag
71 C> (IDIR>0 for wave to grid, IDIR<0 for grid to wave)
72 C>
73 C> @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 
91 C 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)
96 C - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
97 C TRANSFORM WAVE TO GRID
98  IF(idir.GT.0) THEN
99 C$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 
128 C TRANSFORM GRID TO WAVE
129  ELSE
130 C$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