Skip to content

Commit f21a27b

Browse files
committed
Replace use of variable names with numeric index values throughout
1 parent e3b2866 commit f21a27b

File tree

3 files changed

+87
-51
lines changed

3 files changed

+87
-51
lines changed

bmi.sidl

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -21,12 +21,13 @@ package csdms version 3.0-alpha1 {
2121
int get_output_var_names(out array<string, 1> names);
2222

2323
// Variable information
24-
int get_var_grid(in string name, out int grid);
25-
int get_var_type(in string name, out string type);
26-
int get_var_units(in string name, out string units);
27-
int get_var_itemsize(in string name, out int size);
28-
int get_var_nbytes(in string name, out int nbytes);
29-
int get_var_location(in string name, out string location);
24+
int get_var_index(in string name, out int index);
25+
int get_var_grid(in int index, out int grid);
26+
int get_var_type(in int index, out string type);
27+
int get_var_units(in int index, out string units);
28+
int get_var_itemsize(in int index, out int size);
29+
int get_var_nbytes(in int index, out int nbytes);
30+
int get_var_location(in int index, out string location);
3031

3132
// Time information
3233
int get_current_time(out double time);
@@ -36,14 +37,14 @@ package csdms version 3.0-alpha1 {
3637
int get_time_step(out double time_step);
3738

3839
// Getters
39-
int get_value(in string name, in array<> dest);
40-
int get_value_ptr(in string name, out array<> dest_ptr);
41-
int get_value_at_indices(in string name, in array<> dest,
40+
int get_value(in int index, in array<> dest);
41+
int get_value_ptr(in int index, out array<> dest_ptr);
42+
int get_value_at_indices(in int index, in array<> dest,
4243
in array<int, 1> inds);
4344

4445
// Setters
45-
int set_value(in string name, in array<> src);
46-
int set_value_at_indices(in string name, in array<int, 1> inds,
46+
int set_value(in int index, in array<> src);
47+
int set_value_at_indices(in int index, in array<int, 1> inds,
4748
in array<> src);
4849

4950
// Grid information

docs/source/bmi.getter_setter.md

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -24,25 +24,25 @@ state variable can be changed or check the new data for validity.
2424
:::{tab-item} SIDL
2525
:sync: sidl
2626
```java
27-
int get_value(in string name, in array<> dest);
27+
int get_value(in int index, in array<> dest);
2828
```
2929
:::
3030

3131
:::{tab-item} Python
3232
:sync: python
3333
```python
34-
def get_value(self, name: str, dest: NDArray[Any]) -> NDArray[Any]:
34+
def get_value(self, index: int, dest: NDArray[Any]) -> NDArray[Any]:
3535
```
3636
:::
3737
:::{tab-item} c
3838
:sync: c
3939
```c
40-
int get_value(void *self, const char *name, void *dest);
40+
int get_value(void *self, int index, void *dest);
4141
```
4242
:::
4343
::::
4444
45-
The `get_value` function takes a variable name and copies values into a
45+
The `get_value` function takes a variable index and copies values into a
4646
provided array parameter.
4747
The type and size of the array parameter depend on the variable,
4848
and can be determined through
@@ -75,25 +75,25 @@ even if the model uses dimensional variables.
7575
:::{tab-item} SIDL
7676
:sync: sidl
7777
```java
78-
int get_value_ptr(in string name, out array<> dest_ptr);
78+
int get_value_ptr(in int index, out array<> dest_ptr);
7979
```
8080
:::
8181

8282
:::{tab-item} Python
8383
:sync: python
8484
```python
85-
def get_value_ptr(self, name: str) -> NDArray[Any]:
85+
def get_value_ptr(self, index: int) -> NDArray[Any]:
8686
```
8787
:::
8888
:::{tab-item} c
8989
:sync: c
9090
```c
91-
int get_value_ptr(void *self, const char *name, void **dest_ptr);
91+
int get_value_ptr(void *self, int index, void **dest_ptr);
9292
```
9393
:::
9494
::::
9595
96-
The `get_value_ptr` function takes a variable name and returns a reference
96+
The `get_value_ptr` function takes a variable index and returns a reference
9797
to a variable.
9898
Unlike the array parameter returned from {ref}`get-value`,
9999
the reference always points to the current values of the variable,
@@ -119,23 +119,23 @@ even if the model's state has changed.
119119
:::{tab-item} SIDL
120120
:sync: sidl
121121
```java
122-
int get_value_at_indices(in string name, in array<> dest, in array<int, 1> inds);
122+
int get_value_at_indices(in int index, in array<> dest, in array<int, 1> inds);
123123
```
124124
:::
125125

126126
:::{tab-item} Python
127127
:sync: python
128128
```python
129129
def get_value_at_indices(
130-
self, name: str, dest: NDArray[Any], inds: NDArray[np.int_]
130+
self, index: int, dest: NDArray[Any], inds: NDArray[np.int_]
131131
) -> NDArray[Any]:
132132
```
133133
:::
134134
:::{tab-item} c
135135
:sync: c
136136
```c
137137
int get_value_at_indices(
138-
void *self, const char *name, void *dest, int *inds, int count
138+
void *self, int index, void *dest, int *inds, int count
139139
);
140140
```
141141
:::
@@ -164,25 +164,25 @@ Additionally,
164164
:::{tab-item} SIDL
165165
:sync: sidl
166166
```java
167-
int set_value(in string name, in array<> src);
167+
int set_value(in int index, in array<> src);
168168
```
169169
:::
170170

171171
:::{tab-item} Python
172172
:sync: python
173173
```python
174-
def set_value(self, name: str, src: NDArray[Any]) -> None:
174+
def set_value(self, index: int, src: NDArray[Any]) -> None:
175175
```
176176
:::
177177
:::{tab-item} c
178178
:sync: c
179179
```c
180-
int set_value(void *self, const char *name, void *src);
180+
int set_value(void *self, int index, void *src);
181181
```
182182
:::
183183
::::
184184
185-
The `set_value` function takes a variable name and an array of values,
185+
The `set_value` function takes a variable index and an array of values,
186186
*src*,
187187
and copies those values into the model's internal array of values,
188188
overwriting the current contents.
@@ -214,23 +214,23 @@ even if the model uses dimensional variables.
214214
:::{tab-item} SIDL
215215
:sync: sidl
216216
```java
217-
int set_value_at_indices(in string name, in array<int, 1> inds, in array<> src);
217+
int set_value_at_indices(in int index, in array<int, 1> inds, in array<> src);
218218
```
219219
:::
220220

221221
:::{tab-item} Python
222222
:sync: python
223223
```python
224224
def set_value_at_indices(
225-
self, name: str, inds: NDArray[np.int_], src: NDArray[Any]
225+
self, index: int, inds: NDArray[np.int_], src: NDArray[Any]
226226
) -> None:
227227
```
228228
:::
229229
:::{tab-item} c
230230
:sync: c
231231
```c
232232
int set_value_at_indices(
233-
void *self, const char *name, int *inds, int count, void *src
233+
void *self, int index, int *inds, int count, void *src
234234
);
235235
```
236236
:::

docs/source/bmi.var_funcs.md

Lines changed: 57 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,44 @@ These BMI functions provide information
66
about a particular input or output variable.
77
They must accommodate any variable returned from the
88
{ref}`get-input-var-names` or {ref}`get-output-var-names` functions --
9-
the variable name is used as an argument in each function.
10-
Based on the information returned,
11-
type or unit conversions can be applied when necessary.
9+
the variable index as obtained from {ref}`get-var-index` is used as an argument in each function.
10+
Based on the information returned, type or unit conversions can be applied when necessary.
11+
12+
(get-var-index)=
13+
14+
## *get_var_index*
15+
16+
::::{tab-set}
17+
:sync-group: lang
18+
19+
:::{tab-item} SIDL
20+
:sync: sidl
21+
22+
```java
23+
int get_var_index(in string name, out int index);
24+
```
25+
:::
26+
:::{tab-item} Python
27+
:sync: python
28+
```python
29+
def get_var_index(self, name: str) -> int:
30+
```
31+
:::
32+
:::{tab-item} c
33+
:sync: c
34+
```c
35+
int get_var_index(void *self, const char *name, int *index);
36+
```
37+
:::
38+
::::
39+
40+
Each input and output variable is associated with a numerical index.
41+
The `get_var_index` function provides the value for this index.
42+
These index values need not be in any particular order or range.
43+
The identifier can be passed to the BMI
44+
{ref}`variable information <var-funcs>` functions
45+
to get the details of a particular variable;
46+
e.g., size, type, units, grid, etc.
1247
1348
(get-var-grid)=
1449
@@ -21,19 +56,19 @@ type or unit conversions can be applied when necessary.
2156
:sync: sidl
2257
2358
```java
24-
int get_var_grid(in string name, out int grid);
59+
int get_var_grid(in int index, out int grid);
2560
```
2661
:::
2762
:::{tab-item} Python
2863
:sync: python
2964
```python
30-
def get_var_grid(self, name: str) -> int:
65+
def get_var_grid(self, index: int) -> int:
3166
```
3267
:::
3368
:::{tab-item} c
3469
:sync: c
3570
```c
36-
int get_var_grid(void *self, const char *name, int *grid);
71+
int get_var_grid(void *self, int index, int *grid);
3772
```
3873
:::
3974
::::
@@ -65,20 +100,20 @@ A model can have one or more grids.
65100
:::{tab-item} SIDL
66101
:sync: sidl
67102
```java
68-
int get_var_type(in string name, out string type);
103+
int get_var_type(in int index, out string type);
69104
```
70105
:::
71106

72107
:::{tab-item} Python
73108
:sync: python
74109
```python
75-
def get_var_type(self, name: str) -> str:
110+
def get_var_type(self, index: int) -> str:
76111
```
77112
:::
78113
:::{tab-item} c
79114
:sync: c
80115
```c
81-
int get_var_type(void *self, const char *name, char *type);
116+
int get_var_type(void *self, int index, char *type);
82117
```
83118
:::
84119
::::
@@ -110,19 +145,19 @@ while in Fortran, use `integer`, `real`, and `double precision`.
110145
:sync: sidl
111146
112147
```java
113-
int get_var_units(in string name, out string units);
148+
int get_var_units(in int index, out string units);
114149
```
115150
:::
116151
:::{tab-item} Python
117152
:sync: python
118153
```python
119-
def get_var_units(self, name: str) -> str:
154+
def get_var_units(self, index: int) -> str:
120155
```
121156
:::
122157
:::{tab-item} c
123158
:sync: c
124159
```c
125-
int get_var_units(void *self, const char *name, char *units);
160+
int get_var_units(void *self, int index, char *units);
126161
```
127162
:::
128163
::::
@@ -159,20 +194,20 @@ full description of valid unit names and a list of supported units.
159194
:::{tab-item} SIDL
160195
:sync: sidl
161196
```java
162-
int get_var_itemsize(in string name, out int size);
197+
int get_var_itemsize(in int index, out int size);
163198
```
164199
:::
165200

166201
:::{tab-item} Python
167202
:sync: python
168203
```python
169-
def get_var_itemsize(self, name: str) -> int:
204+
def get_var_itemsize(self, index: int) -> int:
170205
```
171206
:::
172207
:::{tab-item} c
173208
:sync: c
174209
```c
175-
int get_var_itemsize(void *self, const char *name, int *size);
210+
int get_var_itemsize(void *self, int index, int *size);
176211
```
177212
:::
178213
::::
@@ -199,20 +234,20 @@ For example, if data for a variable are stored as 64-bit integers,
199234
:::{tab-item} SIDL
200235
:sync: sidl
201236
```java
202-
int get_var_nbytes(in string name, out int nbytes);
237+
int get_var_nbytes(in int index, out int nbytes);
203238
```
204239
:::
205240

206241
:::{tab-item} Python
207242
:sync: python
208243
```python
209-
def get_var_nbytes(self, name: str) -> int:
244+
def get_var_nbytes(self, index: int) -> int:
210245
```
211246
:::
212247
:::{tab-item} c
213248
:sync: c
214249
```c
215-
int get_var_nbytes(void *self, const char *name, int *nbytes);
250+
int get_var_nbytes(void *self, int index, int *nbytes);
216251
```
217252
:::
218253
::::
@@ -237,26 +272,26 @@ a variable; i.e., the number of items multiplied by the size of each item.
237272
:::{tab-item} SIDL
238273
:sync: sidl
239274
```java
240-
int get_var_location(in string name, out string location);
275+
int get_var_location(in int index, out string location);
241276
```
242277
:::
243278

244279
:::{tab-item} Python
245280
:sync: python
246281
```python
247-
def get_var_location(self, name: str) -> str:
282+
def get_var_location(self, index: int) -> str:
248283
```
249284
:::
250285
:::{tab-item} c
251286
:sync: c
252287
```c
253-
int get_var_location(void *self, const char *name, char *location);
288+
int get_var_location(void *self, int index, char *location);
254289
```
255290
:::
256291
::::
257292
258293
The `get_var_location` function,
259-
given a variable name, returns a string that indicates on what grid
294+
given a variable index, returns a string that indicates on what grid
260295
element the variable is defined. Valid return values are:
261296
262297
- `node`

0 commit comments

Comments
 (0)