Index: /issm/trunk-jpl/scripts/BinRead.py
===================================================================
--- /issm/trunk-jpl/scripts/BinRead.py	(revision 20891)
+++ /issm/trunk-jpl/scripts/BinRead.py	(revision 20892)
@@ -8,5 +8,5 @@
 import argparse
 
-def BinRead(filin,filout=''): #{{{
+def BinRead(filin,filout='',verbose=0): #{{{
 
 	print "reading binary file."
@@ -23,35 +23,41 @@
 			print "probable EOF: %s" % e
 			break
-		print "\nrecordnamesize = \"%d\"" % (recordnamesize)
+
+		print "============================================================================"
+		if verbose>2:
+			print "\nrecordnamesize = \"%d\"" % (recordnamesize)
 		recordname=struct.unpack('%ds' % recordnamesize,f.read(recordnamesize))[0]
-		print "recordname = '%s'" % recordname
+		print "field: %s" % recordname
 
 		#Step 2: read the data itself.
 		#first read length of record
 		reclen=struct.unpack('i',f.read(struct.calcsize('i')))[0]
-		print "reclen = %d" % reclen
+		if verbose>1:
+			print "reclen = %d" % reclen
 
 		#read data code: 
 		code=struct.unpack('i',f.read(struct.calcsize('i')))[0]
-		print "code = %d" % code
+		#print "code = %d (%s)" % (code,CodeToFormat(code))
+		print "Format = %s" % CodeToFormat(code)
 
 		if   code == FormatToCode('Boolean'):
 #			bval=struct.unpack('b',f.read(reclen-struct.calcsize('i')))[0]
 			bval=struct.unpack('i',f.read(reclen-struct.calcsize('i')))[0]
-			print "bval = %d" % bval
+			print "value = %d" % bval
 
 		elif code == FormatToCode('Integer'):
 			ival=struct.unpack('i',f.read(reclen-struct.calcsize('i')))[0]
-			print "ival = %d" % ival
+			print "value = %d" % ival
 
 		elif code == FormatToCode('Double'):
 			dval=struct.unpack('d',f.read(reclen-struct.calcsize('i')))[0]
-			print "dval = %f" % dval
+			print "value = %f" % dval
 
 		elif code == FormatToCode('String'):
 			strlen=struct.unpack('i',f.read(struct.calcsize('i')))[0]
-			print "strlen = %d" % strlen
+			if verbose>1:
+				print "strlen = %d" % strlen
 			sval=struct.unpack('%ds' % strlen,f.read(strlen))[0]
-			print "sval = '%s'" % sval
+			print "value = '%s'" % sval
 
 		elif code == FormatToCode('BooleanMat'):
@@ -64,10 +70,10 @@
 			s[0]=struct.unpack('i',f.read(struct.calcsize('i')))[0]
 			s[1]=struct.unpack('i',f.read(struct.calcsize('i')))[0]
-			print "s = [%dx%d]" % (s[0],s[1])
+			print "size = [%dx%d]" % (s[0],s[1])
 			data=numpy.zeros((s[0],s[1]))
 			for i in xrange(s[0]):
 				for j in xrange(s[1]):
 					data[i][j]=struct.unpack('d',f.read(struct.calcsize('d')))[0]    #get to the "c" convention, hence the transpose
-					print "data[%d,%d] = %f" % (i,j,data[i][j])
+					if verbose>2: print "data[%d,%d] = %f" % (i,j,data[i][j])
 
 		elif code == FormatToCode('IntMat'):
@@ -80,10 +86,10 @@
 			s[0]=struct.unpack('i',f.read(struct.calcsize('i')))[0]
 			s[1]=struct.unpack('i',f.read(struct.calcsize('i')))[0]
-			print "s = [%dx%d]" % (s[0],s[1])
+			print "size = [%dx%d]" % (s[0],s[1])
 			data=numpy.zeros((s[0],s[1]))
 			for i in xrange(s[0]):
 				for j in xrange(s[1]):
 					data[i][j]=struct.unpack('d',f.read(struct.calcsize('d')))[0]    #get to the "c" convention, hence the transpose
-					print "data[%d,%d] = %f" % (i,j,data[i][j])
+					if verbose>2: print "data[%d,%d] = %f" % (i,j,data[i][j])
 
 		elif code == FormatToCode('DoubleMat'):
@@ -96,10 +102,10 @@
 			s[0]=struct.unpack('i',f.read(struct.calcsize('i')))[0]
 			s[1]=struct.unpack('i',f.read(struct.calcsize('i')))[0]
-			print "s = [%dx%d]" % (s[0],s[1])
+			print "size = [%dx%d]" % (s[0],s[1])
 			data=numpy.zeros((s[0],s[1]))
 			for i in xrange(s[0]):
 				for j in xrange(s[1]):
 					data[i][j]=struct.unpack('d',f.read(struct.calcsize('d')))[0]    #get to the "c" convention, hence the transpose
-					print "data[%d,%d] = %f" % (i,j,data[i][j])
+					if verbose>2: print "data[%d,%d] = %f" % (i,j,data[i][j])
 
 		elif code == FormatToCode('MatArray'):
@@ -146,4 +152,34 @@
 	return code
 # }}}
+def CodeToFormat(code): # {{{
+	"""
+	This routine takes the format string, and hardcodes it into an integer, which 
+	is passed along the record, in order to identify the nature of the dataset being 
+	sent.
+	"""
+
+	if code==1:
+		format='Boolean'
+	elif code==2:
+		format='Integer'
+	elif code==3:
+		format='Double'
+	elif code==4:
+		format='String'
+	elif code==5:
+		format='BooleanMat'
+	elif code==6:
+		format='IntMat'
+	elif code==7:
+		format='DoubleMat'
+	elif code==8:
+		format='MatArray'
+	elif code==9:
+		format='StringArray'
+	else:
+		raise TypeError('FormatToCode error message: code %d not supported yet!' %code)
+
+	return format
+# }}}
 
 if __name__ == '__main__': #{{{
@@ -162,8 +198,9 @@
 	parser.add_argument('-f','--filin', help='name of binary input file', default='')
 	parser.add_argument('-o','--filout', help='optional name of text output file', default='')
+	parser.add_argument('-v','--verbose', help='optional level of output', default=0)
 	args = parser.parse_args()
 
 	from MatlabFuncs import *
 
-	BinRead(args.filin, args.filout)
+	BinRead(args.filin, args.filout,args.verbose)
 #}}}
