Novice programming syntax help please (unknown/inappropriate Name or symbol)

Hi again,

Can anyone help me with something that must be pretty simple but it's giving me a headache. I'm guess it's just a syntax error.

In my code I've got a wave with temperatures and another couple of huge "reference" waves, one with temperature and one with a value that corresponds to each temperature.

The value is the "error" associated with that temperature reading.

I just want to compare each temperature in the small wave with all the temperatures in the huge wave then get the corresponding error value for that temperature, then add it to a smaller wave.

So far I've got this little nested loop thing.

Wavestats TCerror          //V_npnts = num pts in TCerror wave
npts_TCerror = V_npnts

Wavestats AbsTemp          //V_npnts = num pts in AbsTemp wave
npts_AbsTemp = V_npnts

for (i = 0; i < npts_TCerror; i+=1)

    for (j = 0; j < npts_AbsTemp; j+=1)

        if (Temp[i] == AbsTemp[j])
            deltatwt[i] = SigmaDT[j]
        endif
    endfor

endfor


Well, the compiler absolutely does not like anything I put here:

if (Temp[i] == //XXXX//)

What am I doing wrong? I've done these if statements before.
You need to tell Igor that Temp is a wave and where it is. For details execute:
DisplayHelpTopic "Accessing Global Variables And Waves"

For what you are trying to accomplish, use the Interp() function instead of an if statement. This will also eliminate one of your for loops.
hrodstein wrote:
You need to tell Igor that Temp is a wave and where it is. For details execute:
DisplayHelpTopic "Accessing Global Variables And Waves"



I do. That's just a snippet.

No matter WHAT I put there, I get an error.

I'll keep trying.

edit:

Ok, it was fine with Temp for some reason, but not fine with the other thing there. Earlier I Make those waves and then directly after use them in this if statement. I guess I need to make them or load them, then make wave variables for them to use them?
proland wrote:
For what you are trying to accomplish, use the Interp() function instead of an if statement. This will also eliminate one of your for loops.


Can the interp() function do cubic spline instead of linear with a flag?
phonon wrote:
No matter WHAT I put there, I get an error.


If you will post a complete function that we can try to compile then we will be able to diagnose what the problem is.

If necessary create a simplified version of your actual function that shows the error.

phonon wrote:

Can the interp() function do cubic spline instead of linear with a flag?


Not to my knowledge, take a look at the interpolate XOP

displayhelptopic "interpolate xop"


EDIT: Apparently Interpolate2 with the /t=2 flag (default) does cubic splines.
hrodstein wrote:
phonon wrote:
No matter WHAT I put there, I get an error.


If you will post a complete function that we can try to compile then we will be able to diagnose what the problem is.

If necessary create a simplified version of your actual function that shows the error.


I just edited the earlier post. I think it's just the fact that I thought that if you make a wave or load a wave in a procedure then you can just use it without making a variable.

Incomplete code below:

Function FitAllSets ()  

    String listoftempwaves = WaveList("KRDGC*", ";", "")
    String listofdtwaves = Wavelist("Delta*",";","")
    String listofhtrpwrwaves = Wavelist ("PWR*",";","")
    String listofampswaves = Wavelist ("Amps*",";","")
    String listofvoltswaves = Wavelist ("Volts*",";","")
   
    Variable i
    Variable j
    Variable nsets = ItemsInList(listoftempwaves)
    Variable pwr
    Variable tcon
    Variable tcerr
   
    Make/N=(nsets) Temp,TempSD,TCon,TCerr
   
    Variable refNum
       
    Open /R /MULT=0  /M="Select the Weight (StDev) File" refNum
    LoadWave/A/D/H/J/O/W/K=1/L={0,1,0,0,0} S_fileName                          //This will load waves AbsTemp and SigmaDT
    Wave deltawt   
    Wavestats SigmaDT
    Variable npts_SigmaDT = V_npnts
   
    for (i = 0; i < nsets; i += 1)
   
        Wave tempwave = $StringFromList(i, listoftempwaves)
        Wave deltawave = $StringFromList(i, listofdtwaves)
        Wave pwrwave = $StringFromList(i, listofhtrpwrwaves)
        Wave ampswave = $StringFromList(i, listofampswaves)
        Wave voltswave = $StringFromList(i, listofvoltswaves)
       
        Wavestats tempwave
        Temp[i] = V_avg
        TempSD[i] = V_sdev     
       
        for (j = 0; j < npts_SigmaDT; j+=1)
            if (Temp[i] == AbsTemp[j])
            deltatwt[i] = SigmaDT[j]
            endif
        endfor
           
        Wavestats ampswave
               
        for (j = 0;j < V_npnts; j+= 1)
           
            Wave ampserr
            Wave voltserr
            Wave pwrwt
               
            htrpwr = ampswave[j]*voltswave[j]
            ampserr[j] = ampswave[j]*6.6e-4+20e-6
            voltserr[j] = voltswave[j]*1.5e-4+1.5e-3
            htrpwrwt[j] = (sqrt((AmpsErr[j]/ampswave[j])^2+(VoltsErr[j]/voltswave[j])^2))*pwr
           
           
           
        endfor
       
       
        Curvefit/ODR=2 line pwrwave/X=deltatwave /I=1 /W=deltatwt /XW=pwrwt
       
    endfor
   
End
proland wrote:
phonon wrote:

Can the interp() function do cubic spline instead of linear with a flag?


Not to my knowledge, take a look at the interpolate XOP

displayhelptopic "interpolate xop"


EDIT: Apparently Interpolate2 with the /t=2 flag (default) does cubic splines.


Cool. This just might save me lots of time. I would still have to load waves from a file though, either a pre-interpolated one or one that will be interpolated every time the function runs.
You make the waves Temp,TempSD,TCon,TCerr but the function still needs to be told that you intend to do something with them. This is done using wave references.

wave Temp
wave TempSD
wave TCon
wave TCerr
First remove this - it conflicts with your Make statement:
Variable tcon
Variable tcerr


Next add this after the LoadWave statement:
Wave AbsTemp, SigmaDT


Next the wave name here does not agree with the Wave statement above:
deltatwt[i] = SigmaDT[j]


Then you've got some inconsistencies between wave declarations and wave assignment statements in the for loop.

Quote:
I think it's just the fact that I thought that if you make a wave or load a wave in a procedure then you can just use it without making a variable.


In some cases Igor automatically creates wave references but not after LoadWave. Carefully read the following:
DisplayHelpTopic "Wave References"

including the following subtopic "Automatic Creation of Wave References"


hrodstein wrote:
First remove this - it conflicts with your Make statement:
Variable tcon
Variable tcerr


Oh right. I think those were leftovers.

Quote:
Next add this after the LoadWave statement:
Wave AbsTemp, SigmaDT


Oh good, you can do a list like this. That'll save some space.

Quote:
In some cases Igor automatically creates wave references but not after LoadWave. Carefully read the following:
DisplayHelpTopic "Wave References"

including the following subtopic "Automatic Creation of Wave References"


Thanks a lot.

Now I get the way wave references work.

Sorry for being so clueless.