Excluding portions of text from wave

Hello all

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
I'm not too sure that I understand what you need to do. Perhaps an example file would help.

To read individual lines from a file you can either have LoadWave load the file content into a text wave, or you can use FReadLine in conjunction with Open and Close. Using LoadWave is probably the easiest approach.

Jonpope wrote:
directory1/directory2/directory3/filename


Here are two options for extracting filename from this string:
1) Convert the '/' characters to ':' (ReplaceString) and use ParseFilePath with mode = 0 and whichEnd = 1.
2) Use StringFromList(ItemsInList(myString, "/") - 1, myString, "/")
Hi 741

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

If you are asking how to strip the path part of "directory1/directory2/directory3/filename" from a series of strings stored in a text wave then here is a solution:

Function/S GetFileNameFromPath(path)
    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

Thanks once again Hrodstein, sorry to be dense be how do I convert values from a text wave to a string? (Have only done it thus far with numerical waves using num2str)
Quote:
how do I convert values from a text wave to a string? (Have only done it thus far with numerical waves using num2str)


Since a text wave contains strings you don't need to do any conversion. For example:
Make/T/O test = {"Hello", "Goodbye"}
String str = test[0]
Print str
str = test[1]
Print str