PSI sics-cvs-psi-2008-10-02

This commit is contained in:
2008-10-02 00:00:00 +00:00
committed by Douglas Clowes
parent 6e926b813f
commit 4baffb9b7a
304 changed files with 77527 additions and 3612 deletions

337
tasub.c
View File

@@ -9,6 +9,7 @@
#include <assert.h>
#include "sics.h"
#include "lld.h"
#include "trigd.h"
#include "tasub.h"
#include "tasdrive.h"
/*------------------- motor indexes in motor data structure ---------*/
@@ -226,6 +227,13 @@ static int testMotor(ptasUB pNew, SConnection *pCon, char *name, int idx){
return 1;
}
}
/*-------------------------------------------------------------------*/
static void updateTargets(ptasUB pNew, SConnection *pCon){
tasAngles ang;
readTASAngles(pNew,pCon,&ang);
calcTasQEPosition(&pNew->machine, ang, &pNew->target);
}
/*--------------------------------------------------------------------*/
int TasUBFactory(SConnection *pCon,SicsInterp *pSics, void *pData,
int argc, char *argv[]){
@@ -241,6 +249,10 @@ int TasUBFactory(SConnection *pCon,SicsInterp *pSics, void *pData,
SCWrite(pCon,"ERROR: need name to install tasUB",eError);
return 0;
}
if(argc > 2 && argc < 14){
SCWrite(pCon,"ERROR: not enough motor names specified for MakeTasUB",eError);
return 0;
}
pNew = MakeTasUB();
if(pNew == NULL){
SCWrite(pCon,"ERROR: out of memory creating tasUB",eError);
@@ -250,19 +262,39 @@ int TasUBFactory(SConnection *pCon,SicsInterp *pSics, void *pData,
/*
assign motors
*/
pNew->motors[0] = FindMotor(pSics,"a1");
pNew->motors[1] = FindMotor(pSics,"a2");
pNew->motors[2] = FindMotor(pSics,"mcv");
pNew->motors[3] = FindMotor(pSics,"mch");
pNew->motors[4] = FindMotor(pSics,"a3");
pNew->motors[5] = FindMotor(pSics,"a4");
pNew->motors[6] = FindMotor(pSics,"sgu");
pNew->motors[7] = FindMotor(pSics,"sgl");
pNew->motors[8] = FindMotor(pSics,"a5");
pNew->motors[9] = FindMotor(pSics,"a6");
pNew->motors[10] = FindMotor(pSics,"acv");
pNew->motors[11] = FindMotor(pSics,"ach");
if(argc < 14){
/*
* default names and assignement
*/
pNew->motors[0] = FindMotor(pSics,"a1");
pNew->motors[1] = FindMotor(pSics,"a2");
pNew->motors[2] = FindMotor(pSics,"mcv");
pNew->motors[3] = FindMotor(pSics,"mch");
pNew->motors[4] = FindMotor(pSics,"a3");
pNew->motors[5] = FindMotor(pSics,"a4");
pNew->motors[6] = FindMotor(pSics,"sgu");
pNew->motors[7] = FindMotor(pSics,"sgl");
pNew->motors[8] = FindMotor(pSics,"a5");
pNew->motors[9] = FindMotor(pSics,"a6");
pNew->motors[10] = FindMotor(pSics,"acv");
pNew->motors[11] = FindMotor(pSics,"ach");
} else {
/*
* user defined names
*/
pNew->motors[0] = FindMotor(pSics,argv[2]);
pNew->motors[1] = FindMotor(pSics,argv[3]);
pNew->motors[2] = FindMotor(pSics,argv[4]);
pNew->motors[3] = FindMotor(pSics,argv[5]);
pNew->motors[4] = FindMotor(pSics,argv[6]);
pNew->motors[5] = FindMotor(pSics,argv[7]);
pNew->motors[6] = FindMotor(pSics,argv[8]);
pNew->motors[7] = FindMotor(pSics,argv[9]);
pNew->motors[8] = FindMotor(pSics,argv[10]);
pNew->motors[9] = FindMotor(pSics,argv[11]);
pNew->motors[10] = FindMotor(pSics,argv[12]);
pNew->motors[11] = FindMotor(pSics,argv[13]);
}
/*
curvature motors may be missing, anything else is a serious problem
*/
@@ -275,9 +307,10 @@ int TasUBFactory(SConnection *pCon,SicsInterp *pSics, void *pData,
status += testMotor(pNew, pCon,"a5",A5);
status += testMotor(pNew, pCon,"a6",A6);
if(status != 8){
SCWrite(pCon,"ERROR: a required motor is mssing, tasub NOT installed",eError);
return 0;
}
status = AddCommand(pSics,argv[1],
TasUBWrapper,
KillTasUB,
@@ -389,7 +422,7 @@ static int getCrystalParameters(pmaCrystal crystal, SConnection *pCon,
SCWrite(pCon,pBueffel,eValue);
return 1;
}else if(strcmp(argv[2],"vb2") == 0){
snprintf(pBueffel,131,"%s.%s.vb2 = %f",argv[0],argv[1],crystal->VB1);
snprintf(pBueffel,131,"%s.%s.vb2 = %f",argv[0],argv[1],crystal->VB2);
SCWrite(pCon,pBueffel,eValue);
return 1;
}else if(strcmp(argv[2],"ss") == 0){
@@ -849,9 +882,175 @@ static void listDiagnostik(ptasUB self, SConnection *pCon){
status = LLDnodePtr2Next(self->reflectionList);
}
}
/*-----------------------------------------------------------------*/
static int addAuxReflection(ptasUB self, SConnection *pCon,
SicsInterp *pSics, int argc, char *argv[]){
int status;
tasReflection r1, r2;
float value = -999.99;
char pBueffel[256];
MATRIX UB = NULL, B = NULL;
if(argc < 5){
SCWrite(pCon,
"ERROR: not enough arguments auxiliary reflection, need HKL",
eError);
return 0;
}
if(!SCMatchRights(pCon,usUser)){
return 0;
}
status = Tcl_GetDouble(InterpGetTcl(pSics),argv[2],&r2.qe.qh);
if(status != TCL_OK){
snprintf(pBueffel,255,"ERROR: failed to convert %s to number",argv[2]);
SCWrite(pCon,pBueffel,eError);
return 0;
}
status = Tcl_GetDouble(InterpGetTcl(pSics),argv[3],&r2.qe.qk);
if(status != TCL_OK){
snprintf(pBueffel,255,"ERROR: failed to convert %s to number",argv[3]);
SCWrite(pCon,pBueffel,eError);
return 0;
}
status = Tcl_GetDouble(InterpGetTcl(pSics),argv[4],&r2.qe.ql);
if(status != TCL_OK){
snprintf(pBueffel,255,"ERROR: failed to convert %s to number",argv[4]);
SCWrite(pCon,pBueffel,eError);
return 0;
}
B = mat_creat(3,3,ZERO_MATRIX);
if(B == NULL){
SCWrite(pCon,"ERROR: out of memory creating B matrix",eError);
return 0;
}
status = calculateBMatrix(self->cell,B);
if(status < 0){
SCWrite(pCon,"ERROR: bad cell constants, no volume",eError);
mat_free(B);
return 0;
}
status = findReflection(self->reflectionList, 0,&r1);
if(status != 1){
r2.qe.kf = self->current.kf;
r2.qe.ki = self->current.ki;
MotorGetSoftPosition(self->motors[A3],pCon,&value);
r2.angles.a3 = value + 180.;
r2.angles.sgu = .0;
r2.angles.sgl = .0;
calcTwoTheta(B,r2.qe,self->machine.ss_sample,&r2.angles.sample_two_theta);
r1 = r2;
}
status = makeAuxReflection(B, r1, &r2,self->machine.ss_sample);
mat_free(B);
if(status < 0){
SCWrite(pCon,"ERROR: out of memory in makeAuxUB or scattering angle not closed",
eError);
return 0;
}
LLDnodeAppend(self->reflectionList,&r2);
SCSendOK(pCon);
return 1;
}
/*------------------------------------------------------------------*/
static int calcAuxUB(ptasUB self, SConnection *pCon, SicsInterp *pSics,
int argc, char *argv[]){
int status;
tasReflection r1, r2;
char pBueffel[256];
MATRIX UB = NULL, B = NULL;
if(argc < 5){
SCWrite(pCon,
"ERROR: not enough arguments for UB calculation, need HKL of second plane vector",
eError);
return 0;
}
if(!SCMatchRights(pCon,usUser)){
return 0;
}
status = Tcl_GetDouble(InterpGetTcl(pSics),argv[2],&r2.qe.qh);
if(status != TCL_OK){
snprintf(pBueffel,255,"ERROR: failed to convert %s to number",argv[2]);
SCWrite(pCon,pBueffel,eError);
return 0;
}
status = Tcl_GetDouble(InterpGetTcl(pSics),argv[3],&r2.qe.qk);
if(status != TCL_OK){
snprintf(pBueffel,255,"ERROR: failed to convert %s to number",argv[3]);
SCWrite(pCon,pBueffel,eError);
return 0;
}
status = Tcl_GetDouble(InterpGetTcl(pSics),argv[4],&r2.qe.ql);
if(status != TCL_OK){
snprintf(pBueffel,255,"ERROR: failed to convert %s to number",argv[4]);
SCWrite(pCon,pBueffel,eError);
return 0;
}
status = findReflection(self->reflectionList, 0,&r1);
if(status != 1){
snprintf(pBueffel,255,"ERROR: cannot find first reflection");
SCWrite(pCon,pBueffel,eError);
return 0;
}
B = mat_creat(3,3,ZERO_MATRIX);
if(B == NULL){
SCWrite(pCon,"ERROR: out of memory creating B matrix",eError);
return 0;
}
status = calculateBMatrix(self->cell,B);
if(status < 0){
SCWrite(pCon,"ERROR: bad cell constants, no volume",eError);
mat_free(B);
return 0;
}
status = makeAuxReflection(B, r1, &r2,self->machine.ss_sample);
mat_free(B);
if(status < 0){
SCWrite(pCon,"ERROR: out of memory in makeAuxUB",eError);
return 0;
}
UB = calcTasUBFromTwoReflections(self->cell,r1,r2,&status);
if(UB == NULL){
switch(status){
case UBNOMEMORY:
SCWrite(pCon,"ERROR: out of memory calculating UB matrix",eError);
break;
case REC_NO_VOLUME:
SCWrite(pCon,"ERROR: bad cell constants, no volume",eError);
break;
}
return 0;
}
if(mat_det(UB) < .000001){
SCWrite(pCon,"ERROR: invalid UB matrix, check reflections",eError);
return 0;
}
if(self->machine.UB != NULL){
mat_free(self->machine.UB);
}
if(self->machine.planeNormal != NULL){
mat_free(self->machine.planeNormal);
}
self->machine.UB = UB;
self->machine.planeNormal = calcPlaneNormal(r1,r2);
self->ubValid = 1;
SCparChange(pCon);
SCSendOK(pCon);
return 1;
}
/*------------------------------------------------------------------*/
static int calcUB(ptasUB self, SConnection *pCon, SicsInterp *pSics,
int argc, char *argv[]){
int argc, char *argv[]){
int idx1, idx2, status;
tasReflection r1, r2;
char pBueffel[256];
@@ -859,8 +1058,8 @@ static int calcUB(ptasUB self, SConnection *pCon, SicsInterp *pSics,
if(argc < 4){
SCWrite(pCon,
"ERROR: not enough arguments for UB calculation, need index of two reflections",
eError);
"ERROR: not enough arguments for UB calculation, need index of two reflections",
eError);
return 0;
}
@@ -927,6 +1126,54 @@ static int calcUB(ptasUB self, SConnection *pCon, SicsInterp *pSics,
SCparChange(pCon);
return 1;
}
/*-----------------------------------------------------------------*/
static int calcUBFromCell(ptasUB self, SConnection *pCon){
MATRIX B, U, UB;
tasReflection r1;
int status;
B = mat_creat(3,3,UNIT_MATRIX);
U = mat_creat(3,3,UNIT_MATRIX);
status = findReflection(self->reflectionList, 0,&r1);
if(status == 1) {
/*
U[0][0] = Cosd(r1.angles.a3);
U[0][1] = -Sind(r1.angles.a3);
U[1][0] = Sind(r1.angles.a3);
U[1][1] = Cosd(r1.angles.a3);
*/
}
if(B == NULL || U == NULL){
SCWrite(pCon,"ERROR: out of memory in calcUBFromCell",eError);
return 0;
}
status = calculateBMatrix(self->cell,B);
if(status == REC_NO_VOLUME){
SCWrite(pCon,"ERROR: cell has no volume",eError);
return 0;
}
UB = mat_mul(U,B);
if(UB == NULL){
SCWrite(pCon,"ERROR: matrix multiplication failed",eError);
return 0;
}
if(mat_det(UB) < .000001){
SCWrite(pCon,"ERROR: invalid UB matrix, check cell",eError);
return 0;
}
if(self->machine.UB != NULL){
mat_free(self->machine.UB);
}
self->machine.UB = UB;
self->machine.planeNormal[0][0] = .0;
self->machine.planeNormal[1][0] = .0;
self->machine.planeNormal[2][0] = 1.;
self->ubValid = 1;
SCparChange(pCon);
mat_free(U);
mat_free(B);
return 1;
}
/*------------------------------------------------------------------*/
static int calcRefAngles(ptasUB self, SConnection *pCon,
SicsInterp *pSics,
@@ -1198,6 +1445,21 @@ static int setUB(SConnection *pCon, SicsInterp *pSics, ptasUB self,
return 1;
}
/*------------------------------------------------------------------*/
static int getUB(SConnection *pCon, SicsInterp *pSics, ptasUB self,
int argc, char *argv[]){
double value;
char pBueffel[512];
int status;
snprintf(pBueffel,511,"tasub.ub = %f %f %f %f %f %f %f %f %f",
self->machine.UB[0][0], self->machine.UB[0][1], self->machine.UB[0][2],
self->machine.UB[1][0], self->machine.UB[1][1], self->machine.UB[1][2],
self->machine.UB[2][0], self->machine.UB[2][1], self->machine.UB[2][2]);
SCWrite(pCon,pBueffel,eValue);
return 1;
}
/*------------------------------------------------------------------*/
static int setNormal(SConnection *pCon, SicsInterp *pSics, ptasUB self,
int argc, char *argv[]){
double value;
@@ -1370,9 +1632,13 @@ int TasUBWrapper(SConnection *pCon,SicsInterp *pSics, void *pData,
strtolower(argv[1]);
if(strcmp(argv[1],"mono") == 0){
return handleCrystalCommands(&self->machine.monochromator,pCon,argc,argv);
status = handleCrystalCommands(&self->machine.monochromator,pCon,argc,argv);
self->mustRecalculate = 1;
return status;
} else if(strcmp(argv[1],"ana") == 0){
return handleCrystalCommands(&self->machine.analyzer,pCon,argc,argv);
status = handleCrystalCommands(&self->machine.analyzer,pCon,argc,argv);
self->mustRecalculate = 1;
return status;
}else if(strcmp(argv[1],"cell") == 0){
if(argc > 2){
return tasReadCell(pCon,self,argc,argv);
@@ -1396,12 +1662,20 @@ int TasUBWrapper(SConnection *pCon,SicsInterp *pSics, void *pData,
return 1;
} else if(strcmp(argv[1],"makeub") == 0){
return calcUB(self,pCon,pSics,argc,argv);
} else if(strcmp(argv[1],"makeauxub") == 0){
return calcAuxUB(self,pCon,pSics,argc,argv);
} else if(strcmp(argv[1],"addauxref") == 0){
return addAuxReflection(self,pCon,pSics,argc,argv);
} else if(strcmp(argv[1],"makeubfromcell") == 0){
return calcUBFromCell(self,pCon);
} else if(strcmp(argv[1],"calcang") == 0){
return calcRefAngles(self,pCon,pSics,argc,argv);
} else if(strcmp(argv[1],"calcqe") == 0){
return calcQFromAngles(self,pCon,pSics,argc,argv);
} else if(strcmp(argv[1],"setub") == 0){
return setUB(pCon,pSics,self,argc,argv);
} else if(strcmp(argv[1],"getub") == 0){
return getUB(pCon,pSics,self,argc,argv);
} else if(strcmp(argv[1],"setnormal") == 0){
return setNormal(pCon,pSics,self,argc,argv);
} else if(strcmp(argv[1],"settarget") == 0){
@@ -1414,6 +1688,10 @@ int TasUBWrapper(SConnection *pCon,SicsInterp *pSics, void *pData,
return readReflection(pCon,pSics,&self->r1,argc,argv);
} else if(strcmp(argv[1],"r2") == 0){
return readReflection(pCon,pSics,&self->r2,argc,argv);
} else if(strcmp(argv[1],"updatetargets") == 0){
updateTargets(self,pCon);
SCSendOK(pCon);
return 1;
} else if(strcmp(argv[1],"const") == 0){
if(argc > 2){
strtolower(argv[2]);
@@ -1489,6 +1767,25 @@ int TasUBWrapper(SConnection *pCon,SicsInterp *pSics, void *pData,
SCWrite(pCon,pBueffel,eValue);
return 1;
}
} else if(strcmp(argv[1],"silent") == 0){
if(argc > 2){
strtolower(argv[2]);
if(!SCMatchRights(pCon,usUser)){
return 0;
}
status = Tcl_GetInt(InterpGetTcl(pSics),argv[2],&newSS);
if(status != TCL_OK){
SCWrite(pCon,"ERROR: failed to convert argument to number",eError);
return 0;
}
self->silent = newSS;
SCSendOK(pCon);
return 1;
} else {
snprintf(pBueffel,131,"%s.silent = %d",argv[0],self->silent);
SCWrite(pCon,pBueffel,eValue);
return 1;
}
} else {
snprintf(pBueffel,131,"ERROR: subcommand %s to %s not defined",argv[1],
argv[0]);