|
|||||||
| Forums | Search Forums | Register | Forum Rules | Man Pages | Albums | FAQ | Members | Calendar | Search | Today's Posts | Mark Forums Read |
| Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here. |
|
|
|
Thread Tools | Search this Thread | Display Modes |
|
#1
|
|||
|
|||
|
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. Last edited by Scrutinizer; 12-04-2012 at 05:12 PM.. Reason: Removed some really really really spurious formatting |
| Sponsored Links | ||
|
|
#2
|
||||
|
||||
|
I don't understand what you're trying to achieve. Could you please explain a bit more.
|
| Sponsored Links | ||
|
|
#3
|
|||
|
|||
|
Sometimes, Understanding a question is much harder than providing a solution.
Cheers, Korean ![]() |
|
#4
|
|||
|
|||
|
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
|
|||
|
|||
|
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
|
|||
|
|||
|
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
|
|||
|
|||
|
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 | ||
|
![]() |
| Thread Tools | Search this Thread |
| 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 |
|
|