Index: trunk/ippTools/share/Makefile.am
===================================================================
--- trunk/ippTools/share/Makefile.am	(revision 26934)
+++ trunk/ippTools/share/Makefile.am	(revision 26935)
@@ -198,4 +198,5 @@
      magicdstool_definebyquery_diff.sql \
      magicdstool_definecopy_chip.sql \
+     magicdstool_definecopy_warp.sql \
      magicdstool_getrunids.sql \
      magicdstool_getskycells.sql \
Index: trunk/ippTools/share/magicdstool_definecopy_warp.sql
===================================================================
--- trunk/ippTools/share/magicdstool_definecopy_warp.sql	(revision 26935)
+++ trunk/ippTools/share/magicdstool_definecopy_warp.sql	(revision 26935)
@@ -0,0 +1,34 @@
+SELECT DISTINCT       -- DISTINCT because we are going though diffInputSkyfile
+    magicRun.magic_id,
+    chipRun.exp_id,
+    'warp' AS stage,
+    warpRun.warp_id AS stage_id,
+    camRun.cam_id,
+    warpRun.label,
+    CAST(NULL AS SIGNED) AS inv_magic_id
+FROM magicRun
+    JOIN magicMask USING(magic_id)
+    JOIN diffRun USING(diff_id)
+    JOIN diffInputSkyfile USING(diff_id)
+    JOIN warpRun AS oldWarpRun
+        ON (!magicRun.inverse AND diffInputSkyfile.warp1 = oldWarpRun.warp_id)
+        OR ( magicRun.inverse AND diffInputSkyfile.warp2 = oldWarpRun.warp_id)
+    -- This ends the usual JOIN down to the raw level
+    JOIN rawExp
+        ON rawExp.exp_id = magicRun.exp_id
+    JOIN chipRun
+        ON chipRun.exp_id = rawExp.exp_id
+    JOIN camRun
+        ON camRun.chip_id = chipRun.chip_id
+    JOIN fakeRun
+        ON fakeRun.cam_id = camRun.cam_id
+    JOIN warpRun
+        ON warpRun.fake_id = fakeRun.fake_id
+        AND warpRun.warp_id != oldWarpRun.warp_id -- Not allowed to copy yourself
+    LEFT JOIN magicDSRun
+        ON magicRun.magic_id = magicDSRun.magic_id
+        AND magicDSRun.stage  = 'warp'
+WHERE magicRun.state = 'full'
+    -- HOOK: NEWLINE HERE TO ACTIVATE %s AND magicDSRun.magic_ds_id IS NULL
+    AND warpRun.magicked  = 0
+    AND warpRun.state = 'full'
Index: trunk/ippTools/src/magicdstool.c
===================================================================
--- trunk/ippTools/src/magicdstool.c	(revision 26934)
+++ trunk/ippTools/src/magicdstool.c	(revision 26935)
@@ -366,6 +366,7 @@
         query = pxDataGet("magicdstool_definecopy_chip.sql");
         break;
+      case IPP_STAGE_WARP:
+        query = pxDataGet("magicdstool_definecopy_warp.sql");
       case IPP_STAGE_CAMERA:
-      case IPP_STAGE_WARP:
       case IPP_STAGE_DIFF:
       case IPP_STAGE_FAKE:
