/
read_wfile.m
60 lines (46 loc) · 1.16 KB
/
read_wfile.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
54
function [w,v] = read_wfile(fname)
%
% [w,v] = read_wfile(fname)
% reads a vector into a binary 'w' file
% fname - name of file to write to
% w - vector of values to be written
% v - vector of vertex indices (0-based)
%
% See also write_wfile.
%
%
% read_wfile.m
%
% Original Author: Bruce Fischl
%
% Copyright © 2021 The General Hospital Corporation (Boston, MA) "MGH"
%
% Terms and conditions for use, reproduction, distribution and contribution
% are found in the 'FreeSurfer Software License Agreement' contained
% in the file 'LICENSE' found in the FreeSurfer distribution, and here:
%
% https://surfer.nmr.mgh.harvard.edu/fswiki/FreeSurferSoftwareLicense
%
% Reporting: freesurfer@nmr.mgh.harvard.edu
%
w = [];
v = [];
if(nargin ~= 1)
fprintf('[w,v] = read_wfile(fname)\n');
return;
end
% open it as a big-endian file
fid = fopen(fname, 'rb', 'b') ;
if (fid < 0)
str = sprintf('could not open w file %s.', fname) ;
error(str) ;
end
fread(fid, 1, 'int16') ;
vnum = fread3(fid) ;
w = zeros(vnum,1) ;
v = zeros(vnum,1) ;
for i=1:vnum
v(i) = fread3(fid) ; % vertex number (0-based)
w(i) = fread(fid, 1, 'float') ; % vertex value
end
fclose(fid) ;