File: jmakll3.F

package info (click to toggle)
emoslib 2%3A4.4.5-2
  • links: PTS
  • area: main
  • in suites: stretch
  • size: 359,232 kB
  • ctags: 13,125
  • sloc: fortran: 93,166; ansic: 27,958; sh: 7,500; f90: 5,209; perl: 604; cpp: 305; makefile: 78; python: 53
file content (235 lines) | stat: -rw-r--r-- 6,237 bytes parent folder | download | duplicates (6)
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
C Copyright 1981-2016 ECMWF.
C
C This software is licensed under the terms of the Apache Licence
C Version 2.0 which can be obtained at http://www.apache.org/licenses/LICENSE-2.0.
C
C In applying this licence, ECMWF does not waive the privileges and immunities
C granted to it by virtue of its status as an intergovernmental organisation
C nor does it submit to any jurisdiction.
C

      SUBROUTINE JMAKLL3( KUNIT, KTRUNC, PINTVL, PLAT, PLEG, KRET)
C
C---->
C**** JMAKLL
C
C     PURPOSE
C     _______
C
C     This routine creates legendre functions for latitude rows upto
C     the given latitude in a 'non-standard truncation/interval' file.
C
C     INTERFACE
C     _________
C
C     CALL JMAKLL( KUNIT, KTRUNC, PINTVL, PLAT, PLEG, KRET)
C
C     Input parameters
C     ________________
C
C     KUNIT   - Unit number for open file of legendre functions.
C     KTRUNC  - Truncation.
C     PINTVL  - Grid interval (degrees)
C     PLAT    - Latitude in degrees.
C
C     Output parameters
C     ________________
C
C     PLEG     - Array of legendre functions for the latitude.
C     KRET     - Return status code
C                0 = OK
C
C     Common block usage
C     __________________
C
C     JDCNDBG
C
C     Method
C     ______
C
C     Determine which functions already exist for the latitude rows
C     in the file, skip to the end and create necessary extra functions
C     and add to the file.
C
C     Externals
C     _________
C
C     PBSEEK    - Position the coefficients file
C     PBWRITE   - Write the coefficients file
C     INTLOG   - Output log message
C     INTLOGR  - Output log message (with real value)
C
C     Reference
C     _________
C
C     None.
C
C     Comments
C     ________
C
C     Only positive latitude values are allowed.
C
C     AUTHOR
C     ______
C
C     J.D.Chambers      *ECMWF*      Dec 1993
C
C     MODIFICATIONS
C     _____________
C
C     None.
C
C----<
C     _______________________________________________________
C
C
C*    Section 0. Definition of variables.
C     _______________________________________________________
C
C*    Prefix conventions for variable names
C
C     Logical      L (but not LP), global or common.
C                  O, dummy argument
C                  G, local variable
C                  LP, parameter.
C     Character    C, global or common.
C                  H, dummy argument
C                  Y (but not YP), local variable
C                  YP, parameter.
C     Integer      M and N, global or common.
C                  K, dummy argument
C                  I, local variable
C                  J (but not JP), loop control
C                  JP, parameter.
C     REAL         A to F and Q to X, global or common.
C                  P (but not PP), dummy argument
C                  Z, local variable
C                  PP, parameter.
C
      IMPLICIT NONE
C
#include "jparams.h"
#include "parim.h"
C
C     Parameters
C
      INTEGER JPROUTINE
      PARAMETER ( JPROUTINE = 30500 )
C
C     Subroutine arguments
C
      INTEGER KUNIT, KTRUNC, KRET
      REAL PLEG, PINTVL, PLAT
      DIMENSION PLEG(*)
C
C     Local variables
C
      INTEGER NEWPOS, NSIZE, NRET, NROWCT, NBYTES
      REAL ZLATEST, ZLAT, ALAT, PIBY2, DEG2RAD
      INTEGER NEXT, FIRST, LAST
C
C     _______________________________________________________
C
C*    Section 1.    Initialization.
C     _______________________________________________________
C
 100  CONTINUE
C
      IF( NDBG.GT.1 ) THEN
        CALL INTLOG(JP_DEBUG,'JMAKLL3: Input parameters:',JPQUIET)
        CALL INTLOG(JP_DEBUG,
     X    'JMAKLL3: Unit number for leg.funcs file =', KUNIT)
        CALL INTLOG(JP_DEBUG,'JMAKLL3: Truncation = ', KTRUNC)
        CALL INTLOGR(JP_DEBUG,
     X    'JMAKLL3: Grid interval (degrees) = ', PINTVL)
        CALL INTLOGR(JP_DEBUG,
     X    'JMAKLL3: Latitude in degrees = ', PLAT)
      ENDIF
C
      IF( PLAT.LT.0.0 ) THEN
        ZLAT = 0.0
      ELSE
        ZLAT = PLAT
      ENDIF
C
C     Calculate the byte offset into the file where the legendre
C     functions for the latitude should be.
C
#ifdef REAL_8
      NSIZE   = 8 * (KTRUNC+1)*(KTRUNC+4)/2
#else
      NSIZE   = 4 * (KTRUNC+1)*(KTRUNC+4)/2
#endif
      NEWPOS = NINT( (90.0 - ZLAT)/PINTVL ) * NSIZE
C
C     Find the current file length
C
      CALL PBSEEK3( KUNIT, 0, 2, NRET)
      IF( NRET.LT.0 ) THEN
        CALL INTLOG(JP_ERROR,'JMAKLL3: PBSEEK error',NRET)
        KRET = JPROUTINE + 2
        GOTO 990
      ENDIF
C
C     Use the length to determine how many rows have already been
C     put into the file
C
      NROWCT = NRET/NSIZE
      ZLATEST  = 90.0 - REAL(NROWCT) * PINTVL
C
      IF( NDBG.GT.1 ) THen
        CALL INTLOG(JP_DEBUG,'JMAKLL3: File length on open = ', NRET)
        CALL INTLOG(JP_DEBUG,
     X    'JMAKLL3: Number of rows already in file = ', NROWCT)
        CALL INTLOGR(JP_DEBUG,
     X    'JMAKLL3: Next latitude to go in file = ', ZLATEST)
      ENDIF
C
C     _______________________________________________________
C
C*    Section 2.    Processing.
C     _______________________________________________________
C
C     Loop through latitudes not in the file yet
C
#ifdef REAL_8
      NBYTES = (KTRUNC+1)*(KTRUNC+4)/2  * 8
#else
      NBYTES = (KTRUNC+1)*(KTRUNC+4)/2  * 4
#endif
C
      IF( NDBG.GT.1 )
     X  CALL INTLOG(JP_DEBUG,'JMAKLL3: No. of bytes per row = ', NBYTES)
C
      PIBY2   = PPI / 2.0
      DEG2RAD = PPI / 180.0
C
      FIRST = NINT(ZLATEST/PINTVL)
      LAST  = NINT(ZLAT/PINTVL)
      DO NEXT = FIRST, LAST, -1
        ALAT = (NEXT*PINTVL) * DEG2RAD
C
        IF( NDBG.GT.1 ) CALL INTLOGR(JP_DEBUG,
     X    'JMAKLL3: Next latitude constructed = ', (NEXT*PINTVL))
C
        CALL JSPLEG1( PLEG, ALAT, KTRUNC)
        CALL PBWRITE3( KUNIT, PLEG, NBYTES, NRET)
        IF( NRET.LT.NSIZE ) THEN
          CALL INTLOG(JP_ERROR,'JMAKLL3: PBWRITE error.', NRET)
          CALL INTLOG(JP_ERROR,'JMAKLL3: bytes required = ', NSIZE)
          KRET = JPROUTINE + 3
          GOTO 990
        ENDIF
      ENDDO
C     _______________________________________________________
C
C*    Section 9. Return to calling routine. Format statements
C     _______________________________________________________
C
 900  CONTINUE
      KRET = 0
C
 990  CONTINUE
      RETURN
      END