Index: /trunk/Ohana/src/libdvo/include/dvo.h
===================================================================
--- /trunk/Ohana/src/libdvo/include/dvo.h	(revision 35754)
+++ /trunk/Ohana/src/libdvo/include/dvo.h	(revision 35755)
@@ -182,17 +182,18 @@
 /* Secfilt.flags values -- these values are 32 bit (as of PS1_V1) */
 typedef enum {
-  ID_SECF_STAR_FEW    = 0x00000001, // used within relphot: skip star
-  ID_SECF_STAR_POOR   = 0x00000002, // used within relphot: skip star
-  ID_SECF_USE_SYNTH   = 0x00000004, // synthetic photometry used in average measurement
-  ID_SECF_USE_UBERCAL = 0x00000008, // synthetic photometry used in average measurement
-  ID_SECF_HAS_PS1     = 0x00000010, // PS1 photometry used in average measurement
-  ID_SECF_HAS_STACK   = 0x00000020, // PS1 stack photometry exists
-  ID_PHOTOM_PASS_0    = 0x00000100, // average magnitude calculated in 0th pass
-  ID_PHOTOM_PASS_1    = 0x00000200, // average magnitude calculated in 1th pass
-  ID_PHOTOM_PASS_2    = 0x00000400, // average magnitude calculated in 2th pass
-  ID_PHOTOM_PASS_3    = 0x00000800, // average magnitude calculated in 3th pass
-  ID_PHOTOM_PASS_4    = 0x00001000, // average magnitude calculated in 4th pass
-  ID_PSPS_OBJ_EXT     = 0x00002000, // In PSPS ID_SECF_OBJ_EXT is moved here so it fits within 16 bits
-  ID_SECF_OBJ_EXT     = 0x01000000, // extended in this band
+  ID_SECF_STAR_FEW    	= 0x00000001, // used within relphot: skip star
+  ID_SECF_STAR_POOR   	= 0x00000002, // used within relphot: skip star
+  ID_SECF_USE_SYNTH   	= 0x00000004, // synthetic photometry used in average measurement
+  ID_SECF_USE_UBERCAL 	= 0x00000008, // synthetic photometry used in average measurement
+  ID_SECF_HAS_PS1     	= 0x00000010, // PS1 photometry used in average measurement
+  ID_SECF_HAS_STACK   	= 0x00000020, // PS1 stack photometry exists
+  ID_PHOTOM_PASS_0    	= 0x00000100, // average magnitude calculated in 0th pass
+  ID_PHOTOM_PASS_1    	= 0x00000200, // average magnitude calculated in 1th pass
+  ID_PHOTOM_PASS_2    	= 0x00000400, // average magnitude calculated in 2th pass
+  ID_PHOTOM_PASS_3    	= 0x00000800, // average magnitude calculated in 3th pass
+  ID_PHOTOM_PASS_4    	= 0x00001000, // average magnitude calculated in 4th pass
+  ID_PSPS_OBJ_EXT     	= 0x00002000, // In PSPS ID_SECF_OBJ_EXT is moved here so it fits within 16 bits
+  ID_SECF_STACK_PRIMARY = 0x00004000, // PS1 stack photometry comes from primary skycell
+  ID_SECF_OBJ_EXT       = 0x01000000, // extended in this band
 } DVOSecfiltFlags;
 
@@ -250,5 +251,5 @@
 /* definitions for parallel dvo host information 
    XXX : need better names (safer namespace)
- */
+*/
 
 typedef enum {
@@ -328,4 +329,5 @@
   double  **dec; // DEC of projection cell center
   int    **cell; // zone,band -> proj cell sequence
+  int    **projID; // zone,band -> proj cell ID
   char  ***name; // projection cell name
   
Index: /trunk/Ohana/src/libdvo/src/BoundaryTree.c
===================================================================
--- /trunk/Ohana/src/libdvo/src/BoundaryTree.c	(revision 35754)
+++ /trunk/Ohana/src/libdvo/src/BoundaryTree.c	(revision 35755)
@@ -84,4 +84,5 @@
     ALLOCATE (tree->dY,      int *, tree->Nzone);
     ALLOCATE (tree->cell,    int *, tree->Nzone);
+    ALLOCATE (tree->projID,  int *, tree->Nzone);
     ALLOCATE (tree->name,  char **, tree->Nzone);
     for (i = 0; i < tree->Nzone; i++) {
@@ -93,4 +94,5 @@
       ALLOCATE (tree->dY[i],      int, tree->Nband[i]);
       ALLOCATE (tree->cell[i],    int, tree->Nband[i]);
+      ALLOCATE (tree->projID[i],  int, tree->Nband[i]);
       ALLOCATE (tree->name[i], char *, tree->Nband[i]);
       for (j = 0; j < tree->Nband[i]; j++) {
@@ -135,4 +137,6 @@
       tree->cell[nz][nb] = i; // XXX ?
       memcpy(tree->name[nz][nb], &name[i*BOUNDARY_TREE_NAME_LENGTH], BOUNDARY_TREE_NAME_LENGTH);
+      // XXX parse out the ID from the name (skycell.NNNN)
+      tree->projID[nz][nb] = atoi(&tree->name[nz][nb][8]);
     }
 
Index: /trunk/Ohana/src/libdvo/src/LoadPhotcodesFITS.c
===================================================================
--- /trunk/Ohana/src/libdvo/src/LoadPhotcodesFITS.c	(revision 35754)
+++ /trunk/Ohana/src/libdvo/src/LoadPhotcodesFITS.c	(revision 35755)
@@ -15,6 +15,6 @@
 
   /* XXX choose more sensible lock timeouts! */
+  db.timeout   = 60.0;
   db.lockstate = LCK_SOFT;
-  db.timeout   = 60.0;
   gfits_db_init (&db);
 
Index: /trunk/Ohana/src/libdvo/src/dbCheckStack.c
===================================================================
--- /trunk/Ohana/src/libdvo/src/dbCheckStack.c	(revision 35754)
+++ /trunk/Ohana/src/libdvo/src/dbCheckStack.c	(revision 35755)
@@ -23,4 +23,21 @@
 
   for (i = 0; i < Nstack; i++) {
+
+    // BINARY operators
+    if ((stack[i].type >= DB_STACK_LOGIC) && (stack[i].type <= DB_STACK_POWER)) {
+      if (i < 2) {
+	gprint (GP_ERR, "syntax error for field %s (binary operator missing operand)\n", stack[i].name);
+	goto failure;
+      }
+    }
+
+    // UNARY operators
+    if (stack[i].type == DB_STACK_UNARY) {
+      if (i < 1) {
+	gprint (GP_ERR, "syntax error for field %s (unary operator missing operand)\n", stack[i].name);
+	goto failure;
+      }
+    }
+
     if (stack[i].type == DB_STACK_VALUE) {
 
Index: /trunk/Ohana/src/libdvo/src/fits_db.c
===================================================================
--- /trunk/Ohana/src/libdvo/src/fits_db.c	(revision 35754)
+++ /trunk/Ohana/src/libdvo/src/fits_db.c	(revision 35755)
@@ -6,4 +6,13 @@
   db[0].f             = NULL;
   db[0].filename      = NULL;
+  
+# if (1)
+  gfits_init_header (&db->header);
+  gfits_init_matrix (&db->matrix);
+  gfits_init_header (&db->theader);
+  gfits_init_table (&db->ftable);
+  db->ftable.header = &db->theader;
+  gfits_init_vtable (&db->vtable);
+# else  
   db[0].header.buffer = NULL;
   db[0].matrix.buffer = NULL;
@@ -11,8 +20,8 @@
   db[0].ftable.buffer = NULL;
   db[0].ftable.header = &db[0].theader;
-
   db[0].vtable.header = NULL;
   db[0].vtable.buffer = NULL;
   db[0].vtable.row    = NULL;
+# endif
   return (TRUE);
 }
@@ -74,15 +83,15 @@
   }
   if (!gfits_fread_matrix (db[0].f, &db[0].matrix, &db[0].header)) {
-    fprintf (stderr, "can't read primary matrix");
+    fprintf (stderr, "can't read primary matrix\n");
     gfits_db_free (db);
     return (FALSE);
   }
   if (!gfits_fread_header (db[0].f, &db[0].theader)) {
-    fprintf (stderr, "can't read table header");
+    fprintf (stderr, "can't read table header\n");
     gfits_db_free (db);
     return (FALSE);
   }
   if (!gfits_fread_ftable_data (db[0].f, &db[0].ftable, FALSE)) {
-    fprintf (stderr, "can't read table data");
+    fprintf (stderr, "can't read table data\n");
     gfits_db_free (db);
     return (FALSE);
@@ -126,5 +135,5 @@
   if (db[0].matrix.buffer == NULL) {
     if (!gfits_fread_matrix (db[0].f, &db[0].matrix, &db[0].header)) {
-      fprintf (stderr, "can't read primary matrix");
+      fprintf (stderr, "can't read primary matrix\n");
       return (FALSE);
     }
@@ -137,5 +146,5 @@
   if (db[0].theader.buffer == NULL) {
     if (!gfits_fread_header (db[0].f, &db[0].theader)) {
-      fprintf (stderr, "can't read table header");
+      fprintf (stderr, "can't read table header\n");
       return (FALSE);
     }
@@ -147,5 +156,5 @@
   /* read table segment into vtable */
   if (!gfits_fread_vtable_range (db[0].f, &db[0].vtable, start, Nrows)) {
-    fprintf (stderr, "can't read table data");
+    fprintf (stderr, "can't read table data\n");
     return (FALSE);
   }
@@ -167,17 +176,17 @@
 
   if (!gfits_fwrite_header  (db[0].f, &db[0].header)) {
-    fprintf (stderr, "can't write primary header");
+    fprintf (stderr, "can't write primary header\n");
     return (FALSE);
   }
   if (!gfits_fwrite_matrix  (db[0].f, &db[0].matrix)) {
-    fprintf (stderr, "can't write primary matrix");
+    fprintf (stderr, "can't write primary matrix\n");
     return (FALSE);
   }
   if (!gfits_fwrite_Theader (db[0].f, &db[0].theader)) {
-    fprintf (stderr, "can't write table header");
+    fprintf (stderr, "can't write table header\n");
     return (FALSE);
   }
   if (!gfits_fwrite_table   (db[0].f, &db[0].ftable)) {
-    fprintf (stderr, "can't write table data");
+    fprintf (stderr, "can't write table data\n");
     return (FALSE);
   }
@@ -196,17 +205,17 @@
   /* do we revert to the old version if this fails? */
   if (!gfits_fwrite_header   (db[0].f, &db[0].header))  {
-    fprintf (stderr, "can't update primary header");
+    fprintf (stderr, "can't update primary header\n");
     return (FALSE);
   }
   if (!gfits_fwrite_matrix   (db[0].f, &db[0].matrix))  {
-    fprintf (stderr, "can't update primary matrix");
+    fprintf (stderr, "can't update primary matrix\n");
     return (FALSE);
   }
   if (!gfits_fwrite_Theader  (db[0].f, &db[0].theader)) {
-    fprintf (stderr, "can't update table header");
+    fprintf (stderr, "can't update table header\n");
     return (FALSE);
   }
   if (!gfits_fwrite_vtable   (db[0].f, &db[0].vtable))  {
-    fprintf (stderr, "can't update table data");
+    fprintf (stderr, "can't update table data\n");
     return (FALSE);
   }
