Index: trunk/pstamp/src/pstamp.h
===================================================================
--- trunk/pstamp/src/pstamp.h	(revision 17894)
+++ trunk/pstamp/src/pstamp.h	(revision 18243)
@@ -31,5 +31,10 @@
 } pspMode;
 
+#define PSTAMP_SELECT_IMAGE  1
+#define PSTAMP_SELECT_MASK   2
+#define PSTAMP_SELECT_WEIGHT 4
 
+#define PSTAMP_CENTER_IN_PIXELS 1
+#define PSTAMP_RANGE_IN_PIXELS  2
 
 #define STAMP_REQUEST_EXTNAME "PS1_PS_REQUEST"
Index: trunk/pstamp/src/pstampGetROI.c
===================================================================
--- trunk/pstamp/src/pstampGetROI.c	(revision 17894)
+++ trunk/pstamp/src/pstampGetROI.c	(revision 18243)
@@ -116,5 +116,10 @@
     }
 
-    if (!*gotCenter || !*gotRange) {
+    if (!*gotCenter) {
+        psError(PSTAMP_ERR_ARGUMENTS, true, "must specify center");
+        return false;
+    }
+    if (!*gotRange) {
+        psError(PSTAMP_ERR_ARGUMENTS, true, "must specify range for stamp");
         return false;
     }
Index: trunk/pstamp/src/pstampfinish.c
===================================================================
--- trunk/pstamp/src/pstampfinish.c	(revision 17894)
+++ trunk/pstamp/src/pstampfinish.c	(revision 18243)
@@ -118,5 +118,5 @@
     // XXX: need to select the database name based on the project name specified in the input
 
-    options->config->database = pmConfigDB(options->config);
+    options->config->database = psMemIncrRefCounter(pmConfigDB(options->config));
 
     if (!options->config->database) {
@@ -216,5 +216,5 @@
             if (pJob->result == 0) {
                 ++numStamps;
-                // XXX: should we check for existence?
+                // XXX: should we check for existence of the files?
                 psString stampName = getBaseName(pJob->outputBase, true);
                 psString inputName = getBaseName(pJob->uri, false);
Index: trunk/pstamp/src/pstampparse.c
===================================================================
--- trunk/pstamp/src/pstampparse.c	(revision 17894)
+++ trunk/pstamp/src/pstampparse.c	(revision 18243)
@@ -72,4 +72,6 @@
         options->mode = parseMode(argv[argnum]);
         psArgumentRemove(argnum, &argc, argv);
+    } else {
+        options->mode = PSP_MODE_LIST_JOB;
     }
 
@@ -82,4 +84,9 @@
         options->req_id = atol(argv[argnum]);
         psArgumentRemove(argnum, &argc, argv);
+    }
+
+    if ((options->mode == PSP_MODE_QUEUE_JOB) && (options->req_id <= 0)) {
+        psError(PS_ERR_UNKNOWN, true, "need request id in order to queue jobs\n");
+        return false;
     }
 
@@ -147,5 +154,5 @@
     // XXX: need to select the database name based on the project name specified in the input
 
-    options->config->database = pmConfigDB(options->config);
+    options->config->database = psMemIncrRefCounter(pmConfigDB(options->config));
 
     if (!options->config->database) {
@@ -215,5 +222,5 @@
     //
     //
-    // we return an array containing strins for the values
+    // we return an array containing strings for the values
 
     if (!p_psDBRunQuery(options->config->database, query, target, key1, key2)) {
@@ -264,6 +271,6 @@
 
     psStringAppend(&query, "SELECT %%s from %s WHERE %s = %%s", table, id_type);
-    // append class_id unless it is set to the special value "all"
-    if (class_id && strcmp("all", class_id)) {
+    // append class_id unless it is set to the special value "null"
+    if (class_id && strcmp("null", class_id)) {
         psStringAppend(&query, "%s", " and class_id = '%s'" );
     }
@@ -559,39 +566,43 @@
     bool status = false;;
     psString roiString = NULL;
-    psString ra = psMetadataLookupStr(&status, options->md, "RA");
-
-    if (ra != NULL) {
-        psString dec =  psMetadataLookupStr(&status, options->md, "DEC");
-        if (dec == NULL) {
-            psError(PS_ERR_UNKNOWN, true, "bad request file: RA specified without DEC");
-            return NULL;
-        }
-        psStringAppend(&roiString, "-skycenter %s %s", ra, dec);
+
+    psU32 coord_mask = psMetadataLookupU32(&status, options->md, "COORD_MASK");
+    if (!status) {
+        psError(PS_ERR_UNKNOWN, true, "bad request file: COORD_MASK not specified");
+        return NULL;
+    }
+
+    psString x = psMetadataLookupStr(&status, options->md, "CENTER_X");
+    if (x == NULL) {
+        psError(PS_ERR_UNKNOWN, true, "bad request file: CENTER_X not specified");
+        return NULL;
+    }
+    psString y = psMetadataLookupStr(&status, options->md, "CENTER_Y");
+    if (y == NULL) {
+        psError(PS_ERR_UNKNOWN, true, "bad request file: CENTER_Y not specified");
+        return NULL;
+    }
+
+    if (coord_mask & PSTAMP_CENTER_IN_PIXELS) {
+        psStringAppend(&roiString, "-pixcenter %s %s", x, y);
     } else {
-        psString x = psMetadataLookupStr(&status, options->md, "CENTER_X");
-        if (x == NULL) {
-            psError(PS_ERR_UNKNOWN, true, "bad request file: center not specified");
-            return NULL;
-        }
-        psString y = psMetadataLookupStr(&status, options->md, "CENTER_Y");
-        psStringAppend(&roiString, "-pixcenter %s %s", x, y);
-    }
-
-    psString d_ra = psMetadataLookupStr(&status, options->md, "D_RA");
-    if (d_ra != NULL) {
-        psString d_dec =  psMetadataLookupStr(&status, options->md, "D_DEC");
-        if (d_dec == NULL) {
-            psError(PS_ERR_UNKNOWN, true, "bad request file: D_RA specified without D_DEC");
-            return NULL;
-        }
-        psStringAppend(&roiString, " -arcrange %s %s", d_ra, d_dec);
+        psStringAppend(&roiString, "-skycenter %s %s", x, y);
+    }
+
+    psString w = psMetadataLookupStr(&status, options->md, "WIDTH");
+    if (w == NULL) {
+        psError(PS_ERR_UNKNOWN, true, "bad request file: WIDTH not specified");
+        return NULL;
+    }
+    psString h = psMetadataLookupStr(&status, options->md, "HEIGHT");
+    if (h == NULL) {
+        psError(PS_ERR_UNKNOWN, true, "bad request file: HEIGHT not specified");
+        return NULL;
+    }
+
+    if (coord_mask & PSTAMP_RANGE_IN_PIXELS) {
+        psStringAppend(&roiString, " -pixrange %s %s", w, h);
     } else {
-        psString w = psMetadataLookupStr(&status, options->md, "WIDTH");
-        if (w == NULL) {
-            psError(PS_ERR_UNKNOWN, true, "bad request file: range not specified");
-            return NULL;
-        }
-        psString h = psMetadataLookupStr(&status, options->md, "HEIGHT");
-        psStringAppend(&roiString, " -pixrange %s %s", w, h);
+        psStringAppend(&roiString, " -arcrange %s %s", w, h);
     }
 
@@ -636,5 +647,5 @@
 
 static bool
-queueJobs (pspOptions *options, psString job_type, psArray *uris, psString user_tag, psString commandArgs)
+queueJobs (pspOptions *options, psString job_type, psArray *uris, psString stamp_name, psString commandArgs)
 {
     int numURIs = psArrayLength(uris);
@@ -643,11 +654,11 @@
     if (numURIs == 1) {
         // use the user tag as the outputBase
-        status = queueOneJob(options, job_type, uris->data[0], user_tag, commandArgs);
+        status = queueOneJob(options, job_type, uris->data[0], stamp_name, commandArgs);
     } else {
         for (int i = 0; i< numURIs; i++) {
             psString outputBase = NULL;
 
-            // append an integer to the user_tag to get a uniqueu outputBase
-            psStringAppend(&outputBase, "%s_%d", user_tag, i);
+            // append an integer to the stamp_name to get a uniqueu outputBase
+            psStringAppend(&outputBase, "%s_%d", stamp_name, i);
 
             status = queueOneJob(options, job_type, uris->data[i], outputBase, commandArgs);
@@ -664,8 +675,8 @@
 
 static bool
-turnOffResultsFile(pspOptions *options)
+turnOnResultsFile(pspOptions *options)
 {
     // turn off the creation of a results file for this request
-    char * query = "UPDATE pstampRequest SET resultsFile = 0 WHERE req_id = %" PRId64;
+    char * query = "UPDATE pstampRequest SET resultsFile = 1 WHERE req_id = %" PRId64;
     return p_psDBRunQuery(options->config->database, query, options->req_id);
 }
@@ -678,8 +689,10 @@
     psString    img_type = psMetadataLookupStr(NULL, options->md, "IMG_TYPE");
 
+#ifdef notdef
     if (! turnOffResultsFile(options)) {
         fprintf(stderr, "failed to update resultsFile for request %" PRId64 "\n", options->req_id);
         return false;
     }
+#endif
 
     if (options->outputDirectory == NULL) {
@@ -716,32 +729,16 @@
 parseRequestTable(pspOptions *options)
 {
-    bool status;
+    bool status = false;
+
     psString job_type = psMetadataLookupStr(&status, options->md, "JOB_TYPE");
-
     if (job_type == NULL) {
-        // XXX: compatiabilty hack change to error at some point
-        job_type = "stamp";
-    }
-
-    psString cmd_mode = psMetadataLookupStr(&status, options->md, "CMD_MODE");
-
-    // if cmd_mode is set on the command line ignore the value in the request file
-    if (options->mode == PSP_MODE_UNKNOWN) {
-        if (cmd_mode != NULL) {
-            options->mode = parseMode(cmd_mode);
-        } else {
-            // default to listing the parameters of the job's that the request would queue
-            options->mode = PSP_MODE_LIST_JOB;
-        }
-    }
-
-    if ((options->mode == PSP_MODE_QUEUE_JOB) && (options->req_id <= 0)) {
-        fprintf(stderr, "need request id in order to queue jobs\n");
-        return false;
-    }
+        psError(PS_ERR_UNKNOWN, true, "bad request file: JOB_TYPE not specified");
+        return false;
+    }
+
+    bool isStampJob = (strcmp(job_type, "stamp") == 0);
 
     // how are we to select the images ?
     psString req_type = psMetadataLookupStr(&status, options->md, "REQ_TYPE");
-
     if ( !req_type) {
         psError(PS_ERR_UNKNOWN, true, "request file has no REQ_TYPE");
@@ -750,4 +747,8 @@
 
     psString roiString = parseROI(options);
+    if (isStampJob && !roiString) {
+        psError(PS_ERR_UNKNOWN, false, "need valid ROI for stamp request");
+        return false;
+    }
 
     psArray *uris = NULL;
@@ -776,5 +777,5 @@
 
     if (uris == NULL) {
-        // may need a finer grained status code: did something go wrong with the system
+        // XXX we need a finer grained status code: did something go wrong with the system
         // or are there simply no images matching the request
         fprintf(stderr, "No matching images found.\n");
@@ -784,4 +785,5 @@
     int numURIs = psArrayLength(uris);
     if (options->mode == PSP_MODE_LIST_URI) {
+        // Just list the images that would have jobs queued for them
         for (int i=0; i<numURIs; i++) {
             fprintf(stdout, "%s\n", (psString) uris->data[i]);
@@ -790,19 +792,21 @@
         psString commandArgs = roiString;
         psString class_id = psMetadataLookupStr(&status, options->md, "CLASS_ID");
-        if (class_id) {
+        // We don't check here whether class_id is required. We leave that up to
+        // ppstamp
+        if (class_id && strcmp(class_id, "null")) {
             // TODO: the ppstamp argument needs to change to class_id
             // perhaps allow chip as a synonym
             psStringAppend(&commandArgs, " -chip %s", class_id);
         }
-        psString user_tag = psMetadataLookupStr(&status, options->md, "USER_TAG");
+        psString stamp_name = psMetadataLookupStr(&status, options->md, "STAMP_NAME");
 
         if (options->mode == PSP_MODE_LIST_JOB) {
             if (numURIs == 1) {
                 printf("%s %s %s %s\n", job_type, (psString) uris->data[0],
-                    user_tag ? user_tag : "", commandArgs ? commandArgs : "") ;
+                    stamp_name ? stamp_name : "", commandArgs ? commandArgs : "") ;
             } else {
-                // add an integer to the user_tag
+                // add an integer to the stamp_name
                 for (int i = 0; i < numURIs; i++) {
-                    printf("%s %s %s_%d %s\n", job_type, (psString) uris->data[i], user_tag, i,
+                    printf("%s %s %s_%d %s\n", job_type, (psString) uris->data[i], stamp_name, i,
                         commandArgs ? commandArgs :"");
                 }
@@ -812,19 +816,28 @@
             if (!strcmp(job_type, "stamp")) {
                 // Postage stamp job
-                if (user_tag == NULL) {
-                    psError(PS_ERR_UNKNOWN, true, "no user tag in request file");
+                if (stamp_name == NULL) {
+                    psError(PS_ERR_UNKNOWN, true, "no STAMP_NAME in request file");
                     return false;
                 }
 
-                if (!queueJobs(options, job_type, uris, user_tag, commandArgs)) {
+                if (!queueJobs(options, job_type, uris, stamp_name, commandArgs)) {
+                    return false;
+                }
+
+                // Note: This is a DB operation
+                if (!turnOnResultsFile(options)) {
+                    psError(PS_ERR_UNKNOWN, true, "failed to update resultsFile");
+
+                    // TODO: should we unqueue the jobs, set state of request to false??
+                    // Maybe get rid of the column and just use job_type to trigger creation of
+                    // results file. so what if the gui doesn't need it?
                     return false;
                 }
             } else {
-
                 return queueGetImageJob(options, uris, req_type);
             }
 
         } else {
-            // this error is actually caught by parseMode but we might as well check
+            // this error is actually caught by parseMode
             fprintf(stderr, "unknown command mode found: %d\n", options->mode);
             exit(1);
@@ -848,12 +861,15 @@
 
     if (!options) {
+        psErrorStackPrint(stderr, "unable to parse arguments");
         return 1;
     }
 
     if (!readRequestTable(options)) {
+        psErrorStackPrint(stderr, "unable to read request table");
         return 1;
     }
 
     if (!setupDB(options)) {
+        psErrorStackPrint(stderr, "unable to set up data base connection");
         return 1;
     }
@@ -864,5 +880,5 @@
 
     if (!parseRequestTable(options)) {
-        // psErrorStackPrint(stderr, "unable to parse request table");
+        psErrorStackPrint(stderr, "unable to parse request table");
         return 1;
     }
Index: trunk/pstamp/src/pstamprequest.c
===================================================================
--- trunk/pstamp/src/pstamprequest.c	(revision 17894)
+++ trunk/pstamp/src/pstamprequest.c	(revision 18243)
@@ -13,4 +13,26 @@
 } psrOptions;
 
+char *str_columns[] = {
+    "PROJECT",
+    "JOB_TYPE",
+    "REQ_TYPE", // byid,  byexp,         bycoord
+    "ID",       // db id, exposure name, n/a
+    "CLASS_ID",
+    "CENTER_X",
+    "CENTER_Y",
+    "WIDTH",
+    "HEIGHT",
+    "FILTER",
+    "DATE_MIN",
+    "DATE_MAX",
+    "STAMP_NAME",
+    NULL
+};
+char *u32_columns[] = {
+    "COORD_MASK",
+    "OPTION_MASK", // bitmask or of PSTAMP_SELECT_IMAGE PSTAMP_SELECT_MASK PSTAMP_SELECT_WEIGHT
+    NULL
+};
+
 static void usage()
 {
@@ -19,4 +41,16 @@
 }
 
+static psMetadata *initializeTable()
+{
+    psMetadata *md = psMetadataAlloc();
+
+    for (char **col_name = str_columns; *col_name != NULL; col_name++) {
+        psMetadataAddStr(md, PS_LIST_TAIL, *col_name, PS_META_DEFAULT, "", "null");
+    }
+    for (char **col_name = u32_columns; *col_name != NULL; col_name++) {
+        psMetadataAddU32(md, PS_LIST_TAIL, *col_name, PS_META_DEFAULT, "", 0);
+    }
+    return md;
+}
 static void getId(char *idString, int argnum, int *pArgc, char *argv[], psrOptions *options)
 {
@@ -25,5 +59,11 @@
         usage();
     }
-    psMetadataAdd (options->md, PS_LIST_TAIL, idString, PS_DATA_STRING, "", argv[argnum]);
+    // catch common error
+    if (*argv[argnum] == '-') {
+        fprintf(stderr, "%s is not a valid %s\n", argv[argnum], idString);
+        usage();
+    }
+
+    psMetadataAddStr (options->md, PS_LIST_TAIL, idString, PS_META_REPLACE, "", argv[argnum]);
     psArgumentRemove(argnum, pArgc, argv);
 }
@@ -56,5 +96,5 @@
         usage();
     }
-    psMetadataAdd (options->md, PS_LIST_TAIL, "IMG_TYPE", PS_DATA_STRING, "", type);
+    psMetadataAddStr (options->md, PS_LIST_TAIL, "IMG_TYPE", PS_META_REPLACE, "", type);
 
     getId(paramName, argnum, pArgc, argv, options);
@@ -104,5 +144,5 @@
 {
     psrOptions *options = psAlloc(sizeof(psrOptions));
-    psMetadata *md = psMetadataAlloc();
+    psMetadata *md = initializeTable();
     int         argnum;
     bool        gotStyle  = false;
@@ -112,26 +152,29 @@
     bool        needROI   = false;
     bool        makeStamps= false;
+    unsigned    optionMask = PSTAMP_SELECT_IMAGE;
 
     options->md = md;
 
-    // Job type. This is normally "stamp" for postage stamp. 
-    // "get_image" requests that whole images to be retrieved (in PS case magic masked)
+    // Job type. 
+    // "stamp" for make postage stamps. 
+    // "get_image" requests that whole images to be retrieved (magic masked for gpc1)
     // "list_uri" results in a list of matching images
     if ((argnum = psArgumentGet(argc, argv, "-get_image"))) {
-        psMetadataAdd (md, PS_LIST_TAIL, "REQ_TYPE", PS_DATA_STRING, "", "get_image");
+        psMetadataAddStr (md, PS_LIST_TAIL, "JOB_TYPE", PS_META_REPLACE, "", "get_image");
         psArgumentRemove(argnum, &argc, argv);
     } else if ((argnum = psArgumentGet(argc, argv, "-list_uri"))) {
-        psMetadataAdd (md, PS_LIST_TAIL, "REQ_TYPE", PS_DATA_STRING, "", "get_image");
-        psArgumentRemove(argnum, &argc, argv);
-    } else {
-        psMetadataAdd (md, PS_LIST_TAIL, "REQ_TYPE", PS_DATA_STRING, "", "stamp");
+        psMetadataAddStr (md, PS_LIST_TAIL, "JOB_TYPE", PS_META_REPLACE, "", "list_uri");
+        psArgumentRemove(argnum, &argc, argv);
+    } else {
+        // default JOB_TYPE is stamp
+        psMetadataAddStr (md, PS_LIST_TAIL, "JOB_TYPE", PS_META_REPLACE, "", "stamp");
         needROI = true;
         makeStamps = true;
     }
 
-    if ((argnum = psArgumentGet(argc, argv, "-name"))) {
+    if ((argnum = psArgumentGet(argc, argv, "-request_name"))) {
         psArgumentRemove(argnum, &argc, argv);
         if (argc < 2) {
-            psError(PS_ERR_BAD_PARAMETER_VALUE, true, "no request name specified");
+            psError(PS_ERR_BAD_PARAMETER_VALUE, true, "value required for request name");
             usage();
         }
@@ -146,8 +189,8 @@
         psArgumentRemove(argnum, &argc, argv);
         if (argc < 2) {
-            psError(PS_ERR_BAD_PARAMETER_VALUE, true, "no project name specified");
+            psError(PS_ERR_BAD_PARAMETER_VALUE, true, "value required for project name");
             usage();
         }
-        psMetadataAdd(md, PS_LIST_TAIL, "PROJECT", PS_DATA_STRING, "", argv[argnum]);
+        psMetadataAddStr(md, PS_LIST_TAIL, "PROJECT", PS_META_REPLACE, "", argv[argnum]);
         psArgumentRemove(argnum, &argc, argv);
     } else {
@@ -157,23 +200,36 @@
 
     // user tag will be used as the base name for the postage stamp images
-    if ((argnum = psArgumentGet(argc, argv, "-user_tag"))) {
+    if ((argnum = psArgumentGet(argc, argv, "-stamp_name"))) {
         psArgumentRemove(argnum, &argc, argv);
         if (argc < 2) {
-            psError(PS_ERR_BAD_PARAMETER_VALUE, true, "missing value for user_tag");
+            psError(PS_ERR_BAD_PARAMETER_VALUE, true, "missing value for stamp_name");
             usage();
         }
-        psMetadataAdd(md, PS_LIST_TAIL, "USER_TAG", PS_DATA_STRING, "", argv[argnum]);
-        psArgumentRemove(argnum, &argc, argv);
-    } else {
-        // default user tag to requestName
-        psMetadataAdd(md, PS_LIST_TAIL, "USER_TAG", PS_DATA_STRING, "", options->requestName);
-    }
+        psMetadataAddStr(md, PS_LIST_TAIL, "STAMP_NAME", PS_META_REPLACE, "", argv[argnum]);
+        psArgumentRemove(argnum, &argc, argv);
+    } else {
+        // if stamp name not specified use requestName
+        psMetadataAddStr(md, PS_LIST_TAIL, "STAMP_NAME", PS_META_REPLACE, "", options->requestName);
+    }
+
+    if ((argnum = psArgumentGet(argc, argv, "-mask"))) {
+        psArgumentRemove(argnum, &argc, argv);
+        optionMask |= PSTAMP_SELECT_MASK;
+    }
+    if ((argnum = psArgumentGet(argc, argv, "-weight"))) {
+        psArgumentRemove(argnum, &argc, argv);
+        optionMask |= PSTAMP_SELECT_WEIGHT;
+    }
+    psMetadataAddU32(md, PS_LIST_TAIL, "OPTION_MASK", PS_META_REPLACE, "", optionMask);
 
     // find style & image type
     if ((argnum = psArgumentGet(argc, argv, "-bycoord"))) {
+        fprintf(stderr, "-bycoord not implemented yet\n");
+        exit(1);
+
         gotStyle = true;
-        psMetadataAdd(md, PS_LIST_TAIL, "REQ_TYPE", PS_DATA_STRING, "", 1+argv[argnum]);
-        psArgumentRemove(argnum, &argc, argv);
-        needCoord = true;
+        psMetadataAddStr(md, PS_LIST_TAIL, "REQ_TYPE", PS_META_REPLACE, "", 1+argv[argnum]);
+
+        psArgumentRemove(argnum, &argc, argv); needCoord = true;
         needROI = true;
         // TODO: we need an IMG_TYPE too...
@@ -186,5 +242,5 @@
         }
         gotStyle = true;
-        psMetadataAdd(md, PS_LIST_TAIL, "REQ_TYPE", PS_DATA_STRING, "", 1+argv[argnum]);
+        psMetadataAddStr(md, PS_LIST_TAIL, "REQ_TYPE", PS_META_REPLACE, "", 1+argv[argnum]);
         psArgumentRemove(argnum, &argc, argv);
         doById(argnum, &argc, argv, options);
@@ -197,5 +253,5 @@
         }
         gotStyle = true;
-        psMetadataAdd(md, PS_LIST_TAIL, "REQ_TYPE", PS_DATA_STRING, "", 1+argv[argnum]);
+        psMetadataAddStr(md, PS_LIST_TAIL, "REQ_TYPE", PS_META_REPLACE, "", 1+argv[argnum]);
         psArgumentRemove(argnum, &argc, argv);
         doByExp(argnum, &argc, argv, options);
@@ -213,26 +269,29 @@
         if (needROI) {
             usage();
+        } else {
+            psErrorClear();
         }
     }
 
     if (needROI) {
-        if (roiParam.celestialCenter) {
-            psMetadataAdd (md, PS_LIST_TAIL, "RA", PS_DATA_STRING, "",  roiParam.center[0]);
-            psMetadataAdd (md, PS_LIST_TAIL, "DEC", PS_DATA_STRING, "", roiParam.center[1]);
-        } else {
+        unsigned coord_mask = 0;
+
+        if (!roiParam.celestialCenter) {
             if (needCoord) {
                 fprintf(stderr, "need to specify ROI in sky coordinates with -bycoord\n");
                 usage();
             }
-            psMetadataAdd (md, PS_LIST_TAIL, "CENTER_X", PS_DATA_STRING, "", roiParam.center[0]);
-            psMetadataAdd (md, PS_LIST_TAIL, "CENTER_Y", PS_DATA_STRING, "", roiParam.center[1]);
-        }
-        if (roiParam.celestialRange) {
-            psMetadataAdd (md, PS_LIST_TAIL, "D_RA", PS_DATA_STRING, "",  roiParam.range[0]);
-            psMetadataAdd (md, PS_LIST_TAIL, "D_DEC", PS_DATA_STRING, "", roiParam.range[1]);
-        } else {
-            psMetadataAdd (md, PS_LIST_TAIL, "WIDTH", PS_DATA_STRING, "",  roiParam.range[0]);
-            psMetadataAdd (md, PS_LIST_TAIL, "HEIGHT", PS_DATA_STRING, "", roiParam.range[1]);
-        }
+            coord_mask |= PSTAMP_CENTER_IN_PIXELS;
+        }
+        psMetadataAddStr (md, PS_LIST_TAIL, "CENTER_X", PS_META_REPLACE, "", roiParam.center[0]);
+        psMetadataAddStr (md, PS_LIST_TAIL, "CENTER_Y", PS_META_REPLACE, "", roiParam.center[1]);
+
+        if (!roiParam.celestialRange) {
+            coord_mask |= PSTAMP_RANGE_IN_PIXELS;
+        }
+        psMetadataAddStr (md, PS_LIST_TAIL, "WIDTH", PS_META_REPLACE, "",  roiParam.range[0]);
+        psMetadataAddStr (md, PS_LIST_TAIL, "HEIGHT", PS_META_REPLACE, "", roiParam.range[1]);
+
+        psMetadataAddU32(md, PS_LIST_TAIL, "COORD_MASK", PS_META_REPLACE, "", coord_mask);
     }
 
@@ -266,6 +325,6 @@
     psMetadata *header = psMetadataAlloc();
 
-    psMetadataAdd(header, PS_LIST_TAIL, "REQ_NAME", PS_DATA_STRING, "", options->requestName);
-    psMetadataAdd(header, PS_LIST_TAIL, "EXTVER",   PS_DATA_STRING, "", STAMP_REQUEST_VERSION);
+    psMetadataAddStr(header, PS_LIST_TAIL, "EXTVER",   PS_META_REPLACE, "", STAMP_REQUEST_VERSION);
+    psMetadataAddStr(header, PS_LIST_TAIL, "REQ_NAME", PS_META_REPLACE, "", options->requestName);
 
     psArray    *table = psArrayAlloc(1);
@@ -285,33 +344,4 @@
 }
 
-bool sampleTable(const char *fileName)
-{
-    psFits *fitsFile = psFitsOpen(fileName, "w");
-    int     numRows = 42;
-
-    if (fitsFile == NULL) {
-        psError(PS_ERR_IO, true, "failed to open %s for output\n", fileName);
-        return false;
-    }
-
-    psArray    *table = psArrayAlloc(numRows);
-
-    for (int i=0; i< numRows; i++) {
-        psMetadata *row = psMetadataAlloc();
-        psMetadataAdd (row, PS_LIST_TAIL, "ROW",   PS_DATA_S32,    "", i);
-        psMetadataAdd (row, PS_LIST_TAIL, "FROW",  PS_TYPE_F32,    "", 0.1*i);
-        psMetadataAdd (row, PS_LIST_TAIL, "DUMMY", PS_DATA_STRING, "", "test line");
-
-        table->data[i] = row;
-         
-    }
-
-    psFitsWriteTable(fitsFile, NULL, table, "BILLSEXT");
-
-    psFitsClose(fitsFile);
-
-    return true;
-}
-
 int main(int argc, char *argv[])
 {
