Index: trunk/ppMops/src/ppMops.c
===================================================================
--- trunk/ppMops/src/ppMops.c	(revision 25100)
+++ trunk/ppMops/src/ppMops.c	(revision 25256)
@@ -6,22 +6,42 @@
 int main(int argc, char *argv[])
 {
-    if (argc != 7) {
-        fprintf(stderr, "Insufficient arguments.\n");
-        fprintf(stderr, "Usage: %s DETECTIONS ZP EXP_ID EXP_NAME DIRECTION OUTPUT\n", argv[0]);
+    psLibInit(NULL);
+
+    ppMopsArguments *args = ppMopsArgumentsParse(argc, argv); // Parsed arguments
+    if (!args) {
+        psErrorStackPrint(stderr, "Error parsing arguments");
         exit(PS_EXIT_CONFIG_ERROR);
     }
 
-    ppMopsData *data = ppMopsDataAlloc(); // Configuration data
-    data->detections = psStringCopy(argv[1]);
-    data->zp = atof(argv[2]);
-    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)) {
-        psErrorStackPrint(stderr, "Zero point is unknown\n");
-        exit(PS_EXIT_CONFIG_ERROR);
-    }
+    psArray *detections = ppMopsRead(args); // Detections from each input
+    if (!detections) {
+        psErrorStackPrint(stderr, "Unable to read detections");
+        exit(PS_EXIT_SYS_ERROR);
+    }
+
+    ppMopsDetections *merged = ppMopsMerge(detections); // Merged detections
+    psFree(detections);
+    if (!merged) {
+        psErrorStackPrint(stderr, "Unable to merge detections");
+        exit(PS_EXIT_SYS_ERROR);
+    }
+
+    if (!ppMopsWrite(merged, args)) {
+        psErrorStackPrint(stderr, "Unable to write detections");
+        exit(PS_EXIT_SYS_ERROR);
+    }
+
+    psFree(merged);
+    psFree(args);
+
+    psLibFinalize();
+
+    return PS_EXIT_SUCCESS;
+}
+
+
+#if 0
+    ps
+
 
     psArray *detections = NULL;         // Detections
@@ -211,4 +231,4 @@
     psFree(data);
 
-    return PS_EXIT_SUCCESS;
-}
+#endif
+
