Loading multiple waves with different firstline values

noxidxela
Posts: 4
Joined: 2013-04-25
Location: United States

Hi. I have a function that loads in waves from multiple text files using LoadWave. Most of the files have a header of a set length so I use the /L flag and set the location of the first line of data. However in a few of the files, the header is a couple of lines longer, this causes LoadWave to start loading the header itself instead of the desired data. The end of the header has a clear deliminator, Is there any way to read the line location of this delimitation so I can make the "first line" variable?

Thanks!


Posts: 1693
Joined: 2007-06-21
Location: United States

If your data is all numeric, use LoadWave/G, without /L, instead of LoadWave/J. LoadWave/G automatically finds the first line containing data.
Otherwise here is a code snippet that shows how to find the first line: http://www.igorexchange.com/node/4856


HJDrescher
Posts: 364
Joined: 2015-01-20
Location: Germany

In case the automatic detection does not work, the /L flag should do the job. Just parse your file for the end of header delimiter (using FReadLine), count the lines and hand it to the /L flag as a parameter.
HJ


noxidxela
Posts: 4
Joined: 2013-04-25
Location: United States

HJDrescher wrote:
In case the automatic detection does not work, the /L flag should do the job. Just parse your file for the end of header delimiter (using FReadLine), count the lines and hand it to the /L flag as a parameter.
HJ

Thanks, I ended up going with your suggestion and writing a little function to find the start line for the L flag.

Function EndofheaderLoc(path)
	string path
	variable refn,i
	string readstring
        i=0
	open/r refn path
	do
		FReadline refn ,  readstring
		i+=1
	while (strsearch (readstring, "*HeaderEnd*",0,2)<0)
	return i	
end


Posts: 1966
Joined: 2007-06-29
Location: United States

Nice and simple! May I suggest that you call Close on the file before returning?

John Weeks
WaveMetrics, Inc.
support@wavemetrics.com


tony
Posts: 175
Joined: 2007-08-28
Location: Canada

also easy with grep:

Function EndofheaderLoc(path)
	string path
 
	Grep /Q/E="\*HeaderEnd\*"/Z path
	return V_startParagraph
end


[ last edited March 15, 2018 - 10:55 ]
thomas_braun
Posts: 597
Joined: 2009-10-07
Location: Germany

@tony: You are missing the dot before the star in the regexp.


tony
Posts: 175
Joined: 2007-08-28
Location: Canada

thomas_braun wrote:
@tony: You are missing the dot before the star in the regexp.

Oops, actually, I forgot to escape the asterisks in the regexp. The asterisks were part of the end-of-header mark in the example given. Edited to correct. Thanks, Thomas.


Back to top