function get_cdf_wrapper( filelist, refCDFname )

%%%%%%%%%%%%
% read in I/O
% list
fid = fopen(filelist);
L1  = textscan(fid,'%s');
fclose(fid);

%%%%%%%%%%%%
% successively process
% the files
inList = L1{1}; 
refCDF = []; 

while_var = 1;
maxNumPts = 8000000;

k = 1;

if ~isempty(inList) == 1 %check if the file list is empty

	while while_var

		inFile           = strtrim( inList{ k } );
		[ currFile, fs ] = readsph( inFile );	
		currFile         = 0.98 * currFile / max( abs( currFile ) );	
		refCDF           = [ refCDF; currFile ];

		currLen = length( refCDF );
	
		fprintf( '%d samples accumulated\n', currLen );

		if currLen > maxNumPts
			while_var = 0;
		end
	
		k = k + 1;
	end
end

fprintf( 'sorting...' );

refCDF = sort( refCDF );

fprintf( 'done\n' );

wavwrite( refCDF, fs, refCDFname );
