- Introduced a general Hipadaba table module and modified the four

circle codes to use it.
- Added to functions to histmem, getdelay and formattof,  to support new HM
- Removed obsolete mesure.*
This commit is contained in:
koennecke
2009-03-16 14:24:34 +00:00
parent 299ad44be3
commit 3e8b11675a
15 changed files with 948 additions and 2519 deletions

View File

@ -41,7 +41,7 @@ extern void SNXFormatTime(char *pBueffel, int iLen);
typedef struct {
FILE *profFile; /* file with reflection profiles, ccl */
FILE *hklFile; /* file with integrated intensities */
int stepTable; /* table with the scan parameters */
pSICSOBJ stepTable; /* table with the scan parameters */
char *currentFileRoot;
pSICSOBJ messList;
pHdb currentRefl; /* the current reflection being measured */
@ -90,7 +90,7 @@ static int FourMessAction(SConnection * pCon, SicsInterp * pSics,
}
if (strcmp(argv[1], "table") == 0) {
return HandleFourCircleCommands(&priv->stepTable, pCon,
return HandleFourCircleCommands(priv->stepTable, pCon,
argc, argv, &err);
}
@ -774,7 +774,7 @@ static int FourMessSave(void *data, char *name, FILE * fd)
pFourMess priv = self->pPrivate;
SaveSICSOBJ(data, name, fd);
SaveFourCircleTable(priv->stepTable, name, fd);
priv->stepTable->pDes->SaveStatus(priv->stepTable,"fmess table", fd);
return 1;
}
@ -878,6 +878,7 @@ void InstallFourMess(SConnection * pCon, SicsInterp * pSics)
MakeHipadabaCallback(SetScannerCB, priv, NULL));
priv->pScanner = FindCommandData(pSics, "xxxscan", "ScanObject");
AddHipadabaChild(pNew->objectNode, priv->stepTable->objectNode,pCon);
AddCommand(pSics, "fmess", FourMessAction, KillSICSOBJ, pNew);
}

View File

@ -6,196 +6,105 @@
copyright: see copyright.h
Mark Koennecke, February 2005
Massively reworked to make use of the new hdbtable object.
Mark Koennecke, March 2009
---------------------------------------------------------------------------*/
#include <stdlib.h>
#include <assert.h>
#include "sics.h"
#include "fortify.h"
#include "lld.h"
#include <tcl.h>
#include "splitter.h"
#include "hdbtable.h"
#include <sicshipadaba.h>
#include "fourtable.h"
/*====================== table entry ===================================*/
typedef struct {
double twoThetaEnd;
char scanVar[30];
double step;
int np;
float preset;
} FourTableEntry, *pFourTableEntry;
/*==================== functions =======================================*/
int MakeFourCircleTable()
pSICSOBJ MakeFourCircleTable()
{
return LLDcreate(sizeof(FourTableEntry));
pSICSOBJ table = NULL;
pHdb node = NULL;
table = MakeHdbTable("fmesstable","FourMess");
node = GetHipadabaNode(table->objectNode,"template");
assert(node != NULL);
AddSICSHdbPar(node, "endTTH", usUser, MakeHdbFloat(.0));
AddSICSHdbPar(node, "scanvar", usUser, MakeHdbText(""));
AddSICSHdbPar(node, "step", usUser, MakeHdbFloat(.0));
AddSICSHdbPar(node, "np", usUser, MakeHdbInt(0));
AddSICSHdbPar(node, "preset", usUser, MakeHdbFloat(.0));
ReadTableTemplate(table, NULL);
return table;
}
/*-----------------------------------------------------------------------*/
void DeleteFourCircleTable(int handle)
void DeleteFourCircleTable(pSICSOBJ data)
{
LLDdelete(handle);
KillSICSOBJ(data);
}
/*------------------------------------------------------------------------*/
static void printList(int handle, SConnection * pCon)
{
FourTableEntry entry;
char pBueffel[132];
int status, printed = 0;
Tcl_DString list;
Tcl_DStringInit(&list);
status = LLDnodePtr2First(handle);
while (status == 1) {
LLDnodeDataTo(handle, &entry);
snprintf(pBueffel, 131, "%8.3f %10s %8.3f %d %8.3f\n",
entry.twoThetaEnd, entry.scanVar, entry.step, entry.np,
entry.preset);
Tcl_DStringAppend(&list, pBueffel, -1);
printed = 1;
status = LLDnodePtr2Next(handle);
}
if (printed == 0) {
Tcl_DStringAppend(&list, "table is empty", -1);
}
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)
----------------------------------------------------------------------*/
static int rowCompare(const void *r1, const void *r2)
{
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);
}
pHdb *row1, *row2;
pHdb tth1, tth2;
row1 = (pHdb *)r1;
row2 = (pHdb *)r2;
tth1 = GetHipadabaNode(*row1,"endTTH");
tth2 = GetHipadabaNode(*row2,"endTTH");
assert(tth1 != NULL && tth2 != NULL);
if(tth1->value.v.doubleValue < tth2->value.v.doubleValue){
return -1;
} else if(tth1->value.v.doubleValue > tth2->value.v.doubleValue){
return 1;
} else {
return 0;
}
}
/*-----------------------------------------------------------------------*/
static int addToList(int handle, SConnection * pCon, int argc,
char *argv[])
/*--------------------------------------------------------------------*/
static void sortFourTable(pSICSOBJ self)
{
FourTableEntry entry;
char pBueffel[132];
if (argc < 7) {
SCWrite(pCon, "ERROR: not enough arguments to table add", eError);
return 0;
}
if (isNumeric(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;
}
strncpy(entry.scanVar, argv[4], 29);
strtolower(entry.scanVar);
if (strcmp(entry.scanVar, "om") != 0
&& strstr(entry.scanVar, "o2t") == NULL) {
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;
}
if (isNumeric(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;
}
entry.preset = -1.0;
if (argc > 7) {
if (isNumeric(argv[7])) {
entry.preset = atof(argv[7]);
}
}
insertEntry(handle, entry);
return 1;
pHdb data, *dataArray, child;
int count, i;
char number[10];
data = GetHipadabaNode(self->objectNode,"data");
assert(data != NULL);
count = CountHdbChildren(data);
if(count <= 1){
return;
}
dataArray = malloc(count*sizeof(pHdb));
if(dataArray == NULL){
return;
}
child = data->child;
count = 0;
while(child != NULL){
dataArray[count] = child;
count++;
child = child->next;
}
qsort(dataArray, count, sizeof(pHdb), rowCompare);
data->child = NULL;
for(i = 0; i < count; i++){
snprintf(number,10,"%4.4d", i);
child = dataArray[i];
if(child->name != NULL){
free(child->name);
}
child->name = strdup(number);
AddHipadabaChild(data,child, NULL);
}
free(dataArray);
}
/*-----------------------------------------------------------------------*/
static void delEntry(int handle, int index)
{
int count = 0, status;
status = LLDnodePtr2First(handle);
while (status == 1) {
if (count == index) {
LLDnodeDelete(handle);
break;
} else {
count++;
status = LLDnodePtr2Next(handle);
}
}
}
/*------------------------------------------------------------------------*/
int HandleFourCircleCommands(int *table, SConnection * pCon,
int HandleFourCircleCommands(pSICSOBJ self, SConnection * pCon,
int argc, char *argv[], int *err)
{
int handle;
*err = 1;
handle = *table;
int status;
/*
test if this is for us
*/
@ -208,141 +117,84 @@ int HandleFourCircleCommands(int *table, SConnection * pCon,
return 0;
}
/*
what are we supposed to do?
*/
strtolower(argv[2]);
if (strcmp(argv[2], "clear") == 0) {
if (!SCMatchRights(pCon, usUser)) {
*err = 0;
return 1;
}
LLDdelete(handle);
handle = LLDcreate(sizeof(FourTableEntry));
*table = handle;
SCparChange(pCon);
SCSendOK(pCon);
} else if (strcmp(argv[2], "list") == 0) {
printList(handle, pCon);
} else if (strcmp(argv[2], "add") == 0) {
if (!SCMatchRights(pCon, usUser)) {
*err = 0;
return 1;
}
*err = addToList(handle, pCon, argc, argv);
if (*err != 0) {
SCparChange(pCon);
SCSendOK(pCon);
}
} else if (strcmp(argv[2], "del") == 0) {
if (!SCMatchRights(pCon, usUser)) {
*err = 0;
return 1;
}
if (argc < 4) {
SCWrite(pCon, "ERROR: insufficnet number of arguments to table del",
eError);
*err = 0;
} 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);
*err = 0;
}
}
} else {
SCWrite(pCon, "ERROR: subcommand to table not known", eError);
*err = 0;
status = InvokeSICSOBJ(pCon,pServ->pSics,self,argc-1,&argv[1]);
if(strcmp(argv[2],"addrow") == 0){
sortFourTable(self);
}
return 1;
return status;
}
/*-----------------------------------------------------------------------*/
static FourTableEntry findEntry(int handle, double two_theta)
static pHdb findEntry(pSICSOBJ self, double two_theta)
{
int status;
FourTableEntry entry;
status = LLDnodePtr2First(handle);
while (status == 1) {
LLDnodeDataTo(handle, &entry);
if (entry.twoThetaEnd > two_theta) {
return entry;
}
status = LLDnodePtr2Next(handle);
}
strcpy(entry.scanVar, "NOT FOUND");
return entry;
pHdb data, row, tth;
data = GetHipadabaNode(self->objectNode,"data");
assert(data != NULL);
row = data->child;
while(row != NULL){
tth = GetHipadabaNode(row,"endTTH");
if(tth != NULL){
if(tth->value.v.doubleValue > two_theta){
return row;
}
}
row = row->next;
}
return NULL;
}
/*------------------------------------------------------------------------*/
char *GetFourCircleScanVar(int handle, double two_theta)
char *GetFourCircleScanVar(pSICSOBJ handle, double two_theta)
{
FourTableEntry entry;
entry = findEntry(handle, two_theta);
return strdup(entry.scanVar);
}
/*------------------------------------------------------------------------*/
double GetFourCircleStep(int handle, double two_theta)
{
FourTableEntry entry;
entry = findEntry(handle, two_theta);
if (strcmp(entry.scanVar, "NOT FOUND") == 0) {
return -999.99;
} else {
return entry.step;
pHdb row, val;
row = findEntry(handle, two_theta);
if(row != NULL){
val = GetHipadabaNode(row,"scanvar");
if(val != NULL){
return strdup(val->value.v.text);
}
}
return strdup("Not found");
}
/*------------------------------------------------------------------------*/
float GetFourCirclePreset(int handle, double two_theta)
double GetFourCircleStep(pSICSOBJ handle, double two_theta)
{
FourTableEntry entry;
entry = findEntry(handle, two_theta);
if (strcmp(entry.scanVar, "NOT FOUND") == 0) {
return -999.99;
} else {
return entry.preset;
}
pHdb row, val;
row = findEntry(handle, two_theta);
if(row != NULL){
val = GetHipadabaNode(row,"step");
if(val != NULL){
return val->value.v.doubleValue;
}
}
return -999.99;
}
/*------------------------------------------------------------------------*/
int GetFourCircleScanNP(int handle, double two_theta)
float GetFourCirclePreset(pSICSOBJ handle, double two_theta)
{
FourTableEntry entry;
entry = findEntry(handle, two_theta);
if (strcmp(entry.scanVar, "NOT FOUND") == 0) {
return -999;
} else {
return entry.np;
}
pHdb row, val;
row = findEntry(handle, two_theta);
if(row != NULL){
val = GetHipadabaNode(row,"preset");
if(val != NULL){
return val->value.v.doubleValue;
}
}
return -999.99;
}
/*------------------------------------------------------------------------*/
int SaveFourCircleTable(int handle, char *objName, FILE * fd)
int GetFourCircleScanNP(pSICSOBJ handle, double two_theta)
{
FourTableEntry entry;
int status;
fprintf(fd, "%s table clear\n", objName);
status = LLDnodePtr2Last(handle);
while (status != 0) {
LLDnodeDataTo(handle, &entry);
fprintf(fd, "%s table add %f %s %f %d %f\n", objName,
entry.twoThetaEnd, entry.scanVar,
entry.step, entry.np, entry.preset);
status = LLDnodePtr2Prev(handle);
}
return 1;
pHdb row, val;
row = findEntry(handle, two_theta);
if(row != NULL){
val = GetHipadabaNode(row,"np");
if(val != NULL){
return val->value.v.intValue;
}
}
return 1;
}

View File

@ -10,15 +10,15 @@
---------------------------------------------------------------------------*/
#ifndef FOURTABLE
#define FOURTABLE
#include <sicsobj.h>
int MakeFourCircleTable();
void DeleteFourCircleTable(int handle);
int HandleFourCircleCommands(int *handle, SConnection * pCon,
pSICSOBJ MakeFourCircleTable();
void DeleteFourCircleTable(pSICSOBJ self);
int HandleFourCircleCommands(pSICSOBJ self, SConnection * pCon,
int argc, char *argv[], int *err);
char *GetFourCircleScanVar(int handle, double two_theta);
double GetFourCircleStep(int handle, double two_theta);
int SaveFourCircleTable(int handle, char *objName, FILE * fd);
float GetFourCirclePreset(int handle, double twoTheta);
int GetFourCircleScanNP(int handle, double twoTheta);
char *GetFourCircleScanVar(pSICSOBJ self, double two_theta);
double GetFourCircleStep(pSICSOBJ self, double two_theta);
float GetFourCirclePreset(pSICSOBJ self, double twoTheta);
int GetFourCircleScanNP(pSICSOBJ self, double twoTheta);
#endif

381
hdbtable.c Normal file
View File

@ -0,0 +1,381 @@
/**
* Hdbtable is a more generic implementation for a table based on a Hipadaba
* tree structure. This table will be used at various instances in SICS. The general
* approach is that there is a child node called template whose children will be
* the nodes describing each column. Another entry called data will hold the
* rows of the table. Each row is a clone of the template. The result is
* an inefficient mapping of a table into a tree. But then, for smaller tables this
* is good enough and fits nicely into the Hipadaba and gumtree schemes. This file
* provides a couple of commands to deal with such tables. A user of this module will
* have to add content to the template first. And then run readtemplate in order
* to activate the new structure.
*
* I use a descriptor key called rowcount for the row ID management rather then
* the private data structure. This leaves clients of this module to use the
* private data structure at will.
*
* copyright: see file COPYRIGHT
*
* Mark Koennecke, March 2009
*/
#include <stdlib.h>
#include "sicshipadaba.h"
#include <hdbtable.h>
/*------------------------------------------------------------------------*/
int SaveHdbTable(void *data, char *name, FILE * fd)
{
pSICSOBJ self = (pSICSOBJ) data;
pHdb datanode, row, child;
pDynString val;
datanode = GetHipadabaNode(self->objectNode,"data");
assert(datanode != NULL);
row = datanode->child;
while(row != NULL){
fprintf(fd,"%s addrow ", name);
child = row->child;
while(child != NULL){
val = formatValue(child->value, child);
if(val != NULL){
fprintf(fd," %s", GetCharArray(val));
DeleteDynString(val);
}
child = child->next;
}
fprintf(fd,"\n");
row = row->next;
}
return 1;
}
/*------------------------------------------------------------------------*/
static int ClearTblCmd(pSICSOBJ self, SConnection *pCon, pHdb commandNode,
pHdb par[], int nPar)
{
pHdb node;
node = GetHipadabaNode(self->objectNode,"data");
if(node != NULL){
DeleteNodeData(node);
RemoveHdbNodeFromParent(node, pCon);
}
node = MakeHipadabaNode("data",HIPNONE,1);
if(node == NULL){
SCWrite(pCon,"ERROR: out of memory in ClearTblCmd", eError);
return 0;
}
AddHipadabaChild(self->objectNode,node,NULL);
SetDescriptorKey(self->pDes,"rowcount","0");
if(pCon != NULL){
SCparChange(pCon);
}
return 1;
}
/*----------------------------------------------------------------------*/
static int AddTblRowCmd(pSICSOBJ self, SConnection *pCon, pHdb commandNode,
pHdb par[], int nPar)
{
int count;
char *ct, number[10];
pHdb row, val, child, template;
ct = GetDescriptorKey(self->pDes,"rowcount");
count = atoi(ct);
snprintf(number,10,"%4.4d", count);
row = MakeHipadabaNode(number,HIPNONE,1);
if(row == NULL){
SCWrite(pCon,"ERROR: out of memory in AddTblRow", eError);
return 0;
}
count++;
snprintf(number,10,"%d",count);
SetDescriptorKey(self->pDes,"rowcount",number);
SetHdbProperty(row,"__save","true");
template = GetHipadabaNode(self->objectNode,"template");
assert(template != NULL);
child = template->child;
count = 0;
while(child != NULL){
val = MakeHipadabaNode(child->name,child->value.dataType, child->value.arrayLength);
if(count < nPar){
UpdateHipadabaPar(val,par[count]->value,pCon);
}
AddHipadabaChild(row,val, pCon);
SetHdbProperty(val,"__save","true");
count++;
child = child->next;
}
child = GetHipadabaNode(self->objectNode,"data");
assert(child != NULL);
AddHipadabaChild(child,row, pCon);
if(pCon != NULL){
SCparChange(pCon);
}
return 1;
}
/*----------------------------------------------------------------------*/
static int RepTblRowCmd(pSICSOBJ self, SConnection *pCon, pHdb commandNode,
pHdb par[], int nPar)
{
int count;
char path[132];
pHdb row, val, child;
snprintf(path,131,"data/%s", par[0]->value.v.text);
row = GetHipadabaNode(self->objectNode,path);
if(row == NULL){
SCPrintf(pCon,eError,"ERROR: row with ID %s not found", par[0]->value.v.text);
return 0;
}
child = row->child;
count = 1;
while(child != NULL){
if(count < nPar){
UpdateHipadabaPar(child,par[count]->value,pCon);
}
count++;
child = child->next;
}
if(pCon != NULL){
SCparChange(pCon);
}
return 1;
}
/*----------------------------------------------------------------------
* ReadTemplateCmd does something interesting: it rewrites the parameter
* lists of both addrow and reprow according to the template
* ---------------------------------------------------------------------*/
int ReadTableTemplate(pSICSOBJ self, SConnection *con)
{
pHdb node, template, child, cmd;
SConnection *pCon = con;
if(pCon == NULL){
pCon = pServ->dummyCon;
}
template = GetHipadabaNode(self->objectNode,"template");
assert(template != NULL);
node = GetHipadabaNode(self->objectNode,"addrow");
if(node != NULL){
DeleteHipadabaNode(node,pCon);
}
cmd = AddSICSHdbPar(self->objectNode, "addrow", usUser,
MakeSICSFunc(AddTblRowCmd));
if(cmd == NULL){
SCWrite(pCon,"ERROR: out of memory in ReadTemplateCmd",eError );
return 0;
}
child = template->child;
while(child != NULL){
node = MakeHipadabaNode(child->name, child->value.dataType, child->value.arrayLength);
if(node == NULL){
SCWrite(pCon,"ERROR: out of memory in ReadTemplateCmd",eError );
return 0;
}
AddHipadabaChild(cmd,node,pCon);
child = child->next;
}
cmd = AddSICSHdbPar(self->objectNode, "reprow", usUser,
MakeSICSFunc(AddTblRowCmd));
if(cmd == NULL){
SCWrite(pCon,"ERROR: out of memory in ReadTemplateCmd",eError );
return 0;
}
node = MakeHipadabaNode("id",HIPTEXT,1);
AddHipadabaChild(cmd,node, pCon);
child = template->child;
while(child != NULL){
node = MakeHipadabaNode(child->name, child->value.dataType, child->value.arrayLength);
if(node == NULL){
SCWrite(pCon,"ERROR: out of memory in ReadTemplateCmd",eError );
return 0;
}
AddHipadabaChild(cmd,node,pCon);
child = child->next;
}
return 1;
}
/*----------------------------------------------------------------------*/
static int ReadTemplateCmd(pSICSOBJ self, SConnection *pCon, pHdb commandNode,
pHdb par[], int nPar)
{
return ReadTableTemplate(self,pCon);
}
/*----------------------------------------------------------------------*/
static int DelRowCmd(pSICSOBJ self, SConnection *pCon, pHdb commandNode,
pHdb par[], int nPar)
{
pHdb row = NULL;
char path[132];
if(nPar < 1){
SCWrite(pCon,"ERROR: need ID of row to kill",eError);
return 0;
}
snprintf(path,132,"data/%s",par[0]->value.v.text);
row = GetHipadabaNode(self->objectNode,path);
if(row == NULL){
SCPrintf(pCon,eError,"ERROR: row with ID %s not found", par[0]->value.v.text);
return 0;
}
DeleteHipadabaNode(row,pCon);
if(pCon != NULL){
SCparChange(pCon);
}
SCSendOK(pCon);
return 1;
}
/*----------------------------------------------------------------------*/
static int GetRowCmd(pSICSOBJ self, SConnection *pCon, pHdb commandNode,
pHdb par[], int nPar)
{
pHdb row = NULL, child;
char path[132];
pDynString result, val;
if(nPar < 1){
SCWrite(pCon,"ERROR: need ID of row to read",eError);
return 0;
}
snprintf(path,132,"data/%s",par[0]->value.v.text);
row = GetHipadabaNode(self->objectNode,path);
if(row == NULL){
SCPrintf(pCon,eError,"ERROR: row with ID %s not found", par[0]->value.v.text);
return 0;
}
result = CreateDynString(128,128);
if(result == NULL){
SCWrite(pCon,"ERROR: out of memory in GetRowCmd", eError);
return 0;
}
child = row->child;
while(child != NULL){
val = formatValue(child->value, child);
if(val != NULL){
DynStringConcat(result,GetCharArray(val));
if(child->next != NULL){
DynStringConcatChar(result,',');
}
DeleteDynString(val);
}
child = child->next;
}
SCWrite(pCon,GetCharArray(result),eValue);
DeleteDynString(result);
return 1;
}
/*----------------------------------------------------------------------*/
static int ListTblCmd(pSICSOBJ self, SConnection *pCon, pHdb commandNode,
pHdb par[], int nPar)
{
pHdb node, row, child, data, template;
char buffer[20];
pDynString list = NULL, val;
list = CreateDynString(25,256);
if(list == NULL){
SCWrite(pCon,"ERROR: out of memory in LisTblCmd", eError);
return 0;
}
/*
* create the list header
*/
DynStringConcat(list," ID");
template = GetHipadabaNode(self->objectNode,"template");
assert(template != NULL);
child = template->child;
while(child != NULL){
snprintf(buffer,20," %8s", child->name);
DynStringConcat(list,buffer);
child = child->next;
}
DynStringConcatChar(list,'\n');
data = GetHipadabaNode(self->objectNode,"data");
assert(data != NULL);
/*
* list the data
*/
row = data->child;
while(row != NULL){
snprintf(buffer,20," %8s", row->name);
DynStringConcat(list,buffer);
child = row->child;
while(child != NULL){
val = formatValue(child->value,child);
snprintf(buffer,20," %8s", GetCharArray(val));
DynStringConcat(list,buffer);
DeleteDynString(val);
child = child->next;
}
DynStringConcatChar(list,'\n');
row = row->next;
}
SCWrite(pCon,GetCharArray(list),eValue);
DeleteDynString(list);
return 1;
}
/*----------------------------------------------------------------------*/
pSICSOBJ MakeHdbTable(char *name, char *hdbclass)
{
pSICSOBJ result = NULL;
pHdb node, cmd;
result = MakeSICSOBJv(name,hdbclass,HIPNONE,usSpy);
if(result == NULL){
return NULL;
}
SetDescriptorKey(result->pDes,"rowcount","0");
SetHdbProperty(result->objectNode,"viewer","mountaingumui.TableViewer");
result->pDes->SaveStatus = SaveHdbTable;
node = MakeHipadabaNode("template",HIPNONE,1);
if(node == NULL){
return NULL;
}
SetHdbProperty(node,"__save","true");
AddHipadabaChild(result->objectNode,node,NULL);
node = MakeHipadabaNode("data",HIPNONE,1);
if(node == NULL){
return NULL;
}
SetHdbProperty(node,"__save","true");
AddHipadabaChild(result->objectNode,node,NULL);
cmd = AddSICSHdbPar(result->objectNode, "clear", usUser,
MakeSICSFunc(ClearTblCmd));
cmd = AddSICSHdbPar(result->objectNode, "print", usUser,
MakeSICSFunc(ListTblCmd));
cmd = AddSICSHdbPar(result->objectNode, "addrow", usUser,
MakeSICSFunc(AddTblRowCmd));
cmd = AddSICSHdbPar(result->objectNode, "reprow", usUser,
MakeSICSFunc(RepTblRowCmd));
cmd = AddSICSHdbPar(result->objectNode, "readtemplate", usUser,
MakeSICSFunc(ReadTemplateCmd));
cmd = AddSICSHdbPar(result->objectNode, "del", usUser,
MakeSICSFunc(DelRowCmd));
node = MakeHipadabaNode("id",HIPTEXT,1);
AddHipadabaChild(cmd,node, NULL);
cmd = AddSICSHdbPar(result->objectNode, "get", usUser,
MakeSICSFunc(GetRowCmd));
node = MakeHipadabaNode("id",HIPTEXT,1);
AddHipadabaChild(cmd,node, NULL);
return result;
}

16
hdbtable.h Normal file
View File

@ -0,0 +1,16 @@
/**
* Hdbtable is a more generic implementation for a table based on a Hipadaba
* tree structure. This table will be used at various instances in SICS.
*
* copyright: see file COPYRIGHT
*
* Mark Koennecke, March 2009
*/
#ifndef HDBTABLE_H_
#define HDBTABLE_H_
#include <sicsobj.h>
pSICSOBJ MakeHdbTable(char *name, char *hdbclass);
int ReadTableTemplate(pSICSOBJ self, SConnection *con);
#endif /*HDBTABLE_H_*/

View File

@ -202,7 +202,7 @@ int InvokeCallbackChain(pHdb node, pHdbMessage message)
}
/*-----------------------------------------------------------------------*/
static void SendTreeChangeMessage(pHdb node, void *callData)
void SendTreeChangeMessage(pHdb node, void *callData)
{
hdbTreeChangeMessage treeChangeMes;
treeChangeMes.type = treeChange;

View File

@ -274,6 +274,13 @@ void AddHipadabaChild(pHdb parent, pHdb child, void *callData);
* @param node The node to delete.
*/
void DeleteNodeData(pHdb node);
/**
* Send a treechange message for node.
* @param node The node whose child list has changed
* @param calldata The connection or calldata associated with this operation.
*/
void SendTreeChangeMessage(pHdb node, void *callData);
/**
* delete a hipadaba node and all its children. Then invoke the tree
* change callback to notify listeners.

View File

@ -12,6 +12,11 @@
Refactored data handling into separater HMdata class.
Mark Koennecke, January 2003
Added function to retrieve time delay and to format TOF bin array in order
to speed up TOF configuration for new http based HM's
Mark Koennecke, March 2009
Copyright:
@ -1034,7 +1039,40 @@ void HMListOption(pHistMem self, SConnection * pCon)
}
/*--------------------------------------------------------------------------*/
static pDynString formatTOF(pHistMem self)
{
const float *timebin;
int iLength, i, delay, delta;
char number[20];
pDynString result = NULL;
timebin = GetHistTimeBin(self, &iLength);
if(timebin != NULL){
delay = timebin[0];
result = CreateDynString(512,512);
if(result == NULL){
return NULL;
}
for(i = 0; i < iLength; i++){
snprintf(number,20," %12d", (int)(timebin[i] - delay));
DynStringConcat(result,number);
if(i % 5 == 0 && i != 0){
DynStringConcatChar(result,'\n');
}
}
/*
* add the extra one
*/
if(iLength > 3){
delta = timebin[iLength -2] - timebin[iLength -1];
}
snprintf(number,20," %12d", (int)(timebin[iLength -1] + delta));
DynStringConcat(result,number);
return result;
} else {
return NULL;
}
}
/*--------------------------------------------------------------------------*/
int HistAction(SConnection * pCon, SicsInterp * pSics, void *pData,
int argc, char *argv[])
@ -1049,6 +1087,7 @@ int HistAction(SConnection * pCon, SicsInterp * pSics, void *pData,
long lVal;
HistInt *lData = NULL;
int iStart, iEnd, iNum, i;
pDynString tofres = NULL;
CounterMode eCount;
char *pMode[] = {
"timer",
@ -1527,6 +1566,28 @@ int HistAction(SConnection * pCon, SicsInterp * pSics, void *pData,
Tcl_DStringFree(&tResult);
return 1;
}
/* getdelay */
else if(strcmp(argv[1],"getdelay") == 0){
if(self->pDriv->data->nTimeChan > 1) {
SCPrintf(pCon,eValue,"hm.delay = %d", self->pDriv->data->timeBinning[0]);
return 1;
} else {
SCPrintf(pCon,eError,"ERROR: no TOF configured");
return 0;
}
}
/* formattof */
else if(strcmp(argv[1],"formattof") == 0){
tofres = formatTOF(self);
if(tofres == NULL){
SCWrite(pCon,"ERROR: out of memory or not TOF", eError);
return 0;
} else {
SCWrite(pCon,GetCharArray(tofres), eValue);
DeleteDynString(tofres);
return 1;
}
}
/* generate time binning */
else if (strcmp(argv[1], "genbin") == 0) {
if (isRunning(self->pCountInt)) {

View File

@ -18,7 +18,7 @@ SOBJ = network.o ifile.o conman.o SCinter.o splitter.o passwd.o \
danu.o nxdict.o varlog.o stptok.o nread.o trigd.o cell.o\
scan.o fitcenter.o telnet.o token.o wwildcard.o hklmot.o\
tclev.o hkl.o integrate.o optimise.o dynstring.o nxutil.o \
mesure.o uubuffer.o commandlog.o udpquieck.o fourtable.o\
uubuffer.o commandlog.o udpquieck.o fourtable.o\
rmtrail.o help.o nxupdate.o confvirtualmot.o vector.o\
simchop.o choco.o chadapter.o trim.o scaldate.o tasub.o\
xytable.o exebuf.o exeman.o ubfour.o ubcalc.o\
@ -40,7 +40,7 @@ SOBJ = network.o ifile.o conman.o SCinter.o splitter.o passwd.o \
sctdriveadapter.o sctdriveobj.o reflist.o singlex.o fourmess.o \
sgclib.o sgfind.o sgio.o sgsi.o sghkl.o singlediff.o singlebi.o \
singlenb.o simindex.o simidx.o uselect.o singletas.o motorsec.o \
rwpuffer.o asynnet.o background.o countersec.o
rwpuffer.o asynnet.o background.o countersec.o hdbtable.o
MOTOROBJ = motor.o simdriv.o
COUNTEROBJ = countdriv.o simcter.o counter.o

1692
mesure.c

File diff suppressed because it is too large Load Diff

View File

@ -1,45 +0,0 @@
/*----------------------------------------------------------------------------
M E S U R E
A SICS object for doing four circle measurements with a single
counter.
copyright: see copyright.h
Mark Koennecke, April 1998
Heavily reworked: Mark Koennecke, February-March 2005
---------------------------------------------------------------------------*/
#ifndef SICSMESURE
#define SICSMESURE
typedef struct __Mesure *pMesure;
/*--------------------- live & death --------------------------------------*/
pMesure CreateMesure(pHKL pCryst, pScanData pScanner,
pMotor pOmega, char *pom,
pMotor p2Theta, char *p2t,
char *pFileRoot, pDataNumber pDanu,
char *headerTemplate);
void DeleteMesure(void *pData);
int MesureFactory(SConnection * pCon, SicsInterp * pSics, void *pData,
int argc, char *argv[]);
/*------------------- object functions -----------------------------------*/
int MesureReflection(pMesure self, float fHKL[3], float fPsi,
SConnection * pCon);
int MesureGenReflection(pMesure self, float fHKL[3], float fSet[4],
SConnection * pCon);
int MesureStart(pMesure self, SConnection * pCon);
int MesureReopen(pMesure self, char *filename, SConnection * pCon);
int MesureClose(pMesure self);
int MesureFile(pMesure self, char *pFile, int iSkip, SConnection * pCon);
int MesureGenFile(pMesure self, char *pFile, int iSkip,
SConnection * pCon);
int MesureSetPar(pMesure self, char *name, float fVal);
int MesureGetPar(pMesure self, char *name, float *fVal);
int MesureAction(SConnection * pCon, SicsInterp * pSics, void *pData,
int argc, char *argv[]);
#endif

2
ofac.c
View File

@ -80,7 +80,6 @@
#include "token.h"
#include "hkl.h"
#include "optimise.h"
#include "mesure.h"
#include "commandlog.h"
#include "udpquieck.h"
#include "choco.h"
@ -291,7 +290,6 @@ static void InitIniCommands(SicsInterp * pInter, pTaskMan pTask)
AddCommand(pInter, "MakePeakCenter", FitFactory, NULL, NULL);
AddCommand(pInter, "MakeHKL", HKLFactory, NULL, NULL);
AddCommand(pInter, "MakeOptimise", MakeOptimiser, NULL, NULL);
AddCommand(pInter, "MakeMesure", MesureFactory, NULL, NULL);
AddCommand(pInter, "kill_command", SICSKill, NULL, NULL);
AddCommand(pInter, "MakeChopper", ChocoFactory, NULL, NULL);
AddCommand(pInter, "ChopperAdapter", CHAdapterFactory, NULL, NULL);

765
reflist.c

File diff suppressed because it is too large Load Diff

View File

@ -6,6 +6,7 @@
* Mark Koennecke, July 2007
*/
#include <stdio.h>
#include <stdarg.h>
#include <sics.h>
#include <tcl.h>
#include "assert.h"
@ -186,7 +187,26 @@ static int assignPar(pHdb node, SConnection * pCon, char *data)
}
return 1;
}
/*---------------------------------------------------------------------------*/
int runObjFunction(pSICSOBJ object, SConnection *pCon, pHdb commandNode)
{
pHdb parArray[64], child;
int status, count = 0;
SICSOBJFunc pFunc = NULL;
assert(commandNode != NULL);
child = commandNode->child;
while(child != NULL){
parArray[count] = child;
count++;
child = child->next;
}
pFunc = (SICSOBJFunc)commandNode->value.v.func;
assert(pFunc != NULL);
status = pFunc(object, pCon, commandNode, parArray, count);
return status;
}
/*---------------------------------------------------------------------------*/
static int invokeOBJFunction(pSICSOBJ object, pHdb commandNode,
SConnection * pCon, int argc, char *argv[])
@ -210,7 +230,7 @@ static int invokeOBJFunction(pSICSOBJ object, pHdb commandNode,
count = 1;
goto invoke;
}
/*
* assign parameters and fill parameter array for function at the same
* time. Be lenient about missing parameters: Then the old values will

View File

@ -9,6 +9,7 @@
#define SICSOBJ2_H_
#include <stdio.h>
#include <hipadaba.h>
#include "sics.h"
/*======================================================================
* Be careful when changing this data structure. It has to be compatible
* in its first fields with the SICS object descriptor as defined in
@ -43,6 +44,16 @@ int SaveSICSOBJ(void *data, char *name, FILE * fd);
*/
pSICSOBJ SetupSICSOBJ(SConnection * pCon, SicsInterp * pSics, void *pData,
int argc, char *argv[]);
/**
* runObjectFunction is an internal function for running an existing object
* command. The user has to search the node first, prime the parameters,
* and then call this command to actually execute.
* @param object The object on which the command is executed
* @param pCon a connection to use for error reporting
* @param commandNode The node to invoke.
*/
int runObjFunction(pSICSOBJ object, SConnection *pCon, pHdb commandNode);
/*====================== Interpreter Interface ===========================
* InvokeSICSObj is special in that it returns -1 if it cannot handle
* the command. This leaves calling code the opportunity to process