Read a huge binary file

Read a huge binary file

Hi averyone.
I'm trying to read a huge (1024^3 real*4 elements) binary file written in fortran with these lines
...
open(unit=2,file =file2,form="unformatted",status="replace")

do i=1,imax
do j=1,jmax
do k = 1,kmax
cubevx(i,j,k) = vx(k+jmax*(j-1)+imax**2*(i-1))
end do
end do
write(*,*)' vx array -> binary cube...',100*i/imax,'%'
end do
write(*,*)'Writing binary file...',100*i/imax,'%'
write(2)cubevx
write(*,*)'data written at ',file2
close(2)
...
I'm trying to do this from a C program with the followings lines
...
fread(&lenght,sizeof(long long int),1,arch1);

printf("Reading bin file...\\n");
for(k=0; k
for(j=0; j
for(i=0; i
{
fread(&bindata,sizeof(float),1,arch1);
in[i*ny*nz+j*nz+k]=bindata;
}
}
fclose(arch1);
...
The code works ok for small arrays of number_elements<~800^3, but for
these huge 1000^3 file I'm getting bad answers (I'm computing a fft).
I computed the fft from the ascci version of the same file and I got
goods results (of course in much more time), so I'm thinking that due to
some reason I'm not reading the bin file in a good way.
The bin file has 4294967320 bytes = 1024^3 x 4 bytes + 24 bytes.
When I read the first 12 bytes with both a long int and a long long int I
get this number 4310503010900901897. I don't know how to understand it,
it is very diferent from 1024^3.
Thank you in advance.

publicaciones de 3 / 0 nuevos
Último envío
Para obtener más información sobre las optimizaciones del compilador, consulte el aviso sobre la optimización.
Imagen de jose-jesus-ambriz-meza

Hi!The function "fread" uses the second parameter for indicate the size of each reading, but in your code have: "sizeof(float)" this is equal to 4 bytes. this isn't good. at low level the computer done reading by "clusters" (over hard drive ) this represent more that 512 bytes. You need read more data and then process them on memory like you want it (if you want read each element with float ).

Imagen de jose-jesus-ambriz-meza

The function "fread" uses the second parameter for indicate the size of each reading, but in your code have: "sizeof(float)" this is equal to 4 bytes. this isn't good. at low level the computer done reading by "clusters" (over hard drive ) this represent more that 512 bytes. You need read more data and then process them on memory like you want it (if you want read each element with float ).best regards!

Inicie sesión para dejar un comentario.