0001 function err = job_view_cortex_file( action, target, filepath )
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014 data = get( getfield( H, [ target 'data' ] ), 'UserData' );
0015
0016
0017 switch action
0018
0019
0020
0021
0022 case 'load'
0023
0024
0025 H.file_dialog.save_mode = 0;
0026 H.file_dialog.file_extensions = { [ '.' target '.mat' ] };
0027 [ pname, fname ] = visible( H.file_dialog );
0028 if length(pname) == 0; err = 1; return; end;
0029 filepath = fullfile( pname, fname{1} );
0030 elseif exist( filepath ) ~= 2
0031 errordlg( [ '''' filepath ''' doesn''t exist' ] );
0032 err = 1; return;
0033 end
0034
0035
0036 if strcmp( data.filename, filepath )
0037 switch target
0038
0039 err = 1; return;
0040
0041 reloadp = questdlg( [ 'Are you sure to reload area file '''...
0042 filepath ''' ?' ] );
0043 if ~strcmp( reloadp, 'Yes' )
0044 err = 1; return;
0045 end
0046 end
0047 end
0048
0049
0050
0051
0052 varnames.brain = { 'F', 'V', ...
0053 'nextIX', 'nextDD', 'xxA' };
0054 varnames.act = { 'Act' };
0055 varnames.area = { 'MRI_ID', 'Area' };
0056 vnames = getfield( varnames, target );
0057 vnames_exist = whos( '-file', filepath, vnames{:} );
0058 if length( vnames ) ~= length( vnames_exist )
0059 errordlg( [ '''' filepath ''' is invalid ' target ' file' ] );
0060 err = 1; return;
0061 end
0062 Area = [];
0063 load( filepath, vnames{:} );
0064
0065
0066
0067 switch target
0068 case 'brain'
0069 data.F = F;
0070 data.V = V;
0071 for i = 1 : length(V)
0072 data.nextVi{i} = nextIX{i}';
0073 data.nextVd{i} = nextDD{i}';
0074 end
0075 data.Va = xxA';
0076 vinf_exist = whos( '-file', filepath, 'Vinflate', 'inf_C');
0077 if length(vinf_exist) >= 1
0078 load( filepath, 'Vinflate', 'inf_C');
0079 if exist('Vinflate')
0080 data.Vinflate = Vinflate;
0081 if exist('inf_C')
0082 data.S = inf_C';
0083 end
0084 end
0085 else
0086
0087 param.model_type = 'original';
0088 set( H.paramdata, 'UserData', param );
0089 end
0090 set(H.fig, 'Name', filepath);
0091
0092 case 'act'
0093 data.source = [];
0094 for i = 1:length(Act)
0095 data.source(i).key = Act{i}.key;
0096 data.source(i).J = Act{i}.xxP';
0097 if isfield( Act{i}, 'comment' )
0098 data.source(i).comment = Act{i}.comment;
0099 end
0100 end
0101 data.candidate = 1 : length( data.source );
0102 data.plotted = [];
0103 case 'area'
0104 data.MRI_ID = MRI_ID;
0105 data.source = [];
0106 for i = 1:length(Area)
0107 data.source(i).key = Area{i}.key;
0108 data.source(i).Vi = Area{i}.Iextract';
0109 if isfield(Area{i}, 'clr')
0110 data.source(i).color = Area{i}.clr;
0111 end
0112 end
0113 data.candidate = 1 : length( data.source );
0114 data.plotted = [];
0115 data.masking = [];
0116 end
0117 data.filename = filepath;
0118 H.file_dialog.current_dir = fileparts( filepath );
0119
0120
0121
0122
0123
0124 case 'save'
0125
0126
0127 H.file_dialog.save_mode = 1;
0128 H.file_dialog.file_extensions = { [ '.' target '.mat' ] };
0129 [ pname, fname ] = visible( H.file_dialog );
0130 if length(pname) == 0; err = 1; return; end;
0131 filepath = fullfile( pname, fname{1} );
0132 end
0133
0134
0135 case 'area'
0136 count = 0;
0137 for i = data.candidate
0138 count = count + 1;
0139 Area{count}.key = data.source(i).key;
0140 Area{count}.Iextract = data.source(i).Vi';
0141 end
0142 Area = Area';
0143 MRI_ID = data.MRI_ID;
0144 vb_fsave( filepath, 'Area', 'MRI_ID' );
0145 data.filename = filepath;
0146 H.file_dialog.current_dir = fileparts( filepath );
0147 end
0148
0149 end
0150
0151
0152
0153 set( getfield( H, [ target, 'data' ] ), 'UserData', data );
0154 set( gcf, 'UserData', H );
0155
0156 err = 0;