Skip to content
Snippets Groups Projects
Commit 68287758 authored by Laura Nervo's avatar Laura Nervo
Browse files

gtReadTextFile : generalised use of reading text files... Now we can pass...

gtReadTextFile : generalised use of reading text files... Now we can pass inputs as varargin to specify options for textscan

Signed-off-by: default avatarLaura Nervo <laura.nervo@esrf.fr>
parent 4bec7dbf
No related branches found
No related tags found
No related merge requests found
......@@ -58,14 +58,14 @@ cmd = sprintf('%s %s %f %f %d %s %s', ...
[~, msg] = gtPythonCommand(cmd, true); disp(msg);
% read the full list of reflections
[~,Cmat] = gtReadTextFile([filename 'all.txt'],'%f %f %f %f','\n','#',[1 3]);
[~,Cmat] = gtReadTextFile([filename 'all.txt'],'%f %f %f %f',[1 3],'Delimiter','\n','CommentStyle','#');
% extracting information
hklsp = Cmat(:,1:3);
sinthlsp = Cmat(:,4);
% read the full list of reflections
[~,Cmat] = gtReadTextFile([filename 'unique.txt'],'%f %f %f %f','\n','#',[1 3]);
[~,Cmat] = gtReadTextFile([filename 'unique.txt'],'%f %f %f %f',[1 3],'Delimiter','\n','CommentStyle','#');
% extracting information
hkl = Cmat(:,1:3);
......
......@@ -44,10 +44,10 @@ script_file = fullfile(GT_MATLAB_HOME, 'zUtil_Python', 'symmetry_operators_list.
disp(msg);
% read produced files
permN = gtReadTextFile(['perm_' crystal_system '.txt'],'%f %f %f',' ','#',[3 3]);
rotN = gtReadTextFile(['rot_' crystal_system '.txt'],'%f %f %f',' ','#',[3 3]);
sg_rotN = gtReadTextFile(['sg_rot_' crystal_system '.txt'],'%f %f %f',' ','#',[3 3]);
sg_transN = gtReadTextFile(['sg_trans_' crystal_system '.txt'],'%f %f %f',' ','#',[1 3]);
permN = gtReadTextFile(['perm_' crystal_system '.txt'],'%f %f %f',[3 3],'Delimiter',' ','CommentStyle','#');
rotN = gtReadTextFile(['rot_' crystal_system '.txt'],'%f %f %f',[3 3],'Delimiter',' ','CommentStyle','#');
sg_rotN = gtReadTextFile(['sg_rot_' crystal_system '.txt'],'%f %f %f',[3 3],'Delimiter',' ','CommentStyle','#');
sg_transN = gtReadTextFile(['sg_trans_' crystal_system '.txt'],'%f %f %f',[1 3],'Delimiter',' ','CommentStyle','#');
symm = struct('g3', rotN, 'perm', permN);
if nargout == 2
......
function [Ccell,Cmat] = gtReadTextFile(filename, formatS, delimiter, comments, minsize)
function [Ccell,Cmat] = gtReadTextFile(filename, formatS, minsize, varargin)
% GTREADTEXTFILE Reads textfiles into matrices
%
% [Ccell, Cmat] = gtReadTextFile(filename, format, delimiter, comments, minsize)
% ------------------------------------------------------------------------------
% [Ccell, Cmat] = gtReadTextFile(filename, formatS, minsize, varargin)
% ------------------------------------------------=-------------------
%
% INPUT:
% filename = text file to be read <string>
% formatS = format pattern as in fprintf <string> i.e. '%f %f %f'
% delimiter = character as delimiter i.e. ' '
% comments = character as comments i.e. '#'
% minsize = minimum size of element to be consider as object (like
% matrix 3x3 or vector 1x3)
% varargin = optional argument for textscan
%
% OUTPUT:
% Ccell = content of the text file (read as columns) <cell>
% Cmat = read matrix <double>
%
% Example:
% [Ccell,Cmat] = gtReadTextFile('reflections_all.txt','%f %f %f %f',[1 3],'Delimiter','\n','CommentStyle','#');
%
% Version 001 03-12-2012 by LNervo
fid = fopen(filename,'r');
C = textscan(fid, formatS,...
'Delimiter', delimiter,...
'CommentStyle', comments);
C = textscan(fid, formatS, varargin{:});
fclose(fid);
Cmat = cell2mat(C);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment