optimizations: general renderering speedups.
[nova.git] / src / db / db.c
blobcf8943dc463b63f5401cf61d10a2a9fe704d968c
1 /*
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.
18 */
20 #include <stdio.h>
21 #include <string.h>
22 #include <gtk/gtk.h>
23 #include "db.h"
24 #include "star.h"
26 #define CAT_HOME NOVA_CATALOG_DIR
28 struct table_desc {
29 gchar *cat_name;
30 gchar *class;
31 gchar *num;
32 gchar* table_name;
33 struct astro_object *object;
34 struct astrodb_db *cat;
35 struct astrodb_table *table;
38 struct astro_object star_table = {
39 .type = "star",
40 .init = star_object_init,
41 .free = star_object_free,
42 .render = star_object_render,
45 /* default datasets */
46 static struct table_desc dlib[] = {
47 {"Sky2000", "V", "109", "sky2kv4", &star_table},
50 static struct table_desc olib[16];
52 static struct astrodb_library *nova_lib;
54 gint db_init(void)
56 gint i;
58 nova_lib = astrodb_open_library("ftp://cdsarc.u-strasbg.fr/pub/cats",
59 CAT_HOME);
60 if (nova_lib == NULL)
61 g_critical("failed to open astro library at %s\n", CAT_HOME);
63 for (i = 0; i < astrodb_size(dlib); i++) {
65 /* ra,dec,mag bounds are set here along with the 3D
66 * tile array size */
67 dlib[i].cat = astrodb_create_db(nova_lib, dlib[i].class,
68 dlib[i].num,
69 0.0, 360.0,
70 -90.0, 90.0,
71 18.0, -2.0, 0);
72 if (dlib[i].cat == NULL)
73 g_critical("failed to create db for class %s num %s\n",
74 dlib[i].class, dlib[i].num);
76 /* use the first dataset in this example */
77 dlib[i].table = astrodb_table_create(dlib[i].cat,
78 dlib[i].table_name,
79 ADB_MEM | ADB_FILE);
80 if (dlib[i].table == NULL)
81 g_critical("failed to create table %s\n",
82 dlib[i].table_name);
84 if (dlib[i].object->init)
85 dlib[i].object->init(dlib[i].table);
87 return 0;
90 void db_release(void)
92 gint i;
94 for (i = 0; i < astrodb_size(dlib); i++) {
95 if (dlib[i].object->free)
96 dlib[i].object->free(dlib[i].table);
97 astrodb_db_free(dlib[i].cat);
99 astrodb_close_library(nova_lib);
102 struct astrodb_table *db_get_table(gchar *name)
104 gint i;
106 for (i = 0; i < astrodb_size(olib); i++) {
107 if (!strncmp(name, olib[i].table_name, strlen(name)))
108 return olib[i].table;
111 return NULL;
114 struct astrodb_table *db_get_default_table(gchar *type)
116 gint i;
118 for (i = 0; i < astrodb_size(dlib); i++) {
119 if (!strncmp(type, dlib[i].object->type, strlen(type)))
120 return dlib[i].table;
123 return NULL;