Index: trunk/Ohana/src/getstar/src/write_catalog.c
===================================================================
--- trunk/Ohana/src/getstar/src/write_catalog.c	(revision 15539)
+++ trunk/Ohana/src/getstar/src/write_catalog.c	(revision 15539)
@@ -0,0 +1,12 @@
+# include "getstar.h"
+
+int write_catalog (Catalog *catalog) {    
+
+  /* write out the selected stars */
+  // XXX need to set the catalog boundaries by hand? RA0-RA1, DEC0-DEC1
+  dvo_catalog_save   (catalog, VERBOSE);
+  dvo_catalog_unlock (catalog);
+  dvo_catalog_free   (catalog);
+  fprintf (stderr, "SUCCESS\n");
+  exit (0);
+}
Index: trunk/Ohana/src/getstar/src/write_getstar_ps1_dev_0.c
===================================================================
--- trunk/Ohana/src/getstar/src/write_getstar_ps1_dev_0.c	(revision 15539)
+++ trunk/Ohana/src/getstar/src/write_getstar_ps1_dev_0.c	(revision 15539)
@@ -0,0 +1,114 @@
+# include "getstar.h"
+
+// convert the average/secfilt values to getstar format 
+// PS1_DEV_0 has no errors or motions, only positions and magnitudes
+int write_getstar_PS1_DEV_0 (Catalog *catalog) {    
+
+  int i, m, offset;
+  int Nsec_c0, Nsec_c1, Nsec_c2, Nsecfilt;
+  int code_c0, code_c1, code_c2;
+  Average *average;
+  Measure *measure;
+  SecFilt *secfilt;
+  Getstar_PS1_DEV_0 *output;
+  Header header;
+  Matrix matrix;
+  Header theader;
+  FTable ftable;
+  FILE *f;
+  int Noutput;
+
+  Noutput = catalog[0].Naverage;
+  ALLOCATE (output, Getstar_PS1_DEV_0, Noutput);
+
+  // photcode is a global
+  if (photcode == NULL) {
+    fprintf (stderr, "undefined photcode\n");
+    exit (2);
+  }
+
+  Nsec_c0 = GetPhotcodeNsec (photcode[0].code);
+  Nsec_c1 = GetPhotcodeNsec (photcode[0].c1);
+  Nsec_c2 = GetPhotcodeNsec (photcode[0].c2);
+  Nsecfilt = GetPhotcodeNsecfilt ();
+
+  code_c0 = photcode[0].code;
+  code_c1 = photcode[0].c1;
+  code_c2 = photcode[0].c2;
+  measure = catalog[0].measure;
+  average = catalog[0].average;
+  secfilt = catalog[0].secfilt;
+
+  if (Nsec_c0 == -1) {
+    fprintf (stderr, "invalid photcode %s\n", photcode[0].name);
+    exit (2);
+  }
+
+  // do we skip any of catalog entries? (probably not)
+  for (i = 0; i < catalog[0].Naverage; i++) {
+    
+    output[i].R        = average[i].R;
+    output[i].D        = average[i].D;
+    output[i].mag      = secfilt[i*Nsecfilt + Nsec_c0].M;
+
+    output[i].code     = average[i].code;
+    output[i].photcode = code_c0;
+
+    // It is not necessary for the output color terms to be average values.  If they are,
+    // we grab them quickly & easily from the secfilt table.  If not, then we need to scan
+    // the list of measures to find the value of interest
+
+    // find color term 1
+    if (Nsec_c1 != -1) {
+      output[i].c1 = secfilt[i*Nsecfilt + Nsec_c1].M;
+    } else {
+      output[i].c1 = NAN;
+      offset = average[i].offset;
+      for (m = 0; m < average[i].Nm; m++) {
+        if (measure[offset + m].photcode == code_c1) {
+          output[i].c1 = PhotRel (&measure[offset + m], &average[i], &secfilt[i*Nsecfilt]);
+	  break;
+        }
+      }
+    }
+
+    // find color term 2
+    if (Nsec_c2 != -1) {
+      output[i].c2 = secfilt[i*Nsecfilt + Nsec_c2].M;
+    } else {
+      output[i].c2 = NAN;
+      offset = average[i].offset;
+      for (m = 0; m < average[i].Nm; m++) {
+        if (measure[offset + m].photcode == code_c2) {
+          output[i].c2 = PhotRel (&measure[offset + m], &average[i], &secfilt[i*Nsecfilt]);
+	  break;
+        }
+      }
+    }
+  }
+
+  // open file for output
+  f = fopen (OUTPUT, "w");
+  if (f == NULL) {
+    fprintf (stderr, "ERROR: can't open output file %s\n", OUTPUT);
+    exit (1);
+  }
+
+  // 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);
+
+  ftable.header = &theader;
+  gfits_table_set_Getstar_PS1_DEV_0 (&ftable, output, Noutput);
+
+  gfits_fwrite_header  (f, &header);
+  gfits_fwrite_matrix  (f, &matrix);
+  gfits_fwrite_Theader (f, &theader);
+  gfits_fwrite_table   (f, &ftable);
+
+  fprintf (stderr, "SUCCESS\n");
+  exit (0);
+}
Index: trunk/Ohana/src/getstar/src/write_getstar_ps1_dev_1.c
===================================================================
--- trunk/Ohana/src/getstar/src/write_getstar_ps1_dev_1.c	(revision 15539)
+++ trunk/Ohana/src/getstar/src/write_getstar_ps1_dev_1.c	(revision 15539)
@@ -0,0 +1,118 @@
+# include "getstar.h"
+
+// convert the average/secfilt values to getstar format 
+// PS1_DEV_1 has no errors, only positions, motions and magnitudes
+int write_getstar_PS1_DEV_1 (Catalog *catalog) {    
+
+  int i, m, offset;
+  int Nsec_c0, Nsec_c1, Nsec_c2, Nsecfilt;
+  int code_c0, code_c1, code_c2;
+  Average *average;
+  Measure *measure;
+  SecFilt *secfilt;
+  Getstar_PS1_DEV_1 *output;
+  Header header;
+  Matrix matrix;
+  Header theader;
+  FTable ftable;
+  FILE *f;
+  int Noutput;
+
+  Noutput = catalog[0].Naverage;
+  ALLOCATE (output, Getstar_PS1_DEV_1, Noutput);
+
+  // photcode is a global
+  if (photcode == NULL) {
+    fprintf (stderr, "undefined photcode\n");
+    exit (2);
+  }
+
+  Nsec_c0 = GetPhotcodeNsec (photcode[0].code);
+  Nsec_c1 = GetPhotcodeNsec (photcode[0].c1);
+  Nsec_c2 = GetPhotcodeNsec (photcode[0].c2);
+  Nsecfilt = GetPhotcodeNsecfilt ();
+
+  code_c0 = photcode[0].code;
+  code_c1 = photcode[0].c1;
+  code_c2 = photcode[0].c2;
+  measure = catalog[0].measure;
+  average = catalog[0].average;
+  secfilt = catalog[0].secfilt;
+
+  if (Nsec_c0 == -1) {
+    fprintf (stderr, "invalid photcode %s\n", photcode[0].name);
+    exit (2);
+  }
+
+  // do we skip any of catalog entries? (probably not)
+  for (i = 0; i < catalog[0].Naverage; i++) {
+    
+    output[i].R        = average[i].R;
+    output[i].D        = average[i].D;
+    output[i].uR       = average[i].uR;
+    output[i].uD       = average[i].uD;
+    output[i].P        = average[i].P;
+
+    output[i].code     = average[i].code;
+    output[i].photcode = code_c0;
+
+    output[i].mag      = secfilt[i*Nsecfilt + Nsec_c0].M;
+
+    // It is not necessary for the output color terms to be average values.  If they are,
+    // we grab them quickly & easily from the secfilt table.  If not, then we need to scan
+    // the list of measures to find the value of interest
+
+    // find color term 1
+    if (Nsec_c1 != -1) {
+      output[i].c1 = secfilt[i*Nsecfilt + Nsec_c1].M;
+    } else {
+      output[i].c1 = NAN;
+      offset = average[i].offset;
+      for (m = 0; m < average[i].Nm; m++) {
+        if (measure[offset + m].photcode == code_c1) {
+          output[i].c1 = PhotRel (&measure[offset + m], &average[i], &secfilt[i*Nsecfilt]);
+	  break;
+        }
+      }
+    }
+
+    // find color term 2
+    if (Nsec_c2 != -1) {
+      output[i].c2 = secfilt[i*Nsecfilt + Nsec_c2].M;
+    } else {
+      output[i].c2 = NAN;
+      offset = average[i].offset;
+      for (m = 0; m < average[i].Nm; m++) {
+        if (measure[offset + m].photcode == code_c2) {
+          output[i].c2 = PhotRel (&measure[offset + m], &average[i], &secfilt[i*Nsecfilt]);
+	  break;
+        }
+      }
+    }
+  }
+
+  // open file for output
+  f = fopen (OUTPUT, "w");
+  if (f == NULL) {
+    fprintf (stderr, "ERROR: can't open output file %s\n", OUTPUT);
+    exit (1);
+  }
+
+  // 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);
+
+  ftable.header = &theader;
+  gfits_table_set_Getstar_PS1_DEV_1 (&ftable, output, Noutput);
+
+  gfits_fwrite_header  (f, &header);
+  gfits_fwrite_matrix  (f, &matrix);
+  gfits_fwrite_Theader (f, &theader);
+  gfits_fwrite_table   (f, &ftable);
+
+  fprintf (stderr, "SUCCESS\n");
+  exit (0);
+}
Index: trunk/Ohana/src/getstar/src/write_getstar_ps1_dev_2.c
===================================================================
--- trunk/Ohana/src/getstar/src/write_getstar_ps1_dev_2.c	(revision 15539)
+++ trunk/Ohana/src/getstar/src/write_getstar_ps1_dev_2.c	(revision 15539)
@@ -0,0 +1,124 @@
+# include "getstar.h"
+
+// convert the average/secfilt values to getstar format 
+int write_getstar_PS1_DEV_2 (Catalog *catalog) {    
+
+  int i, m, offset;
+  int Nsec_c0, Nsec_c1, Nsec_c2, Nsecfilt;
+  int code_c0, code_c1, code_c2;
+  Average *average;
+  Measure *measure;
+  SecFilt *secfilt;
+  Getstar_PS1_DEV_2 *output;
+  Header header;
+  Matrix matrix;
+  Header theader;
+  FTable ftable;
+  FILE *f;
+  int Noutput;
+
+  Noutput = catalog[0].Naverage;
+  ALLOCATE (output, Getstar_PS1_DEV_2, Noutput);
+
+  // photcode is a global
+  if (photcode == NULL) {
+    fprintf (stderr, "undefined photcode\n");
+    exit (2);
+  }
+
+  Nsec_c0 = GetPhotcodeNsec (photcode[0].code);
+  Nsec_c1 = GetPhotcodeNsec (photcode[0].c1);
+  Nsec_c2 = GetPhotcodeNsec (photcode[0].c2);
+  Nsecfilt = GetPhotcodeNsecfilt ();
+
+  code_c0 = photcode[0].code;
+  code_c1 = photcode[0].c1;
+  code_c2 = photcode[0].c2;
+  measure = catalog[0].measure;
+  average = catalog[0].average;
+  secfilt = catalog[0].secfilt;
+
+  if (Nsec_c0 == -1) {
+    fprintf (stderr, "invalid photcode %s\n", photcode[0].name);
+    exit (2);
+  }
+
+  // do we skip any of catalog entries? (probably not)
+  for (i = 0; i < catalog[0].Naverage; i++) {
+    
+    output[i].R        = average[i].R;
+    output[i].D        = average[i].D;
+    output[i].dR       = average[i].dR;
+    output[i].dD       = average[i].dD;
+
+    output[i].uR       = average[i].uR;
+    output[i].uD       = average[i].uD;
+    output[i].duR      = average[i].duR;
+    output[i].duD      = average[i].duD;
+
+    output[i].P        = average[i].P;
+    output[i].dP       = average[i].dP;
+
+    output[i].code     = average[i].code;
+    output[i].photcode = code_c0;
+
+    output[i].mag      = secfilt[i*Nsecfilt + Nsec_c0].M;
+
+    // It is not necessary for the output color terms to be average values.  If they are,
+    // we grab them quickly & easily from the secfilt table.  If not, then we need to scan
+    // the list of measures to find the value of interest
+
+    // find color term 1
+    if (Nsec_c1 != -1) {
+      output[i].c1 = secfilt[i*Nsecfilt + Nsec_c1].M;
+    } else {
+      output[i].c1 = NAN;
+      offset = average[i].offset;
+      for (m = 0; m < average[i].Nm; m++) {
+        if (measure[offset + m].photcode == code_c1) {
+          output[i].c1 = PhotRel (&measure[offset + m], &average[i], &secfilt[i*Nsecfilt]);
+	  break;
+        }
+      }
+    }
+
+    // find color term 2
+    if (Nsec_c2 != -1) {
+      output[i].c2 = secfilt[i*Nsecfilt + Nsec_c2].M;
+    } else {
+      output[i].c2 = NAN;
+      offset = average[i].offset;
+      for (m = 0; m < average[i].Nm; m++) {
+        if (measure[offset + m].photcode == code_c2) {
+          output[i].c2 = PhotRel (&measure[offset + m], &average[i], &secfilt[i*Nsecfilt]);
+	  break;
+        }
+      }
+    }
+  }
+
+  // open file for output
+  f = fopen (OUTPUT, "w");
+  if (f == NULL) {
+    fprintf (stderr, "ERROR: can't open output file %s\n", OUTPUT);
+    exit (1);
+  }
+
+  // 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);
+
+  ftable.header = &theader;
+  gfits_table_set_Getstar_PS1_DEV_2 (&ftable, output, Noutput);
+
+  gfits_fwrite_header  (f, &header);
+  gfits_fwrite_matrix  (f, &matrix);
+  gfits_fwrite_Theader (f, &theader);
+  gfits_fwrite_table   (f, &ftable);
+
+  fprintf (stderr, "SUCCESS\n");
+  exit (0);
+}
Index: trunk/Ohana/src/libautocode/def/getstar-ps1-dev-0.d
===================================================================
--- trunk/Ohana/src/libautocode/def/getstar-ps1-dev-0.d	(revision 15539)
+++ trunk/Ohana/src/libautocode/def/getstar-ps1-dev-0.d	(revision 15539)
@@ -0,0 +1,17 @@
+STRUCT       Getstar_PS1_DEV_0
+EXTNAME      GETSTAR_PS1_DEV_0
+TYPE         BINTABLE
+SIZE         32
+DESCRIPTION  Getstar output file
+
+# elements of data structure / FITS table
+
+# average R,D are epoch & equinox J2000.0
+FIELD R,              RA,         double,           RA,                	       	  decimal degrees 
+FIELD D,              DEC,        double,           DEC,               	       	  decimal degrees 
+FIELD mag,            MAG,        float,            average magnitude in requested photcode
+FIELD c1,             MAG_C1,     float,            average magnitude in color term 1
+FIELD c2,             MAG_C2,     float,            average magnitude in color term 2
+
+FIELD photcode,       PHOTCODE,   unsigned short,   photcode for this mag
+FIELD code,           CODE,       unsigned short,   ID code (star; ghost; etc)
Index: trunk/Ohana/src/libautocode/def/getstar-ps1-dev-1.d
===================================================================
--- trunk/Ohana/src/libautocode/def/getstar-ps1-dev-1.d	(revision 15539)
+++ trunk/Ohana/src/libautocode/def/getstar-ps1-dev-1.d	(revision 15539)
@@ -0,0 +1,22 @@
+STRUCT       Getstar_PS1_DEV_1
+EXTNAME      GETSTAR_PS1_DEV_1
+TYPE         BINTABLE
+SIZE         48
+DESCRIPTION  Getstar output file
+
+# elements of data structure / FITS table
+
+# average R,D are epoch & equinox J2000.0
+FIELD R,              RA,         double,           RA,                	       	  decimal degrees 
+FIELD D,              DEC,        double,           DEC,               	       	  decimal degrees 
+FIELD uR,             U_RA,       float,            RA*cos(D) proper-motion,      arcsec/year
+FIELD uD,             U_DEC,      float,            DEC proper-motion,            arcsec/year
+FIELD P,              PAR,        float,            parallax,			  arcsec
+
+FIELD mag,            MAG,        float,            average magnitude in requested photcode
+FIELD c1,             MAG_C1,     float,            average magnitude in color term 1
+FIELD c2,             MAG_C2,     float,            average magnitude in color term 2
+
+FIELD photcode,       PHOTCODE,   unsigned short,   photcode for this mag
+FIELD code,           CODE,       unsigned short,   ID code (star; ghost; etc)
+FIELD dummy,          DUMMY,      char[4],          padding
Index: trunk/Ohana/src/libautocode/def/getstar-ps1-dev-2.d
===================================================================
--- trunk/Ohana/src/libautocode/def/getstar-ps1-dev-2.d	(revision 15539)
+++ trunk/Ohana/src/libautocode/def/getstar-ps1-dev-2.d	(revision 15539)
@@ -0,0 +1,28 @@
+STRUCT       Getstar_PS1_DEV_2
+EXTNAME      GETSTAR_PS1_DEV_2
+TYPE         BINTABLE
+SIZE         64
+DESCRIPTION  Getstar output file
+
+# elements of data structure / FITS table
+
+# average R,D are epoch & equinox J2000.0
+FIELD R,              RA,         double,           RA,                	       	  decimal degrees 
+FIELD D,              DEC,        double,           DEC,               	       	  decimal degrees 
+FIELD dR,             RA_ERR,     float,            RA error                      arcsec
+FIELD dD,             DEC_ERR,    float,            DEC error                     arcsec
+
+FIELD uR,             U_RA,       float,            RA*cos(D) proper-motion,      arcsec/year
+FIELD uD,             U_DEC,      float,            DEC proper-motion,            arcsec/year
+FIELD duR,            V_RA_ERR,   float,            RA*cos(D) p-m error,          arcsec/year
+FIELD duD,            V_DEC_ERR,  float,            DEC p-m error,                arcsec/year
+
+FIELD P,              PAR,        float,            parallax,			  arcsec
+FIELD dP,             PAR_ERR,    float,            parallax error,               arcsec
+
+FIELD mag,            MAG,        float,            average magnitude in requested photcode
+FIELD c1,             MAG_C1,     float,            average magnitude in color term 1
+FIELD c2,             MAG_C2,     float,            average magnitude in color term 2
+
+FIELD photcode,       PHOTCODE,   unsigned short,   photcode for this mag
+FIELD code,           CODE,       unsigned short,   ID code (star; ghost; etc)
