diff --git a/HistDriv.i b/HistDriv.i index 995674e4..174045f1 100644 --- a/HistDriv.i +++ b/HistDriv.i @@ -10,7 +10,7 @@ ----------------------------------------------------------------------------*/ #ifndef SICSHISTDRIV #define SICSHISTDRIV -#define MAXCHAN 4096 +#define MAXCHAN 16834 #line 82 "histogram.w" diff --git a/amortest.tcl b/amortest.tcl index 23aecdfb..5baa2ad4 100644 --- a/amortest.tcl +++ b/amortest.tcl @@ -185,8 +185,8 @@ Motor COX SIM -100. 100. .1 2. # counter x ClientPut "Motors initialized" #======================== histogram memory -MakeHM hm SinqHM -#MakeHM hm SIM +#MakeHM hm SinqHM +MakeHM hm SIM hm configure HistMode PSD hm configure OverFlowMode Ceil hm configure Rank 1 diff --git a/danu.dat b/danu.dat index e4833c01..72983f35 100644 --- a/danu.dat +++ b/danu.dat @@ -1,3 +1,3 @@ - 189 + 212 NEVER, EVER modify or delete this file You'll risk eternal damnation and a reincarnation as a cockroach!|n \ No newline at end of file diff --git a/histmem.c b/histmem.c index 4960b6ee..23164f48 100644 --- a/histmem.c +++ b/histmem.c @@ -62,7 +62,6 @@ #include "dynstring.h" #include "event.h" #include "status.h" - /* #define LOADDEBUG 1 */ diff --git a/histogram.tex b/histogram.tex index d1c8e318..276878b2 100644 --- a/histogram.tex +++ b/histogram.tex @@ -629,7 +629,7 @@ following. \mbox{}\verb@----------------------------------------------------------------------------*/@\\ \mbox{}\verb@#ifndef SICSHISTDRIV@\\ \mbox{}\verb@#define SICSHISTDRIV@\\ -\mbox{}\verb@#define MAXCHAN 4096@\\ +\mbox{}\verb@#define MAXCHAN 16834 @\\ \mbox{}\verb@@\\ \mbox{}\verb@@$\langle$HistType {\footnotesize ?}$\rangle$\verb@@\\ \mbox{}\verb@@$\langle$HistDrivProt {\footnotesize ?}$\rangle$\verb@@\\ diff --git a/histogram.w b/histogram.w index f91bd4d0..8bf27d35 100644 --- a/histogram.w +++ b/histogram.w @@ -484,7 +484,7 @@ following. ----------------------------------------------------------------------------*/ #ifndef SICSHISTDRIV #define SICSHISTDRIV -#define MAXCHAN 4096 +#define MAXCHAN 16834 @< HistType@> @< HistDrivProt @> diff --git a/nextrics.c b/nextrics.c index e41236b8..0b025340 100644 --- a/nextrics.c +++ b/nextrics.c @@ -33,6 +33,7 @@ #include "udpquieck.h" #include "nextrics.h" + #define DET1X 256 /* x -length of detector 1 */ #define DET1Y 128 /* y-length of detector 1 */ #define DET1XS 2 /* pixel size in x of detector 1 */ @@ -308,7 +309,7 @@ name of hkl object holding crystallographic information CounterMode eMode; HistInt lData[DET1X*DET1Y], i, lVal; int32 iVal,lBeam; - float fVal, fTTheta; + float fVal, fTTheta, fTime = 0.; pMotor pMot; /* write motors */ @@ -368,6 +369,7 @@ name of hkl object holding crystallographic information eMode = GetCounterMode(self->pCount); fVal = GetCounterPreset(self->pCount); lVal = GetMonitor(self->pCount,1,pCon); + fTime = GetCountTime(self->pCount,pCon); lBeam = GetMonitor(self->pCount,4,pCon); } if(eMode == eTimer) @@ -384,6 +386,7 @@ name of hkl object holding crystallographic information NXDputalias(hfil,self->pDict,"framemonitor",&iVal); iVal = (int32)lBeam; NXDputalias(hfil,self->pDict,"sinqmonitor",&iVal); + NXDputalias(hfil,self->pDict,"cctime",&fTime); /* write detector1 histogram */ if(self->pHistogram1 != NULL) diff --git a/nxdata.c b/nxdata.c index 1bd999cd..a4934b10 100644 --- a/nxdata.c +++ b/nxdata.c @@ -347,7 +347,7 @@ void *pData) { int iStat; - int32 iDim[2]; + int iDim[2]; iDim[0] = iLong; iStat = NXmakedata (Nfil, name, datatype, 1, (int *) iDim); @@ -383,7 +383,7 @@ void *pData, char *attname, char *val) { int iStat; - int32 iDim[2]; + int iDim[2]; iDim[0] = iLong; iStat = NXmakedata (Nfil, name, datatype, 1, (int *) iDim); @@ -465,7 +465,7 @@ pSelVar pPell; char *pP; float fVal; - float32 *fTheta; + float *fTheta; float fTh, f2Th, fB1, fB2; pMotor pMot = NULL; CommandList *pCom = NULL; @@ -474,7 +474,7 @@ pHistMem pHist = NULL; HistInt *lData = NULL; CounterMode eCount; - int32 *iTVal = NULL; + int *iTVal = NULL; pDummy pDum; int bHRPT = 0; float fMean, fStdDev; diff --git a/nxdict.c b/nxdict.c index a5d669ec..64a2efd3 100644 --- a/nxdict.c +++ b/nxdict.c @@ -34,7 +34,6 @@ #include #include #include -#include #include "lld.h" #include "napi.h" #include "stringdict.h" diff --git a/nxsans.c b/nxsans.c index ee8a9034..64fac775 100644 --- a/nxsans.c +++ b/nxsans.c @@ -62,6 +62,7 @@ #include "mumo.h" #include "sanswave.h" + #define HISTNAME "banana" #define SAMPLETABLE "sampletable" diff --git a/polterwrite.c b/polterwrite.c index d4861859..0bc0b627 100644 --- a/polterwrite.c +++ b/polterwrite.c @@ -1,7 +1,7 @@ /*-------------------------------------------------------------------------- P O L T E R W R I T E - fowrite is an object for writing POLTERDI data files. + Polterwrite is an object for writing POLTI data files. copyright: see copyright.h @@ -9,8 +9,12 @@ ----------------------------------------------------------------------------*/ #include #include -#include "fortify.h" +#include +#include +#include +#undef VOID #include "sics.h" +#include "event.h" #include "counter.h" #include "HistMem.h" #include "nxdict.h" @@ -22,41 +26,68 @@ /* diaphragm1 - chopper */ -#define DIA1DIST 3000 -/* - diaphragm2 - diaphragm1 -*/ -#define DIA2DIST 500 - -/* - diaphragm2 - sample position -*/ -#define SADIST 500 +#define DIA1DIST 8000 /* histogram memory name */ #define HM "hm" -/* - detector distance - sample -*/ -#define DETDIST 700 -/* - no detectors, change in poldi.dic as well -*/ -#define NODET 400 -/* - theta spacing -*/ -#define THSPACE .3 - +#define DETRADIUS 3000 typedef struct { pObjectDescriptor pDes; + pHistMem pHist; + int iNew; + time_t tUpdate; + int iInterval; + int iEnd; + SConnection *pCon; char *dictfile; + char *pFile; }Polterdi, *pPolterdi; +/* ------------------- forward declaration of task function --------------*/ + static int PoldiTask(void *pData); + static void PoldiUpdate(pPolterdi self, SConnection *pCon); + +/*------------------ The Countstart Callback Function ----------------------*/ + static int Countstartcallback(int iEvent, void *pEventData, void *pUser) + { + pPolterdi self = NULL; + + if(iEvent == COUNTSTART) + { + self = (pPolterdi)pUser; + assert(self); + self->iNew = 1; + self->iEnd = 0; + self->tUpdate = time(NULL); + self->pCon = (SConnection *)pEventData; + TaskRegister(pServ->pTasker,PoldiTask,NULL,NULL,self,1); + return 1; + } + return 1; + } +/*------------------ The Countend Callback Function ----------------------*/ + static int Countendcallback(int iEvent, void *pEventData, void *pUser) + { + pPolterdi self = NULL; + + if(iEvent == COUNTEND) + { + self = (pPolterdi)pUser; + assert(self); + self->tUpdate = time(NULL); + self->iEnd = 1; + PoldiUpdate(self,self->pCon); + /* + Fortify_CheckAllMemory(); + */ + return 1; + } + return 1; + } /*----------------------------------------------------------------------*/ static void KillPolterdi(void *pData){ pPolterdi self = (pPolterdi)pData; @@ -66,6 +97,9 @@ static void KillPolterdi(void *pData){ if(self->pDes){ DeleteDescriptor(self->pDes); } + if(self->pFile){ + free(self->pFile); + } if(self->dictfile){ free(self->dictfile); } @@ -77,12 +111,26 @@ int PolterInstall(SConnection *pCon, SicsInterp *pSics, void *pData, int argc, char *argv[]) { pPolterdi pNew = NULL; - + pICallBack pCall = NULL; + pDummy pDum; + pHistMem pHist = NULL; + + /* configure fortify */ + /* + iFortifyScope = Fortify_EnterScope(); + Fortify_CheckAllMemory(); + */ if(argc < 2){ SCWrite(pCon,"ERROR: insufficient number of arguments to PolterInstall", eError); return 0; } + pHist = (pHistMem)FindCommandData(pSics,HM,"HistMem"); + + if (!pHist) + { + + } pNew = (pPolterdi)malloc(sizeof(Polterdi)); if(!pNew){ @@ -92,24 +140,42 @@ int PolterInstall(SConnection *pCon, SicsInterp *pSics, } memset(pNew,0,sizeof(Polterdi)); pNew->pDes = CreateDescriptor("PolterdiWrite"); + pNew->pHist = pHist; pNew->dictfile = strdup(argv[1]); + pNew->iInterval = 20*60; if(!pNew->pDes || !pNew->dictfile){ SCWrite(pCon,"ERROR: out of memory in PolterInstall", eError); return 0; } - return AddCommand(pSics,"storedata",PolterAction,KillPolterdi,pNew); + /* install callbacks */ + pDum = (pDummy)pHist; + pCall = (pICallBack)pDum->pDescriptor->GetInterface(pHist,CALLBACKINTERFACE); + if(!pCall) + { + SCWrite(pCon, + "ERROR: no callback interface found at your histogram memory", + eError); + KillPolterdi(pNew); + return 0; + } + RegisterCallback(pCall,COUNTSTART,Countstartcallback,pNew,NULL); + RegisterCallback(pCall,COUNTEND,Countendcallback,pNew,NULL); + + AddCommand(pSics,"storedata",PolterAction,KillPolterdi,pNew); + return 1; + } /*-------------------------------------------------------------------*/ -static void writePolterdiGlobal(NXhandle hfil, NXdict hdict, SConnection *pCon, - SicsInterp *pSics){ +static void writePolterdiGlobal(NXhandle hfil, NXdict hdict, + SConnection *pCon){ char pBueffel[512]; - SNXSPutVariable(pSics,pCon,hfil,hdict,"etitle","title"); + SNXSPutVariable(pServ->pSics,pCon,hfil,hdict,"etitle","title"); SNXFormatTime(pBueffel,511); NXDputalias(hfil,hdict,"estart",pBueffel); - SNXSPutVariable(pSics,pCon,hfil,hdict,"iname","instrument"); + SNXSPutVariable(pServ->pSics,pCon,hfil,hdict,"iname","instrument"); sprintf(pBueffel,"%d",strlen("SINQ, PSI, Switzerland")); NXDupdate(hdict,"strdim",pBueffel); NXDputalias(hfil,hdict,"sname","SINQ, PSI, Switzerland"); @@ -119,95 +185,142 @@ static void writePolterdiGlobal(NXhandle hfil, NXdict hdict, SConnection *pCon, NXDupdate(hdict,"strdim","132"); } /*-------------------------------------------------------------------*/ -static void writeChopper(NXhandle hfil, NXdict hdict, SConnection *pCon, - SicsInterp *pSics){ - SNXSPutVariable(pSics,pCon,hfil,hdict,"cname","choppername"); - SNXSPutDrivable(pSics,pCon,hfil,hdict,"chopperspeed","crot"); +static void writeChopper(NXhandle hfil, NXdict hdict, SConnection *pCon){ + SNXSPutVariable(pServ->pSics,pCon,hfil,hdict,"cname","choppername"); + SNXSPutDrivable(pServ->pSics,pCon,hfil,hdict,"chopperspeed","crot"); } /*-------------------------------------------------------------------*/ -static void writeDiaphragm1(NXhandle hfil, NXdict hdict, SConnection *pCon, - SicsInterp *pSics){ +static void writeDiaphragm1(NXhandle hfil, NXdict hdict, + SConnection *pCon){ float dist; - SNXSPutMotor(pSics,pCon,hfil,hdict,"dia1x","d1m"); - SNXSPutMotorNull(pSics,pCon,hfil,hdict,"dia1x0","d1m"); - SNXSPutMotor(pSics,pCon,hfil,hdict,"dia1y","d1o"); - SNXSPutMotorNull(pSics,pCon,hfil,hdict,"dia1y0","d1o"); + SNXSPutMotor(pServ->pSics,pCon,hfil,hdict,"dia1x","d1m"); + SNXSPutMotorNull(pServ->pSics,pCon,hfil,hdict,"dia1x0","d1m"); + SNXSPutMotor(pServ->pSics,pCon,hfil,hdict,"dia1y","d1o"); + SNXSPutMotorNull(pServ->pSics,pCon,hfil,hdict,"dia1y0","d1o"); dist = (float)DIA1DIST; NXDputalias(hfil,hdict,"dia1dist",&dist); } /*------------------------------------------------------------------*/ -static void writeDiaphragm2(NXhandle hfil, NXdict hdict, SConnection *pCon, - SicsInterp *pSics){ - float dist2; - - SNXSPutMotor(pSics, pCon, hfil, hdict, "dia2x_plus", "d2m"); - SNXSPutMotorNull(pSics, pCon, hfil, hdict, "dia2xplus0", "d2m"); - SNXSPutMotor(pSics, pCon, hfil, hdict, "dia2x_minus", "d2u"); - SNXSPutMotorNull(pSics, pCon, hfil, hdict, "dia2xminus0", "d2u"); - SNXSPutMotor(pSics, pCon, hfil, hdict, "dia2z_plus", "d2o"); - SNXSPutMotorNull(pSics, pCon, hfil, hdict, "dia2zplus0", "d2o"); - SNXSPutMotor(pSics, pCon, hfil, hdict, "dia2z_minus", "d2l"); - SNXSPutMotorNull(pSics, pCon, hfil, hdict, "dia2zminus0", "d2l"); - - dist2 = (float) DIA2DIST; +static void writeDiaphragm2(NXhandle hfil, NXdict hdict, + SConnection *pCon){ + SNXSPutMotor(pServ->pSics, pCon, hfil, hdict, "dia2x_plus", "d2m"); + SNXSPutMotorNull(pServ->pSics, pCon, hfil, hdict, "dia2xplus0", "d2m"); + SNXSPutMotor(pServ->pSics, pCon, hfil, hdict, "dia2x_minus", "d2u"); + SNXSPutMotorNull(pServ->pSics, pCon, hfil, hdict, "dia2xminus0", "d2u"); + SNXSPutMotor(pServ->pSics, pCon, hfil, hdict, "dia2z_plus", "d2o"); + SNXSPutMotorNull(pServ->pSics, pCon, hfil, hdict, "dia2zplus0", "d2o"); + SNXSPutMotor(pServ->pSics, pCon, hfil, hdict, "dia2z_minus", "d2l"); + SNXSPutMotorNull(pServ->pSics, pCon, hfil, hdict, "dia2zminus0", "d2l"); + + SNXSPutVariable(pServ->pSics,pCon,hfil,hdict,"dia2dist","dia1_dia2"); } /*--------------------------------------------------------------------*/ -static void writeSample(NXhandle hfil, NXdict hdict, SConnection *pCon, - SicsInterp *pSics) +static void writeSample(NXhandle hfil, NXdict hdict, + SConnection *pCon) { - float sadist = (float)SADIST; - - NXDputalias(hfil, hdict, "sdist", &sadist); - SNXSPutVariable(pSics,pCon,hfil,hdict,"saname","sample"); - SNXSPutVariable(pSics,pCon,hfil,hdict,"senvir","environment"); + + SNXSPutVariable(pServ->pSics,pCon,hfil,hdict,"sdist","dia2_sample"); + SNXSPutVariable(pServ->pSics,pCon,hfil,hdict,"chopperdist","chopper_sample"); + SNXSPutVariable(pServ->pSics,pCon,hfil,hdict,"saname","sample"); + SNXSPutVariable(pServ->pSics,pCon,hfil,hdict,"senvir","environment"); SNXSPutEVVar(hfil,hdict,"temperature",pCon,"stemp","stddev"); - SNXSPutMotor(pSics, pCon, hfil, hdict, "srsu", "rsu"); - SNXSPutMotorNull(pSics, pCon, hfil, hdict, "srsu0", "rsu"); - SNXSPutMotor(pSics, pCon, hfil, hdict, "srsl", "rsl"); - SNXSPutMotorNull(pSics, pCon, hfil, hdict, "srsl0", "rsl"); - SNXSPutMotor(pSics, pCon, hfil, hdict, "srsa", "rsa"); - SNXSPutMotorNull(pSics, pCon, hfil, hdict, "srsa0", "rsa"); - SNXSPutMotor(pSics, pCon, hfil, hdict, "sshu", "shu"); - SNXSPutMotorNull(pSics, pCon, hfil, hdict, "sshu0", "shu"); - SNXSPutMotor(pSics, pCon, hfil, hdict, "sshl", "shl"); - SNXSPutMotorNull(pSics, pCon, hfil, hdict, "sshl0", "shl"); - SNXSPutMotor(pSics, pCon, hfil, hdict, "ssgu", "sgu"); - SNXSPutMotorNull(pSics, pCon, hfil, hdict, "ssgu0", "sgu"); - SNXSPutMotor(pSics, pCon, hfil, hdict, "ssgl", "sgl"); - SNXSPutMotorNull(pSics, pCon, hfil, hdict, "ssgl0", "sgl"); - SNXSPutMotor(pSics, pCon, hfil, hdict, "ssv", "sv"); - SNXSPutMotorNull(pSics, pCon, hfil, hdict, "ssv0", "sv"); + SNXSPutMotor(pServ->pSics, pCon, hfil, hdict, "srsu", "rsu"); + SNXSPutMotorNull(pServ->pSics, pCon, hfil, hdict, "srsu0", "rsu"); + SNXSPutMotor(pServ->pSics, pCon, hfil, hdict, "srsl", "rsl"); + SNXSPutMotorNull(pServ->pSics, pCon, hfil, hdict, "srsl0", "rsl"); + SNXSPutMotor(pServ->pSics, pCon, hfil, hdict, "srsa", "rsa"); + SNXSPutMotorNull(pServ->pSics, pCon, hfil, hdict, "srsa0", "rsa"); + SNXSPutMotor(pServ->pSics, pCon, hfil, hdict, "sshu", "shu"); + SNXSPutMotorNull(pServ->pSics, pCon, hfil, hdict, "sshu0", "shu"); + SNXSPutMotor(pServ->pSics, pCon, hfil, hdict, "sshl", "shl"); + SNXSPutMotorNull(pServ->pSics, pCon, hfil, hdict, "sshl0", "shl"); + SNXSPutMotor(pServ->pSics, pCon, hfil, hdict, "ssgu", "sgu"); + SNXSPutMotorNull(pServ->pSics, pCon, hfil, hdict, "ssgu0", "sgu"); + SNXSPutMotor(pServ->pSics, pCon, hfil, hdict, "ssgl", "sgl"); + SNXSPutMotorNull(pServ->pSics, pCon, hfil, hdict, "ssgl0", "sgl"); + SNXSPutMotor(pServ->pSics, pCon, hfil, hdict, "ssv", "sv"); + SNXSPutMotorNull(pServ->pSics, pCon, hfil, hdict, "ssv0", "sv"); } -/*-----------------------------------------------------------------------*/ -static void writeDetector(NXhandle hfil, NXdict hdict, SConnection *pCon, - SicsInterp *pSics) + +/*--------------------------------------------------------------------*/ + +static int PoldiStart(pPolterdi self, SConnection *pCon) { + char pBueffel[256]; + NXhandle hfil = NULL; + NXdict hdict= NULL; + int status; const float *fTime = NULL; CounterMode eMode; - pHistMem pHist= NULL; - float *fTime2 = NULL, fTheta[NODET], fVal; - int iLength, i; - char pBueffel[80]; + float *fTime2 = NULL,fTheta0[801],fTheta[801], fVal; + pSicsVariable pVar = NULL; + float det_radius, det_size, x0det, y0det, twothet; + float pi, alpha1, alphasamp, sms, phidetav, phim; + float phi2det, val1, val2, nodet; + int iLength, i, nzell; pMotor sa; HistInt *lData = NULL; long lVal; - pHist = (pHistMem)FindCommandData(pSics,HM,"HistMem"); - if(!pHist) + /* create filename */ + self->pFile = SNXMakeFileName(pServ->pSics,pCon); + if(!self->pFile) { - SCWrite(pCon,"ERROR: Histogram memory NOT found",eError); - return; + SCWrite(pCon,"ERROR: Extra severe: failed to create data file name", + eError); + return 0; } + + /* create a Nexus file */ + NXopen(self->pFile,NXACC_CREATE,&hfil); + if(!hfil) + { + SCWrite(pCon,"ERROR: cannot create data file ",eError); + return 0; + } + + /* tell Uwe User what we are doing */ + sprintf(pBueffel,"Writing %s ......",self->pFile); + SCWrite(pCon,pBueffel,eWarning); + + /* write globals */ + SNXSPutGlobals(hfil,self->pFile,"POLDI",pCon); + + /* open nxdict */ + status = NXDinitfromfile(self->dictfile,&hdict); + if(status != NX_OK) + { + sprintf(pBueffel,"ERROR: failed to open dictionary file %s", + self->dictfile); + SCWrite(pCon,pBueffel,eError); + SCWrite(pCon,"ERROR: Aborting data file writing",eError); + SCWrite(pCon,"ERROR: This is a SERIOUS problem!",eError); + SCWrite(pCon,"ERROR: DATA NOT WRITTEN",eError); + NXclose(&hfil); + return 0; + } + + + writePolterdiGlobal(hfil,hdict,pCon); + + writeChopper(hfil,hdict,pCon); + + writeDiaphragm1(hfil,hdict,pCon); + + writeDiaphragm2(hfil,hdict,pCon); + + writeSample(hfil,hdict,pCon); /* write time binning */ - fTime = GetHistTimeBin(pHist,&iLength); + + fTime = GetHistTimeBin(self->pHist,&iLength); fTime2 = (float *)malloc(iLength*sizeof(float)); if(fTime2) { @@ -226,31 +339,100 @@ static void writeDetector(NXhandle hfil, NXdict hdict, SConnection *pCon, } /* - do theta + theta calculation */ - fVal = -999.; - sa = FindMotor(pSics,"sa"); - if(sa) + det_radius = (float)DETRADIUS; + pVar = FindVariable(pServ->pSics,"det_size"); + if(pVar) { - MotorGetSoftPosition(sa,pCon,&fVal); + VarGetFloat(pVar,&det_size); + } else { + SCWrite(pCon,"ERROR: Command not found!",eError); + return; + } + pVar = NULL; + pVar = FindVariable(pServ->pSics,"nodet"); + if(pVar) + { + VarGetFloat(pVar,&nodet); + } else { + SCWrite(pCon,"ERROR: Command not found!",eError); + return; + } + pVar = NULL; + nzell = (int)nodet; + + pVar = FindVariable(pServ->pSics,"x0_det"); + if(pVar) + { + VarGetFloat(pVar,&x0det); + } else { + SCWrite(pCon,"ERROR: Command not found!",eError); + return; + } + pVar = NULL; + pVar = FindVariable(pServ->pSics,"y0_det"); + if(pVar) + { + VarGetFloat(pVar, &y0det); + } else { + SCWrite(pCon,"ERROR: Command not found!",eError); + return; + } + pVar = NULL; + pVar = FindVariable(pServ->pSics,"twotheta"); + if(pVar) + { + VarGetFloat(pVar, &twothet); + } else { + SCWrite(pCon,"ERROR: Command not found!",eError); + return; + } + + pi = 3.1415926536; + /* transformation to radient */ + twothet = twothet*pi/180; + if (x0det < 0) { + alpha1 = atan(y0det/x0det); } - else - { - SCWrite(pCon,"ERROR: failed to locate two theta motor",eError); + if (x0det > 0) { + alpha1 = pi + atan(y0det/x0det); + } + alphasamp=pi + alpha1 - twothet; + sms = sqrt(x0det*x0det + y0det*y0det); + phidetav = pi - alphasamp - asin(sms/det_radius*sin(alphasamp)) + alpha1; + phim = atan(y0det/x0det); + if (phim < 0) { + phim = pi + phim; } - for(i = 0; i < NODET; i++) + for(i = 0; i <= nzell; i++) + { + phi2det = phidetav+(i-0.5*(nzell-1.0))*det_size/(det_radius); + val1 = det_radius*sin(phi2det) - sms*sin(phim); + val2 = det_radius*cos(phi2det) - sms*cos(phim); + fTheta0[i] = atan(val1/val2); + if (fTheta0[i] < 0) { + fTheta0[i] = pi + fTheta0[i]; + } + /* transformation to degree */ + fTheta0[i] = fTheta0[i]*180/pi; + } + for (i=0;i<=nzell;i++) { - fTheta[i] = fVal + i * THSPACE; + fTheta[i]=fTheta0[nzell-i]; } NXDputalias(hfil,hdict,"dtheta",fTheta); - - fVal = (float)DETDIST; - NXDputalias(hfil,hdict,"ddist",&fVal); - + NXDputalias(hfil,hdict,"detector_radius",&det_radius); + NXDputalias(hfil,hdict,"cell_size",&det_size); + SNXSPutVariable(pServ->pSics,pCon,hfil,hdict,"ddist","detectordist"); + SNXSPutVariable(pServ->pSics,pCon,hfil,hdict,"sangle","scatt_angle"); + SNXSPutVariable(pServ->pSics,pCon,hfil,hdict,"detx0","x0_det"); + SNXSPutVariable(pServ->pSics,pCon,hfil,hdict,"dety0","y0_det"); + SNXSPutVariable(pServ->pSics,pCon,hfil,hdict,"theta","twotheta"); /* write Histogram */ - lData = GetHistogramPointer(pHist,pCon); + lData = GetHistogramPointer(self->pHist,pCon); if(lData) { NXDputalias(hfil,hdict,"dcounts",lData); @@ -263,11 +445,11 @@ static void writeDetector(NXhandle hfil, NXdict hdict, SConnection *pCon, /* write counting data */ - fVal = GetHistCountTime(pHist,pCon); + fVal = GetHistCountTime(self->pHist,pCon); NXDputalias(hfil,hdict,"cntime",&fVal); - lVal = GetHistMonitor(pHist,1,pCon); + lVal = GetHistMonitor(self->pHist,1,pCon); NXDputalias(hfil,hdict,"cnmon1",&lVal); - eMode = GetHistCountMode(pHist); + eMode = GetHistCountMode(self->pHist); if(eMode == eTimer) { strcpy(pBueffel,"timer"); @@ -277,55 +459,45 @@ static void writeDetector(NXhandle hfil, NXdict hdict, SConnection *pCon, strcpy(pBueffel,"monitor"); } NXDputalias(hfil,hdict,"cnmode",pBueffel); - fVal = GetHistPreset(pHist); + fVal = GetHistPreset(self->pHist); NXDputalias(hfil,hdict,"cnpreset",&fVal); + + /* close everything */ + NXclose(&hfil); + NXDclose(hdict,NULL); + self->iNew = 0; } -/*---------------------------------------------------------------------*/ -static void makeLinks(NXhandle hfil, NXdict hdict, SConnection *pCon, - SicsInterp *pSics) -{ - NXDaliaslink(hfil,hdict,"dana","dcounts"); - NXDaliaslink(hfil,hdict,"dana","dtheta"); - NXDaliaslink(hfil,hdict,"dana","dtime"); -} -/*--------------------------------------------------------------------*/ -static int StoreData(SConnection *pCon, SicsInterp *pSics, pPolterdi self) -{ - char pBueffel[256], *pFile = NULL; - NXhandle hfil = NULL; - NXdict hdict= NULL; - int status; - /* create filename */ - pFile = SNXMakeFileName(pSics,pCon); - if(!pFile) - { - SCWrite(pCon,"ERROR: Extra severe: failed to create data file name", - eError); - return 0; - } - - /* create a Nexus file */ - NXopen(pFile,NXACC_CREATE,&hfil); - if(!hfil) - { - SCWrite(pCon,"ERROR: cannot create data file ",eError); - return 0; - } - - /* tell Uwe User what we are doing */ - sprintf(pBueffel,"Writing %s ......",pFile); - SCWrite(pCon,pBueffel,eWarning); - - /* write globals */ - SNXSPutGlobals(hfil,pFile,"POLTERDI",pCon); - free(pFile); - pFile = NULL; - - /* open nxdict */ - status = NXDinitfromfile(self->dictfile,&hdict); - if(status != NX_OK) +/*---------------------------------------------------------------------------*/ + + static void PoldiUpdate(pPolterdi self, SConnection *pCon) { + char pBueffel[256]; + NXhandle hfil = NULL; + NXdict hdict = NULL; + int status; + const float *fTime = NULL; + CounterMode eMode; + float *fTime2 = NULL, fTheta[801], fVal; + pSicsVariable pVar = NULL; + float det_radius, det_size, x0det, y0det, twothet; + float pi, alpha1, alphasamp, sms, phidetav, phim; + float phi2det, val1, val2, nodet; + int iLength, i, nzell; + pMotor sa; + HistInt *lData = NULL; + long lVal; + + /* open everything again */ + NXopen(self->pFile,NXACC_RDWR,&hfil); + if(!self->pFile) + { + SCWrite(pCon,"ERROR: cannot reopen data file ",eError); + return; + } + status = NXDinitfromfile(self->dictfile,&hdict); + if(status != NX_OK) + { sprintf(pBueffel,"ERROR: failed to open dictionary file %s", self->dictfile); SCWrite(pCon,pBueffel,eError); @@ -333,42 +505,240 @@ static int StoreData(SConnection *pCon, SicsInterp *pSics, pPolterdi self) SCWrite(pCon,"ERROR: This is a SERIOUS problem!",eError); SCWrite(pCon,"ERROR: DATA NOT WRITTEN",eError); NXclose(&hfil); - return 0; + return; + } + + /* tell the user that something is happening */ + sprintf(pBueffel,"Updating %s",self->pFile); + SCWrite(pCon,pBueffel,eWarning); + + /* + write time binning + */ + + fTime = GetHistTimeBin(self->pHist,&iLength); + fTime2 = (float *)malloc(iLength*sizeof(float)); + if(fTime2) + { + for(i = 0;i < iLength; i++) + { + fTime2[i] = fTime[i]/10.; + } + sprintf(pBueffel,"%d",iLength); + NXDupdate(hdict,"timebin",pBueffel); + NXDputalias(hfil,hdict,"dtime",fTime2); + free(fTime2); + } + else + { + SCWrite(pCon,"ERROR: out of memory while writing time binning",eError); } + /* + write Histogram + */ - writePolterdiGlobal(hfil,hdict,pCon,pSics); - - writeChopper(hfil,hdict,pCon,pSics); - - writeDiaphragm1(hfil,hdict,pCon,pSics); - - writeDiaphragm2(hfil,hdict,pCon,pSics); - - writeSample(hfil,hdict,pCon,pSics); - - writeDetector(hfil,hdict,pCon,pSics); + lData = GetHistogramPointer(self->pHist,pCon); + if(lData) + { + NXDputalias(hfil,hdict,"dcounts",lData); + } + else + { + SCWrite(pCon,"ERROR: failed to get histogram data",eError); + } + + /* + write counting data + */ + fVal = GetHistCountTime(self->pHist,pCon); + NXDputalias(hfil,hdict,"cntime",&fVal); + lVal = GetHistMonitor(self->pHist,1,pCon); + NXDputalias(hfil,hdict,"cnmon1",&lVal); + eMode = GetHistCountMode(self->pHist); + if(eMode == eTimer) + { + strcpy(pBueffel,"timer"); + } + else + { + strcpy(pBueffel,"monitor"); + } + NXDputalias(hfil,hdict,"cnmode",pBueffel); + fVal = GetHistPreset(self->pHist); + NXDputalias(hfil,hdict,"cnpreset",&fVal); - makeLinks(hfil,hdict,pCon,pSics); + + /* close everything */ + NXclose(&hfil); + NXDclose(hdict,NULL); + + } - /* close everything */ - NXclose(&hfil); - NXDclose(hdict,NULL); +/*------------------------------------------------------------------------- + FoLink sets all the links for the NXdata vGroup. Had to be separate because + at least one update is necessary before this can be done. +-------------------------------------------------------------------------*/ - SCSendOK(pCon); - return 1; -} + static void PoldiLink(pPolterdi self, SConnection *pCon) + { + NXhandle hfil = NULL; + NXdict hdict = NULL; + int status; + char pBueffel[512]; + + /* open everything again */ + NXopen(self->pFile,NXACC_RDWR,&hfil); + if(!self->pFile) + { + SCWrite(pCon,"ERROR: cannot reopen data file ",eError); + return; + } + status = NXDinitfromfile(self->dictfile,&hdict); + if(status != NX_OK) + { + sprintf(pBueffel,"ERROR: failed to open dictionary file %s", + self->dictfile); + SCWrite(pCon,pBueffel,eError); + SCWrite(pCon,"ERROR: Aborting data file writing",eError); + SCWrite(pCon,"ERROR: This is a SERIOUS problem!",eError); + SCWrite(pCon,"ERROR: DATA NOT WRITTEN",eError); + NXclose(&hfil); + return; + } + + NXDaliaslink(hfil,hdict,"dana","dcounts"); + NXDaliaslink(hfil,hdict,"dana","dtheta"); + NXDaliaslink(hfil,hdict,"dana","dtime"); + + /* close everything */ + NXclose(&hfil); + NXDclose(hdict,NULL); + + } + +/*--------------------------------------------------------------------------- + This is the task function for updating the data file any now and then + automatically + --------------------------------------------------------------------------*/ + static int PoldiTask(void *pData) + { + pPolterdi self = NULL; + int iWrite, iRet; + + self = (pPolterdi)pData; + if(!self) + return 0; + + /* figure out if we need to write */ + iWrite = 0; + iRet = 1; + /* first case: update intervall */ + if(time(NULL) >= self->tUpdate) + { + self->tUpdate = time(NULL) + self->iInterval; + iWrite = 1; + iRet = 1; + } + + if(self->iEnd) + { + self->tUpdate = 0; + SCWrite(self->pCon,"Writing finished!",eError); + iWrite = 0; + iRet = 0; + } + + if(iWrite) + { + if(self->iNew) + { + PoldiStart(self,self->pCon); + PoldiUpdate(self,self->pCon); + PoldiLink(self,self->pCon); + } + else + { + PoldiUpdate(self,self->pCon); + PoldiLink(self,self->pCon); + } + } + return iRet; + } /*----------------------------------------------------------------------*/ int PolterAction(SConnection *pCon, SicsInterp *pSics, void *pData, int argc, char *argv[]) { - pPolterdi self = (pPolterdi)pData; + int iRet, iVal; + pPolterdi self = NULL; + char pBueffel[512]; + + if(argc < 2) + { + SCWrite(pCon,"ERROR: Insufficient number of arguments to StoreData", + eError); + return 0; + } - assert(self); - assert(pCon); - assert(pSics); - - return StoreData(pCon,pSics,self); + self = (pPolterdi)pData; + assert(self); + + strtolower(argv[1]); + if(strcmp(argv[1],"start") == 0) + { + PoldiStart(self,pCon); + PoldiUpdate(self,pCon); + PoldiLink(self,pCon); + return 1; + } else if(strcmp(argv[1],"update") == 0) + { + if((self->iNew) || (!self->pFile)) + { + PoldiStart(self,pCon); + } + else + { + PoldiUpdate(self,pCon); + PoldiLink(self,pCon); + } + return 1; + } + else if(strcmp(argv[1],"getfile") == 0) + { + sprintf(pBueffel,"StoreData.file = %s",self->pFile); + SCWrite(pCon,pBueffel,eValue); + return 1; + } + else if(strcmp(argv[1],"interval") == 0) + { + if(argc > 2) /* set value */ + { + if(!SCMatchRights(pCon,usUser)) + { + return 0; + } + iRet = Tcl_GetInt(pSics->pTcl,argv[2],&iVal); + if(iRet != TCL_OK) + { + sprintf(pBueffel,"ERROR: cannot convert --> %s <-- to number ", + argv[2]); + SCWrite(pCon,pBueffel,eError); + return 0; + } + self->iInterval = iVal*60; /* go to seconds from minutes*/ + SCSendOK(pCon); + return 1; + } + else /* read the value */ + { + sprintf(pBueffel,"storefocus.interval = %d",self->iInterval/60); + SCWrite(pCon,pBueffel,eValue); + return 1; + } + } + + SCWrite(pCon,"ERROR: subcommand to StoreData not recognized",eError); + return 0; } diff --git a/sicsstatus.tcl b/sicsstatus.tcl index e5ee4f2e..f23530f6 100644 --- a/sicsstatus.tcl +++ b/sicsstatus.tcl @@ -47,11 +47,11 @@ ps.phiend setAccess 2 ps.phistart 0.000000 ps.phistart setAccess 2 hm3 CountMode timer -hm3 preset 10.000000 -hm2 CountMode monitor -hm2 preset 2.000000 -hm1 CountMode monitor -hm1 preset 2.000000 +hm3 preset 3600.000000 +hm2 CountMode timer +hm2 preset 3600.000000 +hm1 CountMode timer +hm1 preset 3600.000000 #Crystallographic Settings hkl lambda 1.179000 hkl setub -0.017880 -0.074923 0.028280 -0.007008 -0.036800 -0.057747 0.160912 -0.009928 0.000627 @@ -458,5 +458,5 @@ sample D20 30K SNP Okt 2001 GS sample setAccess 2 title snp gs apd 30K title setAccess 2 -starttime 2001-11-16 08:55:46 +starttime 2002-04-23 10:49:18 starttime setAccess 2 diff --git a/sinqhm/FOCUS_srv_main.c b/sinqhm/FOCUS_srv_main.c index 7916ce3d..d16b91bd 100755 --- a/sinqhm/FOCUS_srv_main.c +++ b/sinqhm/FOCUS_srv_main.c @@ -1590,7 +1590,7 @@ int my_daq_save; uint maxbins, my_nbins, bins_in_buff; uint nxtbin_to_send, nbins_to_send, bytes_in_buff; - uint bins_to_go; + uint bins_to_go, lastbin; struct req_buff_struct my_rqst; struct rply_buff_struct my_rply; uchar *buff_pntr, *last_byte, *nxt; @@ -1710,9 +1710,13 @@ nxt = (char *) my_pntr.base; while (nbins_to_send > 0) { /* Read some histogram data into buffer */ + lastbin = nxtbin_to_send + bins_in_buff; + if(lastbin > my_nbins-1){ + lastbin = my_nbins-1; + } bins_to_go = FS_read_hm (index, pkt_size, my_pntr.base, bins_in_buff, - nxtbin_to_send, (my_fstbin + my_nbins - 1)); + nxtbin_to_send, lastbin); if (bins_to_go <= 0) { perror (StrJoin (buff, pkt_size, FS_name[index], "/FS_do_read: FS_read_hm error")); diff --git a/sinqhm/SinqHM_srv_filler.c b/sinqhm/SinqHM_srv_filler.c index cbb10f58..514aef4d 100755 --- a/sinqhm/SinqHM_srv_filler.c +++ b/sinqhm/SinqHM_srv_filler.c @@ -808,6 +808,10 @@ /* We have a valid PSD packet. Find and check positions. */ + + /* + old style calculation, left in for now + xPos = xData.ui2[1]; if(xPos > 32767) xPos -= 65536; @@ -815,21 +819,21 @@ yPos = yData.ui2[1]; if(yPos > 32767) yPos -= 65536; - - /* - if(xPos > 0) - xPos =(int)((float)xPos/(float)psdXFactor +.5 + psdXOffset); - else - xPos =(int)((float)xPos/(float)psdXFactor -.49999 + psdXOffset); - - if(yPos > 0) - yPos =(int)((float)yPos/(float)psdYFactor +.5 + psdYOffset); - else - yPos =(int)((float)yPos/(float)psdYFactor -.49999 + psdYOffset); - */ xPos = (int) ( (float)(xPos+xOff)/(float)psdXFactor); yPos = (int)( (float)(yPos+yOff)/(float)psdYFactor); + */ + + /* + This is the new version where all values are offset by 4096 + in order to give positive values at all times. This relates + to a zero point in the middle of the detector. As we want a + zero point in the lower left corner, we subtract 2048. + */ + xPos = xData.ui2[1]; + xPos = (xPos - 2048)/psdXFactor; + yPos = yData.ui2[1]; + yPos = (yPos - 2048)/psdYFactor; if(xPos < 0 || xPos > psdXSize) diff --git a/sinqhm/SinqHM_srv_main.c b/sinqhm/SinqHM_srv_main.c index 7ec8799b..2091f73c 100755 --- a/sinqhm/SinqHM_srv_main.c +++ b/sinqhm/SinqHM_srv_main.c @@ -151,7 +151,7 @@ Dbg_mask = 0; Dbg_lev0 = 0; - Dbg_lev1 = 1; + Dbg_lev1 = 0; Dbg_lev2 = 0; Dbg_lev3 = 0; Cfgn_done = 0; /* Force a configuration before we can do anything. */ diff --git a/sinqhm/SinqHM_srv_routines.c b/sinqhm/SinqHM_srv_routines.c index d5f9fbf7..86e4d0a6 100755 --- a/sinqhm/SinqHM_srv_routines.c +++ b/sinqhm/SinqHM_srv_routines.c @@ -1205,7 +1205,7 @@ /* switch debugging on by default - Dbg_lev1 = 1; + Dbg_lev1 = 0; */ /* diff --git a/tascom.tcl b/tascom.tcl index bc5ac597..bedcc396 100644 --- a/tascom.tcl +++ b/tascom.tcl @@ -495,8 +495,10 @@ proc co args { #----- format output set cts [tasSplit [counter getcounts]] set m1 [tasSplit [counter getmonitor 1]] - set m3 [tasSplit [counter getmonitor 2]] - return [format " Counts = %8d, M1 = %8d, M3 = %8d" $cts $m1 $m3] + set m2 [tasSplit [counter getmonitor 2]] + set m3 [tasSplit [counter getmonitor 3]] + return [format " Counts = %8d, M1 = %8d, M2 = %8d, M3 = %8d" \ + $cts $m1 $m2 $m3] } #---------------------------------------------------------------------------- @@ -775,7 +777,7 @@ proc le args { set v2 [tasSplit [qm]] set val [format " %9.4f %9.4f\n" $v1 $v2] set v1 [tasSplit [ten]] - set v2 [tasSplit [qm]] + set v2 [tasSplit [tqm]] set val2 [format " %9.4f %9.4f\n" $v1 $v2] append output [format "POSN: %s" $val] append output [format "TARG: %s" $val2] @@ -926,8 +928,7 @@ proc sz args { "%-8sOld: %8.2f %8.2f %8.2f %8.2f %8.2f %8.2f %8.2f\n" \ $mot $loh $los $pos $targ $his $hih $zero] #-------action - set newZero [expr $zero + ($val - $pos)] - madZero $mot $newZero + madZero $mot $val catch {updateqe} msg #-------- more output set zero [tasSplit [madZero $mot]] diff --git a/tasinit.c b/tasinit.c index 32ad0091..1962b7d4 100644 --- a/tasinit.c +++ b/tasinit.c @@ -48,6 +48,7 @@ extern char *tasMotorOrder[] = { "a1", "sgl", "sgu", "agl", + "tt", "i1" , "i2", "i3", @@ -211,10 +212,10 @@ static int MonitorCallback(int iEvent, void *pEvent, void *pUser) return 0; SetCounterMode(self->pScan->pCounterData,ePreset); - SetCounterPreset(self->pScan->pCounterData,self->tasPar[MN]->fVal); + SetCounterPreset(self->pScan->pCounterData,(float)self->tasPar[MN]->iVal); return 1; } - +/*---------------------------------------------------------------------*/ static int TimerCallback(int iEvent, void *pEvent, void *pUser) { pTASdata self = (pTASdata)pUser; diff --git a/trics.dic b/trics.dic index 9b29ad5c..3a3bc4fc 100644 --- a/trics.dic +++ b/trics.dic @@ -52,6 +52,8 @@ framemode = /$(framename),NXentry/TRICS,NXinstrument/count_control,NXcounter/SDS framemonitor = /$(framename),NXentry/TRICS,NXinstrument/count_control,NXcounter/SDS monitor -type DFNT_INT32 sinqmonitor= /$(framename),NXentry/TRICS,NXinstrument/count_control,NXcounter/SDS beam_monitor \ -type DFNT_INT32 +cctime= /$(framename),NXentry/TRICS,NXinstrument/count_control,NXcounter/SDS \ + time -attr {units,seconds} #------------------------ Detector dnumber = detector1 framedim1 = 256