Warning, /verification/flt_example/input/read_flt_traj.m is written in an unsupported language. File is not indexed.
view on githubraw file Latest commit add29e06 on 2018-01-31 20:35:05 UTC
c47828ff44 Davi*0001 function [flt,data,header] = read_flt_traj(varargin)
c806179eb4 Alis*0002 % Reads the float_trajectories files.
0003 %
c47828ff44 Davi*0004 % flts=read_flt_traj(File_Names,[Worldlength]);
0005 % input Worldlength (= 4 or 8) is optional
c806179eb4 Alis*0006 % returns a structured array with fields 'time','x','y','k','u','v','t','s','p'
0007 %
0008 % eg.
c47828ff44 Davi*0009 % >> flts=read_flt_traj('float_trajectories',4);
c806179eb4 Alis*0010 % >> plot( flts(3).time, flts(3).x/1e3 )
0011 % >> for k=1:126;plot(flts(k).x/1e3,flts(k).y/1e3);hold on;end;hold off
0012
c47828ff44 Davi*0013 fName = varargin{1};
1534f74df3 Davi*0014 imax=13; % record size
0015 ieee='b'; % IEEE big-endian format
c47828ff44 Davi*0016 WORDLENGTH = 8; % 8 bytes per real*8
0017 if length(varargin)==2
0018 WORDLENGTH = varargin{2};
0019 end
0020 bytesPerRec=imax*WORDLENGTH;
0021 rtype =['real*',num2str(WORDLENGTH)];
c806179eb4 Alis*0022
10e4febb2f Jean*0023 [I]=strfind(fName,'/');
0024 if length(I) == 0,
0025 bDr='';
0026 else
0027 fprintf(' found Dir Sep in file name (');
1534f74df3 Davi*0028 fprintf(' %i',I);
10e4febb2f Jean*0029 bDr=fName(1:I(end));
0030 fprintf(' ) ; load files from Dir "%s"\n',bDr);
0031 end
0032
0033 fls=dir([fName,'.*data']);
c806179eb4 Alis*0034
0035 data=zeros(imax,0);
0036 header=zeros(imax,0);
0037
0038 % Read everything
0039 for k=1:size(fls,1)
10e4febb2f Jean*0040 fid=fopen([bDr,fls(k).name],'r',ieee);
0041 %fprintf('fid= %i\n',fid);
c806179eb4 Alis*0042 nrecs=fls(k).bytes/bytesPerRec;
c47828ff44 Davi*0043 ldata=fread(fid,[imax nrecs],rtype);
c806179eb4 Alis*0044 fclose(fid);
0045 header=[header ldata(:,1)];
0046 data=[data ldata(:,2:end)];
c47828ff44 Davi*0047 clear ldata;
c806179eb4 Alis*0048 end
0049
a0fa0e8551 Jean*0050 flt=struct('numsteps',[],'time',[],'x',[],'y',[],'z',[]);
c806179eb4 Alis*0051
0052 % Sort it all out
0053 for k=1:max(max(data(1,:)));
0054 j=find( data(1,:)==k );
0055 [t,jj]=sort( data(2,j) ); j=j(jj);
0056 flt(k).time=data(2,j);
a0fa0e8551 Jean*0057 flt(k).x=data( 3,j);
0058 flt(k).y=data( 4,j);
0059 flt(k).z=data( 5,j);
0060 flt(k).i=data( 6,j);
0061 flt(k).j=data( 7,j);
0062 flt(k).k=data( 8,j);
0063 flt(k).p=data( 9,j);
0064 flt(k).u=data(10,j);
0065 flt(k).v=data(11,j);
0066 flt(k).t=data(12,j);
0067 flt(k).s=data(13,j);
c806179eb4 Alis*0068 end
c47828ff44 Davi*0069
0070 return