save_kernels.m 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. function save_kernels(Kernels,kernel_folder)
  2. % saves the Kernels in their matlab format to files that are readable by a
  3. % C-version of the convolution code. The results are all saved in binary
  4. % files so for easy readin. Since there are so many files that will be
  5. % created the option of changing the filenames from outside the function
  6. % was not included.
  7. warning off MATLAB:MKDIR:DirectoryExists
  8. % The kernels have the following structure:
  9. % Kernels =
  10. %
  11. % radii: [1x24 float]
  12. % angles: [1x48 float]
  13. % energies: [1x14 float]
  14. % primary: [24x48x14 float]
  15. % first_scatter: [24x48x14 float]
  16. % second_scatter: [24x48x14 float]
  17. % multiple_scatter: [24x48x14 float]
  18. % brem_annih: [24x48x14 float]
  19. % total: [24x48x14 float]
  20. % mean_radii: [24x48x14 float]
  21. % mean_angles: [24x48x14 float]
  22. % helpfield: [21x72 char] % not saved
  23. % fluence: [1x14 float]
  24. % mu: [1x14 float]
  25. % mu_en: [1x14 float]
  26. mkdir(kernel_folder);
  27. % kernel filenames:
  28. kernel_header = 'kernel_header.txt'; % header file for the kernels
  29. kernel_radii = 'radii.bin';
  30. kernel_angles = 'angles.bin';
  31. kernel_energies = 'energies.bin';
  32. kernel_primary = 'primary.bin';
  33. kernel_first_scatter = 'first_scatter.bin';
  34. kernel_second_scatter = 'second_scatter.bin';
  35. kernel_multiple_scatter = 'multiple_scatter.bin';
  36. kernel_brem_annih = 'brem_annih.bin';
  37. kernel_total = 'total.bin';
  38. kernel_fluence = 'fluence.bin';
  39. kernel_mu = 'mu.bin';
  40. kernel_mu_en = 'mu_en.bin';
  41. [Nradii,Nangles,Nenergies] = size(Kernels.total);
  42. % create the header file
  43. fid = fopen(['./' kernel_folder '/' kernel_header],'w');
  44. fprintf(fid,'Nradii Nangles Nenergies\n');
  45. fprintf(fid,'%g %g %g\n',Nradii,Nangles,Nenergies);
  46. fclose(fid);
  47. % start saving the rest of the data
  48. fid = fopen(['./' kernel_folder '/' kernel_radii],'wb');
  49. fwrite(fid,Kernels.radii,'float');
  50. fclose(fid);
  51. fid = fopen(['./' kernel_folder '/' kernel_angles],'wb');
  52. fwrite(fid,Kernels.angles,'float');
  53. fclose(fid);
  54. fid = fopen(['./' kernel_folder '/' kernel_energies],'wb');
  55. fwrite(fid,Kernels.energies,'float');
  56. fclose(fid);
  57. fid = fopen(['./' kernel_folder '/' kernel_primary],'wb');
  58. fwrite(fid,Kernels.primary,'float');
  59. fclose(fid);
  60. fid = fopen(['./' kernel_folder '/' kernel_first_scatter],'wb');
  61. fwrite(fid,Kernels.first_scatter,'float');
  62. fclose(fid);
  63. fid = fopen(['./' kernel_folder '/' kernel_second_scatter],'wb');
  64. fwrite(fid,Kernels.second_scatter,'float');
  65. fclose(fid);
  66. fid = fopen(['./' kernel_folder '/' kernel_multiple_scatter],'wb');
  67. fwrite(fid,Kernels.multiple_scatter,'float');
  68. fclose(fid);
  69. fid = fopen(['./' kernel_folder '/' kernel_brem_annih],'wb');
  70. fwrite(fid,Kernels.brem_annih,'float');
  71. fclose(fid);
  72. fid = fopen(['./' kernel_folder '/' kernel_total],'wb');
  73. fwrite(fid,Kernels.total,'float');
  74. fclose(fid);
  75. fid = fopen(['./' kernel_folder '/' kernel_fluence],'wb');
  76. fwrite(fid,Kernels.fluence,'float');
  77. fclose(fid);
  78. fid = fopen(['./' kernel_folder '/' kernel_mu],'wb');
  79. fwrite(fid,Kernels.mu,'float');
  80. fclose(fid);
  81. fid = fopen(['./' kernel_folder '/' kernel_mu_en],'wb');
  82. fwrite(fid,Kernels.mu_en,'float');
  83. fclose(fid);