Back to home page

MITgcm

 
 

    


Warning, /verification/natl_box/matlab/readbin.m is written in an unsupported language. File is not indexed.

view on githubraw file Latest commit cdf4d124 on 2000-11-13 16:02:33 UTC
cdf4d1244c Patr*0001 function fld=readbin(fnam,siz,typ,prec)
                0002 
                0003 % Function fld=readbin(fnam,siz,typ,prec)
                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 %
                0012 % OUTPUTS
                0013 % fld    output array of dimension siz
                0014 %
                0015 % SEE ALSO
                0016 % writebin
                0017 
                0018 if nargin<4, prec='real*4'; end
                0019 if nargin<3, typ=0; end
                0020 if nargin<2, siz=[360 224 46]; end
                0021 if nargin<1, t=1; end
                0022 if nargin<0, error('please specify input file name'); end
                0023 
                0024 fid=fopen(fnam,'r','ieee-be');
                0025 switch typ
                0026   case 0
                0027     tmp=read_record(fid,prec);
                0028   case 1
                0029     tmp=fread(fid,[siz(1),prod(siz(2:length(siz)))],prec);
                0030 end
                0031 fid=fclose(fid);
                0032 
                0033 switch length(siz)
                0034   case 2
                0035     fld=reshape(tmp,siz(1),siz(2));
                0036   case 3
                0037     fld=reshape(tmp,siz(1),siz(2),siz(3));
                0038   case 4
                0039     fld=reshape(tmp,siz(1),siz(2),siz(3),siz(4));
                0040   case 5
                0041     fld=reshape(tmp,siz(1),siz(2),siz(3),siz(4),siz(5));
                0042   otherwise
                0043     fld=tmp;
                0044 end