[ncl-talk] Output printing on terminal but not writing in csv files.
Ajay Bankar
ajaybankar123 at gmail.com
Sat Mar 14 04:56:49 MDT 2020
Dear NCL Users,
I am trying to extract wrf model output
parameter from wrfout file corresponding to station latitude longitude from
another csv file. If I'll mention latitude and longitude in ncl script as
an array then script is writing data to csv files but if I'll try to read
latitude and longitude from csv file then it's printing output on terminal
but not writing anything to a file.
Thanks in advance for any help.
Below is ncl code:
begin
stn_file = "./sample.csv"
f = asciiread(stn_file, -1, "string") ; -1 is used to read variables
as 1 dimensional
; stn = str_get_field(f4, 4, ",")
; lats = tofloat(str_get_field(f4, 5, ","))
; lons = tofloat(str_get_field(f4, 6, ","))
stn =
(/"RRN","SUL","AUR","KAM","MAH","KAP","KOD","KAL","SIR","CHI","CHIT","HUB","CHA","KALG
","AMI","ALN","KUN"/)
lats =
(/12.98,17.39,17.44,17.57,17.53,13.23,17.40,17.35,16.17,17.46,17.69,15.36,15.22,15.18,
15.54,15.42,15.25/)
lons =
(/77.51,77.34,76.89,76.98,76.88,74.75,77.19,77.15,77.02,77.42,77.21,75.13,75.15,74.97,
75.05,74.74,75.24/)
ext = "10_1" ; experiment name
lu = "mod" ; Landuse
datafor WRF
; Read the data
fo = addfiles( "wrfout_d03_2017-08-14_00:00:00","r")
wlat=fo[:]->XLAT(0,:,:)
wlon=fo[:]->XLONG(0,:,:)
rainc = wrf_user_getvar(fo,"RAINC",-1)
time = wrf_user_getvar(fo,"times",-1)
print(time)
ntime = dimsizes(time)
nl = dimsizes(lats)
ln = nl-1
do it=0,nl-1
olat = lats(it)
olon = lons(it)
yl = olat
xl = olon
; Find the closest point to the site in WRF grids
obsij=wrf_latlon_to_ij(wlat,wlon,olat,olon)
print(obsij)
; Use the Index to extract data
x = obsij(0)
y = obsij(1)
lm = ntime-1
rainCu = rainc(0:lm,x,y)
print(stn(it)+" "+lats(it)+" "+ lons(it)+" "+ rainCu)
;;;;Write to csv file
csv_filename = "RainC_" +stn(it)+ "_WRF_" +ext+ ".csv"
format = "%s %5.2f %5.2f %5.2f"
fields =(/"STATION", "LAT", "LON", "RAINC"/)
header = [/str_join(fields, " ")/]
write_table(csv_filename, "w", header, "%s")
alist = [/stn(it), lats(it), lons(it), rainCu/]
write_table(csv_filename, "a", alist, format)
end do
end
--
*Thanks & Regards,*
*Ajay Bankar.*
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mailman.ucar.edu/pipermail/ncl-talk/attachments/20200314/97b39e71/attachment.html>
More information about the ncl-talk
mailing list