<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. </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. </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. </div>
<div><br></div><div>Thanks Again</div><div><br></div><div>Sara </div><div><br></div><div><div><div>;******************************************************************************</div><div>;*NCL script to generate netCDF file containing wind speed at specific location *</div>
<div>;* Example for <a href="http://wrfout_d01_2010-12-01.nc">wrfout_d01_2010-12-01.nc</a> *</div><div>;* *</div><div>;************************************************************************************</div>
<div><br></div><div><br></div><div>; -------------- 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>; -------------- 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> 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> </div><div>times = wrf_user_list_times(a) ; get times in the file </div>
<div>ntimes = dimsizes(times) ; number of times in the file </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 ;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>; - Select lon & lat of the point of interest - </div>
<div>;************************************************</div><div><br></div><div><br></div><div> res = True </div><div> res@returnInt = True ; False : return real values, True: return interger values</div><div> lat = 42.47 ; Latitude of the point of interest</div>
<div> lon = 12.98 ; Longitude of the point of interest</div><div> point = wrf_user_ll_to_ij(a,lon,lat,res) ; wrf_user_ll_to_ij(nc_file,lon,lat,opt)</div><div> </div><div> x = point(1)</div><div> y = point(0)</div>
<div><br></div><div> print("X location is: " + x) ; print the value of X at the screen</div><div> print("Y location is: " + y) ; 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> height_levels = (/ 1039./) ; height levels to plot - in meter</div><div> nlevels = 1 ; number of height levels</div><div><br>
</div><div>;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;</div><div><br></div><div><br></div><div>;************************************************</div><div>; - extract wind components and unstagger them - </div>
<div>;************************************************</div><div><br></div><div><br></div><div>; ----- Hence U and V are staggered, we need to average them to get the point on the mass grid using wrf_user_unstagger</div>
<div><br></div><div> U = wrf_user_getvar(a, "U", time)</div><div> ua_in = wrf_user_unstagger(U,U@stagger)</div><div> ua = ua_in(0:0,y,x) ;ua(bottom_up,grid_lon,grid_lat)</div><div> V = wrf_user_getvar(a, "V", time)</div>
<div> va_in = wrf_user_unstagger(V,V@stagger) </div><div> va = va_in(0:0,y,x) ;va(bottom_up,grid_lon,grid_lat)</div><div> W = wrf_user_getvar(a, "W", time)</div><div> z_in = wrf_user_unstagger(W,W@stagger)</div>
<div> z = z_in(0:0,x,y) ;z(bottom_up,grid_lon,grid_lat)</div><div><br></div><div> wind_speed(it) = sqrt(ua^2+va^2)</div><div> ;copy_VarCoords(ua,wind_speed(it)) ; copy coord vars to speed</div><div> ;print(wind_speed(it))</div>
<div><br></div><div>;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;</div><div>;Interpolating to the requested height</div><div>;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;</div><div> u_plane = wrf_user_intrp4d( ua,z,"h",height_levels,0.,False)</div>
<div> v_plane = wrf_user_intrp3d( va,z,"h",height_Levels,0.,False)</div><div> spd_plane =wrf_user_intrp3d (wind_speed(it),z,"h",height_Levels,0.,False) ; speed in m/sec</div><div><br></div><div>
print(spd_plane(it))</div><div><br></div><div>end do ; end of time loop</div><div>;************************************************</div><div>; - Write wind speed in ascii file - </div><div>;************************************************</div>
<div><br></div><div><br></div><div><br></div><div><br></div><div> ; XLAT = lat ; (nlat)</div><div> ; YLON = lon ; (mlon)</div><div> ;windspeed = wind_speed ; (ntim,nlat,mlon)</div>
<div><br></div><div> ;dimwindspeed = dimsizes(windspeed)</div><div> ;ntim = dimwindspeed(0)</div><div> ;nXLAT = dimwindspeed(1)</div><div> ;mYLON = dimwindspeed(2)</div><div><br></div><div> ;npts = nXLAT*mYLON ; total number of grid points</div>
<div><br></div><div> ;fName = "foo.txt"</div><div> ;data = new( npts, "string")</div><div><br></div><div> ;npt = -1</div><div><br></div><div> ;do nl=0,nXLAT-1 </div><div> ; do ml=0,mYLON-1</div>
<div><br></div><div> ; npt = npt + 1 </div><div> ; data(npt) = sprinti("%0.5i", (npt+1) ) </div><div> ; data(npt) = data(npt) + sprintf("%7.1f ",XLAT(nl))</div><div> ;data(npt) = data(npt) + sprintf("%7.1f ",YLON(ml))</div>
<div><br></div><div> ;do nt=0,ntim-1</div><div> ; data(npt) = data(npt) + sprintf("%10.3f ", windspeed(nt,nl,ml))</div><div> ;end do</div><div> ;end do</div><div> ;end do</div><div><br></div>
<div> ;asciiwrite (fName , data)</div><div><br></div><div><br></div><div>; -------------- 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>