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

root/gliderproc/trunk/MATLAB/opnml/FCAST_1.2/read_pth.m

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

Initial import of Stark code.

Line 
1 function [gridname,ndrog,nts,tsec,pth]=read_pth(fname,ncol,fmtstr)
2 %READ_PTH read drogue .pth file output from DROG3D or DROG3DDT.
3 %
4 % [gridname,ndrog,ndts,tsec,pth]=read_pth(fname,ncol,fmtstr);
5 %
6 %          Input:
7 %                 fname  - path/name of .pth file
8 %                 ncol   - number of columns in output matrix
9 %                 fmtstr - format string for PLOTDROG to use in
10 %                          reading the .pth file (optional)
11 %          Output:
12 %                 gridname - domain name of computation
13 %                 ndrog    - number of drogues at start of run
14 %                 ndts     - number of time steps in run
15 %                 tsec     - length of run in seconds
16 %                 pth      - path data part of the .pth file.
17 %
18 %          If only one output argument is provided, READ_PTH returns
19 %          a structure composed of the above components.
20 %
21 %          READ_PTH takes as required arguments the path/filename of the
22 %          .pth file generated by DROG3D(DT), and the number of columns
23 %          the subroutine OUTPUT (from DROG3D(DT)) used to write the .pth
24 %          file.  The filename specified must NOT include the .pth suffix. 
25 %          This allows READ_PTH to verify that the filetype is correct.
26 %          Ex.: if the path/filename is 'results/case1.pth', the name given
27 %          to READ_PTH should be 'results/case1'.
28 %
29 %          Optional argument comments:
30 %
31 %          If fmtstr is NOT specified, READ_PTH makes assumes the following
32 %          as to the format of the path matrix:
33
34 %          If ncol = 3  -->  real   real   real
35 %          If ncol = 4  -->  real   real   real   real
36 %          If ncol = 5  -->  real   real   real   real  integer
37 %          If ncol = 6  -->  real   real   real   real  real  integer
38 %
39 %          If the above assumption about the format of the output matrix
40 %          is NOT correct, you must specify, in the C fashion, the correct
41 %          format for READ_PTH to use in the C fashion.  See the MATLAB
42 %          Reference Guide under FSCANF for more on format specification. 
43 %
44 % Call as: [gridname,ndrog,ndts,tsec,pth]=read_pth(fname,ncol,fmtstr);
45
46 % Written by: Brian O. Blanton
47 %
48
49 % DEFINE ERROR STRINGS
50 err1=['READ_PTH requires 2 or 3 arguments.'];
51 err2=['second argument to READ_PTH must be an integer.'];
52 err3=['format specification to READ_PTH must be a string.'];
53
54 % check arguments
55 if nargin ==2
56    if isstr(ncol),error(err2);,end
57    if ncol==3
58       fmtstr='%f %f %f';
59    elseif ncol==4
60       fmtstr='%f %f %f %f';
61    elseif ncol==5
62       fmtstr='%f %f %f %f %d';
63    elseif ncol==6
64       fmtstr='%f %f %f %f %f %d';
65    end 
66 elseif nargin==3
67     if isstr(ncol),error(err2),end
68     if ~isstr(fmtstr),error(err3),end
69 else
70    error(err1);
71 end
72
73
74 % read path file
75 pathfile=[fname,'.pth'];
76 [pfid,message]=fopen(pathfile);
77 if pfid==-1
78    error([fname,'.pth not found. ',message]);
79 end
80
81 % read grid name from top of .pth file
82 gridname=fscanf(pfid,'%s',1);
83 gridname=blank(gridname);
84
85 % read until 'XXXX' delimiter
86 test=fscanf(pfid,'%s',1);
87 while ~strcmp(test,'XXXX')
88    test=fscanf(pfid,'%s',1);
89    if isempty(test)
90       disp(['String XXXX not found in file ',fname]);
91       gridname=0;
92       return
93    end
94 end
95
96 % read number if timesteps, total run time in secs, and number of drogues
97 a=fscanf(pfid,'%d %f %d',3);
98 nts=a(1);
99 tsec=a(2);
100 ndrog=a(3);
101
102 % read entire path
103 pth=fscanf(pfid,fmtstr,[ncol inf])';
104
105 % If nts==0, then the .pth file was output from DROG3DDT.  Compute
106 % nts from ndrog and the length of the path matrix, pth
107 if nts==0,nts=length(pth)/ndrog;,end
108
109 if nargout==1
110    temp=gridname;
111    clear gridname
112    % Despite appearences, the var gridname is returned as the
113    % structure when there is only one output argument.
114    gridname=struct('gridname',temp,...
115                    'ndrog',ndrog,...
116                    'ndts',nts,...
117                    'tsec',tsec,...
118                    'pth',pth);
119    clear pth nts ndrog temp
120 end
121 return
122 %
123 %        Brian O. Blanton
124 %        Department of Marine Sciences
125 %        15-1A Venable Hall
126 %        CB# 3300
127 %        Uni. of North Carolina
128 %        Chapel Hill, NC
129 %                 27599-3300
130 %
131 %        919-962-4466
132 %        blanton@marine.unc.edu
133 %
134
135
136
137
Note: See TracBrowser for help on using the browser.