% Write Memory
% 
% This function will read words from a file, and do all the necessary
  % work to store them, in a folder.
  % Since the address space is so big, we break up the problem into
% intermediate portions and we run each input on each smaller section.

  function [aSpace,storage,C_SetSizes] = createMemory(n,Nprime,r,inputFileName)

    aSpace = buildAddressSpace(n,Nprime);
    
        
    C_SetSizes = zeros(Nprime,1);
    storage = zeros(Nprime,n);

     % For each input 
    fidinput = fopen(inputFileName);
    
      
input = fscanf(fidinput,'%g',[1 n]);

 
while( not(isempty(input)) )
      
     % dfea = distance from each address
     dfea = zeros(1,Nprime);   
     
     for i = 1:Nprime
       dfea(i) = hamdist(aSpace(i,1:n),input);
     end
     
     S = find(dfea - r < 0);    
     
     for j=1:length(S)
         
       storage(S(j),1:n) = storage(S(j),1:n) + input;
       C_SetSizes(S(j)) = C_SetSizes(S(j)) + 1;
	 
     end
	 
       input = fscanf(fidinput,'%g',[1 n]);

end
     
     fclose(fidinput);




       


