1

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?

1
  • "but somehow mix both." How somehow? Please show an example end explain why is it wrong and how should it look like instead. Is your question about a loop or about formatting? Commented Feb 26, 2018 at 14:18

1 Answer 1

1

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.

Sign up to request clarification or add additional context in comments.

4 Comments

Sorry about that, I hope you mean 1X instead of just X @VladimirF .
Yes, it is fine now.
Thank you for your answers. I did add a space between now, but that didn't help. I think the routine calculates more than one "c"-value. dist(um) c 2. 0.24047 0. 0.24047 0. 0.24047 0. 0.24047 0. 0.24047 0. 0.24047 0. 0.24047 0. 0.24047
I now found the error. I wrote allocate c(n) in the beginning of the code, whereas n referred to a certain number that was already given by another input-file. I could solve the problem by replacing n by 1. Thank you for your thoughts

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.