File: data_parse.m

package info (click to toggle)
apbs 3.4.1-7
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 199,188 kB
  • sloc: ansic: 284,988; cpp: 60,416; fortran: 44,896; xml: 13,895; sh: 13,838; python: 8,105; yacc: 2,922; makefile: 1,428; f90: 989; objc: 448; lex: 294; awk: 266; sed: 205; java: 134; csh: 79
file content (24 lines) | stat: -rw-r--r-- 710 bytes parent folder | download | duplicates (47)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
function data = data_parse(filename, dime)
% e.g. data_parse('pot8.dx', [65 65 65])

disp([ filename '...'])

file_id = fopen(filename, 'rt');
flag=[];
while isempty(flag)
    line=fgetl(file_id);
    flag=strfind(line, 'data follows');
end

data_column=99999*zeros(1,prod(dime));  % 99999 is a flag value.  All values should be replaced.
index=1; % next empty memory location in data_column
for counter=1:ceil(prod(dime)/3)
    line=fgetl(file_id);
    [A, count, errmsg, nextindex]=sscanf(line, '%e');
    data_column(index:(index+length(A)-1))=A;
    index=index+length(A);
end
fclose(file_id);

%% reshape data column into a 3D array
data=permute(reshape(data_column, dime(3), dime(2), dime(1)), [3  2 1]);