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 IGGMEM (KPR, KERR)
12C
13C---->
14C**** *IGGMEM*
15C
16C     PURPOSE
17C     _______
18C
19C     This routine acquires heap space for regular_gg to regular_ll
20C     interpolations.
21C
22C     INTERFACE
23C     _________
24C
25C     IERR = IGGMEM (KPR, KERR)
26C
27C     Input parameters
28C     ________________
29C
30C     KPR        - The debug print switch.
31C                  0  , No debugging output.
32C                  1  , Produce debugging output.
33C
34C     KERR       - The error control flag.
35C                  -ve, No error message. Return error code.
36C                  0  , Hard failure with error message.
37C                  +ve, Print error message. Return error code.
38C
39C     Output parameters
40C     ________________
41C
42C     None
43C
44C     Return value
45C     ____________
46C
47C     The error indicator (INTEGER).
48C
49C     Error and Warning Return Values
50C     _______________________________
51C
52C     None
53C
54C     Common block usage
55C     __________________
56C
57C     nifld.common - This file contains all the input field
58C                    definition variables.
59C
60C     NINS         - Number of grid points in NS direction for input
61C                    field (used in grspace.h).
62C     NIWE         - Number of grid points in WE direction for input
63C                    field (used in grspace.h).
64C
65C     nofld.common - This file contains all the output field
66C                    definition variables.
67C
68C     NONS         - Number of grid points in NS direction for output
69C                    field (used in grspace.h).
70C     NOWE         - Number of grid points in WE direction for output
71C                    field (used in grspace.h).
72C
73C     grspace.h    - This file contains all the work space array
74C                    definitions for grid point to grid point
75C                    interpolation.
76C
77C     GRID_POINT
78C
79C     NILATGP      - POINTER to array MILATG.
80C     NILONGP      - POINTER to array MILONG.
81C     NILSMP       - POINTER to array MILSM.
82C     NINPNTP      - POINTER to array RINPNT.
83C     NISTRTP      - POINTER to array MISTRT.
84C     NNSDISTP     - POINTER to array MNSDIST.
85C     NNSINDP      - POINTER to array MNSIND.
86C     NMAXP        - POINTER to array RMAX.
87C     NOLATGP      - POINTER to array MOLATG.
88C     NOLONGP      - POINTER to array MOLONG.
89C     NOLSMP       - POINTER to array MOLSM.
90C     NWEDISTP     - POINTER to array MWEDIST.
91C     NWEINDP      - POINTER to array MWEIND.
92C     NWFACTP      - POINTER to array WFACT.
93C
94C     MILATG       - Dynamic array of length (NINS) (see nifld.common)
95C                    which holds the values of the input field
96C                    latitudes.
97C     MILONG       - Dynamic array of length (NIWE + 1) (see
98C                    nifld.common) which holds the values of the
99C                    input field longitudes.
100C     MILSM        - Dynamic array of length (NIWE, 2) (see
101C                    nifld.common) used in calculating the effects of
102C                    the land sea mask on interpolation.
103C     MISTRT       - Dynamic array of length (NINS) (see nifld.common)
104C                    which holds the array offsets of the start of
105C                    each latitude line for a quasi regular Gaussian
106C                    input field. No space is assigned to this array
107C                    for a regular input field.
108C     MNSDIST      - Dynamic array of length (2, NONS) (see
109C                    nofld.common) which holds the distances to
110C                    neighbouring latitude lines of the input field
111C                    from the associated line of latitude in the
112C                    output field.
113C     MNSIND       - Dynamic array of length (2, NONS) (see
114C                    nofld.common) which holds the latitude line
115C                    numbers (array offset) of the input field
116C                    associated with each line of latitude in the
117C                    output field.
118C     MOLATG       - Dynamic array of length (NONS) (see nofld.common)
119C                    which holds the values of the output field
120C                    latitudes.
121C     MOLONG       - Dynamic array of length (NOWE) (see nofld.common)
122C                    which holds the values of the output field
123C                    longitudes.
124C     MOLSM        - Dynamic array of length (NOWE) (see nofld.common)
125C                    used in calculating the effects of the land sea
126C                    mask on interpolation.
127C     MWEDIST      - Dynamic array of length (2, NONS) for a regular
128C                    input field and of length (2, 2 * NONS * NOWE)
129C                    (see nofld.common) for a quasi regular Gaussian
130C                    input field.
131C                    This array holds the distances to neighbouring
132C                    longitude points of the input field from the
133C                    associated longitude points in the output field.
134C     MWEIND       - Dynamic array of length (2, NONS) for a regular
135C                    input field and of length (2, 2 * NONS * NOWE)
136C                    (see nofld.common) for a quasi regular Gaussian
137C                    input field.
138C                    This array holds the longitude points (array
139C                    offset) from the input field associated with each
140C                    longitude point in the output field.
141C     RINPNT       - Dynamic array of length (NOWE) (see nofld.common)
142C                    used to aid vectorisation in processing
143C                    precipitation fields.
144C     RMAX         - Dynamic array of length (NOWE) (see nofld.common)
145C                    used to aid vectorisation in processing
146C                    precipitation fields.
147C     WFACT        - Dynamic array of length (4, NOWE * NONS) (see
148C                    nofld.common) which holds the interpolation
149C                    weights for each point in the output field.
150C
151C     EXTERNALS
152C     _________
153C
154C     IGALLOC    - Get a heap allocation for array space.
155C     INTLOG     - Logs messages.
156C
157C     METHOD
158C     ______
159C
160C     This routine calculates how much heap space is required. IGALLOC
161C     is then used to acquire the required space. Finally the POINTERs
162C     in grspace.h are initialised to allow using the dynamic arrays.
163C
164C     REFERENCE
165C     _________
166C
167C     None
168C
169C     COMMENTS
170C     ________
171C
172C     Program contains sections 0 to 3 and 9
173C
174C     AUTHOR
175C     ______
176C
177C     K. Fielding      *ECMWF*      Jan 1994
178C
179C     MODIFICATIONS
180C     _____________
181C
182C     None
183C
184C----<
185
186
187C     Section 0. Definition of variables
188      IMPLICIT NONE
189
190#include "parim.h"
191#include "nifld.common"
192#include "nofld.common"
193#include "grspace.h"
194
195C     Dummy arguments
196      INTEGER KPR, KERR
197
198C     Local variables
199#ifdef POINTER_64
200      INTEGER*8 IBASE
201#else
202      INTEGER IBASE
203#endif
204      INTEGER*8 SIZES(14)
205      INTEGER IREQUEST, IERR, I
206
207C     External functions
208      INTEGER IGALLOC
209
210
211C     Section 1. Initialisation
212  100 CONTINUE
213      IF( KPR.GE.1 ) CALL INTLOG(JP_DEBUG,'IGGMEM: Section 1.',JPQUIET)
214      IGGMEM = 0
215
216
217C     Section 2. Calculate memory required and get heap
218  200 CONTINUE
219
220C     Specify array allocation sizes:
221C     - uses JPRLEN for REAL arrays
222C     - uses JPILEN for INTEGER arrays
223      SIZES( 1) = JPRLEN * (NOWE*NONS*4)    ! NWFACTP  / WFACT
224      SIZES( 2) = JPRLEN * (NOWE)           ! NMAXP    / RMAX   (#1 precipitation)
225      SIZES( 3) = JPRLEN * (NOWE)           ! NINPNTP  / RINPNT (#2)
226      SIZES( 4) = JPILEN * (NIWE+1)         ! NILONGP  / MILONG
227      SIZES( 5) = JPILEN * (NINS)           ! NILATGP  / MILATG
228      SIZES( 6) = JPILEN * (NOWE)           ! NOLONGP  / MOLONG
229      SIZES( 7) = JPILEN * (NONS)           ! NOLATGP  / MOLATG
230      SIZES( 8) = JPILEN * (NONS*2)         ! NNSINDP  / MNSIND
231      SIZES( 9) = JPILEN * (NONS*2)         ! NNSDISTP / MNSDIST
232      SIZES(10) = JPILEN * (NOWE*2)         ! NWEINDP  / MWEIND (*)
233      SIZES(11) = JPILEN * (NOWE*2)         ! NWEDISTP / MWEDIST (*)
234      SIZES(12) = JPILEN * 0                ! NISTRTP  / MISTRT (*)
235      SIZES(13) = JPILEN * (NIWE*2)         ! NILSMP   / MILSM (#1 lsm)
236      SIZES(14) = JPILEN * (NOWE)           ! NOLSMP   / MOLSM (#2)
237
238C     Get the required memory
239      IREQUEST = 0
240      DO I = 1, 14
241        IREQUEST = IREQUEST + SIZES(I)
242      ENDDO
243      IERR = IGALLOC(JPINNER,IREQUEST,IBASE,KPR,KERR)
244      IF (IERR.GT.0) THEN
245         IGGMEM = IERR
246         GOTO 900
247      ENDIF
248
249C     Set POINTER addresses
250      NWFACTP  = IBASE
251      NMAXP    = SIZES( 1) + NWFACTP
252      NINPNTP  = SIZES( 2) + NMAXP
253      NILONGP  = SIZES( 3) + NINPNTP
254      NILATGP  = SIZES( 4) + NILONGP
255      NOLONGP  = SIZES( 5) + NILATGP
256      NOLATGP  = SIZES( 6) + NOLONGP
257      NNSINDP  = SIZES( 7) + NOLATGP
258      NNSDISTP = SIZES( 8) + NNSINDP
259      NWEINDP  = SIZES( 9) + NNSDISTP
260      NWEDISTP = SIZES(10) + NWEINDP
261      NISTRTP  = SIZES(11) + NWEDISTP
262      NILSMP   = SIZES(12) + NISTRTP
263      NOLSMP   = SIZES(13) + NILSMP
264
265C     Display pointers information
266      IF( KPR.GE.1 ) THEN
267        CALL INTLOG(JP_DEBUG,'IGGMEM: ************************',JPQUIET)
268        CALL INTLOG(JP_DEBUG,'IGGMEM: * Output addresses:',     JPQUIET)
269        CALL INTLOG(JP_DEBUG,'IGGMEM: * (print might overflow)',JPQUIET)
270        CALL INTLOG(JP_DEBUG,'IGGMEM: - WFACT        = ',NWFACTP)
271        CALL INTLOG(JP_DEBUG,'IGGMEM: - RMAX         = ',NMAXP)
272        CALL INTLOG(JP_DEBUG,'IGGMEM: - RINPNT       = ',NINPNTP)
273        CALL INTLOG(JP_DEBUG,'IGGMEM: - Input long.  = ',NILONGP)
274        CALL INTLOG(JP_DEBUG,'IGGMEM: - Input lat.   = ',NILATGP)
275        CALL INTLOG(JP_DEBUG,'IGGMEM: - Output long. = ',NOLONGP)
276        CALL INTLOG(JP_DEBUG,'IGGMEM: - Output lat.  = ',NOLATGP)
277        CALL INTLOG(JP_DEBUG,'IGGMEM: - NS offset    = ',NNSINDP)
278        CALL INTLOG(JP_DEBUG,'IGGMEM: - NS distance  = ',NNSDISTP)
279        CALL INTLOG(JP_DEBUG,'IGGMEM: - WE offset    = ',NWEINDP)
280        CALL INTLOG(JP_DEBUG,'IGGMEM: - WE distance  = ',NWEDISTP)
281        CALL INTLOG(JP_DEBUG,'IGGMEM: - Line start   = ',NISTRTP)
282        CALL INTLOG(JP_DEBUG,'IGGMEM: - Input LSM    = ',NILSMP)
283        CALL INTLOG(JP_DEBUG,'IGGMEM: - Output LSM   = ',NOLSMP)
284        CALL INTLOG(JP_DEBUG,'IGGMEM: ***********************', JPQUIET)
285      ENDIF
286
287
288C     Section 9. Return to calling routine
289  900 CONTINUE
290      IF (KPR.GE.1)  CALL INTLOG(JP_DEBUG,'IGGMEM: Section 9.',JPQUIET)
291
292
293      END
294
295