function [Data] = diode_Pt(CurL,CurH,CurInc,fname)
%Ben Nachumi, 2012.  This version of the diode sweep reads just the Pt
%resistance.  It is for those times when the Lakeshore diodes are dead
%(like now).  CurL is the starting current, CurH is the finishing current,
%CurInc is the step.  CurL must be less than CurH.  
pause on
%*****************************************************************************
%Initialize DVM and Matlab function parameters
	comp = 105; %max out compliance--nothing to harm here
	dvmRange = 10;
    testVolts = 0e-3;
	Volts = 0e-3;
    Vav = 0e-3;
    CurR=0e-3;
    newTempl=0;
    Tlav=0;
    Data=[0 0 0];
    NewData = [0 0 0];
    if ishold==0
        hold;
    end
 %*****************************************************************************
%create and open instrument objects, and echo their names
	lakeshore = visa('ni','gpib0::12::INSTR');
	fopen(lakeshore);
		fprintf(lakeshore,'*IDN?');
	lakeshoreName = fscanf(lakeshore);

	keithley1 = visa('ni','gpib0::13::INSTR');
    keithley2 = visa('ni','gpib0::14::INSTR');
	fopen(keithley1);
	fprintf(keithley1,'*IDN?');
    keithley1Name = fscanf(keithley1);
    fopen(keithley2);
    fprintf(keithley2,'*IDN?');
    keithley2Name = fscanf(keithley2);

	disp('Successfully connected to:');
	disp(lakeshoreName(1:end-2)); %eliminates trailing whitespace
	disp(keithley1Name(1:end-2));  
    disp(keithley2Name(1:end-2));
    disp(' ');

%*****************************************************************************
%Initialize the 6220&2182
		fprintf(keithley1,'*RST');
        fprintf(keithley1,'SOUR:CURR:COMP %e', comp);
		fprintf(keithley1,'SOUR:CURR:RANG:AUTO ON');
        fprintf(keithley2,'*RST');	
        fprintf(keithley2,'*CLS');
        
        fprintf(keithley2,'SAMP:COUN 1');
        fprintf(keithley2,'READ?');
        testVolts=fscanf(keithley2,'%e');
        disp(testVolts);

%*******************************************************************************	
%The measurement	
	disp('Strike any key...');
	pause
    CurR=CurL;
    fprintf(keithley1,'OUTP ON');
    while CurR<CurH+CurInc
%Set the current and turn on the 6220
		fprintf(keithley1,'SOUR:CURR %e',CurR);
%Take 10 points 
    Vsum=0;
    Tlsum=0;
    Tusum=0;
    i=0;
        while i<10
        %temp data
        fprintf(lakeshore,'SRDG?a');
        newTempl = fscanf(lakeshore,'%f');
        Tlsum=Tlsum+newTempl;       
		pause(.1);
        fprintf(keithley2,'READ?');
        Volts=fscanf(keithley2,'%e');
        disp(Volts);
        Vsum = Vsum + Volts;
        i=i+1;
        end
    Vav=Vsum/10.0;
    Tlav=Tlsum/10.0;
    disp(CurR);
    disp(Vav);
    plot(Vav,CurR,'*');
    NewData = [Vav, CurR, Tlav];
    Data = [Data; NewData];   
    pause(.1); 
    CurR = CurR + CurInc;
    end
%*******************************************************************************		
		fprintf(keithley1,'OUTP OFF');
        fprintf(keithley1,'SOUR:CLE');
        Data = Data(2:end,:);
        plot(Data(:,1),Data(:,2),'d','Color','r');
%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(keithley1);
    fclose(keithley2);
	delete(instrfind);
	disp('diode_Pt.m was successfully closed.')
end