Skip to content

Commit eba5c71

Browse files
Pedro VicentePedro.vicente
Pedro Vicente
authored and
Pedro.vicente
committed
refs nexusformat#205 updated VS project refs nexusformat#211 added herr_t instead of int
git-svn-id: https://svn.nexusformat.org/code/trunk@1448 ff5d1e40-2be0-497f-93bd-dc18237bd3c7
1 parent a78de6a commit eba5c71

File tree

2 files changed

+181
-154
lines changed

2 files changed

+181
-154
lines changed

src/napi5.c

+179-152
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ static void buildCurrentPath(pNexusFile5 self, char *pathBuffer,
125125
char pBuffer[512];
126126
char *time_buffer = NULL;
127127
char version_nr[10];
128-
int iRet;
128+
herr_t iRet;
129129
unsigned int vers_major, vers_minor, vers_release, am1 ;
130130
hid_t fapl = -1;
131131
int mdc_nelmts;
@@ -315,7 +315,7 @@ static void buildCurrentPath(pNexusFile5 self, char *pathBuffer,
315315
NXstatus NX5close (NXhandle* fid)
316316
{
317317
pNexusFile5 pFile = NULL;
318-
int iRet;
318+
herr_t iRet;
319319

320320
pFile=NXI5assert(*fid);
321321

@@ -362,7 +362,8 @@ static void buildCurrentPath(pNexusFile5 self, char *pathBuffer,
362362
NXstatus NX5makegroup (NXhandle fid, CONSTCHAR *name, CONSTCHAR *nxclass)
363363
{
364364
pNexusFile5 pFile;
365-
hid_t iRet, iVID;
365+
herr_t iRet;
366+
hid_t iVID;
366367
hid_t attr1,aid1, aid2;
367368
char pBuffer[1024] = "";
368369

@@ -418,7 +419,8 @@ static void buildCurrentPath(pNexusFile5 self, char *pathBuffer,
418419
{
419420

420421
pNexusFile5 pFile;
421-
hid_t iRet, attr1, atype;
422+
hid_t attr1, atype;
423+
herr_t iRet;
422424
char pBuffer[1024];
423425
char data[128];
424426

@@ -610,160 +612,183 @@ static hid_t nxToHDF5Type(int datatype)
610612
int rank, int dimensions[],
611613
int compress_type, int chunk_size[])
612614
{
613-
hid_t datatype1, dataspace, iNew, iRet;
614-
hid_t type, cparms = -1;
615-
pNexusFile5 pFile;
616-
char pBuffer[256];
617-
int i, byte_zahl = 0;
618-
hsize_t chunkdims[H5S_MAX_RANK];
619-
hsize_t mydim[H5S_MAX_RANK], mydim1[H5S_MAX_RANK];
620-
hsize_t size[H5S_MAX_RANK];
621-
hsize_t maxdims[H5S_MAX_RANK];
622-
int compress_level;
623-
624-
pFile = NXI5assert (fid);
625-
626-
for (i = 0; i < rank; i++)
627-
{
628-
chunkdims[i]=chunk_size[i];
629-
mydim[i] = dimensions[i];
630-
maxdims[i] = dimensions[i];
631-
size[i] = dimensions[i];
632-
}
615+
hid_t datatype1, dataspace, iNew;
616+
herr_t iRet;
617+
hid_t type, cparms = -1;
618+
pNexusFile5 pFile;
619+
char pBuffer[256];
620+
int i, byte_zahl = 0;
621+
hsize_t chunkdims[H5S_MAX_RANK];
622+
hsize_t mydim[H5S_MAX_RANK], mydim1[H5S_MAX_RANK];
623+
hsize_t size[H5S_MAX_RANK];
624+
hsize_t maxdims[H5S_MAX_RANK];
625+
int compress_level;
626+
627+
pFile = NXI5assert (fid);
628+
629+
for (i = 0; i < rank; i++)
630+
{
631+
chunkdims[i]=chunk_size[i];
632+
mydim[i] = dimensions[i];
633+
maxdims[i] = dimensions[i];
634+
size[i] = dimensions[i];
635+
}
633636

634-
type = nxToHDF5Type(datatype);
637+
type = nxToHDF5Type(datatype);
635638

636-
if (rank <= 0) {
637-
sprintf (pBuffer, "ERROR: invalid rank specified %s",
638-
name);
639-
NXIReportError (NXpData, pBuffer);
640-
return NX_ERROR;
641-
}
642-
/*
639+
if (rank <= 0)
640+
{
641+
sprintf (pBuffer, "ERROR: invalid rank specified %s",
642+
name);
643+
NXIReportError (NXpData, pBuffer);
644+
return NX_ERROR;
645+
}
646+
/*
643647
Check dimensions for consistency. The first dimension may be -1
644648
thus denoting an unlimited dimension.
645-
*/
646-
for (i = 1; i < rank; i++) {
647-
if (dimensions[i] <= 0) {
648-
sprintf (pBuffer,
649-
"ERROR: invalid dimension %d, value %d given for Dataset %s",
650-
i, dimensions[i], name);
651-
NXIReportError (NXpData, pBuffer);
652-
return NX_ERROR;
649+
*/
650+
for (i = 1; i < rank; i++)
651+
{
652+
if (dimensions[i] <= 0)
653+
{
654+
sprintf (pBuffer,
655+
"ERROR: invalid dimension %d, value %d given for Dataset %s",
656+
i, dimensions[i], name);
657+
NXIReportError (NXpData, pBuffer);
658+
return NX_ERROR;
659+
}
660+
}
661+
if (datatype == NX_CHAR)
662+
{
663+
/*
664+
* This assumes string lenght is in the last dimensions and
665+
* the logic must be the same as used in NX5getslab and NX5getinfo
666+
*
667+
* search for tests on H5T_STRING
668+
*/
669+
byte_zahl=dimensions[rank-1];
670+
for(i = 0; i < rank; i++)
671+
{
672+
mydim1[i] = dimensions[i];
673+
}
674+
mydim1[rank-1] = 1;
675+
if (dimensions[rank-1] > 1)
676+
{
677+
mydim[rank-1] = maxdims[rank-1] = size[rank-1] = 1;
678+
}
679+
if (chunkdims[rank-1] > 1)
680+
{
681+
chunkdims[rank-1] = 1;
682+
}
683+
if (dimensions[0] == NX_UNLIMITED)
684+
{
685+
mydim1[0] = 1;
686+
maxdims[0] = H5S_UNLIMITED;
687+
}
688+
dataspace=H5Screate_simple(rank,mydim1,maxdims);
689+
}
690+
else
691+
{
692+
if (dimensions[0] == NX_UNLIMITED)
693+
{
694+
mydim[0] = 1;
695+
maxdims[0] = H5S_UNLIMITED;
696+
dataspace=H5Screate_simple(rank, mydim, maxdims);
697+
}
698+
else
699+
{
700+
/* dataset creation */
701+
dataspace=H5Screate_simple(rank, mydim, NULL);
702+
}
703+
}
704+
datatype1=H5Tcopy(type);
705+
if (datatype == NX_CHAR)
706+
{
707+
H5Tset_size(datatype1, byte_zahl);
708+
/* H5Tset_strpad(H5T_STR_SPACEPAD); */
709+
}
710+
compress_level = 6;
711+
if ( (compress_type / 100) == NX_COMP_LZW )
712+
{
713+
compress_level = compress_type % 100;
714+
compress_type = NX_COMP_LZW;
715+
}
716+
if(compress_type == NX_COMP_LZW)
717+
{
718+
cparms = H5Pcreate(H5P_DATASET_CREATE);
719+
iNew = H5Pset_chunk(cparms,rank,chunkdims);
720+
if (iNew < 0)
721+
{
722+
NXIReportError (NXpData, "ERROR: Size of chunks could not be set!");
723+
return NX_ERROR;
724+
}
725+
H5Pset_deflate(cparms,compress_level);
726+
iRet = H5Dcreate (pFile->iCurrentG, (char*)name, datatype1,
727+
dataspace, cparms);
728+
}
729+
else if (compress_type == NX_COMP_NONE)
730+
{
731+
if (dimensions[0] == NX_UNLIMITED)
732+
{
733+
cparms = H5Pcreate(H5P_DATASET_CREATE);
734+
iNew = H5Pset_chunk(cparms,rank,chunkdims);
735+
if (iNew < 0)
736+
{
737+
NXIReportError (NXpData,
738+
"ERROR: Size of chunks could not be set!");
739+
return NX_ERROR;
740+
}
741+
iRet = H5Dcreate (pFile->iCurrentG, (char*)name, datatype1,
742+
dataspace, cparms);
743+
}
744+
else
745+
{
746+
iRet = H5Dcreate (pFile->iCurrentG, (char*)name, datatype1,
747+
dataspace, H5P_DEFAULT);
748+
}
749+
}
750+
else
751+
{
752+
NXIReportError (NXpData,
753+
"HDF5 doesn't support selected compression method! Dataset was saved without compression");
754+
iRet = H5Dcreate (pFile->iCurrentG, (char*)name, datatype1,
755+
dataspace, H5P_DEFAULT);
756+
}
757+
if (iRet < 0)
758+
{
759+
NXIReportError (NXpData, "ERROR: Creating chunked dataset failed!");
760+
return NX_ERROR;
761+
}
762+
else
763+
{
764+
pFile->iCurrentD = iRet;
653765
}
654-
}
655-
if (datatype == NX_CHAR)
656-
{
657-
/*
658-
* This assumes string lenght is in the last dimensions and
659-
* the logic must be the same as used in NX5getslab and NX5getinfo
660-
*
661-
* search for tests on H5T_STRING
662-
*/
663-
byte_zahl=dimensions[rank-1];
664-
for(i = 0; i < rank; i++)
665-
{
666-
mydim1[i] = dimensions[i];
667-
}
668-
mydim1[rank-1] = 1;
669-
if (dimensions[rank-1] > 1)
670-
{
671-
mydim[rank-1] = maxdims[rank-1] = size[rank-1] = 1;
672-
}
673-
if (chunkdims[rank-1] > 1)
674-
{
675-
chunkdims[rank-1] = 1;
676-
}
677-
if (dimensions[0] == NX_UNLIMITED)
678-
{
679-
mydim1[0] = 1;
680-
maxdims[0] = H5S_UNLIMITED;
681-
}
682-
dataspace=H5Screate_simple(rank,mydim1,maxdims);
683-
} else {
684766
if (dimensions[0] == NX_UNLIMITED)
767+
{
768+
size[0] = 1;
769+
iNew = H5Dextend (pFile->iCurrentD, size);
770+
if (iNew < 0)
771+
{
772+
sprintf (pBuffer, "ERROR: cannot create Dataset %s, check arguments",
773+
name);
774+
NXIReportError (NXpData, pBuffer);
775+
return NX_ERROR;
776+
}
777+
}
778+
if (cparms != -1)
685779
{
686-
mydim[0] = 1;
687-
maxdims[0] = H5S_UNLIMITED;
688-
dataspace=H5Screate_simple(rank, mydim, maxdims);
689-
} else {
690-
/* dataset creation */
691-
dataspace=H5Screate_simple(rank, mydim, NULL);
692-
}
693-
}
694-
datatype1=H5Tcopy(type);
695-
if (datatype == NX_CHAR)
696-
{
697-
H5Tset_size(datatype1, byte_zahl);
698-
/* H5Tset_strpad(H5T_STR_SPACEPAD); */
699-
}
700-
compress_level = 6;
701-
if ( (compress_type / 100) == NX_COMP_LZW )
702-
{
703-
compress_level = compress_type % 100;
704-
compress_type = NX_COMP_LZW;
705-
}
706-
if(compress_type == NX_COMP_LZW)
707-
{
708-
cparms = H5Pcreate(H5P_DATASET_CREATE);
709-
iNew = H5Pset_chunk(cparms,rank,chunkdims);
710-
if (iNew < 0) {
711-
NXIReportError (NXpData, "ERROR: Size of chunks could not be set!");
712-
return NX_ERROR;
780+
iRet = H5Pclose(cparms);
713781
}
714-
H5Pset_deflate(cparms,compress_level);
715-
iRet = H5Dcreate (pFile->iCurrentG, (char*)name, datatype1,
716-
dataspace, cparms);
717-
} else if (compress_type == NX_COMP_NONE) {
718-
if (dimensions[0] == NX_UNLIMITED) {
719-
cparms = H5Pcreate(H5P_DATASET_CREATE);
720-
iNew = H5Pset_chunk(cparms,rank,chunkdims);
721-
if (iNew < 0) {
722-
NXIReportError (NXpData,
723-
"ERROR: Size of chunks could not be set!");
724-
return NX_ERROR;
725-
}
726-
iRet = H5Dcreate (pFile->iCurrentG, (char*)name, datatype1,
727-
dataspace, cparms);
728-
} else {
729-
iRet = H5Dcreate (pFile->iCurrentG, (char*)name, datatype1,
730-
dataspace, H5P_DEFAULT);
731-
}
732-
} else {
733-
NXIReportError (NXpData,
734-
"HDF5 doesn't support selected compression method! Dataset was saved without compression");
735-
iRet = H5Dcreate (pFile->iCurrentG, (char*)name, datatype1,
736-
dataspace, H5P_DEFAULT);
737-
}
738-
if (iRet < 0) {
739-
NXIReportError (NXpData, "ERROR: Creating chunked dataset failed!");
740-
return NX_ERROR;
741-
} else {
742-
pFile->iCurrentD = iRet;
743-
}
744-
if (dimensions[0] == NX_UNLIMITED)
745-
{
746-
size[0] = 1;
747-
iNew = H5Dextend (pFile->iCurrentD, size);
748-
if (iNew < 0) {
749-
sprintf (pBuffer, "ERROR: cannot create Dataset %s, check arguments",
750-
name);
751-
NXIReportError (NXpData, pBuffer);
752-
return NX_ERROR;
782+
iRet = H5Sclose(dataspace);
783+
iRet = H5Tclose(datatype1);
784+
iRet = H5Dclose(pFile->iCurrentD);
785+
pFile->iCurrentD = 0;
786+
if (iRet < 0)
787+
{
788+
NXIReportError (NXpData, "ERROR: HDF cannot close Dataset");
789+
return NX_ERROR;
753790
}
754-
}
755-
if (cparms != -1) {
756-
iRet = H5Pclose(cparms);
757-
}
758-
iRet = H5Sclose(dataspace);
759-
iRet = H5Tclose(datatype1);
760-
iRet = H5Dclose(pFile->iCurrentD);
761-
pFile->iCurrentD = 0;
762-
if (iRet < 0) {
763-
NXIReportError (NXpData, "ERROR: HDF cannot close Dataset");
764-
return NX_ERROR;
765-
}
766-
return NX_OK;
791+
return NX_OK;
767792
}
768793

769794

@@ -843,7 +868,7 @@ static hid_t nxToHDF5Type(int datatype)
843868
NXstatus NX5closedata (NXhandle fid)
844869
{
845870
pNexusFile5 pFile;
846-
int iRet;
871+
herr_t iRet;
847872

848873
pFile = NXI5assert (fid);
849874
iRet = H5Sclose(pFile->iCurrentS);
@@ -1866,7 +1891,8 @@ static int countObjectsInGroup(hid_t loc_id)
18661891
{
18671892
pNexusFile5 pFile;
18681893
hid_t attr_id;
1869-
hid_t iRet, atype, aspace;
1894+
hid_t atype, aspace;
1895+
herr_t iRet;
18701896
int iPType,rank;
18711897
char *iname = NULL;
18721898
unsigned int idx;
@@ -1943,7 +1969,8 @@ static int countObjectsInGroup(hid_t loc_id)
19431969
void *data, int* datalen, int* iType)
19441970
{
19451971
pNexusFile5 pFile;
1946-
int iNew, iRet, vid, asize;
1972+
int iNew, vid, asize;
1973+
herr_t iRet;
19471974
hid_t type, atype = -1, glob;
19481975
char pBuffer[256];
19491976

0 commit comments

Comments
 (0)