NCCOOS Trac Projects: Top | Web | Platforms | Processing | Viz | Sprints | Sandbox | (Wind)

root/gliderproc/trunk/MATLAB/opnml/IO_Functions/read_trn2.m

Revision 495 (checked in by cbc, 12 years ago)

Initial import of Stark code.

Line 
1 %
2 % READ_TRN read a .trn file as output from the OPNML transect code
3 %
4 % data=read_trn(trnname);         
5 %
6 %          If trnname is omitted, READ_TRN enables a file browser
7 %          with which the user can specify the .trn file.
8 %
9 %          Otherwise, READ_TRN takes a input the filename of the
10 %          transect data file, including the .trn suffix.
11 %
12 %          The columns of the returned data part are:
13 %             
14 %              Dist.    Depths    Normal   Parallel   Vert.
15 %              along      at       Vel.      Vel.     Vel.
16 %              trans   Stations
17 %               (X)       (Y)      (Vn)      (Vp)      (W)
18 %
19 %          Read the "man" page for TRANSECT (type "man transect" at a UNIX
20 %          prompt) for the format specifics of a .trn file.
21 %
22 %          In order to plot the results of a transect, an element list
23 %          corresponding to the number of horizontal and vertical
24 %          stations must be generated.  This list is output by TRANSECT,
25 %          either as "trans.ele" or "ftn99".  Alternatively, this list can
26 %          be generated within MATLAB
27 %          with the OPNML/MATLAB routine ELGEN.  The element list can also
28 %          be generated with the OPNML binary code "elgen". 
29 %
30 %          Make sure a semi-colon is used at the end of the command;
31 %          otherwise READ_TRN will return the data part to the screen.
32 %
33 % Call as: data=read_trn(trnname);
34 %
35 function data=read_trn(trnname)
36
37 err1=['READ_TRN requires 0 or 1 argument.'];
38 err2=['Argument to READ_TRN must be a string (filename)'];
39
40 if nargin > 1
41    error(err1)
42 end
43
44 if ~exist('trnname')
45    [trnname,fpath]=uigetfile('*.trn','Which .trn');
46    if trnname==0,return,end
47 else
48    if ~isstr(trnname),error(err2),end
49    fpath=[];
50 end
51
52 [pfid,message]=fopen([fpath trnname]);
53 if pfid==-1
54    error([fpath trnname,' not found. ',message]);
55 end
56
57 %%%%%%%%%%%%%%  READ HEADER INFO FROM TOP OF .trn FILE %%%%%%%%%%%%%%%
58 % read grid name from top of .trn file
59 %
60 gridname=fscanf(pfid,'%s',1);
61 gridname=blank(gridname);
62
63 % read until '=', then get the filename of the
64 % source data used to generate this transect
65 %
66 word=[' '];
67 while word~='='
68    word=fscanf(pfid,'%s',1);
69 end
70 sourcedata=fscanf(pfid,'%s',1);
71
72 % read to the end of the "Transect End-Points" description line
73 %
74 trash=fscanf(pfid,'%s',1);
75 trash=fscanf(pfid,'%s',1);
76
77 % read transect end-points
78 %
79 trash=fscanf(pfid,'%4s',1);trash=fscanf(pfid,'%2s',1);
80 X1=fscanf(pfid,'%f',1);
81 trash=fscanf(pfid,'%4s',1);trash=fscanf(pfid,'%2s',1);
82 Y1=fscanf(pfid,'%f',1);
83 trash=fscanf(pfid,'%4s',1);trash=fscanf(pfid,'%2s',1);
84 X2=fscanf(pfid,'%f',1);
85 trash=fscanf(pfid,'%4s',1);trash=fscanf(pfid,'%2s',1);
86 Y2=fscanf(pfid,'%f',1);
87 endpoints=[X1 Y1 X2 Y2];
88
89 % read until '=', then get number of horizontal points in transect
90 %
91 word=[' '];
92 while word~='='
93    word=fscanf(pfid,'%s',1);
94 end
95 nhorz=fscanf(pfid,'%f',1);
96
97 % read until '=', then get number of vertical points in transect
98 %
99 word=[' '];
100 while word~='='
101    word=fscanf(pfid,'%s',1);
102 end
103 nvert=fscanf(pfid,'%f',1);
104
105 npts=[nhorz nvert];
106
107 data=fscanf(pfid,'%f %f %f %f %f',[5 nhorz*nvert]);
108 data=data';
109 fclose(pfid);
110
111
112
Note: See TracBrowser for help on using the browser.