257 lines
9.1 KiB
Tcl
257 lines
9.1 KiB
Tcl
# TODO Return filename from nxcreatefile and call nxreopen nxclose etc
|
|
# with filename
|
|
set tmpstr [string map {"$" ""} {$Name: not supported by cvs2svn $}]
|
|
set nx_content_release_tag [lindex $tmpstr [expr [llength $tmpstr] - 1]]
|
|
set tmpstr [string map {"$" ""} {$Revision: 1.10 $}]
|
|
set nx_content_revision_num [lindex $tmpstr [expr [llength $tmpstr] - 1]]
|
|
|
|
MakeNXScript
|
|
sicsdatafactory new nxscript_data
|
|
|
|
proc getVal {msg} {
|
|
return [string trim [lindex [split $msg =] 1 ] ]
|
|
}
|
|
|
|
proc newFileName {} {
|
|
sicsdatanumber incr;
|
|
set idNum [SplitReply [sicsdatanumber]];
|
|
set dataPath [SplitReply [sicsdatapath]];
|
|
set prefix [SplitReply [sicsdataprefix]];
|
|
set postfix [SplitReply [sicsdatapostfix]];
|
|
set date_time_arr [split [sicstime] " "]
|
|
set isodate [lindex $date_time_arr 0];
|
|
set isotime [string map {: -} [lindex $date_time_arr 1]];
|
|
return [format "%s/%s_%sT%s_%05d%s" $dataPath $prefix $isodate $isotime $idNum $postfix];
|
|
}
|
|
|
|
proc nxcreatefile {nxdic {type nx.hdf}} {
|
|
global nxFileOpen cfPath nexusdic nx_content_release_tag nx_content_revision_num;
|
|
SicsDataPostFix .$type;
|
|
|
|
set nexusdic $nxdic
|
|
array set nxmode [list nx.hdf create5 h5 create5 nx5 create5 xml createxml];
|
|
dataFileName [newFileName]
|
|
nxscript $nxmode($type) [SplitReply [dataFileName]] $cfPath(nexus)/$nexusdic;
|
|
nxscript puttext sics_release [SplitReply [sics_release]]
|
|
nxscript puttext sics_revision [SplitReply [sics_revision_num]]
|
|
nxscript puttext nx_content_release $nx_content_release_tag
|
|
nxscript puttext nx_content_revision $nx_content_revision_num
|
|
set nxFileOpen true
|
|
}
|
|
|
|
|
|
proc nxreopenfile {} {
|
|
global nxFileOpen cfPath nexusdic;
|
|
nxscript reopen [SplitReply [dataFileName]] $cfPath(nexus)/$nexusdic;
|
|
set nxFileOpen true;
|
|
}
|
|
|
|
proc nxclosefile {} {
|
|
global nxFileOpen;
|
|
if {$nxFileOpen == true} {
|
|
nxscript close;
|
|
set nxFileOpen false;
|
|
set flist [split [SplitReply [dataFileName]] "/"];
|
|
set fname [lindex $flist [expr [llength $flist] - 1] ];
|
|
clientput "$fname updated" "event";
|
|
}
|
|
}
|
|
|
|
set dradius 1.25
|
|
set ndect 128
|
|
set tubedia 0.0254
|
|
set pi 3.1415926
|
|
set angsep 1.25
|
|
# stthmin = (180 - (1.25*127))/2
|
|
proc det_height_arr {active_height_mm row_zero dim0} {
|
|
global det_height
|
|
|
|
set hsep [expr $active_height_mm/($dim0-1)]
|
|
|
|
for {set i 0} {$i < $dim0} {incr i} {
|
|
set height [expr ($row_zero - $i) *$hsep]
|
|
set det_height($i) $height
|
|
}
|
|
}
|
|
|
|
proc hmm_save {nxobj entryname point} {
|
|
global dradius ndect angsep;
|
|
set dim0 [SplitReply [hmm configure dim0]];
|
|
set dim1 [SplitReply [hmm configure dim1]];
|
|
putcommon $nxobj $entryname $point;
|
|
putcrystal $nxobj;
|
|
putmonitor $nxobj;
|
|
putsample $nxobj;
|
|
|
|
$nxobj putfloat detangle_degrees [SplitReply [detector_angle_deg]]
|
|
# putpolar_angle $nxobj $dim0 $dim1
|
|
put_det_height_arr $nxobj $dim0
|
|
$nxobj puttext dtype [SplitReply [detector_type]]
|
|
$nxobj puttext ddesc [SplitReply [detector_description]]
|
|
$nxobj putfloat dradius [SplitReply [detector_radius_mm]]
|
|
$nxobj puttext dlayout area
|
|
$nxobj puthm dcounts hmm [SplitReply [hmm_start]] [SplitReply [hmm_length]] [SplitReply [hmm_bank]]
|
|
$nxobj makelink scandata dcounts
|
|
$nxobj makelink scanvertaxis dvaxis
|
|
}
|
|
|
|
proc hmm_addnxscanentry {nxobj entryname point scanVariable scanVarPos scanVarStep start_time} {
|
|
$nxobj puttext estart $start_time
|
|
$nxobj updatedictvar scan_variable $scanVariable
|
|
|
|
set scanVar_value [string trim [lindex [split [$scanVariable] =] 1]]
|
|
$nxobj updatedictvar scanvar_name $scanVariable
|
|
#TODO $nxobj updatedictvar scanvar_units [SplitReply [$scanVariable units]]
|
|
$nxobj updatedictvar scanvar_units "unknown"
|
|
$nxobj updatedictvar scanvar_longname $scanVariable
|
|
nxscript_data clear
|
|
nxscript_data putfloat 0 $scanVar_value
|
|
$nxobj putslab scanvar [list $point] [list 1] nxscript_data
|
|
# $nxobj putfloat scanstep $scanVarStep
|
|
|
|
hmm_save $nxobj $entryname $point;
|
|
$nxobj puttext eend [sicstime];
|
|
}
|
|
|
|
proc bm_save {nxobj entryname point} {
|
|
global dradius ndect angsep;
|
|
# $nxobj updatedictvar scan_variable $scanVariable;
|
|
putcommon $nxobj $entryname $point
|
|
putcrystal $nxobj
|
|
putmonitor $nxobj $point
|
|
putsample $nxobj
|
|
$nxobj puttext dlayout point
|
|
$nxobj makelink scandata dcounts
|
|
}
|
|
|
|
#TODO Refactor: Add bm_save command and use it here.
|
|
proc bm_addnxscanentry {nxobj entryname point scanVariable scanVarPos scanVarStep start_time} {
|
|
$nxobj puttext estart $start_time
|
|
|
|
set scanVar_value [string trim [lindex [split [$scanVariable] =] 1]]
|
|
$nxobj updatedictvar scanvar_name $scanVariable
|
|
#TODO $nxobj updatedictvar scanvar_units [SplitReply [$scanVariable units]]
|
|
$nxobj updatedictvar scanvar_units "unknown"
|
|
$nxobj updatedictvar scanvar_longname $scanVariable
|
|
nxscript_data clear
|
|
nxscript_data putfloat 0 $scanVar_value
|
|
$nxobj putslab scanvar [list $point] [list 1] nxscript_data
|
|
bm_save $nxobj $entryname $point
|
|
# $nxobj putfloat scanstep $scanVarStep
|
|
# Add thetamin and stth to tharr(i)
|
|
# $nxobj puttext dtype He-3 position sensitive detector, tube active length=335+/-5mm, tube diameter=25.4 +/- 0.8mm
|
|
# $nxobj puttext ddesc 128 He-3 proportional counter detector tubes (GE Energy Reuter Stokes Inc. item=RS-P4-0814-217)
|
|
# $nxobj putfloat dradius $dradius
|
|
#TODO add dtype ddesc
|
|
$nxobj puttext eend [sicstime];
|
|
}
|
|
|
|
proc putmonitor {nxobj point} {
|
|
$nxobj puttext mmode [string trim [lindex [split [bm getmode] =] 1]]
|
|
$nxobj putfloat mpreset [string trim [lindex [split [bm getpreset] =] 1]]
|
|
# $nxobj putint mdata [string trim [lindex [split [bm getcounts] =] 1]]
|
|
nxscript_data clear
|
|
nxscript_data putfloat 0 [SplitReply [bm getcounts]]
|
|
$nxobj putslab dcounts [list $point] [list 1] nxscript_data
|
|
$nxobj putfloat mdistance [SplitReply [bmon_distance]]
|
|
}
|
|
|
|
proc put_det_height_arr {nxobj dim0} {
|
|
global det_height
|
|
set det_active_ht_mm [SplitReply [detector_active_height_mm]]
|
|
set row_zero [ SplitReply [detector_zero_row]]
|
|
|
|
det_height_arr $det_active_ht_mm $row_zero $dim0
|
|
$nxobj putarray dvaxis det_height $dim0
|
|
}
|
|
|
|
proc putpolar_angle {nxobj dim0 dim1} {
|
|
global det_height
|
|
set det_radius_mm [SplitReply [detector_radius_mm]]
|
|
set det_angle_rad [SplitReply [detector_angle_rad]]
|
|
set det_active_ht_mm [SplitReply [detector_active_height_mm]]
|
|
set det_rot_rad [ expr [SplitReply [stth]]/[SplitReply [deg_per_rad]] ]
|
|
set row_zero [ SplitReply [detector_zero_row]]
|
|
set row_offset [ SplitReply [detector_ROI_row_offset]]
|
|
set col_zero [ SplitReply [detector_zero_col]]
|
|
set col_offset [ SplitReply [detector_ROI_col_offset]]
|
|
|
|
set angsep [expr $det_angle_rad / ($dim1-1)]
|
|
$nxobj putpolararray dtheta $det_radius_mm $angsep $det_active_ht_mm $det_rot_rad $row_zero $row_offset $col_zero $col_offset $dim0 $dim1
|
|
}
|
|
|
|
proc putsample {nxobj} {
|
|
$nxobj puttext saname [getVal [Sample]]
|
|
}
|
|
proc putcrystal {nxobj} {
|
|
$nxobj puttext ctype [SplitReply [crystal_type]]
|
|
$nxobj putfloat clambda [SplitReply [crystal_wavelength_A]]
|
|
}
|
|
proc putcommon {nxobj entryName point} {
|
|
$nxobj updatedictvar entryName $entryName
|
|
$nxobj puttext etitle [getVal [Title]]
|
|
$nxobj puttext iname [getVal [Instrument]]
|
|
$nxobj puttext username [SplitReply [user]]
|
|
$nxobj puttext useremail [SplitReply [email]]
|
|
$nxobj puttext userphone [SplitReply [phone]]
|
|
|
|
# NXsource
|
|
$nxobj puttext sname OPAL
|
|
$nxobj puttext stype Reactor Neutron Source
|
|
$nxobj puttext sprobe Neutron
|
|
putsamplemotors $nxobj $point
|
|
putslitmotors $nxobj $point
|
|
putmonomotors $nxobj $point
|
|
}
|
|
|
|
proc putsamplemotors {nxobj point} {
|
|
foreach motor { som schi sphi sx sy stth } {
|
|
$nxobj updatedictvar mot_name $motor;
|
|
$nxobj updatedictvar mot_long_name $motor;
|
|
$nxobj updatedictvar mot_units [SplitReply [$motor units]];
|
|
nxscript_data clear
|
|
nxscript_data putfloat 0 [getVal [$motor] ]
|
|
$nxobj putslab nxsample_mot [list $point] [list 1] nxscript_data;
|
|
}
|
|
# sth is a virtual motor
|
|
nxscript_data clear
|
|
nxscript_data putfloat 0 [getVal [sth ]]
|
|
$nxobj putslab sth [list $point] [list 1] nxscript_data;
|
|
}
|
|
|
|
proc putmonomotors {nxobj point} {
|
|
foreach motor { mom mchi mphi mx my mtth } {
|
|
$nxobj updatedictvar mot_name $motor;
|
|
$nxobj updatedictvar mot_long_name $motor;
|
|
$nxobj updatedictvar mot_units [SplitReply [$motor units]];
|
|
nxscript_data clear
|
|
nxscript_data putfloat 0 [getVal [$motor] ]
|
|
$nxobj putslab nxcrystal_mot [list $point] [list 1] nxscript_data;
|
|
}
|
|
# mth is a virtual motor
|
|
nxscript_data clear
|
|
nxscript_data putfloat 0 [getVal [mth ]]
|
|
$nxobj putslab mth [list $point] [list 1] nxscript_data;
|
|
}
|
|
|
|
proc putslitmotors {nxobj point} {
|
|
foreach motor {ss1u ss1d ss1l ss1r ss2u ss2d ss2l ss2r } {
|
|
$nxobj updatedictvar mot_name $motor;
|
|
$nxobj updatedictvar mot_long_name $motor;
|
|
$nxobj updatedictvar mot_units [SplitReply [$motor units]];
|
|
nxscript_data clear
|
|
nxscript_data putfloat 0 [getVal [$motor] ]
|
|
$nxobj putslab nxfilter_mot [list $point] [list 1] nxscript_data;
|
|
}
|
|
foreach motor {ss1vg ss1vo ss1hg ss1ho ss2vg ss2vo ss2hg ss2ho } {
|
|
nxscript_data clear
|
|
nxscript_data putfloat 0 [getVal [$motor] ]
|
|
$nxobj putslab $motor [list $point] [list 1] nxscript_data;
|
|
}
|
|
}
|
|
|
|
publish nxcreatefile user
|
|
publish addnxscanentry user
|
|
publish bm_addnxscanentry user
|
|
|