-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathrain_extract_points.ncl
68 lines (45 loc) · 1.51 KB
/
rain_extract_points.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
function wrf_rain(file_path_1[*]:string)
local rain,rainnc,rainc,a_1
begin
a_1=addfile(file_path_1,"r")
print("Processing: "+file_path_1)
rainc=wrf_user_getvar(a_1,"RAINC",-1)
rainnc=wrf_user_getvar(a_1,"RAINNC",-1)
rain=rainc+rainnc
return(rain)
end
begin
;---Adding files and Processing Variables
txt_file = ("Rain.csv")
files = (/"wrfout_d04_2014-07-13_18:00:00"/)
in = addfiles(files ,"r")
numFILES = dimsizes(files)
; What times and how many time steps are in the data set?
times = wrf_user_getvar(in,"times",-1) ; get all times in the file
ntimes = dimsizes(times) ; number of times in the file
;---Defining common resources
res = True
res@returnInt = True
;---Read in file as array of strings so we can parse each line
lines = asciiread("lat_lo.csv",-1,"string")
delim = ","
a=NewList("lifo")
lat = tofloat(str_get_field(lines,2,delim)) ;Second column of CSV should be lat
lon = tofloat(str_get_field(lines,3,delim)) ;Third column of CSV should be lon
rain1 = new(dimsizes(lat)-1,float)
do it1=0,ntimes-1
rain=wrf_rain(files(it1))
;---Read fields lat and long
print("Processing Points")
do it=1,dimsizes(lat)-1
point = wrf_user_ll_to_ij(in,lon(it),lat(it),res)
x = point(1)
y = point(0)
rain1(it-1)=rain(0,x,y)
end do
print("Writing File")
write_table(txt_file, "w", [/"Lat","Lon","Rain"/], "%s,%s,%s")
write_table(txt_file, "a",[/lat(1:), lon(1:), rain1/],"%f,%f,%f")
txt_file = ("Rain_"+((it1)+1)+".csv")
end do
end