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

vb_util_make_external_data_file

PURPOSE ^

make external data file

SYNOPSIS ^

function vb_util_make_external_data_file(fpath, fname, f_ext, prec, data, mode)

DESCRIPTION ^

 make external data file
 [usage]
   vb_util_make_external_data_file(fpath, fname, f_ext, prec, data, mode)
 [input]
   fpath : <required> file path
   fname : <required> file name
   f_ext : <required> file extension
   prec  : <required> precision
   data  : <required> data [N x 1]
   mode  : <optional> writing mode 'wb') newly write, 'ab') append
 [output]
   none
 [note]

 [history]
   2010-06-30 (Sako) initial version

 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:

SUBFUNCTIONS ^

SOURCE CODE ^

0001 function vb_util_make_external_data_file(fpath, fname, f_ext, prec, data, mode)
0002 % make external data file
0003 % [usage]
0004 %   vb_util_make_external_data_file(fpath, fname, f_ext, prec, data, mode)
0005 % [input]
0006 %   fpath : <required> file path
0007 %   fname : <required> file name
0008 %   f_ext : <required> file extension
0009 %   prec  : <required> precision
0010 %   data  : <required> data [N x 1]
0011 %   mode  : <optional> writing mode 'wb') newly write, 'ab') append
0012 % [output]
0013 %   none
0014 % [note]
0015 %
0016 % [history]
0017 %   2010-06-30 (Sako) initial version
0018 %
0019 % Copyright (C) 2011, ATR All Rights Reserved.
0020 % License : New BSD License(see VBMEG_LICENSE.txt)
0021 
0022 % --- CHECK ARGUMENTS --- %
0023 if ~exist('fpath', 'var'), fpath = ''; end
0024 if ~exist('fname', 'var'), fname = ''; end
0025 if ~exist('f_ext', 'var'), f_ext = ''; end
0026 if ~exist('prec',  'var'), prec  = ''; end
0027 if ~exist('data',  'var'), data  = []; end
0028 if ~exist('mode',  'var'), mode  = ''; end
0029 
0030 [fpath, fname, f_ext, prec, data, mode] = ...
0031   inner_check_arguments(fpath, fname, f_ext, prec, data, mode);
0032 
0033 % --- MAIN PROCEDURE --------------------------------------------------------- %
0034 %
0035 func_ = mfilename;
0036 
0037 if exist(fpath, 'dir') ~= 7
0038   mkdir(fpath);
0039 end
0040 
0041 ch_file = sprintf('%s/%s.%s', fpath, fname, f_ext);
0042 % fid = fopen(ch_file, 'wb');
0043 fid = fopen(ch_file, mode);
0044 if fid == -1
0045   error('(%s)cannot open file (%s)', func_, ch_file);
0046 end
0047 
0048 fwrite(fid, data(:), prec);
0049 fclose(fid);
0050 return;
0051 
0052 % --- INNER FUNCTIONS -------------------------------------------------------- %
0053 %
0054 % --- inner_check_arguments()
0055 %
0056 function [fpath, fname, f_ext, prec, data, mode] = ...
0057   inner_check_arguments(fpath, fname, f_ext, prec, data, mode)
0058 func_ = mfilename;
0059 
0060 if isempty(fpath)
0061   error('(%s) fpath is a required parameter', func_);
0062 end
0063 
0064 if ~ischar(fpath)
0065   error('(%s) fpath must be charactor', func_);
0066 end
0067 
0068 if isempty(fname)
0069   error('(%s) fname is a required parameter', func_);
0070 end
0071 
0072 if ~ischar(fname)
0073   error('(%s) fname must be charactor', func_);
0074 end
0075 
0076 if isempty(f_ext)
0077   error('(%s) f_ext is a required parameter', func_);
0078 end
0079 
0080 if ~ischar(f_ext)
0081   error('(%s) f_ext must be charactor', func_);
0082 end
0083 
0084 if isempty(prec)
0085   error('(%s) prec is a required parameter', func_);
0086 end
0087 
0088 if ~ischar(prec)
0089   error('(%s) prec must be charactor', func_);
0090 end
0091 
0092 if isempty(data)
0093   error('(%s) data is a required parameter', func_);
0094 end
0095 
0096 if isempty(mode)
0097   mode = 'wb';
0098 end
0099 return;
0100 %
0101 % --- end of inner_check_arguments()
0102 %
0103 % --- END OF INNER FUNCTIONS ------------------------------------------------- %
0104 
0105 % --- END OF FILE --- %

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