-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathts2nc.ncl
359 lines (261 loc) · 8.99 KB
/
ts2nc.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
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;
; NCL Libraries
;
load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_code.ncl"
load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_csm.ncl"
load "$NCARG_ROOT/lib/ncarg/nclscripts/wrf/WRF_contributed.ncl"
load "$NCARG_ROOT/lib/ncarg/nclscripts/wrf/WRFUserARW.ncl"
load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/contributed.ncl"
;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
begin
setfileoption("nc","Format","NetCDF4")
setfileoption("nc","CompressionLevel",5)
dir_local = "/home/wjc/WRF_REALTIME_KUNR-3DOM/"
dir = "/home/wjc/WRF_REALTIME_KUNR-3DOM/WRFV370/WRFV3/test/em_real/"
sigmas = (/ 0.9965, 0.988, 0.9765, 0.962, 0.944, 0.9215, 0.8945, \
0.8603331, 0.8209995, 0.7816658, 0.7423322, 0.6876204, \
0.6201558, 0.5577776, 0.5001665, 0.4470201, 0.3980518, \
0.3529909, 0.3115811, 0.2735802, 0.2387594, 0.2069024, \
0.1778054, 0.1512759, 0.1271323, 0.1054426, 0.08629245, \
0.06946228, 0.05467104, 0.0416717, 0.03024719, \
0.02020672, 0.01138261, 0.003627522 /)
nlevels = 15
sigma = sigmas(0:nlevels-1)
sigma!0 = "sigma"
sigma&sigma = sigma
; print("cat " + dir_local + "current_day.txt")
run_date = systemfunc("cat " + dir_local + "current_day.txt")
print(run_date)
splitted_date = str_split(run_date, "_")
datestring = splitted_date(0)
hourstring = splitted_date(1)
station_id = (/ "CRSV", \
"FYGB", \
"FYGF", \
"FYOO", \
"FYOW", \
"FYWH", \
"FYWB", \
"FYRU" /)
station_name = (/ "Rapid City, SD", "Gillette, WY", "Custer, SD" /)
lat = (/ 44.0453333, 44.3489167, 43.7336542 /)
lat@long_name = "latitude"
lat@units = "degrees north"
lon = (/ -103.0573611, -105.5393611, -103.6194403 /)
lon@long_name = "longitude"
lon@units = "degrees east"
elev = (/ 940.8 , 1330.1, 1707. /)
elev@long_name = "terrain elevation"
elev@units = "m"
ncol = 19
do ss = 0, dimsizes(station_id)-1
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
filename = station_id(ss) + ".d02.TS"
data = readAsciiTable(dir + filename, ncol, "float", 1)
time = data(:,1)
time_min = round( time(0),0)
print(time_min)
time(:) = (/ time - time_min /)
time@long_name = "time"
time@units = "hours since "+ datestring + " "+ hourstring + ":00:00"
time!0 = "time"
time&time = time
print("maxtime = "+max(time))
domain = data(0,0)
domain@long_name = "WRF Domain Nest"
grid_x = data(0,3)
grid_x@long_name = "WRF X Coordinate"
grid_y = data(0,4)
grid_y@long_name = "WRF Y Coordinate"
data!0 = "time"
; data&time = time
data@lat = lat(ss)
data@lon = lon(ss)
data@elev = elev(ss)
data@domain = domain
data@grid_x = grid_x
data@grid_y = grid_y
temperature = data(:,5)
temperature@long_name = "2-m Air Temperature"
temperature@units = "K"
q = data(:,6)
q@long_name = "2-m vapor mixing ratio"
q@units = "kg kg-1"
w = q / (1-q)
u = data(:,7)
u@long_name = "eastward wind"
u@units = "m s-1"
v = data(:,8)
v@long_name = "nortward wind"
v@units = "m s-1"
psfc = data(:,9)
psfc@long_name = "mean sea level pressure"
psfc@units = "Pa"
rh=temperature
rh(:) = relhum(temperature, w, psfc)
rh@long_name = "2-m relative humidity"
rh@units = "%"
rh = where(rh .lt. 0, 0, rh)
rh = where(rh .gt.100,100,rh)
rh!0 = "time"
printVarSummary(rh)
dewpoint=temperature
dewpoint(:) = dewtemp_trh(temperature, rh)
dewpoint@long_name = "2-m dewpoint Temp"
dewpoint@units = "K"
dewpoint!0 = "time"
printVarSummary(dewpoint)
printVarSummary(temperature)
glw = data(:,10)
glw@long_name = "Downward Longwave Radiation"
glw@units = "W m-2"
gsw = data(:,11)
gsw@long_name = "Downward Shortwave Radiation"
gsw@units = "W m-2"
hfx = data(:,12)
hfx@long_name = "Sensible Heat Flux"
hfx@units = "W m-2"
lfx = data(:,13)
lfx@long_name = "Latent Heat Flux"
lfx@units = "W m-2"
tsoil = data(:,14)
tsoil@long_name = "Sfc Skin Temperature"
tsoil@units = "K"
tslb = data(:,15)
tslb@long_name = "Deep Soil Reservoir"
tslb@units = "K"
rainc = data(:,16)
rainc@long_name = "Cumulus Cumulative Precipitation "
rainc@units = "kg m-2"
rainnc = data(:,17)
rainnc@long_name = "Grid-Scale Cumulative Precipitation "
rainnc@units = "kg m-2"
clw = data(:,18)
clw@long_name = "Columnar Water"
clw@units = "kg m-2"
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
delete(data)
filename = station_id(ss) + ".d02.UU"
data = readAsciiTable(dir + filename, (1+nlevels), "float", 1)
data!0 = "time"
data&time = time
data@lat = lat(ss)
data@lon = lon(ss)
data@elev = elev(ss)
data@domain = domain
data@grid_x = grid_x
data@grid_y = grid_y
u_profile = data(:,1:dimsizes(sigma))
u_profile!1 = "sigma"
; u_profile&sigma = sigma
u_profile@long_name = "U-wind"
u_profile@units = "m s-1"
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
delete(data)
filename = station_id(ss) + ".d02.VV"
data = readAsciiTable(dir + filename, (1+nlevels), "float", 1)
data!0 = "time"
data&time = time
data@lat = lat(ss)
data@lon = lon(ss)
data@elev = elev(ss)
data@domain = domain
data@grid_x = grid_x
data@grid_y = grid_y
v_profile = data(:,1:dimsizes(sigma))
v_profile!1 = "sigma"
; v_profile&sigma = sigma
v_profile@long_name = "V-wind"
v_profile@units = "m s-1"
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
delete(data)
filename = station_id(ss) + ".d02.TH"
data = readAsciiTable(dir + filename, (1+nlevels), "float", 1)
data!0 = "time"
data&time = time
data@lat = lat(ss)
data@lon = lon(ss)
data@elev = elev(ss)
data@domain = domain
data@grid_x = grid_x
data@grid_y = grid_y
potential_temperature_profile = data(:,1:dimsizes(sigma))
potential_temperature_profile!1 = "sigma"
; potential_temperature_profile&sigma = sigma
potential_temperature_profile@long_name = "Potential Temperature"
potential_temperature_profile@units = "K"
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
delete(data)
filename = station_id(ss) + ".d02.QV"
data = readAsciiTable(dir + filename, (1+nlevels), "float", 1)
data!0 = "time"
data&time = time
data@lat = lat(ss)
data@lon = lon(ss)
data@elev = elev(ss)
data@domain = domain
data@grid_x = grid_x
data@grid_y = grid_y
specific_humidity_profile = data(:,1:dimsizes(sigma))
specific_humidity_profile!1 = "sigma"
; specific_humidity_profile&sigma = sigma
specific_humidity_profile@long_name = "Specific Humidity"
specific_humidity_profile@units = "kg kg-1"
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
delete(data)
filename = station_id(ss) + ".d02.PH"
data = readAsciiTable(dir + filename, (1+nlevels), "float", 1)
data!0 = "time"
data&time = time
data@lat = lat(ss)
data@lon = lon(ss)
data@elev = elev(ss)
data@domain = domain
data@grid_x = grid_x
data@grid_y = grid_y
geopotential_height_profile = data(:,1:dimsizes(sigma))
geopotential_height_profile!1 = "sigma"
; geopotential_height_profile&sigma = sigma
geopotential_height_profile@long_name = "Geopotential Height"
geopotential_height_profile@units = "m"
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
wrf_file= "wrfout_d" + sprinti("%0.2i", tointeger(domain)) + "_" + \
datestring + "_" + hourstring + "_" + station_id(ss) + ".nc"
system("rm -frv "+dir + wrf_file)
nc = addfile(dir + wrf_file, "c")
nc@station_id = station_id(ss)
nc@station_name = station_name(ss)
nc@lon = lon(ss)
nc@lat = lat(ss)
nc@elev = elev(ss)
nc@domain = domain
nc->time = time
nc->sigma = sigma
nc->temperature = temperature
nc->rh = rh
nc->dewpoint = dewpoint
nc->q = q
nc->u = u
nc->v = v
nc->psfc = psfc
nc->glw = glw
nc->gsw = gsw
nc->hfx = hfx
nc->lfx = lfx
nc->tsoil = tsoil
nc->tslb = tslb
nc->rainc = rainc
nc->rainnc = rainnc
nc->clw = clw
nc->u_profile = u_profile
nc->v_profile = v_profile
nc->potential_temperature_profile = potential_temperature_profile
nc->specific_humidity_profile = specific_humidity_profile
nc->geopotential_height_profile = geopotential_height_profile
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
printVarSummary(time)
delete(data)
end do
end