#!/bin/bash
#
# bak in Amsterdam before start of jc184 uhdas trial
# 3 July 2019
#
# This is run as a bash, because we want the quick_adcp.py to run in the
# python 3 environment
# 
# This script merges the edits stored in the proc_archive asclog file with 
# any stored in the proc_editing file
#
# The combined sorted edits are stored in both of asc and asclog in the proc_editing file
# The editing process takes past input from .asc, and appends new edits to .asclog
#
# List of cruise segments to be processed is found in
# ~/cruise/data/vmadcp/cruise_segments
#

# make sure the bash environment is set up
source ~/.bashrc

# no set command in bash
ldir=~/cruise/data/vmadcp

for segname in `cat ~/cruise/data/vmadcp/cruise_segments`
do

pushd ${ldir}/postprocessing/${segname}/proc_editing


for pingtype in `ls -d *`
do
echo ${segname}/${pingtype}
data=0
if test -f ${ldir}/postprocessing/${segname}/proc_editing/${pingtype}/adcpdb/*dir.blk
then
data=1
fi

echo data ${data}

if [ ${data} -eq  1 ]
then
pushd ${ldir}/postprocessing/${segname}/proc_editing/${pingtype}
thisdir=`pwd`
echo working in ${thisdir}

# now fix the asc files

for asctype in abadbin abottom abadprf
do
echo ${asctype}
f1=${ldir}/postprocessing/${segname}/proc_editing/${pingtype}/edit/${asctype}.asclog
f2=${ldir}/postprocessing/${segname}/proc_archive/${pingtype}/edit/${asctype}.asclog
f3=${ldir}/postprocessing/${segname}/proc_editing/${pingtype}/edit/${asctype}.asc
f4=${ldir}/postprocessing/${segname}/proc_editing/${pingtype}/edit/${asctype}.asclog
cat ${f1} ${f2} | sort -u > ${f3}
/bin/cp -p ${f3} ${f4}
done

thisdir=`pwd`
echo quick_adcp.py in ${thisdir}
which quick_adcp.py
quick_adcp.py --steps2rerun apply_edit:navsteps:calib --auto


popd
fi
done
popd


done