using original datafile names when loading waves thru LoadWave
vishivishi
Hello all, I am trying to name the waves created thru LoadWave using original names of the datafiles. I thought, I would use global $S_waveNames and $S_fileName in Duplicate to do so but it gives me an error Duplicate error: expected wave name. Any help is appreciated.
Thanks,
Vishi
Function CustomWaveSelect(fileName, pathName)
String pathName // Name of Igor symbolic path or ""
String filePath // Full path, partial path or file name
if (V_Flag)
return -1 // User canceled
endif
// Load the waves and set the local variables.
LoadWave/M/J/D/O/P=$pathName fileName
Duplicate/O $S_waveNames, $S_fileName
if (V_flag==0) // No waves loaded. Perhaps user canceled.
return -1
endif
End
String pathName // Name of Igor symbolic path or ""
String filePath // Full path, partial path or file name
if (V_Flag)
return -1 // User canceled
endif
// Load the waves and set the local variables.
LoadWave/M/J/D/O/P=$pathName fileName
Duplicate/O $S_waveNames, $S_fileName
if (V_flag==0) // No waves loaded. Perhaps user canceled.
return -1
endif
End
Here is how I would do it:
String pathName // Name of Igor symbolic path or ""
String filePath // Full path, partial path or file name
if (strlen(filePath) == 0) // Want Open File dialog?
Open/D/R/P=$pathName refNum as filePath
if (strlen(S_fileName) == 0)
return -1 // User canceled.
endif
filePath = S_fileName // This is a full path.
endif
// Get just the fileName but with the extension remove.
String wName = ParseFilePath(3, filePath, ":", 0, 0)
wName = CleanupName(wName, 0) // Change 0 to 1 if you want to allow liberal names
// Get string to pass to LoadWave /B flag to set wave name
String columnInfo
sprintf columnInfo, "N='%s';", wName
// Load the waves and set the local variables.
LoadWave/M/J/D/O/B=columnInfo/P=$pathName filePath
return V_flag // Number of waves loaded
End
If your data contains just numbers (no NaNs, dates, text data), then I recommend using LoadWave/G instead of LoadWave/D. The reason is that LoadWave/G will find the data in the file, skipping any header information, whereas LoadWave/D needs to be told where (on what line) the data starts. However, if the file contains nothing but numbers, both LoadWave/G and LoadWave/D will work fine.
If you are not familiar with Igor symbolic paths, execute this to read the help:
February 17, 2012 at 10:59 am - Permalink
Great! Thanks so much. I've commentized /if (strlen(filePath) == 0) because I want it to loop thru the number of files the user chooses to plot/analyze and it works. A separate thanks for your bonus tips on how to clean the file name and strip it off the extension. Thanks a lot!
Vishi
Open/D/R/P=$pathName refNum as filePath
if (strlen(S_fileName) == 0)
return -1 // User canceled.
endif
filePath = S_fileName // This is a full path.
// endif
February 17, 2012 at 11:40 am - Permalink