2 * This program is free software; you can redistribute it and/or modify
3 * it under the terms of the GNU General Public License as published by
4 * the Free Software Foundation; either version 2 of the License, or
5 * (at your option) any later version.
7 * This program is distributed in the hope that it will be useful,
8 * but WITHOUT ANY WARRANTY; without even the implied warranty of
9 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10 * GNU General Public License for more details.
12 * You should have received a copy of the GNU General Public License
13 * along with this program; if not, write to the Free Software
14 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
16 * Copyright (C) 2008 Liam Girdwood
23 #include <libastrodb/astrodb.h>
27 * Search for all G type stars
28 * Uses Wildcard "G*" to match with Sp
30 static int search(struct astrodb_table
* table
)
32 struct astrodb_slist
*res
= NULL
;
33 struct astrodb_search
*srch
;
36 srch
= astrodb_search_create(table
);
37 astrodb_search_add_comparator(srch
, "MK", ADB_COMP_LT
, "G*");
38 astrodb_search_add_operator(srch
, ADB_OP_OR
);
40 err
= astrodb_search_get_results(srch
, &res
, ADB_SMEM
);
42 printf("Search init failed %d\n", err
);
44 printf(" Search got %d objects out of %d tests\n",
45 astrodb_search_get_hits(srch
),
46 astrodb_search_get_tests(srch
));
47 astrodb_search_put_results(res
);
48 astrodb_search_free(srch
);
52 void init_table(void *data
, void *user
)
54 struct astrodb_table_info
*i
= (struct astrodb_table_info
*) data
;
55 struct astrodb_db
*db
= (struct astrodb_db
*) user
;
56 struct astrodb_table
*table
;
58 struct astrodb_slist
*res
= NULL
;
59 int table_size
, object_size
;
61 printf("\nDset: \t%s\nrecords:\t%d\nrec len: \t%d\ntitle: \t%s\n",
62 i
->name
, i
->records
, i
->length
, i
->title
);
64 table
= astrodb_table_create(db
, i
->name
, ADB_MEM
| ADB_FILE
);
66 printf("failed to create table\n");
70 astrodb_table_add_custom_field(table
, "*");
71 if (astrodb_table_open(table
, 0, 0, 0) < 0) {
72 printf("failed to open table\n");
76 table_size
= astrodb_table_get_size(table
);
77 object_size
= astrodb_table_get_row_size(table
);
79 astrodb_table_unclip(table
);
80 count
= astrodb_table_get_objects(table
, &res
, ADB_SMEM
);
81 printf("Got %d objects\n", count
);
82 astrodb_table_put_objects(res
);
85 astrodb_table_close(table
);
88 int main(int argc
, char *argv
[])
90 struct astrodb_db
*db
= NULL
;
91 struct astrodb_library
*lib
= NULL
;
92 struct astrodb_dlist
*tables
;
94 printf("%s using libastrodb %s\n", argv
[0], astrodb_get_version());
96 /* set the remote db and initialise local repository/cache */
97 lib
= astrodb_open_library("ftp://cdsarc.u-strasbg.fr/pub/cats", "lnc-test");
99 printf("failed to open library\n");
103 /* create a catalog, using class V and catalog 86 */
104 /* ra,dec,mag bounds are set here along with the 3d tile array size */
105 db
= astrodb_create_db(lib
, "V", "86", 0.0, 360.0, -90.0, 90.0,
108 printf("failed to create db\n");
112 tables
= astrodb_db_get_tables(db
);
113 astrodb_dlist_foreach(tables
, init_table
, db
);
115 /* were now done with catalog */
117 astrodb_close_library(lib
);