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