- made fixes to hkl

- Introduced a help system
- introduced a module for handling automatic updates of files during
  long measurements
- Added a circular buffer and handling facilities to varlog
- Upgraded documentation


SKIPPED:
	psi/faverage.h
	psi/nxamor.tex
	psi/pimotor.h
	psi/pimotor.tex
This commit is contained in:
cvs
2003-12-10 13:50:44 +00:00
parent 7a5f0193ab
commit bc02cb79e7
80 changed files with 2680 additions and 664 deletions

385
nxdict.c
View File

@ -1,4 +1,6 @@
#line 2264 "nxdict.w"
/*---------------------------------------------------------------------------
Nexus Dictionary API implementation file.
@ -18,24 +20,14 @@
August, 1997
Version: 1.0
Version 1.1
Updated to use the combined HDF4 HDF5 API. New keyword -chunk which
defines the chunk buffer size for a SDS.
Mark Koennecke, August 2001
-----------------------------------------------------------------------------*/
#include <stdlib.h>
#include <stdio.h>
#include <assert.h>
#include <string.h>
#include <time.h>
#include <mfhdf.h>
#include "fortify.h"
#include "lld.h"
#include "napi.h"
#include "stringdict.h"
@ -49,13 +41,14 @@
extern void *NXpData;
extern void (*NXIReportError)(void *pData, char *pBuffer);
/*--------------------------------------------------------------------------*/
/* #define DEFDEBUG 1 */
#define DEFDEBUG 1
/* define DEFDEBUG when you wish to print your definition strings before
action. This can help a lot to resolve mysteries when working with
dictionaries.
*/
/*-------------------------------------------------------------------------*/
#line 362 "nxdict.w"
typedef struct __NXdict
{
@ -65,6 +58,7 @@
/*------------------ verbosity level -------------------------------------*/
static int iVerbosity = 0 ;
#line 2311 "nxdict.w"
/*-------------------------------------------------------------------------*/
static char *NXDIReadFile(FILE *fd)
@ -106,6 +100,7 @@
}
/*--------------------------------------------------------------------------*/
#line 490 "nxdict.w"
#define FWORD 1
#define FHASH 2
@ -178,9 +173,11 @@
}
#line 2351 "nxdict.w"
/*------------------------------------------------------------------------*/
#line 566 "nxdict.w"
#define AMODE 0
#define DMODE 1
@ -269,6 +266,7 @@
}
}
#line 2353 "nxdict.w"
/*--------------------------------------------------------------------------*/
NXstatus NXDinitfromfile(char *filename, NXdict *pData)
@ -279,6 +277,7 @@
char pError[512];
#line 383 "nxdict.w"
/* allocate a new NXdict structure */
if(iVerbosity == NXalot)
@ -303,6 +302,10 @@
}
#line 2362 "nxdict.w"
#line 410 "nxdict.w"
/* is there a file name argument */
if(filename == NULL)
@ -315,6 +318,10 @@
return NX_OK;
}
#line 2363 "nxdict.w"
#line 424 "nxdict.w"
fd = fopen(filename,"rb");
if(!fd)
@ -327,6 +334,12 @@
}
#line 2364 "nxdict.w"
#line 444 "nxdict.w"
/* read the file contents */
if(iVerbosity == NXalot)
{
@ -350,6 +363,8 @@
}
NXDIParse(pBuffer, pNew->pDictionary);
#line 2365 "nxdict.w"
if(iVerbosity == NXalot)
{
@ -361,6 +376,8 @@
}
/*--------------------------------------------------------------------------*/
#line 660 "nxdict.w"
NXdict NXDIAssert(NXdict handle)
{
NXdict self = NULL;
@ -370,9 +387,12 @@
return self;
}
#line 2376 "nxdict.w"
/*-------------------------------------------------------------------------*/
#line 671 "nxdict.w"
NXstatus NXDclose(NXdict handle, char *filename)
{
NXdict self;
@ -421,8 +441,12 @@
return NX_OK;
}
#line 2378 "nxdict.w"
/*------------------------------------------------------------------------*/
#line 724 "nxdict.w"
NXstatus NXDadd(NXdict handle, char *alias, char *pDef)
{
NXdict self;
@ -467,7 +491,14 @@
}
return NX_OK;
}
#line 2380 "nxdict.w"
/*-----------------------------------------------------------------------*/
#line 776 "nxdict.w"
#define NORMAL 1
#define ALIAS 2
pDynString NXDItextreplace(NXdict handle, char *pDefString)
@ -564,12 +595,23 @@
return NX_OK;
}
#line 2382 "nxdict.w"
/*------------------- The Defintion String Parser -----------------------*/
/*------- Data structures */
#line 886 "nxdict.w"
typedef struct {
char pText[20];
int iCode;
} TokDat;
#line 2385 "nxdict.w"
#line 896 "nxdict.w"
#define TERMSDS 100
#define TERMVG 200
#define TERMLINK 300
@ -583,15 +625,32 @@
int iTerminal;
} ParDat;
#line 2386 "nxdict.w"
#line 1101 "nxdict.w"
static void DummyError(void *pData, char *pError)
{
return;
}
#line 2387 "nxdict.w"
#line 1215 "nxdict.w"
typedef struct {
char name[256];
char value[256];
}AttItem;
#line 2388 "nxdict.w"
/*------------------------------------------------------------------------*/
#line 918 "nxdict.w"
/*---------------- Token name defines ---------------------------*/
#define DSLASH 0
#define DKOMMA 1
@ -606,14 +665,10 @@
#define DCLOSE 11
#define DATTR 12
#define DEND 13
#define DLZW 14
#define DHUF 15
#define DRLE 16
#define CHUNK 17
/*----------------- Keywords ----------------------------------------*/
static TokDat TokenList[12] = {
static TokDat TokenList[8] = {
{"SDS",DSDS},
{"NXLINK",DLINK},
{"NXVGROUP",DGROUP},
@ -621,11 +676,7 @@
{"-type",DTYPE},
{"-rank",DRANK},
{"-attr",DATTR},
{"-chunk",CHUNK},
{"-LZW",DLZW},
{"-HUF",DHUF},
{"-RLE",DRLE},
{NULL,0} };
{"",0} };
/*-----------------------------------------------------------------------*/
static void NXDIDefToken(ParDat *sStat)
@ -693,7 +744,7 @@
sStat->pToken[i] = '\0';
/*--------- try to find word in Tokenlist */
for(i = 0; i < 10; i++)
for(i = 0; i < 7; i++)
{
if(strcmp(sStat->pToken,TokenList[i].pText) == 0)
{
@ -708,8 +759,12 @@
}
#line 2390 "nxdict.w"
/*------------------------------------------------------------------------*/
#line 1114 "nxdict.w"
int NXDIParsePath(NXhandle hfil, ParDat *pParse)
{
int iRet, iToken;
@ -800,8 +855,12 @@
return NX_ERROR;
}
#line 2392 "nxdict.w"
/*------------------------------------------------------------------------*/
#line 1481 "nxdict.w"
static int NXDIParseAttr(ParDat *pParse, int iList)
{
char pError[256];
@ -860,7 +919,12 @@
return NX_OK;
}
#line 2394 "nxdict.w"
/*------------------------------------------------------------------------*/
#line 1428 "nxdict.w"
static int NXDIParseDim(ParDat *pParse, int *iDim)
{
char pError[256];
@ -908,7 +972,13 @@
}
return NX_OK;
}
#line 2396 "nxdict.w"
/*------------------------------------------------------------------------*/
#line 1379 "nxdict.w"
static TokDat tDatType[] = {
{"DFNT_FLOAT32",DFNT_FLOAT32},
{"DFNT_FLOAT64",DFNT_FLOAT64},
@ -918,8 +988,7 @@
{"DFNT_UINT16",DFNT_UINT16},
{"DFNT_INT32",DFNT_INT32},
{"DFNT_UINT32",DFNT_UINT32},
{"DFNT_CHAR",DFNT_CHAR},
{NULL,-122} };
{"",0} };
@ -954,15 +1023,19 @@
return NX_ERROR;
}
#line 2398 "nxdict.w"
/*-------------------------------------------------------------------------*/
#line 1223 "nxdict.w"
static int NXDIParseSDS(NXhandle hfil, ParDat *pParse)
{
int iType = DFNT_FLOAT32;
int iRank = 1;
int iCompress = NX_COMP_NONE;
int32 iDim[MAX_VAR_DIMS], iChunk[MAX_VAR_DIMS];
int iList, iChunkDefined = 0 ;
int iRet, iStat, i;
int32 iDim[MAX_VAR_DIMS];
int iList;
int iRet, iStat;
char pError[256];
char pName[MAX_NC_NAME];
void (*ErrFunc)(void *pData, char *pErr);
@ -1006,17 +1079,8 @@
}
iRank = atoi(pParse->pToken);
break;
case CHUNK: /* chunk size for compression */
iRet = NXDIParseDim(pParse, iChunk);
if(iRet == NX_ERROR)
{
LLDdelete(iList);
return iRet;
}
iChunkDefined = 1;
break;
case DDIM:
iRet = NXDIParseDim(pParse, iDim);
iRet = NXDIParseDim (pParse, (int *) iDim);
if(iRet == NX_ERROR)
{
LLDdelete(iList);
@ -1039,15 +1103,6 @@
return iRet;
}
break;
case DLZW:
iCompress = NX_COMP_LZW;
break;
case DRLE:
iCompress = NX_COMP_RLE;
break;
case DHUF:
iCompress = NX_COMP_HUF;
break;
case DEND:
break;
default:
@ -1060,19 +1115,8 @@
}
NXDIDefToken(pParse);
}
/* whew! got all information for doing the SDS
However, if the chunk sizes for compression have not
been set, default them to the dimensions of the data set
*/
if(iChunkDefined == 0)
{
for(i = 0; i < iRank; i++)
{
iChunk[i] = iDim[i];
}
}
/* whew! got all information for doing the SDS */
/* first install dummy error handler, try open it, then
deinstall again and create if allowed
*/
@ -1092,8 +1136,7 @@
/* we need to create it, if we may */
if(pParse->iMayCreate)
{
iRet = NXcompmakedata(hfil,pName,iType, iRank,iDim,
iCompress,iChunk);
iRet = NXmakedata (hfil, pName, iType, iRank, (int *) iDim);
if(iRet != NX_OK)
{
/* a comment on this one has already been written! */
@ -1107,7 +1150,6 @@
LLDdelete(iList);
return iRet;
}
/* put attributes in */
iRet = LLDnodePtr2First(iList);
while(iRet != 0)
@ -1137,7 +1179,13 @@
}
return NX_OK;
}
#line 2400 "nxdict.w"
/*------------------------------------------------------------------------*/
#line 1544 "nxdict.w"
static int NXDIParseLink(NXhandle hfil, NXdict pDict,ParDat *pParse)
{
char pError[256];
@ -1166,8 +1214,14 @@
return NXDopenalias(hfil, pDict, pParse->pToken);
}
#line 2402 "nxdict.w"
/*------------------------------------------------------------------------*/
int NXDIDefParse(NXhandle hFil, NXdict pDict, ParDat *pParse)
#line 1034 "nxdict.w"
static int NXDIDefParse(NXhandle hFil, NXdict pDict, ParDat *pParse)
{
int iRet;
char pError[256];
@ -1217,8 +1271,14 @@
}
return NX_OK;
}
#line 2404 "nxdict.w"
/*----------------------------------------------------------------------*/
NXstatus NXDIUnwind(NXhandle hFil, int iDepth)
#line 1576 "nxdict.w"
static NXstatus NXDIUnwind(NXhandle hFil, int iDepth)
{
int i, iRet;
@ -1232,7 +1292,13 @@
}
return NX_OK;
}
#line 2406 "nxdict.w"
/*-------------------- The Data Transfer Functions ----------------------*/
#line 1597 "nxdict.w"
NXstatus NXDopendef(NXhandle hfil, NXdict dict, char *pDef)
{
NXdict pDict;
@ -1266,18 +1332,24 @@
/* do not rewind on links */
return iRet;
}
#line 2408 "nxdict.w"
/*------------------------------------------------------------------------*/
#line 1637 "nxdict.w"
NXstatus NXDopenalias(NXhandle hfil, NXdict dict, char *pAlias)
{
NXdict pDict;
int iRet;
char pDefinition[2048];
char pDefinition[1024];
pDynString pReplaced = NULL;
pDict = NXDIAssert(dict);
/* get Definition String */
iRet = NXDget(pDict,pAlias,pDefinition,2047);
iRet = NXDget(pDict,pAlias,pDefinition,1023);
if(iRet != NX_OK)
{
sprintf(pDefinition,"ERROR: alias %s not recognized",pAlias);
@ -1297,7 +1369,13 @@
DeleteDynString(pReplaced);
return iRet;
}
#line 2410 "nxdict.w"
/*------------------------------------------------------------------------*/
#line 1674 "nxdict.w"
NXstatus NXDputdef(NXhandle hFil, NXdict dict, char *pDef, void *pData)
{
NXdict pDict;
@ -1344,18 +1422,24 @@
}
return iStat;
}
#line 2412 "nxdict.w"
/*------------------------------------------------------------------------*/
#line 1725 "nxdict.w"
NXstatus NXDputalias(NXhandle hFil, NXdict dict, char *pAlias, void *pData)
{
NXdict pDict;
int iRet;
char pDefinition[2048];
char pDefinition[1024];
pDynString pReplaced = NULL;
pDict = NXDIAssert(dict);
/* get Definition String */
iRet = NXDget(pDict,pAlias,pDefinition,2047);
iRet = NXDget(pDict,pAlias,pDefinition,1023);
if(iRet != NX_OK)
{
sprintf(pDefinition,"ERROR: alias %s not recognized",pAlias);
@ -1375,7 +1459,13 @@
DeleteDynString(pReplaced);
return iRet;
}
#line 2414 "nxdict.w"
/*------------------------------------------------------------------------*/
#line 1760 "nxdict.w"
NXstatus NXDgetdef(NXhandle hFil, NXdict dict, char *pDef, void *pData)
{
NXdict pDict;
@ -1424,18 +1514,23 @@
return iStat;
}
#line 2416 "nxdict.w"
/*------------------------------------------------------------------------*/
#line 1812 "nxdict.w"
NXstatus NXDgetalias(NXhandle hFil, NXdict dict, char *pAlias, void *pData)
{
NXdict pDict;
int iRet;
char pDefinition[2048];
char pDefinition[1024];
pDynString pReplaced = NULL;
pDict = NXDIAssert(dict);
/* get Definition String */
iRet = NXDget(pDict,pAlias,pDefinition,2047);
iRet = NXDget(pDict,pAlias,pDefinition,1023);
if(iRet != NX_OK)
{
sprintf(pDefinition,"ERROR: alias %s not recognized",pAlias);
@ -1455,92 +1550,13 @@
DeleteDynString(pReplaced);
return iRet;
}
/*------------------------------------------------------------------------*/
NXstatus NXDinfodef(NXhandle hFil, NXdict dict, char *pDef, int *rank,
int dimension[], int *iType)
{
NXdict pDict;
ParDat pParse;
int iRet, i, iStat;
pDict = NXDIAssert(dict);
/* parse and act on definition string */
pParse.iMayCreate = 0;
pParse.pPtr = pDef;
pParse.iDepth = 0;
#ifdef DEFDEBUG
printf("Getting: %s\n",pDef);
#endif
iRet = NXDIDefParse(hFil,pDict,&pParse);
if(iRet == NX_ERROR)
{
/* unwind and throw up */
NXDIUnwind(hFil,pParse.iDepth);
return NX_ERROR;
}
/* only SDS can be written */
if(pParse.iTerminal != TERMSDS)
{
NXIReportError(NXpData,
"ERROR: can only write to an SDS!");
iStat = NX_ERROR;
}
else
{
/* the SDS should be open by now, read it */
iStat = NXgetinfo(hFil, rank,dimension, iType);
iRet = NXclosedata(hFil);
}
/* rewind the hierarchy */
iRet = NXDIUnwind(hFil,pParse.iDepth);
if(iRet != NX_OK)
{
return NX_ERROR;
}
return iStat;
}
#line 2418 "nxdict.w"
/*------------------------------------------------------------------------*/
NXstatus NXDinfoalias(NXhandle hFil, NXdict dict, char *pAlias, int *rank,
int dimension[], int *iType)
{
NXdict pDict;
int iRet;
char pDefinition[2048];
pDynString pReplaced = NULL;
#line 1849 "nxdict.w"
pDict = NXDIAssert(dict);
/* get Definition String */
iRet = NXDget(pDict,pAlias,pDefinition,2047);
if(iRet != NX_OK)
{
sprintf(pDefinition,"ERROR: alias %s not recognized",pAlias);
NXIReportError(NXpData,pDefinition);
return NX_ERROR;
}
/* do text replacement */
pReplaced = NXDItextreplace(dict,pDefinition);
if(!pReplaced)
{
return NX_ERROR;
}
/* call NXDgetdef */
iRet = NXDinfodef(hFil,dict,GetCharArray(pReplaced),rank,dimension,iType);
DeleteDynString(pReplaced);
return iRet;
}
/*------------------------------------------------------------------------*/
NXstatus NXDdeflink(NXhandle hFil, NXdict dict,
char *pTarget, char *pVictim)
{
@ -1629,7 +1645,7 @@
NXstatus NXDaliaslink(NXhandle hFil, NXdict dict,
char *pTarget, char *pVictim)
{
char pTargetDef[2048], pVictimDef[2048];
char pTargetDef[1024], pVictimDef[1024];
int iRet;
NXdict pDict;
pDynString pRep1 = NULL, pRep2 = NULL;
@ -1637,7 +1653,7 @@
pDict = NXDIAssert(dict);
/* get Target Definition String */
iRet = NXDget(pDict,pTarget,pTargetDef,2047);
iRet = NXDget(pDict,pTarget,pTargetDef,1023);
if(iRet != NX_OK)
{
sprintf(pTargetDef,"ERROR: alias %s not recognized",pTarget);
@ -1646,7 +1662,7 @@
}
/* get Victim definition string */
iRet = NXDget(pDict,pVictim,pVictimDef,2047);
iRet = NXDget(pDict,pVictim,pVictimDef,1023);
if(iRet != NX_OK)
{
sprintf(pTargetDef,"ERROR: alias %s not recognized",pTarget);
@ -1672,6 +1688,14 @@
DeleteDynString(pRep2);
return iRet;
}
#line 2420 "nxdict.w"
/*-----------------------------------------------------------------------*/
#line 1986 "nxdict.w"
/*-------------------------------------------------------------------------*/
static void SNXFormatTime(char *pBuffer, int iBufLen)
{
@ -1682,7 +1706,7 @@
iDate = time(NULL);
psTime = localtime(&iDate);
memset(pBuffer,0,iBufLen);
strftime(pBuffer,iBufLen,"%Y-%m-%d %H:%M:%S",psTime);
strftime(pBuffer,iBufLen,"%Y-%d-%m %H:%M:%S",psTime);
}
/*--------------------------------------------------------------------------*/
NXstatus NXUwriteglobals(NXhandle pFile,
@ -1697,28 +1721,26 @@
char pBueffel[512];
int iStat;
/* store global attributes, now done by NXopen
/* store global attributes */
iStat = NXputattr(pFile,"file_name",filename,
strlen(filename)+1,NX_CHAR);
strlen(filename)+1,DFNT_INT8);
if(iStat == NX_ERROR)
{
return NX_ERROR;
}
*/
/* write creation time, now done by NXopen
/* write creation time */
SNXFormatTime(pBueffel,512);
iStat = NXputattr(pFile,"file_time",pBueffel,
strlen(pBueffel)+1,NX_CHAR);
strlen(pBueffel)+1,DFNT_INT8);
if(iStat == NX_ERROR)
{
return NX_ERROR;
}
*/
/* instrument name */
iStat = NXputattr(pFile,"instrument",instrument,
strlen(instrument)+1,NX_CHAR);
strlen(instrument)+1,DFNT_INT8);
if(iStat == NX_ERROR)
{
return iStat;
@ -1726,7 +1748,7 @@
/* owner */
iStat = NXputattr(pFile,"owner",owner,
strlen(owner)+1,NX_CHAR);
strlen(owner)+1,DFNT_INT8);
if(iStat == NX_ERROR)
{
return iStat;
@ -1734,7 +1756,7 @@
/* Adress */
iStat = NXputattr(pFile,"owner_adress",adress,
strlen(adress)+1,NX_CHAR);
strlen(adress)+1,DFNT_INT8);
if(iStat == NX_ERROR)
{
return iStat;
@ -1742,7 +1764,7 @@
/* phone */
iStat = NXputattr(pFile,"owner_telephone_number",phone,
strlen(phone)+1,NX_CHAR);
strlen(phone)+1,DFNT_INT8);
if(iStat == NX_ERROR)
{
return iStat;
@ -1750,7 +1772,7 @@
/* fax */
iStat = NXputattr(pFile,"owner_fax_number",fax,
strlen(fax)+1,NX_CHAR);
strlen(fax)+1,DFNT_INT8);
if(iStat == NX_ERROR)
{
return iStat;
@ -1758,14 +1780,20 @@
/* email */
iStat = NXputattr(pFile,"owner_email",email,
strlen(email)+1,NX_CHAR);
strlen(email)+1,DFNT_INT8);
if(iStat == NX_ERROR)
{
return iStat;
}
return NX_OK;
}
#line 2422 "nxdict.w"
/*-----------------------------------------------------------------------*/
#line 2082 "nxdict.w"
NXstatus NXUentergroup(NXhandle hFil, char *name, char *class)
{
void (*ErrFunc)(void *pData, char *pErr);
@ -1800,7 +1828,13 @@
}
return NX_OK;
}
#line 2424 "nxdict.w"
/*-----------------------------------------------------------------------*/
#line 2119 "nxdict.w"
NXstatus NXUenterdata(NXhandle hFil, char *label, int datatype,
int rank, int dim[], char *pUnits)
{
@ -1843,7 +1877,13 @@
}
return NX_OK;
}
#line 2426 "nxdict.w"
/*-----------------------------------------------------------------------*/
#line 2165 "nxdict.w"
NXstatus NXUallocSDS(NXhandle hFil, void **pData)
{
int iDIM[MAX_VAR_DIMS];
@ -1873,8 +1913,6 @@
lLength *= sizeof(float64);
break;
case DFNT_INT8:
case DFNT_CHAR:
case DFNT_UCHAR8:
lLength *= sizeof(int8);
break;
case DFNT_UINT8:
@ -1905,10 +1943,15 @@
NXIReportError(NXpData,"ERROR: memory exhausted in NXUallocSDS");
return NX_ERROR;
}
memset(*pData,0,lLength);
return NX_OK;
}
#line 2428 "nxdict.w"
/*----------------------------------------------------------------------*/
#line 2229 "nxdict.w"
NXstatus NXUfreeSDS(void **pData)
{
free(*pData);
@ -1916,3 +1959,5 @@
return NX_OK;
}
#line 2430 "nxdict.w"