![](/profiles/wavemetrics/themes/wavemetrics/logo.png)
Simple syntax error in function declaration
![](/sites/default/files/styles/thumbnail/public/default_images/Artboard%201_1.png?itok=jeHOCIXy)
Glory
Hi!
I am writing a simple function which find 3 1-D waves in current folder and take log transformation and save to another wave with log_* in the begining. When it is been compiled it has error that I cannot reference a wave like that [Can't use $ in this way in a function]. It looks like a simple syntax errror. Can some expert correct it or give me an alternative way to achieve this goal? Thanks!
Function GM1D_Log_qrs() NVAR currentWave, currentWaveType, currentWaveDim NVAR i,dim_q DFREF dfr = GetDataFolderDFR() Variable numWave = CountObjectsDFR(dfr, 1) SVAR list,wave_name_q, wave_name_r,wave_name_s SVAR wave_name SVAR name_here name_here = getdatafolder(0) // Get the list of waves in the current folder list = WaveList("*", ";", "DIMS:1") // Get the specific qrs waves in the current folder wave_name_q = WaveList("q_*", ";", "DIMS:1") wave_name_r = WaveList("r_*", ";", "DIMS:1") wave_name_s = WaveList("s_*", ";", "DIMS:1") dim_q=numpnts($wave_name_q) // Iterate through the waves and create new waves based on those starting with "q_" for (i=0; i<numWave; i+=1) wave_name = StringFromList(i,list) if ( (stringmatch(wave_name, "q_*") == 1) || (stringmatch(wave_name, "r_*") == 1)) // Create a new wave with the same data as the existing wave string newWave = "log_" + wave_name make /O/R $newWave = log($wave_name) // this is where the error begin when it compile. Can't use $ in this way in a function??? endif if ( (stringmatch(wave_name, "s_*") == 1) ) string newWave = "log_" + wave_name make /O/R/N=dim_q $newWave = ($wave_name)/($wave_name_q) endfor End
you need something like
wave foo = $wave_name
to create a wave reference for the named wave
August 18, 2023 at 08:11 am - Permalink
This compiles and I think it does what you want.
I also changed the NVAR and SVAR statements to Variable and String, since I don't think you actually want to use globals for those variables.
August 18, 2023 at 08:13 am - Permalink
In reply to This compiles and I think it… by aclight
August 18, 2023 at 02:58 pm - Permalink
In reply to This compiles and I think it… by aclight
Thank you for your correction. I tried this code and compily works well. But it cannot work properly. As screenshot shown, Wave existing_wave_q is null. I have no clue how to fix this issue. So what others I can do?
error message:
While executing WAVE, the following error occurred: WAVE reference to "existing_wave_q" failed.
August 18, 2023 at 02:59 pm - Permalink
WaveList returns a semicolon-delimited list of waves. In your screenshot example, it has found one wave, q_1_C.
Use StringFromList to extract a string from a list.
For your code to work reliably you must ensure that the required wave is the first wave that Wavelist finds.
August 19, 2023 at 06:50 am - Permalink
Giory, I may be wrong, but I suspect that since you are using "qrs" naming system and are trying to take log of q and r waves, you are doing small angle scattering and may be either using my Nika or Irena packages. May be there are other packages in Igor which also generate qrs, in which case I'd love to know which (NIST code used "qis"). This naming system is old, very old, and really cumbersome and complicated to use.
In case you are using Irena, contact me directly (there is link in SAS menu to send me email) and I can help you to use either some of Irena tools directly or help you reuse some of the internal Irena functions. There is quite large and complicated package in Irena which supports data selection and would make your coding simpler - at cost of loading always Irena, though.
August 19, 2023 at 09:08 pm - Permalink