From 1c028cde578a06e3461d4ddc9b07c180e9283a85 Mon Sep 17 00:00:00 2001
From: Laura Nervo <lnervo@esrf.fr>
Date: Mon, 10 Dec 2012 15:01:25 +0000
Subject: [PATCH] Taper analysis with fable : tools to convert output from
 fable to matlab variables

Content:
- gtTaperPar2Mat : reads the .par file output from fable and convert it into a matlab structure
- script_generate_files.sh : bach script to read .map file output from the indexing in fable and creates several .txt files with the information separated
- gtTaperConvertFableOutputToDCT : read .txt files and creates a similar "grain" structure (as output from INDEXTER)

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

git-svn-id: https://svn.code.sf.net/p/dct/code/trunk@957 4c865b51-4357-4376-afb4-474e03ccb993
---
 zUtil_Taper/gtTaperConvertFableOutputToDCT.m | 100 +++++++++++++++++++
 zUtil_Taper/gtTaperPar2Mat.m                 |  33 ++++++
 zUtil_Taper/script_generate_files.sh         |  58 +++++++++++
 3 files changed, 191 insertions(+)
 create mode 100644 zUtil_Taper/gtTaperConvertFableOutputToDCT.m
 create mode 100644 zUtil_Taper/gtTaperPar2Mat.m
 create mode 100755 zUtil_Taper/script_generate_files.sh

diff --git a/zUtil_Taper/gtTaperConvertFableOutputToDCT.m b/zUtil_Taper/gtTaperConvertFableOutputToDCT.m
new file mode 100644
index 00000000..439e1525
--- /dev/null
+++ b/zUtil_Taper/gtTaperConvertFableOutputToDCT.m
@@ -0,0 +1,100 @@
+function grain = gtTaperConvertFableOutputToDCT(pathtofile)
+% grain = gtTaperConvertFableOutputToDCT(pathtofile)
+
+
+if exist(pathtofile,'file') && ~isempty(pathtofile)
+    [fable_dir, map_file, ext] = fileparts(pathtofile);
+    map_file = [map_file ext];
+else
+    fable_dir = 'workspace/grid';
+    map_file = 'all_smalls_fitted_2.map';
+end
+
+% to be run in the analsysis directory
+bash_script = fullfile('/users',getenv('USER'),'matlabDCT','zUtil_Taper','script_generate_files.sh');
+cmd = [bash_script ' ' fullfile(fable_dir,map_file)];
+[~,msg]=unix(cmd);
+disp(msg)
+
+fid = fopen(fullfile(fable_dir,'rodrigues.txt'));
+C = textscan(fid, '%*s %f %f %f');
+fclose(fid);
+A = cell2mat(C);
+
+fid = fopen(fullfile(fable_dir,'centers.txt'));
+C = textscan(fid, '%*s %f %f %f');
+fclose(fid);
+A2 = cell2mat(C);
+
+fid = fopen(fullfile(fable_dir,'npeaks.txt'));
+C = textscan(fid, '%*s %d');
+fclose(fid);
+A3 = cell2mat(C);
+
+format longg
+fid = fopen(fullfile(fable_dir,'sum_of_all.txt'));
+C = textscan(fid, '%f64');
+fclose(fid);
+A4 = cell2mat(C);
+
+fid = fopen(fullfile(fable_dir,'medians.txt'));
+C = textscan(fid, '%f64');
+fclose(fid);
+A5 = cell2mat(C);
+
+fid = fopen(fullfile(fable_dir,'mins.txt'));
+C = textscan(fid, '%f64');
+fclose(fid);
+A6 = cell2mat(C);
+
+fid = fopen(fullfile(fable_dir,'maxs.txt'));
+C = textscan(fid, '%f64');
+fclose(fid);
+A7 = cell2mat(C);
+
+fid = fopen(fullfile(fable_dir,'means.txt'));
+C = textscan(fid, '%f64');
+fclose(fid);
+A8 = cell2mat(C);
+
+fid = fopen(fullfile(fable_dir,'stds.txt'));
+C = textscan(fid, '%f64');
+fclose(fid);
+A9 = cell2mat(C);
+
+fid = fopen(fullfile(fable_dir,'ns.txt'));
+C = textscan(fid, '%d');
+fclose(fid);
+A10 = cell2mat(C);
+
+grain = [];
+
+for ii = 1:length(A)
+    grain{ii}.ind      = ii;
+    grain{ii}.R_vector = A(ii,:);
+    grain{ii}.g        = Rod2g( grain{ii}.R_vector );
+    grain{ii}.angles   = gtMathsRod2Euler( grain{ii}.R_vector );
+    grain{ii}.center   = A2(ii,:);
+    grain{ii}.npeaks   = A3(ii);
+    grain{ii}.allint   = A4(ii);
+    grain{ii}.median   = A5(ii);
+    grain{ii}.min      = A6(ii);
+    grain{ii}.max      = A7(ii);
+    grain{ii}.mean     = A8(ii);
+    grain{ii}.std      = A9(ii);
+    grain{ii}.n        = A10(ii);
+    grain{ii}.stat.intmean  = double(grain{ii}.allint);
+    grain{ii}.stat.bbxsmean = 1;
+    grain{ii}.stat.bbysmean = 1;
+    grain{ii}.R_onedge = false;
+end
+
+rvec = gtIndexAllGrainValues(grain,'R_vector',[],1:3,[]);
+rotmat = gtMathsRod2RotMat( rvec );
+
+for ii=1:length(grain)
+    grain{ii}.rotmat   = rotmat{ii};
+end
+
+end % end of function
+
diff --git a/zUtil_Taper/gtTaperPar2Mat.m b/zUtil_Taper/gtTaperPar2Mat.m
new file mode 100644
index 00000000..c97f7ef5
--- /dev/null
+++ b/zUtil_Taper/gtTaperPar2Mat.m
@@ -0,0 +1,33 @@
+function parameters = gtTaperPar2Mat(parfile)
+
+fid = fopen(parfile);
+C = textscan(fid, '%s %s');
+fclose(fid);
+index = [];
+for ii=1:length(C{2})
+    patt=regexp(C{2}{ii},'[0-9.e-]','match');
+    C{3}{ii} = patt;
+    if length(C{2}{ii})~=length(C{3}{ii})
+        index(end+1) = ii;
+    end
+end
+
+for ii=index
+    C{1}(ii) = [];
+    C{2}(ii) = [];
+    C{3}(ii) = [];
+end
+
+for ii=1:length(C{2})
+    C{4}{ii} = str2num(C{2}{ii});
+end
+
+final = [];
+
+for ii=1:length(C{2})
+    final.(C{1}{ii}) = C{4}{ii};
+end
+
+parameters = final;
+
+end
diff --git a/zUtil_Taper/script_generate_files.sh b/zUtil_Taper/script_generate_files.sh
new file mode 100755
index 00000000..6b7bd1ad
--- /dev/null
+++ b/zUtil_Taper/script_generate_files.sh
@@ -0,0 +1,58 @@
+#!/bin/bash
+# input: fabledir/filename.map 
+
+CDIR="$PWD"
+
+# define usage function
+usage(){
+        echo "Usage: $0 fabledir/filename.map"
+        exit 1
+}
+
+# define is_file_exits function
+# $f -> store argument passed to the script
+exist(){
+        local f="$1"
+        [[ -f "$f" ]] && return 0 || return 1
+}
+
+# invoke  usage
+# call usage() function if filename not supplied
+[[ $# -eq 0 ]] && usage
+
+# less ~vaughan/code/Image/code/image_math.c
+# source /sware/exp/fable/bin/fable.bash 
+
+#BPATH="/data/id19/graintracking/DCT_Analysis/RD4_15N_taper_"
+#DPATH="$BPATH/workspace/grid"
+
+# Invoke is_file_exits
+if ( exist "$1" ) && [ -f "$2"];
+then
+  echo "File found"
+  DPATH=`dirname $1`
+  FILE=`basename $1`
+
+  cd $DPATH
+
+  less $FILE | grep Rod > rodrigues.txt
+  less $FILE | grep trans > centers.txt
+  less $FILE | grep npks > npeaks.txt
+  less $FILE | grep intensity > intensities.txt
+  less intensities.txt | awk -F", " '{print $1}' | awk -F"= " '{print $2}' > sum_of_all.txt
+  less intensities.txt | awk -F", " '{print $2}' | awk -F"= " '{print $2}' > medians.txt
+  less intensities.txt | awk -F", " '{print $3}' | awk -F"= " '{print $2}' > mins.txt
+  less intensities.txt | awk -F", " '{print $4}' | awk -F"= " '{print $2}' > maxs.txt
+  less intensities.txt | awk -F", " '{print $5}' | awk -F"= " '{print $2}' > means.txt
+  less intensities.txt | awk -F", " '{print $6}' | awk -F"= " '{print $2}' > stds.txt
+  less intensities.txt | awk -F", " '{print $7}' | awk -F"= " '{print $2}' > ns.txt
+
+  echo "The following txt files have been created in:"
+  echo $DPATH
+  ls -ltr *.txt
+  cd $CDIR
+
+else
+  echo "File not found"
+fi
+
-- 
GitLab