0

I am having some issues with writing efficiently a vector in fortran to disk.

Here's a minimal working example:

integer :: ind
double precision, allocatable :: c_reshape
allocate(c_reshape(576000))

do ind = 1,576000
            c_reshape(ind) = ind
end do

OPEN(UNIT=25,FILE='c_res',STATUS='replace',ACTION='write')
       WRITE(25,*) c_reshape(:)
CLOSE(UNIT=25)

When I open the output file in notepad this is what I see: enter image description here

Why does Fortran save it in 3 columns? Anyway of saving it in a single column without writing a loop?

phdstudent
  • 1,060
  • 20
  • 41
  • The linked question at first glance is about writing the entire record as a single _row_ (not column), but it really covers the case of a single column too: if you desire a specific layout you need to specify that layout rather than rely on list-directed formatting. How to choose that format is in the answer. – francescalus Dec 09 '21 at 22:23
  • It is indeed possible to write it in one column. Did you read anything about Fortran formatting? The `/` descriptor mentioned in the linked answer will do that or just use format reversion `'(g0)'` (`g0` is the universal decriptor). This format will print each element with the `g0` format and then start on a new line each time. – Vladimir F Героям слава Dec 10 '21 at 06:12

0 Answers0