14 #include "nc4internal.h" 16 #define HDF5_MAX_NAME 1024 19 #define NCHECK(expr) {if((expr)!=NC_NOERR) {goto done;}} 22 #define HCHECK(expr) {if((expr)<0) {ncstat = NC_EHDFERR; goto done;}} 33 NC4_fileinfo_init(
void)
36 unsigned major,minor,release;
40 globalpropinfo.version = NCPROPS_VERSION;
41 globalpropinfo.netcdfver[0] =
'\0';
42 globalpropinfo.hdf5ver[0] =
'\0';
44 stat = NC4_hdf5get_libversion(&major,&minor,&release);
46 snprintf(globalpropinfo.hdf5ver,
sizeof(globalpropinfo.hdf5ver),
47 "%1u.%1u.%1u",major,minor,release);
48 strncpy(globalpropinfo.netcdfver,PACKAGE_VERSION,
sizeof(globalpropinfo.netcdfver));
63 NC4_properties_parse(
struct NCPROPINFO* ncprops,
const char* text)
68 char* propdata = NULL;
71 ncprops->hdf5ver[0] =
'\0';
72 ncprops->netcdfver[0] =
'\0';
76 propdata = (
char*)malloc(len+1);
78 memcpy(propdata,text,len+1);
86 char* q = strchr(p,
'=');
91 q = strchr(p,NCPROPSSEP);
92 if(q == NULL) q = (p+strlen(p));
else* q++ =
'\0';
95 if(strcmp(name,NCPVERSION) == 0) {
99 }
else if(strcmp(name,NCPNCLIBVERSION) == 0)
100 strncpy(ncprops->netcdfver,value,
sizeof(ncprops->netcdfver)-1);
101 else if(strcmp(name,NCPHDF5LIBVERSION) == 0)
102 strncpy(ncprops->hdf5ver,value,
sizeof(ncprops->hdf5ver)-1);
107 ncprops->netcdfver[
sizeof(ncprops->netcdfver)-1] =
'\0';
108 ncprops->hdf5ver[
sizeof(ncprops->hdf5ver)-1] =
'\0';
110 if(propdata != NULL) free(propdata);
123 NC4_get_propattr(NC_HDF5_FILE_INFO_T* h5)
136 grp = h5->root_grp->hdf_grpid;
138 if(H5Aexists(grp,NCPROPS) > 0) {
139 attid = H5Aopen_name(grp, NCPROPS);
140 aspace = H5Aget_space(attid);
141 atype = H5Aget_type(attid);
143 t_class = H5Tget_class(atype);
144 if(t_class != H5T_STRING) {ncstat =
NC_EATTMETA;
goto done;}
145 size = H5Tget_size(atype);
146 if(size == 0)
goto done;
147 text = (
char*)malloc(size+1);
150 HCHECK((ntype = H5Tget_native_type(atype, H5T_DIR_ASCEND)));
151 HCHECK((H5Aread(attid, ntype, text)));
155 ncstat = NC4_properties_parse(&h5->fileinfo->propattr,text);
158 if(attid >= 0) HCHECK((H5Aclose(attid)));
159 if(aspace >= 0) HCHECK((H5Sclose(aspace)));
160 if(ntype >= 0) HCHECK((H5Tclose(ntype)));
161 if(atype >= 0) HCHECK((H5Tclose(atype)));
162 if(text != NULL) free(text);
175 NC4_put_propattr(NC_HDF5_FILE_INFO_T* h5)
185 grp = h5->root_grp->hdf_grpid;
187 if(H5Aexists(grp,NCPROPS) == 0) {
188 ncstat = NC4_buildpropinfo(&h5->fileinfo->propattr,&text);
189 if(text == NULL || ncstat !=
NC_NOERR) {
193 HCHECK((atype = H5Tcopy(H5T_C_S1)));
194 HCHECK((H5Tset_cset(atype, H5T_CSET_ASCII)));
195 HCHECK((H5Tset_size(atype, strlen(text)+1)));
196 HCHECK((aspace = H5Screate(H5S_SCALAR)));
197 HCHECK((attid = H5Acreate(grp, NCPROPS, atype, aspace, H5P_DEFAULT)));
198 HCHECK((H5Awrite(attid, atype, text)));
206 if(attid >= 0) HCHECK((H5Aclose(attid)));
207 if(aspace >= 0) HCHECK((H5Sclose(aspace)));
208 if(atype >= 0) HCHECK((H5Tclose(atype)));
222 NC4_get_fileinfo(NC_HDF5_FILE_INFO_T* h5,
struct NCPROPINFO* init)
227 h5->fileinfo = (
struct NCFILEINFO*)calloc(1,
sizeof(
struct NCFILEINFO));
228 if(h5->fileinfo == NULL)
232 NCHECK((ncstat = NC4_hdf5get_superblock(h5,&h5->fileinfo->superblockversion)));
235 NCHECK((ncstat = NC4_get_propattr(h5)));
237 h5->fileinfo->propattr = *init;
253 NC4_buildpropinfo(
struct NCPROPINFO* info,
char** propdatap)
256 char* propdata = NULL;
258 if(info == NULL || info->version == 0)
return NC_EINVAL;
259 if(propdatap == NULL)
265 total += strlen(NCPVERSION);
266 total += strlen(
"=00000000");
267 if(strlen(info->netcdfver) > 0) {
269 total += strlen(NCPNCLIBVERSION);
270 total += strlen(
"=");
271 total += strlen(info->netcdfver);
273 if(strlen(info->hdf5ver) > 0) {
275 total += strlen(NCPHDF5LIBVERSION);
276 total += strlen(
"=");
277 total += strlen(info->hdf5ver);
279 propdata = (
char*)malloc(total+1);
282 snprintf(propdata,total+1,
284 NCPVERSION,info->version,
285 NCPNCLIBVERSION,info->netcdfver,
286 NCPHDF5LIBVERSION,info->hdf5ver);
288 propdata[total] =
'\0';
289 *propdatap = propdata;
struct NCPROPINFO globalpropinfo
Global property info.
#define NC_ENOMEM
Memory allocation (malloc) failure.
Main header file for the C API.
#define NC_EATTMETA
Problem with attribute metadata.
#define NC_EINVAL
Invalid Argument.
#define NC_NOERR
No Error.