function url = makeWavFileOnWeb(samples,sampRate,bitsPerSamp,dir,file)
% makeWavFileOnWeb   take samples and put on the web as a wave file
%
% Consumes:
%   samples    a vector of numeric samples between -1 and 1 
%   sampRate   scalar number, the number of samples per second (e.g. 44100)
%   bitsPerSamp   scalar number, the number of bits per sample   (e.g. 16)
%   dir        char string, the directory in which to put the file
%                 this directory will be created if it doesn't
%                 exist, and chmod'ed to make it readable
%               directories above this one are assumed to already
%               be readable--if not, they need to be chmod'ed manually.
%   file       char string, the filename for the wave file
%  
% Produces:  
%  
%    url:     the URL of the file that contains the samples
%  
% Example:
%  >> samples = sineWavVector(44100,16,440,3);
%  >> makeWavFileOnWeb(samples,44100,16,'cisc106/10.31','A440_3sec.wav')
%  ans =
%
%      http://copland.udel.edu/~pconrad/cisc106/10.31/A440_3sec.wav
%
%  >>
%  
% P.Conrad for CISC106, 10/31/2007
  

  
  % create the directory
  
  fullDirName = ['~/public_html/' dir];
  system(['mkdir -p ' fullDirName]); 
  
  % write the samples

  fullFileName = [fullDirName '/' file];
  wavwrite(samples,sampRate,bitsPerSamp,fullFileName);
  
  % chmod the directory
  
  system(['chmod -R 755 ' fullDirName]);

  
  % get the userid
    
    [status, userid] = system('whoami');  
    userid = strtrim(userid); % take off the newline character
    
  % make the URL
  
  urlPrefix = ['http://copland.udel.edu/~' userid];

  url = strrep(fullFileName,'~/public_html',urlPrefix);
  
  return;

end % function
