summaryrefslogtreecommitdiffstats
path: root/ast/skyaxis.h
blob: 5c2f7acadd3cf935dd576093b8adc0a9cbc0c50b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
#if !defined( SKYAXIS_INCLUDED ) /* Include this file only once */
#define SKYAXIS_INCLUDED
/*
*+
*  Name:
*     skyaxis.h

*  Type:
*     C include file.

*  Purpose:
*     Define the interface to the SkyAxis class.

*  Invocation:
*     #include "skyaxis.h"

*  Description:
*     This include file defines the interface to the SkyAxis class and
*     provides the type definitions, function prototypes and macros,
*     etc.  needed to use this class.
*
*     The SkyAxis class extends the Axis class to represent angles on
*     the sky measured in radians. It provides alternative formatting
*     facilities for representing these coordinate values either as
*     angles (in degrees) or as time (in hours) using sexagesimal
*     notation. It also provides alternative defaults for certain
*     attributes and adds new attributes and methods of its own which
*     are needed to manipulate angular coordinates on the sky.

*  Inheritance:
*     The SkyAxis class inherits from the Axis class.

*  Attributes Over-Ridden:
*     Format (string)
*        The SkyAxis class defines a new syntax for this string.
*     Label (string)
*        The SkyAxis class defines new default values. These may
*        depend on other attribute settings.
*     Symbol (string)
*        The SkyAxis class defines new default values. These may
*        depend on other attribute settings.
*     Unit (string)
*        The SkyAxis class defines new default values. These may
*        depend on other attribute settings.

*  New Attributes Defined:
*     AsTime (integer)
*        A boolean value which indicates whether SkyAxis coordinate
*        values should be formatted for display as times (instead of
*        angles). It is used to determine the default format to use if
*        no explicit value has been set for the Format attribute.
*     CentreZero (integer)
*        A boolean value which indicates whether a SkyAxis value should
*        be normalised into the range [-PI,+PI] or [0,2.PI] when astNorm
*        is used.
*     IsLatitude (integer)
*        A boolean value which indicates whether a SkyAxis is a
*        latitude axis (as opposed to a longitude axis). It is used to
*        determine default axis labels and symbols. It also determines the
*        default value for the "AsTime" attribute (since longitudes on
*        the sky are usually expressed as times).

*  Methods Over-Ridden:
*     Public:
*        astAxisFormat
*           Format a coordinate value for a SkyAxis.
*        astAxisNorm
*           Normalise a SkyAxis coordinate value.
*        astAxisUnformat
*           Read a formatted coordinate value for a SkyAxis.

*     Protected:
*        astAxisAbbrev
*           Abbreviate a formatted SkyAxis value by skipping leading fields.
*        astAxisDistance
*           Find the distance between two SkyAxis values.
*        astAxisGap
*           Find a "nice" gap for tabulating SkyAxis values.
*        astClearAxisFormat
*           Clear the Format attribute for a SkyAxis.
*        astGetAxisDirection
*           Obtain the value of the Direction attribute for a SkyAxis.
*        astGetAxisFormat
*           Obtain a pointer to the Format attribute for a SkyAxis.
*        astGetAxisLabel
*           Obtain a pointer to the Label attribute for a SkyAxis.
*        astGetAxisSymbol
*           Obtain a pointer to the Symbol attribute for a SkyAxis.
*        astGetAxisUnit
*           Obtain a pointer to the Unit attribute for a SkyAxis.
*        astSetAxisFormat
*           Set a value for the Format attribute of a SkyAxis.
*        astTestAxisFormat
*           Test if a value has been set for the Format attribute of a SkyAxis.
*        astAxisOffset
*           Add an increment onto a supplied SkyAxis value.
*        astAxisOverlay
*           Overlay the attributes of a template SkyAxis on to another Axis.
*        astSetAttrib
*           Set an attribute value for a SkyAxis.

*  New Methods Defined:
*     Public:
*        None.

*     Protected:
*        astClearAxisAsTime
*           Clear the AsTime attribute for a SkyAxis.
*        astClearAxisCentreZero
*           Clear the CentreZero attribute for a SkyAxis.
*        astClearAxisIsLatitude
*           Clear the IsLatitude attribute for a SkyAxis.
*        astGetAxisAsTime
*           Obtain the value of the AsTime attribute for a SkyAxis.
*        astGetAxisIsLatitude
*           Obtain the value of the IsLatitude attribute for a SkyAxis.
*        astGetAxisCentreZero
*           Obtain the value of the CentreZero attribute for a SkyAxis.
*        astSetAxisAsTime
*           Set a value for the AsTime attribute of a SkyAxis.
*        astSetAxisIsLatitude
*           Set a value for the IsLatitude attribute of a SkyAxis.
*        astSetAxisCentreZero
*           Set a value for the CentreZero attribute of a SkyAxis.
*        astTestAxisAsTime
*           Test if a value has been set for the AsTime attribute of a SkyAxis.
*        astTestAxisIsLatitude
*           Test if a value has been set for the IsLatitude attribute of a
*           SkyAxis.
*        astTestAxisCentreZero
*           Test if a value has been set for the CentreZero attribute of a
*           SkyAxis.

*  Other Class Functions:
*     Public:
*        astIsASkyAxis
*           Test class membership.
*        astSkyAxis
*           Create an SkyAxis.

*     Protected:
*        astCheckSkyAxis
*           Validate class membership.
*        astInitSkyAxis
*           Initialise an SkyAxis.

*  Macros:
*     None.

*  Type Definitions:
*     Public:
*        AstSkyAxis
*           SkyAxis object type.

*     Protected:
*        AstSkyAxisVtab
*           SkyAxis virtual function table type.

*  Feature Test Macros:
*     astCLASS
*        If the astCLASS macro is undefined, only public symbols are
*        made available, otherwise protected symbols (for use in other
*        class implementations) are defined. This macro also affects
*        the reporting of error context information, which is only
*        provided for external calls to the AST library.

*  Copyright:
*     Copyright (C) 1997-2006 Council for the Central Laboratory of the
*     Research Councils

*  Licence:
*     This program is free software: you can redistribute it and/or
*     modify it under the terms of the GNU Lesser General Public
*     License as published by the Free Software Foundation, either
*     version 3 of the License, or (at your option) any later
*     version.
*     
*     This program is distributed in the hope that it will be useful,
*     but WITHOUT ANY WARRANTY; without even the implied warranty of
*     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
*     GNU Lesser General Public License for more details.
*     
*     You should have received a copy of the GNU Lesser General
*     License along with this program.  If not, see
*     <http://www.gnu.org/licenses/>.

*  Authors:
*     RFWS: R.F. Warren-Smith (Starlink)

*  History:
*     29-MAR-1996 (RFWS):
*        Original version.
*     25-APR-1996 (RFWS):
*        Made all attribute access functions protected.
*     13-MAY-1996 (RFWS):
*        Documented over-riding of the astGetAxisDirection method.
*     26-FEB-1998 (RFWS):
*        Over-ride the astAxisUnformat method.
*     8-JAN-2003 (DSB):
*        Added protected astInitSkyAxisVtab method.
*-
*/

/* Include files. */
/* ============== */
/* Interface definitions. */
/* ---------------------- */
#include "axis.h"                /* Coordinate axes (parent class) */

/* Macros */
/* ====== */

/* Define constants used to size global arrays in this module. */
/* Define numerical constants for use in thie module. */
#define AST__SKYAXIS_GETAXISFORMAT_BUFF_LEN 50
#define AST__SKYAXIS_DHMSFORMAT_BUFF_LEN 70
#define AST__SKYAXIS_DHMSUNIT_BUFF_LEN 17
#define AST__SKYAXIS_GETATTRIB_BUFF_LEN 50

/* Define a dummy __attribute__ macro for use on non-GNU compilers. */
#ifndef __GNUC__
#  define  __attribute__(x)  /*NOTHING*/
#endif


/* Type Definitions. */
/* ================= */
/* SkyAxis structure. */
/* ------------------ */
/* This structure contains all information that is unique to each
   object in the class (e.g. its instance variables). */
typedef struct AstSkyAxis {

/* Attributes inherited from the parent class. */
   AstAxis axis;                 /* Parent class structure */

/* Attributes specific to objects in this class. */
   char *skyformat;              /* Pointer to sky format string */
   int as_time;                  /* Format angles as time (hours)? */
   int is_latitude;              /* SkyAxis is a latitude axis? */
   int centrezero;               /* Normalised range is zero-centred? */
} AstSkyAxis;

/* Virtual function table. */
/* ----------------------- */
/* This table contains all information that is the same for all
   objects in the class (e.g. pointers to its virtual functions). */
#if defined(astCLASS)            /* Protected */
typedef struct AstSkyAxisVtab {

/* Properties (e.g. methods) inherited from the parent class. */
   AstAxisVtab axis_vtab;        /* Parent class virtual function table */

/* A Unique identifier to determine class membership. */
   AstClassIdentifier id;

/* Properties (e.g. methods) specific to this class. */
   int (* GetAxisAsTime)( AstSkyAxis *, int * );
   int (* GetAxisIsLatitude)( AstSkyAxis *, int * );
   int (* GetAxisCentreZero)( AstSkyAxis *, int * );
   int (* TestAxisAsTime)( AstSkyAxis *, int * );
   int (* TestAxisIsLatitude)( AstSkyAxis *, int * );
   int (* TestAxisCentreZero)( AstSkyAxis *, int * );
   void (* ClearAxisAsTime)( AstSkyAxis *, int * );
   void (* ClearAxisIsLatitude)( AstSkyAxis *, int * );
   void (* ClearAxisCentreZero)( AstSkyAxis *, int * );
   void (* SetAxisAsTime)( AstSkyAxis *, int, int * );
   void (* SetAxisIsLatitude)( AstSkyAxis *, int, int * );
   void (* SetAxisCentreZero)( AstSkyAxis *, int, int * );
} AstSkyAxisVtab;

#if defined(THREAD_SAFE)

/* Define a structure holding all data items that are global within this
   class. */
typedef struct AstSkyAxisGlobals {
   AstSkyAxisVtab Class_Vtab;
   int Class_Init;
   char DHmsFormat_Buff[ AST__SKYAXIS_DHMSFORMAT_BUFF_LEN + 1 ];
   char DHmsUnit_Buff[ AST__SKYAXIS_DHMSUNIT_BUFF_LEN + 1 ];
   char GetAttrib_Buff[ AST__SKYAXIS_GETATTRIB_BUFF_LEN + 1 ];
   char GetAxisFormat_Buff[ AST__SKYAXIS_GETAXISFORMAT_BUFF_LEN + 1 ];
   char *GhDelim;
   char *GmDelim;
   char *GsDelim;
   char *GdDelim;
   char *GamDelim;
   char *GasDelim;
} AstSkyAxisGlobals;

#endif


#endif

/* Function prototypes. */
/* ==================== */
/* Prototypes for standard class functions. */
/* ---------------------------------------- */
astPROTO_CHECK(SkyAxis)          /* Check class membership */
astPROTO_ISA(SkyAxis)            /* Test class membership */

/* Constructor. */
#if defined(astCLASS)            /* Protected. */
AstSkyAxis *astSkyAxis_( const char *, int *, ...);
#else
AstSkyAxis *astSkyAxisId_( const char *, ... )__attribute__((format(printf,1,2)));
#endif

#if defined(astCLASS)            /* Protected */

/* Initialiser. */
AstSkyAxis *astInitSkyAxis_( void *, size_t, int, AstSkyAxisVtab *,
                             const char *, int * );

/* Vtab initialiser. */
void astInitSkyAxisVtab_( AstSkyAxisVtab *, const char *, int * );

/* Loader. */
AstSkyAxis *astLoadSkyAxis_( void *, size_t, AstSkyAxisVtab *,
                             const char *, AstChannel *, int * );

/* Thread-safe initialiser for all global data used by this module. */
#if defined(THREAD_SAFE)
void astInitSkyAxisGlobals_( AstSkyAxisGlobals * );
#endif

#endif

/* Prototypes for member functions. */
/* -------------------------------- */
#if defined(astCLASS)            /* Protected */
int astGetAxisAsTime_( AstSkyAxis *, int * );
int astGetAxisIsLatitude_( AstSkyAxis *, int * );
int astGetAxisCentreZero_( AstSkyAxis *, int * );
int astTestAxisAsTime_( AstSkyAxis *, int * );
int astTestAxisIsLatitude_( AstSkyAxis *, int * );
int astTestAxisCentreZero_( AstSkyAxis *, int * );
void astClearAxisAsTime_( AstSkyAxis *, int * );
void astClearAxisIsLatitude_( AstSkyAxis *, int * );
void astClearAxisCentreZero_( AstSkyAxis *, int * );
void astSetAxisAsTime_( AstSkyAxis *, int, int * );
void astSetAxisIsLatitude_( AstSkyAxis *, int, int * );
void astSetAxisCentreZero_( AstSkyAxis *, int, int * );

#endif

/* Function interfaces. */
/* ==================== */
/* These macros are wrap-ups for the functions defined by this class
   to make them easier to invoke (e.g. to avoid type mis-matches when
   passing pointers to objects from derived classes). */

/* Interfaces to standard class functions. */
/* --------------------------------------- */
/* Some of these functions provide validation, so we cannot use them
   to validate their own arguments. We must use a cast when passing
   object pointers (so that they can accept objects from derived
   classes). */

/* Check class membership. */
#define astCheckSkyAxis(this) astINVOKE_CHECK(SkyAxis,this,0)
#define astVerifySkyAxis(this) astINVOKE_CHECK(SkyAxis,this,1)

/* Test class membership. */
#define astIsASkyAxis(this) astINVOKE_ISA(SkyAxis,this)

/* Constructor. */
#if defined(astCLASS)            /* Protected. */
#define astSkyAxis astINVOKE(F,astSkyAxis_)
#else
#define astSkyAxis astINVOKE(F,astSkyAxisId_)
#endif

#if defined(astCLASS)            /* Protected */

/* Initialiser. */
#define astInitSkyAxis(mem,size,init,vtab,name) \
astINVOKE(O,astInitSkyAxis_(mem,size,init,vtab,name,STATUS_PTR))

/* Vtab Initialiser. */
#define astInitSkyAxisVtab(vtab,name) astINVOKE(V,astInitSkyAxisVtab_(vtab,name,STATUS_PTR))
/* Loader. */
#define astLoadSkyAxis(mem,size,vtab,name,channel) \
astINVOKE(O,astLoadSkyAxis_(mem,size,vtab,name,astCheckChannel(channel),STATUS_PTR))
#endif

/* Interfaces to public member functions. */
/* -------------------------------------- */

/* Here we make use of astCheckSkyAxis to validate SkyAxis pointers
   before use. This provides a contextual error report if a pointer to
   the wrong sort of object is supplied. */
#if defined(astCLASS)            /* Protected */

#define astClearAxisAsTime(this) \
astINVOKE(V,astClearAxisAsTime_(astCheckSkyAxis(this),STATUS_PTR))
#define astClearAxisIsLatitude(this) \
astINVOKE(V,astClearAxisIsLatitude_(astCheckSkyAxis(this),STATUS_PTR))
#define astGetAxisAsTime(this) \
astINVOKE(V,astGetAxisAsTime_(astCheckSkyAxis(this),STATUS_PTR))
#define astGetAxisIsLatitude(this) \
astINVOKE(V,astGetAxisIsLatitude_(astCheckSkyAxis(this),STATUS_PTR))
#define astSetAxisAsTime(this,value) \
astINVOKE(V,astSetAxisAsTime_(astCheckSkyAxis(this),value,STATUS_PTR))
#define astSetAxisIsLatitude(this,value) \
astINVOKE(V,astSetAxisIsLatitude_(astCheckSkyAxis(this),value,STATUS_PTR))
#define astTestAxisAsTime(this) \
astINVOKE(V,astTestAxisAsTime_(astCheckSkyAxis(this),STATUS_PTR))
#define astTestAxisIsLatitude(this) \
astINVOKE(V,astTestAxisIsLatitude_(astCheckSkyAxis(this),STATUS_PTR))

#define astClearAxisCentreZero(this) \
astINVOKE(V,astClearAxisCentreZero_(astCheckSkyAxis(this),STATUS_PTR))
#define astGetAxisCentreZero(this) \
astINVOKE(V,astGetAxisCentreZero_(astCheckSkyAxis(this),STATUS_PTR))
#define astSetAxisCentreZero(this,value) \
astINVOKE(V,astSetAxisCentreZero_(astCheckSkyAxis(this),value,STATUS_PTR))
#define astTestAxisCentreZero(this) \
astINVOKE(V,astTestAxisCentreZero_(astCheckSkyAxis(this),STATUS_PTR))

#endif
#endif