/[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.6 - (hide annotations) (download)
Fri Feb 3 04:08:12 2012 UTC (12 years, 3 months ago) by dfer
Branch: MAIN
CVS Tags: checkpoint65z, checkpoint65x, checkpoint65y, checkpoint65r, checkpoint65s, checkpoint65p, checkpoint65q, checkpoint65v, checkpoint65w, checkpoint65t, checkpoint65u, checkpoint65j, checkpoint65k, checkpoint65h, checkpoint65i, checkpoint65n, checkpoint65l, checkpoint65m, checkpoint65b, checkpoint65c, checkpoint65a, checkpoint65f, checkpoint65g, checkpoint65d, checkpoint65e, checkpoint64, checkpoint65, checkpoint66g, checkpoint66f, checkpoint66e, checkpoint66d, checkpoint66c, checkpoint66b, checkpoint66a, checkpoint66o, checkpoint66n, checkpoint66m, checkpoint66l, checkpoint66k, checkpoint66j, checkpoint66i, checkpoint66h, checkpoint63p, checkpoint63q, checkpoint63r, checkpoint63s, checkpoint63l, checkpoint63m, checkpoint63n, checkpoint63o, checkpoint63j, checkpoint63k, checkpoint65o, checkpoint64y, checkpoint64x, checkpoint64z, checkpoint64q, checkpoint64p, checkpoint64s, checkpoint64r, checkpoint64u, checkpoint64t, checkpoint64w, checkpoint64v, checkpoint64i, checkpoint64h, checkpoint64k, checkpoint64j, checkpoint64m, checkpoint64l, checkpoint64o, checkpoint64n, checkpoint64a, checkpoint64c, checkpoint64b, checkpoint64e, checkpoint64d, checkpoint64g, checkpoint64f, HEAD
Changes since 1.5: +16 -5 lines
fix reading of outputs with float32 precision

1 dfer 1.6 function [flt,data,header] = read_flt_traj(varargin)
2 adcroft 1.1 % Reads the float_trajectories files.
3     %
4 dfer 1.6 % flts=read_flt_traj(File_Names,[Worldlength]);
5     % input Worldlength (= 4 or 8) is optional
6 adcroft 1.1 % returns a structured array with fields 'time','x','y','k','u','v','t','s','p'
7     %
8     % eg.
9 dfer 1.6 % >> flts=read_flt_traj('float_trajectories',4);
10 adcroft 1.1 % >> 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 dfer 1.6 % $Header: /u/gcmpack/MITgcm/verification/flt_example/input/read_flt_traj.m,v 1.5 2009/02/25 01:41:00 dfer Exp $
14 jmc 1.3 % $Name: $
15    
16 dfer 1.6 fName = varargin{1};
17 dfer 1.5 imax=13; % record size
18     ieee='b'; % IEEE big-endian format
19 dfer 1.6 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 adcroft 1.1
26 jmc 1.3 [I]=strfind(fName,'/');
27     if length(I) == 0,
28     bDr='';
29     else
30     fprintf(' found Dir Sep in file name (');
31 dfer 1.5 fprintf(' %i',I);
32 jmc 1.3 bDr=fName(1:I(end));
33     fprintf(' ) ; load files from Dir "%s"\n',bDr);
34     end
35    
36     fls=dir([fName,'.*data']);
37 adcroft 1.1
38     data=zeros(imax,0);
39     header=zeros(imax,0);
40    
41     % Read everything
42     for k=1:size(fls,1)
43 jmc 1.3 fid=fopen([bDr,fls(k).name],'r',ieee);
44     %fprintf('fid= %i\n',fid);
45 adcroft 1.1 nrecs=fls(k).bytes/bytesPerRec;
46 dfer 1.6 ldata=fread(fid,[imax nrecs],rtype);
47 adcroft 1.1 fclose(fid);
48     header=[header ldata(:,1)];
49     data=[data ldata(:,2:end)];
50 dfer 1.6 clear ldata;
51 adcroft 1.1 end
52    
53 jmc 1.4 flt=struct('numsteps',[],'time',[],'x',[],'y',[],'z',[]);
54 adcroft 1.1
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 jmc 1.4 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 adcroft 1.1 end
72 dfer 1.6
73     return

  ViewVC Help
Powered by ViewVC 1.1.22