1 /* nbwid.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            NBWID ( Non-blank width of a character array ) */
nbwid_(char * array,integer * nelt,ftnlen array_len)9 integer nbwid_(char *array, integer *nelt, ftnlen array_len)
10 {
11     /* System generated locals */
12     integer ret_val;
13 
14     /* Builtin functions */
15     integer i_len(char *, ftnlen);
16 
17     /* Local variables */
18     integer i__, j, strlen;
19 
20 /* $ Abstract */
21 
22 /*     Determine the non-blank width of a character array---that is, */
23 /*     the largest value of LASTNB for any element in the array. */
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 /*     ARRAY, CHARACTER */
57 
58 /* $ Declarations */
59 /* $ Brief_I/O */
60 
61 /*     VARIABLE  I/O  DESCRIPTION */
62 /*     --------  ---  -------------------------------------------------- */
63 /*     ARRAY      I   Input array. */
64 /*     NELT       I   Number of elements in the array. */
65 /*     NBWID      O   Maximum value of LASTNB for the array. */
66 
67 /* $ Detailed_Input */
68 
69 /*     ARRAY       is the input array. */
70 
71 /*     NELT        is the number of elements in the input array. */
72 
73 /* $ Detailed_Output */
74 
75 /*     NBWID       is the index of the rightmost non-blank character */
76 /*                 in the entire array. This is equivalent to the */
77 /*                 maximum value of LASTNB for the array, but somewhat */
78 /*                 more efficient to compute. If NELT is not greater */
79 /*                 than zero, NBWID is zero. */
80 
81 /* $ Parameters */
82 
83 /*     None. */
84 
85 /* $ Particulars */
86 
87 /*     Find the last non-blank character in the first element of the */
88 /*     array. Search the rest of the elements, starting at the end of */
89 /*     each string and moving back just far enough to determine if the */
90 /*     current string is wider than any of the previous ones. (This */
91 /*     makes NBWID somewhat more efficient than LASTNB.) */
92 
93 /*     If any of the strings is found to contain no trailing blanks, */
94 /*     NBWID is just the length of the individual elements of the array, */
95 /*     and the search is terminated immediately. */
96 
97 /* $ Examples */
98 
99 /*     Let ARRAY contain the following strings. */
100 
101 /*           ARRAY(1) = 'A string of medium length                      ' */
102 /*           ARRAY(2) = 'A very long string, much longer than the rest  ' */
103 /*           ARRAY(3) = 'Shorter                                        ' */
104 /*           ARRAY(4) = 'Short                                          ' */
105 
106 /*     Then the value returned by */
107 
108 /*           WIDEST = NBWID ( ARRAY, 4 ) */
109 
110 /*     is 45. */
111 
112 /*     If the word 'rest' in the second element is changed to 'others', */
113 /*     the value returned is 47, and the search is terminated after the */
114 /*     second element. */
115 
116 /* $ Restrictions */
117 
118 /*     None. */
119 
120 /* $ Exceptions */
121 
122 /*      Error free. */
123 
124 /* $ Files */
125 
126 /*     None. */
127 
128 /* $ Author_and_Institution */
129 
130 /*     I.M. Underwood  (JPL) */
131 
132 /* $ Literature_References */
133 
134 /*     None. */
135 
136 /* $ Version */
137 
138 /* -     SPICELIB Version 1.0.1, 10-MAR-1992 (WLT) */
139 
140 /*         Comment section for permuted index source lines was added */
141 /*         following the header. */
142 
143 /* -     SPICELIB Version 1.0.0, 31-JAN-1990 (IMU) */
144 
145 /* -& */
146 /* $ Index_Entries */
147 
148 /*     non-blank width of a character array */
149 
150 /* -& */
151 
152 /*     Local variables */
153 
154 
155 /*     Nonsense case: no elements. */
156 
157     if (*nelt < 1) {
158 	ret_val = 0;
159 
160 /*     Get the length of the individual elements of the string. */
161 /*     So far, we have no maximum width, because we haven't examined */
162 /*     any elements. */
163 
164     } else {
165 	strlen = i_len(array, array_len);
166 	ret_val = 0;
167 	i__ = 0;
168 
169 /*        Continue until the end of the array is reached, or until */
170 /*        a string with no trailing blanks is found. */
171 
172 	while(i__ < *nelt && ret_val < strlen) {
173 
174 /*           Search no further than the current value of NBWID. */
175 
176 	    ++i__;
177 	    j = strlen;
178 	    while(j > ret_val && *(unsigned char *)&array[(i__ - 1) *
179 		    array_len + (j - 1)] == ' ') {
180 		--j;
181 	    }
182 
183 /*           NBWID only increases if this string was wider than all */
184 /*           previous strings. */
185 
186 	    ret_val = max(ret_val,j);
187 	}
188     }
189     return ret_val;
190 } /* nbwid_ */
191 
192