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

Annotation 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.3 - (hide annotations) (download)
Sun Jan 4 01:03:59 2009 UTC (15 years, 5 months ago) by jmc
Branch: MAIN
CVS Tags: checkpoint61h
Changes since 1.2: +16 -2 lines
fix for reading files in other dir than the current dir.

1 adcroft 1.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 jmc 1.3 % $Header: $
12     % $Name: $
13    
14 adcroft 1.1 imax=10; % record size
15 jmc 1.2 ieee='b'; % IEEE big-endian format
16 adcroft 1.1 bytesPerRec=imax*8; % 8 bytes per real*8
17    
18 jmc 1.3 [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 adcroft 1.1
30     data=zeros(imax,0);
31     header=zeros(imax,0);
32    
33     % Read everything
34     for k=1:size(fls,1)
35 jmc 1.3 fid=fopen([bDr,fls(k).name],'r',ieee);
36     %fprintf('fid= %i\n',fid);
37 adcroft 1.1 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',[],'k',[]);
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).k=data(5,j);
54     flt(k).u=data(6,j);
55     flt(k).v=data(7,j);
56     flt(k).t=data(8,j);
57     flt(k).s=data(9,j);
58     flt(k).p=data(10,j);
59     end

  ViewVC Help
Powered by ViewVC 1.1.22