function SO = ts1_display
%
% batch for slice_overlay.m
%

% 8/00 Petr Janata

plot_types = { ...
      'listen_attend-rest', ...
      'group_stats', ... 
      'indiv_stats', ...
      't1_vs_t2_group', ...
      't1_vs_t2_group_contour', ...
      't1_vs_t2_indiv_contour', ...
      'attend-listen_threshsum',... 
      'music-rest_threshsum', ...
      'thin_music_vs_rest', ...
      'thin_attend_vs_listen', ...
      'thin_t1_t2_contour'}; 

plot_idx = 1;

things_to_plot = plot_types{plot_idx}

group_path = 'group'

PLOT_SOLID = 0;
ADD_SPLIT_CONTOUR = 1;
ADD_MASK_CONTOUR = 1;
contour_line_width = 2.0;

PRINT_INDIV = 0;
PRINT_TO_FILE = 1;

clear global SO
global SO

rootpath = '/data1/ts1/';

sinfo = get_ts1_sinfo;
subject_ids = cellstr(char(sinfo(:).id))
nsub = length(subject_ids);
%proc_sub = 13:17; %thin
proc_sub = 1:12; %thin

nsub = length(proc_sub)

df_indiv = 426;
df_group = nsub-1

threshold_p = 0.01		% Individual subjects
                                %  2.34 = 0.01 (d.f. = 426)
                                %  3.11 = 0.001 
				%  3.75 = 0.0001
				%  4.31 = 0.00001 (d.f. = 426)

				% Group
				%  2.72 = 0.01 (d.f. = 11)
				%  4.02 = 0.001 (d.f. = 11)
				%  5.45 = 0.0001 (d.f. = 11)
				%  7.10 = 0.00001 (d.f. = 11)
				
transform_types = {'sagittal','coronal','axial'};
transform_idx = 1;		% 1=sagittal, 2=coronal, 3=axial

slice_ranges = [-65 65; -60 -75; -30 65];

slice_skip = 5 ;

%
% Load colormaps that we might want to use
% 
%
load hot2
load hot3

newhot1 = brighten(hot,0.5);
newhot2 = brighten(hot2,0.5);
newhot3 = brighten(hot3,0.5);

switch things_to_plot
  case 'listen_attend-rest'
    nimg = 0;
			
    threshold = abs(tinv(threshold_p, df_group))
    color_range = [threshold 8];
    
    SO.transform = transform_types{transform_idx};
    SO.slices = ...
	slice_ranges(transform_idx,1):sign(diff(slice_ranges(transform_idx,:)))*slice_skip:slice_ranges(transform_idx,2);
    SO.labels.format = '%+d';
    SO.figure = spm_figure('GetWin', 'Graphics'); % use SPM figure window
    set(SO.figure,'DefaultLineLineWidth',contour_line_width)
    SO.cbar = [];
    
    % Anatomical image
    nimg = nimg+1;
    SO.img(nimg).vol = spm_vol(sprintf('%s/group/mean.img', rootpath));
    SO.img(nimg).type = 'truecolor';
    SO.img(nimg).prop = 1;
    SO.img(nimg).cmap = gray;
    nanat = nimg;

    curdir = sprintf('%s/%s/listen-rest', rootpath, group_path);
    nimg = nimg+1;
    SO.img(nimg).vol = spm_vol(sprintf('%s/%s', curdir, 'spmT_0002.img'));
    SO.img(nimg).type = 'split';
    SO.img(nimg).range = color_range;
    SO.img(nimg).prop = 1;
    SO.img(nimg).cmap = newhot2;
%    SO.cbar(end+1) = nimg;

%     if ADD_SPLIT_CONTOUR
%       nimg = nimg+1;
%       SO.img(nimg).vol = spm_vol(sprintf('%s/%s', curdir, 'spmT_0002.img'));
%       SO.img(nimg).type = 'contour';
%       SO.img(nimg).contours = ones(1,2)*threshold;
%       SO.img(nimg).linespec = 'g';
%     end

    curdir = sprintf('%s/%s/attend_t1-rest', rootpath, group_path);
    if PLOT_SOLID
      nimg = nimg+1;
      SO.img(nimg).vol = spm_vol(sprintf('%s/%s', curdir, 'spmT_0002.img'));
      SO.img(nimg).type = 'split';
      SO.img(nimg).range = color_range;
      SO.img(nimg).prop = 1;
      SO.img(nimg).cmap = newhot1;
      SO.cbar(end+1) = nimg;
    end
    
    if ADD_SPLIT_CONTOUR
      nimg = nimg+1;
      SO.img(nimg).vol = spm_vol(sprintf('%s/%s', curdir, 'spmT_0002.img'));
      SO.img(nimg).type = 'contour';
      SO.img(nimg).contours = ones(1,2)*threshold;
      SO.img(nimg).linespec = 'r';
    end

    curdir = sprintf('%s/%s/attend_t2-rest', rootpath, group_path);
    if PLOT_SOLID
      nimg = nimg+1;
      SO.img(nimg).vol = spm_vol(sprintf('%s/%s', curdir, 'spmT_0002.img'));
      SO.img(nimg).type = 'split';
      SO.img(nimg).range = color_range;
      SO.img(nimg).prop = 1;
      SO.img(nimg).cmap = newhot3;
      SO.cbar(end+1) = nimg;
    end
    
    if ADD_SPLIT_CONTOUR
      nimg = nimg+1;
      SO.img(nimg).vol = spm_vol(sprintf('%s/%s', curdir, 'spmT_0002.img'));
      SO.img(nimg).type = 'contour';
      SO.img(nimg).contours = ones(1,2)*threshold;
      SO.img(nimg).linespec = 'b';
    end

    curdir = sprintf('%s/group/music-rest', rootpath);
    if ADD_MASK_CONTOUR
      nimg = nimg+1;
      SO.img(nimg).vol = spm_vol(sprintf('%s/mask.img', curdir));
      SO.img(nimg).type = 'contour';
      SO.img(nimg).cmap = hot3;
      SO.img(nimg).contours = [0.5 0.5];
      SO.img(nimg).linespec = 'm';
    end

    slice_overlay
    
    if PRINT_TO_FILE
      set(gcf,'PaperPositionMode', 'auto')
      print('-dpsc','-painters','-noui', sprintf('%s/group/listen_attend-rest.ps',rootpath))
    end

  case 'group_stats'
    nimg = 0;
			
    threshold = abs(tinv(threshold_p, df_group))
    color_range = [threshold 8];
    
    nimg = nimg+1;
    SO.img(nimg).vol = spm_vol(sprintf('%s/group/mean.img', rootpath));
    SO.img(nimg).type = 'truecolor';
%    SO.img(nimg).vol = spm_vol(sprintf('/group/attend-listen/ResMS.img',rootpath));
%    SO.img(nimg).vol = spm_vol(sprintf('/group/attend-listen/beta_0001.img',rootpath);
    SO.img(nimg).prop = 1;
    SO.img(nimg).cmap = gray;
%    SO.img(nimg).range = [0 10];
    
    SO.cbar = [2 3];
    
    SO.transform = transform_types{transform_idx};
    SO.slices = ...
	slice_ranges(transform_idx,1):sign(diff(slice_ranges(transform_idx,:)))*slice_skip:slice_ranges(transform_idx,2);
    
    nanat = nimg;

    SO.labels.format = '%+d';
    SO.figure = spm_figure('GetWin', 'Graphics'); % use SPM figure window
    set(SO.figure,'DefaultLineLineWidth',2.0)

    % Set up things for the MUSIC VS REST contrast
    curdir = sprintf('%s/group/music-rest', rootpath);
    
    nimg = nanat+1;
    SO.img(nimg).vol = spm_vol(sprintf('%s/%s', curdir, 'spmT_0002.img'));
    SO.img(nimg).type = 'split';
    SO.img(nimg).range = color_range;
    SO.img(nimg).prop = 1;
    SO.img(nimg).cmap = newhot1;

    nimg = nimg+1;
    SO.img(nimg).vol = spm_vol(sprintf('%s/group/music-rest/%s', rootpath, 'spmT_0003.img'));
    SO.img(nimg).type = 'split';
    SO.img(nimg).range = color_range;
    SO.img(nimg).prop = 1;
    SO.img(nimg).cmap = newhot3;

    if ADD_MASK_CONTOUR
      nimg = nimg+1;
      SO.img(nimg).vol = spm_vol(sprintf('%s/mask.img', curdir));
      SO.img(nimg).type = 'contour';
      SO.img(nimg).cmap = hot3;
      SO.img(nimg).contours = [0.5 0.5];
      SO.img(nimg).linespec = 'g';
    end

    %    slice_overlay_contour  % display the slices
    slice_overlay

    if PRINT_TO_FILE
      set(gcf,'PaperPositionMode', 'auto')
      print('-dpsc','-painters','-noui', sprintf('%s/group/music_vs_rest.ps',rootpath))
    end

    pause
    
    % Set up things for the ATTEND VS LISTEN contrast
    nimg = nanat + 1;
    SO.img(nimg).vol = spm_vol(sprintf('%s/group/attend-listen/%s', rootpath, 'spmT_0002.img'));
    SO.img(nimg).type = 'split';
    SO.img(nimg).range = color_range;
    SO.img(nimg).prop = 1;
    SO.img(nimg).cmap = newhot1;

    nimg = nimg+1;
    SO.img(nimg).vol = spm_vol(sprintf('%s/group/attend-listen/%s', rootpath, 'spmT_0003.img'));
    SO.img(nimg).type = 'split';
    SO.img(nimg).range = color_range;
    SO.img(nimg).prop = 1;
    SO.img(nimg).cmap = newhot3;

    if ADD_MASK_CONTOUR
      nimg = nimg+1;
      SO.img(nimg).vol = spm_vol(sprintf('%s/mask.img', curdir));
      SO.img(nimg).type = 'split';
      SO.img(nimg).cmap = hot3;
      SO.img(nimg).range = [0.5];
      SO.img(nimg).linespec = 'g';
    end

    %    slice_overlay_contour  % display the slices
    slice_overlay

    if PRINT_TO_FILE
      set(gcf,'PaperPositionMode', 'auto')
      print('-dpsc','-painters','-noui', sprintf('%s/group/attend_vs_listen.ps',rootpath))
    end
  
  case 'thin_music_vs_rest'
    group_path = 'thin_group';
    
    nimg = 0;
			
    threshold = abs(tinv(threshold_p, df_group))
    color_range = [threshold 8];
    
    nimg = nimg+1;
    SO.img(nimg).vol = spm_vol(sprintf('%s/%s/mean.img', rootpath, group_path));
    SO.img(nimg).type = 'truecolor';
    SO.img(nimg).prop = 1;
    SO.img(nimg).cmap = gray;
    
    SO.cbar = [2 3];
    
    SO.transform = transform_types{transform_idx};
    SO.slices = ...
	slice_ranges(transform_idx,1):sign(diff(slice_ranges(transform_idx,:)))*slice_skip:slice_ranges(transform_idx,2);
    
    nanat = nimg;

    SO.labels.format = '%+0.2f';
    SO.figure = spm_figure('GetWin', 'Graphics'); % use SPM figure window
    set(SO.figure,'DefaultLineLineWidth',2.0)

    % Set up things for the MUSIC VS REST contrast
    curdir = sprintf('%s/%s/music-rest', rootpath, group_path);
    
    nimg = nanat+1;
    SO.img(nimg).vol = spm_vol(sprintf('%s/%s', curdir, 'spmT_0002.img'));
    SO.img(nimg).type = 'split';
    SO.img(nimg).range = color_range;
    SO.img(nimg).prop = 1;
    SO.img(nimg).cmap = newhot1;

    nimg = nimg+1;
    SO.img(nimg).vol = spm_vol(sprintf('%s/%s', curdir, 'spmT_0003.img'));
    SO.img(nimg).type = 'split';
    SO.img(nimg).range = color_range;
    SO.img(nimg).prop = 1;
    SO.img(nimg).cmap = newhot3;

    if ADD_MASK_CONTOUR
      nimg = nimg+1;
      SO.img(nimg).vol = spm_vol(sprintf('%s/mask.img', curdir));
      SO.img(nimg).type = 'contour';
      SO.img(nimg).cmap = hot3;
      SO.img(nimg).contours = [0.5 0.5];
      SO.img(nimg).linespec = 'g';
    end

    %    slice_overlay_contour  % display the slices
    slice_overlay

    if PRINT_TO_FILE
      set(gcf,'PaperPositionMode', 'auto')
      print('-dpsc','-painters','-noui', sprintf('%s/thin_group/music_vs_rest.ps',rootpath))
    end
    
  case 'thin_attend_vs_listen'
    group_path = 'thin_group';
    
    nimg = 0;
			
    threshold = abs(tinv(threshold_p, df_group))
    color_range = [threshold 8];
    
    nimg = nimg+1;
    SO.img(nimg).vol = spm_vol(sprintf('%s/%s/mean.img', rootpath, group_path));
    SO.img(nimg).type = 'truecolor';
    SO.img(nimg).prop = 1;
    SO.img(nimg).cmap = gray;
    
    SO.cbar = [2 3];
    
    SO.transform = transform_types{transform_idx};
    SO.slices = ...
	slice_ranges(transform_idx,1):sign(diff(slice_ranges(transform_idx,:)))*slice_skip:slice_ranges(transform_idx,2);
    
    nanat = nimg;

    SO.labels.format = '%+d';
    SO.figure = spm_figure('GetWin', 'Graphics'); % use SPM figure window
    set(SO.figure,'DefaultLineLineWidth',2.0)

    % Set up things for the MUSIC VS REST contrast
    curdir = sprintf('%s/%s/attend-listen', rootpath, group_path);
    
    nimg = nanat+1;
    SO.img(nimg).vol = spm_vol(sprintf('%s/%s', curdir, 'spmT_0002.img'));
    SO.img(nimg).type = 'split';
    SO.img(nimg).range = color_range;
    SO.img(nimg).prop = 1;
    SO.img(nimg).cmap = newhot1;

    nimg = nimg+1;
    SO.img(nimg).vol = spm_vol(sprintf('%s/%s', curdir, 'spmT_0003.img'));
    SO.img(nimg).type = 'split';
    SO.img(nimg).range = color_range;
    SO.img(nimg).prop = 1;
    SO.img(nimg).cmap = newhot3;

    if ADD_MASK_CONTOUR
      nimg = nimg+1;
      SO.img(nimg).vol = spm_vol(sprintf('%s/mask.img', curdir));
      SO.img(nimg).type = 'contour';
      SO.img(nimg).cmap = hot3;
      SO.img(nimg).contours = [0.5 0.5];
      SO.img(nimg).linespec = 'g';
    end

    %    slice_overlay_contour  % display the slices
    slice_overlay

    if PRINT_TO_FILE
      set(gcf,'PaperPositionMode', 'auto')
      print('-dpsc','-painters','-noui', sprintf('%s/thin_group/attend_vs_listen.ps',rootpath))
    end
    
    
  case 'indiv_stats'
    for isub = proc_sub
      curdir = fullfile(rootpath, subject_ids{isub},'normalized');
      fname = sprintf('%s/spmT_0009.img', curdir)

      threshold = abs(tinv(threshold_p, df_indiv))

      nimg = 0;
      
        nimg = nimg+1;
        SO.img(nimg).vol = spm_vol('/usr/local/matlab/toolbox/local/spm99/canonical/avg152T1.img');
        SO.img(nimg).prop = 0.0;
        SO.img(nimg).cmap = gray;

      nimg = nimg+1;
      SO.img(nimg).vol = spm_vol(fname);
      SO.img(nimg).cmap = hot;
      SO.img(nimg).range = [threshold threshold+0.001];
      
      SO.transform = transform_types{transform_idx};
      SO.slices = ...
	  slice_ranges(transform_idx,1):sign(diff(slice_ranges(transform_idx,:)))*slice_skip:slice_ranges(transform_idx,2);
      SO.labels = [];

      SO.figure = spm_figure('GetWin', 'Graphics'); % use SPM figure window

      slice_overlay

      if PRINT_INDIV
	set(gcf,'PaperPositionMode', 'auto')
	print('-dpsc','-painters','-noui', sprintf('%s/%s_attend.ps',rootpath,subject_ids{isub}))
%	print('-dpsc','-painters','-noui','-append', sprintf('%s/allindiv_attend.ps',rootpath))
      end
	
    end
    
  case 't1_vs_t2_group'
    nimg = 0;

    threshold = abs(tinv(threshold_p, df_group))
    color_range = [threshold 8];
    
    nimg = nimg+1;
    SO.img(nimg).vol = spm_vol(sprintf('%s/group/mean.img', rootpath));
    SO.img(nimg).prop = 0.2;
    SO.img(nimg).cmap = gray;
%    SO.img(nimg).range = [0 10];
    
    SO.cbar = [2 3];
    
    SO.transform = transform_types{transform_idx};
    SO.slices = ...
	slice_ranges(transform_idx,1):sign(diff(slice_ranges(transform_idx,:)))*slice_skip:slice_ranges(transform_idx,2);
    
    nanat = nimg;

    SO.labels.format = '%+d';
    SO.figure = spm_figure('GetWin', 'Graphics'); % use SPM figure window

    % Set up things for the TIMBRE 1 (vibes)  vs TIMBRE 2 (strings) overlay
    nimg = nanat+1;
    SO.img(nimg).vol = spm_vol(sprintf('%s/group/t1-listen/%s', rootpath, 'spmT_0002.img'));
    SO.img(nimg).range = color_range;
    SO.img(nimg).prop = 0.4;
    SO.img(nimg).cmap = newhot1;

    nimg = nimg+1;
    SO.img(nimg).vol = spm_vol(sprintf('%s/group/t2-listen/%s', rootpath, 'spmT_0002.img'));
    SO.img(nimg).range = color_range;
    SO.img(nimg).prop = 0.4;
    SO.img(nimg).cmap = newhot3;

    slice_overlay  % display the slices
    print('-dpsc','-painters','-noui', sprintf('%s/group/t1_vs_t2_group.ps',rootpath))
  
  case 't1_vs_t2_group_contour'
    nimg = 0;
    threshold = abs(tinv(threshold_p, df_group))
    color_range = [threshold 8];
    
    nimg = nimg+1;
    SO.img(nimg).vol = spm_vol(sprintf('%s/group/mean.img', rootpath));
    SO.img(nimg).type = 'truecolor';
    SO.img(nimg).prop = 1;
    SO.img(nimg).cmap = gray;
%    SO.img(nimg).range = [0 10];
    
    SO.transform = transform_types{transform_idx};
    SO.slices = ...
	slice_ranges(transform_idx,1):sign(diff(slice_ranges(transform_idx,:)))*slice_skip:slice_ranges(transform_idx,2);
    
    nanat = nimg;

    SO.labels.format = '%+d';
    SO.figure = spm_figure('GetWin', 'Graphics'); % use SPM figure window
    set(SO.figure,'DefaultLineLineWidth',2.0)
    
    % Set up things for the TIMBRE 1 (vibes)  vs TIMBRE 2 (strings) overlay
    nimg = nanat+1;
    SO.img(nimg).vol = spm_vol(sprintf('%s/group/t1-listen/%s', rootpath, 'spmT_0002.img'));
    SO.img(nimg).type = 'contour';
    SO.img(nimg).contours = [threshold threshold];
    SO.img(nimg).prop = 0.4;
    SO.img(nimg).cmap = newhot1;
    SO.img(nimg).linespec = 'r';
    
    nimg = nimg+1;
    SO.img(nimg).vol = spm_vol(sprintf('%s/group/t2-listen/%s', rootpath, 'spmT_0002.img'));
    SO.img(nimg).type = 'contour';
    SO.img(nimg).contours = [threshold threshold];
    SO.img(nimg).prop = 0.4;
    SO.img(nimg).cmap = newhot3;
    SO.img(nimg).linespec = 'c';

    if ADD_MASK_CONTOUR
      nimg = nimg+1;
      SO.img(nimg).vol = spm_vol(sprintf('%s/group/t1-listen/mask.img', rootpath));
      SO.img(nimg).type = 'contour';
      SO.img(nimg).cmap = hot3;
      SO.img(nimg).contours = [0.5 0.5];
      SO.img(nimg).linespec = 'g';
    end

    %slice_overlay_contour  % display the slices
    slice_overlay
    
    if PRINT_TO_FILE
      set(gcf,'PaperPositionMode', 'auto')
      print('-dpsc','-painters','-noui', sprintf('%s/group/t1_vs_t2_contour.ps',rootpath))
    end
  
  case 'thin_t1_t2_contour'
    group_path = 'thin_group';
    
    nimg = 0;
    threshold = abs(tinv(threshold_p, df_group))
    color_range = [threshold 8];
    
    nimg = nimg+1;
    SO.img(nimg).vol = spm_vol(sprintf('%s/%s/mean.img', rootpath, group_path));
    SO.img(nimg).type = 'truecolor';
    SO.img(nimg).prop = 1;
    SO.img(nimg).cmap = gray;
    
    SO.transform = transform_types{transform_idx};
    SO.slices = ...
	slice_ranges(transform_idx,1):sign(diff(slice_ranges(transform_idx,:)))*slice_skip:slice_ranges(transform_idx,2);
    
    nanat = nimg;

    SO.labels.format = '%+d';
    SO.figure = spm_figure('GetWin', 'Graphics'); % use SPM figure window
    set(SO.figure,'DefaultLineLineWidth',2.0)

    curdir = sprintf('%s/%s/t1-listen/', rootpath, group_path);
    
    % Set up things for the TIMBRE 1 (vibes)  vs TIMBRE 2 (strings) overlay
    nimg = nanat+1;
    SO.img(nimg).vol = spm_vol(sprintf('%s/%s', curdir, 'spmT_0002.img'));
    SO.img(nimg).type = 'contour';
    SO.img(nimg).contours = [threshold threshold];
    SO.img(nimg).prop = 0.4;
    SO.img(nimg).cmap = newhot1;
    SO.img(nimg).linespec = 'r';
    
    curdir = sprintf('%s/%s/t2-listen/', rootpath, group_path);
    nimg = nimg+1;
    SO.img(nimg).vol = spm_vol(sprintf('%s/%s', curdir, 'spmT_0002.img'));
    SO.img(nimg).type = 'contour';
    SO.img(nimg).contours = [threshold threshold];
    SO.img(nimg).prop = 0.4;
    SO.img(nimg).cmap = newhot3;
    SO.img(nimg).linespec = 'c';

    if ADD_MASK_CONTOUR
      nimg = nimg+1;
      SO.img(nimg).vol = spm_vol(sprintf('%s/mask.img', curdir));
      SO.img(nimg).type = 'contour';
      SO.img(nimg).cmap = hot3;
      SO.img(nimg).contours = [0.5 0.5];
      SO.img(nimg).linespec = 'g';
    end

    %slice_overlay_contour  % display the slices
    slice_overlay
    
    if PRINT_TO_FILE
      set(gcf,'PaperPositionMode', 'auto')
      print('-dpsc','-painters','-noui', sprintf('%s/group/t1_vs_t2_contour.ps',rootpath))
    end
      
  case 't1_vs_t2_indiv_contour'
    threshold = abs(tinv(threshold_p, df_indiv))
    for isub = proc_sub
      
      disp(sprintf('Working on subject: %s', subject_ids{isub}))
      
      curdir = fullfile(rootpath, subject_ids{isub},'normalized');

      hires_dir = fullfile(rootpath, subject_ids{isub},'hires');

      eval(['ls ' hires_dir '/n*.img;']); hires_img = ans(1:end-1);

      fname{1} = hires_img;
      fname{2} = sprintf('%s/spmT_0014.img', curdir);
      fname{3} = sprintf('%s/spmT_0015.img', curdir);

      nimg = 0;

      SO.contours = [2 3 4];
      SO.transform = transform_types{transform_idx};
      SO.slices = ...
	  slice_ranges(transform_idx,1):sign(diff(slice_ranges(transform_idx,:)))*slice_skip:slice_ranges(transform_idx,2);
      SO.labels.format = '%+d';
    
      nimg = nimg+1;
      SO.img(nimg).vol = spm_vol(fname{1});
      SO.img(nimg).prop = 1;
      SO.img(nimg).cmap = gray;

      nimg = nimg+1;
      SO.img(nimg).vol = spm_vol(fname{2});
      SO.img(nimg).cmap = hot;
      SO.img(nimg).range = [threshold];
      SO.img(nimg).linestr = 'r';
      
      nimg = nimg+1;
      SO.img(nimg).vol = spm_vol(fname{3});
      SO.img(nimg).cmap = hot3;
      SO.img(nimg).range = [threshold];
      SO.img(nimg).linestr = 'c';

      if ADD_MASK_CONTOUR
	nimg = nimg+1;
	SO.img(nimg).vol = spm_vol(sprintf('%s/mask.img', curdir));
	SO.img(nimg).cmap = hot3;
	SO.img(nimg).range = [0.5];
	SO.img(nimg).linestr = 'g';
	
      end
      
      SO.figure = spm_figure('GetWin', 'Graphics'); % use SPM figure window

      slice_overlay_contour

      if PRINT_INDIV
	set(gcf,'PaperPositionMode', 'auto')
	print('-dpsc','-painters','-noui', sprintf('%s/%s_timbre_contour.ps',rootpath,subject_ids{isub}))
%	print('-dpsc','-painters','-noui','-append', sprintf('%s/allindiv_attend.ps',rootpath))
      end
    end
  case 'attend-listen_threshsum'
    nimg = 0;
    threshold = abs(tinv(threshold_p, df_group))
    color_range = [threshold 8];
    
    nimg = nimg+1;
    SO.img(nimg).vol = spm_vol(sprintf('%s/group/mean.img', rootpath));
    SO.img(nimg).prop = 1;
    SO.img(nimg).cmap = gray;
%    SO.img(nimg).range = [0 10];
    
    SO.contours = [2];
    SO.cbar = 3;
    
    SO.transform = transform_types{transform_idx};
    SO.slices = ...
	slice_ranges(transform_idx,1):sign(diff(slice_ranges(transform_idx,:)))*slice_skip:slice_ranges(transform_idx,2);
    
    SO.labels.format = '%+d';
    SO.figure = spm_figure('GetWin', 'Graphics'); % use SPM figure window
    set(SO.figure,'DefaultLineLineWidth',2.0)

    nanat = nimg;
    
    curdir = sprintf('%s/group/attend-listen/%s', rootpath);
    
    % Set up things ATTEND - LISTEN
    nimg = nanat+1;
    SO.img(nimg).vol = spm_vol(sprintf('%s/group/attend-listen/%s', rootpath, 'spmT_0002.img'));
    SO.img(nimg).range = color_range;
    SO.img(nimg).prop = 0.4;
    SO.img(nimg).cmap = newhot1;
    SO.img(nimg).linestr = 'c';

    nimg = nimg+1;
    SO.img(nimg).vol = spm_vol(sprintf('%s/group/%s', rootpath, 'sumthresh_spmT_0013.img'));
    SO.img(nimg).range = [2 nsub];
    SO.img(nimg).prop = inf;
    SO.img(nimg).cmap = newhot1;
    SO.img(nimg).hold = 0;

    if ADD_MASK_CONTOUR
      nimg = nimg+1;
      SO.img(nimg).vol = spm_vol(sprintf('%s/mask.img', curdir));
      SO.img(nimg).cmap = hot3;
      SO.img(nimg).range = [0.5];
      SO.img(nimg).linestr = 'm';
      SO.contours(end+1) = nimg;	
    end

    slice_overlay_contour
    set(gcf,'PaperPositionMode', 'auto')
    print('-dpsc','-painters','-noui', sprintf('%s/group/attend_threshsum.ps',rootpath))
    
  case 'music-rest_threshsum'
    nimg = 0;
    threshold = abs(tinv(threshold_p, df_group))
    color_range = [threshold 8];
    
    nimg = nimg+1;
    SO.img(nimg).vol = spm_vol(sprintf('%s/group/mean.img', rootpath));
    SO.img(nimg).prop = 1;
    SO.img(nimg).cmap = gray;
%    SO.img(nimg).range = [0 10];
    
    SO.contours = [2];
    SO.cbar = 3;
    
    SO.transform = transform_types{transform_idx};
    SO.slices = ...
	slice_ranges(transform_idx,1):sign(diff(slice_ranges(transform_idx,:)))*slice_skip:slice_ranges(transform_idx,2);
    
    SO.labels.format = '%+d';
    SO.figure = spm_figure('GetWin', 'Graphics'); % use SPM figure window
    set(SO.figure,'DefaultLineLineWidth',2.0)

    nanat = nimg;

    curdir = sprintf('%s/group/music-rest/%s', rootpath);
    
    % Set up things MUSIC-REST
    nimg = nanat+1;
    SO.img(nimg).vol = spm_vol(sprintf('%s/group/music-rest/%s', rootpath, 'spmT_0002.img'));
    SO.img(nimg).range = color_range;
    SO.img(nimg).prop = 0.4;
    SO.img(nimg).cmap = newhot1;
    SO.img(nimg).linestr = 'c';

    nimg = nimg+1;
    SO.img(nimg).vol = spm_vol(sprintf('%s/group/%s', rootpath, 'sumthresh_spmT_0012.img'));
    SO.img(nimg).range = [2 nsub];
    SO.img(nimg).prop = inf;
    SO.img(nimg).cmap = newhot1;
    SO.img(nimg).hold = 0;

    if ADD_MASK_CONTOUR
      nimg = nimg+1;
      SO.img(nimg).vol = spm_vol(sprintf('%s/mask.img', curdir));
      SO.img(nimg).cmap = hot3;
      SO.img(nimg).range = [0.5];
      SO.img(nimg).linestr = 'm';
      SO.contours(end+1) = nimg;	
    end

    slice_overlay_contour
    set(gcf,'PaperPositionMode', 'auto')
    print('-dpsc','-painters','-noui', sprintf('%s/group/music_threshsum.ps',rootpath))

end


if PRINT_TO_FILE
  set(gcf,'PaperPositionMode', 'auto')
  
  switch things_to_plot
    otherwise
      print -dpsc -painters -noui ts1_fig.ps
  end
end