From 176fffd9f85d67b1c7859c9cf60e636bf4ab7807 Mon Sep 17 00:00:00 2001 From: Liam Girdwood Date: Wed, 30 Jul 2008 20:54:15 +0100 Subject: [PATCH] core: table API rework Phase II. --- examples/Makefile.am | 14 ---- examples/client.c | 119 ------------------------------ examples/custom.c | 174 -------------------------------------------- examples/ngc.c | 2 +- examples/sky2k.c | 4 +- examples/vii110a.c | 2 +- examples/vii237.c | 4 +- src/libastrodb/table.h | 44 ++++++----- src/readme.c | 11 +-- src/search.c | 3 +- src/table.c | 194 ++++++++++++++----------------------------------- src/table_get.c | 55 ++++++-------- src/table_insert.c | 99 +++++++++---------------- 13 files changed, 146 insertions(+), 579 deletions(-) delete mode 100644 examples/client.c delete mode 100644 examples/custom.c diff --git a/examples/Makefile.am b/examples/Makefile.am index c17e5c9..0e41613 100644 --- a/examples/Makefile.am +++ b/examples/Makefile.am @@ -1,13 +1,8 @@ noinst_PROGRAMS = \ - client \ sky2k \ vii110a \ - custom \ ngc \ vii237 - -client_SOURCES = \ - client.c sky2k_SOURCES = \ sky2k.c @@ -15,9 +10,6 @@ sky2k_SOURCES = \ vii110a_SOURCES = \ vii110a.c -custom_SOURCES = \ - custom.c - ngc_SOURCES = \ ngc.c @@ -27,18 +19,12 @@ vii237_SOURCES = \ INCLUDES = \ -Wall -I../src -client_LDADD = \ - ../src/libastrodb.la - sky2k_LDADD = \ ../src/libastrodb.la vii110a_LDADD = \ ../src/libastrodb.la -custom_LDADD = \ - ../src/libastrodb.la - ngc_LDADD = \ ../src/libastrodb.la diff --git a/examples/client.c b/examples/client.c deleted file mode 100644 index 85b4334..0000000 --- a/examples/client.c +++ /dev/null @@ -1,119 +0,0 @@ -/* - * 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) 2008 Liam Girdwood - */ - -#include -#include -#include -#include -#include - - -/* - * Search for all G type stars - * Uses Wildcard "G*" to match with Sp - */ -static int search(struct astrodb_table * table) -{ - struct astrodb_slist *res = NULL; - struct astrodb_search *srch; - int err; - - srch = astrodb_search_create(table); - astrodb_search_add_comparator(srch, "MK", ADB_COMP_LT, "G*"); - astrodb_search_add_operator(srch, ADB_OP_OR); - - err = astrodb_search_get_results(srch, &res, ADB_SMEM); - if (err < 0) - printf("Search init failed %d\n", err); - - printf(" Search got %d objects out of %d tests\n", - astrodb_search_get_hits(srch), - astrodb_search_get_tests(srch)); - astrodb_search_put_results(res); - astrodb_search_free(srch); - return 0; -} - -void init_table(void *data, void *user) -{ - struct astrodb_table_info *i = (struct astrodb_table_info *) data; - struct astrodb_db *db = (struct astrodb_db *) user; - struct astrodb_table *table; - int count; - struct astrodb_slist *res = NULL; - int table_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); - - table = astrodb_table_create(db, i->name, ADB_MEM | ADB_FILE); - if (table == NULL) { - printf("failed to create table\n"); - return; - } - - astrodb_table_add_custom_field(table, "*"); - if (astrodb_table_open(table, 0, 0, 0) < 0) { - printf("failed to open table\n"); - return; - } - - table_size = astrodb_table_get_size(table); - object_size = astrodb_table_get_row_size(table); - - astrodb_table_unclip(table); - count = astrodb_table_get_objects(table, &res, ADB_SMEM); - printf("Got %d objects\n", count); - astrodb_table_put_objects(res); - - search(table); - astrodb_table_close(table); -} - -int main(int argc, char *argv[]) -{ - struct astrodb_db *db = NULL; - struct astrodb_library *lib = NULL; - struct astrodb_dlist *tables; - - printf("%s using libastrodb %s\n", argv[0], astrodb_get_version()); - - /* set the remote db and initialise local repository/cache */ - lib = astrodb_open_library("ftp://cdsarc.u-strasbg.fr/pub/cats", "lnc-test"); - if (lib == NULL) { - printf("failed to open library\n"); - return -1; - } - - /* create a catalog, using class V and catalog 86 */ - /* ra,dec,mag bounds are set here along with the 3d tile array size */ - db = astrodb_create_db(lib, "V", "86", 0.0, 360.0, -90.0, 90.0, - 15.0, -2.0, 0); - if (db == NULL) { - printf("failed to create db\n"); - return -1; - } - - tables = astrodb_db_get_tables(db); - astrodb_dlist_foreach(tables, init_table, db); - - /* were now done with catalog */ - astrodb_db_free(db); - astrodb_close_library(lib); - return 0; -} diff --git a/examples/custom.c b/examples/custom.c deleted file mode 100644 index 3246349..0000000 --- a/examples/custom.c +++ /dev/null @@ -1,174 +0,0 @@ -/* - * 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 - */ - -#include -#include -#include -#include -#include -#include - -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(float percent, char* msg, void* data) -{ - printf("Progress %2.2f %s\n", percent, msg); -} - -struct sky2k { - struct astrodb_object d; - float RV; - char HD[6]; - char sp[3]; -}; - -static struct astrodb_schema_object sky2k_fields[] = { - astrodb_member("RA", "RA", struct sky2k, d.posn_mag.ra, CT_DOUBLE, "degrees", 0, NULL), - astrodb_member("DEC", "DEC", struct sky2k, d.posn_mag.dec, CT_DOUBLE, "degrees", 0, NULL), - astrodb_gmember("RA Hours", "RAh", struct sky2k, d.posn_mag.ra, CT_DOUBLE_HMS_HRS, "hours", 2, NULL), - astrodb_gmember("RA Minutes", "RAm", struct sky2k, d.posn_mag.ra, CT_DOUBLE_HMS_MINS, "minutes", 1, NULL), - astrodb_gmember("RA Seconds", "RAs", struct sky2k, d.posn_mag.ra, CT_DOUBLE_HMS_SECS, "seconds", 0, NULL), - astrodb_gmember("DEC Degrees", "DEd", struct sky2k, d.posn_mag.dec, CT_DOUBLE_DMS_DEGS, "degrees", 3, NULL), - astrodb_gmember("DEC Minutes", "DEm", struct sky2k, d.posn_mag.dec, CT_DOUBLE_DMS_MINS, "minutes", 2, NULL), - astrodb_gmember("DEC Seconds", "DEs", struct sky2k, d.posn_mag.dec, CT_DOUBLE_DMS_SECS, "seconds", 1, NULL), - astrodb_gmember("DEC sign", "DE-", struct sky2k, d.posn_mag.dec, CT_SIGN, "", 0, NULL), - astrodb_member("Visual Mag", "Vmag", struct sky2k, d.posn_mag.Vmag, CT_FLOAT, "", 0, NULL), - astrodb_member("RV", "RV", struct sky2k, RV, CT_FLOAT, "", 0, NULL), - astrodb_member("Sp", "Sp", struct sky2k, sp, CT_STRING, "", 0, NULL), - astrodb_member("HD", "HD", struct sky2k, HD, CT_STRING, "", 0, NULL), -}; - - -/* - * Get all the objects in the table. - */ -static int get1(struct astrodb_table * table) -{ - int count = 0; - struct astrodb_slist *res = NULL; - - printf("Get all table objects\n"); - astrodb_table_unclip(table); - count = astrodb_table_get_objects(table, &res, ADB_SMEM); - printf(" Got %d objects\n", count); - astrodb_table_put_objects(res); - return 0; -} - -int main (int argc, char *argv[]) -{ - struct astrodb_db *db = NULL; - struct astrodb_library *lib = NULL; - struct astrodb_table *table = NULL; - int table_size, object_size, err; - - printf("%s using libastro %s\n", argv[0], astrodb_get_version()); - - /* set the remote db and initialise local repository/cache */ - lib = astrodb_open_library("ftp://cdsarc.u-strasbg.fr/pub/cats", - "lnc-test"); - if (lib == NULL) { - printf("failed to open library\n"); - return -1; - } - - /* create a dbalog, using class V and dbalog 109 (Skymap2000) */ - /* ra,dec,mag bounds are set here along with the 3d tile array size */ - db = astrodb_create_db(lib, "V", "109", - 0.0, 360.0, -90.0, 90.0, 15.0, -2.0, 0); - if (db == NULL) { - printf("failed to open db\n"); - return -1; - } - - /* use the first table in this example */ - table = astrodb_table_create(db, "sky2kv4", ADB_MEM | ADB_FILE); - if (table == NULL) { - printf("failed to create table\n"); - return -1; - } - - err = astrodb_table_register_schema(table, sky2k_fields, - astrodb_size(sky2k_fields), - sizeof(struct sky2k)); - if (err < 0) { - printf("failed to register schema\n"); - return -1; - } - - /* Vmag is blank in some records in the table, so we use can Vder - * as an alternate field. - */ - if (astrodb_table_alt_column(table, "Vmag", "Vder", 0)) - printf("failed to add alt index\n"); - - /* We want to quickly search the table based on object ID and HD number */ - if (astrodb_table_hash_key(table, "ID")) - printf("failed to hash on ID\n"); - if (astrodb_table_hash_key(table, "HD")) - printf("failed to hash on HD\n"); - - /* Import the table from remote/local repo into memory/disk cache */ - start_timer(); - err = astrodb_table_open(table, 0, 0, 0); - if (err < 0) { - printf("failed to open table\n"); - return -1; - } - - table_size = astrodb_table_get_size(table); - object_size = astrodb_table_get_row_size(table); - end_timer(table_size, table_size * object_size); - - /* we can now perform operations on the dbalog data !!! */ - get1(table); - - /* get some hashed id's */ - printf("object %p\n", astrodb_table_get_object(table, " 7000303", "ID")); - printf("object %p\n", astrodb_table_get_object(table, "7000303", "ID")); - printf("object %p\n", astrodb_table_get_object(table, "73256", "HD")); - - /* were done with the table */ - astrodb_table_close(table); - - /* were now done with dbalog */ - astrodb_db_free(db); - astrodb_close_library(lib); - - return 0; -} diff --git a/examples/ngc.c b/examples/ngc.c index 5169e71..d583ade 100644 --- a/examples/ngc.c +++ b/examples/ngc.c @@ -98,7 +98,7 @@ int main(int argc, char *argv[]) } /* Import every field in the dataset. */ - if (astrodb_table_add_custom_field(table, "*")) +// if (astrodb_table_add_custom_field(table, "*")) printf("failed to add *\n"); /* Import the dataset from remote/local repo into memory/disk cache */ diff --git a/examples/sky2k.c b/examples/sky2k.c index 67f0fd3..3505b20 100644 --- a/examples/sky2k.c +++ b/examples/sky2k.c @@ -300,7 +300,7 @@ int main(int argc, char *argv[]) printf("failed to create table\n"); return -1; } -#if 1 +#if 0 /* RA, DEC, Vmag and ID/Name are imported by default * Add a couple of custom fields that we are interested in */ @@ -320,7 +320,7 @@ int main(int argc, char *argv[]) */ if (astrodb_table_alt_column(table, "Vmag", "Vder", 0)) printf("failed to add alt index\n"); -#else + /* Import every field in the dataset. */ if (astrodb_table_add_custom_field(table, "*")) printf("failed to add *\n"); diff --git a/examples/vii110a.c b/examples/vii110a.c index f0829ae..126de92 100644 --- a/examples/vii110a.c +++ b/examples/vii110a.c @@ -87,7 +87,7 @@ void init_table(void *data, void *user) if ((table = astrodb_table_create(db, i->name, ADB_MEM | ADB_FILE))) { start_timer(); - astrodb_table_add_custom_field(table, "*"); + // astrodb_table_add_custom_field(table, "*"); if (astrodb_table_open(table, 0, 0, 0) < 0) { exit(-1); } diff --git a/examples/vii237.c b/examples/vii237.c index 5c9cf0b..92398bb 100644 --- a/examples/vii237.c +++ b/examples/vii237.c @@ -81,8 +81,6 @@ static int otype_insert(void *dest, void *src) return 0; } - - static struct astrodb_schema_object hyperleda_fields[] = { astrodb_member("Name", "ANames", struct hyperleda_object, other_name, CT_STRING, "", 0, NULL), @@ -150,7 +148,7 @@ int main (int argc, char* argv[]) printf("%s: failed to hash on ID\n", __func__); /* Import the dataset from remote/local repo into memory/disk cache */ - if (astrodb_table_open(table, 0, 0, 0) < 0) { + if (astrodb_table_open(table, 20, 10, 1) < 0) { printf("failed to open table\n"); return -1; } diff --git a/src/libastrodb/table.h b/src/libastrodb/table.h index fa7ae87..a686773 100644 --- a/src/libastrodb/table.h +++ b/src/libastrodb/table.h @@ -68,11 +68,10 @@ struct hash_map { }; struct dimension { - int stride; - double stride_size; /* in degrees */ + int stride; /*!< number of strides */ + double stride_size; /*!< stride size in degrees */ int clip_min; int clip_max; - int offset; }; /*! \typedef struct struct astrodb_table @@ -87,21 +86,10 @@ struct astrodb_table { struct astrodb_db *db; /*!< catalog we belong to */ int init_flags; /*!< initialisation flags */ - /* tile array dimensions */ - int ra_stride; /*!< number of ra strides, covers 360 deg*/ - int dec_stride; /*!< number of dec strides, covers 180 deg */ - int mag_stride; /*!< number of mag strides */ - double ra_stride_size; /*!< size of each ra stride in degrees */ - double dec_stride_size; /*!< size of each dec stride in degrees */ - double mag_stride_size; /*!< size of each mag stride */ - - /* clipping bounds */ - int clip_min_ra; /*!< Clipping Min RA stride */ - int clip_min_dec; /*!< Clipping Min DEC stride */ - int clip_max_ra; /*!< Clipping Max RA stride */ - int clip_max_dec; /*!< Clipping Max DEC stride */ - int clip_faint_mag; /*!< Clipping Max Mag stride */ - int clip_bright_mag; /*!< Clipping Min Mag stride */ + struct dimension ra; + struct dimension dec; + struct dimension mag; + double fov; /*!< Clipping radius in degrees */ double clip_centre_ra; /*!< Clipping centre RA (circular) */ double clip_centre_dec; /*!< Clipping centre DEC (circular) */ @@ -153,14 +141,14 @@ struct astrodb_table_index { int insert_id; /*!< object importer func */ }; -/*! \fn static inline int calc_deep_offset(struct astrodb_table* data, int ra, int dec, int mag) +/*! \fn static inline int calc_offset(struct astrodb_table* data, int ra, int dec, int mag) * \brief Calculate offset into 3d tile array */ -static inline int table_calc_deep_offset(struct astrodb_table *data, +static inline int table_calc_offset(struct astrodb_table *table, int ra, int dec, int mag) { - return ra + (dec * data->ra_stride) + - (mag * data->ra_stride * data->dec_stride); + return ra + (dec * table->ra.stride) + + (mag * table->ra.stride * table->dec.stride); } /*! \fn static inline int calc_hash(char* data, int len, int mod) @@ -168,7 +156,7 @@ static inline int table_calc_deep_offset(struct astrodb_table *data, * * We dont hash ' ' or '-'. */ -static inline int table_calc_hash(char *data, int len, int mod) +static inline int table_calc_hash_str(char *data, int len, int mod) { int val = 0; @@ -182,6 +170,15 @@ static inline int table_calc_hash(char *data, int len, int mod) return val; } +/*! \fn static inline int calc_hash(char* data, int len, int mod) +* \brief Calculate hash based on string and in range +* +*/ +static inline int table_calc_hash(int val, int mod) +{ + return abs(val % mod); +} + int table_is_field(struct astrodb_table *table, char *field); int table_find_field(struct astrodb_table *table, char *field); int table_add_alt_field(struct astrodb_table *table, char *field, int pri_idx); @@ -200,6 +197,7 @@ int table_uncache_tiles(struct astrodb_table *table); int table_save_hdr(struct astrodb_table *table); int table_load_hdr(struct astrodb_table *table); int table_get_remote_dataset(struct astrodb_table *table); + int table_get_objects_mem(struct astrodb_table *table, struct astrodb_slist ** result); int table_get_objects_cache(struct astrodb_table *table, struct astrodb_slist ** result); int table_get_objects_raw(struct astrodb_table *table, struct astrodb_slist ** result); diff --git a/src/readme.c b/src/readme.c index be5a99b..b12e156 100644 --- a/src/readme.c +++ b/src/readme.c @@ -370,22 +370,23 @@ static void free_byte_descs(struct astrodb_dlist *list) } } -static void free_file(void *data, void *user) +static int free_file(void *data, void *user) { struct astrodb_table_info *file = (struct astrodb_table_info *)data; free(file->name); free(file->title); + return 0; } -static void free_note(void *data, void *user) +static int free_note(void *data, void *user) { - + return 0; } -static void free_keyword(void *data, void *user) +static int free_keyword(void *data, void *user) { - + return 0; } void free_readme(struct astrodb_readme_info *info) diff --git a/src/search.c b/src/search.c index 2a04a99..18417b7 100644 --- a/src/search.c +++ b/src/search.c @@ -259,7 +259,7 @@ struct astrodb_search *astrodb_search_create(struct astrodb_table *table) return srch; } -static void free_orphans(void *data, void *user) +static int free_orphans(void *data, void *user) { struct astrodb_slist *slist = data; @@ -268,6 +268,7 @@ static void free_orphans(void *data, void *user) slist = slist->tail; free(tmp); } + return 0; } /*! \fn void astrodb_search_free(astrodb_search* search); diff --git a/src/table.c b/src/table.c index 198002b..27baeff 100644 --- a/src/table.c +++ b/src/table.c @@ -40,22 +40,6 @@ #define FLOAT_SIZE '6' /* CDS F string size and below for float else double */ #define FILE_LEN 1024 -struct _tile_dim { - int records; /*!< Number of records in dataset */ - int ra, dec, mag; /*!< Stride size */ -}; - -/* - * Table containing default dataset 3d tile dimensions - */ -static struct _tile_dim tile_dim[] = { - {10000, 6, 3, 20}, - {100000, 45, 20, 20}, - {500000, 90, 45, 20}, - {1000000, 180, 90, 20}, - {10000000, 360, 180, 20}, -}; - /*! \fn static int init_table(astrodb_table * table, int ra_stride, int dec_stride, int mag_stride) * \brief Initialise a dataset */ @@ -66,34 +50,23 @@ static int init_table(struct astrodb_table *table, struct astrodb_tile_status *status; int i = 0; - /* do we use the default tile dimensions */ - if (ra_stride == 0) { - for (; i < astrodb_size(tile_dim); i++) { - if (table->table_size <= tile_dim[i].records) - break; - } - table->ra_stride = tile_dim[i].ra; - table->dec_stride = tile_dim[i].dec; - table->mag_stride = tile_dim[i].mag; - } else { - table->ra_stride = ra_stride; - table->dec_stride = dec_stride; - table->mag_stride = mag_stride; - } + table->ra.stride = ra_stride; + table->dec.stride = dec_stride; + table->mag.stride = mag_stride; - table->array_size = table->ra_stride * table->dec_stride * - table->mag_stride * sizeof(struct astrodb_slist *); - table->status_size = table->ra_stride * table->dec_stride * - table->mag_stride * sizeof(struct astrodb_tile_status); - table->no_tiles = table->ra_stride * table->dec_stride * - table->mag_stride; + table->array_size = table->ra.stride * table->dec.stride * + table->mag.stride * sizeof(struct astrodb_slist *); + table->status_size = table->ra.stride * table->dec.stride * + table->mag.stride * sizeof(struct astrodb_tile_status); + table->no_tiles = table->ra.stride * table->dec.stride * + table->mag.stride; - table->ra_stride_size = - fabs((table->db->ra_max - table->db->ra_min) / table->ra_stride); - table->dec_stride_size = - fabs((table->db->dec_max - table->db->dec_min) / table->dec_stride); - table->mag_stride_size = - fabs((table->db->mag_bright - table->db->mag_faint) / table->mag_stride); + table->ra.stride_size = + fabs((table->db->ra_max - table->db->ra_min) / table->ra.stride); + table->dec.stride_size = + fabs((table->db->dec_max - table->db->dec_min) / table->dec.stride); + table->mag.stride_size = + fabs((table->db->mag_bright - table->db->mag_faint) / table->mag.stride); slist = (struct astrodb_slist **) calloc(1, table->array_size); if (slist == 0) { @@ -199,8 +172,6 @@ struct astrodb_table *astrodb_table_create(struct astrodb_db *db, * * Initialise a dataset. This will download and import the raw data if necessary. */ -int insert_posn_mag(void *d, void *object); - int astrodb_table_open(struct astrodb_table *table, int ra, int dec, int mag) { struct stat stat_info; @@ -214,8 +185,8 @@ int astrodb_table_open(struct astrodb_table *table, int ra, int dec, int mag) //if (flags & ADB_REFRESH) // delete_table(astrodb_table* table); - //table_get_object_insert(table); - table->object_insert = &insert_posn_mag; + table_get_object_insert(table); + ret = init_table(table, ra, dec, mag); if (ret < 0) { astrodb_error("failed to initialise table %d\n", ret); @@ -317,61 +288,6 @@ void astrodb_table_close(struct astrodb_table *table) db->tables = astrodb_dlist_free_object(db->tables, table); } -/*! \fn int astrodb_table_add_custom_field(astrodb_table* table, char* field) - * \param table dataset - * \param field Field name to add - * \return 0 on success - * - * Add a custom field to a dataset for import. - */ -int astrodb_table_add_custom_field(struct astrodb_table *table, char *field) -{ - struct astrodb_table_column_info *byte = NULL; - struct astrodb_schema_object *idx = NULL; - struct astrodb_dlist *desc = table->byte_description; - int full = 0; - - /* do we add all the fields */ - if (!strncmp(field, "*", 1)) - full = 1; - - while (desc != NULL) { - - byte = (struct astrodb_table_column_info *) desc->data; - idx = &table->idx[table->object_fields]; - - if ((!strncmp(field, byte->label, strlen(byte->label)) || full) && - !table_is_field(table, byte->label)) { - - idx->s_offset = table->object_size; - idx->l_offset = byte->start; - idx->l_size = byte->end - byte->start + 1; - strncpy(idx->name, byte->explanation, 32); - strncpy(idx->units, byte->units, 16); - strncpy(idx->symbol, byte->label, 8); - idx->type = table_get_ctype(byte->type); - idx->s_size = table_get_csize(byte->type); -#if 0 - if (table->idx[table->object_fields].insert == NULL) - table->idx[table->object_fields].insert = - table_get_custom_insert(byte->type); -#endif - table->object_fields++; - table->object_size += idx->s_size; - - if (!full) - return 0; - } - desc = desc->tail; - } - if (full) - return 0; - - astrodb_error("failed to add custom field %s\n", field); - return -EINVAL; -} - - /*! \fn void astrodb_table_put_objects(astrodb_slist *results) * \param results Results from astrodb_table_get_objects() * @@ -464,13 +380,13 @@ void astrodb_table_clip_on_position(struct astrodb_table *table, table->fov = 0; /* convert to stride boundaries */ - table->clip_min_ra = floor(min_ra / table->ra_stride_size); - table->clip_max_ra = floor(max_ra / table->ra_stride_size); - table->clip_min_dec = floor(min_dec / table->dec_stride_size); - table->clip_max_dec = floor(max_dec / table->dec_stride_size); + table->ra.clip_min = floor(min_ra / table->ra.stride_size); + table->ra.clip_max = floor(max_ra / table->ra.stride_size); + table->dec.clip_min = floor(min_dec / table->dec.stride_size); + table->dec.clip_max = floor(max_dec / table->dec.stride_size); - table->clip_bright_mag = floor(bright_mag / table->mag_stride_size); - table->clip_faint_mag = floor(faint_mag / table->mag_stride_size); + table->mag.clip_max = floor(bright_mag / table->mag.stride_size); + table->mag.clip_min = floor(faint_mag / table->mag.stride_size); } /*! \fn void astrodb_table_clip_on_distance (astrodb_table* table, double min_AU, double max_AU) @@ -498,8 +414,8 @@ void astrodb_table_clip_on_distance(struct astrodb_table *table, table->fov = 0; /* convert to stride boundaries */ - table->clip_min_ra = (int) min_AU / table->ra_stride_size; - table->clip_max_ra = ((int) max_AU / table->ra_stride_size) + 1; + table->ra.clip_min = (int) min_AU / table->ra.stride_size; + table->ra.clip_max = ((int) max_AU / table->ra.stride_size) + 1; } /*! \fn void astrodb_table_clip_on_fov (astrodb_table* table, double ra, double dec, double radius, @@ -534,8 +450,8 @@ void astrodb_table_clip_on_fov (struct astrodb_table *table, bright_mag -= table->db->mag_bright; /* convert to stride boundaries */ - table->clip_bright_mag = (int) bright_mag / table->mag_stride_size; - table->clip_faint_mag = ((int) faint_mag / table->mag_stride_size) + 1; + table->mag.clip_max = (int) bright_mag / table->mag.stride_size; + table->mag.clip_min = ((int) faint_mag / table->mag.stride_size) + 1; } /*! \fn void astrodb_table_unclip (astrodb_table* table) @@ -548,18 +464,18 @@ void astrodb_table_unclip(struct astrodb_table *table) int i,j,k, offset; /* in stride */ - table->clip_min_ra = 0; - table->clip_min_dec = 0; - table->clip_max_ra = table->ra_stride - 1; - table->clip_max_dec = table->dec_stride - 1; - table->clip_faint_mag = table->mag_stride - 1; - table->clip_bright_mag = 0; + table->ra.clip_min = 0; + table->dec.clip_min = 0; + table->ra.clip_max = table->ra.stride - 1; + table->dec.clip_max = table->dec.stride - 1; + table->mag.clip_min = table->mag.stride - 1; + table->mag.clip_max = 0; table->fov = 0; - for (i = 0; i <= table->clip_max_ra; i++) { - for (j = 0; j <= table->clip_max_dec; j++) { - for (k = 0; k <= table->clip_faint_mag; k++) { - offset = table_calc_deep_offset(table, i, j, k); + for (i = 0; i <= table->ra.clip_max; i++) { + for (j = 0; j <= table->dec.clip_max; j++) { + for (k = 0; k <= table->mag.clip_min; k++) { + offset = table_calc_offset(table, i, j, k); (table->status + offset)->flags &= ~ADB_SUSED; } } @@ -653,20 +569,20 @@ void astrodb_table_set_status_posn(struct astrodb_table *table, int clip_min_ra, clip_max_ra, clip_min_dec, clip_max_dec, clip_bright_mag, clip_faint_mag; - clip_min_ra = table->clip_min_ra; - clip_max_ra = table->clip_max_ra; - clip_min_dec = table->clip_min_dec; - clip_max_dec = table->clip_max_dec; - clip_bright_mag = table->clip_bright_mag; - clip_faint_mag = table->clip_faint_mag; + clip_min_ra = table->ra.clip_min; + clip_max_ra = table->ra.clip_max; + clip_min_dec = table->dec.clip_min; + clip_max_dec = table->dec.clip_max; + clip_bright_mag = table->mag.clip_max; + clip_faint_mag = table->mag.clip_min; astrodb_table_clip_on_position(table, min_ra, min_dec, max_ra, max_dec, bright_mag, faint_mag); - for (i = table->clip_min_ra; i < table->clip_max_ra; i++) { - for (j = table->clip_min_dec; j < table->clip_max_dec; j++) { - for (k = table->clip_bright_mag; - k < table->clip_faint_mag; k++) { + for (i = table->ra.clip_min; i < table->ra.clip_max; i++) { + for (j = table->dec.clip_min; j < table->dec.clip_max; j++) { + for (k = table->mag.clip_max; + k < table->mag.clip_min; k++) { } } @@ -685,8 +601,8 @@ void astrodb_table_set_status_dist(struct astrodb_table *table, double min_AU, double max_AU, unsigned int status) { - int min_offset = (min_AU - table->db->ra_min) / table->ra_stride_size; - int max_offset = (max_AU - table->db->ra_min) / table->ra_stride_size; + int min_offset = (min_AU - table->db->ra_min) / table->ra.stride_size; + int max_offset = (max_AU - table->db->ra_min) / table->ra.stride_size; for (; min_offset < max_offset; min_offset++) { ((struct astrodb_tile_status*) @@ -708,10 +624,10 @@ astrodb_table_get_status_posn(struct astrodb_table *table, { int x, y, z, offset; - x = floor((ra - table->db->ra_min) / table->ra_stride_size); - y = floor((dec - table->db->dec_min) / table->dec_stride_size); - z = floor((mag - table->db->mag_bright) / table->mag_stride_size); - offset = table_calc_deep_offset(table, x, y, z); + x = floor((ra - table->db->ra_min) / table->ra.stride_size); + y = floor((dec - table->db->dec_min) / table->dec.stride_size); + z = floor((mag - table->db->mag_bright) / table->mag.stride_size); + offset = table_calc_offset(table, x, y, z); return *(table->status + offset); } @@ -726,7 +642,7 @@ astrodb_table_get_status_posn(struct astrodb_table *table, struct astrodb_tile_status astrodb_table_get_status_dist(struct astrodb_table *table, double AU) { - int offset = floor((AU - table->db->ra_min) / table->ra_stride_size); + int offset = floor((AU - table->db->ra_min) / table->ra.stride_size); return *(table->status + offset); } @@ -833,7 +749,7 @@ void* astrodb_table_get_object (struct astrodb_table *table, char *id, return NULL; get_object: - offset = table_calc_hash(id, strlen(id), table->no_tiles); + offset = table_calc_hash_str(id, strlen(id), table->no_tiles); slist = *(table->hmaps[i].hobjects + offset); while (slist) { diff --git a/src/table_get.c b/src/table_get.c index 6a9033a..0fa4751 100644 --- a/src/table_get.c +++ b/src/table_get.c @@ -58,17 +58,6 @@ static void rotate_y(double *x, double *z, double a) *z = _z; } -static void rotate_z(double *x, double *y, double a) -{ - double _x, _y; - - _x = (*x * cos(a)) + (*y * -sin(a)); - _y = (*x * sin(a)) + (*y * cos(a)); - - *x = _x; - *y = _y; -} - /*! \fn int table_get_objects_mem(astrodb_table * table, astrodb_slist ** result) * \brief Get objects from memory based on posn */ @@ -78,15 +67,15 @@ int table_get_objects_mem(struct astrodb_table *table, int count = 0, ra, dec, mag, offset; *result = NULL; - for (ra = table->clip_min_ra; ra <= table->clip_max_ra; ra++) { + for (ra = table->ra.clip_min; ra <= table->ra.clip_max; ra++) { - for (dec = table->clip_min_dec; - dec <= table->clip_max_dec; dec++) { + for (dec = table->dec.clip_min; + dec <= table->dec.clip_max; dec++) { - for (mag = table->clip_bright_mag; - mag <= table->clip_faint_mag; mag++) { + for (mag = table->mag.clip_max; + mag <= table->mag.clip_min; mag++) { - offset = table_calc_deep_offset(table, ra, dec, mag); + offset = table_calc_offset(table, ra, dec, mag); if (*(table->objects + offset)) { *result = astrodb_slist_prepend(*result, @@ -133,8 +122,8 @@ static inline int is_tile_base_valid(struct astrodb_table *table, double ra, dec, x, y, z; /* bottom left */ - ra = tile_ra * table->ra_stride_size; - dec = (tile_dec * table->dec_stride_size) - 90.0; + ra = tile_ra * table->ra.stride_size; + dec = (tile_dec * table->dec.stride_size) - 90.0; unit_vector(ra, dec, &x, &y, &z); rotate_y(&x, &z, ra_angle); rotate_x(&y, &z, dec_angle); @@ -142,8 +131,8 @@ static inline int is_tile_base_valid(struct astrodb_table *table, return 1; /* bottom right */ - ra = (tile_ra + 1) * table->ra_stride_size; - dec = (tile_dec * table->dec_stride_size) - 90.0; + ra = (tile_ra + 1) * table->ra.stride_size; + dec = (tile_dec * table->dec.stride_size) - 90.0; unit_vector(ra, dec, &x, &y, &z); rotate_y(&x, &z, ra_angle); rotate_x(&y, &z, dec_angle); @@ -151,8 +140,8 @@ static inline int is_tile_base_valid(struct astrodb_table *table, return 1; /* top left */ - ra = tile_ra * table->ra_stride_size; - dec = ((tile_dec + 1) * table->dec_stride_size) - 90.0; + ra = tile_ra * table->ra.stride_size; + dec = ((tile_dec + 1) * table->dec.stride_size) - 90.0; unit_vector(ra, dec, &x, &y, &z); rotate_y(&x, &z, ra_angle); rotate_x(&y, &z, dec_angle); @@ -160,8 +149,8 @@ static inline int is_tile_base_valid(struct astrodb_table *table, return 1; /* top right */ - ra = (tile_ra + 1) * table->ra_stride_size; - dec = ((tile_dec + 1) * table->dec_stride_size) - 90.0; + ra = (tile_ra + 1) * table->ra.stride_size; + dec = ((tile_dec + 1) * table->dec.stride_size) - 90.0; unit_vector(ra, dec, &x, &y, &z); rotate_y(&x, &z, ra_angle); rotate_x(&y, &z, dec_angle); @@ -169,8 +158,8 @@ static inline int is_tile_base_valid(struct astrodb_table *table, return 1; /* tile centre */ - ra = (tile_ra + 0.5) * table->ra_stride_size; - dec = ((tile_dec + 0.5) * table->dec_stride_size) - 90.0; + ra = (tile_ra + 0.5) * table->ra.stride_size; + dec = ((tile_dec + 0.5) * table->dec.stride_size) - 90.0; unit_vector(ra, dec, &x, &y, &z); rotate_y(&x, &z, ra_angle); rotate_x(&y, &z, dec_angle); @@ -186,10 +175,10 @@ static int get_tile_base_objects(struct astrodb_table *table, { int mag, count = 0, offset; - for (mag = table->clip_bright_mag; - mag <= table->clip_faint_mag; mag++) { + for (mag = table->mag.clip_max; + mag <= table->mag.clip_min; mag++) { - offset = table_calc_deep_offset(table, ra, dec, mag); + offset = table_calc_offset(table, ra, dec, mag); if (*(table->objects + offset)) { *result = astrodb_slist_prepend(*result, @@ -216,8 +205,8 @@ int table_get_objects_memc(struct astrodb_table *table, ra_angle = (360.0 - table->clip_centre_ra) * D2R; dec_angle = table->clip_centre_dec * D2R; - for (ra = 0; ra < table->ra_stride; ra++) { - for (dec = 0; dec < table->dec_stride; dec++) { + for (ra = 0; ra < table->ra.stride; ra++) { + for (dec = 0; dec < table->dec.stride; dec++) { valid = is_tile_base_valid(table, ra, dec, ra_angle, dec_angle); if (valid) @@ -266,7 +255,7 @@ int table_get_objects_cache_near(struct astrodb_table *table, int count = 0, ra; *result = NULL; - for (ra = table->clip_min_ra; ra <= table->clip_max_ra; ra++) { + for (ra = table->ra.clip_min; ra <= table->ra.clip_max; ra++) { if (*(table->objects + ra)) { *result = astrodb_slist_prepend(*result, diff --git a/src/table_insert.c b/src/table_insert.c index 388f509..30e7e37 100644 --- a/src/table_insert.c +++ b/src/table_insert.c @@ -42,10 +42,10 @@ /*! \fn static int insert_posn_mag (void* d, void* object) * \brief Insert object into dataset based upon position and mag */ -int insert_posn_mag(void *d, void *object) +int insert_posn_mag(void *table_, void *object) { int ra, dec, mag, offset; - struct astrodb_table *table = (struct astrodb_table *) d; + struct astrodb_table *table = (struct astrodb_table *) table_; struct astrodb_object *dobject = object; if (dobject->posn_mag.ra < table->db->ra_min || @@ -59,13 +59,13 @@ int insert_posn_mag(void *d, void *object) return 0; ra = floor((dobject->posn_mag.ra - table->db->ra_min) / - table->ra_stride_size); + table->ra.stride_size); dec = floor((dobject->posn_mag.dec - table->db->dec_min) / - table->dec_stride_size); + table->dec.stride_size); mag = floor((dobject->posn_mag.Vmag - table->db->mag_bright) / - table->mag_stride_size); + table->mag.stride_size); - offset = table_calc_deep_offset(table, ra, dec, mag); + offset = table_calc_offset(table, ra, dec, mag); if (offset < 0) { astrodb_error("failed to calculate offset for RA %3.2f" @@ -83,26 +83,26 @@ int insert_posn_mag(void *d, void *object) /*! \fn static int insert_posn_type (void* d, void* object) * \brief Insert object into dataset based upon position and type */ -static int insert_posn_type(void *d, void *object) +static int insert_posn_type(void *table_, void *object) { int ra, dec, type, offset; - struct astrodb_table *table = (struct astrodb_table *) d; + struct astrodb_table *table = (struct astrodb_table *) table_; struct astrodb_object *dobject = object; - if (dobject->posn_mag.ra < table->db->ra_min || - dobject->posn_mag.ra > table->db->ra_max) + if (dobject->posn_type.ra < table->db->ra_min || + dobject->posn_type.ra > table->db->ra_max) return 0; - if (dobject->posn_mag.dec < table->db->dec_min || - dobject->posn_mag.dec > table->db->dec_max) + if (dobject->posn_type.dec < table->db->dec_min || + dobject->posn_type.dec > table->db->dec_max) return 0; - ra = floor((dobject->posn_mag.ra - table->db->ra_min) / - table->ra_stride_size); - dec = floor((dobject->posn_mag.dec - table->db->dec_min) / - table->dec_stride_size); - type = dobject->id; + ra = floor((dobject->posn_type.ra - table->db->ra_min) / + table->ra.stride_size); + dec = floor((dobject->posn_type.dec - table->db->dec_min) / + table->dec.stride_size); + type = dobject->posn_type.type; - offset = table_calc_deep_offset(table, ra, dec, type); + offset = table_calc_offset(table, ra, dec, type); if (offset < 0) { astrodb_error("failed to calculate offset for RA %3.2f" " DEC %3.2f type %3.2f\n", ra, dec, type); @@ -119,11 +119,12 @@ static int insert_posn_type(void *d, void *object) /*! \fn static int insert_hash_id (void* d, void* object) * \brief Insert object into dataset based upon position and mag */ -static int insert_hash_id(void *d, void *object) +static int insert_hash_id(void *table_, void *object) { - struct astrodb_table *table = (struct astrodb_table *) d; - int offset = table_calc_hash(((struct astrodb_object *) object)->id, - OBJECT_ID_SIZE, table->no_tiles); + struct astrodb_table *table = (struct astrodb_table *) table_; + int offset = + table_calc_hash(((struct astrodb_object *) object)->id, + table->no_tiles); *(table->objects + offset) = astrodb_slist_prepend(*(table->objects + offset), object); @@ -140,7 +141,7 @@ static inline int insert_hash_id_hobject(struct astrodb_table *table, { int offset; - offset = table_calc_hash((char *) object + table->hmaps[hid].offset, + offset = table_calc_hash_str((char *) object + table->hmaps[hid].offset, OBJECT_ID_SIZE, table->no_tiles); *(table->hmaps[hid].hobjects + offset) = @@ -169,13 +170,13 @@ static int insert_posn_mag_hash(void *d, void *object) return 0; ra = floor((dobject->posn_mag.ra - table->db->ra_min) / - table->ra_stride_size); + table->ra.stride_size); dec = floor((dobject->posn_mag.dec - table->db->dec_min) / - table->dec_stride_size); + table->dec.stride_size); mag = floor((dobject->posn_mag.Vmag - table->db->mag_bright) / - table->mag_stride_size); + table->mag.stride_size); - offset = table_calc_deep_offset(table, ra, dec, mag); + offset = table_calc_offset(table, ra, dec, mag); if (offset < 0) { astrodb_error("failed to calculate deep offset for RA %3.2f" " DEC %3.2f mag %3.2f\n", ra, dec, mag); @@ -193,43 +194,13 @@ static int insert_posn_mag_hash(void *d, void *object) return 1; } -/*! \fn static int insert_posn_type_hash (void* d, void* object) - * \brief Insert object into dataset based upon position and type - */ -static int insert_posn_type_hash(void *d, void *object) +void table_get_object_insert(struct astrodb_table *table) { - int ra, dec, type, offset, i; - struct astrodb_table *table = (struct astrodb_table *) d; - struct astrodb_object *dobject = object; - - if (dobject->posn_mag.ra < table->db->ra_min || - dobject->posn_mag.ra > table->db->ra_max) - return 0; - if (dobject->posn_mag.dec < table->db->dec_min || - dobject->posn_mag.dec > table->db->dec_max) - return 0; - - ra = floor((dobject->posn_mag.ra - table->db->ra_min) / - table->ra_stride_size); - dec = floor((dobject->posn_mag.dec - table->db->dec_min) / - table->dec_stride_size); - type = dobject->id; - offset = table_calc_deep_offset(table, ra, dec, type); - if (offset < 0) { - astrodb_error("failed to calculate deep offset for RA %3.2f" - " DEC %3.2f type %3.2f\n", ra, dec, type); - return 0; - } - - *(table->objects + offset) = - astrodb_slist_prepend(*(table->objects + offset), object); - (table->status + offset)->flags = ADB_SMEM; - (table->status + offset)->size++; - - for (i = 0; i < table->num_hmaps; i++) - insert_hash_id_hobject(table, object, i); - - return 1; + // TODO use standard IDs + if (table->num_hmaps > 0) + table->object_insert = &insert_posn_mag_hash; + else + table->object_insert = &insert_posn_mag; } /* table type insert's */ @@ -266,7 +237,7 @@ static int double_insert(void *dest, void *src) } static int str_insert(void *dest, void *src) { -// printf("str %s len %d\n", (char*)src, strlen(src)); + /* do not overrun our string */ strncpy(dest, src, strlen(src)); return 0; } -- 2.11.4.GIT