Get NetCDF string attribute. More...
#include <io.h>
Go to the source code of this file.
Functions | |
int | get_attribute_str (char **var, int ncinid, int varid, char *attrname) |
Get NetCDF string attribute. |
Get NetCDF string attribute.
Definition in file get_attribute_str.c.
int get_attribute_str | ( | char ** | var, | |
int | ncinid, | |||
int | varid, | |||
char * | attrname | |||
) |
Get NetCDF string attribute.
[out] | var | String attribute value |
[in] | ncinid | NetCDF input filename ID |
[in] | varid | NetCDF variable ID |
[in] | attrname | NetCDF attribute name |
Definition at line 66 of file get_attribute_str.c.
References alloc_error().
Referenced by read_netcdf_dims_3d(), read_netcdf_var_2d(), read_netcdf_var_3d(), and read_netcdf_var_3d_2d().
00067 { 00075 int istat; /* Diagnostic status */ 00076 size_t t_len; /* Length of attribute value string */ 00077 00078 /* Get attribute length */ 00079 istat = nc_inq_attlen(ncinid, varid, attrname, &t_len); 00080 if (istat == NC_NOERR) { 00081 /* Allocate required space before retrieving values */ 00082 (*var) = (char *) malloc(t_len + 1); 00083 if ((*var) == NULL) alloc_error(__FILE__, __LINE__); 00084 /* Get attribute value */ 00085 istat = nc_get_att_text(ncinid, varid, attrname, (*var)); 00086 if (istat != NC_NOERR) 00087 (*var)[0] = '\0'; 00088 else 00089 if ((*var)[t_len-1] != '\0') 00090 (*var)[t_len] = '\0'; /* null terminate if needed */ 00091 } 00092 else { 00093 /* Allocate required space */ 00094 (*var) = (char *) malloc(sizeof(char)); 00095 if ((*var) == NULL) alloc_error(__FILE__, __LINE__); 00096 (*var)[0] = '\0'; 00097 } 00098 00099 /* Diagnostic status */ 00100 return ((int) istat); 00101 }