From f8aabd58b3df2e33e0b7d7434b16bd3a65ce8784 Mon Sep 17 00:00:00 2001 From: zhang <zhang@9a6e40ed-f3a0-4838-9b4a-bf418f78e88d> Date: Wed, 20 Oct 2010 10:26:35 +0000 Subject: [PATCH] 20/10/2010 Add comments and fix a bug to read the end of line in get_prm( ). --- tracy/tracy/src/nsls-ii_lib.cc | 343 ++++++++++++++++++++++++++++++++- 1 file changed, 335 insertions(+), 8 deletions(-) diff --git a/tracy/tracy/src/nsls-ii_lib.cc b/tracy/tracy/src/nsls-ii_lib.cc index 7c75eb0..9a2d52e 100644 --- a/tracy/tracy/src/nsls-ii_lib.cc +++ b/tracy/tracy/src/nsls-ii_lib.cc @@ -1422,6 +1422,8 @@ void set_aper_type(const int type, const double Dxmin, const double Dxmax, Comments: Enumeration of special variables: enum { All = 0, Dip = 1, Quad = 2, Sext = 3, Oct = 4, Dec = 5, Dodec = 6 } + + 10/2010 Comments by Jianfeng Zhang ****************************************************************************/ void LoadApers(const char *AperFile, const double scl_x, const double scl_y) @@ -1668,7 +1670,39 @@ void set_bnL_design_type(const int type, printf("Bad type argument to set_bnL_design_type()\n"); } +/*********************************************************************** +void set_bnL_sys_elem(const int Fnum, const int Knum, + const int n, const double bnL, const double anL) + + Purpose: + Set field error to the kid of a family, errors are absolute + integrated field strength, replace the previous value!!! + + + Input: + Fnum family index + Knum kids index + n order of the error + bnL absolute integrated B component for the n-th error + anL absolute integrated A component for the n-th error + + + Output: + None + + Return: + None + + Global variables + None + + Specific functions: + None + + Comments: + None +**********************************************************************/ void set_bnL_sys_elem(const int Fnum, const int Knum, const int n, const double bnL, const double anL) { @@ -1686,7 +1720,8 @@ void set_bnL_sys_elem(const int Fnum, const int Knum, elem.M->PBsys[HOMmax+n] = bnL; elem.M->PBsys[HOMmax-n] = anL; } - Mpole_SetPB(Fnum, Knum, n); Mpole_SetPB(Fnum, Knum, -n); + Mpole_SetPB(Fnum, Knum, n); //set for Bn component + Mpole_SetPB(Fnum, Knum, -n); //set for An component if (prt) printf("set the n=%d component of %s to %e %e\n", @@ -1694,7 +1729,39 @@ void set_bnL_sys_elem(const int Fnum, const int Knum, bnL, elem.M->PBsys[HOMmax+n]); } +/*********************************************************************** +void set_bnL_sys_fam(const int Fnum, + const int n, const double bnL, const double anL) + + Purpose: + Set field error to all the kids of a family,errors are absolute + integrated field strength + + + + Input: + Fnum family index + n order of the error + bnL absolute integrated B component for the n-th error + anL absolute integrated A component for the n-th error + + + Output: + None + + Return: + None + + Global variables + None + + Specific functions: + None + + Comments: + None +**********************************************************************/ void set_bnL_sys_fam(const int Fnum, const int n, const double bnL, const double anL) { @@ -1704,7 +1771,47 @@ void set_bnL_sys_fam(const int Fnum, set_bnL_sys_elem(Fnum, k, n, bnL, anL); } +/*********************************************************************** +void set_bnL_sys_type(const int type, + const int n, const double bnL, const double anL) + + Purpose: + Set field error to the type, errors are absolute + integrated field strength + + + + Input: + type type name + n order of the error + bnL absolute integrated B component for the n-th error + anL absolute integrated A component for the n-th error + + + Output: + None + + Return: + None + + Global variables + None + + Specific functions: + None + + Comments: + Attension: + This code has a bug, in the for loop, when looking for the + quadrupole family, it will also find the skew quadrupole family, + since their Pkind == Mpole & n_design =2. + It means the multipole error is additionally set N times, + and N is the number of skew quadrupole in the lattice. + + 10/2010 Comments by Jianfeng Zhang + +**********************************************************************/ void set_bnL_sys_type(const int type, const int n, const double bnL, const double anL) { @@ -1781,7 +1888,45 @@ void set_bnL_rms_type(const int type, printf("Bad type argument to set_bnL_rms_type()\n"); } +/*********************************************************************** +void set_bnr_sys_elem(const int Fnum, const int Knum, + const int n, const double bnr, const double anr) + + Purpose: + Set field error to the kid of a family, errors are relative to + design values for (Dip, Quad, Sext, ...) + + If r0 != 0, call this function + + Input: + Fnum family index + Knum kids index + n order of the error + bnL relative integrated B component for the n-th error + anL relative integrated A component for the n-th error + + + Output: + None + + Return: + None + + Global variables + None + + Specific functions: + None + + Comments: + !!!!!!!!! + This function desn't work for dipole, since + mp->PBpar[HOMmax+1] is not assigned a value when dipole is + read in t2lat.cc. + + comments by Jianfeng Zhang 10/2010 +**********************************************************************/ void set_bnr_sys_elem(const int Fnum, const int Knum, const int n, const double bnr, const double anr) { @@ -1802,7 +1947,39 @@ void set_bnr_sys_elem(const int Fnum, const int Knum, bnr, mp->PBpar[HOMmax+nd], mp->PBsys[HOMmax+n]); } +/*********************************************************************** +void set_bnr_sys_fam(const int Fnum, + const int n, const double bnr, const double anr) + + Purpose: + Set field error to all the kids of a family, errors are relative + to design values for (Dip, Quad, Sext, ...). + + If r0 != 0, call this function + + Input: + Fnum family index + n order of the error + bnL relative integrated B component for the n-th error + anL relative integrated A component for the n-th error + + + Output: + None + + Return: + None + + Global variables + None + + Specific functions: + None + + Comments: + None +**********************************************************************/ void set_bnr_sys_fam(const int Fnum, const int n, const double bnr, const double anr) { @@ -1812,7 +1989,39 @@ void set_bnr_sys_fam(const int Fnum, set_bnr_sys_elem(Fnum, k, n, bnr, anr); } +/*********************************************************************** +void set_bnr_sys_type(const int type, + const int n, const double bnr, const double anr) + + Purpose: + Set field error to the type, errors are relative + to design values for (Dip, Quad, Sext, ...) + + If r0 != 0, call this function + + Input: + type type name + n order of the error + bnL relative integrated B component for the n-th error + anL relative integrated A component for the n-th error + + + Output: + None + + Return: + None + + Global variables + None + + Specific functions: + None + + Comments: + None +**********************************************************************/ void set_bnr_sys_type(const int type, const int n, const double bnr, const double anr) { @@ -2046,7 +2255,39 @@ void set_ID_scl(const int Fnum, const double scl) set_ID_scl(Fnum, k, scl); } +/*********************************************************************** +void SetFieldValues_fam(const int Fnum, const bool rms, const double r0, + const int n, const double Bn, const double An, + const bool new_rnd) + + Purpose: + Set field error to all the kids in a family + + Input: + Fnum family name + rms flag to set rms field error + r0 radius at which error is measured + n order of the error + Bn integrated B component for the n-th error + An integrated A component for the n-th error + new_rnd bool flag to set new random number + + Output: + None + + Return: + None + + Global variables + None + + Specific functions: + None + + Comments: + None +**********************************************************************/ void SetFieldValues_fam(const int Fnum, const bool rms, const double r0, const int n, const double Bn, const double An, const bool new_rnd) @@ -2071,6 +2312,39 @@ void SetFieldValues_fam(const int Fnum, const bool rms, const double r0, } +/*********************************************************************** +void SetFieldValues_type(const int N, const bool rms, const double r0, + const int n, const double Bn, const double An, + const bool new_rnd) + + Purpose: + Set field error to the type + + Input: + N type name + rms flag to set rms field error + r0 radius at which error is measured + n order of the error + Bn integrated B component for the n-th error + An integrated A component for the n-th error + new_rnd bool flag to set new random number + + + Output: + None + + Return: + None + + Global variables + None + + Specific functions: + None + + Comments: + None +**********************************************************************/ void SetFieldValues_type(const int N, const bool rms, const double r0, const int n, const double Bn, const double An, const bool new_rnd) @@ -2093,6 +2367,39 @@ void SetFieldValues_type(const int N, const bool rms, const double r0, } +/*********************************************************************** +void SetFieldErrors(const char *name, const bool rms, const double r0, + const int n, const double Bn, const double An, + const bool new_rnd) + + Purpose: + Set field error to the type or element + + Input: + name type name or element name + rms flag to set rms field error + r0 radius at which error is measured + n order of the error + Bn integrated B component for the n-th error + An integrated A component for the n-th error + new_rnd flag to set new random number for the error + + + Output: + None + + Return: + None + + Global variables + None + + Specific functions: + None + + Comments: + 10/2010 Comments by Jianfeng Zhang +**********************************************************************/ void SetFieldErrors(const char *name, const bool rms, const double r0, const int n, const double Bn, const double An, const bool new_rnd) @@ -2117,12 +2424,28 @@ void SetFieldErrors(const char *name, const bool rms, const double r0, } + +/******************************************************************** +char* get_prm(void) + + Purpose: + Find the stoke talbe symbol "\t" in the string, and + then saved and return the position of the pointer. + + symbol for end of the line: + \n + Comments: + 10/2010 By Jianfeng Zhang + Fix the bug for reading the line end symbol "\n" or "\r" +*********************************************************************/ char* get_prm(void) { char *prm; prm = strtok(NULL, " \t"); - if ((prm == NULL) || (strcmp(prm, "\r\n") == 0)) { + + //if ((prm == NULL) || (strcmp(prm, "\r\n") == 0)) { + if ((prm == NULL) || (strcmp(prm, "\n") == 0)|| (strcmp(prm, "\r") == 0)|| (strcmp(prm, "\r\n") == 0)) { printf("get_prm: incorrect format\n"); exit_(1); } @@ -4206,7 +4529,8 @@ void pol_fit(int n, double x[], double y[], int order, Vector &b, int i, j, k; Matrix T1; - + bool prt = false; + const double sigma_k = 1.0, chi2 = 4.0; for (i = 0; i <= order; i++) { @@ -4224,10 +4548,12 @@ void pol_fit(int n, double x[], double y[], int order, Vector &b, if (InvMat(order+1, T1)) { LinTrans(order+1, T1, b); sigma = get_chi2(n, x, y, order, b); - printf("\n"); - printf(" n Coeff.\n"); - for (i = 0; i <= order; i++) - printf("%3d %10.3e+/-%8.2e\n", i, b[i], sigma*sqrt(chi2*T1[i][i])); + if(prt){ + printf("\n"); + printf(" n Coeff.\n"); + for (i = 0; i <= order; i++) + printf("%3d %10.3e+/-%8.2e\n", i, b[i], sigma*sqrt(chi2*T1[i][i])); + } } else { printf("pol_fit: Matrix is singular\n"); exit_(1); @@ -4533,7 +4859,8 @@ void get_alphac2(void) } pol_fit(n, delta, alphac, 3, b, sigma); printf("\n"); - printf("alphac = %10.3e + %10.3e*delta + %10.3e*delta^2\n", + printf("Momentum compact factor:\n"); + printf("alphac = %10.3e + %10.3e*delta + %10.3e*delta^2\n\n", b[1], b[2], b[3]); } -- GitLab