-
Notifications
You must be signed in to change notification settings - Fork 5
/
wps.ncl
287 lines (240 loc) · 9.17 KB
/
wps.ncl
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
; File: wps.ncl
; Created: 月曜日, 8月 20 2012
import("WRFUserARW")
;_____________________________________________________________________________
; Function: wps_parse_namelist_for_domain
; Doc: parse namelist.wps and set domain specific resources.
;
;_____________________________________________________________________________
undef("wps_parse_namelist_for_domain")
function wps_parse_namelist_for_domain(wpsFileName:string,res_in:logical)
local res_out,parent_id, parent_grid_ratio,j_parent_start,e_sn,e_we,test
begin
res_out = res_in
res_out@max_dom = stringtoint (systemfunc("grep max_dom " +wpsFileName+ " | cut -f2 -d'=' | cut -f1 -d','" ) )
res_out@dx = stringtofloat(systemfunc("grep dx " +wpsFileName+ " | cut -f2 -d'=' | cut -f1 -d','" ) )
res_out@dy = stringtofloat(systemfunc("grep dy " +wpsFileName+ " | cut -f2 -d'=' | cut -f1 -d','" ) )
res_out@ref_lat = stringtofloat(systemfunc("grep ref_lat " +wpsFileName+ " | cut -f2 -d'=' | cut -f1 -d','" ) )
res_out@ref_lon = stringtofloat(systemfunc("grep ref_lon " +wpsFileName+ " | cut -f2 -d'=' | cut -f1 -d','" ) )
test = systemfunc("grep truelat1 " +wpsFileName )
if ( .not. ismissing(test) )
res_out@truelat1 = stringtofloat(systemfunc("grep truelat1 " +wpsFileName+ " | cut -f2 -d'=' | cut -f1 -d','" ) )
else
res_out@truelat1 = 0.0
end if
test = systemfunc("grep truelat2 " +wpsFileName )
if ( .not. ismissing(test) )
res_out@truelat2 = stringtofloat(systemfunc("grep truelat2 " +wpsFileName+ " | cut -f2 -d'=' | cut -f1 -d','" ) )
else
res_out@truelat2 = 0.0
end if
res_out@stand_lon = stringtofloat(systemfunc("grep stand_lon " +wpsFileName+ " | cut -f2 -d'=' | cut -f1 -d','" ) )
test = systemfunc("grep lambert " +wpsFileName )
if ( .not. ismissing(test) )
res_out@map_proj = "lambert"
end if
test = systemfunc("grep mercator " +wpsFileName )
if ( .not. ismissing(test) )
res_out@map_proj = "mercator"
end if
test = systemfunc("grep polar " +wpsFileName )
if ( .not. ismissing(test) )
res_out@map_proj = "polar"
end if
testa = systemfunc("grep 'lat-lon' " +wpsFileName )
if ( .not. ismissing(testa) )
res_out@map_proj = "lat-lon"
res_out@pole_lat = stringtofloat(systemfunc("grep pole_lat " +wpsFileName+ " | cut -f2 -d'=' | cut -f1 -d','" ) )
res_out@pole_lon = stringtofloat(systemfunc("grep pole_lon " +wpsFileName+ " | cut -f2 -d'=' | cut -f1 -d','" ) )
end if
parent_id = new ( res_out@max_dom , integer )
parent_grid_ratio = new ( res_out@max_dom , integer )
i_parent_start = new ( res_out@max_dom , integer )
j_parent_start = new ( res_out@max_dom , integer )
e_we = new ( res_out@max_dom , integer )
e_sn = new ( res_out@max_dom , integer )
do n = 1, res_out@max_dom
n0 = n - 1
parent_id(n0) = stringtoint(systemfunc("grep parent_id " +wpsFileName+ " | cut -f2 -d'=' | cut -f"+n+" -d','" ) )
parent_grid_ratio(n0) = stringtoint(systemfunc("grep parent_grid_ratio " +wpsFileName+ " | cut -f2 -d'=' | cut -f"+n+" -d','" ) )
i_parent_start(n0) = stringtoint(systemfunc("grep i_parent_start " +wpsFileName+ " | cut -f2 -d'=' | cut -f"+n+" -d','" ) )
j_parent_start(n0) = stringtoint(systemfunc("grep j_parent_start " +wpsFileName+ " | cut -f2 -d'=' | cut -f"+n+" -d','" ) )
e_we(n0) = stringtoint(systemfunc("grep e_we " +wpsFileName+ " | cut -f2 -d'=' | cut -f"+n+" -d','" ) )
e_sn(n0) = stringtoint(systemfunc("grep e_sn " +wpsFileName+ " | cut -f2 -d'=' | cut -f"+n+" -d','" ) )
end do
res_out@parent_id = parent_id
res_out@parent_grid_ratio = parent_grid_ratio
res_out@i_parent_start = i_parent_start
res_out@j_parent_start = j_parent_start
res_out@e_we = e_we
res_out@e_sn = e_sn
return(res_out)
end
;_____________________________________________________________________________
; Function: wps_resolve_domain_type
; Doc:
;
;_____________________________________________________________________________
undef("wps_resolve_domain_type")
function wps_resolve_domain_type(res:logical,mpres:logical)
begin
res@DX = mpres@dx
res@DY = mpres@dy
res@LATINC = 0.0
res@LONINC = 0.0
if ( mpres@map_proj .eq. "lambert") then
mpres@map_proj = 1
res@MAP_PROJ = 1
end if
if ( mpres@map_proj .eq. "polar") then
mpres@map_proj = 2
res@MAP_PROJ = 2
end if
if ( mpres@map_proj .eq. "mercator") then
mpres@map_proj = 3
res@MAP_PROJ = 3
end if
if ( mpres@map_proj .eq. "lat-lon") then
mpres@map_proj = 6
res@MAP_PROJ = 6
res@LATINC = mpres@dy
res@LONINC = mpres@dx
end if
res@TRUELAT1 = mpres@truelat1
res@TRUELAT2 = mpres@truelat2
res@STAND_LON = mpres@stand_lon
res@REF_LAT = mpres@ref_lat
res@REF_LON = mpres@ref_lon
if ( isatt(mpres,"ref_x") ) then
res@KNOWNI = mpres@ref_x
else
res@KNOWNI = int2flt(mpres@e_we(0))/2.
end if
if ( isatt(mpres,"ref_y") ) then
res@KNOWNJ = mpres@ref_y
else
res@KNOWNJ = int2flt(mpres@e_sn(0))/2.
end if
if ( isatt(mpres,"pole_lat") ) then
res@POLE_LAT = mpres@pole_lat
else
res@POLE_LAT = 90.0
end if
if ( isatt(mpres,"pole_lon") ) then
res@POLE_LON = mpres@pole_lon
else
res@POLE_LON = 0.0
end if
return(res)
end
;_____________________________________________________________________________
; Function: wrf_wps_dom
; Doc:
;
;_____________________________________________________________________________
undef("wrf_wps_dom")
function wrf_wps_dom(wks[1]:graphic,mp:graphic,opt_args[1]:logical,lnres[1]:logical,txres[1]:logical)
begin
mpres = opt_args
res = True
res = wps_resolve_domain_type(res,mpres)
xx = 1.0
yy = 1.0
loc = wrf_ij_to_ll (xx,yy,res)
start_lon = loc(0)
start_lat = loc(1)
xx = int2flt(mpres@e_we(0))
yy = int2flt(mpres@e_sn(0))
loc = wrf_ij_to_ll (xx,yy,res)
end_lon = loc(0)
end_lat = loc(1)
mpres@start_lat = start_lat
mpres@start_lon = start_lon
mpres@end_lat = end_lat
mpres@end_lon = end_lon
; mp = wrf_wps_map(wks,mpres)
; draw(mp)
if ( mpres@max_dom .gt. 1 ) then
numLineColors = 0
if ( isatt(lnres,"domLineColors") ) then
numLineColors = dimsizes(lnres@domLineColors)
end if
do idom = 1,mpres@max_dom-1
if ( numLineColors .gt. 0 ) then
if ( numLineColors .ge. idom ) then
lnres@gsLineColor = lnres@domLineColors(idom-1)
txres@txFontColor = lnres@domLineColors(idom-1)
else
lnres@gsLineColor = lnres@domLineColors(numLineColors-1)
txres@txFontColor = lnres@domLineColors(numLineColors-1)
end if
end if
; nest start and end points in large domain space
if ( mpres@parent_id(idom) .eq. 1) then
; corner value
i_start = mpres@i_parent_start(idom)
j_start = mpres@j_parent_start(idom)
; end point
i_end = (mpres@e_we(idom)-1)/mpres@parent_grid_ratio(idom) + i_start
j_end = (mpres@e_sn(idom)-1)/mpres@parent_grid_ratio(idom) + j_start
end if
if ( mpres@parent_id(idom) .ge. 2) then
; corner value
nd = mpres@parent_id(idom)
i_points = ((mpres@e_we(idom)-1)/mpres@parent_grid_ratio(idom))
j_points = ((mpres@e_sn(idom)-1)/mpres@parent_grid_ratio(idom))
ai_start = mpres@i_parent_start(idom)*1.0
aj_start = mpres@j_parent_start(idom)*1.0
do while ( nd .gt. 1)
ai_start = ai_start/mpres@parent_grid_ratio(nd-1) + mpres@i_parent_start(nd-1)
aj_start = aj_start/mpres@parent_grid_ratio(nd-1) + mpres@j_parent_start(nd-1)
i_points = (i_points/mpres@parent_grid_ratio(nd-1))
j_points = (j_points/mpres@parent_grid_ratio(nd-1))
;nd = nd - 1
nd = mpres@parent_id(nd-1)
end do
i_start = tointeger(ai_start + .5 )
j_start = tointeger(aj_start + .5 )
; end point
i_end = i_points + i_start + 1
j_end = j_points + j_start + 1
end if
; get the four corners
xx = int2flt(i_start)
yy = int2flt(j_start)
loc = wrf_ij_to_ll (xx,yy,res)
lon_SW = loc(0)
lat_SW = loc(1)
xx = int2flt(i_end)
yy = int2flt(j_start)
loc = wrf_ij_to_ll (xx,yy,res)
lon_SE = loc(0)
lat_SE = loc(1)
xx = int2flt(i_start)
yy = int2flt(j_end)
loc = wrf_ij_to_ll (xx,yy,res)
lon_NW = loc(0)
lat_NW = loc(1)
xx = int2flt(i_end)
yy = int2flt(j_end)
loc = wrf_ij_to_ll (xx,yy,res)
lon_NE = loc(0)
lat_NE = loc(1)
xbox = (/lon_SW, lon_SE, lon_NE, lon_NW, lon_SW /)
ybox = (/lat_SW, lat_SE, lat_NE, lat_NW, lat_SW /)
x_out = new(dimsizes(xbox),typeof(xbox))
y_out = new(dimsizes(ybox),typeof(ybox))
datatondc(mp, xbox, ybox, x_out, y_out)
gsn_polyline_ndc(wks, x_out, y_out, lnres)
idd = idom + 1
dom_text = "d0"+idd
if ( txres@txJust .eq. "BottomLeft" ) then
gsn_text(wks,mp,dom_text,lon_NW,lat_NW,txres)
else
gsn_text_ndc(wks,dom_text,x_out(3)+0.01,y_out(3)-0.01,txres)
end if
end do
end if
return(mp)
end
;;; wps.ncl ends here