Search code examples
fortrangfortran

Writing data in a line


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


Solution

  • 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.