http://www.chem.ucl.ac.uk/resources/history/people/vanmourik/images/Fortran%2095-manual.pdf
In C:
void foo(void)
{
static int a = 5;
int const b = 6;
}
In Fortran90/95:
SUBROUTINE FOO()
IMPLICIT NONE
INTEGER, SAVE :: A = 5
INTEGER, PARAMETER :: B = 5
END
Array assignment statements
coords(1) = 3.5
block(3,2) = 7
do i = 1,3
coords(i) = 0.0
end do
coords = (/ 1.3, 5.6, 0.0 /)
coords = (/ (2.0*i, i = 1, 3) /) ! yields (2.0, 4.0, 6.0)
odd_ints = (/ (i, i = 1, 10, 2) /) ! yields (1, 3, 5, 7, 9)
integer, dimension (8), parameter :: primes = (/ 1, 2, 3, 7, 11, 13, 17, 19 /)
For example, a two-dimensional array b(2,3) can be added to the array section a(2:3, 1:3)
of the array a of the previous section. If the array c is an array of dimension (2,3), then
the expression
c = a(2:3,1:3) + b
causes the elements of the array c to have the following values:
c(1,1) = a(2,1) + b(1,1)
c(2,1) = a(3,1) + b(2,1)
c(1,2) = a(2,2) + b(1,2)
c(2,2) = a(3,2) + b(2,2)
c(1,3) = a(2,3) + b(1,3)
c(2,3) = a(3,3) + b(2,3)
The same can be achieved by using a do loop:
do i = 1, 3
do j = 1, 2
c(j,i) = a(j+1,i) + b(j,i)
end do
end do
But the expression c = a(2:3,1:3) + b is clearly more concise.
沒有留言:
張貼留言