0

I am trying to write a variable z in a line in fortran. As you can see, z is the product of g*h. The problem I have is that I would like to print in a line z11,z12,z13,...zn1,x. The first number is the value of i and the second one, the value of j. This is what I have tried:

do i=1,ny
  do j=1,nx
     s=xmin + alongintx * (dfloat(j)-1.d0)
     t=ymin + alonginty * (dfloat(i)-1.d0)
     g=(1.d0/(desvestx*dsqrt(2.d0*pi)))*dexp(-(s-amedx)**2/
     $           (2.d0*desvestx**2))
     h=(1.d0/(desvesty*dsqrt(2.d0*pi)))*dexp(-(t-amedy)**2/
     $           (2.d0*desvesty**2))
     z=g*h
     write(45,*)(z,m=1,nx)
   end do
end do

The problem is that it prints the same value in a line nx times. How can I solve it without saving data in arrays? I would be interested in treating great amounts of data (nx and ny >10000) so store in array is not an option

Paul Roberts
  • 119
  • 6
  • `nx` about 10000 doesn't lead to huge volumes of data, but if you are still against that then you may be interested in _non-advancing_ output. That's a broad area, so please search here on that concept to see whether it helps. – francescalus Oct 01 '19 at 22:08
  • On formatting your code here, what you present is not understandable as Fortran: it appears to be a mixture of free- and fixed-form source. Please look again at the code you show. – francescalus Oct 01 '19 at 22:10

2 Answers2

1

Assuming that z is an array with nx elements (you forgot to show declarations), then your write statement should be

write(45,*) (z(m), m = 1, nx)

PS: Don't use specific intrinsic names. Use sqrt instead of dsqrt. Use exp instead of dexp. Don't use dfloat as it is unneeded.

steve
  • 657
  • 1
  • 4
  • 7
  • Thanks for your answer. The problem is that I am not interested in store data in an array. z is just a variable, not an array. – Paul Roberts Oct 01 '19 at 21:57
1

I think what you are looking for is advance='no' and specifying a format.
Have a look at What does advance='no' mean in Fortran?
Something like:

write(45,'f13.27',advance='no') z

should do the trick.

Playing on f13.27 should allow you to deal with the spaces between the output.

PilouPili
  • 2,601
  • 2
  • 17
  • 31
  • It works!! What about if I want to print n values of z in a line and then pass to the next line, writing other n values, and so...? – Paul Roberts Oct 02 '19 at 21:52
  • Just write an empy character like write(45,'a1') ' ' to switch to the next line or write(45,'a1',advance='no') '\n' – PilouPili Oct 03 '19 at 21:02