Save polar angle
r1621 | ffr | 2007-03-12 08:28:11 +1100 (Mon, 12 Mar 2007) | 2 lines
This commit is contained in:
committed by
Douglas Clowes
parent
7527e7f6f3
commit
d729b37e1a
314
nxscript.c
314
nxscript.c
@@ -33,6 +33,95 @@
|
||||
|
||||
extern char *trim(char *str);
|
||||
|
||||
/*ANSTO MOD START */
|
||||
static void putArray(SConnection *pCon, SicsInterp *pSics,
|
||||
pNXScript self,
|
||||
int argc, char *argv[]){
|
||||
float *data = NULL;
|
||||
int length, i, status;
|
||||
char num[20];
|
||||
char buffer[256], defString[512], *varData;
|
||||
Tcl_Interp *tcl = NULL;
|
||||
double dVal;
|
||||
|
||||
if(argc < 5){
|
||||
SCWrite(pCon,"ERROR: insufficient number of arguments to array",
|
||||
eError);
|
||||
return;
|
||||
}
|
||||
tcl = InterpGetTcl(pSics);
|
||||
assert(tcl != NULL);
|
||||
|
||||
/*
|
||||
get array length
|
||||
*/
|
||||
status = Tcl_GetInt(tcl,argv[4],&length);
|
||||
if(status != TCL_OK){
|
||||
sprintf(buffer,"ERROR: failed to convert %s to integer",argv[4]);
|
||||
SCWrite(pCon,buffer,eError);
|
||||
return;
|
||||
}
|
||||
|
||||
/*
|
||||
allocate
|
||||
*/
|
||||
if(length > 0){
|
||||
data = (float *)malloc(length*sizeof(float));
|
||||
}
|
||||
if(data == NULL){
|
||||
snprintf(buffer,255,
|
||||
"ERROR: out of memory or invalid length at %s, length = %s",
|
||||
argv[2],argv[4]);
|
||||
SCWrite(pCon,buffer,eError);
|
||||
return;
|
||||
}
|
||||
memset(data,0,length*sizeof(float));
|
||||
|
||||
/*
|
||||
try getting data
|
||||
*/
|
||||
for(i = 0; i < length; i++){
|
||||
sprintf(num,"%d",i);
|
||||
varData = (char *)Tcl_GetVar2(tcl,argv[3],num,0);
|
||||
if(varData != NULL){
|
||||
status = Tcl_GetDouble(tcl,varData,&dVal);
|
||||
if(status != TCL_OK){
|
||||
sprintf(buffer,"ERROR: failed to convert %s to double",
|
||||
varData);
|
||||
SCWrite(pCon,buffer,eError);
|
||||
}
|
||||
data[i] = (float)dVal;
|
||||
} else {
|
||||
snprintf(buffer,254,"WARNING: failed to find array element %d", i);
|
||||
SCWrite(pCon,buffer,eError);
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
build definition string
|
||||
*/
|
||||
status = NXDdefget(self->dictHandle,argv[2],buffer,254);
|
||||
if(!status){
|
||||
sprintf(buffer,"ERROR: alias %s for array not found",
|
||||
argv[2]);
|
||||
SCWrite(pCon,buffer,eError);
|
||||
free(data);
|
||||
return;
|
||||
}
|
||||
snprintf(defString,511,"%s -dim {%d} ",buffer,length);
|
||||
|
||||
/*
|
||||
write it!
|
||||
*/
|
||||
status = NXDputdef(self->fileHandle,self->dictHandle,defString,data);
|
||||
if(status != NX_OK){
|
||||
sprintf(buffer,"ERROR: failed to write array");
|
||||
SCWrite(pCon,buffer,eError);
|
||||
}
|
||||
free(data);
|
||||
SCSendOK(pCon);
|
||||
}
|
||||
/* ANSTO MOD END */
|
||||
/* missing in nxdict.h: */
|
||||
NXstatus NXDdefget(NXdict handle, char *pKey, char *pBuffer, int iBufLen);
|
||||
/*------------------------------------------------------------------------*/
|
||||
@@ -715,6 +804,138 @@ static void putTimeBinning(SConnection *pCon, SicsInterp *pSics,
|
||||
return;
|
||||
}
|
||||
/*----------------------------------------------------------------------*/
|
||||
/**\brief Calculates polar angles on a 2D grid for cylindrical detectors.
|
||||
*
|
||||
* param dradius detector radius
|
||||
* param angsep angular separation between detector columns in radians
|
||||
* param active_height_mm of a detector in mm
|
||||
* param det_rot_rad detector rotation in radians
|
||||
* param row_zero vertical pixel at beam centre.
|
||||
* param ROI_row_offset horizontal pixel offset of ROI
|
||||
* param col_zero horizontal pixel at beam centre for detector rotation of zero.
|
||||
* param ROI_col_offset vertical pixel offset of ROI
|
||||
* param rownum number of detector rows
|
||||
* param colnum number of detector columns
|
||||
*
|
||||
* Detector pixel layout uses display coordinates viewed from the sample.
|
||||
* ie If you stand at the sample and face the detector the (0,0) is at the
|
||||
* left.
|
||||
*/
|
||||
float *G_TwoThetaArr=NULL;
|
||||
void polar_angle(double dradius, double angsep, double active_height_mm, double det_rot_rad, double row_zero, double ROI_row_offset, double col_zero, double ROI_col_offset, double rownum, double colnum) {
|
||||
|
||||
int row,col;
|
||||
double rowsep, height, alpha, pang;
|
||||
|
||||
if (G_TwoThetaArr != NULL)
|
||||
free(G_TwoThetaArr);
|
||||
|
||||
G_TwoThetaArr = (float *)malloc(rownum*colnum*sizeof(float));
|
||||
|
||||
|
||||
rowsep = active_height_mm/(rownum-1);
|
||||
|
||||
for (row=0; row < rownum; row++) {
|
||||
height=(row_zero - ROI_row_offset - row)*rowsep;
|
||||
for (col=0; col < colnum; col++) {
|
||||
alpha = (col_zero - ROI_col_offset - col)*angsep + det_rot_rad;
|
||||
pang = acos(dradius * cos(alpha)/sqrt(dradius*dradius+ height*height));
|
||||
G_TwoThetaArr[(int)(row*colnum+col)]=pang;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static void putPolarArray(SConnection *pCon, SicsInterp *pSics,
|
||||
pNXScript self,
|
||||
int argc, char *argv[]){
|
||||
int status;
|
||||
char buffer[256];
|
||||
Tcl_Interp *tcl = NULL;
|
||||
|
||||
double angsep, det_rot_rad, active_height_mm, rowsep;
|
||||
double row_zero, ROI_row_offset, col_zero, ROI_col_offset, dradius;
|
||||
double rownum, colnum;
|
||||
|
||||
if(argc < 11){
|
||||
SCWrite(pCon,"ERROR: insufficient number of arguments to array",
|
||||
eError);
|
||||
return;
|
||||
}
|
||||
tcl = InterpGetTcl(pSics);
|
||||
assert(tcl != NULL);
|
||||
|
||||
|
||||
status = Tcl_GetDouble(tcl,argv[3],&dradius);
|
||||
if(status != TCL_OK){
|
||||
sprintf(buffer,"ERROR: failed to convert %s to double",argv[3]);
|
||||
SCWrite(pCon,buffer,eError);
|
||||
return;
|
||||
}
|
||||
status = Tcl_GetDouble(tcl,argv[4],&angsep);
|
||||
if(status != TCL_OK){
|
||||
sprintf(buffer,"ERROR: failed to convert %s to double",argv[4]);
|
||||
SCWrite(pCon,buffer,eError);
|
||||
return;
|
||||
}
|
||||
status = Tcl_GetDouble(tcl,argv[5],&active_height_mm);
|
||||
if(status != TCL_OK){
|
||||
sprintf(buffer,"ERROR: failed to convert %s to double",argv[5]);
|
||||
SCWrite(pCon,buffer,eError);
|
||||
return;
|
||||
}
|
||||
status = Tcl_GetDouble(tcl,argv[6],&det_rot_rad);
|
||||
if(status != TCL_OK){
|
||||
sprintf(buffer,"ERROR: failed to convert %s to double",argv[6]);
|
||||
SCWrite(pCon,buffer,eError);
|
||||
return;
|
||||
}
|
||||
status = Tcl_GetDouble(tcl,argv[7],&row_zero);
|
||||
if(status != TCL_OK){
|
||||
sprintf(buffer,"ERROR: failed to convert %s to double",argv[7]);
|
||||
SCWrite(pCon,buffer,eError);
|
||||
return;
|
||||
}
|
||||
status = Tcl_GetDouble(tcl,argv[8],&ROI_row_offset);
|
||||
if(status != TCL_OK){
|
||||
sprintf(buffer,"ERROR: failed to convert %s to double",argv[8]);
|
||||
SCWrite(pCon,buffer,eError);
|
||||
return;
|
||||
}
|
||||
status = Tcl_GetDouble(tcl,argv[9],&col_zero);
|
||||
if(status != TCL_OK){
|
||||
sprintf(buffer,"ERROR: failed to convert %s to double",argv[9]);
|
||||
SCWrite(pCon,buffer,eError);
|
||||
return;
|
||||
}
|
||||
status = Tcl_GetDouble(tcl,argv[10],&ROI_col_offset);
|
||||
if(status != TCL_OK){
|
||||
sprintf(buffer,"ERROR: failed to convert %s to double",argv[10]);
|
||||
SCWrite(pCon,buffer,eError);
|
||||
return;
|
||||
}
|
||||
status = Tcl_GetDouble(tcl,argv[11],&rownum);
|
||||
if(status != TCL_OK){
|
||||
sprintf(buffer,"ERROR: failed to convert %s to double",argv[11]);
|
||||
SCWrite(pCon,buffer,eError);
|
||||
return;
|
||||
}
|
||||
status = Tcl_GetDouble(tcl,argv[12],&colnum);
|
||||
if(status != TCL_OK){
|
||||
sprintf(buffer,"ERROR: failed to convert %s to double",argv[12]);
|
||||
SCWrite(pCon,buffer,eError);
|
||||
return;
|
||||
}
|
||||
|
||||
polar_angle(dradius, angsep, active_height_mm, det_rot_rad, row_zero, ROI_row_offset, col_zero, ROI_col_offset, rownum, colnum);
|
||||
|
||||
status = NXDputalias(self->fileHandle, self->dictHandle,argv[2],G_TwoThetaArr);
|
||||
if(status != NX_OK){
|
||||
sprintf(buffer,"ERROR: failed to write array");
|
||||
SCWrite(pCon,buffer,eError);
|
||||
}
|
||||
SCSendOK(pCon);
|
||||
}
|
||||
|
||||
static void putGenArray(SConnection *pCon, SicsInterp *pSics,
|
||||
pNXScript self,
|
||||
int argc, char *argv[]){
|
||||
@@ -804,94 +1025,6 @@ static void putGenArray(SConnection *pCon, SicsInterp *pSics,
|
||||
SCSendOK(pCon);
|
||||
}
|
||||
/*----------------------------------------------------------------------*/
|
||||
static void putArray(SConnection *pCon, SicsInterp *pSics,
|
||||
pNXScript self,
|
||||
int argc, char *argv[]){
|
||||
float *data = NULL;
|
||||
int length, i, status;
|
||||
char num[20];
|
||||
char buffer[256], defString[512], *varData;
|
||||
Tcl_Interp *tcl = NULL;
|
||||
double dVal;
|
||||
|
||||
if(argc < 5){
|
||||
SCWrite(pCon,"ERROR: insufficient number of arguments to array",
|
||||
eError);
|
||||
return;
|
||||
}
|
||||
tcl = InterpGetTcl(pSics);
|
||||
assert(tcl != NULL);
|
||||
|
||||
/*
|
||||
get array length
|
||||
*/
|
||||
status = Tcl_GetInt(tcl,argv[4],&length);
|
||||
if(status != TCL_OK){
|
||||
sprintf(buffer,"ERROR: failed to convert %s to integer",argv[4]);
|
||||
SCWrite(pCon,buffer,eError);
|
||||
return;
|
||||
}
|
||||
|
||||
/*
|
||||
allocate
|
||||
*/
|
||||
if(length > 0){
|
||||
data = (float *)malloc(length*sizeof(float));
|
||||
}
|
||||
if(data == NULL){
|
||||
snprintf(buffer,255,
|
||||
"ERROR: out of memory or invalid length at %s, length = %s",
|
||||
argv[2],argv[4]);
|
||||
SCWrite(pCon,buffer,eError);
|
||||
return;
|
||||
}
|
||||
memset(data,0,length*sizeof(float));
|
||||
|
||||
/*
|
||||
try getting data
|
||||
*/
|
||||
for(i = 0; i < length; i++){
|
||||
sprintf(num,"%d",i);
|
||||
varData = (char *)Tcl_GetVar2(tcl,argv[3],num,0);
|
||||
if(varData != NULL){
|
||||
status = Tcl_GetDouble(tcl,varData,&dVal);
|
||||
if(status != TCL_OK){
|
||||
sprintf(buffer,"ERROR: failed to convert %s to double",
|
||||
varData);
|
||||
SCWrite(pCon,buffer,eError);
|
||||
}
|
||||
data[i] = (float)dVal;
|
||||
} else {
|
||||
snprintf(buffer,254,"WARNING: failed to find array element %d", i);
|
||||
SCWrite(pCon,buffer,eError);
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
build definition string
|
||||
*/
|
||||
status = NXDdefget(self->dictHandle,argv[2],buffer,254);
|
||||
if(!status){
|
||||
sprintf(buffer,"ERROR: alias %s for array not found",
|
||||
argv[2]);
|
||||
SCWrite(pCon,buffer,eError);
|
||||
free(data);
|
||||
return;
|
||||
}
|
||||
snprintf(defString,511,"%s -dim {%d} ",buffer,length);
|
||||
|
||||
/*
|
||||
write it!
|
||||
*/
|
||||
status = NXDputdef(self->fileHandle,self->dictHandle,defString,data);
|
||||
if(status != NX_OK){
|
||||
sprintf(buffer,"ERROR: failed to write array");
|
||||
SCWrite(pCon,buffer,eError);
|
||||
}
|
||||
free(data);
|
||||
SCSendOK(pCon);
|
||||
}
|
||||
/*----------------------------------------------------------------------*/
|
||||
static void putIntArray(SConnection *pCon, SicsInterp *pSics,
|
||||
pNXScript self,
|
||||
int argc, char *argv[]){
|
||||
@@ -1099,8 +1232,11 @@ static int handlePut(SConnection *pCon, SicsInterp *pSics, pNXScript self,
|
||||
/*=================*/
|
||||
putTimeBinning(pCon,pSics,self,argc,argv);
|
||||
}else if(strcmp(argv[1],"putarray") == 0){
|
||||
/*================*/
|
||||
/*== ANSTO MOD ===*/
|
||||
putArray(pCon,pSics,self,argc,argv);
|
||||
}else if(strcmp(argv[1],"putpolararray") == 0){
|
||||
/*================*/
|
||||
putPolarArray(pCon,pSics,self,argc,argv);
|
||||
}else if(strcmp(argv[1],"putgenarray") == 0){
|
||||
/*================*/
|
||||
putGenArray(pCon,pSics,self,argc,argv);
|
||||
|
||||
Reference in New Issue
Block a user