save_beamspec_batch.m 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. function save_beamspec_batch(batch,batch_folder,batch_file_name)
  2. % Saves a beamspec batch to batch_folder/batch_filename. The batch is a
  3. % cell array of beam structures.
  4. %
  5. % Each beam structure has the following fields:
  6. % beam =
  7. %
  8. % num: 1
  9. % y_vec: [86.6025 50.0000 0]
  10. % SAD: 100
  11. % ip: [0.5000 -0.8660 0]
  12. % jp: [0 0 1]
  13. % kp: [-0.8660 -0.5000 0]
  14. % xp: 0.5000
  15. % yp: 0
  16. % del_yp: 1
  17. % del_xp: 2
  18. warning off MATLAB:MKDIR:DirectoryExists
  19. mkdir(batch_folder);
  20. N = prod(size(batch)); % number of beamspecs in the batch
  21. fid = fopen([batch_folder '/' batch_file_name],'w');
  22. fprintf(fid,'beamnum:\n %g\n\n',N); % write the total number of beams that are in this batch
  23. for k=1:N
  24. % save each beam structure
  25. beam = batch{k}; % current beam structure
  26. fprintf(fid,'num\n');
  27. fprintf(fid,'%g\n',double(beam.num));
  28. fprintf(fid,'SAD xp yp del_xp del_yp\n');
  29. fprintf(fid,'%4.20E %4.20E %4.20E %4.20E %4.20E\n',double(beam.SAD),double(beam.xp),double(beam.yp),double(beam.del_xp),double(beam.del_yp));
  30. fprintf(fid,'y_vec\n');
  31. fprintf(fid,'%4.20E %4.20E %4.20E\n',double(beam.y_vec(1)),double(beam.y_vec(2)),double(beam.y_vec(3)));
  32. fprintf(fid,'ip\n');
  33. fprintf(fid,'%4.20E %4.20E %4.20E\n',double(beam.ip(1)),double(beam.ip(2)),double(beam.ip(3)));
  34. fprintf(fid,'jp\n');
  35. fprintf(fid,'%4.20E %4.20E %4.20E\n',double(beam.jp(1)),double(beam.jp(2)),double(beam.jp(3)));
  36. fprintf(fid,'kp\n');
  37. fprintf(fid,'%4.20E %4.20E %4.20E\n\n',double(beam.kp(1)),double(beam.kp(2)),double(beam.kp(3)));
  38. end
  39. fclose(fid);