This step generates a global spatial shift, which is an average of the individual shifts for each order that can be located successfully. The calculations are based on an 11-pixel-wide swath in the spatial direction of the crudely rotated raw image. Initially, the maximum and minimum DN values are computed in a predefined search window, which is expected to include the first (long-wavelength) order. These maxima and minima are assumed to be the ``peak'' flux of the order and the local ``background'' level, respectively. The local background (interpolated from pixels on either side of the order) is subtracted from the spatial profile, resulting in a ``net-flux'' profile. If the peak of the net-flux profile exceeds 5 DN, the algorithm proceeds to compute the centroid position of the order.

The centroid position of the order is computed using a least-squares
gaussian fit to the net-flux profile within the preselected search
window limits. Following the determination of an order centroid, *
ORDERG* steps to the search window for the next order. This window is
computed from the found positions of the preceding three orders (except
for the first two orders). If an order does not have sufficient net flux
for explicit centroid-finding, *ORDERG* steps to the estimated
position for the next order, and an attempt is made to find that order.
This process continues from the long-wavelength orders to the
short-wavelength orders.

Following the determination of the order centroid positions, relative
weights are assigned to each position according to the peak net flux.
Found-minus-expected centroid position differences are computed for
these orders and compared to the corresponding differences computed for
orders from a fiducial image unique to each camera (LWP06316, LWR14996,
and SWP13589). The order positions for these special images were
calculated during the initial development of the *ORDERG* algorithm.
A weighted least-squares solution of these pixel differences computes
both a mean global shift and an rms statistic. The mean shift is the
final value output from Step 1 and is the value applied to all lines in
the image if any test in Step 2 fails (see below). However, two tests
must first be passed before Step 1 is completed. The first is that a
minimum number of orders (five for SWP, three for LWP/LWR) must be found
with sufficient flux for order-centroiding. The second is that the rms
statistic referred to above must be below a threshold (1.5 pixels). If
either of these tests fails, a default value is adopted for the global
spatial shift based on statistical predictions using time- and THDA-dependent
spatial motions. Also, for either of these failure conditions, the
noncontinuum keyword for the appropriate aperture is also set to ``YES"
in the HISTORY portion of the FITS header. Note that the setting of
this keyword to ``NO" (i.e., all tests in Step 1 are passed) denotes
that the image is considered to have continuum flux and is treated as
such by the background-extraction algorithm described in
Chapter 10.