On Tue, 2011-07-19 at 09:49 -0500, Ataollah Mesgarnejad wrote:
> Dear Ethan,
> 
> I started deciphering your code for some reason it tries to read header two 
> times and the error comes from the second try! 

That is the expected behavior.  The code cannot know, a priori, how many
vecs you have in your file.  The first pass reads the first vec, and the
second pass tries to read a second PETSc object but gets an empty file.
This is expected to error.  Line 119, the except line that I asked you
to change, is supposed to catch that error and tell the program that the
file is empty.  

However, I screwed up the line in my last email -- it should read:

except (MemoryError, IndexError):

That should fix your problem, and will be fixed in dev.

Ethan

> Is it normal for PetscBinaryRead to try to read header twice?
> 
> 
> Best,
> Ata
> On Jul 18, 2011, at 6:28 PM, Ethan Coon wrote:
> 
> > Hi Ata,
> > 
> > Can you tell me what version of numpy you're using?  In some older
> > versions of numpy, a "fromfile" called on a file with no data left to
> > read did not error, but instead returned an empty list.  This
> > implementation, since it doesn't know how many objects are in the file,
> > tries to read objects until it gets an error saying the file is empty.
> > Try something for me:
> > 
> > change line 119 of PetscBinaryRead.py to read:
> > 
> > except MemoryError, IndexError:
> > 
> > Does that fix it?  
> > 
> > Thanks,
> > 
> > Ethan
> > 
> > 
> > On Mon, 2011-07-18 at 17:56 -0500, Ataollah Mesgarnejad wrote:
> >> Thanks Ethan,
> >> 
> >> I did as you said but when I try to read the file using:
> >> 
> >> petsc_objs = PetscBinaryRead.readBinaryFile('V-018.bin')
> >> 
> >> I get the following error:
> >> 
> >> Traceback (most recent call last):
> >>  File "./petscvec.py", line 4, in <module>
> >>    petsc_objs = PetscBinaryRead.readBinaryFile('V-018.bin')
> >>  File 
> >> "/Users/ataollahmesgarnejad/Software/petsc-3.1/bin/python/PetscBinaryRead.py",
> >>  line 118, in readBinaryFile
> >>    header = np.fromfile(fid, dtype=IntType, count=1)[0]
> >> IndexError: index out of bounds
> >> 
> >> Which is peculiar since when I try to read the header myself using:
> >> 
> >> header=numpy.fromfile('V-018.bin',dtype='>i4',count=1) 
> >> print header[0]
> >> 
> >> I get:
> >> 
> >> 1211214
> >> 
> >> which is a Vec identifier.
> >> 
> >> Any thoughts on what goes wrong?
> >> 
> >> Best,
> >> Ata
> > 
> > -- 
> > ------------------------------------
> > Ethan Coon
> > Post-Doctoral Researcher
> > Applied Mathematics - T-5
> > Los Alamos National Laboratory
> > 505-665-8289
> > 
> > http://www.ldeo.columbia.edu/~ecoon/
> > ------------------------------------
> > 
> 

-- 
------------------------------------
Ethan Coon
Post-Doctoral Researcher
Applied Mathematics - T-5
Los Alamos National Laboratory
505-665-8289

http://www.ldeo.columbia.edu/~ecoon/
------------------------------------

Reply via email to