Using Loops in Directories

Hello Forum,

I have sorted my calculated waves and added them into 54 folders each called NearbyR_xy and are placed in folder named "tests" (as a result of previous For Loop).  Each NearbyR_xy folder contains two waves NearbyR_x and NearbyR_y. My goal is to do some more calculation on each waves within NearbyR_xy folder. In this piece of snippet I use "while" and "for" loops.

When I execute my code, the operation is done only on last folder NearbyR54xy,  the other folders contain no waves and have duplicates of parent empty folder.

The Error I'm getting is: " While ex

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.

I think it has to do with indexing and path,

Thanks for your help.

 

// I excluded first part of the code
killwaves /A/Z
    //this part moves each waves to corresponding folder   				
   			newdatafolder /o root:tryFolders:rec1:tests
  			DFREF tests = GetDataFolderDFR()
      			
	
     				string WaveNear = "NearbyR"+num2str(b)+"xy" 
                             NewDataFolder root:tryFolders:rec1:tests:$(WaveNear)
     				SetDataFolder root:tryFolders:rec1:tests:$(WaveNear)
    
      			
      				MoveWave  root:tryFolders:rec1:$recon_col1, root:tryFolders:rec1:tests:$(WaveNear):  
      				MoveWave  root:tryFolders:rec1:$recon_col2, root:tryFolders:rec1:tests:$(WaveNear):	


    // This starts while loop operation and for loop within it

 	     		Variable numDataFolders = CountObjectsDFR(tests, 4)
			variable a
	
     			DFREF tests = GetDataFolderDFR()
     			SetDataFolder root:tryFolders:rec1:tests:$(WaveNear):
     				
     	
do 
  
      	For (a=0; a < numpnts($recon_col1); a+=1)

        	wave RC1=$recon_col1
    		wave RC2=$recon_col2	
    		wave waveNx1,waveNy1
        	
        	string wNameX1 = "p"+num2str(a)+"x"
       	 duplicate/o root:tryFolders:rec1:tests:$(WaveNear):$recon_col1, root:tryFolders:rec1:tests:$(WaveNear):$wNameX1
        	 wave  waveNx1 =$wnamex1
        	 WAVENx1= RC1[a]        	 
     		
      		 string wNameY1 = "p"+num2str(a)+"y"
        duplicate/o root:tryFolders:rec1:tests:$(WaveNear):$recon_col2, root:tryFolders:rec1:tests:$(WaveNear):$wNameY1
        	 wave waveNy1 = $wnamey1
        	 WAVENy1= RC1[a]   
      		
        	string rPx1 = "rr"+num2str(a)+"xToAll"
   		string rPy1 = "rr"+num2str(a)+"yToAll"
    		string Ar1 = "RR"+num2str(a)
    		
     		duplicate/o root:tryFolders:rec1:tests:$(WaveNear):recon_col1, root:tryFolders:rec1:tests:$(WaveNear):$rPx1
   		duplicate/o root:tryFolders:rec1:tests:$(WaveNear):recon_col1, root:tryFolders:rec1:tests:$(WaveNear):$rPy1
   		duplicate/o root:tryFolders:rec1:tests:$(WaveNear):recon_col1, root:tryFolders:rec1:tests:$(WaveNear):$Ar1
   							
   		wave rPxWave1=root:tryFolders:rec1:tests:$(WaveNear):$rPx1
   		wave rPyWave1=root:tryFolders:rec1:tests:$(WaveNear):$rPy1
   		wave Rwaves1=root:tryFolders:rec1:tests:$(WaveNear):$Ar1

     		rPxWave1=(RC1-WAVENx1)^2		
     		rPyWave1=(RC2-WAVENy1)^2	
     		Rwaves1 = sqrt(rPyWave1+rPxWave1)
     							
     		EndFor
     						
     numdatafolders+=1	
     							
While ( numdatafolders < CountObjectsDFR(tests,4) )
 
       	
END

 

This is how data browser looks

It is quite hard to follow, but two things spring to mind:

1. Try running your code with the debugger and step through each line to check that it is doing what you expect.

2. In your code snippet above you have the line:

DFREF tests = GetDataFolderDFR()

twice - once for this data folder: root:tryFolders:rec1:tests,  and once for this data folder: root:tryFolders:rec1:tests:$(WaveNear). Is this really what you intended?

Good luck.