/[MITgcm]/MITgcm/verification/lab_sea/matlab/readbin.m
ViewVC logotype

Annotation of /MITgcm/verification/lab_sea/matlab/readbin.m

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


Revision 1.2.4.1 - (hide annotations) (download)
Sat Feb 15 12:40:31 2003 UTC (21 years, 1 month ago) by dimitri
Branch: ecco-branch
CVS Tags: ecco_c50_e32, ecco_c50_e33, ecco_c50_e30, ecco_c50_e31, ecco_c51_e34d, ecco_c51_e34e, ecco_c51_e34f, ecco_c51_e34g, ecco_c51_e34a, ecco_c51_e34b, ecco_c51_e34c, icebear5, icebear4, icebear3, icebear2, ecco_c50_e29, ecco_c50_e28, ecco_c50_e33a, ecco_c51_e34, ecco_c44_e27
Branch point for: icebear
Changes since 1.2: +0 -0 lines
o added verification/lab_sea as per release1_p12_pre

1 dimitri 1.2 function fld=readbin(fnam,siz,typ,prec,skip)
2    
3     % Function fld=readbin(fnam,siz,typ,prec,skip)
4     % read in N-D binary field
5     %
6     % INPUTS
7     % fnam input path and file name
8     % siz grid dimension (default [360 224 46])
9     % typ 0: sequential FORTRAN (default); 1: plain binary
10     % prec numeric precision (default 'real*4')
11     % skip records to skip before reading (default 0)
12     %
13     % OUTPUTS
14     % fld output array of dimension siz
15     %
16     % SEE ALSO
17     % writebin
18    
19     if nargin < 5, skip=0; end
20     if nargin < 4, prec='real*4'; end
21     if nargin < 3, typ=0; end
22     if nargin < 2, siz=[360 224 46]; end
23     if nargin < 1, t=1; end
24     if nargin < 0, error('please specify input file name'); end
25    
26     fid=fopen(fnam,'r','ieee-be');
27    
28     if skip>0
29     if typ==0
30     error('feature not implemented yet');
31     else
32     switch prec
33     case {'int8','integer*1'}
34     reclength=prod(siz);
35     case {'int16','integer*2','uint16','integer*2'}
36     reclength=2*prod(siz);
37     case {'int32','integer*4','uint32','single','real*4','float32'}
38     reclength=4*prod(siz);
39     case {'int64','integer*8','uint64','double','real*8','float64'}
40     reclength=8*prod(siz);
41     end
42     end
43     fseek(fid,skip*reclength,'bof');
44     end
45    
46     switch typ
47     case 0
48     tmp=read_record(fid,prec);
49     case 1
50     tmp=fread(fid,[siz(1),prod(siz(2:length(siz)))],prec);
51     end
52     fid=fclose(fid);
53    
54     switch length(siz)
55     case 2
56     fld=reshape(tmp,siz(1),siz(2));
57     case 3
58     fld=reshape(tmp,siz(1),siz(2),siz(3));
59     case 4
60     fld=reshape(tmp,siz(1),siz(2),siz(3),siz(4));
61     case 5
62     fld=reshape(tmp,siz(1),siz(2),siz(3),siz(4),siz(5));
63     otherwise
64     fld=tmp;
65     end

  ViewVC Help
Powered by ViewVC 1.1.22