Package a table with an ipf? and lookup tables in general

2 questions that are semi-related...

 

1) I have a table of values that I would like to load automatically with a procedure file.  I know that I could either make a template file for experiments (not ideal because there is a library of old .exp files I want to apply this to) or I could more simply include a function that looks for the file I want to load and then call that function.  I guess my questions are:

a) if I write a function to load my table, is there a way to make it call upon compiling? I know you can do some things with the "#" statements below the #pragma but I have not been able to get this to work...and

b) is there a better way to auto-load waves with an ipf compiling that I am missing?

 

 

2) Other than BinarySearch and BinarySearchInterp, is there an ideal way to search through a multi-dimensional lookup table? I.e. I have a 3-dimensional matrix with 3 1-d waves of header values that I need to look through.  I have some code that calculates Maxwell's equations but I run it over and over and it takes waaaayyyy too long to run. Moving to a lookup table would save me a lot of computational time but I'm wondering if there is an even faster way of looking for specific values I don't know about.

As far as calling functions after compilation, see the user-defined hook function AfterCompiledHook (displayhelptopic "AfterCompiledHook")

for question 2: unless your header values change in a non-linear fashion (and cannot be linearized, for example by switching to log(value)), you should set the wave scaling for each dimension of the matrix /multi-dimensional wave. Then you look up a value as MatrixWave(x)(y)(z) instead of MatrixWave[p][q][r].

And for question 1, you could consider supplying the lookup table as an Igor binary wave file. The user can either load the file with a double click, or your code can attempt to locate and load the file as part of an initialization routine. Maybe fall back to some user-interaction if the wave isn't loaded and the file cannot be found.

1) If values are static and there are not many of them (you decide how many are not many) you could define a wave to hold them in your procedure file.  

2) It's not clear to me what you mean by "looking for specific values I don't know about."  How do you know when you've found the right value?   If you do go to a lookup table, dimension labels (SetDimLabel, FindDimLabel & GetDimLabel, for example) might be helpful. 

In reply to by jtigor

jtigor wrote:

1) If values are static and not there are not many of them (you decide how many are not many) you could define a wave to hold them in your procedure file. 

tip: if your matrix wave (w) is a reasonable size, you can execute

print w

on the command line to generate the code needed to fill in the values.

In reply to by tony

tony wrote:

tip: if your matrix wave (w) is a reasonable size, you can execute

print w

on the command line to generate the code needed to fill in the values.

@tony

Nice.  I'll try to remember that.  Too many times I did this the hard way.

If your table is large and you need to load it from a data file, you can use the FunctionPath function to find the location of the procedure file and then load the data file from that location.

If your table is small you should represent it in the function itself, e.g.,

Function/WAVE GetMyTableWave()
    WAVE/Z w = root:MyTableWave
    if (WaveExists(w))
        return w
    endif
   
    Make/D/N=(3,2) root:MyTableWave
    WAVE w = root:MyTableWave
    w[0][0]= {0,1,2}
    w[0][1]= {10,11,12}
    return w
End

 

Take a look also at the SavePackagePreferences and LoadPackagePreferences operations.