1 /* vprojg.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      VPROJG ( Vector projection, general dimension ) */
vprojg_(doublereal * a,doublereal * b,integer * ndim,doublereal * p)9 /* Subroutine */ int vprojg_(doublereal *a, doublereal *b, integer *ndim,
10 	doublereal *p)
11 {
12     doublereal scale, adotb, bdotb;
13     extern /* Subroutine */ int vsclg_(doublereal *, doublereal *, integer *,
14 	    doublereal *);
15     extern doublereal vdotg_(doublereal *, doublereal *, integer *);
16 
17 /* $ Abstract */
18 
19 /*     VPROJG finds the projection of the one vector onto another */
20 /*     vector.  All vectors are of arbitrary dimension. */
21 
22 /* $ Disclaimer */
23 
24 /*     THIS SOFTWARE AND ANY RELATED MATERIALS WERE CREATED BY THE */
25 /*     CALIFORNIA INSTITUTE OF TECHNOLOGY (CALTECH) UNDER A U.S. */
26 /*     GOVERNMENT CONTRACT WITH THE NATIONAL AERONAUTICS AND SPACE */
27 /*     ADMINISTRATION (NASA). THE SOFTWARE IS TECHNOLOGY AND SOFTWARE */
28 /*     PUBLICLY AVAILABLE UNDER U.S. EXPORT LAWS AND IS PROVIDED "AS-IS" */
29 /*     TO THE RECIPIENT WITHOUT WARRANTY OF ANY KIND, INCLUDING ANY */
30 /*     WARRANTIES OF PERFORMANCE OR MERCHANTABILITY OR FITNESS FOR A */
31 /*     PARTICULAR USE OR PURPOSE (AS SET FORTH IN UNITED STATES UCC */
32 /*     SECTIONS 2312-2313) OR FOR ANY PURPOSE WHATSOEVER, FOR THE */
33 /*     SOFTWARE AND RELATED MATERIALS, HOWEVER USED. */
34 
35 /*     IN NO EVENT SHALL CALTECH, ITS JET PROPULSION LABORATORY, OR NASA */
36 /*     BE LIABLE FOR ANY DAMAGES AND/OR COSTS, INCLUDING, BUT NOT */
37 /*     LIMITED TO, INCIDENTAL OR CONSEQUENTIAL DAMAGES OF ANY KIND, */
38 /*     INCLUDING ECONOMIC DAMAGE OR INJURY TO PROPERTY AND LOST PROFITS, */
39 /*     REGARDLESS OF WHETHER CALTECH, JPL, OR NASA BE ADVISED, HAVE */
40 /*     REASON TO KNOW, OR, IN FACT, SHALL KNOW OF THE POSSIBILITY. */
41 
42 /*     RECIPIENT BEARS ALL RISK RELATING TO QUALITY AND PERFORMANCE OF */
43 /*     THE SOFTWARE AND ANY RELATED MATERIALS, AND AGREES TO INDEMNIFY */
44 /*     CALTECH AND NASA FOR ALL THIRD-PARTY CLAIMS RESULTING FROM THE */
45 /*     ACTIONS OF RECIPIENT IN THE USE OF THE SOFTWARE. */
46 
47 /* $ Required_Reading */
48 
49 /*     None. */
50 
51 /* $ Keywords */
52 
53 /*     VECTOR */
54 
55 /* $ Declarations */
56 /* $ Brief_I/O */
57 
58 /*     VARIABLE  I/O  DESCRIPTION */
59 /*     --------  ---  -------------------------------------------------- */
60 /*     A          I   The vector to be projected. */
61 /*     B          I   The vector onto which A is to be projected. */
62 /*     NDIM       I   Dimension of A, B, and P. */
63 /*     P          O   The projection of A onto B. */
64 
65 /* $ Detailed_Input */
66 
67 /*     A     is a double precision vector of arbitrary dimension.  This */
68 /*           vector is to be projected onto the vector B. */
69 
70 /*     B     is a double precision vector of arbitrary dimension.  This */
71 /*           vector is the vector which receives the projection. */
72 
73 /*     NDIM  is the dimension of A, B and P. */
74 
75 /* $ Detailed_Output */
76 
77 /*     P     is a double precision vector of arbitrary dimension */
78 /*           containing the projection of A onto B. (P is necessarily */
79 /*           parallel to B.) */
80 
81 /* $ Parameters */
82 
83 /*     None. */
84 
85 /* $ Exceptions */
86 
87 /*     Error free. */
88 
89 /* $ Files */
90 
91 /*     None. */
92 
93 /* $ Particulars */
94 
95 /*     The projection of a vector A onto a vector B is, by definition, */
96 /*     that component of A which is parallel to B.  To find this */
97 /*     component it is enough to find the scalar ratio of the length of */
98 /*     B to the projection of A onto B, and then use this number to */
99 /*     scale the length of B.  This ratio is given by */
100 
101 /*         RATIO = (A DOT B) / (B DOT B) */
102 
103 /*     where DOT denotes the general vector dot product. This routine */
104 /*     does not attempt to divide by zero in the event that B is the */
105 /*     zero vector. */
106 
107 /* $ Examples */
108 
109 /*     The following table gives sample inputs and results from calling */
110 /*     VPROJG. */
111 
112 /*        A                  B                NDIM       P */
113 /*        ----------------------------------------------------------- */
114 /*        (6, 6, 6, 6)      ( 2, 0, 0, 0)     4          (6, 0, 0, 0) */
115 /*        (6, 6, 6, 0)      (-3, 0, 0, 0)     4          (6, 0, 0, 0) */
116 /*        (6, 6, 0, 0)      ( 0, 7, 0, 0)     4          (0, 6, 0, 0) */
117 /*        (6, 0, 0, 0)      ( 0, 0, 9, 0)     4          (0, 0, 0, 0) */
118 
119 /* $ Restrictions */
120 
121 /*     No error detection or recovery schemes are incorporated into this */
122 /*     subroutine except to insure that no attempt is made to divide by */
123 /*     zero.  Thus, the user is required to make sure that the vectors */
124 /*     A and B are such that no floating point overflow will occur when */
125 /*     the dot products are calculated. */
126 
127 /* $ Literature_References */
128 
129 /*     Any reasonable calculus text (for example Thomas) */
130 
131 /* $ Author_and_Institution */
132 
133 /*     N.J. Bachman    (JPL) */
134 /*     H.A. Neilan     (JPL) */
135 /*     W.L. Taber      (JPL) */
136 
137 /* $ Version */
138 
139 /* -    SPICELIB Version 1.0.3, 23-APR-2010 (NJB) */
140 
141 /*        Header correction: assertions that the output */
142 /*        can overwrite the input have been removed. */
143 
144 /* -    SPICELIB Version 1.0.2, 22-AUG-2001 (EDW) */
145 
146 /*        Corrected ENDIF to END IF. */
147 
148 /* -    SPICELIB Version 1.0.1, 10-MAR-1992 (WLT) */
149 
150 /*        Comment section for permuted index source lines was added */
151 /*        following the header. */
152 
153 /* -    SPICELIB Version 1.0.0, 31-JAN-1990 (WLT) */
154 
155 /* -& */
156 /* $ Index_Entries */
157 
158 /*     n-dimensional vector projection */
159 
160 /* -& */
161 /* $ Revisions */
162 
163 /* -     Beta Version 1.1.0, 17-FEB-1989 (HAN) (NJB) */
164 
165 /*         Contents of the Exceptions section was changed */
166 /*         to "error free" to reflect the decision that the */
167 /*         module will never participate in error handling. */
168 
169 /*         The declaration of the unused variable I was removed. */
170 /* -& */
171 
172 
173     adotb = vdotg_(a, b, ndim);
174     bdotb = vdotg_(b, b, ndim);
175 
176     if (bdotb == 0.) {
177 	scale = 0.;
178     } else {
179 	scale = adotb / bdotb;
180     }
181 
182     vsclg_(&scale, b, ndim, p);
183 
184     return 0;
185 } /* vprojg_ */
186 
187