1 /* traceg.f -- translated by f2c (version 19980913).
2 You must link the resulting object file with the libraries:
3 -lf2c -lm (in that order)
4 */
5
6 #include "f2c.h"
7
8 /* $Procedure TRACEG ( Trace of a matrix, general dimension ) */
traceg_(doublereal * matrix,integer * ndim)9 doublereal traceg_(doublereal *matrix, integer *ndim)
10 {
11 /* System generated locals */
12 integer matrix_dim1, matrix_dim2, matrix_offset, i__1, i__2;
13 doublereal ret_val;
14
15 /* Builtin functions */
16 integer s_rnge(char *, integer, char *, integer);
17
18 /* Local variables */
19 integer i__;
20
21 /* $ Abstract */
22
23 /* Return the trace of a square matrix of arbitrary dimension. */
24
25 /* $ Disclaimer */
26
27 /* THIS SOFTWARE AND ANY RELATED MATERIALS WERE CREATED BY THE */
28 /* CALIFORNIA INSTITUTE OF TECHNOLOGY (CALTECH) UNDER A U.S. */
29 /* GOVERNMENT CONTRACT WITH THE NATIONAL AERONAUTICS AND SPACE */
30 /* ADMINISTRATION (NASA). THE SOFTWARE IS TECHNOLOGY AND SOFTWARE */
31 /* PUBLICLY AVAILABLE UNDER U.S. EXPORT LAWS AND IS PROVIDED "AS-IS" */
32 /* TO THE RECIPIENT WITHOUT WARRANTY OF ANY KIND, INCLUDING ANY */
33 /* WARRANTIES OF PERFORMANCE OR MERCHANTABILITY OR FITNESS FOR A */
34 /* PARTICULAR USE OR PURPOSE (AS SET FORTH IN UNITED STATES UCC */
35 /* SECTIONS 2312-2313) OR FOR ANY PURPOSE WHATSOEVER, FOR THE */
36 /* SOFTWARE AND RELATED MATERIALS, HOWEVER USED. */
37
38 /* IN NO EVENT SHALL CALTECH, ITS JET PROPULSION LABORATORY, OR NASA */
39 /* BE LIABLE FOR ANY DAMAGES AND/OR COSTS, INCLUDING, BUT NOT */
40 /* LIMITED TO, INCIDENTAL OR CONSEQUENTIAL DAMAGES OF ANY KIND, */
41 /* INCLUDING ECONOMIC DAMAGE OR INJURY TO PROPERTY AND LOST PROFITS, */
42 /* REGARDLESS OF WHETHER CALTECH, JPL, OR NASA BE ADVISED, HAVE */
43 /* REASON TO KNOW, OR, IN FACT, SHALL KNOW OF THE POSSIBILITY. */
44
45 /* RECIPIENT BEARS ALL RISK RELATING TO QUALITY AND PERFORMANCE OF */
46 /* THE SOFTWARE AND ANY RELATED MATERIALS, AND AGREES TO INDEMNIFY */
47 /* CALTECH AND NASA FOR ALL THIRD-PARTY CLAIMS RESULTING FROM THE */
48 /* ACTIONS OF RECIPIENT IN THE USE OF THE SOFTWARE. */
49
50 /* $ Required_Reading */
51
52 /* None. */
53
54 /* $ Keywords */
55
56 /* MATRIX */
57
58 /* $ Declarations */
59 /* $ Brief_I/O */
60
61 /* VARIABLE I/O DESCRIPTION */
62 /* -------- --- -------------------------------------------------- */
63 /* MATRIX I NDIM x NDIM matrix of double precision numbers. */
64 /* NDIM I Dimension of the matrix. */
65 /* TRACEG O The trace of MATRIX. */
66
67 /* $ Detailed_Input */
68
69 /* MATRIX is a double precision square matrix of arbitrary */
70 /* dimension. The input matrix must be square or else */
71 /* the concept is meaningless. */
72
73 /* NDIM is the dimension of MATRIX. */
74
75 /* $ Detailed_Output */
76
77 /* TRACEG is the trace of MATRIX, i.e. it is the sum of the */
78 /* diagonal elements of MATRIX. */
79
80 /* $ Parameters */
81
82 /* None. */
83
84 /* $ Particulars */
85
86 /* TRACEG simply executes in FORTRAN code the following loop: */
87
88 /* TRACEG = Summation from I = 1 to NDIM of MATRIX(I,I) */
89
90 /* No error detection or correction is implemented within this */
91 /* function. */
92
93 /* $ Examples */
94
95 /* | 3 5 7 | */
96 /* Suppose that MATRIX = | 0 -2 8 | (with NDIM = 3), then */
97 /* | 3 0 -1 | */
98
99 /* TRACEG (MATRIX, 3) = 0. (which is the sum of 3, -2 and -1). */
100
101 /* $ Restrictions */
102
103 /* No checking is performed to guard against floating point overflow */
104 /* or underflow. This routine should probably not be used if the */
105 /* input matrix is expected to have large double precision numbers */
106 /* along the diagonal. */
107
108 /* $ Exceptions */
109
110 /* Error free. */
111
112 /* $ Files */
113
114 /* None. */
115
116 /* $ Author_and_Institution */
117
118 /* W.L. Taber (JPL) */
119
120 /* $ Literature_References */
121
122 /* None. */
123
124 /* $ Version */
125
126 /* - SPICELIB Version 1.0.1, 10-MAR-1992 (WLT) */
127
128 /* Comment section for permuted index source lines was added */
129 /* following the header. */
130
131 /* - SPICELIB Version 1.0.0, 31-JAN-1990 (WLT) */
132
133 /* -& */
134 /* $ Index_Entries */
135
136 /* trace of a nxn_matrix */
137
138 /* -& */
139 /* Parameter adjustments */
140 matrix_dim1 = *ndim;
141 matrix_dim2 = *ndim;
142 matrix_offset = matrix_dim1 + 1;
143
144 /* Function Body */
145 ret_val = 0.;
146 i__1 = *ndim;
147 for (i__ = 1; i__ <= i__1; ++i__) {
148 ret_val += matrix[(i__2 = i__ + i__ * matrix_dim1 - matrix_offset) <
149 matrix_dim1 * matrix_dim2 && 0 <= i__2 ? i__2 : s_rnge("matr"
150 "ix", i__2, "traceg_", (ftnlen)133)];
151 }
152 return ret_val;
153 } /* traceg_ */
154
155