CARMA C++
scan.h
1 #ifndef SCAN_H
2 #define SCAN_H
3 
4 #include "carma/szaarrayutils/input.h"
5 #include "carma/szaarrayutils/output.h"
6 #include "carma/szaarrayutils/cache.h"
7 #include "carma/szaarrayutils/scancache.h"
8 
9 /*
10  * The opaque ScanCatalog type contains a catalog of scans, indexed
11  * by name and number. Its definition and implementation is private
12  * to scan.c.
13  */
14 typedef struct ScanCatalog ScanCatalog;
15 
16 /*
17  * Create an empty scan catalog.
18  */
19 ScanCatalog *new_ScanCatalog(void);
20 
21 /*
22  * Delete a scan catalog.
23  */
24 ScanCatalog *del_ScanCatalog(ScanCatalog *sc);
25 
26 /*
27  * Read scan catalog entries from an input stream. Note that
28  * the new scans are added to the existing catalog. If a new scan
29  * has the same name as an existing catalog entry, the existing catalog
30  * entry is overwritten with the new one.
31  */
32 int input_ScanCatalog(ScanCatalog *sc, InputStream *stream);
33 
34 /*
35  * Read scan catalog entries from a file. This is a wrapper around
36  * input_ScanCatalog().
37  */
38 int read_ScanCatalog(ScanCatalog *sc, char *dir, char *file);
39 
40 /*
41  * Write scan catalog entries to an output stream, using the format
42  * expected by input_ScanCatalog().
43  */
44 int output_ScanCatalog(ScanCatalog *sc, OutputStream *stream);
45 
46 /*
47  * Write scan catalog entries to a file. This is a wrapper around
48  * output_ScanCatalog().
49  */
50 int write_ScanCatalog(ScanCatalog *sc, char *dir, char *file);
51 
52 /*
53  * The opaque Scan datatype is a union of all scan types.
54  * Its definition is private to scan.c. Be careful about
55  * cacheing (Scan *) pointers. If add_Scan() et al. is called
56  * to change the definition of an existing scan (identified by name),
57  * then the original (Scan *) pointer associated with that name will
58  * become invalid and should not be used. It is safer to record catalog
59  * numbers or scan names (see get_ScanId).
60  */
61 namespace sza {
62  namespace array {
63 
64  typedef union ScanUnion Scan;
65 
66  /*
67  * Enumerate the supported types of scans
68  */
69  enum ScanType {
70  SCAN_NORMAL, /* All scans */
71  SCAN_BOGUS, /* A fake scan */
72  SCAN_ALIAS /* An alternative name for another scan */
73  };
74 
75  /*
76  * Set the max length of a scan name (including '\0').
77  * This should be set equal to SCAN_LEN in cbiregs.h.
78  */
79  enum {SCAN_NAME_MAX=12};
80 
81  /*
82  * All scans share an initial member of the following type.
83  *
84  * When a given scan name is enterred into a ScanCatalog for the
85  * first time, it is assigned a catalog index. This index can thereafter
86  * be used as a unique synonym for the scan name, since it doesn't change
87  * even if the definition of the scan associated with that name is
88  * modified.
89  */
90  struct ScanId {
91  ScanType type; /* The enumerated type of the scan */
92  char name[SCAN_NAME_MAX]; /* The name of the scan */
93  int number; /* The catalog index tied to name[] */
94  };
95 
96  /*
97  * The following scan type is for non-sidereal scans whos positions
98  * are recorded in ephemeris files. The ephemeris file is not kept
99  * open at all times, instead up to EPHEM_CACHE_SIZE contemporary
100  * entries are kept in a cache. At any given time three points from
101  * this cache are loaded into quadratic interpolators, to provide more
102  * precise positions. The middle of these three entries is at element
103  * 'midpt' of the cache. When the cache has been exhausted, it will
104  * be refreshed from the ephemeris file.
105  */
106  struct NormalScan {
107  ScanId id; /* The generic scan identification header */
108  char *file; /* The pathname of the scan file */
109  ScanCache offsets; /* A cache of size <= SCAN_CACHE_SIZE entries */
110  };
111 
115  struct AliasScan {
116  ScanId id; /* The generic scan identification header */
117  Scan **sptr; /* The catalog entry of the scan. Using this relies */
118  /* on the fact the only destructive operation that */
119  /* is allowed on an existing catalog entry is */
120  /* to replace its contents with a new scan of the */
121  /* same name. We can't actually store the (Scan *) */
122  /* pointer because that can change. */
123  };
124 
125  /*
126  * This is just a placeholder. So that the scan catalog can contain
127  * entries like "none"
128  */
129  struct BogusScan {
130  ScanId id; /* The generic scan identification header */
131  };
132 
133  /*
134  * Define a generic scan container. This is typedef'd to Scan
135  * in scan.h.
136  */
137  union ScanUnion {
138  ScanId id; /* The first members of all scan types */
139  NormalScan normal; /* An ordinary scan */
140  BogusScan bogus; /* A fake scan */
141  AliasScan alias; /* A link to another scan */
142  };
143  };
144 };
145 
146 /*
147  * The following function returns non-zero if a given character is
148  * valid within a scan name.
149  */
150 int valid_scan_char(int c);
151 
152 /*
153  * Get a copy of the identification header of a given Scan.
154  * On error it returns non-zero. If resolve is true and the
155  * scan is an alias to another scan, the id of the aliased
156  * scan will be returned in its place (this rule is applied
157  * recursively).
158  */
159 int get_ScanId(sza::array::Scan *scan, int resolve, sza::array::ScanId *id);
160 
161 /*
162  * Return the scan-catalog index of a given scan (-1 on error).
163  * See the documentation of ScanId for the usage of such indexes.
164  * The resolve member is used as described for get_ScanId().
165  */
166 int get_Scan_number(sza::array::Scan *scan, int resolve);
167 
168 /*
169  * Use the following functions to add scans to the catalog.
170  * Each function returns NULL on failure.
171  */
172 sza::array::Scan *add_NormalScan(ScanCatalog *sc, char *name, char* file);
173 sza::array::Scan *add_BogusScan(ScanCatalog *sc, char *name);
174 sza::array::Scan *add_AliasScan(ScanCatalog *sc, char *name, char *scan);
175 
176 /*
177  * Use the following functions to look up a scan. The first is
178  * useful for finding a scan named by a user. It uses a hash table
179  * so it should be relatively fast. The second uses the ordinal
180  * position of the scan in the catalog. This should be more
181  * efficient for repeat lookups of the same scan and can also be
182  * used to step through the catalog. Note that if you have a ScanId
183  * object, the ordinal number of the scan is given by the 'number'
184  * field.
185  */
186 sza::array::Scan* find_ScanByName(ScanCatalog* sc, char* name);
187 sza::array::Scan* find_ScanByNumber(ScanCatalog* sc, int number);
188 
189 /*
190  * Return the number of scans that are currently in a scan catalog.
191  */
192 int size_ScanCatalog(ScanCatalog* sc);
193 
194 int get_scan_window(ScanCatalog* scanc, sza::array::Scan* scan, double tt,
195  sza::array::CacheWindow* win);
196 
197 sza::array::Scan* resolve_ScanAliases(sza::array::Scan* scan);
198 
199 #endif
The following type of scan is a symbolic link to another scan.
Definition: scan.h:115
......................................................................
Definition: scancache.h:23