Civil Engineering Reference
In-Depth Information
of this topic. For example, if a , b ,and c conform and s is a scalar, the following are
valid:
a = b+c
!
no need for a matrix add, involving DO loops
a = b-c
!
no need for a matrix subtract
a = s*b
!
no need for a matrix-scalar multiply by s
a = b/s
!
no need for a matrix-scalar divide by s
a = 0.0
!
no need for a matrix null
However, although a = b*c has a meaning for conforming arrays a , b ,and c , its
consequence is the computation of the element-by-element products of b and c and is not
to be confused with the matrix multiply described in the next sub-section.
1.9.7
Intrinsic procedures for arrays
To supplement whole-array arithmetic operations, Fortran 95 provides a few intrinsic pro-
cedures (functions) which are very useful in finite element work. These can be grouped
conveniently into those involving array computations, and those involving array inspection.
The array computation functions are
FUNCTION MATMUL(a,b)
!
returns matrix product of a and b
FUNCTION DOT_PRODUCT(v1,v2)
!
returns dot product of v1 and v2
FUNCTION TRANSPOSE(a)
!
returns transpose of a.
All three are heavily used in the programs in this topic and replace the user-written
subroutines which had to be provided in previous FORTRAN 77 editions.
The array inspection functions include:
FUNCTION MAXVAL(a) ! returns the element of an array a of
! maximum value (not absolute maximum)
FUNCTION MINVAL(a) ! returns the element of an array a of
! minimum value (not absolute minimum)
FUNCTION MAXLOC(a) ! returns the location of the maximum element
! of array a
FUNCTION MINLOC(a) ! returns the location of the minimum element
! of array a
FUNCTION PRODUCT(a) ! returns the product of all the elements of a
FUNCTION SUM(a) ! returns the sum of all the elements of a
FUNCTION LBOUND(a,1) ! returns the first lower bound of a, etc.
FUNCTION UBOUND(a,1) ! returns the first upper bound of a, etc.
The first six of these procedures allow an optional argument called a masking argument.
For example the statement
asum=SUM(column,MASK=column>=0.0)
will result in asum containing the sum of the positive elements of array column .
Useful procedures whose only argument is a MASK are:
ALL(MASK=column>=0.0) ! true if all elements of column are positive
ANY(MASK=column>=0.0) ! true if any elements of column are positive
COUNT(MASK=column<=0.0)! number of elements of column which are
! negative.
For multidimensional arrays, operations such as SUM can be carried out on a particular
dimension of the array. When a mask is used, the dimension argument must be specified
Search WWH ::




Custom Search