How can I preserve numeric wave names when importing?

I am importing waves automatically in a user-defined function from multiple .csv files. In some of the .csv's, the wave names are simply numbers (ie "1", "2", etc), representing information I need to keep (the waves represent concentrations of species with that number of carbon atoms).

However, because LoadWave automatically uses standard (not liberal) naming, I haven't been able to find a way to load the waves in with numeric names, and they are replaced with "wave0, "wave1", etc. due to my use of the /A flag.

I am trying to use LoadWave as follows:

LoadWave/O/J/W/A/Q/L={0, 1, 0, 0, 0} path_to_csv
  • /O to overwrite previous files
  • /J to indicate that the files are in delimited text format
  • /W/A to indicate that the wave names should be taken from the file without displaying a dialog to the user
  • /Q to suppress error messages in the console
  • /L={0, 1, 0, 0,} to indicate that the wave names should be taken from the first row (0), data should start from the second row (1), and use all rows (0) and start from the first column (0), and use all columns (0).

Is there a way to force Igor to use liberal names somehow when loading these waves? All other waves in my .csv's load properly, it's just about 5-10% of them that have numeric names.

Thanks in advance for your time!

The short answer is that LoadWave will not easily do what you want.

When you use /W, LoadWave looks for a line containing column names. If it does not find such a line, it ignores /W and uses default names. During this process, it sees numbers as numeric data, not as names. So it won't do what you want.

The only workaround would be to use the /B flag to specify the column names explicitly. If you don't know them a priori, then you would have to use Open/R + FReadLine + Close to read the name line and extract the names programmatically.

Here is an example of calling FReadLine and LoadWave on the same file.

After calling FReadLine on your name line, you would parse it into a semicolon-separated list of wave names.

You would then have to construct a parameter for the LoadWave /B flag.

Altogether it would look something like this:

Function Demo()
   
    // Call Open, FReadLine and create list of names, Close
    String listOfNames = <semicolon-separated list> // e.g., "1;2;3;"
   
    String columnInfoStr = ""
    int numNames = ItemsInList(listOfNames)
    int i
    for(i=0; i<numNames; i+=1)
        String name = StringFromList(i, listOfNames)
       // Uses single quotes to support liberal names
        columnInfoStr += "N='" + name + "';"
    endfor

    LoadWave/J/B=columnInfoStr ...

End

 

 

 

Look at the /B flag documentation. It gives you column-by-column control of a lot of properties, including the wave names. It's complex to read about, but ultimately not too bad to work with in a user-defined function.

if the case that you're trying to deal with is one where all the names are numeric, an alternative strategy could be to let loadwave do what it wants, and, if it doesn't take wave names from the first row, rename the loaded waves based on their first data point, then delete those points.

Thanks @hrodstein! I was wondering if it was possible in an ultra-simple way with LoadWave but I expected I might have to implement a workaround with the /B flag like you suggested. I did implement it today and it works just fine! I am hoping it won't be super slow if I have future use cases with many files, but this is seems to work quite well for now.

Thanks as well to John and Tony for your suggestions!