Problem reading a binary file in fortran
- From: "pradeep.bhattad@xxxxxxxxx" <pradeep.bhattad@xxxxxxxxx>
- Date: 17 Jan 2007 09:31:13 -0800
I am trying to read the binary data file of size 200*200*200 into the
fortran95 program, but i keep getting some erroneous values or an error
saing 'end of file reached'. However the following c program reads it
fine.
_____________________________________________________________________________
The working c program writen by my friend
#include <stdio.h>
int main() {
FILE *infile, *outfile;
int i;
infile = fopen("mid.bin","r+b");
outfile = fopen("mid.dat","w");
while ((i=fgetc(infile)) != EOF) {
fprintf(outfile,"%d\n",i);
}
close(infile);
close(outfile);
return(0);
}
___________________________________________________________________________________
The fortran program that i tried and does not work
program binary_read
implicit real*8(a-h,o-z)
integer,parameter::n=200
dimension::mat(n,n,n)
open(unit=1, file='mid.bin', form='unformatted')
read(1) (((mat(i,j,k),i=1,n),j=1,n),k=1,n)
close(1)
open(unit=2, file='mid.txt')
do k=1,n; do j=1,n
write(2,*) (mat(i,j,k),i=1,n)
enddo; enddo
close(2)
stop
end
____________________________________________________________________________
I would be great it anyone can help me read the binary file in fortran,
or modify my fortran code so that it resembles c program. I dont have
knowldge in c program and just working knowldge in fortran.
Thanks in advence
PRADEEP
.
- Follow-Ups:
- Re: Problem reading a binary file in fortran
- From: Gib Bogle
- Re: Problem reading a binary file in fortran
- From: Louis Krupp
- Re: Problem reading a binary file in fortran
- From: Gib Bogle
- Re: Problem reading a binary file in fortran
- From: glen herrmannsfeldt
- Re: Problem reading a binary file in fortran
- From: mecej4
- Re: Problem reading a binary file in fortran
- From: David Frank
- Re: Problem reading a binary file in fortran
- Prev by Date: Re: Passing Unallocated Allocatable arrays
- Next by Date: Re: gfortran and ifort unformatted files
- Previous by thread: using optional arguments
- Next by thread: Re: Problem reading a binary file in fortran
- Index(es):
Relevant Pages
|