Thilo
Thilo

Reputation: 11

Loop using variable that changes every loop-calculation with certain step-size

I am using a loop that adds a value (step) to dist. After adding step to dist I would like to use it in the following calculation which provides the value c. Both, dist and c, should then be listed in two columns next to each other in an output file.

If I use the code below it works at least to list the values for dist in the output file.

dist=0
  do while (dist < rim)
   dist=dist+step
   c=0.5*(cl-cr)*erfc((dist)/(2*sqrt(t*d)))+cr
   write(1,'(1f20.0)')dist*1E+06
  enddo

If I replace the write command by the one below it will not list two nice columns but somehow mix both.

  write(1,'(1f20.0,1f15.5)')dist*1E+06,c

Is this a problem related to the positioning of the writing command in the loop or is it related to the format it is told to write the values?

Upvotes: 1

Views: 119

Answers (1)

Aristotelis
Aristotelis

Reputation: 141

You should add a space between them and re-check:

write(*,'(F20.0,1X,F15.5)') dist*1E+06, c

Also consider the accuracy with which you are writing the results to the file.

Upvotes: 1

Related Questions