03-21-2013 02:59 PM
Hi all,
Please see the attached picture for the problem I am facing. Basically, I want to open up several files in one folder, and use the file names to derive other file names in a different folder and plot the data in all the files.
Here is what I am doing:
1. Use File Dialog to select files
2. Create a local variable of "selected files" - see below
3. Derive new files "new files" using the "selected files" and make a local variable of the "new files"
4. Plot data from "selected files"
5. Plot data from the "new files"
The reason for making local variables is that I will be accessing the original files and derived files from many places in my VI and I want to avoid uncessary wiring or opening up the File Dialog multiple times (less clicking - my index figure hurts :))
Problem: Data from "selected files" get plotted. However, data from "new files" is NOT data from the "new files" of the existing run, but data from a previous run. Apparently, the local variable "new files" does not get UPDATED
with the "new files" from the current run. I have to run my VI twice. Why is this? How can I fix it?
Solved! Go to Solution.
03-21-2013 03:08 PM - edited 03-21-2013 03:10 PM
Is it safe to assume that the sequence exists in your real code? The problem is a lot more interesting if the sequence is actually there.
If it's not there then the local is being read before the for loop finishes, therefore returning the previous runs value. This is your classic race condition, and the main reason to avoid locals to begin with.
03-21-2013 03:15 PM - edited 03-21-2013 03:18 PM
Yes, my code has the flat sequence, and that is why I am a little baffled.
I also wanted to add the following: I use the file names to derive the legend for my plots. Could it be that the plots are updated but the legend is stuck from the old run?
03-21-2013 03:17 PM - edited 03-21-2013 03:18 PM
Are you using the sequence structure as you have shown? This sounds like a classic race condition (the main reason for not using locals).
Nevermind. That's what I get for getting distrcted for a few minutes.
03-21-2013 03:21 PM
@murchak wrote:
Problem: Data from "selected files" get plotted. However, data from "new files" is NOT data from the "new files" of the existing run, but data from a previous run. Apparently, the local variable "new files" does not get UPDATED
with the "new files" from the current run. I have to run my VI twice. Why is this? How can I fix it?
This definitely does not sound right. Can you attach the actual code?
03-21-2013 03:22 PM - edited 03-21-2013 03:24 PM
@crossrulz wrote:
Are you using the sequence structure as you have shown? This sounds like a classic race condition (the main reason for not using locals).
Nevermind. That's what I get for getting distrcted for a few minutes.
Wow, that was almost word for word.
@murchak wrote:
I also wanted to add the following: I use the file names to derive the legend for my plots. Could it be that the plots are updated but the legend is stuck from the old run?
If the legend is being updated outside the sequence then it's likely still a race condition, where its getting updated using the old value rather than the new. Of course it'd be much easier to tell if you attached your actual code.
The only other possible thing I could think of just going off your image is that there is an indicator somewhere else with the same label that your local is tied to, rather than the one in the first frame of the sequence.
Edit: Wow formatting with multiple quotes is a little tough in this editor.
03-21-2013 03:23 PM
You guys have to pardon my ignorance, but this seems like a good instance for using local variables to avoid cluttering up my code wires running from one frame of the sequence to another.
My code is of course more complicated than above in the sense that it takes a lot more to derive the new file names from the selected files, which initially I had created as a subvi which would take in
the selected files as input and spit out new file paths. Initially I had only created a local variable out of the selected paths and feed that into my subvi whereever it was called in my code if I needed to access the new files.
I thought it was my subvi that was remembering the "new files" from an older run, and not the current run, so I took my subvi and stuck in the first frame of the sequence, and created locals of the "new files" to be used in the code.
03-21-2013 03:28 PM
@murchak wrote:
You guys have to pardon my ignorance, but this seems like a good instance for using local variables to avoid cluttering up my code wires running from one frame of the sequence to another.
Your sequences and locals take up way more screen pixels than a few wires ever would.
murchak wrote:My code is of course more complicated than above in the sense that it takes a lot more to derive the new file names from the selected files, which initially I had created as a subvi which would take in
the selected files as input and spit out new file paths. Initially I had only created a local variable out of the selected paths and feed that into my subvi whereever it was called in my code if I needed to access the new files.
I thought it was my subvi that was remembering the "new files" from an older run, and not the current run, so I took my subvi and stuck in the first frame of the sequence, and created locals of the "new files" to be used in the code.
All I can see is gibberish. Show us some code instead!
03-21-2013 03:28 PM
@murchak wrote:
You guys have to pardon my ignorance, but this seems like a good instance for using local variables to avoid cluttering up my code wires running from one frame of the sequence to another.
That's the beauty of using a wire though. In all likelihood you don't even need the sequence if you use the wires.
03-21-2013 03:34 PM
elset191 wrote:Wow, that was almost word for word.
Great minds think alike.