Hi please help. Any help would be appreciated :D

I have to write a program to read data from a large text file, analyze it, and output the results of the analysis to a data file. there are two data files to process.
Problem: Using airborne sensors that record GPS position and time, you have collected data on the airflow patterns of a tornado. The time (t) and altitude (Z) data are space-separated in a text file (twister.dat).
-As a first-step in data analysis, read-in the (unknown number of) data points and compute when the sensor changes direction. This occurs when the velocity, ΔZ/Δt, changes sign, passing through zero.
-Output the time and altitude of each occurrence of a change in direction to a new data file, change.dat.

So far this is what i have and i am stuck because i do not know how to find when the derivative goes from negative to positive or from positive to negative.

#include<iostream.h>
#include<fstream.h>
#include<string>
#include <C:\dislin\dislin.h>

 main () {
    ifstream fin ("prog10.text");
    float x[10000], y[10000], deltaT[10000], deltaZ[10000], derivative[10000];
    int nPoints;
    int lcv = 0;
    cout<< "The velocity changes direction at: " << endl;
    
    for (lcv  = 0; !fin.eof(); lcv++)
    { 
        fin >> deltaT[lcv] >> deltaZ[lcv];
        
    }
    deltaT[lcv] = deltaT[lcv] - deltaT[lcv -1]; // finds how much T changes for each lcv
    deltaZ[lcv] = deltaZ[lcv] - deltaZ[lcv-1]; // finds how much Z chnages for each lcv
    derivative[lcv] = deltaT[lcv]/ deltaZ[lcv]; // equation for derivative
    if(derivative[lcv]>0 && derivative[lcv-1] <0)
    {
    // find when the derivative goes from negative to positive or from positive to negative
}

So far this is what i have and i am stuck because i do not know how to find when the derivative goes from negative to positive or from positive to negative.

You need to store some data(altitude and time) in change.dat when velocity becomes negative. I htink this is what you are trying to do?
correct me if i am wrong.

The second thing is , in line 20 you have given derivative[lcv] = deltaT[lcv]/ deltaZ[lcv]; which contradicts the expression you posted (v= z/t)

The easiest way to see if the derivative changes sign when considering time derivatives would of course be to see if the difference between the last and 2nd to last Z changes sign.
This would mean something like if((deltaZ[lcv] - deltaZ[lcv - 1]) * (deltaZ[lcv - 1] - deltaZ[lcv - 2]) < 0). (Note that this fails when Z is identical for subsequent values of t)
You don't even need to compute the derivative for each set of values.

#include<iostream.h>
#include<fstream.h>
#include<string>
#include <C:\dislin\dislin.h>

 main () {
    ifstream fin ("prog10.text");
    float x[10000], y[10000], T[10000], Z[10000], derivative[10000];
    float direction = 0;
    int nPoints;
    int lcv = 0;
    cout<< "The velocity changes direction at: " << endl;
    
    for (lcv  = 0; !fin.eof(); lcv++)
    { 
        fin >> T[lcv] >> Z[lcv];
        
        // Make sure two subsequent identical Z's don't mess everything up
        // by keeping track of the latest non-zero direction
        if (lcv > 0 && Z[lcv] != Z[lcv - 1])
        {
            // Check if the direction changes sign for this (T,Z)
            if (direction * (Z[lcv] - Z[lcv - 1]) < 0)
            {
                // Got one
            }

            direction = Z[lcv] - Z[lcv - 1];
        }
    }
}

fin >> T[lcv] >> Z[lcv];

According to the OP:

The time (t) and altitude (Z) data are space-separated in a text file (twister.dat).

Why not declare a string empty val and input it in between t[lcv] and Z[lcv] to achieve the spacing?

string spacing= " ";
//Other code
for (lcv = 0; !fin.eof(); lcv++)
{
fin >> T[lcv] >> spacing >> Z[lcv];
 //Rest of the code..

Why not declare a string empty val and input it in between t[lcv] and Z[lcv] to achieve the spacing?

The extraction operator (>>) takes input delimited on spaces. The way the OP has it is fine.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.