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

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

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


Revision 1.1 - (hide annotations) (download)
Fri Jan 31 21:30:01 2014 UTC (11 years, 5 months ago) by gforget
Branch: MAIN
CVS Tags: checkpoint65r, checkpoint65p, checkpoint65q
previously : ecco_v4/v4_read_bin.m

1 gforget 1.1 function [fld]=read_bin(fileName,varargin);
2     %usage: fld=read_bin(fileName); reads 3D field (N levels in 3rd dim)
3     %usage: fld=read_bin(fileName,trec); reads 3D field, at trec (50 levels)
4     %usage: fld=read_bin(fileName,trec,k); reads 2D field, at level k, at trec (50 levels)
5     %usage: fld=read_bin(fileName,trec,0); reads 2D field, at trec (1 level)
6    
7     global mygrid;
8    
9     n1=mygrid.ioSize(1); n2=mygrid.ioSize(2); n3=length(mygrid.RC); nF=mygrid.nFaces;
10     recl2D=n1*n2*4; recl3D=n1*n2*n3*4; myprec='float32';
11     %recl2D=n1*n2*8; recl3D=n1*n2*n3*8; myprec='float64';
12    
13     if nargin==1; n3=dir(fileName); n3=n3.bytes/recl2D; recl3D=recl2D*n3; end;
14     if nargin>1; tt=varargin{1}; else; tt=1; end;
15     if nargin>2; kk=varargin{2}; else; kk=[]; end;
16    
17     fid=fopen(fileName,'r','b');
18     if ~isempty(kk);
19     if kk==0;%meaning the field is only two dimensional
20     status=fseek(fid,(tt-1)*recl2D,'bof');
21     fld=reshape(fread(fid,n1*n2,myprec),[n1 n2]);
22     else;
23     status=fseek(fid,(tt-1)*recl3D+(kk-1)*recl2D,'bof');
24     fld=reshape(fread(fid,n1*n2,myprec),[n1 n2]);
25     end;
26     else;
27     status=fseek(fid,(tt-1)*recl3D,'bof');
28     fld=reshape(fread(fid,n1*n2*n3,myprec),[n1 n2 n3]);
29     end;
30     fclose(fid);
31    
32     fld=convert2gcmfaces(fld);
33    

  ViewVC Help
Powered by ViewVC 1.1.22