-
Notifications
You must be signed in to change notification settings - Fork 1
/
par2afile.sh
executable file
·58 lines (48 loc) · 1.63 KB
/
par2afile.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
#! /bin/bash
#
############################################################################
#
# MODULE: par2afile.sh for Grass 7.x
#
# AUTHOR: Eric Patton, Geological Survey of Canada (Atlantic)
# <Eric dot Patton at Canada dot ca>
#
# PURPOSE: Parses a PAR file for the start and stop times of the
# navigation of a seismic instrument and outputs the time, lat and long of the
# nav file to a GSCA-formatted NAV file.
#
# COPYRIGHT: (c) 2022 by Eric Patton
#
# This program is free software under the GNU General Public
# License (>=v3). Read the file COPYING that comes with GRASS
# for details.
#
# Created: January 20, 2021
# Last Modified: January 22, 2021
#
#############################################################################
SCRIPT=$(basename $0)
if [ "$#" -ne 2 -o "$1" == "-H" -o "$1" == "-h" -o "$1" == "--help" -o "$1" == "-help" ] ; then
echo -e "\nusage: $SCRIPT parfile navfile \n"
exit 1
fi
# What to do in case of user break:
exitprocedure()
{
echo -e "\n\n$SCRIPT: User break or similar caught; Exiting.\n"
exit 1
}
# Setup clean exit for Ctrl-C or similar breaks.
trap 'exitprocedure' 2 3 15
PARFILE=$1
NAVFILE=$2
OUTPUT="$(basename $PARFILE .PAR).afile"
# Since we are going to be appending the out $OUTPUT later on, remove it if it
# already exists.
[[ -f ${OUTPUT} ]] && rm ${OUTPUT}
for LINE in $(seq 1 $(wc -l ${PARFILE} | cut -d' ' -f1)) ; do
START=$(awk -v line=$LINE 'NR == line {print $1}' ${PARFILE})
STOP=$(awk -v line=$LINE 'NR == line {print $2}' ${PARFILE})
sed -n "/${START}/,/${STOP}/p" ${NAVFILE} >> ${OUTPUT}
done
exit 0