Sponsored Content
Top Forums Shell Programming and Scripting calculate the average of time series data using AWK Post 302271341 by nica on Wednesday 24th of December 2008 10:48:07 PM
Old 12-24-2008
Hi,

I have another request..

here, V2 is a counter
I want to match V2 value with the V1 value with the same time series (t1) before V2 counter get reset to "1"..
e.g. 1,2,3,1 ---> I want to get value of V1 when value of V2 is "3" (before reset to "1")
or
e.g. 1,2,1,1,1, ---> I want to get the value of V1 when value of V2 are "2" followed by three consecutive "1"


Input File:

t1 V1 t2 V2
10.000000 4.387413 10.139355302 1
10.100000 4.397372 10.252770182 2
10.200000 4.406951 10.398060182 1
10.300000 3.940732 10.515105302 1
10.400000 4.044359 10.645365302 1
10.500000 4.139778 10.768800182 2
10.600000 4.222087 10.929725222 3
10.700000 4.299174 11.106285302 1
10.800000 2.941378 11.216505302 1
10.900000 3.081282 11.324910182 2
11.000000 3.219284 11.626115222 3
11.100000 3.354575 11.822715302 4
11.200000 3.486347 11.968005302 5
11.300000 3.613792 12.107075222 1
11.400000 3.730119 12.233535302 1
11.500000 3.846800 12.377615222 1
11.600000 3.956768 12.494055302 1
11.700000 4.059215 12.642540182 1
11.800000 4.153333 12.742740182 1
11.900000 4.234293 12.853565222 1
12.000000 4.309844 13.093440182 1
..............
..............



Desired Output:

t1 V1 V2
10.200000 4.406951 2
10.300000 3.940732 1
10.500000 4.139778 1
10.900000 3.081282 3
11.100000 3.354575 1
11.900000 4.234293 5
...............
...............
 

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Use awk to calculate average of column 3

Suppose I have 500 files in a directory and I need to Use awk to calculate average of column 3 for each of the file, how would I do that? (6 Replies)
Discussion started by: grossgermany
6 Replies

2. HP-UX

calculate average of multiple line data

I have a question as below and i need to write a shell or perl script for this query:My Input file looks like below RNo Marks 12 50 15 70 18 80 12 40 13 55 18 88 13 75... (4 Replies)
Discussion started by: smacherla
4 Replies

3. UNIX for Dummies Questions & Answers

Iterate a min/max awk script over time-series temperature data

I'm trying to iterate a UNIX awk script that returns min/max temperature data for each day from a monthly weather data file (01_weath.dat). The temperature data is held in $5. The temps are reported each minute so each day contains 1440 temperature enteries. The below code has gotten me as far as... (5 Replies)
Discussion started by: jgourley
5 Replies

4. Shell Programming and Scripting

Calculate average time using a script

Hello, I'm hoping to get some help on calculating an average time from a list of times (hour:minute:second). Here's what my list looks like right now, it will grow (I can get the full date or change the formatting of this as well): 07:55:31 09:42:00 08:09:02 09:15:23 09:27:45 09:49:26... (4 Replies)
Discussion started by: jaredhanks
4 Replies

5. Shell Programming and Scripting

AWK novice - calculate the average

Hi, I have the following data in a file for example: P1 XXXXXXX.1 YYYYYYY.1 ZZZ.1 P1 XXXXXXX.2 YYYYYYY.2 ZZZ.2 P1 XXXXXXX.3 YYYYYYY.3 ZZZ.3 P1 XXXXXXX.4 YYYYYYY.4 ZZZ.4 P1 XXXXXXX.5 YYYYYYY.5 ZZZ.5 P1 XXXXXXX.6 YYYYYYY.6 ZZZ.6 P1 XXXXXXX.7 YYYYYYY.7 ZZZ.7 P1 XXXXXXX.8 YYYYYYY.8 ZZZ.8 P2... (6 Replies)
Discussion started by: alex2005
6 Replies

6. Shell Programming and Scripting

Calculate Average AWK

I want to calculate the average line by line of some files with several lines on them, the files are identical, just want to average the 3rd columns of those files.:wall: Example file: File 1 001 0.046 0.667267 001 0.047 0.672028 001 0.048 0.656025 001 0.049 ... (2 Replies)
Discussion started by: AriasFco
2 Replies

7. Shell Programming and Scripting

Calculate average for repeated ID within a data

I have an awk script that gives the following output: Average end-to-end transmission delay 2.7 to 5.7 is 0.635392 seconds Average end-to-end transmission delay 2.1 to 5.1 is 0.66272 seconds Average end-to-end transmission delay 2.1 to 5.1 is 0.691712 seconds Average end-to-end transmission... (4 Replies)
Discussion started by: ENG_MOHD
4 Replies

8. Programming

Resample time series data with replacement any way to do this in awk or just bash script

I have some time series data that I need to resample or downsample at some specific time intervals. The firs column is time in decimal hours. I am tryiong to resample this data every 3 minutse. So I need a data value ever 0.05. Here is the example data and as you can see, there time slot for 0.1500... (3 Replies)
Discussion started by: malandisa
3 Replies

9. Shell Programming and Scripting

Average of multiple time-stamped data every half hour

Hi All, Thank you for reading through my post and helping me figure out how I would be able to perform this task. For example: I have a list of continuous output collected into a file in the format as seen below: Date...........Time........C....A......... B ==========================... (5 Replies)
Discussion started by: terrychen
5 Replies

10. Shell Programming and Scripting

Calculate Average time of one column

Hello dears, I have a log file with records like below and want to get a average of one column based on the search of one specific keyword. 2015-02-07 08:15:28 10.102.51.100 10.112.55.101 "kevin.c" POST ... (2 Replies)
Discussion started by: Newman
2 Replies
PLANIMETER(1)						      GeographicLib Utilities						     PLANIMETER(1)

NAME
Planimeter -- compute the area of geodesic polygons SYNOPSIS
Planimeter [ -r ] [ -s ] [ -l ] [ -e a f ] [ --comment-delimiter commentdelim ] [ --version | -h | --help ] [ --input-file infile | --input-string instring ] [ --line-separator linesep ] [ --output-file outfile ] DESCRIPTION
Measure the area of a geodesic polygon. Reads polygon vertices from standard input, one per line. Vertices may be given as latitude and longitude, UTM/UPS, or MGRS coordinates, interpreted in the same way as GeoConvert(1). (MGRS coordinates signify the center of the corresponding MGRS square.) The end of input, a blank line, or a line which can't be interpreted as a vertex signals the end of one polygon and the start of the next. For each polygon print a summary line with the number of points, the perimeter (in meters), and the area (in meters^2). By default, polygons traversed in a counter-clockwise direction return a positive area and those traversed in a clockwise direction return a negative area. This sign convention is reversed if the -r option is given. Of course, encircling an area in the clockwise direction is equivalent to encircling the rest of the ellipsoid in the counter-clockwise direction. The default interpretation used by Planimeter is the one that results in a smaller magnitude of area; i.e., the magnitude of the area is less than or equal to one half the total area of the ellipsoid. If the -s option is given, then the interpretation used is the one that results in a positive area; i.e., the area is positive and less than the total area of the ellipsoid. Only simple polygons are supported for the area computation. Polygons may include one or both poles. There is no need to close the polygon. OPTIONS
-r toggle whether counter-clockwise traversal of the polygon returns a positive (the default) or negative result. -s toggle whether to return a signed result (the default) or not. -l toggle whether the vertices represent a polygon (the default) or a polyline. For a polyline, the number of points and the length of the path joining them is returned; the path is not closed and the area is not reported. -e specify the ellipsoid via a f; the equatorial radius is a and the flattening is f. Setting f = 0 results in a sphere. Specify f < 0 for a prolate ellipsoid. A simple fraction, e.g., 1/297, is allowed for f. (Also, if f > 1, the flattening is set to 1/f.) By default, the WGS84 ellipsoid is used, a = 6378137 m, f = 1/298.257223563. If entering vertices as UTM/UPS or MGRS coordinates, use the default ellipsoid, since the conversion of these coordinates to latitude and longitude uses the WGS84 parameters. --comment-delimiter set the comment delimiter to commentdelim (e.g., "#" or "//"). If set, the input lines will be scanned for this delimiter and, if found, the delimiter and the rest of the line will be removed prior to processing. For a given polygon, the last such string found will be appended to the output line (separated by a space). --version print version and exit. -h print usage and exit. --help print full documentation and exit. --input-file read input from the file infile instead of from standard input; a file name of "-" stands for standard input. --input-string read input from the string instring instead of from standard input. All occurrences of the line separator character (default is a semicolon) in instring are converted to newlines before the reading begins. --line-separator set the line separator character to linesep. By default this is a semicolon. --output-file write output to the file outfile instead of to standard output; a file name of "-" stands for standard output. EXAMPLES
Example (the area of the 100km MGRS square 18SWK) Planimeter <<EOF 18N 500000 4400000 18N 600000 4400000 18N 600000 4500000 18N 500000 4500000 EOF => 4 400139.53295860 10007388597.1913 The following code takes the output from gdalinfo and reports the area covered by the data (assuming the edges of the image are geodesics). #! /bin/sh egrep '^((Upper|Lower) (Left|Right)|Center) ' | sed -e 's/d /d/g' -e "s/' /'/g" | tr -s '(), ' ' ' | awk '{ if ($1 $2 == "UpperLeft") ul = $6 " " $5; else if ($1 $2 == "LowerLeft") ll = $6 " " $5; else if ($1 $2 == "UpperRight") ur = $6 " " $5; else if ($1 $2 == "LowerRight") lr = $6 " " $5; else if ($1 == "Center") { printf "%s %s %s %s ", ul, ll, lr, ur; ul = ll = ur = lr = ""; } } ' | Planimeter | cut -f3 -d' ' SEE ALSO
GeoConvert(1). The algorithm for the area of geodesic polygon is given in Section 15 of C. F. F. Karney, Geodesics on an ellipsoid of revolution, Feb. 2011; preprint <http://arxiv.org/abs/1102.1215>. See also Section 6 of C. F. F. Karney, Algorithms for geodesics, Sept. 2011; preprint <http://arxiv.org/abs/1109.4448>. AUTHOR
Planimeter was written by Charles Karney. HISTORY
Planimeter was added to GeographicLib, <http://geographiclib.sf.net>, in version 1.4. GeographicLib 1.21 2012-04-24 PLANIMETER(1)
All times are GMT -4. The time now is 04:43 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy