function [p,t] = clone(filename, position1)

% CLONE clones initial mesh element saved in FILENAME 
% N times. Single copies are located at positions 
% POSITION(1:3,1:N). The total mesh contains N copies 
% of the initial element with the same orientation.

% Usage: clone('plate.mat', position)
%        clone('plate', position)
% where, position is an array of the ORDER (N,3) 
% e.g. [0 0 1 ; 0 0 2 ; 0 0 3 ; 0 0 4].


%Load the data.
load(filename);

position1 = position1';
q=p; 

%Create clones of the initial file at given positions. 

for i = 1:length(position1)

  p = q + repmat(position1(:,i),1,length(p));
    
  %Save the result in separate files..e.g. 
  %clone1.mat, clone2.mat...cloneN.mat
  
  file_name=strcat('clone', num2str(i));
  save (file_name);
  
end

%View the result.

for j  = 1:length(position1)
  hold on
  file_name=strcat('clone', num2str(j));
  viewer (file_name)
  view(45,45)
end

%Clear the position array.
clear position1

