My Project
 All Classes Files Functions Variables Enumerations Enumerator Friends Macros Pages
source.h
1 #ifndef source_h
2 #define source_h
3 
4 #include "gcp/control/code/unix/libunix_src/common/input.h"
5 #include "gcp/control/code/unix/libunix_src/common/output.h"
6 #include "gcp/control/code/unix/libunix_src/common/quad.h"
7 #include "gcp/control/code/unix/libunix_src/common/astrom.h"
8 #include "gcp/control/code/unix/libunix_src/common/cache.h"
9 
10 /*
11  * In all of the following functions time is specified in the form
12  * of Modified Julian Dates (Julian Date - 2400000.5). If the time
13  * is specified as -1.0, then the current time will automatically
14  * be substituted. See astrom.h for time generation and manipulation
15  * functions. Also note that in some places where one should strictly
16  * use Barycentric Dynamical Time, Terrestrial Time is used instead.
17  * The two time systems differ by at most a couple of milli-seconds.
18  *
19  * Thus arguments named utc denote Universal Coordinated Time's, whereas
20  * arguments named tt denote Terrestrial Time.
21  */
22 
23 /*
24  * The opaque SourceCatalog type contains a catalog of sources, indexed
25  * by name and number. Its definition and implementation is private
26  * to source.c.
27  */
28 typedef struct SourceCatalog SourceCatalog;
29 
30 /*
31  * Create an empty source catalog.
32  */
33 SourceCatalog *new_SourceCatalog(bool update=false);
34 
35 /*
36  * Delete a source catalog.
37  */
38 SourceCatalog *del_SourceCatalog(SourceCatalog *sc);
39 
40 /*
41  * Read source catalog entries from an input stream. Note that
42  * the new sources are added to the existing catalog. If a new source
43  * has the same name as an existing catalog entry, the existing catalog
44  * entry is overwritten with the new one.
45  */
46 int input_SourceCatalog(SourceCatalog *sc, InputStream *stream);
47 
48 /*
49  * Read source catalog entries from a file. This is a wrapper around
50  * input_SourceCatalog().
51  */
52 int read_SourceCatalog(SourceCatalog *sc, char *dir, char *file);
53 
54 /*
55  * Write source catalog entries to an output stream, using the format
56  * expected by input_SourceCatalog().
57  */
58 int output_SourceCatalog(SourceCatalog *sc, OutputStream *stream);
59 
60 /*
61  * Write source catalog entries to a file. This is a wrapper around
62  * output_SourceCatalog().
63  */
64 int write_SourceCatalog(SourceCatalog *sc, char *dir, char *file);
65 
66 /*
67  * Specify a new UT1-UTC ephemeris file.
68  */
69 int sc_set_ut1utc_ephemeris(SourceCatalog *sc, char *dir, char *file);
70 
71 namespace gcp {
72  namespace control {
73 
74  typedef union SourceUnion Source;
75 
76  /*
77  * Enumerate the supported types of sources.
78  */
79  enum SourceType {
80  SRC_J2000, /* A source at fixed J2000 RA and Dec */
81  SRC_EPHEM, /* An ephemeris source (eg. a planet) */
82  SRC_FIXED, /* A source at fixed azimuth and elevation */
83  SRC_ALIAS, /* An alternative name for another source */
84  SRC_CENTER, /* A source at fixed azimuth and elevation which should be tracked */
85  SRC_UNKNOWN /* A type we can assign to unititalized
86  SourceType variables */
87  };
88 
89  /*
90  * Set the max length of a source name (including '\0'). This
91  * should be set equal to SRC_LEN in genericregs.h.
92  */
93  enum {SRC_NAME_MAX=30};
94 
95 
96  /*
97  * All source types share an initial member of the following type.
98  *
99  * When a given source name is enterred into a SourceCatalog for the
100  * first time, it is assigned a catalog index. This index can thereafter
101  * be used as a unique synonym for the source name, since it doesn't change
102  * even if the definition of the source associated with that name is
103  * modified.
104  */
105  struct SourceId {
106  SourceType type; /* The enumerated type of the source */
107  char name[SRC_NAME_MAX]; /* The name of the source */
108  int number; /* The catalog index tied to name[] */
109  };
110 
111  /*
112  * The following type of source is specified at a fixed J2000.0 Right
113  * Ascension and Declination.
114  */
115  struct J2000Source {
116  SourceId id; /* The generic source identification header */
117  double ra; /* The mean right-ascension at epoch J2000.0 (radians) */
118  double dec; /* The mean declination at epoch J2000.0 (radians) */
119  float pmra; /* The proper motion in Right Ascension (radians) */
120  float pmdec; /* The proper motion in Declination (radians) */
121  float mag; /* The magnitude of the star */
122  };
123 
124  /*
125  * The following type of source is located at a fixed azimuth and
126  * elevation.
127  */
128  struct FixedSource {
129  SourceId id; /* The generic source identification header */
130  unsigned axis_mask;/* A bitwise union of source.h::SourceAxes enumerators */
131  /* specifying which of the following axes are */
132  /* significant to this source. */
133  double az; /* The target azimuth (radians) */
134  double el; /* The target elevation (radians) */
135  double dk; /* The target deck-angle (radians) */
136  };
137 
138  /*
139  * The following type of source is located at a fixed azimuth and
140  * elevation.
141  */
142  struct CenterSource {
143  SourceId id; /* The generic source identification header */
144  unsigned axis_mask;/* A bitwise union of source.h::SourceAxes enumerators */
145  /* specifying which of the following axes are */
146  /* significant to this source. */
147  double az; /* The target azimuth (radians) */
148  double el; /* The target elevation (radians) */
149  double dk; /* The target deck-angle (radians) */
150  };
151 
152  struct EphemEntry {
153  double ra; /* The geocentric apparent Right Ascension (radians) */
154  double dec; /* The geocentric apparent Declination (radians) */
155  double dist; /* The geocentric distance of the source (AU) */
156  double tt; /* The terrestrial time of the entry (MJD) */
157  };
158 
159  /*
160  * The following source type is for non-sidereal sources whos positions
161  * are recorded in ephemeris files. The ephemeris file is not kept open
162  * at all times, instead up to EPHEM_CACHE_SIZE contemporary entries are
163  * kept in a cache. At any given time three points from this cache are
164  * loaded into quadratic interpolators, to provide more precise positions.
165  * The middle of these three entries is at element 'midpt' of the cache.
166  * When the cache has been exhausted, it will be refreshed from the
167  * ephemeris file.
168  */
169  struct EphemSource {
170  SourceId id; /* The generic source identification header */
171  char *file; /* The pathname of the ephemeris file */
172  EphemEntry *cache; /* A cache of size<=EPHEM_CACHE_SIZE entries */
173  int size; /* The number of elements in cache[] */
174  int midpt; /* The middle element of the interpolation triple */
175  QuadPath *ra; /* The Right Ascension interpolator */
176  QuadPath *dec; /* The Declination interpolator */
177  QuadPath *dist; /* The Distance interpolator */
178  };
179 
180  /*
181  * The following type of source is a symbolic link to another source.
182  */
183  struct AliasSource {
184  SourceId id; /* The generic source identification header */
185  Source **sptr; // The catalog entry of the source. Using
186  // this relies on the fact the only
187  // destructive operation that is allowed on
188  // an existing catalog entry is to replace
189  // its contents with a new source of the same
190  // name. We can't actually store the (Source
191  // *) pointer because that can change.
192  };
193 
194  /*
195  * The opaque Source datatype is a union of all source types.
196  * Its definition is private to source.c. Be careful about
197  * cacheing (Source *) pointers. If add_J2000Source() et al. is called
198  * to change the definition of an existing source (identified by name),
199  * then the original (Source *) pointer associated with that name will
200  * become invalid and should not be used. It is safer to record catalog
201  * numbers or source names (see get_SourceId).
202  */
203  union SourceUnion {
204  SourceId id; /* The first members of all source types */
205  J2000Source j2000; /* A source at fixed Ra and Dec (J2000) */
206  EphemSource ephem; /* An ephemeris source */
207  FixedSource fixed; /* A source at fixed azimuth and elevation */
208  CenterSource center; /* A source at fixed azimuth and elevation */
209  AliasSource alias; /* A link to another source */
210  };
211 
212  /*
213  * Fixed sources directly set the position of one or more of the
214  * azimuth, elevation and deck axes. The following enumerators
215  * are used in a bitwise union to specify which of the axes are
216  * specified by the source.
217  */
218  enum SourceAxes {
219  SRC_AZ_AXIS = 1, /* The source specifies the azimuth axis */
220  SRC_EL_AXIS = 2, /* The source specifies the elevation axis */
221  SRC_DK_AXIS = 4, /* The source specifies the deck axis */
222  /* The source specifies all of the axes */
223  SRC_ALL_AXES = SRC_AZ_AXIS | SRC_EL_AXIS | SRC_DK_AXIS
224  };
225  };
226 };
227 
228 /*
229  * The following function returns non-zero if a given character is
230  * valid within a source name.
231  */
232 int valid_source_char(int c);
233 
234 /*
235  * Get a copy of the identification header of a given Source.
236  * On error it returns non-zero. If resolve is true and the
237  * source is an alias to another source, the id of the aliased
238  * source will be returned in its place (this rule is applied
239  * recursively).
240  */
241 int get_SourceId(gcp::control::Source* src, int resolve, gcp::control::SourceId *id);
242 
243 /*
244  * Return the source-catalog index of a given source (-1 on error).
245  * See the documentation of SourceId for the usage of such indexes.
246  * The resolve member is used as described for get_SourceId().
247  */
248 int get_Source_number(gcp::control::Source* src, int resolve);
249 
250 /*
251  * Use the following functions to add sources to the catalog.
252  * Each function returns NULL on failure.
253  */
254 gcp::control::Source* add_J2000Source(SourceCatalog *sc, char *name, double ra,
255  double dec, float pmra, float pmdec);
256 gcp::control::Source* add_EphemSource(SourceCatalog *sc, char *name, char *file);
257 gcp::control::Source* add_FixedSource(SourceCatalog *sc, char *name,
258  unsigned axis_mask, double az, double el,
259  double dk);
260 gcp::control::Source* add_CenterSource(SourceCatalog *sc, char *name,
261  unsigned axis_mask, double az, double el,
262  double dk);
263 gcp::control::Source* add_AliasSource(SourceCatalog *sc, char *name, char *source);
264 
265 /*
266  * Use the following functions to look up a source. The first is
267  * useful for finding a source named by a user. It uses a hash table
268  * so it should be relatively fast. The second uses the ordinal
269  * position of the source in the catalog. This should be more
270  * efficient for repeat lookups of the same source and can also be
271  * used to step through the catalog. Note that if you have a SourceId
272  * object, the ordinal number of the source is given by the 'number'
273  * field.
274  */
275 gcp::control::Source* find_SourceByName(SourceCatalog *sc, char *name);
276 gcp::control::Source* find_SourceByNumber(SourceCatalog *sc, int number);
277 
278 /*
279  * Return the number of sources that are currently in a source catalog.
280  */
281 int size_SourceCatalog(SourceCatalog *sc);
282 
283 /*
284  * The following types are used with the source_visibility() function
285  * to return the projected visibility of a given source with respect
286  * to a specified horizon elevation.
287  */
288 typedef enum {
289  SRC_NEVER_RISES, /* The source is always below the horizon */
290  SRC_NEVER_SETS, /* The source is always above the horizon */
291  SRC_ALTERNATES, /* The source periodically crosses the horizon */
292  SRC_IRREGULAR /* A source who's path is too different from */
293  /* sidereal for rise and set times to be determined. */
294 } SourceSched;
295 
296 /*
297  * The source_info() function takes a bit-wise union of the following
298  * options for its "options" argument. This argument tells the
299  * source_info() function which parameters you want it to compute.
300  */
301 typedef enum {
302  SIO_EQUAT = 1, /* Topocentric equatorial coordinates */
303  SIO_HORIZ = 2, /* Topocentric horizon coordinates and rates */
304  SIO_ALMANAC = 4, /* Rise and set times */
305  /*
306  * The following option selects all options.
307  */
308  SIO_ALL = SIO_EQUAT | SIO_HORIZ | SIO_ALMANAC
309 } SrcInfoOpt;
310 
311 /*
312  * Describe the structure that source_info() uses to return contemporary
313  * information about a given source. All angles are in radians.
314  */
315 typedef struct {
316  double az; /* The azimuth of a source (radians) */
317  double el; /* The elevation of a source (radians) */
318  double pa; /* The parallactic angle of a source (radians) */
319 } SourceAzElPa;
320 
321 typedef struct {
322  double utc; /* The UTC for which this information was computed (MJD)*/
323  double ut1; /* The UT1 equivalent of 'utc' (MJD) */
324  double tt; /* The corresponding Terrestrial Time (MJD) */
325  double lst; /* The corresponding Local Apparent Sidereal Time, */
326  /* measured in radians. */
327  double ra,dec; /* The topocentric Right Ascension and Declination */
328  unsigned axis_mask; /* For fixed sources this mask contains a bitwise */
329  /* union of gcp::util::Axis::Type enumerators
330  to specify which of the telescope axes are
331  specified by this source. */
332  SourceAzElPa coord; /* The horizon coordinates of the source */
333  SourceAzElPa rates; /* The az,el,pa motion of the source (radians/sec)*/
334  SourceSched sched; /* The visibility type of the source */
335  double rise,set; /* The rise and set times (UTC) of the source if */
336  /* sched==SRC_ALTERNATES */
337 } SourceInfo;
338 
339 /*
340  * Fill in a provided SourceInfo structure with details about a given
341  * source, as seen from a given site at a given time. The (Site *) datatype
342  * needed by the "site" argument is defined in astrom.h and initialized with
343  * set_Site(). The utc argument must be given either as a Modified Julian Date,
344  * or as the value -1 which selects the current time. The horizon argument is
345  * the local elevation of the horizon in radians. The options argument is a
346  * bit-wise union of the SrcInfoOpt options defined above.
347  */
348 int source_info(SourceCatalog *sc, gcp::control::Site *site,
349  gcp::control::Source* src,
350  double utc, double horizon, unsigned options, SourceInfo *info);
351 
352 /*
353  * Return the time window over which the 3 UT1-UTC interpolation
354  * entries for the time 'utc' are usable. The returned time
355  * limits are specified in UTC. If no UT1-UTC ephemeris has been
356  * specified via sc_set_ut1utc_ephemeris() then win->tmin and win->tmax
357  * will be set to 0.0.
358  */
359 int get_ut1utc_window(SourceCatalog *sc, double utc,
361 
362 /*
363  * Return the contents of the quadratic interpolator of UT1-UTC at
364  * Universal Coordinated Time, 'utc'. The QuadData x values are UTC
365  * expressed as MJDs, and the y values are the values of UT1-UTC in
366  * seconds.
367  */
368 int get_ut1utc_QuadData(SourceCatalog *sc, double utc,
369  gcp::control::QuadData *data);
370 
371 /*
372  * Return the time window over which the 3 equation-of-the-equinoxes
373  * interpolation entries for the time 'tt' are usable.
374  * The returned time limits are specified in TT.
375  */
376 int get_eqneqx_window(SourceCatalog *sc, double tt,
378 
379 /*
380  * Return the contents of the quadratic interpolator of the equation of
381  * the equinoxes at time 'tt'. The QuadData x values are TT times
382  * expressed as MJDs, and the y values are the values of the equation
383  * of the equinoxes, measured in radians.
384  */
385 int get_eqneqx_QuadData(SourceCatalog *sc, double tt,
386  gcp::control::QuadData *data);
387 
388 /*
389  * Given an ephemeris source, return the time window over which
390  * the 3 ephemeris in its quadratic interpolators, initialized for
391  * the Terrestrial Time 'tt', are usable. Since src must be an ephemeris
392  * source, you should call get_SourceId() to check its type before calling
393  * this function.
394  *
395  * The returned time limits are specified in TT.
396  */
397 int get_ephem_window(SourceCatalog *sc, gcp::control::Source* src, double tt,
399 
400 /*
401  * Return the contents of the quadratic interpolators of a specified
402  * ephemeris source, valid for the time 'tt'. Since src must be an
403  * ephemeris source, you should call get_SourceId() to check its type
404  * before calling this function. The QuadData x axis values are all
405  * Terrestrial Times, expressed as MJDs. The ra interpolator y values
406  * are geocentric Right Ascensions in radians, and the dec interpolator
407  * y values are geocentric Declinations in radians. The dist interpolator
408  * y values are geocentric source distances in AU. For sources who's
409  * distances are unknown, 0 is substituted.
410  */
411 int get_ephem_QuadData(SourceCatalog *sc, gcp::control::Source* src, double tt,
414  gcp::control::QuadData *dist);
415 
416 /*
417  * Return the time window over which the cached precession and nutation
418  * parameters for time (tt) are usable for J2000 sources. These are
419  * parameters used with the slalib slaMapqk/slaMapqkz functions to
420  * precess the geocentric Right Ascension and declination of a source
421  * from J2000 to the current epoch. The Right Ascensions of J2000 sources
422  * are updated whenever this cache is updated.
423  *
424  * The returned time limits are specified in TT.
425  */
426 int get_mapqk_window(SourceCatalog *sc, double tt,
428 
429 /*
430  * Return the contents of the precession/nutation parameter cache for
431  * time 'tt'. See slaMapqk() and slaMapqkz() for details of how to use
432  * the parameters in the cache.
433  */
434 typedef struct {
435  double mappa[21]; /* The array of cached parameters. */
436  /* This is the array of parameters returned by */
437  /* the slalib slaMappa() function. */
438 } MapqkData;
439 
440 int get_mapqk_data(SourceCatalog *sc, double tt, MapqkData *data);
441 
442 /*
443  * Return the geocentric Right Ascension and Declination of a
444  * J2000 source precessed to time 'tt'. An error will be returned
445  * if 'src' is not a J2000 source, so be sure to use get_SourceId()
446  * to determine the type of the source before making this call.
447  */
448 int precess_J2000_source(SourceCatalog *sc, gcp::control::Source* src, double tt,
449  double *ra, double *dec);
450 
451 /*
452  * Get the coordinates of a fixed source.
453  */
454 int describe_fixed_source(gcp::control::Source* src, SourceAzElPa *coord,
455  unsigned *axis_mask);
456 
457 /*
458  * Get the coordinates of a center source.
459  */
460 int describe_center_source(gcp::control::Source* src, SourceAzElPa *coord,
461  unsigned *axis_mask);
462 
463 unsigned nSource(SourceCatalog* sc);
464 
465 #endif
Definition: source.c:236
Definition: quad.h:40
Definition: input.h:87
Definition: source.h:315
Definition: source.h:203
Definition: source.h:434
Definition: cache.h:14
Definition: source.h:321
Definition: logfile.c:20
Definition: output.h:40
Definition: source.h:105
Definition: astrom.h:10