- Fixed a few problems with hklscan

- Added transfer of zipped data to conman.c, histogram memory software
  in order to support the TRICS status display.
- Upgraded TRICS data file writing.
- First installment of triple axis spectrometer support: initialization of
  data structures and an implementation of the MAD dr(ive) command.
This commit is contained in:
cvs
2000-11-21 08:16:46 +00:00
parent f9a31d2065
commit e83d3e6946
39 changed files with 5301 additions and 563 deletions

View File

@@ -12,6 +12,8 @@
copyright: see copyright.h
Mark Koennecke, April 1998
Revised: Mark Koennecke, October 2000
----------------------------------------------------------------------------*/
#include <stdlib.h>
#include <assert.h>
@@ -30,12 +32,17 @@
#include "udpquieck.h"
#include "nextrics.h"
#define DET1X 128 /* x -length of detector 1 */
#define DET1Y 128 /* y-length of detector 1 */
#define DET1X 256 /* x -length of detector 1 */
#define DET1Y 256 /* y-length of detector 1 */
#define DET1XS 2 /* pixel size in x of detector 1 */
#define DET1YS 2 /* pixel size in y of detector 1 */
#define DET1DESC "Non existent Detector"
#define DETAMAX 128 /* maximum length of pixelsize array */
#define DETAMAX 256 /* maximum length of pixelsize array */
/* histogram memory names */
#define HM1 "hm1"
#define HM2 "hm2"
#define HM3 "hm3"
/*------------------------ the data structure ----------------------------*/
typedef struct __NexTrics {
@@ -44,10 +51,14 @@
char *pFileRoot;
pDataNumber pDanu;
NXdict pDict;
pHistMem pHistogram;
pHistMem pHistogram1, pHistogram2, pHistogram3;
int iFirst;
int iFrameNum;
pICallBack pCall;
} NexTrics;
/* event type */
#define NEWFRAME 1166
/*----------------------------------------------------------------------*/
pNexTrics CreateNexTrics(pDataNumber pNum, char *pRoot, char *pDict,
SicsInterp *pSics)
@@ -64,9 +75,10 @@
}
memset(pNew,0,sizeof(NexTrics));
/* new object descriptor */
pNew->pDes = CreateDescriptor("NexTrics");
if(!pNew->pDes)
/* new object descriptor and callback interface */
pNew->pDes = CreateDescriptor(HM1);
pNew->pCall = CreateCallBackInterface();
if(!pNew->pDes || !pNew->pCall)
{
free(pNew);
return NULL;
@@ -83,14 +95,33 @@
pNew->pDanu = pNum;
/* find things in interpreter */
pCom = FindCommand(pSics,"banana");
pCom = FindCommand(pSics,HM1);
if(!pCom)
{
DeleteNexTrics(pNew);
return NULL;
}
pNew->pHistogram = (pHistMem)pCom->pData;
pNew->pHistogram1 = (pHistMem)pCom->pData;
pCom = FindCommand(pSics,HM2);
if(pCom)
{
pNew->pHistogram2 = (pHistMem)pCom->pData;
}
else
{
pNew->pHistogram2 = NULL;
}
pCom = FindCommand(pSics,HM3);
if(pCom)
{
pNew->pHistogram3 = (pHistMem)pCom->pData;
}
else
{
pNew->pHistogram3 = NULL;
}
pNew->iFirst = 1;
pNew->iFrameNum = 0;
return pNew;
}
@@ -114,6 +145,9 @@
if(self->pDict)
NXDclose(self->pDict,NULL);
if(self->pCall)
DeleteCallBackInterface(self->pCall);
free(self);
}
@@ -215,7 +249,7 @@
}
/* write counting parameters */
eMode = GetHistCountMode(self->pHistogram);
eMode = GetHistCountMode(self->pHistogram1);
if(eMode == eTimer)
{
strcpy(pBueffel,"Timer");
@@ -225,14 +259,14 @@
strcpy(pBueffel,"Monitor");
}
NXDputalias(hfil,self->pDict,"framemode",pBueffel);
fVal = GetHistPreset(self->pHistogram);
fVal = GetHistPreset(self->pHistogram1);
NXDputalias(hfil,self->pDict,"framepreset",&fVal);
lVal = GetHistMonitor(self->pHistogram,1,pCon);
lVal = GetHistMonitor(self->pHistogram1,1,pCon);
iVal = (int32)lVal;
NXDputalias(hfil,self->pDict,"framemonitor",&iVal);
/* write detector1 histogram */
GetHistogram(self->pHistogram,pCon,0,0,DET1X*DET1Y,lData,DET1X*DET1Y*sizeof(HistInt));
GetHistogram(self->pHistogram1,pCon,0,0,DET1X*DET1Y,lData,DET1X*DET1Y*sizeof(HistInt));
NXDputalias(hfil,self->pDict,"framecounts",lData);
/* the NXdata links */
@@ -274,7 +308,8 @@
/* make sure: first frame */
NXDupdate(self->pDict,"framename","frame0000");
self->iFrameNum = 0;
/* title */
pVar = NULL;
pVar = FindVariable(pServ->pSics,"title");
@@ -308,7 +343,7 @@
{
SCWrite(pCon,"ERROR: failed to write source name",eError);
}
strcpy(pBueffel,"Continous flux spallation source");
strcpy(pBueffel,"Spallation Neutron Source");
iRet = NXDputalias(hfil,self->pDict,"stype",pBueffel);
if(iRet != NX_OK)
{
@@ -510,6 +545,8 @@
{
SCWrite(pCon,"ERROR: failed to write initial frame number",eError);
}
self->iFrameNum = 1;
InvokeCallBack(self->pCall, NEWFRAME,&(self->iFrameNum));
self->iFirst = 0;
@@ -552,6 +589,8 @@
sprintf(pBueffel,"frame%4.4d", iFrameNum);
NXDupdate(self->pDict,"framename",pBueffel);
iFrameNum++;
self->iFrameNum++;
InvokeCallBack(self->pCall, NEWFRAME,&(self->iFrameNum));
iRet = NXDputalias(hfil,self->pDict,"fnum",&iFrameNum);
if(iRet != NX_OK)
{
@@ -675,6 +714,8 @@
pCon);
self->iFirst = 1;
self->iFrameNum = 0;
InvokeCallBack(self->pCall, NEWFRAME,&(self->iFrameNum));
/* close the file and go */
NXclose(&hfil);
@@ -692,7 +733,6 @@
/* concat with data root and check for existence */
sprintf(pBueffel,"%s/%s",self->pFileRoot,filename);
iRet = NXopen(pBueffel,NXACC_RDWR,&hfil);
NXclose(&hfil);
if(iRet != NX_OK)
{
return 0;
@@ -714,6 +754,8 @@
{
self->iFirst = 0;
}
self->iFrameNum = iFrameNum;
InvokeCallBack(self->pCall, NEWFRAME,&(self->iFrameNum));
return 1;
}
/*--------------------------------------------------------------------------*/
@@ -735,13 +777,122 @@
return iRet;
}
/*-------------------------------------------------------------------------*/
static int FrameInterest(int iEvent, void *pEvent, void *pUser)
{
SConnection *pCon = NULL;
int *iFrame;
char pBueffel[512];
if(iEvent != NEWFRAME)
{
return 0;
}
pCon = (SConnection *)pUser;
iFrame = (int *)pEvent;
assert(pCon);
sprintf(pBueffel,"framenumber = %d",*iFrame);
SCWrite(pCon,pBueffel,eWarning);
return 1;
}
/*-------------------------------------------------------------------------
NexusGetFrame opens a TRICS NeXus file and retrieves a frame for the
specified detector from it. This is a specila feature for the
status display.
---------------------------------------------------------------------------*/
static int NexusGetFrame(SConnection *pCon, pNexTrics self,
int iDetector, int iFrame)
{
char pBueffel[132];
int iRet;
NXhandle hfil;
HistInt *lData = NULL;
/* do a few range checks */
if(iDetector < 1 || iDetector > 3)
{
sprintf(pBueffel,"ERROR: unknown detector %d requested",iDetector);
return 0;
}
if(iFrame < 0 || iFrame >= self->iFrameNum)
{
sprintf(pBueffel,"ERROR: farme %d not yet written",iDetector);
return 0;
}
/* open file */
iRet = NXopen(self->pCurrentFile,NXACC_READ,&hfil);
if(iRet != NX_OK)
{
sprintf(pBueffel,"ERROR: cannot open %s",self->pCurrentFile);
SCWrite(pCon,pBueffel,eError);
return 0;
}
/* open groups */
sprintf(pBueffel,"frame%4.4d",iFrame);
iRet = NXopengroup(hfil,pBueffel,"NXentry");
if(iRet != NX_OK)
{
sprintf(pBueffel,"ERROR: frame %d not found in %s",iFrame,
self->pCurrentFile);
SCWrite(pCon,pBueffel,eError);
NXclose(&hfil);
return 0;
}
sprintf(pBueffel,"detector%1.1d",iDetector);
iRet = NXopengroup(hfil,pBueffel,"NXdata");
if(iRet != NX_OK)
{
sprintf(pBueffel,"ERROR: detector %d not found in %s",iFrame,
self->pCurrentFile);
SCWrite(pCon,pBueffel,eError);
NXclose(&hfil);
return 0;
}
iRet = NXopendata(hfil,"counts");
if(iRet != NX_OK)
{
SCWrite(pCon,"ERROR: no counts found, file corrupted",eError);
NXclose(&hfil);
return 0;
}
/* read data */
lData = (HistInt *)malloc(DET1X*DET1Y*sizeof(HistInt));
if(!lData)
{
SCWrite(pCon,"ERROR: out of memory in NexusGetFrame",eError);
NXclose(&hfil);
return 0;
}
memset(lData,0,DET1X*DET1Y*sizeof(HistInt));
iRet = NXgetdata(hfil,lData);
if(iRet != NX_OK)
{
SCWrite(pCon,"ERROR: failed to read data",eError);
NXclose(&hfil);
return 0;
}
/* send it */
sprintf(pBueffel,"detector%1.1d",iDetector);
SCWriteZipped(pCon,pBueffel,lData,DET1X*DET1Y*sizeof(HistInt));
/* clean up */
NXclose(&hfil);
free(lData);
return 1;
}
/*---------------------------------------------------------------------------*/
int NexTricsAction(SConnection *pCon, SicsInterp *pSics, void *pData,
int argc, char *argv[])
{
pNexTrics self;
char pBueffel[1024];
int iRet;
int iRet, iDet, iFrame;
long lID;
self = (pNexTrics)pData;
assert(self);
@@ -778,6 +929,33 @@
SCWrite(pCon,pBueffel,eValue);
return 1;
}
else if(strcmp(argv[1],"oldframe") == 0)
{
if(argc < 4)
{
SCWrite(pCon,"ERROR: insufficient number of arguments to oldframe",
eError);
return 0;
}
iDet = atoi(argv[2]);
iFrame = atoi(argv[3]);
iRet = NexusGetFrame(pCon,self,iDet, iFrame);
return 1;
}
else if(strcmp(argv[1],"interest") == 0)
{
lID = RegisterCallback(self->pCall, NEWFRAME, FrameInterest,
pCon, NULL);
SCRegister(pCon,pSics, self->pCall,lID);
SCSendOK(pCon);
return 1;
}
else if(strcmp(argv[1],"framenum") == 0)
{
sprintf(pBueffel,"framenumber = %d",self->iFrameNum);
SCWrite(pCon,pBueffel,eValue);
return 1;
}
else if(strcmp(argv[1],"dumpframe") == 0)
{
if(!SCMatchRights(pCon,usUser))
@@ -813,3 +991,4 @@
SCWrite(pCon,pBueffel,eError);
return 0;
}