Skip to content

Commit 9850588

Browse files
authored
Initial commit.
Copies 0 ms spin lock time files to new directory.
1 parent 3b3c14a commit 9850588

File tree

1 file changed

+111
-0
lines changed

1 file changed

+111
-0
lines changed

T1rho_slt0.m

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

0 commit comments

Comments
 (0)