Skip to content

Commit

Permalink
initial import
Browse files Browse the repository at this point in the history
git-svn-id: https://q3c.googlecode.com/svn/trunk@1 8c088d1f-841a-aa82-adcb-f5b00ec8af86
  • Loading branch information
Sergey Koposov committed Dec 25, 2005
0 parents commit c894339
Show file tree
Hide file tree
Showing 16 changed files with 6,866 additions and 0 deletions.
340 changes: 340 additions & 0 deletions COPYING

Large diffs are not rendered by default.

98 changes: 98 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
OPT=-O3 #-mcpu=pentium4 -march=pentium4 -msse -msse2 -mfpmath=sse -mmmx
OPT_LOW=-O2
#DEBUG=-g3 -ggdb -DQ3C_DEBUG
#STATIC=-static
#PROF=-pg
#GCOV_PROF=-fprofile-arcs -ftest-coverage

MATH_LINK=-lm

ifdef PROF
LPROF=-pg -lc_p
MATH_LINK=-lm_p
endif

#PG_PATH=/opt/pgsql/include/server
PG_PATH=`pg_config --includedir-server`
PG_INC=-I$(PG_PATH)
#PG_INC=-I$(PG_PATH) -I/db2/q3cube/pgsql/include/server


MY_CFLAGS= -DQ3C_INT8 $(PG_INC) #-DQ3C_LONG_DOUBLE

PIC=-fpic
CFLAGS=$(OPT) $(DEBUG) $(PROF) $(GCOV_PROF) -Wall $(MY_CFLAGS) $(PG_INC)
CFLAGS1=$(OPT_LOW) $(DEBUG) $(PROF) $(GCOV_PROF) -W -Wall $(MY_CFLAGS) $(PG_INC)
CFLAGS2=$(OPT) $(DEBUG) $(PROF) $(GCOV_PROF) $(MY_CFLAGS) $(PG_INC)

LDFLAGS=$(MATH_LINK) $(LPROF) $(STATIC)

CC = gcc
LD = ld


all: q3c test test1 mini_test q3c.sql poly_test

q3c: q3c.o dump.o q3cube.o q3c_poly.o
$(LD) -shared -o lib$@.so $^

q3c_fast: q3c.o q3cube.o
$(LD) -shared -o libq3c.so $^ dump.o

q3c.o: q3c.c common.h
$(CC) -c $< $(PIC) $(CFLAGS1) -o $@

q3cube.o: q3cube.c common.h my_bits.h
$(CC) -c $< $(PIC) $(CFLAGS) -o $@

prepare.o: prepare.c common.h
$(CC) -c $< $(CFLAGS) -o $@

q3c_poly.o: q3c_poly.c q3cube.o common.h
$(CC) -c $< $(CFLAGS) -o $@

prepare: prepare.o q3cube.o q3c_poly.o
$(CC) $^ $(LDFLAGS) -o $@

dump.so: dump.c common.h
$(CC) -c $< $(PIC) -shared $(MY_CFLAGS) -o $@

dump.o: dump.c common.h
$(CC) -c $< $(PIC) $(MY_CFLAGS) $(OPT) -o $@

q3c.sql: q3c.sql.in
cat q3c.sql.in | sed s/MODULE_PATHNAME/"`echo $(CURDIR)/libq3c|sed 's/\//\\\\\//g'`"/g > q3c.sql

dump.c: prepare
./prepare

clean:
rm -f *.o test mini_test poly_test test1 prepare *.so q3c.sql dump.c

oclean:
rm -f *.o

oldclean:
rm -f *~

binclean:
rm -f test mini_test prepare test test1


test.o: test.c common.h
$(CC) -c $< $(CFLAGS2) -o $@

mini_test.o: mini_test.c common.h
$(CC) -c $< $(CFLAGS2) -o $@

test: test.o q3cube.o dump.o q3c_poly.o
$(CC) $^ $(LDFLAGS) -o $@

poly_test: poly_test.c q3c_poly.o q3cube.o dump.o
$(CC) $(CFLAGS) $^ $(LDFLAGS) -o $@

test1: test1.c dump.o q3cube.o
$(CC) $< $(CFLAGS2) q3cube.o dump.o q3c_poly.o $(LDFLAGS) -o $@

mini_test: mini_test.o q3cube.o q3c_poly.o
$(CC) $< q3cube.o dump.o q3c_poly.o $(LDFLAGS) -o $@
93 changes: 93 additions & 0 deletions README.q3c
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
Q3C

Author: Sergey Koposov, Sternberg Astronomical Institute
Email: [email protected]
http://lnfm1.sai.msu.ru/~math

About Q3C:
To read more about the whole Q3C scheme, look into the paper on Q3C from the
ADASS proceedings. The URL of the paper:
http://lnfm1.sai.msu.ru/~math/docs/adass_proceedings.pdf
If you will use Q3C you are kindly asked to cite this paper. Also, I
(Sergey Koposov) will be also happy to hear about any usage of Q3C.

----------------------------------------------------------------------

Small note: To work successfully with Q3C you need to have the version of
PostgreSQL 8.1 and later. (in principal, the cone search queries will
probably work even with earlier version, but the 8.1+ version is strongly
recommended).

----------------------------------------------------------------------

Installation:

1) make

2) Do "\i q3c.sql" in postgres

After that you will have
several new functions in postgres with the q3c_ prefix.

The useful ones are:

q3c_ang2ipix -- the function which converts the ra and dec to ipix value

q3c_join -- the function for the spatial join on the sphere

q3c_radial_query -- the function for the radial queries

Examples:

If you have the table with ra and dec columns

You can first create the spatial index:

my_db# CREATE INDEX q3c_mytable_idx ON mytable (q3c_ang2ipix(ra, dec));

And after that it is better to cluster that table using that index.
(Clustering procedure mainly order the data on the disk according to the
Q3C spatial index values). If the data is already loaded in the DB ordered by
some spherical zones or something similar, the clustering step can be ommited.

my_db# CLUSTER q3c_mytable_idx ON my_table;

Now you should do the last step -- analyze your table:

my_db# ANALYZE my_table;

Now the power of Q3C is available for you!!! :)

To perform the query around ra0 = 11 and dec0 = 12 with radius0 = 0.1
from the table mytable you can do:

my_db# SELECT * FROM mytable WHERE q3c_radial_query(ra, dec, 11, 12, 0.1);


The join example:

Assuming that we have a huge table "table2" with already created ipix index
and with ra and dec columns and the smaller one "table1" with ra and dec
columns.

If we want now to join "table1" with "table2" with error circle with the size
0.001 degrees, we do:

my_table# SELECT * FROM table1 AS a, table2 AS b WHERE
q3c_join(a.ra, a.dec, b.ra, b.dec, 0.001)

If every object in the table1 have his own error circle (like with X-ray data
for example) (suppose that the radius of that circle is the column "err"),
then you can run the query:

my_table# SELECT * FROM table1 AS a, table2 AS b WHERE
q3c_join(a.ra, a.dec, b.ra, b.dec, a.err);


The example with polygon query:

To query everything in the polygon ((0,0),(1,0),(1,1),(0,1)) ):

my_table# SELECT * FROM mytable WHERE
q3c_poly_query(ra, dec, '{0, 0, 1, 0, 1, 1, 0, 1}');

Loading

0 comments on commit c894339

Please sign in to comment.