/[MITgcm]/MITgcm_contrib/gael/matlab_class/gcmfaces_IO/read2memory.m
ViewVC logotype

Annotation of /MITgcm_contrib/gael/matlab_class/gcmfaces_IO/read2memory.m

Parent Directory Parent Directory | Revision Log Revision Log | View Revision Graph Revision Graph


Revision 1.1 - (hide annotations) (download)
Wed Dec 22 01:04:08 2010 UTC (14 years, 6 months ago) by gforget
Branch: MAIN
CVS Tags: checkpoint65x, checkpoint65r, checkpoint65p, checkpoint65q, checkpoint65v, checkpoint65w, checkpoint65t, checkpoint65u, checkpoint66f, checkpoint66e, checkpoint66d, checkpoint66c, checkpoint66b, checkpoint66a, checkpoint66o, HEAD
- rdmds2workspace.m	load all fields from rdmds file, assuming
			that names are incldued in the meta file
- read2memory.m write2file.m	basic binary read/write shortcuts

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    

  ViewVC Help
Powered by ViewVC 1.1.22