function multiraw2wav( in_name, nchannels, out_name, out_template, fs )
  
  if nargin < 3
    error( [ mfilename ' needs at least 3 input arguments.' ] );
  end
  
  if ~exist( 'out_template', 'var' )
    out_template = '-channel%02d.wav';
  end
  
  if ~exist( 'fs', 'var' )
    fs = 16000;
  end

  %
  
  fid_in = fopen( in_name, 'r', 'l' );
  if fid_in < 0
    error( [ mfilename ' could not read-open "' in_name '".' ] );
  end
  
  % How many samples in the multichannel waveform?

  fseek(fid_in, 0, 'eof');
  nsamples = floor( ftell(fid_in) / (nchannels * 2) );
  fseek(fid_in, 0, 'bof');
  
  % Read data
  
  x = fread( fid_in, [ nchannels  nsamples ], 'int16' );
  x = x.' / 32768;
  
  fclose( fid_in );
  
  disp( sprintf( [ mfilename ': nchannels:%d, nsamples:%d, fs:%d' ], nchannels, nsamples, fs ) );
  
  % Write data
  
  for a = 1:nchannels
  
    out_filename = [ out_name   sprintf( out_template, a ) ];
    
    wavwrite( x(:,a), fs, 16, out_filename );
    
    disp( [ mfilename ' wrote out "' out_filename '".' ] );
    
  end
  