Save scratch files in data directory.

Refactor to have explicit ::nexus:: prefix on procedures.

r2204 | ffr | 2007-10-31 16:44:38 +1100 (Wed, 31 Oct 2007) | 3 lines
This commit is contained in:
Ferdi Franceschini
2007-10-31 16:44:38 +11:00
committed by Douglas Clowes
parent 5c66aa29ac
commit f8c64b55a0

View File

@@ -5,33 +5,14 @@
MakeNXScript
sicsdatafactory new nxscript_data
##
# @brief Strips the output of a SICS command leaving only the value\n
# TODO Replace $cmd_output with [$cmd_output] so we can just pass the command name
#
# @param cmd_output The output from a command substitution
# @return The unadorned value returned by the SICS command which produced cmd_output
proc getVal {cmd_output} {
return [string trim [lindex [split $cmd_output =] 1 ] ]
}
##
# @brief Generate a filename from sicsdatanumber and sicsdatapath
#
# @param postfix This is the filename suffix, must be one of: nx.hdf, hdf, h5, nx5, xml
proc newFileName {postfix} {
array set inst_mnem {quokka QKK wombat WBT echidna ECH kowari KWR koala KOL taipan TPN platypus PLP pelican PLN}
set idNum [SplitReply [sicsdatanumber]]
set dataPath [SplitReply [sicsdatapath]]
# set prefix [SplitReply [sicsdataprefix]]
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%07d.%s" $dataPath $inst_mnem([instname]) $idNum $postfix]
}
namespace eval nexus {
set exports [list newfile closefile save data]
eval namespace export $exports
if 0 {datafilename}
variable filetypes
set filetypes [list BEAM_MONITOR HISTOPERIOD_XYT TOTAL_HISTOGRAM_XY TOTAL_HISTOGRAM_XT TOTAL_HISTOGRAM_YT TOTAL_HISTOGRAM_X TOTAL_HISTOGRAM_Y TOTAL_HISTOGRAM_T ]
##
# @brief This is the nexus dictionary generated by the gen_nxdict function
variable nxdictionary
@@ -100,6 +81,35 @@ namespace eval nexus {
save_policy {include @all exclude {hmm_xy hmm_xt hmm_yt hmm_x hmm_y hmm}}
}
}
}
##
# @brief Strips the output of a SICS command leaving only the value\n
# TODO Replace $cmd_output with [$cmd_output] so we can just pass the command name
#
# @param cmd_output The output from a command substitution
# @return The unadorned value returned by the SICS command which produced cmd_output
proc getVal {cmd_output} {
return [string trim [lindex [split $cmd_output =] 1 ] ]
}
proc ::nexus::datapath {} {
return [SplitReply [sicsdatapath]]
}
##
# @brief Generate a filename from sicsdatanumber and sicsdatapath
#
# @param postfix This is the filename suffix, must be one of: nx.hdf, hdf, h5, nx5, xml
proc newFileName {postfix} {
array set inst_mnem {quokka QKK wombat WBT echidna ECH kowari KWR koala KOL taipan TPN platypus PLP pelican PLN}
set idNum [SplitReply [sicsdatanumber]]
# set prefix [SplitReply [sicsdataprefix]]
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%07d.%s" [::nexus::datapath] $inst_mnem([instname]) $idNum $postfix]
}
proc ::nexus::process_filetype_policy {filetype filetype_spec} {
upvar $filetype_spec ft_spec
@@ -115,7 +125,6 @@ namespace eval nexus {
::nexus::data $policy
}
"save_policy" {
clientput "save_policy is $policy"
foreach {save_action action_list} $policy {
switch $save_action {
"include" {
@@ -155,13 +164,10 @@ namespace eval nexus {
}
}
set exports [list newfile closefile save data]
eval namespace export $exports
if 0 {datafilename}
##
# @brief Initialise state variables
proc init {} {
proc ::nexus::init {} {
variable state
variable nexusdic
array set state {file,new "true" file,open "false" file,namestyle "data"\
@@ -173,7 +179,7 @@ namespace eval nexus {
# @brief Create a nexus file
# This first generates a nexus dictionary file from the hdb tree and then creates a new
# nexus file based on that dictionary.
proc createfile {} {
proc ::nexus::createfile {} {
global cfPath
variable nexusdic
variable state
@@ -187,7 +193,7 @@ namespace eval nexus {
array set nxmode [list nx.hdf create5 hdf create5 h5 create5 nx5 create5 xml createxml]
set nxdict_path [::nexus::gen_nxdict $nexusdic]
if {$state(file,namestyle) == "scratch"} {
dataFileName [format "scratch.%s" $file_format]
dataFileName [format "%s/scratch.%s" [::nexus::datapath] $file_format]
} else {
sicsdatanumber incr
dataFileName [newFileName $file_format]
@@ -198,13 +204,11 @@ namespace eval nexus {
set state(file,new) false
}
variable filetypes
set filetypes [list BEAM_MONITOR HISTOPERIOD_XYT TOTAL_HISTOGRAM_XY TOTAL_HISTOGRAM_XT TOTAL_HISTOGRAM_YT TOTAL_HISTOGRAM_X TOTAL_HISTOGRAM_Y TOTAL_HISTOGRAM_T ]
##
# @brief Checks if the given file type is defined.
#
# @return 1 on success, 0 on failure
proc isValidFileType {type} {
proc ::nexus::isValidFileType {type} {
variable filetypes
if {[lsearch $filetypes $type] == -1} {
return 0
@@ -224,7 +228,7 @@ proc isValidFileType {type} {
# postconditions:
# state(file,open) true state(file,new) false
# /data/currentfiletype == UNKNOWN
proc newfile {type {namestyle data}} {
proc ::nexus::newfile {type {namestyle data}} {
variable filetype_spec
variable state
@@ -250,7 +254,7 @@ proc newfile {type {namestyle data}} {
# function
#
# @see ::nexus::savetree
proc save_data {point} {
proc ::nexus::save_data {point} {
debug_msg "save point $point in [dataFileName]"
::nexus::nxreopenfile
foreach child [hlist /] {
@@ -269,7 +273,7 @@ proc newfile {type {namestyle data}} {
#
# A new file will be created if the new file state has been set to true, or
# if the current data type doesn't match the current file type.
proc save {{point 0}} {
proc ::nexus::save {{point 0}} {
variable state
if {[string is integer $point] == 0} {
@@ -304,7 +308,7 @@ proc newfile {type {namestyle data}} {
# @brief Reopen the current file, close it with nxclosefile
#
# @see nxclosefile
proc nxreopenfile {} {
proc ::nexus::nxreopenfile {} {
global cfPath
variable state
variable nexusdic
@@ -318,7 +322,7 @@ proc newfile {type {namestyle data}} {
# @brief Close the current file. You can reopen it with nxreopenfile
#
# @see nxreopenfile
proc nxclosefile {} {
proc ::nexus::nxclosefile {} {
variable state
if {$state(file,open) == "true"} {
nxscript close
@@ -427,7 +431,7 @@ proc newfile {type {namestyle data}} {
#
# Sets the "signal" and "axes" attributes on the plottable data
# Also sets the "axis" attribute for each of the axes.
proc linkdata {} {
proc ::nexus::linkdata {} {
array unset axes
set hpath /data
::nexus::nxreopenfile
@@ -469,7 +473,7 @@ proc newfile {type {namestyle data}} {
#
# @param hpath path of subtree to save, must not be "/"
# @param pt Current array index for mutable data (optional default=0)
proc savetree {hpath {pt 0}} {
proc ::nexus::savetree {hpath {pt 0}} {
foreach child [hlist /$hpath] {
array unset p_arr
array set p_arr [::utility::hlistplainprop /$hpath/$child]
@@ -504,7 +508,7 @@ proc newfile {type {namestyle data}} {
# hdb path
#
# @see gen_nxdict
proc _gen_nxdict {hpath dictPath name nxc} {
proc ::nexus::_gen_nxdict {hpath dictPath name nxc} {
variable nxdictionary
if {[::utility::hgetplainprop /$hpath data] == "false"} {
debug_msg "$hpath doesn't have a data property"
@@ -544,7 +548,7 @@ proc newfile {type {namestyle data}} {
#
# @param nexusdic Name of the nexus dictionary that will be created.
# @return Full path to the nexus dictionary.
proc gen_nxdict {nexusdic} {
proc ::nexus::gen_nxdict {nexusdic} {
global cfPath
variable nxdictionary
set nxdict_path $cfPath(nexus)/$nexusdic
@@ -569,7 +573,7 @@ proc newfile {type {namestyle data}} {
##
# @brief Set SICS object attributes which are required for creating nexus data files.
proc set_sobj_attributes {} {
proc ::nexus::set_sobj_attributes {} {
# SICS commands
sicslist setatt nxscript privilege internal
# SICS data objects
@@ -604,7 +608,6 @@ proc newfile {type {namestyle data}} {
sicslist setatt $sobj sdsinfo ::nexus::script::sdsinfo
}
}
}
namespace eval ::nexus::histmem {}
namespace eval ::nexus::motor {}
@@ -613,12 +616,6 @@ namespace eval ::nexus::sicsvariable {}
namespace eval ::nexus::singlecounter {}
namespace eval ::nexus::script {}
namespace import ::nexus::*
foreach expt $::nexus::exports {
publish $expt user
sicslist setatt $expt privilege internal
}
##
# @brief Convert the given hdb type to Nexus data type
#
@@ -659,6 +656,7 @@ proc ::nexus::histmem::save {hm nxalias data_type args} {
}
set data_start 0
set bank 0
$hm init
nxscript putslab $nxalias $indStartList $indLenList $hm $data_start $datalen $bank
}] {
return -code error $::errorInfo
@@ -812,6 +810,12 @@ proc ::nexus::script::sdsinfo {script data_type args} {
return " -type $dtype -rank 1 -dim {$size}"
}
namespace import ::nexus::*
foreach expt $::nexus::exports {
publish $expt user
sicslist setatt $expt privilege internal
}
# TODO Return filename from nxcreatefile and call nxreopen nxclose etc
# TODO Make an nxscript namespace for all this.
@@ -823,7 +827,7 @@ proc ::nexus::script::sdsinfo {script data_type args} {
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.32 $}]
set tmpstr [string map {"$" ""} {$Revision: 1.33 $}]
set nx_content_revision_num [lindex $tmpstr [expr [llength $tmpstr] - 1]]
namespace eval data {