06-30-2017 10:15 AM - edited 06-30-2017 10:16 AM
Hello
I am having trouble understanding how the nested for loop structure within Labview works. I have three nested for loops. The outer loop takes the number of image files in folder and iterates that number of times. The next loop iterates based on the number of rows of data within a text file. Within that loop there is a counter(for crank angle) and the strings that are overlayed on the image file are formatted and adjusted based on data from text file. The inner most loop is controlled by a calculated value which determines how many images need the same data overlayed onto them. The issue I am having is the image files are not being read in in order(some are being skipped) and at some points the images jump around(goes from image 1001 to 1010). I believe it is an issue with how I formatted my loops and where I am auto indexing my array of image files. I attached my VI and subvis.
Thanks
06-30-2017 10:55 AM - edited 06-30-2017 11:04 AM
I can't immediately work out the problem with your VI, but I would like to suggest you might find it easier to troubleshoot if you could see more of it at once. At the very least, I expect forum-goers who aren't the authors of your code would find it easier 😉
One comment beyond the whitespace available for cutting out (holding Ctrl-Alt and Left clicking and dragging will remove space) is that lots of space it taken up by very long labels. It's fine if you need to give instructions for controls, but consider using Captions instead of Labels for this purpose. That way, you can have text bound to the control, without it taking up lots of (especially horizontal) space on the block diagram. To use a caption, right click on the control and click on Visible Items > Caption. By default it will hide the label and take the same value as the label. You can then right click and go to properties to change the Label, or you can just double click on the block diagram to edit the label.
Edit: In answer to your actual question, I would try autoindexing the File Path array into the first loop instead of wiring the result of the Array Size, since it will give the same number of iterations to that (outermost) loop. The inner loop has two conflicting instructions on how many times to iterate - you don't want the file path to be autoindexing there (and if you autoindex the outermost loop, it won't be an array anymore anyway).
06-30-2017 02:02 PM - edited 06-30-2017 02:06 PM
Okay thank you for your response. I will try to remove the white space and create captions instead of labels to make the VI more readable. When, I index the array using the outer for loop only the first image in the folder is used in the inner loops. I think I may have to invert the structure of my for loops to get the desired result. How are the nested for loops executed(from out to in or in to out, I assume the latter)? I tried debugging using highlighted execution and probes but I have been unable to tell bc it seems like it is always within the inner loop, but that might just be bc that is where the main image processing occurs.
Thanks
06-30-2017 11:07 PM
The inner loops execute first - you can imagine it by thinking about how they work in a way related to the dataflow.
First, the outer loop starts. Before it can go to the next iteration, everything inside the current iteration needs to finish. It doesn't have any operations except a for loop (the middle one), so it passes some wires through and starts the middle For loop. This takes basically no time, and even with Highlight Execution, it will happen very quickly.
Next, the middle loop starts. As with the first loop, before it can go to the next iteration, everything inside its current iteration needs to finish. This loop does a little bit of string processing, which probably takes a few seconds with Highlight Execution on (and pretty much no time without) and then it starts the inner loop.
The inner loop does a bunch of work, for "Duration 1 Degree of CA (Frames of Camera)" number of times. I'm not sure how many that is - you should check it gives the value you expect, but anyway, this innermost loop takes some time, and especially with H-E has a number of blocks, so that will take more time. Consequently, it looks to be always in the middle loop.
Once the inner loop has run "Duration 1 Degree..." times, the middle loop goes to the second iteration. The outer loop is still stuck in its first iteration until the middle loop has run "Number of Rows of Data" times, and the inner loop has run "Number of Rows of Data" * "Duration 1 Degree of CA" times.
Note that none of these values are calculated per file - they are all calculated as constant values and passed into the loops. (The string passed into the inner loop from the middle loop is the exception - this is calculated once per middle loop, as you probably already knew!)
I'm surprised that it's only doing the first file - did you let it finish? If the "Array of Files in Folder to be Edited" (I wish some of these names were shorter 😉 ) has a number of files, then the loop should run that many times when autoindexing that wire. Make sure that N is not connected (although the previous connection would give the same value, so it wouldn't matter). A For loop finishes whenever the first stop condition is met, i=N-1 (because i starts from 0), or the smallest autoindexed loop runs out of elements, or if you set it up with a conditional terminal, that terminal causes the end.