Sponsored Content
Top Forums Shell Programming and Scripting XY interpolation by time in awk Post 302929056 by Joćo Noiva on Wednesday 17th of December 2014 08:37:34 AM
Old 12-17-2014
Dear Don,

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:


Code:
RESULT.TXT
010001 0469557.90 4266045.60 1386557563.76
010002 0469558.32 4266046.88 1386557564.65
010003 0469558.65 4266048.13 1386557565.55
010004 0469558.94 4266049.05 1386557566.45
010005 0469559.24 4266049.98 1386557567.36
010006 0469559.53 4266050.89 1386557568.25
010007 0469559.82 4266051.82 1386557569.16
010008 0469560.48 4266053.00 1386557570.05
010009 0469561.10 4266054.12 1386557570.95
010010 0469561.64 4266055.28 1386557571.85
010011 0469562.00 4266056.50 1386557572.76
010012 0469562.25 4266057.80 1386557573.66
010013 0469562.52 4266059.11 1386557574.55
010014 0469562.88 4266060.08 1386557575.45
010015 0469563.23 4266061.05 1386557576.35
010016 0469563.59 4266062.03 1386557577.25
010017 0469563.95 4266063.01 1386557578.16
010018 0469564.31 4266063.98 1386557579.06
010019 0469564.85 4266065.22 1386557579.95
010020 0469565.34 4266066.47 1386557580.85
010021 0469565.79 4266067.67 1386557581.76
...........


Code:
 AIS_557.txt
468953.73 4264882.13 1386533790
468944.97 4264871.07 1386533820
468936.22 4264860.01 1386533850
468927.46 4264848.94 1386533880
468918.70 4264837.88 1386533910
468918.65 4264826.79 1386533940
468909.89 4264815.72 1386533970
468892.38 4264793.60 1386534030
468883.62 4264782.54 1386534060
468874.90 4264782.57 1386534090
468866.14 4264771.51 1386534150
468857.43 4264771.54 1386534180
468839.95 4264760.51 1386534210
468822.43 4264738.39 1386534240
468813.67 4264727.33 1386534270
..........

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:

Code:
awk '
function interpola(i, P1, P2,  Xi, Yi) {
	Xi= Xais[P1] +((Xais[P2]-Xais[P1])*(Tsis[i]-Tais[P1]))/(Tais[P2]-Tais[P1])
	Yi= Yais[P1] +((Yais[P2]-Yais[P1])*(Tsis[i]-Tais[P1]))/(Tais[P2]-Tais[P1])
	printf("%06i %010.2f %010.2f %013.2f\n", FFID[i], Xi, Yi, T[i])
#	print FFID[i], T[i], P1, P2 #test fitting points for interpolation (keeps line number where are P1 or P2)
}
{
NR==FNR{Tsis[FNR]=$4; Sis[FNR]=$0; next} # Reads the first file with principal serie 
{Xais[FNR]=$1; Yais[FNR]=$2; Tais[FNR]=$3 } # Reads the second file with AIS values to interpolate

}
END {
for (i in Tsis[FNR]) {
	for (j=1; j<FNR; j++) {	# Runs down until find P1
		if (Tsis[i]>Tais[FNR]) {
			P1=j
			break
		}
	}
	for (k=j; k<=FNR; k++) { # Runs down until find P2
		if ((Tsis[i]<Tais[FNR]) ) {
			P2=k
			break
		}
	}	
	interpola(i, P1, P2) 	#interpolation and print interpolated values
}

}' '  RESULT.txt AIS_557.txt  > AIS_INTERPOLATION.txt

Can you give us, please, a suggestion!

Thanks in advance
 

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

variable interpolation

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)
Discussion started by: egkumpe
0 Replies

2. Web Development

JavaScript variable interpolation

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)
Discussion started by: z1dane
0 Replies

3. Shell Programming and Scripting

Variable interpolation in "print" of awk command

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)
Discussion started by: forums123456
4 Replies

4. Shell Programming and Scripting

Interpolation using awk

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)
Discussion started by: ardy_yana
7 Replies

5. UNIX for Dummies Questions & Answers

Converting string date time to unix time in AWK

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)
Discussion started by: bkkid
2 Replies

6. Shell Programming and Scripting

Hi ! whether it is possible to do interpolation in scripting...

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)
Discussion started by: nex_asp
12 Replies

7. Programming

Find gaps in time data and replace missing time value and column 2 value by interpolation in awk

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)
Discussion started by: malandisa
4 Replies

8. Shell Programming and Scripting

Awk: time intervals based on epoch time

I have a list of epoch times delimited by "-" as follows: 1335078000 - 1335176700 1335340800 - 1335527400 1335771300 - 1335945600 1336201200 - 1336218000 The corresponding dates are: 20120422 1000 - 20120423 1325 20120425 1100 - 20120427 1450 20120430 1035 - 20120502 1100 ... (3 Replies)
Discussion started by: alex2005
3 Replies

9. Shell Programming and Scripting

Interpolation of two values in two different files

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)
Discussion started by: jypark22
17 Replies

10. Shell Programming and Scripting

An interpolation between two files

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)
Discussion started by: jypark22
4 Replies
All times are GMT -4. The time now is 04:12 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy