-
Notifications
You must be signed in to change notification settings - Fork 3
/
T1rho_slt0.m
111 lines (110 loc) · 3.09 KB
/
T1rho_slt0.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
%#######################################################################
%
% * T1rho Spin Lock Time 0 Program *
%
% M-File which reads a dicom_lst MAT file and copies the zero
% ms spin lock time files from the T1rho series to separate
% directories. The new directory(ies) is(are) DICOM_*, where *
% is(are) the series number(s). Also, creates a command/shell file
% with the commands to copy the files.
%
% NOTES: 1. MAT file dicom_lst.MAT must be in the current working
% directory. See dicom_lst.m.
%
% 2. Assumes the DICOM subdirectory is in the current
% working directory.
%
% 3. Assumes there are more than 10 and less than 100 MRI
% slices through the knee.
%
% 4. The shell files must be made executable (chmod +x)
% and run from a terminal window (unix console). The
% command/batch file must be run with the run command or
% in a command/DOS window.
%
% 15-Sep-2020 * Mack Gardner-Morse
%
%#######################################################################
%
% Load File Names and Other Variables
%
load dicom_lst afiles id im_type nimages ptxt sn splcktc;
%
fnams = afiles(id); % Valid file names
%
% Find T1rho Series
%
idt1r = contains(ptxt,'3DMAPPS');
%
im_typ = im_type(id); % Valid image types
%
id2 = ~contains(im_typ,'T1rho');
idt1r = idt1r&id2;
%
nt1r = sum(idt1r);
idt1r = find(idt1r);
%
nimags = nimages(id); % Valid number of images for series
%
if ispc
cmd0 = 'copy ';
fext = '.bat';
hdr = 'REM ';
cm = 'REM';
else
cmd0 = 'cp ';
fext = '.sh';
hdr = '#!/bin/sh';
cm = '#'
end
%
for k = 1:nt1r
%
% Generate Operating System Commands
%
id0 = idt1r(k); % Series index
%
slt = eval([ '[' splcktc{id0} ']' ]); % Get spin lock times
nslt = size(slt,2); % Number of spin lock times
%
fnams0 = char(fnams{id0}(1:nslt:nimags(id0))); % Files w/ 0 ms spin lock times
nf = size(fnams0,1); % Number of files
%
fn = int2str((1:nf)'); % File numbers
fn = char(strrep(cellstr(fn),' ','0')); % Replace space with zero
%
sn_str = int2str(sn(id0)); % Series number as a string
ddir = repmat([' DICOM_' sn_str '\IM_00'],nf,1); % New directory
%
cmds = [repmat(cmd0,nf,1) fnams0 ddir fn]; % DOS/shell commands
%
% Open Command/Shell File and Write Header Comments
%
fid = fopen(['dicom_' sn_str fext],'wt');
fprintf(fid,'%s\n',hdr);
if ~ispc
fprintf(fid,'%s\n',cm);
end
fprintf(fid,'%s\n',[cm ' Command/shell file for Series ' sn_str]);
fprintf(fid,'%s\n',[cm ' Auto-generated by T1rho_slt0.m']);
fprintf(fid,'%s\n',[cm ' ' date]);
if ispc
fprintf(fid,'%s',[cm ' ']);
else
fprintf(fid,'%s',cm);
end
%
% Make Directory
%
mddir = ['mkdir DICOM_' sn_str];
eval(['!' mddir]);
fprintf(fid,'\n%s',mddir);
%
% Execute and Write Commands
%
for l = 1:nf
eval(['!' cmds(l,:)]);
fprintf(fid,'\n%s',cmds(l,:));
end
%
end