PSI sics-cvs-psi-complete-tree-post-site-support
This commit is contained in:
117
hkl.c
117
hkl.c
@@ -18,6 +18,10 @@
|
||||
three detectors.
|
||||
|
||||
Mark Koennecke, May 2002
|
||||
|
||||
Added handling of the chi ==0 or chi == 180 degree case to tryTweakOmega
|
||||
|
||||
Mark Koennecke, December 2003
|
||||
-----------------------------------------------------------------------------*/
|
||||
#include <math.h>
|
||||
#include <ctype.h>
|
||||
@@ -30,11 +34,16 @@
|
||||
#include "matrix/matrix.h"
|
||||
#include "hkl.h"
|
||||
#include "hkl.i"
|
||||
|
||||
#include "splitter.h"
|
||||
/*
|
||||
the space we leave in omega in order to allow for a scan to be done
|
||||
*/
|
||||
#define SCANBORDER 3.
|
||||
/*
|
||||
the tolerance in chi we give before we allow to fix omega with phi
|
||||
*/
|
||||
#define CHITOLERANCE 3.
|
||||
#define ABS(x) (x < 0 ? -(x) : (x))
|
||||
/*-------------------------------------------------------------------------*/
|
||||
static int HKLSave(void *pData, char *name, FILE *fd)
|
||||
{
|
||||
@@ -466,9 +475,22 @@ static int checkNormalBeam(double om, double *gamma, double nu,
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
/*--------------------------------------------------------------------*/
|
||||
static int chiVertical(double chi){
|
||||
if(ABS(chi - .0) < CHITOLERANCE){
|
||||
return 1;
|
||||
}
|
||||
if(ABS(chi - 180.0) < CHITOLERANCE){
|
||||
return 1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
/*-----------------------------------------------------------------------
|
||||
tryOmegaTweak tries to calculate a psi angle in order to put an
|
||||
offending omega back into range.
|
||||
|
||||
This routine also handles the special case when chi ~ 0 or chi ~ 180.
|
||||
Then it is possible to fix a omega problem by turing in phi.
|
||||
-----------------------------------------------------------------------*/
|
||||
static int tryOmegaTweak(pHKL self, MATRIX z1, double *stt, double *om,
|
||||
double *chi, double *phi){
|
||||
@@ -506,6 +528,22 @@ static int tryOmegaTweak(pHKL self, MATRIX z1, double *stt, double *om,
|
||||
omOffset = *om - omTarget;
|
||||
omOffset = -omOffset;
|
||||
|
||||
/*
|
||||
check for the special case of chi == 0 or chi == 180
|
||||
*/
|
||||
if(chiVertical(*chi)){
|
||||
dumstt = *stt;
|
||||
offom = omTarget;
|
||||
offchi = *chi;
|
||||
offphi = *phi - omOffset;
|
||||
if(checkBisecting(self,&dumstt,offom,offchi,offphi)){
|
||||
*om = offom;
|
||||
*chi = offchi;
|
||||
*phi = offphi;
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
calculate angles with omega offset
|
||||
*/
|
||||
@@ -603,16 +641,25 @@ static int calculateBisecting(MATRIX z1, pHKL self, SConnection *pCon,
|
||||
}
|
||||
|
||||
/*
|
||||
giving up!
|
||||
giving up! But calculate one more time in order to show Jurg where
|
||||
he should be.
|
||||
*/
|
||||
for(i = 0; i < 4; i++)
|
||||
{
|
||||
fSet[i] = .0;
|
||||
z1mToBisecting(self->fLambda,z1,&stt,&om,&chi,&phi);
|
||||
if(iRetry == 1){
|
||||
rotatePsi(om,chi,phi,psi,&ompsi,&chipsi,&phipsi);
|
||||
fSet[0] = (float)stt;
|
||||
fSet[1] = (float)ompsi;
|
||||
fSet[2] = (float)chipsi;
|
||||
fSet[3]= (float)phipsi;
|
||||
} else {
|
||||
fSet[0] = (float)stt;
|
||||
fSet[1] = (float)om;
|
||||
fSet[2] = (float)chi;
|
||||
fSet[3]= (float)phi;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
/*----------------------------------------------------------------------*/
|
||||
#define ABS(x) (x < 0 ? -(x) : (x))
|
||||
/*-----------------------------------------------------------------------*/
|
||||
static int calculateNormalBeam(MATRIX z1, pHKL self, SConnection *pCon,
|
||||
float fSet[4], double myPsi, int iRetry)
|
||||
@@ -1140,29 +1187,6 @@ ente:
|
||||
return 1;
|
||||
}
|
||||
/*--------------------------------------------------------------------------*/
|
||||
int isNumeric(char *pText)
|
||||
{
|
||||
int i, ii, iGood;
|
||||
static char pNum[13] = {"1234567890.+-"};
|
||||
|
||||
for(i = 0; i < strlen(pText); i++)
|
||||
{
|
||||
for(ii = 0; ii < 13; ii++)
|
||||
{
|
||||
iGood = 0;
|
||||
if(pText[i] == pNum[ii])
|
||||
{
|
||||
iGood = 1;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if(!iGood)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
/*--------------------------------------------------------------------------*/
|
||||
static int GetCommandData(int argc, char *argv[], float fHKL[3],
|
||||
@@ -1226,6 +1250,7 @@ ente:
|
||||
char pBueffel[512];
|
||||
float fUB[9], fPsi, fVal;
|
||||
float fHKL[3], fSet[4];
|
||||
double dVal;
|
||||
pHKL self = NULL;
|
||||
CommandList *pCom = NULL;
|
||||
pDummy pDum = NULL;
|
||||
@@ -1292,6 +1317,34 @@ ente:
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
else if(strcmp(argv[1],"fromangles") == 0)
|
||||
{
|
||||
if(argc < 6)
|
||||
{
|
||||
SCWrite(pCon,
|
||||
"ERROR: need stt, om, chi,phi to calculate HKL from angles",
|
||||
eError);
|
||||
return 0;
|
||||
}
|
||||
for(i = 0; i < 4; i++)
|
||||
{
|
||||
iRet = Tcl_GetDouble(InterpGetTcl(pSics),argv[i+2],&dVal);
|
||||
if(iRet != TCL_OK)
|
||||
{
|
||||
snprintf(pBueffel,511,"ERROR: failed to convert %s to number",
|
||||
argv[i+2]);
|
||||
SCWrite(pCon,pBueffel,eError);
|
||||
return 0;
|
||||
}
|
||||
fSet[i] = (float)dVal;
|
||||
}
|
||||
angle2HKL(self,(double)fSet[0],(double)fSet[1],
|
||||
(double)fSet[2],(double)fSet[3],fHKL);
|
||||
sprintf(pBueffel,"HKL from angles: %8.4f %8.4f %8.4f ",
|
||||
fHKL[0], fHKL[1],fHKL[2]);
|
||||
SCWrite(pCon,pBueffel,eValue);
|
||||
return 1;
|
||||
}
|
||||
/*------------- lambda */
|
||||
else if(strcmp(argv[1],"lambda") == 0)
|
||||
{
|
||||
@@ -1491,14 +1544,14 @@ ente:
|
||||
}
|
||||
else
|
||||
{
|
||||
sprintf(pBueffel," theta = %f, omega = %f, chi = %f, phi = %f",
|
||||
sprintf(pBueffel," 2-theta = %f, omega = %f, chi = %f, phi = %f",
|
||||
fSet[0], fSet[1], fSet[2],fSet[3]);
|
||||
SCWrite(pCon,pBueffel,eValue);
|
||||
}
|
||||
if(!iRet)
|
||||
{
|
||||
SCWrite(pCon,
|
||||
"WARNING: Settings violate motor limits or cannot be calculated",
|
||||
"WARNING: Cannot drive to the hkl of your desire",
|
||||
eWarning);
|
||||
return 0;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user