Home > vbmeg > functions > common > utility > vb_matfile_to_v6.m

vb_matfile_to_v6

PURPOSE ^

convert MATLAB7 or later format file into MATLAB6 format file.

SYNOPSIS ^

function vb_matfile_to_v6(inputfile, output_v6, output_org)

DESCRIPTION ^

 convert MATLAB7 or later format file into MATLAB6 format file. 
 USAGE:
    vb_matfile_to_v6(inputfile);
    vb_matfile_to_v6(inputfile, output_v6);
    vb_matfile_to_v6(inputfile, output_v6, output_org);
 [IN]
    inputfile  : <required> input MAT-FILE
    output_v6  : <optional> output file the data of which is
               :  converted to version 6 format
               :  [same as inputfile]
    output_org : <optional> output file which is original data
               :  if this is the same as output_v6, original data
               :  will not be lost.
               :  [same as inputfile]
 [NOTE]
    This function should be executed in MATLAB version 7 or later.

 2007-12-04 rhayashi

 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 vb_matfile_to_v6(inputfile, output_v6, output_org)
0002 % convert MATLAB7 or later format file into MATLAB6 format file.
0003 % USAGE:
0004 %    vb_matfile_to_v6(inputfile);
0005 %    vb_matfile_to_v6(inputfile, output_v6);
0006 %    vb_matfile_to_v6(inputfile, output_v6, output_org);
0007 % [IN]
0008 %    inputfile  : <required> input MAT-FILE
0009 %    output_v6  : <optional> output file the data of which is
0010 %               :  converted to version 6 format
0011 %               :  [same as inputfile]
0012 %    output_org : <optional> output file which is original data
0013 %               :  if this is the same as output_v6, original data
0014 %               :  will not be lost.
0015 %               :  [same as inputfile]
0016 % [NOTE]
0017 %    This function should be executed in MATLAB version 7 or later.
0018 %
0019 % 2007-12-04 rhayashi
0020 %
0021 % Copyright (C) 2011, ATR All Rights Reserved.
0022 % License : New BSD License(see VBMEG_LICENSE.txt)
0023 
0024 %
0025 % --- Previous check
0026 %
0027 if vb_matlab_version < 7
0028     error('This function should be executed in MATLAB version 7 or later. File not converted.');
0029 end
0030 if ~exist('inputfile', 'var')
0031     error('inputfile is a required parameter.');
0032 end
0033 if exist(inputfile, 'file') ~= 2
0034     error('inputfile not found.');
0035 end
0036 
0037 if ~exist('output_v6', 'var'), output_v6 = ''; end
0038 if ~exist('output_org', 'var'), output_org = ''; end
0039 if isdir(output_org), output_org = fullfile(output_org, inputfile); end
0040 
0041 %
0042 % --- Main Procedure
0043 %
0044 if isempty(output_v6), output_v6 = inputfile; end
0045 
0046 if ~strcmp(output_v6, output_org) && ~isempty(output_org)
0047     do_copy = true;
0048     if exist(output_org, 'file') == 2
0049         res = questdlg([output_org ' is already exists. Overwrite?'], ...
0050                         'Copy Original file', 'Yes', 'No', 'Yes');
0051         if strcmp(res, 'No'), do_copy = false; end
0052     end
0053     if do_copy
0054         % save original file
0055         [result, msg, msg_id] = copyfile(inputfile, output_org);
0056         % copy failed
0057         if result == 0
0058             fprintf('XXX : original file copy was failed. output_org = %s\n', ...
0059                     output_org);
0060             fprintf('XXX : conversion was terminated.\n');
0061             return;
0062         end
0063         fprintf('original file copy was succeeded.\n');
0064     else
0065         fprintf('original file copy was cancelled.\n');
0066     end
0067 end
0068 
0069 % load variable in the file as fields of struct S.
0070 S = load(inputfile);
0071 
0072 do_convert = true;
0073 if ~strcmp(inputfile, output_v6) && exist(output_v6, 'file') == 2
0074     res = questdlg([output_v6 ' is already exists. Overwrite?'], ...
0075             'Conversion', 'Yes', 'No', 'Yes');
0076     if strcmp(res, 'No'), do_convert = false; end
0077 end
0078 
0079 % save the field of structure S in the file as an independent variable.
0080 if do_convert
0081     save(output_v6, '-STRUCT', 'S', '-V6');
0082     fprintf('file conversion was succeeded.\n');
0083 else
0084     fprintf('file conversion was cancelled.\n');
0085 end

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