function plot_prewired_structure(MNlayers,Nlayers,NNeurons_per_layer,Ninputs,neurons)
%	plot input lines
for i=1:size(neurons,2)
   row=cat(2,neurons{i}.presynaptic_neurons{:});
   if isempty(row)
      row=[ 0 0 0 0 0];
   elseif size(row,2)==1
      row=[row 0 0 0 0];
   elseif size(row,2)==2
      row=[row 0 0 0];
   elseif size(row,2)==3
      row=[row 0 0];   
   elseif size(row,2)==4
      row=[row 0];
   end
   input_links(i,:)=row; 
end;
nnplot(MNlayers,Nlayers,NNeurons_per_layer,Ninputs,input_links,0,'r');

% plot clock lines
row=[];
input_links=[];
for i=1+NNeurons_per_layer:size(neurons,2)
   if (isempty(neurons{i}.scf_neurons))
      row=[ 0 0];
   else
      row=cat(2,neurons{i}.scf_neurons{:});
      if size(row,2)==1
         row=[row 0];
      end
   end
   input_links(i,:)=row; 
end;
nnplot(MNlayers,Nlayers,NNeurons_per_layer,Ninputs,input_links,1,':');


%ploting structure of 
function nnplot(MNlayers,maxlayers,mnpl,inports,links,r,s)

la=[1:inports];
plot(0,.9,'');hold on;
plot(MNlayers,0.9,'');
plot(0,la,'>');hold on;
la=[1:mnpl];
R=sqrt(2)/5;
laraise=la+R*ones(1,mnpl);
cnt=inports;
sz=size(links);
inputs=sz(2);
ep=0.05;
for i=1:maxlayers
   if rem(i,2)==1
      plot(i,laraise,'o');
   else
      plot(i,la,'o');
      end;
   for k=1:mnpl
      cnt=cnt+1;
      for m=1:inputs
         if links(cnt,m)>0
            pos=links(cnt,m);
            if pos<=inports
               x=[0,i];
               xx=0;
               y=[pos,k];
            else
               pos=pos-inports;
               xx=ceil(pos/mnpl);
               y=pos-(xx-1)*mnpl;               
               x=[xx,i];
               y=[y,k];
            end ;
            if rem(i,2)==1
               y=y+[0 R];
            end;
            if rem(xx,2)==1
               y=y+[R 0];
            end;
           if r==0 
                plot(x,y,s);
            else
                x=[x(1),(2*x(1)+x(2))/3,(x(1)+2*x(2))/3,x(2)];
                y=[y(1),(2*y(1)+y(2))/3+ep,(y(1)+2*y(2))/3+ep,y(2)];
                plot(x,y,s);
            end;
         end;
      end;
   end;
end;



