Index: trunk/Ohana/src/addstar/src/mkcmf.c
===================================================================
--- trunk/Ohana/src/addstar/src/mkcmf.c	(revision 34615)
+++ trunk/Ohana/src/addstar/src/mkcmf.c	(revision 34620)
@@ -178,4 +178,6 @@
   }
     
+  gauss_init (2048);
+
   // load test stars from a file:
   Nstars = 0;
@@ -254,6 +256,9 @@
   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())); 
+  int imageID = 1000.0*drand48();
+  int sourceID = 100.0*drand48();
+
+  gfits_modify (&header, "IMAGEID",  "%d", 1, imageID);
+  gfits_modify (&header, "SOURCEID", "%d", 1, sourceID);
 
   PutCoords (&coords, &header);
@@ -396,5 +401,4 @@
   // 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;
@@ -441,5 +445,4 @@
   // this needs to make different output 'stars' entries depending on the desired type
   ALLOCATE (stars, PS1_DEV_1, Nstars);
-  gauss_init (2048);
   for (i = 0; i < Nstars; i++) {
     stars[i].detID = i;
@@ -489,5 +492,4 @@
   // 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;
@@ -537,5 +539,4 @@
   // 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;
@@ -591,5 +592,4 @@
   // this needs to make different output 'stars' entries depending on the desired type
   ALLOCATE (stars, CMF_PS1_V3, Nstars);
-  gauss_init (2048);
   for (i = 0; i < Nstars; i++) {
     stars[i].detID = i;
@@ -649,5 +649,4 @@
   // this needs to make different output 'stars' entries depending on the desired type
   ALLOCATE (stars, CMF_PS1_V4, Nstars);
-  gauss_init (2048);
   for (i = 0; i < Nstars; i++) {
     stars[i].detID = i;
@@ -660,4 +659,11 @@
     stars[i].M = M[i];
     stars[i].Map = M[i] - 0.05;
+    stars[i].MapRaw = M[i] - 0.10;
+
+    stars[i].Flux = flux;
+    stars[i].dFlux = flux * fSN;
+
+    stars[i].apFlux = pow(10.0, -0.4*stars[i].Map);
+    stars[i].apFluxErr = stars[i].apFlux * fSN;
 
     if (ADDNOISE) {
Index: trunk/Ohana/src/addstar/test/relphot.stacks.dvo
===================================================================
--- trunk/Ohana/src/addstar/test/relphot.stacks.dvo	(revision 34620)
+++ trunk/Ohana/src/addstar/test/relphot.stacks.dvo	(revision 34620)
@@ -0,0 +1,323 @@
+# -*-sh-*-
+
+# relphot can set some secfilt values base on stack properties
+# we would like to test that these are correctly set
+
+input tap.dvo
+
+# set globals
+if (not($?PLOT)) set PLOT = 0 
+
+# set various global variables
+macro init
+  $RA_CENTER = 10.0
+  $DEC_CENTER = 20.0
+  $PLATE_SCALE = 0.25
+  $NSEASON = 3
+  $NFILTER = 3
+  $NCHIP_X = 2
+  $NCHIP_Y = 2
+  $NCELL_X = 2
+  $NCELL_Y = 2
+  $CHIP_DX = 1000
+  $CHIP_DY = 1000
+
+  # images are loaded into dvo with GPC1 photcodes, so we need to get the nominal zps for those filters
+  $zpt_nominal:g = 24.58
+  $zpt_nominal:r = 24.80
+  $zpt_nominal:i = 24.74
+  $zpt_nominal:z = 24.26
+  $zpt_nominal:y = 23.41
+
+  # klam is negative, so klam*(airmass - 1) increase the zero point
+  $klam_nominal:g = -0.15
+  $klam_nominal:r = -0.10
+  $klam_nominal:i = -0.04
+  $klam_nominal:z = -0.03
+  $klam_nominal:y = -0.03
+end
+
+macro go
+  if ($0 != 3)
+    echo "go (fileroot) (catdir)"
+    break
+  end
+
+  local i fileroot rootdir catdir
+
+  $fileroot = $1
+  $catdir = $2
+
+  dirname $1 -var rootdir
+  mkdir $rootdir
+
+  exec rm -rf $catdir
+
+  init
+  mkstars 500
+
+  # tapPLAN {((mjd_uc[]*4 + mjd_nc[]*4) + (mjd_uc[] + mjd_nc[]) + (mjd_uc[] + mjd_nc[])) / 3}
+
+  # generate the basic images and check they were correctly ingested by dvo
+  mksequence $fileroot $catdir
+  break
+
+  foreach filter g r i z y
+    ckexposure $catdir mjd_uc[$i] zpt_uc[$i] exptime_uc[$i] airmass_uc[$i] $filt_uc:$i raw
+  end
+
+  # run relphot on the db and check that the images now match the expected values
+  exec relphot g,r,i,z,y -v -region 9.5 10.5 19.5 20.5 -D CATDIR $catdir -nloop 0 -update >& tmp.log
+  foreach filter g r i z y
+    ckexposure catdir.test mjd_uc[$i] zpt_uc[$i] exptime_uc[$i] airmass_uc[$i] $filt_uc:$i relphot
+  end
+
+  tapDONE
+end
+
+# go testdata/t1 catdir.test
+# ckexposure catdir.test mjd_uc[0] zpt_uc[0] raw : result is mean of 0.0 (since test corrects for ZPT_NOMINAL vs REAL)
+# ckexposure catdir.test mjd_nc[0] zpt_nc[0] raw : result is mean of 0.0 
+# setphot -update -ubercal testzpt.fits -D CATDIR catdir.test
+# ckexposure catdir.test mjd_uc[0] zpt_uc[0] corr : result is mean of 0.0 (since image is corrected to ZPT_REAL)
+# ckexposure catdir.test mjd_nc[0] zpt_nc[0] corr : result is mean of -0.42 (since image is NOT corrected to ZPT_REAL)
+# relphot g -region 9.5 10.5 19.5 20.5 -update -D CATDIR catdir.test -D STAR_TOOFEW 1 -D SIGMA_LIM 0.075 -statmode MEAN
+# dvo: ckexposure catdir.test mjd_uc[0] zpt_uc[0] corr
+#  mean is now -0.42
+# dvo: ckexposure catdir.test mjd_nc[0] zpt_nc[0] corr
+#  mean is now -0.42 
+#  ** setphot assigned the zero point of the uc exposure to an effective -0.4 (ie, negative clouds), relphot was not told to keep this so it dragged the negative clouds to 0.0 -- this seems to be the right thing to do
+
+# re-run setphot, then relphot with -keep-ubercal
+
+# the test case has only 2 exposures, so the STAR_TOOFEW of 1 is necessary.  Also, the mag and sigma distributions are somewhat artificial
+# relphot g -v -region 9.5 10.5 19.5 20.5 -D CATDIR catdir.test -D STAR_TOOFEW 1 -D SIGMA_LIM 0.07 -statmode WT_MEAN -cloud-limit 0.5 -keep-ubercal -D IMAGE_OFFSET 0.5 -update
+# dvo: ckexposure catdir.test mjd_uc[0] zpt_uc[0] corr
+#  mean is now 0.0 
+# dvo: ckexposure catdir.test mjd_nc[0] zpt_nc[0] corr
+#  mean is now 0.0
+#  ** setphot correctly assigned the zero point of UC & relphot adjusted NC to match
+
+macro ckexposure
+  if ($0 != 8)
+    echo "ckexposure (catdir) (mjd) (zpt) (exptime) (airmass) (filter) (mode)"
+    echo "  mode == raw or corr"
+    break
+  end
+
+  local CATDIR MJD_IMAGE ZPT_REAL ZPT_NOMINAL EXPTIME FILTER AIRMASS
+  
+  $CATDIR      = $1
+  $MJD_IMAGE   = $2
+  $ZPT_REAL    = $3
+  $EXPTIME     = $4
+  $AIRMASS     = $5
+  $FILTER      = $6
+  $MODE        = $7
+
+  # XXX need a function to extract the nominal zpt for a given filter / photcode from the db
+  $ZPT_NOMINAL = $zpt_nominal:$FILTER
+  $KLAM_NOMINAL = $klam_nominal:$FILTER
+
+  $TIMEFORMAT = mjd
+  $TIMEREF = 0.0
+
+  catdir $CATDIR
+
+  # assume we still have stars_ra, stars_dec, stars_mag in hand
+  if ($PLOT)
+    dev -n 0
+    region $RA_CENTER $DEC_CENTER 0.2
+    images
+    pmeasure -all -m 15 20
+  end
+
+  skyregion {$RA_CENTER - 0.2/dcos($DEC_CENTER)} {$RA_CENTER + 0.2/dcos($DEC_CENTER)} {$DEC_CENTER - 0.2} {$DEC_CENTER + 0.2} 
+  mextract ra dec mag xccd yccd where (abs(time - $MJD_IMAGE) < 0.0001)
+ 
+  match2d -closest ra dec stars_ra stars_dec 0.001 -index1 index1 -index2 index2
+
+  reindex stars_ra_m  = stars_ra  using index1
+  reindex stars_dec_m = stars_dec using index1
+  reindex stars_mag_m = stars_mag using index1
+  set dr = 3600*(ra - stars_ra_m)
+  set dd = 3600*(dec - stars_dec_m)
+  set dm = mag - stars_mag_m
+
+  if ($PLOT) 
+    dev -n 1
+    lim mag dm; clear; box; plot mag dm
+  end
+
+  set cell_xbin = int(xccd / ($CHIP_DX / $NCELL_X))
+  set cell_ybin = int(yccd / ($CHIP_DY / $NCELL_Y))
+  subset dm00 = dm if (cell_xbin == 0) && (cell_ybin == 0)
+  subset dm01 = dm if (cell_xbin == 0) && (cell_ybin == 1)
+  subset dm10 = dm if (cell_xbin == 1) && (cell_ybin == 0)
+  subset dm11 = dm if (cell_xbin == 1) && (cell_ybin == 1)
+
+  # uncorrected values behave like this:
+  #   mag_DVO  = m_inst + zpt_nominal + 2.5*log(exptime) + K*(airmass - 1.0)
+  #   mag_real = m_inst + zpt_real + cell_offset
+  #   dm = mag_DVO - mag_real = zpt_nominal - zpt_real - cell_offset
+  #   <dm> - zpt_nominal + zpt_real + cell_offset ~ 0.0
+  #   zpt_real (in this case) = 25.0  + 2.5*log(exptime) + K*(airmass - 1.0) 
+  #     (actually, it is the value in the vector 'zpt' for this entry
+  #   zpt_nominal = 24.58
+
+  # setphot-corrected values behave like this:
+  #   mag_DVO  = mag_real (because m_inst has cell_offset applied)
+  #   dm = mag_DVO - mag_real ~ 0.0
+
+  $ZPT_REAL_NORM = $ZPT_REAL - 2.5*log($EXPTIME) - $KLAM_NOMINAL*($AIRMASS - 1.0)
+
+  if ("$MODE" == "raw") 
+    for ix 0 $NCELL_X
+      for iy 0 $NCELL_Y
+        # vstat -q dm$ix\$iy
+        # echo cell_off[$ix][$iy] {$MEDIAN - $ZPT_NOMINAL + $ZPT_REAL + cell_off[$ix][$iy]} $MEDIAN $MEAN $SIGMA 
+  
+        set dm_adjust = dm$ix\$iy - $ZPT_NOMINAL + $ZPT_REAL_NORM + cell_off[$ix][$iy]
+        vstat -q dm_adjust
+        tapOK {abs($MEAN) < 0.005} "addstar raw ZP $MJD_IMAGE $FILTER"
+      end
+    end
+    return
+  end
+
+  if ("$MODE" == "setphot_uc") 
+    vstat -q dm
+    tapOK {abs($MEAN) < 0.005} "setphot_uc  ZP $MJD_IMAGE $FILTER"
+    return
+  end
+
+  if ("$MODE" == "setphot_nc") 
+    vstat -q dm
+    tapOK {abs($MEAN - $ZPT_NOMINAL + $ZPT_REAL_NORM) < 0.005} "setphot_nc  ZP $MJD_IMAGE $FILTER"
+    return
+  end
+
+  if ("$MODE" == "relphot") 
+    vstat -q dm
+    tapOK {abs($MEAN) < 0.005} "relphot    ZP $MJD_IMAGE $FILTER"
+    return
+  end
+
+end
+
+macro mksequence
+  if ($0 != 3)
+    echo "mksequence (fileroot) (catdir)"
+    break
+  end
+
+  local i
+
+  # basic set of 5 stacks
+  foreach filter g r i z y
+    mkstack $1.$filter $RA_CENTER $DEC_CENTER $zpt_nominal:$filter 100.0 1.0 56228.666146 $filter $2
+  end
+end
+
+macro mkstack
+ if ($0 != 10)
+   echo "mkstack (fileroot) (ra) (dec) (zpt) (exptime) (airmass) (mjd) (filter) (catdir)"
+   break
+ end
+
+ local ix iy date time datetime ra dec ROOT RAo DECo ZPT MJD FILTER EXPTIME AIRMASS CATDIR
+
+ $ROOT    = $1
+ $RAo     = $2
+ $DECo    = $3
+ $ZPT     = $4
+ $EXPTIME = $5
+ $AIRMASS = $6 
+ $MJD     = $7
+ $FILTER  = $8
+ $CATDIR  = $9
+
+ $TIMEFORMAT = mjd
+ $TIMEREF = 0.0
+
+ for ix 0 $NCHIP_X
+  for iy 0 $NCHIP_Y
+    $dx  = $CHIP_DX * $PLATE_SCALE * ($ix - 0.5*$NCHIP_X + 0.5)
+    $dy  = $CHIP_DY * $PLATE_SCALE * ($iy - 0.5*$NCHIP_Y + 0.5)
+    $ra  = $RAo  - $dx / 3600.0 / dcos($DECo)
+    $dec = $DECo - $dy / 3600.0
+    # echo $ra $dec $dx $dy
+    mkinput test.in.txt $ra $dec $ZPT 
+    
+    # ra,dec is the center of this chip
+    local options
+    $options = 
+    $options = $options -radec $ra $dec 
+    $options = $options -type PS1_V4
+    $options = $options -coords 
+    $options = $options -photcode GPC1.$FILTER.SkyChip 
+    $options = $options -no-noise 
+    $options = $options -size $CHIP_DX $CHIP_DY 
+    $options = $options -crpix {0.5*$CHIP_DX} {0.5*$CHIP_DY} 
+    $options = $options -exptime $EXPTIME
+
+    # these should not be needed for stacks, right
+    $options = $options -airmass $AIRMASS
+    $options = $options -mjd $MJD 
+
+    exec mkcmf test.in.txt $ROOT.$ix.$iy.cmf $options
+    echo mkcmf test.in.txt $ROOT.$ix.$iy.cmf $options 
+    
+    # the fake images have inconsistent ra,dec and airmass,sidtime values
+    echo addstar $ROOT.$ix.$iy.cmf -D CATDIR $CATDIR -D CATFORMAT PS1_V4 -D CAMERA gpc1 -quick-airmass
+    exec addstar $ROOT.$ix.$iy.cmf -D CATDIR $CATDIR -D CATFORMAT PS1_V4 -D CAMERA gpc1 -quick-airmass >& tmp.log
+  end
+ end
+end
+
+# make a simple input file for mkcmf
+macro mkinput
+  if ($0 != 5)
+    echo "mkinput (filename) (ra) (dec) (zpt)"
+    break
+  end
+
+  # chip coordinate of the stars
+  # ra,dec is at the chip center, which corresponds to pixel (CHIP_DX,CHIP_DY)/2
+  set stars_X = (stars_ra  - $2) * 3600.0 * dcos($3) / $PLATE_SCALE + $CHIP_DX*0.5
+  set stars_Y = (stars_dec - $3) * 3600.0            / $PLATE_SCALE + $CHIP_DY*0.5
+  set stars_M = (stars_mag - $4)
+
+  set valid = (stars_X > 0) && (stars_X < $CHIP_DX) && (stars_Y > 0) && (stars_Y < $CHIP_DX)
+  subset stars_x  = stars_X if valid
+  subset stars_y  = stars_Y if valid
+  subset stars_mi = stars_M if valid
+  subset stars_r  = stars_ra if valid
+  subset stars_d  = stars_dec if valid
+  subset stars_mr = stars_mag if valid
+
+  write -f "%10.6f %10.6f %7.3f  %6.1f %6.1f %7.3f" $1 stars_r stars_d stars_mr stars_x stars_y stars_mi
+end
+
+# generate a set of stars with raw RA, DEC, MAG values to use for all of the output cmf files
+macro mkstars
+  if ($0 != 2)
+    echo "USAGE: mkstars (Nstars)"
+    break
+  end
+
+  local RA_RANGE DEC_RANGE
+
+  # the images are oriented along N-S, E-W lines
+
+  # size of region of interest in linear arcseconds
+  $RA_RANGE  = 1.25 * $CHIP_DX * $NCHIP_X * $PLATE_SCALE
+  $DEC_RANGE = 1.25 * $CHIP_DY * $NCHIP_Y * $PLATE_SCALE 
+
+  create tmp 0 $1
+  set stars_ra  = $RA_CENTER  + $RA_RANGE  * (rnd(tmp) - 0.5) / 3600 / dcos ($DEC_CENTER)
+  set stars_dec = $DEC_CENTER + $DEC_RANGE * (rnd(tmp) - 0.5) / 3600
+  set stars_mag = 15.0 + 4.0 * rnd(tmp) 
+
+  # stars_ra,dec,mag are the true positions and mags of the stars
+end
Index: trunk/Ohana/src/libautocode/def/secfilt-ps1-v4.d
===================================================================
--- trunk/Ohana/src/libautocode/def/secfilt-ps1-v4.d	(revision 34615)
+++ trunk/Ohana/src/libautocode/def/secfilt-ps1-v4.d	(revision 34620)
@@ -6,21 +6,20 @@
 
 # elements of data structure / FITS table
-FIELD  M,     	    MAG,      	   float,      average mag in this band,              mags
-FIELD  Map,    	    MAG_AP,    	   float,      ave aperture mag in this band,         mags
-FIELD  Mkron,  	    MAG_KRON,  	   float,      ave kron mag in this band,             mags
-FIELD  dMkron, 	    MAG_KRON_ERR,  float,      formal error on average kron mag,      mags
-FIELD  dM,    	    MAG_ERR,  	   float,      formal error on average mag,           mags
-FIELD  Xm,    	    MAG_CHI,  	   float,      chisq on average mag,                  [100*log(value)]
-FIELD  FluxPSF,     FLUX_PSF,      float,      mean flux psf fit (PS1: stack)
-FIELD  dFluxPSF,    FLUX_PSF_ERR,  float,      mean flux psf error
-FIELD  FluxKron,    FLUX_KRON,     float,      mean flux kron ap (PS1: stack)
-FIELD  dFluxKron,   FLUX_KRON_ERR, float,      mean flux kron err
-FIELD  flags, 	    FLAGS,    	   uint32_t,   photometry flags
-FIELD  Ncode, 	    NCODE,    	   short,      number of detections in band
-FIELD  Nused, 	    NUSED,    	   short,      number of detections used in average
-FIELD  M_20,  	    MAG_20,   	   short,      lower 20percent mag,                   millimags
-FIELD  M_80,  	    MAG_80,   	   short,      upper 20percent mag,                   millimags
-FIELD  ubercalDist, UBERCAL_DIST,  short,      number of images from an ubercal-image
-FIELD  Mstdev,      MAG_STDEV,     short,      standard deviation of measurements,    millimags
-FIELD  stackID,     STACK_ID,      uint32_t,   image ID of stack used for fluxes (if any)
-FIELD  dummy,       DUMMY,         uint32_t,   padding
+FIELD  M,             MAG,             float,      average mag in this band,              mags
+FIELD  Map,           MAG_AP,          float,      ave aperture mag in this band,         mags
+FIELD  Mkron,         MAG_KRON,        float,      ave kron mag in this band,             mags
+FIELD  dMkron,        MAG_KRON_ERR,    float,      formal error on average kron mag,      mags
+FIELD  dM,            MAG_ERR,         float,      formal error on average mag,           mags
+FIELD  Xm,            MAG_CHI,         float,      chisq on average mag,                  [100*log(value)]
+FIELD  FluxPSF,       FLUX_PSF,        float,      mean flux psf fit (PS1: stack)
+FIELD  dFluxPSF,      FLUX_PSF_ERR,    float,      mean flux psf error
+FIELD  FluxKron,      FLUX_KRON,       float,      mean flux kron ap (PS1: stack)
+FIELD  dFluxKron,     FLUX_KRON_ERR,   float,      mean flux kron err
+FIELD  flags,         FLAGS,           uint32_t,   photometry flags
+FIELD  Ncode,         NCODE,           short,      number of detections in band
+FIELD  Nused,         NUSED,           short,      number of detections used in average
+FIELD  M_20,          MAG_20,          short,      lower 20percent mag,                   millimags
+FIELD  M_80,          MAG_80,          short,      upper 20percent mag,                   millimags
+FIELD  ubercalDist,   UBERCAL_DIST,    short,      number of images from an ubercal-image
+FIELD  Mstdev,        MAG_STDEV,       short,      standard deviation of measurements,    millimags
+FIELD  stackDetectID, STACK_DETECT_ID, uint64_t,   detection ID on stack used for fluxes (if any)
Index: trunk/Ohana/src/libautocode/def/secfilt.d
===================================================================
--- trunk/Ohana/src/libautocode/def/secfilt.d	(revision 34615)
+++ trunk/Ohana/src/libautocode/def/secfilt.d	(revision 34620)
@@ -6,23 +6,22 @@
 
 # elements of data structure / FITS table
-FIELD  M,     	    MAG,      	   float,      average mag in this band,              mags
-FIELD  Map,    	    MAG,      	   float,      average mag in this band,              mags
-FIELD  Mkron,  	    MAG_KRON,  	   float,      ave kron mag in this band,             mags
-FIELD  dMkron, 	    MAG_KRON_ERR,  float,      formal error on average kron mag,      mags
-FIELD  dM,    	    MAG_ERR,  	   float,      formal error on average mag,           mags
-FIELD  Xm,    	    MAG_CHI,  	   float,      chisq on average mag,                  [100*log(value)]
-FIELD  FluxPSF,     FLUX_PSF,      float,      mean flux psf fit (PS1: stack)
-FIELD  dFluxPSF,    FLUX_PSF_ERR,  float,      mean flux psf error
-FIELD  FluxKron,    FLUX_KRON,     float,      mean flux kron ap (PS1: stack)
-FIELD  dFluxKron,   FLUX_KRON_ERR, float,      mean flux kron err
-FIELD  flags, 	    FLAGS,    	   uint32_t,   photometry flags
-FIELD  Ncode, 	    NCODE,    	   short,      number of detections in band
-FIELD  Nused, 	    NUSED,    	   short,      number of detections used in average
-FIELD  M_20,  	    MAG_20,   	   short,      lower 20percent mag,                   millimags
-FIELD  M_80,  	    MAG_80,   	   short,      upper 20percent mag,                   millimags
-FIELD  ubercalDist, UBERCAL_DIST,  short,      number of images from an ubercal-image
-FIELD  Mstdev,      MAG_STDEV,     short,      standard deviation of measurements,    millimags
-FIELD  stackID,     STACK_ID,      uint32_t,   image ID of stack used for fluxes (if any)
-FIELD  dummy,       DUMMY,         uint32_t,   padding
+FIELD  M,             MAG,             float,      average mag in this band,              mags
+FIELD  Map,           MAG,             float,      average mag in this band,              mags
+FIELD  Mkron,         MAG_KRON,        float,      ave kron mag in this band,             mags
+FIELD  dMkron,        MAG_KRON_ERR,    float,      formal error on average kron mag,      mags
+FIELD  dM,            MAG_ERR,         float,      formal error on average mag,           mags
+FIELD  Xm,            MAG_CHI,         float,      chisq on average mag,                  [100*log(value)]
+FIELD  FluxPSF,       FLUX_PSF,        float,      mean flux psf fit (PS1: stack)
+FIELD  dFluxPSF,      FLUX_PSF_ERR,    float,      mean flux psf error
+FIELD  FluxKron,      FLUX_KRON,       float,      mean flux kron ap (PS1: stack)
+FIELD  dFluxKron,     FLUX_KRON_ERR,   float,      mean flux kron err
+FIELD  flags,         FLAGS,           uint32_t,   photometry flags
+FIELD  Ncode,         NCODE,           short,      number of detections in band
+FIELD  Nused,         NUSED,           short,      number of detections used in average
+FIELD  M_20,          MAG_20,          short,      lower 20percent mag,                   millimags
+FIELD  M_80,          MAG_80,          short,      upper 20percent mag,                   millimags
+FIELD  ubercalDist,   UBERCAL_DIST,    short,      number of images from an ubercal-image
+FIELD  Mstdev,        MAG_STDEV,       short,      standard deviation of measurements,    millimags
+FIELD  stackDetectID, STACK_DETECT_ID, uint64_t,   detection ID on stack used for fluxes (if any)
 
 # *** 20090206 : new fields : M_20, M_80; dropped dummy
Index: trunk/Ohana/src/libdvo/include/dvodb.h
===================================================================
--- trunk/Ohana/src/libdvo/include/dvodb.h	(revision 34615)
+++ trunk/Ohana/src/libdvo/include/dvodb.h	(revision 34620)
@@ -45,5 +45,5 @@
       MAG_80, 
       MAG_UC_DIST, 
-      MAG_STACK_ID, 
+      MAG_STACK_DET_ID, 
       MAG_FLUX_PSF,
       MAG_FLUX_PSF_ERR,
Index: trunk/Ohana/src/libdvo/src/dbExtractAverages.c
===================================================================
--- trunk/Ohana/src/libdvo/src/dbExtractAverages.c	(revision 34615)
+++ trunk/Ohana/src/libdvo/src/dbExtractAverages.c	(revision 34620)
@@ -242,5 +242,5 @@
 	  value.Flt = PhotUCdist (field->photcode, average, secfilt);
 	  break;
-	case MAG_STACK_ID:
+	case MAG_STACK_DET_ID:
 	  value.Int = PhotStackID (field->photcode, average, secfilt);
 	  break;
Index: trunk/Ohana/src/libdvo/src/dbFields.c
===================================================================
--- trunk/Ohana/src/libdvo/src/dbFields.c	(revision 34615)
+++ trunk/Ohana/src/libdvo/src/dbFields.c	(revision 34620)
@@ -56,5 +56,5 @@
   if (!strcasecmp (string, "80"))          return (MAG_80);
   if (!strcasecmp (string, "ucdist"))      return (MAG_UC_DIST);
-  if (!strcasecmp (string, "stackID"))     return (MAG_STACK_ID);
+  if (!strcasecmp (string, "stackDetectID")) return (MAG_STACK_DET_ID);
   if (!strcasecmp (string, "fluxpsf"))     return (MAG_FLUX_PSF);
   if (!strcasecmp (string, "fluxpsferr"))  return (MAG_FLUX_PSF_ERR);
@@ -260,5 +260,5 @@
   field->magMode = mode;
   switch (mode) {
-    case MAG_STACK_ID:
+    case MAG_STACK_DET_ID:
     case MAG_NCODE:
     case MAG_NPHOT:
@@ -351,5 +351,5 @@
   field->magMode = mode;
   switch (mode) {
-    case MAG_STACK_ID:
+    case MAG_STACK_DET_ID:
     case MAG_NCODE:
     case MAG_NPHOT:
Index: trunk/Ohana/src/libdvo/src/dvo_catalog.c
===================================================================
--- trunk/Ohana/src/libdvo/src/dvo_catalog.c	(revision 34615)
+++ trunk/Ohana/src/libdvo/src/dvo_catalog.c	(revision 34620)
@@ -134,7 +134,5 @@
   secfilt->ubercalDist = 1000;
   secfilt->Mstdev      = NAN_S_SHORT;
-  secfilt->stackID     = 0;
-
-  secfilt->dummy       = 0;
+  secfilt->stackDetectID     = 0;
 }
 
Index: trunk/Ohana/src/libdvo/src/dvo_convert_PS1_DEV_1.c
===================================================================
--- trunk/Ohana/src/libdvo/src/dvo_convert_PS1_DEV_1.c	(revision 34615)
+++ trunk/Ohana/src/libdvo/src/dvo_convert_PS1_DEV_1.c	(revision 34620)
@@ -235,5 +235,5 @@
     out[i].FluxKron    = NAN;
     out[i].dFluxKron   = NAN;
-    out[i].stackID     = 0;
+    out[i].stackDetectID     = 0;
  }
   return (out);
Index: trunk/Ohana/src/libdvo/src/dvo_convert_PS1_DEV_2.c
===================================================================
--- trunk/Ohana/src/libdvo/src/dvo_convert_PS1_DEV_2.c	(revision 34615)
+++ trunk/Ohana/src/libdvo/src/dvo_convert_PS1_DEV_2.c	(revision 34620)
@@ -229,5 +229,5 @@
     out[i].FluxKron    = NAN;
     out[i].dFluxKron   = NAN;
-    out[i].stackID     = 0;
+    out[i].stackDetectID     = 0;
  }
   return (out);
Index: trunk/Ohana/src/libdvo/src/dvo_convert_PS1_REF.c
===================================================================
--- trunk/Ohana/src/libdvo/src/dvo_convert_PS1_REF.c	(revision 34615)
+++ trunk/Ohana/src/libdvo/src/dvo_convert_PS1_REF.c	(revision 34620)
@@ -190,5 +190,5 @@
     out[i].FluxKron    = NAN;
     out[i].dFluxKron   = NAN;
-    out[i].stackID     = 0;
+    out[i].stackDetectID     = 0;
  }
   return (out);
Index: trunk/Ohana/src/libdvo/src/dvo_convert_PS1_V1.c
===================================================================
--- trunk/Ohana/src/libdvo/src/dvo_convert_PS1_V1.c	(revision 34615)
+++ trunk/Ohana/src/libdvo/src/dvo_convert_PS1_V1.c	(revision 34620)
@@ -233,5 +233,5 @@
     out[i].FluxKron    = NAN;
     out[i].dFluxKron   = NAN;
-    out[i].stackID     = 0;
+    out[i].stackDetectID     = 0;
  }
   return (out);
Index: trunk/Ohana/src/libdvo/src/dvo_convert_PS1_V2.c
===================================================================
--- trunk/Ohana/src/libdvo/src/dvo_convert_PS1_V2.c	(revision 34615)
+++ trunk/Ohana/src/libdvo/src/dvo_convert_PS1_V2.c	(revision 34620)
@@ -236,5 +236,5 @@
     out[i].FluxKron    = NAN;
     out[i].dFluxKron   = NAN;
-    out[i].stackID     = 0;
+    out[i].stackDetectID     = 0;
  }
   return (out);
Index: trunk/Ohana/src/libdvo/src/dvo_convert_PS1_V3.c
===================================================================
--- trunk/Ohana/src/libdvo/src/dvo_convert_PS1_V3.c	(revision 34615)
+++ trunk/Ohana/src/libdvo/src/dvo_convert_PS1_V3.c	(revision 34620)
@@ -234,5 +234,5 @@
     out[i].FluxKron    = NAN;
     out[i].dFluxKron   = NAN;
-    out[i].stackID     = 0;
+    out[i].stackDetectID     = 0;
  }
   return (out);
Index: trunk/Ohana/src/libdvo/src/dvo_convert_PS1_V4.c
===================================================================
--- trunk/Ohana/src/libdvo/src/dvo_convert_PS1_V4.c	(revision 34615)
+++ trunk/Ohana/src/libdvo/src/dvo_convert_PS1_V4.c	(revision 34620)
@@ -221,22 +221,22 @@
 
   for (i = 0; i < Nvalues; i++) {
-    out[i].M           = in[i].M;      
-    out[i].Map         = in[i].Map;      
-    out[i].Mkron       = in[i].Mkron;      
-    out[i].dMkron      = in[i].dMkron;      
-    out[i].dM          = in[i].dM;      
-    out[i].Xm          = in[i].Xm;     
-    out[i].FluxPSF     = in[i].FluxPSF;
-    out[i].dFluxPSF    = in[i].dFluxPSF;
-    out[i].FluxKron    = in[i].FluxKron;
-    out[i].dFluxKron   = in[i].dFluxKron;
-    out[i].flags       = in[i].flags;     
-    out[i].Ncode       = in[i].Ncode;
-    out[i].Nused       = in[i].Nused;
-    out[i].M_20        = in[i].M_20;      
-    out[i].M_80        = in[i].M_80;      
-    out[i].Mstdev      = in[i].Mstdev;      
-    out[i].ubercalDist = in[i].ubercalDist;      
-    out[i].stackID     = in[i].stackID;      
+    out[i].M             = in[i].M;      
+    out[i].Map           = in[i].Map;      
+    out[i].Mkron         = in[i].Mkron;      
+    out[i].dMkron        = in[i].dMkron;      
+    out[i].dM            = in[i].dM;      
+    out[i].Xm            = in[i].Xm;     
+    out[i].FluxPSF       = in[i].FluxPSF;
+    out[i].dFluxPSF      = in[i].dFluxPSF;
+    out[i].FluxKron      = in[i].FluxKron;
+    out[i].dFluxKron     = in[i].dFluxKron;
+    out[i].flags         = in[i].flags;     
+    out[i].Ncode         = in[i].Ncode;
+    out[i].Nused         = in[i].Nused;
+    out[i].M_20          = in[i].M_20;      
+    out[i].M_80          = in[i].M_80;      
+    out[i].Mstdev        = in[i].Mstdev;      
+    out[i].ubercalDist   = in[i].ubercalDist;      
+    out[i].stackDetectID = in[i].stackDetectID;      
  }
   return (out);
@@ -251,22 +251,22 @@
 
   for (i = 0; i < Nvalues; i++) {
-    out[i].M           = in[i].M;      
-    out[i].Map         = in[i].Map;      
-    out[i].Mkron       = in[i].Mkron;      
-    out[i].dMkron      = in[i].dMkron;      
-    out[i].dM          = in[i].dM;      
-    out[i].Xm          = in[i].Xm;     
-    out[i].FluxPSF     = in[i].FluxPSF;
-    out[i].dFluxPSF    = in[i].dFluxPSF;
-    out[i].FluxKron    = in[i].FluxKron;
-    out[i].dFluxKron   = in[i].dFluxKron;
-    out[i].flags       = in[i].flags;     
-    out[i].Ncode       = in[i].Ncode;
-    out[i].Nused       = in[i].Nused;
-    out[i].M_20        = in[i].M_20;      
-    out[i].M_80        = in[i].M_80;      
-    out[i].Mstdev      = in[i].Mstdev;      
-    out[i].ubercalDist = in[i].ubercalDist;      
-    out[i].stackID     = in[i].stackID;      
+    out[i].M           	 = in[i].M;      
+    out[i].Map         	 = in[i].Map;      
+    out[i].Mkron       	 = in[i].Mkron;      
+    out[i].dMkron      	 = in[i].dMkron;      
+    out[i].dM          	 = in[i].dM;      
+    out[i].Xm          	 = in[i].Xm;     
+    out[i].FluxPSF     	 = in[i].FluxPSF;
+    out[i].dFluxPSF    	 = in[i].dFluxPSF;
+    out[i].FluxKron    	 = in[i].FluxKron;
+    out[i].dFluxKron   	 = in[i].dFluxKron;
+    out[i].flags       	 = in[i].flags;     
+    out[i].Ncode       	 = in[i].Ncode;
+    out[i].Nused       	 = in[i].Nused;
+    out[i].M_20        	 = in[i].M_20;      
+    out[i].M_80        	 = in[i].M_80;      
+    out[i].Mstdev      	 = in[i].Mstdev;      
+    out[i].ubercalDist 	 = in[i].ubercalDist;      
+    out[i].stackDetectID = in[i].stackDetectID;
   }
   return (out);
Index: trunk/Ohana/src/libdvo/src/dvo_convert_elixir.c
===================================================================
--- trunk/Ohana/src/libdvo/src/dvo_convert_elixir.c	(revision 34615)
+++ trunk/Ohana/src/libdvo/src/dvo_convert_elixir.c	(revision 34620)
@@ -244,5 +244,5 @@
     out[i].FluxKron   = NAN;
     out[i].dFluxKron  = NAN;
-    out[i].stackID     = 0;
+    out[i].stackDetectID     = 0;
   }
   return (out);
Index: trunk/Ohana/src/libdvo/src/dvo_convert_loneos.c
===================================================================
--- trunk/Ohana/src/libdvo/src/dvo_convert_loneos.c	(revision 34615)
+++ trunk/Ohana/src/libdvo/src/dvo_convert_loneos.c	(revision 34620)
@@ -237,5 +237,5 @@
     out[i].FluxKron   = NAN;
     out[i].dFluxKron  = NAN;
-    out[i].stackID     = 0;
+    out[i].stackDetectID     = 0;
   }
   return (out);
Index: trunk/Ohana/src/libdvo/src/dvo_convert_panstarrs_DEV_0.c
===================================================================
--- trunk/Ohana/src/libdvo/src/dvo_convert_panstarrs_DEV_0.c	(revision 34615)
+++ trunk/Ohana/src/libdvo/src/dvo_convert_panstarrs_DEV_0.c	(revision 34620)
@@ -244,5 +244,5 @@
     out[i].FluxKron    = NAN;
     out[i].dFluxKron   = NAN;
-    out[i].stackID     = 0;
+    out[i].stackDetectID     = 0;
  }
   return (out);
Index: trunk/Ohana/src/libdvo/src/dvo_convert_panstarrs_DEV_1.c
===================================================================
--- trunk/Ohana/src/libdvo/src/dvo_convert_panstarrs_DEV_1.c	(revision 34615)
+++ trunk/Ohana/src/libdvo/src/dvo_convert_panstarrs_DEV_1.c	(revision 34620)
@@ -244,5 +244,5 @@
     out[i].FluxKron    = NAN;
     out[i].dFluxKron   = NAN;
-    out[i].stackID     = 0;
+    out[i].stackDetectID     = 0;
  }
   return (out);
Index: trunk/Ohana/src/libdvo/src/dvo_photcode_ops.c
===================================================================
--- trunk/Ohana/src/libdvo/src/dvo_photcode_ops.c	(revision 34615)
+++ trunk/Ohana/src/libdvo/src/dvo_photcode_ops.c	(revision 34620)
@@ -664,5 +664,5 @@
 
   Ns = photcodes[0].hashNsec[code[0].code];
-  ID = (Ns == -1) ? 0 : secfilt[Ns].stackID;
+  ID = (Ns == -1) ? 0 : secfilt[Ns].stackDetectID;
   return (ID);
 }
