%% test read/write functions
fprintf('Testing functionality: ');

Nx				= 1024;
Ny				= 1024;
rawdata		= uint16(rand(Nx,Ny)*(2^12-1));
fname			= 'test.raw';
imwrite_raw12(fname, rawdata);
im				= imread_raw12(fname, Nx, Ny);

if all(size(im) == size(rawdata)) && all(im(:) == rawdata(:))
	fprintf('success\n');
else
	fprintf('failed\n');
end

%% test write  speed
fprintf('Testing write speed: ');

time_elapsed = 0;
n_images		= 1000;
rawdata		= uint16(rand(1024,1024)*(2^12-1));
for idx = 1 : n_images	
	fname		= sprintf('D:/test/im%04d.raw', idx);
	
	tic;
	imwrite_raw12(fname, rawdata);
	
	time_elapsed = time_elapsed + toc;
end

fprintf('took %0.2fs to save %d images (%0.2f fps)\n', time_elapsed, n_images, n_images/time_elapsed);

%% test read speed

fprintf('Testing read speed:  ');

time_elapsed = 0;
n_images			= 1000;
rawdata			= uint16(rand(1024,1024)*(2^12-1));
for idx = 1 : n_images	
	fname		= sprintf('D:/test/im%04d.raw', idx);
	
	tic;
	im			= imread_raw12(fname, Nx, Ny);
	
	time_elapsed = time_elapsed + toc;
end

fprintf('took %0.2fs to read %d images (%0.2f fps)\n', time_elapsed, n_images, n_images/time_elapsed);
