Refactored file saving.
r2723 | ffr | 2008-10-17 12:47:58 +1100 (Fri, 17 Oct 2008) | 2 lines
This commit is contained in:
committed by
Douglas Clowes
parent
8f95806ecc
commit
fb97ee8631
@@ -120,10 +120,9 @@ proc ::nexus::datapath {} {
|
|||||||
# @brief Generate a filename from sicsdatanumber and 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
|
# @param postfix This is the filename suffix, must be one of: nx.hdf, hdf, h5, nx5, xml
|
||||||
proc newFileName {postfix} {
|
proc newFileName {idNum postfix} {
|
||||||
|
|
||||||
array set inst_mnem {quokka QKK wombat WBT echidna ECH kowari KWR koala KOL taipan TPN platypus PLP pelican PLN}
|
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 prefix [SplitReply [sicsdataprefix]]
|
||||||
set date_time_arr [split [sicstime] " "]
|
set date_time_arr [split [sicstime] " "]
|
||||||
set isodate [lindex $date_time_arr 0]
|
set isodate [lindex $date_time_arr 0]
|
||||||
@@ -193,49 +192,52 @@ proc newFileName {postfix} {
|
|||||||
variable nexusdic
|
variable nexusdic
|
||||||
variable currFilename
|
variable currFilename
|
||||||
variable start_seconds_array
|
variable start_seconds_array
|
||||||
variable links_and_plotinfo_notdone
|
|
||||||
|
|
||||||
array set state {file,new "true" file,open "false" file,namestyle "data"\
|
array set state {
|
||||||
file,format "hdf" file,type "@none"}
|
file,open "false"
|
||||||
|
file,namestyle "data"
|
||||||
|
file,format "hdf"
|
||||||
|
file,fileset "false"
|
||||||
|
file,incr_datnum "false"
|
||||||
|
file,labels @singlefile
|
||||||
|
}
|
||||||
|
|
||||||
set nexusdic "nexus.dic"
|
set nexusdic "nexus.dic"
|
||||||
array set currFilename ""
|
array set currFilename ""
|
||||||
array set start_seconds_array ""
|
array set start_seconds_array ""
|
||||||
array set links_and_plotinfo_notdone ""
|
|
||||||
}
|
}
|
||||||
|
|
||||||
##
|
##
|
||||||
# @brief Create a nexus file
|
# @brief Create a nexus file
|
||||||
# This first generates a nexus dictionary file from the hdb tree and then creates a new
|
# This first generates a nexus dictionary file from the hdb tree and then creates a new
|
||||||
# nexus file based on that dictionary.
|
# nexus file based on that dictionary.
|
||||||
proc ::nexus::createfile {} {
|
proc ::nexus::createfile {FileName} {
|
||||||
global cfPath
|
|
||||||
variable nexusdic
|
variable nexusdic
|
||||||
variable state
|
variable state
|
||||||
variable data_gp_path
|
variable data_gp_path
|
||||||
variable currFilename
|
|
||||||
|
|
||||||
if [ catch {
|
if [ catch {
|
||||||
if {$state(file,open) == "true"} {
|
if {$state(file,open) == "true"} {
|
||||||
error_msg "Can't create a new file because the current file is still open"
|
error "Can't create a new file because the current file is still open"
|
||||||
} elseif {$state(file,new) == "false"} {
|
}
|
||||||
error_msg "This function should only be called when state(file,new) = true"
|
switch $state(file,format) {
|
||||||
|
"hdf" {set create_type create5}
|
||||||
|
"xml" {set create_type createxml}
|
||||||
|
default {
|
||||||
|
error "ERROR: Invalid file format $state(file,format)"
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
set file_format [SplitReply [SicsDataPostFix]]
|
|
||||||
array set nxmode [list nx.hdf create5 hdf create5 h5 create5 nx5 create5 xml createxml]
|
|
||||||
set nxdict_path [::nexus::gen_nxdict $nexusdic]
|
set nxdict_path [::nexus::gen_nxdict $nexusdic]
|
||||||
hsetprop $data_gp_path currentfiletype [::utility::hgetplainprop $data_gp_path datatype]
|
hsetprop $data_gp_path currentfiletype [::utility::hgetplainprop $data_gp_path datatype]
|
||||||
if {$state(file,fileset) == true} {
|
if {$state(file,incr_datnum) == true} {
|
||||||
foreach flabel $state(file,labels) {
|
sicsdatanumber incr
|
||||||
dataFileName $currFilename($flabel)
|
}
|
||||||
nxscript $nxmode($file_format) $currFilename($flabel) $nxdict_path
|
if [catch {nxscript $create_type $FileName $nxdict_path} message] {
|
||||||
}
|
killfile
|
||||||
} else {
|
error $message
|
||||||
dataFileName $currFilename(@singlefile)
|
|
||||||
nxscript $nxmode($file_format) $currFilename(@singlefile) $nxdict_path
|
|
||||||
}
|
}
|
||||||
set state(file,open) false
|
set state(file,open) false
|
||||||
set state(file,new) false
|
|
||||||
} message ] {
|
} message ] {
|
||||||
if {$::errorCode=="NONE"} {return $message}
|
if {$::errorCode=="NONE"} {return $message}
|
||||||
return -code error $message
|
return -code error $message
|
||||||
@@ -264,7 +266,7 @@ proc ::nexus::isValidFileType {type} {
|
|||||||
# If namestyle=scratch, the save command will create scratch files.
|
# If namestyle=scratch, the save command will create scratch files.
|
||||||
#
|
#
|
||||||
# postconditions:
|
# postconditions:
|
||||||
# state(file,open) true state(file,new) false
|
# state(file,open) true
|
||||||
# /data/currentfiletype == UNKNOWN
|
# /data/currentfiletype == UNKNOWN
|
||||||
proc ::nexus::newfile {type {namestyle data}} {
|
proc ::nexus::newfile {type {namestyle data}} {
|
||||||
::nexus::newfile_collection -filetype $type -savetype $namestyle
|
::nexus::newfile_collection -filetype $type -savetype $namestyle
|
||||||
@@ -273,7 +275,7 @@ proc ::nexus::newfile {type {namestyle data}} {
|
|||||||
##
|
##
|
||||||
# @brief Let's make a collection of files (ie a file-set) or just one.
|
# @brief Let's make a collection of files (ie a file-set) or just one.
|
||||||
#
|
#
|
||||||
# @param -label L or {L1 L2 ..}, optional. A list of labels which identify a file-set
|
# @param -labels L or {L1 L2 ..}, optional. A list of labels which identify a file-set
|
||||||
# If you don't specify a list of labels then only one file is created
|
# If you don't specify a list of labels then only one file is created
|
||||||
proc ::nexus::newfile_collection {args} {
|
proc ::nexus::newfile_collection {args} {
|
||||||
variable filetype_spec
|
variable filetype_spec
|
||||||
@@ -287,24 +289,33 @@ proc ::nexus::newfile_collection {args} {
|
|||||||
::utility::check_valid_options $args $valid_options
|
::utility::check_valid_options $args $valid_options
|
||||||
::utility::check_required_options $args $required_options
|
::utility::check_required_options $args $required_options
|
||||||
array set param $args
|
array set param $args
|
||||||
set file_format [SplitReply [SicsDataPostFix]]
|
set file_suffix [SplitReply [SicsDataPostFix]]
|
||||||
|
switch $file_suffix {
|
||||||
|
hdf - nx.hdf - h5 - nx5 {set state(file,format) hdf}
|
||||||
|
xml {set state(file,format) xml}
|
||||||
|
default { error "ERROR: Invalid file suffix $file_suffix" }
|
||||||
|
}
|
||||||
set state(file,namestyle) $param(-savetype)
|
set state(file,namestyle) $param(-savetype)
|
||||||
file_set_list "UNKNOWN"
|
file_set_list "UNKNOWN"
|
||||||
set state(file,new) true
|
if {$param(-savetype) == "scratch"} {
|
||||||
|
set state(file,incr_datnum) false
|
||||||
|
} else {
|
||||||
|
set state(file,incr_datnum) true
|
||||||
|
}
|
||||||
|
set idNum [expr 1 + [SplitReply [sicsdatanumber]]]
|
||||||
if [info exists param(-labels)] {
|
if [info exists param(-labels)] {
|
||||||
set state(file,fileset) "true"
|
set state(file,fileset) "true"
|
||||||
set state(file,labels) $param(-labels)
|
set state(file,labels) $param(-labels)
|
||||||
if {$param(-savetype) == "scratch"} {
|
if {$param(-savetype) == "scratch"} {
|
||||||
foreach fid $state(file,labels) {
|
foreach fid $state(file,labels) {
|
||||||
set currFilename($fid) [format "%s/scratch_%s.%s" [::nexus::datapath] $fid $file_format]
|
set currFilename($fid) [format "%s/scratch_%s.%s" [::nexus::datapath] $fid $file_suffix]
|
||||||
lappend files $currFilename($fid)
|
lappend files $currFilename($fid)
|
||||||
sicsdatanumber incr
|
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
foreach fid $state(file,labels) {
|
foreach fid $state(file,labels) {
|
||||||
set currFilename($fid) [newFileName $file_format]
|
set currFilename($fid) [newFileName $idNum $file_suffix]
|
||||||
|
incr idNum
|
||||||
lappend files $currFilename($fid)
|
lappend files $currFilename($fid)
|
||||||
sicsdatanumber incr
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
file_set_list [join $files ,]
|
file_set_list [join $files ,]
|
||||||
@@ -312,11 +323,9 @@ proc ::nexus::newfile_collection {args} {
|
|||||||
set state(file,fileset) "false"
|
set state(file,fileset) "false"
|
||||||
set state(file,labels) @singlefile
|
set state(file,labels) @singlefile
|
||||||
if {$param(-savetype) == "scratch"} {
|
if {$param(-savetype) == "scratch"} {
|
||||||
set currFilename(@singlefile) [format "%s/scratch.%s" [::nexus::datapath] $file_format]
|
set currFilename(@singlefile) [format "%s/scratch.%s" [::nexus::datapath] $file_suffix]
|
||||||
sicsdatanumber incr
|
|
||||||
} else {
|
} else {
|
||||||
set currFilename(@singlefile) [newFileName $file_format]
|
set currFilename(@singlefile) [newFileName $idNum $file_suffix]
|
||||||
sicsdatanumber incr
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
hsetprop $data_gp_path currentfiletype UNKNOWN
|
hsetprop $data_gp_path currentfiletype UNKNOWN
|
||||||
@@ -394,7 +403,6 @@ proc ::nexus::save {{point 0}} {
|
|||||||
variable state
|
variable state
|
||||||
variable data_gp_path
|
variable data_gp_path
|
||||||
variable start_seconds_array
|
variable start_seconds_array
|
||||||
variable links_and_plotinfo_notdone
|
|
||||||
variable currFilename
|
variable currFilename
|
||||||
|
|
||||||
set valid_options [list "-index" "-label"]
|
set valid_options [list "-index" "-label"]
|
||||||
@@ -413,7 +421,6 @@ proc ::nexus::save {{point 0}} {
|
|||||||
# ::data::gumtree_save -set run_number $point
|
# ::data::gumtree_save -set run_number $point
|
||||||
data_run_number $point
|
data_run_number $point
|
||||||
|
|
||||||
set isNewFile [expr {$state(file,new) == "true"}]
|
|
||||||
set currFileType [::utility::hgetplainprop $data_gp_path currentfiletype]
|
set currFileType [::utility::hgetplainprop $data_gp_path currentfiletype]
|
||||||
set currDataType [::utility::hgetplainprop $data_gp_path datatype]
|
set currDataType [::utility::hgetplainprop $data_gp_path datatype]
|
||||||
set dataTypeChanged [expr {$currFileType != $currDataType}]
|
set dataTypeChanged [expr {$currFileType != $currDataType}]
|
||||||
@@ -421,7 +428,6 @@ proc ::nexus::save {{point 0}} {
|
|||||||
error_msg "You must set the file type, eg 'newfile BEAM_MONITOR' or 'newfile BEAM_MONITOR scratch' "
|
error_msg "You must set the file type, eg 'newfile BEAM_MONITOR' or 'newfile BEAM_MONITOR scratch' "
|
||||||
}
|
}
|
||||||
|
|
||||||
#TODO User must provide a -label if we are creating a file-set
|
|
||||||
if [info exists param(-label)] {
|
if [info exists param(-label)] {
|
||||||
if {[lsearch -exact $state(file,labels) $param(-label)] == -1} {
|
if {[lsearch -exact $state(file,labels) $param(-label)] == -1} {
|
||||||
error "ERROR: The label must be one of $state(file,labels)"
|
error "ERROR: The label must be one of $state(file,labels)"
|
||||||
@@ -433,27 +439,29 @@ proc ::nexus::save {{point 0}} {
|
|||||||
}
|
}
|
||||||
set data_label @singlefile
|
set data_label @singlefile
|
||||||
}
|
}
|
||||||
if {$isNewFile || $dataTypeChanged} {
|
if {! [file exists $currFilename($data_label)]} {
|
||||||
set state(file,new) true
|
set isNewFile true
|
||||||
::nexus::createfile
|
} else {
|
||||||
estart [lindex [sicstime] 1]
|
set isNewFile false
|
||||||
eend [lindex [sicstime] 1]
|
}
|
||||||
array unset start_seconds_array
|
if [string match -nocase "*scratch*" $currFilename($data_label)] {
|
||||||
array unset links_and_plotinfo_notdone
|
set isScratchFile true
|
||||||
set start_seconds [clock seconds]
|
} else {
|
||||||
foreach flabel $state(file,labels) {
|
set isScratchFile false
|
||||||
set start_seconds_array($flabel) $start_seconds
|
}
|
||||||
set links_and_plotinfo_notdone($flabel) "true"
|
if {$isNewFile || $isScratchFile} {
|
||||||
}
|
::nexus::createfile $currFilename($data_label)
|
||||||
timestamp 0
|
|
||||||
dataFileName $currFilename($data_label)
|
dataFileName $currFilename($data_label)
|
||||||
|
estart [lindex [sicstime] 1]
|
||||||
|
eend [lindex [sicstime] 1]
|
||||||
|
array unset start_seconds_array
|
||||||
|
set start_seconds [clock seconds]
|
||||||
|
set start_seconds_array($data_label) $start_seconds
|
||||||
|
timestamp 0
|
||||||
::nexus::nxreopenfile $currFilename($data_label)
|
::nexus::nxreopenfile $currFilename($data_label)
|
||||||
::nexus::save_data $point
|
::nexus::save_data $point
|
||||||
if $links_and_plotinfo_notdone($data_label) {
|
::nexus::makelinks
|
||||||
::nexus::makelinks
|
::nexus::set_plotdata_info
|
||||||
::nexus::set_plotdata_info
|
|
||||||
set links_and_plotinfo_notdone($data_label) "false"
|
|
||||||
}
|
|
||||||
::nexus::nxclosefile $currFilename($data_label)
|
::nexus::nxclosefile $currFilename($data_label)
|
||||||
} else {
|
} else {
|
||||||
eend [lindex [sicstime] 1]
|
eend [lindex [sicstime] 1]
|
||||||
@@ -461,15 +469,10 @@ proc ::nexus::save {{point 0}} {
|
|||||||
dataFileName $currFilename($data_label)
|
dataFileName $currFilename($data_label)
|
||||||
::nexus::nxreopenfile $currFilename($data_label)
|
::nexus::nxreopenfile $currFilename($data_label)
|
||||||
::nexus::save_data $point
|
::nexus::save_data $point
|
||||||
if $links_and_plotinfo_notdone($data_label) {
|
|
||||||
::nexus::makelinks
|
|
||||||
::nexus::set_plotdata_info
|
|
||||||
set links_and_plotinfo_notdone($data_label) "false"
|
|
||||||
}
|
|
||||||
::nexus::nxclosefile $currFilename($data_label)
|
::nexus::nxclosefile $currFilename($data_label)
|
||||||
}
|
}
|
||||||
} message ] {
|
} message ] {
|
||||||
::nexus::nxclosefile
|
::nexus::nxclosefile $currFilename($data_label)
|
||||||
if {$::errorCode=="NONE"} {return $message}
|
if {$::errorCode=="NONE"} {return $message}
|
||||||
return -code error $message
|
return -code error $message
|
||||||
}
|
}
|
||||||
@@ -1211,7 +1214,7 @@ foreach expt $::nexus::exports {
|
|||||||
|
|
||||||
set tmpstr [string map {"$" ""} {$Name: not supported by cvs2svn $}]
|
set tmpstr [string map {"$" ""} {$Name: not supported by cvs2svn $}]
|
||||||
set nx_content_release_tag [lindex $tmpstr [expr [llength $tmpstr] - 1]]
|
set nx_content_release_tag [lindex $tmpstr [expr [llength $tmpstr] - 1]]
|
||||||
set tmpstr [string map {"$" ""} {$Revision: 1.43 $}]
|
set tmpstr [string map {"$" ""} {$Revision: 1.44 $}]
|
||||||
set nx_content_revision_num [lindex $tmpstr [expr [llength $tmpstr] - 1]]
|
set nx_content_revision_num [lindex $tmpstr [expr [llength $tmpstr] - 1]]
|
||||||
|
|
||||||
#namespace eval data {
|
#namespace eval data {
|
||||||
|
|||||||
Reference in New Issue
Block a user