- Dokumentation updates

- Fixed bad file generated through nuweb
- fixed problems in synchronize.c
- New file writing scheme implemented
- Changes to hkl
This commit is contained in:
cvs
2003-12-23 15:54:50 +00:00
parent 3ce5573ea7
commit fcfb569518
5 changed files with 461 additions and 276 deletions

View File

@ -958,6 +958,15 @@ void SCSetWriteFunc(SConnection *self, writeFunc x)
return 0; return 0;
} }
/*
do nothing if no data
*/
if(pName == NULL || pData == NULL)
{
SCWrite(self,"ERROR: no data to write in SCWriteZiped",eError);
return 0;
}
/* initialize the compression stuff */ /* initialize the compression stuff */
compStream.zalloc = (alloc_func)NULL; compStream.zalloc = (alloc_func)NULL;
compStream.zfree = (free_func)NULL; compStream.zfree = (free_func)NULL;

242
danu.c
View File

@ -4,7 +4,12 @@
Implementation file for the data number module. Implementation file for the data number module.
Mark Koennecke, Juli 1997 Mark Koennecke, Juli 1997
Added callbacks, stepping to next thousand
Mark Koennecke, December 2003
Copyright: Copyright:
Labor fuer Neutronenstreuung Labor fuer Neutronenstreuung
@ -38,18 +43,87 @@
#include <string.h> #include <string.h>
#include <stdlib.h> #include <stdlib.h>
#include <stdio.h> #include <stdio.h>
#include <math.h>
#include <time.h> #include <time.h>
#include <assert.h> #include <assert.h>
#include "fortify.h" #include "fortify.h"
#include "conman.h" #include "sics.h"
#include "obdes.h"
#include "danu.h" #include "danu.h"
/* ------------------ the data structure ----------------------------------*/ /* ------------------ the data structure ----------------------------------*/
typedef struct __DataNumber { typedef struct __DataNumber {
pObjectDescriptor pDes; pObjectDescriptor pDes;
pICallBack pCall;
char *pFileName; char *pFileName;
} DataNumber; } DataNumber;
/*----------------------------------------------------------------------*/
static int readDataNumber(pDataNumber self)
{
FILE *fd = NULL;
int iNum = 0;
/* open file */
fd = fopen(self->pFileName,"r");
if(!fd)
{
return -1;
}
/* get and increment number */
fscanf(fd,"%d",&iNum);
fclose(fd);
return iNum;
}
/*-----------------------------------------------------------------------*/
static int writeDataNumber(pDataNumber self, int iNum)
{
FILE *fd = NULL;
/* reopen for rewriting */
fd = fopen(self->pFileName,"w");
if(fd == NULL)
{
return -1;
}
/* write file and leave */
fprintf(fd," %d \n",iNum);
fprintf(fd,"NEVER, EVER modify or delete this file\n");
fprintf(fd,
"You'll risk eternal damnation and a reincarnation as a cockroach!|n");
fclose(fd);
return 1;
}
/*------------------- The CallBack function for interest ------------------*/
static int InterestCallback(int iEvent, void *pEvent, void *pUser)
{
pDataNumber self = NULL;
SConnection *pCon = NULL;
char pBueffel[132];
int iNum;
if(iEvent != VALUECHANGE)
{
return 1;
}
assert(pEvent);
assert(pUser);
pCon = (SConnection *)pUser;
self = (pDataNumber)pEvent;
/*
read number
*/
iNum = readDataNumber(self);
if(iNum > 0)
{
snprintf(pBueffel,131,"sicsdatanumber = %d", iNum);
SCWrite(pCon,pBueffel,eValue);
}
return 1;
}
/*-------------------------------------------------------------------------*/ /*-------------------------------------------------------------------------*/
pDataNumber CreateDataNumber(char *pFileName) pDataNumber CreateDataNumber(char *pFileName)
{ {
@ -64,7 +138,8 @@
memset(pNew,0,sizeof(DataNumber)); memset(pNew,0,sizeof(DataNumber));
pNew->pDes = CreateDescriptor("DataNumber"); pNew->pDes = CreateDescriptor("DataNumber");
if(!pNew->pDes) pNew->pCall = CreateCallBackInterface();
if(!pNew->pDes || !pNew->pCall)
{ {
free(pNew); free(pNew);
return NULL; return NULL;
@ -95,6 +170,11 @@
{ {
DeleteDescriptor(self->pDes); DeleteDescriptor(self->pDes);
} }
if(self->pCall)
{
DeleteCallBackInterface(self->pCall);
self->pCall = NULL;
}
if(self->pFileName) if(self->pFileName)
{ {
free(self->pFileName); free(self->pFileName);
@ -109,36 +189,26 @@
time_t iTime; time_t iTime;
struct tm *psTime; struct tm *psTime;
/* open file */
fd = fopen(self->pFileName,"r");
if(!fd)
{
return -1;
}
/* get and increment number */
fscanf(fd,"%d",&iNum);
iNum++;
fclose(fd);
/* reopen for rewriting */ iNum = readDataNumber(self);
fd = fopen(self->pFileName,"w"); if(iNum < 0)
if(fd == NULL)
{ {
return -1; return iNum;
} }
/* write file and leave */ iNum++;
fprintf(fd," %d \n",iNum);
fprintf(fd,"NEVER, EVER modify or delete this file\n");
fprintf(fd,"You'll risk eternal damnation and a reincarnation as a cockroach!|n");
fclose(fd);
/* get year */ /* get year */
iTime = time(NULL); iTime = time(NULL);
psTime = localtime(&iTime); psTime = localtime(&iTime);
*iYear = psTime->tm_year + 1900; *iYear = psTime->tm_year + 1900;
if(writeDataNumber(self,iNum) < 0)
{
return -1;
}
InvokeCallBack(self->pCall, VALUECHANGE, self);
return iNum; return iNum;
} }
@ -146,34 +216,55 @@
int DecrementDataNumber(pDataNumber self) int DecrementDataNumber(pDataNumber self)
{ {
FILE *fd = NULL; FILE *fd = NULL;
int iNum; int iNum, currentThousand;
/* open file */
fd = fopen(self->pFileName,"r");
if(!fd)
{
return -1;
}
/* get and decrement number */
fscanf(fd,"%d",&iNum);
iNum--;
if(iNum < 0)
iNum = 0;
fclose(fd);
/* reopen for rewriting */ iNum = readDataNumber(self);
fd = fopen(self->pFileName,"w"); if(iNum < 0)
{
/* write file and leave */ return iNum;
fprintf(fd," %d \n",iNum); }
fprintf(fd,"NEVER, EVER modify or delete this file\n");
fprintf(fd,"You'll risk eternal damnation and a reincarnation as a cockroach!|n"); /*
fclose(fd); decrement DataNumber with restrictions:
- not at all lower 0
- do not understep a thousand boundary
*/
currentThousand = (int)floor(iNum/1000.);
iNum--;
if((int)floor(iNum/1000.) < currentThousand)
{
iNum++;
}
if(writeDataNumber(self,iNum) < 0)
{
return -1;
}
return iNum; return iNum;
} }
/*------------------------------------------------------------------------*/
int NewThousand(pDataNumber self)
{
int iNum, currentThousand;
iNum = readDataNumber(self);
if(iNum < 0)
{
return iNum;
}
/* set to next thousand number */
currentThousand = (int)floor(iNum/1000.);
iNum = (currentThousand + 1)*1000;
if(writeDataNumber(self,iNum) < 0)
{
return -1;
}
return iNum;
}
/*-------------------------------------------------------------------------*/ /*-------------------------------------------------------------------------*/
int DNWrapper(SConnection *pCon, SicsInterp *pSics, void *pData, int DNWrapper(SConnection *pCon, SicsInterp *pSics, void *pData,
int argc, char *argv[]) int argc, char *argv[])
@ -182,6 +273,7 @@
FILE *fd = NULL; FILE *fd = NULL;
int iNum, iYear; int iNum, iYear;
char pBueffel[512]; char pBueffel[512];
long lID;
self = (pDataNumber)pData; self = (pDataNumber)pData;
assert(self); assert(self);
@ -190,18 +282,16 @@
argtolower(argc,argv); argtolower(argc,argv);
if(argc < 2) /* value request */ if(argc < 2) /* value request */
{ {
fd = fopen(self->pFileName,"r"); iNum = readDataNumber(self);
if(!fd) if(iNum < 0)
{ {
sprintf(pBueffel,"ERROR: cannot open file %s",self->pFileName); sprintf(pBueffel,"ERROR: cannot open file %s",self->pFileName);
SCWrite(pCon,pBueffel,eError); SCWrite(pCon,pBueffel,eError);
return 0; return 0;
} }
fscanf(fd,"%d",&iNum); sprintf(pBueffel,"%s = %d",argv[0],iNum);
fclose(fd); SCWrite(pCon,pBueffel,eValue);
sprintf(pBueffel,"%s = %d",argv[0],iNum); return 1;
SCWrite(pCon,pBueffel,eValue);
return 1;
} }
if(strcmp(argv[1],"incr") == 0) if(strcmp(argv[1],"incr") == 0)
@ -219,6 +309,38 @@
return 0; return 0;
} }
} }
if(strcmp(argv[1],"nextthousand") == 0)
{
if(!SCMatchRights(pCon,usMugger))
{
return 0;
}
iNum = NewThousand(self);
if(iNum > 0)
{
SCSendOK(pCon);
return 1;
}
else
{
sprintf(pBueffel,"ERROR: cannot increment %s",argv[0]);
SCWrite(pCon,pBueffel,eError);
return 0;
}
}
if(strcmp(argv[1],"interest") == 0)
{
lID = RegisterCallback(self->pCall, VALUECHANGE, InterestCallback,
pCon, NULL);
SCRegister(pCon,pSics, self->pCall,lID);
SCSendOK(pCon);
return 1;
}
if(strcmp(argv[1],"uninterest") == 0)
{
RemoveCallback2(self->pCall,pCon);
SCSendOK(pCon);
}
sprintf(pBueffel,"ERROR: unknown command %s supplied to %s", sprintf(pBueffel,"ERROR: unknown command %s supplied to %s",
argv[1], argv[0]); argv[1], argv[0]);

385
nxdict.c
View File

@ -1,5 +1,6 @@
#line 2264 "nxdict.w"
/*--------------------------------------------------------------------------- /*---------------------------------------------------------------------------
Nexus Dictionary API implementation file. Nexus Dictionary API implementation file.
@ -20,8 +21,17 @@
August, 1997 August, 1997
Version: 1.0 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 <stdlib.h>
#include <stdio.h> #include <stdio.h>
#include <assert.h> #include <assert.h>
@ -41,14 +51,13 @@
extern void *NXpData; extern void *NXpData;
extern void (*NXIReportError)(void *pData, char *pBuffer); extern void (*NXIReportError)(void *pData, char *pBuffer);
/*--------------------------------------------------------------------------*/ /*--------------------------------------------------------------------------*/
#define DEFDEBUG 1 /* #define DEFDEBUG 1 */
/* define DEFDEBUG when you wish to print your definition strings before /* define DEFDEBUG when you wish to print your definition strings before
action. This can help a lot to resolve mysteries when working with action. This can help a lot to resolve mysteries when working with
dictionaries. dictionaries.
*/ */
/*-------------------------------------------------------------------------*/ /*-------------------------------------------------------------------------*/
#line 362 "nxdict.w"
typedef struct __NXdict typedef struct __NXdict
{ {
@ -58,7 +67,6 @@
/*------------------ verbosity level -------------------------------------*/ /*------------------ verbosity level -------------------------------------*/
static int iVerbosity = 0 ; static int iVerbosity = 0 ;
#line 2311 "nxdict.w"
/*-------------------------------------------------------------------------*/ /*-------------------------------------------------------------------------*/
static char *NXDIReadFile(FILE *fd) static char *NXDIReadFile(FILE *fd)
@ -100,7 +108,6 @@
} }
/*--------------------------------------------------------------------------*/ /*--------------------------------------------------------------------------*/
#line 490 "nxdict.w"
#define FWORD 1 #define FWORD 1
#define FHASH 2 #define FHASH 2
@ -173,11 +180,9 @@
} }
#line 2351 "nxdict.w"
/*------------------------------------------------------------------------*/ /*------------------------------------------------------------------------*/
#line 566 "nxdict.w"
#define AMODE 0 #define AMODE 0
#define DMODE 1 #define DMODE 1
@ -266,7 +271,6 @@
} }
} }
#line 2353 "nxdict.w"
/*--------------------------------------------------------------------------*/ /*--------------------------------------------------------------------------*/
NXstatus NXDinitfromfile(char *filename, NXdict *pData) NXstatus NXDinitfromfile(char *filename, NXdict *pData)
@ -277,7 +281,6 @@
char pError[512]; char pError[512];
#line 383 "nxdict.w"
/* allocate a new NXdict structure */ /* allocate a new NXdict structure */
if(iVerbosity == NXalot) if(iVerbosity == NXalot)
@ -302,10 +305,6 @@
} }
#line 2362 "nxdict.w"
#line 410 "nxdict.w"
/* is there a file name argument */ /* is there a file name argument */
if(filename == NULL) if(filename == NULL)
@ -318,10 +317,6 @@
return NX_OK; return NX_OK;
} }
#line 2363 "nxdict.w"
#line 424 "nxdict.w"
fd = fopen(filename,"rb"); fd = fopen(filename,"rb");
if(!fd) if(!fd)
@ -334,12 +329,6 @@
} }
#line 2364 "nxdict.w"
#line 444 "nxdict.w"
/* read the file contents */ /* read the file contents */
if(iVerbosity == NXalot) if(iVerbosity == NXalot)
{ {
@ -363,8 +352,6 @@
} }
NXDIParse(pBuffer, pNew->pDictionary); NXDIParse(pBuffer, pNew->pDictionary);
#line 2365 "nxdict.w"
if(iVerbosity == NXalot) if(iVerbosity == NXalot)
{ {
@ -376,8 +363,6 @@
} }
/*--------------------------------------------------------------------------*/ /*--------------------------------------------------------------------------*/
#line 660 "nxdict.w"
NXdict NXDIAssert(NXdict handle) NXdict NXDIAssert(NXdict handle)
{ {
NXdict self = NULL; NXdict self = NULL;
@ -387,12 +372,9 @@
return self; return self;
} }
#line 2376 "nxdict.w"
/*-------------------------------------------------------------------------*/ /*-------------------------------------------------------------------------*/
#line 671 "nxdict.w"
NXstatus NXDclose(NXdict handle, char *filename) NXstatus NXDclose(NXdict handle, char *filename)
{ {
NXdict self; NXdict self;
@ -441,12 +423,8 @@
return NX_OK; return NX_OK;
} }
#line 2378 "nxdict.w"
/*------------------------------------------------------------------------*/ /*------------------------------------------------------------------------*/
#line 724 "nxdict.w"
NXstatus NXDadd(NXdict handle, char *alias, char *pDef) NXstatus NXDadd(NXdict handle, char *alias, char *pDef)
{ {
NXdict self; NXdict self;
@ -491,14 +469,7 @@
} }
return NX_OK; return NX_OK;
} }
#line 2380 "nxdict.w"
/*-----------------------------------------------------------------------*/ /*-----------------------------------------------------------------------*/
#line 776 "nxdict.w"
#define NORMAL 1 #define NORMAL 1
#define ALIAS 2 #define ALIAS 2
pDynString NXDItextreplace(NXdict handle, char *pDefString) pDynString NXDItextreplace(NXdict handle, char *pDefString)
@ -595,23 +566,12 @@
return NX_OK; return NX_OK;
} }
#line 2382 "nxdict.w"
/*------------------- The Defintion String Parser -----------------------*/ /*------------------- The Defintion String Parser -----------------------*/
/*------- Data structures */ /*------- Data structures */
#line 886 "nxdict.w"
typedef struct { typedef struct {
char pText[20]; char pText[20];
int iCode; int iCode;
} TokDat; } TokDat;
#line 2385 "nxdict.w"
#line 896 "nxdict.w"
#define TERMSDS 100 #define TERMSDS 100
#define TERMVG 200 #define TERMVG 200
#define TERMLINK 300 #define TERMLINK 300
@ -625,32 +585,15 @@
int iTerminal; int iTerminal;
} ParDat; } ParDat;
#line 2386 "nxdict.w"
#line 1101 "nxdict.w"
static void DummyError(void *pData, char *pError) static void DummyError(void *pData, char *pError)
{ {
return; return;
} }
#line 2387 "nxdict.w"
#line 1215 "nxdict.w"
typedef struct { typedef struct {
char name[256]; char name[256];
char value[256]; char value[256];
}AttItem; }AttItem;
#line 2388 "nxdict.w"
/*------------------------------------------------------------------------*/
#line 918 "nxdict.w"
/*---------------- Token name defines ---------------------------*/ /*---------------- Token name defines ---------------------------*/
#define DSLASH 0 #define DSLASH 0
#define DKOMMA 1 #define DKOMMA 1
@ -665,10 +608,14 @@
#define DCLOSE 11 #define DCLOSE 11
#define DATTR 12 #define DATTR 12
#define DEND 13 #define DEND 13
#define DLZW 14
#define DHUF 15
#define DRLE 16
#define CHUNK 17
/*----------------- Keywords ----------------------------------------*/ /*----------------- Keywords ----------------------------------------*/
static TokDat TokenList[8] = { static TokDat TokenList[12] = {
{"SDS",DSDS}, {"SDS",DSDS},
{"NXLINK",DLINK}, {"NXLINK",DLINK},
{"NXVGROUP",DGROUP}, {"NXVGROUP",DGROUP},
@ -676,7 +623,11 @@
{"-type",DTYPE}, {"-type",DTYPE},
{"-rank",DRANK}, {"-rank",DRANK},
{"-attr",DATTR}, {"-attr",DATTR},
{"",0} }; {"-chunk",CHUNK},
{"-LZW",DLZW},
{"-HUF",DHUF},
{"-RLE",DRLE},
{NULL,0} };
/*-----------------------------------------------------------------------*/ /*-----------------------------------------------------------------------*/
static void NXDIDefToken(ParDat *sStat) static void NXDIDefToken(ParDat *sStat)
@ -744,7 +695,7 @@
sStat->pToken[i] = '\0'; sStat->pToken[i] = '\0';
/*--------- try to find word in Tokenlist */ /*--------- try to find word in Tokenlist */
for(i = 0; i < 7; i++) for(i = 0; i < 10; i++)
{ {
if(strcmp(sStat->pToken,TokenList[i].pText) == 0) if(strcmp(sStat->pToken,TokenList[i].pText) == 0)
{ {
@ -759,12 +710,8 @@
} }
#line 2390 "nxdict.w"
/*------------------------------------------------------------------------*/ /*------------------------------------------------------------------------*/
#line 1114 "nxdict.w"
int NXDIParsePath(NXhandle hfil, ParDat *pParse) int NXDIParsePath(NXhandle hfil, ParDat *pParse)
{ {
int iRet, iToken; int iRet, iToken;
@ -855,12 +802,8 @@
return NX_ERROR; return NX_ERROR;
} }
#line 2392 "nxdict.w"
/*------------------------------------------------------------------------*/ /*------------------------------------------------------------------------*/
#line 1481 "nxdict.w"
static int NXDIParseAttr(ParDat *pParse, int iList) static int NXDIParseAttr(ParDat *pParse, int iList)
{ {
char pError[256]; char pError[256];
@ -919,12 +862,7 @@
return NX_OK; return NX_OK;
} }
#line 2394 "nxdict.w"
/*------------------------------------------------------------------------*/ /*------------------------------------------------------------------------*/
#line 1428 "nxdict.w"
static int NXDIParseDim(ParDat *pParse, int *iDim) static int NXDIParseDim(ParDat *pParse, int *iDim)
{ {
char pError[256]; char pError[256];
@ -972,13 +910,7 @@
} }
return NX_OK; return NX_OK;
} }
#line 2396 "nxdict.w"
/*------------------------------------------------------------------------*/ /*------------------------------------------------------------------------*/
#line 1379 "nxdict.w"
static TokDat tDatType[] = { static TokDat tDatType[] = {
{"DFNT_FLOAT32",DFNT_FLOAT32}, {"DFNT_FLOAT32",DFNT_FLOAT32},
{"DFNT_FLOAT64",DFNT_FLOAT64}, {"DFNT_FLOAT64",DFNT_FLOAT64},
@ -988,7 +920,8 @@
{"DFNT_UINT16",DFNT_UINT16}, {"DFNT_UINT16",DFNT_UINT16},
{"DFNT_INT32",DFNT_INT32}, {"DFNT_INT32",DFNT_INT32},
{"DFNT_UINT32",DFNT_UINT32}, {"DFNT_UINT32",DFNT_UINT32},
{"",0} }; {"DFNT_CHAR",DFNT_CHAR},
{NULL,-122} };
@ -1023,19 +956,15 @@
return NX_ERROR; return NX_ERROR;
} }
#line 2398 "nxdict.w"
/*-------------------------------------------------------------------------*/ /*-------------------------------------------------------------------------*/
#line 1223 "nxdict.w"
static int NXDIParseSDS(NXhandle hfil, ParDat *pParse) static int NXDIParseSDS(NXhandle hfil, ParDat *pParse)
{ {
int iType = DFNT_FLOAT32; int iType = DFNT_FLOAT32;
int iRank = 1; int iRank = 1;
int32 iDim[MAX_VAR_DIMS]; int iCompress = NX_COMP_NONE;
int iList; int32 iDim[MAX_VAR_DIMS], iChunk[MAX_VAR_DIMS];
int iRet, iStat; int iList, iChunkDefined = 0 ;
int iRet, iStat, i;
char pError[256]; char pError[256];
char pName[MAX_NC_NAME]; char pName[MAX_NC_NAME];
void (*ErrFunc)(void *pData, char *pErr); void (*ErrFunc)(void *pData, char *pErr);
@ -1079,8 +1008,17 @@
} }
iRank = atoi(pParse->pToken); iRank = atoi(pParse->pToken);
break; break;
case CHUNK: /* chunk size for compression */
iRet = NXDIParseDim(pParse, iChunk);
if(iRet == NX_ERROR)
{
LLDdelete(iList);
return iRet;
}
iChunkDefined = 1;
break;
case DDIM: case DDIM:
iRet = NXDIParseDim (pParse, (int *) iDim); iRet = NXDIParseDim(pParse, iDim);
if(iRet == NX_ERROR) if(iRet == NX_ERROR)
{ {
LLDdelete(iList); LLDdelete(iList);
@ -1103,6 +1041,15 @@
return iRet; return iRet;
} }
break; break;
case DLZW:
iCompress = NX_COMP_LZW;
break;
case DRLE:
iCompress = NX_COMP_RLE;
break;
case DHUF:
iCompress = NX_COMP_HUF;
break;
case DEND: case DEND:
break; break;
default: default:
@ -1115,8 +1062,19 @@
} }
NXDIDefToken(pParse); 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 /* first install dummy error handler, try open it, then
deinstall again and create if allowed deinstall again and create if allowed
*/ */
@ -1136,7 +1094,8 @@
/* we need to create it, if we may */ /* we need to create it, if we may */
if(pParse->iMayCreate) if(pParse->iMayCreate)
{ {
iRet = NXmakedata (hfil, pName, iType, iRank, (int *) iDim); iRet = NXcompmakedata(hfil,pName,iType, iRank,iDim,
iCompress,iChunk);
if(iRet != NX_OK) if(iRet != NX_OK)
{ {
/* a comment on this one has already been written! */ /* a comment on this one has already been written! */
@ -1150,6 +1109,7 @@
LLDdelete(iList); LLDdelete(iList);
return iRet; return iRet;
} }
/* put attributes in */ /* put attributes in */
iRet = LLDnodePtr2First(iList); iRet = LLDnodePtr2First(iList);
while(iRet != 0) while(iRet != 0)
@ -1179,13 +1139,7 @@
} }
return NX_OK; return NX_OK;
} }
#line 2400 "nxdict.w"
/*------------------------------------------------------------------------*/ /*------------------------------------------------------------------------*/
#line 1544 "nxdict.w"
static int NXDIParseLink(NXhandle hfil, NXdict pDict,ParDat *pParse) static int NXDIParseLink(NXhandle hfil, NXdict pDict,ParDat *pParse)
{ {
char pError[256]; char pError[256];
@ -1214,14 +1168,8 @@
return NXDopenalias(hfil, pDict, pParse->pToken); 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; int iRet;
char pError[256]; char pError[256];
@ -1271,14 +1219,8 @@
} }
return NX_OK; 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; int i, iRet;
@ -1292,13 +1234,7 @@
} }
return NX_OK; return NX_OK;
} }
#line 2406 "nxdict.w"
/*-------------------- The Data Transfer Functions ----------------------*/ /*-------------------- The Data Transfer Functions ----------------------*/
#line 1597 "nxdict.w"
NXstatus NXDopendef(NXhandle hfil, NXdict dict, char *pDef) NXstatus NXDopendef(NXhandle hfil, NXdict dict, char *pDef)
{ {
NXdict pDict; NXdict pDict;
@ -1332,24 +1268,18 @@
/* do not rewind on links */ /* do not rewind on links */
return iRet; return iRet;
} }
#line 2408 "nxdict.w"
/*------------------------------------------------------------------------*/ /*------------------------------------------------------------------------*/
#line 1637 "nxdict.w"
NXstatus NXDopenalias(NXhandle hfil, NXdict dict, char *pAlias) NXstatus NXDopenalias(NXhandle hfil, NXdict dict, char *pAlias)
{ {
NXdict pDict; NXdict pDict;
int iRet; int iRet;
char pDefinition[1024]; char pDefinition[2048];
pDynString pReplaced = NULL; pDynString pReplaced = NULL;
pDict = NXDIAssert(dict); pDict = NXDIAssert(dict);
/* get Definition String */ /* get Definition String */
iRet = NXDget(pDict,pAlias,pDefinition,1023); iRet = NXDget(pDict,pAlias,pDefinition,2047);
if(iRet != NX_OK) if(iRet != NX_OK)
{ {
sprintf(pDefinition,"ERROR: alias %s not recognized",pAlias); sprintf(pDefinition,"ERROR: alias %s not recognized",pAlias);
@ -1369,13 +1299,7 @@
DeleteDynString(pReplaced); DeleteDynString(pReplaced);
return iRet; return iRet;
} }
#line 2410 "nxdict.w"
/*------------------------------------------------------------------------*/ /*------------------------------------------------------------------------*/
#line 1674 "nxdict.w"
NXstatus NXDputdef(NXhandle hFil, NXdict dict, char *pDef, void *pData) NXstatus NXDputdef(NXhandle hFil, NXdict dict, char *pDef, void *pData)
{ {
NXdict pDict; NXdict pDict;
@ -1422,24 +1346,18 @@
} }
return iStat; return iStat;
} }
#line 2412 "nxdict.w"
/*------------------------------------------------------------------------*/ /*------------------------------------------------------------------------*/
#line 1725 "nxdict.w"
NXstatus NXDputalias(NXhandle hFil, NXdict dict, char *pAlias, void *pData) NXstatus NXDputalias(NXhandle hFil, NXdict dict, char *pAlias, void *pData)
{ {
NXdict pDict; NXdict pDict;
int iRet; int iRet;
char pDefinition[1024]; char pDefinition[2048];
pDynString pReplaced = NULL; pDynString pReplaced = NULL;
pDict = NXDIAssert(dict); pDict = NXDIAssert(dict);
/* get Definition String */ /* get Definition String */
iRet = NXDget(pDict,pAlias,pDefinition,1023); iRet = NXDget(pDict,pAlias,pDefinition,2047);
if(iRet != NX_OK) if(iRet != NX_OK)
{ {
sprintf(pDefinition,"ERROR: alias %s not recognized",pAlias); sprintf(pDefinition,"ERROR: alias %s not recognized",pAlias);
@ -1459,13 +1377,7 @@
DeleteDynString(pReplaced); DeleteDynString(pReplaced);
return iRet; return iRet;
} }
#line 2414 "nxdict.w"
/*------------------------------------------------------------------------*/ /*------------------------------------------------------------------------*/
#line 1760 "nxdict.w"
NXstatus NXDgetdef(NXhandle hFil, NXdict dict, char *pDef, void *pData) NXstatus NXDgetdef(NXhandle hFil, NXdict dict, char *pDef, void *pData)
{ {
NXdict pDict; NXdict pDict;
@ -1514,23 +1426,18 @@
return iStat; return iStat;
} }
#line 2416 "nxdict.w"
/*------------------------------------------------------------------------*/ /*------------------------------------------------------------------------*/
#line 1812 "nxdict.w"
NXstatus NXDgetalias(NXhandle hFil, NXdict dict, char *pAlias, void *pData) NXstatus NXDgetalias(NXhandle hFil, NXdict dict, char *pAlias, void *pData)
{ {
NXdict pDict; NXdict pDict;
int iRet; int iRet;
char pDefinition[1024]; char pDefinition[2048];
pDynString pReplaced = NULL; pDynString pReplaced = NULL;
pDict = NXDIAssert(dict); pDict = NXDIAssert(dict);
/* get Definition String */ /* get Definition String */
iRet = NXDget(pDict,pAlias,pDefinition,1023); iRet = NXDget(pDict,pAlias,pDefinition,2047);
if(iRet != NX_OK) if(iRet != NX_OK)
{ {
sprintf(pDefinition,"ERROR: alias %s not recognized",pAlias); sprintf(pDefinition,"ERROR: alias %s not recognized",pAlias);
@ -1550,13 +1457,92 @@
DeleteDynString(pReplaced); DeleteDynString(pReplaced);
return iRet; return iRet;
} }
/*------------------------------------------------------------------------*/
#line 2418 "nxdict.w" 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 1849 "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;
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, NXstatus NXDdeflink(NXhandle hFil, NXdict dict,
char *pTarget, char *pVictim) char *pTarget, char *pVictim)
{ {
@ -1645,7 +1631,7 @@
NXstatus NXDaliaslink(NXhandle hFil, NXdict dict, NXstatus NXDaliaslink(NXhandle hFil, NXdict dict,
char *pTarget, char *pVictim) char *pTarget, char *pVictim)
{ {
char pTargetDef[1024], pVictimDef[1024]; char pTargetDef[2048], pVictimDef[2048];
int iRet; int iRet;
NXdict pDict; NXdict pDict;
pDynString pRep1 = NULL, pRep2 = NULL; pDynString pRep1 = NULL, pRep2 = NULL;
@ -1653,7 +1639,7 @@
pDict = NXDIAssert(dict); pDict = NXDIAssert(dict);
/* get Target Definition String */ /* get Target Definition String */
iRet = NXDget(pDict,pTarget,pTargetDef,1023); iRet = NXDget(pDict,pTarget,pTargetDef,2047);
if(iRet != NX_OK) if(iRet != NX_OK)
{ {
sprintf(pTargetDef,"ERROR: alias %s not recognized",pTarget); sprintf(pTargetDef,"ERROR: alias %s not recognized",pTarget);
@ -1662,7 +1648,7 @@
} }
/* get Victim definition string */ /* get Victim definition string */
iRet = NXDget(pDict,pVictim,pVictimDef,1023); iRet = NXDget(pDict,pVictim,pVictimDef,2047);
if(iRet != NX_OK) if(iRet != NX_OK)
{ {
sprintf(pTargetDef,"ERROR: alias %s not recognized",pTarget); sprintf(pTargetDef,"ERROR: alias %s not recognized",pTarget);
@ -1688,14 +1674,6 @@
DeleteDynString(pRep2); DeleteDynString(pRep2);
return iRet; return iRet;
} }
#line 2420 "nxdict.w"
/*-----------------------------------------------------------------------*/
#line 1986 "nxdict.w"
/*-------------------------------------------------------------------------*/ /*-------------------------------------------------------------------------*/
static void SNXFormatTime(char *pBuffer, int iBufLen) static void SNXFormatTime(char *pBuffer, int iBufLen)
{ {
@ -1706,7 +1684,7 @@
iDate = time(NULL); iDate = time(NULL);
psTime = localtime(&iDate); psTime = localtime(&iDate);
memset(pBuffer,0,iBufLen); memset(pBuffer,0,iBufLen);
strftime(pBuffer,iBufLen,"%Y-%d-%m %H:%M:%S",psTime); strftime(pBuffer,iBufLen,"%Y-%m-%d %H:%M:%S",psTime);
} }
/*--------------------------------------------------------------------------*/ /*--------------------------------------------------------------------------*/
NXstatus NXUwriteglobals(NXhandle pFile, NXstatus NXUwriteglobals(NXhandle pFile,
@ -1721,26 +1699,28 @@
char pBueffel[512]; char pBueffel[512];
int iStat; int iStat;
/* store global attributes */ /* store global attributes, now done by NXopen
iStat = NXputattr(pFile,"file_name",filename, iStat = NXputattr(pFile,"file_name",filename,
strlen(filename)+1,DFNT_INT8); strlen(filename)+1,NX_CHAR);
if(iStat == NX_ERROR) if(iStat == NX_ERROR)
{ {
return NX_ERROR; return NX_ERROR;
} }
*/
/* write creation time */ /* write creation time, now done by NXopen
SNXFormatTime(pBueffel,512); SNXFormatTime(pBueffel,512);
iStat = NXputattr(pFile,"file_time",pBueffel, iStat = NXputattr(pFile,"file_time",pBueffel,
strlen(pBueffel)+1,DFNT_INT8); strlen(pBueffel)+1,NX_CHAR);
if(iStat == NX_ERROR) if(iStat == NX_ERROR)
{ {
return NX_ERROR; return NX_ERROR;
} }
*/
/* instrument name */ /* instrument name */
iStat = NXputattr(pFile,"instrument",instrument, iStat = NXputattr(pFile,"instrument",instrument,
strlen(instrument)+1,DFNT_INT8); strlen(instrument)+1,NX_CHAR);
if(iStat == NX_ERROR) if(iStat == NX_ERROR)
{ {
return iStat; return iStat;
@ -1748,7 +1728,7 @@
/* owner */ /* owner */
iStat = NXputattr(pFile,"owner",owner, iStat = NXputattr(pFile,"owner",owner,
strlen(owner)+1,DFNT_INT8); strlen(owner)+1,NX_CHAR);
if(iStat == NX_ERROR) if(iStat == NX_ERROR)
{ {
return iStat; return iStat;
@ -1756,7 +1736,7 @@
/* Adress */ /* Adress */
iStat = NXputattr(pFile,"owner_adress",adress, iStat = NXputattr(pFile,"owner_adress",adress,
strlen(adress)+1,DFNT_INT8); strlen(adress)+1,NX_CHAR);
if(iStat == NX_ERROR) if(iStat == NX_ERROR)
{ {
return iStat; return iStat;
@ -1764,7 +1744,7 @@
/* phone */ /* phone */
iStat = NXputattr(pFile,"owner_telephone_number",phone, iStat = NXputattr(pFile,"owner_telephone_number",phone,
strlen(phone)+1,DFNT_INT8); strlen(phone)+1,NX_CHAR);
if(iStat == NX_ERROR) if(iStat == NX_ERROR)
{ {
return iStat; return iStat;
@ -1772,7 +1752,7 @@
/* fax */ /* fax */
iStat = NXputattr(pFile,"owner_fax_number",fax, iStat = NXputattr(pFile,"owner_fax_number",fax,
strlen(fax)+1,DFNT_INT8); strlen(fax)+1,NX_CHAR);
if(iStat == NX_ERROR) if(iStat == NX_ERROR)
{ {
return iStat; return iStat;
@ -1780,20 +1760,14 @@
/* email */ /* email */
iStat = NXputattr(pFile,"owner_email",email, iStat = NXputattr(pFile,"owner_email",email,
strlen(email)+1,DFNT_INT8); strlen(email)+1,NX_CHAR);
if(iStat == NX_ERROR) if(iStat == NX_ERROR)
{ {
return iStat; return iStat;
} }
return NX_OK; return NX_OK;
} }
#line 2422 "nxdict.w"
/*-----------------------------------------------------------------------*/ /*-----------------------------------------------------------------------*/
#line 2082 "nxdict.w"
NXstatus NXUentergroup(NXhandle hFil, char *name, char *class) NXstatus NXUentergroup(NXhandle hFil, char *name, char *class)
{ {
void (*ErrFunc)(void *pData, char *pErr); void (*ErrFunc)(void *pData, char *pErr);
@ -1828,13 +1802,7 @@
} }
return NX_OK; return NX_OK;
} }
#line 2424 "nxdict.w"
/*-----------------------------------------------------------------------*/ /*-----------------------------------------------------------------------*/
#line 2119 "nxdict.w"
NXstatus NXUenterdata(NXhandle hFil, char *label, int datatype, NXstatus NXUenterdata(NXhandle hFil, char *label, int datatype,
int rank, int dim[], char *pUnits) int rank, int dim[], char *pUnits)
{ {
@ -1877,13 +1845,7 @@
} }
return NX_OK; return NX_OK;
} }
#line 2426 "nxdict.w"
/*-----------------------------------------------------------------------*/ /*-----------------------------------------------------------------------*/
#line 2165 "nxdict.w"
NXstatus NXUallocSDS(NXhandle hFil, void **pData) NXstatus NXUallocSDS(NXhandle hFil, void **pData)
{ {
int iDIM[MAX_VAR_DIMS]; int iDIM[MAX_VAR_DIMS];
@ -1913,6 +1875,8 @@
lLength *= sizeof(float64); lLength *= sizeof(float64);
break; break;
case DFNT_INT8: case DFNT_INT8:
case DFNT_CHAR:
case DFNT_UCHAR8:
lLength *= sizeof(int8); lLength *= sizeof(int8);
break; break;
case DFNT_UINT8: case DFNT_UINT8:
@ -1943,15 +1907,10 @@
NXIReportError(NXpData,"ERROR: memory exhausted in NXUallocSDS"); NXIReportError(NXpData,"ERROR: memory exhausted in NXUallocSDS");
return NX_ERROR; return NX_ERROR;
} }
memset(*pData,0,lLength);
return NX_OK; return NX_OK;
} }
#line 2428 "nxdict.w"
/*----------------------------------------------------------------------*/ /*----------------------------------------------------------------------*/
#line 2229 "nxdict.w"
NXstatus NXUfreeSDS(void **pData) NXstatus NXUfreeSDS(void **pData)
{ {
free(*pData); free(*pData);
@ -1959,5 +1918,3 @@
return NX_OK; return NX_OK;
} }
#line 2430 "nxdict.w"

View File

@ -12,13 +12,19 @@
#include <assert.h> #include <assert.h>
#include <errno.h> #include <errno.h>
#include <tcl.h> #include <tcl.h>
#include <math.h>
#include <unistd.h> #include <unistd.h>
#include <sys/stat.h>
#include <sys/types.h>
#include <dirent.h>
#include "fortify.h" #include "fortify.h"
#include "sics.h" #include "sics.h"
#include "splitter.h" #include "splitter.h"
#include "HistMem.h" #include "HistMem.h"
#include "motor.h" #include "motor.h"
#include "counter.h" #include "counter.h"
#include "sicsvar.h"
#include "danu.h"
#include "udpquieck.h" #include "udpquieck.h"
#include "nxdict.h" #include "nxdict.h"
#include "nxscript.h" #include "nxscript.h"
@ -28,6 +34,85 @@ typedef struct {
NXhandle fileHandle; NXhandle fileHandle;
NXdict dictHandle; NXdict dictHandle;
} NXScript, *pNXScript; } NXScript, *pNXScript;
/*------------------------------------------------------------------------*/
char *makeFilename(SicsInterp *pSics, SConnection *pCon) {
pSicsVariable pPath = NULL, pPref = NULL, pEnd = NULL;
char *pRes = NULL;
int iLen, iNum, iYear, thousand;
char pNumText[10], pBueffel[256];
CommandList *pCom = NULL;
DIR *dir = NULL;
/* Try, get all the Variables */
pPath = FindVariable(pSics,"sicsdatapath");
pPref = FindVariable(pSics,"sicsdataprefix");
pCom = FindCommand(pSics,"sicsdatanumber");
pEnd = FindVariable(pSics,"sicsdatapostfix");
if( (!pPath) || (!pPref) || (!pCom) || (!pEnd) ){
SCWrite(pCon,
"ERROR: cannot read variables for automatic data file name creation",
eError);
SCWrite(pCon,
"ERROR: This is a VERY, VERY, VERY serious installation problem",
eError);
SCWrite(pCon,"ERROR: your data will be dumped into emergency.hdf",eError);
return NULL;
}
/* find length */
iLen = strlen(pPath->text) + 4; /* extra 4 for dir number */
iLen += strlen(pPref->text);
iLen += 8; /* for number + year */
iLen += strlen(pEnd->text);
iLen += 10; /* safety margin */
/* allocate memory */
pRes = (char *)malloc(iLen*sizeof(char));
if(!pRes){
SCWrite(pCon,"ERROR: no memory in makeFilename",eError);
return NULL;
}
memset(pRes,0,iLen);
/* increment the data file number */
iNum = IncrementDataNumber(pCom->pData,&iYear);
if(iNum < 0){
SCWrite(pCon,"ERROR: cannot increment data number!",eError);
SCWrite(pCon,"ERROR: your data will be dumped to emergency.hdf",eError);
free(pRes);
return NULL;
}
strcpy(pRes,pPath->text);
thousand = (int)floor(iNum/1000.);
snprintf(pNumText,9,"%3.3d",thousand);
strcat(pRes,pNumText);
/*
check for existence of directory and create if neccessary
*/
dir = opendir(pRes);
if(dir == NULL){
mkdir(pRes,S_IRWXU | S_IRGRP | S_IXGRP);
snprintf(pBueffel,255,"Creating dir: %s", pRes);
SCWrite(pCon,pBueffel,eWarning);
} else {
closedir(dir);
}
/*
build the rest of the filename
*/
strcat(pRes,"/");
strcat(pRes,pPref->text);
sprintf(pNumText,"%5.5d",iNum);
strcat(pRes,pNumText);
sprintf(pNumText,"%4.4d",iYear);
strcat(pRes,pNumText);
strcat(pRes,pEnd->text);
return pRes;
}
/*======================== Action =======================================*/ /*======================== Action =======================================*/
static int handleFileOperations(SConnection *pCon, pNXScript self, static int handleFileOperations(SConnection *pCon, pNXScript self,
int argc, char *argv[]){ int argc, char *argv[]){
@ -742,7 +827,7 @@ static void makeLink(SConnection *pCon, SicsInterp *pSics,
int NXScriptAction(SConnection *pCon, SicsInterp *pSics, void *pData, int NXScriptAction(SConnection *pCon, SicsInterp *pSics, void *pData,
int argc, char *argv[]){ int argc, char *argv[]){
pNXScript self = (pNXScript)pData; pNXScript self = (pNXScript)pData;
char *pFile = NULL;
/* /*
preliminary checks preliminary checks
*/ */
@ -756,6 +841,18 @@ int NXScriptAction(SConnection *pCon, SicsInterp *pSics, void *pData,
} }
strtolower(argv[1]); strtolower(argv[1]);
if(strcmp(argv[1],"makefilename") == 0){
pFile = makeFilename(pSics,pCon);
if(pFile != NULL){
SCWrite(pCon,pFile,eValue);
free(pFile);
return 1;
} else {
SCWrite(pCon,"ERROR: failed to create filename",eError);
return 0;
}
}
if(handleFileOperations(pCon,self,argc,argv)){ if(handleFileOperations(pCon,self,argc,argv)){
return 1; return 1;
} }

View File

@ -57,7 +57,7 @@ static void syncLogin(void)
} }
pBueffel[0] = '\0'; pBueffel[0] = '\0';
for(i = 0; i < 10; i++) for(i = 0; i < 60; i++)
{ {
memset(pRead,0,80); memset(pRead,0,80);
test = NETRead(connection,pRead,70,10*1000); test = NETRead(connection,pRead,70,10*1000);