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

root/gliderproc/trunk/MATLAB/util/read_gliderasc3.m

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

Initial import of Stark code.

Line 
1
2 function dstruct = read_gliderasc3(file)
3
4
5
6 % dbdasc_extract.m
7
8 %fn = './pelagia-2012-046-4-0.tbdasc'
9
10 %file = 'pelagia-2012-022-0-0.dbdasc';
11 file = 'pelagia-2012-039-1-10.dbdasc';
12
13 datadir = '';
14
15 fid = fopen(blank([datadir, file]), 'r');
16
17 if fid>0
18   numHeaderLines = 0;
19   while (~feof(fid))
20    
21     % read header data without concern for order
22     a = fgetl(fid);
23     numHeaderLines = numHeaderLines + 1;
24     if strmatch('num_ascii_tags:', a)
25       numAsciiTags = str2num(a(17:end));
26     elseif strmatch('filename_label:', a)
27       fileName = a(17:end);
28     elseif strmatch('mission_name:', a)
29       missionName = a(15:end);
30     elseif strmatch('sensors_per_cycle:', a)
31       numVars = str2num(a(20:end));
32     elseif strmatch('num_label_lines:', a)
33       numLabelLines = str2num(a(17:end));
34     elseif strmatch('segment_filename_0:', a)
35       break;
36     end
37   end % while (~feof(fid))
38
39  
40  
41   % extract variable labels
42   labels = fgetl(fid);
43   splitstring = textscan(labels,'%s');
44   varLabels = splitstring{1}.';
45  
46   % extract unit labels
47   labels = fgetl(fid);
48   splitstring = textscan(labels,'%s');
49   unitLabels = splitstring{1}.';
50  
51   % extract numbers
52   a = fgetl(fid);
53
54
55  
56   dstruct.fname = fileName;
57   dstruct.mname = missionName;
58   dstruct.vars = varLabels;
59   dstruct.varlabs = unitLabels;
60
61  
62  
63   totalNumHeaderLines = numHeaderLines + numLabelLines; 
64  
65   formatString = repmat('%f', 1, numVars);
66   % This creates '%f%f%f' ... but with dynamic length based on header info
67   % You can make this elaborate based on file type (edb, dbd, tbd) and
68   % intermix integers, float and strings.  e.g. %d%d%d%f%f%f%s%s
69
70  
71   % SMH -- 100 times faster to textscan() rather than load()
72   %     -- and probably 1000 timers faster than reading line by line.
73   D = textscan(fid, formatString, 'Headerlines', totalNumHeaderLines);
74   D = cell2mat(D);
75   [nr nc] = size(D);
76   if nr>0
77     dstruct.data = [D];
78   end
79  
80 end % if fid>0
81
82
83 fclose(fid);
Note: See TracBrowser for help on using the browser.