[petsc-users] reading petsc binary vec in python.

Ataollah Mesgarnejad amesga1 at tigers.lsu.edu
Mon Jul 18 21:07:29 CDT 2011


I'm using 1.5.1 on my Mac with python 2.7. I changed the line and still getting the same error. Let me say this again that it doesn't make any sense since when I do it in python command line np.fromfile works fine and I get the right output. 

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/
> ------------------------------------
> 



More information about the petsc-users mailing list