Understanding referencing?
Irvine_audit
I am still more or less new to Igor programming although I have been using Igor for a couple of years already. Here is my probably rather simple problem:
This is my working example code:
#pragma rtGlobals=3 // Use modern global access method and strict wave access.
Function test_analysis()
string prefix, all_test
variable count, i
prefix="test"
all_test = WaveList(prefix+"*", ";", "")
count = ItemsInList(all_test)
for (i = 0; i < count; i+=1)
wave test_p = $StringFromList(i, all_test)
wavestats/Q test_p
endfor
End
Function test_analysis()
string prefix, all_test
variable count, i
prefix="test"
all_test = WaveList(prefix+"*", ";", "")
count = ItemsInList(all_test)
for (i = 0; i < count; i+=1)
wave test_p = $StringFromList(i, all_test)
wavestats/Q test_p
endfor
End
Now, if I put the wave reference of "test_p" before the loop, it is not working anymore with the error message "Can't use "$" like this in a function".
Although that error already occured on multiple occassions in other projects of mine, I do not really know what is causing this in this context here. Here is the example code:
#pragma rtGlobals=3 // Use modern global access method and strict wave access.
Function test_analysis()
string prefix, all_test
variable count, i
wave test_p
prefix="test"
all_test = WaveList(prefix+"*", ";", "")
count = ItemsInList(all_test)
for (i = 0; i < count; i+=1)
test_p = $StringFromList(i, all_test)
wavestats/Q test_p
endfor
End
Function test_analysis()
string prefix, all_test
variable count, i
wave test_p
prefix="test"
all_test = WaveList(prefix+"*", ";", "")
count = ItemsInList(all_test)
for (i = 0; i < count; i+=1)
test_p = $StringFromList(i, all_test)
wavestats/Q test_p
endfor
End
Furthermore, I just really like to know whether there is something like a "style guide" for Igor Programming (like it exists for C++ from google e.g.) because I could not really find related information in the manual and I think it is quite important. It would be just great to have some general "guide lines" for indentation, referencing and so on which would probably also make sharing Igor code easier.
Best regards,
Martin
so first to your problem. If you create a wave reference, you have to always use the
Wave
keyword in front of the wave name. This is different from variables and strings where you can separate definition and assignment.Due to this fact you can also have multiple wave statements with the same name.
Function doStuff()
Make/O data
// Make implicitly creates a wave reference named "data"
data = p
Wave d1 = data
print d1
Make/O data2
Wave d1 = data2
print d1
End
And now if you use
wv = $StringFromList(...)
you are missing the wave keyword infront of wv. No matter if you use$
or a literal string.Regarding the coding guidelines. I'm not aware of any official guidelines either.
I'm trying to follow my own rules:
See also my earlier post here.
If anyone is interested I can also post my gitconfig settings for igor code.
September 5, 2014 at 04:46 am - Permalink
And I would be interested in your configuration, too.
September 5, 2014 at 05:59 am - Permalink
I suspect then that perhaps you mean
Function DoStuff()
:-)--
J. J. Weimer
Chemistry / Chemical & Materials Engineering, UAHuntsville
September 5, 2014 at 08:25 am - Permalink
Yes, I'm glad I wrote trying ;-)
Btw. here are my git settings http://www.igorexchange.com/node/6013.
September 5, 2014 at 08:48 am - Permalink
A WAVE statement has two purposes, one at compile time and one at runtime. At compile time, it tells Igor's compiler that a given name (like test_p) refers to a wave so that the compiler can create wave code instead of, for instance, variable code. At runtime, it causes Igor to actually look up the wave with the given real name (the result of evaluating the string expression StringFromList(i, all_test)) and assigning a pointer to that wave to the wave reference test_p.
Many people with programming experience expect a WAVE statement to be like a C or C++ variable declaration. That is the compile-time part of a WAVE statement's job.
Many people fail to understand the run-time part of the WAVE statement. That is why your WAVE statement must be inside the loop- every time through the loop, it evaluates the string expression, finds the named wave and assigns the pointer to test_p. When you have a variable name that has been identified as a wave reference (via a previous WAVE statement) then any line that assigns to that variable must be a wave assignment statement, not a wave look-up. That is, it must be putting numeric values into the wave elements.
As far as indentation style goes, we have a preferred style that can be seen using the Edit->Adjust Indentation menu item. Select some code, then select that menu item to see what we prefer. As far as use of case, we don't have much of a preference, and everyone at WaveMetrics has their own style :) The Adjust Indentation menu item was a reaction to getting customer code that had NO indentation, and was nearly impossible to read...
John Weeks
WaveMetrics, Inc.
support@wavemetrics.com
September 5, 2014 at 09:28 am - Permalink
September 5, 2014 at 09:33 am - Permalink
September 8, 2014 at 12:51 am - Permalink