/[MITgcm]/MITgcm/verification/flt_example/input/read_flt_traj.m
ViewVC logotype

Contents of /MITgcm/verification/flt_example/input/read_flt_traj.m

Parent Directory Parent Directory | Revision Log Revision Log | View Revision Graph Revision Graph


Revision 1.2 - (show annotations) (download)
Wed Dec 3 01:50:15 2008 UTC (15 years ago) by jmc
Branch: MAIN
CVS Tags: checkpoint61g
Changes since 1.1: +1 -1 lines
use "big-endian" binary (instead of a mix)

1 function [flt,data,header] = read_flt_traj(fName)
2 % Reads the float_trajectories files.
3 %
4 % returns a structured array with fields 'time','x','y','k','u','v','t','s','p'
5 %
6 % eg.
7 % >> flts=read_flt_traj('float_trajectories');
8 % >> plot( flts(3).time, flts(3).x/1e3 )
9 % >> for k=1:126;plot(flts(k).x/1e3,flts(k).y/1e3);hold on;end;hold off
10
11 imax=10; % record size
12 ieee='b'; % IEEE big-endian format
13 bytesPerRec=imax*8; % 8 bytes per real*8
14
15 fls=dir([fName '.*data']);
16
17 data=zeros(imax,0);
18 header=zeros(imax,0);
19
20 % Read everything
21 for k=1:size(fls,1)
22 fid=fopen(fls(k).name,'r',ieee);
23 nrecs=fls(k).bytes/bytesPerRec;
24 ldata=fread(fid,[imax nrecs],'real*8');
25 fclose(fid);
26 header=[header ldata(:,1)];
27 data=[data ldata(:,2:end)];
28 end
29
30 flt=struct('numsteps',[],'time',[],'x',[],'y',[],'k',[]);
31
32 % Sort it all out
33 for k=1:max(max(data(1,:)));
34 j=find( data(1,:)==k );
35 [t,jj]=sort( data(2,j) ); j=j(jj);
36 flt(k).time=data(2,j);
37 flt(k).x=data(3,j);
38 flt(k).y=data(4,j);
39 flt(k).k=data(5,j);
40 flt(k).u=data(6,j);
41 flt(k).v=data(7,j);
42 flt(k).t=data(8,j);
43 flt(k).s=data(9,j);
44 flt(k).p=data(10,j);
45 end

  ViewVC Help
Powered by ViewVC 1.1.22