From 48d2f6551091dd1ac8e913f027d7784dcc585991 Mon Sep 17 00:00:00 2001
From: Laura Nervo <lnervo@esrf.fr>
Date: Tue, 25 Sep 2012 09:27:30 +0000
Subject: [PATCH] gtReadSpaceGroup : improve speed by using cellfun (back to
 version 005)

Signed-off-by: Laura Nervo <laura.nervo@esrf.fr>

git-svn-id: https://svn.code.sf.net/p/dct/code/trunk@800 4c865b51-4357-4376-afb4-474e03ccb993
---
 zUtil_Cryst/gtReadSpaceGroup.m | 38 +++++++++++++++++++++-------------
 1 file changed, 24 insertions(+), 14 deletions(-)

diff --git a/zUtil_Cryst/gtReadSpaceGroup.m b/zUtil_Cryst/gtReadSpaceGroup.m
index 24b0e821..9151423c 100644
--- a/zUtil_Cryst/gtReadSpaceGroup.m
+++ b/zUtil_Cryst/gtReadSpaceGroup.m
@@ -1,7 +1,7 @@
 function [lattice, crystal, herm] = gtReadSpaceGroup(sg)
 % GTREADSPACEGROUP  Read the spacegroup and give the hermann_mauguin symbol
-%     [lattice, crystal, table] = gtReadSpaceGroup(sg)
-%     ------------------------------------------------
+%     [lattice, crystal, herm] = gtReadSpaceGroup(sg)
+%     -----------------------------------------------
 %
 %     INPUT:
 %       sg = spacegroup to look at <double>
@@ -9,11 +9,18 @@ function [lattice, crystal, herm] = gtReadSpaceGroup(sg)
 %     OUTPUT:
 %       lattice = lattice system for this spacegroup
 %       crystal = crystal system for this spacegroup
+%       herm    = hermann-mauguin symbol
 %
-%     Version 005 24/09/2012 by AKing
+%     Version 007 25-09-2012 by LNervo
+%       Improve speed and use cellfun (back to version 005)
+%
+%     Version 006 24/09/2012 by AKing
 %       Remove the unused hashtable, fix the logic for trigonal
 %       spacegroups, return harmann-mauguin symbol
 %
+%     Version 005 21-09-2012 by LNervo
+%       Removed mhashtable
+%                 
 %     Version 004 20-09-2012 by YGuilhem
 %       Now using GT_MATLAB_HOME to determine path to spacegroups.dat
 %
@@ -22,15 +29,16 @@ function [lattice, crystal, herm] = gtReadSpaceGroup(sg)
 
 global GT_MATLAB_HOME
 
-fid=fopen( fullfile(GT_MATLAB_HOME, 'zUtil_Cryst', 'spacegroups.dat' ),'r');
-C=textscan(fid,'%s %d','delimiter','\t','commentstyle','matlab');
+fid = fopen( fullfile(GT_MATLAB_HOME, 'zUtil_Cryst', 'spacegroups.dat' ),'r');
+C = textscan(fid,'%s %*d','delimiter','\t','commentstyle','matlab');
 fclose(fid);
 
-spacegroup=uint8(C{2});
-hermann=C{1};
-% read the hermann mauguin 
-herm=hermann{find(spacegroup==sg)};
+% clean the cell structure
+index = cellfun(@(num) ~isempty(strfind(num, '%')), C{:});
+C{:}(index) = [];
 
+% get the hermann-mauguin symbol list, by removing the space at the end of each cell string
+hermann = cellfun(@(num) strtrim(num), C{:},'UniformOutput', false);
 
 if between(sg,1,2)
     crystal = 'triclinic'; % a ~= b ~= c;  alpha ~= beta ~= gamma ~= 90
@@ -54,11 +62,11 @@ end
 
 if between(sg,143,167)
     crystal = 'trigonal';
-    
-    if ~isempty(strfind(herm,'P')) % hexagonal lattice 
+
+    if ~isempty(strfind(hermann{sg},'P')) % hexagonal lattice 
         % a1 = a2 = a3 ~= c;  alpha = beta = 90; gamma = 120
         lattice = 'hexagonal';
-    elseif ~isempty(strfind(herm,'R')) % rhombohedral lattice
+    elseif ~isempty(strfind(hermann{sg},'R')) % rhombohedral lattice
         % a = b = c;  alpha = beta = gamma ~= 90
         lattice = 'rhombohedral';
     end
@@ -72,8 +80,10 @@ end
 if between(sg,195,230)
     crystal = 'cubic'; % a = b = c;  alpha = beta = gamma = 90
     lattice = 'cubic';
+end        
+        
+if nargout == 3
+    herm = hermann{sg};
 end
 
-        
-        
 end % end of function
-- 
GitLab