-------------------------------------------
tcl function: writeupsampstats -- write upsamp stats
-------------------------------------------
keyboard equivalent: none

The "W" button writes currently visible
upsampled stats to the file(s) in the entry to
the left (variable=$upsampstat).  The stats may
be real or complex, and possibly 3D-smoothed.
The files are written as one (real) or two
(complex) 256x256x256 float BRIK files.

For a single-subject session, this is typically
used to save smoothed upsampled data.

For a cross-session 3D average, this can save a
file containing additional post-average
smoothing.

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

Here is the tcl code for the "W" (write) button
function, which calls the tcl-linked-C-function,
write_regupsamp_stat:

# write real or complex upsampled stats
proc writeupsampstats { } {
  global complexvalflag upstatpatt
  setfile upstatpatt [.mri.main.right.fi.val.e get]
  write_regupsamp_stat 0  ;# (0=real,1=imag,2=stat)
  if {$complexvalflag} {  ;# also write imaginary
    set infix [getstatbrikinfix $upstatpatt]
    if {$infix == "_r"} { 
      set imaginfix "_i"
    } elseif {$infix == "_x"} { 
      set imaginfix "_y"
    } else { return }
    set origupstatpatt $upstatpatt
    set stem \
      [string range $upstatpatt 0 \
        [expr [string length $upstatpatt] - 13]]
    # setfile is csurf-specific glob
    setfile upstatpatt ${stem}${imaginfix}+orig.BRIK
    write_regupsamp_stat 1
    set upstatpatt $origupstatpatt
  } 
}
