-
Notifications
You must be signed in to change notification settings - Fork 266
/
Copy pathdcompound.c
483 lines (387 loc) · 14.5 KB
/
dcompound.c
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
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
/*! \file
Functions for Compound Types
Copyright 2018 University Corporation for Atmospheric
Research/Unidata. See \ref copyright file for more info. */
#include "ncdispatch.h"
/** \name Compound Types
Functions to create and learn about compound types. */
/*! \{ */ /* All these functions are part of this named group... */
/** \ingroup user_types
Create a compound type. Provide an ncid, a name, and a total size (in
bytes) of one element of the completed compound type.
After calling this function, fill out the type with repeated calls to
nc_insert_compound(). Call nc_insert_compound() once for each field
you wish to insert into the compound type.
\param ncid \ref ncid
\param size The size, in bytes, of the compound type.
\param name \ref object_name of the created type.
\param typeidp The type ID of the new type is copied here.
\returns ::NC_NOERR No error.
\returns ::NC_EBADID Bad \ref ncid.
\returns ::NC_EBADTYPE Bad type id.
\returns ::NC_ENAMEINUSE That name is in use.
\returns ::NC_EMAXNAME Name exceeds max length NC_MAX_NAME.
\returns ::NC_EBADNAME Name contains illegal characters.
\returns ::NC_ESTRICTNC3 Attempting a netCDF-4 operation on a netCDF-3 file.
\returns ::NC_ENOTNC4 This file was created with the strict netcdf-3 flag, therefore netcdf-4 operations are not allowed. (see nc_open).
\returns ::NC_EHDFERR An error was reported by the HDF5 layer.
\returns ::NC_EPERM Attempt to write to a read-only file.
\returns ::NC_ENOTINDEFINE Not in define mode.
\section nc_def_compound_example Example
\code
struct s1
{
int i1;
int i2;
};
struct s1 data[DIM_LEN], data_in[DIM_LEN];
if (nc_create(FILE_NAME, NC_NETCDF4, &ncid)) ERR;
if (nc_def_compound(ncid, sizeof(struct s1), SVC_REC, &typeid)) ERR;
if (nc_insert_compound(ncid, typeid, BATTLES_WITH_KLINGONS,
HOFFSET(struct s1, i1), NC_INT)) ERR;
if (nc_insert_compound(ncid, typeid, DATES_WITH_ALIENS,
HOFFSET(struct s1, i2), NC_INT)) ERR;
if (nc_def_dim(ncid, STARDATE, DIM_LEN, &dimid)) ERR;
if (nc_def_var(ncid, SERVICE_RECORD, typeid, 1, dimids, &varid)) ERR;
if (nc_put_var(ncid, varid, data)) ERR;
if (nc_close(ncid)) ERR;
\endcode
*/
int
nc_def_compound(int ncid, size_t size, const char *name,
nc_type *typeidp)
{
NC* ncp;
int stat = NC_check_id(ncid,&ncp);
if(stat != NC_NOERR) return stat;
return ncp->dispatch->def_compound(ncid,size,name,typeidp);
}
/** \ingroup user_types
Insert a named field into a compound type.
\param ncid \ref ncid
\param xtype The typeid for this compound type, as returned by
nc_def_compound(), or nc_inq_var().
\param name The \ref object_name of the new field.
\param offset Offset in byte from the beginning of the compound type
for this field.
\param field_typeid The type of the field to be inserted.
\returns ::NC_NOERR No error.
\returns ::NC_EBADID Bad \ref ncid.
\returns ::NC_EBADTYPE Bad type id.
\returns ::NC_ENAMEINUSE That name is in use.
\returns ::NC_EMAXNAME Name exceeds max length NC_MAX_NAME.
\returns ::NC_EBADNAME Name contains illegal characters.
\returns ::NC_ENOTNC4 Not an netCDF-4 file, or classic model enabled.
\returns ::NC_EHDFERR An error was reported by the HDF5 layer.
\returns ::NC_EPERM Attempt to write to a read-only file.
\returns ::NC_ENOTINDEFINE Not in define mode.
*/
int
nc_insert_compound(int ncid, nc_type xtype, const char *name,
size_t offset, nc_type field_typeid)
{
NC *ncp;
int stat = NC_check_id(ncid, &ncp);
if(stat != NC_NOERR) return stat;
return ncp->dispatch->insert_compound(ncid, xtype, name,
offset, field_typeid);
}
/** \ingroup user_types
Insert a named array field into a compound type.
\param ncid \ref ncid
\param xtype The typeid for this compound type, as returned by
nc_def_compound(), or nc_inq_var().
\param name The \ref object_name of the new field.
\param offset Offset in byte from the beginning of the compound type
for this field.
\param field_typeid The type of the field to be inserted.
\param ndims Number of dimensions in array.
\param dim_sizes Array of dimension sizes.
\returns ::NC_NOERR No error.
\returns ::NC_EBADID Bad \ref ncid.
\returns ::NC_EBADTYPE Bad type id.
\returns ::NC_ENAMEINUSE That name is in use.
\returns ::NC_EMAXNAME Name exceeds max length NC_MAX_NAME.
\returns ::NC_EBADNAME Name contains illegal characters.
\returns ::NC_ESTRICTNC3 Attempting a netCDF-4 operation on a netCDF-3 file.
\returns ::NC_ENOTNC4 Not an netCDF-4 file, or classic model enabled.
\returns ::NC_EHDFERR An error was reported by the HDF5 layer.
\returns ::NC_EPERM Attempt to write to a read-only file.
\returns ::NC_ENOTINDEFINE Not in define mode.
*/
int
nc_insert_array_compound(int ncid, nc_type xtype, const char *name,
size_t offset, nc_type field_typeid,
int ndims, const int *dim_sizes)
{
NC* ncp;
int stat = NC_check_id(ncid,&ncp);
if(stat != NC_NOERR) return stat;
return ncp->dispatch->insert_array_compound(ncid,xtype,name,offset,field_typeid,ndims,dim_sizes);
}
/** \ingroup user_types
Learn about a compound type. Get the number of fields, len, and
name of a compound type.
\param ncid \ref ncid
\param xtype The typeid for this compound type, as returned by
nc_def_compound(), or nc_inq_var().
\param name Returned \ref object_name of compound type. \ref
ignored_if_null.
\param sizep Returned size of compound type in bytes. \ref ignored_if_null.
\param nfieldsp The number of fields in the compound type will be
placed here. \ref ignored_if_null.
\returns ::NC_NOERR No error.
\returns ::NC_EBADID Bad \ref ncid.
\returns ::NC_EBADTYPE Bad type id.
\returns ::NC_ENOTNC4 Not an netCDF-4 file, or classic model enabled.
\returns ::NC_EHDFERR An error was reported by the HDF5 layer.
*/
int
nc_inq_compound(int ncid, nc_type xtype, char *name,
size_t *sizep, size_t *nfieldsp)
{
int class = 0;
int stat = nc_inq_user_type(ncid,xtype,name,sizep,NULL,nfieldsp,&class);
if(stat != NC_NOERR) return stat;
if(class != NC_COMPOUND) stat = NC_EBADTYPE;
return stat;
}
/** \ingroup user_types
Learn the name of a compound type.
\param ncid \ref ncid
\param xtype The typeid for this compound type, as returned by
nc_def_compound(), or nc_inq_var().
\param name Returned \ref object_name of compound type. \ref
ignored_if_null.
\returns ::NC_NOERR No error.
\returns ::NC_EBADID Bad \ref ncid.
\returns ::NC_EBADTYPE Bad type id.
\returns ::NC_ENOTNC4 Not an netCDF-4 file, or classic model enabled.
\returns ::NC_EHDFERR An error was reported by the HDF5 layer.
*/
int
nc_inq_compound_name(int ncid, nc_type xtype, char *name)
{
return nc_inq_compound(ncid,xtype,name,NULL,NULL);
}
/** \ingroup user_types
Learn the size of a compound type.
\param ncid \ref ncid
\param xtype The typeid for this compound type, as returned by
nc_def_compound(), or nc_inq_var().
\param sizep Returned size of compound type in bytes. \ref
ignored_if_null.
\returns ::NC_NOERR No error.
\returns ::NC_EBADID Bad \ref ncid.
\returns ::NC_EBADTYPE Bad type id.
\returns ::NC_ENOTNC4 Not an netCDF-4 file, or classic model enabled.
\returns ::NC_EHDFERR An error was reported by the HDF5 layer.
*/
int
nc_inq_compound_size(int ncid, nc_type xtype, size_t *sizep)
{
return nc_inq_compound(ncid,xtype,NULL,sizep,NULL);
}
/** \ingroup user_types
Learn the number of fields in a compound type.
\param ncid \ref ncid
\param xtype The typeid for this compound type, as returned by
nc_def_compound(), or nc_inq_var().
\param nfieldsp The number of fields in the compound type will be
placed here. \ref ignored_if_null.
\returns ::NC_NOERR No error.
\returns ::NC_EBADID Bad \ref ncid.
\returns ::NC_EBADTYPE Bad type id.
\returns ::NC_ENOTNC4 Not an netCDF-4 file, or classic model enabled.
\returns ::NC_EHDFERR An error was reported by the HDF5 layer.
*/
int
nc_inq_compound_nfields(int ncid, nc_type xtype, size_t *nfieldsp)
{
return nc_inq_compound(ncid,xtype,NULL,NULL,nfieldsp);
}
/** \ingroup user_types
Get information about one of the fields of a compound type.
\param ncid \ref ncid
\param xtype The typeid for this compound type, as returned by
nc_def_compound(), or nc_inq_var().
\param fieldid A zero-based index number specifying a field in the
compound type.
\param name Returned \ref object_name of the field. \ref
ignored_if_null.
\param offsetp A pointer which will get the offset of the field. \ref
ignored_if_null.
\param field_typeidp A pointer which will get the typeid of the
field. \ref ignored_if_null.
\param ndimsp A pointer which will get the number of dimensions of the
field. \ref ignored_if_null.
\param dim_sizesp A pointer which will get the dimension sizes of the
field. \ref ignored_if_null.
\returns ::NC_NOERR No error.
\returns ::NC_EBADID Bad \ref ncid.
\returns ::NC_EBADTYPE Bad type id.
\returns ::NC_ENOTNC4 Not an netCDF-4 file, or classic model enabled.
\returns ::NC_EHDFERR An error was reported by the HDF5 layer.
*/
int
nc_inq_compound_field(int ncid, nc_type xtype, int fieldid,
char *name, size_t *offsetp,
nc_type *field_typeidp, int *ndimsp,
int *dim_sizesp)
{
NC* ncp;
int stat = NC_check_id(ncid,&ncp);
if(stat != NC_NOERR) return stat;
return ncp->dispatch->inq_compound_field(ncid, xtype, fieldid,
name, offsetp, field_typeidp,
ndimsp, dim_sizesp);
}
/** \ingroup user_types
Get information about one of the fields of a compound type.
\param ncid \ref ncid
\param xtype The typeid for this compound type, as returned by
nc_def_compound(), or nc_inq_var().
\param fieldid A zero-based index number specifying a field in the
compound type.
\param name Returned \ref object_name of the field. \ref
ignored_if_null.
\returns ::NC_NOERR No error.
\returns ::NC_EBADID Bad \ref ncid.
\returns ::NC_EBADTYPE Bad type id.
\returns ::NC_ENOTNC4 Not an netCDF-4 file, or classic model enabled.
\returns ::NC_EHDFERR An error was reported by the HDF5 layer.
*/
int
nc_inq_compound_fieldname(int ncid, nc_type xtype, int fieldid,
char *name)
{
NC* ncp;
int stat = NC_check_id(ncid,&ncp);
if(stat != NC_NOERR) return stat;
return ncp->dispatch->inq_compound_field(ncid, xtype, fieldid,
name, NULL, NULL, NULL,
NULL);
}
/** \ingroup user_types
Get information about one of the fields of a compound type.
\param ncid \ref ncid
\param xtype The typeid for this compound type, as returned by
nc_def_compound(), or nc_inq_var().
\param fieldid A zero-based index number specifying a field in the
compound type.
\param offsetp A pointer which will get the offset of the field. \ref
ignored_if_null.
\returns ::NC_NOERR No error.
\returns ::NC_EBADID Bad \ref ncid.
\returns ::NC_EBADTYPE Bad type id.
\returns ::NC_ENOTNC4 Not an netCDF-4 file, or classic model enabled.
\returns ::NC_EHDFERR An error was reported by the HDF5 layer.
*/
int
nc_inq_compound_fieldoffset(int ncid, nc_type xtype, int fieldid,
size_t *offsetp)
{
NC* ncp;
int stat = NC_check_id(ncid,&ncp);
if(stat != NC_NOERR) return stat;
return ncp->dispatch->inq_compound_field(ncid,xtype,fieldid,NULL,offsetp,NULL,NULL,NULL);
}
/** \ingroup user_types
Get information about one of the fields of a compound type.
\param ncid \ref ncid
\param xtype The typeid for this compound type, as returned by
nc_def_compound(), or nc_inq_var().
\param fieldid A zero-based index number specifying a field in the
compound type.
\param field_typeidp A pointer which will get the typeid of the
field. \ref ignored_if_null.
\returns ::NC_NOERR No error.
\returns ::NC_EBADID Bad \ref ncid.
\returns ::NC_EBADTYPE Bad type id.
\returns ::NC_ENOTNC4 Not an netCDF-4 file, or classic model enabled.
\returns ::NC_EHDFERR An error was reported by the HDF5 layer.
*/
int
nc_inq_compound_fieldtype(int ncid, nc_type xtype, int fieldid,
nc_type *field_typeidp)
{
NC* ncp;
int stat = NC_check_id(ncid,&ncp);
if(stat != NC_NOERR) return stat;
return ncp->dispatch->inq_compound_field(ncid,xtype,fieldid,NULL,NULL,field_typeidp,NULL,NULL);
}
/** \ingroup user_types
Get information about one of the fields of a compound type.
\param ncid \ref ncid
\param xtype The typeid for this compound type, as returned by
nc_def_compound(), or nc_inq_var().
\param fieldid A zero-based index number specifying a field in the
compound type.
\param ndimsp A pointer which will get the number of dimensions of the
field. \ref ignored_if_null.
\returns ::NC_NOERR No error.
\returns ::NC_EBADID Bad \ref ncid.
\returns ::NC_EBADTYPE Bad type id.
\returns ::NC_ENOTNC4 Not an netCDF-4 file, or classic model enabled.
\returns ::NC_EHDFERR An error was reported by the HDF5 layer.
*/
int
nc_inq_compound_fieldndims(int ncid, nc_type xtype, int fieldid,
int *ndimsp)
{
NC* ncp;
int stat = NC_check_id(ncid,&ncp);
if(stat != NC_NOERR) return stat;
return ncp->dispatch->inq_compound_field(ncid,xtype,fieldid,NULL,NULL,NULL,ndimsp,NULL);
}
/** \ingroup user_types
Get information about one of the fields of a compound type.
\param ncid \ref ncid
\param xtype The typeid for this compound type, as returned by
nc_def_compound(), or nc_inq_var().
\param fieldid A zero-based index number specifying a field in the
compound type.
\param dim_sizesp A pointer which will get the dimension sizes of the
field. \ref ignored_if_null.
\returns ::NC_NOERR No error.
\returns ::NC_EBADID Bad \ref ncid.
\returns ::NC_EBADTYPE Bad type id.
\returns ::NC_ENOTNC4 Not an netCDF-4 file, or classic model enabled.
\returns ::NC_EHDFERR An error was reported by the HDF5 layer.
*/
int
nc_inq_compound_fielddim_sizes(int ncid, nc_type xtype, int fieldid,
int *dim_sizesp)
{
NC *ncp;
int stat = NC_check_id(ncid, &ncp);
if(stat != NC_NOERR) return stat;
return ncp->dispatch->inq_compound_field(ncid, xtype, fieldid,
NULL, NULL, NULL, NULL,
dim_sizesp);
}
/** \ingroup user_types
Learn the Index of a Named Field in a Compound Type. Get the index
* of a field in a compound type from the name.
\param ncid \ref ncid
\param xtype The typeid for this compound type, as returned by
nc_def_compound(), or nc_inq_var().
\param name \ref object_name of the field. \ref ignored_if_null.
\param fieldidp A pointer which will get the index of the named
field. \ref ignored_if_null.
\returns ::NC_NOERR No error.
\returns ::NC_EBADID Bad \ref ncid.
\returns ::NC_EBADTYPE Bad type id.
\returns ::NC_ENOTNC4 Not an netCDF-4 file, or classic model enabled.
\returns ::NC_EHDFERR An error was reported by the HDF5 layer.
*/
int
nc_inq_compound_fieldindex(int ncid, nc_type xtype, const char *name,
int *fieldidp)
{
NC* ncp;
int stat = NC_check_id(ncid,&ncp);
if(stat != NC_NOERR) return stat;
return ncp->dispatch->inq_compound_fieldindex(ncid,xtype,name,fieldidp);
}
/*! \} */ /* End of named group ...*/