Home > vbmeg > functions > gui > project_mgr_dir > project_mgr_export_as_script.m

project_mgr_export_as_script

PURPOSE ^

Export parameter as a M-file.

SYNOPSIS ^

function project_mgr_export_as_script(proj_root, parm, parm_type)

DESCRIPTION ^

 Export parameter as a M-file.
 [USAGE]
    project_mgr_export_as_script(proj_root, parm);
 [IN]
    proj_root : project root directory.
         parm : execusion parameter.
    parm_type : parameter type(string)
                (e.g. 'brain_parm', 'head_parm')

 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 project_mgr_export_as_script(proj_root, parm, parm_type)
0002 % Export parameter as a M-file.
0003 % [USAGE]
0004 %    project_mgr_export_as_script(proj_root, parm);
0005 % [IN]
0006 %    proj_root : project root directory.
0007 %         parm : execusion parameter.
0008 %    parm_type : parameter type(string)
0009 %                (e.g. 'brain_parm', 'head_parm')
0010 %
0011 % Copyright (C) 2011, ATR All Rights Reserved.
0012 % License : New BSD License(see VBMEG_LICENSE.txt)
0013 
0014 %
0015 % --- Previous check
0016 %
0017 if ~exist('proj_root', 'var')
0018     error('proj_root is a required parameter.');
0019 end
0020 if ~exist('parm', 'var')
0021     error('parm is a required parameter.');
0022 end
0023 if ~exist('parm_type', 'var')
0024     error('parm_type is a required parameter.');
0025 end
0026 
0027 %
0028 % --- Main Procedure
0029 %
0030   
0031 % get job function name
0032 func_name = vb_judge_function_name(parm, parm_type);
0033 if strcmp(func_name, 'unknown')
0034     errordlg('Cannot export as M-file(Unknown parameter was specified).', 'error');
0035     return;
0036 end
0037 
0038 % Open save dialog
0039 [d, f] = vb_file_select({'.m'}, 'Export as M-file.', true);
0040 if isempty(d), return; end
0041 
0042 % Save as M-file
0043 mfile = fullfile(d, f{1});
0044 if exist(mfile, 'file') == 2
0045     msg = [mfile ' already exists. Do you want to overwrite it?'];
0046     res = questdlg(msg, 'Confirm', 'Yes', 'No', 'Yes');
0047     if strcmp(res, 'No'), return; end
0048 end
0049 fid = fopen(mfile, 'wt');
0050 if fid == -1
0051     error('Cannot open M-file.', 'error');
0052     return;
0053 end
0054 
0055 % Convert parm to str
0056 if isfield(parm, 'caller_function')
0057     parm = rmfield(parm, 'caller_function');
0058 end
0059 if isfield(parm, 'time_stamp')
0060     time_stamp = parm.time_stamp;
0061     parm = rmfield(parm, 'time_stamp');
0062 end
0063 parm_str = vb_struct2executable_str(parm, parm_type);
0064 
0065 % write script
0066 fprintf(fid, 'function %s\n', strrep(f{1}, '.m', ''));
0067 if exist('time_stamp', 'var')
0068     fprintf(fid, ['%% original parameter(' time_stamp, ')\n']);
0069 end
0070 fprintf(fid, '\n%% Project root directory\n');
0071 fprintf(fid, 'proj_root = ''%s'';\n\n', proj_root);
0072 fprintf(fid, '%% Parameter\n');
0073 fprintf(fid, '%s\n', parm_str);
0074 fprintf(fid, '%% Execute job function\n');
0075 fprintf(fid, '%s(proj_root, %s);\n', func_name, parm_type);
0076 
0077 fclose(fid);
0078 h = msgbox([mfile ' was created.'], 'Notice');
0079 waitfor(h);
0080 edit(mfile);

Generated on Mon 22-May-2023 06:53:56 by m2html © 2005