save_geometry.m 1.4 KB

123456789101112131415161718192021222324252627282930313233343536
  1. function save_geometry2(Geometry,geometry_folder,header_filename,density_filename)
  2. % saves the Geometry file without the beam data in its matlab format to
  3. % files that are readable by a C-version of the convolution code.
  4. % The results are all saved in binary files so that no truncation errors
  5. % occur in the numbers.
  6. warning off MATLAB:MKDIR:DirectoryExists
  7. % load GeometryCT.mat; % load the Matlab kernels, which look like:
  8. % Geometry =
  9. %
  10. % start: [-24.0128 -24.0128 -1.5000]
  11. % voxel_size: [0.3752 0.3752 0.3000]
  12. % data: [128x128x10 float]
  13. % beam: [1x1 struct] % the beam field is not used by this file
  14. %
  15. mkdir(geometry_folder);
  16. % density grid dimensions
  17. [Xcount,Ycount,Zcount] = size(Geometry.data);
  18. % create the geometry header file
  19. fid = fopen([geometry_folder '/' header_filename],'w');
  20. fprintf(fid,'Xcount Ycount Zcount\n');
  21. fprintf(fid,'%g %g %g\n',Xcount,Ycount,Zcount);
  22. fprintf(fid,'Xstart Ystart Zstart\n');
  23. fprintf(fid,'%4.20E %4.20E %4.20E\n',double(Geometry.start(1)),double(Geometry.start(2)),double(Geometry.start(3)));
  24. fprintf(fid,'dx dy dz\n');
  25. fprintf(fid,'%4.20E %4.20E %4.20E\n',double(Geometry.voxel_size(1)),double(Geometry.voxel_size(2)),double(Geometry.voxel_size(3)));
  26. fclose(fid);
  27. % save the density data to a binary file
  28. fid = fopen([geometry_folder '/' density_filename],'wb');
  29. fwrite(fid,Geometry.rhomw,'float');
  30. fclose(fid);