Home > functions > job > job_view_cortex_dir > job_view_cortex_file.m

job_view_cortex_file

PURPOSE ^

err = job_view_cortex_file( action, target, filepath )

SYNOPSIS ^

function err = job_view_cortex_file( action, target, filepath )

DESCRIPTION ^

 err = job_view_cortex_file( action, target, filepath )

  各種ファイルを読み込み、データを格納する
  またはデータをファイルに書き出す

 action : 'load' or 'save'
 target : 'brain', 'act', or 'area
 filepath : ファイルのパス (空でもよい)


 Copyright (C) 2011, ATR All Rights Reserved.
 License : New BSD License(see VBMEG_LICENSE.txt)

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function err = job_view_cortex_file( action, target, filepath )
0002 % err = job_view_cortex_file( action, target, filepath )
0003 %
0004 %  各種ファイルを読み込み、データを格納する
0005 %  またはデータをファイルに書き出す
0006 %
0007 % action : 'load' or 'save'
0008 % target : 'brain', 'act', or 'area
0009 % filepath : ファイルのパス (空でもよい)
0010 %
0011 %
0012 % Copyright (C) 2011, ATR All Rights Reserved.
0013 % License : New BSD License(see VBMEG_LICENSE.txt)
0014 
0015 % 必要なデータの取得
0016 H = get( gcf, 'UserData' );
0017 data = get( getfield( H, [ target 'data' ] ), 'UserData' );
0018 
0019 
0020 switch action
0021 
0022  %==================================================================
0023  %===  ファイルのロード  ===========================================
0024  %==================================================================
0025  case 'load'
0026     
0027   % ファイルが指定されていなければ、GUIを開いて取得
0028   if isempty( filepath )
0029     H.file_dialog.save_mode = 0;
0030     H.file_dialog.file_extensions = { [ '.' target '.mat' ] };
0031     [ pname, fname ] = visible( H.file_dialog );
0032     if length(pname) == 0; err = 1; return; end;
0033     filepath = fullfile( pname, fname{1} );
0034   elseif exist( filepath ) ~= 2
0035     errordlg( [ '''' filepath ''' doesn''t exist' ] );
0036     err = 1; return;
0037   end
0038   
0039   % 既にロード済みのファイルならば...
0040   if strcmp( data.filename, filepath )
0041     switch target
0042      % brain, act の場合はロードしない
0043      case { 'brain', 'act' }
0044       err = 1; return;
0045      % area の場合は再ロードするかどうかを聞く
0046      case 'area'
0047       reloadp = questdlg( [ 'Are you sure to reload area file '''...
0048                     filepath ''' ?' ] );
0049       if ~strcmp( reloadp, 'Yes' ) 
0050     err = 1; return;
0051       end
0052     end
0053   end
0054 
0055   % ファイルのチェック --- ファイル内に必要な変数が存在するか?
0056 %  varnames.brain = { 'F', 'V', 'Vinflate', 'inf_C',...
0057 %             'nextIX', 'nextDD', 'xxA' };
0058   varnames.brain = { 'F', 'V', ...
0059              'nextIX', 'nextDD', 'xxA' };
0060   varnames.act = { 'Act' };
0061   varnames.area = { 'MRI_ID', 'Area' };
0062   vnames = getfield( varnames, target );
0063   vnames_exist = whos( '-file', filepath, vnames{:} );
0064   if length( vnames ) ~= length( vnames_exist )
0065     errordlg( [ '''' filepath ''' is invalid ' target ' file' ] );
0066     err = 1; return;
0067   end
0068   Area = []; % 関数名とバッティングするので初期化しておく
0069   % 変数のロード
0070   load( filepath, vnames{:} );
0071 
0072   % 変数のチェック ????? --- 正しい形式の変数かどうか...面倒だ。後回し
0073 
0074   % 登録 ( ファイル内のデータ構造が使い辛いので、少し変換 )
0075   switch target
0076    case 'brain'
0077     data.F = F;
0078     data.V = V;
0079     for i = 1 : length(V)
0080       data.nextVi{i} = nextIX{i}';
0081       data.nextVd{i} = nextDD{i}';
0082     end
0083     data.Va = xxA';
0084     vinf_exist = whos( '-file', filepath, 'Vinflate', 'inf_C');
0085     if length(vinf_exist) >= 1
0086       load( filepath, 'Vinflate', 'inf_C');
0087       if exist('Vinflate')
0088         data.Vinflate = Vinflate;
0089         if exist('inf_C')
0090             data.S = inf_C';
0091         end
0092       end
0093     else
0094       % インフレート情報がない場合、表示設定はoriginalにする
0095       param = get( H.paramdata, 'UserData' );
0096       param.model_type = 'original';
0097       set( H.paramdata, 'UserData', param );
0098     end
0099 
0100    case 'act'
0101     data.source = [];
0102     for i = 1:length(Act)
0103       data.source(i).key = Act{i}.key;
0104       data.source(i).J = Act{i}.xxP';
0105       if isfield( Act{i}, 'comment' )
0106     data.source(i).comment = Act{i}.comment;
0107       end
0108     end
0109     data.candidate = 1 : length( data.source );
0110     data.plotted = [];
0111    case 'area'
0112     data.MRI_ID = MRI_ID;
0113     data.source = [];
0114     for i = 1:length(Area)
0115       data.source(i).key = Area{i}.key;
0116       data.source(i).Vi = Area{i}.Iextract';
0117     end
0118     data.candidate = 1 : length( data.source );
0119     data.plotted = [];
0120     data.masking = [];
0121   end
0122   data.filename = filepath;
0123   H.file_dialog.current_dir = fileparts( filepath );
0124 
0125 
0126  %==================================================================
0127  %===  ファイルのセーブ  ===========================================
0128  %==================================================================
0129  case 'save'
0130   
0131   % ファイル名が指定されていなければ、GUIを開いて取得
0132   if isempty( filepath )
0133     H.file_dialog.save_mode = 1;
0134     H.file_dialog.file_extensions = { [ '.' target '.mat' ] };
0135     [ pname, fname ] = visible( H.file_dialog );
0136     if length(pname) == 0; err = 1; return; end;
0137     filepath = fullfile( pname, fname{1} );
0138   end
0139   
0140   % フォーマットを調整して出力
0141   switch target
0142    case 'area'
0143     count = 0;
0144     for i = data.candidate
0145       count = count + 1;
0146       Area{count}.key = data.source(i).key;
0147       Area{count}.Iextract = data.source(i).Vi';
0148     end
0149     Area = Area';
0150     MRI_ID = data.MRI_ID;
0151     vb_fsave( filepath, 'Area', 'MRI_ID' );
0152     data.filename = filepath;
0153     H.file_dialog.current_dir = fileparts( filepath );
0154   end
0155 
0156 end
0157 
0158 
0159 % データの格納
0160 set( getfield( H, [ target, 'data' ] ), 'UserData', data );
0161 set( gcf, 'UserData', H );
0162 
0163 err = 0;

Generated on Tue 27-Aug-2013 11:46:04 by m2html © 2005