File: jreadll.F

package info (click to toggle)
emoslib 000382%2Bdfsg-2
  • links: PTS
  • area: main
  • in suites: wheezy
  • size: 49,276 kB
  • sloc: fortran: 90,253; ansic: 26,730; makefile: 417; sh: 388; f90: 276
file content (177 lines) | stat: -rwxr-xr-x 4,104 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
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

      SUBROUTINE JREADLL( KUNIT, KTRUNC, PBUILD, PLAT, PLEG, KRET)
C
C---->
C**** JREADLL
C
C     PURPOSE
C     _______
C
C     This routine reads legendre functions for one latitude.
C
C     INTERFACE
C     _________
C
C     CALL JREADLL( KUNIT, KTRUNC, PBUILD, PLAT, PLEG, KRET)
C
C     Input parameters
C     ________________
C
C     KUNIT   - Unit number for open file of legendre functions.
C     KTRUNC  - Truncation.
C     PBUILD  - Grid interval used to build legendre coefficients file
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     None.
C
C     Method
C     ______
C
C     Calculate offset of the legendre functions for the latitude row 
C     in the file, skip to the row and read the functions.
C
C     Retries the read upto 3 times if necessary
C
C     Externals
C     _________
C
C     PBSEEK    - Position the coefficients file
C     PBREAD    - Read 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*      Nov 1993
C
C     MODIFICATIONS
C     _____________
C
C     None.
C
C----<
C     _______________________________________________________
C
C
      IMPLICIT NONE
#include "jparams.h"
#include "parim.h"
C
C     Subroutine arguments
C
      INTEGER KUNIT, KTRUNC, KRET
      REAL PBUILD, PLEG, PLAT
      DIMENSION PLEG(*)
C
C     Parameters
      INTEGER JPROUTINE
      PARAMETER ( JPROUTINE = 31100 )
C
C     Local variables
C
      INTEGER NTRIES
      INTEGER NSIZE, NRET
      INTEGER*8 FSIZE, FRET
      INTEGER*8 NEWPOS, OLDPOS

      REAL ZLAT
      DATA OLDPOS/-1/
      SAVE NEWPOS, OLDPOS
C
C     _______________________________________________________
C
C*    Section 1.    Initialization.
C     _______________________________________________________
C
100   CONTINUE
      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.
#ifdef REAL_8
      NSIZE   = 8 * (KTRUNC+1)*(KTRUNC+4)/2
      FSIZE   = 8 * (KTRUNC+1)*(KTRUNC+4)/2
#else
      NSIZE   = 4 * (KTRUNC+1)*(KTRUNC+4)/2
      FSIZE   = 4 * (KTRUNC+1)*(KTRUNC+4)/2
#endif
cs      NEWPOS = NINT( (90.0 - ZLAT)/PBUILD ) * NSIZE
      NEWPOS = NINT( (90.0 - ZLAT)/PBUILD ) * FSIZE
C
C     _______________________________________________________
C
C*    Section 2.    Processing.
C     _______________________________________________________
C
C     Position file unless the previous read left it in the correct 
C     position already
C
      NTRIES = 0
 210  CONTINUE
      NTRIES = NTRIES + 1
      IF ( NEWPOS .NE. OLDPOS ) THEN
        CALL PBSEEK64( KUNIT, NEWPOS, 0, FRET)
        IF ( FRET .NE. NEWPOS ) THEN
          CALL INTLOG(JP_ERROR,'JREADLL: PBSEEK64 error.',FRET)
	  KRET = JPROUTINE + 2
	  GOTO 990
	ENDIF
      ENDIF
C
C     Read the legendre coefficients
      CALL PBREAD( KUNIT, PLEG, NSIZE, NRET)
      IF ( NRET .NE. NSIZE ) THEN
	IF ( NTRIES .EQ. JPMXTRY ) THEN
          CALL INTLOG(JP_ERROR,'JREADLL: PBREAD error.',NRET)
	  KRET = JPROUTINE + 3
	  GOTO 990
	ELSE
	  GOTO 210
        ENDIF
      ENDIF
C
C     Record the current file byte position
      OLDPOS = NEWPOS + NSIZE
C     _______________________________________________________
C
C*    Section 9. Return to calling routine. Format statements
C     _______________________________________________________
C
 900  CONTINUE
      KRET = 0
C
 990  CONTINUE
      RETURN
      END