forked from erget/wgrib2
-
Notifications
You must be signed in to change notification settings - Fork 0
/
gdswiz.f
237 lines (237 loc) · 9.09 KB
/
gdswiz.f
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
C-----------------------------------------------------------------------
SUBROUTINE GDSWIZ(KGDS,IOPT,NPTS,FILL,XPTS,YPTS,RLON,RLAT,NRET,
& LROT,CROT,SROT)
C$$$ SUBPROGRAM DOCUMENTATION BLOCK
C
C SUBPROGRAM: GDSWIZ GRID DESCRIPTION SECTION WIZARD
C PRGMMR: IREDELL ORG: W/NMC23 DATE: 96-04-10
C
C ABSTRACT: THIS SUBPROGRAM DECODES THE GRIB GRID DESCRIPTION SECTION
C (PASSED IN INTEGER FORM AS DECODED BY SUBPROGRAM W3FI63)
C AND RETURNS ONE OF THE FOLLOWING:
C (IOPT= 0) GRID AND EARTH COORDINATES OF ALL GRID POINTS
C (IOPT=+1) EARTH COORDINATES OF SELECTED GRID COORDINATES
C (IOPT=-1) GRID COORDINATES OF SELECTED EARTH COORDINATES
C THE CURRENT CODE RECOGNIZES THE FOLLOWING PROJECTIONS:
C (KGDS(1)=000) EQUIDISTANT CYLINDRICAL
C (KGDS(1)=001) MERCATOR CYLINDRICAL
C (KGDS(1)=003) LAMBERT CONFORMAL CONICAL
C (KGDS(1)=004) GAUSSIAN CYLINDRICAL
C (KGDS(1)=005) POLAR STEREOGRAPHIC AZIMUTHAL
C (KGDS(1)=201) STAGGERED ROTATED EQUIDISTANT CYLINDRICAL
C (KGDS(1)=202) ROTATED EQUIDISTANT CYLINDRICAL
C (KGDS(1)=203) E-STAGGERED ROTATED EQUIDISTANT CYLINDRICAL 2-D
C (KGDS(1)=205) B-STAGGERED ROTATED EQUIDISTANT CYLINDRICAL 2-D
C IF THE SELECTED COORDINATES ARE MORE THAN ONE GRIDPOINT
C BEYOND THE THE EDGES OF THE GRID DOMAIN, THEN THE RELEVANT
C OUTPUT ELEMENTS ARE SET TO FILL VALUES. ALSO IF IOPT=0,
C IF THE NUMBER OF GRID POINTS EXCEEDS THE NUMBER ALLOTTED,
C THEN ALL THE OUTPUT ELEMENTS ARE SET TO FILL VALUES.
C THE ACTUAL NUMBER OF VALID POINTS COMPUTED IS RETURNED TOO.
C
C PROGRAM HISTORY LOG:
C 96-04-10 IREDELL
C 98-08-20 BALDWIN ADD TYPE 203 STAGGERED 2-D ETA GRIDS
C 08-04-11 GAYNO ADD TYPE 205 B-STAGGERED ROT LAT/LON GRIDS
C
C USAGE: CALL GDSWIZ(KGDS,IOPT,NPTS,FILL,XPTS,YPTS,RLON,RLAT,NRET,
C & LROT,CROT,SROT)
C
C INPUT ARGUMENT LIST:
C KGDS - INTEGER (200) GDS PARAMETERS AS DECODED BY W3FI63
C IOPT - INTEGER OPTION FLAG
C ( 0 TO COMPUTE EARTH COORDS OF ALL THE GRID POINTS)
C (+1 TO COMPUTE EARTH COORDS OF SELECTED GRID COORDS)
C (-1 TO COMPUTE GRID COORDS OF SELECTED EARTH COORDS)
C NPTS - INTEGER MAXIMUM NUMBER OF COORDINATES
C FILL - REAL FILL VALUE TO SET INVALID OUTPUT DATA
C (MUST BE IMPOSSIBLE VALUE; SUGGESTED VALUE: -9999.)
C XPTS - REAL (NPTS) GRID X POINT COORDINATES IF IOPT>0
C YPTS - REAL (NPTS) GRID Y POINT COORDINATES IF IOPT>0
C RLON - REAL (NPTS) EARTH LONGITUDES IN DEGREES E IF IOPT<0
C (ACCEPTABLE RANGE: -360. TO 360.)
C RLAT - REAL (NPTS) EARTH LATITUDES IN DEGREES N IF IOPT<0
C (ACCEPTABLE RANGE: -90. TO 90.)
C LROT - INTEGER FLAG TO RETURN VECTOR ROTATIONS IF 1
C
C OUTPUT ARGUMENT LIST:
C XPTS - REAL (NPTS) GRID X POINT COORDINATES IF IOPT<=0
C YPTS - REAL (NPTS) GRID Y POINT COORDINATES IF IOPT<=0
C RLON - REAL (NPTS) EARTH LONGITUDES IN DEGREES E IF IOPT>=0
C RLAT - REAL (NPTS) EARTH LATITUDES IN DEGREES N IF IOPT>=0
C NRET - INTEGER NUMBER OF VALID POINTS COMPUTED
C (-1 IF PROJECTION UNRECOGNIZED)
C CROT - REAL (NPTS) CLOCKWISE VECTOR ROTATION COSINES IF LROT=1
C SROT - REAL (NPTS) CLOCKWISE VECTOR ROTATION SINES IF LROT=1
C (UGRID=CROT*UEARTH-SROT*VEARTH;
C VGRID=SROT*UEARTH+CROT*VEARTH)
C
C SUBPROGRAMS CALLED:
C GDSWIZ00 GDS WIZARD FOR EQUIDISTANT CYLINDRICAL
C GDSWIZ01 GDS WIZARD FOR MERCATOR CYLINDRICAL
C GDSWIZ03 GDS WIZARD FOR LAMBERT CONFORMAL CONICAL
C GDSWIZ04 GDS WIZARD FOR GAUSSIAN CYLINDRICAL
C GDSWIZ05 GDS WIZARD FOR POLAR STEREOGRAPHIC AZIMUTHAL
C GDSWIZC9 GDS WIZARD FOR ROTATED EQUIDISTANT CYLINDRICAL
C GDSWIZCA GDS WIZARD FOR ROTATED EQUIDISTANT CYLINDRICAL
C GDSWIZCB GDS WIZARD FOR ROTATED EQUIDISTANT CYLINDRICAL 2-D
C GDSWIZCD GDS WIZARD FOR ROTATED EQUIDISTANT CYLINDRICAL 2-D
C
C ATTRIBUTES:
C LANGUAGE: FORTRAN 77
C
C$$$
INTEGER KGDS(200)
REAL XPTS(NPTS),YPTS(NPTS),RLON(NPTS),RLAT(NPTS)
REAL CROT(NPTS),SROT(NPTS)
C - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
C COMPUTE GRID COORDINATES FOR ALL GRID POINTS
IF(IOPT.EQ.0) THEN
IF(KGDS(1).EQ.201) THEN
IM=KGDS(7)*2-1
JM=KGDS(8)
KSCAN=MOD(KGDS(11)/256,2)
IF(KSCAN.EQ.0) THEN
IS1=(JM+1)/2
NM=(IM/2+1)*JM-JM/2
ELSE
IS1=JM/2
NM=IM/2*JM+JM/2
ENDIF
ELSEIF(KGDS(1).EQ.202) THEN
IM=KGDS(7)
JM=KGDS(8)
NM=IM*JM
ELSEIF(KGDS(1).EQ.203) THEN
IM=KGDS(2)
JM=KGDS(3)
NM=IM*JM
KSCAN=MOD(KGDS(11)/256,2)
IF(KSCAN.EQ.0) THEN
IS1=(JM+1)/2
ELSE
IS1=JM/2
ENDIF
ELSE
IM=KGDS(2)
JM=KGDS(3)
NM=IM*JM
ENDIF
NSCAN=MOD(KGDS(11)/32,2)
IF(NM.LE.NPTS) THEN
IF(KGDS(1).EQ.201) THEN
DO N=1,NM
NN=2*N-1+KSCAN
IF(NSCAN.EQ.0) THEN
J=(NN-1)/IM+1
I=NN-IM*(J-1)
ELSE
I=(NN-1)/JM+1
J=NN-JM*(I-1)
ENDIF
XPTS(N)=IS1+(I-(J-KSCAN))/2
YPTS(N)=(I+(J-KSCAN))/2
ENDDO
ELSEIF(KGDS(1).EQ.203) THEN
DO N=1,NM
IF(NSCAN.EQ.0) THEN
J=(N-1)/IM+1
I=(N-IM*(J-1))*2-MOD(J+KSCAN,2)
ELSE
I=(N-1)/JM+1
J=(N-JM*(I-1))*2-MOD(I+KSCAN,2)
ENDIF
XPTS(N)=IS1+(I-(J-KSCAN))/2
YPTS(N)=(I+(J-KSCAN))/2
ENDDO
ELSE
DO N=1,NM
IF(NSCAN.EQ.0) THEN
J=(N-1)/IM+1
I=N-IM*(J-1)
ELSE
I=(N-1)/JM+1
J=N-JM*(I-1)
ENDIF
XPTS(N)=I
YPTS(N)=J
ENDDO
ENDIF
DO N=NM+1,NPTS
XPTS(N)=FILL
YPTS(N)=FILL
ENDDO
ELSE
DO N=1,NPTS
XPTS(N)=FILL
YPTS(N)=FILL
ENDDO
ENDIF
IOPF=1
ELSE
IOPF=IOPT
ENDIF
C - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
C EQUIDISTANT CYLINDRICAL
IF(KGDS(1).EQ.000) THEN
CALL GDSWIZ00(KGDS,IOPF,NPTS,FILL,XPTS,YPTS,RLON,RLAT,NRET,
& LROT,CROT,SROT)
C - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
C MERCATOR CYLINDRICAL
ELSEIF(KGDS(1).EQ.001) THEN
CALL GDSWIZ01(KGDS,IOPF,NPTS,FILL,XPTS,YPTS,RLON,RLAT,NRET,
& LROT,CROT,SROT)
C - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
C LAMBERT CONFORMAL CONICAL
ELSEIF(KGDS(1).EQ.003) THEN
CALL GDSWIZ03(KGDS,IOPF,NPTS,FILL,XPTS,YPTS,RLON,RLAT,NRET,
& LROT,CROT,SROT)
C - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
C GAUSSIAN CYLINDRICAL
ELSEIF(KGDS(1).EQ.004) THEN
CALL GDSWIZ04(KGDS,IOPF,NPTS,FILL,XPTS,YPTS,RLON,RLAT,NRET,
& LROT,CROT,SROT)
C - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
C POLAR STEREOGRAPHIC AZIMUTHAL
ELSEIF(KGDS(1).EQ.005) THEN
CALL GDSWIZ05(KGDS,IOPF,NPTS,FILL,XPTS,YPTS,RLON,RLAT,NRET,
& LROT,CROT,SROT)
C - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
C STAGGERED ROTATED EQUIDISTANT CYLINDRICAL
ELSEIF(KGDS(1).EQ.201) THEN
CALL GDSWIZC9(KGDS,IOPF,NPTS,FILL,XPTS,YPTS,RLON,RLAT,NRET,
& LROT,CROT,SROT)
C - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
C ROTATED EQUIDISTANT CYLINDRICAL
ELSEIF(KGDS(1).EQ.202) THEN
CALL GDSWIZCA(KGDS,IOPF,NPTS,FILL,XPTS,YPTS,RLON,RLAT,NRET,
& LROT,CROT,SROT)
C - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
C E-STAGGERED ROTATED EQUIDISTANT CYLINDRICAL
ELSEIF(KGDS(1).EQ.203) THEN
CALL GDSWIZCB(KGDS,IOPF,NPTS,FILL,XPTS,YPTS,RLON,RLAT,NRET,
& LROT,CROT,SROT)
C - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
C B-STAGGERED ROTATED EQUIDISTANT CYLINDRICAL
ELSEIF(KGDS(1).EQ.205) THEN
CALL GDSWIZCD(KGDS,IOPF,NPTS,FILL,XPTS,YPTS,RLON,RLAT,NRET,
& LROT,CROT,SROT)
C - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
C PROJECTION UNRECOGNIZED
ELSE
IRET=-1
IF(IOPT.GE.0) THEN
DO N=1,NPTS
RLON(N)=FILL
RLAT(N)=FILL
ENDDO
ENDIF
IF(IOPT.LE.0) THEN
DO N=1,NPTS
XPTS(N)=FILL
YPTS(N)=FILL
ENDDO
ENDIF
ENDIF
C - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
END