Home > vbmeg > functions > tool_box > dmri_processor > functions > util > dmri_system.m

dmri_system

PURPOSE ^

This command creates bash script file and execute.

SYNOPSIS ^

function [status, result] = dmri_system(command, arg2)

DESCRIPTION ^

 This command creates bash script file and execute.
 Use this script instead of system().
  e.g. 

 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 [status, result] = dmri_system(command, arg2)
0002 % This command creates bash script file and execute.
0003 % Use this script instead of system().
0004 %  e.g.
0005 %
0006 % Copyright (C) 2011, ATR All Rights Reserved.
0007 % License : New BSD License(see VBMEG_LICENSE.txt)
0008 
0009 %
0010 % --- Previous check
0011 %
0012 if ~(nargin == 1 || nargin == 2)
0013     error('Please check function usage.');
0014 end
0015 
0016 %
0017 % --- Main Procedure
0018 %
0019 dmri_setenv;
0020 
0021 % Create base script including environment setup
0022 sh_file = [tempname, '.sh'];
0023 isok = dmri_script_file_create(sh_file);
0024 if isok == false
0025     error('Failed to create temporary shellscript file: %s', sh_file);
0026 end
0027 
0028 % before command chech
0029 % * Special(fslview is obsolete and renamed. but is very useful).
0030 if strfind(command, 'fslview ')
0031     [s, r] = dmri_system('which fslview_deprecated');
0032     if s == 0 && ~isempty(r)
0033         command = strrep(command, 'fslview ', 'fslview_deprecated ');
0034     end
0035 end
0036 
0037 % Put command to the bottom of the file.
0038 fid = fopen(sh_file, 'a');
0039 if fid == -1
0040     error('Failed to open temporaryh shell script file: %s', sh_file);
0041 end
0042 fprintf(fid, '%s\n', command);
0043 fclose(fid);
0044 
0045 % Execute
0046 if exist('arg2', 'var')
0047     [status, result] = system(sh_file, arg2);
0048 else
0049     [status, result] = system(sh_file);
0050 end
0051 if status ~= 0 && ~isempty(result)
0052     ix = strfind(result, ':');
0053     result2 = result(ix(end-1):end);
0054     disp(['dmri_system(''', command ''');']);
0055     warning('dmri_system: Failed to execute command.\n reason: %s', result2);
0056 end

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