Back to home page

MITgcm

 
 

    


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

view on githubraw file Latest commit 602828db on 2009-11-21 19:16:16 UTC
602828dbcc Dimi*0001 function fld=read_ijkt(fnam,ix,jx,kx,tx,nx,ny,nz,nt,prec)
                0002 
                0003 % Function fld=read_ijkt(fnam,ix,jx,kx,tx,nx,ny,nz,nt,prec)
                0004 % read in specific indices (ix,jx,kx,tx) from a 4D
                0005 % binary file of dimension(nx,ny,nz,nt)
                0006 %
                0007 % INPUTS
                0008 % fnam  input path and file name
                0009 % ix    i-indices, 1 to nx, to read (default 1)
                0010 % jx    j-indices, 1 to ny, to read (default 1)
                0011 % kx    k-indices, 1 to nz, to read (e.g., 1:50, default 1)
                0012 % tx    t-indices, 1 to nt, to read (default 1)
                0013 % nx    x-dimension of binary file (default 1440)
                0014 % ny    y-dimension of binary file (default 640)
                0015 % nz    z-dimension of binary file (default 50)
                0016 % nz    t-dimension of binary file (default 1)
                0017 % prec  numeric precision (see fread; default 'real*4')
                0018 %
                0019 % OUTPUTS
                0020 % fld    output array of dimension
                0021 %        length(ix)*length(jx)*length(kx)*length(kt)
                0022 %
                0023 % SEE ALSO
                0024 % readbin read_ijk writebin
                0025 
                0026 if nargin < 10, prec='real*4'; end
                0027 if nargin < 9, nt=1; end
                0028 if nargin < 8, nz=50; end
                0029 if nargin < 7, ny=640; end
                0030 if nargin < 6, nx=1440; end
                0031 if nargin < 5, tx=1; end
                0032 if nargin < 4, kx=1; end
                0033 if nargin < 3, jx=1; end
                0034 if nargin < 2, ix=1; end
                0035 if nargin < 1, error('please specify input file name'); end
                0036 
                0037 fld=zeros(length(ix),length(jx),length(kx),length(tx));
                0038 fid=fopen(fnam,'r','ieee-be');
                0039 
                0040 switch prec
                0041   case {'int8','integer*1'}
                0042     preclength=1;
                0043   case {'int16','integer*2','uint16','integer*2'}
                0044     preclength=2;
                0045   case {'int32','integer*4','uint32','single','real*4','float32'}
                0046     preclength=4;
                0047   case {'int64','integer*8','uint64','double','real*8','float64'}
                0048     preclength=8;
                0049 end
                0050 
                0051 for t=1:length(tx)
                0052   for k=1:length(kx)
                0053     for j=1:length(jx)
                0054       for i=1:length(ix)
                0055         skip = (tx(t)-1)*nz*ny*nx + (kx(k)-1)*ny*nx + (jx(j)-1)*nx + ix(i)-1;
                0056         if(fseek(fid,skip*preclength,'bof')<0), error('past end of file'); end
                0057         fld(i,j,k,t)=fread(fid,1,prec);
                0058       end
                0059     end
                0060   end
                0061 end
                0062 
                0063 fid=fclose(fid);
                0064 fld=squeeze(fld);