IR Spectrums integration

Hi all,

I'm learning how to program in Igor Pro because my major professor asked me for a macro. Which has to be capable of integrating some IR spectrums at a time, plus it has to be able to narrow the range in which I want to run such integration. The idea is, to identify the products of a catalytic reaction in function of the time, the problem is that 2 of the principal products absorb at almost the same wavelength what makes difficult the characterization. Well, I thought that a slight modification of the integrating macro would work, but it seems that something is missing. Somebody with more expertise, please!


Macro IntSpect(name1,name2,name3,name4,start_INT,stop_INT)

STRING name1,name2,name3,name4,name1_IntSpect,name2_IntSpect,name3_IntSpect,name4_IntSpect
VARIABLE start_INT=400,stop_INT=4000
PROMPT start_INT, "What is the integration to start at?"
PROMPT stop_INT, "What is the integration to stop at?"
Prompt name1,"What is name of wave to convert?", popup, WaveList("*",";","")
Prompt name2,"What is name of wave to convert?", popup, WaveList("*",";","")
Prompt name3,"What is name of wave to convert?", popup, WaveList("*",";","")
Prompt name4,"What is name of wave to convert?", popup, WaveList("*",";","")

name1_IntSpect = name1 + "_IntSpect"
name2_IntSpect = name2 + "_IntSpect"
name3_IntSpect = name3 + "_IntSpect"
name4_IntSpect = name4 + "_IntSpect"

wavestats/R=(stop_INT,start_INT)$name1
wavestats/R=(stop_INT,start_INT)$name2
wavestats/R=(stop_INT,start_INT)$name3
wavestats/R=(stop_INT,start_INT)$name4

Integrate $name1/D=$name1_IntSpect
Integrate $name2/D=$name2_IntSpect
Integrate $name3/D=$name3_IntSpect
Integrate $name4/D=$name4_IntSpect


//Display $N_name
//SetAxis/A/R bottom
//Label left "area under de curve";DelayUpdate
//Label bottom "Wavelength"

Endmacro

IntSpect.ipf
Quote:

but it seems that something is missing.

And what is the problem? You can eliminate the output into the history from the WaveStats operation by adding the /Q flag.

I did this:
make/n=5000 junk1,junk2,junk3,junk4
•junk1=gnoise(1)
•junk2=gnoise(1)
•junk3=gnoise(1)
•junk4=gnoise(1)

And the result was lots of garbage in the history and four integrated waves.

John Weeks
WaveMetrics, Inc.
support@wavemetrics.com
Thanks John for your help, the macro pop-up the Error parameter not declared:


parameter not declared

Error in IntSpect:ipf:IntSpect

Macro IntSpect(name1,name2,name3,name4,start_INT,stop_INT)


Interesting. I tried it in Igor 7 and it worked. I realize now that the order of declaration of your variables isn't quite right- you declare name1_IntSpect,name2_IntSpect,name3_IntSpect,name4_IntSpect before you finish the declarations of the input parameters. You should change it by re-ordering:
Macro IntSpect(name1,name2,name3,name4,start_INT,stop_INT)
STRING name1
Prompt name1,"What is name of wave to convert?", popup, WaveList("*",";","")
STRING name2
Prompt name2,"What is name of wave to convert?", popup, WaveList("*",";","")
STRING name3
Prompt name3,"What is name of wave to convert?", popup, WaveList("*",";","")
STRING name4
Prompt name4,"What is name of wave to convert?", popup, WaveList("*",";","")
VARIABLE start_INT=400
PROMPT start_INT, "What is the integration to start at?"
Variable stop_INT=4000
PROMPT stop_INT, "What is the integration to stop at?"

STRING name1_IntSpect,name2_IntSpect,name3_IntSpect,name4_IntSpect

Really you should be writing functions. Here is a function implementation:
Menu "Macros"
    "Integrate Spectra", mIntSpec()
end

Function mIntSpec()

    STRING name1,name2,name3,name4
    VARIABLE start_INT=400,stop_INT=4000
    PROMPT start_INT, "What is the integration to start at?"
    PROMPT stop_INT, "What is the integration to stop at?"
    Prompt name1,"What is name of wave to convert?", popup, WaveList("*",";","")
    Prompt name2,"What is name of wave to convert?", popup, WaveList("*",";","")
    Prompt name3,"What is name of wave to convert?", popup, WaveList("*",";","")
    Prompt name4,"What is name of wave to convert?", popup, WaveList("*",";","")
    DoPrompt "IntSpect", name1,name2,name3,name4,start_INT,stop_INT
    if (V_flag == 0)
        fIntSpect($name1,$name2,$name3,$name4,start_INT,stop_INT)
    endif
end

Function fIntSpect(w1,w2,w3,w4,start_INT,stop_INT)
    WAVE w1,w2,w3,w4
    VARIABLE start_INT,stop_INT
   
    STRING name1_IntSpect,name2_IntSpect,name3_IntSpect,name4_IntSpect

    wavestats/R=(stop_INT,start_INT) w1
    wavestats/R=(stop_INT,start_INT) w2
    wavestats/R=(stop_INT,start_INT) w3
    wavestats/R=(stop_INT,start_INT) w4

    name1_IntSpect = NameOfWave(w1) + "_IntSpect"
    name2_IntSpect = NameOfWave(w2) + "_IntSpect"
    name3_IntSpect = NameOfWave(w3) + "_IntSpect"
    name4_IntSpect = NameOfWave(w4) + "_IntSpect"

    Integrate w1/D=$name1_IntSpect
    Integrate w2/D=$name2_IntSpect
    Integrate w3/D=$name3_IntSpect
    Integrate w4/D=$name4_IntSpect
end

One advantage of doing it this way is the separation between the GUI (menu "Macros" and mIntSpect()) and the actual computations (fIntSpect). It is almost sure that you will some day want to use the computation part in a different way, and this way it is ready to go. The separation also aids in debugging and in readability. Writing Igor functions gives you access to our most recent enhancements to the language, and it runs much faster. Functions are easier to write correctly because the compiler gives you immediate feedback on the correctness of the syntax for every line, whereas with a macro you have to actually execute it to get the syntax checked.

John Weeks
WaveMetrics, Inc.
support@wavemetrics.com
Thank you so much for your help, John Weeks! Everything works perfectly using functions, however, the idea to use the start and the stop integration is to delimit a particular area in the X-axis, and when I do the graph of the resultant integration, I still have the complete range of values in X. I will try using the setscale command. Thanks again!