- Marcar como novo
- Marcador
- Subscrever
- Silenciar
- Subscrever fonte RSS
- Destacar
- Imprimir
- Denunciar conteúdo inapropriado
Hi Everyone!
I am trying to read/write binary data to files in FORTRAN using the Intel compiler that will be read/write with Matlab. I have successfully done this however the runtime for large files is slow. A small example of my code for writting a binary file is,
real*8 a(10)
open(unit = 1, file = 'foo.dat', form = 'unformatted', recordtype = 'stream')
do i = 1,10
write(1) a(10)
end do
I believe that I am being slowed down by constantly fetching the A data in memory? Is there a way I can write the vector A as is done in C using FWRITE where one specifies the number of bytes and the loop is eliminated?
I also need to write COMPLEX data into the output. I am currently doing the following (Matlab stores real() and imag() data in separate vectors),
complex*16 b(10)
do i = 1,10
write(1) real(b(i))
end do
do i = 1,20
write(1) imag(b(i))
end do
Is there a way this can be done using a type of STRIDE variable as opposed to storing the real and imaginary parts in separate vectors? Since in FORTRAN, the real/imaginary parts are interlaced, is there a way of writing every other value? For example, if we were to write out B,
real(b(1)) imag(b(1)) real(b(2)) imag(b(2)) ...
byte chunk 1 byte chunk 2 byte chunk 3 byte chunk 4 .....
I would want to write byte chunk 1,3,5, ... for the reals and chunk 2,4,6,... for the imaginary data.
Thank you very much for your time. Any help would be greatly appreciated.
Sincerely,
David
I am trying to read/write binary data to files in FORTRAN using the Intel compiler that will be read/write with Matlab. I have successfully done this however the runtime for large files is slow. A small example of my code for writting a binary file is,
real*8 a(10)
open(unit = 1, file = 'foo.dat', form = 'unformatted', recordtype = 'stream')
do i = 1,10
write(1) a(10)
end do
I believe that I am being slowed down by constantly fetching the A data in memory? Is there a way I can write the vector A as is done in C using FWRITE where one specifies the number of bytes and the loop is eliminated?
I also need to write COMPLEX data into the output. I am currently doing the following (Matlab stores real() and imag() data in separate vectors),
complex*16 b(10)
do i = 1,10
write(1) real(b(i))
end do
do i = 1,20
write(1) imag(b(i))
end do
Is there a way this can be done using a type of STRIDE variable as opposed to storing the real and imaginary parts in separate vectors? Since in FORTRAN, the real/imaginary parts are interlaced, is there a way of writing every other value? For example, if we were to write out B,
real(b(1)) imag(b(1)) real(b(2)) imag(b(2)) ...
byte chunk 1 byte chunk 2 byte chunk 3 byte chunk 4 .....
I would want to write byte chunk 1,3,5, ... for the reals and chunk 2,4,6,... for the imaginary data.
Thank you very much for your time. Any help would be greatly appreciated.
Sincerely,
David
- Marcas:
- Intel® Fortran Compiler
Link copiado
6 Respostas
- Marcar como novo
- Marcador
- Subscrever
- Silenciar
- Subscrever fonte RSS
- Destacar
- Imprimir
- Denunciar conteúdo inapropriado
write(1) A(1:10)
- Marcar como novo
- Marcador
- Subscrever
- Silenciar
- Subscrever fonte RSS
- Destacar
- Imprimir
- Denunciar conteúdo inapropriado
Quoting - david.sallngc.com
...
real*8 a(10)
open(unit = 1, file = 'foo.dat', form = 'unformatted', recordtype = 'stream')
do i = 1,10
write(1) a(10)
end do
I believe that I am being slowed down by constantly fetching the A data in memory? Is there a way I can write the vector A as is done in C using FWRITE where one specifies the number of bytes and the loop is eliminated?
real*8 a(10)
open(unit = 1, file = 'foo.dat', form = 'unformatted', recordtype = 'stream')
do i = 1,10
write(1) a(10)
end do
I believe that I am being slowed down by constantly fetching the A data in memory? Is there a way I can write the vector A as is done in C using FWRITE where one specifies the number of bytes and the loop is eliminated?
Instead of Fortran WRITE, use the Win32 API function WriteFile:
lret = WriteFile(handl, LOC(A), 10*SIZEOF(A(1)), NULL, os)
This does exactly what you want.
- Marcar como novo
- Marcador
- Subscrever
- Silenciar
- Subscrever fonte RSS
- Destacar
- Imprimir
- Denunciar conteúdo inapropriado
Quoting - jimdempseyatthecove
write(1) A(1:10)
Thanks Jim. I can not believe that is all that is necessary!
How about if my vector is complex? Is there a way to write all REAL's and IMAG's separately usig some type of indexing?
Thanks again.
Sincerely,
David
- Marcar como novo
- Marcador
- Subscrever
- Silenciar
- Subscrever fonte RSS
- Destacar
- Imprimir
- Denunciar conteúdo inapropriado
Quoting - Paul Curtis
Instead of Fortran WRITE, use the Win32 API function WriteFile:
lret = WriteFile(handl, LOC(A), 10*SIZEOF(A(1)), NULL, os)
This does exactly what you want.
Thanks for the reply. I need code that will run on both Windows 32-bit and 64-bit as well as a 64-bit Linux. Even though WriteFile looks just like fwrite, I need something more portable.
Thanks again.
Sincerely,
David
- Marcar como novo
- Marcador
- Subscrever
- Silenciar
- Subscrever fonte RSS
- Destacar
- Imprimir
- Denunciar conteúdo inapropriado
Quoting - david.sallngc.com
How about if my vector is complex? Is there a way to write all REAL's and IMAG's separately usig some type of indexing?
David,
write(1) (real(a(i)),i=1,10), (aimag(a(j)),j=1,10)
should work
Les
- Marcar como novo
- Marcador
- Subscrever
- Silenciar
- Subscrever fonte RSS
- Destacar
- Imprimir
- Denunciar conteúdo inapropriado
You can open the file ACCESS='STREAM' and just write a stream of bytes. This is standard F2003.

Responder
Opções do tópico
- Subscrever fonte RSS
- Marcar tópico como novo
- Marcar tópico como lido
- Flutuar este Tópico para o utilizador atual
- Marcador
- Subscrever
- Página amigável para impressora