1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
//
// GENERATED FILE
//
use super::*;
use f2rust_std::*;
const TOL: f64 = 0.000000000001;
//$Procedure ZZELLSEC ( Tessellate an ellipsoid section with plates )
pub fn ZZELLSEC(
A: f64,
B: f64,
C: f64,
MINLON: f64,
MAXLON: f64,
MINLAT: f64,
MAXLAT: f64,
NLON: i32,
NLAT: i32,
MAXV: i32,
MAXP: i32,
NV: &mut i32,
VERTS: &mut [f64],
NP: &mut i32,
PLATES: &mut [i32],
ctx: &mut Context,
) -> f2rust_std::Result<()> {
let mut VERTS = DummyArrayMut2D::new(VERTS, 1..=3, 1..);
let mut PLATES = DummyArrayMut2D::new(PLATES, 1..=3, 1..);
let mut DIR = StackArray::<f64, 3>::new(1..=3);
let mut DLAT: f64 = 0.0;
let mut DLON: f64 = 0.0;
let mut LAT: f64 = 0.0;
let mut LEVEL: f64 = 0.0;
let mut LMXLON: f64 = 0.0;
let mut LON: f64 = 0.0;
let mut S: f64 = 0.0;
let mut BIX: i32 = 0;
let mut LATLB: i32 = 0;
let mut LATUB: i32 = 0;
let mut N: i32 = 0;
let mut NCOLS: i32 = 0;
let mut NNP: i32 = 0;
let mut NROWS: i32 = 0;
let mut NSP: i32 = 0;
let mut PIX: i32 = 0;
let mut POLIDX: i32 = 0;
let mut VIX: i32 = 0;
let mut NCAP: bool = false;
let mut SCAP: bool = false;
let mut WRAP: bool = false;
//
// SPICELIB functions
//
//
// Local parameters
//
//
// Local variables
//
if spicelib::RETURN(ctx) {
return Ok(());
}
spicelib::CHKIN(b"ZZELLSEC", ctx)?;
//
// The semi-axes must have positive length.
//
if (((A <= 0.0) || (B <= 0.0)) || (C <= 0.0)) {
spicelib::SETMSG(b"Semi-axis lengths: A = #, B = #, C = #. ", ctx);
spicelib::ERRDP(b"#", A, ctx);
spicelib::ERRDP(b"#", B, ctx);
spicelib::ERRDP(b"#", C, ctx);
spicelib::SIGERR(b"SPICE(INVALIDAXISLENGTH)", ctx)?;
spicelib::CHKOUT(b"ZZELLSEC", ctx)?;
return Ok(());
}
//
// The longitude and latitude band counts must be realizable.
//
if (NLAT < 2) {
spicelib::SETMSG(
b"The latitude band count must be at least 2 but was #.",
ctx,
);
spicelib::ERRINT(b"#", NLAT, ctx);
spicelib::SIGERR(b"SPICE(INVALIDCOUNT)", ctx)?;
spicelib::CHKOUT(b"ZZELLSEC", ctx)?;
return Ok(());
}
if (NLON < 3) {
spicelib::SETMSG(
b"The longitude band count must be at least 3 but was #.",
ctx,
);
spicelib::ERRINT(b"#", NLON, ctx);
spicelib::SIGERR(b"SPICE(INVALIDCOUNT)", ctx)?;
spicelib::CHKOUT(b"ZZELLSEC", ctx)?;
return Ok(());
}
//
// Decide whether we have two distinct longitude boundaries. First
// create a local maximum longitude that's greater than the minimum
// longitude. The logical variable WRAP is .TRUE. if and only if we
// have 2*pi - TOL radians of longitude coverage, where TOL is a
// small value.
//
if (MAXLON > MINLON) {
LMXLON = MAXLON;
} else {
LMXLON = (MAXLON + ((2 as f64) * spicelib::PI(ctx)));
}
WRAP = ((LMXLON - MINLON) > (((2 as f64) * spicelib::PI(ctx)) - TOL));
//
// Decide whether we have north or south polar caps.
//
NCAP = (MAXLAT > ((spicelib::PI(ctx) / 2 as f64) - TOL));
SCAP = (MINLAT < (-(spicelib::PI(ctx) / 2 as f64) + TOL));
//
// Compute the vertex counts.
//
if WRAP {
//
// Vertex count: When both caps are present, there are NLAT-2
// latitude bands, excluding the polar caps. These
// are bounded by NLAT-1 rows of vertices. Each
// row of vertices has NLON members. The caps add
// two vertices.
//
if (NCAP && SCAP) {
//
// There are two polar caps.
//
*NV = ((NLON * (NLAT - 1)) + 2);
} else if (NCAP || SCAP) {
//
// There's just one polar cap. Excluding the polar
// vertex, there are NLAT rows of vertices.
//
*NV = ((NLON * NLAT) + 1);
} else {
//
// No polar caps. There are NLAT+1 rows of vertices.
//
*NV = (NLON * (NLAT + 1));
}
} else {
if (NCAP && SCAP) {
//
// There are two polar caps.
//
*NV = (((NLON + 1) * (NLAT - 1)) + 2);
} else if (NCAP || SCAP) {
//
// There's just one polar cap. Excluding the polar
// vertex, there are NLAT rows of vertices.
//
*NV = (((NLON + 1) * NLAT) + 1);
} else {
//
// No polar caps. There are NLAT+1 rows of vertices.
//
*NV = ((NLON + 1) * (NLAT + 1));
}
}
//
// Compute the plate counts. These depend on the set of
// polar caps.
//
//
// Plate count: each latitude band, excluding the polar caps,
// contains 2*NLON plates. Each cap contains NLON
// plates.
//
if (NCAP && SCAP) {
//
// There are two polar caps.
//
*NP = ((2 * NLON) * (NLAT - 1));
} else if (NCAP || SCAP) {
//
// There's just one polar cap. Excluding the polar
// vertex, there are NLAT rows of vertices.
//
*NP = (NLON * ((2 * NLAT) - 1));
} else {
//
// No polar caps. There are NLAT+1 rows of vertices.
//
*NP = ((2 * NLON) * NLAT);
}
if (*NV > MAXV) {
spicelib::SETMSG(
b"The requested plate model requires # vertices but the maximum vertex count is #.",
ctx,
);
spicelib::ERRINT(b"#", *NV, ctx);
spicelib::ERRINT(b"#", MAXV, ctx);
spicelib::SIGERR(b"SPICE(ARRAYTOOSMALL)", ctx)?;
spicelib::CHKOUT(b"ZZELLSEC", ctx)?;
return Ok(());
}
if (*NP > MAXP) {
spicelib::SETMSG(
b"The requested plate model requires # plates but the maximum plate count is #.",
ctx,
);
spicelib::ERRINT(b"#", *NP, ctx);
spicelib::ERRINT(b"#", MAXP, ctx);
spicelib::SIGERR(b"SPICE(ARRAYTOOSMALL)", ctx)?;
spicelib::CHKOUT(b"ZZELLSEC", ctx)?;
return Ok(());
}
//
// Create the vertex set, excluding the polar caps.
//
// LATLB will be the index of the first vertex row, excluding
// the caps. LATUB will be the index of the last vertex row,
// excluding the caps.
//
if (NCAP && SCAP) {
LATLB = 2;
LATUB = NLAT;
} else if NCAP {
LATLB = 2;
LATUB = (NLAT + 1);
} else if SCAP {
LATLB = 1;
LATUB = NLAT;
} else {
LATLB = 1;
LATUB = (NLAT + 1);
}
//
// NCOLS is the number of columns of vertices.
//
if WRAP {
NCOLS = NLON;
} else {
NCOLS = (NLON + 1);
}
//
// The latitude bands are equally spaced in planetocentric latitude.
//
DLAT = ((MAXLAT - MINLAT) / NLAT as f64);
DLON = ((LMXLON - MINLON) / NLON as f64);
VIX = 1;
for I in LATLB..=LATUB {
LAT = (MAXLAT - (((I - 1) as f64) * DLAT));
for J in 1..=NCOLS {
LON = (MINLON + (((J - 1) as f64) * DLON));
//
// Create a unit direction vector for the current
// vertex. Scale this vector to make it lie on the
// ellipsoid's surface; the scaled vector is the
// current vertex.
//
spicelib::LATREC(1.0, LON, LAT, DIR.as_slice_mut());
LEVEL = ((f64::powi((DIR[1] / A), 2) + f64::powi((DIR[2] / B), 2))
+ f64::powi((DIR[3] / C), 2));
S = (1.0 / f64::sqrt(LEVEL));
spicelib::VSCL(S, DIR.as_slice(), VERTS.subarray_mut([1, VIX]));
//
// Next vertex.
//
VIX = (VIX + 1);
}
}
//
// Create the polar vertices if necessary.
//
if (NCAP && SCAP) {
spicelib::VPACK(0.0, 0.0, C, VERTS.subarray_mut([1, (*NV - 1)]));
spicelib::VPACK(0.0, 0.0, -C, VERTS.subarray_mut([1, *NV]));
} else if NCAP {
spicelib::VPACK(0.0, 0.0, C, VERTS.subarray_mut([1, *NV]));
} else if SCAP {
spicelib::VPACK(0.0, 0.0, -C, VERTS.subarray_mut([1, *NV]));
}
//
// Create the plates for the latitude bounds other than
// those belonging to the caps.
//
// The first two inputs are the vertex row and column counts.
// Next is a logical flag indicating whether longitude wrapping
// should be used.
//
if (LATUB > LATLB) {
NROWS = ((LATUB - LATLB) + 1);
ZZGRDPLT(NROWS, NCOLS, WRAP, &mut N, PLATES.as_slice_mut(), ctx)?;
if spicelib::FAILED(ctx) {
spicelib::CHKOUT(b"ZZELLSEC", ctx)?;
return Ok(());
}
} else {
N = 0;
}
if NCAP {
//
// Add the north cap. This is a set of plates; the vertices
// already have been computed.
//
// PIX is the index of the first cap plate. BIX is the
// base (predecessor) index of the first vertex in the
// first vertex row.
//
PIX = (N + 1);
BIX = 0;
//
// POLIDX is the vertex index of the north polar vertex.
//
if SCAP {
POLIDX = (*NV - 1);
} else {
POLIDX = *NV;
}
ZZCAPPLT(
NCOLS,
true,
WRAP,
BIX,
POLIDX,
&mut NNP,
PLATES.subarray_mut([1, PIX]),
ctx,
)?;
if spicelib::FAILED(ctx) {
spicelib::CHKOUT(b"ZZELLSEC", ctx)?;
return Ok(());
}
}
if SCAP {
//
// Add the south cap.
//
POLIDX = *NV;
if NCAP {
PIX = (PIX + NNP);
BIX = (*NV - (NCOLS + 2));
} else {
PIX = (N + 1);
BIX = (*NV - (NCOLS + 1));
}
ZZCAPPLT(
NCOLS,
false,
WRAP,
BIX,
POLIDX,
&mut NSP,
PLATES.subarray_mut([1, PIX]),
ctx,
)?;
}
spicelib::CHKOUT(b"ZZELLSEC", ctx)?;
Ok(())
}