next up previous 264
Next: Simplifying IntraMaps
Up: Creating Your Own Private Mappings (IntraMaps)
Previous: Variable Numbers of Coordinates


Adapting a Transformation Routine to Individual IntraMaps

In the examples given so far, our coordinate transformation routines have not made use of the THIS pointer passed to them (which identifies the IntraMap whose transformation we are implementing). In practice, this will often be the case. However, the presence of the THIS pointer allows the transformation routine to invoke any other AST routine on the IntraMap, and this permits enquiries about its attributes. The transformation routine's behaviour can therefore be modified according to any attribute values which are set. This turns out to be a useful thing to do, so each IntraMap has a special IntraFlag attribute reserved for exactly this purpose.

Consider, for instance, the case where the transformation routine has access to several alternative sets of internally-stored data which it may apply to perform its transformation. Rather than implement many different versions of the transformation routine, you may switch between them by setting a value for the IntraFlag attribute when you create an instance of an IntraMap, for example:

      INTRAMAP1 = AST_INTRAMAP( 'MyTran', 2, 2, 'IntraFlag=A', STATUS )
      INTRAMAP2 = AST_INTRAMAP( 'MyTran', 2, 2, 'IntraFlag=B', STATUS )

The transformation routine may then enquire the value of the IntraFlag attribute (e.g. using AST_GETC and passing it the THIS pointer) and use whichever dataset is required for that particular IntraMap.

This approach is particularly useful when the number of possible transformations is unbounded or not known in advance, in which case the IntraFlag attribute may be used to hold numerical values encoded as part of a character string (effectively using them as data for the IntraMap). It is also superior to the use of a global switch for communication (e.g. setting an index to select the ``current'' data before using the IntraMap), because it continues to work when several IntraMaps are embedded within a more complex compound Mapping, when you may have no control over the order in which they are used.


next up previous 264
Next: Simplifying IntraMaps
Up: Creating Your Own Private Mappings (IntraMaps)
Previous: Variable Numbers of Coordinates

AST A Library for Handling World Coordinate Systems in Astronomy
Starlink User Note 210
R.F. Warren-Smith & D.S. Berry
24th May 2011
E-mail:ussc@star.rl.ac.uk

Copyright (C) 2009 Science \& Technology Facilities Council