Home > functions > device > vivid > vb_read_vrml_line.m

vb_read_vrml_line

PURPOSE ^

Read Coordinate frpm XML-file

SYNOPSIS ^

function [Nskip, Nline, Mmax] = vb_read_vrml_line(fname,key,form)

DESCRIPTION ^

 Read Coordinate frpm XML-file
 
 Coordinate3 {
    point [ 
        9.06 87.16 -851.32,
        10.02 87.13 -851.20,
            ...
    ]
    point [ 9.06 87.16 -851.32,
        10.02 87.13 -851.20,
            ...
       76.95 -72.55 23.16 ]

 Copyright (C) 2011, ATR All Rights Reserved.
 License : New BSD License(see VBMEG_LICENSE.txt)

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function    [Nskip, Nline, Mmax] = vb_read_vrml_line(fname,key,form)
0002 % Read Coordinate frpm XML-file
0003 %
0004 % Coordinate3 {
0005 %    point [
0006 %        9.06 87.16 -851.32,
0007 %        10.02 87.13 -851.20,
0008 %            ...
0009 %    ]
0010 %    point [ 9.06 87.16 -851.32,
0011 %        10.02 87.13 -851.20,
0012 %            ...
0013 %       76.95 -72.55 23.16 ]
0014 %
0015 % Copyright (C) 2011, ATR All Rights Reserved.
0016 % License : New BSD License(see VBMEG_LICENSE.txt)
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 % check line number
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 % from now on data is written
0047 % Count number of data lines
0048 Nline  = 0;
0049 Mmax   = 0;
0050 
0051 % Check case such as [ 12, 13,
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);

Generated on Tue 27-Aug-2013 11:46:04 by m2html © 2005