Index: unk/psastro/Makefile
===================================================================
--- /trunk/psastro/Makefile	(revision 7572)
+++ 	(revision )
@@ -1,88 +1,0 @@
-default: psastro
-help:
-	@echo "USAGE: make psastro"
-
-CC      =       gcc
-SRC     =       src
-BIN     =       bin
-
-DESTBIN =       $(HOME)/src/bin/$(ARCH)
-
-LPSLIB  :=      $(shell pslib-config --libs)
-IPSLIB  :=      $(shell pslib-config --cflags)
-
-LPSMOD  :=      $(shell psmodule-config --libs)
-IPSMOD  :=      $(shell psmodule-config --cflags)
-
-INCS	= 	$(IPSLIB) $(IPSMOD)
-LIBS	= 	$(LPSLIB) $(LPSMOD)
-CFLAGS	=	$(INCS) -std=c99 -Wall -Werror -g
-LFLAGS	=	$(LIBS) 
-
-PSASTRO = \
-$(SRC)/psastro.$(ARCH).o               	    \
-$(SRC)/psastroArguments.$(ARCH).o      	    \
-$(SRC)/psastroParseCamera.$(ARCH).o    	    \
-$(SRC)/psastroDataLoad.$(ARCH).o       	    \
-$(SRC)/psastroDataSave.$(ARCH).o       	    \
-$(SRC)/psastroAstromGuess.$(ARCH).o    	    \
-$(SRC)/psastroLoadReferences.$(ARCH).o 	    \
-$(SRC)/psastroConvert.$(ARCH).o	       	    \
-$(SRC)/psastroChipAstrom.$(ARCH).o     	    \
-$(SRC)/psastroOneChip.$(ARCH).o	       	    \
-$(SRC)/psastroUtils.$(ARCH).o	       	    \
-$(SRC)/psastroTestFuncs.$(ARCH).o      	    \
-$(SRC)/psastroMosaicAstrom.$(ARCH).o        \
-$(SRC)/psastroMosaicGetGrads.$(ARCH).o      \
-$(SRC)/psastroMosaicGetRefstars.$(ARCH).o   \
-$(SRC)/psastroMosaicChipAstrom.$(ARCH).o    \
-$(SRC)/psastroMosaicSetAstrom.$(ARCH).o	    \
-$(SRC)/psastroMosaicSetMatch.$(ARCH).o	    \
-$(SRC)/psastroMosaicHeaders.$(ARCH).o	    \
-$(SRC)/psastroMosaicRescaleChips.$(ARCH).o	    \
-$(SRC)/psastroWCS.$(ARCH).o	   
-
-psastro: $(BIN)/psastro.$(ARCH)
-$(BIN)/psastro.$(ARCH) : $(PSASTRO)
-$(PSASTRO): $(SRC)/psastro.h
-
-INSTALL = psastro
-
-all: psastro.install
-
-# dependancy rules for binary code #########################
-.PRECIOUS: %.$(ARCH).o
-.PRECIOUS: $(BIN)/%.$(ARCH)
-
-%.$(ARCH).o : %.c
-	$(CC) $(CFLAGS) -c $< -o $@
-
-$(BIN)/%.$(ARCH) : $(SRC)/%.$(ARCH).o
-	@if [ ! -d $(BIN) ]; then mkdir -p $(BIN); fi
-	$(CC) $^ -o $@ $(LFLAGS)
-	@echo "done with $@"
-
-$(DESTBIN)/%: $(BIN)/%.$(ARCH)
-	@if [ ! -d $(DESTBIN) ]; then mkdir -p $(DESTBIN); fi
-	rm -f $(DESTBIN)/$*
-	cp $(BIN)/$*.$(ARCH) $(DESTBIN)/$*
-
-$(INSTALL): % : $(BIN)/%.$(ARCH)
-
-%.clean :
-	rm -f $(BIN)/$*.$(ARCH)
-	rm -f $(SRC)/*.$(ARCH).o
-
-%.install:
-	make $(DESTBIN)/$*
-
-# utilities #################################################
-
-install:
-	for i in $(INSTALL); do make $$i.install; done
-
-clean:	
-	rm -f $(BIN)/*.$(ARCH)
-	rm -f `find . -name "*.o"`
-	rm -f `find . -name "*~"`
-	rm -f `find . -name "#*"`
Index: /trunk/psastro/Makefile.am
===================================================================
--- /trunk/psastro/Makefile.am	(revision 7573)
+++ /trunk/psastro/Makefile.am	(revision 7573)
@@ -0,0 +1,10 @@
+SUBDIRS = src
+
+CLEANFILES = *.pyc *~ core core.*
+
+pkgconfigdir = $(libdir)/pkgconfig
+pkgconfig_DATA= psastro.pc
+
+EXTRA_DIST = \
+	psastro.pc.in \
+	autogen.sh
Index: /trunk/psastro/configure.ac
===================================================================
--- /trunk/psastro/configure.ac	(revision 7573)
+++ /trunk/psastro/configure.ac	(revision 7573)
@@ -0,0 +1,55 @@
+dnl Process this file with autoconf to produce a configure script.
+AC_PREREQ(2.59)
+
+AC_INIT([psastro], [0.0.1], [http://pan-starrs.ifa.hawaii.edu])
+AC_CONFIG_SRCDIR([src])
+
+AM_INIT_AUTOMAKE([1.6 foreign dist-bzip2])
+dnl AM_CONFIG_HEADER([config.h])
+AM_MAINTAINER_MODE
+
+AC_LANG(C)
+AC_GNU_SOURCE
+AC_PROG_CC
+AC_PROG_INSTALL
+AC_PROG_LIBTOOL
+
+dnl handle debug building
+AC_ARG_ENABLE(optimize,
+  [AS_HELP_STRING(--enable-optimize,enable compiler optimization)],
+  [AC_MSG_RESULT(compile optimization enabled)
+   CFLAGS="-O2"],
+  [AC_MSG_RESULT([compile optimization disabled])
+   CFLAGS="-O0 -g"]
+)
+
+dnl handle profiler building
+AC_ARG_ENABLE(profile,
+  [AS_HELP_STRING(--enable-profile,enable compiler profiler information inclusion)],
+  [AC_MSG_RESULT(compile optimization enabled)
+   CFLAGS="${CFLAGS=} -pg"]
+)
+
+dnl ------------------------------------------------------------
+
+AC_PATH_PROG([ERRORCODES], [psParseErrorCodes], [missing])
+if test "$ERRORCODES" = "missing" ; then
+  AC_MSG_ERROR([psParseErrorCodes is required])
+fi
+
+PKG_CHECK_MODULES(PSLIB, pslib >= 0.9.0)
+PKG_CHECK_MODULES(PSMODULE, psmodule >= 0.0.0)
+
+dnl Set CFLAGS for build
+CFLAGS="${CFLAGS} -Wall -Werror -std=c99"
+
+AC_SUBST([PSASTRO_CFLAGS])
+AC_SUBST([PSASTRO_LIBS])
+
+AC_CONFIG_FILES([
+  Makefile
+  src/Makefile
+  psastro.pc
+])
+
+AC_OUTPUT
Index: /trunk/psastro/psastro.pc.in
===================================================================
--- /trunk/psastro/psastro.pc.in	(revision 7573)
+++ /trunk/psastro/psastro.pc.in	(revision 7573)
@@ -0,0 +1,10 @@
+prefix=@prefix@
+exec_prefix=@exec_prefix@
+libdir=@libdir@
+includedir=@includedir@
+
+Name: libpsastro
+Description: Pan-STARRS Photometry Library
+Version: @VERSION@
+Libs: -L${libdir} -lpsastro @PSASTRO_LIBS@
+Cflags: -I${includedir} @PSASTRO_CFLAGS@
Index: /trunk/psastro/src/Makefile.am
===================================================================
--- /trunk/psastro/src/Makefile.am	(revision 7573)
+++ /trunk/psastro/src/Makefile.am	(revision 7573)
@@ -0,0 +1,53 @@
+
+lib_LTLIBRARIES = libpsastro.la
+libpsastro_la_CPPFLAGS = $(PSLIB_CFLAGS) $(PSMODULE_CFLAGS) $(PSASTRO_CFLAGS)
+
+bin_PROGRAMS = psastro
+psastro_CPPFLAGS = $(PSLIB_CFLAGS) $(PSMODULE_CFLAGS) $(PSASTRO_CFLAGS)
+psastro_LDFLAGS = $(PSLIB_LIBS) $(PSMODULE_LIBS)
+psastro_LDADD = libpsastro.la
+
+psastro_SOURCES = \
+	psastro.c		
+
+libpsastro_la_SOURCES = \
+psastroArguments.c          \
+psastroParseCamera.c   	    \
+psastroDataLoad.c           \
+psastroDataSave.c           \
+psastroAstromGuess.c        \
+psastroLoadReferences.c     \
+psastroConvert.c	    \
+psastroChipAstrom.c         \
+psastroOneChip.c	    \
+psastroUtils.c	       	    \
+psastroTestFuncs.c          \
+psastroMosaicAstrom.c       \
+psastroMosaicGetGrads.c     \
+psastroMosaicGetRefstars.c  \
+psastroMosaicChipAstrom.c   \
+psastroMosaicSetAstrom.c    \
+psastroMosaicSetMatch.c	    \
+psastroMosaicHeaders.c	    \
+psastroMosaicRescaleChips.c \
+psastroWCS.c	   
+
+include_HEADERS = \
+	psastro.h		
+
+clean-local:
+	-rm -f TAGS
+
+# Tags for emacs
+tags:
+	etags `find . -name \*.[ch] -print`
+
+### Error codes.
+#BUILT_SOURCES = psastroErrorCodes.h psastroErrorCodes.c
+#CLEANFILES = psastroErrorCodes.h psastroErrorCodes.c
+
+#psastroErrorCodes.h : psastroErrorCodes.dat psastroErrorCodes.h.in
+#	$(ERRORCODES) --data=psastroErrorCodes.dat --outdir=. psastroErrorCodes.h
+
+#psastroErrorCodes.c : psastroErrorCodes.dat psastroErrorCodes.c.in psastroErrorCodes.h
+#	$(ERRORCODES) --data=psastroEerrorCodes.dat --outdir=. psastroErrorCodes.c
Index: /trunk/psastro/src/psastroArguments.c
===================================================================
--- /trunk/psastro/src/psastroArguments.c	(revision 7572)
+++ /trunk/psastro/src/psastroArguments.c	(revision 7573)
@@ -41,5 +41,5 @@
     if ((N = psArgumentGet (*argc, argv, "-chip"))) {
 	psArgumentRemove (N, argc, argv);
-	psMetadataAddStr (config->arguments, PS_LIST_TAIL, "CHIP_SELECTION", PS_DATA_STRING, "", psStringCopy(argv[N]));
+	psMetadataAddStr (config->arguments, PS_LIST_TAIL, "CHIP_SELECTIONS", PS_DATA_STRING, "", psStringCopy(argv[N]));
 	psArgumentRemove (N, argc, argv);
     }
Index: /trunk/psastro/src/psastroLoadReferences.c
===================================================================
--- /trunk/psastro/src/psastroLoadReferences.c	(revision 7572)
+++ /trunk/psastro/src/psastroLoadReferences.c	(revision 7573)
@@ -3,4 +3,5 @@
 
 # define ELIXIR_MODE 1
+# define PIPE_MODE 1
 
 psArray *psastroLoadReferences (pmConfig *config) {
@@ -8,5 +9,5 @@
     int fd;
     bool status;
-    char tempFile[64], tempLine[256];
+    char tempLine[256];
 
     // select the DVO database?
@@ -25,4 +26,31 @@
     // getstar -region RAmin RAmax DECmin DECmax
 
+# if PIPE_MODE
+    // use fork to add timeout capability
+    // use cfitsio |filename format to avoid tempFile
+    # if ELIXIR_MODE
+    sprintf (tempLine, "getstar -D CATFORMAT elixir -D CATMODE mef -region %f %f %f %f |", RAmin, DECmin, RAmax, DECmax, tempFile);
+    # else
+    sprintf (tempLine, "getstar -D CATFORMAT panstarrs -D CATMODE mef -region %f %f %f %f |", RAmin, DECmin, RAmax, DECmax, tempFile);
+    # endif
+
+    psTrace (__func__, 3, "%s\n", tempLine);
+
+    // the output from getstar is a file with the Average table
+    psFits *fits = psFitsOpen (tempLine, "r");
+
+    # if ELIXIR_MODE
+    psFitsMoveExtName (fits, "DVO_AVERAGE_ELIXIR");
+    # else
+    psFitsMoveExtName (fits, "DVO_AVERAGE_PANSTARRS");
+    # endif
+
+    psMetadata *header = psFitsReadHeader (NULL, fits);
+    psArray *table = psFitsReadTable (fits);
+    psFitsClose (fits);
+
+# else /***** use a temp file instead ****/
+
+    char tempFile[64];
     sprintf (tempFile, "/tmp/psastro.XXXXXX");
     if ((fd = mkstemp (tempFile)) == -1) {
@@ -61,4 +89,6 @@
     unlink (tempFile);
 
+# endif
+
     // convert the Average table to the pmAstromObj entries
     psArray *refs = psArrayAlloc (table->n);
Index: /trunk/psastro/src/psastroParseCamera.c
===================================================================
--- /trunk/psastro/src/psastroParseCamera.c	(revision 7572)
+++ /trunk/psastro/src/psastroParseCamera.c	(revision 7573)
@@ -44,17 +44,2 @@
     return true;
 }
-
-
-// useful for debugging
-# if 0
-for (int i = 0; i < input->fpa->chips->n; i++) {
-    pmChip *chip = input->fpa->chips->data[i];
-    fprintf (stderr, "chip %2d: %x %x\n", i, chip->file_exists, chip->process);
-
-    for (int j = 0; j < chip->cells->n; j++) {
-	pmCell *cell = chip->cells->data[j];
-	fprintf (stderr, "cell %2d: %x %x\n", j, cell->file_exists, cell->process);
-
-    }
-}
-# endif
