- 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:
koennecke
2005-03-16 07:58:52 +00:00
parent 5cd7d30d62
commit b8fea0bc38
16 changed files with 331 additions and 2633 deletions

View File

@ -17,10 +17,10 @@
#include "fourtable.h"
/*====================== table entry ===================================*/
typedef struct {
double twoThetaStart;
double twoThetaEnd;
double step;
char scanVar[30];
double step;
int np;
}FourTableEntry, *pFourTableEntry;
/*==================== functions =======================================*/
int MakeFourCircleTable(){
@ -51,8 +51,8 @@ static void printList(int handle, SConnection *pCon){
status = LLDnodePtr2First(handle);
while(status == 1) {
LLDnodeDataTo(handle,&entry);
snprintf(pBueffel,131,"%8.3f %8.3f %s %8.3f\n", entry.twoThetaStart, entry.twoThetaEnd,
entry.scanVar,entry.step);
snprintf(pBueffel,131,"%8.3f %s %8.3f %d\n", entry.twoThetaEnd,
entry.scanVar,entry.step, entry.np);
Tcl_DStringAppend(&list,pBueffel,-1);
printed = 1;
status = LLDnodePtr2Next(handle);
@ -63,6 +63,58 @@ static void printList(int handle, SConnection *pCon){
SCWrite(pCon,Tcl_DStringValue(&list), eValue);
Tcl_DStringFree(&list);
}
/*---------------------------------------------------------------------
Make sure that the entry is added in a sorted way according to two_theta
----------------------------------------------------------------------*/
static void insertEntry(int list, FourTableEntry newEntry){
int status, count = 0, pos;
FourTableEntry test;
/*
locate the last entry bigger then us
*/
status = LLDnodePtr2First(list);
while(status == 1){
LLDnodeDataTo(list,&test);
count++;
if(test.twoThetaEnd == newEntry.twoThetaEnd){
LLDnodeDataFrom(list,&newEntry);
return;
}
if(test.twoThetaEnd > newEntry.twoThetaEnd){
break;
}
status = LLDnodePtr2Next(list);
}
/*
special case: empty list
*/
if(count == 0){
LLDnodeAppendFrom(list,&newEntry);
return;
}
/*
special case: append after last
*/
LLDnodePtr2Last(list);
LLDnodeDataTo(list,&test);
if(newEntry.twoThetaEnd > test.twoThetaEnd){
LLDnodeAppendFrom(list,&newEntry);
return;
}
status = LLDnodePtr2First(list);
pos = 0;
while(status == 1){
LLDnodeDataTo(list,&test);
pos++;
if(pos == count){
LLDnodeInsertFrom(list,&newEntry);
return;
}
status = LLDnodePtr2Next(list);
}
}
/*-----------------------------------------------------------------------*/
static int addToList(int handle, SConnection *pCon, int argc, char *argv[]){
FourTableEntry entry;
@ -74,29 +126,33 @@ static int addToList(int handle, SConnection *pCon, int argc, char *argv[]){
}
if(isNumeric(argv[3])){
entry.twoThetaStart = atof(argv[3]);
entry.twoThetaEnd = atof(argv[3]);
} else {
snprintf(pBueffel,131,"ERROR: expected numeric argument, received %s", argv[3]);
SCWrite(pCon,pBueffel,eError);
return 0;
}
if(isNumeric(argv[4])){
entry.twoThetaEnd = atof(argv[4]);
strncpy(entry.scanVar,argv[4],29);
strtolower(entry.scanVar);
if(strcmp(entry.scanVar,"om") != 0 && strcmp(entry.scanVar,"o2t") != 0){
SCWrite(pCon,"ERROR: Invalied scan variable specified, only om, o2t allowed",eError);
return 0;
}
if(isNumeric(argv[5])){
entry.step = atof(argv[5]);
} else {
snprintf(pBueffel,131,"ERROR: expected numeric argument, received %s", argv[4]);
SCWrite(pCon,pBueffel,eError);
return 0;
}
strncpy(entry.scanVar,argv[5],29);
if(isNumeric(argv[6])){
entry.step = atof(argv[6]);
entry.np = atoi(argv[6]);
} else {
snprintf(pBueffel,131,"ERROR: expected numeric argument, received %s", argv[6]);
SCWrite(pCon,pBueffel,eError);
return 0;
}
LLDnodePrependFrom(handle,&entry);
insertEntry(handle,entry);
return 1;
}
/*-----------------------------------------------------------------------*/
@ -141,6 +197,7 @@ int HandleFourCircleCommands(int handle, SConnection *pCon,
return 1;
}
clearTable(handle);
SCparChange(pCon);
SCSendOK(pCon);
} else if (strcmp(argv[2],"list") == 0){
printList(handle,pCon);
@ -152,6 +209,7 @@ int HandleFourCircleCommands(int handle, SConnection *pCon,
*err = addToList(handle,pCon,argc,argv);
if(*err != 0)
{
SCparChange(pCon);
SCSendOK(pCon);
}
} else if(strcmp(argv[2],"del") == 0){
@ -165,6 +223,7 @@ int HandleFourCircleCommands(int handle, SConnection *pCon,
} else {
if(isNumeric(argv[3])){
delEntry(handle, atoi(argv[3]));
SCparChange(pCon);
SCSendOK(pCon);
} else {
SCWrite(pCon,"ERROR: bad argument: expected numeric argument to table del",eError);
@ -181,15 +240,17 @@ int HandleFourCircleCommands(int handle, SConnection *pCon,
/*-----------------------------------------------------------------------*/
static FourTableEntry findEntry(int handle, double two_theta){
int status;
FourTableEntry entry;
FourTableEntry entry, prevEntry;
status = LLDnodePtr2First(handle);
LLDnodeDataTo(handle,&prevEntry);
while(status == 1) {
LLDnodeDataTo(handle,&entry);
if(two_theta > entry.twoThetaStart && two_theta <= entry.twoThetaEnd){
return entry;
if(entry.twoThetaEnd > two_theta){
return prevEntry;
}
status = LLDnodePtr2Next(handle);
prevEntry = entry;
}
strcpy(entry.scanVar,"NOT FOUND");
return entry;
@ -213,6 +274,17 @@ double GetFourCircleStep(int handle, double two_theta){
}
}
/*------------------------------------------------------------------------*/
int GetFourCircleScanNP(int handle, double two_theta){
FourTableEntry entry;
entry = findEntry(handle,two_theta);
if(strcmp(entry.scanVar,"NOT FOUND") == 0){
return -999;
} else {
return entry.np;
}
}
/*------------------------------------------------------------------------*/
int SaveFourCircleTable(int handle, char *objName, FILE *fd){
FourTableEntry entry;
int status;
@ -221,9 +293,9 @@ int SaveFourCircleTable(int handle, char *objName, FILE *fd){
status = LLDnodePtr2Last(handle);
while(status != 0) {
LLDnodeDataTo(handle,&entry);
fprintf(fd,"%s table add %f %f %s %f\n",objName,
entry.twoThetaStart, entry.twoThetaEnd,entry.scanVar,
entry.step);
fprintf(fd,"%s table add %f %s %f %d\n",objName,
entry.twoThetaEnd,entry.scanVar,
entry.step,entry.np);
status = LLDnodePtr2Prev(handle);
}
return 1;