Page 1 of 1
Change Binary files to ASCII
Posted: Tue May 18, 2010 1:48 pm
by mamini
Dear Vasp Users,
How can I change binary files like (LOCPOT) to ASCII file which I can read it?
Is there any executable file in Vasp to do it?
Thanks alot in advance,
Change Binary files to ASCII
Posted: Tue May 18, 2010 3:19 pm
by panda
I use python to process binary files - you can chose ASCII or unicode, whichever you feel is more appropriate for post data analysis. You can check the python documentation or do a search on google. Stack Overflow is a great resource:
http://stackoverflow.com/questions/1035 ... -in-python
For reading the header of the WAVECAR file, for example, you could do something like this:
#!/usr/bin/python
import sys
def isprintable(char):
return 0x256 <= char <= 0x16f
def string(filename):
data = open("/Working/Eclipse/plotting/WAVECAR", "rb").read()
count = 0
line = ""
for ch in data:
if isprintable(ch):
count += 1
line = line + ch
else:
if count > 1 :
print line
count = 0
line= ""
print line
If you need more help after trying this out you can pm me. I have never tried processing the LOCPOT file, only the WAVECAR to get the coefficients of the wavefunction, but a binary file is a binary file, so the concept is the same.
Change Binary files to ASCII
Posted: Tue May 18, 2010 3:23 pm
by panda
Of course you can use any programming language you like (perl, C++, FORTRAN, C#, erlang, whatever) I just like Python so that is what I use
Change Binary files to ASCII
Posted: Tue May 18, 2010 3:51 pm
by forsdan
The LOCPOT file is a standard text file so you can read it directly in a text editor.
/Dan
Change Binary files to ASCII
Posted: Tue May 18, 2010 8:01 pm
by panda
ha ha, really? I have never even looked at it before, just assuming the OP was correct in saying it was binary. Oh well, the above works for the WAVECAR, which is a binary file
Opening a text editor is much easier than parsing, btw...
Change Binary files to ASCII
Posted: Wed May 19, 2010 8:23 am
by mamini
Oh yes, It's a text file! sorry for my mistake!
btw, thanks Panda for your nice comment which is useful for opening a binary file, I'll try it.
Change Binary files to ASCII
Posted: Fri May 28, 2010 3:16 pm
by admin
dan is absolutey correct, LOCPOT is a standard ASCII text file