Index: /trunk/Ohana/src/imregister/photreg/args.photreg.c
===================================================================
--- /trunk/Ohana/src/imregister/photreg/args.photreg.c	(revision 125)
+++ /trunk/Ohana/src/imregister/photreg/args.photreg.c	(revision 126)
@@ -6,7 +6,8 @@
 int regargs (int argc, char **argv, PhotPars *newdata) {
 
-  int N, Np, required, photcode, Ntimes;
+  int N, required, Ntimes;
   double dtime;
   unsigned long *tstart, *tstop;
+  PhotCode *photcode;
 
   ConfigInit (&argc, argv);
@@ -19,15 +20,15 @@
   if (get_argument (argc, argv, "--help")) usage ();
 
+  /* load photcode data */
+  if (!LoadPhotcodes (PhotCodeFile)) {
+    fprintf (stderr, "error loading photcodes from %s\n", PhotCodeFile);
+    exit (1);
+  }
+
   /* set the required database */
-  set_db ("phot");
+  output.db = strcreate ("phot");
   if (N = get_argument (argc, argv, "-trans")) {
     remove_argument (N, &argc, argv);
-    set_db ("trans");
-  }
-
-  /* load photcode data */
-  if (!LoadPhotcodes (PhotCodeFile, &photcodes)) {
-    fprintf (stderr, "error loading photcodes from %s\n", PhotCodeFile);
-    exit (1);
+    output.db = strcreate ("trans");
   }
 
@@ -83,12 +84,11 @@
   }
 
-  /* error on observed zero point */
+  /* photcode system */
   if (N = get_argument (argc, argv, "-photcode")) {
     remove_argument (N, &argc, argv);
-    if (!GetPhotcodeRefs (&photcodes, argv[N], &photcode, &Np)) {
+    if ((photcode = GetPhotcodebyName (argv[N])) == NULL) {
       fprintf (stderr, "ERROR: photcode not found in photcode table\n");
       exit (1);
     }
-    newdata[0].photcode = photcode;
     remove_argument (N, &argc, argv);
     required |= 0x10;
@@ -106,13 +106,13 @@
   */
   
-  newdata[0].ZPo = 0.001*photcodes.code[Np].C;
-  if (output.offset) {
-    newdata[0].ZP += newdata[0].ZPo;
-  }
-  newdata[0].K = photcodes.code[Np].K;
-  newdata[0].X = photcodes.code[Np].X;
-  newdata[0].c1 = photcodes.code[Np].c1;
-  newdata[0].c2 = photcodes.code[Np].c2;
+  newdata[0].photcode = photcode[0].code;
+  newdata[0].refcode  = photcode[0].equiv;
+  newdata[0].K        = photcode[0].K;
+  newdata[0].X        = photcode[0].X;
+  newdata[0].c1       = photcode[0].c1;
+  newdata[0].c2       = photcode[0].c2;
   
+  newdata[0].ZPo      = 0.001*photcode[0].C;
+  if (output.offset) newdata[0].ZP += newdata[0].ZPo;
 }
 
Index: /trunk/Ohana/src/imregister/photreg/args.photsearch.c
===================================================================
--- /trunk/Ohana/src/imregister/photreg/args.photsearch.c	(revision 125)
+++ /trunk/Ohana/src/imregister/photreg/args.photsearch.c	(revision 126)
@@ -4,9 +4,15 @@
 int args (int argc, char **argv) {
 
-  int N;
+  int N, equiv;
 
   ConfigInit (&argc, argv);
   ConfigCamera ();
   ConfigFilter ();
+
+  /* load photcode data */
+  if (!LoadPhotcodes (PhotCodeFile)) {
+    fprintf (stderr, "error loading photcodes from %s\n", PhotCodeFile);
+    exit (1);
+  }
 
   criteria.Ntimes = 0;
@@ -19,5 +25,8 @@
   if (N = get_argument (argc, argv, "-photcode")) {
     remove_argument (N, &argc, argv);
-    criteria.PhotCode = strcreate (argv[N]);
+    if ((criteria.photcode = GetPhotcodeCodebyName (argv[N])) == NULL) {
+      fprintf (stderr, "ERROR: photcode not found in table\n");
+      exit (1);
+    }
     remove_argument (N, &argc, argv);
     criteria.PhotCodeSelect = TRUE;
@@ -106,23 +115,11 @@
   }
  
-  /* load photcode data */
-  if (!LoadPhotcodes (PhotCodeFile, &photcodes)) {
-    fprintf (stderr, "error loading photcodes from %s\n", PhotCodeFile);
-    exit (1);
-  }
-
   /* set up photcode information */
-  if (criteria.PhotCodeSelect) {
-    if (output.equiv) {
-      if (!GetPhotcodeEquiv (&photcodes, criteria.PhotCode, &criteria.PHOTCODE, &N)) {
-	fprintf (stderr, "ERROR: photcode not found in photcode table\n");
-	exit (1);
-      }
-    } else {
-      if (!GetPhotcodeRefs (&photcodes, criteria.PhotCode, &criteria.PHOTCODE, &N)) {
-	fprintf (stderr, "ERROR: photcode not found in photcode table\n");
-	exit (1);
-      }
+  if (criteria.PhotCodeSelect && output.equiv) {
+    if (!(equiv = GetPhotcodeEquivCodebyCode (criteria.photcode))) {
+      fprintf (stderr, "ERROR: photcode not found in photcode table\n");
+      exit (1);
     }
+    criteria.photcode = equiv;
   }
 }
Index: /trunk/Ohana/src/imregister/photreg/define.c
===================================================================
--- /trunk/Ohana/src/imregister/photreg/define.c	(revision 125)
+++ /trunk/Ohana/src/imregister/photreg/define.c	(revision 126)
@@ -30,5 +30,6 @@
   fits_define_bintable_column (theader, "I",   "C2_CODE",    "code 2 for color",          "photcode",                      1.0, 0.0);
   fits_define_bintable_column (theader, "I",   "PHOTCODE",   "photcode",                  "photcode",                      1.0, 0.0);
-  fits_define_bintable_column (theader, "66A", "LABEL",      "data label",                "",                              1.0, 0.0);
+  fits_define_bintable_column (theader, "64A", "LABEL",      "data label",                "",                              1.0, 0.0);
+  fits_define_bintable_column (theader, "I",   "REFCODE",    "photcode",                  "photcode",                      1.0, 0.0);
   fits_define_bintable_column (theader, "J",   "N_TIME",     "number of times",           "",                              1.0, 0.0);
   fits_define_bintable_column (theader, "J",   "N_MEAS",     "number of measurements",    "",                              1.0, 0.0);
Index: /trunk/Ohana/src/imregister/photreg/getImageData.c
===================================================================
--- /trunk/Ohana/src/imregister/photreg/getImageData.c	(revision 125)
+++ /trunk/Ohana/src/imregister/photreg/getImageData.c	(revision 126)
@@ -5,5 +5,5 @@
 
   Header header;
-  char detector[64], filter[64], *PhotCode;
+  char detector[64], filter[64], photcode[64];
   int i, ccd, Nfilter;
   
@@ -60,8 +60,10 @@
   }
 
-  ALLOCATE (PhotCode, char, 64);
-  sprintf (PhotCode, "%s.%s.%02d", detector, filter, ccd);
+  sprintf (photcode, "%s.%s.%02d", detector, filter, ccd);
+  if (!(criteria.photcode = GetPhotcodeCodebyName (photcode))) {
+    fprintf (stderr, "ERROR: photcode not found table\n");
+    exit (1);
+  }
   criteria.PhotCodeSelect = TRUE;
-  criteria.PhotCode = PhotCode;
 
 }
Index: /trunk/Ohana/src/imregister/photreg/match.c
===================================================================
--- /trunk/Ohana/src/imregister/photreg/match.c	(revision 125)
+++ /trunk/Ohana/src/imregister/photreg/match.c	(revision 126)
@@ -23,5 +23,5 @@
     }
     if (criteria.Ntimes && reject) continue;
-    if (criteria.PhotCodeSelect && (photdata[i].photcode != criteria.PHOTCODE)) continue;
+    if (criteria.PhotCodeSelect && (photdata[i].photcode != criteria.photcode)) continue;
     if (criteria.LabelSelect && strcmp (photdata[i].label, criteria.Label)) continue;
 
Index: /trunk/Ohana/src/imregister/src/imphotsearch.c
===================================================================
--- /trunk/Ohana/src/imregister/src/imphotsearch.c	(revision 125)
+++ /trunk/Ohana/src/imregister/src/imphotsearch.c	(revision 126)
@@ -1,23 +1,18 @@
 # include "imregister.h"
-FILE *fsetlockfile (char *filename, double timeout, int type, int *state);
-char *sec_to_date (unsigned long second);
+
 static char PhotError[] = "unknown";
-PhotCodeData photcodes;
-static char *version = "imphotsearch $Revision: 1.1 $";
+static char *version = "imphotsearch $Revision: 1.2 $";
 
 main (int argc, char **argv) {
  
   FILE *f;
-  Header header, theader;
-  Matrix matrix;
-  FTable table;
-  int i, j, status, N, TimeSelect;
-  char *dBFile, *Label, *PhotCode, *timestr, *photstr;
-  int Nimage, nimage, Nskip, *index, Ntimes;
+  Header header;
+  int i, j, status, N;
+  char *dBFile, *timestr, *photstr;
+  int Nimage, nimage, *index, Ntimes;
   unsigned long *tstart, *tstop;
   int VERBOSE, FORCE_READ, PHOTCODE, dbstate, lockstate;
   Image *image;
-  int PhotCodeSelect, LabelSelect, Np, Nin;
-  int Delete, *Dellist, Nkeep;
+  int PhotCodeSelect, Nin;
   char *FitsOutput, *NameSelect;
   int NameSelectLength;
@@ -28,4 +23,10 @@
   ConfigInit (&argc, argv);
 
+  /* load photcode data */
+  if (!LoadPhotcodes (PhotCodeFile)) {
+    fprintf (stderr, "error loading photcodes from %s\n", PhotCodeFile);
+    exit (1);
+  }
+
   /* interpret command-line arguments */
   if (!get_trange_arguments (&argc, argv, &tstart, &tstop, &Ntimes)) {
@@ -34,8 +35,12 @@
   }
 
+  /* select by image photcode */
   PhotCodeSelect = FALSE;
   if (N = get_argument (argc, argv, "-photcode")) {
     remove_argument (N, &argc, argv);
-    PhotCode = strcreate (argv[N]);
+    if (!(PHOTCODE = GetPhotcodeCodebyName (argv[N]))) {
+      fprintf (stderr, "ERROR: photcode not found in photcode table\n");
+      exit (1);
+    }
     remove_argument (N, &argc, argv);
     PhotCodeSelect = TRUE;
@@ -75,16 +80,4 @@
   }
  
-  /* load photcode data */
-  if (!LoadPhotcodes (PhotCodeFile, &photcodes)) {
-    fprintf (stderr, "error loading photcodes from %s\n", PhotCodeFile);
-    exit (1);
-  }
-  if (PhotCodeSelect) {
-    if (!GetPhotcodeRefs (&photcodes, argv[1], &PHOTCODE, &Np)) {
-      fprintf (stderr, "ERROR: photcode not found in photcode table\n");
-      exit (1);
-    }
-  }
-
   /* load image database - still a non-FITS file */
   dBFile = ImPhotDB;
@@ -158,8 +151,9 @@
       
       /* convert photcode to filter name */
-      photstr = GetPhotnamebyCode (&photcodes, image[i].source);
+      photstr = GetPhotcodeNamebyCode (image[i].source);
       if (photstr == (char *) NULL) photstr = PhotError;
       
-      fprintf (stdout, "%s %s %s  %7.4f %d\n", image[i].name, photstr, timestr, image[i].secz, image[i].nstar); 
+      fprintf (stdout, "%s %s %s  %7.4f %7.4f  %7.4f %d\n", image[i].name, photstr, timestr, 
+	       0.001*image[i].Mcal, 0.001*image[i].dMcal, 0.001*image[i].secz, image[i].nstar); 
       free (timestr);
     }
@@ -238,5 +232,5 @@
     newdata  = &image[index[i]];
     startstr = sec_to_date (newdata[0].tzero);
-    filtstr  = GetPhotnamebyCode (&photcodes, newdata[0].source);
+    filtstr  = GetPhotcodeNamebyCode (newdata[0].source);
     zp       = 0.001*newdata[0].Mcal;
     dzp      = 0.001*newdata[0].dMcal;
@@ -251,5 +245,4 @@
     free (line);
     free (startstr);
-    free (filtstr);
   }
     
