Excluding portions of text from wave
Jonpope
I've encountered an issue whilst attempting to load a series of filenames as a wave. These are contained within a reference file, some columns in which are in the format "directory1/directory2/directory3/filename" and the filename portion is all that is required for the wave. The Igor manual seems to suggest that the 'LoadWave' function doesn't have the capability to do this.
If needs be I can read them into Igor as a text string and convert to a wave later: Is there a facility/function within Igor that allows me to specify which characters are read from a line, like in C++?
As always any help is greatly appreciated.
Jon
To read individual lines from a file you can either have
LoadWave
load the file content into a text wave, or you can useFReadLine
in conjunction withOpen
andClose
. Using LoadWave is probably the easiest approach.Here are two options for extracting filename from this string:
1) Convert the '/' characters to ':' (
ReplaceString
) and useParseFilePath
with mode = 0 and whichEnd = 1.2) Use
StringFromList(ItemsInList(myString, "/") - 1, myString, "/")
November 20, 2012 at 05:50 am - Permalink
I previously looked into using FreadLine, unfortunately I have not been able to find any way of determining which line is the first to be read, therefore I'm assuming it would read from the beginning of the file which is not suitable.
The file from which I'm reading has the following format:
H , K , L , INTENSITY , FILENAME , TEMPERATURE
1 , 1 , 1 , 43 , directory/directory1/filename1 , 30
1 , 0 , 1 , 30 , directory/directory1/filename2 , 30
2 , 1 , 1 , 57 , directory/directory1/filename3 , 30
1 , 0 , 0 , 50 , directory/directory1/filename4 , 30
etc.....
(the commas are just to make it a bit easier to read in a forum post; the file is tab delimited)
So ideally I would like to load a wave consisting of filename1,filename2,etc.... however if this isn't possible then I can read in the whole contents of the column as a wave (directory/directory1/filename1,directory/directory1/filename2,directory/directory1/filename3,etc.....) and then perform another operation to remove the 'directory' component of the wave.
There are two scenarios I'm attempting this for, in one case 'filename' is a real number and in the other it is solely text.
Thanks
Jon
November 20, 2012 at 06:50 am - Permalink
String path // e.g., "directory1/directory2/directory3/filename"
Variable len = strlen(path)
Variable pos = strsearch(path, "/", len, 3) // Find last backslash
if (pos < 0)
return "" // Not found
endif
path = path[pos+1,len]
return path
End
Function Demo()
Make /O /T test = {"directory1/directory2/directory3/filenameA", "directory1/directory2/directory3/filenameB"}
// Remove path up to filename, returning just filename
test = GetFileNameFromPath(test)
Edit test
End
November 20, 2012 at 06:54 am - Permalink
November 20, 2012 at 08:59 am - Permalink
Since a text wave contains strings you don't need to do any conversion. For example:
String str = test[0]
Print str
str = test[1]
Print str
November 20, 2012 at 11:24 am - Permalink
November 20, 2012 at 03:27 pm - Permalink