write_ryan_beamlets.m 971 B

123456789101112131415161718192021222324252627282930313233343536
  1. function [ beamlets ] = write_ryan_beamlets ( filename, beamlets )
  2. %WRITE_RYAN_BEAMLETS Write beamlet cell array out to Ryan's format
  3. %
  4. % Example:
  5. % [ ] = write_ryan_beamlets ( filename, beamlets )
  6. %
  7. % See also read_ryan_beamlets, open_beamlet_batch.
  8. %
  9. % Copyleft 1999-, XMO.
  10. if nargin < 2
  11. error('Usage: write_ryan_beamlets ( filename, beamlets )');
  12. end
  13. fid = fopen(filename, 'w');
  14. if ( fid == -1 )
  15. error(['cannot open "' filename '"']);
  16. end
  17. fwrite(fid, numel(beamlets), 'int');
  18. for k = 1:numel(beamlets)
  19. % beamlet number (or index), base 0 for C
  20. fwrite(fid, beamlets{k}.num, 'int');
  21. fwrite(fid, beamlets{k}.x_count, 'int');
  22. fwrite(fid, beamlets{k}.y_count, 'int');
  23. fwrite(fid, beamlets{k}.z_count, 'int');
  24. fwrite(fid, numel(beamlets{k}.non_zero_indices), 'int');
  25. fwrite(fid, beamlets{k}.non_zero_indices-1, 'int'); % base 0 for C
  26. fwrite(fid, beamlets{k}.non_zero_values, 'float');
  27. end
  28. fclose(fid);