| 136 | } |
| 137 | |
| 138 | bool vtkNetCDFAccessor::ReadTextAttribute( |
| 139 | int ncid, int varId, const char* name, std::string& result) |
| 140 | { |
| 141 | size_t length; |
| 142 | if (this->inq_attlen(ncid, varId, name, &length) != NC_NOERR) |
| 143 | { |
| 144 | return false; |
| 145 | } |
| 146 | |
| 147 | result.resize(length); |
| 148 | if (length > 0) |
| 149 | { |
| 150 | if (this->get_att_text(ncid, varId, name, &result.at(0)) != NC_NOERR) |
| 151 | { |
| 152 | return false; |
| 153 | } |
| 154 | } |
| 155 | else |
| 156 | { |
| 157 | // If length == 0, then there really is nothing to read. Do nothing |
| 158 | } |
| 159 | |
| 160 | // The line below seems weird, but it is here for a good reason. In general, |
| 161 | // text attributes are not null terminated, so you have to add your own (which |
| 162 | // the std::string will do for us). However, sometimes a null terminating |
| 163 | // character is written in the attribute anyway. In a C string this is no big |
| 164 | // deal. But it means that the std::string has a null character in it and it |
| 165 | // is technically different than its own C string. This line corrects that |
| 166 | // regardless of whether the null string was written we will get the right |
| 167 | // string. |
| 168 | // NOLINTNEXTLINE(readability-redundant-string-cstr) |
| 169 | result = result.c_str(); |
| 170 | |
| 171 | return true; |
| 172 | } |
| 173 | |
| 174 | bool vtkNetCDFAccessor::NeedsFileName() |
| 175 | { |
no test coverage detected