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