NewDirectory issue

Hi forum,

My question contains 2 parts,

In my procedure, I am extracting data from waveP1x0 and waveP2x0 and doing some wave analysis. At one stage I need to move waves from folder "rec1" to "tests" such that for each pair (such as NearbyR0x and Nearby R0y) i want to create a folder that contains each point. When I run my code all the previous folders are also created in destination folder "tests" (the one that are highlighted in yellow), and the name strings "NearbyR"+num2str(b)+"x(or y)" are not moved the each corresponding folder.  I also get this error (while executing MoveWave, the following error occurred: expected wave name).

 

Here is the last piece of my code

string recon = "recon"+num2str(b)+"rxy"
            string recon_col0 = "R"+num2str(b)+"recon"
                string recon_col1 = "NearbyR"+num2str(b)+"x"
                string recon_col2 = "NearbyR"+num2str(b)+"y"    //these create each waves


wave    rec0=$recon_col0, rec1=$recon_col1, rec2=$recon_col2
                      rec0=beson[p][0]
                          rec1=beson[p][1] 
                                                           
                rec2=beson[p][2]   



NewDataFolder /o IndividualPoints
            duplicate $wnamex, root:tryFolders:IndividualPoints:$wnamex
            duplicate $wnamey, root:tryFolders:IndividualPoints:$wnamey
               
            NewDataFolder /o R_waves
            NewDataFolder /o R_xy_to_all_other 
            duplicate $Ar, root:tryFolders:R_waves:$Ar
            duplicate $rPx, root:tryFolders:R_xy_to_all_other:$rPx
            duplicate $rPy, root:tryFolders:R_xy_to_all_other:$rPy 
               
            NewDataFolder /o Concatinated  
            duplicate $bol, root:tryFolders:Concatinated:$bol
           
            NewDataFolder /o Sorted_R_waves_between7and12
                duplicate $dataR, root:tryFolders:Sorted_R_waves_between7and12:$dataR

            NewDataFolder /o rec0
                NewDataFolder /o rec1
                NewDataFolder /o rec2
                duplicate $recon_col0, root:tryFolders:rec0:$recon_col0
                duplicate $recon_col1, root:tryFolders:rec1:$recon_col1
                duplicate $recon_col2, root:tryFolders:rec1:$recon_col2         //moved all in one folder
               
               
               
                killwaves /A/Z                         //to kill all other waves in "tryFolders" folder
               
               
                newdatafolder /o root:tryFolders:rec1:tests
                SetDataFolder root:tryFolders:rec1:tests
               
               
               
                string WaveNear = "NearbyR"+num2str(b)+"xy"                  //set string variable name for folders b is defined from 0 to 54
               
                    NewDataFolder root:tryFolders:rec1:tests:$WaveNear
                    MoveWave $recon_col1, root:tryFolders:rec1:tests:$WaveNear
                    MoveWave $recon_col2, root:tryFolders:rec1:tests:$WaveNear


// Part 2:ATTEMPT TO: Use for loop for $WaveNear folders (this part has not been tested yet)

SetDataFolder root:tryFolders:rec1:tests:$WaveNear       //not sure about $ , I here trying to start my loop within each folder

For (c=0; c < numpnts($WaveNear); c+=1)
           
             string wNx = "p"+num2str(b)+"x"
             duplicate/o $WaveNear, $wNameX
             wave wvNxx =$wNx
             wvNxx= $WaveNear[b]             
           
             string wNy = "p"+num2str(b)+"y"
             duplicate/o wwNyy, $wNy
             wave wvNyy =$wNy
             wvNxx= $WaveNear[b]

          //here to do some operation*****

Endfor

Second Part:

I once have each wave in corresponding folder, I then want to do a For loop for each folder (string WaveNear = "NearbyR"+num2str(b)+"xy" ) and do some analysis on each wave in different folder. Since I already have a for loop, can I use another for loop with "c" being a variable for number of wave points in each folder "WaveNear"? I tried to run a for loop within a for loop , it either gave me error took very long time to load and igor crashed.

thanks for your Help

what is outputed

A few thoughts are immediately apparent to me to troubleshoot and/or improve your processing on Step 1:

  • Assure yourself that you are always in the same starting folder each time you enter a function by using a GetDataFolder + SetDataFolder combination at the outset of any code that hops + skips + jumps + weaves itself around in data folders
  • Consider learning about and using DFREF options to lower the possibility of long data paths and the commensurate typos and/or need to hop/skip/jump/weave physically around in data folders.
  • Remember that NewDataFolder/O only creates the data folder, it does not "go" there.
  • When you need to make/duplicate bunches of waves in different locations through repetitive processing, consider making all the waves systematically in a TMP folder at the root level and then MOVING that data folder entirely to the desired location rather than constantly moving into different folders and then duplicating waves in that folder to locations in some other folder that is dynamically generated (many times over) and also is three times or more removed back up and across the directly path tree.

In reply to by jjweimer

Having gone through your comments, I figured how to move the waves to corresponding folders here:

 

newdatafolder /o root:tryFolders:rec1:tests
                DFREF tests = GetDataFolderDFR()
               
                string WaveNear = "NearbyR"+num2str(b)+"xy"
               
                    SetDataFolder tests
               
                NewDataFolder root:tryFolders:rec1:tests:$WaveNear
               
            MoveWave  root:tryFolders:rec1:$recon_col1, root:tryFolders:rec1:tests:$(WaveNear):    // when moving waves to different folders USE : : and Parentheses () instead of just $WaveNear
            MoveWave  root:tryFolders:rec1:$recon_col2, root:tryFolders:rec1:tests:$(WaveNear)

Now I am working to figure out the second part

Thanks,

Is this what you are trying to accomplish?

    string WaveNear1, WaveNear2

    DFREF cdf = GetDataFolderDFR()

    SetDataFolder root:tryFolders:rec1
    wave rc1 = $recon_col1
    wave rc2 = $recon_col2

    NewDataFolder/O tests // generate new folder

    sprintf WaveNear1, "NearbyR%dxy1", b
    sprintf WaveNear2, "NearbyR%dxy2", b
   
    MoveWave rc1, :tests:$(WaveNear1)
    MoveWave rc2, :tests:$(WaveNear2)

 

In reply to by jjweimer

I was able to solve Part 1 of my question, which is moving waves from folder "tests" to each corresponding folder (WaveNear). So no issue about that.

Now that I have 2 waves in each folder; Part 2 of my question is, that I am trying to do a loop for each data folder:

I am using Do/While to go over the number of corresponding folders in main folder "tests", and I use a For Loop for waves in each corresponding folders,

My code does work but only for last folder, "NearbyR54xy". Other folders (such as NearbyR54xy) are empty and have and have no points. (as seen in image attached)

Here is the snippet

 

string recon_col1 = "NearbyR"+num2str(b)+"x"
string recon_col2 = "NearbyR"+num2str(b)+"y"


Variable numDataFolders = CountObjectsDFR(tests, 4)
variable e
           
               
    do
                   
        DFREF tests = GetDataFolderDFR()
     
                   
        SetDataFolder root:tryFolders:rec1:tests:$WaveNear
                   
        numDataFolders = CountObjectsDFR(tests, 4)
       
           For (e=0; e < numpnts($recon_col1); e+=1)
           
           
            wave RC1=$recon_col1
            wave RC2=$recon_col2   
           
             string wNameX1 = "p"+num2str(e)+"x"
             duplicate/o $recon_col1, $wNameX1
             wave waveNx1 =$wnamex1
              WAVENx1= RC1[e]            
             string wNameY1 = "p"+num2str(e)+"y"
             duplicate/o $recon_col2, $wNameY1
                 wave waveNy1 =$wnamey1
             WAVENy1= RC2[e]  
           
           
                               
            string rPx1 = "rr"+num2str(e)+"xToAll"
        string rPy1 = "rr"+num2str(e)+"yToAll"
            string Ar1 = "RR"+num2str(e)
                duplicate/o recon_col1, $rPx1, $rPy1, $Ar1
        wave rPxWave1=$rPx1, rPyWave1=$rPy1, Rwaves1=$Ar1
 
           
            rPxWave1=(RC1-WAVENx1)^2       
            rPyWave1=(RC2-WAVENy1)^2   
            Rwaves1 = sqrt(rPyWave1+rPxWave1)
            EndFor
                               
                               
      While ( numDataFolders < CountObjectsDFR(tests,4) )

Also as you see in code rPxWave1, rPxWave2 and Rwaves1 supposed to give waves with names rr..xToAll, rr..yToAll and RR respectively. I don't know why those waves are not created

 

forloop_folders.png (14.04 KB)

Where do you update $WaveNear in the do-while loop? Otherwise, the loop stays in one data folder.

You probably should avoid "e" as a counter in a loop.

I must admit that the approach being taken remains too convoluted with naming and duplicating processes for me to follow it easily.

Also, I have to think that some of the processing may be better handled by implicit loops over wave points.

I don't know at this point what else to suggest.