-------------------------------------------
tcl function: readnativestats -- read native stats
-------------------------------------------
keyboard equivalent: none

The "R" button reads native resolution stats
(specified by options: -statnslices, -statyres,
and -statxres) from the entry to the left (tcl
filename variable=$statpatt), registers them to
the struct volume using the matrix specified by
option -regdat (typically register.dat in current
$scandir), and then upsamples them to the
current struct resolution (1mm^3/256^3 or
0.5mm^3/512^3) for display and smoothing.

The stats may be real or complex.  The files are
read as one (real) or two (complex) bfloat file
sets, or one (real) or two (complex) float BRIK
files.

This is the procedure performed by the View
Functional Data -> VOLUME-STATS button.

If the file in the entry contains an infix
indicating the data is complex (_r or _x), and if
"cpx" is ticked, the companion file for the
imaginary component (_i or _y) will also be read
automatically.

Here is the tcl code for the "R" (read) button
function, which calls the tcl-linked-C-function,
read_native_stat to (re-)read native stats, and
do_regupsamp_stat to upsample them:

# read real or complex native stats
proc readnativestats { } {
  global complexvalflag statpatt
  setfile statpatt [.mri.main.right.fi.valn.cbx subwidget entry get]
  read_native_stat 0   ;# (0=real,1=imag,2=stat)
  if {$complexvalflag} {
    if [string match *_%03d.bfloat $statpatt] {
      set infix [getstatbfloatinfix $statpatt]
    }
    if [string match *+orig.BRIK $statpatt] {
      set infix [getstatbrikinfix $statpatt]
    }
    if {$infix == "_r"} {
      set imaginfix "_i"
    } elseif {$infix == "_x"} {
      set imaginfix "_y"
    } else { return }
    set origstatpatt $statpatt
    if [string match *_%03d.bfloat $statpatt] {
      set stem [string range $statpatt 0 \
        [expr [string length $statpatt] - 15]]
      setfile statpatt ${stem}${imaginfix}_%03d.bfloat
    }
    if [string match *+orig.BRIK $statpatt] {
      set stem [string range $statpatt 0 \
        [expr [string length $statpatt] - 13]]
      setfile statpatt ${stem}${imaginfix}+orig.BRIK
    }
    read_native_stat 1
    set statpatt $origstatpatt
  }
  do_regupsamp_stat
}
