Starlink-AST
view release on metacpan or search on metacpan
ast/src/specfluxframe.c view on Meta::CPAN
template = (AstSpecFluxFrame *) template_frame;
/* If the target is not a SpecFluxFrame, use the results returned by the
parent Match method inherited from the CmpFrame class. */
if( !astIsASpecFluxFrame( target ) ) {
match = (*parent_match)( template_frame, target, matchsub, template_axes,
target_axes, map, result, status );
/* If the target is a SpecFluxFrame, see if we can convert between target
and template */
} else {
/* We must now decide how the order of the axes in the result Frame relates to
the order of axes in the target Frame. There are two factors involved. The
first depends on whether the axis permutation array for the template
SpecFluxFrame (whose method we are executing) causes an axis
reversal. Determine this by permuting axis index zero. */
swap1 = ( astValidateAxis( template, 0, 1, "astMatch" ) != 0 );
/* The second factor depends on whether the axes of the target SpecFluxFrame
causes an axis reversal. Determine this by permuting axis index zero. */
swap2 = ( astValidateAxis( target, 0, 1, "astMatch" ) != 0 );
/* Combine these to determine if an additional axis swap will be
needed. */
swap = ( swap1 != swap2 );
/* Now check to see if this additional swap is permitted by the template's
Permute attribute. */
match = ( !swap || astGetPermute( template ) );
/* Allocate the target and template axes arrays. */
*template_axes = astMalloc( sizeof(int)*2 );
*target_axes = astMalloc( sizeof(int)*2 );
/* If the Frames still match, we next set up the axis association
arrays. */
if ( astOK && match ) {
/* If the target axis order is to be preserved, then the target axis
association involves no permutation but the template axis
association may involve an axis swap. */
if ( astGetPreserveAxes( template ) ) {
(*template_axes)[ 0 ] = swap;
(*template_axes)[ 1 ] = !swap;
(*target_axes)[ 0 ] = 0;
(*target_axes)[ 1 ] = 1;
/* Otherwise, any swap applies to the target axis association
instead. */
} else {
(*template_axes)[ 0 ] = 0;
(*template_axes)[ 1 ] = 1;
(*target_axes)[ 0 ] = swap;
(*target_axes)[ 1 ] = !swap;
}
/* Use the target's "astSubFrame" method to create a new Frame (the
result Frame) with copies of the target axes in the required
order. This process also overlays the template attributes on to the
target Frame and returns a Mapping between the target and result
Frames which effects the required coordinate conversion. */
match = astSubFrame( target, template, 2, *target_axes, *template_axes,
map, result );
/* If an error occurred, or conversion to the result Frame's
coordinate system was not possible, then free all memory, annul the
returned objects, and reset the returned value. */
if ( !astOK || !match ) {
*template_axes = astFree( *template_axes );
*target_axes = astFree( *target_axes );
if( *map ) *map = astAnnul( *map );
if( *result ) *result = astAnnul( *result );
match = 0;
}
}
}
/* Return the result. */
return match;
}
static int SubFrame( AstFrame *target_frame, AstFrame *template,
int result_naxes, const int *target_axes,
const int *template_axes, AstMapping **map,
AstFrame **result, int *status ) {
/*
* Name:
* SubFrame
* Purpose:
* Select axes from a SpecFluxFrame and convert to the new coordinate system.
* Type:
* Private function.
* Synopsis:
* #include "specfluxframe.h"
* int SubFrame( AstFrame *target, AstFrame *template,
* int result_naxes, const int *target_axes,
* const int *template_axes, AstMapping **map,
* AstFrame **result, int *status )
* Class Membership:
* SpecFluxFrame member function (over-rides the protected astSubFrame
* method inherited from the Frame class).
* Description:
* This function selects a requested sub-set (or super-set) of the
* axes from a "target" SpecFluxFrame and creates a new Frame with
* copies of the selected axes assembled in the requested order. It
* then optionally overlays the attributes of a "template" Frame on
* to the result. It returns both the resulting Frame and a Mapping
* that describes how to convert between the coordinate systems
* described by the target and result Frames. If necessary, this
* Mapping takes account of any differences in the Frames'
* attributes due to the influence of the template.
* Parameters:
* target
* Pointer to the target SpecFluxFrame, from which axes are to be selected.
* template
* Pointer to the template Frame, from which new attributes for
* the result Frame are to be obtained. Optionally, this may be
* NULL, in which case no overlaying of template attributes will
* be performed.
* result_naxes
* Number of axes to be selected from the target Frame. This
* number may be greater than or less than the number of axes in
* this Frame (or equal).
* target_axes
* Pointer to an array of int with result_naxes elements, giving
* a list of the (zero-based) axis indices of the axes to be
* selected from the target SpecFluxFrame. The order in which these
* are given determines the order in which the axes appear in
* the result Frame. If any of the values in this array is set
* to -1, the corresponding result axis will not be derived from
* the target Frame, but will be assigned default attributes
* instead.
* template_axes
* Pointer to an array of int with result_naxes elements. This
* should contain a list of the template axes (given as
* zero-based axis indices) with which the axes of the result
* Frame are to be associated. This array determines which axes
* are used when overlaying axis-dependent attributes of the
* template on to the result. If any element of this array is
* set to -1, the corresponding result axis will not receive any
* template attributes.
*
* If the template argument is given as NULL, this array is not
* used and a NULL pointer may also be supplied here.
* map
* Address of a location to receive a pointer to the returned
* Mapping. The forward transformation of this Mapping will
* describe how to convert coordinates from the coordinate
* system described by the target SpecFluxFrame to that described by
* the result Frame. The inverse transformation will convert in
* the opposite direction.
* result
* Address of a location to receive a pointer to the result Frame.
* status
* Pointer to the inherited status variable.
* Returned Value:
* A non-zero value is returned if coordinate conversion is
* possible between the target and the result Frame. Otherwise zero
* is returned and *map and *result are returned as NULL (but this
* will not in itself result in an error condition). In general,
* coordinate conversion should always be possible if no template
* Frame is supplied but may not always be possible otherwise.
* Notes:
* - A value of zero will be returned if this function is invoked
* with the global error status set, or if it should fail for any
* reason.
* Implementation Deficiencies:
* - It is not clear that the method of handling "extra" axes is
* the best one, nor is the method of setting the "following" flag
* necessarily correct. However, it is also not obvious that this
* feature will ever be needed, so improvements have been left
* until the requirement is clearer.
*/
/* Local Variables: */
AstMapping *tmpmap; /* Temporary Mapping pointer */
AstPermMap *permmap; /* Pointer to PermMap */
AstSpecFluxFrame *target; /* Pointer to target SpecFluxFrame structure */
int match; /* Coordinate conversion is possible? */
int perm[ 2 ]; /* Permutation array for axis swap */
int result_swap; /* Swap result SpecFluxFrame coordinates? */
int target_swap; /* Swap target SpecFluxFrame coordinates? */
/* Initialise the returned values. */
*map = NULL;
*result = NULL;
match = 0;
/* Check the global error status. */
if ( !astOK ) return match;
/* If the template is not a SpecFluxFrame we use the parent SubFrame
method inherited form the CmpFrame class. */
if( !template || !astIsASpecFluxFrame( template ) || result_naxes != 2 ) {
match = (*parent_subframe)( target_frame, template, result_naxes,
( run in 0.638 second using v1.01-cache-2.11-cpan-7fcb06a456a )