1 |
function [flt,data,header] = read_flt_traj(varargin) |
2 |
% Reads the float_trajectories files. |
3 |
% |
4 |
% flts=read_flt_traj(File_Names,[Worldlength]); |
5 |
% input Worldlength (= 4 or 8) is optional |
6 |
% returns a structured array with fields 'time','x','y','k','u','v','t','s','p' |
7 |
% |
8 |
% eg. |
9 |
% >> flts=read_flt_traj('float_trajectories',4); |
10 |
% >> plot( flts(3).time, flts(3).x/1e3 ) |
11 |
% >> for k=1:126;plot(flts(k).x/1e3,flts(k).y/1e3);hold on;end;hold off |
12 |
|
13 |
% $Header: /u/gcmpack/MITgcm/verification/flt_example/input/read_flt_traj.m,v 1.5 2009/02/25 01:41:00 dfer Exp $ |
14 |
% $Name: $ |
15 |
|
16 |
fName = varargin{1}; |
17 |
imax=13; % record size |
18 |
ieee='b'; % IEEE big-endian format |
19 |
WORDLENGTH = 8; % 8 bytes per real*8 |
20 |
if length(varargin)==2 |
21 |
WORDLENGTH = varargin{2}; |
22 |
end |
23 |
bytesPerRec=imax*WORDLENGTH; |
24 |
rtype =['real*',num2str(WORDLENGTH)]; |
25 |
|
26 |
[I]=strfind(fName,'/'); |
27 |
if length(I) == 0, |
28 |
bDr=''; |
29 |
else |
30 |
fprintf(' found Dir Sep in file name ('); |
31 |
fprintf(' %i',I); |
32 |
bDr=fName(1:I(end)); |
33 |
fprintf(' ) ; load files from Dir "%s"\n',bDr); |
34 |
end |
35 |
|
36 |
fls=dir([fName,'.*data']); |
37 |
|
38 |
data=zeros(imax,0); |
39 |
header=zeros(imax,0); |
40 |
|
41 |
% Read everything |
42 |
for k=1:size(fls,1) |
43 |
fid=fopen([bDr,fls(k).name],'r',ieee); |
44 |
%fprintf('fid= %i\n',fid); |
45 |
nrecs=fls(k).bytes/bytesPerRec; |
46 |
ldata=fread(fid,[imax nrecs],rtype); |
47 |
fclose(fid); |
48 |
header=[header ldata(:,1)]; |
49 |
data=[data ldata(:,2:end)]; |
50 |
clear ldata; |
51 |
end |
52 |
|
53 |
flt=struct('numsteps',[],'time',[],'x',[],'y',[],'z',[]); |
54 |
|
55 |
% Sort it all out |
56 |
for k=1:max(max(data(1,:))); |
57 |
j=find( data(1,:)==k ); |
58 |
[t,jj]=sort( data(2,j) ); j=j(jj); |
59 |
flt(k).time=data(2,j); |
60 |
flt(k).x=data( 3,j); |
61 |
flt(k).y=data( 4,j); |
62 |
flt(k).z=data( 5,j); |
63 |
flt(k).i=data( 6,j); |
64 |
flt(k).j=data( 7,j); |
65 |
flt(k).k=data( 8,j); |
66 |
flt(k).p=data( 9,j); |
67 |
flt(k).u=data(10,j); |
68 |
flt(k).v=data(11,j); |
69 |
flt(k).t=data(12,j); |
70 |
flt(k).s=data(13,j); |
71 |
end |
72 |
|
73 |
return |