Index: trunk/psphot/src/psphotTest.c
===================================================================
--- trunk/psphot/src/psphotTest.c	(revision 5837)
+++ trunk/psphot/src/psphotTest.c	(revision 5980)
@@ -1,35 +1,65 @@
 # include "psphot.h"
+bool apResidSetPower (float value);
+
+void psExit (int status, char *process, char *format, ...) {
+
+    va_list ap;
+
+    va_start (ap, format);
+    fprintf (stderr, "exiting %s\n", process);
+    vfprintf (stderr, format, ap);
+    va_end (ap);
+
+    exit (status);
+}
 
 int main (int argc, char **argv) {
 
-    char line[80];
-    psImage *image;
+    // read in a file consisting of:
+    // x y radius fitmag apmag dmag
 
-    image = psImageAlloc (512, 512, PS_DATA_F32);
-    for (int j = 0; j < 512; j++) {
-	for (int i = 0; i < 512; i++) {
-	    image->data.F32[j][i] = i;
-	}
+    double fit;
+    double ap;
+
+    psphotTestArguments (&argc, argv);
+
+    FILE *f = fopen (argv[1], "r");
+    if (f == NULL) psExit (2, "test", "no file\n");
+
+    float power = atof (argv[2]);
+    apResidSetPower (power);
+
+    psVector *x     = psVectorAlloc (100, PS_TYPE_F64);
+    psVector *y     = psVectorAlloc (100, PS_TYPE_F64);
+    psVector *rad   = psVectorAlloc (100, PS_TYPE_F64);
+    psVector *rflux = psVectorAlloc (100, PS_TYPE_F64);
+    psVector *apres = psVectorAlloc (100, PS_TYPE_F64);
+    psVector *dmag  = psVectorAlloc (100, PS_TYPE_F64);
+
+    int Npt = 0;
+    while (fscanf (f, "%lf %lf %lf %lf %lf %lf", 
+		   &x->data.F64[Npt], 
+		   &y->data.F64[Npt], 
+		   &rad->data.F64[Npt], 
+		   &fit, &ap, 
+		   &dmag->data.F64[Npt]) != EOF) {
+
+	if (fabs(ap-fit) > 0.1) continue;
+	if (fit > -10) continue;
+
+	apres->data.F64[Npt] = ap-fit;
+	rflux->data.F64[Npt] = pow(10.0, 0.4*fit);
+
+	psVectorExtend (x,     100, 1);
+	psVectorExtend (y,     100, 1);
+	psVectorExtend (rad,   100, 1);
+	psVectorExtend (rflux, 100, 1);
+	psVectorExtend (apres, 100, 1);
+	psVectorExtend (dmag,  100, 1);
+	Npt ++;
     }
+    x->n = y->n = rad->n = rflux->n = apres->n = dmag->n = Npt;
 
-    psMetadata *row = NULL;
-
-    psArray *table = psArrayAlloc (100);
-    table->n = 0;
-    
-    for (int i = 0; i < 100; i++) {
-	row = psMetadataAlloc ();
-	sprintf (line, "line %03d", i);
-	psMetadataAdd (row, PS_LIST_HEAD, "FLOAT_DATA", PS_DATA_F32,    "", 0.2*i);
-	psMetadataAdd (row, PS_LIST_HEAD, "INT_DATA",   PS_DATA_S32,    "", i);
-	psMetadataAdd (row, PS_LIST_HEAD, "CHAR_DATA",  PS_DATA_STRING, "", line);
-	psArrayAdd (table, 100, row);
-	// psFree (row);
-    }
-
-    psFits *fits = psFitsOpen ("test.fits", "w");
-    psFitsWriteImage (fits, NULL, image, 0);
-    psFitsWriteTable (fits, NULL, table);
-    psFitsClose (fits);
+    psphotApResidPolyFit (x, y, rad, rflux, apres, dmag);
 
     exit (0);
