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

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

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

Initial import of Stark code.

Line 
1
2 function dstruct = read_gliderasc2(file)
3
4
5 %file = 'pelagia-2012-039-0-0.ebdasc';
6 %file = 'pelagia-2012-022-0-0.dbdasc';
7 %file = 'pelagia-2012-039-1-10.dbdasc';
8
9
10 % Calls: strfun/blank
11
12 datadir = '';
13 %file='test2.asc';
14
15 fid = fopen(blank([datadir, file]), 'r');
16
17 if(fid<0);
18     error(['File ', file, ' does not exist.']);
19 end
20
21 for i=1:3 
22   line = fgetl(fid);
23 end
24
25 % grab #
26 nvar = str2num(line(17:end));
27 for i=1:5
28   line = fgetl(fid);
29 end
30
31 dstruct.fname = line(17:end);
32 line = fgetl(fid);
33 dstruct.mname = line(15:end);
34 for i=1:6
35   line = fgetl(fid);
36 end
37
38 %line=fgetl(fid);
39 line2 = fgetl(fid);
40 ndigits = str2num(fgetl(fid));
41 blpos = [0 find(line==' ') length(line)-1];
42 blpos2 = [0 find(line2==' ') length(line2)-1];
43 for i=1:length(blpos)-2
44   dstruct.vars{i} = line(blpos(i)+1:blpos(i+1));
45   dstruct.varlabs{i} = line2(blpos2(i)+1:blpos2(i+1));
46 end
47
48
49 % data=[];
50 % while 1
51 %   line=fgetl(fid);
52 %   if ischar(line);
53 %       data=[data;
54 %       str2num(line)];
55 %   else;
56 %       break;
57 %   end
58 % end
59
60
61
62 % BEGIN NEW CODE (WStark) /////////////////////////////////////////////////
63 % Use Matlab IMPORTDATA function to read in body of glider ascii file
64 %
65 %  IMPORTDATA(FILENAME, DELIM, NHEADERLINES) loads data from ASCII file
66 %                                            FILENAME, delimited by DELIM,
67 %                                            reading numeric data starting
68 %                                            from line NHEADERLINES+1.
69
70 file = blank(file);  % make sure the filename has no trailing whitespace
71
72 fimport = importdata(file, ' ', 17);
73
74 if(length(fimport)==1)
75 %    if(length(fimport.data)>=1)
76         dstruct.data = fimport.data;
77     else
78         dstruct.data = [];
79 %    end
80 end
81 % END NEW CODE ///////////////////////////////////////////////////////////
82
83
84
85 fclose(fid);
86
87 %d=fscanf(fid,'%f %f %f %f %f %f %f %f %f %f %f %f %f %f\n',[14 inf]);
Note: See TracBrowser for help on using the browser.