1 | /*! \file |
---|
2 | Functions for Enum Types |
---|
3 | |
---|
4 | Copyright 2011 University Corporation for Atmospheric |
---|
5 | Research/Unidata. See \ref copyright file for more info. */ |
---|
6 | |
---|
7 | #include "ncdispatch.h" |
---|
8 | |
---|
9 | /** \name Enum Types |
---|
10 | Functions to create and learn about enum types. */ |
---|
11 | /*! \{ */ /* All these functions are part of this named group... */ |
---|
12 | |
---|
13 | /** \ingroup user_types |
---|
14 | Create an enum type. Provide an ncid, a name, and a base integer type. |
---|
15 | |
---|
16 | After calling this function, fill out the type with repeated calls to |
---|
17 | nc_insert_enum(). Call nc_insert_enum() once for each value you wish |
---|
18 | to make part of the enumeration. |
---|
19 | |
---|
20 | \param ncid \ref ncid |
---|
21 | |
---|
22 | \param base_typeid The base integer type for this enum. Must be one |
---|
23 | of: ::NC_BYTE, ::NC_UBYTE, ::NC_SHORT, ::NC_USHORT, ::NC_INT, |
---|
24 | ::NC_UINT, ::NC_INT64, ::NC_UINT64. |
---|
25 | |
---|
26 | \param name \ref object_name of new type. |
---|
27 | |
---|
28 | \param typeidp A pointer to an nc_type. The typeid of the new type |
---|
29 | will be placed there. |
---|
30 | |
---|
31 | \returns ::NC_NOERR No error. |
---|
32 | \returns ::NC_EBADID Bad \ref ncid. |
---|
33 | \returns ::NC_EBADTYPE Bad type id. |
---|
34 | \returns ::NC_ENOTNC4 Not an netCDF-4 file, or classic model enabled. |
---|
35 | \returns ::NC_EHDFERR An error was reported by the HDF5 layer. |
---|
36 | \returns ::NC_ENAMEINUSE That name is in use. |
---|
37 | \returns ::NC_EMAXNAME Name exceeds max length NC_MAX_NAME. |
---|
38 | \returns ::NC_EBADNAME Name contains illegal characters. |
---|
39 | \returns ::NC_EPERM Attempt to write to a read-only file. |
---|
40 | \returns ::NC_ENOTINDEFINE Not in define mode. |
---|
41 | */ |
---|
42 | int |
---|
43 | nc_def_enum(int ncid, nc_type base_typeid, const char *name, nc_type *typeidp) |
---|
44 | { |
---|
45 | NC* ncp; |
---|
46 | int stat = NC_check_id(ncid,&ncp); |
---|
47 | if(stat != NC_NOERR) return stat; |
---|
48 | return ncp->dispatch->def_enum(ncid,base_typeid,name,typeidp); |
---|
49 | } |
---|
50 | |
---|
51 | /** \ingroup user_types |
---|
52 | Insert a named member into a enum type. |
---|
53 | |
---|
54 | \param ncid \ref ncid |
---|
55 | \param xtype |
---|
56 | \param name The identifier (\ref object_name) of the new member. |
---|
57 | \param value The value that is to be associated with this member. |
---|
58 | |
---|
59 | \returns ::NC_NOERR No error. |
---|
60 | \returns ::NC_EBADID Bad \ref ncid. |
---|
61 | \returns ::NC_EBADTYPE Bad type id. |
---|
62 | \returns ::NC_ENOTNC4 Not an netCDF-4 file, or classic model enabled. |
---|
63 | \returns ::NC_EHDFERR An error was reported by the HDF5 layer. |
---|
64 | \returns ::NC_ENAMEINUSE That name is in use. |
---|
65 | \returns ::NC_EMAXNAME Name exceeds max length NC_MAX_NAME. |
---|
66 | \returns ::NC_EBADNAME Name contains illegal characters. |
---|
67 | \returns ::NC_EPERM Attempt to write to a read-only file. |
---|
68 | \returns ::NC_ENOTINDEFINE Not in define mode. |
---|
69 | */ |
---|
70 | int |
---|
71 | nc_insert_enum(int ncid, nc_type xtype, const char *name, |
---|
72 | const void *value) |
---|
73 | { |
---|
74 | NC *ncp; |
---|
75 | int stat = NC_check_id(ncid, &ncp); |
---|
76 | if(stat != NC_NOERR) return stat; |
---|
77 | return ncp->dispatch->insert_enum(ncid, xtype, name, |
---|
78 | value); |
---|
79 | } |
---|
80 | |
---|
81 | /** \ingroup user_types |
---|
82 | Learn about a user-define enumeration type. |
---|
83 | |
---|
84 | \param ncid \ref ncid |
---|
85 | |
---|
86 | \param xtype Typeid to inquire about. |
---|
87 | |
---|
88 | \param name \ref object_name of type will be copied here. \ref |
---|
89 | ignored_if_null. |
---|
90 | |
---|
91 | \param base_nc_typep Typeid if the base type of the enum.\ref |
---|
92 | ignored_if_null. |
---|
93 | |
---|
94 | \param base_sizep Pointer that will get the size in bytes of the base |
---|
95 | type. \ref ignored_if_null. |
---|
96 | |
---|
97 | \param num_membersp Pointer that will get the number of members |
---|
98 | defined for this enum type. \ref ignored_if_null. |
---|
99 | |
---|
100 | \returns ::NC_NOERR No error. |
---|
101 | \returns ::NC_EBADID Bad \ref ncid. |
---|
102 | \returns ::NC_EBADTYPE Bad type id. |
---|
103 | \returns ::NC_ENOTNC4 Not an netCDF-4 file, or classic model enabled. |
---|
104 | \returns ::NC_EHDFERR An error was reported by the HDF5 layer. |
---|
105 | */ |
---|
106 | int |
---|
107 | nc_inq_enum(int ncid, nc_type xtype, char *name, nc_type *base_nc_typep, |
---|
108 | size_t *base_sizep, size_t *num_membersp) |
---|
109 | { |
---|
110 | int class = 0; |
---|
111 | int stat = nc_inq_user_type(ncid, xtype, name, base_sizep, |
---|
112 | base_nc_typep, num_membersp, &class); |
---|
113 | if(stat != NC_NOERR) return stat; |
---|
114 | if(class != NC_ENUM) stat = NC_EBADTYPE; |
---|
115 | return stat; |
---|
116 | } |
---|
117 | |
---|
118 | /** \ingroup user_types |
---|
119 | Learn about a about a member of an enum type. |
---|
120 | |
---|
121 | \param ncid \ref ncid |
---|
122 | |
---|
123 | \param xtype Typeid of the enum type. |
---|
124 | |
---|
125 | \param idx Index to the member to inquire about. |
---|
126 | |
---|
127 | \param name The identifier (\ref object_name) of this member will be |
---|
128 | copied here. \ref ignored_if_null. |
---|
129 | |
---|
130 | \param value The value of this member will be copied here. \ref |
---|
131 | ignored_if_null. |
---|
132 | |
---|
133 | \returns ::NC_NOERR No error. |
---|
134 | \returns ::NC_EBADID Bad \ref ncid. |
---|
135 | \returns ::NC_EBADTYPE Bad type id. |
---|
136 | \returns ::NC_ENOTNC4 Not an netCDF-4 file, or classic model enabled. |
---|
137 | \returns ::NC_EHDFERR An error was reported by the HDF5 layer. |
---|
138 | */ |
---|
139 | int |
---|
140 | nc_inq_enum_member(int ncid, nc_type xtype, int idx, char *name, |
---|
141 | void *value) |
---|
142 | { |
---|
143 | NC *ncp; |
---|
144 | int stat = NC_check_id(ncid, &ncp); |
---|
145 | if(stat != NC_NOERR) return stat; |
---|
146 | return ncp->dispatch->inq_enum_member(ncid, xtype, idx, name, value); |
---|
147 | } |
---|
148 | |
---|
149 | /** \ingroup user_types |
---|
150 | Get the name which is associated with an enum member value. |
---|
151 | |
---|
152 | \param ncid \ref ncid |
---|
153 | |
---|
154 | \param xtype Typeid of the enum type. |
---|
155 | |
---|
156 | \param value Value of interest. |
---|
157 | |
---|
158 | \param identifier The identifier (\ref object_name) of this value will |
---|
159 | be copied here. \ref ignored_if_null. |
---|
160 | |
---|
161 | \returns ::NC_NOERR No error. |
---|
162 | \returns ::NC_EBADID Bad \ref ncid. |
---|
163 | \returns ::NC_EBADTYPE Bad type id. |
---|
164 | \returns ::NC_ENOTNC4 Not an netCDF-4 file, or classic model enabled. |
---|
165 | \returns ::NC_EHDFERR An error was reported by the HDF5 layer. |
---|
166 | */ |
---|
167 | int |
---|
168 | nc_inq_enum_ident(int ncid, nc_type xtype, long long value, |
---|
169 | char *identifier) |
---|
170 | { |
---|
171 | NC* ncp; |
---|
172 | int stat = NC_check_id(ncid,&ncp); |
---|
173 | if(stat != NC_NOERR) return stat; |
---|
174 | return ncp->dispatch->inq_enum_ident(ncid,xtype,value,identifier); |
---|
175 | } |
---|
176 | /*! \} */ /* End of named group ...*/ |
---|