Duplicate waves using Prompt
Hi all,
I'm trying to implement duplication of waves using while-loop and prompt (interacting with the user). Please find attached IgorPro experiment file. There are 2 functions in the procedure - for creation and for duplication of waves. I have 2 questions:
1) For example, I'd like to duplicate 5 waves (Wave0, Wave1, ..., Wave4) to Wave0d, Wave1d, ..., Wave4d. To implement it, I should 5 times type source wave and duplicate wave names in the prompt, and then click "Cancel". But I see the result of running this function only after clicking "Cancel", i.e. duplicate waves do not immediately appear in Data Browser after clicking "Continue". Is it possible to make function show each duplicate wave immediately after clicking "Continue"?
2) In function duplicate_waves(), I didn't declare wave. According to manual: "WAVE is a declaration that tells Igor the nature of a user-defined function parameter or creates a local reference to a wave accessed in the body of a user-defined function." Could you please tell, why the function works without wave declaration?
Here are functions:
Variable number
String s
Variable n, i, j
for (n=0; n<number; n+=1)
s = "Wave"+num2str(n)
make/O/D/N=(10,10) $s
Wave wave_ = $s
print "wave name = ", s
for(i=0; i<DimSize(wave_, 0); i+=1)
for(j=0; j<DimSize(wave_, 1); j+=1)
print "i = ", i, "; j = ", j
wave_[i][j] = abs(enoise(10))
printf "%s[%d][%d] = %g\r", s, i, j, wave_[i][j]
print "-------------------"
endfor
endfor
endfor
End
macro Create2DData()
create_2D_data(5)
end
Function duplicate_waves()
do
String source_wave_name="Wave", duplicate_wave_name="Wave"
Prompt source_wave_name, "Enter source wave name: "
Prompt duplicate_wave_name, "Enter duplicate wave name: "
DoPrompt "", source_wave_name, duplicate_wave_name
if (V_Flag)
return -1 // User canceled
endif
duplicate $source_wave_name, $duplicate_wave_name
while(1)
End
macro DuplicateWaves()
duplicate_waves()
end
Forum
Support
Gallery
Igor Pro 9
Learn More
Igor XOP Toolkit
Learn More
Igor NIDAQ Tools MX
Learn More
Hi,
It looks like when you click 'Continue" V_flag of 0 is set and this would cause you to stay in the Do loop since the only exit is to click cancel which sets V-Flag to 1 and enters the if statement and exits.
When I try your experiment in IP 8.04beta, I get an error when I try to run the duplicate macro specifically asking for wave reference. The error you expected.
What version are you running? There was change introduced in 6.3.
WAVE Reference Is Needed To Pass a Wave By Name
In Igor Pro 6.3 and later, new procedure windows are created with this pragma statement:
#pragma rtGlobals=3 // Use modern global access method and strict wave access.
The strict wave access mode causes a compile error if you pass a literal wave name as a parameter to an operation or function. Instead you must pass a wave reference.
Andy
October 27, 2019 at 09:58 am - Permalink
In reply to Hi, It looks like when you… by hegedus
Thank you for reply!
I'm running IgorPro 8.0.4.1(beta).
October 27, 2019 at 10:20 am - Permalink
Regarding #1, this behavior is intentional. Updating the Data Browser can be slow, if lots of waves were added/removed/changed, so that only happens when Igor is idle, not during function execution.
If you add the following two lines after your Duplicate command, you can get what you want:
CreateBrowser
October 28, 2019 at 05:29 am - Permalink