Refactored file saving.

r2723 | ffr | 2008-10-17 12:47:58 +1100 (Fri, 17 Oct 2008) | 2 lines
This commit is contained in:
Ferdi Franceschini
2008-10-17 12:47:58 +11:00
committed by Douglas Clowes
parent 8f95806ecc
commit fb97ee8631

View File

@@ -120,10 +120,9 @@ proc ::nexus::datapath {} {
# @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} {
proc newFileName {idNum 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]
@@ -193,49 +192,52 @@ proc newFileName {postfix} {
variable nexusdic
variable currFilename
variable start_seconds_array
variable links_and_plotinfo_notdone
array set state {file,new "true" file,open "false" file,namestyle "data"\
file,format "hdf" file,type "@none"}
array set state {
file,open "false"
file,namestyle "data"
file,format "hdf"
file,fileset "false"
file,incr_datnum "false"
file,labels @singlefile
}
set nexusdic "nexus.dic"
array set currFilename ""
array set start_seconds_array ""
array set links_and_plotinfo_notdone ""
}
##
# @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 ::nexus::createfile {} {
global cfPath
proc ::nexus::createfile {FileName} {
variable nexusdic
variable state
variable data_gp_path
variable currFilename
if [ catch {
if {$state(file,open) == "true"} {
error_msg "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"
error "Can't create a new file because the current file is still open"
}
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]
hsetprop $data_gp_path currentfiletype [::utility::hgetplainprop $data_gp_path datatype]
if {$state(file,fileset) == true} {
foreach flabel $state(file,labels) {
dataFileName $currFilename($flabel)
nxscript $nxmode($file_format) $currFilename($flabel) $nxdict_path
}
} else {
dataFileName $currFilename(@singlefile)
nxscript $nxmode($file_format) $currFilename(@singlefile) $nxdict_path
if {$state(file,incr_datnum) == true} {
sicsdatanumber incr
}
if [catch {nxscript $create_type $FileName $nxdict_path} message] {
killfile
error $message
}
set state(file,open) false
set state(file,new) false
} message ] {
if {$::errorCode=="NONE"} {return $message}
return -code error $message
@@ -264,7 +266,7 @@ proc ::nexus::isValidFileType {type} {
# If namestyle=scratch, the save command will create scratch files.
#
# postconditions:
# state(file,open) true state(file,new) false
# state(file,open) true
# /data/currentfiletype == UNKNOWN
proc ::nexus::newfile {type {namestyle data}} {
::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.
#
# @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
proc ::nexus::newfile_collection {args} {
variable filetype_spec
@@ -287,24 +289,33 @@ proc ::nexus::newfile_collection {args} {
::utility::check_valid_options $args $valid_options
::utility::check_required_options $args $required_options
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)
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)] {
set state(file,fileset) "true"
set state(file,labels) $param(-labels)
if {$param(-savetype) == "scratch"} {
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)
sicsdatanumber incr
}
} else {
foreach fid $state(file,labels) {
set currFilename($fid) [newFileName $file_format]
set currFilename($fid) [newFileName $idNum $file_suffix]
incr idNum
lappend files $currFilename($fid)
sicsdatanumber incr
}
}
file_set_list [join $files ,]
@@ -312,11 +323,9 @@ proc ::nexus::newfile_collection {args} {
set state(file,fileset) "false"
set state(file,labels) @singlefile
if {$param(-savetype) == "scratch"} {
set currFilename(@singlefile) [format "%s/scratch.%s" [::nexus::datapath] $file_format]
sicsdatanumber incr
set currFilename(@singlefile) [format "%s/scratch.%s" [::nexus::datapath] $file_suffix]
} else {
set currFilename(@singlefile) [newFileName $file_format]
sicsdatanumber incr
set currFilename(@singlefile) [newFileName $idNum $file_suffix]
}
}
hsetprop $data_gp_path currentfiletype UNKNOWN
@@ -394,7 +403,6 @@ proc ::nexus::save {{point 0}} {
variable state
variable data_gp_path
variable start_seconds_array
variable links_and_plotinfo_notdone
variable currFilename
set valid_options [list "-index" "-label"]
@@ -413,7 +421,6 @@ proc ::nexus::save {{point 0}} {
# ::data::gumtree_save -set run_number $point
data_run_number $point
set isNewFile [expr {$state(file,new) == "true"}]
set currFileType [::utility::hgetplainprop $data_gp_path currentfiletype]
set currDataType [::utility::hgetplainprop $data_gp_path datatype]
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' "
}
#TODO User must provide a -label if we are creating a file-set
if [info exists param(-label)] {
if {[lsearch -exact $state(file,labels) $param(-label)] == -1} {
error "ERROR: The label must be one of $state(file,labels)"
@@ -433,27 +439,29 @@ proc ::nexus::save {{point 0}} {
}
set data_label @singlefile
}
if {$isNewFile || $dataTypeChanged} {
set state(file,new) true
::nexus::createfile
estart [lindex [sicstime] 1]
eend [lindex [sicstime] 1]
array unset start_seconds_array
array unset links_and_plotinfo_notdone
set start_seconds [clock seconds]
foreach flabel $state(file,labels) {
set start_seconds_array($flabel) $start_seconds
set links_and_plotinfo_notdone($flabel) "true"
}
timestamp 0
if {! [file exists $currFilename($data_label)]} {
set isNewFile true
} else {
set isNewFile false
}
if [string match -nocase "*scratch*" $currFilename($data_label)] {
set isScratchFile true
} else {
set isScratchFile false
}
if {$isNewFile || $isScratchFile} {
::nexus::createfile $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::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::makelinks
::nexus::set_plotdata_info
::nexus::nxclosefile $currFilename($data_label)
} else {
eend [lindex [sicstime] 1]
@@ -461,15 +469,10 @@ proc ::nexus::save {{point 0}} {
dataFileName $currFilename($data_label)
::nexus::nxreopenfile $currFilename($data_label)
::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)
}
} message ] {
::nexus::nxclosefile
::nexus::nxclosefile $currFilename($data_label)
if {$::errorCode=="NONE"} {return $message}
return -code error $message
}
@@ -1211,7 +1214,7 @@ foreach expt $::nexus::exports {
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.43 $}]
set tmpstr [string map {"$" ""} {$Revision: 1.44 $}]
set nx_content_revision_num [lindex $tmpstr [expr [llength $tmpstr] - 1]]
#namespace eval data {