function write_text_mat( filename, m, printftype )
  
  if nargin < 2
    error( [ mfilename ' needs at least 2 input arguments.' ] );
  end
  
  if ~exist( 'printftype', 'var' )
    printftype = '%.10e';
  end
  
  % Try to write-open
  fid = fopen( filename, 'wt' );
  if fid < 0 
    error( [ mfilename ' could not write-open "' filename '".' ] );
  end
  
  % Find how many numbers per line (dim)
  dim = size( m, 2 );
  
  % Prepare template
  a_template = repmat( [ printftype(:).' ' ' ], 1, dim );
  a_template = [ a_template( 1:end-1 ) '\n' ];
  
  % Write out
  fprintf( fid, a_template, m.' );
  
  fclose( fid );
  