Starlink-AST

 view release on metacpan or  search on metacpan

ast/src/skyaxis.c  view on Meta::CPAN

*        Use tuning parameters to store graphical delimiters.
*     27-APR-2015 (DSB):
*        Added InternalUNit attribute..
*     26-OCT-2016 (DSB):
*        Override astAxisNormValues.
*     7-NOV-2016 (DSB):
*        Ensure astAxisNormValues ignores bad axis values.
*class--
*/

/* Module Macros. */
/* ============== */
/* Set the name of the class we are implementing. This indicates to the header
   files that define class interfaces that they should make "protected"
   symbols available. */
#define astCLASS SkyAxis

/* Header files. */
/* ============= */
#include "ast_err.h"             /* Error code definitions */

/* Interface definitions. */
/* ---------------------- */
#include "pal.h"                 /* SLALIB interface */

#include "globals.h"             /* Thread-safe global data access */
#include "error.h"               /* Error reporting facilities */
#include "memory.h"              /* Memory allocation facilities */
#include "pointset.h"            /* Sets of points (for AST__BAD) */
#include "axis.h"                /* Axis (parent) class interface */
#include "skyaxis.h"             /* Interface definition for this class */
#include "globals.h"             /* Thread-safe global data access */
#include "wcsmap.h"              /* For constants */

/* C header files. */
/* --------------- */
#include <ctype.h>
#include <limits.h>
#include <math.h>
#include <stdarg.h>
#include <stddef.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

/* Module Variables. */
/* ================= */

/* Address of this static variable is used as a unique identifier for
   member of this class. */
static int class_check;

/* Pointers to parent class methods which are extended by this class. */
static size_t (* parent_getobjsize)( AstObject *, int * );
static const char *(* parent_getattrib)( AstObject *, const char *, int * );
static const char *(* parent_getaxislabel)( AstAxis *, int * );
static const char *(* parent_getaxissymbol)( AstAxis *, int * );
static const char *(* parent_getaxisunit)( AstAxis *, int * );
static int (* parent_testattrib)( AstObject *, const char *, int * );
static int (*parent_getaxisdirection)( AstAxis *this, int * );
static void (* parent_axisoverlay)( AstAxis *, AstAxis *, int * );
static void (* parent_clearattrib)( AstObject *, const char *, int * );
static void (* parent_setattrib)( AstObject *, const char *, int * );
static double (*parent_getaxisbottom)( AstAxis *this, int * );
static double (*parent_getaxistop)( AstAxis *this, int * );
static const char *(* parent_axisformat)( AstAxis *, double, int * );
static double (*parent_axisgap)( AstAxis *, double, int *, int * );
static int (*parent_axisunformat)( AstAxis *, const char *, double *, int * );
static int (*parent_axisfields)( AstAxis *, const char *, const char *, int, char **, int *, double *, int * );

/* Factors for converting between hours, degrees and radians. */
static double hr2rad;
static double deg2rad;
static double pi;
static double piby2;

/* Define macros for accessing each item of thread specific global data. */
#ifdef THREAD_SAFE

/* Define how to initialise thread-specific globals. */
#define GLOBAL_inits \
   globals->Class_Init = 0; \
   globals->DHmsFormat_Buff[ 0 ] = 0; \
   globals->DHmsUnit_Buff[ 0 ] = 0; \
   globals->GetAttrib_Buff[ 0 ] = 0; \
   globals->GetAxisFormat_Buff[ 0 ] = 0;

/* Create the function that initialises global data for this module. */
astMAKE_INITGLOBALS(SkyAxis)

/* Define macros for accessing each item of thread specific global data. */
#define class_init astGLOBAL(SkyAxis,Class_Init)
#define class_vtab astGLOBAL(SkyAxis,Class_Vtab)
#define dhmsformat_buff astGLOBAL(SkyAxis,DHmsFormat_Buff)
#define dhmsunit_buff astGLOBAL(SkyAxis,DHmsUnit_Buff)
#define getattrib_buff astGLOBAL(SkyAxis,GetAttrib_Buff)
#define getaxisformat_buff astGLOBAL(SkyAxis,GetAxisFormat_Buff)

static pthread_mutex_t mutex2 = PTHREAD_MUTEX_INITIALIZER;
#define LOCK_MUTEX2 pthread_mutex_lock( &mutex2 );
#define UNLOCK_MUTEX2 pthread_mutex_unlock( &mutex2 );

/* If thread safety is not needed, declare and initialise globals at static
   variables. */
#else

static char dhmsformat_buff[ AST__SKYAXIS_DHMSFORMAT_BUFF_LEN + 1 ];
static char dhmsunit_buff[ AST__SKYAXIS_DHMSUNIT_BUFF_LEN + 1 ];
static char getattrib_buff[ AST__SKYAXIS_GETATTRIB_BUFF_LEN + 1 ];
static char getaxisformat_buff[ AST__SKYAXIS_GETAXISFORMAT_BUFF_LEN + 1 ];

/* Define the class virtual function table and its initialisation flag
   as static variables. */
static AstSkyAxisVtab class_vtab;   /* Virtual function table */
static int class_init = 0;       /* Virtual function table initialised? */

#define LOCK_MUTEX2
#define UNLOCK_MUTEX2

#endif

ast/src/skyaxis.c  view on Meta::CPAN

*     For a SkyFrame, the result is normalized into the correct angular
*     range (+PI to -PI for latitude axes, and 0 to 2*PI for longitude axes).

*  Parameters:
*     this
*        Pointer to the SkyAxis.
*     v1
*        The supplied axis value
*     dist
*        The axis increment

*  Returned Value:
*     The axis value which is the specified increment away from v1.

*  Notes:
*     - A value of AST__BAD is returned if either axis value is AST__BAD.
*     - A value of AST__BAD will be returned if this function is invoked
*     with the global error status set, or if it should fail for any
*     reason.
*/

/* Local Variables: */
   double result;                /* Returned gap size */

/* Initialise. */
   result = AST__BAD;

/* Check the global error status. */
   if ( !astOK ) return result;

/* Check both axis values are OK, and form the returned axis value. */
   if( v1 != AST__BAD && dist != AST__BAD ) {
      result = v1 + dist;
      AxisNorm( this_axis, &result, status );
   }

/* Return the result. */
   return result;
}

static void AxisOverlay( AstAxis *template_axis, AstAxis *result, int *status ) {
/*
*  Name:
*     AxisOverlay

*  Purpose:
*     Overlay the attributes of a template SkyAxis on to another Axis.

*  Type:
*     Private function.

*  Synopsis:
*     #include "skyaxis.h"
*     void AxisOverlay( AstAxis *template, AstAxis *result, int *status )

*  Class Membership:
*     SkyAxis member function (over-rides the astAxisOverlay method inherited
*     from the Axis class).

*  Description:
*     This function overlays attributes of a SkyAxis (the "template") on to
*     another Axis, so as to over-ride selected attributes of that second
*     Axis. Normally only those attributes which have been specifically set
*     in the template will be transferred. This implements a form of
*     defaulting, in which an Axis acquires attributes from the template, but
*     retains its original attributes (as the default) if new values have not
*     previously been explicitly set in the template.

*  Parameters:
*     template
*        Pointer to the template SkyAxis, for which values should have been
*        explicitly set for any attribute which is to be transferred.
*     result
*        Pointer to the Axis which is to receive the new attribute values.
*     status
*        Pointer to the inherited status variable.

*  Returned Value:
*     void
*/

/* Local Variables: */
   AstSkyAxis *template;         /* Pointer to the SkyAxis structure */

/* Check the global error status. */
   if ( !astOK ) return;

/* Obtain a pointer to the template SkyAxis structure. */
   template = (AstSkyAxis *) template_axis;

/* Invoke the parent astAstOverlay method to overlay inherited attributes. */
   (*parent_axisoverlay)( template_axis, result, status );

/* Test if the "result" Axis is a SkyAxis (if not, it cannot acquire any
   further attributes, so there is nothing more to do). */
   if ( astIsASkyAxis( result ) && astOK ) {

/* Overlay the Format attribute if it is set in the template. Note that we
   use private member functions (not methods) to access the Format value, since
   derived classes may extend the syntax of this string and we should not
   overlay a string whose syntax cannot be interpreted by the result Axis. */
      if ( TestAxisFormat( template_axis, status ) ) {
         SetAxisFormat( result, GetAxisFormat( template_axis, status ), status );
      }

/* Overlay the AsTime attribute in the same way, but this time using methods
   to access it. */
      if ( astTestAxisAsTime( template ) ) {
         astSetAxisAsTime( result, astGetAxisAsTime( template ) );
      }

/* Also overlay the IsLatitude attribute. */
      if ( astTestAxisIsLatitude( template ) ) {
         astSetAxisIsLatitude( result, astGetAxisIsLatitude( template ) );
      }

/* Also overlay the CentreZero attribute. */
      if ( astTestAxisCentreZero( template ) ) {
         astSetAxisCentreZero( result, astGetAxisCentreZero( template ) );
      }
   }
}

static void ClearAttrib( AstObject *this_object, const char *attrib, int *status ) {
/*
*  Name:
*     ClearAttrib

*  Purpose:
*     Clear an attribute value for a SkyAxis.

*  Type:
*     Private function.

*  Synopsis:
*     #include "skyaxis.h"
*     void ClearAttrib( AstObject *this, const char *attrib, int *status )

*  Class Membership:
*     SkyAxis member function (over-rides the astClearAttrib protected
*     method inherited from the Axis class).

*  Description:
*     This function clears the value of a specified attribute for a
*     SkyAxis, so that the default value will subsequently be used.

*  Parameters:
*     this
*        Pointer to the SkyAxis.
*     attrib
*        Pointer to a null-terminated string specifying the attribute
*        name.  This should be in lower case with no surrounding white
*        space.
*     status
*        Pointer to the inherited status variable.
*/

/* Local Variables: */
   AstSkyAxis *this;             /* Pointer to the SkyAxis structure */

/* Check the global error status. */
   if ( !astOK ) return;

/* Obtain a pointer to the SkyAxis structure. */
   this = (AstSkyAxis *) this_object;

/* Check the attribute name and clear the appropriate attribute. */

/* AsTime. */
/* ------- */
   if ( !strcmp( attrib, "astime" ) ) {
      astClearAxisAsTime( this );

/* IsLatitude. */
/* ----------- */
   } else if ( !strcmp( attrib, "islatitude" ) ) {
      astClearAxisIsLatitude( this );

ast/src/skyaxis.c  view on Meta::CPAN

*        astClass function).
*-
*/

/* Local Variables: */
   astDECLARE_GLOBALS            /* Pointer to thread-specific global data */
   AstAxisVtab *axis;            /* Pointer to Axis component of Vtab */
   AstObjectVtab *object;        /* Pointer to Object component of Vtab */
   int stat;                     /* SLALIB status */

/* Check the local error status. */
   if ( !astOK ) return;

/* Get a pointer to the thread specific global data structure. */
   astGET_GLOBALS(NULL);

/* Initialize the component of the virtual function table used by the
   parent class. */
   astInitAxisVtab( (AstAxisVtab *) vtab, name );

/* Store a unique "magic" value in the virtual function table. This
   will be used (by astIsASkyAxis) to determine if an object belongs
   to this class.  We can conveniently use the address of the (static)
   class_check variable to generate this unique value. */
   vtab->id.check = &class_check;
   vtab->id.parent = &(((AstAxisVtab *) vtab)->id);

/* Initialise member function pointers. */
/* ------------------------------------ */
/* Store pointers to the member functions (implemented here) that provide
   virtual methods for this class. */
   vtab->ClearAxisAsTime = ClearAxisAsTime;
   vtab->ClearAxisIsLatitude = ClearAxisIsLatitude;
   vtab->ClearAxisCentreZero = ClearAxisCentreZero;
   vtab->GetAxisAsTime = GetAxisAsTime;
   vtab->GetAxisIsLatitude = GetAxisIsLatitude;
   vtab->GetAxisCentreZero = GetAxisCentreZero;
   vtab->SetAxisAsTime = SetAxisAsTime;
   vtab->SetAxisIsLatitude = SetAxisIsLatitude;
   vtab->SetAxisCentreZero = SetAxisCentreZero;
   vtab->TestAxisAsTime = TestAxisAsTime;
   vtab->TestAxisIsLatitude = TestAxisIsLatitude;
   vtab->TestAxisCentreZero = TestAxisCentreZero;

/* Save the inherited pointers to methods that will be extended, and
   replace them with pointers to the new member functions. */
   object = (AstObjectVtab *) vtab;
   axis = (AstAxisVtab *) vtab;
   parent_getobjsize = object->GetObjSize;
   object->GetObjSize = GetObjSize;

   parent_clearattrib = object->ClearAttrib;
   object->ClearAttrib = ClearAttrib;
   parent_getattrib = object->GetAttrib;
   object->GetAttrib = GetAttrib;
   parent_setattrib = object->SetAttrib;
   object->SetAttrib = SetAttrib;
   parent_testattrib = object->TestAttrib;
   object->TestAttrib = TestAttrib;

   parent_axisoverlay = axis->AxisOverlay;
   axis->AxisOverlay = AxisOverlay;
   parent_getaxisdirection = axis->GetAxisDirection;
   axis->GetAxisDirection = GetAxisDirection;
   parent_getaxislabel = axis->GetAxisLabel;
   axis->GetAxisLabel = GetAxisLabel;
   parent_getaxissymbol = axis->GetAxisSymbol;
   axis->GetAxisSymbol = GetAxisSymbol;
   parent_getaxisunit = axis->GetAxisUnit;
   axis->GetAxisUnit = GetAxisUnit;

   parent_getaxistop = axis->GetAxisTop;
   axis->GetAxisTop = GetAxisTop;

   parent_getaxisbottom = axis->GetAxisBottom;
   axis->GetAxisBottom = GetAxisBottom;

   parent_axisformat = axis->AxisFormat;
   axis->AxisFormat = AxisFormat;

   parent_axisunformat = axis->AxisUnformat;
   axis->AxisUnformat = AxisUnformat;

   parent_axisgap = axis->AxisGap;
   axis->AxisGap = AxisGap;

   parent_axisfields = axis->AxisFields;
   axis->AxisFields = AxisFields;

/* Store replacement pointers for methods which will be over-ridden by
   new member functions implemented here. */
   axis->AxisAbbrev = AxisAbbrev;
   axis->AxisIn = AxisIn;
   axis->AxisDistance = AxisDistance;
   axis->AxisOffset = AxisOffset;
   axis->AxisNorm = AxisNorm;
   axis->AxisNormValues = AxisNormValues;
   axis->ClearAxisFormat = ClearAxisFormat;
   axis->GetAxisFormat = GetAxisFormat;
   axis->SetAxisFormat = SetAxisFormat;
   axis->TestAxisFormat = TestAxisFormat;
   axis->GetAxisInternalUnit = GetAxisInternalUnit;
   axis->TestAxisInternalUnit = TestAxisInternalUnit;

/* Declare the destructor, copy constructor and dump function. */
   astSetDelete( vtab, Delete );
   astSetCopy( vtab, Copy );
   astSetDump( vtab, Dump, "SkyAxis", "Celestial coordinate axis" );

/* Initialize constants for converting between hours, degrees and radians. */
   LOCK_MUTEX2
   palDtf2r( 1, 0, 0.0, &hr2rad, &stat );
   palDaf2r( 1, 0, 0.0, &deg2rad, &stat );
   palDaf2r( 180, 0, 0.0, &pi, &stat );
   piby2 = 0.5*pi;
   UNLOCK_MUTEX2

/* If we have just initialised the vtab for the current class, indicate
   that the vtab is now initialised, and store a pointer to the class
   identifier in the base "object" level of the vtab. */
   if( vtab == &class_vtab ) {



( run in 0.984 second using v1.01-cache-2.11-cpan-7fcb06a456a )