c c . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . c . . c . copyright (c) 1998 by UCAR . c . . c . University Corporation for Atmospheric Research . c . . c . all rights reserved . c . . c . . c . SPHEREPACK . c . . c . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . c c c c ... file vshifte.f contains code and documentation for subroutine vshifte c and its initialization subroutine vshifti c c ... required files c c hrfft.f c c subroutine vshifte(ioff,nlon,nlat,uoff,voff,ureg,vreg, c + wsave,lsave,work,lwork,ierror) c c *** purpose c c subroutine vshifte does a highly accurate 1/2 grid increment shift c in both longitude and latitude of equally spaced vector data on the c sphere. data is transferred between the nlon by nlat "offset grid" c in (uoff,voff) (which excludes poles) and the nlon by nlat+1 "regular c grid" in (ureg,vreg) (which includes poles). the transfer can go from c (uoff,voff) to (ureg,vreg) or vice versa (see ioff). the grids which c underly the vector fields are described below. the north and south c pole are at 0.5*pi and-0.5*pi radians respectively (pi=4.*atan(1.)). c uoff and ureg are the east longitudinal vector data components. voff c and vreg are the latitudinal vector data components. c c subroutine sshifte can be used to shift scalar data on the sphere. c notice that scalar and vector quantities are fundamentally different c on the sphere. for example, vectors are discontinuous and multiple c valued at the poles. scalars are continuous and single valued at the c poles. erroneous results would be produced if one attempted to shift c vector fields with subroutine sshifte applied to each component of c of the vector. c c *** grid descriptions c c let dlon = (pi+pi)/nlon and dlat = pi/nlat be the uniform grid c increments in longitude and latitude c c offset grid c c the "1/2 increment offset" grid (long(j),lat(i)) on which uoff(j,i) c and voff(j,i) are given (ioff=0) or generated (ioff=1) is c c long(j) =0.5*dlon + (j-1)*dlon (j=1,...,nlon) c c and c c lat(i) = -0.5*pi + 0.5*dlat + (i-1)*dlat (i=1,...,nlat) c c the data in (uoff,voff) is "shifted" one half a grid increment in both c longitude and latitude and excludes the poles. each uoff(j,1),voff(j,1) c is given at latitude -pi/2+dlat/2. uoff(j,nlat),voff(j,nlat) is c given at pi/2-dlat/2 (1/2 a grid increment away from the poles). c uoff(1,i),voff(1,i) is given at longitude dlon/2. each uoff(nlon,i), c voff(nlon,i) is given at longitude 2*pi-dlon/2. c c regular grid c c let dlat,dlon be as above. then the nlon by nlat+1 grid on which c ureg(j,i),vreg(j,i) are generated (ioff=0) or given (ioff=1) is c c lone(j) = (j-1)*dlon (j=1,...,nlon) c c and c c late(i) = -0.5*pi + (i-1)*dlat (i=1,...,nlat+1) c c values in ureg,vreg include the poles and start at zero degrees c longitude and at the south pole this is the "usual" equally spaced c grid in geophysical coordinates. c c *** remark c c subroutine vshifte can be used in conjunction with subroutine trvsph c when transferring vector data from an equally spaced "1/2 increment c offset" grid to a gaussian or equally spaced grid (which includes poles) c of any resolution. this problem (personal communication with dennis c shea) is encountered in geophysical modeling and data analysis. c c *** method c c fast fourier transform software from spherepack2 and trigonometric c identities are used to accurately "shift" periodic vectors half a c grid increment in latitude and longitude. latitudinal shifts are c accomplished by setting periodic 2*nlat vectors over the pole for each c longitude. vector values must be negated on one side of the pole c to maintain periodicity prior to the 2*nlat shift over the poles. c when nlon is odd, the 2*nlat latitudinal shift requires an additional c longitude shift to obtain symmetry necessary for full circle shifts c over the poles. finally longitudinal shifts are executed for each c shifted latitude. c c *** argument description c c ... ioff c c ioff = 0 if values on the offset grid in (uoff,voff) are given and c values on the regular grid in (ureg,vreg) are to be generated. c c ioff = 1 if values on the regular grid in (ureg,vreg) are given and c values on the offset grid in (uoff,voff) are to be generated. c c ... nlon c c the number of longitude points on both the "offset" and "regular" c uniform grid in longitude (see "grid description" above). nlon c is also the first dimension of uoff,voff,ureg,vreg. nlon determines c the grid increment in longitude as dlon = 2.*pi/nlon. for example, c nlon = 144 for a 2.5 degree grid. nlon can be even or odd and must c be greater than or equal to 4. the efficiency of the computation c is improved when nlon is a product of small primes. c c ... nlat c c the number of latitude points on the "offset" uniform grid. nlat+1 c is the number of latitude points on the "regular" uniform grid (see c "grid description" above). nlat is the second dimension of uoff,voff. c nlat+1 must be the second dimension of ureg,vreg in the program c calling vshifte. nlat determines the grid in latitude as pi/nlat. c for example, nlat = 36 for a five degree grid. nlat must be at least 3. c c ... uoff c c a nlon by nlat array that contains the east longitudinal vector c data component on the offset grid described above. uoff is a c given input argument if ioff=0. uoff is a generated output c argument if ioff=1. c c ... voff c c a nlon by nlat array that contains the latitudinal vector data c component on the offset grid described above. voff is a given c input argument if ioff=0. voff is a generated output argument c if ioff=1. c c ... ureg c c a nlon by nlat+1 array that contains the east longitudinal vector c data component on the regular grid described above. ureg is a given c input argument if ioff=1. ureg is a generated output argument c if ioff=0. c c ... vreg c c a nlon by nlat+1 array that contains the latitudinal vector data c component on the regular grid described above. vreg is a given c input argument if ioff=1. vreg is a generated output argument c if ioff=0. c c ... wsav c c a real saved work space array that must be initialized by calling c subroutine vshifti(ioff,nlon,nlat,wsav,ier) before calling vshifte. c wsav can then be used repeatedly by vshifte as long as ioff, nlon, c and nlat do not change. this bypasses redundant computations and c saves time. undetectable errors will result if vshifte is called c without initializing wsav whenever ioff, nlon, or nlat change. c c ... lsav c c the length of the saved work space wsav in the routine calling vshifte c and sshifti. lsave must be greater than or equal to 2*(2*nlat+nlon+16). c c ... work c c a real unsaved work space c c ... lwork c c the length of the unsaved work space in the routine calling vshifte c if nlon is even then lwork must be greater than or equal to c c 2*nlon*(nlat+1) c c if nlon is odd then lwork must be greater than or equal to c c nlon*(5*nlat+1) c c ... ier c c indicates errors in input parameters c c = 0 if no errors are detected c c = 1 if ioff is not equal to 0 or 1 c c = 2 if nlon < 4 c c = 3 if nlat < 3 c c = 4 if lsave < 2*(nlon+2*nlat)+32 c c = 5 if lwork < 2*nlon*(nlat+1) for nlon even or c lwork < nlon*(5*nlat+1) for nlon odd c c *** end of vshifte documentation c c subroutine vshifti(ioff,nlon,nlat,lsav,wsav,ier) c c subroutine vshifti initializes the saved work space wsav c for ioff and nlon and nlat (see documentation for vshifte). c vshifti must be called before vshifte whenever ioff or nlon c or nlat change. c c ... ier c c = 0 if no errors with input arguments c c = 1 if ioff is not 0 or 1 c c = 2 if nlon < 4 c c = 3 if nlat < 3 c c = 4 if lsav < 2*(2*nlat+nlon+16) c c *** end of vshifti documentation c