# This script was written to process fMRI data containing a 
# number of time points all stored in one raw file.
# The script will create a new folder and load each time
# point as a separate volume. This may take several minutes.
# After each volume is opened, the display range will be set.
# Finally, a group page will be created containing all of 
# these volumes (time points)
# The paradigm file should then be applied to this group page.
# This script was developed by Jeff Solomon on 8/06/97 
#
# Edited by Raj 09/23/99
# to incorporate voxel dimensions in images opened
# to check if a folder is already open and if so open these images 
# in that folder

set PXHOME $env(PXHOME)
set auto_path [linsert $auto_path 0 $PXHOME/tcl]

global DIR
 
# Set DIR to the directory where the images are located
set DIR "/net/fafner/home2/Data/"
InputFromWidget "Image Directory" 1 "Image Directory:" DIR 40

# Create new folder and load the raw image.

set result [MxGetCurrentFolder F]

if $result {
    MxNewFolder F W
  }

set result [catch {glob $DIR/2dseq} file]
 
 if {$result == 1} {
	 ScriptUpdate "There were no images of the correct format in \
		 this directory"
	 return
 }

# Prompt user for raw image parameters
InputFromWidget "Image Parameters" 9 "Image width:" width 5 \
"Image height:" height 5 "Number of slices/time point:" slices_time 5 \
"Number of time points:" time_points 5 "X size:" x 5 "Y size:" y 5 \
"Z size " z 5 "Bits/pixel:" bits 5 "Encoding (UI, SI, R):" encod 5

set offset 0
for {set i 0} {$i < $time_points} {incr i 1} {
	set offset [expr $i*$width*$height*$slices_time*$bits/8]
	MxOpenRawImage $F "{Offset $offset} {Width $width} {Height $height} \
   	{Slices $slices_time} {Bits $bits} {Encoding $encod}" $file Volume($i) 
	MxSetScale $Volume($i) $x $y $z
	MxComputeDisplayRange $Volume($i) min max
}

# Create a list of these volumes so that we can form a group page
for {set i 0} {$i < $time_points} {incr i 1} {
	lappend volumes $Volume($i)
}

MxGroupVolumes $volumes "Group of Time Points" group













