File: hgengg.F

package info (click to toggle)
emoslib 000380%2Bdfsg-3
  • links: PTS
  • area: main
  • in suites: squeeze
  • size: 47,712 kB
  • ctags: 11,551
  • sloc: fortran: 89,643; ansic: 24,200; makefile: 370; sh: 355
file content (292 lines) | stat: -rwxr-xr-x 7,581 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
C Copyright 1981-2007 ECMWF
C 
C Licensed under the GNU Lesser General Public License which
C incorporates the terms and conditions of version 3 of the GNU
C General Public License.
C See LICENSE and gpl-3.0.txt for details.
C

      INTEGER FUNCTION HGENGG(AREA,POLE,KGNNEW,HGTYPE,KNPTS,GNLATS,
     X                        IGSIZE,RLAT,RLON,NUMPTS)
C
C---->
C**** HGENGG
C
C     Purpose
C     -------
C
C     This routine calculates the original latitude and longitude
C     values (before rotation) for a rotated gaussian grid.
C
C
C     Interface
C     ---------
C
C     IRET = HGENGG(AREA,POLE,KGNNEW,HGTYPE,KNPTS,IGSIZE,
C    X              RLAT,RLON,NUMPTS)
C
C
C     Input parameters
C     ----------------
C
C     AREA    - Limits of area (N/W/S/E)
C     POLE    - Pole of rotation (lat/long)
C     KGNNEW  - Gaussian number for field
C     HGTYPE  - Type of new gaussian field
C               'F' = full, ie regular
C               'R' = reduced, ie quasi-regular
C     KNPTS   - Array containing number of points at each latitude
C     GNLATS  - Array containing list of gaussian latitudes
C     IGSIZE  - The size of the array to fill with the gaussian field
C     NUMPTWE - Calculate number of grid pts in range from west to east
C
C
C     Output parameters
C     -----------------
C
C     RLAT  - Vector of orginal latitude values for the points in
C             the rotated grid.
C     RLON  - Vector of orginal longitude values for the points in
C             the rotated grid.
C     NUMPTS - Number of points in new field
C
C     Returns 0 if function successful, non-zero otherwise.
C
C
C     Common block usage
C     ------------------
C
C     None.
C
C
C     Method
C     ------
C
C     The vector of points runs from West to East in rows, the rows
C     run from North to South.
C
C
C     Externals
C     ---------
C
C     INTLOG  - Log error message.
C     JDEBUG  - Tests if debug output required.
C     HLL2XYZ - Converts a latitude/longitude position to (x,y,z)
C               wrt axes through the centre of the globe. The z-axis
C               runs from the south to north pole. The x- and y-axes
C               are in the plane of the equator with the x-axis
C               pointing out through lat/long (0,0).
C     YROTATE - Rotates the globe about the new y-axis.
C     XYZ2LL  - Converts an (x,y,z) position to a latitude/longitude.
C     JMALLOC - Dynamically allocate memory
C     JFREE   - Free dynamically allocated memory
C
C
C     Reference
C     ---------
C
C     None.
C
C
C     Comments
C     --------
C
C     None.
C
C
C     Author
C     ------
C
C     J.D.Chambers      ECMWF      February 2001
C
C
C     Modifications
C     -------------
C
C     None.
C
C----<
C     -----------------------------------------------------------------|
C*    Section 0. Definition of variables.
C     -----------------------------------------------------------------|
C
      IMPLICIT NONE
C
#include "parim.h"
#include "nofld.common"
C
C     Parameters
C
      INTEGER JNORTH, JSOUTH, JWEST, JEAST, JW_E, JN_S, JLAT, JLON
      REAL JSCALE
      PARAMETER (JNORTH = 1 )
      PARAMETER (JWEST  = 2 )
      PARAMETER (JSOUTH = 3 )
      PARAMETER (JEAST  = 4 )
      PARAMETER (JW_E  = 1 )
      PARAMETER (JN_S  = 2 )
      PARAMETER (JLAT  = 1 )
      PARAMETER (JLON  = 2 )
      PARAMETER (JSCALE  = 1000.0 )
C
C     Function arguments
C
      CHARACTER*1 HGTYPE
      INTEGER KGNNEW,KNPTS(KGNNEW*2),IGSIZE,NUMPTS
      REAL AREA(4),POLE(2),RLAT(*),RLON(*), GNLATS(KGNNEW*2)
C
C     Local variables
C
      INTEGER LOOP, LOOPI, LOOPO, IGRIDNI, NLON
      INTEGER ISIZE, ISIZOLD, NBYTES
      REAL GRID, X(1), Y(1), Z(1)
      REAL RX(1), RY(1), RZ(1)
      POINTER( IPX, X )
      POINTER( IPY, Y )
      POINTER( IPZ, Z )
      POINTER( IPRX, RX )
      POINTER( IPRY, RY )
      POINTER( IPRZ, RZ )
C
      DATA ISIZOLD/-1/
      SAVE ISIZOLD,IPX,IPY,IPZ,IPRX,IPRY,IPRZ
C
C     Externals
C
      INTEGER NUMPTWE
#ifdef POINTER_64
      INTEGER*8 JMALLOC
#else
      INTEGER JMALLOC
#endif
C
C     Statement functions
C
      REAL A, B
      LOGICAL SOUTHOF
      SOUTHOF(A,B) = ((A) - (B)).GT.-1E-4
C
C     -----------------------------------------------------------------|
C     Section 1.  Initialise.
C     -----------------------------------------------------------------|
C
  100 CONTINUE
C
      HGENGG = 0
C
      CALL JDEBUG()
C
C     -----------------------------------------------------------------|
C     Section 2.  Calculate current grid latitudes and longitudes
C     -----------------------------------------------------------------|
C
  200 CONTINUE
C
      GRID = 360.0 / REAL(KGNNEW*4)
      IGRIDNI = NINT(GRID*JSCALE)
C
      NUMPTS = 0
      NOPCNT = 0
      NONS   = 0
      NOWE   = 0
      NO1NS  = 0
C
      DO LOOPO = 1, KGNNEW*2
C
C       Generate points inside the area only.
C
        IF( SOUTHOF(AREA(JNORTH),GNLATS(LOOPO)).AND.
     X      SOUTHOF(GNLATS(LOOPO),AREA(JSOUTH)) ) THEN
C
          IF( NO1NS.EQ.0 ) NO1NS = LOOPO
          NONS = NONS + 1
C
C         Grid step varies for a reduced (quasi-regular) gaussian grid
C
          IF( HGTYPE.EQ.'R' ) THEN
            GRID = 360.0 / REAL(KNPTS(LOOPO))
            IGRIDNI = NINT(GRID*JSCALE)
          ENDIF
C
          NLON = NUMPTWE(AREA(JWEST),AREA(JEAST),GRID)
          NOWE = NLON
          DO LOOPI = 1, NLON
            NUMPTS = NUMPTS + 1
            RLAT(NUMPTS) = GNLATS(LOOPO)
            RLON(NUMPTS) = AREA(JWEST)+REAL((LOOPI-1)*IGRIDNI)/JSCALE
          ENDDO
        ENDIF
      ENDDO
C
C     -----------------------------------------------------------------|
C     Section 3.  Get some space for rotating the lat/longs
C     -----------------------------------------------------------------|
C
  300 CONTINUE
C
      NOPCNT = NUMPTS
      ISIZE  = NUMPTS
      IF( ISIZE.GT.ISIZOLD ) THEN
C
        IF( ISIZOLD.GT.0 ) CALL JFREE(IPX)
C
        NBYTES = 6*ISIZE*JPRLEN
C
        IPX = JMALLOC(NBYTES)
#ifdef hpR64
        IPX = IPX/(1024*1024*1024*4)
#endif
        IF( IPX.EQ.0 ) THEN
          CALL INTLOG(JP_WARN,'HGENGG: Memory allocate fail',JPQUIET)
          HGENGG = 1
          GOTO 900
        ENDIF
C
        IPY  = IPX  + (ISIZE*JPRLEN)
        IPZ  = IPY  + (ISIZE*JPRLEN)
        IPRX = IPZ  + (ISIZE*JPRLEN)
        IPRY = IPRX + (ISIZE*JPRLEN)
        IPRZ = IPRY + (ISIZE*JPRLEN)
C
        ISIZOLD = ISIZE
C
      ENDIF
C
C     -----------------------------------------------------------------|
C     Section 4.  Calculate the lat/longs before rotation
C     -----------------------------------------------------------------|
C
  400 CONTINUE
C
C     Convert the rotated row points lat/longs to (x,y,z) coordinates
C
      CALL HLL2XYZ(RLAT,RLON,X,Y,Z,ISIZE)
C
C     Rotate the rotated row points back through the original latitude
C     rotation
C
      CALL YROTATE(-(90.0+POLE(JLAT)),X,Y,Z,RX,RY,RZ,ISIZE)
C
C     Convert the rotated row points adjusted (x,y,z) coordinates to
C     lat/long in the original grid (but still containing the
C     longitude rotation)
C
      CALL XYZ2LL(RX,RY,RZ,RLAT,RLON,ISIZE)
C
C     Adjust the rotated line longitudes to remove the longitude
C     rotation
C
      DO LOOP = 1, ISIZE
        RLON(LOOP) = RLON(LOOP) + POLE(JLON)
        IF( RLON(LOOP).LT.0.0 )   RLON(LOOP) = RLON(LOOP) + 360.0
        IF( RLON(LOOP).GE.360.0 ) RLON(LOOP) = RLON(LOOP) - 360.0
      ENDDO
C
C     -----------------------------------------------------------------|
C     Section 9.  Return
C     -----------------------------------------------------------------|
C
  900 CONTINUE
C
      RETURN
      END