Duplicating a wave, same name, different folder
patarroyo
SetDataFolder $DataFolderName
Duplicate root:wave0, wave0
Duplicate root:wave0, wave0
is what I think should work, but I get an error about trying to duplicate into the same wave, even though my intent is to duplicate root:wave0 to root:DataFolderName:wave0. DataFolderName is distinct from root.
Duplicate/O ...
--
J. J. Weimer
Chemistry / Chemical & Materials Engineering, UAH
November 2, 2016 at 10:19 am - Permalink
wave wave0
) in the procedure prior to using the duplicate command. I still get confused about when and how to properly use Wave to pass an existing wave into a procedure. It appears that I don't need to use Wave at all! Any comment on that? I always seek to better understand the wave command.Your reminder to use
/O
was very helpful. Inevitably, I will forget to actually load the data. I should also mention that since the procedure is in active transition, I intend to label the subfolder "wave0" with something more sensible, like "RawData". And all of this is in a subfolder that contains date and file index (from that particular day, e.g., 20161102_04).November 2, 2016 at 12:09 pm - Permalink
Yes, you didn't post your complete function, but if it was like this:
Wave junk
SetDataFolder RawData
Duplicate root:junk, junk
end
then, yes, it is the WAVE statement that was responsible.
WAVE statements do two different things, one at compile time and one at run time. At compile time, it establishes a name as an alias for a wave that doesn't necessarily exist at the time. The WAVE statement allows Igor to compile wave handling code when it sees that name later in the code.
At run time, when the WAVE statement is encountered, it causes Igor to look up a wave with the specified name and causes that name to be associated with a real wave. In this case, the real wave is the one in the root folder, so the Duplicate command is asked to duplicate root:junk onto the wave previously looked up, which is root:junk. The wave reference doesn't stop pointing to the original wave just because you changed the data folder.
In addition to my explanation above, there are some convenience behaviors that can be confusing.
The basic WAVE statement works like
WAVE localname = root:RawData:globalname
. That establishes "localname" as an alias at run time for "globalname" in a data folder that isn't necessarily the current data folder. But Igor also allows a shortcut:WAVE globalname
. That makes a local alias "globalname" for a wave called "globalname" in the current data folder. The confusing part is that the localname is the same as the real globalname, but in fact, in the function "globalname" is a local alias that happens to have the same name as the actual wave.Another source of confusion is that some commands that create waves can sometimes make a wave reference. In particular, Make and Duplicate (and some others) if you give it a literal name will make a wave reference for you without requiring a WAVE statement. So
Make myWave
will make a wave in the current data folder called "myWave" and it also creates a wave reference with the local alias name "myWave", just as if you had used the shortcutWAVE myWave
.Completely clear now, right? :)
John Weeks
WaveMetrics, Inc.
support@wavemetrics.com
November 3, 2016 at 11:56 am - Permalink
The rules are somewhat complex and depend on the rtGlobals statement in your procedure file.
For the complete story, execute this:
For simplicity, I recommend you follow this rule:
"Simple name" means just a standard (not liberal) wave name (e.g., wave0) with no path (root:wave0 is not a simple name) and with no use of strings or $.
Examples:
// Create sample data using liberal name which are more exacting.
// The single quotes used below are required only for liberal names.
SetDataFolder root:
Make/O root:'A wave' // Spaces, dots and so on make a name liberal
NewDataFolder/O 'Data Folder' // Spaces, dots and so on make a name liberal
Make/O root:'Data Folder':'Another wave'
String stringContainingNameOfWave = "A wave"
String stringContainingNameOfDataFolder = "Data Folder"
String stringContainingNameOfAnotherWave = "Another wave"
// Wave references using a string
WAVE w = $stringContainingNameOfWave // References wave in current data folder
WaveStats/Q w
String path = "root:'Data Folder':'Another wave'"
Wave w = $path // References wave in another data folder
WaveStats/Q w
path = "root:'Data Folder':" + PossiblyQuoteName(stringContainingNameOfAnotherWave)
Wave w = $path // References wave in another data folder
WaveStats/Q w
Wave w = root:$(stringContainingNameOfDataFolder):'Another wave' // References wave in another data folder
WaveStats/Q w
DFREF dfr = $path
Wave w = dfr:$(stringContainingNameOfWave)
WaveStats/Q w
// Wave references using literal names
Wave w = 'A wave' // References wave in current data folder
WaveStats/Q w
Wave w = :'A wave' // References wave in current data folder
WaveStats/Q w
Wave w = root:'Data Folder':'Another wave' // References wave in another data folder
WaveStats/Q w
Wave w = :'Data Folder':'Another wave' // References wave in another data folder
WaveStats/Q w
// Wave references using simple, standard wave names
// Make and Duplicate automatically creates wave references only when
// the destination is a simple wave name (e.g., wave0)
Make/O wave0 // Igor automatically creates a wave reference named wave0
Wave wave0 // This is optional and is usually omitted
WaveStats/Q wave0
Duplicate/O wave0, wave1 // Igor automatically creates a wave reference named wave0
Wave wave1 // This is optional and is usually omitted
WaveStats/Q wave1
KillWaves wave0, wave1
End
November 3, 2016 at 03:04 pm - Permalink