[ncl-talk] List subscripting used on non-list variable, can't continue
Borja Sas González
saszalez at gmail.com
Wed Aug 7 05:40:01 MDT 2019
I am trying to write a csv to represent several variables. To make it easy,
copy the example from the NCL page (write_csv_5.ncl) that represents the
temperature at 2 m.
The only changes I made in the script are the output file of the WRF that
you are going to read and the map points that I want.
When executing it, the following error is printed:
fatal:List subscripting used on non-list variable, can't continue
fatal:["Execute.c":8637]:Execute: Error occurred at or near line 51 in file
csv.ncl
The script is:
load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_code.ncl"
load "$NCARG_ROOT/lib/ncarg/nclscripts/wrf/WRFUserARW.ncl"
begin
a =
addfile("/home/bsas/wrf_wind/WRF/test/em_real/wrfout_d03_2019-08-07_00:00:
00.nc","r")
times = wrf_user_list_times(a) ; "2019-08-01_12:00:00", etc
tk2 = wrf_user_getvar(a,"T2",-1) ; T2 in Kelvin
times = wrf_user_list_times(a)
ntimes = dimsizes(times)
print("ntimes = " + ntimes)
;---Calculate i,j locations of data closest to set of lat/lon points
lats = (/28.290147,28.379555/)
lons = (/-16.377643,-16.585276/)
nlatlon = dimsizes(lats)
loc = wrf_user_ll_to_xy(a, lons, lats, True) ; 2 x nlatnlon
; loc = wrf_user_ll_to_ij(a, lons, lats, True) ; 2 x nlatnlon
; loc = loc - 1 ; wrf_user_ll_to_ij
returns 1-based indexes
;---Set up CSV file and header information for the file
csv_filename = "wrf_2m_temperature.csv"
system("rm -f " + csv_filename) ; Remove file in case it
exists.
fields = (/"TIME", "LAT", "LON", "TEMPERATURE (degC)"/)
;---Create a header line for CSV file
dq = str_get_dq()
fields = dq + fields + dq ; Pre/append quotes to
field names
header = [/str_join(fields,",")/] ; Header is field names
separated
; by commas.
;
; Format to use for writing each variable to CSV file.
; If you don't want spaces in CSV file, use the following
; format string:
; format = "%s,%g,%g,%g"
;
format = "%s,%6.2f,%7.2f,%6.2f"
;
; Loop through each time step and desired list of lat/lon values,
; and write a single line of data to CSV file.
;
write_table(csv_filename, "w", header, "%s") ; Write header to CSV file.
do it = 0,ntimes-1
do nl = 0,nlatlon-1
nln = loc(0,nl)
nlt = loc(1,nl)
lat1 = a[0]->XLAT(0,nlt,nln) ; nearest grid point
lon1 = a[0]->XLONG(0,nlt,nln)
alist = [/times(it),lat1,lon1,tk2(it,nlt,nln)/] ; Store data to be
written in a list.
write_table(csv_filename, "a", alist, format) ; Write list to CSV
file.
end do
end do
end
--
Borja Sas González
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mailman.ucar.edu/pipermail/ncl-talk/attachments/20190807/2db28509/attachment.html>
More information about the ncl-talk
mailing list