PSI sics-cvs-psi-2006

This commit is contained in:
2006-05-08 02:00:00 +00:00
committed by Douglas Clowes
parent ae77364de2
commit 6e926b813f
388 changed files with 445529 additions and 14109 deletions

222
napi4.c
View File

@@ -20,6 +20,8 @@
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
For further information, see <http://www.neutron.anl.gov/NeXus/>
$Id$
----------------------------------------------------------------------------*/
#include <stdlib.h>
@@ -27,6 +29,11 @@
#include <string.h>
#include <time.h>
#include "napi.h"
#include "napi4.h"
extern void *NXpData;
typedef struct __NexusFile {
struct iStack {
int32 *iRefDir;
@@ -45,8 +52,7 @@
int iStackPtr;
char iAccess[2];
} NexusFile, *pNexusFile;
/*--------------------------------------------------------------------*/
static pNexusFile NXIassert(NXhandle fid)
@@ -61,7 +67,7 @@
/* --------------------------------------------------------------------- */
static int32 NXIFindVgroup (pNexusFile pFile, char *name, char *nxclass)
static int32 NXIFindVgroup (pNexusFile pFile, CONSTCHAR *name, CONSTCHAR *nxclass)
{
int32 iNew, iRef, iTag;
int iN, i;
@@ -285,8 +291,28 @@
self->iAtt.iCurDir = 0;
self->iAtt.iNDir = 0;
}
/*------------------------------------------------------------------*/
static void NXIbuildPath(pNexusFile pFile, char *buffer, int bufLen)
{
int i;
int32 groupID, iA, iD1, iD2, iDim[MAX_VAR_DIMS];
NXname pText;
buffer[0] = '\0';
for(i = 0; i < pFile->iStackPtr; i++){
strncat(buffer,"/",bufLen-strlen(buffer));
groupID = Vattach(pFile->iVID,pFile->iStack[pFile->iStackPtr].iVref,
"r");
Vgetname(groupID, pText);
strncat(buffer,pText,bufLen-strlen(buffer));
Vdetach(groupID);
}
if(pFile->iCurrentSDS != 0){
strncat(buffer,"/",bufLen-strlen(buffer));
SDgetinfo(pFile->iCurrentSDS,pText,&iA,iDim,&iD1,&iD2);
strncat(buffer,pText,bufLen-strlen(buffer));
}
}
/* ----------------------------------------------------------------------
Definition of NeXus API
@@ -294,21 +320,16 @@
---------------------------------------------------------------------*/
NXstatus CALLING_STYLE NX4open(CONSTCHAR *filename, NXaccess am, NXhandle* pHandle)
NXstatus NX4open(CONSTCHAR *filename, NXaccess am,
NXhandle* pHandle)
{
pNexusFile pNew = NULL;
char pBuffer[512], time_buffer[64];
char pBuffer[512];
char *time_puffer;
char HDF_VERSION[64];
uint32 lmajor, lminor, lrelease;
int32 am1=0;
int32 file_id=0, an_id=0, ann_id=0;
time_t timer;
struct tm *time_info;
const char* time_format;
long gmt_offset;
#ifdef USE_FTIME
struct timeb timeb_struct;
#endif /* USE_FTIME */
*pHandle = NULL;
/* map Nexus NXaccess types to HDF4 types */
@@ -328,49 +349,9 @@
return NX_ERROR;
}
memset (pNew, 0, sizeof (NexusFile));
/*
* get time in ISO 8601 format
*/
#ifdef NEED_TZSET
tzset();
#endif /* NEED_TZSET */
time(&timer);
#ifdef USE_FTIME
ftime(&timeb_struct);
gmt_offset = -timeb_struct.timezone * 60;
if (timeb_struct.dstflag != 0) {
gmt_offset += 3600;
}
#else
time_info = gmtime(&timer);
if (time_info != NULL) {
gmt_offset = (long)difftime(timer, mktime(time_info));
} else {
NXIReportError(NXpData, "Your gmtime() function does not work ... timezone information will be incorrect\n");
gmt_offset = 0;
}
#endif /* USE_FTIME */
time_info = localtime(&timer);
if (time_info != NULL) {
if (gmt_offset < 0) {
time_format = "%04d-%02d-%02d %02d:%02d:%02d-%02d%02d";
} else {
time_format = "%04d-%02d-%02d %02d:%02d:%02d+%02d%02d";
}
sprintf(time_buffer, time_format,
1900 + time_info->tm_year,
1 + time_info->tm_mon,
time_info->tm_mday,
time_info->tm_hour,
time_info->tm_min,
time_info->tm_sec,
abs(gmt_offset / 3600),
abs((gmt_offset % 3600) / 60)
);
} else {
strcpy(time_buffer, "1970-01-01 00:00:00+0000");
}
time_puffer = NXIformatNeXusTime();
#if WRITE_OLD_IDENT /* not used at moment */
/*
* write something that can be used by OLE
@@ -426,9 +407,15 @@
NXIReportError (NXpData, "ERROR: HDF failed to store file_name attribute ");
return NX_ERROR;
}
if (SDsetattr(pNew->iSID, "file_time", DFNT_CHAR8, strlen(time_buffer), time_buffer) < 0) {
NXIReportError (NXpData, "ERROR: HDF failed to store file_time attribute ");
return NX_ERROR;
if(time_puffer != NULL){
if (SDsetattr(pNew->iSID, "file_time", DFNT_CHAR8,
strlen(time_puffer), time_puffer) < 0) {
NXIReportError (NXpData,
"ERROR: HDF failed to store file_time attribute ");
free(time_puffer);
return NX_ERROR;
}
free(time_puffer);
}
}
@@ -467,7 +454,7 @@
/*-----------------------------------------------------------------------*/
NXstatus CALLING_STYLE NX4close (NXhandle* fid)
NXstatus NX4close (NXhandle* fid)
{
pNexusFile pFile = NULL;
int iRet;
@@ -505,7 +492,7 @@
/*-----------------------------------------------------------------------*/
NXstatus CALLING_STYLE NX4makegroup (NXhandle fid, CONSTCHAR *name, char *nxclass)
NXstatus NX4makegroup (NXhandle fid, CONSTCHAR *name, CONSTCHAR *nxclass)
{
pNexusFile pFile;
int32 iNew, iRet;
@@ -549,7 +536,7 @@
/*------------------------------------------------------------------------*/
NXstatus CALLING_STYLE NX4opengroup (NXhandle fid, CONSTCHAR *name, char *nxclass)
NXstatus NX4opengroup (NXhandle fid, CONSTCHAR *name, CONSTCHAR *nxclass)
{
pNexusFile pFile;
int32 iRef;
@@ -583,7 +570,7 @@
/* ------------------------------------------------------------------- */
NXstatus CALLING_STYLE NX4closegroup (NXhandle fid)
NXstatus NX4closegroup (NXhandle fid)
{
pNexusFile pFile;
@@ -616,7 +603,7 @@
/* --------------------------------------------------------------------- */
NXstatus CALLING_STYLE NX4makedata (NXhandle fid, CONSTCHAR *name, int datatype, int rank,
NXstatus NX4makedata (NXhandle fid, CONSTCHAR *name, int datatype, int rank,
int dimensions[])
{
pNexusFile pFile;
@@ -741,7 +728,7 @@
/* --------------------------------------------------------------------- */
NXstatus CALLING_STYLE NX4compmakedata (NXhandle fid, CONSTCHAR *name, int datatype, int rank,
NXstatus NX4compmakedata (NXhandle fid, CONSTCHAR *name, int datatype, int rank,
int dimensions[],int compress_type, int chunk_size[])
{
pNexusFile pFile;
@@ -908,7 +895,7 @@
/* --------------------------------------------------------------------- */
NXstatus CALLING_STYLE NX4compress (NXhandle fid, int compress_type)
NXstatus NX4compress (NXhandle fid, int compress_type)
{
pNexusFile pFile;
int32 iRank, iAtt, iType, iRet;
@@ -972,7 +959,7 @@
/* --------------------------------------------------------------------- */
NXstatus CALLING_STYLE NX4opendata (NXhandle fid, CONSTCHAR *name)
NXstatus NX4opendata (NXhandle fid, CONSTCHAR *name)
{
pNexusFile pFile;
int32 iNew;
@@ -1014,7 +1001,7 @@
/* ----------------------------------------------------------------- */
NXstatus CALLING_STYLE NX4closedata (NXhandle fid)
NXstatus NX4closedata (NXhandle fid)
{
pNexusFile pFile;
int iRet;
@@ -1039,7 +1026,7 @@
/* ------------------------------------------------------------------- */
NXstatus CALLING_STYLE NX4putdata (NXhandle fid, void *data)
NXstatus NX4putdata (NXhandle fid, void *data)
{
pNexusFile pFile;
int32 iStart[MAX_VAR_DIMS], iSize[MAX_VAR_DIMS], iStride[MAX_VAR_DIMS];
@@ -1076,7 +1063,7 @@
/* ------------------------------------------------------------------- */
NXstatus
CALLING_STYLE NX4putattr (NXhandle fid, CONSTCHAR *name, void *data, int datalen, int iType)
NX4putattr (NXhandle fid, CONSTCHAR *name, void *data, int datalen, int iType)
{
pNexusFile pFile;
int iRet, type;
@@ -1130,7 +1117,7 @@
}
iType = type;
if (iRet < 0) {
NXIReportError (NXpData, "ERROR: HDf failed to store attribute ");
NXIReportError (NXpData, "ERROR: HDF failed to store attribute ");
return NX_ERROR;
}
return NX_OK;
@@ -1139,7 +1126,7 @@
/* ------------------------------------------------------------------- */
NXstatus CALLING_STYLE NX4putslab (NXhandle fid, void *data, int iStart[], int iSize[])
NXstatus NX4putslab (NXhandle fid, void *data, int iStart[], int iSize[])
{
pNexusFile pFile;
int iRet;
@@ -1196,7 +1183,7 @@
/* ------------------------------------------------------------------- */
NXstatus CALLING_STYLE NX4getdataID (NXhandle fid, NXlink* sRes)
NXstatus NX4getdataID (NXhandle fid, NXlink* sRes)
{
pNexusFile pFile;
@@ -1208,6 +1195,7 @@
} else {
sRes->iTag = DFTAG_NDG;
sRes->iRef = SDidtoref (pFile->iCurrentSDS);
NXIbuildPath(pFile,sRes->targetPath,1024);
return NX_OK;
}
sRes->iTag = NX_ERROR;
@@ -1218,24 +1206,44 @@
/* ------------------------------------------------------------------- */
NXstatus CALLING_STYLE NX4makelink (NXhandle fid, NXlink* sLink)
NXstatus NX4makelink (NXhandle fid, NXlink* sLink)
{
pNexusFile pFile;
int32 iVG, iRet;
int32 iVG, iRet, dataID, type = DFNT_CHAR8, length;
char name[] = "target";
pFile = NXIassert (fid);
if (pFile->iCurrentVG == 0) { /* root level, can not link here */
return NX_ERROR;
}
Vaddtagref (pFile->iCurrentVG, sLink->iTag, sLink->iRef);
Vaddtagref(pFile->iCurrentVG, sLink->iTag, sLink->iRef);
if(sLink->iTag == DFTAG_SDG || sLink->iTag == DFTAG_NDG ||
sLink->iTag == DFTAG_SDS)
{
dataID = SDreftoindex(pFile->iSID,sLink->iRef);
dataID = SDselect(pFile->iSID,dataID);
length = strlen(sLink->targetPath);
SDsetattr(dataID,name,type,length,sLink->targetPath);
SDendaccess(dataID);
}
return NX_OK;
}
/*----------------------------------------------------------------------*/
NXstatus NX4printlink (NXhandle fid, NXlink* sLink)
{
pNexusFile pFile;
pFile = NXIassert (fid);
printf("HDF4 link: iTag = %ld, iRef = %ld, target=\"%s\"\n",
sLink->iTag, sLink->iRef, sLink->targetPath);
return NX_OK;
}
/*----------------------------------------------------------------------*/
NXstatus CALLING_STYLE NX4flush(NXhandle *pHandle)
NXstatus NX4flush(NXhandle *pHandle)
{
char *pFileName, *pCopy = NULL;
int access, dummy, iRet, i, iStack;
@@ -1316,7 +1324,7 @@
/*-------------------------------------------------------------------------*/
NXstatus CALLING_STYLE NX4getnextentry (NXhandle fid, NXname name, NXname nxclass, int *datatype)
NXstatus NX4getnextentry (NXhandle fid, NXname name, NXname nxclass, int *datatype)
{
pNexusFile pFile;
int iRet, iStackPtr, iCurDir;
@@ -1398,7 +1406,7 @@
/*-------------------------------------------------------------------------*/
NXstatus CALLING_STYLE NX4getdata (NXhandle fid, void *data)
NXstatus NX4getdata (NXhandle fid, void *data)
{
pNexusFile pFile;
int32 iStart[MAX_VAR_DIMS], iSize[MAX_VAR_DIMS];
@@ -1423,7 +1431,8 @@
/*-------------------------------------------------------------------------*/
NXstatus
CALLING_STYLE NX4getinfo (NXhandle fid, int *rank, int dimension[], int *iType)
NX4getinfo (NXhandle fid, int *rank, int dimension[],
int *iType)
{
pNexusFile pFile;
NXname pBuffer;
@@ -1454,7 +1463,7 @@
/*-------------------------------------------------------------------------*/
NXstatus CALLING_STYLE NX4getslab (NXhandle fid, void *data, int iStart[], int iSize[])
NXstatus NX4getslab (NXhandle fid, void *data, int iStart[], int iSize[])
{
pNexusFile pFile;
int32 myStart[MAX_VAR_DIMS], mySize[MAX_VAR_DIMS];
@@ -1497,7 +1506,7 @@
/*-------------------------------------------------------------------------*/
NXstatus CALLING_STYLE NX4getnextattr (NXhandle fileid, NXname pName,
NXstatus NX4getnextattr (NXhandle fileid, NXname pName,
int *iLength, int *iType)
{
pNexusFile pFile;
@@ -1540,7 +1549,7 @@
/*-------------------------------------------------------------------------*/
NXstatus CALLING_STYLE NX4getattr (NXhandle fid, char *name, void *data, int* datalen, int* iType)
NXstatus NX4getattr (NXhandle fid, char *name, void *data, int* datalen, int* iType)
{
pNexusFile pFile;
int32 iNew, iType32;
@@ -1649,7 +1658,7 @@
/*-------------------------------------------------------------------------*/
NXstatus CALLING_STYLE NX4getattrinfo (NXhandle fid, int *iN)
NXstatus NX4getattrinfo (NXhandle fid, int *iN)
{
pNexusFile pFile;
int iRet;
@@ -1675,7 +1684,7 @@
/*-------------------------------------------------------------------------*/
NXstatus CALLING_STYLE NX4getgroupID (NXhandle fileid, NXlink* sRes)
NXstatus NX4getgroupID (NXhandle fileid, NXlink* sRes)
{
pNexusFile pFile;
@@ -1687,6 +1696,7 @@
} else {
sRes->iTag = DFTAG_VG;
sRes->iRef = VQueryref(pFile->iCurrentVG);
NXIbuildPath(pFile,sRes->targetPath,1024);
return NX_OK;
}
/* not reached */
@@ -1697,7 +1707,7 @@
/*-------------------------------------------------------------------------*/
NXstatus
CALLING_STYLE NX4getgroupinfo (NXhandle fid, int *iN, NXname pName, NXname pClass)
NX4getgroupinfo (NXhandle fid, int *iN, NXname pName, NXname pClass)
{
pNexusFile pFile;
@@ -1718,7 +1728,7 @@
/* ------------------------------------------------------------------- */
NXstatus CALLING_STYLE NX4sameID (NXhandle fileid, NXlink* pFirstID, NXlink* pSecondID)
NXstatus NX4sameID (NXhandle fileid, NXlink* pFirstID, NXlink* pSecondID)
{
pNexusFile pFile;
@@ -1733,7 +1743,7 @@
/*-------------------------------------------------------------------------*/
NXstatus CALLING_STYLE NX4initattrdir (NXhandle fid)
NXstatus NX4initattrdir (NXhandle fid)
{
pNexusFile pFile;
int iRet;
@@ -1750,7 +1760,7 @@
/*-------------------------------------------------------------------------*/
NXstatus CALLING_STYLE NX4initgroupdir (NXhandle fid)
NXstatus NX4initgroupdir (NXhandle fid)
{
pNexusFile pFile;
int iRet;
@@ -1765,3 +1775,35 @@
return NX_OK;
}
/*--------------------------------------------------------------------*/
void NX4assignFunctions(pNexusFunction fHandle)
{
fHandle->nxclose=NX4close;
fHandle->nxflush=NX4flush;
fHandle->nxmakegroup=NX4makegroup;
fHandle->nxopengroup=NX4opengroup;
fHandle->nxclosegroup=NX4closegroup;
fHandle->nxmakedata=NX4makedata;
fHandle->nxcompmakedata=NX4compmakedata;
fHandle->nxcompress=NX4compress;
fHandle->nxopendata=NX4opendata;
fHandle->nxclosedata=NX4closedata;
fHandle->nxputdata=NX4putdata;
fHandle->nxputattr=NX4putattr;
fHandle->nxputslab=NX4putslab;
fHandle->nxgetdataID=NX4getdataID;
fHandle->nxmakelink=NX4makelink;
fHandle->nxgetdata=NX4getdata;
fHandle->nxgetinfo=NX4getinfo;
fHandle->nxgetnextentry=NX4getnextentry;
fHandle->nxgetslab=NX4getslab;
fHandle->nxgetnextattr=NX4getnextattr;
fHandle->nxgetattr=NX4getattr;
fHandle->nxgetattrinfo=NX4getattrinfo;
fHandle->nxgetgroupID=NX4getgroupID;
fHandle->nxgetgroupinfo=NX4getgroupinfo;
fHandle->nxsameID=NX4sameID;
fHandle->nxinitgroupdir=NX4initgroupdir;
fHandle->nxinitattrdir=NX4initattrdir;
fHandle->nxprintlink=NX4printlink;
}