This archive contains answers to questions sent to Unidata support through mid-2025. Note that the archive is no longer being updated. We provide the archive for reference; many of the answers presented here remain technically correct, even if somewhat outdated. For the most up-to-date information on the use of NSF Unidata software and data services, please consult the Software Documentation first.
Hi Thomas, > I have a question about the correct use of nc_get_att_string. > > int nc_get_att_string (int ncid, int varid, const char *name, char **ip); > > I understand the function should be used as follows: > > 1) user determines the number of strings in the attribute (for > example using nc_inq_att_len). > > 2) user creates a buffer ip, holding a number of char*'s, long enough > to store the required number of attributes. The char*'s in the > buffer need not be initialized/allocated. > > 3) when calling nc_get_att_string, the netCDF library will allocate > character buffers to hold the string attributes, and store their > addresses in the char** ip. > > 4) the user should free the char*'s ip[0],ip[1,],... when he/she is > done using the strings. > > Can you confirm this is the correct way to use the function? I > believe the behaviour of the function w.r.t. malloc/free (who > allocates, and who calls free() ) is not explicitly documented. You're right, I think the documentation for that function is currently inadequate. There's a test program in the distribution that demonstrates the intended usage, starting at line 133: https://github.com/Unidata/netcdf-c/blob/master/nc_test4/tst_strings.c It shows use of the nc_free_string() function to free string data, which is malloced by the library. Thanks for pointing out the missing documentation problem. --Russ Russ Rew UCAR Unidata Program address@hidden http://www.unidata.ucar.edu Ticket Details =================== Ticket ID: LUG-158105 Department: Support netCDF Priority: Normal Status: Closed