Re: Problem when writing unformatted data to file using Intel Fortran Compiler



Matthias Möller wrote:

> I need to write large data to file without formatting them. The following program demonstrates what happens if compiled with:


(snip)

>   n1=10; n2=264448
>   allocate(kdata(n1,n2)); kdata=1


> open(unit=77,file="test.bin",form="UNFORMATTED") > write(unit=77) n1 > write(unit=77) n2 > write(unit=77) kdata > close(77)


Remember that each UNFORMATTED write writes one record to the file. It might require enough buffer space for the largest record written, which is huge in your case.

I don't know that there is any magical record size, but
I might suggest keeping it below about 64K bytes, or
16K elements assuming four byte data.  For your case, I would
probably try:

      open(unit=77,file="test.bin",form="UNFORMATTED")
      write(unit=77) n1,n2
      do 1 i=1,n2
1     write(unit=77) (kdata(j,i),j=1,n1)
      close(77)

Without knowing the possible values for n1, it is hard to say.
This might make the record length a little small, but if n1 can
get to the 100's or 1000's it is probably about right.
If n1 is always 10 then you could write multiple columns
(or is it rows, I forget) to each record.

As data is in memory with the leftmost subscript varying fastest,
you should write it out that way, as shown above.

-- glen


.