Code covered by the BSD License  

Highlights from
rd scripts v1.1

image thumbnail
from rd scripts v1.1 by M. A. Hopcroft
A collection of scripts which load the data from contact surface profilometers

p10rd(ufilename,plotmode,verbose)
function p10_data = p10rd(ufilename,plotmode,verbose)
%p10rd - read Tencor P-10 surface profilometer data file
%Load a Tencor P-10 data file, plot, and store as an array of
%  horizontal position and vertical measurement.
%
%P10_DATA = P10RD(UFILENAME,PLOTMODE,VERBOSE)
%
%P10RD reads the data from file UFILENAME.txt, and stores it in the
%workspace variable P10_DATA.
% P10_DATA will have 5 columns:
%  (:,1) is the position data in microns
%  (:,2) is the levelled data in microns
%  (:,3) is the raw deflection data in microns
%  (:,4) is the Wav/A data (unscaled)
%  (:,5) is the Rough/A data (unscaled)
%
% Options:
% If VERBOSE == 0, no messages will be displayed.
% If VERBOSE == 1, the data summary will be displayed. (default)
% If VERBOSE == 2, the file header and data summary will be displayed.
% If PLOTMODE == 0, no data will be plotted.
% If PLOTMODE == 1, the levelled data will be plotted in a new figure. (default)
% If PLOTMODE == 2, a second data plot with the raw data will be shown.
%
% If no input parameters are specified, the program is interactive, and the
% user will be prompted to enter a filename.
%
% NOTE: The function can only read ASCII text data files, not binary data files.
%  The name of the data file must have the extension ".txt", but you do not
%  need include the extension when specifying the file name.
%
% Examples:
%
%  If the data is stored in a text file called "mydata.txt", then:
%
%      p10rd mydata;
%
%  will load the file, plot the data, and print a summary. You can also use:
%
%      p10rd;
%
%  and you will be prompted for the file name. The command:
%
%      profile_data=p10rd('mydata',0,1);
%
%  will open the file mydata.txt, plot the data,
%   and save the data to the variable profile_data in the workspace
%   without printing anything in the command window.
%
%
% M.A. Hopcroft
%      hopcroft at mems dot stanford dot edu
%
% MH MAY2007
% v1.1  re-order input (verbose last)
%       filename w/ or w/o .txt
%
% MH OCT2006
% v1.0 out of beta
%
versionstr='p10rd 1.1';

% handle input arguments - set defaults
% default to verbose mode 1 (summary only)
if nargin < 3
    verbose = 1;
end

% default to plot mode 1 (levelled data only)
if nargin < 2
    plotmode = 1;
end

% get interactive if not being called by another program
if (nargout == 0)
    if (verbose >= 1 & nargin == 0)
        clc;
        fprintf(1, '\n\n  %s\n  %s\n\n', versionstr, 'Read in Tencor P-10 data files');
    end
end


%%%%
% open user's file
if nargin >= 1 % if the user already specified a file, use it
    userfilename=ufilename;
else % if user did not specify the file name, ask for one
    userfilename=input(' Enter the name of the Dektak 3ST .txt file: ','s');
end

% check to see if file exists
cfid=fopen(userfilename);
if cfid== -1
    % try with ".txt"
    userfilename=strcat(userfilename,'.txt');
    cfid=fopen(userfilename);
    if cfid== -1, disp(pwd); error('data file not found in current directory [%s]',userfilename); end
end
fclose(cfid);

% open the file
userfile=fopen(userfilename);
[fpath, fname, fext, fver]=fileparts(userfilename);


%%%%
% process the file header
% the first 5 lines are header information
% read them in and get some data: scan length, number of points, etc.
if verbose == 2
    fprintf(1,'\n\n %s\n %s %s\n\n %s\n\n', versionstr, 'Filename:', fname, 'File header:');
end

% additional linein statements should handle unix/DOS ASCII/ANSI problem
%  [note: investigate this further]

% line 1: filename and date
linein=fgetl(userfile);
if verbose == 2
    fprintf(1,' %s\n', linein);
end

% line 2: number of data points
linein=fgetl(userfile); 
if isempty(linein), linein=fgetl(userfile); end % spurious carriage returns?
if verbose == 2
    fprintf(1,' %s\n', linein);
end
%  because the bastards use tabs instead of spaces, we have to 
%   parse the line to isolate the number at the start of it
lspace=0; % initialize
for i=1:8
    if isspace(linein(i))
        lspace=i;
        break
    end
end
num_points=str2num(linein(1:lspace-1));

% line 3: length of scan (um)
scan_length=fscanf(userfile,'%g',1);
linein=fgetl(userfile); % line 3: length of scan (um)
if isempty(linein), linein=fgetl(userfile); end % spurious carriage returns?
if verbose == 2
    fprintf(1,' %g %s\n', scan_length,'um	Scan length');
end


%line 4: "A per Y count" ??
linein=fgetl(userfile); 
if isempty(linein), linein=fgetl(userfile); end %spurious carriage returns?
if verbose == 2
    fprintf(1,' %s\n', linein);
end

%line 5: column headers
linein=fgetl(userfile);
if isempty(linein), linein=fgetl(userfile); end %spurious carriage returns?

%the position of the data points is now known
% the P-10 appears to add spurious data points, i.e. 700um scan, 702 data points
%  ignore step
stepsize=scan_length/num_points;
%rstep=round(stepsize);
%if rstep-stepsize <= 0.005
%    stepsize=rstep; %the scan length is effectively lengthed slightly
%end


%get data
% data is formatted in 5 columns
% column 1 is horizontal position in um
% column 2 is the "raw data" in Angstroms
% column 3 is the levelled data in Angstroms
% column 4 is "Wav/A" ??
% column 5 is "Rough/A" ?? surface roughness?


for ind=1:num_points %read data from file
    
    %column 1
    [p10_data(ind,1),count]=fscanf(userfile,'%f',1); %data point number #
    %column 2
    [p10_data(ind,3),count]=fscanf(userfile,'%f',1); %raw data   
    %column 3
    [p10_data(ind,2),count]=fscanf(userfile,'%f',1); %levelled data
    %column 4
    [p10_data(ind,4),count]=fscanf(userfile,'%f',1); %Wav/A ??
    %column 5
    [p10_data(ind,5),count]=fscanf(userfile,'%f',1); %Rough/A ??
    
   
end %loop to read data

%adjust data point number to be position
%p10_data(:,1)=p10_data(:,1).*stepsize;
%scale data to um from Angstroms
p10_data(:,2)=p10_data(:,2)./10000; %convert to um
p10_data(:,3)=p10_data(:,3)./10000; %convert to um

% plot
% plot the levelled data
if plotmode >= 1
    
    figure;
    plot(p10_data(:,1),p10_data(:,2));
    title(['p10rd: ', userfilename, ' (levelled data)']);
    % change Interpreter so that the underscores show correctly
    set(get(gca,'Title'),'Interpreter','none');
    xlabel('Scan Length (\mum)');
    ylabel('Profile (\mum)');
    grid on;
    
end

if plotmode == 2
    
    figure;
    plot(p10_data(:,1),p10_data(:,3));
    title(['p10rd: ', fname, ' (raw data)']);
    % change Interpreter so that the underscores show correctly
    set(get(gca,'Title'),'Interpreter','none');
    xlabel('Scan Length (\mum)');
    ylabel('Profile (\mum)');
    grid on;
    
end

%close the file
fclose(userfile);

%print summary data
if verbose >= 1
    
    fprintf(1,'\n');
    fprintf(1,' %s\n', 'Data Summary:');
    fprintf(1,'\n');
    fprintf(1,' %s %s\n', 'File name:', fname);
    
    fprintf(1,'\n');
    
    fprintf(1,' %s %i\n', 'Number of data points read:', num_points);
    fprintf(1,' %s %.1f %s\n', 'Scan Length:', scan_length, 'um');
    fprintf(1,' %s %d %s\n %s %d %s\n %s %.4f %s\n',...
        'Scan Start:', p10_data(1,1), 'um', 'Scan End:',...
        p10_data(end,1), 'um', 'Scan Step (~):', stepsize, 'um');
    
    fprintf(1,'\n');
    
end


Contact us at files@mathworks.com