function [data] = testing(Curl,sampleCurrh,CurrIncrement,fname)
pause on
%*****************************************************************************
%Initialize Matlab function parameters
	comp = 105; %max out compliance--nothing to harm here
	dvmRange = 10;
	Volts = 0;
%*****************************************************************************
%create and open instrument objects, and echo their names
	lakeshore = visa('ni','gpib0::12::INSTR');
	fopen(lakeshore);
		fprintf(lakeshore,'*IDN?');
	lakeshoreName = fscanf(lakeshore);

	keithley = visa('ni','gpib0::13::INSTR');
	fopen(keithley);
		fprintf(keithley,'*IDN?');
	keithleyName = fscanf(keithley);

	disp('Successfully connected to:');
	disp(lakeshoreName(1:end-2)); %eliminates trailing whitespace
	disp(keithleyName(1:end-2));  %eliminates trailing whitespace
	disp(' ');
%check keithley internal setup--IS THIS NECESSARY AND RIGHT?
		fprintf(keithley,'SOUR:DELT:NVPR?');
	is2182aConnected = fscanf(keithley);
	if is2182aConnected == 1
	disp('WARNING: Voltmeter is not connected.');
	disp(' ');
	end
%*****************************************************************************
%Initialize the 6220
		fprintf(keithley,'*RST');
		fprintf(keithley,('TRAC:CLE');
		fprintf(keithley,'TRAC:POIN 10');
		fprintf(keithley,'SOUR:CURR:COMP %e', comp);
		fprintf(keithley,'SOUR:CURR:RANG:AUTO ON');
%tell the 2182 what to look at				
				fprintf(keithley,'SYST:COMM:SER:SEND "SENS:CHAN 1"');
				%fprintf(keithley,'SYST:COMM:SER:SEND "SENS:FUNC VOLT"');
				fprintf(keithley,'SYST:COMM:SER:SEND "VOLT:RANG 10"');
%set the 2182 triggering loop--copied from 2182 manual, p. E-6
				fprintf(keithley,'SYST:COMM:SER:SEND "*RST"');
				fprintf(keithley,'SYST:COMM:SER:SEND "STAT:PRES;*CLS"');
				fprintf(keithley,'SYST:COMM:SER:SEND "STAT:MEAS:ENAB 512"');
				fprintf(keithley,'SYST:COMM:SER:SEND "*SRE 1"');
				fprintf(keithley,'SYST:COMM:SER:SEND "TRIG:COUN 10"');
%set up 2182 buffer to snarf up 10 readings from the appropriate channel
				fprintf(keithley,'SYST:COMM:SER:SEND "TRAC:CLE"');
				fprintf(keithley,'SYST:COMM:SER:SEND "TRAC:POIN 10"');
				fprintf(keithley,'SYST:COMM:SER:SEND "TRAC:FEED SENS1; FEED:CONT:NEXT"');
				fprintf(keithley,'SYST:COMM:SER:SEND "FORM:DATA ASC"');
				fprintf(keithley,'SYST:COMM:SER:SEND "FORM:ELEM READ"');
%*******************************************************************************	
%The measurement	
	disp('Strike any key...');
	pause
%Set the current and turn on the 6220
		fprintf(keithley,'SOUR:CURR %e',Curl);
		fprintf(keithley,'OUTP ON');
%Take 10 points into the 2182 buffer
				fprintf(keithley,'SYST:COMM:SER:SEND "INIT"');
				pause(.1);
%Calculate the average in the 2182                
				fprintf(keithley,'SYST:COMM:SER:SEND "CALC2:FORM MEAN"');
				fprintf(keithley,'SYST:COMM:SER:SEND "CALC2:IMM"');
%Query the 2182 and read the average into the Matlab variable				
				fprintf(keithley,'SYST:COMM:SER:SEND "CALC2:DATA?"');
%IS THIS HOW TO READ FROM THE SERIALLY CONNECTED 2182 TO THE 6220?
				fprintf(keithley,'SYST:COMM:SER:ENT? "%s"');
%IS THIS HOW TO GET THE RESULT FROM THE 6220?
		fscanf(keithley,'%e',Volts);
	pause(10);
%Reset for the next round			
		fprintf(keithley,'OUTP OFF');
		fprintf(keithley,'SYST:COMM:SER:SEND "TRAC:CLE"');



	disp(Volts);
%*******************************************************************************		
		fprintf(keithley, 'SOUR:CLE');
%save data file to folder as tabs-delimited text file
	cd 'C:\Documents and Settings\Student\My Documents\MATLAB\supercond\data';
%fname = ['sc' datestr(now,30) '.txt'];
	fname = [fname '.txt'];
	dlmwrite (fname,data,'-append','delimiter','\t','precision',10,'newline','pc');
		
%close instrument objects and delete them
	fclose(lakeshore);
	fclose(keithley);
	delete(instrfind);
	disp('supercond.m was successfully closed.')
end