Index: branches/ipp-magic-v0/Ohana/src/lightcurve/Makefile
===================================================================
--- branches/elixir/Ohana/src/lightcurve/Makefile	(revision 2489)
+++ branches/ipp-magic-v0/Ohana/src/lightcurve/Makefile	(revision 21062)
@@ -1,53 +1,31 @@
-include ../../Configure
-PROGRAM =	lightcurve
+default: lightcurve
+help:
+	@echo "make options: lightcurve (default)"
+
+include ../../Makefile.System
 HOME 	=	$(ROOT)/lightcurve
-
-default: $(PROGRAM)
-
 BIN	=	$(HOME)/bin
-INC	= 	$(HOME)/include
+LIB	=	$(HOME)/lib
 SRC	=	$(HOME)/src
 MAN	=	$(HOME)/doc
-DESTBIN	=	$(LBIN)
-DESTLIB	=	$(LLIB)
-DESTINC	=	$(LINC)
-DESTMAN	=	$(LMAN)
+INC	= 	$(HOME)/include
+include ../../Makefile.Common
 
-#  
-INCS	= 	-I$(INC) -I$(LINC) -I$(XINC) -I$(LINC)/$(ARCH)
-LIBS	= 	-L$(LLIB) -lohana -lFITS -lm 
-CFLAGS	=	-o $*.o $(INCS) 
-CCFLAGS	=	$(INCS) $(LIBS) 
+# programs may add their own internal requirements here
+FULL_CFLAGS   = $(BASE_CFLAGS)
+FULL_CPPFLAGS = $(BASE_CPPFLAGS)
+FULL_LDFLAGS  = -ldvo -lFITS -lohana $(BASE_LDFLAGS)
 
-OBJS = \
-$(SRC)/args.o 		$(SRC)/get_names.o \
-$(SRC)/get_stars.o 	$(SRC)/sort_stars.o \
-$(SRC)/get_unique.o 	$(SRC)/get_sources.o \
-$(SRC)/get_info.o 	$(SRC)/make_table.o \
-$(SRC)/lightcurve.o	\
-$(SRC)/sort_seq.o	\
-$(SRC)/help.o 
+lightcurve: $(BIN)/lightcurve.$(ARCH)
+install: $(DESTBIN)/lightcurve
 
-$(OBJS): $(INC)/lightcurve.h
+LIGHTCURVE = \
+$(SRC)/args.$(ARCH).o 		$(SRC)/get_names.$(ARCH).o \
+$(SRC)/get_stars.$(ARCH).o 	$(SRC)/sort_stars.$(ARCH).o \
+$(SRC)/get_unique.$(ARCH).o 	$(SRC)/get_sources.$(ARCH).o \
+$(SRC)/get_info.$(ARCH).o 	$(SRC)/make_table.$(ARCH).o \
+$(SRC)/lightcurve.$(ARCH).o	\
+$(SRC)/help.$(ARCH).o 
 
-$(PROGRAM):	$(BIN)/$(PROGRAM)
-
-$(BIN)/$(PROGRAM): $(OBJS)
-	$(CC) $(OBJS) -o $(BIN)/$(PROGRAM) $(CCFLAGS)
-
-# -----------------------
-install:
-	rm -f $(DESTBIN)/$(PROGRAM)
-#	rm -f $(DESTMAN)/$(PROGRAM).1
-	cp $(BIN)/$(PROGRAM)   $(DESTBIN)/
-#	cp $(MAN)/$(PROGRAM).1 $(DESTMAN)/
-
-clean:	
-	rm -f $(BIN)/*.$(ARCH)
-	rm -f `find . -name "*.o"`
-	rm -f `find . -name "*~"`
-	rm -f `find . -name "#*"`
-
-dist: clean
-	rm -f $(BIN)/$(PROGRAM)
-
+$(LIGHTCURVE): $(INC)/lightcurve.h
+$(BIN)/lightcurve.$(ARCH): $(LIGHTCURVE)
Index: branches/ipp-magic-v0/Ohana/src/lightcurve/src/alter_headers.c
===================================================================
--- branches/elixir/Ohana/src/lightcurve/src/alter_headers.c	(revision 2489)
+++ branches/ipp-magic-v0/Ohana/src/lightcurve/src/alter_headers.c	(revision 21062)
@@ -29,5 +29,5 @@
     strcpy (head, images[i].name);
     strcpy (strchr(head, '.'), ".head");
-    fits_read_header (head, &header);
+    gfits_read_header (head, &header);
 
     sprintf (line, "mv %s %s~\0", head, head);
@@ -41,16 +41,16 @@
 	     images[i].Nunique, images[i].fixed, images[i].empty);
 
-    fits_modify (&header, "Mcal",   "%lf", 1, images[i].Mcal);
-    fits_modify (&header, "dMcal",  "%lf", 1, images[i].dMcal);
-    fits_modify (&header, "clouds", "%lf", 1, images[i].clouds);
-    fits_modify (&header, "NMcal",  "%d", 1,  images[i].Nstars);
+    gfits_modify (&header, "Mcal",   "%lf", 1, images[i].Mcal);
+    gfits_modify (&header, "dMcal",  "%lf", 1, images[i].dMcal);
+    gfits_modify (&header, "clouds", "%lf", 1, images[i].clouds);
+    gfits_modify (&header, "NMcal",  "%d", 1,  images[i].Nstars);
 
-    fits_modify (&header, "Mcal",   "%C", 1, "relphot: calibration magnitude");
-    fits_modify (&header, "dMcal",  "%C", 1, "relphot: calibration error");
-    fits_modify (&header, "clouds", "%C", 1, "relphot: cloud level");
-    fits_modify (&header, "NMcal",  "%C", 1, "relphot: number of stars");
+    gfits_modify (&header, "Mcal",   "%C", 1, "relphot: calibration magnitude");
+    gfits_modify (&header, "dMcal",  "%C", 1, "relphot: calibration error");
+    gfits_modify (&header, "clouds", "%C", 1, "relphot: cloud level");
+    gfits_modify (&header, "NMcal",  "%C", 1, "relphot: number of stars");
 
-    fits_write_header (head, &header);
-    fits_free_header (&header);
+    gfits_write_header (head, &header);
+    gfits_free_header (&header);
   }
   fclose (f);
Index: branches/ipp-magic-v0/Ohana/src/lightcurve/src/fix_header.c
===================================================================
--- branches/elixir/Ohana/src/lightcurve/src/fix_header.c	(revision 2489)
+++ branches/ipp-magic-v0/Ohana/src/lightcurve/src/fix_header.c	(revision 21062)
@@ -35,5 +35,5 @@
 
   header[0].size = Nbytes;
-  p1 = fits_header_field (header, "END", 1);
+  p1 = gfits_header_field (header, "END", 1);
   for (i = 3; i < 79; i++) 
     *(p1 + i) = ' ';
Index: branches/ipp-magic-v0/Ohana/src/lightcurve/src/get_info.c
===================================================================
--- branches/elixir/Ohana/src/lightcurve/src/get_info.c	(revision 2489)
+++ branches/ipp-magic-v0/Ohana/src/lightcurve/src/get_info.c	(revision 21062)
@@ -15,5 +15,5 @@
   strcpy (strchr(head, '.'), ".head");
 
-  status = fits_read_header (head, &header);
+  status = gfits_read_header (head, &header);
   if (!status) {
     fprintf (stderr, "could not open header file %s\n", head);
@@ -24,28 +24,28 @@
   switch (PIXELS) {
   case 0:
-    status &= fits_scan (&header, "RA_O",    "%lf", 1, &images[0].RA_O);
-    status &= fits_scan (&header, "RA_X",    "%lf", 1, &images[0].RA_X);
-    status &= fits_scan (&header, "RA_Y",    "%lf", 1, &images[0].RA_Y);
-    status &= fits_scan (&header, "DEC_O",   "%lf", 1, &images[0].DEC_O);
-    status &= fits_scan (&header, "DEC_X",   "%lf", 1, &images[0].DEC_X);
-    status &= fits_scan (&header, "DEC_Y",   "%lf", 1, &images[0].DEC_Y);
+    status &= gfits_scan (&header, "RA_O",    "%lf", 1, &images[0].RA_O);
+    status &= gfits_scan (&header, "RA_X",    "%lf", 1, &images[0].RA_X);
+    status &= gfits_scan (&header, "RA_Y",    "%lf", 1, &images[0].RA_Y);
+    status &= gfits_scan (&header, "DEC_O",   "%lf", 1, &images[0].DEC_O);
+    status &= gfits_scan (&header, "DEC_X",   "%lf", 1, &images[0].DEC_X);
+    status &= gfits_scan (&header, "DEC_Y",   "%lf", 1, &images[0].DEC_Y);
     COS = cos (RAD_DEG * images[0].DEC_O);
     break;
 
   case 1:
-    status &= fits_scan (&header, "X_O",    "%lf", 1, &images[0].RA_O);
-    status &= fits_scan (&header, "X_X",    "%lf", 1, &images[0].RA_X);
-    status &= fits_scan (&header, "X_Y",    "%lf", 1, &images[0].RA_Y);
-    status &= fits_scan (&header, "Y_O",    "%lf", 1, &images[0].DEC_O);
-    status &= fits_scan (&header, "Y_X",    "%lf", 1, &images[0].DEC_X);
-    status &= fits_scan (&header, "Y_Y",    "%lf", 1, &images[0].DEC_Y);
+    status &= gfits_scan (&header, "X_O",    "%lf", 1, &images[0].RA_O);
+    status &= gfits_scan (&header, "X_X",    "%lf", 1, &images[0].RA_X);
+    status &= gfits_scan (&header, "X_Y",    "%lf", 1, &images[0].RA_Y);
+    status &= gfits_scan (&header, "Y_O",    "%lf", 1, &images[0].DEC_O);
+    status &= gfits_scan (&header, "Y_X",    "%lf", 1, &images[0].DEC_X);
+    status &= gfits_scan (&header, "Y_Y",    "%lf", 1, &images[0].DEC_Y);
     COS = 1;
     break;
   }
   
-  fits_scan (&header, "ORIGIN", "%s", 1, line);
+  gfits_scan (&header, "ORIGIN", "%s", 1, line);
   /* interpret the silly way ESO / La Palma stores exposure time and duration   */
   if (!strcmp (line, "ESO-MIDAS")) { 
-    status &= fits_scan (&header, "DATE-OBS", "%s", 1, line);
+    status &= gfits_scan (&header, "DATE-OBS", "%s", 1, line);
     stripwhite (line);
     fprintf (stderr, "date line: %s\n", line);
@@ -53,28 +53,28 @@
     jd = atof(line);
     line[0] = 0;
-    status = fits_scan (&header, "TM-START", "%lf", 1, &sec);
+    status = gfits_scan (&header, "TM-START", "%lf", 1, &sec);
     fprintf (stderr, "date: %f, sec: %f\n", jd, sec);
     jd += (sec/86400.0) + 0.5;
     images[0].JD =  jd;
-    fits_scan (&header, "EXPTIME", "%lf", 1, &images[0].exptime);
+    gfits_scan (&header, "EXPTIME", "%lf", 1, &images[0].exptime);
   }
   else {
-    status &= fits_scan (&header, "JD", "%lf", 1, &images[0].JD);
+    status &= gfits_scan (&header, "JD", "%lf", 1, &images[0].JD);
     images[0].JD -= 2400000.5;   /* convert to MJD */
-    fits_scan (&header, "EXPTIME", "%lf", 1, &images[0].exptime);
+    gfits_scan (&header, "EXPTIME", "%lf", 1, &images[0].exptime);
   }
 
-  status &= fits_scan (&header, "Mcal", "%lf", 1, &images[0].Mcal);
-  status &= fits_scan (&header, "McalR", "%lf", 1, &images[0].McalR);
-  status &= fits_scan (&header, "McalD", "%lf", 1, &images[0].McalD);
-  status &= fits_scan (&header, "McalR2", "%lf", 1, &images[0].McalR2);
-  status &= fits_scan (&header, "McalD2", "%lf", 1, &images[0].McalD2);
-  status &= fits_scan (&header, "McalRD", "%lf", 1, &images[0].McalRD);
-  status &= fits_scan (&header, "dMcal", "%lf", 1, &images[0].dMcal);
+  status &= gfits_scan (&header, "Mcal", "%lf", 1, &images[0].Mcal);
+  status &= gfits_scan (&header, "McalR", "%lf", 1, &images[0].McalR);
+  status &= gfits_scan (&header, "McalD", "%lf", 1, &images[0].McalD);
+  status &= gfits_scan (&header, "McalR2", "%lf", 1, &images[0].McalR2);
+  status &= gfits_scan (&header, "McalD2", "%lf", 1, &images[0].McalD2);
+  status &= gfits_scan (&header, "McalRD", "%lf", 1, &images[0].McalRD);
+  status &= gfits_scan (&header, "dMcal", "%lf", 1, &images[0].dMcal);
 
   images[0].airmass = 1000;  
-  fits_scan (&header, "SECZ", "%lf", 1, &images[0].airmass);
-  fits_scan (&header, "AIRMASS", "%lf", 1, &images[0].airmass);
-  /* a stupid value as a flag (i hate flags!) but fits_scan will not alter the
+  gfits_scan (&header, "SECZ", "%lf", 1, &images[0].airmass);
+  gfits_scan (&header, "AIRMASS", "%lf", 1, &images[0].airmass);
+  /* a stupid value as a flag (i hate flags!) but gfits_scan will not alter the
      value if it fails to find the entry.  try a couple possibilities */
  
@@ -99,5 +99,5 @@
   images[0].clouds  = 0.0;
 
-  fits_free_header (&header);
+  gfits_free_header (&header);
   
 }
@@ -119,5 +119,5 @@
 /*
    code for using RA, DEC, ST info, if needed. 
-    status &= fits_scan (&header, "ST", "%lf", 1, &LST);
+    status &= gfits_scan (&header, "ST", "%lf", 1, &LST);
     ra  =  info[0].RA_O  + info[0].RA_X *CCD_X/2.0 + info[0].RA_Y *CCD_Y/2.0;
     dec =  info[0].DEC_O + info[0].DEC_X*CCD_X/2.0 + info[0].DEC_Y*CCD_Y/2.0;
Index: branches/ipp-magic-v0/Ohana/src/lightcurve/src/sort_seq.c
===================================================================
--- branches/elixir/Ohana/src/lightcurve/src/sort_seq.c	(revision 2489)
+++ 	(revision )
@@ -1,39 +1,0 @@
-# include "lightcurve.h"
-
-void sort_seq (seq, value, N) 
-int *seq;
-double *value;
-int N;
-{
-  int l,j,ir,i;
-  int temp;
-  
-  l = N >> 1;
-  ir = N - 1;
-  for (;;) {
-    if (l > 0) {
-      temp = seq[--l];
-    }
-    else {
-      temp = seq[ir];
-      seq[ir] = seq[0];
-      if (--ir == 0) {
-	seq[0] = temp;
-	return;
-      }
-    }
-    i = l;
-    j = (l << 1) + 1;
-    while (j <= ir) {
-      if (j < ir && value[seq[j]] < value[seq[j+1]]) ++j;
-      if (value[temp] < value[seq[j]]) {
-	seq[i]=seq[j];
-	j += (i=j) + 1;
-      }
-      else j = ir + 1;
-    }
-    seq[i] = temp;
-  }
-}
-
-
Index: branches/ipp-magic-v0/Ohana/src/lightcurve/src/sort_stars.c
===================================================================
--- branches/elixir/Ohana/src/lightcurve/src/sort_stars.c	(revision 2489)
+++ branches/ipp-magic-v0/Ohana/src/lightcurve/src/sort_stars.c	(revision 21062)
@@ -1,24 +1,23 @@
 # include "lightcurve.h"
 
-void sort_stars (radec, stars, Nstars)
-int  **radec;
-Star  *stars;
-int    Nstars;
-{
+// construct an index for the stars sorted by RA
+void sort_stars (int **index, Star *stars, int Nstars) {
   
   int i;
   double *RAs;
 
-  ALLOCATE (radec[0], int, Nstars);
-  ALLOCATE (RAs, double, Nstars);
+  ALLOCATE (myIndex, int, Nstars);
   for (i = 0; i < Nstars; i++) {
-    radec[0][i] = i;
-    RAs[i] = stars[i].RA;
+    myIndex[i] = i;
   }
 
-  sort_seq (radec[0], RAs, Nstars);
-  free (RAs);
+# define SWAPFUNC(A,B){ int tmp = myIndex[A]; myIndex[A] = myIndex[B]; myIndex[B] = tmp; }
+# define COMPARE(A,B)(stars[myIndex[A]].RA < stars[myIndex[B]].RA)
 
+  OHANA_SORT (Nstars, COMPARE, SWAPFUNC);
+
+# undef SWAPFUNC
+# undef COMPARE
+
+  *index = myIndex;
 }
-
-
