Small script to convert output of reporter to Octave/Matlab

"Erwin Aertbelien" <[email protected]> Wed, 19 Oct 2005 13:53:58 +0200
Newsgroups gmane.science.robotics.orocos.user
Message-ID <NJEHIOHNIHMOAMBCLFKFOEDHCCAA.Erwin.Aertbelien@mech.kuleuven.ac.be>
To whom it's usefull for,

Included you'll find a small python script to translate
the output of the reporter extension to Octave/Matlab workspace
with meaningfull variables.

the script does the following :
  - reads report.txt
  - writers report.dat
  - writers report.m to read out report.dat and present it as variables
    in the Octave/matlab workspace.


you can access the data in Octave/Matlab, use report.m to load data.

Best regards,
Erwin

-- 
Erwin Aertbelien 
Office 02.071                    [email protected]
Dep. of Mech. Eng., div. PMA                 tel : +32 (0)16 32 25 14
Celestijnenlaan 300B                         fax : +32 (0)16 32 29 87 
B-3001 HEVERLEE
BELGIUM







Disclaimer: http://www.kuleuven.be/cwis/email_disclaimer.htm

_______________________________________________
Orocos mailing list
[email protected]
http://lists.mech.kuleuven.be/mailman/listinfo/orocos
convert.py (application/octet-stream, 2.1 KB)
#!/usr/bin/python
#
# Python script to read an orocos report file and construct
# an m-file to read this file.  Does not work very well
# with nested output structures.  If used for other types
# then std::vector<double> and MotCon::Twist you probably have
# to edit this file.
#
#
# Erwin Aertbelien, oct. 2005
# =================================================================
import re

inp = open('report.txt','r')
outp = open('report.dat','w')
outpm = open('loadreport.m','w')
outpm.write('load report.dat\n')
linenr = 0;
line1expr = re.compile("\|\s*(\w+)::(\w+)")	
line3expr = re.compile("\s*(\w*)\s*(\<[^\|]*\>)?\s*\|")	
pos1   = []
name1a  = []
name1b = []
name3a  = []
name3b  = []
name3c  = []
size3  = []
offs3  = []
count  = 1 
for line in inp:
	linenr=linenr+1
	if (linenr==1):
		print line
		iter = line1expr.finditer(line)	
		for match in iter:
			pos1.append(match.start())
			name1a.append(match.group(1))
			name1b.append(match.group(2))
			print match.group(1)
			print match.group(2)
		pos1.append(10000)
	if (linenr==3):
		iter = line3expr.finditer(line)	
		for match in iter:
			#pos1.append(match.start())
			if (match.group(1) == ""):
				name3c.append("time")
				size3.append(1)
				offs3.append(0)
			else : 
				if (match.group(2) == "<std::vector<double>>"):
					name3c.append(match.group(1))
					size3.append(7)
					offs3.append(1)
				else :
					if (match.group(2) == "<MotCon::Twist>"):
						name3c.append(match.group(1))
						size3.append(6)
						offs3.append(0)
					else:
						print "Unknown size of "+match.group(2)
			pos3 = match.start()
			if (pos3 >= pos1[count]):
				count=count+1	
			name3a.append(name1a[count-1])
			name3b.append(name1b[count-1])
	if (linenr >5):
		outp.write(line)
print pos1
print name1a
print name1b
print name3a
print name3b
print name3c
print size3
print offs3

count = 1;
for i in range(1,len(name3c)):
	countstart = count+offs3[i]
	countend   = count+size3[i]-1
	outpm.write( name3a[i]+"."+name3b[i]+"."+name3c[i]+"= report(:,"+str(countstart)+":"+str(countend)+");\n")
	count = countend+1

inp.close()
outp.close()
outpm.close()