helicalDosecalcSetup6.m 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523
  1. %%
  2. % This version was modified by Peter Ferjancic to accept .nrrd file format
  3. % for target.
  4. % This file has been modified by Surendra Prajapati especially to run
  5. % WiscPlan for KV beams. Works for running locally as well as in Server.
  6. %
  7. % RTF 11/4/05
  8. % Sets up the run files needed for running a Condor convolution
  9. % superposition dose calculation with photon beams.
  10. % Versions of the convolution code that run in both Windows XP, Condor, and
  11. % directly through Matlab can all be created here. The only real
  12. % differences between the files are in the access conventions, which just%
  13. % This has to do with switching forward slashes with backslashes.
  14. % Surendra edits: num_batches, SAD, pitch, xpmin/max, ypmin/max, Mxp, Nphi
  15. % Also edit:
  16. % Kernel should always be named Kernels.mat
  17. % SAD < 20 was edited from SAD < 50 for clinical system (error message)
  18. %
  19. function helicalDosecalcSetup6()
  20. % specify where kernel and [geometry] files are located
  21. patient_dir = 'C:\010-work\003_localGit\WiscPlan_v2\WiscPlanPhotonkV125\PatientData';
  22. num_batches = 4; % number of cores you want to run the beam calculation
  23. iso = [0 0 0]; % Point about which gantry rotations begin
  24. % SAD = 35; % source-axis distance for the x-ray source
  25. SAD = 60; % source-axis distance for the x-ray source ##
  26. pitch = 0.86; % fraction of beam with couch translates per rotation
  27. % define the overall beam field size for each beam angle
  28. xpmin = -0.5; % -field width / 2
  29. xpmax = 0.5; % +field width / 2
  30. ypmin = -0.5; % -jaw width / 2
  31. ypmax = 0.5; % +jaw width / 2
  32. % ##
  33. xpmin = -5.0; % -field width / 2
  34. xpmax = 5.0; % +field width / 2
  35. ypmin = -1.0; % -jaw width / 2
  36. ypmax = 1.0; % +jaw width / 2
  37. % y-prime points in the z-direction in the CT coordinate system
  38. % Number of beamlets in the BEV for each direction
  39. Mxp = 20; % number of leaves; leaf size is 1/20cm= 0.5mm
  40. Nyp = 1; % always 1 for Tomo due to binary mlc
  41. %
  42. % Mxp = 20; % ## Grozomah
  43. % ============================================= End of user-supplied inputs
  44. executable_path = 'C:\010-work\003_localGit\WiscPlan_v2\WiscPlanPhotonkV125\WiscPlanEXE\RyanCsphoton.x86.exe';
  45. kernel_file = 'Kernels.mat';
  46. geometry_file = fullfile(patient_dir, 'matlab_files\Geometry.mat');
  47. load(geometry_file);
  48. ROI_names = cellfun(@(c)c.name, Geometry.ROIS, 'UniformOutput', false);
  49. [target_idx, okay] = listdlg('ListString', ROI_names, ...
  50. 'SelectionMode', 'single', 'Name', 'Target Selection', ...
  51. 'PromptString', 'Please select the target ROI. ');
  52. if okay ~= 1
  53. msgbox('Plan creation aborted');
  54. return;
  55. end
  56. targetMask = zeros(size(Geometry.data));
  57. targetMask(Geometry.ROIS{target_idx}.ind) = 1;
  58. % Grozomah - targetMask needs to get a 'double' matrix with the location of
  59. % the target
  60. targetMaskZ = sum(sum(targetMask,1),2);
  61. zBow = find(targetMaskZ>0, 1, 'first')*Geometry.voxel_size(3) + Geometry.start(3) + ypmin;
  62. zStern = find(targetMaskZ>0, 1, 'last')*Geometry.voxel_size(3) + Geometry.start(3) + ypmax;
  63. [subi, subj, subk] = ind2sub(size(Geometry.data), Geometry.ROIS{target_idx}.ind);
  64. iso = [Geometry.start(1)+Geometry.voxel_size(1)*mean(subi) ...
  65. Geometry.start(2)+Geometry.voxel_size(2)*mean(subj) 0];
  66. % flags used to select which calculations will be set up
  67. Condor_flag = 1;
  68. ptvInd = target_idx; % PTV index in Geometry.ROIS
  69. fieldWidth = ypmax - ypmin;
  70. % total number of rotations required for treatment
  71. Nrot = ceil(abs(zBow - zStern)/(pitch*fieldWidth));
  72. Nphi = Nrot*51; % number of angles used in the calculation
  73. % Nphi = Nrot*21; % Grozomah
  74. % load(geometry_file);
  75. % define the limits of the angles that will be used for the calculation
  76. % ##phimin = 0; % starting angle in radians
  77. % ##phimax = 2*pi*Nphi;
  78. phi = [0:Nphi-1]/Nphi *2*pi*Nrot;
  79. condor_folder = patient_dir;
  80. winxp_folder = 'winxp';
  81. % create names for condor input and output folders
  82. input_folder = '.';
  83. output_folder = '.';
  84. % name of the convolution/superposition executable, which will be in the
  85. % 'code' folder of each respective run type folder
  86. condor_exectuable_name = 'convolutionCondor'; % relative path on the cluster where code will be
  87. winxp_executable_name = 'convolution.exe';
  88. matlab_executable_name = 'convolution_mex'; % name of the Matlab version of the dose calculation code
  89. % set the beam parameters, assuming a helical beam trajectory
  90. % folders that will be inside the 'input' folder
  91. beamspec_folder = 'beamspecfiles'; % directory where beam files will be stored
  92. beamspec_batches_folder = 'beamspecbatches';
  93. beamspec_batch_base_name = 'beamspecbatch'; % base name for a beamlet batch file
  94. kernel_folder = 'kernelfiles'; % folder where kernel information will be saved
  95. kernel_filenames_condor = 'kernelFilenamesCondor.txt';
  96. kernel_filenames_winxp = 'kernelFilenamesWinXP.txt';
  97. % output folders
  98. beamlet_batch_base_name = 'beamletbatch'; % base name for a dose batch file
  99. geometry_header_filename = 'geometryHeader.txt';
  100. geometry_density_filename = 'density.bin'; % save the density, not the Hounsfield units!
  101. % end of user-defined parameters
  102. % check the validity of the user-defined variables
  103. if xpmin >= xpmax
  104. error('xpmin must be less than xpmax.');
  105. end
  106. if ypmin >= ypmax
  107. error('ypmin must be less than ypmax.');b
  108. end
  109. % if phimin > phimax
  110. % error('phimin must be less than or equal to phimax.');
  111. % end
  112. if Mxp <= 0 || Nyp <= 0 || Nphi <= 0
  113. error('Mxp, Nyp, and Nphi must be greater than zero.');
  114. end
  115. if SAD < 20
  116. error('It is recommended that the SAD be greater than 20 cm.');
  117. end
  118. % the xy plane is perpendicular to the isocenter axis of the linac gantry
  119. % size of each beam aperture, making them vectors so extension to
  120. % non-uniform aperture sizes becomes obvious
  121. del_xp = (xpmax - xpmin)/Mxp;
  122. del_yp = (ypmax - ypmin)/Nyp;
  123. % Calculate the xp and yp offsets, which lie at the centers of the
  124. % apertures.
  125. xp = [xpmin:del_xp:xpmax-del_xp] + del_xp/2;
  126. yp = [ypmin:del_yp:ypmax-del_yp] + del_yp/2;
  127. [M,N,Q] = size(Geometry.rhomw);
  128. START = single(Geometry.start - iso);
  129. INC = single(Geometry.voxel_size);
  130. % Grozomah ##
  131. % START(1) = START(1)/10;
  132. % START(2) = START(2)/10;
  133. % INC(1) = INC(1)/10;
  134. % INC(2) = INC(2)/10;
  135. % END= START+[32,32,40].*INC
  136. % define the tumor mask
  137. tumorMask = zeros(size(Geometry.rhomw),'single');
  138. tumorMask(Geometry.ROIS{ptvInd}.ind) = 1;
  139. BW = bwdist(tumorMask);
  140. tumorMaskExp = tumorMask;
  141. tumorMaskExp(BW <= 4) = 1;
  142. P = zeros(Mxp,Nphi);
  143. fprintf('Checking beam''s eye view ...\n');
  144. for p=1:Nphi
  145. % ir and jr form the beam's eye view (BEV)
  146. ir = [-sin(phi(p)); cos(phi(p)); 0];
  147. jr = [0 0 1]';
  148. % kr denotes the beam direction
  149. kr = [cos(phi(p)); sin(phi(p)); 0];
  150. for m=1:Mxp
  151. point1 = single(-kr*SAD + [0 0 zBow + pitch*fieldWidth*phi(p)/(2*pi)]'); % source point
  152. point2 = single(point1 + (SAD*kr + ir*xp(m))*10);
  153. [indVisited,deffVisited] = singleRaytraceClean(tumorMaskExp,START,INC,point1,point2);
  154. if ~isempty(indVisited)
  155. P(m,p) = max(deffVisited);
  156. end
  157. end
  158. end
  159. fprintf('Finished checking BEV\n');
  160. % load data required for the dose calculator
  161. load(kernel_file);
  162. Geometry.rhomw(Geometry.rhomw < 0) = 0;
  163. Geometry.rhomw(Geometry.rhomw < 0.0013) = 0.0013; % fill blank voxels with air
  164. % convert Geometry and kernels to single
  165. f = fieldnames(Kernels);
  166. for k=1:length(f)
  167. if isnumeric(getfield(Kernels,f{k}))
  168. Kernels = setfield(Kernels,f{k},single(getfield(Kernels,f{k})));
  169. end
  170. end
  171. f = fieldnames(Geometry);
  172. for k=1:length(f)
  173. if isnumeric(getfield(Geometry,f{k}))
  174. Geometry = setfield(Geometry,f{k},single(getfield(Geometry,f{k})));
  175. end
  176. end
  177. % account for isocenter
  178. Geometry.start = single(Geometry.start - iso);
  179. % find the total number of beams
  180. Nbeam = Nphi*Mxp*Nyp;
  181. batch_num = 0; % start the count for the number of total batches
  182. % fill up a cell array of beam structures, grouped by batch
  183. clear batches;
  184. batch_num = 0;
  185. batches = cell(1,Nrot); % start the batches cell array (cell array of beam batches)
  186. rotNum = 0;
  187. % calculate beams for all source directions and apertures
  188. for k=1:Nphi % loop through all gantry angles
  189. % calculate the source location for a helical trajectory
  190. beam.SAD = single(SAD);
  191. % the kp vector is the beam direction, ip and jp span the beam's eye view
  192. beam.ip = single([-sin(phi(k)) cos(phi(k)) 0]);
  193. beam.jp = single([0 0 1]);
  194. beam.kp = single([cos(phi(k)) sin(phi(k)) 0]);
  195. beam.y_vec = single(-beam.kp*SAD + [0 0 zBow + pitch*fieldWidth*phi(k)/(2*pi)]);
  196. rotNumOld = rotNum;
  197. rotNum = floor(k/51) + 1; % current rotation number
  198. if rotNum - rotNumOld > 0
  199. beam_num = 0; % if the rotation number has changed, start the beam count over
  200. end
  201. for m=1:Mxp % loop through all apertures in the xp-direction
  202. % calculate the beam if the tomotherapy fluence value is non-zero
  203. if P(m,k) > 0
  204. num = m + (k-1)*Mxp - 1; % beamlet number (overall)
  205. beam_num = beam_num + 1;
  206. % set the beam aperture parameters
  207. beam.del_xp = single(del_xp);
  208. beam.del_yp = single(del_yp);
  209. beam.xp = single(xp(m));
  210. beam.yp = single(0);
  211. beam.num = single(num); % record the beam number to avoid any later ambiguity
  212. batches{rotNum}{beam_num} = beam;
  213. end
  214. end
  215. end
  216. % merge/split batches
  217. all_beams = horzcat(batches{:});
  218. num_beams_per_batch = ceil(numel(all_beams)/num_batches);
  219. batches = cell(num_batches,1);
  220. for k = 1:(num_batches-1)
  221. batches{k} = all_beams(1+num_beams_per_batch*(k-1):num_beams_per_batch*k);
  222. end
  223. batches{num_batches} = all_beams(1+num_beams_per_batch*(k):end);
  224. % Everything else in this file is related to saving the batches in a
  225. % useable form.
  226. if Condor_flag == 1
  227. % delete the old submission file
  228. err = rmdir(fullfile(condor_folder,beamspec_batches_folder),'s');
  229. err = rmdir(fullfile(condor_folder,kernel_folder),'s');
  230. % create folders where batch information will be sent
  231. mkdir([condor_folder '/' input_folder '/' beamspec_batches_folder]);
  232. % save the kernels
  233. save_kernels(Kernels,[condor_folder '/' input_folder '/' kernel_folder]);
  234. fprintf(['Successfully saved Condor kernels to ' input_folder '/' kernel_folder '\n']);
  235. % create kernel filenames files
  236. kernel_filenames_CHTC = 'kernelFilenamesCHTC.txt';
  237. kernel_filenames_condor = 'kernelFilenamesCondor.txt';
  238. fid = fopen([condor_folder '/' input_folder '/' kernel_filenames_condor],'w');
  239. fid2 = fopen([condor_folder '/' input_folder '/' kernel_filenames_CHTC],'w');
  240. fprintf(fid,'kernel_header\n');
  241. % fprintf(fid,['./' input_folder '/' kernel_folder '/kernel_header.txt\n']);
  242. fprintf(fid,'%s\n',fullfile(patient_dir,input_folder,kernel_folder,'kernel_header.txt'));
  243. fprintf(fid2,'kernel_header\n');
  244. fprintf(fid2, '%s/%s\n', kernel_folder,'kernel_header.txt');
  245. fprintf(fid,'kernel_radii\n');
  246. % fprintf(fid,['./' input_folder '/' kernel_folder '/radii.bin\n']);
  247. fprintf(fid,'%s\n',fullfile(patient_dir,input_folder,kernel_folder,'radii.bin'));
  248. fprintf(fid2,'kernel_radii\n');
  249. fprintf(fid2, '%s/%s\n', kernel_folder,'radii.bin');
  250. fprintf(fid,'kernel_angles\n');
  251. % fprintf(fid,['./' input_folder '/' kernel_folder '/angles.bin\n']);
  252. fprintf(fid,'%s\n',fullfile(patient_dir,input_folder,kernel_folder,'angles.bin'));
  253. fprintf(fid2,'kernel_angles\n');
  254. fprintf(fid2, '%s/%s\n', kernel_folder,'angles.bin');
  255. fprintf(fid,'kernel_energies\n');
  256. % fprintf(fid,['./' input_folder '/' kernel_folder '/energies.bin\n']);
  257. fprintf(fid,'%s\n',fullfile(patient_dir,input_folder,kernel_folder,'energies.bin'));
  258. fprintf(fid2,'kernel_energies\n');
  259. fprintf(fid2, '%s/%s\n', kernel_folder,'energies.bin');
  260. fprintf(fid,'kernel_primary\n');
  261. % fprintf(fid,['./' input_folder '/' kernel_folder '/primary.bin\n']);
  262. fprintf(fid,'%s\n',fullfile(patient_dir,input_folder,kernel_folder,'primary.bin'));
  263. fprintf(fid2,'kernel_primary\n');
  264. fprintf(fid2, '%s/%s\n', kernel_folder,'primary.bin');
  265. fprintf(fid,'kernel_first_scatter\n');
  266. % fprintf(fid,['./' input_folder '/' kernel_folder '/first_scatter.bin\n']);
  267. fprintf(fid,'%s\n',fullfile(patient_dir,input_folder,kernel_folder,'first_scatter.bin'));
  268. fprintf(fid2,'kernel_first_scatter\n');
  269. fprintf(fid2, '%s/%s\n', kernel_folder,'first_scatter.bin');
  270. fprintf(fid,'kernel_second_scatter\n');
  271. % fprintf(fid,['./' input_folder '/' kernel_folder '/second_scatter.bin\n']);
  272. fprintf(fid,'%s\n',fullfile(patient_dir,input_folder,kernel_folder,'second_scatter.bin'));
  273. fprintf(fid2,'kernel_second_scatter\n');
  274. fprintf(fid2, '%s/%s\n', kernel_folder,'second_scatter.bin');
  275. fprintf(fid,'kernel_multiple_scatter\n');
  276. % fprintf(fid,['./' input_folder '/' kernel_folder '/multiple_scatter.bin\n']);
  277. fprintf(fid,'%s\n',fullfile(patient_dir,input_folder,kernel_folder,'multiple_scatter.bin'));
  278. fprintf(fid2,'kernel_multiple_scatter\n');
  279. fprintf(fid2, '%s/%s\n', kernel_folder,'multiple_scatter.bin');
  280. fprintf(fid,'kernel_brem_annih\n');
  281. % fprintf(fid,['./' input_folder '/' kernel_folder '/brem_annih.bin\n']);
  282. fprintf(fid,'%s\n',fullfile(patient_dir,input_folder,kernel_folder,'brem_annih.bin'));
  283. fprintf(fid2,'kernel_brem_annih\n');
  284. fprintf(fid2, '%s/%s\n', kernel_folder,'brem_annih.bin');
  285. fprintf(fid,'kernel_total\n');
  286. % fprintf(fid,['./' input_folder '/' kernel_folder '/total.bin\n']);
  287. fprintf(fid,'%s\n',fullfile(patient_dir,input_folder,kernel_folder,'total.bin'));
  288. fprintf(fid2,'kernel_total\n');
  289. fprintf(fid2, '%s/%s\n', kernel_folder,'total.bin');
  290. fprintf(fid,'kernel_fluence\n');
  291. % fprintf(fid,['./' input_folder '/' kernel_folder '/fluence.bin\n']);
  292. fprintf(fid,'%s\n',fullfile(patient_dir,input_folder,kernel_folder,'fluence.bin'));
  293. fprintf(fid2,'kernel_fluence\n');
  294. fprintf(fid2, '%s/%s\n', kernel_folder,'fluence.bin');
  295. fprintf(fid,'kernel_mu\n');
  296. % fprintf(fid,['./' input_folder '/' kernel_folder '/mu.bin\n']);
  297. fprintf(fid,'%s\n',fullfile(patient_dir,input_folder,kernel_folder,'mu.bin'));
  298. fprintf(fid2,'kernel_mu\n');
  299. fprintf(fid2, '%s/%s\n', kernel_folder,'mu.bin');
  300. fprintf(fid,'kernel_mu_en\n');
  301. % fprintf(fid,['./' input_folder '/' kernel_folder '/mu_en.bin\n']);
  302. fprintf(fid,'%s\n',fullfile(patient_dir,input_folder,kernel_folder,'mu_en.bin'));
  303. fprintf(fid2,'kernel_mu_en\n');
  304. fprintf(fid2, '%s/%s\n', kernel_folder,'mu_en.bin');
  305. fclose(fid);
  306. end
  307. % name for the condor submit file that will be used
  308. condor_submit_file = 'convolutionSubmit.txt';
  309. geometry_filenames_condor = 'geometryFilenamesCondor.txt';
  310. geometry_filenames_CHTC = 'geometryFilenamesCHTC.txt';
  311. % check the geometry file to ensure that it's not in Hounsfield units
  312. if length(find(Geometry.rhomw > 20)) || length(find(Geometry.rhomw < 0))
  313. error('Double check the Geometry structure, it may still be in Hounsfield units!');
  314. end
  315. geometry_folder = 'geometryfiles';
  316. batch_output_folder = 'batchoutput'; % folder to which stdout will be printed
  317. beamlet_batches_folder = 'beamletbatches'; % folder where resulting beamlet batches will be stored
  318. if Condor_flag == 1
  319. mkdir([condor_folder '/' output_folder '/' beamlet_batches_folder]);
  320. mkdir([condor_folder '/' output_folder '/' batch_output_folder]);
  321. save_geometry(Geometry,[condor_folder '/' input_folder '/' geometry_folder],geometry_header_filename,geometry_density_filename);
  322. fprintf(['Successfully saved Condor geometry to ' input_folder '/' geometry_folder '\n']);
  323. % create geometry filenames files
  324. fid = fopen([condor_folder '/' input_folder '/' geometry_filenames_condor],'w');
  325. fid2 = fopen([condor_folder '/' input_folder '/' geometry_filenames_CHTC],'w');
  326. fprintf(fid,'geometry_header\n');
  327. % fprintf(fid,['./' input_folder '/' geometry_folder '/' geometry_header_filename '\n']);
  328. fprintf(fid,'%s\n',fullfile(patient_dir,input_folder,geometry_folder,geometry_header_filename));
  329. fprintf(fid2,'geometry_header\n');
  330. fprintf(fid2, '%s/%s\n', geometry_folder,'geometryHeader.txt');
  331. fprintf(fid,'geometry_density\n');
  332. % fprintf(fid,['./' input_folder '/' geometry_folder '/' geometry_density_filename '\n']);
  333. fprintf(fid,'%s\n',fullfile(patient_dir,input_folder,geometry_folder,geometry_density_filename));
  334. fprintf(fid2,'geometry_density\n');
  335. fprintf(fid2, '%s/%s\n', geometry_folder,'density.bin');
  336. fclose(fid);
  337. % write command file
  338. % TODO consistent naming throughout script
  339. for k = 1:numel(batches)
  340. fid = fopen(fullfile(patient_dir,sprintf('run%d.cmd',k-1)), 'w');
  341. fprintf(fid, '"%s" "%s" "%s" "%s" "%s"', executable_path,...
  342. fullfile(patient_dir, kernel_filenames_condor),...
  343. fullfile(patient_dir, geometry_filenames_condor),...
  344. fullfile(patient_dir, 'beamspecbatches', sprintf('beamspecbatch%d.txt',k-1)),...
  345. fullfile(patient_dir, sprintf('batch_dose%d.bin',k-1)));
  346. fclose(fid);
  347. end
  348. % write the condor submit file
  349. % beamspec_batch_filename = ['./' input_folder '/' beamspec_batches_folder '/' beamspec_batch_base_name '$(Process).txt'];
  350. % beamlet_batch_filename = ['./' output_folder '/' beamlet_batches_folder '/' beamlet_batch_base_name '$(Process).bin'];
  351. % fid = fopen([condor_folder '/' condor_submit_file],'w');
  352. % fprintf(fid,'###############################################################\n');
  353. % fprintf(fid,'# Condor submission script for convolution/superposition code\n');
  354. % fprintf(fid,'###############################################################\n\n');
  355. % fprintf(fid,'copy_to_spool = false\n');
  356. % fprintf(fid,['Executable = ' code_folder '/' condor_exectuable_name '\n']);
  357. % fprintf(fid,['arguments = ' input_folder '/' kernel_filenames_condor ' ' input_folder '/' geometry_filenames_condor ' ' beamspec_batch_filename ' ' beamlet_batch_filename '\n']);
  358. % fprintf(fid,['Output = ./' output_folder '/' batch_output_folder '/batchout$(Process).txt\n']);
  359. % fprintf(fid,['Log = ./' output_folder '/' batch_output_folder '/log.txt\n']);
  360. % fprintf(fid,['Queue ' num2str(Nrot)]);
  361. % fclose(fid);
  362. % % write the condor submit file
  363. % beamspec_batch_filename = ['./' input_folder '/' beamspec_batches_folder '/' beamspec_batch_base_name '$(Process).txt'];
  364. % beamlet_batch_filename = ['./' output_folder '/' beamlet_batches_folder '/' beamlet_batch_base_name '$(Process).bin'];
  365. fid = fopen([condor_folder '/' condor_submit_file],'w');
  366. fprintf(fid,'###############################################################\n');
  367. fprintf(fid,'# Condor submission script for convolution/superposition code\n');
  368. fprintf(fid,'###############################################################\n\n');
  369. fprintf(fid,'copy_to_spool = false\n');
  370. fprintf(fid,['Executable = ' condor_exectuable_name '\n']);
  371. fprintf(fid,['Arguments = ' kernel_filenames_CHTC ' ' geometry_filenames_CHTC ' ' beamspec_batch_base_name '$(Process).txt ' 'batch_dose$(Process).bin\n']);
  372. fprintf(fid,['Transfer_input_files = ' kernel_folder ',' geometry_folder ',' beamspec_batches_folder '/' beamspec_batch_base_name '$(Process).txt' ',' kernel_filenames_CHTC ',' geometry_filenames_CHTC '\n']);
  373. fprintf(fid,['Request_memory = 1000' '\n']);
  374. fprintf(fid,['Request_disk = 500000' '\n']);
  375. fprintf(fid,['Output = $(Cluster).out' '\n']);
  376. fprintf(fid,['Log = $(Cluster).log' '\n']);
  377. fprintf(fid,['Error = $(Cluster).err' '\n']);
  378. fprintf(fid,['Queue ' num2str(num_batches) '\n']);
  379. % fclose(fid);
  380. end
  381. % write the batches to files
  382. for n=1:numel(batches)
  383. batch = batches{n}; % current batch
  384. if Condor_flag == 1
  385. save_beamspec_batch(batch,[condor_folder '/' input_folder '/' beamspec_batches_folder],[beamspec_batch_base_name num2str(n-1) '.txt']);
  386. end
  387. end
  388. % for k = 1:numel(batches)
  389. % system([fullfile(patient_dir,sprintf('run%d.cmd',k-1)) ' &']);
  390. % end
  391. % Ask for User option to run the dose calculation locally on the computer
  392. % or just to get necessary files for CHTC server
  393. % 'y' means run locally, 'n' means not to run locally on the computer
  394. strBeamlet = '';
  395. while(1)
  396. if strcmpi('y',strBeamlet)
  397. break;
  398. elseif strcmpi('n',strBeamlet)
  399. break;
  400. end
  401. strBeamlet = input('Run beamlet batches dose calculation locally? y/n \n','s');
  402. end
  403. disp(['Calculating ' num2str(size(all_beams, 2)) ' beamlets in ' num2str(size(batches, 1))...
  404. ' batches. '])
  405. if(strcmpi('y',strBeamlet))
  406. for k = 1:numel(batches)
  407. system([fullfile(patient_dir,sprintf('run%d.cmd',k-1)) ' &']);
  408. end
  409. end
  410. end