-
Notifications
You must be signed in to change notification settings - Fork 0
/
loadZScan.m
executable file
·54 lines (42 loc) · 1.3 KB
/
loadZScan.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
function zData = loadZScan(fInput)
%loadZScan Loads Z-scan data
% ZDATA = loadZScan() Opens a file dialog and returns Z-scan data. Dimension 1
% contains sampled sensor signal. Due to memory limitations ZDATA is returned
% in INT8 format.
%
% ZDATA = loadZScan(FILENAME) Returns rata from a specified file.
%% get and open the file reference
if nargin==0
[fName,fPath,~] = uigetfile({'*.saz', 'KSI V8 Z-scan files (*.saz)'; '*.*', 'All Files (*.*)'});
else
[fPath,fName,fExt] = fileparts(fInput);
fName = [fName fExt];
end
fFullPath = fullfile(fPath,fName);
fid = fopen(fFullPath,'r');
%% get scan parameters from header
% find file size
fseek(fid, 0, 'eof');
fSize = ftell(fid);
% fixed header size
headerSize = 496;
idxXdim = 480;
idxYdim = 484;
% calculate Z-scan size
scanSize(1:2) = getDimensions(fid,[idxXdim,idxYdim]);
scanSize(3) = (fSize - headerSize)/prod(scanSize(1:2));
%% load and reshape the scan data
fseek(fid,headerSize,'bof');
fData = fread(fid,prod(scanSize),'int8=>int8');
zData = reshape(fData,[scanSize(3),scanSize(1),scanSize(2)]);
% close file reference
fclose(fid);
% helper functions
function [xy] = getDimensions(fid,idxsDim)
xy = [];
for idxDim = idxsDim
fseek(fid,idxDim,'bof');
xy = [xy,fread(fid,1,'int16=>double')]; %#ok<AGROW>
end
end
end