Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how do you iterate through an array in fortran?

Tags:

json

fortran

really simple question.

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

thanks

like image 502
Steven Noble Avatar asked May 03 '09 23:05

Steven Noble


People also ask

Is there for loop in Fortran?

If you are familiar with other programming languages you have probably heard about for-loops, while-loops, and until-loops. Fortran 77 has only one loop construct, called the do-loop. The do-loop corresponds to what is known as a for-loop in other languages.

What is an array in Fortran?

An array is a named collection of elements of the same type. It is a nonempty sequence of data and occupies a group of contiguous storage locations. An array has a name, a set of elements, and a type. An array name is a symbolic name for the whole sequence of data.

How many dimensions can an array have in Fortran?

Arrays can be one- dimensional (like vectors), two-dimensional (like matrices) and Fortran allows you to create up to 7-dimensional arrays.


2 Answers

In Fortran 90 you can do array iteration like:

do i = lbound(realResults), ubound(realResults)
  ! do something with realResults(i)
end do
like image 169
Ozgur Ozcitak Avatar answered Oct 12 '22 00:10

Ozgur Ozcitak


FORTRAN and json in the same paragraph?!?! WTF? Maybe something like:

      do 10 i = 0, 100
C        do something with realResults(i)
  10  continue
like image 43
Michael Burr Avatar answered Oct 11 '22 22:10

Michael Burr