diff --git a/alpha_def b/alpha_def
index 0daf5c61..1d963678 100644
--- a/alpha_def
+++ b/alpha_def
@@ -12,4 +12,4 @@
MFLAGS= -f $(SRC)makefile_alpha$(DUMMY) SRC=$(SRC)
#------------- path to HDF installation
-HDFROOT=/data/lnslib
+HDFROOT=/afs/psi.ch/project/sinq/tru64
diff --git a/doc/manager/nxscript.htm b/doc/manager/nxscript.htm
index 6e11f5cd..3bcf187e 100644
--- a/doc/manager/nxscript.htm
+++ b/doc/manager/nxscript.htm
@@ -76,6 +76,10 @@ definition string for the alias should not contain a dimension
description, this is automatically appended.
nxscript putfloat alias value
Writes a single floating point value to alias alias.
+nxscript putint alias value
+Writes a single integer value to alias alias.
+nxscript updatedictvar alias value
+Updates the dictionary value alis to value.
nscript putmot aliasName motorName
Writes the position of the motor motorName into the NeXus file as
described by aliasName. Theposition is a zero point corrected position. If
diff --git a/fomerge.c b/fomerge.c
index 5948c88e..a5028c82 100644
--- a/fomerge.c
+++ b/fomerge.c
@@ -15,11 +15,20 @@
Mark Koennecke, March 2000
+
+ extended to support nxscripted file writing: Mark Koennecke, May 2004
--------------------------------------------------------------------------*/
#include
#include
#include
+#include "sics.h"
+#include "nxscript.h"
+#include "HistMem.h"
#include "fortify.h"
+#include "scan.h"
+#include "fitcenter.h"
+
+static pFit fitter = NULL;
/* change this in line with HistMem.h */
@@ -402,5 +411,394 @@ int getFMdim(int which)
assert(0);
}
}
+/*---------------------------------------------------------------------*/
+int InstallFocusMerge(SConnection *pCon, SicsInterp *pSics, void *pData,
+ int argc, char *argv[])
+{
+ int status;
+ char pBueffel[256];
+
+ if(argc < 2)
+ {
+ SCWrite(pCon,"ERROR: Insufficient arguments to InstallFocusMerge",
+ eError);
+ return 0;
+ }
+
+ status = initializeFM(argv[1]);
+ if(!status)
+ {
+ snprintf(pBueffel,255,"ERROR: failed to read mergefile %s",
+ argv[1]);
+ SCWrite(pCon,pBueffel,eError);
+ return 0;
+ }
+
+ /* Install command */
+ AddCommand(pSics,"focusmerge",FocusMergeAction,NULL,NULL);
+ return 1;
+}
+/*---------------------------------------------------------------------*/
+static pNXScript checkNXScript(SicsInterp *pSics, char *name)
+{
+ pNXScript result = NULL;
+
+ result = FindCommandData(pSics,name,"NXScript");
+ if(result == NULL)
+ {
+ return NULL;
+ }
+ if(result->fileHandle == NULL || result->dictHandle == NULL)
+ {
+ return NULL;
+ }
+ return result;
+}
+/*---------------------------------------------------------------------*/
+static int updateHMFMData(SicsInterp *pSics, SConnection *pCon)
+{
+ int status, iTime;
+ const float *fTimeBin = NULL;
+ HistInt *data = NULL;
+ pHistMem pMem = NULL;
+
+ pMem = (pHistMem)FindCommandData(pSics,"hm2","HistMem");
+ if(pMem == NULL)
+ {
+ return 0;
+ }
+ fTimeBin = GetHistTimeBin(pMem,&iTime);
+ setFMDataPointer(GetHistogramPointer(pMem,pCon),iTime,MIDDLE);
+
+ pMem = (pHistMem)FindCommandData(pSics,"hm1","HistMem");
+ if(pMem == NULL)
+ {
+ return 0;
+ }
+ setFMDataPointer(GetHistogramPointer(pMem,pCon),iTime,LOWER);
+
+ pMem = (pHistMem)FindCommandData(pSics,"hm3","HistMem");
+ if(pMem == NULL)
+ {
+ return 0;
+ }
+ setFMDataPointer(GetHistogramPointer(pMem,pCon),iTime,UPPER);
+ setFMconfiguration(1,1,1);
+ return 1;
+}
+/*-------------------------------------------------------------------*/
+static int *calculateSum(HistInt *data, int iDet, int iTime)
+{
+ int i, j, iIndex;
+ int *sum = NULL;
+
+ sum = (int *)malloc(iDet*sizeof(int));
+ if(!sum)
+ {
+ return NULL;
+ }
+ memset(sum,0,iDet*sizeof(int));
+
+ for(i = 0; i < iDet; i++)
+ {
+ iIndex = i * iTime;
+ for(j = 0; j < iTime; j++)
+ {
+ sum[i] += data[iIndex+j];
+ }
+ }
+ return sum;
+}
+/*---------------------------------------------------------------------*/
+static int putSum(SicsInterp *pSics, SConnection *pCon,
+ pNXScript nxscript, char *name, char *alias)
+{
+ HistInt *data = NULL;
+ HistInt *sum = NULL;
+ int iDet, iTime, i, j, iIndex, status;
+
+ iTime = getFMdim(TIMEBIN);
+ if(strcmp(name,"upper") == 0)
+ {
+ iDet = getFMdim(UPPER);
+ data = getFMBankPointer(UPPER);
+ }
+ else if(strcmp(name,"middle") == 0)
+ {
+ iDet = getFMdim(MIDDLE);
+ data = getFMBankPointer(MIDDLE);
+ }
+ else if(strcmp(name,"lower") == 0)
+ {
+ iDet = getFMdim(LOWER);
+ data = getFMBankPointer(LOWER);
+ }
+ else if(strcmp(name,"merged") == 0)
+ {
+ iDet = getFMdim(MERGED);
+ data = getFMBankPointer(MERGED);
+ }
+ else
+ {
+ SCWrite(pCon,"ERROR: detector bank to sum not recognised",eError);
+ return NX_ERROR;
+ }
+
+ sum = calculateSum(data,iDet,iTime);
+ if(!sum)
+ {
+ SCWrite(pCon,"ERROR: out of memory summing bank",eError);
+ return NX_ERROR;
+ }
+
+ status = NXDputalias(nxscript->fileHandle,nxscript->dictHandle,
+ alias,sum);
+ free(sum);
+ return status;
+}
+/*---------------------------------------------------------------------*/
+static int putElastic(SicsInterp *pSics, SConnection *pCon,
+ pNXScript pNexus, char *alias, float fElastic)
+{
+
+ int status, iTime, iDet;
+ const float *fTimeBin = NULL;
+ int *sum = NULL;
+ pHistMem pMem = NULL;
+ float fCenter, fFWHM, fStdDev, fVal;
+
+ pMem = (pHistMem)FindCommandData(pSics,"hm2","HistMem");
+ if(pMem == NULL)
+ {
+ SCWrite(pCon,
+ "ERROR: need middle detector bank for elastic peak calculation",
+ eError);
+ return NX_ERROR;
+ }
+ fTimeBin = GetHistTimeBin(pMem,&iTime);
+ iDet = getFMdim(MIDDLE);
+ sum = calculateSum(GetHistogramPointer(pMem,pCon),iDet,iTime);
+ if(!sum)
+ {
+ SCWrite(pCon,"ERROR: out of memory calculating elastic peak position",
+ eError);
+ return NX_ERROR;
+ }
+ if(fitter == NULL)
+ {
+ fitter = CreateFitCenter(NULL);
+ if(!fitter)
+ {
+ SCWrite(pCon,"ERROR: cannot allocate fitting structure",eError);
+ return NX_ERROR;
+ }
+ }
+ status = CalculateFitFromData(fitter,fTimeBin,sum,iTime);
+ if(status != 1)
+ {
+ SCWrite(pCon,"WARNING: problem locating elastic peak",eWarning);
+ }
+ GetFitResults(fitter,&fCenter,&fStdDev,&fFWHM,&fVal);
+ fVal = fCenter - fElastic;
+ if(fVal < 0.)
+ fVal = - fVal;
+ /* bad value, leave at theoretical value */
+ if(fVal > 10.)
+ {
+ SCWrite(pCon,
+ "WARNING: bad fit result, using theoretical elastic peak position",
+ eWarning);
+ }
+ else
+ {
+ fElastic = fCenter;
+ }
+ free(sum);
+
+ status = NXDputalias(pNexus->fileHandle, pNexus->dictHandle,alias,
+ &fElastic);
+ return status;
+
+}
+/*-----------------------------------------------------------------------
+ Usage:
+ focusmerge puttwotheta nxscriptmod bankname alias
+ focusmerge putmerged nxscriptmod alias
+ focusmerge putsum nxscriptmod bankname alias
+ focusmerge putelastic nxscriptmod alias theoelastic
+
+nxscriptmod = name of the nxscript module used for writing, must be open
+alias = The alias under which to write the data item
+theoelastic = theoretical elastic peak position
+------------------------------------------------------------------------*/
+int FocusMergeAction(SConnection *pCon, SicsInterp *pSics, void *pData,
+ int argc, char *argv[])
+{
+ int status;
+ pNXScript pNexus = NULL;
+ float fElastic;
+ char pNum[20];
+
+ if(argc < 2)
+ {
+ SCWrite(pCon,"ERROR: Insufficient arguments to focusmerge",
+ eError);
+ return 0;
+ }
+
+ strtolower(argv[1]);
+ if(strcmp(argv[1],"puttwotheta") == 0)
+ {
+ if(argc < 4)
+ {
+ SCWrite(pCon,"ERROR: Insufficient arguments to focusmerge puttwotheta",
+ eError);
+ return 0;
+ }
+ pNexus = checkNXScript(pSics, argv[2]);
+ if(pNexus == NULL)
+ {
+ SCWrite(pCon,"ERROR: bad nxscript name or NeXus file not open",eError);
+ return 0;
+ }
+ strtolower(argv[3]);
+ if(strcmp(argv[3],"upper") == 0)
+ {
+ status = NXDputalias(pNexus->fileHandle,pNexus->dictHandle,
+ argv[4],getFMBankTheta(UPPER));
+ }
+ else if(strcmp(argv[3],"middle") == 0)
+ {
+ status = NXDputalias(pNexus->fileHandle,pNexus->dictHandle,
+ argv[4],getFMBankTheta(MIDDLE));
+ }
+ else if(strcmp(argv[3],"lower") == 0)
+ {
+ status = NXDputalias(pNexus->fileHandle,pNexus->dictHandle,
+ argv[4],getFMBankTheta(LOWER));
+ }
+ else if(strcmp(argv[3],"merged") == 0)
+ {
+ status = NXDputalias(pNexus->fileHandle,pNexus->dictHandle,
+ argv[4],getFMBankTheta(MERGED));
+ }
+ else
+ {
+ SCWrite(pCon,"ERROR: requested two_theta for invalid detector bank",
+ eError);
+ return 0;
+ }
+ if(status == NX_OK)
+ {
+ SCSendOK(pCon);
+ return 1;
+ }
+ else
+ {
+ SCWrite(pCon,"ERROR: failed to write two theta array to file",eError);
+ return 0;
+ }
+ }
+ else if(strcmp(argv[1],"putmerged") == 0 )
+ {
+ if(argc < 4)
+ {
+ SCWrite(pCon,"ERROR: Insufficient arguments to focusmerge",
+ eError);
+ return 0;
+ }
+ pNexus = checkNXScript(pSics, argv[2]);
+ if(pNexus == NULL)
+ {
+ SCWrite(pCon,"ERROR: bad nxscript name or NeXus file not open",eError);
+ return 0;
+ }
+ if(!updateHMFMData(pSics, pCon))
+ {
+ SCWrite(pCon,"ERROR: not enough HM's to merge or bad names in fomerge.c",
+ eError);
+ return 0;
+ }
+ snprintf(pNum,19,"%d",getFMdim(MERGED));
+ NXDupdate(pNexus->dictHandle,"noofdetectors",pNum);
+ snprintf(pNum,19,"%d",getFMdim(TIMEBIN));
+ NXDupdate(pNexus->dictHandle,"timebin",pNum);
+ status = NXDputalias(pNexus->fileHandle,pNexus->dictHandle,
+ argv[3],getFMBankPointer(MERGED));
+ if(status == NX_OK)
+ {
+ SCSendOK(pCon);
+ return 1;
+ }
+ else
+ {
+ SCWrite(pCon,"ERROR: failed to write merged data to file",eError);
+ return 0;
+ }
+
+ }
+ else if(strcmp(argv[1],"putsum") == 0 )
+ {
+ if(argc < 4)
+ {
+ SCWrite(pCon,"ERROR: Insufficient arguments to focusmerge putsum",
+ eError);
+ return 0;
+ }
+ pNexus = checkNXScript(pSics, argv[2]);
+ if(pNexus == NULL)
+ {
+ SCWrite(pCon,"ERROR: bad nxscript name or NeXus file not open",eError);
+ return 0;
+ }
+ updateHMFMData(pSics, pCon);
+ status = putSum(pSics,pCon,pNexus,argv[3],argv[4]);
+ if(status == NX_OK)
+ {
+ SCSendOK(pCon);
+ return 1;
+ }
+ else
+ {
+ SCWrite(pCon,"ERROR: failed to write summed data to file",eError);
+ return 0;
+ }
+ }
+ else if(strcmp(argv[1],"putelastic") == 0 )
+ {
+ if(argc < 4)
+ {
+ SCWrite(pCon,"ERROR: Insufficient arguments to focusmerge putelastic",
+ eError);
+ return 0;
+ }
+ pNexus = checkNXScript(pSics, argv[2]);
+ if(pNexus == NULL)
+ {
+ SCWrite(pCon,"ERROR: bad nxscript name or NeXus file not open",eError);
+ return 0;
+ }
+ fElastic = atof(argv[4]);
+ status = putElastic(pSics,pCon,pNexus,argv[3],fElastic);
+ if(status == NX_OK)
+ {
+ SCSendOK(pCon);
+ return 1;
+ }
+ else
+ {
+ SCWrite(pCon,"ERROR: failed to write elastic peak position",eError);
+ return 0;
+ }
+ }
+ else
+ {
+ SCWrite(pCon,"ERROR: subcommand to focusmerge not understood",eError);
+ return 0;
+ }
+ return 0;
+}
+
+
diff --git a/fomerge.h b/fomerge.h
index b04ba8ba..89972939 100644
--- a/fomerge.h
+++ b/fomerge.h
@@ -51,7 +51,7 @@
int initializeFM(char *mergefile);
/*
initializes the two-theta and merging data from the file
- mergefile. This must have been cllaed before anything else.
+ mergefile. This must have been called before anything else.
*/
void killFM(void);
@@ -65,7 +65,17 @@
the length of the time binning if TIMEBIN has been specified.
*/
-
+ int InstallFocusMerge(SConnection *pCon, SicsInterp *pSics, void *pData,
+ int argc, char *argv[]);
+ /*
+ install the standalone FocusMerge module
+ */
+ int FocusMergeAction(SConnection *pCon, SicsInterp *pSics, void *pData,
+ int argc, char *argv[]);
+
+ /*
+ FocusMerge interpreter wrapper function
+ */
#endif
diff --git a/nxdict.h b/nxdict.h
index e0acaa3e..17dc1a0f 100644
--- a/nxdict.h
+++ b/nxdict.h
@@ -31,7 +31,6 @@
NXstatus NXDadd(NXdict handle, char *alias, char *DefString);
NXstatus NXDget(NXdict handle, char *alias, char *pBuffer, int iBufLen);
- NXstatus NXDdefget(NXdict handle, char *alias, char *pBuffer, int iBufLen);
NXstatus NXDupdate(NXdict handle, char *alias, char *pNewVal);
NXstatus NXDtextreplace(NXdict handle, char *pDefString, char *pBuffer,
int iBuflen);
diff --git a/nxscript.c b/nxscript.c
index f191c1ee..d6dd170e 100644
--- a/nxscript.c
+++ b/nxscript.c
@@ -29,12 +29,6 @@
#include "udpquieck.h"
#include "nxdict.h"
#include "nxscript.h"
-/*============== a personal data structure ============================*/
-typedef struct {
- pObjectDescriptor pDes;
- NXhandle fileHandle;
- NXdict dictHandle;
-} NXScript, *pNXScript;
/*------------------------------------------------------------------------*/
char *makeFilename(SicsInterp *pSics, SConnection *pCon) {
pSicsVariable pPath = NULL, pPref = NULL, pEnd = NULL;
@@ -64,7 +58,7 @@ char *makeFilename(SicsInterp *pSics, SConnection *pCon) {
/* find length */
iLen = strlen(pPath->text) + 4; /* extra 4 for dir number */
iLen += strlen(pPref->text);
- iLen += 9; /* for number + year */
+ iLen += 10; /* for number + year */
iLen += strlen(pEnd->text);
iLen += 10; /* safety margin */
@@ -109,7 +103,7 @@ char *makeFilename(SicsInterp *pSics, SConnection *pCon) {
sprintf(pNumText,"%4.4d",iYear);
strcat(pRes,pNumText);
strcat(pRes,"n");
- sprintf(pNumText,"%5.5d",iNum);
+ sprintf(pNumText,"%6.6d",iNum);
strcat(pRes,pNumText);
strcat(pRes,pEnd->text);
@@ -721,7 +715,7 @@ static void putGlobal(SConnection *pCon, SicsInterp *pSics,
/*-----------------------------------------------------------------------*/
static int handlePut(SConnection *pCon, SicsInterp *pSics, pNXScript self,
int argc, char *argv[]){
- int status;
+ int status, iVal;
char buffer[1024], defString[1024], numBuf[25];
double dVal;
float fVal;
@@ -749,6 +743,27 @@ static int handlePut(SConnection *pCon, SicsInterp *pSics, pNXScript self,
SCWrite(pCon,buffer,eError);
}
return 1;
+ } else if(strcmp(argv[1],"putint") == 0){
+ if(argc < 4){
+ SCWrite(pCon,"ERROR: insufficient number of arguments to putint",
+ eError);
+ return 1;
+ }
+ status = Tcl_GetInt(InterpGetTcl(pSics),argv[3],&iVal);
+ if(status != TCL_OK){
+ sprintf(buffer,"ERROR: failed to convert %s to int",
+ argv[3]);
+ SCWrite(pCon,buffer,eError);
+ return 1;
+ }
+ status = NXDputalias(self->fileHandle, self->dictHandle,
+ argv[2],&iVal);
+ if(status != NX_OK){
+ sprintf(buffer,"ERROR: failed to write %f to alias %s",
+ iVal, argv[2]);
+ SCWrite(pCon,buffer,eError);
+ }
+ return 1;
} else if (strcmp(argv[1],"puttext") == 0){
/*====================*/
if(argc < 4){
diff --git a/nxscript.h b/nxscript.h
index 8fb88926..8a6a5cc3 100644
--- a/nxscript.h
+++ b/nxscript.h
@@ -11,6 +11,8 @@
------------------------------------------------------------------------*/
#ifndef NXSCRIPT
#define NXSCRIPT
+#include "napi.h"
+#include "nxdict.h"
int MakeNXScript(SConnection *pCon, SicsInterp *pSics, void *pData,
int argc, char *argv[]);
@@ -18,4 +20,11 @@ int NXScriptAction(SConnection *pCon, SicsInterp *pSics, void *pData,
int argc, char *argv[]);
char *makeFilename(SicsInterp *pSics, SConnection *pCon);
+/*============== a personal data structure ============================*/
+typedef struct {
+ pObjectDescriptor pDes;
+ NXhandle fileHandle;
+ NXdict dictHandle;
+} NXScript, *pNXScript;
+
#endif
diff --git a/nxscript.w b/nxscript.w
index cd54dae5..abed3db9 100644
--- a/nxscript.w
+++ b/nxscript.w
@@ -35,8 +35,10 @@ the interface to the interpreter.
Mark Koennecke, February 2003
------------------------------------------------------------------------*/
-#ifndef NXSCRIPT
+#ifndef NXSCRIPTo
#define NXSCRIPT
+#include "napi.h"
+#include "nxdict.h"
int MakeNXScript(SConnection *pCon, SicsInterp *pSics, void *pData,
int argc, char *argv[]);
@@ -44,6 +46,13 @@ int NXScriptAction(SConnection *pCon, SicsInterp *pSics, void *pData,
int argc, char *argv[]);
char *makeFilename(SicsInterp *pSics, SConnection *pCon);
+/*============== a personal data structure ============================*/
+typedef struct {
+ pObjectDescriptor pDes;
+ NXhandle fileHandle;
+ NXdict dictHandle;
+} NXScript, *pNXScript;
+
#endif
@}