get_attribute_str.c File Reference

Get NetCDF string attribute. More...

#include <io.h>
Include dependency graph for get_attribute_str.c:

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.

Detailed Description

Get NetCDF string attribute.

Definition in file get_attribute_str.c.


Function Documentation

int get_attribute_str ( char **  var,
int  ncinid,
int  varid,
char *  attrname 
)

Get NetCDF string attribute.

Parameters:
[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 }


Generated on 12 May 2016 for DSCLIM by  doxygen 1.6.1