Files
sics/site_ansto/instrument/config/nexus/nxscripts_common_1.tcl
Ferdi Franceschini 2d7cf89385 Set x and y pixel offsets and run number.
The run number is used as the first dimension axis for
simple count and save operations.

r1770 | ffr | 2007-04-01 14:36:09 +1000 (Sun, 01 Apr 2007) | 4 lines
2012-11-15 13:12:52 +11:00

305 lines
10 KiB
Tcl

# TODO Return filename from nxcreatefile and call nxreopen nxclose etc
# TODO Make an nxscript namespace for all this.
# dictalias is a global hash which records the alias which the value of
# a sics object (eg motors) is written to. The has is indexed by the
# objects name. It is useful for making links to datasets.
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.17 $}]
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 dim1} {
global det_height
set hsep [expr $active_height_mm/($dim1-1)]
for {set i 0} {$i < $dim1} {incr i} {
set height [expr ($row_zero - $i) *$hsep]
set det_height($i) $height
}
}
proc hmm_save {nxobj entryname point} {
global dradius ndect angsep dictalias;
set dictalias(hmm) hmcounts
set dim0 [SplitReply [hmm configure dim0]];
set dim1 [SplitReply [hmm configure dim1]];
putcommon $nxobj $entryname $point;
putcrystal $nxobj;
putmonitor $nxobj $point;
putsample $nxobj;
$nxobj putfloat detangle_degrees [SplitReply [detector_angle_deg]]
# put1Dpolar_angle $nxobj $dim0;
put_det_haxis_arr $nxobj $dim0;
put_det_vaxis_arr $nxobj $dim1;
$nxobj puttext dtype [SplitReply [detector_type]]
$nxobj puttext ddesc [SplitReply [detector_description]]
$nxobj putfloat dradius [SplitReply [detector_radius_mm]]
$nxobj puttext dlayout area
set histo_length [SplitReply [hmm_length]]
$nxobj updatedictvar padim0 $dim0
$nxobj updatedictvar padim1 $dim1
$nxobj putslab $dictalias(hmm) [list $point 0 0] [list 1 $dim0 $dim1 ] hmm [SplitReply [hmm_start]] $histo_length [SplitReply [hmm_bank]]
#TODO replace scandata with generic name
$nxobj makelink scandata hmcounts
$nxobj makelink scanhoraxis x_pixel_offset
$nxobj makelink scanvertaxis y_pixel_offset
}
proc hmm_addnxscanentry {nxobj entryname point scanVariable scanVarPos scanVarStep start_time} {
global dictalias;
$nxobj puttext estart $start_time;
hmm_save $nxobj $entryname $point;
fillPath $nxobj $scanVariable;
$nxobj makelink scanvar $dictalias($scanVariable);
$nxobj putattribute $dictalias($scanVariable) axis 1;
$nxobj putattribute hmcounts signal 1;
$nxobj putattribute hmcounts axes $scanVariable:x_pixel_offset:y_pixel_offset;
$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
#TODO replace scandata with generic name
$nxobj makelink scandata bmcounts
}
proc bm_addnxscanentry {nxobj entryname point scanVariable scanVarPos scanVarStep start_time} {
global dictalias;
$nxobj puttext estart $start_time;
bm_save $nxobj $entryname $point;
fillPath $nxobj $scanVariable;
$nxobj makelink scanvar $dictalias($scanVariable);
$nxobj putattribute $dictalias($scanVariable) axis 1;
$nxobj putattribute bmcounts signal 1;
$nxobj putattribute bmcounts axes $scanVariable;
#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 bmcounts [list $point] [list 1] nxscript_data
$nxobj putfloat mdistance [SplitReply [bmon_distance]]
}
proc put_det_haxis_arr {nxobj dim0} {
set det_radius_mm [SplitReply [detector_radius_mm]]
set angsep [expr $det_angle_rad / ($dim0-1)]
for {set i 0} {$i < $dim0} {incr i} {
set x_arr($i) [expr ($dim0 - 1 - $i)*$angsep*$detector_radius_mm]
}
$nxobj putarray x_pixel_offset x_arr $dim0;
}
proc put_det_vaxis_arr {nxobj dim1} {
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 $dim1
$nxobj putarray dvaxis det_height $dim1
$nxobj putattribute dvaxis axis 3;
}
proc put1Dpolar_angle {nxobj dim0} {
set det_angle_rad [SplitReply [detector_angle_rad]]
set col_zero [ SplitReply [detector_zero_col]]
set col_offset [ SplitReply [detector_ROI_col_offset]]
set det_rot_rad [ expr [SplitReply [stth]]/[SplitReply [deg_per_rad]] ]
set angsep [expr $det_angle_rad / ($dim0-1)]
for {set i 0} {$i < $dim0} {incr i} {
set polar_array($i) [expr $det_rot_rad+(($dim0 - 1 - $i) + $col_zero + $col_offset)*$angsep]
}
$nxobj putarray polar_angle polar_array $dim0;
}
proc put2Dpolar_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
nxscript_data clear;
nxscript_data putint 0 $point;
$nxobj putslab erun [list $point] [list 1] nxscript_data;
$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
}
# This should be called before making a link to a dataset
# via a value in the dictalias hash.
proc fillPath {nxobj sobj} {
set otype [SplitReply [sicslist $sobj type]];
if {$otype == "Motor"} {
fillMotPath $nxobj $sobj;
}
}
proc fillMotPath {nxobj motor} {
$nxobj updatedictvar mot_name $motor;
$nxobj updatedictvar mot_long_name [SplitReply [$motor long_name]];
$nxobj updatedictvar mot_units [SplitReply [$motor units]];
}
proc putsamplemotors {nxobj point} {
global dictalias;
foreach motor { som schi sphi sx sy stth } {
fillMotPath $nxobj $motor;
set dictalias($motor) nxsample_mot
nxscript_data clear;
nxscript_data putfloat 0 [getVal [$motor] ];
$nxobj putslab $dictalias($motor) [list $point] [list 1] nxscript_data;
}
# sth is a virtual motor
nxscript_data clear
nxscript_data putfloat 0 [getVal [sth ]]
set dictalias(sth) sth
$nxobj putslab $dictalias(sth) [list $point] [list 1] nxscript_data;
}
proc putmonomotors {nxobj point} {
global dictalias;
foreach motor { mom mchi mphi mx my mtth } {
fillMotPath $nxobj $motor;
set dictalias($motor) nxcrystal_mot
nxscript_data clear
nxscript_data putfloat 0 [getVal [$motor] ]
$nxobj putslab $dictalias($motor) [list $point] [list 1] nxscript_data;
}
# mth is a virtual motor
nxscript_data clear
nxscript_data putfloat 0 [getVal [mth ]]
set dictalias(mth) mth
$nxobj putslab $dictalias(mth) [list $point] [list 1] nxscript_data;
}
proc putslitmotors {nxobj point} {
global dictalias;
foreach motor {ss1u ss1d ss1l ss1r ss2u ss2d ss2l ss2r } {
fillMotPath $nxobj $motor;
set dictalias($motor) nxfilter_mot
nxscript_data clear
nxscript_data putfloat 0 [getVal [$motor] ]
$nxobj putslab $dictalias($motor) [list $point] [list 1] nxscript_data;
}
foreach motor {ss1vg ss1vo ss1hg ss1ho ss2vg ss2vo ss2hg ss2ho } {
set dictalias($motor) $motor
nxscript_data clear
nxscript_data putfloat 0 [getVal [$motor] ]
$nxobj putslab $dictalias($motor) [list $point] [list 1] nxscript_data;
}
}
publish nxcreatefile user
publish addnxscanentry user
publish bm_addnxscanentry user