Skip to content

Instantly share code, notes, and snippets.

@tonyfast
Created June 13, 2014 18:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tonyfast/ceac9c76514c1a231ea7 to your computer and use it in GitHub Desktop.
Save tonyfast/ceac9c76514c1a231ea7 to your computer and use it in GitHub Desktop.
Reads Elastic Strain Files for MKS calibration data
function [ M, P, file_handle] = Read_Elastic_Strain_Files( directory_location, samp_num )
responseOI = 1;
% this function is used for reconstruction and calibration
evalin( 'base', 'method = ''Elastic'';');
[ dirtemp ] = textscan( directory_location, '%s','delimiter','\\');
directory_str = dirtemp{1}{end};
file_handle = directory_str;
top_directory = regexprep( directory_location, directory_str, '');
%%
H = 100;
if strcmp( directory_str, 'padded_15_5_1')
map_handle = 'padded_15_5_1.map';
contrast = 5;
S = [15 15 15];
elseif strcmp( directory_str, 'padded_15_5_2')
map_handle = 'tailored15.map';
contrast = 5;
S = [15 15 15];
elseif strcmp( directory_str, 'padded_45_5_1')
map_handle = 'padded_45_4_1.map';
contrast = 5;
S = [45 45 45];
elseif strcmp( directory_str, 'padded_45_10_1')
map_handle = 'padded_45_4_1.map';
contrast = 10;
S = [45 45 45];
elseif strcmp( directory_str, 'Contrast6')
map_handle = 'Elements2.map';
contrast = 6;
S = [21 21 21];
elseif strcmp( directory_str, 'Contrast2')
map_handle = 'Contrast2.map';
contrast = 2;
S = [15 15 15];
elseif strcmp( directory_str, 'Contrast10')
map_handle = 'Elements2_10.map';
contrast = 10;
S = [21 21 21];
end
assignin( 'base', 'H', H * [ 1 contrast]);
assignin( 'base', 'S', S);
assignin( 'base', 'D', sum(S~=1));
map_location = [ top_directory, '\', map_handle ];
%% read in the microstructure information
fo = fopen( map_location, 'r');
for ii = 0 : (samp_num - 1)
[~] = fgetl( fo );
end
s = fgetl( fo );
fclose( fo );
% get values after the semicolon
[~,s] = strtok(s,':');
% remove the semicolon
s = s( 2:end);
C = textscan(s, '%u','delimiter',',');
% indexes of active voxels
Mind = C{1};
% the microstructure information
M = zeros( S );
M( Mind ) = 1;
base_young = 100;
M(M==1) = base_young * contrast;
M(M==0) = base_young;
%%
%% read in the response information
response_dir = ['\0\0\',num2str(floor(samp_num./1000)), '\',num2str(floor((samp_num-floor(samp_num./1000)*1000)./100) ),'\'];
response_fil = [response_dir, 'DELTA_',num2str( samp_num), '.dat.txt'];
response_location = [ directory_location, response_fil];
fmt_str = '%*f %*f %*f %*f %*f %*f';
ast_pos = 2 : 4 : numel( fmt_str );
fmt_str( ast_pos( responseOI ) ) = [];
fmt_str = '%f';
fo = fopen( response_location, 'r');
P = zeros( [ S numel( responseOI )] );
P(:) = fscanf( fo, fmt_str, [numel( responseOI ) prod(S) ])';
fclose( fo );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment