Problem reading a binary file in fortran



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

.



Relevant Pages

  • Re: Problem reading a binary file in fortran
    ... int main{ ... enddo; enddo ... I would be great it anyone can help me read the binary file in fortran, ... knowldge in c program and just working knowldge in fortran. ...
    (comp.lang.fortran)
  • Re: grom c++ to fortran [not short]
    ... and fortran algorithms were logically equivalent, ... piv gets set, but lp, cp are set only after exit from the i-loop ... take a look at the EPSILON function ... > ENDDO ...
    (comp.lang.fortran)
  • Re: Fortran to matlab conversion
    ... > Tim Twomey wrote: ... >> no previous experience with fortran so it is proving difficult. ... > problems before you could even manage to get it to compile to start ... ENDDO ...
    (comp.soft-sys.matlab)
  • Re: Q about Array Manipulation in F90
    ... Now can I reduce the above two-fold loop into a single line in Fortran ... compiles as fast as anything else (you would have to measure or look ...
    (comp.lang.fortran)
  • Re: Q about F90 Array Manipulation
    ... which is more readable to the average Fortran programmer ... To someone who does not just talk about Fortran 90 or 95 but actually ... both sum the array in the slow dimension. ...
    (comp.lang.fortran)