Sponsored Content
Top Forums Shell Programming and Scripting Calculate average, azimut and distance Post 302968337 by jiam912 on Tuesday 8th of March 2016 11:35:05 AM
Old 03-08-2016
Hi Don

I manage to do this script.. I got the distance but I cant get the azimut

Code:
#!/bin/bash

cat input.txt | awk '$0 !~ /^ *$/' |
      awk '{
  	      pv[NR]  = substr($3,1,5)
              line[NR]  = substr($2,1,5)
              x[NR]   = substr($0,57,8)
              y[NR]   = substr($0,66,9)
           } END {
                   first = 1
                   count = 0
                   for ( i=1 ; i <= NR ; i++ ) {
                       if (pv[i] != pv[i+1] || line[i] != line[i+1]) {
                          last = i
                          count++
                          dx = x[first]-x[last]
                          dy = y[first]-y[last]
                          len[count] = sqrt(dx^2+dy^2)
                             if ( len[count] <= 1000 && len[count] > 0 ) {
                                          printf (" %4s %4s : %-8.2f\n", line[i],pv[i],len[count])
                          }\
                          first = i+1
                      }
                   }
                  }' > output.txt

Input

Code:
A         35591.0 52025.01714 75   1  -2101674 79 69 81 504913.2 2386393.5 122.9  1747 1 7 1
A         35591.0 52025.01726 75   1   2102374 78 72 81 504913.0 2386381.2 122.8  1747 1 7 1
A         35623.0 50561.01222 75   1   2121874 78 73 80 486612.3 2386795.1 134.2  1333 112 1
A         35623.0 50561.012 6 75   1   3122374 80 70 79 486612.0 2386782.6 134.3  1333 112 1
A         35179.0 51449.01328 75   1   2113274 79 71 80 497712.4 2381242.9 129.9   531 1 3 1
A         35179.0 51449.01330 75   1   3172374 80 72 79 497712.7 2381231.0 130.3   531 1 3 1

Output
Code:
35591 52025 : 12.30   
35623 50561 : 12.50   
35179 51449 : 11.90

Please, I will like to get the results as mentioned previously #1... I try my best but i cant get even the azimut..Please try to help me to get it.

Last edited by jiam912; 03-08-2016 at 02:01 PM..
 

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

calculate average of column 2

Hi I have fakebook.csv as following: F1(current date) F2(popularity) F3(name of book) F4(release date of book) 2006-06-21,6860,"Harry Potter",2006-12-31 2006-06-22,,"Harry Potter",2006-12-31 2006-06-23,7120,"Harry Potter",2006-12-31 2006-06-24,,"Harry Potter",2006-12-31... (0 Replies)
Discussion started by: onthetopo
0 Replies

2. 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

3. Shell Programming and Scripting

program to calculate distance between 5 atoms

Hello, I am a beginner with perl. I have a perl program to calculate the distance between 5 atoms or more. i have an array which looks like this: 6.324 32.707 50.379 5.197 32.618 46.826 4.020 36.132 46.259 7.131 38.210 45.919 6.719 38.935 42.270 2.986 39.221 ... (1 Reply)
Discussion started by: annie_singh
1 Replies

4. Programming

calculate average

I have a file which is 2 3 4 5 6 6 so i am writing program in C to calculate mean.. #include<stdio.h> #include<string.h> #include <math.h> double CALL mean(int n , double x) main (int argc, char **argv) { char Buf,SEQ; int i; double result = 0; FILE *fp; (3 Replies)
Discussion started by: cdfd123
3 Replies

5. Programming

Converting distance list to distance matrix in R

Hi power user, I have this type of data (distance list): file1 A B 10 B C 20 C D 50I want output like this # A B C D A 0 10 30 80 B 10 0 20 70 C 30 20 0 50 D 80 70 50 0 Which is a distance matrix I have tried... (0 Replies)
Discussion started by: anjas
0 Replies

6. Shell Programming and Scripting

Calculate distance and azimuth

Hi all, I have a data file like this lat lon lat lon 12.000 25.125 14.235 25.012 14.200 81.000 25.584 25.014 45.023 25.365 25.152 35.222 I want to calculate distance and azimuth between this points eg:- 12.000,25.125 and 14.235,25.012 I want to use awk programming... (3 Replies)
Discussion started by: chamara
3 Replies

7. 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

8. 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

9. 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

10. Shell Programming and Scripting

Calculate the average per block.

My old school way is a one liner. And will search for average from SAR, to get the data receive rate. But, I dont think it is practical or accurate,. Because it calculates to off peak hours. I am planning to change it. My cron runs every 30 mins. When my cron runs, and my time is 14:47pm,, it will... (1 Reply)
Discussion started by: invinzin21
1 Replies
Tk_GetPixelsFromObj(3)					       Tk Library Procedures					    Tk_GetPixelsFromObj(3)

__________________________________________________________________________________________________________________________________________________

NAME
Tk_GetPixelsFromObj, Tk_GetPixels, Tk_GetMMFromObj, Tk_GetScreenMM - translate between strings and screen units SYNOPSIS
#include <tk.h> int Tk_GetPixelsFromObj(interp, tkwin, objPtr, intPtr) int Tk_GetPixels(interp, tkwin, string, intPtr) int Tk_GetMMFromObj(interp, tkwin, objPtr, doublePtr) int Tk_GetScreenMM(interp, tkwin, string, doublePtr) ARGUMENTS
Tcl_Interp *interp (in) Interpreter to use for error reporting. Tk_Window tkwin (in) Window whose screen geometry determines the conversion between absolute units and pixels. Tcl_Obj *objPtr (in/out) String value specifies a distance on the screen; internal rep will be modified to cache converted dis- tance. const char *string (in) Same as objPtr except specification of distance is passed as a string. int *intPtr (out) Pointer to location in which to store converted distance in pixels. double *doublePtr (out) Pointer to location in which to store converted distance in millimeters. _________________________________________________________________ DESCRIPTION
These procedures take as argument a specification of distance on the screen (objPtr or string) and compute the corresponding distance either in integer pixels or floating-point millimeters. In either case, objPtr or string specifies a screen distance as a floating-point number followed by one of the following characters that indicates units: <none> The number specifies a distance in pixels. c The number specifies a distance in centimeters on the screen. i The number specifies a distance in inches on the screen. m The number specifies a distance in millimeters on the screen. p The number specifies a distance in printer's points (1/72 inch) on the screen. Tk_GetPixelsFromObj converts the value of objPtr to the nearest even number of pixels and stores that value at *intPtr. It returns TCL_OK under normal circumstances. If an error occurs (e.g. objPtr contains a number followed by a character that is not one of the ones above) then TCL_ERROR is returned and an error message is left in interp's result if interp is not NULL. Tk_GetPixelsFromObj caches information about the return value in objPtr, which speeds up future calls to Tk_GetPixelsFromObj with the same objPtr. Tk_GetPixels is identical to Tk_GetPixelsFromObj except that the screen distance is specified with a string instead of an object. This prevents Tk_GetPixels from caching the return value, so Tk_GetAnchor is less efficient than Tk_GetPixelsFromObj. Tk_GetMMFromObj and Tk_GetScreenMM are similar to Tk_GetPixelsFromObj and Tk_GetPixels (respectively) except that they convert the screen distance to millimeters and store a double-precision floating-point result at *doublePtr. KEYWORDS
centimeters, convert, inches, millimeters, pixels, points, screen units Tk 8.1 Tk_GetPixelsFromObj(3)
All times are GMT -4. The time now is 11:03 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy