Starlink-AST
view release on metacpan or search on metacpan
ast/src/axis.c view on Meta::CPAN
* Returned Value:
* A pointer to a null-terminated string containing the formatted value.
* Notes:
* - The returned string pointer may point at memory allocated within
* the Axis object, or at static memory. The contents of the string may be
* over-written or the pointer may become invalid following a further
* invocation of the same function or deletion of the Axis. A copy of the
* string should therefore be made if necessary.
* - A NULL pointer will be returned if this function is invoked with the
* global error status set, or if it should fail for any reason.
*-
*/
/* Local Constants: */
#define ERRBUF_LEN 80
/* Local Variables: */
astDECLARE_GLOBALS /* Pointer to thread-specific global data */
char *errstat; /* Pointer for system error message */
char errbuf[ ERRBUF_LEN ]; /* Buffer for system error message */
char log_esc[ 50 ]; /* Buffer for graphical delimiter string */
const char *fmt0; /* Pointer to original Format string */
const char *fmt; /* Pointer to parsed Format string */
const char *log_del; /* Pointer to delimiter string */
const char *result; /* Pointer to formatted value */
double x; /* The value to be formatted by sprintf */
int integ; /* Cast axis value to integer before printing? */
int log; /* Format as "10**x"? */
int nc; /* Total number of characters written */
int ncc; /* Number of characters written */
int sign; /* Include leading sign in front of "10**x"? */
int space; /* Include leading space in front of "10**x"? */
int stat; /* Value of errno after error */
/* Check the global error status. */
if ( !astOK ) return NULL;
/* Get a pointer to the thread specific global data structure. */
astGET_GLOBALS(this);
/* Initialise. */
result = NULL;
nc = 0;
x = value;
/* Check if a bad coordinate value was supplied and return a pointer to an
appropriate string if necessary. */
if ( value == AST__BAD ) {
result = "<bad>";
/* Otherwise, obtain a pointer to the Format string. Note a private member
function is used here in preference to an object method. This is because the
syntax of the Format string may be extended by derived classes and we do not
want to obtain a string that we cannot interpret here (where we are
restricted to C format specifiers capable of formatting double values).
Classes that extend the syntax should provide their own astAxisFormat method
and may need to store the string in a separate location. The original
location should not be re-used as the string it contains may be needed by
the Axis astOverlay method when overlaying attributes on to another Axis
object. */
} else {
fmt0 = GetAxisFormat( this, status );
/* Parse the Format string. This returns a collection of flags indicating
if any AST specific formatting features are specified in the Format
string. It also returns a pointer to a new Format string which is a
standard C printf format specifier. Currently the only flags are "log"
which indicates if the value should be formatted as "10**x" using
the graphical escape sequences defined within the Plot class to produce
"x" as a superscript of "10", "sign" which is used with log to indicate
if a sign should always be included infront of the "10", and "space"
which indicates if a leading space should be included infronyt of "10"
if no sign is included. It also modifies ".*" precision fields by
replacing the "*" by the current vale of the Digits attribute. */
fmt = ParseAxisFormat( fmt0, astGetAxisDigits( this ), &log, &sign,
&space, &integ, status );
if( astOK ) {
/* Format zero normally. */
if( value == 0.0 ) log = 0;
/* If log format is required, find the value of the exponent "x", and
initialise the returned string to hold the exponent and the graphical
escape sequence which produces a superscript. Otherwise just format the
supplied value. */
if( log ) {
if( sign ) {
axisformat_buff[ 0 ] ='+';
nc = 1;
} else if( space ) {
axisformat_buff[ 0 ] =' ';
nc = 1;
}
if( value > 0 ) {
x = log10( integ ? (int) value : value );
} else {
x = log10( integ ? (int) -value : -value );
axisformat_buff[ 0 ] ='-';
nc = 1;
}
if( astEscapes( -1 ) ) {
astTuneC( "exdel", NULL, log_esc, sizeof( log_esc ) );
log_del = log_esc;
} else {
log_del = log_txt;
}
nc += sprintf( axisformat_buff + nc, "%s", log_del );
/* Round small exponents to zero. */
if( fabs( x ) < 1.0E-10 ) x = 0.0;
}
}
ast/src/axis.c view on Meta::CPAN
* increment onto a supplied axis value.
*
* For a simple Axis, this is a trivial operation. But for other
* derived classes of Axis (such as a SkyAxis) this is not the case.
* Parameters:
* this
* Pointer to the Axis.
* 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;
/* Return the result. */
return result;
}
static void AxisOverlay( AstAxis *template, AstAxis *result, int *status ) {
/*
*+
* Name:
* astAxisOverlay
* Purpose:
* Overlay the attributes of a template Axis on to another Axis.
* Type:
* Protected virtual function.
* Synopsis:
* #include "axis.h"
* void astAxisOverlay( AstAxis *template, AstAxis *result )
* Class Membership:
* Axis method.
* Description:
* This function overlays attributes of one Axis (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 Axis, 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.
* Returned Value:
* void
*-
*/
/* Check the global error status. */
if ( !astOK ) return;
/* Define a macro to overlay a single attribute. This tests if the attribute
is set in the template Axis. If it is, its value is obtained and set in the
result Axis also. */
#define OVERLAY(par) \
if ( astTestAxis##par( template ) ) { \
astSetAxis##par( result, astGetAxis##par( template ) ); \
}
/* Overlay each Axis attribute in turn. */
OVERLAY(Digits);
OVERLAY(Direction);
OVERLAY(Label);
OVERLAY(Symbol);
OVERLAY(Unit);
/* Handle the Format string slightly differently by using a private member
function to obtain it. This is necessary in case derived classes have
extended the string syntax (see the AxisFormat function for more
details). */
if ( TestAxisFormat( template, status ) ) {
SetAxisFormat( result, GetAxisFormat( template, status ), status );
}
/* Undefine macros local to this function. */
#undef OVERLAY
}
static int AxisUnformat( AstAxis *this, const char *string, double *value, int *status ) {
/*
*+
* Name:
* astAxisUnformat
* Purpose:
* Read a formatted coordinate value for an Axis.
* Type:
* Public virtual function.
* Synopsis:
* #include "axis.h"
* int astAxisUnformat( AstAxis *this, const char *string, double *value )
* Class Membership:
* Axis method.
* Description:
* This function reads a formatted coordinate value for an Axis
* (supplied as a string) and returns the equivalent numerical
* value as a double. It also returns the number of characters read
* from the string.
* Parameters:
* this
* Pointer to the Axis.
* string
* Pointer to a constant null-terminated string containing the
* formatted coordinate value.
* value
* Pointer to a double in which the coordinate value read will be
* returned.
( run in 1.783 second using v1.01-cache-2.11-cpan-7fcb06a456a )