Index: branches/tracy3-3.10.1b/tracy/tracy/src/read_script.cc
===================================================================
--- branches/tracy3-3.10.1b/tracy/tracy/src/read_script.cc	(revision 22)
+++ branches/tracy3-3.10.1b/tracy/tracy/src/read_script.cc	(revision 23)
@@ -25,14 +25,4 @@
    Comments:
        Written by Jianfeng Zhang 03/2011 soleil
-       
-       (1) 15/10/2013 by Jianfeng Zhang @ LAL
-           Fix the bugs of fgets():
-              to read lines with arbritracy length, 
-	      to read the empty space at the end of the line.
-	      
-	   Remove the rontine to move the address of "line" if the 
-	   contents of "line" is empty space; otherwise free() can't
-	   find the orignial address of "line". 
-           
 
 ****************************************************************************/
@@ -40,5 +30,4 @@
 /* files */ 
 
-char    lat_file[max_str]="voidlattice";
 // girder file
 char girder_file[max_str];
@@ -78,13 +67,11 @@
  
   
-  char    str[max_str]="voidstring", dummy[max_str]="voidstring",dummy2[max_str]="voidstring", nextpara[max_str]="voidpara";
+  char    str[max_str]="voidstring", dummy[max_str]="voidstring", nextpara[max_str]="voidpara";
   char    in[max_str];  //temporary line with preceding white space
-  char    *line = NULL; //line to store the command without preceding white space
-  size_t   len = 0;
-  ssize_t  read;
+  char    *line; //line to store the command without preceding white space
   char    name[max_str]="voidname";
- // char    lat_file[max_str]="voidlattice";
+  char    lat_file[max_str]="voidlattice";
   char    EndName[]="void";
-
+ 
   FILE    *inf;
   const bool  prt = false; // for debugging printout each line of input file
@@ -100,30 +87,34 @@
   // Manipulation of the parameter file
   strcpy(dummy, param_file_name);
-
-  sprintf(full_param_file_name,"%s",dummy);
-  if (!prt) printf("\n reading in script file: %s\n",full_param_file_name);
+  pch = strstr (dummy,".prm"); // search for extension .prm
+  /* remove additional .prm if exist */
+  if (pch != NULL) strncpy(pch,"\0",1);
+
+  sprintf(full_param_file_name,"%s.prm",dummy);
+  if (prt) printf("\n reading in script file: %s\n",full_param_file_name);
 
   //
   inf = file_read(full_param_file_name);
-   if(inf == NULL){
-     printf("read_script(): Error! Read File %s Failure!\n",full_param_file_name);
-     exit_(1);  
-  }
+
   
   // read parameter file, line by line 
-   while ((read = getline(&line, &len, inf)) != -1) {
-     
-     LineNum++;
-     if(prt){
-       printf("Line # %ld \n",LineNum);
-       printf("Retrieved line of length %zu : \n",read);
-       cout << line << endl;
-     }
-               
-     
+ //  while (fgets(line, max_str, inf) != NULL) {
+   while (line = fgets(in, max_str, inf)) {
+   
+     /* kill preceding whitespace generated by "table" key
+        or "space" key, but leave \n 
+        so we're guaranteed to have something*/
+     while(*line == ' ' || *line == '\t') {
+       line++;
+     }       
+    
+    if(prt)
+      printf("cfg: %s",line);
+      
+      LineNum++;
            
     /* read the end of line symbol '\n','\r' or '\r\n' at different operation system*/
-    if (strstr(line, "#") == NULL && line[0] != '\n' &&
-        line[0] != '\r' && strcmp(line, "\r\n") != 0 ){
+    if (strstr(line, "#") == NULL && strcmp(line,"\n") != 0 &&
+        strcmp(line,"\r") != 0 && strcmp(line,"\r\n") != 0) {
       // get initial command token
       sscanf(line, "%s", name); 
@@ -260,21 +251,4 @@
 	  strcpy(UserCommandFlag[CommNo].CommandStr,name);
       }  
-      //print the cooridinates using tracking at each element
-      else if (strcmp("PrintTrackElemFlag", name) == 0){
-	  sscanf(line, "%*s %s",nextpara);
-	 
-	  if(strcmp(nextpara,"voidpara")!=0)
-	    sscanf(line, "%*s %s %lf %lf %lf %lf %lf %lf %ld %ld", 
-	                UserCommandFlag[CommNo]._PrintTrackElem_track_file,
-          		&(UserCommandFlag[CommNo]._PrintTrackElem_x), 
-			&(UserCommandFlag[CommNo]._PrintTrackElem_px),
-          		&(UserCommandFlag[CommNo]._PrintTrackElem_y), 
-			&(UserCommandFlag[CommNo]._PrintTrackElem_py), 
-			&(UserCommandFlag[CommNo]._PrintTrackElem_delta), 
-			&(UserCommandFlag[CommNo]._PrintTrackElem_ctau),
-			&(UserCommandFlag[CommNo]._PrintTrackElem_nelem1),
-	    		&(UserCommandFlag[CommNo]._PrintTrackElem_nelem2));
-	  strcpy(UserCommandFlag[CommNo].CommandStr,name);
-      } 
       //print close orbit(COD) flag
       else if (strcmp("PrintGirderFlag", name) == 0){
@@ -293,10 +267,9 @@
       else if (strcmp("FmapFlag", name) == 0){        
     	  strcpy(dummy, "");
-	  strcpy(dummy2,"");
+	  
 	  sscanf(line, "%*s %s",nextpara);
 	 
-	  //if no definition of loss flag in the lattice file, then "dummy2" is empty string.
 	  if(strcmp(nextpara,"voidpara")!=0)
-            sscanf(line, "%*s %s %ld %ld %ld %lf %lf %lf %s %s", 
+            sscanf(line, "%*s %s %ld %ld %ld %lf %lf %lf %s", 
               		  UserCommandFlag[CommNo]._FmapFlag_fmap_file,
 			  &(UserCommandFlag[CommNo]._FmapFlag_nxpoint), 
@@ -306,5 +279,5 @@
 			  &(UserCommandFlag[CommNo]._FmapFlag_ymax),
           		  &(UserCommandFlag[CommNo]._FmapFlag_delta), 
-			  dummy,dummy2);
+			  dummy);
          
         if(strcmp(dummy, "true") == 0)
@@ -313,15 +286,4 @@
           UserCommandFlag[CommNo]._FmapFlag_diffusion = false;
        
-	if(strcmp(dummy2, "true") == 0)
-          UserCommandFlag[CommNo]._FmapFlag_printloss = true;
-        else if(strcmp(dummy2, "false") == 0)
-          UserCommandFlag[CommNo]._FmapFlag_printloss = false;
-	else
-	  UserCommandFlag[CommNo]._FmapFlag_printloss = false;
-	
-	
-	//cout << "debug:      " << line << endl;
-	//cout << "dummy2 =  " << dummy2 << "     lossflag =  " << UserCommandFlag[CommNo]._FmapFlag_printloss << endl;
-	
        // FmapFlag = true;
          strcpy(UserCommandFlag[CommNo].CommandStr,name);
@@ -330,9 +292,8 @@
       else if (strcmp("FmapdpFlag", name) == 0){         
     	  strcpy(dummy, "");
-	  strcpy(dummy2,"");
 	  sscanf(line, "%*s %s",nextpara);
-	  
+	 
 	  if(strcmp(nextpara,"voidpara")!=0)
-            sscanf(line, "%*s %s %ld %ld %ld %lf %lf %lf %s %s", 
+            sscanf(line, "%*s %s %ld %ld %ld %lf %lf %lf %s", 
           		UserCommandFlag[CommNo]._FmapdpFlag_fmapdp_file,
 			&(UserCommandFlag[CommNo]._FmapdpFlag_nxpoint),
@@ -342,5 +303,5 @@
 			&(UserCommandFlag[CommNo]._FmapdpFlag_emax),
           		&(UserCommandFlag[CommNo]._FmapdpFlag_z), 
-			dummy,dummy2);
+			dummy);
 	 
         if(strcmp(dummy, "true") == 0)
@@ -349,15 +310,4 @@
           UserCommandFlag[CommNo]._FmapdpFlag_diffusion = false;
 
-	if(strcmp(dummy2, "true") == 0)
-          UserCommandFlag[CommNo]._FmapdpFlag_printloss = true;
-        else if(strcmp(dummy2, "false") == 0)
-          UserCommandFlag[CommNo]._FmapdpFlag_printloss = false;
-	else
-	  UserCommandFlag[CommNo]._FmapdpFlag_printloss = false;
-	
-	
-	cout << "debug:      " << line << endl;
-	cout << "dummy2 =  " << dummy2 << "     lossflag =  " << UserCommandFlag[CommNo]._FmapdpFlag_printloss << endl;
-	
 	  //  FmapdpFlag = true;
          strcpy(UserCommandFlag[CommNo].CommandStr,name);
@@ -585,12 +535,9 @@
         exit_(1);
       }
-  }
+    }
     /* continue read in the line */ 
     else
-     continue;
-  }//end of while loop
-  
-  free(line);
-  
+      continue;
+  }
   fclose(inf);
 }  
