| 1 |
function fn_fprintvector(fid, vec, ncols, indxFloat) |
| 2 |
% Prints a row vector to an ascii file indexed by fid without any spacing. |
| 3 |
% |
| 4 |
% Inputs: |
| 5 |
% fid: Ascii file id. Example: fid = fopen('outdatainp_3s_stv_tvms6lags.prn','a'); |
| 6 |
% vec: A row vector to be written to the file. |
| 7 |
% ncols: Number of columns of vec. |
| 8 |
% indxFloat: 1 if double; |
| 9 |
% 2 if single; |
| 10 |
% 0 if integer. |
| 11 |
% |
| 12 |
% Copyright (C) 1997-2012 Tao Zha |
| 13 |
% |
| 14 |
% This free software: you can redistribute it and/or modify |
| 15 |
% it under the terms of the GNU General Public License as published by |
| 16 |
% the Free Software Foundation, either version 3 of the License, or |
| 17 |
% (at your option) any later version. |
| 18 |
% |
| 19 |
% It is distributed in the hope that it will be useful, |
| 20 |
% but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 21 |
% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 22 |
% GNU General Public License for more details. |
| 23 |
% |
| 24 |
% If you did not received a copy of the GNU General Public License |
| 25 |
% with this software, see <http://www.gnu.org/licenses/>. |
| 26 |
% |
| 27 |
|
| 28 |
% |
| 29 |
if size(vec,1)~=1 |
| 30 |
error('fn_fprintvector(): The vector must be a row vector'); |
| 31 |
end |
| 32 |
if ncols~=size(vec,2) |
| 33 |
error('fn_fprintvector(): The column number supplied match that of the vector'); |
| 34 |
end |
| 35 |
for kj=1:ncols |
| 36 |
if (indxFloat == 1) |
| 37 |
fprintf(fid,' %.16e ',vec(kj)); |
| 38 |
elseif (indxFloat == 2) |
| 39 |
fprintf(fid,' %.8e ',vec(kj)); |
| 40 |
else |
| 41 |
fprintf(fid,' %d ',vec(kj)); |
| 42 |
end |
| 43 |
if (kj==ncols) |
| 44 |
fprintf(fid,'\n'); |
| 45 |
end |
| 46 |
end |