Permalink
Switch branches/tags
Nothing to show
Find file Copy path
Fetching contributors…
Cannot retrieve contributors at this time
105 lines (93 sloc) 2.35 KB
function topo = read_gwyddion_ascii(filefullpath, varargin)
%% Read topography data as exported by Gwyddion.net software
% Export with header lines !!!
% author: c.zambaldi@mpie.de
% Data format from Gwyddion
% - channel: 'Height'
% - width: 5
% - height: 5
% - FEM_mode: 0
% - data: [512x512 double]
% - nX: 512
% - nY: 512
% - resX: 0.0098
% - resY: 0.0098
% - linX: [1x512 double]
% - linY: [1x512 double]
% - max: 1.9029e-06
% - min: -7.2871e-07
% - data_range: 2.6316e-06
% - X: [512x512 double]
% - Y: [512x512 double]
if nargin < 1
TESTING = 1;
[fname, pname] = uigetfile({'*.txt;*_tip.mat'},'Choose a file');
cd(pname)
filefullpath = fullfile(pname, fname);
else
TESTING = 0;
end
fid = fopen(filefullpath,'rt');
if fid == -1
commandwindow;
error(sprintf('Couldn''t open file at %s',filefullpath));
end
iL = 0; % line number
iY = 0;
topo = struct();
while feof(fid)~=1 % read until end of file
ln = fgetl(fid);
iL = iL+1;
if iL < 5
if ln(1) == '#'
if strfind(ln,'# Channel:')
cln = ln;
channel = sscanf(cln,'# Channel: %s');
topo.channel = channel;
elseif strfind(ln,'Width:')
wln = ln;
width = sscanf(wln,'# Width: %f unit');
topo.width = width;
elseif strfind(ln,'Height:')
hln = ln;
height = sscanf(hln,'# Height: %f unit');
topo.height = height;
end
else
error(' No header lines found');
end
else
iY = iY + 1;
data(iY,:) = sscanf(ln,'%e');
end
end
fclose(fid);
if any(strfind(topo.channel,'FEM'))
topo.FEM_mode = 1;
%data = flipud(data);
else
topo.FEM_mode = 0;
end
data = flipud(data); % Gwyddion writes data flipped in the Matlab sense
topo.data = data;
topo.nX = size(data,2);
topo.nY = size(data,1);
topo.resX = width/topo.nX;
topo.resY = height/topo.nY;
topo.linX = linspace(-width/2, width/2, topo.nX);
topo.linY = linspace(-height/2, height/2, topo.nY);
%% Datarange
topo.max = max(max(topo.data));
topo.min = min(min(topo.data));
topo.data_range = topo.max - topo.min;
[X,Y] = meshgrid(topo.linX,topo.linY);
topo.X = X;
topo.Y = Y;
topo.X_ori = topo.X;
topo.Y_ori = topo.Y;
if TESTING
figure;
topo_plot(topo)
set(gcf,'name','original data');
end
return