function [C,G2,M] = crossref(currdirec,direc)
% [C,G2,M] = crossref(currdirec,[direc])
% Finds the cross reference matrix between all the
% m-files in directories direc and currdirec. Dir has dimension
% [k x m] where k=number of directories and m=max no.
% of string elements to keep the longest dir name
% Sometimes we are only interested in the cross-references
% between m-files within currdirec, that is why direc
% is optional. currdirect is a VECTOR.
% If only currdir then G2=M.
%
M =[];
if nargin ==2
[dd,m]=size(direc);
for i = 1:dd
G = diread(direc(i,:),' ','m');
M = [M;G];
end;
end;
G2 = diread(currdirec,' ','m');
M = [M;G2];
[n1,m1]=size(G2);
[n2,m2]=size(M);
C = zeros(n1,n2);
for j =1:n1
filename = deblank(G2(j,:));
disp(['Checking file ',filename]);
for k =1:n2
fid = fopen([currdirec,'\',filename],'r');
word = lower(deblank(M(k,:)));
word = word(1:length(word)-2);
s = lower(fscanf(fid,'%s'));
res = findstr(s,word);
if length(res) >0
C(j,k) = 1;
end;
fclose(fid);
end;
end;