Index: /branches/eam_branches/ipp-20111122/Ohana/src/addstar/src/mkcmf.c
===================================================================
--- /branches/eam_branches/ipp-20111122/Ohana/src/addstar/src/mkcmf.c	(revision 33137)
+++ /branches/eam_branches/ipp-20111122/Ohana/src/addstar/src/mkcmf.c	(revision 33138)
@@ -74,4 +74,24 @@
   }
 
+  double CRPIX1 = 0.0;
+  double CRPIX2 = 0.0;
+  if ((N = get_argument (argc, argv, "-crpix"))) {
+    remove_argument (N, &argc, argv);
+    CRPIX1 = atof (argv[N]);
+    remove_argument (N, &argc, argv);
+    CRPIX2 = atof (argv[N]);
+    remove_argument (N, &argc, argv);
+  }
+
+  int NX = 0;
+  int NY = 0;
+  if ((N = get_argument (argc, argv, "-size"))) {
+    remove_argument (N, &argc, argv);
+    NX = atof (argv[N]);
+    remove_argument (N, &argc, argv);
+    NY = atof (argv[N]);
+    remove_argument (N, &argc, argv);
+  }
+
   // add support for all cmf types
   static char *type = "PS1_V2";
@@ -105,6 +125,6 @@
   coords.crval1 = RA;
   coords.crval2 = DEC;
-  coords.crpix1 = 0.0;
-  coords.crpix2 = 0.0;
+  coords.crpix1 = CRPIX1;
+  coords.crpix2 = CRPIX2;
   
   coords.cdelt1 = 0.25/3600.0;
@@ -157,4 +177,8 @@
     Nstars ++;
   }
+  if (NX && NY) {
+      Xmax = NX;
+      Ymax = NY;
+  }
 
   // create primary header
@@ -166,6 +190,6 @@
 
   // 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_print (&header, "IMNAXIS1", "%d", 1, (int)(Xmax));
+  gfits_print (&header, "IMNAXIS2", "%d", 1, (int)(Ymax));
 
   gfits_modify (&header, "NSTARS",   "%d", 1, Nstars);
Index: /branches/eam_branches/ipp-20111122/Ohana/src/addstar/test/relphot.flatcorr.dvo
===================================================================
--- /branches/eam_branches/ipp-20111122/Ohana/src/addstar/test/relphot.flatcorr.dvo	(revision 33137)
+++ /branches/eam_branches/ipp-20111122/Ohana/src/addstar/test/relphot.flatcorr.dvo	(revision 33138)
@@ -69,4 +69,11 @@
 
 macro go
+  if ($0 != 3)
+    echo "go (fileroot) (catdir)"
+    break
+  end
+
+  exec rm -rf $2
+
   init
   mkzptfile
@@ -74,10 +81,30 @@
 
   mkdir testdata
-  mksequence testdata/t1
+  mksequence $1 $2
+end
+
+macro ckexposure
+
+  # assume we still have stars_ra, stars_dec, stars_mag in hand
+  catdir catdir.test
+  region $RA_CENTER $DEC_CENTER 0.2
+  images
+  pmeasure -all -m 15 20
+  mextract -region ra dec mag
+ 
+  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
+  lim mag dm; clear; box; plot mag dm
 end
 
 macro mksequence
-  if ($0 != 2)
-    echo "mksequence (fileroot)"
+  if ($0 != 3)
+    echo "mksequence (fileroot) (catdir)"
     break
   end
@@ -86,12 +113,13 @@
 
   # we have defined a set of images by mjd and zero point
-  for i 0 mjd[]
-    mkexposure $1.$i $RA_CENTER $DEC_CENTER zpt[$i] mjd[$i] g
+  # for i 0 mjd[]
+  for i 0 1
+    mkexposure $1.$i $RA_CENTER $DEC_CENTER zpt[$i] mjd[$i] g $2
   end
 end
 
 macro mkexposure
- if ($0 != 7)
-   echo "mkexposure (fileroot) (ra) (dec) (zpt) (mjd) (filter)"
+ if ($0 != 8)
+   echo "mkexposure (fileroot) (ra) (dec) (zpt) (mjd) (filter) (catdir)"
    break
  end
@@ -119,14 +147,12 @@
     $ra  = $RAo  - $dx / 3600.0 / dcos($DECo)
     $dec = $DECo - $dy / 3600.0
+    echo $ra $dec $dx $dy
     mkinput test.in.txt $ra $dec $ZPT
-
-    # make a GPC1-style chip
-    # XX exec mkcmf test.in.txt $ROOT.$ix.$iy.cmf -date $date -time $time -radec $ra $dec -type PS1_V2 -coords -photcode GPC1.$FILTER.XY$ix\$iy
-    # XX echo mkcmf test.in.txt $ROOT.$ix.$iy.cmf -date $date -time $time -radec $ra $dec -type PS1_V2 -coords -photcode GPC1.$FILTER.XY$ix\$iy
-
-    exec mkcmf test.in.txt $ROOT.$ix.$iy.cmf -mjd $MJD -radec $ra $dec -type PS1_V2 -coords -photcode GPC1.$FILTER.XY$ix\$iy -no-noise
-    echo mkcmf test.in.txt $ROOT.$ix.$iy.cmf -mjd $MJD -radec $ra $dec -type PS1_V2 -coords -photcode GPC1.$FILTER.XY$ix\$iy -no-noise
     
-    exec addstar $ROOT.$ix.$iy.cmf -D CATDIR catdir.test -D CAMERA gpc1
+    # ra,dec is the center of this chip
+    exec mkcmf test.in.txt $ROOT.$ix.$iy.cmf -mjd $MJD -radec $ra $dec -type PS1_V2 -coords -photcode GPC1.$FILTER.XY$ix\$iy -no-noise -size $CHIP_DX $CHIP_DY -crpix {0.5*$CHIP_DX} {0.5*$CHIP_DY} 
+    echo mkcmf test.in.txt $ROOT.$ix.$iy.cmf -mjd $MJD -radec $ra $dec -type PS1_V2 -coords -photcode GPC1.$FILTER.XY$ix\$iy -no-noise -size $CHIP_DX $CHIP_DY -crpix {0.5*$CHIP_DX} {0.5*$CHIP_DY} 
+    
+    exec addstar $ROOT.$ix.$iy.cmf -D CATDIR $7 -D CAMERA gpc1
   end
  end
@@ -141,6 +167,7 @@
 
   # chip coordinate of the stars
-  set stars_X = (stars_ra  - $2) * 3600.0 * dcos($3) / $PLATE_SCALE
-  set stars_Y = (stars_dec - $3) * 3600.0 / $PLATE_SCALE
+  # 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)
 
@@ -213,5 +240,5 @@
   # create 9 exposures, 3 per season
   create imageID 0 9
-  set zpt = imageID*0.0050 - 0.0025
+  set zpt = 25.0 + imageID*0.0050 - 0.0025
   set mjd = zero(zpt)
   mjd[0] = 55000.01
