Change Binary files to ASCII

Queries about input and output files, running specific calculations, etc.


Moderators: Global Moderator, Moderator

Post Reply
Message
Author
mamini
Newbie
Newbie
Posts: 3
Joined: Tue May 18, 2010 9:18 am
License Nr.: 5-568

Change Binary files to ASCII

#1 Post by mamini » Tue May 18, 2010 1:48 pm

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,
Last edited by mamini on Tue May 18, 2010 1:48 pm, edited 1 time in total.

panda

Change Binary files to ASCII

#2 Post by panda » Tue May 18, 2010 3:19 pm

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.
Last edited by panda on Tue May 18, 2010 3:19 pm, edited 1 time in total.

panda

Change Binary files to ASCII

#3 Post by panda » Tue May 18, 2010 3:23 pm

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 :)
Last edited by panda on Tue May 18, 2010 3:23 pm, edited 1 time in total.

forsdan
Sr. Member
Sr. Member
Posts: 339
Joined: Mon Apr 24, 2006 9:07 am
License Nr.: 173
Location: Gothenburg, Sweden

Change Binary files to ASCII

#4 Post by forsdan » Tue May 18, 2010 3:51 pm

The LOCPOT file is a standard text file so you can read it directly in a text editor.

/Dan
Last edited by forsdan on Tue May 18, 2010 3:51 pm, edited 1 time in total.

panda

Change Binary files to ASCII

#5 Post by panda » Tue May 18, 2010 8:01 pm

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...
Last edited by panda on Tue May 18, 2010 8:01 pm, edited 1 time in total.

mamini
Newbie
Newbie
Posts: 3
Joined: Tue May 18, 2010 9:18 am
License Nr.: 5-568

Change Binary files to ASCII

#6 Post by mamini » Wed May 19, 2010 8:23 am

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. :)
Last edited by mamini on Wed May 19, 2010 8:23 am, edited 1 time in total.

admin
Administrator
Administrator
Posts: 2921
Joined: Tue Aug 03, 2004 8:18 am
License Nr.: 458

Change Binary files to ASCII

#7 Post by admin » Fri May 28, 2010 3:16 pm

dan is absolutey correct, LOCPOT is a standard ASCII text file
Last edited by admin on Fri May 28, 2010 3:16 pm, edited 1 time in total.

Post Reply