<html><head><meta http-equiv="content-type" content="text/html; charset=utf-8"></head><body dir="auto"><div>Hi Sara,</div><div><br></div><div>Basically your error is to interpolate with a single value (rather than an array). Here</div><div><br></div><div><span style="-webkit-tap-highlight-color: rgba(26, 26, 26, 0.292969); -webkit-composition-fill-color: rgba(175, 192, 227, 0.230469); -webkit-composition-frame-color: rgba(77, 128, 180, 0.230469); ">ua &nbsp; &nbsp;= ua_in(0:0,y,x)</span></div><div><span style="-webkit-tap-highlight-color: rgba(26, 26, 26, 0.292969); -webkit-composition-fill-color: rgba(175, 192, 227, 0.230469); -webkit-composition-frame-color: rgba(77, 128, 180, 0.230469); "><br></span></div><div><span style="-webkit-tap-highlight-color: rgba(26, 26, 26, 0.292969); -webkit-composition-fill-color: rgba(175, 192, 227, 0.230469); -webkit-composition-frame-color: rgba(77, 128, 180, 0.230469);">is just a scalar rather than an array. It should be</span></div><div><span style="-webkit-tap-highlight-color: rgba(26, 26, 26, 0.292969); -webkit-composition-fill-color: rgba(175, 192, 227, 0.230469); -webkit-composition-frame-color: rgba(77, 128, 180, 0.230469);"><br></span></div><div><span style="-webkit-tap-highlight-color: rgba(26, 26, 26, 0.292969); -webkit-composition-fill-color: rgba(175, 192, 227, 0.230469); -webkit-composition-frame-color: rgba(77, 128, 180, 0.230469);">ua = us_in(:, y,x)</span></div><div><span style="-webkit-tap-highlight-color: rgba(26, 26, 26, 0.292969); -webkit-composition-fill-color: rgba(175, 192, 227, 0.230469); -webkit-composition-frame-color: rgba(77, 128, 180, 0.230469);"><br></span></div><div><span style="-webkit-tap-highlight-color: rgba(26, 26, 26, 0.292969); -webkit-composition-fill-color: rgba(175, 192, 227, 0.230469); -webkit-composition-frame-color: rgba(77, 128, 180, 0.230469);">The same applies to other variables. You can use printVarSummary to check the dimension of a variable.</span></div><div><span style="-webkit-tap-highlight-color: rgba(26, 26, 26, 0.292969); -webkit-composition-fill-color: rgba(175, 192, 227, 0.230469); -webkit-composition-frame-color: rgba(77, 128, 180, 0.230469);"><br></span></div><div><span style="-webkit-tap-highlight-color: rgba(26, 26, 26, 0.292969); -webkit-composition-fill-color: rgba(175, 192, 227, 0.230469); -webkit-composition-frame-color: rgba(77, 128, 180, 0.230469);">Other thoughts:</span></div><div><span style="-webkit-tap-highlight-color: rgba(26, 26, 26, 0.292969); -webkit-composition-fill-color: rgba(175, 192, 227, 0.230469); -webkit-composition-frame-color: rgba(77, 128, 180, 0.230469);">1. wrf_ll_to_ij returns the index of the point in the domain, starting from 1. But in ncl index of an array starts from 0. So usually we should subtract 1 from the i and j. However, I may be wrong here. You'd better check.</span></div><div><span style="-webkit-tap-highlight-color: rgba(26, 26, 26, 0.292969); -webkit-composition-fill-color: rgba(175, 192, 227, 0.230469); -webkit-composition-frame-color: rgba(77, 128, 180, 0.230469);"><br></span></div><div><span style="-webkit-tap-highlight-color: rgba(26, 26, 26, 0.292969); -webkit-composition-fill-color: rgba(175, 192, 227, 0.230469); -webkit-composition-frame-color: rgba(77, 128, 180, 0.230469);">2. I remember wrf_user_getvar(nc_file, "ua", time) returns the unstaggered u. You can check.</span></div><div><span style="-webkit-tap-highlight-color: rgba(26, 26, 26, 0.292969); -webkit-composition-fill-color: rgba(175, 192, 227, 0.230469); -webkit-composition-frame-color: rgba(77, 128, 180, 0.230469);"><br></span></div><div><span style="-webkit-tap-highlight-color: rgba(26, 26, 26, 0.292969); -webkit-composition-fill-color: rgba(175, 192, 227, 0.230469); -webkit-composition-frame-color: rgba(77, 128, 180, 0.230469);">Xianxiang</span></div><div><br></div><div><br>On 30 Jun, 2014, at 11:38 PM, "Sara Fenech" &lt;<a href="mailto:sarafenech@gmail.com">sarafenech@gmail.com</a>&gt; wrote:<br><br></div><blockquote type="cite"><div><div dir="ltr">Hi all<div><br></div><div>I am very new to NCL and I've been trying to write a simple script but I'm having some problems. Well I have done 7 runs using wrf having hourly data for 3 months. Now I would like to extract the wind speed for each time step:</div>
<div>1) at a particular Lat and Lon (I managed this)</div><div>2) at a predefined height (in m)</div><div><br></div><div>Now I have managed to plot the wind speed for all my domain at a particular and I have managed to get wind speeds for a particular lat and lon but I cannot manage to obtain both at once.&nbsp;</div>
<div><br></div><div>Thus to sum it up I would like one value for wind speed for each time step (where lat lon and lev are predefined.)</div><div><br></div><div>The last thing I would like to ask is how I can save the extracted data into a file.&nbsp;</div>
<div><br></div><div>Thanks a lot for all you help. I'm attaching the script which is not working maybe you can spot what's wrong (Something to do with dimensions) together with the error message at the bottom.&nbsp;</div>
<div><br></div><div>Thanks Again</div><div><br></div><div>Sara&nbsp;</div><div><br></div><div><div><div>;******************************************************************************</div><div>;*NCL script to generate netCDF file containing wind speed at specific location &nbsp; &nbsp;*</div>
<div>;* Example for <a href="http://wrfout_d01_2010-12-01.nc">wrfout_d01_2010-12-01.nc</a> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;*</div><div>;* &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;*</div><div>;************************************************************************************</div>
<div><br></div><div><br></div><div>; -------------- &nbsp;LOAD FUNCTIONS AND PROCEDURES ----------------</div><div><br></div><div>load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_code.ncl"</div><div>load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_csm.ncl"</div>
<div>load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/contributed.ncl"</div><div>load "$NCARG_ROOT/lib/ncarg/nclscripts/wrf/WRFUserARW.ncl"</div><div><br></div><div>; -------------- &nbsp;BEGINING OF NCL SCRIPT ----------------</div>
<div><br></div><div><br></div><div>begin</div><div>;********************************************************</div><div>; read in netCDF file and make a loop for all time steps</div><div>;********************************************************</div>
<div><br></div><div>&nbsp; a = addfile("/home/wrf/OUTPUT/run_PBL2winter/<a href="http://wrfout_d01_2010-12-01.nc">wrfout_d01_2010-12-01.nc</a>","r")</div><div><br></div><div>&nbsp;&nbsp;</div><div>times = wrf_user_list_times(a) &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;; get times in the file&nbsp;</div>
<div>ntimes = dimsizes(times) &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;; number of times in the file&nbsp;</div><div>wind_speed = new(ntimes,float) ; creation of a windspeed vector at each time step</div><div>;print(ntimes)</div><div><br></div><div>do it = 0,ntimes-1 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;;Loop for the time: it= starting time</div>
<div>print("Working on time " + it )</div><div>time = it</div><div><br></div><div><br></div><div>;************************************************</div><div>; &nbsp;- Select lon &amp; lat of the point of interest -&nbsp;</div>
<div>;************************************************</div><div><br></div><div><br></div><div>&nbsp;res = True &nbsp; &nbsp; &nbsp;</div><div>&nbsp;res@returnInt = True &nbsp;; False : return real values, True: return interger values</div><div>&nbsp;lat = 42.47 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;; Latitude of the point of interest</div>
<div>&nbsp;lon = 12.98 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;; Longitude of the point of interest</div><div>&nbsp;point = wrf_user_ll_to_ij(a,lon,lat,res) &nbsp; &nbsp; &nbsp; ; wrf_user_ll_to_ij(nc_file,lon,lat,opt)</div><div>&nbsp;</div><div>&nbsp;x = point(1)</div><div>&nbsp;y = point(0)</div>
<div><br></div><div>&nbsp;print("X location is: " + x) &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;; print the value of X at the screen</div><div>&nbsp;print("Y location is: " + y) &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;; print the value of Y at the screen</div><div>;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;</div>
<div>; The specific height levels that we want the data interpolated to.</div><div>&nbsp; height_levels = (/ 1039./) &nbsp; ; height levels to plot - in meter</div><div>&nbsp; nlevels &nbsp; &nbsp; &nbsp; = 1 &nbsp; &nbsp; ; number of height levels</div><div><br>
</div><div>;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;</div><div><br></div><div><br></div><div>;************************************************</div><div>; &nbsp;- extract wind components and unstagger them -&nbsp;</div>
<div>;************************************************</div><div><br></div><div><br></div><div>; ----- Hence U and V are staggered, we need to &nbsp;average them to get the point on the mass grid using wrf_user_unstagger</div>
<div><br></div><div>&nbsp; U &nbsp; &nbsp; = wrf_user_getvar(a, "U", time)</div><div>&nbsp; ua_in = wrf_user_unstagger(U,U@stagger)</div><div>&nbsp; ua &nbsp; &nbsp;= ua_in(0:0,y,x) &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ;ua(bottom_up,grid_lon,grid_lat)</div><div>&nbsp; V &nbsp; &nbsp; = wrf_user_getvar(a, "V", time)</div>
<div>&nbsp; va_in = wrf_user_unstagger(V,V@stagger) &nbsp; &nbsp; &nbsp;</div><div>&nbsp; va &nbsp; &nbsp;= va_in(0:0,y,x) &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;;va(bottom_up,grid_lon,grid_lat)</div><div>&nbsp; W &nbsp; &nbsp; = wrf_user_getvar(a, "W", time)</div><div>&nbsp; z_in = wrf_user_unstagger(W,W@stagger)</div>
<div>&nbsp; z &nbsp; &nbsp;= z_in(0:0,x,y) &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ;z(bottom_up,grid_lon,grid_lat)</div><div><br></div><div>&nbsp; wind_speed(it) = sqrt(ua^2+va^2)</div><div>&nbsp; ;copy_VarCoords(ua,wind_speed(it)) &nbsp; &nbsp; ; copy coord vars to speed</div><div>&nbsp; ;print(wind_speed(it))</div>
<div><br></div><div>;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;</div><div>;Interpolating to the requested height</div><div>;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;</div><div>&nbsp; &nbsp; &nbsp; u_plane &nbsp;= wrf_user_intrp4d( ua,z,"h",height_levels,0.,False)</div>
<div>&nbsp; &nbsp; &nbsp; v_plane &nbsp;= wrf_user_intrp3d( va,z,"h",height_Levels,0.,False)</div><div>&nbsp; &nbsp; &nbsp; spd_plane =wrf_user_intrp3d (wind_speed(it),z,"h",height_Levels,0.,False) ; speed in m/sec</div><div><br></div><div>
&nbsp; print(spd_plane(it))</div><div><br></div><div>end do &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ; end of time loop</div><div>;************************************************</div><div>; &nbsp;- Write wind speed in ascii file -&nbsp;</div><div>;************************************************</div>
<div><br></div><div><br></div><div><br></div><div><br></div><div>&nbsp;; XLAT = lat &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;; (nlat)</div><div>&nbsp;; YLON = lon &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;; (mlon)</div><div>&nbsp; ;windspeed &nbsp; = wind_speed &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ; (ntim,nlat,mlon)</div>
<div><br></div><div>&nbsp; ;dimwindspeed &nbsp;= dimsizes(windspeed)</div><div>&nbsp; ;ntim &nbsp;= dimwindspeed(0)</div><div>&nbsp; ;nXLAT &nbsp;= dimwindspeed(1)</div><div>&nbsp; ;mYLON &nbsp;= dimwindspeed(2)</div><div><br></div><div>&nbsp; ;npts &nbsp;= nXLAT*mYLON &nbsp; &nbsp; &nbsp; &nbsp;; total number of grid points</div>
<div><br></div><div>&nbsp; ;fName = "foo.txt"</div><div>&nbsp; ;data &nbsp;= new( npts, "string")</div><div><br></div><div>&nbsp; ;npt &nbsp; = -1</div><div><br></div><div>&nbsp; ;do nl=0,nXLAT-1 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;</div><div>&nbsp; &nbsp;; do ml=0,mYLON-1</div>
<div><br></div><div>&nbsp; &nbsp; ; &nbsp; npt &nbsp;= npt + 1 &nbsp;&nbsp;</div><div>&nbsp; &nbsp; &nbsp;; &nbsp;data(npt) = sprinti("%0.5i", (npt+1) ) &nbsp;</div><div>&nbsp; &nbsp; &nbsp; ; data(npt) = data(npt) + sprintf("%7.1f ",XLAT(nl))</div><div>&nbsp; &nbsp; &nbsp; &nbsp;;data(npt) = data(npt) + sprintf("%7.1f ",YLON(ml))</div>
<div><br></div><div>&nbsp; &nbsp; &nbsp; ;do nt=0,ntim-1</div><div>&nbsp; &nbsp; &nbsp; &nbsp;; &nbsp;data(npt) = data(npt) + sprintf("%10.3f ", windspeed(nt,nl,ml))</div><div>&nbsp; &nbsp; &nbsp; ;end do</div><div>&nbsp; &nbsp; ;end do</div><div>&nbsp; ;end do</div><div><br></div>
<div>&nbsp; ;asciiwrite (fName , data)</div><div><br></div><div><br></div><div>; -------------- &nbsp;END OF NCL SCRIPT ----------------</div><div><br></div><div>end</div><div><br></div><div><b><u>Error Message</u></b></div><div><br>
</div><div><div>fatal:Subscript out of range, error in subscript #0</div><div>fatal:An error occurred reading dims</div><div>fatal:["Execute.c":8567]:Execute: Error occurred at or near line 223 in file $NCARG_ROOT/lib/ncarg/nclscripts/wrf/WRFUserARW.ncl</div>
<div><br></div><div>fatal:["Execute.c":8567]:Execute: Error occurred at or near line 84 in file SpLev.ncl</div></div><div><br></div><div><br></div></div></div></div>
</div></blockquote><blockquote type="cite"><div><span>_______________________________________________</span><br><span>Wrf-users mailing list</span><br><span><a href="mailto:Wrf-users@ucar.edu">Wrf-users@ucar.edu</a></span><br><span><a href="http://mailman.ucar.edu/mailman/listinfo/wrf-users">http://mailman.ucar.edu/mailman/listinfo/wrf-users</a></span><br></div></blockquote></body></html>