Cleaned up Makefiles after port to Linux, updated nxdict and napi

This commit is contained in:
cvs
2000-02-21 08:11:15 +00:00
parent cbc7fdf334
commit 9a7084ed23
11 changed files with 423 additions and 130 deletions

294
napi.c
View File

@@ -3,7 +3,7 @@
Application Program Interface Routines
Copyright (C) 1997, 1998, 1999 Mark Koennecke, Przemek Klosowski
Copyright (C) 1997-2000 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
@@ -35,7 +35,7 @@
----------------------------------------------------------------------------*/
static const char* rscid = "$Id: napi.c,v 1.1 2000/02/07 10:38:56 cvs Exp $"; /* Revision interted by CVS */
static const char* rscid = "$Id: napi.c,v 1.2 2000/02/21 08:11:15 cvs Exp $"; /* Revision interted by CVS */
#include <stdlib.h>
#include <assert.h>
@@ -397,6 +397,8 @@ static const char* rscid = "$Id: napi.c,v 1.1 2000/02/07 10:38:56 cvs Exp $"; /*
{
gmt_offset += 3600;
}
#elif defined(__MWERKS__)
gmt_offset = difftime (timer, mktime(gmtime(&timer)));
#else
gmt_offset = time_info->tm_gmtoff;
#endif
@@ -679,11 +681,6 @@ static const char* rscid = "$Id: napi.c,v 1.1 2000/02/07 10:38:56 cvs Exp $"; /*
return NX_OK;
}
NXstatus NXfcompress(NXhandle fid, int *compr_type)
{
return NXcompress(fid,*compr_type);
}
NXstatus NXfmakedata(NXhandle fid, char *name, int *pDatatype,
int *pRank, int dimensions[])
{
@@ -716,7 +713,8 @@ static const char* rscid = "$Id: napi.c,v 1.1 2000/02/07 10:38:56 cvs Exp $"; /*
int32 iNew;
char pBuffer[256];
int i, iRet;
int32 myDim[MAX_VAR_DIMS];
pFile = NXIassert (fid);
@@ -761,7 +759,14 @@ static const char* rscid = "$Id: napi.c,v 1.1 2000/02/07 10:38:56 cvs Exp $"; /*
return NX_ERROR;
}
}
/* cast the dimensions array properly for non 32-bit ints */
for(i = 0; i < rank; i++)
{
myDim[i] = (int32)dimensions[i];
}
/* behave nicely, if there is still an SDS open */
if (pFile->iCurrentSDS != 0) {
SDendaccess (pFile->iCurrentSDS);
@@ -776,7 +781,8 @@ static const char* rscid = "$Id: napi.c,v 1.1 2000/02/07 10:38:56 cvs Exp $"; /*
}
/* dataset creation */
iNew = SDcreate (pFile->iSID, (char*)name, datatype, rank, (int32*)dimensions);
iNew = SDcreate (pFile->iSID, (char*)name, (int32)datatype,
(int32)rank, myDim);
if (iNew < 0) {
sprintf (pBuffer, "ERROR: cannot create SDS %s, check arguments",
name);
@@ -837,6 +843,55 @@ static const char* rscid = "$Id: napi.c,v 1.1 2000/02/07 10:38:56 cvs Exp $"; /*
}
NXstatus NXfcompress(NXhandle fid, int *compr_type)
{
return NXcompress(fid,*compr_type);
}
NXstatus
NXcompress (NXhandle fid, int compress_type)
{
pNexusFile pFile;
int32 iRank, iAtt, iType, iRet, i, e;
int32 iSize[MAX_VAR_DIMS];
NXname pBuffer;
char pError[512];
comp_info compstruct;
char *str;
pFile = NXIassert (fid);
/* check if there is an SDS open */
if (pFile->iCurrentSDS == 0) {
NXIReportError (NXpData, "ERROR: no SDS open");
return NX_ERROR;
}
/* first read dimension information */
SDgetinfo (pFile->iCurrentSDS, pBuffer, &iRank, iSize, &iType, &iAtt);
/*
according to compression type initialize compression
information
*/
if(compress_type == NX_COMP_LZW)
{
compstruct.deflate.level = 6;
}
else if(compress_type == NX_COMP_HUF)
{
compstruct.skphuff.skp_size = DFKNTsize(iType);
}
iRet = SDsetcompress(pFile->iCurrentSDS, compress_type, &compstruct);
if (iRet < 0) {
sprintf (pError, "ERROR: failure to compress data to %s", pBuffer);
NXIReportError (NXpData, pError);
return NX_ERROR;
}
return NX_OK;
}
NXstatus
NXclosedata (NXhandle fid)
{
@@ -889,7 +944,10 @@ static const char* rscid = "$Id: napi.c,v 1.1 2000/02/07 10:38:56 cvs Exp $"; /*
NXgetslab (NXhandle fid, void *data, int iStart[], int iSize[])
{
pNexusFile pFile;
int32 myStart[MAX_VAR_DIMS], mySize[MAX_VAR_DIMS];
int32 i, iRank, iType, iAtt;
NXname pBuffer;
pFile = NXIassert (fid);
/* check if there is an SDS open */
@@ -897,9 +955,31 @@ static const char* rscid = "$Id: napi.c,v 1.1 2000/02/07 10:38:56 cvs Exp $"; /*
NXIReportError (NXpData, "ERROR: no SDS open");
return NX_ERROR;
}
/* actually read */
SDreaddata (pFile->iCurrentSDS, (int32*)iStart, NULL, (int32*)iSize, data);
return NX_OK;
/* if an int is not 32-bit we have to cast them properly in order
to kill a bug.
*/
if(sizeof(int) != 4)
{
SDgetinfo (pFile->iCurrentSDS, pBuffer,
&iRank, myStart, &iType, &iAtt);
for(i = 0; i < iRank; i++)
{
myStart[i] = (int32)iStart[i];
mySize[i] = (int32)iSize[i];
}
/* finally read */
SDreaddata (pFile->iCurrentSDS, myStart, NULL,
mySize, data);
return NX_OK;
}
else
{
/* read directly */
SDreaddata (pFile->iCurrentSDS, (int32*)iStart, NULL,
(int32*)iSize, data);
return NX_OK;
}
}
@@ -1007,57 +1087,15 @@ static const char* rscid = "$Id: napi.c,v 1.1 2000/02/07 10:38:56 cvs Exp $"; /*
return NX_OK;
}
NXstatus
NXcompress (NXhandle fid, int compress_type)
{
pNexusFile pFile;
int32 iRank, iAtt, iType, iRet, i, e;
int32 iSize[MAX_VAR_DIMS];
NXname pBuffer;
char pError[512];
comp_info compstruct;
char *str;
pFile = NXIassert (fid);
/* check if there is an SDS open */
if (pFile->iCurrentSDS == 0) {
NXIReportError (NXpData, "ERROR: no SDS open");
return NX_ERROR;
}
/* first read dimension information */
SDgetinfo (pFile->iCurrentSDS, pBuffer, &iRank, iSize, &iType, &iAtt);
/*
according to compression type initialize compression
information
*/
if(compress_type == NX_COMP_LZW)
{
compstruct.deflate.level = 6;
}
else if(compress_type == NX_COMP_HUF)
{
compstruct.skphuff.skp_size = DFKNTsize(iType);
}
iRet = SDsetcompress(pFile->iCurrentSDS, compress_type, &compstruct);
if (iRet < 0) {
sprintf (pError, "ERROR: failure to compress data to %s", pBuffer);
NXIReportError (NXpData, pError);
return NX_ERROR;
}
return NX_OK;
}
NXstatus
NXputslab (NXhandle fid, void *data, int iStart[], int iSize[])
{
pNexusFile pFile;
int iRet;
int iStride[MAX_VAR_DIMS], i;
int32 iStride[MAX_VAR_DIMS];
int32 myStart[MAX_VAR_DIMS], mySize[MAX_VAR_DIMS];
int32 i, iRank, iType, iAtt;
NXname pBuffer;
pFile = NXIassert (fid);
@@ -1071,10 +1109,32 @@ static const char* rscid = "$Id: napi.c,v 1.1 2000/02/07 10:38:56 cvs Exp $"; /*
for (i = 0; i < MAX_VAR_DIMS; i++) {
iStride[i] = 1;
}
/* actually write */
iRet = SDwritedata (pFile->iCurrentSDS, (int32*)iStart,
(int32*)iStride, (int32*)iSize, data);
/* if an int is not 32-bit we have to cast them properly in order
to kill a bug.
*/
if(sizeof(int) != 4)
{
SDgetinfo (pFile->iCurrentSDS, pBuffer,
&iRank, myStart, &iType, &iAtt);
for(i = 0; i < iRank; i++)
{
myStart[i] = (int32)iStart[i];
mySize[i] = (int32)iSize[i];
}
/* finally write */
iRet = SDwritedata (pFile->iCurrentSDS, myStart,
iStride, mySize, data);
}
else
{
/* write directly */
iRet = SDwritedata (pFile->iCurrentSDS,iStart,
iStride, iSize, data);
}
/* deal with HDF errors */
if (iRet < 0) {
NXIReportError (NXpData, "ERROR: writing slab failed");
return NX_ERROR;
@@ -1098,12 +1158,12 @@ static const char* rscid = "$Id: napi.c,v 1.1 2000/02/07 10:38:56 cvs Exp $"; /*
if (pFile->iCurrentSDS != 0) {
/* SDS attribute */
iRet = SDsetattr (pFile->iCurrentSDS, (char*)name, iType,
datalen, data);
iRet = SDsetattr (pFile->iCurrentSDS, (char*)name, (int32)iType,
(int32)datalen, data);
} else {
/* global attribute */
iRet = SDsetattr (pFile->iSID, (char*)name, iType,
datalen, data);
iRet = SDsetattr (pFile->iSID, (char*)name, (int32)iType,
(int32)datalen, data);
}
if (iRet < 0) {
@@ -1119,7 +1179,7 @@ static const char* rscid = "$Id: napi.c,v 1.1 2000/02/07 10:38:56 cvs Exp $"; /*
{
pNexusFile pFile;
NXname pBuffer;
int32 iAtt;
int32 iAtt, myDim[MAX_VAR_DIMS], i, iRank, mType;
pFile = NXIassert (fid);
@@ -1129,13 +1189,85 @@ static const char* rscid = "$Id: napi.c,v 1.1 2000/02/07 10:38:56 cvs Exp $"; /*
return NX_ERROR;
}
/* read information */
SDgetinfo (pFile->iCurrentSDS, pBuffer, (int32*)rank, (int32*)dimension,
(int32*)iType, &iAtt);
SDgetinfo (pFile->iCurrentSDS, pBuffer, &iRank, myDim,
&mType, &iAtt);
/* conversion to proper ints for the platform */
*iType = (int)mType;
*rank = (int)iRank;
for(i = 0; i < iRank; i++)
{
dimension[i] = (int)myDim[i];
}
return NX_OK;
}
/*-------------------------------------------------------------------------*/
NXstatus
NXgetgroupinfo (NXhandle fid, int *iN, NXname pName, NXname pClass)
{
pNexusFile pFile;
int
pFile = NXIassert (fid);
/* check if there is a group open */
if (pFile->iCurrentVG == 0) {
*iN = Vlone (pFile->iVID, NULL, 0);
strcpy (pName, "root");
strcpy (pClass, "NXroot");
}
else {
*iN = Vntagrefs (pFile->iCurrentVG);
Vgetname (pFile->iCurrentVG, pName);
Vgetclass (pFile->iCurrentVG, pClass);
}
return NX_OK;
}
/*-------------------------------------------------------------------------*/
NXstatus
NXgetattrinfo (NXhandle fid, int *iN)
{
pNexusFile pFile;
int iRet;
int32 iData, iAtt, iRank, iType;
int32 iDim[MAX_VAR_DIMS];
NXname pNam;
pFile = NXIassert (fid);
if (pFile->iCurrentSDS != 0) { /* SDS level */
iRet = SDgetinfo (pFile->iCurrentSDS, pNam, &iRank, iDim, &iType,
&iAtt);
} else { /* global level */
iRet = SDfileinfo (pFile->iSID, &iData, &iAtt);
}
if (iRet < 0) {
NXIReportError (NXpData, "NX_ERROR: HDF cannot read attribute numbers");
*iN = 0;
return NX_ERROR;
}
*iN = iAtt;
return iRet;
}
NXstatus
NXinitgroupdir (NXhandle fid)
{
pNexusFile pFile;
int iRet;
pFile = NXIassert (fid);
NXIKillDir (fid);
iRet = NXIInitDir (pFile);
if (iRet < 0) {
NXIReportError (NXpData,
"NX_ERROR: no memory to store directory info");
return NX_EOD;
}
return NX_OK;
}
/*-------------------------------------------------------------------------*/
NXstatus
NXgetnextentry (NXhandle fid, NXname name, NXname nxclass, int *datatype)
{
pNexusFile pFile;
@@ -1206,7 +1338,7 @@ static const char* rscid = "$Id: napi.c,v 1.1 2000/02/07 10:38:56 cvs Exp $"; /*
} else { /* unidentified */
strcpy (name, "UNKNOWN");
strcpy (nxclass, "UNKNOWN");
*datatype = pFile->iStack[iStackPtr].iTagDir[iCurDir];
*datatype = pFile->iStack[iStackPtr].iTagDir[iCurDir];
pFile->iStack[pFile->iStackPtr].iCurDir++;
return NX_OK;
}
@@ -1214,6 +1346,20 @@ static const char* rscid = "$Id: napi.c,v 1.1 2000/02/07 10:38:56 cvs Exp $"; /*
return NX_ERROR; /* not reached */
}
/*-------------------------------------------------------------------------*/
NXstatus
NXinitattrdir (NXhandle fid)
{
pNexusFile pFile;
int iRet;
pFile = NXIassert (fid);
NXIKillAttDir (fid);
iRet = NXIInitAttDir (pFile);
if (iRet == NX_ERROR)
return NX_ERROR;
return NX_OK;
}
/*-------------------------------------------------------------------------*/
NXstatus
@@ -1297,7 +1443,6 @@ static const char* rscid = "$Id: napi.c,v 1.1 2000/02/07 10:38:56 cvs Exp $"; /*
return NX_ERROR; /* not reached */
}
NXstatus
NXmakelink (NXhandle fid, NXlink* sLink)
{
@@ -1371,3 +1516,4 @@ static const char* rscid = "$Id: napi.c,v 1.1 2000/02/07 10:38:56 cvs Exp $"; /*
*data = NULL;
return NX_OK;
}