;getrotated_wc.pro determines hourly rotation angles to save in rot files that ;are used to determine long term rotations. It also converts non-rotated ;u,v,w arrays into rotated arrays based on long term rotation angles, or ;angles based on inputed u,v,w. ; ;The rotation angles determined for the rot files are as follows: ; Rotation into mean wind direction (phi) ; Vertical rotation to make avg wr equal zero (theta) ; ;There are currently two determinations of the angles. One based on averages ;of u,v,w and one based on the median value of u,v,w. These are denoted in ;the code below as phi and th for average method, nphi and nth for median ;method. ; ;Long term rotations are currently based on fits of nphi and nth. If long term ;rotation angles are requested to rotate u,v,w then nphi is used to get the ;fitted value of theta (called nnth). If long term angles are not used then ;phi and th are used to rotate u,v,w. ; ;Use of this routine is as follows: ; getrotated,year,jday,long_term,u,v,w,ur,vr,wr,rot,usedrot ;Where ; | year = integer 4-digit year ; input| jday = Julian day ; | long_term = flag denoting whether to rotate with long term angles ; | =1 use long term angles,=0 use angles from input u,v,w ; | u,v,w = data arrays of wind velocity (columns for each level) ; ; | ur,vr,wr = rotated wind velocity arrays (same size as u,v,w arrays) ;output| rot = array of rotation angles based on input u,v,w (rad) ; | (used to write .rot files in save_wlef.pro) ; | usedrot = rotation angles used to rotate u,v,w into ur,vr,wr (rad) ; | (used to write .flx and .sflx files in save_wlef.pro) ; ;Written by BWBerger 8/99 based on getrotated.pro for wlef. ;Modified by Wwang for Lost Creek, Sep 20 , 2000 pro getrotated_lc,year,jday,long_term,u,v,w,ur,vr,wr,rot,usedrot badval=-999. n=len(u) ;initialize rotated velocities and rotation angle array ur=fltarr(1,n)-999. vr=fltarr(1,n)-999. wr=fltarr(1,n)-999. rot=fltarr(4,1)-999. ;for rotation files usedrot=fltarr(2,1)-999. ;for flx and sflx files utemp=transpose(u) vtemp=transpose(v) wtemp=transpose(w) ;Compute rotation angles for un-filtered data. ;th and phi are saved to files for fitting long term rotations. angles,utemp,vtemp,wtemp,th,phi,badval ;*********************************************************************** ; median filter to remove "comb-spikes", then try rotation again to look ; for systematic differences in rotation angles. ; nfil defines the number of points to be median filtered. Data, recall, ; is 5 Hz. nu is median filtered array which is always returned as a ; row vector regardless of whether input is a row or column vector. ;*********************************************************************** nfil=10 medfil,utemp,nfil,nu,num,badval ;output is row vector medfil,vtemp,nfil,nv,nvm,badval medfil,wtemp,nfil,nw,nwm,badval ;Compute rotation angles for median filtered data. ;nth and nphi are saved to files for fitting long term rotations. ;nphi is used in the long term fit equation to get a fitted theta nnth ;that is used for final flux calculations. angles,nu,nv,nw,nth,nphi,badval ;input is row vector ;Get long term fitted rotations. ;The rotation angle nphi is used in a long term fit equation to get the ;fitted theta nnth for flux calculations if (long_term eq 'y') then begin ;get the long term theta nnth for given avg wind dir nphi getlongterm_theta_lc,year,jday,nphi,nnth ;get rotated u,v and w (called ur,vr,wr) using long term rotations ;u,v,w go into rotat unrotated and come back rotated ;input and output is row vector rotat2,utemp,vtemp,wtemp,nnth,nphi,badval,urtemp,vrtemp,wrtemp usedrot(*,0)=[nnth,nphi] ;for flx and sflx files endif else begin ;get approximate rotated u,v,and w using rough rotations ;input and output is row vector rotat2,utemp,vtemp,wtemp,th,phi,badval,urtemp,vrtemp,wrtemp usedrot(*,0)=[th,phi] ;for flx and sflx files endelse ur=transpose(urtemp) ;load up columns of velocity vectors vr=transpose(vrtemp) wr=transpose(wrtemp) rot(*,0)=[th,phi,nth,nphi] ;for rotation files return end