- Fixed sign problems with om in tasub
- Mended tasdrive to drive energy even if Q is askew - Fixed QM values - Fixed problems in mesure: om2th, wrong theta selection - Fixed core dump when driving h,kl, failed
This commit is contained in:
251
tasub.c
251
tasub.c
@ -53,6 +53,7 @@ static void saveReflections(ptasUB self, char *name, FILE *fd){
|
||||
/*-------------------------------------------------------------------*/
|
||||
static int tasUBSave(void *pData, char *name, FILE *fd){
|
||||
ptasUB self = (ptasUB)pData;
|
||||
tasReflection r;
|
||||
|
||||
if(self == NULL){
|
||||
return 0;
|
||||
@ -83,8 +84,16 @@ static int tasUBSave(void *pData, char *name, FILE *fd){
|
||||
name,
|
||||
self->target.qh, self->target.qk, self->target.ql, self->target.qm,
|
||||
self->target.ki, self->target.kf);
|
||||
fprintf(fd,"%s setidx %d %d\n",
|
||||
name, self->r1, self->r2);
|
||||
r = self->r1;
|
||||
fprintf(fd,"%s r1 %6.2f %6.2f %6.2f %6.2f %6.2f %6.2f %6.2f %6.2f %6.2f\n",
|
||||
name, r.qe.qh, r.qe.qk, r.qe.ql, r.angles.a3, r.angles.sample_two_theta,
|
||||
r.angles.sgu, r.angles.sgl,
|
||||
KtoEnergy(r.qe.ki), KtoEnergy(r.qe.kf));
|
||||
r = self->r2;
|
||||
fprintf(fd,"%s r2 %6.2f %6.2f %6.2f %6.2f %6.2f %6.2f %6.2f %6.2f %6.2f\n",
|
||||
name, r.qe.qh, r.qe.qk, r.qe.ql, r.angles.a3, r.angles.sample_two_theta,
|
||||
r.angles.sgu, r.angles.sgl,
|
||||
KtoEnergy(r.qe.ki), KtoEnergy(r.qe.kf));
|
||||
fprintf(fd,"%s update\n", name);
|
||||
return 1;
|
||||
}
|
||||
@ -455,6 +464,8 @@ static int tasReadCell(SConnection *pCon, ptasUB self, int argc, char *argv[]){
|
||||
SCWrite(pCon,pBueffel,eError);
|
||||
return 0;
|
||||
}
|
||||
self->ubValid = 0;
|
||||
SCWrite(pCon,"WARNING: UB is now invalid",eWarning);
|
||||
SCparChange(pCon);
|
||||
SCSendOK(pCon);
|
||||
return 1;
|
||||
@ -477,8 +488,7 @@ static void clearReflections(ptasUB self){
|
||||
LLDnodeDelete(self->reflectionList);
|
||||
status = LLDnodePtr2Next(self->reflectionList);
|
||||
}
|
||||
self->r1 = -1;
|
||||
self->r2 = -1;
|
||||
self->ubValid = 0;
|
||||
}
|
||||
/*------------------------------------------------------------------*/
|
||||
static void listReflections(ptasUB self, SConnection *pCon){
|
||||
@ -621,6 +631,84 @@ static int addReflection(ptasUB self, SicsInterp *pSics,
|
||||
SCparChange(pCon);
|
||||
return 1;
|
||||
}
|
||||
/*------------------------------------------------------------------------------*/
|
||||
static int readReflection(SConnection *pCon, SicsInterp *pSics,
|
||||
ptasReflection res,
|
||||
int argc, char *argv[]){
|
||||
tasReflection r;
|
||||
int status;
|
||||
char pBueffel[256];
|
||||
|
||||
if(!SCMatchRights(pCon,usUser)){
|
||||
return 0;
|
||||
}
|
||||
|
||||
if(argc < 11){
|
||||
SCWrite(pCon,"ERROR: not enough parameters to read reflection",eError);
|
||||
return 0;
|
||||
}
|
||||
status = Tcl_GetDouble(InterpGetTcl(pSics),argv[2],&r.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],&r.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],&r.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 = Tcl_GetDouble(InterpGetTcl(pSics),argv[5],&r.angles.a3);
|
||||
if(status != TCL_OK){
|
||||
snprintf(pBueffel,255,"ERROR: failed to convert %s to number",argv[5]);
|
||||
SCWrite(pCon,pBueffel,eError);
|
||||
return 0;
|
||||
}
|
||||
status = Tcl_GetDouble(InterpGetTcl(pSics),argv[6],&r.angles.sample_two_theta);
|
||||
if(status != TCL_OK){
|
||||
snprintf(pBueffel,255,"ERROR: failed to convert %s to number",argv[6]);
|
||||
SCWrite(pCon,pBueffel,eError);
|
||||
return 0;
|
||||
}
|
||||
status = Tcl_GetDouble(InterpGetTcl(pSics),argv[7],&r.angles.sgu);
|
||||
if(status != TCL_OK){
|
||||
snprintf(pBueffel,255,"ERROR: failed to convert %s to number",argv[7]);
|
||||
SCWrite(pCon,pBueffel,eError);
|
||||
return 0;
|
||||
}
|
||||
status = Tcl_GetDouble(InterpGetTcl(pSics),argv[8],&r.angles.sgl);
|
||||
if(status != TCL_OK){
|
||||
snprintf(pBueffel,255,"ERROR: failed to convert %s to number",argv[8]);
|
||||
SCWrite(pCon,pBueffel,eError);
|
||||
return 0;
|
||||
}
|
||||
status = Tcl_GetDouble(InterpGetTcl(pSics),argv[9],&r.qe.ki);
|
||||
if(status != TCL_OK){
|
||||
snprintf(pBueffel,255,"ERROR: failed to convert %s to number",argv[9]);
|
||||
SCWrite(pCon,pBueffel,eError);
|
||||
return 0;
|
||||
}
|
||||
r.qe.ki = energyToK(r.qe.ki);
|
||||
status = Tcl_GetDouble(InterpGetTcl(pSics),argv[10],&r.qe.kf);
|
||||
if(status != TCL_OK){
|
||||
snprintf(pBueffel,255,"ERROR: failed to convert %s to number",argv[10]);
|
||||
SCWrite(pCon,pBueffel,eError);
|
||||
return 0;
|
||||
}
|
||||
r.qe.kf = energyToK(r.qe.kf);
|
||||
if(ABS(r.qe.ki - r.qe.kf) > .01) {
|
||||
SCWrite(pCon,"WARNING: KI != KF!",eWarning);
|
||||
}
|
||||
*res = r;
|
||||
return 1;
|
||||
}
|
||||
/*-----------------------------------------------------------------*/
|
||||
int findReflection(int list, int idx, ptasReflection r){
|
||||
int count = 0;
|
||||
@ -642,7 +730,7 @@ static void listUB(ptasUB self , SConnection *pCon){
|
||||
Tcl_DString list;
|
||||
char pBueffel[255];
|
||||
int i;
|
||||
|
||||
tasReflection r;
|
||||
|
||||
Tcl_DStringInit(&list);
|
||||
if(self->machine.UB == NULL){
|
||||
@ -658,9 +746,32 @@ static void listUB(ptasUB self , SConnection *pCon){
|
||||
Tcl_DStringAppend(&list,pBueffel,-1);
|
||||
}
|
||||
}
|
||||
snprintf(pBueffel,255,"UB generated from reflections %d and %d in list\n",
|
||||
self->r1, self->r2);
|
||||
snprintf(pBueffel,255,"UB generated from reflections:\n");
|
||||
Tcl_DStringAppend(&list,pBueffel,-1);
|
||||
snprintf(pBueffel,255,
|
||||
" QH QK QL A3 A4 SGU SGL EI EF\n");
|
||||
Tcl_DStringAppend(&list,pBueffel,-1);
|
||||
r = self->r1;
|
||||
snprintf(pBueffel,255,
|
||||
" %8.4f %8.4f %8.4f %7.2f %7.2f %6.2f %6.2f %6.2f %6.2f\n",
|
||||
r.qe.qh, r.qe.qk, r.qe.ql, r.angles.a3,
|
||||
r.angles.sample_two_theta, r.angles.sgu, r.angles.sgl,
|
||||
KtoEnergy(r.qe.ki), KtoEnergy(r.qe.kf));
|
||||
Tcl_DStringAppend(&list,pBueffel,-1);
|
||||
r = self->r2;
|
||||
snprintf(pBueffel,255,
|
||||
" %8.4f %8.4f %8.4f %7.2f %7.2f %6.2f %6.2f %6.2f %6.2f\n",
|
||||
r.qe.qh, r.qe.qk, r.qe.ql, r.angles.a3,
|
||||
r.angles.sample_two_theta, r.angles.sgu, r.angles.sgl,
|
||||
KtoEnergy(r.qe.ki), KtoEnergy(r.qe.kf));
|
||||
Tcl_DStringAppend(&list,pBueffel,-1);
|
||||
snprintf(pBueffel,255,"Plane Normal: %8.4f %8.4f %8.4f\n",
|
||||
self->machine.planeNormal[0][0], self->machine.planeNormal[1][0],
|
||||
self->machine.planeNormal[2][0]);
|
||||
Tcl_DStringAppend(&list,pBueffel,-1);
|
||||
if(self->ubValid == 0){
|
||||
Tcl_DStringAppend(&list,"WARNING: UB matrix is invalid\n",-1);
|
||||
}
|
||||
SCWrite(pCon,Tcl_DStringValue(&list),eValue);
|
||||
Tcl_DStringFree(&list);
|
||||
}
|
||||
@ -723,7 +834,7 @@ static void listDiagnostik(ptasUB self, SConnection *pCon){
|
||||
/*------------------------------------------------------------------*/
|
||||
static int calcUB(ptasUB self, SConnection *pCon, SicsInterp *pSics,
|
||||
int argc, char *argv[]){
|
||||
int idx, status;
|
||||
int idx1, idx2, status;
|
||||
tasReflection r1, r2;
|
||||
char pBueffel[256];
|
||||
MATRIX UB = NULL;
|
||||
@ -739,32 +850,32 @@ static int calcUB(ptasUB self, SConnection *pCon, SicsInterp *pSics,
|
||||
return 0;
|
||||
}
|
||||
|
||||
status = Tcl_GetInt(InterpGetTcl(pSics),argv[2],&idx);
|
||||
status = Tcl_GetInt(InterpGetTcl(pSics),argv[2],&idx1);
|
||||
if(status != TCL_OK){
|
||||
snprintf(pBueffel,255,"ERROR: failed to convert %s to number",argv[2]);
|
||||
SCWrite(pCon,pBueffel,eError);
|
||||
return 0;
|
||||
}
|
||||
status = findReflection(self->reflectionList, idx-1,&r1);
|
||||
idx1--;
|
||||
status = findReflection(self->reflectionList, idx1,&r1);
|
||||
if(status != 1){
|
||||
snprintf(pBueffel,255,"ERROR: cannot find reflection with index %d",idx);
|
||||
snprintf(pBueffel,255,"ERROR: cannot find reflection with index %d",idx1+1);
|
||||
SCWrite(pCon,pBueffel,eError);
|
||||
return 0;
|
||||
}
|
||||
self->r1 = idx;
|
||||
status = Tcl_GetInt(InterpGetTcl(pSics),argv[3],&idx);
|
||||
status = Tcl_GetInt(InterpGetTcl(pSics),argv[3],&idx2);
|
||||
if(status != TCL_OK){
|
||||
snprintf(pBueffel,255,"ERROR: failed to convert %s to number",argv[3]);
|
||||
SCWrite(pCon,pBueffel,eError);
|
||||
return 0;
|
||||
}
|
||||
status = findReflection(self->reflectionList, idx-1,&r2);
|
||||
idx2--;
|
||||
status = findReflection(self->reflectionList, idx2,&r2);
|
||||
if(status != 1){
|
||||
snprintf(pBueffel,255,"ERROR: cannot find reflection with index %d",idx);
|
||||
snprintf(pBueffel,255,"ERROR: cannot find reflection with index %d",idx2+1);
|
||||
SCWrite(pCon,pBueffel,eError);
|
||||
return 0;
|
||||
}
|
||||
self->r2 = idx;
|
||||
|
||||
UB = calcTasUBFromTwoReflections(self->cell,r1,r2,&status);
|
||||
if(UB == NULL){
|
||||
@ -778,6 +889,10 @@ static int calcUB(ptasUB self, SConnection *pCon, SicsInterp *pSics,
|
||||
}
|
||||
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);
|
||||
}
|
||||
@ -786,6 +901,9 @@ static int calcUB(ptasUB self, SConnection *pCon, SicsInterp *pSics,
|
||||
}
|
||||
self->machine.UB = UB;
|
||||
self->machine.planeNormal = calcPlaneNormal(r1,r2);
|
||||
self->r1 = r1;
|
||||
self->r2 = r2;
|
||||
self->ubValid = 1;
|
||||
listUB(self,pCon);
|
||||
listDiagnostik(self,pCon);
|
||||
SCparChange(pCon);
|
||||
@ -866,6 +984,74 @@ static int calcRefAngles(ptasUB self, SConnection *pCon,
|
||||
return 1;
|
||||
}
|
||||
/*------------------------------------------------------------------*/
|
||||
static int calcQFromAngles(ptasUB self, SConnection *pCon,
|
||||
SicsInterp *pSics,
|
||||
int argc, char *argv[]){
|
||||
tasQEPosition q;
|
||||
tasAngles angles;
|
||||
char pBueffel[256];
|
||||
int status;
|
||||
|
||||
if(argc < 8){
|
||||
SCWrite(pCon,"ERROR: need a2, a3, a4, sgu, sgl, a6 for calculation",
|
||||
eError);
|
||||
return 0;
|
||||
}
|
||||
status = Tcl_GetDouble(InterpGetTcl(pSics),argv[2],
|
||||
&angles.monochromator_two_theta);
|
||||
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],&angles.a3);
|
||||
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],&angles.sample_two_theta);
|
||||
if(status != TCL_OK){
|
||||
snprintf(pBueffel,255,"ERROR: failed to convert %s to number",argv[4]);
|
||||
SCWrite(pCon,pBueffel,eError);
|
||||
return 0;
|
||||
}
|
||||
status = Tcl_GetDouble(InterpGetTcl(pSics),argv[5],&angles.sgu);
|
||||
if(status != TCL_OK){
|
||||
snprintf(pBueffel,255,"ERROR: failed to convert %s to number",argv[5]);
|
||||
SCWrite(pCon,pBueffel,eError);
|
||||
return 0;
|
||||
}
|
||||
status = Tcl_GetDouble(InterpGetTcl(pSics),argv[6],&angles.sgl);
|
||||
if(status != TCL_OK){
|
||||
snprintf(pBueffel,255,"ERROR: failed to convert %s to number",argv[6]);
|
||||
SCWrite(pCon,pBueffel,eError);
|
||||
return 0;
|
||||
}
|
||||
status = Tcl_GetDouble(InterpGetTcl(pSics),argv[7],&angles.analyzer_two_theta);
|
||||
if(status != TCL_OK){
|
||||
snprintf(pBueffel,255,"ERROR: failed to convert %s to number",argv[7]);
|
||||
SCWrite(pCon,pBueffel,eError);
|
||||
return 0;
|
||||
}
|
||||
status = calcTasQEPosition(&self->machine,angles,&q);
|
||||
switch(status){
|
||||
case UBNOMEMORY:
|
||||
SCWrite(pCon,"ERROR: Out of memory calculating angles",eError);
|
||||
return 0;
|
||||
break;
|
||||
}
|
||||
|
||||
snprintf(pBueffel,255,"%8.4f %8.4f %8.4f %8.4f %8.4f",
|
||||
q.qh,
|
||||
q.qk,
|
||||
q.ql,
|
||||
KtoEnergy(q.ki),
|
||||
KtoEnergy(q.kf));
|
||||
SCWrite(pCon,pBueffel,eValue);
|
||||
return 1;
|
||||
}
|
||||
/*------------------------------------------------------------------*/
|
||||
static int setUB(SConnection *pCon, SicsInterp *pSics, ptasUB self,
|
||||
int argc, char *argv[]){
|
||||
double value;
|
||||
@ -953,28 +1139,13 @@ static int setUB(SConnection *pCon, SicsInterp *pSics, ptasUB self,
|
||||
return 0;
|
||||
}
|
||||
self->machine.UB[2][2] = value;
|
||||
self->ubValid = 1;
|
||||
SCSendOK(pCon);
|
||||
SCparChange(pCon);
|
||||
|
||||
return 1;
|
||||
}
|
||||
/*------------------------------------------------------------------*/
|
||||
static int setIDX(SConnection *pCon, SicsInterp *pSics, ptasUB self,
|
||||
int argc, char *argv[]){
|
||||
if(argc < 4) {
|
||||
SCWrite(pCon,"ERROR: not enough arguments to setidx", eError);
|
||||
return 0;
|
||||
}
|
||||
|
||||
if(!SCMatchRights(pCon,usMugger)){
|
||||
return 0;
|
||||
}
|
||||
self->r1 = atoi(argv[2]);
|
||||
self->r2 = atoi(argv[3]);
|
||||
SCSendOK(pCon);
|
||||
return 1;
|
||||
}
|
||||
/*------------------------------------------------------------------*/
|
||||
static int setNormal(SConnection *pCon, SicsInterp *pSics, ptasUB self,
|
||||
int argc, char *argv[]){
|
||||
double value;
|
||||
@ -1114,11 +1285,6 @@ static int deleteReflection(SConnection *pCon, SicsInterp *pSics,
|
||||
SCWrite(pCon,pBueffel,eError);
|
||||
return 0;
|
||||
}
|
||||
if(idx == self->r1 || idx == self->r2) {
|
||||
SCWrite(pCon,"ERROR: I refuse to delete reflections used for current UB",
|
||||
eError);
|
||||
return 0;
|
||||
}
|
||||
idx--;
|
||||
status = LLDnodePtr2First(self->reflectionList);
|
||||
while(status == 1){
|
||||
@ -1162,6 +1328,7 @@ int TasUBWrapper(SConnection *pCon,SicsInterp *pSics, void *pData,
|
||||
} else if(strcmp(argv[1],"clear") == 0){
|
||||
clearReflections(self);
|
||||
clearReflections(self);
|
||||
SCWrite(pCon,"WARNING: UB is now invalid",eWarning);
|
||||
SCSendOK(pCon);
|
||||
return 1;
|
||||
} else if(strcmp(argv[1],"listref") == 0){
|
||||
@ -1174,20 +1341,24 @@ 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],"calcref") == 0){
|
||||
} 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],"setnormal") == 0){
|
||||
return setNormal(pCon,pSics,self,argc,argv);
|
||||
} else if(strcmp(argv[1],"setidx") == 0){
|
||||
return setIDX(pCon,pSics,self,argc,argv);
|
||||
} else if(strcmp(argv[1],"settarget") == 0){
|
||||
return setTarget(pCon,pSics,self,argc,argv);
|
||||
} else if(strcmp(argv[1],"update") == 0){
|
||||
return tasUpdate(pCon,self);
|
||||
} else if(strcmp(argv[1],"del") == 0){
|
||||
return deleteReflection(pCon,pSics,self,argc,argv);
|
||||
} else if(strcmp(argv[1],"r1") == 0){
|
||||
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],"const") == 0){
|
||||
if(argc > 2){
|
||||
strtolower(argv[2]);
|
||||
|
Reference in New Issue
Block a user