/[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.4 - (show annotations) (download)
Thu Feb 5 01:03:33 2009 UTC (14 years, 9 months ago) by jmc
Branch: MAIN
CVS Tags: checkpoint61i
Changes since 1.3: +14 -11 lines
adapt to new output file (with depth & i,j indices)

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 % $Header: /u/gcmpack/MITgcm/verification/flt_example/input/read_flt_traj.m,v 1.3 2009/01/04 01:03:59 jmc Exp $
12 % $Name: $
13
14 imax=13; % record size
15 ieee='b'; % IEEE big-endian format
16 bytesPerRec=imax*8; % 8 bytes per real*8
17
18 [I]=strfind(fName,'/');
19 if length(I) == 0,
20 bDr='';
21 else
22 fprintf(' found Dir Sep in file name (');
23 fprintf(' %i',I);
24 bDr=fName(1:I(end));
25 fprintf(' ) ; load files from Dir "%s"\n',bDr);
26 end
27
28 fls=dir([fName,'.*data']);
29
30 data=zeros(imax,0);
31 header=zeros(imax,0);
32
33 % Read everything
34 for k=1:size(fls,1)
35 fid=fopen([bDr,fls(k).name],'r',ieee);
36 %fprintf('fid= %i\n',fid);
37 nrecs=fls(k).bytes/bytesPerRec;
38 ldata=fread(fid,[imax nrecs],'real*8');
39 fclose(fid);
40 header=[header ldata(:,1)];
41 data=[data ldata(:,2:end)];
42 end
43
44 flt=struct('numsteps',[],'time',[],'x',[],'y',[],'z',[]);
45
46 % Sort it all out
47 for k=1:max(max(data(1,:)));
48 j=find( data(1,:)==k );
49 [t,jj]=sort( data(2,j) ); j=j(jj);
50 flt(k).time=data(2,j);
51 flt(k).x=data( 3,j);
52 flt(k).y=data( 4,j);
53 flt(k).z=data( 5,j);
54 flt(k).i=data( 6,j);
55 flt(k).j=data( 7,j);
56 flt(k).k=data( 8,j);
57 flt(k).p=data( 9,j);
58 flt(k).u=data(10,j);
59 flt(k).v=data(11,j);
60 flt(k).t=data(12,j);
61 flt(k).s=data(13,j);
62 end

  ViewVC Help
Powered by ViewVC 1.1.22