MCPcopy Create free account
hub / github.com/FEniCS/dolfinx / set_attribute

Method set_attribute

cpp/dolfinx/io/HDF5Interface.cpp:162–193  ·  view source on GitHub ↗

-----------------------------------------------------------------------------

Source from the content-addressed store, hash-verified

160}
161//-----------------------------------------------------------------------------
162void io::hdf5::set_attribute(hid_t handle, const std::string& attr_name,
163 const std::string& value)
164{
165 if (htri_t attr_exists = H5Aexists(handle, attr_name.c_str());
166 attr_exists < 0)
167 {
168 throw std::runtime_error("Error checking attribute");
169 }
170 else if (attr_exists == 0)
171 {
172 // create attribute
173 hid_t space_id = H5Screate(H5S_SCALAR);
174 hid_t atype = H5Tcopy(H5T_C_S1);
175 H5Tset_size(atype, value.size());
176 H5Tset_strpad(atype, H5T_STR_NULLTERM);
177 hid_t attr_id = H5Acreate(handle, attr_name.c_str(), atype, space_id,
178 H5P_DEFAULT, H5P_DEFAULT);
179 H5Awrite(attr_id, atype, value.c_str());
180 H5Aclose(attr_id);
181 H5Sclose(space_id);
182 }
183 else
184 {
185 // update attribute
186 hid_t attr_id = H5Aopen(handle, attr_name.c_str(), H5P_DEFAULT);
187 hid_t atype = H5Aget_type(attr_id);
188 H5Tset_size(atype, value.size());
189 H5Tset_strpad(atype, H5T_STR_NULLTERM);
190 H5Awrite(attr_id, atype, value.c_str());
191 H5Aclose(attr_id);
192 }
193}
194//-----------------------------------------------------------------------------
195void io::hdf5::set_attribute(hid_t handle, const std::string& attr_name,
196 std::int32_t value)

Callers

nothing calls this directly

Calls 2

dataMethod · 0.80
sizeMethod · 0.45

Tested by

no test coverage detected