Warning, /verification/lab_sea/matlab/readbin.m is written in an unsupported language. File is not indexed.
view on githubraw file Latest commit baa476ee on 2002-12-05 08:43:03 UTC
baa476eeba Dimi*0001 function fld=readbin(fnam,siz,typ,prec,skip)
0002
0003 % Function fld=readbin(fnam,siz,typ,prec,skip)
0004 % read in N-D binary field
0005 %
0006 % INPUTS
0007 % fnam input path and file name
0008 % siz grid dimension (default [360 224 46])
0009 % typ 0: sequential FORTRAN (default); 1: plain binary
0010 % prec numeric precision (default 'real*4')
0011 % skip records to skip before reading (default 0)
0012 %
0013 % OUTPUTS
0014 % fld output array of dimension siz
0015 %
0016 % SEE ALSO
0017 % writebin
0018
0019 if nargin < 5, skip=0; end
0020 if nargin < 4, prec='real*4'; end
0021 if nargin < 3, typ=0; end
0022 if nargin < 2, siz=[360 224 46]; end
0023 if nargin < 1, t=1; end
0024 if nargin < 0, error('please specify input file name'); end
0025
0026 fid=fopen(fnam,'r','ieee-be');
0027
0028 if skip>0
0029 if typ==0
0030 error('feature not implemented yet');
0031 else
0032 switch prec
0033 case {'int8','integer*1'}
0034 reclength=prod(siz);
0035 case {'int16','integer*2','uint16','integer*2'}
0036 reclength=2*prod(siz);
0037 case {'int32','integer*4','uint32','single','real*4','float32'}
0038 reclength=4*prod(siz);
0039 case {'int64','integer*8','uint64','double','real*8','float64'}
0040 reclength=8*prod(siz);
0041 end
0042 end
0043 fseek(fid,skip*reclength,'bof');
0044 end
0045
0046 switch typ
0047 case 0
0048 tmp=read_record(fid,prec);
0049 case 1
0050 tmp=fread(fid,[siz(1),prod(siz(2:length(siz)))],prec);
0051 end
0052 fid=fclose(fid);
0053
0054 switch length(siz)
0055 case 2
0056 fld=reshape(tmp,siz(1),siz(2));
0057 case 3
0058 fld=reshape(tmp,siz(1),siz(2),siz(3));
0059 case 4
0060 fld=reshape(tmp,siz(1),siz(2),siz(3),siz(4));
0061 case 5
0062 fld=reshape(tmp,siz(1),siz(2),siz(3),siz(4),siz(5));
0063 otherwise
0064 fld=tmp;
0065 end