Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Is it possible to skip data from input file(read for more info)

Status
Not open for further replies.

SEALs1230

Programmer
Oct 23, 2004
4
US
Hi,

I'm trying to write a program that will take and read data from an outside file. I can open the file and all that and get values from the file. The file is a list of times, altitudes, velocities, and accelerations. I need to figure out how to find when the velocity changes from decreasing to increasing and output the time when this occurs. I figured out how to do this using the acceleration. For my data it is every time the acceleration changes from negative to positive. Therefore I used an if statement to say to output the time when acceleration is positive. This doesnt work however because I only need that single value when it changes. With the way I did it, I output the time for every all positive acceleration data points, not just the ones for when the acceleration changes from negative to positive. I've tried switch, for, while, if-else, everything I can think of. Is there any way to just use the first positive acceleration and have the program skip all the other positive accelerations in the data file until the data changes from negative to positive again??
 
Why are you using acceleration use the velocity. Set your velocity in a variable and compare each velocity. Output when new velocity is larger than old velocity. Change velocity variable every cycle.
 
I tried that too. Right now I'm trying to figure a way to do that. However, I need to output the time when the velocity changes from decreasing to increasing. If I do what you say, then it will out put all the velocities when the velocity is increasing rather than just that one when it changes from decreasing to increasing. I need to find a way to output just the exact values when the velocity changes from decreasing to increasing and skip the rest. I was trying it with acceleration because when the velocity is decreasing, accel. will be negative and when velocity is increasing, accel will be positive. This way I can avoid the difference stuff and make it much neater by only finding when the acceleration is greater than 0. However, I run into that same problem where I only need the first positive value each time but I output all positive values. I need to know how to skip the other values.
 
1. create a function called ReadRecord, which reads one record from the file (velocity, time, etc

Then you can do something like this pseudocode.
Code:
record old, new;
old = ReadRecord();  get the first one
while ( new = ReadRecord() ) {
  if ( old.acceleration < 0 && new.acceleration >= 0 ) {
    // output new
  }
  old = new;
}

--
 
It worked!! I did it a little differently but used the basic idea. I knew that that was what I had to do but I couldnt figure out how. I sat here for 4 hours!!! trying to figure out the setup for it to work. But I couldnt get it out of me. I'm the kind of person that needs examples. If I see a similar example to what I need I can usually use that as a base and work from there. You helped a lot. Thanks.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top