Correct index

Hello everyone,

I'm new to Igor and have a problem I can't solve.
I have three Waves Time, Latitiude and Longitude.

Now I want to write function that gives me the lat and lon values for a specific time.

i tried it this way but latlist is empty.

Please help me.

Max
#pragma rtGlobals=1     // Use modern global access method.
Function/D search(x1, x2)

Variable x1,x2
Variable x3,x4 

Wave LAT
Wave TIMEW
Wave LON

x3=TIMEW(x1)
x4=TIMEW(x2)
   
Extract/O LAT,latlist,LAT=x3 && LAT=x4
This is probably not doing what you think:
x3=TIMEW(x1)

You are asking for the value of TIMEW where its x value equals x1 but its x values are in terms of point number by default. To understand this execute:
DisplayHelpTopic "The Waveform Model of Data"


If you are looking for the point number at which TIMEW hits x1 then you need to use FindLevel.

This is incorrect:
Extract/O LAT,latlist,LAT=x3 && LAT=x4

To check for equality use ==, not = which does assignment.

I think a different approach would be easier but I don't know if it will get you where you want to go. Assuming that timew is monotonic you can use the interp function to get a linearly interpolated value for a given time:
Print interp(<some time value>, timew, lat) // Print interpolated latitude
Print interp(<some time value>, timew, lon) // Print interpolated longitude

Hmm well the interpolating function is not what I need.
I have a file from a flight. In this file I've got the time in seconds, latitude, longitude and altitude. Every thing in a seperate wave.
Now I want for a specific time that Igor gives me the latitude longitude and altitude corresponding to this time.

So I need the point of the time and than I have to tell Igor that I want the corresponding values from the other waves.

Somehow I don't get findlevel to work right.

I would be glad if someone could help me!
It sounds like your data is reported from a flight recorder and that you want to view specific information from those waves, and not to interpolate values which lie between them.

You could use findvalue on the time wave to get the point number at which that time value occurs, then use this point number to get the lattitude and longitude.

Function Search (x1)
variable x1

Wave TIMEW
WAVE LAT
WAVE LON

findvalue/v=x1 TIMEW       //search time wave for the value of 40 (i'm assuming 40 seconds into flight)
                                       //point saved in V_Value, if not found, V_Value = -1... you can add some logic to check for this
print LON[v_value]            
print LAT[V_Value]

end




If your time points are uniformly spaced, you could use them to scale the other three waves. Type the following into the command line for more information

DisplayHelpTopic "The Waveform Model of Data"
DisplayHelpTopic "SetScale"

max2331 wrote:
Hmm well the interpolating function is not what I need.
I have a file from a flight. In this file I've got the time in seconds, latitude, longitude and altitude. Every thing in a seperate wave.
Now I want for a specific time that Igor gives me the latitude longitude and altitude corresponding to this time.

So I need the point of the time and than I have to tell Igor that I want the corresponding values from the other waves.

Somehow I don't get findlevel to work right.

I would be glad if someone could help me!


What is wrong with interpolating? Perhaps it's not clear from Howard's answer, but using the interp function (or setting the wave scaling) will return exact values of data in your Lat and Long waves as long as the user inputs an exact time value that is in your time wave. The issue you should think about is what should happen if a nonexistant time value is input. I.E. you have data at 40 seconds and 50 seconds, but I call your function for a time of 43 seconds. Interpolating 30% of the way between 40 and 50 seconds is a common and valid approach (and what is done implicitly whenever data is graphed with lines instead of markers), but if it seems misleading to give the user an answer for a time that falls between data points, than what should happen? Should it be coerced to the nearest real data point or should the function indicate an error? To coerce to the nearest point you can use

pointnumber = round(BinarySearchInterp(TimeWave,InputTime)
ActualTime = TimeWave[pointnumber]
ActualLatitude = LatitudeWave[pointnumber]
ActualLongitude = LongitudeWave[pointnumber]


But if you do that you should also probably indicate to the user that you're giving an answer for ActualTime rather than the time they asked for. In this case too, if the user inputs an exact time value, they get an exact answer (ActualTime == InputTime).

If the time values are monotonic (it would be surprising if they were not) you can use BinarySearch to find the point number closest to the value you are looking for. That will avoid interpolation, but does not require exact time values. If interpolation is acceptable/desirable, BinarySearchInterp will give you a fractional point number.

John Weeks
WaveMetrics, Inc.
support@wavemetrics.com