I'm working with a file with xy coordinates that were acquired with a time stamp. All the time stamps were recorded but not the XY coordinates. Let see an example:
What I need to implement in awk is a interpolation by time e.g:
For the gap 10004-10006 fill the X gaps with this formula
Please reconsider the formulae you presented. If used as given, x(10004) = 1002939159,51. If parenthesizing the difference, as I assume it should be, x(10007) = 469559,65, so the interpolation doesn't fit. It's even worse for the second gap.
In fact I forgot parenthesizing. Is now correct. I need only to fill the gaps with the interpolation by time. The low value after the last gap in this example x (10007) = 469559,65 don't need to be interpolated because was measured. What I need is to interpolate only the gaps (that are variable)
For example for the formula that I want the result for the gaps is:
My need is to automatize this process.
Last edited by Joćo Noiva; 12-15-2014 at 01:42 PM..
Reason: to complete the idea
Printing the values you gave and the deltas, you can see that this is not a correct interpolation as the last delta is too large
This data was acquired by a moving vessel. The timetag
was always recorded but the not the coordinates. So as the vessel speed is not constant I will have always will have deltas in the interpolation.
Your interpolation formula is adding a percentage of the number one to the coordinates; not a percentage of the range between two coordinate values. Instead of the formula:
you need something more like:
where N is the index of the next known coordinate point and timestamp.
Using this formula, the awk script:
(with your sample input with commas converted to periods (since I'm in the US instead of Portugal)) produces the output:
As a sanity check, you can uncomment line before the for loop. In that mode it produces the output:
The lines shown in red confirm that the interpolated values for the end of the range match the actual end of range values.
The provided values are all shown with the number of decimal places provided in the input; the interpolated values are shown with four decimal places. If you'd like the interpolated values to be printed with two decimal places, change both occurrences of %.4f in the printf format string to %.2f. (I used a different number of decimal places to make it obvious which values were interpolated.)
Note that if you have other code that is generating the TIMEGAP field in your sample input, it isn't needed for this code to work.
You haven't said what OS you're using. If you want to run this script on a Solaris/SunOS system, change awk to /usr/xpg4/bin/awk, /usr/xpg6/bin/awk or nawk.
This User Gave Thanks to Don Cragun For This Post:
First I want to thank you for you suggestion and correction of the equation that was obviously wrong as RudiC also said.
Secondly I also thank you for your clean, simple and functional code!
Thirdly I ask you if you don't my mind a little more help.
I have a second pack of data that I need to interpolate based on the previous interpolated file.
I try to be short and clear:
Based on the RESULT.txt file (with all the data interpolated) I need to interpolate the values from a second file AIS_557.txt that have (due to issues during data acquisition) very few data points and with time stamps without decimals, based on first file. See example:
So I need to find the best fit for each time stamp of AIS file on the RESULT file. Interpolate X Y (for each time stamp of RESULT file) for the second file (AIS file).
Me and a colleague we are trying to adapt your function to do this but it is not working yet. The code is this one:
Dear all,
I always appreciate your help. I am an electrical engineer. I am using a tool for timing analysis of a circuit. I would like to interpolate results from two timing reports at different voltages (0.945V and 0.78V). If voltage is decreased, data arrival time is increased.
For... (4 Replies)
Dear All,
I have two files which contain numerical data and strings. I want to create a new file that only revise numerical data from two files using interpolation. I guess AWK works, but I am new on AWK.
FileA.txt
.
.
index_2("0.1, 1, 2, 4, 8, 16, 32");
values("0.0330208, 0.0345557,... (17 Replies)
Dear all,
I am kindly seeking assistance on the following issue.
I am working with data that is sampled every 0.05 hours (that is 3 minutes intervals) here is a sample data from the file
5.00000 15.5030
5.05000 15.6680
5.10000 16.0100
5.15000 16.3450
5.20000 16.7120
5.25000... (4 Replies)
Hi ! Experts...
I just wanted to know whether it is possible in scripting...to do interpolation....
if so....have a look on my data file
I need temperature and salinity value with a bin size of 0.5 m
output looks somewhat like this
dep temp sal
0.5 25 0.077
1 25 ... (12 Replies)
I'd like to convert a date string in the form of sun aug 19 09:03:10 EDT 2012, to unixtime timestamp using awk.
I tried
This is how each line of the file looks like, different date and time in this format
Sun Aug 19 08:33:45 EDT 2012, user1(108.6.217.236) all: test on the 17th
... (2 Replies)
Hi all,
Consider I have a text file containing:
1003 60
1005 80
1100 110
Based on that file I need to create another file which is containing value from 1001 till 1100 which is a linear interpolation between two point (for 1004; 1006;1007 until 1109) and extrapolation based on 2... (7 Replies)
Hi,
I have a snippet like below.
Based on variable i, i wish to print 1,2,3,4,5th columns to Sample files.
For each loop, one column from contetn and results will be pused to sample files. But i have a problem here
i=1
while ; do
`awk -F"\t" '{print $($i)}' $content > Sample_${i}_original`;... (4 Replies)
Hi everybody,
Firstly, this would be the first time I'm using JavaScript. My background is mainly Perl. Nevertheless, here's my problem.
So I've created a function
function linkout(url){
setTimeout("window.open(url)",5000) //in milliseconds
}
However because the variable "url" is... (0 Replies)
I've become obsessed with trying to get this to work.
As of yet, I am unable to figure it out. Unfortunately, I don't have Linux or UNIX available when I get home.
Anyone have tips for me on how I can pass param1 to ID via use of COUNTER and loop?
thx.
LIMIT=6
param1="999999999"
export... (0 Replies)