Changeset 23 in TRACY3 for branches/tracy3-3.10.1b/tracy/tracy/src/read_script.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/read_script.cc
r11 r23 25 25 Comments: 26 26 Written by Jianfeng Zhang 03/2011 soleil 27 28 (1) 15/10/2013 by Jianfeng Zhang @ LAL29 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 the34 contents of "line" is empty space; otherwise free() can't35 find the orignial address of "line".36 37 27 38 28 ****************************************************************************/ … … 40 30 /* files */ 41 31 42 char lat_file[max_str]="voidlattice";43 32 // girder file 44 33 char girder_file[max_str]; … … 78 67 79 68 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"; 81 70 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 85 72 char name[max_str]="voidname"; 86 //char lat_file[max_str]="voidlattice";73 char lat_file[max_str]="voidlattice"; 87 74 char EndName[]="void"; 88 75 89 76 FILE *inf; 90 77 const bool prt = false; // for debugging printout each line of input file … … 100 87 // Manipulation of the parameter file 101 88 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); 105 95 106 96 // 107 97 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 112 99 113 100 // 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++; 124 115 125 116 /* 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) { 128 119 // get initial command token 129 120 sscanf(line, "%s", name); … … 260 251 strcpy(UserCommandFlag[CommNo].CommandStr,name); 261 252 } 262 //print the cooridinates using tracking at each element263 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 }279 253 //print close orbit(COD) flag 280 254 else if (strcmp("PrintGirderFlag", name) == 0){ … … 293 267 else if (strcmp("FmapFlag", name) == 0){ 294 268 strcpy(dummy, ""); 295 strcpy(dummy2,"");269 296 270 sscanf(line, "%*s %s",nextpara); 297 271 298 //if no definition of loss flag in the lattice file, then "dummy2" is empty string.299 272 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", 301 274 UserCommandFlag[CommNo]._FmapFlag_fmap_file, 302 275 &(UserCommandFlag[CommNo]._FmapFlag_nxpoint), … … 306 279 &(UserCommandFlag[CommNo]._FmapFlag_ymax), 307 280 &(UserCommandFlag[CommNo]._FmapFlag_delta), 308 dummy ,dummy2);281 dummy); 309 282 310 283 if(strcmp(dummy, "true") == 0) … … 313 286 UserCommandFlag[CommNo]._FmapFlag_diffusion = false; 314 287 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 else320 UserCommandFlag[CommNo]._FmapFlag_printloss = false;321 322 323 //cout << "debug: " << line << endl;324 //cout << "dummy2 = " << dummy2 << " lossflag = " << UserCommandFlag[CommNo]._FmapFlag_printloss << endl;325 326 288 // FmapFlag = true; 327 289 strcpy(UserCommandFlag[CommNo].CommandStr,name); … … 330 292 else if (strcmp("FmapdpFlag", name) == 0){ 331 293 strcpy(dummy, ""); 332 strcpy(dummy2,"");333 294 sscanf(line, "%*s %s",nextpara); 334 295 335 296 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", 337 298 UserCommandFlag[CommNo]._FmapdpFlag_fmapdp_file, 338 299 &(UserCommandFlag[CommNo]._FmapdpFlag_nxpoint), … … 342 303 &(UserCommandFlag[CommNo]._FmapdpFlag_emax), 343 304 &(UserCommandFlag[CommNo]._FmapdpFlag_z), 344 dummy ,dummy2);305 dummy); 345 306 346 307 if(strcmp(dummy, "true") == 0) … … 349 310 UserCommandFlag[CommNo]._FmapdpFlag_diffusion = false; 350 311 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 else356 UserCommandFlag[CommNo]._FmapdpFlag_printloss = false;357 358 359 cout << "debug: " << line << endl;360 cout << "dummy2 = " << dummy2 << " lossflag = " << UserCommandFlag[CommNo]._FmapdpFlag_printloss << endl;361 362 312 // FmapdpFlag = true; 363 313 strcpy(UserCommandFlag[CommNo].CommandStr,name); … … 585 535 exit_(1); 586 536 } 587 }537 } 588 538 /* continue read in the line */ 589 539 else 590 continue; 591 }//end of while loop 592 593 free(line); 594 540 continue; 541 } 595 542 fclose(inf); 596 543 }
Note: See TracChangeset
for help on using the changeset viewer.