### 21 ALTERING BOUNDS AND PIXEL INDICES

#### 21.1 Setting New Pixel-Index Bounds and Dimensionality

The pixel-index bounds of an NDF may be altered when required by explicitly setting them to new values using the routine NDF_SBND. The dimensionality of the NDF may also be changed at the same time. For instance:

INTEGER NDIM, LBND( NDIM ), UBND( NDIM )

...

CALL NDF_SBND( NDIM, LBND, UBND, INDF, STATUS )

will change an NDF’s dimensionality to the value specified by the NDIM argument, and set its lower and upper pixel-index bounds to the values specified in the LBND and UBND arrays. When an NDF’s shape is changed in this way, the pixel values of any array component which is in a defined state may be affected, as follows:

Retained Pixels
– These are pixels with indices which lie within both the initial and final NDF pixel-index bounds. The values of these pixels are retained.
New Pixels
– These are pixels with indices which lie within the new pixel-index bounds, but did not exist within the initial bounds. These pixels will be assigned the appropriate bad-pixel value (see §9). If such pixels are introduced, then the bad-pixel flag of affected NDF components will be updated to reflect this fact.
Lost Pixels
– These are pixels with indices which lie within the initial NDF pixel-index bounds, but outside the new bounds. The values of such pixels are lost and cannot be recovered, even by changing the NDF’s bounds back to their original values.

In cases where the dimensionality of the NDF also changes, the association between pixel indices before and after the change is established in the same way as when creating NDF sections (see §15.6), i.e. by padding the bounds with 1’s to match the dimensionalities.

Note that altering the shape of an NDF section using NDF_SBND is a relatively inexpensive operation which merely involves changing the shape of the “window” into the NDF which the section describes. In contrast, altering the shape of a base NDF causes changes to be made to the actual data structure and can take considerably longer, especially if one or more of the NDF’s array components are in a defined state and contain values which may need to be shuffled to accommodate the change. Consequently, if the values of any array components need not be retained, they should be reset to an undefined state before changing the shape of a base NDF. For instance:

CALL NDF_RESET( INDF, ’Data,Variance,Quality’, STATUS )
CALL NDF_SBND( NDIM, LBND, UBND, INDF, STATUS )

would ensure that no array values are retained and that no time is unnecessarily wasted as a result.

#### 21.2 Applying Pixel-Index Shifts

An alternative way of changing the pixel-index bounds of an NDF is to apply shifts to its pixel indices using the routine NDF_SHIFT. For instance:

INTEGER NSHIFT, SHIFT( NSHIFT )

...

CALL NDF_SHIFT( NSHIFT, SHIFT, INDF, STATUS )

would apply a set of NSHIFT shifts to an NDF (one to each dimension) as specified in the integer array SHIFT. As a result, the pixel-index bounds and the indices of each pixel in the NDF would be changed by the amount of shift applied to the corresponding dimension. The shifts applied may be positive or negative. Thus, if the set of shifts (10,1,$-$3) were applied to an NDF with shape:

(10:20, 7, 0:5)

then its shape would change to become:

(20:30, 2:8, $-$3:2)

Note that the behaviour of NDF_SHIFT and NDF_SBND is quite different. With NDF_SBND (§21.1) the pixel indices remain fixed while the NDF bounds move, so that pixels can be lost from the edges of the NDF and new ones can be introduced. With NDF_SHIFT, however, the pixel indices move with the bounds, so that no pixels can ever be lost and no new ones are introduced. NDF_SHIFT also preserves the dimension sizes of the NDF.

The application of pixel-index shifts with NDF_SHIFT is a relatively inexpensive operation. When applied to an NDF section, the change in pixel indices applies only to that section (and any identifiers subsequently derived from it) and causes no permanent change to the base NDF or to other sections. When applied to a base NDF, however, the actual data structure is altered and this will be apparent through any other base NDF identifiers which refer to it. Note, however, that sections previously derived from a base NDF are not affected if NDF_SHIFT is applied to the base NDF (i.e. such sections will retain their original pixel indices and values).