- Reworked mesure for four circle to new specifications
* reworked table * added psd mode - exe now allows absolute paths - added getRS232Timeout to rs232controller - Fixed a couple of "guessed" return values
This commit is contained in:
203
mesure.c
203
mesure.c
@@ -74,6 +74,7 @@
|
||||
remeasured */
|
||||
int fastScan; /* flag for using fastscans for scanning reflections */
|
||||
int psiMode; /* 1 for psi scan mode, 0 else */
|
||||
int psd; /* a flag for making 2D detector scans */
|
||||
int stepTable; /* mapping of two theta ranges to step width and
|
||||
variable to scan */
|
||||
} Mesure;
|
||||
@@ -96,6 +97,7 @@ static int SaveMesure(void *pData, char *name, FILE *fd)
|
||||
fprintf(fd,"%s step %f\n", name, self->fStep);
|
||||
fprintf(fd,"%s weakthreshold %ld\n", name, self->weakThreshold);
|
||||
fprintf(fd,"%s compact %d\n", name, self->iCompact);
|
||||
fprintf(fd,"%s psd %d\n", name, self->psd);
|
||||
fprintf(fd,"%s weak %d\n", name, self->weak);
|
||||
fprintf(fd,"%s fastscan %d\n", name, self->fastScan);
|
||||
SaveFourCircleTable(self->stepTable,name,fd);
|
||||
@@ -127,6 +129,8 @@ static void ListMesure(pMesure self, char *name, SConnection *pCon)
|
||||
Tcl_DStringAppend(&list,pBuffer,-1);
|
||||
snprintf(pBuffer,131,"%s.compact %d\n", name, self->iCompact);
|
||||
Tcl_DStringAppend(&list,pBuffer,-1);
|
||||
snprintf(pBuffer,131,"%s.psd %d\n", name, self->psd);
|
||||
Tcl_DStringAppend(&list,pBuffer,-1);
|
||||
snprintf(pBuffer,131,"%s.weak %d\n", name, self->weak);
|
||||
Tcl_DStringAppend(&list,pBuffer,-1);
|
||||
snprintf(pBuffer,131,"%s.fastscan %d\n", name, self->fastScan);
|
||||
@@ -177,7 +181,8 @@ static void ListMesure(pMesure self, char *name, SConnection *pCon)
|
||||
pNew->fStep = 0.05;
|
||||
pNew->fPreset = 2;
|
||||
pNew->iCompact = 1;
|
||||
pNew->weak = 0;
|
||||
pNew->psd = 0;
|
||||
pNew->weak = 0;
|
||||
pNew->weakThreshold = 99999;
|
||||
pNew->fastScan = 0;
|
||||
pNew->psiMode = 0;
|
||||
@@ -395,6 +400,16 @@ static void ListMesure(pMesure self, char *name, SConnection *pCon)
|
||||
|
||||
return 1;
|
||||
}
|
||||
/*------------------------------------------------------------------------*/
|
||||
static int getMesureNP(pMesure self, double twoTheta)
|
||||
{
|
||||
int np;
|
||||
np = GetFourCircleScanNP(self->stepTable,twoTheta);
|
||||
if(np < -800){
|
||||
np = self->np;
|
||||
}
|
||||
return np;
|
||||
}
|
||||
/*-------------------------------------------------------------------------
|
||||
This is slightly tricky: the crystallography module has a scan tolerance.
|
||||
This is supposed to be automatically set. In order to do so, I need
|
||||
@@ -406,7 +421,7 @@ static void ListMesure(pMesure self, char *name, SConnection *pCon)
|
||||
static int MesureCalculateSettings(pMesure self, float fHKL[3], float fSet[4],
|
||||
float fPsi, SConnection *pCon)
|
||||
{
|
||||
int status;
|
||||
int status, np;
|
||||
float step, tolerance;
|
||||
|
||||
SetHKLScanTolerance(self->pCryst,.0);
|
||||
@@ -419,7 +434,8 @@ static int MesureCalculateSettings(pMesure self, float fHKL[3], float fSet[4],
|
||||
if(step < -900.){
|
||||
step = self->fStep;
|
||||
}
|
||||
tolerance = (step * (float)self->np)/2. + .2;
|
||||
np = getMesureNP(self,(double)fSet[0]);
|
||||
tolerance = (step * (float)np)/2. + .2;
|
||||
SetHKLScanTolerance(self->pCryst,tolerance);
|
||||
return CalculateSettings(self->pCryst,fHKL,fPsi,0,fSet,pCon);
|
||||
}
|
||||
@@ -481,19 +497,21 @@ static int DriveToReflection(pMesure self, float fSet[4], SConnection *pCon)
|
||||
/*-----------------------------------------------------------------------
|
||||
test if this scan has to be remeasured because it is weak
|
||||
------------------------------------------------------------------------*/
|
||||
int weakScan(pMesure self)
|
||||
int weakScan(pMesure self, double twoTheta)
|
||||
{
|
||||
int i;
|
||||
int i, np;
|
||||
long low = 99999, high = -99999;
|
||||
|
||||
/*
|
||||
ths scan is always OK if we do not test for weak conditions
|
||||
the scan is always OK if we do not test for weak conditions or we are in psd mode
|
||||
*/
|
||||
if(self->weak == 0){
|
||||
if(self->weak == 0 || self->psd == 1){
|
||||
return 0;
|
||||
}
|
||||
GetScanCounts(self->pScanner,self->lCounts,self->np);
|
||||
for(i = 0; i < self->np; i++)
|
||||
|
||||
np = getMesureNP(self,twoTheta);
|
||||
GetScanCounts(self->pScanner,self->lCounts,np);
|
||||
for(i = 0; i < np; i++)
|
||||
{
|
||||
if(self->lCounts[i] < low)
|
||||
{
|
||||
@@ -517,11 +535,43 @@ int weakScan(pMesure self)
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
/*-----------------------------------------------------------------------*/
|
||||
static int PerformPSDScan(pMesure self, char *scanVar, float fStart, float step, int np)
|
||||
{
|
||||
int status;
|
||||
char pCommand[1024];
|
||||
char countMode[20];
|
||||
Tcl_Interp *pTcl;
|
||||
|
||||
/*
|
||||
PSD scans are done by calling the routine Tcl procedure tricsscan with the
|
||||
appropriate parameters. tricsscan does only omega scans!
|
||||
*/
|
||||
if(self->CountMode == eTimer)
|
||||
{
|
||||
strcpy(countMode,"timer");
|
||||
}
|
||||
else
|
||||
{
|
||||
strcpy(countMode,"monitor");
|
||||
}
|
||||
snprintf(pCommand,1023,"tricsscan %f %f %d %s %f", fStart, step, np,countMode,self->fPreset);
|
||||
pTcl = InterpGetTcl(pServ->pSics);
|
||||
status = Tcl_Eval(pTcl,pCommand);
|
||||
if(status != TCL_OK)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
/*------------------------------------------------------------------------*/
|
||||
static int ScanReflection(pMesure self, float twoTheta, SConnection *pCon)
|
||||
{
|
||||
float fStart, stepWidth;
|
||||
int iRet;
|
||||
int iRet, np;
|
||||
char pBueffel[132];
|
||||
char *scanVar = NULL;
|
||||
|
||||
@@ -540,21 +590,54 @@ static int ScanReflection(pMesure self, float twoTheta, SConnection *pCon)
|
||||
} else {
|
||||
stepWidth = GetFourCircleStep(self->stepTable,(double)twoTheta);
|
||||
}
|
||||
np = getMesureNP(self,(double)twoTheta);
|
||||
|
||||
if(stepWidth != self->fStep)
|
||||
{
|
||||
snprintf(pBueffel,130,"Using stepwidth %f",stepWidth);
|
||||
snprintf(pBueffel,130,"Using stepwidth %f, %d points",stepWidth,np);
|
||||
SCWrite(pCon,pBueffel,eWarning);
|
||||
}
|
||||
fStart -= (self->np/2)*stepWidth;
|
||||
fStart -= (np/2)*stepWidth;
|
||||
|
||||
/* set the scan up */
|
||||
/*
|
||||
spcial case: psd mode
|
||||
*/
|
||||
if(self->psd == 1)
|
||||
{
|
||||
iRet = PerformPSDScan(self,scanVar,fStart, stepWidth, np);
|
||||
free(scanVar);
|
||||
return iRet;
|
||||
}
|
||||
|
||||
/*
|
||||
below is the code for a single counter scan.
|
||||
TODO: (maybe) make this clearer and separte this into another subroutine
|
||||
|
||||
Set the scan up
|
||||
*/
|
||||
ClearScanVar(self->pScanner);
|
||||
AddScanVar(self->pScanner, pServ->pSics,pCon,scanVar,
|
||||
fStart, stepWidth);
|
||||
free(scanVar);
|
||||
|
||||
/*
|
||||
as np can change, we have to reallocate enough space
|
||||
*/
|
||||
if(self->lCounts != NULL){
|
||||
free(self->lCounts);
|
||||
self->lCounts = (long *)malloc(np*sizeof(long));
|
||||
if(self->lCounts == NULL){
|
||||
SCWrite(pCon,"ERROR: out of memory for scan scan data",eError);
|
||||
SCSetInterrupt(pCon,eAbortScan);
|
||||
return 0;
|
||||
}
|
||||
memset(self->lCounts,0,np*sizeof(long));
|
||||
}
|
||||
|
||||
/* do the scan */
|
||||
snprintf(pBueffel,131,"Scanning %s, step %f, np = %d",scanVar, stepWidth, np);
|
||||
SCWrite(pCon,pBueffel,eWarning);
|
||||
free(scanVar);
|
||||
|
||||
if(self->iCompact)
|
||||
{
|
||||
self->pScanner->CollectScanData = CompactScanData;
|
||||
@@ -563,9 +646,9 @@ static int ScanReflection(pMesure self, float twoTheta, SConnection *pCon)
|
||||
{
|
||||
self->pScanner->ScanDrive = ScanFastDrive;
|
||||
}
|
||||
iRet = SilentScan(self->pScanner,self->np,self->CountMode,
|
||||
iRet = SilentScan(self->pScanner,np,self->CountMode,
|
||||
self->fPreset,pServ->pSics,pCon);
|
||||
if(weakScan(self))
|
||||
if(weakScan(self,twoTheta))
|
||||
{
|
||||
/*
|
||||
look for interrupts before restarting scan
|
||||
@@ -585,7 +668,7 @@ static int ScanReflection(pMesure self, float twoTheta, SConnection *pCon)
|
||||
redo scan with preset * 5
|
||||
*/
|
||||
SCWrite(pCon,"Remeasuring weak reflection",eWarning);
|
||||
iRet = SilentScan(self->pScanner,self->np,self->CountMode,
|
||||
iRet = SilentScan(self->pScanner,np,self->CountMode,
|
||||
self->fPreset*5.,pServ->pSics,pCon);
|
||||
|
||||
}
|
||||
@@ -651,10 +734,20 @@ static int ScanReflection(pMesure self, float twoTheta, SConnection *pCon)
|
||||
strcat(pFilename,"log");
|
||||
self->iLogFile = SCAddLogFile(pCon,pFilename);
|
||||
self->pCon = pCon;
|
||||
sprintf(pBueffel,"Writing to %s.log, .ccl, .rfl",pRoot);
|
||||
SCWrite(pCon,pBueffel,eValue);
|
||||
|
||||
/*
|
||||
we do not need reflection files when doing a PSD scan
|
||||
*/
|
||||
if(self->psd == 1)
|
||||
{
|
||||
sprintf(pBueffel,"Logging to %s.log", pRoot);
|
||||
SCWrite(pCon,pBueffel,eValue);
|
||||
return 1;
|
||||
}
|
||||
|
||||
/* open the reflection file */
|
||||
sprintf(pBueffel,"Writing to %s.log, .ccl, .rfl",pRoot);
|
||||
SCWrite(pCon,pBueffel,eValue);
|
||||
strcpy(pFilename,pRoot);
|
||||
strcat(pFilename,"ccl");
|
||||
self->fRefl = fopen(pFilename,"w");
|
||||
@@ -666,10 +759,6 @@ static int ScanReflection(pMesure self, float twoTheta, SConnection *pCon)
|
||||
SCSetInterrupt(pCon,eAbortBatch);
|
||||
return 0;
|
||||
}
|
||||
/* put filename
|
||||
fputs(pFilename,self->fRefl);
|
||||
fputs("\n",self->fRefl);
|
||||
*/
|
||||
|
||||
/* open hkl-data file */
|
||||
strcpy(pFilename,pRoot);
|
||||
@@ -688,15 +777,10 @@ static int ScanReflection(pMesure self, float twoTheta, SConnection *pCon)
|
||||
|
||||
/* write some header data */
|
||||
SNXFormatTime(pBueffel,1024);
|
||||
/* fprintf(self->fRefl,"filetime = %s\n",pBueffel); */
|
||||
fprintf(self->fHKL,"filetime = %s\n",pBueffel);
|
||||
GetLambda(self->pCryst,&fVal);
|
||||
/* fprintf(self->fRefl,"lambda = %f Angstroem\n",fVal); */
|
||||
fprintf(self->fHKL,"lambda = %f Angstroem\n",fVal);
|
||||
GetUB(self->pCryst,fUB);
|
||||
/* fprintf(self->fRefl,
|
||||
"UB = %7.6f %7.6f %7.6f %7.6f %7.6f %7.6f %7.6f %7.6f %7.6f\n",
|
||||
fUB[0], fUB[1],fUB[2],fUB[3],fUB[4],fUB[5],fUB[6],fUB[7],fUB[8]); */
|
||||
fprintf(self->fHKL,
|
||||
"UB = %7.6f %7.6f %7.6f %7.6f %7.6f %7.6f %7.6f %7.6f %7.6f\n",
|
||||
fUB[0], fUB[1],fUB[2],fUB[3],fUB[4],fUB[5],fUB[6],fUB[7],fUB[8]);
|
||||
@@ -737,6 +821,22 @@ static int ScanReflection(pMesure self, float twoTheta, SConnection *pCon)
|
||||
{
|
||||
MesureClose(self);
|
||||
}
|
||||
|
||||
/* log file */
|
||||
strcpy(pFile,self->pFileRoot);
|
||||
strcat(pFile,"/");
|
||||
strcat(pFile,fileroot);
|
||||
strcat(pFile,".log");
|
||||
self->iLogFile = SCAddLogFile(pCon,pFile);
|
||||
self->pCon = pCon;
|
||||
|
||||
/*
|
||||
No reopening of reflection files in psd mode
|
||||
*/
|
||||
if(self->psd == 1)
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
|
||||
/* check if this is possible */
|
||||
strcpy(pFile,self->pFileRoot);
|
||||
@@ -764,13 +864,6 @@ static int ScanReflection(pMesure self, float twoTheta, SConnection *pCon)
|
||||
strcat(pFile,".rfl");
|
||||
self->fHKL = fopen(pFile,"a");
|
||||
|
||||
/* log file */
|
||||
strcpy(pFile,self->pFileRoot);
|
||||
strcat(pFile,"/");
|
||||
strcat(pFile,fileroot);
|
||||
strcat(pFile,".log");
|
||||
self->iLogFile = SCAddLogFile(pCon,pFile);
|
||||
self->pCon = pCon;
|
||||
|
||||
return 1;
|
||||
}
|
||||
@@ -779,6 +872,16 @@ static int ScanReflection(pMesure self, float twoTheta, SConnection *pCon)
|
||||
{
|
||||
assert(self);
|
||||
|
||||
SCDelLogFile(self->pCon,self->iLogFile);
|
||||
if(self->psd == 1)
|
||||
{
|
||||
self->pCon = NULL;
|
||||
self->iLogFile = -1;
|
||||
if(self->pCurrentFile)
|
||||
free(self->pCurrentFile);
|
||||
return 1;
|
||||
}
|
||||
|
||||
if(self->fRefl)
|
||||
{
|
||||
fclose(self->fRefl);
|
||||
@@ -789,7 +892,6 @@ static int ScanReflection(pMesure self, float twoTheta, SConnection *pCon)
|
||||
fclose(self->fHKL);
|
||||
self->fHKL = NULL;
|
||||
}
|
||||
SCDelLogFile(self->pCon,self->iLogFile);
|
||||
self->pCon = NULL;
|
||||
self->iLogFile = -1;
|
||||
if(self->pCurrentFile)
|
||||
@@ -819,6 +921,14 @@ static int ScanReflection(pMesure self, float twoTheta, SConnection *pCon)
|
||||
}
|
||||
#endif
|
||||
|
||||
/*
|
||||
no writing in PSD mode
|
||||
*/
|
||||
if(self->psd == 1)
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
|
||||
/* get necessary data */
|
||||
fSum = 0.;
|
||||
fSigma = 0.;
|
||||
@@ -850,7 +960,8 @@ static int ScanReflection(pMesure self, float twoTheta, SConnection *pCon)
|
||||
}
|
||||
SCWrite(pCon,pBueffel,eWarning);
|
||||
}
|
||||
GetScanCounts(self->pScanner,self->lCounts,self->np);
|
||||
iNP = GetScanNP(self->pScanner);
|
||||
GetScanCounts(self->pScanner,self->lCounts,iNP);
|
||||
|
||||
/* write it */
|
||||
if(self->fRefl)
|
||||
@@ -891,7 +1002,6 @@ static int ScanReflection(pMesure self, float twoTheta, SConnection *pCon)
|
||||
/* collect data */
|
||||
SNXFormatTime(pBueffel,512);
|
||||
GetScanVarStep(self->pScanner,0,&fStep);
|
||||
iNP = GetScanNP(self->pScanner);
|
||||
fPreset = GetScanPreset(self->pScanner);
|
||||
fprintf(self->fRefl,"%3d %7.3f %9.0f %7.3f %s\n",iNP,fStep,
|
||||
fPreset,fTemp,pBueffel);
|
||||
@@ -1226,6 +1336,18 @@ static int ScanReflection(pMesure self, float twoTheta, SConnection *pCon)
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
else if(strcmp(name,"psd") == 0)
|
||||
{
|
||||
if(fVal >= 1.)
|
||||
{
|
||||
self->psd = 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
self->psd = 0;
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
else if(strcmp(name,"weak") == 0)
|
||||
{
|
||||
if(fVal >= 1.)
|
||||
@@ -1307,6 +1429,11 @@ static int ScanReflection(pMesure self, float twoTheta, SConnection *pCon)
|
||||
*fVal = self->iCompact;
|
||||
return 1;
|
||||
}
|
||||
else if(strcmp(name,"psd") == 0)
|
||||
{
|
||||
*fVal = self->psd;
|
||||
return 1;
|
||||
}
|
||||
else if(strcmp(name,"fastscan") == 0)
|
||||
{
|
||||
*fVal = (float)self->fastScan;
|
||||
|
||||
Reference in New Issue
Block a user