| Author | 
                
                  Topic   | 
                
                
                 
                 
                 
                 
                 
                                 | 
              
              
                | 
                 Markus 
                 
                
                Germany 
                29 Posts  | 
                
                  
                    
                      
                       Posted - 11/08/2001 :  04:44:17 AM
                        
                        
                        
                        
                        
                      
  | 
                     
                    
                       I want to import a single ascii-file into different worksheets by using the 'when non-numeric is found in numeric fields-start new worksheet' feature in the ascii-import options. The spectral-data-file looks like the following lines: # 06.11.2001 12:24:00 304.448	237.000	220.000	269.000 307.782	272.000	253.000	299.000 311.114	310.000	262.000	317.000 ..... 1124.781	413.000	360.000	384.000 1127.961	405.000	374.000	390.000 1131.141	420.000	372.000	396.000 1134.320	412.000	376.000	395.000 # 06.11.2001 12:24:05 304.448	242.000	214.000	270.000 307.782	268.000	252.000	301.000 311.114	318.000	266.000	325.000 314.446	355.000	290.000	359.000 317.778	425.000	322.000	409.000 ..... 1124.781	427.000	382.000	398.000 1127.961	416.000	376.000	393.000 1131.141	426.000	376.000	401.000 1134.320	420.000	376.000	394.000 # 06.11.2001 12:24:10 304.448	236.000	217.000	271.000 307.782	273.000	258.000	310.000 311.114	313.000	264.000	322.000 ..... During import I want to rename the wks with the header line or a string of substrings representing the header (which is yyyy.mm.dd hh:mm:ss), like Ammddhhmmss. Import into new wks works, but where to place the renaming script. I thought it must be somewhere in a loop in the file.ogs but I can't find it. And how to access the header line that caused the new worksheet. Is it stored in a string variable? Thanks for any help
  Markus | 
                     
                   
                 | 
              
              
                | 
                 Laurie 
                 
                
                USA 
                404 Posts  | 
                
                  
                    
                      
                       Posted - 11/08/2001 :  12:37:45 PM
                        
                        
                        
                        
                        
                      
  | 
                     
                    
                       You will need to create a text label on the worksheet and name it header.  (you can even hide the object so that is is not visible)  The header for each worksheet will then be placed as the text for this header object.
  You will then have to run a script after all the data is brought in - the code that handles importing into a new worksheet when non-numeric is found is all handled internally.  You can get the header text by using the following:
  %Z=header.text$;
  You'll have to loop through all the worksheets...if you have further questions about how to do this, please feel free to ask.
  Thanks, Laurie
  OriginLab Technical Support | 
                     
                    
                        | 
                     
                   
                 | 
              
              
                | 
                 Markus 
                 
                
                Germany 
                29 Posts  | 
                
                  
                    
                      
                       Posted - 11/12/2001 :  04:18:27 AM
                        
                        
                        
                        
                        
                      
  | 
                     
                    
                       Hi Laurie, this works fine; I played a little with the FUM from Origin Prof. and got the following:
  getfile *.spk;   #select spectra hfile=file.open(%B%A,0);   #open file file.listsep("\t");   #separator Tab win -c Data1;   #close wks
  m=1;    #initial value i=0;    #counter for No. of spectra
  for (;m>0;) { m=file.lread(M);#read the header in %M if ($(m)==0) {file.close();break;};     #EOF reached
  win -t data origin;  #new wks for the data
  %M=A%[%M,11:12]%[%M,6:7]%[%M,3:4]%[%M,14:15]%[%M,17:18]%[%M,20:21];   #this is the new wks name win -r %H %M;   #rename wks and loop through the 256 data rows, import them into cols 1 to 4
  	loop(row,1,256)				 	{ 	tokensread=file.readrow(%H,4); 	}; i+=1; # increase counter for spectra }; file.close();
 
  Thank you Markus
  Edited by - Markus on 11/12/2001  08:55:20 | 
                     
                    
                        | 
                     
                   
                 | 
              
              
                | 
                 Laurie 
                 
                
                USA 
                404 Posts  | 
                
                  
                    
                      
                       Posted - 11/12/2001 :  1:06:17 PM
                        
                        
                        
                        
                        
                      
  | 
                     
                    
                       Hi Markus,
  Looks good.  Yes, using the FUM, File Utilities Module, in OriginPRO, you'll have more control over how the file is brought in.
  Laurie
  OriginLab Technical Support | 
                     
                    
                        | 
                     
                   
                 | 
              
              
                | 
                 sasi245 
                 
                
                Germany 
                9 Posts  | 
                
                  
                    
                      
                       Posted - 03/15/2002 :  10:01:50 AM
                        
                        
                        
                        
                        
                      
  | 
                     
                    
                       Hi  I also want to import Single ansii file into different wks  on 'when non-numeric is found in numeric fields-start new worksheet', same as Markus.But in My case no. of rows are not fixed.I think I have to get the no. of end numeric row and loop through those rows as in the above program. I want your help in this regard. Thank You....sasi
 
   
  | 
                     
                    
                        | 
                     
                   
                 | 
              
              
                | 
                 Laurie 
                 
                
                USA 
                404 Posts  | 
                
                  
                    
                      
                       Posted - 03/15/2002 :  11:23:18 AM
                        
                        
                        
                        
                        
                      
  | 
                     
                    
                       It depends upon what you're trying to do.  If you are only interested in creating new worksheets when non-numeric data is found you can just use the ASCII Import Options and you don't need to write your own import routine using the FUM.  And it doesn't matter that the number of rows are not the same.  Have you tried just using the menu, File:Import ASCII?
  OriginLab Technical Support | 
                     
                    
                        | 
                     
                   
                 | 
              
              
                | 
                 sasi245 
                 
                
                Germany 
                9 Posts  | 
                
                  
                    
                      
                       Posted - 03/18/2002 :  07:04:42 AM
                        
                        
                        
                        
                        
                      
  | 
                     
                    
                       HiLaurie, Thanks for the reply.My problem is Table1 data should come into one wks and table2 data into another wks like that.Its not just open a new wks.I tried File:Import ASCII Option,but its not producing desired results. So I want to write a Import Routine. Thanks for any help....Sasi | 
                     
                    
                        | 
                     
                   
                 | 
              
              
                | 
                 Laurie 
                 
                
                USA 
                404 Posts  | 
                
                  
                    
                      
                       Posted - 03/18/2002 :  09:56:33 AM
                        
                        
                        
                        
                        
                      
  | 
                     
                    
                       You say that the ASCII Import Options are not providing the desired results.  Can you explain what you get and what you want?  With the menu, you do get a new wks for each table?
  Laurie
  OriginLab Technical Support | 
                     
                    
                        | 
                     
                   
                 | 
              
              
                | 
                 sasi245 
                 
                
                Germany 
                9 Posts  | 
                
                  
                    
                      
                       Posted - 03/19/2002 :  08:36:29 AM
                        
                        
                        
                        
                        
                      
  | 
                     
                    
                       Hi Laurie, I am getting the new worksheet,if I use ANSII options.But my problem is I have to rename each worksheet.Which at present I am not able to do with Ansii options.And second is I want some text data in the first column.In detail my table look like  Table1 Voltage =0.0213V, Current =...., Frequency =..; ..(up to 10 parameters) (Then numeric data starts) I want the first 10 text fields ,which are different for each Table, in  first columns of each worksheet.If I can do this with ANSII options Please let me know.. Thanks for your help...sasi
  | 
                     
                    
                        | 
                     
                   
                 | 
              
              
                | 
                 Laurie 
                 
                
                USA 
                404 Posts  | 
                
                  
                    
                      
                       Posted - 03/19/2002 :  10:27:04 AM
                        
                        
                        
                        
                        
                      
  | 
                     
                    
                       If you use the FUM, ideally you'd know the number of rows of data or you'd have a line in the file that stores this information (so that you can then read this).
  You'd have to write your script so that you check the return value and then that would depend upon whether the line was data or text.  This checking process will slow down the import routine.
  If you use File:Import ASCII menu option, then on your worksheet add a text label.  It doesn't matter what the text says because it will get replaced with the header information.  Open Label Control for this text object by Alt.+double-clicking on it and rename it 'header'.  Now when you import, for each new worksheet created, you'll see the following text:
  Table1 Voltage =0.0213V, Current =...., Frequency =..; ..(up to 10 parameters)
  You can then write a LabTalk script to parse out the text in order to label your columns (wks.col1.label$="mylabel") and rename your worksheets (win -r %H newname;)
  Laurie
  OriginLab Technical Support | 
                     
                    
                        | 
                     
                   
                 | 
              
              
                | 
                 sasi245 
                 
                
                Germany 
                9 Posts  | 
                
                  
                    
                      
                       Posted - 03/21/2002 :  08:19:12 AM
                        
                        
                        
                        
                        
                      
  | 
                     
                    
                       hi laurie; Thanks .That works fine. One question,Is there any procedure to insert this header data in to the first column of each wks?
  Means by inserting new rows and put this text data in first column line by line? Thanks once again...Sasi | 
                     
                    
                        | 
                     
                   
                 | 
              
              
                | 
                 Mike Buess 
                 
                
                USA 
                3037 Posts  | 
                
                  
                    
                      
                       Posted - 03/21/2002 :  08:48:49 AM
                        
                        
                        
                        
                        
                      
  | 
                     
                    
                       Sasi,
  This script should work. It assumes that the worksheet is active. The second and third lines might be unnecessary and you might want to name the first column differently.
  wo -i 0 Header; // Insert column at beginning wo -t 1 2; // Set type as 'disregard' wo -f 1 2; // Set format as 'text' %Z=header.text$; for(ii=1;ii>0;ii++) { %A=%[%Z,@ii]; if(%A=="") break; %(%H,1,ii)=%A; };
  You could use it as the worksheet script for the template (Tools | Worksheet Script) and check Run Script Automatically after Import.
  Mike Buess Origin WebRing Member
  Edited by - Mike Buess on 03/21/2002  08:53:55 | 
                     
                    
                        | 
                     
                   
                 | 
              
              
                | 
                 sasi245 
                 
                
                Germany 
                9 Posts  | 
                
                  
                    
                      
                       Posted - 03/21/2002 :  11:59:07 AM
                        
                        
                        
                        
                        
                      
  | 
                     
                    
                       Thanks Mike, It's working. Another thing is I have to Delete the last text line in the header.I tried assuming  %A=%[%Z,@ii-1]; in your script but I failed to do so. Suggest me.  Thanks for your help....Sasi | 
                     
                    
                        | 
                     
                   
                 | 
              
              
                | 
                 Mike Buess 
                 
                
                USA 
                3037 Posts  | 
                
                  
                    
                      
                       Posted - 03/21/2002 :  12:26:57 PM
                        
                        
                        
                        
                        
                      
  | 
                     
                    
                       Sasi,
  If you just want to keep the last line out of the column change the for loop to this...
  for(ii=1;ii>0;ii++) { %A=%[%Z,@ii+1]; if(%A=="") break; %(%H,1,ii)=%[%Z,@ii]; };
  BTW, if your header always has N lines you can replace the for loop with
  loop (ii,1,N-1) {%(%H,1,ii)=%[%Z,@ii]};
  Mike Buess Origin WebRing Member | 
                     
                    
                        | 
                     
                   
                 | 
              
              
                |   | 
                
                  Topic   | 
                
                
                 
                 
                 
                 
                 
                 |