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/read_script.cc

    r11 r23  
    2525   Comments:
    2626       Written by Jianfeng Zhang 03/2011 soleil
    27        
    28        (1) 15/10/2013 by Jianfeng Zhang @ LAL
    29            Fix the bugs of fgets():
    30               to read lines with arbritracy length,
    31               to read the empty space at the end of the line.
    32              
    33            Remove the rontine to move the address of "line" if the
    34            contents of "line" is empty space; otherwise free() can't
    35            find the orignial address of "line".
    36            
    3727
    3828****************************************************************************/
     
    4030/* files */
    4131
    42 char    lat_file[max_str]="voidlattice";
    4332// girder file
    4433char girder_file[max_str];
     
    7867 
    7968 
    80   char    str[max_str]="voidstring", dummy[max_str]="voidstring",dummy2[max_str]="voidstring", nextpara[max_str]="voidpara";
     69  char    str[max_str]="voidstring", dummy[max_str]="voidstring", nextpara[max_str]="voidpara";
    8170  char    in[max_str];  //temporary line with preceding white space
    82   char    *line = NULL; //line to store the command without preceding white space
    83   size_t   len = 0;
    84   ssize_t  read;
     71  char    *line; //line to store the command without preceding white space
    8572  char    name[max_str]="voidname";
    86  // char    lat_file[max_str]="voidlattice";
     73  char    lat_file[max_str]="voidlattice";
    8774  char    EndName[]="void";
    88 
     75 
    8976  FILE    *inf;
    9077  const bool  prt = false; // for debugging printout each line of input file
     
    10087  // Manipulation of the parameter file
    10188  strcpy(dummy, param_file_name);
    102 
    103   sprintf(full_param_file_name,"%s",dummy);
    104   if (!prt) printf("\n reading in script file: %s\n",full_param_file_name);
     89  pch = strstr (dummy,".prm"); // search for extension .prm
     90  /* remove additional .prm if exist */
     91  if (pch != NULL) strncpy(pch,"\0",1);
     92
     93  sprintf(full_param_file_name,"%s.prm",dummy);
     94  if (prt) printf("\n reading in script file: %s\n",full_param_file_name);
    10595
    10696  //
    10797  inf = file_read(full_param_file_name);
    108    if(inf == NULL){
    109      printf("read_script(): Error! Read File %s Failure!\n",full_param_file_name);
    110      exit_(1); 
    111   }
     98
    11299 
    113100  // read parameter file, line by line
    114    while ((read = getline(&line, &len, inf)) != -1) {
    115      
    116      LineNum++;
    117      if(prt){
    118        printf("Line # %ld \n",LineNum);
    119        printf("Retrieved line of length %zu : \n",read);
    120        cout << line << endl;
    121      }
    122                
    123      
     101 //  while (fgets(line, max_str, inf) != NULL) {
     102   while (line = fgets(in, max_str, inf)) {
     103   
     104     /* kill preceding whitespace generated by "table" key
     105        or "space" key, but leave \n
     106        so we're guaranteed to have something*/
     107     while(*line == ' ' || *line == '\t') {
     108       line++;
     109     }       
     110   
     111    if(prt)
     112      printf("cfg: %s",line);
     113     
     114      LineNum++;
    124115           
    125116    /* read the end of line symbol '\n','\r' or '\r\n' at different operation system*/
    126     if (strstr(line, "#") == NULL && line[0] != '\n' &&
    127         line[0] != '\r' && strcmp(line, "\r\n") != 0 ){
     117    if (strstr(line, "#") == NULL && strcmp(line,"\n") != 0 &&
     118        strcmp(line,"\r") != 0 && strcmp(line,"\r\n") != 0) {
    128119      // get initial command token
    129120      sscanf(line, "%s", name);
     
    260251          strcpy(UserCommandFlag[CommNo].CommandStr,name);
    261252      } 
    262       //print the cooridinates using tracking at each element
    263       else if (strcmp("PrintTrackElemFlag", name) == 0){
    264           sscanf(line, "%*s %s",nextpara);
    265          
    266           if(strcmp(nextpara,"voidpara")!=0)
    267             sscanf(line, "%*s %s %lf %lf %lf %lf %lf %lf %ld %ld",
    268                         UserCommandFlag[CommNo]._PrintTrackElem_track_file,
    269                         &(UserCommandFlag[CommNo]._PrintTrackElem_x),
    270                         &(UserCommandFlag[CommNo]._PrintTrackElem_px),
    271                         &(UserCommandFlag[CommNo]._PrintTrackElem_y),
    272                         &(UserCommandFlag[CommNo]._PrintTrackElem_py),
    273                         &(UserCommandFlag[CommNo]._PrintTrackElem_delta),
    274                         &(UserCommandFlag[CommNo]._PrintTrackElem_ctau),
    275                         &(UserCommandFlag[CommNo]._PrintTrackElem_nelem1),
    276                         &(UserCommandFlag[CommNo]._PrintTrackElem_nelem2));
    277           strcpy(UserCommandFlag[CommNo].CommandStr,name);
    278       }
    279253      //print close orbit(COD) flag
    280254      else if (strcmp("PrintGirderFlag", name) == 0){
     
    293267      else if (strcmp("FmapFlag", name) == 0){       
    294268          strcpy(dummy, "");
    295           strcpy(dummy2,"");
     269         
    296270          sscanf(line, "%*s %s",nextpara);
    297271         
    298           //if no definition of loss flag in the lattice file, then "dummy2" is empty string.
    299272          if(strcmp(nextpara,"voidpara")!=0)
    300             sscanf(line, "%*s %s %ld %ld %ld %lf %lf %lf %s %s",
     273            sscanf(line, "%*s %s %ld %ld %ld %lf %lf %lf %s",
    301274                          UserCommandFlag[CommNo]._FmapFlag_fmap_file,
    302275                          &(UserCommandFlag[CommNo]._FmapFlag_nxpoint),
     
    306279                          &(UserCommandFlag[CommNo]._FmapFlag_ymax),
    307280                          &(UserCommandFlag[CommNo]._FmapFlag_delta),
    308                           dummy,dummy2);
     281                          dummy);
    309282         
    310283        if(strcmp(dummy, "true") == 0)
     
    313286          UserCommandFlag[CommNo]._FmapFlag_diffusion = false;
    314287       
    315         if(strcmp(dummy2, "true") == 0)
    316           UserCommandFlag[CommNo]._FmapFlag_printloss = true;
    317         else if(strcmp(dummy2, "false") == 0)
    318           UserCommandFlag[CommNo]._FmapFlag_printloss = false;
    319         else
    320           UserCommandFlag[CommNo]._FmapFlag_printloss = false;
    321        
    322        
    323         //cout << "debug:      " << line << endl;
    324         //cout << "dummy2 =  " << dummy2 << "     lossflag =  " << UserCommandFlag[CommNo]._FmapFlag_printloss << endl;
    325        
    326288       // FmapFlag = true;
    327289         strcpy(UserCommandFlag[CommNo].CommandStr,name);
     
    330292      else if (strcmp("FmapdpFlag", name) == 0){         
    331293          strcpy(dummy, "");
    332           strcpy(dummy2,"");
    333294          sscanf(line, "%*s %s",nextpara);
    334           
     295         
    335296          if(strcmp(nextpara,"voidpara")!=0)
    336             sscanf(line, "%*s %s %ld %ld %ld %lf %lf %lf %s %s",
     297            sscanf(line, "%*s %s %ld %ld %ld %lf %lf %lf %s",
    337298                        UserCommandFlag[CommNo]._FmapdpFlag_fmapdp_file,
    338299                        &(UserCommandFlag[CommNo]._FmapdpFlag_nxpoint),
     
    342303                        &(UserCommandFlag[CommNo]._FmapdpFlag_emax),
    343304                        &(UserCommandFlag[CommNo]._FmapdpFlag_z),
    344                         dummy,dummy2);
     305                        dummy);
    345306         
    346307        if(strcmp(dummy, "true") == 0)
     
    349310          UserCommandFlag[CommNo]._FmapdpFlag_diffusion = false;
    350311
    351         if(strcmp(dummy2, "true") == 0)
    352           UserCommandFlag[CommNo]._FmapdpFlag_printloss = true;
    353         else if(strcmp(dummy2, "false") == 0)
    354           UserCommandFlag[CommNo]._FmapdpFlag_printloss = false;
    355         else
    356           UserCommandFlag[CommNo]._FmapdpFlag_printloss = false;
    357        
    358        
    359         cout << "debug:      " << line << endl;
    360         cout << "dummy2 =  " << dummy2 << "     lossflag =  " << UserCommandFlag[CommNo]._FmapdpFlag_printloss << endl;
    361        
    362312          //  FmapdpFlag = true;
    363313         strcpy(UserCommandFlag[CommNo].CommandStr,name);
     
    585535        exit_(1);
    586536      }
    587   }
     537    }
    588538    /* continue read in the line */
    589539    else
    590      continue;
    591   }//end of while loop
    592  
    593   free(line);
    594  
     540      continue;
     541  }
    595542  fclose(inf);
    596543
Note: See TracChangeset for help on using the changeset viewer.