From kde-commits Sun May 31 21:18:21 2015 From: Stefan Gerlach Date: Sun, 31 May 2015 21:18:21 +0000 To: kde-commits Subject: [labplot] src/backend/datasources/filters: HDF filter: improved error handling Message-Id: X-MARC-Message: https://marc.info/?l=kde-commits&m=143310711101475 Git commit 16679b11d7ad17ace9d2c20a3ff8081fbf792763 by Stefan Gerlach. Committed on 31/05/2015 at 21:18. Pushed by sgerlach into branch 'master'. HDF filter: improved error handling M +165 -54 src/backend/datasources/filters/HDFFilter.cpp M +2 -0 src/backend/datasources/filters/HDFFilterPrivate.h http://commits.kde.org/labplot/16679b11d7ad17ace9d2c20a3ff8081fbf792763 diff --git a/src/backend/datasources/filters/HDFFilter.cpp b/src/backend/da= tasources/filters/HDFFilter.cpp index f142a3f..bfb2fdc 100644 --- a/src/backend/datasources/filters/HDFFilter.cpp +++ b/src/backend/datasources/filters/HDFFilter.cpp @@ -153,6 +153,12 @@ HDFFilterPrivate::HDFFilterPrivate(HDFFilter* owner) : } = #ifdef HAVE_HDF5 +void HDFFilterPrivate::handleError(int status, QString function, QString a= rg) { + if (status < 0) { + qDebug()<<"ERROR"<operator[](i-startRow+1) =3D data[i]; @@ -303,13 +315,18 @@ QStringList HDFFilterPrivate::readHDFData1D(hid_t dat= aset, hid_t type, int rows, = QStringList HDFFilterPrivate::readHDFCompoundData1D(hid_t dataset, hid_t t= id, int rows, int lines, QVector< QVector* >& dataPointer) { int members =3D H5Tget_nmembers(tid); + handleError(members,"H5Tget_nmembers"); = QStringList data[members]; for(int m=3D0;m* dataP=3DNULL; if(dataPointer.size()>0) @@ -343,6 +360,7 @@ QStringList HDFFilterPrivate::readHDFCompoundData1D(hid= _t dataset, hid_t tid, in data[m]=3DreadHDFData1D(dataset,ctype,rows,lines,dataP); else { H5T_class_t mclass =3D H5Tget_member_class(tid,m); + handleError((int)mclass,"H5Tget_member_class"); qDebug()<<" not supported type of class"<* > dummy; if(H5Tequal(mtype,H5T_STD_I8LE) || H5Tequal(mtype,H5T_STD_I8BE)) @@ -439,7 +463,8 @@ QStringList HDFFilterPrivate::readHDFCompoundData2D(hid= _t dataset, hid_t tid, in qDebug()<<" not supported class"<setIcon(0,QIcon(KIcon("accessories-calculator"))); @@ -733,27 +794,34 @@ void HDFFilterPrivate::scanHDFDataSet(hid_t did, char= *dataSetName, QTreeWidgetI QString attr =3D scanHDFAttrs(did).join(""); = char link[MAXNAMELENGTH]; - H5Iget_name(did, link, MAXNAMELENGTH); + status =3D H5Iget_name(did, link, MAXNAMELENGTH); + handleError(status,"H5Iget_name"); = QStringList dataSetProps; hsize_t size =3D H5Dget_storage_size(did); + handleError((int)size,"H5Dget_storage_size"); hid_t datatype =3D H5Dget_type(did); + handleError((int)datatype,"H5Dget_type"); size_t typeSize =3D H5Tget_size(datatype); + handleError((int)typeSize,"H5Dget_size"); = dataSetProps<setIcon(0,QIcon(KIcon("emblem-symbolic-link"))); @@ -781,8 +851,9 @@ void HDFFilterPrivate::scanHDFLink(hid_t gid, char *lin= kName, QTreeWidgetItem* p void HDFFilterPrivate::scanHDFGroup(hid_t gid, char *groupName, QTreeWidge= tItem* parentItem) { = //check for hard link - H5G_stat_t statbuf; - H5Gget_objinfo(gid, ".", TRUE, &statbuf); + H5G_stat_t statbuf; + status =3D H5Gget_objinfo(gid, ".", TRUE, &statbuf); + handleError(status,"H5Gget_objinfo"); if (statbuf.nlink > 1) { if(multiLinkList.contains(statbuf.objno[0])) { QTreeWidgetItem *objectItem =3D new QTreeWidgetItem((QTreeWidget*)0, QS= tringList()<addChild(groupItem); = hsize_t numObj; - H5Gget_num_objs(gid, &numObj); + status =3D H5Gget_num_objs(gid, &numObj); + handleError(status,"H5Gget_num_objs"); = for (unsigned int i =3D 0; i < numObj; i++) { char memberName[MAXNAMELENGTH]; - H5Gget_objname_by_idx(gid, (hsize_t)i, memberName, (size_t= )MAXNAMELENGTH ); + status =3D H5Gget_objname_by_idx(gid, (hsize_t)i, memberNa= me, (size_t)MAXNAMELENGTH ); + handleError(status,"H5Gget_objname_by_idx"); = int otype =3D H5Gget_objtype_by_idx(gid, (size_t)i ); + handleError(otype,"H5Gget_objtype_by_idx"); switch(otype) { case H5G_LINK: { scanHDFLink(gid,memberName, groupItem); @@ -819,20 +894,26 @@ void HDFFilterPrivate::scanHDFGroup(hid_t gid, char *= groupName, QTreeWidgetItem* } case H5G_GROUP: { hid_t grpid =3D H5Gopen(gid,memberName, H5P_DEFAUL= T); + handleError((int)grpid,"H5Gopen"); scanHDFGroup(grpid, memberName, groupItem); - H5Gclose(grpid); + status =3D H5Gclose(grpid); + handleError(status,"H5Gclose"); break; } case H5G_DATASET: { hid_t dsid =3D H5Dopen(gid,memberName, H5P_DEFAULT= ); + handleError((int)dsid,"H5Dopen"); scanHDFDataSet(dsid, memberName, groupItem); - H5Dclose(dsid); + status =3D H5Dclose(dsid); + handleError(status,"H5Dclose"); break; } case H5G_TYPE: { hid_t tid =3D H5Topen(gid,memberName, H5P_DEFAULT); + handleError((int)tid,"H5Topen"); scanHDFDataType(tid, memberName, groupItem); - H5Tclose(tid); + status =3D H5Tclose(tid); + handleError(status,"H5Tclose"); break; } default: @@ -849,14 +930,20 @@ void HDFFilterPrivate::scanHDFGroup(hid_t gid, char *= groupName, QTreeWidgetItem* */ void HDFFilterPrivate::parse(const QString & fileName, QTreeWidgetItem* ro= otItem) { #ifdef HAVE_HDF5 + int status; + QByteArray bafileName =3D fileName.toLatin1(); hid_t file =3D H5Fopen(bafileName.data(), H5F_ACC_RDONLY, H5P_DEFAULT); + handleError((int)file,"H5Fopen",fileName); char rootName[]=3D"/"; hid_t group =3D H5Gopen(file, rootName, H5P_DEFAULT); + handleError((int)group,"H5Gopen",rootName); multiLinkList.clear(); scanHDFGroup(group,rootName, rootItem); - H5Gclose(group); - H5Fclose(file); + status =3D H5Gclose(group); + handleError(status,"H5Gclose",""); + status =3D H5Fclose(file); + handleError(status,"H5Fclose",""); #else Q_UNUSED(fileName) Q_UNUSED(rootItem) @@ -867,6 +954,7 @@ void HDFFilterPrivate::parse(const QString & fileName, = QTreeWidgetItem* rootItem reads the content of the date set in the file \c fileName to a string = (for preview) or to the data source. */ QString HDFFilterPrivate::readCurrentDataSet(const QString & fileName, Abs= tractDataSource* dataSource, AbstractFileFilter::ImportMode mode, int lines= ){ + int status; QStringList dataString; = if(currentDataSet.isEmpty()) @@ -878,16 +966,23 @@ QString HDFFilterPrivate::readCurrentDataSet(const QS= tring & fileName, AbstractD #ifdef HAVE_HDF5 QByteArray bafileName =3D fileName.toLatin1(); hid_t file =3D H5Fopen(bafileName.data(), H5F_ACC_RDONLY, H5P_DEFAULT); + handleError((int)file,"H5Fopen",fileName); QByteArray badataSet =3D currentDataSet.toLatin1(); hid_t dataset =3D H5Dopen2(file, badataSet.data(), H5P_DEFAULT); + handleError((int)file,"H5Dopen2",currentDataSet); = // Get datatype and dataspace hid_t dtype =3D H5Dget_type(dataset); + handleError((int)dtype,"H5Dget_type"); H5T_class_t dclass =3D H5Tget_class(dtype); + handleError((int)dclass,"H5Dget_class"); size_t typeSize =3D H5Tget_size(dtype); + handleError((int)(typeSize-1),"H5Dget_size"); = hid_t dataspace =3D H5Dget_space(dataset); + handleError((int)dataspace,"H5Dget_space"); int rank =3D H5Sget_simple_extent_ndims(dataspace); + handleError(rank,"H5Dget_simple_extent_ndims"); = int columnOffset =3D 0; // offset to import data int actualRows=3D0, actualCols=3D0; // rows and cols to read @@ -902,9 +997,12 @@ QString HDFFilterPrivate::readCurrentDataSet(const QSt= ring & fileName, AbstractD case H5T_STRING: { char* data =3D (char *) malloc(typeSize * sizeof (char)); hid_t memtype =3D H5Tcopy(H5T_C_S1); - H5Tset_size(memtype, typeSize); + handleError((int)memtype,"H5Tcopy"); + status =3D H5Tset_size(memtype, typeSize); + handleError(status,"H5Tset_size"); = - H5Dread(dataset, memtype, H5S_ALL, H5S_ALL, H5P_DEFAULT, data); + status =3D H5Dread(dataset, memtype, H5S_ALL, H5S_ALL, H5P_DEFAULT, dat= a); + handleError(status,"H5Tread"); dataString<create(dataPointers, mode, actualRows, members); @@ -1010,15 +1114,17 @@ QString HDFFilterPrivate::readCurrentDataSet(const = QString & fileName, AbstractD dataString<inherits("Spreadsheet")) { diff --git a/src/backend/datasources/filters/HDFFilterPrivate.h b/src/backe= nd/datasources/filters/HDFFilterPrivate.h index 3ab5113..d930ca8 100644 --- a/src/backend/datasources/filters/HDFFilterPrivate.h +++ b/src/backend/datasources/filters/HDFFilterPrivate.h @@ -57,6 +57,8 @@ class HDFFilterPrivate { const static int MAXNAMELENGTH=3D1024; QList multiLinkList; // used to find hard links #ifdef HAVE_HDF5 + int status; + void handleError(int status, QString function, QString arg=3DQString()); QString translateHDFOrder(H5T_order_t); QString translateHDFType(hid_t); QString translateHDFClass(H5T_class_t);