Ignore:
Timestamp:
Dec 6, 2013, 5:12:43 PM (10 years ago)
Author:
zhangj
Message:

Clean version of Tracy: SoleilVersion at the end of 2011.Use this clean version to find the correct dipole fringe field to have the correct FMAP and FMAPDP of ThomX. Modified files: tpsa_lin.cc, soleillib.cc, prtmfile.cc, rdmfile.cc, read_script.cc, physlib.cc, tracy.cc, t2lat.cc, t2elem.cc, naffutils.cc in /tracy/tracy/src folder; naffutils.h, tracy_global.h, physlib.h, tracy.h, read_script.h, solielilib.h, t2elem.h in /tracy/tracy.inc folder; soltracy.cc in tracy/tools folder

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/tracy3-3.10.1b/tracy/tracy/src/soleillib.cc

    r11 r23  
    2525       none
    2626
    27        
    2827   Global variables:
    2928       trace
     
    3837void Get_Disp_dp(void)
    3938{
    40   long i=0L;
     39  long i;
    4140//  long lastpos = 0;
    4241  const char nomfic[] = "dispersion.out";
     
    9695{
    9796  Vector        x1;     /* tracking coordinates */
    98   long          i = 0L, k = 0L, imax = 50L;
     97  long          i = 0L, k = 0L, imax = 50;
    9998  FILE *        outf;
    10099  double        dP = 0.0, dP20 = 0.0, dpmax = 0.06;
    101100  Vector2       amp = {0.0, 0.0}, H = {0.0, 0.0};
    102101  const char    nomfic[] = "amp_ind.out";
    103   long          lastpos = 0L;
     102  long          lastpos = 0;
    104103  CellType      Celldebut, Cell;
    105104  Vector        codvector[Cell_nLocMax];
     
    201200{
    202201  CellType Cell;
    203   long i=0L;
     202  long i;
    204203Vector2 H;
    205204
     
    252251{
    253252  CellType Cell;
    254   long i=0L;
     253  long i;
    255254  long lastpos = 1L;
    256255  Vector2 H;
     
    462461       See also LoadApers in nsrl-ii.cc
    463462       J.Zhang 07/10 soleil
    464        
    465       (1) 15/10/2013 Jianfeng Zhang @ LAL
    466          Replace fgets() by getline() to fix the bug
    467          to read arbritrary line length.
    468463****************************************************************************/
    469464void ReadCh(const char *AperFile)
    470465{
    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;
    475468  int     Fnum1=0, Fnum2=0, Kidnum1=0, Kidnum2=0, k1=0, k2=0;
    476469  int     i=0, j=0,LineNum=0;
     
    480473
    481474  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++; 
    499488    /* 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)
    502491    /* read the aperture setting */
    503492    {
     
    570559 //     printf("%s", line);
    571560  }
    572   free(line);
    573561  fclose(fp);
    574562  // turn on the global flag for CheckAmpl()
     
    617605  bool lostF = true; /* Lost particle Flag */
    618606  Vector x1;            /* tracking coordinates */
    619   long i=0L;
     607  long i;
    620608  Vector2  aperture;
    621609  aperture[0] = 1e0; aperture[1] = 1e0;
     
    811799#undef nterm
    812800
    813 /*******************************************************************************
    814  *
    815  *
    816  *
    817  *
    818  ******************************************************************************/
     801
    819802double get_D(const double df_x, const double df_y)
    820803{
    821   double  D=0.0;
     804  double  D;
    822805
    823806  const double D_min = -2.0, D_max = -10.0;
     
    851834   Input:
    852835       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
    861842       matlab  set file print format for matlab post-process; specific for nsrl-ii
    862843       
    863844   Output:
    864        status2 true if stable
     845       status true if stable
    865846              false otherwise
    866847
     
    895876 int nb_freq[2] = {0, 0};
    896877 long nturn = Nbtour;
    897  bool status2 = true;
     878 bool status = true;
    898879 struct tm *newtime;
    899880
     
    946927 //    z  = z0 + sgn(j)*sqrt((double)abs(j))*zstep;
    947928     // tracking around closed orbit
    948      Trac_Simple4DCOD(x,xp,z,zp,energy,ctau,nturn,Tab,&status2);
    949      if (status2) { // if trajectory is stable
     929     Trac_Simple4DCOD(x,xp,z,zp,energy,ctau,nturn,Tab,&status);
     930     if (status) { // if trajectory is stable
    950931       // gets frequency vectors
    951932       Get_NAFF(NTERM2, Nbtour, Tab, fx, fz, nb_freq);
     
    993974#undef NTERM2
    994975
    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 points
    1003        For each set of initial conditions the particle is tracked over
    1004        Nbtour for an energy offset dp
    1005 
    1006        Frequency map is based on fixed beam energy, trace x versus z,
    1007        or, tracking transverse dynamic aperture for fixed momentum
    1008        (usually, on-momentum) particle.
    1009        
    1010        The stepsize follows a square root law
    1011 
    1012        Results in fmap.out
    1013 
    1014    Input:
    1015        FmapFile file to save calculated frequency map analysis
    1016        Nbx                horizontal step number
    1017        Nby                vertical step number
    1018        xmax               horizontal maximum amplitude
    1019        zmax              vertical maximum amplitude
    1020        Nbtour            number of turn for tracking
    1021        energy            particle energy offset
    1022        diffusion        flag to calculate tune diffusion/ tune
    1023                         difference between the first Nbtour and last Nbtour
    1024        matlab  set file print format for matlab post-process; specific for nsrl-ii
    1025        
    1026    Output:
    1027        status2 true if stable
    1028               false otherwise
    1029 
    1030    Return:
    1031        none
    1032 
    1033    Global variables:
    1034        none
    1035 
    1036    Specific functions:
    1037        Trac_Simple, Get_NAFF
    1038 
    1039    Comments:
    1040        15/10/03 run for the diffusion: nasty patch for retrieving the closed orbit
    1041        16/02/03 patch removed
    1042        19/07/11 add interface of file defined by user which is used to save calculated
    1043                 frequency map analysis
    1044                
    1045        11/06/2013  Modified by Jianfeng Zhang @ LAL
    1046        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 of
    1048           the particle; if the final turn is not the "Nbtour", then the particle is lost.
    1049 ****************************************************************************/
    1050 #define NTERM2  10
    1051 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 point
    1055  FILE *outf_loss; //file with the information of the lost particle
    1056  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 particle
    1071  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 information
    1106 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 planes
    1125  xstep = xmax/sqrt((double)Nbx);
    1126  zstep = zmax/sqrt((double)Nbz);
    1127 
    1128  // double number of turn if diffusion to compute
    1129  if (diffusion) nturn = 2*Nbtour;
    1130 
    1131  // px and pz zeroed
    1132  xp = xp0;
    1133  zp = zp0;
    1134 
    1135 // Tracking part + NAFF
    1136  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 information
    1148    if(printloss)
    1149      Trac_Simple4DCOD(x,xp,z,zp,energy,ctau,nturn,Tab,lastn, lastpos, x1, &status2);
    1150      else
    1151      // tracking around closed orbit
    1152      Trac_Simple4DCOD(x,xp,z,zp,energy,ctau,nturn,Tab,&status2);
    1153 
    1154    if (status2) { // if trajectory is stable
    1155        // gets frequency vectors
    1156        Get_NAFF(NTERM2, Nbtour, Tab, fx, fz, nb_freq);
    1157        Get_freq(fx,fz,&nux1,&nuz1);  // gets nux and nuz
    1158        if (diffusion) { // diffusion
    1159          // shift data for second round NAFF
    1160          Get_Tabshift(Tab,Tab0,Nbtour,Nbtour);
    1161          // gets frequency vectors
    1162          Get_NAFF(NTERM2, Nbtour, Tab0, fx2, fz2, nb_freq);
    1163          Get_freq(fx2,fz2,&nux2,&nuz2); // gets nux and nuz
    1164        }
    1165      } // unstable trajectory
    1166      else { //zeroing output
    1167       nux1 = 0.0; nuz1 = 0.0;
    1168       nux2 = 0.0; nuz2 = 0.0;
    1169      }
    1170      
    1171      // printout value
    1172      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 particle
    1191      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 NTERM2
    1204 
    1205976
    1206977/****************************************************************************/
     
    12531024#define NTERM2  10
    12541025void 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)   
    12561027{
    12571028 FILE * outf;
    1258  FILE *outf_loss; //file with the information of the lost particle
    12591029 long i = 0L, j = 0L;
    12601030 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;
    12621032 double x = 0.0, xp = 0.0, z = 0.0, zp = 0.0;
    12631033 double x0 = 1e-6, xp0 = 0.0, z0 = 1e-6, zp0 = 0.0;
     
    12671037 int nb_freq[2] = {0, 0};
    12681038 long nturn = Nbtour;
    1269  bool status2 = true;
     1039 bool status = true;
    12701040 struct tm *newtime;
    12711041
     
    12741044 strcat(FmapFile,FmapFile_p);
    12751045 printf("%s\n",FmapFile);
    1276 
    1277 //variables of the returned the tracked particle
    1278  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 
    12861046
    12871047 /* Get time and date */
     
    12991059 }
    13001060
    1301 //file with lost particle information
    1302  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 
    13091061 if(myid==0)
    13101062 {
     
    13121064  fprintf(outf,"# nu = f(x) \n");
    13131065  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 }
    13241067 
    13251068 if ((Nbx < 1) || (Nbz < 1))
     
    13701113 
    13711114     // 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
    13791117     {
    13801118       // gets frequency vectors
     
    14101148     fprintf(stdout,"%14.6e %14.6e %14.6e %14.6e %14.6e %14.6e\n", x, z, nux1, nuz1, dfx, dfz);
    14111149     }
    1412 
    1413  //print out the information of the lost particle
    1414      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]);
    14181150   }
    14191151 }
    14201152
    14211153 fclose(outf);
    1422 
    1423  if(printloss)
    1424    fclose(outf_loss);
    1425 
    14261154}
    14271155#undef NTERM2
     
    14531181       emax             maximum energy
    14541182       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
    14571184       matlab  set file print format for matlab post-process; specific for nsrl-ii
    14581185   Output:
    1459        status2 true if stable
     1186       status true if stable
    14601187              false otherwise
    14611188
     
    14741201       is negative for negative enrgy offset since this is true for the cod
    14751202       19/07/11  add features to save calculated fmapdp in the user defined file
    1476 
    1477        18/06/2013   by Jianfeng Zhang @ LAL
    1478 
    1479       Add bool flag to print out the last information      of the tracked particle
    14801203****************************************************************************/
    14811204#define NTERM2  10
    14821205void 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)
    14841207{
    14851208 FILE * outf;
    1486 FILE *outf_loss; //file with the information of the lost particle
    14871209 long i = 0L, j = 0L;
    14881210 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;
    14901212 double x = 0.0, xp = 0.0, zp = 0.0, dp = 0.0, ctau = 0.0;
    14911213 double x0 = 1e-6, xp0 = 0.0, zp0 = 0.0;
     
    14951217 int nb_freq[2] = {0, 0};
    14961218 long nturn = Nbtour;
    1497  bool status2=true;
     1219 bool status=true;
    14981220 struct tm *newtime;
    1499 
    1500  //variables of the returned the tracked particle
    1501  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");
    15081221
    15091222 /* Get time and date */
     
    15141227 if (diffusion && globval.Cavity_on == false) nturn = 2*Nbtour;
    15151228
    1516  if (trace) printf("Entering fmapdp ... results in %s\n\n",FmapdpFile);
     1229 if (trace) printf("Entering fmap ... results in %s\n\n",FmapdpFile);
    15171230
    15181231 /* Opening file */
     
    15271240fprintf(outf,"#    dp[m]         x[m]           fx            fz           dfx           dfz\n");
    15281241 
    1529 
    1530 //file with lost particle information
    1531 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 
    15461242 if ((Nbx <= 1) || (Nbe <= 1))
    15471243   fprintf(stdout,"fmapdp: Error Nbx=%ld Nbe=%ld\n",Nbx,Nbe);
     
    15661262        diffusion = false;
    15671263     }   
    1568      else{
     1264     else
    15691265      // x  = x0 + sgn(j)*sqrt((double)abs(j))*xstep;
    15701266         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) {
    15791269       Get_NAFF(NTERM2, Nbtour, Tab, fx, fz, nb_freq);
    15801270       Get_freq(fx,fz,&nux1,&nuz1);  // gets nux and nuz
     
    16101300        dp, x, nux1, nuz2, dfx, dfz);
    16111301     }
    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 
    16171302   }
    16181303 }
    16191304
    16201305 fclose(outf);
    1621 
    1622 if(printloss)
    1623    fclose(outf_loss);
    16241306}
    16251307#undef NTERM2
     
    16561338
    16571339   Output:
    1658        status2 true if stable
     1340       status true if stable
    16591341              false otherwise
    16601342
     
    16711353       14/11/2011  add features to parallel calculate fmapdp.
    16721354                   Merged with the version written by Mao-sen Qiu at Taiwan light source.
    1673                    
    1674        18/06/2013   by Jianfeng Zhang @ LAL
    1675         Add bool flag to print out the last information of the tracked particle           
    16761355****************************************************************************/
    16771356#define NTERM2  10
    16781357void 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)
    16801359{
    16811360 FILE * outf;
    1682 FILE *outf_loss; //file with the information of the lost particle
    16831361 long i = 0L, j = 0L;
    16841362 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;
    16861364 double x = 0.0, xp = 0.0, zp = 0.0, dp = 0.0, ctau = 0.0;
    16871365 double x0 = 1e-6, xp0 = 0.0, zp0 = 0.0;
     
    16911369 int nb_freq[2] = {0, 0};
    16921370 long nturn = Nbtour;
    1693  bool status2=true;
     1371 bool status=true;
    16941372 struct tm *newtime;
    16951373
     
    16991377 printf("%s\n",FmapdpFile);
    17001378
    1701 //variables of the returned the tracked particle
    1702  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 
    17101379 /* Get time and date */
    17111380 time_t aclock;
     
    17211390   fprintf(stdout, "fmapdp: error while opening file %s\n", FmapdpFile);
    17221391   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    }
    17301392 }
    17311393
     
    17361398     // fprintf(outf,"#    dp[%%]         x[mm]          fx            fz           dfx           dfz\n");
    17371399     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   }
    17491401 
    17501402if ((Nbx <= 1) || (Nbe <= 1))
     
    17961448        diffusion = false;
    17971449     }   
    1798      else{
     1450     else
    17991451      // x  = x0 + sgn(j)*sqrt((double)abs(j))*xstep;
    18001452         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) {
    18091455       Get_NAFF(NTERM2, Nbtour, Tab, fx, fz, nb_freq);
    18101456       Get_freq(fx,fz,&nux1,&nuz1);  // gets nux and nuz
     
    18401486        dp, x, nux1, nuz2, dfx, dfz);
    18411487     }
    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 
    18471488   }
    18481489 }
    18491490
    18501491 fclose(outf);
    1851 
    1852  if(printloss)
    1853    fclose(outf_loss);
    18541492}
    18551493#undef NTERM2
     
    18971535  double nux1 = 0.0, nuz1 = 0.0;
    18981536  int nb_freq[2] = {0, 0};
    1899   bool status2 = true;
     1537  bool status = true;
    19001538  struct tm *newtime;
    19011539
     
    19291567    ctau = ctau0;
    19301568   
    1931     Trac_Simple4DCOD(x,xp,z,zp,dp,ctau,Nbtour,Tab,&status2); // tracking around closed orbit
    1932     if (status2) {
     1569    Trac_Simple4DCOD(x,xp,z,zp,dp,ctau,Nbtour,Tab,&status); // tracking around closed orbit
     1570    if (status) {
    19331571       Get_NAFF(NTERM, Nbtour, Tab, fx, fz, nb_freq); // get frequency vectors
    19341572       Get_freq(fx,fz,&nux1,&nuz1);  // gets nux and nuz
     
    19361574    else {
    19371575       nux1 = 0.0; nuz1 = 0.0;
    1938        status2 = true;
     1576       status = true;
    19391577    }
    19401578   
     
    19911629  FILE *outf;
    19921630  const char *fic = phasefile;
    1993   int i=0;
    1994   bool status2=false;
     1631  int i;
     1632  bool status;
    19951633  struct tm *newtime;
    19961634
     
    20251663  }
    20261664 
    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);
    20291666  for (i = 0; i < Nbtour; i++) {
    20301667    fprintf(outf,"% .5e % .5e % .5e % .5e % .5e % .5e\n",
    20311668            Tab[0][i],Tab[1][i],Tab[2][i],Tab[3][i],Tab[4][i],Tab[5][i]);
    20321669  }
    2033   //  cout << "status is: " << status2 << endl;
    20341670  fclose(outf);
    20351671}
     
    20691705  FILE *outf;
    20701706  const char  *fic="phasepoly.out";
    2071   long        lastpos = 0L,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;
    20741710  double      ex = 1368E-9, el = 1.78E-4;
    20751711  double      betax = 9.0, /*betaz = 8.2, */betal = 45.5;
     
    21631799  double start = 0.0, step = 0.0;
    21641800  double x = 0.0, px = 0.0, z = 0.0, pz = 0.0, delta = 0.0, ctau = 0.0;
    2165   bool status2 = true;
     1801  bool status = true;
    21661802  struct tm *newtime;
    21671803
     
    22221858   fprintf(stdout,"% .5e % .5e % .5e % .5e % .5e % .5e\n",
    22231859            x,px,z,pz,delta,ctau);
    2224     Trac_Simple4DCOD(x,px,z,pz,delta,ctau,Nbtour,Tab,&status2);
     1860    Trac_Simple4DCOD(x,px,z,pz,delta,ctau,Nbtour,Tab,&status);
    22251861   for (i = 0; i < Nbtour; i++) {
    22261862      fprintf(outf,"% .5e % .5e % .5e % .5e % .5e % .5e\n",
     
    22651901  FILE *outf;
    22661902  const char fic[] = "check_ampl.out";
    2267   int i=0;
     1903  int i;
    22681904
    22691905  if ((outf = fopen(fic, "w")) == NULL)
     
    23201956  FILE *outf;
    23211957  const char fic[] = "enveloppe.out";
    2322   int i=0,j=0 ;
     1958  int i,j ;
    23231959  CellType Cell;
    23241960
     
    35623198  FILE *fi;
    35633199  const char fic_skew[] = "QT-solamor_2_3.dat";
    3564   int i=0;
     3200  int i;
    35653201  double theta[500]; /* array for skew quad tilt*/
    3566   double b2=0.0, mKL=0.0;
     3202  double b2, mKL;
    35673203  CellType Cell;
    3568   long mOrder=0L;
     3204  long mOrder;
    35693205
    35703206  int nquad = 0;  /* Number of skew quadrupoles */
     
    37673403  struct tm     *newtime;  // for time
    37683404  Vector        codvector[Cell_nLocMax];
    3769   bool          cavityflag=false, radiationflag=false;
     3405  bool          cavityflag, radiationflag;
    37703406  bool          trace=true;
    37713407 
     
    41653801  struct tm     *newtime;  // for time
    41663802  Vector        codvector[Cell_nLocMax];
    4167   bool          cavityflag=false, radiationflag=false;
     3803  bool          cavityflag, radiationflag;
    41683804  bool          trace=true;
    41693805 
     
    46504286 const char xfic[] = "xspectrum.out";
    46514287 const char zfic[] = "zspectrum.out";
    4652  long i=0L, j=0L, k=0L;
     4288 long i, j, k;
    46534289 #define nterm2  20
    46544290 double Tab[6][NTURN], fx[nterm2], fz[nterm2], fx2[nterm2], fz2[nterm2];
     
    46584294 int nb_freq[2] = {0, 0};
    46594295 long nturn = Nbtour;
    4660  bool status2=true;
     4296 bool status=true;
    46614297 struct tm *newtime;
    46624298
     
    46994335   for (j = 0; j<= Nbz; j++) {
    47004336     z  = z0 + sqrt((double)j)*zstep;
    4701      Trac_Simple4DCOD(x,xp,z,zp,energy,0.0,nturn,Tab,&status2);
    4702      if (status2) {
     4337     Trac_Simple4DCOD(x,xp,z,zp,energy,0.0,nturn,Tab,&status);
     4338     if (status) {
    47034339      Get_NAFF(nterm2, Nbtour, Tab, fx, fz, nb_freq);
    47044340     }
     
    47794415            long nmax, long pos, long &lastn, long &lastpos, FILE *outf1)
    47804416{
    4781   bool lostF=false; /* Lost particle Flag */
     4417  bool lostF; /* Lost particle Flag */
    47824418  Vector x1;     /* tracking coordinates */
    47834419  Vector2  aperture;
     
    47924428  getelem(pos-1,&Cell);
    47934429
    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",
    47954431             dp*1e2, Cell.BeamPos[0]*1e3, Cell.BeamPos[2]*1e3);
    47964432
     
    48634499  CellType Cell;
    48644500  int qlist[320];
    4865   int nquad=0, i=0;
     4501  int nquad=0, i;
    48664502  double A = 0.0;
    48674503
     
    48974533/****************************************************************************/
    48984534/* void fmapfull(long Nbx, long Nbz, long Nbtour, double xmax, double zmax,
    4899    double energy, bool *status2)
     4535   double energy, bool *status)
    49004536
    49014537   Purpose:
     
    49174553
    49184554   Output:
    4919        status2 true if stable
     4555       status true if stable
    49204556              false otherwise
    49214557
     
    49394575 FILE * outf;
    49404576 const char fic[] = "fmapfull.out";
    4941  int i=0, j=0, k=0;
     4577 int i, j, k;
    49424578 double Tab[DIM][NTURN], Tab0[DIM][NTURN];
    49434579 double fx[NTERM], fz[NTERM], fx2[NTERM], fz2[NTERM];
     
    49484584 double nux1[NTERM], nuz1[NTERM],nux2[NTERM], nuz2[NTERM];
    49494585 long nturn = Nbtour;
    4950  bool status2=true;
     4586 bool status=true;
    49514587 struct tm *newtime;
    49524588 char name[14];
     
    50084644   for (j = 0; j<= Nbz; j++) {
    50094645     z  = z0 + sqrt((double)j)*zstep;
    5010      Trac_Simple4DCOD(x,xp,z,zp,energy,0.0,nturn,Tab,&status2);
    5011 
    5012      if (status2) {
     4646     Trac_Simple4DCOD(x,xp,z,zp,energy,0.0,nturn,Tab,&status);
     4647
     4648     if (status) {
    50134649       Get_NAFF(NTERM, Nbtour, Tab, fx, fz, nb_freq);
    50144650
     
    50914727/****************************************************************************/
    50924728/* void Dyna(long Nbx, long Nbz, long Nbtour, double xmax, double zmax,
    5093    double energy, bool *status2)
     4729   double energy, bool *status)
    50944730
    50954731   Purpose:
     
    51114747
    51124748   Output:
    5113        status2 true if stable
     4749       status true if stable
    51144750              false otherwise
    51154751
     
    51334769  FILE * outf;
    51344770  const char fic[] = "dyna.out";
    5135   long i=0, j=0;
     4771  long i, j;
    51364772  double Tab[6][NTURN], fx[NTERM2], fz[NTERM2];
    51374773  double x = 0.0, xp = 0.0, z = 0.0, zp = 0.0;
     
    51404776  int nb_freq[2] = {0, 0};
    51414777  long nturn = Nbtour;
    5142   bool status2=true;
     4778  bool status=true;
    51434779  struct tm *newtime;
    51444780
     
    51744810    for (j = 0; j<= Nbz; j++) {
    51754811      z  = z0 + sqrt((double)j)*zstep;
    5176       Trac_Simple4DCOD(x,xp,z,zp,energy,0.0,nturn,Tab,&status2);
    5177       if (status2) 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);
    51784814      else {
    51794815       fx[0] = 0.0; fz[0] = 0.0;
    51804816      }
    5181       fprintf(outf,"%14.6e %14.6e %14.6e %14.6e %d\n", x, z, fx[0], fz[0], status2);
    5182       fprintf(stdout,"%14.6e %14.6e %14.6e %14.6e %d\n", x, z, fx[0], fz[0], status2);
     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);
    51834819      if (diffusion) {
    5184         if (status2) 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], status2);
    5186         fprintf(stdout,"%14.6e %14.6e %14.6e %14.6e %d\n", x, z, fx[0], fz[0], status2);
     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);
    51874823      }
    51884824    }
     
    51964832    for (j = 0; j<= Nbz; j++) {
    51974833      z  = z0 + sqrt((double)j)*zstep;
    5198       Trac_Simple4DCOD(x,xp,z,zp,energy,0.0,nturn,Tab,&status2);
    5199       if (status2) 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);
    52004836      else {
    52014837       fx[0] = 0.0; fz[0] =0.0;
    52024838      }
    5203       fprintf(outf,"%14.6e %14.6e %14.6e %14.6e %d\n", x, z, fx[0], fz[0], status2);
    5204       fprintf(stdout,"%14.6e %14.6e %14.6e %14.6e %d\n", x, z, fx[0], fz[0], status2);
     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);
    52054841      if (diffusion) {
    5206         if (status2) Get_NAFF(NTERM2, Nbtour, Tab, fx, fz, nb_freq);
     4842        if (status) Get_NAFF(NTERM2, Nbtour, Tab, fx, fz, nb_freq);
    52074843        fprintf(outf,"%14.6e %14.6e %14.6e %14.6e\n", x, z, fx[0], fz[0]);
    52084844        fprintf(stdout,"%14.6e %14.6e %14.6e %14.6e\n", x, z, fx[0], fz[0]);
     
    52474883  FILE *outf;
    52484884  const char fic[] = "phase2.out";
    5249   long lastpos = 0L,lastn = 0L;
     4885  long lastpos = 0,lastn = 0;
    52504886  struct tm *newtime;
    52514887
     
    53735009  int i,j;
    53745010  bool chroma=true, trace=false;
    5375   bool radiationflag=false, cavityflag=false;
     5011  bool radiationflag, cavityflag;
    53765012  double dP      = 0.0;
    53775013  double diffcmu = 0.0,   /* cos(mu1) - cos(mu2)*/
     
    57955431void PhaseLongitudinalHamiltonien(void)
    57965432{
    5797   long i=0L,j=0L;
     5433  long i,j;
    57985434  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;
    58005436  long imax = 1000L,         // turn number
    58015437       jmax = 25L;          // starting condition number
     
    59935629}
    59945630
    5995 /*******************************************************************************
    5996  *
    5997  *
    5998  *
    5999  *
    6000  ******************************************************************************/
     5631
    60015632double EnergySmall(double *X, double irho)
    60025633{
    6003  double A=0.0, B=0.0;
     5634 double A, B;
    60045635 double h = irho;
    60055636
     
    60085639 return (A+B);
    60095640}
    6010 /*******************************************************************************
    6011  *
    6012  *
    6013  *
    6014  *
    6015  ******************************************************************************/
     5641
    60165642double EnergyDrift(double *X)
    60175643{
    6018  double A=0.0;
     5644 double A;
    60195645
    60205646 A = (X[1]*X[1]+X[3]*X[3])/2.0/(1.0+X[4]);
     
    60555681  FILE *outf;
    60565682  const char fic[] = "enveloppe2.out";
    6057   int i=0,j=0 ;
     5683  int i,j ;
    60585684  CellType Cell;
    60595685  /* Array for Enveloppes */
     
    61855811void set_RFVoltage(const int Fnum, const double V_RF){
    61865812
    6187   int k=0, n = 0;
     5813  int k, n = 0;
    61885814 
    61895815 
     
    62325858       01/2011  Fix the bug for reading the end of line symbol "\n" , "\r",'\r\n'
    62335859                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.     
    62375861*****************************************************************************************************/
    62385862void ReadFieldErr(const char *FieldErrorFile)
    62395863
    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;
    62455867  int     n = 0;    /* field error order*/
    62465868  int     LineNum = 0;
    6247   int     seed_val = 0; // random seed number for the rms error
     5869  int     seed_val; // random seed number for the rms error
    62485870  double  Bn = 0.0, An = 0.0, r0 = 0.0; /* field error components and radius when the field error is measured */
    62495871  /* conversion number from A to T.m for soleil*/
     
    62545876
    62555877  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
    62615879  printf("\n");
    62625880  /* 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     }   
    62645889   
    62655890    /* count line number for debug*/
    62665891    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     }
    62725892   
    62735893    /* check the line is whether comment line or null line*/
     
    62875907        /*read and assign the key words and measure radius*/
    62885908          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);
    62905910         
    62915911          rms = (strcmp("rms", keywrd) == 0)? true : false;
     
    63115931            sscanf(prm, "%lf", &An);
    63125932         
    6313             if (!prt)
     5933            if (prt)
    63145934              printf(" n = %2d, Bn = %9.1e, An = %9.1e\n", n, Bn, An);
    63155935         
     
    63355955     // printf("%s", line);
    63365956  }
    6337   free(line);
     5957
    63385958  fclose(inf);
    63395959}
     
    63936013      AddFieldValues_fam(Fnum,keywrd, r0, n, Bn, An);
    63946014    else
    6395       printf("AddFieldErrors(): Error! undefined lattice element %s !\n", name);
     6015      printf("SetFieldErrors: undefined element %s\n", name);
    63966016  }
    63976017}
     
    66746294         which also functions as these correctors. 
    66756295                 
    6676        10/2010  Written by Jianfeng Zhang @ SOLEIL
     6296       10/2010  Written by Jianfeng Zhang
    66776297**********************************************************************/
    66786298void AddCorrQtErr_fam(char const *fic, const int Fnum, const double conv, const char *keywrd, const double r0,
     
    66826302  double  bnL = 0.0, anL = 0.0;
    66836303  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*/
    66856305  int    corrlistThick[120];   /* index of associated sextupole*/
    66866306 
     
    67986418void FitTune4(long qf1,long qf2, long qd1, long qd2, double nux, double nuy)
    67996419{
    6800   long      i=0L;
     6420  long      i;
    68016421  iVector2  nq1 = {0,0},nq2 = {0,0}, nq={0,0};
    68026422  Vector2   nu = {0.0, 0.0};
     
    68476467      delta            initial delta relative to closed orbit
    68486468      ctau             initial c*tau relative to closed orbit
    6849       nmax             maximum number of tracking turns
     6469      nmax             maximum number of turns
    68506470     
    68516471     
     
    68596479{
    68606480   
    6861     long int i=0L, pos = 1L;
    6862     long int lastn = 0L, lastpos = 0L;
     6481    long int i,pos = 1;
     6482    long int lastn = 0, lastpos = 0;
    68636483    Vector x0, x1, x2, xf,codvector[Cell_nLocMax];
    68646484    FILE *outf;
     
    69056525    do {
    69066526        pos = 1;//track from first element
    6907         (lastn)++; //number of turns
     6527        (lastn)++;
    69086528        for (i = 0; i < nv_; i++)  //nv_ = 6
    69096529            x1[i] = x2[i];
    69106530
    6911         //tracking for one turn
    69126531        while( pos <= globval.Cell_nLoc){ 
    69136532         
     
    69336552                     pos, lastpos,Cell[pos].Elem.PName,Cell[pos].S, 1e3*xf[x_], 1e3*xf[px_],
    69346553                     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",
    69386556                     pos,Cell[pos].Elem.PName,Cell[pos].S, 1e3*xf[x_], 1e3*xf[px_],
    69396557                     1e3*xf[y_], 1e3*xf[py_],1e2*xf[delta_], 1e3*xf[ct_],lastn);           
     
    69426560        }//finish of tracking and printing to file 
    69436561       
    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));
    70336563
    70346564//     if (globval.MatMeth)
Note: See TracChangeset for help on using the changeset viewer.