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/WRFUserARW.ncl" begin DATADir = "$NCARGTEST/nclscripts/wrf_files/" FILES = systemfunc (" ls -1 " + DATADir + "wrfout_d05* ") a = addfiles(FILES+".nc","r") times = wrf_user_list_times(a) tc2 = wrf_user_getvar(a,"T2",-1) ; T2 in Kelvin tc2 = tc2-273.16 ; T2 in C tc2@units = "degC" ; Not required, but a good idea times = wrf_user_list_times(a) ntimes = dimsizes(times) print("ntimes = " + ntimes) ;---Get i,j locations of data closest to these lat/lon points lats = (/ 30, 40, 50/) lons = (/130,135,140/) nlatlon = dimsizes(lats) loc = wrf_user_ll_to_ij(a, lons, lats, True) ; 2 x nlatnlon loc = loc - 1 ; NCL wants values from 0 to n-1 ;---Set up CSV file and header information for the file csv_filename = "2mtemperature.csv" system("rm -f " + csv_filename) ; Remove file in case it exists. fields = (/"TIME", "LAT", "LON", "TEMPERATURE (degC)"/) 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,tc2(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