/src/utils/guineapig.m

http://slac-lucretia.googlecode.com/ · MATLAB · 141 lines · 90 code · 20 blank · 31 comment · 10 complexity · 36ef19dc0b5e8c89dd3d55863cc08e97 MD5 · raw file

  1. function gpdata=guineapig(erfile,prfile,afile)
  2. %
  3. % gpdata=guineapig(erfile,prfile,afile);
  4. %
  5. % Run GuineaPig starting from two matLIAR (DIMAD) output rays files
  6. % (use "add_charge=.t." in LIAR "meas_part" command to get particle
  7. % charge information) and a GuineaPig "acc.dat" template file.
  8. %
  9. % INPUTs
  10. %
  11. % erfile = matLIAR (DIMAD) "electron" output rays file name
  12. % prfile = matLIAR (DIMAD) "positron" output rays file name
  13. % afile = GuineaPig "acc.dat" template file name
  14. % (see acc_nm_*.dat files in GuineaPig directory)
  15. %
  16. % OUTPUT
  17. %
  18. % gpdata = GuineaPig output (see the user's guide)
  19. %
  20. % [n_m,lumi_fine;lumi_ee;lumi_ee_high; ...
  21. % bpm_vx.1;bpm_sig_vx.1;bpm_vy.1;bpm_sig_vy.1; ...
  22. % bpm_vx.2;bpm_sig_vx.2;bpm_vy.2;bpm_sig_vy.2];
  23. %
  24. % set these paths for your particular system
  25. gdir='D:\guineapig'; % GuineaPig directory
  26. wdir='D:\guineapig\work'; % working directory
  27. % make input filespecs DOS compatible
  28. erfiled=strrep(erfile,'/','\'); % DOS format
  29. prfiled=strrep(prfile,'/','\'); % DOS format
  30. afiled=strrep(afile,'/','\'); % DOS format
  31. disp(' ')
  32. % copy matLIAR (DIMAD) output ray files to working directory
  33. disp(' copying files ...')
  34. cmd=['copy ',erfiled,' ',wdir,'\electronc.ini'];
  35. [iss,result]=dos(cmd);
  36. if (iss)
  37. error(['DOS copy error (',int2str(iss),'): ',erfile])
  38. end
  39. cmd=['copy ',prfiled,' ',wdir,'\positronc.ini'];
  40. [iss,result]=dos(cmd);
  41. if (iss)
  42. error(['DOS copy error (',int2str(iss),'): ',prfile])
  43. end
  44. % copy GuineaPig "acc.dat" template file to working directory
  45. cmd=['copy ',gdir,'\',afiled,' ',wdir,'\acc_nm.dat'];
  46. [iss,result]=dos(cmd);
  47. if (iss)
  48. error(['DOS copy error (',int2str(iss),'): ',afile])
  49. end
  50. % cd to the working directory
  51. wd=cd;
  52. cd(wdir)
  53. % run Andrei's GuineaPig prep program
  54. disp(' preparing GuineaPig input files ...')
  55. cmd=[gdir,'\prepare_gp'];
  56. [iss,result]=dos(cmd);
  57. if (iss)
  58. cd(wd)
  59. error('prepare_gp failed')
  60. end
  61. % get accelerator name, computational parameter set name, and number
  62. % of particles (n_m) from acc.dat
  63. aname=[];
  64. pname=[];
  65. fid=fopen('acc.dat','r');
  66. while (1)
  67. temp=fgetl(fid);
  68. if (~ischar(temp)),break,end
  69. n=strfind(temp,'$ACCELERATOR::');
  70. if (~isempty(n))
  71. n1=n+length('$ACCELERATOR::');
  72. n2=length(temp);
  73. aname=deblank(temp(n1:n2));
  74. aname=fliplr(deblank(fliplr(aname)));
  75. end
  76. n=strfind(temp,'$PARAMETERS::');
  77. if (~isempty(n))
  78. n1=n+length('$PARAMETERS::');
  79. n2=length(temp);
  80. pname=deblank(temp(n1:n2));
  81. pname=fliplr(deblank(fliplr(pname)));
  82. end
  83. if (strfind(temp,'n_m='))
  84. n1=strfind(temp,'=')+1;
  85. n2=strfind(temp,';')-1;
  86. n_m=str2num(temp(n1:n2));
  87. end
  88. end
  89. fclose(fid);
  90. if (isempty(aname)|isempty(pname))
  91. cd(wd)
  92. error('Can''t find $ACCELERATOR:: and/or $PARAMETERS:: in acc.dat')
  93. end
  94. % run GuineaPig
  95. disp([' running GuineaPig (',int2str(n_m),' macroparticles) ...'])
  96. cmd=[gdir,'\guinea ',aname,' ',pname,' gp.out > gp.log'];
  97. [iss,result]=dos(cmd);
  98. if (iss)
  99. cd(wd)
  100. error('guinea failed')
  101. end
  102. % extract results from acc.out
  103. disp(' extracting results ...')
  104. cmd=[gdir,'\read_gp_out < gp.out > gp_out.m'];
  105. [iss,result]=dos(cmd);
  106. if (iss)
  107. cd(wd)
  108. error('read_gp_out failed')
  109. end
  110. gp_out
  111. gpdata=[n_m;lumi_fine;lumi_ee;lumi_ee_high; ...
  112. bpm_vx_1;bpm_sig_vx_1;bpm_vy_1;bpm_sig_vy_1; ...
  113. bpm_vx_2;bpm_sig_vx_2;bpm_vy_2;bpm_sig_vy_2];
  114. % cd back to starting directory
  115. cd(wd)
  116. disp(' ')