forked from gkwt/read-gaussian-cube
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathreadXYZ.m
38 lines (32 loc) · 775 Bytes
/
readXYZ.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
function xyz = readXYZ( filename, nmolec)
%Program written by Gary Tom (LAIR and McGill University), July 13, 2016
% Enter filename of xyz file (leave out ".xyz")
% Return the matrix of XYZ, or -1 if error
% load data file
fid = fopen([filename,'.xyz']);
% remove headers
nline = linecount([filename,'.xyz']);
headers=nline-nmolec;
for i=1:headers
fgetl(fid);
end
% read data
[xyz,count] = fscanf(fid,'%*s %f %f %f',[3,Inf]);
if count/3 ~= nmolec % ensure all molecules are read
xyz = -1;
display('Error in readXYZ() input');
else
xyz = xyz';
end
fclose(fid);
end
function n = linecount(name)
n = 0;
fid = fopen(name);
tline = fgetl(fid);
while ischar(tline)
tline = fgetl(fid);
n = n+1;
end
fclose(fid);
end