/* * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * * Copyright (C) 2005 Liam Girdwood, Radu Corlan */ #include <stdlib.h> #include <errno.h> #include <sys/time.h> #include <stdio.h> #include <libncat/libncat.h> static struct timeval start, end; inline static void start_timer(void) { gettimeofday(&start, NULL); } static void end_timer(int objects, int bytes) { double usecs; gettimeofday(&end, NULL); usecs = (end.tv_sec * 1000000 + end.tv_usec) - (start.tv_sec * 1000000 + start.tv_usec); if (bytes) printf ("Time(secs) %f : %9.0f objects per sec %9.0f bytes per secs\n", usecs / 1000000.0, (1000000.0 / usecs) * objects, (1000000.0 / usecs) * bytes); else printf("Time(secs) %f : %9.0f objects per sec\n", usecs / 1000000.0, (1000000.0 / usecs) * objects); } static void print_progress(lnc_catalog * cat, float percent, char *msg, void *data) { printf("Progess %f %s\n", percent, msg); } /* * Search for all G type stars * Uses Wildcard "G*" to match with Sp */ static int search(lnc_dataset * dset) { lnc_slist *res = NULL; lnc_search *srch; int err; srch = lnc_search_create(dset); lnc_search_add_comparator(srch, "MK", LNC_COMP_LT, "G*"); lnc_search_add_operator(srch, LNC_OP_OR); start_timer(); if ((err = lnc_search_get_results(srch, NULL, &res, 0)) < 0) printf("Search init failed %d\n", err); end_timer(lnc_search_get_tests(srch), 0); printf(" Search got %d objects out of %d tests\n", lnc_search_get_hits(srch), lnc_search_get_tests(srch)); lnc_search_put_results(res); lnc_search_free(srch); return 0; } void init_dset(void *data, void *user) { lnc_dset_info *i = (lnc_dset_info *) data; lnc_catalog *cat = (lnc_catalog *) user; lnc_dataset *dset; int count; lnc_slist *res = NULL; int dset_size, object_size; printf("\nDset: \t%s\nrecords:\t%d\nrec len: \t%d\ntitle: \t%s\n", i->name, i->records, i->length, i->title); if ((dset = lnc_dset_create(cat, i->name))) { start_timer(); lnc_dset_add_custom_field(dset, "*"); if (lnc_dset_init(dset, NULL, 0, 0, 0, LNC_PRECACHE | LNC_PRELOAD) < 0) { printf("%s\n", lnc_get_last_err_msg()); exit(-lnc_get_last_err()); } dset_size = lnc_dset_get_size(dset); object_size = lnc_dset_get_object_size(dset); end_timer(dset_size, dset_size * object_size); lnc_dset_unclip(dset); count = lnc_dset_get_objects(dset, NULL, &res, 0); printf("Got %d objects\n", count); lnc_dset_put_objects(res); search(dset); lnc_dset_free(dset); } } int main(int argc, char *argv[]) { lnc_catalog *cat = NULL; // lnc_progress progress = print_progress; lnc_library *lib = NULL; lnc_dlist *datasets; printf("%s using libncat %s\n", argv[0], lnc_get_version()); /* set the remote db and initialise local repository/cache */ if ((lib = lnc_lib_init("ftp://cdsarc.u-strasbg.fr/pub/cats", "lnc-test")) == NULL) { printf("%s\n", lnc_get_last_err_msg()); exit(-lnc_get_last_err()); } /* create a catalog, using class V and catalog 86 */ /* ra,dec,mag bounds are set here along with the 3d tile array size */ if ((cat = lnc_cat_create(lib, "V", "86", 0.0, 360.0, -90.0, 90.0, 15.0, -2.0, LNC_PRELOAD)) == NULL) { printf("%s\n", lnc_get_last_err_msg()); exit(-lnc_get_last_err()); } datasets = lnc_cat_query(cat); lnc_dlist_foreach(datasets, init_dset, cat); /* were now done with catalog */ lnc_cat_free(cat); lnc_lib_free(lib); return 0; }