| 1 |
gforget |
1.1 |
function []=write2file(fileOut,fldIn,varargin); |
| 2 |
|
|
%purpose: write array to binary file |
| 3 |
|
|
% |
| 4 |
|
|
%inputs: fileOut is the file name |
| 5 |
|
|
% fldIn is the array to write to disk |
| 6 |
|
|
%(optional) prec is the file precision (32, by default, or 64) |
| 7 |
|
|
|
| 8 |
|
|
if nargin>2; prec=varargin{1}; else; prec=32; end; |
| 9 |
gforget |
1.2 |
if nargin>3; omitNaNs=varargin{2}; else; omitNaNs=1; end; |
| 10 |
gforget |
1.1 |
|
| 11 |
|
|
if ~ischar(fldIn); |
| 12 |
gforget |
1.2 |
fid=fopen(fileOut,'w','b'); tmp1=fldIn; |
| 13 |
|
|
if omitNaNs; tmp1(isnan(tmp1))=0; end; |
| 14 |
|
|
fwrite(fid,tmp1,['float' num2str(prec)]); |
| 15 |
|
|
fclose(fid); |
| 16 |
gforget |
1.1 |
else; |
| 17 |
|
|
fid=fopen(fileOut,'wt'); fwrite(fid,fldIn); fclose(fid); |
| 18 |
|
|
end; |
| 19 |
|
|
|
| 20 |
|
|
|
| 21 |
|
|
|