1C Copyright 1981-2016 ECMWF.
2C
3C This software is licensed under the terms of the Apache Licence
4C Version 2.0 which can be obtained at http://www.apache.org/licenses/LICENSE-2.0.
5C
6C In applying this licence, ECMWF does not waive the privileges and immunities
7C granted to it by virtue of its status as an intergovernmental organisation
8C nor does it submit to any jurisdiction.
9C
10
11       SUBROUTINE RPHI( DATA, NM, WORK, SLON)
12C
13C---->
14C**** RPHI
15C
16C     Purpose
17C     -------
18C
19C     Rotates spectral coefficients by longitude.
20C
21C
22C     Interface
23C     ---------
24C
25C     CALL RPHI(DATA,NM,WORK,SLON)
26C
27C     Input
28C     -----
29C
30C     DATA   = Input spectral field of REAL*8s of size (NM+1)*(NM+2).
31C     NM     = Triangular truncation (e.g. 106)
32C     WORK   = Work space of size at least 2*(NM+1).
33C     SLON   = Rotation angle (REAL*8).
34C              (degrees, positive => rotate west to east).
35C
36C     Output
37C     ------
38C
39C     Transformed fields are returned in data.
40C
41C
42C     Method
43C     ------
44C
45C     See reference below.
46C
47C
48C     Externals
49C     ---------
50C
51C     None.
52C
53C
54C     Author
55C     ------
56C
57C     R.McGrath and P.Lynch    HIRLAM
58C
59C
60C     Reference.
61C     ----------
62C
63C     "Spectral synthesis on rotated and regular grids"
64C     by P.Lynch and R.McGrath (Irish Meteorological Service).
65C
66C
67C     Modifications
68C     -------------
69C
70C     J.D.Chambers       ECMWF     October 1995
71C     Reformat and put into clearcase.
72C
73C ------------------------------------------------------------------
74C----<
75C
76      IMPLICIT NONE
77C
78#include "jparams.h"
79C
80C     Function arguments
81      COMPLEX*16 DATA
82      COMPLEX*16 WORK
83      DIMENSION DATA(*), WORK(*)
84      REAL*8 SLON
85      INTEGER NM
86C
87C     Parameters
88      INTEGER JPROUTINE
89      PARAMETER (JPROUTINE = 26000 )
90C
91C     Local variables
92      COMPLEX*16 CC
93      INTEGER IPMN, NS, M, J
94      REAL*8 RAD, XLON
95C
96C ------------------------------------------------------------------
97C*    Section 1.   Initialise
98C ------------------------------------------------------------------
99C
100  100 CONTINUE
101C
102      IPMN = ((NM+1)*(NM+2))/2
103      RAD  = 180.0/PPI
104      XLON = -SLON/RAD
105C
106C ------------------------------------------------------------------
107C*    Section 2.   Transform the fields.
108C ------------------------------------------------------------------
109C
110  200 CONTINUE
111C
112      NS = 1
113      CC = (1.0,0.0)
114C
115      DO 215 M = 1,NM+1
116        DO 210 J = NS,NS+NM-M+1
117          WORK(J) = CC
118  210   CONTINUE
119C
120        NS = J
121        CC = CEXP(CMPLX(0.0,REAL(XLON*M)))
122  215 CONTINUE
123C
124C     Transform fields in output array.
125        DO 220 J = 1,IPMN
126          DATA(J) = WORK(J)*DATA(J)
127  220   CONTINUE
128C
129C ------------------------------------------------------------------
130C*    Section 9.   Return.
131C ------------------------------------------------------------------
132C
133  900 CONTINUE
134C
135      RETURN
136      END
137