function [ l ] = avld( D , quiet)
%AVLD  calculates the average path length
%
%   AVLD(D)  returns the average path length of the network
%       given by its distance matrix D
%
%       Note: If the network is not connected a note is issued
%
%  Last change:  10/2/2005 - Florian Knorn

if nargin < 1
	error('Please input a distance matrix !');
else
	if nargin ~= 2
		quiet = false;
	end
end
if islogical( D )
	error('How can D be of type LOGICAL ? Adjacency matrix ?');
end

D = unpenalize(D); % remove (potential) penalty-entries

l = mean(nonzeros(D));

if ~quiet
	n = size(D,1);
	if length(nonzeros(D)) < n*(n-1)
		disp('Graph is not connected !');
	end
end