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
25 #include <libastrodb/astrodb.h>
27 static struct timeval start
, end
;
29 inline static void start_timer(void)
31 gettimeofday(&start
, NULL
);
34 static void end_timer(int objects
, int bytes
)
38 gettimeofday(&end
, NULL
);
39 usecs
= (end
.tv_sec
* 1000000 + end
.tv_usec
) -
40 (start
.tv_sec
* 1000000 + start
.tv_usec
);
43 printf ("Time(secs) %f : %9.0f objects per sec %9.0f bytes per"
44 " secs\n", usecs
/ 1000000.0,
45 (1000000.0 / usecs
) * objects
,
46 (1000000.0 / usecs
) * bytes
);
48 printf("Time(secs) %f : %9.0f objects per sec\n",
49 usecs
/ 1000000.0, (1000000.0 / usecs
) * objects
);
53 * Get all the objects in the dataset.
55 static int get_all(struct astrodb_table
* table
)
58 struct astrodb_slist
*res
= NULL
;
60 printf("Get all dataset objects\n");
61 astrodb_table_unclip(table
);
62 count
= astrodb_table_get_objects(table
, &res
, ADB_SMEM
);
63 printf(" Got %d objects\n", count
);
64 astrodb_table_put_objects(res
);
68 int main(int argc
, char *argv
[])
70 struct astrodb_db
*db
= NULL
;
71 struct astrodb_library
*lib
= NULL
;
72 struct astrodb_table
*table
= NULL
;
73 int table_size
, object_size
;
75 printf("%s using libastrodb %s\n", argv
[0], astrodb_get_version());
77 /* set the remote db and initialise local repository/cache */
78 lib
= astrodb_open_library("ftp://cdsarc.u-strasbg.fr/pub/cats", "lnc-test");
80 printf("failed to open library\n");
84 /* create a dbalog, using class VII and dbalog 118 (NGC2000) */
85 /* ra,dec,mag bounds are set here along with the 3d tile array size */
86 db
= astrodb_create_db(lib
, "VII", "118", 0.0, 360.0, -90.0, 90.0,
89 printf("failed to create db\n");
93 /* use the first dataset in this example */
94 table
= astrodb_table_create(db
, "ngc2000.dat", ADB_MEM
| ADB_FILE
);
96 printf("failed to create table\n");
100 /* Import every field in the dataset. */
101 // if (astrodb_table_add_custom_field(table, "*"))
102 printf("failed to add *\n");
104 /* Import the dataset from remote/local repo into memory/disk cache */
107 if (astrodb_table_open(table
, 0, 0, 0) < 0) {
108 printf("failed to open table\n");
112 table_size
= astrodb_table_get_size(table
);
113 object_size
= astrodb_table_get_row_size(table
);
114 end_timer(table_size
, table_size
* object_size
);
116 /* we can now perform operations on the dbalog data !!! */
119 /* were done with the table */
120 astrodb_table_close(table
);
122 /* were now done with db */
124 astrodb_close_library(lib
);