- Adding first working version of the McStas SICS connection to cvs

SKIPPED:
	psi/polterwrite.c
This commit is contained in:
koennecke
2005-06-22 07:09:59 +00:00
parent 734577e394
commit ef6c04e6b8
42 changed files with 3268 additions and 18 deletions

3
mcstas/dmc/DataNumber Normal file
View File

@ -0,0 +1,3 @@
6
NEVER, EVER modify or delete this file
You'll risk eternal damnation and a reincarnation as a cockroach!|n

141
mcstas/dmc/PSD_monitor.comp Normal file
View File

@ -0,0 +1,141 @@
/*******************************************************************************
*
* McStas, neutron ray-tracing package
* Copyright 1997-2002, All rights reserved
* Risoe National Laboratory, Roskilde, Denmark
* Institut Laue Langevin, Grenoble, France
*
* Component: PSD_monitor
*
* %I
* Written by: Kim Lefmann
* Date: Feb 3, 1998
* Version: $Revision: 1.1 $
* Origin: Risoe
* Release: McStas 1.6
*
* Hacked by to dump the total number of neutrons any dumpCount
* neutrons into a very simple one line file. This is needed to stay in control
* for virtual instruments.
*
* Mark Koennecke, June 2005
*
* Position-sensitive monitor.
*
* %D
* An (n times m) pixel PSD monitor. This component may also be used as a beam
* detector.
*
* Example: PSD_monitor(xmin=-0.1, xmax=0.1, ymin=-0.1, ymax=0.1,
nx=90, ny=90, filename="Output.psd")
*
* %P
* INPUT PARAMETERS:
*
* xmin: Lower x bound of detector opening (m)
* xmax: Upper x bound of detector opening (m)
* ymin: Lower y bound of detector opening (m)
* ymax: Upper y bound of detector opening (m)
* nx: Number of pixel columns (1)
* ny: Number of pixel rows (1)
* filename: Name of file in which to store the detector image (text)
* controlfile: A file to which the total number of neutrons detected is dumped
* any dumpCount counts.
* dumpCount: The number of counst after which a controlfile is written. A negative
* value switches the feauture off.
* OUTPUT PARAMETERS:
*
* PSD_N: Array of neutron counts
* PSD_p: Array of neutron weight counts
* PSD_p2: Array of second moments
* totalCounts: The total number of counts in the detector
* currentCount: The current counter since the last dump.
*
* %E
*******************************************************************************/
DEFINE COMPONENT PSD_monitor
DEFINITION PARAMETERS (nx=90, ny=90, filename, controlfile="mon01.dat")
SETTING PARAMETERS (xmin, xmax, ymin, ymax, int dumpCount = -1.)
OUTPUT PARAMETERS (PSD_N, PSD_p, PSD_p2, totalCount, currentCount)
STATE PARAMETERS (x,y,z,vx,vy,vz,t,s1,s2,p)
SHARE
%{
void dumpTotal(char *ffilename, long totalCounts){
FILE *fd = NULL;
fd = fopen(ffilename,"w");
if(fd != NULL){
fprintf(fd,"%ld\n",totalCounts);
fclose(fd);
}
}
%}
DECLARE
%{
long totalCount, currentCount;
double PSD_N[nx][ny];
double PSD_p[nx][ny];
double PSD_p2[nx][ny];
%}
INITIALIZE
%{
int i,j;
for (i=0; i<nx; i++)
for (j=0; j<ny; j++)
{
PSD_N[i][j] = 0;
PSD_p[i][j] = 0;
PSD_p2[i][j] = 0;
}
totalCount = 0;
currentCount = 0;
%}
TRACE
%{
int i,j;
PROP_Z0;
if (x>xmin && x<xmax && y>ymin && y<ymax)
{
i = floor((x - xmin)*nx/(xmax - xmin));
j = floor((y - ymin)*ny/(ymax - ymin));
PSD_N[i][j]++;
PSD_p[i][j] += p;
PSD_p2[i][j] += p*p;
totalCount++;
currentCount++;
if(dumpCount > 0 && currentCount > dumpCount){
dumpTotal(controlfile,totalCount);
currentCount = 0;
}
SCATTER;
}
%}
SAVE
%{
DETECTOR_OUT_2D(
"PSD monitor",
"X position [cm]",
"Y position [cm]",
xmin*100.0, xmax*100.0, ymin*100.0, ymax*100.0,
nx, ny,
&PSD_N[0][0],&PSD_p[0][0],&PSD_p2[0][0],
filename);
%}
MCDISPLAY
%{
magnify("xy");
multiline(5, (double)xmin, (double)ymin, 0.0,
(double)xmax, (double)ymin, 0.0,
(double)xmax, (double)ymax, 0.0,
(double)xmin, (double)ymax, 0.0,
(double)xmin, (double)ymin, 0.0);
%}
END

8
mcstas/dmc/batch.tcl Normal file
View File

@ -0,0 +1,8 @@
proc SplitReply { text } {
set l [split $text =]
return [lindex $l 1]
}
proc batchrun file {
fileeval [string trim [SplitReply [BatchRoot]]/$file]
}

89
mcstas/dmc/dmc.dic Normal file
View File

@ -0,0 +1,89 @@
##NXDICT-1.0
#----------------------------------------------------------------------------
# NeXus dictionary file for the SINQ instrument DMC and HRPT
#
# DO NOT EDIT WHEN YOU DO NOT KNOW WHAT YOU ARE DOING!
# This file determines the placement of data items in the Powder NeXus
# data file. Your data may not be readable if this file is messed up.
#
# Mark Koennecke, May 2004
#----------------------------------------------------------------------------
inst=DMC
detector=DMC-BF3-Detector
noofdetectors=400
#---------- NXentry level
etitle=/entry1,NXentry/SDS title -type DFNT_CHAR -rank 1
estart=/entry1,NXentry/SDS start_time -type DFNT_CHAR -rank 1
eend=/entry1,NXentry/SDS end_time -type DFNT_CHAR -rank 1
#----------------- NXinstrument
iname=/entry1,NXentry/$(inst),NXinstrument/SDS name -type DFNT_CHAR \
-rank 1 -dim {132}
#----------------- NXsource
sname=/entry1,NXentry/$(inst),NXinstrument/SINQ,NXsource/SDS name \
-type DFNT_CHAR -rank 1
stype=/entry1,NXentry/$(inst),NXinstrument/SINQ,NXsource/SDS type \
-type DFNT_CHAR -rank 1
#-------------- Monochromator
mname=/entry1,NXentry/$(inst),NXinstrument/Monochromator,NXcrystal/SDS type \
-type DFNT_CHAR -rank 1
mtheta=/entry1,NXentry/$(inst),NXinstrument/Monochromator,NXcrystal/SDS \
theta
mttheta=/entry1,NXentry/$(inst),NXinstrument/Monochromator,NXcrystal/SDS \
two_theta
mlambda=/entry1,NXentry/$(inst),NXinstrument/Monochromator,NXcrystal/SDS \
lambda -attr {units,Angstroem}
mdd=/entry1,NXentry/$(inst),NXinstrument/Monochromator,NXcrystal/SDS \
d_spacing -attr {units,Angstroem}
mcurve=/entry1,NXentry/$(inst),NXinstrument/Monochromator,NXcrystal/SDS \
curvature
monox=/entry1,NXentry/$(inst),NXinstrument/Monochromator,NXcrystal/SDS \
x_translation
monoy=/entry1,NXentry/$(inst),NXinstrument/Monochromator,NXcrystal/SDS \
y_translation
mchi=/entry1,NXentry/$(inst),NXinstrument/Monochromator,NXcrystal/SDS \
chi
mphi=/entry1,NXentry/$(inst),NXinstrument/Monochromator,NXcrystal/SDS \
phi
#------------- counter
cter_mode=/entry1,NXentry/$(inst),NXinstrument/$(detector),NXpsd/SDS \
CounterMode -type DFNT_CHAR -rank 1 -dim {30}
cter_preset=/entry1,NXentry/$(inst),NXinstrument/$(detector),NXpsd/SDS \
Preset -type NX_INT32
cter_time=/entry1,NXentry/$(inst),NXinstrument/$(detector),NXpsd/SDS \
time
cter_01=/entry1,NXentry/$(inst),NXinstrument/$(detector),NXpsd/SDS \
Monitor -type DFNT_INT32 -attr {units,counts}
cter_00=/entry1,NXentry/$(inst),NXinstrument/$(detector),NXpsd/SDS \
beam_monitor -type DFNT_INT32 -attr {units,counts}
cter_04=/entry1,NXentry/$(inst),NXinstrument/$(detector),NXpsd/SDS \
proton_monitor -type DFNT_INT32 -attr {units,counts}
#-------------- detector bank
dtheta=/entry1,NXentry/$(inst),NXinstrument/$(detector),NXpsd/SDS \
two_theta -rank 1 -dim {$(noofdetectors)} -attr {axis,1} \
-attr {units,degree}
dcounts=/entry1,NXentry/$(inst),NXinstrument/$(detector),NXpsd/SDS \
counts -type DFNT_INT32 -LZW -rank 1 -dim {$(noofdetectors)} \
-attr {signal,1}
dthst=/entry1,NXentry/$(inst),NXinstrument/$(detector),NXpsd/SDS \
two_theta_start -attr {units,degree}
dtstep=/entry1,NXentry/$(inst),NXinstrument/$(detector),NXpsd/SDS \
Step -attr {units,degree}
dtnstep=/entry1,NXentry/$(inst),NXinstrument/$(detector),NXpsd/SDS \
no_of_steps -type NX_INT32
#--------------- Sample
saname=/entry1,NXentry/sample,NXsample/SDS sample_name -type DFNT_CHAR \
-rank 1
devname=/entry1,NXentry/sample,NXsample/SDS device_name -type DFNT_CHAR \
-rank 1
stemp=/entry1,NXentry/sample,NXsample/SDS sample_temperature -attr {units,K}
smean=/entry1,NXentry/sample,NXsample/SDS temperature_mean -attr {units,K}
stddev=/entry1,NXentry/sample,NXsample/SDS temperature_stddev -attr {units,K}
mfield=/entry1,NXentry/sample,NXsample/SDS magfield -attr {units,T}
saangle=/entry1,NXentry/sample,NXsample/SDS sample_table_rotation \
-attr {units,degree}
smur=/entry1,NXentry/sample,NXsample/SDS sample_mur \
-attr {units,degree}
#----------------NXdata ------------------------------------------------
dana=/entry1,NXentry/data1,NXdata/NXVGROUP

184
mcstas/dmc/dmc_sics01.instr Normal file
View File

@ -0,0 +1,184 @@
DEFINE INSTRUMENT DMC_diff(TKOFF,lambda,char *samplefile, char *monfile)
DECLARE
%{
double mono_q = 1.87;
double OMA;
double RV;
double y_mono = 0.025;
double NV = 5;
double d_phi_0;
double TKOFF;
double sample_radius = 0.005;
double sample_height = 0.03;
double lambda;
double ldiff=0.5;
char *samplefile;
%}
INITIALIZE
%{
OMA = TKOFF/2;
RV = fabs(2*2.82*sin(DEG2RAD*OMA));
%}
TRACE
COMPONENT source_arm = Arm()
AT (0, 0, 0) ABSOLUTE
/* values for guide side window RNR12 */
COMPONENT csource = Source_gen(
radius = 0.08,xw = 0.02, yh = 0.12, dist = 1.5,
Lambda0 = lambda, dLambda = ldiff,
T1=150.42,I1=5.98e11,
T2=37.23,I2=5.637e11,T3=14.9,I3=0.962e11)
AT (0,0,0) RELATIVE source_arm ROTATED (0,0,0) RELATIVE source_arm
/* guide segment 1, m=2, 4.66 m */
COMPONENT guide1 = Guide(w1=0.02, h1=0.12, w2=0.02, h2=0.12,
l=4.66, R0=0.995, Qc=0.0217, alpha = 5.76,
m = 2.0, W = 0.0033)
AT (0,0,1.5) RELATIVE source_arm ROTATED (0,0,0) RELATIVE source_arm
/* guide segment 2, curved, m=2, 24.5 m */
COMPONENT guide2 = Bender(
w = 0.02, h = 0.12, r = 3612, R0a = 0.995, Qca = 0.0217,
alphaa = 5.76, ma = 2, Wa = 0.0033, R0i = 0.995, Qci = 0.0217,
alphai = 5.76, mi = 2, Wi = 0.0033, R0s = 0.995, Qcs = 0.0217,
alphas = 5.76, ms = 2, Ws = 0.0033, l = 24.5)
AT (0,0,6.16) RELATIVE source_arm ROTATED (0,0,0) RELATIVE source_arm
/* bunker wall, m=2, 3.0 m */
COMPONENT bunker = Guide(
w1=0.02, h1=.12, w2=0.02, h2=.12,
l=3.0, R0=0.995, Qc=0.0217, alpha = 5.76,
m = 2.0, W = 0.0033)
AT (0,0,30.66) RELATIVE source_arm ROTATED (0,0,0) RELATIVE source_arm
/* guide segment 3, m=2, 8.84 m */
COMPONENT guide3 = Guide(
w1=0.02, h1=.12, w2=0.02, h2=.12,
l=8.84, R0=0.995,Qc=0.0217, alpha = 5.76,
m = 2.0, W = 0.0033)
AT (0,0,33.66) RELATIVE source_arm ROTATED (0,0,0) RELATIVE source_arm
/* guide exit at 42.5 m - measured flux 2.46 10e8 cm-2 s-1 mA-1 */
COMPONENT in_slit = Slit(
xmin = -0.01, xmax=0.01 , ymin = -0.06, ymax = 0.06)
AT (0,0,42.5) RELATIVE source_arm ROTATED (0,0,0) RELATIVE source_arm
/* Monochromator description */
COMPONENT sma = Arm() /* source - monochromator arm */
AT (0, 0, 43.15) RELATIVE source_arm ROTATED (0,OMA,0) RELATIVE source_arm
COMPONENT foc_mono = Monochromator_2foc(
zwidth = 0.05, yheight = 0.025, gap = 0.0005, NH = 1, NV = 5,
mosaich = 38, mosaicv = 38, r0 = 0.7, Q = 1.8857, RV = RV,
RH = 0)
AT (0, 0, 0) RELATIVE sma
COMPONENT msa = Arm() /* monochromator - sample arm */
AT (0, 0, 0) RELATIVE sma ROTATED (0, TKOFF, 0) RELATIVE source_arm
COMPONENT out1_slit = Slit(
xmin=-0.01, xmax=0.01, ymin=-0.06, ymax=0.06)
AT (0,0,0.2) RELATIVE msa ROTATED (0,0,0) RELATIVE msa
COMPONENT Amoin_slit = Slit(
xmin=-0.01, xmax=0.01, ymin=-0.06, ymax=0.06)
AT (0,0,0.325) RELATIVE msa ROTATED (0,0,0) RELATIVE msa
COMPONENT Bmoin_slit = Slit(
xmin=-0.01, xmax=0.01, ymin=-0.06, ymax=0.06)
AT (0,0,0.525) RELATIVE msa ROTATED (0,0,0) RELATIVE msa
COMPONENT out2_slit = Slit(
xmin=-0.01, xmax=0.01, ymin=-0.06, ymax=0.06)
AT (0,0,0.65) RELATIVE msa ROTATED (0,0,0) RELATIVE msa
COMPONENT PSD_sample = PSD_monitor(
xmin=-0.05, xmax=0.05, ymin=-0.07, ymax=0.07,
nx=80, ny=80, filename="PSD_sample.dat",controlfile=monfile, dumpCount=500)
AT ( 0, 0, 1.5) RELATIVE msa
COMPONENT sa_arm = Arm()
AT (0, 0, 2.82) RELATIVE msa
ROTATED (0, 0, 0) RELATIVE msa
COMPONENT sample = PowderN (
d_phi0=40,radius=sample_radius, h=sample_height,
pack=1, Vc=1076.98, reflections = samplefile,
sigma_a=0.2, target_index=+4)
AT ( 0, 0, 0) RELATIVE sa_arm
COMPONENT sda = Arm() /* sample-detector arm */
AT (0, 0, 0) RELATIVE sa_arm ROTATED (0, -93.8, 0) RELATIVE sa_arm
COMPONENT Det9 = Monitor_nD(
xwidth=3.0,yheight=0.09,
options="banana theta limits [19 99] bins=400, file=det9.dat")
AT (0,0,0) RELATIVE sa_arm
ROTATED (0, 0, 180) RELATIVE sa_arm
END

84
mcstas/dmc/log.tcl Normal file
View File

@ -0,0 +1,84 @@
#-----------------------------------------------------------------------------
# This file implements a LogBook facility for SICS.
# Usage:
# LogBook - lists the current status
# LogBook filename - sets the logbook file name
# LogBook on - starts logging, creates new file
# LogBook off - closes log file
#
# Mark Koennecke, June 1997, initially developed for SANS
# works using one procedure and an array for data. All internal procedures
# start with cli
#----------------------------------------------------------------------------
set cliArray(file) default.log
set cliArray(status) off
set cliArray(number) 0
#---------------------------------------------------------------------------
proc cliList { } {
global cliArray
# ClientPut [format " LogBook file: %s\n" $cliArray(file)]
# ClientPut [format " Logging: %s " $cliArray(status)] ]
append res [format " LogBook file: %s\n" $cliArray(file)] \
[format " Logging: %s " $cliArray(status)]
return $res
}
#-------------------------------------------------------------------------
proc cliLogOn { } {
global cliArray
set cmd [list config File $cliArray(file)]
set ret [catch {eval $cmd} msg]
if { $ret != 0 } {
error $msg
} else {
set l [ split $msg = ]
set cliArray(number) [lindex $l 1]
set cliArray(status) on
}
}
#--------------------------------------------------------------------------
proc cliLogOff { } {
global cliArray
set cmd [list config close $cliArray(number)]
set ret [catch {eval $cmd} msg]
if { $ret != 0 } {
error $msg
} else {
set cliArray(status) off
}
}
#-------------------------------------------------------------------------
proc logbook args {
global cliArray
#---- first case: a listing
if { [llength $args] == 0} {
return [cliList]
}
#---- there must be an argument
set argument [lindex $args 0]
#---- on/ off
if {[string compare "on" $argument] == 0} {
set ret [catch {cliLogOn} msg]
if { $ret != 0 } {
error $msg
} else {
ClientPut OK
}
} elseif {[string compare "off" $argument] == 0} {
set ret [catch {cliLogOff} msg]
if { $ret != 0 } {
error $msg
} else {
ClientPut OK
}
} elseif {[string compare "file" $argument] >= 0} {
if {[llength $args] < 1} {
error "ERROR: nor filename specified for LogBook"
}
set cliArray(file) [lindex $args 1]
} elseif {[string compare "no" $argument] == 0} {
ClientPut $cliArray(number)
} else {
error [format "ERROR: unknown argument %s to LogBook" $argument]
}
}

66
mcstas/dmc/mcsupport.tcl Normal file
View File

@ -0,0 +1,66 @@
#-------------------------------------------------------------------
# These are a couple of Tcl function which help with the interface
# between SICS and McStas
#
# Mark Koennecke, June 2005
#--------------------------------------------------------------------
# washsimfile fixes the evil NXsimulation name ="./dmc.xml" thing in
# the XML file. Path separators in name attributes throw off
# NXopenpath
#--------------------------------------------------------------------
proc washsimfile {name} {
set oriname $name
set in [open $name "r"]
set name [file tail $name]
set out [open /tmp/$name "w"]
while { [gets $in line] >= 0} {
if { [string first "NXsimulation name=" $line] > 0} {
puts $out "<NXsimulation name=\"$name\">"
} else {
puts $out $line
}
}
close $in
close $out
file copy -force /tmp/$name $oriname
file delete /tmp/$name
}
#---------------------------------------------------------------------
# When McStas dumps or is killed we need to give McStas some time to
# dump its data. Otherwise we observe that data reading fails.
# mcwaittime is used for this. Increase if you see problems
#--------------------------------------------------------------------
set mcwaittime 7
#----------------------------------------------------------------------
proc mcstasdump {pid} {
global mcwaittime
catch {eval exec /usr/bin/kill -USR2 $pid}
wait $mcwaittime
}
#-----------------------------------------------------------------------
proc mcstasisrunning {pid} {
set ret [catch {eval exec /bin/ps --pid $pid} msg]
if {$ret == 0} {
return 1
} else {
return 0;
}
}
#-----------------------------------------------------------------------
proc mcstaskill {pid} {
global mcwaittime
catch {eval exec /usr/bin/kill -TERM $pid}
wait $mcwaittime
}
#-----------------------------------------------------------------------
proc mcinstall {} {
allowexec /usr/bin/kill
allowexec /bin/ps
Publish mcstasdump User
Publish mcstasisrunning User
Publish mcstaskill User
mccontrol configure mcdump mcstasdump
mccontrol configure mckill mcstaskill
mccontrol configure mcisrunning mcstasisrunning
mccontrol configure update 300
}

29
mcstas/dmc/na2ca3al2f14.q Normal file
View File

@ -0,0 +1,29 @@
// mult Q(hkl) F2 DW w
12 0.8669 0.81 1 0
6 1.2259 16.0 1 0
24 1.5015 9.0 1 0
12 1.7338 40.96 1 0
12 1.9384 7.84 1 0
12 1.9384 0.64 1 0
8 2.1234 26.01 1 0
24 2.2936 5.29 1 0
24 2.2936 10.24 1 0
6 2.4519 62.41 1 0
24 2.601 38.44 1 0
12 2.601 0.81 1 0
12 2.7413 56.25 1 0
12 2.7413 60.84 1 0
24 2.8751 161.29 1 0
24 3.003 4.41 1 0
24 3.1256 108.16 1 0
12 3.1256 1.96 1 0
12 3.1256 18.49 1 0
24 3.1256 51.84 1 0
24 3.3574 116.64 1 0
24 3.3574 53.29 1 0
12 3.4675 256.0 1 0
12 3.5743 28.09 1 0
12 3.5743 0.81 1 0
24 3.5743 4.0 1 0
24 3.6779 39.69 1 0
6 3.6779 33.64 1 0

108
mcstas/dmc/nxdmc.tcl Normal file
View File

@ -0,0 +1,108 @@
#--------------------------------------------------------------------------
# NeXus file writing for DMC
#
# This is the scripted version using nxscript
#
# Mark Koennecke, May 2004
#---------------------------------------------------------------------------
proc storeMonochromator {} {
nxscript puttext mname "Pyrolithic Graphite 002"
writeFloatVar mtheta OmegaM
writeFloatVar mttheta TwoThetaM
writeFloatVar mlambda lambda
writeFloatVar mcurve CurveM
writeFloatVar monox MonoX
writeFloatVar monoy MonoY
writeFloatVar mchi MonoChi
writeFloatVar mphi MonoPhi
set dd [SplitReply [mono dd]]
set dd [string trim $dd]
set ret [catch {expr $dd * 1.0} msg]
if {$ret != 0} {
clientput "ERROR: failed to read monochromator d spacing"
} else {
nxscript putfloat mdd $dd
}
}
#------------------------------------------------------------------------
proc storeSample {} {
writeTextVar saname sample
writeFloatVar saangle Table
set ret [catch {set temp [SplitReply [temperature]]} msg]
if {$ret == 0} {
nxscript putfloat stemp $temp
set dname [string trim [SplitReply [temperature driver]]]
if {"$dname" == "tecs"} {
set dname [SplitReply [temperature device]]
}
nxscript puttext devname $dname
set ret [catch {temperature log getmean} msg]
if {$ret == 0} {
set l [split $msg =]
set stddev [string trim [lindex $l 2]]
set l2 [split [string trim [lindex $l 1]]]
set mean [string trim [lindex $l2 0]]
nxscript putfloat smean $mean
nxscript putfloat stddev $stddev
}
}
writeFloatVar smur sample_mur
set ret [catch {set mtemp [SplitReply [magfield]]} msg]
if {$ret == 0} {
nxscript putfloat mfield $mtemp
}
}
#---------------------------------------------------------------------
proc storeDetector {ndet stepwidth} {
nxscript udpatedictvar noofdetectors $ndet
set start [string trim [SplitReply [TwoThetaD]]]
for {set i 0} { $i < $ndet} {incr i} {
set th($i) [expr $start + $i * $stepwidth]
}
nxscript putfloat dthst $start
nxscript putfloat dtstep $stepwidth
nxscript putint dtnstep [string trim $ndet]
nxscript putarray dtheta th 400
nxscript puthm dcounts banana
}
#----------------------------------------------------------------------
proc makeLinks {} {
nxscript makelink dana dcounts
nxscript makelink dana dtheta
nxscript makelink dana dthst
nxscript makelink dana dtstep
nxscript makelink dana dtnstep
nxscript makelink dana mlambda
}
#-------------------------------------------------------------------------
# store DMC data
#-------------------------------------------------------------------------
proc storedata {} {
global home
set fil [newFileName]
clientput "Opening $fil for writing"
nxscript create4 $fil $home/dmc.dic
writeStandardAttributes $fil
writeTextVar etitle title
nxscript puttext estart [sicstime]
nxscript puttext iname "DMC at SINQ"
nxscript puttext sname "SINQ"
nxscript puttext stype "Continuous flux spallation source"
nxscript updatedictvar inst DMC
nxscript updatedictvar detector "DMC-BF3-Detector"
storeMonochromator
storeSample
nxscript putcounter cter counter
storeDetector 400 .2
makeLinks
nxscript close
}

96
mcstas/dmc/nxsupport.tcl Normal file
View File

@ -0,0 +1,96 @@
#===========================================================================
# Support routines for scripting NeXus files with nxscript.
#
# Mark Koennecke, February 2003
# Mark Koennecke, January 2004
#==========================================================================
proc makeFileName args {
sicsdatanumber incr
set num [SplitReply [sicsdatanumber]]
set p [string trim [SplitReply [sicsdatapath]]]
set pre [string trim [SplitReply [sicsdataprefix]]]
set po [string trim [SplitReply [sicsdatapostfix]]]
return [format "%s%s%5.5d2003%s" $p $pre $num $po]
}
#==========================================================================
# new version, attending to the new 1000 grouping logic
proc newFileName args {
set ret [catch {nxscript makefilename} msg]
if {$ret != 0} {
clientput "ERROR: Misconfiguration of file writing variables"
clientput "Defaulting filename to emergency.hdf"
set fil emergency.hdf
} else {
set fil $msg
}
return $fil
}
#==========================================================================
proc writeFloatVar {alias var} {
set ret [catch {set val [SplitReply [$var]]} val]
if { $ret != 0} {
clientput [format "ERROR: failed to read %s, %s" $var $val]
return
} else {
set val [string trim $val]
set ret [catch {expr $val * 1.0} val]
if { $ret == 0} {
nxscript putfloat $alias [expr $val * 1.0 ]
} else {
clientput "ERROR: bad value $val when reading $var"
}
}
}
#==========================================================================
proc writeIntVar {alias var} {
set ret [catch {set val [SplitReply [$var]]} val]
if { $ret != 0} {
clientput [format "ERROR: failed to read %s, %s" $var $val]
return
} else {
set val [string trim $val]
set ret [catch {expr $val * 1.0} val]
if { $ret == 0} {
nxscript putint $alias [expr int($val * 1.0) ]
} else {
clientput "ERROR: bad value $val when reading $var"
}
}
}
#=========================================================================
proc writeTextVar {alias var} {
set ret [catch {$var} val]
if { $ret != 0} {
clientput [format "ERROR: failed to read %s" $var]
return
} else {
set index [string first = $val]
if {$index >= 0} {
set txt [string trim [string range $val [expr $index + 1] end]]
nxscript puttext $alias $txt
} else {
clientput [format "ERROR: failed to read %s" $var]
}
}
}
#========================================================================
proc writeTextAttribute {attName var} {
set ret [catch {set val [SplitReply [$var]]} val]
if { $ret != 0} {
clientput [format "ERROR: failed to read %s" $var]
return
} else {
nxscript putglobal $attName [string trim $val]
}
}
#=======================================================================
proc writeStandardAttributes {fileName} {
nxscript putglobal file_name $fileName
nxscript putglobal file_time [sicstime]
writeTextAttribute instrument instrument
writeTextAttribute owner user
writeTextAttribute owner_telephone_number phone
writeTextAttribute owner_fax_number fax
writeTextAttribute owner_email email
writeTextAttribute owner_address adress
}

138
mcstas/dmc/vdmc.tcl Normal file
View File

@ -0,0 +1,138 @@
# --------------------------------------------------------------------------
# Initialization script for a virtual DMC instrument using a McStas
# simulationas a data source
#
# Dr. Mark Koennecke, June 2005
#---------------------------------------------------------------------------
# O P T I O N S
set home $env(HOME)/src/workspace/sics/mcstas/dmc
#--------------------------------- first all the server options are set
#ServerOption RedirectFile $home/stdcdmc
ServerOption ReadTimeOut 0
ServerOption AcceptTimeOut 0
ServerOption ReadUserPasswdTimeout 500000
ServerOption LogFileBaseName "$home/vdmclog"
ServerOption LogFileDir $home/
ServerOption ServerPort 2911
ServerOption statusfile $home/vdmcstatus.tcl
ServerOption InterruptPort 3007
ServerOption TelnetPort 1301
ServerOption TelWord sicslogin
#---------------------------------------------------------------------------
# U S E R S
SicsUser lnsmanager lnsSICSlns 1
SicsUser Manager Manager 1
SicsUser user looser 2
SicsUser Spy 007 1
#--------------------------------------------------------------------------
# D E V I C E S : M O T O R S
#---------------------------------------------------------------------------
ClientPut "Installing Motors"
Motor OmegaM SIM 0 120 -.1 2.
Motor TwoThetaM SIM 30 100 -.1 1.
Motor MonoX SIM -30 30 -.1 3.0
Motor MonoY SIM -30 30 -.1 3.0
Motor CurveM SIM 0 20 -.1 3.0
Motor MonoPhi SIM -30 30 -.1 3.0
Motor MonoChi SIM -30 30 -.1 3.0
# sample Table
Motor Table SIM -180 360 -.1 2.
Motor TwoThetaD SIM -10 120 -.1 1.
#-------------------------------------------------------------
# Monochromator
#-------------------------------------------------------------
MakeMono Mono "PG-002" OmegaM TwoThetaM CurveM
Mono DD 3.3537
Mono vk1 -0.025942
Mono vk2 5.351660
# Syntax MakeWaveLength name MonochromatorToUse
MakeWaveLength lambda Mono
#--------------------------------------------------------------------------
# Configure Detector
# NOTE: the McStas objects have to be created first, otherwise
# the initialisation will fail.
#--------------------------------------------------------------------------
MakeMcStasReader
MakeMcStasController
allowexec $home/dmc_sics01
ClientPut "Installing counter"
MakeCounter counter mcstas
counter SetExponent 1
MakeHM banana mcstas
banana configure HistMode Normal
banana configure OverFlowMode Ceil
banana configure Rank 1
banana configure dim0 400
banana configure BinWidth 4
banana preset 100.
banana CountMode Timer
banana configure Counter counter
banana configure init 0
banana init
banana exponent 3
#-------------------------------------------------------------------------
# Aliases
#-------------------------------------------------------------------------
SicsAlias OmegaM A1
SicsAlias TwoThetaM A2
SicsAlias Table A3
SicsAlias TwoThetaD A4
SicsAlias MonoX A5
SicsAlias MonoY A6
SicsAlias MonoPhi A7
SicsAlias MonoChi A8
SicsAlias CurveM A9
DefineAlias TT temperature
#--------------------------------------------------------------------------
# V A R I A B L E S
# now a few general variables are created
# Syntax: VarMake name type access
# type can be one of: Text, Int, Float
#access can be one of: Internal, Mugger, User, Spy
#-----------------------------------------------------------------------------
VarMake SicsDataPath Text Internal
SicsDataPath "$home/"
SicsDataPath lock
VarMake DetStepWidth Float Internal
DetStepWidth 0.2
DetStepWidth lock
VarMake Instrument Text Internal
Instrument "Virtual DMC driven by McStas"
Instrument lock
VarMake Title Text User
VarMake User Text User
VarMake Collimation Text User
VarMake Sample Text User
Sample Kellerit
VarMake comment1 Text User
VarMake comment2 Text User
VarMake comment3 Text User
VarMake starttime Text User
starttime ""
VarMake SicsDataPrefix Text Internal
SicsDataPrefix vdmc
#--------- make data number
MakeDataNumber SicsDataNumber $home/DataNumber
VarMake SicsDataPostFix Text Internal
SicsDataPostFix ".hdf"
VarMake Adress Text User
VarMake phone Text User
VarMake fax Text User
VarMake email Text User
VarMake sample_mur Float User
#--------------------------------------------------------------------------
# P R O C E D U R E S
#--------------------------------------------------------------------------
MakeDrive
MakeBatchManager
MakeNXScript
#-------------------- initialize scripted commands
source $home/vdmccom.tcl
#-------------------- configure commandlog
commandlog auto
commandlog intervall 5

156
mcstas/dmc/vdmccom.tcl Normal file
View File

@ -0,0 +1,156 @@
#----------------------------------------------------------------------------
# VDMC instrument special scripted commands
#
# Mark Koennecke, June 2005
#---------------------------------------------------------------------------
source $home/mcsupport.tcl
if { [info exists vdmcinit] == 0 } {
set vdmcinit 1
Publish LogBook Spy
Publish count User
Publish Repeat User
Publish storedmcdata User
Publish rundmcsim User
Publish copydmcdata User
mcinstall
}
source $home/log.tcl
source $home/nxsupport.tcl
source $home/nxdmc.tcl
#------------------------------------------------------------------------
proc SplitReply { text } {
set l [split $text =]
return [lindex $l 1]
}
#-----------------------------------------------------------------------
# Scripts required for controlling McStas simulations
#-----------------------------------------------------------------------
proc rundmcsim {mode preset} {
global home
append command $home/dmc_sics01 " -f $home/dmc.xml --format=\"XML\""
append command " -n 9e15 "
append command " lambda=[string trim [SplitReply [lambda]]]"
append command " TKOFF=[string trim [SplitReply [TwoThetaM]]]"
append command " samplefile=$home/[string trim [SplitReply [sample]]].q"
append command " monfile=$home/monfile "
append command " >& $home/dmc.log &"
clientput "Starting McStas.. "
set ret [catch {eval exec $command} msg]
if {$ret != 0} {
error $msg
} else {
return $msg
}
}
#------------------------------------------------------------------------
proc copydmcdata { } {
global home
set mcversion "McStas 1.8 - Mar. 05, 2004"
washsimfile $home/dmc.xml
mcreader open $home/dmc.xml
mcreader insertmon \
"/$mcversion/DMC_diff/dmc.xml/PSD_sample/PSD_sample.dat/values" \
counter 1
mcreader inserthm \
"/$mcversion/DMC_diff/dmc.xml/Det9/det9.dat/data" banana
mcreader close
}
#--------------------------------------------------------------------------
mccontrol configure mcstart rundmcsim
mccontrol configure mccopydata copydmcdata
mccontrol configure update 60
mccontrol configure mcmonfile $home/monfile
#--------------------------------------------------------------------------
# A count command for VDMC
# All arguments are optional. The current values will be used if not
# specified
# Dr. Mark Koennecke, Juli 1997
#--------------------------------------------------------------------------
proc count { {mode NULL } { preset NULL } } {
starttime [sicstime]
catch {temperature log clear} msg
#----- deal with mode
set mode2 [string toupper $mode]
set mode3 [string trim $mode2]
set mc [string index $mode2 0]
if { [string compare $mc T] == 0 } {
banana CountMode Timer
} elseif { [string compare $mc M] == 0 } {
banana CountMode Monitor
}
#------ deal with preset
if { [string compare $preset NULL] != 0 } {
banana preset $preset
}
#------ prepare a count message
set a [banana preset]
set aa [SplitReply $a]
set b [banana CountMode]
set bb [SplitReply $b]
ClientPut [format " Starting counting in %s mode with a preset of %s" \
$bb $aa]
#------- count
banana InitVal 0
wait 1
banana count
set ret [catch {Success} msg]
#------- StoreData
storedata
if { $ret != 0 } {
error [format "Counting ended with error"]
}
}
#---------------- Repeat -----------------------------------------------
proc repeat { num {mode NULL} {preset NULL} } {
for { set i 0 } { $i < $num } { incr i } {
set ret [catch {count $mode $preset} msg]
if {$ret != 0} {
error "Counting ended with error"
}
}
}
#------------------------------------------------------------------------
# This implements the wwwsics command which generates a listing of
# important experiment parameters in html format for the SICS WWW Status
# application. This version is for the powder diffractometers DMC and
# HRPT.
#
# Mark Koennecke, March 2000
#------------------------------------------------------------------------
proc wwwsics {} {
#----- get all the data we need
set user [GetNum [user]]
set sample [GetNum [sample]]
set tit [GetNum [title]]
set ret [catch {lambda} msg]
if {$ret != 0 } {
set lam Undetermined
} else {
set lam [GetNum $msg]
}
set ret [catch {temperature} msg]
if {$ret != 0 } {
set tem Undetermined
} else {
set tem [GetNum $msg]
}
set run [GetNum [sicsdatanumber]]
catch {incr run} msg
set stat [GetNum [status]]
#------- html format the reply
append result "<table BORDER=2>"
append result <tr> <th>Run Number</th> <td> $run </td> </tr>
append result <tr> <th>Title</th> <td> $tit </td> </tr>
append result <tr> <th>User</th> <td> $user </td> </tr>
append result <tr> <th>Sample </th> <td> $sample </td> </tr>
append result <tr> <th>wavelength</th> <td> $lam</td> </tr>
append result <tr> <th>Sample Temperature</th> <td> $tem</td> </tr>
append result <tr> <th>Status</th> <td> $stat</td> </tr>
append result </table>
return $result
}
#------------ install command
catch {Publish wwwsics Spy} msg

217
mcstas/dmc/vdmcstatus.tcl Normal file
View File

@ -0,0 +1,217 @@
exe batchpath ./
exe syspath ./
sample_mur 0.000000
sample_mur setAccess 2
email UNKNOWN
email setAccess 2
fax UNKNOWN
fax setAccess 2
phone UNKNOWN
phone setAccess 2
adress UNKNOWN
adress setAccess 2
sicsdatapostfix .hdf
sicsdatapostfix setAccess 0
sicsdataprefix powder
sicsdataprefix setAccess 0
starttime 2005-06-21 14:21:44
starttime setAccess 2
comment3 UNKNOWN
comment3 setAccess 2
comment2 UNKNOWN
comment2 setAccess 2
comment1 UNKNOWN
comment1 setAccess 2
sample na2ca3al2f14
sample setAccess 2
collimation UNKNOWN
collimation setAccess 2
user UNKNOWN
user setAccess 2
title UNKNOWN
title setAccess 2
# Motor a9
a9 sign 1.000000
a9 SoftZero 0.000000
a9 SoftLowerLim 0.000000
a9 SoftUpperLim 20.000000
a9 Fixed -1.000000
a9 InterruptMode 0.000000
a9 precision 0.010000
a9 AccessCode 2.000000
a9 movecount 10.000000
# Motor a8
a8 sign 1.000000
a8 SoftZero 0.000000
a8 SoftLowerLim -30.000000
a8 SoftUpperLim 30.000000
a8 Fixed -1.000000
a8 InterruptMode 0.000000
a8 precision 0.010000
a8 AccessCode 2.000000
a8 movecount 10.000000
# Motor a7
a7 sign 1.000000
a7 SoftZero 0.000000
a7 SoftLowerLim -30.000000
a7 SoftUpperLim 30.000000
a7 Fixed -1.000000
a7 InterruptMode 0.000000
a7 precision 0.010000
a7 AccessCode 2.000000
a7 movecount 10.000000
# Motor a6
a6 sign 1.000000
a6 SoftZero 0.000000
a6 SoftLowerLim -30.000000
a6 SoftUpperLim 30.000000
a6 Fixed -1.000000
a6 InterruptMode 0.000000
a6 precision 0.010000
a6 AccessCode 2.000000
a6 movecount 10.000000
# Motor a5
a5 sign 1.000000
a5 SoftZero 0.000000
a5 SoftLowerLim -30.000000
a5 SoftUpperLim 30.000000
a5 Fixed -1.000000
a5 InterruptMode 0.000000
a5 precision 0.010000
a5 AccessCode 2.000000
a5 movecount 10.000000
# Motor a4
a4 sign 1.000000
a4 SoftZero 0.000000
a4 SoftLowerLim -10.000000
a4 SoftUpperLim 120.000000
a4 Fixed -1.000000
a4 InterruptMode 0.000000
a4 precision 0.010000
a4 AccessCode 2.000000
a4 movecount 10.000000
# Motor a3
a3 sign 1.000000
a3 SoftZero 0.000000
a3 SoftLowerLim -180.000000
a3 SoftUpperLim 360.000000
a3 Fixed -1.000000
a3 InterruptMode 0.000000
a3 precision 0.010000
a3 AccessCode 2.000000
a3 movecount 10.000000
# Motor a2
a2 sign 1.000000
a2 SoftZero 0.000000
a2 SoftLowerLim 30.000000
a2 SoftUpperLim 100.000000
a2 Fixed -1.000000
a2 InterruptMode 0.000000
a2 precision 0.010000
a2 AccessCode 2.000000
a2 movecount 10.000000
# Motor a1
a1 sign 1.000000
a1 SoftZero 0.000000
a1 SoftLowerLim 0.000000
a1 SoftUpperLim 120.000000
a1 Fixed -1.000000
a1 InterruptMode 0.000000
a1 precision 0.010000
a1 AccessCode 2.000000
a1 movecount 10.000000
banana CountMode timer
banana preset 180.000000
# Counter counter
counter SetPreset 180.000000
counter SetMode Timer
# Motor twothetad
twothetad sign 1.000000
twothetad SoftZero 0.000000
twothetad SoftLowerLim -10.000000
twothetad SoftUpperLim 120.000000
twothetad Fixed -1.000000
twothetad InterruptMode 0.000000
twothetad precision 0.010000
twothetad AccessCode 2.000000
twothetad movecount 10.000000
# Motor table
table sign 1.000000
table SoftZero 0.000000
table SoftLowerLim -180.000000
table SoftUpperLim 360.000000
table Fixed -1.000000
table InterruptMode 0.000000
table precision 0.010000
table AccessCode 2.000000
table movecount 10.000000
# Motor monochi
monochi sign 1.000000
monochi SoftZero 0.000000
monochi SoftLowerLim -30.000000
monochi SoftUpperLim 30.000000
monochi Fixed -1.000000
monochi InterruptMode 0.000000
monochi precision 0.010000
monochi AccessCode 2.000000
monochi movecount 10.000000
# Motor monophi
monophi sign 1.000000
monophi SoftZero 0.000000
monophi SoftLowerLim -30.000000
monophi SoftUpperLim 30.000000
monophi Fixed -1.000000
monophi InterruptMode 0.000000
monophi precision 0.010000
monophi AccessCode 2.000000
monophi movecount 10.000000
# Motor curvem
curvem sign 1.000000
curvem SoftZero 0.000000
curvem SoftLowerLim 0.000000
curvem SoftUpperLim 20.000000
curvem Fixed -1.000000
curvem InterruptMode 0.000000
curvem precision 0.010000
curvem AccessCode 2.000000
curvem movecount 10.000000
# Motor monoy
monoy sign 1.000000
monoy SoftZero 0.000000
monoy SoftLowerLim -30.000000
monoy SoftUpperLim 30.000000
monoy Fixed -1.000000
monoy InterruptMode 0.000000
monoy precision 0.010000
monoy AccessCode 2.000000
monoy movecount 10.000000
# Motor monox
monox sign 1.000000
monox SoftZero 0.000000
monox SoftLowerLim -30.000000
monox SoftUpperLim 30.000000
monox Fixed -1.000000
monox InterruptMode 0.000000
monox precision 0.010000
monox AccessCode 2.000000
monox movecount 10.000000
# Motor twothetam
twothetam sign 1.000000
twothetam SoftZero 0.000000
twothetam SoftLowerLim 30.000000
twothetam SoftUpperLim 100.000000
twothetam Fixed -1.000000
twothetam InterruptMode 0.000000
twothetam precision 0.010000
twothetam AccessCode 2.000000
twothetam movecount 10.000000
# Motor omegam
omegam sign 1.000000
omegam SoftZero 0.000000
omegam SoftLowerLim 0.000000
omegam SoftUpperLim 120.000000
omegam Fixed -1.000000
omegam InterruptMode 0.000000
omegam precision 0.010000
omegam AccessCode 2.000000
omegam movecount 10.000000