Adding filename to Wave names

 

 

Hello,

I am trying to upload many files that each have 50 or so waves. These waves are the same in each file (each file -which represents a date- has a methanol wave, a chloroform wave, etc). I upload each file to a different data folder. Eventually, I want to graph all the ethanol traces from all the different dates on the same graph. I am able to upload everything just fine, but I would like to know how to append the date from the filename to each trace. For example, Ethanol (the name comes from the file itself) would be renamed Ethanol07072007 for example

Thank you

 

 

Function/S DoLoadMultipleFiles()
   
    // change this to be the folder that contains the files
    NewPath/O TOGAFrappe "C:Users:aroob:Desktop:Research:TOGAFrappe:"
   
        String filelist= IndexedFile(TOGAFRAPPE,-1,".ict")
        Variable numFilesSelected = ItemsInList(filelist)
        Variable ifile
       
        //loads the waves
        for(ifile=0; ifile<numFilesSelected; ifile+=1)
            String filename = StringFromList(ifile, filelist, ";")
           
            // Get just the fileName but with the extension removed.
            String DataFldrName = ParseFilePath(0, filename, "_", 1, 1)
            NewDataFolder/O/S root:$DataFldrName
           
            LoadWave/A/W/D/G/K=0/E=2/V={" "," $",0,0}/L={0,2,0,0,0}/P=TOGAFrappe filename
           
            //Function that deletes the random 1 and -199 throughout the file
            DeleteExtra()      
           
        endfor

    End
For cleaner organization, you should consider loading the waves from each file into a separate data folder. Then you don't need unique names for corresponding waves from different files. I have posted an example at http://www.igorexchange.com/node/6490.

If you don't want to do that then ...

If you know the desired base wave names in advance, use the LoadWave /B flag to set the wave names of waves being loaded. See LoadWave documentation for details.

See http://www.igorexchange.com/node/6409 for an example. In your case you would set columnInfoStr something like this:
String suffix = "07072007"   // You would compute this by examining your filename variable
String columnInfoStr = ""
columnInfoStr += "N=Ethanol_" + suffix + ";"
columnInfoStr += "N=Methanol_" + suffix + ";"
columnInfoStr += "N=Propanol_" + suffix + ";"
...
LoadWave /B=columnInfoStr ...
Hello,

Thank you so much for responding so quickly. If I understood you correctly, I actually did do your first idea. Each data folder has all the waves for that file. That post was the base for what I did. I only need them to have different names because eventually I will plot all the ethanol traces on the same graph and would like to distinguish them from each other (so Ethanol_070815 and Ethanol_070915 will be on the same graph and I want to be able to click on a point and know which date that data point comes from). I could manually edit them all in using the B_flag, but that would mean I enter all 50 wavenames in (since they are all different). Is there a more efficient way of doing it, or is this it?
Quote:
I actually did do your first idea. Each data folder has all the waves for that file.


Excellent.

Quote:
I only need them to have different names because eventually I will plot all the ethanol traces on the same graph and would like to distinguish them from each other (so Ethanol_070815 and Ethanol_070915 will be on the same graph and I want to be able to click on a point and know which date that data point comes from).


You can achieve this by using a different trace name. Execute this for relevant help and note the /TN flag used with Display and AppendToGraph.
DisplayHelpTopic "Trace Names"


Even with different trace names, you still might want unique wave names for other reasons.

Quote:
I could manually edit them all in using the B_flag, but that would mean I enter all 50 wavenames in (since they are all different). Is there a more efficient way of doing it, or is this it?


You could read the wave names from the file using Open, FReadLine and Close. However, if the wave names are fixed, it is easier to just write a function that returns the string appropriate for the LoadWave /B flag. You only have to do this once. When dealing with a lot of wave names, I split this out into a function like this:

static Function/S GetColumnInfoStr(suffix)
    String suffix               // e.g., "07072007"

    String columnInfoStr = ""
   
    columnInfoStr += "N=Ethanol_" + suffix + ";"
    columnInfoStr += "N=Methanol_" + suffix + ";"
    columnInfoStr += "N=Propanol_" + suffix + ";"
    ...
   
    return columnInfoStr
End


If your wave names are liberal names then you need to include single quotes, like this:
static Function/S GetColumnInfoStr(suffix)
    String suffix               // e.g., "07072007"

    String columnInfoStr = ""
   
    columnInfoStr += "N='Ethanol-" + suffix + "';"
    columnInfoStr += "N='Methanol-" + suffix + "';"
    columnInfoStr += "N='Propanol-" + suffix + "';"
    ...
   
    return columnInfoStr
End


You can use the single quotes even if the names are not liberal.

For details on liberal names, execute:
DisplayHelpTopic "Object Names"


Ok I see. So then I would make columninfostring be the list of the wave names in order, and all I would do is write /B=ColumnInfoString and it would write them all in?

Thank you so much.