Index: /trunk/Ohana/src/addstar/Makefile
===================================================================
--- /trunk/Ohana/src/addstar/Makefile	(revision 27581)
+++ /trunk/Ohana/src/addstar/Makefile	(revision 27582)
@@ -1,3 +1,3 @@
-default: addstar
+default: all
 help:
 	@echo "make options: addstar (default)"
@@ -27,5 +27,5 @@
 mkcmf       : $(BIN)/mkcmf.$(ARCH)
 
-all: addstar sedstar load2mass skycells
+all: addstar sedstar load2mass skycells mkcmf
 
 # I need to fix the client/server version of addstar now that I have dropped Stars
Index: /trunk/Ohana/src/addstar/src/find_matches.c
===================================================================
--- /trunk/Ohana/src/addstar/src/find_matches.c	(revision 27581)
+++ /trunk/Ohana/src/addstar/src/find_matches.c	(revision 27582)
@@ -272,5 +272,9 @@
 
     catalog[0].average[Nave].Xp        	   = 0;
-    catalog[0].average[Nave].ChiSq    	   = 0.0;
+    catalog[0].average[Nave].ChiSqAve  	   = 0.0;
+    catalog[0].average[Nave].ChiSqPM   	   = 0.0;
+    catalog[0].average[Nave].ChiSqPar  	   = 0.0;
+    catalog[0].average[Nave].Tmean   	   = 0;
+    catalog[0].average[Nave].Trange   	   = 0;
     catalog[0].average[Nave].Npos    	   = 0;
 
Index: /trunk/Ohana/src/addstar/src/find_matches_closest.c
===================================================================
--- /trunk/Ohana/src/addstar/src/find_matches_closest.c	(revision 27581)
+++ /trunk/Ohana/src/addstar/src/find_matches_closest.c	(revision 27582)
@@ -267,5 +267,9 @@
 
     catalog[0].average[Nave].Xp        	   = 0;
-    catalog[0].average[Nave].ChiSq    	   = 0.0;
+    catalog[0].average[Nave].ChiSqAve  	   = 0.0;
+    catalog[0].average[Nave].ChiSqPM   	   = 0.0;
+    catalog[0].average[Nave].ChiSqPar  	   = 0.0;
+    catalog[0].average[Nave].Tmean   	   = 0;
+    catalog[0].average[Nave].Trange   	   = 0;
     catalog[0].average[Nave].Npos    	   = 0;
 
Index: /trunk/Ohana/src/addstar/src/find_matches_closest_refstars.c
===================================================================
--- /trunk/Ohana/src/addstar/src/find_matches_closest_refstars.c	(revision 27581)
+++ /trunk/Ohana/src/addstar/src/find_matches_closest_refstars.c	(revision 27582)
@@ -285,5 +285,9 @@
 
     catalog[0].average[Nave].Xp            = 0;
-    catalog[0].average[Nave].ChiSq    	   = 0.0;
+    catalog[0].average[Nave].ChiSqAve  	   = 0.0;
+    catalog[0].average[Nave].ChiSqPM   	   = 0.0;
+    catalog[0].average[Nave].ChiSqPar  	   = 0.0;
+    catalog[0].average[Nave].Tmean   	   = 0;
+    catalog[0].average[Nave].Trange   	   = 0;
     catalog[0].average[Nave].Npos    	   = 0;
 
Index: /trunk/Ohana/src/addstar/src/find_matches_refstars.c
===================================================================
--- /trunk/Ohana/src/addstar/src/find_matches_refstars.c	(revision 27581)
+++ /trunk/Ohana/src/addstar/src/find_matches_refstars.c	(revision 27582)
@@ -255,5 +255,9 @@
 
     catalog[0].average[Nave].Xp            = 0;
-    catalog[0].average[Nave].ChiSq    	   = 0.0;
+    catalog[0].average[Nave].ChiSqAve  	   = 0.0;
+    catalog[0].average[Nave].ChiSqPM   	   = 0.0;
+    catalog[0].average[Nave].ChiSqPar  	   = 0.0;
+    catalog[0].average[Nave].Tmean   	   = 0;
+    catalog[0].average[Nave].Trange   	   = 0;
     catalog[0].average[Nave].Npos    	   = 0;
 
Index: /trunk/Ohana/src/addstar/src/mkcmf.c
===================================================================
--- /trunk/Ohana/src/addstar/src/mkcmf.c	(revision 27581)
+++ /trunk/Ohana/src/addstar/src/mkcmf.c	(revision 27582)
@@ -1,5 +1,3 @@
 # include "mkcmf.h"
-void gauss_init (int Nbin);
-double rnd_gauss (double mean, double sigma);
 
 # define SKY 100.0
@@ -14,4 +12,11 @@
 # define FLAGS 0x1101
 
+void gauss_init (int Nbin);
+double rnd_gauss (double mean, double sigma);
+void writeStars_PS1_V2 (FTable *ftable, double *X, double *Y, double *M, int Nstars);
+void writeStars_PS1_V1 (FTable *ftable, double *X, double *Y, double *M, int Nstars);
+void writeStars_PS1_DEV_1 (FTable *ftable, double *X, double *Y, double *M, int Nstars);
+void writeStars_PS1_DEV_0 (FTable *ftable, double *X, double *Y, double *M, int Nstars);
+
 int main (int argc, char **argv) {
 
@@ -19,17 +24,14 @@
   // load a text table with X,Y,Mag (instrumental?)
 
-  int i, N, Nstars, NSTARS, found;
-  double *X, *Y, *M;
-  double Xmax, Ymax;
-  float flux, fSN;
+  int N, Nstars, NSTARS, found;
+  double *X, *Y, *M, Xmax, Ymax;
 
   FILE *f, *fits;
-  Header header, theader;
+  Header header;
+  Header theader;
   Matrix matrix;
   FTable ftable;
   Coords coords;
 
-  PS1_DEV_1 *stars;
-
   static char *date = "2001-01-01";
   if ((N = get_argument (argc, argv, "-date"))) {
@@ -57,11 +59,9 @@
 
   // add support for all cmf types
-  static char *type = "PS1_DEV_1";
+  static char *type = "PS1_V2";
   if ((N = get_argument (argc, argv, "-type"))) {
     remove_argument (N, &argc, argv);
     type = strcreate (argv[N]);
     remove_argument (N, &argc, argv);
-    fprintf (stderr, "support for other types is broken: see comment at line 97\n");
-    exit (1);
   }
 
@@ -77,4 +77,5 @@
   }
     
+  // load test stars from a file:
   Nstars = 0;
   NSTARS = 100;
@@ -84,6 +85,8 @@
 
   Xmax = Ymax = 0;
-
   while (fscanf (f, "%lf %lf %lf", &X[Nstars], &Y[Nstars], &M[Nstars]) != EOF) {
+    Xmax  = MAX(Xmax, X[Nstars]);
+    Ymax  = MAX(Ymax, Y[Nstars]);
+
     if (Nstars == NSTARS - 1) {
       NSTARS += 100;
@@ -95,4 +98,208 @@
   }
 
+  // create primary header
+  gfits_init_header (&header);    
+  header.extend = TRUE;
+  gfits_create_header (&header);
+  gfits_create_matrix (&header, &matrix);
+  gfits_print (&header, "NEXTEND", "%d", 1, 1);
+
+  // XXX add minimum needed header fields 
+  gfits_print (&header, "IMNAXIS1", "%d", 1, (int)(Xmax + 50));
+  gfits_print (&header, "IMNAXIS2", "%d", 1, (int)(Ymax + 50));
+
+  gfits_modify (&header, "NSTARS",   "%d", 1, Nstars);
+  gfits_modify (&header, "PHOTCODE", "%s", 1, "SIMTEST.r.Chip");
+  gfits_modify (&header, "DATE-OBS", "%s", 1, date);
+  gfits_modify (&header, "UTC-OBS",  "%s", 1, time);
+  gfits_modify (&header, "ZERO_PT", "%lf", 1, 25.0);
+  gfits_modify (&header, "EXPTIME", "%lf", 1, 1.0);
+  gfits_modify (&header, "AIRMASS", "%lf", 1, 1.0);
+  gfits_modify (&header, "NASTRO",   "%d", 1, 10); 
+
+  gfits_modify (&header, "IMAGEID",  "%d", 1, (int)(1000*drand48())); 
+  gfits_modify (&header, "SOURCEID", "%d", 1, (int)(100*drand48())); 
+
+  /* bore site center guess */
+  strcpy (coords.ctype, "DEC--TAN");
+  coords.crval1 = RA;
+  coords.crval2 = DEC;
+  coords.crpix1 = 0.0;
+  coords.crpix2 = 0.0;
+  
+  coords.cdelt1 = 0.25/3600.0;
+  coords.cdelt2 = 0.25/3600.0;
+
+  coords.pc1_1  = 1;
+  coords.pc2_2  = 1;
+  coords.pc1_2  = 0;
+  coords.pc2_1  = 0;
+  coords.Npolyterms = 1;
+
+  PutCoords (&coords, &header);
+  gfits_modify (&header, "EXTNAME",   "%s", 1, "Chip.hdr");
+
+  ftable.header = &theader;
+
+  // set up desired CMF type:
+  found = FALSE;
+  if (!strcmp(type, "PS1_DEV_0")) {
+    writeStars_PS1_DEV_0 (&ftable, X, Y, M, Nstars);
+    found = TRUE;
+  }
+  if (!strcmp(type, "PS1_DEV_1")) {
+    writeStars_PS1_DEV_1 (&ftable, X, Y, M, Nstars); 
+    found = TRUE;
+  }
+  if (!strcmp(type, "PS1_V1")) {
+    writeStars_PS1_V1 (&ftable, X, Y, M, Nstars); 
+    found = TRUE;
+  }
+  if (!strcmp(type, "PS1_V2")) {
+    writeStars_PS1_V2 (&ftable, X, Y, M, Nstars); 
+    found = TRUE;
+  }
+  if (!found) {
+    fprintf (stderr, "ERROR: unknown CMF type %s\n", type);
+    exit (1);
+  }
+
+  gfits_modify (ftable.header, "EXTHEAD",   "%s", 1, "Chip.hdr");
+  gfits_modify (ftable.header, "EXTNAME",   "%s", 1, "Chip.psf");
+
+  fits = fopen (argv[2], "w");
+  if (fits == NULL) {
+    fprintf (stderr, "ERROR: can't open output file %s\n", argv[2]);
+    exit (1);
+  }
+
+  gfits_fwrite_header  (fits, &header);
+  gfits_fwrite_matrix  (fits, &matrix);
+  gfits_fwrite_Theader (fits, ftable.header);
+  gfits_fwrite_table   (fits, &ftable);
+  fclose (fits);
+
+  exit (0);
+}
+
+
+static int Ngaussint = 0;
+static double *gaussint;
+
+extern double drand48();
+
+double gaussian (double x, double mean, double sigma) {
+
+  double f;
+
+  f = exp (-0.5 * SQ(x - mean) / SQ(sigma)) / sqrt(2 * M_PI * SQ(sigma));
+
+  return (f);
+
+}
+
+/* integrate a gaussian from -5 sigma to +5 sigma */
+void gauss_init (int Nbin) {
+ 
+  int i;
+  long A, B;
+  double val, x, dx, dx1, dx2, dx3, df;
+  double mean, sigma;
+ 
+  /* no need to generate this if it already exists */
+  if (Ngaussint == Nbin) return;
+
+  A = time(NULL);
+  for (B = 0; A == time(NULL); B++);
+  srand48(B);
+ 
+  Ngaussint = Nbin;
+  ALLOCATE (gaussint, double, Ngaussint + 1);
+
+  val = 0;
+  dx = 1.0 / Ngaussint;
+  dx1 = dx / 3.0;
+  dx2 = 2.0*dx/3.0;
+  dx3 = dx;
+  mean = 0.0;
+  sigma = 1.0;
+ 
+  for (i = 0, x = -7.0; (i < Ngaussint) && (x < 7.0); x += dx)  {
+    df = (3.0*gaussian(x    , mean, sigma) + 
+          9.0*gaussian(x+dx1, mean, sigma) +
+          9.0*gaussian(x+dx2, mean, sigma) + 
+          3.0*gaussian(x+dx3, mean, sigma)) * (dx1/8.0);
+    val += df;
+    if (val > (i + 0.5) / (double) Ngaussint) {
+      gaussint[i] = x + dx / 2.0;
+      i++;
+    }
+  }
+}
+
+double rnd_gauss (double mean, double sigma) {
+ 
+  int i;
+  double y;
+ 
+  y = drand48();
+  i = Ngaussint*y;
+  y = gaussint[i]*sigma + mean;
+ 
+  return (y);
+ 
+}
+ 
+double int_gauss (int i) {
+  double y;
+  y = gaussint[i];
+  return (y);
+}
+ 
+void writeStars_PS1_DEV_0 (FTable *ftable, double *X, double *Y, double *M, int Nstars) {
+
+  int i;
+  PS1_DEV_0 *stars;
+  float flux, fSN;
+
+  // XXX add gaussian-distributed noise based on counts
+  // this needs to make different output 'stars' entries depending on the desired type
+  ALLOCATE (stars, PS1_DEV_0, Nstars);
+  gauss_init (2048);
+  for (i = 0; i < Nstars; i++) {
+    stars[i].detID = i;
+
+    flux = pow (10.0, -0.4*M[i]);
+    fSN = 1.0 / sqrt(flux);
+
+    stars[i].X = X[i] + FX * fSN * rnd_gauss(0.0, 1.0);
+    stars[i].Y = Y[i] + FY * fSN * rnd_gauss(0.0, 1.0);
+    stars[i].M = M[i] + fSN*rnd_gauss(0.0, 1.0);
+
+    stars[i].dX = FX * fSN;
+    stars[i].dY = FY * fSN;
+    stars[i].dM = fSN;
+
+    stars[i].Mpeak     = M[i] + 1.0;
+    stars[i].sky       = SKY;
+    stars[i].dSky      = DSKY;
+    stars[i].psfChisq  = PSFCHI;
+    stars[i].fx        = FX;
+    stars[i].fy        = FY;
+    stars[i].df        = DF;
+    stars[i].psfQual   = PSFQUAL;
+    stars[i].nFrames   = 1;
+  }
+
+  gfits_table_set_PS1_DEV_0 (ftable, stars, Nstars);
+  gfits_modify (ftable->header, "EXTTYPE",   "%s", 1, "PS1_DEV_0");
+}
+
+void writeStars_PS1_DEV_1 (FTable *ftable, double *X, double *Y, double *M, int Nstars) {
+
+  int i;
+  PS1_DEV_1 *stars;
+  float flux, fSN;
+
   // XXX add gaussian-distributed noise based on counts
   // this needs to make different output 'stars' entries depending on the desired type
@@ -108,7 +315,4 @@
     stars[i].Y = Y[i] + FY * fSN * rnd_gauss(0.0, 1.0);
     stars[i].M = M[i] + fSN*rnd_gauss(0.0, 1.0);
-
-    Xmax  = MAX(Xmax, X[i]);
-    Ymax  = MAX(Ymax, Y[i]);
 
     stars[i].dX = FX * fSN;
@@ -130,169 +334,90 @@
   }
 
-  // create primary header
-  gfits_init_header (&header);    
-  header.extend = TRUE;
-  gfits_create_header (&header);
-  gfits_create_matrix (&header, &matrix);
-  gfits_print (&header, "NEXTEND", "%d", 1, 1);
-
-  // XXX add minimum needed header fields 
-  gfits_print (&header, "IMNAXIS1", "%d", 1, (int)(Xmax + 50));
-  gfits_print (&header, "IMNAXIS2", "%d", 1, (int)(Ymax + 50));
-
-  gfits_modify (&header, "NSTARS",   "%d", 1, Nstars);
-  gfits_modify (&header, "PHOTCODE", "%s", 1, "SIMTEST.r.Chip");
-  gfits_modify (&header, "DATE-OBS", "%s", 1, date);
-  gfits_modify (&header, "UTC-OBS",  "%s", 1, time);
-  gfits_modify (&header, "ZERO_PT", "%lf", 1, 25.0);
-  gfits_modify (&header, "EXPTIME", "%lf", 1, 1.0);
-  gfits_modify (&header, "AIRMASS", "%lf", 1, 1.0);
-  gfits_modify (&header, "NASTRO",   "%d", 1, 10); 
-
-  gfits_modify (&header, "IMAGEID",  "%d", 1, (int)(1000*drand48())); 
-  gfits_modify (&header, "SOURCEID", "%d", 1, (int)(100*drand48())); 
-
-  /* bore site center guess */
-  strcpy (coords.ctype, "DEC--TAN");
-  coords.crval1 = RA;
-  coords.crval2 = DEC;
-  coords.crpix1 = 0.0;
-  coords.crpix2 = 0.0;
-  
-  coords.cdelt1 = 0.25/3600.0;
-  coords.cdelt2 = 0.25/3600.0;
-
-  coords.pc1_1  = 1;
-  coords.pc2_2  = 1;
-  coords.pc1_2  = 0;
-  coords.pc2_1  = 0;
-  coords.Npolyterms = 1;
-
-  PutCoords (&coords, &header);
-  gfits_modify (&header, "EXTNAME",   "%s", 1, "Chip.hdr");
-
-  ftable.header = &theader;
-
-  // set up desired CMF type:
-  found = FALSE;
-# if 0
-  if (!strcmp(type, "PS1_DEV_0")) {
-    gfits_table_set_PS1_DEV_0 (&ftable, stars, Nstars);
-    gfits_modify (&theader, "EXTTYPE",   "%s", 1, "PS1_DEV_0");
-    found = TRUE;
-  }
-# endif
-  if (!strcmp(type, "PS1_DEV_1")) {
-    gfits_table_set_PS1_DEV_1 (&ftable, stars, Nstars);
-    gfits_modify (&theader, "EXTTYPE",   "%s", 1, "PS1_DEV_1");
-    found = TRUE;
-  }
-# if 0
-  if (!strcmp(type, "PS1_V1")) {
-    gfits_table_set_CMF_PS1_V1 (&ftable, stars, Nstars);
-    gfits_modify (&theader, "EXTTYPE",   "%s", 1, "PS1_V1");
-    found = TRUE;
-  }
-  if (!strcmp(type, "PS1_V2")) {
-    gfits_table_set_CMF_PS1_V2 (&ftable, stars, Nstars);
-    gfits_modify (&theader, "EXTTYPE",   "%s", 1, "PS1_V2");
-    found = TRUE;
-  }
-# endif
-  if (!found) {
-    fprintf (stderr, "ERROR: unknown CMF type %s\n", type);
-    exit (1);
-  }
-
-  gfits_modify (&theader, "EXTHEAD",   "%s", 1, "Chip.hdr");
-  gfits_modify (&theader, "EXTNAME",   "%s", 1, "Chip.psf");
-
-  fits = fopen (argv[2], "w");
-  if (fits == NULL) {
-    fprintf (stderr, "ERROR: can't open output file %s\n", argv[2]);
-    exit (1);
-  }
-
-  gfits_fwrite_header  (fits, &header);
-  gfits_fwrite_matrix  (fits, &matrix);
-  gfits_fwrite_Theader (fits, &theader);
-  gfits_fwrite_table   (fits, &ftable);
-  fclose (fits);
-
-  exit (0);
-}
-
-
-static int Ngaussint = 0;
-static double *gaussint;
-
-extern double drand48();
-
-double gaussian (double x, double mean, double sigma) {
-
-  double f;
-
-  f = exp (-0.5 * SQ(x - mean) / SQ(sigma)) / sqrt(2 * M_PI * SQ(sigma));
-
-  return (f);
-
-}
-
-/* integrate a gaussian from -5 sigma to +5 sigma */
-void gauss_init (int Nbin) {
- 
-  int i;
-  long A, B;
-  double val, x, dx, dx1, dx2, dx3, df;
-  double mean, sigma;
- 
-  /* no need to generate this if it already exists */
-  if (Ngaussint == Nbin) return;
-
-  A = time(NULL);
-  for (B = 0; A == time(NULL); B++);
-  srand48(B);
- 
-  Ngaussint = Nbin;
-  ALLOCATE (gaussint, double, Ngaussint + 1);
-
-  val = 0;
-  dx = 1.0 / Ngaussint;
-  dx1 = dx / 3.0;
-  dx2 = 2.0*dx/3.0;
-  dx3 = dx;
-  mean = 0.0;
-  sigma = 1.0;
- 
-  for (i = 0, x = -7.0; (i < Ngaussint) && (x < 7.0); x += dx)  {
-    df = (3.0*gaussian(x    , mean, sigma) + 
-          9.0*gaussian(x+dx1, mean, sigma) +
-          9.0*gaussian(x+dx2, mean, sigma) + 
-          3.0*gaussian(x+dx3, mean, sigma)) * (dx1/8.0);
-    val += df;
-    if (val > (i + 0.5) / (double) Ngaussint) {
-      gaussint[i] = x + dx / 2.0;
-      i++;
-    }
-  }
-}
-
-double rnd_gauss (double mean, double sigma) {
- 
-  int i;
-  double y;
- 
-  y = drand48();
-  i = Ngaussint*y;
-  y = gaussint[i]*sigma + mean;
- 
-  return (y);
- 
-}
- 
-double int_gauss (int i) {
-  double y;
-  y = gaussint[i];
-  return (y);
-}
- 
+  gfits_table_set_PS1_DEV_1 (ftable, stars, Nstars);
+  gfits_modify (ftable->header, "EXTTYPE",   "%s", 1, "PS1_DEV_1");
+}
+
+void writeStars_PS1_V1 (FTable *ftable, double *X, double *Y, double *M, int Nstars) {
+
+  int i;
+  CMF_PS1_V1 *stars;
+  float flux, fSN;
+
+  // XXX add gaussian-distributed noise based on counts
+  // this needs to make different output 'stars' entries depending on the desired type
+  ALLOCATE (stars, CMF_PS1_V1, Nstars);
+  gauss_init (2048);
+  for (i = 0; i < Nstars; i++) {
+    stars[i].detID = i;
+
+    flux = pow (10.0, -0.4*M[i]);
+    fSN = 1.0 / sqrt(flux);
+
+    stars[i].X = X[i] + FX * fSN * rnd_gauss(0.0, 1.0);
+    stars[i].Y = Y[i] + FY * fSN * rnd_gauss(0.0, 1.0);
+    stars[i].M = M[i] + fSN*rnd_gauss(0.0, 1.0);
+
+    stars[i].dX = FX * fSN;
+    stars[i].dY = FY * fSN;
+    stars[i].dM = fSN;
+
+    stars[i].Mpeak     = M[i] + 1.0;
+    stars[i].sky       = SKY;
+    stars[i].dSky      = DSKY;
+    stars[i].psfChisq  = PSFCHI;
+    stars[i].crNsigma  = CRN;
+    stars[i].extNsigma = EXTN;
+    stars[i].fx        = FX;
+    stars[i].fy        = FY;
+    stars[i].df        = DF;
+    stars[i].psfQual   = PSFQUAL;
+    stars[i].nFrames   = 1;
+    stars[i].flags     = FLAGS;
+  }
+
+  gfits_table_set_CMF_PS1_V1 (ftable, stars, Nstars);
+  gfits_modify (ftable->header, "EXTTYPE",   "%s", 1, "PS1_V1");
+}
+
+void writeStars_PS1_V2 (FTable *ftable, double *X, double *Y, double *M, int Nstars) {
+
+  int i;
+  CMF_PS1_V2 *stars;
+  float flux, fSN;
+
+  // XXX add gaussian-distributed noise based on counts
+  // this needs to make different output 'stars' entries depending on the desired type
+  ALLOCATE (stars, CMF_PS1_V2, Nstars);
+  gauss_init (2048);
+  for (i = 0; i < Nstars; i++) {
+    stars[i].detID = i;
+
+    flux = pow (10.0, -0.4*M[i]);
+    fSN = 1.0 / sqrt(flux);
+
+    stars[i].X = X[i] + FX * fSN * rnd_gauss(0.0, 1.0);
+    stars[i].Y = Y[i] + FY * fSN * rnd_gauss(0.0, 1.0);
+    stars[i].M = M[i] + fSN*rnd_gauss(0.0, 1.0);
+
+    stars[i].dX = FX * fSN;
+    stars[i].dY = FY * fSN;
+    stars[i].dM = fSN;
+
+    stars[i].Mpeak     = M[i] + 1.0;
+    stars[i].sky       = SKY;
+    stars[i].dSky      = DSKY;
+    stars[i].psfChisq  = PSFCHI;
+    stars[i].crNsigma  = CRN;
+    stars[i].extNsigma = EXTN;
+    stars[i].fx        = FX;
+    stars[i].fy        = FY;
+    stars[i].df        = DF;
+    stars[i].psfQual   = PSFQUAL;
+    stars[i].nFrames   = 1;
+    stars[i].flags     = FLAGS;
+  }
+
+  gfits_table_set_CMF_PS1_V2 (ftable, stars, Nstars);
+  gfits_modify (ftable->header, "EXTTYPE",   "%s", 1, "PS1_V2");
+}
+
Index: /trunk/Ohana/src/addstar/test/relastro.dvo
===================================================================
--- /trunk/Ohana/src/addstar/test/relastro.dvo	(revision 27581)
+++ /trunk/Ohana/src/addstar/test/relastro.dvo	(revision 27582)
@@ -2,4 +2,15 @@
 
 input tap.dvo
+
+macro test.all
+  test.relastro PS1_DEV_0 PS1_V1
+  test.relastro PS1_DEV_1 PS1_V1
+  test.relastro PS1_V1 	PS1_V1
+  test.relastro PS1_V2 	PS1_V1
+  test.relastro PS1_DEV_0 PS1_V2
+  test.relastro PS1_DEV_1 PS1_V2
+  test.relastro PS1_V1 	PS1_V2
+  test.relastro PS1_V2 	PS1_V2
+end  
 
 # this set fails because the match radius does not equal the keep radius:
@@ -33,4 +44,8 @@
 # create a populated catdir with a couple of cmf files
 macro test.relastro
+  if ($0 != 3)
+    echo "test.relastro (cmftype) (dvotype)"
+    break
+  end
 
   tapPLAN 42
@@ -44,6 +59,6 @@
   for i 0 $offset:n
     mkinput $offset:$i
-    exec mkcmf test.in.txt test.cmf -date 2008/1/1 -time $i\:00:00 -radec $RA $DEC
-    exec addstar -D CATDIR catdir.test -D CAMERA simtest test.cmf
+    exec mkcmf test.in.txt test.cmf -date 2008/1/1 -time $i\:00:00 -radec $RA $DEC -type $1
+    exec addstar -D CATDIR catdir.test -D CAMERA simtest test.cmf -D CATFORMAT $2
   end
 
Index: /trunk/Ohana/src/addstar/test/relphot.dvo
===================================================================
--- /trunk/Ohana/src/addstar/test/relphot.dvo	(revision 27581)
+++ /trunk/Ohana/src/addstar/test/relphot.dvo	(revision 27582)
@@ -2,4 +2,15 @@
 
 input tap.dvo
+
+macro test.all
+  test.relphot PS1_DEV_0 PS1_V1
+  test.relphot PS1_DEV_1 PS1_V1
+  test.relphot PS1_V1 	PS1_V1
+  test.relphot PS1_V2 	PS1_V1
+  test.relphot PS1_DEV_0 PS1_V2
+  test.relphot PS1_DEV_1 PS1_V2
+  test.relphot PS1_V1 	PS1_V2
+  test.relphot PS1_V2 	PS1_V2
+end  
 
 list offset
@@ -12,4 +23,8 @@
 # create a populated catdir with a couple of cmf files
 macro test.relphot
+  if ($0 != 3)
+    echo "test.relphot (cmftype) (dvotype)"
+    break
+  end
 
   tapPLAN 4
@@ -22,6 +37,6 @@
   for i 0 $offset:n
     mkinput $offset:$i
-    exec mkcmf test.in.txt test.cmf -date 2008/1/1 -time $i\:00:00 -radec $RA $DEC
-    exec addstar -D CATDIR catdir.test -D CAMERA simtest test.cmf 
+    exec mkcmf test.in.txt test.cmf -date 2008/1/1 -time $i\:00:00 -radec $RA $DEC -type $1
+    exec addstar -D CATDIR catdir.test -D CAMERA simtest test.cmf -D CATFORMAT $2
   end
 
Index: /trunk/Ohana/src/addstar/test/simple.dvo
===================================================================
--- /trunk/Ohana/src/addstar/test/simple.dvo	(revision 27581)
+++ /trunk/Ohana/src/addstar/test/simple.dvo	(revision 27582)
@@ -4,12 +4,19 @@
 
 macro test.all
-  test.fields.type PS1_V1
-
+  test.fields PS1_DEV_0 PS1_V1
+  test.fields PS1_DEV_1 PS1_V1
+  test.fields PS1_V1 	PS1_V1
+  test.fields PS1_V2 	PS1_V1
+
+  test.fields PS1_DEV_0 PS1_V2
+  test.fields PS1_DEV_1 PS1_V2
+  test.fields PS1_V1 	PS1_V2
+  test.fields PS1_V2 	PS1_V2
 end  
 
 # create a populated catdir with a single cmf -- test each field
-macro test.fields.type
-  if ($0 != 2)
-    echo "USAGE: test.fields.type (cmftype) (dvotype?)"
+macro test.fields
+  if ($0 != 3)
+    echo "USAGE: test.fields (cmftype) (dvotype?)"
     break
   end
@@ -24,5 +31,7 @@
   mkinput
   exec mkcmf test.in.txt test.cmf -date 2008/1/1 -time 01:00:00 -radec $RA $DEC -type $1
-  exec addstar -D CATDIR catdir.test -D CAMERA simtest test.cmf
+  exec addstar -D CATDIR catdir.test -D CAMERA simtest test.cmf -D CATFORMAT $2
+
+  list testfields -copy testfields_$1
 
   catdir catdir.test
@@ -76,6 +85,6 @@
   end    
 
-  exec rm test.cmf test.in.txt
-  exec rm -r catdir.test
+  # exec rm test.cmf test.in.txt
+  # exec rm -r catdir.test
 
   tapDONE
@@ -96,6 +105,27 @@
 
 # list of cmf fields to test matched to mextract fields
+# this list is good for PS1_DEV_0
+list testfields_PS1_DEV_0
+  IPP_IDET          : detid
+  X_PSF             : xccd
+  Y_PSF             : yccd
+  X_PSF_SIG         : xccd:err
+  Y_PSF_SIG         : yccd:err
+  PSF_INST_MAG      : mag:inst
+  PSF_INST_MAG_SIG  : mag:err
+  PEAK_FLUX_AS_MAG  : SKIP
+  SKY               : sky
+  SKY_SIG           : sky_err
+  PSF_CHISQ         : psf_chisq
+  PSF_WIDTH_X       : FWHM_MAJ
+  PSF_WIDTH_Y       : FWHM_MIN
+  PSF_THETA         : THETA
+  PSF_QF            : PSF_QF
+  N_FRAMES          : SKIP
+end
+
+# list of cmf fields to test matched to mextract fields
 # this list is good for PS1_DEV_1
-list testfields_PS1_DEV_V1
+list testfields_PS1_DEV_1
   IPP_IDET          : detid
   X_PSF             : xccd
@@ -119,26 +149,73 @@
 end
 
-... etc ...
-# this list is good for PS1_DEV_0
-list testfields_PS1_DEV_V0
-  IPP_IDET          : detid
-  X_PSF             : xccd
-  Y_PSF             : yccd
-  X_PSF_SIG         : xccd:err
-  Y_PSF_SIG         : yccd:err
-  PSF_INST_MAG      : mag:inst
-  PSF_INST_MAG_SIG  : mag:err
-  PEAK_FLUX_AS_MAG  : SKIP
-  SKY               : sky
-  SKY_SIG           : sky_err
-  PSF_CHISQ         : psf_chisq
-  CR_NSIGMA         : cr_nsigma
+# this list is good for PS1_V1
+list testfields_PS1_V1
+  IPP_IDET          : detid	
+  X_PSF             : xccd	
+  Y_PSF             : yccd	
+  X_PSF_SIG         : xccd:err #  FAIL
+  Y_PSF_SIG         : yccd:err # FAIL
+  RA_PSF            : SKIP # astrometry is not calibrated in the cmf
+  DEC_PSF           : SKIP # astrometry is not calibrated in the cmf
+  POSANGLE          : SKIP # astrometry is not calibrated in the cmf
+  PLTSCALE          : SKIP # astrometry is not calibrated in the cmf
+  PSF_INST_MAG      : mag:inst	
+  PSF_INST_MAG_SIG  : mag:err	
+  AP_MAG_STANDARD   : mag:ap # FAIL
+  AP_MAG_RADIUS     : SKIP # no accessor
+  PEAK_FLUX_AS_MAG  : SKIP # no accessor
+  CAL_PSF_MAG       : SKIP # photometry is not calibrated in the cmf
+  CAL_PSF_MAG_SIG   : SKIP # photometry is not calibrated in the cmf
+  SKY               : sky	
+  SKY_SIG           : sky_err	
+  PSF_CHISQ         : psf_chisq	
+  CR_NSIGMA         : cr_nsigma	
   EXT_NSIGMA        : ext_nsigma
-  PSF_WIDTH_X       : FWHM_MAJ
-  PSF_WIDTH_Y       : FWHM_MIN
-  PSF_THETA         : THETA
-  PSF_QF            : PSF_QF
-  N_FRAMES          : SKIP
+  PSF_MAJOR         : FWHM_MAJ	
+  PSF_MINOR         : FWHM_MIN	
+  PSF_THETA         : THETA # FAIL
+  PSF_QF            : PSF_QF	
+  PSF_NDOF          : SKIP # no accessor
+  PSF_NPIX          : SKIP # no accessor
+  MOMENTS_XX        : SKIP # no accessor
+  MOMENTS_XY        : SKIP # no accessor
+  MOMENTS_YY        : SKIP # no accessor
   FLAGS             : phot_flags
-end
-
+  N_FRAMES          : SKIP # no accessor	
+end
+
+# this list is good for PS1_V2
+list testfields_PS1_V2
+  IPP_IDET          : detid	
+  X_PSF             : xccd	
+  Y_PSF             : yccd	
+  X_PSF_SIG         : xccd:err # FAIL
+  Y_PSF_SIG         : yccd:err # FAIL
+  RA_PSF            : SKIP # astrometry is not calibrated in the cmf
+  DEC_PSF           : SKIP # astrometry is not calibrated in the cmf
+  POSANGLE          : SKIP # astrometry is not calibrated in the cmf
+  PLTSCALE          : SKIP # astrometry is not calibrated in the cmf
+  PSF_INST_MAG      : mag:inst	
+  PSF_INST_MAG_SIG  : mag:err	
+  AP_MAG_STANDARD   : mag:ap # FAIL
+  AP_MAG_RADIUS     : SKIP # no accessor
+  PEAK_FLUX_AS_MAG  : SKIP # no accessor
+  CAL_PSF_MAG       : SKIP # photometry is not calibrated in the cmf
+  CAL_PSF_MAG_SIG   : SKIP # photometry is not calibrated in the cmf
+  SKY               : sky	
+  SKY_SIG           : sky_err	
+  PSF_CHISQ         : psf_chisq	
+  CR_NSIGMA         : cr_nsigma	
+  EXT_NSIGMA        : ext_nsigma
+  PSF_MAJOR         : FWHM_MAJ	
+  PSF_MINOR         : FWHM_MIN	
+  PSF_THETA         : THETA # FAIL
+  PSF_QF            : PSF_QF	
+  PSF_NDOF          : SKIP # no accessor
+  PSF_NPIX          : SKIP # no accessor
+  MOMENTS_XX        : SKIP # no accessor
+  MOMENTS_XY        : SKIP # no accessor
+  MOMENTS_YY        : SKIP # no accessor
+  FLAGS             : phot_flags
+  N_FRAMES          : SKIP # no accessor	
+end
