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
//
// GENERATED FILE
//
use super::*;
use f2rust_std::*;
//$Procedure ZZGRDPLT ( Create grid of plates )
pub fn ZZGRDPLT(
NROWS: i32,
NCOLS: i32,
WRAP: bool,
NP: &mut i32,
PLATES: &mut [i32],
ctx: &mut Context,
) -> f2rust_std::Result<()> {
let mut PLATES = DummyArrayMut2D::new(PLATES, 1..=3, 1..);
let mut BL: i32 = 0;
let mut BR: i32 = 0;
let mut TL: i32 = 0;
let mut TR: i32 = 0;
let mut UB: i32 = 0;
//
// SPICELIB functions
//
//
// Local variables
//
//
// Standard SPICE error handling.
//
if spicelib::RETURN(ctx) {
return Ok(());
}
spicelib::CHKIN(b"ZZGRDPLT", ctx)?;
//
// Check row and column dimensions.
//
if (NROWS < 2) {
spicelib::SETMSG(b"Grid must have at least two rows but NROWS is #.", ctx);
spicelib::ERRINT(b"#", NROWS, ctx);
spicelib::SIGERR(b"SPICE(INVALIDDIMENSION)", ctx)?;
spicelib::CHKOUT(b"ZZGRDPLT", ctx)?;
return Ok(());
}
if (NCOLS < 2) {
spicelib::SETMSG(b"Grid must have at least two columns but NCOLSS is #.", ctx);
spicelib::ERRINT(b"#", NCOLS, ctx);
spicelib::SIGERR(b"SPICE(INVALIDDIMENSION)", ctx)?;
spicelib::CHKOUT(b"ZZGRDPLT", ctx)?;
return Ok(());
}
//
// Set the upper bound on the column loop. If longitude
// wrapping is turned on, the final column connects to
// the first column.
//
if WRAP {
UB = NCOLS;
} else {
UB = (NCOLS - 1);
}
//
// Connect the vertices to generate plates.
//
*NP = 0;
for I in 1..=(NROWS - 1) {
for J in 1..=UB {
//
// Since the vertices are stored in a 3xN
// array, it will be convenient to use aliases for
// their indices---this cuts down on use of complicated
// index expressions. For each square defined by
// four neighboring vertices, we'll call the vertices
//
// TL "top left"
// TR "top right"
// BL "bottom left"
// BR "bottom right"
//
// Recall that the input pixel grid has dimensions
//
// NROWS x NCOLS
//
// The top row is at the highest latitude.
//
// The leftmost column corresponds to the west
// boundary of the region.
//
// The top left vertex corresponds to pixel (I,J).
//
if (WRAP && (J == UB)) {
//
// Connect the right edge of the grid to the left edge.
//
TL = (I * NCOLS);
TR = ((TL - NCOLS) + 1);
BL = (TL + NCOLS);
BR = (TR + NCOLS);
} else {
//
// This is the normal case: the column at index
// J is connected to the column at index J+1.
//
TL = (((I - 1) * NCOLS) + J);
TR = (TL + 1);
BL = (TL + NCOLS);
BR = (BL + 1);
}
//
// For each square defined by neighboring pixel centers,
// we must represent the corresponding surface by a pair
// of plates. We have two choices for the diagonal
// common edge connecting these plates: descending or
// ascending to the right.
//
// We choose the descending diagonal.
//
// The vertex assignment must be positively
// oriented about the outward normal direction.
//
*NP = (*NP + 1);
PLATES[[1, *NP]] = BL;
PLATES[[2, *NP]] = BR;
PLATES[[3, *NP]] = TL;
*NP = (*NP + 1);
PLATES[[1, *NP]] = TL;
PLATES[[2, *NP]] = BR;
PLATES[[3, *NP]] = TR;
}
}
//
// The plate and vertex counts and arrays have been
// assigned.
//
spicelib::CHKOUT(b"ZZGRDPLT", ctx)?;
Ok(())
}