Looping folders to extract elements of waves?

Hi all,

I am relatively new to Igor programming, and I am trying to do the following:

I have the data structure as following:
root:data:traces:Par1
root:data:traces:Par2
root:data:traces:Par3
...
root:data:traces:ParN

Par1 to ParN are waves. and I hope to write a script that extract the elements for all Par, one element at a time. What is the right language to loop data folder? Greatly appreciated if you can help out. My current code is as attached. Thanks.

Thanks,
William
IntensitySum.ipf (1.15 KB)
Hi John,

Thanks for your reply. However, I am still confused about getting the elements of data in a loop.
Say my data is in root:data:Par1:raw and root:data:Par2:raw, raw are waves with 3 elements.
Since I want to loop both the Par# and then elements within the raw of that Par#, I try something like this:

NVAR temp=root:data:Par+num2str(i)+:raw(j) // where i and j are the for loop variables, i for Par# looping, and j for raw element looping
--> basically, I want to extract the element from root:data:Par"i":raw(j)

But this doesn't work, and I wonder how to do this correctly. Thanks again.

William

johnweeks wrote:
You need either GetIndexedObjName() or GetIndexedObjNameDFR().

John Weeks
WaveMetrics, Inc.
support@wavemetrics.com

I would do it like this:
Function Demo()
    // Create sample data for demo purposes
    NewDataFolder/O root:Par0
    Variable/G root:Par0:raw0 = 1000
    Variable/G root:Par0:raw1 = 2000
    NewDataFolder/O root:Par1
    Variable/G root:Par1:raw0 = 3000
    Variable/G root:Par1:raw1 = 4000

    // Access the sample data
    DFREF baseDFR = root:                   // Reference to base data folder
    Variable i
    for(i=0; i<=1; i+=1)
        String thisDF
        sprintf thisDF, "Par%d", i
        DFREF dfr = baseDFR:$(thisDF)       // Reference to varying data folder
        Variable j
        for(j=0; j<=1; j+=1)
            String thisVar
            sprintf thisVar, "Raw%d", j
            NVAR var = dfr:$(thisVar)       // Reference to global numeric variable
            Print thisDF, thisVar, var
        endfor
    endfor
End

Thanks a lot :D

hrodstein wrote:
I would do it like this:
Function Demo()
    // Create sample data for demo purposes
    NewDataFolder/O root:Par0
    Variable/G root:Par0:raw0 = 1000
    Variable/G root:Par0:raw1 = 2000
    NewDataFolder/O root:Par1
    Variable/G root:Par1:raw0 = 3000
    Variable/G root:Par1:raw1 = 4000

    // Access the sample data
    DFREF baseDFR = root:                   // Reference to base data folder
    Variable i
    for(i=0; i<=1; i+=1)
        String thisDF
        sprintf thisDF, "Par%d", i
        DFREF dfr = baseDFR:$(thisDF)       // Reference to varying data folder
        Variable j
        for(j=0; j<=1; j+=1)
            String thisVar
            sprintf thisVar, "Raw%d", j
            NVAR var = dfr:$(thisVar)       // Reference to global numeric variable
            Print thisDF, thisVar, var
        endfor
    endfor
End