#! /bin/sh
# (next line not see by tcl) \
exec tclsh $0 ${1+"$@"}

#
# printdat
#
# CVS Revision Info:
#    $Author: nicks $
#    $Date: 2007/01/06 00:01:14 $
#    $Revision: 1.2 $
#
# Copyright (C) 2002-2007,
# The General Hospital Corporation (Boston, MA).
# All rights reserved.
#
# Distribution, usage and copying of this software is covered under the
# terms found in the License Agreement file named 'COPYING' found in the
# FreeSurfer source code root directory, and duplicated here:
# https://surfer.nmr.mgh.harvard.edu/fswiki/FreeSurferOpenSourceLicense
#
# General inquiries: freesurfer@nmr.mgh.harvard.edu
# Bug reports: analysis-bugs@nmr.mgh.harvard.edu
#

if {$argc != 1} {
  puts "use: printdat <session/subject/\"local\">"
  return
}

set datfile csurf.dat
set name [lindex $argv 0]
if {$name != "local"} {
  set spatt1 \[0-9\]\[0-9\]\[0-9\]\[0-9\]\[0-9\]\[0-9\]\[A-Z\]\[A-Z\]
  set spatt2 \[0-9\]\[0-9\]\[0-9\]\[0-9\]\[0-9\]\[0-9\]\[A-Z\]\[A-Z\]\[A-Z\]
  set spatt3 \[A-Z\]*\[0-9\]\[0-9\]\[0-9\]
  if { [string match $spatt1 $name] || [string match $spatt2 $name] ||
       [string match $spatt3 $name] } {
    set datfile \
      [glob -nocomplain $env(FUNCTIONALS_DIR)/$name/?????/scripts/$datfile]
  } else {
    set datfile $env(SUBJECTS_DIR)/$name/scripts/$datfile
  }
}
if ![file exists $datfile] { puts "printdat: ### $datfile not found";return }

set arraynamelist { \
  convparms stripskullparms normalizeparms wmfilterparms wmfillparms \
  inflateparms flattenparms sphereparms structscanlists postclparms \
  sessionscanlists alignscanparms functscanlists renderscanlists \
  functscanparms }

set id [open $datfile r]
set i -1
set currarray none
set foundprev 0
foreach line [split [read $id] \n] {
  incr i
  if {$i == 0} { continue }
  if {$foundprev} {
    array set $currarray $line
    puts "\n#####################################################"
    puts   "$currarray"
    puts   "#####################################################"
    foreach index [lsort [array names $currarray]] {
      puts "  $index = [set ${currarray}($index)]"
    }
    set currarray none
    set foundprev 0
    continue
  }
  foreach arrayname $arraynamelist {
    if {$line == "csurf arrayname: $arrayname"} {
      set currarray $arrayname
      set foundprev 1
      break
    }
  }
}
close $id
puts "\n(from $datfile)\n"







