Skip to content

Commit 0929e8b

Browse files
Started to replace int with hid_t
Someone else should continue this! Update #421
1 parent 7561635 commit 0929e8b

1 file changed

Lines changed: 55 additions & 28 deletions

File tree

src/napi5.c

Lines changed: 55 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -59,12 +59,12 @@ typedef struct __NexusFile5 {
5959
hsize_t iCurrentIDX;
6060
} iStack5[NXMAXSTACK];
6161
struct iStack5 iAtt5;
62-
int iFID;
63-
int iCurrentG;
64-
int iCurrentD;
65-
int iCurrentS;
66-
int iCurrentT;
67-
int iCurrentA;
62+
hid_t iFID;
63+
hid_t iCurrentG;
64+
hid_t iCurrentD;
65+
hid_t iCurrentS;
66+
hid_t iCurrentT;
67+
hid_t iCurrentA;
6868
int iNX;
6969
int iNXID;
7070
int iStackPtr;
@@ -275,31 +275,57 @@ NXstatus NX5open(CONSTCHAR * filename, NXaccess am, NXhandle * pHandle)
275275
return NX_ERROR;
276276
}
277277
memset(pNew, 0, sizeof(NexusFile5));
278+
279+
/* create file access property list - required in all cases*/
280+
if((fapl = H5Pcreate(H5P_FILE_ACCESS))<0){
281+
sprintf(pBuffer,"Error: failed to create file access property "
282+
"list for file %s",filename);
283+
NXReportError(pBuffer);
284+
free(pNew);
285+
return NX_ERROR;
286+
}
287+
288+
/* set file close policy - need this in all cases*/
289+
if(H5Pset_fclose_degree(fapl, H5F_CLOSE_STRONG)<0){
290+
sprintf(pBuffer,"Error: cannot set close policy for file "
291+
"%s",filename);
292+
NXReportError(pBuffer);
293+
free(pNew);
294+
return NX_ERROR;
295+
}
278296

279297
/* start HDF5 interface */
280298
if (am == NXACC_CREATE5) {
281-
fapl = H5Pcreate(H5P_FILE_ACCESS);
282-
H5Pget_cache(fapl, &mdc_nelmts, &rdcc_nelmts, &rdcc_nbytes,
283-
&rdcc_w0);
299+
if(H5Pget_cache(fapl, &mdc_nelmts, &rdcc_nelmts, &rdcc_nbytes,
300+
&rdcc_w0) < 0){
301+
sprintf(pBuffer,"Error: cannot obtain HDF5 cache size"
302+
" for file %s",filename);
303+
NXReportError(pBuffer);
304+
free(pNew);
305+
return NX_ERROR;
306+
}
307+
284308
rdcc_nbytes = (size_t) nx_cacheSize;
285-
H5Pset_cache(fapl, mdc_nelmts, rdcc_nelmts, rdcc_nbytes,
286-
rdcc_w0);
287-
H5Pset_fclose_degree(fapl, H5F_CLOSE_STRONG);
309+
if(H5Pset_cache(fapl, mdc_nelmts, rdcc_nelmts, rdcc_nbytes,
310+
rdcc_w0) < 0){
311+
sprintf(pBuffer,"Error: cannot set cache size "
312+
"for file %s",filename);
313+
NXReportError(pBuffer);
314+
free(pNew);
315+
return NX_ERROR;
316+
}
317+
288318
am1 = H5F_ACC_TRUNC;
289319
pNew->iFID = H5Fcreate(filename, am1, H5P_DEFAULT, fapl);
290320
} else {
291-
if (am == NXACC_READ) {
292-
am1 = H5F_ACC_RDONLY;
293-
} else {
294-
am1 = H5F_ACC_RDWR;
295-
}
296-
fapl = H5Pcreate(H5P_FILE_ACCESS);
297-
H5Pset_fclose_degree(fapl, H5F_CLOSE_STRONG);
321+
if (am == NXACC_READ) am1 = H5F_ACC_RDONLY;
322+
else am1 = H5F_ACC_RDWR;
323+
298324
pNew->iFID = H5Fopen(filename, am1, fapl);
299325
}
300-
if (fapl != -1) {
301-
H5Pclose(fapl);
302-
}
326+
327+
if (fapl != -1) H5Pclose(fapl); /*close file access property list*/
328+
303329
if (pNew->iFID <= 0) {
304330
sprintf(pBuffer, "ERROR: cannot open file: %s", filename);
305331
NXReportError(pBuffer);
@@ -477,7 +503,7 @@ NXstatus NX5close(NXhandle * fid)
477503
NXstatus NX5makegroup(NXhandle fid, CONSTCHAR * name, CONSTCHAR * nxclass)
478504
{
479505
pNexusFile5 pFile;
480-
herr_t iRet;
506+
hid_t iRet;
481507
hid_t iVID;
482508
hid_t attr1, aid1, aid2;
483509
char pBuffer[1024] = "";
@@ -535,7 +561,7 @@ NXstatus NX5opengroup(NXhandle fid, CONSTCHAR * name, CONSTCHAR * nxclass)
535561

536562
pNexusFile5 pFile;
537563
hid_t attr1, atype;
538-
herr_t iRet;
564+
hid_t iRet;
539565
char pBuffer[1024];
540566
char data[128];
541567

@@ -712,7 +738,7 @@ NXstatus NX5compmakedata64(NXhandle fid, CONSTCHAR * name,
712738
int compress_type, int64_t chunk_size[])
713739
{
714740
hid_t datatype1, dataspace, iNew;
715-
herr_t iRet;
741+
hid_t iRet;
716742
hid_t type, cparms = -1;
717743
pNexusFile5 pFile;
718744
char pBuffer[256];
@@ -1057,6 +1083,7 @@ NXstatus NX5putattr(NXhandle fid, CONSTCHAR * name, const void *data,
10571083
pNexusFile5 pFile;
10581084
hid_t attr1, aid1, aid2;
10591085
hid_t type;
1086+
hid_t attr_id;
10601087
herr_t iRet;
10611088
int vid;
10621089

@@ -1066,9 +1093,9 @@ NXstatus NX5putattr(NXhandle fid, CONSTCHAR * name, const void *data,
10661093

10671094
/* determine vid */
10681095
vid = getAttVID(pFile);
1069-
iRet = H5Aopen_by_name(vid, ".", name, H5P_DEFAULT, H5P_DEFAULT);
1070-
if (iRet > 0) {
1071-
H5Aclose(iRet);
1096+
attr_id = H5Aopen_by_name(vid, ".", name, H5P_DEFAULT, H5P_DEFAULT);
1097+
if (attr_id > 0) {
1098+
H5Aclose(attr_id);
10721099
iRet = H5Adelete(vid, name);
10731100
if (iRet < 0) {
10741101
NXReportError

0 commit comments

Comments
 (0)