Warning, /utils/matlab/cs_grid/read_cs/read_cs_index.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_index(fnam,ij_indices,kx,prec,cx)
0002
0003 % Function fld=read_cs_index(fnam,ij_indices,kx,prec,cx)
0004 % read in horizontal-slice indices for cube sphere configuration
0005 %
0006 % INPUTS
0007 % fnam input path and file name
0008 % ij_indices cube sphere horizontal-slice indices (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 length(ij_indices)*length(kx)
0015 %
0016 % SEE ALSO
0017 % readbin, read_cs_bin, read_cs_face, read_cs_ifjk
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, ij_indices=1; end
0023 if nargin < 1, error('please specify input file name'); end
0024
0025 fld=zeros(length(ij_indices),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 for i=1:length(ij_indices)
0041 skip = (kx(k)-1)*cx*6*cx + ij_indices(i)-1;
0042 if(fseek(fid,skip*preclength,'bof')<0), error('past end of file'); end
0043 fld(i,k)=fread(fid,1,prec);
0044 end
0045 end
da16053df7 Dimi*0046
0047 fid=fclose(fid);