Back to home page

MITgcm

 
 

    


Warning, /utils/matlab/cs_grid/read_cs/read_cs_face.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_face(fnam,face,kx,prec,cx)
                0002 
61379c5f56 Dimi*0003 % Function fld=read_cs_face(fnam,face,kx,prec,cx)
b75ad9d212 Dimi*0004 % read in a cube sphere face
                0005 %
                0006 % INPUTS
                0007 % fnam  input path and file name
                0008 % face  face number, 1 to 6, to read (default 1)
                0009 % kx    vertical indices to read, e.g., 1:50 (default 1)
                0010 % prec  numeric precision (see fread; default 'real*4')
                0011 % cx    cube face size (default 510)
                0012 %
                0013 % OUTPUTS
                0014 % fld    output array of dimension cx*cx*length(kx)
                0015 %
                0016 % SEE ALSO
                0017 % readbin, read_cs_bin, read_cs_ifjk, read_cs_index
                0018 
                0019 if nargin < 5, cx=510; end
                0020 if nargin < 4, prec='real*4'; end
                0021 if nargin < 3, kx=1; end
                0022 if nargin < 2, face=1; end
                0023 if nargin < 1, error('please specify input file name'); end
                0024 
                0025 fld=zeros(cx,cx,length(kx));
                0026 fid=fopen(fnam,'r','ieee-be');
                0027 
                0028 switch prec
                0029  case {'int8','integer*1'}
                0030   preclength=1;
                0031  case {'int16','integer*2','uint16','integer*2'}
                0032   preclength=2;
                0033  case {'int32','integer*4','uint32','single','real*4','float32'}
                0034   preclength=4;
                0035  case {'int64','integer*8','uint64','double','real*8','float64'}
                0036   preclength=8;
                0037 end
                0038 
                0039 for k=1:length(kx)
                0040   skip=(kx(k)-1)*cx*6*cx;
                0041   if(fseek(fid,skip*preclength,'bof')<0), error('past end of file'); end
                0042   skip=(face-1)*cx;
                0043   if(fseek(fid,skip*preclength,'cof')<0), error('past end of file'); end
                0044   fld(:,:,k)=reshape(fread(fid,cx*cx,[int2str(cx) '*' prec],cx*5*preclength),cx,cx);
                0045 end
da16053df7 Dimi*0046 
                0047 fid=fclose(fid);