/* Converting Astra output particle distribution to Elegant SDDS compliant input * Version 1.00 by Victor Verzilov, Sincrotrone Trieste * 13 Sept 2002 * * update by Mauro Trovo` * 17 Gen 2004 * * update S.M. Lidia * 3 Feb 2006 * * Update by M. Borland * 27 July 2009 * Include betaz in computation of arrival time. * Include correction to x and y using dz*xp and dz*yp, respectively. * * correction of line 149 by CHAIPATTANA SAISA-ARD, Chiang Mai University, Aug. 2017 */ #include #include #include #include main (int argc,char *argv[]) { int i,index,sFlag,dFlag=0; FILE *fin,*fout; float x_r,y_r,z_r,px_r,py_r,pz_r,p_r,clock_r; float x,y,z,px,py,pz,p,clock,mCharge; float dpz; float MEC=510999.06; // rest electron momentum eV/c float t0=1.0e-09; // conversion coefficient from ns to s float clight=2.99792458e08; //speed of light in m/s float betaz, gamma; char *arg=NULL,*par=NULL,foutName[255],description[255]; char *fmt[2]={"%6ld","%14.7e"}; char *Usage="Usage: astra2elegant inputfile \n \ [-output=] \n \ [-description=] \n "; /* Analysing arguments */ if (argc<2){ printf("astra2elegant: too few arguments\n"); printf("%s",Usage); exit(1); } if ((fin=fopen(argv[1],"r"))==NULL){ printf("\n astra2elegant: Cannot open file %s \n",argv[1]); exit(1); } if(argc==2){ strcpy(foutName,argv[1]); strcat(foutName,".sdds"); } else{ for(i=2;i