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) 2005 Liam Girdwood
23 #include <libastrodb/astrodb.h>
25 static struct timeval start
, end
;
27 inline static void start_timer(void)
29 gettimeofday(&start
, NULL
);
32 static void end_timer(int objects
, int bytes
)
35 gettimeofday(&end
, NULL
);
36 usecs
= (end
.tv_sec
* 1000000 + end
.tv_usec
) - (start
.tv_sec
* 1000000 + start
.tv_usec
);
40 ("Time(secs) %f : %9.0f objects per sec %9.0f bytes per secs\n",
41 usecs
/ 1000000.0, (1000000.0 / usecs
) * objects
,
42 (1000000.0 / usecs
) * bytes
);
44 printf("Time(secs) %f : %9.0f objects per sec\n",
45 usecs
/ 1000000.0, (1000000.0 / usecs
) * objects
);
48 static void print_progress(float percent
, char *msg
, void *data
)
50 printf("Progess %f %s\n", percent
, msg
);
54 * Search for red shift > 0
56 static int search(struct astrodb_table
* table
)
58 struct astrodb_slist
*res
= NULL
;
59 struct astrodb_search
*srch
;
62 srch
= astrodb_search_create(table
);
63 astrodb_search_add_comparator(srch
, "z", ADB_COMP_GT
, "0");
64 astrodb_search_add_operator(srch
, ADB_OP_OR
);
67 if ((err
= astrodb_search_get_results(srch
, &res
, ADB_SMEM
)) < 0)
68 printf("Search init failed %d\n", err
);
69 end_timer(astrodb_search_get_tests(srch
), 0);
70 printf(" Search got %d objects out of %d tests\n", astrodb_search_get_hits(srch
), astrodb_search_get_tests(srch
));
71 astrodb_search_put_results(res
);
72 astrodb_search_free(srch
);
76 void init_table(void *data
, void *user
)
78 struct astrodb_table_info
*i
= (struct astrodb_table_info
*) data
;
79 struct astrodb_db
*db
= (struct astrodb_db
*) user
;
80 struct astrodb_table
*table
;
82 struct astrodb_slist
*res
= NULL
;
83 int table_size
, object_size
;
85 printf("\nDset: \t%s\nrecords:\t%d\nrec len: \t%d\ntitle: \t%s\n",
86 i
->name
, i
->records
, i
->length
, i
->title
);
88 if ((table
= astrodb_table_create(db
, i
->name
, ADB_MEM
| ADB_FILE
))) {
90 // astrodb_table_add_custom_field(table, "*");
91 if (astrodb_table_open(table
, 0, 0, 0) < 0) {
94 table_size
= astrodb_table_get_size(table
);
95 object_size
= astrodb_table_get_row_size(table
);
96 end_timer(table_size
, table_size
* object_size
);
98 astrodb_table_unclip(table
);
99 count
= astrodb_table_get_objects(table
, &res
, ADB_SMEM
);
100 printf("Got %d objects\n", count
);
101 astrodb_table_put_objects(res
);
104 astrodb_table_close(table
);
108 int main(int argc
, char *argv
[])
110 struct astrodb_db
*db
= NULL
;
111 // astrodb_progress progress = print_progress;
112 struct astrodb_library
*lib
= NULL
;
113 struct astrodb_dlist
*datasets
;
115 printf("%s using libastrodb %s\n", argv
[0], astrodb_get_version());
117 /* set the remote db and initialise local repository/cache */
118 if ((lib
= astrodb_open_library("ftp://cdsarc.u-strasbg.fr/pub/cats", "lnc-test")) == NULL
) {
122 /* create a dbalog, using class V and dbalog 86 */
123 /* ra,dec,mag bounds are set here along with the 3d tile array size */
124 if ((db
= astrodb_create_db(lib
, "VII", "110A", 0.0, 360.0, -90.0, 90.0, 15.0, -2.0, 0)) == NULL
) {
128 datasets
= astrodb_db_get_tables(db
);
129 astrodb_dlist_foreach(datasets
, init_table
, db
);
131 /* were now done with dbalog */
133 astrodb_close_library(lib
);