
Concatenate produces null wave in procedure

Hello Everyone:
This should be simple but has me stumped. Inside a procedure, I create a text wave to hold names of different waves that will be concatenated from subfolders:
// list of waves to be concatenated for this experimenter (or condition). Make/FREE/T dataWaves = {"Re_data", "f_data", "f_calc"} Variable numWaves = numpnts( dataWaves)
Later I check to see if one of these waves exists, if not I then cycle over the subfolders concatenating the contained waves:
Wave f_calc if (!WaveExists(f_calc)) // - we must be at a top level datafolder (eg, Erken) // need to cycle over subfolders & concatenate waves Variable numDFs = CountObjects(":",4) Variable n for (n=0; n<numDFs; n+=1) String expPath = GetIndexedObjName(":",4,n) SetDataFolder expPath for (i=0; i<numWaves; i+=1) String destWavePath = "::" + dataWaves[i] Concatenate/NP {$dataWaves[i]}, $destWavePath endfor SetDataFolder saveDF endfor endif
This works just as I intended. All 3 data waves (f_calc, f_data and Re_data) are present and correctly filled with data from the subfolders. But, when I try to use f_calc, it is null:
Wave f_data Variable f_min = min(WaveMin(f_calc), WaveMin(f_data))
It has something to do with f_calc being referenced before it is created via the concatenate operation. I know that I must be making a simple error but...
NOTE: this was run using Igor 8.04 on Mac OS 11.6.1
Thanks for the help,
Joe Kelly
Let us see all of the code.
I don't see where you are re-assigning WAVE f_calc anywhere.
November 30, 2021 at 12:28 pm - Permalink
Yes. Execute this for details:
DisplayHelpTopic "Put WAVE Declaration After Wave Is Created"
November 30, 2021 at 12:30 pm - Permalink
Thanks for looking at this. The entire function is pasted below. The reason that f_calc is declared before the concatenation is so that I can check for its existence. Sometimes (depending on how experiments are organized in subfolders) the concatenation has already been done.
Thanks again,
Joe
November 30, 2021 at 12:37 pm - Permalink
My quick read says that when f_calc does not exist, it is also never created. If f_calc is created within doCalcs or getData, you might do better to return it explicitly from these functions rather than having it "hidden". Or, since you kill it at the end of this top level function anyway, why not just create it as a FREE wave to start?
November 30, 2021 at 12:50 pm - Permalink
First, if you declare a wave reference to a wave that my not exist, always use WAVE/Z instead of just WAVE. The /Z prevents the debugger from kicking in on a null wave reference. For details on this, execute:
DisplayHelpTopic "Runtime Lookup Failure And The Debugger"
You can solve the problem by adding this after the "endif" part of the "if (!WaveExists(f_calc))" block:
It is OK to redeclare a wave reference.
Here I did not use /Z because the waves are guaranteed to exist.
(Caveat: I don't understand what the Concatenate call is all about.)
November 30, 2021 at 01:03 pm - Permalink
THANKS!
I had forgotten (or never knew) that a wave reference can be redeclared. Although I have used Igor since 1991, I only use it intermittently and so it is always a relearning experience.
Thanks again for a great product and support,
Joe Kelly
PS - Thanks also to J. Weimer for looking at this.
November 30, 2021 at 01:12 pm - Permalink