Index: /issm/trunk-jpl/src/m/solve/WriteData.py
===================================================================
--- /issm/trunk-jpl/src/m/solve/WriteData.py	(revision 21707)
+++ /issm/trunk-jpl/src/m/solve/WriteData.py	(revision 21708)
@@ -234,4 +234,74 @@
 				for j in xrange(s[1]):
 					fid.write(struct.pack('d',float(data[i][j])))    #get to the "c" convention, hence the transpose
+		# }}}
+
+	elif m.strcmpi(format,'CompressedMat'):    # {{{
+
+		if   isinstance(data,(bool,int,long,float)):
+			data=np.array([data])
+		elif isinstance(data,(list,tuple)):
+			data=np.array(data).reshape(-1,)
+		if np.ndim(data) == 1:
+			if np.size(data):
+				data=data.reshape(np.size(data),)
+			else:
+				data=data.reshape(0,0)
+
+		#Get size
+		s=data.shape
+		if np.ndim(data) == 1:
+		   n2=1
+		else:
+			n2=s[1]
+
+		#if matrix = NaN, then do not write anything
+		if np.ndim(data)==1 and np.product(s)==1 and np.all(np.isnan(data)):
+			s=(0,0)
+			n2=0
+
+		#first write length of record
+		recordlength=4+4+8+8+1*(s[0]-1)*n2+8*n2+4+4 #2 integers (32 bits) + the matrix + code + matrix type
+		if recordlength > 4**31 :
+			raise ValueError('field %s cannot be marshalled because it is larger than 4^31 bytes!' % enum)
+
+		fid.write(struct.pack('i',recordlength))  #2 integers (32 bits) + the matrix + code + matrix type
+
+		#write data code and matrix type: 
+		fid.write(struct.pack('i',FormatToCode(format))) 
+		fid.write(struct.pack('i',mattype))
+
+		#Write offset and range
+		A = data[0:s[0]-1]
+		offsetA = A.min()
+		rangeA = A.max() - offsetA
+
+		if rangeA == 0:
+			A = A*0 
+		else:
+			A = (A-offsetA)/rangeA*255. 
+		
+		#now write matrix
+		if np.ndim(data) == 1:
+			fid.write(struct.pack('i',s[0])) 
+			fid.write(struct.pack('i',1)) 
+			fid.write(struct.pack('d',float(offsetA)))
+			fid.write(struct.pack('d',float(rangeA)))
+			for i in xrange(s[0]-1):
+				fid.write(struct.pack('B',int(A[i])))
+
+			fid.write(struct.pack('d',float(data[s[0]-1])))    #get to the "c" convention, hence the transpose
+
+		elif np.product(s) > 0:
+			fid.write(struct.pack('i',s[0])) 
+			fid.write(struct.pack('i',s[1])) 
+			fid.write(struct.pack('d',float(offsetA)))
+			fid.write(struct.pack('d',float(rangeA)))
+			for i in xrange(s[0]-1):
+				for j in xrange(s[1]):
+					fid.write(struct.pack('B',int(A[i][j])))    #get to the "c" convention, hence the transpose
+
+			for j in xrange(s[1]):
+				fid.write(struct.pack('d',float(data[s[0]-1][j])))
+
 		# }}}
 
@@ -337,4 +407,6 @@
 	elif m.strcmpi(format,'StringArray'):
 		code=9
+	elif m.strcmpi(format,'CompressedMat'):
+		code=10
 	else:
 		raise InputError('FormatToCode error message: data type not supported yet!')
