1 |
gforget |
1.1 |
function [fldOut]=read2memory(fileIn,varargin); |
2 |
|
|
%purpose: load binary file to memory |
3 |
|
|
% |
4 |
|
|
%inputs: fileIn is the file name |
5 |
|
|
%(optional) sizeOut is the output array size (or [] if not known) |
6 |
|
|
% prec is the file precision (32, by default, or 64) |
7 |
|
|
% |
8 |
|
|
%output: fldOut is the binary vector (default) or array (if sizeOut is spec.) |
9 |
|
|
|
10 |
|
|
if nargin>1; sizeOut=varargin{1}; else; sizeOut=[]; end; |
11 |
|
|
if nargin>2; prec=varargin{2}; else; prec=32; end; |
12 |
|
|
|
13 |
|
|
if ~strcmp(fileIn(end-2:end),'txt'); |
14 |
|
|
nn=dir(fileIn); nn=nn.bytes/(prec/8); fid=fopen(fileIn,'r','b'); fldOut=fread(fid,nn,['float' num2str(prec)]); fclose(fid); |
15 |
|
|
else; |
16 |
|
|
error('text read is not implemented\n'); |
17 |
|
|
% fid=fopen(fileIn,'rt'); fread(fid,fldOut); fclose(fid); |
18 |
|
|
end; |
19 |
|
|
|
20 |
|
|
if ~isempty(sizeOut); fldOut=reshape(fldOut,sizeOut); end; |
21 |
|
|
|
22 |
|
|
|
23 |
|
|
|
24 |
|
|
|