Back to home page

MITgcm

 
 

    


Warning, /utils/matlab/cs_grid/read_cs/read_cs_bin.m is written in an unsupported language. File is not indexed.

view on githubraw file Latest commit da16053d on 2007-03-27 15:00:38 UTC
b75ad9d212 Dimi*0001 function fld=read_cs_bin(fnam,kx,prec,cx)
                0002 
                0003 % Function fld=read_cs_bin(fnam,kx,prec,cx)
                0004 % read in cube sphere binary output
                0005 %
                0006 % INPUTS
                0007 % fnam  input path and file name
                0008 % kx    vertical indices to read, e.g., 1:50 (default 1)
                0009 % prec  numeric precision (see fread; default 'real*4')
                0010 % cx    cube face size (default 510)
                0011 %
                0012 % OUTPUTS
                0013 % fld    output array of dimension cx*6*cx*length(kx)
                0014 %
                0015 % SEE ALSO
                0016 % readbin, read_cs_face, read_cs_ifjk, read_cs_index
                0017 
                0018 if nargin < 4, cx=510; end
                0019 if nargin < 3, prec='real*4'; end
                0020 if nargin < 2, kx=1; end
                0021 if nargin < 1, error('please specify input file name'); end
                0022 
                0023 fld=zeros(cx,6,cx,length(kx));
                0024 fid=fopen(fnam,'r','ieee-be');
                0025 
                0026 switch prec
                0027  case {'int8','integer*1'}
                0028   preclength=1;
                0029  case {'int16','integer*2','uint16','integer*2'}
                0030   preclength=2;
                0031  case {'int32','integer*4','uint32','single','real*4','float32'}
                0032   preclength=4;
                0033  case {'int64','integer*8','uint64','double','real*8','float64'}
                0034   preclength=8;
                0035 end
                0036 
                0037 for k=1:length(kx)
                0038   skip=(kx(k)-1)*cx*6*cx;
                0039   if(fseek(fid,skip*preclength,'bof')<0), error('past end of file'); end
                0040   fld(:,:,:,k)=reshape(fread(fid,cx*6*cx,prec),cx,6,cx);
                0041 end
da16053df7 Dimi*0042 
                0043 fid=fclose(fid);