elbarto_87
November 9th, 2009, 12:56 PM
Hi All,
I am taking part in another maths forum where the situation has come up to convert a binary file to a text file. I initially suggested python because I assumed there would be a suitable module out there but I am afraid I spoke to soon or haven't looked in the right places.
If someone could please take a look at the format of the .bin file and the desired resulting .txt file (we have the code to convert a single file only, but this is in fortran and we are trying to use python to convert multiple files) that would be greatly appreciated. I am just having trouble with where to look to convert a .bin file into a txt file with columns of integer values.
I have tried using the binascii module but I do not think this is the right module. I have changed the file extension to .doc so I could upload here. Any advice would be great.
Thank you,
Regards Elbarto
Fortran Code:
program:
implicit none
integer lat, lon, irec,x,y
real*4 bmap(180,90)
parameter(irec=180*90*4)
open(21,file=
& 'c_015.bip_c1.bin',
& access='direct',
& form='unformatted',
& recl=irec,status='old',err=999)
read(21,rec=1,err=999)
& ((bmap(lon,lat),lon=1,180),lat=1,90)
close(21)
open(31,file=
& 'c_015.bip_c1.txt',
& form='formatted')
do 123 y=1,90
write(31,30) (bmap(x,y),x=1,180)
30 Format(180F12.6)
123 continue
999 continue
stop
End
I am taking part in another maths forum where the situation has come up to convert a binary file to a text file. I initially suggested python because I assumed there would be a suitable module out there but I am afraid I spoke to soon or haven't looked in the right places.
If someone could please take a look at the format of the .bin file and the desired resulting .txt file (we have the code to convert a single file only, but this is in fortran and we are trying to use python to convert multiple files) that would be greatly appreciated. I am just having trouble with where to look to convert a .bin file into a txt file with columns of integer values.
I have tried using the binascii module but I do not think this is the right module. I have changed the file extension to .doc so I could upload here. Any advice would be great.
Thank you,
Regards Elbarto
Fortran Code:
program:
implicit none
integer lat, lon, irec,x,y
real*4 bmap(180,90)
parameter(irec=180*90*4)
open(21,file=
& 'c_015.bip_c1.bin',
& access='direct',
& form='unformatted',
& recl=irec,status='old',err=999)
read(21,rec=1,err=999)
& ((bmap(lon,lat),lon=1,180),lat=1,90)
close(21)
open(31,file=
& 'c_015.bip_c1.txt',
& form='formatted')
do 123 y=1,90
write(31,30) (bmap(x,y),x=1,180)
30 Format(180F12.6)
123 continue
999 continue
stop
End