Changeset 23 in TRACY3 for branches/tracy3-3.10.1b/tracy/tracy/src/soleillib.cc
- Timestamp:
- Dec 6, 2013, 5:12:43 PM (10 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/tracy3-3.10.1b/tracy/tracy/src/soleillib.cc
r11 r23 25 25 none 26 26 27 28 27 Global variables: 29 28 trace … … 38 37 void Get_Disp_dp(void) 39 38 { 40 long i =0L;39 long i; 41 40 // long lastpos = 0; 42 41 const char nomfic[] = "dispersion.out"; … … 96 95 { 97 96 Vector x1; /* tracking coordinates */ 98 long i = 0L, k = 0L, imax = 50 L;97 long i = 0L, k = 0L, imax = 50; 99 98 FILE * outf; 100 99 double dP = 0.0, dP20 = 0.0, dpmax = 0.06; 101 100 Vector2 amp = {0.0, 0.0}, H = {0.0, 0.0}; 102 101 const char nomfic[] = "amp_ind.out"; 103 long lastpos = 0 L;102 long lastpos = 0; 104 103 CellType Celldebut, Cell; 105 104 Vector codvector[Cell_nLocMax]; … … 201 200 { 202 201 CellType Cell; 203 long i =0L;202 long i; 204 203 Vector2 H; 205 204 … … 252 251 { 253 252 CellType Cell; 254 long i =0L;253 long i; 255 254 long lastpos = 1L; 256 255 Vector2 H; … … 462 461 See also LoadApers in nsrl-ii.cc 463 462 J.Zhang 07/10 soleil 464 465 (1) 15/10/2013 Jianfeng Zhang @ LAL466 Replace fgets() by getline() to fix the bug467 to read arbritrary line length.468 463 ****************************************************************************/ 469 464 void ReadCh(const char *AperFile) 470 465 { 471 char Name1[max_str], Name2[max_str]; 472 char *line = NULL; 473 size_t len = 0; 474 ssize_t read; 466 char in[max_str], Name1[max_str], Name2[max_str]; 467 char *line; 475 468 int Fnum1=0, Fnum2=0, Kidnum1=0, Kidnum2=0, k1=0, k2=0; 476 469 int i=0, j=0,LineNum=0; … … 480 473 481 474 fp = file_read(AperFile); 482 if(fp == NULL){ 483 printf("ReadCh(): Error! Failure to read file %s\n", AperFile); 484 exit_(1); 485 } 486 487 printf("\n Loading and setting vacuum apertures to lattice elements...\n"); 488 489 while ((read=getline(&line, &len, fp)) != -1) { 490 491 /* count the line number that has been read*/ 492 LineNum++; 493 if(!prt){ 494 printf("Line # %ld : \n",LineNum); 495 printf("Retrieved line of length %zu :\n",read); 496 printf("%s\n",line); 497 } 498 475 476 printf("\n"); 477 printf("Loading and setting vacuum apertures to lattice elements...\n"); 478 479 while (line=fgets(in, max_str, fp)) { 480 /* kill preceding whitespace generated by "table" key 481 or "space" key, but leave \n 482 so we're guaranteed to have something*/ 483 while(*line == ' ' || *line == '\t') { 484 line++; 485 } 486 /* count the line number that has been read*/ 487 LineNum++; 499 488 /* NOT read comment line or blank line with the end of line symbol '\n','\r' or '\r\n'*/ 500 if (strstr(line, "#") == NULL && line[0] != '\n'&&501 line[0] != '\r'&&strcmp(line,"\r\n") != 0)489 if (strstr(line, "#") == NULL && strcmp(line,"\n") != 0 && 490 strcmp(line,"\r") != 0 &&strcmp(line,"\r\n") != 0) 502 491 /* read the aperture setting */ 503 492 { … … 570 559 // printf("%s", line); 571 560 } 572 free(line);573 561 fclose(fp); 574 562 // turn on the global flag for CheckAmpl() … … 617 605 bool lostF = true; /* Lost particle Flag */ 618 606 Vector x1; /* tracking coordinates */ 619 long i =0L;607 long i; 620 608 Vector2 aperture; 621 609 aperture[0] = 1e0; aperture[1] = 1e0; … … 811 799 #undef nterm 812 800 813 /******************************************************************************* 814 * 815 * 816 * 817 * 818 ******************************************************************************/ 801 819 802 double get_D(const double df_x, const double df_y) 820 803 { 821 double D =0.0;804 double D; 822 805 823 806 const double D_min = -2.0, D_max = -10.0; … … 851 834 Input: 852 835 FmapFile file to save calculated frequency map analysis 853 Nbx horizontal step number 854 Nby vertical step number 855 xmax horizontal maximum amplitude 856 zmax vertical maximum amplitude 857 Nbtour number of turn for tracking 858 energy particle energy offset 859 diffusion flag to calculate tune diffusion/ tune 860 difference between the first Nbtour and last Nbtour 836 Nbx horizontal step number 837 Nby vertical step number 838 xmax horizontal maximum amplitude 839 zmax vertical maximum amplitude 840 Nbtour number of turn for tracking 841 energy particle energy offset 861 842 matlab set file print format for matlab post-process; specific for nsrl-ii 862 843 863 844 Output: 864 status 2true if stable845 status true if stable 865 846 false otherwise 866 847 … … 895 876 int nb_freq[2] = {0, 0}; 896 877 long nturn = Nbtour; 897 bool status 2= true;878 bool status = true; 898 879 struct tm *newtime; 899 880 … … 946 927 // z = z0 + sgn(j)*sqrt((double)abs(j))*zstep; 947 928 // tracking around closed orbit 948 Trac_Simple4DCOD(x,xp,z,zp,energy,ctau,nturn,Tab,&status 2);949 if (status 2) { // if trajectory is stable929 Trac_Simple4DCOD(x,xp,z,zp,energy,ctau,nturn,Tab,&status); 930 if (status) { // if trajectory is stable 950 931 // gets frequency vectors 951 932 Get_NAFF(NTERM2, Nbtour, Tab, fx, fz, nb_freq); … … 993 974 #undef NTERM2 994 975 995 /****************************************************************************/996 /* void fmap(const char *FmapFile, long Nbx, long Nbz, long Nbtour, double xmax, double zmax,997 double energy, bool diffusion, bool loss)998 999 Purpose:1000 1001 1002 Compute a frequency map of Nbx x Nbz points1003 For each set of initial conditions the particle is tracked over1004 Nbtour for an energy offset dp1005 1006 Frequency map is based on fixed beam energy, trace x versus z,1007 or, tracking transverse dynamic aperture for fixed momentum1008 (usually, on-momentum) particle.1009 1010 The stepsize follows a square root law1011 1012 Results in fmap.out1013 1014 Input:1015 FmapFile file to save calculated frequency map analysis1016 Nbx horizontal step number1017 Nby vertical step number1018 xmax horizontal maximum amplitude1019 zmax vertical maximum amplitude1020 Nbtour number of turn for tracking1021 energy particle energy offset1022 diffusion flag to calculate tune diffusion/ tune1023 difference between the first Nbtour and last Nbtour1024 matlab set file print format for matlab post-process; specific for nsrl-ii1025 1026 Output:1027 status2 true if stable1028 false otherwise1029 1030 Return:1031 none1032 1033 Global variables:1034 none1035 1036 Specific functions:1037 Trac_Simple, Get_NAFF1038 1039 Comments:1040 15/10/03 run for the diffusion: nasty patch for retrieving the closed orbit1041 16/02/03 patch removed1042 19/07/11 add interface of file defined by user which is used to save calculated1043 frequency map analysis1044 1045 11/06/2013 Modified by Jianfeng Zhang @ LAL1046 The same as famp(onst char *FmapFile, long Nbx, long Nbz, long Nbtour, double xmax, double zmax,1047 double energy, bool diffusion); but with a flag to print/not print the final information of1048 the particle; if the final turn is not the "Nbtour", then the particle is lost.1049 ****************************************************************************/1050 #define NTERM2 101051 void fmap(const char *FmapFile, long Nbx, long Nbz, long Nbtour, double xmax, double zmax,1052 double energy, bool diffusion, bool printloss)1053 {1054 FILE * outf; //file with the tunes at the grid point1055 FILE *outf_loss; //file with the information of the lost particle1056 long i = 0L, j = 0L;1057 double Tab[DIM][NTURN], Tab0[DIM][NTURN];1058 double fx[NTERM2], fz[NTERM2], fx2[NTERM2], fz2[NTERM2], dfx=0.0, dfz=0.0;1059 double x = 0.0, xp = 0.0, z = 0.0, zp = 0.0;1060 double x0 = 1e-6, xp0 = 0.0, z0 = 1e-6, zp0 = 0.0;1061 const double ctau = 0.0;1062 double xstep = 0.0, zstep = 0.0;1063 double nux1 = 0.0, nuz1 = 0.0, nux2 = 0.0, nuz2 = 0.0;1064 int nb_freq[2] = {0, 0};1065 long nturn = Nbtour;1066 bool status2 = true;1067 1068 struct tm *newtime;1069 1070 //variables of the returned the tracked particle1071 long lastn = 0;1072 long lastpos = 1;1073 ss_vect<double> x1;1074 1075 1076 //if(loss){1077 char FmapLossFile[S_SIZE+5]=" ";1078 strcpy(FmapLossFile,FmapFile);1079 strcat(FmapLossFile,".loss");1080 //}1081 1082 /* Get time and date */1083 time_t aclock;1084 time(&aclock); /* Get time in seconds */1085 newtime = localtime(&aclock); /* Convert time to struct */1086 1087 if (trace) printf("Entering fmap ... results in %s\n\n",FmapFile);1088 1089 /* Opening file */1090 if ((outf = fopen(FmapFile, "w")) == NULL) {1091 fprintf(stdout, "fmap: error while opening file %s\n", FmapFile);1092 exit_(1);1093 }1094 1095 1096 fprintf(outf,"# TRACY III -- %s -- %s \n", FmapFile, asctime2(newtime));1097 fprintf(outf,"# nu = f(x) \n");1098 // fprintf(outf,"# x[mm] z[mm] fx fz"1099 // " dfx dfz D=log_10(sqrt(df_x^2+df_y^2))\n");1100 //1101 fprintf(outf,"# x[m] z[m] fx fz"1102 " dfx dfz\n");1103 1104 1105 //file with lost particle information1106 if(printloss){1107 1108 if ((outf_loss = fopen(FmapLossFile, "w")) == NULL) {1109 fprintf(stdout, "fmap: error while opening file %s\n", FmapLossFile);1110 exit_(1);1111 }1112 1113 fprintf(outf_loss,"# TRACY III -- %s -- %s \n", FmapLossFile, asctime2(newtime));1114 fprintf(outf_loss,"# information of the lost particle: "1115 " lostp = 0 (no particle lost /1(horizontal) /2(vertical) /3(longitudinal) plane) \n");1116 1117 fprintf(outf_loss,"# x[m] z[m] Nturn lostp S[m] x[m]"1118 " xp[rad] z[m] zp[rad] delta ctau\n");1119 }1120 1121 if ((Nbx < 1) || (Nbz < 1))1122 fprintf(stdout,"fmap: Error Nbx=%ld Nbz=%ld\n",Nbx,Nbz);1123 1124 // steps in both planes1125 xstep = xmax/sqrt((double)Nbx);1126 zstep = zmax/sqrt((double)Nbz);1127 1128 // double number of turn if diffusion to compute1129 if (diffusion) nturn = 2*Nbtour;1130 1131 // px and pz zeroed1132 xp = xp0;1133 zp = zp0;1134 1135 // Tracking part + NAFF1136 for (i = 0; i <= Nbx; i++) {1137 x = x0 + sqrt((double)i)*xstep;1138 // for (i = -Nbx; i <= Nbx; i++) {1139 // x = x0 + sgn(i)*sqrt((double)abs(i))*xstep;1140 // if (!matlab) fprintf(outf,"\n");1141 fprintf(stdout,"\n");1142 for (j = 0; j<= Nbz; j++) {1143 z = z0 + sqrt((double)j)*zstep;1144 // for (j = -Nbz; j<= Nbz; j++) {1145 // z = z0 + sgn(j)*sqrt((double)abs(j))*zstep;1146 1147 //print out the lost information1148 if(printloss)1149 Trac_Simple4DCOD(x,xp,z,zp,energy,ctau,nturn,Tab,lastn, lastpos, x1, &status2);1150 else1151 // tracking around closed orbit1152 Trac_Simple4DCOD(x,xp,z,zp,energy,ctau,nturn,Tab,&status2);1153 1154 if (status2) { // if trajectory is stable1155 // gets frequency vectors1156 Get_NAFF(NTERM2, Nbtour, Tab, fx, fz, nb_freq);1157 Get_freq(fx,fz,&nux1,&nuz1); // gets nux and nuz1158 if (diffusion) { // diffusion1159 // shift data for second round NAFF1160 Get_Tabshift(Tab,Tab0,Nbtour,Nbtour);1161 // gets frequency vectors1162 Get_NAFF(NTERM2, Nbtour, Tab0, fx2, fz2, nb_freq);1163 Get_freq(fx2,fz2,&nux2,&nuz2); // gets nux and nuz1164 }1165 } // unstable trajectory1166 else { //zeroing output1167 nux1 = 0.0; nuz1 = 0.0;1168 nux2 = 0.0; nuz2 = 0.0;1169 }1170 1171 // printout value1172 if (!diffusion){1173 // fprintf(outf,"%14.6e %14.6e %14.6e %14.6e\n",1174 // 1e3*x, 1e3*z, nux1, nuz1);1175 // fprintf(stdout,"%14.6e %14.6e %14.6e %14.6e\n",1176 // 1e3*x, 1e3*z, nux1, nuz1);1177 fprintf(outf,"%10.6e %10.6e %10.6e %10.6e\n",1178 x, z, nux1, nuz1);1179 fprintf(stdout,"%14.6e %14.6e %14.6e %14.6e\n",1180 x, z, nux1, nuz1);1181 }1182 else {1183 dfx = nux1 - nux2; dfz = nuz1 - nuz2;1184 fprintf(outf,"%10.6e %10.6e %10.6e %10.6e %10.6e %10.6e\n",1185 x, z, nux1, nuz1, dfx, dfz);1186 fprintf(stdout,"%14.6e %14.6e %14.6e %14.6e %14.6e %14.6e\n",1187 x, z, nux1, nuz1, dfx, dfz);1188 }1189 1190 //print out the information of the lost particle1191 if(printloss)1192 fprintf(outf_loss, "%6.3e %6.3e %8ld %3d %+12.6f %+10.6f %+10.6f %+10.6f %+10.6f %+10.6f %+10.6f \n",1193 x, z, lastn,status.lossplane, Cell[lastpos].S, x1[0],x1[1],1194 x1[2], x1[3], x1[4], x1[5]);1195 1196 }1197 }1198 1199 fclose(outf);1200 if(printloss)1201 fclose(outf_loss);1202 }1203 #undef NTERM21204 1205 976 1206 977 /****************************************************************************/ … … 1253 1024 #define NTERM2 10 1254 1025 void fmap_p(const char *FmapFile_p, long Nbx, long Nbz, long Nbtour, double xmax, 1255 double zmax, double energy, bool diffusion, bool printloss,int numprocs, int myid)1026 double zmax, double energy, bool diffusion, int numprocs, int myid) 1256 1027 { 1257 1028 FILE * outf; 1258 FILE *outf_loss; //file with the information of the lost particle1259 1029 long i = 0L, j = 0L; 1260 1030 double Tab[DIM][NTURN], Tab0[DIM][NTURN]; 1261 double fx[NTERM2], fz[NTERM2], fx2[NTERM2], fz2[NTERM2], dfx =0.0, dfz=0.0;1031 double fx[NTERM2], fz[NTERM2], fx2[NTERM2], fz2[NTERM2], dfx, dfz; 1262 1032 double x = 0.0, xp = 0.0, z = 0.0, zp = 0.0; 1263 1033 double x0 = 1e-6, xp0 = 0.0, z0 = 1e-6, zp0 = 0.0; … … 1267 1037 int nb_freq[2] = {0, 0}; 1268 1038 long nturn = Nbtour; 1269 bool status 2= true;1039 bool status = true; 1270 1040 struct tm *newtime; 1271 1041 … … 1274 1044 strcat(FmapFile,FmapFile_p); 1275 1045 printf("%s\n",FmapFile); 1276 1277 //variables of the returned the tracked particle1278 long lastn = 0;1279 long lastpos = 1;1280 ss_vect<double> x1;1281 1282 char FmapLossFile[S_SIZE+5]=" ";1283 strcpy(FmapLossFile,FmapFile);1284 strcat(FmapLossFile,".loss");1285 1286 1046 1287 1047 /* Get time and date */ … … 1299 1059 } 1300 1060 1301 //file with lost particle information1302 if(printloss){1303 if ((outf_loss = fopen(FmapLossFile, "w")) == NULL) {1304 fprintf(stdout, "fmap: error while opening file %s\n", FmapLossFile);1305 exit_(1);1306 }1307 }1308 1309 1061 if(myid==0) 1310 1062 { … … 1312 1064 fprintf(outf,"# nu = f(x) \n"); 1313 1065 fprintf(outf,"# x[m] z[m] fx fz dfx dfz\n"); 1314 1315 if(printloss){ 1316 fprintf(outf_loss,"# TRACY III -- %s -- %s \n", FmapLossFile, asctime2(newtime)); 1317 fprintf(outf_loss,"# information of the lost particle: " 1318 " lostp = 0 (no particle lost /1(horizontal) /2(vertical) /3(longitudinal) plane) \n"); 1319 1320 fprintf(outf_loss,"# x[m] z[m] Nturn lostp S[m] x[m]" 1321 " xp[rad] z[m] zp[rad] delta ctau\n"); 1322 } 1323 } 1066 } 1324 1067 1325 1068 if ((Nbx < 1) || (Nbz < 1)) … … 1370 1113 1371 1114 // tracking around closed orbit 1372 if(printloss) 1373 Trac_Simple4DCOD(x,xp,z,zp,energy,ctau,nturn,Tab,lastn, lastpos, x1, &status2); 1374 else 1375 Trac_Simple4DCOD(x,xp,z,zp,energy,ctau,nturn,Tab,&status2); 1376 1377 1378 if (status2) // if trajectory is stable 1115 Trac_Simple4DCOD(x,xp,z,zp,energy,ctau,nturn,Tab,&status); 1116 if (status) // if trajectory is stable 1379 1117 { 1380 1118 // gets frequency vectors … … 1410 1148 fprintf(stdout,"%14.6e %14.6e %14.6e %14.6e %14.6e %14.6e\n", x, z, nux1, nuz1, dfx, dfz); 1411 1149 } 1412 1413 //print out the information of the lost particle1414 if(printloss)1415 fprintf(outf_loss, "%6.3e %6.3e %8ld %3d %+12.6f %+10.6f %+10.6f %+10.6f %+10.6f %+10.6f %+10.6f \n",1416 x, z, lastn,status.lossplane, Cell[lastpos].S, x1[0],x1[1],1417 x1[2], x1[3], x1[4], x1[5]);1418 1150 } 1419 1151 } 1420 1152 1421 1153 fclose(outf); 1422 1423 if(printloss)1424 fclose(outf_loss);1425 1426 1154 } 1427 1155 #undef NTERM2 … … 1453 1181 emax maximum energy 1454 1182 z vertical amplitude 1455 diffusion flag to calculate tune diffusion/ tune 1456 difference between the first Nbtour and last Nbtour 1183 diffusion flag to calculate tune diffusion 1457 1184 matlab set file print format for matlab post-process; specific for nsrl-ii 1458 1185 Output: 1459 status 2true if stable1186 status true if stable 1460 1187 false otherwise 1461 1188 … … 1474 1201 is negative for negative enrgy offset since this is true for the cod 1475 1202 19/07/11 add features to save calculated fmapdp in the user defined file 1476 1477 18/06/2013 by Jianfeng Zhang @ LAL1478 1479 Add bool flag to print out the last information of the tracked particle1480 1203 ****************************************************************************/ 1481 1204 #define NTERM2 10 1482 1205 void fmapdp(const char *FmapdpFile, long Nbx, long Nbe, long Nbtour, double xmax, double emax, 1483 double z, bool diffusion , bool printloss)1206 double z, bool diffusion) 1484 1207 { 1485 1208 FILE * outf; 1486 FILE *outf_loss; //file with the information of the lost particle1487 1209 long i = 0L, j = 0L; 1488 1210 double Tab[DIM][NTURN], Tab0[DIM][NTURN]; 1489 double fx[NTERM2], fz[NTERM2], fx2[NTERM2], fz2[NTERM2], dfx =0.0, dfz=0.0;1211 double fx[NTERM2], fz[NTERM2], fx2[NTERM2], fz2[NTERM2], dfx, dfz; 1490 1212 double x = 0.0, xp = 0.0, zp = 0.0, dp = 0.0, ctau = 0.0; 1491 1213 double x0 = 1e-6, xp0 = 0.0, zp0 = 0.0; … … 1495 1217 int nb_freq[2] = {0, 0}; 1496 1218 long nturn = Nbtour; 1497 bool status 2=true;1219 bool status=true; 1498 1220 struct tm *newtime; 1499 1500 //variables of the returned the tracked particle1501 long lastn = 0;1502 long lastpos = 1;1503 ss_vect<double> x1;1504 1505 char FmapdpLossFile[S_SIZE+5]=" ";1506 strcpy(FmapdpLossFile,FmapdpFile);1507 strcat(FmapdpLossFile,".loss");1508 1221 1509 1222 /* Get time and date */ … … 1514 1227 if (diffusion && globval.Cavity_on == false) nturn = 2*Nbtour; 1515 1228 1516 if (trace) printf("Entering fmap dp... results in %s\n\n",FmapdpFile);1229 if (trace) printf("Entering fmap ... results in %s\n\n",FmapdpFile); 1517 1230 1518 1231 /* Opening file */ … … 1527 1240 fprintf(outf,"# dp[m] x[m] fx fz dfx dfz\n"); 1528 1241 1529 1530 //file with lost particle information1531 if(printloss){1532 1533 if ((outf_loss = fopen(FmapdpLossFile, "w")) == NULL) {1534 fprintf(stdout, "fmapdp: error while opening file %s\n", FmapdpLossFile);1535 exit_(1);1536 }1537 1538 fprintf(outf_loss,"# TRACY III -- %s -- %s \n", FmapdpLossFile, asctime2(newtime));1539 fprintf(outf_loss,"# information of the lost particle: "1540 " lostp = 0 (no particle lost /1(horizontal) /2(vertical) /3(longitudinal) plane) \n");1541 1542 fprintf(outf_loss,"# dp x[m] Nturn lostp S[m] x[m]"1543 " xp[rad] z[m] zp[rad] delta ctau\n");1544 }1545 1546 1242 if ((Nbx <= 1) || (Nbe <= 1)) 1547 1243 fprintf(stdout,"fmapdp: Error Nbx=%ld Nbe=%ld\n",Nbx,Nbe); … … 1566 1262 diffusion = false; 1567 1263 } 1568 else {1264 else 1569 1265 // x = x0 + sgn(j)*sqrt((double)abs(j))*xstep; 1570 1266 x = x0 + sqrt((double)j)*xstep; 1571 } 1572 1573 if(printloss) 1574 Trac_Simple4DCOD(x,xp,z,zp,dp,ctau,nturn,Tab,lastn, lastpos, x1, &status2); 1575 else 1576 Trac_Simple4DCOD(x,xp,z,zp,dp,ctau,nturn,Tab,&status2); 1577 1578 if (status2) { 1267 Trac_Simple4DCOD(x,xp,z,zp,dp,ctau,nturn,Tab,&status); 1268 if (status) { 1579 1269 Get_NAFF(NTERM2, Nbtour, Tab, fx, fz, nb_freq); 1580 1270 Get_freq(fx,fz,&nux1,&nuz1); // gets nux and nuz … … 1610 1300 dp, x, nux1, nuz2, dfx, dfz); 1611 1301 } 1612 1613 if(printloss)1614 fprintf(outf_loss," %-+8.3f %-+8.3f %-8ld %2d %+12.3f %+10.6f %+10.6f %+10.6f %+10.6f %+10.6f %+10.6f \n",1615 dp, x, lastn,status.lossplane, Cell[lastpos].S, x1[0],x1[1], x1[2], x1[3], x1[4], x1[5]);1616 1617 1302 } 1618 1303 } 1619 1304 1620 1305 fclose(outf); 1621 1622 if(printloss)1623 fclose(outf_loss);1624 1306 } 1625 1307 #undef NTERM2 … … 1656 1338 1657 1339 Output: 1658 status 2true if stable1340 status true if stable 1659 1341 false otherwise 1660 1342 … … 1671 1353 14/11/2011 add features to parallel calculate fmapdp. 1672 1354 Merged with the version written by Mao-sen Qiu at Taiwan light source. 1673 1674 18/06/2013 by Jianfeng Zhang @ LAL1675 Add bool flag to print out the last information of the tracked particle1676 1355 ****************************************************************************/ 1677 1356 #define NTERM2 10 1678 1357 void fmapdp_p(const char *FmapdpFile_p, long Nbx, long Nbe, long Nbtour, double xmax, 1679 double emax, double z, bool diffusion, bool printloss,int numprocs, int myid)1358 double emax, double z, bool diffusion, int numprocs, int myid) 1680 1359 { 1681 1360 FILE * outf; 1682 FILE *outf_loss; //file with the information of the lost particle1683 1361 long i = 0L, j = 0L; 1684 1362 double Tab[DIM][NTURN], Tab0[DIM][NTURN]; 1685 double fx[NTERM2], fz[NTERM2], fx2[NTERM2], fz2[NTERM2], dfx =0.0, dfz=0.0;1363 double fx[NTERM2], fz[NTERM2], fx2[NTERM2], fz2[NTERM2], dfx, dfz; 1686 1364 double x = 0.0, xp = 0.0, zp = 0.0, dp = 0.0, ctau = 0.0; 1687 1365 double x0 = 1e-6, xp0 = 0.0, zp0 = 0.0; … … 1691 1369 int nb_freq[2] = {0, 0}; 1692 1370 long nturn = Nbtour; 1693 bool status 2=true;1371 bool status=true; 1694 1372 struct tm *newtime; 1695 1373 … … 1699 1377 printf("%s\n",FmapdpFile); 1700 1378 1701 //variables of the returned the tracked particle1702 long lastn = 0;1703 long lastpos = 1;1704 ss_vect<double> x1;1705 1706 char FmapdpLossFile[S_SIZE+5]=" ";1707 strcpy(FmapdpLossFile,FmapdpFile);1708 strcat(FmapdpLossFile,".loss");1709 1710 1379 /* Get time and date */ 1711 1380 time_t aclock; … … 1721 1390 fprintf(stdout, "fmapdp: error while opening file %s\n", FmapdpFile); 1722 1391 exit_(1); 1723 }1724 1725 if(printloss){1726 if ((outf_loss = fopen(FmapdpLossFile, "w")) == NULL) {1727 fprintf(stdout, "fmapdp: error while opening file %s\n", FmapdpLossFile);1728 exit_(1);1729 }1730 1392 } 1731 1393 … … 1736 1398 // fprintf(outf,"# dp[%%] x[mm] fx fz dfx dfz\n"); 1737 1399 fprintf(outf,"# dp[m] x[m] fx fz dfx dfz\n"); 1738 1739 1740 if(printloss){ 1741 fprintf(outf_loss,"# TRACY III -- %s -- %s \n", FmapdpLossFile, asctime2(newtime)); 1742 fprintf(outf_loss,"# information of the lost particle: " 1743 " lostp = 0 (no particle lost /1(horizontal) /2(vertical) /3(longitudinal) plane) \n"); 1744 1745 fprintf(outf_loss,"# dp x[m] Nturn lostp S[m] x[m]" 1746 " xp[rad] z[m] zp[rad] delta ctau\n"); 1747 } 1748 } 1400 } 1749 1401 1750 1402 if ((Nbx <= 1) || (Nbe <= 1)) … … 1796 1448 diffusion = false; 1797 1449 } 1798 else {1450 else 1799 1451 // x = x0 + sgn(j)*sqrt((double)abs(j))*xstep; 1800 1452 x = x0 + sqrt((double)j)*xstep; 1801 } 1802 1803 if(printloss) 1804 Trac_Simple4DCOD(x,xp,z,zp,dp,ctau,nturn,Tab,lastn, lastpos, x1, &status2); 1805 else 1806 Trac_Simple4DCOD(x,xp,z,zp,dp,ctau,nturn,Tab,&status2); 1807 1808 if (status2) { 1453 Trac_Simple4DCOD(x,xp,z,zp,dp,ctau,nturn,Tab,&status); 1454 if (status) { 1809 1455 Get_NAFF(NTERM2, Nbtour, Tab, fx, fz, nb_freq); 1810 1456 Get_freq(fx,fz,&nux1,&nuz1); // gets nux and nuz … … 1840 1486 dp, x, nux1, nuz2, dfx, dfz); 1841 1487 } 1842 1843 if(printloss)1844 fprintf(outf_loss," %-+8.3f %-+8.3f %-8ld %2d %+12.3f %+10.6f %+10.6f %+10.6f %+10.6f %+10.6f %+10.6f \n",1845 dp, x, lastn,status.lossplane, Cell[lastpos].S, x1[0],x1[1], x1[2], x1[3], x1[4], x1[5]);1846 1847 1488 } 1848 1489 } 1849 1490 1850 1491 fclose(outf); 1851 1852 if(printloss)1853 fclose(outf_loss);1854 1492 } 1855 1493 #undef NTERM2 … … 1897 1535 double nux1 = 0.0, nuz1 = 0.0; 1898 1536 int nb_freq[2] = {0, 0}; 1899 bool status 2= true;1537 bool status = true; 1900 1538 struct tm *newtime; 1901 1539 … … 1929 1567 ctau = ctau0; 1930 1568 1931 Trac_Simple4DCOD(x,xp,z,zp,dp,ctau,Nbtour,Tab,&status 2); // tracking around closed orbit1932 if (status 2) {1569 Trac_Simple4DCOD(x,xp,z,zp,dp,ctau,Nbtour,Tab,&status); // tracking around closed orbit 1570 if (status) { 1933 1571 Get_NAFF(NTERM, Nbtour, Tab, fx, fz, nb_freq); // get frequency vectors 1934 1572 Get_freq(fx,fz,&nux1,&nuz1); // gets nux and nuz … … 1936 1574 else { 1937 1575 nux1 = 0.0; nuz1 = 0.0; 1938 status 2= true;1576 status = true; 1939 1577 } 1940 1578 … … 1991 1629 FILE *outf; 1992 1630 const char *fic = phasefile; 1993 int i =0;1994 bool status 2=false;1631 int i; 1632 bool status; 1995 1633 struct tm *newtime; 1996 1634 … … 2025 1663 } 2026 1664 2027 Trac_Simple6DCOD(x,xp,y,yp,energy,ctau,Nbtour,Tab,&status2); 2028 1665 Trac_Simple6DCOD(x,xp,y,yp,energy,ctau,Nbtour,Tab,&status); 2029 1666 for (i = 0; i < Nbtour; i++) { 2030 1667 fprintf(outf,"% .5e % .5e % .5e % .5e % .5e % .5e\n", 2031 1668 Tab[0][i],Tab[1][i],Tab[2][i],Tab[3][i],Tab[4][i],Tab[5][i]); 2032 1669 } 2033 // cout << "status is: " << status2 << endl;2034 1670 fclose(outf); 2035 1671 } … … 2069 1705 FILE *outf; 2070 1706 const char *fic="phasepoly.out"; 2071 long lastpos = 0 L,lastn = 0L;2072 int i =0,j=0;2073 double x =0.0, z=0.0, px=0.0, pz=0.0, delta=0.0, ctau=0.0;1707 long lastpos = 0,lastn = 0; 1708 int i,j; 1709 double x, z, px, pz, delta, ctau; 2074 1710 double ex = 1368E-9, el = 1.78E-4; 2075 1711 double betax = 9.0, /*betaz = 8.2, */betal = 45.5; … … 2163 1799 double start = 0.0, step = 0.0; 2164 1800 double x = 0.0, px = 0.0, z = 0.0, pz = 0.0, delta = 0.0, ctau = 0.0; 2165 bool status 2= true;1801 bool status = true; 2166 1802 struct tm *newtime; 2167 1803 … … 2222 1858 fprintf(stdout,"% .5e % .5e % .5e % .5e % .5e % .5e\n", 2223 1859 x,px,z,pz,delta,ctau); 2224 Trac_Simple4DCOD(x,px,z,pz,delta,ctau,Nbtour,Tab,&status 2);1860 Trac_Simple4DCOD(x,px,z,pz,delta,ctau,Nbtour,Tab,&status); 2225 1861 for (i = 0; i < Nbtour; i++) { 2226 1862 fprintf(outf,"% .5e % .5e % .5e % .5e % .5e % .5e\n", … … 2265 1901 FILE *outf; 2266 1902 const char fic[] = "check_ampl.out"; 2267 int i =0;1903 int i; 2268 1904 2269 1905 if ((outf = fopen(fic, "w")) == NULL) … … 2320 1956 FILE *outf; 2321 1957 const char fic[] = "enveloppe.out"; 2322 int i =0,j=0;1958 int i,j ; 2323 1959 CellType Cell; 2324 1960 … … 3562 3198 FILE *fi; 3563 3199 const char fic_skew[] = "QT-solamor_2_3.dat"; 3564 int i =0;3200 int i; 3565 3201 double theta[500]; /* array for skew quad tilt*/ 3566 double b2 =0.0, mKL=0.0;3202 double b2, mKL; 3567 3203 CellType Cell; 3568 long mOrder =0L;3204 long mOrder; 3569 3205 3570 3206 int nquad = 0; /* Number of skew quadrupoles */ … … 3767 3403 struct tm *newtime; // for time 3768 3404 Vector codvector[Cell_nLocMax]; 3769 bool cavityflag =false, radiationflag=false;3405 bool cavityflag, radiationflag; 3770 3406 bool trace=true; 3771 3407 … … 4165 3801 struct tm *newtime; // for time 4166 3802 Vector codvector[Cell_nLocMax]; 4167 bool cavityflag =false, radiationflag=false;3803 bool cavityflag, radiationflag; 4168 3804 bool trace=true; 4169 3805 … … 4650 4286 const char xfic[] = "xspectrum.out"; 4651 4287 const char zfic[] = "zspectrum.out"; 4652 long i =0L, j=0L, k=0L;4288 long i, j, k; 4653 4289 #define nterm2 20 4654 4290 double Tab[6][NTURN], fx[nterm2], fz[nterm2], fx2[nterm2], fz2[nterm2]; … … 4658 4294 int nb_freq[2] = {0, 0}; 4659 4295 long nturn = Nbtour; 4660 bool status 2=true;4296 bool status=true; 4661 4297 struct tm *newtime; 4662 4298 … … 4699 4335 for (j = 0; j<= Nbz; j++) { 4700 4336 z = z0 + sqrt((double)j)*zstep; 4701 Trac_Simple4DCOD(x,xp,z,zp,energy,0.0,nturn,Tab,&status 2);4702 if (status 2) {4337 Trac_Simple4DCOD(x,xp,z,zp,energy,0.0,nturn,Tab,&status); 4338 if (status) { 4703 4339 Get_NAFF(nterm2, Nbtour, Tab, fx, fz, nb_freq); 4704 4340 } … … 4779 4415 long nmax, long pos, long &lastn, long &lastpos, FILE *outf1) 4780 4416 { 4781 bool lostF =false; /* Lost particle Flag */4417 bool lostF; /* Lost particle Flag */ 4782 4418 Vector x1; /* tracking coordinates */ 4783 4419 Vector2 aperture; … … 4792 4428 getelem(pos-1,&Cell); 4793 4429 4794 if ( trace) printf("dp= % .5e %% xcod= % .5e mm zcod= % .5e mm \n",4430 if (!trace) printf("dp= % .5e %% xcod= % .5e mm zcod= % .5e mm \n", 4795 4431 dp*1e2, Cell.BeamPos[0]*1e3, Cell.BeamPos[2]*1e3); 4796 4432 … … 4863 4499 CellType Cell; 4864 4500 int qlist[320]; 4865 int nquad=0, i =0;4501 int nquad=0, i; 4866 4502 double A = 0.0; 4867 4503 … … 4897 4533 /****************************************************************************/ 4898 4534 /* void fmapfull(long Nbx, long Nbz, long Nbtour, double xmax, double zmax, 4899 double energy, bool *status 2)4535 double energy, bool *status) 4900 4536 4901 4537 Purpose: … … 4917 4553 4918 4554 Output: 4919 status 2true if stable4555 status true if stable 4920 4556 false otherwise 4921 4557 … … 4939 4575 FILE * outf; 4940 4576 const char fic[] = "fmapfull.out"; 4941 int i =0, j=0, k=0;4577 int i, j, k; 4942 4578 double Tab[DIM][NTURN], Tab0[DIM][NTURN]; 4943 4579 double fx[NTERM], fz[NTERM], fx2[NTERM], fz2[NTERM]; … … 4948 4584 double nux1[NTERM], nuz1[NTERM],nux2[NTERM], nuz2[NTERM]; 4949 4585 long nturn = Nbtour; 4950 bool status 2=true;4586 bool status=true; 4951 4587 struct tm *newtime; 4952 4588 char name[14]; … … 5008 4644 for (j = 0; j<= Nbz; j++) { 5009 4645 z = z0 + sqrt((double)j)*zstep; 5010 Trac_Simple4DCOD(x,xp,z,zp,energy,0.0,nturn,Tab,&status 2);5011 5012 if (status 2) {4646 Trac_Simple4DCOD(x,xp,z,zp,energy,0.0,nturn,Tab,&status); 4647 4648 if (status) { 5013 4649 Get_NAFF(NTERM, Nbtour, Tab, fx, fz, nb_freq); 5014 4650 … … 5091 4727 /****************************************************************************/ 5092 4728 /* void Dyna(long Nbx, long Nbz, long Nbtour, double xmax, double zmax, 5093 double energy, bool *status 2)4729 double energy, bool *status) 5094 4730 5095 4731 Purpose: … … 5111 4747 5112 4748 Output: 5113 status 2true if stable4749 status true if stable 5114 4750 false otherwise 5115 4751 … … 5133 4769 FILE * outf; 5134 4770 const char fic[] = "dyna.out"; 5135 long i =0, j=0;4771 long i, j; 5136 4772 double Tab[6][NTURN], fx[NTERM2], fz[NTERM2]; 5137 4773 double x = 0.0, xp = 0.0, z = 0.0, zp = 0.0; … … 5140 4776 int nb_freq[2] = {0, 0}; 5141 4777 long nturn = Nbtour; 5142 bool status 2=true;4778 bool status=true; 5143 4779 struct tm *newtime; 5144 4780 … … 5174 4810 for (j = 0; j<= Nbz; j++) { 5175 4811 z = z0 + sqrt((double)j)*zstep; 5176 Trac_Simple4DCOD(x,xp,z,zp,energy,0.0,nturn,Tab,&status 2);5177 if (status 2) Get_NAFF(NTERM2, Nbtour, Tab, fx, fz, nb_freq);4812 Trac_Simple4DCOD(x,xp,z,zp,energy,0.0,nturn,Tab,&status); 4813 if (status) Get_NAFF(NTERM2, Nbtour, Tab, fx, fz, nb_freq); 5178 4814 else { 5179 4815 fx[0] = 0.0; fz[0] = 0.0; 5180 4816 } 5181 fprintf(outf,"%14.6e %14.6e %14.6e %14.6e %d\n", x, z, fx[0], fz[0], status 2);5182 fprintf(stdout,"%14.6e %14.6e %14.6e %14.6e %d\n", x, z, fx[0], fz[0], status 2);4817 fprintf(outf,"%14.6e %14.6e %14.6e %14.6e %d\n", x, z, fx[0], fz[0], status); 4818 fprintf(stdout,"%14.6e %14.6e %14.6e %14.6e %d\n", x, z, fx[0], fz[0], status); 5183 4819 if (diffusion) { 5184 if (status 2) Get_NAFF(NTERM2, Nbtour, Tab, fx, fz, nb_freq);5185 fprintf(outf,"%14.6e %14.6e %14.6e %14.6e %d\n", x, z, fx[0], fz[0], status 2);5186 fprintf(stdout,"%14.6e %14.6e %14.6e %14.6e %d\n", x, z, fx[0], fz[0], status 2);4820 if (status) Get_NAFF(NTERM2, Nbtour, Tab, fx, fz, nb_freq); 4821 fprintf(outf,"%14.6e %14.6e %14.6e %14.6e %d\n", x, z, fx[0], fz[0], status); 4822 fprintf(stdout,"%14.6e %14.6e %14.6e %14.6e %d\n", x, z, fx[0], fz[0], status); 5187 4823 } 5188 4824 } … … 5196 4832 for (j = 0; j<= Nbz; j++) { 5197 4833 z = z0 + sqrt((double)j)*zstep; 5198 Trac_Simple4DCOD(x,xp,z,zp,energy,0.0,nturn,Tab,&status 2);5199 if (status 2) Get_NAFF(NTERM2, Nbtour, Tab, fx, fz, nb_freq);4834 Trac_Simple4DCOD(x,xp,z,zp,energy,0.0,nturn,Tab,&status); 4835 if (status) Get_NAFF(NTERM2, Nbtour, Tab, fx, fz, nb_freq); 5200 4836 else { 5201 4837 fx[0] = 0.0; fz[0] =0.0; 5202 4838 } 5203 fprintf(outf,"%14.6e %14.6e %14.6e %14.6e %d\n", x, z, fx[0], fz[0], status 2);5204 fprintf(stdout,"%14.6e %14.6e %14.6e %14.6e %d\n", x, z, fx[0], fz[0], status 2);4839 fprintf(outf,"%14.6e %14.6e %14.6e %14.6e %d\n", x, z, fx[0], fz[0], status); 4840 fprintf(stdout,"%14.6e %14.6e %14.6e %14.6e %d\n", x, z, fx[0], fz[0], status); 5205 4841 if (diffusion) { 5206 if (status 2) Get_NAFF(NTERM2, Nbtour, Tab, fx, fz, nb_freq);4842 if (status) Get_NAFF(NTERM2, Nbtour, Tab, fx, fz, nb_freq); 5207 4843 fprintf(outf,"%14.6e %14.6e %14.6e %14.6e\n", x, z, fx[0], fz[0]); 5208 4844 fprintf(stdout,"%14.6e %14.6e %14.6e %14.6e\n", x, z, fx[0], fz[0]); … … 5247 4883 FILE *outf; 5248 4884 const char fic[] = "phase2.out"; 5249 long lastpos = 0 L,lastn = 0L;4885 long lastpos = 0,lastn = 0; 5250 4886 struct tm *newtime; 5251 4887 … … 5373 5009 int i,j; 5374 5010 bool chroma=true, trace=false; 5375 bool radiationflag =false, cavityflag=false;5011 bool radiationflag, cavityflag; 5376 5012 double dP = 0.0; 5377 5013 double diffcmu = 0.0, /* cos(mu1) - cos(mu2)*/ … … 5795 5431 void PhaseLongitudinalHamiltonien(void) 5796 5432 { 5797 long i =0L,j=0L;5433 long i,j; 5798 5434 const double t = T; // To get a one turn map 5799 double phi =0.0, delta=0.0, H0=0.0;5435 double phi, delta, H0; 5800 5436 long imax = 1000L, // turn number 5801 5437 jmax = 25L; // starting condition number … … 5993 5629 } 5994 5630 5995 /******************************************************************************* 5996 * 5997 * 5998 * 5999 * 6000 ******************************************************************************/ 5631 6001 5632 double EnergySmall(double *X, double irho) 6002 5633 { 6003 double A =0.0, B=0.0;5634 double A, B; 6004 5635 double h = irho; 6005 5636 … … 6008 5639 return (A+B); 6009 5640 } 6010 /******************************************************************************* 6011 * 6012 * 6013 * 6014 * 6015 ******************************************************************************/ 5641 6016 5642 double EnergyDrift(double *X) 6017 5643 { 6018 double A =0.0;5644 double A; 6019 5645 6020 5646 A = (X[1]*X[1]+X[3]*X[3])/2.0/(1.0+X[4]); … … 6055 5681 FILE *outf; 6056 5682 const char fic[] = "enveloppe2.out"; 6057 int i =0,j=0;5683 int i,j ; 6058 5684 CellType Cell; 6059 5685 /* Array for Enveloppes */ … … 6185 5811 void set_RFVoltage(const int Fnum, const double V_RF){ 6186 5812 6187 int k =0, n = 0;5813 int k, n = 0; 6188 5814 6189 5815 … … 6232 5858 01/2011 Fix the bug for reading the end of line symbol "\n" , "\r",'\r\n' 6233 5859 at different operation system 6234 04/2011 Change the set of 'seed' for rms error in file, now it's mandatory. 6235 10/2013 Jianfeng Zhang @ LAL 6236 Fix the bug of fgets() to read lines of arbritrary length. 5860 04/2011 Change the set of 'seed' for rms error in file, now it's mandatory. 6237 5861 *****************************************************************************************************/ 6238 5862 void ReadFieldErr(const char *FieldErrorFile) 6239 5863 { 6240 bool rms=false, set_rnd = false; 6241 char name[max_str],keywrd[max_str], *prm; 6242 char *line = NULL; 6243 size_t len = 0; 6244 ssize_t read; 5864 bool rms, set_rnd = false; 5865 char in[max_str], name[max_str],keywrd[max_str], *prm; 5866 char *line; 6245 5867 int n = 0; /* field error order*/ 6246 5868 int LineNum = 0; 6247 int seed_val = 0; // random seed number for the rms error5869 int seed_val; // random seed number for the rms error 6248 5870 double Bn = 0.0, An = 0.0, r0 = 0.0; /* field error components and radius when the field error is measured */ 6249 5871 /* conversion number from A to T.m for soleil*/ … … 6254 5876 6255 5877 inf = file_read(FieldErrorFile); 6256 if(inf == NULL){ 6257 printf("ReadFieldErr(): Error! Failure to read file %s !\n",FieldErrorFile); 6258 exit_(1); 6259 } 6260 5878 6261 5879 printf("\n"); 6262 5880 /* read lines*/ 6263 while ((read=getline(&line, &len, inf)) != -1) { 5881 while (line=fgets(in, max_str, inf)) { 5882 5883 /* kill preceding whitespace generated by "table" key 5884 or "space" key, but leave \n 5885 so we're guaranteed to have something*/ 5886 while(*line == ' ' || *line == '\t') { 5887 line++; 5888 } 6264 5889 6265 5890 /* count line number for debug*/ 6266 5891 LineNum++; 6267 if(prt){6268 printf("Line # %ld \n",LineNum);6269 printf("Retrieved line of length %zu : \n",read);6270 printf("%s\n",line);6271 }6272 5892 6273 5893 /* check the line is whether comment line or null line*/ … … 6287 5907 /*read and assign the key words and measure radius*/ 6288 5908 sscanf(line, " %*s %s %lf",keywrd, &r0); 6289 if ( !prt) printf("\nsetting <%s> multipole error to: %-5s r0 = %7.1le\n",keywrd,name,r0);5909 if (prt) printf("\nsetting <%s> multipole error to: %-5s r0 = %7.1le\n",keywrd,name,r0); 6290 5910 6291 5911 rms = (strcmp("rms", keywrd) == 0)? true : false; … … 6311 5931 sscanf(prm, "%lf", &An); 6312 5932 6313 if ( !prt)5933 if (prt) 6314 5934 printf(" n = %2d, Bn = %9.1e, An = %9.1e\n", n, Bn, An); 6315 5935 … … 6335 5955 // printf("%s", line); 6336 5956 } 6337 free(line); 5957 6338 5958 fclose(inf); 6339 5959 } … … 6393 6013 AddFieldValues_fam(Fnum,keywrd, r0, n, Bn, An); 6394 6014 else 6395 printf(" AddFieldErrors(): Error! undefined lattice element %s !\n", name);6015 printf("SetFieldErrors: undefined element %s\n", name); 6396 6016 } 6397 6017 } … … 6674 6294 which also functions as these correctors. 6675 6295 6676 10/2010 Written by Jianfeng Zhang @ SOLEIL6296 10/2010 Written by Jianfeng Zhang 6677 6297 **********************************************************************/ 6678 6298 void AddCorrQtErr_fam(char const *fic, const int Fnum, const double conv, const char *keywrd, const double r0, … … 6682 6302 double bnL = 0.0, anL = 0.0; 6683 6303 double brho = 0.0, conv_strength = 0.0; 6684 double corr = 0.0; /* skew quadrupole horizontal or vertical corrector error, read from a file*/6304 double corr; /* skew quadrupole horizontal or vertical corrector error, read from a file*/ 6685 6305 int corrlistThick[120]; /* index of associated sextupole*/ 6686 6306 … … 6798 6418 void FitTune4(long qf1,long qf2, long qd1, long qd2, double nux, double nuy) 6799 6419 { 6800 long i =0L;6420 long i; 6801 6421 iVector2 nq1 = {0,0},nq2 = {0,0}, nq={0,0}; 6802 6422 Vector2 nu = {0.0, 0.0}; … … 6847 6467 delta initial delta relative to closed orbit 6848 6468 ctau initial c*tau relative to closed orbit 6849 nmax maximum number of t racking turns6469 nmax maximum number of turns 6850 6470 6851 6471 … … 6859 6479 { 6860 6480 6861 long int i =0L, pos = 1L;6862 long int lastn = 0 L, lastpos = 0L;6481 long int i,pos = 1; 6482 long int lastn = 0, lastpos = 0; 6863 6483 Vector x0, x1, x2, xf,codvector[Cell_nLocMax]; 6864 6484 FILE *outf; … … 6905 6525 do { 6906 6526 pos = 1;//track from first element 6907 (lastn)++; //number of turns6527 (lastn)++; 6908 6528 for (i = 0; i < nv_; i++) //nv_ = 6 6909 6529 x1[i] = x2[i]; 6910 6530 6911 //tracking for one turn6912 6531 while( pos <= globval.Cell_nLoc){ 6913 6532 … … 6933 6552 pos, lastpos,Cell[pos].Elem.PName,Cell[pos].S, 1e3*xf[x_], 1e3*xf[px_], 6934 6553 1e3*xf[y_], 1e3*xf[py_],1e2*xf[delta_], 1e3*xf[ct_],lastn); 6935 } 6936 fprintf(outf,"i name S x(mm) px(mrad) y(mm) py(mrad) delta(%) z(mm) Nturn\n"); 6937 fprintf(outf,"%6d %s %8.4e %12.4e %12.4e %12.4e %12.4e %12.4e %12.4e %4ld \n", 6554 } 6555 fprintf(outf,"%6d %s %8.4e %12.4e %12.4e %12.4e %12.4e %12.4e %12.4e %4ld \n", 6938 6556 pos,Cell[pos].Elem.PName,Cell[pos].S, 1e3*xf[x_], 1e3*xf[px_], 6939 6557 1e3*xf[y_], 1e3*xf[py_],1e2*xf[delta_], 1e3*xf[ct_],lastn); … … 6942 6560 }//finish of tracking and printing to file 6943 6561 6944 } while ((lastn != nmax) && (lastpos == globval.Cell_nLoc)); //track for nmax turns 6945 6946 // if (globval.MatMeth) 6947 // Cell_Pass(0, globval.Cell_nLoc, x1, lastpos); 6948 6949 fclose(outf); 6950 } 6951 /********************************************************************** 6952 void PrintTrackElem(const char *TrackFile, double x, double px, double y,double py, 6953 double delta, double ctau, long int nelem1, long int nelem2) 6954 6955 Purpose: 6956 Print the coordinates tracked around a lattice element by tracking around COD 6957 6958 Input: 6959 TrackFile file to be print 6960 x initial x relative to closed orbit 6961 px initial px relative to closed orbit 6962 y initial y relative to closed orbit 6963 py initial py relative to closed orbit 6964 delta initial delta relative to closed orbit 6965 ctau initial c*tau relative to closed orbit 6966 nelem1 start lattice index of the tracked element 6967 nelem2 end lattice index of the tracked element 6968 6969 6970 Output: 6971 6972 Comments: 6973 Written by Jianfeng Zhang @ LAL 04/2013 6974 **********************************************************************/ 6975 void PrintTrackElem(const char *TrackFile, double x, double px, double y,double py, 6976 double delta, double ctau, long int nelem1, long int nelem2) 6977 { 6978 6979 long int i=0L, pos = 1L; 6980 Vector x0, x1; 6981 FILE *outf; 6982 struct tm *newtime; 6983 6984 bool prt = true; 6985 6986 outf = file_write(TrackFile); 6987 /* Get time and date */ 6988 newtime = GetTime(); 6989 6990 fprintf(outf, "# Element tracking using TRACY III-- %s -- %s\n",TrackFile, asctime2(newtime)); 6991 fprintf(outf, "#\n"); 6992 // fprintf(outf, "# work tunes: %7.5f %7.5f\n",globval.TotalTune[0], globval.TotalTune[1]); 6993 // fprintf(outf, "# i ElemName S x p_x y p_y"); 6994 // fprintf(outf, " delta cdt NElem \n"); 6995 // fprintf(outf, "# [m] [mm] [mrad] [mm] [mrad]"); 6996 // fprintf(outf, " [%%] [mm]\n"); 6997 6998 fprintf(outf,"i ElemName S[m] x(m) px(rad) y(m) py(rad) delta(-) z(m) \n"); 6999 //initial coordinates 7000 x0[x_] = x; 7001 x0[px_] = px; 7002 x0[y_] = y; 7003 x0[py_] = py; 7004 x0[delta_] = delta; 7005 x0[ct_] = ctau; 7006 7007 for (i = 0; i < nv_; i++) //nv_ = 6 7008 x1[i] = x0[i]; 7009 7010 //print the coordinates at the element 7011 pos = nelem1+1;//first element "1" of Tracy is a default "debut", it's diffirent from the real lattice index 7012 7013 //tracking from the start element to the end element 7014 while( pos <= nelem2+1){ 7015 7016 Elem_Pass(pos,x1); 7017 7018 7019 if (prt) { 7020 printf("%4ld %s %6.4f %16.8f %16.8f %16.8f %16.8f %16.8f %16.8f \n", 7021 pos-1,Cell[pos].Elem.PName,Cell[pos].S, x1[x_], x1[px_], 7022 x1[y_], x1[py_],x1[delta_], x1[ct_]); 7023 } 7024 7025 fprintf(outf,"%6d %s %8.4e %16.8e %16.8e %16.8e %16.8e %16.8e %16.8e \n", 7026 pos-1,Cell[pos].Elem.PName,Cell[pos].S, x1[x_], x1[px_], 7027 x1[y_], x1[py_],x1[delta_], x1[ct_]); 7028 7029 pos++; 7030 }//finish of tracking and printing to file 7031 7032 6562 } while ((lastn != nmax) && (lastpos == globval.Cell_nLoc)); 7033 6563 7034 6564 // if (globval.MatMeth)
Note: See TracChangeset
for help on using the changeset viewer.