- TDC histogram memory driver sort of working

- New class for scripting datafiles
- SANS-II almost complete initialization file
This commit is contained in:
cvs
2003-02-07 15:20:19 +00:00
parent f51588e2a7
commit ac10723d74
25 changed files with 2965 additions and 1711 deletions

351
napi5.c
View File

@@ -1,3 +1,27 @@
/*---------------------------------------------------------------------------
NeXus - Neutron & X-ray Common Data Format
Application Program Interface (HDF5) Routines
Copyright (C) 1997-2002 Mark Koennecke, Przemek Klosowski
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
For further information, see <http://www.neutron.anl.gov/NeXus/>
----------------------------------------------------------------------------*/
#include <stdlib.h>
#include <assert.h>
#include <string.h>
@@ -9,17 +33,15 @@
int *iTagDir;
char irefn[1024];
int iVref;
int iCurrentIDX;
} iStack5[NXMAXSTACK];
struct iStack5 iAtt5;
int iVID;
int iFID;
int fapl;
int iCurrentG;
int iCurrentD;
int iCurrentS;
int iCurrentT;
int iCurrentIDX;
unsigned int iCurrentA_IDX;
int iCurrentA;
int iNX;
int iNXID;
@@ -56,6 +78,7 @@
free (self->iStack5[self->iStackPtr].iTagDir);
self->iStack5[self->iStackPtr].iTagDir = NULL;
}
self->iStack5[self->iStackPtr].iCurrentIDX = 0;
}
/*--------------------------------------------------------------------*/
@@ -70,6 +93,7 @@
free (self->iAtt5.iTagDir);
self->iAtt5.iTagDir = NULL;
}
self->iAtt5.iCurrentIDX = 0;
}
/* ----------------------------------------------------------------------
@@ -78,7 +102,7 @@
---------------------------------------------------------------------*/
NXstatus NX5open(CONSTCHAR *filename, NXaccess am, NXhandle* pHandle)
NXstatus CALLING_STYLE NX5open(CONSTCHAR *filename, NXaccess am, NXhandle* pHandle)
{
hid_t attr1,aid1, aid2;
pNexusFile5 pNew = NULL;
@@ -90,6 +114,7 @@
const char* time_format;
long gmt_offset;
unsigned int vers_major, vers_minor, vers_release, am1 ;
hid_t fapl;
int mdc_nelmts, rdcc_nelmts;
size_t rdcc_nbytes;
double rdcc_w0;
@@ -126,7 +151,7 @@
time_info = gmtime(&timer);
if (time_info != NULL)
{
gmt_offset = difftime(timer, mktime(time_info));
gmt_offset = (long)difftime(timer, mktime(time_info));
}
else
{
@@ -163,12 +188,12 @@
}
/* start HDF5 interface */
if (am == NXACC_CREATE5) {
pNew->fapl = H5Pcreate(H5P_FILE_ACCESS);
iRet=H5Pget_cache(pNew->fapl,&mdc_nelmts,&rdcc_nelmts,&rdcc_nbytes,&rdcc_w0);
fapl = H5Pcreate(H5P_FILE_ACCESS);
iRet=H5Pget_cache(fapl,&mdc_nelmts,&rdcc_nelmts,&rdcc_nbytes,&rdcc_w0);
rdcc_nbytes=(size_t)cacheSize;
iRet = H5Pset_cache(pNew->fapl,mdc_nelmts,rdcc_nelmts,rdcc_nbytes,rdcc_w0);
iRet = H5Pset_cache(fapl,mdc_nelmts,rdcc_nelmts,rdcc_nbytes,rdcc_w0);
am1 = H5F_ACC_TRUNC;
pNew->iFID = H5Fcreate (filename, am1, H5P_DEFAULT, pNew->fapl);
pNew->iFID = H5Fcreate (filename, am1, H5P_DEFAULT, fapl);
} else {
if (am == NXACC_READ) {
am1 = H5F_ACC_RDONLY;
@@ -289,14 +314,8 @@
pNexusFile5 pFile = NULL;
int iRet;
pFile = NXI5assert(*fid);
if (pFile->fapl != NULL) {
iRet = H5Pclose(pFile->fapl);
if (iRet < 0) {
NXIReportError (NXpData, "ERROR: HDF cannot close plist.");
}
}
iRet = 0;
pFile=NXI5assert(*fid);
iRet=0;
iRet = H5Fclose(pFile->iFID);
if (iRet < 0) {
NXIReportError (NXpData, "ERROR: HDF cannot close HDF file");
@@ -305,11 +324,6 @@
NXI5KillDir (pFile);
free (pFile);
*fid = NULL;
iRet = 0;
iRet = H5close();
if (iRet < 0) {
NXIReportError (NXpData, "ERROR: HDF cannot close HDF library");
}
return NX_OK;
}
@@ -364,7 +378,7 @@
herr_t attr_check (hid_t loc_id, const char *member_name, void *opdata)
{
char attr_name[8];
char attr_name[8+1]; /* need to leave space for \0 as well */
strcpy(attr_name,"NX_class");
return strstr(member_name, attr_name) ? 1 : 0;
@@ -391,7 +405,7 @@
/* check group attribute */
iRet = H5Aiterate(pFile->iCurrentG,NULL,attr_check,NULL);
if (iRet < 0) {
NXIReportError (NXpData, "ERROR iterating thourgh group!");
NXIReportError (NXpData, "ERROR iterating through group!");
return NX_ERROR;
} else if (iRet == 1) {
/* group attribute was found */
@@ -400,7 +414,7 @@
NXIReportError (NXpData, "No group attribute available");
return NX_ERROR;
}
/* check contains of group attribute */
/* check contents of group attribute */
attr1 = H5Aopen_name(pFile->iCurrentG, "NX_class");
atype=H5Tcopy(H5T_C_S1);
H5Tset_size(atype,128);
@@ -433,7 +447,7 @@
/* check group attribute */
iRet=H5Aiterate(pFile->iCurrentG,NULL,attr_check,NULL);
if (iRet < 0) {
NXIReportError (NXpData, "ERROR iterating thourgh group!");
NXIReportError (NXpData, "ERROR iterating through group!");
return NX_ERROR;
} else if (iRet == 1) {
/* group attribute was found */
@@ -461,8 +475,7 @@
pFile->iStackPtr++;
pFile->iStack5[pFile->iStackPtr].iVref=pFile->iCurrentG;
strcpy(pFile->iStack5[pFile->iStackPtr].irefn,name);
pFile->iCurrentIDX=0;
pFile->iCurrentA_IDX=0;
pFile->iAtt5.iCurrentIDX=0;
pFile->iCurrentLGG = strdup(name);
NXI5KillDir (pFile);
return NX_OK;
@@ -502,7 +515,7 @@
for (i=0; i<ii; i++) {
*(u1name + i) = *(uname + i);
}
*(u1name + i) = NULL;
*(u1name + i) = '\0';
/*
strncpy(u1name, uname, ii);
*/
@@ -514,42 +527,17 @@
strcpy(pFile->name_ref,"");
strcpy(pFile->name_tmp,"");
}
NXI5KillDir (pFile);
pFile->iStackPtr--;
if (pFile->iStackPtr>0) {
pFile->iCurrentG=pFile->iStack5[pFile->iStackPtr].iVref;
} else {
pFile->iCurrentG=0;
}
NXI5KillDir (pFile);
}
pFile->iCurrentIDX=0;
pFile->iCurrentA_IDX=0;
return NX_OK;
}
/* --------------------------------------------------------------------- */
NXstatus CALLING_STYLE NX5makedata (NXhandle fid, CONSTCHAR *name, int datatype,
int rank, int dimensions[])
{
pNexusFile5 pFile;
int chunk_size[H5S_MAX_RANK];
int i;
pFile = NXI5assert (fid);
memset(chunk_size,0,H5S_MAX_RANK*sizeof(int));
if (dimensions[0] == NX_UNLIMITED)
{
for (i = 0; i < H5S_MAX_RANK; i++)
{
chunk_size[i]= 1;
}
}
return NX5compmakedata (fid, name, datatype, rank, dimensions, NX_COMP_NONE, chunk_size);
return NX_OK;
}
/* --------------------------------------------------------------------- */
NXstatus CALLING_STYLE NX5compmakedata (NXhandle fid, CONSTCHAR *name, int datatype,
@@ -659,7 +647,7 @@
cparms = H5Pcreate(H5P_DATASET_CREATE);
iNew = H5Pset_chunk(cparms,rank,chunkdims);
if (iNew < 0) {
NXIReportError (NXpData, "ERROR: Size of chuncks could not be set!");
NXIReportError (NXpData, "ERROR: Size of chunks could not be set!");
return NX_ERROR;
}
H5Pset_deflate(cparms,6);
@@ -669,7 +657,7 @@
cparms = H5Pcreate(H5P_DATASET_CREATE);
iNew = H5Pset_chunk(cparms,rank,chunkdims);
if (iNew < 0) {
NXIReportError (NXpData, "ERROR: Size1 of chuncks could not be set!");
NXIReportError (NXpData, "ERROR: Size of chunks could not be set!");
return NX_ERROR;
}
iRet = H5Dcreate (pFile->iCurrentG, (char*)name, datatype1, dataspace, cparms);
@@ -677,11 +665,11 @@
iRet = H5Dcreate (pFile->iCurrentG, (char*)name, datatype1, dataspace, H5P_DEFAULT);
}
} else {
NXIReportError (NXpData, "HDF5 don't support selected compression method! Dataset was saved without compression");
NXIReportError (NXpData, "HDF5 doesn't support selected compression method! Dataset was saved without compression");
iRet = H5Dcreate (pFile->iCurrentG, (char*)name, datatype1, dataspace, H5P_DEFAULT);
}
if (iRet < 0) {
NXIReportError (NXpData, "ERROR: Creating chuncked Dataset failed!");
NXIReportError (NXpData, "ERROR: Creating chunked dataset failed!");
return NX_ERROR;
} else {
pFile->iCurrentD = iRet;
@@ -709,12 +697,37 @@
return NX_OK;
}
/* --------------------------------------------------------------------- */
NXstatus CALLING_STYLE NX5makedata (NXhandle fid, CONSTCHAR *name, int datatype,
int rank, int dimensions[])
{
pNexusFile5 pFile;
int chunk_size[H5S_MAX_RANK];
int i;
pFile = NXI5assert (fid);
memset(chunk_size,0,H5S_MAX_RANK*sizeof(int));
if (dimensions[0] == NX_UNLIMITED)
{
for (i = 0; i < H5S_MAX_RANK; i++)
{
chunk_size[i]= 1;
}
}
return NX5compmakedata (fid, name, datatype, rank, dimensions, NX_COMP_NONE, chunk_size);
return NX_OK;
}
/* --------------------------------------------------------------------- */
NXstatus CALLING_STYLE NX5compress (NXhandle fid, int compress_type)
{
printf(" NXcompress ERROR: NeXus API based on HDF5 don't supports\n");
printf(" NXcompress function! Using HDF5 library\n");
printf(" NXcompress ERROR: NeXus API based on HDF5 doesn't support\n");
printf(" NXcompress function! Using HDF5 library,\n");
printf(" the NXcompmakedata function can be applied\n");
printf(" for compression of data!\n");
return NX_ERROR;
@@ -782,27 +795,15 @@
{
pNexusFile5 pFile;
NXname pBuffer;
hid_t iRet, xfer_plist;
size_t size;
hid_t iRet;
char pError[512];
pFile = NXI5assert (fid);
/* set buffer size to 16 MB */
xfer_plist = H5Pcreate(H5P_DATASET_XFER);
size = 16000000;
iRet = H5Pset_buffer(xfer_plist, size, NULL, NULL);
if (iRet < 0) {
NXIReportError (NXpData, "ERROR: Buffer size can not be set to 16 MB");
return NX_ERROR;
}
/* actually write */
iRet = H5Dwrite (pFile->iCurrentD, pFile->iCurrentT, H5S_ALL, H5S_ALL,
xfer_plist, data);
H5Pclose(xfer_plist);
H5P_DEFAULT, data);
if (iRet < 0) {
sprintf (pError, "ERROR: failure to write data to %s", pBuffer);
NXIReportError (NXpData, pError);
@@ -882,7 +883,7 @@
}
if (H5Awrite(attr1,aid1,data) < 0)
{
NXIReportError (NXpData, "ERROR: HDf failed to store attribute ");
NXIReportError (NXpData, "ERROR: HDF failed to store attribute ");
return NX_ERROR;
}
/* Close attribute dataspace */
@@ -934,38 +935,18 @@
{
pNexusFile5 pFile;
int iRet, i;
int rank, size_id;
int rank;
hssize_t myStart[H5S_MAX_RANK];
hsize_t mySize[H5S_MAX_RANK];
hsize_t size[1],maxdims[H5S_MAX_RANK];
size_t buff_size;
hid_t filespace, dataspace, xfer_plist;
hid_t filespace,dataspace;
pFile = NXI5assert (fid);
/* check if there is an Dataset open */
if (pFile->iCurrentD == 0) {
NXIReportError (NXpData, "ERROR: no Dataset open");
NXIReportError (NXpData, "ERROR: no dataset open");
return NX_ERROR;
}
/* set buffer size to 16 MB */
buff_size = 16000000;
/*
size_id = H5Tget_size(pFile->iCurrentT);
buff_size = 1;
for(i = 0; i < rank;i++){
buff_size *= iSize[i];
}
buff_size *= size_id;
*/
xfer_plist = H5Pcreate(H5P_DATASET_XFER);
iRet = H5Pset_buffer(xfer_plist, buff_size, NULL, NULL);
if (iRet < 0) {
NXIReportError (NXpData, "ERROR: Buffer size can not be set to 16 MB");
return NX_ERROR;
}
rank = H5Sget_simple_extent_ndims(pFile->iCurrentS);
for(i = 0; i < rank; i++)
{
@@ -991,7 +972,7 @@
}
/* write slab */
iRet = H5Dwrite(pFile->iCurrentD, pFile->iCurrentT, dataspace,
filespace, xfer_plist, data);
filespace, H5P_DEFAULT,data);
iRet = H5Sclose(filespace);
} else {
/* define slab */
@@ -1005,10 +986,9 @@
}
/* write slab */
iRet = H5Dwrite(pFile->iCurrentD, pFile->iCurrentT, dataspace,
pFile->iCurrentS, xfer_plist, data);
pFile->iCurrentS, H5P_DEFAULT,data);
}
/* deal with HDF errors */
H5Pclose(xfer_plist);
iRet = H5Sclose(dataspace);
if (iRet < 0)
{
@@ -1035,7 +1015,7 @@
NXstatus CALLING_STYLE NX5makelink (NXhandle fid, NXlink* sLink)
{
pNexusFile5 pFile;
int iRet;
/* int iRet; */
herr_t status;
int size_type;
@@ -1137,7 +1117,7 @@
pFile = NXI5assert (fid);
op_data.iname = NULL;
idx=pFile->iCurrentIDX;
idx=pFile->iStack5[pFile->iStackPtr].iCurrentIDX;
if (strlen(pFile->name_ref) == 0) {
/* root group */
strcpy(pFile->name_ref,"/");
@@ -1146,7 +1126,7 @@
strcpy(nxclass,"");
if (iRet > 0)
{
pFile->iCurrentIDX++;
pFile->iStack5[pFile->iStackPtr].iCurrentIDX++;
strcpy(name,op_data.iname);
if (op_data.iname != NULL) {
free(op_data.iname);
@@ -1233,7 +1213,8 @@
{
if (op_data.iname != NULL) {
free(op_data.iname);
}
}
pFile->iStack5[pFile->iStackPtr].iCurrentIDX = 0;
return NX_EOD;
}
else
@@ -1253,18 +1234,69 @@
{
pNexusFile5 pFile;
int iStart[H5S_MAX_RANK];
hid_t data_id, memtype_id, size_id, sign_id;
int dims;
pFile = NXI5assert (fid);
/* check if there is an Dataset open */
if (pFile->iCurrentD == 0)
{
NXIReportError (NXpData, "ERROR: no Dataset open");
return NX_ERROR;
}
{
NXIReportError (NXpData, "ERROR: no Dataset open");
return NX_ERROR;
}
memset (iStart, 0, H5S_MAX_RANK * sizeof(int));
/* actually read */
H5Dread (pFile->iCurrentD, pFile->iCurrentT, H5S_ALL, H5S_ALL,H5P_DEFAULT, data);
/* map datatypes of other plateforms */
data_id = H5Tget_class(pFile->iCurrentT);
if (data_id==H5T_STRING)
{
dims = H5Tget_size(pFile->iCurrentT);
memtype_id = H5Tcopy(H5T_C_S1);
H5Tset_size(memtype_id, dims);
}
if (data_id==H5T_INTEGER)
{
size_id=H5Tget_size(pFile->iCurrentT);
sign_id=H5Tget_sign(pFile->iCurrentT);
if (size_id==1)
{
if (sign_id==H5T_SGN_2)
{
memtype_id = H5T_NATIVE_INT8;
} else {
memtype_id = H5T_NATIVE_UINT8;
}
}
else if (size_id==2)
{
if (sign_id==H5T_SGN_2)
{
memtype_id = H5T_NATIVE_INT16;
} else {
memtype_id = H5T_NATIVE_UINT16;
}
}
else if (size_id==4)
{
if (sign_id==H5T_SGN_2)
{
memtype_id = H5T_NATIVE_INT32;
} else {
memtype_id = H5T_NATIVE_UINT32;
}
}
} else if (data_id==H5T_FLOAT)
{
size_id=H5Tget_size(pFile->iCurrentT);
if (size_id==4)
{
memtype_id = H5T_NATIVE_FLOAT;
} else if (size_id==8) {
memtype_id = H5T_NATIVE_DOUBLE;
}
}
/* actually read */
H5Dread (pFile->iCurrentD, memtype_id, H5S_ALL, H5S_ALL,H5P_DEFAULT, data);
return NX_OK;
}
@@ -1360,9 +1392,10 @@
hsize_t mySize[H5S_MAX_RANK];
hssize_t mStart[H5S_MAX_RANK];
hid_t memspace, iRet, data_id;
hid_t memtype_id, size_id, sign_id;
char *tmp_data;
char *data1;
int i, iRank, mtype = 0;
int i, dims, iRank, mtype = 0;
pFile = NXI5assert (fid);
/* check if there is an Dataset open */
@@ -1408,16 +1441,64 @@
NXIReportError (NXpData, "ERROR: Select memspace failed");
return NX_ERROR;
}
/* map datatypes of other plateforms */
if (data_id==H5T_STRING)
{
dims = H5Tget_size(pFile->iCurrentT);
memtype_id = H5Tcopy(H5T_C_S1);
H5Tset_size(memtype_id, dims);
}
if (data_id==H5T_INTEGER)
{
size_id=H5Tget_size(pFile->iCurrentT);
sign_id=H5Tget_sign(pFile->iCurrentT);
if (size_id==1)
{
if (sign_id==H5T_SGN_2)
{
memtype_id = H5T_NATIVE_INT8;
} else {
memtype_id = H5T_NATIVE_UINT8;
}
}
else if (size_id==2)
{
if (sign_id==H5T_SGN_2)
{
memtype_id = H5T_NATIVE_INT16;
} else {
memtype_id = H5T_NATIVE_UINT16;
}
}
else if (size_id==4)
{
if (sign_id==H5T_SGN_2)
{
memtype_id = H5T_NATIVE_INT32;
} else {
memtype_id = H5T_NATIVE_UINT32;
}
}
} else if (data_id==H5T_FLOAT)
{
size_id=H5Tget_size(pFile->iCurrentT);
if (size_id==4)
{
memtype_id = H5T_NATIVE_FLOAT;
} else if (size_id==8) {
memtype_id = H5T_NATIVE_DOUBLE;
}
}
/* read slab */
if (mtype == NX_CHAR) {
iRet = H5Dread(pFile->iCurrentD, pFile->iCurrentT, H5S_ALL,
iRet = H5Dread(pFile->iCurrentD, memtype_id, H5S_ALL,
H5S_ALL, H5P_DEFAULT,tmp_data);
data1 = tmp_data + myStart[0];
strncpy(data,data1,(hsize_t)iSize[0]);
free(tmp_data);
} else {
iRet = H5Dread(pFile->iCurrentD, pFile->iCurrentT, memspace,
iRet = H5Dread(pFile->iCurrentD, memtype_id, memspace,
pFile->iCurrentS, H5P_DEFAULT,data);
}
@@ -1450,18 +1531,18 @@
unsigned int idx;
pFile = NXI5assert (fileid);
idx=pFile->iCurrentA_IDX;
idx=pFile->iAtt5.iCurrentIDX;
if ((pFile->iCurrentD == 0) && (pFile->iCurrentG==0))
{
/* global attribute */
pFile->iVID=H5Gopen(pFile->iFID,"/");
iRet=H5Aiterate(pFile->iVID,&idx,attr_info,&iname);
} else {
iRet=H5Aiterate(pFile->iCurrentD,&idx,attr_info,&iname);
iRet=H5Aiterate(pFile->iCurrentD,&idx,attr_info,&iname);
}
if (iRet>0)
{
pFile->iCurrentA_IDX++;
pFile->iAtt5.iCurrentIDX++;
strcpy(pName, iname);
if (iname != NULL) {
free(iname);
@@ -1545,10 +1626,10 @@
}
if (idx == 0)
{
NXIReportError (NXpData, "Dataset has no attributes!");
return NX_EOD;
pFile->iAtt5.iCurrentIDX = 0;
return NX_EOD;
}
pFile->iAtt5.iCurrentIDX = 0;
return NX_EOD;
}
else
@@ -1812,7 +1893,23 @@
return NX_ERROR;
}
/*-------------------------------------------------------------------------*/
/* ------------------------------------------------------------------- */
NXstatus CALLING_STYLE NX5sameID (NXhandle fileid, NXlink* pFirstID, NXlink* pSecondID)
{
pNexusFile5 pFile;
pFile = NXI5assert (fileid);
if ((strcmp(pFirstID->iTag5,pSecondID->iTag5) == 0) &
(strcmp(pFirstID->iRef5,pSecondID->iRef5) == 0) &
(strcmp(pFirstID->iRefd,pSecondID->iRefd) == 0)) {
return NX_OK;
} else {
return NX_ERROR;
}
}
/*-------------------------------------------------------------------------*/
NXstatus CALLING_STYLE NX5initattrdir (NXhandle fid)
{
@@ -1820,10 +1917,9 @@
pFile = NXI5assert (fid);
NXI5KillAttDir (fid);
pFile->iCurrentA_IDX=0;
return NX_OK;
}
/*-------------------------------------------------------------------------*/
NXstatus CALLING_STYLE NX5initgroupdir (NXhandle fid)
@@ -1832,6 +1928,5 @@
pFile = NXI5assert (fid);
NXI5KillDir (fid);
pFile->iCurrentIDX=0;
return NX_OK;
}