function [segment n_length n_nodes nodes] = read_bom(filenm)

%  [seg_name seg_length seg_n_nodes seg_nodes]

cmd = ['grep -e ^[0-9][0-9][0-9][0-9] ' filenm '.bom > foo'];
system(cmd);

data = dlmread('foo');
N = size(data)(1);
n_length = data(:,3);
n_nodes = data(:,4);
nodes = data(:,7);

fid = fopen('foo','r');

for n = 1:N
 line = fgetl(fid);
 [seg remain] = strtok(line);
 segment{n} = strtok(remain);
end
fclose(fid);


fid = fopen([filenm '.lay'],'w');
field_width = 17;
str = sprintf('     Element             Length       Nodes');  disp(str); fprintf(fid,'%s\n',str);
fmt_str = ['%d    %-' num2str(field_width) 's     %4.1f m      %d - %d'];
str = sprintf(fmt_str,N+1,'Buoy',0,nodes(1),nodes(1)); disp(str); fprintf(fid,'%s\n',str);
for n = 1:N
  str = sprintf(fmt_str,N-n+2,segment{n},n_length(n),nodes(n),nodes(n)-n_nodes(n)+1); disp(str);fprintf(fid,'%s\n',str);
end
str = sprintf(fmt_str,1,'Anchor',0,1,1); disp(str); disp(''); fprintf(fid,'%s\n\n',str);

str = ['  Total Length = ' num2str(sum(n_length)) ' m'];  disp(str); fprintf(fid,'%s\n',str);

fclose(fid);


%
