-3

I have this fortran 95 do-loop code which return answers in array form, please how do i find the SUM of the answers (fv) without writing them out, because they're iterative and subject to change. thanks

  !.......vapor fraction..............
  do i=1,6
    FV=Z(I)*(K(i)-1)/(VOLD*(K(i)-1)+1)
    write(*,99001)FV
  END DO

I saw a similar code where someone did:

  Real :: Zi(99),Ki(99),NV,FNV,FPNV
  FNV = 0.
  FPNV = 0.  
  Do i=1,NCOMP
    FNV= FNV + Zi(i)*(Ki(i)-1)/(NV*(Ki(i)-1)+1)
    FPNV = FPNV + (1)*Zi(i)*(Ki(i)-1)**2/((NV*(Ki(i)-1)+1)**2)
  end do
  NV1= NV - (FNV/(-1)*FPNV)

Hence the values of FNV and FPNV are summed up in the do..end do loop.

CKE
  • 1,533
  • 19
  • 18
  • 29
priest
  • 15
  • 3
  • Please show more code. Explain where do you need the sum to be stored or returned. – Vladimir F Героям слава May 27 '18 at 10:18
  • study the comments at your previous question (https://stackoverflow.com/questions/50544053/how-do-i-use-resultski-from-the-first-do-loop-in-the-second-do-loop) about Fortan usage and how to ask. – albert May 27 '18 at 10:30
  • Do not concentrate on the spelling, fix the [tag:fortran] tag and show the the code *inside the question*, not in a comment. It is much more important than spelling. See [ask]. – Vladimir F Героям слава May 27 '18 at 11:05
  • 1
    Advice to OP: delete the code currently in the question and insert a [mcve], paying particular attention to `M`, `C` and `V`. Right now the code posted, especially the part beginning *I saw a similar code where someone did* seems to be almost entirely irrelevant to what I think might be the underlying question. The discipline required to construct the [mcve] will assist you greatly in clarifying your question, you may even figure it out yourself. – High Performance Mark May 27 '18 at 11:39

1 Answers1

0

Assuming that FV is a floating number then you can sum it up this way:

!.......vapor fraction..............
FVSUM=0.     ! Initialization of sum
do i=1,6
  FV=Z(I)*(K(i)-1)/(VOLD*(K(i)-1)+1)
  write(*,99001)FV
  FVSUM = FVSUM + FV
end do
write(*,*) 'Sum of FV = ', FVSUM

After the loop, the sum is printed to standard output in free format.
Please add the declaration of FVSUM:

real :: FVSUM

and tell me if this answers your question.

CKE
  • 1,533
  • 19
  • 18
  • 29