Hi ! whether it is possible to do interpolation in scripting... | Unix Linux Forums | Shell Programming and Scripting

  Go Back    


Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

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

Shell Programming and Scripting


Closed Thread    
 
Thread Tools Search this Thread Display Modes
    #1  
Old 12-04-2012
nex_asp nex_asp is offline
Banned
 
Join Date: Dec 2012
Last Activity: 21 May 2013, 2:14 AM EDT
Location: India
Posts: 70
Thanks: 20
Thanked 0 Times in 0 Posts
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


Code:
dep   temp  sal
0.5     25     0.077
1        25     0.077
1.5
2
2.5
-
-
-
8.5     25     0.16

Note : one more thing here same dep value (0.789) repeated for around 22 rows so average of temperature and salinity should be taken, so whenever backward derivative equal to forward derivative average of temperature and salinity should be taken something like this
Code:
                mask  depth
1:   .... 1:  1.000  0.789  ---backward derivative
2     /   2:  1.000  0.789  ---forward derivative
3     /   3:  1.000  0.789
4     /   4:  1.000  0.789
5     /   5:  1.000  0.789
23    /  23:   ....    0.789
24    /  24:   ....    0.790
25    /  25: 1.000 0.790
26    /  26: 1.000 0.790

Here I am not completing asking you people to do the script for interpolation at least if you can able to do the averaging of temperature and salinity by checking forward and backward derivative it would be very helpful for me.
Attached Files
File Type: txt ctd001_ins1_04-08-07_1100.txt (20.7 KB, 16 views)

Last edited by Scrutinizer; 12-04-2012 at 05:12 PM.. Reason: Removed some really really really spurious formatting
Sponsored Links
    #2  
Old 12-04-2012
balajesuri's Avatar
balajesuri balajesuri is offline Forum Advisor  
#! /bin/bash
 
Join Date: Apr 2009
Last Activity: 22 August 2014, 7:46 AM EDT
Location: India
Posts: 1,822
Thanks: 24
Thanked 523 Times in 502 Posts
I don't understand what you're trying to achieve. Could you please explain a bit more.
Sponsored Links
    #3  
Old 12-04-2012
Joseph_TKLee Joseph_TKLee is offline
Registered User
 
Join Date: Nov 2012
Last Activity: 24 September 2013, 6:55 AM EDT
Location: Brisbane, Australia
Posts: 40
Thanks: 3
Thanked 10 Times in 10 Posts
Sometimes, Understanding a question is much harder than providing a solution.

Cheers,
Korean
    #4  
Old 12-05-2012
nex_asp nex_asp is offline
Banned
 
Join Date: Dec 2012
Last Activity: 21 May 2013, 2:14 AM EDT
Location: India
Posts: 70
Thanks: 20
Thanked 0 Times in 0 Posts
I have a need of doing averaging..for interpolation purpose

Try to understand..

consider 1st column, you can find duplicate values 0.789 repeated for about 22 times, but in second and third column values are varying, because of duplicates in 1st column, I have to take average of 2nd and 3rd values (22 values), so what script has to do is whenever it finds duplicate value it has to do averaging..

example : let me take first one sample input here


Code:
column 1 column 2  
1                 20.2
1                 21.2        -------> 3 values in 1st column are same 
1                 22.3                   so I need average of column 2
2                 22.5                   average will be 21.13
3                 25.9
4                 26.8
4                 26.9
4                 26.7

output file should look like this

Code:
column 1 column 2
1               21.13
2               22.5
3               25.9
4               26.8

wherever script finds duplicates in 1st column it has to do the averaging.

I hope now its clear

Last edited by Scott; 12-05-2012 at 05:06 AM.. Reason: Use code tags, please...
Sponsored Links
    #5  
Old 12-05-2012
pamu pamu is offline
Registered User
 
Join Date: Mar 2012
Last Activity: 20 August 2014, 7:37 AM EDT
Posts: 1,649
Thanks: 58
Thanked 478 Times in 474 Posts

Code:
$ cat file
1 20.2
1 21.2
1 22.3
2 22.5
3 25.9
4 26.8
4 26.9
4 26.7

$ awk 's != $1 && NR > 1{print s,a/X[s];a=0}{a+=$2;s=$1;X[$1]++}END{print s,a/X[s]}' file
1 21.2333
2 22.5
3 25.9
4 26.8

Sponsored Links
    #6  
Old 12-05-2012
RudiC RudiC is offline Forum Advisor  
Registered User
 
Join Date: Jul 2012
Last Activity: 28 August 2014, 8:56 AM EDT
Location: Aachen, Germany
Posts: 4,135
Thanks: 67
Thanked 984 Times in 932 Posts
I'm not sure I understand either. You want to generate data points every 0.5 m. Depth ranging from 0.789 to 8.305 you will get sth. like 16 data points, say 1, 1.5, ..., 8.5. So why don't you collect the temperatue and salinity into avarages around those abcissa values?
Why do you crack a nut with a sledge hammer, averaging 23 values for 0.789m, when everything will disappear in a large lump sum at 1.0m?
BTW, nit-picking, you can have difference quotients on those columns but no derivatives. And, I think it would be helpful to use one single sample file to discuss and attach, so col 1 would be col 1 everywhre.

And, finally answering your introductory question, yes, I'm pretty sure you can do (some degree of) interpolation in scripts.
Sponsored Links
    #7  
Old 12-05-2012
nex_asp nex_asp is offline
Banned
 
Join Date: Dec 2012
Last Activity: 21 May 2013, 2:14 AM EDT
Location: India
Posts: 70
Thanks: 20
Thanked 0 Times in 0 Posts
Can you explain second line of script

Dear Pamu, if you have time can you please explain 2nd line (awk) of script.. please
Sponsored Links
Closed Thread

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Interpolation using awk ardy_yana Shell Programming and Scripting 7 04-05-2012 03:04 AM
Variable interpolation in "print" of awk command forums123456 Shell Programming and Scripting 4 02-22-2012 06:35 PM
JavaScript variable interpolation z1dane Web Programming 0 01-27-2010 12:10 AM
scripting guru's pls help me with scripting on AIX thatiprashant Shell Programming and Scripting 1 01-20-2006 06:58 PM
variable interpolation egkumpe UNIX for Dummies Questions & Answers 0 08-05-2004 06:05 PM



All times are GMT -4. The time now is 11:16 PM.