PSI sics-cvs-psi-complete-tree-post-site-support
This commit is contained in:
331
napi5.c
331
napi5.c
@@ -53,6 +53,11 @@
|
||||
char iAccess[2];
|
||||
} NexusFile5, *pNexusFile5;
|
||||
|
||||
/*
|
||||
forward declaration of NX5closegroup in order to get rid of a nasty
|
||||
warning
|
||||
*/
|
||||
NXstatus CALLING_STYLE NX5closegroup (NXhandle fid);
|
||||
|
||||
/*--------------------------------------------------------------------*/
|
||||
|
||||
@@ -120,10 +125,8 @@
|
||||
size_t rdcc_nbytes;
|
||||
double rdcc_w0;
|
||||
|
||||
/* turn off the automatic HDF error handling */
|
||||
|
||||
H5Eset_auto(NULL,NULL);
|
||||
|
||||
/* turn off the automatic HDF error handling */
|
||||
H5Eset_auto(NULL,NULL);
|
||||
#ifdef USE_FTIME
|
||||
struct timeb timeb_struct;
|
||||
#endif
|
||||
@@ -193,6 +196,12 @@
|
||||
iRet=H5Pget_cache(fapl,&mdc_nelmts,&rdcc_nelmts,&rdcc_nbytes,&rdcc_w0);
|
||||
rdcc_nbytes=(size_t)cacheSize;
|
||||
iRet = H5Pset_cache(fapl,mdc_nelmts,rdcc_nelmts,rdcc_nbytes,rdcc_w0);
|
||||
/*
|
||||
setting the close degree is absolutely necessary in HDF5
|
||||
versions > 1.6. If you use a lessere version and the compiler
|
||||
complains, comment it out but keep this in mind.
|
||||
*/
|
||||
H5Pset_fclose_degree(fapl,H5F_CLOSE_STRONG);
|
||||
am1 = H5F_ACC_TRUNC;
|
||||
pNew->iFID = H5Fcreate (filename, am1, H5P_DEFAULT, fapl);
|
||||
} else {
|
||||
@@ -331,9 +340,29 @@
|
||||
pNexusFile5 pFile = NULL;
|
||||
int iRet;
|
||||
|
||||
pFile=NXI5assert(*fid);
|
||||
pFile=NXI5assert(*fid);
|
||||
|
||||
iRet=0;
|
||||
/*
|
||||
printf("HDF5 object count before close: %d\n",
|
||||
H5Fget_obj_count(pFile->iFID,H5F_OBJ_ALL));
|
||||
*/
|
||||
iRet = H5Fclose(pFile->iFID);
|
||||
|
||||
/*
|
||||
Please leave this here, it helps debugging HDF5 resource leakages
|
||||
printf("HDF5 object count after close: %d\n",
|
||||
H5Fget_obj_count(H5F_OBJ_ALL,H5F_OBJ_ALL));
|
||||
printf("HDF5 dataset count after close: %d\n",
|
||||
H5Fget_obj_count(H5F_OBJ_ALL,H5F_OBJ_DATASET));
|
||||
printf("HDF5 group count after close: %d\n",
|
||||
H5Fget_obj_count(H5F_OBJ_ALL,H5F_OBJ_GROUP));
|
||||
printf("HDF5 datatype count after close: %d\n",
|
||||
H5Fget_obj_count(H5F_OBJ_ALL,H5F_OBJ_DATATYPE));
|
||||
printf("HDF5 attribute count after close: %d\n",
|
||||
H5Fget_obj_count(H5F_OBJ_ALL,H5F_OBJ_ATTR));
|
||||
*/
|
||||
|
||||
if (iRet < 0) {
|
||||
NXIReportError (NXpData, "ERROR: HDF cannot close HDF file");
|
||||
}
|
||||
@@ -347,6 +376,7 @@
|
||||
}
|
||||
free (pFile);
|
||||
*fid = NULL;
|
||||
H5garbage_collect();
|
||||
return NX_OK;
|
||||
}
|
||||
|
||||
@@ -357,16 +387,17 @@
|
||||
pNexusFile5 pFile;
|
||||
hid_t iRet;
|
||||
hid_t attr1,aid1, aid2;
|
||||
char pBuffer[1024];
|
||||
char pBuffer[1024] = "";
|
||||
|
||||
pFile = NXI5assert (fid);
|
||||
/* create and configure the group */
|
||||
if (pFile->iCurrentG==0)
|
||||
{
|
||||
iRet = H5Gcreate(pFile->iFID,(const char*)name, 0);
|
||||
snprintf(pBuffer,1023,"/%s",name);
|
||||
} else
|
||||
{
|
||||
sprintf(pBuffer,"/%s/%s",pFile->name_ref,name);
|
||||
snprintf(pBuffer,1023,"/%s/%s",pFile->name_ref,name);
|
||||
iRet = H5Gcreate(pFile->iFID,(const char*)pBuffer, 0);
|
||||
}
|
||||
if (iRet < 0) {
|
||||
@@ -374,7 +405,7 @@
|
||||
return NX_ERROR;
|
||||
}
|
||||
pFile->iVID = iRet;
|
||||
strcpy(pFile->name_ref,pBuffer);
|
||||
strncpy(pFile->name_ref,pBuffer,1023);
|
||||
aid2 = H5Screate(H5S_SCALAR);
|
||||
aid1 = H5Tcopy(H5T_C_S1);
|
||||
H5Tset_size(aid1, strlen(nxclass));
|
||||
@@ -829,10 +860,9 @@
|
||||
NXstatus CALLING_STYLE NX5putdata (NXhandle fid, void *data)
|
||||
{
|
||||
pNexusFile5 pFile;
|
||||
NXname pBuffer;
|
||||
hid_t iRet;
|
||||
|
||||
char pError[512];
|
||||
char pError[512] = "";
|
||||
|
||||
pFile = NXI5assert (fid);
|
||||
|
||||
@@ -840,7 +870,7 @@
|
||||
iRet = H5Dwrite (pFile->iCurrentD, pFile->iCurrentT, H5S_ALL, H5S_ALL,
|
||||
H5P_DEFAULT, data);
|
||||
if (iRet < 0) {
|
||||
sprintf (pError, "ERROR: failure to write data to %s", pBuffer);
|
||||
snprintf (pError,511, "ERROR: failure to write data");
|
||||
NXIReportError (NXpData, pError);
|
||||
return NX_ERROR;
|
||||
}
|
||||
@@ -1066,7 +1096,7 @@
|
||||
strcpy(sLink->iTag5,pFile->name_ref);
|
||||
} else {
|
||||
/* group link */
|
||||
strcpy(buffer,pFile->iCurrentLGG);
|
||||
strcpy(buffer, pFile->name_ref);
|
||||
strcat(buffer, sLink->iTag5);
|
||||
strcpy(sLink->iTag5,"/");
|
||||
strcat(sLink->iTag5,buffer);
|
||||
@@ -1082,6 +1112,9 @@
|
||||
strcat(sLink->iTag5,sLink->iRefd);
|
||||
}
|
||||
status = H5Glink(pFile->iFID, H5G_LINK_HARD, sLink->iRef5, sLink->iTag5);
|
||||
if(status < 0){
|
||||
return NX_ERROR;
|
||||
}
|
||||
return NX_OK;
|
||||
}
|
||||
|
||||
@@ -1139,7 +1172,68 @@
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
/* --------------------------------------------------------------------- */
|
||||
|
||||
/* Operator function. */
|
||||
|
||||
herr_t group_info1(hid_t loc_id, const char *name, void *opdata)
|
||||
{
|
||||
NexusFile5 self;
|
||||
H5G_stat_t statbuf;
|
||||
self.iNX = *((int*)opdata);
|
||||
H5Gget_objinfo(loc_id, name, 0, &statbuf);
|
||||
|
||||
switch (statbuf.type)
|
||||
{
|
||||
case H5G_GROUP:
|
||||
self.iNX++;
|
||||
*((int*)opdata)=self.iNX;
|
||||
break;
|
||||
case H5G_DATASET:
|
||||
self.iNX++;
|
||||
*((int*)opdata)=self.iNX;
|
||||
break;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
/*-------------------------------------------------------------------------*/
|
||||
|
||||
NXstatus CALLING_STYLE NX5getgroupinfo (NXhandle fid, int *iN, NXname pName, NXname pClass)
|
||||
{
|
||||
pNexusFile5 pFile;
|
||||
hid_t atype,attr_id;
|
||||
char data[64];
|
||||
int iRet;
|
||||
|
||||
pFile = NXI5assert (fid);
|
||||
/* check if there is a group open */
|
||||
if (pFile->iCurrentG == 0) {
|
||||
strcpy (pName, "root");
|
||||
strcpy (pClass, "NXroot");
|
||||
pFile->iNX=0;
|
||||
iRet=H5Giterate(pFile->iFID,"/",0,group_info1,&pFile->iNX);
|
||||
*iN=pFile->iNX;
|
||||
}
|
||||
else {
|
||||
strcpy (pName,pFile->name_ref);
|
||||
attr_id = H5Aopen_name(pFile->iCurrentG,"NX_class");
|
||||
if (attr_id<0) {
|
||||
strcpy(pClass,"non");
|
||||
} else {
|
||||
atype=H5Tcopy(H5T_C_S1);
|
||||
H5Tset_size(atype,64);
|
||||
H5Aread(attr_id, atype, data);
|
||||
strcpy(pClass,data);
|
||||
pFile->iNX=0;
|
||||
iRet=H5Giterate(pFile->iFID,pFile->name_ref,0,group_info1, &pFile->iNX);
|
||||
*iN=pFile->iNX;
|
||||
H5Aclose(attr_id);
|
||||
}
|
||||
}
|
||||
return NX_OK;
|
||||
}
|
||||
|
||||
/*-------------------------------------------------------------------------*/
|
||||
|
||||
NXstatus CALLING_STYLE NX5getnextentry (NXhandle fid,NXname name, NXname nxclass, int *datatype)
|
||||
@@ -1151,6 +1245,7 @@
|
||||
char data[128];
|
||||
char ph_name[1024];
|
||||
info_type op_data;
|
||||
int iRet_iNX=-1;
|
||||
|
||||
pFile = NXI5assert (fid);
|
||||
op_data.iname = NULL;
|
||||
@@ -1161,6 +1256,18 @@
|
||||
}
|
||||
iRet=H5Giterate(pFile->iFID,pFile->name_ref,&idx,nxgroup_info,&op_data);
|
||||
strcpy(nxclass,"");
|
||||
|
||||
if (pFile->iCurrentG == 0) {
|
||||
pFile->iNX=0;
|
||||
iRet_iNX = H5Giterate(pFile->iFID,"/",0,group_info1,&pFile->iNX);
|
||||
} else {
|
||||
pFile->iNX=0;
|
||||
iRet_iNX = H5Giterate(pFile->iFID,pFile->name_ref,0,group_info1, &pFile->iNX);
|
||||
}
|
||||
if (idx == pFile->iNX) {
|
||||
iRet_iNX = 2;
|
||||
}
|
||||
|
||||
if (iRet > 0)
|
||||
{
|
||||
pFile->iStack5[pFile->iStackPtr].iCurrentIDX++;
|
||||
@@ -1243,25 +1350,25 @@
|
||||
*datatype=iPtype;
|
||||
strcpy(nxclass, "SDS");
|
||||
H5Tclose(atype);
|
||||
H5Tclose(type);
|
||||
H5Dclose(grp);
|
||||
}
|
||||
return NX_OK;
|
||||
}
|
||||
else if (iRet==0)
|
||||
{
|
||||
if (op_data.iname != NULL) {
|
||||
free(op_data.iname);
|
||||
}
|
||||
pFile->iStack5[pFile->iStackPtr].iCurrentIDX = 0;
|
||||
return NX_EOD;
|
||||
}
|
||||
return NX_OK;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (iRet_iNX == 2) {
|
||||
if (op_data.iname != NULL) {
|
||||
free(op_data.iname);
|
||||
}
|
||||
pFile->iStack5[pFile->iStackPtr].iCurrentIDX = 0;
|
||||
return NX_EOD;
|
||||
}
|
||||
if (op_data.iname != NULL) {
|
||||
free(op_data.iname);
|
||||
}
|
||||
NXIReportError (NXpData,
|
||||
"ERROR: Iteration was not successful");
|
||||
"ERROR: Iteration (directory) was not successful");
|
||||
return NX_ERROR;
|
||||
}
|
||||
}
|
||||
@@ -1271,7 +1378,7 @@
|
||||
NXstatus CALLING_STYLE NX5getdata (NXhandle fid, void *data)
|
||||
{
|
||||
pNexusFile5 pFile;
|
||||
int iStart[H5S_MAX_RANK];
|
||||
int iStart[H5S_MAX_RANK], status;
|
||||
hid_t data_id, memtype_id, size_id, sign_id;
|
||||
int dims;
|
||||
|
||||
@@ -1334,7 +1441,18 @@
|
||||
}
|
||||
|
||||
/* actually read */
|
||||
H5Dread (pFile->iCurrentD, memtype_id, H5S_ALL, H5S_ALL,H5P_DEFAULT, data);
|
||||
status = H5Dread (pFile->iCurrentD, memtype_id,
|
||||
H5S_ALL, H5S_ALL,H5P_DEFAULT, data);
|
||||
if(data_id == H5T_STRING)
|
||||
{
|
||||
H5Tclose(memtype_id);
|
||||
}
|
||||
if(status < 0)
|
||||
{
|
||||
NXIReportError (NXpData, "ERROR: failed to transfer dataset");
|
||||
return NX_ERROR;
|
||||
|
||||
}
|
||||
return NX_OK;
|
||||
}
|
||||
|
||||
@@ -1567,16 +1685,42 @@
|
||||
int iPType,rank;
|
||||
char *iname = NULL;
|
||||
unsigned int idx;
|
||||
int intern_idx=-1;
|
||||
|
||||
pFile = NXI5assert (fileid);
|
||||
idx=pFile->iAtt5.iCurrentIDX;
|
||||
iRet=0;
|
||||
if ((pFile->iCurrentD == 0) && (pFile->iCurrentG==0))
|
||||
{
|
||||
/* global attribute */
|
||||
pFile->iVID=H5Gopen(pFile->iFID,"/");
|
||||
iRet=H5Aiterate(pFile->iVID,&idx,attr_info,&iname);
|
||||
intern_idx=H5Aget_num_attrs(pFile->iVID);
|
||||
if (intern_idx > idx) {
|
||||
iRet=H5Aiterate(pFile->iVID,&idx,attr_info,&iname);
|
||||
}
|
||||
else
|
||||
{
|
||||
iRet=0;
|
||||
}
|
||||
intern_idx=-1;
|
||||
if (iRet < 0) {
|
||||
NXIReportError (NXpData, "ERROR iterating through ROOT Attr. list!");
|
||||
return NX_ERROR;
|
||||
}
|
||||
} else {
|
||||
iRet=H5Aiterate(pFile->iCurrentD,&idx,attr_info,&iname);
|
||||
intern_idx=H5Aget_num_attrs(pFile->iCurrentD);
|
||||
if (intern_idx > idx) {
|
||||
iRet=H5Aiterate(pFile->iCurrentD,&idx,attr_info,&iname);
|
||||
}
|
||||
else
|
||||
{
|
||||
iRet=0;
|
||||
}
|
||||
intern_idx=-1;
|
||||
if (iRet < 0) {
|
||||
NXIReportError (NXpData, "ERROR iterating through Attr. list!");
|
||||
return NX_ERROR;
|
||||
}
|
||||
}
|
||||
if (iRet>0)
|
||||
{
|
||||
@@ -1650,31 +1794,28 @@
|
||||
H5Tclose(atype);
|
||||
H5Sclose(aspace);
|
||||
H5Aclose(pFile->iCurrentA);
|
||||
if ((pFile->iCurrentD == 0) && (pFile->iCurrentG==0))
|
||||
{
|
||||
/* close group for global attribute */
|
||||
H5Gclose(pFile->iVID);
|
||||
}
|
||||
return NX_OK;
|
||||
}
|
||||
else if (iRet==0)
|
||||
{
|
||||
if (iname != NULL) {
|
||||
free(iname);
|
||||
}
|
||||
if (idx == 0)
|
||||
{
|
||||
pFile->iAtt5.iCurrentIDX = 0;
|
||||
return NX_EOD;
|
||||
}
|
||||
pFile->iAtt5.iCurrentIDX = 0;
|
||||
return NX_EOD;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (iname != NULL) {
|
||||
free(iname);
|
||||
}
|
||||
if ((pFile->iCurrentD == 0) && (pFile->iCurrentG==0))
|
||||
{
|
||||
/* global attribute */
|
||||
intern_idx=H5Aget_num_attrs(pFile->iVID);
|
||||
} else {
|
||||
if (pFile->iCurrentD>0){
|
||||
intern_idx=H5Aget_num_attrs(pFile->iCurrentD);
|
||||
} else {
|
||||
intern_idx=H5Aget_num_attrs(pFile->iCurrentG);
|
||||
}
|
||||
}
|
||||
if ((intern_idx == 0)||(intern_idx == idx)) {
|
||||
pFile->iAtt5.iCurrentIDX = 0;
|
||||
if (iname != NULL) {
|
||||
free(iname);
|
||||
}
|
||||
return NX_EOD;
|
||||
}
|
||||
NXIReportError (NXpData,
|
||||
"ERROR: Iteration was not successful");
|
||||
return NX_ERROR;
|
||||
@@ -1792,33 +1933,42 @@
|
||||
pNexusFile5 pFile;
|
||||
char *iname = NULL;
|
||||
unsigned int idx;
|
||||
int iRet;
|
||||
herr_t iRet;
|
||||
|
||||
pFile = NXI5assert (fid);
|
||||
idx=0;
|
||||
*iN = idx;
|
||||
if (pFile->iCurrentD == 0 && pFile->iCurrentG == 0) {
|
||||
/*
|
||||
global attribute
|
||||
*/
|
||||
pFile->iVID=H5Gopen(pFile->iFID,"/");
|
||||
iRet = H5Aiterate(pFile->iVID,&idx,attr_info,&iname);
|
||||
iRet = 1;
|
||||
while (iRet != 0) {
|
||||
iRet = H5Aiterate(pFile->iVID,&idx,attr_info,&iname);
|
||||
}
|
||||
if (iRet < 0) {
|
||||
NXIReportError (NXpData, "iterating ERROR!");
|
||||
return NX_ERROR;
|
||||
}
|
||||
idx=H5Aget_num_attrs(pFile->iVID);
|
||||
|
||||
if (idx > 0) {
|
||||
*iN = idx;
|
||||
} else {
|
||||
*iN = 1;
|
||||
}
|
||||
/*
|
||||
if (iname != NULL) {
|
||||
free(iname);
|
||||
}
|
||||
}
|
||||
*/
|
||||
return NX_OK;
|
||||
}
|
||||
else
|
||||
{
|
||||
iRet=H5Aiterate(pFile->iCurrentD,&idx,attr_info,&iname);
|
||||
if (pFile->iCurrentD>0) {
|
||||
iRet=H5Aiterate(pFile->iCurrentD,&idx,attr_info,&iname);
|
||||
} else {
|
||||
iRet=H5Aiterate(pFile->iCurrentG,&idx,attr_info,&iname);
|
||||
}
|
||||
}
|
||||
if (iRet<0) {
|
||||
NXIReportError (NXpData, "Attribute number cannot be fixed!");
|
||||
@@ -1828,84 +1978,17 @@
|
||||
*iN=idx;
|
||||
return NX_OK;
|
||||
}
|
||||
iRet = 1;
|
||||
while (iRet != 0) {
|
||||
iRet = H5Aiterate(pFile->iCurrentD,&idx,attr_info,&iname);
|
||||
}
|
||||
idx=H5Aget_num_attrs(pFile->iCurrentD);
|
||||
if (idx > 0) {
|
||||
*iN = idx;
|
||||
} else {
|
||||
*iN = 1;
|
||||
}
|
||||
if (iname != NULL) {
|
||||
free(iname);
|
||||
}
|
||||
return NX_OK;
|
||||
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------- */
|
||||
|
||||
/* Operator function. */
|
||||
|
||||
herr_t group_info1(hid_t loc_id, const char *name, void *opdata)
|
||||
{
|
||||
NexusFile5 self;
|
||||
H5G_stat_t statbuf;
|
||||
self.iNX = *((int*)opdata);
|
||||
H5Gget_objinfo(loc_id, name, 0, &statbuf);
|
||||
|
||||
switch (statbuf.type)
|
||||
{
|
||||
case H5G_GROUP:
|
||||
self.iNX++;
|
||||
*((int*)opdata)=self.iNX;
|
||||
break;
|
||||
case H5G_DATASET:
|
||||
self.iNX++;
|
||||
*((int*)opdata)=self.iNX;
|
||||
break;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
/*-------------------------------------------------------------------------*/
|
||||
|
||||
NXstatus CALLING_STYLE NX5getgroupinfo (NXhandle fid, int *iN, NXname pName, NXname pClass)
|
||||
{
|
||||
pNexusFile5 pFile;
|
||||
hid_t atype,attr_id;
|
||||
char data[64];
|
||||
int iRet;
|
||||
|
||||
pFile = NXI5assert (fid);
|
||||
/* check if there is a group open */
|
||||
if (pFile->iCurrentG == 0) {
|
||||
strcpy (pName, "root");
|
||||
strcpy (pClass, "NXroot");
|
||||
pFile->iNX=0;
|
||||
iRet=H5Giterate(pFile->iFID,"/",0,group_info1,&pFile->iNX);
|
||||
*iN=pFile->iNX;
|
||||
}
|
||||
else {
|
||||
strcpy (pName,pFile->name_ref);
|
||||
attr_id = H5Aopen_name(pFile->iCurrentG,"NX_class");
|
||||
if (attr_id<0) {
|
||||
strcpy(pClass,"non");
|
||||
} else {
|
||||
atype=H5Tcopy(H5T_C_S1);
|
||||
H5Tset_size(atype,64);
|
||||
H5Aread(attr_id, atype, data);
|
||||
strcpy(pClass,data);
|
||||
pFile->iNX=0;
|
||||
iRet=H5Giterate(pFile->iFID,pFile->name_ref,0,group_info1, &pFile->iNX);
|
||||
*iN=pFile->iNX;
|
||||
H5Aclose(attr_id);
|
||||
}
|
||||
}
|
||||
return NX_OK;
|
||||
}
|
||||
|
||||
/*-------------------------------------------------------------------------*/
|
||||
|
||||
NXstatus CALLING_STYLE NX5getgroupID (NXhandle fileid, NXlink* sRes)
|
||||
|
||||
Reference in New Issue
Block a user