0001 function [Nskip, Nline, Mmax] = vb_read_vrml_line(fname,key,form)
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018 if ~exist('form','var'), form = '%f'; end;
0019
0020 key_start = key.start ;
0021 key_start2 = key.start2;
0022 key_end = key.end ;
0023 key_braket = key.braket;
0024
0025
0026 fid=fopen(fname);
0027
0028 if fid == -1, fprintf('[%s] can not be opened\n',fname);return; end;
0029
0030 Nskip = 0;
0031
0032 while 1
0033 next_line = fgetl(fid);
0034 Nskip = Nskip+1;
0035 if ~ischar(next_line), break, end;
0036 if ~isempty( strfind(next_line,key_start)), break, end;
0037 end
0038
0039 while 1
0040 next_line = fgetl(fid);
0041 Nskip = Nskip+1;
0042 if ~ischar(next_line), break, end;
0043 if ~isempty( strfind(next_line,key_start2)), break, end;
0044 end
0045
0046
0047
0048 Nline = 0;
0049 Mmax = 0;
0050
0051
0052 ix = strfind(next_line,key_braket);
0053
0054 if ~isempty(ix)
0055 next_line = next_line(ix+1:end);
0056
0057 if ~isempty(next_line)
0058 x = sscanf(next_line,'%f');
0059 if ~isempty(x),
0060 Nline = Nline+1;
0061 end;
0062 end
0063 end
0064
0065 while 1
0066 next_line = fgetl(fid);
0067 if ~ischar(next_line), break, end;
0068
0069 ix = strfind(next_line,key_end);
0070
0071 if ~isempty( ix ),
0072 tmp = next_line(1:ix-1);
0073 x = sscanf(tmp,'%f');
0074 if ~isempty(x), Nline=Nline+1; end;
0075 break,
0076 end;
0077
0078 Nline=Nline+1;
0079 x = sscanf(next_line,form);
0080 Mmax=max(Mmax,length(x));
0081 end
0082
0083 fclose(fid);