Skip to content

Commit 7cbf1c9

Browse files
authored
Clarify return values (#85)
* Clarify status code values for C and Fortran * Add comment on using return codes
1 parent 5871b8a commit 7cbf1c9

7 files changed

+79
-11
lines changed

docs/source/bmi.best_practices.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,8 @@ here are some tips to help when writing a BMI for a model.
8080
they wrap a very simple model, they give useful insights into how a
8181
BMI can be implemented in each language.
8282

83+
* Return codes (C and Fortran) and exceptions (C++ and Python) can help with
84+
debugging a BMI, and can provide useful information to a user.
8385

8486
.. Links:
8587

docs/source/bmi.control_funcs.rst

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ formatted.
3939
* In C and Fortran, the *config_file* argument is passed as
4040
a character array, whereas in C++ and Python, it's passed as
4141
a string -- a basic type in these languages.
42-
* In C and Fortran, an integer status code indicating success or failure
42+
* In C and Fortran, an integer status code indicating success (zero) or failure (nonzero)
4343
is returned. In C++ and Python, an exception is raised on failure.
4444

4545
[:ref:`control_funcs` | :ref:`basic_model_interface`]
@@ -68,7 +68,7 @@ function can just return without doing anything.
6868

6969
**Implementation notes**
7070

71-
* In C and Fortran, an integer status code indicating success or failure
71+
* In C and Fortran, an integer status code indicating success (zero) or failure (nonzero)
7272
is returned. In C++ and Python, an exception is raised on failure.
7373

7474
[:ref:`control_funcs` | :ref:`basic_model_interface`]
@@ -96,7 +96,7 @@ to reflect that the model was updated to the requested time.
9696
**Implementation notes**
9797

9898
* Time is always a double-precision value.
99-
* In C and Fortran, an integer status code indicating success or failure
99+
* In C and Fortran, an integer status code indicating success (zero) or failure (nonzero)
100100
is returned. In C++ and Python, an exception is raised on failure.
101101

102102
[:ref:`control_funcs` | :ref:`basic_model_interface`]
@@ -119,7 +119,7 @@ deallocating memory, closing files and printing reports.
119119

120120
**Implementation notes**
121121

122-
* In C and Fortran, an integer status code indicating success or failure
122+
* In C and Fortran, an integer status code indicating success (zero) or failure (nonzero)
123123
is returned. In C++ and Python, an exception is raised on failure.
124124

125125
[:ref:`control_funcs` | :ref:`basic_model_interface`]

docs/source/bmi.getter_setter.rst

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,8 @@ even if the model uses dimensional variables.
4444
* Depending on how a model is written, a variable may not be
4545
accessible until after the call to :ref:`initialize`. Likewise, the
4646
variable may not be accessible after calling :ref:`finalize`.
47+
* In C and Fortran, an integer status code indicating success (zero) or failure
48+
(nonzero) is returned.
4749

4850
[:ref:`getter_setter_funcs` | :ref:`basic_model_interface`]
4951

@@ -69,6 +71,8 @@ even if the model's state has changed.
6971
* In C++, the *dest_ptr* argument is omitted, and the reference is
7072
returned through the function.
7173
* In Python, a :term:`numpy` array is returned.
74+
* In C and Fortran, an integer status code indicating success (zero) or failure
75+
(nonzero) is returned.
7276

7377
[:ref:`getter_setter_funcs` | :ref:`basic_model_interface`]
7478

@@ -126,6 +130,8 @@ even if the model uses dimensional variables.
126130
* Depending on how a model is written, a variable may not be
127131
accessible until after the call to :ref:`initialize`. Likewise, the
128132
variable may not be accessible after calling :ref:`finalize`.
133+
* In C and Fortran, an integer status code indicating success (zero) or failure
134+
(nonzero) is returned.
129135

130136
[:ref:`getter_setter_funcs` | :ref:`basic_model_interface`]
131137

docs/source/bmi.grid_funcs.rst

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,8 @@ is given in the :ref:`model_grids` section.
5151

5252
* In C++ and Python, the *type* argument is omitted and the grid
5353
type name is returned from the function.
54+
* In C and Fortran, an integer status code indicating success (zero) or failure
55+
(nonzero) is returned.
5456

5557
[:ref:`grid_funcs` | :ref:`basic_model_interface`]
5658

@@ -79,6 +81,8 @@ of :ref:`get_grid_x`, :ref:`get_grid_y`, etc. are implemented.
7981
* This function is needed for every :ref:`grid type <model_grids>`.
8082
* In C++ and Python, the *rank* argument is omitted and the grid
8183
rank is returned from the function.
84+
* In C and Fortran, an integer status code indicating success (zero) or failure
85+
(nonzero) is returned.
8286

8387
[:ref:`grid_funcs` | :ref:`basic_model_interface`]
8488

@@ -107,6 +111,8 @@ for :ref:`unstructured <unstructured_grids>` and
107111
* This function is needed for every :ref:`grid type <model_grids>`.
108112
* In C++ and Python, the *size* argument is omitted and the grid
109113
size is returned from the function.
114+
* In C and Fortran, an integer status code indicating success (zero) or failure
115+
(nonzero) is returned.
110116

111117
[:ref:`grid_funcs` | :ref:`basic_model_interface`]
112118

@@ -145,6 +151,8 @@ the cells.
145151
<structured_grids>`.
146152
* In Python, the *shape* argument is a :term:`numpy <NumPy>` array.
147153
* In C++, this is a void function.
154+
* In C and Fortran, an integer status code indicating success (zero) or failure
155+
(nonzero) is returned.
148156

149157
[:ref:`grid_funcs` | :ref:`basic_model_interface`]
150158

@@ -174,6 +182,8 @@ the spacing between rows is followed by spacing between columns, ``[dy, dx]``.
174182
<uniform_rectilinear>` grids.
175183
* In Python, the *spacing* argument is a :term:`numpy <NumPy>` array.
176184
* In C++, this is a void function.
185+
* In C and Fortran, an integer status code indicating success (zero) or failure
186+
(nonzero) is returned.
177187

178188
[:ref:`grid_funcs` | :ref:`basic_model_interface`]
179189

@@ -204,6 +214,8 @@ the origin is given in the column dimension, followed by the row dimension,
204214
<uniform_rectilinear>` grids.
205215
* In Python, the *origin* argument is a :term:`numpy <NumPy>` array.
206216
* In C++, this is a void function.
217+
* In C and Fortran, an integer status code indicating success (zero) or failure
218+
(nonzero) is returned.
207219

208220
[:ref:`grid_funcs` | :ref:`basic_model_interface`]
209221

@@ -232,6 +244,8 @@ See :ref:`model_grids` for more information.
232244
and all :ref:`unstructured <unstructured_grids>` grids.
233245
* In Python, the *x* argument is a :term:`numpy <NumPy>` array.
234246
* In C++, this is a void function.
247+
* In C and Fortran, an integer status code indicating success (zero) or failure
248+
(nonzero) is returned.
235249

236250
[:ref:`grid_funcs` | :ref:`basic_model_interface`]
237251

@@ -260,6 +274,8 @@ See :ref:`model_grids` for more information.
260274
and all :ref:`unstructured <unstructured_grids>` grids.
261275
* In Python, the *y* argument is a :term:`numpy <NumPy>` array.
262276
* In C++, this is a void function.
277+
* In C and Fortran, an integer status code indicating success (zero) or failure
278+
(nonzero) is returned.
263279

264280
[:ref:`grid_funcs` | :ref:`basic_model_interface`]
265281

@@ -288,6 +304,8 @@ See :ref:`model_grids` for more information.
288304
and all :ref:`unstructured <unstructured_grids>` grids.
289305
* In Python, the *z* argument is a :term:`numpy <NumPy>` array.
290306
* In C++, this is a void function.
307+
* In C and Fortran, an integer status code indicating success (zero) or failure
308+
(nonzero) is returned.
291309

292310
[:ref:`grid_funcs` | :ref:`basic_model_interface`]
293311

@@ -310,6 +328,8 @@ Get the number of :term:`nodes <node>` in the grid.
310328
<unstructured_grids>` grids.
311329
* In C++ and Python, the *count* argument is omitted and the node
312330
count is returned from the function.
331+
* In C and Fortran, an integer status code indicating success (zero) or failure
332+
(nonzero) is returned.
313333

314334
[:ref:`grid_funcs` | :ref:`basic_model_interface`]
315335

@@ -332,6 +352,8 @@ Get the number of :term:`edges <edge>` in the grid.
332352
<unstructured_grids>` grids.
333353
* In C++ and Python, the *count* argument is omitted and the edge
334354
count is returned from the function.
355+
* In C and Fortran, an integer status code indicating success (zero) or failure
356+
(nonzero) is returned.
335357

336358
[:ref:`grid_funcs` | :ref:`basic_model_interface`]
337359

@@ -354,6 +376,8 @@ Get the number of :term:`faces <face>` in the grid.
354376
<unstructured_grids>` grids.
355377
* In C++ and Python, the *count* argument is omitted and the face
356378
count is returned from the function.
379+
* In C and Fortran, an integer status code indicating success (zero) or failure
380+
(nonzero) is returned.
357381

358382
[:ref:`grid_funcs` | :ref:`basic_model_interface`]
359383

@@ -380,6 +404,8 @@ node at edge head. The total length of the array is
380404
<unstructured_grids>` grids.
381405
* In Python, the *edge_nodes* argument is a :term:`numpy <NumPy>` array.
382406
* In C++, this is a void function.
407+
* In C and Fortran, an integer status code indicating success (zero) or failure
408+
(nonzero) is returned.
383409

384410
[:ref:`grid_funcs` | :ref:`basic_model_interface`]
385411

@@ -405,6 +431,8 @@ The length of the array returned is the sum of the values of
405431
<unstructured_grids>` grids.
406432
* In Python, the *face_edges* argument is a :term:`numpy <NumPy>` array.
407433
* In C++, this is a void function.
434+
* In C and Fortran, an integer status code indicating success (zero) or failure
435+
(nonzero) is returned.
408436

409437
[:ref:`grid_funcs` | :ref:`basic_model_interface`]
410438

@@ -435,6 +463,8 @@ the length of the array is the sum of the values of
435463
<unstructured_grids>` grids.
436464
* In Python, the *face_nodes* argument is a :term:`numpy <NumPy>` array.
437465
* In C++, this is a void function.
466+
* In C and Fortran, an integer status code indicating success (zero) or failure
467+
(nonzero) is returned.
438468

439469
[:ref:`grid_funcs` | :ref:`basic_model_interface`]
440470

@@ -460,5 +490,7 @@ The number of edges per face is equal to the number of nodes per face.
460490
<unstructured_grids>` grids.
461491
* In Python, the *nodes_per_face* argument is a :term:`numpy <NumPy>` array.
462492
* In C++, this is a void function.
493+
* In C and Fortran, an integer status code indicating success (zero) or failure
494+
(nonzero) is returned.
463495

464496
[:ref:`grid_funcs` | :ref:`basic_model_interface`]

docs/source/bmi.info_funcs.rst

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,9 @@ but it should be unique to prevent conflicts with other components.
2424

2525
**Implementation notes**
2626

27-
* In C and Fortran, the *name* argument is a a character array.
28-
In C++ and Python, this argument is omitted, and a string -- a basic type
27+
* In C and Fortran, the *name* argument is a a character array, and an integer
28+
status code indicating success (zero) or failure (nonzero) is returned.
29+
* In C++ and Python, this argument is omitted, and a string -- a basic type
2930
in these languages -- is returned from the function.
3031

3132
[:ref:`info_funcs` | :ref:`basic_model_interface`]
@@ -49,6 +50,8 @@ Also the number of variables that can be set with :ref:`set_value`.
4950

5051
* In C++ and Python, the argument is omitted and the count is returned
5152
from the function.
53+
* In C and Fortran, an integer status code indicating success (zero) or failure
54+
(nonzero) is returned.
5255

5356
[:ref:`info_funcs` | :ref:`basic_model_interface`]
5457

@@ -69,8 +72,10 @@ Also the number of variables that can be retrieved with :ref:`get_value`.
6972

7073
**Implementation notes**
7174

72-
* In C++ and Python, the argument is omittedq and the count is
75+
* In C++ and Python, the argument is omitted and the count is
7376
returned from the function.
77+
* In C and Fortran, an integer status code indicating success (zero) or failure
78+
(nonzero) is returned.
7479

7580
[:ref:`info_funcs` | :ref:`basic_model_interface`]
7681

@@ -98,7 +103,8 @@ Standard Names do not have to be used within the model.
98103
**Implementation notes**
99104

100105
* In C and Fortran, the names are passed back as an array of character
101-
pointers (because the variable names could have differing lengths).
106+
pointers (because the variable names could have differing lengths), and an
107+
integer status code indicating success (zero) or failure (nonzero) is returned.
102108
* In C++, the argument is omitted and the names are returned from the
103109
function in a vector, a standard container in the language.
104110
* In Python, the argument is omitted and the names are returned from the
@@ -131,7 +137,8 @@ Standard Names do not have to be used within the model.
131137
**Implementation notes**
132138

133139
* In C and Fortran, the names are passed back as an array of character
134-
pointers (because the variable names could have differing lengths).
140+
pointers (because the variable names could have differing lengths), and an
141+
integer status code indicating success (zero) or failure (nonzero) is returned.
135142
* In C++, the argument is omitted and the names are returned from the
136143
function in a vector, a standard container in the language.
137144
* In Python, the argument is omitted and the names are returned from the

docs/source/bmi.time_funcs.rst

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@ The current model time.
2222

2323
* In C++ and Python, the argument is omitted and the time is returned
2424
from the function.
25+
* In C and Fortran, an integer status code indicating success (zero) or failure
26+
(nonzero) is returned.
2527

2628
[:ref:`time_funcs` | :ref:`basic_model_interface`]
2729

@@ -43,6 +45,8 @@ The start time of the model.
4345
* The start time in BMI is typically defined to be 0.0.
4446
* In C++ and Python, the argument is omitted and the time is returned
4547
from the function.
48+
* In C and Fortran, an integer status code indicating success (zero) or failure
49+
(nonzero) is returned.
4650

4751
[:ref:`time_funcs` | :ref:`basic_model_interface`]
4852

@@ -66,6 +70,8 @@ The end time of the model.
6670
chosen.
6771
* In C++ and Python, the argument is omitted and the time is returned
6872
from the function.
73+
* In C and Fortran, an integer status code indicating success (zero) or failure
74+
(nonzero) is returned.
6975

7076
[:ref:`time_funcs` | :ref:`basic_model_interface`]
7177

@@ -95,6 +101,8 @@ It's recommended to use `time unit conventions`_ from Unidata's
95101
use ``"none"``.
96102
* In C++ and Python, the argument is omitted and the units are returned
97103
from the function.
104+
* In C and Fortran, an integer status code indicating success (zero) or failure
105+
(nonzero) is returned.
98106

99107
[:ref:`time_funcs` | :ref:`basic_model_interface`]
100108

@@ -119,5 +127,7 @@ The time step is always expressed as a floating point value.
119127
backward).
120128
* In C++ and Python, the argument is omitted and the time step is returned
121129
from the function.
130+
* In C and Fortran, an integer status code indicating success (zero) or failure
131+
(nonzero) is returned.
122132

123133
[:ref:`time_funcs` | :ref:`basic_model_interface`]

docs/source/bmi.var_funcs.rst

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,8 @@ A model can have one or more grids.
3636
* Grid identifiers start at 0.
3737
* In C++ and Python, the *grid* argument is omitted and the grid
3838
identifier is returned from the function.
39+
* In C and Fortran, an integer status code indicating success (zero) or
40+
failure (nonzero) is returned.
3941

4042
[:ref:`var_funcs` | :ref:`basic_model_interface`]
4143

@@ -61,6 +63,8 @@ while in Fortran, use `integer`, `real`, and `double precision`.
6163

6264
* In C++ and Python, the *type* argument is omitted and the variable
6365
type name is returned from the function.
66+
* In C and Fortran, an integer status code indicating success (zero) or failure
67+
(nonzero) is returned.
6468

6569
[:ref:`var_funcs` | :ref:`basic_model_interface`]
6670

@@ -94,6 +98,8 @@ full description of valid unit names and a list of supported units.
9498
* Variables without units should use ``"none"``.
9599
* In C++ and Python, the *units* argument is omitted and the variable
96100
units name is returned from the function.
101+
* In C and Fortran, an integer status code indicating success (zero) or failure
102+
(nonzero) is returned.
97103

98104
[:ref:`var_funcs` | :ref:`basic_model_interface`]
99105

@@ -117,6 +123,8 @@ For example, if data for a variable are stored as 64-bit integers,
117123

118124
* In C++ and Python, the *size* argument is omitted and the item size
119125
is returned from the function.
126+
* In C and Fortran, an integer status code indicating success (zero) or failure
127+
(nonzero) is returned.
120128

121129
[:ref:`var_funcs` | :ref:`basic_model_interface`]
122130

@@ -138,6 +146,8 @@ a variable; i.e., the number of items multiplied by the size of each item.
138146

139147
* In C++ and Python, the *nbytes* argument is omitted and the total
140148
amount of memory used by the variable is returned from the function.
149+
* In C and Fortran, an integer status code indicating success (zero) or failure
150+
(nonzero) is returned.
141151

142152
[:ref:`var_funcs` | :ref:`basic_model_interface`]
143153

@@ -164,9 +174,10 @@ element the variable is defined. Valid return values are:
164174

165175
* In C++ and Python, the *location* argument is omitted and the location
166176
is returned from the function.
177+
* In C and Fortran, an integer status code indicating success (zero) or failure
178+
(nonzero) is returned.
167179
* If the given variable is a scalar (i.e., defined on a :ref:`scalar
168-
grid <unstructured_grids>`), the return from this function is
169-
ignored.
180+
grid <unstructured_grids>`), the location from this function is ignored.
170181

171182
[:ref:`var_funcs` | :ref:`basic_model_interface`]
172183

0 commit comments

Comments
 (0)