- Enhanced and debugged histogram memory for AMOR

* added PROJECT both in HM and driver code
  * added single detector support.
- Removed several bugs in the AMOR data bit.
- Updated documentation
This commit is contained in:
cvs
2001-08-17 14:33:05 +00:00
parent a538361516
commit db6c355f44
56 changed files with 4060 additions and 426 deletions

159
nxamor.c
View File

@@ -8,6 +8,7 @@
Mark Koennecke, September 1999
Updated, Mark Koennecke, August 2001
--------------------------------------------------------------------------*/
#include <stdlib.h>
#include <assert.h>
@@ -20,6 +21,12 @@
#include "HistMem.h"
#include "counter.h"
#include "nxamor.h"
#include "obpar.h"
#include "motor.h"
#define MAXMOT 13 /* must be same as in amor2t.c */
#include "amor2t.i"
#include "amor2t.h"
/* some defines for some names */
#define AMORDICT "amor.dic"
@@ -27,19 +34,18 @@
#define SOURCENAME "Spallation source SINQ"
#define SOURCETYPE "Continous flux spallation source"
#define CHOPPERNAME "Dornier Chopper System"
/*
this is the real detector size, the one in the dictionary will be
updated from this!
/*
a pointer to amor2t which we need for a couple of parameters
*/
#define DETSIZE 128
pAmor2T pAmor = NULL;
/*------------------------------------------------------------------------*/
static void WriteDiaphragm(NXhandle hfil, NXdict hdict, int i,
SConnection *pCon)
{
char pThing[30];
sprintf(pThing,"d%1.1ddist",i);
SNXSPutVariable(pServ->pSics,pCon,hfil, hdict,pThing,pThing);
sprintf(pThing,"d%1.1dt",i);
SNXSPutMotor(pServ->pSics,pCon,hfil,hdict,pThing,pThing);
@@ -56,7 +62,7 @@
NXhandle hfil;
NXdict hdict;
int iRet;
char pBueffel[512];
char pBueffel[512], pThing[80];
CounterMode eMode;
CommandList *pCom = NULL;
float fVal;
@@ -105,6 +111,8 @@
/* first Diaphragm */
WriteDiaphragm(hfil,hdict,1,pCon);
sprintf(pThing,"d%1.1ddist",1);
SNXSPutVariable(pServ->pSics,pCon,hfil, hdict,pThing,pThing);
/* polarizing, monochromating mirror */
SNXSPutVariable(pServ->pSics,pCon,hfil, hdict,"polname",
@@ -118,9 +126,13 @@
/* second Diaphragm */
WriteDiaphragm(hfil,hdict,2,pCon);
sprintf(pThing,"d%1.1ddist",2);
SNXSPutVariable(pServ->pSics,pCon,hfil, hdict,pThing,pThing);
/* third Diaphragm */
WriteDiaphragm(hfil,hdict,3,pCon);
sprintf(pThing,"d%1.1ddist",3);
SNXSPutVariable(pServ->pSics,pCon,hfil, hdict,pThing,pThing);
/* sample table */
SNXSPutVariable(pServ->pSics,pCon,hfil, hdict,"saname",
@@ -131,9 +143,16 @@
SNXSPutMotor(pServ->pSics,pCon,hfil,hdict,"schi","sch");
SNXSPutMotor(pServ->pSics,pCon,hfil,hdict,"somega","som");
SNXSPutMotor(pServ->pSics,pCon,hfil,hdict,"stheight","soz");
fVal = ObVal(pAmor->aParameter,PARDH);
NXDputalias(hfil,hdict,"baseheight",&fVal);
/* fourth Diaphragm */
WriteDiaphragm(hfil,hdict,4,pCon);
fVal = ObVal(pAmor->aParameter,PARDD4);
NXDputalias(hfil,hdict,"d4dist",&fVal);
fVal = ObVal(pAmor->aParameter,PARD4H);
NXDputalias(hfil,hdict,"d4base",&fVal);
/* analyzer */
SNXSPutVariable(pServ->pSics,pCon,hfil, hdict,"anname",
@@ -143,9 +162,18 @@
SNXSPutMotor(pServ->pSics,pCon,hfil,hdict,"anoz","atz");
SNXSPutMotor(pServ->pSics,pCon,hfil,hdict,"anom","aom");
SNXSPutMotor(pServ->pSics,pCon,hfil,hdict,"antz","aoz");
fVal = ObVal(pAmor->aParameter,PARADIS);
NXDputalias(hfil,hdict,"adis",&fVal);
fVal = ObVal(pAmor->aParameter,PARANA);
NXDputalias(hfil,hdict,"abase",&fVal);
/* fifth Diaphragm!!!!!!!!! */
WriteDiaphragm(hfil,hdict,5,pCon);
fVal = ObVal(pAmor->aParameter,PARDD5);
NXDputalias(hfil,hdict,"d5dist",&fVal);
fVal = ObVal(pAmor->aParameter,PARD5H);
NXDputalias(hfil,hdict,"d5base",&fVal);
/* counting data */
pCom = FindCommand(pServ->pSics,"counter");
@@ -205,10 +233,6 @@
return 0;
}
/* write general detector data */
SNXSPutVariable(pServ->pSics,pCon,hfil, hdict,"sdetdist",
"detectordist");
/* allocate memory for writing scan data */
fAxis = (float *)malloc(pScan->iNP*sizeof(float));
@@ -313,7 +337,8 @@
CommandList *pCom = NULL;
const float *fTime;
HistInt *lData = NULL, lVal;
int detxsize, detysize, iDim[MAXDIM];
/* open files */
iRet = NXopen(file,NXACC_RDWR,&hfil);
@@ -331,9 +356,6 @@
return 0;
}
/* write general detector data */
SNXSPutVariable(pServ->pSics,pCon,hfil, hdict,"detdist",
"detectordist");
/* a few motors which may or may not be useful */
SNXSPutMotor(pServ->pSics,pCon,hfil,hdict,"detx","cox");
@@ -363,26 +385,51 @@
SCWrite(pCon,"WARNING: failed to find counter!",eWarning);
}
/*
find dimensions of detector
*/
GetHistDim(pHM,iDim,&iLength);
detxsize = iDim[0];
detysize = iDim[1];
/* update detector size */
sprintf(pBueffel,"%d",detxsize);
NXDupdate(hdict,"detxsize",pBueffel);
sprintf(pBueffel,"%d",detysize);
NXDupdate(hdict,"detysize",pBueffel);
/* write two axis */
fAxis = (float *)malloc(DETSIZE*sizeof(float));
if(detxsize > detysize)
iLength = detxsize;
else
iLength = detysize;
fAxis = (float *)malloc(iLength*sizeof(float));
if(!fAxis)
{
SCWrite(pCon,"ERROR: out of memory in WriteAmorTOF",eError);
return 0;
}
for(i = 0; i < DETSIZE; i++)
for(i = 0; i < detxsize; i++)
{
fAxis[i] = (float)i;
}
NXDputalias(hfil,hdict,"detxx",fAxis);
for(i = 0; i < detysize; i++)
{
fAxis[i] = (float)i;
}
NXDputalias(hfil,hdict,"dety",fAxis);
NXDaliaslink(hfil,hdict,"dana","detxx");
NXDaliaslink(hfil,hdict,"dana","dety");
free(fAxis);
/* update detector size */
sprintf(pBueffel,"%d",DETSIZE);
NXDupdate(hdict,"detsize",pBueffel);
/* add height and distances */
fVal = ObVal(pAmor->aParameter,PARDS);
NXDputalias(hfil,hdict,"detdist",&fVal);
fVal = ObVal(pAmor->aParameter,PARDDH);
NXDputalias(hfil,hdict,"detbase",&fVal);
/* deal with time binning */
@@ -397,6 +444,7 @@
sprintf(pBueffel,"%d",iLength);
NXDupdate(hdict,"timebin",pBueffel);
NXDputalias(hfil,hdict,"dettime",fTime2);
NXDputalias(hfil,hdict,"singletime",fTime2);
NXDaliaslink(hfil,hdict,"dana","dettime");
free(fTime2);
fTime2 = NULL;
@@ -408,18 +456,46 @@
}
/* finally get histogram */
iLength = GetHistLength(pHM);
lData = (HistInt *)malloc(iLength*sizeof(HistInt));
if(!lData)
if(iDim[2] == 2) /* 2D data, no time binning on this detector */
{
SCWrite(pCon,
"ERROR: out of memory, failed to write histogram",eError);
return 0;
iLength = detxsize*detysize;
lData = (HistInt *)malloc(iLength*sizeof(HistInt));
if(!lData)
{
SCWrite(pCon,
"ERROR: out of memory, failed to write histogram",eError);
return 0;
}
memset(lData,0,iLength*sizeof(HistInt));
GetHistogram(pHM,pCon, 0,0,iLength,lData,iLength*sizeof(HistInt));
NXDputalias(hfil,hdict,"spinup2d",lData);
NXDaliaslink(hfil,hdict,"dana","spinup2d");
}
else
{
iLength = iDim[0]*iDim[1]*iDim[2];
lData = (HistInt *)malloc(iLength*sizeof(HistInt));
if(!lData)
{
SCWrite(pCon,
"ERROR: out of memory, failed to write histogram",eError);
return 0;
}
memset(lData,0,iLength*sizeof(HistInt));
GetHistogramDirect(pHM,pCon,
0,0,iLength,lData,iLength*sizeof(HistInt));
NXDputalias(hfil,hdict,"spinup",lData);
NXDaliaslink(hfil,hdict,"dana","spinup");
/*
now get and write single detectors
*/
GetHistogramDirect(pHM,pCon,0,iLength,2*iDim[2],
lData, iLength*sizeof(HistInt));
NXDputalias(hfil,hdict,"singleup",lData);
NXDaliaslink(hfil,hdict,"singledana","singleup");
NXDaliaslink(hfil,hdict,"singledana","singletime");
}
memset(lData,0,iLength*sizeof(HistInt));
GetHistogram(pHM,pCon, 0,0,iLength,lData,iLength*sizeof(HistInt));
NXDputalias(hfil,hdict,"spinup",lData);
NXDaliaslink(hfil,hdict,"dana","spinup");
/* to do: add polarizing code */
@@ -459,7 +535,7 @@
char pBueffel[512];
int iRet;
if(argc < 2)
if(argc < 3)
{
SCWrite(pCon,
"ERROR: insufficient number of arguments to AmorStoreMake",
@@ -467,7 +543,7 @@
return 0;
}
/* we need one parameter which is the name of the histogram memory*/
/* we need a parameter which is the name of the histogram memory*/
pCom = FindCommand(pServ->pSics,argv[1]);
if(!pCom)
{
@@ -483,6 +559,25 @@
}
pMeme = (pHistMem)pCom->pData;
/* we need another parameter which is the name of the
2theta calculation module
*/
pCom = FindCommand(pServ->pSics,argv[2]);
if(!pCom)
{
sprintf(pBueffel,"ERROR: amor2T module %s NOT found", argv[2]);
SCWrite(pCon,pBueffel,eError);
return 0;
}
if(!pCom->pData)
{
sprintf(pBueffel,"ERROR: amor2t module %s NOT found", argv[2]);
SCWrite(pCon,pBueffel,eError);
return 0;
}
pAmor = (pAmor2T)pCom->pData;
/* install command */
iRet = AddCommand(pSics,"storeamor",
AmorStore,NULL,NULL);