I have two shell script. One for pick up information and other one is for update those information to sac header. I am facing problem when 1.sh passes the arguments to the shell script 2.sh for updating sac header. Please help. Thanks in advance
Below one is 1.sh which finds the information from a list of events
#!/bin/bash
while IFS=' ' read -r ev[$i] || [[ -n "${ev[$i]}" ]]; do # Reads event list
echo ${ev[$i]} | cut -c1-12 # shows events in proper format
while IFS=' ' read -r ct[$j] || [[ -n "${ct[$j]}" ]]; do # Reads catalog file
ct1[$j]=`echo ${ct[$j]} | tr --delete ' ' | tr --delete '-'| tr --delete ':' | cut -c1-12` # Picks events in proper format
if [ ${ev[$i]} -ge $((${ct1[$j]}-5)) -a ${ev[$i]} -le $((${ct1[$j]}+5)) ] then # Checks the events and catalog information
echo ${ct[$j]}>>events.txt # Writes event information
lat= awk -v i=$k 'FNR == i {print $3}' events.txt
lon= awk -v i=$k 'FNR == i {print $4}' events.txt
depth= awk -v i=$k 'FNR == i {print $5}' events.txt
magnitude= awk -v i=$k 'FNR == i {print $6}' events.txt
./2.sh $lat $lon $depth $magnitude # Edit sac header
k=$(($k+1))
fi
j=$(($j+1)) # Update loop
done < "catalog.txt"
i=$(($i+1)) # Update loop
done < "event_list.txt"
This is another shell file named 2.sh which edits the sac header
#!/bin/bash
lat=$1
lon=$2
depth=$3
magnitude=$4
sac << EOD
setbb sacfile "200701081245*.sac"
r %sacfile%
ch lovrok true
ch o 0
ch evla $lat
ch evlo $lon
ch evdp $depth
ch mag $magnitude
w over
q
EOD
Event lists are like
cat > event_list.txt << END
200701081245
END
Catalog file is like
cat > catalog.txt << END
2007-01-07 08:01:41.82 47.0525 153.8486 19.8 5.8
2007-01-08 02:22:06.74 -9.9751 160.77 47.8 5.5
2007-01-08 12:48:41.66 8.0486 92.4527 17.4 5.5
2007-01-08 17:21:50.43 39.823 70.309 18.4 5.8
2007-01-08 20:52:21.47 -18.6573 -177.7743 410.5 5.5
END
With best regards
Prateek Mondal
Contact No. : +91-9476433227
Below one is 1.sh which finds the information from a list of events
#!/bin/bash
while IFS=' ' read -r ev[$i] || [[ -n "${ev[$i]}" ]]; do # Reads event list
echo ${ev[$i]} | cut -c1-12 # shows events in proper format
while IFS=' ' read -r ct[$j] || [[ -n "${ct[$j]}" ]]; do # Reads catalog file
ct1[$j]=`echo ${ct[$j]} | tr --delete ' ' | tr --delete '-'| tr --delete ':' | cut -c1-12` # Picks events in proper format
if [ ${ev[$i]} -ge $((${ct1[$j]}-5)) -a ${ev[$i]} -le $((${ct1[$j]}+5)) ] then # Checks the events and catalog information
echo ${ct[$j]}>>events.txt # Writes event information
lat= awk -v i=$k 'FNR == i {print $3}' events.txt
lon= awk -v i=$k 'FNR == i {print $4}' events.txt
depth= awk -v i=$k 'FNR == i {print $5}' events.txt
magnitude= awk -v i=$k 'FNR == i {print $6}' events.txt
./2.sh $lat $lon $depth $magnitude # Edit sac header
k=$(($k+1))
fi
j=$(($j+1)) # Update loop
done < "catalog.txt"
i=$(($i+1)) # Update loop
done < "event_list.txt"
This is another shell file named 2.sh which edits the sac header
#!/bin/bash
lat=$1
lon=$2
depth=$3
magnitude=$4
sac << EOD
setbb sacfile "200701081245*.sac"
r %sacfile%
ch lovrok true
ch o 0
ch evla $lat
ch evlo $lon
ch evdp $depth
ch mag $magnitude
w over
q
EOD
Event lists are like
cat > event_list.txt << END
200701081245
END
Catalog file is like
cat > catalog.txt << END
2007-01-07 08:01:41.82 47.0525 153.8486 19.8 5.8
2007-01-08 02:22:06.74 -9.9751 160.77 47.8 5.5
2007-01-08 12:48:41.66 8.0486 92.4527 17.4 5.5
2007-01-08 17:21:50.43 39.823 70.309 18.4 5.8
2007-01-08 20:52:21.47 -18.6573 -177.7743 410.5 5.5
END
With best regards
Prateek Mondal
Contact No. : +91-9476433227