2 * Copyright (C) 2008 Liam Girdwood
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 59 Temple Place, Suite 330,
17 * Boston, MA 02111-1307, USA.
28 #include <libastrodb/astrodb.h>
33 struct star_colour_data
{
46 static char * sky2kv4
[] = {"pmRA", "pmDE", "RV", "Sp", "Vder"};
48 static const struct db db_info
[] = {
49 {"V", "109", "sky2kv4", astrodb_size(sky2kv4
), sky2kv4
},
52 static void sp_insert(void *dest
, void *src
);
54 /* rgb star colours */
55 static const struct star_colour_data sp
[SP_NUM
] = {
56 {"O5V", 0.607843, 0.690196, 1.000000},
57 {"O6V", 0.635294, 0.721569, 1.000000},
58 {"O7V", 0.615686, 0.694118, 1.000000},
59 {"O8V", 0.615686, 0.694118, 1.000000},
60 {"O9V", 0.603922, 0.698039, 1.000000},
61 {"O9.5V", 0.643137, 0.729412, 1.000000},
62 {"B0V", 0.611765, 0.698039, 1.000000},
63 {"B0.5V", 0.654902, 0.737255, 1.000000},
64 {"B1V", 0.627451, 0.713725, 1.000000},
65 {"B2V", 0.627451, 0.705882, 1.000000},
66 {"B3V", 0.647059, 0.725490, 1.000000},
67 {"B4V", 0.643137, 0.721569, 1.000000},
68 {"B5V", 0.666667, 0.749020, 1.000000},
69 {"B6V", 0.674510, 0.741176, 1.000000},
70 {"B7V", 0.678431, 0.749020, 1.000000},
71 {"B8V", 0.694118, 0.764706, 1.000000},
72 {"B9V", 0.709804, 0.776471, 1.000000},
73 {"A0V", 0.725490, 0.788235, 1.000000},
74 {"A1V", 0.709804, 0.780392, 1.000000},
75 {"A2V", 0.733333, 0.796078, 1.000000},
76 {"A5V", 0.792157, 0.843137, 1.000000},
77 {"A6V", 0.780392, 0.831373, 1.000000},
78 {"A7V", 0.784314, 0.835294, 1.000000},
79 {"A8V", 0.835294, 0.870588, 1.000000},
80 {"A9V", 0.858824, 0.878431, 1.000000},
81 {"F0V", 0.878431, 0.898039, 1.000000},
82 {"F2V", 0.925490, 0.937255, 1.000000},
83 {"F4V", 0.878431, 0.886275, 1.000000},
84 {"F5V", 0.972549, 0.968627, 1.000000},
85 {"F6V", 0.956863, 0.945098, 1.000000},
86 {"F7V", 0.964706, 0.952941, 1.000000},
87 {"F8V", 1.000000, 0.968627, 0.988235},
88 {"F9V", 1.000000, 0.968627, 0.988235},
89 {"G0V", 1.000000, 0.972549, 0.988235},
90 {"G1V", 1.000000, 0.968627, 0.972549},
91 {"G2V", 1.000000, 0.960784, 0.949020},
92 {"G4V", 1.000000, 0.945098, 0.898039},
93 {"G5V", 1.000000, 0.956863, 0.917647},
94 {"G6V", 1.000000, 0.956863, 0.921569},
95 {"G7V", 1.000000, 0.956863, 0.921569},
96 {"G8V", 1.000000, 0.929412, 0.870588},
97 {"G9V", 1.000000, 0.937255, 0.866667},
98 {"K0V", 1.000000, 0.933333, 0.866667},
99 {"K1V", 1.000000, 0.878431, 0.737255},
100 {"K2V", 1.000000, 0.890196, 0.768627},
101 {"K3V", 1.000000, 0.870588, 0.764706},
102 {"K4V", 1.000000, 0.847059, 0.709804},
103 {"K5V", 1.000000, 0.823529, 0.631373},
104 {"K7V", 1.000000, 0.780392, 0.556863},
105 {"K8V", 1.000000, 0.819608, 0.682353},
106 {"M0V", 1.000000, 0.764706, 0.545098},
107 {"M1V", 1.000000, 0.800000, 0.556863},
108 {"M2V", 1.000000, 0.768627, 0.513725},
109 {"M3V", 1.000000, 0.807843, 0.505882},
110 {"M4V", 1.000000, 0.788235, 0.498039},
111 {"M5V", 1.000000, 0.800000, 0.435294},
112 {"M6V", 1.000000, 0.764706, 0.439216},
113 {"M8V", 1.000000, 0.776471, 0.427451},
114 {"B1IV", 0.615686, 0.705882, 1.000000},
115 {"B2IV", 0.623529, 0.701961, 1.000000},
116 {"B3IV", 0.650980, 0.737255, 1.000000},
117 {"B6IV", 0.686275, 0.760784, 1.000000},
118 {"B7IV", 0.666667, 0.741176, 1.000000},
119 {"B9IV", 0.705882, 0.772549, 1.000000},
120 {"A0IV", 0.701961, 0.772549, 1.000000},
121 {"A3IV", 0.745098, 0.803922, 1.000000},
122 {"A4IV", 0.764706, 0.823529, 1.000000},
123 {"A5IV", 0.831373, 0.862745, 1.000000},
124 {"A7IV", 0.752941, 0.811765, 1.000000},
125 {"A9IV", 0.878431, 0.890196, 1.000000},
126 {"F0IV", 0.854902, 0.878431, 1.000000},
127 {"F2IV", 0.890196, 0.901961, 1.000000},
128 {"F3IV", 0.890196, 0.901961, 1.000000},
129 {"F5IV", 0.945098, 0.937255, 1.000000},
130 {"F7IV", 0.941176, 0.937255, 1.000000},
131 {"F8IV", 1.000000, 0.988235, 0.992157},
132 {"G0IV", 1.000000, 0.972549, 0.960784},
133 {"G2IV", 1.000000, 0.956863, 0.949020},
134 {"G3IV", 1.000000, 0.933333, 0.886275},
135 {"G4IV", 1.000000, 0.960784, 0.933333},
136 {"G5IV", 1.000000, 0.921569, 0.835294},
137 {"G6IV", 1.000000, 0.949020, 0.917647},
138 {"G7IV", 1.000000, 0.905882, 0.803922},
139 {"G8IV", 1.000000, 0.913725, 0.827451},
140 {"K0IV", 1.000000, 0.882353, 0.741176},
141 {"K1IV", 1.000000, 0.847059, 0.670588},
142 {"K2IV", 1.000000, 0.898039, 0.792157},
143 {"K3IV", 1.000000, 0.858824, 0.654902},
144 {"O7III", 0.619608, 0.694118, 1.000000},
145 {"O8III", 0.615686, 0.698039, 1.000000},
146 {"O9III", 0.619608, 0.694118, 1.000000},
147 {"B0III", 0.619608, 0.694118, 1.000000},
148 {"B1III", 0.619608, 0.694118, 1.000000},
149 {"B2III", 0.623529, 0.705882, 1.000000},
150 {"B3III", 0.639216, 0.733333, 1.000000},
151 {"B5III", 0.658824, 0.741176, 1.000000},
152 {"B7III", 0.670588, 0.749020, 1.000000},
153 {"B9III", 0.698039, 0.764706, 1.000000},
154 {"A0III", 0.737255, 0.803922, 1.000000},
155 {"A3III", 0.741176, 0.796078, 1.000000},
156 {"A5III", 0.792157, 0.843137, 1.000000},
157 {"A6III", 0.819608, 0.858824, 1.000000},
158 {"A7III", 0.823529, 0.858824, 1.000000},
159 {"A8III", 0.819608, 0.858824, 1.000000},
160 {"A9III", 0.819608, 0.858824, 1.000000},
161 {"F0III", 0.835294, 0.870588, 1.000000},
162 {"F2III", 0.945098, 0.945098, 1.000000},
163 {"F4III", 0.945098, 0.941176, 1.000000},
164 {"F5III", 0.949020, 0.941176, 1.000000},
165 {"F6III", 0.945098, 0.941176, 1.000000},
166 {"F7III", 0.945098, 0.941176, 1.000000},
167 {"G0III", 1.000000, 0.949020, 0.913725},
168 {"G1III", 1.000000, 0.952941, 0.913725},
169 {"G2III", 1.000000, 0.952941, 0.913725},
170 {"G3III", 1.000000, 0.952941, 0.913725},
171 {"G4III", 1.000000, 0.952941, 0.913725},
172 {"G5III", 1.000000, 0.925490, 0.827451},
173 {"G6III", 1.000000, 0.925490, 0.843137},
174 {"G8III", 1.000000, 0.905882, 0.780392},
175 {"G9III", 1.000000, 0.905882, 0.768627},
176 {"K0III", 1.000000, 0.890196, 0.745098},
177 {"K1III", 1.000000, 0.874510, 0.709804},
178 {"K2III", 1.000000, 0.866667, 0.686275},
179 {"K3III", 1.000000, 0.847059, 0.654902},
180 {"K4III", 1.000000, 0.827451, 0.572549},
181 {"K5III", 1.000000, 0.800000, 0.541176},
182 {"K7III", 1.000000, 0.815686, 0.556863},
183 {"M0III", 1.000000, 0.796078, 0.517647},
184 {"M1III", 1.000000, 0.784314, 0.474510},
185 {"M2III", 1.000000, 0.776471, 0.462745},
186 {"M3III", 1.000000, 0.784314, 0.466667},
187 {"M4III", 1.000000, 0.807843, 0.498039},
188 {"M5III", 1.000000, 0.772549, 0.486275},
189 {"M6III", 1.000000, 0.698039, 0.474510},
190 {"M7III", 1.000000, 0.647059, 0.380392},
191 {"M8III", 1.000000, 0.654902, 0.380392},
192 {"M9III", 1.000000, 0.913725, 0.603922},
193 {"B2II", 0.647059, 0.752941, 1.000000},
194 {"B5II", 0.686275, 0.764706, 1.000000},
195 {"F0II", 0.796078, 0.850980, 1.000000},
196 {"F2II", 0.898039, 0.913725, 1.000000},
197 {"G5II", 1.000000, 0.921569, 0.796078},
198 {"M3II", 1.000000, 0.788235, 0.466667},
199 {"O9I", 0.643137, 0.725490, 1.000000},
200 {"B0I", 0.631373, 0.741176, 1.000000},
201 {"B1I", 0.658824, 0.756863, 1.000000},
202 {"B2I", 0.694118, 0.768627, 1.000000},
203 {"B3I", 0.686275, 0.760784, 1.000000},
204 {"B4I", 0.733333, 0.796078, 1.000000},
205 {"B5I", 0.701961, 0.792157, 1.000000},
206 {"B6I", 0.749020, 0.811765, 1.000000},
207 {"B7I", 0.764706, 0.819608, 1.000000},
208 {"B8I", 0.713725, 0.807843, 1.000000},
209 {"B9I", 0.800000, 0.847059, 1.000000},
210 {"A0I", 0.733333, 0.807843, 1.000000},
211 {"A1I", 0.839216, 0.874510, 1.000000},
212 {"A2I", 0.780392, 0.839216, 1.000000},
213 {"A5I", 0.874510, 0.898039, 1.000000},
214 {"F0I", 0.792157, 0.843137, 1.000000},
215 {"F2I", 0.956863, 0.952941, 1.000000},
216 {"F5I", 0.858824, 0.882353, 1.000000},
217 {"F8I", 1.000000, 0.988235, 0.968627},
218 {"G0I", 1.000000, 0.937255, 0.858824},
219 {"G2I", 1.000000, 0.925490, 0.803922},
220 {"G3I", 1.000000, 0.905882, 0.796078},
221 {"G5I", 1.000000, 0.901961, 0.717647},
222 {"G8I", 1.000000, 0.862745, 0.654902},
223 {"K0I", 1.000000, 0.866667, 0.709804},
224 {"K1I", 1.000000, 0.862745, 0.694118},
225 {"K2I", 1.000000, 0.827451, 0.529412},
226 {"K3I", 1.000000, 0.800000, 0.501961},
227 {"K4I", 1.000000, 0.788235, 0.462745},
228 {"K5I", 1.000000, 0.819608, 0.603922},
229 {"M0I", 1.000000, 0.800000, 0.560784},
230 {"M1I", 1.000000, 0.792157, 0.541176},
231 {"M2I", 1.000000, 0.756863, 0.407843},
232 {"M3I", 1.000000, 0.752941, 0.462745},
233 {"M4I", 1.000000, 0.725490, 0.407843},
234 {"N", 1.000000, 0.615686, 0.000000},
238 static inline void get_sp_index (struct star_object
*object
, gchar
*spect
, gint match
)
243 for (object
->dobject
.aobject
.type
= 0;
244 object
->dobject
.aobject
.type
< SP_NUM
;
245 object
->dobject
.aobject
.type
++) {
246 //printf("%s %s\n", sp[object->dobject.aobject.type].sp, spect);
247 if (!strncmp(sp
[object
->dobject
.aobject
.type
].sp
,
254 static void sp_insert(void *dest
, void *src
)
256 struct star_object
*so
=
257 (struct star_object
*)((glong
)dest
-
258 astrodb_offset(struct star_object
, sp
));
259 //printf("insert\n");
261 get_sp_index(so
, src
, strlen(src
));
264 static struct astrodb_schema_object star_fields
[] = {
265 astrodb_member("Name", "Name", struct star_object
, dobject
.aobject
.name
,
266 CT_STRING
, "", 0, NULL
),
267 astrodb_member("ID", "ID", struct star_object
, dobject
.aobject
.id
,
268 CT_STRING
, "", 0, NULL
),
269 astrodb_member("RA", "RA", struct star_object
, dobject
.posn
.ra
,
270 CT_DOUBLE
, "degrees", 0, NULL
),
271 astrodb_member("DEC", "DEC", struct star_object
, dobject
.posn
.dec
,
272 CT_DOUBLE
, "degrees", 0, NULL
),
273 astrodb_gmember("RA Hours", "RAh", struct star_object
, dobject
.posn
.ra
,
274 CT_DOUBLE_HMS_HRS
, "hours", 2, NULL
),
275 astrodb_gmember("RA Minutes", "RAm", struct star_object
, dobject
.posn
.ra
,
276 CT_DOUBLE_HMS_MINS
, "minutes", 1, NULL
),
277 astrodb_gmember("RA Seconds", "RAs", struct star_object
, dobject
.posn
.ra
,
278 CT_DOUBLE_HMS_SECS
, "seconds", 0, NULL
),
279 astrodb_gmember("DEC Degrees", "DEd", struct star_object
, dobject
.posn
.dec
,
280 CT_DOUBLE_DMS_DEGS
, "degrees", 3, NULL
),
281 astrodb_gmember("DEC Minutes", "DEm", struct star_object
, dobject
.posn
.dec
,
282 CT_DOUBLE_DMS_MINS
, "minutes", 2, NULL
),
283 astrodb_gmember("DEC Seconds", "DEs", struct star_object
, dobject
.posn
.dec
,
284 CT_DOUBLE_DMS_SECS
, "seconds", 1, NULL
),
285 astrodb_gmember("DEC sign", "DE-", struct star_object
, dobject
.posn
.dec
,
286 CT_SIGN
, "", 0, NULL
),
287 astrodb_member("Visual Mag", "Vmag", struct star_object
, dobject
.Vmag
,
288 CT_FLOAT
, "", 0, NULL
),
289 astrodb_member("sp", "Sp", struct star_object
, sp
,
290 CT_STRING
, "", 0, sp_insert
),
291 astrodb_member("HD", "HD", struct star_object
, HD
,
292 CT_STRING
, "", 0, NULL
),
293 astrodb_member("SAO", "SAO", struct star_object
, SAO
,
294 CT_INT
, "", 0, NULL
),
297 /* we only accept the --prefix as our 1 arg*/
298 int main (int argc
, char* argv
[])
301 struct astrodb_library
*lib
;
304 printf ("usage: %s prefix\n", argv
[0]);
308 printf("%s using libastrodb %s\n", argv
[0], astrodb_get_version());
309 printf("\n\n** Downloading 25Mb data. This may take some time.\n");
311 /* set the remote db and initialise local repository/cache */
312 lib
= astrodb_open_library("ftp://cdsarc.u-strasbg.fr/pub/cats", argv
[1]);
314 printf("failed to open library\n");
318 for (i
= 0; i
< astrodb_size(db_info
); i
++) {
319 struct astrodb_db
*db
;
320 struct astrodb_table
*table
;
322 /* create a dbalog */
323 db
= astrodb_create_db(lib
, db_info
[i
].cls
, db_info
[i
].num
,
324 0.0, 360.0, -90.0, 90.0, 15.0, -2.0, 0);
326 printf("failed to create db\n");
330 table
= astrodb_table_create(db
, "sky2kv4", ADB_MEM
| ADB_FILE
);
332 printf("failed to create table\n");
336 /* add dataset fields */
337 //for (j = 0; j < db_info[i].nfields; j++)
338 // if (astrodb_table_add_custom_field(table, db_info[i].fields[j]))
341 /* Vmag is blank in some records in the dataset, so we use can Vder
342 * as an alternate field.
344 if (astrodb_table_alt_column(table
, "Vmag", "Vder", 0))
345 printf("warning: failed to add alt index\n");
347 if (astrodb_table_register_schema(table
, star_fields
,
348 astrodb_size(star_fields
)) < 0)
349 g_critical("%s: failed to register object type\n", __func__
);
351 /* We want to quickly search the dataset based on object ID and HD number */
352 if (astrodb_table_hash_key(table
, "ID"))
353 g_warning("%s: failed to hash on ID\n", __func__
);
354 if (astrodb_table_hash_key(table
, "HD"))
355 g_warning("%s: failed to hash on HD\n", __func__
);
357 /* Import the dataset from remote/local repo into memory/disk cache */
358 if (astrodb_table_open(table
, 0, 0, 0) < 0) {
359 printf("failed to open table\n");
363 /* were done with the dataset */
364 astrodb_table_close(table
);
366 /* were now done with dbalog */
370 astrodb_close_library(lib
);