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      INTEGER FUNCTION IGNORM (PWFACT, PSUM, KOWE, KONS, KPR, KERR)
12C
13C---->
14C**** *IGNORM*
15C
16C     PURPOSE
17C     _______
18C
19C     Normalise the array of interpolation weights.
20C
21C     INTERFACE
22C     _________
23C
24C     IERR = IGNORM (PWFACT, PSUM, KOWE, KONS, KPR, KERR)
25C
26C     Input parameters
27C     ________________
28C
29C     PWFACT     - The array of unnormalised interpolating weights to
30C                  the four neighbouring points for every output point.
31C
32C     PSUM       - Work array used to aid vectorisation.
33C
34C     KOWE       - The number of points in the West-East direction in
35C                  the output field.
36C
37C     KONS       - The number of points in the North-South direction
38C                  in the output field.
39C
40C     KPR        - The debug print switch.
41C                  0  , No debugging output.
42C                  1  , Produce debugging output.
43C
44C     KERR       - The error control flag.
45C                  -ve, No error message. Return error code.
46C                  0  , Hard failure with error message.
47C                  +ve, Print error message. Return error code.
48C
49C     Output parameters
50C     ________________
51C
52C     PWFACT     - The normalised array of interpolating weights to
53C                  the four neighbouring points for every output point.
54C
55C     Return value
56C     ____________
57C
58C     The error indicator (INTEGER).
59C
60C     Error and Warning Return Values
61C     _______________________________
62C
63C     None
64C
65C     Common block usage
66C     __________________
67C
68C     None
69C
70C     EXTERNALS
71C     _________
72C
73C     INTLOG(R)    - Logs messages.
74C
75C     METHOD
76C     ______
77C
78C     The four weights for each output point are normalised to have a
79C     sum of one.
80C
81C     REFERENCE
82C     _________
83C
84C     None
85C
86C     COMMENTS
87C     ________
88C
89C     Program contains sections 0 to 2 and 9
90C
91C     AUTHOR
92C     ______
93C
94C     K. Fielding      *ECMWF*      Oct 1993
95C
96C     MODIFICATIONS
97C     _____________
98C
99C     None
100C
101C----<
102C     _______________________________________________________
103C
104C
105C*    Section 0. Definition of variables.
106C     _______________________________________________________
107C
108C*    Prefix conventions for variable names
109C
110C     Logical      L (but not LP), global or common.
111C                  O, dummy argument
112C                  G, local variable
113C                  LP, parameter.
114C     Character    C, global or common.
115C                  H, dummy argument
116C                  Y (but not YP), local variable
117C                  YP, parameter.
118C     Integer      M and N, global or common.
119C                  K, dummy argument
120C                  I, local variable
121C                  J (but not JP), loop control
122C                  JP, parameter.
123C     REAL         A to F and Q to X, global or common.
124C                  P (but not PP), dummy argument
125C                  Z, local variable
126C                  PP, parameter.
127C
128C     Implicit statement to force declarations
129C
130      IMPLICIT NONE
131C
132#include "parim.h"
133C
134C     Dummy arguments
135      INTEGER KOWE, KONS, KPR, KERR
136      REAL PWFACT (4, KOWE, KONS), PSUM (KOWE)
137C
138C     Local variables
139      INTEGER JOLAT, JOLON, JDIR
140      INTEGER JPROUTINE
141      PARAMETER (JPROUTINE = 25600)
142C
143C     _______________________________________________________
144C
145C*    Section 1. Initialisation
146C     _______________________________________________________
147C
148  100 CONTINUE
149C
150      IF (KPR.GE.1) CALL INTLOG(JP_DEBUG,'IGNORM: Section 1.',JPQUIET)
151C
152      IGNORM = 0
153C
154      IF (KPR .GE. 1) THEN
155        CALL INTLOG(JP_DEBUG,'IGNORM: No of output longitudes = ',KOWE)
156        CALL INTLOG(JP_DEBUG,'IGNORM: No of output latitudes  = ',KONS)
157      ENDIF
158C
159C     _______________________________________________________
160C
161C*    Section 2. Calculate arrays of weights
162C     _______________________________________________________
163C
164  200 CONTINUE
165C
166      IF (KPR.GE.1) CALL INTLOG(JP_DEBUG,'IGNORM: Section 2.',JPQUIET)
167C
168      DO 260 JOLAT = 1, KONS
169C
170         DO 210 JOLON = 1, KOWE
171C
172            PSUM (JOLON) = PPZERO
173C
174  210    CONTINUE
175C
176         DO 230 JDIR = 1, 4
177            DO 220 JOLON = 1, KOWE
178C
179               PSUM (JOLON) = PSUM (JOLON) +
180     1            PWFACT (JDIR, JOLON, JOLAT)
181C
182  220       CONTINUE
183  230    CONTINUE
184C
185         DO 250 JDIR = 1, 4
186            DO 240 JOLON = 1, KOWE
187C
188               PWFACT (JDIR, JOLON, JOLAT) =
189     1            PWFACT (JDIR, JOLON, JOLAT) / PSUM (JOLON)
190C
191  240       CONTINUE
192  250    CONTINUE
193C
194  260 CONTINUE
195C
196C     _______________________________________________________
197C
198C*    Section 9. Return to calling routine. Format statements
199C     _______________________________________________________
200C
201  900 CONTINUE
202C
203      IF (KPR.GE.1) CALL INTLOG(JP_DEBUG,'IGNORM: Section 9.',JPQUIET)
204C
205C
206      RETURN
207      END
208