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

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

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

Initial import of Stark code.

Line 
1 %
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 (or zero)
15 %                 tsec     - length of run (or timestep) 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 function [gridname,ndrog,nts,tsec,pth]=read_pth(fname,ncol,fmtstr)
46
47 % DEFINE ERROR STRINGS
48 err1=['READ_PTH requires 2 or 3 arguments.'];
49 err2=['second argument to READ_PTH must be an integer.'];
50 err3=['format specification to READ_PTH must be a string.'];
51
52 % check arguments
53 if nargin ==2
54    if isstr(ncol),error(err2);,end
55    if ncol==3
56       fmtstr='%f %f %f';
57    elseif ncol==4
58       fmtstr='%f %f %f %f';
59    elseif ncol==5
60       fmtstr='%f %f %f %f %d';
61    elseif ncol==6
62       fmtstr='%f %f %f %f %f %d';
63    end 
64 elseif nargin==3
65     if isstr(ncol),error(err2),end
66     if ~isstr(fmtstr),error(err3),end
67 else
68    error(err1);
69 end
70
71
72 % read path file
73 pathfile=[fname,'.pth'];
74 [pfid,message]=fopen(pathfile);
75 if pfid==-1
76    error([fname,'.pth not found. ',message]);
77 end
78
79 % read grid name from top of .pth file
80 gridname=fscanf(pfid,'%s',1);
81 gridname=blank(gridname);
82
83 % read until 'XXXX' delimiter
84 test=fscanf(pfid,'%s',1);
85 while ~strcmp(test,'XXXX')
86    test=fscanf(pfid,'%s',1);
87    if isempty(test)==1
88       disp(['String XXXX not found in file ',fname]);
89       gridname=0;
90       return
91    end
92 end
93
94 % read number if timesteps, total run time in secs, and number of drogues
95 a=fscanf(pfid,'%d %f %d',3);
96 nts=a(1);
97 tsec=a(2);
98 ndrog=a(3);
99
100 % read entire path
101 pth=fscanf(pfid,fmtstr,[ncol inf])';
102 fclose(pfid);
103 return
104 %
105 %        Brian O. Blanton
106 %        Curr. in Marine Science
107 %        15-1A Venable Hall
108 %        CB# 3300
109 %        Uni. of North Carolina
110 %        Chapel Hill, NC
111 %                 27599-3300
112 %
113 %        919-962-4466
114 %        blanton@marine.unc.edu
115 %
116
117
118
119
Note: See TracBrowser for help on using the browser.