I also have some information at the beginning of the file and between
each field.  Is there a way to get the info at the beginning and tell
it once it sees Leaf 1A to read the values for the next 120 and then
repeat until there are no more Fields.

File Rev = G
Treatment = Dynamic Dose
Last Name = Fodness
First Name = Bryan
Patient ID = 0001
Number of Fields = 4
Number of Leaves = 120
Tolerance = 0.50

Field = 10
Index = 0.0000
Carriage Group = 1
Operator =
Collimator = 0.0
Leaf  1A =   0.00
Leaf  2A =   0.00
Leaf  3A =   0.00
Leaf  4A =   0.00
...
Leaf 57B =   0.00
Leaf 58B =   0.00
Leaf 59B =   0.00
Leaf 60B =   0.00
Note = 0
Shape = 4
  500   500
  500  -500
 -500  -500
 -500   500
Magnification = 1.00

Field = 8
Index = 0.4000
Carriage Group = 1
Operator =
Collimator = 0.0
Leaf  1A =   0.00
Leaf  2A =   0.00
Leaf  3A =   0.00
Leaf  4A =   0.00
...
Leaf 57B =   0.00
Leaf 58B =   0.00
Leaf 59B =   0.00
Leaf 60B =   0.00
Note = 0
Shape = 4
  400   400
  400  -400
 -400  -400
 -400   400
Magnification = 1.00

I would like to have a data structure that I can use in one of the
graphing utilities (matpolotlib?).  I probably want to populate an
array with values, but I have not figured out how I want to do that
yet.

On Nov 7, 2007 8:52 AM, Kent Johnson <[EMAIL PROTECTED]> wrote:
> Bryan Fodness wrote:
> > I would like to have my data in a format so that I can create a contour 
> > plot.
> >
> > My data is in a file with a format, where there may be multiple fields
> >
> > field = 1
> >
> > 1a    0
>
> If your data is really this regular, it is pretty easy to parse. A
> useful technique is to access a file's next method directly. Something
> like this (not tested!):
>
> f = open('data.txt')
> fields = {} # build a dict of fields
> try:
>   while True:
>     # Get the field line
>     line = f.next()
>     field = int(line.split()[-1]) # last part of the line as an int
>
>     f.next() # skip blank line
>
>     data = {} # for each field, map (row, col) to value
>     for i in range(20): # read 20 data lines
>       line = f.next()
>       ix, value = f.split()
>       row = int(ix[:-1])
>       col = ix[-1]
>       data[row, col] = int(value)
>
>     fields[field] = data
>
>     f.next()
> except StopIteration:
>   pass
>
> This builds a dict whose keys are field numbers and values are
> themselves dicts mapping (row, col) pairs to a value.
>
> > where,
> >
> >                            a           b
> >   a           b                                 a            b
> > 10    0000000000|0000000000   0000000000|0000000000   0000000000|0000000000
> > 9     0000000000|0000000000   0000000000|0000000000   0000000000|0000000000
> > 8     0000011111|1111100000   0000000000|0000000000   0000000000|0000000000
> > 7     0000011111|1111100000   0000001111|1111000000   0000000000|0000000000
> > 6     0000011111|1111100000   0000001111|1111000000   0000000111|1110000000
> > 5     0000011111|1111100000   0000001111|1111000000   0000000111|1110000000
> > 4     0000011111|1111100000   0000001111|1111000000   0000000000|0000000000
> > 3     0000011111|1111100000   0000000000|0000000000   0000000000|0000000000
> > 2     0000000000|0000000000   0000000000|0000000000   0000000000|0000000000
> > 1     0000000000|0000000000   0000000000|0000000000   0000000000|0000000000
>
> I guess this is the intended output? Do you want to actually create a
> printed table like this, or some kind of data structure that represents
> the table, or what?
>
> Kent
>
_______________________________________________
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor

Reply via email to