I have a data file as:
LINE 95
SPNT 942
VELF 188 1500 276 1515 342 1532 402 1568 462 1595
VELF 534 1682 600 1802 672 1909 738 1985 822 2071
VELF 894 2136 978 2210 1056 2279 1179 2375 1310 2487
VELF 1494 2666 1620 2791 1722 2892 1836 3005 1950 3108
VELF 2064 3213 2166 3308 2280 3424 2424 3573 2664 3706
VELF 2922 3899 3144 4055 3564 4211 3894 4251 4308 4393
VELF 4890 4655 5370 4830 6042 5109 6426 5195 7296 5359
VELF 7872 5468
SPNT 962
VELF 188 1500 290 1513 341 1532 402 1568 452 1596
VELF 528 1683 600 1803 678 1909 741 1985 823 2072
VELF 895 2136 978 2210 1065 2281 1224 2374 1334 2480
VELF 1494 2666 1621 2791 1729 2893 1865 3006 1961 3106
VELF 2063 3213 2162 3308 2284 3424 2468 3572 2653 3710
VELF 2904 3898 3166 4054 3585 4209 3814 4259 4248 4393
VELF 4891 4655 5368 4830 6153 5105 6495 5192 7332 5359
VELF 7872 5468
SPNT 982
VELF 188 1500 282 1505 342 1533 402 1568 486 1625
VELF 594 1796 780 2033 936 2172 1044 2268 1218 2329
VELF 1308 2409 1440 2613 1584 2754 1692 2862 1884 2993
VELF 2016 3167 2160 3310 2352 3481 2526 3581 2748 3823
VELF 3036 3983 3348 4131 4176 4389 4482 4495 4860 4643
VELF 5382 4836 5916 5008 6612 5209 7032 5287 7872 5468
SPNT 1002
VELF 188 1500 239 1517 293 1526 398 1570 460 1634
VELF 592 1796 742 2113 832 2298 896 2371 990 2413
VELF 1044 2437 1465 2622 1621 2754 1726 2856 1868 3003
VELF 2014 3167 2156 3310 2330 3479 2482 3582 2800 3824
VELF 3093 3980 3371 4127 4172 4390 4477 4495 4860 4643
VELF 5395 4836 5916 5008 6629 5209 7021 5287 7872 5468
SPNT 1022
VELF 188 1500 246 1535 384 1556 500 1715 583 1789
VELF 682 1912 729 2183 786 2437 885 2606 974 2606
VELF 1089 2606 1203 2606 1279 2606 1380 2606 1482 2606
VELF 1596 2691 1800 2904 1896 3074 2052 3200 2307 3480
VELF 2448 3588 2736 3762 3096 3951 3702 4316 4146 4382
VELF 4560 4525 4944 4676 5856 4991 6162 5079 6510 5180
VELF 6858 5255 7872 5468
SPNT 1042
VELF 184 1500 296 1532 377 1558 518 1706 578 1793
VELF 681 1913 738 2185 794 2421 903 2597 947 2618
VELF 1005 2626 1062 2633 1100 2633 1150 2633 1201 2633
VELF 1563 2699 1752 2898 1922 3076 2075 3196 2332 3478
VELF 2459 3586 2739 3763 3075 3955 3797 4308 4123 4385
VELF 4547 4525 4939 4676 5855 4991 6157 5079 6518 5180
VELF 6850 5255 7876 5468
SPNT 1062
VELF 180 1500 282 1519 342 1533 516 1678 609 1863
VELF 674 1887 714 2052 784 2331 810 2487 938 2626
VELF 1055 2660 1201 2660 1323 2660 1506 2660 1692 2895
VELF 1812 2988 2058 3143 2172 3304 2514 3630 2682 3737
VELF 2906 3833 3232 4095 3588 4218 4008 4353 4584 4542
VELF 4890 4660 5400 4845 5904 5007 6360 5140 6846 5256
VELF 7932 5479
SPNT 1082
and an xy file named xy_file.dat which looks like:
....+....1....+....2....+....3....+....4....+....5....+....6....+....7
SAR02095 11 980 81045.87S1332934.76E 333983.59095557.5 134.819310 227
SAR02095 11 981 81046.65S1332934.55E 333977.29095533.4 134.919310 237
SAR02095 11 982 81047.43S1332934.35E 333971.09095509.6 135.019310 246
SAR02095 11 1002 81048.22S1332934.15E 333965.19095485.1 135.019310 256
SAR02095 11 1022 81049.01S1332933.95E 333959.29095461.0 135.119310 3 5
SAR02095 11 1023 81049.80S1332933.74E 333952.99095436.8 135.119310 315
SAR02095 11 1024 81050.58S1332933.52E 333946.29095412.8 135.119310 324
SAR02095 11 1042 81051.36S1332933.28E 333939.09095388.7 135.319310 334
SAR02095 11 1009 81052.14S1332933.06E 333932.29095364.6 135.419310 343
SAR02095 11 1010 81052.93S1332932.85E 333925.89095340.4 135.419310 353
SAR02095 11 1011 81053.72S1332932.65E 333919.79095316.2 135.419310 4 2
SAR02095 11 1012 81054.50S1332932.45E 333913.89095292.1 135.419310 412
SAR02095 11 1013 81055.30S1332932.26E 333908.29095267.5 135.319310 421
SAR02095 11 1014 81056.10S1332932.09E 333903.09095242.8 135.419310 431
SAR02095 11 1015 81056.90S1332931.90E 333897.49095218.4 135.519310 441
SAR02095 11 1016 81057.68S1332931.71E 333891.69095194.3 135.819310 450
and here is my awk script:
#!/usr/bin/nawk -f
#awk program reformat.nawk
BEGIN {
if (!fn) fn="xy_file.dat"
while ((getline < fn) > 0) a[NR]=$0
station[NR]=substr(a[NR],22,4)
xa=substr(a[NR],47,9)
ya=substr(a[NR],56,9)
}
{
if (match($0, "^H")) next;
if (match($0, "^1")) next;
if (match($0, "^CONT")) next;
if (match($0, "^AREA")) next;
if (match($0, "^INFO")) next;
if (match($0, "^COM")) next;
if (match($0, "^PNMO")) next;
if (match($0, "^$")) next;
if (match($0, "^EOF")) next;
if (match($0, "LINE")) {
line_name=substr($0,5,30);
gsub(/ /, "",line_name);
}
if (match($0, /SPNT/)) {
sp=substr($0,20,6);
gsub(/ /, "",sp);
for(sp in station) {x=xa;y=ya}######### how do you get the xys to populate?
# x=substr($0,26,10);
# y=substr($0,36,11);
# y=y+10000000;
}
if (match($0, /VELF/)) {
time_1= substr($0,21,5);
velocity_1=substr($0,26,5);
time_2= substr($0,31,5);
velocity_2=substr($0,36,5);
time_3= substr($0,41,5);
velocity_3=substr($0,46,5);
time_4= substr($0,51,5);
velocity_4=substr($0,56,5);
time_5= substr($0,61,5);
velocity_5=substr($0,66,5);
if (NF>=2) printf("%-12s%6s%13.1f%11.1f %4d %4d\n",line_name,sp,x,y,time_1,velocity_1);
if (NF>=4) printf("%-12s%6s%13.1f%11.1f %4d %4d\n",line_name,sp,x,y,time_2,velocity_2);
if (NF>=6) printf("%-12s%6s%13.1f%11.1f %4d %4d\n",line_name,sp,x,y,time_3,velocity_3);
if (NF>=8) printf("%-12s%6s%13.1f%11.1f %4d %4d\n",line_name,sp,x,y,time_4,velocity_4);
if (NF>=10) printf("%-12s%6s%13.1f%11.1f %4d %4d\n",line_name,sp,x,y,time_5,velocity_5);
}
}
I am matching up the x y values from the file xy_file.dat which are in columns 47 - 64 where the value in columns 22-25 match the value in the data file in columns 22-25 and the record begins with "SPNT"
The script reformats the data file properly except the matching of the xy pairs with the same "SPNT" value.
All I get is the last record from the array xa and ya.
How do you extract from the array the correct x and y when it matches the "SPNT" record value?
Thanks for any help.
LINE 95
SPNT 942
VELF 188 1500 276 1515 342 1532 402 1568 462 1595
VELF 534 1682 600 1802 672 1909 738 1985 822 2071
VELF 894 2136 978 2210 1056 2279 1179 2375 1310 2487
VELF 1494 2666 1620 2791 1722 2892 1836 3005 1950 3108
VELF 2064 3213 2166 3308 2280 3424 2424 3573 2664 3706
VELF 2922 3899 3144 4055 3564 4211 3894 4251 4308 4393
VELF 4890 4655 5370 4830 6042 5109 6426 5195 7296 5359
VELF 7872 5468
SPNT 962
VELF 188 1500 290 1513 341 1532 402 1568 452 1596
VELF 528 1683 600 1803 678 1909 741 1985 823 2072
VELF 895 2136 978 2210 1065 2281 1224 2374 1334 2480
VELF 1494 2666 1621 2791 1729 2893 1865 3006 1961 3106
VELF 2063 3213 2162 3308 2284 3424 2468 3572 2653 3710
VELF 2904 3898 3166 4054 3585 4209 3814 4259 4248 4393
VELF 4891 4655 5368 4830 6153 5105 6495 5192 7332 5359
VELF 7872 5468
SPNT 982
VELF 188 1500 282 1505 342 1533 402 1568 486 1625
VELF 594 1796 780 2033 936 2172 1044 2268 1218 2329
VELF 1308 2409 1440 2613 1584 2754 1692 2862 1884 2993
VELF 2016 3167 2160 3310 2352 3481 2526 3581 2748 3823
VELF 3036 3983 3348 4131 4176 4389 4482 4495 4860 4643
VELF 5382 4836 5916 5008 6612 5209 7032 5287 7872 5468
SPNT 1002
VELF 188 1500 239 1517 293 1526 398 1570 460 1634
VELF 592 1796 742 2113 832 2298 896 2371 990 2413
VELF 1044 2437 1465 2622 1621 2754 1726 2856 1868 3003
VELF 2014 3167 2156 3310 2330 3479 2482 3582 2800 3824
VELF 3093 3980 3371 4127 4172 4390 4477 4495 4860 4643
VELF 5395 4836 5916 5008 6629 5209 7021 5287 7872 5468
SPNT 1022
VELF 188 1500 246 1535 384 1556 500 1715 583 1789
VELF 682 1912 729 2183 786 2437 885 2606 974 2606
VELF 1089 2606 1203 2606 1279 2606 1380 2606 1482 2606
VELF 1596 2691 1800 2904 1896 3074 2052 3200 2307 3480
VELF 2448 3588 2736 3762 3096 3951 3702 4316 4146 4382
VELF 4560 4525 4944 4676 5856 4991 6162 5079 6510 5180
VELF 6858 5255 7872 5468
SPNT 1042
VELF 184 1500 296 1532 377 1558 518 1706 578 1793
VELF 681 1913 738 2185 794 2421 903 2597 947 2618
VELF 1005 2626 1062 2633 1100 2633 1150 2633 1201 2633
VELF 1563 2699 1752 2898 1922 3076 2075 3196 2332 3478
VELF 2459 3586 2739 3763 3075 3955 3797 4308 4123 4385
VELF 4547 4525 4939 4676 5855 4991 6157 5079 6518 5180
VELF 6850 5255 7876 5468
SPNT 1062
VELF 180 1500 282 1519 342 1533 516 1678 609 1863
VELF 674 1887 714 2052 784 2331 810 2487 938 2626
VELF 1055 2660 1201 2660 1323 2660 1506 2660 1692 2895
VELF 1812 2988 2058 3143 2172 3304 2514 3630 2682 3737
VELF 2906 3833 3232 4095 3588 4218 4008 4353 4584 4542
VELF 4890 4660 5400 4845 5904 5007 6360 5140 6846 5256
VELF 7932 5479
SPNT 1082
and an xy file named xy_file.dat which looks like:
....+....1....+....2....+....3....+....4....+....5....+....6....+....7
SAR02095 11 980 81045.87S1332934.76E 333983.59095557.5 134.819310 227
SAR02095 11 981 81046.65S1332934.55E 333977.29095533.4 134.919310 237
SAR02095 11 982 81047.43S1332934.35E 333971.09095509.6 135.019310 246
SAR02095 11 1002 81048.22S1332934.15E 333965.19095485.1 135.019310 256
SAR02095 11 1022 81049.01S1332933.95E 333959.29095461.0 135.119310 3 5
SAR02095 11 1023 81049.80S1332933.74E 333952.99095436.8 135.119310 315
SAR02095 11 1024 81050.58S1332933.52E 333946.29095412.8 135.119310 324
SAR02095 11 1042 81051.36S1332933.28E 333939.09095388.7 135.319310 334
SAR02095 11 1009 81052.14S1332933.06E 333932.29095364.6 135.419310 343
SAR02095 11 1010 81052.93S1332932.85E 333925.89095340.4 135.419310 353
SAR02095 11 1011 81053.72S1332932.65E 333919.79095316.2 135.419310 4 2
SAR02095 11 1012 81054.50S1332932.45E 333913.89095292.1 135.419310 412
SAR02095 11 1013 81055.30S1332932.26E 333908.29095267.5 135.319310 421
SAR02095 11 1014 81056.10S1332932.09E 333903.09095242.8 135.419310 431
SAR02095 11 1015 81056.90S1332931.90E 333897.49095218.4 135.519310 441
SAR02095 11 1016 81057.68S1332931.71E 333891.69095194.3 135.819310 450
and here is my awk script:
#!/usr/bin/nawk -f
#awk program reformat.nawk
BEGIN {
if (!fn) fn="xy_file.dat"
while ((getline < fn) > 0) a[NR]=$0
station[NR]=substr(a[NR],22,4)
xa=substr(a[NR],47,9)
ya=substr(a[NR],56,9)
}
{
if (match($0, "^H")) next;
if (match($0, "^1")) next;
if (match($0, "^CONT")) next;
if (match($0, "^AREA")) next;
if (match($0, "^INFO")) next;
if (match($0, "^COM")) next;
if (match($0, "^PNMO")) next;
if (match($0, "^$")) next;
if (match($0, "^EOF")) next;
if (match($0, "LINE")) {
line_name=substr($0,5,30);
gsub(/ /, "",line_name);
}
if (match($0, /SPNT/)) {
sp=substr($0,20,6);
gsub(/ /, "",sp);
for(sp in station) {x=xa;y=ya}######### how do you get the xys to populate?
# x=substr($0,26,10);
# y=substr($0,36,11);
# y=y+10000000;
}
if (match($0, /VELF/)) {
time_1= substr($0,21,5);
velocity_1=substr($0,26,5);
time_2= substr($0,31,5);
velocity_2=substr($0,36,5);
time_3= substr($0,41,5);
velocity_3=substr($0,46,5);
time_4= substr($0,51,5);
velocity_4=substr($0,56,5);
time_5= substr($0,61,5);
velocity_5=substr($0,66,5);
if (NF>=2) printf("%-12s%6s%13.1f%11.1f %4d %4d\n",line_name,sp,x,y,time_1,velocity_1);
if (NF>=4) printf("%-12s%6s%13.1f%11.1f %4d %4d\n",line_name,sp,x,y,time_2,velocity_2);
if (NF>=6) printf("%-12s%6s%13.1f%11.1f %4d %4d\n",line_name,sp,x,y,time_3,velocity_3);
if (NF>=8) printf("%-12s%6s%13.1f%11.1f %4d %4d\n",line_name,sp,x,y,time_4,velocity_4);
if (NF>=10) printf("%-12s%6s%13.1f%11.1f %4d %4d\n",line_name,sp,x,y,time_5,velocity_5);
}
}
I am matching up the x y values from the file xy_file.dat which are in columns 47 - 64 where the value in columns 22-25 match the value in the data file in columns 22-25 and the record begins with "SPNT"
The script reformats the data file properly except the matching of the xy pairs with the same "SPNT" value.
All I get is the last record from the array xa and ya.
How do you extract from the array the correct x and y when it matches the "SPNT" record value?
Thanks for any help.