%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %Author: Matthew Brukman, Engineering Physics Department, University of %Wisconsin-Madison, 1500 Engineering Dr., Madison, WI 53706. %This function/script is authorized for use in government and academic %research laboratories and non-profit institutions only. Though this %function has been tested prior to its posting, it may contain mistakes or %require improvements. In exchange for use of this free product, we %request that its use and any issues that may arise be reported to us. %Comments and suggestions are therefore welcome and should be sent to %Prof. Robert Carpick , Engineering Physics %Department, UW-Madison. %Date posted: April 7, 2005 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% function g = batchfd(file_name,endno) %Reads DI Force-Distance files starting from 'filename' and ending with %'endno' and returns a matrix g containing the "Sens Deflection" and pulloff %voltage for each file. Also creates a text file with labeled column %headings containing the same. File extension numbers must be contiguous %Usage: batchfd('m040609.001',010) %Determine the extension of the 1st file and convert from string to number k = findstr('.',file_name); str = file_name(k+1:k+3); no1 = str2num(str); %Extract the base name [pathstr,name,ext,versn] = fileparts(file_name); base_name = fullfile(pathstr,name); en = num2str(endno); %create output matrix g = [0 0]; for (n = (no1):endno) index = num2str(n); if (n < 10) new_ext = strcat('00',index); elseif (n >=10) & (n < 100) new_ext = strcat('0',index); elseif (n >= 100) new_ext = index; end full_name = strcat(name,'.',new_ext); %Run getfd1 and append successive outputs of that program to the %output matrix A = fdbatch(full_name); g = [g;A]; end %Delete inital zeros in output matrix g(1,:) = []; %Create text file with name format basename-1st file #last file#.txt %eg m040609-001-010.txt from usage example above new_file = fullfile(pathstr,[name '-' str '-' new_ext '.txt']); %Add data to output text file fid = fopen(new_file,'w'); label = ['slope(V/nm) ' 'Vpo']; fprintf(fid,'%s\r',label); fprintf(fid, '%4.4d %4.4d\r', g'); fclose(fid); function Databatch = fdbatch(file_name) %These commands find the line numbers in the header file that contain %the following info: # of pixels for each line, % -- positions of the 1st pixel of data for each line, % -- vertical scale factor of PSDvolts/bit, % -- horizontal scale factor of nm/piezo volt, % -- and size of piezo ramp in V. pos_spl = di_header_find(file_name,'\Samps/line'); pos_data = di_header_find(file_name,'\Data offset'); scal_data = di_header_find(file_name,'\@4:Z scale: V [Sens.'); pos_senszscan = di_header_find(file_name,'\@Sens. Zscan'); pos_ramp = di_header_find(file_name,'Ramp size Zsweep'); pos_sensdef = di_header_find(file_name,'Sens. Deflection'); %Open the DI file, move to the various line numbers, and read the numbers %therein to extact the values mentioned above. fid = fopen(file_name,'r'); fseek( fid , pos_spl(2), -1 ); line = fgets(fid); spl = extract_num(line); line = fgets(fid); linno = extract_num(line); fseek(fid, pos_senszscan, -1); line = fgets(fid); senszscan = extract_num( line ); fseek(fid, pos_ramp, -1); line = fgets(fid); ramp = extract_num( line ); fseek(fid,pos_data(1),-1); line = fgets(fid); imag_pos = extract_num(line); fseek(fid,scal_data(1),-1); line = fgets(fid); scaling = extract_num(line); hscale = senszscan*ramp*2^16/spl; % Go to 1st pixel data and start reading fseek(fid,imag_pos,-1); % Convert to PSD (normal force) volts A = scaling*fread(fid,[1 2*spl] ,'int16'); %Split extend/retract data and convert to nm va = A(1:spl); vr = A(spl+1:2*spl); B = hscale*[1:spl]; %Define pulloff voltage as the difference between the minimum PSD voltage %and the PSD signal a number of pixels later -- after transients have decayed %Here number of pixels is chosen to be 1/75 of the total number of data points. %If pulloff is close to the edge of the window, you may need a bigger %number than 75. [minv, i] = min(vr); Vpo = vr(i+round(spl/75))-minv; %Create empty vector with same length as the ext/ret data M = zeros(spl,1); %Fit line to the contact region of retract trace p= -polyfit( B(1:i), vr(1:i), 1); %Put slope of line and pulloff voltage in zeros matrix M(spl)= p(1); M(spl-1)=Vpo; %Create matrix with position [nm], Normal force/extending piezo [V], %Normal force/retracting piezo [V], slope [V/nm], and pulloff [V] data. %Slope (the inverse of sens deflection) is the 1st element of column 4. %Pulloff voltage is the 2nd. Dat = [B; va; vr; M']; Dat = rot90(Dat); Databatch = Dat(1:2,4)';