LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

How to append new data and delete old data from a custom text file?

Solved!
Go to solution

Hi guys!

Well, I'm in a little trouble.

I need to make an application with some GPS tools. Split data into indicators, generate coordinates (in google maps format), and so it goes.

One of the systems functions is the calculation of coordinates oscillation. The formula should be: latitude 1 - latitude 2 = latitude oscillation AND longitude 1 - longitude 2 = longitude oscillation.

Since I'm using two values, I thought: "Oh, if I log those data into a file, I just retrieve them and do all the math part." Yes, that idea is suitable for my needs (even if it's not the best, it solved part of my problem).

BUT, I can't see a way to write the current loop value and erase the old results.

For example, let's assume loop 1 gave me coordinates 1.00000 and 2.00000 and loop 2 gave me coordinates 3.00000 and 4.00000. Right?

My log file would be similar to: 1.00000,2.00000;3.00000,4.00000;

Well, that works. However, let's look forward to loop 3: coordinates 5.00000,6.00000.

If the program logs it, I'd get the string: 1.00000,2.00000;5.00000,6.00000; when I actually needed 3.00000,4.00000;5.00000,6.00000;.

Because of this, when I apply oscillation calculation, it will always take the most recent value and do all calculation with the first result (from loop 1).

Well, I wonder that there's a way to append new data to a file and replace the oldest values, with simple code. If someone knows how, please reply here!

 

Considerations:

1) I'd like to do it as simple as possible. My code is kind of big, and it's not suitable to insert structures or library right now.

2) Maybe the explanation isn't too simple as it's for me. I really couldn't find a better way to tell what I need.

3) If someone has any doubts about my doubts, please just comment and I'll try to be the more specific as possible.


Thanks in advance!!

 

Mondoni
0 Kudos
Message 1 of 7
(4,428 Views)

Read everything in. Delete what you don't want. Write back the data you do want.

There isn't any other easy way.

 

0 Kudos
Message 2 of 7
(4,421 Views)

Hello, thanks for answering!

That's a good idea, even if I see that I'd have to do some adjustments in my code.

I tell the result later. 

Thank you

Mondoni
0 Kudos
Message 3 of 7
(4,416 Views)

A really simple alternative would be to just keep appending the data in the file.  When you do your comparison, you just look at the last 2 samples.


GCentral
There are only two ways to tell somebody thanks: Kudos and Marked Solutions
Unofficial Forum Rules and Guidelines
"Not that we are sufficient in ourselves to claim anything as coming from us, but our sufficiency is from God" - 2 Corinthians 3:5
0 Kudos
Message 4 of 7
(4,415 Views)
Solution
Accepted by topic author joaopam

I guess my question is why write it to a file just to delete it. 

 

If you pass an array of points from one iteration to the next you will not have to take the extra time to open the file, read the file, delete the old data, write the new data, save the file and then close the file.  It would be just about the same thing, but without having to go to the hard drive.

 

Just a thought.  

Message 5 of 7
(4,403 Views)

Hello Bryan,

 

Yes, that's a good idea.

At first time, I realized that would be much more simple to write and read data, even if they're temporally. 

I'll try to make that. Thanks for it!!

Mondoni
0 Kudos
Message 6 of 7
(4,393 Views)

@crossrulz wrote:

A really simple alternative would be to just keep appending the data in the file.  When you do your comparison, you just look at the last 2 samples.


Hello Crossrulz!

 

Sorry, but I don't think I get your solution. You mean: log all data and then just read the last 2?

If is that what you meant, I don't remember any function on LabVIEW that reads last 2 samples without code size and complexity increasing. 

Thanks for the answer!

Mondoni
0 Kudos
Message 7 of 7
(4,390 Views)