Index: trunk/ippconfig/gpc1/format_20090220.config
===================================================================
--- trunk/ippconfig/gpc1/format_20090220.config	(revision 33237)
+++ trunk/ippconfig/gpc1/format_20090220.config	(revision 33243)
@@ -590,4 +590,6 @@
         XY76    STR     1111111111111111111111111111111111111111111111111111111111111111
 END
+PATTERN.CELL    BOOL    FALSE
+PATTERN.CONTINUITY BOOL TRUE
 PATTERN.CELL.SUBSET      METADATA        # List of chips and whether to do cell pattern correction  
         XY01    BOOL 	FALSE
Index: trunk/ippconfig/gpc1/format_20091209.config
===================================================================
--- trunk/ippconfig/gpc1/format_20091209.config	(revision 33237)
+++ trunk/ippconfig/gpc1/format_20091209.config	(revision 33243)
@@ -717,79 +717,82 @@
 END
 
-# PATTERN.CELL	BOOL 	TRUE		# by default, do not do any cell pattern correction
-PATTERN.CELL.SUBSET	METADATA	# List of chips and whether to do cell pattern correction
-	XY01	BOOL	FALSE
-	XY02	BOOL	FALSE
-	XY03	BOOL	FALSE
-	XY04	BOOL	FALSE
-	XY05	BOOL	FALSE
-#	XY06    STR     0101000000010000000110000100000000000000000000000000000000000000
-	XY06	BOOL	FALSE
-	XY10	BOOL	FALSE
-	XY11	BOOL	FALSE
-	XY12	BOOL	FALSE
-	XY13	BOOL	FALSE
-	XY14	STR     0000000000000000111111110000000000000000000000000000000000000000
-	XY15	STR     1111111110000000100000000000000000000000000000000000000000000000
-#	XY16	STR     0000000100000000000000000000000000000001000000000000000000000000
-	XY16	BOOL	FALSE
-	XY17	BOOL	FALSE
-	XY20	BOOL	FALSE
-	XY21	BOOL	FALSE
-	XY22	BOOL	FALSE
-	XY23	BOOL	FALSE
-#	XY24	STR     0000000000100000000000000110100000100000001000000011100000000000
-	XY24	BOOL	FALSE
-#	XY25	STR     0100010000001001001011000000001000000111000110000000100000000010
-	XY25	BOOL	FALSE
-#	XY26	STR     0000000000000100000000000000000000001000001000000000000000000000
-	XY26	BOOL	FALSE
-	XY27	BOOL	FALSE
-	XY30	BOOL	FALSE
-	XY31	BOOL	FALSE
-	XY32	BOOL	FALSE
-	XY33	BOOL	FALSE
-#	XY34	STR     0000000000000000000000000000000000000001000011000000101000111111
-	XY34	BOOL	FALSE
-	XY35	BOOL	FALSE
-#	XY36	STR     0001000000000000000000000000000000010000000000000000000000000000
-	XY36	BOOL	FALSE
-#	XY37	STR     0000000000000000000000000000000100010001000000001011000010110110 ?
-	XY37	BOOL	FALSE
-#	XY40	STR     0000000000000000000000000010110000000000000001110000001000011111
-	XY40	BOOL	FALSE
-	XY41	BOOL	FALSE
-#	XY42	BOOL	FALSE
-	XY42	STR	0000000000000000000100000001000000000000000000000000000000000000
-#	XY43	STR     0000000000000000000000010000000100000000000010000100000100000100
-	XY43	STR 	0000000000000000000000000000000000000000000010000000000000000000
-	XY44	BOOL	FALSE
-	XY45	BOOL	FALSE
-	XY46	BOOL	FALSE
-	XY47	BOOL	FALSE
-	XY50	BOOL	FALSE
-	XY51	BOOL	FALSE
-	XY52	BOOL	FALSE
-	XY53	BOOL	FALSE
-	XY54	BOOL	FALSE
-	XY55	BOOL	FALSE
-	XY56	BOOL	FALSE
-	XY57	BOOL	FALSE
-	XY60	BOOL	FALSE
-	XY61	BOOL	FALSE
-#	XY62	STR     0000000000000000000000000000000000000000000000000000000000000010
-	XY62	BOOL	FALSE
-	XY63	BOOL	FALSE
-	XY64	BOOL	FALSE
-	XY65	BOOL	FALSE
-	XY66	BOOL	FALSE
-	XY67	BOOL	FALSE
-	XY71	BOOL	FALSE
-#	XY72	STR     0000000000000000000000000000000000000000000000000000000000000001
-	XY72	BOOL	FALSE
-#	XY73	STR     0001100000000000000000000000001000000000000000000000000000000000
-	XY73	BOOL	FALSE
-	XY74	BOOL	FALSE
-	XY75	BOOL	FALSE
-	XY76	BOOL	FALSE
-END
+PATTERN.CELL    BOOL   FALSE
+PATTERN.CONTINUITY BOOL TRUE
+
+# # PATTERN.CELL	BOOL 	TRUE		# by default, do not do any cell pattern correction
+# PATTERN.CELL.SUBSET	METADATA	# List of chips and whether to do cell pattern correction
+# 	XY01	BOOL	FALSE
+# 	XY02	BOOL	FALSE
+# 	XY03	BOOL	FALSE
+# 	XY04	BOOL	FALSE
+# 	XY05	BOOL	FALSE
+# #	XY06    STR     0101000000010000000110000100000000000000000000000000000000000000
+# 	XY06	BOOL	FALSE
+# 	XY10	BOOL	FALSE
+# 	XY11	BOOL	FALSE
+# 	XY12	BOOL	FALSE
+# 	XY13	BOOL	FALSE
+# 	XY14	STR     0000000000000000111111110000000000000000000000000000000000000000
+# 	XY15	STR     1111111110000000100000000000000000000000000000000000000000000000
+# #	XY16	STR     0000000100000000000000000000000000000001000000000000000000000000
+# 	XY16	BOOL	FALSE
+# 	XY17	BOOL	FALSE
+# 	XY20	BOOL	FALSE
+# 	XY21	BOOL	FALSE
+# 	XY22	BOOL	FALSE
+# 	XY23	BOOL	FALSE
+# #	XY24	STR     0000000000100000000000000110100000100000001000000011100000000000
+# 	XY24	BOOL	FALSE
+# #	XY25	STR     0100010000001001001011000000001000000111000110000000100000000010
+# 	XY25	BOOL	FALSE
+# #	XY26	STR     0000000000000100000000000000000000001000001000000000000000000000
+# 	XY26	BOOL	FALSE
+# 	XY27	BOOL	FALSE
+# 	XY30	BOOL	FALSE
+# 	XY31	BOOL	FALSE
+# 	XY32	BOOL	FALSE
+# 	XY33	BOOL	FALSE
+# #	XY34	STR     0000000000000000000000000000000000000001000011000000101000111111
+# 	XY34	BOOL	FALSE
+# 	XY35	BOOL	FALSE
+# #	XY36	STR     0001000000000000000000000000000000010000000000000000000000000000
+# 	XY36	BOOL	FALSE
+# #	XY37	STR     0000000000000000000000000000000100010001000000001011000010110110 ?
+# 	XY37	BOOL	FALSE
+# #	XY40	STR     0000000000000000000000000010110000000000000001110000001000011111
+# 	XY40	BOOL	FALSE
+# 	XY41	BOOL	FALSE
+# #	XY42	BOOL	FALSE
+# 	XY42	STR	0000000000000000000100000001000000000000000000000000000000000000
+# #	XY43	STR     0000000000000000000000010000000100000000000010000100000100000100
+# 	XY43	STR 	0000000000000000000000000000000000000000000010000000000000000000
+# 	XY44	BOOL	FALSE
+# 	XY45	BOOL	FALSE
+# 	XY46	BOOL	FALSE
+# 	XY47	BOOL	FALSE
+# 	XY50	BOOL	FALSE
+# 	XY51	BOOL	FALSE
+# 	XY52	BOOL	FALSE
+# 	XY53	BOOL	FALSE
+# 	XY54	BOOL	FALSE
+# 	XY55	BOOL	FALSE
+# 	XY56	BOOL	FALSE
+# 	XY57	BOOL	FALSE
+# 	XY60	BOOL	FALSE
+# 	XY61	BOOL	FALSE
+# #	XY62	STR     0000000000000000000000000000000000000000000000000000000000000010
+# 	XY62	BOOL	FALSE
+# 	XY63	BOOL	FALSE
+# 	XY64	BOOL	FALSE
+# 	XY65	BOOL	FALSE
+# 	XY66	BOOL	FALSE
+# 	XY67	BOOL	FALSE
+# 	XY71	BOOL	FALSE
+# #	XY72	STR     0000000000000000000000000000000000000000000000000000000000000001
+# 	XY72	BOOL	FALSE
+# #	XY73	STR     0001100000000000000000000000001000000000000000000000000000000000
+# 	XY73	BOOL	FALSE
+# 	XY74	BOOL	FALSE
+# 	XY75	BOOL	FALSE
+# 	XY76	BOOL	FALSE
+# END
Index: trunk/ippconfig/gpc1/format_20100122.config
===================================================================
--- trunk/ippconfig/gpc1/format_20100122.config	(revision 33237)
+++ trunk/ippconfig/gpc1/format_20100122.config	(revision 33243)
@@ -720,79 +720,82 @@
 END
 
-# PATTERN.CELL	BOOL 	TRUE		# by default, do not do any cell pattern correction
-PATTERN.CELL.SUBSET	METADATA	# List of chips and whether to do cell pattern correction
-	XY01	BOOL	FALSE
-	XY02	BOOL	FALSE
-	XY03	BOOL	FALSE
-	XY04	BOOL	FALSE
-	XY05	BOOL	FALSE
-#	XY06    STR     0101000000010000000110000100000000000000000000000000000000000000
-	XY06	BOOL	FALSE
-	XY10	BOOL	FALSE
-	XY11	BOOL	FALSE
-	XY12	BOOL	FALSE
-	XY13	BOOL	FALSE
-	XY14	STR     0000000000000000111111110000000000000000000000000000000000000000
-	XY15	STR     1111111110000000100000000000000000000000000000000000000000000000
-#	XY16	STR     0000000100000000000000000000000000000001000000000000000000000000
-	XY16	BOOL	FALSE
-	XY17	BOOL	FALSE
-	XY20	BOOL	FALSE
-	XY21	BOOL	FALSE
-	XY22	BOOL	FALSE
-	XY23	BOOL	FALSE
-#	XY24	STR     0000000000100000000000000110100000100000001000000011100000000000
-	XY24	BOOL	FALSE
-#	XY25	STR     0100010000001001001011000000001000000111000110000000100000000010
-	XY25	BOOL	FALSE
-#	XY26	STR     0000000000000100000000000000000000001000001000000000000000000000
-	XY26	BOOL	FALSE
-	XY27	BOOL	FALSE
-	XY30	BOOL	FALSE
-	XY31	BOOL	FALSE
-	XY32	BOOL	FALSE
-	XY33	BOOL	FALSE
-#	XY34	STR     0000000000000000000000000000000000000001000011000000101000111111
-	XY34	BOOL	FALSE
-	XY35	BOOL	FALSE
-#	XY36	STR     0001000000000000000000000000000000010000000000000000000000000000
-	XY36	BOOL	FALSE
-#	XY37	STR     0000000000000000000000000000000100010001000000001011000010110110 ?
-	XY37	BOOL	FALSE
-#	XY40	STR     0000000000000000000000000010110000000000000001110000001000011111
-	XY40	BOOL	FALSE
-	XY41	BOOL	FALSE
-#	XY42	BOOL	FALSE
-	XY42	STR	0000000000000000000100000001000000000000000000000000000000000000
-#	XY43	STR     0000000000000000000000010000000100000000000010000100000100000100
-	XY43	STR 	0000000000000000000000000000000000000000000010000000000000000000
-	XY44	BOOL	FALSE
-	XY45	BOOL	FALSE
-	XY46	BOOL	FALSE
-	XY47	BOOL	FALSE
-	XY50	BOOL	FALSE
-	XY51	BOOL	FALSE
-	XY52	BOOL	FALSE
-	XY53	BOOL	FALSE
-	XY54	BOOL	FALSE
-	XY55	BOOL	FALSE
-	XY56	BOOL	FALSE
-	XY57	BOOL	FALSE
-	XY60	BOOL	FALSE
-	XY61	BOOL	FALSE
-#	XY62	STR     0000000000000000000000000000000000000000000000000000000000000010
-	XY62	BOOL	FALSE
-	XY63	BOOL	FALSE
-	XY64	BOOL	FALSE
-	XY65	BOOL	FALSE
-	XY66	BOOL	FALSE
-	XY67	BOOL	FALSE
-	XY71	BOOL	FALSE
-#	XY72	STR     0000000000000000000000000000000000000000000000000000000000000001
-	XY72	BOOL	FALSE
-#	XY73	STR     0001100000000000000000000000001000000000000000000000000000000000
-	XY73	BOOL	FALSE
-	XY74	BOOL	FALSE
-	XY75	BOOL	FALSE
-	XY76	BOOL	FALSE
-END
+PATTERN.CELL BOOL FALSE
+PATTERN.CONTINUITY BOOL TRUE
+
+# # PATTERN.CELL	BOOL 	TRUE		# by default, do not do any cell pattern correction
+# PATTERN.CELL.SUBSET	METADATA	# List of chips and whether to do cell pattern correction
+# 	XY01	BOOL	FALSE
+# 	XY02	BOOL	FALSE
+# 	XY03	BOOL	FALSE
+# 	XY04	BOOL	FALSE
+# 	XY05	BOOL	FALSE
+# #	XY06    STR     0101000000010000000110000100000000000000000000000000000000000000
+# 	XY06	BOOL	FALSE
+# 	XY10	BOOL	FALSE
+# 	XY11	BOOL	FALSE
+# 	XY12	BOOL	FALSE
+# 	XY13	BOOL	FALSE
+# 	XY14	STR     0000000000000000111111110000000000000000000000000000000000000000
+# 	XY15	STR     1111111110000000100000000000000000000000000000000000000000000000
+# #	XY16	STR     0000000100000000000000000000000000000001000000000000000000000000
+# 	XY16	BOOL	FALSE
+# 	XY17	BOOL	FALSE
+# 	XY20	BOOL	FALSE
+# 	XY21	BOOL	FALSE
+# 	XY22	BOOL	FALSE
+# 	XY23	BOOL	FALSE
+# #	XY24	STR     0000000000100000000000000110100000100000001000000011100000000000
+# 	XY24	BOOL	FALSE
+# #	XY25	STR     0100010000001001001011000000001000000111000110000000100000000010
+# 	XY25	BOOL	FALSE
+# #	XY26	STR     0000000000000100000000000000000000001000001000000000000000000000
+# 	XY26	BOOL	FALSE
+# 	XY27	BOOL	FALSE
+# 	XY30	BOOL	FALSE
+# 	XY31	BOOL	FALSE
+# 	XY32	BOOL	FALSE
+# 	XY33	BOOL	FALSE
+# #	XY34	STR     0000000000000000000000000000000000000001000011000000101000111111
+# 	XY34	BOOL	FALSE
+# 	XY35	BOOL	FALSE
+# #	XY36	STR     0001000000000000000000000000000000010000000000000000000000000000
+# 	XY36	BOOL	FALSE
+# #	XY37	STR     0000000000000000000000000000000100010001000000001011000010110110 ?
+# 	XY37	BOOL	FALSE
+# #	XY40	STR     0000000000000000000000000010110000000000000001110000001000011111
+# 	XY40	BOOL	FALSE
+# 	XY41	BOOL	FALSE
+# #	XY42	BOOL	FALSE
+# 	XY42	STR	0000000000000000000100000001000000000000000000000000000000000000
+# #	XY43	STR     0000000000000000000000010000000100000000000010000100000100000100
+# 	XY43	STR 	0000000000000000000000000000000000000000000010000000000000000000
+# 	XY44	BOOL	FALSE
+# 	XY45	BOOL	FALSE
+# 	XY46	BOOL	FALSE
+# 	XY47	BOOL	FALSE
+# 	XY50	BOOL	FALSE
+# 	XY51	BOOL	FALSE
+# 	XY52	BOOL	FALSE
+# 	XY53	BOOL	FALSE
+# 	XY54	BOOL	FALSE
+# 	XY55	BOOL	FALSE
+# 	XY56	BOOL	FALSE
+# 	XY57	BOOL	FALSE
+# 	XY60	BOOL	FALSE
+# 	XY61	BOOL	FALSE
+# #	XY62	STR     0000000000000000000000000000000000000000000000000000000000000010
+# 	XY62	BOOL	FALSE
+# 	XY63	BOOL	FALSE
+# 	XY64	BOOL	FALSE
+# 	XY65	BOOL	FALSE
+# 	XY66	BOOL	FALSE
+# 	XY67	BOOL	FALSE
+# 	XY71	BOOL	FALSE
+# #	XY72	STR     0000000000000000000000000000000000000000000000000000000000000001
+# 	XY72	BOOL	FALSE
+# #	XY73	STR     0001100000000000000000000000001000000000000000000000000000000000
+# 	XY73	BOOL	FALSE
+# 	XY74	BOOL	FALSE
+# 	XY75	BOOL	FALSE
+# 	XY76	BOOL	FALSE
+# END
Index: trunk/ippconfig/gpc1/format_20100228.config
===================================================================
--- trunk/ippconfig/gpc1/format_20100228.config	(revision 33237)
+++ trunk/ippconfig/gpc1/format_20100228.config	(revision 33243)
@@ -719,79 +719,82 @@
 END
 
+PATTERN.CELL BOOL FALSE
+PATTERN.CONTINUITY BOOL TRUE
+
 # PATTERN.CELL	BOOL 	TRUE		# by default, do not do any cell pattern correction
-PATTERN.CELL.SUBSET	METADATA	# List of chips and whether to do cell pattern correction
-	XY01	BOOL	FALSE
-	XY02	BOOL	FALSE
-	XY03	BOOL	FALSE
-	XY04	BOOL	FALSE
-	XY05	BOOL	FALSE
-#	XY06    STR     0101000000010000000110000100000000000000000000000000000000000000
-	XY06	BOOL	FALSE
-	XY10	BOOL	FALSE
-	XY11	BOOL	FALSE
-	XY12	BOOL	FALSE
-	XY13	BOOL	FALSE
-	XY14	STR     0000000000000000111111110000000000000000000000000000000000000000
-	XY15	STR     1111111110000000100000000000000000000000000000000000000000000000
-#	XY16	STR     0000000100000000000000000000000000000001000000000000000000000000
-	XY16	BOOL	FALSE
-	XY17	BOOL	FALSE
-	XY20	BOOL	FALSE
-	XY21	BOOL	FALSE
-	XY22	BOOL	FALSE
-	XY23	BOOL	FALSE
-#	XY24	STR     0000000000100000000000000110100000100000001000000011100000000000
-	XY24	BOOL	FALSE
-#	XY25	STR     0100010000001001001011000000001000000111000110000000100000000010
-	XY25	BOOL	FALSE
-#	XY26	STR     0000000000000100000000000000000000001000001000000000000000000000
-	XY26	BOOL	FALSE
-	XY27	BOOL	FALSE
-	XY30	BOOL	FALSE
-	XY31	BOOL	FALSE
-	XY32	BOOL	FALSE
-	XY33	BOOL	FALSE
-#	XY34	STR     0000000000000000000000000000000000000001000011000000101000111111
-	XY34	BOOL	FALSE
-	XY35	BOOL	FALSE
-#	XY36	STR     0001000000000000000000000000000000010000000000000000000000000000
-	XY36	BOOL	FALSE
-#	XY37	STR     0000000000000000000000000000000100010001000000001011000010110110 ?
-	XY37	BOOL	FALSE
-#	XY40	STR     0000000000000000000000000010110000000000000001110000001000011111
-	XY40	BOOL	FALSE
-	XY41	BOOL	FALSE
-#	XY42	BOOL	FALSE
-	XY42	STR	0000000000000000000100000001000000000000000000000000000000000000
-#	XY43	STR     0000000000000000000000010000000100000000000010000100000100000100
-	XY43	STR 	0000000000000000000000000000000000000000000010000000000000000000
-	XY44	BOOL	FALSE
-	XY45	BOOL	FALSE
-	XY46	BOOL	FALSE
-	XY47	BOOL	FALSE
-	XY50	BOOL	FALSE
-	XY51	BOOL	FALSE
-	XY52	BOOL	FALSE
-	XY53	BOOL	FALSE
-	XY54	BOOL	FALSE
-	XY55	BOOL	FALSE
-	XY56	BOOL	FALSE
-	XY57	BOOL	FALSE
-	XY60	BOOL	FALSE
-	XY61	BOOL	FALSE
-#	XY62	STR     0000000000000000000000000000000000000000000000000000000000000010
-	XY62	BOOL	FALSE
-	XY63	BOOL	FALSE
-	XY64	BOOL	FALSE
-	XY65	BOOL	FALSE
-	XY66	BOOL	FALSE
-	XY67	BOOL	FALSE
-	XY71	BOOL	FALSE
-#	XY72	STR     0000000000000000000000000000000000000000000000000000000000000001
-	XY72	BOOL	FALSE
-#	XY73	STR     0001100000000000000000000000001000000000000000000000000000000000
-	XY73	BOOL	FALSE
-	XY74	BOOL	FALSE
-	XY75	BOOL	FALSE
-	XY76	BOOL	FALSE
-END
+# PATTERN.CELL.SUBSET	METADATA	# List of chips and whether to do cell pattern correction
+# 	XY01	BOOL	FALSE
+# 	XY02	BOOL	FALSE
+# 	XY03	BOOL	FALSE
+# 	XY04	BOOL	FALSE
+# 	XY05	BOOL	FALSE
+# #	XY06    STR     0101000000010000000110000100000000000000000000000000000000000000
+# 	XY06	BOOL	FALSE
+# 	XY10	BOOL	FALSE
+# 	XY11	BOOL	FALSE
+# 	XY12	BOOL	FALSE
+# 	XY13	BOOL	FALSE
+# 	XY14	STR     0000000000000000111111110000000000000000000000000000000000000000
+# 	XY15	STR     1111111110000000100000000000000000000000000000000000000000000000
+# #	XY16	STR     0000000100000000000000000000000000000001000000000000000000000000
+# 	XY16	BOOL	FALSE
+# 	XY17	BOOL	FALSE
+# 	XY20	BOOL	FALSE
+# 	XY21	BOOL	FALSE
+# 	XY22	BOOL	FALSE
+# 	XY23	BOOL	FALSE
+# #	XY24	STR     0000000000100000000000000110100000100000001000000011100000000000
+# 	XY24	BOOL	FALSE
+# #	XY25	STR     0100010000001001001011000000001000000111000110000000100000000010
+# 	XY25	BOOL	FALSE
+# #	XY26	STR     0000000000000100000000000000000000001000001000000000000000000000
+# 	XY26	BOOL	FALSE
+# 	XY27	BOOL	FALSE
+# 	XY30	BOOL	FALSE
+# 	XY31	BOOL	FALSE
+# 	XY32	BOOL	FALSE
+# 	XY33	BOOL	FALSE
+# #	XY34	STR     0000000000000000000000000000000000000001000011000000101000111111
+# 	XY34	BOOL	FALSE
+# 	XY35	BOOL	FALSE
+# #	XY36	STR     0001000000000000000000000000000000010000000000000000000000000000
+# 	XY36	BOOL	FALSE
+# #	XY37	STR     0000000000000000000000000000000100010001000000001011000010110110 ?
+# 	XY37	BOOL	FALSE
+# #	XY40	STR     0000000000000000000000000010110000000000000001110000001000011111
+# 	XY40	BOOL	FALSE
+# 	XY41	BOOL	FALSE
+# #	XY42	BOOL	FALSE
+# 	XY42	STR	0000000000000000000100000001000000000000000000000000000000000000
+# #	XY43	STR     0000000000000000000000010000000100000000000010000100000100000100
+# 	XY43	STR 	0000000000000000000000000000000000000000000010000000000000000000
+# 	XY44	BOOL	FALSE
+# 	XY45	BOOL	FALSE
+# 	XY46	BOOL	FALSE
+# 	XY47	BOOL	FALSE
+# 	XY50	BOOL	FALSE
+# 	XY51	BOOL	FALSE
+# 	XY52	BOOL	FALSE
+# 	XY53	BOOL	FALSE
+# 	XY54	BOOL	FALSE
+# 	XY55	BOOL	FALSE
+# 	XY56	BOOL	FALSE
+# 	XY57	BOOL	FALSE
+# 	XY60	BOOL	FALSE
+# 	XY61	BOOL	FALSE
+# #	XY62	STR     0000000000000000000000000000000000000000000000000000000000000010
+# 	XY62	BOOL	FALSE
+# 	XY63	BOOL	FALSE
+# 	XY64	BOOL	FALSE
+# 	XY65	BOOL	FALSE
+# 	XY66	BOOL	FALSE
+# 	XY67	BOOL	FALSE
+# 	XY71	BOOL	FALSE
+# #	XY72	STR     0000000000000000000000000000000000000000000000000000000000000001
+# 	XY72	BOOL	FALSE
+# #	XY73	STR     0001100000000000000000000000001000000000000000000000000000000000
+# 	XY73	BOOL	FALSE
+# 	XY74	BOOL	FALSE
+# 	XY75	BOOL	FALSE
+# 	XY76	BOOL	FALSE
+# END
Index: trunk/ippconfig/gpc1/format_20100723.config
===================================================================
--- trunk/ippconfig/gpc1/format_20100723.config	(revision 33237)
+++ trunk/ippconfig/gpc1/format_20100723.config	(revision 33243)
@@ -592,79 +592,80 @@
 END
 
-# PATTERN.CELL	BOOL 	TRUE		# by default, do not do any cell pattern correction
-PATTERN.CELL.SUBSET	METADATA	# List of chips and whether to do cell pattern correction
-	XY01	BOOL	FALSE
-	XY02	BOOL	FALSE
-	XY03	BOOL	FALSE
-	XY04	BOOL	FALSE
-	XY05	BOOL	FALSE
-#	XY06    STR     0101000000010000000110000100000000000000000000000000000000000000
-	XY06	BOOL	FALSE
-	XY10	BOOL	FALSE
-	XY11	BOOL	FALSE
-	XY12	BOOL	FALSE
-	XY13	BOOL	FALSE
-	XY14	STR     0000000000000000111111110000000000000000000000000000000000000000
-	XY15	STR     1111111110000000100000000000000000000000000000000000000000000000
-#	XY16	STR     0000000100000000000000000000000000000001000000000000000000000000
-	XY16	BOOL	FALSE
-	XY17	BOOL	FALSE
-	XY20	BOOL	FALSE
-	XY21	BOOL	FALSE
-	XY22	BOOL	FALSE
-	XY23	BOOL	FALSE
-#	XY24	STR     0000000000100000000000000110100000100000001000000011100000000000
-	XY24	BOOL	FALSE
-#	XY25	STR     0100010000001001001011000000001000000111000110000000100000000010
-	XY25	BOOL	FALSE
-#	XY26	STR     0000000000000100000000000000000000001000001000000000000000000000
-	XY26	BOOL	FALSE
-	XY27	BOOL	FALSE
-	XY30	BOOL	FALSE
-	XY31	BOOL	FALSE
-	XY32	BOOL	FALSE
-	XY33	BOOL	FALSE
-#	XY34	STR     0000000000000000000000000000000000000001000011000000101000111111
-	XY34	BOOL	FALSE
-	XY35	BOOL	FALSE
-#	XY36	STR     0001000000000000000000000000000000010000000000000000000000000000
-	XY36	BOOL	FALSE
-#	XY37	STR     0000000000000000000000000000000100010001000000001011000010110110 ?
-	XY37	BOOL	FALSE
-#	XY40	STR     0000000000000000000000000010110000000000000001110000001000011111
-	XY40	BOOL	FALSE
-	XY41	BOOL	FALSE
-#	XY42	BOOL	FALSE
-	XY42	STR	0000000000000000000100000001000000000000000000000000000000000000
-#	XY43	STR     0000000000000000000000010000000100000000000010000100000100000100
-	XY43	STR 	0000000000000000000000000000000000000000000010000000000000000000
-	XY44	BOOL	FALSE
-	XY45	BOOL	FALSE
-	XY46	BOOL	FALSE
-	XY47	BOOL	FALSE
-	XY50	BOOL	FALSE
-	XY51	BOOL	FALSE
-	XY52	BOOL	FALSE
-	XY53	BOOL	FALSE
-	XY54	BOOL	FALSE
-	XY55	BOOL	FALSE
-	XY56	BOOL	FALSE
-	XY57	BOOL	FALSE
-	XY60	BOOL	FALSE
-	XY61	BOOL	FALSE
-#	XY62	STR     0000000000000000000000000000000000000000000000000000000000000010
-	XY62	BOOL	FALSE
-	XY63	BOOL	FALSE
-	XY64	BOOL	FALSE
-	XY65	BOOL	FALSE
-	XY66	BOOL	FALSE
-	XY67	BOOL	FALSE
-	XY71	BOOL	FALSE
-#	XY72	STR     0000000000000000000000000000000000000000000000000000000000000001
-	XY72	BOOL	FALSE
-#	XY73	STR     0001100000000000000000000000001000000000000000000000000000000000
-	XY73	BOOL	FALSE
-	XY74	BOOL	FALSE
-	XY75	BOOL	FALSE
-	XY76	BOOL	FALSE
-END
+PATTERN.CONTINUITY BOOL TRUE
+ PATTERN.CELL	BOOL 	FALSE		# by default, do not do any cell pattern correction
+# PATTERN.CELL.SUBSET	METADATA	# List of chips and whether to do cell pattern correction
+# 	XY01	BOOL	FALSE
+# 	XY02	BOOL	FALSE
+# 	XY03	BOOL	FALSE
+# 	XY04	BOOL	FALSE
+# 	XY05	BOOL	FALSE
+# #	XY06    STR     0101000000010000000110000100000000000000000000000000000000000000
+# 	XY06	BOOL	FALSE
+# 	XY10	BOOL	FALSE
+# 	XY11	BOOL	FALSE
+# 	XY12	BOOL	FALSE
+# 	XY13	BOOL	FALSE
+# 	XY14	STR     0000000000000000111111110000000000000000000000000000000000000000
+# 	XY15	STR     1111111110000000100000000000000000000000000000000000000000000000
+# #	XY16	STR     0000000100000000000000000000000000000001000000000000000000000000
+# 	XY16	BOOL	FALSE
+# 	XY17	BOOL	FALSE
+# 	XY20	BOOL	FALSE
+# 	XY21	BOOL	FALSE
+# 	XY22	BOOL	FALSE
+# 	XY23	BOOL	FALSE
+# #	XY24	STR     0000000000100000000000000110100000100000001000000011100000000000
+# 	XY24	BOOL	FALSE
+# #	XY25	STR     0100010000001001001011000000001000000111000110000000100000000010
+# 	XY25	BOOL	FALSE
+# #	XY26	STR     0000000000000100000000000000000000001000001000000000000000000000
+# 	XY26	BOOL	FALSE
+# 	XY27	BOOL	FALSE
+# 	XY30	BOOL	FALSE
+# 	XY31	BOOL	FALSE
+# 	XY32	BOOL	FALSE
+# 	XY33	BOOL	FALSE
+# #	XY34	STR     0000000000000000000000000000000000000001000011000000101000111111
+# 	XY34	BOOL	FALSE
+# 	XY35	BOOL	FALSE
+# #	XY36	STR     0001000000000000000000000000000000010000000000000000000000000000
+# 	XY36	BOOL	FALSE
+# #	XY37	STR     0000000000000000000000000000000100010001000000001011000010110110 ?
+# 	XY37	BOOL	FALSE
+# #	XY40	STR     0000000000000000000000000010110000000000000001110000001000011111
+# 	XY40	BOOL	FALSE
+# 	XY41	BOOL	FALSE
+# #	XY42	BOOL	FALSE
+# 	XY42	STR	0000000000000000000100000001000000000000000000000000000000000000
+# #	XY43	STR     0000000000000000000000010000000100000000000010000100000100000100
+# 	XY43	STR 	0000000000000000000000000000000000000000000010000000000000000000
+# 	XY44	BOOL	FALSE
+# 	XY45	BOOL	FALSE
+# 	XY46	BOOL	FALSE
+# 	XY47	BOOL	FALSE
+# 	XY50	BOOL	FALSE
+# 	XY51	BOOL	FALSE
+# 	XY52	BOOL	FALSE
+# 	XY53	BOOL	FALSE
+# 	XY54	BOOL	FALSE
+# 	XY55	BOOL	FALSE
+# 	XY56	BOOL	FALSE
+# 	XY57	BOOL	FALSE
+# 	XY60	BOOL	FALSE
+# 	XY61	BOOL	FALSE
+# #	XY62	STR     0000000000000000000000000000000000000000000000000000000000000010
+# 	XY62	BOOL	FALSE
+# 	XY63	BOOL	FALSE
+# 	XY64	BOOL	FALSE
+# 	XY65	BOOL	FALSE
+# 	XY66	BOOL	FALSE
+# 	XY67	BOOL	FALSE
+# 	XY71	BOOL	FALSE
+# #	XY72	STR     0000000000000000000000000000000000000000000000000000000000000001
+# 	XY72	BOOL	FALSE
+# #	XY73	STR     0001100000000000000000000000001000000000000000000000000000000000
+# 	XY73	BOOL	FALSE
+# 	XY74	BOOL	FALSE
+# 	XY75	BOOL	FALSE
+# 	XY76	BOOL	FALSE
+# END
Index: trunk/ippconfig/gpc1/ppImage.config
===================================================================
--- trunk/ippconfig/gpc1/ppImage.config	(revision 33237)
+++ trunk/ippconfig/gpc1/ppImage.config	(revision 33243)
@@ -166,5 +166,6 @@
   MASK.BURNTOOL      BOOL    TRUE            # Mask potential burntool trails
   PATTERN.ROW        BOOL    TRUE            # Row pattern correction
-  PATTERN.CELL	     BOOL    TRUE	     # Cell pattern correction
+  PATTERN.CELL	     BOOL    FALSE	     # Cell pattern correction
+  PATTERN.CONTINUITY BOOL    TRUE            # Cell pattern correction using edge continuity
   FRINGE             BOOL    TRUE            # Fringe subtraction
   BIN1.FITS          BOOL    TRUE            # Save 1st binned chip image?
Index: trunk/ippconfig/recipes/ppImage.config
===================================================================
--- trunk/ippconfig/recipes/ppImage.config	(revision 33237)
+++ trunk/ippconfig/recipes/ppImage.config	(revision 33243)
@@ -27,4 +27,7 @@
 PATTERN.SUBSET	   METADATA
 END
+PATTERN.CONTINUITY BOOL    FALSE
+PATTERN.CONTINUITY.WIDTH S32  50
+PATTERN.CONTINUITY.SUBSET BOOL TRUE
 FRINGE             BOOL    FALSE           # Fringe subtraction
 PHOTOM             BOOL    FALSE           # Source identification and photometry
Index: trunk/ppImage/src/ppImage.h
===================================================================
--- trunk/ppImage/src/ppImage.h	(revision 33237)
+++ trunk/ppImage/src/ppImage.h	(revision 33243)
@@ -40,4 +40,5 @@
     bool doPatternRow;                  // Row pattern correction
     bool doPatternCell;                 // Cell pattern correction
+    bool doPatternContinuity;           // Cell continuity correction
     bool doFringe;                      // Fringe subtraction
     bool doPhotom;                      // Source identification and photometry
@@ -109,4 +110,6 @@
     psStatsOptions patternCellMean;        // Statistic for mean
 
+  int patternContinuityEdgeWidth;        // Size of box to use for edge matching.
+  
     int remnanceSize;                   // Size for remnance detection
     float remnanceThresh;               // Threshold for remnance detection
Index: trunk/ppImage/src/ppImageDetrendPattern.c
===================================================================
--- trunk/ppImage/src/ppImageDetrendPattern.c	(revision 33237)
+++ trunk/ppImage/src/ppImageDetrendPattern.c	(revision 33243)
@@ -18,5 +18,5 @@
     pmCell *cell = NULL;
 
-    assert(options->doPatternRow || options->doPatternCell); // do not call if not needed
+    assert(options->doPatternRow || options->doPatternCell || options->doPatternContinuity); // do not call if not needed
     assert(inputView->chip != -1);
     assert(inputView->cell == -1);
@@ -40,5 +40,5 @@
 	if (psMetadataLookupBool(NULL,hdu->header,"PTRN_ROW")) {
 	  psLogMsg("ppImage", PS_LOG_INFO, "Not performing row pattern correction as it has already been done.");
-	  goto pattern_cell;
+	  goto pattern_continuity;
 	}
 
@@ -98,8 +98,54 @@
     }
 
+ pattern_continuity:
+
+    // see the comment for PATTERN.ROW; the same rules apply for PATTERN.CELL
+
+    if (options->doPatternContinuity) {
+        int numCells = chip->cells->n;       // Number of cells
+        psVector *tweak = psVectorAlloc(numCells, PS_TYPE_U8); // Tweak cell?
+        pmFPAview *view = pmFPAviewAlloc(0); // View for local processing
+        *view = *inputView;
+
+	pmHDU *hdu = pmHDUFromChip(chip);
+	if (psMetadataLookupBool(NULL,hdu->header,"PTRN_CON")) {
+	  psLogMsg("ppImage", PS_LOG_INFO, "Not performing cell continuity correction as it has already been done.");
+	  goto pattern_cell;
+	}
+
+	for (int i = 0; i < chip->cells->n; i++) {
+            view->cell = i;
+
+            pmCell *cell = chip->cells->data[i]; // Cell of interest
+
+            if (cell->readouts->n > 1) {
+                psLogMsg("ppImage", PS_LOG_INFO, "Not performing cell continuity correction on video cell.");
+                continue;
+            }
+
+            bool doPattern = false;
+            if (!doPatternForView(&doPattern, config, chip, view, RECIPE_NAME, "PATTERN.CONTINUITY.SUBSET")) {
+                ESCAPE(false, "Unable to determine whether row pattern matching should be applied.");
+            }
+            if (doPattern) {
+                tweak->data.U8[i] = 0xFF;
+            }
+	}
+
+	// Tweak the cells
+	if (!pmPatternContinuity(chip, tweak, options->patternCellBG, options->patternCellMean,
+				 options->maskValue, options->darkMask,options->patternContinuityEdgeWidth)) {
+	    psFree(tweak);
+	    psFree(view);
+	    return false;
+	}
+	psFree(tweak);
+	psFree(view);
+
+	psMetadataAddBool(hdu->header, PS_LIST_TAIL, "PTRN_CON",PS_META_REPLACE,"PATTERN.CONTINUITY correction applied",true);
+    }
+
  pattern_cell:
-
-    // see the comment for PATTERN.ROW; the same rules apply for PATTERN.CELL
-
+    
     if (options->doPatternCell) {
         int numCells = chip->cells->n;       // Number of cells
@@ -131,5 +177,4 @@
                 tweak->data.U8[i] = 0xFF;
             }
-
 	}
 
Index: trunk/ppImage/src/ppImageLoop.c
===================================================================
--- trunk/ppImage/src/ppImageLoop.c	(revision 33237)
+++ trunk/ppImage/src/ppImageLoop.c	(revision 33243)
@@ -170,5 +170,5 @@
 
         // Apply the pattern correction
-        if (options->doPatternRow || options->doPatternCell) {
+        if (options->doPatternRow || options->doPatternCell || options->doPatternContinuity) {
           if (!ppImageDetrendPatternApply(config,chip,view,options)) {
             ESCAPE("Unable to apply pattern corrections");
Index: trunk/ppImage/src/ppImageOptions.c
===================================================================
--- trunk/ppImage/src/ppImageOptions.c	(revision 33237)
+++ trunk/ppImage/src/ppImageOptions.c	(revision 33243)
@@ -34,4 +34,5 @@
     options->doPatternRow    = false;   // Row pattern correction
     options->doPatternCell   = false;   // Cell pattern correction
+    options->doPatternContinuity = false; // Cell continuity correction
     options->doFringe        = false;   // Fringe subtraction
     options->doPhotom        = false;   // Source identification and photometry
@@ -253,4 +254,5 @@
     options->doPatternRow = psMetadataLookupBool(NULL, recipe, "PATTERN.ROW");
     options->doPatternCell = psMetadataLookupBool(NULL, recipe, "PATTERN.CELL");
+    options->doPatternContinuity = psMetadataLookupBool(NULL, recipe, "PATTERN.CONTINUITY");
 
     options->doMaskStats = psMetadataLookupBool(NULL, recipe, "MASK.STATS");
@@ -408,4 +410,11 @@
     }
 
+    if (psMetadataLookup(format, "PATTERN.CONTINUITY.WIDTH")) {
+      options->patternContinuityEdgeWidth = psMetadataLookupS32(NULL, format, "PATTERN.CONTINUITY.WIDTH");
+    }
+    else {
+      options->patternContinuityEdgeWidth = psMetadataLookupS32(NULL, recipe, "PATTERN.CONTINUITY.WIDTH");
+    }
+    
 
     // Remnance options
Index: trunk/psModules/src/detrend/pmPattern.c
===================================================================
--- trunk/psModules/src/detrend/pmPattern.c	(revision 33237)
+++ trunk/psModules/src/detrend/pmPattern.c	(revision 33243)
@@ -146,4 +146,10 @@
 	// Store the results we found for this row.
 	yaxisData->data.F32[y] = poly->coeff[0];
+	xaxisData->data.F32[y] = poly->coeff[1];
+	psTrace("pattern",1,"%d %g %g\n",y,poly->coeff[0],poly->coeff[1]);
+	
+	//	yaxisData->data.F32[y] = 0.0;
+/* 	xaxisData->data.F32[y] = 0.0; */
+	
 #endif
         memcpy(corr->data.F64[y], poly->coeff, (order + 1) * PSELEMTYPE_SIZEOF(PS_TYPE_F64));
@@ -161,4 +167,5 @@
         for (int x = 0; x < numCols; x++) {
             image->data.F32[y][x] -= solution->data.F32[x];
+	    psTrace("pattern",5,"A: %d %d %g\n",x,y,solution->data.F32[x]);
         }
         psFree(solution);
@@ -177,5 +184,5 @@
     // Fit the trend of the constant term, producing the y-axis global trend
     psStatsInit(clip);
-    psPolynomial1D *yaxisPoly = psPolynomial1DAlloc(PS_POLYNOMIAL_ORD, 2); // Polynomial to fit.
+    psPolynomial1D *yaxisPoly = psPolynomial1DAlloc(PS_POLYNOMIAL_ORD, 1); // Polynomial to fit.
     if (!psVectorClipFitPolynomial1D(yaxisPoly,clip,yaxisMask,0xFF,yaxisData, NULL, yaxisIndices)) {
       psWarning("Unable to fit polynomial to y-axis trend");
@@ -209,4 +216,5 @@
 	    image->data.F32[y][x] += solution->data.F32[y];
 	    corr->data.F64[y][0]  -= solution->data.F32[y];
+	    psTrace("pattern",5,"B: %d %d %g\n",x,y,solution->data.F32[x]);
 	  }
 	}
@@ -218,5 +226,5 @@
     // We can use the same mask vector, as the same rows failed the row-fit earlier.
     psStatsInit(clip);
-    psPolynomial1D *xaxisPoly = psPolynomial1DAlloc(PS_POLYNOMIAL_ORD, 2); // Polynomial to fit.
+    psPolynomial1D *xaxisPoly = psPolynomial1DAlloc(PS_POLYNOMIAL_ORD, 1); // Polynomial to fit.
     if (!psVectorClipFitPolynomial1D(xaxisPoly,clip,yaxisMask,0xFF,xaxisData, NULL, yaxisIndices)) {
       psWarning("Unable to fit polynomial to x-axis trend");
@@ -233,5 +241,6 @@
 	  for (int x = 0; x < numCols; x++) {
 	    image->data.F32[y][x] += solution->data.F32[y] * indices->data.F32[x];
-	    corr->data.F64[y][0]  -= solution->data.F32[y] * indices->data.F32[x];
+	    corr->data.F64[y][1]  -= solution->data.F32[y] ;
+	    psTrace("pattern",5,"C: %d %d %g %g\n",x,y,solution->data.F32[x],indices->data.F32[x]);
 	  }
 	}
@@ -500,2 +509,346 @@
 
 
+
+bool pmPatternContinuity(pmChip *chip, const psVector *tweak, psStatsOptions bgStat, psStatsOptions cellStat,
+			 psImageMaskType maskVal, psImageMaskType maskBad, int edgeWidth)
+{
+    PS_ASSERT_PTR_NON_NULL(chip, false);
+    PS_ASSERT_VECTOR_NON_NULL(tweak, false);
+    PS_ASSERT_VECTOR_SIZE(tweak, chip->cells->n, false);
+    PS_ASSERT_VECTOR_TYPE(tweak, PS_TYPE_U8, false);
+
+    int numCells = tweak->n;            // Number of cells
+
+    psVector *meanMask = psVectorAlloc(numCells, PS_TYPE_VECTOR_MASK); // Mask for means
+    psVectorInit(meanMask, 0);
+
+    // Mask bits
+    enum {
+        PM_PATTERN_IGNORE = 0x01,       // Ignore this cell
+        PM_PATTERN_TWEAK  = 0x02,       // Tweak this cell
+        PM_PATTERN_ERROR  = 0x04,       // Error in calculating background
+        PM_PATTERN_ALL    = 0xFF,       // All causes
+    };
+
+    // Count number of cells to tweak
+    int numTweak = 0;                   // Number of cells to tweak
+    int numIgnore = 0;                  // Number of cells to ignore
+    for (int i = 0; i < numCells; i++) {
+        pmCell *cell = chip->cells->data[i]; // Cell of interest
+        if (!cell || !cell->data_exists || !cell->process ||
+            cell->readouts->n == 0 || cell->readouts->n > 1 || !cell->readouts->data[0]) {
+            numIgnore++;
+            meanMask->data.PS_TYPE_VECTOR_MASK_DATA[i] = PM_PATTERN_IGNORE;
+            continue;
+        }
+        if (tweak->data.U8[i]) {
+            meanMask->data.PS_TYPE_VECTOR_MASK_DATA[i] = PM_PATTERN_TWEAK;
+            numTweak++;
+        }
+    }
+    if (numTweak == 0) {
+        // Nothing to do
+        psFree(meanMask);
+        return true;
+    }
+
+    // Measure mean of each cell edge, and use that to determine the cell offsets.
+
+    psStats *bgStats = psStatsAlloc(bgStat); // Statistics on background
+    psRandom *rng = psRandomAlloc(PS_RANDOM_TAUS); // Random number generator
+
+    psRegion region = {0,0,0,0};
+
+    /* These images hold the edge data for the OTA structure.  */
+    psImage *A = psImageAlloc(8,8,PS_TYPE_F64); // Top edge
+    psImage *B = psImageAlloc(8,8,PS_TYPE_F64); // Bottom edge
+    psImage *C = psImageAlloc(8,8,PS_TYPE_F64); // Right edge
+    psImage *D = psImageAlloc(8,8,PS_TYPE_F64); // Left edge
+    
+    for (int i = 0; i < numCells; i++) {
+        if (meanMask->data.PS_TYPE_VECTOR_MASK_DATA[i] & PM_PATTERN_IGNORE) {
+            continue;
+        }
+        pmCell *cell = chip->cells->data[i]; // Cell of interest
+        pmReadout *ro = cell->readouts->data[0]; // Readout of interest
+
+        psStatsInit(bgStats);
+
+	// Convert cell iterator i into an xy coordinate on the grid of cells
+	int y = (i % 8);
+	int x = (i - y) / 8;
+	
+	for (int j = 0; j < 4; j++) {
+	  if (j == 0) {  // Region B
+	    region = psRegionSet(0,ro->image->numCols,
+				 0,edgeWidth);
+	  }
+	  else if (j == 1) { // Region A
+	    region = psRegionSet(0,ro->image->numCols,
+				 ro->image->numRows - edgeWidth,ro->image->numRows);
+	  }
+	  else if (j == 2) { // Region D
+	    region = psRegionSet(0,edgeWidth,
+				 0,ro->image->numRows);
+	  }
+	  else if (j == 3) { // Region C
+	    region = psRegionSet(ro->image->numCols - edgeWidth,ro->image->numCols,
+				 0,ro->image->numRows);
+	  }
+	  psImage *subset  = psImageSubset(ro->image,region);
+	  psImage *submask = psImageSubset(ro->mask,region);
+
+	  if (!psImageBackground(bgStats, NULL, subset, submask, maskVal, rng)) {
+            psWarning("Unable to measure background for cell %d on edge %d\n", i, j);
+            psErrorClear();
+            meanMask->data.PS_TYPE_VECTOR_MASK_DATA[i] |= PM_PATTERN_ERROR;
+	    if (j == 0)      { B->data.F64[y][x] = NAN; }
+	    else if (j == 1) { A->data.F64[y][x] = NAN; }
+	    else if (j == 2) { C->data.F64[y][x] = NAN; }
+	    else if (j == 3) { D->data.F64[y][x] = NAN; }
+	    psFree(subset);
+	    psFree(submask);
+            continue; // Move on to next edge, as only part of this cell may be a problem
+	  }
+
+	  // If the returned value is zero, assume something is wrong.  Do I still need this?
+	  if (psStatsGetValue(bgStats,bgStat) < 1e-6) {
+	    if (j == 0)      { B->data.F64[y][x] = NAN; }
+	    else if (j == 1) { A->data.F64[y][x] = NAN; }
+	    else if (j == 2) { C->data.F64[y][x] = NAN; }
+	    else if (j == 3) { D->data.F64[y][x] = NAN; }
+	  }
+	  // If we have an error for this cell/edge, make sure we mask the value
+	  if (meanMask->data.PS_TYPE_VECTOR_MASK_DATA[i] & PM_PATTERN_ERROR) {
+	    if (j == 0)      { B->data.F64[y][x] = NAN; }
+	    else if (j == 1) { A->data.F64[y][x] = NAN; }
+	    else if (j == 2) { C->data.F64[y][x] = NAN; }
+	    else if (j == 3) { D->data.F64[y][x] = NAN; }
+	  }
+	  else { // Set the value to match what we got from the edge box.
+	    if (j == 0)      { B->data.F64[y][x] = psStatsGetValue(bgStats,bgStat); }
+	    else if (j == 1) { A->data.F64[y][x] = psStatsGetValue(bgStats,bgStat); }
+	    else if (j == 2) { C->data.F64[y][x] = psStatsGetValue(bgStats,bgStat); }
+	    else if (j == 3) { D->data.F64[y][x] = psStatsGetValue(bgStats,bgStat); }
+	  }
+	  psFree(subset);
+	  psFree(submask);
+
+	}
+	psTrace("psModules.detrend.cont",5, "OTA: %d (%d %d) A: %f B: %f C: %f D: %f",
+		i,x,y,
+		A->data.F32[y][x],B->data.F32[y][x],C->data.F32[y][x],D->data.F32[y][x]);		
+    }
+    psFree(bgStats);
+    psFree(rng);
+
+    // We've now allocated all the edge values, so we can now minimize the offsets.
+    // This involves solving the equation A x = b, where
+    // A is the (64x64 for GPC1) matrix containing the edges that match for each cell
+    // x is the solution vector
+    // b is the combination of offsets across each cell boundary for each cell.
+    // Below "XX" is used as the matrix A, and "solution" is used as both b and x
+    //   (due to the way psMatrixLUSolve operates).
+    psVector *solution = psVectorAlloc(64,PS_TYPE_F64);
+    psImage  *XX       = psImageAlloc(64,64,PS_TYPE_F64);
+    psVectorInit(solution,0.0);
+    psImageInit(XX,0.0);
+    
+    for (int i = 0; i < numCells; i++) {
+      // Accumulate all the possible edge differences we can for this cell.
+      // As we do so, make a note of the correlations by incrementing the element of the matrix.
+      int y = (i % 8);
+      int x = (i - y) / 8;
+      int j;
+      if (meanMask->data.PS_TYPE_VECTOR_MASK_DATA[i] & PM_PATTERN_IGNORE) {
+	continue;
+      }
+      if (x + 1 < 8) {  // We have a neighbor adjacent in the +x direction
+	j = 8 * (x + 1) + y; // Determine that neighbor's index
+	psTrace("psModules.detrend.cont",5,"CmD %d %d %d %d %g %g", // diagnostic
+		i,x,y,j,
+		C->data.F64[y][x],
+		D->data.F64[y][x+1]
+		);
+	if (!(meanMask->data.PS_TYPE_VECTOR_MASK_DATA[j] & PM_PATTERN_IGNORE)&&  // If there are no errors with the neighbor,
+	    (isfinite(C->data.F64[y][x]))&&(isfinite(D->data.F64[y][x+1]))) {    // and all edges have valid values:
+	  solution->data.F64[i] += C->data.F64[y][x] - D->data.F64[y][x+1];     // Take the difference
+	  XX->data.F64[i][i] += 1;                                              // increment our relation with ourself
+	  XX->data.F64[i][j] += -1;                                             // decrement our relation with the neighbor
+	}
+      }
+      if (x - 1 > -1) { // etc.
+	j = 8 * (x - 1) + y;
+	psTrace("psModules.detrend.cont",5,"DmC %d %d %d %d %g %g",
+		i,x,y,j,
+		D->data.F64[y][x],
+		C->data.F64[y][x-1]
+		);
+
+	if (!(meanMask->data.PS_TYPE_VECTOR_MASK_DATA[j] & PM_PATTERN_IGNORE)&&
+	    (isfinite(D->data.F64[y][x]))&&(isfinite(C->data.F64[y][x-1]))) {
+	  solution->data.F64[i] += D->data.F64[y][x] - C->data.F64[y][x-1];
+	  XX->data.F64[i][i] += 1;
+	  XX->data.F64[i][j] += -1;
+	}
+      }
+      if (y + 1 < 8) {
+	j = 8 * x + (y + 1);
+	psTrace("psModules.detrend.cont",5,"AmB %d %d %d %d %g %g",
+		i,x,y,j,
+		A->data.F64[y][x],
+		B->data.F64[y+1][x]
+		);
+
+	if (!(meanMask->data.PS_TYPE_VECTOR_MASK_DATA[j] & PM_PATTERN_IGNORE)&&
+	    (isfinite(A->data.F64[y][x]))&&(isfinite(B->data.F64[y+1][x]))) {
+	  solution->data.F64[i] += A->data.F64[y][x] - B->data.F64[y+1][x];
+	  XX->data.F64[i][i] += 1;
+	  XX->data.F64[i][j] += -1;
+	}
+      }
+      if (y - 1 > -1) {
+	j = 8 * x +  (y - 1);
+	psTrace("psModules.detrend.cont",5,"BmA %d %d %d %d %g %g",
+		i,x,y,j,
+		B->data.F64[y][x],
+		A->data.F64[y-1][x]
+		);
+
+	if (!(meanMask->data.PS_TYPE_VECTOR_MASK_DATA[j] & PM_PATTERN_IGNORE)&&
+	    (isfinite(B->data.F64[y][x]))&&(isfinite(A->data.F64[y-1][x]))) {
+	  solution->data.F64[i] += B->data.F64[y][x] - A->data.F64[y-1][x];
+	  XX->data.F64[i][i] += 1;
+	  XX->data.F64[i][j] += -1;
+	}
+      }
+    }
+    for (int i = 0; i < numCells; i++) { // If any cells have no value of themself, set the matrix to 1.0.
+      if (XX->data.F64[i][i] == 0.0) {
+	XX->data.F64[i][i] = 1.0;
+      }
+    }
+#if (0)
+    for (int i = 0; i < numCells; i++) { // print matrix A
+      psTrace("psModules.detrend.cont",5,"A: %3d % 2.0f % 2.0f % 2.0f % 2.0f % 2.0f % 2.0f % 2.0f % 2.0f % 2.0f % 2.0f % 2.0f % 2.0f % 2.0f % 2.0f % 2.0f % 2.0f % 2.0f % 2.0f % 2.0f % 2.0f % 2.0f % 2.0f % 2.0f % 2.0f % 2.0f % 2.0f % 2.0f % 2.0f % 2.0f % 2.0f % 2.0f % 2.0f % 2.0f % 2.0f % 2.0f % 2.0f % 2.0f % 2.0f % 2.0f % 2.0f % 2.0f % 2.0f % 2.0f % 2.0f % 2.0f % 2.0f % 2.0f % 2.0f % 2.0f % 2.0f % 2.0f % 2.0f % 2.0f % 2.0f % 2.0f % 2.0f % 2.0f % 2.0f % 2.0f % 2.0f % 2.0f % 2.0f % 2.0f % 2.0f",
+	      i,
+	      XX->data.F64[i][0],	      XX->data.F64[i][1],	      XX->data.F64[i][2],	      XX->data.F64[i][3],
+	      XX->data.F64[i][4],	      XX->data.F64[i][5],	      XX->data.F64[i][6],	      XX->data.F64[i][7],
+	      XX->data.F64[i][8],	      XX->data.F64[i][9],	      XX->data.F64[i][10],	      XX->data.F64[i][11],
+	      XX->data.F64[i][12],	      XX->data.F64[i][13],	      XX->data.F64[i][14],	      XX->data.F64[i][15],
+	      XX->data.F64[i][16],	      XX->data.F64[i][17],	      XX->data.F64[i][18],	      XX->data.F64[i][19],
+	      XX->data.F64[i][20],	      XX->data.F64[i][21],	      XX->data.F64[i][22],	      XX->data.F64[i][23],
+	      XX->data.F64[i][24],	      XX->data.F64[i][25],	      XX->data.F64[i][26],	      XX->data.F64[i][27],
+	      XX->data.F64[i][28],	      XX->data.F64[i][29],	      XX->data.F64[i][30],	      XX->data.F64[i][31],
+	      XX->data.F64[i][32],	      XX->data.F64[i][33],	      XX->data.F64[i][34],	      XX->data.F64[i][35],
+	      XX->data.F64[i][36],	      XX->data.F64[i][37],	      XX->data.F64[i][38],	      XX->data.F64[i][39],
+	      XX->data.F64[i][40],	      XX->data.F64[i][41],	      XX->data.F64[i][42],	      XX->data.F64[i][43],
+	      XX->data.F64[i][44],	      XX->data.F64[i][45],	      XX->data.F64[i][46],	      XX->data.F64[i][47],
+	      XX->data.F64[i][48],	      XX->data.F64[i][49],	      XX->data.F64[i][50],	      XX->data.F64[i][51],
+	      XX->data.F64[i][52],	      XX->data.F64[i][53],	      XX->data.F64[i][54],	      XX->data.F64[i][55],
+	      XX->data.F64[i][56],	      XX->data.F64[i][57],	      XX->data.F64[i][58],	      XX->data.F64[i][59],
+	      XX->data.F64[i][60],	      XX->data.F64[i][61],	      XX->data.F64[i][62],	      XX->data.F64[i][63]
+	      );
+    }
+
+    for (int i = 0; i < numCells; i++) { // print vector b
+      psTrace("psModules.detrend.cont",5,"b: %d %f",
+	      i,
+	      solution->data.F64[i]
+	      );
+    }
+#endif    
+    
+    // Solve the Ax=b equation
+    psMatrixLUSolve(XX,solution);
+
+    /* old code to remove the minimum solution value from the set, to give a "minimal set of offsets." Mathematically unnecessary. */
+/*     double min = 99e99; */
+/*     for (int i = 0; i < numCells; i++) { */
+/*       if (solution->data.F64[i] < min) { */
+/* 	min = solution->data.F64[i]; */
+/*       } */
+/*       psTrace("psModules.detrend.cont",5,"x: %d %f %f ", */
+/* 	      i, */
+/* 	      solution->data.F64[i],min */
+/* 	      ); */
+/*     } */
+/*     for (int i = 0; i < numCells; i++) { */
+/* 	if (solution->data.F64[i] != 0.0) { */
+/* 	  solution->data.F64[i] -= min; */
+/* 	} */
+/*     } */
+
+    // Cleanup
+    psFree(XX);
+    psFree(A);
+    psFree(B);
+    psFree(C);
+    psFree(D);
+
+    // Correct cells based on the offsets calculated, and store the result in the analysis metadata.
+    for (int i = 0; i < numCells; i++) {
+        if (meanMask->data.PS_TYPE_VECTOR_MASK_DATA[i] & PM_PATTERN_IGNORE) {
+            continue;
+        }
+        if (!(meanMask->data.PS_TYPE_VECTOR_MASK_DATA[i] & PM_PATTERN_TWEAK)) {
+            continue;
+        }
+        pmCell *cell = chip->cells->data[i]; // Cell of interest
+        pmReadout *ro = cell->readouts->data[0]; // Readout of interest
+
+        float correction = solution->data.F64[i];
+        const char *cellName = psMetadataLookupStr(NULL, cell->concepts, "CELL.NAME"); // Name of cell
+        psLogMsg("psModules.detrend", PS_LOG_DETAIL, "Correcting background of cell %s by %f",
+                 cellName, correction);
+        psBinaryOp(ro->image, ro->image, "-", psScalarAlloc(correction, PS_TYPE_F32));
+        psMetadataAddF32(ro->analysis, PS_LIST_TAIL, PM_PATTERN_CELL_CORRECTION, PS_META_REPLACE,
+                         "Pattern cell correction solution", correction);
+    }
+
+    psFree(solution);
+    psFree(meanMask);
+
+    return true;
+}
+
+bool pmPatternContinuityApply(pmReadout *ro, psImageMaskType maskBad)
+{
+    PM_ASSERT_READOUT_NON_NULL(ro, false);
+    PM_ASSERT_READOUT_IMAGE(ro, false);
+
+    bool mdok;                          // Status of MD lookup
+    float corr = psMetadataLookupF32(&mdok, ro->analysis, PM_PATTERN_CELL_CORRECTION); // Correction to apply
+    if (!mdok) {
+        // No correction to apply
+        return true;
+    }
+
+    psImage *image = ro->image, *mask = ro->mask; // Image and mask of interest
+    int numCols = image->numCols, numRows = image->numRows; // Size of image
+
+    if (!isfinite(corr)) {
+        for (int y = 0; y < numRows; y++) {
+            for (int x = 0; x < numCols; x++) {
+                image->data.F32[y][x] = NAN;
+            }
+        }
+        if (mask) {
+            for (int y = 0; y < numRows; y++) {
+                for (int x = 0; x < numCols; x++) {
+                    mask->data.PS_TYPE_IMAGE_MASK_DATA[y][x] |= maskBad;
+                }
+            }
+        }
+    } else {
+        for (int y = 0; y < numRows; y++) {
+            for (int x = 0; x < numCols; x++) {
+                image->data.F32[y][x] += corr;
+            }
+        }
+    }
+
+    return true;
+}
+
+
Index: trunk/psModules/src/detrend/pmPattern.h
===================================================================
--- trunk/psModules/src/detrend/pmPattern.h	(revision 33237)
+++ trunk/psModules/src/detrend/pmPattern.h	(revision 33243)
@@ -54,4 +54,21 @@
                         );
 
+/// Fix the background on cells known to be troublesome
+bool pmPatternContinuity(
+    pmChip *chip,                       ///< Chip to correct
+    const psVector *tweak,              ///< U8 vector indicating whether to tweak the corresponding cell
+    psStatsOptions bgStat,              ///< Statistic to use for background measurement
+    psStatsOptions cellStat,            ///< Statistic to use for combination of cell background measurements
+    psImageMaskType maskVal,            ///< Mask value to use
+    psImageMaskType maskBad,            ///< Mask value to give bad pixels
+    int edgeWidth                       ///< Size of box to use
+    );
+
+/// Apply previously measured cell pattern correction
+bool pmPatternContinuityApply(pmReadout *ro,          ///< Readout to correct
+                        psImageMaskType maskBad ///< Mask value to give bad pixels
+                        );
+
+
 
 /// @}
