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';
    data=[0 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);        
        
%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"');
        
%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.0"');
                %pause(1);

                %pause(1);
%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"');
%set the serial format
                fprintf(keithley,'SYST:COMM:SER:SEND "FORM:DATA ASC"');
              
%*******************************************************************************	
%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(10);
%Calculate the average in the 2182                
				fprintf(keithley,'SYST:COMM:SER:SEND "CALC2:FORM MEAN"');
				fprintf(keithley,'SYST:COMM:SER:SEND "CALC2:STAT ON"');
                fprintf(keithley,'SYST:COMM:SER:SEND "CALC2:IMM?"');
%Query the 2182 and read the average into the Matlab variable		
                pause(1);      
%IS THIS HOW TO READ FROM THE SERIALLY CONNECTED 2182?  I GET "-400 QUERY INTERRUPTED". 
%ALSO, DO I HAVE TO CONFIGURE THE BUFFER OF THE 6220 FOR THE OUTPUT OF ENT?
%RIGHT NOW, THIS GIVES "-113 (
				fprintf(keithley,'SYST:COMM:SER:ENT');
                             
	%pause(1);
%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