Search code examples
fortran

How do you iterate through an array in Fortran?


Say I have

real, dimension(0:100) :: realResults

and I want to iterate over realResults, ultimately to create json of the array of the form

[[x1,y1], [x2,y2], [x3, y3], ... ]

I'm pretty sure I want to use "do" but I'm not sure how.


Solution

  • In Fortran 90 you can do array iteration like:

    do i = lbound(realResults, 1), ubound(realResults, 1)
      ! do something with realResults(i)
    end do