Reading mixed ASCII/bin file-HOW?

josegomez at gmx.net josegomez at gmx.net
Tue Dec 4 09:18:27 EST 2001


Hi all,
	I want to read a number of files, all of which have a header,
and then some data. More often than not :-), the data will be binary.
The file looks a bit like this:

31/05/00 16:59:01 
COMMENTS
Cal - C Band. 12 cm tri 
ENDOFCOMMENTS
NETWORK ANALYSER SETTINGS
4,            Start Freq (GHz)
6,            End Freq (GHz)
1601,         No. of Freqs per Step


	The order of the parameters (and units) is always the same, so
what I want to do is to read all that information into a dictionary. For
the previous example, that'd be
data = {'Date':"31/05/00",
	'Time':"16:59:01",
	'Comments':"Cal - C Band, 12 cm tri",
	'StartFreq':4.0,
	'EndFreq':6.0,
	'NumFreq':1601}

	Now, I don't reallu understand how this is done, but I guess
that I could parse it through a number of readline() calls. There has to
be a better way though...

	OK, and now we get to the problem of what to do if the file is
mixed  binary/ascii. Basically, after the header, I get a "delimiter"
in ASCII and a bunch of datapoints (to be calculated from the
information on the header). Also, if the data isn't binary and is ascii,
I get a lot of lines containing to numbers.

	In general, these datapoints fit neatly into a 2D complex array,
and I have to convert the pairs of reals into complex number (Re+j*Im),
for both ASCII and binary types.

	As you can see, I'm very much a newbie, and I am used to dealing
with this sort of things in fortran 77. I was wondering if any kind soul
might be able to help :-)

	Cheers,
	José
written in ASCII, and a lump of datapoints 


-- 
José L Gómez Dans			PhD student
Tel: +44 114 222 5582			Radar & Communications Group
FAX; +44 870 132 2990			Department of Electronic Engineering
					University of Sheffield UK



More information about the Python-list mailing list