Index: /branches/czw_branch/cleanup/ppMops/ICDlite.txt
===================================================================
--- /branches/czw_branch/cleanup/ppMops/ICDlite.txt	(revision 25154)
+++ /branches/czw_branch/cleanup/ppMops/ICDlite.txt	(revision 25154)
@@ -0,0 +1,150 @@
+== General notes ==
+
+Though efforts have been made to avoid this from occurring, where
+header keyword names are longer than the usual 8 character maximum,
+the HIERARCH convention will be used.
+
+Celestial coordinates are in ICRS.
+
+Magnitudes are AB magnitudes (flux zero point is 3631 Jy).
+
+Unless otherwise noted, error values are statistical only, and include
+no contribution by systematic errors.
+
+== Primary header ==
+
+The primary header will not contain any information beyond that
+written automatically by cfitsio, and is present only for compliance
+with the FITS standard.
+
+== FITS table ==
+
+The FITS table will include all detections within an exposure.
+
+Duplicates from overlapping skycells will have been filtered out by
+IPP, with the measurements from the source closest to the centre of a
+skycell included (and all others discarded).
+
+=== Header ===
+
+The header will contain information relevant to the exposure as a whole.
+
+ * Version information
+  * SWSOURCE (string): source of software (e.g., "60eb6cdc-a59c-4636-a4e0-dba66a9721fd")
+  * SWVERSN (string): version of software (e.g., "trunk/ppMops@24658")
+
+ * Provenance information
+  * EXP_NAME (string): Exposure name (e.g., "o1234g5678")
+  * EXP_ID (S64): Exposure identifier
+  * CHIP_ID (S64): Chip stage identifier
+  * CAM_ID (S64): Camera stage identifier
+  * FAKE_ID (S64): Fake stage identifier
+  * WARP_ID (S64): Warp stage identifier
+  * DIFF_ID (S64): Diff stage identifier
+  * DIFF_POS (boolean): Sense of subtraction; T for forward, F for backward
+
+ * Exposure details
+  * MJD-OBS (F64): TAI MJD of exposure mid-point
+  * RA (string): Reported Right Ascension of telescope boresight, sexagesimal hours (e.g., "12:34:56.789")
+  * DEC (string): Reported Declination of telescope boresight, sexagesimal degrees (e.g., "-12:34:56.78")
+  * TEL_ALT (F64): Reported telescope altitude, degrees
+  * TEL_AZ (F64): Reported telescope azimuth, degrees
+  * EXPTIME (F32): Exposure time, seconds
+  * ROTANGLE (F64): Rotator angle, degrees
+  * FILTER (string): Filter name (e.g., "r.00000")
+  * AIRMASS (F32): Airmass for exposure
+  * OBSCODE (string): IAU observatory code (i.e., "F51" for PS1)
+  * SEEING (F32): Measured seeing at diff stage, arcsec
+  * MAGZP (F32): Magnitude zero point
+  * MAGZPERR (F32): Error in magnitude zero point
+  * ASTRORMS (F32): RMS of astrometric fit, arcsec
+
+ * Detection efficiency
+  * DE_MAGnn (F32): Magnitude (calibrated) for detection efficiency
+  * DE_EFFnn (F32): Detection efficiency (0..1)
+
+==== Current limitations ====
+
+The IPP is not yet calculating detection efficiencies (it is still
+being developed).  Further, it is not yet clear how to merge the
+detection efficiency measurements for different skycells.  Until these
+issues are resolved, the detection efficiency values will be fake.
+
+==== Differences from original ICD ====
+
+ * SWSOURCE, SWVERSN has replaced TABLEVER which was never defined
+ * All of the "Provenance information" has replaced FPA_ID, for better tracking of the source of each detection
+ * SEEING and MAGZP added as indicators of the quality of the exposure
+ * MAGZPERR added to make absolute (i.e., across exposures) magnitude errors more accurate
+ * ASTRORMS added to make absolute (i.e., across exposures) astrometry errors more accurate
+ * DE_MAGnn and DE_EFFnn replace DE1 through DE10, which were never well defined
+
+=== Table ===
+
+The table will contain information relevant to the individual
+detections within the exposure.
+
+ * RA (F64): Right Ascension of detection centre, degrees
+ * RA_ERR (F64): Error in RA, degrees
+ * DEC (F64): Declination of detection centre, degrees
+ * DEC_ERR (F64): Error in DEC, degrees
+ * MAG (F32): Calibrated magnitude of detection
+ * MAG_ERR (F32): Error in MAG
+ * STARPSF (F32): A PSF/extended source separator
+ * ANGLE (F64): Angle of trail fit to source, degrees E of N
+ * ANGLE_ERR (F64): Error in ANGLE, degrees
+ * LENGTH (F32): Length of trail fit to source, degrees
+ * LENGTH_ERR (F32): Error in LENGTH, degrees
+ * FLAGS (S32): IPP detection flags, bit mask
+ * DIFF_SKYFILE_ID (S64): IPP diff_skyfile_id for source
+
+==== Current limitations ====
+
+The IPP is not yet fitting trails to sources in the difference images.
+Until this is being done, the ANGLE, ANGLE_ERR, LENGTH and LENGTH_ERR
+values will be zero.
+
+The value being written as STARPSF is EXT_NSIGMA from the IPP CMF
+files; it is not clear that this is what MOPS wants, but this is
+probably irrelevant until the trail fitting has been implemented.
+
+==== Differences from original ICD ====
+
+ * RA_DEG, DEC_DEG renamed RA, DEC to match apparent naming policy
+ * *_SIG renamed *_ERR to be more clear
+ * ANG, ANG_SIG, LEN, LEN_SIG spelled out as ANGLE, ANGLE_ERR, LENGTH, LENGTH_ERR
+ * FLUX, FLUX_SIG renamed MAG, MAG_ERR since IPP writes magnitudes
+ * FLAGS added to allow additional weeding out of bad detections
+ * DIFF_SKYFILE_ID added to allow trace back to IPP diff skyfile, for postage stamps
+
+
+
+
+                            Table 3: IPP-MOPS Transient Detection Keywords
+FITS Keyword      Precision                     Description
+FPA ID            char(20)                      IPP-assigned identifier that can be used to trace back to this FPA
+MJD-OBS           F64                           midpoint time of the exposure as a MJD and day fraction
+RA                HH:MM:SS.SSS                 field center RA at exposure midpoint, string
+DEC               sDD:MM:SS (s is + or -) field center declination at exposure midpoint, string
+EXPTIME           F64                          exposure time in seconds
+ROTANGLE          F64                          image rotation of the y-axis in degrees, from local N toward E
+FILTER            char(3)                       effective filter used for the exposure, one of g, r, i, z, y, B, V, w
+AIRMASS           F64                          airmass at exposure midpoint
+LIMITMAG          F64                           limiting magnitude of detections for this FPA
+DE1 through DE10  F64                           detection efficiency coefficients
+OBSCODE           char(5)                       MPC three-character observatory code
+TEL ALT           F64                          telescope altitude at exposure midpoint, in degrees
+TEL AZ            F64                          telescope azimuth at exposure midpoint, in degrees
+                         Table 4: IPP-MOPS Transient Detection Table Columns
+             Column       Precision Description
+             RA DEG       F64          detection center coordinates in degrees
+             RA SIG       F64          error in the detection center, in degrees
+             DEC DEG      F64          detection center coordinates in degrees
+             DEC SIG      F64          error in the detection center, in degrees
+             FLUX         F64          flux
+             FLUX SIG     F64          error in the flux value
+             STARPSF      F64          probability that the PSF matches a starlike PSF
+             ANG          F64          detectionâs elongation angle in degrees, local N toward E
+             ANG SIG      F64          error in the angle, in degrees
+             LEN          F64          elongation length of the detection in degrees
+             LEN SIG      F64          error in the length, in degrees
Index: /branches/czw_branch/cleanup/ppMops/src/ppMops.c
===================================================================
--- /branches/czw_branch/cleanup/ppMops/src/ppMops.c	(revision 25153)
+++ /branches/czw_branch/cleanup/ppMops/src/ppMops.c	(revision 25154)
@@ -6,7 +6,7 @@
 int main(int argc, char *argv[])
 {
-    if (argc != 4) {
+    if (argc != 7) {
         fprintf(stderr, "Insufficient arguments.\n");
-        fprintf(stderr, "Usage: %s DETECTIONS ZP OUTPUT\n", argv[0]);
+        fprintf(stderr, "Usage: %s DETECTIONS ZP EXP_ID EXP_NAME DIRECTION OUTPUT\n", argv[0]);
         exit(PS_EXIT_CONFIG_ERROR);
     }
@@ -15,5 +15,8 @@
     data->detections = psStringCopy(argv[1]);
     data->zp = atof(argv[2]);
-    data->output = psStringCopy(argv[3]);
+    data->exp_id = atoll(argv[3]);
+    data->exp_name = psStringCopy(argv[4]);
+    data->direction = atoi(argv[5]);
+    data->output = psStringCopy(argv[6]);
 
     if (!isfinite(data->zp)) {
@@ -120,13 +123,9 @@
         double alt = psMetadataLookupF64(NULL, header, "FPA.ALT");
         double az = psMetadataLookupF64(NULL, header, "FPA.AZ");
-        int imageid = psMetadataLookupS32(NULL, header, "IMAGEID");
+        psS64 imageid = psMetadataLookupS64(NULL, header, "IMAGEID");
         double mjd = psMetadataLookupF64(NULL, header, "MJD-OBS") + exptime / 2.0 / 3600 / 24;
 
         float psf = plateScale * 0.5 * (psMetadataLookupF32(NULL, header, "FWHM_MAJ") +
                                         psMetadataLookupF32(NULL, header, "FWHM_MIN"));
-
-        // XXX This is wrong
-        int fpaid = psMetadataLookupS32(NULL, header, "IMAGEID");
-
 
         psMetadataAddStr(outHeader, PS_LIST_TAIL, "RA", 0, "Right ascension of boresight", ra);
@@ -139,11 +138,13 @@
         psMetadataAddF64(outHeader, PS_LIST_TAIL, "TEL_ALT", 0, "Telescope altitude", alt);
         psMetadataAddF64(outHeader, PS_LIST_TAIL, "TEL_AZ", 0, "Telescope azimuth", az);
-        psMetadataAddS32(outHeader, PS_LIST_TAIL, "DIFFIMID", 0, "Difference image identifier", imageid);
-        psMetadataAddS32(outHeader, PS_LIST_TAIL, "FPA_ID", 0, "Exposure identifier", fpaid);
+        psMetadataAddS64(outHeader, PS_LIST_TAIL, "DIFFIMID", 0, "Difference image identifier", imageid);
+        psMetadataAddStr(outHeader, PS_LIST_TAIL, "FPA_ID", 0, "Exposure name", data->exp_name);
+        psMetadataAddS64(outHeader, PS_LIST_TAIL, "EXP_ID", 0, "Exposure identifier", data->exp_id);
+        psMetadataAddBool(outHeader, PS_LIST_TAIL, "POSITIVE", 0, "Positive subtraction?", data->direction);
         psMetadataAddStr(outHeader, PS_LIST_TAIL, "OBSCODE", 0, "IAU Observatory code", OBSERVATORY_CODE);
         psMetadataAddF32(outHeader, PS_LIST_TAIL, "STARPSF", 0, "Stellar PSF (arcsec)", psf);
 
         // These are completely fake
-        psMetadataAddF32(outHeader, PS_LIST_TAIL, "LIMITMAG", 0, "Limiting magnitude (FAKE)", 25.0);
+        psMetadataAddF32(outHeader, PS_LIST_TAIL, "LIMITMAG", 0, "Limiting magnitude (FAKE)", 99.0);
         psMetadataAddF32(outHeader, PS_LIST_TAIL, "DE1", 0, "Detection efficiency (FAKE)", 0.0);
         psMetadataAddF32(outHeader, PS_LIST_TAIL, "DE2", 0, "Detection efficiency (FAKE)", 0.0);
Index: /branches/czw_branch/cleanup/ppMops/src/ppMops.h
===================================================================
--- /branches/czw_branch/cleanup/ppMops/src/ppMops.h	(revision 25153)
+++ /branches/czw_branch/cleanup/ppMops/src/ppMops.h	(revision 25154)
@@ -16,4 +16,5 @@
     psString detections;                // Detections filename
     float zp;                           // Magnitude zero point
+    bool direction;                     // Direction of subtraction, 1=positive, 0=negative
     psString output;                    // Output filename
 } ppMopsData;
